@hellcoder/companion 0.96.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 (242) hide show
  1. package/bin/cli.ts +168 -0
  2. package/bin/ctl.ts +528 -0
  3. package/bin/generate-token.ts +28 -0
  4. package/dist/apple-touch-icon.png +0 -0
  5. package/dist/assets/AgentsPage-DCFhrJ28.js +13 -0
  6. package/dist/assets/CronManager-EGwLJONv.js +1 -0
  7. package/dist/assets/IntegrationsPage-CTMRnbQS.js +1 -0
  8. package/dist/assets/LinearOAuthSettingsPage-CgQFMIgr.js +1 -0
  9. package/dist/assets/LinearSettingsPage-C9nok1qi.js +1 -0
  10. package/dist/assets/Playground-BV3k0RbV.js +109 -0
  11. package/dist/assets/PromptsPage-CFojqNKP.js +4 -0
  12. package/dist/assets/RunsPage-DUJ1QUSa.js +1 -0
  13. package/dist/assets/SandboxManager-CrVQ-VU_.js +8 -0
  14. package/dist/assets/SettingsPage-D1fPCL19.js +1 -0
  15. package/dist/assets/TailscalePage-D06cyvyC.js +1 -0
  16. package/dist/assets/index-BhUa1e6X.css +1 -0
  17. package/dist/assets/index-DkqeP-R9.js +134 -0
  18. package/dist/assets/sw-register-BibwRdvC.js +1 -0
  19. package/dist/assets/workbox-window.prod.es5-BIl4cyR9.js +2 -0
  20. package/dist/favicon.svg +8 -0
  21. package/dist/fonts/MesloLGSNerdFontMono-Bold.woff2 +0 -0
  22. package/dist/fonts/MesloLGSNerdFontMono-Regular.woff2 +0 -0
  23. package/dist/icon-192.png +0 -0
  24. package/dist/icon-512.png +0 -0
  25. package/dist/index.html +20 -0
  26. package/dist/logo-codex.svg +14 -0
  27. package/dist/logo-docker.svg +4 -0
  28. package/dist/logo.svg +14 -0
  29. package/dist/manifest.json +24 -0
  30. package/dist/sw.js +2 -0
  31. package/package.json +104 -0
  32. package/server/agent-cron-migrator.test.ts +610 -0
  33. package/server/agent-cron-migrator.ts +85 -0
  34. package/server/agent-executor.test.ts +1108 -0
  35. package/server/agent-executor.ts +346 -0
  36. package/server/agent-store.test.ts +588 -0
  37. package/server/agent-store.ts +185 -0
  38. package/server/agent-types.ts +138 -0
  39. package/server/ai-validation-settings.test.ts +128 -0
  40. package/server/ai-validation-settings.ts +35 -0
  41. package/server/ai-validator.test.ts +387 -0
  42. package/server/ai-validator.ts +271 -0
  43. package/server/auth-manager.test.ts +83 -0
  44. package/server/auth-manager.ts +150 -0
  45. package/server/auto-namer.test.ts +252 -0
  46. package/server/auto-namer.ts +78 -0
  47. package/server/backend-adapter.test.ts +38 -0
  48. package/server/backend-adapter.ts +54 -0
  49. package/server/cache-headers.test.ts +98 -0
  50. package/server/cache-headers.ts +61 -0
  51. package/server/claude-adapter.test.ts +1363 -0
  52. package/server/claude-adapter.ts +889 -0
  53. package/server/claude-container-auth.test.ts +44 -0
  54. package/server/claude-container-auth.ts +30 -0
  55. package/server/claude-protocol-contract.test.ts +71 -0
  56. package/server/claude-protocol-drift.test.ts +78 -0
  57. package/server/claude-session-discovery.test.ts +132 -0
  58. package/server/claude-session-discovery.ts +157 -0
  59. package/server/claude-session-history.test.ts +158 -0
  60. package/server/claude-session-history.ts +410 -0
  61. package/server/cli-launcher.test.ts +1343 -0
  62. package/server/cli-launcher.ts +1298 -0
  63. package/server/cli.test.ts +16 -0
  64. package/server/codex-adapter.test.ts +5545 -0
  65. package/server/codex-adapter.ts +3062 -0
  66. package/server/codex-container-auth.test.ts +50 -0
  67. package/server/codex-container-auth.ts +24 -0
  68. package/server/codex-home.test.ts +61 -0
  69. package/server/codex-home.ts +26 -0
  70. package/server/codex-protocol-contract.test.ts +96 -0
  71. package/server/codex-protocol-drift.test.ts +123 -0
  72. package/server/codex-ws-proxy.cjs +226 -0
  73. package/server/commands-discovery.test.ts +179 -0
  74. package/server/commands-discovery.ts +81 -0
  75. package/server/constants.ts +7 -0
  76. package/server/container-manager.test.ts +1211 -0
  77. package/server/container-manager.ts +1053 -0
  78. package/server/cron-scheduler.test.ts +957 -0
  79. package/server/cron-scheduler.ts +243 -0
  80. package/server/cron-store.test.ts +422 -0
  81. package/server/cron-store.ts +148 -0
  82. package/server/cron-types.ts +63 -0
  83. package/server/env-manager.test.ts +268 -0
  84. package/server/env-manager.ts +161 -0
  85. package/server/event-bus-types.ts +64 -0
  86. package/server/event-bus.test.ts +244 -0
  87. package/server/event-bus.ts +124 -0
  88. package/server/execution-store.test.ts +307 -0
  89. package/server/execution-store.ts +170 -0
  90. package/server/fs-utils.ts +15 -0
  91. package/server/git-utils.test.ts +938 -0
  92. package/server/git-utils.ts +421 -0
  93. package/server/github-pr.test.ts +498 -0
  94. package/server/github-pr.ts +379 -0
  95. package/server/image-pull-manager.test.ts +303 -0
  96. package/server/image-pull-manager.ts +279 -0
  97. package/server/index.ts +396 -0
  98. package/server/linear-agent-bridge.test.ts +1157 -0
  99. package/server/linear-agent-bridge.ts +629 -0
  100. package/server/linear-agent.test.ts +473 -0
  101. package/server/linear-agent.ts +479 -0
  102. package/server/linear-cache.test.ts +136 -0
  103. package/server/linear-cache.ts +113 -0
  104. package/server/linear-connections.test.ts +350 -0
  105. package/server/linear-connections.ts +231 -0
  106. package/server/linear-credential-migration.test.ts +337 -0
  107. package/server/linear-credential-migration.ts +63 -0
  108. package/server/linear-oauth-connections-migration.test.ts +268 -0
  109. package/server/linear-oauth-connections.test.ts +365 -0
  110. package/server/linear-oauth-connections.ts +294 -0
  111. package/server/linear-project-manager.test.ts +162 -0
  112. package/server/linear-project-manager.ts +111 -0
  113. package/server/linear-prompt-builder.test.ts +74 -0
  114. package/server/linear-prompt-builder.ts +61 -0
  115. package/server/linear-staging.test.ts +276 -0
  116. package/server/linear-staging.ts +142 -0
  117. package/server/logger.test.ts +393 -0
  118. package/server/logger.ts +259 -0
  119. package/server/metrics-collector.test.ts +413 -0
  120. package/server/metrics-collector.ts +350 -0
  121. package/server/metrics-types.ts +108 -0
  122. package/server/middleware/managed-auth.test.ts +264 -0
  123. package/server/middleware/managed-auth.ts +195 -0
  124. package/server/novnc-proxy.test.ts +333 -0
  125. package/server/novnc-proxy.ts +99 -0
  126. package/server/path-resolver.test.ts +552 -0
  127. package/server/path-resolver.ts +186 -0
  128. package/server/paths.test.ts +31 -0
  129. package/server/paths.ts +11 -0
  130. package/server/pr-poller.test.ts +191 -0
  131. package/server/pr-poller.ts +162 -0
  132. package/server/prompt-manager.test.ts +211 -0
  133. package/server/prompt-manager.ts +211 -0
  134. package/server/protocol/claude-upstream/README.md +19 -0
  135. package/server/protocol/claude-upstream/sdk.d.ts.txt +1943 -0
  136. package/server/protocol/codex-upstream/ClientNotification.ts.txt +5 -0
  137. package/server/protocol/codex-upstream/ClientRequest.ts.txt +60 -0
  138. package/server/protocol/codex-upstream/README.md +18 -0
  139. package/server/protocol/codex-upstream/ServerNotification.ts.txt +41 -0
  140. package/server/protocol/codex-upstream/ServerRequest.ts.txt +16 -0
  141. package/server/protocol/codex-upstream/v2/DynamicToolCallParams.ts.txt +6 -0
  142. package/server/protocol/codex-upstream/v2/DynamicToolCallResponse.ts.txt +6 -0
  143. package/server/protocol-monitor.ts +50 -0
  144. package/server/recorder.test.ts +454 -0
  145. package/server/recorder.ts +374 -0
  146. package/server/recording-hub/compat-validator.test.ts +150 -0
  147. package/server/recording-hub/compat-validator.ts +284 -0
  148. package/server/recording-hub/diagnostics.test.ts +140 -0
  149. package/server/recording-hub/diagnostics.ts +299 -0
  150. package/server/recording-hub/hub-config.test.ts +44 -0
  151. package/server/recording-hub/hub-config.ts +19 -0
  152. package/server/recording-hub/hub-routes.test.ts +417 -0
  153. package/server/recording-hub/hub-routes.ts +236 -0
  154. package/server/recording-hub/hub-store.test.ts +262 -0
  155. package/server/recording-hub/hub-store.ts +265 -0
  156. package/server/recording-hub/replay-adapter.test.ts +294 -0
  157. package/server/recording-hub/replay-adapter.ts +207 -0
  158. package/server/relay-client.test.ts +337 -0
  159. package/server/relay-client.ts +320 -0
  160. package/server/replay.test.ts +200 -0
  161. package/server/replay.ts +78 -0
  162. package/server/routes/agent-routes.test.ts +1400 -0
  163. package/server/routes/agent-routes.ts +409 -0
  164. package/server/routes/cron-routes.test.ts +881 -0
  165. package/server/routes/cron-routes.ts +103 -0
  166. package/server/routes/env-routes.test.ts +383 -0
  167. package/server/routes/env-routes.ts +95 -0
  168. package/server/routes/fs-routes.test.ts +1198 -0
  169. package/server/routes/fs-routes.ts +605 -0
  170. package/server/routes/git-routes.test.ts +813 -0
  171. package/server/routes/git-routes.ts +97 -0
  172. package/server/routes/linear-agent-routes.test.ts +721 -0
  173. package/server/routes/linear-agent-routes.ts +304 -0
  174. package/server/routes/linear-connection-routes.test.ts +927 -0
  175. package/server/routes/linear-connection-routes.ts +244 -0
  176. package/server/routes/linear-oauth-connection-routes.test.ts +406 -0
  177. package/server/routes/linear-oauth-connection-routes.ts +129 -0
  178. package/server/routes/linear-routes.test.ts +1510 -0
  179. package/server/routes/linear-routes.ts +953 -0
  180. package/server/routes/metrics-routes.test.ts +103 -0
  181. package/server/routes/metrics-routes.ts +13 -0
  182. package/server/routes/prompt-routes.ts +67 -0
  183. package/server/routes/sandbox-routes.test.ts +513 -0
  184. package/server/routes/sandbox-routes.ts +127 -0
  185. package/server/routes/settings-routes.ts +270 -0
  186. package/server/routes/skills-routes.test.ts +690 -0
  187. package/server/routes/skills-routes.ts +100 -0
  188. package/server/routes/system-routes.test.ts +637 -0
  189. package/server/routes/system-routes.ts +228 -0
  190. package/server/routes/tailscale-routes.test.ts +176 -0
  191. package/server/routes/tailscale-routes.ts +22 -0
  192. package/server/routes.test.ts +4655 -0
  193. package/server/routes.ts +1277 -0
  194. package/server/sandbox-manager.test.ts +378 -0
  195. package/server/sandbox-manager.ts +168 -0
  196. package/server/service.test.ts +1419 -0
  197. package/server/service.ts +718 -0
  198. package/server/session-creation-service.test.ts +661 -0
  199. package/server/session-creation-service.ts +473 -0
  200. package/server/session-git-info.ts +104 -0
  201. package/server/session-linear-issues.test.ts +118 -0
  202. package/server/session-linear-issues.ts +88 -0
  203. package/server/session-names.test.ts +94 -0
  204. package/server/session-names.ts +67 -0
  205. package/server/session-orchestrator.test.ts +1784 -0
  206. package/server/session-orchestrator.ts +973 -0
  207. package/server/session-state-machine.test.ts +606 -0
  208. package/server/session-state-machine.ts +207 -0
  209. package/server/session-store.test.ts +290 -0
  210. package/server/session-store.ts +146 -0
  211. package/server/session-types.ts +509 -0
  212. package/server/settings-manager.test.ts +275 -0
  213. package/server/settings-manager.ts +173 -0
  214. package/server/tailscale-manager.test.ts +553 -0
  215. package/server/tailscale-manager.ts +451 -0
  216. package/server/terminal-manager.ts +240 -0
  217. package/server/update-checker.test.ts +306 -0
  218. package/server/update-checker.ts +197 -0
  219. package/server/usage-limits.test.ts +536 -0
  220. package/server/usage-limits.ts +225 -0
  221. package/server/worktree-tracker.test.ts +243 -0
  222. package/server/worktree-tracker.ts +84 -0
  223. package/server/ws-auth.test.ts +59 -0
  224. package/server/ws-auth.ts +41 -0
  225. package/server/ws-bridge-browser-ingest.test.ts +272 -0
  226. package/server/ws-bridge-browser-ingest.ts +72 -0
  227. package/server/ws-bridge-browser.ts +112 -0
  228. package/server/ws-bridge-cli-ingest.test.ts +302 -0
  229. package/server/ws-bridge-cli-ingest.ts +81 -0
  230. package/server/ws-bridge-codex.test.ts +1837 -0
  231. package/server/ws-bridge-codex.ts +266 -0
  232. package/server/ws-bridge-controls.test.ts +124 -0
  233. package/server/ws-bridge-controls.ts +20 -0
  234. package/server/ws-bridge-persist.test.ts +296 -0
  235. package/server/ws-bridge-persist.ts +66 -0
  236. package/server/ws-bridge-publish.test.ts +234 -0
  237. package/server/ws-bridge-publish.ts +79 -0
  238. package/server/ws-bridge-replay.test.ts +44 -0
  239. package/server/ws-bridge-replay.ts +61 -0
  240. package/server/ws-bridge-types.ts +106 -0
  241. package/server/ws-bridge.test.ts +4777 -0
  242. package/server/ws-bridge.ts +1279 -0
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Generate (or regenerate) the Companion auth token.
4
+ *
5
+ * Usage:
6
+ * bun run generate-token # show current or auto-generated token
7
+ * bun run generate-token --force # force-regenerate a new token
8
+ */
9
+ import { existsSync, rmSync } from "node:fs";
10
+ import { join } from "node:path";
11
+ import { homedir } from "node:os";
12
+
13
+ const AUTH_FILE = join(homedir(), ".companion", "auth.json");
14
+ const force = process.argv.includes("--force");
15
+
16
+ if (force && existsSync(AUTH_FILE)) {
17
+ rmSync(AUTH_FILE);
18
+ }
19
+
20
+ // Import after potential delete so getToken() generates fresh
21
+ const { getToken } = await import("../server/auth-manager.ts");
22
+
23
+ const token = getToken();
24
+ const isNew = force ? "New" : existsSync(AUTH_FILE) ? "Current" : "Generated";
25
+
26
+ console.log(`\n ${isNew} auth token: ${token}\n`);
27
+ console.log(` Stored at: ${AUTH_FILE}`);
28
+ console.log(` Tip: pass --force to regenerate\n`);
Binary file
@@ -0,0 +1,13 @@
1
+ import{r,j as e,u as Be,a as z,x as ae,F as ye,L as ne,t as Ee,B as we,y as Oe,E as Ie}from"./index-DkqeP-R9.js";const ze="companion_public_url_dismissed";function De({publicUrl:t}){const[i,d]=r.useState(()=>localStorage.getItem(ze)==="1");return t||i?null:e.jsxs("div",{className:"mb-4 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/30 text-amber-400 text-xs flex items-start justify-between gap-3",role:"alert",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"No public URL configured."})," ","Webhook URLs currently use your browser address, which external services like Linear may not be able to reach."," ",e.jsx("a",{href:"#/settings",className:"underline hover:text-amber-300",children:"Set your public URL in Settings"}),"."]}),e.jsx("button",{onClick:()=>{localStorage.setItem(ze,"1"),d(!0)},className:"text-amber-400 hover:text-amber-200 transition-colors cursor-pointer flex-shrink-0","aria-label":"Dismiss public URL banner",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]})}function He({steps:t,currentStep:i,completedSteps:d}){return e.jsx("nav",{"aria-label":"Setup progress",className:"flex items-center gap-0 w-full mb-8",children:t.map((a,m)=>{const u=m+1,h=d.has(u),g=u===i,v=!h&&!g;return e.jsxs("div",{className:"flex items-center flex-1 last:flex-none",children:[e.jsxs("div",{className:"flex flex-col items-center gap-1.5",children:[e.jsx("div",{className:`flex items-center justify-center w-8 h-8 rounded-full text-xs font-semibold border-2 transition-colors ${h?"bg-cc-success/15 border-cc-success text-cc-success":g?"bg-cc-primary/15 border-cc-primary text-cc-primary":"bg-cc-hover border-cc-border text-cc-muted"}`,"aria-current":g?"step":void 0,"aria-label":`Step ${u}: ${a.label}${h?" (completed)":g?" (current)":""}`,children:h?e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):u}),e.jsx("span",{className:`text-[10px] whitespace-nowrap ${v?"text-cc-muted":g?"text-cc-primary font-medium":"text-cc-success"}`,children:a.label})]}),m<t.length-1&&e.jsx("div",{className:`flex-1 h-0.5 mx-2 mt-[-18px] rounded ${d.has(u)?"bg-cc-success/40":"bg-cc-border"}`})]},u)})})}function Pe({onNext:t}){const i=Be(m=>m.publicUrl),d=i||window.location.origin,a=!!i;return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"pt-1",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-widest text-cc-primary font-medium mb-2",children:"Linear Agent Setup"}),e.jsx("h2",{className:"text-xl font-semibold text-cc-fg tracking-tight leading-tight",children:"Connect your Linear workspace"}),e.jsx("p",{className:"mt-2 text-sm text-cc-muted leading-relaxed max-w-md",children:"This wizard connects the Agent Interaction SDK so your agent can respond to @mentions in Linear issues."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`mt-0.5 flex-shrink-0 w-5 h-5 rounded-full flex items-center justify-center ${a?"bg-cc-success/15 text-cc-success":"bg-cc-warning/15 text-cc-warning"}`,children:a?e.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):e.jsx("span",{className:"text-[10px] font-bold",children:"!"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[13px] text-cc-fg font-medium",children:"Public URL"}),e.jsx("p",{className:"text-xs text-cc-muted mt-0.5 leading-relaxed",children:a?e.jsx(e.Fragment,{children:e.jsx("code",{className:"px-1 py-0.5 rounded bg-cc-hover text-[10px] font-mono-code",children:i})}):e.jsxs(e.Fragment,{children:["Not set. Linear needs to reach your instance. Configure in ",e.jsx("a",{href:"#/integrations/tailscale",className:"text-cc-primary hover:underline",children:"Tailscale"})," or ",e.jsx("a",{href:"#/settings",className:"text-cc-primary hover:underline",children:"Settings"}),"."]})})]})]}),e.jsx("div",{className:"border-t border-cc-border/50"}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 flex-shrink-0 w-5 h-5 rounded-full flex items-center justify-center bg-cc-hover text-cc-muted",children:e.jsx("span",{className:"text-[10px] font-semibold",children:"1"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[13px] text-cc-fg font-medium",children:"Create a Linear OAuth app"}),e.jsx("p",{className:"text-xs text-cc-muted mt-0.5 leading-relaxed",children:e.jsx("a",{href:"https://linear.app/settings/api",target:"_blank",rel:"noopener noreferrer",className:"text-cc-primary hover:underline",children:"Linear → Settings → API → OAuth Applications"})}),e.jsxs("dl",{className:"mt-3 space-y-2.5 text-xs",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-cc-muted",children:"Webhooks"}),e.jsxs("dd",{className:"text-cc-fg mt-0.5",children:["Enable and subscribe to ",e.jsx("strong",{children:"Agent session events"})]})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-cc-muted",children:"Scope"}),e.jsx("dd",{className:"mt-0.5",children:e.jsx("code",{className:"px-1.5 py-0.5 rounded bg-cc-hover text-cc-fg text-[10px] font-mono-code",children:"app:mentionable"})})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-cc-muted",children:"Redirect URI"}),e.jsx("dd",{className:"mt-0.5",children:e.jsx("code",{className:"px-1.5 py-0.5 rounded bg-cc-hover text-cc-fg text-[10px] font-mono-code break-all",children:`${d}/api/linear/oauth/callback`})})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-cc-muted",children:"Webhook URL"}),e.jsx("dd",{className:"mt-0.5",children:e.jsx("code",{className:"px-1.5 py-0.5 rounded bg-cc-hover text-cc-fg text-[10px] font-mono-code break-all",children:`${d}/api/linear/agent-webhook`})})]})]})]})]})]}),e.jsx("div",{className:"flex justify-end pt-1",children:e.jsx("button",{onClick:t,className:"px-5 py-2.5 rounded-lg text-sm font-medium bg-cc-primary hover:bg-cc-primary-hover text-white transition-colors cursor-pointer",children:"Next"})})]})}function Ue({onNext:t,onBack:i,selectedConnectionId:d}){const[a,m]=r.useState([]),[u,h]=r.useState(!0),[g,v]=r.useState(d||""),[j,o]=r.useState("");r.useEffect(()=>{z.listLinearOAuthConnections().then(b=>{m(b.connections),o(""),d?b.connections.some(p=>p.id===d)&&v(d):b.connections.length===1&&v(b.connections[0].id)}).catch(b=>o(b instanceof Error?b.message:String(b))).finally(()=>h(!1))},[d]);const y=a.find(b=>b.id===g),k=!!g&&(y==null?void 0:y.status)==="connected";return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-cc-fg",children:"Select OAuth Connection"}),e.jsx("p",{className:"mt-1 text-sm text-cc-muted",children:"Choose which Linear OAuth app this agent should use for @mention triggers."})]}),j&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:j}),u?e.jsx("p",{className:"text-sm text-cc-muted",children:"Loading connections..."}):a.length===0?e.jsxs("div",{className:"rounded-lg border border-cc-border bg-cc-bg p-5 text-center space-y-3",children:[e.jsx("p",{className:"text-sm text-cc-muted",children:"No OAuth connections found."}),e.jsx("p",{className:"text-xs text-cc-muted",children:"Create an OAuth app connection first, then come back to set up the agent."}),e.jsx("a",{href:"#/integrations/linear-oauth",className:"inline-flex px-4 py-2.5 rounded-lg text-sm font-medium bg-cc-primary hover:bg-cc-primary-hover text-white transition-colors",children:"Go to OAuth Settings"})]}):e.jsxs("div",{className:"space-y-3",children:[a.map(b=>{const C=g===b.id,p=b.status==="connected";return e.jsxs("button",{type:"button",onClick:()=>v(b.id),className:`w-full text-left p-4 rounded-lg border transition-colors cursor-pointer ${C?"border-cc-primary bg-cc-primary/5":"border-cc-border hover:border-cc-border hover:bg-cc-hover/50"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:`w-4 h-4 rounded-full border-2 flex items-center justify-center flex-shrink-0 ${C?"border-cc-primary":"border-cc-border"}`,children:C&&e.jsx("div",{className:"w-2 h-2 rounded-full bg-cc-primary"})}),e.jsx("span",{className:"text-sm font-medium text-cc-fg truncate",children:b.name})]}),e.jsx("span",{className:`px-2 py-0.5 text-[10px] rounded-full border flex-shrink-0 ${p?"bg-cc-success/10 text-cc-success border-cc-success/20":"bg-cc-hover text-cc-muted border-cc-border"}`,children:p?"Connected":"Not installed"})]}),!p&&C&&e.jsxs("p",{className:"mt-2 ml-6 text-xs text-cc-warning",children:["This connection needs to be installed to a workspace first."," ",e.jsx("a",{href:"#/integrations/linear-oauth",className:"text-cc-primary underline",onClick:S=>S.stopPropagation(),children:"Install now"})]})]},b.id)}),e.jsx("a",{href:"#/integrations/linear-oauth",className:"block text-center text-xs text-cc-primary hover:underline py-2",children:"+ Create a new OAuth connection"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("button",{onClick:i,className:"px-4 py-2.5 rounded-lg text-sm font-medium text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Back"}),e.jsx("button",{onClick:()=>k&&t(g),disabled:!k,className:`px-4 py-2.5 rounded-lg text-sm font-medium transition-colors ${k?"bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer":"bg-cc-hover text-cc-muted cursor-not-allowed"}`,children:"Next"})]})]})}const Ve=`You are an AI agent responding to a Linear issue. The issue context will be provided when you are @mentioned.
2
+
3
+ Read the issue details carefully, then complete the requested task. When done, summarize what you did.
4
+
5
+ {{input}}`;function Fe({onNext:t,onBack:i,oauthConnectionId:d,stagingId:a,cloneFromAgentId:m,existingAgent:u}){const h=!!u,[g,v]=r.useState((u==null?void 0:u.name)??"Linear Agent"),[j,o]=r.useState((u==null?void 0:u.prompt)??Ve),[y,k]=r.useState((u==null?void 0:u.backendType)??"claude"),[b,C]=r.useState((u==null?void 0:u.model)??""),[p,S]=r.useState((u==null?void 0:u.cwd)??""),[M,E]=r.useState(!1),[w,L]=r.useState(!1),[B,R]=r.useState(""),U=p?p.split("/").pop()||p:"Temp directory";async function V(){if(!g.trim()){R("Agent name is required.");return}if(!j.trim()){R("Agent prompt is required.");return}L(!0),R("");try{const l={version:1,name:g.trim(),description:"Linear Agent created via setup wizard",backendType:y,model:b||ae(y),permissionMode:"bypassPermissions",cwd:p||"",prompt:j.trim(),triggers:{webhook:{enabled:!1,secret:""},schedule:{enabled:!1,expression:"",recurring:!0},linear:{enabled:!0,...d?{oauthConnectionId:d}:{}}},enabled:!0};if(h)await z.updateAgent(u.id,l),t(u.id,g.trim());else{const I=await z.createAgent({...l,...a?{stagingId:a}:{},...m?{cloneFromAgentId:m}:{}});t(I.id,I.name)}}catch(l){R(l instanceof Error?l.message:String(l))}finally{L(!1)}}const D="w-full px-3 py-2.5 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/60";return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-cc-fg",children:h?"Edit Linear Agent":"Configure Your Agent"}),e.jsx("p",{className:"mt-1 text-sm text-cc-muted",children:h?"Update the agent settings. These can be customized further in the Agents page.":"Set up the agent that will respond to @mentions in Linear. You can customize it further in the Agents page later."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-cc-fg mb-1.5",htmlFor:"wizard-agent-name",children:"Agent Name"}),e.jsx("input",{id:"wizard-agent-name",type:"text",value:g,onChange:l=>v(l.target.value),placeholder:"My Linear Agent",className:D})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-cc-fg mb-1.5",children:"Backend"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>{k("claude"),C("")},className:`flex-1 px-3 py-2 rounded-lg text-sm font-medium border transition-colors cursor-pointer ${y==="claude"?"border-cc-primary bg-cc-primary/10 text-cc-primary":"border-cc-border text-cc-muted hover:text-cc-fg"}`,children:"Claude Code"}),e.jsx("button",{onClick:()=>{k("codex"),C("")},className:`flex-1 px-3 py-2 rounded-lg text-sm font-medium border transition-colors cursor-pointer ${y==="codex"?"border-cc-primary bg-cc-primary/10 text-cc-primary":"border-cc-border text-cc-muted hover:text-cc-fg"}`,children:"Codex"})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-cc-fg mb-1.5",htmlFor:"wizard-agent-model",children:["Model ",e.jsx("span",{className:"text-cc-muted font-normal",children:"(optional)"})]}),e.jsx("input",{id:"wizard-agent-model",type:"text",value:b,onChange:l=>C(l.target.value),placeholder:`${ae(y)} (default)`,className:D})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-cc-fg mb-1.5",children:"Working Directory"}),e.jsxs("button",{onClick:()=>E(!0),className:"flex items-center gap-2 px-3 py-2.5 rounded-lg border border-cc-border bg-cc-input-bg text-sm text-cc-fg hover:border-cc-primary/40 transition-colors cursor-pointer w-full text-left",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4 text-cc-muted flex-shrink-0",children:e.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.879a1.5 1.5 0 011.06.44l1.122 1.12A1.5 1.5 0 009.62 4H13.5A1.5 1.5 0 0115 5.5v7a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})}),e.jsx("span",{className:"truncate font-mono-code text-cc-muted",children:U}),p&&e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-muted hover:text-cc-fg flex-shrink-0 ml-auto",onClick:l=>{l.stopPropagation(),S("")},children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})]}),e.jsx("p",{className:"text-[10px] text-cc-muted mt-1",children:"Leave empty to use a temporary directory for each run."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-cc-fg mb-1.5",htmlFor:"wizard-agent-prompt",children:"Prompt"}),e.jsx("textarea",{id:"wizard-agent-prompt",value:j,onChange:l=>o(l.target.value),rows:6,placeholder:"Instructions for your agent...",className:`${D} font-mono-code text-xs leading-relaxed resize-y`}),e.jsxs("p",{className:"text-[10px] text-cc-muted mt-1",children:["Use ",e.jsx("code",{className:"px-1 py-0.5 rounded bg-cc-hover",children:"{{input}}"})," as a placeholder for the trigger-provided context."]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded-full text-xs font-medium bg-cc-success/10 text-cc-success border border-cc-success/20",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:e.jsx("path",{d:"M3 1a1 1 0 00-1 1v12a1 1 0 001 1h10a1 1 0 001-1V2a1 1 0 00-1-1H3zm1 2h8v2H4V3zm0 4h5v2H4V7zm0 4h8v2H4v-2z"})}),"Linear Agent trigger enabled"]})})]}),B&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:B}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("button",{onClick:i,className:"px-4 py-2.5 rounded-lg text-sm font-medium text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Back"}),e.jsx("button",{onClick:V,disabled:w,className:`px-4 py-2.5 rounded-lg text-sm font-medium transition-colors ${w?"bg-cc-hover text-cc-muted cursor-not-allowed":"bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer"}`,children:w?h?"Saving...":"Creating...":h?"Save Agent":"Create Agent"})]}),M&&e.jsx(ye,{initialPath:p||"/",onSelect:l=>{S(l),E(!1)},onClose:()=>E(!1)})]})}function _e({agentName:t,onFinish:i,onAddAnotherSameApp:d,onAddAnotherNewApp:a}){const[m,u]=r.useState(!1);return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"pt-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-5 h-5 rounded-full bg-cc-success/15 flex items-center justify-center",children:e.jsx("svg",{className:"w-3 h-3 text-cc-success",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})}),e.jsx("p",{className:"text-[11px] uppercase tracking-widest text-cc-success font-medium",children:"Complete"})]}),e.jsxs("h2",{className:"text-xl font-semibold text-cc-fg tracking-tight leading-tight",children:[t," is live"]}),e.jsx("p",{className:"mt-2 text-sm text-cc-muted leading-relaxed max-w-md",children:"Your agent is connected and listening for @mentions in Linear."})]}),e.jsx("div",{className:"space-y-3",children:[{label:"OAuth app connected",detail:"Your Linear workspace is linked"},{label:`Agent "${t}" created`,detail:"Linear trigger enabled with full auto permissions"},{label:"Ready for @mentions",detail:"Mention the agent in any issue to trigger a session"}].map(h=>e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 flex-shrink-0 w-5 h-5 rounded-full bg-cc-success/12 flex items-center justify-center",children:e.jsx("svg",{className:"w-2.5 h-2.5 text-cc-success",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[13px] font-medium text-cc-fg",children:h.label}),e.jsx("p",{className:"text-xs text-cc-muted mt-0.5",children:h.detail})]})]},h.label))}),e.jsxs("div",{className:"border-t border-cc-border/50 pt-5",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-widest text-cc-muted font-medium mb-3",children:"Next steps"}),e.jsxs("ul",{className:"space-y-2 text-xs text-cc-muted leading-relaxed",children:[e.jsxs("li",{children:["@mention ",e.jsx("strong",{className:"text-cc-fg",children:t})," in any Linear issue to test it"]}),e.jsxs("li",{children:["Fine-tune in the"," ",e.jsx("a",{href:"#/agents",className:"text-cc-primary hover:underline",children:"Agents page"})]}),e.jsxs("li",{children:["Manage credentials in"," ",e.jsx("a",{href:"#/integrations/linear-oauth",className:"text-cc-primary hover:underline",children:"OAuth Settings"})]})]})]}),m&&(d||a)&&e.jsxs("div",{className:"border-t border-cc-border/50 pt-5 space-y-3",children:[e.jsx("p",{className:"text-[13px] font-medium text-cc-fg",children:"Create another agent"}),e.jsx("p",{className:"text-xs text-cc-muted",children:"Reuse the same OAuth connection or set up a new one?"}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[d&&e.jsx("button",{onClick:d,className:"flex-1 px-3 py-2.5 rounded-lg text-xs font-medium border border-cc-border text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Same OAuth app"}),a&&e.jsx("button",{onClick:a,className:"flex-1 px-3 py-2.5 rounded-lg text-xs font-medium border border-cc-border text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Different OAuth app"})]})]}),e.jsxs("div",{className:"flex justify-between pt-1",children:[(d||a)&&!m&&e.jsx("button",{onClick:()=>u(!0),className:"text-xs font-medium text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"+ Create Another Agent"}),e.jsx("button",{onClick:i,className:"px-5 py-2.5 rounded-lg text-sm font-medium bg-cc-primary hover:bg-cc-primary-hover text-white transition-colors cursor-pointer ml-auto",children:"Go to Agents"})]})]})}const Ye=["bot","terminal","pencil","search","shield","chart","flask","rocket","wrench","clipboard","lightbulb","code","globe","zap","database","git-branch","mail","cpu"];function he({icon:t,className:i="w-5 h-5"}){const a={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",className:`${i} shrink-0`,role:"img","aria-label":t||"bot"};switch(t){case"bot":return e.jsxs("svg",{...a,children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),e.jsx("circle",{cx:"9",cy:"16",r:"1"}),e.jsx("circle",{cx:"15",cy:"16",r:"1"}),e.jsx("path",{d:"M12 2v4"}),e.jsx("path",{d:"M8 7h8"}),e.jsx("circle",{cx:"12",cy:"2",r:"1"})]});case"terminal":return e.jsxs("svg",{...a,children:[e.jsx("polyline",{points:"4 17 10 11 4 5"}),e.jsx("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]});case"pencil":return e.jsx("svg",{...a,children:e.jsx("path",{d:"M17 3a2.83 2.83 0 114 4L7.5 20.5 2 22l1.5-5.5Z"})});case"search":return e.jsxs("svg",{...a,children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]});case"shield":return e.jsx("svg",{...a,children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})});case"chart":return e.jsxs("svg",{...a,children:[e.jsx("line",{x1:"18",y1:"20",x2:"18",y2:"10"}),e.jsx("line",{x1:"12",y1:"20",x2:"12",y2:"4"}),e.jsx("line",{x1:"6",y1:"20",x2:"6",y2:"14"})]});case"flask":return e.jsxs("svg",{...a,children:[e.jsx("path",{d:"M9 3h6V8l5 10a1 1 0 01-.9 1.4H4.9A1 1 0 014 18L9 8V3z"}),e.jsx("line",{x1:"9",y1:"3",x2:"15",y2:"3"})]});case"rocket":return e.jsxs("svg",{...a,children:[e.jsx("path",{d:"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 00-2.91-.09z"}),e.jsx("path",{d:"M12 15l-3-3a22 22 0 012-3.95A12.88 12.88 0 0122 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 01-4 2z"}),e.jsx("path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"}),e.jsx("path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"})]});case"wrench":return e.jsx("svg",{...a,children:e.jsx("path",{d:"M14.7 6.3a1 1 0 000 1.4l1.6 1.6a1 1 0 001.4 0l3.77-3.77a6 6 0 01-7.94 7.94l-6.91 6.91a2.12 2.12 0 01-3-3l6.91-6.91a6 6 0 017.94-7.94l-3.76 3.76z"})});case"clipboard":return e.jsxs("svg",{...a,children:[e.jsx("path",{d:"M16 4h2a2 2 0 012 2v14a2 2 0 01-2 2H6a2 2 0 01-2-2V6a2 2 0 012-2h2"}),e.jsx("rect",{x:"8",y:"2",width:"8",height:"4",rx:"1"})]});case"lightbulb":return e.jsxs("svg",{...a,children:[e.jsx("path",{d:"M9 18h6"}),e.jsx("path",{d:"M10 22h4"}),e.jsx("path",{d:"M12 2a7 7 0 00-3 13.33V17h6v-1.67A7 7 0 0012 2z"})]});case"code":return e.jsxs("svg",{...a,children:[e.jsx("polyline",{points:"16 18 22 12 16 6"}),e.jsx("polyline",{points:"8 6 2 12 8 18"})]});case"globe":return e.jsxs("svg",{...a,children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"2",y1:"12",x2:"22",y2:"12"}),e.jsx("path",{d:"M12 2a15.3 15.3 0 014 10 15.3 15.3 0 01-4 10 15.3 15.3 0 01-4-10 15.3 15.3 0 014-10z"})]});case"zap":return e.jsx("svg",{...a,children:e.jsx("polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2"})});case"database":return e.jsxs("svg",{...a,children:[e.jsx("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),e.jsx("path",{d:"M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"}),e.jsx("path",{d:"M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"})]});case"git-branch":return e.jsxs("svg",{...a,children:[e.jsx("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),e.jsx("circle",{cx:"18",cy:"6",r:"3"}),e.jsx("circle",{cx:"6",cy:"18",r:"3"}),e.jsx("path",{d:"M18 9a9 9 0 01-9 9"})]});case"mail":return e.jsxs("svg",{...a,children:[e.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),e.jsx("polyline",{points:"22 7 12 13 2 7"})]});case"cpu":return e.jsxs("svg",{...a,children:[e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),e.jsx("rect",{x:"9",y:"9",width:"6",height:"6"}),e.jsx("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),e.jsx("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),e.jsx("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),e.jsx("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),e.jsx("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),e.jsx("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),e.jsx("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),e.jsx("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]});default:return t?e.jsx("span",{className:i,children:t}):e.jsxs("svg",{...a,children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),e.jsx("circle",{cx:"9",cy:"16",r:"1"}),e.jsx("circle",{cx:"15",cy:"16",r:"1"}),e.jsx("path",{d:"M12 2v4"}),e.jsx("path",{d:"M8 7h8"}),e.jsx("circle",{cx:"12",cy:"2",r:"1"})]})}}function Je({agent:t,copiedWebhook:i,onEdit:d,onDelete:a,onToggle:m,onExport:u,onCopyWebhook:h,onRegenerateSecret:g}){var b,C;const[v,j]=r.useState(!1),o=r.useRef(null);r.useEffect(()=>{if(!v)return;function p(S){o.current&&!o.current.contains(S.target)&&j(!1)}return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[v]),r.useEffect(()=>{if(!v)return;function p(S){S.key==="Escape"&&j(!1)}return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[v]);const y=(C=(b=t.triggers)==null?void 0:b.webhook)==null?void 0:C.enabled;function k(p){j(!1),p()}return e.jsxs("div",{className:"relative",ref:o,children:[e.jsx("button",{onClick:()=>j(!v),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":v,"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"})]})}),v&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 w-48 bg-cc-card border border-cc-border rounded-xl shadow-lg z-20 py-1 origin-top-right",style:{animation:"menu-appear 120ms ease-out"},role:"menu",children:[e.jsxs("button",{onClick:()=>k(d),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:e.jsx("path",{d:"M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25c.081-.286.235-.547.445-.758l8.61-8.61z"})}),"Edit"]}),e.jsxs("button",{onClick:()=>k(u),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:e.jsx("path",{d:"M3.5 13a.5.5 0 01-.5-.5V11h1v1h8v-1h1v1.5a.5.5 0 01-.5.5h-9zM8 2a.5.5 0 01.5.5v6.793l2.146-2.147a.5.5 0 01.708.708l-3 3a.5.5 0 01-.708 0l-3-3a.5.5 0 01.708-.708L7.5 9.293V2.5A.5.5 0 018 2z"})}),"Export JSON"]}),y&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"my-1 border-t border-cc-border/40",role:"separator"}),e.jsxs("button",{onClick:()=>k(h),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:[e.jsx("path",{d:"M4.715 6.542L3.343 7.914a3 3 0 104.243 4.243l1.828-1.829A3 3 0 008.586 5.5L8 6.086a1 1 0 00-.154.199 2 2 0 01.861 3.337L6.88 11.45a2 2 0 11-2.83-2.83l.793-.792a4.018 4.018 0 01-.128-1.287z"}),e.jsx("path",{d:"M11.285 9.458l1.372-1.372a3 3 0 10-4.243-4.243L6.586 5.671A3 3 0 007.414 10.5l.586-.586a1 1 0 00.154-.199 2 2 0 01-.861-3.337L9.12 4.55a2 2 0 112.83 2.83l-.793.792c.112.42.155.855.128 1.287z"})]}),i===t.id?"Copied!":"Copy Webhook URL"]}),e.jsxs("button",{onClick:()=>k(g),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:[e.jsx("path",{d:"M11.534 7h3.932a.25.25 0 01.192.41l-1.966 2.36a.25.25 0 01-.384 0l-1.966-2.36a.25.25 0 01.192-.41zm-7 2H.602a.25.25 0 01-.192-.41l1.966-2.36a.25.25 0 01.384 0l1.966 2.36a.25.25 0 01-.192.41z"}),e.jsx("path",{d:"M8 3a5 5 0 014.546 2.914.5.5 0 00.908-.418A6 6 0 002 8c0 .088.002.176.006.264l-.058-.024a.5.5 0 00-.394.908l2 1a.5.5 0 00.668-.17L5.59 7.864a.5.5 0 00-.274-.846l-.09-.016A4 4 0 018 3zm.002 10a4 4 0 002.49-4.002l.09.016a.5.5 0 00.274.846l-1.367 2.114a.5.5 0 01-.668.17l-2-1a.5.5 0 01.394-.908l.058.024A5.972 5.972 0 008.002 13a5 5 0 01-4.546-2.914.5.5 0 00-.908.418A6 6 0 008.002 13z"})]}),"Regenerate Secret"]})]}),e.jsx("div",{className:"my-1 border-t border-cc-border/40",role:"separator"}),e.jsxs("button",{onClick:()=>k(m),className:"w-full px-3 py-2 text-xs text-left text-cc-fg hover:bg-cc-hover transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted",children:t.enabled?e.jsx("path",{d:"M5 3a5 5 0 000 10h6a5 5 0 000-10H5zm6 3a2 2 0 110 4 2 2 0 010-4z"}):e.jsx("path",{d:"M11 3a5 5 0 010 10H5A5 5 0 015 3h6zM5 6a2 2 0 100 4 2 2 0 000-4z"})}),t.enabled?"Disable":"Enable"]}),e.jsx("div",{className:"my-1 border-t border-cc-border/40",role:"separator"}),e.jsxs("button",{onClick:()=>k(a),className:"w-full px-3 py-2 text-xs text-left text-cc-error hover:bg-cc-error/10 transition-colors flex items-center gap-2.5 cursor-pointer",role:"menuitem",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5",children:e.jsx("path",{d:"M5.5 5.5a.5.5 0 01.5.5v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm5 0a.5.5 0 01.5.5v6a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zm-7-3A1.5 1.5 0 015 1h6a1.5 1.5 0 011.5 1.5H14a.5.5 0 010 1h-.554L12.2 14.118A1.5 1.5 0 0110.706 15H5.294a1.5 1.5 0 01-1.494-.882L2.554 3.5H2a.5.5 0 010-1h1.5z"})}),"Delete"]})]})]})}function Ke(t,i){if(!i)return"One-time";const d=t.trim().split(/\s+/);if(d.length!==5)return t;const[a,m,,,u]=d;if(t==="* * * * *")return"Every minute";if(m==="*"&&a.startsWith("*/")){const h=parseInt(a.slice(2),10);return h===1?"Every minute":`Every ${h} minutes`}if(a==="0"&&m==="*")return"Every hour";if(a==="0"&&m.startsWith("*/")){const h=parseInt(m.slice(2),10);return h===1?"Every hour":`Every ${h} hours`}if(a!=="*"&&m!=="*"&&!m.includes("/")&&!m.includes(",")){const h=parseInt(m,10),g=parseInt(a,10);if(!isNaN(h)&&!isNaN(g)){const v=h>=12?"PM":"AM",j=h===0?12:h>12?h-12:h,o=g.toString().padStart(2,"0"),y=`${j}:${o} ${v}`;if(u==="*")return`Daily at ${y}`;if(u==="1-5")return`Weekdays at ${y}`}}return t}function qe(t,i){var a,m;return`${i||window.location.origin}/api/agents/${encodeURIComponent(t.id)}/webhook/${((m=(a=t.triggers)==null?void 0:a.webhook)==null?void 0:m.secret)||""}`}function Ge({agent:t,publicUrl:i,onEdit:d,onDelete:a,onToggle:m,onRun:u,onExport:h,onCopyWebhook:g,onRegenerateSecret:v,copiedWebhook:j}){var k,b,C,p,S,M,E,w;const o=["Manual"];(b=(k=t.triggers)==null?void 0:k.webhook)!=null&&b.enabled&&o.push("Webhook"),(p=(C=t.triggers)==null?void 0:C.schedule)!=null&&p.enabled&&o.push(Ke(t.triggers.schedule.expression,t.triggers.schedule.recurring)),(M=(S=t.triggers)==null?void 0:S.linear)!=null&&M.enabled&&o.push("Linear Agent");const y=(w=(E=t.triggers)==null?void 0:E.linear)==null?void 0:w.enabled;return e.jsxs("div",{className:`
6
+ group relative rounded-xl border bg-cc-card p-4
7
+ transition-all duration-150
8
+ ${t.enabled?"border-cc-border hover:border-cc-primary/30 hover:shadow-[0_2px_12px_rgba(217,119,87,0.06)]":"border-cc-border/60 opacity-75 hover:opacity-100"}
9
+ `,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsx("div",{className:`${t.enabled?"text-cc-primary":"text-cc-muted"} transition-colors`,children:e.jsx(he,{icon:t.icon||"bot",className:"w-5 h-5"})}),e.jsx("span",{className:`absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full ring-2 ring-cc-card ${t.enabled?"bg-cc-success":"bg-cc-muted/50"}`,title:t.enabled?"Enabled":"Disabled","data-testid":"status-dot"})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("h3",{className:"text-sm font-medium text-cc-fg truncate",children:t.name}),e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] rounded-full bg-cc-hover text-cc-muted font-medium leading-none",children:t.backendType==="codex"?"Codex":"Claude"}),y&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded-full bg-violet-500/10 text-violet-400 font-medium leading-none",children:[e.jsx(ne,{className:"w-2.5 h-2.5"}),"Linear"]})]}),t.description&&e.jsx("p",{className:"text-xs text-cc-muted mt-0.5 truncate max-w-md",children:t.description})]})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsx("button",{onClick:u,className:"px-2.5 py-1 text-xs font-medium rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors cursor-pointer",title:"Run agent",children:"Run"}),e.jsx(Je,{agent:t,copiedWebhook:j,onEdit:d,onDelete:a,onToggle:m,onExport:h,onCopyWebhook:g,onRegenerateSecret:v})]})]}),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:o.map((L,B)=>e.jsx("span",{className:"px-2 py-0.5 text-[10px] rounded-full bg-cc-hover text-cc-muted",children:L},B))}),e.jsxs("div",{className:"flex items-center gap-3 text-[10px] text-cc-muted",children:[t.totalRuns>0&&e.jsxs("span",{children:[t.totalRuns," run",t.totalRuns!==1?"s":""]}),t.lastRunAt&&e.jsxs("span",{children:["Last: ",Ee(t.lastRunAt)]}),t.nextRunAt&&e.jsxs("span",{children:["Next: ",Ee(t.nextRunAt)]})]})]})]})}const Re={name:"",description:"",icon:"",backendType:"claude",model:ae("claude"),permissionMode:we("claude"),cwd:"",prompt:"",envSlug:"",env:[],codexInternetAccess:!1,branch:"",createBranch:!1,useWorktree:!1,mcpServers:{},skills:[],allowedTools:[],webhookEnabled:!1,scheduleEnabled:!1,scheduleExpression:"0 8 * * *",scheduleRecurring:!0,linearEnabled:!1,linearOAuthConnectionId:""},Ze=[{label:"Every hour",value:"0 * * * *"},{label:"Every day at 8am",value:"0 8 * * *"},{label:"Every day at noon",value:"0 12 * * *"},{label:"Weekdays at 9am",value:"0 9 * * 1-5"},{label:"Every Monday at 8am",value:"0 8 * * 1"},{label:"Every 30 minutes",value:"*/30 * * * *"}];function je(t){let i=0;return Object.keys(t.mcpServers).length>0&&i++,t.skills.length>0&&i++,t.allowedTools.length>0&&i++,t.env.length>0&&i++,i}function Qe({form:t,setForm:i,editingId:d,publicUrl:a,error:m,saving:u,onSave:h,onCancel:g,linearOAuthConfigured:v}){const j=Oe(t.backendType),o=Ie(t.backendType),[y,k]=r.useState(!1),[b,C]=r.useState(()=>je(t)>0),[p,S]=r.useState(!1),[M,E]=r.useState(""),[w,L]=r.useState({type:"stdio",command:"",args:"",url:"",env:""}),[B,R]=r.useState([]),[U,V]=r.useState([]),[D,l]=r.useState([]),[I,H]=r.useState(!1),[O,le]=r.useState(""),[F,K]=r.useState(!1),[_,$]=r.useState(!1),[q,P]=r.useState(!1),[G,W]=r.useState(!!t.branch),[oe,Z]=r.useState(!1),Q=r.useRef(null),X=r.useRef(null),te=r.useRef(null),Y=r.useRef(null);r.useEffect(()=>{z.listSkills().then(R).catch(()=>{}),z.listEnvs().then(V).catch(()=>{})},[]),r.useEffect(()=>{t.linearEnabled&&(H(!0),z.listLinearOAuthConnections().then(({connections:s})=>{l(s),s.length===1&&!t.linearOAuthConnectionId&&N("linearOAuthConnectionId",s[0].id)}).catch(()=>{}).finally(()=>H(!1)))},[t.linearEnabled]);function N(s,n){i(A=>({...A,[s]:n}))}function ie(s){i(n=>({...n,backendType:s,model:ae(s),permissionMode:we(s)}))}function pe(){i(s=>({...s,env:[...s.env,{key:"",value:""}]}))}function de(s,n,A){i(T=>{const ee=[...T.env];return ee[s]={...ee[s],[n]:A},{...T,env:ee}})}function xe(s){i(n=>({...n,env:n.env.filter((A,T)=>T!==s)}))}function me(){if(!M.trim())return;const s={type:w.type};if(w.type==="stdio"?(s.command=w.command,s.args=w.args?w.args.split(" ").filter(Boolean):void 0):s.url=w.url,w.env.trim())try{s.env=JSON.parse(w.env)}catch{}i(n=>({...n,mcpServers:{...n.mcpServers,[M.trim()]:s}})),E(""),L({type:"stdio",command:"",args:"",url:"",env:""}),S(!1)}function ge(s){i(n=>{const A={...n.mcpServers};return delete A[s],{...n,mcpServers:A}})}function ue(s){i(n=>({...n,skills:n.skills.includes(s)?n.skills.filter(A=>A!==s):[...n.skills,s]}))}function be(s){if(s.key==="Enter"&&O.trim()){s.preventDefault();const n=O.trim();t.allowedTools.includes(n)||N("allowedTools",[...t.allowedTools,n]),le("")}}function fe(s){N("allowedTools",t.allowedTools.filter(n=>n!==s))}r.useEffect(()=>{function s(n){X.current&&!X.current.contains(n.target)&&K(!1),te.current&&!te.current.contains(n.target)&&$(!1),Y.current&&!Y.current.contains(n.target)&&P(!1),Q.current&&!Q.current.contains(n.target)&&Z(!1)}return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[]);const J=j.find(s=>s.value===t.model)||j[0],se=o.find(s=>s.value===t.permissionMode)||o[0],ce=U.find(s=>s.slug===t.envSlug),ve=t.cwd?t.cwd.split("/").pop()||t.cwd:"temp",re=a||(typeof window<"u"?window.location.origin:""),c="flex items-center gap-1.5 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer",x=`${c} text-cc-muted hover:text-cc-fg hover:bg-cc-hover`,f=`${c} text-cc-primary bg-cc-primary/10 hover:bg-cc-primary/15`;return e.jsx("div",{className:"h-full overflow-y-auto bg-cc-bg",children:e.jsxs("div",{className:"max-w-3xl mx-auto p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:g,className:"p-1.5 rounded-lg text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4",children:e.jsx("path",{d:"M11 2L5 8l6 6",stroke:"currentColor",strokeWidth:"2",fill:"none"})})}),e.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:d?"Edit Agent":"New Agent"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:g,className:"px-3 py-1.5 text-xs rounded-lg border border-cc-border text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{onClick:h,disabled:u||!t.name.trim()||!t.prompt.trim(),className:"px-3 py-1.5 text-xs rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors disabled:opacity-50 cursor-pointer disabled:cursor-not-allowed",children:u?"Saving...":d?"Save":"Create"})]})]}),m&&e.jsx("div",{className:"mb-4 px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/30 text-cc-error text-xs",children:m}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex gap-3 items-start",children:[e.jsxs("div",{ref:Q,className:"relative flex-shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>Z(!oe),className:"w-10 h-10 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg flex items-center justify-center hover:border-cc-primary/50 focus:outline-none focus:ring-1 focus:ring-cc-primary transition-colors","aria-label":"Choose agent icon",children:e.jsx(he,{icon:t.icon||"bot",className:"w-5 h-5"})}),oe&&e.jsx("div",{className:"absolute top-12 left-0 z-50 bg-cc-card border border-cc-border rounded-lg shadow-lg p-2 grid grid-cols-6 gap-1 w-[216px]",children:Ye.map(s=>e.jsx("button",{type:"button",onClick:()=>{N("icon",s),Z(!1)},className:`w-8 h-8 rounded-md flex items-center justify-center transition-colors ${t.icon===s?"bg-cc-primary/20 ring-1 ring-cc-primary":"hover:bg-cc-hover"}`,title:s,children:e.jsx(he,{icon:s,className:"w-4 h-4 text-cc-fg"})},s))})]}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("input",{value:t.name,onChange:s=>N("name",s.target.value),placeholder:"Agent name *",className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsx("input",{value:t.description,onChange:s=>N("description",s.target.value),placeholder:"Short description (optional)",className:"w-full px-3 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs focus:outline-none focus:ring-1 focus:ring-cc-primary"})]})]}),e.jsxs("div",{children:[e.jsx("textarea",{value:t.prompt,onChange:s=>N("prompt",s.target.value),placeholder:`System prompt *
10
+ Write the agent's instructions here.
11
+ Use {{input}} as a placeholder for trigger-provided input.`,className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm resize-none h-40 font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsxs("p",{className:"text-[10px] text-cc-muted mt-1",children:["Use ",e.jsx("code",{className:"px-1 py-0.5 rounded bg-cc-hover",children:"{{input}}"})," where trigger input should be inserted."]})]}),e.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 flex-wrap","data-testid":"controls-row",children:[e.jsxs("div",{className:"flex items-center bg-cc-hover/50 rounded-lg p-0.5",children:[e.jsx("button",{onClick:()=>ie("claude"),className:`flex items-center gap-1 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer ${t.backendType==="claude"?"bg-cc-card text-cc-fg font-medium shadow-sm":"text-cc-muted hover:text-cc-fg"}`,children:"Claude"}),e.jsx("button",{onClick:()=>ie("codex"),className:`flex items-center gap-1 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer ${t.backendType==="codex"?"bg-cc-card text-cc-fg font-medium shadow-sm":"text-cc-muted hover:text-cc-fg"}`,children:"Codex"})]}),e.jsxs("div",{className:"relative",ref:X,children:[e.jsxs("button",{onClick:()=>{K(!F),$(!1),P(!1)},"aria-expanded":F,className:x,children:[e.jsx("span",{children:J==null?void 0:J.icon}),e.jsx("span",{children:J==null?void 0:J.label}),e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50",children:e.jsx("path",{d:"M4 6l4 4 4-4"})})]}),F&&e.jsx("div",{className:"absolute left-0 top-full mt-1 w-48 bg-cc-card border border-cc-border rounded-[10px] shadow-lg z-10 py-1",children:j.map(s=>e.jsxs("button",{onClick:()=>{N("model",s.value),K(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer flex items-center gap-2 ${s.value===t.model?"text-cc-primary font-medium":"text-cc-fg"}`,children:[e.jsx("span",{children:s.icon}),s.label]},s.value))})]}),e.jsxs("div",{className:"relative",ref:te,children:[e.jsxs("button",{onClick:()=>{$(!_),K(!1),P(!1)},"aria-expanded":_,className:x,children:[e.jsx("span",{children:se==null?void 0:se.label}),e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50",children:e.jsx("path",{d:"M4 6l4 4 4-4"})})]}),_&&e.jsx("div",{className:"absolute left-0 top-full mt-1 w-48 bg-cc-card border border-cc-border rounded-[10px] shadow-lg z-10 py-1",children:o.map(s=>e.jsx("button",{onClick:()=>{N("permissionMode",s.value),$(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer flex items-center gap-2 ${s.value===t.permissionMode?"text-cc-primary font-medium":"text-cc-fg"}`,children:s.label},s.value))})]}),e.jsxs("button",{onClick:()=>k(!0),className:t.cwd?f:x,title:t.cwd||"Temporary directory",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.879a1.5 1.5 0 011.06.44l1.122 1.12A1.5 1.5 0 009.62 4H13.5A1.5 1.5 0 0115 5.5v7a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})}),e.jsx("span",{className:"max-w-[120px] sm:max-w-[200px] truncate font-mono-code",children:ve}),t.cwd&&e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50 hover:opacity-100",onClick:s=>{s.stopPropagation(),N("cwd","")},children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})]}),t.cwd&&(G?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 text-cc-muted opacity-60",children:e.jsx("path",{d:"M9.5 3.25a2.25 2.25 0 113 2.122V6.5A2.5 2.5 0 0110 9H6a1 1 0 00-1 1v1.128a2.251 2.251 0 11-1.5 0V5.372a2.25 2.25 0 111.5 0v1.836A2.492 2.492 0 016 7h4a1 1 0 001-1v-.878A2.25 2.25 0 019.5 3.25z"})}),e.jsx("input",{value:t.branch,onChange:s=>N("branch",s.target.value),placeholder:"branch name",className:"w-28 px-1.5 py-1 text-xs rounded-md bg-cc-input-bg border border-cc-border text-cc-fg font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary",autoFocus:!0,onBlur:()=>{t.branch||W(!1)}}),t.branch&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-center gap-1 text-[10px] text-cc-muted cursor-pointer",title:"Create branch if it doesn't exist",children:[e.jsx("input",{type:"checkbox",checked:t.createBranch,onChange:s=>N("createBranch",s.target.checked),className:"rounded w-3 h-3"}),"create"]}),e.jsxs("label",{className:"flex items-center gap-1 text-[10px] text-cc-muted cursor-pointer",title:"Use git worktree",children:[e.jsx("input",{type:"checkbox",checked:t.useWorktree,onChange:s=>N("useWorktree",s.target.checked),className:"rounded w-3 h-3"}),"worktree"]})]})]}):e.jsxs("button",{onClick:()=>W(!0),className:x,title:"Set a git branch",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M9.5 3.25a2.25 2.25 0 113 2.122V6.5A2.5 2.5 0 0110 9H6a1 1 0 00-1 1v1.128a2.251 2.251 0 11-1.5 0V5.372a2.25 2.25 0 111.5 0v1.836A2.492 2.492 0 016 7h4a1 1 0 001-1v-.878A2.25 2.25 0 019.5 3.25z"})}),e.jsx("span",{children:"branch"})]})),e.jsxs("div",{className:"relative",ref:Y,children:[e.jsxs("button",{onClick:()=>{P(!q),K(!1),$(!1)},"aria-expanded":q,className:t.envSlug?f:x,children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M8 1a2 2 0 012 2v4H6V3a2 2 0 012-2zm3.5 6V3a3.5 3.5 0 10-7 0v4A1.5 1.5 0 003 8.5v5A1.5 1.5 0 004.5 15h7a1.5 1.5 0 001.5-1.5v-5A1.5 1.5 0 0011.5 7z"})}),e.jsx("span",{children:(ce==null?void 0:ce.name)||"None"}),e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50",children:e.jsx("path",{d:"M4 6l4 4 4-4"})})]}),q&&e.jsxs("div",{className:"absolute left-0 top-full mt-1 w-48 bg-cc-card border border-cc-border rounded-[10px] shadow-lg z-10 py-1",children:[e.jsx("button",{onClick:()=>{N("envSlug",""),P(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer ${t.envSlug?"text-cc-fg":"text-cc-primary font-medium"}`,children:"None"}),U.map(s=>e.jsx("button",{onClick:()=>{N("envSlug",s.slug),P(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer ${t.envSlug===s.slug?"text-cc-primary font-medium":"text-cc-fg"}`,children:s.name},s.slug))]})]}),t.backendType==="codex"&&e.jsxs("button",{onClick:()=>N("codexInternetAccess",!t.codexInternetAccess),className:t.codexInternetAccess?f:x,title:"Allow internet access (Codex)",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M0 8a8 8 0 1116 0A8 8 0 010 8zm7.5-6.923c-.67.204-1.335.82-1.887 1.855A7.97 7.97 0 005.145 4H7.5V1.077zM4.09 4a9.267 9.267 0 01.64-1.539 6.7 6.7 0 01.597-.933A6.504 6.504 0 002.536 4H4.09zm-.582 3.5c.03-.877.138-1.718.312-2.5H1.674a6.51 6.51 0 00-.656 2.5h2.49zM4.847 5a12.5 12.5 0 00-.338 2.5H7.5V5H4.847zM8.5 5v2.5h2.99a12.495 12.495 0 00-.337-2.5H8.5zM4.51 8.5a12.5 12.5 0 00.337 2.5H7.5V8.5H4.51zm3.99 0V11h2.653c.187-.765.306-1.608.338-2.5H8.5zM5.145 12c.138.386.295.744.468 1.068.552 1.035 1.218 1.65 1.887 1.855V12H5.145zm.182 2.472a6.696 6.696 0 01-.597-.933A9.268 9.268 0 014.09 12H2.536a6.504 6.504 0 002.79 2.472zM3.82 11a13.652 13.652 0 01-.312-2.5h-2.49c.062.89.291 1.733.656 2.5H3.82zm6.853 3.472A6.504 6.504 0 0013.464 12H11.91a9.27 9.27 0 01-.64 1.539 6.688 6.688 0 01-.597.933zM8.5 14.923c.67-.204 1.335-.82 1.887-1.855.173-.324.33-.682.468-1.068H8.5v2.923zm3.68-3.923c.174-.782.282-1.623.312-2.5H15c-.094.89-.323 1.733-.656 2.5h-2.163zM12.18 8.5c-.03-.877-.138-1.718-.312-2.5h2.158c.365.767.594 1.61.656 2.5H12.18zm-1.508-4.5h2.792a6.504 6.504 0 00-2.79-2.472c.218.284.418.598.597.933.226.423.424.896.59 1.539z"})}),e.jsx("span",{children:"Internet"})]})]}),y&&e.jsx(ye,{initialPath:t.cwd||"",onSelect:s=>{N("cwd",s),k(!1)},onClose:()=>k(!1)}),e.jsxs("section",{children:[e.jsx("h2",{className:"text-xs text-cc-muted mb-2",children:"Triggers"}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("button",{onClick:()=>N("webhookEnabled",!t.webhookEnabled),className:t.webhookEnabled?f:x,children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M8.543 2.232a.75.75 0 00-1.085 0l-5.25 5.5A.75.75 0 002.75 9H4v4a1 1 0 001 1h6a1 1 0 001-1V9h1.25a.75.75 0 00.543-1.268l-5.25-5.5z"})}),"Webhook"]}),e.jsxs("button",{onClick:()=>N("scheduleEnabled",!t.scheduleEnabled),className:t.scheduleEnabled?f:x,children:[e.jsxs("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:[e.jsx("path",{d:"M8 3.5a.5.5 0 00-1 0V8a.5.5 0 00.252.434l3.5 2a.5.5 0 00.496-.868L8 7.71V3.5z"}),e.jsx("path",{d:"M8 16A8 8 0 108 0a8 8 0 000 16zm7-8A7 7 0 111 8a7 7 0 0114 0z"})]}),"Schedule"]}),v&&e.jsxs("button",{onClick:()=>N("linearEnabled",!t.linearEnabled),className:t.linearEnabled?f:x,children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M3 1a1 1 0 00-1 1v12a1 1 0 001 1h10a1 1 0 001-1V2a1 1 0 00-1-1H3zm1 2h8v2H4V3zm0 4h5v2H4V7zm0 4h8v2H4v-2z"})}),"Linear Agent"]})]}),t.webhookEnabled&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsxs("p",{className:"text-[10px] text-cc-muted",children:["A unique URL will be generated after saving. POST to it with ",e.jsx("code",{className:"px-1 py-0.5 rounded bg-cc-hover",children:'{"input": "..."}'}),"."]}),re&&e.jsxs("p",{className:"text-[10px] text-cc-muted",children:["Base URL: ",e.jsx("span",{className:"font-mono-code",children:re})]})]}),t.linearEnabled&&e.jsx("div",{className:"mt-3 space-y-2","data-testid":"linear-connection-picker",children:I?e.jsx("p",{className:"text-[10px] text-cc-muted",children:"Loading connections..."}):D.length===0?e.jsxs("p",{className:"text-[10px] text-cc-muted",children:["No OAuth connections found."," ",e.jsx("a",{href:"#/agents?setup=linear",className:"text-cc-primary underline",children:"Set up a Linear OAuth app"})," ","first."]}):e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"block text-[10px] text-cc-muted mb-1",children:"OAuth Connection"}),e.jsx("div",{className:"space-y-1",children:D.map(s=>e.jsxs("button",{type:"button",onClick:()=>N("linearOAuthConnectionId",s.id),className:`w-full flex items-center justify-between px-3 py-2 rounded-lg border text-xs transition-colors cursor-pointer ${t.linearOAuthConnectionId===s.id?"border-cc-primary bg-cc-primary/10 text-cc-fg":"border-cc-border bg-cc-input-bg text-cc-muted hover:text-cc-fg hover:border-cc-primary/50"}`,children:[e.jsx("span",{className:"font-medium",children:s.name}),e.jsx("span",{className:`px-1.5 py-0.5 text-[10px] rounded-full ${s.status==="connected"?"bg-emerald-500/15 text-emerald-400":"bg-cc-muted/15 text-cc-muted"}`,children:s.status==="connected"?"Connected":"Not connected"})]},s.id))}),e.jsxs("p",{className:"text-[10px] text-cc-muted",children:["This agent will respond to @mentions in Linear."," ",e.jsx("a",{href:"#/agents?setup=linear",className:"text-cc-primary underline",children:"Manage connections"})]})]})}),t.scheduleEnabled&&e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-cc-muted cursor-pointer",children:[e.jsx("input",{type:"radio",checked:t.scheduleRecurring,onChange:()=>N("scheduleRecurring",!0)}),"Recurring"]}),e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-cc-muted cursor-pointer",children:[e.jsx("input",{type:"radio",checked:!t.scheduleRecurring,onChange:()=>N("scheduleRecurring",!1)}),"One-time"]})]}),t.scheduleRecurring?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex flex-wrap gap-1",children:Ze.map(s=>e.jsx("button",{onClick:()=>N("scheduleExpression",s.value),className:`px-2 py-1 text-[10px] rounded-lg border transition-colors cursor-pointer ${t.scheduleExpression===s.value?"border-cc-primary text-cc-primary":"border-cc-border text-cc-muted hover:text-cc-fg"}`,children:s.label},s.value))}),e.jsx("input",{value:t.scheduleExpression,onChange:s=>N("scheduleExpression",s.target.value),placeholder:"Cron expression (e.g. 0 8 * * *)",className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"})]}):e.jsx("input",{type:"datetime-local",value:t.scheduleExpression,onChange:s=>N("scheduleExpression",s.target.value),className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm focus:outline-none focus:ring-1 focus:ring-cc-primary"})]})]}),e.jsxs("section",{children:[e.jsxs("button",{onClick:()=>C(!b),className:"flex items-center gap-2 text-xs text-cc-muted cursor-pointer hover:text-cc-fg transition-colors w-full",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:`w-3 h-3 transition-transform ${b?"rotate-90":""}`,children:e.jsx("path",{d:"M6 3l5 5-5 5V3z"})}),"Advanced",je(t)>0&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] rounded-full bg-cc-primary/15 text-cc-primary font-normal",children:je(t)})]}),b&&e.jsxs("div",{className:"mt-4 space-y-6 pl-5 border-l-2 border-cc-border/30",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted",children:"MCP Servers"}),e.jsx("button",{onClick:()=>S(!p),className:"text-[10px] text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:p?"Cancel":"+ Add Server"})]}),Object.keys(t.mcpServers).length===0&&!p&&e.jsx("p",{className:"text-[10px] text-cc-muted",children:"No MCP servers configured."}),Object.entries(t.mcpServers).map(([s,n])=>e.jsxs("div",{className:"flex items-center justify-between py-1.5 px-2 rounded-lg bg-cc-hover/50 mb-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-cc-fg font-mono-code",children:s}),e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] rounded bg-cc-border text-cc-muted",children:n.type})]}),e.jsx("button",{onClick:()=>ge(s),className:"text-cc-muted hover:text-cc-error transition-colors cursor-pointer p-0.5",title:"Remove server",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]},s)),p&&e.jsxs("div",{className:"rounded-lg border border-cc-border p-3 mt-2 space-y-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] text-cc-muted mb-0.5",children:"Server Name"}),e.jsx("input",{value:M,onChange:s=>E(s.target.value),placeholder:"e.g., my-server",className:"w-full px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] text-cc-muted mb-0.5",children:"Type"}),e.jsx("div",{className:"flex rounded-lg border border-cc-border overflow-hidden",children:["stdio","sse","http"].map(s=>e.jsx("button",{onClick:()=>L(n=>({...n,type:s})),className:`flex-1 px-2 py-1 text-[10px] transition-colors cursor-pointer ${w.type===s?"bg-cc-primary text-white":"bg-cc-input-bg text-cc-muted hover:text-cc-fg"}`,children:s},s))})]}),w.type==="stdio"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] text-cc-muted mb-0.5",children:"Command"}),e.jsx("input",{value:w.command,onChange:s=>L(n=>({...n,command:s.target.value})),placeholder:"e.g., npx -y @some/mcp-server",className:"w-full px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] text-cc-muted mb-0.5",children:"Args (space-separated)"}),e.jsx("input",{value:w.args,onChange:s=>L(n=>({...n,args:s.target.value})),placeholder:"--port 3000",className:"w-full px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"})]})]}):e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] text-cc-muted mb-0.5",children:"URL"}),e.jsx("input",{value:w.url,onChange:s=>L(n=>({...n,url:s.target.value})),placeholder:"https://example.com/mcp",className:"w-full px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"})]}),e.jsx("button",{onClick:me,disabled:!M.trim(),className:"px-3 py-1.5 text-xs rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors disabled:opacity-50 cursor-pointer disabled:cursor-not-allowed",children:"Add Server"})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted mb-2",children:"Skills"}),B.length===0?e.jsx("p",{className:"text-[10px] text-cc-muted",children:"No skills found in ~/.claude/skills/"}):e.jsx("div",{className:"space-y-1.5",children:B.map(s=>e.jsxs("label",{className:"flex items-start gap-2 text-sm text-cc-fg cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:t.skills.includes(s.slug),onChange:()=>ue(s.slug),className:"rounded mt-0.5"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs",children:s.name}),s.description&&e.jsx("p",{className:"text-[10px] text-cc-muted",children:s.description})]})]},s.slug))})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted mb-2",children:"Allowed Tools"}),e.jsxs("div",{className:"space-y-2",children:[t.allowedTools.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.allowedTools.map(s=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-xs font-mono-code rounded-lg bg-cc-hover text-cc-fg",children:[s,e.jsx("button",{onClick:()=>fe(s),className:"text-cc-muted hover:text-cc-error transition-colors cursor-pointer",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-2.5 h-2.5",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]},s))}),e.jsx("input",{value:O,onChange:s=>le(s.target.value),onKeyDown:be,placeholder:"Type tool name and press Enter",className:"w-full px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsx("p",{className:"text-[10px] text-cc-muted",children:"Leave empty to allow all tools."})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-xs font-medium text-cc-muted",children:"Environment Variables"}),e.jsx("button",{onClick:pe,className:"text-[10px] text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"+ Add Variable"})]}),t.env.length===0?e.jsx("p",{className:"text-[10px] text-cc-muted",children:"No extra variables set."}):e.jsx("div",{className:"space-y-1.5",children:t.env.map((s,n)=>e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("input",{value:s.key,onChange:A=>de(n,"key",A.target.value),placeholder:"KEY",className:"w-1/3 px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsx("input",{value:s.value,onChange:A=>de(n,"value",A.target.value),placeholder:"value",className:"flex-1 px-2 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsx("button",{onClick:()=>xe(n),className:"text-cc-muted hover:text-cc-error transition-colors cursor-pointer p-1",title:"Remove variable",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3",children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})})]},n))})]})]})]})]})]})})}function Xe({form:t,setForm:i,editingId:d,error:a,saving:m,onSave:u,onCancel:h,onOpenGenericEditor:g}){const[v,j]=r.useState(!1),[o,y]=r.useState(!1),[k,b]=r.useState(!1),C=r.useRef(null),p=r.useRef(null);function S(l,I){i(H=>({...H,[l]:I}))}function M(l){i(I=>({...I,backendType:l,model:ae(l),permissionMode:we(l)}))}r.useEffect(()=>{function l(I){C.current&&!C.current.contains(I.target)&&y(!1),p.current&&!p.current.contains(I.target)&&b(!1)}return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[]);const E=Oe(t.backendType),w=Ie(t.backendType),L=E.find(l=>l.value===t.model)||E[0],B=w.find(l=>l.value===t.permissionMode)||w[0],R=t.cwd?t.cwd.split("/").pop()||t.cwd:"temp",U="flex items-center gap-1.5 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer",V=`${U} text-cc-muted hover:text-cc-fg hover:bg-cc-hover`,D=`${U} text-cc-primary bg-cc-primary/10 hover:bg-cc-primary/15`;return e.jsx("div",{className:"h-full overflow-y-auto bg-cc-bg",children:e.jsxs("div",{className:"max-w-3xl mx-auto p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:h,className:"p-1.5 rounded-lg text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-4 h-4",children:e.jsx("path",{d:"M11 2L5 8l6 6",stroke:"currentColor",strokeWidth:"2",fill:"none"})})}),e.jsx(ne,{className:"w-5 h-5 text-cc-fg"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Edit Linear Agent"}),e.jsxs("p",{className:"text-[10px] text-cc-muted font-mono-code",children:["ID: ",d]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:h,className:"px-3 py-1.5 text-xs rounded-lg border border-cc-border text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{onClick:u,disabled:m||!t.name.trim()||!t.prompt.trim(),className:"px-3 py-1.5 text-xs rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors disabled:opacity-50 cursor-pointer disabled:cursor-not-allowed",children:m?"Saving...":"Save"})]})]}),a&&e.jsx("div",{className:"mb-4 px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/30 text-cc-error text-xs",children:a}),e.jsxs("div",{className:"space-y-5",children:[e.jsx("input",{value:t.name,onChange:l=>S("name",l.target.value),placeholder:"Agent name *",className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsx("input",{value:t.description,onChange:l=>S("description",l.target.value),placeholder:"Short description (optional)",className:"w-full px-3 py-1.5 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-xs focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsxs("div",{children:[e.jsx("textarea",{value:t.prompt,onChange:l=>S("prompt",l.target.value),placeholder:`System prompt *
12
+ Write the agent’s instructions here.
13
+ Use {{input}} as a placeholder for trigger-provided input.`,className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm resize-none h-40 font-mono-code focus:outline-none focus:ring-1 focus:ring-cc-primary"}),e.jsxs("p",{className:"text-[10px] text-cc-muted mt-1",children:["Use ",e.jsx("code",{className:"px-1 py-0.5 rounded bg-cc-hover",children:"{{input}}"})," where trigger input should be inserted."]})]}),e.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 flex-wrap","data-testid":"controls-row",children:[e.jsxs("div",{className:"flex items-center bg-cc-hover/50 rounded-lg p-0.5",children:[e.jsx("button",{onClick:()=>M("claude"),className:`flex items-center gap-1 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer ${t.backendType==="claude"?"bg-cc-card text-cc-fg font-medium shadow-sm":"text-cc-muted hover:text-cc-fg"}`,children:"Claude"}),e.jsx("button",{onClick:()=>M("codex"),className:`flex items-center gap-1 px-2 py-1 text-xs rounded-md transition-colors cursor-pointer ${t.backendType==="codex"?"bg-cc-card text-cc-fg font-medium shadow-sm":"text-cc-muted hover:text-cc-fg"}`,children:"Codex"})]}),e.jsxs("div",{className:"relative",ref:C,children:[e.jsxs("button",{onClick:()=>{y(!o),b(!1)},"aria-expanded":o,className:V,children:[e.jsx("span",{children:L==null?void 0:L.icon}),e.jsx("span",{children:L==null?void 0:L.label}),e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50",children:e.jsx("path",{d:"M4 6l4 4 4-4"})})]}),o&&e.jsx("div",{className:"absolute left-0 top-full mt-1 w-48 bg-cc-card border border-cc-border rounded-[10px] shadow-lg z-10 py-1",children:E.map(l=>e.jsxs("button",{onClick:()=>{S("model",l.value),y(!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 ${l.value===t.model?"text-cc-primary font-medium":"text-cc-fg"}`,children:[e.jsx("span",{children:l.icon}),l.label]},l.value))})]}),e.jsxs("div",{className:"relative",ref:p,children:[e.jsxs("button",{onClick:()=>{b(!k),y(!1)},"aria-expanded":k,className:V,children:[e.jsx("span",{children:B==null?void 0:B.label}),e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50",children:e.jsx("path",{d:"M4 6l4 4 4-4"})})]}),k&&e.jsx("div",{className:"absolute left-0 top-full mt-1 w-48 bg-cc-card border border-cc-border rounded-[10px] shadow-lg z-10 py-1",children:w.map(l=>e.jsx("button",{onClick:()=>{S("permissionMode",l.value),b(!1)},className:`w-full px-3 py-2 text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer flex items-center gap-2 ${l.value===t.permissionMode?"text-cc-primary font-medium":"text-cc-fg"}`,children:l.label},l.value))})]}),e.jsxs("button",{onClick:()=>j(!0),className:t.cwd?D:V,title:t.cwd||"Temporary directory",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60",children:e.jsx("path",{d:"M1 3.5A1.5 1.5 0 012.5 2h3.879a1.5 1.5 0 011.06.44l1.122 1.12A1.5 1.5 0 009.62 4H13.5A1.5 1.5 0 0115 5.5v7a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})}),e.jsx("span",{className:"max-w-[120px] sm:max-w-[200px] truncate font-mono-code",children:R}),t.cwd&&e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50 hover:opacity-100",onClick:l=>{l.stopPropagation(),S("cwd","")},children:e.jsx("path",{d:"M4.646 4.646a.5.5 0 01.708 0L8 7.293l2.646-2.647a.5.5 0 01.708.708L8.707 8l2.647 2.646a.5.5 0 01-.708.708L8 8.707l-2.646 2.647a.5.5 0 01-.708-.708L7.293 8 4.646 5.354a.5.5 0 010-.708z"})})]})]}),v&&e.jsx(ye,{initialPath:t.cwd||"",onSelect:l=>{S("cwd",l),j(!1)},onClose:()=>j(!1)}),e.jsxs("section",{className:"rounded-lg border border-cc-success/30 bg-cc-success/5 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium bg-cc-success/10 text-cc-success border border-cc-success/20",children:"Linear Agent trigger enabled"})}),e.jsx("button",{onClick:g,className:"text-xs text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Open in full editor →"})]}),e.jsxs("p",{className:"text-[10px] text-cc-muted mt-2",children:["This agent responds to @mentions in Linear."," ",e.jsx("a",{href:"#/integrations/linear-oauth",className:"text-cc-primary underline",children:"Manage OAuth connections"}),"."]})]})]})]})})}const Te={all:"All",linear:"Linear",scheduled:"Scheduled",webhook:"Webhook"};function tt({route:t}){const i=Be(c=>c.publicUrl),[d,a]=r.useState([]),[m,u]=r.useState(!0),[h,g]=r.useState("list"),[v,j]=r.useState(null),[o,y]=r.useState(Re),[k,b]=r.useState(!1),[C,p]=r.useState(""),[S,M]=r.useState(null),[E,w]=r.useState(""),[L,B]=r.useState(null),[R,U]=r.useState("all"),[V,D]=r.useState(!1),l=r.useRef(null),I=[{label:"Intro"},{label:"Connection"},{label:"Agent"},{label:"Done"}],[H,O]=r.useState(1),[le,F]=r.useState(""),[K,_]=r.useState(null),[$,q]=r.useState(null),[P,G]=r.useState(null);r.useEffect(()=>{window.location.hash.includes("setup=linear")&&(X(),history.replaceState(null,"","#/agents"))},[]);const W=r.useCallback(async()=>{try{const c=await z.listAgents();if(a(c),c.some(f=>{var s,n,A,T;return((n=(s=f.triggers)==null?void 0:s.linear)==null?void 0:n.enabled)&&((T=(A=f.triggers)==null?void 0:A.linear)==null?void 0:T.hasAccessToken)}))D(!0);else try{const{connections:f}=await z.listLinearOAuthConnections();D(f.length>0)}catch{D(!1)}}catch{}finally{u(!1)}},[]);r.useEffect(()=>{W()},[W]),r.useEffect(()=>{if(t.page==="agent-detail"&&"agentId"in t){const c=d.find(x=>x.id===t.agentId);c&&Z(c)}},[t,d]);function oe(){j(null),y(Re),p(""),g("edit")}function Z(c){var x,f,s,n,A,T,ee,Ne,ke,Ce,Se,Ae,Le,Me;j(c.id),y({name:c.name,description:c.description,icon:c.icon||"",backendType:c.backendType,model:c.model,permissionMode:c.permissionMode,cwd:c.cwd==="temp"?"":c.cwd,prompt:c.prompt,envSlug:c.envSlug||"",env:c.env?Object.entries(c.env).map(([$e,We])=>({key:$e,value:We})):[],codexInternetAccess:c.codexInternetAccess??!1,branch:c.branch||"",createBranch:c.createBranch??!1,useWorktree:c.useWorktree??!1,mcpServers:c.mcpServers||{},skills:c.skills||[],allowedTools:c.allowedTools||[],webhookEnabled:((f=(x=c.triggers)==null?void 0:x.webhook)==null?void 0:f.enabled)??!1,scheduleEnabled:((n=(s=c.triggers)==null?void 0:s.schedule)==null?void 0:n.enabled)??!1,scheduleExpression:((T=(A=c.triggers)==null?void 0:A.schedule)==null?void 0:T.expression)||"0 8 * * *",scheduleRecurring:((Ne=(ee=c.triggers)==null?void 0:ee.schedule)==null?void 0:Ne.recurring)??!0,linearEnabled:((Ce=(ke=c.triggers)==null?void 0:ke.linear)==null?void 0:Ce.enabled)??!1,linearOAuthConnectionId:((Ae=(Se=c.triggers)==null?void 0:Se.linear)==null?void 0:Ae.oauthConnectionId)??""}),p(""),(Me=(Le=c.triggers)==null?void 0:Le.linear)!=null&&Me.enabled?g("edit-linear"):g("edit")}function Q(){g("list"),j(null),p(""),window.location.hash="#/agents"}function X(){g("setup-linear"),O(1)}function te(){g("list"),O(1),F(""),_(null),q(null),G(null)}const Y=new Set;P&&(Y.add(1),Y.add(2)),K&&Y.add(3);const N=r.useCallback((c,x)=>{_(c),F(x),O(4)},[]),ie=r.useCallback(()=>{g("list"),O(1),F(""),_(null),G(null),W()},[W]),pe=r.useCallback(()=>{F(""),q(null),_(null),O(3)},[]),de=r.useCallback(()=>{_(null),F(""),q(null),G(null),O(2)},[]);async function xe(){b(!0),p("");try{const c={};for(const{key:f,value:s}of o.env)f.trim()&&(c[f.trim()]=s);const x={version:1,name:o.name,description:o.description,icon:o.icon||void 0,backendType:o.backendType,model:o.model,permissionMode:o.permissionMode,cwd:o.cwd||"temp",prompt:o.prompt,envSlug:o.envSlug||void 0,env:Object.keys(c).length>0?c:void 0,codexInternetAccess:o.backendType==="codex"?o.codexInternetAccess:void 0,branch:o.branch||void 0,createBranch:o.branch?o.createBranch:void 0,useWorktree:o.branch?o.useWorktree:void 0,mcpServers:Object.keys(o.mcpServers).length>0?o.mcpServers:void 0,skills:o.skills.length>0?o.skills:void 0,allowedTools:o.allowedTools.length>0?o.allowedTools:void 0,enabled:!0,triggers:{webhook:{enabled:o.webhookEnabled,secret:""},schedule:{enabled:o.scheduleEnabled,expression:o.scheduleExpression,recurring:o.scheduleRecurring},linear:{enabled:o.linearEnabled,...o.linearOAuthConnectionId?{oauthConnectionId:o.linearOAuthConnectionId}:{}}}};v?await z.updateAgent(v,x):await z.createAgent(x),await W(),g("list"),j(null),window.location.hash="#/agents"}catch(c){p(c instanceof Error?c.message:String(c))}finally{b(!1)}}async function me(c){var n,A;const x=d.find(T=>T.id===c),s=((A=(n=x==null?void 0:x.triggers)==null?void 0:n.linear)==null?void 0:A.enabled)?"Delete this Linear agent? It will no longer respond to @mentions in Linear.":"Delete this agent?";if(confirm(s))try{await z.deleteAgent(c),await W()}catch{}}async function ge(c){try{await z.toggleAgent(c),await W()}catch{}}async function ue(c,x){try{await z.runAgent(c.id,x),M(null),w(""),await W()}catch{}}function be(c){c.prompt.includes("{{input}}")?(M(c),w("")):ue(c)}async function fe(c){try{const x=await z.exportAgent(c.id),f=new Blob([JSON.stringify(x,null,2)],{type:"application/json"}),s=URL.createObjectURL(f),n=document.createElement("a");n.href=s,n.download=`${c.id}.agent.json`,n.click(),URL.revokeObjectURL(s)}catch{}}async function J(c){var f;const x=(f=c.target.files)==null?void 0:f[0];if(x){try{const s=await x.text(),n=JSON.parse(s);await z.importAgent(n),await W()}catch(s){p(s instanceof Error?s.message:"Failed to import agent")}l.current&&(l.current.value="")}}function se(c){const x=qe(c,i);navigator.clipboard.writeText(x).then(()=>{B(c.id),setTimeout(()=>B(null),2e3)})}async function ce(c){if(confirm("Regenerate webhook secret? The old URL will stop working."))try{await z.regenerateAgentWebhookSecret(c),await W()}catch{}}if(h==="edit")return e.jsx(Qe,{form:o,setForm:y,editingId:v,publicUrl:i,error:C,saving:k,onSave:xe,onCancel:Q,linearOAuthConfigured:V});if(h==="edit-linear"&&v)return e.jsx(Xe,{form:o,setForm:y,editingId:v,error:C,saving:k,onSave:xe,onCancel:Q,onOpenGenericEditor:()=>g("edit")});if(h==="setup-linear")return e.jsx("main",{className:"h-full overflow-y-auto bg-cc-bg",children:e.jsxs("div",{className:"max-w-3xl mx-auto px-4 sm:px-8 py-6 sm:py-10",children:[e.jsxs("div",{className:"flex items-center justify-between mb-8",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ne,{className:"w-6 h-6 text-cc-fg"}),e.jsx("h1",{className:"text-xl font-semibold text-cc-fg",children:"Linear Agent Setup"})]}),e.jsx("button",{onClick:te,className:"px-3 py-2 rounded-lg text-sm text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Cancel"})]}),e.jsx(He,{steps:I,currentStep:H,completedSteps:Y}),e.jsxs("div",{className:"bg-cc-card border border-cc-border rounded-xl p-5 sm:p-7",children:[H===1&&e.jsx(Pe,{onNext:()=>O(2)}),H===2&&e.jsx(Ue,{onNext:c=>{G(c),O(3)},onBack:()=>O(1),selectedConnectionId:P}),H===3&&e.jsx(Fe,{onNext:N,onBack:()=>O(2),oauthConnectionId:P,existingAgent:$?{id:$.id,name:$.name,prompt:$.prompt,backendType:$.backendType,model:$.model,cwd:$.cwd}:void 0}),H===4&&e.jsx(_e,{agentName:le,onFinish:ie,onAddAnotherSameApp:pe,onAddAnotherNewApp:de})]})]})});const ve={all:d.length,linear:d.filter(c=>{var x,f;return(f=(x=c.triggers)==null?void 0:x.linear)==null?void 0:f.enabled}).length,scheduled:d.filter(c=>{var x,f;return(f=(x=c.triggers)==null?void 0:x.schedule)==null?void 0:f.enabled}).length,webhook:d.filter(c=>{var x,f;return(f=(x=c.triggers)==null?void 0:x.webhook)==null?void 0:f.enabled}).length},re=d.filter(c=>{var x,f,s,n,A,T;switch(R){case"linear":return((f=(x=c.triggers)==null?void 0:x.linear)==null?void 0:f.enabled)===!0;case"scheduled":return((n=(s=c.triggers)==null?void 0:s.schedule)==null?void 0:n.enabled)===!0;case"webhook":return((T=(A=c.triggers)==null?void 0:A.webhook)==null?void 0:T.enabled)===!0;default:return!0}});return e.jsxs("div",{className:"h-full overflow-y-auto bg-cc-bg",children:[e.jsxs("div",{className:"max-w-4xl mx-auto p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Agents"}),e.jsx("p",{className:"text-xs text-cc-muted mt-0.5",children:"Reusable autonomous session configs. Run manually, via webhook, or on a schedule."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{ref:l,type:"file",accept:".json",onChange:J,className:"hidden"}),e.jsx("button",{onClick:()=>{var c;return(c=l.current)==null?void 0:c.click()},className:"px-3 py-1.5 text-xs rounded-lg border border-cc-border text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Import"}),e.jsx("button",{onClick:oe,className:"px-3 py-1.5 text-xs rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors cursor-pointer",children:"+ New Agent"})]})]}),C&&e.jsx("div",{className:"mb-4 px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/30 text-cc-error text-xs",children:C}),e.jsx(De,{publicUrl:i}),!m&&d.length>0&&e.jsx("div",{className:"flex items-center gap-1 mb-4","data-testid":"filter-tabs",children:["all","linear","scheduled","webhook"].map(c=>e.jsxs("button",{onClick:()=>U(c),className:`text-xs px-2.5 py-1 rounded-full transition-colors cursor-pointer ${R===c?"bg-cc-fg text-cc-bg":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:[Te[c]," (",ve[c],")"]},c))}),m?e.jsx("div",{className:"text-sm text-cc-muted",children:"Loading..."}):d.length===0?e.jsxs("div",{className:"text-center py-16",children:[e.jsx("div",{className:"mb-3 flex justify-center text-cc-muted",children:e.jsx(he,{icon:"bot",className:"w-8 h-8"})}),e.jsx("p",{className:"text-sm text-cc-muted",children:"No agents yet"}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Create an agent to get started, or import a shared JSON config."})]}):re.length===0?e.jsx("div",{className:"text-center py-12",children:R==="linear"?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mb-3 flex justify-center text-cc-muted",children:e.jsx(ne,{className:"w-6 h-6"})}),e.jsx("p",{className:"text-sm text-cc-muted",children:"No Linear agents"}),e.jsx("p",{className:"text-xs text-cc-muted mt-1",children:"Create a Linear agent to respond to @mentions in Linear issues."}),e.jsxs("button",{onClick:X,className:"mt-3 px-3 py-1.5 text-xs rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors cursor-pointer inline-flex items-center gap-1.5",children:[e.jsx(ne,{className:"w-3 h-3"}),"Setup Linear Agent"]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-sm text-cc-muted",children:["No ",Te[R].toLowerCase()," agents"]}),e.jsxs("p",{className:"text-xs text-cc-muted mt-1",children:[R==="scheduled"&&"Create an agent with a schedule trigger to see it here.",R==="webhook"&&"Create an agent with a webhook trigger to see it here."]})]})}):e.jsx("div",{className:"space-y-3",children:re.map(c=>e.jsx(Ge,{agent:c,publicUrl:i,onEdit:()=>Z(c),onDelete:()=>me(c.id),onToggle:()=>ge(c.id),onRun:()=>be(c),onExport:()=>fe(c),onCopyWebhook:()=>se(c),onRegenerateSecret:()=>ce(c.id),copiedWebhook:L},c.id))})]}),S&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>M(null),children:e.jsxs("div",{className:"bg-cc-card rounded-[14px] shadow-2xl p-6 w-full max-w-lg border border-cc-border",onClick:c=>c.stopPropagation(),children:[e.jsxs("h3",{className:"text-sm font-medium text-cc-fg mb-1",children:["Run ",S.name]}),e.jsxs("p",{className:"text-xs text-cc-muted mb-3",children:["This agent's prompt uses ","{{input}}"," — provide the input below."]}),e.jsx("textarea",{value:E,onChange:c=>w(c.target.value),placeholder:"Enter input for the agent...",className:"w-full px-3 py-2 rounded-lg bg-cc-input-bg border border-cc-border text-cc-fg text-sm resize-none h-24 focus:outline-none focus:ring-1 focus:ring-cc-primary",autoFocus:!0}),e.jsxs("div",{className:"flex justify-end gap-2 mt-3",children:[e.jsx("button",{onClick:()=>M(null),className:"px-3 py-1.5 text-xs rounded-lg border border-cc-border text-cc-muted hover:text-cc-fg transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{onClick:()=>ue(S,E),className:"px-3 py-1.5 text-xs rounded-lg bg-cc-primary text-white hover:bg-cc-primary-hover transition-colors cursor-pointer",children:"Run"})]})]})})]})}export{tt as AgentsPage};
@@ -0,0 +1 @@
1
+ import{r as a,a as j,j as e,t as W,w as _,x as B,y as U,z as Y,F as q}from"./index-DkqeP-R9.js";function z(s,p,c=!0){a.useEffect(()=>{if(!c)return;function d(o){s.some(m=>m.current&&m.current.contains(o.target))||p()}return document.addEventListener("pointerdown",d),()=>document.removeEventListener("pointerdown",d)},[s,p,c])}function J(s){const p=s-Date.now();if(p<=0)return"now";const c=Math.floor(p/6e4);if(c<60)return`in ${c}m`;const d=Math.floor(c/60);return d<24?`in ${d}h`:`in ${Math.floor(d/24)}d`}function F(s,p){if(!p)return"One-time";const c=s.trim().split(/\s+/);if(c.length!==5)return s;const[d,o,g,m,x]=c;if(s==="* * * * *")return"Every minute";if(o==="*"&&g==="*"&&m==="*"&&x==="*"&&d.startsWith("*/")){const l=parseInt(d.slice(2),10);return l===1?"Every minute":`Every ${l} minutes`}if(d==="0"&&g==="*"&&m==="*"&&x==="*"){if(o==="*")return"Every hour";if(o.startsWith("*/")){const l=parseInt(o.slice(2),10);return l===1?"Every hour":`Every ${l} hours`}}if(g==="*"&&m==="*"&&d!=="*"&&o!=="*"&&!o.includes("/")&&!o.includes(",")){const l=parseInt(o,10),y=parseInt(d,10);if(!isNaN(l)&&!isNaN(y)){const u=l>=12?"PM":"AM",w=l===0?12:l>12?l-12:l,r=y.toString().padStart(2,"0"),v=`${w}:${r} ${u}`;if(x==="*")return`Every day at ${v}`;if(x==="1-5")return`Weekdays at ${v}`;if(x==="0,6")return`Weekends at ${v}`}}return s}const $={name:"",prompt:"",recurring:!0,schedule:"0 8 * * *",oneTimeDate:"",backendType:"claude",model:B("claude"),cwd:""},G=[{label:"Every hour",value:"0 * * * *"},{label:"Every day at 8am",value:"0 8 * * *"},{label:"Every 2 hours",value:"0 */2 * * *"},{label:"Weekdays at 9am",value:"0 9 * * 1-5"}];function X({onClose:s,embedded:p=!1}){const[c,d]=a.useState([]),[o,g]=a.useState(!0),[m,x]=a.useState(""),[l,y]=a.useState(null),[u,w]=a.useState($),[r,v]=a.useState($),[h,M]=a.useState(!1),[f,S]=a.useState(!1),[k,E]=a.useState(new Set),n=a.useCallback(()=>{j.listCronJobs().then(d).catch(()=>{}).finally(()=>g(!1))},[]);a.useEffect(()=>{n();const t=setInterval(n,1e4);return()=>clearInterval(t)},[n]);async function C(){const t=r.name.trim(),i=r.prompt.trim();if(!t||!i)return;M(!0),x("");let N=r.schedule;!r.recurring&&r.oneTimeDate&&(N=new Date(r.oneTimeDate).toISOString());try{await j.createCronJob({name:t,prompt:i,schedule:N,recurring:r.recurring,backendType:r.backendType,model:r.model.trim()||void 0,cwd:r.cwd.trim()||void 0}),v($),S(!1),n()}catch(b){x(b instanceof Error?b.message:String(b))}finally{M(!1)}}function R(t){y(t.id),w({name:t.name,prompt:t.prompt,recurring:t.recurring,schedule:t.schedule,oneTimeDate:"",backendType:t.backendType,model:t.model,cwd:t.cwd}),x("")}function D(){y(null),x("")}async function L(){if(!l)return;const t=u.name.trim(),i=u.prompt.trim();if(!t||!i)return;let N=u.schedule;!u.recurring&&u.oneTimeDate&&(N=new Date(u.oneTimeDate).toISOString());try{await j.updateCronJob(l,{name:t,prompt:i,schedule:N,recurring:u.recurring,backendType:u.backendType,model:u.model.trim()||void 0,cwd:u.cwd.trim()||void 0}),y(null),x(""),n()}catch(b){x(b instanceof Error?b.message:String(b))}}async function A(t){try{await j.deleteCronJob(t),l===t&&y(null),n()}catch(i){x(i instanceof Error?i.message:String(i))}}async function I(t){try{await j.toggleCronJob(t),n()}catch(i){x(i instanceof Error?i.message:String(i))}}async function P(t){E(i=>new Set(i).add(t));try{await j.runCronJob(t),n()}catch(i){x(i instanceof Error?i.message:String(i))}finally{E(i=>{const N=new Set(i);return N.delete(t),N})}}if(p)return e.jsx("div",{className:"h-full bg-cc-bg text-cc-fg font-sans-ui antialiased overflow-y-auto",children:e.jsxs("div",{className:"max-w-2xl mx-auto px-4 sm:px-6 py-6 sm:py-10 pb-safe",children:[e.jsx("div",{className:"flex items-start justify-between gap-3 mb-2",children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-lg font-semibold text-cc-fg",children:"Scheduled Tasks"}),e.jsx("p",{className:"mt-0.5 text-[13px] text-cc-muted leading-relaxed",children:"Run autonomous Claude Code or Codex sessions on a schedule."})]})}),e.jsxs("div",{className:"flex items-center gap-2 mt-4 mb-5",children:[e.jsx("div",{className:"flex-1"}),e.jsxs("button",{onClick:()=>S(!f),className:`flex items-center gap-1.5 px-3.5 py-2.5 min-h-[44px] rounded-lg text-sm font-medium transition-colors cursor-pointer shrink-0 ${f?"bg-cc-active text-cc-fg":"bg-cc-primary hover:bg-cc-primary-hover text-white"}`,children:[e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"w-4 h-4",children:f?e.jsx("path",{d:"M18 6 6 18M6 6l12 12"}):e.jsx("path",{d:"M12 5v14M5 12h14"})}),e.jsx("span",{className:"hidden sm:inline",children:f?"Cancel":"New Task"})]})]}),f&&e.jsxs("div",{className:"mb-6 rounded-xl bg-cc-card p-4 sm:p-5 space-y-3",style:{animation:"fadeSlideIn 150ms ease-out"},children:[e.jsx(T,{form:r,onChange:v}),e.jsx("p",{className:"text-[10px] text-cc-muted",children:"Scheduled tasks run with full autonomy (bypassPermissions)"}),m&&f&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 text-xs text-cc-error",children:m}),e.jsx("div",{className:"flex items-center justify-end pt-1",children:e.jsx("button",{onClick:C,disabled:!r.name.trim()||!r.prompt.trim()||h,className:`px-4 py-2.5 min-h-[44px] rounded-lg text-sm font-medium transition-colors ${r.name.trim()&&r.prompt.trim()&&!h?"bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer":"bg-cc-hover text-cc-muted cursor-not-allowed"}`,children:h?"Creating...":"Create"})})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-3 text-[12px] text-cc-muted",children:[e.jsxs("span",{children:[c.length," task",c.length!==1?"s":""]}),c.filter(t=>t.enabled).length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-cc-border",children:"·"}),e.jsxs("span",{children:[c.filter(t=>t.enabled).length," active"]})]})]}),o?e.jsx("div",{className:"py-12 text-center text-sm text-cc-muted",children:"Loading scheduled tasks..."}):c.length===0?e.jsx("div",{className:"py-12 text-center text-sm text-cc-muted",children:"No scheduled tasks yet."}):e.jsx("div",{className:"space-y-1",children:c.map(t=>l===t.id?e.jsxs("div",{className:"rounded-xl bg-cc-card p-4 space-y-3",style:{animation:"fadeSlideIn 150ms ease-out"},children:[e.jsx(T,{form:u,onChange:w}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:D,className:"px-3 py-2.5 min-h-[44px] text-sm rounded-lg text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{onClick:()=>void L(),className:"px-4 py-2.5 min-h-[44px] text-sm rounded-lg font-medium bg-cc-primary hover:bg-cc-primary-hover text-white transition-colors cursor-pointer",children:"Save"})]})]},t.id):e.jsx(K,{job:t,isRunning:k.has(t.id),onStartEdit:()=>R(t),onDelete:()=>void A(t.id),onToggle:()=>void I(t.id),onRunNow:()=>void P(t.id)},t.id))}),m&&!f&&e.jsx("div",{className:"mt-4 px-3 py-2 rounded-lg bg-cc-error/10 text-xs text-cc-error",children:m})]})});const O=m&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 text-xs text-cc-error",children:m}),H=o?e.jsx("div",{className:"text-sm text-cc-muted text-center py-6",children:"Loading scheduled tasks..."}):c.length===0?e.jsx("div",{className:"text-sm text-cc-muted text-center py-6",children:"No scheduled tasks yet."}):e.jsx("div",{className:"space-y-3",children:c.map(t=>e.jsxs("div",{className:"rounded-xl bg-cc-card overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[e.jsx("span",{className:"text-sm font-medium text-cc-fg flex-1 truncate",children:t.name}),e.jsx("span",{className:`text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 ${t.backendType==="codex"?"text-blue-500 bg-blue-500/10":"text-[#5BA8A0] bg-[#5BA8A0]/10"}`,children:t.backendType==="codex"?"Codex":"Claude"}),t.consecutiveFailures>0&&e.jsxs("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-cc-error bg-cc-error/10",children:[t.consecutiveFailures," fail",t.consecutiveFailures!==1?"s":""]}),e.jsx("button",{onClick:()=>I(t.id),className:`relative w-10 h-6 rounded-full transition-colors cursor-pointer shrink-0 ${t.enabled?"bg-cc-primary":"bg-cc-border"}`,title:t.enabled?"Disable":"Enable",children:e.jsx("span",{className:`absolute top-[3px] w-[18px] h-[18px] rounded-full bg-white transition-transform ${t.enabled?"left-[19px]":"left-[3px]"}`})}),l===t.id?e.jsx("button",{onClick:D,className:"text-xs px-2 py-1.5 min-h-[44px] text-cc-muted hover:text-cc-fg cursor-pointer",children:"Cancel"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>P(t.id),disabled:k.has(t.id),className:`text-xs px-2 py-1.5 min-h-[44px] cursor-pointer ${k.has(t.id)?"text-cc-muted cursor-not-allowed":"text-cc-primary hover:text-cc-primary-hover"}`,children:k.has(t.id)?"Running...":"Run Now"}),e.jsx("button",{onClick:()=>R(t),className:"text-xs px-2 py-1.5 min-h-[44px] text-cc-muted hover:text-cc-fg cursor-pointer",children:"Edit"}),e.jsx("button",{onClick:()=>A(t.id),className:"text-xs px-2 py-1.5 min-h-[44px] text-cc-muted hover:text-cc-error cursor-pointer",children:"Delete"})]})]}),l===t.id&&e.jsxs("div",{className:"px-3 py-3 space-y-2.5",children:[e.jsx(T,{form:u,onChange:w}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:L,className:"px-4 py-2.5 min-h-[44px] text-sm font-medium bg-cc-primary hover:bg-cc-primary-hover text-white rounded-lg transition-colors cursor-pointer",children:"Save"}),e.jsx("button",{onClick:D,className:"px-3 py-2.5 min-h-[44px] text-sm font-medium text-cc-muted hover:text-cc-fg rounded-lg transition-colors cursor-pointer",children:"Cancel"})]})]}),l!==t.id&&e.jsxs("div",{className:"px-3 py-2.5 space-y-1.5",children:[e.jsx("div",{className:"text-xs text-cc-muted truncate",title:t.prompt,children:t.prompt}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-cc-muted",children:[e.jsx("span",{children:F(t.schedule,t.recurring)}),t.nextRunAt!=null&&t.enabled&&e.jsxs("span",{children:["Next: ",J(t.nextRunAt)]}),t.lastRunAt!=null&&e.jsxs("span",{className:"flex items-center gap-1",children:["Last: ",W(t.lastRunAt),t.consecutiveFailures===0?e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-success",children:e.jsx("path",{d:"M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2.5-2.5a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z"})}):e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 text-cc-error",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.totalRuns>0&&e.jsxs("span",{children:[t.totalRuns," run",t.totalRuns!==1?"s":""]}),t.cwd&&e.jsx("span",{className:"font-mono-code truncate max-w-[200px]",title:t.cwd,children:t.cwd})]})]})]},t.id))}),V=e.jsxs("div",{className:"rounded-xl bg-cc-card overflow-hidden",children:[e.jsxs("button",{onClick:()=>S(!f),className:"w-full flex items-center gap-2 px-3 py-2.5 cursor-pointer hover:bg-cc-hover transition-colors",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`w-3 h-3 text-cc-muted transition-transform ${f?"rotate-90":""}`,children:e.jsx("path",{d:"M6 4l4 4-4 4",strokeLinecap:"round",strokeLinejoin:"round"})}),e.jsx("span",{className:"text-sm font-medium text-cc-fg",children:"New Scheduled Task"})]}),f&&e.jsxs("div",{className:"px-3 py-3 space-y-2.5",children:[e.jsx(T,{form:r,onChange:v}),e.jsx("div",{className:"text-[10px] text-cc-muted",children:"Scheduled tasks run with full autonomy (bypassPermissions)"}),e.jsx("button",{onClick:C,disabled:!r.name.trim()||!r.prompt.trim()||h,className:`px-4 py-2.5 min-h-[44px] text-sm font-medium rounded-lg transition-colors ${r.name.trim()&&r.prompt.trim()&&!h?"bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer":"bg-cc-hover text-cc-muted cursor-not-allowed"}`,children:h?"Creating...":"Create"})]})]}),Z=e.jsxs("div",{className:"w-full max-w-2xl max-h-[90dvh] sm:max-h-[80dvh] mx-0 sm:mx-4 flex flex-col bg-cc-bg rounded-t-[14px] sm:rounded-[14px] shadow-2xl overflow-hidden",onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-4 sm:px-5 py-3 sm:py-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold text-cc-fg",children:"Scheduled Tasks"}),e.jsx("p",{className:"text-xs text-cc-muted mt-0.5",children:"Run autonomous Claude Code or Codex sessions on a schedule"})]}),s&&e.jsx("button",{onClick:s,className:"w-8 h-8 flex items-center justify-center rounded-md 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:"none",stroke:"currentColor",strokeWidth:"2",className:"w-3.5 h-3.5",children:e.jsx("path",{d:"M4 4l8 8M12 4l-8 8",strokeLinecap:"round"})})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-3 sm:px-5 py-3 sm:py-4 pb-safe space-y-4",children:[O,H,V]})]});return _.createPortal(e.jsx("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-black/50",onClick:s,children:Z}),document.body)}function K({job:s,isRunning:p,onStartEdit:c,onDelete:d,onToggle:o,onRunNow:g}){return e.jsxs("div",{className:"group flex items-start gap-3 px-3 py-3 min-h-[44px] rounded-lg hover:bg-cc-hover/60 transition-colors",children:[e.jsx("div",{className:"shrink-0 mt-0.5 w-7 h-7 rounded-md bg-cc-primary/10 flex items-center justify-center",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-3.5 h-3.5 text-cc-primary",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 6v6l4 2"})]})}),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:s.name}),e.jsx("span",{className:`text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 ${s.backendType==="codex"?"text-blue-500 bg-blue-500/10":"text-[#5BA8A0] bg-[#5BA8A0]/10"}`,children:s.backendType==="codex"?"Codex":"Claude"}),s.consecutiveFailures>0&&e.jsxs("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-cc-error bg-cc-error/10",children:[s.consecutiveFailures," fail",s.consecutiveFailures!==1?"s":""]}),!s.enabled&&e.jsx("span",{className:"text-[9px] font-medium px-1.5 rounded-full leading-[16px] shrink-0 text-cc-muted bg-cc-hover",children:"Paused"})]}),e.jsx("p",{className:"mt-0.5 text-xs text-cc-muted line-clamp-1 leading-relaxed",children:s.prompt}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-0.5 mt-1 text-[11px] text-cc-muted",children:[e.jsx("span",{children:F(s.schedule,s.recurring)}),s.nextRunAt!=null&&s.enabled&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-cc-border",children:"·"}),e.jsxs("span",{children:["Next ",J(s.nextRunAt)]})]}),s.lastRunAt!=null&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-cc-border",children:"·"}),e.jsxs("span",{className:"flex items-center gap-0.5",children:["Last ",W(s.lastRunAt),s.consecutiveFailures===0?e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-2.5 h-2.5 text-cc-success",children:e.jsx("path",{d:"M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2.5-2.5a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z"})}):e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-2.5 h-2.5 text-cc-error",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.totalRuns>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-cc-border",children:"·"}),e.jsxs("span",{children:[s.totalRuns," run",s.totalRuns!==1?"s":""]})]})]})]}),e.jsxs("div",{className:"shrink-0 flex items-center gap-0.5 opacity-100 sm:opacity-0 sm:group-hover:opacity-100 transition-opacity",children:[e.jsx("button",{onClick:o,className:`relative w-9 h-5 rounded-full transition-colors cursor-pointer shrink-0 ${s.enabled?"bg-cc-primary":"bg-cc-border"}`,title:s.enabled?"Disable":"Enable",children:e.jsx("span",{className:`absolute top-[2px] w-4 h-4 rounded-full bg-white transition-transform ${s.enabled?"left-[17px]":"left-[2px]"}`})}),e.jsx("button",{onClick:g,disabled:p,className:`p-2 min-h-[44px] min-w-[44px] sm:min-h-0 sm:min-w-0 sm:p-1.5 rounded-md transition-colors cursor-pointer ${p?"text-cc-muted cursor-not-allowed":"text-cc-primary hover:bg-cc-primary/10"}`,"aria-label":"Run now",title:p?"Running...":"Run now",children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",className:"w-3.5 h-3.5",children:e.jsx("path",{d:"M8 5v14l11-7z"})})}),e.jsx("button",{onClick:c,className:"p-2 min-h-[44px] min-w-[44px] sm:min-h-0 sm:min-w-0 sm:p-1.5 rounded-md text-cc-muted hover:text-cc-fg hover:bg-cc-active transition-colors cursor-pointer","aria-label":"Edit",children:e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-3.5 h-3.5",children:[e.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),e.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5Z"})]})}),e.jsx("button",{onClick:d,className:"p-2 min-h-[44px] min-w-[44px] sm:min-h-0 sm:min-w-0 sm:p-1.5 rounded-md text-cc-muted hover:text-cc-error hover:bg-cc-error/10 transition-colors cursor-pointer","aria-label":"Delete",children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"w-3.5 h-3.5",children:e.jsx("path",{d:"M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2m3 0v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6h14Z"})})})]})]})}function T({form:s,onChange:p}){const c=n=>p({...s,...n}),[d,o]=a.useState(null),[g,m]=a.useState(!1),x=a.useRef(null),[l,y]=a.useState(!1),[u,w]=a.useState(!1),r=a.useRef(null),v=d||U(s.backendType),h=v.find(n=>n.value===s.model)||v[0];a.useEffect(()=>{o(null),s.backendType==="codex"&&j.getBackendModels(s.backendType).then(n=>{if(n.length>0){const C=Y(n);o(C),C.some(R=>R.value===s.model)||c({model:C[0].value})}}).catch(()=>{})},[s.backendType]),a.useEffect(()=>{s.model||c({model:B(s.backendType)})},[]);const M=a.useMemo(()=>[x],[]),f=a.useCallback(()=>m(!1),[]);z(M,f,g);const S=a.useMemo(()=>[r],[]),k=a.useCallback(()=>w(!1),[]);z(S,k,u);const E=s.cwd?s.cwd.split("/").pop()||s.cwd:"Select folder";return e.jsxs("div",{className:"space-y-2.5",children:[e.jsx("input",{type:"text",value:s.name,onChange:n=>c({name:n.target.value}),placeholder:"Task name (e.g. Daily test suite)",className:"w-full px-3 py-2.5 min-h-[44px] text-sm bg-cc-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40 transition-shadow"}),e.jsx("textarea",{value:s.prompt,onChange:n=>c({prompt:n.target.value}),placeholder:"Prompt for the session (e.g. Run the test suite and fix any failures)",rows:4,className:"w-full px-3 py-2.5 text-sm bg-cc-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40 resize-y transition-shadow",style:{minHeight:"100px"}}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>c({recurring:!0}),className:`px-2.5 py-2 min-h-[44px] text-xs font-medium rounded-lg transition-colors cursor-pointer ${s.recurring?"bg-cc-primary text-white":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:"Recurring"}),e.jsx("button",{onClick:()=>c({recurring:!1}),className:`px-2.5 py-2 min-h-[44px] text-xs font-medium rounded-lg transition-colors cursor-pointer ${s.recurring?"bg-cc-hover text-cc-muted hover:text-cc-fg":"bg-cc-primary text-white"}`,children:"One-time"})]}),s.recurring?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:G.map(n=>e.jsx("button",{onClick:()=>c({schedule:n.value}),className:`px-2.5 py-2 min-h-[44px] text-xs font-medium rounded-md transition-colors cursor-pointer ${s.schedule===n.value?"bg-cc-primary/20 text-cc-primary":"bg-cc-hover text-cc-muted hover:text-cc-fg"}`,children:n.label},n.value))}),e.jsx("input",{type:"text",value:s.schedule,onChange:n=>c({schedule:n.target.value}),placeholder:"Cron expression (e.g. 0 8 * * *)",className:"w-full px-3 py-2.5 min-h-[44px] text-sm font-mono-code bg-cc-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40 transition-shadow"}),e.jsx("div",{className:"text-[10px] text-cc-muted",children:F(s.schedule,!0)})]}):e.jsx("input",{type:"datetime-local",value:s.oneTimeDate,onChange:n=>c({oneTimeDate:n.target.value}),className:"w-full px-3 py-2.5 min-h-[44px] text-sm bg-cc-bg rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:ring-1 focus:ring-cc-primary/40 transition-shadow"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsxs("div",{className:"relative",ref:r,children:[e.jsxs("button",{onClick:()=>w(!u),className:"flex items-center gap-1.5 px-2.5 py-2 min-h-[44px] text-xs font-medium text-cc-fg rounded-lg hover:bg-cc-hover transition-colors cursor-pointer",children:[e.jsx("span",{children:s.backendType==="codex"?"Codex":"Claude Code"}),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.jsx("div",{className:"absolute left-0 bottom-full mb-1 w-40 bg-cc-card rounded-xl shadow-lg z-10 py-1",children:[{value:"claude",label:"Claude Code"},{value:"codex",label:"Codex"}].map(n=>e.jsx("button",{onClick:()=>{c({backendType:n.value,model:B(n.value)}),w(!1)},className:`w-full px-3 py-2.5 min-h-[44px] text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer ${n.value===s.backendType?"text-cc-primary font-medium":"text-cc-fg"}`,children:n.label},n.value))})]}),e.jsxs("div",{className:"relative",ref:x,children:[e.jsxs("button",{onClick:()=>m(!g),className:"flex items-center gap-1.5 px-2.5 py-2 min-h-[44px] text-xs text-cc-muted hover:text-cc-fg rounded-lg hover:bg-cc-hover transition-colors cursor-pointer",children:[e.jsx("span",{children:h==null?void 0:h.icon}),e.jsx("span",{children:h==null?void 0:h.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"})})]}),g&&e.jsx("div",{className:"absolute left-0 bottom-full mb-1 w-52 bg-cc-card rounded-xl shadow-lg z-10 py-1",children:v.map(n=>e.jsxs("button",{onClick:()=>{c({model:n.value}),m(!1)},className:`w-full px-3 py-2.5 min-h-[44px] text-xs text-left hover:bg-cc-hover transition-colors cursor-pointer flex items-center gap-2 ${n.value===s.model?"text-cc-primary font-medium":"text-cc-fg"}`,children:[e.jsx("span",{children:n.icon}),n.label]},n.value))})]}),e.jsxs("button",{onClick:()=>y(!0),className:"flex items-center gap-1.5 px-2.5 py-2 min-h-[44px] text-xs text-cc-muted hover:text-cc-fg rounded-lg hover:bg-cc-hover transition-colors cursor-pointer",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.379a1.5 1.5 0 011.06.44l.622.621a.5.5 0 00.353.146H13.5A1.5 1.5 0 0115 4.707V12.5a1.5 1.5 0 01-1.5 1.5h-11A1.5 1.5 0 011 12.5v-9z"})}),e.jsx("span",{className:"max-w-[200px] truncate font-mono-code",children:E}),e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3 h-3 opacity-50",children:e.jsx("path",{d:"M4 6l4 4 4-4"})})]}),l&&e.jsx(q,{initialPath:s.cwd||"",onSelect:n=>c({cwd:n}),onClose:()=>y(!1)})]})]})}export{X as CronManager};
@@ -0,0 +1 @@
1
+ import{r,a,j as e,u as N,n as y,b as _,L as h}from"./index-DkqeP-R9.js";function L({embedded:d=!1}){const[g,p]=r.useState(!1),[b,v]=r.useState(""),[x,f]=r.useState(""),[s,m]=r.useState(null),[c,j]=r.useState([]),[o,w]=r.useState([]);r.useEffect(()=>{a.getTailscaleStatus().then(m).catch(()=>m({installed:!1,binaryPath:null,connected:!1,dnsName:null,funnelActive:!1,funnelUrl:null,error:"Could not reach Tailscale status endpoint"})),a.getSettings().then(t=>{if(t.linearApiKeyConfigured)return a.getLinearConnection().then(n=>{p(n.connected);const i=n.viewerName||n.viewerEmail||"Connected account",l=n.teamName?` • ${n.teamName}`:"";v(`${i}${l}`)})}).catch(t=>f(t instanceof Error?t.message:String(t))),a.listLinearOAuthConnections().then(t=>j(t.connections)).catch(()=>{}),a.listAgents().then(t=>{w(t.filter(n=>{var i,l;return(l=(i=n.triggers)==null?void 0:i.linear)==null?void 0:l.enabled}))}).catch(()=>{})},[]);const u=c.filter(t=>t.status==="connected").length;return e.jsx("div",{className:`${d?"h-full":"h-[100dvh]"} bg-cc-bg text-cc-fg font-sans-ui antialiased overflow-y-auto`,children:e.jsxs("div",{className:"max-w-5xl mx-auto px-4 sm:px-8 py-6 sm:py-10 pb-safe",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold text-cc-fg",children:"Integrations"}),e.jsx("p",{className:"mt-1 text-sm text-cc-muted",children:"Connect tools and open their dedicated settings page."})]}),!d&&e.jsx("button",{onClick:()=>{const t=N.getState().currentSessionId;t?y(t):_()},className:"px-3 py-2.5 min-h-[44px] rounded-lg text-sm text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Back"})]}),x&&e.jsx("div",{className:"mb-4 px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:x}),e.jsxs("section",{className:"group relative overflow-hidden rounded-3xl border border-cc-border/80 bg-cc-card p-5 pb-16 sm:p-7 sm:pb-7 transition-all duration-300 hover:border-cc-primary/35 hover:shadow-[0_18px_44px_rgba(0,0,0,0.18)]",children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-[radial-gradient(80%_140%_at_100%_0%,rgba(251,146,60,0.18),transparent_52%)]"}),e.jsx("div",{className:"pointer-events-none absolute inset-0 opacity-30 bg-[linear-gradient(120deg,transparent_0%,rgba(255,255,255,0.04)_35%,transparent_62%)]"}),e.jsxs("div",{className:"relative min-w-0",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-cc-border bg-cc-hover/55 px-3 py-1.5 text-xs tracking-wide text-cc-muted",children:[e.jsx(h,{className:"h-3.5 w-3.5 text-cc-fg"}),e.jsx("span",{children:"Linear Tickets"}),g&&e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-cc-success shadow-[0_0_0_3px_rgba(34,197,94,0.15)]","aria-label":"Connected",title:"Connected"})]}),e.jsx("div",{className:"mt-4 flex flex-wrap items-center gap-2.5",children:e.jsx("h2",{className:"text-[clamp(1.45rem,2.6vw,2rem)] font-semibold leading-[1.12] tracking-tight text-cc-fg",children:"Issue context before first prompt"})}),e.jsx("p",{className:"mt-2 max-w-2xl text-sm leading-relaxed text-cc-muted sm:text-[15px]",children:"Connect your workspace, search an issue from Home, and inject scope automatically when a session starts."}),e.jsx("div",{className:"mt-4 inline-flex max-w-full items-center rounded-lg border border-cc-border/80 bg-black/10 px-3 py-1.5 text-xs text-cc-muted/95",children:e.jsx("span",{className:"truncate",children:b||"No workspace linked yet"})})]}),e.jsx("div",{className:"absolute bottom-0 right-0 sm:bottom-0 sm:right-0 flex items-center gap-2",children:e.jsx("button",{type:"button",onClick:()=>{window.location.hash="#/integrations/linear"},"aria-label":"Open Linear Tickets settings",title:"Open Linear Tickets settings",className:"inline-flex h-10 w-10 items-center justify-center rounded-full border border-cc-primary/28 bg-cc-primary/12 text-cc-fg transition-colors hover:border-cc-primary/50 hover:bg-cc-primary/20 focus:outline-none focus:ring-2 focus:ring-cc-primary/35 cursor-pointer",children:e.jsxs("svg",{viewBox:"0 0 24 24",className:"h-4.5 w-4.5",fill:"none",stroke:"currentColor",strokeWidth:"1.8","aria-hidden":"true",children:[e.jsx("path",{d:"M9.67 4.53 10 2h4l.33 2.53a7.9 7.9 0 0 1 1.7.7l2.03-1.55 2.83 2.83-1.55 2.03c.28.54.51 1.1.7 1.7L22 10v4l-2.53.33a7.9 7.9 0 0 1-.7 1.7l1.55 2.03-2.83 2.83-2.03-1.55c-.54.28-1.1.51-1.7.7L14 22h-4l-.33-2.53a7.9 7.9 0 0 1-1.7-.7l-2.03 1.55-2.83-2.83 1.55-2.03a7.9 7.9 0 0 1-.7-1.7L2 14v-4l2.53-.33c.19-.6.42-1.16.7-1.7L3.68 5.94 6.5 3.1l2.03 1.55c.54-.28 1.1-.51 1.7-.7Z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3.2"})]})})})]})]}),e.jsxs("section",{className:"group relative mt-6 overflow-hidden rounded-3xl border border-cc-border/80 bg-cc-card p-5 pb-16 sm:p-7 sm:pb-7 transition-all duration-300 hover:border-cc-primary/35 hover:shadow-[0_18px_44px_rgba(0,0,0,0.18)]",children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-[radial-gradient(80%_140%_at_100%_0%,rgba(124,58,237,0.18),transparent_52%)]"}),e.jsx("div",{className:"pointer-events-none absolute inset-0 opacity-30 bg-[linear-gradient(120deg,transparent_0%,rgba(255,255,255,0.04)_35%,transparent_62%)]"}),e.jsxs("div",{className:"relative min-w-0",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-cc-border bg-cc-hover/55 px-3 py-1.5 text-xs tracking-wide text-cc-muted",children:[e.jsx(h,{className:"h-3.5 w-3.5 text-cc-fg"}),e.jsx("span",{children:"Linear OAuth Apps"}),u>0&&e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-cc-success shadow-[0_0_0_3px_rgba(34,197,94,0.15)]","aria-label":"Connected",title:"Connected"})]}),e.jsx("div",{className:"mt-4 flex flex-wrap items-center gap-2.5",children:e.jsx("h2",{className:"text-[clamp(1.45rem,2.6vw,2rem)] font-semibold leading-[1.12] tracking-tight text-cc-fg",children:"Agent triggers via Linear"})}),e.jsx("p",{className:"mt-2 max-w-2xl text-sm leading-relaxed text-cc-muted sm:text-[15px]",children:"Create OAuth apps to trigger agents from @mentions in Linear issues. Each app can connect to a different workspace."}),e.jsx("div",{className:"mt-4 inline-flex max-w-full items-center rounded-lg border border-cc-border/80 bg-black/10 px-3 py-1.5 text-xs text-cc-muted/95",children:e.jsxs("span",{className:"truncate",children:[c.length===0?"No OAuth apps configured":`${c.length} app${c.length!==1?"s":""}, ${u} connected`,o.length>0&&` · ${o.length} agent${o.length!==1?"s":""}`]})})]}),e.jsxs("div",{className:"absolute bottom-0 right-0 sm:bottom-0 sm:right-0 flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>{window.location.hash="#/agents?setup=linear"},"aria-label":"Set up Linear Agent",title:"Set up Linear Agent",className:"inline-flex items-center gap-1.5 px-3 py-2 rounded-full border border-violet-500/28 bg-violet-500/12 text-xs font-medium text-cc-fg transition-colors hover:border-violet-500/50 hover:bg-violet-500/20 focus:outline-none focus:ring-2 focus:ring-violet-500/35 cursor-pointer",children:[e.jsx("svg",{viewBox:"0 0 16 16",fill:"currentColor",className:"w-3.5 h-3.5 opacity-60","aria-hidden":"true",children:e.jsx("path",{d:"M8 1.5a2.5 2.5 0 00-2.5 2.5c0 1.38 1.12 2.5 2.5 2.5s2.5-1.12 2.5-2.5S9.38 1.5 8 1.5zM4 8a4 4 0 00-4 4v1.5a.5.5 0 00.5.5h15a.5.5 0 00.5-.5V12a4 4 0 00-4-4H4z"})}),"Setup Agent"]}),e.jsx("button",{type:"button",onClick:()=>{window.location.hash="#/integrations/linear-oauth"},"aria-label":"Open Linear OAuth settings",title:"Open Linear OAuth settings",className:"inline-flex h-10 w-10 items-center justify-center rounded-full border border-violet-500/28 bg-violet-500/12 text-cc-fg transition-colors hover:border-violet-500/50 hover:bg-violet-500/20 focus:outline-none focus:ring-2 focus:ring-violet-500/35 cursor-pointer",children:e.jsxs("svg",{viewBox:"0 0 24 24",className:"h-4.5 w-4.5",fill:"none",stroke:"currentColor",strokeWidth:"1.8","aria-hidden":"true",children:[e.jsx("path",{d:"M9.67 4.53 10 2h4l.33 2.53a7.9 7.9 0 0 1 1.7.7l2.03-1.55 2.83 2.83-1.55 2.03c.28.54.51 1.1.7 1.7L22 10v4l-2.53.33a7.9 7.9 0 0 1-.7 1.7l1.55 2.03-2.83 2.83-2.03-1.55c-.54.28-1.1.51-1.7.7L14 22h-4l-.33-2.53a7.9 7.9 0 0 1-1.7-.7l-2.03 1.55-2.83-2.83 1.55-2.03a7.9 7.9 0 0 1-.7-1.7L2 14v-4l2.53-.33c.19-.6.42-1.16.7-1.7L3.68 5.94 6.5 3.1l2.03 1.55c.54-.28 1.1-.51 1.7-.7Z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3.2"})]})})]})]})]}),e.jsxs("section",{className:"group relative mt-6 overflow-hidden rounded-3xl border border-cc-border/80 bg-cc-card p-5 pb-16 sm:p-7 sm:pb-7 transition-all duration-300 hover:border-cc-primary/35 hover:shadow-[0_18px_44px_rgba(0,0,0,0.18)]",children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-[radial-gradient(80%_140%_at_100%_0%,rgba(6,182,212,0.18),transparent_52%)]"}),e.jsx("div",{className:"pointer-events-none absolute inset-0 opacity-30 bg-[linear-gradient(120deg,transparent_0%,rgba(255,255,255,0.04)_35%,transparent_62%)]"}),e.jsxs("div",{className:"relative min-w-0",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-cc-border bg-cc-hover/55 px-3 py-1.5 text-xs tracking-wide text-cc-muted",children:[e.jsx("svg",{className:"h-3.5 w-3.5 text-cc-fg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})}),e.jsx("span",{children:"Tailscale"}),(s==null?void 0:s.funnelActive)&&e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-cc-success shadow-[0_0_0_3px_rgba(34,197,94,0.15)]","aria-label":"Funnel active",title:"Funnel active"})]}),e.jsx("div",{className:"mt-4 flex flex-wrap items-center gap-2.5",children:e.jsx("h2",{className:"text-[clamp(1.45rem,2.6vw,2rem)] font-semibold leading-[1.12] tracking-tight text-cc-fg",children:"HTTPS access in one click"})}),e.jsx("p",{className:"mt-2 max-w-2xl text-sm leading-relaxed text-cc-muted sm:text-[15px]",children:"Use Tailscale Funnel to expose your Companion over HTTPS with automatic TLS certificates."}),e.jsx("div",{className:"mt-4 inline-flex max-w-full items-center rounded-lg border border-cc-border/80 bg-black/10 px-3 py-1.5 text-xs text-cc-muted/95",children:e.jsx("span",{className:"truncate",children:s===null?"Checking...":s.funnelActive&&s.funnelUrl?s.funnelUrl:s.connected?s.dnsName||"Connected":s.installed?"Not connected":"Not installed"})})]}),e.jsx("button",{type:"button",onClick:()=>{window.location.hash="#/integrations/tailscale"},"aria-label":"Open Tailscale settings",title:"Open Tailscale settings",className:"absolute bottom-0 right-0 sm:bottom-0 sm:right-0 inline-flex h-10 w-10 items-center justify-center rounded-full border border-cc-primary/28 bg-cc-primary/12 text-cc-fg transition-colors hover:border-cc-primary/50 hover:bg-cc-primary/20 focus:outline-none focus:ring-2 focus:ring-cc-primary/35 cursor-pointer",children:e.jsxs("svg",{viewBox:"0 0 24 24",className:"h-4.5 w-4.5",fill:"none",stroke:"currentColor",strokeWidth:"1.8","aria-hidden":"true",children:[e.jsx("path",{d:"M9.67 4.53 10 2h4l.33 2.53a7.9 7.9 0 0 1 1.7.7l2.03-1.55 2.83 2.83-1.55 2.03c.28.54.51 1.1.7 1.7L22 10v4l-2.53.33a7.9 7.9 0 0 1-.7 1.7l1.55 2.03-2.83 2.83-2.03-1.55c-.54.28-1.1.51-1.7.7L14 22h-4l-.33-2.53a7.9 7.9 0 0 1-1.7-.7l-2.03 1.55-2.83-2.83 1.55-2.03a7.9 7.9 0 0 1-.7-1.7L2 14v-4l2.53-.33c.19-.6.42-1.16.7-1.7L3.68 5.94 6.5 3.1l2.03 1.55c.54-.28 1.1-.51 1.7-.7Z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3.2"})]})})]})]})]})})}export{L as IntegrationsPage};
@@ -0,0 +1 @@
1
+ import{r,a as i,j as e,u as X,n as Y,b as Z,L as M}from"./index-DkqeP-R9.js";function te({embedded:C=!1}){const[o,B]=r.useState([]),[P,U]=r.useState(!0),[S,q]=r.useState(""),[g,A]=r.useState(!1),[l,k]=r.useState(""),[d,I]=r.useState(""),[u,L]=r.useState(""),[m,O]=r.useState(""),[b,D]=r.useState(!1),[E,x]=r.useState(""),[f,$]=r.useState(null),[v,_]=r.useState(null),[F,h]=r.useState(""),[j,R]=r.useState(null),[z,H]=r.useState([]),[w,p]=r.useState(null),a=r.useCallback(async()=>{try{const t=await i.listLinearOAuthConnections();B(t.connections)}catch(t){q(t instanceof Error?t.message:String(t))}finally{U(!1)}},[]),W=r.useCallback(async()=>{try{const t=await i.listAgents();H(t)}catch{}},[]);r.useEffect(()=>{a(),W();let t;const s=window.location.hash;if(s.includes("oauth_success=true"))p({type:"success",message:"OAuth app connected to workspace successfully!"}),window.location.hash="#/integrations/linear-oauth",t=setTimeout(()=>p(null),5e3);else if(s.includes("oauth_error=")){const c=s.match(/oauth_error=([^&]*)/);let n;try{n=decodeURIComponent((c==null?void 0:c[1])||"OAuth failed")}catch{n=(c==null?void 0:c[1])||"OAuth failed"}p({type:"error",message:n}),window.location.hash="#/integrations/linear-oauth"}return()=>{t&&clearTimeout(t)}},[a,W]);async function G(t){t.preventDefault();const s=l.trim(),c=d.trim(),n=u.trim(),T=m.trim();if(!s||!c||!n||!T){x("All fields are required.");return}D(!0),x("");try{await i.createLinearOAuthConnection({name:s,oauthClientId:c,oauthClientSecret:n,webhookSecret:T}),k(""),I(""),L(""),O(""),A(!1),await a()}catch(N){x(N instanceof Error?N.message:String(N))}finally{D(!1)}}async function J(t){if(f!==t){$(t),h("");return}_(t),$(null);try{await i.deleteLinearOAuthConnection(t),h(""),await a()}catch(s){h(s instanceof Error?s.message:String(s)),await a()}finally{_(null)}}async function K(t){R(t);try{const s=await i.getLinearOAuthConnectionAuthorizeUrl(t,"/#/integrations/linear-oauth");window.open(s.url,"_self")}catch(s){p({type:"error",message:s instanceof Error?s.message:String(s)}),R(null)}}function Q(t,s=16){return t.length<=s?t:t.slice(0,s)+"..."}function V(t){return z.filter(s=>{var c,n;return((n=(c=s.triggers)==null?void 0:c.linear)==null?void 0:n.oauthConnectionId)===t})}const y=o.filter(t=>t.status==="connected").length;return e.jsx("div",{className:`${C?"h-full":"h-[100dvh]"} bg-cc-bg text-cc-fg font-sans-ui antialiased overflow-y-auto`,children:e.jsxs("div",{className:"max-w-5xl mx-auto px-4 sm:px-8 py-6 sm:py-10 pb-safe",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold text-cc-fg",children:"Linear OAuth Apps"}),e.jsx("p",{className:"mt-1 text-sm text-cc-muted",children:"Manage OAuth app connections for Linear agent integrations."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>{window.location.hash="#/integrations"},className:"px-3 py-2.5 min-h-[44px] rounded-lg text-sm text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Integrations"}),!C&&e.jsx("button",{onClick:()=>{const t=X.getState().currentSessionId;t?Y(t):Z()},className:"px-3 py-2.5 min-h-[44px] rounded-lg text-sm text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Back"})]})]}),e.jsxs("div",{className:"mb-4 px-3 py-2 rounded-lg bg-cc-hover/60 border border-cc-border text-sm text-cc-muted",children:["Looking for ticket integration?"," ",e.jsx("a",{href:"#/settings/linear",className:"text-cc-primary underline cursor-pointer",children:"Linear Tickets Settings"})]}),w&&e.jsx("div",{className:`mb-4 px-3 py-2 rounded-lg text-xs border ${w.type==="success"?"bg-cc-success/10 border-cc-success/20 text-cc-success":"bg-cc-error/10 border-cc-error/20 text-cc-error"}`,children:w.message}),e.jsxs("section",{className:"relative overflow-hidden bg-cc-card border border-cc-border rounded-xl p-4 sm:p-6 mb-4",children:[e.jsx("div",{className:"absolute inset-0 pointer-events-none bg-[radial-gradient(circle_at_top_right,rgba(124,58,237,0.1),transparent_45%)]"}),e.jsxs("div",{className:"relative flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 px-2.5 py-1 rounded-full border border-cc-border bg-cc-hover/60 text-xs text-cc-muted",children:[e.jsx(M,{className:"w-3.5 h-3.5 text-cc-fg"}),e.jsx("span",{children:"Linear OAuth"})]}),e.jsx("h2",{className:"mt-3 text-lg sm:text-xl font-semibold text-cc-fg",children:"OAuth app connections for agent workflows"}),e.jsx("p",{className:"mt-1.5 text-sm text-cc-muted max-w-2xl",children:"Each connection represents a Linear OAuth app. Agents reference these connections to receive @mentions and interact with Linear issues."})]}),e.jsxs("div",{className:"shrink-0 rounded-xl border border-cc-border bg-cc-bg px-3 py-2 text-right min-w-[170px]",children:[e.jsx("p",{className:"text-[11px] text-cc-muted uppercase tracking-wide",children:"Status"}),e.jsx("p",{className:`mt-1 text-sm font-medium ${y>0?"text-cc-success":"text-cc-muted"}`,children:y>0?`${y} connected`:"Not connected"}),e.jsx("p",{className:"mt-0.5 text-[11px] text-cc-muted truncate",children:o.length>0?`${o.length} connection${o.length!==1?"s":""} configured`:"No connections yet"})]})]})]}),e.jsxs("div",{className:"bg-cc-card border border-cc-border rounded-xl p-4 sm:p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h2",{className:"text-sm font-semibold text-cc-fg flex items-center gap-2",children:[e.jsx(M,{className:"w-4 h-4 text-cc-fg"}),e.jsx("span",{children:"OAuth Connections"})]}),e.jsx("button",{type:"button",onClick:()=>{A(!g),x(""),h("")},className:"px-3 py-2 rounded-lg text-sm font-medium transition-colors bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer",children:g?"Cancel":"Add Connection"})]}),S&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:S}),F&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:F}),g&&e.jsxs("form",{onSubmit:G,className:"border border-cc-border rounded-lg p-4 space-y-3 bg-cc-bg",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1.5",htmlFor:"new-oauth-name",children:"Connection Name"}),e.jsx("input",{id:"new-oauth-name",type:"text",value:l,onChange:t=>k(t.target.value),placeholder:'e.g. "Production App", "Dev App"',className:"w-full px-3 py-2.5 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/60"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1.5",htmlFor:"new-oauth-client-id",children:"OAuth Client ID"}),e.jsx("input",{id:"new-oauth-client-id",type:"text",value:d,onChange:t=>I(t.target.value),placeholder:"OAuth app client ID from Linear",className:"w-full px-3 py-2.5 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/60"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1.5",htmlFor:"new-oauth-client-secret",children:"OAuth Client Secret"}),e.jsx("input",{id:"new-oauth-client-secret",type:"password",value:u,onChange:t=>L(t.target.value),placeholder:"OAuth app client secret",className:"w-full px-3 py-2.5 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/60"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1.5",htmlFor:"new-oauth-webhook-secret",children:"Webhook Secret"}),e.jsx("input",{id:"new-oauth-webhook-secret",type:"password",value:m,onChange:t=>O(t.target.value),placeholder:"Webhook signing secret from Linear",className:"w-full px-3 py-2.5 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/60"})]}),E&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:E}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"submit",disabled:b||!l.trim()||!d.trim()||!u.trim()||!m.trim(),className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors ${b||!l.trim()||!d.trim()||!u.trim()||!m.trim()?"bg-cc-hover text-cc-muted cursor-not-allowed":"bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer"}`,children:b?"Saving...":"Save"})})]}),P?e.jsx("p",{className:"text-sm text-cc-muted",children:"Loading connections..."}):o.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-sm text-cc-muted",children:"No OAuth connections yet."}),e.jsx("p",{className:"mt-1 text-xs text-cc-muted",children:"Add your first OAuth app connection to enable Linear agent integrations."})]}):e.jsx("div",{className:"space-y-3",children:o.map(t=>{const s=V(t.id);return e.jsx("div",{className:"border border-cc-border rounded-lg overflow-hidden",children:e.jsxs("div",{className:"p-4 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm font-medium text-cc-fg",children:t.name}),e.jsx("span",{className:`px-2 py-0.5 text-[10px] rounded-full border ${t.status==="connected"?"bg-cc-success/10 text-cc-success border-cc-success/20":"bg-cc-hover text-cc-muted border-cc-border"}`,children:t.status==="connected"?"Connected":"Disconnected"})]}),e.jsxs("p",{className:"mt-1 text-xs text-cc-muted truncate",children:["Client ID: ",Q(t.oauthClientId)]}),e.jsx("p",{className:"mt-1 text-xs text-cc-muted",children:t.status==="connected"?"Ready to receive @mentions and post updates back to Linear.":"This app may already be installed in Linear, but Companion no longer has a valid OAuth token. Reconnect it to restore agent replies."}),s.length>0&&e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:s.map(c=>e.jsxs("span",{className:"px-2 py-0.5 text-[10px] rounded-md bg-cc-hover text-cc-muted",children:["Agent: ",c.name]},c.id))})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>K(t.id),disabled:j===t.id,"aria-label":t.status==="connected"?`Manage ${t.name}`:`Reconnect ${t.name}`,className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors ${j===t.id?"bg-cc-hover text-cc-muted cursor-not-allowed":"bg-violet-600 hover:bg-violet-700 text-white cursor-pointer"}`,children:j===t.id?"Redirecting...":t.status==="connected"?"Manage in Linear":"Reconnect to Workspace"}),e.jsx("button",{type:"button",onClick:()=>J(t.id),disabled:v===t.id,className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors ${v===t.id?"bg-cc-hover text-cc-muted cursor-not-allowed":f===t.id?"bg-cc-error hover:bg-cc-error/90 text-white cursor-pointer":"bg-cc-error/10 hover:bg-cc-error/20 text-cc-error cursor-pointer"}`,children:v===t.id?"Deleting...":f===t.id?"Confirm Delete":"Delete"})]})]})},t.id)})})]})]})})}export{te as LinearOAuthSettingsPage};
@@ -0,0 +1 @@
1
+ import{r as o,a as x,j as e,u as M,n as Q,b as X,L as _}from"./index-DkqeP-R9.js";function Z({embedded:I=!1}){const[m,O]=o.useState([]),[H,V]=o.useState(!0),[C,q]=o.useState(""),[v,L]=o.useState(!1),[g,$]=o.useState(""),[p,A]=o.useState(""),[N,E]=o.useState(!1),[W,u]=o.useState(""),[s,c]=o.useState(null),[j,D]=o.useState(null),[y,F]=o.useState(null),l=o.useCallback(async()=>{try{const t=await x.listLinearConnections();O(t.connections)}catch(t){q(t instanceof Error?t.message:String(t))}finally{V(!1)}},[]);o.useEffect(()=>{l()},[l]);async function B(t){t.preventDefault();const a=g.trim(),i=p.trim();if(!a||!i){u("Name and API key are required.");return}E(!0),u("");try{const r=await x.createLinearConnection({name:a,apiKey:i});r.error?u(r.error):($(""),A(""),L(!1),await l())}catch(r){u(r instanceof Error?r.message:String(r))}finally{E(!1)}}async function R(t){D(t);try{await x.verifyLinearConnection(t),await l()}catch{await l()}finally{D(null)}}async function U(t){F(t);try{await x.deleteLinearConnection(t),(s==null?void 0:s.connectionId)===t&&c(null),await l()}catch{await l()}finally{F(null)}}async function z(t){if((s==null?void 0:s.connectionId)===t.id){c(null);return}const a={connectionId:t.id,teams:[],loadingStates:!0,autoTransition:t.autoTransition,autoTransitionTeamId:"",autoTransitionStateId:t.autoTransitionStateId,autoTransitionStateName:t.autoTransitionStateName,autoTransitionWorkflowStates:[],archiveTransition:t.archiveTransition,archiveTransitionTeamId:"",archiveTransitionStateId:t.archiveTransitionStateId,archiveTransitionStateName:t.archiveTransitionStateName,archiveTransitionWorkflowStates:[],saving:!1,saved:!1,error:""};c(a);try{const r=(await x.getLinearStates(t.id)).teams,n=r[0];let b="",w=[],K=t.autoTransitionStateId;if(t.autoTransitionStateName&&r.length>0)for(const d of r){const h=d.states.find(k=>k.name===t.autoTransitionStateName);if(h){b=d.id,w=d.states,K=h.id;break}}!b&&n&&(b=n.id,w=n.states);let f="",S=[],P=t.archiveTransitionStateId;if(t.archiveTransitionStateName&&r.length>0)for(const d of r){const h=d.states.find(k=>k.name===t.archiveTransitionStateName);if(h){f=d.id,S=d.states,P=h.id;break}}!f&&n&&(f=n.id,S=n.states),c(d=>d&&d.connectionId===t.id?{...d,teams:r,loadingStates:!1,autoTransitionTeamId:b,autoTransitionStateId:K,autoTransitionWorkflowStates:w,archiveTransitionTeamId:f,archiveTransitionStateId:P,archiveTransitionWorkflowStates:S}:d)}catch{c(i=>i&&i.connectionId===t.id?{...i,loadingStates:!1}:i)}}async function G(){if(s){c(t=>t&&{...t,saving:!0,saved:!1,error:""});try{await x.updateLinearConnection(s.connectionId,{autoTransition:s.autoTransition,autoTransitionStateId:s.autoTransitionStateId,autoTransitionStateName:s.autoTransitionStateName,archiveTransition:s.archiveTransition,archiveTransitionStateId:s.archiveTransitionStateId,archiveTransitionStateName:s.archiveTransitionStateName}),c(t=>t&&{...t,saving:!1,saved:!0}),setTimeout(()=>c(t=>t&&{...t,saved:!1}),1800),await l()}catch(t){c(a=>a&&{...a,saving:!1,error:t instanceof Error?t.message:String(t)})}}}const T=m.filter(t=>t.connected).length,J=m.length>0;return e.jsx("div",{className:`${I?"h-full":"h-[100dvh]"} bg-cc-bg text-cc-fg font-sans-ui antialiased overflow-y-auto`,children:e.jsxs("div",{className:"max-w-5xl mx-auto px-4 sm:px-8 py-6 sm:py-10 pb-safe",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold text-cc-fg",children:"Linear Settings"}),e.jsx("p",{className:"mt-1 text-sm text-cc-muted",children:"Connect Linear for issue context injection and agent @mentions via the Agent SDK."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>{window.location.hash="#/integrations"},className:"px-3 py-2.5 min-h-[44px] rounded-lg text-sm text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Integrations"}),!I&&e.jsx("button",{onClick:()=>{const t=M.getState().currentSessionId;t?Q(t):X()},className:"px-3 py-2.5 min-h-[44px] rounded-lg text-sm text-cc-muted hover:text-cc-fg hover:bg-cc-hover transition-colors cursor-pointer",children:"Back"})]})]}),e.jsxs("section",{className:"relative overflow-hidden bg-cc-card border border-cc-border rounded-xl p-4 sm:p-6 mb-4",children:[e.jsx("div",{className:"absolute inset-0 pointer-events-none bg-[radial-gradient(circle_at_top_right,rgba(124,58,237,0.1),transparent_45%)]"}),e.jsxs("div",{className:"relative flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 px-2.5 py-1 rounded-full border border-cc-border bg-cc-hover/60 text-xs text-cc-muted",children:[e.jsx(_,{className:"w-3.5 h-3.5 text-cc-fg"}),e.jsx("span",{children:"Linear Integration"})]}),e.jsx("h2",{className:"mt-3 text-lg sm:text-xl font-semibold text-cc-fg",children:"Turn issues into concrete session context"}),e.jsx("p",{className:"mt-1.5 text-sm text-cc-muted max-w-2xl",children:"Search and attach the right Linear issue before the first prompt, so the companion starts with scope, state, and links."}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2 text-[11px]",children:[e.jsx("span",{className:"px-2 py-1 rounded-md bg-cc-hover text-cc-muted",children:"Issue lookup on Home"}),e.jsx("span",{className:"px-2 py-1 rounded-md bg-cc-hover text-cc-muted",children:"Context injection on start"}),e.jsx("span",{className:"px-2 py-1 rounded-md bg-cc-hover text-cc-muted",children:"No key exposure in API responses"})]})]}),e.jsxs("div",{className:"shrink-0 rounded-xl border border-cc-border bg-cc-bg px-3 py-2 text-right min-w-[170px]",children:[e.jsx("p",{className:"text-[11px] text-cc-muted uppercase tracking-wide",children:"Status"}),e.jsx("p",{className:`mt-1 text-sm font-medium ${T>0?"text-cc-success":"text-cc-muted"}`,children:T>0?`${T} connected`:"Not connected"}),e.jsx("p",{className:"mt-0.5 text-[11px] text-cc-muted truncate",children:J?`${m.length} connection${m.length!==1?"s":""} configured`:"No connections yet"})]})]})]}),e.jsxs("div",{className:"bg-cc-card border border-cc-border rounded-xl p-4 sm:p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h2",{className:"text-sm font-semibold text-cc-fg flex items-center gap-2",children:[e.jsx(_,{className:"w-4 h-4 text-cc-fg"}),e.jsx("span",{children:"Linear Connections"})]}),e.jsx("button",{type:"button",onClick:()=>{L(!v),u("")},className:"px-3 py-2 rounded-lg text-sm font-medium transition-colors bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer",children:v?"Cancel":"Add Connection"})]}),C&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:C}),v&&e.jsxs("form",{onSubmit:B,className:"border border-cc-border rounded-lg p-4 space-y-3 bg-cc-bg",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1.5",htmlFor:"new-conn-name",children:"Connection Name"}),e.jsx("input",{id:"new-conn-name",type:"text",value:g,onChange:t=>$(t.target.value),placeholder:'e.g. "Work", "Personal"',className:"w-full px-3 py-2.5 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/60"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1.5",htmlFor:"new-conn-key",children:"API Key"}),e.jsx("input",{id:"new-conn-key",type:"password",value:p,onChange:t=>A(t.target.value),placeholder:"lin_api_...",className:"w-full px-3 py-2.5 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg placeholder:text-cc-muted focus:outline-none focus:border-cc-primary/60"}),e.jsx("p",{className:"mt-1.5 text-xs text-cc-muted",children:"The key is verified automatically when saved."})]}),W&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:W}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"submit",disabled:N||!g.trim()||!p.trim(),className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors ${N||!g.trim()||!p.trim()?"bg-cc-hover text-cc-muted cursor-not-allowed":"bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer"}`,children:N?"Saving...":"Save"})})]}),H?e.jsx("p",{className:"text-sm text-cc-muted",children:"Loading connections..."}):m.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-sm text-cc-muted",children:"No Linear connections yet."}),e.jsx("p",{className:"mt-1 text-xs text-cc-muted",children:"Add your first connection to search and attach Linear issues to sessions."})]}):e.jsx("div",{className:"space-y-3",children:m.map(t=>e.jsxs("div",{className:"border border-cc-border rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"p-4 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm font-medium text-cc-fg",children:t.name}),e.jsx("span",{className:`px-2 py-0.5 text-[10px] rounded-full border ${t.connected?"bg-cc-success/10 text-cc-success border-cc-success/20":"bg-cc-error/10 text-cc-error border-cc-error/20"}`,children:t.connected?"Connected":"Not connected"})]}),e.jsxs("p",{className:"mt-1 text-xs text-cc-muted truncate",children:[t.workspaceName&&t.viewerName?`${t.viewerName} -- ${t.workspaceName}`:t.workspaceName||t.viewerName||"Unverified"," ","· Key ending in ...",t.apiKeyLast4]}),(t.autoTransition||t.archiveTransition)&&e.jsxs("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:[t.autoTransition&&t.autoTransitionStateName&&e.jsxs("span",{className:"px-2 py-0.5 text-[10px] rounded-md bg-cc-hover text-cc-muted",children:["Auto-transition: ",t.autoTransitionStateName]}),t.archiveTransition&&t.archiveTransitionStateName&&e.jsxs("span",{className:"px-2 py-0.5 text-[10px] rounded-md bg-cc-hover text-cc-muted",children:["On archive: ",t.archiveTransitionStateName]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>z(t),disabled:!t.connected,className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors ${t.connected?(s==null?void 0:s.connectionId)===t.id?"bg-cc-active text-cc-fg cursor-pointer":"bg-cc-hover hover:bg-cc-active text-cc-fg cursor-pointer":"bg-cc-hover text-cc-muted cursor-not-allowed"}`,children:(s==null?void 0:s.connectionId)===t.id?"Close":"Edit"}),e.jsx("button",{type:"button",onClick:()=>R(t.id),disabled:j===t.id,className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors ${j===t.id?"bg-cc-hover text-cc-muted cursor-not-allowed":"bg-cc-hover hover:bg-cc-active text-cc-fg cursor-pointer"}`,children:j===t.id?"Checking...":"Verify"}),e.jsx("button",{type:"button",onClick:()=>U(t.id),disabled:y===t.id,className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors ${y===t.id?"bg-cc-hover text-cc-muted cursor-not-allowed":"bg-cc-error/10 hover:bg-cc-error/20 text-cc-error cursor-pointer"}`,children:y===t.id?"Deleting...":"Delete"})]})]}),(s==null?void 0:s.connectionId)===t.id&&e.jsxs("div",{className:"border-t border-cc-border p-4 space-y-5 bg-cc-bg/50",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-cc-fg",children:"Auto-transition"}),e.jsx("p",{className:"text-xs text-cc-muted",children:"Automatically move the linked issue to a chosen status when starting a session."}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{type:"button",role:"switch","aria-checked":s.autoTransition,onClick:()=>c(a=>a&&{...a,autoTransition:!a.autoTransition}),className:`relative inline-flex h-5 w-9 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors ${s.autoTransition?"bg-cc-primary":"bg-cc-hover"}`,children:e.jsx("span",{className:`pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white shadow-sm transition-transform ${s.autoTransition?"translate-x-4":"translate-x-0"}`})}),e.jsx("span",{className:"text-sm text-cc-fg",children:s.autoTransition?"Enabled":"Disabled"})]}),s.autoTransition&&s.teams.length>1&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1.5",htmlFor:`auto-team-${t.id}`,children:"Team"}),e.jsx("select",{id:`auto-team-${t.id}`,value:s.autoTransitionTeamId,onChange:a=>{const i=a.target.value,r=s.teams.find(n=>n.id===i);c(n=>n&&{...n,autoTransitionTeamId:i,autoTransitionWorkflowStates:(r==null?void 0:r.states)||[],autoTransitionStateId:"",autoTransitionStateName:""})},className:"w-full px-3 py-2.5 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg focus:outline-none focus:border-cc-primary/60",children:s.teams.map(a=>e.jsxs("option",{value:a.id,children:[a.name," (",a.key,")"]},a.id))})]}),s.autoTransition&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1.5",htmlFor:`auto-state-${t.id}`,children:"Target status"}),s.loadingStates?e.jsx("p",{className:"text-xs text-cc-muted",children:"Loading workflow states..."}):s.autoTransitionWorkflowStates.length===0?e.jsx("p",{className:"text-xs text-cc-muted",children:"No workflow states found."}):e.jsxs("select",{id:`auto-state-${t.id}`,value:s.autoTransitionStateId,onChange:a=>{const i=s.autoTransitionWorkflowStates.find(r=>r.id===a.target.value);c(r=>r&&{...r,autoTransitionStateId:a.target.value,autoTransitionStateName:(i==null?void 0:i.name)||""})},className:"w-full px-3 py-2.5 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg focus:outline-none focus:border-cc-primary/60",children:[e.jsx("option",{value:"",children:"Select a status..."}),s.autoTransitionWorkflowStates.map(a=>e.jsx("option",{value:a.id,children:a.name},a.id))]})]})]}),e.jsx("div",{className:"border-t border-cc-border"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-cc-fg",children:"On session archive"}),e.jsx("p",{className:"text-xs text-cc-muted",children:"When archiving a session linked to a Linear issue that is not done, optionally move it to a chosen status."}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{type:"button",role:"switch","aria-checked":s.archiveTransition,onClick:()=>c(a=>a&&{...a,archiveTransition:!a.archiveTransition}),className:`relative inline-flex h-5 w-9 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors ${s.archiveTransition?"bg-cc-primary":"bg-cc-hover"}`,children:e.jsx("span",{className:`pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white shadow-sm transition-transform ${s.archiveTransition?"translate-x-4":"translate-x-0"}`})}),e.jsx("span",{className:"text-sm text-cc-fg",children:s.archiveTransition?"Enabled":"Disabled"})]}),s.archiveTransition&&s.teams.length>1&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1.5",htmlFor:`archive-team-${t.id}`,children:"Team"}),e.jsx("select",{id:`archive-team-${t.id}`,value:s.archiveTransitionTeamId,onChange:a=>{const i=a.target.value,r=s.teams.find(n=>n.id===i);c(n=>n&&{...n,archiveTransitionTeamId:i,archiveTransitionWorkflowStates:(r==null?void 0:r.states)||[],archiveTransitionStateId:"",archiveTransitionStateName:""})},className:"w-full px-3 py-2.5 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg focus:outline-none focus:border-cc-primary/60",children:s.teams.map(a=>e.jsxs("option",{value:a.id,children:[a.name," (",a.key,")"]},a.id))})]}),s.archiveTransition&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1.5",htmlFor:`archive-state-${t.id}`,children:"Target status"}),s.loadingStates?e.jsx("p",{className:"text-xs text-cc-muted",children:"Loading workflow states..."}):s.archiveTransitionWorkflowStates.length===0?e.jsx("p",{className:"text-xs text-cc-muted",children:"No workflow states found."}):e.jsxs("select",{id:`archive-state-${t.id}`,value:s.archiveTransitionStateId,onChange:a=>{const i=s.archiveTransitionWorkflowStates.find(r=>r.id===a.target.value);c(r=>r&&{...r,archiveTransitionStateId:a.target.value,archiveTransitionStateName:(i==null?void 0:i.name)||""})},className:"w-full px-3 py-2.5 text-sm bg-cc-input-bg border border-cc-border rounded-lg text-cc-fg focus:outline-none focus:border-cc-primary/60",children:[e.jsx("option",{value:"",children:"Select a status..."}),s.archiveTransitionWorkflowStates.map(a=>e.jsx("option",{value:a.id,children:a.name},a.id))]})]})]}),s.error&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-error/10 border border-cc-error/20 text-xs text-cc-error",children:s.error}),s.saved&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-cc-success/10 border border-cc-success/20 text-xs text-cc-success",children:"Connection settings saved."}),(()=>{const a=s.saving||s.autoTransition&&!s.autoTransitionStateId||s.archiveTransition&&!s.archiveTransitionStateId;return e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:G,disabled:a,className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors ${a?"bg-cc-hover text-cc-muted cursor-not-allowed":"bg-cc-primary hover:bg-cc-primary-hover text-white cursor-pointer"}`,children:s.saving?"Saving...":"Save Settings"})})})()]})]},t.id))})]}),e.jsxs("div",{className:"mt-4 px-3 py-3 rounded-xl bg-cc-card border border-cc-border text-sm text-cc-muted",children:["Looking for OAuth app settings for agent triggers?"," ",e.jsx("a",{href:"#/integrations/linear-oauth",className:"text-cc-primary underline cursor-pointer",children:"Linear OAuth Apps"})]}),e.jsxs("section",{className:"mt-4 grid grid-cols-1 md:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"bg-cc-card border border-cc-border rounded-xl p-4",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wide text-cc-muted",children:"1. Configure"}),e.jsx("p",{className:"mt-1 text-sm text-cc-fg",children:"Add a Linear API key and verify the connection."})]}),e.jsxs("div",{className:"bg-cc-card border border-cc-border rounded-xl p-4",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wide text-cc-muted",children:"2. Select"}),e.jsx("p",{className:"mt-1 text-sm text-cc-fg",children:"From Home, search an issue by key or title in one click."})]}),e.jsxs("div",{className:"bg-cc-card border border-cc-border rounded-xl p-4",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wide text-cc-muted",children:"3. Start"}),e.jsx("p",{className:"mt-1 text-sm text-cc-fg",children:"The issue details are injected as startup context."})]})]})]})})}export{Z as LinearSettingsPage};