apteva 0.4.53 → 0.4.54
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.
- package/dist/{ActivityPage.sw9p594m.js → ActivityPage.k33hj12v.js} +1 -1
- package/dist/{ApiDocsPage.90e03bz7.js → ApiDocsPage.q37747gr.js} +1 -1
- package/dist/{App.9t1zc5r7.js → App.3hp80jc2.js} +13 -13
- package/dist/{App.pse0pzar.js → App.5ebcd85d.js} +1 -1
- package/dist/{App.p7jjw1zf.js → App.6fefs2d5.js} +1 -1
- package/dist/{App.tm3k7h4b.js → App.794kjn6a.js} +1 -1
- package/dist/{App.ysxy7akk.js → App.c5ebgvec.js} +1 -1
- package/dist/App.cb1np6f0.js +20 -0
- package/dist/{App.jhb45d7r.js → App.ccs4g85x.js} +1 -1
- package/dist/{App.9sryp183.js → App.g1qhcmpc.js} +1 -1
- package/dist/{App.r43t58w6.js → App.jemr4v3a.js} +2 -2
- package/dist/{App.vkg121c6.js → App.kpyf0grm.js} +1 -1
- package/dist/{App.stgng5bx.js → App.p7zc1bv2.js} +1 -1
- package/dist/{App.xva0tfzh.js → App.qx4wdtjg.js} +1 -1
- package/dist/{App.yzkh4gq2.js → App.wjxmwjrp.js} +1 -1
- package/dist/{App.3vnrera5.js → App.wq1f2jke.js} +1 -1
- package/dist/{App.pfbdzrhh.js → App.zx6x0gk2.js} +1 -1
- package/dist/ConnectionsPage.8b2v07qp.js +3 -0
- package/dist/McpPage.3800a82c.js +3 -0
- package/dist/SettingsPage.88nj3hbv.js +3 -0
- package/dist/SkillsPage.b8pxj5mb.js +3 -0
- package/dist/TasksPage.6b3y4b1n.js +3 -0
- package/dist/TelemetryPage.7q4d69wj.js +3 -0
- package/dist/TestsPage.dpevv5xb.js +3 -0
- package/dist/ThreadsPage.1h15363y.js +3 -0
- package/dist/index.html +1 -1
- package/package.json +1 -1
- package/src/mcp-platform.ts +75 -9
- package/src/routes/api/telemetry.ts +0 -7
- package/src/web/components/telemetry/TelemetryPage.tsx +13 -10
- package/src/web/context/TelemetryContext.tsx +4 -1
- package/dist/App.94x6mh7f.js +0 -20
- package/dist/ConnectionsPage.q5f9fd37.js +0 -3
- package/dist/McpPage.f3ccrezb.js +0 -3
- package/dist/SettingsPage.zmzm1pp6.js +0 -3
- package/dist/SkillsPage.whxnez67.js +0 -3
- package/dist/TasksPage.zp4jfevw.js +0 -3
- package/dist/TelemetryPage.an0ky78c.js +0 -3
- package/dist/TestsPage.18krj0d1.js +0 -3
- package/dist/ThreadsPage.nnphgy98.js +0 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{G as x,H as n,I as r,l as m,q as i}from"./App.9sryp183.js";import{O as j}from"./App.vkg121c6.js";import{U as D}from"./App.p7jjw1zf.js";import{$ as t,X as g,aa as u,da as c,ja as V,ma as d}from"./App.94x6mh7f.js";var Q=g(t(),1);var z=g(u(),1);function Zz({onSelectAgent:B}){let{authFetch:N}=V(),{currentProjectId:w}=d(),[L,P]=Q.useState([]),[O,K]=Q.useState(!0),[_,J]=Q.useState("all"),[Z,Y]=Q.useState("all"),[U,W]=Q.useState(null),[R,I]=Q.useState(!1),[$,A]=Q.useState(!1),f=Q.useRef(null),{events:C}=c({category:"TASK"}),v=Q.useCallback(async()=>{try{let G=`/api/tasks?status=${_}`;if(w!==null)G+=`&project_id=${encodeURIComponent(w)}`;let X=await(await N(G)).json();P(X.tasks||[])}catch(G){console.error("Failed to fetch tasks:",G)}finally{K(!1)}},[N,_,w]);Q.useEffect(()=>{v()},[v]),Q.useEffect(()=>{if(!C.length)return;let G=C[0];if(!G||G.id===f.current)return;let H=G.type;if(H==="task_created"||H==="task_updated"||H==="task_deleted")f.current=G.id,console.log("[TasksPage] Telemetry event:",H),v()},[C,v]);let y=Q.useCallback(async(G)=>{W(G),I(!0);try{let H=await N(`/api/tasks/${G.agentId}/${G.id}`);if(console.log("[TasksPage] Fetch task response status:",H.status),H.ok){let X=await H.json();if(console.log("[TasksPage] Task data:",X),console.log("[TasksPage] Has trajectory:",!!X.task?.trajectory,"Length:",X.task?.trajectory?.length),X.task)W({...X.task,agentId:G.agentId,agentName:G.agentName})}else console.error("[TasksPage] Failed to fetch task:",H.status,await H.text())}catch(H){console.error("Failed to fetch task details:",H)}finally{I(!1)}},[N]),b=Q.useMemo(()=>{let G=new Map;for(let H of L){let X=H.agentId||H.agent_id,T=H.agentName||H.agent_name;if(X&&T&&!G.has(X))G.set(X,T)}return Array.from(G.entries()).sort((H,X)=>H[1].localeCompare(X[1]))},[L]),M=Q.useMemo(()=>{return[...Z==="all"?L:L.filter((H)=>(H.agentId||H.agent_id)===Z)].sort((H,X)=>{if(H.status==="running"&&X.status!=="running")return-1;if(X.status==="running"&&H.status!=="running")return 1;let T=H.status==="pending",p=X.status==="pending";if(T&&!p)return-1;if(p&&!T)return 1;if(T&&p||H.status==="running"&&X.status==="running"){let h=H.next_run||H.execute_at||null,l=X.next_run||X.execute_at||null,e=h?new Date(h).getTime():1/0,s=l?new Date(l).getTime():1/0;return e-s}let k=H.completed_at||H.executed_at||H.created_at,a=X.completed_at||X.executed_at||X.created_at;return new Date(a).getTime()-new Date(k).getTime()})},[L,Z]),q={pending:"bg-yellow-500/20 text-yellow-400",running:"bg-blue-500/20 text-blue-400",completed:"bg-green-500/20 text-green-400",failed:"bg-red-500/20 text-red-400",cancelled:"bg-gray-500/20 text-gray-400"};return z.jsxDEV("div",{className:"flex-1 flex overflow-hidden",children:[z.jsxDEV("div",{className:`flex-1 p-4 md:p-6 overflow-auto ${U?"hidden md:block md:w-1/2 lg:w-2/3":""}`,children:z.jsxDEV("div",{className:"max-w-4xl",children:[z.jsxDEV("div",{className:"mb-6",children:[z.jsxDEV("div",{className:"mb-4 flex items-start justify-between",children:[z.jsxDEV("div",{children:[z.jsxDEV("h1",{className:"text-xl md:text-2xl font-semibold mb-1",children:"Tasks"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)]",children:"View tasks from all running agents"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("button",{onClick:()=>A(!0),className:"px-3 py-1.5 rounded text-sm bg-[var(--color-accent)] text-black hover:opacity-90 transition flex items-center gap-1.5 flex-shrink-0",children:[z.jsxDEV("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:z.jsxDEV("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Create Task"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"flex items-center gap-3 flex-wrap pb-1",children:[z.jsxDEV("div",{className:"flex gap-2 overflow-x-auto scrollbar-hide",children:[{value:"all",label:"All"},{value:"pending",label:"Pending"},{value:"running",label:"Running"},{value:"completed",label:"Completed"},{value:"failed",label:"Failed"}].map((G)=>z.jsxDEV("button",{onClick:()=>J(G.value),className:`px-3 py-1.5 rounded text-sm transition whitespace-nowrap ${_===G.value?"bg-[var(--color-accent)] text-black":"bg-[var(--color-surface-raised)] hover:bg-[var(--color-surface-raised)]"}`,children:G.label},G.value,!1,void 0,this))},void 0,!1,void 0,this),b.length>0&&z.jsxDEV("div",{className:"w-48",children:z.jsxDEV(D,{value:Z,onChange:Y,placeholder:"All agents",compact:!0,options:[{value:"all",label:"All agents"},...b.map(([G,H])=>({value:G,label:H}))]},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O?z.jsxDEV("div",{className:"text-center py-12 text-[var(--color-text-muted)]",children:"Loading tasks..."},void 0,!1,void 0,this):M.length===0?z.jsxDEV("div",{className:"text-center py-12",children:[z.jsxDEV(i,{className:"w-12 h-12 mx-auto mb-4 text-[var(--color-border-light)]"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-[var(--color-text-muted)]",children:"No tasks found"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-sm text-[var(--color-text-faint)] mt-1",children:"Tasks will appear here when agents create them"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):z.jsxDEV("div",{className:"space-y-3",children:M.map((G)=>z.jsxDEV("div",{onClick:()=>y(G),className:`bg-[var(--color-surface)] border rounded-lg p-4 cursor-pointer transition ${U?.id===G.id&&U?.agentId===G.agentId?"border-[var(--color-accent)]":"border-[var(--color-border)] hover:border-[var(--color-border-light)]"}`,children:[z.jsxDEV("div",{className:"flex items-start justify-between mb-2",children:[z.jsxDEV("div",{className:"flex-1",children:[z.jsxDEV("h3",{className:"font-medium",children:G.title},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)]",children:G.agentName},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("span",{className:`px-2 py-1 rounded text-xs font-medium ${q[G.status]||q.pending}`,children:G.status},void 0,!1,void 0,this)]},void 0,!0,void 0,this),G.description&&z.jsxDEV("p",{className:"text-sm text-[var(--color-text-secondary)] mb-2 line-clamp-2",children:G.description},void 0,!1,void 0,this),z.jsxDEV("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-[var(--color-text-faint)]",children:[z.jsxDEV("span",{className:"flex items-center gap-1",children:[G.type==="recurring"?z.jsxDEV(x,{className:"w-3.5 h-3.5"},void 0,!1,void 0,this):G.execute_at?z.jsxDEV(n,{className:"w-3.5 h-3.5"},void 0,!1,void 0,this):z.jsxDEV(r,{className:"w-3.5 h-3.5"},void 0,!1,void 0,this),G.type==="recurring"&&G.recurrence?E(G.recurrence):G.type]},void 0,!0,void 0,this),z.jsxDEV("span",{children:["Priority: ",G.priority]},void 0,!0,void 0,this),G.next_run&&z.jsxDEV("span",{className:"text-[var(--color-accent)]",children:F(G.next_run)},void 0,!1,void 0,this),!G.next_run&&G.execute_at&&z.jsxDEV("span",{className:"text-[var(--color-accent)]",children:F(G.execute_at)},void 0,!1,void 0,this),z.jsxDEV("span",{children:["Created: ",new Date(G.created_at).toLocaleDateString()]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},`${G.agentId}-${G.id}`,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),U&&z.jsxDEV(zz,{task:U,statusColors:q,onClose:()=>W(null),onSelectAgent:B,loading:R,authFetch:N,onRefresh:()=>{v(),W(null)}},void 0,!1,void 0,this),$&&z.jsxDEV(Gz,{authFetch:N,currentProjectId:w,onClose:()=>A(!1),onCreated:()=>{v(),A(!1)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function zz({task:B,statusColors:N,onClose:w,onSelectAgent:L,loading:P,authFetch:O,onRefresh:K}){let[_,J]=Q.useState(!1),[Z,Y]=Q.useState(!1),[U,W]=Q.useState(!1),[R,I]=Q.useState(!1),[$,A]=Q.useState({title:B.title,description:B.description||"",type:B.type,priority:B.priority,execute_at:B.execute_at?new Date(B.execute_at).toISOString().slice(0,16):"",recurrence:B.recurrence||""}),{confirm:f,ConfirmDialog:C}=j();Q.useEffect(()=>{A({title:B.title,description:B.description||"",type:B.type,priority:B.priority,execute_at:B.execute_at?new Date(B.execute_at).toISOString().slice(0,16):"",recurrence:B.recurrence||""}),W(!1)},[B.id,B.agentId]);let v=async()=>{if(!O||R)return;I(!0);try{let q={title:$.title.trim(),description:$.description.trim()||void 0,type:$.type,priority:$.priority};if($.type==="once"&&$.execute_at)q.execute_at=new Date($.execute_at).toISOString();if($.type==="recurring"&&$.recurrence.trim())q.recurrence=$.recurrence.trim();if((await O(`/api/tasks/${B.agentId}/${B.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(q)})).ok)W(!1),K?.()}catch(q){console.error("Failed to update task:",q)}finally{I(!1)}},y=async()=>{if(!O||_)return;J(!0);try{await O(`/api/tasks/${B.agentId}/${B.id}/execute`,{method:"POST"}),K?.()}catch(q){console.error("Failed to execute task:",q)}finally{J(!1)}},b=async()=>{if(!O||Z)return;if(!await f(`Are you sure you want to delete "${B.title}"?`,{title:"Delete Task",confirmText:"Delete",confirmVariant:"danger"}))return;Y(!0);try{await O(`/api/tasks/${B.agentId}/${B.id}`,{method:"DELETE"}),K?.()}catch(S){console.error("Failed to delete task:",S)}finally{Y(!1)}},M="w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-2 py-1.5 text-sm focus:outline-none focus:border-[var(--color-accent)] text-[var(--color-text)]";return z.jsxDEV("div",{className:"w-full md:w-1/2 lg:w-1/3 border-l border-[var(--color-border)] bg-[var(--color-bg)] flex flex-col overflow-hidden",children:[C,z.jsxDEV("div",{className:"flex items-center justify-between p-4 border-b border-[var(--color-border)]",children:[z.jsxDEV("h2",{className:"font-medium truncate pr-2",children:U?"Edit Task":"Task Details"},void 0,!1,void 0,this),z.jsxDEV("div",{className:"flex items-center gap-2",children:[O&&!U&&(B.status==="pending"||B.status==="completed"||B.status==="failed")&&z.jsxDEV("button",{onClick:()=>W(!0),title:"Edit task",className:"text-[var(--color-text-muted)] hover:text-[var(--color-accent)] transition",children:z.jsxDEV("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:z.jsxDEV("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O&&!U&&(B.status==="pending"||B.status==="completed")&&z.jsxDEV("button",{onClick:y,disabled:_,title:"Execute now",className:"text-[var(--color-accent)] hover:opacity-80 transition disabled:opacity-50",children:z.jsxDEV("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[z.jsxDEV("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"},void 0,!1,void 0,this),z.jsxDEV("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 12a9 9 0 11-18 0 9 9 0 0118 0z"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),O&&!U&&z.jsxDEV("button",{onClick:b,disabled:Z,title:"Delete task",className:"text-red-400 hover:text-red-300 transition disabled:opacity-50",children:z.jsxDEV("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:z.jsxDEV("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),U&&z.jsxDEV(z.Fragment,{children:[z.jsxDEV("button",{onClick:()=>{W(!1),A({title:B.title,description:B.description||"",type:B.type,priority:B.priority,execute_at:B.execute_at?new Date(B.execute_at).toISOString().slice(0,16):"",recurrence:B.recurrence||""})},className:"text-[var(--color-text-muted)] hover:text-[var(--color-text)] text-sm transition",children:"Cancel"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:v,disabled:R||!$.title.trim(),className:"px-3 py-1 rounded text-sm bg-[var(--color-accent)] text-black hover:opacity-90 transition disabled:opacity-50",children:R?"Saving...":"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!U&&z.jsxDEV("button",{onClick:w,className:"text-[var(--color-text-muted)] hover:text-[var(--color-text)] transition",children:z.jsxDEV(m,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"flex-1 overflow-auto p-4 space-y-4",children:[z.jsxDEV("div",{children:[z.jsxDEV("div",{className:"flex items-start justify-between gap-2 mb-2",children:[U?z.jsxDEV("input",{type:"text",value:$.title,onChange:(q)=>A({...$,title:q.target.value}),className:`${M} text-lg font-medium`,placeholder:"Task title"},void 0,!1,void 0,this):z.jsxDEV("h3",{className:"text-lg font-medium",children:B.title},void 0,!1,void 0,this),!U&&z.jsxDEV("span",{className:`px-2 py-1 rounded text-xs font-medium flex-shrink-0 ${N[B.status]}`,children:B.status},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!U&&z.jsxDEV("button",{onClick:()=>L?.(B.agentId),className:"text-sm text-[var(--color-accent)] hover:underline",children:B.agentName},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U?z.jsxDEV("div",{children:[z.jsxDEV("h4",{className:"text-xs text-[var(--color-text-muted)] uppercase tracking-wider mb-1",children:"Description"},void 0,!1,void 0,this),z.jsxDEV("textarea",{value:$.description,onChange:(q)=>A({...$,description:q.target.value}),className:`${M} resize-none`,rows:3,placeholder:"Task description..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this):B.description?z.jsxDEV("div",{children:[z.jsxDEV("h4",{className:"text-xs text-[var(--color-text-muted)] uppercase tracking-wider mb-1",children:"Description"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-sm text-[var(--color-text-secondary)] whitespace-pre-wrap",children:B.description},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null,U?z.jsxDEV("div",{className:"grid grid-cols-2 gap-3",children:[z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"text-xs text-[var(--color-text-muted)] uppercase tracking-wider mb-1 block",children:"Type"},void 0,!1,void 0,this),z.jsxDEV("select",{value:$.type,onChange:(q)=>A({...$,type:q.target.value}),className:M,children:[z.jsxDEV("option",{value:"once",children:"One-time"},void 0,!1,void 0,this),z.jsxDEV("option",{value:"recurring",children:"Recurring"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"text-xs text-[var(--color-text-muted)] uppercase tracking-wider mb-1 block",children:"Priority"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"number",min:1,max:10,value:$.priority,onChange:(q)=>A({...$,priority:Number(q.target.value)}),className:M},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):z.jsxDEV("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[z.jsxDEV("div",{children:[z.jsxDEV("span",{className:"text-[var(--color-text-muted)]",children:"Type"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"capitalize",children:B.type},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("span",{className:"text-[var(--color-text-muted)]",children:"Priority"},void 0,!1,void 0,this),z.jsxDEV("p",{children:B.priority},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("span",{className:"text-[var(--color-text-muted)]",children:"Source"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"capitalize",children:B.source},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B.recurrence&&z.jsxDEV("div",{children:[z.jsxDEV("span",{className:"text-[var(--color-text-muted)]",children:"Recurrence"},void 0,!1,void 0,this),z.jsxDEV("p",{children:E(B.recurrence)},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-0.5 font-mono",children:B.recurrence},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),U&&$.type==="once"&&z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"text-xs text-[var(--color-text-muted)] uppercase tracking-wider mb-1 block",children:"Schedule"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"datetime-local",value:$.execute_at,onChange:(q)=>A({...$,execute_at:q.target.value}),className:M},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"Leave empty for manual execution"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U&&$.type==="recurring"&&z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"text-xs text-[var(--color-text-muted)] uppercase tracking-wider mb-1 block",children:"Cron Schedule"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:$.recurrence,onChange:(q)=>A({...$,recurrence:q.target.value}),className:`${M} font-mono`,placeholder:"*/30 * * * *"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"e.g. */30 * * * * = every 30 min"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!U&&z.jsxDEV("div",{className:"space-y-2 text-sm",children:[z.jsxDEV("div",{className:"flex justify-between",children:[z.jsxDEV("span",{className:"text-[var(--color-text-muted)]",children:"Created"},void 0,!1,void 0,this),z.jsxDEV("span",{children:new Date(B.created_at).toLocaleString()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B.execute_at&&z.jsxDEV("div",{className:"flex justify-between",children:[z.jsxDEV("span",{className:"text-[var(--color-text-muted)]",children:"Scheduled"},void 0,!1,void 0,this),z.jsxDEV("span",{className:"text-[var(--color-accent)]",children:F(B.execute_at)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B.executed_at&&z.jsxDEV("div",{className:"flex justify-between",children:[z.jsxDEV("span",{className:"text-[var(--color-text-muted)]",children:"Started"},void 0,!1,void 0,this),z.jsxDEV("span",{children:new Date(B.executed_at).toLocaleString()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B.completed_at&&z.jsxDEV("div",{className:"flex justify-between",children:[z.jsxDEV("span",{className:"text-[var(--color-text-muted)]",children:"Completed"},void 0,!1,void 0,this),z.jsxDEV("span",{children:new Date(B.completed_at).toLocaleString()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B.next_run&&z.jsxDEV("div",{className:"flex justify-between",children:[z.jsxDEV("span",{className:"text-[var(--color-text-muted)]",children:"Next Run"},void 0,!1,void 0,this),z.jsxDEV("span",{className:"text-[var(--color-accent)]",children:F(B.next_run)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),B.status==="failed"&&B.error&&z.jsxDEV("div",{className:"min-w-0",children:[z.jsxDEV("h4",{className:"text-xs text-red-400 uppercase tracking-wider mb-1",children:"Error"},void 0,!1,void 0,this),z.jsxDEV("div",{className:"bg-red-500/10 border border-red-500/20 rounded p-3 overflow-x-auto",children:z.jsxDEV("pre",{className:"text-sm text-red-400 whitespace-pre-wrap break-words",children:B.error},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B.status==="completed"&&B.result&&z.jsxDEV("div",{className:"min-w-0",children:[z.jsxDEV("h4",{className:"text-xs text-green-400 uppercase tracking-wider mb-1",children:"Result"},void 0,!1,void 0,this),z.jsxDEV("div",{className:"bg-green-500/10 border border-green-500/20 rounded p-3 overflow-x-auto",children:z.jsxDEV("pre",{className:"text-sm text-green-400 whitespace-pre-wrap break-words",children:typeof B.result==="string"?B.result:JSON.stringify(B.result,null,2)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P&&!B.trajectory&&z.jsxDEV("div",{children:[z.jsxDEV("h4",{className:"text-xs text-[var(--color-text-muted)] uppercase tracking-wider mb-2",children:"Trajectory"},void 0,!1,void 0,this),z.jsxDEV("div",{className:"text-sm text-[var(--color-text-faint)]",children:"Loading trajectory..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B.trajectory&&B.trajectory.length>0&&z.jsxDEV("div",{children:[z.jsxDEV("h4",{className:"text-xs text-[var(--color-text-muted)] uppercase tracking-wider mb-2",children:["Trajectory (",B.trajectory.length," steps)"]},void 0,!0,void 0,this),z.jsxDEV(Bz,{trajectory:B.trajectory},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Bz({trajectory:B}){let[N,w]=Q.useState(new Set),L=(K)=>{w((_)=>{let J=new Set(_);if(J.has(K))J.delete(K);else J.add(K);return J})},P={user:{bg:"bg-blue-500/10",text:"text-blue-400",icon:"\uD83D\uDC64",label:"User"},assistant:{bg:"bg-purple-500/10",text:"text-purple-400",icon:"\uD83E\uDD16",label:"Assistant"}},O=(K)=>{let _=K.content;if(typeof _==="string"){let J=_.length>200,Z=N.has(K.id);return z.jsxDEV("div",{children:[z.jsxDEV("p",{className:`text-sm text-[var(--color-text)] whitespace-pre-wrap break-words ${!Z&&J?"line-clamp-4":""}`,children:_},void 0,!1,void 0,this),J&&z.jsxDEV("button",{onClick:()=>L(K.id),className:"text-xs text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)] mt-1",children:Z?"Show less":"Show more..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}return z.jsxDEV("div",{className:"space-y-2",children:_.map((J,Z)=>{if(J.type==="tool_use"){let Y=JSON.stringify(J.input,null,2),U=Y.length>150,W=`${K.id}-${Z}`,R=N.has(W);return z.jsxDEV("div",{className:"bg-orange-500/10 border border-orange-500/20 rounded p-2",children:[z.jsxDEV("div",{className:"flex items-center gap-2 mb-1",children:[z.jsxDEV("span",{className:"text-orange-400",children:"\uD83D\uDD27"},void 0,!1,void 0,this),z.jsxDEV("span",{className:"text-xs font-medium text-orange-400",children:"Tool Call"},void 0,!1,void 0,this),z.jsxDEV("span",{className:"text-xs text-[var(--color-text-secondary)]",children:J.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("pre",{className:`text-xs text-[var(--color-text-secondary)] overflow-x-auto ${!R&&U?"line-clamp-3":""}`,children:Y},void 0,!1,void 0,this),U&&z.jsxDEV("button",{onClick:()=>L(W),className:"text-xs text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)] mt-1",children:R?"Show less":"Show more..."},void 0,!1,void 0,this)]},Z,!0,void 0,this)}if(J.type==="tool_result"){let Y=J.is_error,U=`${K.id}-${Z}`,W=N.has(U),R=J.content.length>150;return z.jsxDEV("div",{className:`${Y?"bg-red-500/10 border-red-500/20":"bg-teal-500/10 border-teal-500/20"} border rounded p-2`,children:[z.jsxDEV("div",{className:"flex items-center gap-2 mb-1",children:[z.jsxDEV("span",{children:Y?"❌":"\uD83D\uDCCB"},void 0,!1,void 0,this),z.jsxDEV("span",{className:`text-xs font-medium ${Y?"text-red-400":"text-teal-400"}`,children:"Tool Result"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("pre",{className:`text-xs text-[var(--color-text-secondary)] overflow-x-auto whitespace-pre-wrap break-words ${!W&&R?"line-clamp-3":""}`,children:J.content},void 0,!1,void 0,this),R&&z.jsxDEV("button",{onClick:()=>L(U),className:"text-xs text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)] mt-1",children:W?"Show less":"Show more..."},void 0,!1,void 0,this)]},Z,!0,void 0,this)}return null})},void 0,!1,void 0,this)};return z.jsxDEV("div",{className:"space-y-2",children:B.map((K)=>{let _=P[K.role]||P.assistant;return z.jsxDEV("div",{className:`${_.bg} border border-[var(--color-border)] rounded overflow-hidden p-3`,children:[z.jsxDEV("div",{className:"flex items-center gap-2 mb-2",children:[z.jsxDEV("span",{children:_.icon},void 0,!1,void 0,this),z.jsxDEV("span",{className:`text-xs font-medium ${_.text}`,children:_.label},void 0,!1,void 0,this),K.model&&z.jsxDEV("span",{className:"text-xs text-[var(--color-text-faint)]",children:["· ",K.model]},void 0,!0,void 0,this),z.jsxDEV("span",{className:"text-xs text-[var(--color-text-faint)]",children:["· ",new Date(K.created_at).toLocaleTimeString()]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O(K)]},K.id,!0,void 0,this)})},void 0,!1,void 0,this)}function Gz({authFetch:B,currentProjectId:N,onClose:w,onCreated:L}){let[P,O]=Q.useState([]),[K,_]=Q.useState(""),[J,Z]=Q.useState(""),[Y,U]=Q.useState(""),[W,R]=Q.useState("once"),[I,$]=Q.useState(5),[A,f]=Q.useState(""),[C,v]=Q.useState(""),[y,b]=Q.useState(!1),[M,q]=Q.useState("");return Q.useEffect(()=>{B("/api/agents").then((G)=>G.json()).then((G)=>{let H=(G.agents||[]).filter((X)=>X.status==="running"&&X.features?.tasks);if(O(H.map((X)=>({id:X.id,name:X.name}))),H.length===1)_(H[0].id)}).catch(()=>{})},[B]),z.jsxDEV("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:w,children:z.jsxDEV("div",{className:"bg-[var(--color-surface)] card w-full max-w-md",onClick:(G)=>G.stopPropagation(),children:[z.jsxDEV("div",{className:"flex items-center justify-between p-4 border-b border-[var(--color-border)]",children:[z.jsxDEV("h2",{className:"font-medium",children:"Create Task"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:w,className:"text-[var(--color-text-muted)] hover:text-[var(--color-text)] transition",children:z.jsxDEV(m,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("form",{onSubmit:async(G)=>{if(G.preventDefault(),!K||!J.trim())return;b(!0),q("");let H={title:J.trim(),description:Y.trim()||void 0,type:W,priority:I};if(W==="once"&&A)H.execute_at=new Date(A).toISOString();if(W==="recurring"&&C.trim())H.recurrence=C.trim();try{let X=await B(`/api/tasks/${K}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(H)});if(!X.ok){let T=await X.json().catch(()=>({}));q(T.error||`HTTP ${X.status}`);return}L()}catch(X){q(String(X))}finally{b(!1)}},className:"p-4 space-y-4",children:[z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Agent"},void 0,!1,void 0,this),P.length===0?z.jsxDEV("p",{className:"text-sm text-[var(--color-text-faint)]",children:"No running agents with tasks enabled"},void 0,!1,void 0,this):z.jsxDEV("select",{value:K,onChange:(G)=>_(G.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border)] rounded px-3 py-2 text-sm",required:!0,children:[z.jsxDEV("option",{value:"",children:"Select agent..."},void 0,!1,void 0,this),P.map((G)=>z.jsxDEV("option",{value:G.id,children:G.name},G.id,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Title"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:J,onChange:(G)=>Z(G.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border)] rounded px-3 py-2 text-sm",placeholder:"e.g. Check email for new orders",required:!0},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Description"},void 0,!1,void 0,this),z.jsxDEV("textarea",{value:Y,onChange:(G)=>U(G.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border)] rounded px-3 py-2 text-sm resize-none",rows:2,placeholder:"Optional instructions for the agent..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"grid grid-cols-2 gap-3",children:[z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Type"},void 0,!1,void 0,this),z.jsxDEV("select",{value:W,onChange:(G)=>R(G.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border)] rounded px-3 py-2 text-sm",children:[z.jsxDEV("option",{value:"once",children:"One-time"},void 0,!1,void 0,this),z.jsxDEV("option",{value:"recurring",children:"Recurring"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Priority"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"number",min:1,max:10,value:I,onChange:(G)=>$(Number(G.target.value)),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border)] rounded px-3 py-2 text-sm"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),W==="once"&&z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Schedule (optional)"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"datetime-local",value:A,onChange:(G)=>f(G.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border)] rounded px-3 py-2 text-sm"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"Leave empty to execute immediately"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),W==="recurring"&&z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Cron Schedule"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:C,onChange:(G)=>v(G.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border)] rounded px-3 py-2 text-sm font-mono",placeholder:"*/30 * * * *",required:!0},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"e.g. */30 * * * * = every 30 min, 0 9 * * 1-5 = weekdays at 9am"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),M&&z.jsxDEV("p",{className:"text-sm text-red-400",children:M},void 0,!1,void 0,this),z.jsxDEV("div",{className:"flex justify-end gap-2 pt-2",children:[z.jsxDEV("button",{type:"button",onClick:w,className:"px-4 py-2 rounded text-sm bg-[var(--color-surface-raised)] hover:bg-[var(--color-border)] transition",children:"Cancel"},void 0,!1,void 0,this),z.jsxDEV("button",{type:"submit",disabled:y||!K||!J.trim()||P.length===0,className:"px-4 py-2 rounded text-sm bg-[var(--color-accent)] text-black hover:opacity-90 transition disabled:opacity-50",children:y?"Creating...":"Create Task"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var o=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function E(B){try{let N=B.trim().split(/\s+/);if(N.length!==5)return B;let[w,L,P,O,K]=N;if(w.startsWith("*/")&&L==="*"&&P==="*"&&O==="*"&&K==="*"){let J=parseInt(w.slice(2));if(J===1)return"Every minute";return`Every ${J} minutes`}if(w!=="*"&&!w.includes("/")&&L==="*"&&P==="*"&&O==="*"&&K==="*")return"Every hour";if(L.startsWith("*/")&&P==="*"&&O==="*"&&K==="*"){let J=parseInt(L.slice(2));if(J===1)return"Every hour";return`Every ${J} hours`}let _=(J,Z)=>{let Y=parseInt(J),U=parseInt(Z);if(isNaN(Y))return"";let W=Y>=12?"PM":"AM";return`${Y===0?12:Y>12?Y-12:Y}:${U.toString().padStart(2,"0")} ${W}`};if(L!=="*"&&!L.includes("/")&&P==="*"&&O==="*"){let J=_(L,w);if(K==="*")return`Daily at ${J}`;let Z=K.split(",").map((Y)=>{let U=parseInt(Y.trim());return o[U]||Y});if(Z.length===7)return`Daily at ${J}`;if(Z.length===5&&!Z.includes("Sat")&&!Z.includes("Sun"))return`Weekdays at ${J}`;if(Z.length===1)return`Weekly on ${Z[0]} at ${J}`;return`${Z.join(" & ")} at ${J}`}return B}catch{return B}}function F(B){let N=new Date(B),w=new Date,L=N.getTime()-w.getTime(),P=Math.abs(L),O=L>0,K=Math.floor(P/60000),_=Math.floor(P/3600000),J=Math.floor(P/86400000),Z=N.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}),Y=N.toDateString()===w.toDateString(),U=new Date(w);U.setDate(U.getDate()+1);let W=N.toDateString()===U.toDateString(),R=new Date(w);R.setDate(R.getDate()-1);let I=N.toDateString()===R.toDateString();if(Y){if(K<1)return O?"now":"just now";if(K<60)return O?`in ${K} min (${Z})`:`${K} min ago`;return O?`in ${_}h (${Z})`:`${_}h ago`}if(W)return`Tomorrow at ${Z}`;if(I)return`Yesterday at ${Z}`;if(J<7)return`${o[N.getDay()]} at ${Z}`;return N.toLocaleDateString([],{month:"short",day:"numeric"})+` at ${Z}`}
|
|
1
|
+
import{G as x,H as n,I as r,l as m,q as i}from"./App.g1qhcmpc.js";import{O as j}from"./App.kpyf0grm.js";import{U as D}from"./App.6fefs2d5.js";import{$ as t,X as g,aa as u,da as c,ja as V,ma as d}from"./App.cb1np6f0.js";var Q=g(t(),1);var z=g(u(),1);function Zz({onSelectAgent:B}){let{authFetch:N}=V(),{currentProjectId:w}=d(),[L,P]=Q.useState([]),[O,K]=Q.useState(!0),[_,J]=Q.useState("all"),[Z,Y]=Q.useState("all"),[U,W]=Q.useState(null),[R,I]=Q.useState(!1),[$,A]=Q.useState(!1),f=Q.useRef(null),{events:C}=c({category:"TASK"}),v=Q.useCallback(async()=>{try{let G=`/api/tasks?status=${_}`;if(w!==null)G+=`&project_id=${encodeURIComponent(w)}`;let X=await(await N(G)).json();P(X.tasks||[])}catch(G){console.error("Failed to fetch tasks:",G)}finally{K(!1)}},[N,_,w]);Q.useEffect(()=>{v()},[v]),Q.useEffect(()=>{if(!C.length)return;let G=C[0];if(!G||G.id===f.current)return;let H=G.type;if(H==="task_created"||H==="task_updated"||H==="task_deleted")f.current=G.id,console.log("[TasksPage] Telemetry event:",H),v()},[C,v]);let y=Q.useCallback(async(G)=>{W(G),I(!0);try{let H=await N(`/api/tasks/${G.agentId}/${G.id}`);if(console.log("[TasksPage] Fetch task response status:",H.status),H.ok){let X=await H.json();if(console.log("[TasksPage] Task data:",X),console.log("[TasksPage] Has trajectory:",!!X.task?.trajectory,"Length:",X.task?.trajectory?.length),X.task)W({...X.task,agentId:G.agentId,agentName:G.agentName})}else console.error("[TasksPage] Failed to fetch task:",H.status,await H.text())}catch(H){console.error("Failed to fetch task details:",H)}finally{I(!1)}},[N]),b=Q.useMemo(()=>{let G=new Map;for(let H of L){let X=H.agentId||H.agent_id,T=H.agentName||H.agent_name;if(X&&T&&!G.has(X))G.set(X,T)}return Array.from(G.entries()).sort((H,X)=>H[1].localeCompare(X[1]))},[L]),M=Q.useMemo(()=>{return[...Z==="all"?L:L.filter((H)=>(H.agentId||H.agent_id)===Z)].sort((H,X)=>{if(H.status==="running"&&X.status!=="running")return-1;if(X.status==="running"&&H.status!=="running")return 1;let T=H.status==="pending",p=X.status==="pending";if(T&&!p)return-1;if(p&&!T)return 1;if(T&&p||H.status==="running"&&X.status==="running"){let h=H.next_run||H.execute_at||null,l=X.next_run||X.execute_at||null,e=h?new Date(h).getTime():1/0,s=l?new Date(l).getTime():1/0;return e-s}let k=H.completed_at||H.executed_at||H.created_at,a=X.completed_at||X.executed_at||X.created_at;return new Date(a).getTime()-new Date(k).getTime()})},[L,Z]),q={pending:"bg-yellow-500/20 text-yellow-400",running:"bg-blue-500/20 text-blue-400",completed:"bg-green-500/20 text-green-400",failed:"bg-red-500/20 text-red-400",cancelled:"bg-gray-500/20 text-gray-400"};return z.jsxDEV("div",{className:"flex-1 flex overflow-hidden",children:[z.jsxDEV("div",{className:`flex-1 p-4 md:p-6 overflow-auto ${U?"hidden md:block md:w-1/2 lg:w-2/3":""}`,children:z.jsxDEV("div",{className:"max-w-4xl",children:[z.jsxDEV("div",{className:"mb-6",children:[z.jsxDEV("div",{className:"mb-4 flex items-start justify-between",children:[z.jsxDEV("div",{children:[z.jsxDEV("h1",{className:"text-xl md:text-2xl font-semibold mb-1",children:"Tasks"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)]",children:"View tasks from all running agents"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("button",{onClick:()=>A(!0),className:"px-3 py-1.5 rounded text-sm bg-[var(--color-accent)] text-black hover:opacity-90 transition flex items-center gap-1.5 flex-shrink-0",children:[z.jsxDEV("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:z.jsxDEV("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Create Task"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"flex items-center gap-3 flex-wrap pb-1",children:[z.jsxDEV("div",{className:"flex gap-2 overflow-x-auto scrollbar-hide",children:[{value:"all",label:"All"},{value:"pending",label:"Pending"},{value:"running",label:"Running"},{value:"completed",label:"Completed"},{value:"failed",label:"Failed"}].map((G)=>z.jsxDEV("button",{onClick:()=>J(G.value),className:`px-3 py-1.5 rounded text-sm transition whitespace-nowrap ${_===G.value?"bg-[var(--color-accent)] text-black":"bg-[var(--color-surface-raised)] hover:bg-[var(--color-surface-raised)]"}`,children:G.label},G.value,!1,void 0,this))},void 0,!1,void 0,this),b.length>0&&z.jsxDEV("div",{className:"w-48",children:z.jsxDEV(D,{value:Z,onChange:Y,placeholder:"All agents",compact:!0,options:[{value:"all",label:"All agents"},...b.map(([G,H])=>({value:G,label:H}))]},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O?z.jsxDEV("div",{className:"text-center py-12 text-[var(--color-text-muted)]",children:"Loading tasks..."},void 0,!1,void 0,this):M.length===0?z.jsxDEV("div",{className:"text-center py-12",children:[z.jsxDEV(i,{className:"w-12 h-12 mx-auto mb-4 text-[var(--color-border-light)]"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-[var(--color-text-muted)]",children:"No tasks found"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-sm text-[var(--color-text-faint)] mt-1",children:"Tasks will appear here when agents create them"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):z.jsxDEV("div",{className:"space-y-3",children:M.map((G)=>z.jsxDEV("div",{onClick:()=>y(G),className:`bg-[var(--color-surface)] border rounded-lg p-4 cursor-pointer transition ${U?.id===G.id&&U?.agentId===G.agentId?"border-[var(--color-accent)]":"border-[var(--color-border)] hover:border-[var(--color-border-light)]"}`,children:[z.jsxDEV("div",{className:"flex items-start justify-between mb-2",children:[z.jsxDEV("div",{className:"flex-1",children:[z.jsxDEV("h3",{className:"font-medium",children:G.title},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)]",children:G.agentName},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("span",{className:`px-2 py-1 rounded text-xs font-medium ${q[G.status]||q.pending}`,children:G.status},void 0,!1,void 0,this)]},void 0,!0,void 0,this),G.description&&z.jsxDEV("p",{className:"text-sm text-[var(--color-text-secondary)] mb-2 line-clamp-2",children:G.description},void 0,!1,void 0,this),z.jsxDEV("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-[var(--color-text-faint)]",children:[z.jsxDEV("span",{className:"flex items-center gap-1",children:[G.type==="recurring"?z.jsxDEV(x,{className:"w-3.5 h-3.5"},void 0,!1,void 0,this):G.execute_at?z.jsxDEV(n,{className:"w-3.5 h-3.5"},void 0,!1,void 0,this):z.jsxDEV(r,{className:"w-3.5 h-3.5"},void 0,!1,void 0,this),G.type==="recurring"&&G.recurrence?E(G.recurrence):G.type]},void 0,!0,void 0,this),z.jsxDEV("span",{children:["Priority: ",G.priority]},void 0,!0,void 0,this),G.next_run&&z.jsxDEV("span",{className:"text-[var(--color-accent)]",children:F(G.next_run)},void 0,!1,void 0,this),!G.next_run&&G.execute_at&&z.jsxDEV("span",{className:"text-[var(--color-accent)]",children:F(G.execute_at)},void 0,!1,void 0,this),z.jsxDEV("span",{children:["Created: ",new Date(G.created_at).toLocaleDateString()]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},`${G.agentId}-${G.id}`,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),U&&z.jsxDEV(zz,{task:U,statusColors:q,onClose:()=>W(null),onSelectAgent:B,loading:R,authFetch:N,onRefresh:()=>{v(),W(null)}},void 0,!1,void 0,this),$&&z.jsxDEV(Gz,{authFetch:N,currentProjectId:w,onClose:()=>A(!1),onCreated:()=>{v(),A(!1)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function zz({task:B,statusColors:N,onClose:w,onSelectAgent:L,loading:P,authFetch:O,onRefresh:K}){let[_,J]=Q.useState(!1),[Z,Y]=Q.useState(!1),[U,W]=Q.useState(!1),[R,I]=Q.useState(!1),[$,A]=Q.useState({title:B.title,description:B.description||"",type:B.type,priority:B.priority,execute_at:B.execute_at?new Date(B.execute_at).toISOString().slice(0,16):"",recurrence:B.recurrence||""}),{confirm:f,ConfirmDialog:C}=j();Q.useEffect(()=>{A({title:B.title,description:B.description||"",type:B.type,priority:B.priority,execute_at:B.execute_at?new Date(B.execute_at).toISOString().slice(0,16):"",recurrence:B.recurrence||""}),W(!1)},[B.id,B.agentId]);let v=async()=>{if(!O||R)return;I(!0);try{let q={title:$.title.trim(),description:$.description.trim()||void 0,type:$.type,priority:$.priority};if($.type==="once"&&$.execute_at)q.execute_at=new Date($.execute_at).toISOString();if($.type==="recurring"&&$.recurrence.trim())q.recurrence=$.recurrence.trim();if((await O(`/api/tasks/${B.agentId}/${B.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(q)})).ok)W(!1),K?.()}catch(q){console.error("Failed to update task:",q)}finally{I(!1)}},y=async()=>{if(!O||_)return;J(!0);try{await O(`/api/tasks/${B.agentId}/${B.id}/execute`,{method:"POST"}),K?.()}catch(q){console.error("Failed to execute task:",q)}finally{J(!1)}},b=async()=>{if(!O||Z)return;if(!await f(`Are you sure you want to delete "${B.title}"?`,{title:"Delete Task",confirmText:"Delete",confirmVariant:"danger"}))return;Y(!0);try{await O(`/api/tasks/${B.agentId}/${B.id}`,{method:"DELETE"}),K?.()}catch(S){console.error("Failed to delete task:",S)}finally{Y(!1)}},M="w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-2 py-1.5 text-sm focus:outline-none focus:border-[var(--color-accent)] text-[var(--color-text)]";return z.jsxDEV("div",{className:"w-full md:w-1/2 lg:w-1/3 border-l border-[var(--color-border)] bg-[var(--color-bg)] flex flex-col overflow-hidden",children:[C,z.jsxDEV("div",{className:"flex items-center justify-between p-4 border-b border-[var(--color-border)]",children:[z.jsxDEV("h2",{className:"font-medium truncate pr-2",children:U?"Edit Task":"Task Details"},void 0,!1,void 0,this),z.jsxDEV("div",{className:"flex items-center gap-2",children:[O&&!U&&(B.status==="pending"||B.status==="completed"||B.status==="failed")&&z.jsxDEV("button",{onClick:()=>W(!0),title:"Edit task",className:"text-[var(--color-text-muted)] hover:text-[var(--color-accent)] transition",children:z.jsxDEV("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:z.jsxDEV("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O&&!U&&(B.status==="pending"||B.status==="completed")&&z.jsxDEV("button",{onClick:y,disabled:_,title:"Execute now",className:"text-[var(--color-accent)] hover:opacity-80 transition disabled:opacity-50",children:z.jsxDEV("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[z.jsxDEV("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"},void 0,!1,void 0,this),z.jsxDEV("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 12a9 9 0 11-18 0 9 9 0 0118 0z"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),O&&!U&&z.jsxDEV("button",{onClick:b,disabled:Z,title:"Delete task",className:"text-red-400 hover:text-red-300 transition disabled:opacity-50",children:z.jsxDEV("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:z.jsxDEV("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),U&&z.jsxDEV(z.Fragment,{children:[z.jsxDEV("button",{onClick:()=>{W(!1),A({title:B.title,description:B.description||"",type:B.type,priority:B.priority,execute_at:B.execute_at?new Date(B.execute_at).toISOString().slice(0,16):"",recurrence:B.recurrence||""})},className:"text-[var(--color-text-muted)] hover:text-[var(--color-text)] text-sm transition",children:"Cancel"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:v,disabled:R||!$.title.trim(),className:"px-3 py-1 rounded text-sm bg-[var(--color-accent)] text-black hover:opacity-90 transition disabled:opacity-50",children:R?"Saving...":"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!U&&z.jsxDEV("button",{onClick:w,className:"text-[var(--color-text-muted)] hover:text-[var(--color-text)] transition",children:z.jsxDEV(m,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"flex-1 overflow-auto p-4 space-y-4",children:[z.jsxDEV("div",{children:[z.jsxDEV("div",{className:"flex items-start justify-between gap-2 mb-2",children:[U?z.jsxDEV("input",{type:"text",value:$.title,onChange:(q)=>A({...$,title:q.target.value}),className:`${M} text-lg font-medium`,placeholder:"Task title"},void 0,!1,void 0,this):z.jsxDEV("h3",{className:"text-lg font-medium",children:B.title},void 0,!1,void 0,this),!U&&z.jsxDEV("span",{className:`px-2 py-1 rounded text-xs font-medium flex-shrink-0 ${N[B.status]}`,children:B.status},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!U&&z.jsxDEV("button",{onClick:()=>L?.(B.agentId),className:"text-sm text-[var(--color-accent)] hover:underline",children:B.agentName},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U?z.jsxDEV("div",{children:[z.jsxDEV("h4",{className:"text-xs text-[var(--color-text-muted)] uppercase tracking-wider mb-1",children:"Description"},void 0,!1,void 0,this),z.jsxDEV("textarea",{value:$.description,onChange:(q)=>A({...$,description:q.target.value}),className:`${M} resize-none`,rows:3,placeholder:"Task description..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this):B.description?z.jsxDEV("div",{children:[z.jsxDEV("h4",{className:"text-xs text-[var(--color-text-muted)] uppercase tracking-wider mb-1",children:"Description"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-sm text-[var(--color-text-secondary)] whitespace-pre-wrap",children:B.description},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null,U?z.jsxDEV("div",{className:"grid grid-cols-2 gap-3",children:[z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"text-xs text-[var(--color-text-muted)] uppercase tracking-wider mb-1 block",children:"Type"},void 0,!1,void 0,this),z.jsxDEV("select",{value:$.type,onChange:(q)=>A({...$,type:q.target.value}),className:M,children:[z.jsxDEV("option",{value:"once",children:"One-time"},void 0,!1,void 0,this),z.jsxDEV("option",{value:"recurring",children:"Recurring"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"text-xs text-[var(--color-text-muted)] uppercase tracking-wider mb-1 block",children:"Priority"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"number",min:1,max:10,value:$.priority,onChange:(q)=>A({...$,priority:Number(q.target.value)}),className:M},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):z.jsxDEV("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[z.jsxDEV("div",{children:[z.jsxDEV("span",{className:"text-[var(--color-text-muted)]",children:"Type"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"capitalize",children:B.type},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("span",{className:"text-[var(--color-text-muted)]",children:"Priority"},void 0,!1,void 0,this),z.jsxDEV("p",{children:B.priority},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("span",{className:"text-[var(--color-text-muted)]",children:"Source"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"capitalize",children:B.source},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B.recurrence&&z.jsxDEV("div",{children:[z.jsxDEV("span",{className:"text-[var(--color-text-muted)]",children:"Recurrence"},void 0,!1,void 0,this),z.jsxDEV("p",{children:E(B.recurrence)},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-0.5 font-mono",children:B.recurrence},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),U&&$.type==="once"&&z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"text-xs text-[var(--color-text-muted)] uppercase tracking-wider mb-1 block",children:"Schedule"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"datetime-local",value:$.execute_at,onChange:(q)=>A({...$,execute_at:q.target.value}),className:M},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"Leave empty for manual execution"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U&&$.type==="recurring"&&z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"text-xs text-[var(--color-text-muted)] uppercase tracking-wider mb-1 block",children:"Cron Schedule"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:$.recurrence,onChange:(q)=>A({...$,recurrence:q.target.value}),className:`${M} font-mono`,placeholder:"*/30 * * * *"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"e.g. */30 * * * * = every 30 min"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!U&&z.jsxDEV("div",{className:"space-y-2 text-sm",children:[z.jsxDEV("div",{className:"flex justify-between",children:[z.jsxDEV("span",{className:"text-[var(--color-text-muted)]",children:"Created"},void 0,!1,void 0,this),z.jsxDEV("span",{children:new Date(B.created_at).toLocaleString()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B.execute_at&&z.jsxDEV("div",{className:"flex justify-between",children:[z.jsxDEV("span",{className:"text-[var(--color-text-muted)]",children:"Scheduled"},void 0,!1,void 0,this),z.jsxDEV("span",{className:"text-[var(--color-accent)]",children:F(B.execute_at)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B.executed_at&&z.jsxDEV("div",{className:"flex justify-between",children:[z.jsxDEV("span",{className:"text-[var(--color-text-muted)]",children:"Started"},void 0,!1,void 0,this),z.jsxDEV("span",{children:new Date(B.executed_at).toLocaleString()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B.completed_at&&z.jsxDEV("div",{className:"flex justify-between",children:[z.jsxDEV("span",{className:"text-[var(--color-text-muted)]",children:"Completed"},void 0,!1,void 0,this),z.jsxDEV("span",{children:new Date(B.completed_at).toLocaleString()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B.next_run&&z.jsxDEV("div",{className:"flex justify-between",children:[z.jsxDEV("span",{className:"text-[var(--color-text-muted)]",children:"Next Run"},void 0,!1,void 0,this),z.jsxDEV("span",{className:"text-[var(--color-accent)]",children:F(B.next_run)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),B.status==="failed"&&B.error&&z.jsxDEV("div",{className:"min-w-0",children:[z.jsxDEV("h4",{className:"text-xs text-red-400 uppercase tracking-wider mb-1",children:"Error"},void 0,!1,void 0,this),z.jsxDEV("div",{className:"bg-red-500/10 border border-red-500/20 rounded p-3 overflow-x-auto",children:z.jsxDEV("pre",{className:"text-sm text-red-400 whitespace-pre-wrap break-words",children:B.error},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B.status==="completed"&&B.result&&z.jsxDEV("div",{className:"min-w-0",children:[z.jsxDEV("h4",{className:"text-xs text-green-400 uppercase tracking-wider mb-1",children:"Result"},void 0,!1,void 0,this),z.jsxDEV("div",{className:"bg-green-500/10 border border-green-500/20 rounded p-3 overflow-x-auto",children:z.jsxDEV("pre",{className:"text-sm text-green-400 whitespace-pre-wrap break-words",children:typeof B.result==="string"?B.result:JSON.stringify(B.result,null,2)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P&&!B.trajectory&&z.jsxDEV("div",{children:[z.jsxDEV("h4",{className:"text-xs text-[var(--color-text-muted)] uppercase tracking-wider mb-2",children:"Trajectory"},void 0,!1,void 0,this),z.jsxDEV("div",{className:"text-sm text-[var(--color-text-faint)]",children:"Loading trajectory..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B.trajectory&&B.trajectory.length>0&&z.jsxDEV("div",{children:[z.jsxDEV("h4",{className:"text-xs text-[var(--color-text-muted)] uppercase tracking-wider mb-2",children:["Trajectory (",B.trajectory.length," steps)"]},void 0,!0,void 0,this),z.jsxDEV(Bz,{trajectory:B.trajectory},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Bz({trajectory:B}){let[N,w]=Q.useState(new Set),L=(K)=>{w((_)=>{let J=new Set(_);if(J.has(K))J.delete(K);else J.add(K);return J})},P={user:{bg:"bg-blue-500/10",text:"text-blue-400",icon:"\uD83D\uDC64",label:"User"},assistant:{bg:"bg-purple-500/10",text:"text-purple-400",icon:"\uD83E\uDD16",label:"Assistant"}},O=(K)=>{let _=K.content;if(typeof _==="string"){let J=_.length>200,Z=N.has(K.id);return z.jsxDEV("div",{children:[z.jsxDEV("p",{className:`text-sm text-[var(--color-text)] whitespace-pre-wrap break-words ${!Z&&J?"line-clamp-4":""}`,children:_},void 0,!1,void 0,this),J&&z.jsxDEV("button",{onClick:()=>L(K.id),className:"text-xs text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)] mt-1",children:Z?"Show less":"Show more..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}return z.jsxDEV("div",{className:"space-y-2",children:_.map((J,Z)=>{if(J.type==="tool_use"){let Y=JSON.stringify(J.input,null,2),U=Y.length>150,W=`${K.id}-${Z}`,R=N.has(W);return z.jsxDEV("div",{className:"bg-orange-500/10 border border-orange-500/20 rounded p-2",children:[z.jsxDEV("div",{className:"flex items-center gap-2 mb-1",children:[z.jsxDEV("span",{className:"text-orange-400",children:"\uD83D\uDD27"},void 0,!1,void 0,this),z.jsxDEV("span",{className:"text-xs font-medium text-orange-400",children:"Tool Call"},void 0,!1,void 0,this),z.jsxDEV("span",{className:"text-xs text-[var(--color-text-secondary)]",children:J.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("pre",{className:`text-xs text-[var(--color-text-secondary)] overflow-x-auto ${!R&&U?"line-clamp-3":""}`,children:Y},void 0,!1,void 0,this),U&&z.jsxDEV("button",{onClick:()=>L(W),className:"text-xs text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)] mt-1",children:R?"Show less":"Show more..."},void 0,!1,void 0,this)]},Z,!0,void 0,this)}if(J.type==="tool_result"){let Y=J.is_error,U=`${K.id}-${Z}`,W=N.has(U),R=J.content.length>150;return z.jsxDEV("div",{className:`${Y?"bg-red-500/10 border-red-500/20":"bg-teal-500/10 border-teal-500/20"} border rounded p-2`,children:[z.jsxDEV("div",{className:"flex items-center gap-2 mb-1",children:[z.jsxDEV("span",{children:Y?"❌":"\uD83D\uDCCB"},void 0,!1,void 0,this),z.jsxDEV("span",{className:`text-xs font-medium ${Y?"text-red-400":"text-teal-400"}`,children:"Tool Result"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("pre",{className:`text-xs text-[var(--color-text-secondary)] overflow-x-auto whitespace-pre-wrap break-words ${!W&&R?"line-clamp-3":""}`,children:J.content},void 0,!1,void 0,this),R&&z.jsxDEV("button",{onClick:()=>L(U),className:"text-xs text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)] mt-1",children:W?"Show less":"Show more..."},void 0,!1,void 0,this)]},Z,!0,void 0,this)}return null})},void 0,!1,void 0,this)};return z.jsxDEV("div",{className:"space-y-2",children:B.map((K)=>{let _=P[K.role]||P.assistant;return z.jsxDEV("div",{className:`${_.bg} border border-[var(--color-border)] rounded overflow-hidden p-3`,children:[z.jsxDEV("div",{className:"flex items-center gap-2 mb-2",children:[z.jsxDEV("span",{children:_.icon},void 0,!1,void 0,this),z.jsxDEV("span",{className:`text-xs font-medium ${_.text}`,children:_.label},void 0,!1,void 0,this),K.model&&z.jsxDEV("span",{className:"text-xs text-[var(--color-text-faint)]",children:["· ",K.model]},void 0,!0,void 0,this),z.jsxDEV("span",{className:"text-xs text-[var(--color-text-faint)]",children:["· ",new Date(K.created_at).toLocaleTimeString()]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O(K)]},K.id,!0,void 0,this)})},void 0,!1,void 0,this)}function Gz({authFetch:B,currentProjectId:N,onClose:w,onCreated:L}){let[P,O]=Q.useState([]),[K,_]=Q.useState(""),[J,Z]=Q.useState(""),[Y,U]=Q.useState(""),[W,R]=Q.useState("once"),[I,$]=Q.useState(5),[A,f]=Q.useState(""),[C,v]=Q.useState(""),[y,b]=Q.useState(!1),[M,q]=Q.useState("");return Q.useEffect(()=>{B("/api/agents").then((G)=>G.json()).then((G)=>{let H=(G.agents||[]).filter((X)=>X.status==="running"&&X.features?.tasks);if(O(H.map((X)=>({id:X.id,name:X.name}))),H.length===1)_(H[0].id)}).catch(()=>{})},[B]),z.jsxDEV("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:w,children:z.jsxDEV("div",{className:"bg-[var(--color-surface)] card w-full max-w-md",onClick:(G)=>G.stopPropagation(),children:[z.jsxDEV("div",{className:"flex items-center justify-between p-4 border-b border-[var(--color-border)]",children:[z.jsxDEV("h2",{className:"font-medium",children:"Create Task"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:w,className:"text-[var(--color-text-muted)] hover:text-[var(--color-text)] transition",children:z.jsxDEV(m,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("form",{onSubmit:async(G)=>{if(G.preventDefault(),!K||!J.trim())return;b(!0),q("");let H={title:J.trim(),description:Y.trim()||void 0,type:W,priority:I};if(W==="once"&&A)H.execute_at=new Date(A).toISOString();if(W==="recurring"&&C.trim())H.recurrence=C.trim();try{let X=await B(`/api/tasks/${K}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(H)});if(!X.ok){let T=await X.json().catch(()=>({}));q(T.error||`HTTP ${X.status}`);return}L()}catch(X){q(String(X))}finally{b(!1)}},className:"p-4 space-y-4",children:[z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Agent"},void 0,!1,void 0,this),P.length===0?z.jsxDEV("p",{className:"text-sm text-[var(--color-text-faint)]",children:"No running agents with tasks enabled"},void 0,!1,void 0,this):z.jsxDEV("select",{value:K,onChange:(G)=>_(G.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border)] rounded px-3 py-2 text-sm",required:!0,children:[z.jsxDEV("option",{value:"",children:"Select agent..."},void 0,!1,void 0,this),P.map((G)=>z.jsxDEV("option",{value:G.id,children:G.name},G.id,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Title"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:J,onChange:(G)=>Z(G.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border)] rounded px-3 py-2 text-sm",placeholder:"e.g. Check email for new orders",required:!0},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Description"},void 0,!1,void 0,this),z.jsxDEV("textarea",{value:Y,onChange:(G)=>U(G.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border)] rounded px-3 py-2 text-sm resize-none",rows:2,placeholder:"Optional instructions for the agent..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"grid grid-cols-2 gap-3",children:[z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Type"},void 0,!1,void 0,this),z.jsxDEV("select",{value:W,onChange:(G)=>R(G.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border)] rounded px-3 py-2 text-sm",children:[z.jsxDEV("option",{value:"once",children:"One-time"},void 0,!1,void 0,this),z.jsxDEV("option",{value:"recurring",children:"Recurring"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Priority"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"number",min:1,max:10,value:I,onChange:(G)=>$(Number(G.target.value)),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border)] rounded px-3 py-2 text-sm"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),W==="once"&&z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Schedule (optional)"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"datetime-local",value:A,onChange:(G)=>f(G.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border)] rounded px-3 py-2 text-sm"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"Leave empty to execute immediately"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),W==="recurring"&&z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Cron Schedule"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:C,onChange:(G)=>v(G.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border)] rounded px-3 py-2 text-sm font-mono",placeholder:"*/30 * * * *",required:!0},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"e.g. */30 * * * * = every 30 min, 0 9 * * 1-5 = weekdays at 9am"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),M&&z.jsxDEV("p",{className:"text-sm text-red-400",children:M},void 0,!1,void 0,this),z.jsxDEV("div",{className:"flex justify-end gap-2 pt-2",children:[z.jsxDEV("button",{type:"button",onClick:w,className:"px-4 py-2 rounded text-sm bg-[var(--color-surface-raised)] hover:bg-[var(--color-border)] transition",children:"Cancel"},void 0,!1,void 0,this),z.jsxDEV("button",{type:"submit",disabled:y||!K||!J.trim()||P.length===0,className:"px-4 py-2 rounded text-sm bg-[var(--color-accent)] text-black hover:opacity-90 transition disabled:opacity-50",children:y?"Creating...":"Create Task"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var o=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function E(B){try{let N=B.trim().split(/\s+/);if(N.length!==5)return B;let[w,L,P,O,K]=N;if(w.startsWith("*/")&&L==="*"&&P==="*"&&O==="*"&&K==="*"){let J=parseInt(w.slice(2));if(J===1)return"Every minute";return`Every ${J} minutes`}if(w!=="*"&&!w.includes("/")&&L==="*"&&P==="*"&&O==="*"&&K==="*")return"Every hour";if(L.startsWith("*/")&&P==="*"&&O==="*"&&K==="*"){let J=parseInt(L.slice(2));if(J===1)return"Every hour";return`Every ${J} hours`}let _=(J,Z)=>{let Y=parseInt(J),U=parseInt(Z);if(isNaN(Y))return"";let W=Y>=12?"PM":"AM";return`${Y===0?12:Y>12?Y-12:Y}:${U.toString().padStart(2,"0")} ${W}`};if(L!=="*"&&!L.includes("/")&&P==="*"&&O==="*"){let J=_(L,w);if(K==="*")return`Daily at ${J}`;let Z=K.split(",").map((Y)=>{let U=parseInt(Y.trim());return o[U]||Y});if(Z.length===7)return`Daily at ${J}`;if(Z.length===5&&!Z.includes("Sat")&&!Z.includes("Sun"))return`Weekdays at ${J}`;if(Z.length===1)return`Weekly on ${Z[0]} at ${J}`;return`${Z.join(" & ")} at ${J}`}return B}catch{return B}}function F(B){let N=new Date(B),w=new Date,L=N.getTime()-w.getTime(),P=Math.abs(L),O=L>0,K=Math.floor(P/60000),_=Math.floor(P/3600000),J=Math.floor(P/86400000),Z=N.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}),Y=N.toDateString()===w.toDateString(),U=new Date(w);U.setDate(U.getDate()+1);let W=N.toDateString()===U.toDateString(),R=new Date(w);R.setDate(R.getDate()-1);let I=N.toDateString()===R.toDateString();if(Y){if(K<1)return O?"now":"just now";if(K<60)return O?`in ${K} min (${Z})`:`${K} min ago`;return O?`in ${_}h (${Z})`:`${_}h ago`}if(W)return`Tomorrow at ${Z}`;if(I)return`Yesterday at ${Z}`;if(J<7)return`${o[N.getDay()]} at ${Z}`;return N.toLocaleDateString([],{month:"short",day:"numeric"})+` at ${Z}`}
|
|
2
2
|
export{Zz as d,zz as e,Bz as f,E as g,F as h};
|
|
3
3
|
|
|
4
4
|
//# debugId=8E2D9B056A9C318964756E2164756E21
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as r}from"./App.tm3k7h4b.js";import{t as Oz}from"./App.9sryp183.js";import{O as Jz,P as o}from"./App.vkg121c6.js";import{U as t}from"./App.p7jjw1zf.js";import{$ as Qz,X as a,aa as zz,ja as c,ma as Gz}from"./App.94x6mh7f.js";var J=a(Qz(),1);var z=a(zz(),1);function Mz(){let{authFetch:G}=c(),{projects:$,currentProjectId:H}=Gz(),[K,w]=J.useState([]),[X,B]=J.useState(!0),[q,F]=J.useState(!1),[U,T]=J.useState(null),[M,L]=J.useState(null),[Q,k]=J.useState("servers"),{confirm:y,ConfirmDialog:f}=Jz(),Y=$.length>0,A=async()=>{try{let b=await(await G("/api/mcp/servers")).json();w(b.servers||[])}catch(W){console.error("Failed to fetch MCP servers:",W)}B(!1)};J.useEffect(()=>{A()},[G]);let Z=K.filter((W)=>{if(!H)return!0;if(H==="unassigned")return W.project_id===null;return W.project_id===null||W.project_id===H}),S=async(W)=>{try{await G(`/api/mcp/servers/${W}/start`,{method:"POST"}),A()}catch(b){console.error("Failed to start server:",b)}},I=async(W)=>{try{await G(`/api/mcp/servers/${W}/stop`,{method:"POST"}),A()}catch(b){console.error("Failed to stop server:",b)}},p=async(W)=>{if(!await y("Delete this MCP server?",{confirmText:"Delete",title:"Delete Server"}))return;try{if(await G(`/api/mcp/servers/${W}`,{method:"DELETE"}),M?.id===W)L(null);A()}catch(C){console.error("Failed to delete server:",C)}},u=async(W,b)=>{try{await G(`/api/mcp/servers/${W}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:b})}),A()}catch(C){console.error("Failed to rename server:",C)}},i=async(W,b)=>{try{await G(`/api/mcp/servers/${W}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)}),A()}catch(C){throw console.error("Failed to update server:",C),C}};return z.jsxDEV(z.Fragment,{children:[f,z.jsxDEV("div",{className:"flex-1 overflow-auto p-6",children:[z.jsxDEV("div",{className:"max-w-6xl",children:[z.jsxDEV("div",{className:"flex items-center justify-between mb-6",children:[z.jsxDEV("div",{children:[z.jsxDEV("h1",{className:"text-2xl font-semibold mb-1",children:"MCP Servers"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-[var(--color-text-muted)]",children:"Manage Model Context Protocol servers for tool integrations."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q==="servers"&&z.jsxDEV("button",{onClick:()=>F(!0),className:"bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] text-black px-4 py-2 rounded font-medium transition",children:"+ Add Server"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"flex gap-1 mb-6 bg-[var(--color-surface)] card p-1 w-fit",children:[z.jsxDEV("button",{onClick:()=>k("servers"),className:`px-4 py-2 rounded text-sm font-medium transition ${Q==="servers"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"My Servers"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:()=>k("hosted"),className:`px-4 py-2 rounded text-sm font-medium transition ${Q==="hosted"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"Hosted Services"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:()=>k("registry"),className:`px-4 py-2 rounded text-sm font-medium transition ${Q==="registry"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"Browse Registry"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q==="servers"&&z.jsxDEV(z.Fragment,{children:[X&&z.jsxDEV("div",{className:"text-center py-8 text-[var(--color-text-muted)]",children:"Loading..."},void 0,!1,void 0,this),!X&&Z.length===0&&K.length===0&&z.jsxDEV("div",{className:"bg-[var(--color-surface)] card p-8 text-center",children:[z.jsxDEV(Oz,{className:"w-12 h-12 text-[var(--color-border-light)] mx-auto mb-4"},void 0,!1,void 0,this),z.jsxDEV("h3",{className:"text-lg font-medium mb-2",children:"No MCP servers configured"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-[var(--color-text-muted)] mb-6 max-w-md mx-auto",children:"MCP servers extend your agents with tools like file access, web browsing, database connections, and more."},void 0,!1,void 0,this),z.jsxDEV("div",{className:"flex gap-3 justify-center",children:[z.jsxDEV("button",{onClick:()=>F(!0),className:"bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] text-black px-4 py-2 rounded font-medium transition",children:"Add Manually"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:()=>k("registry"),className:"border border-[var(--color-border-light)] hover:border-[var(--color-text-muted)] px-4 py-2 rounded font-medium transition",children:"Browse Registry"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!X&&Z.length===0&&K.length>0&&z.jsxDEV("div",{className:"bg-[var(--color-surface)] card p-6 text-center",children:z.jsxDEV("p",{className:"text-[var(--color-text-muted)]",children:"No servers match this filter."},void 0,!1,void 0,this)},void 0,!1,void 0,this),!X&&Z.length>0&&z.jsxDEV("div",{className:"flex gap-6",children:[z.jsxDEV("div",{className:`space-y-3 ${M?"w-1/2":"w-full"}`,children:Z.map((W)=>{let C=W.type==="http"&&W.url||W.status==="running",h=Y&&W.project_id?$.find((v)=>v.id===W.project_id):null;return z.jsxDEV(Wz,{server:W,project:h,selected:M?.id===W.id,onSelect:()=>L(C?W:null),onStart:()=>S(W.id),onStop:()=>I(W.id),onDelete:()=>p(W.id),onEdit:async()=>{try{let D=await(await G(`/api/mcp/servers/${W.id}`)).json();T(D.server||W)}catch{T(W)}}},W.id,!1,void 0,this)})},void 0,!1,void 0,this),M&&z.jsxDEV("div",{className:"w-1/2",children:z.jsxDEV(Xz,{server:M,onClose:()=>L(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Q==="hosted"&&z.jsxDEV(_z,{onServerAdded:A,projectId:H},void 0,!1,void 0,this),Q==="registry"&&z.jsxDEV(Zz,{onInstall:(W)=>{A(),k("servers")}},void 0,!1,void 0,this),Q==="servers"&&z.jsxDEV("div",{className:"mt-8 p-4 bg-[var(--color-surface)] card",children:[z.jsxDEV("h3",{className:"font-medium mb-2",children:"Quick Start"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)] mb-3",children:"Add an MCP server by providing its npm package name. For example:"},void 0,!1,void 0,this),z.jsxDEV("div",{className:"flex flex-wrap gap-2",children:[{name:"filesystem",pkg:"@modelcontextprotocol/server-filesystem"},{name:"fetch",pkg:"@modelcontextprotocol/server-fetch"},{name:"memory",pkg:"@modelcontextprotocol/server-memory"}].map((W)=>z.jsxDEV("code",{className:"text-xs bg-[var(--color-bg)] px-2 py-1 rounded",children:W.pkg},W.name,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),q&&z.jsxDEV(Bz,{onClose:()=>F(!1),onAdded:()=>{F(!1),A()},projects:Y?$:void 0,defaultProjectId:H&&H!=="unassigned"?H:null},void 0,!1,void 0,this),U&&z.jsxDEV(Uz,{server:U,projects:Y?$:void 0,onClose:()=>T(null),onSaved:()=>{T(null),A()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Wz({server:G,project:$,selected:H,onSelect:K,onStart:w,onStop:X,onDelete:B,onEdit:q}){let F=G.type==="http"&&G.url,U=F||G.status==="running",T=()=>{if(F)return`${G.source||"remote"} • http`;return`${G.type} • ${G.package||G.command||"custom"}${G.status==="running"&&G.port?` • :${G.port}`:""}`},M=()=>{if($)return z.jsxDEV("span",{className:"text-xs px-1.5 py-0.5 rounded",style:{backgroundColor:`${$.color}20`,color:$.color},children:$.name},void 0,!1,void 0,this);if(G.project_id===null)return z.jsxDEV("span",{className:"text-xs text-[var(--color-text-muted)] bg-[var(--color-surface-raised)] px-1.5 py-0.5 rounded",children:"Global"},void 0,!1,void 0,this);return null};return z.jsxDEV("div",{className:`bg-[var(--color-surface)] border rounded-lg p-4 cursor-pointer transition ${H?"border-[var(--color-accent)]":"border-[var(--color-border)] hover:border-[var(--color-border-light)]"}`,onClick:U?K:void 0,children:z.jsxDEV("div",{className:"flex items-center justify-between",children:[z.jsxDEV("div",{className:"flex items-center gap-3",children:[z.jsxDEV("div",{className:`w-2 h-2 rounded-full ${U?"bg-green-400":"bg-[var(--color-scrollbar)]"}`},void 0,!1,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("div",{className:"flex items-center gap-2",children:[z.jsxDEV("h3",{className:"font-medium",children:G.name},void 0,!1,void 0,this),M()]},void 0,!0,void 0,this),z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)]",children:T()},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"flex items-center gap-2",children:[z.jsxDEV("button",{onClick:(L)=>{L.stopPropagation(),q()},className:"text-sm text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)] px-3 py-1 transition",title:"Edit server settings",children:"Edit"},void 0,!1,void 0,this),F?z.jsxDEV("button",{onClick:(L)=>{L.stopPropagation(),B()},className:"text-sm text-[var(--color-text-muted)] hover:text-red-400 px-3 py-1 transition",children:"Remove"},void 0,!1,void 0,this):G.status==="running"?z.jsxDEV(z.Fragment,{children:[z.jsxDEV("button",{onClick:(L)=>{L.stopPropagation(),K()},className:"text-sm text-[var(--color-accent)] hover:text-[var(--color-accent-hover)] px-3 py-1 transition",children:"Tools"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:(L)=>{L.stopPropagation(),X()},className:"text-sm text-[var(--color-text-muted)] hover:text-red-400 px-3 py-1 transition",children:"Stop"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:(L)=>{L.stopPropagation(),B()},className:"text-sm text-[var(--color-text-muted)] hover:text-red-400 px-3 py-1 transition",children:"Delete"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):z.jsxDEV(z.Fragment,{children:[z.jsxDEV("button",{onClick:(L)=>{L.stopPropagation(),w()},className:"text-sm text-[var(--color-text-muted)] hover:text-green-400 px-3 py-1 transition",children:"Start"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:(L)=>{L.stopPropagation(),B()},className:"text-sm text-[var(--color-text-muted)] hover:text-red-400 px-3 py-1 transition",children:"Delete"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function Xz({server:G,onClose:$}){let{authFetch:H}=c(),[K,w]=J.useState([]),[X,B]=J.useState(null),[q,F]=J.useState(!0),[U,T]=J.useState(null),[M,L]=J.useState(null);return J.useEffect(()=>{(async()=>{F(!0),T(null);try{let k=await H(`/api/mcp/servers/${G.id}/tools`),y=await k.json();if(!k.ok){T(y.error||"Failed to fetch tools");return}w(y.tools||[]),B(y.serverInfo||null)}catch(k){T(`Failed to fetch tools: ${k}`)}finally{F(!1)}})()},[G.id,H]),z.jsxDEV("div",{className:"bg-[var(--color-surface)] card overflow-hidden",children:[z.jsxDEV("div",{className:"p-4 border-b border-[var(--color-border)] flex items-center justify-between",children:[z.jsxDEV("div",{children:[z.jsxDEV("h3",{className:"font-medium",children:[G.name," Tools"]},void 0,!0,void 0,this),X&&z.jsxDEV("p",{className:"text-xs text-[var(--color-text-muted)]",children:[X.name," v",X.version]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("button",{onClick:$,className:"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)] text-xl leading-none",children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"p-4 max-h-[500px] overflow-auto",children:[q&&z.jsxDEV("p",{className:"text-[var(--color-text-muted)]",children:"Loading tools..."},void 0,!1,void 0,this),U&&z.jsxDEV("div",{className:"text-red-400 text-sm p-3 bg-red-500/10 rounded",children:U},void 0,!1,void 0,this),!q&&!U&&K.length===0&&z.jsxDEV("p",{className:"text-[var(--color-text-muted)]",children:"No tools available from this server."},void 0,!1,void 0,this),!q&&!U&&K.length>0&&!M&&z.jsxDEV("div",{className:"space-y-2",children:K.map((Q)=>z.jsxDEV("button",{onClick:()=>L(Q),className:"w-full text-left p-3 bg-[var(--color-bg)] hover:bg-[var(--color-surface-raised)] border border-[var(--color-border-light)] hover:border-[var(--color-border-light)] rounded transition",children:[z.jsxDEV("div",{className:"font-medium text-sm",children:Q.name},void 0,!1,void 0,this),Q.description&&z.jsxDEV("div",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:Q.description},void 0,!1,void 0,this)]},Q.name,!0,void 0,this))},void 0,!1,void 0,this),M&&z.jsxDEV(Yz,{serverId:G.id,tool:M,onBack:()=>L(null)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Yz({serverId:G,tool:$,onBack:H}){let{authFetch:K}=c(),[w,X]=J.useState("{}"),[B,q]=J.useState(null),[F,U]=J.useState(null),[T,M]=J.useState(!1);J.useEffect(()=>{let Q=$.inputSchema;if(Q&&typeof Q==="object"&&"properties"in Q){let k=Q.properties,y={};for(let[f,Y]of Object.entries(k))if(Y.default!==void 0)y[f]=Y.default;else if(Y.type==="string")y[f]="";else if(Y.type==="number"||Y.type==="integer")y[f]=0;else if(Y.type==="boolean")y[f]=!1;else if(Y.type==="array")y[f]=[];else if(Y.type==="object")y[f]={};X(JSON.stringify(y,null,2))}},[$]);let L=async()=>{M(!0),U(null),q(null);try{let Q=JSON.parse(w),k=await K(`/api/mcp/servers/${G}/tools/${encodeURIComponent($.name)}/call`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({arguments:Q})}),y=await k.json();if(!k.ok){U(y.error||"Failed to call tool");return}q(y.result)}catch(Q){U(`Error: ${Q}`)}finally{M(!1)}};return z.jsxDEV("div",{className:"space-y-4",children:[z.jsxDEV("div",{className:"flex items-center gap-2",children:[z.jsxDEV("button",{onClick:H,className:"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)] text-sm",children:"← Back"},void 0,!1,void 0,this),z.jsxDEV("span",{className:"text-[var(--color-text-faint)]",children:"/"},void 0,!1,void 0,this),z.jsxDEV("span",{className:"font-medium",children:$.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),$.description&&z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)]",children:$.description},void 0,!1,void 0,this),$.inputSchema&&z.jsxDEV("div",{className:"text-xs",children:z.jsxDEV("details",{className:"cursor-pointer",children:[z.jsxDEV("summary",{className:"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]",children:"Input Schema"},void 0,!1,void 0,this),z.jsxDEV("pre",{className:"mt-2 p-2 bg-[var(--color-bg)] rounded text-[var(--color-text-secondary)] overflow-auto max-h-32",children:JSON.stringify($.inputSchema,null,2)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Arguments (JSON)"},void 0,!1,void 0,this),z.jsxDEV("textarea",{value:w,onChange:(Q)=>X(Q.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 h-32 font-mono text-sm focus:outline-none focus:border-[var(--color-accent)] resize-none",placeholder:"{}"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("button",{onClick:L,disabled:T,className:"w-full bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] disabled:opacity-50 text-black px-4 py-2 rounded font-medium transition",children:T?"Calling...":"Call Tool"},void 0,!1,void 0,this),F&&z.jsxDEV("div",{className:"text-red-400 text-sm p-3 bg-red-500/10 rounded",children:F},void 0,!1,void 0,this),B&&z.jsxDEV("div",{className:"space-y-2",children:[z.jsxDEV("div",{className:"text-sm text-[var(--color-text-muted)]",children:["Result ",B.isError&&z.jsxDEV("span",{className:"text-red-400",children:"(error)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:`p-3 rounded text-sm ${B.isError?"bg-red-500/10":"bg-green-500/10"}`,children:B.content.map((Q,k)=>z.jsxDEV("div",{className:"mb-2 last:mb-0",children:[Q.type==="text"&&z.jsxDEV("pre",{className:"whitespace-pre-wrap font-mono text-xs",children:Q.text},void 0,!1,void 0,this),Q.type==="image"&&Q.data&&z.jsxDEV("img",{src:`data:${Q.mimeType||"image/png"};base64,${Q.data}`,alt:"Tool result",className:"max-w-full rounded"},void 0,!1,void 0,this)]},k,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Zz({onInstall:G}){let{authFetch:$}=c(),[H,K]=J.useState(""),[w,X]=J.useState([]),[B,q]=J.useState(!1),[F,U]=J.useState(!1),[T,M]=J.useState(null),[L,Q]=J.useState(null),k=async(Y)=>{q(!0),Q(null);try{let A=await $(`/api/mcp/registry?search=${encodeURIComponent(Y)}&limit=20`),Z=await A.json();if(!A.ok)Q(Z.error||"Failed to search registry"),X([]);else X(Z.servers||[])}catch(A){Q(`Failed to search: ${A}`),X([])}finally{q(!1),U(!0)}},y=(Y)=>{if(Y.preventDefault(),H.trim())k(H.trim())};J.useEffect(()=>{k("")},[]);let f=async(Y)=>{if(!Y.npmPackage){Q("This server does not have an npm package");return}M(Y.id),Q(null);try{let A=await $("/api/mcp/servers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:Y.name,type:"npm",package:Y.npmPackage})});if(!A.ok){let Z=await A.json();Q(Z.error||"Failed to add server");return}G(Y)}catch(A){Q(`Failed to add server: ${A}`)}finally{M(null)}};return z.jsxDEV("div",{className:"space-y-6",children:[z.jsxDEV("form",{onSubmit:y,className:"flex gap-2",children:[z.jsxDEV("input",{type:"text",value:H,onChange:(Y)=>K(Y.target.value),placeholder:"Search MCP servers (e.g., filesystem, github, slack...)",className:"flex-1 bg-[var(--color-surface)] border border-[var(--color-border-light)] rounded-lg px-4 py-3 focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this),z.jsxDEV("button",{type:"submit",disabled:B,className:"bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] disabled:opacity-50 text-black px-6 py-3 rounded-lg font-medium transition",children:B?"...":"Search"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L&&z.jsxDEV("div",{className:"text-red-400 text-sm p-3 bg-red-500/10 border border-red-500/20 rounded-lg",children:L},void 0,!1,void 0,this),!B&&F&&w.length===0&&z.jsxDEV("div",{className:"text-center py-8 text-[var(--color-text-muted)]",children:"No servers found. Try a different search term."},void 0,!1,void 0,this),w.length>0&&z.jsxDEV("div",{className:"grid gap-4 md:grid-cols-2",children:w.map((Y)=>z.jsxDEV("div",{className:"bg-[var(--color-surface)] card p-4 hover:border-[var(--color-border-light)] transition",children:z.jsxDEV("div",{className:"flex items-start justify-between gap-3",children:[z.jsxDEV("div",{className:"flex-1 min-w-0",children:[z.jsxDEV("h3",{className:"font-medium truncate",children:Y.name},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)] mt-1 line-clamp-2",children:Y.description||"No description"},void 0,!1,void 0,this),z.jsxDEV("div",{className:"flex items-center gap-2 mt-2 text-xs text-[var(--color-text-faint)]",children:[Y.version&&z.jsxDEV("span",{children:["v",Y.version]},void 0,!0,void 0,this),z.jsxDEV("span",{className:`px-1.5 py-0.5 rounded ${Y.npmPackage?"bg-green-500/10 text-green-400":"bg-blue-500/10 text-blue-400"}`,children:Y.npmPackage?"npm":"remote"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("code",{className:"text-xs text-[var(--color-text-faint)] bg-[var(--color-bg)] px-2 py-0.5 rounded mt-2 inline-block truncate max-w-full",children:Y.npmPackage||Y.fullName},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"flex-shrink-0",children:Y.npmPackage?z.jsxDEV("button",{onClick:()=>f(Y),disabled:T===Y.id,className:"text-sm bg-[var(--color-surface-raised)] hover:bg-[var(--color-surface-raised)] border border-[var(--color-border-light)] hover:border-[var(--color-accent)] px-3 py-1.5 rounded transition disabled:opacity-50",children:T===Y.id?"Adding...":"Add"},void 0,!1,void 0,this):Y.repository?z.jsxDEV("a",{href:Y.repository,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-[var(--color-text-muted)] hover:text-[var(--color-accent)] transition",children:"View →"},void 0,!1,void 0,this):null},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},Y.id,!1,void 0,this))},void 0,!1,void 0,this),B&&z.jsxDEV("div",{className:"text-center py-8 text-[var(--color-text-muted)]",children:"Searching registry..."},void 0,!1,void 0,this),z.jsxDEV("div",{className:"p-4 bg-[var(--color-surface)] card text-sm text-[var(--color-text-muted)]",children:z.jsxDEV("p",{children:["Servers are sourced from the"," ",z.jsxDEV("a",{href:"https://github.com/modelcontextprotocol/servers",target:"_blank",rel:"noopener noreferrer",className:"text-[var(--color-accent)] hover:underline",children:"official MCP registry"},void 0,!1,void 0,this),". Not all servers have npm packages - some require manual setup."]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function _z({onServerAdded:G,projectId:$}){let{authFetch:H}=c(),[K,w]=J.useState("composio"),[X,B]=J.useState("configs"),[q,F]=J.useState(!1),[U,T]=J.useState(!1),[M,L]=J.useState(!1),[Q,k]=J.useState([]),[y,f]=J.useState(new Set),[Y,A]=J.useState(!0),[Z,S]=J.useState(!1),[I,p]=J.useState(null),{alert:u,AlertDialog:i}=o(),W=async()=>{try{let P=$&&$!=="unassigned"?`/api/mcp/servers?project=${encodeURIComponent($)}`:"/api/mcp/servers",[x,_]=await Promise.all([H("/api/providers"),H(P)]),R=await x.json(),g=await _.json(),V=R.providers||[],O=g.servers||[],N=new Set(O.filter((E)=>E.source==="composio"&&E.url).map((E)=>{let e=E.url.match(/\/v3\/mcp\/([^/]+)/);return e?e[1]:null}).filter(Boolean));f(N);let m=V.find((E)=>E.id==="composio"),l=V.find((E)=>E.id==="smithery"),n=V.find((E)=>E.id==="agentdojo"),d=m?.hasKey||!1,j=l?.hasKey||!1,s=n?.hasKey||!1;if(F(d),T(j),L(s),d)w("composio"),b();else if(j)w("smithery");else if(s)w("agentdojo")}catch(P){console.error("Failed to fetch providers:",P)}A(!1)},b=async()=>{S(!0);try{let P=$&&$!=="unassigned"?`?project_id=${$}`:"",_=await(await H(`/api/integrations/composio/configs${P}`)).json();k(_.configs||[])}catch(P){console.error("Failed to fetch Composio configs:",P)}S(!1)},C=async(P)=>{p(P);try{let x=$&&$!=="unassigned"?`?project_id=${$}`:"",_=await H(`/api/integrations/composio/configs/${P}/add${x}`,{method:"POST"});if(_.ok)f((R)=>new Set([...R,P])),G?.();else{let R=await _.json();await u(R.error||"Failed to add config",{title:"Error",variant:"error"})}}catch(x){console.error("Failed to add config:",x)}p(null)},h=(P)=>{return y.has(P)};if(J.useEffect(()=>{W()},[H,$]),Y)return z.jsxDEV("div",{className:"text-center py-8 text-[var(--color-text-muted)]",children:"Loading..."},void 0,!1,void 0,this);let v=q||U||M,D=[q,U,M].filter(Boolean).length;if(!v)return z.jsxDEV("div",{className:"bg-[var(--color-surface)] card p-8 text-center",children:[z.jsxDEV("p",{className:"text-[var(--color-text-secondary)] mb-2",children:"No hosted MCP services connected"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)] mb-4",children:"Connect Composio, Smithery, or AgentDojo in Settings to access cloud-based MCP servers."},void 0,!1,void 0,this),z.jsxDEV("a",{href:"/settings",className:"inline-block bg-[var(--color-surface-raised)] hover:bg-[var(--color-surface-raised)] border border-[var(--color-border-light)] hover:border-[var(--color-accent)] px-4 py-2 rounded text-sm font-medium transition",children:"Go to Settings →"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return z.jsxDEV(z.Fragment,{children:[i,z.jsxDEV("div",{className:"space-y-6",children:[D>1&&z.jsxDEV("div",{className:"flex gap-1 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded-lg p-1 w-fit",children:[q&&z.jsxDEV("button",{onClick:()=>{w("composio"),B("configs")},className:`px-4 py-2 rounded text-sm font-medium transition flex items-center gap-2 ${K==="composio"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:[z.jsxDEV("span",{className:"w-2 h-2 rounded-full bg-purple-500"},void 0,!1,void 0,this),"Composio"]},void 0,!0,void 0,this),U&&z.jsxDEV("button",{onClick:()=>w("smithery"),className:`px-4 py-2 rounded text-sm font-medium transition flex items-center gap-2 ${K==="smithery"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:[z.jsxDEV("span",{className:"w-2 h-2 rounded-full bg-blue-500"},void 0,!1,void 0,this),"Smithery"]},void 0,!0,void 0,this),M&&z.jsxDEV("button",{onClick:()=>w("agentdojo"),className:`px-4 py-2 rounded text-sm font-medium transition flex items-center gap-2 ${K==="agentdojo"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:[z.jsxDEV("span",{className:"w-2 h-2 rounded-full bg-green-500"},void 0,!1,void 0,this),"AgentDojo"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),q&&(D===1||K==="composio")&&z.jsxDEV(z.Fragment,{children:[z.jsxDEV("div",{className:"flex items-center justify-between",children:[z.jsxDEV("div",{className:"flex gap-1 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded-lg p-1",children:[z.jsxDEV("button",{onClick:()=>B("configs"),className:`px-4 py-2 rounded text-sm font-medium transition ${X==="configs"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"MCP Configs"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:()=>B("connect"),className:`px-4 py-2 rounded text-sm font-medium transition ${X==="connect"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"Connect Apps"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D===1&&z.jsxDEV("div",{className:"flex items-center gap-2 text-xs text-[var(--color-text-muted)]",children:[z.jsxDEV("span",{className:"w-2 h-2 rounded-full bg-purple-500"},void 0,!1,void 0,this),"Composio",z.jsxDEV("span",{className:"text-green-400",children:"Connected"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),X==="connect"&&z.jsxDEV("div",{children:[z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)] mb-4",children:"Connect your accounts to enable tools in MCP configs"},void 0,!1,void 0,this),z.jsxDEV(r,{providerId:"composio",projectId:$,onConnectionComplete:()=>{b()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X==="configs"&&z.jsxDEV("div",{children:[z.jsxDEV("div",{className:"flex items-center justify-between mb-3",children:[z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)]",children:"Your MCP configs from Composio"},void 0,!1,void 0,this),z.jsxDEV("div",{className:"flex items-center gap-3",children:[z.jsxDEV("button",{onClick:b,disabled:Z,className:"text-xs text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)] transition",children:Z?"Loading...":"Refresh"},void 0,!1,void 0,this),z.jsxDEV("a",{href:"https://app.composio.dev/mcp_configs",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-[var(--color-text-muted)] hover:text-[var(--color-accent)] transition",children:"Create Config →"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Z?z.jsxDEV("div",{className:"text-center py-6 text-[var(--color-text-muted)]",children:"Loading configs..."},void 0,!1,void 0,this):Q.length===0?z.jsxDEV("div",{className:"bg-[var(--color-surface)] card p-4 text-center",children:[z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)]",children:"No MCP configs found"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-2",children:["First ",z.jsxDEV("button",{onClick:()=>B("connect"),className:"text-[var(--color-accent)] hover:text-[var(--color-accent-hover)]",children:"connect some apps"},void 0,!1,void 0,this),", then create a config."]},void 0,!0,void 0,this),z.jsxDEV("a",{href:"https://app.composio.dev/mcp_configs",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-[var(--color-accent)] hover:text-[var(--color-accent-hover)] mt-2 inline-block",children:"Create in Composio →"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):z.jsxDEV("div",{className:"space-y-2",children:Q.map((P)=>{let x=h(P.id),_=I===P.id;return z.jsxDEV("div",{className:`bg-[var(--color-surface)] border rounded-lg p-3 transition flex items-center justify-between ${x?"border-green-500/30":"border-[var(--color-border)] hover:border-[var(--color-border-light)]"}`,children:[z.jsxDEV("div",{className:"flex-1 min-w-0",children:[z.jsxDEV("div",{className:"flex items-center gap-2",children:[z.jsxDEV("span",{className:"font-medium text-sm",children:P.name},void 0,!1,void 0,this),z.jsxDEV("span",{className:"text-xs text-[var(--color-text-faint)]",children:[P.toolsCount," tools"]},void 0,!0,void 0,this),x&&z.jsxDEV("span",{className:"text-xs text-green-400",children:"Added"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P.toolkits.length>0&&z.jsxDEV("div",{className:"flex flex-wrap gap-1 mt-1",children:[P.toolkits.slice(0,4).map((R)=>z.jsxDEV("span",{className:"text-xs bg-[var(--color-surface-raised)] text-[var(--color-text-muted)] px-1.5 py-0.5 rounded",children:R},R,!1,void 0,this)),P.toolkits.length>4&&z.jsxDEV("span",{className:"text-xs text-[var(--color-text-faint)]",children:["+",P.toolkits.length-4]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"flex items-center gap-2 ml-3",children:[x?z.jsxDEV("span",{className:"text-xs text-[var(--color-text-faint)] px-2 py-1",children:"In Servers"},void 0,!1,void 0,this):z.jsxDEV("button",{onClick:()=>C(P.id),disabled:_,className:"text-xs bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] text-black px-3 py-1 rounded font-medium transition disabled:opacity-50",children:_?"Adding...":"Add"},void 0,!1,void 0,this),z.jsxDEV("a",{href:`https://app.composio.dev/mcp_configs/${P.id}`,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)] transition",children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},P.id,!0,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),U&&(D===1||K==="smithery")&&z.jsxDEV("div",{children:[D===1&&z.jsxDEV("div",{className:"flex items-center gap-2 text-xs text-[var(--color-text-muted)] mb-4",children:[z.jsxDEV("span",{className:"w-2 h-2 rounded-full bg-blue-500"},void 0,!1,void 0,this),"Smithery",z.jsxDEV("span",{className:"text-green-400",children:"Connected"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"flex items-center justify-between mb-3",children:[z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)]",children:"Add MCP servers from the Smithery registry"},void 0,!1,void 0,this),z.jsxDEV("a",{href:"https://smithery.ai/servers",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-[var(--color-text-muted)] hover:text-[var(--color-accent)] transition",children:"Browse Smithery →"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"bg-[var(--color-surface)] card p-4 text-center",children:[z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)]",children:["Smithery servers can be added from the ",z.jsxDEV("strong",{children:"Browse Registry"},void 0,!1,void 0,this)," tab."]},void 0,!0,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-2",children:"Your API key will be used automatically when adding Smithery servers."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),M&&(D===1||K==="agentdojo")&&z.jsxDEV($z,{projectId:$,onServerAdded:G,showProviderBadge:D===1},void 0,!1,void 0,this),z.jsxDEV("div",{className:"p-3 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded text-xs text-[var(--color-text-muted)]",children:[z.jsxDEV("strong",{className:"text-[var(--color-text-secondary)]",children:"Tip:"},void 0,!1,void 0,this)," Connect apps first, then add MCP configs to make tools available to your agents."," · ",z.jsxDEV("a",{href:"/settings",className:"text-[var(--color-accent)] hover:text-[var(--color-accent-hover)]",children:"Add more providers in Settings"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function $z({projectId:G,onServerAdded:$,showProviderBadge:H}){let{authFetch:K}=c(),[w,X]=J.useState("configs"),[B,q]=J.useState([]),[F,U]=J.useState(new Set),[T,M]=J.useState(!1),[L,Q]=J.useState(null),{alert:k,AlertDialog:y}=o(),f=async()=>{M(!0);try{let Z=G&&G!=="unassigned"?`?project_id=${G}`:"",S=G&&G!=="unassigned"?`/api/mcp/servers?project=${encodeURIComponent(G)}`:"/api/mcp/servers";console.log(`[AgentDojo:fetchConfigs] projectId=${G} serversUrl=${S}`);let[I,p]=await Promise.all([K(`/api/integrations/agentdojo/configs${Z}`),K(S)]),u=await I.json(),i=await p.json();console.log(`[AgentDojo:fetchConfigs] configs=${(u.configs||[]).length} servers=${(i.servers||[]).length}`),q(u.configs||[]);let W=(i.servers||[]).filter((C)=>C.source==="agentdojo");console.log(`[AgentDojo:fetchConfigs] agentdojo servers found: ${W.length}`);for(let C of W){let h=C.url?.match(/\/mcp\/([^/?]+)/);console.log(`[AgentDojo:fetchConfigs] server: id=${C.id} name=${C.name} project_id=${C.project_id} url=${C.url?.substring(0,80)} extracted=${h?h[1]:C.name}`)}let b=new Set(W.map((C)=>{let h=C.url?.match(/\/mcp\/([^/?]+)/);return h?h[1]:C.name}));console.log("[AgentDojo:fetchConfigs] addedServers set:",[...b]),U(b)}catch(Z){console.error("Failed to fetch AgentDojo configs:",Z)}M(!1)},Y=async(Z)=>{Q(Z);try{let S=G&&G!=="unassigned"?`?project_id=${G}`:"";console.log(`[AgentDojo:addConfig] configId=${Z} projectParam=${S}`);let I=await K(`/api/integrations/agentdojo/configs/${Z}/add${S}`,{method:"POST"}),p=await I.json();if(console.log(`[AgentDojo:addConfig] response status=${I.status} ok=${I.ok} message=${p.message} server.id=${p.server?.id} server.project_id=${p.server?.project_id}`),I.ok){let u=B.find((W)=>W.id===Z),i=u?.slug||Z;console.log(`[AgentDojo:addConfig] marking as added: key=${i} config.slug=${u?.slug} config.id=${u?.id} config.name=${u?.name}`),U((W)=>new Set([...W,i])),$?.()}else await k(p.error||"Failed to add config",{title:"Error",variant:"error"})}catch(S){console.error("Failed to add config:",S)}Q(null)},A=(Z)=>{return F.has(Z.slug)||F.has(Z.id)||F.has(Z.name)};return J.useEffect(()=>{f()},[K,G]),z.jsxDEV(z.Fragment,{children:[y,z.jsxDEV("div",{children:[H&&z.jsxDEV("div",{className:"flex items-center gap-2 text-xs text-[var(--color-text-muted)] mb-4",children:[z.jsxDEV("span",{className:"w-2 h-2 rounded-full bg-green-500"},void 0,!1,void 0,this),"AgentDojo",z.jsxDEV("span",{className:"text-green-400",children:"Connected"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"flex items-center justify-between mb-4",children:z.jsxDEV("div",{className:"flex gap-1 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded-lg p-1",children:[z.jsxDEV("button",{onClick:()=>X("configs"),className:`px-4 py-2 rounded text-sm font-medium transition ${w==="configs"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"MCP Servers"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:()=>X("toolkits"),className:`px-4 py-2 rounded text-sm font-medium transition ${w==="toolkits"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"Browse Toolkits"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),w==="configs"&&z.jsxDEV("div",{children:[z.jsxDEV("div",{className:"flex items-center justify-between mb-3",children:[z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)]",children:"Your MCP servers from AgentDojo"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:f,disabled:T,className:"text-xs text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)] transition",children:T?"Loading...":"Refresh"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T?z.jsxDEV("div",{className:"text-center py-6 text-[var(--color-text-muted)]",children:"Loading servers..."},void 0,!1,void 0,this):B.length===0?z.jsxDEV("div",{className:"bg-[var(--color-surface)] card p-4 text-center",children:[z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)]",children:"No MCP servers found"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-2",children:[z.jsxDEV("button",{onClick:()=>X("toolkits"),className:"text-[var(--color-accent)] hover:text-[var(--color-accent-hover)]",children:"Browse toolkits"},void 0,!1,void 0,this)," ","to create a new MCP server."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):z.jsxDEV("div",{className:"space-y-2",children:B.map((Z)=>{let S=A(Z),I=L===Z.id;return z.jsxDEV("div",{className:`bg-[var(--color-surface)] border rounded-lg p-3 transition flex items-center justify-between ${S?"border-green-500/30":"border-[var(--color-border)] hover:border-[var(--color-border-light)]"}`,children:[z.jsxDEV("div",{className:"flex-1 min-w-0",children:[z.jsxDEV("div",{className:"flex items-center gap-2",children:[z.jsxDEV("span",{className:"font-medium text-sm",children:Z.name},void 0,!1,void 0,this),z.jsxDEV("span",{className:"text-xs text-[var(--color-text-faint)]",children:[Z.toolsCount," tools"]},void 0,!0,void 0,this),S&&z.jsxDEV("span",{className:"text-xs text-green-400",children:"Added"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z.mcpUrl&&z.jsxDEV("code",{className:"text-xs text-[var(--color-text-faint)] mt-1 block truncate",children:Z.mcpUrl},void 0,!1,void 0,this),!Z.mcpUrl&&Z.slug&&z.jsxDEV("code",{className:"text-xs text-[var(--color-text-faint)] mt-1 block truncate",children:Z.slug},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"flex items-center gap-2 ml-3",children:S?z.jsxDEV("span",{className:"text-xs text-[var(--color-text-faint)] px-2 py-1",children:"In Servers"},void 0,!1,void 0,this):z.jsxDEV("button",{onClick:()=>Y(Z.id),disabled:I,className:"text-xs bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] text-black px-3 py-1 rounded font-medium transition disabled:opacity-50",children:I?"Adding...":"Add"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},Z.id,!0,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),w==="toolkits"&&z.jsxDEV("div",{children:[z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)] mb-4",children:"Browse available toolkits and create MCP servers"},void 0,!1,void 0,this),z.jsxDEV(r,{providerId:"agentdojo",projectId:G,onConnectionComplete:()=>{f()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function qz(G){let $=[],H=G,K=null,w=G.match(/(?:npx\s+-y\s+)?(@?[\w-]+\/)?(@?[\w-]+)(?:@[\w.-]+)?/);if(w){let q=w[2]||w[1];if(q)K=q.replace(/^@/,"").replace(/-mcp$/,"").replace(/-server$/,"").replace(/^server-/,"").replace(/^mcp-/,"")}let X=/--(\w+[-\w]*)\s+(YOUR_\w+|<[\w_]+>|\{[\w_]+\}|\$[\w_]+|[\w_]*(?:TOKEN|KEY|SECRET|PASSWORD|USER|ID|APIKEY)[\w_]*)/gi,B;while((B=X.exec(G))!==null){let q=B[1],F=B[2],U=q.toUpperCase().replace(/-/g,"_"),T=K?`${K.toUpperCase().replace(/-/g,"_")}_${U}`:U;$.push({key:T,flag:q}),H=H.replace(new RegExp(`(--${q}\\s+)${F.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}`,"i"),`--${q} $${T}`)}return{cleanCommand:H,credentials:$,serverName:K}}function Bz({onClose:G,onAdded:$,projects:H,defaultProjectId:K}){let{authFetch:w}=c(),[X,B]=J.useState("npm"),[q,F]=J.useState(""),[U,T]=J.useState(""),[M,L]=J.useState(""),[Q,k]=J.useState(""),[y,f]=J.useState(""),[Y,A]=J.useState(""),[Z,S]=J.useState(""),[I,p]=J.useState([]),[u,i]=J.useState(K||null),[W,b]=J.useState(!1),[C,h]=J.useState(null),v=H&&H.length>0,D=()=>{p([...I,{key:"",value:""}])},P=(O,N,m)=>{let l=[...I];l[O][N]=m,p(l)},x=(O)=>{p(I.filter((N,m)=>m!==O))},_=(O)=>{if(k(O),O.includes("YOUR_")||O.includes("<")||O.includes("{")||/TOKEN|KEY|SECRET|PASSWORD/i.test(O)){let{cleanCommand:N,credentials:m,serverName:l}=qz(O);if(!q&&l)F(l);if(m.length>0){let n=new Set(I.map((j)=>j.key)),d=m.filter((j)=>!n.has(j.key)).map((j)=>({key:j.key,value:""}));if(d.length>0)p([...I,...d]),k(N)}}},R=(O)=>{if(O.startsWith("npx ")||O.includes(" --")||O.includes("YOUR_")||O.includes("<")||/\s+(TOKEN|KEY|SECRET|PASSWORD)/i.test(O))B("command"),_(O);else if(T(O),!q&&O){let m=O.replace(/^@[\w-]+\//,"").replace(/@[\w.-]+$/,"").replace(/^server-/,"").replace(/-server$/,"").replace(/^mcp-/,"").replace(/-mcp$/,"");if(m&&m!==O)F(m)}},g=async()=>{if(!q){h("Name is required");return}if(X==="npm"&&!U){h("npm package is required");return}if(X==="pip"&&!U){h("pip package is required");return}if(X==="command"&&!Q){h("Command is required");return}if(X==="http"&&!y){h("URL is required");return}b(!0),h(null);let O={};for(let{key:N,value:m}of I)if(N.trim())O[N.trim()]=m;try{let N={name:q};if(X==="npm")N.type="npm",N.package=U;else if(X==="pip"){if(N.type="pip",N.package=U,M)N.pip_module=M}else if(X==="http"){N.type="http",N.url=y;let l={"Content-Type":"application/json"};if(Y&&Z){let n=btoa(`${Y}:${Z}`);l.Authorization=`Basic ${n}`}N.headers=l}else{let l=Q.trim().split(/\s+/);N.type="custom",N.command=l[0],N.args=l.slice(1).join(" ")}if(Object.keys(O).length>0)N.env=O;if(u)N.project_id=u;let m=await w("/api/mcp/servers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(N)});if(!m.ok){let l=await m.json();h(l.error||"Failed to add server"),b(!1);return}$()}catch(N){h("Failed to add server"),b(!1)}},V=(O,N)=>{B("npm"),F(O),T(N)};return z.jsxDEV("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-[2px] z-50 flex items-center justify-center p-4",children:z.jsxDEV("div",{className:"bg-[var(--color-surface)] card w-full max-w-lg max-h-[90vh] overflow-y-auto",children:[z.jsxDEV("div",{className:"p-4 border-b border-[var(--color-border)] flex items-center justify-between sticky top-0 bg-[var(--color-surface)]",children:[z.jsxDEV("h2",{className:"text-lg font-semibold",children:"Add MCP Server"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:G,className:"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"p-4 space-y-4",children:[z.jsxDEV("div",{children:[z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)] mb-2",children:"Quick add:"},void 0,!1,void 0,this),z.jsxDEV("div",{className:"flex flex-wrap gap-2",children:[{name:"filesystem",pkg:"@modelcontextprotocol/server-filesystem",type:"npm"},{name:"fetch",pkg:"@modelcontextprotocol/server-fetch",type:"npm"},{name:"memory",pkg:"@modelcontextprotocol/server-memory",type:"npm"},{name:"github",pkg:"@modelcontextprotocol/server-github",type:"npm"},{name:"time",pkg:"mcp-server-time",module:"mcp_server_time",type:"pip"}].map((O)=>z.jsxDEV("button",{onClick:()=>{if(B(O.type),F(O.name),T(O.pkg),O.type==="pip"&&"module"in O)L(O.module||"");else L("")},className:"text-sm bg-[var(--color-surface-raised)] hover:bg-[var(--color-surface-raised)] px-3 py-1 rounded transition",children:O.name},O.name,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"flex gap-1 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded p-1",children:[z.jsxDEV("button",{onClick:()=>B("npm"),className:`flex-1 px-2 py-1.5 rounded text-sm transition ${X==="npm"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"npm"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:()=>B("pip"),className:`flex-1 px-2 py-1.5 rounded text-sm transition ${X==="pip"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"pip"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:()=>B("command"),className:`flex-1 px-2 py-1.5 rounded text-sm transition ${X==="command"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"Command"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:()=>B("http"),className:`flex-1 px-2 py-1.5 rounded text-sm transition ${X==="http"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"HTTP"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Name"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:q,onChange:(O)=>F(O.target.value),placeholder:"e.g., pushover",className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v&&z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Scope"},void 0,!1,void 0,this),z.jsxDEV(t,{value:u||"",onChange:(O)=>i(O||null),options:[{value:"",label:"Global (all projects)"},...H.map((O)=>({value:O.id,label:O.name}))],placeholder:"Select scope..."},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"Global servers are available to all agents. Project-scoped servers are only available to agents in that project."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X==="npm"&&z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"npm Package"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:U,onChange:(O)=>R(O.target.value),placeholder:"e.g., @modelcontextprotocol/server-filesystem or paste full command",className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"Package name or paste a full npx command with credentials"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X==="pip"&&z.jsxDEV("div",{className:"space-y-4",children:[z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"pip Package"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:U,onChange:(O)=>{if(T(O.target.value),!M&&O.target.value){let N=O.target.value.split("[")[0].replace(/-/g,".");L(N)}},placeholder:"e.g., late-sdk[mcp]",className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"Python package with extras, e.g., late-sdk[mcp] or mcp-server-time"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Module (optional)"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:M,onChange:(O)=>L(O.target.value),placeholder:"e.g., late.mcp",className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 font-mono text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"Python module to run with -m. Auto-detected from package name if not specified."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),X==="command"&&z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Command"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:Q,onChange:(O)=>_(O.target.value),placeholder:"e.g., npx -y pushover-mcp@latest start --token YOUR_TOKEN",className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 font-mono text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"Paste the full command - credentials like YOUR_TOKEN will be auto-extracted"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X==="http"&&z.jsxDEV("div",{className:"space-y-4",children:[z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"URL"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:y,onChange:(O)=>f(O.target.value),placeholder:"e.g., https://example.com/wp-json/mcp/v1/messages",className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 font-mono text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"p-3 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded",children:[z.jsxDEV("p",{className:"text-xs text-[var(--color-text-muted)] mb-3",children:"Optional: Basic Auth credentials (will be encoded and stored securely)"},void 0,!1,void 0,this),z.jsxDEV("div",{className:"grid grid-cols-2 gap-3",children:[z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-xs text-[var(--color-text-faint)] mb-1",children:"Username"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:Y,onChange:(O)=>A(O.target.value),placeholder:"username",className:"w-full bg-[var(--color-surface)] border border-[var(--color-border-light)] rounded px-3 py-2 text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-xs text-[var(--color-text-faint)] mb-1",children:"Password"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"password",value:Z,onChange:(O)=>S(O.target.value),placeholder:"password or app key",className:"w-full bg-[var(--color-surface)] border border-[var(--color-border-light)] rounded px-3 py-2 text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("div",{className:"flex items-center justify-between mb-2",children:[z.jsxDEV("label",{className:"text-sm text-[var(--color-text-muted)]",children:"Environment Variables / Credentials"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:D,className:"text-xs text-[var(--color-accent)] hover:text-[var(--color-accent-hover)] transition",children:"+ Add Variable"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),I.length===0&&z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded p-3",children:"Add environment variables for API tokens and credentials. These are stored encrypted and passed to the server at startup."},void 0,!1,void 0,this),I.length>0&&z.jsxDEV("div",{className:"space-y-2",children:I.map((O,N)=>z.jsxDEV("div",{className:"flex gap-2",children:[z.jsxDEV("input",{type:"text",value:O.key,onChange:(m)=>P(N,"key",m.target.value),placeholder:"KEY",className:"w-1/3 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-2 py-1.5 text-sm font-mono focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"password",value:O.value,onChange:(m)=>P(N,"value",m.target.value),placeholder:"value",className:"flex-1 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-2 py-1.5 text-sm font-mono focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:()=>x(N),className:"text-[var(--color-text-muted)] hover:text-red-400 px-2 transition",children:"✕"},void 0,!1,void 0,this)]},N,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),C&&z.jsxDEV("p",{className:"text-red-400 text-sm",children:C},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"p-4 border-t border-[var(--color-border)] flex justify-end gap-2 sticky bottom-0 bg-[var(--color-surface)]",children:[z.jsxDEV("button",{onClick:G,className:"px-4 py-2 border border-[var(--color-border-light)] hover:border-[var(--color-text-muted)] rounded transition",children:"Cancel"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:g,disabled:W||!q||(X==="npm"?!U:X==="pip"?!U:X==="http"?!y:!Q),className:"px-4 py-2 bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] text-black rounded font-medium transition disabled:opacity-50",children:W?"Adding...":"Add Server"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function Uz({server:G,projects:$,onClose:H,onSaved:K}){let{authFetch:w}=c(),[X,B]=J.useState(G.name),[q,F]=J.useState(G.package||""),[U,T]=J.useState(G.command||""),[M,L]=J.useState(G.args||""),[Q,k]=J.useState(G.url||""),[y,f]=J.useState(()=>{let _=G.headers?.Authorization||"";if(_.startsWith("Basic "))try{return atob(_.slice(6)).split(":")[0]||""}catch{return""}return""}),[Y,A]=J.useState(()=>{let _=G.headers?.Authorization||"";if(_.startsWith("Basic "))try{return atob(_.slice(6)).split(":").slice(1).join(":")||""}catch{return""}return""}),[Z,S]=J.useState(()=>{return Object.entries(G.env||{}).map(([_,R])=>({key:_,value:R}))}),[I,p]=J.useState(G.project_id),[u,i]=J.useState(!1),[W,b]=J.useState(null),C=$&&$.length>0,h=G.type==="http",v=()=>{S([...Z,{key:"",value:""}])},D=(_,R,g)=>{let V=[...Z];V[_][R]=g,S(V)},P=(_)=>{S(Z.filter((R,g)=>g!==_))},x=async()=>{if(!X.trim()){b("Name is required");return}i(!0),b(null);let _={};for(let{key:R,value:g}of Z)if(R.trim())_[R.trim()]=g;try{let R={name:X.trim(),env:_};if(h){if(Q.trim())R.url=Q.trim();let V={"Content-Type":"application/json"};if(y&&Y){let O=btoa(`${y}:${Y}`);V.Authorization=`Basic ${O}`}R.headers=V}else{if(G.type==="npm"&&q.trim())R.package=q.trim();if(G.type==="pip"&&q.trim())R.package=q.trim();if(G.type==="custom"){if(U.trim())R.command=U.trim();if(M.trim())R.args=M.trim()}}R.project_id=I;let g=await w(`/api/mcp/servers/${G.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(R)});if(!g.ok){let V=await g.json();b(V.error||"Failed to save changes"),i(!1);return}if(G.status==="running"&&!h)try{await w(`/api/mcp/servers/${G.id}/stop`,{method:"POST"}),await w(`/api/mcp/servers/${G.id}/start`,{method:"POST"})}catch(V){console.error("Failed to restart server:",V)}K()}catch(R){b("Failed to save changes"),i(!1)}};return z.jsxDEV("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-[2px] z-50 flex items-center justify-center p-4",children:z.jsxDEV("div",{className:"bg-[var(--color-surface)] card w-full max-w-lg max-h-[90vh] overflow-y-auto",children:[z.jsxDEV("div",{className:"p-4 border-b border-[var(--color-border)] flex items-center justify-between sticky top-0 bg-[var(--color-surface)]",children:[z.jsxDEV("h2",{className:"text-lg font-semibold",children:"Edit MCP Server"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:H,className:"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"p-4 space-y-4",children:[z.jsxDEV("div",{className:"text-sm text-[var(--color-text-muted)] bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded p-3",children:["Type: ",z.jsxDEV("span",{className:"text-[var(--color-text-secondary)]",children:G.type},void 0,!1,void 0,this),G.package&&z.jsxDEV(z.Fragment,{children:[" • Package: ",z.jsxDEV("span",{className:"text-[var(--color-text-secondary)] font-mono",children:G.package},void 0,!1,void 0,this)]},void 0,!0,void 0,this),G.command&&z.jsxDEV(z.Fragment,{children:[" • Command: ",z.jsxDEV("span",{className:"text-[var(--color-text-secondary)] font-mono",children:G.command},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Name"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:X,onChange:(_)=>B(_.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),C&&z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Scope"},void 0,!1,void 0,this),z.jsxDEV(t,{value:I||"",onChange:(_)=>p(_||null),options:[{value:"",label:"Global (all projects)"},...$.map((_)=>({value:_.id,label:_.name}))],placeholder:"Select scope..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),G.type==="npm"&&z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"npm Package"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:q,onChange:(_)=>F(_.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 font-mono text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),G.type==="pip"&&z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"pip Package"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:q,onChange:(_)=>F(_.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 font-mono text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),h&&z.jsxDEV(z.Fragment,{children:[z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Server URL"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:Q,onChange:(_)=>k(_.target.value),placeholder:"https://example.com/mcp",className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 font-mono text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Authentication (Basic Auth)"},void 0,!1,void 0,this),z.jsxDEV("div",{className:"flex gap-2",children:[z.jsxDEV("input",{type:"text",value:y,onChange:(_)=>f(_.target.value),placeholder:"Username",className:"flex-1 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"password",value:Y,onChange:(_)=>A(_.target.value),placeholder:"Password / App Password",className:"flex-1 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"Leave empty if no authentication required"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),G.type==="custom"&&z.jsxDEV(z.Fragment,{children:[z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Command"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:U,onChange:(_)=>T(_.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 font-mono text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Arguments"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:M,onChange:(_)=>L(_.target.value),placeholder:"e.g., --token $TOKEN --verbose",className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 font-mono text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!h&&z.jsxDEV("div",{children:[z.jsxDEV("div",{className:"flex items-center justify-between mb-2",children:[z.jsxDEV("label",{className:"text-sm text-[var(--color-text-muted)]",children:"Environment Variables / Credentials"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:v,className:"text-xs text-[var(--color-accent)] hover:text-[var(--color-accent-hover)] transition",children:"+ Add Variable"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z.length===0&&z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded p-3",children:"No environment variables configured."},void 0,!1,void 0,this),Z.length>0&&z.jsxDEV("div",{className:"space-y-2",children:Z.map((_,R)=>z.jsxDEV("div",{className:"flex gap-2",children:[z.jsxDEV("input",{type:"text",value:_.key,onChange:(g)=>D(R,"key",g.target.value),placeholder:"KEY",className:"w-1/3 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-2 py-1.5 text-sm font-mono focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"password",value:_.value,onChange:(g)=>D(R,"value",g.target.value),placeholder:"value",className:"flex-1 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-2 py-1.5 text-sm font-mono focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:()=>P(R),className:"text-[var(--color-text-muted)] hover:text-red-400 px-2 transition",children:"✕"},void 0,!1,void 0,this)]},R,!0,void 0,this))},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-2",children:G.status==="running"?"Server will be automatically restarted to apply changes.":"Changes will take effect when the server is started."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),W&&z.jsxDEV("p",{className:"text-red-400 text-sm",children:W},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"p-4 border-t border-[var(--color-border)] flex justify-end gap-2 sticky bottom-0 bg-[var(--color-surface)]",children:[z.jsxDEV("button",{onClick:H,className:"px-4 py-2 border border-[var(--color-border-light)] hover:border-[var(--color-text-muted)] rounded transition",children:"Cancel"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:x,disabled:u||!X.trim(),className:"px-4 py-2 bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] text-black rounded font-medium transition disabled:opacity-50",children:u?"Saving...":"Save Changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}
|
|
1
|
+
import{j as r}from"./App.794kjn6a.js";import{t as Oz}from"./App.g1qhcmpc.js";import{O as Jz,P as o}from"./App.kpyf0grm.js";import{U as t}from"./App.6fefs2d5.js";import{$ as Qz,X as a,aa as zz,ja as c,ma as Gz}from"./App.cb1np6f0.js";var J=a(Qz(),1);var z=a(zz(),1);function Mz(){let{authFetch:G}=c(),{projects:$,currentProjectId:H}=Gz(),[K,w]=J.useState([]),[X,B]=J.useState(!0),[q,F]=J.useState(!1),[U,T]=J.useState(null),[M,L]=J.useState(null),[Q,k]=J.useState("servers"),{confirm:y,ConfirmDialog:f}=Jz(),Y=$.length>0,A=async()=>{try{let b=await(await G("/api/mcp/servers")).json();w(b.servers||[])}catch(W){console.error("Failed to fetch MCP servers:",W)}B(!1)};J.useEffect(()=>{A()},[G]);let Z=K.filter((W)=>{if(!H)return!0;if(H==="unassigned")return W.project_id===null;return W.project_id===null||W.project_id===H}),S=async(W)=>{try{await G(`/api/mcp/servers/${W}/start`,{method:"POST"}),A()}catch(b){console.error("Failed to start server:",b)}},I=async(W)=>{try{await G(`/api/mcp/servers/${W}/stop`,{method:"POST"}),A()}catch(b){console.error("Failed to stop server:",b)}},p=async(W)=>{if(!await y("Delete this MCP server?",{confirmText:"Delete",title:"Delete Server"}))return;try{if(await G(`/api/mcp/servers/${W}`,{method:"DELETE"}),M?.id===W)L(null);A()}catch(C){console.error("Failed to delete server:",C)}},u=async(W,b)=>{try{await G(`/api/mcp/servers/${W}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:b})}),A()}catch(C){console.error("Failed to rename server:",C)}},i=async(W,b)=>{try{await G(`/api/mcp/servers/${W}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)}),A()}catch(C){throw console.error("Failed to update server:",C),C}};return z.jsxDEV(z.Fragment,{children:[f,z.jsxDEV("div",{className:"flex-1 overflow-auto p-6",children:[z.jsxDEV("div",{className:"max-w-6xl",children:[z.jsxDEV("div",{className:"flex items-center justify-between mb-6",children:[z.jsxDEV("div",{children:[z.jsxDEV("h1",{className:"text-2xl font-semibold mb-1",children:"MCP Servers"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-[var(--color-text-muted)]",children:"Manage Model Context Protocol servers for tool integrations."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q==="servers"&&z.jsxDEV("button",{onClick:()=>F(!0),className:"bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] text-black px-4 py-2 rounded font-medium transition",children:"+ Add Server"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"flex gap-1 mb-6 bg-[var(--color-surface)] card p-1 w-fit",children:[z.jsxDEV("button",{onClick:()=>k("servers"),className:`px-4 py-2 rounded text-sm font-medium transition ${Q==="servers"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"My Servers"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:()=>k("hosted"),className:`px-4 py-2 rounded text-sm font-medium transition ${Q==="hosted"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"Hosted Services"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:()=>k("registry"),className:`px-4 py-2 rounded text-sm font-medium transition ${Q==="registry"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"Browse Registry"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q==="servers"&&z.jsxDEV(z.Fragment,{children:[X&&z.jsxDEV("div",{className:"text-center py-8 text-[var(--color-text-muted)]",children:"Loading..."},void 0,!1,void 0,this),!X&&Z.length===0&&K.length===0&&z.jsxDEV("div",{className:"bg-[var(--color-surface)] card p-8 text-center",children:[z.jsxDEV(Oz,{className:"w-12 h-12 text-[var(--color-border-light)] mx-auto mb-4"},void 0,!1,void 0,this),z.jsxDEV("h3",{className:"text-lg font-medium mb-2",children:"No MCP servers configured"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-[var(--color-text-muted)] mb-6 max-w-md mx-auto",children:"MCP servers extend your agents with tools like file access, web browsing, database connections, and more."},void 0,!1,void 0,this),z.jsxDEV("div",{className:"flex gap-3 justify-center",children:[z.jsxDEV("button",{onClick:()=>F(!0),className:"bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] text-black px-4 py-2 rounded font-medium transition",children:"Add Manually"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:()=>k("registry"),className:"border border-[var(--color-border-light)] hover:border-[var(--color-text-muted)] px-4 py-2 rounded font-medium transition",children:"Browse Registry"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!X&&Z.length===0&&K.length>0&&z.jsxDEV("div",{className:"bg-[var(--color-surface)] card p-6 text-center",children:z.jsxDEV("p",{className:"text-[var(--color-text-muted)]",children:"No servers match this filter."},void 0,!1,void 0,this)},void 0,!1,void 0,this),!X&&Z.length>0&&z.jsxDEV("div",{className:"flex gap-6",children:[z.jsxDEV("div",{className:`space-y-3 ${M?"w-1/2":"w-full"}`,children:Z.map((W)=>{let C=W.type==="http"&&W.url||W.status==="running",h=Y&&W.project_id?$.find((v)=>v.id===W.project_id):null;return z.jsxDEV(Wz,{server:W,project:h,selected:M?.id===W.id,onSelect:()=>L(C?W:null),onStart:()=>S(W.id),onStop:()=>I(W.id),onDelete:()=>p(W.id),onEdit:async()=>{try{let D=await(await G(`/api/mcp/servers/${W.id}`)).json();T(D.server||W)}catch{T(W)}}},W.id,!1,void 0,this)})},void 0,!1,void 0,this),M&&z.jsxDEV("div",{className:"w-1/2",children:z.jsxDEV(Xz,{server:M,onClose:()=>L(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Q==="hosted"&&z.jsxDEV(_z,{onServerAdded:A,projectId:H},void 0,!1,void 0,this),Q==="registry"&&z.jsxDEV(Zz,{onInstall:(W)=>{A(),k("servers")}},void 0,!1,void 0,this),Q==="servers"&&z.jsxDEV("div",{className:"mt-8 p-4 bg-[var(--color-surface)] card",children:[z.jsxDEV("h3",{className:"font-medium mb-2",children:"Quick Start"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)] mb-3",children:"Add an MCP server by providing its npm package name. For example:"},void 0,!1,void 0,this),z.jsxDEV("div",{className:"flex flex-wrap gap-2",children:[{name:"filesystem",pkg:"@modelcontextprotocol/server-filesystem"},{name:"fetch",pkg:"@modelcontextprotocol/server-fetch"},{name:"memory",pkg:"@modelcontextprotocol/server-memory"}].map((W)=>z.jsxDEV("code",{className:"text-xs bg-[var(--color-bg)] px-2 py-1 rounded",children:W.pkg},W.name,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),q&&z.jsxDEV(Bz,{onClose:()=>F(!1),onAdded:()=>{F(!1),A()},projects:Y?$:void 0,defaultProjectId:H&&H!=="unassigned"?H:null},void 0,!1,void 0,this),U&&z.jsxDEV(Uz,{server:U,projects:Y?$:void 0,onClose:()=>T(null),onSaved:()=>{T(null),A()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Wz({server:G,project:$,selected:H,onSelect:K,onStart:w,onStop:X,onDelete:B,onEdit:q}){let F=G.type==="http"&&G.url,U=F||G.status==="running",T=()=>{if(F)return`${G.source||"remote"} • http`;return`${G.type} • ${G.package||G.command||"custom"}${G.status==="running"&&G.port?` • :${G.port}`:""}`},M=()=>{if($)return z.jsxDEV("span",{className:"text-xs px-1.5 py-0.5 rounded",style:{backgroundColor:`${$.color}20`,color:$.color},children:$.name},void 0,!1,void 0,this);if(G.project_id===null)return z.jsxDEV("span",{className:"text-xs text-[var(--color-text-muted)] bg-[var(--color-surface-raised)] px-1.5 py-0.5 rounded",children:"Global"},void 0,!1,void 0,this);return null};return z.jsxDEV("div",{className:`bg-[var(--color-surface)] border rounded-lg p-4 cursor-pointer transition ${H?"border-[var(--color-accent)]":"border-[var(--color-border)] hover:border-[var(--color-border-light)]"}`,onClick:U?K:void 0,children:z.jsxDEV("div",{className:"flex items-center justify-between",children:[z.jsxDEV("div",{className:"flex items-center gap-3",children:[z.jsxDEV("div",{className:`w-2 h-2 rounded-full ${U?"bg-green-400":"bg-[var(--color-scrollbar)]"}`},void 0,!1,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("div",{className:"flex items-center gap-2",children:[z.jsxDEV("h3",{className:"font-medium",children:G.name},void 0,!1,void 0,this),M()]},void 0,!0,void 0,this),z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)]",children:T()},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"flex items-center gap-2",children:[z.jsxDEV("button",{onClick:(L)=>{L.stopPropagation(),q()},className:"text-sm text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)] px-3 py-1 transition",title:"Edit server settings",children:"Edit"},void 0,!1,void 0,this),F?z.jsxDEV("button",{onClick:(L)=>{L.stopPropagation(),B()},className:"text-sm text-[var(--color-text-muted)] hover:text-red-400 px-3 py-1 transition",children:"Remove"},void 0,!1,void 0,this):G.status==="running"?z.jsxDEV(z.Fragment,{children:[z.jsxDEV("button",{onClick:(L)=>{L.stopPropagation(),K()},className:"text-sm text-[var(--color-accent)] hover:text-[var(--color-accent-hover)] px-3 py-1 transition",children:"Tools"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:(L)=>{L.stopPropagation(),X()},className:"text-sm text-[var(--color-text-muted)] hover:text-red-400 px-3 py-1 transition",children:"Stop"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:(L)=>{L.stopPropagation(),B()},className:"text-sm text-[var(--color-text-muted)] hover:text-red-400 px-3 py-1 transition",children:"Delete"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):z.jsxDEV(z.Fragment,{children:[z.jsxDEV("button",{onClick:(L)=>{L.stopPropagation(),w()},className:"text-sm text-[var(--color-text-muted)] hover:text-green-400 px-3 py-1 transition",children:"Start"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:(L)=>{L.stopPropagation(),B()},className:"text-sm text-[var(--color-text-muted)] hover:text-red-400 px-3 py-1 transition",children:"Delete"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function Xz({server:G,onClose:$}){let{authFetch:H}=c(),[K,w]=J.useState([]),[X,B]=J.useState(null),[q,F]=J.useState(!0),[U,T]=J.useState(null),[M,L]=J.useState(null);return J.useEffect(()=>{(async()=>{F(!0),T(null);try{let k=await H(`/api/mcp/servers/${G.id}/tools`),y=await k.json();if(!k.ok){T(y.error||"Failed to fetch tools");return}w(y.tools||[]),B(y.serverInfo||null)}catch(k){T(`Failed to fetch tools: ${k}`)}finally{F(!1)}})()},[G.id,H]),z.jsxDEV("div",{className:"bg-[var(--color-surface)] card overflow-hidden",children:[z.jsxDEV("div",{className:"p-4 border-b border-[var(--color-border)] flex items-center justify-between",children:[z.jsxDEV("div",{children:[z.jsxDEV("h3",{className:"font-medium",children:[G.name," Tools"]},void 0,!0,void 0,this),X&&z.jsxDEV("p",{className:"text-xs text-[var(--color-text-muted)]",children:[X.name," v",X.version]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("button",{onClick:$,className:"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)] text-xl leading-none",children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"p-4 max-h-[500px] overflow-auto",children:[q&&z.jsxDEV("p",{className:"text-[var(--color-text-muted)]",children:"Loading tools..."},void 0,!1,void 0,this),U&&z.jsxDEV("div",{className:"text-red-400 text-sm p-3 bg-red-500/10 rounded",children:U},void 0,!1,void 0,this),!q&&!U&&K.length===0&&z.jsxDEV("p",{className:"text-[var(--color-text-muted)]",children:"No tools available from this server."},void 0,!1,void 0,this),!q&&!U&&K.length>0&&!M&&z.jsxDEV("div",{className:"space-y-2",children:K.map((Q)=>z.jsxDEV("button",{onClick:()=>L(Q),className:"w-full text-left p-3 bg-[var(--color-bg)] hover:bg-[var(--color-surface-raised)] border border-[var(--color-border-light)] hover:border-[var(--color-border-light)] rounded transition",children:[z.jsxDEV("div",{className:"font-medium text-sm",children:Q.name},void 0,!1,void 0,this),Q.description&&z.jsxDEV("div",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:Q.description},void 0,!1,void 0,this)]},Q.name,!0,void 0,this))},void 0,!1,void 0,this),M&&z.jsxDEV(Yz,{serverId:G.id,tool:M,onBack:()=>L(null)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Yz({serverId:G,tool:$,onBack:H}){let{authFetch:K}=c(),[w,X]=J.useState("{}"),[B,q]=J.useState(null),[F,U]=J.useState(null),[T,M]=J.useState(!1);J.useEffect(()=>{let Q=$.inputSchema;if(Q&&typeof Q==="object"&&"properties"in Q){let k=Q.properties,y={};for(let[f,Y]of Object.entries(k))if(Y.default!==void 0)y[f]=Y.default;else if(Y.type==="string")y[f]="";else if(Y.type==="number"||Y.type==="integer")y[f]=0;else if(Y.type==="boolean")y[f]=!1;else if(Y.type==="array")y[f]=[];else if(Y.type==="object")y[f]={};X(JSON.stringify(y,null,2))}},[$]);let L=async()=>{M(!0),U(null),q(null);try{let Q=JSON.parse(w),k=await K(`/api/mcp/servers/${G}/tools/${encodeURIComponent($.name)}/call`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({arguments:Q})}),y=await k.json();if(!k.ok){U(y.error||"Failed to call tool");return}q(y.result)}catch(Q){U(`Error: ${Q}`)}finally{M(!1)}};return z.jsxDEV("div",{className:"space-y-4",children:[z.jsxDEV("div",{className:"flex items-center gap-2",children:[z.jsxDEV("button",{onClick:H,className:"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)] text-sm",children:"← Back"},void 0,!1,void 0,this),z.jsxDEV("span",{className:"text-[var(--color-text-faint)]",children:"/"},void 0,!1,void 0,this),z.jsxDEV("span",{className:"font-medium",children:$.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),$.description&&z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)]",children:$.description},void 0,!1,void 0,this),$.inputSchema&&z.jsxDEV("div",{className:"text-xs",children:z.jsxDEV("details",{className:"cursor-pointer",children:[z.jsxDEV("summary",{className:"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]",children:"Input Schema"},void 0,!1,void 0,this),z.jsxDEV("pre",{className:"mt-2 p-2 bg-[var(--color-bg)] rounded text-[var(--color-text-secondary)] overflow-auto max-h-32",children:JSON.stringify($.inputSchema,null,2)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Arguments (JSON)"},void 0,!1,void 0,this),z.jsxDEV("textarea",{value:w,onChange:(Q)=>X(Q.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 h-32 font-mono text-sm focus:outline-none focus:border-[var(--color-accent)] resize-none",placeholder:"{}"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("button",{onClick:L,disabled:T,className:"w-full bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] disabled:opacity-50 text-black px-4 py-2 rounded font-medium transition",children:T?"Calling...":"Call Tool"},void 0,!1,void 0,this),F&&z.jsxDEV("div",{className:"text-red-400 text-sm p-3 bg-red-500/10 rounded",children:F},void 0,!1,void 0,this),B&&z.jsxDEV("div",{className:"space-y-2",children:[z.jsxDEV("div",{className:"text-sm text-[var(--color-text-muted)]",children:["Result ",B.isError&&z.jsxDEV("span",{className:"text-red-400",children:"(error)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:`p-3 rounded text-sm ${B.isError?"bg-red-500/10":"bg-green-500/10"}`,children:B.content.map((Q,k)=>z.jsxDEV("div",{className:"mb-2 last:mb-0",children:[Q.type==="text"&&z.jsxDEV("pre",{className:"whitespace-pre-wrap font-mono text-xs",children:Q.text},void 0,!1,void 0,this),Q.type==="image"&&Q.data&&z.jsxDEV("img",{src:`data:${Q.mimeType||"image/png"};base64,${Q.data}`,alt:"Tool result",className:"max-w-full rounded"},void 0,!1,void 0,this)]},k,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Zz({onInstall:G}){let{authFetch:$}=c(),[H,K]=J.useState(""),[w,X]=J.useState([]),[B,q]=J.useState(!1),[F,U]=J.useState(!1),[T,M]=J.useState(null),[L,Q]=J.useState(null),k=async(Y)=>{q(!0),Q(null);try{let A=await $(`/api/mcp/registry?search=${encodeURIComponent(Y)}&limit=20`),Z=await A.json();if(!A.ok)Q(Z.error||"Failed to search registry"),X([]);else X(Z.servers||[])}catch(A){Q(`Failed to search: ${A}`),X([])}finally{q(!1),U(!0)}},y=(Y)=>{if(Y.preventDefault(),H.trim())k(H.trim())};J.useEffect(()=>{k("")},[]);let f=async(Y)=>{if(!Y.npmPackage){Q("This server does not have an npm package");return}M(Y.id),Q(null);try{let A=await $("/api/mcp/servers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:Y.name,type:"npm",package:Y.npmPackage})});if(!A.ok){let Z=await A.json();Q(Z.error||"Failed to add server");return}G(Y)}catch(A){Q(`Failed to add server: ${A}`)}finally{M(null)}};return z.jsxDEV("div",{className:"space-y-6",children:[z.jsxDEV("form",{onSubmit:y,className:"flex gap-2",children:[z.jsxDEV("input",{type:"text",value:H,onChange:(Y)=>K(Y.target.value),placeholder:"Search MCP servers (e.g., filesystem, github, slack...)",className:"flex-1 bg-[var(--color-surface)] border border-[var(--color-border-light)] rounded-lg px-4 py-3 focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this),z.jsxDEV("button",{type:"submit",disabled:B,className:"bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] disabled:opacity-50 text-black px-6 py-3 rounded-lg font-medium transition",children:B?"...":"Search"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L&&z.jsxDEV("div",{className:"text-red-400 text-sm p-3 bg-red-500/10 border border-red-500/20 rounded-lg",children:L},void 0,!1,void 0,this),!B&&F&&w.length===0&&z.jsxDEV("div",{className:"text-center py-8 text-[var(--color-text-muted)]",children:"No servers found. Try a different search term."},void 0,!1,void 0,this),w.length>0&&z.jsxDEV("div",{className:"grid gap-4 md:grid-cols-2",children:w.map((Y)=>z.jsxDEV("div",{className:"bg-[var(--color-surface)] card p-4 hover:border-[var(--color-border-light)] transition",children:z.jsxDEV("div",{className:"flex items-start justify-between gap-3",children:[z.jsxDEV("div",{className:"flex-1 min-w-0",children:[z.jsxDEV("h3",{className:"font-medium truncate",children:Y.name},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)] mt-1 line-clamp-2",children:Y.description||"No description"},void 0,!1,void 0,this),z.jsxDEV("div",{className:"flex items-center gap-2 mt-2 text-xs text-[var(--color-text-faint)]",children:[Y.version&&z.jsxDEV("span",{children:["v",Y.version]},void 0,!0,void 0,this),z.jsxDEV("span",{className:`px-1.5 py-0.5 rounded ${Y.npmPackage?"bg-green-500/10 text-green-400":"bg-blue-500/10 text-blue-400"}`,children:Y.npmPackage?"npm":"remote"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("code",{className:"text-xs text-[var(--color-text-faint)] bg-[var(--color-bg)] px-2 py-0.5 rounded mt-2 inline-block truncate max-w-full",children:Y.npmPackage||Y.fullName},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"flex-shrink-0",children:Y.npmPackage?z.jsxDEV("button",{onClick:()=>f(Y),disabled:T===Y.id,className:"text-sm bg-[var(--color-surface-raised)] hover:bg-[var(--color-surface-raised)] border border-[var(--color-border-light)] hover:border-[var(--color-accent)] px-3 py-1.5 rounded transition disabled:opacity-50",children:T===Y.id?"Adding...":"Add"},void 0,!1,void 0,this):Y.repository?z.jsxDEV("a",{href:Y.repository,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-[var(--color-text-muted)] hover:text-[var(--color-accent)] transition",children:"View →"},void 0,!1,void 0,this):null},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},Y.id,!1,void 0,this))},void 0,!1,void 0,this),B&&z.jsxDEV("div",{className:"text-center py-8 text-[var(--color-text-muted)]",children:"Searching registry..."},void 0,!1,void 0,this),z.jsxDEV("div",{className:"p-4 bg-[var(--color-surface)] card text-sm text-[var(--color-text-muted)]",children:z.jsxDEV("p",{children:["Servers are sourced from the"," ",z.jsxDEV("a",{href:"https://github.com/modelcontextprotocol/servers",target:"_blank",rel:"noopener noreferrer",className:"text-[var(--color-accent)] hover:underline",children:"official MCP registry"},void 0,!1,void 0,this),". Not all servers have npm packages - some require manual setup."]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function _z({onServerAdded:G,projectId:$}){let{authFetch:H}=c(),[K,w]=J.useState("composio"),[X,B]=J.useState("configs"),[q,F]=J.useState(!1),[U,T]=J.useState(!1),[M,L]=J.useState(!1),[Q,k]=J.useState([]),[y,f]=J.useState(new Set),[Y,A]=J.useState(!0),[Z,S]=J.useState(!1),[I,p]=J.useState(null),{alert:u,AlertDialog:i}=o(),W=async()=>{try{let P=$&&$!=="unassigned"?`/api/mcp/servers?project=${encodeURIComponent($)}`:"/api/mcp/servers",[x,_]=await Promise.all([H("/api/providers"),H(P)]),R=await x.json(),g=await _.json(),V=R.providers||[],O=g.servers||[],N=new Set(O.filter((E)=>E.source==="composio"&&E.url).map((E)=>{let e=E.url.match(/\/v3\/mcp\/([^/]+)/);return e?e[1]:null}).filter(Boolean));f(N);let m=V.find((E)=>E.id==="composio"),l=V.find((E)=>E.id==="smithery"),n=V.find((E)=>E.id==="agentdojo"),d=m?.hasKey||!1,j=l?.hasKey||!1,s=n?.hasKey||!1;if(F(d),T(j),L(s),d)w("composio"),b();else if(j)w("smithery");else if(s)w("agentdojo")}catch(P){console.error("Failed to fetch providers:",P)}A(!1)},b=async()=>{S(!0);try{let P=$&&$!=="unassigned"?`?project_id=${$}`:"",_=await(await H(`/api/integrations/composio/configs${P}`)).json();k(_.configs||[])}catch(P){console.error("Failed to fetch Composio configs:",P)}S(!1)},C=async(P)=>{p(P);try{let x=$&&$!=="unassigned"?`?project_id=${$}`:"",_=await H(`/api/integrations/composio/configs/${P}/add${x}`,{method:"POST"});if(_.ok)f((R)=>new Set([...R,P])),G?.();else{let R=await _.json();await u(R.error||"Failed to add config",{title:"Error",variant:"error"})}}catch(x){console.error("Failed to add config:",x)}p(null)},h=(P)=>{return y.has(P)};if(J.useEffect(()=>{W()},[H,$]),Y)return z.jsxDEV("div",{className:"text-center py-8 text-[var(--color-text-muted)]",children:"Loading..."},void 0,!1,void 0,this);let v=q||U||M,D=[q,U,M].filter(Boolean).length;if(!v)return z.jsxDEV("div",{className:"bg-[var(--color-surface)] card p-8 text-center",children:[z.jsxDEV("p",{className:"text-[var(--color-text-secondary)] mb-2",children:"No hosted MCP services connected"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)] mb-4",children:"Connect Composio, Smithery, or AgentDojo in Settings to access cloud-based MCP servers."},void 0,!1,void 0,this),z.jsxDEV("a",{href:"/settings",className:"inline-block bg-[var(--color-surface-raised)] hover:bg-[var(--color-surface-raised)] border border-[var(--color-border-light)] hover:border-[var(--color-accent)] px-4 py-2 rounded text-sm font-medium transition",children:"Go to Settings →"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return z.jsxDEV(z.Fragment,{children:[i,z.jsxDEV("div",{className:"space-y-6",children:[D>1&&z.jsxDEV("div",{className:"flex gap-1 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded-lg p-1 w-fit",children:[q&&z.jsxDEV("button",{onClick:()=>{w("composio"),B("configs")},className:`px-4 py-2 rounded text-sm font-medium transition flex items-center gap-2 ${K==="composio"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:[z.jsxDEV("span",{className:"w-2 h-2 rounded-full bg-purple-500"},void 0,!1,void 0,this),"Composio"]},void 0,!0,void 0,this),U&&z.jsxDEV("button",{onClick:()=>w("smithery"),className:`px-4 py-2 rounded text-sm font-medium transition flex items-center gap-2 ${K==="smithery"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:[z.jsxDEV("span",{className:"w-2 h-2 rounded-full bg-blue-500"},void 0,!1,void 0,this),"Smithery"]},void 0,!0,void 0,this),M&&z.jsxDEV("button",{onClick:()=>w("agentdojo"),className:`px-4 py-2 rounded text-sm font-medium transition flex items-center gap-2 ${K==="agentdojo"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:[z.jsxDEV("span",{className:"w-2 h-2 rounded-full bg-green-500"},void 0,!1,void 0,this),"AgentDojo"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),q&&(D===1||K==="composio")&&z.jsxDEV(z.Fragment,{children:[z.jsxDEV("div",{className:"flex items-center justify-between",children:[z.jsxDEV("div",{className:"flex gap-1 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded-lg p-1",children:[z.jsxDEV("button",{onClick:()=>B("configs"),className:`px-4 py-2 rounded text-sm font-medium transition ${X==="configs"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"MCP Configs"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:()=>B("connect"),className:`px-4 py-2 rounded text-sm font-medium transition ${X==="connect"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"Connect Apps"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D===1&&z.jsxDEV("div",{className:"flex items-center gap-2 text-xs text-[var(--color-text-muted)]",children:[z.jsxDEV("span",{className:"w-2 h-2 rounded-full bg-purple-500"},void 0,!1,void 0,this),"Composio",z.jsxDEV("span",{className:"text-green-400",children:"Connected"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),X==="connect"&&z.jsxDEV("div",{children:[z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)] mb-4",children:"Connect your accounts to enable tools in MCP configs"},void 0,!1,void 0,this),z.jsxDEV(r,{providerId:"composio",projectId:$,onConnectionComplete:()=>{b()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X==="configs"&&z.jsxDEV("div",{children:[z.jsxDEV("div",{className:"flex items-center justify-between mb-3",children:[z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)]",children:"Your MCP configs from Composio"},void 0,!1,void 0,this),z.jsxDEV("div",{className:"flex items-center gap-3",children:[z.jsxDEV("button",{onClick:b,disabled:Z,className:"text-xs text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)] transition",children:Z?"Loading...":"Refresh"},void 0,!1,void 0,this),z.jsxDEV("a",{href:"https://app.composio.dev/mcp_configs",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-[var(--color-text-muted)] hover:text-[var(--color-accent)] transition",children:"Create Config →"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Z?z.jsxDEV("div",{className:"text-center py-6 text-[var(--color-text-muted)]",children:"Loading configs..."},void 0,!1,void 0,this):Q.length===0?z.jsxDEV("div",{className:"bg-[var(--color-surface)] card p-4 text-center",children:[z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)]",children:"No MCP configs found"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-2",children:["First ",z.jsxDEV("button",{onClick:()=>B("connect"),className:"text-[var(--color-accent)] hover:text-[var(--color-accent-hover)]",children:"connect some apps"},void 0,!1,void 0,this),", then create a config."]},void 0,!0,void 0,this),z.jsxDEV("a",{href:"https://app.composio.dev/mcp_configs",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-[var(--color-accent)] hover:text-[var(--color-accent-hover)] mt-2 inline-block",children:"Create in Composio →"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):z.jsxDEV("div",{className:"space-y-2",children:Q.map((P)=>{let x=h(P.id),_=I===P.id;return z.jsxDEV("div",{className:`bg-[var(--color-surface)] border rounded-lg p-3 transition flex items-center justify-between ${x?"border-green-500/30":"border-[var(--color-border)] hover:border-[var(--color-border-light)]"}`,children:[z.jsxDEV("div",{className:"flex-1 min-w-0",children:[z.jsxDEV("div",{className:"flex items-center gap-2",children:[z.jsxDEV("span",{className:"font-medium text-sm",children:P.name},void 0,!1,void 0,this),z.jsxDEV("span",{className:"text-xs text-[var(--color-text-faint)]",children:[P.toolsCount," tools"]},void 0,!0,void 0,this),x&&z.jsxDEV("span",{className:"text-xs text-green-400",children:"Added"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P.toolkits.length>0&&z.jsxDEV("div",{className:"flex flex-wrap gap-1 mt-1",children:[P.toolkits.slice(0,4).map((R)=>z.jsxDEV("span",{className:"text-xs bg-[var(--color-surface-raised)] text-[var(--color-text-muted)] px-1.5 py-0.5 rounded",children:R},R,!1,void 0,this)),P.toolkits.length>4&&z.jsxDEV("span",{className:"text-xs text-[var(--color-text-faint)]",children:["+",P.toolkits.length-4]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"flex items-center gap-2 ml-3",children:[x?z.jsxDEV("span",{className:"text-xs text-[var(--color-text-faint)] px-2 py-1",children:"In Servers"},void 0,!1,void 0,this):z.jsxDEV("button",{onClick:()=>C(P.id),disabled:_,className:"text-xs bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] text-black px-3 py-1 rounded font-medium transition disabled:opacity-50",children:_?"Adding...":"Add"},void 0,!1,void 0,this),z.jsxDEV("a",{href:`https://app.composio.dev/mcp_configs/${P.id}`,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)] transition",children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},P.id,!0,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),U&&(D===1||K==="smithery")&&z.jsxDEV("div",{children:[D===1&&z.jsxDEV("div",{className:"flex items-center gap-2 text-xs text-[var(--color-text-muted)] mb-4",children:[z.jsxDEV("span",{className:"w-2 h-2 rounded-full bg-blue-500"},void 0,!1,void 0,this),"Smithery",z.jsxDEV("span",{className:"text-green-400",children:"Connected"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"flex items-center justify-between mb-3",children:[z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)]",children:"Add MCP servers from the Smithery registry"},void 0,!1,void 0,this),z.jsxDEV("a",{href:"https://smithery.ai/servers",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-[var(--color-text-muted)] hover:text-[var(--color-accent)] transition",children:"Browse Smithery →"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"bg-[var(--color-surface)] card p-4 text-center",children:[z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)]",children:["Smithery servers can be added from the ",z.jsxDEV("strong",{children:"Browse Registry"},void 0,!1,void 0,this)," tab."]},void 0,!0,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-2",children:"Your API key will be used automatically when adding Smithery servers."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),M&&(D===1||K==="agentdojo")&&z.jsxDEV($z,{projectId:$,onServerAdded:G,showProviderBadge:D===1},void 0,!1,void 0,this),z.jsxDEV("div",{className:"p-3 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded text-xs text-[var(--color-text-muted)]",children:[z.jsxDEV("strong",{className:"text-[var(--color-text-secondary)]",children:"Tip:"},void 0,!1,void 0,this)," Connect apps first, then add MCP configs to make tools available to your agents."," · ",z.jsxDEV("a",{href:"/settings",className:"text-[var(--color-accent)] hover:text-[var(--color-accent-hover)]",children:"Add more providers in Settings"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function $z({projectId:G,onServerAdded:$,showProviderBadge:H}){let{authFetch:K}=c(),[w,X]=J.useState("configs"),[B,q]=J.useState([]),[F,U]=J.useState(new Set),[T,M]=J.useState(!1),[L,Q]=J.useState(null),{alert:k,AlertDialog:y}=o(),f=async()=>{M(!0);try{let Z=G&&G!=="unassigned"?`?project_id=${G}`:"",S=G&&G!=="unassigned"?`/api/mcp/servers?project=${encodeURIComponent(G)}`:"/api/mcp/servers";console.log(`[AgentDojo:fetchConfigs] projectId=${G} serversUrl=${S}`);let[I,p]=await Promise.all([K(`/api/integrations/agentdojo/configs${Z}`),K(S)]),u=await I.json(),i=await p.json();console.log(`[AgentDojo:fetchConfigs] configs=${(u.configs||[]).length} servers=${(i.servers||[]).length}`),q(u.configs||[]);let W=(i.servers||[]).filter((C)=>C.source==="agentdojo");console.log(`[AgentDojo:fetchConfigs] agentdojo servers found: ${W.length}`);for(let C of W){let h=C.url?.match(/\/mcp\/([^/?]+)/);console.log(`[AgentDojo:fetchConfigs] server: id=${C.id} name=${C.name} project_id=${C.project_id} url=${C.url?.substring(0,80)} extracted=${h?h[1]:C.name}`)}let b=new Set(W.map((C)=>{let h=C.url?.match(/\/mcp\/([^/?]+)/);return h?h[1]:C.name}));console.log("[AgentDojo:fetchConfigs] addedServers set:",[...b]),U(b)}catch(Z){console.error("Failed to fetch AgentDojo configs:",Z)}M(!1)},Y=async(Z)=>{Q(Z);try{let S=G&&G!=="unassigned"?`?project_id=${G}`:"";console.log(`[AgentDojo:addConfig] configId=${Z} projectParam=${S}`);let I=await K(`/api/integrations/agentdojo/configs/${Z}/add${S}`,{method:"POST"}),p=await I.json();if(console.log(`[AgentDojo:addConfig] response status=${I.status} ok=${I.ok} message=${p.message} server.id=${p.server?.id} server.project_id=${p.server?.project_id}`),I.ok){let u=B.find((W)=>W.id===Z),i=u?.slug||Z;console.log(`[AgentDojo:addConfig] marking as added: key=${i} config.slug=${u?.slug} config.id=${u?.id} config.name=${u?.name}`),U((W)=>new Set([...W,i])),$?.()}else await k(p.error||"Failed to add config",{title:"Error",variant:"error"})}catch(S){console.error("Failed to add config:",S)}Q(null)},A=(Z)=>{return F.has(Z.slug)||F.has(Z.id)||F.has(Z.name)};return J.useEffect(()=>{f()},[K,G]),z.jsxDEV(z.Fragment,{children:[y,z.jsxDEV("div",{children:[H&&z.jsxDEV("div",{className:"flex items-center gap-2 text-xs text-[var(--color-text-muted)] mb-4",children:[z.jsxDEV("span",{className:"w-2 h-2 rounded-full bg-green-500"},void 0,!1,void 0,this),"AgentDojo",z.jsxDEV("span",{className:"text-green-400",children:"Connected"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"flex items-center justify-between mb-4",children:z.jsxDEV("div",{className:"flex gap-1 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded-lg p-1",children:[z.jsxDEV("button",{onClick:()=>X("configs"),className:`px-4 py-2 rounded text-sm font-medium transition ${w==="configs"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"MCP Servers"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:()=>X("toolkits"),className:`px-4 py-2 rounded text-sm font-medium transition ${w==="toolkits"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"Browse Toolkits"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),w==="configs"&&z.jsxDEV("div",{children:[z.jsxDEV("div",{className:"flex items-center justify-between mb-3",children:[z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)]",children:"Your MCP servers from AgentDojo"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:f,disabled:T,className:"text-xs text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)] transition",children:T?"Loading...":"Refresh"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T?z.jsxDEV("div",{className:"text-center py-6 text-[var(--color-text-muted)]",children:"Loading servers..."},void 0,!1,void 0,this):B.length===0?z.jsxDEV("div",{className:"bg-[var(--color-surface)] card p-4 text-center",children:[z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)]",children:"No MCP servers found"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-2",children:[z.jsxDEV("button",{onClick:()=>X("toolkits"),className:"text-[var(--color-accent)] hover:text-[var(--color-accent-hover)]",children:"Browse toolkits"},void 0,!1,void 0,this)," ","to create a new MCP server."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):z.jsxDEV("div",{className:"space-y-2",children:B.map((Z)=>{let S=A(Z),I=L===Z.id;return z.jsxDEV("div",{className:`bg-[var(--color-surface)] border rounded-lg p-3 transition flex items-center justify-between ${S?"border-green-500/30":"border-[var(--color-border)] hover:border-[var(--color-border-light)]"}`,children:[z.jsxDEV("div",{className:"flex-1 min-w-0",children:[z.jsxDEV("div",{className:"flex items-center gap-2",children:[z.jsxDEV("span",{className:"font-medium text-sm",children:Z.name},void 0,!1,void 0,this),z.jsxDEV("span",{className:"text-xs text-[var(--color-text-faint)]",children:[Z.toolsCount," tools"]},void 0,!0,void 0,this),S&&z.jsxDEV("span",{className:"text-xs text-green-400",children:"Added"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z.mcpUrl&&z.jsxDEV("code",{className:"text-xs text-[var(--color-text-faint)] mt-1 block truncate",children:Z.mcpUrl},void 0,!1,void 0,this),!Z.mcpUrl&&Z.slug&&z.jsxDEV("code",{className:"text-xs text-[var(--color-text-faint)] mt-1 block truncate",children:Z.slug},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"flex items-center gap-2 ml-3",children:S?z.jsxDEV("span",{className:"text-xs text-[var(--color-text-faint)] px-2 py-1",children:"In Servers"},void 0,!1,void 0,this):z.jsxDEV("button",{onClick:()=>Y(Z.id),disabled:I,className:"text-xs bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] text-black px-3 py-1 rounded font-medium transition disabled:opacity-50",children:I?"Adding...":"Add"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},Z.id,!0,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),w==="toolkits"&&z.jsxDEV("div",{children:[z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)] mb-4",children:"Browse available toolkits and create MCP servers"},void 0,!1,void 0,this),z.jsxDEV(r,{providerId:"agentdojo",projectId:G,onConnectionComplete:()=>{f()}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function qz(G){let $=[],H=G,K=null,w=G.match(/(?:npx\s+-y\s+)?(@?[\w-]+\/)?(@?[\w-]+)(?:@[\w.-]+)?/);if(w){let q=w[2]||w[1];if(q)K=q.replace(/^@/,"").replace(/-mcp$/,"").replace(/-server$/,"").replace(/^server-/,"").replace(/^mcp-/,"")}let X=/--(\w+[-\w]*)\s+(YOUR_\w+|<[\w_]+>|\{[\w_]+\}|\$[\w_]+|[\w_]*(?:TOKEN|KEY|SECRET|PASSWORD|USER|ID|APIKEY)[\w_]*)/gi,B;while((B=X.exec(G))!==null){let q=B[1],F=B[2],U=q.toUpperCase().replace(/-/g,"_"),T=K?`${K.toUpperCase().replace(/-/g,"_")}_${U}`:U;$.push({key:T,flag:q}),H=H.replace(new RegExp(`(--${q}\\s+)${F.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}`,"i"),`--${q} $${T}`)}return{cleanCommand:H,credentials:$,serverName:K}}function Bz({onClose:G,onAdded:$,projects:H,defaultProjectId:K}){let{authFetch:w}=c(),[X,B]=J.useState("npm"),[q,F]=J.useState(""),[U,T]=J.useState(""),[M,L]=J.useState(""),[Q,k]=J.useState(""),[y,f]=J.useState(""),[Y,A]=J.useState(""),[Z,S]=J.useState(""),[I,p]=J.useState([]),[u,i]=J.useState(K||null),[W,b]=J.useState(!1),[C,h]=J.useState(null),v=H&&H.length>0,D=()=>{p([...I,{key:"",value:""}])},P=(O,N,m)=>{let l=[...I];l[O][N]=m,p(l)},x=(O)=>{p(I.filter((N,m)=>m!==O))},_=(O)=>{if(k(O),O.includes("YOUR_")||O.includes("<")||O.includes("{")||/TOKEN|KEY|SECRET|PASSWORD/i.test(O)){let{cleanCommand:N,credentials:m,serverName:l}=qz(O);if(!q&&l)F(l);if(m.length>0){let n=new Set(I.map((j)=>j.key)),d=m.filter((j)=>!n.has(j.key)).map((j)=>({key:j.key,value:""}));if(d.length>0)p([...I,...d]),k(N)}}},R=(O)=>{if(O.startsWith("npx ")||O.includes(" --")||O.includes("YOUR_")||O.includes("<")||/\s+(TOKEN|KEY|SECRET|PASSWORD)/i.test(O))B("command"),_(O);else if(T(O),!q&&O){let m=O.replace(/^@[\w-]+\//,"").replace(/@[\w.-]+$/,"").replace(/^server-/,"").replace(/-server$/,"").replace(/^mcp-/,"").replace(/-mcp$/,"");if(m&&m!==O)F(m)}},g=async()=>{if(!q){h("Name is required");return}if(X==="npm"&&!U){h("npm package is required");return}if(X==="pip"&&!U){h("pip package is required");return}if(X==="command"&&!Q){h("Command is required");return}if(X==="http"&&!y){h("URL is required");return}b(!0),h(null);let O={};for(let{key:N,value:m}of I)if(N.trim())O[N.trim()]=m;try{let N={name:q};if(X==="npm")N.type="npm",N.package=U;else if(X==="pip"){if(N.type="pip",N.package=U,M)N.pip_module=M}else if(X==="http"){N.type="http",N.url=y;let l={"Content-Type":"application/json"};if(Y&&Z){let n=btoa(`${Y}:${Z}`);l.Authorization=`Basic ${n}`}N.headers=l}else{let l=Q.trim().split(/\s+/);N.type="custom",N.command=l[0],N.args=l.slice(1).join(" ")}if(Object.keys(O).length>0)N.env=O;if(u)N.project_id=u;let m=await w("/api/mcp/servers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(N)});if(!m.ok){let l=await m.json();h(l.error||"Failed to add server"),b(!1);return}$()}catch(N){h("Failed to add server"),b(!1)}},V=(O,N)=>{B("npm"),F(O),T(N)};return z.jsxDEV("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-[2px] z-50 flex items-center justify-center p-4",children:z.jsxDEV("div",{className:"bg-[var(--color-surface)] card w-full max-w-lg max-h-[90vh] overflow-y-auto",children:[z.jsxDEV("div",{className:"p-4 border-b border-[var(--color-border)] flex items-center justify-between sticky top-0 bg-[var(--color-surface)]",children:[z.jsxDEV("h2",{className:"text-lg font-semibold",children:"Add MCP Server"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:G,className:"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"p-4 space-y-4",children:[z.jsxDEV("div",{children:[z.jsxDEV("p",{className:"text-sm text-[var(--color-text-muted)] mb-2",children:"Quick add:"},void 0,!1,void 0,this),z.jsxDEV("div",{className:"flex flex-wrap gap-2",children:[{name:"filesystem",pkg:"@modelcontextprotocol/server-filesystem",type:"npm"},{name:"fetch",pkg:"@modelcontextprotocol/server-fetch",type:"npm"},{name:"memory",pkg:"@modelcontextprotocol/server-memory",type:"npm"},{name:"github",pkg:"@modelcontextprotocol/server-github",type:"npm"},{name:"time",pkg:"mcp-server-time",module:"mcp_server_time",type:"pip"}].map((O)=>z.jsxDEV("button",{onClick:()=>{if(B(O.type),F(O.name),T(O.pkg),O.type==="pip"&&"module"in O)L(O.module||"");else L("")},className:"text-sm bg-[var(--color-surface-raised)] hover:bg-[var(--color-surface-raised)] px-3 py-1 rounded transition",children:O.name},O.name,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"flex gap-1 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded p-1",children:[z.jsxDEV("button",{onClick:()=>B("npm"),className:`flex-1 px-2 py-1.5 rounded text-sm transition ${X==="npm"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"npm"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:()=>B("pip"),className:`flex-1 px-2 py-1.5 rounded text-sm transition ${X==="pip"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"pip"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:()=>B("command"),className:`flex-1 px-2 py-1.5 rounded text-sm transition ${X==="command"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"Command"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:()=>B("http"),className:`flex-1 px-2 py-1.5 rounded text-sm transition ${X==="http"?"bg-[var(--color-surface-raised)] text-white":"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]"}`,children:"HTTP"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Name"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:q,onChange:(O)=>F(O.target.value),placeholder:"e.g., pushover",className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v&&z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Scope"},void 0,!1,void 0,this),z.jsxDEV(t,{value:u||"",onChange:(O)=>i(O||null),options:[{value:"",label:"Global (all projects)"},...H.map((O)=>({value:O.id,label:O.name}))],placeholder:"Select scope..."},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"Global servers are available to all agents. Project-scoped servers are only available to agents in that project."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X==="npm"&&z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"npm Package"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:U,onChange:(O)=>R(O.target.value),placeholder:"e.g., @modelcontextprotocol/server-filesystem or paste full command",className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"Package name or paste a full npx command with credentials"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X==="pip"&&z.jsxDEV("div",{className:"space-y-4",children:[z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"pip Package"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:U,onChange:(O)=>{if(T(O.target.value),!M&&O.target.value){let N=O.target.value.split("[")[0].replace(/-/g,".");L(N)}},placeholder:"e.g., late-sdk[mcp]",className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"Python package with extras, e.g., late-sdk[mcp] or mcp-server-time"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Module (optional)"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:M,onChange:(O)=>L(O.target.value),placeholder:"e.g., late.mcp",className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 font-mono text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"Python module to run with -m. Auto-detected from package name if not specified."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),X==="command"&&z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Command"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:Q,onChange:(O)=>_(O.target.value),placeholder:"e.g., npx -y pushover-mcp@latest start --token YOUR_TOKEN",className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 font-mono text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"Paste the full command - credentials like YOUR_TOKEN will be auto-extracted"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X==="http"&&z.jsxDEV("div",{className:"space-y-4",children:[z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"URL"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:y,onChange:(O)=>f(O.target.value),placeholder:"e.g., https://example.com/wp-json/mcp/v1/messages",className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 font-mono text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"p-3 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded",children:[z.jsxDEV("p",{className:"text-xs text-[var(--color-text-muted)] mb-3",children:"Optional: Basic Auth credentials (will be encoded and stored securely)"},void 0,!1,void 0,this),z.jsxDEV("div",{className:"grid grid-cols-2 gap-3",children:[z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-xs text-[var(--color-text-faint)] mb-1",children:"Username"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:Y,onChange:(O)=>A(O.target.value),placeholder:"username",className:"w-full bg-[var(--color-surface)] border border-[var(--color-border-light)] rounded px-3 py-2 text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-xs text-[var(--color-text-faint)] mb-1",children:"Password"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"password",value:Z,onChange:(O)=>S(O.target.value),placeholder:"password or app key",className:"w-full bg-[var(--color-surface)] border border-[var(--color-border-light)] rounded px-3 py-2 text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("div",{className:"flex items-center justify-between mb-2",children:[z.jsxDEV("label",{className:"text-sm text-[var(--color-text-muted)]",children:"Environment Variables / Credentials"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:D,className:"text-xs text-[var(--color-accent)] hover:text-[var(--color-accent-hover)] transition",children:"+ Add Variable"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),I.length===0&&z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded p-3",children:"Add environment variables for API tokens and credentials. These are stored encrypted and passed to the server at startup."},void 0,!1,void 0,this),I.length>0&&z.jsxDEV("div",{className:"space-y-2",children:I.map((O,N)=>z.jsxDEV("div",{className:"flex gap-2",children:[z.jsxDEV("input",{type:"text",value:O.key,onChange:(m)=>P(N,"key",m.target.value),placeholder:"KEY",className:"w-1/3 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-2 py-1.5 text-sm font-mono focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"password",value:O.value,onChange:(m)=>P(N,"value",m.target.value),placeholder:"value",className:"flex-1 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-2 py-1.5 text-sm font-mono focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:()=>x(N),className:"text-[var(--color-text-muted)] hover:text-red-400 px-2 transition",children:"✕"},void 0,!1,void 0,this)]},N,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),C&&z.jsxDEV("p",{className:"text-red-400 text-sm",children:C},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"p-4 border-t border-[var(--color-border)] flex justify-end gap-2 sticky bottom-0 bg-[var(--color-surface)]",children:[z.jsxDEV("button",{onClick:G,className:"px-4 py-2 border border-[var(--color-border-light)] hover:border-[var(--color-text-muted)] rounded transition",children:"Cancel"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:g,disabled:W||!q||(X==="npm"?!U:X==="pip"?!U:X==="http"?!y:!Q),className:"px-4 py-2 bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] text-black rounded font-medium transition disabled:opacity-50",children:W?"Adding...":"Add Server"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function Uz({server:G,projects:$,onClose:H,onSaved:K}){let{authFetch:w}=c(),[X,B]=J.useState(G.name),[q,F]=J.useState(G.package||""),[U,T]=J.useState(G.command||""),[M,L]=J.useState(G.args||""),[Q,k]=J.useState(G.url||""),[y,f]=J.useState(()=>{let _=G.headers?.Authorization||"";if(_.startsWith("Basic "))try{return atob(_.slice(6)).split(":")[0]||""}catch{return""}return""}),[Y,A]=J.useState(()=>{let _=G.headers?.Authorization||"";if(_.startsWith("Basic "))try{return atob(_.slice(6)).split(":").slice(1).join(":")||""}catch{return""}return""}),[Z,S]=J.useState(()=>{return Object.entries(G.env||{}).map(([_,R])=>({key:_,value:R}))}),[I,p]=J.useState(G.project_id),[u,i]=J.useState(!1),[W,b]=J.useState(null),C=$&&$.length>0,h=G.type==="http",v=()=>{S([...Z,{key:"",value:""}])},D=(_,R,g)=>{let V=[...Z];V[_][R]=g,S(V)},P=(_)=>{S(Z.filter((R,g)=>g!==_))},x=async()=>{if(!X.trim()){b("Name is required");return}i(!0),b(null);let _={};for(let{key:R,value:g}of Z)if(R.trim())_[R.trim()]=g;try{let R={name:X.trim(),env:_};if(h){if(Q.trim())R.url=Q.trim();let V={"Content-Type":"application/json"};if(y&&Y){let O=btoa(`${y}:${Y}`);V.Authorization=`Basic ${O}`}R.headers=V}else{if(G.type==="npm"&&q.trim())R.package=q.trim();if(G.type==="pip"&&q.trim())R.package=q.trim();if(G.type==="custom"){if(U.trim())R.command=U.trim();if(M.trim())R.args=M.trim()}}R.project_id=I;let g=await w(`/api/mcp/servers/${G.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(R)});if(!g.ok){let V=await g.json();b(V.error||"Failed to save changes"),i(!1);return}if(G.status==="running"&&!h)try{await w(`/api/mcp/servers/${G.id}/stop`,{method:"POST"}),await w(`/api/mcp/servers/${G.id}/start`,{method:"POST"})}catch(V){console.error("Failed to restart server:",V)}K()}catch(R){b("Failed to save changes"),i(!1)}};return z.jsxDEV("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-[2px] z-50 flex items-center justify-center p-4",children:z.jsxDEV("div",{className:"bg-[var(--color-surface)] card w-full max-w-lg max-h-[90vh] overflow-y-auto",children:[z.jsxDEV("div",{className:"p-4 border-b border-[var(--color-border)] flex items-center justify-between sticky top-0 bg-[var(--color-surface)]",children:[z.jsxDEV("h2",{className:"text-lg font-semibold",children:"Edit MCP Server"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:H,className:"text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"p-4 space-y-4",children:[z.jsxDEV("div",{className:"text-sm text-[var(--color-text-muted)] bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded p-3",children:["Type: ",z.jsxDEV("span",{className:"text-[var(--color-text-secondary)]",children:G.type},void 0,!1,void 0,this),G.package&&z.jsxDEV(z.Fragment,{children:[" • Package: ",z.jsxDEV("span",{className:"text-[var(--color-text-secondary)] font-mono",children:G.package},void 0,!1,void 0,this)]},void 0,!0,void 0,this),G.command&&z.jsxDEV(z.Fragment,{children:[" • Command: ",z.jsxDEV("span",{className:"text-[var(--color-text-secondary)] font-mono",children:G.command},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Name"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:X,onChange:(_)=>B(_.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),C&&z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Scope"},void 0,!1,void 0,this),z.jsxDEV(t,{value:I||"",onChange:(_)=>p(_||null),options:[{value:"",label:"Global (all projects)"},...$.map((_)=>({value:_.id,label:_.name}))],placeholder:"Select scope..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),G.type==="npm"&&z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"npm Package"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:q,onChange:(_)=>F(_.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 font-mono text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),G.type==="pip"&&z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"pip Package"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:q,onChange:(_)=>F(_.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 font-mono text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),h&&z.jsxDEV(z.Fragment,{children:[z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Server URL"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:Q,onChange:(_)=>k(_.target.value),placeholder:"https://example.com/mcp",className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 font-mono text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Authentication (Basic Auth)"},void 0,!1,void 0,this),z.jsxDEV("div",{className:"flex gap-2",children:[z.jsxDEV("input",{type:"text",value:y,onChange:(_)=>f(_.target.value),placeholder:"Username",className:"flex-1 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"password",value:Y,onChange:(_)=>A(_.target.value),placeholder:"Password / App Password",className:"flex-1 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"Leave empty if no authentication required"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),G.type==="custom"&&z.jsxDEV(z.Fragment,{children:[z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Command"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:U,onChange:(_)=>T(_.target.value),className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 font-mono text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{children:[z.jsxDEV("label",{className:"block text-sm text-[var(--color-text-muted)] mb-1",children:"Arguments"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"text",value:M,onChange:(_)=>L(_.target.value),placeholder:"e.g., --token $TOKEN --verbose",className:"w-full bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-3 py-2 font-mono text-sm focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),!h&&z.jsxDEV("div",{children:[z.jsxDEV("div",{className:"flex items-center justify-between mb-2",children:[z.jsxDEV("label",{className:"text-sm text-[var(--color-text-muted)]",children:"Environment Variables / Credentials"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:v,className:"text-xs text-[var(--color-accent)] hover:text-[var(--color-accent-hover)] transition",children:"+ Add Variable"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z.length===0&&z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded p-3",children:"No environment variables configured."},void 0,!1,void 0,this),Z.length>0&&z.jsxDEV("div",{className:"space-y-2",children:Z.map((_,R)=>z.jsxDEV("div",{className:"flex gap-2",children:[z.jsxDEV("input",{type:"text",value:_.key,onChange:(g)=>D(R,"key",g.target.value),placeholder:"KEY",className:"w-1/3 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-2 py-1.5 text-sm font-mono focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this),z.jsxDEV("input",{type:"password",value:_.value,onChange:(g)=>D(R,"value",g.target.value),placeholder:"value",className:"flex-1 bg-[var(--color-bg)] border border-[var(--color-border-light)] rounded px-2 py-1.5 text-sm font-mono focus:outline-none focus:border-[var(--color-accent)]"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:()=>P(R),className:"text-[var(--color-text-muted)] hover:text-red-400 px-2 transition",children:"✕"},void 0,!1,void 0,this)]},R,!0,void 0,this))},void 0,!1,void 0,this),z.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-2",children:G.status==="running"?"Server will be automatically restarted to apply changes.":"Changes will take effect when the server is started."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),W&&z.jsxDEV("p",{className:"text-red-400 text-sm",children:W},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV("div",{className:"p-4 border-t border-[var(--color-border)] flex justify-end gap-2 sticky bottom-0 bg-[var(--color-surface)]",children:[z.jsxDEV("button",{onClick:H,className:"px-4 py-2 border border-[var(--color-border-light)] hover:border-[var(--color-text-muted)] rounded transition",children:"Cancel"},void 0,!1,void 0,this),z.jsxDEV("button",{onClick:x,disabled:u||!X.trim(),className:"px-4 py-2 bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] text-black rounded font-medium transition disabled:opacity-50",children:u?"Saving...":"Save Changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}
|
|
2
2
|
export{Mz as i};
|
|
3
3
|
|
|
4
4
|
//# debugId=C82C00D733F3FB7164756E2164756E21
|