@agentprojectcontext/apx 1.56.1 → 1.56.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentprojectcontext/apx",
3
- "version": "1.56.1",
3
+ "version": "1.56.2",
4
4
  "description": "APX — unified CLI + daemon for the Agent Project Context (APC) standard.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -635,7 +635,7 @@ ${s.join(`
635
635
  → (omitido)`);return}const u=[];if(o.options&&o.options.length>0){const g=[...c.picked].sort((h,b)=>h-b).map(h=>o.options[h]?.label).filter(Boolean);g.length>0&&u.push(g.join(", "))}const p=c.text.trim();p&&u.push(o.options&&o.options.length>0?`(Otro: ${p})`:p);const m=u.length>0?u.join(" "):"(sin respuesta)";s.push(`- ${o.question}
636
636
  → ${m}`)}),s.join(`
637
637
  `)}function EN({turnKey:e,questions:t,onSubmit:s,onDismiss:o,disabled:l}){const c=t.length,[u,p]=x.useState(0),[m,g]=x.useState(()=>t.map(()=>kl()));x.useEffect(()=>{p(0),g(t.map(()=>kl()))},[e,t]);const h=t[u],b=m[u]||kl(),v=!!h?.options&&h.options.length>0,k=!!h?.multiSelect,N=h?.allowText!==!1,j=T=>{g(O=>{const D=[...O],U=D[u]||kl();return D[u]={...U,...T,skipped:!1},D})},y=T=>{g(O=>{const D=[...O],U=D[u]||kl(),L=new Set(U.picked);return k?L.has(T)?L.delete(T):L.add(T):(L.clear(),L.add(T)),D[u]={...U,picked:L,skipped:!1},D})},C=x.useMemo(()=>!0,[]),S=u===c-1,E=()=>p(T=>Math.max(0,T-1)),R=()=>{if(S){s(dw(t,m));return}p(T=>Math.min(c-1,T+1))},M=()=>{if(g(T=>{const O=[...T];return O[u]={picked:new Set,text:"",skipped:!0},O}),S){const T=m.map((O,D)=>D===u?{picked:new Set,text:"",skipped:!0}:O);s(dw(t,T))}else p(T=>Math.min(c-1,T+1))};return x.useEffect(()=>{const T=O=>{if(l)return;const D=O.target?.tagName?.toLowerCase(),U=D==="input"||D==="textarea";if(O.key==="Enter"&&(O.metaKey||O.ctrlKey)){O.preventDefault(),R();return}if(!U&&v&&/^[1-9]$/.test(O.key)){const L=parseInt(O.key,10)-1;L<(h?.options?.length||0)&&(O.preventDefault(),y(L))}};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)}),!h||c===0?null:r.jsxs("div",{className:Te("mx-3 mb-2 rounded-xl border border-border bg-card/95 shadow-xl backdrop-blur supports-[backdrop-filter]:bg-card/80",l&&"pointer-events-none opacity-60"),"data-testid":"inline-ask-panel",children:[r.jsxs("header",{className:"flex items-start gap-2 border-b border-border px-3 py-2",children:[r.jsxs("span",{className:"mt-0.5 shrink-0 rounded-md bg-amber-500/15 px-1.5 py-0.5 text-[10px] font-mono font-medium text-amber-700 dark:text-amber-300",children:[u+1,"/",c]}),h.header&&r.jsx("span",{className:"mt-0.5 shrink-0 rounded-md bg-muted px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground",children:h.header}),r.jsx("p",{className:"min-w-0 flex-1 text-sm font-semibold leading-snug",children:h.question}),o&&r.jsx("button",{type:"button",onClick:o,className:"rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground","aria-label":f("common.close"),children:r.jsx(Ys,{className:"size-3.5"})})]}),r.jsxs("div",{className:"space-y-1 px-2 py-2",children:[v&&h.options.map((T,O)=>{const D=b.picked.has(O);return r.jsxs("button",{type:"button",onClick:()=>y(O),className:Te("flex w-full items-start gap-2 rounded-md border border-transparent px-2 py-1.5 text-left transition",D?"border-emerald-500/40 bg-emerald-500/10":"hover:border-border hover:bg-accent/40"),children:[r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("div",{className:"text-xs font-medium",children:T.label}),T.description&&r.jsx("div",{className:"text-[11px] text-muted-foreground",children:T.description})]}),k?r.jsx("span",{className:Te("mt-0.5 grid size-4 shrink-0 place-items-center rounded border",D?"border-emerald-500 bg-emerald-500 text-white":"border-border bg-background"),children:D&&r.jsx("span",{className:"text-[10px] leading-none",children:"✓"})}):r.jsx("span",{className:Te("mt-0.5 grid size-4 shrink-0 place-items-center rounded border font-mono text-[10px]",D?"border-emerald-500 bg-emerald-500 text-white":"border-border bg-muted text-muted-foreground"),children:O+1})]},`${O}:${T.label}`)}),(N||!v)&&r.jsxs("div",{className:"rounded-md border border-transparent px-2 py-1.5 hover:border-border",children:[v&&r.jsx("div",{className:"mb-1 text-xs font-medium",children:f("ask_panel.other")}),r.jsx("input",{type:"text",value:b.text,onChange:T=>j({text:T.target.value}),placeholder:f(v?"ask_panel.other_placeholder":"ask_panel.text_placeholder"),className:"w-full rounded border border-border bg-background px-2 py-1 text-xs outline-none focus:border-emerald-500"})]})]}),r.jsxs("footer",{className:"flex items-center justify-between gap-2 border-t border-border px-3 py-2",children:[r.jsx("button",{type:"button",onClick:E,disabled:u===0,className:"rounded px-2 py-1 text-[11px] text-muted-foreground hover:bg-accent disabled:opacity-30",children:f("ask_panel.back")}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("button",{type:"button",onClick:M,className:"rounded px-2 py-1 text-[11px] text-muted-foreground hover:bg-accent",children:f("ask_panel.skip")}),r.jsxs("button",{type:"button",onClick:R,disabled:!C,className:"inline-flex items-center gap-1 rounded bg-emerald-500/15 px-2 py-1 text-[11px] font-medium text-emerald-700 hover:bg-emerald-500/25 dark:text-emerald-300",children:[f(S?"ask_panel.submit":"ask_panel.next"),r.jsx(jM,{className:"size-3 opacity-60"})]})]})]})]})}function TI(e){if(typeof e=="string")return{question:e,options:[],multiSelect:!1,allowText:!0};if(!e||typeof e!="object")return null;const t=e,s=typeof t.question=="string"?t.question:"";if(!s)return null;const l=(Array.isArray(t.options)?t.options:[]).map(c=>{if(typeof c=="string")return{label:c};if(c&&typeof c=="object"&&typeof c.label=="string"){const u=c;return{label:u.label,description:typeof u.description=="string"?u.description:void 0}}return null}).filter(c=>c!==null);return{question:s,header:typeof t.header=="string"?t.header:void 0,options:l,multiSelect:t.multiSelect===!0,allowText:t.allowText!==!1}}function RN(e){if(!e.length)return null;const t=e[e.length-1];if(t.role!=="assistant")return null;let s=null,o=-1;for(let g=t.parts.length-1;g>=0;g--){const h=t.parts[g];if(h.kind==="tool"&&h.tool==="ask_questions"){s=h,o=g;break}}if(!s||o<0)return null;let l=null;if(typeof s.result=="string")try{l=JSON.parse(s.result)}catch{l=null}else s.result&&typeof s.result=="object"&&(l=s.result);const c=[];Array.isArray(s.args?.questions)&&c.push(s.args.questions),l&&Array.isArray(l.questions)&&c.push(l.questions);let u=[];for(const g of c)if(u=g.map(TI).filter(h=>!!h),u.length>0)break;return u.length?{turnKey:`${t.ts||""}#${o}`,questions:u}:null}const Cx={live:{label:"Live",icon:ma,order:0},telegram:{label:"Telegram",icon:Gs,order:1},voice:{label:"Voice",icon:nS,order:2},desktop:{label:"Desktop",icon:Gx,order:3},web:{label:"Web",icon:Fx,order:4},a2a:{label:"Agent ↔ Agent",icon:dn,order:5},schedule:{label:"Schedule",icon:t3,order:6},other:{label:"Other",icon:Af,order:7}};function fw(e){if(!e)return"web";const t=e.toLowerCase();return t==="telegram"?"telegram":t==="voice"||t==="overlay"?"voice":t==="desktop"?"desktop":t==="web"||t==="sidebar"||t==="web-sidebar"?"web":t==="a2a"||t.startsWith("agent")?"a2a":t==="schedule"||t==="cron"||t==="routine"?"schedule":"other"}function AI({pid:e,slug:t,onLoaded:s}){const{data:o}=We(`/projects/${e}/agents/${t}/conversations`,()=>Dc.list(e,t),{revalidateOnFocus:!1});return x.useEffect(()=>{s(t,o)},[t,o]),null}function MI({pid:e,agents:t,superAgentSlug:s,superAgentLabel:o,selected:l,onSelect:c,onNewChat:u}){const[p,m]=x.useState(""),[g,h]=x.useState(""),[b,v]=x.useState({}),[k,N]=x.useState({}),j=String(e)==="0",y=We(j?`/projects/${e}/super-agent/threads`:null,()=>Dc.threads(e),{revalidateOnFocus:!1}),C=(L,I)=>{I&&N(z=>{const B=z[L];return B&&B.length===I.length&&B===I?z:{...z,[L]:I}})},S=x.useMemo(()=>{const L=[];for(const I of t)for(const z of k[I.slug]||[])L.push({...z,agent_slug:z.agent_slug||I.slug});return L},[t,k]),E=x.useMemo(()=>{const L=p.trim().toLowerCase();return S.filter(I=>!(g&&I.agent_slug!==g||L&&!`${I.title||""} ${I.id} ${I.agent_slug}`.toLowerCase().includes(L)))},[S,p,g]),R=x.useMemo(()=>{if(g&&g!==s)return[];const L=p.trim().toLowerCase();return(y.data||[]).filter(I=>L?`${I.title} ${I.id} ${I.channel}`.toLowerCase().includes(L):!0)},[y.data,p,g,s]),M=x.useMemo(()=>{const L=new Map,I=(z,B)=>{const H=L.get(z);H?H.push(B):L.set(z,[B])};for(const z of E)I(fw(z.channel),{type:"conv",conv:z,sortTs:z.started_at||""});for(const z of R)I(fw(z.channel),{type:"thread",thread:z,sortTs:z.last_ts||z.started_at||""});return Array.from(L.entries()).map(([z,B])=>({key:z,items:B.sort((H,$)=>new Date($.sortTs||0).getTime()-new Date(H.sortTs||0).getTime())})).sort((z,B)=>Cx[z.key].order-Cx[B.key].order)},[E,R]),T=x.useMemo(()=>{if(g===s)return[{slug:s,label:o}];const L=[];g||L.push({slug:s,label:o});for(const I of t)g&&I.slug!==g||L.push({slug:I.slug,label:I.slug});return L},[t,g,s,o]),O=x.useMemo(()=>[{value:"",label:f("project.chat.list.all_agents")},{value:s,label:o},...t.map(L=>({value:L.slug,label:L.slug}))],[t,s,o]),D=S.length+(y.data?.length||0)+T.length,U=Object.keys(k).length>0||t.length===0||!!y.data;return r.jsxs("aside",{className:"flex h-full w-72 shrink-0 flex-col border-r border-border bg-card/30",children:[t.map(L=>r.jsx(AI,{pid:e,slug:L.slug,onLoaded:C},L.slug)),r.jsxs("header",{className:"flex h-[57px] shrink-0 items-center justify-between gap-2 border-b border-border px-3",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("p",{className:"truncate text-sm font-semibold",children:f("project.chat.list.title")}),r.jsx("p",{className:"text-[10px] text-muted-fg",children:f("project.chat.list.count",{n:D})})]}),r.jsxs("button",{type:"button",onClick:u,className:"inline-flex items-center gap-1 rounded-md border border-border bg-accent/60 px-2 py-1 text-[11px] font-medium hover:bg-accent",children:[r.jsx(an,{className:"size-3"})," ",f("project.chat.list.new")]})]}),r.jsxs("div",{className:"space-y-2 border-b border-border p-2",children:[r.jsx(Ee,{value:p,onChange:L=>m(L.target.value),placeholder:f("project.chat.list.search")}),r.jsx(_t,{value:g,onChange:h,options:O})]}),r.jsxs("div",{className:"flex-1 space-y-3 overflow-y-auto p-2",children:[!U&&r.jsx("div",{className:"px-2 py-1",children:r.jsx(rt,{})}),T.length>0&&r.jsx(pw,{keyName:"live",count:T.length,collapsed:!!b.live,onToggle:()=>v(L=>({...L,live:!L.live})),children:T.map(L=>{const I=L.slug===s,z=l.kind==="live"&&l.agentSlug===L.slug;return r.jsx(mh,{title:I?L.label:f("project.chat.list.live_with",{slug:L.slug}),subtitle:f("project.chat.list.live_subtitle"),badge:I?"super":L.slug,selected:z,onClick:()=>c({kind:"live",agentSlug:L.slug})},`live-${L.slug}`)})}),M.map(L=>r.jsx(pw,{keyName:L.key,count:L.items.length,collapsed:!!b[L.key],onToggle:()=>v(I=>({...I,[L.key]:!I[L.key]})),children:L.items.map(I=>{if(I.type==="thread"){const H=I.thread,$=l.kind==="thread"&&l.channel===H.channel&&l.threadId===H.id;return r.jsx(mh,{title:H.title,subtitle:[H.channel,`${H.messages} msg`].join(" · "),badge:"super",timeAgo:H.last_ts,selected:$,onClick:()=>c({kind:"thread",channel:H.channel,threadId:H.id})},`thread-${H.channel}-${H.id}`)}const z=I.conv,B=l.kind==="conv"&&l.agentSlug===z.agent_slug&&l.convId===z.id;return r.jsx(mh,{title:z.title||z.id,subtitle:[z.agent_slug,`${z.messages??0} msg`].filter(Boolean).join(" · "),badge:z.agent_slug,timeAgo:z.started_at,selected:B,onClick:()=>c({kind:"conv",agentSlug:z.agent_slug,convId:z.id})},`${z.agent_slug}-${z.id}`)})},L.key)),U&&S.length===0&&R.length===0&&r.jsx("p",{className:"px-3 py-6 text-center text-xs text-muted-fg",children:f("project.chat.list.empty")})]})]})}function pw({keyName:e,count:t,collapsed:s,onToggle:o,children:l}){const c=Cx[e],u=c.icon;return r.jsxs("section",{className:"space-y-1",children:[r.jsxs("button",{type:"button",onClick:o,className:"flex w-full items-center justify-between rounded-md px-2 py-1 text-muted-fg hover:bg-accent/30",children:[r.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s?r.jsx(Zl,{className:"size-3"}):r.jsx(pa,{className:"size-3"}),r.jsx(u,{className:"size-3"}),r.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider",children:c.label})]}),r.jsx("span",{className:"text-[10px]",children:t})]}),!s&&r.jsx("div",{className:"space-y-0.5",children:l})]})}function mh({title:e,subtitle:t,badge:s,timeAgo:o,selected:l,onClick:c}){return r.jsxs("button",{type:"button",onClick:c,className:Tc("w-full rounded-md border px-2.5 py-2 text-left transition-colors",l?"border-primary/50 bg-primary/10":"border-transparent hover:border-border hover:bg-accent/40"),children:[r.jsxs("div",{className:"flex items-start justify-between gap-2",children:[r.jsx("p",{className:Tc("truncate text-sm",l?"font-semibold":"font-medium"),children:e}),o&&r.jsxs("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-[10px] text-muted-fg",children:[r.jsx(_M,{className:"size-2.5"}),OI(o)]})]}),r.jsxs("div",{className:"mt-0.5 flex items-center justify-between gap-2 text-[10px] text-muted-fg",children:[r.jsx("span",{className:"truncate",children:t}),s&&r.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 rounded bg-accent/50 px-1.5 py-0.5",children:[r.jsx(Xx,{className:"size-2.5"}),s]})]})]})}function OI(e){if(!e)return"";const t=new Date(e).getTime();if(!Number.isFinite(t))return"";const s=Date.now()-t,o=Math.floor(s/6e4);if(o<1)return"now";if(o<60)return`${o}m`;const l=Math.floor(o/60);return l<24?`${l}h`:`${Math.floor(l/24)}d`}const Md="__super_agent__";function zI({pid:e}){const t=ot(),[s]=$c(),o=We(`/projects/${e}/agents`,()=>on.list(e)),[l,c]=x.useState(!1),[u,p]=x.useState(""),[m,g]=x.useState(null),{msgs:h,send:b,stop:v,clear:k,load:N,loadThread:j,streaming:y,conversationId:C}=SI(e,$=>t.error($)),S=ip(),E=s.get("agent"),[R,M]=x.useState(E?{kind:"live",agentSlug:E}:{kind:"live",agentSlug:Md}),T=o.data||[],O=$=>$===Md,D=x.useMemo(()=>R.kind==="thread"?void 0:T.find($=>$.slug===R.agentSlug),[T,R]),U=R.kind==="thread"||O(R.agentSlug);x.useEffect(()=>{R.kind==="conv"?N(R.agentSlug,R.convId):R.kind==="thread"?j(R.channel,R.threadId):k()},[R.kind,R.kind==="conv"?R.convId:R.kind==="thread"?`${R.channel}:${R.threadId}`:R.agentSlug]);const L=async $=>{if(U){await b($,{model:u||void 0});return}D&&await b($,{model:u||void 0,agentSlug:D.slug})},I=async $=>{try{await navigator.clipboard.writeText($),t.info(f("project.chat.copied"))}catch{}},z=()=>{M({kind:"live",agentSlug:Md}),k()},B=R.kind==="thread"?`${R.channel} · ${R.threadId}`:U?f("project.chat.superagent_title",{persona:S}):R.kind==="conv"?R.convId:f("project.chat.title"),H=R.kind==="thread"?f("project.chat.thread_subtitle",{channel:R.channel,persona:S}):U?f("project.chat.superagent_subtitle",{persona:S}):R.kind==="conv"?f("project.chat.loaded_subtitle",{slug:R.agentSlug}):f("project.chat.subtitle");return o.isLoading?r.jsx(rt,{}):r.jsxs("div",{className:"flex h-full overflow-hidden rounded-xl border border-border bg-card/40",children:[r.jsx(MI,{pid:e,agents:T,superAgentSlug:Md,superAgentLabel:f("agents_ui.super_agent_label",{persona:S}),selected:R,onSelect:M,onNewChat:z}),r.jsxs("section",{className:"flex min-w-0 flex-1 flex-col",children:[r.jsxs("header",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-border px-4 py-3",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("h2",{className:"truncate text-sm font-semibold",children:B}),r.jsx("p",{className:"truncate text-[11px] text-muted-fg",children:H})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[U?r.jsx($e,{tone:"success",children:f("agents_ui.super_agent_badge")}):D?.model&&r.jsx($e,{tone:"info",children:D.model}),R.kind==="conv"&&r.jsx($e,{tone:"info",children:C||"…"}),!T.length&&!U&&r.jsxs(ce,{variant:"primary",size:"sm",onClick:()=>c(!0),children:[r.jsx(an,{size:14})," ",f("project.chat.create_agent")]}),r.jsxs(ce,{variant:"ghost",size:"sm",disabled:y||h.length===0,onClick:z,children:[r.jsx(Zn,{size:13})," ",f("project.chat.clear")]})]})]}),r.jsx("div",{className:"flex-1 overflow-y-auto",children:h.length?r.jsx(b_,{msgs:h,onCopy:I}):r.jsx("div",{className:"flex h-full items-center justify-center p-8",children:r.jsx("p",{className:"text-sm text-muted-fg",children:f("project.chat.empty")})})}),r.jsx(NN,{msgs:h}),(()=>{const $=y?null:RN(h);return!$||$.turnKey===m?null:r.jsx(EN,{turnKey:$.turnKey,questions:$.questions,onSubmit:q=>void L(q),onDismiss:()=>g($.turnKey),disabled:y})})(),r.jsx(fI,{onSend:L,onStop:v,streaming:y,model:u,onModelChange:p})]}),r.jsx(DI,{open:l,pid:e,onClose:()=>c(!1),onCreated:()=>{c(!1),o.mutate()}})]})}function DI({open:e,onClose:t,onCreated:s,pid:o}){const l=ot(),[c,u]=x.useState(""),[p,m]=x.useState("master"),[g,h]=x.useState(""),[b,v]=x.useState(!0),[k,N]=x.useState(!1),j=async()=>{if(!/^[a-z][a-z0-9_-]*$/.test(c)){l.error(f("project.agents.slug_invalid"));return}N(!0);try{await on.create(o,{slug:c,role:p,model:g||void 0,is_master:b}),l.success(f("project.agents.created",{slug:c})),u(""),m("master"),h(""),v(!0),s()}catch(y){l.error(y.message)}finally{N(!1)}};return r.jsx(On,{open:e,onClose:t,title:f("project.chat.create_agent_title"),description:f("project.chat.create_agent_desc"),footer:r.jsxs(r.Fragment,{children:[r.jsx(ce,{variant:"ghost",onClick:t,disabled:k,children:f("common.cancel")}),r.jsx(ce,{variant:"primary",onClick:j,loading:k,children:f("common.create")})]}),children:r.jsxs("div",{className:"space-y-3",children:[r.jsx(le,{label:"slug",children:r.jsx(Ee,{autoFocus:!0,value:c,onChange:y=>u(y.target.value),placeholder:"master"})}),r.jsx(le,{label:f("project.chat.role_label"),children:r.jsx(Ee,{value:p,onChange:y=>m(y.target.value),placeholder:"master"})}),r.jsx(le,{label:f("project.chat.model_label"),hint:f("project.chat.model_hint"),children:r.jsx(Ee,{value:g,onChange:y=>h(y.target.value)})}),r.jsx(Qt,{checked:b,onChange:v,label:f("project.chat.master_label")})]})})}function LI({pid:e}){const t=ot(),{project:s}=Wb(e),{channels:o,isLoading:l,mutate:c}=a_(),u=String(e),p=s?.name||s?.path?.split("/").pop()||u,m=`proj-${u}`,g=o.find(O=>O.project===u||O.project===p||O.name===m),[h,b]=x.useState(!!g),[v,k]=x.useState(""),[N,j]=x.useState(""),[y,C]=x.useState(""),[S,E]=x.useState(!0),[R,M]=x.useState(!1);if(x.useEffect(()=>{g?(b(!0),k(""),j(g.chat_id||""),C(g.route_to_agent||""),E(g.respond_with_engine??!0)):(b(!1),k(""),j(""),C(""),E(!0))},[g?.name,g?.chat_id,g?.route_to_agent]),l)return r.jsx(rt,{});const T=async()=>{M(!0);try{if(!h){g&&(await An.channels.remove(g.name),t.success(f("project.telegram.cleared"))),await c();return}const O={name:g?.name||m,project:u,chat_id:N,route_to_agent:y,respond_with_engine:S,...v?{bot_token:v}:{}};g?await An.channels.patch(g.name,O):await An.channels.upsert(O),t.success(f("project.telegram.saved")),await c(),k("")}catch(O){t.error(O.message)}finally{M(!1)}};return r.jsx(Ye,{title:f("project.telegram.title"),description:f("project.telegram.subtitle"),children:r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(Qt,{checked:h,onChange:b,label:f(h?"project.telegram.override_active":"project.telegram.use_default")}),g&&r.jsx($e,{tone:"success",children:f("project.telegram.channel_badge",{name:g.name})})]}),h&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsx(le,{label:f("project.telegram.bot_token"),hint:g?.bot_token?`${Mr(g.bot_token)} ${f("telegram_ui.empty_keep")}`:f("project.telegram.bot_hint_none"),children:r.jsx(Ee,{type:"password",value:v,onChange:O=>k(O.target.value),placeholder:g?.bot_token?Mr(g.bot_token):""})}),r.jsx(le,{label:f("project.telegram.chat_id"),children:r.jsx(Ee,{value:N,onChange:O=>j(O.target.value)})}),r.jsx(le,{label:f("project.telegram.route_agent"),hint:f("project.telegram.route_hint"),children:r.jsx(Ee,{value:y,onChange:O=>C(O.target.value)})})]}),r.jsx(Qt,{checked:S,onChange:E,label:f("project.telegram.respond_engine")})]}),r.jsx("div",{className:"pt-2",children:r.jsx(ce,{variant:"primary",loading:R,onClick:T,children:f("common.save")})}),!h&&!g&&r.jsx(bt,{children:f("project.telegram.no_override")})]})})}function TN({load:e,save:t,rows:s=10,placeholder:o}){const l=ot(),[c,u]=x.useState(null),[p,m]=x.useState(""),[g,h]=x.useState(!1);if(x.useEffect(()=>{let k=!0;return e().then(N=>{k&&(u(N),m(N))}).catch(()=>{k&&(u(""),m(""))}),()=>{k=!1}},[e]),c===null)return r.jsx(rt,{});const b=p!==c,v=async()=>{h(!0);try{await t(p),u(p),l.success(f("project.memories.saved"))}catch(k){l.error(k.message)}finally{h(!1)}};return r.jsxs("div",{className:"space-y-2",children:[r.jsx(Mn,{rows:s,className:"font-mono text-xs",value:p,onChange:k=>m(k.target.value),placeholder:o}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("span",{className:"text-[11px] text-muted-fg",children:[p.length," ",f("project.memories.chars")]}),r.jsxs(ce,{size:"sm",variant:"primary",loading:g,disabled:!b,onClick:v,children:[r.jsx(zf,{size:12})," ",f("project.memories.save_btn")]})]})]})}function PI({pid:e,agent:t}){const[s,o]=x.useState(!1),l=t.is_master?Ga:dn;return r.jsxs("li",{className:"rounded-xl border border-border bg-muted/30",children:[r.jsxs("button",{type:"button",onClick:()=>o(c=>!c),className:"flex w-full items-center gap-3 px-3 py-2 text-left",children:[s?r.jsx(pa,{size:14,className:"text-muted-fg"}):r.jsx(Zl,{size:14,className:"text-muted-fg"}),r.jsx(l,{size:14,className:t.is_master?"text-violet-400":"text-muted-fg"}),r.jsx("span",{className:"text-sm font-medium",children:t.slug}),t.role&&r.jsxs("span",{className:"text-xs text-muted-fg",children:["· ",t.role]})]}),s&&r.jsx("div",{className:"border-t border-border p-3",children:r.jsx(TN,{rows:8,load:()=>on.memory.get(e,t.slug).then(c=>c.body),save:c=>on.memory.put(e,t.slug,c).then(()=>{})})})]})}function II({pid:e}){const t=We(`/projects/${e}/agents`,()=>on.list(e));return r.jsxs("div",{className:"space-y-6",children:[r.jsx(Ye,{title:f("project.memories.project_title"),description:f("project.memories.project_desc"),children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("div",{className:"mt-1 flex size-9 shrink-0 items-center justify-center rounded-xl bg-gradient-to-br from-sky-600 to-indigo-600",children:r.jsx(Xd,{className:"size-4 text-white"})}),r.jsx("div",{className:"min-w-0 flex-1",children:r.jsx(TN,{rows:12,load:()=>ls.memory.get(e).then(s=>s.body),save:s=>ls.memory.put(e,s).then(()=>{}),placeholder:f("project.memories.project_ph")})})]})}),r.jsxs(Ye,{title:f("project.memories.agents_title"),description:f("project.memories.agents_desc"),children:[t.isLoading&&r.jsx(rt,{}),!t.isLoading&&(t.data?.length??0)===0&&r.jsx(bt,{children:f("project.memories.no_agents")}),r.jsx("ul",{className:"space-y-2",children:(t.data||[]).map(s=>r.jsx(PI,{pid:e,agent:s},s.slug))})]})]})}function BI({pid:e,entry:t,onDeleted:s,onRenamed:o,onRunInTerminal:l,onEditArtifact:c}){const[u,p]=x.useState(!1),[m,g]=x.useState(null),h=ot(),[b,v]=x.useState(!1),[k,N]=x.useState(t.name),j=x.useRef(null),[y,C]=x.useState(!1),[S,E]=x.useState(!1),[R,M]=x.useState(!1),T=y?["artifact",e,t.name]:null,O=We(T,()=>Tr.read(e,t.name),{revalidateOnFocus:!1}),D=!O.data?.content||O.data.content.startsWith("#!"),U=async H=>{try{await navigator.clipboard.writeText(H),h.info(f("modules_ui.code_copied"))}catch{}},L=async()=>{p(!0),g(null);try{const H=await Tr.run(e,t.name);g(H),H.ok?h.info(f("modules_ui.code_artifact_exit_ok",{ms:H.durationMs??0})):h.error(f("modules_ui.code_artifact_exit_fail",{code:H.exitCode??H.signal??"?",timeout:H.timedOut?f("modules_ui.code_artifact_timeout_suffix"):""}))}catch(H){h.error(H.message)}finally{p(!1)}},I=async()=>{M(!0);try{await Tr.remove(e,t.name),E(!1),s()}catch(H){h.error(H.message)}finally{M(!1)}},z=()=>{N(t.name),v(!0),requestAnimationFrame(()=>j.current?.select())},B=async()=>{const H=k.trim();if(v(!1),!(!H||H===t.name))try{await Tr.rename(e,t.name,H),o()}catch($){h.error($.message)}};return r.jsxs("li",{className:"rounded-md border border-border",children:[r.jsxs("div",{className:"flex w-full items-center gap-2 px-2 py-1.5 text-xs",children:[r.jsx(Qd,{className:"size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400"}),b?r.jsx("input",{ref:j,value:k,onChange:H=>N(H.target.value),onBlur:()=>void B(),onKeyDown:H=>{H.key==="Enter"&&B(),H.key==="Escape"&&v(!1)},autoFocus:!0,className:"min-w-0 flex-1 rounded border border-border bg-background px-1 py-0.5 font-mono text-xs outline-none focus:ring-1 focus:ring-ring"}):r.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",children:t.name}),r.jsx(Ge,{content:f("code_module.artifacts_rename"),children:r.jsx("button",{type:"button",onClick:z,className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground",children:r.jsx(Ro,{className:"size-3"})})}),r.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-muted-foreground",children:[t.size,"b"]})]}),r.jsxs("div",{className:"space-y-2 border-t border-border p-2",children:[r.jsxs("div",{className:"flex w-full min-w-0 items-center gap-1 rounded bg-muted px-1.5 py-0.5",children:[r.jsx("code",{className:"min-w-0 flex-1 truncate font-mono text-[10px] text-muted-foreground",children:t.path}),r.jsx(Ge,{content:f("code_module.artifacts_copy_path"),children:r.jsx("button",{type:"button",onClick:()=>void U(t.path),className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground",children:r.jsx(Ec,{className:"size-3"})})})]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-1 mt-1",children:[r.jsxs(xx,{open:y,onOpenChange:C,children:[r.jsx(Ge,{content:f("code_module.artifacts_view"),children:r.jsxs("button",{type:"button",onClick:()=>C(!0),className:"inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] font-medium bg-blue-500/15 text-blue-700 hover:bg-blue-500/25 dark:text-blue-300",children:[r.jsx(Tf,{className:"size-3"}),f("modules_ui.code_artifact_view_short")]})}),r.jsxs(bx,{className:"sm:max-w-lg",children:[r.jsx(_x,{children:r.jsx(vx,{className:"font-mono text-sm",children:t.name})}),O.isLoading?r.jsx("div",{className:"flex justify-center py-6",children:r.jsx(us,{size:16})}):r.jsx("pre",{className:"max-h-96 overflow-auto rounded bg-muted/50 p-3 font-mono text-[11px] leading-tight whitespace-pre-wrap break-all",children:O.data?.content??""}),r.jsx(Yj,{showCloseButton:!0})]})]}),c&&r.jsx(Ge,{content:f("code_module.artifacts_edit"),children:r.jsxs("button",{type:"button",onClick:()=>c(t.name),className:"inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] font-medium bg-violet-500/15 text-violet-700 hover:bg-violet-500/25 dark:text-violet-300",children:[r.jsx(JM,{className:"size-3"}),f("modules_ui.code_artifact_edit_short")]})}),D&&r.jsx(Ge,{content:f("code_module.artifacts_run"),children:r.jsxs("button",{type:"button",disabled:u,onClick:()=>l?l(`apx artifact run ${t.name}`):void L(),className:"inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] font-medium bg-emerald-500/15 text-emerald-700 hover:bg-emerald-500/25 disabled:opacity-60 dark:text-emerald-300",children:[u?r.jsx(us,{size:10}):r.jsx(Yx,{className:"size-3"}),f("code_module.artifacts_run")]})}),r.jsxs(xx,{open:S,onOpenChange:E,children:[r.jsx(Ge,{content:f("code_module.artifacts_delete"),children:r.jsx("button",{type:"button",onClick:()=>E(!0),className:"ml-auto rounded p-1 text-rose-600 hover:bg-rose-50 dark:text-rose-400 dark:hover:bg-rose-950",children:r.jsx(Zn,{className:"size-3"})})}),r.jsxs(bx,{className:"sm:max-w-sm",children:[r.jsx(_x,{children:r.jsxs(vx,{className:"font-mono text-sm",children:[f("code_module.artifacts_delete")," — ",t.name]})}),r.jsx("p",{className:"px-1 text-sm text-muted-foreground",children:f("code_module.artifacts_delete_confirm")}),r.jsxs(Yj,{children:[r.jsx(PL,{render:r.jsx("button",{type:"button",className:"rounded px-3 py-1.5 text-xs font-medium hover:bg-accent"}),children:f("common.cancel")}),r.jsxs("button",{type:"button",onClick:()=>void I(),disabled:R,className:Te("inline-flex items-center gap-1.5 rounded px-3 py-1.5 text-xs font-medium",R?"bg-muted text-muted-foreground":"bg-rose-500/15 text-rose-700 hover:bg-rose-500/25 dark:text-rose-300"),children:[R&&r.jsx(us,{size:10}),f("code_module.delete")]})]})]})]})]}),r.jsxs("div",{className:"mt-1 text-[10px] text-muted-foreground",children:[f("code_module.artifacts_run_hint")," ",r.jsxs("code",{className:"rounded bg-muted px-1 font-mono",children:["apx artifact run ",t.name]})]}),m&&r.jsxs("div",{className:"space-y-1",children:[r.jsxs("div",{className:"flex items-center gap-2 text-[10px]",children:[r.jsx("span",{className:Te("rounded px-1.5 py-0.5 font-mono",m.ok?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300":"bg-rose-500/15 text-rose-700 dark:text-rose-300"),children:f("modules_ui.code_artifact_exit_badge",{code:m.exitCode??m.signal??"?"})}),m.timedOut&&r.jsx("span",{className:"rounded bg-amber-500/15 px-1.5 py-0.5 font-mono text-amber-700 dark:text-amber-300",children:f("modules_ui.code_artifact_timeout")}),m.truncated&&r.jsx("span",{className:"rounded bg-amber-500/15 px-1.5 py-0.5 font-mono text-amber-700 dark:text-amber-300",children:f("modules_ui.code_artifact_truncated")}),r.jsxs("span",{className:"font-mono text-muted-foreground",children:[m.durationMs,"ms"]})]}),m.stdout&&r.jsx("pre",{className:"max-h-32 overflow-auto rounded bg-background/60 p-2 text-[10px] leading-tight",children:m.stdout}),m.stderr&&r.jsx("pre",{className:"max-h-32 overflow-auto rounded bg-rose-500/5 p-2 text-[10px] leading-tight text-rose-700 dark:text-rose-300",children:m.stderr})]})]})]})}function AN({pid:e,onRunInTerminal:t,onEditArtifact:s}){const o=We(e?["artifacts",e]:null,()=>Tr.list(e)),l=o.data||[];return r.jsxs("div",{className:"flex h-full flex-col","data-testid":"code-artifacts-tab",children:[r.jsxs("div",{className:"flex shrink-0 items-center justify-between px-3 py-2",children:[r.jsx("span",{className:"text-[11px] text-muted-foreground",children:l.length>0?f("code_module.artifacts_count",{n:l.length}):""}),r.jsx(Ge,{content:f("code_module.reload"),children:r.jsx("button",{type:"button",onClick:()=>void o.mutate(),className:"rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground",children:o.isLoading?r.jsx(us,{size:12}):r.jsx(ua,{className:"size-3"})})})]}),r.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-3 pb-3",children:l.length===0?r.jsx(bt,{children:f("code_module.artifacts_none")}):r.jsx("ul",{className:"space-y-1.5",children:l.map(c=>r.jsx(BI,{pid:e,entry:c,onDeleted:()=>void o.mutate(),onRenamed:()=>void o.mutate(),onRunInTerminal:t,onEditArtifact:s},c.name))})})]})}function UI({pid:e}){const t=Gn(),s=o=>{const l=new URLSearchParams({pid:e,...o}).toString();t(`/m/code?${l}`)};return r.jsx(Ye,{title:f("project.artifacts.title"),description:f("project.artifacts.subtitle"),fullHeight:!0,className:"min-h-[24rem]",children:r.jsx(AN,{pid:e,onRunInTerminal:o=>s({cmd:o}),onEditArtifact:o=>s({edit:o})})})}function HI(e,t){var s,o=1;e==null&&(e=0),t==null&&(t=0);function l(){var c,u=s.length,p,m=0,g=0;for(c=0;c<u;++c)p=s[c],m+=p.x,g+=p.y;for(m=(m/u-e)*o,g=(g/u-t)*o,c=0;c<u;++c)p=s[c],p.x-=m,p.y-=g}return l.initialize=function(c){s=c},l.x=function(c){return arguments.length?(e=+c,l):e},l.y=function(c){return arguments.length?(t=+c,l):t},l.strength=function(c){return arguments.length?(o=+c,l):o},l}function VI(e){const t=+this._x.call(null,e),s=+this._y.call(null,e);return MN(this.cover(t,s),t,s,e)}function MN(e,t,s,o){if(isNaN(t)||isNaN(s))return e;var l,c=e._root,u={data:o},p=e._x0,m=e._y0,g=e._x1,h=e._y1,b,v,k,N,j,y,C,S;if(!c)return e._root=u,e;for(;c.length;)if((j=t>=(b=(p+g)/2))?p=b:g=b,(y=s>=(v=(m+h)/2))?m=v:h=v,l=c,!(c=c[C=y<<1|j]))return l[C]=u,e;if(k=+e._x.call(null,c.data),N=+e._y.call(null,c.data),t===k&&s===N)return u.next=c,l?l[C]=u:e._root=u,e;do l=l?l[C]=new Array(4):e._root=new Array(4),(j=t>=(b=(p+g)/2))?p=b:g=b,(y=s>=(v=(m+h)/2))?m=v:h=v;while((C=y<<1|j)===(S=(N>=v)<<1|k>=b));return l[S]=c,l[C]=u,e}function qI(e){var t,s,o=e.length,l,c,u=new Array(o),p=new Array(o),m=1/0,g=1/0,h=-1/0,b=-1/0;for(s=0;s<o;++s)isNaN(l=+this._x.call(null,t=e[s]))||isNaN(c=+this._y.call(null,t))||(u[s]=l,p[s]=c,l<m&&(m=l),l>h&&(h=l),c<g&&(g=c),c>b&&(b=c));if(m>h||g>b)return this;for(this.cover(m,g).cover(h,b),s=0;s<o;++s)MN(this,u[s],p[s],e[s]);return this}function $I(e,t){if(isNaN(e=+e)||isNaN(t=+t))return this;var s=this._x0,o=this._y0,l=this._x1,c=this._y1;if(isNaN(s))l=(s=Math.floor(e))+1,c=(o=Math.floor(t))+1;else{for(var u=l-s||1,p=this._root,m,g;s>e||e>=l||o>t||t>=c;)switch(g=(t<o)<<1|e<s,m=new Array(4),m[g]=p,p=m,u*=2,g){case 0:l=s+u,c=o+u;break;case 1:s=l-u,c=o+u;break;case 2:l=s+u,o=c-u;break;case 3:s=l-u,o=c-u;break}this._root&&this._root.length&&(this._root=p)}return this._x0=s,this._y0=o,this._x1=l,this._y1=c,this}function FI(){var e=[];return this.visit(function(t){if(!t.length)do e.push(t.data);while(t=t.next)}),e}function GI(e){return arguments.length?this.cover(+e[0][0],+e[0][1]).cover(+e[1][0],+e[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]}function Kn(e,t,s,o,l){this.node=e,this.x0=t,this.y0=s,this.x1=o,this.y1=l}function YI(e,t,s){var o,l=this._x0,c=this._y0,u,p,m,g,h=this._x1,b=this._y1,v=[],k=this._root,N,j;for(k&&v.push(new Kn(k,l,c,h,b)),s==null?s=1/0:(l=e-s,c=t-s,h=e+s,b=t+s,s*=s);N=v.pop();)if(!(!(k=N.node)||(u=N.x0)>h||(p=N.y0)>b||(m=N.x1)<l||(g=N.y1)<c))if(k.length){var y=(u+m)/2,C=(p+g)/2;v.push(new Kn(k[3],y,C,m,g),new Kn(k[2],u,C,y,g),new Kn(k[1],y,p,m,C),new Kn(k[0],u,p,y,C)),(j=(t>=C)<<1|e>=y)&&(N=v[v.length-1],v[v.length-1]=v[v.length-1-j],v[v.length-1-j]=N)}else{var S=e-+this._x.call(null,k.data),E=t-+this._y.call(null,k.data),R=S*S+E*E;if(R<s){var M=Math.sqrt(s=R);l=e-M,c=t-M,h=e+M,b=t+M,o=k.data}}return o}function KI(e){if(isNaN(h=+this._x.call(null,e))||isNaN(b=+this._y.call(null,e)))return this;var t,s=this._root,o,l,c,u=this._x0,p=this._y0,m=this._x1,g=this._y1,h,b,v,k,N,j,y,C;if(!s)return this;if(s.length)for(;;){if((N=h>=(v=(u+m)/2))?u=v:m=v,(j=b>=(k=(p+g)/2))?p=k:g=k,t=s,!(s=s[y=j<<1|N]))return this;if(!s.length)break;(t[y+1&3]||t[y+2&3]||t[y+3&3])&&(o=t,C=y)}for(;s.data!==e;)if(l=s,!(s=s.next))return this;return(c=s.next)&&delete s.next,l?(c?l.next=c:delete l.next,this):t?(c?t[y]=c:delete t[y],(s=t[0]||t[1]||t[2]||t[3])&&s===(t[3]||t[2]||t[1]||t[0])&&!s.length&&(o?o[C]=s:this._root=s),this):(this._root=c,this)}function XI(e){for(var t=0,s=e.length;t<s;++t)this.remove(e[t]);return this}function QI(){return this._root}function WI(){var e=0;return this.visit(function(t){if(!t.length)do++e;while(t=t.next)}),e}function ZI(e){var t=[],s,o=this._root,l,c,u,p,m;for(o&&t.push(new Kn(o,this._x0,this._y0,this._x1,this._y1));s=t.pop();)if(!e(o=s.node,c=s.x0,u=s.y0,p=s.x1,m=s.y1)&&o.length){var g=(c+p)/2,h=(u+m)/2;(l=o[3])&&t.push(new Kn(l,g,h,p,m)),(l=o[2])&&t.push(new Kn(l,c,h,g,m)),(l=o[1])&&t.push(new Kn(l,g,u,p,h)),(l=o[0])&&t.push(new Kn(l,c,u,g,h))}return this}function JI(e){var t=[],s=[],o;for(this._root&&t.push(new Kn(this._root,this._x0,this._y0,this._x1,this._y1));o=t.pop();){var l=o.node;if(l.length){var c,u=o.x0,p=o.y0,m=o.x1,g=o.y1,h=(u+m)/2,b=(p+g)/2;(c=l[0])&&t.push(new Kn(c,u,p,h,b)),(c=l[1])&&t.push(new Kn(c,h,p,m,b)),(c=l[2])&&t.push(new Kn(c,u,b,h,g)),(c=l[3])&&t.push(new Kn(c,h,b,m,g))}s.push(o)}for(;o=s.pop();)e(o.node,o.x0,o.y0,o.x1,o.y1);return this}function e8(e){return e[0]}function t8(e){return arguments.length?(this._x=e,this):this._x}function n8(e){return e[1]}function s8(e){return arguments.length?(this._y=e,this):this._y}function __(e,t,s){var o=new v_(t??e8,s??n8,NaN,NaN,NaN,NaN);return e==null?o:o.addAll(e)}function v_(e,t,s,o,l,c){this._x=e,this._y=t,this._x0=s,this._y0=o,this._x1=l,this._y1=c,this._root=void 0}function mw(e){for(var t={data:e.data},s=t;e=e.next;)s=s.next={data:e.data};return t}var Jn=__.prototype=v_.prototype;Jn.copy=function(){var e=new v_(this._x,this._y,this._x0,this._y0,this._x1,this._y1),t=this._root,s,o;if(!t)return e;if(!t.length)return e._root=mw(t),e;for(s=[{source:t,target:e._root=new Array(4)}];t=s.pop();)for(var l=0;l<4;++l)(o=t.source[l])&&(o.length?s.push({source:o,target:t.target[l]=new Array(4)}):t.target[l]=mw(o));return e};Jn.add=VI;Jn.addAll=qI;Jn.cover=$I;Jn.data=FI;Jn.extent=GI;Jn.find=YI;Jn.remove=KI;Jn.removeAll=XI;Jn.root=QI;Jn.size=WI;Jn.visit=ZI;Jn.visitAfter=JI;Jn.x=t8;Jn.y=s8;function ho(e){return function(){return e}}function Ar(e){return(e()-.5)*1e-6}function a8(e){return e.x+e.vx}function r8(e){return e.y+e.vy}function o8(e){var t,s,o,l=1,c=1;typeof e!="function"&&(e=ho(e==null?1:+e));function u(){for(var g,h=t.length,b,v,k,N,j,y,C=0;C<c;++C)for(b=__(t,a8,r8).visitAfter(p),g=0;g<h;++g)v=t[g],j=s[v.index],y=j*j,k=v.x+v.vx,N=v.y+v.vy,b.visit(S);function S(E,R,M,T,O){var D=E.data,U=E.r,L=j+U;if(D){if(D.index>v.index){var I=k-D.x-D.vx,z=N-D.y-D.vy,B=I*I+z*z;B<L*L&&(I===0&&(I=Ar(o),B+=I*I),z===0&&(z=Ar(o),B+=z*z),B=(L-(B=Math.sqrt(B)))/B*l,v.vx+=(I*=B)*(L=(U*=U)/(y+U)),v.vy+=(z*=B)*L,D.vx-=I*(L=1-L),D.vy-=z*L)}return}return R>k+L||T<k-L||M>N+L||O<N-L}}function p(g){if(g.data)return g.r=s[g.data.index];for(var h=g.r=0;h<4;++h)g[h]&&g[h].r>g.r&&(g.r=g[h].r)}function m(){if(t){var g,h=t.length,b;for(s=new Array(h),g=0;g<h;++g)b=t[g],s[b.index]=+e(b,g,t)}}return u.initialize=function(g,h){t=g,o=h,m()},u.iterations=function(g){return arguments.length?(c=+g,u):c},u.strength=function(g){return arguments.length?(l=+g,u):l},u.radius=function(g){return arguments.length?(e=typeof g=="function"?g:ho(+g),m(),u):e},u}function l8(e){return e.index}function gw(e,t){var s=e.get(t);if(!s)throw new Error("node not found: "+t);return s}function i8(e){var t=l8,s=b,o,l=ho(30),c,u,p,m,g,h=1;e==null&&(e=[]);function b(y){return 1/Math.min(p[y.source.index],p[y.target.index])}function v(y){for(var C=0,S=e.length;C<h;++C)for(var E=0,R,M,T,O,D,U,L;E<S;++E)R=e[E],M=R.source,T=R.target,O=T.x+T.vx-M.x-M.vx||Ar(g),D=T.y+T.vy-M.y-M.vy||Ar(g),U=Math.sqrt(O*O+D*D),U=(U-c[E])/U*y*o[E],O*=U,D*=U,T.vx-=O*(L=m[E]),T.vy-=D*L,M.vx+=O*(L=1-L),M.vy+=D*L}function k(){if(u){var y,C=u.length,S=e.length,E=new Map(u.map((M,T)=>[t(M,T,u),M])),R;for(y=0,p=new Array(C);y<S;++y)R=e[y],R.index=y,typeof R.source!="object"&&(R.source=gw(E,R.source)),typeof R.target!="object"&&(R.target=gw(E,R.target)),p[R.source.index]=(p[R.source.index]||0)+1,p[R.target.index]=(p[R.target.index]||0)+1;for(y=0,m=new Array(S);y<S;++y)R=e[y],m[y]=p[R.source.index]/(p[R.source.index]+p[R.target.index]);o=new Array(S),N(),c=new Array(S),j()}}function N(){if(u)for(var y=0,C=e.length;y<C;++y)o[y]=+s(e[y],y,e)}function j(){if(u)for(var y=0,C=e.length;y<C;++y)c[y]=+l(e[y],y,e)}return v.initialize=function(y,C){u=y,g=C,k()},v.links=function(y){return arguments.length?(e=y,k(),v):e},v.id=function(y){return arguments.length?(t=y,v):t},v.iterations=function(y){return arguments.length?(h=+y,v):h},v.strength=function(y){return arguments.length?(s=typeof y=="function"?y:ho(+y),N(),v):s},v.distance=function(y){return arguments.length?(l=typeof y=="function"?y:ho(+y),j(),v):l},v}var c8={value:()=>{}};function ON(){for(var e=0,t=arguments.length,s={},o;e<t;++e){if(!(o=arguments[e]+"")||o in s||/[\s.]/.test(o))throw new Error("illegal type: "+o);s[o]=[]}return new Fd(s)}function Fd(e){this._=e}function u8(e,t){return e.trim().split(/^|\s+/).map(function(s){var o="",l=s.indexOf(".");if(l>=0&&(o=s.slice(l+1),s=s.slice(0,l)),s&&!t.hasOwnProperty(s))throw new Error("unknown type: "+s);return{type:s,name:o}})}Fd.prototype=ON.prototype={constructor:Fd,on:function(e,t){var s=this._,o=u8(e+"",s),l,c=-1,u=o.length;if(arguments.length<2){for(;++c<u;)if((l=(e=o[c]).type)&&(l=d8(s[l],e.name)))return l;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++c<u;)if(l=(e=o[c]).type)s[l]=hw(s[l],e.name,t);else if(t==null)for(l in s)s[l]=hw(s[l],e.name,null);return this},copy:function(){var e={},t=this._;for(var s in t)e[s]=t[s].slice();return new Fd(e)},call:function(e,t){if((l=arguments.length-2)>0)for(var s=new Array(l),o=0,l,c;o<l;++o)s[o]=arguments[o+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(c=this._[e],o=0,l=c.length;o<l;++o)c[o].value.apply(t,s)},apply:function(e,t,s){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var o=this._[e],l=0,c=o.length;l<c;++l)o[l].value.apply(t,s)}};function d8(e,t){for(var s=0,o=e.length,l;s<o;++s)if((l=e[s]).name===t)return l.value}function hw(e,t,s){for(var o=0,l=e.length;o<l;++o)if(e[o].name===t){e[o]=c8,e=e.slice(0,o).concat(e.slice(o+1));break}return s!=null&&e.push({name:t,value:s}),e}var Yl=0,hc=0,ac=0,zN=1e3,wf,xc,kf=0,So=0,gp=0,Ic=typeof performance=="object"&&performance.now?performance:Date,DN=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function LN(){return So||(DN(f8),So=Ic.now()+gp)}function f8(){So=0}function Nx(){this._call=this._time=this._next=null}Nx.prototype=PN.prototype={constructor:Nx,restart:function(e,t,s){if(typeof e!="function")throw new TypeError("callback is not a function");s=(s==null?LN():+s)+(t==null?0:+t),!this._next&&xc!==this&&(xc?xc._next=this:wf=this,xc=this),this._call=e,this._time=s,Ex()},stop:function(){this._call&&(this._call=null,this._time=1/0,Ex())}};function PN(e,t,s){var o=new Nx;return o.restart(e,t,s),o}function p8(){LN(),++Yl;for(var e=wf,t;e;)(t=So-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Yl}function xw(){So=(kf=Ic.now())+gp,Yl=hc=0;try{p8()}finally{Yl=0,g8(),So=0}}function m8(){var e=Ic.now(),t=e-kf;t>zN&&(gp-=t,kf=e)}function g8(){for(var e,t=wf,s,o=1/0;t;)t._call?(o>t._time&&(o=t._time),e=t,t=t._next):(s=t._next,t._next=null,t=e?e._next=s:wf=s);xc=e,Ex(o)}function Ex(e){if(!Yl){hc&&(hc=clearTimeout(hc));var t=e-So;t>24?(e<1/0&&(hc=setTimeout(xw,e-Ic.now()-gp)),ac&&(ac=clearInterval(ac))):(ac||(kf=Ic.now(),ac=setInterval(m8,zN)),Yl=1,DN(xw))}}const h8=1664525,x8=1013904223,bw=4294967296;function b8(){let e=1;return()=>(e=(h8*e+x8)%bw)/bw}function _8(e){return e.x}function v8(e){return e.y}var y8=10,j8=Math.PI*(3-Math.sqrt(5));function w8(e){var t,s=1,o=.001,l=1-Math.pow(o,1/300),c=0,u=.6,p=new Map,m=PN(b),g=ON("tick","end"),h=b8();e==null&&(e=[]);function b(){v(),g.call("tick",t),s<o&&(m.stop(),g.call("end",t))}function v(j){var y,C=e.length,S;j===void 0&&(j=1);for(var E=0;E<j;++E)for(s+=(c-s)*l,p.forEach(function(R){R(s)}),y=0;y<C;++y)S=e[y],S.fx==null?S.x+=S.vx*=u:(S.x=S.fx,S.vx=0),S.fy==null?S.y+=S.vy*=u:(S.y=S.fy,S.vy=0);return t}function k(){for(var j=0,y=e.length,C;j<y;++j){if(C=e[j],C.index=j,C.fx!=null&&(C.x=C.fx),C.fy!=null&&(C.y=C.fy),isNaN(C.x)||isNaN(C.y)){var S=y8*Math.sqrt(.5+j),E=j*j8;C.x=S*Math.cos(E),C.y=S*Math.sin(E)}(isNaN(C.vx)||isNaN(C.vy))&&(C.vx=C.vy=0)}}function N(j){return j.initialize&&j.initialize(e,h),j}return k(),t={tick:v,restart:function(){return m.restart(b),t},stop:function(){return m.stop(),t},nodes:function(j){return arguments.length?(e=j,k(),p.forEach(N),t):e},alpha:function(j){return arguments.length?(s=+j,t):s},alphaMin:function(j){return arguments.length?(o=+j,t):o},alphaDecay:function(j){return arguments.length?(l=+j,t):+l},alphaTarget:function(j){return arguments.length?(c=+j,t):c},velocityDecay:function(j){return arguments.length?(u=1-j,t):1-u},randomSource:function(j){return arguments.length?(h=j,p.forEach(N),t):h},force:function(j,y){return arguments.length>1?(y==null?p.delete(j):p.set(j,N(y)),t):p.get(j)},find:function(j,y,C){var S=0,E=e.length,R,M,T,O,D;for(C==null?C=1/0:C*=C,S=0;S<E;++S)O=e[S],R=j-O.x,M=y-O.y,T=R*R+M*M,T<C&&(D=O,C=T);return D},on:function(j,y){return arguments.length>1?(g.on(j,y),t):g.on(j)}}}function k8(){var e,t,s,o,l=ho(-30),c,u=1,p=1/0,m=.81;function g(k){var N,j=e.length,y=__(e,_8,v8).visitAfter(b);for(o=k,N=0;N<j;++N)t=e[N],y.visit(v)}function h(){if(e){var k,N=e.length,j;for(c=new Array(N),k=0;k<N;++k)j=e[k],c[j.index]=+l(j,k,e)}}function b(k){var N=0,j,y,C=0,S,E,R;if(k.length){for(S=E=R=0;R<4;++R)(j=k[R])&&(y=Math.abs(j.value))&&(N+=j.value,C+=y,S+=y*j.x,E+=y*j.y);k.x=S/C,k.y=E/C}else{j=k,j.x=j.data.x,j.y=j.data.y;do N+=c[j.data.index];while(j=j.next)}k.value=N}function v(k,N,j,y){if(!k.value)return!0;var C=k.x-t.x,S=k.y-t.y,E=y-N,R=C*C+S*S;if(E*E/m<R)return R<p&&(C===0&&(C=Ar(s),R+=C*C),S===0&&(S=Ar(s),R+=S*S),R<u&&(R=Math.sqrt(u*R)),t.vx+=C*k.value*o/R,t.vy+=S*k.value*o/R),!0;if(k.length||R>=p)return;(k.data!==t||k.next)&&(C===0&&(C=Ar(s),R+=C*C),S===0&&(S=Ar(s),R+=S*S),R<u&&(R=Math.sqrt(u*R)));do k.data!==t&&(E=c[k.data.index]*o/R,t.vx+=C*E,t.vy+=S*E);while(k=k.next)}return g.initialize=function(k,N){e=k,s=N,h()},g.strength=function(k){return arguments.length?(l=typeof k=="function"?k:ho(+k),h(),g):l},g.distanceMin=function(k){return arguments.length?(u=k*k,g):Math.sqrt(u)},g.distanceMax=function(k){return arguments.length?(p=k*k,g):Math.sqrt(p)},g.theta=function(k){return arguments.length?(m=k*k,g):Math.sqrt(m)},g}const rc={agent:"#a78bfa",memory:"#38bdf8",thread:"#34d399",task:"#fbbf24",routine:"#f472b6",agentlink:"#c084fc"};function S8(){return{agent:f("agents_ui.kind_agent"),memory:f("agents_ui.kind_memory"),thread:f("agents_ui.kind_thread"),task:f("agents_ui.kind_task"),routine:f("agents_ui.kind_routine"),agentlink:f("agents_ui.kind_hierarchy")}}const oc=760,lc=460;function C8({center:e,nodes:t}){const s=x.useRef(null),o=x.useRef(null),l=x.useRef([]),c=x.useRef([]),u=x.useRef(null),[,p]=x.useState(0),[m,g]=x.useState(null);x.useEffect(()=>{const y={id:"__center",label:e,kind:"agent",relation:"self",x:oc/2,y:lc/2,fx:oc/2,fy:lc/2},C=[y,...t.map(R=>({...R}))],S=C.slice(1).map(R=>({source:y,target:R}));l.current=C,c.current=S;const E=w8(C).force("link",i8(S).distance(120).strength(.5)).force("charge",k8().strength(-220)).force("center",HI(oc/2,lc/2).strength(.05)).force("collide",o8(26)).on("tick",()=>p(R=>R+1));return o.current=E,()=>{E.stop()}},[e,t]);const h=y=>{const C=s.current.getBoundingClientRect();return{x:(y.clientX-C.left)/C.width*oc,y:(y.clientY-C.top)/C.height*lc}},b=y=>C=>{y.id!=="__center"&&(u.current=y,C.target.setPointerCapture?.(C.pointerId),o.current?.alphaTarget(.3).restart())},v=y=>{const C=u.current;if(!C)return;const{x:S,y:E}=h(y);C.fx=S,C.fy=E},k=()=>{const y=u.current;y&&(y.fx=null,y.fy=null),u.current=null,o.current?.alphaTarget(0)},N=l.current,j=c.current;return r.jsxs("div",{className:"space-y-3",children:[r.jsx("div",{className:"overflow-hidden rounded-xl border border-border bg-muted/10",children:r.jsxs("svg",{ref:s,viewBox:`0 0 ${oc} ${lc}`,className:"h-[460px] w-full touch-none select-none",onPointerMove:v,onPointerUp:k,onPointerLeave:k,children:[j.map((y,C)=>r.jsx("line",{x1:y.source.x,y1:y.source.y,x2:y.target.x,y2:y.target.y,stroke:rc[y.target.kind],strokeOpacity:.22,strokeWidth:1.5},C)),N.map(y=>{if(y.id==="__center")return r.jsxs("g",{transform:`translate(${y.x},${y.y})`,children:[r.jsx("circle",{r:22,fill:rc.agent}),r.jsx("text",{textAnchor:"middle",y:4,fontSize:11,fontWeight:700,fill:"#1a1a1a",children:e.length>8?e.slice(0,8):e})]},y.id);const C=m?.id===y.id;return r.jsxs("g",{transform:`translate(${y.x},${y.y})`,className:"cursor-grab active:cursor-grabbing",onPointerDown:b(y),onClick:()=>g(y),children:[r.jsx("circle",{r:C?9:6,fill:rc[y.kind],fillOpacity:C?1:.9,stroke:C?"#fff":"none",strokeWidth:C?2:0}),r.jsx("text",{x:10,y:4,fontSize:10,className:"fill-foreground/80",children:y.label.length>22?`${y.label.slice(0,22)}…`:y.label})]},y.id)})]})}),r.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-[11px] text-muted-fg",children:[(()=>{const y=S8();return Object.keys(y).filter(C=>C!=="agent").map(C=>r.jsxs("span",{className:"inline-flex items-center gap-1",children:[r.jsx("span",{className:"size-2 rounded-full",style:{background:rc[C]}})," ",y[C]]},C))})(),r.jsx("span",{className:"ml-auto",children:f("agents_ui.nodes_drag_hint",{n:String(t.length)})})]}),m&&r.jsxs("div",{className:"rounded-lg border border-border bg-card p-3 text-xs",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"size-2 rounded-full",style:{background:rc[m.kind]}}),r.jsx("span",{className:"font-medium",children:m.label}),r.jsxs("span",{className:"text-muted-fg",children:["· ",m.relation]})]}),m.detail&&r.jsx("p",{className:"mt-1 whitespace-pre-wrap text-muted-fg",children:m.detail})]})]})}function N8(){return[{key:"overview",label:f("agents_ui.tab_explorer"),icon:Mf},{key:"memories",label:f("project.nav.memories"),icon:Xd},{key:"records",label:f("project.agent_detail.records_title"),icon:Fk},{key:"sleep",label:f("project.agent_detail.sleep_title"),icon:Ll},{key:"brain",label:f("project.agent_detail.brain_title"),icon:ma},{key:"config",label:f("settings.tabs.advanced"),icon:Rc}]}function E8(){return[{value:"",label:f("agents_ui.type_none")},{value:"orchestrator",label:f("agents_ui.type_orchestrator"),description:f("agents_ui.type_orchestrator_desc")},{value:"specialist",label:f("agents_ui.type_specialist"),description:f("agents_ui.type_specialist_desc")},{value:"assistant",label:f("agents_ui.type_assistant"),description:f("agents_ui.type_assistant_desc")},{value:"worker",label:f("agents_ui.type_worker"),description:f("agents_ui.type_worker_desc")},{value:"monitor",label:f("agents_ui.type_monitor"),description:f("agents_ui.type_monitor_desc")}]}const Rx=e=>e.split(",").map(t=>t.trim()).filter(Boolean),R8=(e,t)=>e.filter(s=>s.spec?.agent===t||t==="super-agent"&&s.kind==="super_agent");function T8(e){return e.split(`
