heyhank 0.1.0 → 0.3.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 (161) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +83 -10
  3. package/bin/cli.ts +7 -7
  4. package/bin/ctl.ts +42 -42
  5. package/dist/assets/{AgentsPage-BPhirnCe.js → AgentsPage-DqjDAcIw.js} +3 -3
  6. package/dist/assets/AssistantPage-C50CQFSB.js +2 -0
  7. package/dist/assets/BusinessPage-AY70tf1k.js +1 -0
  8. package/dist/assets/{CronManager-DDbz-yiT.js → CronManager-Dt7LLuRr.js} +1 -1
  9. package/dist/assets/HelpPage-tlGx7fQF.js +1 -0
  10. package/dist/assets/{IntegrationsPage-CrOitCmJ.js → IntegrationsPage-B4XOuHXu.js} +1 -1
  11. package/dist/assets/JarvisHUD-BDvuRd0I.js +120 -0
  12. package/dist/assets/MediaPage-CofV9Rd-.js +1 -0
  13. package/dist/assets/MemoryPage-Cj7FeqmJ.js +1 -0
  14. package/dist/assets/{PlatformDashboard-Do6F0O2p.js → PlatformDashboard-B9kXAlH1.js} +1 -1
  15. package/dist/assets/{Playground-Fc5cdc5p.js → Playground-Cka-pRkP.js} +1 -1
  16. package/dist/assets/{ProcessPanel-CslEiZkI.js → ProcessPanel-BqhQgfYj.js} +1 -1
  17. package/dist/assets/{PromptsPage-D2EhsdNO.js → PromptsPage-VveKc9uX.js} +2 -2
  18. package/dist/assets/RunsPage-DXVEk0AZ.js +1 -0
  19. package/dist/assets/{SandboxManager-a1AVI5q2.js → SandboxManager-DACcwfDF.js} +1 -1
  20. package/dist/assets/SettingsPage-jfuQh8Tu.js +51 -0
  21. package/dist/assets/SkillsMarketplace-DrigiApe.js +1 -0
  22. package/dist/assets/SocialMediaPage-DOh3IPe8.js +10 -0
  23. package/dist/assets/{TailscalePage-CHiFhZXF.js → TailscalePage-DLhJWATT.js} +1 -1
  24. package/dist/assets/TelephonyPage-9C4C3_ot.js +9 -0
  25. package/dist/assets/{TerminalPage-Drwyrnfd.js → TerminalPage-ChX-8Wu7.js} +1 -1
  26. package/dist/assets/{gemini-live-client-C7rqAW7G.js → gemini-live-client-C70FEtX2.js} +11 -8
  27. package/dist/assets/index-C6Q5UQHD.js +229 -0
  28. package/dist/assets/index-ZxGXgiV3.css +32 -0
  29. package/dist/assets/sw-register-BBYuk-kw.js +1 -0
  30. package/dist/assets/text-chat-client-BSbLJerZ.js +2 -0
  31. package/dist/assets/workbox-window.prod.es5-BBnX5xw4.js +2 -0
  32. package/dist/index.html +2 -2
  33. package/dist/sw.js +1 -1
  34. package/dist/{workbox-d2a0910a.js → workbox-080c8b91.js} +1 -1
  35. package/package.json +6 -1
  36. package/server/agent-executor.ts +102 -2
  37. package/server/agent-store.ts +3 -3
  38. package/server/agent-types.ts +11 -0
  39. package/server/assistant-store.ts +232 -6
  40. package/server/auth-manager.ts +9 -0
  41. package/server/cache-headers.ts +1 -1
  42. package/server/calendar-service.ts +10 -0
  43. package/server/ceo/document-store.ts +129 -0
  44. package/server/ceo/finance-store.ts +343 -0
  45. package/server/ceo/kpi-store.ts +208 -0
  46. package/server/ceo/memory-import.ts +277 -0
  47. package/server/ceo/news-store.ts +208 -0
  48. package/server/ceo/template-store.ts +134 -0
  49. package/server/ceo/time-tracking-store.ts +227 -0
  50. package/server/claude-auth-monitor.ts +128 -0
  51. package/server/claude-code-worker.ts +86 -0
  52. package/server/claude-session-discovery.ts +74 -1
  53. package/server/cli-launcher.ts +32 -10
  54. package/server/codex-adapter.ts +2 -2
  55. package/server/codex-ws-proxy.cjs +1 -1
  56. package/server/container-manager.ts +4 -4
  57. package/server/content-intelligence/content-engine.ts +1112 -0
  58. package/server/content-intelligence/platform-knowledge.ts +870 -0
  59. package/server/cron-store.ts +3 -3
  60. package/server/embedding-service.ts +49 -0
  61. package/server/event-bus-types.ts +13 -0
  62. package/server/execution-store.ts +54 -1
  63. package/server/federation/node-store.ts +5 -4
  64. package/server/fs-utils.ts +28 -1
  65. package/server/hank-notifications-store.ts +91 -0
  66. package/server/hank-tool-executor.ts +1835 -0
  67. package/server/hank-tools.ts +2107 -0
  68. package/server/image-pull-manager.ts +2 -2
  69. package/server/index.ts +25 -2
  70. package/server/llm-providers-streaming.ts +541 -0
  71. package/server/llm-providers.ts +12 -0
  72. package/server/marketplace.ts +249 -0
  73. package/server/mcp-registry.ts +158 -0
  74. package/server/memory-service.ts +296 -0
  75. package/server/obsidian-sync.ts +184 -0
  76. package/server/provider-manager.ts +5 -2
  77. package/server/provider-registry.ts +12 -0
  78. package/server/reminder-scheduler.ts +37 -1
  79. package/server/routes/agent-routes.ts +44 -1
  80. package/server/routes/assistant-routes.ts +198 -5
  81. package/server/routes/ceo-finance-kpi-routes.ts +167 -0
  82. package/server/routes/ceo-news-time-routes.ts +137 -0
  83. package/server/routes/ceo-routes.ts +99 -0
  84. package/server/routes/content-routes.ts +116 -0
  85. package/server/routes/email-routes.ts +147 -0
  86. package/server/routes/env-routes.ts +3 -3
  87. package/server/routes/fs-routes.ts +12 -9
  88. package/server/routes/hank-chat-routes.ts +592 -0
  89. package/server/routes/llm-routes.ts +12 -0
  90. package/server/routes/marketplace-routes.ts +63 -0
  91. package/server/routes/media-routes.ts +1 -1
  92. package/server/routes/memory-routes.ts +127 -0
  93. package/server/routes/platform-routes.ts +14 -675
  94. package/server/routes/sandbox-routes.ts +1 -1
  95. package/server/routes/settings-routes.ts +51 -1
  96. package/server/routes/socialmedia-routes.ts +152 -2
  97. package/server/routes/system-routes.ts +2 -2
  98. package/server/routes/team-routes.ts +71 -0
  99. package/server/routes/telephony-routes.ts +98 -18
  100. package/server/routes.ts +36 -9
  101. package/server/session-creation-service.ts +2 -2
  102. package/server/session-orchestrator.ts +54 -2
  103. package/server/session-types.ts +2 -0
  104. package/server/settings-manager.ts +50 -2
  105. package/server/skill-discovery.ts +68 -0
  106. package/server/socialmedia/adapters/browser-adapter.ts +179 -0
  107. package/server/socialmedia/adapters/postiz-adapter.ts +291 -14
  108. package/server/socialmedia/manager.ts +234 -15
  109. package/server/socialmedia/store.ts +51 -1
  110. package/server/socialmedia/types.ts +35 -2
  111. package/server/socialview/browser-manager.ts +150 -0
  112. package/server/socialview/extractors.ts +1298 -0
  113. package/server/socialview/image-describe.ts +188 -0
  114. package/server/socialview/library.ts +119 -0
  115. package/server/socialview/poster.ts +276 -0
  116. package/server/socialview/routes.ts +371 -0
  117. package/server/socialview/style-analyzer.ts +187 -0
  118. package/server/socialview/style-profiles.ts +67 -0
  119. package/server/socialview/types.ts +166 -0
  120. package/server/socialview/vision.ts +127 -0
  121. package/server/socialview/vnc-manager.ts +110 -0
  122. package/server/style-injector.ts +135 -0
  123. package/server/team-service.ts +239 -0
  124. package/server/team-store.ts +75 -0
  125. package/server/team-types.ts +52 -0
  126. package/server/telephony/audio-bridge.ts +281 -35
  127. package/server/telephony/audio-recorder.ts +132 -0
  128. package/server/telephony/call-manager.ts +803 -104
  129. package/server/telephony/call-types.ts +67 -1
  130. package/server/telephony/esl-client.ts +319 -0
  131. package/server/telephony/freeswitch-sync.ts +155 -0
  132. package/server/telephony/phone-utils.ts +63 -0
  133. package/server/telephony/telephony-store.ts +9 -8
  134. package/server/url-validator.ts +82 -0
  135. package/server/vault-markdown.ts +317 -0
  136. package/server/vault-migration.ts +121 -0
  137. package/server/vault-store.ts +466 -0
  138. package/server/vault-watcher.ts +59 -0
  139. package/server/vector-store.ts +210 -0
  140. package/server/voice-pipeline/gemini-live-adapter.ts +97 -0
  141. package/server/voice-pipeline/greeting-cache.ts +200 -0
  142. package/server/voice-pipeline/manager.ts +249 -0
  143. package/server/voice-pipeline/pipeline.ts +335 -0
  144. package/server/voice-pipeline/providers/index.ts +47 -0
  145. package/server/voice-pipeline/providers/llm-internal.ts +527 -0
  146. package/server/voice-pipeline/providers/stt-google.ts +157 -0
  147. package/server/voice-pipeline/providers/tts-google.ts +126 -0
  148. package/server/voice-pipeline/types.ts +247 -0
  149. package/server/ws-bridge-types.ts +6 -1
  150. package/dist/assets/AssistantPage-DJ-cMQfb.js +0 -1
  151. package/dist/assets/HelpPage-DMfkzERp.js +0 -1
  152. package/dist/assets/MediaPage-CE5rdvkC.js +0 -1
  153. package/dist/assets/RunsPage-C5BZF5Rx.js +0 -1
  154. package/dist/assets/SettingsPage-DirhjQrJ.js +0 -51
  155. package/dist/assets/SocialMediaPage-DBuM28vD.js +0 -1
  156. package/dist/assets/TelephonyPage-x0VV0fOo.js +0 -1
  157. package/dist/assets/index-C8M_PUmX.css +0 -32
  158. package/dist/assets/index-CEqZnThB.js +0 -204
  159. package/dist/assets/sw-register-LSSpj6RU.js +0 -1
  160. package/dist/assets/workbox-window.prod.es5-BIl4cyR9.js +0 -2
  161. package/server/socialmedia/adapters/ayrshare-adapter.ts +0 -169
