(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[63230],{49470:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>p});var r=n(95155),s=n(64577),a=n(99314),o=n(81402),c=n(73321),u=n(12115),l=n(3765),i=n(98757),d=n(45160),f=n(89239),m=n(60529);let h=`---
name: my-agent
description: What this agent does
model: sonnet
---

Your system prompt here.
`;function p({params:e}){let{name:t}=(0,u.use)(e),n=(0,c.useSearchParams)(),x=(0,c.useRouter)(),g="new"===t,v=n.get("scope")||"user",w=n.get("cwd")||void 0;(0,l.si)(g?"New Agent":"Edit Agent");let[y,b]=(0,u.useState)(g?"":decodeURIComponent(t)),[N,j]=(0,u.useState)(g?h:""),[C,S]=(0,u.useState)(g?h:""),[k,E]=(0,u.useState)(!g),[R,$]=(0,u.useState)(!1),[L,_]=(0,u.useState)(null),[z,U]=(0,u.useState)(!1),A=N!==C;(0,u.useEffect)(()=>{if(g)return;let e=new URLSearchParams({scope:v});w&&e.set("cwd",w),fetch(`/api/agents/${encodeURIComponent(t)}?${e}`).then(e=>{if(!e.ok)throw Error("Not found");return e.json()}).then(e=>{j(e.content),S(e.content)}).catch(()=>{_("Failed to load agent")}).finally(()=>E(!1))},[g,t,v,w]);let O=(0,u.useCallback)(async()=>{let e=y.trim();if(!e)return void _("Name is required");if(!/^[a-zA-Z0-9_-]+$/.test(e))return void _("Name can only contain letters, numbers, hyphens, and underscores");$(!0),_(null);try{if(!(await fetch(`/api/agents/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({scope:v,cwd:w,content:N})})).ok)throw Error("Save failed");if(S(N),_("Saved"),g){let t=new URLSearchParams({scope:v});w&&t.set("cwd",w),x.replace(`/agents/${encodeURIComponent(e)}?${t}`)}}catch{_("Failed to save")}finally{$(!1)}},[y,N,v,w,g,x]);return k?(0,r.jsx)("div",{className:"flex-1 min-h-0 p-4",children:(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"Loading..."})}):(0,r.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto p-4 space-y-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)("div",{className:"flex-1 min-w-0",children:g?(0,r.jsx)(m.p,{placeholder:"agent-name",value:y,onChange:e=>b(e.target.value),className:"font-mono"}):(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("span",{className:"font-mono font-bold text-lg",children:y}),(0,r.jsx)(d.E,{variant:"secondary",children:"user"===v?"Global":"Project"})]})}),(0,r.jsxs)(f.$,{size:"sm",variant:"outline",onClick:()=>{let e=document.createElement("textarea");e.value=N,e.style.position="fixed",e.style.opacity="0",document.body.appendChild(e),e.select(),document.execCommand("copy"),document.body.removeChild(e),U(!0),setTimeout(()=>U(!1),1500)},children:[z?(0,r.jsx)(s.A,{className:"h-4 w-4 mr-1"}):(0,r.jsx)(a.A,{className:"h-4 w-4 mr-1"}),z?"Copied":"Copy"]}),(0,r.jsxs)(f.$,{size:"sm",onClick:O,disabled:R||!g&&!A,children:[(0,r.jsx)(o.A,{className:"h-4 w-4 mr-1"}),R?"Saving...":"Save"]})]}),L&&(0,r.jsx)("p",{className:`text-sm ${"Saved"===L?"text-green-600":"text-destructive"}`,children:L}),(0,r.jsx)(i.B,{value:N,onChange:j,language:"markdown",onSave:O,className:"flex-1"})]})}},60470:(e,t,n)=>{Promise.resolve().then(n.bind(n,49470))},98757:(e,t,n)=>{"use strict";n.d(t,{B:()=>h});var r=n(95155),s=n(13748),a=n(53649),o=n(27071),c=n(74059),u=n(89561),l=n(62465),i=n(12115);let d=u.Lz.theme({"&":{backgroundColor:"transparent"},".cm-gutters":{backgroundColor:"transparent",borderRight:"1px solid hsl(var(--border))"}});function f(){return!("u"<typeof document)&&document.documentElement.classList.contains("dark")}function m(e){switch(e){case"markdown":default:return(0,s.wD)();case"yaml":return(0,a.oQ)()}}function h({value:e,onChange:t,language:n,readOnly:s,className:a,onSave:p}){let x=(0,i.useRef)(null),g=(0,i.useRef)(null),v=(0,i.useRef)(new o.xx),w=(0,i.useRef)(new o.xx),y=(0,i.useRef)(new o.xx),b=(0,i.useRef)(t),N=(0,i.useRef)(p),j=(0,i.useRef)(e);return b.current=t,N.current=p,(0,i.useEffect)(()=>{if(!x.current)return;let e=o.$t.create({doc:j.current,extensions:[l.oQ,u.Lz.lineWrapping,v.current.of(f()?c.bM:d),w.current.of(m(n)),y.current.of(o.$t.readOnly.of(!!s)),u.w4.of([{key:"Mod-s",run:()=>(N.current?.(),!0)}]),u.Lz.updateListener.of(e=>{if(e.docChanged){let t=e.state.doc.toString();j.current=t,b.current(t)}})]}),t=new u.Lz({state:e,parent:x.current});return g.current=t,()=>{t.destroy(),g.current=null}},[]),(0,i.useEffect)(()=>{let t=g.current;t&&e!==j.current&&(j.current=e,t.dispatch({changes:{from:0,to:t.state.doc.length,insert:e}}))},[e]),(0,i.useEffect)(()=>{let e=g.current;if(!e)return;let t=new MutationObserver(()=>{e.dispatch({effects:v.current.reconfigure(f()?c.bM:d)})});return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]),(0,i.useEffect)(()=>{let e=g.current;e&&e.dispatch({effects:w.current.reconfigure(m(n))})},[n]),(0,i.useEffect)(()=>{let e=g.current;e&&e.dispatch({effects:y.current.reconfigure(o.$t.readOnly.of(!!s))})},[s]),(0,r.jsx)("div",{ref:x,className:`overflow-auto rounded-md border bg-background text-sm [&_.cm-editor]:min-h-[200px] [&_.cm-editor.cm-focused]:outline-none ${a||""}`})}}},e=>{e.O(0,[6079,989,11242,6802,3765,28441,93794,77358],()=>e(e.s=60470)),_N_E=e.O()}]);