638
- `).map(t=>t.replace(/^[-*#>\s]+/,"").trim()).filter(t=>t.length>2&&!t.startsWith("```")).slice(0,12)}function A8({pid:e}){const{slug:t=""}=Lk(),s=Gn(),[o,l]=x.useState("overview"),c=N8(),u=We(`/projects/${e}/agents/${t}`,()=>on.get(e,t)),p=We(`/projects/${e}/agents`,()=>on.list(e)),m=We(`/projects/${e}/routines`,()=>Cr.list(e)),g=We(`/projects/${e}/messages?agent=${t}`,()=>hf.project(e,{agent:t,limit:200})),h=We(`/projects/${e}/agents/${t}/conversations`,()=>Dc.list(e,t)),b=We(`/projects/${e}/tasks?all`,()=>Nr.list(e,"all")),v=u.data,k=R8(m.data||[],t),N=(b.data||[]).filter(C=>C.agent===t),j=(p.data||[]).filter(C=>C.parent===t);if(u.isLoading)return r.jsx(rt,{});if(!v)return r.jsx("div",{className:"text-sm text-muted-fg",children:f("project.agent_detail.not_found")});const y=v.is_master?Ga:dn;return r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-start justify-between gap-3",children:[r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("button",{onClick:()=>s(`/p/${e}/agents`),className:"mt-1 text-muted-fg hover:text-foreground",children:r.jsx(cM,{size:16})}),r.jsx("div",{className:Te("flex size-11 items-center justify-center rounded-xl bg-gradient-to-br",v.is_master?"from-violet-600 to-indigo-600":"from-slate-600 to-gray-600"),children:r.jsx(y,{className:"size-5 text-white"})}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx("h1",{className:"text-lg font-semibold",children:v.slug}),v.is_master&&r.jsxs($e,{tone:"success",children:[r.jsx(Ga,{size:10})," ",f("project.agents.orchestrator")]}),v.role&&r.jsx($e,{children:v.role}),v.model&&r.jsx($e,{tone:"info",children:v.model}),v.parent&&r.jsxs("button",{onClick:()=>s(`/p/${e}/agents/${v.parent}`),className:"text-[11px] text-violet-400 hover:underline",children:[f("project.agent_detail.reports_to")," ",v.parent]})]}),v.description&&r.jsx("p",{className:"mt-0.5 max-w-2xl text-xs text-muted-fg",children:v.description})]})]}),r.jsxs(ce,{size:"sm",variant:"primary",onClick:()=>s(`/p/${e}/chat?agent=${t}`),children:[r.jsx(Gs,{size:13})," ",f("project.agent_detail.chat_btn",{slug:v.slug})]})]}),r.jsx("div",{className:"flex flex-wrap gap-1 border-b border-border",children:c.map(({key:C,label:S,icon:E})=>r.jsxs("button",{onClick:()=>l(C),className:Te("flex items-center gap-1.5 border-b-2 px-3 py-2 text-sm transition-colors -mb-px",o===C?"border-foreground text-foreground":"border-transparent text-muted-fg hover:text-foreground"),children:[r.jsx(E,{size:14})," ",S]},C))}),o==="overview"&&r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[r.jsx(Od,{label:f("agents_ui.stat_threads"),value:h.data?.length??0,icon:Zd}),r.jsx(Od,{label:f("agents_ui.stat_records"),value:g.data?.length??0,icon:Fk}),r.jsx(Od,{label:f("agents_ui.stat_tasks"),value:N.length,icon:Mf}),r.jsx(Od,{label:f("agents_ui.stat_heartbeats"),value:k.length,icon:Ll})]}),r.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[r.jsx(Ye,{title:f("agent_detail_extra.skills_title"),description:"",children:r.jsxs("div",{className:"flex flex-wrap gap-1",children:[v.skills?.map(C=>r.jsxs($e,{tone:"info",children:[r.jsx(ma,{size:10})," ",C]},C)),v.tools?.map(C=>r.jsxs($e,{children:[r.jsx(Jl,{size:10})," ",C]},C)),!v.skills?.length&&!v.tools?.length&&r.jsx("span",{className:"text-xs text-muted-fg",children:"—"})]})}),r.jsx(Ye,{title:f("project.agent_detail.threads_recent"),description:"",children:r.jsxs("ul",{className:"space-y-1 text-xs",children:[(h.data||[]).slice(0,6).map(C=>r.jsxs("li",{className:"flex items-center justify-between rounded-md bg-muted/30 px-2 py-1",children:[r.jsx("span",{className:"truncate",children:C.title||C.filename}),r.jsxs("span",{className:"shrink-0 text-muted-fg",children:[C.messages??0," ",f("project.agent_detail.msgs_count")]})]},C.id)),!h.data?.length&&r.jsx("li",{className:"text-muted-fg",children:f("project.agent_detail.no_threads")})]})})]}),j.length>0&&r.jsx(Ye,{title:f("project.agent_detail.subagents"),description:f("project.agent_detail.subagents_desc"),children:r.jsx("div",{className:"flex flex-wrap gap-2",children:j.map(C=>r.jsxs("button",{onClick:()=>s(`/p/${e}/agents/${C.slug}`),className:"flex items-center gap-2 rounded-lg border border-border bg-muted/30 px-3 py-1.5 text-sm hover:border-muted-fg/50",children:[r.jsx(dn,{size:14,className:"text-muted-fg"})," ",C.slug]},C.slug))})})]}),o==="memories"&&r.jsx(O8,{pid:e,slug:t,initial:v.memory||"",onSaved:()=>u.mutate()}),o==="records"&&r.jsx(z8,{records:g.data||[],loading:g.isLoading}),o==="sleep"&&r.jsx(D8,{routines:k}),o==="brain"&&r.jsx(P8,{slug:t,memory:v.memory||"",threads:(h.data||[]).map(C=>({id:C.id,label:C.title||C.filename})),tasks:N.map(C=>({id:C.id,label:C.title,detail:C.body||void 0})),routines:k,parent:v.parent||null,children:j.map(C=>C.slug)}),o==="config"&&r.jsx(M8,{pid:e,agent:v,agents:p.data||[],onSaved:()=>{u.mutate(),p.mutate()},onDeleted:()=>{p.mutate(),s(`/p/${e}/agents`)}})]})}function M8({pid:e,agent:t,agents:s,onSaved:o,onDeleted:l}){const c=ot(),[u,p]=x.useState(t.type||""),[m,g]=x.useState(t.area||""),[h,b]=x.useState(t.role||""),[v,k]=x.useState(t.model||""),[N,j]=x.useState(t.parent||""),[y,C]=x.useState(!!t.is_master),[S,E]=x.useState((t.skills||[]).join(", ")),[R,M]=x.useState((t.tools||[]).join(", ")),[T,O]=x.useState(t.description||""),[D,U]=x.useState(t.system||""),[L,I]=x.useState(!1),z=async()=>{I(!0);try{await on.update(e,t.slug,{type:u||null,area:m||null,role:h||null,model:v||null,parent:N||null,is_master:y||u==="orchestrator",skills:Rx(S),tools:Rx(R),description:T||null,system:D}),c.success(f("project.agent_detail.update_success")),o()}catch(H){c.error(H.message)}finally{I(!1)}},B=async()=>{if(confirm(f("project.agent_detail.delete_confirm",{slug:t.slug})))try{await on.remove(e,t.slug),c.success(f("project.agent_detail.delete_success")),l()}catch(H){c.error(H.message)}};return r.jsx(Ye,{title:f("project.agent_detail.config_title"),description:`.apc/agents/${t.slug}.md — ${f("agents_ui.config_def_desc")}`,children:r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsx(le,{label:f("project.agent_detail.type_label"),children:r.jsx(_t,{value:u,onChange:p,options:E8()})}),r.jsx(le,{label:f("project.agent_detail.area_label"),hint:f("project.agent_detail.area_hint"),children:r.jsx(Ee,{value:m,onChange:H=>g(H.target.value),placeholder:f("project.agent_detail.area_ph")})})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsx(le,{label:f("project.agent_detail.role_label"),children:r.jsx(Ee,{value:h,onChange:H=>b(H.target.value),placeholder:"Operations Lead"})}),r.jsx(le,{label:f("project.agent_detail.parent_label"),children:r.jsx(_t,{value:N,onChange:j,placeholder:f("project.agent_detail.none_parent"),options:[{value:"",label:f("project.agent_detail.none_parent")},...s.filter(H=>H.slug!==t.slug).map(H=>({value:H.slug,label:H.slug}))]})})]}),r.jsx(le,{label:f("project.agent_detail.model_label"),hint:f("project.agent_detail.model_hint"),children:r.jsx(Ee,{value:v,onChange:H=>k(H.target.value),placeholder:f("project.agent_detail.model_ph")})}),r.jsx(le,{label:f("project.agent_detail.skills_label"),children:r.jsx(Ee,{value:S,onChange:H=>E(H.target.value),placeholder:"skill-a, skill-b"})}),r.jsx(L8,{value:R,onChange:M}),r.jsx(le,{label:f("project.agent_detail.bio_label"),children:r.jsx(Mn,{rows:2,value:T,onChange:H=>O(H.target.value)})}),r.jsx(le,{label:f("project.agent_detail.system_label"),hint:f("project.agent_detail.system_hint"),children:r.jsx(Mn,{rows:10,className:"font-mono text-xs",value:D,onChange:H=>U(H.target.value),placeholder:"You are…"})}),r.jsx(Qt,{checked:y,onChange:C,label:f("project.agent_detail.master_label")}),r.jsxs("div",{className:"flex items-center justify-between border-t border-border pt-3",children:[r.jsxs(ce,{variant:"destructive",onClick:B,children:[r.jsx(Zn,{size:13})," ",f("project.agent_detail.delete_btn")]}),r.jsxs(ce,{variant:"primary",loading:L,onClick:z,children:[r.jsx(zf,{size:13})," ",f("project.agent_detail.save_btn")]})]})]})})}function Od({label:e,value:t,icon:s}){return r.jsxs("div",{className:"rounded-xl border border-border bg-muted/30 p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-fg",children:[r.jsx(s,{size:13})," ",e]}),r.jsx("div",{className:"mt-1 text-2xl font-semibold",children:t})]})}function O8({pid:e,slug:t,initial:s,onSaved:o}){const l=ot(),[c,u]=x.useState(s),[p,m]=x.useState(!1);x.useEffect(()=>{u(s)},[s]);const g=c!==s,h=async()=>{m(!0);try{await on.memory.put(e,t,c),l.success(f("project.agent_detail.memory_saved")),o()}catch(b){l.error(b.message)}finally{m(!1)}};return r.jsxs(Ye,{title:f("project.agent_detail.memory_title"),description:`~/.apx/projects/<id>/agents/${t}/memory.md — ${f("agents_ui.memory_durable_desc")}`,children:[r.jsx(Mn,{rows:16,className:"font-mono text-xs",value:c,onChange:b=>u(b.target.value),placeholder:f("project.agent_detail.memory_empty")}),r.jsxs("div",{className:"mt-2 flex items-center justify-between",children:[r.jsxs("span",{className:"text-[11px] text-muted-fg",children:[c.length," ",f("project.memories.chars")]}),r.jsxs(ce,{size:"sm",variant:"primary",loading:p,disabled:!g,onClick:h,children:[r.jsx(zf,{size:12})," ",f("project.memories.save_btn")]})]})]})}function z8({records:e,loading:t}){const s=x.useMemo(()=>[...e].sort((o,l)=>(l.ts||"").localeCompare(o.ts||"")),[e]);return r.jsxs(Ye,{title:f("project.agent_detail.records_title"),description:f("project.agent_detail.records_desc"),children:[t&&r.jsx(rt,{}),!t&&s.length===0&&r.jsx("p",{className:"text-xs text-muted-fg",children:f("project.agent_detail.no_activity")}),r.jsx("ul",{className:"space-y-1 text-sm",children:s.map((o,l)=>r.jsxs("li",{className:"flex items-start gap-2 rounded-md border border-border bg-muted/30 px-3 py-2",children:[r.jsx("span",{className:"mt-0.5 shrink-0",children:o.direction==="in"?r.jsx(Gk,{size:13,className:"text-blue-400"}):r.jsx(Kk,{size:13,className:"text-emerald-400"})}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] text-muted-fg",children:[r.jsx("span",{className:"font-mono",children:new Date(o.ts).toLocaleString()}),r.jsx($e,{tone:"info",children:o.channel}),o.type&&r.jsx($e,{children:o.type})]}),o.body&&r.jsx("p",{className:"mt-1 whitespace-pre-wrap break-words text-xs",children:o.body.length>400?`${o.body.slice(0,400)}…`:o.body})]})]},`${o.ts}-${l}`))})]})}function D8({routines:e}){return e.length===0?r.jsx(Ye,{title:f("project.agent_detail.sleep_title"),description:f("project.agent_detail.sleep_desc"),children:r.jsxs("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 p-4 text-sm",children:[r.jsx("div",{className:"font-medium text-amber-400",children:f("project.agent_detail.sleep_deep")}),r.jsx("p",{className:"mt-1 text-xs text-muted-fg",children:f("project.agent_detail.sleep_deep_desc")})]})}):r.jsx(Ye,{title:f("project.agent_detail.sleep_title"),description:f("project.agent_detail.sleep_desc"),children:r.jsx("div",{className:"space-y-3",children:e.map(t=>{const s=t.enabled,o=t.last_status==="error";return r.jsxs("div",{className:"rounded-xl border border-border bg-muted/30 p-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:Te("size-2 rounded-full",o?"bg-destructive":s?"bg-emerald-400":"bg-muted-fg/40")}),r.jsx("span",{className:"text-sm font-medium",children:t.name}),r.jsx($e,{tone:s?"success":"muted",children:f(s?"agents_ui.running":"agents_ui.paused")}),o&&r.jsx($e,{tone:"danger",children:f("agents_ui.last_error")})]}),r.jsxs("div",{className:"mt-2 grid grid-cols-2 gap-2 text-xs sm:grid-cols-4",children:[r.jsx(zd,{label:f("agents_ui.field_tick"),value:t.schedule}),r.jsx(zd,{label:f("agents_ui.field_next_tick"),value:t.next_run_at?new Date(t.next_run_at).toLocaleString():"—"}),r.jsx(zd,{label:f("agents_ui.field_last_tick"),value:t.last_run_at?new Date(t.last_run_at).toLocaleString():"—"}),r.jsx(zd,{label:f("agents_ui.field_last_run"),value:t.last_status||"—"})]}),t.last_error&&r.jsx("p",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1 text-[11px] text-destructive",children:t.last_error})]},t.name)})})})}function zd({label:e,value:t}){return r.jsxs("div",{className:"rounded-md border border-border bg-card p-2",children:[r.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-fg",children:e}),r.jsx("div",{className:"mt-0.5 truncate font-mono text-[11px]",children:t})]})}function L8({value:e,onChange:t}){const s=We("/tools",()=>GD.list()),o=Rx(e),l=s.data||[],c=p=>{const m=new Set(o);m.has(p)?m.delete(p):m.add(p),t([...m].join(", "))},u=o.filter(p=>!l.some(m=>m.name===p));return r.jsxs(le,{label:f("agents_ui.tools_label"),hint:f("project.agent_detail.tools_hint"),children:[r.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[l.map(p=>{const m=o.includes(p.name);return r.jsx(Ge,{content:p.description||p.name,children:r.jsx("button",{type:"button",onClick:()=>c(p.name),className:Te("rounded-md border px-2 py-0.5 font-mono text-[11px] transition-colors",m?"border-emerald-500/50 bg-emerald-500/10 text-emerald-400":"border-border text-muted-fg hover:text-foreground"),children:p.name})},p.name)}),u.map(p=>r.jsxs("button",{type:"button",onClick:()=>c(p),className:"rounded-md border border-sky-500/50 bg-sky-500/10 px-2 py-0.5 font-mono text-[11px] text-sky-400",children:[p," ✕"]},p))]}),r.jsx(Ee,{className:"mt-2",value:e,onChange:p=>t(p.target.value),placeholder:f("project.agent_detail.tools_custom_ph")})]})}function P8({slug:e,memory:t,threads:s,tasks:o,routines:l,parent:c,children:u}){const p=x.useMemo(()=>{const m=[];return T8(t).forEach((g,h)=>m.push({id:`m${h}`,label:g,kind:"memory",relation:"knows",detail:g})),s.slice(0,8).forEach(g=>m.push({id:`th-${g.id}`,label:g.label,kind:"thread",relation:"in_thread"})),o.slice(0,8).forEach(g=>m.push({id:`ts-${g.id}`,label:g.label,kind:"task",relation:"handles_task",detail:g.detail})),l.forEach(g=>m.push({id:`rt-${g.name}`,label:g.name,kind:"routine",relation:"ticks",detail:`schedule: ${g.schedule}`})),c&&m.push({id:`p-${c}`,label:c,kind:"agentlink",relation:"reports_to"}),u.forEach(g=>m.push({id:`c-${g}`,label:g,kind:"agentlink",relation:"orchestrates"})),m},[t,s,o,l,c,u]);return r.jsx(Ye,{title:f("project.agent_detail.brain_title"),description:f("project.agent_detail.brain_desc"),children:p.length===0?r.jsx("p",{className:"text-xs text-muted-fg",children:f("project.agent_detail.brain_empty")}):r.jsx(C8,{center:e,nodes:p})})}function I8(){const e=Gn(),t=Wn(),{pid:s=""}=Lk(),{project:o}=Wb(s),{collapsed:l,toggle:c}=Yb(Tn.sidebarCollapsed+".project"),u=String(s)==="0",p=x.useMemo(()=>u?[{title:f("base.nav_general"),items:[{key:"",label:"Dashboard",icon:VM},{key:"workspaces",label:f("base.workspaces_title"),icon:pM},{key:"models",label:f("settings.tabs.engines"),icon:qx},{key:"agent-defaults",label:f("base.defaults_title"),icon:dn}]},{title:f("base.nav_activity"),items:[{key:"chat",label:f("project.nav.chat"),icon:Zd},{key:"sessions",label:f("base.sessions_title"),icon:IM},{key:"tasks",label:f("project.nav.tasks"),icon:Pl},{key:"logs",label:f("project.nav.logs"),icon:Jd}]},{title:f("base.nav_system"),items:[{key:"agents",label:f("project.nav.agents"),icon:dn},{key:"memories",label:f("project.nav.memories"),icon:Xd},{key:"routines",label:f("project.nav.routines"),icon:Ll},{key:"mcps",label:f("project.nav.mcps"),icon:Yh},{key:"artifacts",label:f("project.nav.artifacts"),icon:Qd},{key:"vars",label:f("project.nav.vars"),icon:Gh},{key:"config",label:f("project.nav.config"),icon:Rc}]}]:[{title:f("project.sections.workspace"),items:[{key:"",label:f("project.nav.overview"),icon:Jk},{key:"telegram",label:f("project.nav.telegram"),icon:Gs},{key:"chat",label:f("project.nav.chat"),icon:Zd},{key:"agents",label:f("project.nav.agents"),icon:dn},{key:"memories",label:f("project.nav.memories"),icon:Xd}]},{title:f("project.sections.automation"),items:[{key:"routines",label:f("project.nav.routines"),icon:Ll},{key:"tasks",label:f("project.nav.tasks"),icon:Pl},{key:"mcps",label:f("project.nav.mcps"),icon:Yh},{key:"artifacts",label:f("project.nav.artifacts"),icon:Qd},{key:"vars",label:f("project.nav.vars"),icon:Gh},{key:"logs",label:f("project.nav.logs"),icon:Jd}]},{title:f("project.sections.config"),items:[{key:"config",label:f("project.nav.config"),icon:Rc}]}],[u]),m=t.pathname.replace(`/p/${s}`,"").replace(/^\//,"").split("/")[0];if(!o)return r.jsx(ZC,{testId:"screen-project-not-found",mood:"confused",message:f("project.not_found",{pid:s}),action:r.jsx(Wa,{variant:"outline",onClick:()=>e("/"),children:f("not_found.home")})});const g=h=>{const b=h?`/p/${s}/${h}`:`/p/${s}`;e(b)};return r.jsx(QC,{sections:p,active:m,onChange:g,collapsed:l,onToggleCollapse:c,contentClassName:"w-full space-y-6 p-6 pt-3",testId:`project-tab-${m||"overview"}`,children:r.jsxs(Uk,{children:[r.jsx(Kt,{index:!0,element:r.jsx(Xj,{pid:s})}),r.jsx(Kt,{path:"workspaces",element:r.jsx(nP,{})}),r.jsx(Kt,{path:"models",element:r.jsx(fN,{})}),r.jsx(Kt,{path:"agent-defaults",element:r.jsx(s6,{})}),r.jsx(Kt,{path:"sessions",element:r.jsx(c6,{})}),r.jsx(Kt,{path:"logs",element:r.jsx(GP,{pid:s})}),r.jsx(Kt,{path:"config",element:r.jsx(E6,{pid:s})}),r.jsx(Kt,{path:"telegram",element:r.jsx(LI,{pid:s})}),r.jsx(Kt,{path:"agents",element:r.jsx(O6,{pid:s})}),r.jsx(Kt,{path:"agents/:slug",element:r.jsx(A8,{pid:s})}),r.jsx(Kt,{path:"memories",element:r.jsx(II,{pid:s})}),r.jsx(Kt,{path:"routines",element:r.jsx(Y6,{pid:s})}),r.jsx(Kt,{path:"tasks",element:u?r.jsx(u6,{}):r.jsx(K6,{pid:s})}),r.jsx(Kt,{path:"mcps",element:r.jsx(aI,{pid:s})}),r.jsx(Kt,{path:"artifacts",element:r.jsx(UI,{pid:s})}),r.jsx(Kt,{path:"vars",element:r.jsx(uI,{pid:s})}),r.jsx(Kt,{path:"threads",element:r.jsx(SA,{to:`/p/${s}/chat`,replace:!0})}),r.jsx(Kt,{path:"chat",element:r.jsx(zI,{pid:s})}),r.jsx(Kt,{path:"*",element:r.jsx(Xj,{pid:s})})]})})}function B8({value:e,onChange:t,options:s,placeholder:o,className:l}){const c=S=>s.find(E=>E.value===S)?.label??S,[u,p]=x.useState(!1),[m,g]=x.useState(c(e)),h=x.useRef(null),b=x.useRef(null),[v,k]=x.useState(null);x.useEffect(()=>{g(c(e))},[e,s]),x.useLayoutEffect(()=>{if(!u)return;const S=()=>{const E=h.current;if(!E)return;const R=E.getBoundingClientRect();k({top:R.bottom+4,left:R.left,width:R.width})};return S(),window.addEventListener("scroll",S,!0),window.addEventListener("resize",S),()=>{window.removeEventListener("scroll",S,!0),window.removeEventListener("resize",S)}},[u]),x.useEffect(()=>{if(!u)return;const S=E=>{const R=E.target;h.current?.contains(R)||b.current?.contains(R)||(g(c(e)),p(!1))};return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[u,e,s]);const N=m.trim().toLowerCase(),j=m===c(e),y=N&&!j?s.filter(S=>S.label.toLowerCase().includes(N)||S.value.toLowerCase().includes(N)):s,C=S=>{t(S.value),g(S.label),p(!1)};return r.jsxs("div",{ref:h,className:Te("relative",l),children:[r.jsxs("div",{className:"flex items-center gap-1 rounded-lg border border-input bg-transparent px-2.5 transition-colors focus-within:border-ring focus-within:ring-1 focus-within:ring-ring dark:bg-input/30 dark:hover:bg-input/50",children:[r.jsx("input",{value:m,placeholder:o,onChange:S=>{g(S.target.value),p(!0)},onFocus:()=>p(!0),className:"w-full bg-transparent py-1.5 text-sm outline-none placeholder:text-muted-fg/60"}),r.jsx("button",{type:"button",tabIndex:-1,onClick:()=>p(S=>!S),className:"shrink-0 text-muted-fg hover:text-foreground",children:r.jsx(pa,{className:"size-4"})})]}),u&&y.length>0&&v&&Ps.createPortal(r.jsx("ul",{ref:b,style:{position:"fixed",top:v.top,left:v.left,width:v.width},className:"z-[1000] max-h-60 overflow-y-auto rounded-lg bg-popover p-1 shadow-md ring-1 ring-foreground/10",children:y.map(S=>r.jsx("li",{children:r.jsx("button",{type:"button",onMouseDown:E=>{E.preventDefault(),C(S)},className:Te("flex w-full items-center rounded-md px-2 py-1 text-left text-sm hover:bg-accent hover:text-accent-fg",S.value===e&&"bg-accent/50"),children:r.jsx("span",{className:"truncate font-mono text-xs",children:S.label})})},S.value))}),document.body)]})}const U8=["es","en","pt","fr","it","de","ca","gl","eu","nl","sv","no","da","fi","is","pl","cs","sk","sl","hr","sr","uk","ru","bg","ro","hu","el","tr","ar","he","fa","hi","bn","ta","ur","id","ms","vi","th","ko","ja","zh"];function H8(e){return e&&e.charAt(0).toLocaleUpperCase()+e.slice(1)}function V8(){const e=Gb();let t=null;try{t=new Intl.DisplayNames([e],{type:"language"})}catch{t=null}return U8.map(s=>{const o=t?.of(s);return{value:s,label:o?H8(o):s}}).sort((s,o)=>s.label.localeCompare(o.label,e))}const q8=["UTC","America/Argentina/Buenos_Aires","America/Sao_Paulo","America/New_York","America/Los_Angeles","America/Mexico_City","Europe/London","Europe/Madrid","Europe/Berlin","Asia/Tokyo","Asia/Shanghai","Australia/Sydney"];function $8(){try{const e=Intl.supportedValuesOf;if(typeof e=="function")return e("timeZone")}catch{}return q8}function _w(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}function F8(e,t){try{const s=new Intl.DateTimeFormat("en-US",{timeZone:e,timeZoneName:"longOffset"}).formatToParts(t).find(c=>c.type==="timeZoneName")?.value??"GMT",o=/GMT([+-])(\d{1,2})(?::(\d{2}))?/.exec(s);return o?(o[1]==="-"?-1:1)*(parseInt(o[2],10)*60+(o[3]?parseInt(o[3],10):0)):0}catch{return 0}}function G8(e){const t=e<0?"-":"+",s=Math.abs(e),o=String(Math.floor(s/60)).padStart(2,"0"),l=String(s%60).padStart(2,"0");return`GMT${t}${o}:${l}`}let Dd=null;function Y8(){if(Dd)return Dd;const e=new Date;return Dd=$8().map(t=>({value:t,label:t,off:F8(t,e)})).sort((t,s)=>t.off-s.off||t.value.localeCompare(s.value)).map(({value:t,off:s})=>({value:t,label:`(${G8(s)}) ${t}`})),Dd}function K8(){const e=ot(),{identity:t,isLoading:s,save:o}=Zb(),[l,c]=x.useState({}),[u,p]=x.useState(!1),m=x.useMemo(()=>Y8(),[]);if(x.useEffect(()=>{c({...t,timezone:t?.timezone||_w()})},[t]),s)return r.jsx(rt,{});const g=async()=>{p(!0);try{await o({owner_name:l.owner_name,owner_context:l.owner_context,language:l.language,timezone:l.timezone}),e.success(f("settings.identity.saved"))}catch(h){e.error(h.message)}finally{p(!1)}};return r.jsxs(Ye,{title:f("settings.identity.title"),description:f("settings.identity.subtitle"),children:[t?null:r.jsx(bt,{children:f("common.none_yet")}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsx(le,{label:f("settings.identity.owner_name"),children:r.jsx(Ee,{value:l.owner_name||"",onChange:h=>c({...l,owner_name:h.target.value})})}),r.jsx(le,{label:f("settings.identity.language"),children:r.jsx(_t,{value:l.language||"es",onChange:h=>c({...l,language:h}),options:V8()})}),r.jsx(le,{label:f("settings.identity.timezone"),hint:f("settings.identity.timezone_hint"),children:r.jsx(B8,{value:l.timezone||_w(),onChange:h=>c({...l,timezone:h}),options:m})})]}),r.jsx("div",{className:"mt-3",children:r.jsx(le,{label:f("settings.identity.owner_context"),hint:f("settings.identity.owner_context_hint"),children:r.jsx(Mn,{rows:3,value:l.owner_context||"",onChange:h=>c({...l,owner_context:h.target.value})})})}),r.jsx("div",{className:"mt-4",children:r.jsx(ce,{variant:"primary",loading:u,onClick:g,children:f("common.save")})})]})}function X8(){const e=ot(),t=Gn(),{superAgent:s,isLoading:o,mutate:l}=uN(),{patch:c}=qr(),{identity:u,save:p}=Zb(),[m,g]=x.useState(!0),[h,b]=x.useState(""),[v,k]=x.useState(""),[N,j]=x.useState("permiso"),[y,C]=x.useState(!1);if(x.useEffect(()=>{s&&(g(!!s.enabled),b(s.system||""),j(s.permission_mode||"permiso"))},[s]),x.useEffect(()=>{k(u.personality||"")},[u.personality]),o||!s)return r.jsx(rt,{});const S=async()=>{C(!0);try{await c({"super_agent.enabled":m,"super_agent.system":h,"super_agent.permission_mode":N},["super_agent.name"]),await p({personality:v}),e.success(f("settings.super_agent.saved")),l()}catch(E){e.error(E.message)}finally{C(!1)}};return r.jsx(Ye,{title:f("settings.super_agent.title"),description:f("settings.super_agent.behavior_subtitle"),children:r.jsxs("div",{className:"space-y-4",children:[r.jsx("div",{className:"flex items-center gap-3",children:r.jsx(Qt,{checked:m,onChange:g,label:f("settings.super_agent.enabled_label")})}),r.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-border bg-muted/20 p-3",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"text-sm font-medium",children:f("settings.super_agent.model_active")}),r.jsx("div",{className:"truncate font-mono text-xs text-muted-fg",children:s.model||"—"})]}),r.jsxs(ce,{size:"sm",variant:"secondary",onClick:()=>t("/p/0/models"),children:[r.jsx(qx,{size:13})," ",f("settings.super_agent.model_configure")]})]}),r.jsx(le,{label:f("settings.super_agent.permission_mode"),children:r.jsx(_t,{value:N,onChange:j,options:Qx.map(E=>({value:E,label:E}))})}),r.jsx(le,{label:f("settings.super_agent.personality"),children:r.jsx(Mn,{rows:2,value:v,onChange:E=>k(E.target.value)})}),r.jsx(le,{label:f("settings.super_agent.system"),hint:f("settings.super_agent.system_hint"),children:r.jsx(Mn,{rows:6,className:"font-mono text-xs",value:h,onChange:E=>b(E.target.value),placeholder:f("settings.super_agent.system_ph")})}),r.jsx(ce,{variant:"primary",loading:y,onClick:S,children:f("common.save")})]})})}const gh={providers:()=>ge.get("/embeddings/providers"),test:(e={})=>ge.post("/embeddings/test",e),reindex:()=>ge.post("/embeddings/reindex",{})},Q8=()=>[{value:"auto",label:f("memory_panel.provider_auto")},{value:"ollama",label:f("memory_panel.provider_ollama")},{value:"gemini",label:f("memory_panel.provider_gemini")},{value:"openai",label:f("memory_panel.provider_openai")},{value:"tf",label:f("memory_panel.provider_tf")}],W8=()=>[{value:"chain",label:f("memory_panel.mode_chain")},{value:"single",label:f("memory_panel.mode_single")}],vw=e=>e.startsWith("***");function Z8(){const e=ot(),{config:t,isLoading:s,patch:o}=qr(),{data:l,mutate:c}=We("/embeddings/providers",()=>gh.providers()),[u,p]=x.useState(!1),[m,g]=x.useState(null);if(s)return r.jsx(rt,{});const h=t.memory||{},b=h.embeddings||{},v=l?.configured_provider||b.provider||"auto",k=l?.mode||b.mode||"chain",N=l?.engines||[],j=async S=>{p(!0);try{await o(S),await c()}catch(E){e.error(f("memory_panel.save_failed",{msg:E.message}))}finally{p(!1)}},y=async()=>{p(!0),g(null);try{const S=await gh.test({});g(`${S.embedder} · dim ${S.dim} · ${S.ms}ms`),e.success(f("memory_panel.test_ok",{embedder:S.embedder}))}catch(S){e.error(f("memory_panel.test_failed",{msg:S.message}))}finally{p(!1)}},C=async()=>{p(!0);try{const S=await gh.reindex();e.success(f("memory_panel.reindexed",{indexed:S.indexed,cleared:S.cleared}))}catch(S){e.error(f("memory_panel.reindex_failed",{msg:S.message}))}finally{p(!1)}};return r.jsxs("div",{className:"grid gap-6 xl:grid-cols-2 xl:items-start",children:[r.jsx(Ye,{title:f("memory_panel.embeddings_title"),description:f("memory_panel.embeddings_desc"),children:r.jsxs("div",{className:"space-y-3",children:[r.jsx(le,{label:f("memory_panel.provider_label"),hint:f("memory_panel.provider_hint"),children:r.jsx(_t,{value:v,onChange:S=>j({"memory.embeddings.provider":S}),options:Q8(),disabled:u,className:"max-w-xl"})}),r.jsx(le,{label:f("memory_panel.mode_label"),hint:f("memory_panel.mode_hint"),children:r.jsx(_t,{value:k,onChange:S=>j({"memory.embeddings.mode":S}),options:W8(),disabled:u,className:"max-w-md"})}),r.jsx("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:N.map(S=>r.jsxs($e,{tone:S.available?"success":"muted",children:[S.id,": ",S.available?f("memory_panel.available"):f("memory_panel.unavailable")]},S.id))}),r.jsxs("div",{className:"flex flex-wrap items-center gap-3 pt-1",children:[r.jsxs(ce,{variant:"secondary",onClick:y,loading:u,children:[r.jsx(ma,{size:14})," ",f("memory_panel.test_btn")]}),r.jsxs(ce,{variant:"secondary",onClick:C,loading:u,children:[r.jsx(Wk,{size:14})," ",f("memory_panel.reindex_btn")]}),m&&r.jsx("span",{className:"text-sm text-muted-foreground",children:m})]})]})}),r.jsxs(Ye,{title:f("memory_panel.ollama_title"),description:f("memory_panel.ollama_desc"),children:[r.jsx(le,{label:f("memory_panel.model_label"),children:r.jsx(Ee,{defaultValue:b.ollama?.model||"nomic-embed-text",placeholder:"nomic-embed-text",disabled:u,onBlur:S=>{const E=S.target.value.trim();E&&E!==b.ollama?.model&&j({"memory.embeddings.ollama.model":E})},className:"max-w-md"})}),r.jsx(le,{label:f("memory_panel.base_url_label"),hint:f("memory_panel.ollama_base_url_hint"),children:r.jsx(Ee,{defaultValue:b.ollama?.base_url||"",placeholder:"http://localhost:11434",disabled:u,onBlur:S=>j({"memory.embeddings.ollama.base_url":S.target.value.trim()}),className:"max-w-md"})})]}),r.jsxs(Ye,{title:f("memory_panel.openai_title"),description:f("memory_panel.openai_desc"),children:[r.jsx(le,{label:f("memory_panel.model_label"),children:r.jsx(Ee,{defaultValue:b.openai?.model||"text-embedding-3-small",placeholder:"text-embedding-3-small",disabled:u,onBlur:S=>{const E=S.target.value.trim();E&&E!==b.openai?.model&&j({"memory.embeddings.openai.model":E})},className:"max-w-md"})}),r.jsx(le,{label:f("memory_panel.api_key_label"),hint:f("memory_panel.openai_key_hint"),children:r.jsx(Ee,{type:"password",defaultValue:b.openai?.api_key||"",placeholder:"sk-…",disabled:u,onBlur:S=>{const E=S.target.value;E&&!vw(E)&&j({"memory.embeddings.openai.api_key":E})},className:"max-w-md"})})]}),r.jsxs(Ye,{title:f("memory_panel.gemini_title"),description:f("memory_panel.gemini_desc"),children:[r.jsx(le,{label:f("memory_panel.model_label"),children:r.jsx(Ee,{defaultValue:b.gemini?.model||"text-embedding-004",placeholder:"text-embedding-004",disabled:u,onBlur:S=>{const E=S.target.value.trim();E&&E!==b.gemini?.model&&j({"memory.embeddings.gemini.model":E})},className:"max-w-md"})}),r.jsx(le,{label:f("memory_panel.api_key_label"),hint:f("memory_panel.gemini_key_hint"),children:r.jsx(Ee,{type:"password",defaultValue:b.gemini?.api_key||"",placeholder:"AIza…",disabled:u,onBlur:S=>{const E=S.target.value;E&&!vw(E)&&j({"memory.embeddings.gemini.api_key":E})},className:"max-w-md"})})]}),r.jsxs(Ye,{title:f("memory_panel.compaction_title"),description:f("memory_panel.compaction_desc"),children:[r.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[r.jsx(le,{label:f("memory_panel.threshold_label"),hint:f("memory_panel.threshold_hint"),children:r.jsx(Ee,{type:"number",min:1,defaultValue:h.compact_threshold??60,placeholder:"60",disabled:u,onBlur:S=>{const E=parseInt(S.target.value,10);Number.isFinite(E)&&E>0&&E!==h.compact_threshold&&j({"memory.compact_threshold":E})},className:"max-w-[10rem]"})}),r.jsx(le,{label:f("memory_panel.keep_recent_label"),hint:f("memory_panel.keep_recent_hint"),children:r.jsx(Ee,{type:"number",min:1,defaultValue:h.keep_recent??40,placeholder:"40",disabled:u,onBlur:S=>{const E=parseInt(S.target.value,10);Number.isFinite(E)&&E>0&&E!==h.keep_recent&&j({"memory.keep_recent":E})},className:"max-w-[10rem]"})})]}),r.jsx(le,{label:f("memory_panel.compact_model_label"),hint:f("memory_panel.compact_model_hint"),children:r.jsx(Ee,{defaultValue:h.compact_model||"ollama:gemma4:31b-cloud",placeholder:"ollama:gemma4:31b-cloud",disabled:u,onBlur:S=>{const E=S.target.value.trim();E&&E!==h.compact_model&&j({"memory.compact_model":E})},className:"max-w-md"})}),r.jsx(le,{label:f("memory_panel.compact_fallback_label"),hint:f("memory_panel.compact_fallback_hint"),children:r.jsx(Ee,{defaultValue:h.compact_fallback_model||"",placeholder:f("memory_panel.compact_fallback_ph"),disabled:u,onBlur:S=>{const E=S.target.value.trim();E!==(h.compact_fallback_model||"")&&j({"memory.compact_fallback_model":E})},className:"max-w-md"})})]})]})}function J8(){return[{key:"load_threshold",label:f("settings_ui.knob_load_threshold"),hint:f("settings_ui.knob_load_threshold_hint"),step:.01,min:0,max:1},{key:"hint_threshold",label:f("settings_ui.knob_hint_threshold"),hint:f("settings_ui.knob_hint_threshold_hint"),step:.01,min:0,max:1},{key:"margin",label:f("settings_ui.knob_margin"),hint:f("settings_ui.knob_margin_hint"),step:.01,min:0,max:1},{key:"max_loaded",label:f("settings_ui.knob_max_loaded"),hint:f("settings_ui.knob_max_loaded_hint"),step:1,min:0,max:5},{key:"max_hints",label:f("settings_ui.knob_max_hints"),hint:f("settings_ui.knob_max_hints_hint"),step:1,min:0,max:8},{key:"prompt_floor",label:f("settings_ui.knob_prompt_floor"),hint:f("settings_ui.knob_prompt_floor_hint"),step:1,min:0,max:40},{key:"body_char_cap",label:f("settings_ui.knob_body_char_cap"),hint:f("settings_ui.knob_body_char_cap_hint"),step:500,min:500,max:2e4}]}function e7(){const e=ot(),{data:t,mutate:s,isLoading:o}=We("/skills/inspector",()=>fc.inspector()),[l,c]=x.useState(!1),[u,p]=x.useState(""),[m,g]=x.useState(null);if(o||!t)return r.jsx(rt,{});const h=t.config,b=t.index,v=async j=>{c(!0);try{await fc.updateInspector(j),await s()}catch(y){e.error(f("settings_ui.could_not_save",{msg:y.message}))}finally{c(!1)}},k=async(j=!1)=>{c(!0);try{const y=await fc.index({force:j});e.success(f("settings_ui.indexed_with",{embedder:y.embedder,dim:y.dim,added:y.changed.added,refreshed:y.changed.refreshed,removed:y.changed.removed})),await s()}catch(y){e.error(f("settings_ui.index_failed",{msg:y.message}))}finally{c(!1)}},N=async()=>{if(u.trim()){c(!0),g(null);try{const j=await fc.inspect(u.trim());g(j.trace)}catch(j){e.error(f("settings_ui.dry_run_failed",{msg:j.message}))}finally{c(!1)}}};return r.jsxs("div",{className:"grid gap-6 xl:grid-cols-2 xl:items-start",children:[r.jsx(Ye,{title:f("settings_ui.inspector_title"),description:f("settings_ui.inspector_desc"),children:r.jsxs("div",{className:"space-y-4",children:[r.jsx(le,{label:f("settings_ui.enable_inspector"),hint:f("settings_ui.enable_inspector_hint"),children:r.jsx(Qt,{checked:h.enabled,disabled:l,onChange:j=>v({enabled:j}),label:h.enabled?f("settings_ui.on"):f("settings_ui.off")})}),r.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[r.jsx($e,{tone:b.count>0?"success":"warning",children:f("settings_ui.index_count",{n:b.count})}),r.jsx($e,{tone:"muted",children:b.embedder||f("settings_ui.not_indexed")}),b.dim?r.jsx($e,{tone:"muted",children:f("settings_ui.dim",{dim:b.dim})}):null,b.updated_at?r.jsx("span",{className:"text-xs text-muted-foreground",children:f("settings_ui.updated_at",{date:new Date(b.updated_at).toLocaleString()})}):null]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-3 pt-1",children:[r.jsxs(ce,{variant:"secondary",onClick:()=>k(!1),loading:l,children:[r.jsx(ua,{size:14})," ",f("settings_ui.reindex")]}),r.jsxs(ce,{variant:"secondary",onClick:()=>k(!0),loading:l,children:[r.jsx(ua,{size:14})," ",f("settings_ui.reindex_forced")]}),r.jsx("span",{className:"text-xs text-muted-foreground",children:f("settings_ui.embedder_source")})]})]})}),r.jsx(Ye,{title:f("settings_ui.thresholds_title"),description:f("settings_ui.thresholds_desc"),children:r.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:J8().map(j=>r.jsx(le,{label:j.label,hint:j.hint,children:r.jsx(Ee,{type:"number",step:j.step,min:j.min,max:j.max,defaultValue:String(h[j.key]),disabled:l,onBlur:y=>{const C=Number(y.target.value);Number.isFinite(C)&&C!==h[j.key]&&v({[j.key]:C})},className:"max-w-[12rem]"})},j.key))})}),r.jsx(Ye,{title:f("settings_ui.test_title"),description:f("settings_ui.test_desc"),children:r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx(Ee,{value:u,placeholder:f("settings_ui.test_placeholder"),disabled:l,onChange:j=>p(j.target.value),onKeyDown:j=>{j.key==="Enter"&&N()},className:"max-w-xl flex-1"}),r.jsxs(ce,{variant:"primary",onClick:N,loading:l,children:[r.jsx(a3,{size:14})," ",f("settings_ui.test_btn")]})]}),m&&r.jsxs("div",{className:"rounded-md border border-border/60 bg-muted/30 p-3 text-sm",children:[r.jsxs("div",{className:"mb-2 flex flex-wrap items-center gap-2",children:[r.jsx(ma,{size:14,className:"text-muted-foreground"}),r.jsx("span",{className:"text-muted-foreground",children:m.embedder||"—"}),m.jit?r.jsx($e,{tone:"warning",children:f("settings_ui.jit_empty_index")}):null,m.reason&&!m.loaded?.length&&!m.hinted?.length?r.jsx($e,{tone:"muted",children:m.reason}):null]}),m.loaded?.length?r.jsxs("div",{className:"mb-1",children:[r.jsxs("span",{className:"text-muted-foreground",children:[f("settings_ui.loaded_label")," "]}),m.loaded.map(j=>r.jsx($e,{tone:"success",className:"mr-1",children:j},j))]}):null,m.hinted?.length?r.jsxs("div",{className:"mb-1",children:[r.jsxs("span",{className:"text-muted-foreground",children:[f("settings_ui.suggested_label")," "]}),m.hinted.map(j=>r.jsx($e,{tone:"info",className:"mr-1",children:j},j))]}):null,m.scored?.length?r.jsx("div",{className:"mt-2 space-y-0.5 font-mono text-xs text-muted-foreground",children:m.scored.map(j=>r.jsxs("div",{children:[j.sim.toFixed(3)," ",j.slug]},j.slug))}):null]})]})})]})}function t7(){const e=ot(),{config:t,isLoading:s,patch:o,mutate:l}=qr(),c=t.telegram?.channels||[],u=Math.max(0,c.findIndex(M=>M.name==="default")),p=c[u],[m,g]=x.useState(!0),[h,b]=x.useState(1500),[v,k]=x.useState(!0),[N,j]=x.useState(""),[y,C]=x.useState(""),[S,E]=x.useState(!1);if(x.useEffect(()=>{g(!!t.telegram?.enabled),b(Number(t.telegram?.poll_interval_ms||1500)),k(!!t.telegram?.respond_with_engine),j(""),C(p?.chat_id||"")},[t,p?.chat_id]),s)return r.jsx(rt,{});const R=async()=>{E(!0);try{const M=c.slice(),T={name:"default",chat_id:y,respond_with_engine:v,...N?{bot_token:N}:{}};c.length===0?M.push(T):M[u]={...p,...T},await o({"telegram.enabled":m,"telegram.poll_interval_ms":h,"telegram.respond_with_engine":v,"telegram.channels":M}),e.success(f("settings.telegram_global.saved")),l(),j("")}catch(M){e.error(M.message)}finally{E(!1)}};return r.jsx(Ye,{title:f("settings.telegram_global.title"),description:f("settings.telegram_global.subtitle"),children:r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(Qt,{checked:m,onChange:g,label:f("settings.telegram_global.enabled")}),r.jsx(Qt,{checked:v,onChange:k,label:f("settings.telegram_global.respond_with_engine")})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsx(le,{label:f("settings.telegram_global.bot_token"),hint:p?.bot_token?`…${wo(p.bot_token)??""} ${f("telegram_ui.secret_set_replace")}`:f("telegram_ui.bot_token_hint_short"),children:r.jsx(Ee,{type:"password",value:N,onChange:M=>j(M.target.value),placeholder:p?.bot_token?`…${wo(p.bot_token)??""} ${f("telegram_ui.secret_already_set")}`:""})}),r.jsx(le,{label:f("settings.telegram_global.chat_id"),children:r.jsx(Ee,{value:y,onChange:M=>C(M.target.value),placeholder:"889721252"})}),r.jsx(le,{label:f("settings.telegram_global.poll_interval"),children:r.jsx(Ee,{type:"number",value:String(h),onChange:M=>b(Number(M.target.value)||1500)})})]}),r.jsx(ce,{variant:"primary",loading:S,onClick:R,children:f("common.save")})]})})}function n7(){const e=ot(),{channels:t,isLoading:s,mutate:o}=a_(),{contacts:l}=r_(),[c,u]=x.useState(null),[p,m]=x.useState(null),g=new Map;for(const b of l)g.set(String(b.user_id),b.name||`@${b.username||b.user_id}`);const h=async b=>{if(confirm(f("telegram_channels.delete_confirm",{name:b})))try{await An.channels.remove(b),e.success(f("telegram_channels.removed")),o()}catch(v){e.error(v.message)}};return r.jsxs(Ye,{title:f("telegram_channels.title"),description:f("telegram_channels.desc"),action:r.jsxs(ce,{size:"sm",onClick:()=>u({name:""}),children:[r.jsx(an,{size:14})," ",f("telegram_channels.new_btn")]}),children:[s&&r.jsx(rt,{}),!s&&t.length===0&&r.jsx(bt,{children:f("telegram_channels.empty")}),r.jsx("ul",{className:"space-y-2 text-sm",children:t.map(b=>{const v=b.owner_user_id!=null?g.get(String(b.owner_user_id))||f("telegram_ui.user_id_fallback",{id:b.owner_user_id}):f("telegram_channels.no_owner");return r.jsxs("li",{className:"rounded-md border border-border bg-muted/30 px-3 py-2",children:[r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[r.jsx("span",{className:"font-medium",children:b.name}),r.jsxs("div",{className:"flex items-center gap-2",children:[b.project&&r.jsxs($e,{tone:"success",children:["project = ",b.project]}),r.jsxs(ce,{size:"sm",variant:"ghost",onClick:()=>m(b),children:[r.jsx(Gs,{size:13})," ",f("admin.telegram_send_test")]}),r.jsx(ce,{size:"sm",variant:"secondary",onClick:()=>u(b),children:f("common.edit")}),r.jsx(ce,{size:"sm",variant:"destructive",onClick:()=>h(b.name),children:f("common.delete")})]})]}),r.jsxs("div",{className:"mt-1 grid grid-cols-2 gap-2 text-xs text-muted-fg",children:[r.jsxs("span",{children:["chat_id: ",b.chat_id||"—"]}),r.jsxs("span",{children:["bot_token: ",b.bot_token?`…${wo(b.bot_token)??""}`:"—"]}),r.jsxs("span",{children:["route_to_agent: ",b.route_to_agent||f("telegram_ui.default_apx")]}),r.jsxs("span",{children:["engine: ",b.respond_with_engine?f("telegram_ui.yes"):f("telegram_ui.no")]}),r.jsxs("span",{className:"col-span-2",children:[f("telegram_channels.owner_label")," ",v]})]})]},b.name)})}),r.jsx(HC,{channel:c,onClose:()=>u(null),onSaved:()=>{u(null),o()}}),r.jsx(VC,{channel:p,onClose:()=>m(null)})]})}const yw=new Set(["owner","guest"]);function s7(){const e=ot(),{roles:t,mutate:s,isLoading:o}=r_(),[l,c]=x.useState(""),[u,p]=x.useState(""),[m,g]=x.useState(!1),[h,b]=x.useState(!1),v=async()=>{const j=l.trim();if(!j){e.error(f("telegram_roles.name_required"));return}if(yw.has(j)){e.error(f("telegram_roles.builtin_error",{name:j}));return}b(!0);try{const y=m?"*":u.split(",").map(C=>C.trim()).filter(Boolean);await An.roles.set(j,y),e.success(f("telegram_roles.saved",{name:j})),c(""),p(""),g(!1),s()}catch(y){e.error(y.message)}finally{b(!1)}},k=async j=>{if(confirm(f("telegram_roles.delete_confirm",{name:j})))try{await An.roles.remove(j),e.success(f("telegram_roles.removed")),s()}catch(y){e.error(y.message)}},N=Object.entries(t);return r.jsxs(Ye,{title:f("telegram_roles.title"),description:f("telegram_roles.desc"),children:[o&&r.jsx(rt,{}),N.length===0&&!o&&r.jsx(bt,{children:f("telegram_roles.empty")}),N.length>0&&r.jsx("ul",{className:"space-y-2 text-sm",children:N.map(([j,y])=>{const C=yw.has(j),S=y?.tools==="*"?f("telegram_roles.tools_all"):Array.isArray(y?.tools)&&y.tools.length>0?y.tools.join(", "):f("telegram_roles.tools_none");return r.jsxs("li",{className:"rounded-md border border-border bg-muted/30 px-3 py-2",children:[r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("span",{className:"font-medium",children:j}),C&&r.jsx($e,{tone:"info",children:f("telegram_roles.builtin")})]}),!C&&r.jsx(ce,{size:"sm",variant:"destructive",onClick:()=>k(j),children:f("telegram_roles.delete_btn")})]}),r.jsxs("div",{className:"mt-1 text-xs text-muted-fg",children:[f("telegram_contacts.tools_label")," ",S]})]},j)})}),r.jsxs("div",{className:"mt-4 space-y-3 rounded-md border border-dashed border-border p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[r.jsx(an,{size:14})," ",f("telegram_roles.new_title")]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsx(le,{label:f("telegram_roles.name_label"),children:r.jsx(Ee,{value:l,onChange:j=>c(j.target.value),placeholder:f("telegram_roles.name_ph")})}),r.jsx(le,{label:f("telegram_roles.tools_label"),hint:f("telegram_roles.tools_hint"),children:r.jsx(Ee,{value:u,onChange:j=>p(j.target.value),disabled:m,placeholder:f("telegram_roles.tools_ph")})})]}),r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsx(Qt,{checked:m,onChange:g,label:f("telegram_roles.full_access")}),r.jsx(ce,{variant:"primary",loading:h,onClick:v,children:f("telegram_roles.save_btn")})]})]})]})}const IN="apx.settings.telegramTab";function a7(){if(typeof window>"u")return"default";const e=window.localStorage.getItem(IN);return e==="channels"||e==="contacts"||e==="roles"||e==="default"?e:"default"}function r7(){const[e,t]=x.useState("default");x.useEffect(()=>{t(a7())},[]);const s=o=>{const l=o==="channels"||o==="contacts"||o==="roles"||o==="default"?o:"default";t(l);try{window.localStorage.setItem(IN,l)}catch{}};return r.jsxs(pp,{value:e,onValueChange:s,className:"w-full",children:[r.jsxs(mp,{children:[r.jsx(ra,{value:"default",children:f("settings.telegram_global.title")}),r.jsx(ra,{value:"channels",children:f("telegram_channels.title")}),r.jsx(ra,{value:"contacts",children:f("telegram_contacts.title")}),r.jsx(ra,{value:"roles",children:f("telegram_roles.title")})]}),r.jsx(Ds,{value:"default",className:"mt-4",children:r.jsx(t7,{})}),r.jsx(Ds,{value:"channels",className:"mt-4",children:r.jsx(n7,{})}),r.jsx(Ds,{value:"contacts",className:"mt-4",children:r.jsx(qC,{})}),r.jsx(Ds,{value:"roles",className:"mt-4",children:r.jsx(s7,{})})]})}function o7(){const{data:e,error:t,isLoading:s,mutate:o}=We("/pair/list",()=>Gl.list(),{refreshInterval:Df.pairList});return{clients:e?.clients||[],error:t,isLoading:s,mutate:o}}var jl={},hh,jw;function l7(){return jw||(jw=1,hh=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),hh}var xh={},Sr={},ww;function Mo(){if(ww)return Sr;ww=1;let e;const t=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return Sr.getSymbolSize=function(o){if(!o)throw new Error('"version" cannot be null or undefined');if(o<1||o>40)throw new Error('"version" should be in range from 1 to 40');return o*4+17},Sr.getSymbolTotalCodewords=function(o){return t[o]},Sr.getBCHDigit=function(s){let o=0;for(;s!==0;)o++,s>>>=1;return o},Sr.setToSJISFunction=function(o){if(typeof o!="function")throw new Error('"toSJISFunc" is not a valid function.');e=o},Sr.isKanjiModeEnabled=function(){return typeof e<"u"},Sr.toSJIS=function(o){return e(o)},Sr}var bh={},kw;function y_(){return kw||(kw=1,(function(e){e.L={bit:1},e.M={bit:0},e.Q={bit:3},e.H={bit:2};function t(s){if(typeof s!="string")throw new Error("Param is not a string");switch(s.toLowerCase()){case"l":case"low":return e.L;case"m":case"medium":return e.M;case"q":case"quartile":return e.Q;case"h":case"high":return e.H;default:throw new Error("Unknown EC Level: "+s)}}e.isValid=function(o){return o&&typeof o.bit<"u"&&o.bit>=0&&o.bit<4},e.from=function(o,l){if(e.isValid(o))return o;try{return t(o)}catch{return l}}})(bh)),bh}var _h,Sw;function i7(){if(Sw)return _h;Sw=1;function e(){this.buffer=[],this.length=0}return e.prototype={get:function(t){const s=Math.floor(t/8);return(this.buffer[s]>>>7-t%8&1)===1},put:function(t,s){for(let o=0;o<s;o++)this.putBit((t>>>s-o-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(t){const s=Math.floor(this.length/8);this.buffer.length<=s&&this.buffer.push(0),t&&(this.buffer[s]|=128>>>this.length%8),this.length++}},_h=e,_h}var vh,Cw;function c7(){if(Cw)return vh;Cw=1;function e(t){if(!t||t<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=t,this.data=new Uint8Array(t*t),this.reservedBit=new Uint8Array(t*t)}return e.prototype.set=function(t,s,o,l){const c=t*this.size+s;this.data[c]=o,l&&(this.reservedBit[c]=!0)},e.prototype.get=function(t,s){return this.data[t*this.size+s]},e.prototype.xor=function(t,s,o){this.data[t*this.size+s]^=o},e.prototype.isReserved=function(t,s){return this.reservedBit[t*this.size+s]},vh=e,vh}var yh={},Nw;function u7(){return Nw||(Nw=1,(function(e){const t=Mo().getSymbolSize;e.getRowColCoords=function(o){if(o===1)return[];const l=Math.floor(o/7)+2,c=t(o),u=c===145?26:Math.ceil((c-13)/(2*l-2))*2,p=[c-7];for(let m=1;m<l-1;m++)p[m]=p[m-1]-u;return p.push(6),p.reverse()},e.getPositions=function(o){const l=[],c=e.getRowColCoords(o),u=c.length;for(let p=0;p<u;p++)for(let m=0;m<u;m++)p===0&&m===0||p===0&&m===u-1||p===u-1&&m===0||l.push([c[p],c[m]]);return l}})(yh)),yh}var jh={},Ew;function d7(){if(Ew)return jh;Ew=1;const e=Mo().getSymbolSize,t=7;return jh.getPositions=function(o){const l=e(o);return[[0,0],[l-t,0],[0,l-t]]},jh}var wh={},Rw;function f7(){return Rw||(Rw=1,(function(e){e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const t={N1:3,N2:3,N3:40,N4:10};e.isValid=function(l){return l!=null&&l!==""&&!isNaN(l)&&l>=0&&l<=7},e.from=function(l){return e.isValid(l)?parseInt(l,10):void 0},e.getPenaltyN1=function(l){const c=l.size;let u=0,p=0,m=0,g=null,h=null;for(let b=0;b<c;b++){p=m=0,g=h=null;for(let v=0;v<c;v++){let k=l.get(b,v);k===g?p++:(p>=5&&(u+=t.N1+(p-5)),g=k,p=1),k=l.get(v,b),k===h?m++:(m>=5&&(u+=t.N1+(m-5)),h=k,m=1)}p>=5&&(u+=t.N1+(p-5)),m>=5&&(u+=t.N1+(m-5))}return u},e.getPenaltyN2=function(l){const c=l.size;let u=0;for(let p=0;p<c-1;p++)for(let m=0;m<c-1;m++){const g=l.get(p,m)+l.get(p,m+1)+l.get(p+1,m)+l.get(p+1,m+1);(g===4||g===0)&&u++}return u*t.N2},e.getPenaltyN3=function(l){const c=l.size;let u=0,p=0,m=0;for(let g=0;g<c;g++){p=m=0;for(let h=0;h<c;h++)p=p<<1&2047|l.get(g,h),h>=10&&(p===1488||p===93)&&u++,m=m<<1&2047|l.get(h,g),h>=10&&(m===1488||m===93)&&u++}return u*t.N3},e.getPenaltyN4=function(l){let c=0;const u=l.data.length;for(let m=0;m<u;m++)c+=l.data[m];return Math.abs(Math.ceil(c*100/u/5)-10)*t.N4};function s(o,l,c){switch(o){case e.Patterns.PATTERN000:return(l+c)%2===0;case e.Patterns.PATTERN001:return l%2===0;case e.Patterns.PATTERN010:return c%3===0;case e.Patterns.PATTERN011:return(l+c)%3===0;case e.Patterns.PATTERN100:return(Math.floor(l/2)+Math.floor(c/3))%2===0;case e.Patterns.PATTERN101:return l*c%2+l*c%3===0;case e.Patterns.PATTERN110:return(l*c%2+l*c%3)%2===0;case e.Patterns.PATTERN111:return(l*c%3+(l+c)%2)%2===0;default:throw new Error("bad maskPattern:"+o)}}e.applyMask=function(l,c){const u=c.size;for(let p=0;p<u;p++)for(let m=0;m<u;m++)c.isReserved(m,p)||c.xor(m,p,s(l,m,p))},e.getBestMask=function(l,c){const u=Object.keys(e.Patterns).length;let p=0,m=1/0;for(let g=0;g<u;g++){c(g),e.applyMask(g,l);const h=e.getPenaltyN1(l)+e.getPenaltyN2(l)+e.getPenaltyN3(l)+e.getPenaltyN4(l);e.applyMask(g,l),h<m&&(m=h,p=g)}return p}})(wh)),wh}var Ld={},Tw;function BN(){if(Tw)return Ld;Tw=1;const e=y_(),t=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],s=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return Ld.getBlocksCount=function(l,c){switch(c){case e.L:return t[(l-1)*4+0];case e.M:return t[(l-1)*4+1];case e.Q:return t[(l-1)*4+2];case e.H:return t[(l-1)*4+3];default:return}},Ld.getTotalCodewordsCount=function(l,c){switch(c){case e.L:return s[(l-1)*4+0];case e.M:return s[(l-1)*4+1];case e.Q:return s[(l-1)*4+2];case e.H:return s[(l-1)*4+3];default:return}},Ld}var kh={},ic={},Aw;function p7(){if(Aw)return ic;Aw=1;const e=new Uint8Array(512),t=new Uint8Array(256);return(function(){let o=1;for(let l=0;l<255;l++)e[l]=o,t[o]=l,o<<=1,o&256&&(o^=285);for(let l=255;l<512;l++)e[l]=e[l-255]})(),ic.log=function(o){if(o<1)throw new Error("log("+o+")");return t[o]},ic.exp=function(o){return e[o]},ic.mul=function(o,l){return o===0||l===0?0:e[t[o]+t[l]]},ic}var Mw;function m7(){return Mw||(Mw=1,(function(e){const t=p7();e.mul=function(o,l){const c=new Uint8Array(o.length+l.length-1);for(let u=0;u<o.length;u++)for(let p=0;p<l.length;p++)c[u+p]^=t.mul(o[u],l[p]);return c},e.mod=function(o,l){let c=new Uint8Array(o);for(;c.length-l.length>=0;){const u=c[0];for(let m=0;m<l.length;m++)c[m]^=t.mul(l[m],u);let p=0;for(;p<c.length&&c[p]===0;)p++;c=c.slice(p)}return c},e.generateECPolynomial=function(o){let l=new Uint8Array([1]);for(let c=0;c<o;c++)l=e.mul(l,new Uint8Array([1,t.exp(c)]));return l}})(kh)),kh}var Sh,Ow;function g7(){if(Ow)return Sh;Ow=1;const e=m7();function t(s){this.genPoly=void 0,this.degree=s,this.degree&&this.initialize(this.degree)}return t.prototype.initialize=function(o){this.degree=o,this.genPoly=e.generateECPolynomial(this.degree)},t.prototype.encode=function(o){if(!this.genPoly)throw new Error("Encoder not initialized");const l=new Uint8Array(o.length+this.degree);l.set(o);const c=e.mod(l,this.genPoly),u=this.degree-c.length;if(u>0){const p=new Uint8Array(this.degree);return p.set(c,u),p}return c},Sh=t,Sh}var Ch={},Nh={},Eh={},zw;function UN(){return zw||(zw=1,Eh.isValid=function(t){return!isNaN(t)&&t>=1&&t<=40}),Eh}var ea={},Dw;function HN(){if(Dw)return ea;Dw=1;const e="[0-9]+",t="[A-Z $%*+\\-./:]+";let s="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";s=s.replace(/u/g,"\\u");const o="(?:(?![A-Z0-9 $%*+\\-./:]|"+s+`)(?:.|[\r
638
+ `).map(t=>t.replace(/^[-*#>\s]+/,"").trim()).filter(t=>t.length>2&&!t.startsWith("```")).slice(0,12)}function A8({pid:e}){const{slug:t=""}=Lk(),s=Gn(),[o,l]=x.useState("overview"),c=N8(),u=We(`/projects/${e}/agents/${t}`,()=>on.get(e,t)),p=We(`/projects/${e}/agents`,()=>on.list(e)),m=We(`/projects/${e}/routines`,()=>Cr.list(e)),g=We(`/projects/${e}/messages?agent=${t}`,()=>hf.project(e,{agent:t,limit:200})),h=We(`/projects/${e}/agents/${t}/conversations`,()=>Dc.list(e,t)),b=We(`/projects/${e}/tasks?all`,()=>Nr.list(e,"all")),v=u.data,k=R8(m.data||[],t),N=(b.data||[]).filter(C=>C.agent===t),j=(p.data||[]).filter(C=>C.parent===t);if(u.isLoading)return r.jsx(rt,{});if(!v)return r.jsx("div",{className:"text-sm text-muted-fg",children:f("project.agent_detail.not_found")});const y=v.is_master?Ga:dn;return r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-start justify-between gap-3",children:[r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("button",{onClick:()=>s(`/p/${e}/agents`),className:"mt-1 text-muted-fg hover:text-foreground",children:r.jsx(cM,{size:16})}),r.jsx("div",{className:Te("flex size-11 items-center justify-center rounded-xl bg-gradient-to-br",v.is_master?"from-violet-600 to-indigo-600":"from-slate-600 to-gray-600"),children:r.jsx(y,{className:"size-5 text-white"})}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx("h1",{className:"text-lg font-semibold",children:v.slug}),v.is_master&&r.jsxs($e,{tone:"success",children:[r.jsx(Ga,{size:10})," ",f("project.agents.orchestrator")]}),v.role&&r.jsx($e,{children:v.role}),v.model&&r.jsx($e,{tone:"info",children:v.model}),v.parent&&r.jsxs("button",{onClick:()=>s(`/p/${e}/agents/${v.parent}`),className:"text-[11px] text-violet-400 hover:underline",children:[f("project.agent_detail.reports_to")," ",v.parent]})]}),v.description&&r.jsx("p",{className:"mt-0.5 max-w-2xl text-xs text-muted-fg",children:v.description})]})]}),r.jsxs(ce,{size:"sm",variant:"primary",onClick:()=>s(`/p/${e}/chat?agent=${t}`),children:[r.jsx(Gs,{size:13})," ",f("project.agent_detail.chat_btn",{slug:v.slug})]})]}),r.jsx("div",{className:"flex flex-wrap gap-1 border-b border-border",children:c.map(({key:C,label:S,icon:E})=>r.jsxs("button",{onClick:()=>l(C),className:Te("flex items-center gap-1.5 border-b-2 px-3 py-2 text-sm transition-colors -mb-px",o===C?"border-foreground text-foreground":"border-transparent text-muted-fg hover:text-foreground"),children:[r.jsx(E,{size:14})," ",S]},C))}),o==="overview"&&r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[r.jsx(Od,{label:f("agents_ui.stat_threads"),value:h.data?.length??0,icon:Zd}),r.jsx(Od,{label:f("agents_ui.stat_records"),value:g.data?.length??0,icon:Fk}),r.jsx(Od,{label:f("agents_ui.stat_tasks"),value:N.length,icon:Mf}),r.jsx(Od,{label:f("agents_ui.stat_heartbeats"),value:k.length,icon:Ll})]}),r.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[r.jsx(Ye,{title:f("agent_detail_extra.skills_title"),description:"",children:r.jsxs("div",{className:"flex flex-wrap gap-1",children:[v.skills?.map(C=>r.jsxs($e,{tone:"info",children:[r.jsx(ma,{size:10})," ",C]},C)),v.tools?.map(C=>r.jsxs($e,{children:[r.jsx(Jl,{size:10})," ",C]},C)),!v.skills?.length&&!v.tools?.length&&r.jsx("span",{className:"text-xs text-muted-fg",children:"—"})]})}),r.jsx(Ye,{title:f("project.agent_detail.threads_recent"),description:"",children:r.jsxs("ul",{className:"space-y-1 text-xs",children:[(h.data||[]).slice(0,6).map(C=>r.jsxs("li",{className:"flex items-center justify-between rounded-md bg-muted/30 px-2 py-1",children:[r.jsx("span",{className:"truncate",children:C.title||C.filename}),r.jsxs("span",{className:"shrink-0 text-muted-fg",children:[C.messages??0," ",f("project.agent_detail.msgs_count")]})]},C.id)),!h.data?.length&&r.jsx("li",{className:"text-muted-fg",children:f("project.agent_detail.no_threads")})]})})]}),j.length>0&&r.jsx(Ye,{title:f("project.agent_detail.subagents"),description:f("project.agent_detail.subagents_desc"),children:r.jsx("div",{className:"flex flex-wrap gap-2",children:j.map(C=>r.jsxs("button",{onClick:()=>s(`/p/${e}/agents/${C.slug}`),className:"flex items-center gap-2 rounded-lg border border-border bg-muted/30 px-3 py-1.5 text-sm hover:border-muted-fg/50",children:[r.jsx(dn,{size:14,className:"text-muted-fg"})," ",C.slug]},C.slug))})})]}),o==="memories"&&r.jsx(O8,{pid:e,slug:t,initial:v.memory||"",onSaved:()=>u.mutate()}),o==="records"&&r.jsx(z8,{records:g.data||[],loading:g.isLoading}),o==="sleep"&&r.jsx(D8,{routines:k}),o==="brain"&&r.jsx(P8,{slug:t,memory:v.memory||"",threads:(h.data||[]).map(C=>({id:C.id,label:C.title||C.filename})),tasks:N.map(C=>({id:C.id,label:C.title,detail:C.body||void 0})),routines:k,parent:v.parent||null,children:j.map(C=>C.slug)}),o==="config"&&r.jsx(M8,{pid:e,agent:v,agents:p.data||[],onSaved:()=>{u.mutate(),p.mutate()},onDeleted:()=>{p.mutate(),s(`/p/${e}/agents`)}})]})}function M8({pid:e,agent:t,agents:s,onSaved:o,onDeleted:l}){const c=ot(),[u,p]=x.useState(t.type||""),[m,g]=x.useState(t.area||""),[h,b]=x.useState(t.role||""),[v,k]=x.useState(t.model||""),[N,j]=x.useState(t.parent||""),[y,C]=x.useState(!!t.is_master),[S,E]=x.useState((t.skills||[]).join(", ")),[R,M]=x.useState((t.tools||[]).join(", ")),[T,O]=x.useState(t.description||""),[D,U]=x.useState(t.system||""),[L,I]=x.useState(!1),z=async()=>{I(!0);try{await on.update(e,t.slug,{type:u||null,area:m||null,role:h||null,model:v||null,parent:N||null,is_master:y||u==="orchestrator",skills:Rx(S),tools:Rx(R),description:T||null,system:D}),c.success(f("project.agent_detail.update_success")),o()}catch(H){c.error(H.message)}finally{I(!1)}},B=async()=>{if(confirm(f("project.agent_detail.delete_confirm",{slug:t.slug})))try{await on.remove(e,t.slug),c.success(f("project.agent_detail.delete_success")),l()}catch(H){c.error(H.message)}};return r.jsx(Ye,{title:f("project.agent_detail.config_title"),description:`.apc/agents/${t.slug}.md — ${f("agents_ui.config_def_desc")}`,children:r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsx(le,{label:f("project.agent_detail.type_label"),children:r.jsx(_t,{value:u,onChange:p,options:E8()})}),r.jsx(le,{label:f("project.agent_detail.area_label"),hint:f("project.agent_detail.area_hint"),children:r.jsx(Ee,{value:m,onChange:H=>g(H.target.value),placeholder:f("project.agent_detail.area_ph")})})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsx(le,{label:f("project.agent_detail.role_label"),children:r.jsx(Ee,{value:h,onChange:H=>b(H.target.value),placeholder:"Operations Lead"})}),r.jsx(le,{label:f("project.agent_detail.parent_label"),children:r.jsx(_t,{value:N,onChange:j,placeholder:f("project.agent_detail.none_parent"),options:[{value:"",label:f("project.agent_detail.none_parent")},...s.filter(H=>H.slug!==t.slug).map(H=>({value:H.slug,label:H.slug}))]})})]}),r.jsx(le,{label:f("project.agent_detail.model_label"),hint:f("project.agent_detail.model_hint"),children:r.jsx(Ee,{value:v,onChange:H=>k(H.target.value),placeholder:f("project.agent_detail.model_ph")})}),r.jsx(le,{label:f("project.agent_detail.skills_label"),children:r.jsx(Ee,{value:S,onChange:H=>E(H.target.value),placeholder:"skill-a, skill-b"})}),r.jsx(L8,{value:R,onChange:M}),r.jsx(le,{label:f("project.agent_detail.bio_label"),children:r.jsx(Mn,{rows:2,value:T,onChange:H=>O(H.target.value)})}),r.jsx(le,{label:f("project.agent_detail.system_label"),hint:f("project.agent_detail.system_hint"),children:r.jsx(Mn,{rows:10,className:"font-mono text-xs",value:D,onChange:H=>U(H.target.value),placeholder:"You are…"})}),r.jsx(Qt,{checked:y,onChange:C,label:f("project.agent_detail.master_label")}),r.jsxs("div",{className:"flex items-center justify-between border-t border-border pt-3",children:[r.jsxs(ce,{variant:"destructive",onClick:B,children:[r.jsx(Zn,{size:13})," ",f("project.agent_detail.delete_btn")]}),r.jsxs(ce,{variant:"primary",loading:L,onClick:z,children:[r.jsx(zf,{size:13})," ",f("project.agent_detail.save_btn")]})]})]})})}function Od({label:e,value:t,icon:s}){return r.jsxs("div",{className:"rounded-xl border border-border bg-muted/30 p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-fg",children:[r.jsx(s,{size:13})," ",e]}),r.jsx("div",{className:"mt-1 text-2xl font-semibold",children:t})]})}function O8({pid:e,slug:t,initial:s,onSaved:o}){const l=ot(),[c,u]=x.useState(s),[p,m]=x.useState(!1);x.useEffect(()=>{u(s)},[s]);const g=c!==s,h=async()=>{m(!0);try{await on.memory.put(e,t,c),l.success(f("project.agent_detail.memory_saved")),o()}catch(b){l.error(b.message)}finally{m(!1)}};return r.jsxs(Ye,{title:f("project.agent_detail.memory_title"),description:`~/.apx/projects/<id>/agents/${t}/memory.md — ${f("agents_ui.memory_durable_desc")}`,children:[r.jsx(Mn,{rows:16,className:"font-mono text-xs",value:c,onChange:b=>u(b.target.value),placeholder:f("project.agent_detail.memory_empty")}),r.jsxs("div",{className:"mt-2 flex items-center justify-between",children:[r.jsxs("span",{className:"text-[11px] text-muted-fg",children:[c.length," ",f("project.memories.chars")]}),r.jsxs(ce,{size:"sm",variant:"primary",loading:p,disabled:!g,onClick:h,children:[r.jsx(zf,{size:12})," ",f("project.memories.save_btn")]})]})]})}function z8({records:e,loading:t}){const s=x.useMemo(()=>[...e].sort((o,l)=>(l.ts||"").localeCompare(o.ts||"")),[e]);return r.jsxs(Ye,{title:f("project.agent_detail.records_title"),description:f("project.agent_detail.records_desc"),children:[t&&r.jsx(rt,{}),!t&&s.length===0&&r.jsx("p",{className:"text-xs text-muted-fg",children:f("project.agent_detail.no_activity")}),r.jsx("ul",{className:"space-y-1 text-sm",children:s.map((o,l)=>r.jsxs("li",{className:"flex items-start gap-2 rounded-md border border-border bg-muted/30 px-3 py-2",children:[r.jsx("span",{className:"mt-0.5 shrink-0",children:o.direction==="in"?r.jsx(Gk,{size:13,className:"text-blue-400"}):r.jsx(Kk,{size:13,className:"text-emerald-400"})}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] text-muted-fg",children:[r.jsx("span",{className:"font-mono",children:new Date(o.ts).toLocaleString()}),r.jsx($e,{tone:"info",children:o.channel}),o.type&&r.jsx($e,{children:o.type})]}),o.body&&r.jsx("p",{className:"mt-1 whitespace-pre-wrap break-words text-xs",children:o.body.length>400?`${o.body.slice(0,400)}…`:o.body})]})]},`${o.ts}-${l}`))})]})}function D8({routines:e}){return e.length===0?r.jsx(Ye,{title:f("project.agent_detail.sleep_title"),description:f("project.agent_detail.sleep_desc"),children:r.jsxs("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 p-4 text-sm",children:[r.jsx("div",{className:"font-medium text-amber-400",children:f("project.agent_detail.sleep_deep")}),r.jsx("p",{className:"mt-1 text-xs text-muted-fg",children:f("project.agent_detail.sleep_deep_desc")})]})}):r.jsx(Ye,{title:f("project.agent_detail.sleep_title"),description:f("project.agent_detail.sleep_desc"),children:r.jsx("div",{className:"space-y-3",children:e.map(t=>{const s=t.enabled,o=t.last_status==="error";return r.jsxs("div",{className:"rounded-xl border border-border bg-muted/30 p-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:Te("size-2 rounded-full",o?"bg-destructive":s?"bg-emerald-400":"bg-muted-fg/40")}),r.jsx("span",{className:"text-sm font-medium",children:t.name}),r.jsx($e,{tone:s?"success":"muted",children:f(s?"agents_ui.running":"agents_ui.paused")}),o&&r.jsx($e,{tone:"danger",children:f("agents_ui.last_error")})]}),r.jsxs("div",{className:"mt-2 grid grid-cols-2 gap-2 text-xs sm:grid-cols-4",children:[r.jsx(zd,{label:f("agents_ui.field_tick"),value:t.schedule}),r.jsx(zd,{label:f("agents_ui.field_next_tick"),value:t.next_run_at?new Date(t.next_run_at).toLocaleString():"—"}),r.jsx(zd,{label:f("agents_ui.field_last_tick"),value:t.last_run_at?new Date(t.last_run_at).toLocaleString():"—"}),r.jsx(zd,{label:f("agents_ui.field_last_run"),value:t.last_status||"—"})]}),t.last_error&&r.jsx("p",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1 text-[11px] text-destructive",children:t.last_error})]},t.name)})})})}function zd({label:e,value:t}){return r.jsxs("div",{className:"rounded-md border border-border bg-card p-2",children:[r.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-fg",children:e}),r.jsx("div",{className:"mt-0.5 truncate font-mono text-[11px]",children:t})]})}function L8({value:e,onChange:t}){const s=We("/tools",()=>GD.list()),o=Rx(e),l=s.data||[],c=p=>{const m=new Set(o);m.has(p)?m.delete(p):m.add(p),t([...m].join(", "))},u=o.filter(p=>!l.some(m=>m.name===p));return r.jsxs(le,{label:f("agents_ui.tools_label"),hint:f("project.agent_detail.tools_hint"),children:[r.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[l.map(p=>{const m=o.includes(p.name);return r.jsx(Ge,{content:p.description||p.name,children:r.jsx("button",{type:"button",onClick:()=>c(p.name),className:Te("rounded-md border px-2 py-0.5 font-mono text-[11px] transition-colors",m?"border-emerald-500/50 bg-emerald-500/10 text-emerald-400":"border-border text-muted-fg hover:text-foreground"),children:p.name})},p.name)}),u.map(p=>r.jsxs("button",{type:"button",onClick:()=>c(p),className:"rounded-md border border-sky-500/50 bg-sky-500/10 px-2 py-0.5 font-mono text-[11px] text-sky-400",children:[p," ✕"]},p))]}),r.jsx(Ee,{className:"mt-2",value:e,onChange:p=>t(p.target.value),placeholder:f("project.agent_detail.tools_custom_ph")})]})}function P8({slug:e,memory:t,threads:s,tasks:o,routines:l,parent:c,children:u}){const p=x.useMemo(()=>{const m=[];return T8(t).forEach((g,h)=>m.push({id:`m${h}`,label:g,kind:"memory",relation:"knows",detail:g})),s.slice(0,8).forEach(g=>m.push({id:`th-${g.id}`,label:g.label,kind:"thread",relation:"in_thread"})),o.slice(0,8).forEach(g=>m.push({id:`ts-${g.id}`,label:g.label,kind:"task",relation:"handles_task",detail:g.detail})),l.forEach(g=>m.push({id:`rt-${g.name}`,label:g.name,kind:"routine",relation:"ticks",detail:`schedule: ${g.schedule}`})),c&&m.push({id:`p-${c}`,label:c,kind:"agentlink",relation:"reports_to"}),u.forEach(g=>m.push({id:`c-${g}`,label:g,kind:"agentlink",relation:"orchestrates"})),m},[t,s,o,l,c,u]);return r.jsx(Ye,{title:f("project.agent_detail.brain_title"),description:f("project.agent_detail.brain_desc"),children:p.length===0?r.jsx("p",{className:"text-xs text-muted-fg",children:f("project.agent_detail.brain_empty")}):r.jsx(C8,{center:e,nodes:p})})}function I8(){const e=Gn(),t=Wn(),{pid:s=""}=Lk(),{project:o}=Wb(s),{collapsed:l,toggle:c}=Yb(Tn.sidebarCollapsed+".project"),u=String(s)==="0",p=x.useMemo(()=>u?[{title:f("base.nav_general"),items:[{key:"",label:"Dashboard",icon:VM},{key:"workspaces",label:f("base.workspaces_title"),icon:pM},{key:"models",label:f("settings.tabs.engines"),icon:qx},{key:"agent-defaults",label:f("base.defaults_title"),icon:dn}]},{title:f("base.nav_activity"),items:[{key:"chat",label:f("project.nav.chat"),icon:Zd},{key:"sessions",label:f("base.sessions_title"),icon:IM},{key:"tasks",label:f("project.nav.tasks"),icon:Pl},{key:"logs",label:f("project.nav.logs"),icon:Jd}]},{title:f("base.nav_system"),items:[{key:"agents",label:f("project.nav.agents"),icon:dn},{key:"memories",label:f("project.nav.memories"),icon:Xd},{key:"routines",label:f("project.nav.routines"),icon:Ll},{key:"mcps",label:f("project.nav.mcps"),icon:Yh},{key:"vars",label:f("project.nav.vars"),icon:Gh},{key:"artifacts",label:f("project.nav.artifacts"),icon:Qd},{key:"config",label:f("project.nav.config"),icon:Rc}]}]:[{title:f("project.sections.workspace"),items:[{key:"",label:f("project.nav.overview"),icon:Jk},{key:"telegram",label:f("project.nav.telegram"),icon:Gs},{key:"chat",label:f("project.nav.chat"),icon:Zd},{key:"agents",label:f("project.nav.agents"),icon:dn},{key:"memories",label:f("project.nav.memories"),icon:Xd}]},{title:f("project.sections.automation"),items:[{key:"routines",label:f("project.nav.routines"),icon:Ll},{key:"tasks",label:f("project.nav.tasks"),icon:Pl},{key:"mcps",label:f("project.nav.mcps"),icon:Yh},{key:"vars",label:f("project.nav.vars"),icon:Gh},{key:"artifacts",label:f("project.nav.artifacts"),icon:Qd},{key:"logs",label:f("project.nav.logs"),icon:Jd}]},{title:f("project.sections.config"),items:[{key:"config",label:f("project.nav.config"),icon:Rc}]}],[u]),m=t.pathname.replace(`/p/${s}`,"").replace(/^\//,"").split("/")[0];if(!o)return r.jsx(ZC,{testId:"screen-project-not-found",mood:"confused",message:f("project.not_found",{pid:s}),action:r.jsx(Wa,{variant:"outline",onClick:()=>e("/"),children:f("not_found.home")})});const g=h=>{const b=h?`/p/${s}/${h}`:`/p/${s}`;e(b)};return r.jsx(QC,{sections:p,active:m,onChange:g,collapsed:l,onToggleCollapse:c,contentClassName:"w-full space-y-6 p-6 pt-3",testId:`project-tab-${m||"overview"}`,children:r.jsxs(Uk,{children:[r.jsx(Kt,{index:!0,element:r.jsx(Xj,{pid:s})}),r.jsx(Kt,{path:"workspaces",element:r.jsx(nP,{})}),r.jsx(Kt,{path:"models",element:r.jsx(fN,{})}),r.jsx(Kt,{path:"agent-defaults",element:r.jsx(s6,{})}),r.jsx(Kt,{path:"sessions",element:r.jsx(c6,{})}),r.jsx(Kt,{path:"logs",element:r.jsx(GP,{pid:s})}),r.jsx(Kt,{path:"config",element:r.jsx(E6,{pid:s})}),r.jsx(Kt,{path:"telegram",element:r.jsx(LI,{pid:s})}),r.jsx(Kt,{path:"agents",element:r.jsx(O6,{pid:s})}),r.jsx(Kt,{path:"agents/:slug",element:r.jsx(A8,{pid:s})}),r.jsx(Kt,{path:"memories",element:r.jsx(II,{pid:s})}),r.jsx(Kt,{path:"routines",element:r.jsx(Y6,{pid:s})}),r.jsx(Kt,{path:"tasks",element:u?r.jsx(u6,{}):r.jsx(K6,{pid:s})}),r.jsx(Kt,{path:"mcps",element:r.jsx(aI,{pid:s})}),r.jsx(Kt,{path:"artifacts",element:r.jsx(UI,{pid:s})}),r.jsx(Kt,{path:"vars",element:r.jsx(uI,{pid:s})}),r.jsx(Kt,{path:"threads",element:r.jsx(SA,{to:`/p/${s}/chat`,replace:!0})}),r.jsx(Kt,{path:"chat",element:r.jsx(zI,{pid:s})}),r.jsx(Kt,{path:"*",element:r.jsx(Xj,{pid:s})})]})})}function B8({value:e,onChange:t,options:s,placeholder:o,className:l}){const c=S=>s.find(E=>E.value===S)?.label??S,[u,p]=x.useState(!1),[m,g]=x.useState(c(e)),h=x.useRef(null),b=x.useRef(null),[v,k]=x.useState(null);x.useEffect(()=>{g(c(e))},[e,s]),x.useLayoutEffect(()=>{if(!u)return;const S=()=>{const E=h.current;if(!E)return;const R=E.getBoundingClientRect();k({top:R.bottom+4,left:R.left,width:R.width})};return S(),window.addEventListener("scroll",S,!0),window.addEventListener("resize",S),()=>{window.removeEventListener("scroll",S,!0),window.removeEventListener("resize",S)}},[u]),x.useEffect(()=>{if(!u)return;const S=E=>{const R=E.target;h.current?.contains(R)||b.current?.contains(R)||(g(c(e)),p(!1))};return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[u,e,s]);const N=m.trim().toLowerCase(),j=m===c(e),y=N&&!j?s.filter(S=>S.label.toLowerCase().includes(N)||S.value.toLowerCase().includes(N)):s,C=S=>{t(S.value),g(S.label),p(!1)};return r.jsxs("div",{ref:h,className:Te("relative",l),children:[r.jsxs("div",{className:"flex items-center gap-1 rounded-lg border border-input bg-transparent px-2.5 transition-colors focus-within:border-ring focus-within:ring-1 focus-within:ring-ring dark:bg-input/30 dark:hover:bg-input/50",children:[r.jsx("input",{value:m,placeholder:o,onChange:S=>{g(S.target.value),p(!0)},onFocus:()=>p(!0),className:"w-full bg-transparent py-1.5 text-sm outline-none placeholder:text-muted-fg/60"}),r.jsx("button",{type:"button",tabIndex:-1,onClick:()=>p(S=>!S),className:"shrink-0 text-muted-fg hover:text-foreground",children:r.jsx(pa,{className:"size-4"})})]}),u&&y.length>0&&v&&Ps.createPortal(r.jsx("ul",{ref:b,style:{position:"fixed",top:v.top,left:v.left,width:v.width},className:"z-[1000] max-h-60 overflow-y-auto rounded-lg bg-popover p-1 shadow-md ring-1 ring-foreground/10",children:y.map(S=>r.jsx("li",{children:r.jsx("button",{type:"button",onMouseDown:E=>{E.preventDefault(),C(S)},className:Te("flex w-full items-center rounded-md px-2 py-1 text-left text-sm hover:bg-accent hover:text-accent-fg",S.value===e&&"bg-accent/50"),children:r.jsx("span",{className:"truncate font-mono text-xs",children:S.label})})},S.value))}),document.body)]})}const U8=["es","en","pt","fr","it","de","ca","gl","eu","nl","sv","no","da","fi","is","pl","cs","sk","sl","hr","sr","uk","ru","bg","ro","hu","el","tr","ar","he","fa","hi","bn","ta","ur","id","ms","vi","th","ko","ja","zh"];function H8(e){return e&&e.charAt(0).toLocaleUpperCase()+e.slice(1)}function V8(){const e=Gb();let t=null;try{t=new Intl.DisplayNames([e],{type:"language"})}catch{t=null}return U8.map(s=>{const o=t?.of(s);return{value:s,label:o?H8(o):s}}).sort((s,o)=>s.label.localeCompare(o.label,e))}const q8=["UTC","America/Argentina/Buenos_Aires","America/Sao_Paulo","America/New_York","America/Los_Angeles","America/Mexico_City","Europe/London","Europe/Madrid","Europe/Berlin","Asia/Tokyo","Asia/Shanghai","Australia/Sydney"];function $8(){try{const e=Intl.supportedValuesOf;if(typeof e=="function")return e("timeZone")}catch{}return q8}function _w(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch{return"UTC"}}function F8(e,t){try{const s=new Intl.DateTimeFormat("en-US",{timeZone:e,timeZoneName:"longOffset"}).formatToParts(t).find(c=>c.type==="timeZoneName")?.value??"GMT",o=/GMT([+-])(\d{1,2})(?::(\d{2}))?/.exec(s);return o?(o[1]==="-"?-1:1)*(parseInt(o[2],10)*60+(o[3]?parseInt(o[3],10):0)):0}catch{return 0}}function G8(e){const t=e<0?"-":"+",s=Math.abs(e),o=String(Math.floor(s/60)).padStart(2,"0"),l=String(s%60).padStart(2,"0");return`GMT${t}${o}:${l}`}let Dd=null;function Y8(){if(Dd)return Dd;const e=new Date;return Dd=$8().map(t=>({value:t,label:t,off:F8(t,e)})).sort((t,s)=>t.off-s.off||t.value.localeCompare(s.value)).map(({value:t,off:s})=>({value:t,label:`(${G8(s)}) ${t}`})),Dd}function K8(){const e=ot(),{identity:t,isLoading:s,save:o}=Zb(),[l,c]=x.useState({}),[u,p]=x.useState(!1),m=x.useMemo(()=>Y8(),[]);if(x.useEffect(()=>{c({...t,timezone:t?.timezone||_w()})},[t]),s)return r.jsx(rt,{});const g=async()=>{p(!0);try{await o({owner_name:l.owner_name,owner_context:l.owner_context,language:l.language,timezone:l.timezone}),e.success(f("settings.identity.saved"))}catch(h){e.error(h.message)}finally{p(!1)}};return r.jsxs(Ye,{title:f("settings.identity.title"),description:f("settings.identity.subtitle"),children:[t?null:r.jsx(bt,{children:f("common.none_yet")}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsx(le,{label:f("settings.identity.owner_name"),children:r.jsx(Ee,{value:l.owner_name||"",onChange:h=>c({...l,owner_name:h.target.value})})}),r.jsx(le,{label:f("settings.identity.language"),children:r.jsx(_t,{value:l.language||"es",onChange:h=>c({...l,language:h}),options:V8()})}),r.jsx(le,{label:f("settings.identity.timezone"),hint:f("settings.identity.timezone_hint"),children:r.jsx(B8,{value:l.timezone||_w(),onChange:h=>c({...l,timezone:h}),options:m})})]}),r.jsx("div",{className:"mt-3",children:r.jsx(le,{label:f("settings.identity.owner_context"),hint:f("settings.identity.owner_context_hint"),children:r.jsx(Mn,{rows:3,value:l.owner_context||"",onChange:h=>c({...l,owner_context:h.target.value})})})}),r.jsx("div",{className:"mt-4",children:r.jsx(ce,{variant:"primary",loading:u,onClick:g,children:f("common.save")})})]})}function X8(){const e=ot(),t=Gn(),{superAgent:s,isLoading:o,mutate:l}=uN(),{patch:c}=qr(),{identity:u,save:p}=Zb(),[m,g]=x.useState(!0),[h,b]=x.useState(""),[v,k]=x.useState(""),[N,j]=x.useState("permiso"),[y,C]=x.useState(!1);if(x.useEffect(()=>{s&&(g(!!s.enabled),b(s.system||""),j(s.permission_mode||"permiso"))},[s]),x.useEffect(()=>{k(u.personality||"")},[u.personality]),o||!s)return r.jsx(rt,{});const S=async()=>{C(!0);try{await c({"super_agent.enabled":m,"super_agent.system":h,"super_agent.permission_mode":N},["super_agent.name"]),await p({personality:v}),e.success(f("settings.super_agent.saved")),l()}catch(E){e.error(E.message)}finally{C(!1)}};return r.jsx(Ye,{title:f("settings.super_agent.title"),description:f("settings.super_agent.behavior_subtitle"),children:r.jsxs("div",{className:"space-y-4",children:[r.jsx("div",{className:"flex items-center gap-3",children:r.jsx(Qt,{checked:m,onChange:g,label:f("settings.super_agent.enabled_label")})}),r.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-border bg-muted/20 p-3",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"text-sm font-medium",children:f("settings.super_agent.model_active")}),r.jsx("div",{className:"truncate font-mono text-xs text-muted-fg",children:s.model||"—"})]}),r.jsxs(ce,{size:"sm",variant:"secondary",onClick:()=>t("/p/0/models"),children:[r.jsx(qx,{size:13})," ",f("settings.super_agent.model_configure")]})]}),r.jsx(le,{label:f("settings.super_agent.permission_mode"),children:r.jsx(_t,{value:N,onChange:j,options:Qx.map(E=>({value:E,label:E}))})}),r.jsx(le,{label:f("settings.super_agent.personality"),children:r.jsx(Mn,{rows:2,value:v,onChange:E=>k(E.target.value)})}),r.jsx(le,{label:f("settings.super_agent.system"),hint:f("settings.super_agent.system_hint"),children:r.jsx(Mn,{rows:6,className:"font-mono text-xs",value:h,onChange:E=>b(E.target.value),placeholder:f("settings.super_agent.system_ph")})}),r.jsx(ce,{variant:"primary",loading:y,onClick:S,children:f("common.save")})]})})}const gh={providers:()=>ge.get("/embeddings/providers"),test:(e={})=>ge.post("/embeddings/test",e),reindex:()=>ge.post("/embeddings/reindex",{})},Q8=()=>[{value:"auto",label:f("memory_panel.provider_auto")},{value:"ollama",label:f("memory_panel.provider_ollama")},{value:"gemini",label:f("memory_panel.provider_gemini")},{value:"openai",label:f("memory_panel.provider_openai")},{value:"tf",label:f("memory_panel.provider_tf")}],W8=()=>[{value:"chain",label:f("memory_panel.mode_chain")},{value:"single",label:f("memory_panel.mode_single")}],vw=e=>e.startsWith("***");function Z8(){const e=ot(),{config:t,isLoading:s,patch:o}=qr(),{data:l,mutate:c}=We("/embeddings/providers",()=>gh.providers()),[u,p]=x.useState(!1),[m,g]=x.useState(null);if(s)return r.jsx(rt,{});const h=t.memory||{},b=h.embeddings||{},v=l?.configured_provider||b.provider||"auto",k=l?.mode||b.mode||"chain",N=l?.engines||[],j=async S=>{p(!0);try{await o(S),await c()}catch(E){e.error(f("memory_panel.save_failed",{msg:E.message}))}finally{p(!1)}},y=async()=>{p(!0),g(null);try{const S=await gh.test({});g(`${S.embedder} · dim ${S.dim} · ${S.ms}ms`),e.success(f("memory_panel.test_ok",{embedder:S.embedder}))}catch(S){e.error(f("memory_panel.test_failed",{msg:S.message}))}finally{p(!1)}},C=async()=>{p(!0);try{const S=await gh.reindex();e.success(f("memory_panel.reindexed",{indexed:S.indexed,cleared:S.cleared}))}catch(S){e.error(f("memory_panel.reindex_failed",{msg:S.message}))}finally{p(!1)}};return r.jsxs("div",{className:"grid gap-6 xl:grid-cols-2 xl:items-start",children:[r.jsx(Ye,{title:f("memory_panel.embeddings_title"),description:f("memory_panel.embeddings_desc"),children:r.jsxs("div",{className:"space-y-3",children:[r.jsx(le,{label:f("memory_panel.provider_label"),hint:f("memory_panel.provider_hint"),children:r.jsx(_t,{value:v,onChange:S=>j({"memory.embeddings.provider":S}),options:Q8(),disabled:u,className:"max-w-xl"})}),r.jsx(le,{label:f("memory_panel.mode_label"),hint:f("memory_panel.mode_hint"),children:r.jsx(_t,{value:k,onChange:S=>j({"memory.embeddings.mode":S}),options:W8(),disabled:u,className:"max-w-md"})}),r.jsx("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:N.map(S=>r.jsxs($e,{tone:S.available?"success":"muted",children:[S.id,": ",S.available?f("memory_panel.available"):f("memory_panel.unavailable")]},S.id))}),r.jsxs("div",{className:"flex flex-wrap items-center gap-3 pt-1",children:[r.jsxs(ce,{variant:"secondary",onClick:y,loading:u,children:[r.jsx(ma,{size:14})," ",f("memory_panel.test_btn")]}),r.jsxs(ce,{variant:"secondary",onClick:C,loading:u,children:[r.jsx(Wk,{size:14})," ",f("memory_panel.reindex_btn")]}),m&&r.jsx("span",{className:"text-sm text-muted-foreground",children:m})]})]})}),r.jsxs(Ye,{title:f("memory_panel.ollama_title"),description:f("memory_panel.ollama_desc"),children:[r.jsx(le,{label:f("memory_panel.model_label"),children:r.jsx(Ee,{defaultValue:b.ollama?.model||"nomic-embed-text",placeholder:"nomic-embed-text",disabled:u,onBlur:S=>{const E=S.target.value.trim();E&&E!==b.ollama?.model&&j({"memory.embeddings.ollama.model":E})},className:"max-w-md"})}),r.jsx(le,{label:f("memory_panel.base_url_label"),hint:f("memory_panel.ollama_base_url_hint"),children:r.jsx(Ee,{defaultValue:b.ollama?.base_url||"",placeholder:"http://localhost:11434",disabled:u,onBlur:S=>j({"memory.embeddings.ollama.base_url":S.target.value.trim()}),className:"max-w-md"})})]}),r.jsxs(Ye,{title:f("memory_panel.openai_title"),description:f("memory_panel.openai_desc"),children:[r.jsx(le,{label:f("memory_panel.model_label"),children:r.jsx(Ee,{defaultValue:b.openai?.model||"text-embedding-3-small",placeholder:"text-embedding-3-small",disabled:u,onBlur:S=>{const E=S.target.value.trim();E&&E!==b.openai?.model&&j({"memory.embeddings.openai.model":E})},className:"max-w-md"})}),r.jsx(le,{label:f("memory_panel.api_key_label"),hint:f("memory_panel.openai_key_hint"),children:r.jsx(Ee,{type:"password",defaultValue:b.openai?.api_key||"",placeholder:"sk-…",disabled:u,onBlur:S=>{const E=S.target.value;E&&!vw(E)&&j({"memory.embeddings.openai.api_key":E})},className:"max-w-md"})})]}),r.jsxs(Ye,{title:f("memory_panel.gemini_title"),description:f("memory_panel.gemini_desc"),children:[r.jsx(le,{label:f("memory_panel.model_label"),children:r.jsx(Ee,{defaultValue:b.gemini?.model||"text-embedding-004",placeholder:"text-embedding-004",disabled:u,onBlur:S=>{const E=S.target.value.trim();E&&E!==b.gemini?.model&&j({"memory.embeddings.gemini.model":E})},className:"max-w-md"})}),r.jsx(le,{label:f("memory_panel.api_key_label"),hint:f("memory_panel.gemini_key_hint"),children:r.jsx(Ee,{type:"password",defaultValue:b.gemini?.api_key||"",placeholder:"AIza…",disabled:u,onBlur:S=>{const E=S.target.value;E&&!vw(E)&&j({"memory.embeddings.gemini.api_key":E})},className:"max-w-md"})})]}),r.jsxs(Ye,{title:f("memory_panel.compaction_title"),description:f("memory_panel.compaction_desc"),children:[r.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[r.jsx(le,{label:f("memory_panel.threshold_label"),hint:f("memory_panel.threshold_hint"),children:r.jsx(Ee,{type:"number",min:1,defaultValue:h.compact_threshold??60,placeholder:"60",disabled:u,onBlur:S=>{const E=parseInt(S.target.value,10);Number.isFinite(E)&&E>0&&E!==h.compact_threshold&&j({"memory.compact_threshold":E})},className:"max-w-[10rem]"})}),r.jsx(le,{label:f("memory_panel.keep_recent_label"),hint:f("memory_panel.keep_recent_hint"),children:r.jsx(Ee,{type:"number",min:1,defaultValue:h.keep_recent??40,placeholder:"40",disabled:u,onBlur:S=>{const E=parseInt(S.target.value,10);Number.isFinite(E)&&E>0&&E!==h.keep_recent&&j({"memory.keep_recent":E})},className:"max-w-[10rem]"})})]}),r.jsx(le,{label:f("memory_panel.compact_model_label"),hint:f("memory_panel.compact_model_hint"),children:r.jsx(Ee,{defaultValue:h.compact_model||"ollama:gemma4:31b-cloud",placeholder:"ollama:gemma4:31b-cloud",disabled:u,onBlur:S=>{const E=S.target.value.trim();E&&E!==h.compact_model&&j({"memory.compact_model":E})},className:"max-w-md"})}),r.jsx(le,{label:f("memory_panel.compact_fallback_label"),hint:f("memory_panel.compact_fallback_hint"),children:r.jsx(Ee,{defaultValue:h.compact_fallback_model||"",placeholder:f("memory_panel.compact_fallback_ph"),disabled:u,onBlur:S=>{const E=S.target.value.trim();E!==(h.compact_fallback_model||"")&&j({"memory.compact_fallback_model":E})},className:"max-w-md"})})]})]})}function J8(){return[{key:"load_threshold",label:f("settings_ui.knob_load_threshold"),hint:f("settings_ui.knob_load_threshold_hint"),step:.01,min:0,max:1},{key:"hint_threshold",label:f("settings_ui.knob_hint_threshold"),hint:f("settings_ui.knob_hint_threshold_hint"),step:.01,min:0,max:1},{key:"margin",label:f("settings_ui.knob_margin"),hint:f("settings_ui.knob_margin_hint"),step:.01,min:0,max:1},{key:"max_loaded",label:f("settings_ui.knob_max_loaded"),hint:f("settings_ui.knob_max_loaded_hint"),step:1,min:0,max:5},{key:"max_hints",label:f("settings_ui.knob_max_hints"),hint:f("settings_ui.knob_max_hints_hint"),step:1,min:0,max:8},{key:"prompt_floor",label:f("settings_ui.knob_prompt_floor"),hint:f("settings_ui.knob_prompt_floor_hint"),step:1,min:0,max:40},{key:"body_char_cap",label:f("settings_ui.knob_body_char_cap"),hint:f("settings_ui.knob_body_char_cap_hint"),step:500,min:500,max:2e4}]}function e7(){const e=ot(),{data:t,mutate:s,isLoading:o}=We("/skills/inspector",()=>fc.inspector()),[l,c]=x.useState(!1),[u,p]=x.useState(""),[m,g]=x.useState(null);if(o||!t)return r.jsx(rt,{});const h=t.config,b=t.index,v=async j=>{c(!0);try{await fc.updateInspector(j),await s()}catch(y){e.error(f("settings_ui.could_not_save",{msg:y.message}))}finally{c(!1)}},k=async(j=!1)=>{c(!0);try{const y=await fc.index({force:j});e.success(f("settings_ui.indexed_with",{embedder:y.embedder,dim:y.dim,added:y.changed.added,refreshed:y.changed.refreshed,removed:y.changed.removed})),await s()}catch(y){e.error(f("settings_ui.index_failed",{msg:y.message}))}finally{c(!1)}},N=async()=>{if(u.trim()){c(!0),g(null);try{const j=await fc.inspect(u.trim());g(j.trace)}catch(j){e.error(f("settings_ui.dry_run_failed",{msg:j.message}))}finally{c(!1)}}};return r.jsxs("div",{className:"grid gap-6 xl:grid-cols-2 xl:items-start",children:[r.jsx(Ye,{title:f("settings_ui.inspector_title"),description:f("settings_ui.inspector_desc"),children:r.jsxs("div",{className:"space-y-4",children:[r.jsx(le,{label:f("settings_ui.enable_inspector"),hint:f("settings_ui.enable_inspector_hint"),children:r.jsx(Qt,{checked:h.enabled,disabled:l,onChange:j=>v({enabled:j}),label:h.enabled?f("settings_ui.on"):f("settings_ui.off")})}),r.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[r.jsx($e,{tone:b.count>0?"success":"warning",children:f("settings_ui.index_count",{n:b.count})}),r.jsx($e,{tone:"muted",children:b.embedder||f("settings_ui.not_indexed")}),b.dim?r.jsx($e,{tone:"muted",children:f("settings_ui.dim",{dim:b.dim})}):null,b.updated_at?r.jsx("span",{className:"text-xs text-muted-foreground",children:f("settings_ui.updated_at",{date:new Date(b.updated_at).toLocaleString()})}):null]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-3 pt-1",children:[r.jsxs(ce,{variant:"secondary",onClick:()=>k(!1),loading:l,children:[r.jsx(ua,{size:14})," ",f("settings_ui.reindex")]}),r.jsxs(ce,{variant:"secondary",onClick:()=>k(!0),loading:l,children:[r.jsx(ua,{size:14})," ",f("settings_ui.reindex_forced")]}),r.jsx("span",{className:"text-xs text-muted-foreground",children:f("settings_ui.embedder_source")})]})]})}),r.jsx(Ye,{title:f("settings_ui.thresholds_title"),description:f("settings_ui.thresholds_desc"),children:r.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:J8().map(j=>r.jsx(le,{label:j.label,hint:j.hint,children:r.jsx(Ee,{type:"number",step:j.step,min:j.min,max:j.max,defaultValue:String(h[j.key]),disabled:l,onBlur:y=>{const C=Number(y.target.value);Number.isFinite(C)&&C!==h[j.key]&&v({[j.key]:C})},className:"max-w-[12rem]"})},j.key))})}),r.jsx(Ye,{title:f("settings_ui.test_title"),description:f("settings_ui.test_desc"),children:r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx(Ee,{value:u,placeholder:f("settings_ui.test_placeholder"),disabled:l,onChange:j=>p(j.target.value),onKeyDown:j=>{j.key==="Enter"&&N()},className:"max-w-xl flex-1"}),r.jsxs(ce,{variant:"primary",onClick:N,loading:l,children:[r.jsx(a3,{size:14})," ",f("settings_ui.test_btn")]})]}),m&&r.jsxs("div",{className:"rounded-md border border-border/60 bg-muted/30 p-3 text-sm",children:[r.jsxs("div",{className:"mb-2 flex flex-wrap items-center gap-2",children:[r.jsx(ma,{size:14,className:"text-muted-foreground"}),r.jsx("span",{className:"text-muted-foreground",children:m.embedder||"—"}),m.jit?r.jsx($e,{tone:"warning",children:f("settings_ui.jit_empty_index")}):null,m.reason&&!m.loaded?.length&&!m.hinted?.length?r.jsx($e,{tone:"muted",children:m.reason}):null]}),m.loaded?.length?r.jsxs("div",{className:"mb-1",children:[r.jsxs("span",{className:"text-muted-foreground",children:[f("settings_ui.loaded_label")," "]}),m.loaded.map(j=>r.jsx($e,{tone:"success",className:"mr-1",children:j},j))]}):null,m.hinted?.length?r.jsxs("div",{className:"mb-1",children:[r.jsxs("span",{className:"text-muted-foreground",children:[f("settings_ui.suggested_label")," "]}),m.hinted.map(j=>r.jsx($e,{tone:"info",className:"mr-1",children:j},j))]}):null,m.scored?.length?r.jsx("div",{className:"mt-2 space-y-0.5 font-mono text-xs text-muted-foreground",children:m.scored.map(j=>r.jsxs("div",{children:[j.sim.toFixed(3)," ",j.slug]},j.slug))}):null]})]})})]})}function t7(){const e=ot(),{config:t,isLoading:s,patch:o,mutate:l}=qr(),c=t.telegram?.channels||[],u=Math.max(0,c.findIndex(M=>M.name==="default")),p=c[u],[m,g]=x.useState(!0),[h,b]=x.useState(1500),[v,k]=x.useState(!0),[N,j]=x.useState(""),[y,C]=x.useState(""),[S,E]=x.useState(!1);if(x.useEffect(()=>{g(!!t.telegram?.enabled),b(Number(t.telegram?.poll_interval_ms||1500)),k(!!t.telegram?.respond_with_engine),j(""),C(p?.chat_id||"")},[t,p?.chat_id]),s)return r.jsx(rt,{});const R=async()=>{E(!0);try{const M=c.slice(),T={name:"default",chat_id:y,respond_with_engine:v,...N?{bot_token:N}:{}};c.length===0?M.push(T):M[u]={...p,...T},await o({"telegram.enabled":m,"telegram.poll_interval_ms":h,"telegram.respond_with_engine":v,"telegram.channels":M}),e.success(f("settings.telegram_global.saved")),l(),j("")}catch(M){e.error(M.message)}finally{E(!1)}};return r.jsx(Ye,{title:f("settings.telegram_global.title"),description:f("settings.telegram_global.subtitle"),children:r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(Qt,{checked:m,onChange:g,label:f("settings.telegram_global.enabled")}),r.jsx(Qt,{checked:v,onChange:k,label:f("settings.telegram_global.respond_with_engine")})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsx(le,{label:f("settings.telegram_global.bot_token"),hint:p?.bot_token?`…${wo(p.bot_token)??""} ${f("telegram_ui.secret_set_replace")}`:f("telegram_ui.bot_token_hint_short"),children:r.jsx(Ee,{type:"password",value:N,onChange:M=>j(M.target.value),placeholder:p?.bot_token?`…${wo(p.bot_token)??""} ${f("telegram_ui.secret_already_set")}`:""})}),r.jsx(le,{label:f("settings.telegram_global.chat_id"),children:r.jsx(Ee,{value:y,onChange:M=>C(M.target.value),placeholder:"889721252"})}),r.jsx(le,{label:f("settings.telegram_global.poll_interval"),children:r.jsx(Ee,{type:"number",value:String(h),onChange:M=>b(Number(M.target.value)||1500)})})]}),r.jsx(ce,{variant:"primary",loading:S,onClick:R,children:f("common.save")})]})})}function n7(){const e=ot(),{channels:t,isLoading:s,mutate:o}=a_(),{contacts:l}=r_(),[c,u]=x.useState(null),[p,m]=x.useState(null),g=new Map;for(const b of l)g.set(String(b.user_id),b.name||`@${b.username||b.user_id}`);const h=async b=>{if(confirm(f("telegram_channels.delete_confirm",{name:b})))try{await An.channels.remove(b),e.success(f("telegram_channels.removed")),o()}catch(v){e.error(v.message)}};return r.jsxs(Ye,{title:f("telegram_channels.title"),description:f("telegram_channels.desc"),action:r.jsxs(ce,{size:"sm",onClick:()=>u({name:""}),children:[r.jsx(an,{size:14})," ",f("telegram_channels.new_btn")]}),children:[s&&r.jsx(rt,{}),!s&&t.length===0&&r.jsx(bt,{children:f("telegram_channels.empty")}),r.jsx("ul",{className:"space-y-2 text-sm",children:t.map(b=>{const v=b.owner_user_id!=null?g.get(String(b.owner_user_id))||f("telegram_ui.user_id_fallback",{id:b.owner_user_id}):f("telegram_channels.no_owner");return r.jsxs("li",{className:"rounded-md border border-border bg-muted/30 px-3 py-2",children:[r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[r.jsx("span",{className:"font-medium",children:b.name}),r.jsxs("div",{className:"flex items-center gap-2",children:[b.project&&r.jsxs($e,{tone:"success",children:["project = ",b.project]}),r.jsxs(ce,{size:"sm",variant:"ghost",onClick:()=>m(b),children:[r.jsx(Gs,{size:13})," ",f("admin.telegram_send_test")]}),r.jsx(ce,{size:"sm",variant:"secondary",onClick:()=>u(b),children:f("common.edit")}),r.jsx(ce,{size:"sm",variant:"destructive",onClick:()=>h(b.name),children:f("common.delete")})]})]}),r.jsxs("div",{className:"mt-1 grid grid-cols-2 gap-2 text-xs text-muted-fg",children:[r.jsxs("span",{children:["chat_id: ",b.chat_id||"—"]}),r.jsxs("span",{children:["bot_token: ",b.bot_token?`…${wo(b.bot_token)??""}`:"—"]}),r.jsxs("span",{children:["route_to_agent: ",b.route_to_agent||f("telegram_ui.default_apx")]}),r.jsxs("span",{children:["engine: ",b.respond_with_engine?f("telegram_ui.yes"):f("telegram_ui.no")]}),r.jsxs("span",{className:"col-span-2",children:[f("telegram_channels.owner_label")," ",v]})]})]},b.name)})}),r.jsx(HC,{channel:c,onClose:()=>u(null),onSaved:()=>{u(null),o()}}),r.jsx(VC,{channel:p,onClose:()=>m(null)})]})}const yw=new Set(["owner","guest"]);function s7(){const e=ot(),{roles:t,mutate:s,isLoading:o}=r_(),[l,c]=x.useState(""),[u,p]=x.useState(""),[m,g]=x.useState(!1),[h,b]=x.useState(!1),v=async()=>{const j=l.trim();if(!j){e.error(f("telegram_roles.name_required"));return}if(yw.has(j)){e.error(f("telegram_roles.builtin_error",{name:j}));return}b(!0);try{const y=m?"*":u.split(",").map(C=>C.trim()).filter(Boolean);await An.roles.set(j,y),e.success(f("telegram_roles.saved",{name:j})),c(""),p(""),g(!1),s()}catch(y){e.error(y.message)}finally{b(!1)}},k=async j=>{if(confirm(f("telegram_roles.delete_confirm",{name:j})))try{await An.roles.remove(j),e.success(f("telegram_roles.removed")),s()}catch(y){e.error(y.message)}},N=Object.entries(t);return r.jsxs(Ye,{title:f("telegram_roles.title"),description:f("telegram_roles.desc"),children:[o&&r.jsx(rt,{}),N.length===0&&!o&&r.jsx(bt,{children:f("telegram_roles.empty")}),N.length>0&&r.jsx("ul",{className:"space-y-2 text-sm",children:N.map(([j,y])=>{const C=yw.has(j),S=y?.tools==="*"?f("telegram_roles.tools_all"):Array.isArray(y?.tools)&&y.tools.length>0?y.tools.join(", "):f("telegram_roles.tools_none");return r.jsxs("li",{className:"rounded-md border border-border bg-muted/30 px-3 py-2",children:[r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("span",{className:"font-medium",children:j}),C&&r.jsx($e,{tone:"info",children:f("telegram_roles.builtin")})]}),!C&&r.jsx(ce,{size:"sm",variant:"destructive",onClick:()=>k(j),children:f("telegram_roles.delete_btn")})]}),r.jsxs("div",{className:"mt-1 text-xs text-muted-fg",children:[f("telegram_contacts.tools_label")," ",S]})]},j)})}),r.jsxs("div",{className:"mt-4 space-y-3 rounded-md border border-dashed border-border p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[r.jsx(an,{size:14})," ",f("telegram_roles.new_title")]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsx(le,{label:f("telegram_roles.name_label"),children:r.jsx(Ee,{value:l,onChange:j=>c(j.target.value),placeholder:f("telegram_roles.name_ph")})}),r.jsx(le,{label:f("telegram_roles.tools_label"),hint:f("telegram_roles.tools_hint"),children:r.jsx(Ee,{value:u,onChange:j=>p(j.target.value),disabled:m,placeholder:f("telegram_roles.tools_ph")})})]}),r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsx(Qt,{checked:m,onChange:g,label:f("telegram_roles.full_access")}),r.jsx(ce,{variant:"primary",loading:h,onClick:v,children:f("telegram_roles.save_btn")})]})]})]})}const IN="apx.settings.telegramTab";function a7(){if(typeof window>"u")return"default";const e=window.localStorage.getItem(IN);return e==="channels"||e==="contacts"||e==="roles"||e==="default"?e:"default"}function r7(){const[e,t]=x.useState("default");x.useEffect(()=>{t(a7())},[]);const s=o=>{const l=o==="channels"||o==="contacts"||o==="roles"||o==="default"?o:"default";t(l);try{window.localStorage.setItem(IN,l)}catch{}};return r.jsxs(pp,{value:e,onValueChange:s,className:"w-full",children:[r.jsxs(mp,{children:[r.jsx(ra,{value:"default",children:f("settings.telegram_global.title")}),r.jsx(ra,{value:"channels",children:f("telegram_channels.title")}),r.jsx(ra,{value:"contacts",children:f("telegram_contacts.title")}),r.jsx(ra,{value:"roles",children:f("telegram_roles.title")})]}),r.jsx(Ds,{value:"default",className:"mt-4",children:r.jsx(t7,{})}),r.jsx(Ds,{value:"channels",className:"mt-4",children:r.jsx(n7,{})}),r.jsx(Ds,{value:"contacts",className:"mt-4",children:r.jsx(qC,{})}),r.jsx(Ds,{value:"roles",className:"mt-4",children:r.jsx(s7,{})})]})}function o7(){const{data:e,error:t,isLoading:s,mutate:o}=We("/pair/list",()=>Gl.list(),{refreshInterval:Df.pairList});return{clients:e?.clients||[],error:t,isLoading:s,mutate:o}}var jl={},hh,jw;function l7(){return jw||(jw=1,hh=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),hh}var xh={},Sr={},ww;function Mo(){if(ww)return Sr;ww=1;let e;const t=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return Sr.getSymbolSize=function(o){if(!o)throw new Error('"version" cannot be null or undefined');if(o<1||o>40)throw new Error('"version" should be in range from 1 to 40');return o*4+17},Sr.getSymbolTotalCodewords=function(o){return t[o]},Sr.getBCHDigit=function(s){let o=0;for(;s!==0;)o++,s>>>=1;return o},Sr.setToSJISFunction=function(o){if(typeof o!="function")throw new Error('"toSJISFunc" is not a valid function.');e=o},Sr.isKanjiModeEnabled=function(){return typeof e<"u"},Sr.toSJIS=function(o){return e(o)},Sr}var bh={},kw;function y_(){return kw||(kw=1,(function(e){e.L={bit:1},e.M={bit:0},e.Q={bit:3},e.H={bit:2};function t(s){if(typeof s!="string")throw new Error("Param is not a string");switch(s.toLowerCase()){case"l":case"low":return e.L;case"m":case"medium":return e.M;case"q":case"quartile":return e.Q;case"h":case"high":return e.H;default:throw new Error("Unknown EC Level: "+s)}}e.isValid=function(o){return o&&typeof o.bit<"u"&&o.bit>=0&&o.bit<4},e.from=function(o,l){if(e.isValid(o))return o;try{return t(o)}catch{return l}}})(bh)),bh}var _h,Sw;function i7(){if(Sw)return _h;Sw=1;function e(){this.buffer=[],this.length=0}return e.prototype={get:function(t){const s=Math.floor(t/8);return(this.buffer[s]>>>7-t%8&1)===1},put:function(t,s){for(let o=0;o<s;o++)this.putBit((t>>>s-o-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(t){const s=Math.floor(this.length/8);this.buffer.length<=s&&this.buffer.push(0),t&&(this.buffer[s]|=128>>>this.length%8),this.length++}},_h=e,_h}var vh,Cw;function c7(){if(Cw)return vh;Cw=1;function e(t){if(!t||t<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=t,this.data=new Uint8Array(t*t),this.reservedBit=new Uint8Array(t*t)}return e.prototype.set=function(t,s,o,l){const c=t*this.size+s;this.data[c]=o,l&&(this.reservedBit[c]=!0)},e.prototype.get=function(t,s){return this.data[t*this.size+s]},e.prototype.xor=function(t,s,o){this.data[t*this.size+s]^=o},e.prototype.isReserved=function(t,s){return this.reservedBit[t*this.size+s]},vh=e,vh}var yh={},Nw;function u7(){return Nw||(Nw=1,(function(e){const t=Mo().getSymbolSize;e.getRowColCoords=function(o){if(o===1)return[];const l=Math.floor(o/7)+2,c=t(o),u=c===145?26:Math.ceil((c-13)/(2*l-2))*2,p=[c-7];for(let m=1;m<l-1;m++)p[m]=p[m-1]-u;return p.push(6),p.reverse()},e.getPositions=function(o){const l=[],c=e.getRowColCoords(o),u=c.length;for(let p=0;p<u;p++)for(let m=0;m<u;m++)p===0&&m===0||p===0&&m===u-1||p===u-1&&m===0||l.push([c[p],c[m]]);return l}})(yh)),yh}var jh={},Ew;function d7(){if(Ew)return jh;Ew=1;const e=Mo().getSymbolSize,t=7;return jh.getPositions=function(o){const l=e(o);return[[0,0],[l-t,0],[0,l-t]]},jh}var wh={},Rw;function f7(){return Rw||(Rw=1,(function(e){e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const t={N1:3,N2:3,N3:40,N4:10};e.isValid=function(l){return l!=null&&l!==""&&!isNaN(l)&&l>=0&&l<=7},e.from=function(l){return e.isValid(l)?parseInt(l,10):void 0},e.getPenaltyN1=function(l){const c=l.size;let u=0,p=0,m=0,g=null,h=null;for(let b=0;b<c;b++){p=m=0,g=h=null;for(let v=0;v<c;v++){let k=l.get(b,v);k===g?p++:(p>=5&&(u+=t.N1+(p-5)),g=k,p=1),k=l.get(v,b),k===h?m++:(m>=5&&(u+=t.N1+(m-5)),h=k,m=1)}p>=5&&(u+=t.N1+(p-5)),m>=5&&(u+=t.N1+(m-5))}return u},e.getPenaltyN2=function(l){const c=l.size;let u=0;for(let p=0;p<c-1;p++)for(let m=0;m<c-1;m++){const g=l.get(p,m)+l.get(p,m+1)+l.get(p+1,m)+l.get(p+1,m+1);(g===4||g===0)&&u++}return u*t.N2},e.getPenaltyN3=function(l){const c=l.size;let u=0,p=0,m=0;for(let g=0;g<c;g++){p=m=0;for(let h=0;h<c;h++)p=p<<1&2047|l.get(g,h),h>=10&&(p===1488||p===93)&&u++,m=m<<1&2047|l.get(h,g),h>=10&&(m===1488||m===93)&&u++}return u*t.N3},e.getPenaltyN4=function(l){let c=0;const u=l.data.length;for(let m=0;m<u;m++)c+=l.data[m];return Math.abs(Math.ceil(c*100/u/5)-10)*t.N4};function s(o,l,c){switch(o){case e.Patterns.PATTERN000:return(l+c)%2===0;case e.Patterns.PATTERN001:return l%2===0;case e.Patterns.PATTERN010:return c%3===0;case e.Patterns.PATTERN011:return(l+c)%3===0;case e.Patterns.PATTERN100:return(Math.floor(l/2)+Math.floor(c/3))%2===0;case e.Patterns.PATTERN101:return l*c%2+l*c%3===0;case e.Patterns.PATTERN110:return(l*c%2+l*c%3)%2===0;case e.Patterns.PATTERN111:return(l*c%3+(l+c)%2)%2===0;default:throw new Error("bad maskPattern:"+o)}}e.applyMask=function(l,c){const u=c.size;for(let p=0;p<u;p++)for(let m=0;m<u;m++)c.isReserved(m,p)||c.xor(m,p,s(l,m,p))},e.getBestMask=function(l,c){const u=Object.keys(e.Patterns).length;let p=0,m=1/0;for(let g=0;g<u;g++){c(g),e.applyMask(g,l);const h=e.getPenaltyN1(l)+e.getPenaltyN2(l)+e.getPenaltyN3(l)+e.getPenaltyN4(l);e.applyMask(g,l),h<m&&(m=h,p=g)}return p}})(wh)),wh}var Ld={},Tw;function BN(){if(Tw)return Ld;Tw=1;const e=y_(),t=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],s=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return Ld.getBlocksCount=function(l,c){switch(c){case e.L:return t[(l-1)*4+0];case e.M:return t[(l-1)*4+1];case e.Q:return t[(l-1)*4+2];case e.H:return t[(l-1)*4+3];default:return}},Ld.getTotalCodewordsCount=function(l,c){switch(c){case e.L:return s[(l-1)*4+0];case e.M:return s[(l-1)*4+1];case e.Q:return s[(l-1)*4+2];case e.H:return s[(l-1)*4+3];default:return}},Ld}var kh={},ic={},Aw;function p7(){if(Aw)return ic;Aw=1;const e=new Uint8Array(512),t=new Uint8Array(256);return(function(){let o=1;for(let l=0;l<255;l++)e[l]=o,t[o]=l,o<<=1,o&256&&(o^=285);for(let l=255;l<512;l++)e[l]=e[l-255]})(),ic.log=function(o){if(o<1)throw new Error("log("+o+")");return t[o]},ic.exp=function(o){return e[o]},ic.mul=function(o,l){return o===0||l===0?0:e[t[o]+t[l]]},ic}var Mw;function m7(){return Mw||(Mw=1,(function(e){const t=p7();e.mul=function(o,l){const c=new Uint8Array(o.length+l.length-1);for(let u=0;u<o.length;u++)for(let p=0;p<l.length;p++)c[u+p]^=t.mul(o[u],l[p]);return c},e.mod=function(o,l){let c=new Uint8Array(o);for(;c.length-l.length>=0;){const u=c[0];for(let m=0;m<l.length;m++)c[m]^=t.mul(l[m],u);let p=0;for(;p<c.length&&c[p]===0;)p++;c=c.slice(p)}return c},e.generateECPolynomial=function(o){let l=new Uint8Array([1]);for(let c=0;c<o;c++)l=e.mul(l,new Uint8Array([1,t.exp(c)]));return l}})(kh)),kh}var Sh,Ow;function g7(){if(Ow)return Sh;Ow=1;const e=m7();function t(s){this.genPoly=void 0,this.degree=s,this.degree&&this.initialize(this.degree)}return t.prototype.initialize=function(o){this.degree=o,this.genPoly=e.generateECPolynomial(this.degree)},t.prototype.encode=function(o){if(!this.genPoly)throw new Error("Encoder not initialized");const l=new Uint8Array(o.length+this.degree);l.set(o);const c=e.mod(l,this.genPoly),u=this.degree-c.length;if(u>0){const p=new Uint8Array(this.degree);return p.set(c,u),p}return c},Sh=t,Sh}var Ch={},Nh={},Eh={},zw;function UN(){return zw||(zw=1,Eh.isValid=function(t){return!isNaN(t)&&t>=1&&t<=40}),Eh}var ea={},Dw;function HN(){if(Dw)return ea;Dw=1;const e="[0-9]+",t="[A-Z $%*+\\-./:]+";let s="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";s=s.replace(/u/g,"\\u");const o="(?:(?![A-Z0-9 $%*+\\-./:]|"+s+`)(?:.|[\r
639
639
  ]))+`;ea.KANJI=new RegExp(s,"g"),ea.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),ea.BYTE=new RegExp(o,"g"),ea.NUMERIC=new RegExp(e,"g"),ea.ALPHANUMERIC=new RegExp(t,"g");const l=new RegExp("^"+s+"$"),c=new RegExp("^"+e+"$"),u=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return ea.testKanji=function(m){return l.test(m)},ea.testNumeric=function(m){return c.test(m)},ea.testAlphanumeric=function(m){return u.test(m)},ea}var Lw;function Oo(){return Lw||(Lw=1,(function(e){const t=UN(),s=HN();e.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},e.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},e.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},e.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},e.MIXED={bit:-1},e.getCharCountIndicator=function(c,u){if(!c.ccBits)throw new Error("Invalid mode: "+c);if(!t.isValid(u))throw new Error("Invalid version: "+u);return u>=1&&u<10?c.ccBits[0]:u<27?c.ccBits[1]:c.ccBits[2]},e.getBestModeForData=function(c){return s.testNumeric(c)?e.NUMERIC:s.testAlphanumeric(c)?e.ALPHANUMERIC:s.testKanji(c)?e.KANJI:e.BYTE},e.toString=function(c){if(c&&c.id)return c.id;throw new Error("Invalid mode")},e.isValid=function(c){return c&&c.bit&&c.ccBits};function o(l){if(typeof l!="string")throw new Error("Param is not a string");switch(l.toLowerCase()){case"numeric":return e.NUMERIC;case"alphanumeric":return e.ALPHANUMERIC;case"kanji":return e.KANJI;case"byte":return e.BYTE;default:throw new Error("Unknown mode: "+l)}}e.from=function(c,u){if(e.isValid(c))return c;try{return o(c)}catch{return u}}})(Nh)),Nh}var Pw;function h7(){return Pw||(Pw=1,(function(e){const t=Mo(),s=BN(),o=y_(),l=Oo(),c=UN(),u=7973,p=t.getBCHDigit(u);function m(v,k,N){for(let j=1;j<=40;j++)if(k<=e.getCapacity(j,N,v))return j}function g(v,k){return l.getCharCountIndicator(v,k)+4}function h(v,k){let N=0;return v.forEach(function(j){const y=g(j.mode,k);N+=y+j.getBitsLength()}),N}function b(v,k){for(let N=1;N<=40;N++)if(h(v,N)<=e.getCapacity(N,k,l.MIXED))return N}e.from=function(k,N){return c.isValid(k)?parseInt(k,10):N},e.getCapacity=function(k,N,j){if(!c.isValid(k))throw new Error("Invalid QR Code version");typeof j>"u"&&(j=l.BYTE);const y=t.getSymbolTotalCodewords(k),C=s.getTotalCodewordsCount(k,N),S=(y-C)*8;if(j===l.MIXED)return S;const E=S-g(j,k);switch(j){case l.NUMERIC:return Math.floor(E/10*3);case l.ALPHANUMERIC:return Math.floor(E/11*2);case l.KANJI:return Math.floor(E/13);case l.BYTE:default:return Math.floor(E/8)}},e.getBestVersionForData=function(k,N){let j;const y=o.from(N,o.M);if(Array.isArray(k)){if(k.length>1)return b(k,y);if(k.length===0)return 1;j=k[0]}else j=k;return m(j.mode,j.getLength(),y)},e.getEncodedBits=function(k){if(!c.isValid(k)||k<7)throw new Error("Invalid QR Code version");let N=k<<12;for(;t.getBCHDigit(N)-p>=0;)N^=u<<t.getBCHDigit(N)-p;return k<<12|N}})(Ch)),Ch}var Rh={},Iw;function x7(){if(Iw)return Rh;Iw=1;const e=Mo(),t=1335,s=21522,o=e.getBCHDigit(t);return Rh.getEncodedBits=function(c,u){const p=c.bit<<3|u;let m=p<<10;for(;e.getBCHDigit(m)-o>=0;)m^=t<<e.getBCHDigit(m)-o;return(p<<10|m)^s},Rh}var Th={},Ah,Bw;function b7(){if(Bw)return Ah;Bw=1;const e=Oo();function t(s){this.mode=e.NUMERIC,this.data=s.toString()}return t.getBitsLength=function(o){return 10*Math.floor(o/3)+(o%3?o%3*3+1:0)},t.prototype.getLength=function(){return this.data.length},t.prototype.getBitsLength=function(){return t.getBitsLength(this.data.length)},t.prototype.write=function(o){let l,c,u;for(l=0;l+3<=this.data.length;l+=3)c=this.data.substr(l,3),u=parseInt(c,10),o.put(u,10);const p=this.data.length-l;p>0&&(c=this.data.substr(l),u=parseInt(c,10),o.put(u,p*3+1))},Ah=t,Ah}var Mh,Uw;function _7(){if(Uw)return Mh;Uw=1;const e=Oo(),t=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function s(o){this.mode=e.ALPHANUMERIC,this.data=o}return s.getBitsLength=function(l){return 11*Math.floor(l/2)+6*(l%2)},s.prototype.getLength=function(){return this.data.length},s.prototype.getBitsLength=function(){return s.getBitsLength(this.data.length)},s.prototype.write=function(l){let c;for(c=0;c+2<=this.data.length;c+=2){let u=t.indexOf(this.data[c])*45;u+=t.indexOf(this.data[c+1]),l.put(u,11)}this.data.length%2&&l.put(t.indexOf(this.data[c]),6)},Mh=s,Mh}var Oh,Hw;function v7(){if(Hw)return Oh;Hw=1;const e=Oo();function t(s){this.mode=e.BYTE,typeof s=="string"?this.data=new TextEncoder().encode(s):this.data=new Uint8Array(s)}return t.getBitsLength=function(o){return o*8},t.prototype.getLength=function(){return this.data.length},t.prototype.getBitsLength=function(){return t.getBitsLength(this.data.length)},t.prototype.write=function(s){for(let o=0,l=this.data.length;o<l;o++)s.put(this.data[o],8)},Oh=t,Oh}var zh,Vw;function y7(){if(Vw)return zh;Vw=1;const e=Oo(),t=Mo();function s(o){this.mode=e.KANJI,this.data=o}return s.getBitsLength=function(l){return l*13},s.prototype.getLength=function(){return this.data.length},s.prototype.getBitsLength=function(){return s.getBitsLength(this.data.length)},s.prototype.write=function(o){let l;for(l=0;l<this.data.length;l++){let c=t.toSJIS(this.data[l]);if(c>=33088&&c<=40956)c-=33088;else if(c>=57408&&c<=60351)c-=49472;else throw new Error("Invalid SJIS character: "+this.data[l]+`