@@ -1,7 +1,7 @@
1
- import{r as l,j as e,y as be,v as ve,w as je,z as ye,b as E,F as we,u as Ne}from"./index-CEqZnThB.js";import{t as pe}from"./time-ago-B6r_l9u1.js";const me="heyhank_public_url_dismissed";function ke({publicUrl:s}){const[o,x]=l.useState(()=>localStorage.getItem(me)==="1");return s||o?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 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(me,"1"),x(!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"})})})]})}const Ce=["bot","terminal","pencil","search","shield","chart","flask","rocket","wrench","clipboard","lightbulb","code","globe","zap","database","git-branch","mail","cpu"];function ae({icon:s,className:o="w-5 h-5"}){const n={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",className:`${o} shrink-0`,role:"img","aria-label":s||"bot"};switch(s){case"bot":return e.jsxs("svg",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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 s?e.jsx("span",{className:o,children:s}):e.jsxs("svg",{...n,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 Ae({agent:s,copiedWebhook:o,onEdit:x,onDelete:n,onToggle:h,onExport:S,onCopyWebhook:p,onRegenerateSecret:v}){var z,N;const[g,b]=l.useState(!1),a=l.useRef(null);l.useEffect(()=>{if(!g)return;function m(k){a.current&&!a.current.contains(k.target)&&b(!1)}return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[g]),l.useEffect(()=>{if(!g)return;function m(k){k.key==="Escape"&&b(!1)}return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[g]);const f=(N=(z=s.triggers)==null?void 0:z.webhook)==null?void 0:N.enabled;function w(m){b(!1),m()}return e.jsxs("div",{className:"relative",ref:a,children:[e.jsx("button",{onClick:()=>b(!g),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":g,"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"})]})}),g&&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:()=>w(x),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:()=>w(S),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"]}),f&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"my-1 border-t border-cc-border/40",role:"separator"}),e.jsxs("button",{onClick:()=>w(p),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"})]}),o===s.id?"Copied!":"Copy Webhook URL"]}),e.jsxs("button",{onClick:()=>w(v),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:()=>w(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.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:s.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"})}),s.enabled?"Disable":"Enable"]}),e.jsx("div",{className:"my-1 border-t border-cc-border/40",role:"separator"}),e.jsxs("button",{onClick:()=>w(n),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 Se(s,o){if(!o)return"One-time";const x=s.trim().split(/\s+/);if(x.length!==5)return s;const[n,h,,,S]=x;if(s==="* * * * *")return"Every minute";if(h==="*"&&n.startsWith("*/")){const p=parseInt(n.slice(2),10);return p===1?"Every minute":`Every ${p} minutes`}if(n==="0"&&h==="*")return"Every hour";if(n==="0"&&h.startsWith("*/")){const p=parseInt(h.slice(2),10);return p===1?"Every hour":`Every ${p} hours`}if(n!=="*"&&h!=="*"&&!h.includes("/")&&!h.includes(",")){const p=parseInt(h,10),v=parseInt(n,10);if(!isNaN(p)&&!isNaN(v)){const g=p>=12?"PM":"AM",b=p===0?12:p>12?p-12:p,a=v.toString().padStart(2,"0"),f=`${b}:${a} ${g}`;if(S==="*")return`Daily at ${f}`;if(S==="1-5")return`Weekdays at ${f}`}}return s}function Me(s,o){var n,h;return`${o||window.location.origin}/api/agents/${encodeURIComponent(s.id)}/webhook/${((h=(n=s.triggers)==null?void 0:n.webhook)==null?void 0:h.secret)||""}`}function Ee({agent:s,publicUrl:o,onEdit:x,onDelete:n,onToggle:h,onRun:S,onExport:p,onCopyWebhook:v,onRegenerateSecret:g,copiedWebhook:b}){var f,w,z,N;const a=["Manual"];return(w=(f=s.triggers)==null?void 0:f.webhook)!=null&&w.enabled&&a.push("Webhook"),(N=(z=s.triggers)==null?void 0:z.schedule)!=null&&N.enabled&&a.push(Se(s.triggers.schedule.expression,s.triggers.schedule.recurring)),e.jsxs("div",{className:`
1
+ import{r as l,j as e,J as be,E as ve,H as je,K as ye,b as E,F as we,u as Ne}from"./index-C6Q5UQHD.js";import{t as pe}from"./time-ago-B6r_l9u1.js";const me="heyhank_public_url_dismissed";function ke({publicUrl:s}){const[o,x]=l.useState(()=>localStorage.getItem(me)==="1");return s||o?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 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(me,"1"),x(!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"})})})]})}const Ce=["bot","terminal","pencil","search","shield","chart","flask","rocket","wrench","clipboard","lightbulb","code","globe","zap","database","git-branch","mail","cpu"];function ae({icon:s,className:o="w-5 h-5"}){const n={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",className:`${o} shrink-0`,role:"img","aria-label":s||"bot"};switch(s){case"bot":return e.jsxs("svg",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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",{...n,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 s?e.jsx("span",{className:o,children:s}):e.jsxs("svg",{...n,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 Ae({agent:s,copiedWebhook:o,onEdit:x,onDelete:n,onToggle:h,onExport:S,onCopyWebhook:p,onRegenerateSecret:v}){var z,N;const[g,b]=l.useState(!1),a=l.useRef(null);l.useEffect(()=>{if(!g)return;function m(k){a.current&&!a.current.contains(k.target)&&b(!1)}return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[g]),l.useEffect(()=>{if(!g)return;function m(k){k.key==="Escape"&&b(!1)}return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[g]);const f=(N=(z=s.triggers)==null?void 0:z.webhook)==null?void 0:N.enabled;function w(m){b(!1),m()}return e.jsxs("div",{className:"relative",ref:a,children:[e.jsx("button",{onClick:()=>b(!g),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":g,"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"})]})}),g&&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:()=>w(x),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:()=>w(S),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"]}),f&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"my-1 border-t border-cc-border/40",role:"separator"}),e.jsxs("button",{onClick:()=>w(p),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"})]}),o===s.id?"Copied!":"Copy Webhook URL"]}),e.jsxs("button",{onClick:()=>w(v),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:()=>w(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.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:s.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"})}),s.enabled?"Disable":"Enable"]}),e.jsx("div",{className:"my-1 border-t border-cc-border/40",role:"separator"}),e.jsxs("button",{onClick:()=>w(n),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 Se(s,o){if(!o)return"One-time";const x=s.trim().split(/\s+/);if(x.length!==5)return s;const[n,h,,,S]=x;if(s==="* * * * *")return"Every minute";if(h==="*"&&n.startsWith("*/")){const p=parseInt(n.slice(2),10);return p===1?"Every minute":`Every ${p} minutes`}if(n==="0"&&h==="*")return"Every hour";if(n==="0"&&h.startsWith("*/")){const p=parseInt(h.slice(2),10);return p===1?"Every hour":`Every ${p} hours`}if(n!=="*"&&h!=="*"&&!h.includes("/")&&!h.includes(",")){const p=parseInt(h,10),v=parseInt(n,10);if(!isNaN(p)&&!isNaN(v)){const g=p>=12?"PM":"AM",b=p===0?12:p>12?p-12:p,a=v.toString().padStart(2,"0"),f=`${b}:${a} ${g}`;if(S==="*")return`Daily at ${f}`;if(S==="1-5")return`Weekdays at ${f}`}}return s}function Me(s,o){var n,h;return`${o||window.location.origin}/api/agents/${encodeURIComponent(s.id)}/webhook/${((h=(n=s.triggers)==null?void 0:n.webhook)==null?void 0:h.secret)||""}`}function Ee({agent:s,publicUrl:o,onEdit:x,onDelete:n,onToggle:h,onRun:S,onExport:p,onCopyWebhook:v,onRegenerateSecret:g,copiedWebhook:b}){var f,w,z,N;const a=["Manual"];return(w=(f=s.triggers)==null?void 0:f.webhook)!=null&&w.enabled&&a.push("Webhook"),(N=(z=s.triggers)==null?void 0:z.schedule)!=null&&N.enabled&&a.push(Se(s.triggers.schedule.expression,s.triggers.schedule.recurring)),e.jsxs("div",{className:`
2
2
  group relative rounded-xl border bg-cc-card p-4
3
3
  transition-all duration-150
4
4
  ${s.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"}
5
- `,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:`${s.enabled?"text-cc-primary":"text-cc-muted"} transition-colors`,children:e.jsx(ae,{icon:s.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 ${s.enabled?"bg-cc-success":"bg-cc-muted/50"}`,title:s.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:s.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:s.backendType==="codex"?"Codex":"Claude"})]}),s.description&&e.jsx("p",{className:"text-xs text-cc-muted mt-0.5 truncate max-w-md",children:s.description})]})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsx("button",{onClick:S,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(Ae,{agent:s,copiedWebhook:b,onEdit:x,onDelete:n,onToggle:h,onExport:p,onCopyWebhook:v,onRegenerateSecret:g})]})]}),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:a.map((m,k)=>e.jsx("span",{className:"px-2 py-0.5 text-[10px] rounded-full bg-cc-hover text-cc-muted",children:m},k))}),e.jsxs("div",{className:"flex items-center gap-3 text-[10px] text-cc-muted",children:[s.totalRuns>0&&e.jsxs("span",{children:[s.totalRuns," run",s.totalRuns!==1?"s":""]}),s.lastRunAt&&e.jsxs("span",{children:["Last: ",pe(s.lastRunAt)]}),s.nextRunAt&&e.jsxs("span",{className:"text-cc-primary font-medium",children:["Next: ",pe(s.nextRunAt)]})]})]})]})}const ne={name:"",description:"",icon:"",backendType:"claude",model:ve("claude"),permissionMode:be("claude"),cwd:"",prompt:"",envSlug:"",env:[],codexInternetAccess:!1,branch:"",createBranch:!1,useWorktree:!1,mcpServers:{},skills:[],allowedTools:[],webhookEnabled:!1,scheduleEnabled:!1,scheduleExpression:"0 8 * * *",scheduleRecurring:!0},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 xe(s){let o=0;return Object.keys(s.mcpServers).length>0&&o++,s.skills.length>0&&o++,s.allowedTools.length>0&&o++,s.env.length>0&&o++,o}function Re({form:s,setForm:o,editingId:x,publicUrl:n,error:h,saving:S,onSave:p,onCancel:v}){const g=je(s.backendType),b=ye(s.backendType),[a,f]=l.useState(!1),[w,z]=l.useState(()=>xe(s)>0),[N,m]=l.useState(!1),[k,H]=l.useState(""),[y,R]=l.useState({type:"stdio",command:"",args:"",url:"",env:""}),[Q,Z]=l.useState([]),[L,le]=l.useState([]),[T,M]=l.useState(""),[P,V]=l.useState(!1),[$,O]=l.useState(!1),[U,B]=l.useState(!1),[oe,W]=l.useState(!!s.branch),[X,F]=l.useState(!1),_=l.useRef(null),Y=l.useRef(null),J=l.useRef(null),G=l.useRef(null);l.useEffect(()=>{E.listSkills().then(Z).catch(()=>{}),E.listEnvs().then(le).catch(()=>{})},[]);function d(t,r){o(A=>({...A,[t]:r}))}function c(t){o(r=>({...r,backendType:t,model:ve(t),permissionMode:be(t)}))}function i(){o(t=>({...t,env:[...t.env,{key:"",value:""}]}))}function u(t,r,A){o(re=>{const de=[...re.env];return de[t]={...de[t],[r]:A},{...re,env:de}})}function j(t){o(r=>({...r,env:r.env.filter((A,re)=>re!==t)}))}function C(){if(!k.trim())return;const t={type:y.type};if(y.type==="stdio"?(t.command=y.command,t.args=y.args?y.args.split(" ").filter(Boolean):void 0):t.url=y.url,y.env.trim())try{t.env=JSON.parse(y.env)}catch{}o(r=>({...r,mcpServers:{...r.mcpServers,[k.trim()]:t}})),H(""),R({type:"stdio",command:"",args:"",url:"",env:""}),m(!1)}function ee(t){o(r=>{const A={...r.mcpServers};return delete A[t],{...r,mcpServers:A}})}function te(t){o(r=>({...r,skills:r.skills.includes(t)?r.skills.filter(A=>A!==t):[...r.skills,t]}))}function se(t){if(t.key==="Enter"&&T.trim()){t.preventDefault();const r=T.trim();s.allowedTools.includes(r)||d("allowedTools",[...s.allowedTools,r]),M("")}}function ce(t){d("allowedTools",s.allowedTools.filter(r=>r!==t))}l.useEffect(()=>{function t(r){Y.current&&!Y.current.contains(r.target)&&V(!1),J.current&&!J.current.contains(r.target)&&O(!1),G.current&&!G.current.contains(r.target)&&B(!1),_.current&&!_.current.contains(r.target)&&F(!1)}return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[]);const D=g.find(t=>t.value===s.model)||g[0],K=b.find(t=>t.value===s.permissionMode)||b[0],ie=L.find(t=>t.slug===s.envSlug),fe=s.cwd?s.cwd.split("/").pop()||s.cwd:"temp",ue=n||(typeof window<"u"?window.location.origin:""),he="flex items-center gap-1.5 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer",I=`${he} text-cc-muted hover:text-cc-fg hover:bg-cc-hover`,q=`${he} 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:v,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:x?"Edit Agent":"New Agent"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:v,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:p,disabled:S||!s.name.trim()||!s.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:S?"Saving...":x?"Save":"Create"})]})]}),h&&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:h}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex gap-3 items-start",children:[e.jsxs("div",{ref:_,className:"relative flex-shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>F(!X),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(ae,{icon:s.icon||"bot",className:"w-5 h-5"})}),X&&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:Ce.map(t=>e.jsx("button",{type:"button",onClick:()=>{d("icon",t),F(!1)},className:`w-8 h-8 rounded-md flex items-center justify-center transition-colors ${s.icon===t?"bg-cc-primary/20 ring-1 ring-cc-primary":"hover:bg-cc-hover"}`,title:t,children:e.jsx(ae,{icon:t,className:"w-4 h-4 text-cc-fg"})},t))})]}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("input",{value:s.name,onChange:t=>d("name",t.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:s.description,onChange:t=>d("description",t.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:s.prompt,onChange:t=>d("prompt",t.target.value),placeholder:`System prompt *
5
+ `,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:`${s.enabled?"text-cc-primary":"text-cc-muted"} transition-colors`,children:e.jsx(ae,{icon:s.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 ${s.enabled?"bg-cc-success":"bg-cc-muted/50"}`,title:s.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:s.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:s.backendType==="codex"?"Codex":"Claude"})]}),s.description&&e.jsx("p",{className:"text-xs text-cc-muted mt-0.5 truncate max-w-md",children:s.description})]})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsx("button",{onClick:S,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(Ae,{agent:s,copiedWebhook:b,onEdit:x,onDelete:n,onToggle:h,onExport:p,onCopyWebhook:v,onRegenerateSecret:g})]})]}),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:a.map((m,k)=>e.jsx("span",{className:"px-2 py-0.5 text-[10px] rounded-full bg-cc-hover text-cc-muted",children:m},k))}),e.jsxs("div",{className:"flex items-center gap-3 text-[10px] text-cc-muted",children:[s.totalRuns>0&&e.jsxs("span",{children:[s.totalRuns," run",s.totalRuns!==1?"s":""]}),s.lastRunAt&&e.jsxs("span",{children:["Last: ",pe(s.lastRunAt)]}),s.nextRunAt&&e.jsxs("span",{className:"text-cc-primary font-medium",children:["Next: ",pe(s.nextRunAt)]})]})]})]})}const ne={name:"",description:"",icon:"",backendType:"claude",model:ve("claude"),permissionMode:be("claude"),cwd:"",prompt:"",envSlug:"",env:[],codexInternetAccess:!1,branch:"",createBranch:!1,useWorktree:!1,mcpServers:{},skills:[],allowedTools:[],webhookEnabled:!1,scheduleEnabled:!1,scheduleExpression:"0 8 * * *",scheduleRecurring:!0},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 xe(s){let o=0;return Object.keys(s.mcpServers).length>0&&o++,s.skills.length>0&&o++,s.allowedTools.length>0&&o++,s.env.length>0&&o++,o}function Re({form:s,setForm:o,editingId:x,publicUrl:n,error:h,saving:S,onSave:p,onCancel:v}){const g=je(s.backendType),b=ye(s.backendType),[a,f]=l.useState(!1),[w,z]=l.useState(()=>xe(s)>0),[N,m]=l.useState(!1),[k,H]=l.useState(""),[y,R]=l.useState({type:"stdio",command:"",args:"",url:"",env:""}),[Q,Z]=l.useState([]),[L,le]=l.useState([]),[T,M]=l.useState(""),[P,V]=l.useState(!1),[$,O]=l.useState(!1),[U,B]=l.useState(!1),[oe,W]=l.useState(!!s.branch),[X,F]=l.useState(!1),_=l.useRef(null),Y=l.useRef(null),J=l.useRef(null),K=l.useRef(null);l.useEffect(()=>{E.listSkills().then(Z).catch(()=>{}),E.listEnvs().then(le).catch(()=>{})},[]);function d(t,r){o(A=>({...A,[t]:r}))}function c(t){o(r=>({...r,backendType:t,model:ve(t),permissionMode:be(t)}))}function i(){o(t=>({...t,env:[...t.env,{key:"",value:""}]}))}function u(t,r,A){o(re=>{const de=[...re.env];return de[t]={...de[t],[r]:A},{...re,env:de}})}function j(t){o(r=>({...r,env:r.env.filter((A,re)=>re!==t)}))}function C(){if(!k.trim())return;const t={type:y.type};if(y.type==="stdio"?(t.command=y.command,t.args=y.args?y.args.split(" ").filter(Boolean):void 0):t.url=y.url,y.env.trim())try{t.env=JSON.parse(y.env)}catch{}o(r=>({...r,mcpServers:{...r.mcpServers,[k.trim()]:t}})),H(""),R({type:"stdio",command:"",args:"",url:"",env:""}),m(!1)}function ee(t){o(r=>{const A={...r.mcpServers};return delete A[t],{...r,mcpServers:A}})}function te(t){o(r=>({...r,skills:r.skills.includes(t)?r.skills.filter(A=>A!==t):[...r.skills,t]}))}function se(t){if(t.key==="Enter"&&T.trim()){t.preventDefault();const r=T.trim();s.allowedTools.includes(r)||d("allowedTools",[...s.allowedTools,r]),M("")}}function ce(t){d("allowedTools",s.allowedTools.filter(r=>r!==t))}l.useEffect(()=>{function t(r){Y.current&&!Y.current.contains(r.target)&&V(!1),J.current&&!J.current.contains(r.target)&&O(!1),K.current&&!K.current.contains(r.target)&&B(!1),_.current&&!_.current.contains(r.target)&&F(!1)}return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[]);const D=g.find(t=>t.value===s.model)||g[0],G=b.find(t=>t.value===s.permissionMode)||b[0],ie=L.find(t=>t.slug===s.envSlug),fe=s.cwd?s.cwd.split("/").pop()||s.cwd:"temp",ue=n||(typeof window<"u"?window.location.origin:""),he="flex items-center gap-1.5 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer",I=`${he} text-cc-muted hover:text-cc-fg hover:bg-cc-hover`,q=`${he} 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:v,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:x?"Edit Agent":"New Agent"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:v,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:p,disabled:S||!s.name.trim()||!s.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:S?"Saving...":x?"Save":"Create"})]})]}),h&&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:h}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex gap-3 items-start",children:[e.jsxs("div",{ref:_,className:"relative flex-shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>F(!X),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(ae,{icon:s.icon||"bot",className:"w-5 h-5"})}),X&&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:Ce.map(t=>e.jsx("button",{type:"button",onClick:()=>{d("icon",t),F(!1)},className:`w-8 h-8 rounded-md flex items-center justify-center transition-colors ${s.icon===t?"bg-cc-primary/20 ring-1 ring-cc-primary":"hover:bg-cc-hover"}`,title:t,children:e.jsx(ae,{icon:t,className:"w-4 h-4 text-cc-fg"})},t))})]}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("input",{value:s.name,onChange:t=>d("name",t.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:s.description,onChange:t=>d("description",t.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:s.prompt,onChange:t=>d("prompt",t.target.value),placeholder:`System prompt *
6
6
  Write the agent's instructions here.
7
- 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:()=>c("claude"),className:`flex items-center gap-1 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer ${s.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:()=>c("codex"),className:`flex items-center gap-1 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer ${s.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:Y,children:[e.jsxs("button",{onClick:()=>{V(!P),O(!1),B(!1)},"aria-expanded":P,className:I,children:[e.jsx("span",{children:D==null?void 0:D.icon}),e.jsx("span",{children:D==null?void 0:D.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"})})]}),P&&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:g.map(t=>e.jsxs("button",{onClick:()=>{d("model",t.value),V(!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 ${t.value===s.model?"text-cc-primary font-medium":"text-cc-fg"}`,children:[e.jsx("span",{children:t.icon}),t.label]},t.value))})]}),e.jsxs("div",{className:"relative",ref:J,children:[e.jsxs("button",{onClick:()=>{O(!$),V(!1),B(!1)},"aria-expanded":$,className:I,children:[e.jsx("span",{children:K==null?void 0:K.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:b.map(t=>e.jsx("button",{onClick:()=>{d("permissionMode",t.value),O(!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 ${t.value===s.permissionMode?"text-cc-primary font-medium":"text-cc-fg"}`,children:t.label},t.value))})]}),e.jsxs("button",{onClick:()=>f(!0),className:s.cwd?q:I,title:s.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:fe}),s.cwd&&e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50 hover:opacity-100",onClick:t=>{t.stopPropagation(),d("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"})})]}),s.cwd&&(oe?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:s.branch,onChange:t=>d("branch",t.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:()=>{s.branch||W(!1)}}),s.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:s.createBranch,onChange:t=>d("createBranch",t.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:s.useWorktree,onChange:t=>d("useWorktree",t.target.checked),className:"rounded w-3 h-3"}),"worktree"]})]})]}):e.jsxs("button",{onClick:()=>W(!0),className:I,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:G,children:[e.jsxs("button",{onClick:()=>{B(!U),V(!1),O(!1)},"aria-expanded":U,className:s.envSlug?q:I,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:(ie==null?void 0:ie.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"})})]}),U&&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:()=>{d("envSlug",""),B(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer ${s.envSlug?"text-cc-fg":"text-cc-primary font-medium"}`,children:"None"}),L.map(t=>e.jsx("button",{onClick:()=>{d("envSlug",t.slug),B(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer ${s.envSlug===t.slug?"text-cc-primary font-medium":"text-cc-fg"}`,children:t.name},t.slug))]})]}),s.backendType==="codex"&&e.jsxs("button",{onClick:()=>d("codexInternetAccess",!s.codexInternetAccess),className:s.codexInternetAccess?q:I,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"})]})]}),a&&e.jsx(we,{initialPath:s.cwd||"",onSelect:t=>{d("cwd",t),f(!1)},onClose:()=>f(!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:()=>d("webhookEnabled",!s.webhookEnabled),className:s.webhookEnabled?q:I,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:()=>d("scheduleEnabled",!s.scheduleEnabled),className:s.scheduleEnabled?q:I,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"]})]}),s.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": "..."}'}),"."]}),ue&&e.jsxs("p",{className:"text-[10px] text-cc-muted",children:["Base URL: ",e.jsx("span",{className:"font-mono-code",children:ue})]})]}),s.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:s.scheduleRecurring,onChange:()=>d("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:!s.scheduleRecurring,onChange:()=>d("scheduleRecurring",!1)}),"One-time"]})]}),s.scheduleRecurring?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex flex-wrap gap-1",children:ze.map(t=>e.jsx("button",{onClick:()=>d("scheduleExpression",t.value),className:`px-2 py-1 text-[10px] rounded-lg border transition-colors cursor-pointer ${s.scheduleExpression===t.value?"border-cc-primary text-cc-primary":"border-cc-border text-cc-muted hover:text-cc-fg"}`,children:t.label},t.value))}),e.jsx("input",{value:s.scheduleExpression,onChange:t=>d("scheduleExpression",t.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:s.scheduleExpression,onChange:t=>d("scheduleExpression",t.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("section",{children:[e.jsxs("button",{onClick:()=>z(!w),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 ${w?"rotate-90":""}`,children:e.jsx("path",{d:"M6 3l5 5-5 5V3z"})}),"Advanced",xe(s)>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:xe(s)})]}),w&&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:()=>m(!N),className:"text-[10px] text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:N?"Cancel":"+ Add Server"})]}),Object.keys(s.mcpServers).length===0&&!N&&e.jsx("p",{className:"text-[10px] text-cc-muted",children:"No MCP servers configured."}),Object.entries(s.mcpServers).map(([t,r])=>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:t}),e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] rounded bg-cc-border text-cc-muted",children:r.type})]}),e.jsx("button",{onClick:()=>ee(t),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"})})})]},t)),N&&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:k,onChange:t=>H(t.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(t=>e.jsx("button",{onClick:()=>R(r=>({...r,type:t})),className:`flex-1 px-2 py-1 text-[10px] transition-colors cursor-pointer ${y.type===t?"bg-cc-primary text-white":"bg-cc-input-bg text-cc-muted hover:text-cc-fg"}`,children:t},t))})]}),y.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:y.command,onChange:t=>R(r=>({...r,command:t.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:y.args,onChange:t=>R(r=>({...r,args:t.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:y.url,onChange:t=>R(r=>({...r,url:t.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:C,disabled:!k.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"}),Q.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:Q.map(t=>e.jsxs("label",{className:"flex items-start gap-2 text-sm text-cc-fg cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:s.skills.includes(t.slug),onChange:()=>te(t.slug),className:"rounded mt-0.5"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs",children:t.name}),t.description&&e.jsx("p",{className:"text-[10px] text-cc-muted",children:t.description})]})]},t.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:[s.allowedTools.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.allowedTools.map(t=>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:[t,e.jsx("button",{onClick:()=>ce(t),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"})})})]},t))}),e.jsx("input",{value:T,onChange:t=>M(t.target.value),onKeyDown:se,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:i,className:"text-[10px] text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"+ Add Variable"})]}),s.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:s.env.map((t,r)=>e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("input",{value:t.key,onChange:A=>u(r,"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:t.value,onChange:A=>u(r,"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:()=>j(r),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"})})})]},r))})]})]})]})]})]})})}const ge={all:"All",scheduled:"Scheduled",webhook:"Webhook"};function Ie({route:s}){const o=Ne(c=>c.publicUrl),[x,n]=l.useState([]),[h,S]=l.useState(!0),[p,v]=l.useState("list"),[g,b]=l.useState(null),[a,f]=l.useState(ne),[w,z]=l.useState(!1),[N,m]=l.useState(""),[k,H]=l.useState(null),[y,R]=l.useState(""),[Q,Z]=l.useState(null),[L,le]=l.useState("all"),T=l.useRef(null),M=l.useCallback(async()=>{try{const c=await E.listAgents();n(c)}catch{}finally{S(!1)}},[]);l.useEffect(()=>{M()},[M]),l.useEffect(()=>{if(s.page==="agent-detail"&&"agentId"in s){const c=x.find(i=>i.id===s.agentId);c&&$(c)}},[s,x]);function P(){b(null),f(ne),m(""),v("pick-template")}function V(c){b(null),f(c),m(""),v("edit")}function $(c){var i,u,j,C,ee,te,se,ce;b(c.id),f({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(([D,K])=>({key:D,value:K})):[],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:((u=(i=c.triggers)==null?void 0:i.webhook)==null?void 0:u.enabled)??!1,scheduleEnabled:((C=(j=c.triggers)==null?void 0:j.schedule)==null?void 0:C.enabled)??!1,scheduleExpression:((te=(ee=c.triggers)==null?void 0:ee.schedule)==null?void 0:te.expression)||"0 8 * * *",scheduleRecurring:((ce=(se=c.triggers)==null?void 0:se.schedule)==null?void 0:ce.recurring)??!0}),m(""),v("edit")}function O(){v("list"),b(null),m(""),window.location.hash="#/agents"}async function U(){z(!0),m("");try{const c={};for(const{key:u,value:j}of a.env)u.trim()&&(c[u.trim()]=j);const i={version:1,name:a.name,description:a.description,icon:a.icon||void 0,backendType:a.backendType,model:a.model,permissionMode:a.permissionMode,cwd:a.cwd||"temp",prompt:a.prompt,envSlug:a.envSlug||void 0,env:Object.keys(c).length>0?c:void 0,codexInternetAccess:a.backendType==="codex"?a.codexInternetAccess:void 0,branch:a.branch||void 0,createBranch:a.branch?a.createBranch:void 0,useWorktree:a.branch?a.useWorktree:void 0,mcpServers:Object.keys(a.mcpServers).length>0?a.mcpServers:void 0,skills:a.skills.length>0?a.skills:void 0,allowedTools:a.allowedTools.length>0?a.allowedTools:void 0,enabled:!0,triggers:{webhook:{enabled:a.webhookEnabled,secret:""},schedule:{enabled:a.scheduleEnabled,expression:a.scheduleExpression,recurring:a.scheduleRecurring}}};g?await E.updateAgent(g,i):await E.createAgent(i),await M(),v("list"),b(null),window.location.hash="#/agents"}catch(c){m(c instanceof Error?c.message:String(c))}finally{z(!1)}}async function B(c){if(confirm("Delete this agent?"))try{await E.deleteAgent(c),await M()}catch{}}async function oe(c){try{await E.toggleAgent(c),await M()}catch{}}async function W(c,i){try{await E.runAgent(c.id,i),H(null),R(""),await M()}catch{}}function X(c){c.prompt.includes("{{input}}")?(H(c),R("")):W(c)}async function F(c){try{const i=await E.exportAgent(c.id),u=new Blob([JSON.stringify(i,null,2)],{type:"application/json"}),j=URL.createObjectURL(u),C=document.createElement("a");C.href=j,C.download=`${c.id}.agent.json`,C.click(),URL.revokeObjectURL(j)}catch{}}async function _(c){var u;const i=(u=c.target.files)==null?void 0:u[0];if(i){try{const j=await i.text(),C=JSON.parse(j);await E.importAgent(C),await M()}catch(j){m(j instanceof Error?j.message:"Failed to import agent")}T.current&&(T.current.value="")}}function Y(c){const i=Me(c,o);navigator.clipboard.writeText(i).then(()=>{Z(c.id),setTimeout(()=>Z(null),2e3)})}async function J(c){if(confirm("Regenerate webhook secret? The old URL will stop working."))try{await E.regenerateAgentWebhookSecret(c),await M()}catch{}}if(p==="pick-template")return e.jsx(Te,{onSelect:V,onBlank:()=>{f(ne),v("edit")},onCancel:()=>v("list")});if(p==="edit")return e.jsx(Re,{form:a,setForm:f,editingId:g,publicUrl:o,error:N,saving:w,onSave:U,onCancel:O});const G={all:x.length,scheduled:x.filter(c=>{var i,u;return(u=(i=c.triggers)==null?void 0:i.schedule)==null?void 0:u.enabled}).length,webhook:x.filter(c=>{var i,u;return(u=(i=c.triggers)==null?void 0:i.webhook)==null?void 0:u.enabled}).length},d=x.filter(c=>{var i,u,j,C;switch(L){case"scheduled":return((u=(i=c.triggers)==null?void 0:i.schedule)==null?void 0:u.enabled)===!0;case"webhook":return((C=(j=c.triggers)==null?void 0:j.webhook)==null?void 0:C.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:T,type:"file",accept:".json",onChange:_,className:"hidden"}),e.jsx("button",{onClick:()=>{var c;return(c=T.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:P,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"})]})]}),N&&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:N}),e.jsx(ke,{publicUrl:o}),!h&&x.length>0&&e.jsx("div",{className:"flex items-center gap-1 mb-4","data-testid":"filter-tabs",children:["all","scheduled","webhook"].map(c=>e.jsxs("button",{onClick:()=>le(c),className:`text-xs px-2.5 py-1 rounded-full transition-colors cursor-pointer ${L===c?"bg-cc-fg text-cc-bg":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:[ge[c]," (",G[c],")"]},c))}),h?e.jsx("div",{className:"text-sm text-cc-muted",children:"Loading..."}):x.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(ae,{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."})]}):d.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsxs("p",{className:"text-sm text-cc-muted",children:["No ",ge[L].toLowerCase()," agents"]}),e.jsxs("p",{className:"text-xs text-cc-muted mt-1",children:[L==="scheduled"&&"Create an agent with a schedule trigger to see it here.",L==="webhook"&&"Create an agent with a webhook trigger to see it here."]})]}):e.jsx("div",{className:"space-y-3",children:d.map(c=>e.jsx(Ee,{agent:c,publicUrl:o,onEdit:()=>$(c),onDelete:()=>B(c.id),onToggle:()=>oe(c.id),onRun:()=>X(c),onExport:()=>F(c),onCopyWebhook:()=>Y(c),onRegenerateSecret:()=>J(c.id),copiedWebhook:Q},c.id))})]}),k&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>H(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 ",k.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:y,onChange:c=>R(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:()=>H(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:()=>W(k,y),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"})]})]})})]})}const Le=[{name:"Coding Agent",icon:"code",description:"Develops features, fixes bugs, writes tests. Full file and terminal access.",color:"text-blue-400",form:{name:"Coding Agent",description:"Develops features, fixes bugs, writes tests",icon:"code",prompt:"You are a coding agent. Help the user with software development tasks: writing code, fixing bugs, refactoring, writing tests, and code reviews. Be thorough and follow best practices.",permissionMode:"acceptEdits"}},{name:"Monitoring Agent",icon:"activity",description:"Checks server health: CPU, RAM, disk, Docker, PM2. Great for cron schedules.",color:"text-green-400",form:{name:"Monitoring Agent",description:"Checks server health and reports issues",icon:"activity",prompt:"You are a monitoring agent. Check server health: CPU usage, RAM, disk space, running processes (PM2, Docker), and network status. Report any issues found. Be concise and actionable.",permissionMode:"plan"}},{name:"Content Agent",icon:"pen-tool",description:"Creates social media posts, generates images and videos via Gemini.",color:"text-pink-400",form:{name:"Content Agent",description:"Creates social media content, images, and videos",icon:"pen-tool",prompt:"You are a content creation agent. Help create social media posts, marketing copy, blog articles, and visual content. You can generate images with Imagen and videos with Veo. Be creative and on-brand."}},{name:"Research Agent",icon:"search",description:"Researches topics, summarizes findings, gathers competitive intelligence.",color:"text-purple-400",form:{name:"Research Agent",description:"Researches topics and summarizes findings",icon:"search",prompt:"You are a research agent. Help the user research topics thoroughly: gather information, analyze data, compare options, and provide well-structured summaries with sources. Be objective and comprehensive."}},{name:"DevOps Agent",icon:"server",description:"Manages deployments, CI/CD, Docker, Nginx, SSL certificates.",color:"text-orange-400",form:{name:"DevOps Agent",description:"Manages deployments, infrastructure, and CI/CD",icon:"server",prompt:"You are a DevOps agent. Help with server management, deployments, CI/CD pipelines, Docker, Nginx configuration, SSL certificates, and infrastructure automation. Prioritize security and reliability.",permissionMode:"acceptEdits"}},{name:"Data Agent",icon:"database",description:"Analyzes data, writes SQL queries, creates reports and visualizations.",color:"text-yellow-400",form:{name:"Data Agent",description:"Analyzes data and creates reports",icon:"database",prompt:"You are a data analysis agent. Help with SQL queries, data analysis, creating reports, and data visualization. Be precise with numbers and provide clear insights."}}];function Te({onSelect:s,onBlank:o,onCancel:x}){return e.jsx("div",{className:"h-full overflow-auto",children:e.jsxs("div",{className:"mx-auto max-w-3xl px-6 py-8",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-bold text-cc-fg",children:"New Agent"}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Start from a template or create from scratch."})]}),e.jsx("button",{onClick:x,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",children:"Cancel"})]}),e.jsx("button",{onClick:o,className:"w-full mb-4 p-4 rounded-xl border-2 border-dashed border-cc-border hover:border-cc-primary/50 bg-cc-card hover:bg-cc-hover transition-colors text-left group",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-cc-hover flex items-center justify-center text-cc-muted group-hover:text-cc-fg",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"w-5 h-5",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-cc-fg",children:"Blank Agent"}),e.jsx("div",{className:"text-xs text-cc-muted",children:"Start with an empty configuration"})]})]})}),e.jsx("h2",{className:"text-xs font-semibold text-cc-muted uppercase tracking-wider mb-3",children:"Templates"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Le.map(n=>e.jsxs("button",{onClick:()=>s({...ne,...n.form}),className:"p-4 rounded-xl border border-cc-border bg-cc-card hover:bg-cc-hover hover:border-cc-primary/30 transition-colors text-left",children:[e.jsx("div",{className:`text-sm font-medium ${n.color}`,children:n.name}),e.jsx("div",{className:"text-xs text-cc-muted mt-1 line-clamp-2",children:n.description})]},n.name))})]})})}export{Ie as AgentsPage};
7
+ 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:()=>c("claude"),className:`flex items-center gap-1 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer ${s.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:()=>c("codex"),className:`flex items-center gap-1 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer ${s.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:Y,children:[e.jsxs("button",{onClick:()=>{V(!P),O(!1),B(!1)},"aria-expanded":P,className:I,children:[e.jsx("span",{children:D==null?void 0:D.icon}),e.jsx("span",{children:D==null?void 0:D.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"})})]}),P&&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:g.map(t=>e.jsxs("button",{onClick:()=>{d("model",t.value),V(!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 ${t.value===s.model?"text-cc-primary font-medium":"text-cc-fg"}`,children:[e.jsx("span",{children:t.icon}),t.label]},t.value))})]}),e.jsxs("div",{className:"relative",ref:J,children:[e.jsxs("button",{onClick:()=>{O(!$),V(!1),B(!1)},"aria-expanded":$,className:I,children:[e.jsx("span",{children:G==null?void 0:G.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:b.map(t=>e.jsx("button",{onClick:()=>{d("permissionMode",t.value),O(!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 ${t.value===s.permissionMode?"text-cc-primary font-medium":"text-cc-fg"}`,children:t.label},t.value))})]}),e.jsxs("button",{onClick:()=>f(!0),className:s.cwd?q:I,title:s.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:fe}),s.cwd&&e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50 hover:opacity-100",onClick:t=>{t.stopPropagation(),d("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"})})]}),s.cwd&&(oe?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:s.branch,onChange:t=>d("branch",t.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:()=>{s.branch||W(!1)}}),s.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:s.createBranch,onChange:t=>d("createBranch",t.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:s.useWorktree,onChange:t=>d("useWorktree",t.target.checked),className:"rounded w-3 h-3"}),"worktree"]})]})]}):e.jsxs("button",{onClick:()=>W(!0),className:I,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:K,children:[e.jsxs("button",{onClick:()=>{B(!U),V(!1),O(!1)},"aria-expanded":U,className:s.envSlug?q:I,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:(ie==null?void 0:ie.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"})})]}),U&&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:()=>{d("envSlug",""),B(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer ${s.envSlug?"text-cc-fg":"text-cc-primary font-medium"}`,children:"None"}),L.map(t=>e.jsx("button",{onClick:()=>{d("envSlug",t.slug),B(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer ${s.envSlug===t.slug?"text-cc-primary font-medium":"text-cc-fg"}`,children:t.name},t.slug))]})]}),s.backendType==="codex"&&e.jsxs("button",{onClick:()=>d("codexInternetAccess",!s.codexInternetAccess),className:s.codexInternetAccess?q:I,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"})]})]}),a&&e.jsx(we,{initialPath:s.cwd||"",onSelect:t=>{d("cwd",t),f(!1)},onClose:()=>f(!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:()=>d("webhookEnabled",!s.webhookEnabled),className:s.webhookEnabled?q:I,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:()=>d("scheduleEnabled",!s.scheduleEnabled),className:s.scheduleEnabled?q:I,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"]})]}),s.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": "..."}'}),"."]}),ue&&e.jsxs("p",{className:"text-[10px] text-cc-muted",children:["Base URL: ",e.jsx("span",{className:"font-mono-code",children:ue})]})]}),s.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:s.scheduleRecurring,onChange:()=>d("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:!s.scheduleRecurring,onChange:()=>d("scheduleRecurring",!1)}),"One-time"]})]}),s.scheduleRecurring?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex flex-wrap gap-1",children:ze.map(t=>e.jsx("button",{onClick:()=>d("scheduleExpression",t.value),className:`px-2 py-1 text-[10px] rounded-lg border transition-colors cursor-pointer ${s.scheduleExpression===t.value?"border-cc-primary text-cc-primary":"border-cc-border text-cc-muted hover:text-cc-fg"}`,children:t.label},t.value))}),e.jsx("input",{value:s.scheduleExpression,onChange:t=>d("scheduleExpression",t.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:s.scheduleExpression,onChange:t=>d("scheduleExpression",t.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("section",{children:[e.jsxs("button",{onClick:()=>z(!w),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 ${w?"rotate-90":""}`,children:e.jsx("path",{d:"M6 3l5 5-5 5V3z"})}),"Advanced",xe(s)>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:xe(s)})]}),w&&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:()=>m(!N),className:"text-[10px] text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:N?"Cancel":"+ Add Server"})]}),Object.keys(s.mcpServers).length===0&&!N&&e.jsx("p",{className:"text-[10px] text-cc-muted",children:"No MCP servers configured."}),Object.entries(s.mcpServers).map(([t,r])=>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:t}),e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] rounded bg-cc-border text-cc-muted",children:r.type})]}),e.jsx("button",{onClick:()=>ee(t),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"})})})]},t)),N&&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:k,onChange:t=>H(t.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(t=>e.jsx("button",{onClick:()=>R(r=>({...r,type:t})),className:`flex-1 px-2 py-1 text-[10px] transition-colors cursor-pointer ${y.type===t?"bg-cc-primary text-white":"bg-cc-input-bg text-cc-muted hover:text-cc-fg"}`,children:t},t))})]}),y.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:y.command,onChange:t=>R(r=>({...r,command:t.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:y.args,onChange:t=>R(r=>({...r,args:t.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:y.url,onChange:t=>R(r=>({...r,url:t.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:C,disabled:!k.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"}),Q.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:Q.map(t=>e.jsxs("label",{className:"flex items-start gap-2 text-sm text-cc-fg cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:s.skills.includes(t.slug),onChange:()=>te(t.slug),className:"rounded mt-0.5"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs",children:t.name}),t.description&&e.jsx("p",{className:"text-[10px] text-cc-muted",children:t.description})]})]},t.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:[s.allowedTools.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.allowedTools.map(t=>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:[t,e.jsx("button",{onClick:()=>ce(t),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"})})})]},t))}),e.jsx("input",{value:T,onChange:t=>M(t.target.value),onKeyDown:se,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:i,className:"text-[10px] text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"+ Add Variable"})]}),s.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:s.env.map((t,r)=>e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("input",{value:t.key,onChange:A=>u(r,"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:t.value,onChange:A=>u(r,"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:()=>j(r),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"})})})]},r))})]})]})]})]})]})})}const ge={all:"All",scheduled:"Scheduled",webhook:"Webhook"};function Ie({route:s}){const o=Ne(c=>c.publicUrl),[x,n]=l.useState([]),[h,S]=l.useState(!0),[p,v]=l.useState("list"),[g,b]=l.useState(null),[a,f]=l.useState(ne),[w,z]=l.useState(!1),[N,m]=l.useState(""),[k,H]=l.useState(null),[y,R]=l.useState(""),[Q,Z]=l.useState(null),[L,le]=l.useState("all"),T=l.useRef(null),M=l.useCallback(async()=>{try{const c=await E.listAgents();n(c)}catch{}finally{S(!1)}},[]);l.useEffect(()=>{M()},[M]),l.useEffect(()=>{if(s.page==="agent-detail"&&"agentId"in s){const c=x.find(i=>i.id===s.agentId);c&&$(c)}},[s,x]);function P(){b(null),f(ne),m(""),v("pick-template")}function V(c){b(null),f(c),m(""),v("edit")}function $(c){var i,u,j,C,ee,te,se,ce;b(c.id),f({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(([D,G])=>({key:D,value:G})):[],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:((u=(i=c.triggers)==null?void 0:i.webhook)==null?void 0:u.enabled)??!1,scheduleEnabled:((C=(j=c.triggers)==null?void 0:j.schedule)==null?void 0:C.enabled)??!1,scheduleExpression:((te=(ee=c.triggers)==null?void 0:ee.schedule)==null?void 0:te.expression)||"0 8 * * *",scheduleRecurring:((ce=(se=c.triggers)==null?void 0:se.schedule)==null?void 0:ce.recurring)??!0}),m(""),v("edit")}function O(){v("list"),b(null),m(""),window.location.hash="#/agents"}async function U(){z(!0),m("");try{const c={};for(const{key:u,value:j}of a.env)u.trim()&&(c[u.trim()]=j);const i={version:1,name:a.name,description:a.description,icon:a.icon||void 0,backendType:a.backendType,model:a.model,permissionMode:a.permissionMode,cwd:a.cwd||"temp",prompt:a.prompt,envSlug:a.envSlug||void 0,env:Object.keys(c).length>0?c:void 0,codexInternetAccess:a.backendType==="codex"?a.codexInternetAccess:void 0,branch:a.branch||void 0,createBranch:a.branch?a.createBranch:void 0,useWorktree:a.branch?a.useWorktree:void 0,mcpServers:Object.keys(a.mcpServers).length>0?a.mcpServers:void 0,skills:a.skills.length>0?a.skills:void 0,allowedTools:a.allowedTools.length>0?a.allowedTools:void 0,enabled:!0,triggers:{webhook:{enabled:a.webhookEnabled,secret:""},schedule:{enabled:a.scheduleEnabled,expression:a.scheduleExpression,recurring:a.scheduleRecurring}}};g?await E.updateAgent(g,i):await E.createAgent(i),await M(),v("list"),b(null),window.location.hash="#/agents"}catch(c){m(c instanceof Error?c.message:String(c))}finally{z(!1)}}async function B(c){if(confirm("Delete this agent?"))try{await E.deleteAgent(c),await M()}catch{}}async function oe(c){try{await E.toggleAgent(c),await M()}catch{}}async function W(c,i){try{await E.runAgent(c.id,i),H(null),R(""),await M()}catch{}}function X(c){c.prompt.includes("{{input}}")?(H(c),R("")):W(c)}async function F(c){try{const i=await E.exportAgent(c.id),u=new Blob([JSON.stringify(i,null,2)],{type:"application/json"}),j=URL.createObjectURL(u),C=document.createElement("a");C.href=j,C.download=`${c.id}.agent.json`,C.click(),URL.revokeObjectURL(j)}catch{}}async function _(c){var u;const i=(u=c.target.files)==null?void 0:u[0];if(i){try{const j=await i.text(),C=JSON.parse(j);await E.importAgent(C),await M()}catch(j){m(j instanceof Error?j.message:"Failed to import agent")}T.current&&(T.current.value="")}}function Y(c){const i=Me(c,o);navigator.clipboard.writeText(i).then(()=>{Z(c.id),setTimeout(()=>Z(null),2e3)})}async function J(c){if(confirm("Regenerate webhook secret? The old URL will stop working."))try{await E.regenerateAgentWebhookSecret(c),await M()}catch{}}if(p==="pick-template")return e.jsx(Te,{onSelect:V,onBlank:()=>{f(ne),v("edit")},onCancel:()=>v("list")});if(p==="edit")return e.jsx(Re,{form:a,setForm:f,editingId:g,publicUrl:o,error:N,saving:w,onSave:U,onCancel:O});const K={all:x.length,scheduled:x.filter(c=>{var i,u;return(u=(i=c.triggers)==null?void 0:i.schedule)==null?void 0:u.enabled}).length,webhook:x.filter(c=>{var i,u;return(u=(i=c.triggers)==null?void 0:i.webhook)==null?void 0:u.enabled}).length},d=x.filter(c=>{var i,u,j,C;switch(L){case"scheduled":return((u=(i=c.triggers)==null?void 0:i.schedule)==null?void 0:u.enabled)===!0;case"webhook":return((C=(j=c.triggers)==null?void 0:j.webhook)==null?void 0:C.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 px-4 sm:px-8 py-6 sm:py-10 pb-safe",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:T,type:"file",accept:".json",onChange:_,className:"hidden"}),e.jsx("button",{onClick:()=>{var c;return(c=T.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:P,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"})]})]}),N&&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:N}),e.jsx(ke,{publicUrl:o}),!h&&x.length>0&&e.jsx("div",{className:"flex items-center gap-1 mb-4","data-testid":"filter-tabs",children:["all","scheduled","webhook"].map(c=>e.jsxs("button",{onClick:()=>le(c),className:`text-xs px-2.5 py-1 rounded-full transition-colors cursor-pointer ${L===c?"bg-cc-fg text-cc-bg":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:[ge[c]," (",K[c],")"]},c))}),h?e.jsx("div",{className:"text-sm text-cc-muted",children:"Loading..."}):x.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(ae,{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."})]}):d.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsxs("p",{className:"text-sm text-cc-muted",children:["No ",ge[L].toLowerCase()," agents"]}),e.jsxs("p",{className:"text-xs text-cc-muted mt-1",children:[L==="scheduled"&&"Create an agent with a schedule trigger to see it here.",L==="webhook"&&"Create an agent with a webhook trigger to see it here."]})]}):e.jsx("div",{className:"space-y-3",children:d.map(c=>e.jsx(Ee,{agent:c,publicUrl:o,onEdit:()=>$(c),onDelete:()=>B(c.id),onToggle:()=>oe(c.id),onRun:()=>X(c),onExport:()=>F(c),onCopyWebhook:()=>Y(c),onRegenerateSecret:()=>J(c.id),copiedWebhook:Q},c.id))})]}),k&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>H(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 ",k.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:y,onChange:c=>R(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:()=>H(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:()=>W(k,y),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"})]})]})})]})}const Le=[{name:"Coding Agent",icon:"code",description:"Develops features, fixes bugs, writes tests. Full file and terminal access.",color:"text-blue-400",form:{name:"Coding Agent",description:"Develops features, fixes bugs, writes tests",icon:"code",prompt:"You are a coding agent. Help the user with software development tasks: writing code, fixing bugs, refactoring, writing tests, and code reviews. Be thorough and follow best practices.",permissionMode:"acceptEdits"}},{name:"Monitoring Agent",icon:"activity",description:"Checks server health: CPU, RAM, disk, Docker, PM2. Great for cron schedules.",color:"text-green-400",form:{name:"Monitoring Agent",description:"Checks server health and reports issues",icon:"activity",prompt:"You are a monitoring agent. Check server health: CPU usage, RAM, disk space, running processes (PM2, Docker), and network status. Report any issues found. Be concise and actionable.",permissionMode:"plan"}},{name:"Content Agent",icon:"pen-tool",description:"Creates social media posts, generates images and videos via Gemini.",color:"text-pink-400",form:{name:"Content Agent",description:"Creates social media content, images, and videos",icon:"pen-tool",prompt:"You are a content creation agent. Help create social media posts, marketing copy, blog articles, and visual content. You can generate images with Imagen and videos with Veo. Be creative and on-brand."}},{name:"Research Agent",icon:"search",description:"Researches topics, summarizes findings, gathers competitive intelligence.",color:"text-purple-400",form:{name:"Research Agent",description:"Researches topics and summarizes findings",icon:"search",prompt:"You are a research agent. Help the user research topics thoroughly: gather information, analyze data, compare options, and provide well-structured summaries with sources. Be objective and comprehensive."}},{name:"DevOps Agent",icon:"server",description:"Manages deployments, CI/CD, Docker, Nginx, SSL certificates.",color:"text-orange-400",form:{name:"DevOps Agent",description:"Manages deployments, infrastructure, and CI/CD",icon:"server",prompt:"You are a DevOps agent. Help with server management, deployments, CI/CD pipelines, Docker, Nginx configuration, SSL certificates, and infrastructure automation. Prioritize security and reliability.",permissionMode:"acceptEdits"}},{name:"Data Agent",icon:"database",description:"Analyzes data, writes SQL queries, creates reports and visualizations.",color:"text-yellow-400",form:{name:"Data Agent",description:"Analyzes data and creates reports",icon:"database",prompt:"You are a data analysis agent. Help with SQL queries, data analysis, creating reports, and data visualization. Be precise with numbers and provide clear insights."}}];function Te({onSelect:s,onBlank:o,onCancel:x}){return e.jsx("div",{className:"h-full overflow-auto",children:e.jsxs("div",{className:"mx-auto max-w-3xl px-6 py-8",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-bold text-cc-fg",children:"New Agent"}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Start from a template or create from scratch."})]}),e.jsx("button",{onClick:x,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",children:"Cancel"})]}),e.jsx("button",{onClick:o,className:"w-full mb-4 p-4 rounded-xl border-2 border-dashed border-cc-border hover:border-cc-primary/50 bg-cc-card hover:bg-cc-hover transition-colors text-left group",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-cc-hover flex items-center justify-center text-cc-muted group-hover:text-cc-fg",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"w-5 h-5",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-cc-fg",children:"Blank Agent"}),e.jsx("div",{className:"text-xs text-cc-muted",children:"Start with an empty configuration"})]})]})}),e.jsx("h2",{className:"text-xs font-semibold text-cc-muted uppercase tracking-wider mb-3",children:"Templates"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Le.map(n=>e.jsxs("button",{onClick:()=>s({...ne,...n.form}),className:"p-4 rounded-xl border border-cc-border bg-cc-card hover:bg-cc-hover hover:border-cc-primary/30 transition-colors text-left",children:[e.jsx("div",{className:`text-sm font-medium ${n.color}`,children:n.name}),e.jsx("div",{className:"text-xs text-cc-muted mt-1 line-clamp-2",children:n.description})]},n.name))})]})})}export{Ie as AgentsPage};
@@ -0,0 +1,2 @@
1
+ import{r as t,j as e,b as M,d as Q,t as X,c as Y,e as W}from"./index-C6Q5UQHD.js";const ve={high:"text-red-400 bg-red-500/10 border-red-500/20",medium:"text-yellow-400 bg-yellow-500/10 border-yellow-500/20",low:"text-green-400 bg-green-500/10 border-green-500/20"};function K(x){const m=Date.now()-new Date(x).getTime(),o=Math.floor(m/6e4);if(o<1)return"just now";if(o<60)return`${o}m ago`;const k=Math.floor(o/60);if(k<24)return`${k}h ago`;const p=Math.floor(k/24);return p<7?`${p}d ago`:new Date(x).toLocaleDateString()}function ue(x){return new Date(x).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function De(){const[x,m]=t.useState("todos"),[o,k]=t.useState(0);function p(){k(n=>n+1)}const A=[{id:"todos",label:"Todos"},{id:"notes",label:"Notes"},{id:"reminders",label:"Reminders"},{id:"email",label:"Email"},{id:"contacts",label:"Contacts"},{id:"decisions",label:"Decisions"},{id:"documents",label:"Documents"},{id:"templates",label:"Templates"},{id:"time",label:"Time"},{id:"news",label:"News"}];return e.jsxs("div",{className:"h-full flex flex-col bg-cc-bg overflow-hidden",children:[e.jsx("div",{className:"shrink-0 border-b border-cc-border",children:e.jsxs("div",{className:"max-w-4xl mx-auto w-full px-4 sm:px-8 py-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Assistant"}),e.jsx("p",{className:"text-xs text-cc-muted mt-0.5",children:"Personal todos, notes & reminders — managed by Gemini Live"})]})}),e.jsx("div",{className:"flex gap-1 mt-3",children:A.map(n=>e.jsx("button",{type:"button",onClick:()=>m(n.id),className:`px-3 py-1.5 text-xs font-medium rounded-md transition-colors cursor-pointer ${x===n.id?"bg-cc-accent text-white":"text-cc-muted hover:text-cc-fg hover:bg-cc-hover"}`,children:n.label},n.id))})]})}),e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"max-w-4xl mx-auto w-full px-4 sm:px-8 py-6 pb-safe",children:[x==="todos"&&e.jsx(je,{refreshKey:o,onRefresh:p}),x==="notes"&&e.jsx(ye,{refreshKey:o,onRefresh:p}),x==="reminders"&&e.jsx(Ne,{refreshKey:o,onRefresh:p}),x==="email"&&e.jsx(we,{refreshKey:o,onRefresh:p}),x==="contacts"&&e.jsx(Se,{refreshKey:o,onRefresh:p}),x==="decisions"&&e.jsx(Ce,{refreshKey:o,onRefresh:p}),x==="documents"&&e.jsx(ke,{refreshKey:o,onRefresh:p}),x==="templates"&&e.jsx(Te,{refreshKey:o,onRefresh:p}),x==="time"&&e.jsx(Ae,{refreshKey:o,onRefresh:p}),x==="news"&&e.jsx(Ee,{refreshKey:o,onRefresh:p})]})})]})}function je({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState("all"),[u,$]=t.useState(""),[T,j]=t.useState("medium"),[l,b]=t.useState(""),[f,R]=t.useState(!1),[w,y]=t.useState(null),[g,S]=t.useState(""),[C,P]=t.useState(""),v=t.useCallback(async()=>{A(!0);try{const a={};n==="active"&&(a.done=!1),n==="done"&&(a.done=!0);const c=await M.listTodos(a);k(c.todos)}catch{}A(!1)},[n]);t.useEffect(()=>{v()},[v,x]);async function F(a){if(a.preventDefault(),!!u.trim()){R(!0);try{await M.addTodo({text:u.trim(),priority:T,category:l.trim()||void 0}),$(""),b(""),m()}catch{}R(!1)}}async function E(a){try{await M.updateTodo(a.id,{done:!a.done}),m()}catch{}}async function i(a){try{await M.deleteTodo(a),m()}catch{}}async function N(a){if(g.trim())try{await M.updateTodo(a,{text:g.trim()}),y(null),m()}catch{}}const z=C?o.filter(a=>a.project===C):o,B=z.filter(a=>!a.done),I=z.filter(a=>a.done),V=n==="all"?[...B,...I]:z,d=[...new Set(o.map(a=>a.project).filter(Boolean))];return e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsxs("form",{onSubmit:F,className:"flex flex-col sm:flex-row gap-2",children:[e.jsx("input",{type:"text",value:u,onChange:a=>$(a.target.value),placeholder:"Add a todo...",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{value:T,onChange:a=>j(a.target.value),className:"px-2 py-2 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none cursor-pointer",children:[e.jsx("option",{value:"high",children:"High"}),e.jsx("option",{value:"medium",children:"Medium"}),e.jsx("option",{value:"low",children:"Low"})]}),e.jsx("input",{type:"text",value:l,onChange:a=>b(a.target.value),placeholder:"Category",className:"w-24 px-2 py-2 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none"}),e.jsx("button",{type:"submit",disabled:f||!u.trim(),className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:"Add"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex gap-1",children:["all","active","done"].map(a=>e.jsx("button",{type:"button",onClick:()=>L(a),className:`px-2.5 py-1 text-xs rounded-md transition-colors cursor-pointer ${n===a?"bg-cc-hover text-cc-fg":"text-cc-muted hover:text-cc-fg"}`,children:a.charAt(0).toUpperCase()+a.slice(1)},a))}),d.length>0&&e.jsxs("select",{value:C,onChange:a=>P(a.target.value),className:"px-2 py-1 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none cursor-pointer",children:[e.jsx("option",{value:"",children:"All projects"}),d.map(a=>e.jsx("option",{value:a,children:a},a))]})]}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):V.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:n==="done"?"No completed todos":n==="active"?"All done!":"No todos yet. Add one above or ask Gemini Live."}):e.jsx("div",{className:"space-y-1",children:V.map(a=>e.jsxs("div",{className:`group flex items-start gap-3 px-3 py-2.5 rounded-lg border transition-colors ${a.done?"bg-cc-bg border-cc-border/50 opacity-60":"bg-cc-card border-cc-border hover:border-cc-border-hover"}`,children:[e.jsx("button",{type:"button",onClick:()=>E(a),className:`mt-0.5 w-4 h-4 rounded border-2 shrink-0 flex items-center justify-center cursor-pointer transition-colors ${a.done?"bg-cc-accent border-cc-accent":"border-cc-muted hover:border-cc-accent"}`,children:a.done&&e.jsx("svg",{viewBox:"0 0 12 12",className:"w-2.5 h-2.5 text-white",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M2 6l3 3 5-5"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[w===a.id?e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:g,onChange:c=>S(c.target.value),onKeyDown:c=>{c.key==="Enter"&&N(a.id),c.key==="Escape"&&y(null)},className:"flex-1 px-2 py-1 text-sm bg-cc-input border border-cc-border rounded text-cc-fg focus:outline-none focus:border-cc-accent",autoFocus:!0}),e.jsx("button",{type:"button",onClick:()=>N(a.id),className:"text-xs text-cc-accent hover:underline cursor-pointer",children:"Save"}),e.jsx("button",{type:"button",onClick:()=>y(null),className:"text-xs text-cc-muted hover:underline cursor-pointer",children:"Cancel"})]}):e.jsx("span",{className:`text-sm ${a.done?"line-through text-cc-muted":"text-cc-fg"}`,onDoubleClick:()=>{y(a.id),S(a.text)},children:a.text}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded border ${ve[a.priority]}`,children:a.priority}),a.category&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:a.category}),a.project&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-400 border border-blue-500/20",children:a.project}),a.delegatedTo&&e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-purple-500/10 text-purple-400 border border-purple-500/20",children:[a.delegatedTo,a.dueDate?` · ${a.dueDate}`:""]}),e.jsx("span",{className:"text-[10px] text-cc-muted",children:K(a.createdAt)})]})]}),e.jsx("button",{type:"button",onClick:()=>i(a.id),className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1",title:"Delete",children:e.jsxs("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",children:[e.jsx("path",{d:"M5.5 5.5A.5.5 0 016 6v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm2.5 0a.5.5 0 01.5.5v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm3 .5a.5.5 0 00-1 0v6a.5.5 0 001 0V6z"}),e.jsx("path",{fillRule:"evenodd",d:"M14.5 3a1 1 0 01-1 1H13v9a2 2 0 01-2 2H5a2 2 0 01-2-2V4h-.5a1 1 0 010-2H6a1 1 0 011-1h2a1 1 0 011 1h3.5a1 1 0 011 1zM4.118 4L4 4.059V13a1 1 0 001 1h6a1 1 0 001-1V4.059L11.882 4H4.118z"})]})})]},a.id))})]})}function ye({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState(""),[u,$]=t.useState(null),[T,j]=t.useState(!1),[l,b]=t.useState(""),[f,R]=t.useState(""),[w,y]=t.useState(""),[g,S]=t.useState(!1),C=t.useCallback(async()=>{A(!0);try{const i=await M.listNotes(n||void 0);k(i.notes)}catch{}A(!1)},[n]);t.useEffect(()=>{C()},[C,x]);function P(){$(null),b(""),R(""),y(""),j(!0)}function v(i){$(i),b(i.title),R(i.content),y(i.tags.join(", ")),j(!0)}async function F(){if(!l.trim())return;S(!0);const i=w.split(",").map(N=>N.trim()).filter(Boolean);try{u?await M.updateNote(u.id,{title:l.trim(),content:f,tags:i}):await M.addNote({title:l.trim(),content:f,tags:i}),j(!1),m()}catch{}S(!1)}async function E(i){try{await M.deleteNote(i),(u==null?void 0:u.id)===i&&j(!1),m()}catch{}}return T?e.jsxs("div",{className:"p-4 sm:p-6 max-w-3xl space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("button",{type:"button",onClick:()=>j(!1),className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z"})}),"Back"]}),e.jsx("span",{className:"text-xs text-cc-muted",children:u?"Edit Note":"New Note"})]}),e.jsx("input",{type:"text",value:l,onChange:i=>b(i.target.value),placeholder:"Title",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent",autoFocus:!0}),e.jsx("textarea",{value:f,onChange:i=>R(i.target.value),placeholder:"Write your note...",rows:12,className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent resize-y font-mono"}),e.jsx("input",{type:"text",value:w,onChange:i=>y(i.target.value),placeholder:"Tags (comma separated)",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:F,disabled:g||!l.trim(),className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:g?"Saving...":"Save"}),e.jsx("button",{type:"button",onClick:()=>j(!1),className:"px-4 py-2 text-xs text-cc-muted hover:text-cc-fg rounded-md hover:bg-cc-hover cursor-pointer",children:"Cancel"})]})]}):e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:n,onChange:i=>L(i.target.value),placeholder:"Search notes...",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("button",{type:"button",onClick:P,className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 cursor-pointer",children:"New Note"})]}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):o.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:n?"No matching notes":"No notes yet. Create one or ask Gemini Live."}):e.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:o.map(i=>e.jsxs("div",{className:"group p-4 rounded-lg border border-cc-border bg-cc-card hover:border-cc-border-hover transition-colors cursor-pointer",onClick:()=>v(i),children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg truncate flex-1",children:i.title}),e.jsx("button",{type:"button",onClick:N=>{N.stopPropagation(),E(i.id)},className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1 -mr-1 -mt-1",title:"Delete",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",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"})})})]}),i.content&&e.jsx("p",{className:"text-xs text-cc-muted mt-1 line-clamp-3",children:i.content}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[i.tags.map(N=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:N},N)),e.jsx("span",{className:"text-[10px] text-cc-muted ml-auto",children:K(i.updatedAt)})]})]},i.id))})]})}function Ne({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState(!1),[u,$]=t.useState(""),[T,j]=t.useState(""),[l,b]=t.useState(""),[f,R]=t.useState(!1),[w,y]=t.useState(null),[g,S]=t.useState(""),[C,P]=t.useState(""),[v,F]=t.useState(""),E=t.useCallback(async()=>{A(!0);try{const c=await M.listReminders(n);k(c.reminders)}catch{}A(!1)},[n]);t.useEffect(()=>{E()},[E,x]);async function i(c){if(c.preventDefault(),!(!u.trim()||!T||!l)){R(!0);try{const s=new Date(`${T}T${l}`).toISOString();await M.addReminder({text:u.trim(),triggerAt:s}),$(""),j(""),b(""),m()}catch{}R(!1)}}async function N(c){try{await M.deleteReminder(c),m()}catch{}}function z(c){y(c.id),S(c.text);const s=new Date(c.triggerAt);P(s.toISOString().slice(0,10)),F(s.toTimeString().slice(0,5))}async function B(c){if(c.preventDefault(),!(!w||!g.trim()||!C||!v))try{const s=new Date(`${C}T${v}`).toISOString();await M.updateReminder(w,{text:g.trim(),triggerAt:s}),y(null),m()}catch{}}const I=new Date,V=o.filter(c=>!c.fired&&new Date(c.triggerAt)>I),d=o.filter(c=>!c.fired&&new Date(c.triggerAt)<=I),a=o.filter(c=>c.fired);return e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsxs("form",{onSubmit:i,className:"flex flex-col sm:flex-row gap-2",children:[e.jsx("input",{type:"text",value:u,onChange:c=>$(c.target.value),placeholder:"Remind me to...",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"date",value:T,onChange:c=>j(c.target.value),className:"px-2 py-2 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"}),e.jsx("input",{type:"time",value:l,onChange:c=>b(c.target.value),className:"px-2 py-2 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"}),e.jsx("button",{type:"submit",disabled:f||!u.trim()||!T||!l,className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:"Add"})]})]}),w&&e.jsxs("form",{onSubmit:B,className:"flex flex-col sm:flex-row gap-2 p-3 bg-cc-accent/5 border border-cc-accent/20 rounded-lg",children:[e.jsx("input",{type:"text",value:g,onChange:c=>S(c.target.value),className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none focus:border-cc-accent"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"date",value:C,onChange:c=>P(c.target.value),className:"px-2 py-2 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"}),e.jsx("input",{type:"time",value:v,onChange:c=>F(c.target.value),className:"px-2 py-2 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"}),e.jsx("button",{type:"submit",disabled:!g.trim()||!C||!v,className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:"Save"}),e.jsx("button",{type:"button",onClick:()=>y(null),className:"px-3 py-2 text-xs font-medium rounded-md text-cc-muted hover:text-cc-fg border border-cc-border cursor-pointer",children:"Cancel"})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("button",{type:"button",onClick:()=>L(!n),className:`text-xs cursor-pointer ${n?"text-cc-accent":"text-cc-muted hover:text-cc-fg"}`,children:n?"Hide fired":"Show all"})}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):o.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"No reminders yet. Add one above or ask Gemini Live."}):e.jsxs("div",{className:"space-y-4",children:[d.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs font-medium text-red-400 mb-2",children:"Overdue"}),e.jsx("div",{className:"space-y-1",children:d.map(c=>e.jsx(re,{reminder:c,onDelete:N,onEdit:z,isOverdue:!0},c.id))})]}),V.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs font-medium text-cc-fg mb-2",children:"Upcoming"}),e.jsx("div",{className:"space-y-1",children:V.map(c=>e.jsx(re,{reminder:c,onDelete:N,onEdit:z},c.id))})]}),n&&a.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted mb-2",children:"Completed"}),e.jsx("div",{className:"space-y-1",children:a.map(c=>e.jsx(re,{reminder:c,onDelete:N,isFired:!0},c.id))})]})]})]})}function re({reminder:x,onDelete:m,onEdit:o,isOverdue:k,isFired:p}){return e.jsxs("div",{className:`group flex items-center gap-3 px-3 py-2.5 rounded-lg border transition-colors ${p?"bg-cc-bg border-cc-border/50 opacity-60":k?"bg-red-500/5 border-red-500/20":"bg-cc-card border-cc-border hover:border-cc-border-hover"}`,children:[e.jsx("div",{className:`w-2 h-2 rounded-full shrink-0 ${p?"bg-cc-muted":k?"bg-red-400 animate-pulse":"bg-cc-accent"}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:`text-sm ${p?"line-through text-cc-muted":"text-cc-fg"}`,children:x.text}),e.jsxs("div",{className:"text-[10px] text-cc-muted mt-0.5",children:[ue(x.triggerAt),x.calendarEventUid&&e.jsx("span",{className:"inline-flex items-center gap-0.5 text-cc-accent ml-1",title:"Synced to calendar",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-2.5 h-2.5",fill:"currentColor",children:e.jsx("path",{d:"M4.5 0a.5.5 0 01.5.5V1h6V.5a.5.5 0 011 0V1h1.5A1.5 1.5 0 0115 2.5v11a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 13.5v-11A1.5 1.5 0 012.5 1H4V.5a.5.5 0 01.5-.5zM2 5v8.5a.5.5 0 00.5.5h11a.5.5 0 00.5-.5V5H2z"})})})]})]}),!p&&o&&e.jsx("button",{type:"button",onClick:()=>o(x),className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-cc-accent transition-opacity cursor-pointer p-1",title:"Edit",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",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.61zM11.189 3.07l1.74 1.74 1.131-1.131a.25.25 0 000-.354L12.974 2.24a.25.25 0 00-.354 0L11.49 3.07z"})})}),e.jsx("button",{type:"button",onClick:()=>m(x.id),className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1",title:"Delete",children:e.jsxs("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",children:[e.jsx("path",{d:"M5.5 5.5A.5.5 0 016 6v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm2.5 0a.5.5 0 01.5.5v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm3 .5a.5.5 0 00-1 0v6a.5.5 0 001 0V6z"}),e.jsx("path",{fillRule:"evenodd",d:"M14.5 3a1 1 0 01-1 1H13v9a2 2 0 01-2 2H5a2 2 0 01-2-2V4h-.5a1 1 0 010-2H6a1 1 0 011-1h2a1 1 0 011 1h3.5a1 1 0 011 1zM4.118 4L4 4.059V13a1 1 0 001 1h6a1 1 0 001-1V4.059L11.882 4H4.118z"})]})})]})}const ie={gmail:{imap:{host:"imap.gmail.com",port:993,secure:!0},smtp:{host:"smtp.gmail.com",port:465,secure:!0}},outlook:{imap:{host:"outlook.office365.com",port:993,secure:!0},smtp:{host:"smtp.office365.com",port:587,secure:!1}},icloud:{imap:{host:"imap.mail.me.com",port:993,secure:!0},smtp:{host:"smtp.mail.me.com",port:587,secure:!1}},yahoo:{imap:{host:"imap.mail.yahoo.com",port:993,secure:!0},smtp:{host:"smtp.mail.yahoo.com",port:465,secure:!0}}};function we({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState("accounts"),[u,$]=t.useState(null),[T,j]=t.useState([]),[l,b]=t.useState(null),[f,R]=t.useState([]),[w,y]=t.useState(!1),[g,S]=t.useState(""),[C,P]=t.useState(""),[v,F]=t.useState(""),[E,i]=t.useState(""),[N,z]=t.useState(""),[B,I]=t.useState("gmail"),[V,d]=t.useState("imap.gmail.com"),[a,c]=t.useState(993),[s,U]=t.useState("smtp.gmail.com"),[G,h]=t.useState(465),[H,O]=t.useState(!1),[_,q]=t.useState(""),[Z,ee]=t.useState(""),[J,te]=t.useState(""),[ne,oe]=t.useState(!1),[ce,le]=t.useState(null),de=t.useCallback(async()=>{A(!0);try{const[r,D]=await Promise.allSettled([M.listEmailAccounts(),M.getUnreadSummary()]);r.status==="fulfilled"&&k(r.value.accounts||[]),D.status==="fulfilled"&&R(D.value.summary||[])}catch{}A(!1)},[]);t.useEffect(()=>{de()},[de,x]);function xe(r){I(r);const D=ie[r];D&&(d(D.imap.host),c(D.imap.port),U(D.smtp.host),h(D.smtp.port))}async function me(r){if(r.preventDefault(),!(!C.trim()||!v.trim()||!E.trim()||!N.trim())){O(!0);try{await M.addEmailAccount({name:C.trim(),email:v.trim(),imap:{host:V,port:a,secure:a===993},smtp:{host:s,port:G,secure:G===465},auth:{user:E.trim(),pass:N}}),P(""),F(""),i(""),z(""),L("accounts"),m()}catch(D){S(D instanceof Error?D.message:"Failed to add account")}O(!1)}}async function pe(r){try{await M.deleteEmailAccount(r),m()}catch{}}async function he(r){S("Testing connection...");try{const D=await M.testEmailAccount(r);S(D.ok?"Connection successful!":`Failed: ${D.error}`)}catch(D){S(D instanceof Error?D.message:"Test failed")}}async function se(r){$(r),L("inbox"),y(!0);try{const D=await M.listEmails(r.id,{limit:20});j(D.emails||[])}catch{j([])}y(!1)}async function be(r){y(!0);try{const D=await M.readEmail(r.accountId,r.uid);b(D),L("read")}catch{}y(!1)}function ae(r){$(u),r?(le(r.uid),q(r.from),ee(r.subject.startsWith("Re:")?r.subject:`Re: ${r.subject}`),te("")):(le(null),q(""),ee(""),te("")),L("compose")}async function ge(r){if(r.preventDefault(),!(!u||!_.trim()||!J.trim())){oe(!0);try{ce?await M.replyToEmail(u.id,{uid:ce,body:J}):await M.sendEmailMessage(u.id,{to:_,subject:Z,body:J}),S("Email sent!"),L("inbox"),se(u)}catch(D){S(D instanceof Error?D.message:"Failed to send")}oe(!1)}}return t.useEffect(()=>{if(g){const r=setTimeout(()=>S(""),3e3);return()=>clearTimeout(r)}},[g]),n==="add-account"?e.jsxs("div",{className:"p-4 sm:p-6 max-w-2xl space-y-4",children:[e.jsxs("button",{type:"button",onClick:()=>L("accounts"),className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z"})}),"Back"]}),e.jsx("h3",{className:"text-sm font-medium text-cc-fg",children:"Add Email Account"}),e.jsxs("form",{onSubmit:me,className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Provider"}),e.jsxs("div",{className:"flex gap-1 flex-wrap",children:[Object.keys(ie).map(r=>e.jsx("button",{type:"button",onClick:()=>xe(r),className:`px-2.5 py-1 text-xs rounded-md cursor-pointer transition-colors ${B===r?"bg-cc-accent text-white":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:r.charAt(0).toUpperCase()+r.slice(1)},r)),e.jsx("button",{type:"button",onClick:()=>I("custom"),className:`px-2.5 py-1 text-xs rounded-md cursor-pointer transition-colors ${B==="custom"?"bg-cc-accent text-white":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:"Custom"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Display Name"}),e.jsx("input",{type:"text",value:C,onChange:r=>P(r.target.value),placeholder:"Work",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Email Address"}),e.jsx("input",{type:"email",value:v,onChange:r=>F(r.target.value),placeholder:"user@example.com",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Username"}),e.jsx("input",{type:"text",value:E,onChange:r=>i(r.target.value),placeholder:"user@example.com",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Password / App Password"}),e.jsx("input",{type:"password",value:N,onChange:r=>z(r.target.value),placeholder:"App-specific password",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]})]}),B==="custom"&&e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"IMAP Host"}),e.jsx("input",{type:"text",value:V,onChange:r=>d(r.target.value),className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"IMAP Port"}),e.jsx("input",{type:"number",value:a,onChange:r=>c(Number(r.target.value)),className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"SMTP Host"}),e.jsx("input",{type:"text",value:s,onChange:r=>U(r.target.value),className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"SMTP Port"}),e.jsx("input",{type:"number",value:G,onChange:r=>h(Number(r.target.value)),className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none"})]})]}),e.jsx("p",{className:"text-[10px] text-cc-muted",children:"For Gmail/iCloud, use an App Password (not your regular password). Go to your account security settings to generate one."}),e.jsx("button",{type:"submit",disabled:H||!C.trim()||!v.trim()||!E.trim()||!N.trim(),className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:H?"Adding...":"Add Account"})]})]}):n==="compose"&&u?e.jsxs("div",{className:"p-4 sm:p-6 max-w-2xl space-y-4",children:[e.jsxs("button",{type:"button",onClick:()=>L(l?"read":"inbox"),className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z"})}),"Back"]}),e.jsx("h3",{className:"text-sm font-medium text-cc-fg",children:ce?"Reply":"New Email"}),g&&e.jsx("div",{className:"text-xs text-cc-accent",children:g}),e.jsxs("form",{onSubmit:ge,className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"From"}),e.jsxs("div",{className:"text-xs text-cc-fg",children:[u.name," <",u.email,">"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"To"}),e.jsx("input",{type:"text",value:_,onChange:r=>q(r.target.value),placeholder:"recipient@example.com",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Subject"}),e.jsx("input",{type:"text",value:Z,onChange:r=>ee(r.target.value),placeholder:"Subject",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-cc-muted uppercase tracking-wider block mb-1",children:"Message"}),e.jsx("textarea",{value:J,onChange:r=>te(r.target.value),rows:10,placeholder:"Write your message...",className:"w-full px-2 py-1.5 text-xs bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent resize-y font-mono"})]}),e.jsx("div",{className:"flex gap-2",children:e.jsx("button",{type:"submit",disabled:ne||!_.trim()||!J.trim(),className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:ne?"Sending...":"Send"})})]})]}):n==="read"&&l&&u?e.jsxs("div",{className:"p-4 sm:p-6 max-w-2xl space-y-4",children:[e.jsxs("button",{type:"button",onClick:()=>{L("inbox"),b(null)},className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z"})}),"Back to Inbox"]}),e.jsxs("div",{className:"border border-cc-border rounded-lg p-4 bg-cc-card space-y-3",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg",children:l.subject}),e.jsxs("div",{className:"flex items-center justify-between text-[10px] text-cc-muted",children:[e.jsxs("span",{children:["From: ",l.from]}),e.jsx("span",{children:ue(l.date)})]}),e.jsxs("div",{className:"text-[10px] text-cc-muted",children:["To: ",l.to]}),e.jsx("div",{className:"border-t border-cc-border pt-3",children:e.jsx("pre",{className:"text-xs text-cc-fg whitespace-pre-wrap font-mono leading-relaxed",children:l.textBody})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>ae(l),className:"px-3 py-1.5 text-xs font-medium rounded-md bg-cc-accent/10 text-cc-accent border border-cc-accent/30 hover:bg-cc-accent/20 cursor-pointer",children:"Reply"}),e.jsx("button",{type:"button",onClick:()=>ae(),className:"px-3 py-1.5 text-xs text-cc-muted hover:text-cc-fg rounded-md hover:bg-cc-hover cursor-pointer",children:"New Email"})]})]}):n==="inbox"&&u?e.jsxs("div",{className:"p-4 sm:p-6 max-w-3xl space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("button",{type:"button",onClick:()=>{L("accounts"),$(null)},className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z"})}),"Back"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-cc-fg font-medium",children:u.name}),e.jsx("span",{className:"text-[10px] text-cc-muted",children:u.email})]}),e.jsx("button",{type:"button",onClick:()=>ae(),className:"px-3 py-1.5 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 cursor-pointer",children:"Compose"})]}),w?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading emails..."}):T.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"No emails found."}):e.jsx("div",{className:"space-y-0.5",children:T.map(r=>e.jsxs("button",{type:"button",onClick:()=>be(r),className:`w-full text-left px-3 py-2.5 rounded-lg border transition-colors cursor-pointer ${r.seen?"bg-cc-bg border-cc-border/50":"bg-cc-card border-cc-border hover:border-cc-border-hover"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[!r.seen&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-cc-accent shrink-0"}),e.jsx("span",{className:`text-xs truncate flex-1 ${r.seen?"text-cc-muted":"text-cc-fg font-medium"}`,children:r.from}),e.jsx("span",{className:"text-[10px] text-cc-muted shrink-0",children:K(r.date)})]}),e.jsx("div",{className:`text-xs truncate mt-0.5 ${r.seen?"text-cc-muted":"text-cc-fg"}`,children:r.subject})]},r.uid))})]}):e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[g&&e.jsx("div",{className:"text-xs px-3 py-2 rounded-md bg-cc-accent/10 text-cc-accent",children:g}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-cc-muted",children:o.length===0?"No email accounts configured.":`${o.length} account${o.length>1?"s":""}`}),e.jsx("button",{type:"button",onClick:()=>L("add-account"),className:"px-3 py-1.5 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 cursor-pointer",children:"Add Account"})]}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):e.jsx("div",{className:"space-y-2",children:o.map(r=>{const D=f.find(fe=>fe.email===r.email);return e.jsxs("div",{className:"group flex items-center gap-3 px-4 py-3 rounded-lg border border-cc-border bg-cc-card hover:border-cc-border-hover transition-colors",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-cc-accent/10 text-cc-accent flex items-center justify-center text-sm font-bold shrink-0",children:r.name.charAt(0).toUpperCase()}),e.jsxs("div",{className:"flex-1 min-w-0 cursor-pointer",onClick:()=>se(r),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-cc-fg",children:r.name}),D&&D.unread>0&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-cc-accent text-white font-medium",children:D.unread})]}),e.jsx("div",{className:"text-[10px] text-cc-muted truncate",children:r.email})]}),e.jsxs("div",{className:"flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx("button",{type:"button",onClick:()=>se(r),className:"px-2 py-1 text-[10px] text-cc-accent hover:underline cursor-pointer",children:"Open"}),e.jsx("button",{type:"button",onClick:()=>he(r.id),className:"px-2 py-1 text-[10px] text-cc-muted hover:text-cc-fg cursor-pointer",children:"Test"}),e.jsx("button",{type:"button",onClick:()=>pe(r.id),className:"px-2 py-1 text-[10px] text-cc-muted hover:text-red-400 cursor-pointer",children:"Delete"})]})]},r.id)})}),o.length===0&&!p&&e.jsxs("div",{className:"text-center py-4",children:[e.jsx("p",{className:"text-xs text-cc-muted",children:"Add an email account to read, send, and manage emails."}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Gemini Live can also manage your emails via voice."})]})]})}function Se({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState(""),[u,$]=t.useState(null),[T,j]=t.useState(!1),[l,b]=t.useState(null),[f,R]=t.useState(""),[w,y]=t.useState(""),[g,S]=t.useState(""),[C,P]=t.useState(""),[v,F]=t.useState(""),[E,i]=t.useState(""),[N,z]=t.useState(!1),B=t.useCallback(async()=>{A(!0);try{const c=await M.listCrmContacts(n||void 0);k(c.contacts)}catch{}A(!1)},[n]);t.useEffect(()=>{B()},[B,x]);function I(){b(null),R(""),y(""),S(""),P(""),F(""),i(""),j(!0)}function V(c){b(c),R(c.name),y(c.company||""),S(c.email||""),P(c.phone||""),F(c.notes||""),i(c.tags.join(", ")),j(!0)}async function d(){if(!f.trim())return;z(!0);const c=E.split(",").map(s=>s.trim()).filter(Boolean);try{l?await M.updateCrmContact(l.id,{name:f.trim(),company:w.trim()||void 0,email:g.trim()||void 0,phone:C.trim()||void 0,notes:v,tags:c}):await M.addCrmContact({name:f.trim(),company:w.trim()||void 0,email:g.trim()||void 0,phone:C.trim()||void 0,notes:v,tags:c}),j(!1),m()}catch{}z(!1)}async function a(c){try{await M.deleteCrmContact(c),m()}catch{}}return T?e.jsxs("div",{className:"p-4 sm:p-6 max-w-3xl space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("button",{type:"button",onClick:()=>j(!1),className:"text-xs text-cc-muted hover:text-cc-fg cursor-pointer flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z"})}),"Back"]}),e.jsx("span",{className:"text-xs text-cc-muted",children:l?"Edit Contact":"New Contact"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx("input",{type:"text",value:f,onChange:c=>R(c.target.value),placeholder:"Name *",className:"col-span-2 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent",autoFocus:!0}),e.jsx("input",{type:"text",value:w,onChange:c=>y(c.target.value),placeholder:"Company",className:"px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("input",{type:"email",value:g,onChange:c=>S(c.target.value),placeholder:"Email",className:"px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("input",{type:"tel",value:C,onChange:c=>P(c.target.value),placeholder:"Phone",className:"px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("input",{type:"text",value:E,onChange:c=>i(c.target.value),placeholder:"Tags (comma separated)",className:"px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsx("textarea",{value:v,onChange:c=>F(c.target.value),placeholder:"Notes...",rows:4,className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent resize-y"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:d,disabled:N||!f.trim(),className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 disabled:opacity-50 cursor-pointer",children:N?"Saving...":"Save"}),e.jsx("button",{type:"button",onClick:()=>j(!1),className:"px-4 py-2 text-xs text-cc-muted hover:text-cc-fg rounded-md hover:bg-cc-hover cursor-pointer",children:"Cancel"})]})]}):e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:n,onChange:c=>L(c.target.value),placeholder:"Search contacts...",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("button",{type:"button",onClick:I,className:"px-4 py-2 text-xs font-medium rounded-md bg-cc-accent text-white hover:bg-cc-accent/80 cursor-pointer",children:"New Contact"})]}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):o.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:n?"No matching contacts":"No contacts yet. Add one or ask Hank."}):e.jsx("div",{className:"space-y-2",children:o.map(c=>e.jsxs("div",{className:"group rounded-lg border border-cc-border bg-cc-card hover:border-cc-border-hover transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 cursor-pointer",onClick:()=>$(u===c.id?null:c.id),children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-cc-accent/20 text-cc-accent flex items-center justify-center text-xs font-medium shrink-0",children:c.name.charAt(0).toUpperCase()}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-cc-fg truncate",children:c.name}),c.company&&e.jsx("span",{className:"text-xs text-cc-muted truncate",children:c.company})]}),e.jsxs("div",{className:"flex items-center gap-3 text-[10px] text-cc-muted mt-0.5",children:[c.email&&e.jsx("span",{children:c.email}),c.phone&&e.jsx("span",{children:c.phone}),c.lastContactDate&&e.jsxs("span",{children:["Last: ",K(c.lastContactDate)]})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{type:"button",onClick:s=>{s.stopPropagation(),V(c)},className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-cc-accent transition-opacity cursor-pointer p-1",title:"Edit",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",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.61zM11.189 3.07l1.74 1.74 1.131-1.131a.25.25 0 000-.354L12.974 2.24a.25.25 0 00-.354 0L11.49 3.07z"})})}),e.jsx("button",{type:"button",onClick:s=>{s.stopPropagation(),a(c.id)},className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1",title:"Delete",children:e.jsxs("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",children:[e.jsx("path",{d:"M5.5 5.5A.5.5 0 016 6v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm2.5 0a.5.5 0 01.5.5v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm3 .5a.5.5 0 00-1 0v6a.5.5 0 001 0V6z"}),e.jsx("path",{fillRule:"evenodd",d:"M14.5 3a1 1 0 01-1 1H13v9a2 2 0 01-2 2H5a2 2 0 01-2-2V4h-.5a1 1 0 010-2H6a1 1 0 011-1h2a1 1 0 011 1h3.5a1 1 0 011 1zM4.118 4L4 4.059V13a1 1 0 001 1h6a1 1 0 001-1V4.059L11.882 4H4.118z"})]})})]})]}),u===c.id&&e.jsxs("div",{className:"px-4 pb-3 border-t border-cc-border/50 pt-3 space-y-3",children:[c.tags.length>0&&e.jsx("div",{className:"flex gap-1 flex-wrap",children:c.tags.map(s=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:s},s))}),c.notes&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-[10px] font-medium text-cc-muted uppercase tracking-wider mb-1",children:"Notes"}),e.jsx("p",{className:"text-xs text-cc-fg whitespace-pre-wrap",children:c.notes})]}),c.interactions.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-[10px] font-medium text-cc-muted uppercase tracking-wider mb-1",children:"Interactions"}),e.jsx("div",{className:"space-y-1",children:c.interactions.slice().reverse().map((s,U)=>e.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[e.jsx("span",{className:"text-cc-muted shrink-0",children:s.date.slice(0,10)}),e.jsx("span",{className:`px-1 py-0.5 rounded text-[10px] shrink-0 ${s.type==="call"?"bg-blue-500/10 text-blue-400":s.type==="email"?"bg-green-500/10 text-green-400":s.type==="meeting"?"bg-purple-500/10 text-purple-400":"bg-cc-hover text-cc-muted"}`,children:s.type}),e.jsx("span",{className:"text-cc-fg",children:s.summary})]},U))})]})]})]},c.id))})]})}function Ce({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState(""),[u,$]=t.useState(null),T=t.useCallback(async()=>{A(!0);try{const l=await M.listDecisions(n||void 0);k(l.decisions)}catch{}A(!1)},[n]);t.useEffect(()=>{T()},[T,x]);async function j(l){try{await M.deleteDecision(l),m()}catch{}}return e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsx("div",{className:"flex gap-2",children:e.jsx("input",{type:"text",value:n,onChange:l=>L(l.target.value),placeholder:"Search decisions...",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):o.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:n?"No matching decisions":"No decisions logged yet. Hank will record decisions from conversations."}):e.jsx("div",{className:"space-y-3",children:o.map(l=>e.jsxs("div",{className:"group rounded-lg border border-cc-border bg-cc-card hover:border-cc-border-hover transition-colors",children:[e.jsxs("div",{className:"flex items-start gap-3 px-4 py-3 cursor-pointer",onClick:()=>$(u===l.id?null:l.id),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg",children:l.title}),e.jsx("p",{className:"text-xs text-cc-muted mt-1 line-clamp-2",children:l.decision}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[l.tags.map(b=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:b},b)),e.jsx("span",{className:"text-[10px] text-cc-muted ml-auto",children:K(l.createdAt)})]})]}),e.jsx("button",{type:"button",onClick:b=>{b.stopPropagation(),j(l.id)},className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1 shrink-0",title:"Delete",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",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"})})})]}),u===l.id&&e.jsxs("div",{className:"px-4 pb-3 border-t border-cc-border/50 pt-3 space-y-3",children:[l.context&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-[10px] font-medium text-cc-muted uppercase tracking-wider mb-1",children:"Context"}),e.jsx("p",{className:"text-xs text-cc-fg whitespace-pre-wrap",children:l.context})]}),l.alternatives.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-[10px] font-medium text-cc-muted uppercase tracking-wider mb-1",children:"Alternatives Considered"}),e.jsx("ul",{className:"text-xs text-cc-fg space-y-0.5",children:l.alternatives.map((b,f)=>e.jsxs("li",{className:"flex items-start gap-1",children:[e.jsx("span",{className:"text-cc-muted",children:"-"}),e.jsx("span",{children:b})]},f))})]}),l.reasoning&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-[10px] font-medium text-cc-muted uppercase tracking-wider mb-1",children:"Reasoning"}),e.jsx("p",{className:"text-xs text-cc-fg whitespace-pre-wrap",children:l.reasoning})]})]})]},l.id))})]})}function ke({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState(""),[u,$]=t.useState(""),[T,j]=t.useState([]),[l,b]=t.useState(!1),[f,R]=t.useState(""),[w,y]=t.useState(""),[g,S]=t.useState("markdown"),[C,P]=t.useState(""),[v,F]=t.useState(""),[E,i]=t.useState(!1),N=t.useCallback(async()=>{A(!0);try{if(n){const d=await Q.search(n);k(d.documents)}else{const d=await Q.list(u||void 0);k(d.documents)}}catch{}A(!1)},[n,u]),z=t.useCallback(async()=>{try{const d=await Q.folders();j(d.folders)}catch{}},[]);t.useEffect(()=>{N()},[N,x]),t.useEffect(()=>{z()},[z]);async function B(d){if(d.preventDefault(),!(!f.trim()||!w.trim())){i(!0);try{await Q.create({title:f.trim(),content:w,fileType:g,folder:C.trim()||void 0,tags:v?v.split(",").map(a=>a.trim()).filter(Boolean):void 0}),R(""),y(""),S("markdown"),P(""),F(""),b(!1),m()}catch{}i(!1)}}async function I(d){try{await Q.delete(d),m()}catch{}}const V={markdown:"text-blue-400 bg-blue-500/10",text:"text-gray-400 bg-gray-500/10",json:"text-yellow-400 bg-yellow-500/10",csv:"text-green-400 bg-green-500/10",html:"text-orange-400 bg-orange-500/10"};return e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:n,onChange:d=>L(d.target.value),placeholder:"Search documents...",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsxs("select",{value:u,onChange:d=>$(d.target.value),className:"px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none focus:border-cc-accent cursor-pointer",children:[e.jsx("option",{value:"",children:"All folders"}),T.map(d=>e.jsx("option",{value:d,children:d},d))]}),e.jsx("button",{type:"button",onClick:()=>b(!l),className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 transition-colors cursor-pointer shrink-0",children:"+ New"})]}),l&&e.jsxs("form",{onSubmit:B,className:"rounded-lg border border-cc-border bg-cc-card p-4 space-y-3",children:[e.jsx("input",{type:"text",value:f,onChange:d=>R(d.target.value),placeholder:"Document title",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("textarea",{value:w,onChange:d=>y(d.target.value),placeholder:"Document content...",rows:6,className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent resize-y"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{value:g,onChange:d=>S(d.target.value),className:"px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none focus:border-cc-accent cursor-pointer",children:[e.jsx("option",{value:"markdown",children:"Markdown"}),e.jsx("option",{value:"text",children:"Text"}),e.jsx("option",{value:"json",children:"JSON"}),e.jsx("option",{value:"csv",children:"CSV"}),e.jsx("option",{value:"html",children:"HTML"})]}),e.jsx("input",{type:"text",value:C,onChange:d=>P(d.target.value),placeholder:"Folder (optional)",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("input",{type:"text",value:v,onChange:d=>F(d.target.value),placeholder:"Tags (comma-sep)",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>b(!1),className:"px-3 py-2 text-sm text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:E||!f.trim()||!w.trim(),className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 disabled:opacity-50 transition-colors cursor-pointer",children:E?"Saving...":"Save Document"})]})]}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):o.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:n||u?"No matching documents":"No documents yet. Click + New to create one."}):e.jsx("div",{className:"space-y-2",children:o.map(d=>e.jsxs("div",{className:"group flex items-start gap-3 rounded-lg border border-cc-border bg-cc-card hover:border-cc-border-hover transition-colors px-4 py-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg truncate",children:d.title}),e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${V[d.fileType]||"text-cc-muted bg-cc-hover"}`,children:d.fileType})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[d.folder&&e.jsxs("span",{className:"text-[10px] text-cc-muted",children:[d.folder,"/"]}),d.tags.map(a=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:a},a)),e.jsx("span",{className:"text-[10px] text-cc-muted ml-auto",children:K(d.createdAt)})]})]}),e.jsx("button",{type:"button",onClick:()=>I(d.id),className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1 shrink-0",title:"Delete",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",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"})})})]},d.id))})]})}function Te({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState(!0),[n,L]=t.useState(""),[u,$]=t.useState([]),[T,j]=t.useState(!1),[l,b]=t.useState(""),[f,R]=t.useState(""),[w,y]=t.useState(""),[g,S]=t.useState(!1),[C,P]=t.useState(null),[v,F]=t.useState({}),[E,i]=t.useState(null),N=t.useCallback(async()=>{A(!0);try{const c=await X.list(n||void 0);k(c.templates)}catch{}A(!1)},[n]),z=t.useCallback(async()=>{try{const c=await X.categories();$(c.categories)}catch{}},[]);t.useEffect(()=>{N()},[N,x]),t.useEffect(()=>{z()},[z]);async function B(c){if(c.preventDefault(),!(!l.trim()||!f.trim()||!w.trim())){S(!0);try{await X.create({name:l.trim(),content:f,category:w.trim()}),b(""),R(""),y(""),j(!1),m()}catch{}S(!1)}}async function I(c){try{await X.delete(c),m()}catch{}}function V(c){P(c.id),i(null);const s={};for(const U of c.variables)s[U.name]=U.defaultValue||"";F(s)}async function d(c){try{const s=await X.use(c,v);i(s.result)}catch{}}const a={email:"text-blue-400 bg-blue-500/10",report:"text-purple-400 bg-purple-500/10",contract:"text-orange-400 bg-orange-500/10",invoice:"text-green-400 bg-green-500/10"};return e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{value:n,onChange:c=>L(c.target.value),className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none focus:border-cc-accent cursor-pointer",children:[e.jsx("option",{value:"",children:"All categories"}),u.map(c=>e.jsx("option",{value:c,children:c},c))]}),e.jsx("button",{type:"button",onClick:()=>j(!T),className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 transition-colors cursor-pointer shrink-0",children:"+ New"})]}),T&&e.jsxs("form",{onSubmit:B,className:"rounded-lg border border-cc-border bg-cc-card p-4 space-y-3",children:[e.jsx("input",{type:"text",value:l,onChange:c=>b(c.target.value),placeholder:"Template name",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("textarea",{value:f,onChange:c=>R(c.target.value),placeholder:`Template content...
2
+ Use {{variable_name}} for variables`,rows:6,className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent resize-y"}),e.jsx("input",{type:"text",value:w,onChange:c=>y(c.target.value),placeholder:"Category (e.g. email, report, contract)",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>j(!1),className:"px-3 py-2 text-sm text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:g||!l.trim()||!f.trim()||!w.trim(),className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 disabled:opacity-50 transition-colors cursor-pointer",children:g?"Saving...":"Save Template"})]})]}),p?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):o.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:n?"No templates in this category":"No templates yet. Click + New to create one."}):e.jsx("div",{className:"space-y-2",children:o.map(c=>e.jsxs("div",{className:"group rounded-lg border border-cc-border bg-cc-card hover:border-cc-border-hover transition-colors",children:[e.jsxs("div",{className:"flex items-start gap-3 px-4 py-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg truncate",children:c.name}),e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${a[c.category]||"text-cc-muted bg-cc-hover"}`,children:c.category})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-1.5",children:[e.jsxs("span",{className:"text-[10px] text-cc-muted",children:[c.variables.length," variable",c.variables.length!==1?"s":""]}),e.jsxs("span",{className:"text-[10px] text-cc-muted",children:["Used ",c.usageCount,"x"]}),e.jsx("span",{className:"text-[10px] text-cc-muted ml-auto",children:K(c.createdAt)})]})]}),e.jsxs("div",{className:"flex gap-1 shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>V(c),className:"text-[11px] px-2 py-1 rounded text-cc-accent hover:bg-cc-accent/10 transition-colors cursor-pointer",children:"Use"}),e.jsx("button",{type:"button",onClick:()=>I(c.id),className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1",title:"Delete",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3.5 h-3.5",fill:"currentColor",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"})})})]})]}),C===c.id&&e.jsxs("div",{className:"px-4 pb-3 border-t border-cc-border/50 pt-3 space-y-3",children:[c.variables.length>0?e.jsxs(e.Fragment,{children:[e.jsx("h4",{className:"text-[10px] font-medium text-cc-muted uppercase tracking-wider",children:"Fill Variables"}),c.variables.map(s=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs text-cc-muted w-28 shrink-0",children:s.name}),e.jsx("input",{type:"text",value:v[s.name]||"",onChange:U=>F({...v,[s.name]:U.target.value}),placeholder:s.description||s.name,className:"flex-1 px-2 py-1 text-xs bg-cc-input border border-cc-border rounded text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]},s.name))]}):e.jsx("p",{className:"text-xs text-cc-muted",children:"No variables in this template."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>d(c.id),className:"px-3 py-1.5 text-xs bg-cc-accent text-white rounded hover:bg-cc-accent/80 transition-colors cursor-pointer",children:"Generate"}),e.jsx("button",{type:"button",onClick:()=>{P(null),i(null)},className:"px-3 py-1.5 text-xs text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"})]}),E&&e.jsxs("div",{className:"mt-2 p-3 rounded bg-cc-hover border border-cc-border",children:[e.jsx("h4",{className:"text-[10px] font-medium text-cc-muted uppercase tracking-wider mb-1",children:"Result"}),e.jsx("pre",{className:"text-xs text-cc-fg whitespace-pre-wrap break-words",children:E})]})]})]},c.id))})]})}function Ae({refreshKey:x,onRefresh:m}){const[o,k]=t.useState(null),[p,A]=t.useState([]),[n,L]=t.useState(null),[u,$]=t.useState(!0),[T,j]=t.useState(""),[l,b]=t.useState(!1),[f,R]=t.useState(""),[w,y]=t.useState(""),[g,S]=t.useState(""),[C,P]=t.useState(!1),[v,F]=t.useState(""),[E,i]=t.useState(""),[N,z]=t.useState(""),[B,I]=t.useState(!1),[V,d]=t.useState(!1),a=t.useCallback(async()=>{$(!0);try{const[h,H,O]=await Promise.all([Y.getTimer(),Y.listEntries(),Y.report("week")]);k(h.timer),A(H.entries),L(O)}catch{}$(!1)},[]);t.useEffect(()=>{a()},[a,x]),t.useEffect(()=>{if(!o){j("");return}function h(){if(!o)return;const O=Date.now()-new Date(o.startTime).getTime(),_=Math.floor(O/36e5),q=Math.floor(O%36e5/6e4),Z=Math.floor(O%6e4/1e3);j(`${_.toString().padStart(2,"0")}:${q.toString().padStart(2,"0")}:${Z.toString().padStart(2,"0")}`)}h();const H=setInterval(h,1e3);return()=>clearInterval(H)},[o]);async function c(h){if(h.preventDefault(),!!f.trim()){I(!0);try{await Y.startTimer(f.trim(),w.trim()||void 0,g.trim()||void 0),R(""),y(""),S(""),b(!1),m()}catch{}I(!1)}}async function s(){try{await Y.stopTimer(),m()}catch{}}async function U(h){h.preventDefault();const H=parseFloat(E);if(!(!v.trim()||isNaN(H)||H<=0)){d(!0);try{await Y.logTime({task:v.trim(),duration:H,project:N.trim()||void 0}),F(""),i(""),z(""),P(!1),m()}catch{}d(!1)}}function G(h){if(h<60)return`${Math.round(h)}m`;const H=Math.floor(h/60),O=Math.round(h%60);return O>0?`${H}h ${O}m`:`${H}h`}return e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[o&&e.jsx("div",{className:"rounded-lg border border-cc-accent/50 bg-cc-accent/5 p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-green-400 animate-pulse shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg",children:o.task}),o.project&&e.jsx("span",{className:"text-[10px] text-cc-muted",children:o.project})]}),e.jsx("span",{className:"text-sm font-mono text-cc-accent",children:T}),e.jsx("button",{type:"button",onClick:s,className:"px-3 py-1.5 text-xs bg-red-500/10 text-red-400 rounded hover:bg-red-500/20 transition-colors cursor-pointer",children:"Stop"})]})}),e.jsxs("div",{className:"flex gap-2",children:[!o&&e.jsx("button",{type:"button",onClick:()=>{b(!l),P(!1)},className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 transition-colors cursor-pointer",children:"Start Timer"}),e.jsx("button",{type:"button",onClick:()=>{P(!C),b(!1)},className:"px-3 py-2 text-sm border border-cc-border text-cc-fg rounded-md hover:bg-cc-hover transition-colors cursor-pointer",children:"Quick Log"})]}),l&&e.jsxs("form",{onSubmit:c,className:"rounded-lg border border-cc-border bg-cc-card p-4 space-y-3",children:[e.jsx("input",{type:"text",value:f,onChange:h=>R(h.target.value),placeholder:"What are you working on?",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:w,onChange:h=>y(h.target.value),placeholder:"Project (optional)",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("input",{type:"text",value:g,onChange:h=>S(h.target.value),placeholder:"Category (optional)",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>b(!1),className:"px-3 py-2 text-sm text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:B||!f.trim(),className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 disabled:opacity-50 transition-colors cursor-pointer",children:B?"Starting...":"Start"})]})]}),C&&e.jsxs("form",{onSubmit:U,className:"rounded-lg border border-cc-border bg-cc-card p-4 space-y-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:v,onChange:h=>F(h.target.value),placeholder:"Task description",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("input",{type:"number",value:E,onChange:h=>i(h.target.value),placeholder:"Minutes",min:"1",step:"1",className:"w-24 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),e.jsx("input",{type:"text",value:N,onChange:h=>z(h.target.value),placeholder:"Project (optional)",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>P(!1),className:"px-3 py-2 text-sm text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:V||!v.trim()||!E,className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 disabled:opacity-50 transition-colors cursor-pointer",children:V?"Logging...":"Log Time"})]})]}),u?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):e.jsxs(e.Fragment,{children:[n&&n.totalMinutes>0&&e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4",children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted uppercase tracking-wider mb-3",children:"This Week"}),e.jsxs("div",{className:"flex items-baseline gap-2 mb-3",children:[e.jsx("span",{className:"text-2xl font-semibold text-cc-fg",children:G(n.totalMinutes)}),e.jsx("span",{className:"text-xs text-cc-muted",children:"total"})]}),Object.keys(n.byProject).length>0&&e.jsx("div",{className:"space-y-1.5",children:Object.entries(n.byProject).sort(([,h],[,H])=>H-h).map(([h,H])=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-cc-fg flex-1 truncate",children:h||"No project"}),e.jsx("span",{className:"text-xs text-cc-muted",children:G(H)}),e.jsx("div",{className:"w-20 h-1.5 rounded-full bg-cc-hover overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-cc-accent",style:{width:`${Math.round(H/n.totalMinutes*100)}%`}})})]},h))})]}),p.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted uppercase tracking-wider",children:"Recent Entries"}),p.slice(0,20).map(h=>e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-cc-border bg-cc-card px-4 py-2.5",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm text-cc-fg",children:h.task}),h.project&&e.jsx("span",{className:"text-[10px] text-cc-muted ml-2",children:h.project})]}),e.jsx("span",{className:"text-xs text-cc-muted shrink-0",children:h.duration!=null?G(h.duration):"running"}),e.jsx("span",{className:"text-[10px] text-cc-muted shrink-0",children:K(h.startTime)})]},h.id))]}),p.length===0&&!o&&e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"No time entries yet. Start a timer or log time manually."})]})]})}function Ee({refreshKey:x,onRefresh:m}){const[o,k]=t.useState([]),[p,A]=t.useState([]),[n,L]=t.useState(null),[u,$]=t.useState(!0),[T,j]=t.useState(""),[l,b]=t.useState(!1),[f,R]=t.useState(!1),[w,y]=t.useState(""),[g,S]=t.useState("rss"),[C,P]=t.useState(""),[v,F]=t.useState(""),[E,i]=t.useState(""),[N,z]=t.useState(!1),B=t.useCallback(async()=>{$(!0);try{if(T){const s=await W.search(T);k(s.items)}else{const[s,U,G]=await Promise.all([W.list({limit:50}),W.stats(),W.listSources()]);k(s.items),L(U),A(G.sources)}}catch{}$(!1)},[T]);t.useEffect(()=>{B()},[B,x]);async function I(s){if(s.preventDefault(),!(!w.trim()||!E.trim())){z(!0);try{await W.addSource({name:w.trim(),type:g,category:E.trim(),url:C.trim()||void 0,keywords:v?v.split(",").map(U=>U.trim()).filter(Boolean):void 0}),y(""),S("rss"),P(""),F(""),i(""),b(!1),m()}catch{}z(!1)}}async function V(s){try{await W.deleteSource(s),m()}catch{}}async function d(s){try{await W.markRead(s),m()}catch{}}async function a(s){try{await W.toggleSaved(s),m()}catch{}}async function c(){try{await W.markAllRead(),m()}catch{}}return e.jsxs("div",{className:"p-4 sm:p-6 space-y-4 max-w-3xl",children:[n&&e.jsxs("div",{className:"flex items-center gap-4 text-xs text-cc-muted",children:[e.jsxs("span",{children:[n.total," articles"]}),e.jsxs("span",{className:n.unread>0?"text-cc-accent font-medium":"",children:[n.unread," unread"]}),e.jsxs("span",{children:[n.sources," sources"]}),n.unread>0&&e.jsx("button",{type:"button",onClick:c,className:"ml-auto text-xs text-cc-accent hover:text-cc-accent/80 transition-colors cursor-pointer",children:"Mark all read"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:T,onChange:s=>j(s.target.value),placeholder:"Search news...",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsx("button",{type:"button",onClick:()=>{R(!f),b(!1)},className:"px-3 py-2 text-sm border border-cc-border text-cc-fg rounded-md hover:bg-cc-hover transition-colors cursor-pointer",children:"Sources"}),e.jsx("button",{type:"button",onClick:()=>{b(!l),R(!1)},className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 transition-colors cursor-pointer shrink-0",children:"+ Source"})]}),f&&p.length>0&&e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-card p-4 space-y-2",children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted uppercase tracking-wider mb-2",children:"Sources"}),p.map(s=>e.jsxs("div",{className:"group flex items-center gap-3 py-1.5",children:[e.jsx("div",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${s.enabled?"bg-green-400":"bg-gray-500"}`}),e.jsx("span",{className:"text-sm text-cc-fg flex-1 truncate",children:s.name}),e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:s.type}),e.jsx("span",{className:"text-[10px] text-cc-muted",children:s.category}),e.jsx("button",{type:"button",onClick:()=>V(s.id),className:"opacity-0 group-hover:opacity-100 text-cc-muted hover:text-red-400 transition-opacity cursor-pointer p-1",title:"Delete source",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"w-3 h-3",fill:"currentColor",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.id))]}),l&&e.jsxs("form",{onSubmit:I,className:"rounded-lg border border-cc-border bg-cc-card p-4 space-y-3",children:[e.jsx("input",{type:"text",value:w,onChange:s=>y(s.target.value),placeholder:"Source name",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{value:g,onChange:s=>S(s.target.value),className:"px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg focus:outline-none focus:border-cc-accent cursor-pointer",children:[e.jsx("option",{value:"rss",children:"RSS Feed"}),e.jsx("option",{value:"website",children:"Website"}),e.jsx("option",{value:"keyword",children:"Keyword Monitor"})]}),e.jsx("input",{type:"text",value:E,onChange:s=>i(s.target.value),placeholder:"Category",className:"flex-1 px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"})]}),(g==="rss"||g==="website")&&e.jsx("input",{type:"text",value:C,onChange:s=>P(s.target.value),placeholder:"URL",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),g==="keyword"&&e.jsx("input",{type:"text",value:v,onChange:s=>F(s.target.value),placeholder:"Keywords (comma-separated)",className:"w-full px-3 py-2 text-sm bg-cc-input border border-cc-border rounded-md text-cc-fg placeholder-cc-muted focus:outline-none focus:border-cc-accent"}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>b(!1),className:"px-3 py-2 text-sm text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:N||!w.trim()||!E.trim(),className:"px-3 py-2 text-sm bg-cc-accent text-white rounded-md hover:bg-cc-accent/80 disabled:opacity-50 transition-colors cursor-pointer",children:N?"Adding...":"Add Source"})]})]}),u?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:"Loading..."}):o.length===0?e.jsx("div",{className:"text-sm text-cc-muted py-8 text-center",children:T?"No matching articles":"No news yet. Add sources to start monitoring."}):e.jsx("div",{className:"space-y-2",children:o.map(s=>e.jsx("div",{className:"group rounded-lg border border-cc-border bg-cc-card hover:border-cc-border-hover transition-colors px-4 py-3",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`w-1.5 h-1.5 rounded-full mt-1.5 shrink-0 ${s.read?"bg-transparent":"bg-cc-accent"}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:`text-sm font-medium ${s.read?"text-cc-muted":"text-cc-fg"}`,children:s.url?e.jsx("a",{href:s.url,target:"_blank",rel:"noopener noreferrer",className:"hover:underline",children:s.title}):s.title}),s.summary&&e.jsx("p",{className:"text-xs text-cc-muted mt-1 line-clamp-2",children:s.summary}),e.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[e.jsx("span",{className:"text-[10px] text-cc-muted",children:s.sourceName}),e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-cc-hover text-cc-muted",children:s.category}),e.jsx("span",{className:"text-[10px] text-cc-muted ml-auto",children:K(s.publishedAt)})]})]}),e.jsxs("div",{className:"flex gap-1 shrink-0",children:[!s.read&&e.jsx("button",{type:"button",onClick:()=>d(s.id),className:"text-[10px] px-1.5 py-0.5 text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",title:"Mark read",children:"read"}),e.jsx("button",{type:"button",onClick:()=>a(s.id),className:`text-[10px] px-1.5 py-0.5 transition-colors cursor-pointer ${s.saved?"text-yellow-400":"text-cc-muted hover:text-yellow-400"}`,title:s.saved?"Saved":"Save",children:s.saved?"saved":"save"})]})]})},s.id))})]})}export{De as AssistantPage};