upfynai-code 3.0.2 → 3.0.4

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 (42) hide show
  1. package/client/dist/api-docs.html +838 -838
  2. package/client/dist/assets/{AppContent-Bvg0CPCO.js → AppContent-CwrTP6TW.js} +43 -43
  3. package/client/dist/assets/BrowserPanel-0TLEl-IC.js +2 -0
  4. package/client/dist/assets/{CanvasFullScreen-BdiJ35aq.js → CanvasFullScreen-D1GWQsGL.js} +1 -1
  5. package/client/dist/assets/{CanvasWorkspace-Bk9R9_e0.js → CanvasWorkspace-D7ORj358.js} +1 -1
  6. package/client/dist/assets/DashboardPanel-BV7ybUDe.js +1 -0
  7. package/client/dist/assets/FileTree-5qfhBqdE.js +1 -0
  8. package/client/dist/assets/{GitPanel-RtyZUIWS.js → GitPanel-C_xFM-N2.js} +1 -1
  9. package/client/dist/assets/{LoginModal-BWep8a6g.js → LoginModal-CImJHRjX.js} +3 -3
  10. package/client/dist/assets/{MarkdownPreview-DHmk3qzu.js → MarkdownPreview-CESjI261.js} +1 -1
  11. package/client/dist/assets/{MermaidBlock-BuBc_G-F.js → MermaidBlock-BFM21cwe.js} +2 -2
  12. package/client/dist/assets/Onboarding-B3cteLu2.js +1 -0
  13. package/client/dist/assets/SetupForm-P6dsYgHO.js +1 -0
  14. package/client/dist/assets/WorkflowsPanel-CBoN80kc.js +1 -0
  15. package/client/dist/assets/index-46kkVu2i.css +1 -0
  16. package/client/dist/assets/{index-C5ptjuTl.js → index-HaY-3pK1.js} +20 -20
  17. package/client/dist/assets/{vendor-canvas-D39yWul6.js → vendor-canvas-DvHJ_Pn2.js} +1 -1
  18. package/client/dist/assets/{vendor-codemirror-CbtmxxaB.js → vendor-codemirror-D2ALgpaX.js} +1 -1
  19. package/client/dist/assets/{vendor-icons-BaD0x9SL.js → vendor-icons-GyYE35HP.js} +178 -138
  20. package/client/dist/assets/{vendor-mermaid-CH7SGc99.js → vendor-mermaid-DucWyDEe.js} +3 -3
  21. package/client/dist/assets/{vendor-syntax-DuHI9Ok6.js → vendor-syntax-LS_Nt30I.js} +1 -1
  22. package/client/dist/clear-cache.html +85 -85
  23. package/client/dist/index.html +17 -17
  24. package/client/dist/manifest.json +3 -3
  25. package/client/dist/mcp-docs.html +108 -108
  26. package/client/dist/offline.html +84 -84
  27. package/client/dist/sw.js +82 -82
  28. package/package.json +136 -136
  29. package/server/browser.js +131 -0
  30. package/server/database/db.js +108 -10
  31. package/server/index.js +27 -28
  32. package/server/middleware/auth.js +5 -2
  33. package/server/routes/browser.js +419 -0
  34. package/server/routes/projects.js +118 -19
  35. package/server/routes/vapi-chat.js +1 -1
  36. package/server/services/browser-ai.js +154 -0
  37. package/client/dist/assets/DashboardPanel-CblJfTGi.js +0 -1
  38. package/client/dist/assets/FileTree-BDUnBheV.js +0 -1
  39. package/client/dist/assets/Onboarding-Drnlt75a.js +0 -1
  40. package/client/dist/assets/SetupForm-CtCKitZG.js +0 -1
  41. package/client/dist/assets/WorkflowsPanel-B2mIXDvD.js +0 -1
  42. package/client/dist/assets/index-BFuqS0tY.css +0 -1