640
640
  Make sure your charset is UTF-8`);c=(c>>>8&255)*192+(c&255),o.put(c,13)}},zh=s,zh}var Dh={exports:{}},qw;function j7(){return qw||(qw=1,(function(e){var t={single_source_shortest_paths:function(s,o,l){var c={},u={};u[o]=0;var p=t.PriorityQueue.make();p.push(o,0);for(var m,g,h,b,v,k,N,j,y;!p.empty();){m=p.pop(),g=m.value,b=m.cost,v=s[g]||{};for(h in v)v.hasOwnProperty(h)&&(k=v[h],N=b+k,j=u[h],y=typeof u[h]>"u",(y||j>N)&&(u[h]=N,p.push(h,N),c[h]=g))}if(typeof l<"u"&&typeof u[l]>"u"){var C=["Could not find a path from ",o," to ",l,"."].join("");throw new Error(C)}return c},extract_shortest_path_from_predecessor_list:function(s,o){for(var l=[],c=o;c;)l.push(c),s[c],c=s[c];return l.reverse(),l},find_path:function(s,o,l){var c=t.single_source_shortest_paths(s,o,l);return t.extract_shortest_path_from_predecessor_list(c,l)},PriorityQueue:{make:function(s){var o=t.PriorityQueue,l={},c;s=s||{};for(c in o)o.hasOwnProperty(c)&&(l[c]=o[c]);return l.queue=[],l.sorter=s.sorter||o.default_sorter,l},default_sorter:function(s,o){return s.cost-o.cost},push:function(s,o){var l={value:s,cost:o};this.queue.push(l),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};e.exports=t})(Dh)),Dh.exports}var $w;function w7(){return $w||($w=1,(function(e){const t=Oo(),s=b7(),o=_7(),l=v7(),c=y7(),u=HN(),p=Mo(),m=j7();function g(C){return unescape(encodeURIComponent(C)).length}function h(C,S,E){const R=[];let M;for(;(M=C.exec(E))!==null;)R.push({data:M[0],index:M.index,mode:S,length:M[0].length});return R}function b(C){const S=h(u.NUMERIC,t.NUMERIC,C),E=h(u.ALPHANUMERIC,t.ALPHANUMERIC,C);let R,M;return p.isKanjiModeEnabled()?(R=h(u.BYTE,t.BYTE,C),M=h(u.KANJI,t.KANJI,C)):(R=h(u.BYTE_KANJI,t.BYTE,C),M=[]),S.concat(E,R,M).sort(function(O,D){return O.index-D.index}).map(function(O){return{data:O.data,mode:O.mode,length:O.length}})}function v(C,S){switch(S){case t.NUMERIC:return s.getBitsLength(C);case t.ALPHANUMERIC:return o.getBitsLength(C);case t.KANJI:return c.getBitsLength(C);case t.BYTE:return l.getBitsLength(C)}}function k(C){return C.reduce(function(S,E){const R=S.length-1>=0?S[S.length-1]:null;return R&&R.mode===E.mode?(S[S.length-1].data+=E.data,S):(S.push(E),S)},[])}function N(C){const S=[];for(let E=0;E<C.length;E++){const R=C[E];switch(R.mode){case t.NUMERIC:S.push([R,{data:R.data,mode:t.ALPHANUMERIC,length:R.length},{data:R.data,mode:t.BYTE,length:R.length}]);break;case t.ALPHANUMERIC:S.push([R,{data:R.data,mode:t.BYTE,length:R.length}]);break;case t.KANJI:S.push([R,{data:R.data,mode:t.BYTE,length:g(R.data)}]);break;case t.BYTE:S.push([{data:R.data,mode:t.BYTE,length:g(R.data)}])}}return S}function j(C,S){const E={},R={start:{}};let M=["start"];for(let T=0;T<C.length;T++){const O=C[T],D=[];for(let U=0;U<O.length;U++){const L=O[U],I=""+T+U;D.push(I),E[I]={node:L,lastCount:0},R[I]={};for(let z=0;z<M.length;z++){const B=M[z];E[B]&&E[B].node.mode===L.mode?(R[B][I]=v(E[B].lastCount+L.length,L.mode)-v(E[B].lastCount,L.mode),E[B].lastCount+=L.length):(E[B]&&(E[B].lastCount=L.length),R[B][I]=v(L.length,L.mode)+4+t.getCharCountIndicator(L.mode,S))}}M=D}for(let T=0;T<M.length;T++)R[M[T]].end=0;return{map:R,table:E}}function y(C,S){let E;const R=t.getBestModeForData(C);if(E=t.from(S,R),E!==t.BYTE&&E.bit<R.bit)throw new Error('"'+C+'" cannot be encoded with mode '+t.toString(E)+`.
