@hellcoder/companion 0.107.1-preview.20260708075901.9f18d7b → 0.108.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/assets/{AgentsPage-t4s7ZO2P.js → AgentsPage-DI5hdCnz.js} +5 -5
  2. package/dist/assets/{CronManager-C_0weC_z.js → CronManager-yX8i4C_S.js} +1 -1
  3. package/dist/assets/DashboardPage-D1nc0wHf.js +1 -0
  4. package/dist/assets/{IntegrationsPage-Gte53t7Z.js → IntegrationsPage-iSfvR9vX.js} +1 -1
  5. package/dist/assets/{LinearOAuthSettingsPage-DHJ73rFh.js → LinearOAuthSettingsPage-omExXsGc.js} +1 -1
  6. package/dist/assets/{LinearSettingsPage-D7ZHYkum.js → LinearSettingsPage-C4oBf1iO.js} +1 -1
  7. package/dist/assets/{Playground-DBWsv4R6.js → Playground-CjiZI9QY.js} +1 -1
  8. package/dist/assets/{PromptsPage-Cnjs3hD9.js → PromptsPage-CU6z49U6.js} +1 -1
  9. package/dist/assets/{RunsPage-B5PsNevy.js → RunsPage-mcU7OUoZ.js} +1 -1
  10. package/dist/assets/{SandboxManager-DpFA1it7.js → SandboxManager-BkYS-dK5.js} +1 -1
  11. package/dist/assets/SettingsPage-CyHMmTBB.js +1 -0
  12. package/dist/assets/{TailscalePage-CMG1g7e2.js → TailscalePage-CRyiyMcJ.js} +1 -1
  13. package/dist/assets/index-DMoY-FDD.css +1 -0
  14. package/dist/assets/index-DOle27vf.js +136 -0
  15. package/dist/assets/{sw-register-CS-6kwSW.js → sw-register-Dqdfho7x.js} +1 -1
  16. package/dist/index.html +2 -2
  17. package/dist/sw.js +1 -1
  18. package/package.json +1 -1
  19. package/server/auto-namer.test.ts +16 -0
  20. package/server/claude-cli-runner.ts +92 -0
  21. package/server/dashboard-scheduler.test.ts +73 -0
  22. package/server/dashboard-scheduler.ts +46 -0
  23. package/server/dashboard-store.test.ts +101 -0
  24. package/server/dashboard-store.ts +121 -0
  25. package/server/dashboard-summarizer.test.ts +216 -0
  26. package/server/dashboard-summarizer.ts +290 -0
  27. package/server/dashboard-types.ts +70 -0
  28. package/server/index.ts +4 -0
  29. package/server/linear-connections.test.ts +16 -0
  30. package/server/routes/dashboard-routes.test.ts +139 -0
  31. package/server/routes/dashboard-routes.ts +101 -0
  32. package/server/routes/settings-routes.ts +47 -1
  33. package/server/routes.test.ts +112 -0
  34. package/server/routes.ts +4 -0
  35. package/server/settings-manager.test.ts +12 -0
  36. package/server/settings-manager.ts +45 -1
  37. package/server/ws-bridge-codex.test.ts +24 -0
  38. package/dist/assets/SettingsPage-v8ndyXOz.js +0 -1
  39. package/dist/assets/index-Bp3e_166.js +0 -136
  40. package/dist/assets/index-D4AeOLki.css +0 -1
