@agentprojectcontext/apx 1.50.0 → 1.50.1

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.50.0",
3
+ "version": "1.50.1",
4
4
  "description": "APX — unified CLI + daemon for the Agent Project Context (APC) standard.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -32,7 +32,20 @@ export function register(app, { project, config }) {
32
32
  if (!p) return;
33
33
  const conv = readConversation(p.storagePath, req.params.slug, req.params.id);
34
34
  if (!conv) return res.status(404).json({ error: "conversation not found" });
35
- res.json(conv);
35
+ // Shape the response as the `ConversationDetail` the web client expects:
36
+ // `messages[]` (mapped from the parsed `turns`) + id/agent/channel. Without
37
+ // this the client's `detail.messages.filter(...)` throws on every load.
38
+ res.json({
39
+ id: req.params.id,
40
+ agent_slug: req.params.slug,
41
+ channel: conv.fm?.channel,
42
+ messages: (conv.turns || []).map((t) => ({
43
+ role: t.role,
44
+ content: t.content,
45
+ ts: t.ts,
46
+ })),
47
+ meta: conv.fm || {},
48
+ });
36
49
  });
37
50
 
38
51
  async function handleCompact(req, res, filename) {
@@ -636,7 +636,7 @@ Stable facts that any agent should know…`,agents_title:"Agent memories",agents
636
636
  ${a.join(`
637
637
  `)}`}function pI(e){const t=[];for(const a of e.parts)if(a.kind==="text"&&a.text)t.push(a.text);else if(a.kind==="tool"&&a.tool==="ask_questions"){const o=fI(a);o&&t.push(o)}return t.join(`
638
638
 
639
- `).trim()}const mI=e=>[{kind:"text",text:e}];function gI(e){if(!e||typeof e!="object")return!1;const t=e;return"error"in t&&!!t.error}function f_(e,t){const a=o=>({...e,notes:[...e.notes||[],o]});switch(t.type){case"model_start":return t.model?{...e,model:t.model}:e;case"model_routed":{const o=t.model?{...e,model:t.model}:e;return t.from_fallback?{...o,notes:[...o.notes||[],`routing fell back → ${t.model}`]}:o}case"engine_failed":return a(`engine ${t.model||"?"} failed → ${t.retry_with||"retry"}`);case"model_retry":return a(`retry (${t.reason||"?"})`);case"tools_suppressed":return a(`tools suppressed: ${(t.tools||[]).join(", ")}`);case"skill_inspector":{const o=t.inspector;return!o||!o.loaded?.length&&!o.hinted?.length?e:{...e,inspector:{embedder:o.embedder,loaded:o.loaded||[],hinted:o.hinted||[]}}}case"assistant_text":return t.text?{...e,parts:[...e.parts,{kind:"text",text:t.text}]}:e;case"tool_start":return t.trace?{...e,parts:[...e.parts,{kind:"tool",id:t.trace.id,tool:t.trace.tool,args:t.trace.args,status:"running"}]}:e;case"tool_deduped":return t.trace?{...e,parts:e.parts.map(o=>o.kind==="tool"&&o.id===t.trace.id?{...o,status:"deduped"}:o)}:e;case"tool_result":if(!t.trace)return e;{const o=gI(t.trace.result);return{...e,parts:e.parts.map(l=>l.kind==="tool"&&l.id===t.trace.id?{...l,result:t.trace.result,status:o?"error":l.status==="deduped"?"deduped":"done"}:l)}}case"final":return{...e,pending:!1,usage:t.result?.usage??e.usage,model:e.model??t.result?.name,parts:t.result?.text&&!e.parts.some(o=>o.kind==="text")?[...e.parts,{kind:"text",text:t.result.text}]:e.parts};default:{const o=t.delta||t.content||"";if(!o)return e;const l=[...e.parts],c=l[l.length-1];return c&&c.kind==="text"?l[l.length-1]={...c,text:c.text+o}:l.push({kind:"text",text:o}),{...e,parts:l}}}}function hI(e,t){const[a,o]=x.useState([]),[l,c]=x.useState(!1),[u,p]=x.useState(void 0),m=x.useRef(null),g=x.useRef(void 0),h=x.useCallback(y=>{o(S=>{const C=[...S],E=C[C.length-1];return E&&E.role==="assistant"&&(C[C.length-1]=y(E)),C})},[]),b=x.useCallback(y=>{if(y.type==="error"){t?.(y.error||f("shared_ui.err_stream"));return}h(S=>f_(S,y))},[h,t]),v=x.useCallback(async(y,S={})=>{const C=y.trim();if(!C||l)return;const E=()=>new Date().toISOString(),R=a.map(T=>({role:T.role,content:pI(T)}));if(o(T=>[...T,{role:"user",parts:mI(C),ts:E()},{role:"assistant",parts:[],ts:E(),pending:!0}]),c(!0),S.agentSlug){try{const T=await an.chat(e,S.agentSlug,{prompt:C,conversation_id:g.current,model:S.model||void 0,channel:"web"});g.current=T.conversation_id,p(T.conversation_id),h(M=>({...M,pending:!1,model:T.engine,parts:[{kind:"text",text:T.text}]}))}catch(T){t?.(T?.message||f("shared_ui.err_chat_failed")),o(M=>M.filter((z,L)=>L!==M.length-1))}finally{c(!1)}return}const A=new AbortController;m.current=A;try{await hC.stream(e,{prompt:C,previousMessages:R,model:S.model||void 0,channel:"web"},b,A.signal),h(T=>({...T,pending:!1}))}catch(T){A.signal.aborted?h(M=>({...M,pending:!1,parts:[...M.parts,{kind:"text",text:f("code_module.stopped")}]})):(t?.(T?.message||f("shared_ui.err_stream_failed")),o(M=>M.filter((z,L)=>L!==M.length-1)))}finally{c(!1),m.current=null}},[e,a,l,b,h,t]),k=x.useCallback(()=>m.current?.abort(),[]),N=x.useCallback(()=>{l||(g.current=void 0,p(void 0),o([]))},[l]),j=x.useCallback(async(y,S)=>{if(!l)try{const E=(await Fb.get(e,y,S)).messages.filter(R=>R.role==="user"||R.role==="assistant").map(R=>({role:R.role,parts:[{kind:"text",text:R.content}],ts:R.ts||new Date().toISOString()}));g.current=S,p(S),o(E)}catch(C){t?.(C?.message||f("shared_ui.err_load_conversation"))}},[e,l,t]);return{msgs:a,send:v,stop:k,clear:N,load:j,streaming:l,conversationId:u}}function xI({msg:e,isLast:t,isAskAnswer:a,onCopy:o}){const l=e.role==="user",c=_x(e),u=e.parts.some(p=>p.kind==="tool");if(l&&a){const p=_x(e);if(xN(p))return r.jsx(dI,{text:p})}return r.jsxs("div",{className:Me("group flex items-start gap-2",l?"justify-end":"justify-start"),children:[!l&&r.jsx("span",{className:"mt-0.5 grid size-7 shrink-0 place-items-center rounded-full bg-muted text-muted-foreground",children:r.jsx(un,{size:14})}),r.jsxs("div",{className:Me("flex min-w-0 flex-col gap-1.5",l?"items-end":"w-full max-w-[85%]"),children:[!l&&e.notes&&e.notes.length>0&&r.jsx("div",{className:"flex flex-col gap-0.5",children:e.notes.map((p,m)=>r.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-amber-400/80",children:[r.jsx(TM,{size:10})," ",p]},m))}),!l&&e.inspector&&(e.inspector.loaded?.length||e.inspector.hinted?.length)?r.jsx(Ye,{content:f("shared_ui.skill_inspector_title",{embedder:e.inspector.embedder||"RAG"}),children:r.jsxs("div",{className:"flex flex-wrap items-center gap-1 text-[10px] text-sky-400/90",children:[r.jsx(pa,{size:10}),e.inspector.loaded?.map(p=>r.jsx("span",{className:"rounded bg-sky-500/15 px-1 py-0.5 font-mono",children:p},`l-${p}`)),e.inspector.hinted?.map(p=>r.jsxs("span",{className:"rounded border border-sky-500/30 px-1 py-0.5 font-mono opacity-70",children:[p,"?"]},`h-${p}`))]})}):null,e.parts.map((p,m)=>p.kind==="tool"?p.tool==="ask_questions"&&!l?r.jsx(uI,{part:p,pending:!!t},`${p.id}-${m}`):r.jsx(iI,{part:p},`${p.id}-${m}`):p.text?r.jsx("div",{className:Me("whitespace-pre-wrap rounded-2xl px-3 py-2 text-sm leading-relaxed shadow-sm",l?"rounded-br-sm border border-emerald-500/30 bg-emerald-500/10 text-foreground dark:bg-emerald-500/15":"w-full rounded-bl-sm border border-border bg-card text-foreground"),children:p.text},m):null),!l&&e.pending&&e.parts.length===0&&r.jsx("div",{className:"rounded-2xl rounded-bl-sm border border-border bg-card px-3 py-2 text-sm text-muted-foreground",children:"…"}),r.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:[r.jsx("span",{children:bI(e.ts)}),!l&&e.model&&r.jsxs("span",{className:"font-mono",children:["· ",e.model]}),!l&&u&&r.jsxs("span",{children:["· ",f("shared_ui.tools_count",{n:e.parts.filter(p=>p.kind==="tool").length})]}),o&&c&&r.jsx(Ye,{content:f("chat_ui.copy"),children:r.jsxs("button",{type:"button",onClick:()=>o(c),className:"inline-flex items-center gap-1 hover:text-foreground","aria-label":f("chat_ui.copy"),children:[r.jsx(Ec,{size:10})," ",f("chat_ui.copy")]})})]})]}),l&&r.jsx("span",{className:"mt-0.5 grid size-7 shrink-0 place-items-center rounded-full bg-muted text-muted-foreground",children:r.jsx($x,{size:14})})]})}function bI(e){try{return new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}catch{return e}}function p_({msgs:e,onCopy:t}){const a=x.useRef(null);if(x.useEffect(()=>{a.current?.scrollIntoView({behavior:"smooth",block:"end"})},[e]),e.length===0)return r.jsx("div",{className:"grid h-full place-items-center p-6",children:r.jsx(xt,{children:f("project.chat.empty")})});const o=e.length-1;return r.jsxs("div",{className:"space-y-4 px-3 py-4",children:[e.map((l,c)=>r.jsx(xI,{msg:l,isLast:c===o,isAskAnswer:_I(e,c),onCopy:t},c)),r.jsx("div",{ref:a})]})}function _I(e,t){const a=e[t];if(!a||a.role!=="user")return!1;const o=e[t-1];if(!o||o.role!=="assistant")return!1;for(let l=o.parts.length-1;l>=0;l--){const c=o.parts[l];if(c.kind==="tool")return c.tool==="ask_questions"}return!1}function vI(e){if(!e)return;const t=e.path??e.file??e.filename;return typeof t=="string"?t:void 0}function bN({msgs:e}){const[t,a]=x.useState(!1),{inTok:o,outTok:l,toolCount:c,changed:u,model:p}=x.useMemo(()=>{let g=0,h=0,b=0,v;const k=new Set,N=[];for(const j of e)if(j.role==="assistant"){j.usage&&(g+=j.usage.input_tokens||0,h+=j.usage.output_tokens||0),j.model&&(v=j.model);for(const y of j.parts)if(y.kind==="tool"&&(b+=1,hN.has(y.tool)&&y.status!=="error")){const S=vI(y.args);S&&!k.has(S)&&(k.add(S),N.push({path:S,tool:y.tool}))}}return{inTok:g,outTok:h,toolCount:b,changed:N,model:v}},[e]),m=o+l;return m===0&&c===0?null:r.jsxs("div",{className:"shrink-0 border-t border-border bg-card/40 text-[11px]",children:[r.jsxs("button",{type:"button",onClick:()=>u.length>0&&a(g=>!g),className:Me("flex w-full items-center gap-3 px-4 py-1.5 text-muted-foreground",u.length>0&&"hover:text-foreground"),children:[r.jsxs("span",{className:"flex items-center gap-1",children:[r.jsx(Rf,{size:12})," ",ih(m)," tok",r.jsxs("span",{className:"text-muted-foreground/60",children:["(",ih(o),"↑ / ",ih(l),"↓)"]})]}),c>0&&r.jsxs("span",{className:"flex items-center gap-1",children:[r.jsx(Wl,{size:12})," ",c," tools"]}),u.length>0&&r.jsxs("span",{className:"flex items-center gap-1 text-violet-400",children:[r.jsx(Yd,{size:12})," ",u.length," archivos"]}),p&&r.jsx("span",{className:"ml-auto font-mono text-muted-foreground/70",children:p}),u.length>0&&r.jsx(Wa,{className:Me("size-3 shrink-0 transition-transform",t&&"rotate-180")})]}),t&&u.length>0&&r.jsx("ul",{className:"max-h-40 space-y-0.5 overflow-y-auto border-t border-border/60 px-4 py-2",children:u.map(g=>r.jsxs("li",{className:"flex items-center gap-2 font-mono text-[11px]",children:[r.jsx(Yd,{size:11,className:"shrink-0 text-violet-400"}),r.jsx("span",{className:"truncate",children:g.path}),r.jsx("span",{className:"ml-auto shrink-0 text-[10px] text-muted-foreground/60",children:g.tool==="write_file"?"write":"edit"})]},g.path))})]})}function ih(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function jl(){return{picked:new Set,text:"",skipped:!1}}function rw(e,t){const a=[];return e.forEach((o,l)=>{const c=t[l]||jl();if(c.skipped){a.push(`- ${o.question}
639
+ `).trim()}const mI=e=>[{kind:"text",text:e}];function gI(e){if(!e||typeof e!="object")return!1;const t=e;return"error"in t&&!!t.error}function f_(e,t){const a=o=>({...e,notes:[...e.notes||[],o]});switch(t.type){case"model_start":return t.model?{...e,model:t.model}:e;case"model_routed":{const o=t.model?{...e,model:t.model}:e;return t.from_fallback?{...o,notes:[...o.notes||[],`routing fell back → ${t.model}`]}:o}case"engine_failed":return a(`engine ${t.model||"?"} failed → ${t.retry_with||"retry"}`);case"model_retry":return a(`retry (${t.reason||"?"})`);case"tools_suppressed":return a(`tools suppressed: ${(t.tools||[]).join(", ")}`);case"skill_inspector":{const o=t.inspector;return!o||!o.loaded?.length&&!o.hinted?.length?e:{...e,inspector:{embedder:o.embedder,loaded:o.loaded||[],hinted:o.hinted||[]}}}case"assistant_text":return t.text?{...e,parts:[...e.parts,{kind:"text",text:t.text}]}:e;case"tool_start":return t.trace?{...e,parts:[...e.parts,{kind:"tool",id:t.trace.id,tool:t.trace.tool,args:t.trace.args,status:"running"}]}:e;case"tool_deduped":return t.trace?{...e,parts:e.parts.map(o=>o.kind==="tool"&&o.id===t.trace.id?{...o,status:"deduped"}:o)}:e;case"tool_result":if(!t.trace)return e;{const o=gI(t.trace.result);return{...e,parts:e.parts.map(l=>l.kind==="tool"&&l.id===t.trace.id?{...l,result:t.trace.result,status:o?"error":l.status==="deduped"?"deduped":"done"}:l)}}case"final":return{...e,pending:!1,usage:t.result?.usage??e.usage,model:e.model??t.result?.name,parts:t.result?.text&&!e.parts.some(o=>o.kind==="text")?[...e.parts,{kind:"text",text:t.result.text}]:e.parts};default:{const o=t.delta||t.content||"";if(!o)return e;const l=[...e.parts],c=l[l.length-1];return c&&c.kind==="text"?l[l.length-1]={...c,text:c.text+o}:l.push({kind:"text",text:o}),{...e,parts:l}}}}function hI(e,t){const[a,o]=x.useState([]),[l,c]=x.useState(!1),[u,p]=x.useState(void 0),m=x.useRef(null),g=x.useRef(void 0),h=x.useCallback(y=>{o(S=>{const C=[...S],E=C[C.length-1];return E&&E.role==="assistant"&&(C[C.length-1]=y(E)),C})},[]),b=x.useCallback(y=>{if(y.type==="error"){t?.(y.error||f("shared_ui.err_stream"));return}h(S=>f_(S,y))},[h,t]),v=x.useCallback(async(y,S={})=>{const C=y.trim();if(!C||l)return;const E=()=>new Date().toISOString(),R=a.map(T=>({role:T.role,content:pI(T)}));if(o(T=>[...T,{role:"user",parts:mI(C),ts:E()},{role:"assistant",parts:[],ts:E(),pending:!0}]),c(!0),S.agentSlug){try{const T=await an.chat(e,S.agentSlug,{prompt:C,conversation_id:g.current,model:S.model||void 0,channel:"web"});g.current=T.conversation_id,p(T.conversation_id),h(M=>({...M,pending:!1,model:T.engine,parts:[{kind:"text",text:T.text}]}))}catch(T){t?.(T?.message||f("shared_ui.err_chat_failed")),o(M=>M.filter((z,L)=>L!==M.length-1))}finally{c(!1)}return}const A=new AbortController;m.current=A;try{await hC.stream(e,{prompt:C,previousMessages:R,model:S.model||void 0,channel:"web"},b,A.signal),h(T=>({...T,pending:!1}))}catch(T){A.signal.aborted?h(M=>({...M,pending:!1,parts:[...M.parts,{kind:"text",text:f("code_module.stopped")}]})):(t?.(T?.message||f("shared_ui.err_stream_failed")),o(M=>M.filter((z,L)=>L!==M.length-1)))}finally{c(!1),m.current=null}},[e,a,l,b,h,t]),k=x.useCallback(()=>m.current?.abort(),[]),N=x.useCallback(()=>{l||(g.current=void 0,p(void 0),o([]))},[l]),j=x.useCallback(async(y,S)=>{if(!l)try{const E=((await Fb.get(e,y,S)).messages??[]).filter(R=>R.role==="user"||R.role==="assistant").map(R=>({role:R.role,parts:[{kind:"text",text:R.content}],ts:R.ts||new Date().toISOString()}));g.current=S,p(S),o(E)}catch(C){t?.(C?.message||f("shared_ui.err_load_conversation"))}},[e,l,t]);return{msgs:a,send:v,stop:k,clear:N,load:j,streaming:l,conversationId:u}}function xI({msg:e,isLast:t,isAskAnswer:a,onCopy:o}){const l=e.role==="user",c=_x(e),u=e.parts.some(p=>p.kind==="tool");if(l&&a){const p=_x(e);if(xN(p))return r.jsx(dI,{text:p})}return r.jsxs("div",{className:Me("group flex items-start gap-2",l?"justify-end":"justify-start"),children:[!l&&r.jsx("span",{className:"mt-0.5 grid size-7 shrink-0 place-items-center rounded-full bg-muted text-muted-foreground",children:r.jsx(un,{size:14})}),r.jsxs("div",{className:Me("flex min-w-0 flex-col gap-1.5",l?"items-end":"w-full max-w-[85%]"),children:[!l&&e.notes&&e.notes.length>0&&r.jsx("div",{className:"flex flex-col gap-0.5",children:e.notes.map((p,m)=>r.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-amber-400/80",children:[r.jsx(TM,{size:10})," ",p]},m))}),!l&&e.inspector&&(e.inspector.loaded?.length||e.inspector.hinted?.length)?r.jsx(Ye,{content:f("shared_ui.skill_inspector_title",{embedder:e.inspector.embedder||"RAG"}),children:r.jsxs("div",{className:"flex flex-wrap items-center gap-1 text-[10px] text-sky-400/90",children:[r.jsx(pa,{size:10}),e.inspector.loaded?.map(p=>r.jsx("span",{className:"rounded bg-sky-500/15 px-1 py-0.5 font-mono",children:p},`l-${p}`)),e.inspector.hinted?.map(p=>r.jsxs("span",{className:"rounded border border-sky-500/30 px-1 py-0.5 font-mono opacity-70",children:[p,"?"]},`h-${p}`))]})}):null,e.parts.map((p,m)=>p.kind==="tool"?p.tool==="ask_questions"&&!l?r.jsx(uI,{part:p,pending:!!t},`${p.id}-${m}`):r.jsx(iI,{part:p},`${p.id}-${m}`):p.text?r.jsx("div",{className:Me("whitespace-pre-wrap rounded-2xl px-3 py-2 text-sm leading-relaxed shadow-sm",l?"rounded-br-sm border border-emerald-500/30 bg-emerald-500/10 text-foreground dark:bg-emerald-500/15":"w-full rounded-bl-sm border border-border bg-card text-foreground"),children:p.text},m):null),!l&&e.pending&&e.parts.length===0&&r.jsx("div",{className:"rounded-2xl rounded-bl-sm border border-border bg-card px-3 py-2 text-sm text-muted-foreground",children:"…"}),r.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:[r.jsx("span",{children:bI(e.ts)}),!l&&e.model&&r.jsxs("span",{className:"font-mono",children:["· ",e.model]}),!l&&u&&r.jsxs("span",{children:["· ",f("shared_ui.tools_count",{n:e.parts.filter(p=>p.kind==="tool").length})]}),o&&c&&r.jsx(Ye,{content:f("chat_ui.copy"),children:r.jsxs("button",{type:"button",onClick:()=>o(c),className:"inline-flex items-center gap-1 hover:text-foreground","aria-label":f("chat_ui.copy"),children:[r.jsx(Ec,{size:10})," ",f("chat_ui.copy")]})})]})]}),l&&r.jsx("span",{className:"mt-0.5 grid size-7 shrink-0 place-items-center rounded-full bg-muted text-muted-foreground",children:r.jsx($x,{size:14})})]})}function bI(e){try{return new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}catch{return e}}function p_({msgs:e,onCopy:t}){const a=x.useRef(null);if(x.useEffect(()=>{a.current?.scrollIntoView({behavior:"smooth",block:"end"})},[e]),e.length===0)return r.jsx("div",{className:"grid h-full place-items-center p-6",children:r.jsx(xt,{children:f("project.chat.empty")})});const o=e.length-1;return r.jsxs("div",{className:"space-y-4 px-3 py-4",children:[e.map((l,c)=>r.jsx(xI,{msg:l,isLast:c===o,isAskAnswer:_I(e,c),onCopy:t},c)),r.jsx("div",{ref:a})]})}function _I(e,t){const a=e[t];if(!a||a.role!=="user")return!1;const o=e[t-1];if(!o||o.role!=="assistant")return!1;for(let l=o.parts.length-1;l>=0;l--){const c=o.parts[l];if(c.kind==="tool")return c.tool==="ask_questions"}return!1}function vI(e){if(!e)return;const t=e.path??e.file??e.filename;return typeof t=="string"?t:void 0}function bN({msgs:e}){const[t,a]=x.useState(!1),{inTok:o,outTok:l,toolCount:c,changed:u,model:p}=x.useMemo(()=>{let g=0,h=0,b=0,v;const k=new Set,N=[];for(const j of e)if(j.role==="assistant"){j.usage&&(g+=j.usage.input_tokens||0,h+=j.usage.output_tokens||0),j.model&&(v=j.model);for(const y of j.parts)if(y.kind==="tool"&&(b+=1,hN.has(y.tool)&&y.status!=="error")){const S=vI(y.args);S&&!k.has(S)&&(k.add(S),N.push({path:S,tool:y.tool}))}}return{inTok:g,outTok:h,toolCount:b,changed:N,model:v}},[e]),m=o+l;return m===0&&c===0?null:r.jsxs("div",{className:"shrink-0 border-t border-border bg-card/40 text-[11px]",children:[r.jsxs("button",{type:"button",onClick:()=>u.length>0&&a(g=>!g),className:Me("flex w-full items-center gap-3 px-4 py-1.5 text-muted-foreground",u.length>0&&"hover:text-foreground"),children:[r.jsxs("span",{className:"flex items-center gap-1",children:[r.jsx(Rf,{size:12})," ",ih(m)," tok",r.jsxs("span",{className:"text-muted-foreground/60",children:["(",ih(o),"↑ / ",ih(l),"↓)"]})]}),c>0&&r.jsxs("span",{className:"flex items-center gap-1",children:[r.jsx(Wl,{size:12})," ",c," tools"]}),u.length>0&&r.jsxs("span",{className:"flex items-center gap-1 text-violet-400",children:[r.jsx(Yd,{size:12})," ",u.length," archivos"]}),p&&r.jsx("span",{className:"ml-auto font-mono text-muted-foreground/70",children:p}),u.length>0&&r.jsx(Wa,{className:Me("size-3 shrink-0 transition-transform",t&&"rotate-180")})]}),t&&u.length>0&&r.jsx("ul",{className:"max-h-40 space-y-0.5 overflow-y-auto border-t border-border/60 px-4 py-2",children:u.map(g=>r.jsxs("li",{className:"flex items-center gap-2 font-mono text-[11px]",children:[r.jsx(Yd,{size:11,className:"shrink-0 text-violet-400"}),r.jsx("span",{className:"truncate",children:g.path}),r.jsx("span",{className:"ml-auto shrink-0 text-[10px] text-muted-foreground/60",children:g.tool==="write_file"?"write":"edit"})]},g.path))})]})}function ih(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function jl(){return{picked:new Set,text:"",skipped:!1}}function rw(e,t){const a=[];return e.forEach((o,l)=>{const c=t[l]||jl();if(c.skipped){a.push(`- ${o.question}
640
640
  → (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)";a.push(`- ${o.question}
641
641
  → ${m}`)}),a.join(`
642
642
  `)}function _N({turnKey:e,questions:t,onSubmit:a,onDismiss:o,disabled:l}){const c=t.length,[u,p]=x.useState(0),[m,g]=x.useState(()=>t.map(()=>jl()));x.useEffect(()=>{p(0),g(t.map(()=>jl()))},[e,t]);const h=t[u],b=m[u]||jl(),v=!!h?.options&&h.options.length>0,k=!!h?.multiSelect,N=h?.allowText!==!1,j=T=>{g(M=>{const z=[...M],L=z[u]||jl();return z[u]={...L,...T,skipped:!1},z})},y=T=>{g(M=>{const z=[...M],L=z[u]||jl(),D=new Set(L.picked);return k?D.has(T)?D.delete(T):D.add(T):(D.clear(),D.add(T)),z[u]={...L,picked:D,skipped:!1},z})},S=x.useMemo(()=>!0,[]),C=u===c-1,E=()=>p(T=>Math.max(0,T-1)),R=()=>{if(C){a(rw(t,m));return}p(T=>Math.min(c-1,T+1))},A=()=>{if(g(T=>{const M=[...T];return M[u]={picked:new Set,text:"",skipped:!0},M}),C){const T=m.map((M,z)=>z===u?{picked:new Set,text:"",skipped:!0}:M);a(rw(t,T))}else p(T=>Math.min(c-1,T+1))};return x.useEffect(()=>{const T=M=>{if(l)return;const z=M.target?.tagName?.toLowerCase(),L=z==="input"||z==="textarea";if(M.key==="Enter"&&(M.metaKey||M.ctrlKey)){M.preventDefault(),R();return}if(!L&&v&&/^[1-9]$/.test(M.key)){const D=parseInt(M.key,10)-1;D<(h?.options?.length||0)&&(M.preventDefault(),y(D))}};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)}),!h||c===0?null:r.jsxs("div",{className:Me("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(Gs,{className:"size-3.5"})})]}),r.jsxs("div",{className:"space-y-1 px-2 py-2",children:[v&&h.options.map((T,M)=>{const z=b.picked.has(M);return r.jsxs("button",{type:"button",onClick:()=>y(M),className:Me("flex w-full items-start gap-2 rounded-md border border-transparent px-2 py-1.5 text-left transition",z?"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:Me("mt-0.5 grid size-4 shrink-0 place-items-center rounded border",z?"border-emerald-500 bg-emerald-500 text-white":"border-border bg-background"),children:z&&r.jsx("span",{className:"text-[10px] leading-none",children:"✓"})}):r.jsx("span",{className:Me("mt-0.5 grid size-4 shrink-0 place-items-center rounded border font-mono text-[10px]",z?"border-emerald-500 bg-emerald-500 text-white":"border-border bg-muted text-muted-foreground"),children:M+1})]},`${M}:${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:A,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:!S,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(C?"ask_panel.submit":"ask_panel.next"),r.jsx(fM,{className:"size-3 opacity-60"})]})]})]})]})}function yI(e){if(typeof e=="string")return{question:e,options:[],multiSelect:!1,allowText:!0};if(!e||typeof e!="object")return null;const t=e,a=typeof t.question=="string"?t.question:"";if(!a)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:a,header:typeof t.header=="string"?t.header:void 0,options:l,multiSelect:t.multiSelect===!0,allowText:t.allowText!==!1}}function vN(e){if(!e.length)return null;const t=e[e.length-1];if(t.role!=="assistant")return null;let a=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"){a=h,o=g;break}}if(!a||o<0)return null;let l=null;if(typeof a.result=="string")try{l=JSON.parse(a.result)}catch{l=null}else a.result&&typeof a.result=="object"&&(l=a.result);const c=[];Array.isArray(a.args?.questions)&&c.push(a.args.questions),l&&Array.isArray(l.questions)&&c.push(l.questions);let u=[];for(const g of c)if(u=g.map(yI).filter(h=>!!h),u.length>0)break;return u.length?{turnKey:`${t.ts||""}#${o}`,questions:u}:null}const vx={live:{label:"Live",icon:pa,order:0},telegram:{label:"Telegram",icon:Fs,order:1},voice:{label:"Voice",icon:Gk,order:2},desktop:{label:"Desktop",icon:Hx,order:3},web:{label:"Web",icon:Ux,order:4},a2a:{label:"Agent ↔ Agent",icon:un,order:5},schedule:{label:"Schedule",icon:GM,order:6},other:{label:"Other",icon:Ef,order:7}};function jI(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 wI({pid:e,slug:t,onLoaded:a}){const{data:o}=et(`/projects/${e}/agents/${t}/conversations`,()=>Fb.list(e,t),{revalidateOnFocus:!1});return x.useEffect(()=>{a(t,o)},[t,o]),null}function kI({pid:e,agents:t,superAgentSlug:a,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=(M,z)=>{z&&N(L=>{const D=L[M];return D&&D.length===z.length&&D===z?L:{...L,[M]:z}})},y=x.useMemo(()=>{const M=[];for(const z of t)for(const L of k[z.slug]||[])M.push({...L,agent_slug:L.agent_slug||z.slug});return M},[t,k]),S=x.useMemo(()=>{const M=p.trim().toLowerCase();return y.filter(z=>!(g&&z.agent_slug!==g||M&&!`${z.title||""} ${z.id} ${z.agent_slug}`.toLowerCase().includes(M)))},[y,p,g]),C=x.useMemo(()=>{const M=new Map;for(const z of S){const L=jI(z.channel),D=M.get(L);D?D.push(z):M.set(L,[z])}return Array.from(M.entries()).map(([z,L])=>({key:z,items:L.sort((D,H)=>new Date(H.started_at||0).getTime()-new Date(D.started_at||0).getTime())})).sort((z,L)=>vx[z.key].order-vx[L.key].order)},[S]),E=x.useMemo(()=>{if(g===a)return[{slug:a,label:o}];const M=[];g||M.push({slug:a,label:o});for(const z of t)g&&z.slug!==g||M.push({slug:z.slug,label:z.slug});return M},[t,g,a,o]),R=x.useMemo(()=>[{value:"",label:f("project.chat.list.all_agents")},{value:a,label:o},...t.map(M=>({value:M.slug,label:M.slug}))],[t,a,o]),A=y.length+E.length,T=Object.keys(k).length>0||t.length===0;return r.jsxs("aside",{className:"flex h-full w-72 shrink-0 flex-col border-r border-border bg-card/30",children:[t.map(M=>r.jsx(wI,{pid:e,slug:M.slug,onLoaded:j},M.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:A})})]}),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(rn,{className:"size-3"})," ",f("project.chat.list.new")]})]}),r.jsxs("div",{className:"space-y-2 border-b border-border p-2",children:[r.jsx(Re,{value:p,onChange:M=>m(M.target.value),placeholder:f("project.chat.list.search")}),r.jsx(bt,{value:g,onChange:h,options:R})]}),r.jsxs("div",{className:"flex-1 space-y-3 overflow-y-auto p-2",children:[!T&&r.jsx("div",{className:"px-2 py-1",children:r.jsx(lt,{})}),E.length>0&&r.jsx(ow,{keyName:"live",count:E.length,collapsed:!!b.live,onToggle:()=>v(M=>({...M,live:!M.live})),children:E.map(M=>{const z=M.slug===a,L=l.kind==="live"&&l.agentSlug===M.slug;return r.jsx(lw,{title:z?M.label:f("project.chat.list.live_with",{slug:M.slug}),subtitle:f("project.chat.list.live_subtitle"),badge:z?"super":M.slug,selected:L,onClick:()=>c({kind:"live",agentSlug:M.slug})},`live-${M.slug}`)})}),C.map(M=>r.jsx(ow,{keyName:M.key,count:M.items.length,collapsed:!!b[M.key],onToggle:()=>v(z=>({...z,[M.key]:!z[M.key]})),children:M.items.map(z=>{const L=l.kind==="conv"&&l.agentSlug===z.agent_slug&&l.convId===z.id;return r.jsx(lw,{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:L,onClick:()=>c({kind:"conv",agentSlug:z.agent_slug,convId:z.id})},`${z.agent_slug}-${z.id}`)})},M.key)),T&&y.length===0&&r.jsx("p",{className:"px-3 py-6 text-center text-xs text-muted-fg",children:f("project.chat.list.empty")})]})]})}function ow({keyName:e,count:t,collapsed:a,onToggle:o,children:l}){const c=vx[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:[a?r.jsx(Zl,{className:"size-3"}):r.jsx(Wa,{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})]}),!a&&r.jsx("div",{className:"space-y-0.5",children:l})]})}function lw({title:e,subtitle:t,badge:a,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(cM,{className:"size-2.5"}),SI(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}),a&&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($x,{className:"size-2.5"}),a]})]})]})}function SI(e){if(!e)return"";const t=new Date(e).getTime();if(!Number.isFinite(t))return"";const a=Date.now()-t,o=Math.floor(a/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 Td="__super_agent__";function CI({pid:e}){const t=rt(),[a]=Cf(),o=et(`/projects/${e}/agents`,()=>an.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,streaming:j,conversationId:y}=hI(e,V=>t.error(V)),S=rp(),C=a.get("agent"),[E,R]=x.useState(C?{kind:"live",agentSlug:C}:{kind:"live",agentSlug:Td}),A=o.data||[],T=V=>V===Td,M=x.useMemo(()=>E.kind==="live"?A.find(V=>V.slug===E.agentSlug):A.find(V=>V.slug===E.agentSlug),[A,E]),z=T(E.agentSlug);x.useEffect(()=>{E.kind==="conv"?N(E.agentSlug,E.convId):y&&k()},[E.kind,E.kind==="conv"?E.convId:E.agentSlug]);const L=async V=>{if(z){await b(V,{model:u||void 0});return}M&&await b(V,{model:u||void 0,agentSlug:M.slug})},D=async V=>{try{await navigator.clipboard.writeText(V),t.info(f("project.chat.copied"))}catch{}},H=()=>{R({kind:"live",agentSlug:Td}),k()},I=z?f("project.chat.superagent_title",{persona:S}):E.kind==="conv"?E.convId:f("project.chat.title"),B=z?f("project.chat.superagent_subtitle",{persona:S}):E.kind==="conv"?f("project.chat.loaded_subtitle",{slug:E.agentSlug}):f("project.chat.subtitle");return o.isLoading?r.jsx(lt,{}):r.jsxs("div",{className:"flex h-full overflow-hidden rounded-xl border border-border bg-card/40",children:[r.jsx(kI,{pid:e,agents:A,superAgentSlug:Td,superAgentLabel:f("agents_ui.super_agent_label",{persona:S}),selected:E,onSelect:R,onNewChat:H}),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:I}),r.jsx("p",{className:"truncate text-[11px] text-muted-fg",children:B})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[z?r.jsx(Fe,{tone:"success",children:f("agents_ui.super_agent_badge")}):M?.model&&r.jsx(Fe,{tone:"info",children:M.model}),E.kind==="conv"&&r.jsx(Fe,{tone:"info",children:y||"…"}),!A.length&&!z&&r.jsxs(ie,{variant:"primary",size:"sm",onClick:()=>c(!0),children:[r.jsx(rn,{size:14})," ",f("project.chat.create_agent")]}),r.jsxs(ie,{variant:"ghost",size:"sm",disabled:j||h.length===0,onClick:H,children:[r.jsx(cs,{size:13})," ",f("project.chat.clear")]})]})]}),r.jsx("div",{className:"flex-1 overflow-y-auto",children:h.length?r.jsx(p_,{msgs:h,onCopy:D}):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(bN,{msgs:h}),(()=>{const V=j?null:vN(h);return!V||V.turnKey===m?null:r.jsx(_N,{turnKey:V.turnKey,questions:V.questions,onSubmit:G=>void L(G),onDismiss:()=>g(V.turnKey),disabled:j})})(),r.jsx(sI,{onSend:L,onStop:v,streaming:j,model:u,onModelChange:p})]}),r.jsx(NI,{open:l,pid:e,onClose:()=>c(!1),onCreated:()=>{c(!1),o.mutate()}})]})}function NI({open:e,onClose:t,onCreated:a,pid:o}){const l=rt(),[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 an.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),a()}catch(y){l.error(y.message)}finally{N(!1)}};return r.jsx(An,{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(ie,{variant:"ghost",onClick:t,disabled:k,children:f("common.cancel")}),r.jsx(ie,{variant:"primary",onClick:j,loading:k,children:f("common.create")})]}),children:r.jsxs("div",{className:"space-y-3",children:[r.jsx(ue,{label:"slug",children:r.jsx(Re,{autoFocus:!0,value:c,onChange:y=>u(y.target.value),placeholder:"master"})}),r.jsx(ue,{label:f("project.chat.role_label"),children:r.jsx(Re,{value:p,onChange:y=>m(y.target.value),placeholder:"master"})}),r.jsx(ue,{label:f("project.chat.model_label"),hint:f("project.chat.model_hint"),children:r.jsx(Re,{value:g,onChange:y=>h(y.target.value)})}),r.jsx(Qt,{checked:b,onChange:v,label:f("project.chat.master_label")})]})})}function EI({pid:e}){const t=rt(),{project:a}=Gb(e),{channels:o,isLoading:l,mutate:c}=Jb(),u=String(e),p=a?.name||a?.path?.split("/").pop()||u,m=`proj-${u}`,g=o.find(M=>M.project===u||M.project===p||M.name===m),[h,b]=x.useState(!!g),[v,k]=x.useState(""),[N,j]=x.useState(""),[y,S]=x.useState(""),[C,E]=x.useState(!0),[R,A]=x.useState(!1);if(x.useEffect(()=>{g?(b(!0),k(""),j(g.chat_id||""),S(g.route_to_agent||""),E(g.respond_with_engine??!0)):(b(!1),k(""),j(""),S(""),E(!0))},[g?.name,g?.chat_id,g?.route_to_agent]),l)return r.jsx(lt,{});const T=async()=>{A(!0);try{if(!h){g&&(await Tn.channels.remove(g.name),t.success(f("project.telegram.cleared"))),await c();return}const M={name:g?.name||m,project:u,chat_id:N,route_to_agent:y,respond_with_engine:C,...v?{bot_token:v}:{}};g?await Tn.channels.patch(g.name,M):await Tn.channels.upsert(M),t.success(f("project.telegram.saved")),await c(),k("")}catch(M){t.error(M.message)}finally{A(!1)}};return r.jsx(Ke,{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(Fe,{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(ue,{label:f("project.telegram.bot_token"),hint:g?.bot_token?`${Ar(g.bot_token)} ${f("telegram_ui.empty_keep")}`:f("project.telegram.bot_hint_none"),children:r.jsx(Re,{type:"password",value:v,onChange:M=>k(M.target.value),placeholder:g?.bot_token?Ar(g.bot_token):""})}),r.jsx(ue,{label:f("project.telegram.chat_id"),children:r.jsx(Re,{value:N,onChange:M=>j(M.target.value)})}),r.jsx(ue,{label:f("project.telegram.route_agent"),hint:f("project.telegram.route_hint"),children:r.jsx(Re,{value:y,onChange:M=>S(M.target.value)})})]}),r.jsx(Qt,{checked:C,onChange:E,label:f("project.telegram.respond_engine")})]}),r.jsx("div",{className:"pt-2",children:r.jsx(ie,{variant:"primary",loading:R,onClick:T,children:f("common.save")})}),!h&&!g&&r.jsx(xt,{children:f("project.telegram.no_override")})]})})}function yN({load:e,save:t,rows:a=10,placeholder:o}){const l=rt(),[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(lt,{});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(Un,{rows:a,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(ie,{size:"sm",variant:"primary",loading:g,disabled:!b,onClick:v,children:[r.jsx(Af,{size:12})," ",f("project.memories.save_btn")]})]})]})}function RI({pid:e,agent:t}){const[a,o]=x.useState(!1),l=t.is_master?Fa:un;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:[a?r.jsx(Wa,{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]})]}),a&&r.jsx("div",{className:"border-t border-border p-3",children:r.jsx(yN,{rows:8,load:()=>an.memory.get(e,t.slug).then(c=>c.body),save:c=>an.memory.put(e,t.slug,c).then(()=>{})})})]})}function TI({pid:e}){const t=et(`/projects/${e}/agents`,()=>an.list(e));return r.jsxs("div",{className:"space-y-6",children:[r.jsx(Ke,{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(Gd,{className:"size-4 text-white"})}),r.jsx("div",{className:"min-w-0 flex-1",children:r.jsx(yN,{rows:12,load:()=>rs.memory.get(e).then(a=>a.body),save:a=>rs.memory.put(e,a).then(()=>{}),placeholder:f("project.memories.project_ph")})})]})}),r.jsxs(Ke,{title:f("project.memories.agents_title"),description:f("project.memories.agents_desc"),children:[t.isLoading&&r.jsx(lt,{}),!t.isLoading&&(t.data?.length??0)===0&&r.jsx(xt,{children:f("project.memories.no_agents")}),r.jsx("ul",{className:"space-y-2",children:(t.data||[]).map(a=>r.jsx(RI,{pid:e,agent:a},a.slug))})]})]})}function AI(e,t){var a,o=1;e==null&&(e=0),t==null&&(t=0);function l(){var c,u=a.length,p,m=0,g=0;for(c=0;c<u;++c)p=a[c],m+=p.x,g+=p.y;for(m=(m/u-e)*o,g=(g/u-t)*o,c=0;c<u;++c)p=a[c],p.x-=m,p.y-=g}return l.initialize=function(c){a=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 MI(e){const t=+this._x.call(null,e),a=+this._y.call(null,e);return jN(this.cover(t,a),t,a,e)}function jN(e,t,a,o){if(isNaN(t)||isNaN(a))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,S,C;if(!c)return e._root=u,e;for(;c.length;)if((j=t>=(b=(p+g)/2))?p=b:g=b,(y=a>=(v=(m+h)/2))?m=v:h=v,l=c,!(c=c[S=y<<1|j]))return l[S]=u,e;if(k=+e._x.call(null,c.data),N=+e._y.call(null,c.data),t===k&&a===N)return u.next=c,l?l[S]=u:e._root=u,e;do l=l?l[S]=new Array(4):e._root=new Array(4),(j=t>=(b=(p+g)/2))?p=b:g=b,(y=a>=(v=(m+h)/2))?m=v:h=v;while((S=y<<1|j)===(C=(N>=v)<<1|k>=b));return l[C]=c,l[S]=u,e}function OI(e){var t,a,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(a=0;a<o;++a)isNaN(l=+this._x.call(null,t=e[a]))||isNaN(c=+this._y.call(null,t))||(u[a]=l,p[a]=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),a=0;a<o;++a)jN(this,u[a],p[a],e[a]);return this}function zI(e,t){if(isNaN(e=+e)||isNaN(t=+t))return this;var a=this._x0,o=this._y0,l=this._x1,c=this._y1;if(isNaN(a))l=(a=Math.floor(e))+1,c=(o=Math.floor(t))+1;else{for(var u=l-a||1,p=this._root,m,g;a>e||e>=l||o>t||t>=c;)switch(g=(t<o)<<1|e<a,m=new Array(4),m[g]=p,p=m,u*=2,g){case 0:l=a+u,c=o+u;break;case 1:a=l-u,c=o+u;break;case 2:l=a+u,o=c-u;break;case 3:a=l-u,o=c-u;break}this._root&&this._root.length&&(this._root=p)}return this._x0=a,this._y0=o,this._x1=l,this._y1=c,this}function DI(){var e=[];return this.visit(function(t){if(!t.length)do e.push(t.data);while(t=t.next)}),e}function PI(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 Gn(e,t,a,o,l){this.node=e,this.x0=t,this.y0=a,this.x1=o,this.y1=l}function LI(e,t,a){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 Gn(k,l,c,h,b)),a==null?a=1/0:(l=e-a,c=t-a,h=e+a,b=t+a,a*=a);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,S=(p+g)/2;v.push(new Gn(k[3],y,S,m,g),new Gn(k[2],u,S,y,g),new Gn(k[1],y,p,m,S),new Gn(k[0],u,p,y,S)),(j=(t>=S)<<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 C=e-+this._x.call(null,k.data),E=t-+this._y.call(null,k.data),R=C*C+E*E;if(R<a){var A=Math.sqrt(a=R);l=e-A,c=t-A,h=e+A,b=t+A,o=k.data}}return o}function II(e){if(isNaN(h=+this._x.call(null,e))||isNaN(b=+this._y.call(null,e)))return this;var t,a=this._root,o,l,c,u=this._x0,p=this._y0,m=this._x1,g=this._y1,h,b,v,k,N,j,y,S;if(!a)return this;if(a.length)for(;;){if((N=h>=(v=(u+m)/2))?u=v:m=v,(j=b>=(k=(p+g)/2))?p=k:g=k,t=a,!(a=a[y=j<<1|N]))return this;if(!a.length)break;(t[y+1&3]||t[y+2&3]||t[y+3&3])&&(o=t,S=y)}for(;a.data!==e;)if(l=a,!(a=a.next))return this;return(c=a.next)&&delete a.next,l?(c?l.next=c:delete l.next,this):t?(c?t[y]=c:delete t[y],(a=t[0]||t[1]||t[2]||t[3])&&a===(t[3]||t[2]||t[1]||t[0])&&!a.length&&(o?o[S]=a:this._root=a),this):(this._root=c,this)}function BI(e){for(var t=0,a=e.length;t<a;++t)this.remove(e[t]);return this}function UI(){return this._root}function HI(){var e=0;return this.visit(function(t){if(!t.length)do++e;while(t=t.next)}),e}function VI(e){var t=[],a,o=this._root,l,c,u,p,m;for(o&&t.push(new Gn(o,this._x0,this._y0,this._x1,this._y1));a=t.pop();)if(!e(o=a.node,c=a.x0,u=a.y0,p=a.x1,m=a.y1)&&o.length){var g=(c+p)/2,h=(u+m)/2;(l=o[3])&&t.push(new Gn(l,g,h,p,m)),(l=o[2])&&t.push(new Gn(l,c,h,g,m)),(l=o[1])&&t.push(new Gn(l,g,u,p,h)),(l=o[0])&&t.push(new Gn(l,c,u,g,h))}return this}function qI(e){var t=[],a=[],o;for(this._root&&t.push(new Gn(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 Gn(c,u,p,h,b)),(c=l[1])&&t.push(new Gn(c,h,p,m,b)),(c=l[2])&&t.push(new Gn(c,u,b,h,g)),(c=l[3])&&t.push(new Gn(c,h,b,m,g))}a.push(o)}for(;o=a.pop();)e(o.node,o.x0,o.y0,o.x1,o.y1);return this}function $I(e){return e[0]}function FI(e){return arguments.length?(this._x=e,this):this._x}function GI(e){return e[1]}function YI(e){return arguments.length?(this._y=e,this):this._y}function m_(e,t,a){var o=new g_(t??$I,a??GI,NaN,NaN,NaN,NaN);return e==null?o:o.addAll(e)}function g_(e,t,a,o,l,c){this._x=e,this._y=t,this._x0=a,this._y0=o,this._x1=l,this._y1=c,this._root=void 0}function iw(e){for(var t={data:e.data},a=t;e=e.next;)a=a.next={data:e.data};return t}var Zn=m_.prototype=g_.prototype;Zn.copy=function(){var e=new g_(this._x,this._y,this._x0,this._y0,this._x1,this._y1),t=this._root,a,o;if(!t)return e;if(!t.length)return e._root=iw(t),e;for(a=[{source:t,target:e._root=new Array(4)}];t=a.pop();)for(var l=0;l<4;++l)(o=t.source[l])&&(o.length?a.push({source:o,target:t.target[l]=new Array(4)}):t.target[l]=iw(o));return e};Zn.add=MI;Zn.addAll=OI;Zn.cover=zI;Zn.data=DI;Zn.extent=PI;Zn.find=LI;Zn.remove=II;Zn.removeAll=BI;Zn.root=UI;Zn.size=HI;Zn.visit=VI;Zn.visitAfter=qI;Zn.x=FI;Zn.y=YI;function go(e){return function(){return e}}function Tr(e){return(e()-.5)*1e-6}function KI(e){return e.x+e.vx}function XI(e){return e.y+e.vy}function QI(e){var t,a,o,l=1,c=1;typeof e!="function"&&(e=go(e==null?1:+e));function u(){for(var g,h=t.length,b,v,k,N,j,y,S=0;S<c;++S)for(b=m_(t,KI,XI).visitAfter(p),g=0;g<h;++g)v=t[g],j=a[v.index],y=j*j,k=v.x+v.vx,N=v.y+v.vy,b.visit(C);function C(E,R,A,T,M){var z=E.data,L=E.r,D=j+L;if(z){if(z.index>v.index){var H=k-z.x-z.vx,I=N-z.y-z.vy,B=H*H+I*I;B<D*D&&(H===0&&(H=Tr(o),B+=H*H),I===0&&(I=Tr(o),B+=I*I),B=(D-(B=Math.sqrt(B)))/B*l,v.vx+=(H*=B)*(D=(L*=L)/(y+L)),v.vy+=(I*=B)*D,z.vx-=H*(D=1-D),z.vy-=I*D)}return}return R>k+D||T<k-D||A>N+D||M<N-D}}function p(g){if(g.data)return g.r=a[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(a=new Array(h),g=0;g<h;++g)b=t[g],a[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:go(+g),m(),u):e},u}function ZI(e){return e.index}function cw(e,t){var a=e.get(t);if(!a)throw new Error("node not found: "+t);return a}function WI(e){var t=ZI,a=b,o,l=go(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 S=0,C=e.length;S<h;++S)for(var E=0,R,A,T,M,z,L,D;E<C;++E)R=e[E],A=R.source,T=R.target,M=T.x+T.vx-A.x-A.vx||Tr(g),z=T.y+T.vy-A.y-A.vy||Tr(g),L=Math.sqrt(M*M+z*z),L=(L-c[E])/L*y*o[E],M*=L,z*=L,T.vx-=M*(D=m[E]),T.vy-=z*D,A.vx+=M*(D=1-D),A.vy+=z*D}function k(){if(u){var y,S=u.length,C=e.length,E=new Map(u.map((A,T)=>[t(A,T,u),A])),R;for(y=0,p=new Array(S);y<C;++y)R=e[y],R.index=y,typeof R.source!="object"&&(R.source=cw(E,R.source)),typeof R.target!="object"&&(R.target=cw(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(C);y<C;++y)R=e[y],m[y]=p[R.source.index]/(p[R.source.index]+p[R.target.index]);o=new Array(C),N(),c=new Array(C),j()}}function N(){if(u)for(var y=0,S=e.length;y<S;++y)o[y]=+a(e[y],y,e)}function j(){if(u)for(var y=0,S=e.length;y<S;++y)c[y]=+l(e[y],y,e)}return v.initialize=function(y,S){u=y,g=S,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?(a=typeof y=="function"?y:go(+y),N(),v):a},v.distance=function(y){return arguments.length?(l=typeof y=="function"?y:go(+y),j(),v):l},v}var JI={value:()=>{}};function wN(){for(var e=0,t=arguments.length,a={},o;e<t;++e){if(!(o=arguments[e]+"")||o in a||/[\s.]/.test(o))throw new Error("illegal type: "+o);a[o]=[]}return new Vd(a)}function Vd(e){this._=e}function e8(e,t){return e.trim().split(/^|\s+/).map(function(a){var o="",l=a.indexOf(".");if(l>=0&&(o=a.slice(l+1),a=a.slice(0,l)),a&&!t.hasOwnProperty(a))throw new Error("unknown type: "+a);return{type:a,name:o}})}Vd.prototype=wN.prototype={constructor:Vd,on:function(e,t){var a=this._,o=e8(e+"",a),l,c=-1,u=o.length;if(arguments.length<2){for(;++c<u;)if((l=(e=o[c]).type)&&(l=t8(a[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)a[l]=uw(a[l],e.name,t);else if(t==null)for(l in a)a[l]=uw(a[l],e.name,null);return this},copy:function(){var e={},t=this._;for(var a in t)e[a]=t[a].slice();return new Vd(e)},call:function(e,t){if((l=arguments.length-2)>0)for(var a=new Array(l),o=0,l,c;o<l;++o)a[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,a)},apply:function(e,t,a){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,a)}};function t8(e,t){for(var a=0,o=e.length,l;a<o;++a)if((l=e[a]).name===t)return l.value}function uw(e,t,a){for(var o=0,l=e.length;o<l;++o)if(e[o].name===t){e[o]=JI,e=e.slice(0,o).concat(e.slice(o+1));break}return a!=null&&e.push({name:t,value:a}),e}var Gl=0,hc=0,ac=0,kN=1e3,_f,xc,vf=0,ko=0,fp=0,Lc=typeof performance=="object"&&performance.now?performance:Date,SN=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function CN(){return ko||(SN(n8),ko=Lc.now()+fp)}function n8(){ko=0}function yx(){this._call=this._time=this._next=null}yx.prototype=NN.prototype={constructor:yx,restart:function(e,t,a){if(typeof e!="function")throw new TypeError("callback is not a function");a=(a==null?CN():+a)+(t==null?0:+t),!this._next&&xc!==this&&(xc?xc._next=this:_f=this,xc=this),this._call=e,this._time=a,jx()},stop:function(){this._call&&(this._call=null,this._time=1/0,jx())}};function NN(e,t,a){var o=new yx;return o.restart(e,t,a),o}function s8(){CN(),++Gl;for(var e=_f,t;e;)(t=ko-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Gl}function dw(){ko=(vf=Lc.now())+fp,Gl=hc=0;try{s8()}finally{Gl=0,r8(),ko=0}}function a8(){var e=Lc.now(),t=e-vf;t>kN&&(fp-=t,vf=e)}function r8(){for(var e,t=_f,a,o=1/0;t;)t._call?(o>t._time&&(o=t._time),e=t,t=t._next):(a=t._next,t._next=null,t=e?e._next=a:_f=a);xc=e,jx(o)}function jx(e){if(!Gl){hc&&(hc=clearTimeout(hc));var t=e-ko;t>24?(e<1/0&&(hc=setTimeout(dw,e-Lc.now()-fp)),ac&&(ac=clearInterval(ac))):(ac||(vf=Lc.now(),ac=setInterval(a8,kN)),Gl=1,SN(dw))}}const o8=1664525,l8=1013904223,fw=4294967296;function i8(){let e=1;return()=>(e=(o8*e+l8)%fw)/fw}function c8(e){return e.x}function u8(e){return e.y}var d8=10,f8=Math.PI*(3-Math.sqrt(5));function p8(e){var t,a=1,o=.001,l=1-Math.pow(o,1/300),c=0,u=.6,p=new Map,m=NN(b),g=wN("tick","end"),h=i8();e==null&&(e=[]);function b(){v(),g.call("tick",t),a<o&&(m.stop(),g.call("end",t))}function v(j){var y,S=e.length,C;j===void 0&&(j=1);for(var E=0;E<j;++E)for(a+=(c-a)*l,p.forEach(function(R){R(a)}),y=0;y<S;++y)C=e[y],C.fx==null?C.x+=C.vx*=u:(C.x=C.fx,C.vx=0),C.fy==null?C.y+=C.vy*=u:(C.y=C.fy,C.vy=0);return t}function k(){for(var j=0,y=e.length,S;j<y;++j){if(S=e[j],S.index=j,S.fx!=null&&(S.x=S.fx),S.fy!=null&&(S.y=S.fy),isNaN(S.x)||isNaN(S.y)){var C=d8*Math.sqrt(.5+j),E=j*f8;S.x=C*Math.cos(E),S.y=C*Math.sin(E)}(isNaN(S.vx)||isNaN(S.vy))&&(S.vx=S.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?(a=+j,t):a},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,S){var C=0,E=e.length,R,A,T,M,z;for(S==null?S=1/0:S*=S,C=0;C<E;++C)M=e[C],R=j-M.x,A=y-M.y,T=R*R+A*A,T<S&&(z=M,S=T);return z},on:function(j,y){return arguments.length>1?(g.on(j,y),t):g.on(j)}}}function m8(){var e,t,a,o,l=go(-30),c,u=1,p=1/0,m=.81;function g(k){var N,j=e.length,y=m_(e,c8,u8).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,S=0,C,E,R;if(k.length){for(C=E=R=0;R<4;++R)(j=k[R])&&(y=Math.abs(j.value))&&(N+=j.value,S+=y,C+=y*j.x,E+=y*j.y);k.x=C/S,k.y=E/S}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 S=k.x-t.x,C=k.y-t.y,E=y-N,R=S*S+C*C;if(E*E/m<R)return R<p&&(S===0&&(S=Tr(a),R+=S*S),C===0&&(C=Tr(a),R+=C*C),R<u&&(R=Math.sqrt(u*R)),t.vx+=S*k.value*o/R,t.vy+=C*k.value*o/R),!0;if(k.length||R>=p)return;(k.data!==t||k.next)&&(S===0&&(S=Tr(a),R+=S*S),C===0&&(C=Tr(a),R+=C*C),R<u&&(R=Math.sqrt(u*R)));do k.data!==t&&(E=c[k.data.index]*o/R,t.vx+=S*E,t.vy+=C*E);while(k=k.next)}return g.initialize=function(k,N){e=k,a=N,h()},g.strength=function(k){return arguments.length?(l=typeof k=="function"?k:go(+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 g8(){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 h8({center:e,nodes:t}){const a=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},S=[y,...t.map(R=>({...R}))],C=S.slice(1).map(R=>({source:y,target:R}));l.current=S,c.current=C;const E=p8(S).force("link",WI(C).distance(120).strength(.5)).force("charge",m8().strength(-220)).force("center",AI(oc/2,lc/2).strength(.05)).force("collide",QI(26)).on("tick",()=>p(R=>R+1));return o.current=E,()=>{E.stop()}},[e,t]);const h=y=>{const S=a.current.getBoundingClientRect();return{x:(y.clientX-S.left)/S.width*oc,y:(y.clientY-S.top)/S.height*lc}},b=y=>S=>{y.id!=="__center"&&(u.current=y,S.target.setPointerCapture?.(S.pointerId),o.current?.alphaTarget(.3).restart())},v=y=>{const S=u.current;if(!S)return;const{x:C,y:E}=h(y);S.fx=C,S.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:a,viewBox:`0 0 ${oc} ${lc}`,className:"h-[460px] w-full touch-none select-none",onPointerMove:v,onPointerUp:k,onPointerLeave:k,children:[j.map((y,S)=>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},S)),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 S=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:S?9:6,fill:rc[y.kind],fillOpacity:S?1:.9,stroke:S?"#fff":"none",strokeWidth:S?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=g8();return Object.keys(y).filter(S=>S!=="agent").map(S=>r.jsxs("span",{className:"inline-flex items-center gap-1",children:[r.jsx("span",{className:"size-2 rounded-full",style:{background:rc[S]}})," ",y[S]]},S))})(),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 x8(){return[{key:"overview",label:f("agents_ui.tab_explorer"),icon:Rf},{key:"memories",label:f("project.nav.memories"),icon:Gd},{key:"records",label:f("project.agent_detail.records_title"),icon:Pk},{key:"sleep",label:f("project.agent_detail.sleep_title"),icon:Dl},{key:"brain",label:f("project.agent_detail.brain_title"),icon:pa},{key:"config",label:f("settings.tabs.advanced"),icon:Rc}]}function b8(){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 wx=e=>e.split(",").map(t=>t.trim()).filter(Boolean),_8=(e,t)=>e.filter(a=>a.spec?.agent===t||t==="super-agent"&&a.kind==="super_agent");function v8(e){return e.split(`
@@ -653,4 +653,4 @@ Minimum version required to store current data is: `+H+`.
653
653
  `).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 s9({pid:e,className:t,initCmd:a,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(()=>{a&&(p(a),setTimeout(()=>j.current?.focus(),50))},[a]);const y=async C=>{const E=C.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(A=>[...A,{type:"out",text:R.stdout}]),R.stderr&&c(A=>[...A,{type:"err",text:R.stderr}])}catch(R){c(A=>[...A,{type:"err",text:String(R.message)}])}finally{g(!1)}}},S=C=>{if(C.key==="Enter")y(u),p("");else if(C.key==="ArrowUp"){C.preventDefault();const E=Math.min(v+1,h.length-1);k(E),p(h[E]??"")}else if(C.key==="ArrowDown"){C.preventDefault();const E=Math.max(v-1,-1);k(E),p(E===-1?"":h[E]??"")}};return r.jsxs("div",{className:Me("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(Ga,{className:"size-3 text-muted-foreground"}),r.jsx("span",{className:"flex-1 text-[11px] text-muted-foreground",children:"Terminal"}),r.jsx(Ye,{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(mM,{className:"size-3"})})}),r.jsx(Ye,{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(Gs,{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((C,E)=>r.jsx("div",{className:Me("whitespace-pre-wrap break-all",C.type==="cmd"&&"text-emerald-400",C.type==="err"&&"text-rose-400",C.type==="out"&&"text-foreground/90"),children:C.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:C=>p(C.target.value),onKeyDown:S,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 Ph(){return r.jsx(S_,{className:"relative z-10 w-px shrink-0 cursor-col-resize bg-border transition-colors hover:bg-primary/50 active:bg-primary/70"})}function a9(){return r.jsx(S_,{className:"relative z-10 h-px shrink-0 cursor-row-resize bg-border transition-colors hover:bg-primary/50 active:bg-primary/70"})}function r9(){const e=rt(),t=et("/projects",()=>rs.list()),a=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),[S,C]=x.useState(!0),[E,R]=x.useState(!1),[A,T]=x.useState(""),[M,z]=x.useState(!1),L=x.useRef(null),[D,H]=x.useState([]),[I,B]=x.useState("chat"),V=x.useCallback(_e=>{R(!0),T(_e)},[]);x.useEffect(()=>{!o&&a.length&&l(String(a[0].id))},[o,a]);const G=et(o?["code-sessions",o]:null,()=>Ia.sessions.list(o)),q=et(o?["agents",o]:null,()=>an.list(o)),Y=et(o&&c?["code-session",o,c]:null,()=>Ia.sessions.get(o,c)),K=et(o&&c?["code-changes",o,c]:null,()=>Ia.changes(o,c));x.useEffect(()=>{const _e=G.data||[];!c&&_e.length&&u(_e[0].id),c&&_e.length&&!_e.some(Oe=>Oe.id===c)&&u(_e[0]?.id??null)},[G.data,c]),x.useEffect(()=>{Y.data&&m(Y.data.agentSlug||cc)},[Y.data]),x.useEffect(()=>{k||(Y.data?h(Y.data.messages||[]):c||h([]))},[Y.data,c,k]),x.useEffect(()=>()=>L.current?.abort(),[]);const $=Y.data,X=$?.mode==="plan"?"plan":"build",P=$?.model||"",F=_e=>{_e===o||k||(l(_e),u(null),h([]))},W=_e=>{k||_e===c||(u(_e),h([]))},ee=async()=>{if(!(!o||k))try{const _e=await Ia.sessions.create(o,{title:f("code_module.untitled"),agentSlug:p!==cc?p:null});await G.mutate(),u(_e.id),h([])}catch(_e){e.error(_e.message)}},de=async(_e,Oe)=>{const He=window.prompt(f("code_module.rename"),Oe);if(!(!He||He===Oe))try{await Ia.sessions.update(o,_e,{title:He}),await G.mutate(),_e===c&&await Y.mutate()}catch(Xe){e.error(Xe.message)}},fe=async _e=>{if(!k&&window.confirm(f("code_module.delete_confirm")))try{await Ia.sessions.remove(o,_e),_e===c&&(u(null),h([])),await G.mutate()}catch(Oe){e.error(Oe.message)}},ae=async _e=>{if(m(_e),!!c)try{await Ia.sessions.update(o,c,{agentSlug:_e!==cc?_e:null}),await Promise.all([Y.mutate(),G.mutate()])}catch(Oe){e.error(Oe.message)}},oe=x.useCallback(async _e=>{if(c)try{await Ia.sessions.update(o,c,_e),await Promise.all([Y.mutate(),G.mutate()])}catch(Oe){e.error(Oe.message)}},[o,c,Y,G,e]),me=()=>{L.current?.abort(),N(!1)},Te=_e=>h(Oe=>{const He=[...Oe],Xe=He[He.length-1];return Xe&&Xe.role==="assistant"&&(He[He.length-1]=_e(Xe)),He}),le=async _e=>{const Oe=(_e??b).trim();if(!Oe||k||!o||!c)return;const He=new Date().toISOString();h(nn=>[...nn,{role:"user",parts:[{kind:"text",text:Oe}],ts:He},{role:"assistant",parts:[],ts:He,pending:!0}]),v(""),N(!0);const Xe=new AbortController;L.current=Xe;const ot=nn=>{if(nn.type==="error"){e.error(nn.error||f("modules_ui.code_stream_error"));return}Te(dn=>f_(dn,nn))};try{await Ia.stream(o,c,{prompt:Oe},ot,Xe.signal),Te(nn=>({...nn,pending:!1}))}catch(nn){Xe.signal.aborted?Te(dn=>({...dn,pending:!1,parts:[...dn.parts,{kind:"text",text:f("code_module.stopped")}]})):(e.error(nn.message),h(dn=>dn.filter((pt,Et)=>Et!==dn.length-1)))}finally{L.current===Xe&&(L.current=null),N(!1),Y.mutate(),G.mutate(),K.mutate()}},pe=async _e=>{try{await navigator.clipboard.writeText(_e),e.info(f("modules_ui.code_copied"))}catch{}},Se=x.useCallback(_e=>{B(_e),H(Oe=>Oe.some(He=>He.path===_e)?Oe:[...Oe,{path:_e,content:"",loading:!0}]),ge.post("/run",{cmd:`cat "${_e}"`,project:o}).then(Oe=>{const He=Oe.stdout||Oe.stderr||f("modules_ui.code_file_empty");H(Xe=>Xe.map(ot=>ot.path===_e?{...ot,content:He,loading:!1}:ot))}).catch(Oe=>{H(He=>He.map(Xe=>Xe.path===_e?{...Xe,content:f("modules_ui.code_file_error",{msg:Oe.message}),loading:!1}:Xe))})},[o]),je=x.useCallback(_e=>{H(Oe=>Oe.filter(He=>He.path!==_e)),B(Oe=>Oe===_e?"chat":Oe)},[]),Be=x.useCallback(_e=>{const Oe=`artifacts/${_e}`;B(Oe),H(He=>He.some(Xe=>Xe.path===Oe)?He:[...He,{path:Oe,content:"",loading:!0,artifactName:_e}]),Ml.read(o,_e).then(He=>{H(Xe=>Xe.map(ot=>ot.path===Oe?{...ot,content:He.content,loading:!1}:ot))}).catch(He=>{H(Xe=>Xe.map(ot=>ot.path===Oe?{...ot,content:f("modules_ui.code_file_error",{msg:He.message}),loading:!1}:ot))})},[o]),Ve=x.useCallback(async(_e,Oe)=>{const He=D.find(Xe=>Xe.path===_e);if(He?.artifactName)try{await Ml.write(o,He.artifactName,Oe),H(Xe=>Xe.map(ot=>ot.path===_e?{...ot,content:Oe}:ot)),e.info(f("modules_ui.code_saved"))}catch(Xe){e.error(Xe.message)}},[D,o,e]),we=!t.isLoading&&a.length>0,Ne=x.useMemo(()=>{const _e=[{value:cc,label:f("modules_ui.code_super_agent"),icon:un,description:f("modules_ui.code_super_agent_desc")}],Oe=(q.data||[]).map(He=>({value:He.slug,label:He.slug,icon:un,description:He.description||He.role||void 0}));return[..._e,...Oe]},[q.data]),ve=x.useMemo(()=>g,[g]),Ce=x.useMemo(()=>G.data?.find(_e=>_e.id===c)?.title||"",[G.data,c]),Pe=x.useMemo(()=>a.find(_e=>String(_e.id)===o),[a,o]);qP(Ce);const[Le,Ie]=x.useState(null),se=k?null:vN(g),be=se&&se.turnKey!==Le,$e=_e=>{le(_e)},Ee=x.useCallback(()=>y(_e=>!_e),[]),ze=x.useCallback(()=>z(_e=>!_e),[]),Ze=x.useCallback(()=>R(_e=>!_e),[]),at=x.useCallback(()=>C(_e=>!_e),[]),yt=x.useMemo(()=>c?r.jsx("div",{className:"flex items-center gap-0.5",children:[{Icon:Yk,open:j,toggle:Ee,title:f("modules_ui.code_panel_sessions")},{Icon:$k,open:M,toggle:ze,title:f("modules_ui.code_panel_tree")},{Icon:Ga,open:E,toggle:Ze,title:f("modules_ui.code_panel_terminal")},{Icon:BM,open:S,toggle:at,title:f("modules_ui.code_panel_context")}].map(({Icon:_e,open:Oe,toggle:He,title:Xe})=>r.jsx(Ye,{content:Xe,children:r.jsx("button",{type:"button",onClick:He,"data-active":Oe,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(_e,{className:"size-3.5"})})},Xe))}):null,[c,j,M,E,S,Ee,ze,Ze,at]);return FP(yt),r.jsx("div",{className:"flex h-full min-h-0 flex-col","data-testid":"screen-code",children:t.isLoading?r.jsx(lt,{}):we?r.jsxs(Nx,{orientation:"vertical",id:"code-layout-v",className:"min-h-0 flex-1",children:[r.jsx(uo,{id:"top",defaultSize:E?"55%":"100%",minSize:"20%",children:r.jsxs(Nx,{orientation:"horizontal",id:"code-layout",className:"h-full",children:[j&&r.jsxs(r.Fragment,{children:[r.jsx(uo,{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(LB,{projects:a,value:o,onChange:F,disabled:k})}),r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:r.jsx(IB,{sessions:G.data||[],activeId:c,busy:k,onSelect:W,onCreate:ee,onRename:de,onDelete:fe})}),r.jsx("div",{className:"shrink-0 border-t border-border p-2",children:r.jsx(bt,{value:p,onChange:ae,options:Ne,disabled:k,showIcon:!0})})]})}),r.jsx(Ph,{})]}),M&&r.jsxs(r.Fragment,{children:[r.jsx(uo,{id:"tree",defaultSize:"13%",minSize:"8%",children:r.jsx("div",{className:"h-full",children:r.jsx(t9,{pid:o,projectPath:Pe?.path,onOpenFile:Se})})}),r.jsx(Ph,{})]}),r.jsx(uo,{id:"main",defaultSize:"50%",minSize:"20%",children:r.jsxs("div",{className:"flex h-full flex-col",children:[D.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:()=>B("chat"),"data-active":I==="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(Ux,{className:"size-3 shrink-0"}),f("modules_ui.code_chat_tab")]}),D.map(_e=>{const Oe=_e.path.split("/").pop()??_e.path,He=I===_e.path;return r.jsxs("div",{"data-active":He,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(Ye,{content:_e.path,children:r.jsx("button",{type:"button",onClick:()=>B(_e.path),className:"min-w-0 max-w-[140px] truncate font-mono",children:Oe})}),r.jsx(Ye,{content:f("code_module.close"),children:r.jsx("button",{type:"button",onClick:()=>je(_e.path),className:"shrink-0 rounded p-0.5 opacity-60 hover:bg-accent hover:opacity-100",children:r.jsx(Gs,{className:"size-2.5"})})})]},_e.path)})]}),I==="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(p_,{msgs:g,onCopy:pe}):r.jsx("div",{className:"grid h-full place-items-center p-6",children:r.jsx(xt,{children:f("code_module.empty_chat")})}):r.jsx("div",{className:"grid h-full place-items-center p-6",children:r.jsx(xt,{children:f("code_module.pick_project")})})}),be&&se&&r.jsx(_N,{turnKey:se.turnKey,questions:se.questions,onSubmit:$e,onDismiss:()=>Ie(se.turnKey),disabled:k})]}):r.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:(()=>{const _e=D.find(Oe=>Oe.path===I);return _e?r.jsx(n9,{path:_e.path,content:_e.content,loading:_e.loading,onSave:_e.artifactName?Oe=>Ve(_e.path,Oe):void 0}):null})()}),r.jsx("div",{className:"shrink-0 border-t border-border p-2","data-testid":"code-input",children:r.jsx(UB,{value:b,onValueChange:v,onSubmit:()=>void le(),onStop:me,busy:k,disabled:!c,mode:X,onModeChange:_e=>void oe({mode:_e}),model:P,onModelChange:_e=>void oe({model:_e||null})})})]})}),S&&r.jsxs(r.Fragment,{children:[r.jsx(Ph,{}),r.jsx(uo,{id:"right",defaultSize:"22%",minSize:"15%",children:r.jsx("aside",{className:"flex h-full flex-col",children:r.jsx(JB,{pid:o,turns:ve,changes:K.data,changesLoading:K.isLoading,onRefreshChanges:()=>void K.mutate(),session:Y.data?{title:Y.data.title,mode:Y.data.mode,createdAt:Y.data.createdAt,updatedAt:Y.data.updatedAt,agentSlug:Y.data.agentSlug??null}:null,onRunInTerminal:V,onEditArtifact:Be})})})]})]})}),E&&o&&r.jsxs(r.Fragment,{children:[r.jsx(a9,{}),r.jsx(uo,{id:"terminal",defaultSize:"45%",minSize:"10%",maxSize:"80%",children:r.jsx(s9,{pid:o,initCmd:A,onClose:Ze,className:"h-full"})})]})]}):r.jsx("div",{className:"grid flex-1 place-items-center",children:r.jsx(xt,{children:f("code_module.no_projects")})})})}function o9({open:e,onClose:t}){const{mutate:a}=mC(),o=Qn(),l=rt(),[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(""),[S,C]=x.useState(!1),[E,R]=x.useState(!1),A=async(z,L=!1)=>{C(!0),y("");try{const D=await zj.dirs(z||"~");h(D.path),u(D.path),N(D.parent),v(D.entries)}catch(D){const H=D.message;y(H),L||l.error(H)}finally{C(!1)}};x.useEffect(()=>{e||(u(""),m(!1),h(""),v([]),N(null),y(""))},[e]);const T=async()=>{C(!0);try{const z=await zj.pickDir(f("add_project.picker_prompt"));if("cancelled"in z)return;u(z.path);return}catch{m(!0),await A(c||"~")}finally{C(!1)}},M=async()=>{const z=c.trim();if(!z){l.error(f("add_project.path_required"));return}R(!0);try{const L=await rs.register(z);l.success(f("add_project.registered",{id:L.id})),await a("/projects"),t(),o(`/p/${L.id}`)}catch(L){l.error(L.message)}finally{R(!1)}};return r.jsx(An,{open:e,onClose:t,title:f("add_project.title"),description:f("add_project.subtitle"),footer:r.jsxs(r.Fragment,{children:[r.jsx(ie,{variant:"ghost",onClick:t,disabled:E,children:f("common.cancel")}),r.jsx(ie,{variant:"primary",onClick:M,loading:E,children:f("add_project.register")})]}),children:r.jsxs("div",{className:"space-y-3",children:[r.jsx(ue,{label:f("add_project.path_label"),hint:f("add_project.path_hint"),children:r.jsxs("div",{className:"flex gap-2",children:[r.jsx(Re,{autoFocus:!0,placeholder:f("add_project.path_placeholder"),value:c,onChange:z=>u(z.target.value),onKeyDown:z=>{z.key==="Enter"&&M()}}),r.jsxs(ie,{onClick:T,disabled:S,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(ie,{size:"sm",variant:"ghost",onClick:()=>A("~"),disabled:S,children:r.jsx(RM,{size:13})}),r.jsx(ie,{size:"sm",variant:"ghost",onClick:()=>k&&A(k),disabled:!k||S,children:".."}),r.jsx(ie,{size:"sm",variant:"ghost",onClick:()=>m(!1),disabled:S,children:r.jsx(Gs,{size:13})})]})]}),r.jsxs("div",{className:"max-h-64 overflow-y-auto p-2",children:[S&&r.jsx(lt,{}),!S&&j&&r.jsx(xt,{children:f("add_project.browser_unavailable")}),!S&&!j&&b.length===0&&r.jsx(xt,{children:f("add_project.no_folders")}),!S&&!j&&b.map(z=>r.jsxs("button",{type:"button",onClick:()=>A(z),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(Ef,{size:14,className:"text-muted-fg"}),r.jsx("span",{className:"truncate",children:z.split("/").pop()}),r.jsx("span",{className:"ml-auto truncate font-mono text-[10px] text-muted-fg",children:z})]},z))]})]})]})})}function l9({onPaired:e}){const[t,a]=x.useState(""),[o,l]=x.useState(i9()),[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 Fl.confirm({pairing_id:h,label:o.trim()||void 0});fo(b.token);try{localStorage.setItem(Rn.token,b.token)}catch{}e()}catch(b){m(c9(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(Uh,{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(ue,{label:f("pairing.code_label"),children:r.jsx(Re,{value:t,onChange:h=>a(h.target.value),placeholder:f("pairing.code_ph"),spellCheck:!1,autoComplete:"off"})}),r.jsx(ue,{label:f("pairing.label_label"),hint:f("pairing.revoke_hint"),children:r.jsx(Re,{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(ie,{type:"submit",variant:"primary",size:"md",loading:c,className:"w-full justify-center",children:f(c?"pairing.linking":"pairing.submit")})]})]})})}function i9(){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 c9(e){if(e instanceof Kc){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 u9({...e}){return r.jsx(EC,{"data-slot":"sheet",...e})}function d9({...e}){return r.jsx(NC,{"data-slot":"sheet-portal",...e})}function f9({className:e,...t}){return r.jsx(wC,{"data-slot":"sheet-overlay",className:St("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 p9({className:e,children:t,side:a="right",showCloseButton:o=!0,...l}){return r.jsxs(d9,{children:[r.jsx(f9,{}),r.jsxs(CC,{"data-slot":"sheet-content","data-side":a,className:St("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(ip,{"data-slot":"sheet-close",render:r.jsx(Qa,{variant:"ghost",className:"absolute top-3 right-3",size:"icon-sm"}),children:[r.jsx(Gs,{}),r.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function m9({className:e,...t}){return r.jsx("div",{"data-slot":"sheet-header",className:St("flex flex-col gap-0.5 p-4",e),...t})}function g9({className:e,...t}){return r.jsx(RC,{"data-slot":"sheet-title",className:St("font-heading text-base font-medium text-foreground",e),...t})}function h9({className:e,...t}){return r.jsx(kC,{"data-slot":"sheet-description",className:St("text-sm text-muted-foreground",e),...t})}function x9({value:e,projectPath:t,onPick:a}){const o=b9(e),l=o?_9(e):"",{data:c}=et(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:()=>a(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 b9(e){return!!e.match(/^\s*\/([A-Za-z0-9_-]*)$/)}function _9(e){const t=e.match(/^\s*\/([A-Za-z0-9_-]*)$/);return t?t[1]:""}function v9(){try{const e=localStorage.getItem(Rn.robyChat);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(a=>a&&Array.isArray(a.parts)&&!a.pending):[]}catch{return[]}}function y9({open:e,onOpenChange:t}){const a=rp(),o=rt(),[l,c]=x.useState(v9),[u,p]=x.useState(""),[m,g]=x.useState(!1),[h,b]=x.useState(""),v=x.useRef(null);x.useEffect(()=>{const C=l.filter(E=>!E.pending);try{C.length?localStorage.setItem(Rn.robyChat,JSON.stringify(C)):localStorage.removeItem(Rn.robyChat)}catch{}},[l]);const k=()=>{if(!m){c([]),p("");try{localStorage.removeItem(Rn.robyChat)}catch{}}};x.useEffect(()=>()=>v.current?.abort(),[]),x.useEffect(()=>{const C=E=>{const R=E.detail?.prompt;typeof R=="string"&&(t(!0),p(R))};return window.addEventListener("apx:roby-prompt",C),()=>window.removeEventListener("apx:roby-prompt",C)},[t]);const N=()=>{v.current?.abort(),g(!1)},j=C=>c(E=>{const R=[...E],A=R[R.length-1];return A?.role==="assistant"&&(R[R.length-1]=C(A)),R}),y=async()=>{const C=u.trim();if(!C||m)return;const E=new Date().toISOString(),R=l.filter(z=>!z.pending).map(z=>({role:z.role,content:_x(z)}));c(z=>[...z,{role:"user",parts:[{kind:"text",text:C}],ts:E},{role:"assistant",parts:[],ts:E,pending:!0}]),p(""),g(!0);const A=new AbortController;v.current=A;let T=!1;const M=z=>{if(z?.type==="error"){T=!0,o.error(z.error||"error"),c(L=>{const D=[...L],H=D[D.length-1];return H?.role==="assistant"&&H.pending&&D.pop(),D});return}j(L=>f_(L,z))};try{await hC.stream(0,{prompt:C,previousMessages:R,model:h||void 0,channel:"web_sidebar"},M,A.signal),j(z=>({...z,pending:!1}))}catch(z){A.signal.aborted?j(L=>({...L,pending:!1,parts:[...L.parts,{kind:"text",text:f("project.chat.stopped_marker")}]})):T||(o.error(z.message),c(L=>{const D=[...L],H=D[D.length-1];return H?.role==="assistant"&&H.pending&&D.pop(),D}))}finally{v.current===A&&(v.current=null),g(!1)}},S=async C=>{try{await navigator.clipboard.writeText(C),o.info(f("project.chat.copied"))}catch{}};return r.jsx(u9,{open:e,onOpenChange:t,children:r.jsxs(p9,{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(m9,{className:"pr-12",children:[r.jsxs(g9,{className:"flex items-center gap-2",children:[r.jsx(un,{size:18})," ",f("superagent.title",{persona:a}),r.jsx("span",{className:"text-xs font-normal text-muted-fg",children:f("superagent.badge")})]}),r.jsx(h9,{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:a})}):r.jsx(p_,{msgs:l,onCopy:S})}),r.jsx(bN,{msgs:l}),r.jsxs("div",{className:"border-t border-border p-3",children:[r.jsx("div",{className:"mb-1.5",children:r.jsx(x9,{value:u,onPick:C=>p(`/${C} `)})}),r.jsx(u_,{value:u,onValueChange:p,onSubmit:()=>void y(),onStop:N,busy:m,placeholder:f("superagent.placeholder"),footer:r.jsx(d_,{value:h,onChange:b,disabled:m})}),r.jsx("div",{className:"mt-1.5 flex justify-end",children:r.jsxs(Qa,{size:"xs",variant:"ghost",onClick:k,disabled:m||l.length===0,children:[r.jsx(rn,{className:"size-3"})," ",f("superagent.new_chat")]})})]})]})})}function j9(){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 w9(){const[e,t]=x.useState({status:"loading"}),[a,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 Fl.confirm({pairing_id:m,label:j9(),kind:"web"});fo(h.token);try{localStorage.setItem(Rn.token,h.token)}catch{}c||t({status:"ok"});return}catch{}}const g=p.get("token");if(g){fo(g);try{localStorage.setItem(Rn.token,g)}catch{}history.replaceState(null,"",window.location.pathname+window.location.search)}else try{const h=localStorage.getItem(Rn.token);h&&fo(h)}catch{}try{const h=await fetch("/admin/web-token");if(h.ok){const b=await h.json();if(b?.token){fo(b.token);try{localStorage.setItem(Rn.token,b.token)}catch{}}}}catch{}if(!$b()){c||t({status:"unpaired"});return}try{await ge.get("/projects"),c||t({status:"ok"})}catch(h){if(h instanceof Kc&&(h.status===401||h.status===403)){fo(null);try{localStorage.removeItem(Rn.token)}catch{}c||t({status:"unpaired"})}else c||t({status:"error",reason:String(h)})}})(),()=>{c=!0}},[a]),{...e,reload:l}}function k9(){const e=w9();return e.status==="loading"?r.jsx(uk,{text:f("daemon.connecting")}):e.status==="error"?r.jsx(uk,{mood:"sad",text:f("daemon.unreachable"),sub:`${f("daemon.unreachable_hint")}
654
654
 
655
655
  ${e.reason}`}):e.status==="unpaired"?r.jsx(l9,{onPaired:e.reload}):r.jsx(zP,{children:r.jsx(K4,{delay:0,children:r.jsx(S9,{})})})}function S9(){const e=Qn(),t=Xn(),[a,o]=Cf(),{theme:l,toggle:c}=Gx(),u=a.get("action")==="add-project",[p,m]=x.useState(!1),g=()=>{const b=new URLSearchParams(a);b.delete("action"),o(b,{replace:!0})},h=()=>{const b=new URLSearchParams(a);b.set("action","add-project"),o(b)};return r.jsx(BP,{children:r.jsxs("div",{className:"flex h-screen w-screen overflow-hidden bg-background text-foreground","data-testid":"app-shell",children:[r.jsx(GD,{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(C9,{onToggleTheme:c,isDark:l==="dark",pathname:t.pathname}),r.jsx("div",{className:"flex-1 overflow-y-auto",children:r.jsxs(Ak,{children:[r.jsx(Xt,{path:"/",element:r.jsx(IP,{})}),r.jsx(Xt,{path:"/settings/*",element:r.jsx(Q7,{})}),r.jsx(Xt,{path:"/m/desktop/*",element:r.jsx(J7,{})}),r.jsx(Xt,{path:"/m/code/*",element:r.jsx(r9,{})}),r.jsx(Xt,{path:"/p/:pid/*",element:r.jsx(E8,{})}),r.jsx(Xt,{path:"*",element:r.jsx(A9,{})})]})})]}),r.jsx(o9,{open:u,onClose:g}),r.jsx(y9,{open:p,onOpenChange:m})]})})}function C9({onToggleTheme:e,isDark:t,pathname:a}){const{projects:o}=Xc(),l=VP(),c=a.split("/").filter(Boolean),u=c[0]==="p"?o.find(N=>String(N.id)===c[1]):void 0,p=c[0]==="settings"?R9(c[1]):c[0]==="p"?T9(c[2]):"",m=c[0]==="p"&&c[1]==="0",g=u?.name||u?.path?.split("/").pop()||f("nav.project"),h=a==="/"?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"),E9(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=a==="/"?"":c[0]==="settings"?f("settings.subtitle"):c[0]==="p"?m?f("base.subtitle"):u?`${bC(u.kind)} · ${u.path}`:"":"",v=UP(),k=$P();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(rD,{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(N9,{}),r.jsx(Ye,{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(FM,{size:14}):r.jsx(PM,{size:14})})})]})}function N9(){const e=aC(),t=a=>{a!==e&&(nC(a),window.location.reload())};return r.jsxs(J2,{children:[r.jsxs(eC,{"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(AM,{size:14}),r.jsx("span",{className:"text-[11px] font-medium uppercase",children:e})]}),r.jsx(tC,{align:"end",children:r.jsx(Zz,{value:e,onValueChange:a=>t(a),children:sC.map(a=>r.jsx(Wz,{value:a.value,children:a.label},a.value))})})]})}function E9(e){switch(e){case"desktop":return f("nav.modules.desktop");case"code":return f("nav.modules.code");default:return e||""}}function R9(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 T9(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"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 uk({text:e,sub:t,mood:a="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(VC,{mood:a,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 A9(){const e=Qn();return r.jsx(qC,{testId:"screen-not-found",mood:"confused",title:f("not_found.title"),titleClassName:"text-7xl",message:f("not_found.message"),action:r.jsx(Qa,{variant:"outline",onClick:()=>e("/"),children:f("not_found.home")})})}hT.createRoot(document.getElementById("root")).render(r.jsx(Uc.StrictMode,{children:r.jsx(UA,{children:r.jsx(WM,{children:r.jsx(k9,{})})})}));
656
- //# sourceMappingURL=index--24yvYc5.js.map
656
+ //# sourceMappingURL=index-rx9XIp5S.js.map