641
641
  Suggested mode is: `+t.toString(R));switch(E===t.KANJI&&!p.isKanjiModeEnabled()&&(E=t.BYTE),E){case t.NUMERIC:return new s(C);case t.ALPHANUMERIC:return new o(C);case t.KANJI:return new c(C);case t.BYTE:return new l(C)}}e.fromArray=function(S){return S.reduce(function(E,R){return typeof R=="string"?E.push(y(R,null)):R.data&&E.push(y(R.data,R.mode)),E},[])},e.fromString=function(S,E){const R=b(S,p.isKanjiModeEnabled()),M=N(R),T=j(M,E),O=m.find_path(T.map,"start","end"),D=[];for(let U=1;U<O.length-1;U++)D.push(T.table[O[U]].node);return e.fromArray(k(D))},e.rawSplit=function(S){return e.fromArray(b(S,p.isKanjiModeEnabled()))}})(Th)),Th}var Fw;function k7(){if(Fw)return xh;Fw=1;const e=Mo(),t=y_(),s=i7(),o=c7(),l=u7(),c=d7(),u=f7(),p=BN(),m=g7(),g=h7(),h=x7(),b=Oo(),v=w7();function k(T,O){const D=T.size,U=c.getPositions(O);for(let L=0;L<U.length;L++){const I=U[L][0],z=U[L][1];for(let B=-1;B<=7;B++)if(!(I+B<=-1||D<=I+B))for(let H=-1;H<=7;H++)z+H<=-1||D<=z+H||(B>=0&&B<=6&&(H===0||H===6)||H>=0&&H<=6&&(B===0||B===6)||B>=2&&B<=4&&H>=2&&H<=4?T.set(I+B,z+H,!0,!0):T.set(I+B,z+H,!1,!0))}}function N(T){const O=T.size;for(let D=8;D<O-8;D++){const U=D%2===0;T.set(D,6,U,!0),T.set(6,D,U,!0)}}function j(T,O){const D=l.getPositions(O);for(let U=0;U<D.length;U++){const L=D[U][0],I=D[U][1];for(let z=-2;z<=2;z++)for(let B=-2;B<=2;B++)z===-2||z===2||B===-2||B===2||z===0&&B===0?T.set(L+z,I+B,!0,!0):T.set(L+z,I+B,!1,!0)}}function y(T,O){const D=T.size,U=g.getEncodedBits(O);let L,I,z;for(let B=0;B<18;B++)L=Math.floor(B/3),I=B%3+D-8-3,z=(U>>B&1)===1,T.set(L,I,z,!0),T.set(I,L,z,!0)}function C(T,O,D){const U=T.size,L=h.getEncodedBits(O,D);let I,z;for(I=0;I<15;I++)z=(L>>I&1)===1,I<6?T.set(I,8,z,!0):I<8?T.set(I+1,8,z,!0):T.set(U-15+I,8,z,!0),I<8?T.set(8,U-I-1,z,!0):I<9?T.set(8,15-I-1+1,z,!0):T.set(8,15-I-1,z,!0);T.set(U-8,8,1,!0)}function S(T,O){const D=T.size;let U=-1,L=D-1,I=7,z=0;for(let B=D-1;B>0;B-=2)for(B===6&&B--;;){for(let H=0;H<2;H++)if(!T.isReserved(L,B-H)){let $=!1;z<O.length&&($=(O[z]>>>I&1)===1),T.set(L,B-H,$),I--,I===-1&&(z++,I=7)}if(L+=U,L<0||D<=L){L-=U,U=-U;break}}}function E(T,O,D){const U=new s;D.forEach(function(H){U.put(H.mode.bit,4),U.put(H.getLength(),b.getCharCountIndicator(H.mode,T)),H.write(U)});const L=e.getSymbolTotalCodewords(T),I=p.getTotalCodewordsCount(T,O),z=(L-I)*8;for(U.getLengthInBits()+4<=z&&U.put(0,4);U.getLengthInBits()%8!==0;)U.putBit(0);const B=(z-U.getLengthInBits())/8;for(let H=0;H<B;H++)U.put(H%2?17:236,8);return R(U,T,O)}function R(T,O,D){const U=e.getSymbolTotalCodewords(O),L=p.getTotalCodewordsCount(O,D),I=U-L,z=p.getBlocksCount(O,D),B=U%z,H=z-B,$=Math.floor(U/z),q=Math.floor(I/z),X=q+1,Y=$-q,F=new m(Y);let K=0;const P=new Array(z),G=new Array(z);let Z=0;const ee=new Uint8Array(T.buffer);for(let me=0;me<z;me++){const Me=me<H?q:X;P[me]=ee.slice(K,K+Me),G[me]=F.encode(P[me]),K+=Me,Z=Math.max(Z,Me)}const de=new Uint8Array(U);let fe=0,se,oe;for(se=0;se<Z;se++)for(oe=0;oe<z;oe++)se<P[oe].length&&(de[fe++]=P[oe][se]);for(se=0;se<Y;se++)for(oe=0;oe<z;oe++)de[fe++]=G[oe][se];return de}function M(T,O,D,U){let L;if(Array.isArray(T))L=v.fromArray(T);else if(typeof T=="string"){let $=O;if(!$){const q=v.rawSplit(T);$=g.getBestVersionForData(q,D)}L=v.fromString(T,$||40)}else throw new Error("Invalid data");const I=g.getBestVersionForData(L,D);if(!I)throw new Error("The amount of data is too big to be stored in a QR Code");if(!O)O=I;else if(O<I)throw new Error(`