@@ -1,13 +1,13 @@
1
- import{r,j as e,u as Be,a as z,y as ae,F as ye,L as ne,t as Ee,E as Ne,z as Oe,H as Ie}from"./index-Bp3e_166.js";const ze="companion_public_url_dismissed";function De({publicUrl:t}){const[i,d]=r.useState(()=>localStorage.getItem(ze)==="1");return t||i?null:e.jsxs("div",{className:"mb-4 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/30 text-amber-400 text-xs flex items-start justify-between gap-3",role:"alert",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"No public URL configured."})," ","Webhook URLs currently use your browser address, which external services like Linear may not be able to reach."," ",e.jsx("a",{href:"#/settings",className:"underline hover:text-amber-300",children:"Set your public URL in Settings"}),"."]}),e.jsx("button",{onClick:()=>{localStorage.setItem(ze,"1"),d(!0)},className:"text-amber-400 hover:text-amber-200 transition-colors cursor-pointer flex-shrink-0","aria-label":"Dismiss public URL banner",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]})}function He({steps:t,currentStep:i,completedSteps:d}){return e.jsx("nav",{"aria-label":"Setup progress",className:"flex items-center gap-0 w-full mb-8",children:t.map((a,m)=>{const u=m+1,h=d.has(u),g=u===i,j=!h&&!g;return e.jsxs("div",{className:"flex items-center flex-1 last:flex-none",children:[e.jsxs("div",{className:"flex flex-col items-center gap-1.5",children:[e.jsx("div",{className:`flex items-center justify-center w-8 h-8 rounded-full text-xs font-semibold border-2 transition-colors ${h?"bg-cc-success/15 border-cc-success text-cc-success":g?"bg-cc-primary/15 border-cc-primary text-cc-primary":"bg-cc-hover border-cc-border text-cc-muted"}`,"aria-current":g?"step":void 0,"aria-label":`Step ${u}: ${a.label}${h?" (completed)":g?" (current)":""}`,children:h?e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):u}),e.jsx("span",{className:`text-[10px] whitespace-nowrap ${j?"text-cc-muted":g?"text-cc-primary font-medium":"text-cc-success"}`,children:a.label})]}),m<t.length-1&&e.jsx("div",{className:`flex-1 h-0.5 mx-2 mt-[-18px] rounded ${d.has(u)?"bg-cc-success/40":"bg-cc-border"}`})]},u)})})}function Pe({onNext:t}){const i=Be(m=>m.publicUrl),d=i||window.location.origin,a=!!i;return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"pt-1",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-widest text-cc-primary font-medium mb-2",children:"Linear Agent Setup"}),e.jsx("h2",{className:"text-xl font-semibold text-cc-fg tracking-tight leading-tight",children:"Connect your Linear workspace"}),e.jsx("p",{className:"mt-2 text-sm text-cc-muted leading-relaxed max-w-md",children:"This wizard connects the Agent Interaction SDK so your agent can respond to @mentions in Linear issues."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`mt-0.5 flex-shrink-0 w-5 h-5 rounded-full flex items-center justify-center ${a?"bg-cc-success/15 text-cc-success":"bg-cc-warning/15 text-cc-warning"}`,children:a?e.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):e.jsx("span",{className:"text-[10px] font-bold",children:"!"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[13px] text-cc-fg font-medium",children:"Public URL"}),e.jsx("p",{className:"text-xs text-cc-muted mt-0.5 leading-relaxed",children:a?e.jsx(e.Fragment,{children:e.jsx("code",{className:"px-1 py-0.5 rounded bg-cc-hover text-[10px] font-mono-code",children:i})}):e.jsxs(e.Fragment,{children:["Not set. Linear needs to reach your instance. Configure in ",e.jsx("a",{href:"#/integrations/tailscale",className:"text-cc-primary hover:underline",children:"Tailscale"})," or ",e.jsx("a",{href:"#/settings",className:"text-cc-primary hover:underline",children:"Settings"}),"."]})})]})]}),e.jsx("div",{className:"border-t border-cc-border/50"}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 flex-shrink-0 w-5 h-5 rounded-full flex items-center justify-center bg-cc-hover text-cc-muted",children:e.jsx("span",{className:"text-[10px] font-semibold",children:"1"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[13px] text-cc-fg font-medium",children:"Create a Linear OAuth app"}),e.jsx("p",{className:"text-xs text-cc-muted mt-0.5 leading-relaxed",children:e.jsx("a",{href:"https://linear.app/settings/api",target:"_blank",rel:"noopener noreferrer",className:"text-cc-primary hover:underline",children:"Linear → Settings → API → OAuth Applications"})}),e.jsxs("dl",{className:"mt-3 space-y-2.5 text-xs",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-cc-muted",children:"Webhooks"}),e.jsxs("dd",{className:"text-cc-fg mt-0.5",children:["Enable and subscribe to ",e.jsx("strong",{children:"Agent session events"})]})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-cc-muted",children:"Scope"}),e.jsx("dd",{className:"mt-0.5",children:e.jsx("code",{className:"px-1.5 py-0.5 rounded bg-cc-hover text-cc-fg text-[10px] font-mono-code",children:"app:mentionable"})})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-cc-muted",children:"Redirect URI"}),e.jsx("dd",{className:"mt-0.5",children:e.jsx("code",{className:"px-1.5 py-0.5 rounded bg-cc-hover text-cc-fg text-[10px] font-mono-code break-all",children:`${d}/api/linear/oauth/callback`})})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-cc-muted",children:"Webhook URL"}),e.jsx("dd",{className:"mt-0.5",children:e.jsx("code",{className:"px-1.5 py-0.5 rounded bg-cc-hover text-cc-fg text-[10px] font-mono-code break-all",children:`${d}/api/linear/agent-webhook`})})]})]})]})]})]}),e.jsx("div",{className:"flex justify-end pt-1",children:e.jsx("button",{onClick:t,className:"px-5 py-2.5 rounded-lg text-sm font-medium bg-cc-primary hover:bg-cc-primary-hover text-white transition-colors cursor-pointer",children:"Next"})})]})}function Ue({onNext:t,onBack:i,selectedConnectionId:d}){const[a,m]=r.useState([]),[u,h]=r.useState(!0),[g,j]=r.useState(d||""),[y,l]=r.useState("");r.useEffect(()=>{z.listLinearOAuthConnections().then(b=>{m(b.connections),l(""),d?b.connections.some(p=>p.id===d)&&j(d):b.connections.length===1&&j(b.connections[0].id)}).catch(b=>l(b instanceof Error?b.message:String(b))).finally(()=>h(!1))},[d]);const N=a.find(b=>b.id===g),k=!!g&&(N==null?void 0:N.status)==="connected";return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-cc-fg",children:"Select OAuth Connection"}),e.jsx("p",{className:"mt-1 text-sm text-cc-muted",children:"Choose which Linear OAuth app this agent should use for @mention triggers."})]}),y&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:y}),u?e.jsx("p",{className:"text-sm text-cc-muted",children:"Loading connections..."}):a.length===0?e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-bg p-5 text-center space-y-3",children:[e.jsx("p",{className:"text-sm text-cc-muted",children:"No OAuth connections found."}),e.jsx("p",{className:"text-xs text-cc-muted",children:"Create an OAuth app connection first, then come back to set up the agent."}),e.jsx("a",{href:"#/integrations/linear-oauth",className:"inline-flex px-4 py-2.5 rounded-lg text-sm font-medium bg-cc-primary hover:bg-cc-primary-hover text-white transition-colors",children:"Go to OAuth Settings"})]}):e.jsxs("div",{className:"space-y-3",children:[a.map(b=>{const C=g===b.id,p=b.status==="connected";return e.jsxs("button",{type:"button",onClick:()=>j(b.id),className:`w-full text-left p-4 rounded-lg border transition-colors cursor-pointer ${C?"border-cc-primary bg-cc-primary/5":"border-cc-border hover:border-cc-border hover:bg-cc-hover/50"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:`w-4 h-4 rounded-full border-2 flex items-center justify-center flex-shrink-0 ${C?"border-cc-primary":"border-cc-border"}`,children:C&&e.jsx("div",{className:"w-2 h-2 rounded-full bg-cc-primary"})}),e.jsx("span",{className:"text-sm font-medium text-cc-fg truncate",children:b.name})]}),e.jsx("span",{className:`px-2 py-0.5 text-[10px] rounded-full border flex-shrink-0 ${p?"bg-cc-success/10 text-cc-success border-cc-success/20":"bg-cc-hover text-cc-muted border-cc-border"}`,children:p?"Connected":"Not installed"})]}),!p&&C&&e.jsxs("p",{className:"mt-2 ml-6 text-xs text-cc-warning",children:["This connection needs to be installed to a workspace first."," ",e.jsx("a",{href:"#/integrations/linear-oauth",className:"text-cc-primary underline",onClick:S=>S.stopPropagation(),children:"Install now"})]})]},b.id)}),e.jsx("a",{href:"#/integrations/linear-oauth",className:"block text-center text-xs text-cc-primary hover:underline py-2",children:"+ Create a new OAuth connection"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("button",{onClick:i,className:"px-4 py-2.5 rounded-lg text-sm font-medium text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Back"}),e.jsx("button",{onClick:()=>k&&t(g),disabled:!k,className:`px-4 py-2.5 rounded-lg text-sm font-medium transition-colors ${k?"bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer":"bg-cc-hover text-cc-muted cursor-not-allowed"}`,children:"Next"})]})]})}const Ve=`You are an AI agent responding to a Linear issue. The issue context will be provided when you are @mentioned.
1
+ import{r,j as e,u as Be,a as E,z as ae,F as ye,L as ne,t as ze,H as Ne,B as Ie,I as Oe}from"./index-DOle27vf.js";const Ee="companion_public_url_dismissed";function De({publicUrl:t}){const[i,d]=r.useState(()=>localStorage.getItem(Ee)==="1");return t||i?null:e.jsxs("div",{className:"mb-4 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/30 text-amber-400 text-xs flex items-start justify-between gap-3",role:"alert",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"No public URL configured."})," ","Webhook URLs currently use your browser address, which external services like Linear may not be able to reach."," ",e.jsx("a",{href:"#/settings",className:"underline hover:text-amber-300",children:"Set your public URL in Settings"}),"."]}),e.jsx("button",{onClick:()=>{localStorage.setItem(Ee,"1"),d(!0)},className:"text-amber-400 hover:text-amber-200 transition-colors cursor-pointer flex-shrink-0","aria-label":"Dismiss public URL banner",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]})}function He({steps:t,currentStep:i,completedSteps:d}){return e.jsx("nav",{"aria-label":"Setup progress",className:"flex items-center gap-0 w-full mb-8",children:t.map((a,m)=>{const u=m+1,h=d.has(u),g=u===i,j=!h&&!g;return e.jsxs("div",{className:"flex items-center flex-1 last:flex-none",children:[e.jsxs("div",{className:"flex flex-col items-center gap-1.5",children:[e.jsx("div",{className:`flex items-center justify-center w-8 h-8 rounded-full text-xs font-semibold border-2 transition-colors ${h?"bg-cc-success/15 border-cc-success text-cc-success":g?"bg-cc-primary/15 border-cc-primary text-cc-primary":"bg-cc-hover border-cc-border text-cc-muted"}`,"aria-current":g?"step":void 0,"aria-label":`Step ${u}: ${a.label}${h?" (completed)":g?" (current)":""}`,children:h?e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):u}),e.jsx("span",{className:`text-[10px] whitespace-nowrap ${j?"text-cc-muted":g?"text-cc-primary font-medium":"text-cc-success"}`,children:a.label})]}),m<t.length-1&&e.jsx("div",{className:`flex-1 h-0.5 mx-2 mt-[-18px] rounded ${d.has(u)?"bg-cc-success/40":"bg-cc-border"}`})]},u)})})}function Pe({onNext:t}){const i=Be(m=>m.publicUrl),d=i||window.location.origin,a=!!i;return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"pt-1",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-widest text-cc-primary font-medium mb-2",children:"Linear Agent Setup"}),e.jsx("h2",{className:"text-xl font-semibold text-cc-fg tracking-tight leading-tight",children:"Connect your Linear workspace"}),e.jsx("p",{className:"mt-2 text-sm text-cc-muted leading-relaxed max-w-md",children:"This wizard connects the Agent Interaction SDK so your agent can respond to @mentions in Linear issues."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`mt-0.5 flex-shrink-0 w-5 h-5 rounded-full flex items-center justify-center ${a?"bg-cc-success/15 text-cc-success":"bg-cc-warning/15 text-cc-warning"}`,children:a?e.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):e.jsx("span",{className:"text-[10px] font-bold",children:"!"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[13px] text-cc-fg font-medium",children:"Public URL"}),e.jsx("p",{className:"text-xs text-cc-muted mt-0.5 leading-relaxed",children:a?e.jsx(e.Fragment,{children:e.jsx("code",{className:"px-1 py-0.5 rounded bg-cc-hover text-[10px] font-mono-code",children:i})}):e.jsxs(e.Fragment,{children:["Not set. Linear needs to reach your instance. Configure in ",e.jsx("a",{href:"#/integrations/tailscale",className:"text-cc-primary hover:underline",children:"Tailscale"})," or ",e.jsx("a",{href:"#/settings",className:"text-cc-primary hover:underline",children:"Settings"}),"."]})})]})]}),e.jsx("div",{className:"border-t border-cc-border/50"}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 flex-shrink-0 w-5 h-5 rounded-full flex items-center justify-center bg-cc-hover text-cc-muted",children:e.jsx("span",{className:"text-[10px] font-semibold",children:"1"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[13px] text-cc-fg font-medium",children:"Create a Linear OAuth app"}),e.jsx("p",{className:"text-xs text-cc-muted mt-0.5 leading-relaxed",children:e.jsx("a",{href:"https://linear.app/settings/api",target:"_blank",rel:"noopener noreferrer",className:"text-cc-primary hover:underline",children:"Linear → Settings → API → OAuth Applications"})}),e.jsxs("dl",{className:"mt-3 space-y-2.5 text-xs",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-cc-muted",children:"Webhooks"}),e.jsxs("dd",{className:"text-cc-fg mt-0.5",children:["Enable and subscribe to ",e.jsx("strong",{children:"Agent session events"})]})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-cc-muted",children:"Scope"}),e.jsx("dd",{className:"mt-0.5",children:e.jsx("code",{className:"px-1.5 py-0.5 rounded bg-cc-hover text-cc-fg text-[10px] font-mono-code",children:"app:mentionable"})})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-cc-muted",children:"Redirect URI"}),e.jsx("dd",{className:"mt-0.5",children:e.jsx("code",{className:"px-1.5 py-0.5 rounded bg-cc-hover text-cc-fg text-[10px] font-mono-code break-all",children:`${d}/api/linear/oauth/callback`})})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-cc-muted",children:"Webhook URL"}),e.jsx("dd",{className:"mt-0.5",children:e.jsx("code",{className:"px-1.5 py-0.5 rounded bg-cc-hover text-cc-fg text-[10px] font-mono-code break-all",children:`${d}/api/linear/agent-webhook`})})]})]})]})]})]}),e.jsx("div",{className:"flex justify-end pt-1",children:e.jsx("button",{onClick:t,className:"px-5 py-2.5 rounded-lg text-sm font-medium bg-cc-primary hover:bg-cc-primary-hover text-white transition-colors cursor-pointer",children:"Next"})})]})}function Ue({onNext:t,onBack:i,selectedConnectionId:d}){const[a,m]=r.useState([]),[u,h]=r.useState(!0),[g,j]=r.useState(d||""),[y,l]=r.useState("");r.useEffect(()=>{E.listLinearOAuthConnections().then(b=>{m(b.connections),l(""),d?b.connections.some(p=>p.id===d)&&j(d):b.connections.length===1&&j(b.connections[0].id)}).catch(b=>l(b instanceof Error?b.message:String(b))).finally(()=>h(!1))},[d]);const N=a.find(b=>b.id===g),k=!!g&&(N==null?void 0:N.status)==="connected";return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-cc-fg",children:"Select OAuth Connection"}),e.jsx("p",{className:"mt-1 text-sm text-cc-muted",children:"Choose which Linear OAuth app this agent should use for @mention triggers."})]}),y&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:y}),u?e.jsx("p",{className:"text-sm text-cc-muted",children:"Loading connections..."}):a.length===0?e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-bg p-5 text-center space-y-3",children:[e.jsx("p",{className:"text-sm text-cc-muted",children:"No OAuth connections found."}),e.jsx("p",{className:"text-xs text-cc-muted",children:"Create an OAuth app connection first, then come back to set up the agent."}),e.jsx("a",{href:"#/integrations/linear-oauth",className:"inline-flex px-4 py-2.5 rounded-lg text-sm font-medium bg-cc-primary hover:bg-cc-primary-hover text-white transition-colors",children:"Go to OAuth Settings"})]}):e.jsxs("div",{className:"space-y-3",children:[a.map(b=>{const C=g===b.id,p=b.status==="connected";return e.jsxs("button",{type:"button",onClick:()=>j(b.id),className:`w-full text-left p-4 rounded-lg border transition-colors cursor-pointer ${C?"border-cc-primary bg-cc-primary/5":"border-cc-border hover:border-cc-border hover:bg-cc-hover/50"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:`w-4 h-4 rounded-full border-2 flex items-center justify-center flex-shrink-0 ${C?"border-cc-primary":"border-cc-border"}`,children:C&&e.jsx("div",{className:"w-2 h-2 rounded-full bg-cc-primary"})}),e.jsx("span",{className:"text-sm font-medium text-cc-fg truncate",children:b.name})]}),e.jsx("span",{className:`px-2 py-0.5 text-[10px] rounded-full border flex-shrink-0 ${p?"bg-cc-success/10 text-cc-success border-cc-success/20":"bg-cc-hover text-cc-muted border-cc-border"}`,children:p?"Connected":"Not installed"})]}),!p&&C&&e.jsxs("p",{className:"mt-2 ml-6 text-xs text-cc-warning",children:["This connection needs to be installed to a workspace first."," ",e.jsx("a",{href:"#/integrations/linear-oauth",className:"text-cc-primary underline",onClick:S=>S.stopPropagation(),children:"Install now"})]})]},b.id)}),e.jsx("a",{href:"#/integrations/linear-oauth",className:"block text-center text-xs text-cc-primary hover:underline py-2",children:"+ Create a new OAuth connection"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("button",{onClick:i,className:"px-4 py-2.5 rounded-lg text-sm font-medium text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Back"}),e.jsx("button",{onClick:()=>k&&t(g),disabled:!k,className:`px-4 py-2.5 rounded-lg text-sm font-medium transition-colors ${k?"bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer":"bg-cc-hover text-cc-muted cursor-not-allowed"}`,children:"Next"})]})]})}const Ve=`You are an AI agent responding to a Linear issue. The issue context will be provided when you are @mentioned.
2
2
 
3
3
  Read the issue details carefully, then complete the requested task. When done, summarize what you did.
4
4
 
5
- {{input}}`;function Fe({onNext:t,onBack:i,oauthConnectionId:d,stagingId:a,cloneFromAgentId:m,existingAgent:u}){const h=!!u,[g,j]=r.useState((u==null?void 0:u.name)??"Linear Agent"),[y,l]=r.useState((u==null?void 0:u.prompt)??Ve),[N,k]=r.useState((u==null?void 0:u.backendType)??"claude"),[b,C]=r.useState((u==null?void 0:u.model)??""),[p,S]=r.useState((u==null?void 0:u.cwd)??""),[M,E]=r.useState(!1),[w,L]=r.useState(!1),[B,R]=r.useState(""),U=p?p.split("/").pop()||p:"Temp directory";async function V(){if(!g.trim()){R("Agent name is required.");return}if(!y.trim()){R("Agent prompt is required.");return}L(!0),R("");try{const o={version:1,name:g.trim(),description:"Linear Agent created via setup wizard",backendType:N,model:b||ae(N),permissionMode:"bypassPermissions",cwd:p||"",prompt:y.trim(),triggers:{webhook:{enabled:!1,secret:""},schedule:{enabled:!1,expression:"",recurring:!0},linear:{enabled:!0,...d?{oauthConnectionId:d}:{}}},enabled:!0};if(h)await z.updateAgent(u.id,o),t(u.id,g.trim());else{const I=await z.createAgent({...o,...a?{stagingId:a}:{},...m?{cloneFromAgentId:m}:{}});t(I.id,I.name)}}catch(o){R(o instanceof Error?o.message:String(o))}finally{L(!1)}}const D="w-full px-3 py-2.5 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/60";return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-cc-fg",children:h?"Edit Linear Agent":"Configure Your Agent"}),e.jsx("p",{className:"mt-1 text-sm text-cc-muted",children:h?"Update the agent settings. These can be customized further in the Agents page.":"Set up the agent that will respond to @mentions in Linear. You can customize it further in the Agents page later."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-cc-fg mb-1.5",htmlFor:"wizard-agent-name",children:"Agent Name"}),e.jsx("input",{id:"wizard-agent-name",type:"text",value:g,onChange:o=>j(o.target.value),placeholder:"My Linear Agent",className:D})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-cc-fg mb-1.5",children:"Backend"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>{k("claude"),C("")},className:`flex-1 px-3 py-2 rounded-lg text-sm font-medium border transition-colors cursor-pointer ${N==="claude"?"border-cc-primary bg-cc-primary/10 text-cc-primary":"border-cc-border text-cc-muted hover:text-cc-fg"}`,children:"Claude Code"}),e.jsx("button",{onClick:()=>{k("codex"),C("")},className:`flex-1 px-3 py-2 rounded-lg text-sm font-medium border transition-colors cursor-pointer ${N==="codex"?"border-cc-primary bg-cc-primary/10 text-cc-primary":"border-cc-border text-cc-muted hover:text-cc-fg"}`,children:"Codex"})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-cc-fg mb-1.5",htmlFor:"wizard-agent-model",children:["Model ",e.jsx("span",{className:"text-cc-muted font-normal",children:"(optional)"})]}),e.jsx("input",{id:"wizard-agent-model",type:"text",value:b,onChange:o=>C(o.target.value),placeholder:`${ae(N)} (default)`,className:D})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-cc-fg mb-1.5",children:"Working Directory"}),e.jsxs("button",{onClick:()=>E(!0),className:"flex items-center gap-2 px-3 py-2.5 rounded-lg border border-cc-border bg-cc-input-bg text-sm text-cc-fg hover:border-cc-primary/40 transition-colors cursor-pointer w-full text-left",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 text-cc-muted flex-shrink-0",children:e.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.879a1.5 1.5 0 011.06.44l1.122 1.12A1.5 1.5 0 009.62 4H13.5A1.5 1.5 0 0115 5.5v7a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})}),e.jsx("span",{className:"truncate font-mono-code text-cc-muted",children:U}),p&&e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-muted hover:text-cc-fg flex-shrink-0 ml-auto",onClick:o=>{o.stopPropagation(),S("")},children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})]}),e.jsx("p",{className:"text-[10px] text-cc-muted mt-1",children:"Leave empty to use a temporary directory for each run."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-cc-fg mb-1.5",htmlFor:"wizard-agent-prompt",children:"Prompt"}),e.jsx("textarea",{id:"wizard-agent-prompt",value:y,onChange:o=>l(o.target.value),rows:6,placeholder:"Instructions for your agent...",className:`${D} font-mono-code text-xs leading-relaxed resize-y`}),e.jsxs("p",{className:"text-[10px] text-cc-muted mt-1",children:["Use ",e.jsx("code",{className:"px-1 py-0.5 rounded bg-cc-hover",children:"{{input}}"})," as a placeholder for the trigger-provided context."]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded-full text-xs font-medium bg-cc-success/10 text-cc-success border border-cc-success/20",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:e.jsx("path",{d:"M3 1a1 1 0 00-1 1v12a1 1 0 001 1h10a1 1 0 001-1V2a1 1 0 00-1-1H3zm1 2h8v2H4V3zm0 4h5v2H4V7zm0 4h8v2H4v-2z"})}),"Linear Agent trigger enabled"]})})]}),B&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:B}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("button",{onClick:i,className:"px-4 py-2.5 rounded-lg text-sm font-medium text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Back"}),e.jsx("button",{onClick:V,disabled:w,className:`px-4 py-2.5 rounded-lg text-sm font-medium transition-colors ${w?"bg-cc-hover text-cc-muted cursor-not-allowed":"bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer"}`,children:w?h?"Saving...":"Creating...":h?"Save Agent":"Create Agent"})]}),M&&e.jsx(ye,{initialPath:p||"/",onSelect:o=>{S(o),E(!1)},onClose:()=>E(!1)})]})}function _e({agentName:t,onFinish:i,onAddAnotherSameApp:d,onAddAnotherNewApp:a}){const[m,u]=r.useState(!1);return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"pt-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-5 h-5 rounded-full bg-cc-success/15 flex items-center justify-center",children:e.jsx("svg",{className:"w-3 h-3 text-cc-success",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})}),e.jsx("p",{className:"text-[11px] uppercase tracking-widest text-cc-success font-medium",children:"Complete"})]}),e.jsxs("h2",{className:"text-xl font-semibold text-cc-fg tracking-tight leading-tight",children:[t," is live"]}),e.jsx("p",{className:"mt-2 text-sm text-cc-muted leading-relaxed max-w-md",children:"Your agent is connected and listening for @mentions in Linear."})]}),e.jsx("div",{className:"space-y-3",children:[{label:"OAuth app connected",detail:"Your Linear workspace is linked"},{label:`Agent "${t}" created`,detail:"Linear trigger enabled with full auto permissions"},{label:"Ready for @mentions",detail:"Mention the agent in any issue to trigger a session"}].map(h=>e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 flex-shrink-0 w-5 h-5 rounded-full bg-cc-success/12 flex items-center justify-center",children:e.jsx("svg",{className:"w-2.5 h-2.5 text-cc-success",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[13px] font-medium text-cc-fg",children:h.label}),e.jsx("p",{className:"text-xs text-cc-muted mt-0.5",children:h.detail})]})]},h.label))}),e.jsxs("div",{className:"border-t border-cc-border/50 pt-5",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-widest text-cc-muted font-medium mb-3",children:"Next steps"}),e.jsxs("ul",{className:"space-y-2 text-xs text-cc-muted leading-relaxed",children:[e.jsxs("li",{children:["@mention ",e.jsx("strong",{className:"text-cc-fg",children:t})," in any Linear issue to test it"]}),e.jsxs("li",{children:["Fine-tune in the"," ",e.jsx("a",{href:"#/agents",className:"text-cc-primary hover:underline",children:"Agents page"})]}),e.jsxs("li",{children:["Manage credentials in"," ",e.jsx("a",{href:"#/integrations/linear-oauth",className:"text-cc-primary hover:underline",children:"OAuth Settings"})]})]})]}),m&&(d||a)&&e.jsxs("div",{className:"border-t border-cc-border/50 pt-5 space-y-3",children:[e.jsx("p",{className:"text-[13px] font-medium text-cc-fg",children:"Create another agent"}),e.jsx("p",{className:"text-xs text-cc-muted",children:"Reuse the same OAuth connection or set up a new one?"}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[d&&e.jsx("button",{onClick:d,className:"flex-1 px-3 py-2.5 rounded-lg text-xs font-medium border border-cc-border text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Same OAuth app"}),a&&e.jsx("button",{onClick:a,className:"flex-1 px-3 py-2.5 rounded-lg text-xs font-medium border border-cc-border text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Different OAuth app"})]})]}),e.jsxs("div",{className:"flex justify-between pt-1",children:[(d||a)&&!m&&e.jsx("button",{onClick:()=>u(!0),className:"text-xs font-medium text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"+ Create Another Agent"}),e.jsx("button",{onClick:i,className:"px-5 py-2.5 rounded-lg text-sm font-medium bg-cc-primary hover:bg-cc-primary-hover text-white transition-colors cursor-pointer ml-auto",children:"Go to Agents"})]})]})}const Ye=["bot","terminal","pencil","search","shield","chart","flask","rocket","wrench","clipboard","lightbulb","code","globe","zap","database","git-branch","mail","cpu"];function he({icon:t,className:i="w-5 h-5"}){const a={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",className:`${i} shrink-0`,role:"img","aria-label":t||"bot"};switch(t){case"bot":return e.jsxs("svg",{...a,children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),e.jsx("circle",{cx:"9",cy:"16",r:"1"}),e.jsx("circle",{cx:"15",cy:"16",r:"1"}),e.jsx("path",{d:"M12 2v4"}),e.jsx("path",{d:"M8 7h8"}),e.jsx("circle",{cx:"12",cy:"2",r:"1"})]});case"terminal":return e.jsxs("svg",{...a,children:[e.jsx("polyline",{points:"4 17 10 11 4 5"}),e.jsx("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]});case"pencil":return e.jsx("svg",{...a,children:e.jsx("path",{d:"M17 3a2.83 2.83 0 114 4L7.5 20.5 2 22l1.5-5.5Z"})});case"search":return e.jsxs("svg",{...a,children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]});case"shield":return e.jsx("svg",{...a,children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})});case"chart":return e.jsxs("svg",{...a,children:[e.jsx("line",{x1:"18",y1:"20",x2:"18",y2:"10"}),e.jsx("line",{x1:"12",y1:"20",x2:"12",y2:"4"}),e.jsx("line",{x1:"6",y1:"20",x2:"6",y2:"14"})]});case"flask":return e.jsxs("svg",{...a,children:[e.jsx("path",{d:"M9 3h6V8l5 10a1 1 0 01-.9 1.4H4.9A1 1 0 014 18L9 8V3z"}),e.jsx("line",{x1:"9",y1:"3",x2:"15",y2:"3"})]});case"rocket":return e.jsxs("svg",{...a,children:[e.jsx("path",{d:"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 00-2.91-.09z"}),e.jsx("path",{d:"M12 15l-3-3a22 22 0 012-3.95A12.88 12.88 0 0122 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 01-4 2z"}),e.jsx("path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"}),e.jsx("path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"})]});case"wrench":return e.jsx("svg",{...a,children:e.jsx("path",{d:"M14.7 6.3a1 1 0 000 1.4l1.6 1.6a1 1 0 001.4 0l3.77-3.77a6 6 0 01-7.94 7.94l-6.91 6.91a2.12 2.12 0 01-3-3l6.91-6.91a6 6 0 017.94-7.94l-3.76 3.76z"})});case"clipboard":return e.jsxs("svg",{...a,children:[e.jsx("path",{d:"M16 4h2a2 2 0 012 2v14a2 2 0 01-2 2H6a2 2 0 01-2-2V6a2 2 0 012-2h2"}),e.jsx("rect",{x:"8",y:"2",width:"8",height:"4",rx:"1"})]});case"lightbulb":return e.jsxs("svg",{...a,children:[e.jsx("path",{d:"M9 18h6"}),e.jsx("path",{d:"M10 22h4"}),e.jsx("path",{d:"M12 2a7 7 0 00-3 13.33V17h6v-1.67A7 7 0 0012 2z"})]});case"code":return e.jsxs("svg",{...a,children:[e.jsx("polyline",{points:"16 18 22 12 16 6"}),e.jsx("polyline",{points:"8 6 2 12 8 18"})]});case"globe":return e.jsxs("svg",{...a,children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"2",y1:"12",x2:"22",y2:"12"}),e.jsx("path",{d:"M12 2a15.3 15.3 0 014 10 15.3 15.3 0 01-4 10 15.3 15.3 0 01-4-10 15.3 15.3 0 014-10z"})]});case"zap":return e.jsx("svg",{...a,children:e.jsx("polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2"})});case"database":return e.jsxs("svg",{...a,children:[e.jsx("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),e.jsx("path",{d:"M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"}),e.jsx("path",{d:"M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"})]});case"git-branch":return e.jsxs("svg",{...a,children:[e.jsx("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),e.jsx("circle",{cx:"18",cy:"6",r:"3"}),e.jsx("circle",{cx:"6",cy:"18",r:"3"}),e.jsx("path",{d:"M18 9a9 9 0 01-9 9"})]});case"mail":return e.jsxs("svg",{...a,children:[e.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),e.jsx("polyline",{points:"22 7 12 13 2 7"})]});case"cpu":return e.jsxs("svg",{...a,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("rect",{x:"9",y:"9",width:"6",height:"6"}),e.jsx("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),e.jsx("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),e.jsx("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),e.jsx("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),e.jsx("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),e.jsx("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),e.jsx("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),e.jsx("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]});default:return t?e.jsx("span",{className:i,children:t}):e.jsxs("svg",{...a,children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),e.jsx("circle",{cx:"9",cy:"16",r:"1"}),e.jsx("circle",{cx:"15",cy:"16",r:"1"}),e.jsx("path",{d:"M12 2v4"}),e.jsx("path",{d:"M8 7h8"}),e.jsx("circle",{cx:"12",cy:"2",r:"1"})]})}}function Je({agent:t,copiedWebhook:i,onEdit:d,onDelete:a,onToggle:m,onExport:u,onCopyWebhook:h,onRegenerateSecret:g}){var b,C;const[j,y]=r.useState(!1),l=r.useRef(null);r.useEffect(()=>{if(!j)return;function p(S){l.current&&!l.current.contains(S.target)&&y(!1)}return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[j]),r.useEffect(()=>{if(!j)return;function p(S){S.key==="Escape"&&y(!1)}return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[j]);const N=(C=(b=t.triggers)==null?void 0:b.webhook)==null?void 0:C.enabled;function k(p){y(!1),p()}return e.jsxs("div",{className:"relative",ref:l,children:[e.jsx("button",{onClick:()=>y(!j),className:"p-1.5 rounded-lg text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",title:"More actions","aria-label":"More actions","aria-expanded":j,"aria-haspopup":"true",children:e.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:[e.jsx("circle",{cx:"8",cy:"3",r:"1.5"}),e.jsx("circle",{cx:"8",cy:"8",r:"1.5"}),e.jsx("circle",{cx:"8",cy:"13",r:"1.5"})]})}),j&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 w-48 bg-cc-card border border-cc-border rounded-xl shadow-lg z-20 py-1 origin-top-right",style:{animation:"menu-appear 120ms ease-out"},role:"menu",children:[e.jsxs("button",{onClick:()=>k(d),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:e.jsx("path",{d:"M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25c.081-.286.235-.547.445-.758l8.61-8.61z"})}),"Edit"]}),e.jsxs("button",{onClick:()=>k(u),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:e.jsx("path",{d:"M3.5 13a.5.5 0 01-.5-.5V11h1v1h8v-1h1v1.5a.5.5 0 01-.5.5h-9zM8 2a.5.5 0 01.5.5v6.793l2.146-2.147a.5.5 0 01.708.708l-3 3a.5.5 0 01-.708 0l-3-3a.5.5 0 01.708-.708L7.5 9.293V2.5A.5.5 0 018 2z"})}),"Export JSON"]}),N&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"my-1 border-t border-cc-border/40",role:"separator"}),e.jsxs("button",{onClick:()=>k(h),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:[e.jsx("path",{d:"M4.715 6.542L3.343 7.914a3 3 0 104.243 4.243l1.828-1.829A3 3 0 008.586 5.5L8 6.086a1 1 0 00-.154.199 2 2 0 01.861 3.337L6.88 11.45a2 2 0 11-2.83-2.83l.793-.792a4.018 4.018 0 01-.128-1.287z"}),e.jsx("path",{d:"M11.285 9.458l1.372-1.372a3 3 0 10-4.243-4.243L6.586 5.671A3 3 0 007.414 10.5l.586-.586a1 1 0 00.154-.199 2 2 0 01-.861-3.337L9.12 4.55a2 2 0 112.83 2.83l-.793.792c.112.42.155.855.128 1.287z"})]}),i===t.id?"Copied!":"Copy Webhook URL"]}),e.jsxs("button",{onClick:()=>k(g),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:[e.jsx("path",{d:"M11.534 7h3.932a.25.25 0 01.192.41l-1.966 2.36a.25.25 0 01-.384 0l-1.966-2.36a.25.25 0 01.192-.41zm-7 2H.602a.25.25 0 01-.192-.41l1.966-2.36a.25.25 0 01.384 0l1.966 2.36a.25.25 0 01-.192.41z"}),e.jsx("path",{d:"M8 3a5 5 0 014.546 2.914.5.5 0 00.908-.418A6 6 0 002 8c0 .088.002.176.006.264l-.058-.024a.5.5 0 00-.394.908l2 1a.5.5 0 00.668-.17L5.59 7.864a.5.5 0 00-.274-.846l-.09-.016A4 4 0 018 3zm.002 10a4 4 0 002.49-4.002l.09.016a.5.5 0 00.274.846l-1.367 2.114a.5.5 0 01-.668.17l-2-1a.5.5 0 01.394-.908l.058.024A5.972 5.972 0 008.002 13a5 5 0 01-4.546-2.914.5.5 0 00-.908.418A6 6 0 008.002 13z"})]}),"Regenerate Secret"]})]}),e.jsx("div",{className:"my-1 border-t border-cc-border/40",role:"separator"}),e.jsxs("button",{onClick:()=>k(m),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:t.enabled?e.jsx("path",{d:"M5 3a5 5 0 000 10h6a5 5 0 000-10H5zm6 3a2 2 0 110 4 2 2 0 010-4z"}):e.jsx("path",{d:"M11 3a5 5 0 010 10H5A5 5 0 015 3h6zM5 6a2 2 0 100 4 2 2 0 000-4z"})}),t.enabled?"Disable":"Enable"]}),e.jsx("div",{className:"my-1 border-t border-cc-border/40",role:"separator"}),e.jsxs("button",{onClick:()=>k(a),className:"w-full px-3 py-2 text-xs text-left text-cc-error hover:bg-cc-error/10 transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:e.jsx("path",{d:"M5.5 5.5a.5.5 0 01.5.5v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm5 0a.5.5 0 01.5.5v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm-7-3A1.5 1.5 0 015 1h6a1.5 1.5 0 011.5 1.5H14a.5.5 0 010 1h-.554L12.2 14.118A1.5 1.5 0 0110.706 15H5.294a1.5 1.5 0 01-1.494-.882L2.554 3.5H2a.5.5 0 010-1h1.5z"})}),"Delete"]})]})]})}function Ke(t,i){if(!i)return"One-time";const d=t.trim().split(/\s+/);if(d.length!==5)return t;const[a,m,,,u]=d;if(t==="* * * * *")return"Every minute";if(m==="*"&&a.startsWith("*/")){const h=parseInt(a.slice(2),10);return h===1?"Every minute":`Every ${h} minutes`}if(a==="0"&&m==="*")return"Every hour";if(a==="0"&&m.startsWith("*/")){const h=parseInt(m.slice(2),10);return h===1?"Every hour":`Every ${h} hours`}if(a!=="*"&&m!=="*"&&!m.includes("/")&&!m.includes(",")){const h=parseInt(m,10),g=parseInt(a,10);if(!isNaN(h)&&!isNaN(g)){const j=h>=12?"PM":"AM",y=h===0?12:h>12?h-12:h,l=g.toString().padStart(2,"0"),N=`${y}:${l} ${j}`;if(u==="*")return`Daily at ${N}`;if(u==="1-5")return`Weekdays at ${N}`}}return t}function qe(t,i){var a,m;return`${i||window.location.origin}/api/agents/${encodeURIComponent(t.id)}/webhook/${((m=(a=t.triggers)==null?void 0:a.webhook)==null?void 0:m.secret)||""}`}function Ge({agent:t,publicUrl:i,onEdit:d,onDelete:a,onToggle:m,onRun:u,onExport:h,onCopyWebhook:g,onRegenerateSecret:j,copiedWebhook:y}){var k,b,C,p,S,M,E,w;const l=["Manual"];(b=(k=t.triggers)==null?void 0:k.webhook)!=null&&b.enabled&&l.push("Webhook"),(p=(C=t.triggers)==null?void 0:C.schedule)!=null&&p.enabled&&l.push(Ke(t.triggers.schedule.expression,t.triggers.schedule.recurring)),(M=(S=t.triggers)==null?void 0:S.linear)!=null&&M.enabled&&l.push("Linear Agent");const N=(w=(E=t.triggers)==null?void 0:E.linear)==null?void 0:w.enabled;return e.jsxs("div",{className:`
5
+ {{input}}`;function Fe({onNext:t,onBack:i,oauthConnectionId:d,stagingId:a,cloneFromAgentId:m,existingAgent:u}){const h=!!u,[g,j]=r.useState((u==null?void 0:u.name)??"Linear Agent"),[y,l]=r.useState((u==null?void 0:u.prompt)??Ve),[N,k]=r.useState((u==null?void 0:u.backendType)??"claude"),[b,C]=r.useState((u==null?void 0:u.model)??""),[p,S]=r.useState((u==null?void 0:u.cwd)??""),[M,z]=r.useState(!1),[w,L]=r.useState(!1),[B,R]=r.useState(""),U=p?p.split("/").pop()||p:"Temp directory";async function V(){if(!g.trim()){R("Agent name is required.");return}if(!y.trim()){R("Agent prompt is required.");return}L(!0),R("");try{const o={version:1,name:g.trim(),description:"Linear Agent created via setup wizard",backendType:N,model:b||ae(N),permissionMode:"bypassPermissions",cwd:p||"",prompt:y.trim(),triggers:{webhook:{enabled:!1,secret:""},schedule:{enabled:!1,expression:"",recurring:!0},linear:{enabled:!0,...d?{oauthConnectionId:d}:{}}},enabled:!0};if(h)await E.updateAgent(u.id,o),t(u.id,g.trim());else{const O=await E.createAgent({...o,...a?{stagingId:a}:{},...m?{cloneFromAgentId:m}:{}});t(O.id,O.name)}}catch(o){R(o instanceof Error?o.message:String(o))}finally{L(!1)}}const D="w-full px-3 py-2.5 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/60";return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-cc-fg",children:h?"Edit Linear Agent":"Configure Your Agent"}),e.jsx("p",{className:"mt-1 text-sm text-cc-muted",children:h?"Update the agent settings. These can be customized further in the Agents page.":"Set up the agent that will respond to @mentions in Linear. You can customize it further in the Agents page later."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-cc-fg mb-1.5",htmlFor:"wizard-agent-name",children:"Agent Name"}),e.jsx("input",{id:"wizard-agent-name",type:"text",value:g,onChange:o=>j(o.target.value),placeholder:"My Linear Agent",className:D})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-cc-fg mb-1.5",children:"Backend"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>{k("claude"),C("")},className:`flex-1 px-3 py-2 rounded-lg text-sm font-medium border transition-colors cursor-pointer ${N==="claude"?"border-cc-primary bg-cc-primary/10 text-cc-primary":"border-cc-border text-cc-muted hover:text-cc-fg"}`,children:"Claude Code"}),e.jsx("button",{onClick:()=>{k("codex"),C("")},className:`flex-1 px-3 py-2 rounded-lg text-sm font-medium border transition-colors cursor-pointer ${N==="codex"?"border-cc-primary bg-cc-primary/10 text-cc-primary":"border-cc-border text-cc-muted hover:text-cc-fg"}`,children:"Codex"})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-cc-fg mb-1.5",htmlFor:"wizard-agent-model",children:["Model ",e.jsx("span",{className:"text-cc-muted font-normal",children:"(optional)"})]}),e.jsx("input",{id:"wizard-agent-model",type:"text",value:b,onChange:o=>C(o.target.value),placeholder:`${ae(N)} (default)`,className:D})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-cc-fg mb-1.5",children:"Working Directory"}),e.jsxs("button",{onClick:()=>z(!0),className:"flex items-center gap-2 px-3 py-2.5 rounded-lg border border-cc-border bg-cc-input-bg text-sm text-cc-fg hover:border-cc-primary/40 transition-colors cursor-pointer w-full text-left",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 text-cc-muted flex-shrink-0",children:e.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.879a1.5 1.5 0 011.06.44l1.122 1.12A1.5 1.5 0 009.62 4H13.5A1.5 1.5 0 0115 5.5v7a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})}),e.jsx("span",{className:"truncate font-mono-code text-cc-muted",children:U}),p&&e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-muted hover:text-cc-fg flex-shrink-0 ml-auto",onClick:o=>{o.stopPropagation(),S("")},children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})]}),e.jsx("p",{className:"text-[10px] text-cc-muted mt-1",children:"Leave empty to use a temporary directory for each run."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-cc-fg mb-1.5",htmlFor:"wizard-agent-prompt",children:"Prompt"}),e.jsx("textarea",{id:"wizard-agent-prompt",value:y,onChange:o=>l(o.target.value),rows:6,placeholder:"Instructions for your agent...",className:`${D} font-mono-code text-xs leading-relaxed resize-y`}),e.jsxs("p",{className:"text-[10px] text-cc-muted mt-1",children:["Use ",e.jsx("code",{className:"px-1 py-0.5 rounded bg-cc-hover",children:"{{input}}"})," as a placeholder for the trigger-provided context."]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded-full text-xs font-medium bg-cc-success/10 text-cc-success border border-cc-success/20",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:e.jsx("path",{d:"M3 1a1 1 0 00-1 1v12a1 1 0 001 1h10a1 1 0 001-1V2a1 1 0 00-1-1H3zm1 2h8v2H4V3zm0 4h5v2H4V7zm0 4h8v2H4v-2z"})}),"Linear Agent trigger enabled"]})})]}),B&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:B}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("button",{onClick:i,className:"px-4 py-2.5 rounded-lg text-sm font-medium text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Back"}),e.jsx("button",{onClick:V,disabled:w,className:`px-4 py-2.5 rounded-lg text-sm font-medium transition-colors ${w?"bg-cc-hover text-cc-muted cursor-not-allowed":"bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer"}`,children:w?h?"Saving...":"Creating...":h?"Save Agent":"Create Agent"})]}),M&&e.jsx(ye,{initialPath:p||"/",onSelect:o=>{S(o),z(!1)},onClose:()=>z(!1)})]})}function _e({agentName:t,onFinish:i,onAddAnotherSameApp:d,onAddAnotherNewApp:a}){const[m,u]=r.useState(!1);return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"pt-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-5 h-5 rounded-full bg-cc-success/15 flex items-center justify-center",children:e.jsx("svg",{className:"w-3 h-3 text-cc-success",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})}),e.jsx("p",{className:"text-[11px] uppercase tracking-widest text-cc-success font-medium",children:"Complete"})]}),e.jsxs("h2",{className:"text-xl font-semibold text-cc-fg tracking-tight leading-tight",children:[t," is live"]}),e.jsx("p",{className:"mt-2 text-sm text-cc-muted leading-relaxed max-w-md",children:"Your agent is connected and listening for @mentions in Linear."})]}),e.jsx("div",{className:"space-y-3",children:[{label:"OAuth app connected",detail:"Your Linear workspace is linked"},{label:`Agent "${t}" created`,detail:"Linear trigger enabled with full auto permissions"},{label:"Ready for @mentions",detail:"Mention the agent in any issue to trigger a session"}].map(h=>e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 flex-shrink-0 w-5 h-5 rounded-full bg-cc-success/12 flex items-center justify-center",children:e.jsx("svg",{className:"w-2.5 h-2.5 text-cc-success",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[13px] font-medium text-cc-fg",children:h.label}),e.jsx("p",{className:"text-xs text-cc-muted mt-0.5",children:h.detail})]})]},h.label))}),e.jsxs("div",{className:"border-t border-cc-border/50 pt-5",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-widest text-cc-muted font-medium mb-3",children:"Next steps"}),e.jsxs("ul",{className:"space-y-2 text-xs text-cc-muted leading-relaxed",children:[e.jsxs("li",{children:["@mention ",e.jsx("strong",{className:"text-cc-fg",children:t})," in any Linear issue to test it"]}),e.jsxs("li",{children:["Fine-tune in the"," ",e.jsx("a",{href:"#/agents",className:"text-cc-primary hover:underline",children:"Agents page"})]}),e.jsxs("li",{children:["Manage credentials in"," ",e.jsx("a",{href:"#/integrations/linear-oauth",className:"text-cc-primary hover:underline",children:"OAuth Settings"})]})]})]}),m&&(d||a)&&e.jsxs("div",{className:"border-t border-cc-border/50 pt-5 space-y-3",children:[e.jsx("p",{className:"text-[13px] font-medium text-cc-fg",children:"Create another agent"}),e.jsx("p",{className:"text-xs text-cc-muted",children:"Reuse the same OAuth connection or set up a new one?"}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[d&&e.jsx("button",{onClick:d,className:"flex-1 px-3 py-2.5 rounded-lg text-xs font-medium border border-cc-border text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Same OAuth app"}),a&&e.jsx("button",{onClick:a,className:"flex-1 px-3 py-2.5 rounded-lg text-xs font-medium border border-cc-border text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Different OAuth app"})]})]}),e.jsxs("div",{className:"flex justify-between pt-1",children:[(d||a)&&!m&&e.jsx("button",{onClick:()=>u(!0),className:"text-xs font-medium text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"+ Create Another Agent"}),e.jsx("button",{onClick:i,className:"px-5 py-2.5 rounded-lg text-sm font-medium bg-cc-primary hover:bg-cc-primary-hover text-white transition-colors cursor-pointer ml-auto",children:"Go to Agents"})]})]})}const Ye=["bot","terminal","pencil","search","shield","chart","flask","rocket","wrench","clipboard","lightbulb","code","globe","zap","database","git-branch","mail","cpu"];function he({icon:t,className:i="w-5 h-5"}){const a={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",className:`${i} shrink-0`,role:"img","aria-label":t||"bot"};switch(t){case"bot":return e.jsxs("svg",{...a,children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),e.jsx("circle",{cx:"9",cy:"16",r:"1"}),e.jsx("circle",{cx:"15",cy:"16",r:"1"}),e.jsx("path",{d:"M12 2v4"}),e.jsx("path",{d:"M8 7h8"}),e.jsx("circle",{cx:"12",cy:"2",r:"1"})]});case"terminal":return e.jsxs("svg",{...a,children:[e.jsx("polyline",{points:"4 17 10 11 4 5"}),e.jsx("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]});case"pencil":return e.jsx("svg",{...a,children:e.jsx("path",{d:"M17 3a2.83 2.83 0 114 4L7.5 20.5 2 22l1.5-5.5Z"})});case"search":return e.jsxs("svg",{...a,children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]});case"shield":return e.jsx("svg",{...a,children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})});case"chart":return e.jsxs("svg",{...a,children:[e.jsx("line",{x1:"18",y1:"20",x2:"18",y2:"10"}),e.jsx("line",{x1:"12",y1:"20",x2:"12",y2:"4"}),e.jsx("line",{x1:"6",y1:"20",x2:"6",y2:"14"})]});case"flask":return e.jsxs("svg",{...a,children:[e.jsx("path",{d:"M9 3h6V8l5 10a1 1 0 01-.9 1.4H4.9A1 1 0 014 18L9 8V3z"}),e.jsx("line",{x1:"9",y1:"3",x2:"15",y2:"3"})]});case"rocket":return e.jsxs("svg",{...a,children:[e.jsx("path",{d:"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 00-2.91-.09z"}),e.jsx("path",{d:"M12 15l-3-3a22 22 0 012-3.95A12.88 12.88 0 0122 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 01-4 2z"}),e.jsx("path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"}),e.jsx("path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"})]});case"wrench":return e.jsx("svg",{...a,children:e.jsx("path",{d:"M14.7 6.3a1 1 0 000 1.4l1.6 1.6a1 1 0 001.4 0l3.77-3.77a6 6 0 01-7.94 7.94l-6.91 6.91a2.12 2.12 0 01-3-3l6.91-6.91a6 6 0 017.94-7.94l-3.76 3.76z"})});case"clipboard":return e.jsxs("svg",{...a,children:[e.jsx("path",{d:"M16 4h2a2 2 0 012 2v14a2 2 0 01-2 2H6a2 2 0 01-2-2V6a2 2 0 012-2h2"}),e.jsx("rect",{x:"8",y:"2",width:"8",height:"4",rx:"1"})]});case"lightbulb":return e.jsxs("svg",{...a,children:[e.jsx("path",{d:"M9 18h6"}),e.jsx("path",{d:"M10 22h4"}),e.jsx("path",{d:"M12 2a7 7 0 00-3 13.33V17h6v-1.67A7 7 0 0012 2z"})]});case"code":return e.jsxs("svg",{...a,children:[e.jsx("polyline",{points:"16 18 22 12 16 6"}),e.jsx("polyline",{points:"8 6 2 12 8 18"})]});case"globe":return e.jsxs("svg",{...a,children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"2",y1:"12",x2:"22",y2:"12"}),e.jsx("path",{d:"M12 2a15.3 15.3 0 014 10 15.3 15.3 0 01-4 10 15.3 15.3 0 01-4-10 15.3 15.3 0 014-10z"})]});case"zap":return e.jsx("svg",{...a,children:e.jsx("polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2"})});case"database":return e.jsxs("svg",{...a,children:[e.jsx("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),e.jsx("path",{d:"M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"}),e.jsx("path",{d:"M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"})]});case"git-branch":return e.jsxs("svg",{...a,children:[e.jsx("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),e.jsx("circle",{cx:"18",cy:"6",r:"3"}),e.jsx("circle",{cx:"6",cy:"18",r:"3"}),e.jsx("path",{d:"M18 9a9 9 0 01-9 9"})]});case"mail":return e.jsxs("svg",{...a,children:[e.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),e.jsx("polyline",{points:"22 7 12 13 2 7"})]});case"cpu":return e.jsxs("svg",{...a,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("rect",{x:"9",y:"9",width:"6",height:"6"}),e.jsx("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),e.jsx("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),e.jsx("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),e.jsx("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),e.jsx("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),e.jsx("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),e.jsx("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),e.jsx("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]});default:return t?e.jsx("span",{className:i,children:t}):e.jsxs("svg",{...a,children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),e.jsx("circle",{cx:"9",cy:"16",r:"1"}),e.jsx("circle",{cx:"15",cy:"16",r:"1"}),e.jsx("path",{d:"M12 2v4"}),e.jsx("path",{d:"M8 7h8"}),e.jsx("circle",{cx:"12",cy:"2",r:"1"})]})}}function Je({agent:t,copiedWebhook:i,onEdit:d,onDelete:a,onToggle:m,onExport:u,onCopyWebhook:h,onRegenerateSecret:g}){var b,C;const[j,y]=r.useState(!1),l=r.useRef(null);r.useEffect(()=>{if(!j)return;function p(S){l.current&&!l.current.contains(S.target)&&y(!1)}return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[j]),r.useEffect(()=>{if(!j)return;function p(S){S.key==="Escape"&&y(!1)}return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[j]);const N=(C=(b=t.triggers)==null?void 0:b.webhook)==null?void 0:C.enabled;function k(p){y(!1),p()}return e.jsxs("div",{className:"relative",ref:l,children:[e.jsx("button",{onClick:()=>y(!j),className:"p-1.5 rounded-lg text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",title:"More actions","aria-label":"More actions","aria-expanded":j,"aria-haspopup":"true",children:e.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:[e.jsx("circle",{cx:"8",cy:"3",r:"1.5"}),e.jsx("circle",{cx:"8",cy:"8",r:"1.5"}),e.jsx("circle",{cx:"8",cy:"13",r:"1.5"})]})}),j&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 w-48 bg-cc-card border border-cc-border rounded-xl shadow-lg z-20 py-1 origin-top-right",style:{animation:"menu-appear 120ms ease-out"},role:"menu",children:[e.jsxs("button",{onClick:()=>k(d),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:e.jsx("path",{d:"M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25c.081-.286.235-.547.445-.758l8.61-8.61z"})}),"Edit"]}),e.jsxs("button",{onClick:()=>k(u),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:e.jsx("path",{d:"M3.5 13a.5.5 0 01-.5-.5V11h1v1h8v-1h1v1.5a.5.5 0 01-.5.5h-9zM8 2a.5.5 0 01.5.5v6.793l2.146-2.147a.5.5 0 01.708.708l-3 3a.5.5 0 01-.708 0l-3-3a.5.5 0 01.708-.708L7.5 9.293V2.5A.5.5 0 018 2z"})}),"Export JSON"]}),N&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"my-1 border-t border-cc-border/40",role:"separator"}),e.jsxs("button",{onClick:()=>k(h),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:[e.jsx("path",{d:"M4.715 6.542L3.343 7.914a3 3 0 104.243 4.243l1.828-1.829A3 3 0 008.586 5.5L8 6.086a1 1 0 00-.154.199 2 2 0 01.861 3.337L6.88 11.45a2 2 0 11-2.83-2.83l.793-.792a4.018 4.018 0 01-.128-1.287z"}),e.jsx("path",{d:"M11.285 9.458l1.372-1.372a3 3 0 10-4.243-4.243L6.586 5.671A3 3 0 007.414 10.5l.586-.586a1 1 0 00.154-.199 2 2 0 01-.861-3.337L9.12 4.55a2 2 0 112.83 2.83l-.793.792c.112.42.155.855.128 1.287z"})]}),i===t.id?"Copied!":"Copy Webhook URL"]}),e.jsxs("button",{onClick:()=>k(g),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:[e.jsx("path",{d:"M11.534 7h3.932a.25.25 0 01.192.41l-1.966 2.36a.25.25 0 01-.384 0l-1.966-2.36a.25.25 0 01.192-.41zm-7 2H.602a.25.25 0 01-.192-.41l1.966-2.36a.25.25 0 01.384 0l1.966 2.36a.25.25 0 01-.192.41z"}),e.jsx("path",{d:"M8 3a5 5 0 014.546 2.914.5.5 0 00.908-.418A6 6 0 002 8c0 .088.002.176.006.264l-.058-.024a.5.5 0 00-.394.908l2 1a.5.5 0 00.668-.17L5.59 7.864a.5.5 0 00-.274-.846l-.09-.016A4 4 0 018 3zm.002 10a4 4 0 002.49-4.002l.09.016a.5.5 0 00.274.846l-1.367 2.114a.5.5 0 01-.668.17l-2-1a.5.5 0 01.394-.908l.058.024A5.972 5.972 0 008.002 13a5 5 0 01-4.546-2.914.5.5 0 00-.908.418A6 6 0 008.002 13z"})]}),"Regenerate Secret"]})]}),e.jsx("div",{className:"my-1 border-t border-cc-border/40",role:"separator"}),e.jsxs("button",{onClick:()=>k(m),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:t.enabled?e.jsx("path",{d:"M5 3a5 5 0 000 10h6a5 5 0 000-10H5zm6 3a2 2 0 110 4 2 2 0 010-4z"}):e.jsx("path",{d:"M11 3a5 5 0 010 10H5A5 5 0 015 3h6zM5 6a2 2 0 100 4 2 2 0 000-4z"})}),t.enabled?"Disable":"Enable"]}),e.jsx("div",{className:"my-1 border-t border-cc-border/40",role:"separator"}),e.jsxs("button",{onClick:()=>k(a),className:"w-full px-3 py-2 text-xs text-left text-cc-error hover:bg-cc-error/10 transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:e.jsx("path",{d:"M5.5 5.5a.5.5 0 01.5.5v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm5 0a.5.5 0 01.5.5v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm-7-3A1.5 1.5 0 015 1h6a1.5 1.5 0 011.5 1.5H14a.5.5 0 010 1h-.554L12.2 14.118A1.5 1.5 0 0110.706 15H5.294a1.5 1.5 0 01-1.494-.882L2.554 3.5H2a.5.5 0 010-1h1.5z"})}),"Delete"]})]})]})}function Ke(t,i){if(!i)return"One-time";const d=t.trim().split(/\s+/);if(d.length!==5)return t;const[a,m,,,u]=d;if(t==="* * * * *")return"Every minute";if(m==="*"&&a.startsWith("*/")){const h=parseInt(a.slice(2),10);return h===1?"Every minute":`Every ${h} minutes`}if(a==="0"&&m==="*")return"Every hour";if(a==="0"&&m.startsWith("*/")){const h=parseInt(m.slice(2),10);return h===1?"Every hour":`Every ${h} hours`}if(a!=="*"&&m!=="*"&&!m.includes("/")&&!m.includes(",")){const h=parseInt(m,10),g=parseInt(a,10);if(!isNaN(h)&&!isNaN(g)){const j=h>=12?"PM":"AM",y=h===0?12:h>12?h-12:h,l=g.toString().padStart(2,"0"),N=`${y}:${l} ${j}`;if(u==="*")return`Daily at ${N}`;if(u==="1-5")return`Weekdays at ${N}`}}return t}function qe(t,i){var a,m;return`${i||window.location.origin}/api/agents/${encodeURIComponent(t.id)}/webhook/${((m=(a=t.triggers)==null?void 0:a.webhook)==null?void 0:m.secret)||""}`}function Ge({agent:t,publicUrl:i,onEdit:d,onDelete:a,onToggle:m,onRun:u,onExport:h,onCopyWebhook:g,onRegenerateSecret:j,copiedWebhook:y}){var k,b,C,p,S,M,z,w;const l=["Manual"];(b=(k=t.triggers)==null?void 0:k.webhook)!=null&&b.enabled&&l.push("Webhook"),(p=(C=t.triggers)==null?void 0:C.schedule)!=null&&p.enabled&&l.push(Ke(t.triggers.schedule.expression,t.triggers.schedule.recurring)),(M=(S=t.triggers)==null?void 0:S.linear)!=null&&M.enabled&&l.push("Linear Agent");const N=(w=(z=t.triggers)==null?void 0:z.linear)==null?void 0:w.enabled;return e.jsxs("div",{className:`
6
6
  group relative rounded-xl border bg-cc-card p-4
7
7
  transition-all duration-150
8
8
  ${t.enabled?"border-cc-border hover:border-cc-primary/30 hover:shadow-[0_2px_12px_rgba(217,119,87,0.06)]":"border-cc-border/60 opacity-75 hover:opacity-100"}
9
- `,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsx("div",{className:`${t.enabled?"text-cc-primary":"text-cc-muted"} transition-colors`,children:e.jsx(he,{icon:t.icon||"bot",className:"w-5 h-5"})}),e.jsx("span",{className:`absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full ring-2 ring-cc-card ${t.enabled?"bg-cc-success":"bg-cc-muted/50"}`,title:t.enabled?"Enabled":"Disabled","data-testid":"status-dot"})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg truncate",children:t.name}),e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] rounded-full bg-cc-hover text-cc-muted font-medium leading-none",children:t.backendType==="codex"?"Codex":"Claude"}),N&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded-full bg-violet-500/10 text-violet-400 font-medium leading-none",children:[e.jsx(ne,{className:"w-2.5 h-2.5"}),"Linear"]})]}),t.description&&e.jsx("p",{className:"text-xs text-cc-muted mt-0.5 truncate max-w-md",children:t.description})]})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsx("button",{onClick:u,className:"px-2.5 py-1 text-xs font-medium rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors cursor-pointer",title:"Run agent",children:"Run"}),e.jsx(Je,{agent:t,copiedWebhook:y,onEdit:d,onDelete:a,onToggle:m,onExport:h,onCopyWebhook:g,onRegenerateSecret:j})]})]}),e.jsxs("div",{className:"flex items-center justify-between mt-3 pt-3 border-t border-cc-border/40",children:[e.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:l.map((L,B)=>e.jsx("span",{className:"px-2 py-0.5 text-[10px] rounded-full bg-cc-hover text-cc-muted",children:L},B))}),e.jsxs("div",{className:"flex items-center gap-3 text-[10px] text-cc-muted",children:[t.totalRuns>0&&e.jsxs("span",{children:[t.totalRuns," run",t.totalRuns!==1?"s":""]}),t.lastRunAt&&e.jsxs("span",{children:["Last: ",Ee(t.lastRunAt)]}),t.nextRunAt&&e.jsxs("span",{children:["Next: ",Ee(t.nextRunAt)]})]})]})]})}const Re={name:"",description:"",icon:"",backendType:"claude",model:ae("claude"),permissionMode:Ne("claude"),cwd:"",prompt:"",envSlug:"",env:[],codexInternetAccess:!1,branch:"",createBranch:!1,useWorktree:!1,mcpServers:{},skills:[],allowedTools:[],webhookEnabled:!1,scheduleEnabled:!1,scheduleExpression:"0 8 * * *",scheduleRecurring:!0,restartMode:"terminate",linearEnabled:!1,linearOAuthConnectionId:""},Ze=[{label:"Every hour",value:"0 * * * *"},{label:"Every day at 8am",value:"0 8 * * *"},{label:"Every day at noon",value:"0 12 * * *"},{label:"Weekdays at 9am",value:"0 9 * * 1-5"},{label:"Every Monday at 8am",value:"0 8 * * 1"},{label:"Every 30 minutes",value:"*/30 * * * *"}];function je(t){let i=0;return Object.keys(t.mcpServers).length>0&&i++,t.skills.length>0&&i++,t.allowedTools.length>0&&i++,t.env.length>0&&i++,i}function Qe({form:t,setForm:i,editingId:d,publicUrl:a,error:m,saving:u,onSave:h,onCancel:g,linearOAuthConfigured:j}){const y=Oe(t.backendType),l=Ie(t.backendType),[N,k]=r.useState(!1),[b,C]=r.useState(()=>je(t)>0),[p,S]=r.useState(!1),[M,E]=r.useState(""),[w,L]=r.useState({type:"stdio",command:"",args:"",url:"",env:""}),[B,R]=r.useState([]),[U,V]=r.useState([]),[D,o]=r.useState([]),[I,H]=r.useState(!1),[O,le]=r.useState(""),[F,K]=r.useState(!1),[_,$]=r.useState(!1),[q,P]=r.useState(!1),[G,W]=r.useState(!!t.branch),[oe,Z]=r.useState(!1),Q=r.useRef(null),X=r.useRef(null),te=r.useRef(null),Y=r.useRef(null);r.useEffect(()=>{z.listSkills().then(R).catch(()=>{}),z.listEnvs().then(V).catch(()=>{})},[]),r.useEffect(()=>{t.linearEnabled&&(H(!0),z.listLinearOAuthConnections().then(({connections:s})=>{o(s),s.length===1&&!t.linearOAuthConnectionId&&v("linearOAuthConnectionId",s[0].id)}).catch(()=>{}).finally(()=>H(!1)))},[t.linearEnabled]);function v(s,n){i(A=>({...A,[s]:n}))}function ie(s){i(n=>({...n,backendType:s,model:ae(s),permissionMode:Ne(s)}))}function pe(){i(s=>({...s,env:[...s.env,{key:"",value:""}]}))}function de(s,n,A){i(T=>{const ee=[...T.env];return ee[s]={...ee[s],[n]:A},{...T,env:ee}})}function xe(s){i(n=>({...n,env:n.env.filter((A,T)=>T!==s)}))}function me(){if(!M.trim())return;const s={type:w.type};if(w.type==="stdio"?(s.command=w.command,s.args=w.args?w.args.split(" ").filter(Boolean):void 0):s.url=w.url,w.env.trim())try{s.env=JSON.parse(w.env)}catch{}i(n=>({...n,mcpServers:{...n.mcpServers,[M.trim()]:s}})),E(""),L({type:"stdio",command:"",args:"",url:"",env:""}),S(!1)}function ge(s){i(n=>{const A={...n.mcpServers};return delete A[s],{...n,mcpServers:A}})}function ue(s){i(n=>({...n,skills:n.skills.includes(s)?n.skills.filter(A=>A!==s):[...n.skills,s]}))}function be(s){if(s.key==="Enter"&&O.trim()){s.preventDefault();const n=O.trim();t.allowedTools.includes(n)||v("allowedTools",[...t.allowedTools,n]),le("")}}function fe(s){v("allowedTools",t.allowedTools.filter(n=>n!==s))}r.useEffect(()=>{function s(n){X.current&&!X.current.contains(n.target)&&K(!1),te.current&&!te.current.contains(n.target)&&$(!1),Y.current&&!Y.current.contains(n.target)&&P(!1),Q.current&&!Q.current.contains(n.target)&&Z(!1)}return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[]);const J=y.find(s=>s.value===t.model)||y[0],se=l.find(s=>s.value===t.permissionMode)||l[0],ce=U.find(s=>s.slug===t.envSlug),ve=t.cwd?t.cwd.split("/").pop()||t.cwd:"temp",re=a||(typeof window<"u"?window.location.origin:""),c="flex items-center gap-1.5 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer",x=`${c} text-cc-muted hover:text-cc-fg hover:bg-cc-hover`,f=`${c} text-cc-primary bg-cc-primary/10 hover:bg-cc-primary/15`;return e.jsx("div",{className:"h-full overflow-y-auto bg-cc-bg",children:e.jsxs("div",{className:"max-w-3xl mx-auto p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:g,className:"p-1.5 rounded-lg text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4",children:e.jsx("path",{d:"M11 2L5 8l6 6",stroke:"currentColor",strokeWidth:"2",fill:"none"})})}),e.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:d?"Edit Agent":"New Agent"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:g,className:"px-3 py-1.5 text-xs rounded-lg border border-cc-border text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{onClick:h,disabled:u||!t.name.trim()||!t.prompt.trim(),className:"px-3 py-1.5 text-xs rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors disabled:opacity-50 cursor-pointer disabled:cursor-not-allowed",children:u?"Saving...":d?"Save":"Create"})]})]}),m&&e.jsx("div",{className:"mb-4 px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/30 text-cc-error text-xs",children:m}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex gap-3 items-start",children:[e.jsxs("div",{ref:Q,className:"relative flex-shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>Z(!oe),className:"w-10 h-10 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg flex items-center justify-center hover:border-cc-primary/50 focus:outline-none focus:ring-1 focus:ring-cc-primary transition-colors","aria-label":"Choose agent icon",children:e.jsx(he,{icon:t.icon||"bot",className:"w-5 h-5"})}),oe&&e.jsx("div",{className:"absolute top-12 left-0 z-50 bg-cc-card border border-cc-border rounded-lg shadow-lg p-2 grid grid-cols-6 gap-1 w-[216px]",children:Ye.map(s=>e.jsx("button",{type:"button",onClick:()=>{v("icon",s),Z(!1)},className:`w-8 h-8 rounded-md flex items-center justify-center transition-colors ${t.icon===s?"bg-cc-primary/20 ring-1 ring-cc-primary":"hover:bg-cc-hover"}`,title:s,children:e.jsx(he,{icon:s,className:"w-4 h-4 text-cc-fg"})},s))})]}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("input",{value:t.name,onChange:s=>v("name",s.target.value),placeholder:"Agent name *",className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsx("input",{value:t.description,onChange:s=>v("description",s.target.value),placeholder:"Short description (optional)",className:"w-full px-3 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs focus:outline-none focus:ring-1 focus:ring-cc-primary"})]})]}),e.jsxs("div",{children:[e.jsx("textarea",{value:t.prompt,onChange:s=>v("prompt",s.target.value),placeholder:`System prompt *
9
+ `,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsx("div",{className:`${t.enabled?"text-cc-primary":"text-cc-muted"} transition-colors`,children:e.jsx(he,{icon:t.icon||"bot",className:"w-5 h-5"})}),e.jsx("span",{className:`absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full ring-2 ring-cc-card ${t.enabled?"bg-cc-success":"bg-cc-muted/50"}`,title:t.enabled?"Enabled":"Disabled","data-testid":"status-dot"})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg truncate",children:t.name}),e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] rounded-full bg-cc-hover text-cc-muted font-medium leading-none",children:t.backendType==="codex"?"Codex":"Claude"}),N&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded-full bg-violet-500/10 text-violet-400 font-medium leading-none",children:[e.jsx(ne,{className:"w-2.5 h-2.5"}),"Linear"]})]}),t.description&&e.jsx("p",{className:"text-xs text-cc-muted mt-0.5 truncate max-w-md",children:t.description})]})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsx("button",{onClick:u,className:"px-2.5 py-1 text-xs font-medium rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors cursor-pointer",title:"Run agent",children:"Run"}),e.jsx(Je,{agent:t,copiedWebhook:y,onEdit:d,onDelete:a,onToggle:m,onExport:h,onCopyWebhook:g,onRegenerateSecret:j})]})]}),e.jsxs("div",{className:"flex items-center justify-between mt-3 pt-3 border-t border-cc-border/40",children:[e.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:l.map((L,B)=>e.jsx("span",{className:"px-2 py-0.5 text-[10px] rounded-full bg-cc-hover text-cc-muted",children:L},B))}),e.jsxs("div",{className:"flex items-center gap-3 text-[10px] text-cc-muted",children:[t.totalRuns>0&&e.jsxs("span",{children:[t.totalRuns," run",t.totalRuns!==1?"s":""]}),t.lastRunAt&&e.jsxs("span",{children:["Last: ",ze(t.lastRunAt)]}),t.nextRunAt&&e.jsxs("span",{children:["Next: ",ze(t.nextRunAt)]})]})]})]})}const Re={name:"",description:"",icon:"",backendType:"claude",model:ae("claude"),permissionMode:Ne("claude"),cwd:"",prompt:"",envSlug:"",env:[],codexInternetAccess:!1,branch:"",createBranch:!1,useWorktree:!1,mcpServers:{},skills:[],allowedTools:[],webhookEnabled:!1,scheduleEnabled:!1,scheduleExpression:"0 8 * * *",scheduleRecurring:!0,restartMode:"terminate",linearEnabled:!1,linearOAuthConnectionId:""},Ze=[{label:"Every hour",value:"0 * * * *"},{label:"Every day at 8am",value:"0 8 * * *"},{label:"Every day at noon",value:"0 12 * * *"},{label:"Weekdays at 9am",value:"0 9 * * 1-5"},{label:"Every Monday at 8am",value:"0 8 * * 1"},{label:"Every 30 minutes",value:"*/30 * * * *"}];function je(t){let i=0;return Object.keys(t.mcpServers).length>0&&i++,t.skills.length>0&&i++,t.allowedTools.length>0&&i++,t.env.length>0&&i++,i}function Qe({form:t,setForm:i,editingId:d,publicUrl:a,error:m,saving:u,onSave:h,onCancel:g,linearOAuthConfigured:j}){const y=Ie(t.backendType),l=Oe(t.backendType),[N,k]=r.useState(!1),[b,C]=r.useState(()=>je(t)>0),[p,S]=r.useState(!1),[M,z]=r.useState(""),[w,L]=r.useState({type:"stdio",command:"",args:"",url:"",env:""}),[B,R]=r.useState([]),[U,V]=r.useState([]),[D,o]=r.useState([]),[O,H]=r.useState(!1),[I,le]=r.useState(""),[F,K]=r.useState(!1),[_,$]=r.useState(!1),[q,P]=r.useState(!1),[G,W]=r.useState(!!t.branch),[oe,Z]=r.useState(!1),Q=r.useRef(null),X=r.useRef(null),te=r.useRef(null),Y=r.useRef(null);r.useEffect(()=>{E.listSkills().then(R).catch(()=>{}),E.listEnvs().then(V).catch(()=>{})},[]),r.useEffect(()=>{t.linearEnabled&&(H(!0),E.listLinearOAuthConnections().then(({connections:s})=>{o(s),s.length===1&&!t.linearOAuthConnectionId&&v("linearOAuthConnectionId",s[0].id)}).catch(()=>{}).finally(()=>H(!1)))},[t.linearEnabled]);function v(s,n){i(A=>({...A,[s]:n}))}function ie(s){i(n=>({...n,backendType:s,model:ae(s),permissionMode:Ne(s)}))}function pe(){i(s=>({...s,env:[...s.env,{key:"",value:""}]}))}function de(s,n,A){i(T=>{const ee=[...T.env];return ee[s]={...ee[s],[n]:A},{...T,env:ee}})}function xe(s){i(n=>({...n,env:n.env.filter((A,T)=>T!==s)}))}function me(){if(!M.trim())return;const s={type:w.type};if(w.type==="stdio"?(s.command=w.command,s.args=w.args?w.args.split(" ").filter(Boolean):void 0):s.url=w.url,w.env.trim())try{s.env=JSON.parse(w.env)}catch{}i(n=>({...n,mcpServers:{...n.mcpServers,[M.trim()]:s}})),z(""),L({type:"stdio",command:"",args:"",url:"",env:""}),S(!1)}function ge(s){i(n=>{const A={...n.mcpServers};return delete A[s],{...n,mcpServers:A}})}function ue(s){i(n=>({...n,skills:n.skills.includes(s)?n.skills.filter(A=>A!==s):[...n.skills,s]}))}function be(s){if(s.key==="Enter"&&I.trim()){s.preventDefault();const n=I.trim();t.allowedTools.includes(n)||v("allowedTools",[...t.allowedTools,n]),le("")}}function fe(s){v("allowedTools",t.allowedTools.filter(n=>n!==s))}r.useEffect(()=>{function s(n){X.current&&!X.current.contains(n.target)&&K(!1),te.current&&!te.current.contains(n.target)&&$(!1),Y.current&&!Y.current.contains(n.target)&&P(!1),Q.current&&!Q.current.contains(n.target)&&Z(!1)}return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[]);const J=y.find(s=>s.value===t.model)||y[0],se=l.find(s=>s.value===t.permissionMode)||l[0],ce=U.find(s=>s.slug===t.envSlug),ve=t.cwd?t.cwd.split("/").pop()||t.cwd:"temp",re=a||(typeof window<"u"?window.location.origin:""),c="flex items-center gap-1.5 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer",x=`${c} text-cc-muted hover:text-cc-fg hover:bg-cc-hover`,f=`${c} text-cc-primary bg-cc-primary/10 hover:bg-cc-primary/15`;return e.jsx("div",{className:"h-full overflow-y-auto bg-cc-bg",children:e.jsxs("div",{className:"max-w-3xl mx-auto p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:g,className:"p-1.5 rounded-lg text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4",children:e.jsx("path",{d:"M11 2L5 8l6 6",stroke:"currentColor",strokeWidth:"2",fill:"none"})})}),e.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:d?"Edit Agent":"New Agent"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:g,className:"px-3 py-1.5 text-xs rounded-lg border border-cc-border text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{onClick:h,disabled:u||!t.name.trim()||!t.prompt.trim(),className:"px-3 py-1.5 text-xs rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors disabled:opacity-50 cursor-pointer disabled:cursor-not-allowed",children:u?"Saving...":d?"Save":"Create"})]})]}),m&&e.jsx("div",{className:"mb-4 px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/30 text-cc-error text-xs",children:m}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex gap-3 items-start",children:[e.jsxs("div",{ref:Q,className:"relative flex-shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>Z(!oe),className:"w-10 h-10 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg flex items-center justify-center hover:border-cc-primary/50 focus:outline-none focus:ring-1 focus:ring-cc-primary transition-colors","aria-label":"Choose agent icon",children:e.jsx(he,{icon:t.icon||"bot",className:"w-5 h-5"})}),oe&&e.jsx("div",{className:"absolute top-12 left-0 z-50 bg-cc-card border border-cc-border rounded-lg shadow-lg p-2 grid grid-cols-6 gap-1 w-[216px]",children:Ye.map(s=>e.jsx("button",{type:"button",onClick:()=>{v("icon",s),Z(!1)},className:`w-8 h-8 rounded-md flex items-center justify-center transition-colors ${t.icon===s?"bg-cc-primary/20 ring-1 ring-cc-primary":"hover:bg-cc-hover"}`,title:s,children:e.jsx(he,{icon:s,className:"w-4 h-4 text-cc-fg"})},s))})]}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("input",{value:t.name,onChange:s=>v("name",s.target.value),placeholder:"Agent name *",className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsx("input",{value:t.description,onChange:s=>v("description",s.target.value),placeholder:"Short description (optional)",className:"w-full px-3 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs focus:outline-none focus:ring-1 focus:ring-cc-primary"})]})]}),e.jsxs("div",{children:[e.jsx("textarea",{value:t.prompt,onChange:s=>v("prompt",s.target.value),placeholder:`System prompt *
10
10
  Write the agent's instructions here.
11
- Use {{input}} as a placeholder for trigger-provided input.`,className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm resize-none h-40 font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsxs("p",{className:"text-[10px] text-cc-muted mt-1",children:["Use ",e.jsx("code",{className:"px-1 py-0.5 rounded bg-cc-hover",children:"{{input}}"})," where trigger input should be inserted."]})]}),e.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 flex-wrap","data-testid":"controls-row",children:[e.jsxs("div",{className:"flex items-center bg-cc-hover/50 rounded-lg p-0.5",children:[e.jsx("button",{onClick:()=>ie("claude"),className:`flex items-center gap-1 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer ${t.backendType==="claude"?"bg-cc-card text-cc-fg font-medium shadow-sm":"text-cc-muted hover:text-cc-fg"}`,children:"Claude"}),e.jsx("button",{onClick:()=>ie("codex"),className:`flex items-center gap-1 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer ${t.backendType==="codex"?"bg-cc-card text-cc-fg font-medium shadow-sm":"text-cc-muted hover:text-cc-fg"}`,children:"Codex"})]}),e.jsxs("div",{className:"relative",ref:X,children:[e.jsxs("button",{onClick:()=>{K(!F),$(!1),P(!1)},"aria-expanded":F,className:x,children:[e.jsx("span",{children:J==null?void 0:J.icon}),e.jsx("span",{children:J==null?void 0:J.label}),e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50",children:e.jsx("path",{d:"M4 6l4 4 4-4"})})]}),F&&e.jsx("div",{className:"absolute left-0 top-full mt-1 w-48 bg-cc-card border border-cc-border rounded-[10px] shadow-lg z-10 py-1",children:y.map(s=>e.jsxs("button",{onClick:()=>{v("model",s.value),K(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer flex items-center gap-2 ${s.value===t.model?"text-cc-primary font-medium":"text-cc-fg"}`,children:[e.jsx("span",{children:s.icon}),s.label]},s.value))})]}),e.jsxs("div",{className:"relative",ref:te,children:[e.jsxs("button",{onClick:()=>{$(!_),K(!1),P(!1)},"aria-expanded":_,className:x,children:[e.jsx("span",{children:se==null?void 0:se.label}),e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50",children:e.jsx("path",{d:"M4 6l4 4 4-4"})})]}),_&&e.jsx("div",{className:"absolute left-0 top-full mt-1 w-48 bg-cc-card border border-cc-border rounded-[10px] shadow-lg z-10 py-1",children:l.map(s=>e.jsx("button",{onClick:()=>{v("permissionMode",s.value),$(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer flex items-center gap-2 ${s.value===t.permissionMode?"text-cc-primary font-medium":"text-cc-fg"}`,children:s.label},s.value))})]}),e.jsxs("button",{onClick:()=>k(!0),className:t.cwd?f:x,title:t.cwd||"Temporary directory",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.879a1.5 1.5 0 011.06.44l1.122 1.12A1.5 1.5 0 009.62 4H13.5A1.5 1.5 0 0115 5.5v7a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})}),e.jsx("span",{className:"max-w-[120px] sm:max-w-[200px] truncate font-mono-code",children:ve}),t.cwd&&e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50 hover:opacity-100",onClick:s=>{s.stopPropagation(),v("cwd","")},children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})]}),t.cwd&&(G?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted opacity-60",children:e.jsx("path",{d:"M9.5 3.25a2.25 2.25 0 113 2.122V6.5A2.5 2.5 0 0110 9H6a1 1 0 00-1 1v1.128a2.251 2.251 0 11-1.5 0V5.372a2.25 2.25 0 111.5 0v1.836A2.492 2.492 0 016 7h4a1 1 0 001-1v-.878A2.25 2.25 0 019.5 3.25z"})}),e.jsx("input",{value:t.branch,onChange:s=>v("branch",s.target.value),placeholder:"branch name",className:"w-28 px-1.5 py-1 text-xs rounded-md bg-cc-input-bg border border-cc-border text-cc-fg font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary",autoFocus:!0,onBlur:()=>{t.branch||W(!1)}}),t.branch&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-center gap-1 text-[10px] text-cc-muted cursor-pointer",title:"Create branch if it doesn't exist",children:[e.jsx("input",{type:"checkbox",checked:t.createBranch,onChange:s=>v("createBranch",s.target.checked),className:"rounded w-3 h-3"}),"create"]}),e.jsxs("label",{className:"flex items-center gap-1 text-[10px] text-cc-muted cursor-pointer",title:"Use git worktree",children:[e.jsx("input",{type:"checkbox",checked:t.useWorktree,onChange:s=>v("useWorktree",s.target.checked),className:"rounded w-3 h-3"}),"worktree"]})]})]}):e.jsxs("button",{onClick:()=>W(!0),className:x,title:"Set a git branch",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M9.5 3.25a2.25 2.25 0 113 2.122V6.5A2.5 2.5 0 0110 9H6a1 1 0 00-1 1v1.128a2.251 2.251 0 11-1.5 0V5.372a2.25 2.25 0 111.5 0v1.836A2.492 2.492 0 016 7h4a1 1 0 001-1v-.878A2.25 2.25 0 019.5 3.25z"})}),e.jsx("span",{children:"branch"})]})),e.jsxs("div",{className:"relative",ref:Y,children:[e.jsxs("button",{onClick:()=>{P(!q),K(!1),$(!1)},"aria-expanded":q,className:t.envSlug?f:x,children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M8 1a2 2 0 012 2v4H6V3a2 2 0 012-2zm3.5 6V3a3.5 3.5 0 10-7 0v4A1.5 1.5 0 003 8.5v5A1.5 1.5 0 004.5 15h7a1.5 1.5 0 001.5-1.5v-5A1.5 1.5 0 0011.5 7z"})}),e.jsx("span",{children:(ce==null?void 0:ce.name)||"None"}),e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50",children:e.jsx("path",{d:"M4 6l4 4 4-4"})})]}),q&&e.jsxs("div",{className:"absolute left-0 top-full mt-1 w-48 bg-cc-card border border-cc-border rounded-[10px] shadow-lg z-10 py-1",children:[e.jsx("button",{onClick:()=>{v("envSlug",""),P(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer ${t.envSlug?"text-cc-fg":"text-cc-primary font-medium"}`,children:"None"}),U.map(s=>e.jsx("button",{onClick:()=>{v("envSlug",s.slug),P(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer ${t.envSlug===s.slug?"text-cc-primary font-medium":"text-cc-fg"}`,children:s.name},s.slug))]})]}),t.backendType==="codex"&&e.jsxs("button",{onClick:()=>v("codexInternetAccess",!t.codexInternetAccess),className:t.codexInternetAccess?f:x,title:"Allow internet access (Codex)",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M0 8a8 8 0 1116 0A8 8 0 010 8zm7.5-6.923c-.67.204-1.335.82-1.887 1.855A7.97 7.97 0 005.145 4H7.5V1.077zM4.09 4a9.267 9.267 0 01.64-1.539 6.7 6.7 0 01.597-.933A6.504 6.504 0 002.536 4H4.09zm-.582 3.5c.03-.877.138-1.718.312-2.5H1.674a6.51 6.51 0 00-.656 2.5h2.49zM4.847 5a12.5 12.5 0 00-.338 2.5H7.5V5H4.847zM8.5 5v2.5h2.99a12.495 12.495 0 00-.337-2.5H8.5zM4.51 8.5a12.5 12.5 0 00.337 2.5H7.5V8.5H4.51zm3.99 0V11h2.653c.187-.765.306-1.608.338-2.5H8.5zM5.145 12c.138.386.295.744.468 1.068.552 1.035 1.218 1.65 1.887 1.855V12H5.145zm.182 2.472a6.696 6.696 0 01-.597-.933A9.268 9.268 0 014.09 12H2.536a6.504 6.504 0 002.79 2.472zM3.82 11a13.652 13.652 0 01-.312-2.5h-2.49c.062.89.291 1.733.656 2.5H3.82zm6.853 3.472A6.504 6.504 0 0013.464 12H11.91a9.27 9.27 0 01-.64 1.539 6.688 6.688 0 01-.597.933zM8.5 14.923c.67-.204 1.335-.82 1.887-1.855.173-.324.33-.682.468-1.068H8.5v2.923zm3.68-3.923c.174-.782.282-1.623.312-2.5H15c-.094.89-.323 1.733-.656 2.5h-2.163zM12.18 8.5c-.03-.877-.138-1.718-.312-2.5h2.158c.365.767.594 1.61.656 2.5H12.18zm-1.508-4.5h2.792a6.504 6.504 0 00-2.79-2.472c.218.284.418.598.597.933.226.423.424.896.59 1.539z"})}),e.jsx("span",{children:"Internet"})]})]}),N&&e.jsx(ye,{initialPath:t.cwd||"",onSelect:s=>{v("cwd",s),k(!1)},onClose:()=>k(!1)}),e.jsxs("section",{children:[e.jsx("h2",{className:"text-xs text-cc-muted mb-2",children:"Triggers"}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("button",{onClick:()=>v("webhookEnabled",!t.webhookEnabled),className:t.webhookEnabled?f:x,children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M8.543 2.232a.75.75 0 00-1.085 0l-5.25 5.5A.75.75 0 002.75 9H4v4a1 1 0 001 1h6a1 1 0 001-1V9h1.25a.75.75 0 00.543-1.268l-5.25-5.5z"})}),"Webhook"]}),e.jsxs("button",{onClick:()=>v("scheduleEnabled",!t.scheduleEnabled),className:t.scheduleEnabled?f:x,children:[e.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:[e.jsx("path",{d:"M8 3.5a.5.5 0 00-1 0V8a.5.5 0 00.252.434l3.5 2a.5.5 0 00.496-.868L8 7.71V3.5z"}),e.jsx("path",{d:"M8 16A8 8 0 108 0a8 8 0 000 16zm7-8A7 7 0 111 8a7 7 0 0114 0z"})]}),"Schedule"]}),j&&e.jsxs("button",{onClick:()=>v("linearEnabled",!t.linearEnabled),className:t.linearEnabled?f:x,children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M3 1a1 1 0 00-1 1v12a1 1 0 001 1h10a1 1 0 001-1V2a1 1 0 00-1-1H3zm1 2h8v2H4V3zm0 4h5v2H4V7zm0 4h8v2H4v-2z"})}),"Linear Agent"]})]}),t.webhookEnabled&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsxs("p",{className:"text-[10px] text-cc-muted",children:["A unique URL will be generated after saving. POST to it with ",e.jsx("code",{className:"px-1 py-0.5 rounded bg-cc-hover",children:'{"input": "..."}'}),"."]}),re&&e.jsxs("p",{className:"text-[10px] text-cc-muted",children:["Base URL: ",e.jsx("span",{className:"font-mono-code",children:re})]})]}),t.linearEnabled&&e.jsx("div",{className:"mt-3 space-y-2","data-testid":"linear-connection-picker",children:I?e.jsx("p",{className:"text-[10px] text-cc-muted",children:"Loading connections..."}):D.length===0?e.jsxs("p",{className:"text-[10px] text-cc-muted",children:["No OAuth connections found."," ",e.jsx("a",{href:"#/agents?setup=linear",className:"text-cc-primary underline",children:"Set up a Linear OAuth app"})," ","first."]}):e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"block text-[10px] text-cc-muted mb-1",children:"OAuth Connection"}),e.jsx("div",{className:"space-y-1",children:D.map(s=>e.jsxs("button",{type:"button",onClick:()=>v("linearOAuthConnectionId",s.id),className:`w-full flex items-center justify-between px-3 py-2 rounded-lg border text-xs transition-colors cursor-pointer ${t.linearOAuthConnectionId===s.id?"border-cc-primary bg-cc-primary/10 text-cc-fg":"border-cc-border bg-cc-input-bg text-cc-muted hover:text-cc-fg hover:border-cc-primary/50"}`,children:[e.jsx("span",{className:"font-medium",children:s.name}),e.jsx("span",{className:`px-1.5 py-0.5 text-[10px] rounded-full ${s.status==="connected"?"bg-emerald-500/15 text-emerald-400":"bg-cc-muted/15 text-cc-muted"}`,children:s.status==="connected"?"Connected":"Not connected"})]},s.id))}),e.jsxs("p",{className:"text-[10px] text-cc-muted",children:["This agent will respond to @mentions in Linear."," ",e.jsx("a",{href:"#/agents?setup=linear",className:"text-cc-primary underline",children:"Manage connections"})]})]})}),t.scheduleEnabled&&e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-cc-muted cursor-pointer",children:[e.jsx("input",{type:"radio",checked:t.scheduleRecurring,onChange:()=>v("scheduleRecurring",!0)}),"Recurring"]}),e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-cc-muted cursor-pointer",children:[e.jsx("input",{type:"radio",checked:!t.scheduleRecurring,onChange:()=>v("scheduleRecurring",!1)}),"One-time"]})]}),t.scheduleRecurring?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex flex-wrap gap-1",children:Ze.map(s=>e.jsx("button",{onClick:()=>v("scheduleExpression",s.value),className:`px-2 py-1 text-[10px] rounded-lg border transition-colors cursor-pointer ${t.scheduleExpression===s.value?"border-cc-primary text-cc-primary":"border-cc-border text-cc-muted hover:text-cc-fg"}`,children:s.label},s.value))}),e.jsx("input",{value:t.scheduleExpression,onChange:s=>v("scheduleExpression",s.target.value),placeholder:"Cron expression (e.g. 0 8 * * *)",className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"})]}):e.jsx("input",{type:"datetime-local",value:t.scheduleExpression,onChange:s=>v("scheduleExpression",s.target.value),className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsxs("div",{className:"pt-1",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-cc-muted mb-1",children:"If a previous run is still open"}),e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx("button",{type:"button",onClick:()=>v("restartMode","terminate"),className:`px-2 py-1 text-[10px] rounded-lg border transition-colors cursor-pointer ${t.restartMode==="terminate"?"border-cc-primary text-cc-primary":"border-cc-border text-cc-muted hover:text-cc-fg"}`,children:"Terminate it & start fresh"}),e.jsx("button",{type:"button",onClick:()=>v("restartMode","skip"),className:`px-2 py-1 text-[10px] rounded-lg border transition-colors cursor-pointer ${t.restartMode==="skip"?"border-cc-primary text-cc-primary":"border-cc-border text-cc-muted hover:text-cc-fg"}`,children:"Skip this run"})]}),e.jsx("p",{className:"mt-1 text-[10px] text-cc-muted",children:"Agent sessions stay open until archived. “Terminate” closes the leftover session so the next scheduled run can start; “Skip” keeps it and waits."})]})]})]}),e.jsxs("section",{children:[e.jsxs("button",{onClick:()=>C(!b),className:"flex items-center gap-2 text-xs text-cc-muted cursor-pointer hover:text-cc-fg transition-colors w-full",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:`w-3 h-3 transition-transform ${b?"rotate-90":""}`,children:e.jsx("path",{d:"M6 3l5 5-5 5V3z"})}),"Advanced",je(t)>0&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] rounded-full bg-cc-primary/15 text-cc-primary font-normal",children:je(t)})]}),b&&e.jsxs("div",{className:"mt-4 space-y-6 pl-5 border-l-2 border-cc-border/30",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted",children:"MCP Servers"}),e.jsx("button",{onClick:()=>S(!p),className:"text-[10px] text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:p?"Cancel":"+ Add Server"})]}),Object.keys(t.mcpServers).length===0&&!p&&e.jsx("p",{className:"text-[10px] text-cc-muted",children:"No MCP servers configured."}),Object.entries(t.mcpServers).map(([s,n])=>e.jsxs("div",{className:"flex items-center justify-between py-1.5 px-2 rounded-lg bg-cc-hover/50 mb-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-cc-fg font-mono-code",children:s}),e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] rounded bg-cc-border text-cc-muted",children:n.type})]}),e.jsx("button",{onClick:()=>ge(s),className:"text-cc-muted hover:text-cc-error transition-colors cursor-pointer p-0.5",title:"Remove server",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]},s)),p&&e.jsxs("div",{className:"rounded-lg border border-cc-border p-3 mt-2 space-y-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] text-cc-muted mb-0.5",children:"Server Name"}),e.jsx("input",{value:M,onChange:s=>E(s.target.value),placeholder:"e.g., my-server",className:"w-full px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] text-cc-muted mb-0.5",children:"Type"}),e.jsx("div",{className:"flex rounded-lg border border-cc-border overflow-hidden",children:["stdio","sse","http"].map(s=>e.jsx("button",{onClick:()=>L(n=>({...n,type:s})),className:`flex-1 px-2 py-1 text-[10px] transition-colors cursor-pointer ${w.type===s?"bg-cc-primary text-white":"bg-cc-input-bg text-cc-muted hover:text-cc-fg"}`,children:s},s))})]}),w.type==="stdio"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] text-cc-muted mb-0.5",children:"Command"}),e.jsx("input",{value:w.command,onChange:s=>L(n=>({...n,command:s.target.value})),placeholder:"e.g., npx -y @some/mcp-server",className:"w-full px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] text-cc-muted mb-0.5",children:"Args (space-separated)"}),e.jsx("input",{value:w.args,onChange:s=>L(n=>({...n,args:s.target.value})),placeholder:"--port 3000",className:"w-full px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"})]})]}):e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] text-cc-muted mb-0.5",children:"URL"}),e.jsx("input",{value:w.url,onChange:s=>L(n=>({...n,url:s.target.value})),placeholder:"https://example.com/mcp",className:"w-full px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"})]}),e.jsx("button",{onClick:me,disabled:!M.trim(),className:"px-3 py-1.5 text-xs rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors disabled:opacity-50 cursor-pointer disabled:cursor-not-allowed",children:"Add Server"})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted mb-2",children:"Skills"}),B.length===0?e.jsx("p",{className:"text-[10px] text-cc-muted",children:"No skills found in ~/.claude/skills/"}):e.jsx("div",{className:"space-y-1.5",children:B.map(s=>e.jsxs("label",{className:"flex items-start gap-2 text-sm text-cc-fg cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:t.skills.includes(s.slug),onChange:()=>ue(s.slug),className:"rounded mt-0.5"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs",children:s.name}),s.description&&e.jsx("p",{className:"text-[10px] text-cc-muted",children:s.description})]})]},s.slug))})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted mb-2",children:"Allowed Tools"}),e.jsxs("div",{className:"space-y-2",children:[t.allowedTools.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.allowedTools.map(s=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-xs font-mono-code rounded-lg bg-cc-hover text-cc-fg",children:[s,e.jsx("button",{onClick:()=>fe(s),className:"text-cc-muted hover:text-cc-error transition-colors cursor-pointer",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-2.5 h-2.5",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]},s))}),e.jsx("input",{value:O,onChange:s=>le(s.target.value),onKeyDown:be,placeholder:"Type tool name and press Enter",className:"w-full px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsx("p",{className:"text-[10px] text-cc-muted",children:"Leave empty to allow all tools."})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted",children:"Environment Variables"}),e.jsx("button",{onClick:pe,className:"text-[10px] text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"+ Add Variable"})]}),t.env.length===0?e.jsx("p",{className:"text-[10px] text-cc-muted",children:"No extra variables set."}):e.jsx("div",{className:"space-y-1.5",children:t.env.map((s,n)=>e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("input",{value:s.key,onChange:A=>de(n,"key",A.target.value),placeholder:"KEY",className:"w-1/3 px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsx("input",{value:s.value,onChange:A=>de(n,"value",A.target.value),placeholder:"value",className:"flex-1 px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsx("button",{onClick:()=>xe(n),className:"text-cc-muted hover:text-cc-error transition-colors cursor-pointer p-1",title:"Remove variable",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]},n))})]})]})]})]})]})})}function Xe({form:t,setForm:i,editingId:d,error:a,saving:m,onSave:u,onCancel:h,onOpenGenericEditor:g}){const[j,y]=r.useState(!1),[l,N]=r.useState(!1),[k,b]=r.useState(!1),C=r.useRef(null),p=r.useRef(null);function S(o,I){i(H=>({...H,[o]:I}))}function M(o){i(I=>({...I,backendType:o,model:ae(o),permissionMode:Ne(o)}))}r.useEffect(()=>{function o(I){C.current&&!C.current.contains(I.target)&&N(!1),p.current&&!p.current.contains(I.target)&&b(!1)}return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[]);const E=Oe(t.backendType),w=Ie(t.backendType),L=E.find(o=>o.value===t.model)||E[0],B=w.find(o=>o.value===t.permissionMode)||w[0],R=t.cwd?t.cwd.split("/").pop()||t.cwd:"temp",U="flex items-center gap-1.5 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer",V=`${U} text-cc-muted hover:text-cc-fg hover:bg-cc-hover`,D=`${U} text-cc-primary bg-cc-primary/10 hover:bg-cc-primary/15`;return e.jsx("div",{className:"h-full overflow-y-auto bg-cc-bg",children:e.jsxs("div",{className:"max-w-3xl mx-auto p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:h,className:"p-1.5 rounded-lg text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4",children:e.jsx("path",{d:"M11 2L5 8l6 6",stroke:"currentColor",strokeWidth:"2",fill:"none"})})}),e.jsx(ne,{className:"w-5 h-5 text-cc-fg"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Edit Linear Agent"}),e.jsxs("p",{className:"text-[10px] text-cc-muted font-mono-code",children:["ID: ",d]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:h,className:"px-3 py-1.5 text-xs rounded-lg border border-cc-border text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{onClick:u,disabled:m||!t.name.trim()||!t.prompt.trim(),className:"px-3 py-1.5 text-xs rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors disabled:opacity-50 cursor-pointer disabled:cursor-not-allowed",children:m?"Saving...":"Save"})]})]}),a&&e.jsx("div",{className:"mb-4 px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/30 text-cc-error text-xs",children:a}),e.jsxs("div",{className:"space-y-5",children:[e.jsx("input",{value:t.name,onChange:o=>S("name",o.target.value),placeholder:"Agent name *",className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsx("input",{value:t.description,onChange:o=>S("description",o.target.value),placeholder:"Short description (optional)",className:"w-full px-3 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsxs("div",{children:[e.jsx("textarea",{value:t.prompt,onChange:o=>S("prompt",o.target.value),placeholder:`System prompt *
11
+ Use {{input}} as a placeholder for trigger-provided input.`,className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm resize-none h-40 font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsxs("p",{className:"text-[10px] text-cc-muted mt-1",children:["Use ",e.jsx("code",{className:"px-1 py-0.5 rounded bg-cc-hover",children:"{{input}}"})," where trigger input should be inserted."]})]}),e.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 flex-wrap","data-testid":"controls-row",children:[e.jsxs("div",{className:"flex items-center bg-cc-hover/50 rounded-lg p-0.5",children:[e.jsx("button",{onClick:()=>ie("claude"),className:`flex items-center gap-1 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer ${t.backendType==="claude"?"bg-cc-card text-cc-fg font-medium shadow-sm":"text-cc-muted hover:text-cc-fg"}`,children:"Claude"}),e.jsx("button",{onClick:()=>ie("codex"),className:`flex items-center gap-1 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer ${t.backendType==="codex"?"bg-cc-card text-cc-fg font-medium shadow-sm":"text-cc-muted hover:text-cc-fg"}`,children:"Codex"})]}),e.jsxs("div",{className:"relative",ref:X,children:[e.jsxs("button",{onClick:()=>{K(!F),$(!1),P(!1)},"aria-expanded":F,className:x,children:[e.jsx("span",{children:J==null?void 0:J.icon}),e.jsx("span",{children:J==null?void 0:J.label}),e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50",children:e.jsx("path",{d:"M4 6l4 4 4-4"})})]}),F&&e.jsx("div",{className:"absolute left-0 top-full mt-1 w-48 bg-cc-card border border-cc-border rounded-[10px] shadow-lg z-10 py-1",children:y.map(s=>e.jsxs("button",{onClick:()=>{v("model",s.value),K(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer flex items-center gap-2 ${s.value===t.model?"text-cc-primary font-medium":"text-cc-fg"}`,children:[e.jsx("span",{children:s.icon}),s.label]},s.value))})]}),e.jsxs("div",{className:"relative",ref:te,children:[e.jsxs("button",{onClick:()=>{$(!_),K(!1),P(!1)},"aria-expanded":_,className:x,children:[e.jsx("span",{children:se==null?void 0:se.label}),e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50",children:e.jsx("path",{d:"M4 6l4 4 4-4"})})]}),_&&e.jsx("div",{className:"absolute left-0 top-full mt-1 w-48 bg-cc-card border border-cc-border rounded-[10px] shadow-lg z-10 py-1",children:l.map(s=>e.jsx("button",{onClick:()=>{v("permissionMode",s.value),$(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer flex items-center gap-2 ${s.value===t.permissionMode?"text-cc-primary font-medium":"text-cc-fg"}`,children:s.label},s.value))})]}),e.jsxs("button",{onClick:()=>k(!0),className:t.cwd?f:x,title:t.cwd||"Temporary directory",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.879a1.5 1.5 0 011.06.44l1.122 1.12A1.5 1.5 0 009.62 4H13.5A1.5 1.5 0 0115 5.5v7a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})}),e.jsx("span",{className:"max-w-[120px] sm:max-w-[200px] truncate font-mono-code",children:ve}),t.cwd&&e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50 hover:opacity-100",onClick:s=>{s.stopPropagation(),v("cwd","")},children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})]}),t.cwd&&(G?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted opacity-60",children:e.jsx("path",{d:"M9.5 3.25a2.25 2.25 0 113 2.122V6.5A2.5 2.5 0 0110 9H6a1 1 0 00-1 1v1.128a2.251 2.251 0 11-1.5 0V5.372a2.25 2.25 0 111.5 0v1.836A2.492 2.492 0 016 7h4a1 1 0 001-1v-.878A2.25 2.25 0 019.5 3.25z"})}),e.jsx("input",{value:t.branch,onChange:s=>v("branch",s.target.value),placeholder:"branch name",className:"w-28 px-1.5 py-1 text-xs rounded-md bg-cc-input-bg border border-cc-border text-cc-fg font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary",autoFocus:!0,onBlur:()=>{t.branch||W(!1)}}),t.branch&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-center gap-1 text-[10px] text-cc-muted cursor-pointer",title:"Create branch if it doesn't exist",children:[e.jsx("input",{type:"checkbox",checked:t.createBranch,onChange:s=>v("createBranch",s.target.checked),className:"rounded w-3 h-3"}),"create"]}),e.jsxs("label",{className:"flex items-center gap-1 text-[10px] text-cc-muted cursor-pointer",title:"Use git worktree",children:[e.jsx("input",{type:"checkbox",checked:t.useWorktree,onChange:s=>v("useWorktree",s.target.checked),className:"rounded w-3 h-3"}),"worktree"]})]})]}):e.jsxs("button",{onClick:()=>W(!0),className:x,title:"Set a git branch",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M9.5 3.25a2.25 2.25 0 113 2.122V6.5A2.5 2.5 0 0110 9H6a1 1 0 00-1 1v1.128a2.251 2.251 0 11-1.5 0V5.372a2.25 2.25 0 111.5 0v1.836A2.492 2.492 0 016 7h4a1 1 0 001-1v-.878A2.25 2.25 0 019.5 3.25z"})}),e.jsx("span",{children:"branch"})]})),e.jsxs("div",{className:"relative",ref:Y,children:[e.jsxs("button",{onClick:()=>{P(!q),K(!1),$(!1)},"aria-expanded":q,className:t.envSlug?f:x,children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M8 1a2 2 0 012 2v4H6V3a2 2 0 012-2zm3.5 6V3a3.5 3.5 0 10-7 0v4A1.5 1.5 0 003 8.5v5A1.5 1.5 0 004.5 15h7a1.5 1.5 0 001.5-1.5v-5A1.5 1.5 0 0011.5 7z"})}),e.jsx("span",{children:(ce==null?void 0:ce.name)||"None"}),e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50",children:e.jsx("path",{d:"M4 6l4 4 4-4"})})]}),q&&e.jsxs("div",{className:"absolute left-0 top-full mt-1 w-48 bg-cc-card border border-cc-border rounded-[10px] shadow-lg z-10 py-1",children:[e.jsx("button",{onClick:()=>{v("envSlug",""),P(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer ${t.envSlug?"text-cc-fg":"text-cc-primary font-medium"}`,children:"None"}),U.map(s=>e.jsx("button",{onClick:()=>{v("envSlug",s.slug),P(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer ${t.envSlug===s.slug?"text-cc-primary font-medium":"text-cc-fg"}`,children:s.name},s.slug))]})]}),t.backendType==="codex"&&e.jsxs("button",{onClick:()=>v("codexInternetAccess",!t.codexInternetAccess),className:t.codexInternetAccess?f:x,title:"Allow internet access (Codex)",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M0 8a8 8 0 1116 0A8 8 0 010 8zm7.5-6.923c-.67.204-1.335.82-1.887 1.855A7.97 7.97 0 005.145 4H7.5V1.077zM4.09 4a9.267 9.267 0 01.64-1.539 6.7 6.7 0 01.597-.933A6.504 6.504 0 002.536 4H4.09zm-.582 3.5c.03-.877.138-1.718.312-2.5H1.674a6.51 6.51 0 00-.656 2.5h2.49zM4.847 5a12.5 12.5 0 00-.338 2.5H7.5V5H4.847zM8.5 5v2.5h2.99a12.495 12.495 0 00-.337-2.5H8.5zM4.51 8.5a12.5 12.5 0 00.337 2.5H7.5V8.5H4.51zm3.99 0V11h2.653c.187-.765.306-1.608.338-2.5H8.5zM5.145 12c.138.386.295.744.468 1.068.552 1.035 1.218 1.65 1.887 1.855V12H5.145zm.182 2.472a6.696 6.696 0 01-.597-.933A9.268 9.268 0 014.09 12H2.536a6.504 6.504 0 002.79 2.472zM3.82 11a13.652 13.652 0 01-.312-2.5h-2.49c.062.89.291 1.733.656 2.5H3.82zm6.853 3.472A6.504 6.504 0 0013.464 12H11.91a9.27 9.27 0 01-.64 1.539 6.688 6.688 0 01-.597.933zM8.5 14.923c.67-.204 1.335-.82 1.887-1.855.173-.324.33-.682.468-1.068H8.5v2.923zm3.68-3.923c.174-.782.282-1.623.312-2.5H15c-.094.89-.323 1.733-.656 2.5h-2.163zM12.18 8.5c-.03-.877-.138-1.718-.312-2.5h2.158c.365.767.594 1.61.656 2.5H12.18zm-1.508-4.5h2.792a6.504 6.504 0 00-2.79-2.472c.218.284.418.598.597.933.226.423.424.896.59 1.539z"})}),e.jsx("span",{children:"Internet"})]})]}),N&&e.jsx(ye,{initialPath:t.cwd||"",onSelect:s=>{v("cwd",s),k(!1)},onClose:()=>k(!1)}),e.jsxs("section",{children:[e.jsx("h2",{className:"text-xs text-cc-muted mb-2",children:"Triggers"}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("button",{onClick:()=>v("webhookEnabled",!t.webhookEnabled),className:t.webhookEnabled?f:x,children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M8.543 2.232a.75.75 0 00-1.085 0l-5.25 5.5A.75.75 0 002.75 9H4v4a1 1 0 001 1h6a1 1 0 001-1V9h1.25a.75.75 0 00.543-1.268l-5.25-5.5z"})}),"Webhook"]}),e.jsxs("button",{onClick:()=>v("scheduleEnabled",!t.scheduleEnabled),className:t.scheduleEnabled?f:x,children:[e.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:[e.jsx("path",{d:"M8 3.5a.5.5 0 00-1 0V8a.5.5 0 00.252.434l3.5 2a.5.5 0 00.496-.868L8 7.71V3.5z"}),e.jsx("path",{d:"M8 16A8 8 0 108 0a8 8 0 000 16zm7-8A7 7 0 111 8a7 7 0 0114 0z"})]}),"Schedule"]}),j&&e.jsxs("button",{onClick:()=>v("linearEnabled",!t.linearEnabled),className:t.linearEnabled?f:x,children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M3 1a1 1 0 00-1 1v12a1 1 0 001 1h10a1 1 0 001-1V2a1 1 0 00-1-1H3zm1 2h8v2H4V3zm0 4h5v2H4V7zm0 4h8v2H4v-2z"})}),"Linear Agent"]})]}),t.webhookEnabled&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsxs("p",{className:"text-[10px] text-cc-muted",children:["A unique URL will be generated after saving. POST to it with ",e.jsx("code",{className:"px-1 py-0.5 rounded bg-cc-hover",children:'{"input": "..."}'}),"."]}),re&&e.jsxs("p",{className:"text-[10px] text-cc-muted",children:["Base URL: ",e.jsx("span",{className:"font-mono-code",children:re})]})]}),t.linearEnabled&&e.jsx("div",{className:"mt-3 space-y-2","data-testid":"linear-connection-picker",children:O?e.jsx("p",{className:"text-[10px] text-cc-muted",children:"Loading connections..."}):D.length===0?e.jsxs("p",{className:"text-[10px] text-cc-muted",children:["No OAuth connections found."," ",e.jsx("a",{href:"#/agents?setup=linear",className:"text-cc-primary underline",children:"Set up a Linear OAuth app"})," ","first."]}):e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"block text-[10px] text-cc-muted mb-1",children:"OAuth Connection"}),e.jsx("div",{className:"space-y-1",children:D.map(s=>e.jsxs("button",{type:"button",onClick:()=>v("linearOAuthConnectionId",s.id),className:`w-full flex items-center justify-between px-3 py-2 rounded-lg border text-xs transition-colors cursor-pointer ${t.linearOAuthConnectionId===s.id?"border-cc-primary bg-cc-primary/10 text-cc-fg":"border-cc-border bg-cc-input-bg text-cc-muted hover:text-cc-fg hover:border-cc-primary/50"}`,children:[e.jsx("span",{className:"font-medium",children:s.name}),e.jsx("span",{className:`px-1.5 py-0.5 text-[10px] rounded-full ${s.status==="connected"?"bg-emerald-500/15 text-emerald-400":"bg-cc-muted/15 text-cc-muted"}`,children:s.status==="connected"?"Connected":"Not connected"})]},s.id))}),e.jsxs("p",{className:"text-[10px] text-cc-muted",children:["This agent will respond to @mentions in Linear."," ",e.jsx("a",{href:"#/agents?setup=linear",className:"text-cc-primary underline",children:"Manage connections"})]})]})}),t.scheduleEnabled&&e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-cc-muted cursor-pointer",children:[e.jsx("input",{type:"radio",checked:t.scheduleRecurring,onChange:()=>v("scheduleRecurring",!0)}),"Recurring"]}),e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-cc-muted cursor-pointer",children:[e.jsx("input",{type:"radio",checked:!t.scheduleRecurring,onChange:()=>v("scheduleRecurring",!1)}),"One-time"]})]}),t.scheduleRecurring?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex flex-wrap gap-1",children:Ze.map(s=>e.jsx("button",{onClick:()=>v("scheduleExpression",s.value),className:`px-2 py-1 text-[10px] rounded-lg border transition-colors cursor-pointer ${t.scheduleExpression===s.value?"border-cc-primary text-cc-primary":"border-cc-border text-cc-muted hover:text-cc-fg"}`,children:s.label},s.value))}),e.jsx("input",{value:t.scheduleExpression,onChange:s=>v("scheduleExpression",s.target.value),placeholder:"Cron expression (e.g. 0 8 * * *)",className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"})]}):e.jsx("input",{type:"datetime-local",value:t.scheduleExpression,onChange:s=>v("scheduleExpression",s.target.value),className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsxs("div",{className:"pt-1",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-cc-muted mb-1",children:"If a previous run is still open"}),e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx("button",{type:"button",onClick:()=>v("restartMode","terminate"),className:`px-2 py-1 text-[10px] rounded-lg border transition-colors cursor-pointer ${t.restartMode==="terminate"?"border-cc-primary text-cc-primary":"border-cc-border text-cc-muted hover:text-cc-fg"}`,children:"Terminate it & start fresh"}),e.jsx("button",{type:"button",onClick:()=>v("restartMode","skip"),className:`px-2 py-1 text-[10px] rounded-lg border transition-colors cursor-pointer ${t.restartMode==="skip"?"border-cc-primary text-cc-primary":"border-cc-border text-cc-muted hover:text-cc-fg"}`,children:"Skip this run"})]}),e.jsx("p",{className:"mt-1 text-[10px] text-cc-muted",children:"Agent sessions stay open until archived. “Terminate” closes the leftover session so the next scheduled run can start; “Skip” keeps it and waits."})]})]})]}),e.jsxs("section",{children:[e.jsxs("button",{onClick:()=>C(!b),className:"flex items-center gap-2 text-xs text-cc-muted cursor-pointer hover:text-cc-fg transition-colors w-full",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:`w-3 h-3 transition-transform ${b?"rotate-90":""}`,children:e.jsx("path",{d:"M6 3l5 5-5 5V3z"})}),"Advanced",je(t)>0&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] rounded-full bg-cc-primary/15 text-cc-primary font-normal",children:je(t)})]}),b&&e.jsxs("div",{className:"mt-4 space-y-6 pl-5 border-l-2 border-cc-border/30",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted",children:"MCP Servers"}),e.jsx("button",{onClick:()=>S(!p),className:"text-[10px] text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:p?"Cancel":"+ Add Server"})]}),Object.keys(t.mcpServers).length===0&&!p&&e.jsx("p",{className:"text-[10px] text-cc-muted",children:"No MCP servers configured."}),Object.entries(t.mcpServers).map(([s,n])=>e.jsxs("div",{className:"flex items-center justify-between py-1.5 px-2 rounded-lg bg-cc-hover/50 mb-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-cc-fg font-mono-code",children:s}),e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] rounded bg-cc-border text-cc-muted",children:n.type})]}),e.jsx("button",{onClick:()=>ge(s),className:"text-cc-muted hover:text-cc-error transition-colors cursor-pointer p-0.5",title:"Remove server",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]},s)),p&&e.jsxs("div",{className:"rounded-lg border border-cc-border p-3 mt-2 space-y-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] text-cc-muted mb-0.5",children:"Server Name"}),e.jsx("input",{value:M,onChange:s=>z(s.target.value),placeholder:"e.g., my-server",className:"w-full px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] text-cc-muted mb-0.5",children:"Type"}),e.jsx("div",{className:"flex rounded-lg border border-cc-border overflow-hidden",children:["stdio","sse","http"].map(s=>e.jsx("button",{onClick:()=>L(n=>({...n,type:s})),className:`flex-1 px-2 py-1 text-[10px] transition-colors cursor-pointer ${w.type===s?"bg-cc-primary text-white":"bg-cc-input-bg text-cc-muted hover:text-cc-fg"}`,children:s},s))})]}),w.type==="stdio"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] text-cc-muted mb-0.5",children:"Command"}),e.jsx("input",{value:w.command,onChange:s=>L(n=>({...n,command:s.target.value})),placeholder:"e.g., npx -y @some/mcp-server",className:"w-full px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] text-cc-muted mb-0.5",children:"Args (space-separated)"}),e.jsx("input",{value:w.args,onChange:s=>L(n=>({...n,args:s.target.value})),placeholder:"--port 3000",className:"w-full px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"})]})]}):e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] text-cc-muted mb-0.5",children:"URL"}),e.jsx("input",{value:w.url,onChange:s=>L(n=>({...n,url:s.target.value})),placeholder:"https://example.com/mcp",className:"w-full px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"})]}),e.jsx("button",{onClick:me,disabled:!M.trim(),className:"px-3 py-1.5 text-xs rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors disabled:opacity-50 cursor-pointer disabled:cursor-not-allowed",children:"Add Server"})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted mb-2",children:"Skills"}),B.length===0?e.jsx("p",{className:"text-[10px] text-cc-muted",children:"No skills found in ~/.claude/skills/"}):e.jsx("div",{className:"space-y-1.5",children:B.map(s=>e.jsxs("label",{className:"flex items-start gap-2 text-sm text-cc-fg cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:t.skills.includes(s.slug),onChange:()=>ue(s.slug),className:"rounded mt-0.5"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs",children:s.name}),s.description&&e.jsx("p",{className:"text-[10px] text-cc-muted",children:s.description})]})]},s.slug))})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted mb-2",children:"Allowed Tools"}),e.jsxs("div",{className:"space-y-2",children:[t.allowedTools.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.allowedTools.map(s=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-xs font-mono-code rounded-lg bg-cc-hover text-cc-fg",children:[s,e.jsx("button",{onClick:()=>fe(s),className:"text-cc-muted hover:text-cc-error transition-colors cursor-pointer",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-2.5 h-2.5",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]},s))}),e.jsx("input",{value:I,onChange:s=>le(s.target.value),onKeyDown:be,placeholder:"Type tool name and press Enter",className:"w-full px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsx("p",{className:"text-[10px] text-cc-muted",children:"Leave empty to allow all tools."})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted",children:"Environment Variables"}),e.jsx("button",{onClick:pe,className:"text-[10px] text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"+ Add Variable"})]}),t.env.length===0?e.jsx("p",{className:"text-[10px] text-cc-muted",children:"No extra variables set."}):e.jsx("div",{className:"space-y-1.5",children:t.env.map((s,n)=>e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("input",{value:s.key,onChange:A=>de(n,"key",A.target.value),placeholder:"KEY",className:"w-1/3 px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsx("input",{value:s.value,onChange:A=>de(n,"value",A.target.value),placeholder:"value",className:"flex-1 px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsx("button",{onClick:()=>xe(n),className:"text-cc-muted hover:text-cc-error transition-colors cursor-pointer p-1",title:"Remove variable",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]},n))})]})]})]})]})]})})}function Xe({form:t,setForm:i,editingId:d,error:a,saving:m,onSave:u,onCancel:h,onOpenGenericEditor:g}){const[j,y]=r.useState(!1),[l,N]=r.useState(!1),[k,b]=r.useState(!1),C=r.useRef(null),p=r.useRef(null);function S(o,O){i(H=>({...H,[o]:O}))}function M(o){i(O=>({...O,backendType:o,model:ae(o),permissionMode:Ne(o)}))}r.useEffect(()=>{function o(O){C.current&&!C.current.contains(O.target)&&N(!1),p.current&&!p.current.contains(O.target)&&b(!1)}return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[]);const z=Ie(t.backendType),w=Oe(t.backendType),L=z.find(o=>o.value===t.model)||z[0],B=w.find(o=>o.value===t.permissionMode)||w[0],R=t.cwd?t.cwd.split("/").pop()||t.cwd:"temp",U="flex items-center gap-1.5 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer",V=`${U} text-cc-muted hover:text-cc-fg hover:bg-cc-hover`,D=`${U} text-cc-primary bg-cc-primary/10 hover:bg-cc-primary/15`;return e.jsx("div",{className:"h-full overflow-y-auto bg-cc-bg",children:e.jsxs("div",{className:"max-w-3xl mx-auto p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:h,className:"p-1.5 rounded-lg text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4",children:e.jsx("path",{d:"M11 2L5 8l6 6",stroke:"currentColor",strokeWidth:"2",fill:"none"})})}),e.jsx(ne,{className:"w-5 h-5 text-cc-fg"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Edit Linear Agent"}),e.jsxs("p",{className:"text-[10px] text-cc-muted font-mono-code",children:["ID: ",d]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:h,className:"px-3 py-1.5 text-xs rounded-lg border border-cc-border text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{onClick:u,disabled:m||!t.name.trim()||!t.prompt.trim(),className:"px-3 py-1.5 text-xs rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors disabled:opacity-50 cursor-pointer disabled:cursor-not-allowed",children:m?"Saving...":"Save"})]})]}),a&&e.jsx("div",{className:"mb-4 px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/30 text-cc-error text-xs",children:a}),e.jsxs("div",{className:"space-y-5",children:[e.jsx("input",{value:t.name,onChange:o=>S("name",o.target.value),placeholder:"Agent name *",className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsx("input",{value:t.description,onChange:o=>S("description",o.target.value),placeholder:"Short description (optional)",className:"w-full px-3 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsxs("div",{children:[e.jsx("textarea",{value:t.prompt,onChange:o=>S("prompt",o.target.value),placeholder:`System prompt *
12
12
  Write the agent’s instructions here.