@@ -0,0 +1,154 @@
1
+ /**
2
+ * Browser AI Service — Stagehand integration for AI-driven browser automation.
3
+ * Lazy-loads @browserbasehq/stagehand (cloud-only dep, installed via nixpacks).
4
+ * Follows the composio.js pattern: lazy SDK, per-session instances, availability check.
5
+ */
6
+
7
+ let Stagehand = null;
8
+ let sdkReady = null;
9
+
10
+ // Lazy-load Stagehand SDK (cloud-only dependency)
11
+ sdkReady = (async () => {
12
+ try {
13
+ const mod = await import('@browserbasehq/stagehand');
14
+ Stagehand = mod.Stagehand || mod.default;
15
+ } catch {
16
+ // SDK not installed — browser AI features unavailable (local installs)
17
+ }
18
+ })();
19
+
20
+ // Per-session Stagehand instance cache
21
+ const instances = new Map();
22
+
23
+ /**
24
+ * Check if the Stagehand SDK is available.
25
+ */
26
+ async function isAvailable() {
27
+ await sdkReady;
28
+ return !!Stagehand;
29
+ }
30
+
31
+ /**
32
+ * Get or create a Stagehand instance for a session.
33
+ */
34
+ async function getOrCreate(sessionId, cdpUrl) {
35
+ if (instances.has(sessionId)) return instances.get(sessionId);
36
+
37
+ await sdkReady;
38
+ if (!Stagehand) throw new Error('Browser AI not available — Stagehand SDK not installed');
39
+
40
+ const stagehand = new Stagehand({
41
+ env: 'LOCAL',
42
+ enableCaching: true,
43
+ localBrowserLaunchOptions: {
44
+ cdpUrl,
45
+ },
46
+ });
47
+ await stagehand.init();
48
+
49
+ instances.set(sessionId, stagehand);
50
+ return stagehand;
51
+ }
52
+
53
+ /**
54
+ * Execute a single AI action on the page.
55
+ * Chat mode: user says "click the login button" → this executes it.
56
+ */
57
+ async function act(sessionId, cdpUrl, instruction) {
58
+ const stagehand = await getOrCreate(sessionId, cdpUrl);
59
+ const page = stagehand.page;
60
+ const result = await page.act({ action: instruction });
61
+ return { success: true, result, url: page.url() };
62
+ }
63
+
64
+ /**
65
+ * Extract structured data from the current page.
66
+ */
67
+ async function extract(sessionId, cdpUrl, instruction, schema) {
68
+ const stagehand = await getOrCreate(sessionId, cdpUrl);
69
+ const page = stagehand.page;
70
+ const opts = { instruction };
71
+ if (schema) opts.schema = schema;
72
+ const result = await page.extract(opts);
73
+ return { success: true, data: result };
74
+ }
75
+
76
+ /**
77
+ * Observe the current page — returns available actions/elements.
78
+ */
79
+ async function observe(sessionId, cdpUrl, instruction) {
80
+ const stagehand = await getOrCreate(sessionId, cdpUrl);
81
+ const page = stagehand.page;
82
+ const opts = instruction ? { instruction } : {};
83
+ const result = await page.observe(opts);
84
+ return { success: true, observations: result };
85
+ }
86
+
87
+ /**
88
+ * Run an autonomous agent that pursues a goal across multiple steps.
89
+ * Streams each step to the onStep callback (for SSE).
90
+ */
91
+ async function autonomousGoal(sessionId, cdpUrl, goal, maxSteps = 10, onStep) {
92
+ const stagehand = await getOrCreate(sessionId, cdpUrl);
93
+ const page = stagehand.page;
94
+
95
+ for (let step = 0; step < maxSteps; step++) {
96
+ try {
97
+ // Observe current state
98
+ const observations = await page.observe();
99
+ onStep({ step, type: 'observe', data: observations, url: page.url(), timestamp: Date.now() });
100
+
101
+ // Execute next action toward goal
102
+ const actionResult = await page.act({ action: `Working towards this goal: ${goal}` });
103
+ onStep({ step, type: 'act', data: actionResult, url: page.url(), timestamp: Date.now() });
104
+
105
+ // Check if done
106
+ const check = await page.extract({
107
+ instruction: `Has this goal been achieved: "${goal}"? Answer with done=true or done=false and a brief reason.`,
108
+ });
109
+ onStep({ step, type: 'check', data: check, timestamp: Date.now() });
110
+
111
+ if (check && check.done) break;
112
+ } catch (err) {
113
+ onStep({ step, type: 'error', message: err.message, timestamp: Date.now() });
114
+ break;
115
+ }
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Get console errors from the browser via CDP.
121
+ */
122
+ async function getConsoleErrors(sessionId, cdpUrl) {
123
+ const stagehand = await getOrCreate(sessionId, cdpUrl);
124
+ const page = stagehand.page;
125
+
126
+ // Collect console errors using page.evaluate
127
+ const errors = await page.evaluate(() => {
128
+ // Check for any errors the page might have stored
129
+ return (window.__upfynErrors || []).slice(-50);
130
+ }).catch(() => []);
131
+
132
+ return errors;
133
+ }
134
+
135
+ /**
136
+ * Release a Stagehand instance for a session.
137
+ */
138
+ async function release(sessionId) {
139
+ const instance = instances.get(sessionId);
140
+ if (instance) {
141
+ try { await instance.close(); } catch { /* ignore */ }
142
+ instances.delete(sessionId);
143
+ }
144
+ }
145
+
146
+ export {
147
+ isAvailable,
148
+ act,
149
+ extract,
150
+ observe,
151
+ autonomousGoal,
152
+ getConsoleErrors,
153
+ release,
154
+ };
@@ -1 +0,0 @@
1
- import{r as o,j as e}from"./vendor-react-96lCPsRK.js";import{d as C,I as j}from"./index-C5ptjuTl.js";import{u as M,a as T}from"./AppContent-Bvg0CPCO.js";import{ab as $,R as A,M as L,Z as I,b9 as R,h as _,bi as D,t as U,at as E,aB as V,v as B,bj as F}from"./vendor-icons-BaD0x9SL.js";import"./vendor-syntax-DuHI9Ok6.js";import"./vendor-markdown-CimbIo6Y.js";import"./vendor-i18n-DCFGyhQR.js";import"./LoginModal-BWep8a6g.js";import"./vendor-xterm-CZq1hqo1.js";import"./vendor-canvas-D39yWul6.js";import"./vendor-mermaid-CH7SGc99.js";import"./vendor-codemirror-CbtmxxaB.js";function O({onRefresh:t,threshold:r=80,maxPull:i=120,enabled:s=!0}){const d=o.useRef(0),[n,c]=o.useState(0),[m,f]=o.useState(!1),u=o.useRef(!1),w=o.useCallback(l=>{!s||m||(d.current=l.touches[0].clientY,u.current=!1)},[s,m]),h=o.useCallback(l=>{if(!s||m||l.currentTarget.scrollTop>0)return;const b=l.touches[0].clientY-d.current;b>0&&(u.current=!0,c(Math.min(b*.5,i)))},[s,m,i]),x=o.useCallback(async()=>{if(u.current){if(n>=r){f(!0);try{await t()}finally{f(!1)}}c(0),u.current=!1}},[n,r,t]);return{pullDistance:n,isRefreshing:m,handlers:{onTouchStart:w,onTouchMove:h,onTouchEnd:x}}}function S({className:t}){return e.jsx("div",{className:`animate-pulse rounded-md bg-muted/60 ${t||""}`})}function ee({selectedProject:t}){var k;const[r,i]=o.useState(null),[s,d]=o.useState(null),[n,c]=o.useState(!0),[m,f]=o.useState(null),{canPrompt:u,promptInstall:w}=M(),{isMobile:h}=T({trackPWA:!1}),x=o.useCallback(async()=>{c(!0),f(null);try{const a=await C("/api/dashboard/stats");if(a.ok){const g=await a.json();i(g)}}catch{}if(j)try{const a=await C("/api/vapi/usage");if(a.ok){const g=await a.json();d(g)}}catch{}c(!1)},[]),{pullDistance:l,isRefreshing:y,handlers:b}=O({onRefresh:x,enabled:h});return o.useEffect(()=>{x()},[x]),e.jsxs("div",{className:"h-full overflow-y-auto p-4 sm:p-6 space-y-6","data-pull-refresh":!0,...h?b:{},style:l>0?{transform:`translateY(${l*.3}px)`}:void 0,children:[h&&(l>0||y)&&e.jsx("div",{className:"flex items-center justify-center py-2 -mt-2",children:y?e.jsx("div",{className:"w-5 h-5 border-2 border-primary/30 border-t-primary rounded-full animate-spin"}):e.jsx("svg",{className:"w-5 h-5 text-muted-foreground transition-transform",style:{transform:`rotate(${Math.min(l/80*180,180)}deg)`},fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 14l-7 7m0 0l-7-7m7 7V3"})})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-lg font-semibold text-foreground flex items-center gap-2",children:[e.jsx($,{className:"w-5 h-5 text-blue-500"}),"Dashboard"]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:t?`Project: ${t.displayName||t.name}`:"Overview"})]}),e.jsx("button",{onClick:x,disabled:n,className:"p-2 rounded-lg hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors",title:"Refresh stats",children:e.jsx(A,{className:`w-4 h-4 ${n?"animate-spin":""}`})})]}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3",children:[e.jsx(N,{icon:L,label:"Sessions",value:(r==null?void 0:r.total)??0,subtext:r!=null&&r.today?`${r.today} today`:void 0,color:"blue",loading:n}),e.jsx(N,{icon:I,label:"AI Providers",value:r!=null&&r.providers?Object.keys(r.providers).length:0,subtext:r!=null&&r.providers?Object.keys(r.providers).join(", "):void 0,color:"purple",loading:n}),j&&e.jsxs(e.Fragment,{children:[e.jsx(N,{icon:R,label:"Voice Calls",value:((k=s==null?void 0:s.allTime)==null?void 0:k.calls)??0,subtext:s!=null&&s.today?`${s.today.calls} today`:void 0,color:"amber",loading:n}),e.jsx(N,{icon:_,label:"Call Limit",value:(s==null?void 0:s.remaining)!=null?`${s.remaining} left`:0,subtext:s!=null&&s.limit?`of ${s.limit}/day`:void 0,color:"emerald",loading:n})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground mb-3 uppercase tracking-wider",children:"Quick Actions"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-2",children:[e.jsx(v,{label:"Install CLI",description:"npm install -g upfynai-code",onClick:()=>navigator.clipboard.writeText("npm install -g upfynai-code")}),e.jsx(v,{label:"Connect Machine",description:"uc connect",onClick:()=>navigator.clipboard.writeText("uc connect")}),j&&e.jsx(v,{label:"View Pricing",description:"Upgrade your plan",href:"https://cli.upfyn.com/pricing"}),u&&e.jsx(v,{label:"Install App",description:"Add Upfyn to your home screen",onClick:w})]})]}),j&&(s==null?void 0:s.recentCalls)&&s.recentCalls.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground mb-3 uppercase tracking-wider",children:"Recent Voice Calls"}),e.jsx("div",{className:"space-y-2",children:s.recentCalls.slice(0,5).map((a,g)=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-muted/30 border border-border/50",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(R,{className:"w-4 h-4 text-amber-500 flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm text-foreground truncate",children:a.summary||`Voice call — ${Math.round(a.duration_seconds||0)}s`}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a.created_at?new Date(a.created_at).toLocaleString():"Unknown time"})]})]}),e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${a.status==="completed"?"bg-emerald-500/10 text-emerald-400":a.status==="ended"?"bg-blue-500/10 text-blue-400":"bg-muted text-muted-foreground"}`,children:a.status||"unknown"})]},a.vapi_call_id||g))})]}),t&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground mb-3 uppercase tracking-wider",children:"Project Info"}),e.jsxs("div",{className:"rounded-lg bg-muted/30 border border-border/50 p-4 space-y-2",children:[e.jsx(p,{label:"Name",value:t.displayName||t.name}),e.jsx(p,{label:"Path",value:t.fullPath||t.path||"—"}),t.sessions&&e.jsx(p,{label:"Claude Sessions",value:String(t.sessions.length)}),t.cursorSessions&&e.jsx(p,{label:"Cursor Sessions",value:String(t.cursorSessions.length)}),t.codexSessions&&e.jsx(p,{label:"Codex Sessions",value:String(t.codexSessions.length)})]})]}),!t&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium text-muted-foreground mb-3 uppercase tracking-wider flex items-center gap-2",children:[e.jsx(D,{className:"w-3.5 h-3.5"}),"Getting Started"]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"rounded-lg border border-border/50 bg-card/50 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(U,{className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:"1. Install the CLI"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mb-2",children:["Install globally, then run ",e.jsx("code",{className:"bg-muted px-1 rounded",children:"uc"})," to launch."]}),e.jsx("code",{className:"text-xs bg-muted/50 px-2 py-1 rounded block text-foreground/80",children:"npm install -g upfynai-code"})]}),e.jsxs("div",{className:"rounded-lg border border-border/50 bg-card/50 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(I,{className:"w-4 h-4 text-yellow-500"}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:"2. Connect Your Machine"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Bridge your local dev environment to this web UI."}),e.jsx("code",{className:"text-xs bg-muted/50 px-2 py-1 rounded block text-foreground/80",children:"uc connect --key your_relay_token"})]}),e.jsxs("div",{className:"rounded-lg border border-border/50 bg-card/50 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(E,{className:"w-4 h-4 text-indigo-500"}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:"3. Use the Canvas"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Switch to the Canvas tab to create visual workspaces with code blocks, diagrams, and notes."})]}),e.jsxs("div",{className:"rounded-lg border border-border/50 bg-card/50 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(V,{className:"w-4 h-4 text-emerald-500"}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:"4. Chat with AI"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Use the Chat tab to talk to Claude, Cursor, or Codex. Bring your own API keys in Settings."})]})]})]})]})}function N({icon:t,label:r,value:i,subtext:s,color:d,loading:n}){const c={blue:"text-blue-500 bg-blue-500/10",purple:"text-purple-500 bg-purple-500/10",amber:"text-amber-500 bg-amber-500/10",emerald:"text-emerald-500 bg-emerald-500/10"};return e.jsxs("div",{className:"rounded-lg border border-border/50 bg-card/50 p-3 sm:p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:`w-7 h-7 rounded-md flex items-center justify-center ${c[d]}`,children:e.jsx(t,{className:"w-3.5 h-3.5"})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:r})]}),n?e.jsxs(e.Fragment,{children:[e.jsx(S,{className:"h-6 w-16 mb-1"}),e.jsx(S,{className:"h-3 w-20"})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-xl font-semibold text-foreground",children:i}),s&&e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:s})]})]})}function v({label:t,description:r,onClick:i,href:s}){const d=s?"a":"button",n=s?{href:s,target:"_blank",rel:"noopener noreferrer"}:{onClick:i};return e.jsxs(d,{...n,className:"flex items-center justify-between p-3 rounded-lg border border-border/50 bg-card/50 hover:bg-muted/60 transition-colors text-left group",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r})]}),s?e.jsx(B,{className:"w-3.5 h-3.5 text-muted-foreground group-hover:text-foreground"}):e.jsx(F,{className:"w-3.5 h-3.5 text-muted-foreground group-hover:text-foreground"})]})}function p({label:t,value:r}){return e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:t}),e.jsx("span",{className:"text-foreground font-mono text-xs truncate max-w-[60%] text-right",children:r})]})}export{ee as default};
@@ -1 +0,0 @@
1
- import{r as x,j as e,R as Ee}from"./vendor-react-96lCPsRK.js";import{B as V,I as Ie,S as Fe,c as h}from"./AppContent-Bvg0CPCO.js";import{d as Te,b as Le}from"./index-C5ptjuTl.js";import{X as ye,a6 as Me,E as ze,aw as Ae,e as xe,n as me,q as De,m as Re,ax as y,ay as U,$ as I,az as J,aA as Y,aB as ee,S as a,aC as $,aD as F,aE as oe,aF as T,t as j,aG as te,y as w,aH as G,aI as je,aJ as C,aK as S,aL as A,aM as D,aN as E,aO as Be,aP as b,aQ as pe,aR as Oe,aS as ue,aT as R,aU as B,A as ge,aV as Ve,aW as Ue,aX as O,aY as fe,aZ as $e,a_ as Ge,ae as Z}from"./vendor-icons-BaD0x9SL.js";import{u as qe}from"./LoginModal-BWep8a6g.js";import"./vendor-syntax-DuHI9Ok6.js";import"./vendor-markdown-CimbIo6Y.js";import"./vendor-codemirror-CbtmxxaB.js";import"./vendor-i18n-DCFGyhQR.js";import"./vendor-xterm-CZq1hqo1.js";import"./vendor-canvas-D39yWul6.js";import"./vendor-mermaid-CH7SGc99.js";function _e({file:i,onClose:u}){const d=`/api/projects/${i.projectName}/files/content?path=${encodeURIComponent(i.path)}`,[s,p]=x.useState(null),[L,q]=x.useState(null),[N,g]=x.useState(!0);return x.useEffect(()=>{let f;const M=new AbortController;return(async()=>{try{g(!0),q(null),p(null);const m=await Te(d,{signal:M.signal});if(!m.ok)throw new Error(`Request failed with status ${m.status}`);const _=await m.blob();f=URL.createObjectURL(_),p(f)}catch(m){if(m.name==="AbortError")return;console.error("Error loading image:",m),q("Unable to load image")}finally{g(!1)}})(),()=>{M.abort(),f&&URL.revokeObjectURL(f)}},[d]),e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-4xl max-h-[90vh] w-full mx-4 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:i.name}),e.jsx(V,{variant:"ghost",size:"sm",onClick:u,className:"h-8 w-8 p-0",children:e.jsx(ye,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"p-4 flex justify-center items-center bg-gray-50 dark:bg-gray-900 min-h-[400px]",children:[N&&e.jsx("div",{className:"text-center text-gray-500 dark:text-gray-400",children:e.jsx("p",{children:"Loading image…"})}),!N&&s&&e.jsx("img",{src:s,alt:i.name,className:"max-w-full max-h-[70vh] object-contain rounded-lg shadow-md"}),!N&&!s&&e.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[e.jsx("p",{children:L||"Unable to load image"}),e.jsx("p",{className:"text-sm mt-2 break-all",children:i.path})]})]}),e.jsx("div",{className:"p-4 border-t bg-gray-50 dark:bg-gray-800",children:e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:i.path})})]})})}const He="w-4 h-4 flex-shrink-0",he={js:{icon:R,color:"text-yellow-500"},jsx:{icon:R,color:"text-yellow-500"},mjs:{icon:R,color:"text-yellow-500"},cjs:{icon:R,color:"text-yellow-500"},ts:{icon:B,color:"text-blue-500"},tsx:{icon:B,color:"text-blue-500"},mts:{icon:B,color:"text-blue-500"},py:{icon:Z,color:"text-emerald-500"},pyw:{icon:Z,color:"text-emerald-500"},pyi:{icon:Z,color:"text-emerald-400"},ipynb:{icon:Ge,color:"text-orange-500"},rs:{icon:$,color:"text-orange-600"},toml:{icon:a,color:"text-gray-500"},go:{icon:U,color:"text-cyan-500"},rb:{icon:te,color:"text-red-500"},erb:{icon:te,color:"text-red-400"},php:{icon:$e,color:"text-violet-500"},java:{icon:fe,color:"text-red-600"},jar:{icon:fe,color:"text-red-500"},kt:{icon:U,color:"text-violet-500"},kts:{icon:U,color:"text-violet-400"},c:{icon:O,color:"text-blue-600"},h:{icon:O,color:"text-blue-400"},cpp:{icon:O,color:"text-blue-700"},hpp:{icon:O,color:"text-blue-500"},cc:{icon:O,color:"text-blue-700"},cs:{icon:U,color:"text-purple-600"},swift:{icon:oe,color:"text-orange-500"},lua:{icon:Ue,color:"text-blue-500"},r:{icon:Ve,color:"text-blue-600"},html:{icon:ge,color:"text-orange-600"},htm:{icon:ge,color:"text-orange-600"},css:{icon:F,color:"text-blue-500"},scss:{icon:F,color:"text-pink-500"},sass:{icon:F,color:"text-pink-400"},less:{icon:F,color:"text-indigo-500"},vue:{icon:B,color:"text-emerald-500"},svelte:{icon:B,color:"text-orange-500"},json:{icon:T,color:"text-yellow-600"},jsonc:{icon:T,color:"text-yellow-500"},json5:{icon:T,color:"text-yellow-500"},yaml:{icon:a,color:"text-purple-400"},yml:{icon:a,color:"text-purple-400"},xml:{icon:R,color:"text-orange-500"},csv:{icon:ue,color:"text-green-600"},tsv:{icon:ue,color:"text-green-500"},sql:{icon:Oe,color:"text-blue-500"},graphql:{icon:pe,color:"text-pink-500"},gql:{icon:pe,color:"text-pink-500"},proto:{icon:G,color:"text-green-500"},env:{icon:w,color:"text-yellow-600"},md:{icon:ee,color:"text-blue-500"},mdx:{icon:ee,color:"text-blue-400"},txt:{icon:I,color:"text-gray-500"},doc:{icon:I,color:"text-blue-600"},docx:{icon:I,color:"text-blue-600"},pdf:{icon:Y,color:"text-red-600"},rtf:{icon:I,color:"text-gray-500"},tex:{icon:J,color:"text-teal-600"},rst:{icon:I,color:"text-gray-400"},sh:{icon:j,color:"text-green-500"},bash:{icon:j,color:"text-green-500"},zsh:{icon:j,color:"text-green-400"},fish:{icon:j,color:"text-green-400"},ps1:{icon:j,color:"text-blue-400"},bat:{icon:j,color:"text-gray-500"},cmd:{icon:j,color:"text-gray-500"},png:{icon:b,color:"text-purple-500"},jpg:{icon:b,color:"text-purple-500"},jpeg:{icon:b,color:"text-purple-500"},gif:{icon:b,color:"text-purple-400"},webp:{icon:b,color:"text-purple-400"},ico:{icon:b,color:"text-purple-400"},bmp:{icon:b,color:"text-purple-400"},tiff:{icon:b,color:"text-purple-400"},svg:{icon:Be,color:"text-amber-500"},mp3:{icon:E,color:"text-pink-500"},wav:{icon:E,color:"text-pink-500"},ogg:{icon:E,color:"text-pink-400"},flac:{icon:E,color:"text-pink-400"},aac:{icon:E,color:"text-pink-400"},m4a:{icon:E,color:"text-pink-400"},mp4:{icon:D,color:"text-rose-500"},mov:{icon:D,color:"text-rose-500"},avi:{icon:D,color:"text-rose-500"},webm:{icon:D,color:"text-rose-400"},mkv:{icon:D,color:"text-rose-400"},ttf:{icon:A,color:"text-red-500"},otf:{icon:A,color:"text-red-500"},woff:{icon:A,color:"text-red-400"},woff2:{icon:A,color:"text-red-400"},eot:{icon:A,color:"text-red-400"},zip:{icon:S,color:"text-amber-600"},tar:{icon:S,color:"text-amber-600"},gz:{icon:S,color:"text-amber-600"},bz2:{icon:S,color:"text-amber-600"},rar:{icon:S,color:"text-amber-500"},"7z":{icon:S,color:"text-amber-500"},lock:{icon:y,color:"text-gray-500"},exe:{icon:C,color:"text-gray-500"},bin:{icon:C,color:"text-gray-500"},dll:{icon:C,color:"text-gray-400"},so:{icon:C,color:"text-gray-400"},dylib:{icon:C,color:"text-gray-400"},wasm:{icon:C,color:"text-purple-500"},ini:{icon:a,color:"text-gray-500"},cfg:{icon:a,color:"text-gray-500"},conf:{icon:a,color:"text-gray-500"},log:{icon:J,color:"text-gray-400"},map:{icon:je,color:"text-gray-400"}},be={Dockerfile:{icon:G,color:"text-blue-500"},"docker-compose.yml":{icon:G,color:"text-blue-500"},"docker-compose.yaml":{icon:G,color:"text-blue-500"},".dockerignore":{icon:G,color:"text-gray-500"},".gitignore":{icon:a,color:"text-gray-500"},".gitmodules":{icon:a,color:"text-gray-500"},".gitattributes":{icon:a,color:"text-gray-500"},".editorconfig":{icon:a,color:"text-gray-500"},".prettierrc":{icon:a,color:"text-pink-400"},".prettierignore":{icon:a,color:"text-gray-500"},".eslintrc":{icon:a,color:"text-violet-500"},".eslintrc.js":{icon:a,color:"text-violet-500"},".eslintrc.json":{icon:a,color:"text-violet-500"},".eslintrc.cjs":{icon:a,color:"text-violet-500"},"eslint.config.js":{icon:a,color:"text-violet-500"},"eslint.config.mjs":{icon:a,color:"text-violet-500"},".env":{icon:w,color:"text-yellow-600"},".env.local":{icon:w,color:"text-yellow-600"},".env.development":{icon:w,color:"text-yellow-500"},".env.production":{icon:w,color:"text-yellow-600"},".env.example":{icon:w,color:"text-yellow-400"},"package.json":{icon:T,color:"text-green-500"},"package-lock.json":{icon:y,color:"text-gray-500"},"yarn.lock":{icon:y,color:"text-blue-400"},"pnpm-lock.yaml":{icon:y,color:"text-orange-400"},"bun.lockb":{icon:y,color:"text-gray-400"},"Cargo.toml":{icon:$,color:"text-orange-600"},"Cargo.lock":{icon:y,color:"text-orange-400"},Gemfile:{icon:te,color:"text-red-500"},"Gemfile.lock":{icon:y,color:"text-red-400"},Makefile:{icon:j,color:"text-gray-500"},"CMakeLists.txt":{icon:$,color:"text-blue-500"},"tsconfig.json":{icon:T,color:"text-blue-500"},"jsconfig.json":{icon:T,color:"text-yellow-500"},"vite.config.ts":{icon:oe,color:"text-purple-500"},"vite.config.js":{icon:oe,color:"text-purple-500"},"webpack.config.js":{icon:$,color:"text-blue-500"},"tailwind.config.js":{icon:F,color:"text-cyan-500"},"tailwind.config.ts":{icon:F,color:"text-cyan-500"},"postcss.config.js":{icon:$,color:"text-red-400"},"babel.config.js":{icon:a,color:"text-yellow-500"},".babelrc":{icon:a,color:"text-yellow-500"},"README.md":{icon:ee,color:"text-blue-500"},LICENSE:{icon:Y,color:"text-gray-500"},"LICENSE.md":{icon:Y,color:"text-gray-500"},"CHANGELOG.md":{icon:J,color:"text-blue-400"},"requirements.txt":{icon:I,color:"text-emerald-400"},"go.mod":{icon:U,color:"text-cyan-500"},"go.sum":{icon:y,color:"text-cyan-400"}};function We(i){var d;if(be[i])return be[i];if(i.startsWith(".env"))return{icon:w,color:"text-yellow-600"};const u=(d=i.split(".").pop())==null?void 0:d.toLowerCase();return u&&he[u]?he[u]:{icon:je,color:"text-muted-foreground"}}function no({selectedProject:i,onFileOpen:u,activeFilePath:d=null}){const{t:s}=qe(),[p,L]=x.useState([]),[q,N]=x.useState(!1),[g,f]=x.useState(new Set),[M,W]=x.useState(null),[m,_]=x.useState("detailed"),[v,re]=x.useState(""),[z,ce]=x.useState([]),H=Ee.useRef(null);x.useEffect(()=>{i&&we()},[i]),x.useEffect(()=>{const t=localStorage.getItem("file-tree-view-mode");t&&["simple","detailed","compact"].includes(t)&&_(t)},[]),x.useEffect(()=>{if(!d||p.length===0)return;const t=d.replace(/\\/g,"/"),c=(r,l,n=[])=>{for(const k of r){const ie=(k.path||"").replace(/\\/g,"/");if(k.type==="directory"&&k.children){const Se=[...n,k.path];if(t.startsWith(ie+"/")){const de=c(k.children,l,Se);if(de)return de}}if(k.type!=="directory"&&ie===t)return n}return null},o=c(p,t);o&&o.length>0&&f(r=>{const l=new Set(r);return o.forEach(n=>l.add(n)),l}),requestAnimationFrame(()=>{var r;(r=H.current)==null||r.scrollIntoView({block:"nearest",behavior:"smooth"})})},[d,p]),x.useEffect(()=>{if(!v.trim())ce(p);else{const t=ne(p,v.toLowerCase());ce(t);const c=o=>{o.forEach(r=>{r.type==="directory"&&r.children&&r.children.length>0&&(f(l=>new Set(l.add(r.path))),c(r.children))})};c(t)}},[p,v]);const ne=(t,c)=>t.reduce((o,r)=>{const l=r.name.toLowerCase().includes(c);let n=[];return r.type==="directory"&&r.children&&(n=ne(r.children,c)),(l||n.length>0)&&o.push({...r,children:n}),o},[]),we=async()=>{N(!0);try{const t=await Le.getFiles(i.name);if(!t.ok){const o=await t.text();console.error("❌ File fetch failed:",t.status,o),L([]);return}const c=await t.json();L(c)}catch(t){console.error("❌ Error fetching files:",t),L([])}finally{N(!1)}},Ne=t=>{const c=new Set(g);c.has(t)?c.delete(t):c.add(t),f(c)},P=t=>{_(t),localStorage.setItem("file-tree-view-mode",t)},Q=t=>{if(!t||t===0)return"0 B";const c=1024,o=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(c));return parseFloat((t/Math.pow(c,r)).toFixed(1))+" "+o[r]},ve=t=>{if(!t)return"-";const c=new Date,o=new Date(t),r=Math.floor((c-o)/1e3);return r<60?s("fileTree.justNow"):r<3600?s("fileTree.minAgo",{count:Math.floor(r/60)}):r<86400?s("fileTree.hoursAgo",{count:Math.floor(r/3600)}):r<2592e3?s("fileTree.daysAgo",{count:Math.floor(r/86400)}):o.toLocaleDateString()},ke=t=>{var r;const c=(r=t.split(".").pop())==null?void 0:r.toLowerCase();return["png","jpg","jpeg","gif","svg","webp","ico","bmp"].includes(c)},Ce=t=>{const{icon:c,color:o}=We(t);return e.jsx(c,{className:h(He,o)})},X=t=>{t.type==="directory"?Ne(t.path):ke(t.name)?W({name:t.name,path:t.path,projectPath:i.path,projectName:i.name}):u&&u(t.path)},K=t=>{const c=t.type==="directory",o=g.has(t.path);return c?e.jsxs("span",{className:"flex items-center gap-0.5 flex-shrink-0",children:[e.jsx(De,{className:h("w-3.5 h-3.5 text-muted-foreground/70 transition-transform duration-150",o&&"rotate-90")}),o?e.jsx(Re,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}):e.jsx(me,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"})]}):e.jsx("span",{className:"flex items-center flex-shrink-0 ml-[18px]",children:Ce(t.name)})},se=(t,c=0)=>t.map(o=>{const r=o.type==="directory",l=r&&g.has(o.path),n=!r&&d&&(o.path||"").replace(/\\/g,"/")===d.replace(/\\/g,"/");return e.jsxs("div",{className:"select-none",children:[e.jsxs("div",{ref:n?H:void 0,className:h("group flex items-center gap-1.5 py-[3px] pr-2 cursor-pointer rounded-sm","hover:bg-accent/60 transition-colors duration-100",n&&"bg-primary/10 border-l-2 !border-primary font-medium",!n&&r&&l&&"border-l-2 border-primary/30",!n&&r&&!l&&"border-l-2 border-transparent",!n&&!r&&"border-l-2 border-transparent"),style:{paddingLeft:`${c*16+4}px`},onClick:()=>X(o),children:[K(o),e.jsx("span",{className:h("text-[13px] leading-tight truncate",n?"font-medium text-primary":r?"font-medium text-foreground":"text-foreground/90"),children:o.name})]}),r&&l&&o.children&&o.children.length>0&&e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute top-0 bottom-0 border-l border-border/40",style:{left:`${c*16+14}px`},"aria-hidden":"true"}),se(o.children,c+1)]})]},o.path)}),le=(t,c=0)=>t.map(o=>{const r=o.type==="directory",l=r&&g.has(o.path),n=!r&&d&&(o.path||"").replace(/\\/g,"/")===d.replace(/\\/g,"/");return e.jsxs("div",{className:"select-none",children:[e.jsxs("div",{ref:n?H:void 0,className:h("group grid grid-cols-1 sm:grid-cols-12 gap-0 sm:gap-2 py-[3px] pr-2 hover:bg-accent/60 cursor-pointer items-center rounded-sm transition-colors duration-100",n&&"bg-primary/10 border-l-2 !border-primary font-medium",!n&&r&&l&&"border-l-2 border-primary/30",!n&&r&&!l&&"border-l-2 border-transparent",!n&&!r&&"border-l-2 border-transparent"),style:{paddingLeft:`${c*16+4}px`},onClick:()=>X(o),children:[e.jsxs("div",{className:"sm:col-span-5 flex items-center gap-1.5 min-w-0",children:[K(o),e.jsx("span",{className:h("text-[13px] leading-tight truncate",n?"font-medium text-primary":r?"font-medium text-foreground":"text-foreground/90"),children:o.name}),o.type==="file"&&o.size!=null&&e.jsx("span",{className:"sm:hidden text-[10px] text-muted-foreground/60 ml-auto flex-shrink-0",children:Q(o.size)})]}),e.jsx("div",{className:"hidden sm:block sm:col-span-2 text-sm text-muted-foreground tabular-nums",children:o.type==="file"?Q(o.size):""}),e.jsx("div",{className:"hidden sm:block sm:col-span-3 text-sm text-muted-foreground",children:ve(o.modified)}),e.jsx("div",{className:"hidden sm:block sm:col-span-2 text-sm text-muted-foreground font-mono",children:o.permissionsRwx||""})]}),r&&l&&o.children&&e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute top-0 bottom-0 border-l border-border/40",style:{left:`${c*16+14}px`},"aria-hidden":"true"}),le(o.children,c+1)]})]},o.path)}),ae=(t,c=0)=>t.map(o=>{const r=o.type==="directory",l=r&&g.has(o.path),n=!r&&d&&(o.path||"").replace(/\\/g,"/")===d.replace(/\\/g,"/");return e.jsxs("div",{className:"select-none",children:[e.jsxs("div",{ref:n?H:void 0,className:h("group flex items-center justify-between py-[3px] pr-2 hover:bg-accent/60 cursor-pointer rounded-sm transition-colors duration-100",n&&"bg-primary/10 border-l-2 !border-primary font-medium",!n&&r&&l&&"border-l-2 border-primary/30",!n&&r&&!l&&"border-l-2 border-transparent",!n&&!r&&"border-l-2 border-transparent"),style:{paddingLeft:`${c*16+4}px`},onClick:()=>X(o),children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[K(o),e.jsx("span",{className:h("text-[13px] leading-tight truncate",n?"font-medium text-primary":r?"font-medium text-foreground":"text-foreground/90"),children:o.name})]}),e.jsx("div",{className:"flex items-center gap-3 text-sm text-muted-foreground flex-shrink-0 ml-2",children:o.type==="file"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tabular-nums",children:Q(o.size)}),e.jsx("span",{className:"font-mono",children:o.permissionsRwx})]})})]}),r&&l&&o.children&&e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute top-0 bottom-0 border-l border-border/40",style:{left:`${c*16+14}px`},"aria-hidden":"true"}),ae(o.children,c+1)]})]},o.path)});return q?e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsx("div",{className:"text-muted-foreground text-sm",children:s("fileTree.loading")})}):e.jsxs("div",{className:"h-full flex flex-col bg-background",children:[e.jsxs("div",{className:"px-3 pt-3 pb-2 border-b border-border space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-medium text-foreground",children:s("fileTree.files")}),e.jsxs("div",{className:"flex gap-0.5",children:[e.jsx(V,{variant:m==="simple"?"default":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>P("simple"),title:s("fileTree.simpleView"),children:e.jsx(Me,{className:"w-3.5 h-3.5"})}),e.jsx(V,{variant:m==="compact"?"default":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>P("compact"),title:s("fileTree.compactView"),children:e.jsx(ze,{className:"w-3.5 h-3.5"})}),e.jsx(V,{variant:m==="detailed"?"default":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>P("detailed"),title:s("fileTree.detailedView"),children:e.jsx(Ae,{className:"w-3.5 h-3.5"})})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(xe,{className:"absolute left-2 top-1/2 transform -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground"}),e.jsx(Ie,{type:"text",placeholder:s("fileTree.searchPlaceholder"),value:v,onChange:t=>re(t.target.value),className:"pl-8 pr-8 h-8 text-sm"}),v&&e.jsx(V,{variant:"ghost",size:"sm",className:"absolute right-0.5 top-1/2 transform -translate-y-1/2 h-5 w-5 p-0 hover:bg-accent",onClick:()=>re(""),title:s("fileTree.clearSearch"),children:e.jsx(ye,{className:"w-3 h-3"})})]})]}),m==="detailed"&&z.length>0&&e.jsx("div",{className:"px-3 pt-1.5 pb-1 border-b border-border",children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-12 gap-2 px-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground/70",children:[e.jsx("div",{className:"sm:col-span-5",children:s("fileTree.name")}),e.jsx("div",{className:"hidden sm:block sm:col-span-2",children:s("fileTree.size")}),e.jsx("div",{className:"hidden sm:block sm:col-span-3",children:s("fileTree.modified")}),e.jsx("div",{className:"hidden sm:block sm:col-span-2",children:s("fileTree.permissions")})]})}),e.jsx(Fe,{className:"flex-1 px-2 py-1",children:p.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"w-12 h-12 bg-muted rounded-lg flex items-center justify-center mx-auto mb-3",children:e.jsx(me,{className:"w-6 h-6 text-muted-foreground"})}),e.jsx("h4",{className:"font-medium text-foreground mb-1",children:s("fileTree.noFilesFound")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("fileTree.checkProjectPath")})]}):z.length===0&&v?e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"w-12 h-12 bg-muted rounded-lg flex items-center justify-center mx-auto mb-3",children:e.jsx(xe,{className:"w-6 h-6 text-muted-foreground"})}),e.jsx("h4",{className:"font-medium text-foreground mb-1",children:s("fileTree.noMatchesFound")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("fileTree.tryDifferentSearch")})]}):e.jsxs("div",{children:[m==="simple"&&se(z),m==="compact"&&ae(z),m==="detailed"&&le(z)]})}),M&&e.jsx(_e,{file:M,onClose:()=>W(null)})]})}export{no as default};
@@ -1 +0,0 @@
1
- import{r,j as e}from"./vendor-react-96lCPsRK.js";import{L as X,b as ee,C as te,a as se}from"./LoginModal-BWep8a6g.js";import{I as ae,h as re,d as c}from"./index-C5ptjuTl.js";import{b as ie,t as ne,at as oe,Z as le,G as de,au as ce,av as ue,j as me,r as xe,L as $,a4 as O,q as ge}from"./vendor-icons-BaD0x9SL.js";import"./vendor-xterm-CZq1hqo1.js";import"./vendor-canvas-D39yWul6.js";import"./vendor-mermaid-CH7SGc99.js";import"./vendor-syntax-DuHI9Ok6.js";import"./vendor-markdown-CimbIo6Y.js";import"./vendor-i18n-DCFGyhQR.js";const ke=({onComplete:y})=>{const[a,q]=r.useState(0),[m,N]=r.useState(""),[d,v]=r.useState(""),[o,x]=r.useState(!1),[w,l]=r.useState(""),[G,C]=r.useState(!1),[M,T]=r.useState("right"),[i,g]=r.useState(null),[B]=r.useState({name:"default",fullPath:ae?"/workspace":""}),[k,p]=r.useState({authenticated:!1,email:null,loading:!0,error:null}),[S,b]=r.useState({authenticated:!1,email:null,loading:!0,error:null}),[A,j]=r.useState({authenticated:!1,email:null,loading:!0,error:null}),{user:h}=re(),L=r.useRef(void 0);r.useEffect(()=>{D()},[]);const D=async()=>{try{const t=await c("/api/user/git-config");if(t.ok){const s=await t.json();s.gitName&&N(s.gitName),s.gitEmail&&v(s.gitEmail)}}catch{}};r.useEffect(()=>{const t=L.current;L.current=i,(t===void 0||t!==null&&i===null)&&(F(),E(),I())},[i]);const F=async()=>{try{const t=await c("/api/cli/claude/status");if(t.ok){const s=await t.json();p({authenticated:s.authenticated,email:s.email,loading:!1,error:s.error||null})}else p({authenticated:!1,email:null,loading:!1,error:"Failed to check status"})}catch(t){p({authenticated:!1,email:null,loading:!1,error:t.message})}},E=async()=>{try{const t=await c("/api/cli/cursor/status");if(t.ok){const s=await t.json();b({authenticated:s.authenticated,email:s.email,loading:!1,error:s.error||null})}else b({authenticated:!1,email:null,loading:!1,error:"Failed to check status"})}catch(t){b({authenticated:!1,email:null,loading:!1,error:t.message})}},I=async()=>{try{const t=await c("/api/cli/codex/status");if(t.ok){const s=await t.json();j({authenticated:s.authenticated,email:s.email,loading:!1,error:s.error||null})}else j({authenticated:!1,email:null,loading:!1,error:"Failed to check status"})}catch(t){j({authenticated:!1,email:null,loading:!1,error:t.message})}},U=()=>g("claude"),Y=()=>g("cursor"),_=()=>g("codex"),z=t=>{t===0&&(i==="claude"?F():i==="cursor"?E():i==="codex"&&I())},u=(t,s="right")=>{T(s),C(!0),setTimeout(()=>{q(t),C(!1)},200)},J=async()=>{if(l(""),a===0){u(1,"right");return}if(a===1){if(!m.trim()||!d.trim()){l("Both git name and email are required");return}if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(d)){l("Please enter a valid email address");return}x(!0);try{const s=await c("/api/user/git-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({gitName:m,gitEmail:d})});if(!s.ok){const n=await s.json();throw new Error(n.error||"Failed to save git configuration")}u(2,"right")}catch(s){l(s.message)}finally{x(!1)}return}u(a+1,"right")},V=()=>{l(""),u(a-1,"left")},W=async()=>{x(!0),l("");try{const t=await c("/api/user/complete-onboarding",{method:"POST"});if(!t.ok){const s=await t.json();throw new Error(s.error||"Failed to complete onboarding")}y&&y()}catch(t){l(t.message)}finally{x(!1)}},f=[{title:"Welcome",required:!1},{title:"Git Identity",required:!0},{title:"Agents",required:!1}],Z=()=>a===0?!0:a===1?m.trim()&&d.trim()&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(d):!0,P=[k,S,A].filter(t=>t.authenticated).length,Q=[{icon:ne,title:"AI Agents",desc:"Claude, Cursor & Codex — unified in one interface",gradient:"from-blue-500/10 to-blue-600/5",iconColor:"text-blue-500"},{icon:oe,title:"Canvas",desc:"Visual workspace with code blocks, diagrams & notes",gradient:"from-violet-500/10 to-violet-600/5",iconColor:"text-violet-500"},{icon:le,title:"Relay",desc:"Bridge your local machine to the web UI seamlessly",gradient:"from-amber-500/10 to-amber-600/5",iconColor:"text-amber-500"}],H=[{name:"Claude Code",status:k,onLogin:U,logo:e.jsx(ee,{size:22}),accent:"blue"},{name:"Cursor",status:S,onLogin:Y,logo:e.jsx(te,{size:22}),accent:"violet"},{name:"OpenAI Codex",status:A,onLogin:_,logo:e.jsx(se,{className:"w-5 h-5"}),accent:"neutral"}],K=G?`opacity-0 ${M==="right"?"translate-x-4":"-translate-x-4"}`:"opacity-100 translate-x-0";return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4 sm:p-8",children:e.jsxs("div",{className:"w-full max-w-xl",children:[e.jsxs("div",{className:"mb-10",children:[e.jsx("div",{className:"flex items-center justify-between mb-3 px-1",children:f.map((t,s)=>e.jsxs("button",{onClick:()=>{s<a&&u(s,"left")},disabled:s>a,className:`text-xs font-medium tracking-wide uppercase transition-colors duration-300 ${s===a?"text-foreground":s<a?"text-primary cursor-pointer hover:text-primary/80":"text-muted-foreground/50"}`,children:[t.title,t.required&&s===a&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]},s))}),e.jsx("div",{className:"h-1 bg-muted/60 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary rounded-full transition-all duration-500 ease-out",style:{width:`${a/(f.length-1)*100}%`}})})]}),e.jsxs("div",{className:"bg-card rounded-2xl border border-border/60 shadow-xl shadow-black/[0.04] dark:shadow-black/[0.2] overflow-hidden",children:[e.jsxs("div",{className:`p-8 sm:p-10 transition-all duration-200 ease-out ${K}`,children:[a===0&&e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"text-center",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 px-3 py-1 rounded-full bg-primary/10 text-primary text-xs font-medium mb-6",children:[e.jsx(ie,{className:"w-3.5 h-3.5"}),"Quick setup — under a minute"]}),e.jsxs("h1",{className:"text-3xl sm:text-4xl font-bold text-foreground tracking-tight leading-tight",children:["Welcome to Upfyn",h!=null&&h.first_name?e.jsxs("span",{className:"text-primary",children:[", ",h.first_name]}):null]}),e.jsx("p",{className:"text-muted-foreground mt-3 text-base max-w-md mx-auto leading-relaxed",children:"Your visual AI coding interface. Connect your favorite agents, manage projects, and build faster."})]}),e.jsx("div",{className:"grid gap-3",children:Q.map((t,s)=>e.jsxs("div",{className:`group flex items-start gap-4 p-4 rounded-xl bg-gradient-to-r ${t.gradient} border border-border/40 hover:border-border/80 transition-all duration-200`,children:[e.jsx("div",{className:`mt-0.5 p-2 rounded-lg bg-background/80 ${t.iconColor} flex-shrink-0`,children:e.jsx(t.icon,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-foreground text-sm",children:t.title}),e.jsx("p",{className:"text-muted-foreground text-sm mt-0.5",children:t.desc})]})]},s))})]}),a===1&&e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-primary/10 flex items-center justify-center mx-auto mb-5",children:e.jsx(de,{className:"w-7 h-7 text-primary"})}),e.jsx("h2",{className:"text-2xl sm:text-3xl font-bold text-foreground tracking-tight",children:"Git Identity"}),e.jsx("p",{className:"text-muted-foreground mt-2 text-sm max-w-sm mx-auto",children:"Set your name and email for commit attribution"})]}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"gitName",className:"flex items-center gap-2 text-sm font-medium text-foreground mb-2",children:[e.jsx(ce,{className:"w-3.5 h-3.5 text-muted-foreground"}),"Name"]}),e.jsx("input",{type:"text",id:"gitName",value:m,onChange:t=>N(t.target.value),className:"w-full px-4 py-3 border border-border/60 rounded-xl bg-background text-foreground placeholder:text-muted-foreground/50 focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary/40 transition-all duration-200",placeholder:"John Doe",required:!0,disabled:o})]}),e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"gitEmail",className:"flex items-center gap-2 text-sm font-medium text-foreground mb-2",children:[e.jsx(ue,{className:"w-3.5 h-3.5 text-muted-foreground"}),"Email"]}),e.jsx("input",{type:"email",id:"gitEmail",value:d,onChange:t=>v(t.target.value),className:"w-full px-4 py-3 border border-border/60 rounded-xl bg-background text-foreground placeholder:text-muted-foreground/50 focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary/40 transition-all duration-200",placeholder:"john@example.com",required:!0,disabled:o})]}),e.jsxs("p",{className:"text-xs text-muted-foreground/70 text-center",children:["Applied as ",e.jsx("code",{className:"px-1 py-0.5 rounded bg-muted/60 text-xs",children:"git config --global"})," on your machine"]})]})]}),a===2&&e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("h2",{className:"text-2xl sm:text-3xl font-bold text-foreground tracking-tight",children:"Connect Your Agents"}),e.jsxs("p",{className:"text-muted-foreground mt-2 text-sm max-w-sm mx-auto",children:["Optional — login to one or more AI assistants.",P>0&&e.jsxs("span",{className:"text-primary font-medium",children:[" ",P," connected"]})]})]}),e.jsx("div",{className:"space-y-3",children:H.map((t,s)=>{const n=t.status.authenticated,R=t.status.loading;return e.jsxs("div",{className:`group flex items-center justify-between p-4 rounded-xl border transition-all duration-200 ${n?"bg-primary/5 border-primary/20":"bg-card border-border/50 hover:border-border"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-xl flex items-center justify-center flex-shrink-0 ${n?"bg-primary/10":"bg-muted/60"}`,children:t.logo}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-medium text-sm text-foreground flex items-center gap-2",children:[t.name,n&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md bg-green-500/10 text-green-600 dark:text-green-400 text-[10px] font-semibold uppercase tracking-wider",children:[e.jsx(me,{className:"w-3 h-3"}),"Connected"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:R?"Checking...":n?t.status.email||"Ready to use":"Not connected"})]})]}),!n&&!R&&e.jsx("button",{onClick:t.onLogin,className:"px-4 py-2 text-sm font-medium rounded-lg bg-foreground text-background hover:opacity-90 transition-opacity flex-shrink-0",children:"Connect"})]},s)})}),e.jsx("p",{className:"text-xs text-muted-foreground/60 text-center",children:"You can always add or change these in Settings later."})]})]}),w&&e.jsx("div",{className:"mx-8 sm:mx-10 mb-2 p-3 rounded-xl bg-destructive/10 border border-destructive/20",children:e.jsx("p",{className:"text-sm text-destructive",children:w})}),e.jsxs("div",{className:"flex items-center justify-between px-8 sm:px-10 py-5 border-t border-border/40 bg-muted/20",children:[e.jsxs("button",{onClick:V,disabled:a===0||o,className:"flex items-center gap-1.5 text-sm font-medium text-muted-foreground hover:text-foreground disabled:opacity-0 disabled:pointer-events-none transition-all duration-200",children:[e.jsx(xe,{className:"w-4 h-4"}),"Back"]}),a<f.length-1?e.jsx("button",{onClick:J,disabled:!Z()||o,className:"flex items-center gap-2 px-6 py-2.5 bg-primary text-primary-foreground font-medium text-sm rounded-xl hover:opacity-90 disabled:opacity-50 disabled:cursor-not-allowed transition-all duration-200 shadow-sm",children:o?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"w-4 h-4 animate-spin"}),"Saving..."]}):a===0?e.jsxs(e.Fragment,{children:["Get Started",e.jsx(O,{className:"w-4 h-4"})]}):e.jsxs(e.Fragment,{children:["Continue",e.jsx(ge,{className:"w-4 h-4"})]})}):e.jsx("button",{onClick:W,disabled:o,className:"flex items-center gap-2 px-6 py-2.5 bg-primary text-primary-foreground font-medium text-sm rounded-xl hover:opacity-90 disabled:opacity-50 disabled:cursor-not-allowed transition-all duration-200 shadow-sm",children:o?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"w-4 h-4 animate-spin"}),"Finishing..."]}):e.jsxs(e.Fragment,{children:["Start Building",e.jsx(O,{className:"w-4 h-4"})]})})]})]}),e.jsxs("p",{className:"text-center text-xs text-muted-foreground/50 mt-6",children:["Step ",a+1," of ",f.length]})]})}),i&&e.jsx(X,{isOpen:!!i,onClose:()=>g(null),provider:i,project:B,onComplete:z,isOnboarding:!0})]})};export{ke as default};
@@ -1 +0,0 @@
1
- import{r as t,j as e}from"./vendor-react-96lCPsRK.js";import{h as y}from"./index-C5ptjuTl.js";import"./vendor-syntax-DuHI9Ok6.js";import"./vendor-markdown-CimbIo6Y.js";import"./vendor-icons-BaD0x9SL.js";import"./vendor-i18n-DCFGyhQR.js";const q=()=>{const[a,f]=t.useState(""),[d,p]=t.useState(""),[l,x]=t.useState(""),[n,g]=t.useState(""),[u,h]=t.useState(""),[s,i]=t.useState(!1),[c,o]=t.useState(""),{register:j}=y(),N=async r=>{if(r.preventDefault(),o(""),n!==u){o("Passwords do not match");return}if(!a.trim()||a.trim().length<2){o("Name must be at least 2 characters");return}if(!d.trim()||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(d)){o("Please enter a valid email address");return}if(n.length<6){o("Password must be at least 6 characters");return}i(!0);const m=a.trim().split(" "),w=m[0]||a.trim(),v=m.slice(1).join(" ")||"",b=await j(w,v,n,d.trim(),l.trim()||null);b.success||o(b.error),i(!1)};return e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4",children:e.jsx("div",{className:"w-full max-w-md",children:e.jsxs("div",{className:"bg-card rounded-lg shadow-lg border border-border p-8 space-y-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx("img",{src:"/logo.svg",alt:"Upfyn-Code",className:"w-16 h-16",onError:r=>{r.target.style.display="none"}})}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"Create Your Account"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"Sign up to start using Upfyn-Code"})]}),e.jsxs("form",{onSubmit:N,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"name",className:"block text-sm font-medium text-foreground mb-1",children:"Full Name"}),e.jsx("input",{type:"text",id:"name",value:a,onChange:r=>f(r.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"Your full name",required:!0,disabled:s})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email",className:"block text-sm font-medium text-foreground mb-1",children:"Email"}),e.jsx("input",{type:"email",id:"email",value:d,onChange:r=>p(r.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"you@example.com",required:!0,disabled:s})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"phone",className:"block text-sm font-medium text-foreground mb-1",children:"Mobile Number"}),e.jsx("input",{type:"tel",id:"phone",value:l,onChange:r=>x(r.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"+91 9876543210",disabled:s})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"password",className:"block text-sm font-medium text-foreground mb-1",children:"Password"}),e.jsx("input",{type:"password",id:"password",value:n,onChange:r=>g(r.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"At least 6 characters",required:!0,disabled:s})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"confirmPassword",className:"block text-sm font-medium text-foreground mb-1",children:"Confirm Password"}),e.jsx("input",{type:"password",id:"confirmPassword",value:u,onChange:r=>h(r.target.value),className:"w-full px-3 py-2 border border-border rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"Confirm your password",required:!0,disabled:s})]}),c&&e.jsx("div",{className:"p-3 bg-red-100 dark:bg-red-900/20 border border-red-300 dark:border-red-800 rounded-md",children:e.jsx("p",{className:"text-sm text-red-700 dark:text-red-400",children:c})}),e.jsx("button",{type:"submit",disabled:s,className:"w-full bg-blue-600 hover:bg-blue-700 disabled:bg-blue-400 text-white font-medium py-2 px-4 rounded-md transition-colors duration-200",children:s?"Creating account...":"Create Account"})]})]})})})};export{q as default};
@@ -1 +0,0 @@
1
- import{r as s,j as e,R as be}from"./vendor-react-96lCPsRK.js";import{d as U,b as $}from"./index-C5ptjuTl.js";import{L as D,b2 as Q,P as J,X as q,f as ne,b as re,b3 as fe,a4 as je,a9 as me,b0 as ue,k as ge,i as oe,g as ee,C as te,h as ae,b4 as V,v as le,j as ie,M as Ne,Z,G as ye,b5 as ve,a1 as we,O as ke,a7 as Ce,l as Se,b6 as Ee,R as Ae,b7 as Ie,b8 as Te,b9 as _e,ba as Le,bb as Re,bc as De,bd as Oe,be as Pe,bf as Ge,$ as Me,w as Ue,aD as $e,bg as We,av as Fe,bh as He}from"./vendor-icons-BaD0x9SL.js";import"./vendor-syntax-DuHI9Ok6.js";import"./vendor-markdown-CimbIo6Y.js";import"./vendor-i18n-DCFGyhQR.js";const Be={"ai-prompt":"bg-blue-500/10 text-blue-400 ring-blue-500/20",webhook:"bg-yellow-500/10 text-yellow-400 ring-yellow-500/20",delay:"bg-purple-500/10 text-purple-400 ring-purple-500/20",condition:"bg-green-500/10 text-green-400 ring-green-500/20",integration:"bg-cyan-500/10 text-cyan-400 ring-cyan-500/20"},Ke=["Send a Slack message when a GitHub issue is created","Email me a daily summary of calendar events","Create a Notion page from each new Trello card","Notify Discord when a payment is received"];function ze({onEdit:o,onCreate:h,refreshKey:b}){const[N,E]=s.useState([]),[A,C]=s.useState(!0),[d,f]=s.useState(null),[m,v]=s.useState(null),[l,j]=s.useState(null),[c,t]=s.useState([]),[u,g]=s.useState(!1),[w,S]=s.useState(!1),[T,R]=s.useState(""),[M,O]=s.useState(!1),[W,I]=s.useState(""),P=s.useCallback(async()=>{try{const a=await U("/api/workflows");if(a.ok){const n=await a.json();E(n.workflows||[])}}catch{}C(!1)},[]);s.useEffect(()=>{P()},[P,b]);const G=async a=>{if(l===a){j(null);return}j(a),g(!0);try{const n=await U(`/api/workflows/${a}/runs`);if(n.ok){const i=await n.json();t(i.runs||[])}}catch{t([])}g(!1)},B=async a=>{try{await U(`/api/workflows/${a}`,{method:"DELETE"}),P()}catch{}},F=async a=>{var n;f(a),v(null);try{const L=await(await U(`/api/workflows/${a}/run`,{method:"POST"})).json();v({id:a,success:L.success,message:L.success?`Completed ${((n=L.results)==null?void 0:n.length)||0} steps`:L.error||"Failed",results:L.results}),P()}catch{v({id:a,success:!1,message:"Network error"})}f(null)},K=async()=>{if(T.trim()){O(!0),I("");try{const a=await U("/api/workflows/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({description:T.trim()})}),n=await a.json();a.ok&&n.success?(S(!1),R(""),P(),n.workflow&&o(n.workflow)):I(n.error||"Failed to generate workflow")}catch{I("Network error")}O(!1)}};return A?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 gap-3",children:[e.jsx(D,{className:"w-5 h-5 animate-spin text-muted-foreground/50"}),e.jsx("span",{className:"text-xs text-muted-foreground/40",children:"Loading workflows..."})]}):e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-foreground tracking-tight",children:"Workflows"}),e.jsx("p",{className:"text-xs text-muted-foreground/50 mt-0.5",children:"Automate tasks with AI prompts, webhooks, and integrations"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>S(!w),className:`flex items-center gap-1.5 px-3 py-2 text-xs font-medium rounded-lg transition-all ${w?"bg-primary/10 text-primary":"bg-muted/30 text-muted-foreground hover:text-foreground hover:bg-muted/50"}`,children:[e.jsx(Q,{className:"w-3.5 h-3.5"}),"AI Create"]}),e.jsxs("button",{onClick:h,className:"flex items-center gap-1.5 px-3.5 py-2 text-xs font-medium bg-foreground text-background rounded-lg hover:opacity-90 transition-opacity",children:[e.jsx(J,{className:"w-3.5 h-3.5"}),"New Workflow"]})]})]}),w&&e.jsxs("div",{className:"bg-gradient-to-br from-primary/[0.03] to-transparent border border-primary/15 rounded-2xl p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-primary/10",children:e.jsx(Q,{className:"w-3.5 h-3.5 text-primary"})}),e.jsx("span",{className:"text-xs font-semibold text-foreground",children:"Describe your workflow"})]}),e.jsx("button",{onClick:()=>{S(!1),I("")},className:"p-1 text-muted-foreground/40 hover:text-foreground rounded-lg transition-colors",children:e.jsx(q,{className:"w-3.5 h-3.5"})})]}),e.jsx("textarea",{value:T,onChange:a=>R(a.target.value),placeholder:"Describe what you want to automate in plain English...",rows:3,className:"w-full px-3.5 py-2.5 text-sm bg-background border border-border/40 rounded-xl text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 focus:ring-1 focus:ring-primary/10 resize-none transition-colors",onKeyDown:a=>{a.key==="Enter"&&(a.metaKey||a.ctrlKey)&&!M&&K()}}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Ke.map(a=>e.jsx("button",{onClick:()=>R(a),className:"px-2.5 py-1 text-[10px] text-muted-foreground/50 hover:text-foreground bg-muted/20 hover:bg-muted/40 rounded-full transition-colors",children:a},a))}),W&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-red-400 bg-red-500/[0.03] border border-red-500/15 rounded-xl",children:[e.jsx(ne,{className:"w-3.5 h-3.5 flex-shrink-0"}),W]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{onClick:K,disabled:M||!T.trim(),className:"flex items-center gap-1.5 px-4 py-2 text-xs font-medium bg-foreground text-background rounded-lg hover:opacity-90 transition-opacity disabled:opacity-40",children:M?e.jsxs(e.Fragment,{children:[e.jsx(D,{className:"w-3.5 h-3.5 animate-spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"w-3.5 h-3.5"}),"Generate Workflow"]})})})]}),N.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-muted/30 flex items-center justify-center mb-4",children:e.jsx(re,{className:"w-7 h-7 text-muted-foreground/25"})}),e.jsx("h4",{className:"text-sm font-semibold text-foreground tracking-tight mb-1",children:"No workflows yet"}),e.jsx("p",{className:"text-xs text-muted-foreground/50 max-w-xs leading-relaxed mb-5",children:"Chain AI prompts, webhook calls, conditions, and app integrations into automated pipelines."}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>S(!0),className:"flex items-center gap-1.5 px-3.5 py-2 text-xs font-medium bg-primary/10 text-primary rounded-lg hover:bg-primary/15 transition-colors",children:[e.jsx(Q,{className:"w-3.5 h-3.5"}),"Create with AI"]}),e.jsxs("button",{onClick:h,className:"flex items-center gap-1.5 px-4 py-2 text-xs font-medium bg-foreground text-background rounded-lg hover:opacity-90 transition-opacity",children:[e.jsx(J,{className:"w-3.5 h-3.5"}),"Create Manually"]})]})]}):e.jsx("div",{className:"space-y-3",children:N.map((a,n)=>e.jsxs("div",{className:"bg-card/50 border border-border/30 rounded-2xl p-4 hover:border-border/50 transition-all duration-200",style:{animationDelay:`${n*30}ms`},children:[e.jsxs("div",{className:"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 mb-1",children:[e.jsx("h4",{className:"text-sm font-semibold text-foreground tracking-tight",children:a.name}),a.schedule&&a.schedule_enabled?e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-primary/70 bg-primary/5 px-1.5 py-0.5 rounded-full",children:[e.jsx(fe,{className:"w-2.5 h-2.5"}),"Scheduled"]}):null]}),a.description&&e.jsx("p",{className:"text-xs text-muted-foreground/60 mb-3 line-clamp-1",children:a.description}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[a.steps.map((i,L)=>e.jsxs(be.Fragment,{children:[e.jsx("span",{className:`inline-flex items-center gap-1 text-[10px] font-medium px-2 py-0.5 rounded-full ring-1 ${Be[i.type]||"bg-muted text-muted-foreground ring-border/30"}`,children:i.label}),L<a.steps.length-1&&e.jsx(je,{className:"w-3 h-3 text-muted-foreground/20 flex-shrink-0"})]},i.id||L)),a.steps.length===0&&e.jsx("span",{className:"text-[10px] text-muted-foreground/30 italic",children:"No steps configured"})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-2.5 text-[10px] text-muted-foreground/35",children:[e.jsxs("span",{children:[a.steps.length," step",a.steps.length!==1?"s":""]}),a.schedule&&a.schedule_enabled&&e.jsx("span",{className:"font-mono",children:a.schedule}),a.last_run&&e.jsxs("span",{children:["Last run ",new Date(a.last_run).toLocaleDateString()]})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs("button",{onClick:()=>F(a.id),disabled:d===a.id||a.steps.length===0,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium bg-green-500/8 text-green-400 hover:bg-green-500/15 rounded-lg transition-colors disabled:opacity-30",title:"Run workflow",children:[d===a.id?e.jsx(D,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(me,{className:"w-3.5 h-3.5"}),"Run"]}),e.jsx("button",{onClick:()=>G(a.id),className:`p-2 rounded-lg transition-colors ${l===a.id?"text-primary bg-primary/5":"text-muted-foreground/40 hover:text-foreground hover:bg-muted/30"}`,title:"Execution history",children:e.jsx(ue,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>o(a),className:"p-2 text-muted-foreground/40 hover:text-foreground hover:bg-muted/30 rounded-lg transition-colors",title:"Edit",children:e.jsx(ge,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>B(a.id),className:"p-2 text-muted-foreground/40 hover:text-red-400 hover:bg-red-500/5 rounded-lg transition-colors",title:"Delete",children:e.jsx(oe,{className:"w-3.5 h-3.5"})})]})]}),(m==null?void 0:m.id)===a.id&&e.jsxs("div",{className:`mt-3 p-3 rounded-xl text-xs ${m.success?"bg-green-500/[0.03] border border-green-500/15":"bg-red-500/[0.03] border border-red-500/15"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[m.success?e.jsx(ee,{className:"w-3.5 h-3.5 text-green-400"}):e.jsx(te,{className:"w-3.5 h-3.5 text-red-400"}),e.jsx("span",{className:`font-medium ${m.success?"text-green-400":"text-red-400"}`,children:m.message})]}),m.results&&e.jsx("div",{className:"space-y-1 mt-2",children:m.results.map((i,L)=>{var H;return e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px]",children:[i.success?e.jsx(ee,{className:"w-2.5 h-2.5 text-green-400/60"}):e.jsx(te,{className:"w-2.5 h-2.5 text-red-400/60"}),e.jsx("span",{className:"text-muted-foreground",children:i.label}),((H=i.result)==null?void 0:H.status)&&e.jsxs("span",{className:"text-muted-foreground/30",children:["(",i.result.status,")"]}),i.error&&e.jsx("span",{className:"text-red-400/60",children:i.error})]},L)})})]}),l===a.id&&e.jsxs("div",{className:"mt-3 border-t border-border/15 pt-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2.5",children:[e.jsx(ue,{className:"w-3 h-3 text-muted-foreground/50"}),e.jsx("span",{className:"text-[11px] font-semibold text-foreground",children:"Execution History"})]}),u?e.jsxs("div",{className:"flex items-center gap-2 py-3 text-[10px] text-muted-foreground/40",children:[e.jsx(D,{className:"w-3 h-3 animate-spin"}),"Loading..."]}):c.length===0?e.jsx("div",{className:"text-[10px] text-muted-foreground/30 py-3 italic",children:"No runs yet"}):e.jsx("div",{className:"space-y-1.5 max-h-48 overflow-y-auto",children:c.map(i=>e.jsxs("div",{className:"flex items-start gap-2.5 text-[10px] bg-muted/10 rounded-lg p-2.5",children:[e.jsx("div",{className:"shrink-0 mt-0.5",children:i.status==="completed"?e.jsx(ee,{className:"w-3 h-3 text-green-400"}):i.status==="failed"?e.jsx(te,{className:"w-3 h-3 text-red-400"}):i.status==="running"?e.jsx(D,{className:"w-3 h-3 text-yellow-400 animate-spin"}):e.jsx(ae,{className:"w-3 h-3 text-muted-foreground/40"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`font-medium ${i.status==="completed"?"text-green-400":i.status==="failed"?"text-red-400":"text-muted-foreground"}`,children:i.status==="completed"?"Success":i.status==="failed"?"Failed":i.status}),e.jsxs("span",{className:"text-muted-foreground/25",children:[i.steps_completed,"/",i.total_steps," steps"]}),e.jsx("span",{className:"text-muted-foreground/25",children:new Date(i.started_at).toLocaleString()})]}),i.error&&e.jsx("p",{className:"text-red-400/60 mt-0.5 truncate",children:i.error}),i.completed_at&&e.jsxs("span",{className:"text-muted-foreground/20",children:["Duration: ",Math.round((new Date(i.completed_at).getTime()-new Date(i.started_at).getTime())/1e3),"s"]})]})]},i.id))})]})]},a.id))})]})}const de=[{id:"GMAIL",name:"Gmail",icon:"mail",keywords:["gmail","email","send email","inbox","mail"],authConfigId:null,popularActions:[{slug:"GMAIL_SEND_EMAIL",label:"Send Email",params:["to","subject","body"]},{slug:"GMAIL_FETCH_EMAILS",label:"Fetch Emails",params:["query","max_results"]}]},{id:"GOOGLECALENDAR",name:"Google Calendar",icon:"calendar",keywords:["calendar","event","meeting","schedule meeting"],authConfigId:null,popularActions:[{slug:"GOOGLECALENDAR_CREATE_EVENT",label:"Create Event",params:["summary","start_time","end_time"]},{slug:"GOOGLECALENDAR_LIST_EVENTS",label:"List Events",params:["time_min","time_max"]}]},{id:"SLACK",name:"Slack",icon:"hash",keywords:["slack","channel","slack message"],authConfigId:null,popularActions:[{slug:"SLACK_SENDS_A_MESSAGE_TO_A_SLACK_CHANNEL",label:"Send Message",params:["channel","text"]}]},{id:"GITHUB",name:"GitHub",icon:"github",keywords:["github","repository","pull request","issue","commit"],authConfigId:null,popularActions:[{slug:"GITHUB_CREATE_AN_ISSUE",label:"Create Issue",params:["owner","repo","title","body"]},{slug:"GITHUB_CREATE_A_PULL_REQUEST",label:"Create PR",params:["owner","repo","title","head","base"]}]},{id:"NOTION",name:"Notion",icon:"file-text",keywords:["notion","page","note"],authConfigId:null,popularActions:[{slug:"NOTION_CREATE_A_PAGE",label:"Create Page",params:["parent_id","title","content"]}]},{id:"DISCORD",name:"Discord",icon:"message-circle",keywords:["discord"],authConfigId:null,popularActions:[{slug:"DISCORD_SEND_MESSAGE",label:"Send Message",params:["channel_id","content"]}]},{id:"GOOGLEDRIVE",name:"Google Drive",icon:"hard-drive",keywords:["drive","google drive","upload file","file storage"],authConfigId:null,popularActions:[{slug:"GOOGLEDRIVE_UPLOAD_FILE",label:"Upload File",params:["file_name","content"]},{slug:"GOOGLEDRIVE_LIST_FILES",label:"List Files",params:["query"]}]},{id:"TRELLO",name:"Trello",icon:"kanban",keywords:["trello","board","card","kanban"],authConfigId:null,popularActions:[{slug:"TRELLO_CREATE_CARD",label:"Create Card",params:["list_id","name","desc"]}]},{id:"LINEAR",name:"Linear",icon:"bug",keywords:["linear","ticket","linear issue"],authConfigId:null,popularActions:[{slug:"LINEAR_CREATE_ISSUE",label:"Create Issue",params:["team_id","title","description"]},{slug:"LINEAR_LIST_ISSUES",label:"List Issues",params:["team_id","status"]}]},{id:"JIRA",name:"Jira",icon:"bug",keywords:["jira","sprint","jira issue","jira ticket"],authConfigId:null,popularActions:[{slug:"JIRA_CREATE_ISSUE",label:"Create Issue",params:["project_key","summary","description","issue_type"]},{slug:"JIRA_GET_ISSUE",label:"Get Issue",params:["issue_key"]}]},{id:"ASANA",name:"Asana",icon:"list-checks",keywords:["asana","task","asana task","project management"],authConfigId:null,popularActions:[{slug:"ASANA_CREATE_TASK",label:"Create Task",params:["project_id","name","notes"]},{slug:"ASANA_LIST_TASKS",label:"List Tasks",params:["project_id"]}]},{id:"STRIPE",name:"Stripe",icon:"credit-card",keywords:["stripe","payment","invoice","charge","billing"],authConfigId:null,popularActions:[{slug:"STRIPE_CREATE_INVOICE",label:"Create Invoice",params:["customer_id","amount","currency"]},{slug:"STRIPE_LIST_PAYMENTS",label:"List Payments",params:["limit"]}]},{id:"TWILIO",name:"Twilio",icon:"phone",keywords:["twilio","sms","text message","phone"],authConfigId:null,popularActions:[{slug:"TWILIO_SEND_SMS",label:"Send SMS",params:["to","body"]}]},{id:"AIRTABLE",name:"Airtable",icon:"table",keywords:["airtable","spreadsheet","database","airtable record"],authConfigId:null,popularActions:[{slug:"AIRTABLE_CREATE_RECORD",label:"Create Record",params:["base_id","table_name","fields"]},{slug:"AIRTABLE_LIST_RECORDS",label:"List Records",params:["base_id","table_name"]}]}],Y={};for(const o of de)for(const h of o.keywords)Y[h.toLowerCase()]=o.id;const ce={};for(const o of de)ce[o.id]=o;function Je({stepId:o,config:h,onUpdateConfig:b}){const[N,E]=s.useState([]),[A,C]=s.useState(!0),[d,f]=s.useState(!1),[m,v]=s.useState(!1);s.useEffect(()=>{$.composio.catalog().then(t=>t.json()).then(t=>{E(t.catalog||[]),v(t.composioAvailable),C(!1)}).catch(()=>{E(de.map(t=>({...t,connected:!1,connectionId:null}))),C(!1)})},[]);const l=N.find(t=>t.id===h.integrationId),j=l==null?void 0:l.popularActions.find(t=>t.slug===h.toolSlug),c=async t=>{f(!0);try{const g=await(await $.composio.connect(t)).json();if(g.redirectUrl){const w=window.open(g.redirectUrl,"composio_oauth","width=600,height=700,popup=yes"),S=setInterval(async()=>{try{if((await(await $.composio.waitForConnection(g.connectedAccountId)).json()).status==="ACTIVE"){clearInterval(S),w==null||w.close();const O=await(await $.composio.catalog()).json();E(O.catalog||[]),f(!1)}}catch{}},2e3);setTimeout(()=>{clearInterval(S),f(!1)},12e4)}}catch{f(!1)}};return A?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground/50 py-3",children:[e.jsx(D,{className:"w-3 h-3 animate-spin"}),"Loading integrations..."]}):m?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 mb-1 block",children:"Integration"}),e.jsxs("select",{value:h.integrationId||"",onChange:t=>{const u=t.target.value;b("integrationId",u),b("toolSlug",""),b("arguments",{})},className:"w-full px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground focus:outline-none focus:border-primary/40 transition-colors",children:[e.jsx("option",{value:"",children:"Select an integration..."}),N.map(t=>e.jsxs("option",{value:t.id,children:[t.name," ",t.connected?"(Connected)":""]},t.id))]})]}),l&&!l.connected&&e.jsxs("div",{className:"flex items-center gap-2 p-2.5 bg-yellow-500/[0.03] border border-yellow-500/15 rounded-xl",children:[e.jsxs("span",{className:"text-[10px] text-yellow-400 flex-1",children:[l.name," is not connected yet."]}),e.jsxs("button",{onClick:()=>c(l.id),disabled:d,className:"flex items-center gap-1 px-2.5 py-1.5 text-[10px] font-medium bg-foreground text-background rounded-lg hover:opacity-90 disabled:opacity-50 transition-opacity",children:[d?e.jsx(D,{className:"w-3 h-3 animate-spin"}):e.jsx(le,{className:"w-3 h-3"}),"Connect"]})]}),l&&l.connected&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-green-400 font-medium",children:[e.jsx(ie,{className:"w-3 h-3"}),"Connected"]}),l&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 mb-1 block",children:"Action"}),e.jsxs("select",{value:h.toolSlug||"",onChange:t=>{b("toolSlug",t.target.value),b("arguments",{})},className:"w-full px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground focus:outline-none focus:border-primary/40 transition-colors",children:[e.jsx("option",{value:"",children:"Select an action..."}),l.popularActions.map(t=>e.jsx("option",{value:t.slug,children:t.label},t.slug))]})]}),j&&j.params.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 block",children:"Parameters"}),j.params.map(t=>{var u;return e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-muted-foreground/40 mb-0.5 block capitalize",children:t.replace(/_/g," ")}),e.jsx("input",{value:((u=h.arguments)==null?void 0:u[t])||"",onChange:g=>{const w={...h.arguments||{},[t]:g.target.value};b("arguments",w)},placeholder:`{{prev.${t}}} or value`,className:"w-full px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground placeholder-muted-foreground/25 focus:outline-none focus:border-primary/40 font-mono transition-colors"})]},t)}),e.jsxs("p",{className:"text-[10px] text-muted-foreground/30",children:["Use ","{{prev.field}}"," to reference output from the previous step."]})]})]}):e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground/50 py-3",children:[e.jsx(V,{className:"w-3.5 h-3.5"}),e.jsxs("span",{children:["Composio not configured. Set ",e.jsx("code",{className:"px-1 py-0.5 bg-muted/40 rounded text-[10px] font-mono",children:"COMPOSIO_API_KEY"})," on the server."]})]})}function Ve({keyword:o,integrationId:h,integrationName:b,position:N,onDismiss:E,onAddAction:A}){const[C,d]=s.useState(null),[f,m]=s.useState(!1),v=s.useRef(null),l=ce[h],j=(l==null?void 0:l.popularActions)||[];s.useEffect(()=>{$.composio.catalog().then(t=>t.json()).then(t=>{const u=(t.catalog||[]).find(g=>g.id===h);d((u==null?void 0:u.connected)||!1)}).catch(()=>d(!1))},[h]),s.useEffect(()=>{const t=g=>{v.current&&!v.current.contains(g.target)&&E()},u=g=>{g.key==="Escape"&&E()};return document.addEventListener("mousedown",t),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("keydown",u)}},[E]);const c=async()=>{m(!0);try{const u=await(await $.composio.connect(h)).json();if(u.redirectUrl){const g=window.open(u.redirectUrl,"composio_oauth","width=600,height=700,popup=yes"),w=setInterval(async()=>{try{(await(await $.composio.waitForConnection(u.connectedAccountId)).json()).status==="ACTIVE"&&(clearInterval(w),g==null||g.close(),d(!0),m(!1))}catch{}},2e3);setTimeout(()=>{clearInterval(w),m(!1)},12e4)}}catch{m(!1)}};return e.jsxs("div",{ref:v,className:"fixed z-50 bg-card border border-border/40 rounded-2xl shadow-2xl overflow-hidden min-w-[240px] max-w-[300px]",style:{top:N.top,left:Math.min(N.left,window.innerWidth-320)},children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2.5 bg-muted/20 border-b border-border/20",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-cyan-500/10",children:e.jsx(re,{className:"w-3.5 h-3.5 text-cyan-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-foreground",children:b}),e.jsxs("div",{className:"text-[10px] text-muted-foreground/40",children:['Detected "',e.jsx("span",{className:"text-primary/60 font-medium",children:o}),'"']})]}),e.jsx("button",{onClick:E,className:"p-1 text-muted-foreground/30 hover:text-foreground rounded-lg transition-colors",children:e.jsx(q,{className:"w-3.5 h-3.5"})})]}),e.jsxs("div",{className:"p-1.5",children:[C===null&&e.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-3 text-xs text-muted-foreground/50",children:[e.jsx(D,{className:"w-3 h-3 animate-spin"}),"Checking connection..."]}),C===!1&&e.jsxs("button",{onClick:c,disabled:f,className:"w-full flex items-center gap-2.5 px-2.5 py-2.5 text-xs text-foreground hover:bg-muted/30 rounded-xl transition-colors",children:[f?e.jsx(D,{className:"w-3.5 h-3.5 animate-spin text-primary"}):e.jsx(le,{className:"w-3.5 h-3.5 text-primary"}),e.jsxs("span",{children:["Connect ",b," to use this"]})]}),C===!0&&j.length>0&&e.jsx("div",{className:"space-y-0.5",children:j.map(t=>e.jsxs("button",{onClick:()=>A(h,t.slug,t.label),className:"w-full flex items-center gap-2.5 px-2.5 py-2 text-xs text-foreground hover:bg-muted/30 rounded-xl transition-colors group",children:[e.jsx(J,{className:"w-3.5 h-3.5 text-cyan-400 group-hover:text-cyan-300"}),e.jsxs("span",{className:"flex-1 text-left",children:["Add: ",t.label]})]},t.slug))})]})]})}function qe(){const[o,h]=s.useState(null),b=s.useRef(null),N=s.useRef(null),E=s.useCallback((d,f,m)=>{b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{if(!d||f===0){h(null);return}const l=d.slice(0,f).toLowerCase().split(/\s+/).filter(Boolean);let j=null;if(l.length>=2){const c=`${l[l.length-2]} ${l[l.length-1]}`;Y[c]&&(j=c)}if(!j&&l.length>=1){const c=l[l.length-1];Y[c]&&(j=c)}if(j&&j!==N.current){const c=Y[j],t=ce[c];if(t){h({keyword:j,integrationId:c,integrationName:t.name,position:m?{top:m.bottom+4,left:m.left}:{top:0,left:0}});return}}h(null)},300)},[]),A=s.useCallback(()=>{o&&(N.current=o.keyword),h(null)},[o]),C=s.useCallback(()=>{N.current=null},[]);return s.useEffect(()=>()=>{b.current&&clearTimeout(b.current)},[]),{activeMatch:o,detectKeywords:E,dismiss:A,resetDismissed:C}}const se=[{value:"ai-prompt",label:"AI Prompt",desc:"Ask AI to process data",icon:Ne,color:"text-blue-400 bg-blue-500/10",ring:"ring-blue-500/20"},{value:"webhook",label:"Webhook",desc:"Call an HTTP endpoint",icon:Z,color:"text-yellow-400 bg-yellow-500/10",ring:"ring-yellow-500/20"},{value:"delay",label:"Delay",desc:"Wait before continuing",icon:ae,color:"text-purple-400 bg-purple-500/10",ring:"ring-purple-500/20"},{value:"condition",label:"Condition",desc:"Branch on a condition",icon:ye,color:"text-green-400 bg-green-500/10",ring:"ring-green-500/20"},{value:"integration",label:"Integration",desc:"Use a connected app",icon:V,color:"text-cyan-400 bg-cyan-500/10",ring:"ring-cyan-500/20"}];let Ye=0;const xe=()=>`step_${Date.now()}_${++Ye}`,Ze=[{label:"Every minute",cron:"* * * * *"},{label:"Every 5 minutes",cron:"*/5 * * * *"},{label:"Every 15 minutes",cron:"*/15 * * * *"},{label:"Every hour",cron:"0 * * * *"},{label:"Every 6 hours",cron:"0 */6 * * *"},{label:"Daily at midnight",cron:"0 0 * * *"},{label:"Daily at 9 AM",cron:"0 9 * * *"},{label:"Weekly (Monday)",cron:"0 9 * * 1"},{label:"Monthly (1st)",cron:"0 0 1 * *"}];function Xe({workflow:o,onSave:h,onCancel:b}){const[N,E]=s.useState((o==null?void 0:o.name)||""),[A,C]=s.useState((o==null?void 0:o.description)||""),[d,f]=s.useState((o==null?void 0:o.steps)||[]),[m,v]=s.useState((o==null?void 0:o.schedule)||""),[l,j]=s.useState(!!(o!=null&&o.schedule_enabled)),[c,t]=s.useState((o==null?void 0:o.schedule_timezone)||Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"),[u,g]=s.useState([]),[w,S]=s.useState(!1),[T,R]=s.useState(""),[M,O]=s.useState(null),[W,I]=s.useState(!1),P=s.useRef(null),{activeMatch:G,detectKeywords:B,dismiss:F}=qe();s.useEffect(()=>{U("/api/webhooks").then(r=>r.json()).then(r=>{g(r.webhooks||[])}).catch(()=>{})},[]);const K=s.useCallback(r=>{const k=se.find(y=>y.value===r),p={id:xe(),type:r,label:(k==null?void 0:k.label)||r,config:r==="delay"?{seconds:5}:{},order:d.length};f(y=>[...y,p]),O(p.id),I(!1)},[d.length]),a=s.useCallback(r=>{f(k=>k.filter(p=>p.id!==r).map((p,y)=>({...p,order:y}))),M===r&&O(null)},[M]),n=s.useCallback((r,k)=>{f(p=>{const y=p.findIndex(z=>z.id===r);if(y<0)return p;const _=k==="up"?y-1:y+1;if(_<0||_>=p.length)return p;const x=[...p];return[x[y],x[_]]=[x[_],x[y]],x.map((z,he)=>({...z,order:he}))})},[]),i=s.useCallback((r,k,p)=>{f(y=>y.map(_=>_.id===r?{..._,config:{..._.config,[k]:p}}:_))},[]),L=s.useCallback((r,k)=>{f(p=>p.map(y=>y.id===r?{...y,label:k}:y))},[]),H=s.useCallback((r,k,p)=>{const y={id:xe(),type:"integration",label:p,config:{integrationId:r,toolSlug:k,arguments:{}},order:d.length};f(_=>[..._,y]),O(y.id),F()},[d.length,F]),X=s.useCallback(r=>{const k=r.target.value;C(k);const p=r.target.getBoundingClientRect();B(k,r.target.selectionStart||0,p)},[B]),pe=async()=>{if(R(""),!N.trim()){R("Workflow name is required");return}if(d.length===0){R("Add at least one step");return}S(!0);try{const r={name:N,description:A,steps:d,schedule:m||null,schedule_enabled:l,schedule_timezone:c},k=o!=null&&o.id?`/api/workflows/${o.id}`:"/api/workflows",p=o!=null&&o.id?"PUT":"POST",y=await U(k,{method:p,headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!y.ok){const _=await y.json();R(_.error||"Failed to save"),S(!1);return}h()}catch{R("Network error")}S(!1)};return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border/20 bg-card/50",children:[e.jsx("button",{onClick:b,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-muted/30 rounded-lg transition-colors",children:e.jsx(ve,{className:"w-4 h-4"})}),e.jsx("span",{className:"text-sm font-semibold text-foreground tracking-tight",children:o!=null&&o.id?"Edit Workflow":"New Workflow"}),e.jsx("div",{className:"flex-1"}),e.jsxs("button",{onClick:pe,disabled:w,className:"flex items-center gap-1.5 px-4 py-2 text-xs font-medium bg-foreground text-background rounded-lg hover:opacity-90 transition-opacity disabled:opacity-50",children:[e.jsx(we,{className:"w-3.5 h-3.5"}),w?"Saving...":"Save Workflow"]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-5",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground/70 mb-1.5 block",children:"Name"}),e.jsx("input",{value:N,onChange:r=>E(r.target.value),placeholder:"My Workflow",className:"w-full px-3.5 py-2.5 text-sm bg-background border border-border/40 rounded-xl text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 focus:ring-1 focus:ring-primary/10 transition-colors"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground/70 mb-1.5 block",children:"Description"}),e.jsxs("div",{className:"relative",children:[e.jsx("textarea",{ref:P,value:A,onChange:X,placeholder:"Describe what this workflow does... Try typing 'email', 'slack', or 'calendar' to auto-detect integrations",rows:2,className:"w-full px-3.5 py-2.5 text-xs bg-background border border-border/40 rounded-xl text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 focus:ring-1 focus:ring-primary/10 resize-none transition-colors"}),G&&e.jsx(Ve,{keyword:G.keyword,integrationId:G.integrationId,integrationName:G.integrationName,position:G.position,onDismiss:F,onAddAction:H})]})]})]}),e.jsxs("div",{className:"bg-card/50 border border-border/30 rounded-2xl p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs font-semibold text-foreground flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-purple-500/10",children:e.jsx(ae,{className:"w-3.5 h-3.5 text-purple-400"})}),"Schedule"]}),e.jsx("button",{onClick:()=>j(!l),className:`relative w-9 h-5 rounded-full transition-colors ${l?"bg-primary":"bg-muted/60"}`,children:e.jsx("div",{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white shadow-sm transition-transform ${l?"translate-x-[18px]":"translate-x-0.5"}`})})]}),l&&e.jsxs("div",{className:"space-y-3 pt-1",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 mb-1 block",children:"Cron Expression"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{value:m,onChange:r=>v(r.target.value),placeholder:"*/15 * * * *",className:"flex-1 px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 font-mono transition-colors"}),e.jsxs("select",{value:m,onChange:r=>v(r.target.value),className:"px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground focus:outline-none focus:border-primary/40 transition-colors",children:[e.jsx("option",{value:"",children:"Presets..."}),Ze.map(r=>e.jsx("option",{value:r.cron,children:r.label},r.cron))]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 mb-1 block",children:"Timezone"}),e.jsx("input",{value:c,onChange:r=>t(r.target.value),placeholder:"UTC",className:"w-48 px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 transition-colors"})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground/35 leading-relaxed",children:'Runs automatically when the server is online. Missed runs while offline appear as "missed" in execution history.'})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center justify-between mb-3",children:e.jsxs("span",{className:"text-xs font-semibold text-foreground",children:["Steps (",d.length,")"]})}),d.length===0?e.jsx("div",{className:"text-center py-10 border border-dashed border-border/30 rounded-2xl",children:e.jsx("p",{className:"text-xs text-muted-foreground/40",children:"No steps yet. Add your first step below."})}):e.jsx("div",{className:"space-y-2",children:d.map((r,k)=>{const p=se.find(x=>x.value===r.type),y=(p==null?void 0:p.icon)||Z,_=M===r.id;return e.jsxs("div",{className:`border rounded-2xl overflow-hidden transition-colors ${_?"border-border/50 bg-card/50":"border-border/25 bg-card/30"}`,children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2.5 cursor-pointer hover:bg-muted/20 transition-colors",onClick:()=>O(_?null:r.id),children:[e.jsx(ke,{className:"w-3 h-3 text-muted-foreground/20 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-muted-foreground/40 w-5 text-center font-mono",children:k+1}),e.jsx("div",{className:`p-1.5 rounded-lg ${(p==null?void 0:p.color)||"bg-muted text-muted-foreground"}`,children:e.jsx(y,{className:"w-3.5 h-3.5"})}),e.jsx("span",{className:"text-xs font-medium text-foreground flex-1 min-w-0 truncate",children:r.label}),e.jsx("span",{className:"text-[10px] text-muted-foreground/35",children:p==null?void 0:p.label}),e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsx("button",{onClick:x=>{x.stopPropagation(),n(r.id,"up")},disabled:k===0,className:"p-1 text-muted-foreground/30 hover:text-foreground rounded transition-colors disabled:opacity-20",children:e.jsx(Ce,{className:"w-3 h-3"})}),e.jsx("button",{onClick:x=>{x.stopPropagation(),n(r.id,"down")},disabled:k===d.length-1,className:"p-1 text-muted-foreground/30 hover:text-foreground rounded transition-colors disabled:opacity-20",children:e.jsx(Se,{className:"w-3 h-3"})}),e.jsx("button",{onClick:x=>{x.stopPropagation(),a(r.id)},className:"p-1 text-muted-foreground/30 hover:text-red-400 rounded transition-colors",children:e.jsx(oe,{className:"w-3 h-3"})})]})]}),_&&e.jsxs("div",{className:"px-4 pb-4 pt-2 border-t border-border/15 space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 mb-1 block",children:"Step Label"}),e.jsx("input",{value:r.label,onChange:x=>L(r.id,x.target.value),className:"w-full px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground focus:outline-none focus:border-primary/40 transition-colors"})]}),r.type==="ai-prompt"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 mb-1 block",children:"Prompt"}),e.jsx("textarea",{value:r.config.prompt||"",onChange:x=>i(r.id,"prompt",x.target.value),placeholder:"Describe what the AI should do...",rows:3,className:"w-full px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 resize-none transition-colors"})]}),r.type==="webhook"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 mb-1 block",children:"Webhook"}),e.jsxs("select",{value:r.config.webhookId||"",onChange:x=>i(r.id,"webhookId",x.target.value),className:"w-full px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground focus:outline-none focus:border-primary/40 transition-colors",children:[e.jsx("option",{value:"",children:"Select a webhook..."}),u.map(x=>e.jsxs("option",{value:x.id,children:[x.name," (",x.method," ",x.url,")"]},x.id))]}),u.length===0&&e.jsx("p",{className:"text-[10px] text-muted-foreground/35 mt-1",children:"No webhooks created yet. Go to the Webhooks tab first."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 mb-1 block",children:"Payload Template (JSON)"}),e.jsx("textarea",{value:r.config.payloadTemplate||"",onChange:x=>i(r.id,"payloadTemplate",x.target.value),placeholder:'{"key": "value"}',rows:2,className:"w-full px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 resize-none font-mono transition-colors"})]})]}),r.type==="delay"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 mb-1 block",children:"Delay (seconds, max 30)"}),e.jsx("input",{type:"number",min:1,max:30,value:r.config.seconds||5,onChange:x=>i(r.id,"seconds",Math.min(30,Math.max(1,parseInt(x.target.value)||1))),className:"w-24 px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground focus:outline-none focus:border-primary/40 transition-colors"})]}),r.type==="condition"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-medium text-muted-foreground/60 mb-1 block",children:"Condition Expression"}),e.jsx("input",{value:r.config.expression||"",onChange:x=>i(r.id,"expression",x.target.value),placeholder:"e.g. response.status === 200",className:"w-full px-3 py-2 text-xs bg-background border border-border/40 rounded-lg text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 font-mono transition-colors"}),e.jsx("p",{className:"text-[10px] text-muted-foreground/30 mt-1",children:"Condition evaluation coming soon"})]}),r.type==="integration"&&e.jsx(Je,{stepId:r.id,config:r.config,onUpdateConfig:(x,z)=>i(r.id,x,z)})]})]},r.id)})}),e.jsx("div",{className:"mt-3",children:W?e.jsxs("div",{className:"border border-border/30 rounded-2xl p-3 bg-card/50",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2.5",children:[e.jsx("span",{className:"text-[11px] font-semibold text-foreground",children:"Add a step"}),e.jsx("button",{onClick:()=>I(!1),className:"p-1 text-muted-foreground/40 hover:text-foreground rounded transition-colors",children:e.jsx(q,{className:"w-3.5 h-3.5"})})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:se.map(r=>{const k=r.icon;return e.jsxs("button",{onClick:()=>K(r.value),className:"flex flex-col items-center gap-2 p-3 rounded-xl border border-border/20 bg-background/50 hover:border-border/50 hover:bg-muted/20 transition-all text-center",children:[e.jsx("div",{className:`p-2 rounded-xl ${r.color}`,children:e.jsx(k,{className:"w-4 h-4"})}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] font-medium text-foreground block",children:r.label}),e.jsx("span",{className:"text-[9px] text-muted-foreground/40",children:r.desc})]})]},r.value)})})]}):e.jsxs("button",{onClick:()=>I(!0),className:"w-full flex items-center justify-center gap-1.5 py-2.5 text-xs text-muted-foreground/50 hover:text-foreground border border-dashed border-border/30 hover:border-border/50 rounded-2xl transition-colors",children:[e.jsx(J,{className:"w-3.5 h-3.5"}),"Add Step"]})})]}),T&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 text-xs text-red-400 bg-red-500/[0.03] border border-red-500/15 rounded-xl",children:[e.jsx(ne,{className:"w-3.5 h-3.5 flex-shrink-0"}),T]})]})]})}const Qe=["GET","POST","PUT","PATCH","DELETE"],et={GET:"bg-green-500/10 text-green-400",POST:"bg-blue-500/10 text-blue-400",PUT:"bg-yellow-500/10 text-yellow-400",PATCH:"bg-orange-500/10 text-orange-400",DELETE:"bg-red-500/10 text-red-400"};function tt({onWebhooksChange:o}){const[h,b]=s.useState([]),[N,E]=s.useState(!0),[A,C]=s.useState(!1),[d,f]=s.useState(null),[m,v]=s.useState(null),[l,j]=s.useState(null),[c,t]=s.useState(""),[u,g]=s.useState(""),[w,S]=s.useState("POST"),[T,R]=s.useState("{}"),[M,O]=s.useState(""),[W,I]=s.useState(""),P=s.useCallback(async()=>{try{const n=await U("/api/webhooks");if(n.ok){const i=await n.json();b(i.webhooks||[])}}catch{}E(!1)},[]);s.useEffect(()=>{P()},[P]);const G=()=>{t(""),g(""),S("POST"),R("{}"),O(""),I(""),f(null),C(!1)},B=n=>{t(n.name),g(n.url),S(n.method),R(n.headers||"{}"),O(n.description||""),f(n.id),C(!0),I("")},F=async()=>{if(I(""),!c.trim()){I("Name is required");return}if(!u.trim()){I("URL is required");return}try{new URL(u)}catch{I("Invalid URL");return}try{JSON.parse(T)}catch{I("Headers must be valid JSON");return}try{const n={name:c,url:u,method:w,headers:T,description:M},i=d?`/api/webhooks/${d}`:"/api/webhooks",H=await U(i,{method:d?"PUT":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!H.ok){const X=await H.json();I(X.error||"Failed to save");return}G(),P(),o==null||o()}catch{I("Network error")}},K=async n=>{try{await U(`/api/webhooks/${n}`,{method:"DELETE"}),P(),o==null||o()}catch{}},a=async n=>{v(n),j(null);try{const L=await(await U(`/api/webhooks/${n}/test`,{method:"POST"})).json();j({id:n,result:L.result,success:L.success})}catch{j({id:n,result:{error:"Network error"},success:!1})}v(null)};return N?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 gap-3",children:[e.jsx(D,{className:"w-5 h-5 animate-spin text-muted-foreground/50"}),e.jsx("span",{className:"text-xs text-muted-foreground/40",children:"Loading webhooks..."})]}):e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-foreground tracking-tight",children:"Webhooks"}),e.jsx("p",{className:"text-xs text-muted-foreground/50 mt-0.5",children:"HTTP endpoints that workflows can call during execution"})]}),!A&&e.jsxs("button",{onClick:()=>{G(),C(!0)},className:"flex items-center gap-1.5 px-3.5 py-2 text-xs font-medium bg-foreground text-background rounded-lg hover:opacity-90 transition-opacity",children:[e.jsx(J,{className:"w-3.5 h-3.5"}),"Add Webhook"]})]}),A&&e.jsxs("div",{className:"bg-card/50 border border-border/30 rounded-2xl p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-xs font-semibold text-foreground",children:d?"Edit Webhook":"New Webhook"}),e.jsx("button",{onClick:G,className:"p-1.5 text-muted-foreground/40 hover:text-foreground hover:bg-muted/30 rounded-lg transition-colors",children:e.jsx(q,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground/70 mb-1.5 block",children:"Name"}),e.jsx("input",{value:c,onChange:n=>t(n.target.value),placeholder:"My Webhook",className:"w-full px-3.5 py-2.5 text-xs bg-background border border-border/40 rounded-xl text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 focus:ring-1 focus:ring-primary/10 transition-colors"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground/70 mb-1.5 block",children:"Method"}),e.jsx("select",{value:w,onChange:n=>S(n.target.value),className:"w-full px-3.5 py-2.5 text-xs bg-background border border-border/40 rounded-xl text-foreground focus:outline-none focus:border-primary/40 transition-colors",children:Qe.map(n=>e.jsx("option",{value:n,children:n},n))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground/70 mb-1.5 block",children:"URL"}),e.jsx("input",{value:u,onChange:n=>g(n.target.value),placeholder:"https://example.com/webhook",className:"w-full px-3.5 py-2.5 text-xs bg-background border border-border/40 rounded-xl text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 focus:ring-1 focus:ring-primary/10 transition-colors"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground/70 mb-1.5 block",children:"Headers (JSON)"}),e.jsx("textarea",{value:T,onChange:n=>R(n.target.value),placeholder:'{"Authorization": "Bearer ..."}',rows:2,className:"w-full px-3.5 py-2.5 text-xs bg-background border border-border/40 rounded-xl text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 font-mono resize-none transition-colors"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground/70 mb-1.5 block",children:"Description"}),e.jsx("input",{value:M,onChange:n=>O(n.target.value),placeholder:"Optional description...",className:"w-full px-3.5 py-2.5 text-xs bg-background border border-border/40 rounded-xl text-foreground placeholder-muted-foreground/40 focus:outline-none focus:border-primary/40 transition-colors"})]}),W&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 text-xs text-red-400 bg-red-500/[0.03] border border-red-500/15 rounded-xl",children:[e.jsx(ne,{className:"w-3.5 h-3.5 flex-shrink-0"}),W]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[e.jsx("button",{onClick:G,className:"px-3.5 py-2 text-xs text-muted-foreground hover:text-foreground transition-colors rounded-lg",children:"Cancel"}),e.jsxs("button",{onClick:F,className:"flex items-center gap-1.5 px-4 py-2 text-xs font-medium bg-foreground text-background rounded-lg hover:opacity-90 transition-opacity",children:[e.jsx(ie,{className:"w-3.5 h-3.5"}),d?"Update":"Create"]})]})]}),h.length===0&&!A?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-muted/30 flex items-center justify-center mb-4",children:e.jsx(Ee,{className:"w-7 h-7 text-muted-foreground/25"})}),e.jsx("h4",{className:"text-sm font-semibold text-foreground tracking-tight mb-1",children:"No webhooks yet"}),e.jsx("p",{className:"text-xs text-muted-foreground/50 max-w-xs leading-relaxed",children:"Create a webhook endpoint to use in your workflow steps."})]}):e.jsx("div",{className:"space-y-3",children:h.map((n,i)=>e.jsxs("div",{className:"bg-card/50 border border-border/30 rounded-2xl p-4 hover:border-border/50 transition-all duration-200",style:{animationDelay:`${i*30}ms`},children:[e.jsxs("div",{className:"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 mb-1",children:[e.jsx("span",{className:"text-sm font-semibold text-foreground tracking-tight",children:n.name}),e.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full font-mono font-medium ${et[n.method]||"bg-muted text-muted-foreground"}`,children:n.method})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground/50 font-mono truncate",children:n.url}),n.description&&e.jsx("p",{className:"text-[11px] text-muted-foreground/40 mt-1",children:n.description}),n.last_triggered&&e.jsxs("p",{className:"text-[10px] text-muted-foreground/30 mt-1.5",children:["Last triggered: ",new Date(n.last_triggered).toLocaleString()]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:()=>a(n.id),disabled:m===n.id,className:"p-2 text-muted-foreground/40 hover:text-green-400 hover:bg-green-500/5 rounded-lg transition-colors disabled:opacity-50",title:"Test webhook",children:m===n.id?e.jsx(D,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(me,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>B(n),className:"p-2 text-muted-foreground/40 hover:text-foreground hover:bg-muted/30 rounded-lg transition-colors",title:"Edit",children:e.jsx(ge,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>K(n.id),className:"p-2 text-muted-foreground/40 hover:text-red-400 hover:bg-red-500/5 rounded-lg transition-colors",title:"Delete",children:e.jsx(oe,{className:"w-3.5 h-3.5"})})]})]}),(l==null?void 0:l.id)===n.id&&e.jsx("div",{className:`mt-3 p-3 rounded-xl text-xs ${l.success?"bg-green-500/[0.03] border border-green-500/15":"bg-red-500/[0.03] border border-red-500/15"}`,children:l.result.error?e.jsx("span",{className:"text-red-400",children:l.result.error}):e.jsxs("div",{children:[e.jsxs("span",{className:l.result.status&&l.result.status<400?"text-green-400 font-medium":"text-red-400 font-medium",children:[l.result.status," ",l.result.statusText]}),l.result.body&&e.jsx("pre",{className:"mt-2 text-[10px] text-muted-foreground/50 font-mono overflow-x-auto max-h-24 overflow-y-auto p-2 bg-background/50 rounded-lg",children:typeof l.result.body=="string"?l.result.body:JSON.stringify(l.result.body,null,2)})]})})]},n.id))})]})}const st={mail:Fe,calendar:We,hash:$e,github:Ue,"file-text":Me,"message-circle":Ge,"hard-drive":Pe,"layout-grid":Oe,zap:Z,bug:De,"list-checks":Re,"credit-card":Le,phone:_e,table:Te,kanban:Ie},rt={GMAIL:{bg:"bg-red-500/8",text:"text-red-400",ring:"ring-red-500/20"},GOOGLECALENDAR:{bg:"bg-blue-500/8",text:"text-blue-400",ring:"ring-blue-500/20"},SLACK:{bg:"bg-purple-500/8",text:"text-purple-400",ring:"ring-purple-500/20"},GITHUB:{bg:"bg-neutral-500/8",text:"text-neutral-300",ring:"ring-neutral-500/20"},NOTION:{bg:"bg-neutral-500/8",text:"text-neutral-300",ring:"ring-neutral-500/20"},DISCORD:{bg:"bg-indigo-500/8",text:"text-indigo-400",ring:"ring-indigo-500/20"},GOOGLEDRIVE:{bg:"bg-yellow-500/8",text:"text-yellow-400",ring:"ring-yellow-500/20"},TRELLO:{bg:"bg-blue-500/8",text:"text-blue-400",ring:"ring-blue-500/20"},LINEAR:{bg:"bg-violet-500/8",text:"text-violet-400",ring:"ring-violet-500/20"},JIRA:{bg:"bg-blue-600/8",text:"text-blue-500",ring:"ring-blue-600/20"},ASANA:{bg:"bg-rose-500/8",text:"text-rose-400",ring:"ring-rose-500/20"},STRIPE:{bg:"bg-violet-500/8",text:"text-violet-400",ring:"ring-violet-500/20"},TWILIO:{bg:"bg-red-500/8",text:"text-red-400",ring:"ring-red-500/20"},AIRTABLE:{bg:"bg-teal-500/8",text:"text-teal-400",ring:"ring-teal-500/20"}},nt={bg:"bg-primary/8",text:"text-primary",ring:"ring-primary/20"};function ot(){const[o,h]=s.useState([]),[b,N]=s.useState(!0),[E,A]=s.useState(!1),[C,d]=s.useState(null),[f,m]=s.useState(null),v=s.useCallback(async()=>{try{const u=await(await $.composio.catalog()).json();h(u.catalog||[]),A(u.composioAvailable)}catch{A(!1)}N(!1)},[]);s.useEffect(()=>{v()},[v]);const l=async t=>{d(t);try{const g=await(await $.composio.connect(t)).json();if(g.redirectUrl){const w=window.open(g.redirectUrl,"composio_oauth","width=600,height=700,popup=yes"),S=setInterval(async()=>{try{(await(await $.composio.waitForConnection(g.connectedAccountId)).json()).status==="ACTIVE"&&(clearInterval(S),w==null||w.close(),d(null),v())}catch{}},2e3);setTimeout(()=>{clearInterval(S),d(null)},12e4)}}catch{d(null)}},j=async t=>{if(t.connectionId){m(t.id);try{await $.composio.disconnect(t.connectionId),await v()}catch{}m(null)}};if(b)return e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 gap-3",children:[e.jsx(D,{className:"w-5 h-5 animate-spin text-muted-foreground/50"}),e.jsx("span",{className:"text-xs text-muted-foreground/40",children:"Loading integrations..."})]});if(!E)return e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-muted/30 flex items-center justify-center mb-4",children:e.jsx(V,{className:"w-7 h-7 text-muted-foreground/25"})}),e.jsx("h4",{className:"text-sm font-semibold text-foreground tracking-tight mb-1",children:"Composio Not Configured"}),e.jsxs("p",{className:"text-xs text-muted-foreground/50 max-w-xs leading-relaxed",children:["Set ",e.jsx("code",{className:"px-1 py-0.5 bg-muted/40 rounded text-[10px] font-mono",children:"COMPOSIO_API_KEY"})," in your server environment to unlock 850+ app integrations."]})]});const c=o.filter(t=>t.connected).length;return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-foreground tracking-tight",children:"Integrations"}),e.jsxs("p",{className:"text-xs text-muted-foreground/50 mt-0.5",children:[c," of ",o.length," connected"]})]}),e.jsxs("button",{onClick:v,className:"flex items-center gap-1.5 px-2.5 py-1.5 text-xs text-muted-foreground hover:text-foreground bg-muted/30 hover:bg-muted/50 rounded-lg transition-colors",title:"Refresh",children:[e.jsx(Ae,{className:"w-3.5 h-3.5"}),"Refresh"]})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:o.map((t,u)=>{const g=rt[t.id]||nt,w=st[t.icon]||V,S=C===t.id,T=f===t.id;return e.jsxs("div",{className:`group relative flex flex-col items-center text-center p-4 rounded-2xl border transition-all duration-200 ${t.connected?"bg-green-500/[0.03] border-green-500/15 hover:border-green-500/30":"bg-card/50 border-border/30 hover:border-border/60 hover:bg-muted/20"}`,style:{animationDelay:`${u*40}ms`},children:[t.connected&&e.jsx("div",{className:"absolute top-2.5 right-2.5",children:e.jsx("div",{className:"w-2 h-2 rounded-full bg-green-400 ring-2 ring-green-400/20"})}),e.jsx("div",{className:`w-12 h-12 rounded-xl ${g.bg} ring-1 ${g.ring} flex items-center justify-center mb-3 transition-transform duration-200 group-hover:scale-105`,children:e.jsx(w,{className:`w-5 h-5 ${g.text}`})}),e.jsx("span",{className:"text-xs font-semibold text-foreground mb-0.5",children:t.name}),e.jsxs("span",{className:"text-[10px] text-muted-foreground/40 mb-3",children:[t.popularActions.length," action",t.popularActions.length!==1?"s":""]}),t.connected?e.jsxs("div",{className:"flex items-center gap-2 w-full",children:[e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-green-400 font-medium flex-1 justify-center",children:[e.jsx(ie,{className:"w-3 h-3"}),"Connected"]}),e.jsx("button",{onClick:()=>j(t),disabled:T,className:"p-1 text-muted-foreground/30 hover:text-red-400 transition-colors opacity-0 group-hover:opacity-100",title:"Disconnect",children:T?e.jsx(D,{className:"w-3 h-3 animate-spin"}):e.jsx(q,{className:"w-3 h-3"})})]}):e.jsxs("button",{onClick:()=>l(t.id),disabled:S,className:"flex items-center justify-center gap-1.5 w-full px-3 py-1.5 text-[11px] font-medium bg-foreground/[0.06] hover:bg-foreground/10 text-foreground rounded-lg transition-colors disabled:opacity-50",children:[S?e.jsx(D,{className:"w-3 h-3 animate-spin"}):e.jsx(le,{className:"w-3 h-3"}),"Connect"]})]},t.id)})})]})}const at=[{id:"workflows",label:"Workflows",icon:Z},{id:"webhooks",label:"Webhooks",icon:He},{id:"integrations",label:"Integrations",icon:V}];function mt({selectedProject:o}){const[h,b]=s.useState("list"),[N,E]=s.useState("workflows"),[A,C]=s.useState(null),[d,f]=s.useState(0),m=s.useCallback(c=>{C(c),b("editor")},[]),v=s.useCallback(()=>{C(null),b("editor")},[]),l=s.useCallback(()=>{b("list"),E("workflows"),C(null),f(c=>c+1)},[]),j=s.useCallback(()=>{b("list"),C(null)},[]);return h==="editor"?e.jsx("div",{className:"h-full",children:e.jsx(Xe,{workflow:A,onSave:l,onCancel:j})}):e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsx("div",{className:"flex-shrink-0 px-4 pt-4 pb-0",children:e.jsx("div",{className:"flex sm:inline-flex items-center bg-muted/30 rounded-xl p-1 gap-0.5",children:at.map(c=>{const t=c.icon,u=N===c.id;return e.jsxs("button",{onClick:()=>E(c.id),className:`flex items-center gap-1.5 px-3.5 py-2 text-xs font-medium rounded-lg transition-all duration-150 ${u?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:[e.jsx(t,{className:"w-3.5 h-3.5"}),c.label]},c.id)})})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4",children:[N==="workflows"&&e.jsx(ze,{onEdit:m,onCreate:v,refreshKey:d}),N==="webhooks"&&e.jsx(tt,{onWebhooksChange:()=>f(c=>c+1)}),N==="integrations"&&e.jsx(ot,{})]})]})}export{mt as default};