@@ -648,4 +648,4 @@ Minimum version required to store current data is: `+I+`.
648
648
  `).map((b,v)=>r.jsxs("tr",{className:"hover:bg-accent/20",children:[r.jsx("td",{className:"w-12 select-none border-r border-border/30 px-3 py-0 text-right align-top text-[10px] text-muted-foreground/40","aria-hidden":"true",children:v+1}),r.jsx("td",{className:"px-4 py-0 align-top text-foreground/90 whitespace-pre",children:b||" "})]},v))})})})]})}function vU({pid:e,className:t,initCmd:s,onClose:o}){const[l,c]=x.useState([]),[u,p]=x.useState(""),[m,g]=x.useState(!1),[h,b]=x.useState([]),[v,k]=x.useState(-1),N=x.useRef(null),j=x.useRef(null);x.useEffect(()=>{N.current?.scrollIntoView({behavior:"smooth"})},[l]),x.useEffect(()=>{s&&(p(s),setTimeout(()=>j.current?.focus(),50))},[s]);const y=async S=>{const E=S.trim();if(E){b(R=>[E,...R.slice(0,49)]),k(-1),c(R=>[...R,{type:"cmd",text:`$ ${E}`}]),g(!0);try{const R=await ge.post("/run",{cmd:E,project:e});R.stdout&&c(M=>[...M,{type:"out",text:R.stdout}]),R.stderr&&c(M=>[...M,{type:"err",text:R.stderr}])}catch(R){c(M=>[...M,{type:"err",text:String(R.message)}])}finally{g(!1)}}},C=S=>{if(S.key==="Enter")y(u),p("");else if(S.key==="ArrowUp"){S.preventDefault();const E=Math.min(v+1,h.length-1);k(E),p(h[E]??"")}else if(S.key==="ArrowDown"){S.preventDefault();const E=Math.max(v-1,-1);k(E),p(E===-1?"":h[E]??"")}};return r.jsxs("div",{className:Te("flex h-full min-h-0 flex-col bg-card/60",t),"data-testid":"code-terminal",children:[r.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-3 py-1",children:[r.jsx(Ya,{className:"size-3 text-muted-foreground"}),r.jsx("span",{className:"flex-1 text-[11px] text-muted-foreground",children:"Terminal"}),r.jsx(Ge,{content:f("code_module.terminal_clear"),children:r.jsx("button",{type:"button",onClick:()=>c([]),className:"rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground",children:r.jsx(kM,{className:"size-3"})})}),r.jsx(Ge,{content:f("code_module.terminal_close"),children:r.jsx("button",{type:"button",onClick:()=>o?.(),className:"rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground",children:r.jsx(Ys,{className:"size-3"})})})]}),r.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-3 py-1 font-mono text-[11px] leading-snug cursor-text",onClick:()=>j.current?.focus(),children:[l.map((S,E)=>r.jsx("div",{className:Te("whitespace-pre-wrap break-all",S.type==="cmd"&&"text-emerald-400",S.type==="err"&&"text-rose-400",S.type==="out"&&"text-foreground/90"),children:S.text},E)),r.jsx("div",{ref:N})]}),r.jsxs("div",{className:"flex shrink-0 items-center border-t border-border px-3 py-1",children:[r.jsx("span",{className:"mr-2 text-[11px] text-emerald-400 font-mono",children:"$"}),r.jsx("input",{ref:j,value:u,onChange:S=>p(S.target.value),onKeyDown:C,disabled:m,placeholder:m?"ejecutando…":"comando…",className:"flex-1 bg-transparent font-mono text-[11px] text-foreground outline-none placeholder:text-muted-foreground/50 disabled:opacity-50",spellCheck:!1,autoComplete:"off"})]})]})}const cc="super-agent";function Vh(){return r.jsx(T_,{className:"relative z-10 w-px shrink-0 cursor-col-resize bg-border transition-colors hover:bg-primary/50 active:bg-primary/70"})}function yU(){return r.jsx(T_,{className:"relative z-10 h-px shrink-0 cursor-row-resize bg-border transition-colors hover:bg-primary/50 active:bg-primary/70"})}function jU(){const e=ot(),t=We("/projects",()=>ls.list()),s=x.useMemo(()=>t.data||[],[t.data]),[o,l]=x.useState(""),[c,u]=x.useState(null),[p,m]=x.useState(cc),[g,h]=x.useState([]),[b,v]=x.useState(""),[k,N]=x.useState(!1),[j,y]=x.useState(!0),[C,S]=x.useState(!0),[E,R]=x.useState(!1),[M,T]=x.useState(""),[O,D]=x.useState(!1),U=x.useRef(null),[L,I]=$c(),z=x.useRef(!1),[B,H]=x.useState([]),[$,q]=x.useState("chat"),X=x.useCallback(xe=>{R(!0),T(xe)},[]);x.useEffect(()=>{!o&&s.length&&l(String(s[0].id))},[o,s]);const Y=We(o?["code-sessions",o]:null,()=>Ba.sessions.list(o)),F=We(o?["agents",o]:null,()=>on.list(o)),K=We(o&&c?["code-session",o,c]:null,()=>Ba.sessions.get(o,c)),P=We(o&&c?["code-changes",o,c]:null,()=>Ba.changes(o,c));x.useEffect(()=>{const xe=Y.data||[];!c&&xe.length&&u(xe[0].id),c&&xe.length&&!xe.some(Le=>Le.id===c)&&u(xe[0]?.id??null)},[Y.data,c]),x.useEffect(()=>{K.data&&m(K.data.agentSlug||cc)},[K.data]),x.useEffect(()=>{k||(K.data?h(K.data.messages||[]):c||h([]))},[K.data,c,k]),x.useEffect(()=>()=>U.current?.abort(),[]);const G=K.data,Z=G?.mode==="plan"?"plan":"build",ee=G?.model||"",de=xe=>{xe===o||k||(l(xe),u(null),h([]))},fe=xe=>{k||xe===c||(u(xe),h([]))},se=async()=>{if(!(!o||k))try{const xe=await Ba.sessions.create(o,{title:f("code_module.untitled"),agentSlug:p!==cc?p:null});await Y.mutate(),u(xe.id),h([])}catch(xe){e.error(xe.message)}},oe=async(xe,Le)=>{const Ke=window.prompt(f("code_module.rename"),Le);if(!(!Ke||Ke===Le))try{await Ba.sessions.update(o,xe,{title:Ke}),await Y.mutate(),xe===c&&await K.mutate()}catch(it){e.error(it.message)}},me=async xe=>{if(!k&&window.confirm(f("code_module.delete_confirm")))try{await Ba.sessions.remove(o,xe),xe===c&&(u(null),h([])),await Y.mutate()}catch(Le){e.error(Le.message)}},Me=async xe=>{if(m(xe),!!c)try{await Ba.sessions.update(o,c,{agentSlug:xe!==cc?xe:null}),await Promise.all([K.mutate(),Y.mutate()])}catch(Le){e.error(Le.message)}},ie=x.useCallback(async xe=>{if(c)try{await Ba.sessions.update(o,c,xe),await Promise.all([K.mutate(),Y.mutate()])}catch(Le){e.error(Le.message)}},[o,c,K,Y,e]),pe=()=>{U.current?.abort(),N(!1)},ke=xe=>h(Le=>{const Ke=[...Le],it=Ke[Ke.length-1];return it&&it.role==="assistant"&&(Ke[Ke.length-1]=xe(it)),Ke}),je=async xe=>{const Le=(xe??b).trim();if(!Le||k||!o||!c)return;const Ke=new Date().toISOString();h(ft=>[...ft,{role:"user",parts:[{kind:"text",text:Le}],ts:Ke},{role:"assistant",parts:[],ts:Ke,pending:!0}]),v(""),N(!0);const it=new AbortController;U.current=it;const Xe=ft=>{if(ft.type==="error"){e.error(ft.error||f("modules_ui.code_stream_error"));return}ke(Ot=>x_(Ot,ft))};try{await Ba.stream(o,c,{prompt:Le},Xe,it.signal),ke(ft=>({...ft,pending:!1}))}catch(ft){it.signal.aborted?ke(Ot=>({...Ot,pending:!1,parts:[...Ot.parts,{kind:"text",text:f("code_module.stopped")}]})):(e.error(ft.message),h(Ot=>Ot.filter((Wt,Yt)=>Yt!==Ot.length-1)))}finally{U.current===it&&(U.current=null),N(!1),K.mutate(),Y.mutate(),P.mutate()}},Be=async xe=>{try{await navigator.clipboard.writeText(xe),e.info(f("modules_ui.code_copied"))}catch{}},He=x.useCallback(xe=>{q(xe),H(Le=>Le.some(Ke=>Ke.path===xe)?Le:[...Le,{path:xe,content:"",loading:!0}]),ge.post("/run",{cmd:`cat "${xe}"`,project:o}).then(Le=>{const Ke=Le.stdout||Le.stderr||f("modules_ui.code_file_empty");H(it=>it.map(Xe=>Xe.path===xe?{...Xe,content:Ke,loading:!1}:Xe))}).catch(Le=>{H(Ke=>Ke.map(it=>it.path===xe?{...it,content:f("modules_ui.code_file_error",{msg:Le.message}),loading:!1}:it))})},[o]),we=x.useCallback(xe=>{H(Le=>Le.filter(Ke=>Ke.path!==xe)),q(Le=>Le===xe?"chat":Le)},[]),Re=x.useCallback(xe=>{const Le=`artifacts/${xe}`;q(Le),H(Ke=>Ke.some(it=>it.path===Le)?Ke:[...Ke,{path:Le,content:"",loading:!0,artifactName:xe}]),Tr.read(o,xe).then(Ke=>{H(it=>it.map(Xe=>Xe.path===Le?{...Xe,content:Ke.content,loading:!1}:Xe))}).catch(Ke=>{H(it=>it.map(Xe=>Xe.path===Le?{...Xe,content:f("modules_ui.code_file_error",{msg:Ke.message}),loading:!1}:Xe))})},[o]);x.useEffect(()=>{if(z.current)return;const xe=L.get("pid"),Le=L.get("cmd"),Ke=L.get("edit");if(!(!xe||!Le&&!Ke)){if(String(o)!==String(xe)){l(String(xe));return}z.current=!0,Ke&&Re(Ke),Le&&X(Le.endsWith(" ")?Le:Le+" "),I({},{replace:!0})}},[L,o,Re,X,I]);const ve=x.useCallback(async(xe,Le)=>{const Ke=B.find(it=>it.path===xe);if(Ke?.artifactName)try{await Tr.write(o,Ke.artifactName,Le),H(it=>it.map(Xe=>Xe.path===xe?{...Xe,content:Le}:Xe)),e.info(f("modules_ui.code_saved"))}catch(it){e.error(it.message)}},[B,o,e]),Ce=!t.isLoading&&s.length>0,De=x.useMemo(()=>{const xe=[{value:cc,label:f("modules_ui.code_super_agent"),icon:dn,description:f("modules_ui.code_super_agent_desc")}],Le=(F.data||[]).map(Ke=>({value:Ke.slug,label:Ke.slug,icon:dn,description:Ke.description||Ke.role||void 0}));return[...xe,...Le]},[F.data]),Pe=x.useMemo(()=>g,[g]),Ie=x.useMemo(()=>Y.data?.find(xe=>xe.id===c)?.title||"",[Y.data,c]),re=x.useMemo(()=>s.find(xe=>String(xe.id)===o),[s,o]);JL(Ie);const[_e,qe]=x.useState(null),Ne=k?null:RN(g),Oe=Ne&&Ne.turnKey!==_e,et=xe=>{je(xe)},at=x.useCallback(()=>y(xe=>!xe),[]),vt=x.useCallback(()=>D(xe=>!xe),[]),Mt=x.useCallback(()=>R(xe=>!xe),[]),lt=x.useCallback(()=>S(xe=>!xe),[]),Rt=x.useMemo(()=>c?r.jsx("div",{className:"flex items-center gap-0.5",children:[{Icon:sS,open:j,toggle:at,title:f("modules_ui.code_panel_sessions")},{Icon:eS,open:O,toggle:vt,title:f("modules_ui.code_panel_tree")},{Icon:Ya,open:E,toggle:Mt,title:f("modules_ui.code_panel_terminal")},{Icon:KM,open:C,toggle:lt,title:f("modules_ui.code_panel_context")}].map(({Icon:xe,open:Le,toggle:Ke,title:it})=>r.jsx(Ge,{content:it,children:r.jsx("button",{type:"button",onClick:Ke,"data-active":Le,className:"rounded p-1 text-muted-fg transition-colors hover:bg-accent hover:text-accent-fg data-[active=true]:bg-accent data-[active=true]:text-accent-fg",children:r.jsx(xe,{className:"size-3.5"})})},it))}):null,[c,j,O,E,C,at,vt,Mt,lt]);return tP(Rt),r.jsx("div",{className:"flex h-full min-h-0 flex-col","data-testid":"screen-code",children:t.isLoading?r.jsx(rt,{}):Ce?r.jsxs(Ox,{orientation:"vertical",id:"code-layout-v",className:"min-h-0 flex-1",children:[r.jsx(fo,{id:"top",defaultSize:E?"55%":"100%",minSize:"20%",children:r.jsxs(Ox,{orientation:"horizontal",id:"code-layout",className:"h-full",children:[j&&r.jsxs(r.Fragment,{children:[r.jsx(fo,{id:"left",defaultSize:"14%",minSize:"8%",children:r.jsxs("aside",{className:"flex h-full flex-col",children:[r.jsx("div",{className:"shrink-0 border-b border-border p-2",children:r.jsx(nU,{projects:s,value:o,onChange:de,disabled:k})}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:r.jsx(sU,{sessions:Y.data||[],activeId:c,busy:k,onSelect:fe,onCreate:se,onRename:oe,onDelete:me})}),r.jsx("div",{className:"shrink-0 border-t border-border p-2",children:r.jsx(_t,{value:p,onChange:Me,options:De,disabled:k,showIcon:!0})})]})}),r.jsx(Vh,{})]}),O&&r.jsxs(r.Fragment,{children:[r.jsx(fo,{id:"tree",defaultSize:"13%",minSize:"8%",children:r.jsx("div",{className:"h-full",children:r.jsx(bU,{pid:o,projectPath:re?.path,onOpenFile:He})})}),r.jsx(Vh,{})]}),r.jsx(fo,{id:"main",defaultSize:"50%",minSize:"20%",children:r.jsxs("div",{className:"flex h-full flex-col",children:[B.length>0&&r.jsxs("div",{className:"flex shrink-0 items-center gap-0 overflow-x-auto border-b border-border",children:[r.jsxs("button",{type:"button",onClick:()=>q("chat"),"data-active":$==="chat",className:"flex shrink-0 items-center gap-1.5 border-r border-border px-3 py-2 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-accent/40 data-[active=true]:text-foreground",children:[r.jsx(Fx,{className:"size-3 shrink-0"}),f("modules_ui.code_chat_tab")]}),B.map(xe=>{const Le=xe.path.split("/").pop()??xe.path,Ke=$===xe.path;return r.jsxs("div",{"data-active":Ke,className:"group flex shrink-0 items-center gap-1 border-r border-border px-2 py-2 text-[11px] text-muted-foreground transition-colors hover:bg-accent/40 data-[active=true]:text-foreground",children:[r.jsx(Ge,{content:xe.path,children:r.jsx("button",{type:"button",onClick:()=>q(xe.path),className:"min-w-0 max-w-[140px] truncate font-mono",children:Le})}),r.jsx(Ge,{content:f("code_module.close"),children:r.jsx("button",{type:"button",onClick:()=>we(xe.path),className:"shrink-0 rounded p-0.5 opacity-60 hover:bg-accent hover:opacity-100",children:r.jsx(Ys,{className:"size-2.5"})})})]},xe.path)})]}),$==="chat"?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto","data-testid":"code-transcript",children:c?g.length?r.jsx(b_,{msgs:g,onCopy:Be}):r.jsx("div",{className:"grid h-full place-items-center p-6",children:r.jsx(bt,{children:f("code_module.empty_chat")})}):r.jsx("div",{className:"grid h-full place-items-center p-6",children:r.jsx(bt,{children:f("code_module.pick_project")})})}),Oe&&Ne&&r.jsx(EN,{turnKey:Ne.turnKey,questions:Ne.questions,onSubmit:et,onDismiss:()=>qe(Ne.turnKey),disabled:k})]}):r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:(()=>{const xe=B.find(Le=>Le.path===$);return xe?r.jsx(_U,{path:xe.path,content:xe.content,loading:xe.loading,onSave:xe.artifactName?Le=>ve(xe.path,Le):void 0}):null})()}),r.jsx("div",{className:"shrink-0 border-t border-border p-2","data-testid":"code-input",children:r.jsx(rU,{value:b,onValueChange:v,onSubmit:()=>void je(),onStop:pe,busy:k,disabled:!c,mode:Z,onModeChange:xe=>void ie({mode:xe}),model:ee,onModelChange:xe=>void ie({model:xe||null})})})]})}),C&&r.jsxs(r.Fragment,{children:[r.jsx(Vh,{}),r.jsx(fo,{id:"right",defaultSize:"22%",minSize:"15%",children:r.jsx("aside",{className:"flex h-full flex-col",children:r.jsx(hU,{pid:o,turns:Pe,changes:P.data,changesLoading:P.isLoading,onRefreshChanges:()=>void P.mutate(),session:K.data?{title:K.data.title,mode:K.data.mode,createdAt:K.data.createdAt,updatedAt:K.data.updatedAt,agentSlug:K.data.agentSlug??null}:null,onRunInTerminal:X,onEditArtifact:Re})})})]})]})}),E&&o&&r.jsxs(r.Fragment,{children:[r.jsx(yU,{}),r.jsx(fo,{id:"terminal",defaultSize:"45%",minSize:"10%",maxSize:"80%",children:r.jsx(vU,{pid:o,initCmd:M,onClose:Mt,className:"h-full"})})]})]}):r.jsx("div",{className:"grid flex-1 place-items-center",children:r.jsx(bt,{children:f("code_module.no_projects")})})})}function wU({open:e,onClose:t}){const{mutate:s}=wC(),o=Gn(),l=ot(),[c,u]=x.useState(""),[p,m]=x.useState(!1),[g,h]=x.useState(""),[b,v]=x.useState([]),[k,N]=x.useState(null),[j,y]=x.useState(""),[C,S]=x.useState(!1),[E,R]=x.useState(!1),M=async(D,U=!1)=>{S(!0),y("");try{const L=await Uj.dirs(D||"~");h(L.path),u(L.path),N(L.parent),v(L.entries)}catch(L){const I=L.message;y(I),U||l.error(I)}finally{S(!1)}};x.useEffect(()=>{e||(u(""),m(!1),h(""),v([]),N(null),y(""))},[e]);const T=async()=>{S(!0);try{const D=await Uj.pickDir(f("add_project.picker_prompt"));if("cancelled"in D)return;u(D.path);return}catch{m(!0),await M(c||"~")}finally{S(!1)}},O=async()=>{const D=c.trim();if(!D){l.error(f("add_project.path_required"));return}R(!0);try{const U=await ls.register(D);l.success(f("add_project.registered",{id:U.id})),await s("/projects"),t(),o(`/p/${U.id}`)}catch(U){l.error(U.message)}finally{R(!1)}};return r.jsx(On,{open:e,onClose:t,title:f("add_project.title"),description:f("add_project.subtitle"),footer:r.jsxs(r.Fragment,{children:[r.jsx(ce,{variant:"ghost",onClick:t,disabled:E,children:f("common.cancel")}),r.jsx(ce,{variant:"primary",onClick:O,loading:E,children:f("add_project.register")})]}),children:r.jsxs("div",{className:"space-y-3",children:[r.jsx(le,{label:f("add_project.path_label"),hint:f("add_project.path_hint"),children:r.jsxs("div",{className:"flex gap-2",children:[r.jsx(Ee,{autoFocus:!0,placeholder:f("add_project.path_placeholder"),value:c,onChange:D=>u(D.target.value),onKeyDown:D=>{D.key==="Enter"&&O()}}),r.jsxs(ce,{onClick:T,disabled:C,children:[r.jsx(_c,{size:14})," ",f("add_project.search_btn")]})]})}),p&&r.jsxs("div",{className:"rounded-md border border-border bg-muted/20",children:[r.jsxs("div",{className:"flex items-center justify-between border-b border-border px-3 py-2",children:[r.jsx("span",{className:"truncate font-mono text-xs text-muted-fg",children:g||c||"~"}),r.jsxs("div",{className:"flex gap-1",children:[r.jsx(ce,{size:"sm",variant:"ghost",onClick:()=>M("~"),disabled:C,children:r.jsx(BM,{size:13})}),r.jsx(ce,{size:"sm",variant:"ghost",onClick:()=>k&&M(k),disabled:!k||C,children:".."}),r.jsx(ce,{size:"sm",variant:"ghost",onClick:()=>m(!1),disabled:C,children:r.jsx(Ys,{size:13})})]})]}),r.jsxs("div",{className:"max-h-64 overflow-y-auto p-2",children:[C&&r.jsx(rt,{}),!C&&j&&r.jsx(bt,{children:f("add_project.browser_unavailable")}),!C&&!j&&b.length===0&&r.jsx(bt,{children:f("add_project.no_folders")}),!C&&!j&&b.map(D=>r.jsxs("button",{type:"button",onClick:()=>M(D),className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm hover:bg-accent",children:[r.jsx(Af,{size:14,className:"text-muted-fg"}),r.jsx("span",{className:"truncate",children:D.split("/").pop()}),r.jsx("span",{className:"ml-auto truncate font-mono text-[10px] text-muted-fg",children:D})]},D))]})]})]})})}function kU({onPaired:e}){const[t,s]=x.useState(""),[o,l]=x.useState(SU()),[c,u]=x.useState(!1),[p,m]=x.useState(null);async function g(){const h=t.trim();if(!h){m(f("pairing.err_required"));return}u(!0),m(null);try{const b=await Gl.confirm({pairing_id:h,label:o.trim()||void 0});po(b.token);try{localStorage.setItem(Tn.token,b.token)}catch{}e()}catch(b){m(CU(b)),u(!1)}}return r.jsx("div",{className:"flex min-h-[100dvh] w-full items-center justify-center overflow-y-auto bg-background p-4 text-foreground",children:r.jsxs("div",{className:"my-auto w-full max-w-md rounded-xl border border-border bg-card p-6 shadow-sm",children:[r.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[r.jsx("div",{className:"grid size-10 place-items-center rounded-lg bg-primary/10 text-primary",children:r.jsx(Gh,{size:20})}),r.jsxs("div",{children:[r.jsx("h1",{className:"text-base font-semibold",children:f("pairing.title")}),r.jsx("p",{className:"text-xs text-muted-fg",children:f("pairing.subtitle")})]})]}),r.jsxs("ol",{className:"mb-5 space-y-1.5 rounded-lg bg-muted/50 p-3 text-xs text-muted-fg",children:[r.jsx("li",{className:"font-medium text-foreground",children:f("pairing.steps_title")}),r.jsxs("li",{children:["1. ",f("pairing.step_1")]}),r.jsxs("li",{children:["2. ",f("pairing.step_2")]}),r.jsxs("li",{children:["3. ",f("pairing.step_3")]})]}),r.jsxs("form",{className:"space-y-3",onSubmit:h=>{h.preventDefault(),g()},children:[r.jsx(le,{label:f("pairing.code_label"),children:r.jsx(Ee,{value:t,onChange:h=>s(h.target.value),placeholder:f("pairing.code_ph"),spellCheck:!1,autoComplete:"off"})}),r.jsx(le,{label:f("pairing.label_label"),hint:f("pairing.revoke_hint"),children:r.jsx(Ee,{value:o,onChange:h=>l(h.target.value),placeholder:f("pairing.label_ph")})}),p&&r.jsx("p",{className:"rounded-md bg-destructive/10 px-3 py-2 text-xs text-destructive",children:p}),r.jsx(ce,{type:"submit",variant:"primary",size:"md",loading:c,className:"w-full justify-center",children:f(c?"pairing.linking":"pairing.submit")})]})]})})}function SU(){const e=navigator.userAgent;return/iPhone|iPad/.test(e)?"iPhone":/Android/.test(e)?"Android":/Mac/.test(e)?"Mac":/Windows/.test(e)?"Windows PC":/Linux/.test(e)?"Linux":"browser"}function CU(e){if(e instanceof Qc){if(e.status===410)return f("pairing.err_expired");if(e.status===404||e.status===409)return f("pairing.err_unknown")}return f("pairing.err_generic")}function NU({...e}){return r.jsx(PC,{"data-slot":"sheet",...e})}function EU({...e}){return r.jsx(LC,{"data-slot":"sheet-portal",...e})}function RU({className:e,...t}){return r.jsx(MC,{"data-slot":"sheet-overlay",className:Ct("fixed inset-0 z-50 bg-black/10 transition-opacity duration-150 data-ending-style:opacity-0 data-starting-style:opacity-0 supports-backdrop-filter:backdrop-blur-xs",e),...t})}function TU({className:e,children:t,side:s="right",showCloseButton:o=!0,...l}){return r.jsxs(EU,{children:[r.jsx(RU,{}),r.jsxs(DC,{"data-slot":"sheet-content","data-side":s,className:Ct("fixed z-50 flex flex-col gap-4 bg-popover bg-clip-padding text-sm text-popover-foreground shadow-lg transition duration-200 ease-in-out data-ending-style:opacity-0 data-starting-style:opacity-0 data-[side=bottom]:inset-x-0 data-[side=bottom]:bottom-0 data-[side=bottom]:h-auto data-[side=bottom]:border-t data-[side=bottom]:data-ending-style:translate-y-[2.5rem] data-[side=bottom]:data-starting-style:translate-y-[2.5rem] data-[side=left]:inset-y-0 data-[side=left]:left-0 data-[side=left]:h-full data-[side=left]:w-3/4 data-[side=left]:border-r data-[side=left]:data-ending-style:translate-x-[-2.5rem] data-[side=left]:data-starting-style:translate-x-[-2.5rem] data-[side=right]:inset-y-0 data-[side=right]:right-0 data-[side=right]:h-full data-[side=right]:w-3/4 data-[side=right]:border-l data-[side=right]:data-ending-style:translate-x-[2.5rem] data-[side=right]:data-starting-style:translate-x-[2.5rem] data-[side=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:h-auto data-[side=top]:border-b data-[side=top]:data-ending-style:translate-y-[-2.5rem] data-[side=top]:data-starting-style:translate-y-[-2.5rem] data-[side=left]:sm:max-w-sm data-[side=right]:sm:max-w-sm",e),...l,children:[t,o&&r.jsxs(dp,{"data-slot":"sheet-close",render:r.jsx(Wa,{variant:"ghost",className:"absolute top-3 right-3",size:"icon-sm"}),children:[r.jsx(Ys,{}),r.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function AU({className:e,...t}){return r.jsx("div",{"data-slot":"sheet-header",className:Ct("flex flex-col gap-0.5 p-4",e),...t})}function MU({className:e,...t}){return r.jsx(IC,{"data-slot":"sheet-title",className:Ct("font-heading text-base font-medium text-foreground",e),...t})}function OU({className:e,...t}){return r.jsx(OC,{"data-slot":"sheet-description",className:Ct("text-sm text-muted-foreground",e),...t})}function zU({value:e,projectPath:t,onPick:s}){const o=DU(e),l=o?LU(e):"",{data:c}=We(o?["/skills",t||""]:null,()=>fc.list(t)),u=c?.skills||[],p=x.useMemo(()=>{const m=l.toLowerCase();return m?u.filter(g=>g.slug.toLowerCase().includes(m)).slice(0,8):u.slice(0,8)},[u,l]);return!o||p.length===0?null:r.jsxs("div",{className:"rounded-xl border border-border bg-popover/95 text-sm shadow-md backdrop-blur",children:[r.jsx("ul",{role:"listbox",className:"max-h-64 overflow-y-auto py-1",children:p.map(m=>r.jsx("li",{children:r.jsxs("button",{type:"button",onClick:()=>s(m.slug),className:"flex w-full items-start gap-2 px-3 py-1.5 text-left hover:bg-accent hover:text-accent-foreground",children:[r.jsxs("code",{className:"rounded bg-muted px-1.5 py-0.5 text-[11px]",children:["/",m.slug]}),r.jsx("span",{className:"truncate text-xs text-muted-foreground",children:m.description})]})},m.slug))}),r.jsx("div",{className:"border-t border-border px-3 py-1.5 text-[10px] text-muted-foreground",children:"Type a name to filter · click to insert · the skill body will be loaded for this turn."})]})}function DU(e){return!!e.match(/^\s*\/([A-Za-z0-9_-]*)$/)}function LU(e){const t=e.match(/^\s*\/([A-Za-z0-9_-]*)$/);return t?t[1]:""}function PU(){try{const e=localStorage.getItem(Tn.robyChat);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>s&&Array.isArray(s.parts)&&!s.pending):[]}catch{return[]}}function IU({open:e,onOpenChange:t}){const s=ip(),o=ot(),[l,c]=x.useState(PU),[u,p]=x.useState(""),[m,g]=x.useState(!1),[h,b]=x.useState(""),v=x.useRef(null);x.useEffect(()=>{const S=l.filter(E=>!E.pending);try{S.length?localStorage.setItem(Tn.robyChat,JSON.stringify(S)):localStorage.removeItem(Tn.robyChat)}catch{}},[l]);const k=()=>{if(!m){c([]),p("");try{localStorage.removeItem(Tn.robyChat)}catch{}}};x.useEffect(()=>()=>v.current?.abort(),[]),x.useEffect(()=>{const S=E=>{const R=E.detail?.prompt;typeof R=="string"&&(t(!0),p(R))};return window.addEventListener("apx:roby-prompt",S),()=>window.removeEventListener("apx:roby-prompt",S)},[t]);const N=()=>{v.current?.abort(),g(!1)},j=S=>c(E=>{const R=[...E],M=R[R.length-1];return M?.role==="assistant"&&(R[R.length-1]=S(M)),R}),y=async()=>{const S=u.trim();if(!S||m)return;const E=new Date().toISOString(),R=l.filter(D=>!D.pending).map(D=>({role:D.role,content:Sx(D)}));c(D=>[...D,{role:"user",parts:[{kind:"text",text:S}],ts:E},{role:"assistant",parts:[],ts:E,pending:!0}]),p(""),g(!0);const M=new AbortController;v.current=M;let T=!1;const O=D=>{if(D?.type==="error"){T=!0,o.error(D.error||"error"),c(U=>{const L=[...U],I=L[L.length-1];return I?.role==="assistant"&&I.pending&&L.pop(),L});return}j(U=>x_(U,D))};try{await SC.stream(0,{prompt:S,previousMessages:R,model:h||void 0,channel:"web_sidebar"},O,M.signal),j(D=>({...D,pending:!1}))}catch(D){M.signal.aborted?j(U=>({...U,pending:!1,parts:[...U.parts,{kind:"text",text:f("project.chat.stopped_marker")}]})):T||(o.error(D.message),c(U=>{const L=[...U],I=L[L.length-1];return I?.role==="assistant"&&I.pending&&L.pop(),L}))}finally{v.current===M&&(v.current=null),g(!1)}},C=async S=>{try{await navigator.clipboard.writeText(S),o.info(f("project.chat.copied"))}catch{}};return r.jsx(NU,{open:e,onOpenChange:t,children:r.jsxs(TU,{side:"right",className:"flex w-full flex-col gap-0 p-0 sm:max-w-xl data-[side=right]:sm:max-w-xl",children:[r.jsxs(AU,{className:"pr-12",children:[r.jsxs(MU,{className:"flex items-center gap-2",children:[r.jsx(dn,{size:18})," ",f("superagent.title",{persona:s}),r.jsx("span",{className:"text-xs font-normal text-muted-fg",children:f("superagent.badge")})]}),r.jsx(OU,{children:f("superagent.desc")})]}),r.jsx("div",{className:"flex-1 overflow-y-auto",children:l.length===0?r.jsx("p",{className:"mt-6 text-center text-sm text-muted-fg",children:f("superagent.empty",{persona:s})}):r.jsx(b_,{msgs:l,onCopy:C})}),r.jsx(NN,{msgs:l}),r.jsxs("div",{className:"border-t border-border p-3",children:[r.jsx("div",{className:"mb-1.5",children:r.jsx(zU,{value:u,onPick:S=>p(`/${S} `)})}),r.jsx(g_,{value:u,onValueChange:p,onSubmit:()=>void y(),onStop:N,busy:m,placeholder:f("superagent.placeholder"),footer:r.jsx(h_,{value:h,onChange:b,disabled:m})}),r.jsx("div",{className:"mt-1.5 flex justify-end",children:r.jsxs(Wa,{size:"xs",variant:"ghost",onClick:k,disabled:m||l.length===0,children:[r.jsx(an,{className:"size-3"})," ",f("superagent.new_chat")]})})]})]})})}function BU(){const e=navigator.userAgent;return/iPhone|iPad/.test(e)?"iPhone":/Android/.test(e)?"Android":/Mac/.test(e)?"Mac":/Windows/.test(e)?"Windows PC":/Linux/.test(e)?"Linux":"browser"}function UU(){const[e,t]=x.useState({status:"loading"}),[s,o]=x.useState(0),l=x.useCallback(()=>{t({status:"loading"}),o(c=>c+1)},[]);return x.useEffect(()=>{let c=!1;return(async()=>{try{const h=await fetch("/health");if(!h.ok)throw new Error(`HTTP ${h.status}`)}catch(h){c||t({status:"error",reason:String(h)});return}const u=window.location.hash.replace(/^#/,""),p=new URLSearchParams(u),m=p.get("pair");if(m){history.replaceState(null,"",window.location.pathname+window.location.search);try{const h=await Gl.confirm({pairing_id:m,label:BU(),kind:"web"});po(h.token);try{localStorage.setItem(Tn.token,h.token)}catch{}c||t({status:"ok"});return}catch{}}const g=p.get("token");if(g){po(g);try{localStorage.setItem(Tn.token,g)}catch{}history.replaceState(null,"",window.location.pathname+window.location.search)}else try{const h=localStorage.getItem(Tn.token);h&&po(h)}catch{}try{const h=await fetch("/admin/web-token");if(h.ok){const b=await h.json();if(b?.token){po(b.token);try{localStorage.setItem(Tn.token,b.token)}catch{}}}}catch{}if(!Qb()){c||t({status:"unpaired"});return}try{await ge.get("/projects"),c||t({status:"ok"})}catch(h){if(h instanceof Qc&&(h.status===401||h.status===403)){po(null);try{localStorage.removeItem(Tn.token)}catch{}c||t({status:"unpaired"})}else c||t({status:"error",reason:String(h)})}})(),()=>{c=!0}},[s]),{...e,reload:l}}function HU(){const e=UU();return e.status==="loading"?r.jsx(_k,{text:f("daemon.connecting")}):e.status==="error"?r.jsx(_k,{mood:"sad",text:f("daemon.unreachable"),sub:`${f("daemon.unreachable_hint")}