13
- Use {{input}} as a placeholder for trigger-provided input.`,className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm resize-none h-40 font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsxs("p",{className:"text-[10px] text-cc-muted mt-1",children:["Use ",e.jsx("code",{className:"px-1 py-0.5 rounded bg-cc-hover",children:"{{input}}"})," where trigger input should be inserted."]})]}),e.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 flex-wrap","data-testid":"controls-row",children:[e.jsxs("div",{className:"flex items-center bg-cc-hover/50 rounded-lg p-0.5",children:[e.jsx("button",{onClick:()=>M("claude"),className:`flex items-center gap-1 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer ${t.backendType==="claude"?"bg-cc-card text-cc-fg font-medium shadow-sm":"text-cc-muted hover:text-cc-fg"}`,children:"Claude"}),e.jsx("button",{onClick:()=>M("codex"),className:`flex items-center gap-1 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer ${t.backendType==="codex"?"bg-cc-card text-cc-fg font-medium shadow-sm":"text-cc-muted hover:text-cc-fg"}`,children:"Codex"})]}),e.jsxs("div",{className:"relative",ref:C,children:[e.jsxs("button",{onClick:()=>{N(!l),b(!1)},"aria-expanded":l,className:V,children:[e.jsx("span",{children:L==null?void 0:L.icon}),e.jsx("span",{children:L==null?void 0:L.label}),e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50",children:e.jsx("path",{d:"M4 6l4 4 4-4"})})]}),l&&e.jsx("div",{className:"absolute left-0 top-full mt-1 w-48 bg-cc-card border border-cc-border rounded-[10px] shadow-lg z-10 py-1",children:E.map(o=>e.jsxs("button",{onClick:()=>{S("model",o.value),N(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer flex items-center gap-2 ${o.value===t.model?"text-cc-primary font-medium":"text-cc-fg"}`,children:[e.jsx("span",{children:o.icon}),o.label]},o.value))})]}),e.jsxs("div",{className:"relative",ref:p,children:[e.jsxs("button",{onClick:()=>{b(!k),N(!1)},"aria-expanded":k,className:V,children:[e.jsx("span",{children:B==null?void 0:B.label}),e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50",children:e.jsx("path",{d:"M4 6l4 4 4-4"})})]}),k&&e.jsx("div",{className:"absolute left-0 top-full mt-1 w-48 bg-cc-card border border-cc-border rounded-[10px] shadow-lg z-10 py-1",children:w.map(o=>e.jsx("button",{onClick:()=>{S("permissionMode",o.value),b(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer flex items-center gap-2 ${o.value===t.permissionMode?"text-cc-primary font-medium":"text-cc-fg"}`,children:o.label},o.value))})]}),e.jsxs("button",{onClick:()=>y(!0),className:t.cwd?D:V,title:t.cwd||"Temporary directory",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.879a1.5 1.5 0 011.06.44l1.122 1.12A1.5 1.5 0 009.62 4H13.5A1.5 1.5 0 0115 5.5v7a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})}),e.jsx("span",{className:"max-w-[120px] sm:max-w-[200px] truncate font-mono-code",children:R}),t.cwd&&e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50 hover:opacity-100",onClick:o=>{o.stopPropagation(),S("cwd","")},children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})]})]}),j&&e.jsx(ye,{initialPath:t.cwd||"",onSelect:o=>{S("cwd",o),y(!1)},onClose:()=>y(!1)}),e.jsxs("section",{className:"rounded-lg border border-cc-success/30 bg-cc-success/5 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium bg-cc-success/10 text-cc-success border border-cc-success/20",children:"Linear Agent trigger enabled"})}),e.jsx("button",{onClick:g,className:"text-xs text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Open in full editor →"})]}),e.jsxs("p",{className:"text-[10px] text-cc-muted mt-2",children:["This agent responds to @mentions in Linear."," ",e.jsx("a",{href:"#/integrations/linear-oauth",className:"text-cc-primary underline",children:"Manage OAuth connections"}),"."]})]})]})]})})}const Te={all:"All",linear:"Linear",scheduled:"Scheduled",webhook:"Webhook"};function tt({route:t}){const i=Be(c=>c.publicUrl),[d,a]=r.useState([]),[m,u]=r.useState(!0),[h,g]=r.useState("list"),[j,y]=r.useState(null),[l,N]=r.useState(Re),[k,b]=r.useState(!1),[C,p]=r.useState(""),[S,M]=r.useState(null),[E,w]=r.useState(""),[L,B]=r.useState(null),[R,U]=r.useState("all"),[V,D]=r.useState(!1),o=r.useRef(null),I=[{label:"Intro"},{label:"Connection"},{label:"Agent"},{label:"Done"}],[H,O]=r.useState(1),[le,F]=r.useState(""),[K,_]=r.useState(null),[$,q]=r.useState(null),[P,G]=r.useState(null);r.useEffect(()=>{window.location.hash.includes("setup=linear")&&(X(),history.replaceState(null,"","#/agents"))},[]);const W=r.useCallback(async()=>{try{const c=await z.listAgents();if(a(c),c.some(f=>{var s,n,A,T;return((n=(s=f.triggers)==null?void 0:s.linear)==null?void 0:n.enabled)&&((T=(A=f.triggers)==null?void 0:A.linear)==null?void 0:T.hasAccessToken)}))D(!0);else try{const{connections:f}=await z.listLinearOAuthConnections();D(f.length>0)}catch{D(!1)}}catch{}finally{u(!1)}},[]);r.useEffect(()=>{W()},[W]),r.useEffect(()=>{if(t.page==="agent-detail"&&"agentId"in t){const c=d.find(x=>x.id===t.agentId);c&&Z(c)}},[t,d]);function oe(){y(null),N(Re),p(""),g("edit")}function Z(c){var x,f,s,n,A,T,ee,we,ke,Ce,Se,Ae,Le,Me;y(c.id),N({name:c.name,description:c.description,icon:c.icon||"",backendType:c.backendType,model:c.model,permissionMode:c.permissionMode,cwd:c.cwd==="temp"?"":c.cwd,prompt:c.prompt,envSlug:c.envSlug||"",env:c.env?Object.entries(c.env).map(([$e,We])=>({key:$e,value:We})):[],codexInternetAccess:c.codexInternetAccess??!1,branch:c.branch||"",createBranch:c.createBranch??!1,useWorktree:c.useWorktree??!1,mcpServers:c.mcpServers||{},skills:c.skills||[],allowedTools:c.allowedTools||[],webhookEnabled:((f=(x=c.triggers)==null?void 0:x.webhook)==null?void 0:f.enabled)??!1,scheduleEnabled:((n=(s=c.triggers)==null?void 0:s.schedule)==null?void 0:n.enabled)??!1,scheduleExpression:((T=(A=c.triggers)==null?void 0:A.schedule)==null?void 0:T.expression)||"0 8 * * *",scheduleRecurring:((we=(ee=c.triggers)==null?void 0:ee.schedule)==null?void 0:we.recurring)??!0,restartMode:c.restartMode??"terminate",linearEnabled:((Ce=(ke=c.triggers)==null?void 0:ke.linear)==null?void 0:Ce.enabled)??!1,linearOAuthConnectionId:((Ae=(Se=c.triggers)==null?void 0:Se.linear)==null?void 0:Ae.oauthConnectionId)??""}),p(""),(Me=(Le=c.triggers)==null?void 0:Le.linear)!=null&&Me.enabled?g("edit-linear"):g("edit")}function Q(){g("list"),y(null),p(""),window.location.hash="#/agents"}function X(){g("setup-linear"),O(1)}function te(){g("list"),O(1),F(""),_(null),q(null),G(null)}const Y=new Set;P&&(Y.add(1),Y.add(2)),K&&Y.add(3);const v=r.useCallback((c,x)=>{_(c),F(x),O(4)},[]),ie=r.useCallback(()=>{g("list"),O(1),F(""),_(null),G(null),W()},[W]),pe=r.useCallback(()=>{F(""),q(null),_(null),O(3)},[]),de=r.useCallback(()=>{_(null),F(""),q(null),G(null),O(2)},[]);async function xe(){b(!0),p("");try{const c={};for(const{key:f,value:s}of l.env)f.trim()&&(c[f.trim()]=s);const x={version:1,name:l.name,description:l.description,icon:l.icon||void 0,backendType:l.backendType,model:l.model,permissionMode:l.permissionMode,cwd:l.cwd||"temp",prompt:l.prompt,envSlug:l.envSlug||void 0,env:Object.keys(c).length>0?c:void 0,codexInternetAccess:l.backendType==="codex"?l.codexInternetAccess:void 0,restartMode:l.restartMode,branch:l.branch||void 0,createBranch:l.branch?l.createBranch:void 0,useWorktree:l.branch?l.useWorktree:void 0,mcpServers:Object.keys(l.mcpServers).length>0?l.mcpServers:void 0,skills:l.skills.length>0?l.skills:void 0,allowedTools:l.allowedTools.length>0?l.allowedTools:void 0,enabled:!0,triggers:{webhook:{enabled:l.webhookEnabled,secret:""},schedule:{enabled:l.scheduleEnabled,expression:l.scheduleExpression,recurring:l.scheduleRecurring},linear:{enabled:l.linearEnabled,...l.linearOAuthConnectionId?{oauthConnectionId:l.linearOAuthConnectionId}:{}}}};j?await z.updateAgent(j,x):await z.createAgent(x),await W(),g("list"),y(null),window.location.hash="#/agents"}catch(c){p(c instanceof Error?c.message:String(c))}finally{b(!1)}}async function me(c){var n,A;const x=d.find(T=>T.id===c),s=((A=(n=x==null?void 0:x.triggers)==null?void 0:n.linear)==null?void 0:A.enabled)?"Delete this Linear agent? It will no longer respond to @mentions in Linear.":"Delete this agent?";if(confirm(s))try{await z.deleteAgent(c),await W()}catch{}}async function ge(c){try{await z.toggleAgent(c),await W()}catch{}}async function ue(c,x){try{await z.runAgent(c.id,x),M(null),w(""),await W()}catch{}}function be(c){c.prompt.includes("{{input}}")?(M(c),w("")):ue(c)}async function fe(c){try{const x=await z.exportAgent(c.id),f=new Blob([JSON.stringify(x,null,2)],{type:"application/json"}),s=URL.createObjectURL(f),n=document.createElement("a");n.href=s,n.download=`${c.id}.agent.json`,n.click(),URL.revokeObjectURL(s)}catch{}}async function J(c){var f;const x=(f=c.target.files)==null?void 0:f[0];if(x){try{const s=await x.text(),n=JSON.parse(s);await z.importAgent(n),await W()}catch(s){p(s instanceof Error?s.message:"Failed to import agent")}o.current&&(o.current.value="")}}function se(c){const x=qe(c,i);navigator.clipboard.writeText(x).then(()=>{B(c.id),setTimeout(()=>B(null),2e3)})}async function ce(c){if(confirm("Regenerate webhook secret? The old URL will stop working."))try{await z.regenerateAgentWebhookSecret(c),await W()}catch{}}if(h==="edit")return e.jsx(Qe,{form:l,setForm:N,editingId:j,publicUrl:i,error:C,saving:k,onSave:xe,onCancel:Q,linearOAuthConfigured:V});if(h==="edit-linear"&&j)return e.jsx(Xe,{form:l,setForm:N,editingId:j,error:C,saving:k,onSave:xe,onCancel:Q,onOpenGenericEditor:()=>g("edit")});if(h==="setup-linear")return e.jsx("main",{className:"h-full overflow-y-auto bg-cc-bg",children:e.jsxs("div",{className:"max-w-3xl mx-auto px-4 sm:px-8 py-6 sm:py-10",children:[e.jsxs("div",{className:"flex items-center justify-between mb-8",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ne,{className:"w-6 h-6 text-cc-fg"}),e.jsx("h1",{className:"text-xl font-semibold text-cc-fg",children:"Linear Agent Setup"})]}),e.jsx("button",{onClick:te,className:"px-3 py-2 rounded-lg text-sm text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Cancel"})]}),e.jsx(He,{steps:I,currentStep:H,completedSteps:Y}),e.jsxs("div",{className:"bg-cc-card border border-cc-border rounded-xl p-5 sm:p-7",children:[H===1&&e.jsx(Pe,{onNext:()=>O(2)}),H===2&&e.jsx(Ue,{onNext:c=>{G(c),O(3)},onBack:()=>O(1),selectedConnectionId:P}),H===3&&e.jsx(Fe,{onNext:v,onBack:()=>O(2),oauthConnectionId:P,existingAgent:$?{id:$.id,name:$.name,prompt:$.prompt,backendType:$.backendType,model:$.model,cwd:$.cwd}:void 0}),H===4&&e.jsx(_e,{agentName:le,onFinish:ie,onAddAnotherSameApp:pe,onAddAnotherNewApp:de})]})]})});const ve={all:d.length,linear:d.filter(c=>{var x,f;return(f=(x=c.triggers)==null?void 0:x.linear)==null?void 0:f.enabled}).length,scheduled:d.filter(c=>{var x,f;return(f=(x=c.triggers)==null?void 0:x.schedule)==null?void 0:f.enabled}).length,webhook:d.filter(c=>{var x,f;return(f=(x=c.triggers)==null?void 0:x.webhook)==null?void 0:f.enabled}).length},re=d.filter(c=>{var x,f,s,n,A,T;switch(R){case"linear":return((f=(x=c.triggers)==null?void 0:x.linear)==null?void 0:f.enabled)===!0;case"scheduled":return((n=(s=c.triggers)==null?void 0:s.schedule)==null?void 0:n.enabled)===!0;case"webhook":return((T=(A=c.triggers)==null?void 0:A.webhook)==null?void 0:T.enabled)===!0;default:return!0}});return e.jsxs("div",{className:"h-full overflow-y-auto bg-cc-bg",children:[e.jsxs("div",{className:"max-w-4xl mx-auto p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Agents"}),e.jsx("p",{className:"text-xs text-cc-muted mt-0.5",children:"Reusable autonomous session configs. Run manually, via webhook, or on a schedule."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{ref:o,type:"file",accept:".json",onChange:J,className:"hidden"}),e.jsx("button",{onClick:()=>{var c;return(c=o.current)==null?void 0:c.click()},className:"px-3 py-1.5 text-xs rounded-lg border border-cc-border text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Import"}),e.jsx("button",{onClick:oe,className:"px-3 py-1.5 text-xs rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors cursor-pointer",children:"+ New Agent"})]})]}),C&&e.jsx("div",{className:"mb-4 px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/30 text-cc-error text-xs",children:C}),e.jsx(De,{publicUrl:i}),!m&&d.length>0&&e.jsx("div",{className:"flex items-center gap-1 mb-4","data-testid":"filter-tabs",children:["all","linear","scheduled","webhook"].map(c=>e.jsxs("button",{onClick:()=>U(c),className:`text-xs px-2.5 py-1 rounded-full transition-colors cursor-pointer ${R===c?"bg-cc-fg text-cc-bg":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:[Te[c]," (",ve[c],")"]},c))}),m?e.jsx("div",{className:"text-sm text-cc-muted",children:"Loading..."}):d.length===0?e.jsxs("div",{className:"text-center py-16",children:[e.jsx("div",{className:"mb-3 flex justify-center text-cc-muted",children:e.jsx(he,{icon:"bot",className:"w-8 h-8"})}),e.jsx("p",{className:"text-sm text-cc-muted",children:"No agents yet"}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Create an agent to get started, or import a shared JSON config."})]}):re.length===0?e.jsx("div",{className:"text-center py-12",children:R==="linear"?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mb-3 flex justify-center text-cc-muted",children:e.jsx(ne,{className:"w-6 h-6"})}),e.jsx("p",{className:"text-sm text-cc-muted",children:"No Linear agents"}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Create a Linear agent to respond to @mentions in Linear issues."}),e.jsxs("button",{onClick:X,className:"mt-3 px-3 py-1.5 text-xs rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors cursor-pointer inline-flex items-center gap-1.5",children:[e.jsx(ne,{className:"w-3 h-3"}),"Setup Linear Agent"]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-sm text-cc-muted",children:["No ",Te[R].toLowerCase()," agents"]}),e.jsxs("p",{className:"text-xs text-cc-muted mt-1",children:[R==="scheduled"&&"Create an agent with a schedule trigger to see it here.",R==="webhook"&&"Create an agent with a webhook trigger to see it here."]})]})}):e.jsx("div",{className:"space-y-3",children:re.map(c=>e.jsx(Ge,{agent:c,publicUrl:i,onEdit:()=>Z(c),onDelete:()=>me(c.id),onToggle:()=>ge(c.id),onRun:()=>be(c),onExport:()=>fe(c),onCopyWebhook:()=>se(c),onRegenerateSecret:()=>ce(c.id),copiedWebhook:L},c.id))})]}),S&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>M(null),children:e.jsxs("div",{className:"bg-cc-card rounded-[14px] shadow-2xl p-6 w-full max-w-lg border border-cc-border",onClick:c=>c.stopPropagation(),children:[e.jsxs("h3",{className:"text-sm font-medium text-cc-fg mb-1",children:["Run ",S.name]}),e.jsxs("p",{className:"text-xs text-cc-muted mb-3",children:["This agent's prompt uses ","{{input}}"," — provide the input below."]}),e.jsx("textarea",{value:E,onChange:c=>w(c.target.value),placeholder:"Enter input for the agent...",className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm resize-none h-24 focus:outline-none focus:ring-1 focus:ring-cc-primary",autoFocus:!0}),e.jsxs("div",{className:"flex justify-end gap-2 mt-3",children:[e.jsx("button",{onClick:()=>M(null),className:"px-3 py-1.5 text-xs rounded-lg border border-cc-border text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{onClick:()=>ue(S,E),className:"px-3 py-1.5 text-xs rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors cursor-pointer",children:"Run"})]})]})})]})}export{tt as AgentsPage};
13
+ Use {{input}} as a placeholder for trigger-provided input.`,className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm resize-none h-40 font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsxs("p",{className:"text-[10px] text-cc-muted mt-1",children:["Use ",e.jsx("code",{className:"px-1 py-0.5 rounded bg-cc-hover",children:"{{input}}"})," where trigger input should be inserted."]})]}),e.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 flex-wrap","data-testid":"controls-row",children:[e.jsxs("div",{className:"flex items-center bg-cc-hover/50 rounded-lg p-0.5",children:[e.jsx("button",{onClick:()=>M("claude"),className:`flex items-center gap-1 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer ${t.backendType==="claude"?"bg-cc-card text-cc-fg font-medium shadow-sm":"text-cc-muted hover:text-cc-fg"}`,children:"Claude"}),e.jsx("button",{onClick:()=>M("codex"),className:`flex items-center gap-1 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer ${t.backendType==="codex"?"bg-cc-card text-cc-fg font-medium shadow-sm":"text-cc-muted hover:text-cc-fg"}`,children:"Codex"})]}),e.jsxs("div",{className:"relative",ref:C,children:[e.jsxs("button",{onClick:()=>{N(!l),b(!1)},"aria-expanded":l,className:V,children:[e.jsx("span",{children:L==null?void 0:L.icon}),e.jsx("span",{children:L==null?void 0:L.label}),e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50",children:e.jsx("path",{d:"M4 6l4 4 4-4"})})]}),l&&e.jsx("div",{className:"absolute left-0 top-full mt-1 w-48 bg-cc-card border border-cc-border rounded-[10px] shadow-lg z-10 py-1",children:z.map(o=>e.jsxs("button",{onClick:()=>{S("model",o.value),N(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer flex items-center gap-2 ${o.value===t.model?"text-cc-primary font-medium":"text-cc-fg"}`,children:[e.jsx("span",{children:o.icon}),o.label]},o.value))})]}),e.jsxs("div",{className:"relative",ref:p,children:[e.jsxs("button",{onClick:()=>{b(!k),N(!1)},"aria-expanded":k,className:V,children:[e.jsx("span",{children:B==null?void 0:B.label}),e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50",children:e.jsx("path",{d:"M4 6l4 4 4-4"})})]}),k&&e.jsx("div",{className:"absolute left-0 top-full mt-1 w-48 bg-cc-card border border-cc-border rounded-[10px] shadow-lg z-10 py-1",children:w.map(o=>e.jsx("button",{onClick:()=>{S("permissionMode",o.value),b(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer flex items-center gap-2 ${o.value===t.permissionMode?"text-cc-primary font-medium":"text-cc-fg"}`,children:o.label},o.value))})]}),e.jsxs("button",{onClick:()=>y(!0),className:t.cwd?D:V,title:t.cwd||"Temporary directory",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.879a1.5 1.5 0 011.06.44l1.122 1.12A1.5 1.5 0 009.62 4H13.5A1.5 1.5 0 0115 5.5v7a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})}),e.jsx("span",{className:"max-w-[120px] sm:max-w-[200px] truncate font-mono-code",children:R}),t.cwd&&e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50 hover:opacity-100",onClick:o=>{o.stopPropagation(),S("cwd","")},children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})]})]}),j&&e.jsx(ye,{initialPath:t.cwd||"",onSelect:o=>{S("cwd",o),y(!1)},onClose:()=>y(!1)}),e.jsxs("section",{className:"rounded-lg border border-cc-success/30 bg-cc-success/5 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium bg-cc-success/10 text-cc-success border border-cc-success/20",children:"Linear Agent trigger enabled"})}),e.jsx("button",{onClick:g,className:"text-xs text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Open in full editor →"})]}),e.jsxs("p",{className:"text-[10px] text-cc-muted mt-2",children:["This agent responds to @mentions in Linear."," ",e.jsx("a",{href:"#/integrations/linear-oauth",className:"text-cc-primary underline",children:"Manage OAuth connections"}),"."]})]})]})]})})}const Te={all:"All",linear:"Linear",scheduled:"Scheduled",webhook:"Webhook"};function tt({route:t}){const i=Be(c=>c.publicUrl),[d,a]=r.useState([]),[m,u]=r.useState(!0),[h,g]=r.useState("list"),[j,y]=r.useState(null),[l,N]=r.useState(Re),[k,b]=r.useState(!1),[C,p]=r.useState(""),[S,M]=r.useState(null),[z,w]=r.useState(""),[L,B]=r.useState(null),[R,U]=r.useState("all"),[V,D]=r.useState(!1),o=r.useRef(null),O=[{label:"Intro"},{label:"Connection"},{label:"Agent"},{label:"Done"}],[H,I]=r.useState(1),[le,F]=r.useState(""),[K,_]=r.useState(null),[$,q]=r.useState(null),[P,G]=r.useState(null);r.useEffect(()=>{window.location.hash.includes("setup=linear")&&(X(),history.replaceState(null,"","#/agents"))},[]);const W=r.useCallback(async()=>{try{const c=await E.listAgents();if(a(c),c.some(f=>{var s,n,A,T;return((n=(s=f.triggers)==null?void 0:s.linear)==null?void 0:n.enabled)&&((T=(A=f.triggers)==null?void 0:A.linear)==null?void 0:T.hasAccessToken)}))D(!0);else try{const{connections:f}=await E.listLinearOAuthConnections();D(f.length>0)}catch{D(!1)}}catch{}finally{u(!1)}},[]);r.useEffect(()=>{W()},[W]),r.useEffect(()=>{if(t.page==="agent-detail"&&"agentId"in t){const c=d.find(x=>x.id===t.agentId);c&&Z(c)}},[t,d]);function oe(){y(null),N(Re),p(""),g("edit")}function Z(c){var x,f,s,n,A,T,ee,we,ke,Ce,Se,Ae,Le,Me;y(c.id),N({name:c.name,description:c.description,icon:c.icon||"",backendType:c.backendType,model:c.model,permissionMode:c.permissionMode,cwd:c.cwd==="temp"?"":c.cwd,prompt:c.prompt,envSlug:c.envSlug||"",env:c.env?Object.entries(c.env).map(([$e,We])=>({key:$e,value:We})):[],codexInternetAccess:c.codexInternetAccess??!1,branch:c.branch||"",createBranch:c.createBranch??!1,useWorktree:c.useWorktree??!1,mcpServers:c.mcpServers||{},skills:c.skills||[],allowedTools:c.allowedTools||[],webhookEnabled:((f=(x=c.triggers)==null?void 0:x.webhook)==null?void 0:f.enabled)??!1,scheduleEnabled:((n=(s=c.triggers)==null?void 0:s.schedule)==null?void 0:n.enabled)??!1,scheduleExpression:((T=(A=c.triggers)==null?void 0:A.schedule)==null?void 0:T.expression)||"0 8 * * *",scheduleRecurring:((we=(ee=c.triggers)==null?void 0:ee.schedule)==null?void 0:we.recurring)??!0,restartMode:c.restartMode??"terminate",linearEnabled:((Ce=(ke=c.triggers)==null?void 0:ke.linear)==null?void 0:Ce.enabled)??!1,linearOAuthConnectionId:((Ae=(Se=c.triggers)==null?void 0:Se.linear)==null?void 0:Ae.oauthConnectionId)??""}),p(""),(Me=(Le=c.triggers)==null?void 0:Le.linear)!=null&&Me.enabled?g("edit-linear"):g("edit")}function Q(){g("list"),y(null),p(""),window.location.hash="#/agents"}function X(){g("setup-linear"),I(1)}function te(){g("list"),I(1),F(""),_(null),q(null),G(null)}const Y=new Set;P&&(Y.add(1),Y.add(2)),K&&Y.add(3);const v=r.useCallback((c,x)=>{_(c),F(x),I(4)},[]),ie=r.useCallback(()=>{g("list"),I(1),F(""),_(null),G(null),W()},[W]),pe=r.useCallback(()=>{F(""),q(null),_(null),I(3)},[]),de=r.useCallback(()=>{_(null),F(""),q(null),G(null),I(2)},[]);async function xe(){b(!0),p("");try{const c={};for(const{key:f,value:s}of l.env)f.trim()&&(c[f.trim()]=s);const x={version:1,name:l.name,description:l.description,icon:l.icon||void 0,backendType:l.backendType,model:l.model,permissionMode:l.permissionMode,cwd:l.cwd||"temp",prompt:l.prompt,envSlug:l.envSlug||void 0,env:Object.keys(c).length>0?c:void 0,codexInternetAccess:l.backendType==="codex"?l.codexInternetAccess:void 0,restartMode:l.restartMode,branch:l.branch||void 0,createBranch:l.branch?l.createBranch:void 0,useWorktree:l.branch?l.useWorktree:void 0,mcpServers:Object.keys(l.mcpServers).length>0?l.mcpServers:void 0,skills:l.skills.length>0?l.skills:void 0,allowedTools:l.allowedTools.length>0?l.allowedTools:void 0,enabled:!0,triggers:{webhook:{enabled:l.webhookEnabled,secret:""},schedule:{enabled:l.scheduleEnabled,expression:l.scheduleExpression,recurring:l.scheduleRecurring},linear:{enabled:l.linearEnabled,...l.linearOAuthConnectionId?{oauthConnectionId:l.linearOAuthConnectionId}:{}}}};j?await E.updateAgent(j,x):await E.createAgent(x),await W(),g("list"),y(null),window.location.hash="#/agents"}catch(c){p(c instanceof Error?c.message:String(c))}finally{b(!1)}}async function me(c){var n,A;const x=d.find(T=>T.id===c),s=((A=(n=x==null?void 0:x.triggers)==null?void 0:n.linear)==null?void 0:A.enabled)?"Delete this Linear agent? It will no longer respond to @mentions in Linear.":"Delete this agent?";if(confirm(s))try{await E.deleteAgent(c),await W()}catch{}}async function ge(c){try{await E.toggleAgent(c),await W()}catch{}}async function ue(c,x){try{await E.runAgent(c.id,x),M(null),w(""),await W()}catch{}}function be(c){c.prompt.includes("{{input}}")?(M(c),w("")):ue(c)}async function fe(c){try{const x=await E.exportAgent(c.id),f=new Blob([JSON.stringify(x,null,2)],{type:"application/json"}),s=URL.createObjectURL(f),n=document.createElement("a");n.href=s,n.download=`${c.id}.agent.json`,n.click(),URL.revokeObjectURL(s)}catch{}}async function J(c){var f;const x=(f=c.target.files)==null?void 0:f[0];if(x){try{const s=await x.text(),n=JSON.parse(s);await E.importAgent(n),await W()}catch(s){p(s instanceof Error?s.message:"Failed to import agent")}o.current&&(o.current.value="")}}function se(c){const x=qe(c,i);navigator.clipboard.writeText(x).then(()=>{B(c.id),setTimeout(()=>B(null),2e3)})}async function ce(c){if(confirm("Regenerate webhook secret? The old URL will stop working."))try{await E.regenerateAgentWebhookSecret(c),await W()}catch{}}if(h==="edit")return e.jsx(Qe,{form:l,setForm:N,editingId:j,publicUrl:i,error:C,saving:k,onSave:xe,onCancel:Q,linearOAuthConfigured:V});if(h==="edit-linear"&&j)return e.jsx(Xe,{form:l,setForm:N,editingId:j,error:C,saving:k,onSave:xe,onCancel:Q,onOpenGenericEditor:()=>g("edit")});if(h==="setup-linear")return e.jsx("main",{className:"h-full overflow-y-auto bg-cc-bg",children:e.jsxs("div",{className:"max-w-3xl mx-auto px-4 sm:px-8 py-6 sm:py-10",children:[e.jsxs("div",{className:"flex items-center justify-between mb-8",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ne,{className:"w-6 h-6 text-cc-fg"}),e.jsx("h1",{className:"text-xl font-semibold text-cc-fg",children:"Linear Agent Setup"})]}),e.jsx("button",{onClick:te,className:"px-3 py-2 rounded-lg text-sm text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Cancel"})]}),e.jsx(He,{steps:O,currentStep:H,completedSteps:Y}),e.jsxs("div",{className:"bg-cc-card border border-cc-border rounded-xl p-5 sm:p-7",children:[H===1&&e.jsx(Pe,{onNext:()=>I(2)}),H===2&&e.jsx(Ue,{onNext:c=>{G(c),I(3)},onBack:()=>I(1),selectedConnectionId:P}),H===3&&e.jsx(Fe,{onNext:v,onBack:()=>I(2),oauthConnectionId:P,existingAgent:$?{id:$.id,name:$.name,prompt:$.prompt,backendType:$.backendType,model:$.model,cwd:$.cwd}:void 0}),H===4&&e.jsx(_e,{agentName:le,onFinish:ie,onAddAnotherSameApp:pe,onAddAnotherNewApp:de})]})]})});const ve={all:d.length,linear:d.filter(c=>{var x,f;return(f=(x=c.triggers)==null?void 0:x.linear)==null?void 0:f.enabled}).length,scheduled:d.filter(c=>{var x,f;return(f=(x=c.triggers)==null?void 0:x.schedule)==null?void 0:f.enabled}).length,webhook:d.filter(c=>{var x,f;return(f=(x=c.triggers)==null?void 0:x.webhook)==null?void 0:f.enabled}).length},re=d.filter(c=>{var x,f,s,n,A,T;switch(R){case"linear":return((f=(x=c.triggers)==null?void 0:x.linear)==null?void 0:f.enabled)===!0;case"scheduled":return((n=(s=c.triggers)==null?void 0:s.schedule)==null?void 0:n.enabled)===!0;case"webhook":return((T=(A=c.triggers)==null?void 0:A.webhook)==null?void 0:T.enabled)===!0;default:return!0}});return e.jsxs("div",{className:"h-full overflow-y-auto bg-cc-bg",children:[e.jsxs("div",{className:"max-w-4xl mx-auto p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Agents"}),e.jsx("p",{className:"text-xs text-cc-muted mt-0.5",children:"Reusable autonomous session configs. Run manually, via webhook, or on a schedule."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{ref:o,type:"file",accept:".json",onChange:J,className:"hidden"}),e.jsx("button",{onClick:()=>{var c;return(c=o.current)==null?void 0:c.click()},className:"px-3 py-1.5 text-xs rounded-lg border border-cc-border text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Import"}),e.jsx("button",{onClick:oe,className:"px-3 py-1.5 text-xs rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors cursor-pointer",children:"+ New Agent"})]})]}),C&&e.jsx("div",{className:"mb-4 px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/30 text-cc-error text-xs",children:C}),e.jsx(De,{publicUrl:i}),!m&&d.length>0&&e.jsx("div",{className:"flex items-center gap-1 mb-4","data-testid":"filter-tabs",children:["all","linear","scheduled","webhook"].map(c=>e.jsxs("button",{onClick:()=>U(c),className:`text-xs px-2.5 py-1 rounded-full transition-colors cursor-pointer ${R===c?"bg-cc-fg text-cc-bg":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:[Te[c]," (",ve[c],")"]},c))}),m?e.jsx("div",{className:"text-sm text-cc-muted",children:"Loading..."}):d.length===0?e.jsxs("div",{className:"text-center py-16",children:[e.jsx("div",{className:"mb-3 flex justify-center text-cc-muted",children:e.jsx(he,{icon:"bot",className:"w-8 h-8"})}),e.jsx("p",{className:"text-sm text-cc-muted",children:"No agents yet"}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Create an agent to get started, or import a shared JSON config."})]}):re.length===0?e.jsx("div",{className:"text-center py-12",children:R==="linear"?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mb-3 flex justify-center text-cc-muted",children:e.jsx(ne,{className:"w-6 h-6"})}),e.jsx("p",{className:"text-sm text-cc-muted",children:"No Linear agents"}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Create a Linear agent to respond to @mentions in Linear issues."}),e.jsxs("button",{onClick:X,className:"mt-3 px-3 py-1.5 text-xs rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors cursor-pointer inline-flex items-center gap-1.5",children:[e.jsx(ne,{className:"w-3 h-3"}),"Setup Linear Agent"]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-sm text-cc-muted",children:["No ",Te[R].toLowerCase()," agents"]}),e.jsxs("p",{className:"text-xs text-cc-muted mt-1",children:[R==="scheduled"&&"Create an agent with a schedule trigger to see it here.",R==="webhook"&&"Create an agent with a webhook trigger to see it here."]})]})}):e.jsx("div",{className:"space-y-3",children:re.map(c=>e.jsx(Ge,{agent:c,publicUrl:i,onEdit:()=>Z(c),onDelete:()=>me(c.id),onToggle:()=>ge(c.id),onRun:()=>be(c),onExport:()=>fe(c),onCopyWebhook:()=>se(c),onRegenerateSecret:()=>ce(c.id),copiedWebhook:L},c.id))})]}),S&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>M(null),children:e.jsxs("div",{className:"bg-cc-card rounded-[14px] shadow-2xl p-6 w-full max-w-lg border border-cc-border",onClick:c=>c.stopPropagation(),children:[e.jsxs("h3",{className:"text-sm font-medium text-cc-fg mb-1",children:["Run ",S.name]}),e.jsxs("p",{className:"text-xs text-cc-muted mb-3",children:["This agent's prompt uses ","{{input}}"," — provide the input below."]}),e.jsx("textarea",{value:z,onChange:c=>w(c.target.value),placeholder:"Enter input for the agent...",className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm resize-none h-24 focus:outline-none focus:ring-1 focus:ring-cc-primary",autoFocus:!0}),e.jsxs("div",{className:"flex justify-end gap-2 mt-3",children:[e.jsx("button",{onClick:()=>M(null),className:"px-3 py-1.5 text-xs rounded-lg border border-cc-border text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{onClick:()=>ue(S,z),className:"px-3 py-1.5 text-xs rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors cursor-pointer",children:"Run"})]})]})})]})}export{tt as AgentsPage};