modular-studio 1.0.4 → 1.0.6
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/README.md +122 -41
- package/dist/assets/Badge-DrUmDAXz.js +1 -0
- package/dist/assets/Input-ndEGQSgx.js +1 -0
- package/dist/assets/KnowledgeTab-CxlC76Rf.js +4 -0
- package/dist/assets/MemoryTab-CUScYWs9.js +16 -0
- package/dist/assets/QualificationTab-BqnWSQHm.js +1 -0
- package/dist/assets/ReviewTab-DKYl6cR9.js +103 -0
- package/dist/assets/Section-CgmwAj_2.js +1 -0
- package/dist/assets/TestTab-iJ2vCf9l.js +33 -0
- package/dist/assets/ToolsTab-C10Ulm8b.js +1 -0
- package/dist/assets/conversationStore-CkfEU2eV.js +1 -0
- package/dist/assets/icons-MKpPNvV8.js +1 -0
- package/dist/assets/index-B_ip7Amg.css +1 -0
- package/dist/assets/index-gBy3427k.js +143 -0
- package/dist/assets/{jszip.min-BK6ZQWkj.js → jszip.min-wf-D3Ix_.js} +1 -1
- package/dist/assets/markdown-DWF7F0i0.js +29 -0
- package/dist/assets/services-CTWXQK6j.js +356 -0
- package/dist/assets/stores-CeKWz7ou.js +1 -0
- package/dist/assets/vendor-D1h_O76p.js +9 -0
- package/dist/index.html +20 -16
- package/dist-server/bin/modular-mcp.js +0 -1
- package/dist-server/bin/modular-studio.js +0 -1
- package/dist-server/server/config.js +0 -1
- package/dist-server/server/data/mcp-tokens.json +3 -3
- package/dist-server/server/index.d.ts.map +1 -1
- package/dist-server/server/index.js +6 -1
- package/dist-server/server/mcp/manager.d.ts.map +1 -1
- package/dist-server/server/mcp/manager.js +16 -3
- package/dist-server/server/mcp/modular-server.js +0 -1
- package/dist-server/server/mcp/transport.js +0 -1
- package/dist-server/server/routes/agent-sdk.js +0 -1
- package/dist-server/server/routes/agents.d.ts +9 -5
- package/dist-server/server/routes/agents.d.ts.map +1 -1
- package/dist-server/server/routes/agents.js +108 -8
- package/dist-server/server/routes/auth-codex.js +0 -1
- package/dist-server/server/routes/cache.d.ts +3 -0
- package/dist-server/server/routes/cache.d.ts.map +1 -0
- package/dist-server/server/routes/cache.js +55 -0
- package/dist-server/server/routes/capabilities.js +0 -1
- package/dist-server/server/routes/claude-config.js +0 -1
- package/dist-server/server/routes/connectors.d.ts.map +1 -1
- package/dist-server/server/routes/connectors.js +224 -1
- package/dist-server/server/routes/conversations.js +0 -1
- package/dist-server/server/routes/embeddings.js +0 -1
- package/dist-server/server/routes/health.js +0 -1
- package/dist-server/server/routes/knowledge.js +0 -1
- package/dist-server/server/routes/lessons.d.ts +3 -0
- package/dist-server/server/routes/lessons.d.ts.map +1 -0
- package/dist-server/server/routes/lessons.js +46 -0
- package/dist-server/server/routes/llm.js +0 -1
- package/dist-server/server/routes/mcp-oauth.js +0 -1
- package/dist-server/server/routes/mcp.js +0 -1
- package/dist-server/server/routes/memory.d.ts +3 -0
- package/dist-server/server/routes/memory.d.ts.map +1 -0
- package/dist-server/server/routes/memory.js +314 -0
- package/dist-server/server/routes/pipeline.js +0 -1
- package/dist-server/server/routes/providers.js +0 -1
- package/dist-server/server/routes/qualification.d.ts.map +1 -1
- package/dist-server/server/routes/qualification.js +341 -75
- package/dist-server/server/routes/repo-index.d.ts.map +1 -1
- package/dist-server/server/routes/repo-index.js +7 -1
- package/dist-server/server/routes/runtime.js +0 -1
- package/dist-server/server/routes/skills-search.d.ts.map +1 -1
- package/dist-server/server/routes/skills-search.js +198 -8
- package/dist-server/server/routes/worktrees.js +0 -1
- package/dist-server/server/services/__tests__/embeddingService.test.js +0 -1
- package/dist-server/server/services/adapters/hindsightAdapter.d.ts +28 -0
- package/dist-server/server/services/adapters/hindsightAdapter.d.ts.map +1 -0
- package/dist-server/server/services/adapters/hindsightAdapter.js +63 -0
- package/dist-server/server/services/adapters/postgresAdapter.d.ts +29 -0
- package/dist-server/server/services/adapters/postgresAdapter.d.ts.map +1 -0
- package/dist-server/server/services/adapters/postgresAdapter.js +224 -0
- package/dist-server/server/services/adapters/sqliteAdapter.d.ts +28 -0
- package/dist-server/server/services/adapters/sqliteAdapter.d.ts.map +1 -0
- package/dist-server/server/services/adapters/sqliteAdapter.js +219 -0
- package/dist-server/server/services/adapters/storageAdapter.d.ts +22 -0
- package/dist-server/server/services/adapters/storageAdapter.d.ts.map +1 -0
- package/dist-server/server/services/adapters/storageAdapter.js +1 -0
- package/dist-server/server/services/agentRunner.js +0 -1
- package/dist-server/server/services/agentStore.d.ts +19 -3
- package/dist-server/server/services/agentStore.d.ts.map +1 -1
- package/dist-server/server/services/agentStore.js +117 -23
- package/dist-server/server/services/contentStore.js +0 -1
- package/dist-server/server/services/correctionDetector.d.ts +22 -0
- package/dist-server/server/services/correctionDetector.d.ts.map +1 -0
- package/dist-server/server/services/correctionDetector.js +91 -0
- package/dist-server/server/services/embeddingService.d.ts +2 -0
- package/dist-server/server/services/embeddingService.d.ts.map +1 -1
- package/dist-server/server/services/embeddingService.js +30 -19
- package/dist-server/server/services/factExtractor.js +0 -1
- package/dist-server/server/services/githubIndexer.js +0 -1
- package/dist-server/server/services/hindsightClient.d.ts +15 -0
- package/dist-server/server/services/hindsightClient.d.ts.map +1 -0
- package/dist-server/server/services/hindsightClient.js +47 -0
- package/dist-server/server/services/lessonExtractor.d.ts +19 -0
- package/dist-server/server/services/lessonExtractor.d.ts.map +1 -0
- package/dist-server/server/services/lessonExtractor.js +87 -0
- package/dist-server/server/services/mcpOAuth.js +0 -1
- package/dist-server/server/services/memoryScorer.js +0 -1
- package/dist-server/server/services/repoIndexer.js +0 -1
- package/dist-server/server/services/responseCache.d.ts +24 -0
- package/dist-server/server/services/responseCache.d.ts.map +1 -0
- package/dist-server/server/services/responseCache.js +163 -0
- package/dist-server/server/services/sqliteStore.d.ts +8 -0
- package/dist-server/server/services/sqliteStore.d.ts.map +1 -1
- package/dist-server/server/services/sqliteStore.js +53 -14
- package/dist-server/server/services/teamRunner.js +0 -1
- package/dist-server/server/services/worktreeManager.js +0 -1
- package/dist-server/server/types.d.ts +5 -0
- package/dist-server/server/types.d.ts.map +1 -1
- package/dist-server/server/types.js +0 -1
- package/dist-server/server/utils/pathSecurity.js +0 -1
- package/dist-server/src/services/budgetAllocator.js +0 -1
- package/dist-server/src/services/contradictionDetector.js +0 -1
- package/dist-server/src/services/treeIndexer.js +0 -1
- package/dist-server/src/store/knowledgeBase.d.ts +11 -0
- package/dist-server/src/store/knowledgeBase.d.ts.map +1 -1
- package/dist-server/src/store/knowledgeBase.js +13 -1
- package/dist-server/src/store/lessonStore.d.ts +26 -0
- package/dist-server/src/store/lessonStore.d.ts.map +1 -0
- package/dist-server/src/store/lessonStore.js +64 -0
- package/dist-server/src/store/memoryStore.d.ts +118 -0
- package/dist-server/src/store/memoryStore.d.ts.map +1 -0
- package/dist-server/src/store/memoryStore.js +272 -0
- package/dist-server/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +9 -1
- package/dist/assets/graphPopulator-B3rQxb5A.js +0 -1
- package/dist/assets/index-BA_J-aHx.js +0 -686
- package/dist/assets/index-C7vpqKVZ.css +0 -1
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TestTab-iJ2vCf9l.js","assets/vendor-D1h_O76p.js","assets/conversationStore-CkfEU2eV.js","assets/stores-CeKWz7ou.js","assets/services-CTWXQK6j.js","assets/icons-MKpPNvV8.js","assets/markdown-DWF7F0i0.js","assets/QualificationTab-BqnWSQHm.js","assets/Input-ndEGQSgx.js","assets/Badge-DrUmDAXz.js","assets/KnowledgeTab-CxlC76Rf.js","assets/ToolsTab-C10Ulm8b.js","assets/MemoryTab-CUScYWs9.js","assets/Section-CgmwAj_2.js","assets/ReviewTab-DKYl6cR9.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as u,j as e,a as Ne,c as Yt}from"./vendor-D1h_O76p.js";import{u as $,a as ue,A as J,R as qt,M as Xe,b as je,c as q,d as fe,g as Jt,s as Qt,e as Q,K as Zt,O as Xt,f as es,D as ts,h as ve,i as ss,j as ns,k as os,_ as ce,l as he}from"./services-CTWXQK6j.js";import{c as Ee}from"./stores-CeKWz7ou.js";import{X as ae,C as Me,a as ne,A as rs,G as as,R as is,S as We,b as gt,M as ht,c as ls,P as Ue,Z as ge,B as He,d as yt,H as cs,e as ds,T as bt,F as us,f as kt,D as Ve,g as ps,h as Te,i as Oe,j as ms,k as fs,l as jt,m as xs,n as Fe,W as vt,o as gs,p as Ye,q as hs,r as ys,s as $e,t as bs,u as ks,v as js,w as wt,I as vs,x as le,y as ws,z as Ss,E as St,J as Ct,K as Cs,L as Ns,N as Es,O as qe,Q as X,U as Z,V as Nt,Y as xe,_ as Et,$ as Mt,a0 as re,a1 as Ms,a2 as Ts,a3 as Fs,a4 as $s,a5 as Is,a6 as Ge,a7 as _e,a8 as Tt,a9 as As,aa as Ds,ab as Je,ac as Ls,ad as Ps,ae as Ft,af as $t,ag as It,ah as At,ai as et,aj as zs,ak as Rs,al as Bs,am as Os,an as Gs}from"./icons-MKpPNvV8.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))n(a);new MutationObserver(a=>{for(const r of a)if(r.type==="childList")for(const i of r.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&n(i)}).observe(document,{childList:!0,subtree:!0});function o(a){const r={};return a.integrity&&(r.integrity=a.integrity),a.referrerPolicy&&(r.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?r.credentials="include":a.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function n(a){if(a.ep)return;a.ep=!0;const r=o(a);fetch(a.href,r)}})();const _s=typeof localStorage<"u"?localStorage.getItem("modular-theme"):null,Se=Ee((t,s)=>({theme:_s==="light"?"light":"dark",toggleTheme:()=>{const o=s().theme==="dark"?"light":"dark";localStorage.setItem("modular-theme",o),t({theme:o})}})),Ks={bg:"#111114",surface:"rgba(28, 28, 32, 0.9)",surfaceOpaque:"#1c1c20",surfaceElevated:"#25252a",surfaceHover:"#1f1f24",border:"#2a2a30",borderSubtle:"#222226",textPrimary:"#f0f0f0",textSecondary:"#888",textMuted:"#666",textDim:"#555",textFaint:"#444",inputBg:"#141417",badgeBg:"#25252a",dotGrid:"#222228",minimapBg:"#111114",minimapMask:"rgba(17,17,20,0.8)",minimapNode:"#25252a",controlsBg:"#1c1c20",controlsBorder:"#2a2a30",tileActiveBg:"#25252a",tileHoverBg:"#1f1f24",tileBg:"#1c1c20",tileBorderHover:"#3a3a40",agentBg:"#151210",agentBorder:"#2d2720",agentLabel:"#9a8e82",agentMeta:"#6d6058",agentArrow:"#6d6058",agentLineNum:"#2d2720",agentText:"#8a7e72",tokenLabel:"#999",tokenDivider:"#777",tokenTrackBg:"#25252a",jackRingBase:"#0a0a0a",jackLabelOnRing:"#999",jackLabelBeside:"#666",cableShadow:"rgba(0,0,0,0.4)",cableHighlight:"rgba(255,255,255,0.06)",responseBg:"rgba(28, 28, 32, 0.9)",responseText:"#bbb",statusSuccess:"#00ff88",statusError:"#ff3344",statusWarning:"#ffaa00",statusInfo:"#3498db",statusSuccessBg:"rgba(0,255,136,0.07)",statusErrorBg:"rgba(255,51,68,0.08)",statusWarningBg:"rgba(255,170,0,0.08)",statusSuccessGlow:"0 0 6px rgba(0,255,136,0.5)",statusErrorGlow:"0 0 6px rgba(255,51,68,0.5)",statusWarningGlow:"0 0 6px rgba(255,170,0,0.5)",cableSkills:"#f1c40f",cableMcp:"#2ecc71",cableKnowledge:"#e74c3c"},Ws={bg:"#f0f1f3",surface:"rgba(255,255,255,0.95)",surfaceOpaque:"#ffffff",surfaceElevated:"#eeeef2",surfaceHover:"#f5f5f8",border:"#ccccd4",borderSubtle:"#dddde2",textPrimary:"#1a1a20",textSecondary:"#3a3a45",textMuted:"#555560",textDim:"#5c5c66",textFaint:"#71717a",inputBg:"#f5f5f8",badgeBg:"#e5e5ea",dotGrid:"#d0d0d8",minimapBg:"#f0f1f3",minimapMask:"rgba(240,241,243,0.8)",minimapNode:"#dddde2",controlsBg:"#ffffff",controlsBorder:"#ccccd4",tileActiveBg:"#e8e8ee",tileHoverBg:"#f0f0f5",tileBg:"#ffffff",tileBorderHover:"#bbbbc4",agentBg:"#f8f8fa",agentBorder:"#dddde2",agentLabel:"#555560",agentMeta:"#888890",agentArrow:"#888890",agentLineNum:"#ccccd4",agentText:"#666670",tokenLabel:"#555560",tokenDivider:"#888890",tokenTrackBg:"#dddde2",jackRingBase:"#e8e8ee",jackLabelOnRing:"#555",jackLabelBeside:"#777",cableShadow:"rgba(0,0,0,0.12)",cableHighlight:"rgba(255,255,255,0.3)",responseBg:"rgba(255,255,255,0.95)",responseText:"#444",statusSuccess:"#16a34a",statusError:"#dc2626",statusWarning:"#ca8a04",statusInfo:"#2563eb",statusSuccessBg:"rgba(22,163,74,0.08)",statusErrorBg:"rgba(220,38,38,0.08)",statusWarningBg:"rgba(202,138,4,0.08)",statusSuccessGlow:"0 0 6px rgba(22,163,74,0.3)",statusErrorGlow:"0 0 6px rgba(220,38,38,0.3)",statusWarningGlow:"0 0 6px rgba(202,138,4,0.3)",cableSkills:"#B45309",cableMcp:"#16a34a",cableKnowledge:"#dc2626"};function W(){const t=Se(o=>o.theme);return{...t==="dark"?Ks:Ws,isDark:t==="dark"}}function Us(t,s){const o=[];return t.selectedModel!==s.selectedModel&&o.push({category:"meta",field:"model",type:"modified",before:t.selectedModel,after:s.selectedModel,description:`Model: ${t.selectedModel} → ${s.selectedModel}`}),t.agentConfig.temperature!==s.agentConfig.temperature&&o.push({category:"meta",field:"temperature",type:"modified",before:t.agentConfig.temperature,after:s.agentConfig.temperature,description:`Temperature: ${t.agentConfig.temperature} → ${s.agentConfig.temperature}`}),t.agentConfig.maxTokens!==s.agentConfig.maxTokens&&o.push({category:"meta",field:"maxTokens",type:"modified",before:t.agentConfig.maxTokens,after:s.agentConfig.maxTokens,description:`Max tokens: ${t.agentConfig.maxTokens} → ${s.agentConfig.maxTokens}`}),t.agentConfig.planningMode!==s.agentConfig.planningMode&&o.push({category:"meta",field:"planningMode",type:"modified",before:t.agentConfig.planningMode,after:s.agentConfig.planningMode,description:`Planning mode: ${t.agentConfig.planningMode} → ${s.agentConfig.planningMode}`}),o}function Hs(t,s){const o=[],n=t.instructionState,a=s.instructionState;return n.persona!==a.persona&&o.push({category:"persona",field:"persona",type:"modified",before:n.persona,after:a.persona,description:"Persona updated"}),n.tone!==a.tone&&o.push({category:"persona",field:"tone",type:"modified",before:n.tone,after:a.tone,description:`Tone: ${n.tone} → ${a.tone}`}),n.expertise!==a.expertise&&o.push({category:"persona",field:"expertise",type:"modified",before:n.expertise,after:a.expertise,description:`Expertise: ${n.expertise} → ${a.expertise}`}),n.objectives.primary!==a.objectives.primary&&o.push({category:"persona",field:"primary-objective",type:"modified",before:n.objectives.primary,after:a.objectives.primary,description:"Primary objective changed"}),t.prompt!==s.prompt&&o.push({category:"persona",field:"prompt",type:"modified",before:t.prompt,after:s.prompt,description:"Prompt changed"}),o}function Vs(t,s){const o=[],n=t.instructionState.constraints,a=s.instructionState.constraints,r=["neverMakeUp","askBeforeActions","stayInScope","useOnlyTools","limitWords","wordLimit","customConstraints","scopeDefinition"];for(const i of r)n[i]!==a[i]&&o.push({category:"constraints",field:i,type:"modified",before:n[i],after:a[i],description:`"${i}" changed`});return o}function Ys(t,s){const o=[],n=new Map(t.workflowSteps.map(r=>[r.id,r])),a=new Map(s.workflowSteps.map(r=>[r.id,r]));for(const[r,i]of a){const l=n.get(r);l?JSON.stringify(l)!==JSON.stringify(i)&&o.push({category:"workflow",field:r,type:"modified",before:l,after:i,description:`Step "${i.label}" modified`}):o.push({category:"workflow",field:r,type:"added",after:i,description:`Step "${i.label}" added`})}for(const[r,i]of n)a.has(r)||o.push({category:"workflow",field:r,type:"removed",before:i,description:`Step "${i.label}" removed`});return o}function qs(t,s){const o=[],n=new Map(t.channels.map(r=>[r.sourceId,r])),a=new Map(s.channels.map(r=>[r.sourceId,r]));for(const[r,i]of a){const l=n.get(r);l?(l.depth!==i.depth||l.enabled!==i.enabled)&&o.push({category:"knowledge",field:r,type:"modified",before:l,after:i,description:`"${i.name}" modified`}):o.push({category:"knowledge",field:r,type:"added",after:i,description:`"${i.name}" added`})}for(const[r,i]of n)a.has(r)||o.push({category:"knowledge",field:r,type:"removed",before:i,description:`"${i.name}" removed`});return o}function Js(t,s){const o=[],n=new Set(t.skills.filter(l=>l.added).map(l=>l.id)),a=new Set(s.skills.filter(l=>l.added).map(l=>l.id));for(const l of s.skills.filter(c=>c.added&&!n.has(c.id)))o.push({category:"tools",field:`skill:${l.id}`,type:"added",after:l,description:`Skill "${l.name}" added`});for(const l of t.skills.filter(c=>c.added&&!a.has(c.id)))o.push({category:"tools",field:`skill:${l.id}`,type:"removed",before:l,description:`Skill "${l.name}" removed`});const r=new Set(t.mcpServers.filter(l=>l.added).map(l=>l.id)),i=new Set(s.mcpServers.filter(l=>l.added).map(l=>l.id));for(const l of s.mcpServers.filter(c=>c.added&&!r.has(c.id)))o.push({category:"tools",field:`mcp:${l.id}`,type:"added",after:l,description:`MCP "${l.name}" added`});for(const l of t.mcpServers.filter(c=>c.added&&!i.has(c.id)))o.push({category:"tools",field:`mcp:${l.id}`,type:"removed",before:l,description:`MCP "${l.name}" removed`});return o}function tt(t){const s={},o={added:0,removed:0,modified:0};for(const n of t)s[n.category]=(s[n.category]??0)+1,o[n.type]++;return{totalChanges:t.length,categoryCounts:s,changeTypes:o}}function Qs(t,s,o,n){if(!t||!s)return{versionA:o,versionB:n,changes:[],summary:tt([])};const a=[...Us(t,s),...Hs(t,s),...Vs(t,s),...Ys(t,s),...qs(t,s),...Js(t,s)];return{versionA:o,versionB:n,changes:a,summary:tt(a)}}const Zs={meta:"Model & Config",persona:"Persona & Objectives",constraints:"Constraints",workflow:"Workflow",knowledge:"Knowledge",tools:"Tools & MCP"},st={added:{bg:"rgba(0,200,100,0.08)",text:"#00c864",prefix:"+"},removed:{bg:"rgba(255,60,60,0.08)",text:"#ff4444",prefix:"−"},modified:{bg:"rgba(255,160,0,0.1)",text:"#ffa000",prefix:"~"}},Xs=["meta","persona","constraints","workflow","knowledge","tools"];function ye(t){return t==null?"(empty)":typeof t=="boolean"?t?"on":"off":typeof t=="object"?JSON.stringify(t,null,2):String(t)}function en({change:t,t:s}){const o=st[t.type]??st.modified;return e.jsxs("div",{className:"rounded-md p-2.5 mb-1.5",style:{background:o.bg},children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:"text-[11px] font-bold font-mono",style:{color:o.text},children:o.prefix}),e.jsx("span",{className:"text-[12px] font-medium",style:{color:s.textPrimary},children:t.description})]}),t.type==="modified"&&e.jsxs("div",{className:"mt-1.5 grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"rounded p-1.5",style:{background:"rgba(255,60,60,0.06)"},children:[e.jsx("div",{className:"text-[10px] mb-0.5",style:{color:s.textFaint},children:"BEFORE"}),e.jsx("div",{className:"text-[11px] font-mono break-all",style:{color:"#ff6666"},children:ye(t.before)})]}),e.jsxs("div",{className:"rounded p-1.5",style:{background:"rgba(0,200,100,0.06)"},children:[e.jsx("div",{className:"text-[10px] mb-0.5",style:{color:s.textFaint},children:"AFTER"}),e.jsx("div",{className:"text-[11px] font-mono break-all",style:{color:"#00c864"},children:ye(t.after)})]})]}),t.type==="added"&&t.after!==void 0&&e.jsx("div",{className:"mt-1 text-[11px] font-mono break-all",style:{color:"#00c864"},children:ye(t.after)}),t.type==="removed"&&t.before!==void 0&&e.jsx("div",{className:"mt-1 text-[11px] font-mono break-all",style:{color:"#ff6666"},children:ye(t.before)})]})}function tn({category:t,changes:s,collapsed:o,onToggle:n,t:a}){const r=s.length>0;return e.jsxs("div",{className:"rounded-lg border overflow-hidden",style:{borderColor:a.border},children:[e.jsxs("button",{type:"button",onClick:n,className:"w-full flex items-center justify-between px-3 py-2 cursor-pointer border-none",style:{background:r?a.surfaceElevated:a.surface},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[o?e.jsx(Me,{size:12}):e.jsx(ne,{size:12}),e.jsx("span",{className:"text-[12px] font-semibold",style:{color:a.textPrimary},children:Zs[t]}),r&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full font-bold",style:{background:"#FE5000",color:"white"},children:s.length})]}),!r&&e.jsx("span",{className:"text-[11px]",style:{color:a.textFaint},children:"No changes"})]}),!o&&r&&e.jsx("div",{className:"px-3 py-2",style:{background:a.surface},children:s.map(i=>e.jsx(en,{change:i,t:a},`${i.category}-${i.field}`))})]})}function sn({diff:t,t:s}){const{totalChanges:o,changeTypes:n}=t.summary;return o===0?e.jsx("p",{className:"text-[12px]",style:{color:s.textFaint},children:"These versions are identical."}):e.jsxs("div",{className:"flex items-center gap-3 text-[12px]",children:[e.jsxs("span",{style:{color:s.textSecondary},children:[o," change",o!==1?"s":""]}),n.added>0&&e.jsxs("span",{style:{color:"#00c864"},children:["+",n.added," added"]}),n.removed>0&&e.jsxs("span",{style:{color:"#ff4444"},children:["−",n.removed," removed"]}),n.modified>0&&e.jsxs("span",{style:{color:"#ffa000"},children:[n.modified," modified"]})]})}function nn({versionA:t,versionB:s,onClose:o}){const n=W(),[a,r]=u.useState(new Set),i=u.useMemo(()=>Qs(t.snapshot,s.snapshot,t.version,s.version),[t,s]),l=c=>{r(h=>{const k=new Set(h);return k.has(c)?k.delete(c):k.add(c),k})};return e.jsx("div",{className:"fixed inset-0 z-[200] flex items-center justify-center",style:{background:"rgba(0,0,0,0.65)"},onClick:c=>{c.target===c.currentTarget&&o()},children:e.jsxs("div",{className:"w-[600px] max-h-[80vh] flex flex-col rounded-xl border shadow-2xl",style:{background:n.surface,borderColor:n.border},children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b shrink-0",style:{borderColor:n.border},children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-[13px] font-bold",style:{color:n.textPrimary,fontFamily:"'Geist Mono', monospace"},children:["v",t.version," → v",s.version]}),e.jsx(sn,{diff:i,t:n})]}),e.jsx("button",{type:"button",onClick:o,className:"flex items-center justify-center w-7 h-7 rounded-md cursor-pointer border-none bg-transparent",style:{color:n.textMuted},"aria-label":"Close diff view",children:e.jsx(ae,{size:14})})]}),e.jsx("div",{className:"overflow-y-auto flex-1 p-4 flex flex-col gap-2",children:Xs.map(c=>e.jsx(tn,{category:c,changes:i.changes.filter(h=>h.category===c),collapsed:a.has(c),onToggle:()=>l(c),t:n},c))})]})})}function on({onSettingsClick:t,onBack:s}){const o=$(p=>p.running),n=$(p=>p.run),a=$(p=>p.agentMeta),r=ue(p=>p.currentVersion),i=ue(p=>p.versions),l=ue(p=>p.restoreVersion),c=ue(p=>p.agentId),h=ue(p=>p.loadVersions),k=Se(p=>p.toggleTheme),[f,E]=u.useState(!1),[S,g]=u.useState(null),w=u.useRef(null),b=W();return u.useEffect(()=>{c&&i.length===0&&h()},[c,h]),u.useEffect(()=>{const p=C=>{w.current&&!w.current.contains(C.target)&&E(!1)};if(f)return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[f]),e.jsxs("div",{className:"flex items-center h-[48px] px-4 gap-3 shrink-0 border-b select-none",style:{background:b.surface,backdropFilter:"blur(12px)",borderColor:b.border,position:"relative",zIndex:50},children:[s&&e.jsx("button",{type:"button",onClick:s,className:"flex items-center justify-center w-8 h-8 rounded-md cursor-pointer border-none bg-transparent hover:bg-[#FE500015]",style:{color:b.textSecondary},"aria-label":"Back to library",title:"Back to library",children:e.jsx(rs,{size:16})}),e.jsxs("div",{className:"flex items-center gap-2 mr-4",children:[e.jsx("div",{className:"w-2 h-2 rounded-full",style:{background:"#FE5000",boxShadow:"0 0 8px rgba(254,80,0,0.4)"},"aria-hidden":"true"}),e.jsx("h1",{className:"text-[17px] font-bold tracking-[3px] uppercase m-0",style:{fontFamily:"'Geist Mono', monospace",color:b.textPrimary},children:"MODULAR"})]}),a.name&&e.jsxs("div",{className:"flex items-center gap-2 mx-4",children:[e.jsx("span",{className:"text-[15px] font-semibold",style:{color:b.textPrimary},children:a.name}),e.jsxs("div",{className:"relative",ref:w,children:[e.jsxs("button",{type:"button",onClick:()=>E(!f),"aria-expanded":f,"aria-haspopup":"menu","aria-label":`Version ${r} dropdown menu`,title:"Select version",className:"flex items-center gap-1 px-2 py-1 rounded-md cursor-pointer border-none text-[13px] font-semibold",style:{background:b.surfaceElevated,color:b.textSecondary,fontFamily:"'Geist Mono', monospace",border:`1px solid ${b.border}`},children:["v",r,e.jsx(ne,{size:10})]}),f&&e.jsx("div",{className:"absolute top-full right-0 mt-1 w-64 rounded-lg border shadow-lg overflow-hidden",style:{background:b.surface,borderColor:b.border,boxShadow:"0 4px 12px rgba(0,0,0,0.15)",zIndex:100},children:e.jsxs("div",{className:"p-2 max-h-80 overflow-y-auto",children:[i.slice(-5).reverse().map(p=>e.jsxs("div",{className:"flex items-center justify-between p-2 rounded-md hover:bg-opacity-50",style:{background:p.version===r?"rgba(254, 80, 0, 0.1)":"transparent"},children:[e.jsxs("div",{className:"flex flex-col min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-[13px] font-bold",style:{fontFamily:"'Geist Mono', monospace",color:p.version===r?"#FE5000":b.textPrimary},children:["v",p.version]}),p.version===r&&e.jsx("span",{className:"text-[10px] px-1 py-0.5 rounded text-white bg-green-600",children:"CURRENT"})]}),e.jsx("span",{className:"text-[11px] truncate",style:{color:b.textMuted},children:p.label||"Checkpoint"}),e.jsx("span",{className:"text-[10px]",style:{color:b.textFaint},children:new Date(p.timestamp).toLocaleString()})]}),p.version!==r&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>{i.find(m=>m.version===r)&&(g(p),E(!1))},title:`Compare v${p.version} with current`,className:"flex items-center gap-1 px-2 py-1 rounded text-[11px] font-medium border-none cursor-pointer",style:{background:b.surfaceElevated,color:b.textSecondary,border:`1px solid ${b.border}`},children:[e.jsx(as,{size:10}),"Compare"]}),e.jsxs("button",{type:"button",onClick:()=>{l(p.version),E(!1)},title:`Restore version ${p.version}`,className:"flex items-center gap-1 px-2 py-1 rounded text-[11px] font-medium border-none cursor-pointer",style:{background:"#FE5000",color:"white"},children:[e.jsx(is,{size:10}),"Restore"]})]})]},p.id)),i.length===0&&e.jsx("div",{className:"p-4 text-center",children:e.jsx("div",{className:"text-[12px]",style:{color:b.textFaint},children:"No versions yet"})})]})})]})]}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{type:"button",onClick:t,className:"flex items-center justify-center w-11 h-11 rounded-md cursor-pointer border-none bg-transparent hover-accent-text focus-visible:outline focus-visible:outline-2",style:{color:b.textDim},"aria-label":"LLM settings",title:"LLM settings",children:e.jsx(We,{size:14})}),e.jsx("button",{type:"button",onClick:k,className:"flex items-center justify-center w-11 h-11 rounded-md cursor-pointer border-none bg-transparent hover-accent-text focus-visible:outline focus-visible:outline-2",style:{color:b.textDim},"aria-label":b.isDark?"Switch to light mode":"Switch to dark mode",title:b.isDark?"Switch to light mode":"Switch to dark mode",children:b.isDark?e.jsx(gt,{size:14}):e.jsx(ht,{size:14})}),e.jsxs("button",{type:"button",onClick:n,title:o?"Stop execution":"Run agent",className:"flex items-center justify-center gap-1.5 h-8 px-4 rounded-lg text-[14px] font-semibold tracking-wider uppercase cursor-pointer border-none",style:{background:o?"#CC4000":"#FE5000",color:"#fff",boxShadow:o?"0 0 12px rgba(254,80,0,0.5)":"0 0 8px rgba(254,80,0,0.25)",opacity:o?.8:1,animation:o?"run-pulse-ring 1.5s ease infinite":"none",transition:"background 0.2s ease, opacity 0.2s ease"},children:[o?e.jsx(ls,{size:12,fill:"white"}):e.jsx(Ue,{size:12,fill:"white"}),o?"Stop":"Run",e.jsx("span",{className:"text-[13px] opacity-60 tracking-normal font-normal ml-1",children:o?"click to cancel":"Ctrl+Enter"})]}),S&&(()=>{const p=i.find(C=>C.version===r);return p?e.jsx(nn,{versionA:S,versionB:p,onClose:()=>g(null)}):null})()]})}function rn(){const t=$(i=>i.totalTokens),s=$(i=>i.tokenBudget),o=W(),n=t(),a=Math.min(n/s*100,100);let r=o.statusSuccess;return a>80?r=o.statusError:a>55&&(r=o.statusWarning),e.jsxs("div",{className:"w-full px-4 py-2 flex items-center gap-3 shrink-0 border-t",style:{background:o.surfaceOpaque,borderColor:o.border},children:[e.jsx("span",{className:"text-[12px] tracking-wider uppercase shrink-0 font-medium",style:{fontFamily:"'Geist Mono', monospace",color:o.tokenLabel},children:"Token Budget"}),e.jsx("div",{className:"flex-1 h-[6px] rounded-full overflow-hidden",style:{background:o.tokenTrackBg},children:e.jsx("div",{className:"h-full rounded-full transition-all duration-300",style:{width:`${a}%`,background:`linear-gradient(90deg, ${r}cc, ${r})`,boxShadow:`0 0 6px ${r}30`}})}),e.jsx("span",{className:"text-[13px] shrink-0 tabular-nums",style:{fontFamily:"'Geist Mono', monospace",color:r,minWidth:56,textAlign:"right",whiteSpace:"nowrap"},children:n>=1e3?`${(n/1e3).toFixed(1)}K`:n}),e.jsxs("span",{className:"text-[13px] shrink-0",style:{fontFamily:"'Geist Mono', monospace",color:o.tokenDivider,minWidth:64,whiteSpace:"nowrap"},children:["/ ",s>=1e3?`${(s/1e3).toFixed(0)}K`:s]})]})}const nt=`${J}/knowledge`,ie=Ee(t=>({tree:[],loaded:!1,scanning:!1,error:null,lastDir:"",scanDirectory:async s=>{t({scanning:!0,error:null});try{const n=await(await fetch(`${nt}/scan?dir=${encodeURIComponent(s)}&depth=3`)).json();n.status==="ok"&&n.data?t({tree:n.data,loaded:!0,scanning:!1,lastDir:s}):t({scanning:!1,error:n.error??"Scan failed"})}catch(o){t({scanning:!1,error:o instanceof Error?o.message:"Network error"})}},readFile:async s=>{try{const n=await(await fetch(`${nt}/read?path=${encodeURIComponent(s)}`)).json();return n.status==="ok"&&n.data?n.data:null}catch{return null}}}));function an(t){return t>=1e3?`${(t/1e3).toFixed(1)}K`:String(t)}function Dt(t,s){if(!s)return!0;const o=s.toLowerCase();return!!(t.name.toLowerCase().includes(o)||t.path.toLowerCase().includes(o)||t.children?.some(n=>Dt(n,s)))}function Lt({node:t,depth:s,onAdd:o,filter:n}){const[a,r]=u.useState(s<1||!!n),i=t.type==="directory"&&t.children&&t.children.length>0,l=W();return Dt(t,n)?e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 py-1.5 px-2 rounded cursor-pointer transition-colors",style:{paddingLeft:8+s*16},onMouseEnter:c=>{c.currentTarget.style.background=l.surfaceHover},onMouseLeave:c=>{c.currentTarget.style.background="transparent"},children:[i?e.jsx("button",{type:"button",onClick:()=>r(!a),className:"w-4 h-4 flex items-center justify-center text-[12px] cursor-pointer border-none bg-transparent",style:{color:l.textMuted},"aria-label":a?"Collapse folder":"Expand folder",children:a?"▼":"▶"}):e.jsx("span",{className:"w-4"}),e.jsx("div",{className:"w-[6px] h-[6px] rounded-full shrink-0",style:{background:t.type==="directory"?"#f1c40f":"#3498db"}}),e.jsx("span",{className:"flex-1 text-[13px] truncate",style:{fontFamily:"'Geist Mono', monospace",color:l.textPrimary},children:t.name}),t.tokenEstimate&&e.jsx("span",{className:"text-[13px] shrink-0",style:{fontFamily:"'Geist Mono', monospace",color:l.textDim},children:an(t.tokenEstimate)}),t.type==="file"&&e.jsx("button",{type:"button",onClick:()=>o(t),className:"px-2 py-0.5 rounded text-[12px] tracking-[1px] uppercase cursor-pointer border transition-colors shrink-0",style:{fontFamily:"'Geist Mono', monospace",background:"transparent",borderColor:l.border,color:l.textMuted},onMouseEnter:c=>{c.currentTarget.style.borderColor="#FE5000",c.currentTarget.style.color="#FE5000"},onMouseLeave:c=>{c.currentTarget.style.borderColor=l.border,c.currentTarget.style.color=l.textMuted},"aria-label":`Add ${t.name}`,children:"+ ADD"})]}),i&&a&&t.children.map(c=>e.jsx(Lt,{node:c,depth:s+1,onAdd:o,filter:n},c.path))]}):null}function ln(){const t=$(m=>m.showFilePicker),s=$(m=>m.setShowFilePicker),o=$(m=>m.addFileChannel),n=ie(m=>m.tree),a=ie(m=>m.loaded),r=ie(m=>m.scanning),i=ie(m=>m.scanDirectory),l=ie(m=>m.readFile),c=ie(m=>m.lastDir),[h,k]=u.useState(""),[f,E]=u.useState(""),S=u.useRef(null),g=u.useRef(null),w=W();u.useEffect(()=>{t&&(k(""),E(c),setTimeout(()=>S.current?.focus(),100))},[t,c]),u.useEffect(()=>{if(!t)return;const m=F=>{F.key==="Escape"&&s(!1)};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[t,s]);const b=u.useCallback(m=>{if(m.key!=="Tab"||!g.current)return;const F=g.current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(F.length===0)return;const M=F[0],R=F[F.length-1];m.shiftKey?document.activeElement===M&&(m.preventDefault(),R.focus()):document.activeElement===R&&(m.preventDefault(),M.focus())},[]);if(!t)return null;const p=async m=>{if(m.type!=="file")return;const F=c.replace(/\\/g,"/")+"/"+m.path,M=await l(F);M&&o(M)},C=()=>{f.trim()&&i(f.trim())};return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:()=>s(!1),children:[e.jsx("div",{className:"absolute inset-0",style:{background:"rgba(0,0,0,0.7)"}}),e.jsxs("div",{ref:g,role:"dialog","aria-modal":"true","aria-label":"Add Knowledge Source",className:"relative w-[560px] max-h-[70vh] flex flex-col rounded-lg overflow-hidden",style:{background:w.surfaceOpaque,border:`1px solid ${w.border}`,boxShadow:"0 24px 48px rgba(0,0,0,0.8)",animation:"modal-in 0.2s ease-out"},onClick:m=>m.stopPropagation(),onKeyDown:b,children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b",style:{borderColor:w.border},children:[e.jsx("span",{className:"text-[13px] font-bold tracking-[3px] uppercase",style:{fontFamily:"'Geist Mono', monospace",color:w.textPrimary},children:"ADD KNOWLEDGE SOURCE"}),e.jsx("button",{type:"button",onClick:()=>s(!1),className:"text-[17px] cursor-pointer border-none bg-transparent",style:{color:w.textMuted},onMouseEnter:m=>{m.currentTarget.style.color="#FE5000"},onMouseLeave:m=>{m.currentTarget.style.color=w.textMuted},"aria-label":"Close file picker",children:"✕"})]}),e.jsxs("div",{className:"px-4 py-2 border-b flex items-center gap-2",style:{borderColor:w.border},children:[e.jsx("input",{type:"text",value:f,onChange:m=>E(m.target.value),onKeyDown:m=>{m.key==="Enter"&&C()},placeholder:"Directory path to scan...",className:"flex-1 outline-none text-[13px]",style:{background:w.inputBg,border:`1px solid ${w.border}`,borderRadius:4,color:w.textPrimary,fontFamily:"'Geist Mono', monospace",padding:"6px 10px"},"aria-label":"Directory path to scan"}),e.jsx("button",{type:"button",onClick:C,disabled:r,className:"px-3 py-1 rounded text-[12px] tracking-wide uppercase cursor-pointer border-none",style:{background:"#FE5000",color:"#fff",opacity:r?.6:1},"aria-label":"Scan directory",children:r?"Scanning...":"Scan"})]}),e.jsx("div",{className:"px-4 py-2 border-b",style:{borderColor:w.borderSubtle},children:e.jsx("input",{ref:S,type:"text",value:h,onChange:m=>k(m.target.value),placeholder:"Filter results...",className:"w-full outline-none text-[13px]",style:{background:w.inputBg,border:`1px solid ${w.border}`,borderRadius:4,color:w.textPrimary,fontFamily:"'Geist Mono', monospace",padding:"6px 10px"},onFocus:m=>{m.currentTarget.style.borderColor="#FE500050"},onBlur:m=>{m.currentTarget.style.borderColor=w.border},"aria-label":"Filter knowledge sources"})}),e.jsx("div",{className:"flex-1 overflow-y-auto py-2 px-1",children:a&&n.length>0?n.map(m=>e.jsx(Lt,{node:m,depth:0,onAdd:F=>{p(F)},filter:h},m.path)):a&&n.length===0?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx("span",{className:"text-[13px]",style:{color:w.textDim},children:"No files found. Try scanning a directory."})}):e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx("span",{className:"text-[13px]",style:{color:w.textDim},children:"Enter a directory path and click Scan to browse files."})})})]})]})}const pe=Ee((t,s)=>({skills:[],loaded:!1,loading:!1,error:void 0,loadSkills:async()=>{if(!s().loading){t({loading:!0,error:void 0});try{const o=await fetch(`${J}/claude-config/skills`);if(!o.ok){t({loaded:!0,loading:!1,error:`Failed to load skills (${o.status})`});return}const a=(await o.json())?.data??[];t({skills:a.map(r=>({...r,enabled:!0})),loaded:!0,loading:!1})}catch{t({loaded:!0,loading:!1,error:"Backend unavailable. Start the server with `npm run server` on port 4800."})}}},toggleSkill:o=>{t({skills:s().skills.map(n=>n.id===o?{...n,enabled:!n.enabled}:n)})}})),Qe={presentation:Es,mic:Ns,cloud:Cs,code:Ct,"bar-chart-3":St,anchor:Ss,"git-branch":Oe,palette:ws,search:le,image:vs,"book-open":wt,hexagon:js,workflow:ks,map:bs,sparkles:$e,compass:ys,waves:hs,box:Ye,layout:gs,wrench:vt,cpu:Fe,triangle:xs,"pen-tool":jt,mail:fs,hash:ms,github:Oe,"file-text":Te,flame:ps,database:Ve,globe:kt,folder:us,target:bt,"clipboard-list":ds,"hard-drive":cs,shield:yt,brain:He};function Ae({icon:t,size:s=14,...o}){const n=Qe[t];return n?e.jsx(n,{size:s,...o}):e.jsx(qe,{size:s,...o})}function cn({icon:t,size:s=14,...o}){const n=Qe[t];return n?e.jsx(n,{size:s,...o}):e.jsx(ge,{size:s,...o})}function dn({icon:t,size:s=14,...o}){const n=Qe[t];return n?e.jsx(n,{size:s,...o}):e.jsx(ge,{size:s,...o})}function Pt({open:t,onClose:s,title:o,searchPlaceholder:n,width:a=520,hideSearch:r,children:i}){const[l,c]=u.useState(""),h=u.useRef(null),k=u.useRef(null),f=W();u.useEffect(()=>{t&&(c(""),setTimeout(()=>h.current?.focus(),100))},[t]),u.useEffect(()=>{if(!t)return;const S=g=>{g.key==="Escape"&&s()};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[t,s]);const E=u.useCallback(S=>{if(S.key!=="Tab"||!k.current)return;const g=k.current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(g.length===0)return;const w=g[0],b=g[g.length-1];S.shiftKey?document.activeElement===w&&(S.preventDefault(),b.focus()):document.activeElement===b&&(S.preventDefault(),w.focus())},[]);return t?Ne.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[200] flex items-center justify-center",onClick:s,children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm"}),e.jsxs("div",{ref:k,role:"dialog","aria-modal":"true","aria-label":o,className:"relative max-h-[70vh] flex flex-col rounded-xl overflow-hidden",style:{width:a,background:f.surface,border:`1px solid ${f.border}`,borderRadius:"12px",boxShadow:"0 24px 48px rgba(0,0,0,0.6)",animation:"modal-in 0.2s ease-out"},onClick:S=>S.stopPropagation(),onKeyDown:E,children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4",style:{borderBottom:`1px solid ${f.border}`},children:[e.jsx("span",{className:"text-[14px] font-semibold",style:{color:f.textPrimary,fontFamily:"'Geist Sans', sans-serif"},children:o}),e.jsx("button",{type:"button",onClick:s,className:"p-1 rounded-md cursor-pointer border-none bg-transparent transition-colors",style:{color:f.textDim},"aria-label":"Close",onMouseEnter:S=>{S.currentTarget.style.background="#ef444420",S.currentTarget.style.color="#ef4444"},onMouseLeave:S=>{S.currentTarget.style.background="transparent",S.currentTarget.style.color=f.textDim},children:e.jsx(ae,{size:16})})]}),!r&&e.jsx("div",{className:"px-5 py-3",style:{borderBottom:`1px solid ${f.borderSubtle}`},children:e.jsxs("div",{className:"relative",children:[e.jsx(le,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2",style:{color:f.textDim}}),e.jsx("input",{ref:h,type:"text",value:l,onChange:S=>c(S.target.value),placeholder:n??"Search...",className:"w-full outline-none text-[13px] pl-9 pr-3 py-1.5 rounded-lg",style:{background:f.inputBg,border:`1px solid ${f.border}`,color:f.textPrimary,fontFamily:"'Geist Sans', sans-serif"},"aria-label":"Search"})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto py-2",children:i(l)})]})]}),document.body):null}const me=new Map,be=new Set,zt=new Set;let De=!1,ke=null;function un(t){const s=t.includes(":")?t.split(":").pop():t;return s.includes("/")?s.split("/").pop():s}function pn(){return De?Promise.resolve():ke||(ke=fetch(`${J}/health/skills`).then(t=>t.json()).then(t=>{t.status==="ok"&&Array.isArray(t.data)&&t.data.forEach(s=>zt.add(s.id)),De=!0}).catch(()=>{De=!0}),ke)}function mn(t){return t==="ok"?"#2ecc71":t==="warning"?"#f39c12":t==="error"?"#e74c3c":"#888"}function Ze({skillPath:t}){const s=W(),o=un(t),[n,a]=u.useState(()=>me.get(o)??null),[r,i]=u.useState(()=>!me.has(o)&&!be.has(o)),[l,c]=u.useState(null);if(u.useEffect(()=>{if(me.has(o)){a(me.get(o)),i(!1);return}if(be.has(o)){i(!1);return}let S=!1;return pn().then(()=>{if(!S){if(!zt.has(o)){be.add(o),i(!1);return}fetch(`${J}/health/skills/${encodeURIComponent(o)}`).then(g=>g.status===404?(be.add(o),S||i(!1),null):g.json()).then(g=>{S||g===null||(g.status==="ok"&&g.data&&(me.set(o,g.data),a(g.data)),i(!1))}).catch(()=>{S||i(!1)})}}),()=>{S=!0}},[o]),!r&&n===null)return null;const h=r&&n===null,k=n?.securityIssues.some(S=>S.includes("undocumented"))??!1,f=[{key:"SEC",label:"SEC",color:n?n.securityIssues.length===0?"#2ecc71":"#e74c3c":"#888",tooltip:n?n.securityIssues.length===0?"Security: No issues":`Security: ${n.securityIssues.length} issue${n.securityIssues.length>1?"s":""}`:"Security: Loading..."},{key:"DEP",label:"DEP",color:n?n.outdatedDeps.length===0?"#2ecc71":"#f39c12":"#888",tooltip:n?n.outdatedDeps.length===0?"Dependencies: Up to date":`Dependencies: ${n.outdatedDeps.length} outdated`:"Dependencies: Loading..."},{key:"DOC",label:"DOC",color:n?k?"#e74c3c":"#2ecc71":"#888",tooltip:n?k?"Docs: Missing SKILL.md / README":"Docs: Present":"Docs: Loading..."}],E=mn(n?.status??null);return e.jsxs("div",{style:{position:"relative",display:"inline-flex",alignItems:"center",gap:3},children:[h?e.jsx(X,{size:8,style:{color:"#888"},className:"animate-spin"}):e.jsx("span",{style:{display:"inline-block",width:6,height:6,borderRadius:"50%",background:E,flexShrink:0}}),f.map(S=>e.jsxs("div",{style:{position:"relative",display:"inline-flex",alignItems:"center",gap:2,cursor:"default"},onMouseEnter:()=>c(S.key),onMouseLeave:()=>c(null),children:[e.jsx("span",{style:{fontSize:12,fontFamily:"'Geist Mono', monospace",fontWeight:600,color:h?"#888":S.color,lineHeight:1},children:S.label}),l===S.key&&e.jsx("div",{style:{position:"absolute",bottom:"100%",left:"50%",transform:"translateX(-50%)",marginBottom:4,background:s.surfaceOpaque,border:`1px solid ${s.border}`,borderRadius:4,padding:"2px 6px",whiteSpace:"nowrap",fontSize:12,color:s.textPrimary,boxShadow:"0 4px 12px rgba(0,0,0,0.4)",zIndex:100,pointerEvents:"none"},children:S.tooltip})]},S.key))]})}const fn={content:"Content",analysis:"Analysis",development:"Development",domain:"Domain"},xn=["content","analysis","development","domain"];function gn(t,s){const o=`${t} ${s}`.toLowerCase();return/analysis|insight|research|intel|feedback/.test(o)?"analysis":/code|dev|api|build|test|automation|github/.test(o)?"development":/content|write|presentation|slides|copy/.test(o)?"content":"domain"}function hn(){const t=$(p=>p.showSkillPicker),s=$(p=>p.setShowSkillPicker),o=$(p=>p.skills),n=$(p=>p.addSkill),a=$(p=>p.upsertSkill),r=pe(p=>p.skills),i=pe(p=>p.loaded),l=pe(p=>p.loading),c=pe(p=>p.loadSkills),h=pe(p=>p.toggleSkill),k=W(),[f,E]=u.useState(()=>new Set);u.useEffect(()=>{t&&!i&&!l&&c()},[t,i,l,c]),u.useEffect(()=>{t&&E(new Set)},[t]),u.useEffect(()=>{if(r.length!==0)for(const p of r)a({id:p.id,name:p.name,description:p.description||"Installed skill"})},[r,a]);const S=u.useMemo(()=>{const p=new Set(o.filter(m=>m.added).map(m=>m.id)),C=new Map(o.map(m=>[m.id,m]));for(const m of r)C.has(m.id)||C.set(m.id,{id:m.id,name:m.name,icon:"zap",enabled:m.enabled,added:p.has(m.id),description:m.description||"Installed skill",category:gn(m.name,m.description||"")});return Array.from(C.values())},[o,r]),g=(p,C)=>{C||E(m=>{const F=new Set(m);return F.has(p)?F.delete(p):F.add(p),F})},w=()=>{f.forEach(p=>{n(p);const C=r.find(m=>m.id===p);C&&!C.enabled&&h(p)}),E(new Set),s(!1)},b=()=>{E(new Set),s(!1)};return e.jsx(Pt,{open:t,onClose:b,title:"Select Skills",searchPlaceholder:"Search skills...",children:p=>{const C=S.filter(F=>{if(!p)return!0;const M=p.toLowerCase();return F.name.toLowerCase().includes(M)||F.description.toLowerCase().includes(M)}),m=xn.map(F=>({category:F,label:fn[F],skills:C.filter(M=>M.category===F)})).filter(F=>F.skills.length>0);return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-1 overflow-y-auto",children:m.map(F=>e.jsxs("div",{children:[e.jsx("div",{className:"px-5 py-1.5",children:e.jsx("span",{className:"text-[12px] font-medium tracking-wider uppercase",style:{color:k.textDim},children:F.label})}),F.skills.map(M=>{const R=f.has(M.id),L=M.added;return e.jsxs("div",{className:`flex items-center gap-3 px-5 py-2.5 ${L?"cursor-default":"hover-row cursor-pointer"}`,style:{background:R?"#FE500012":"transparent"},onClick:()=>g(M.id,L),children:[e.jsx("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center shrink-0",style:{background:k.surfaceElevated},children:e.jsx(cn,{icon:M.icon,size:16,style:{color:k.textSecondary}})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[17px] font-medium",style:{color:k.textPrimary},children:M.name}),M.skillUrl?.startsWith("https://skills.sh/")&&e.jsx(Ze,{skillPath:M.skillUrl.replace("https://skills.sh/","").split("/").pop()??""})]}),e.jsx("span",{className:"text-[14px]",style:{color:k.textDim},children:M.description})]}),L?e.jsxs("span",{className:"flex items-center gap-1 text-[14px] px-2.5 py-1 rounded-md",style:{color:k.statusSuccess,background:k.statusSuccessBg},children:[e.jsx(Z,{size:12})," Added"]}):e.jsx("div",{className:"w-4 h-4 rounded border-2 flex items-center justify-center shrink-0",style:{borderColor:R?"#FE5000":k.border,background:R?"#FE5000":"transparent"},children:R&&e.jsx(Z,{size:10,style:{color:"#fff"}})})]},M.id)})]},F.category))}),e.jsxs("div",{className:"flex items-center justify-end gap-3 px-5 py-3",style:{borderTop:`1px solid ${k.border}`,background:k.surfaceOpaque},children:[e.jsx("button",{type:"button",onClick:b,className:"px-4 py-2 text-[14px] rounded-lg cursor-pointer border",style:{background:"transparent",border:`1px solid ${k.border}`,color:k.textSecondary},children:"Cancel"}),e.jsxs("button",{type:"button",onClick:w,disabled:f.size===0,className:"px-4 py-2 text-[14px] rounded-lg cursor-pointer border-none",style:{background:f.size>0?"#FE5000":k.surfaceElevated,color:f.size>0?"#fff":k.textDim,opacity:f.size>0?1:.5,cursor:f.size>0?"pointer":"not-allowed"},children:["Add ",f.size>0?`${f.size} skill${f.size===1?"":"s"}`:"skills"]})]})]})}})}function Rt({content:t,children:s,position:o="top",delay:n=300}){const a=W(),[r,i]=u.useState(!1),[l,c]=u.useState({x:0,y:0}),h=u.useRef(void 0),k=u.useRef(null),f=()=>{h.current=setTimeout(()=>{if(!k.current)return;const g=k.current.getBoundingClientRect();c({x:g.left+g.width/2,y:o==="top"?g.top-8:g.bottom+8}),i(!0)},n)},E=()=>{clearTimeout(h.current),i(!1)},S=a.isDark?"#333":"#222";return e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:k,onMouseEnter:f,onMouseLeave:E,className:"inline-flex",children:s}),r&&Ne.createPortal(e.jsxs("div",{className:"fixed z-[300] pointer-events-none px-2.5 py-1.5 rounded text-[12px]",style:{left:l.x,top:l.y,transform:o==="top"?"translate(-50%, -100%)":"translate(-50%, 0)",background:S,color:"#fff",fontFamily:"'Geist Mono', monospace",boxShadow:"0 2px 8px rgba(0,0,0,0.3)",maxWidth:250,whiteSpace:"normal",lineHeight:1.4},children:[t,e.jsx("div",{style:{position:"absolute",left:"50%",transform:"translateX(-50%)",...o==="top"?{bottom:-4,borderLeft:"5px solid transparent",borderRight:"5px solid transparent",borderTop:`5px solid ${S}`}:{top:-4,borderLeft:"5px solid transparent",borderRight:"5px solid transparent",borderBottom:`5px solid ${S}`},width:0,height:0}})]}),document.body)]})}function yn(){const t=$(d=>d.showMarketplace),s=$(d=>d.activeMarketplaceTab),o=$(d=>d.setShowMarketplace),n=$(d=>d.registrySkills),a=$(d=>d.installRegistrySkill),r=$(d=>d.upsertSkill),i=$(d=>d.skills),[l,c]=u.useState(""),[h,k]=u.useState("all"),[f,E]=u.useState(null),[S,g]=u.useState(null),[w,b]=u.useState(()=>new Set),[p,C]=u.useState([]),[m,F]=u.useState(!1),[M,R]=u.useState(null),[L,z]=u.useState(null),G=u.useRef(null),D=u.useRef(null),y=W(),H=new Set(Array.isArray(i)?i.filter(d=>d.added).map(d=>d.id??""):[]),N=u.useCallback(d=>{if(d.key!=="Tab"||!D.current)return;const _=D.current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(_.length===0)return;const U=_[0],Y=_[_.length-1];d.shiftKey?document.activeElement===U&&(d.preventDefault(),Y.focus()):document.activeElement===Y&&(d.preventDefault(),U.focus())},[]);u.useEffect(()=>{t&&(c(""),k("all"),E(null),g(null),C([]),F(!1),R(null),z(null),setTimeout(()=>G.current?.focus(),100))},[t]),u.useEffect(()=>{if(!t)return;const d=_=>{_.key==="Escape"&&o(!1)};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[t,o]);const B=u.useCallback(d=>{o(!0,d),c(""),k("all"),C([]),R(null),F(!1)},[o]),K=u.useCallback((d,_,U)=>{E(d),z(null),setTimeout(()=>{a(d,_,U),E(null)},1200)},[a]),x=u.useCallback(async d=>{g(d.id);try{const _=await fetch(`${J}/skills/install`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({skillId:d.id})});if(!_.ok)throw new Error(`HTTP ${_.status}`);b(U=>new Set(U).add(d.id)),r({id:d.id,name:d.name,description:`Installed from skills.sh (${d.repo})`,skillUrl:d.url})}catch(_){R(_ instanceof Error?_.message:"Install failed")}finally{g(null)}},[r]);u.useEffect(()=>{if(!t||s!=="skills"){F(!1),C([]),R(null);return}const d=l.trim();if(d.length<2){F(!1),C([]),R(null);return}const _=new AbortController,U=setTimeout(async()=>{F(!0),R(null);try{const Y=await fetch(`${J}/skills/search?q=${encodeURIComponent(d)}`,{signal:_.signal});if(!Y.ok)throw new Error(`HTTP ${Y.status}`);const Ie=await Y.json();C(Array.isArray(Ie.data)?Ie.data:[]),R(Ie.error??null)}catch(Y){if(_.signal.aborted)return;C([]),R(Y instanceof Error?Y.message:"Search failed")}finally{_.signal.aborted||F(!1)}},300);return()=>{_.abort(),clearTimeout(U)}},[s,l,t]);const j=()=>{if(typeof window>"u")return 4;const d=window.innerWidth;return d<=1024?2:d<=1440?3:4},[T,P]=u.useState(j);if(u.useEffect(()=>{const d=()=>P(j());return window.addEventListener("resize",d),()=>window.removeEventListener("resize",d)},[]),!t)return null;const A=(d,_)=>{if(!l)return!0;const U=l.toLowerCase();return d.toLowerCase().includes(U)||_.toLowerCase().includes(U)},I=n.filter(d=>A(d.name,d.description)&&(h==="all"||d.category===h)),v=qt.filter(d=>A(d.name,d.description)),O={display:"grid",gridTemplateColumns:`repeat(${T}, 1fr)`,gap:12,padding:16,alignContent:"start"};return e.jsx(e.Fragment,{children:e.jsxs("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,zIndex:50,display:"flex",alignItems:"center",justifyContent:"center"},onClick:()=>o(!1),children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm"}),e.jsxs("div",{ref:D,role:"dialog","aria-modal":"true","aria-label":"Marketplace",style:{position:"relative",display:"flex",flexDirection:"column",borderRadius:"12px",overflow:"hidden",isolation:"isolate",zIndex:1,width:"90vw",maxWidth:1600,height:"80vh",background:y.surface,border:`1px solid ${y.border}`,boxShadow:"0 24px 48px rgba(0,0,0,0.6)",animation:"modal-in 0.2s ease-out"},onClick:d=>d.stopPropagation(),onKeyDown:N,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"12px 16px",borderBottom:`1px solid ${y.border}`},children:[e.jsx("span",{style:{fontSize:17,fontWeight:600,flexShrink:0,color:y.textPrimary,fontFamily:"'Geist Mono', monospace"},children:"Marketplace"}),e.jsxs("div",{style:{position:"relative",width:240,flexShrink:0},children:[e.jsx(le,{size:13,style:{position:"absolute",left:10,top:"50%",transform:"translateY(-50%)",color:y.textDim}}),e.jsx("input",{ref:G,type:"text",value:l,onChange:d=>c(d.target.value),placeholder:"Search...",style:{width:"100%",outline:"none",fontSize:14,paddingLeft:32,paddingRight:12,paddingTop:6,paddingBottom:6,borderRadius:6,background:y.inputBg,border:`1px solid ${y.border}`,color:y.textPrimary,fontFamily:"'Geist Sans', sans-serif"}})]}),e.jsx("div",{style:{display:"flex",alignItems:"center",marginLeft:"auto",borderBottom:`1px solid ${y.borderSubtle}`},children:["skills","mcp","presets"].map(d=>e.jsx("button",{type:"button",onClick:()=>B(d),style:{padding:"6px 12px",fontSize:13,fontWeight:500,letterSpacing:"0.025em",textTransform:"uppercase",cursor:"pointer",border:"none",color:s===d?"#FE5000":y.textDim,borderBottom:s===d?"2px solid #FE5000":"2px solid transparent",background:"transparent",marginBottom:-1,transition:"color 150ms ease"},children:d==="mcp"?"MCP Servers":d==="presets"?"Presets":"Skills"},d))}),e.jsx(Rt,{content:"Close marketplace (Esc)",children:e.jsx("button",{type:"button",onClick:()=>o(!1),className:"transition-colors",style:{padding:4,borderRadius:6,cursor:"pointer",border:"none",background:"transparent",flexShrink:0,color:y.textDim},"aria-label":"Close marketplace",onMouseEnter:d=>{d.currentTarget.style.background="#ef444420",d.currentTarget.style.color="#ef4444"},onMouseLeave:d=>{d.currentTarget.style.background="transparent",d.currentTarget.style.color=y.textDim},children:e.jsx(ae,{size:16})})})]}),s==="skills"&&e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 16px",borderBottom:`1px solid ${y.borderSubtle}`,gap:12,flexWrap:"wrap"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:4,flexWrap:"wrap",flex:1},children:Xe.map(d=>e.jsx("button",{type:"button",onClick:()=>k(d.id),style:{fontSize:12,padding:"2px 10px",borderRadius:9999,cursor:"pointer",border:"none",fontWeight:500,background:h===d.id?"#FE5000":y.surfaceElevated,color:h===d.id?"#fff":y.textSecondary,transition:"background 150ms ease, color 150ms ease"},children:d.label},d.id))}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:12,flexShrink:0},children:Object.entries(je).map(([d,_])=>e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,fontSize:13,color:y.textDim},children:[e.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:_.color,display:"inline-block",flexShrink:0}}),_.label]},d))})]}),s==="mcp"&&e.jsx("div",{style:{display:"flex",alignItems:"center",padding:"8px 16px",gap:4,flexWrap:"wrap",borderBottom:`1px solid ${y.borderSubtle}`},children:Xe.map(d=>e.jsx("button",{type:"button",onClick:()=>k(d.id),style:{fontSize:12,padding:"2px 10px",borderRadius:9999,cursor:"pointer",border:"none",fontWeight:500,background:h===d.id?"#FE5000":y.surfaceElevated,color:h===d.id?"#fff":y.textSecondary,transition:"background 150ms ease, color 150ms ease"},children:d.label},d.id))}),e.jsxs("div",{style:{flex:1,overflowY:"auto"},children:[s==="skills"&&e.jsxs(e.Fragment,{children:[I.length>0&&e.jsx("div",{style:O,children:I.map(d=>e.jsx(bn,{skill:d,isInLibrary:H.has(d.id),installing:f===d.id,dropdownOpen:L===d.id,onToggleDropdown:()=>z(L===d.id?null:d.id),onInstall:K,t:y},d.id))}),I.length===0&&!m&&!M&&p.length===0&&e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"48px 0"},children:e.jsx("span",{style:{fontSize:14,color:y.textFaint},children:"No skills match your search"})}),(l.trim().length>=2||m||M||p.length>0)&&e.jsx("div",{style:{padding:"16px 16px 8px",borderTop:`1px solid ${y.borderSubtle}`},children:e.jsx("span",{style:{fontSize:12,letterSpacing:"0.05em",textTransform:"uppercase",color:y.textDim,fontFamily:"'Geist Mono', monospace"},children:"From skill.sh"})}),m&&e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"24px 0"},children:e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:6,fontSize:13,color:y.textDim},children:[e.jsx(X,{size:12,style:{animation:"spin 1s linear infinite"}}),"Searching skill.sh..."]})}),!m&&M&&e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"24px 16px"},children:e.jsx("span",{style:{fontSize:13,color:y.statusError},children:"skill.sh search unavailable"})}),!m&&!M&&p.length>0&&e.jsx("div",{style:{...O,paddingTop:0},children:p.map(d=>e.jsx(kn,{skill:d,installing:S===d.id,installed:w.has(d.id),onInstall:()=>x(d),t:y},d.id))}),!m&&!M&&l.trim().length>=2&&p.length===0&&e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"24px 16px"},children:e.jsx("span",{style:{fontSize:13,color:y.textFaint},children:"No results from skill.sh"})})]}),s==="mcp"&&e.jsxs("div",{style:{textAlign:"center",padding:40},children:[e.jsx("p",{style:{color:y.textDim,marginBottom:12},children:"Browse and connect MCP servers"}),e.jsx("button",{onClick:()=>{o(!1),$.getState().setShowConnectionPicker(!0)},style:{background:"#FE5000",color:"#fff",border:"none",borderRadius:6,padding:"8px 16px",cursor:"pointer",fontFamily:"'Geist Mono', monospace"},children:"Open Connection Picker"})]}),s==="presets"&&e.jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[v.map(d=>e.jsx(jn,{preset:d,t:y,onLoad:()=>o(!1)},d.id)),v.length===0&&e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"48px 0"},children:e.jsx("span",{style:{fontSize:14,color:y.textFaint},children:"No presets match your search"})})]})]})]})]})})}function bn({skill:t,isInLibrary:s,installing:o,dropdownOpen:n,onToggleDropdown:a,onInstall:r,t:i}){const[l,c]=u.useState(!1),[h,k]=u.useState("claude"),[f,E]=u.useState("project"),S=s||t.installed;return e.jsxs("div",{style:{background:i.surfaceElevated,border:`1px solid ${S?i.borderSubtle:i.border}`,borderRadius:6,padding:"10px 12px",display:"flex",flexDirection:"column",gap:5,opacity:S?.55:1,position:"relative",transition:"border-color 150ms ease",minHeight:120},onMouseEnter:g=>{S||(g.currentTarget.style.borderColor="#FE500050")},onMouseLeave:g=>{g.currentTarget.style.borderColor=S?i.borderSubtle:i.border},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:6},children:[e.jsx("span",{style:{fontSize:13,fontWeight:600,color:i.textPrimary,fontFamily:"'Geist Mono', monospace",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:t.name}),e.jsxs("span",{style:{fontSize:13,color:i.textDim,background:i.badgeBg,borderRadius:3,padding:"1px 4px",whiteSpace:"nowrap",flexShrink:0,fontFamily:"'Geist Mono', monospace"},children:[t.installs>=1e3?`${(t.installs/1e3).toFixed(1)}k`:t.installs,"↓"]})]}),e.jsx("span",{style:{fontSize:12,color:i.textDim,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"'Geist Sans', sans-serif"},children:t.author}),e.jsxs("div",{style:{flex:1},children:[e.jsx("span",{style:{fontSize:12,color:i.textMuted,fontFamily:"'Geist Sans', sans-serif",lineHeight:1.4,display:l?"block":"-webkit-box",WebkitLineClamp:l?"unset":2,WebkitBoxOrient:"vertical",overflow:l?"visible":"hidden"},children:t.description}),e.jsx("button",{type:"button",onClick:()=>c(!l),style:{background:"none",border:"none",padding:0,cursor:"pointer",color:i.textDim,display:"inline-flex",alignItems:"center",marginTop:1},children:l?e.jsx(Nt,{size:9}):e.jsx(ne,{size:9})})]}),e.jsx(Ze,{skillPath:t.id}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginTop:2},children:[e.jsx("div",{style:{display:"flex",gap:4,alignItems:"center"},children:t.runtimes.map(g=>e.jsx("span",{title:je[g].label,style:{width:7,height:7,borderRadius:"50%",background:je[g].color,display:"inline-block",flexShrink:0}},g))}),S?e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:3,fontSize:13,color:i.statusSuccess,background:i.statusSuccessBg,borderRadius:4,padding:"2px 6px"},children:[e.jsx(Z,{size:9})," In Library"]}):o?e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:3,fontSize:13,color:"#FE5000",background:"#FE500010",borderRadius:4,padding:"2px 6px"},children:[e.jsx(X,{size:9,className:"animate-spin"})," Installing"]}):e.jsxs("button",{type:"button",onClick:a,style:{fontSize:13,padding:"2px 8px",borderRadius:4,cursor:"pointer",border:`1px solid ${n?"#FE5000":i.border}`,color:n?"#FE5000":i.textSecondary,background:"transparent",display:"inline-flex",alignItems:"center",gap:3,transition:"border-color 150ms ease, color 150ms ease"},onMouseEnter:g=>{g.currentTarget.style.borderColor="#FE5000",g.currentTarget.style.color="#FE5000"},onMouseLeave:g=>{n||(g.currentTarget.style.borderColor=i.border,g.currentTarget.style.color=i.textSecondary)},onFocus:g=>{g.currentTarget.style.borderColor="#FE5000",g.currentTarget.style.color="#FE5000"},onBlur:g=>{n||(g.currentTarget.style.borderColor=i.border,g.currentTarget.style.color=i.textSecondary)},children:["Install ",e.jsx(ne,{size:8})]})]}),n&&e.jsxs("div",{style:{position:"absolute",right:0,bottom:"calc(100% + 4px)",background:i.surfaceOpaque,border:`1px solid ${i.border}`,boxShadow:"0 8px 24px rgba(0,0,0,0.5)",borderRadius:6,padding:10,zIndex:20,width:220,display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{children:[e.jsx("span",{style:{fontSize:13,fontWeight:600,color:i.textDim,fontFamily:"'Geist Mono', monospace",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Target"}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginTop:4},children:["all",...t.runtimes].map(g=>e.jsx("button",{type:"button",onClick:()=>k(g),style:{fontSize:13,padding:"2px 6px",borderRadius:4,cursor:"pointer",border:"none",background:h===g?"#FE5000":i.surfaceElevated,color:h===g?"#fff":i.textSecondary,fontWeight:500},children:g==="all"?"All":je[g].label},g))})]}),e.jsxs("div",{children:[e.jsx("span",{style:{fontSize:13,fontWeight:600,color:i.textDim,fontFamily:"'Geist Mono', monospace",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Scope"}),e.jsx("div",{style:{display:"flex",gap:4,marginTop:4},children:["project","global"].map(g=>e.jsx("button",{type:"button",onClick:()=>E(g),style:{fontSize:13,padding:"2px 6px",borderRadius:4,cursor:"pointer",border:"none",background:f===g?"#FE5000":i.surfaceElevated,color:f===g?"#fff":i.textSecondary,fontWeight:500,textTransform:"capitalize"},children:g},g))})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,background:i.inputBg,borderRadius:4,padding:"4px 6px"},children:[e.jsx(xe,{size:9,style:{color:i.textDim,flexShrink:0}}),e.jsxs("code",{style:{fontSize:12,color:i.textMuted,fontFamily:"'Geist Mono', monospace",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[t.installCmd," --target ",h," --scope ",f]})]}),e.jsx("button",{type:"button",onClick:()=>r(t.id,h,f),style:{width:"100%",padding:"6px",borderRadius:4,border:"none",background:"#FE5000",color:"#fff",fontSize:12,fontWeight:600,cursor:"pointer"},children:"Confirm Install"})]})]})}function kn({skill:t,installing:s,installed:o,onInstall:n,t:a}){const[r,i]=u.useState(!1),l=t.url.replace("https://skills.sh/","");return e.jsxs("div",{style:{background:a.surfaceElevated,border:`1px solid ${a.border}`,borderRadius:6,padding:"10px 12px",display:"flex",flexDirection:"column",gap:5,position:"relative",transition:"border-color 150ms ease",minHeight:120},onMouseEnter:c=>{c.currentTarget.style.borderColor="#FE500050"},onMouseLeave:c=>{c.currentTarget.style.borderColor=a.border},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:6},children:[e.jsx("span",{style:{fontSize:13,fontWeight:600,color:a.textPrimary,fontFamily:"'Geist Mono', monospace",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:t.name}),e.jsxs("span",{style:{fontSize:13,color:a.textDim,background:a.badgeBg,borderRadius:3,padding:"1px 4px",whiteSpace:"nowrap",flexShrink:0,fontFamily:"'Geist Mono', monospace"},children:[t.installs,"↓"]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[e.jsx("span",{style:{fontSize:12,color:a.textDim,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,fontFamily:"'Geist Sans', sans-serif"},children:t.repo}),e.jsx(Rt,{content:"View on skills.sh",children:e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:a.textDim,flexShrink:0,display:"inline-flex"},"aria-label":`Open ${t.name} on skills.sh`,onMouseEnter:c=>{c.currentTarget.style.color="#FE5000"},onMouseLeave:c=>{c.currentTarget.style.color=a.textDim},onFocus:c=>{c.currentTarget.style.color="#FE5000"},onBlur:c=>{c.currentTarget.style.color=a.textDim},children:e.jsx(Et,{size:10})})})]}),e.jsxs("div",{style:{flex:1},children:[e.jsx("span",{style:{fontSize:12,color:a.textMuted,fontFamily:"'Geist Sans', sans-serif",lineHeight:1.4,display:r?"block":"-webkit-box",WebkitLineClamp:r?"unset":2,WebkitBoxOrient:"vertical",overflow:r?"visible":"hidden"},children:t.url}),e.jsx("button",{type:"button",onClick:()=>i(!r),style:{background:"none",border:"none",padding:0,cursor:"pointer",color:a.textDim,display:"inline-flex",alignItems:"center",marginTop:1},children:r?e.jsx(Nt,{size:9}):e.jsx(ne,{size:9})})]}),e.jsx(Ze,{skillPath:l}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginTop:2},children:[e.jsx(ge,{size:10,style:{color:a.textDim}}),o?e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:3,fontSize:13,color:a.statusSuccess,background:a.statusSuccessBg,borderRadius:4,padding:"2px 6px"},children:[e.jsx(Z,{size:9})," Installed"]}):s?e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:3,fontSize:13,color:"#FE5000",background:"#FE500010",borderRadius:4,padding:"2px 6px"},children:[e.jsx(X,{size:9,className:"animate-spin"})," Installing"]}):e.jsxs("button",{type:"button",onClick:n,style:{fontSize:13,padding:"2px 8px",borderRadius:4,cursor:"pointer",border:`1px solid ${a.border}`,color:"#FE5000",background:"#FE500010",display:"inline-flex",alignItems:"center",gap:3},children:[e.jsx(Mt,{size:9})," Install"]})]})]})}function jn({preset:t,t:s,onLoad:o}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"0 16px",minHeight:56,borderBottom:`1px solid ${s.borderSubtle}`,transition:"background 100ms ease"},onMouseEnter:n=>{n.currentTarget.style.background=s.surfaceHover},onMouseLeave:n=>{n.currentTarget.style.background="transparent"},children:[e.jsx("div",{style:{width:24,height:24,borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,background:"#FE500010"},children:e.jsx(dn,{icon:t.icon,size:14,style:{color:"#FE5000"}})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:14,fontWeight:500,color:s.textPrimary},children:t.name}),e.jsx("div",{style:{fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:2,color:s.textMuted},title:t.description,spellCheck:!1,children:t.description}),e.jsxs("div",{style:{display:"flex",gap:4,marginTop:2},children:[t.skills.slice(0,3).map(n=>e.jsx("span",{style:{fontSize:12,padding:"0 4px",borderRadius:2,color:s.cableSkills,background:s.cableSkills+"10"},children:n},n)),t.mcpServers.slice(0,2).map(n=>e.jsx("span",{style:{fontSize:12,padding:"0 4px",borderRadius:2,color:s.cableMcp,background:s.cableMcp+"10"},children:n},n))]})]}),e.jsx("button",{type:"button",onClick:o,style:{fontSize:12,padding:"4px 8px",borderRadius:6,cursor:"pointer",flexShrink:0,background:"transparent",border:`1px solid ${s.border}`,color:s.textSecondary,whiteSpace:"nowrap",minWidth:80,transition:"border-color 150ms ease, color 150ms ease, background 150ms ease"},onMouseEnter:n=>{n.currentTarget.style.borderColor="#FE5000",n.currentTarget.style.color="#fff",n.currentTarget.style.background="#FE5000"},onMouseLeave:n=>{n.currentTarget.style.borderColor=s.border,n.currentTarget.style.color=s.textSecondary,n.currentTarget.style.background="transparent"},onFocus:n=>{n.currentTarget.style.borderColor="#FE5000",n.currentTarget.style.color="#fff",n.currentTarget.style.background="#FE5000"},onBlur:n=>{n.currentTarget.style.borderColor=s.border,n.currentTarget.style.color=s.textSecondary,n.currentTarget.style.background="transparent"},children:"Load Preset"})]})}const Le=(t="none")=>{switch(t){case"oauth":return{bg:"#FE500010",color:"#FE5000",text:"OAuth"};case"api-key":return{bg:"#3498db10",color:"#3498db",text:"API Key"};default:return{bg:"#2ecc7110",color:"#2ecc71",text:"Local"}}};function Pe({status:t}){const s=t==="connected"?"#00cc66":t==="connecting"?"#f5a623":t==="error"?"#ff4444":"#555",o=t==="connected"?"Connected":t==="connecting"?"Connecting…":t==="error"?"Error":"Disconnected";return e.jsx("span",{className:t==="connecting"?"animate-pulse":"",style:{display:"inline-block",width:7,height:7,borderRadius:"50%",background:s,flexShrink:0},title:o})}function ot({title:t,collapsed:s,onToggle:o,t:n}){return e.jsxs("div",{className:"flex items-center gap-2 px-5 py-3 cursor-pointer select-none border-t transition-colors",onClick:o,style:{borderColor:n.borderSubtle},onMouseEnter:a=>{a.currentTarget.style.background=n.isDark?"#ffffff08":"#00000008"},onMouseLeave:a=>{a.currentTarget.style.background="transparent"},children:[s?e.jsx(Me,{size:14,style:{color:n.textSecondary}}):e.jsx(ne,{size:14,style:{color:n.textSecondary}}),e.jsx("span",{className:"text-[13px] font-semibold",style:{color:n.textPrimary,fontFamily:"'Geist Sans', sans-serif"},children:t})]})}function vn(){const t=$(x=>x.showConnectionPicker),s=$(x=>x.setShowConnectionPicker),o=$(x=>x.connectors),n=$(x=>x.addConnector),a=$(x=>x.upsertMcpServer),r=W(),[i,l]=u.useState({}),[c,h]=u.useState({}),[k,f]=u.useState({}),[E,S]=u.useState(!1),[g,w]=u.useState(!1),[b,p]=u.useState("All"),[C,m]=u.useState({}),F=q(x=>x.servers),M=q(x=>x.addServer),R=fe.filter(x=>x.authMethod==="oauth"&&!!x.url),L=["All",...Array.from(new Set(fe.map(x=>x.category)))];u.useEffect(()=>{t&&R.forEach(x=>{Jt(x.url).then(j=>{if(l(T=>({...T,[x.url]:j.connected})),j.connected){const T=x.id;$.getState().connectors.some(P=>P.service===T)||n({id:`conn-${x.id}-oauth`,service:T,name:x.name,mcpServerId:x.id,direction:"both",enabled:!0,config:{},status:"connected",authMethod:"oauth"})}}).catch(()=>{})})},[t]);const z=async x=>{h(j=>({...j,[x.url]:!0})),f(j=>({...j,[x.url]:""}));try{await Qt(x.url),l(P=>({...P,[x.url]:!0})),await M({id:x.id,name:x.name,type:"http",command:"",args:[],env:{},url:x.url,headers:{},autoConnect:!0}),await a({id:x.id,name:x.name,description:x.description,connected:!0}),await q.getState().loadServers();const T=x.id;o.some(P=>P.service===T)||n({id:`conn-${x.id}-oauth-${Date.now()}`,service:T,name:x.name,mcpServerId:x.id,direction:"both",enabled:!0,config:{},status:"connected",authMethod:"oauth"})}catch(j){f(T=>({...T,[x.url]:j.message}))}finally{h(j=>({...j,[x.url]:!1}))}},G=x=>{const j=fe.find(T=>T.id===x);j&&m(T=>({...T,[x]:{entry:j,expanded:!T[x]?.expanded,configValues:T[x]?.configValues||{}}}))},D=(x,j,T)=>{m(P=>({...P,[x]:{...P[x],configValues:{...P[x]?.configValues,[j]:T}}}))},y=async x=>{const T=C[x.id]?.configValues||{};await a({id:x.id,name:x.name,description:x.description,connected:!1});const P={};x.configFields&&x.configFields.length>0&&x.configFields.forEach(A=>{const I=T[A.key];I&&(P[A.key]=I)}),await M({id:x.id,name:x.name,type:x.transport==="stdio"?"stdio":"http",command:x.command||"",args:x.defaultArgs||[],env:P,autoConnect:!0,...x.url?{url:x.url}:{}}),m(A=>({...A,[x.id]:{...A[x.id],expanded:!1}}))},H=x=>F.some(j=>j.id===x)||o.some(j=>j.mcpServerId===x),N=x=>F.find(T=>T.id===x)?.status??"disconnected",B=x=>{const j=i[x.url]??!1,T=c[x.url]??!1,P=k[x.url],A=H(x.id),I=Le("oauth");return e.jsxs("div",{className:"flex items-center gap-3 px-4 py-1.5 hover-row cursor-default",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center shrink-0",style:{background:r.surfaceElevated},children:e.jsx(Ae,{icon:x.icon,size:16,style:{color:r.textSecondary}})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Pe,{status:j?"connected":"disconnected"}),e.jsx("span",{className:"text-[13px] font-medium",style:{color:r.textPrimary},children:x.name}),e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full uppercase",style:{background:I.bg,color:I.color,fontFamily:"'Geist Mono', monospace",fontWeight:600},children:I.text})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px]",style:{color:r.textDim},children:x.description}),P&&e.jsx("span",{className:"text-[10px] ml-2",style:{color:"#ff4444"},children:P})]})]}),A&&j?e.jsxs("span",{className:"flex items-center gap-1 text-[11px] px-2.5 py-1 rounded-md",style:{color:r.statusSuccess,background:r.statusSuccessBg},children:[e.jsx(Z,{size:12})," Connected"]}):e.jsxs("button",{type:"button",onClick:()=>z(x),disabled:T,className:"flex items-center gap-1.5 text-[11px] px-3 py-1 rounded-md cursor-pointer border-none transition-colors",style:{background:"#FE500018",color:"#FE5000",fontWeight:600,opacity:T?.7:1},onMouseEnter:v=>{v.currentTarget.style.background="#FE500030"},onMouseLeave:v=>{v.currentTarget.style.background="#FE500018"},children:[T?e.jsx(X,{size:12,className:"animate-spin"}):e.jsx(re,{size:12}),T?"Connecting...":"Connect"]})]},x.id)},K=x=>{if(x.authMethod==="oauth"){const I=i[x.url]??!1,v=Le("oauth");return e.jsxs("div",{className:"flex items-center gap-3 px-4 py-1.5 hover-row cursor-default",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center shrink-0",style:{background:r.surfaceElevated},children:e.jsx(Ae,{icon:x.icon,size:16,style:{color:r.textSecondary}})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Pe,{status:I?"connected":"disconnected"}),e.jsx("span",{className:"text-[13px] font-medium",style:{color:r.textPrimary},children:x.name}),e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full uppercase",style:{background:v.bg,color:v.color,fontFamily:"'Geist Mono', monospace",fontWeight:600},children:v.text})]}),e.jsx("span",{className:"text-[11px]",style:{color:r.textDim},children:x.description})]}),e.jsxs("button",{type:"button",onClick:()=>x.url&&z(x),className:"flex items-center gap-1.5 text-[11px] px-3 py-1 rounded-md cursor-pointer border-none transition-colors",style:{background:"#FE500018",color:"#FE5000",fontWeight:600},onMouseEnter:O=>{O.currentTarget.style.background="#FE500030"},onMouseLeave:O=>{O.currentTarget.style.background="#FE500018"},children:[e.jsx(re,{size:12}),"Connect via OAuth"]})]},x.id)}const j=H(x.id),T=Le(x.authMethod),P=C[x.id],A=x.configFields&&x.configFields.length>0;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-1.5 hover-row cursor-default",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center shrink-0",style:{background:r.surfaceElevated},children:e.jsx(Ae,{icon:x.icon,size:16,style:{color:r.textSecondary}})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Pe,{status:N(x.id)}),e.jsx("span",{className:"text-[13px] font-medium",style:{color:r.textPrimary},children:x.name}),e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full uppercase",style:{background:T.bg,color:T.color,fontFamily:"'Geist Mono', monospace",fontWeight:600},children:T.text})]}),e.jsx("span",{className:"text-[11px]",style:{color:r.textDim},children:x.description})]}),j?e.jsxs("span",{className:"flex items-center gap-1 text-[11px] px-2.5 py-1 rounded-md",style:{color:r.statusSuccess,background:r.statusSuccessBg},children:[e.jsx(Z,{size:12})," Added"]}):e.jsxs("button",{type:"button",onClick:()=>A?G(x.id):y(x),className:"flex items-center gap-1.5 text-[11px] px-3 py-1 rounded-md cursor-pointer border-none",style:{background:"#FE500018",color:"#FE5000",fontWeight:600},children:[e.jsx(re,{size:12}),"Add"]})]}),A&&P?.expanded&&e.jsxs("div",{className:"px-4 py-3 ml-11 mr-4 mb-2 rounded-lg",style:{background:r.surfaceElevated},children:[e.jsx("div",{className:"text-[12px] font-medium mb-2",style:{color:r.textPrimary},children:"Configuration"}),e.jsxs("div",{className:"space-y-2",children:[x.configFields.map(I=>e.jsxs("div",{children:[e.jsxs("label",{className:"text-[11px]",style:{color:r.textDim},children:[I.label," ",I.required&&"*"]}),e.jsx("input",{type:I.type==="password"||I.key.toLowerCase().includes("token")||I.key.toLowerCase().includes("key")?"password":"text",placeholder:I.placeholder,value:P.configValues[I.key]||"",onChange:v=>D(x.id,I.key,v.target.value),className:"w-full mt-1 px-2 py-1 text-[12px] rounded border outline-none",style:{background:r.inputBg,border:`1px solid ${r.border}`,color:r.textPrimary,fontFamily:"'Geist Mono', monospace"}})]},I.key)),e.jsxs("div",{className:"flex gap-2 mt-3",children:[e.jsxs("button",{type:"button",onClick:()=>y(x),disabled:x.configFields.some(I=>I.required&&!P.configValues[I.key]),className:"flex items-center gap-1 text-[11px] px-3 py-1.5 rounded-md cursor-pointer border-none",style:{background:"#FE5000",color:"white",fontWeight:600,opacity:x.configFields.some(I=>I.required&&!P.configValues[I.key])?.5:1},children:[e.jsx(Z,{size:12}),"Save & Add"]}),e.jsx("button",{type:"button",onClick:()=>G(x.id),className:"text-[11px] px-3 py-1.5 rounded-md cursor-pointer border-none",style:{background:r.border,color:r.textDim},children:"Cancel"})]})]})]})]},x.id)};return e.jsx(Pt,{open:t,onClose:()=>s(!1),title:"Add Connection",searchPlaceholder:"Search connections...",width:600,children:x=>{const j=x?.toLowerCase()??"",T=R.filter(A=>!j||A.name.toLowerCase().includes(j)||A.description.toLowerCase().includes(j)),P=fe.filter(A=>{const I=!j||A.name.toLowerCase().includes(j)||A.description.toLowerCase().includes(j)||A.tags&&A.tags.some(O=>O.toLowerCase().includes(j)),v=b==="All"||A.category===b;return I&&v});return e.jsxs(e.Fragment,{children:[T.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ot,{title:"Quick Connect",collapsed:E,onToggle:()=>S(!E),t:r}),!E&&e.jsx("div",{className:"pb-2",children:T.map(B)})]}),e.jsx(ot,{title:"MCP Library",collapsed:g,onToggle:()=>w(!g),t:r}),!g&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex gap-1 px-5 py-2 overflow-x-auto",children:L.map(A=>e.jsx("button",{type:"button",onClick:()=>p(A),className:"text-[11px] px-2 py-1 rounded-md cursor-pointer border-none whitespace-nowrap transition-colors",style:{background:b===A?"#FE5000":"transparent",color:b===A?"white":r.textDim,fontFamily:"'Geist Mono', monospace",fontWeight:600},onMouseEnter:I=>{b!==A&&(I.currentTarget.style.background="#FE500015",I.currentTarget.style.color="#FE5000")},onMouseLeave:I=>{b!==A&&(I.currentTarget.style.background="transparent",I.currentTarget.style.color=r.textDim)},children:A},A))}),e.jsx("div",{className:"max-h-[400px] overflow-y-auto pb-2",children:P.map(K)})]})]})}})}const wn=[{id:"providers",label:"Providers"},{id:"mcp",label:"MCP Servers"},{id:"general",label:"General"}];function Ce(t,s){switch(t){case"connected":return s.statusSuccess;case"configured":return s.statusWarning;case"error":return s.statusError;default:return s.textMuted}}function Sn({provider:t}){const s=W(),[o,n]=u.useState(!1),[a,r]=u.useState(!1),[i,l]=u.useState(t.apiKey||""),[c,h]=u.useState(t.baseUrl),[k,f]=u.useState(null),E=Q(y=>y.setProviderKey),S=Q(y=>y.setProviderAuthMethod),g=Q(y=>y.setProviderBaseUrl),w=Q(y=>y.testConnection),b=Q(y=>y.testing[t.id]),p=Q(y=>y.deleteProvider),C=Q(y=>y.saveProvider),m=t.id.startsWith("custom-"),F=t.id==="openai",M=F&&t.authMethod==="oauth",R=t.id==="anthropic"?"Claude":t.name,L=Array.isArray(t.models)?t.models:[];u.useEffect(()=>{t.apiKey&&t.apiKey.trim().length>0&&l(t.apiKey),h(t.baseUrl)},[t.apiKey,t.baseUrl]);const z=u.useCallback(()=>{E(t.id,i),g(t.id,c),C(t.id)},[t.id,i,c,E,g,C]),G=u.useCallback(async()=>{z();const y=await w(t.id);f(y)},[t.id,z,w]),D={background:s.inputBg,border:`1px solid ${s.border}`,color:s.textPrimary,fontFamily:"'Geist Sans', sans-serif"};return e.jsxs("div",{style:{background:o?s.surfaceElevated:"transparent",borderBottom:`1px solid ${s.borderSubtle}`},children:[e.jsxs("div",{role:"button",tabIndex:0,className:"nodrag nowheel w-full flex items-center gap-3 px-4 py-3 cursor-pointer border-none bg-transparent text-left",onClick:()=>n(!o),style:{color:s.textPrimary},children:[e.jsx("div",{className:"w-2 h-2 rounded-full shrink-0",style:{background:Ce(t.status,s),boxShadow:`0 0 6px ${Ce(t.status,s)}40`}}),e.jsx("div",{className:"w-6 h-6 rounded-md flex items-center justify-center shrink-0",style:{background:t.color+"20"},children:e.jsx(Fe,{size:14,style:{color:t.color}})}),e.jsx("span",{className:"text-[14px] font-semibold flex-1",style:{fontFamily:"'Geist Mono', monospace"},children:R}),e.jsx("span",{className:"text-[12px]",style:{color:s.textMuted},children:t.status==="connected"?`${L.length} models`:t.status})]}),o&&e.jsxs("div",{className:"px-4 pb-4 flex flex-col gap-3",children:[F&&e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-[12px] tracking-wider uppercase",style:{color:s.textMuted,fontFamily:"'Geist Mono', monospace"},children:"Auth Mode"}),e.jsxs("select",{value:t.authMethod,onChange:y=>S(t.id,y.target.value),className:"nodrag nowheel w-full text-[14px] px-3 py-2 rounded-lg outline-none",style:D,children:[e.jsx("option",{value:"api-key",children:"API Key"}),e.jsx("option",{value:"oauth",children:"Local Session (experimental)"})]})]}),t.authMethod==="claude-agent-sdk"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 text-[14px] px-3 py-2.5 rounded-lg",style:{background:s.badgeBg,border:`1px solid ${s.borderSubtle}`},children:[e.jsx(xe,{size:14,style:{color:t.color}}),e.jsx("span",{style:{color:s.textSecondary},children:"Authenticates via your Claude Code login — no API key needed."})]}),t.status==="connected"&&e.jsxs("div",{className:"flex items-center gap-2 text-[14px] px-3 py-2 rounded-lg",style:{background:s.statusSuccessBg,border:`1px solid ${s.statusSuccess}30`,color:s.statusSuccess},children:[e.jsx(Ge,{size:14}),e.jsxs("span",{children:["Authenticated",t.lastError?` — ${t.lastError}`:" via Claude Code"]})]}),t.status==="error"&&e.jsxs("div",{className:"flex items-center gap-2 text-[14px] px-3 py-2 rounded-lg",style:{background:s.statusErrorBg,border:`1px solid ${s.statusError}30`,color:s.statusError},children:[e.jsx(_e,{size:14}),e.jsx("span",{children:t.lastError||"Not authenticated — install Claude Code and run claude login"})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-[12px] tracking-wider uppercase",style:{color:s.textMuted,fontFamily:"'Geist Mono', monospace"},children:"Available Models"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:L.map(y=>e.jsx("span",{className:"text-[12px] px-2 py-0.5 rounded",style:{background:t.color+"15",color:t.color,fontFamily:"'Geist Mono', monospace"},children:y.label},y.id))})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsxs("button",{type:"button",onClick:G,disabled:b,className:"nodrag nowheel flex items-center gap-1.5 text-[14px] px-3 py-1.5 rounded-lg cursor-pointer font-semibold border-none",style:{background:"#FE5000",color:"#fff",opacity:b?.6:1},children:[b?e.jsx(X,{size:12,className:"animate-spin"}):e.jsx(Tt,{size:12}),"Check Status"]}),e.jsx("button",{type:"button",onClick:G,disabled:b,className:"nodrag nowheel flex items-center gap-1 text-[13px] px-2.5 py-1.5 rounded-lg cursor-pointer border-none",style:{color:s.textSecondary,background:s.badgeBg,opacity:b?.6:1},children:"Refresh Models"})]})]}):e.jsxs(e.Fragment,{children:[M?e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-start gap-2 text-[14px] px-3 py-2.5 rounded-lg",style:{background:s.badgeBg,border:`1px solid ${s.borderSubtle}`},children:[e.jsx(xe,{size:14,style:{color:t.color,marginTop:1}}),e.jsx("span",{style:{color:s.textSecondary},children:"Codex browser sign-in (guided): open OpenAI dashboard, create key, and complete login flow."})]}),e.jsx("button",{type:"button",onClick:async()=>{try{const H=await(await fetch(`${J}/auth/codex/start`,{method:"POST"})).json(),N=H?.data?.sessionId,B=H?.data?.authUrl;if(!N||!B)return;window.open(B,"_blank","noopener,noreferrer");const K=window.prompt("Paste your OpenAI API key to complete Codex login");if(!K)return;const T=(await(await fetch(`${J}/auth/codex/complete/${N}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:K.trim()})})).json())?.data?.apiKey;if(!T)return;E(t.id,T),l(T),g(t.id,c),C(t.id),await G()}catch{}},className:"nodrag nowheel flex items-center justify-center gap-1.5 text-[14px] px-3 py-2 rounded-lg cursor-pointer font-semibold border-none",style:{background:"#FE5000",color:"#fff"},children:"Sign in with Codex"})]}):e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-[12px] tracking-wider uppercase",style:{color:s.textMuted,fontFamily:"'Geist Mono', monospace"},children:"API Key"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:a?"text":"password",value:i,onChange:y=>l(y.target.value),onBlur:z,placeholder:t._hasStoredKey?"Key stored on server":"sk-...",className:"nodrag nowheel w-full text-[14px] px-3 py-2 pr-9 rounded-lg outline-none",style:D}),e.jsx("button",{type:"button",onClick:()=>r(!a),className:"nodrag nowheel absolute right-2 top-1/2 -translate-y-1/2 cursor-pointer border-none bg-transparent p-0.5",style:{color:s.textDim},children:a?e.jsx(As,{size:14}):e.jsx(Ds,{size:14})})]})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-[12px] tracking-wider uppercase",style:{color:s.textMuted,fontFamily:"'Geist Mono', monospace"},children:"Base URL"}),e.jsx("input",{type:"text",value:c,onChange:y=>h(y.target.value),onBlur:z,className:"nodrag nowheel w-full text-[14px] px-3 py-2 rounded-lg outline-none",style:D})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsxs("button",{type:"button",onClick:G,disabled:b,className:"nodrag nowheel flex items-center gap-1.5 text-[14px] px-3 py-1.5 rounded-lg cursor-pointer font-semibold border-none",style:{background:"#FE5000",color:"#fff",opacity:b?.6:1},children:[b?e.jsx(X,{size:12,className:"animate-spin"}):e.jsx(qe,{size:12}),"Test Connection"]}),e.jsx("button",{type:"button",onClick:G,disabled:b,className:"nodrag nowheel flex items-center gap-1 text-[13px] px-2.5 py-1.5 rounded-lg cursor-pointer border-none",style:{color:s.textSecondary,background:s.badgeBg,opacity:b?.6:1},children:"Refresh Models"}),t.keyPageUrl&&!M&&e.jsxs("a",{href:t.keyPageUrl,target:"_blank",rel:"noopener noreferrer",className:"nodrag nowheel flex items-center gap-1 text-[13px] px-2 py-1.5 rounded-lg no-underline",style:{color:s.textSecondary,background:s.badgeBg},children:[e.jsx(Et,{size:10}),"Get API Key"]}),m&&e.jsxs("button",{type:"button",onClick:()=>p(t.id),className:"nodrag nowheel flex items-center gap-1 text-[13px] px-2 py-1.5 rounded-lg cursor-pointer border-none ml-auto",style:{color:s.statusError,background:s.statusErrorBg},children:[e.jsx(Je,{size:10}),"Remove"]})]}),k&&e.jsxs("div",{className:"flex items-center gap-2 text-[14px] px-3 py-2 rounded-lg",style:{background:k.ok?s.statusSuccessBg:s.statusErrorBg,border:`1px solid ${k.ok?s.statusSuccess+"30":s.statusError+"30"}`,color:k.ok?s.statusSuccess:s.statusError},children:[k.ok?e.jsx(Ge,{size:14}):e.jsx(_e,{size:14}),k.ok?`Connected${k.models?` — ${k.models.length} models available`:""}`:k.error||"Connection failed"]})]}),t.headerNote&&e.jsx("span",{className:"text-[12px]",style:{color:s.textFaint},children:t.headerNote})]})]})}function Cn(){const t=W(),s=Q(n=>n.providers),o=Q(n=>n.addCustomProvider);return e.jsxs("div",{className:"flex flex-col",children:[e.jsx("div",{className:"flex flex-col",children:s.filter((n,a,r)=>r.findIndex(i=>i.id===n.id)===a).map(n=>e.jsx(Sn,{provider:n},n.id))}),e.jsx("div",{className:"p-4",children:e.jsxs("button",{type:"button",onClick:o,className:"nodrag nowheel flex items-center gap-2 text-[14px] px-3 py-2 rounded-lg cursor-pointer w-full justify-center",style:{border:`1px dashed ${t.border}`,background:"transparent",color:t.textMuted},children:[e.jsx(re,{size:12}),"Add Custom Provider"]})})]})}function Nn({server:t}){const s=W(),[o,n]=u.useState(!1),a=q(h=>h.connectServer),r=q(h=>h.disconnectServer),i=q(h=>h.removeServer),l=$(h=>h.removeMcpServer),c=u.useCallback(()=>{t.status==="connected"?r(t.id):a(t.id)},[t.id,t.status,a,r]);return e.jsxs("div",{style:{borderBottom:`1px solid ${s.borderSubtle}`},children:[e.jsxs("div",{className:"nodrag nowheel w-full flex items-center gap-3 px-4 py-3",children:[e.jsx("div",{className:"w-2 h-2 rounded-full shrink-0",style:{background:Ce(t.status,s),boxShadow:`0 0 6px ${Ce(t.status,s)}40`}}),e.jsx(Ls,{size:14,style:{color:s.textDim}}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"text-[14px] font-semibold",style:{color:s.textPrimary,fontFamily:"'Geist Mono', monospace"},children:[t.name,t.mcpStatus&&t.mcpStatus!=="enabled"&&e.jsx("span",{className:"text-[12px] px-1.5 py-0.5 rounded ml-2 uppercase",style:{fontFamily:"'Geist Mono', monospace",fontWeight:600,background:t.mcpStatus==="deferred"?s.statusWarningBg:s.statusErrorBg,color:t.mcpStatus==="deferred"?s.statusWarning:s.statusError},children:t.mcpStatus})]}),e.jsx("div",{className:"text-[12px]",style:{color:s.textMuted},children:t.status==="connected"?`Connected · ${t.tools.length} tool${t.tools.length!==1?"s":""}${t.uptime?` · ${Math.round(t.uptime/1e3)}s uptime`:""}`:t.status==="connecting"?"Connecting…":t.status==="error"?t.lastError||"Connection error":"Disconnected"})]}),e.jsxs("button",{type:"button",onClick:h=>{h.stopPropagation(),c()},className:"nodrag nowheel flex items-center gap-1 text-[13px] px-2.5 py-1 rounded-lg cursor-pointer border-none",style:{background:t.status==="connected"?s.statusErrorBg:s.statusSuccessBg,color:t.status==="connected"?s.statusError:s.statusSuccess},children:[t.status==="connecting"?e.jsx(X,{size:10,className:"animate-spin"}):t.status==="connected"?e.jsx(Tt,{size:10}):e.jsx(qe,{size:10}),t.status==="connecting"?"Connecting...":t.status==="connected"?"Disconnect":"Reconnect"]}),e.jsx("button",{type:"button",onClick:()=>{i(t.id),l(t.id)},className:"nodrag nowheel flex items-center gap-1 text-[13px] px-2 py-1 rounded-lg cursor-pointer border-none",style:{color:s.statusError,background:s.statusErrorBg},title:"Remove server",children:e.jsx(Je,{size:10})})]}),t.tools.length>0&&e.jsxs("div",{className:"px-4 pb-3",children:[e.jsxs("button",{type:"button",onClick:()=>n(!o),className:"nodrag nowheel flex items-center gap-1 text-[12px] cursor-pointer border-none bg-transparent",style:{color:s.textDim},children:[o?e.jsx(ne,{size:12}):e.jsx(Me,{size:12}),"View Tools (",t.tools.length,")"]}),o&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-2",children:t.tools.map(h=>e.jsx("span",{className:"text-[12px] px-2 py-0.5 rounded",style:{background:"#FE500015",color:"#FE5000",fontFamily:"'Geist Mono', monospace"},title:h.description,children:h.name},h.name))})]})]})}function En(){const t=W(),s=$(D=>D.mcpServers),o=q(D=>D.servers),n=q(D=>D.loaded),a=q(D=>D.loading),r=q(D=>D.loadServers),i=q(D=>D.addServer),l=q(D=>D.error),c=$(D=>D.upsertMcpServer),h=s.map(D=>{const y=o.find(H=>H.id===D.id);return{...D,status:y?.status||"disconnected",tools:y?.tools||[],lastError:y?.lastError||void 0,command:y?.command||D.description||"",args:y?.args||[],env:y?.env||{}}}),k=o.filter(D=>!s.some(y=>y.id===D.id)).map(D=>({...D,isRuntimeOnly:!0})),f=[...h,...k],[E,S]=u.useState(!1),[g,w]=u.useState(""),[b,p]=u.useState(""),[C,m]=u.useState(""),[F,M]=u.useState(""),[R,L]=u.useState(!1);u.useEffect(()=>{!n&&!a&&r()},[n,a,r]);const z=u.useCallback(async()=>{if(!(!g.trim()||!b.trim())){L(!0);try{const D=C.split(`
|
|
3
|
+
`).filter(N=>N.trim()).map(N=>N.trim()),y={};F.split(`
|
|
4
|
+
`).forEach(N=>{const[B,...K]=N.split("=");B?.trim()&&K.length>0&&(y[B.trim()]=K.join("=").trim())});const H=await i({name:g.trim(),command:b.trim(),args:D,env:y});H&&c({id:H.id,name:H.name,description:H.command,connected:H.status==="connected"}),w(""),p(""),m(""),M(""),S(!1)}finally{L(!1)}}},[g,b,C,F,i,c]),G={background:t.inputBg,border:`1px solid ${t.border}`,color:t.textPrimary,fontFamily:"'Geist Sans', sans-serif"};return e.jsxs("div",{className:"flex flex-col",children:[e.jsx("div",{className:"mx-4 mt-3 mb-1 px-3 py-2 rounded-lg text-[12px]",style:{background:t.surfaceElevated,color:t.textMuted,border:`1px solid ${t.borderSubtle}`},children:"Configure new connections in the Connection Picker. This tab shows runtime status."}),a&&e.jsxs("div",{className:"px-4 py-8 text-center text-[14px]",style:{color:t.textMuted},children:[e.jsx(X,{size:16,className:"animate-spin mx-auto mb-2"}),"Loading MCP servers..."]}),l&&e.jsx("div",{className:"mx-4 mt-3 px-3 py-2 rounded-lg text-[14px]",style:{background:t.statusErrorBg,color:t.statusError,border:`1px solid ${t.statusError}30`},children:l}),n&&f.map(D=>e.jsx(Nn,{server:D},D.id)),n&&f.length===0&&!E&&e.jsx("div",{className:"px-4 py-8 text-center text-[14px]",style:{color:t.textMuted},children:"No MCP servers configured. Add a server below."}),E&&e.jsxs("div",{className:"p-4",style:{borderTop:`1px solid ${t.borderSubtle}`,background:t.surfaceElevated},children:[e.jsx("div",{className:"text-[14px] font-semibold mb-3",style:{color:t.textPrimary,fontFamily:"'Geist Mono', monospace"},children:"Add MCP Server"}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-[12px] tracking-wider uppercase",style:{color:t.textMuted,fontFamily:"'Geist Mono', monospace"},children:"Name"}),e.jsx("input",{type:"text",value:g,onChange:D=>w(D.target.value),placeholder:"My MCP Server",className:"nodrag nowheel w-full text-[14px] px-3 py-2 rounded-lg outline-none",style:G})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-[12px] tracking-wider uppercase",style:{color:t.textMuted,fontFamily:"'Geist Mono', monospace"},children:"Command"}),e.jsx("input",{type:"text",value:b,onChange:D=>p(D.target.value),placeholder:"uv",className:"nodrag nowheel w-full text-[14px] px-3 py-2 rounded-lg outline-none",style:G})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-[12px] tracking-wider uppercase",style:{color:t.textMuted,fontFamily:"'Geist Mono', monospace"},children:"Arguments (one per line)"}),e.jsx("textarea",{value:C,onChange:D=>m(D.target.value),placeholder:`tool
|
|
5
|
+
run
|
|
6
|
+
--python
|
|
7
|
+
/path/to/server.py`,className:"nodrag nowheel w-full text-[14px] px-3 py-2 rounded-lg outline-none resize-none",style:{...G,minHeight:"60px"},rows:3})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-[12px] tracking-wider uppercase",style:{color:t.textMuted,fontFamily:"'Geist Mono', monospace"},children:"Environment (key=value, one per line)"}),e.jsx("textarea",{value:F,onChange:D=>M(D.target.value),placeholder:`API_KEY=your_key
|
|
8
|
+
DEBUG=1`,className:"nodrag nowheel w-full text-[14px] px-3 py-2 rounded-lg outline-none resize-none",style:{...G,minHeight:"60px"},rows:3})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:z,disabled:R||!g.trim()||!b.trim(),className:"nodrag nowheel flex items-center gap-1.5 text-[14px] px-3 py-1.5 rounded-lg cursor-pointer font-semibold border-none",style:{background:"#FE5000",color:"#fff",opacity:R||!g.trim()||!b.trim()?.6:1},children:[R?e.jsx(X,{size:12,className:"animate-spin"}):e.jsx(re,{size:12}),"Add Server"]}),e.jsx("button",{type:"button",onClick:()=>S(!1),className:"nodrag nowheel text-[14px] px-3 py-1.5 rounded-lg cursor-pointer border-none",style:{color:t.textMuted,background:t.badgeBg},children:"Cancel"})]})]})]}),n&&!E&&e.jsx("div",{className:"p-4",children:e.jsxs("button",{type:"button",onClick:()=>S(!0),className:"nodrag nowheel flex items-center gap-2 text-[14px] px-3 py-2 rounded-lg cursor-pointer w-full justify-center",style:{border:`1px dashed ${t.border}`,background:"transparent",color:t.textMuted},children:[e.jsx(re,{size:12}),"Add MCP Server"]})})]})}function Mn(){const t=W(),s=Se(C=>C.theme),o=Se(C=>C.toggleTheme),[n,a]=u.useState(()=>localStorage.getItem("modular-edge-style")||"smoothstep"),[r,i]=u.useState(()=>localStorage.getItem("modular-grid-snap")!=="false"),[l,c]=u.useState(()=>localStorage.getItem("modular-minimap")!=="false"),[h,k]=u.useState(()=>localStorage.getItem("modular-bg-style")||"dots"),f=(C,m)=>localStorage.setItem(C,m),E=[{id:"system",label:"System",icon:Ms},{id:"light",label:"Light",icon:gt},{id:"dark",label:"Dark",icon:ht}],S=[{id:"smoothstep",label:"SmoothStep",icon:Ts},{id:"bezier",label:"Bezier",icon:Oe},{id:"step",label:"Step",icon:Fs}],g=[{id:"dots",label:"Dots"},{id:"lines",label:"Lines"},{id:"none",label:"None"}],w={color:t.textMuted,fontFamily:"'Geist Mono', monospace"},b={borderBottom:`1px solid ${t.borderSubtle}`},p=C=>{(C==="light"?"light":"dark")!==s&&o(),f("modular-theme",C)};return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3",style:b,children:[e.jsx("span",{className:"text-[12px] tracking-wider uppercase",style:w,children:"Theme"}),e.jsx("div",{className:"flex gap-1",children:E.map(C=>{const m=C.id==="system"&&s==="dark"&&localStorage.getItem("modular-theme")==="system"||C.id===s;return e.jsxs("button",{type:"button",onClick:()=>p(C.id),className:"nodrag nowheel flex items-center gap-1 text-[13px] px-2.5 py-1 rounded-md cursor-pointer border-none",style:{background:m?"#FE500020":t.badgeBg,color:m?"#FE5000":t.textDim},children:[e.jsx(C.icon,{size:11}),C.label]},C.id)})})]}),e.jsxs("div",{className:"flex items-center justify-between px-4 py-3",style:b,children:[e.jsx("span",{className:"text-[12px] tracking-wider uppercase",style:w,children:"Edge Routing"}),e.jsx("div",{className:"flex gap-1",children:S.map(C=>e.jsxs("button",{type:"button",onClick:()=>{a(C.id),f("modular-edge-style",C.id)},className:"nodrag nowheel flex items-center gap-1 text-[13px] px-2.5 py-1 rounded-md cursor-pointer border-none",style:{background:n===C.id?"#FE500020":t.badgeBg,color:n===C.id?"#FE5000":t.textDim},children:[e.jsx(C.icon,{size:11}),C.label]},C.id))})]}),e.jsxs("div",{className:"flex items-center justify-between px-4 py-3",style:b,children:[e.jsx("span",{className:"text-[12px] tracking-wider uppercase",style:w,children:"Grid Snap"}),e.jsx("button",{type:"button",onClick:()=>{const C=!r;i(C),f("modular-grid-snap",String(C))},className:"nodrag nowheel w-9 h-5 rounded-full cursor-pointer border-none relative transition-colors",style:{background:r?"#FE5000":t.badgeBg},children:e.jsx("div",{className:"absolute top-0.5 w-4 h-4 rounded-full transition-transform",style:{background:"#fff",left:r?"18px":"2px",boxShadow:"0 1px 3px rgba(0,0,0,0.3)"}})})]}),e.jsxs("div",{className:"flex items-center justify-between px-4 py-3",style:b,children:[e.jsx("span",{className:"text-[12px] tracking-wider uppercase",style:w,children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx($s,{size:11})," Minimap"]})}),e.jsx("button",{type:"button",onClick:()=>{const C=!l;c(C),f("modular-minimap",String(C))},className:"nodrag nowheel w-9 h-5 rounded-full cursor-pointer border-none relative transition-colors",style:{background:l?"#FE5000":t.badgeBg},children:e.jsx("div",{className:"absolute top-0.5 w-4 h-4 rounded-full transition-transform",style:{background:"#fff",left:l?"18px":"2px",boxShadow:"0 1px 3px rgba(0,0,0,0.3)"}})})]}),e.jsxs("div",{className:"flex items-center justify-between px-4 py-3",style:b,children:[e.jsx("span",{className:"text-[12px] tracking-wider uppercase",style:w,children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Is,{size:11})," Background"]})}),e.jsx("div",{className:"flex gap-1",children:g.map(C=>e.jsx("button",{type:"button",onClick:()=>{k(C.id),f("modular-bg-style",C.id)},className:"nodrag nowheel text-[13px] px-2.5 py-1 rounded-md cursor-pointer border-none",style:{background:h===C.id?"#FE500020":t.badgeBg,color:h===C.id?"#FE5000":t.textDim},children:C.label},C.id))})]})]})}function Tn({open:t,onClose:s}){const o=W(),n=$(c=>c.activeSettingsTab),[a,r]=u.useState(n||"providers");u.useEffect(()=>{t&&n&&r(n)},[t,n]);const i=u.useRef(null),l=u.useCallback(c=>{if(c.key!=="Tab"||!i.current)return;const h=i.current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(h.length===0)return;const k=h[0],f=h[h.length-1];c.shiftKey?document.activeElement===k&&(c.preventDefault(),f.focus()):document.activeElement===f&&(c.preventDefault(),k.focus())},[]);return u.useEffect(()=>{if(!t)return;const c=h=>{h.key==="Escape"&&s()};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[t,s]),t?e.jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center",onClick:s,children:[e.jsx("div",{className:"absolute inset-0",style:{background:o.isDark?"rgba(0,0,0,0.7)":"rgba(0,0,0,0.35)",backdropFilter:"blur(12px)"}}),e.jsxs("div",{ref:i,role:"dialog","aria-modal":"true","aria-label":"Settings",className:"relative w-[560px] max-h-[80vh] rounded-xl overflow-hidden flex flex-col",style:{background:o.surfaceOpaque,border:`1px solid ${o.border}`,boxShadow:"0 24px 48px rgba(0,0,0,0.4)"},onClick:c=>c.stopPropagation(),onKeyDown:l,children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-b shrink-0",style:{borderColor:o.borderSubtle},children:[e.jsx("span",{className:"text-[14px] tracking-wider uppercase flex-1 font-bold",style:{color:o.textPrimary,fontFamily:"'Geist Mono', monospace"},children:"Settings"}),e.jsx("button",{type:"button",onClick:s,className:"nodrag nowheel cursor-pointer border-none bg-transparent p-1 rounded-md",style:{color:o.textDim},"aria-label":"Close settings",children:e.jsx(ae,{size:14})})]}),e.jsx("div",{className:"flex gap-1 px-4 pt-2 border-b shrink-0 overflow-x-auto",style:{borderColor:o.borderSubtle,scrollbarWidth:"none"},children:wn.map(c=>e.jsx("button",{type:"button",onClick:()=>r(c.id),className:"nodrag nowheel text-[13px] tracking-wider uppercase px-3 py-2 cursor-pointer border-none bg-transparent font-semibold",style:{color:a===c.id?"#FE5000":o.textDim,borderBottom:a===c.id?"2px solid #FE5000":"2px solid transparent",fontFamily:"'Geist Mono', monospace",marginBottom:"-1px"},children:c.label},c.id))}),e.jsxs("div",{className:"flex-1 overflow-y-auto",style:{scrollbarWidth:"thin"},children:[a==="providers"&&e.jsx(Cn,{}),a==="mcp"&&e.jsx(En,{}),a==="general"&&e.jsx(Mn,{})]})]})]}):null}const Bt="modular-agent-library-v1";function ze(){return`${Date.now()}-${Math.random().toString(36).slice(2,8)}`}function Fn(){try{const t=localStorage.getItem(Bt);if(!t)return[];const s=JSON.parse(t);return Array.isArray(s)?s:[]}catch{return[]}}function rt(t){try{localStorage.setItem(Bt,JSON.stringify(t))}catch{}}const $n=Ee((t,s)=>({agents:[],agentLibrary:Fn(),sharedFacts:[],edges:[],activeAgentId:null,addAgent:o=>t(n=>({agents:[...n.agents,{...o,factIds:[],knowledgeSourceIds:[],mcpServerIds:[],skillIds:[]}]})),addAgentFromLibrary:o=>{const n=s().agentLibrary.find(r=>r.id===o);if(!n)return;s().addAgent({id:`${n.id}-${Date.now()}`,name:n.name,description:n.description,avatar:n.avatar,version:n.version});const a=s().agents[s().agents.length-1]?.id;a&&s().updateAgent(a,{mcpServerIds:n.mcpServerIds,skillIds:n.skillIds})},addAgentFromBackend:o=>{(async()=>{try{const n=await fetch(`${J}/agents/${encodeURIComponent(o)}`);if(!n.ok)return;const a=await n.json(),r=a.data??a,i=r.agentMeta??{};s().addAgent({id:`${o}-${Date.now()}`,name:i.name||o,description:i.description||"",avatar:i.avatar||"bot",version:r.version||"1.0.0"});const l=s().agents[s().agents.length-1]?.id;if(!l)return;s().updateAgent(l,{mcpServerIds:(r.mcpServers??[]).map(c=>c.id),skillIds:(r.skills??[]).map(c=>c.id)})}catch{}})()},upsertLibraryAgent:o=>t(n=>{const a=n.agentLibrary.some(r=>r.id===o.id)?n.agentLibrary.map(r=>r.id===o.id?o:r):[...n.agentLibrary,o];return rt(a),{agentLibrary:a}}),removeLibraryAgent:o=>t(n=>{const a=n.agentLibrary.filter(r=>r.id!==o);return rt(a),{agentLibrary:a}}),removeAgent:o=>t(n=>({agents:n.agents.filter(a=>a.id!==o),edges:n.edges.filter(a=>a.fromAgentId!==o&&a.toAgentId!==o)})),updateAgent:(o,n)=>t(a=>({agents:a.agents.map(r=>r.id===o?{...r,...n}:r)})),setActiveAgent:o=>t({activeAgentId:o}),addSharedFact:(o,n,a,r=[])=>{const i=`sf-${ze()}`;return t(l=>({sharedFacts:[...l.sharedFacts,{id:i,content:o,scope:n,originAgentId:a,sharedWith:[],tags:r,timestamp:Date.now()}]})),i},removeSharedFact:o=>t(n=>({sharedFacts:n.sharedFacts.filter(a=>a.id!==o)})),propagateFact:(o,n)=>t(a=>({sharedFacts:a.sharedFacts.map(r=>r.id===o?{...r,sharedWith:[...new Set([...r.sharedWith,...n])]}:r),edges:[...a.edges,...n.filter(r=>!a.edges.some(i=>i.type==="fact_propagation"&&i.fromAgentId===a.sharedFacts.find(l=>l.id===o)?.originAgentId&&i.toAgentId===r)).map(r=>({id:`edge-${ze()}`,fromAgentId:a.sharedFacts.find(i=>i.id===o)?.originAgentId||"",toAgentId:r,type:"fact_propagation",label:"shared fact"}))]})),markFactPromoted:(o,n,a)=>t(r=>({sharedFacts:r.sharedFacts.map(i=>i.id===o?{...i,promotedTo:{agentId:n,target:a,at:Date.now()}}:i)})),addEdge:o=>t(n=>({edges:[...n.edges,{...o,id:`edge-${ze()}`}]})),removeEdge:o=>t(n=>({edges:n.edges.filter(a=>a.id!==o)})),getAgentFacts:o=>s().sharedFacts.filter(n=>n.originAgentId===o),getSharedFactsForAgent:o=>s().sharedFacts.filter(n=>n.scope==="global"||n.originAgentId===o||n.sharedWith.includes(o))}));function In(t){return{...t}}const An={"claude-opus-4":"claude-opus-4","claude-sonnet-4":"claude-sonnet-4","claude-haiku-3.5":"claude-haiku-3.5","gpt-4o":"gpt-4o","gpt-4.1":"gpt-4.1"};function Ot(t,s){if(!t||!t.persona&&!t.objectives.primary&&!t.constraints.customConstraints)return s||"You are an analyst combining multiple knowledge sources to produce structured output.";const o=[];t.persona&&o.push(`You are ${t.persona}.`),t.tone!=="neutral"&&o.push(`Use a ${t.tone} tone.`),t.objectives.primary&&o.push(`
|
|
9
|
+
Primary objective: ${t.objectives.primary}`),t.objectives.successCriteria.length>0&&o.push("Success criteria: "+t.objectives.successCriteria.join("; "));const n=[];return t.constraints.neverMakeUp&&n.push("Never make up information"),t.constraints.askBeforeActions&&n.push("Ask before taking actions"),t.constraints.stayInScope&&n.push(`Stay in scope${t.constraints.scopeDefinition?": "+t.constraints.scopeDefinition:""}`),t.constraints.useOnlyTools&&n.push("Only use provided tools"),t.constraints.limitWords&&n.push(`Keep responses under ${t.constraints.wordLimit} words`),t.constraints.customConstraints&&n.push(t.constraints.customConstraints),n.length>0&&o.push(`
|
|
10
|
+
Constraints:
|
|
11
|
+
`+n.map(a=>`- ${a}`).join(`
|
|
12
|
+
`)),s&&o.push(`
|
|
13
|
+
`+s),o.join(`
|
|
14
|
+
`)}function de(t){const s=t.channels.filter(b=>b.enabled),o=An[t.selectedModel]??t.selectedModel,n=t.agentMeta.name||Gn(t.prompt,s),a=t.agentMeta.description||_n(t.prompt,s),r=t.skills.filter(b=>b.enabled&&b.added),i=t.mcpServers.filter(b=>b.enabled&&b.added),l=r.map(b=>b.name),c=i.map(b=>({name:b.name,transport:"stdio",command:`npx @${b.name.toLowerCase().replace(/\s+/g,"")}hq/mcp`})),h=s.map(b=>b.path),k=t.outputFormats.length>0?t.outputFormats:[t.outputFormat],f=[],E=Ot(t.instructionState,t.prompt);f.push(E);const S=t.agentConfig?.temperature??.7,g=t.agentConfig?.planningMode??"single-shot",w=[...(t.connectors??[]).filter(b=>b.enabled).map(b=>({service:b.service,direction:b.direction,config:b.config,type:"connector"})),...(t.mcpServers??[]).filter(b=>b.enabled!==!1).map(b=>({service:b.name||b.id,type:"mcp",id:b.id}))];return{name:n,description:a,model:o,icon:t.agentMeta.icon||"brain",category:t.agentMeta.category||"general",temperature:S,planningMode:g,tools:l,mcp_servers:c,reads:h,output_format:k,token_budget:t.tokenBudget,prompt:t.prompt,system:f.join(`
|
|
15
|
+
|
|
16
|
+
`),connections:w}}function te(t){return t.includes(`
|
|
17
|
+
`)||t.includes(":")||t.includes("#")||t.includes('"')?`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:t}function Dn(t){const s=["---"];if(s.push(`name: ${te(t.name)}`),s.push(`description: ${te(t.description)}`),s.push(`model: ${t.model}`),s.push(`temperature: ${t.temperature}`),s.push(`icon: ${t.icon}`),s.push(`category: ${t.category}`),t.tools.length>0){s.push("tools:");for(const o of t.tools)s.push(` - ${o}`)}if(t.mcp_servers.length>0){s.push("mcp_servers:");for(const o of t.mcp_servers)s.push(` - name: ${te(o.name)}`),s.push(` transport: ${o.transport}`),o.command&&s.push(` command: ${te(o.command)}`)}if(t.reads.length>0){s.push("reads:");for(const o of t.reads)s.push(` - ${te(o)}`)}if(t.output_format.length>0){s.push("output_format:");for(const o of t.output_format)s.push(` - ${o}`)}return s.push(`token_budget: ${t.token_budget}`),s.push("---"),s.join(`
|
|
18
|
+
`)}function Ln(t,s){const o=s.channels.filter(l=>l.enabled),n=s.instructionState,a=s.workflowSteps,r=[""];if(n?.persona&&(r.push("## Persona"),r.push(n.persona),n.tone!=="neutral"&&r.push(`
|
|
19
|
+
Tone: ${n.tone}`),n.expertise!==3&&r.push(`Expertise level: ${n.expertise}/5`),r.push("")),r.push("## Role"),r.push(t.system),r.push(""),n?.objectives.primary){if(r.push("## Objectives"),r.push(`**Primary:** ${n.objectives.primary}`),n.objectives.successCriteria.length>0){r.push(`
|
|
20
|
+
**Success Criteria:**`);for(const l of n.objectives.successCriteria)r.push(`- ${l}`)}if(n.objectives.failureModes.length>0){r.push(`
|
|
21
|
+
**Failure Modes:**`);for(const l of n.objectives.failureModes)r.push(`- ${l}`)}r.push("")}if(n){const l=[];if(n.constraints.neverMakeUp&&l.push("Never make up information"),n.constraints.askBeforeActions&&l.push("Ask before taking actions"),n.constraints.stayInScope&&l.push(`Stay in scope${n.constraints.scopeDefinition?": "+n.constraints.scopeDefinition:""}`),n.constraints.useOnlyTools&&l.push("Only use provided tools"),n.constraints.limitWords&&l.push(`Keep responses under ${n.constraints.wordLimit} words`),n.constraints.customConstraints&&l.push(n.constraints.customConstraints),l.length>0){r.push("## Constraints");for(const c of l)r.push(`- ${c}`);r.push("")}}if(t.prompt&&(r.push("## Default Prompt"),r.push(t.prompt),r.push("")),r.push("## Workflow"),a&&a.length>0)a.forEach((l,c)=>{const h=`${c+1}. ${l.label}`,k=l.action?` — ${l.action}`:"",f=l.condition!=="always"&&l.conditionText?` (${l.condition} ${l.conditionText})`:"";r.push(`${h}${k}${f}`)});else if(o.length>0){r.push("1. Read all knowledge sources");const l=new Map;for(const h of o){const k=h.knowledgeType;l.has(k)||l.set(k,[]),l.get(k).push(h)}let c=2;for(const[h,k]of l){const f=Zt[h];if(f){const E=k.map(S=>S.name).join(", ");r.push(`${c}. Process ${f.label.toLowerCase()} sources: ${E}`),c++}}r.push(`${c}. Synthesize findings`),r.push(`${c+1}. Generate output`)}else r.push("1. Analyze the provided context"),r.push("2. Identify patterns and key insights"),r.push("3. Synthesize findings"),r.push("4. Generate output");r.push("");const i=s.outputFormats.map(l=>Xt.find(h=>h.id===l)?.label??l);if(r.push("## Output Format"),r.push(i.length>0?i.join(", "):"Markdown"),r.push(""),s.knowledgeContent&&s.knowledgeContent.length>0){r.push("## Knowledge Sources");for(const l of s.knowledgeContent)r.push(`- **${l.name}** (${l.knowledgeType}, ${l.tokens} tokens) — \`${l.path}\``),s.portable&&l.content&&(r.push(""),r.push(" ```"),r.push(l.content.split(`
|
|
22
|
+
`).map(c=>" "+c).join(`
|
|
23
|
+
`)),r.push(" ```"),r.push(""));r.push("")}if(s.facts&&s.facts.length>0){r.push("## Extracted Insights");for(const l of s.facts)r.push(`- ${l.text}`);r.push("")}return r.join(`
|
|
24
|
+
`)}function Gt(t){const s=de(t),o=Dn(s),n=Ln(s,t);return o+`
|
|
25
|
+
`+n}function _t(t){const s=de(t),o=[];if(o.push(`name: ${te(s.name)}`),o.push(`model: ${s.model}`),s.tools.length>0){o.push("tools:");for(const a of s.tools)o.push(` - ${a}`)}if(s.mcp_servers.length>0){o.push("mcp:");for(const a of s.mcp_servers)o.push(` ${a.name.toLowerCase().replace(/\s+/g,"-")}:`),a.command&&o.push(` command: ${te(a.command)}`)}if(s.reads.length>0){o.push("context_files:");for(const a of s.reads)o.push(` - ${te(a)}`)}const n=Ot(t.instructionState,t.prompt);if(n){o.push("instructions: |");for(const a of n.split(`
|
|
26
|
+
`))o.push(` ${a}`)}return o.join(`
|
|
27
|
+
`)+`
|
|
28
|
+
`}function Pn(t){const s=de(t),o={name:s.name,model:s.model,instructions:s.system,tools:s.tools,mcp_servers:s.mcp_servers.map(n=>({name:n.name,transport:n.transport})),context_files:s.reads};return JSON.stringify(o,null,2)}function zn(t){const s=de(t),o={};for(const a of s.mcp_servers)o[a.name.toLowerCase().replace(/\s+/g,"-")]={command:a.command||""};const n={template:s.name,agent:"claude-code",context_files:s.reads,mcp_config:o,tools:s.tools,output_format:s.output_format};return JSON.stringify(n,null,2)}function Rn(t){const s=de(t),o=s.name.toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,""),n=[];if(n.push("agents:"),n.push(` ${o}:`),n.push(` model: ${s.model}`),n.push(` temperature: ${s.temperature}`),s.tools.length>0){n.push(" skills:");for(const a of s.tools)n.push(` - ${a}`)}if(s.mcp_servers.length>0){n.push(" mcp:"),n.push(" servers:");for(const a of s.mcp_servers){const r=a.name.toLowerCase().replace(/\s+/g,"-");n.push(` ${r}:`),a.command&&n.push(` command: ${te(a.command)}`)}}if(s.reads.length>0){n.push(" context:");for(const a of s.reads)n.push(` - ${te(a)}`)}return n.join(`
|
|
29
|
+
`)+`
|
|
30
|
+
`}function Bn(t){const s=de(t),o=t.outputTemplateConfig?Object.fromEntries(Object.entries(t.outputTemplateConfig).map(([r,i])=>[r,In(i)])):void 0,n=t.knowledgeContent?t.knowledgeContent.map(r=>({sourceId:r.sourceId,name:r.name,path:r.path,knowledgeType:r.knowledgeType,depth:r.depth,tokens:r.tokens,...t.portable&&r.content?{content:r.content}:{}})):s.reads.map(r=>({path:r})),a={modular_version:"1.0",agent:{name:s.name,description:s.description,model:s.model,temperature:s.temperature,system_prompt:s.system,planning_mode:s.planningMode,skills:s.tools,mcp_servers:s.mcp_servers,output_formats:s.output_format,token_budget:s.token_budget,connections:s.connections,...t.instructionState?{instructionState:t.instructionState}:{},...t.workflowSteps&&t.workflowSteps.length>0?{workflowSteps:t.workflowSteps}:{},...o&&Object.keys(o).length>0?{output:{templates:o}}:{}},knowledge:n};return t.pipelineSnapshot&&(a.pipeline_snapshot=t.pipelineSnapshot),t.facts&&t.facts.length>0&&(a.facts=t.facts),JSON.stringify(a,null,2)}function Po(t){return Gt(t)}function zo(t){return _t(t)}function Kt(t,s){switch(t){case"claude":return Gt(s);case"amp":return _t(s);case"codex":return Pn(s);case"vibe-kanban":return zn(s);case"openclaw":return Rn(s);case"generic":return Bn(s)}}const Wt={claude:{name:"Claude Code",ext:".md",mime:"text/markdown"},amp:{name:"Amp",ext:".yaml",mime:"text/yaml"},codex:{name:"Codex",ext:".json",mime:"application/json"},"vibe-kanban":{name:"Vibe Kanban",ext:".json",mime:"application/json"},openclaw:{name:"OpenClaw",ext:".yaml",mime:"text/yaml"},generic:{name:"Generic JSON",ext:".json",mime:"application/json"}};function Ut(t,s,o=".md"){const n={".md":"text/markdown",".json":"application/json",".yaml":"text/yaml"},a=new Blob([t],{type:n[o]||"text/plain"}),r=URL.createObjectURL(a),i=document.createElement("a");i.href=r,i.download=`${s}${o}`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}function On(t){const s=(t.agentMeta.name||"modular-agent").toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,""),o=["claude","amp","codex","vibe-kanban","openclaw","generic"];for(const n of o){const a=Kt(n,t),r=Wt[n],i=n==="claude"?s:`${s}-${n}`;Ut(a,i,r.ext)}}function Gn(t,s){if(t){const o=t.split(/\s+/).slice(0,4).join("-").toLowerCase().replace(/[^a-z0-9-]/g,"");if(o.length>3)return o}return s.length>0?s[0].name.toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,""):"modular-agent"}function _n(t,s){return t&&t.length>10?t.length>80?t.slice(0,77)+"...":t:`Analysis using ${s.length} sources via Modular`}function Kn(){const t=$.getState();q.getState();const s={version:"1.0",kind:"agent",identity:{name:t.agentMeta.name||"modular-agent",display_name:t.agentMeta.name||void 0,description:t.agentMeta.description||void 0,avatar:t.agentMeta.avatar||void 0,author:"Modular Studio",tags:t.agentMeta.tags?.length>0?t.agentMeta.tags:void 0,agent_version:"1.0.0"},instructions:{},context:{}},o={};t.instructionState.persona&&(o.persona=t.instructionState.persona),t.instructionState.tone!=="neutral"&&(o.tone=t.instructionState.tone),t.instructionState.expertise!==3&&(o.expertise=t.instructionState.expertise);const n=[];if(t.instructionState.constraints.neverMakeUp&&n.push("Never fabricate information or make up facts"),t.instructionState.constraints.askBeforeActions&&n.push("Ask for permission before taking significant actions"),t.instructionState.constraints.stayInScope&&n.push(`Stay within defined scope: ${t.instructionState.constraints.scopeDefinition||"as specified"}`),t.instructionState.constraints.useOnlyTools&&n.push("Only use explicitly provided tools and capabilities"),t.instructionState.constraints.limitWords&&n.push(`Keep responses under ${t.instructionState.constraints.wordLimit} words`),t.instructionState.constraints.customConstraints&&n.push(t.instructionState.constraints.customConstraints),n.length>0&&(o.constraints=n),t.instructionState.objectives.primary){const c={primary:t.instructionState.objectives.primary};t.instructionState.objectives.successCriteria.length>0&&(c.success_criteria=t.instructionState.objectives.successCriteria),t.instructionState.objectives.failureModes.length>0&&(c.failure_modes=t.instructionState.objectives.failureModes),o.objectives=c}t.instructionState.constraints.scopeDefinition&&(o.scope=t.instructionState.constraints.scopeDefinition),s.instructions=o;const a={},r=t.channels.filter(c=>c.enabled);r.length>0&&(a.knowledge=r.map(c=>({type:"file",ref:c.path||c.name,knowledge_type:c.knowledgeType,depth:c.depth})));const i=t.skills.filter(c=>c.enabled);i.length>0&&(a.skills=i.map(c=>({ref:c.name,source:"registry"})));const l=t.mcpServers.filter(c=>c.enabled);return l.length>0&&(a.mcp_servers=l.map(c=>({name:c.name,description:c.description,transport:"stdio",command:void 0,env:void 0}))),s.context=a,t.workflowSteps.length>0&&(s.workflow={steps:t.workflowSteps.map(c=>({id:c.id,action:c.action,tool:c.tool||void 0,condition:c.condition!=="always"?c.condition:void 0}))}),we(s)}function we(t,s=0){const o=" ".repeat(s);return Array.isArray(t)?t.map(n=>`${o}- ${we(n,0).trim()}`).join(`
|
|
31
|
+
`):typeof t=="object"&&t!==null?Object.entries(t).filter(([,n])=>n!=null).map(([n,a])=>{if(Array.isArray(a))return a.length===0?null:`${o}${n}:
|
|
32
|
+
${we(a,s+1)}`;if(typeof a=="object")return`${o}${n}:
|
|
33
|
+
${we(a,s+1)}`;{const r=typeof a=="string"&&(a.includes(`
|
|
34
|
+
`)||a.includes(":")||a.includes("#"))?`"${a.replace(/"/g,'\\"')}"`:String(a);return`${o}${n}: ${r}`}}).filter(Boolean).join(`
|
|
35
|
+
`):String(t)}const at=[{id:"brain",Icon:He},{id:"code",Icon:Ct},{id:"search",Icon:le},{id:"bar-chart-3",Icon:St},{id:"pen-tool",Icon:jt},{id:"file-text",Icon:Te},{id:"globe",Icon:kt},{id:"layers",Icon:Ps},{id:"zap",Icon:ge},{id:"database",Icon:Ve},{id:"shield",Icon:yt},{id:"settings",Icon:We},{id:"sparkles",Icon:$e},{id:"target",Icon:bt},{id:"book-open",Icon:wt},{id:"lightbulb",Icon:Ft},{id:"terminal",Icon:xe},{id:"box",Icon:Ye},{id:"layout-grid",Icon:$t},{id:"cpu",Icon:Fe}],Wn=["coding","research","analysis","writing","data","design","domain-specific","general"],it=[{id:"claude",name:"Claude Code",ext:".md",Icon:xe},{id:"amp",name:"Amp",ext:".yaml",Icon:ge},{id:"codex",name:"Codex",ext:".json",Icon:Fe},{id:"vibe-kanban",name:"Vibe Kanban",ext:".json",Icon:$t},{id:"openclaw",name:"OpenClaw",ext:".yaml",Icon:It},{id:"generic",name:"Generic JSON",ext:".json",Icon:Ye}];function Un(){const t=$(v=>v.showSaveModal),s=$(v=>v.setShowSaveModal),o=$(v=>v.agentMeta),n=$(v=>v.setAgentMeta),a=$(v=>v.channels),r=$(v=>v.selectedModel),i=$(v=>v.outputFormat),l=$(v=>v.outputFormats),c=$(v=>v.prompt),h=$(v=>v.tokenBudget),k=$(v=>v.mcpServers),f=$(v=>v.skills),E=$(v=>v.exportTarget),S=$(v=>v.setExportTarget),g=$(v=>v.agentConfig),w=$(v=>v.connectors),b=$(v=>v.instructionState),p=$(v=>v.workflowSteps),C=$n(v=>v.upsertLibraryAgent),[m,F]=u.useState(!1),[M,R]=u.useState(!1),[L,z]=u.useState(!0),G=u.useRef(null),D=u.useRef(null),y=W(),H=u.useCallback(v=>{if(v.key!=="Tab"||!D.current)return;const O=D.current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(O.length===0)return;const d=O[0],_=O[O.length-1];v.shiftKey?document.activeElement===d&&(v.preventDefault(),_.focus()):document.activeElement===_&&(v.preventDefault(),d.focus())},[]);u.useEffect(()=>{t?(R(!0),setTimeout(()=>G.current?.focus(),100)):R(!1)},[t]),u.useEffect(()=>{if(!t)return;const v=O=>{O.key==="Escape"&&s(!1)};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[t,s]);const N=u.useMemo(()=>({channels:a,selectedModel:r,outputFormat:i,outputFormats:l,prompt:c,tokenBudget:h,mcpServers:k,skills:f,agentMeta:o,agentConfig:g,connectors:w,instructionState:b,workflowSteps:p}),[a,r,i,l,c,h,k,f,o,g,w,b,p]),B=u.useMemo(()=>Kt(E,N),[N,E]),K=v=>{z(!1),S(v),setTimeout(()=>z(!0),30)},x=()=>{const v=o.name||"modular-agent",O=v.toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,"");C({id:O,name:v,description:o.description||"Saved from builder",avatar:o.avatar||"bot",version:"1.0.0",mcpServerIds:k.filter(U=>U.added).map(U=>U.id),skillIds:f.filter(U=>U.added).map(U=>U.id)});const d=es();fetch(`${J}/agents/${encodeURIComponent(O)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(d)}).catch(()=>{});const _=Wt[E];Ut(B,O,_.ext)},j=async()=>{await navigator.clipboard.writeText(B),F(!0),setTimeout(()=>F(!1),2e3)},T=()=>{On(N)},P=()=>{const v=Kn(),d=(o.name||"modular-agent").toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,""),_=new Blob([v],{type:"text/yaml;charset=utf-8"}),U=URL.createObjectURL(_),Y=document.createElement("a");Y.href=U,Y.download=`${d}.yaml`,document.body.appendChild(Y),Y.click(),document.body.removeChild(Y),URL.revokeObjectURL(U)};if(!t)return null;const A=at.find(v=>v.id===o.icon),I=it.find(v=>v.id===E);return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:()=>s(!1),children:[e.jsx("div",{className:"absolute inset-0",style:{background:"rgba(0,0,0,0.7)",backdropFilter:"blur(4px)",opacity:M?1:0,transition:"opacity 0.15s ease"}}),e.jsxs("div",{ref:D,role:"dialog","aria-modal":"true","aria-label":"Save as agent",className:"relative flex flex-col rounded-xl overflow-hidden",style:{width:880,maxHeight:"85vh",background:y.surface,border:`1px solid ${y.border}`,boxShadow:"0 24px 48px rgba(0,0,0,0.4)",opacity:M?1:0,transform:M?"scale(1)":"scale(0.97)",transition:"opacity 0.15s ease, transform 0.15s ease"},onClick:v=>v.stopPropagation(),onKeyDown:H,children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3.5",style:{borderBottom:`1px solid ${y.borderSubtle}`},children:[e.jsx("span",{className:"text-[14px] font-bold tracking-[3px] uppercase",style:{fontFamily:"'Geist Mono', monospace",color:y.textPrimary},children:"SAVE AS AGENT"}),e.jsx("button",{type:"button",onClick:()=>s(!1),className:"p-1 rounded-md cursor-pointer border-none",style:{background:"transparent",color:y.textMuted},"aria-label":"Close",children:e.jsx(ae,{size:16})})]}),e.jsx("div",{className:"flex gap-2 px-5 py-3",style:{borderBottom:`1px solid ${y.borderSubtle}`},children:it.map(v=>{const O=E===v.id;return e.jsxs("button",{type:"button",onClick:()=>K(v.id),className:"flex flex-col items-center gap-1 rounded-lg cursor-pointer border-none",style:{width:80,padding:"8px 4px",background:O?"#FE500012":"transparent",border:O?"1.5px solid #FE5000":`1.5px solid ${y.borderSubtle}`,transition:"all 0.12s ease"},children:[e.jsx(v.Icon,{size:18,style:{color:O?"#FE5000":y.textMuted}}),e.jsx("span",{className:"text-[12px] font-semibold leading-tight text-center",style:{fontFamily:"'Geist Mono', monospace",color:O?"#FE5000":y.textSecondary},children:v.name}),e.jsx("span",{className:"text-[13px] px-1.5 py-0.5 rounded",style:{fontFamily:"'Geist Mono', monospace",background:O?"#FE500020":y.badgeBg,color:O?"#FE5000":y.textDim},children:v.ext})]},v.id)})}),e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[e.jsxs("div",{className:"flex flex-col",style:{width:340,borderRight:`1px solid ${y.borderSubtle}`},children:[e.jsxs("div",{className:"flex-1 overflow-y-auto p-5 flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{className:"text-[13px] font-semibold uppercase tracking-wider",style:{color:y.textMuted,fontFamily:"'Geist Mono', monospace"},children:"Agent Name"}),e.jsx("input",{ref:G,type:"text",value:o.name,onChange:v=>n({name:v.target.value}),placeholder:"my-analysis-agent",className:"w-full outline-none text-[17px] rounded-lg px-3 py-2 nodrag",style:{background:y.inputBg,border:`1px solid ${y.border}`,color:y.textPrimary,fontFamily:"'Geist Sans', sans-serif"}})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{className:"text-[13px] font-semibold uppercase tracking-wider",style:{color:y.textMuted,fontFamily:"'Geist Mono', monospace"},children:"Description"}),e.jsx("textarea",{value:o.description,onChange:v=>n({description:v.target.value}),placeholder:"Deep research and synthesis agent...",className:"w-full outline-none text-[17px] rounded-lg px-3 py-2 resize-none",rows:3,style:{background:y.inputBg,border:`1px solid ${y.border}`,color:y.textPrimary,fontFamily:"'Geist Sans', sans-serif",lineHeight:1.5}})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{className:"text-[13px] font-semibold uppercase tracking-wider",style:{color:y.textMuted,fontFamily:"'Geist Mono', monospace"},children:"Icon"}),e.jsx("div",{className:"grid grid-cols-10 gap-1",children:at.map(({id:v,Icon:O})=>e.jsx("button",{type:"button",onClick:()=>n({icon:v}),className:"flex items-center justify-center w-7 h-7 rounded-md cursor-pointer border-none",style:{background:o.icon===v?"#FE500020":"transparent",border:o.icon===v?"1px solid #FE500040":"1px solid transparent",color:o.icon===v?"#FE5000":y.textMuted,transition:"all 0.1s ease"},children:e.jsx(O,{size:14})},v))})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{className:"text-[13px] font-semibold uppercase tracking-wider",style:{color:y.textMuted,fontFamily:"'Geist Mono', monospace"},children:"Category"}),e.jsx("select",{value:o.category,onChange:v=>n({category:v.target.value}),className:"w-full outline-none text-[17px] rounded-lg px-3 py-2 cursor-pointer",style:{background:y.inputBg,border:`1px solid ${y.border}`,color:y.textPrimary,fontFamily:"'Geist Sans', sans-serif"},children:Wn.map(v=>e.jsx("option",{value:v,children:v.charAt(0).toUpperCase()+v.slice(1).replace("-"," ")},v))})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 px-5 py-4",style:{borderTop:`1px solid ${y.borderSubtle}`},children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{type:"button",onClick:x,className:"flex items-center justify-center gap-1.5 flex-1 py-2 rounded-lg text-[14px] font-semibold tracking-wider uppercase cursor-pointer border-none",style:{background:"#FE5000",color:"#fff",boxShadow:"0 0 8px rgba(254,80,0,0.25)"},children:[e.jsx(Mt,{size:13}),"Download"]}),e.jsxs("button",{type:"button",onClick:j,className:"flex items-center justify-center gap-1.5 flex-1 py-2 rounded-lg text-[14px] font-semibold tracking-wider uppercase cursor-pointer",style:{background:"transparent",border:`1px solid ${y.border}`,color:m?y.statusSuccess:y.textSecondary,transition:"color 0.15s ease"},children:[m?e.jsx(Z,{size:13}):e.jsx(At,{size:13}),m?"Copied":"Copy"]})]}),e.jsxs("button",{type:"button",onClick:T,className:"flex items-center justify-center gap-1.5 w-full py-2 rounded-lg text-[14px] font-semibold tracking-wider uppercase cursor-pointer",style:{background:"transparent",border:`1px solid ${y.borderSubtle}`,color:y.textMuted},children:[e.jsx(It,{size:13}),"Export All Targets"]}),e.jsxs("button",{type:"button",onClick:P,className:"flex items-center justify-center gap-1.5 w-full py-2 rounded-lg text-[14px] font-semibold tracking-wider uppercase cursor-pointer",style:{background:"transparent",border:`1px solid ${y.borderSubtle}`,color:y.textMuted},children:[e.jsx(Te,{size:13}),"Export as YAML"]})]})]}),e.jsxs("div",{className:"flex flex-col flex-1",style:{background:y.isDark?"#0d0d10":"#f5f5f8"},children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3",style:{borderBottom:`1px solid ${y.borderSubtle}`},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[A&&e.jsx(A.Icon,{size:14,style:{color:"#FE5000"}}),e.jsx("span",{className:"text-[14px] font-bold tracking-[2px] uppercase",style:{fontFamily:"'Geist Mono', monospace",color:y.textMuted},children:"Preview"}),e.jsxs("span",{className:"text-[13px] px-1.5 py-0.5 rounded",style:{fontFamily:"'Geist Mono', monospace",background:"#FE500018",color:"#FE5000"},children:[I.name," ",I.ext]})]}),e.jsxs("span",{className:"text-[12px]",style:{fontFamily:"'Geist Mono', monospace",color:y.textDim},children:[B.split(`
|
|
36
|
+
`).length," lines"]})]}),e.jsx("div",{className:"flex-1 overflow-auto p-4",style:{opacity:L?1:0,transition:"opacity 0.12s ease"},children:e.jsx("pre",{className:"text-[14px] leading-relaxed whitespace-pre-wrap break-all m-0",style:{fontFamily:"'Geist Mono', monospace",color:y.textSecondary},children:B.split(`
|
|
37
|
+
`).map((v,O)=>e.jsxs("div",{className:"flex",children:[e.jsx("span",{className:"inline-block text-right select-none shrink-0",style:{width:32,color:y.textFaint,marginRight:12},children:O+1}),e.jsx("span",{style:{color:Hn(v,E,y)},children:v||" "})]},O))})})]})]})]})]})}function Hn(t,s,o){return t.trim()?s==="codex"||s==="vibe-kanban"||s==="generic"?/^\s*"\w[\w_-]*"\s*:/.test(t)?"#67d4e8":/:\s*"[^"]*"\s*,?$/.test(t)?"#a8d4a0":/:\s*(\d+\.?\d*|true|false|null)\s*,?$/.test(t)?"#d4a86a":o.textSecondary:t==="---"?"#FE5000":t.startsWith("##")||t.startsWith("# ")?o.textPrimary:/^\s*#/.test(t)?o.isDark?"#666":"#999":/^\s*\w[\w_-]*\s*:/.test(t)?"#67d4e8":/^\s+-\s/.test(t)||/^\d+\./.test(t)?o.textSecondary:o.textMuted:o.textMuted}const Re=u.forwardRef(function({variant:s="secondary",size:o="md",icon:n,iconRight:a,loading:r,children:i,className:l="",style:c,disabled:h,...k},f){const E=W(),S={sm:28,md:32},g={sm:"0 8px",md:"0 14px"},w={sm:12,md:13},p={primary:{bg:"#FE5000",color:"#fff",border:"transparent",hoverBg:"#e54700"},secondary:{bg:E.surfaceElevated,color:E.textSecondary,border:E.border,hoverBg:E.isDark?"#2a2a30":"#eee"},ghost:{bg:"transparent",color:E.textSecondary,border:"transparent",hoverBg:E.isDark?"#ffffff08":"#00000008"},danger:{bg:E.statusErrorBg,color:E.statusError,border:"transparent",hoverBg:E.isDark?"#ff4d4f20":"#ff4d4f15"}}[s];return e.jsxs("button",{ref:f,type:"button",disabled:h||r,className:`ds-btn flex items-center justify-center gap-1.5 rounded-lg cursor-pointer border font-semibold tracking-wide uppercase nodrag ${l}`,style:{height:S[o],padding:g[o],fontSize:w[o],fontFamily:"'Geist Mono', monospace",background:p.bg,color:p.color,borderColor:p.border,opacity:h?.5:1,cursor:h?"not-allowed":"pointer",transition:"background 0.15s, opacity 0.15s",...c},onMouseEnter:C=>{h||(C.currentTarget.style.background=p.hoverBg)},onMouseLeave:C=>{C.currentTarget.style.background=p.bg},...k,children:[r?e.jsx("span",{className:"animate-spin text-[12px]",children:"⟳"}):n,i,a]})});function lt({icon:t,title:s,subtitle:o,action:n,className:a=""}){const r=W();return e.jsxs("div",{className:`flex flex-col items-center justify-center text-center py-8 px-4 ${a}`,children:[e.jsx("div",{className:"mb-3 opacity-30",style:{color:r.textFaint},children:t}),e.jsx("h3",{className:"text-[17px] font-semibold mb-1",style:{color:r.textPrimary,fontFamily:"'Geist Mono', monospace",fontSize:13},children:s}),o&&e.jsx("p",{className:"text-[14px] max-w-xs mb-4",style:{color:r.textMuted,fontSize:12,lineHeight:1.4},children:o}),n&&e.jsx("div",{children:n})]})}function Ht({size:t="md",className:s=""}){const o=W(),n={sm:12,md:16,lg:24};return e.jsx("div",{className:`animate-spin rounded-full border-2 border-solid ${s}`,style:{width:n[t],height:n[t],borderColor:`${o.border} ${o.border} #FE5000 ${o.border}`},role:"status","aria-label":"Loading"})}function Vn({open:t,onClose:s,title:o,children:n,footer:a,width:r=520}){const i=W(),l=u.useRef(null);return u.useEffect(()=>{if(!t)return;const c=h=>{h.key==="Escape"&&s()};return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[t,s]),u.useEffect(()=>{t&&l.current?.focus()},[t]),t?Ne.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[200] flex items-center justify-center",onClick:s,children:[e.jsx("div",{className:"absolute inset-0",style:{background:"rgba(0,0,0,0.5)",backdropFilter:"blur(4px)"}}),e.jsxs("div",{ref:l,tabIndex:-1,onClick:c=>c.stopPropagation(),className:"relative flex flex-col rounded-xl overflow-hidden outline-none",style:{width:r,maxWidth:"90vw",maxHeight:"80vh",background:i.surfaceOpaque,border:`1px solid ${i.border}`,boxShadow:`0 16px 48px ${i.isDark?"rgba(0,0,0,0.6)":"rgba(0,0,0,0.15)"}`},children:[o&&e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 shrink-0",style:{borderBottom:`1px solid ${i.borderSubtle}`},children:[e.jsx("span",{className:"text-[17px] font-bold",style:{fontFamily:"'Geist Mono', monospace",color:i.textPrimary},children:o}),e.jsx("button",{type:"button",onClick:s,className:"flex items-center justify-center w-7 h-7 rounded-md cursor-pointer border-none bg-transparent",style:{color:i.textDim},children:e.jsx(ae,{size:14})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:n}),a&&e.jsx("div",{className:"flex items-center justify-end gap-2 px-4 py-3 shrink-0",style:{borderTop:`1px solid ${i.borderSubtle}`},children:a})]})]}),document.body):null}function Yn({options:t,value:s,onChange:o,label:n,placeholder:a="Select...",size:r="md"}){const i=W(),[l,c]=u.useState(!1),[h,k]=u.useState({x:0,y:0,w:0}),f=u.useRef(null),E=t.find(w=>w.value===s),S={sm:28,md:32};u.useEffect(()=>{if(!l)return;const w=()=>c(!1);return document.addEventListener("click",w),()=>document.removeEventListener("click",w)},[l]);const g=()=>{if(!f.current)return;const w=f.current.getBoundingClientRect();k({x:w.left,y:w.bottom+4,w:w.width}),c(!l)};return e.jsxs("div",{className:"flex flex-col gap-1",children:[n&&e.jsx("label",{className:"text-[13px] tracking-wider uppercase font-semibold",style:{color:i.textMuted,fontFamily:"'Geist Mono', monospace"},children:n}),e.jsxs("button",{ref:f,type:"button",onClick:w=>{w.stopPropagation(),g()},className:"flex items-center justify-between gap-2 w-full rounded-lg cursor-pointer border outline-none nodrag",style:{height:S[r],padding:"0 10px",fontSize:13,fontFamily:"'Geist Mono', monospace",background:i.inputBg,borderColor:i.border,color:E?i.textPrimary:i.textMuted},children:[e.jsxs("span",{className:"flex items-center gap-1.5 truncate",children:[E?.icon,E?.label||a]}),e.jsx(ne,{size:12,style:{color:i.textDim,transform:l?"rotate(180deg)":"none",transition:"transform 0.15s"}})]}),l&&Ne.createPortal(e.jsx("div",{className:"fixed z-[250] rounded-lg overflow-hidden py-1",style:{left:h.x,top:h.y,width:h.w,background:i.surfaceElevated,border:`1px solid ${i.border}`,boxShadow:`0 8px 24px ${i.isDark?"rgba(0,0,0,0.5)":"rgba(0,0,0,0.12)"}`,maxHeight:200,overflowY:"auto"},onClick:w=>w.stopPropagation(),children:t.map(w=>e.jsxs("button",{type:"button",onClick:()=>{o(w.value),c(!1)},className:"flex items-center gap-2 w-full px-3 py-1.5 text-[13px] text-left cursor-pointer border-none bg-transparent",style:{fontFamily:"'Geist Mono', monospace",color:w.value===s?"#FE5000":i.textSecondary,background:w.value===s?"#FE500008":"transparent"},onMouseEnter:b=>b.currentTarget.style.background=i.isDark?"#ffffff08":"#00000005",onMouseLeave:b=>b.currentTarget.style.background=w.value===s?"#FE500008":"transparent",children:[w.icon,e.jsx("span",{className:"flex-1 truncate",children:w.label}),w.value===s&&e.jsx(Z,{size:10})]},w.value))}),document.body)]})}const ct="rgba(99,102,241,0.4)",Be="#6366f1",dt="rgba(99,102,241,0.12)";function qn({id:t,name:s,description:o,tags:n,onUse:a}){const r=W(),i={background:r.surfaceOpaque,border:`1px dashed ${ct}`,boxShadow:`0 2px 8px ${r.isDark?"rgba(0,0,0,0.2)":"rgba(0,0,0,0.04)"}`};return e.jsx("div",{role:"button",tabIndex:0,title:`Use ${s} template`,className:"cursor-pointer rounded-lg overflow-hidden transition-all duration-200 hover:shadow-lg",onClick:()=>a(t),onKeyDown:l=>{(l.key==="Enter"||l.key===" ")&&a(t)},style:i,onMouseEnter:l=>{l.currentTarget.style.borderColor=Be},onMouseLeave:l=>{l.currentTarget.style.borderColor=ct},children:e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center shrink-0",style:{background:dt},children:e.jsx($e,{size:14,style:{color:Be}})}),e.jsx("h3",{className:"text-base font-semibold truncate",style:{color:r.textPrimary,fontFamily:"'Geist Sans', sans-serif"},children:s})]}),e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded shrink-0 ml-2 font-medium uppercase tracking-wide",style:{background:dt,color:Be,fontFamily:"'Geist Mono', monospace"},children:"Template"})]}),e.jsx("p",{className:"text-sm line-clamp-2 mb-3",style:{color:r.textSecondary},children:o||"No description"}),n.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[n.slice(0,3).map(l=>e.jsx("span",{className:"text-[11px] px-1.5 py-0.5 rounded",style:{background:r.surfaceElevated,color:r.textDim,fontFamily:"'Geist Mono', monospace"},children:l},l)),n.length>3&&e.jsxs("span",{className:"text-[11px] px-1.5 py-0.5 rounded",style:{background:r.surfaceElevated,color:r.textFaint},children:["+",n.length-3]})]})]})})}const Jn=[{value:"modified",label:"Last Modified"},{value:"name",label:"Name (A–Z)"},{value:"created",label:"Created"}],ut=Object.entries(ts).map(([t,s])=>({id:t,name:s.agentMeta.name,description:s.agentMeta.description,tags:s.agentMeta.tags}));let Qn=0;function Zn({onSelectAgent:t,onNewAgent:s}){const[o,n]=u.useState([]),[a,r]=u.useState(!0),[i,l]=u.useState(null),[c,h]=u.useState(""),[k,f]=u.useState(""),[E,S]=u.useState("modified"),[g,w]=u.useState(null),[b,p]=u.useState(null),[C,m]=u.useState(null),[F,M]=u.useState([]),R=u.useRef(null),L=W();u.useEffect(()=>(R.current&&clearTimeout(R.current),R.current=setTimeout(()=>f(c),300),()=>{R.current&&clearTimeout(R.current)}),[c]);const z=u.useCallback((j,T)=>{const P=++Qn;M(A=>[...A,{id:P,type:j,message:T}]),setTimeout(()=>M(A=>A.filter(I=>I.id!==P)),3500)},[]),G=u.useCallback(j=>{const{loadDemoPreset:T}=$.getState();T(j),s()},[s]),D=u.useMemo(()=>{const j=k.trim().toLowerCase();return j?ut.filter(T=>T.name.toLowerCase().includes(j)||T.description.toLowerCase().includes(j)):ut},[k]),y=u.useCallback(async()=>{try{r(!0),l(null);const j=await fetch(`${J}/agents`);if(!j.ok)throw new Error("Failed to load agents");const T=await j.json(),P=T.data??T??[];n(P.map(A=>({id:A.id,name:A.agentMeta?.name||A.id,description:A.agentMeta?.description||"",avatar:A.agentMeta?.avatar||"",tags:A.agentMeta?.tags||[],updatedAt:A.savedAt||new Date().toISOString()})))}catch(j){l(j instanceof Error?j.message:"Unknown error")}finally{r(!1)}},[]);u.useEffect(()=>{y()},[y]);const H=()=>{const{resetAgent:j}=$.getState();j(),s()},N=async()=>{if(g){p(g.id),w(null);try{if(!(await fetch(`${J}/agents/${encodeURIComponent(g.id)}`,{method:"DELETE"})).ok)throw new Error("Delete failed");n(T=>T.filter(P=>P.id!==g.id)),z("success",`"${g.name}" deleted`)}catch{z("error",`Failed to delete "${g.name}"`)}finally{p(null)}}},B=async(j,T)=>{T.stopPropagation(),m(j.id);try{const P=await fetch(`${J}/agents/${encodeURIComponent(j.id)}`);if(!P.ok)throw new Error("Failed to load agent");const A=await P.json(),I=A.data??A,v=`agent-${Date.now()}`,O={...I,id:v,savedAt:new Date().toISOString(),agentMeta:{...I.agentMeta,name:`${I.agentMeta?.name||j.name} (Copy)`}};if(!(await fetch(`${J}/agents`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(O)})).ok)throw new Error("Failed to save clone");z("success",`Cloned as "${O.agentMeta.name}"`),t(v)}catch{z("error",`Failed to clone "${j.name}"`)}finally{m(null)}},K=u.useMemo(()=>{const j=k.trim().toLowerCase();let T=j?o.filter(P=>P.name.toLowerCase().includes(j)||P.description.toLowerCase().includes(j)):o;return E==="name"?T=[...T].sort((P,A)=>P.name.localeCompare(A.name)):E==="modified"?T=[...T].sort((P,A)=>new Date(A.updatedAt).getTime()-new Date(P.updatedAt).getTime()):E==="created"&&(T=[...T].sort((P,A)=>{const I=parseInt(P.id.replace("agent-",""))||0,v=parseInt(A.id.replace("agent-",""))||0;return I-v})),T},[o,k,E]),x=j=>{const T=new Date(j),A=Math.floor((new Date().getTime()-T.getTime())/(1e3*60*60));return A<1?"Just now":A<24?`${A}h ago`:A<168?`${Math.floor(A/24)}d ago`:T.toLocaleDateString()};return a?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(Ht,{size:"lg"})}):i?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(lt,{icon:e.jsx(et,{size:32}),title:"Failed to Load Agents",subtitle:i})}):e.jsxs("div",{className:"flex flex-col h-full overflow-hidden",style:{background:L.bg},children:[e.jsxs("div",{className:"px-6 py-4 border-b",style:{borderColor:L.border},children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold mb-1",style:{color:L.textPrimary},children:"Agent Library"}),e.jsx("p",{className:"text-sm",style:{color:L.textSecondary},children:"Build, test, and export AI agents with full context engineering."})]}),e.jsxs(Re,{onClick:H,variant:"primary",size:"md",title:"Create new agent",className:"flex items-center gap-2",children:[e.jsx(re,{size:16}),"New Agent"]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(le,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none",style:{color:L.textDim}}),e.jsx("input",{type:"text",placeholder:"Search agents…",value:c,onChange:j=>h(j.target.value),className:"w-full pl-8 pr-3 py-1.5 rounded-lg outline-none",style:{background:L.inputBg,border:`1px solid ${L.border}`,color:L.textPrimary,fontFamily:"'Geist Sans', sans-serif",fontSize:13}})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx(zs,{size:12,style:{color:L.textDim}}),e.jsx("div",{style:{width:160},children:e.jsx(Yn,{options:Jn,value:E,onChange:S,size:"sm"})})]})]})]}),e.jsx("div",{className:"flex-1 overflow-auto p-6",children:D.length===0&&K.length===0?e.jsx(lt,{icon:e.jsx(le,{size:32}),title:"No results match your search",subtitle:`No results for "${k}" — try a different keyword`}):e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[D.map(j=>e.jsx(qn,{...j,onUse:G},j.id)),K.map(j=>e.jsx("div",{role:"button",tabIndex:0,title:`Open ${j.name}`,className:"cursor-pointer rounded-lg overflow-hidden transition-all duration-200 hover:shadow-lg",onClick:()=>t(j.id),onKeyDown:T=>{(T.key==="Enter"||T.key===" ")&&t(j.id)},style:{background:L.surfaceOpaque,border:`1px solid ${L.border}`,boxShadow:`0 2px 8px ${L.isDark?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.06)"}`},onMouseEnter:T=>{T.currentTarget.style.borderColor="#FE5000"},onMouseLeave:T=>{T.currentTarget.style.borderColor=L.border},children:e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"flex items-start gap-3 mb-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center shrink-0",style:{background:"#FE500015"},children:e.jsx(et,{size:16,style:{color:"#FE5000"}})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h3",{className:"text-base font-semibold mb-1 truncate",style:{color:L.textPrimary,fontFamily:"'Geist Sans', sans-serif"},children:j.name}),e.jsx("p",{className:"text-sm line-clamp-2",style:{color:L.textSecondary},children:j.description||"No description"})]})]}),j.tags&&j.tags.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 mb-3",children:[j.tags.slice(0,3).map(T=>e.jsx("span",{className:"text-[11px] px-1.5 py-0.5 rounded",style:{background:L.surfaceElevated,color:L.textDim,fontFamily:"'Geist Mono', monospace"},children:T},T)),j.tags.length>3&&e.jsxs("span",{className:"text-[11px] px-1.5 py-0.5 rounded",style:{background:L.surfaceElevated,color:L.textFaint},children:["+",j.tags.length-3]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs",style:{color:L.textDim},children:[e.jsx(Rs,{size:12}),e.jsx("span",{style:{fontFamily:"'Geist Mono', monospace"},children:x(j.updatedAt)})]}),e.jsxs("div",{className:"flex items-center gap-1",onClick:T=>T.stopPropagation(),children:[e.jsx("button",{type:"button",title:"Clone agent",disabled:C===j.id,onClick:T=>B(j,T),className:"flex items-center justify-center w-6 h-6 rounded cursor-pointer border-none bg-transparent transition-colors",style:{color:C===j.id?L.textFaint:L.textDim},onMouseEnter:T=>{T.currentTarget.style.color="#FE5000"},onMouseLeave:T=>{T.currentTarget.style.color=C===j.id?L.textFaint:L.textDim},children:C===j.id?e.jsx("span",{className:"animate-spin text-[10px]",children:"⟳"}):e.jsx(At,{size:13})}),e.jsx("button",{type:"button",title:"Delete agent",disabled:b===j.id,onClick:T=>{T.stopPropagation(),w(j)},className:"flex items-center justify-center w-6 h-6 rounded cursor-pointer border-none bg-transparent transition-colors",style:{color:b===j.id?L.textFaint:L.textDim},onMouseEnter:T=>{T.currentTarget.style.color="#ff4d4f"},onMouseLeave:T=>{T.currentTarget.style.color=b===j.id?L.textFaint:L.textDim},children:b===j.id?e.jsx("span",{className:"animate-spin text-[10px]",children:"⟳"}):e.jsx(Je,{size:13})})]})]})]})},j.id))]})}),e.jsx(Vn,{open:!!g,onClose:()=>w(null),title:"Delete Agent",width:400,footer:e.jsxs(e.Fragment,{children:[e.jsx(Re,{variant:"secondary",size:"sm",onClick:()=>w(null),children:"Cancel"}),e.jsx(Re,{variant:"danger",size:"sm",onClick:N,children:"Delete"})]}),children:e.jsxs("div",{className:"px-4 py-4 text-sm",style:{color:L.textSecondary},children:["Are you sure you want to delete"," ",e.jsxs("span",{className:"font-semibold",style:{color:L.textPrimary},children:['"',g?.name,'"']}),"? This action cannot be undone."]})}),e.jsx("div",{className:"fixed bottom-5 right-5 z-[300] flex flex-col gap-2 pointer-events-none",children:F.map(j=>e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2.5 rounded-lg text-sm font-medium pointer-events-auto",style:{background:L.surfaceOpaque,border:`1px solid ${j.type==="success"?"#22c55e40":"#ff4d4f40"}`,color:L.textPrimary,boxShadow:`0 4px 16px ${L.isDark?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)"}`,fontFamily:"'Geist Sans', sans-serif"},children:[j.type==="success"?e.jsx(Ge,{size:15,style:{color:"#22c55e",flexShrink:0}}):e.jsx(_e,{size:15,style:{color:"#ff4d4f",flexShrink:0}}),j.message]},j.id))})]})}const Xn={full:0,detail:1,summary:2,headlines:3,mention:4},eo={opus:"claude-opus-4",sonnet:"claude-sonnet-4",haiku:"claude-haiku-3.5","claude-opus-4":"claude-opus-4","claude-sonnet-4":"claude-sonnet-4","claude-haiku-3.5":"claude-haiku-3.5","gpt-4o":"gpt-4o","gpt-4.1":"gpt-4.1"},pt=new Set(["markdown","html-slides","email","code","csv","json","diagram","slack"]);function to(t){const s=t.trim();return s.startsWith("{")?so(s):s.startsWith("---")?no(s):oo(s)}function so(t){let s;try{s=JSON.parse(t)}catch{return{}}if(s.modular_version&&s.agent){const n=s.agent,a=se({...n,system:n.system_prompt,reads:n.knowledge?.map(r=>r.path),output_format:n.output_formats,token_budget:n.token_budget});return a.detectedFormat="generic",n.instructionState&&(a.instructionState=n.instructionState),n.workflowSteps&&(a.workflowSteps=n.workflowSteps),a}if(s.template&&s.context_files){const n=se({name:s.template,reads:s.context_files,tools:s.tools,output_format:s.output_format});return n.detectedFormat="vibe-kanban",n}if(s.instructions&&!s.system){const n=se({...s,system:s.instructions,reads:s.context_files||s.reads});return n.detectedFormat="codex",n}const o=se(s);return o.detectedFormat="generic",o}function no(t){const{frontmatter:s,body:o}=ro(t),n=se(s);if(n.detectedFormat="claude",!n.prompt){const l=o.match(/## Default Prompt\n([\s\S]*?)(?=\n## |$)/);l&&(n.prompt=l[1].trim())}if(!n.prompt){const l=o.match(/(?:##? Role)\n([\s\S]*?)(?=\n##? |$)/);l&&(n.prompt=l[1].trim())}if(!n.channels||n.channels.length===0){const l=io(o);l.length>0&&(n.channels=l)}const a=o.match(/## Persona\n([\s\S]*?)(?=\n## |$)/),r=o.match(/## Constraints\n([\s\S]*?)(?=\n## |$)/),i=o.match(/## Objectives\n([\s\S]*?)(?=\n## |$)/);return(a||r||i)&&(n.instructionState={persona:a?a[1].trim():"",tone:"neutral",expertise:3,constraints:{neverMakeUp:!1,askBeforeActions:!1,stayInScope:!1,useOnlyTools:!1,limitWords:!1,wordLimit:500,customConstraints:r?r[1].trim():"",scopeDefinition:""},objectives:{primary:i?i[1].trim():"",successCriteria:[],failureModes:[]},rawPrompt:"",autoSync:!0}),n}function oo(t){const s=Vt(t);if(s.agents&&typeof s.agents=="object"&&!Array.isArray(s.agents)){const n=s.agents,a=Object.keys(n)[0];if(a){const r=n[a],i=se({name:a.replace(/-/g," "),model:r.model,temperature:r.temperature,tools:r.skills,reads:r.context});return i.detectedFormat="openclaw",i}}if(s.mcp&&typeof s.mcp=="object"&&!Array.isArray(s.mcp)){const n=se({...s,system:s.instructions,reads:s.context_files});return n.detectedFormat="amp",n}const o=se(s);return o.detectedFormat="amp",o}function se(t){const s={},o={name:ee(t.name)||"",description:ee(t.description)||"",icon:ee(t.icon)||"brain",category:ee(t.category)||"general",tags:Array.isArray(t.tags)?t.tags:[],avatar:ee(t.avatar)||""};if(s.agentMeta=o,t.model){const r=ee(t.model);s.selectedModel=eo[r]??r}t.token_budget!==void 0&&(s.tokenBudget=Number(t.token_budget));const n=t.modular;if(n?.tokenBudget!==void 0&&(s.tokenBudget=Number(n.tokenBudget)),Array.isArray(t.output_format)){const r=t.output_format.filter(i=>pt.has(i));r.length>0&&(s.outputFormat=r[0])}else if(t.output_format){const r=ee(t.output_format);pt.has(r)&&(s.outputFormat=r)}!s.outputFormat&&n?.outputFormat&&(s.outputFormat=n.outputFormat),Array.isArray(t.reads)&&(s.channels=t.reads.map((r,i)=>{const l=void 0;return{sourceId:l?.id??`imported-${i}`,name:l?.name??r.split("/").filter(Boolean).pop()??r,path:r,category:l?.category??"knowledge",knowledgeType:l?ve(l.path):ve(r),enabled:!0,depth:0,baseTokens:l?.tokenEstimate??5e3}})),!s.channels&&n?.channels&&(s.channels=n.channels.map((r,i)=>{const l=ao(r.type)?r.type:ve(r.path),c=Xn[r.depth?.toLowerCase()]??0,h=(r.path,void 0);return{sourceId:h?.id??`imported-${i}`,name:h?.name??r.path.split("/").filter(Boolean).pop()??r.path,path:r.path,category:h?.category??"knowledge",knowledgeType:l,enabled:!0,depth:c,baseTokens:h?.tokenEstimate??5e3}})),!s.prompt&&t.system&&(s.prompt=ee(t.system)),t.prompt&&(s.prompt=ee(t.prompt));const a=ee(t.system);if(a){const r=lo(a);s.instructionState={persona:r.persona,tone:"neutral",expertise:3,constraints:{neverMakeUp:!1,askBeforeActions:!1,stayInScope:!1,useOnlyTools:!1,limitWords:!1,wordLimit:500,customConstraints:r.constraints,scopeDefinition:""},objectives:{primary:r.objective,successCriteria:[],failureModes:[]},rawPrompt:"",autoSync:!0}}return s}function ee(t){return typeof t=="string"?t:t==null?"":String(t)}function ro(t){const s=t.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);return s?{frontmatter:Vt(s[1]),body:s[2]}:{frontmatter:{},body:t}}function Vt(t){const s={},o=t.split(`
|
|
38
|
+
`);let n="",a=null,r=null,i=null,l="",c=0,h=[];const k=()=>{if(l&&h.length>0){const f=a||s;f[l]=h.join(`
|
|
39
|
+
`),l="",h=[]}};for(const f of o){if(l)if(f.search(/\S/)>=c&&f.trim()!==""){h.push(f.slice(c));continue}else k();const E=f.match(/^(\w[\w_-]*)\s*:\s*(.*)$/);if(E){i&&r&&(r.push(i),i=null),r=null,a=null;const S=E[1],g=E[2].trim();g===""||g==="|"?g==="|"?(l=S,c=2,h=[]):(n=S,a={},s[S]=a):g.startsWith("[")&&g.endsWith("]")?s[S]=g.slice(1,-1).split(",").map(w=>w.trim()).filter(Boolean):s[S]=oe(g);continue}if(a){const S=f.match(/^ (\w[\w_-]*)\s*:\s*(.*)$/);if(S){i&&r&&(r.push(i),i=null);const g=S[1],w=S[2].trim();w===""||w==="|"?w==="|"?(l=g,c=4,h=[]):(r=[],a[g]=r):(r=null,a[g]=oe(w));continue}if(r){const g=f.match(/^ - (.+)$/);if(g&&!g[1].includes(":")){i&&(r.push(i),i=null),r.push(oe(g[1].trim()));continue}}if(r){const g=f.match(/^ - (\w[\w_-]*)\s*:\s*(.*)$/);if(g){i&&r.push(i),i={[g[1]]:oe(g[2])};continue}const w=f.match(/^ (\w[\w_-]*)\s*:\s*(.*)$/);if(w&&i){i[w[1]]=oe(w[2]);continue}}}if(!a){const S=f.match(/^ - (.+)$/);if(S&&r){if(!S[1].includes(":"))r.push(oe(S[1].trim()));else{const w=S[1].match(/^(\w[\w_-]*)\s*:\s*(.*)$/);w&&(i&&r.push(i),i={[w[1]]:oe(w[2])})}continue}const g=f.match(/^(\w[\w_-]*)\s*:$/);if(g){n=g[1],r=[],s[n]=r;continue}}}return k(),i&&r&&r.push(i),s}function oe(t){return t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1):t}function ao(t){return["ground-truth","signal","evidence","framework","hypothesis","guideline"].includes(t)}function io(t){const s=[],o=t.split(`
|
|
40
|
+
`);let n=0;for(const a of o){const r=a.match(/[-*]\s+(?:\*\*.*?\*\*:?\s*)?([A-Za-z0-9_/-]+(?:\/\*)?)/);if(r){const i=r[1];i.includes("/")&&(s.push({sourceId:`body-${n}`,name:i.split("/").filter(Boolean).pop()??i,path:i,category:"knowledge",knowledgeType:ve(i),enabled:!0,depth:0,baseTokens:5e3}),n++)}}return s}function lo(t){const s=t.replace(/\r\n/g,`
|
|
41
|
+
`).trim();if(!s)return{persona:"",constraints:"",objective:""};const o=s.split(/\n\s*\n/).map(p=>p.trim()).filter(Boolean),a=s.split(`
|
|
42
|
+
`).map(p=>p.trim()).filter(Boolean).map(p=>{const C=p.match(/^[-*]\s+(.+)$/);if(C)return C[1].trim();const m=p.match(/^\d+\.\s+(.+)$/);return m?m[1].trim():""}).filter(Boolean),r=/\b(never|always|must|must not|do not|don't|forbidden|required|only|avoid|without)\b/i,i=/\b(objective|goal|task|deliver|ensure|help|outcome|success|mission)\b/i,l=a.filter(p=>r.test(p)),c=a.filter(p=>!r.test(p)&&i.test(p)),h=s.match(/(?:^|\n)(?:#+\s*)?(?:objective|objectives|goal|goals|mission)\s*:?\s*\n?([\s\S]*?)(?=\n(?:#+\s*)?[A-Za-z][^\n]*:\s*|\n\s*\n|$)/i),k=s.match(/(?:^|\n)(?:#+\s*)?(?:constraint|constraints|guardrails|rules)\s*:?\s*\n?([\s\S]*?)(?=\n(?:#+\s*)?[A-Za-z][^\n]*:\s*|\n\s*\n|$)/i),f=h?.[1]?.split(`
|
|
43
|
+
`).map(p=>p.replace(/^[-*]\s+/,"").trim()).find(Boolean)??"",E=k?.[1]?.split(`
|
|
44
|
+
`).map(p=>p.replace(/^[-*]\s+/,"").trim()).filter(Boolean).join(`
|
|
45
|
+
`)??"",g=(o.find(p=>{const C=p.toLowerCase();return!(/^(constraints?|guardrails?|rules|objectives?|goals?|mission)\s*:/.test(C)||i.test(p)||r.test(p))})??o[0]??"").split(new RegExp("(?<=[.!?])\\s+")).map(p=>p.trim()).find(Boolean)??"",w=f||c[0]||o.find(p=>i.test(p))||"",b=E||l.join(`
|
|
46
|
+
`);return{persona:g,constraints:b,objective:typeof w=="string"?w.trim():""}}const co=u.forwardRef(function({label:s,labelAction:o,error:n,showCount:a,maxChars:r,value:i,className:l="",style:c,...h},k){const f=W(),E=typeof i=="string"?i.length:0;return e.jsxs("div",{className:"flex flex-col gap-1",children:[(s||a||o)&&e.jsxs("div",{className:"flex items-center justify-between",children:[s&&e.jsx("label",{className:"text-[13px] tracking-wider uppercase font-semibold",style:{color:f.textMuted,fontFamily:"'Geist Mono', monospace"},children:s}),e.jsxs("div",{className:"flex items-center gap-2",children:[a&&e.jsxs("span",{className:"text-[13px]",style:{color:r&&E>r?f.statusError:f.textFaint},children:[E,r?` / ${r}`:""]}),o]})]}),e.jsx("textarea",{ref:k,value:i,className:`w-full px-3 py-2.5 rounded-md outline-none resize-none nowheel nodrag ${l}`,style:{background:f.inputBg,border:`1px solid ${n?f.statusError:f.border}`,color:f.textPrimary,fontFamily:"'Geist Sans', sans-serif",fontSize:16,lineHeight:1.5,minHeight:64,...c},...h}),n&&e.jsx("span",{className:"text-[13px]",style:{color:f.statusError},children:n})]})});function uo(t,s,o){return`You are an expert AI agent architect. Given a user's rough description of an agent they want to build, produce a COMPLETE agent configuration as JSON.
|
|
47
|
+
|
|
48
|
+
You have access to these MCP servers (pick ONLY from this list):
|
|
49
|
+
<mcp_servers>
|
|
50
|
+
${t}
|
|
51
|
+
</mcp_servers>
|
|
52
|
+
|
|
53
|
+
You have access to these skills (pick ONLY from this list):
|
|
54
|
+
<skills>
|
|
55
|
+
${s}
|
|
56
|
+
</skills>
|
|
57
|
+
|
|
58
|
+
The user has these REAL knowledge sources already connected (indexed repos, documents, files):
|
|
59
|
+
<connected_knowledge>
|
|
60
|
+
${o}
|
|
61
|
+
</connected_knowledge>
|
|
62
|
+
|
|
63
|
+
Produce a JSON response with this EXACT structure:
|
|
64
|
+
{
|
|
65
|
+
"agentMeta": {
|
|
66
|
+
"name": "<short agent name>",
|
|
67
|
+
"description": "<one-line description>",
|
|
68
|
+
"avatar": "<icon id: bot|brain|zap|flame|lightbulb|target|rocket|shield|microscope|chart|palette|file|drama|star|gem|bird|bug|cat|dog|heart>",
|
|
69
|
+
"tags": ["<tag1>", "<tag2>"]
|
|
70
|
+
},
|
|
71
|
+
"instructionState": {
|
|
72
|
+
"persona": "<2-4 sentence persona using 'You are...' framing>",
|
|
73
|
+
"tone": "<formal|neutral|casual>",
|
|
74
|
+
"expertise": <1-5>,
|
|
75
|
+
"constraints": {
|
|
76
|
+
"neverMakeUp": <true|false>,
|
|
77
|
+
"askBeforeActions": <true|false>,
|
|
78
|
+
"stayInScope": <true|false>,
|
|
79
|
+
"useOnlyTools": <true|false>,
|
|
80
|
+
"limitWords": <true|false>,
|
|
81
|
+
"wordLimit": <number or 0>,
|
|
82
|
+
"customConstraints": ["<constraint>"],
|
|
83
|
+
"scopeDefinition": "<what agent handles and does NOT handle>"
|
|
84
|
+
},
|
|
85
|
+
"objectives": {
|
|
86
|
+
"primary": "<primary goal>",
|
|
87
|
+
"successCriteria": ["<criterion>"],
|
|
88
|
+
"failureModes": ["<failure to avoid>"]
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"workflowSteps": [
|
|
92
|
+
{
|
|
93
|
+
"label": "<step name>",
|
|
94
|
+
"action": "<what the agent does>",
|
|
95
|
+
"condition": false,
|
|
96
|
+
"loop": false
|
|
97
|
+
}
|
|
98
|
+
],
|
|
99
|
+
"mcpServerIds": ["<mcp-id from the list above>"],
|
|
100
|
+
"skillIds": ["<skill-id from the list above>"],
|
|
101
|
+
"knowledgeSelections": [
|
|
102
|
+
{
|
|
103
|
+
"sourceId": "<exact sourceId from connected_knowledge>",
|
|
104
|
+
"type": "<ground-truth|signal|evidence|framework|hypothesis|guideline>",
|
|
105
|
+
"depth": <0-4>,
|
|
106
|
+
"reason": "<why this source is relevant>"
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
"knowledgeGaps": [
|
|
110
|
+
{
|
|
111
|
+
"name": "<what's missing>",
|
|
112
|
+
"type": "<ground-truth|signal|evidence|framework|hypothesis|guideline>",
|
|
113
|
+
"description": "<what the user should connect and why>"
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
"memoryConfig": {
|
|
117
|
+
"maxMessages": <10-50>,
|
|
118
|
+
"summarizeAfter": <5-25>,
|
|
119
|
+
"summarizeEnabled": <true|false>,
|
|
120
|
+
"suggestedFacts": ["<pre-loaded fact for long-term memory>"]
|
|
121
|
+
},
|
|
122
|
+
"outputSuggestions": ["<notion|slack|html-slides|email|github|hubspot>"]
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
Rules:
|
|
126
|
+
1. Pick MCP servers and skills ONLY from the provided lists — use exact IDs
|
|
127
|
+
2. Suggest 2-6 MCP servers and 1-4 skills that are genuinely useful for this agent
|
|
128
|
+
3. Generate 3-8 workflow steps that form a coherent process
|
|
129
|
+
4. **Knowledge: select from REAL connected sources using their exact sourceId**
|
|
130
|
+
- Set the appropriate knowledge type (ground-truth for specs, signal for feedback, etc.)
|
|
131
|
+
- Set depth: 0=Full, 1=Detail(75%), 2=Summary(50%), 3=Headlines(25%), 4=Mention(10%)
|
|
132
|
+
- If no connected sources exist or none are relevant, leave knowledgeSelections empty
|
|
133
|
+
5. **Knowledge gaps: suggest what REAL documents/repos the user should connect**
|
|
134
|
+
- Be specific: "Odfjell fleet spec PDF" not "Company documentation"
|
|
135
|
+
- Only suggest gaps that would genuinely improve the agent
|
|
136
|
+
6. Be opinionated — make real choices, don't hedge
|
|
137
|
+
7. Memory config: enable summarization for conversational agents, disable for one-shot tools
|
|
138
|
+
|
|
139
|
+
Output ONLY the JSON object. No markdown fences, no explanation.`}async function po(t,s,o,n){if(!t.trim())throw new Error("Describe the agent you want to build");const a=Q.getState(),r=a.providers.filter(M=>(M.status==="connected"||M.status==="configured")&&Array.isArray(M.models)&&M.models.length>0),i=a.providers.find(M=>M.id===a.selectedProviderId&&r.includes(M))||r[0];if(!i)throw new Error("No provider with models available. Connect a provider and refresh models in Settings.");const l=i.models[0],c=typeof l=="string"?l:l?.id||"";if(!c)throw new Error(`Provider ${i.name} has no selectable model.`);const h=i.authMethod==="claude-agent-sdk",k=s?.filter(M=>M.added).map(M=>M.id)||[],f=o?.filter(M=>M.added).map(M=>M.id)||[],E=k.length>0?fe.filter(M=>k.includes(M.id)):[],S=f.length>0?ss.filter(M=>f.includes(M.id)):[],g=E.length>0?E.map(M=>`${M.id}: ${M.description}`).join(`
|
|
140
|
+
`):"none",w=S.length>0?S.map(M=>`${M.id}: ${M.description}`).join(`
|
|
141
|
+
`):"none",b=n||[],p=b.length>0?b.map(M=>`- sourceId: "${M.sourceId}" | name: "${M.name}" | path: "${M.path||"(no path)"}" | type: ${M.knowledgeType||"unclassified"} | tokens: ${M.baseTokens} | depth: ${M.depth}`).join(`
|
|
142
|
+
`):"No knowledge sources connected yet. Suggest what the user should add in knowledgeGaps.",C=uo(g,w,p),m=h?await ns({prompt:t,model:c,systemPrompt:C,maxTurns:1}):await os({providerId:i.id,model:c,messages:[{role:"system",content:C},{role:"user",content:t}],temperature:.4,maxTokens:4096});let F;try{F=JSON.parse(m)}catch{}if(!F){const M=m.match(/```(?:json)?\s*([\s\S]*?)```/);if(M)try{F=JSON.parse(M[1].trim())}catch{}}if(!F){const M=m.match(/\{[\s\S]*\}/);if(M)try{F=JSON.parse(M[0])}catch{}}if(!F)throw new Error("Could not parse generated agent config");return mo(F,b),F}function mo(t,s){if(s.length===0)return;function o(i){const l=t.instructionState.constraints.customConstraints;Array.isArray(l)?l.push(i):typeof l=="string"?t.instructionState.constraints.customConstraints=l?`${l}
|
|
143
|
+
${i}`:i:t.instructionState.constraints.customConstraints=[i]}const n=s.filter(i=>i.repoMeta);if(n.length>0){const i=n.map(c=>{const h=c.repoMeta,k=h.stack.length>0?h.stack.join(", "):"unknown stack";return`${h.name} (${k})`});t.instructionState.persona+=` You have deep access to ${i.join(" and ")}.`,o("Explore connected codebases autonomously — read files, check structure, trace dependencies before asking the user for information.");const l=n.flatMap(c=>c.repoMeta.features).filter(Boolean);if(l.length>0){const c=[...new Set(l)];t.instructionState.persona+=` Key capabilities include: ${c.join(", ")}.`}}const a=new Map;for(const i of s){if(!i.knowledgeType)continue;const l=a.get(i.knowledgeType)??[];l.push(i.name),a.set(i.knowledgeType,l)}const r={"ground-truth":i=>`Do not contradict information from: ${i}`,signal:i=>`When interpreting ${i}, look for underlying user needs, not surface requests`,guideline:i=>`Follow the conventions and rules defined in: ${i}`};for(const[i,l]of a){const c=r[i];c&&o(c(l.join(", ")))}}const fo={"knowledge-clients-odfjell":["odfjell","bow optima","bow olympus","bow orion","michelle","chemical tanker"],"knowledge-clients-kcc":["kcc","klaveness","baru","balzani","baleen","combination carrier"],"knowledge-competitors-stormgeo":["stormgeo","storm geo","competitor"],"knowledge-competitors-dtn":["dtn","competitor"],"knowledge-competitors-sofar":["sofar","competitor"],"knowledge-competitors-wni":["wni","weathernews","competitor"],"knowledge-competitors-napa":["napa","competitor"],"knowledge-products":["product","feature","navigation report","live","fleet"],"knowledge-products-nr":["navigation report","nr","post-voyage","voyage report"],"knowledge-products-feedback":["feedback","user feedback","nps"],"discovery-eu-ets":["eu ets","carbon","emission","ets","co2","regulation","fueleu"],"discovery-weather-routing":["weather routing","route optimization","weather"],"discovery-fleet-dashboard":["fleet","dashboard","fleet view"],"discovery-cii-monitor":["cii","carbon intensity","rating"],"intel-competitive":["competitive","competitor","benchmark","versus","vs"],"intel-maritime":["maritime","shipping","vessel","marine"],"odfjell-savings":["savings","fuel savings","optimization","odfjell"],"voyage-prep":["voyage prep","voyage preparation","tce","charter"],"signals-odfjell":["odfjell feedback","odfjell signal","michelle said"],roadmap:["roadmap","prioritize","quarter","q1","q2","q3","q4","planning"],"sales-prep-events":["event","conference","meeting prep","pitch"],"cmo-company-profiles":["company profile","company intel","research company"]};function xo(t,s,o=3){if(!t||t.length<5)return[];const n=t.toLowerCase(),a=new Set(s.map(c=>c.sourceId)),r=[],i=[];for(const[c,h]of Object.entries(fo))if(!a.has(c)){for(const k of h)if(n.includes(k)){const f=r.find(E=>E.id===c);if(f){i.push({source:f,reason:`Prompt mentions "${k}"`});break}}}if(s.length>0){const c=s.some(f=>f.knowledgeType==="ground-truth"&&f.enabled),h=s.some(f=>f.knowledgeType==="signal"&&f.enabled),k=s.some(f=>f.knowledgeType==="evidence"&&f.enabled);if(!c&&!a.has("knowledge-products")){const f=r.find(E=>E.id==="knowledge-products");f&&i.push({source:f,reason:"No Ground Truth — add Products?"})}if(h&&!k&&!a.has("intel-competitive")){const f=r.find(E=>E.id==="intel-competitive");f&&i.push({source:f,reason:"Signals without Evidence"})}}const l=new Set;return i.filter(c=>l.has(c.source.id)?!1:(l.add(c.source.id),!0)).slice(0,o)}const mt=1e4,ft=20,go=50,ho=3;function Ke({onValidationChange:t,onNavigateToNext:s,onNavigateToKnowledge:o}){const n=W(),a=$(d=>d.prompt),r=$(d=>d.setPrompt),i=$(d=>d.hydrateFromGenerated),l=$(d=>d.setKnowledgeGaps),c=$(d=>d.channels),h=$(d=>d.mcpServers),k=$(d=>d.skills),E=Q(d=>d.providers).some(d=>(d.status==="connected"||d.status==="configured")&&(d._hasStoredKey||d._hasStoredAccessToken||!!d.apiKey?.trim()||d.authMethod==="claude-agent-sdk")),[S,g]=u.useState(null),[w,b]=u.useState(!1),[p,C]=u.useState(!1),[m,F]=u.useState(null),[M,R]=u.useState(null),L=u.useRef(void 0),z=u.useRef(void 0),G=u.useRef(new Set),[D,y]=u.useState([]),H={color:n.textPrimary,fontFamily:"'Geist Sans', sans-serif"},N={color:n.textSecondary,lineHeight:1.5},B={minHeight:"200px",fontFamily:"'Geist Sans', sans-serif",fontSize:"14px",lineHeight:1.6},K={background:n.surface,border:`1px solid ${n.border}`},x={color:"#FE5000",marginTop:2,flexShrink:0},j=a.length>=ft;u.useEffect(()=>{const d=!j&&w?`Please enter at least ${ft} characters`:null;g(d),t?.(j)},[j,w,t]);const T=u.useCallback(()=>{L.current&&clearTimeout(L.current),L.current=setTimeout(()=>{},500)},[]);u.useEffect(()=>{if(z.current&&clearTimeout(z.current),c.length>=ho||a.length<go){y([]);return}return z.current=setTimeout(()=>{const _=xo(a,c);y(_.filter(U=>!G.current.has(U.source.id)))},500),()=>{z.current&&clearTimeout(z.current)}},[a,c]);const P=d=>{G.current.add(d),y(_=>_.filter(U=>U.source.id!==d))},A=d=>{P(d),o?.()},I=d=>{r(d),T()},v=()=>{b(!0)},O=async()=>{if(!a.trim()){g("Please enter a description before generating"),b(!0);return}C(!0),F(null),R(null);try{const d=await po(a,h,k,c);l(d.knowledgeGaps||[]),i(d),R(d),setTimeout(()=>{s?.()},2e3)}catch(d){F(d instanceof Error?d.message:"Generation failed")}finally{C(!1)}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-semibold mb-2 m-0",style:H,children:"Describe Your Agent"}),e.jsx("p",{className:"text-sm",style:N,children:"Start by describing what you want your agent to do. Be specific about its role, capabilities, and the types of tasks it should handle."})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"agent-description",className:"block text-sm font-medium mb-3",style:{color:n.textPrimary},children:"Agent Description"}),e.jsx(co,{id:"agent-description",value:a,onChange:d=>I(d.target.value),onBlur:v,placeholder:"Describe your agent in detail... For example: 'A customer support agent that helps users with technical issues. It should have access to documentation, be able to create support tickets, and escalate complex issues to human agents. The agent should be friendly but professional, and always verify user identity before sharing sensitive information.'",rows:8,style:B,maxLength:mt}),e.jsxs("div",{className:"flex justify-between items-center mt-2",children:[e.jsx("div",{children:S&&e.jsx("div",{className:"text-sm text-red-500",children:S})}),e.jsxs("div",{className:"text-sm text-right",style:{color:n.textSecondary},"aria-live":"polite",children:[a.length," / ",mt]})]}),D.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("p",{className:"text-xs mb-2",style:{color:n.textSecondary,fontFamily:"'Inter', 'Geist Sans', sans-serif"},children:"Suggested knowledge sources:"}),e.jsx("div",{className:"flex flex-wrap gap-2",role:"list","aria-label":"Knowledge source suggestions",children:D.map(d=>e.jsxs("div",{role:"listitem",className:"flex items-center gap-1 px-3 py-1 rounded-full text-xs border",style:{background:"#FE500010",borderColor:"#FE500040",color:n.textPrimary},children:[e.jsx("button",{type:"button",onClick:()=>A(d.source.id),className:"font-medium hover:underline",style:{color:"#FE5000",fontFamily:"'Inter', 'Geist Sans', sans-serif",background:"none",border:"none",cursor:"pointer",padding:0},title:`Add ${d.source.name} to knowledge sources`,children:d.source.name}),e.jsxs("span",{style:{color:n.textSecondary},children:["· ",d.reason]}),e.jsx("button",{type:"button",onClick:()=>P(d.source.id),"aria-label":`Dismiss ${d.source.name} suggestion`,className:"ml-1 opacity-60 hover:opacity-100",style:{background:"none",border:"none",cursor:"pointer",padding:0,color:n.textSecondary,display:"flex",alignItems:"center"},children:e.jsx(ae,{size:10})})]},d.source.id))})]}),e.jsx("div",{className:"mt-6 mb-4 text-center",children:e.jsx("p",{className:"text-sm px-4",style:{color:n.textSecondary,lineHeight:1.5},children:"Generate will use AI to create a complete agent configuration from your description — including persona, constraints, objectives, workflow, and tool selection."})}),!E&&e.jsxs("div",{className:"mt-4 flex items-center gap-3 p-4 rounded-lg",style:{background:"#FE500015",border:"1px solid #FE500030"},children:[e.jsx(We,{size:18,style:{color:"#FE5000"}}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium",style:{color:n.textPrimary},children:"Set up an AI provider first"}),e.jsx("div",{className:"text-xs mt-1",style:{color:n.textDim},children:"Configure an API key (OpenAI, Anthropic, etc.) in Settings to generate agents."})]})]}),e.jsx("div",{className:"mt-4 flex justify-center",children:e.jsx("button",{type:"button",onClick:O,disabled:p||!a.trim()||!E,title:E?p?"Generating configuration":a.trim()?"Generate full agent config":"Enter description first":"Set up a provider in Settings first",className:"flex items-center gap-3 px-8 py-4 rounded-lg transition-colors font-semibold text-base",style:{background:p||!a.trim()||!E?"#CC4000":"#FE5000",color:"#FFFFFF",border:"none",fontFamily:"'Geist Sans', sans-serif",opacity:p||!a.trim()||!E?.6:1,cursor:p||!a.trim()||!E?"default":"pointer"},onMouseEnter:d=>{!p&&a.trim()&&(d.currentTarget.style.background="#E54800")},onMouseLeave:d=>{!p&&a.trim()&&(d.currentTarget.style.background="#FE5000")},children:p?e.jsxs(e.Fragment,{children:[e.jsx(X,{size:20,className:"animate-spin motion-reduce:animate-none"}),"Generating Agent..."]}):M?e.jsxs(e.Fragment,{children:[e.jsx(Z,{size:20}),"Agent Generated!"]}):e.jsxs(e.Fragment,{children:[e.jsx($e,{size:20}),"Generate Agent"]})})}),m&&e.jsx("div",{className:"mt-3 p-3 rounded",style:{background:"#fee2e2",border:"1px solid #fecaca"},children:e.jsx("div",{className:"text-sm text-red-700",children:m})}),M&&e.jsx("div",{className:"mt-3 p-4 rounded",style:{background:"#f0fdf4",border:"1px solid #bbf7d0"},children:e.jsxs("div",{className:"text-sm text-green-800",children:[e.jsxs("div",{className:"font-semibold mb-2",children:['✅ Agent "',M.agentMeta.name,'" generated successfully!']}),e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsxs("div",{children:["• ",M.workflowSteps?.length||0," workflow steps configured"]}),e.jsxs("div",{children:["• ",M.skillIds?.length||0," skills selected"]}),e.jsxs("div",{children:["• ",M.mcpServerIds?.length||0," MCP tools configured"]}),M.knowledgeGaps&&M.knowledgeGaps.length>0&&e.jsxs("div",{children:["• ",M.knowledgeGaps.length," knowledge gap",M.knowledgeGaps.length!==1?"s":""," identified"]})]}),e.jsx("div",{className:"mt-2 text-xs text-green-600",children:"Advancing to next tab..."})]})})]}),e.jsx("div",{className:"rounded-lg p-5 bg-surface border border-border",style:K,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Ft,{size:16,style:x}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-sm mb-2 m-0",style:{color:n.textPrimary},children:"Writing Tips"}),e.jsxs("ul",{className:"text-sm space-y-1",style:{color:n.textSecondary},children:[e.jsx("li",{children:"• Be specific about the agent's role and responsibilities"}),e.jsx("li",{children:"• Mention the types of inputs and outputs you expect"}),e.jsx("li",{children:"• Include any domain expertise or specialized knowledge required"}),e.jsx("li",{children:"• Describe the tone and communication style you want"}),e.jsx("li",{children:"• Note any constraints or limitations the agent should respect"})]})]})]})})]})}const xt=56,yo=24,bo=88,ko={position:"fixed",bottom:bo,right:yo,width:xt,height:xt,borderRadius:"50%",background:"#FE5000",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:50,transition:"all 0.2s ease",boxShadow:"0 4px 12px rgba(254, 80, 0, 0.3), 0 2px 4px rgba(0, 0, 0, 0.1)"};function jo({onClick:t,isVisible:s}){const o=W();return s?e.jsx("button",{type:"button","aria-label":"Switch to Test tab and start testing",onClick:t,style:ko,onMouseEnter:n=>{n.currentTarget.style.transform="scale(1.05)",n.currentTarget.style.boxShadow="0 6px 16px rgba(254, 80, 0, 0.4), 0 2px 4px rgba(0, 0, 0, 0.1)"},onMouseLeave:n=>{n.currentTarget.style.transform="scale(1)",n.currentTarget.style.boxShadow="0 4px 12px rgba(254, 80, 0, 0.3), 0 2px 4px rgba(0, 0, 0, 0.1)"},onFocus:n=>{n.currentTarget.style.outline=`2px solid ${o.isDark?"#FF6B1A":"#FE5000"}`,n.currentTarget.style.outlineOffset="2px"},onBlur:n=>{n.currentTarget.style.outline="none"},children:e.jsx(Ue,{size:24,fill:"#fff",color:"#fff","aria-hidden":"true"})}):null}const vo=u.lazy(()=>ce(()=>import("./TestTab-iJ2vCf9l.js"),__vite__mapDeps([0,1,2,3,4,5,6])).then(t=>({default:t.TestTab}))),wo=u.lazy(()=>ce(()=>import("./QualificationTab-BqnWSQHm.js"),__vite__mapDeps([7,1,4,3,8,9,5])).then(t=>({default:t.QualificationTab}))),So=u.lazy(()=>ce(()=>import("./KnowledgeTab-CxlC76Rf.js"),__vite__mapDeps([10,1,4,3,5])).then(t=>({default:t.KnowledgeTab}))),Co=u.lazy(()=>ce(()=>import("./ToolsTab-C10Ulm8b.js"),__vite__mapDeps([11,1,4,3,5])).then(t=>({default:t.ToolsTab}))),No=u.lazy(()=>ce(()=>import("./MemoryTab-CUScYWs9.js"),__vite__mapDeps([12,1,4,3,8,13,5])).then(t=>({default:t.MemoryTab}))),Eo=u.lazy(()=>ce(()=>import("./ReviewTab-DKYl6cR9.js"),__vite__mapDeps([14,1,4,3,2,8,9,5,13])).then(t=>({default:t.ReviewTab}))),V=[{id:"describe",label:"Describe",icon:Te,component:Ke},{id:"knowledge",label:"Knowledge",icon:Ve,component:So},{id:"tools",label:"Tools",icon:vt,component:Co},{id:"memory",label:"Memory",icon:He,component:No},{id:"review",label:"Review",icon:Bs,component:Eo},{id:"test",label:"Test",icon:Ue,component:vo},{id:"qualification",label:"Qualification",icon:Os,component:wo}],Mo=1024;function To(){const t=W();return e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ht,{size:"md"}),e.jsx("span",{style:{color:t.textSecondary},children:"Loading..."})]})})}function Fo(){const t=W(),s=$(N=>N.prompt.length),o=$(N=>N.channels.length),n=$(N=>N.mcpServers.length),a=$(N=>N.skills.length),r=$(N=>N.agentMeta.name),i=he(N=>N.session.strategy),l=he(N=>N.facts.length),c=he(N=>N.longTerm.enabled),h=he(N=>N.working.content),[k,f]=u.useState("describe"),[E,S]=u.useState(!1),[g,w]=u.useState(!1),b=u.useRef([]),p=u.useRef(null),C=u.useRef(null),m=V.find(N=>N.id===k)?.component||Ke,F=V.findIndex(N=>N.id===k),M=()=>{const N=C.current;if(!N)return;const{scrollLeft:B,scrollWidth:K,clientWidth:x}=N;S(B>0),w(B<K-x-1)};u.useEffect(()=>{const N=()=>{if(window.innerWidth>=Mo){S(!1),w(!1);return}M()};return N(),window.addEventListener("resize",N),()=>window.removeEventListener("resize",N)},[]),u.useEffect(()=>{if(p.current){const N=p.current.querySelector("[data-skip-target]"),B=p.current.querySelector("h2, h3, h4"),K=N||B||p.current;K&&K.focus()}},[k]),u.useEffect(()=>{const N=localStorage.getItem("mcp-oauth-completed"),B=localStorage.getItem("mcp-oauth-return-tab");N==="true"&&B&&V.some(K=>K.id===B)&&(f(B),localStorage.removeItem("mcp-oauth-completed"),localStorage.removeItem("mcp-oauth-return-tab"))},[]);const R=()=>{F<V.length-1&&f(V[F+1].id)},L=()=>{F>0&&f(V[F-1].id)},z=()=>{f("test"),setTimeout(()=>{const N=["[data-test-chat-input]",'textarea[placeholder*="message"]','input[placeholder*="message"]','textarea[placeholder*="chat"]','input[placeholder*="chat"]',"textarea",'input[type="text"]'];for(const B of N){const K=document.querySelector(B);if(K){K.focus();break}}},100)},G=(N,B)=>{switch(N.key){case"ArrowLeft":N.preventDefault();const K=B===0?V.length-1:B-1;b.current[K]?.focus(),f(V[K].id);break;case"ArrowRight":N.preventDefault();const x=B===V.length-1?0:B+1;b.current[x]?.focus(),f(V[x].id);break;case"Home":N.preventDefault(),b.current[0]?.focus(),f(V[0].id);break;case"End":N.preventDefault();const j=V.length-1;b.current[j]?.focus(),f(V[j].id);break}},D=(N,B)=>B&&N==="#FE5000"?"#FF6B1A":N,y=N=>{switch(N){case"describe":return s>20;case"knowledge":return o>0;case"tools":return n>0||a>0;case"memory":return i!=="summarize_and_recent"||l>0||!c||h.length>0;case"review":return r!==""&&r.length>0;default:return!1}},H={left:{background:`linear-gradient(to right, ${t.surface} 0%, transparent 100%)`},right:{background:`linear-gradient(to left, ${t.surface} 0%, transparent 100%)`}};return e.jsxs("div",{role:"main",className:"flex-1 flex flex-col overflow-hidden min-h-0",style:{background:t.bg},children:[e.jsx("a",{href:"#main-content",className:"sr-only focus:not-sr-only focus:absolute focus:top-4 focus:left-4 focus:z-50 focus:px-3 focus:py-2 focus:rounded",style:{background:t.surface,color:t.textPrimary,textDecoration:"none",outline:`2px solid ${D("#FE5000",t.isDark)}`},children:"Skip to main content"}),e.jsxs("nav",{"aria-label":"Agent wizard steps",className:"relative flex border-b shrink-0",style:{background:t.surface,borderColor:t.border},children:[E&&e.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-8 pointer-events-none z-10",style:H.left,"aria-hidden":"true"}),g&&e.jsx("div",{className:"absolute right-0 top-0 bottom-0 w-8 pointer-events-none z-10",style:H.right,"aria-hidden":"true"}),e.jsx("div",{ref:C,role:"tablist",className:"flex w-full overflow-x-auto lg:overflow-x-visible tab-scrollbar-hidden",onScroll:M,children:V.map((N,B)=>{const K=N.icon,x=N.id===k,j=B<F,T=y(N.id),P=D("#FE5000",t.isDark),A=I=>{switch(I){case"describe":return"Define your agent";case"knowledge":return"Add data sources";case"tools":return"Select capabilities";case"memory":return"Configure memory";case"review":return"Review and edit";case"test":return"Test and debug";case"qualification":return"Export and deploy";default:return N.label}};return e.jsxs("button",{ref:I=>{b.current[B]=I},type:"button",role:"tab","aria-selected":x,"aria-controls":`tabpanel-${N.id}`,tabIndex:x?0:-1,onClick:()=>f(N.id),onKeyDown:I=>G(I,B),title:A(N.id),className:"flex items-center gap-2 px-6 py-4 text-sm font-medium border-none cursor-pointer transition-colors min-h-[44px] whitespace-nowrap",style:{background:"transparent",color:x?P:t.textSecondary,borderBottom:x?`2px solid ${P}`:"2px solid transparent"},onMouseEnter:I=>{x||(I.currentTarget.style.color=P,I.currentTarget.style.background=t.isDark?"#FE500010":"#FE500005")},onMouseLeave:I=>{x||(I.currentTarget.style.color=t.textSecondary,I.currentTarget.style.background="transparent")},onFocus:I=>{x||(I.currentTarget.style.color=P,I.currentTarget.style.background=t.isDark?"#FE500010":"#FE500005")},onBlur:I=>{x||(I.currentTarget.style.color=t.textSecondary,I.currentTarget.style.background="transparent")},children:[e.jsx(K,{size:16,style:{color:j?"#2ecc71":x?P:t.textDim},"aria-hidden":"true"}),e.jsx("span",{style:{fontFamily:"'Geist Sans', sans-serif"},children:N.label}),T&&e.jsx(Z,{size:12,style:{color:"#2ecc71"},"aria-hidden":"true"}),e.jsxs("span",{className:"sr-only",children:[x&&", selected",j&&", completed",T&&", task completed",". Use arrow keys to navigate tabs."]})]},N.id)})})]}),e.jsx("div",{ref:p,id:"main-content",role:"tabpanel","aria-labelledby":`tab-${k}`,tabIndex:0,className:`flex-1 min-h-0 focus:outline-none ${k==="test"?"overflow-hidden":"overflow-y-auto"}`,"data-skip-target":!0,children:e.jsx("div",{className:k==="test"?"h-full":"w-full max-w-screen-2xl mx-auto px-4 sm:px-6 lg:px-8 xl:px-12 py-6 pb-16",children:e.jsx(u.Suspense,{fallback:e.jsx(To,{}),children:k==="describe"?e.jsx(Ke,{onNavigateToNext:R,onNavigateToKnowledge:()=>f("knowledge")}):e.jsx(m,{})})})}),F>0&&e.jsx("button",{type:"button",onClick:L,"aria-label":`Go to previous step: ${V[F-1].label}`,className:"fixed flex items-center justify-center w-10 h-10 rounded-full border-none cursor-pointer transition-all duration-200",style:{position:"fixed",left:"16px",top:"50%",transform:"translateY(-50%)",zIndex:30,background:t.isDark?`${t.surface}CC`:`${t.surface}CC`,color:t.textPrimary,boxShadow:"0 4px 12px rgba(0,0,0,0.1)"},onMouseEnter:N=>{N.currentTarget.style.background=t.isDark?`${t.surface}E6`:`${t.surface}E6`,N.currentTarget.style.transform="translateY(-50%) scale(1.05)"},onMouseLeave:N=>{N.currentTarget.style.background=t.isDark?`${t.surface}CC`:`${t.surface}CC`,N.currentTarget.style.transform="translateY(-50%) scale(1)"},onFocus:N=>{N.currentTarget.style.background=t.isDark?`${t.surface}E6`:`${t.surface}E6`,N.currentTarget.style.transform="translateY(-50%) scale(1.05)"},onBlur:N=>{N.currentTarget.style.background=t.isDark?`${t.surface}CC`:`${t.surface}CC`,N.currentTarget.style.transform="translateY(-50%) scale(1)"},title:`Previous: ${V[F-1].label}`,children:e.jsx(Gs,{size:20})}),F<V.length-1&&e.jsx("button",{type:"button",onClick:R,"aria-label":`Go to next step: ${V[F+1].label}`,className:"fixed flex items-center justify-center w-10 h-10 rounded-full border-none cursor-pointer transition-all duration-200",style:{position:"fixed",right:"16px",top:"50%",transform:"translateY(-50%)",zIndex:30,background:t.isDark?`${t.surface}CC`:`${t.surface}CC`,color:t.textPrimary,boxShadow:"0 4px 12px rgba(0,0,0,0.1)"},onMouseEnter:N=>{N.currentTarget.style.background=t.isDark?`${t.surface}E6`:`${t.surface}E6`,N.currentTarget.style.transform="translateY(-50%) scale(1.05)"},onMouseLeave:N=>{N.currentTarget.style.background=t.isDark?`${t.surface}CC`:`${t.surface}CC`,N.currentTarget.style.transform="translateY(-50%) scale(1)"},onFocus:N=>{N.currentTarget.style.background=t.isDark?`${t.surface}E6`:`${t.surface}E6`,N.currentTarget.style.transform="translateY(-50%) scale(1.05)"},onBlur:N=>{N.currentTarget.style.background=t.isDark?`${t.surface}CC`:`${t.surface}CC`,N.currentTarget.style.transform="translateY(-50%) scale(1)"},title:`Next: ${V[F+1].label}`,children:e.jsx(Me,{size:20})}),e.jsx(jo,{onClick:z,isVisible:k!=="test"})]})}function $o(){const t=W(),[s,o]=u.useState("library"),n=$(m=>m.showFilePicker),a=$(m=>m.setShowFilePicker),r=$(m=>m.setShowSkillPicker),i=$(m=>m.setShowConnectionPicker),l=$(m=>m.setShowMarketplace),c=$(m=>m.run),h=$(m=>m.running),k=$(m=>m.showSettings),f=$(m=>m.setShowSettings),E=q(m=>m.loadServers),S=$(m=>m.loadAgent),g=u.useRef(null),w=u.useCallback(m=>{const F=m.target.files?.[0];if(!F)return;const M=new FileReader;M.onload=R=>{const L=R.target?.result;if(!L)return;const z=to(L),G=$.getState();if(z.channels){G.clearChannels();for(const D of z.channels)G.addChannel(D)}z.selectedModel&&G.setModel(z.selectedModel),z.outputFormat&&G.setOutputFormat(z.outputFormat),z.prompt&&G.setPrompt(z.prompt),z.tokenBudget&&G.setTokenBudget(z.tokenBudget),z.agentMeta&&G.setAgentMeta(z.agentMeta),z.instructionState&&G.setInstructionState(z.instructionState),z.workflowSteps&&G.setWorkflowSteps(z.workflowSteps)},M.readAsText(F),m.target.value=""},[]);u.useEffect(()=>{const m=F=>{(F.metaKey||F.ctrlKey)&&F.key==="k"&&(F.preventDefault(),a(!n)),(F.metaKey||F.ctrlKey)&&F.key==="Enter"&&(F.preventDefault(),h||c()),F.key==="Escape"&&(a(!1),r(!1),i(!1),l(!1),f(!1),$.getState().setShowSaveModal(!1))};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[a,n,r,i,l,c,h]),u.useEffect(()=>{E()},[E]);const b=m=>{S(m),o("editor")},p=()=>{o("editor")},C=()=>{o("library")};return e.jsxs("div",{"data-theme":t.isDark?"dark":"light",className:"w-full h-full flex flex-col overflow-hidden",style:{background:t.bg},children:[e.jsx("input",{ref:g,type:"file",accept:".md,.yaml,.yml,.json",onChange:w,style:{display:"none"},"aria-hidden":"true"}),s==="library"?e.jsx(Zn,{onSelectAgent:b,onNewAgent:p}):e.jsxs(e.Fragment,{children:[e.jsx(on,{onSettingsClick:()=>f(!0,"providers"),onBack:C}),e.jsx(Fo,{})]}),e.jsx("div",{"aria-live":"polite",id:"canvas-announcements",style:{position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",border:"0"}}),e.jsx(rn,{}),e.jsx(ln,{}),e.jsx(hn,{}),e.jsx(vn,{}),e.jsx(yn,{}),e.jsx(Tn,{open:k,onClose:()=>f(!1)}),e.jsx(Un,{})]})}Yt.createRoot(document.getElementById("root")).render(e.jsx(u.StrictMode,{children:e.jsx($o,{})}));export{Re as B,Vn as M,Yn as S,Rt as T,co as a,ie as b,pe as c,Ut as d,Kt as e,Ze as f,Po as g,zo as h,Bn as i,W as u};
|