649
649
 
650
650
  ${e.reason}`}):e.status==="unpaired"?r.jsx(kU,{onPaired:e.reload}):r.jsx($L,{children:r.jsx(sz,{delay:0,children:r.jsx(VU,{})})})}function VU(){const e=Gn(),t=Wn(),[s,o]=$c(),{theme:l,toggle:c}=Wx(),u=s.get("action")==="add-project",[p,m]=x.useState(!1),g=()=>{const b=new URLSearchParams(s);b.delete("action"),o(b,{replace:!0})},h=()=>{const b=new URLSearchParams(s);b.set("action","add-project"),o(b)};return r.jsx(XL,{children:r.jsxs("div",{className:"flex h-screen w-screen overflow-hidden bg-background text-foreground","data-testid":"app-shell",children:[r.jsx(nL,{onSelect:b=>e(b),onOpenRoby:()=>m(!0),onOpenAddProject:h}),r.jsxs("main",{className:"m-2 ml-0 flex min-w-0 flex-1 flex-col overflow-hidden rounded-xl border border-border bg-card shadow-sm",children:[r.jsx(qU,{onToggleTheme:c,isDark:l==="dark",pathname:t.pathname}),r.jsx("div",{className:"flex-1 overflow-y-auto",children:r.jsxs(Uk,{children:[r.jsx(Kt,{path:"/",element:r.jsx(KL,{})}),r.jsx(Kt,{path:"/settings/*",element:r.jsx(gB,{})}),r.jsx(Kt,{path:"/m/desktop/*",element:r.jsx(bB,{})}),r.jsx(Kt,{path:"/m/code/*",element:r.jsx(jU,{})}),r.jsx(Kt,{path:"/p/:pid/*",element:r.jsx(I8,{})}),r.jsx(Kt,{path:"*",element:r.jsx(KU,{})})]})})]}),r.jsx(wU,{open:u,onClose:g}),r.jsx(IU,{open:p,onOpenChange:m})]})})}function qU({onToggleTheme:e,isDark:t,pathname:s}){const{projects:o}=Wc(),l=ZL(),c=s.split("/").filter(Boolean),u=c[0]==="p"?o.find(N=>String(N.id)===c[1]):void 0,p=c[0]==="settings"?GU(c[1]):c[0]==="p"?YU(c[2]):"",m=c[0]==="p"&&c[1]==="0",g=u?.name||u?.path?.split("/").pop()||f("nav.project"),h=s==="/"?f("topbar.breadcrumb_root"):c[0]==="settings"?[f("topbar.breadcrumb_root"),f("nav.settings"),p].filter(Boolean).join(" › "):c[0]==="m"?[f("topbar.breadcrumb_root"),FU(c[1]),l].filter(Boolean).join(" › "):c[0]==="p"?m?[f("topbar.breadcrumb_root"),f("topbar.breadcrumb_base"),p].filter(Boolean).join(" › "):[f("topbar.breadcrumb_root"),f("topbar.breadcrumb_projects"),g,p].filter(Boolean).join(" › "):f("topbar.breadcrumb_root"),b=s==="/"?"":c[0]==="settings"?f("settings.subtitle"):c[0]==="p"?m?f("base.subtitle"):u?`${NC(u.kind)} · ${u.path}`:"":"",v=QL(),k=eP();return r.jsxs("header",{className:"flex h-10 shrink-0 items-center gap-2 border-b border-border/50 px-3",children:[v&&r.jsx(mD,{collapsed:v.collapsed,onToggle:v.toggle}),r.jsxs("span",{className:"min-w-0 flex-1 truncate text-[11px] tracking-wide text-muted-fg",children:[h,b&&r.jsxs("span",{className:"text-muted-fg/50",children:[" · ",b]})]}),k,r.jsx($U,{}),r.jsx(Ge,{content:f(t?"topbar.light":"topbar.dark"),children:r.jsx("button",{type:"button","data-testid":"theme-toggle",onClick:e,className:"shrink-0 rounded-md p-1.5 text-muted-fg hover:bg-accent hover:text-accent-fg",children:t?r.jsx(e3,{size:14}):r.jsx(GM,{size:14})})})]})}function $U(){const e=Gb(),t=s=>{s!==e&&(fC(s),window.location.reload())};return r.jsxs(cC,{children:[r.jsxs(uC,{"data-testid":"lang-menu",title:f("topbar.lang_toggle"),className:"flex shrink-0 items-center gap-1 rounded-md p-1.5 text-muted-fg hover:bg-accent hover:text-accent-fg",children:[r.jsx(HM,{size:14}),r.jsx("span",{className:"text-[11px] font-medium uppercase",children:e})]}),r.jsx(dC,{align:"end",children:r.jsx(oD,{value:e,onValueChange:s=>t(s),children:pC.map(s=>r.jsx(lD,{value:s.value,children:s.label},s.value))})})]})}function FU(e){switch(e){case"desktop":return f("nav.modules.desktop");case"code":return f("nav.modules.code");default:return e||""}}function GU(e){switch(e){case"super-agent":return f("settings.tabs.super_agent");case"engines":return f("settings.tabs.engines");case"telegram":return f("settings.tabs.telegram");case"devices":return f("settings.tabs.devices");case"voice":return f("nav.modules.voice");case"deck":return f("nav.modules.deck");case"desktop":return f("nav.modules.desktop");case"appearance":return f("settings.appearance");case"config":case"advanced":return f("settings.tabs.advanced");case"identity":default:return e||""}}function YU(e){switch(e){case"chat":return f("project.nav.chat");case"telegram":return f("project.nav.telegram");case"agents":return f("project.nav.agents");case"routines":return f("project.nav.routines");case"tasks":return f("project.nav.tasks");case"mcps":return f("project.nav.mcps");case"artifacts":return f("project.nav.artifacts");case"config":return f("project.nav.config");case"workspaces":return f("base.workspaces_title");case"models":return f("settings.tabs.engines");case"agent-defaults":return f("base.defaults_title");case"sessions":return f("base.sessions_title");case"logs":return f("project.nav.logs");case"memories":return f("project.nav.memories");default:return""}}function _k({text:e,sub:t,mood:s="happy"}){return r.jsx("div",{className:"grid h-screen w-screen place-items-center bg-background text-foreground",children:r.jsxs("div",{className:"flex flex-col items-center text-center",children:[r.jsx(WC,{mood:s,className:"mb-4 text-xs"}),r.jsx("div",{className:"text-foreground",children:e}),t&&r.jsx("pre",{className:"mt-2 max-w-xl whitespace-pre-wrap text-sm text-muted-fg",children:t})]})})}function KU(){const e=Gn();return r.jsx(ZC,{testId:"screen-not-found",mood:"confused",title:f("not_found.title"),titleClassName:"text-7xl",message:f("not_found.message"),action:r.jsx(Wa,{variant:"outline",onClick:()=>e("/"),children:f("not_found.home")})})}NT.createRoot(document.getElementById("root")).render(r.jsx(Hc.StrictMode,{children:r.jsx(WA,{children:r.jsx(l3,{children:r.jsx(HU,{})})})}));
651
- //# sourceMappingURL=index-B34JqOED.js.map
651
+ //# sourceMappingURL=index-DaE_memX.js.map