modular-studio 1.0.3 → 1.0.5
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 +101 -20
- package/dist/assets/Badge-22Ai0eyi.js +1 -0
- package/dist/assets/Input-Bgp734xs.js +1 -0
- package/dist/assets/KnowledgeTab-DABxirZh.js +4 -0
- package/dist/assets/MemoryTab-DZeYElIT.js +16 -0
- package/dist/assets/QualificationTab-Dfpy3J30.js +1 -0
- package/dist/assets/ReviewTab-SD8lQuCc.js +103 -0
- package/dist/assets/Section-DoJrmytO.js +1 -0
- package/dist/assets/TestTab-PDyMF8Fw.js +33 -0
- package/dist/assets/ToolsTab-B83qGCmG.js +1 -0
- package/dist/assets/conversationStore-CkfEU2eV.js +1 -0
- package/dist/assets/icons-C2EV-le6.js +1 -0
- package/dist/assets/index-DkpMAxX7.css +1 -0
- package/dist/assets/index-q24ug5Qs.js +143 -0
- package/dist/assets/{jszip.min-DByyLalk.js → jszip.min-wf-D3Ix_.js} +1 -1
- package/dist/assets/markdown-DWF7F0i0.js +29 -0
- package/dist/assets/services-BaKotDf0.js +343 -0
- package/dist/assets/stores-CeKWz7ou.js +1 -0
- package/dist/assets/vendor-D1h_O76p.js +9 -0
- package/dist/index.html +8 -4
- 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 +12 -1
- package/dist-server/server/index.js.map +1 -1
- package/dist-server/server/mcp/manager.js +0 -1
- 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 +81 -8
- package/dist-server/server/routes/auth-codex.js +0 -1
- 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 +194 -1
- package/dist-server/server/routes/conversations.js +0 -1
- package/dist-server/server/routes/embeddings.d.ts.map +1 -1
- package/dist-server/server/routes/embeddings.js +16 -2
- package/dist-server/server/routes/embeddings.js.map +1 -1
- package/dist-server/server/routes/health.d.ts.map +1 -1
- package/dist-server/server/routes/health.js +10 -2
- package/dist-server/server/routes/health.js.map +1 -1
- package/dist-server/server/routes/knowledge.js +0 -1
- 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 +283 -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 +382 -74
- package/dist-server/server/routes/repo-index.js +0 -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 +44 -5
- package/dist-server/server/routes/skills-search.js.map +1 -1
- 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/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 +18 -3
- package/dist-server/server/services/agentStore.d.ts.map +1 -1
- package/dist-server/server/services/agentStore.js +116 -23
- package/dist-server/server/services/contentStore.js +0 -1
- 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/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/sqliteStore.js +0 -1
- 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 +10 -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/memoryStore.d.ts +107 -0
- package/dist-server/src/store/memoryStore.d.ts.map +1 -0
- package/dist-server/src/store/memoryStore.js +263 -0
- package/dist-server/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +104 -97
- package/dist/assets/graphPopulator-DH0qM1Fu.js +0 -1
- package/dist/assets/index-B0RRTCSi.css +0 -1
- package/dist/assets/index-LWCi_4Hu.js +0 -662
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TestTab-PDyMF8Fw.js","assets/vendor-D1h_O76p.js","assets/conversationStore-CkfEU2eV.js","assets/stores-CeKWz7ou.js","assets/services-BaKotDf0.js","assets/icons-C2EV-le6.js","assets/markdown-DWF7F0i0.js","assets/QualificationTab-Dfpy3J30.js","assets/Input-Bgp734xs.js","assets/Badge-22Ai0eyi.js","assets/KnowledgeTab-DABxirZh.js","assets/ToolsTab-B83qGCmG.js","assets/MemoryTab-DZeYElIT.js","assets/Section-DoJrmytO.js","assets/ReviewTab-SD8lQuCc.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as d,j as e,a as $e,c as ns}from"./vendor-D1h_O76p.js";import{u as A,a as xe,A as Z,R as os,M as st,b as Ne,c as Q,d as ye,g as rs,s as as,e as se,K as is,O as ls,f as cs,D as ds,h as Ee,i as us,j as ps,k as ms,l as be,_ as pe}from"./services-BaKotDf0.js";import{c as Ae}from"./stores-CeKWz7ou.js";import{X as ce,C as Ie,a as ae,A as fs,G as xs,R as gs,S as bt,b as kt,M as vt,c as hs,P as qe,Z as ve,B as Ye,d as wt,H as ys,e as bs,T as jt,F as ks,f as St,D as Je,g as vs,h as De,i as We,j as ws,k as js,l as Ct,m as Ss,n as Le,W as Nt,o as Cs,p as Qe,q as Ns,r as Es,s as Pe,t as Ts,u as Ms,v as Fs,w as Et,I as $s,x as ue,y as As,z as Is,E as Tt,J as Mt,K as Ds,L as Ls,N as Ps,O as Ze,Q as ee,U as X,V as Ft,Y as ke,_ as $t,$ as At,a0 as le,a1 as zs,a2 as Bs,a3 as Rs,a4 as Os,a5 as Gs,a6 as Ue,a7 as He,a8 as It,a9 as _s,aa as Ks,ab as Xe,ac as Ws,ad as Us,ae as Dt,af as Lt,ag as Pt,ah as zt,ai as nt,aj as Hs,ak as Vs,al as qs,am as Ys,an as Js,ao as Qs}from"./icons-C2EV-le6.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 Zs=typeof localStorage<"u"?localStorage.getItem("modular-theme"):null,Me=Ae((t,s)=>({theme:Zs==="light"?"light":"dark",toggleTheme:()=>{const o=s().theme==="dark"?"light":"dark";localStorage.setItem("modular-theme",o),t({theme:o})}})),Xs={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"},en={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 U(){const t=Me(o=>o.theme);return{...t==="dark"?Xs:en,isDark:t==="dark"}}function tn(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 sn(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 nn(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 on(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 rn(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 an(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 ot(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 ln(t,s,o,n){if(!t||!s)return{versionA:o,versionB:n,changes:[],summary:ot([])};const a=[...tn(t,s),...sn(t,s),...nn(t,s),...on(t,s),...rn(t,s),...an(t,s)];return{versionA:o,versionB:n,changes:a,summary:ot(a)}}const cn={meta:"Model & Config",persona:"Persona & Objectives",constraints:"Constraints",workflow:"Workflow",knowledge:"Knowledge",tools:"Tools & MCP"},rt={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:"~"}},dn=["meta","persona","constraints","workflow","knowledge","tools"];function we(t){return t==null?"(empty)":typeof t=="boolean"?t?"on":"off":typeof t=="object"?JSON.stringify(t,null,2):String(t)}function un({change:t,t:s}){const o=rt[t.type]??rt.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:we(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:we(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:we(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:we(t.before)})]})}function pn({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(Ie,{size:12}):e.jsx(ae,{size:12}),e.jsx("span",{className:"text-[12px] font-semibold",style:{color:a.textPrimary},children:cn[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(un,{change:i,t:a},`${i.category}-${i.field}`))})]})}function mn({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 fn({versionA:t,versionB:s,onClose:o}){const n=U(),[a,r]=d.useState(new Set),i=d.useMemo(()=>ln(t.snapshot,s.snapshot,t.version,s.version),[t,s]),l=c=>{r(g=>{const b=new Set(g);return b.has(c)?b.delete(c):b.add(c),b})};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(mn,{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(ce,{size:14})})]}),e.jsx("div",{className:"overflow-y-auto flex-1 p-4 flex flex-col gap-2",children:dn.map(c=>e.jsx(pn,{category:c,changes:i.changes.filter(g=>g.category===c),collapsed:a.has(c),onToggle:()=>l(c),t:n},c))})]})})}function xn({onSettingsClick:t,onBack:s}){const o=A(f=>f.running),n=A(f=>f.run),a=A(f=>f.agentMeta),r=xe(f=>f.currentVersion),i=xe(f=>f.versions),l=xe(f=>f.restoreVersion),c=xe(f=>f.agentId),g=xe(f=>f.loadVersions),b=Me(f=>f.toggleTheme),[p,T]=d.useState(!1),[S,m]=d.useState(null),j=d.useRef(null),y=U();return d.useEffect(()=>{c&&i.length===0&&g()},[c,g]),d.useEffect(()=>{const f=N=>{j.current&&!j.current.contains(N.target)&&T(!1)};if(p)return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[p]),e.jsxs("div",{className:"flex items-center h-[48px] px-4 gap-3 shrink-0 border-b select-none",style:{background:y.surface,backdropFilter:"blur(12px)",borderColor:y.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:y.textSecondary},"aria-label":"Back to library",title:"Back to library",children:e.jsx(fs,{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:y.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:y.textPrimary},children:a.name}),e.jsxs("div",{className:"relative",ref:j,children:[e.jsxs("button",{type:"button",onClick:()=>T(!p),"aria-expanded":p,"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:y.surfaceElevated,color:y.textSecondary,fontFamily:"'Geist Mono', monospace",border:`1px solid ${y.border}`},children:["v",r,e.jsx(ae,{size:10})]}),p&&e.jsx("div",{className:"absolute top-full right-0 mt-1 w-64 rounded-lg border shadow-lg overflow-hidden",style:{background:y.surface,borderColor:y.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(f=>e.jsxs("div",{className:"flex items-center justify-between p-2 rounded-md hover:bg-opacity-50",style:{background:f.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:f.version===r?"#FE5000":y.textPrimary},children:["v",f.version]}),f.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:y.textMuted},children:f.label||"Checkpoint"}),e.jsx("span",{className:"text-[10px]",style:{color:y.textFaint},children:new Date(f.timestamp).toLocaleString()})]}),f.version!==r&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>{i.find(u=>u.version===r)&&(m(f),T(!1))},title:`Compare v${f.version} with current`,className:"flex items-center gap-1 px-2 py-1 rounded text-[11px] font-medium border-none cursor-pointer",style:{background:y.surfaceElevated,color:y.textSecondary,border:`1px solid ${y.border}`},children:[e.jsx(xs,{size:10}),"Compare"]}),e.jsxs("button",{type:"button",onClick:()=>{l(f.version),T(!1)},title:`Restore version ${f.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(gs,{size:10}),"Restore"]})]})]},f.id)),i.length===0&&e.jsx("div",{className:"p-4 text-center",children:e.jsx("div",{className:"text-[12px]",style:{color:y.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:y.textDim},"aria-label":"LLM settings",title:"LLM settings",children:e.jsx(bt,{size:14})}),e.jsx("button",{type:"button",onClick:b,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:y.textDim},"aria-label":y.isDark?"Switch to light mode":"Switch to dark mode",title:y.isDark?"Switch to light mode":"Switch to dark mode",children:y.isDark?e.jsx(kt,{size:14}):e.jsx(vt,{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(hs,{size:12,fill:"white"}):e.jsx(qe,{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 f=i.find(N=>N.version===r);return f?e.jsx(fn,{versionA:S,versionB:f,onClose:()=>m(null)}):null})()]})}function gn(){const t=A(i=>i.totalTokens),s=A(i=>i.tokenBudget),o=U(),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 at=`${Z}/knowledge`,de=Ae(t=>({tree:[],loaded:!1,scanning:!1,error:null,lastDir:"",scanDirectory:async s=>{t({scanning:!0,error:null});try{const n=await(await fetch(`${at}/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(`${at}/read?path=${encodeURIComponent(s)}`)).json();return n.status==="ok"&&n.data?n.data:null}catch{return null}}}));function hn(t){return t>=1e3?`${(t/1e3).toFixed(1)}K`:String(t)}function Bt(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=>Bt(n,s)))}function Rt({node:t,depth:s,onAdd:o,filter:n}){const[a,r]=d.useState(s<1||!!n),i=t.type==="directory"&&t.children&&t.children.length>0,l=U();return Bt(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:hn(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(Rt,{node:c,depth:s+1,onAdd:o,filter:n},c.path))]}):null}function yn(){const t=A(u=>u.showFilePicker),s=A(u=>u.setShowFilePicker),o=A(u=>u.addFileChannel),n=de(u=>u.tree),a=de(u=>u.loaded),r=de(u=>u.scanning),i=de(u=>u.scanDirectory),l=de(u=>u.readFile),c=de(u=>u.lastDir),[g,b]=d.useState(""),[p,T]=d.useState(""),S=d.useRef(null),m=d.useRef(null),j=U();d.useEffect(()=>{t&&(b(""),T(c),setTimeout(()=>S.current?.focus(),100))},[t,c]),d.useEffect(()=>{if(!t)return;const u=M=>{M.key==="Escape"&&s(!1)};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[t,s]);const y=d.useCallback(u=>{if(u.key!=="Tab"||!m.current)return;const M=m.current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(M.length===0)return;const F=M[0],R=M[M.length-1];u.shiftKey?document.activeElement===F&&(u.preventDefault(),R.focus()):document.activeElement===R&&(u.preventDefault(),F.focus())},[]);if(!t)return null;const f=async u=>{if(u.type!=="file")return;const M=c.replace(/\\/g,"/")+"/"+u.path,F=await l(M);F&&o(F)},N=()=>{p.trim()&&i(p.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:m,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:j.surfaceOpaque,border:`1px solid ${j.border}`,boxShadow:"0 24px 48px rgba(0,0,0,0.8)",animation:"modal-in 0.2s ease-out"},onClick:u=>u.stopPropagation(),onKeyDown:y,children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b",style:{borderColor:j.border},children:[e.jsx("span",{className:"text-[13px] font-bold tracking-[3px] uppercase",style:{fontFamily:"'Geist Mono', monospace",color:j.textPrimary},children:"ADD KNOWLEDGE SOURCE"}),e.jsx("button",{type:"button",onClick:()=>s(!1),className:"text-[17px] cursor-pointer border-none bg-transparent",style:{color:j.textMuted},onMouseEnter:u=>{u.currentTarget.style.color="#FE5000"},onMouseLeave:u=>{u.currentTarget.style.color=j.textMuted},"aria-label":"Close file picker",children:"✕"})]}),e.jsxs("div",{className:"px-4 py-2 border-b flex items-center gap-2",style:{borderColor:j.border},children:[e.jsx("input",{type:"text",value:p,onChange:u=>T(u.target.value),onKeyDown:u=>{u.key==="Enter"&&N()},placeholder:"Directory path to scan...",className:"flex-1 outline-none text-[13px]",style:{background:j.inputBg,border:`1px solid ${j.border}`,borderRadius:4,color:j.textPrimary,fontFamily:"'Geist Mono', monospace",padding:"6px 10px"},"aria-label":"Directory path to scan"}),e.jsx("button",{type:"button",onClick:N,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:j.borderSubtle},children:e.jsx("input",{ref:S,type:"text",value:g,onChange:u=>b(u.target.value),placeholder:"Filter results...",className:"w-full outline-none text-[13px]",style:{background:j.inputBg,border:`1px solid ${j.border}`,borderRadius:4,color:j.textPrimary,fontFamily:"'Geist Mono', monospace",padding:"6px 10px"},onFocus:u=>{u.currentTarget.style.borderColor="#FE500050"},onBlur:u=>{u.currentTarget.style.borderColor=j.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(u=>e.jsx(Rt,{node:u,depth:0,onAdd:M=>{f(M)},filter:g},u.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:j.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:j.textDim},children:"Enter a directory path and click Scan to browse files."})})})]})]})}const ge=Ae((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(`${Z}/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)})}})),et={presentation:Ps,mic:Ls,cloud:Ds,code:Mt,"bar-chart-3":Tt,anchor:Is,"git-branch":We,palette:As,search:ue,image:$s,"book-open":Et,hexagon:Fs,workflow:Ms,map:Ts,sparkles:Pe,compass:Es,waves:Ns,box:Qe,layout:Cs,wrench:Nt,cpu:Le,triangle:Ss,"pen-tool":Ct,mail:js,hash:ws,github:We,"file-text":De,flame:vs,database:Je,globe:St,folder:ks,target:jt,"clipboard-list":bs,"hard-drive":ys,shield:wt,brain:Ye};function ze({icon:t,size:s=14,...o}){const n=et[t];return n?e.jsx(n,{size:s,...o}):e.jsx(Ze,{size:s,...o})}function bn({icon:t,size:s=14,...o}){const n=et[t];return n?e.jsx(n,{size:s,...o}):e.jsx(ve,{size:s,...o})}function kn({icon:t,size:s=14,...o}){const n=et[t];return n?e.jsx(n,{size:s,...o}):e.jsx(ve,{size:s,...o})}function Ot({open:t,onClose:s,title:o,searchPlaceholder:n,width:a=520,hideSearch:r,children:i}){const[l,c]=d.useState(""),g=d.useRef(null),b=d.useRef(null),p=U();d.useEffect(()=>{t&&(c(""),setTimeout(()=>g.current?.focus(),100))},[t]),d.useEffect(()=>{if(!t)return;const S=m=>{m.key==="Escape"&&s()};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[t,s]);const T=d.useCallback(S=>{if(S.key!=="Tab"||!b.current)return;const m=b.current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(m.length===0)return;const j=m[0],y=m[m.length-1];S.shiftKey?document.activeElement===j&&(S.preventDefault(),y.focus()):document.activeElement===y&&(S.preventDefault(),j.focus())},[]);return t?$e.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:b,role:"dialog","aria-modal":"true","aria-label":o,className:"relative max-h-[70vh] flex flex-col rounded-xl overflow-hidden",style:{width:a,background:p.surface,border:`1px solid ${p.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:T,children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4",style:{borderBottom:`1px solid ${p.border}`},children:[e.jsx("span",{className:"text-[14px] font-semibold",style:{color:p.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:p.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=p.textDim},children:e.jsx(ce,{size:16})})]}),!r&&e.jsx("div",{className:"px-5 py-3",style:{borderBottom:`1px solid ${p.borderSubtle}`},children:e.jsxs("div",{className:"relative",children:[e.jsx(ue,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2",style:{color:p.textDim}}),e.jsx("input",{ref:g,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:p.inputBg,border:`1px solid ${p.border}`,color:p.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 he=new Map,je=new Set,Gt=new Set;let Be=!1,Se=null;function vn(t){const s=t.includes(":")?t.split(":").pop():t;return s.includes("/")?s.split("/").pop():s}function wn(){return Be?Promise.resolve():Se||(Se=fetch(`${Z}/health/skills`).then(t=>t.json()).then(t=>{t.status==="ok"&&Array.isArray(t.data)&&t.data.forEach(s=>Gt.add(s.id)),Be=!0}).catch(()=>{Be=!0}),Se)}function jn(t){return t==="ok"?"#2ecc71":t==="warning"?"#f39c12":t==="error"?"#e74c3c":"#888"}function tt({skillPath:t}){const s=U(),o=vn(t),[n,a]=d.useState(()=>he.get(o)??null),[r,i]=d.useState(()=>!he.has(o)&&!je.has(o)),[l,c]=d.useState(null);if(d.useEffect(()=>{if(he.has(o)){a(he.get(o)),i(!1);return}if(je.has(o)){i(!1);return}let S=!1;return wn().then(()=>{if(!S){if(!Gt.has(o)){je.add(o),i(!1);return}fetch(`${Z}/health/skills/${encodeURIComponent(o)}`).then(m=>m.status===404?(je.add(o),S||i(!1),null):m.json()).then(m=>{S||m===null||(m.status==="ok"&&m.data&&(he.set(o,m.data),a(m.data)),i(!1))}).catch(()=>{S||i(!1)})}}),()=>{S=!0}},[o]),!r&&n===null)return null;const g=r&&n===null,b=n?.securityIssues.some(S=>S.includes("undocumented"))??!1,p=[{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?b?"#e74c3c":"#2ecc71":"#888",tooltip:n?b?"Docs: Missing SKILL.md / README":"Docs: Present":"Docs: Loading..."}],T=jn(n?.status??null);return e.jsxs("div",{style:{position:"relative",display:"inline-flex",alignItems:"center",gap:3},children:[g?e.jsx(ee,{size:8,style:{color:"#888"},className:"animate-spin"}):e.jsx("span",{style:{display:"inline-block",width:6,height:6,borderRadius:"50%",background:T,flexShrink:0}}),p.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:g?"#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 Sn={content:"Content",analysis:"Analysis",development:"Development",domain:"Domain"},Cn=["content","analysis","development","domain"];function Nn(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 En(){const t=A(f=>f.showSkillPicker),s=A(f=>f.setShowSkillPicker),o=A(f=>f.skills),n=A(f=>f.addSkill),a=A(f=>f.upsertSkill),r=ge(f=>f.skills),i=ge(f=>f.loaded),l=ge(f=>f.loading),c=ge(f=>f.loadSkills),g=ge(f=>f.toggleSkill),b=U(),[p,T]=d.useState(()=>new Set);d.useEffect(()=>{t&&!i&&!l&&c()},[t,i,l,c]),d.useEffect(()=>{t&&T(new Set)},[t]),d.useEffect(()=>{if(r.length!==0)for(const f of r)a({id:f.id,name:f.name,description:f.description||"Installed skill"})},[r,a]);const S=d.useMemo(()=>{const f=new Set(o.filter(u=>u.added).map(u=>u.id)),N=new Map(o.map(u=>[u.id,u]));for(const u of r)N.has(u.id)||N.set(u.id,{id:u.id,name:u.name,icon:"zap",enabled:u.enabled,added:f.has(u.id),description:u.description||"Installed skill",category:Nn(u.name,u.description||"")});return Array.from(N.values())},[o,r]),m=(f,N)=>{N||T(u=>{const M=new Set(u);return M.has(f)?M.delete(f):M.add(f),M})},j=()=>{p.forEach(f=>{n(f);const N=r.find(u=>u.id===f);N&&!N.enabled&&g(f)}),T(new Set),s(!1)},y=()=>{T(new Set),s(!1)};return e.jsx(Ot,{open:t,onClose:y,title:"Select Skills",searchPlaceholder:"Search skills...",children:f=>{const N=S.filter(M=>{if(!f)return!0;const F=f.toLowerCase();return M.name.toLowerCase().includes(F)||M.description.toLowerCase().includes(F)}),u=Cn.map(M=>({category:M,label:Sn[M],skills:N.filter(F=>F.category===M)})).filter(M=>M.skills.length>0);return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"flex-1 overflow-y-auto",children:u.map(M=>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:b.textDim},children:M.label})}),M.skills.map(F=>{const R=p.has(F.id),P=F.added;return e.jsxs("div",{className:`flex items-center gap-3 px-5 py-2.5 ${P?"cursor-default":"hover-row cursor-pointer"}`,style:{background:R?"#FE500012":"transparent"},onClick:()=>m(F.id,P),children:[e.jsx("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center shrink-0",style:{background:b.surfaceElevated},children:e.jsx(bn,{icon:F.icon,size:16,style:{color:b.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:b.textPrimary},children:F.name}),F.skillUrl?.startsWith("https://skills.sh/")&&e.jsx(tt,{skillPath:F.skillUrl.replace("https://skills.sh/","").split("/").pop()??""})]}),e.jsx("span",{className:"text-[14px]",style:{color:b.textDim},children:F.description})]}),P?e.jsxs("span",{className:"flex items-center gap-1 text-[14px] px-2.5 py-1 rounded-md",style:{color:b.statusSuccess,background:b.statusSuccessBg},children:[e.jsx(X,{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":b.border,background:R?"#FE5000":"transparent"},children:R&&e.jsx(X,{size:10,style:{color:"#fff"}})})]},F.id)})]},M.category))}),e.jsxs("div",{className:"flex items-center justify-end gap-3 px-5 py-3",style:{borderTop:`1px solid ${b.border}`,background:b.surfaceOpaque},children:[e.jsx("button",{type:"button",onClick:y,className:"px-4 py-2 text-[14px] rounded-lg cursor-pointer border",style:{background:"transparent",border:`1px solid ${b.border}`,color:b.textSecondary},children:"Cancel"}),e.jsxs("button",{type:"button",onClick:j,disabled:p.size===0,className:"px-4 py-2 text-[14px] rounded-lg cursor-pointer border-none",style:{background:p.size>0?"#FE5000":b.surfaceElevated,color:p.size>0?"#fff":b.textDim,opacity:p.size>0?1:.5,cursor:p.size>0?"pointer":"not-allowed"},children:["Add ",p.size>0?`${p.size} skill${p.size===1?"":"s"}`:"skills"]})]})]})}})}function _t({content:t,children:s,position:o="top",delay:n=300}){const a=U(),[r,i]=d.useState(!1),[l,c]=d.useState({x:0,y:0}),g=d.useRef(void 0),b=d.useRef(null),p=()=>{g.current=setTimeout(()=>{if(!b.current)return;const m=b.current.getBoundingClientRect();c({x:m.left+m.width/2,y:o==="top"?m.top-8:m.bottom+8}),i(!0)},n)},T=()=>{clearTimeout(g.current),i(!1)},S=a.isDark?"#333":"#222";return e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:b,onMouseEnter:p,onMouseLeave:T,className:"inline-flex",children:s}),r&&$e.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 Tn(){const t=A(k=>k.showMarketplace),s=A(k=>k.activeMarketplaceTab),o=A(k=>k.setShowMarketplace),n=A(k=>k.registrySkills),a=A(k=>k.installRegistrySkill),r=A(k=>k.upsertSkill),i=A(k=>k.skills),[l,c]=d.useState(""),[g,b]=d.useState("all"),[p,T]=d.useState(null),[S,m]=d.useState(null),[j,y]=d.useState(()=>new Set),[f,N]=d.useState([]),[u,M]=d.useState(!1),[F,R]=d.useState(null),[P,B]=d.useState(null),_=d.useRef(null),L=d.useRef(null),h=U(),H=new Set(Array.isArray(i)?i.filter(k=>k.added).map(k=>k.id??""):[]),C=d.useCallback(k=>{if(k.key!=="Tab"||!L.current)return;const W=L.current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(W.length===0)return;const V=W[0],J=W[W.length-1];k.shiftKey?document.activeElement===V&&(k.preventDefault(),J.focus()):document.activeElement===J&&(k.preventDefault(),V.focus())},[]);d.useEffect(()=>{t&&(c(""),b("all"),T(null),m(null),N([]),M(!1),R(null),B(null),setTimeout(()=>_.current?.focus(),100))},[t]),d.useEffect(()=>{if(!t)return;const k=W=>{W.key==="Escape"&&o(!1)};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[t,o]);const O=d.useCallback(k=>{o(!0,k),c(""),b("all"),N([]),R(null),M(!1)},[o]),K=d.useCallback((k,W,V)=>{T(k),B(null),setTimeout(()=>{a(k,W,V),T(null)},1200)},[a]),x=d.useCallback(async k=>{m(k.id);try{const W=await fetch(`${Z}/skills/install`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({skillId:k.id})});if(!W.ok)throw new Error(`HTTP ${W.status}`);y(V=>new Set(V).add(k.id)),r({id:k.id,name:k.name,description:`Installed from skills.sh (${k.repo})`,skillUrl:k.url})}catch(W){R(W instanceof Error?W.message:"Install failed")}finally{m(null)}},[r]);d.useEffect(()=>{if(!t||s!=="skills"){M(!1),N([]),R(null);return}const k=l.trim();if(k.length<2){M(!1),N([]),R(null);return}const W=new AbortController,V=setTimeout(async()=>{M(!0),R(null);try{const J=await fetch(`${Z}/skills/search?q=${encodeURIComponent(k)}`,{signal:W.signal});if(!J.ok)throw new Error(`HTTP ${J.status}`);const fe=await J.json();N(Array.isArray(fe.data)?fe.data:[]),R(fe.error??null)}catch(J){if(W.signal.aborted)return;N([]),R(J instanceof Error?J.message:"Search failed")}finally{W.signal.aborted||M(!1)}},300);return()=>{W.abort(),clearTimeout(V)}},[s,l,t]);const v=()=>{if(typeof window>"u")return 4;const k=window.innerWidth;return k<=1024?2:k<=1440?3:4},[E,z]=d.useState(v);if(d.useEffect(()=>{const k=()=>z(v());return window.addEventListener("resize",k),()=>window.removeEventListener("resize",k)},[]),!t)return null;const D=(k,W)=>{if(!l)return!0;const V=l.toLowerCase();return k.toLowerCase().includes(V)||W.toLowerCase().includes(V)},I=n.filter(k=>D(k.name,k.description)&&(g==="all"||k.category===g)),w=os.filter(k=>D(k.name,k.description)),G={display:"grid",gridTemplateColumns:`repeat(${E}, 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:L,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:h.surface,border:`1px solid ${h.border}`,boxShadow:"0 24px 48px rgba(0,0,0,0.6)",animation:"modal-in 0.2s ease-out"},onClick:k=>k.stopPropagation(),onKeyDown:C,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"12px 16px",borderBottom:`1px solid ${h.border}`},children:[e.jsx("span",{style:{fontSize:17,fontWeight:600,flexShrink:0,color:h.textPrimary,fontFamily:"'Geist Mono', monospace"},children:"Marketplace"}),e.jsxs("div",{style:{position:"relative",width:240,flexShrink:0},children:[e.jsx(ue,{size:13,style:{position:"absolute",left:10,top:"50%",transform:"translateY(-50%)",color:h.textDim}}),e.jsx("input",{ref:_,type:"text",value:l,onChange:k=>c(k.target.value),placeholder:"Search...",style:{width:"100%",outline:"none",fontSize:14,paddingLeft:32,paddingRight:12,paddingTop:6,paddingBottom:6,borderRadius:6,background:h.inputBg,border:`1px solid ${h.border}`,color:h.textPrimary,fontFamily:"'Geist Sans', sans-serif"}})]}),e.jsx("div",{style:{display:"flex",alignItems:"center",marginLeft:"auto",borderBottom:`1px solid ${h.borderSubtle}`},children:["skills","mcp","presets"].map(k=>e.jsx("button",{type:"button",onClick:()=>O(k),style:{padding:"6px 12px",fontSize:13,fontWeight:500,letterSpacing:"0.025em",textTransform:"uppercase",cursor:"pointer",border:"none",color:s===k?"#FE5000":h.textDim,borderBottom:s===k?"2px solid #FE5000":"2px solid transparent",background:"transparent",marginBottom:-1,transition:"color 150ms ease"},children:k==="mcp"?"MCP Servers":k==="presets"?"Presets":"Skills"},k))}),e.jsx(_t,{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:h.textDim},"aria-label":"Close marketplace",onMouseEnter:k=>{k.currentTarget.style.background="#ef444420",k.currentTarget.style.color="#ef4444"},onMouseLeave:k=>{k.currentTarget.style.background="transparent",k.currentTarget.style.color=h.textDim},children:e.jsx(ce,{size:16})})})]}),s==="skills"&&e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 16px",borderBottom:`1px solid ${h.borderSubtle}`,gap:12,flexWrap:"wrap"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:4,flexWrap:"wrap",flex:1},children:st.map(k=>e.jsx("button",{type:"button",onClick:()=>b(k.id),style:{fontSize:12,padding:"2px 10px",borderRadius:9999,cursor:"pointer",border:"none",fontWeight:500,background:g===k.id?"#FE5000":h.surfaceElevated,color:g===k.id?"#fff":h.textSecondary,transition:"background 150ms ease, color 150ms ease"},children:k.label},k.id))}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:12,flexShrink:0},children:Object.entries(Ne).map(([k,W])=>e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,fontSize:13,color:h.textDim},children:[e.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:W.color,display:"inline-block",flexShrink:0}}),W.label]},k))})]}),s==="mcp"&&e.jsx("div",{style:{display:"flex",alignItems:"center",padding:"8px 16px",gap:4,flexWrap:"wrap",borderBottom:`1px solid ${h.borderSubtle}`},children:st.map(k=>e.jsx("button",{type:"button",onClick:()=>b(k.id),style:{fontSize:12,padding:"2px 10px",borderRadius:9999,cursor:"pointer",border:"none",fontWeight:500,background:g===k.id?"#FE5000":h.surfaceElevated,color:g===k.id?"#fff":h.textSecondary,transition:"background 150ms ease, color 150ms ease"},children:k.label},k.id))}),e.jsxs("div",{style:{flex:1,overflowY:"auto"},children:[s==="skills"&&e.jsxs(e.Fragment,{children:[I.length>0&&e.jsx("div",{style:G,children:I.map(k=>e.jsx(Mn,{skill:k,isInLibrary:H.has(k.id),installing:p===k.id,dropdownOpen:P===k.id,onToggleDropdown:()=>B(P===k.id?null:k.id),onInstall:K,t:h},k.id))}),I.length===0&&!u&&!F&&f.length===0&&e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"48px 0"},children:e.jsx("span",{style:{fontSize:14,color:h.textFaint},children:"No skills match your search"})}),(l.trim().length>=2||u||F||f.length>0)&&e.jsx("div",{style:{padding:"16px 16px 8px",borderTop:`1px solid ${h.borderSubtle}`},children:e.jsx("span",{style:{fontSize:12,letterSpacing:"0.05em",textTransform:"uppercase",color:h.textDim,fontFamily:"'Geist Mono', monospace"},children:"From skill.sh"})}),u&&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:h.textDim},children:[e.jsx(ee,{size:12,style:{animation:"spin 1s linear infinite"}}),"Searching skill.sh..."]})}),!u&&F&&e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"24px 16px"},children:e.jsx("span",{style:{fontSize:13,color:h.statusError},children:"skill.sh search unavailable"})}),!u&&!F&&f.length>0&&e.jsx("div",{style:{...G,paddingTop:0},children:f.map(k=>e.jsx(Fn,{skill:k,installing:S===k.id,installed:j.has(k.id),onInstall:()=>x(k),t:h},k.id))}),!u&&!F&&l.trim().length>=2&&f.length===0&&e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"24px 16px"},children:e.jsx("span",{style:{fontSize:13,color:h.textFaint},children:"No results from skill.sh"})})]}),s==="mcp"&&e.jsxs("div",{style:{textAlign:"center",padding:40},children:[e.jsx("p",{style:{color:h.textDim,marginBottom:12},children:"Browse and connect MCP servers"}),e.jsx("button",{onClick:()=>{o(!1),A.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:[w.map(k=>e.jsx($n,{preset:k,t:h,onLoad:()=>o(!1)},k.id)),w.length===0&&e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"48px 0"},children:e.jsx("span",{style:{fontSize:14,color:h.textFaint},children:"No presets match your search"})})]})]})]})]})})}function Mn({skill:t,isInLibrary:s,installing:o,dropdownOpen:n,onToggleDropdown:a,onInstall:r,t:i}){const[l,c]=d.useState(!1),[g,b]=d.useState("claude"),[p,T]=d.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:m=>{S||(m.currentTarget.style.borderColor="#FE500050")},onMouseLeave:m=>{m.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(Ft,{size:9}):e.jsx(ae,{size:9})})]}),e.jsx(tt,{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(m=>e.jsx("span",{title:Ne[m].label,style:{width:7,height:7,borderRadius:"50%",background:Ne[m].color,display:"inline-block",flexShrink:0}},m))}),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(X,{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(ee,{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:m=>{m.currentTarget.style.borderColor="#FE5000",m.currentTarget.style.color="#FE5000"},onMouseLeave:m=>{n||(m.currentTarget.style.borderColor=i.border,m.currentTarget.style.color=i.textSecondary)},onFocus:m=>{m.currentTarget.style.borderColor="#FE5000",m.currentTarget.style.color="#FE5000"},onBlur:m=>{n||(m.currentTarget.style.borderColor=i.border,m.currentTarget.style.color=i.textSecondary)},children:["Install ",e.jsx(ae,{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(m=>e.jsx("button",{type:"button",onClick:()=>b(m),style:{fontSize:13,padding:"2px 6px",borderRadius:4,cursor:"pointer",border:"none",background:g===m?"#FE5000":i.surfaceElevated,color:g===m?"#fff":i.textSecondary,fontWeight:500},children:m==="all"?"All":Ne[m].label},m))})]}),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(m=>e.jsx("button",{type:"button",onClick:()=>T(m),style:{fontSize:13,padding:"2px 6px",borderRadius:4,cursor:"pointer",border:"none",background:p===m?"#FE5000":i.surfaceElevated,color:p===m?"#fff":i.textSecondary,fontWeight:500,textTransform:"capitalize"},children:m},m))})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,background:i.inputBg,borderRadius:4,padding:"4px 6px"},children:[e.jsx(ke,{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 ",g," --scope ",p]})]}),e.jsx("button",{type:"button",onClick:()=>r(t.id,g,p),style:{width:"100%",padding:"6px",borderRadius:4,border:"none",background:"#FE5000",color:"#fff",fontSize:12,fontWeight:600,cursor:"pointer"},children:"Confirm Install"})]})]})}function Fn({skill:t,installing:s,installed:o,onInstall:n,t:a}){const[r,i]=d.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(_t,{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($t,{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(Ft,{size:9}):e.jsx(ae,{size:9})})]}),e.jsx(tt,{skillPath:l}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginTop:2},children:[e.jsx(ve,{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(X,{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(ee,{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(At,{size:9})," Install"]})]})]})}function $n({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(kn,{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 Re=(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 Oe({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 it({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(Ie,{size:14,style:{color:n.textSecondary}}):e.jsx(ae,{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 An(){const t=A(x=>x.showConnectionPicker),s=A(x=>x.setShowConnectionPicker),o=A(x=>x.connectors),n=A(x=>x.addConnector),a=A(x=>x.upsertMcpServer),r=U(),[i,l]=d.useState({}),[c,g]=d.useState({}),[b,p]=d.useState({}),[T,S]=d.useState(!1),[m,j]=d.useState(!1),[y,f]=d.useState("All"),[N,u]=d.useState({}),M=Q(x=>x.servers),F=Q(x=>x.addServer),R=ye.filter(x=>x.authMethod==="oauth"&&!!x.url),P=["All",...Array.from(new Set(ye.map(x=>x.category)))];d.useEffect(()=>{t&&R.forEach(x=>{rs(x.url).then(v=>{if(l(E=>({...E,[x.url]:v.connected})),v.connected){const E=x.id;A.getState().connectors.some(z=>z.service===E)||n({id:`conn-${x.id}-oauth`,service:E,name:x.name,mcpServerId:x.id,direction:"both",enabled:!0,config:{},status:"connected",authMethod:"oauth"})}}).catch(()=>{})})},[t]);const B=async x=>{g(v=>({...v,[x.url]:!0})),p(v=>({...v,[x.url]:""}));try{await as(x.url),l(z=>({...z,[x.url]:!0})),await F({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 E=x.id;o.some(z=>z.service===E)||n({id:`conn-${x.id}-oauth-${Date.now()}`,service:E,name:x.name,mcpServerId:x.id,direction:"both",enabled:!0,config:{},status:"connected",authMethod:"oauth"})}catch(v){p(E=>({...E,[x.url]:v.message}))}finally{g(v=>({...v,[x.url]:!1}))}},_=x=>{const v=ye.find(E=>E.id===x);v&&u(E=>({...E,[x]:{entry:v,expanded:!E[x]?.expanded,configValues:E[x]?.configValues||{}}}))},L=(x,v,E)=>{u(z=>({...z,[x]:{...z[x],configValues:{...z[x]?.configValues,[v]:E}}}))},h=async x=>{const E=N[x.id]?.configValues||{};await a({id:x.id,name:x.name,description:x.description,connected:!1});const z={};x.configFields&&x.configFields.length>0&&x.configFields.forEach(D=>{const I=E[D.key];I&&(z[D.key]=I)}),await F({id:x.id,name:x.name,type:x.transport==="stdio"?"stdio":"http",command:x.command||"",args:x.defaultArgs||[],env:z,autoConnect:!0,...x.url?{url:x.url}:{}}),u(D=>({...D,[x.id]:{...D[x.id],expanded:!1}}))},H=x=>M.some(v=>v.id===x)||o.some(v=>v.mcpServerId===x),C=x=>M.find(E=>E.id===x)?.status??"disconnected",O=x=>{const v=i[x.url]??!1,E=c[x.url]??!1,z=b[x.url],D=H(x.id),I=Re("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(ze,{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(Oe,{status:v?"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}),z&&e.jsx("span",{className:"text-[10px] ml-2",style:{color:"#ff4444"},children:z})]})]}),D&&v?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(X,{size:12})," Connected"]}):e.jsxs("button",{type:"button",onClick:()=>B(x),disabled:E,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:E?.7:1},onMouseEnter:w=>{w.currentTarget.style.background="#FE500030"},onMouseLeave:w=>{w.currentTarget.style.background="#FE500018"},children:[E?e.jsx(ee,{size:12,className:"animate-spin"}):e.jsx(le,{size:12}),E?"Connecting...":"Connect"]})]},x.id)},K=x=>{if(x.authMethod==="oauth"){const I=i[x.url]??!1,w=Re("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(ze,{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(Oe,{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:w.bg,color:w.color,fontFamily:"'Geist Mono', monospace",fontWeight:600},children:w.text})]}),e.jsx("span",{className:"text-[11px]",style:{color:r.textDim},children:x.description})]}),e.jsxs("button",{type:"button",onClick:()=>x.url&&B(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:G=>{G.currentTarget.style.background="#FE500030"},onMouseLeave:G=>{G.currentTarget.style.background="#FE500018"},children:[e.jsx(le,{size:12}),"Connect via OAuth"]})]},x.id)}const v=H(x.id),E=Re(x.authMethod),z=N[x.id],D=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(ze,{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(Oe,{status:C(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:E.bg,color:E.color,fontFamily:"'Geist Mono', monospace",fontWeight:600},children:E.text})]}),e.jsx("span",{className:"text-[11px]",style:{color:r.textDim},children:x.description})]}),v?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(X,{size:12})," Added"]}):e.jsxs("button",{type:"button",onClick:()=>D?_(x.id):h(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(le,{size:12}),"Add"]})]}),D&&z?.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:z.configValues[I.key]||"",onChange:w=>L(x.id,I.key,w.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:()=>h(x),disabled:x.configFields.some(I=>I.required&&!z.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&&!z.configValues[I.key])?.5:1},children:[e.jsx(X,{size:12}),"Save & Add"]}),e.jsx("button",{type:"button",onClick:()=>_(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(Ot,{open:t,onClose:()=>s(!1),title:"Add Connection",searchPlaceholder:"Search connections...",width:600,children:x=>{const v=x?.toLowerCase()??"",E=R.filter(D=>!v||D.name.toLowerCase().includes(v)||D.description.toLowerCase().includes(v)),z=ye.filter(D=>{const I=!v||D.name.toLowerCase().includes(v)||D.description.toLowerCase().includes(v)||D.tags&&D.tags.some(G=>G.toLowerCase().includes(v)),w=y==="All"||D.category===y;return I&&w});return e.jsxs(e.Fragment,{children:[E.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(it,{title:"Quick Connect",collapsed:T,onToggle:()=>S(!T),t:r}),!T&&e.jsx("div",{className:"pb-2",children:E.map(O)})]}),e.jsx(it,{title:"MCP Library",collapsed:m,onToggle:()=>j(!m),t:r}),!m&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex gap-1 px-5 py-2 overflow-x-auto",children:P.map(D=>e.jsx("button",{type:"button",onClick:()=>f(D),className:"text-[11px] px-2 py-1 rounded-md cursor-pointer border-none whitespace-nowrap transition-colors",style:{background:y===D?"#FE5000":"transparent",color:y===D?"white":r.textDim,fontFamily:"'Geist Mono', monospace",fontWeight:600},onMouseEnter:I=>{y!==D&&(I.currentTarget.style.background="#FE500015",I.currentTarget.style.color="#FE5000")},onMouseLeave:I=>{y!==D&&(I.currentTarget.style.background="transparent",I.currentTarget.style.color=r.textDim)},children:D},D))}),e.jsx("div",{className:"max-h-[400px] overflow-y-auto pb-2",children:z.map(K)})]})]})}})}const In=[{id:"providers",label:"Providers"},{id:"mcp",label:"MCP Servers"},{id:"general",label:"General"}];function Fe(t,s){switch(t){case"connected":return s.statusSuccess;case"configured":return s.statusWarning;case"error":return s.statusError;default:return s.textMuted}}function Dn({provider:t}){const s=U(),[o,n]=d.useState(!1),[a,r]=d.useState(!1),[i,l]=d.useState(t.apiKey||""),[c,g]=d.useState(t.baseUrl),[b,p]=d.useState(null),T=se(h=>h.setProviderKey),S=se(h=>h.setProviderAuthMethod),m=se(h=>h.setProviderBaseUrl),j=se(h=>h.testConnection),y=se(h=>h.testing[t.id]),f=se(h=>h.deleteProvider),N=se(h=>h.saveProvider),u=t.id.startsWith("custom-"),M=t.id==="openai",F=M&&t.authMethod==="oauth",R=t.id==="anthropic"?"Claude":t.name,P=Array.isArray(t.models)?t.models:[];d.useEffect(()=>{t.apiKey&&t.apiKey.trim().length>0&&l(t.apiKey),g(t.baseUrl)},[t.apiKey,t.baseUrl]);const B=d.useCallback(()=>{T(t.id,i),m(t.id,c),N(t.id)},[t.id,i,c,T,m,N]),_=d.useCallback(async()=>{B();const h=await j(t.id);p(h)},[t.id,B,j]),L={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:Fe(t.status,s),boxShadow:`0 0 6px ${Fe(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(Le,{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"?`${P.length} models`:t.status})]}),o&&e.jsxs("div",{className:"px-4 pb-4 flex flex-col gap-3",children:[M&&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:h=>S(t.id,h.target.value),className:"nodrag nowheel w-full text-[14px] px-3 py-2 rounded-lg outline-none",style:L,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(ke,{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(Ue,{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(He,{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:P.map(h=>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:h.label},h.id))})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsxs("button",{type:"button",onClick:_,disabled:y,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:y?.6:1},children:[y?e.jsx(ee,{size:12,className:"animate-spin"}):e.jsx(It,{size:12}),"Check Status"]}),e.jsx("button",{type:"button",onClick:_,disabled:y,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:y?.6:1},children:"Refresh Models"})]})]}):e.jsxs(e.Fragment,{children:[F?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(ke,{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(`${Z}/auth/codex/start`,{method:"POST"})).json(),C=H?.data?.sessionId,O=H?.data?.authUrl;if(!C||!O)return;window.open(O,"_blank","noopener,noreferrer");const K=window.prompt("Paste your OpenAI API key to complete Codex login");if(!K)return;const E=(await(await fetch(`${Z}/auth/codex/complete/${C}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:K.trim()})})).json())?.data?.apiKey;if(!E)return;T(t.id,E),l(E),m(t.id,c),N(t.id),await _()}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:h=>l(h.target.value),onBlur:B,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:L}),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(_s,{size:14}):e.jsx(Ks,{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:h=>g(h.target.value),onBlur:B,className:"nodrag nowheel w-full text-[14px] px-3 py-2 rounded-lg outline-none",style:L})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsxs("button",{type:"button",onClick:_,disabled:y,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:y?.6:1},children:[y?e.jsx(ee,{size:12,className:"animate-spin"}):e.jsx(Ze,{size:12}),"Test Connection"]}),e.jsx("button",{type:"button",onClick:_,disabled:y,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:y?.6:1},children:"Refresh Models"}),t.keyPageUrl&&!F&&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($t,{size:10}),"Get API Key"]}),u&&e.jsxs("button",{type:"button",onClick:()=>f(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(Xe,{size:10}),"Remove"]})]}),b&&e.jsxs("div",{className:"flex items-center gap-2 text-[14px] px-3 py-2 rounded-lg",style:{background:b.ok?s.statusSuccessBg:s.statusErrorBg,border:`1px solid ${b.ok?s.statusSuccess+"30":s.statusError+"30"}`,color:b.ok?s.statusSuccess:s.statusError},children:[b.ok?e.jsx(Ue,{size:14}):e.jsx(He,{size:14}),b.ok?`Connected${b.models?` — ${b.models.length} models available`:""}`:b.error||"Connection failed"]})]}),t.headerNote&&e.jsx("span",{className:"text-[12px]",style:{color:s.textFaint},children:t.headerNote})]})]})}function Ln(){const t=U(),s=se(n=>n.providers),o=se(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(Dn,{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(le,{size:12}),"Add Custom Provider"]})})]})}function Pn({server:t}){const s=U(),[o,n]=d.useState(!1),a=Q(g=>g.connectServer),r=Q(g=>g.disconnectServer),i=Q(g=>g.removeServer),l=A(g=>g.removeMcpServer),c=d.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:Fe(t.status,s),boxShadow:`0 0 6px ${Fe(t.status,s)}40`}}),e.jsx(Ws,{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:g=>{g.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(ee,{size:10,className:"animate-spin"}):t.status==="connected"?e.jsx(It,{size:10}):e.jsx(Ze,{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(Xe,{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(ae,{size:12}):e.jsx(Ie,{size:12}),"View Tools (",t.tools.length,")"]}),o&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-2",children:t.tools.map(g=>e.jsx("span",{className:"text-[12px] px-2 py-0.5 rounded",style:{background:"#FE500015",color:"#FE5000",fontFamily:"'Geist Mono', monospace"},title:g.description,children:g.name},g.name))})]})]})}function zn(){const t=U(),s=A(L=>L.mcpServers),o=Q(L=>L.servers),n=Q(L=>L.loaded),a=Q(L=>L.loading),r=Q(L=>L.loadServers),i=Q(L=>L.addServer),l=Q(L=>L.error),c=A(L=>L.upsertMcpServer),g=s.map(L=>{const h=o.find(H=>H.id===L.id);return{...L,status:h?.status||"disconnected",tools:h?.tools||[],lastError:h?.lastError||void 0,command:h?.command||L.description||"",args:h?.args||[],env:h?.env||{}}}),b=o.filter(L=>!s.some(h=>h.id===L.id)).map(L=>({...L,isRuntimeOnly:!0})),p=[...g,...b],[T,S]=d.useState(!1),[m,j]=d.useState(""),[y,f]=d.useState(""),[N,u]=d.useState(""),[M,F]=d.useState(""),[R,P]=d.useState(!1);d.useEffect(()=>{!n&&!a&&r()},[n,a,r]);const B=d.useCallback(async()=>{if(!(!m.trim()||!y.trim())){P(!0);try{const L=N.split(`
|
|
3
|
+
`).filter(C=>C.trim()).map(C=>C.trim()),h={};M.split(`
|
|
4
|
+
`).forEach(C=>{const[O,...K]=C.split("=");O?.trim()&&K.length>0&&(h[O.trim()]=K.join("=").trim())});const H=await i({name:m.trim(),command:y.trim(),args:L,env:h});H&&c({id:H.id,name:H.name,description:H.command,connected:H.status==="connected"}),j(""),f(""),u(""),F(""),S(!1)}finally{P(!1)}}},[m,y,N,M,i,c]),_={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(ee,{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&&p.map(L=>e.jsx(Pn,{server:L},L.id)),n&&p.length===0&&!T&&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."}),T&&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:m,onChange:L=>j(L.target.value),placeholder:"My MCP Server",className:"nodrag nowheel w-full text-[14px] px-3 py-2 rounded-lg outline-none",style:_})]}),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:y,onChange:L=>f(L.target.value),placeholder:"uv",className:"nodrag nowheel w-full text-[14px] px-3 py-2 rounded-lg outline-none",style:_})]}),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:N,onChange:L=>u(L.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:{..._,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:M,onChange:L=>F(L.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:{..._,minHeight:"60px"},rows:3})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:B,disabled:R||!m.trim()||!y.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||!m.trim()||!y.trim()?.6:1},children:[R?e.jsx(ee,{size:12,className:"animate-spin"}):e.jsx(le,{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&&!T&&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(le,{size:12}),"Add MCP Server"]})})]})}function Bn(){const t=U(),s=Me(N=>N.theme),o=Me(N=>N.toggleTheme),[n,a]=d.useState(()=>localStorage.getItem("modular-edge-style")||"smoothstep"),[r,i]=d.useState(()=>localStorage.getItem("modular-grid-snap")!=="false"),[l,c]=d.useState(()=>localStorage.getItem("modular-minimap")!=="false"),[g,b]=d.useState(()=>localStorage.getItem("modular-bg-style")||"dots"),p=(N,u)=>localStorage.setItem(N,u),T=[{id:"system",label:"System",icon:zs},{id:"light",label:"Light",icon:kt},{id:"dark",label:"Dark",icon:vt}],S=[{id:"smoothstep",label:"SmoothStep",icon:Bs},{id:"bezier",label:"Bezier",icon:We},{id:"step",label:"Step",icon:Rs}],m=[{id:"dots",label:"Dots"},{id:"lines",label:"Lines"},{id:"none",label:"None"}],j={color:t.textMuted,fontFamily:"'Geist Mono', monospace"},y={borderBottom:`1px solid ${t.borderSubtle}`},f=N=>{(N==="light"?"light":"dark")!==s&&o(),p("modular-theme",N)};return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3",style:y,children:[e.jsx("span",{className:"text-[12px] tracking-wider uppercase",style:j,children:"Theme"}),e.jsx("div",{className:"flex gap-1",children:T.map(N=>{const u=N.id==="system"&&s==="dark"&&localStorage.getItem("modular-theme")==="system"||N.id===s;return e.jsxs("button",{type:"button",onClick:()=>f(N.id),className:"nodrag nowheel flex items-center gap-1 text-[13px] px-2.5 py-1 rounded-md cursor-pointer border-none",style:{background:u?"#FE500020":t.badgeBg,color:u?"#FE5000":t.textDim},children:[e.jsx(N.icon,{size:11}),N.label]},N.id)})})]}),e.jsxs("div",{className:"flex items-center justify-between px-4 py-3",style:y,children:[e.jsx("span",{className:"text-[12px] tracking-wider uppercase",style:j,children:"Edge Routing"}),e.jsx("div",{className:"flex gap-1",children:S.map(N=>e.jsxs("button",{type:"button",onClick:()=>{a(N.id),p("modular-edge-style",N.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===N.id?"#FE500020":t.badgeBg,color:n===N.id?"#FE5000":t.textDim},children:[e.jsx(N.icon,{size:11}),N.label]},N.id))})]}),e.jsxs("div",{className:"flex items-center justify-between px-4 py-3",style:y,children:[e.jsx("span",{className:"text-[12px] tracking-wider uppercase",style:j,children:"Grid Snap"}),e.jsx("button",{type:"button",onClick:()=>{const N=!r;i(N),p("modular-grid-snap",String(N))},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:y,children:[e.jsx("span",{className:"text-[12px] tracking-wider uppercase",style:j,children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Os,{size:11})," Minimap"]})}),e.jsx("button",{type:"button",onClick:()=>{const N=!l;c(N),p("modular-minimap",String(N))},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:y,children:[e.jsx("span",{className:"text-[12px] tracking-wider uppercase",style:j,children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Gs,{size:11})," Background"]})}),e.jsx("div",{className:"flex gap-1",children:m.map(N=>e.jsx("button",{type:"button",onClick:()=>{b(N.id),p("modular-bg-style",N.id)},className:"nodrag nowheel text-[13px] px-2.5 py-1 rounded-md cursor-pointer border-none",style:{background:g===N.id?"#FE500020":t.badgeBg,color:g===N.id?"#FE5000":t.textDim},children:N.label},N.id))})]})]})}function Rn({open:t,onClose:s}){const o=U(),n=A(c=>c.activeSettingsTab),[a,r]=d.useState(n||"providers");d.useEffect(()=>{t&&n&&r(n)},[t,n]);const i=d.useRef(null),l=d.useCallback(c=>{if(c.key!=="Tab"||!i.current)return;const g=i.current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(g.length===0)return;const b=g[0],p=g[g.length-1];c.shiftKey?document.activeElement===b&&(c.preventDefault(),p.focus()):document.activeElement===p&&(c.preventDefault(),b.focus())},[]);return d.useEffect(()=>{if(!t)return;const c=g=>{g.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(ce,{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:In.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(Ln,{}),a==="mcp"&&e.jsx(zn,{}),a==="general"&&e.jsx(Bn,{})]})]})]}):null}const Kt="modular-agent-library-v1";function Ge(){return`${Date.now()}-${Math.random().toString(36).slice(2,8)}`}function On(){try{const t=localStorage.getItem(Kt);if(!t)return[];const s=JSON.parse(t);return Array.isArray(s)?s:[]}catch{return[]}}function lt(t){try{localStorage.setItem(Kt,JSON.stringify(t))}catch{}}const Gn=Ae((t,s)=>({agents:[],agentLibrary:On(),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(`${Z}/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 lt(a),{agentLibrary:a}}),removeLibraryAgent:o=>t(n=>{const a=n.agentLibrary.filter(r=>r.id!==o);return lt(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-${Ge()}`;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-${Ge()}`,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-${Ge()}`}]})),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 _n(t){return{...t}}const Kn={"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 Wt(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 me(t){const s=t.channels.filter(y=>y.enabled),o=Kn[t.selectedModel]??t.selectedModel,n=t.agentMeta.name||Qn(t.prompt,s),a=t.agentMeta.description||Zn(t.prompt,s),r=t.skills.filter(y=>y.enabled&&y.added),i=t.mcpServers.filter(y=>y.enabled&&y.added),l=r.map(y=>y.name),c=i.map(y=>({name:y.name,transport:"stdio",command:`npx @${y.name.toLowerCase().replace(/\s+/g,"")}hq/mcp`})),g=s.map(y=>y.path),b=t.outputFormats.length>0?t.outputFormats:[t.outputFormat],p=[],T=Wt(t.instructionState,t.prompt);p.push(T);const S=t.agentConfig?.temperature??.7,m=t.agentConfig?.planningMode??"single-shot",j=[...(t.connectors??[]).filter(y=>y.enabled).map(y=>({service:y.service,direction:y.direction,config:y.config,type:"connector"})),...(t.mcpServers??[]).filter(y=>y.enabled!==!1).map(y=>({service:y.name||y.id,type:"mcp",id:y.id}))];return{name:n,description:a,model:o,icon:t.agentMeta.icon||"brain",category:t.agentMeta.category||"general",temperature:S,planningMode:m,tools:l,mcp_servers:c,reads:g,output_format:b,token_budget:t.tokenBudget,prompt:t.prompt,system:p.join(`
|
|
15
|
+
|
|
16
|
+
`),connections:j}}function ne(t){return t.includes(`
|
|
17
|
+
`)||t.includes(":")||t.includes("#")||t.includes('"')?`"${t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:t}function Wn(t){const s=["---"];if(s.push(`name: ${ne(t.name)}`),s.push(`description: ${ne(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: ${ne(o.name)}`),s.push(` transport: ${o.transport}`),o.command&&s.push(` command: ${ne(o.command)}`)}if(t.reads.length>0){s.push("reads:");for(const o of t.reads)s.push(` - ${ne(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 Un(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 g=`${c+1}. ${l.label}`,b=l.action?` — ${l.action}`:"",p=l.condition!=="always"&&l.conditionText?` (${l.condition} ${l.conditionText})`:"";r.push(`${g}${b}${p}`)});else if(o.length>0){r.push("1. Read all knowledge sources");const l=new Map;for(const g of o){const b=g.knowledgeType;l.has(b)||l.set(b,[]),l.get(b).push(g)}let c=2;for(const[g,b]of l){const p=is[g];if(p){const T=b.map(S=>S.name).join(", ");r.push(`${c}. Process ${p.label.toLowerCase()} sources: ${T}`),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=>ls.find(g=>g.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 Ut(t){const s=me(t),o=Wn(s),n=Un(s,t);return o+`
|
|
25
|
+
`+n}function Ht(t){const s=me(t),o=[];if(o.push(`name: ${ne(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: ${ne(a.command)}`)}if(s.reads.length>0){o.push("context_files:");for(const a of s.reads)o.push(` - ${ne(a)}`)}const n=Wt(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 Hn(t){const s=me(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 Vn(t){const s=me(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 qn(t){const s=me(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: ${ne(a.command)}`)}}if(s.reads.length>0){n.push(" context:");for(const a of s.reads)n.push(` - ${ne(a)}`)}return n.join(`
|
|
29
|
+
`)+`
|
|
30
|
+
`}function Yn(t){const s=me(t),o=t.outputTemplateConfig?Object.fromEntries(Object.entries(t.outputTemplateConfig).map(([r,i])=>[r,_n(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 Ho(t){return Ut(t)}function Vo(t){return Ht(t)}function Vt(t,s){switch(t){case"claude":return Ut(s);case"amp":return Ht(s);case"codex":return Hn(s);case"vibe-kanban":return Vn(s);case"openclaw":return qn(s);case"generic":return Yn(s)}}const qt={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 Yt(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 Jn(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=Vt(n,t),r=qt[n],i=n==="claude"?s:`${s}-${n}`;Yt(a,i,r.ext)}}function Qn(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 Zn(t,s){return t&&t.length>10?t.length>80?t.slice(0,77)+"...":t:`Analysis using ${s.length} sources via Modular`}function Xn(){const t=A.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}))}),Te(s)}function Te(t,s=0){const o=" ".repeat(s);return Array.isArray(t)?t.map(n=>`${o}- ${Te(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
|
+
${Te(a,s+1)}`;if(typeof a=="object")return`${o}${n}:
|
|
33
|
+
${Te(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 ct=[{id:"brain",Icon:Ye},{id:"code",Icon:Mt},{id:"search",Icon:ue},{id:"bar-chart-3",Icon:Tt},{id:"pen-tool",Icon:Ct},{id:"file-text",Icon:De},{id:"globe",Icon:St},{id:"layers",Icon:Us},{id:"zap",Icon:ve},{id:"database",Icon:Je},{id:"shield",Icon:wt},{id:"settings",Icon:bt},{id:"sparkles",Icon:Pe},{id:"target",Icon:jt},{id:"book-open",Icon:Et},{id:"lightbulb",Icon:Dt},{id:"terminal",Icon:ke},{id:"box",Icon:Qe},{id:"layout-grid",Icon:Lt},{id:"cpu",Icon:Le}],eo=["coding","research","analysis","writing","data","design","domain-specific","general"],dt=[{id:"claude",name:"Claude Code",ext:".md",Icon:ke},{id:"amp",name:"Amp",ext:".yaml",Icon:ve},{id:"codex",name:"Codex",ext:".json",Icon:Le},{id:"vibe-kanban",name:"Vibe Kanban",ext:".json",Icon:Lt},{id:"openclaw",name:"OpenClaw",ext:".yaml",Icon:Pt},{id:"generic",name:"Generic JSON",ext:".json",Icon:Qe}];function to(){const t=A(w=>w.showSaveModal),s=A(w=>w.setShowSaveModal),o=A(w=>w.agentMeta),n=A(w=>w.setAgentMeta),a=A(w=>w.channels),r=A(w=>w.selectedModel),i=A(w=>w.outputFormat),l=A(w=>w.outputFormats),c=A(w=>w.prompt),g=A(w=>w.tokenBudget),b=A(w=>w.mcpServers),p=A(w=>w.skills),T=A(w=>w.exportTarget),S=A(w=>w.setExportTarget),m=A(w=>w.agentConfig),j=A(w=>w.connectors),y=A(w=>w.instructionState),f=A(w=>w.workflowSteps),N=Gn(w=>w.upsertLibraryAgent),[u,M]=d.useState(!1),[F,R]=d.useState(!1),[P,B]=d.useState(!0),_=d.useRef(null),L=d.useRef(null),h=U(),H=d.useCallback(w=>{if(w.key!=="Tab"||!L.current)return;const G=L.current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(G.length===0)return;const k=G[0],W=G[G.length-1];w.shiftKey?document.activeElement===k&&(w.preventDefault(),W.focus()):document.activeElement===W&&(w.preventDefault(),k.focus())},[]);d.useEffect(()=>{t?(R(!0),setTimeout(()=>_.current?.focus(),100)):R(!1)},[t]),d.useEffect(()=>{if(!t)return;const w=G=>{G.key==="Escape"&&s(!1)};return window.addEventListener("keydown",w),()=>window.removeEventListener("keydown",w)},[t,s]);const C=d.useMemo(()=>({channels:a,selectedModel:r,outputFormat:i,outputFormats:l,prompt:c,tokenBudget:g,mcpServers:b,skills:p,agentMeta:o,agentConfig:m,connectors:j,instructionState:y,workflowSteps:f}),[a,r,i,l,c,g,b,p,o,m,j,y,f]),O=d.useMemo(()=>Vt(T,C),[C,T]),K=w=>{B(!1),S(w),setTimeout(()=>B(!0),30)},x=()=>{const w=o.name||"modular-agent",G=w.toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,"");N({id:G,name:w,description:o.description||"Saved from builder",avatar:o.avatar||"bot",version:"1.0.0",mcpServerIds:b.filter(V=>V.added).map(V=>V.id),skillIds:p.filter(V=>V.added).map(V=>V.id)});const k=cs();fetch(`${Z}/agents/${encodeURIComponent(G)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(k)}).catch(()=>{});const W=qt[T];Yt(O,G,W.ext)},v=async()=>{await navigator.clipboard.writeText(O),M(!0),setTimeout(()=>M(!1),2e3)},E=()=>{Jn(C)},z=()=>{const w=Xn(),k=(o.name||"modular-agent").toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,""),W=new Blob([w],{type:"text/yaml;charset=utf-8"}),V=URL.createObjectURL(W),J=document.createElement("a");J.href=V,J.download=`${k}.yaml`,document.body.appendChild(J),J.click(),document.body.removeChild(J),URL.revokeObjectURL(V)};if(!t)return null;const D=ct.find(w=>w.id===o.icon),I=dt.find(w=>w.id===T);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:F?1:0,transition:"opacity 0.15s ease"}}),e.jsxs("div",{ref:L,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:h.surface,border:`1px solid ${h.border}`,boxShadow:"0 24px 48px rgba(0,0,0,0.4)",opacity:F?1:0,transform:F?"scale(1)":"scale(0.97)",transition:"opacity 0.15s ease, transform 0.15s ease"},onClick:w=>w.stopPropagation(),onKeyDown:H,children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3.5",style:{borderBottom:`1px solid ${h.borderSubtle}`},children:[e.jsx("span",{className:"text-[14px] font-bold tracking-[3px] uppercase",style:{fontFamily:"'Geist Mono', monospace",color:h.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:h.textMuted},"aria-label":"Close",children:e.jsx(ce,{size:16})})]}),e.jsx("div",{className:"flex gap-2 px-5 py-3",style:{borderBottom:`1px solid ${h.borderSubtle}`},children:dt.map(w=>{const G=T===w.id;return e.jsxs("button",{type:"button",onClick:()=>K(w.id),className:"flex flex-col items-center gap-1 rounded-lg cursor-pointer border-none",style:{width:80,padding:"8px 4px",background:G?"#FE500012":"transparent",border:G?"1.5px solid #FE5000":`1.5px solid ${h.borderSubtle}`,transition:"all 0.12s ease"},children:[e.jsx(w.Icon,{size:18,style:{color:G?"#FE5000":h.textMuted}}),e.jsx("span",{className:"text-[12px] font-semibold leading-tight text-center",style:{fontFamily:"'Geist Mono', monospace",color:G?"#FE5000":h.textSecondary},children:w.name}),e.jsx("span",{className:"text-[13px] px-1.5 py-0.5 rounded",style:{fontFamily:"'Geist Mono', monospace",background:G?"#FE500020":h.badgeBg,color:G?"#FE5000":h.textDim},children:w.ext})]},w.id)})}),e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[e.jsxs("div",{className:"flex flex-col",style:{width:340,borderRight:`1px solid ${h.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:h.textMuted,fontFamily:"'Geist Mono', monospace"},children:"Agent Name"}),e.jsx("input",{ref:_,type:"text",value:o.name,onChange:w=>n({name:w.target.value}),placeholder:"my-analysis-agent",className:"w-full outline-none text-[17px] rounded-lg px-3 py-2 nodrag",style:{background:h.inputBg,border:`1px solid ${h.border}`,color:h.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:h.textMuted,fontFamily:"'Geist Mono', monospace"},children:"Description"}),e.jsx("textarea",{value:o.description,onChange:w=>n({description:w.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:h.inputBg,border:`1px solid ${h.border}`,color:h.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:h.textMuted,fontFamily:"'Geist Mono', monospace"},children:"Icon"}),e.jsx("div",{className:"grid grid-cols-10 gap-1",children:ct.map(({id:w,Icon:G})=>e.jsx("button",{type:"button",onClick:()=>n({icon:w}),className:"flex items-center justify-center w-7 h-7 rounded-md cursor-pointer border-none",style:{background:o.icon===w?"#FE500020":"transparent",border:o.icon===w?"1px solid #FE500040":"1px solid transparent",color:o.icon===w?"#FE5000":h.textMuted,transition:"all 0.1s ease"},children:e.jsx(G,{size:14})},w))})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{className:"text-[13px] font-semibold uppercase tracking-wider",style:{color:h.textMuted,fontFamily:"'Geist Mono', monospace"},children:"Category"}),e.jsx("select",{value:o.category,onChange:w=>n({category:w.target.value}),className:"w-full outline-none text-[17px] rounded-lg px-3 py-2 cursor-pointer",style:{background:h.inputBg,border:`1px solid ${h.border}`,color:h.textPrimary,fontFamily:"'Geist Sans', sans-serif"},children:eo.map(w=>e.jsx("option",{value:w,children:w.charAt(0).toUpperCase()+w.slice(1).replace("-"," ")},w))})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 px-5 py-4",style:{borderTop:`1px solid ${h.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(At,{size:13}),"Download"]}),e.jsxs("button",{type:"button",onClick:v,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 ${h.border}`,color:u?h.statusSuccess:h.textSecondary,transition:"color 0.15s ease"},children:[u?e.jsx(X,{size:13}):e.jsx(zt,{size:13}),u?"Copied":"Copy"]})]}),e.jsxs("button",{type:"button",onClick:E,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 ${h.borderSubtle}`,color:h.textMuted},children:[e.jsx(Pt,{size:13}),"Export All Targets"]}),e.jsxs("button",{type:"button",onClick:z,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 ${h.borderSubtle}`,color:h.textMuted},children:[e.jsx(De,{size:13}),"Export as YAML"]})]})]}),e.jsxs("div",{className:"flex flex-col flex-1",style:{background:h.isDark?"#0d0d10":"#f5f5f8"},children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3",style:{borderBottom:`1px solid ${h.borderSubtle}`},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[D&&e.jsx(D.Icon,{size:14,style:{color:"#FE5000"}}),e.jsx("span",{className:"text-[14px] font-bold tracking-[2px] uppercase",style:{fontFamily:"'Geist Mono', monospace",color:h.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:h.textDim},children:[O.split(`
|
|
36
|
+
`).length," lines"]})]}),e.jsx("div",{className:"flex-1 overflow-auto p-4",style:{opacity:P?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:h.textSecondary},children:O.split(`
|
|
37
|
+
`).map((w,G)=>e.jsxs("div",{className:"flex",children:[e.jsx("span",{className:"inline-block text-right select-none shrink-0",style:{width:32,color:h.textFaint,marginRight:12},children:G+1}),e.jsx("span",{style:{color:so(w,T,h)},children:w||" "})]},G))})})]})]})]})]})}function so(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 _e=d.forwardRef(function({variant:s="secondary",size:o="md",icon:n,iconRight:a,loading:r,children:i,className:l="",style:c,disabled:g,...b},p){const T=U(),S={sm:28,md:32},m={sm:"0 8px",md:"0 14px"},j={sm:12,md:13},f={primary:{bg:"#FE5000",color:"#fff",border:"transparent",hoverBg:"#e54700"},secondary:{bg:T.surfaceElevated,color:T.textSecondary,border:T.border,hoverBg:T.isDark?"#2a2a30":"#eee"},ghost:{bg:"transparent",color:T.textSecondary,border:"transparent",hoverBg:T.isDark?"#ffffff08":"#00000008"},danger:{bg:T.statusErrorBg,color:T.statusError,border:"transparent",hoverBg:T.isDark?"#ff4d4f20":"#ff4d4f15"}}[s];return e.jsxs("button",{ref:p,type:"button",disabled:g||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:m[o],fontSize:j[o],fontFamily:"'Geist Mono', monospace",background:f.bg,color:f.color,borderColor:f.border,opacity:g?.5:1,cursor:g?"not-allowed":"pointer",transition:"background 0.15s, opacity 0.15s",...c},onMouseEnter:N=>{g||(N.currentTarget.style.background=f.hoverBg)},onMouseLeave:N=>{N.currentTarget.style.background=f.bg},...b,children:[r?e.jsx("span",{className:"animate-spin text-[12px]",children:"⟳"}):n,i,a]})});function ut({icon:t,title:s,subtitle:o,action:n,className:a=""}){const r=U();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 Jt({size:t="md",className:s=""}){const o=U(),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 no({open:t,onClose:s,title:o,children:n,footer:a,width:r=520}){const i=U(),l=d.useRef(null);return d.useEffect(()=>{if(!t)return;const c=g=>{g.key==="Escape"&&s()};return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[t,s]),d.useEffect(()=>{t&&l.current?.focus()},[t]),t?$e.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(ce,{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 oo({options:t,value:s,onChange:o,label:n,placeholder:a="Select...",size:r="md"}){const i=U(),[l,c]=d.useState(!1),[g,b]=d.useState({x:0,y:0,w:0}),p=d.useRef(null),T=t.find(j=>j.value===s),S={sm:28,md:32};d.useEffect(()=>{if(!l)return;const j=()=>c(!1);return document.addEventListener("click",j),()=>document.removeEventListener("click",j)},[l]);const m=()=>{if(!p.current)return;const j=p.current.getBoundingClientRect();b({x:j.left,y:j.bottom+4,w:j.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:p,type:"button",onClick:j=>{j.stopPropagation(),m()},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:T?i.textPrimary:i.textMuted},children:[e.jsxs("span",{className:"flex items-center gap-1.5 truncate",children:[T?.icon,T?.label||a]}),e.jsx(ae,{size:12,style:{color:i.textDim,transform:l?"rotate(180deg)":"none",transition:"transform 0.15s"}})]}),l&&$e.createPortal(e.jsx("div",{className:"fixed z-[250] rounded-lg overflow-hidden py-1",style:{left:g.x,top:g.y,width:g.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:j=>j.stopPropagation(),children:t.map(j=>e.jsxs("button",{type:"button",onClick:()=>{o(j.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:j.value===s?"#FE5000":i.textSecondary,background:j.value===s?"#FE500008":"transparent"},onMouseEnter:y=>y.currentTarget.style.background=i.isDark?"#ffffff08":"#00000005",onMouseLeave:y=>y.currentTarget.style.background=j.value===s?"#FE500008":"transparent",children:[j.icon,e.jsx("span",{className:"flex-1 truncate",children:j.label}),j.value===s&&e.jsx(X,{size:10})]},j.value))}),document.body)]})}const pt="rgba(99,102,241,0.4)",Ke="#6366f1",mt="rgba(99,102,241,0.12)";function ro({id:t,name:s,description:o,tags:n,onUse:a}){const r=U(),i={background:r.surfaceOpaque,border:`1px dashed ${pt}`,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=Ke},onMouseLeave:l=>{l.currentTarget.style.borderColor=pt},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:mt},children:e.jsx(Pe,{size:14,style:{color:Ke}})}),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:mt,color:Ke,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 ao=[{value:"modified",label:"Last Modified"},{value:"name",label:"Name (A–Z)"},{value:"created",label:"Created"}],ft=Object.entries(ds).map(([t,s])=>({id:t,name:s.agentMeta.name,description:s.agentMeta.description,tags:s.agentMeta.tags}));let io=0;function lo({onSelectAgent:t,onNewAgent:s}){const[o,n]=d.useState([]),[a,r]=d.useState(!0),[i,l]=d.useState(null),[c,g]=d.useState(""),[b,p]=d.useState(""),[T,S]=d.useState("modified"),[m,j]=d.useState(null),[y,f]=d.useState(null),[N,u]=d.useState(null),[M,F]=d.useState([]),R=d.useRef(null),P=U();d.useEffect(()=>(R.current&&clearTimeout(R.current),R.current=setTimeout(()=>p(c),300),()=>{R.current&&clearTimeout(R.current)}),[c]);const B=d.useCallback((v,E)=>{const z=++io;F(D=>[...D,{id:z,type:v,message:E}]),setTimeout(()=>F(D=>D.filter(I=>I.id!==z)),3500)},[]),_=d.useCallback(v=>{const{loadDemoPreset:E}=A.getState();E(v),s()},[s]),L=d.useMemo(()=>{const v=b.trim().toLowerCase();return v?ft.filter(E=>E.name.toLowerCase().includes(v)||E.description.toLowerCase().includes(v)):ft},[b]),h=d.useCallback(async()=>{try{r(!0),l(null);const v=await fetch(`${Z}/agents`);if(!v.ok)throw new Error("Failed to load agents");const E=await v.json(),z=E.data??E??[];n(z.map(D=>({id:D.id,name:D.agentMeta?.name||D.id,description:D.agentMeta?.description||"",avatar:D.agentMeta?.avatar||"",tags:D.agentMeta?.tags||[],updatedAt:D.savedAt||new Date().toISOString()})))}catch(v){l(v instanceof Error?v.message:"Unknown error")}finally{r(!1)}},[]);d.useEffect(()=>{h()},[h]);const H=()=>{const{resetAgent:v}=A.getState();v(),s()},C=async()=>{if(m){f(m.id),j(null);try{if(!(await fetch(`${Z}/agents/${encodeURIComponent(m.id)}`,{method:"DELETE"})).ok)throw new Error("Delete failed");n(E=>E.filter(z=>z.id!==m.id)),B("success",`"${m.name}" deleted`)}catch{B("error",`Failed to delete "${m.name}"`)}finally{f(null)}}},O=async(v,E)=>{E.stopPropagation(),u(v.id);try{const z=await fetch(`${Z}/agents/${encodeURIComponent(v.id)}`);if(!z.ok)throw new Error("Failed to load agent");const D=await z.json(),I=D.data??D,w=`agent-${Date.now()}`,G={...I,id:w,savedAt:new Date().toISOString(),agentMeta:{...I.agentMeta,name:`${I.agentMeta?.name||v.name} (Copy)`}};if(!(await fetch(`${Z}/agents`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(G)})).ok)throw new Error("Failed to save clone");B("success",`Cloned as "${G.agentMeta.name}"`),t(w)}catch{B("error",`Failed to clone "${v.name}"`)}finally{u(null)}},K=d.useMemo(()=>{const v=b.trim().toLowerCase();let E=v?o.filter(z=>z.name.toLowerCase().includes(v)||z.description.toLowerCase().includes(v)):o;return T==="name"?E=[...E].sort((z,D)=>z.name.localeCompare(D.name)):T==="modified"?E=[...E].sort((z,D)=>new Date(D.updatedAt).getTime()-new Date(z.updatedAt).getTime()):T==="created"&&(E=[...E].sort((z,D)=>{const I=parseInt(z.id.replace("agent-",""))||0,w=parseInt(D.id.replace("agent-",""))||0;return I-w})),E},[o,b,T]),x=v=>{const E=new Date(v),D=Math.floor((new Date().getTime()-E.getTime())/(1e3*60*60));return D<1?"Just now":D<24?`${D}h ago`:D<168?`${Math.floor(D/24)}d ago`:E.toLocaleDateString()};return a?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(Jt,{size:"lg"})}):i?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(ut,{icon:e.jsx(nt,{size:32}),title:"Failed to Load Agents",subtitle:i})}):e.jsxs("div",{className:"flex flex-col h-full overflow-hidden",style:{background:P.bg},children:[e.jsxs("div",{className:"px-6 py-4 border-b",style:{borderColor:P.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:P.textPrimary},children:"Agent Library"}),e.jsx("p",{className:"text-sm",style:{color:P.textSecondary},children:"Build, test, and export AI agents with full context engineering."})]}),e.jsxs(_e,{onClick:H,variant:"primary",size:"md",title:"Create new agent",className:"flex items-center gap-2",children:[e.jsx(le,{size:16}),"New Agent"]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ue,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none",style:{color:P.textDim}}),e.jsx("input",{type:"text",placeholder:"Search agents…",value:c,onChange:v=>g(v.target.value),className:"w-full pl-8 pr-3 py-1.5 rounded-lg outline-none",style:{background:P.inputBg,border:`1px solid ${P.border}`,color:P.textPrimary,fontFamily:"'Geist Sans', sans-serif",fontSize:13}})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx(Hs,{size:12,style:{color:P.textDim}}),e.jsx("div",{style:{width:160},children:e.jsx(oo,{options:ao,value:T,onChange:S,size:"sm"})})]})]})]}),e.jsx("div",{className:"flex-1 overflow-auto p-6",children:L.length===0&&K.length===0?e.jsx(ut,{icon:e.jsx(ue,{size:32}),title:"No results match your search",subtitle:`No results for "${b}" — try a different keyword`}):e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[L.map(v=>e.jsx(ro,{...v,onUse:_},v.id)),K.map(v=>e.jsx("div",{role:"button",tabIndex:0,title:`Open ${v.name}`,className:"cursor-pointer rounded-lg overflow-hidden transition-all duration-200 hover:shadow-lg",onClick:()=>t(v.id),onKeyDown:E=>{(E.key==="Enter"||E.key===" ")&&t(v.id)},style:{background:P.surfaceOpaque,border:`1px solid ${P.border}`,boxShadow:`0 2px 8px ${P.isDark?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.06)"}`},onMouseEnter:E=>{E.currentTarget.style.borderColor="#FE5000"},onMouseLeave:E=>{E.currentTarget.style.borderColor=P.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(nt,{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:P.textPrimary,fontFamily:"'Geist Sans', sans-serif"},children:v.name}),e.jsx("p",{className:"text-sm line-clamp-2",style:{color:P.textSecondary},children:v.description||"No description"})]})]}),v.tags&&v.tags.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 mb-3",children:[v.tags.slice(0,3).map(E=>e.jsx("span",{className:"text-[11px] px-1.5 py-0.5 rounded",style:{background:P.surfaceElevated,color:P.textDim,fontFamily:"'Geist Mono', monospace"},children:E},E)),v.tags.length>3&&e.jsxs("span",{className:"text-[11px] px-1.5 py-0.5 rounded",style:{background:P.surfaceElevated,color:P.textFaint},children:["+",v.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:P.textDim},children:[e.jsx(Vs,{size:12}),e.jsx("span",{style:{fontFamily:"'Geist Mono', monospace"},children:x(v.updatedAt)})]}),e.jsxs("div",{className:"flex items-center gap-1",onClick:E=>E.stopPropagation(),children:[e.jsx("button",{type:"button",title:"Clone agent",disabled:N===v.id,onClick:E=>O(v,E),className:"flex items-center justify-center w-6 h-6 rounded cursor-pointer border-none bg-transparent transition-colors",style:{color:N===v.id?P.textFaint:P.textDim},onMouseEnter:E=>{E.currentTarget.style.color="#FE5000"},onMouseLeave:E=>{E.currentTarget.style.color=N===v.id?P.textFaint:P.textDim},children:N===v.id?e.jsx("span",{className:"animate-spin text-[10px]",children:"⟳"}):e.jsx(zt,{size:13})}),e.jsx("button",{type:"button",title:"Delete agent",disabled:y===v.id,onClick:E=>{E.stopPropagation(),j(v)},className:"flex items-center justify-center w-6 h-6 rounded cursor-pointer border-none bg-transparent transition-colors",style:{color:y===v.id?P.textFaint:P.textDim},onMouseEnter:E=>{E.currentTarget.style.color="#ff4d4f"},onMouseLeave:E=>{E.currentTarget.style.color=y===v.id?P.textFaint:P.textDim},children:y===v.id?e.jsx("span",{className:"animate-spin text-[10px]",children:"⟳"}):e.jsx(Xe,{size:13})})]})]})]})},v.id))]})}),e.jsx(no,{open:!!m,onClose:()=>j(null),title:"Delete Agent",width:400,footer:e.jsxs(e.Fragment,{children:[e.jsx(_e,{variant:"secondary",size:"sm",onClick:()=>j(null),children:"Cancel"}),e.jsx(_e,{variant:"danger",size:"sm",onClick:C,children:"Delete"})]}),children:e.jsxs("div",{className:"px-4 py-4 text-sm",style:{color:P.textSecondary},children:["Are you sure you want to delete"," ",e.jsxs("span",{className:"font-semibold",style:{color:P.textPrimary},children:['"',m?.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:M.map(v=>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:P.surfaceOpaque,border:`1px solid ${v.type==="success"?"#22c55e40":"#ff4d4f40"}`,color:P.textPrimary,boxShadow:`0 4px 16px ${P.isDark?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)"}`,fontFamily:"'Geist Sans', sans-serif"},children:[v.type==="success"?e.jsx(Ue,{size:15,style:{color:"#22c55e",flexShrink:0}}):e.jsx(He,{size:15,style:{color:"#ff4d4f",flexShrink:0}}),v.message]},v.id))})]})}const co={full:0,detail:1,summary:2,headlines:3,mention:4},uo={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"},xt=new Set(["markdown","html-slides","email","code","csv","json","diagram","slack"]);function po(t){const s=t.trim();return s.startsWith("{")?mo(s):s.startsWith("---")?fo(s):xo(s)}function mo(t){let s;try{s=JSON.parse(t)}catch{return{}}if(s.modular_version&&s.agent){const n=s.agent,a=re({...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=re({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=re({...s,system:s.instructions,reads:s.context_files||s.reads});return n.detectedFormat="codex",n}const o=re(s);return o.detectedFormat="generic",o}function fo(t){const{frontmatter:s,body:o}=go(t),n=re(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=yo(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 xo(t){const s=Qt(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=re({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=re({...s,system:s.instructions,reads:s.context_files});return n.detectedFormat="amp",n}const o=re(s);return o.detectedFormat="amp",o}function re(t){const s={},o={name:te(t.name)||"",description:te(t.description)||"",icon:te(t.icon)||"brain",category:te(t.category)||"general",tags:Array.isArray(t.tags)?t.tags:[],avatar:te(t.avatar)||""};if(s.agentMeta=o,t.model){const r=te(t.model);s.selectedModel=uo[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=>xt.has(i));r.length>0&&(s.outputFormat=r[0])}else if(t.output_format){const r=te(t.output_format);xt.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?Ee(l.path):Ee(r),enabled:!0,depth:0,baseTokens:l?.tokenEstimate??5e3}})),!s.channels&&n?.channels&&(s.channels=n.channels.map((r,i)=>{const l=ho(r.type)?r.type:Ee(r.path),c=co[r.depth?.toLowerCase()]??0,g=(r.path,void 0);return{sourceId:g?.id??`imported-${i}`,name:g?.name??r.path.split("/").filter(Boolean).pop()??r.path,path:r.path,category:g?.category??"knowledge",knowledgeType:l,enabled:!0,depth:c,baseTokens:g?.tokenEstimate??5e3}})),!s.prompt&&t.system&&(s.prompt=te(t.system)),t.prompt&&(s.prompt=te(t.prompt));const a=te(t.system);if(a){const r=bo(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 te(t){return typeof t=="string"?t:t==null?"":String(t)}function go(t){const s=t.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);return s?{frontmatter:Qt(s[1]),body:s[2]}:{frontmatter:{},body:t}}function Qt(t){const s={},o=t.split(`
|
|
38
|
+
`);let n="",a=null,r=null,i=null,l="",c=0,g=[];const b=()=>{if(l&&g.length>0){const p=a||s;p[l]=g.join(`
|
|
39
|
+
`),l="",g=[]}};for(const p of o){if(l)if(p.search(/\S/)>=c&&p.trim()!==""){g.push(p.slice(c));continue}else b();const T=p.match(/^(\w[\w_-]*)\s*:\s*(.*)$/);if(T){i&&r&&(r.push(i),i=null),r=null,a=null;const S=T[1],m=T[2].trim();m===""||m==="|"?m==="|"?(l=S,c=2,g=[]):(n=S,a={},s[S]=a):m.startsWith("[")&&m.endsWith("]")?s[S]=m.slice(1,-1).split(",").map(j=>j.trim()).filter(Boolean):s[S]=ie(m);continue}if(a){const S=p.match(/^ (\w[\w_-]*)\s*:\s*(.*)$/);if(S){i&&r&&(r.push(i),i=null);const m=S[1],j=S[2].trim();j===""||j==="|"?j==="|"?(l=m,c=4,g=[]):(r=[],a[m]=r):(r=null,a[m]=ie(j));continue}if(r){const m=p.match(/^ - (.+)$/);if(m&&!m[1].includes(":")){i&&(r.push(i),i=null),r.push(ie(m[1].trim()));continue}}if(r){const m=p.match(/^ - (\w[\w_-]*)\s*:\s*(.*)$/);if(m){i&&r.push(i),i={[m[1]]:ie(m[2])};continue}const j=p.match(/^ (\w[\w_-]*)\s*:\s*(.*)$/);if(j&&i){i[j[1]]=ie(j[2]);continue}}}if(!a){const S=p.match(/^ - (.+)$/);if(S&&r){if(!S[1].includes(":"))r.push(ie(S[1].trim()));else{const j=S[1].match(/^(\w[\w_-]*)\s*:\s*(.*)$/);j&&(i&&r.push(i),i={[j[1]]:ie(j[2])})}continue}const m=p.match(/^(\w[\w_-]*)\s*:$/);if(m){n=m[1],r=[],s[n]=r;continue}}}return b(),i&&r&&r.push(i),s}function ie(t){return t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1):t}function ho(t){return["ground-truth","signal","evidence","framework","hypothesis","guideline"].includes(t)}function yo(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:Ee(i),enabled:!0,depth:0,baseTokens:5e3}),n++)}}return s}function bo(t){const s=t.replace(/\r\n/g,`
|
|
41
|
+
`).trim();if(!s)return{persona:"",constraints:"",objective:""};const o=s.split(/\n\s*\n/).map(f=>f.trim()).filter(Boolean),a=s.split(`
|
|
42
|
+
`).map(f=>f.trim()).filter(Boolean).map(f=>{const N=f.match(/^[-*]\s+(.+)$/);if(N)return N[1].trim();const u=f.match(/^\d+\.\s+(.+)$/);return u?u[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(f=>r.test(f)),c=a.filter(f=>!r.test(f)&&i.test(f)),g=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),b=s.match(/(?:^|\n)(?:#+\s*)?(?:constraint|constraints|guardrails|rules)\s*:?\s*\n?([\s\S]*?)(?=\n(?:#+\s*)?[A-Za-z][^\n]*:\s*|\n\s*\n|$)/i),p=g?.[1]?.split(`
|
|
43
|
+
`).map(f=>f.replace(/^[-*]\s+/,"").trim()).find(Boolean)??"",T=b?.[1]?.split(`
|
|
44
|
+
`).map(f=>f.replace(/^[-*]\s+/,"").trim()).filter(Boolean).join(`
|
|
45
|
+
`)??"",m=(o.find(f=>{const N=f.toLowerCase();return!(/^(constraints?|guardrails?|rules|objectives?|goals?|mission)\s*:/.test(N)||i.test(f)||r.test(f))})??o[0]??"").split(new RegExp("(?<=[.!?])\\s+")).map(f=>f.trim()).find(Boolean)??"",j=p||c[0]||o.find(f=>i.test(f))||"",y=T||l.join(`
|
|
46
|
+
`);return{persona:m,constraints:y,objective:typeof j=="string"?j.trim():""}}const ko=d.forwardRef(function({label:s,labelAction:o,error:n,showCount:a,maxChars:r,value:i,className:l="",style:c,...g},b){const p=U(),T=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:p.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&&T>r?p.statusError:p.textFaint},children:[T,r?` / ${r}`:""]}),o]})]}),e.jsx("textarea",{ref:b,value:i,className:`w-full px-3 py-2.5 rounded-md outline-none resize-none nowheel nodrag ${l}`,style:{background:p.inputBg,border:`1px solid ${n?p.statusError:p.border}`,color:p.textPrimary,fontFamily:"'Geist Sans', sans-serif",fontSize:16,lineHeight:1.5,minHeight:64,...c},...g}),n&&e.jsx("span",{className:"text-[13px]",style:{color:p.statusError},children:n})]})});function vo(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 wo(t,s,o,n){if(!t.trim())throw new Error("Describe the agent you want to build");const a=se.getState(),r=a.providers.filter(F=>(F.status==="connected"||F.status==="configured")&&Array.isArray(F.models)&&F.models.length>0),i=a.providers.find(F=>F.id===a.selectedProviderId&&r.includes(F))||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 g=i.authMethod==="claude-agent-sdk",b=s?.filter(F=>F.added).map(F=>F.id)||[],p=o?.filter(F=>F.added).map(F=>F.id)||[],T=b.length>0?ye.filter(F=>b.includes(F.id)):[],S=p.length>0?us.filter(F=>p.includes(F.id)):[],m=T.length>0?T.map(F=>`${F.id}: ${F.description}`).join(`
|
|
140
|
+
`):"none",j=S.length>0?S.map(F=>`${F.id}: ${F.description}`).join(`
|
|
141
|
+
`):"none",y=n||[],f=y.length>0?y.map(F=>`- sourceId: "${F.sourceId}" | name: "${F.name}" | path: "${F.path||"(no path)"}" | type: ${F.knowledgeType||"unclassified"} | tokens: ${F.baseTokens} | depth: ${F.depth}`).join(`
|
|
142
|
+
`):"No knowledge sources connected yet. Suggest what the user should add in knowledgeGaps.",N=vo(m,j,f),u=g?await ps({prompt:t,model:c,systemPrompt:N,maxTurns:1}):await ms({providerId:i.id,model:c,messages:[{role:"system",content:N},{role:"user",content:t}],temperature:.4,maxTokens:4096});let M;try{M=JSON.parse(u)}catch{}if(!M){const F=u.match(/```(?:json)?\s*([\s\S]*?)```/);if(F)try{M=JSON.parse(F[1].trim())}catch{}}if(!M){const F=u.match(/\{[\s\S]*\}/);if(F)try{M=JSON.parse(F[0])}catch{}}if(!M)throw new Error("Could not parse generated agent config");return jo(M,y),M}function jo(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 g=c.repoMeta,b=g.stack.length>0?g.stack.join(", "):"unknown stack";return`${g.name} (${b})`});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 So={"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 Co(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,g]of Object.entries(So))if(!a.has(c)){for(const b of g)if(n.includes(b)){const p=r.find(T=>T.id===c);if(p){i.push({source:p,reason:`Prompt mentions "${b}"`});break}}}if(s.length>0){const c=s.some(p=>p.knowledgeType==="ground-truth"&&p.enabled),g=s.some(p=>p.knowledgeType==="signal"&&p.enabled),b=s.some(p=>p.knowledgeType==="evidence"&&p.enabled);if(!c&&!a.has("knowledge-products")){const p=r.find(T=>T.id==="knowledge-products");p&&i.push({source:p,reason:"No Ground Truth — add Products?"})}if(g&&!b&&!a.has("intel-competitive")){const p=r.find(T=>T.id==="intel-competitive");p&&i.push({source:p,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 Ce=[{label:"Code Review Agent",description:"Reviews code for best practices, security, and maintainability",prompt:"A code review agent that analyzes pull requests and provides detailed feedback on code quality, security vulnerabilities, performance issues, and adherence to coding standards. Should use framework sources for style guides and ground-truth for API documentation.",knowledgeDefaults:{type:"Ground Truth",depth:"High"},memoryStrategy:"sliding_window",constraints:{neverMakeUp:!0,askBeforeActions:!1,stayInScope:!0,useOnlyTools:!0,customConstraints:"Focus on code quality, security, and maintainability. Always cite specific line numbers and files when providing feedback."}},{label:"Research Assistant",description:"Gathers and synthesizes information from multiple sources",prompt:"A research assistant that collects information from various sources, synthesizes findings, and produces comprehensive reports. Uses evidence and signal sources to gather data, with broad exploration capabilities for discovering relevant information.",knowledgeDefaults:{type:"Evidence",depth:"Broad"},memoryStrategy:"rag",constraints:{neverMakeUp:!0,askBeforeActions:!0,stayInScope:!1,useOnlyTools:!1,customConstraints:"Provide comprehensive sources and citations. Synthesize information from multiple perspectives."}},{label:"Content Writer",description:"Creates engaging content following brand guidelines",prompt:"A content writing agent that produces high-quality articles, blog posts, and marketing copy. Uses framework sources for brand voice and style guidelines, ground-truth for factual information, and hypothesis sources for creative content development.",knowledgeDefaults:{type:"Framework",depth:"Medium"},memoryStrategy:"summarize_and_recent",constraints:{neverMakeUp:!1,askBeforeActions:!0,stayInScope:!0,useOnlyTools:!1,customConstraints:"Follow brand voice guidelines. Ensure content is engaging and on-brand."}},{label:"Product Manager",description:"Analyzes market data and creates product roadmaps",prompt:"A product management agent that tracks competitor analysis, user feedback, and market trends. Creates weekly reports, manages roadmaps, and provides strategic recommendations. Integrates with tools like GitHub for technical insights and Notion for documentation.",knowledgeDefaults:{type:"Signal",depth:"High"},memoryStrategy:"rag",constraints:{neverMakeUp:!0,askBeforeActions:!1,stayInScope:!0,useOnlyTools:!0,customConstraints:"Focus on data-driven decisions. Prioritize user feedback and market trends in recommendations."}}],gt=1e4,ht=20,No=50,Eo=3;function Ve({onValidationChange:t,onNavigateToTest:s,onNavigateToNext:o,onNavigateToKnowledge:n}){const a=U(),r=A($=>$.prompt),i=A($=>$.setPrompt),l=A($=>$.updateInstruction),c=A($=>$.hydrateFromGenerated),g=A($=>$.setKnowledgeGaps),b=A($=>$.channels),p=A($=>$.mcpServers),T=A($=>$.skills),S=be($=>$.setSessionConfig),[m,j]=d.useState(null),[y,f]=d.useState(null),[N,u]=d.useState(!1),[M,F]=d.useState(!1),[R,P]=d.useState(null),[B,_]=d.useState(null),L=d.useRef(void 0),h=d.useRef(void 0),H=d.useRef(new Set),[C,O]=d.useState([]),K=d.useRef(null),x={color:a.textPrimary,fontFamily:"'Geist Sans', sans-serif"},v={color:a.textSecondary,lineHeight:1.5},E=$=>({background:$?"#FE500010":a.surface,borderColor:$?"#FE5000":a.border,color:a.textPrimary}),z={fontFamily:"'Geist Sans', sans-serif",fontSize:"14px"},D={color:a.textSecondary,lineHeight:1.4},I={minHeight:"200px",fontFamily:"'Geist Sans', sans-serif",fontSize:"14px",lineHeight:1.6},w={background:a.surface,border:`1px solid ${a.border}`},G={color:"#FE5000",marginTop:2,flexShrink:0},k=r.length>=ht;d.useEffect(()=>{const $=!k&&N?`Please enter at least ${ht} characters`:null;f($),t?.(k)},[k,N,t]);const W=d.useCallback(()=>{L.current&&clearTimeout(L.current),L.current=setTimeout(()=>{},500)},[]);d.useEffect(()=>{if(h.current&&clearTimeout(h.current),b.length>=Eo||r.length<No){O([]);return}return h.current=setTimeout(()=>{const oe=Co(r,b);O(oe.filter(q=>!H.current.has(q.source.id)))},500),()=>{h.current&&clearTimeout(h.current)}},[r,b]);const V=$=>{H.current.add($),O(oe=>oe.filter(q=>q.source.id!==$))},J=$=>{V($),n?.()},fe=$=>{i($),W()},Zt=$=>{i($.prompt),j($.label),u(!1),S({strategy:$.memoryStrategy}),l({constraints:{neverMakeUp:$.constraints.neverMakeUp,askBeforeActions:$.constraints.askBeforeActions,stayInScope:$.constraints.stayInScope,useOnlyTools:$.constraints.useOnlyTools,limitWords:!1,wordLimit:500,customConstraints:$.constraints.customConstraints,scopeDefinition:""}})},Xt=($,oe)=>{if($.key==="ArrowDown"||$.key==="ArrowRight"){$.preventDefault();const q=(oe+1)%Ce.length;K.current?.children[q]?.focus()}else if($.key==="ArrowUp"||$.key==="ArrowLeft"){$.preventDefault();const q=(oe-1+Ce.length)%Ce.length;K.current?.children[q]?.focus()}},es=()=>{u(!0)},ts=async()=>{if(!r.trim()){f("Please enter a description before generating"),u(!0);return}F(!0),P(null),_(null);try{const $=await wo(r,p,T,b);g($.knowledgeGaps||[]),c($),_($),setTimeout(()=>{o?.()},2e3)}catch($){P($ instanceof Error?$.message:"Generation failed")}finally{F(!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:x,children:"Describe Your Agent"}),e.jsx("p",{className:"text-sm",style:v,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("h3",{className:"text-lg font-medium mt-3 mb-4 m-0",style:x,children:"Quick Start Templates"}),e.jsx("div",{ref:K,className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",role:"radiogroup","aria-label":"Agent templates",children:Ce.map(($,oe)=>e.jsxs("button",{type:"button",role:"radio","aria-checked":m===$.label,onClick:()=>Zt($),onKeyDown:q=>Xt(q,oe),"aria-describedby":`template-desc-${$.label.replace(/\s+/g,"-").toLowerCase()}`,title:`Use ${$.label} template`,className:"text-left p-5 rounded-lg border cursor-pointer transition-colors min-h-[44px]",style:E(m===$.label),onMouseEnter:q=>{m!==$.label&&(q.currentTarget.style.background="#FE500008",q.currentTarget.style.borderColor="#FE500050")},onMouseLeave:q=>{m!==$.label&&(q.currentTarget.style.background=a.surfaceElevated,q.currentTarget.style.borderColor=a.border)},onFocus:q=>{m!==$.label&&(q.currentTarget.style.background="#FE500008",q.currentTarget.style.borderColor="#FE500050")},onBlur:q=>{m!==$.label&&(q.currentTarget.style.background=a.surfaceElevated,q.currentTarget.style.borderColor=a.border)},children:[e.jsxs("div",{className:"font-semibold mb-1",style:z,children:[$.label,m===$.label&&e.jsx("span",{className:"sr-only",children:" (selected)"})]}),e.jsx("div",{id:`template-desc-${$.label.replace(/\s+/g,"-").toLowerCase()}`,className:"text-xs",style:D,children:$.description})]},$.label))}),m&&e.jsx("div",{className:"mt-4 flex justify-center",children:e.jsxs("button",{type:"button",onClick:s,title:"Test template now",className:"flex items-center gap-2 px-6 py-3 rounded-lg transition-colors",style:{background:"#FE5000",color:"#FFFFFF",border:"none",fontFamily:"'Geist Sans', sans-serif",fontWeight:600,fontSize:"14px"},onMouseEnter:$=>{$.currentTarget.style.background="#E54800"},onMouseLeave:$=>{$.currentTarget.style.background="#FE5000"},onFocus:$=>{$.currentTarget.style.background="#E54800"},onBlur:$=>{$.currentTarget.style.background="#FE5000"},children:["Jump to Test",e.jsx(qs,{size:16})]})})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"agent-description",className:"block text-sm font-medium mb-3",style:{color:a.textPrimary},children:"Agent Description"}),e.jsx(ko,{id:"agent-description",value:r,onChange:$=>fe($.target.value),onBlur:es,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:I,maxLength:gt}),e.jsxs("div",{className:"flex justify-between items-center mt-2",children:[e.jsx("div",{children:y&&e.jsx("div",{className:"text-sm text-red-500",children:y})}),e.jsxs("div",{className:"text-sm text-right",style:{color:a.textSecondary},"aria-live":"polite",children:[r.length," / ",gt]})]}),C.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("p",{className:"text-xs mb-2",style:{color:a.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:C.map($=>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:a.textPrimary},children:[e.jsx("button",{type:"button",onClick:()=>J($.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 ${$.source.name} to knowledge sources`,children:$.source.name}),e.jsxs("span",{style:{color:a.textSecondary},children:["· ",$.reason]}),e.jsx("button",{type:"button",onClick:()=>V($.source.id),"aria-label":`Dismiss ${$.source.name} suggestion`,className:"ml-1 opacity-60 hover:opacity-100",style:{background:"none",border:"none",cursor:"pointer",padding:0,color:a.textSecondary,display:"flex",alignItems:"center"},children:e.jsx(ce,{size:10})})]},$.source.id))})]}),e.jsx("div",{className:"mt-6 mb-4 text-center",children:e.jsx("p",{className:"text-sm px-4",style:{color:a.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.jsx("div",{className:"mt-4 flex justify-center",children:e.jsx("button",{type:"button",onClick:ts,disabled:M||!r.trim(),title:M?"Generating configuration":r.trim()?"Generate full agent config":"Enter description first",className:"flex items-center gap-3 px-8 py-4 rounded-lg transition-colors font-semibold text-base",style:{background:M||!r.trim()?"#CC4000":"#FE5000",color:"#FFFFFF",border:"none",fontFamily:"'Geist Sans', sans-serif",opacity:M||!r.trim()?.6:1,cursor:M||!r.trim()?"default":"pointer"},onMouseEnter:$=>{!M&&r.trim()&&($.currentTarget.style.background="#E54800")},onMouseLeave:$=>{!M&&r.trim()&&($.currentTarget.style.background="#FE5000")},children:M?e.jsxs(e.Fragment,{children:[e.jsx(ee,{size:20,className:"animate-spin motion-reduce:animate-none"}),"Generating Agent..."]}):B?e.jsxs(e.Fragment,{children:[e.jsx(X,{size:20}),"Agent Generated!"]}):e.jsxs(e.Fragment,{children:[e.jsx(Pe,{size:20}),"Generate Agent"]})})}),R&&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:R})}),B&&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 "',B.agentMeta.name,'" generated successfully!']}),e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsxs("div",{children:["• ",B.workflowSteps?.length||0," workflow steps configured"]}),e.jsxs("div",{children:["• ",B.skillIds?.length||0," skills selected"]}),e.jsxs("div",{children:["• ",B.mcpServerIds?.length||0," MCP tools configured"]}),B.knowledgeGaps&&B.knowledgeGaps.length>0&&e.jsxs("div",{children:["• ",B.knowledgeGaps.length," knowledge gap",B.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:w,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Dt,{size:16,style:G}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-sm mb-2 m-0",style:{color:a.textPrimary},children:"Writing Tips"}),e.jsxs("ul",{className:"text-sm space-y-1",style:{color:a.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 yt=56,To=24,Mo=88,Fo={position:"fixed",bottom:Mo,right:To,width:yt,height:yt,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 $o({onClick:t,isVisible:s}){const o=U();return s?e.jsx("button",{type:"button","aria-label":"Switch to Test tab and start testing",onClick:t,style:Fo,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(qe,{size:24,fill:"#fff",color:"#fff","aria-hidden":"true"})}):null}const Ao=d.lazy(()=>pe(()=>import("./TestTab-PDyMF8Fw.js"),__vite__mapDeps([0,1,2,3,4,5,6])).then(t=>({default:t.TestTab}))),Io=d.lazy(()=>pe(()=>import("./QualificationTab-Dfpy3J30.js"),__vite__mapDeps([7,1,4,3,8,9,5])).then(t=>({default:t.QualificationTab}))),Do=d.lazy(()=>pe(()=>import("./KnowledgeTab-DABxirZh.js"),__vite__mapDeps([10,1,4,3,5])).then(t=>({default:t.KnowledgeTab}))),Lo=d.lazy(()=>pe(()=>import("./ToolsTab-B83qGCmG.js"),__vite__mapDeps([11,1,4,3,5])).then(t=>({default:t.ToolsTab}))),Po=d.lazy(()=>pe(()=>import("./MemoryTab-DZeYElIT.js"),__vite__mapDeps([12,1,4,3,8,13,5])).then(t=>({default:t.MemoryTab}))),zo=d.lazy(()=>pe(()=>import("./ReviewTab-SD8lQuCc.js"),__vite__mapDeps([14,1,4,3,2,8,9,5,13])).then(t=>({default:t.ReviewTab}))),Y=[{id:"describe",label:"Describe",icon:De,component:Ve},{id:"knowledge",label:"Knowledge",icon:Je,component:Do},{id:"tools",label:"Tools",icon:Nt,component:Lo},{id:"memory",label:"Memory",icon:Ye,component:Po},{id:"review",label:"Review",icon:Ys,component:zo},{id:"test",label:"Test",icon:qe,component:Ao},{id:"qualification",label:"Qualification",icon:Js,component:Io}],Bo=1024;function Ro(){const t=U();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(Jt,{size:"md"}),e.jsx("span",{style:{color:t.textSecondary},children:"Loading..."})]})})}function Oo(){const t=U(),s=A(C=>C.prompt.length),o=A(C=>C.channels.length),n=A(C=>C.mcpServers.length),a=A(C=>C.skills.length),r=A(C=>C.agentMeta.name),i=be(C=>C.session.strategy),l=be(C=>C.facts.length),c=be(C=>C.longTerm.enabled),g=be(C=>C.working.content),[b,p]=d.useState("describe"),[T,S]=d.useState(!1),[m,j]=d.useState(!1),y=d.useRef([]),f=d.useRef(null),N=d.useRef(null),u=Y.find(C=>C.id===b)?.component||Ve,M=Y.findIndex(C=>C.id===b),F=()=>{const C=N.current;if(!C)return;const{scrollLeft:O,scrollWidth:K,clientWidth:x}=C;S(O>0),j(O<K-x-1)};d.useEffect(()=>{const C=()=>{if(window.innerWidth>=Bo){S(!1),j(!1);return}F()};return C(),window.addEventListener("resize",C),()=>window.removeEventListener("resize",C)},[]),d.useEffect(()=>{if(f.current){const C=f.current.querySelector("[data-skip-target]"),O=f.current.querySelector("h2, h3, h4"),K=C||O||f.current;K&&K.focus()}},[b]),d.useEffect(()=>{const C=localStorage.getItem("mcp-oauth-completed"),O=localStorage.getItem("mcp-oauth-return-tab");C==="true"&&O&&Y.some(K=>K.id===O)&&(p(O),localStorage.removeItem("mcp-oauth-completed"),localStorage.removeItem("mcp-oauth-return-tab"))},[]);const R=()=>{M<Y.length-1&&p(Y[M+1].id)},P=()=>{M>0&&p(Y[M-1].id)},B=()=>{p("test"),setTimeout(()=>{const C=["[data-test-chat-input]",'textarea[placeholder*="message"]','input[placeholder*="message"]','textarea[placeholder*="chat"]','input[placeholder*="chat"]',"textarea",'input[type="text"]'];for(const O of C){const K=document.querySelector(O);if(K){K.focus();break}}},100)},_=(C,O)=>{switch(C.key){case"ArrowLeft":C.preventDefault();const K=O===0?Y.length-1:O-1;y.current[K]?.focus(),p(Y[K].id);break;case"ArrowRight":C.preventDefault();const x=O===Y.length-1?0:O+1;y.current[x]?.focus(),p(Y[x].id);break;case"Home":C.preventDefault(),y.current[0]?.focus(),p(Y[0].id);break;case"End":C.preventDefault();const v=Y.length-1;y.current[v]?.focus(),p(Y[v].id);break}},L=(C,O)=>O&&C==="#FE5000"?"#FF6B1A":C,h=C=>{switch(C){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||g.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 ${L("#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:[T&&e.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-8 pointer-events-none z-10",style:H.left,"aria-hidden":"true"}),m&&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:N,role:"tablist",className:"flex w-full overflow-x-auto lg:overflow-x-visible tab-scrollbar-hidden",onScroll:F,children:Y.map((C,O)=>{const K=C.icon,x=C.id===b,v=O<M,E=h(C.id),z=L("#FE5000",t.isDark),D=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 C.label}};return e.jsxs("button",{ref:I=>{y.current[O]=I},type:"button",role:"tab","aria-selected":x,"aria-controls":`tabpanel-${C.id}`,tabIndex:x?0:-1,onClick:()=>p(C.id),onKeyDown:I=>_(I,O),title:D(C.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?z:t.textSecondary,borderBottom:x?`2px solid ${z}`:"2px solid transparent"},onMouseEnter:I=>{x||(I.currentTarget.style.color=z,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=z,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:v?"#2ecc71":x?z:t.textDim},"aria-hidden":"true"}),e.jsx("span",{style:{fontFamily:"'Geist Sans', sans-serif"},children:C.label}),E&&e.jsx(X,{size:12,style:{color:"#2ecc71"},"aria-hidden":"true"}),e.jsxs("span",{className:"sr-only",children:[x&&", selected",v&&", completed",E&&", task completed",". Use arrow keys to navigate tabs."]})]},C.id)})})]}),e.jsx("div",{ref:f,id:"main-content",role:"tabpanel","aria-labelledby":`tab-${b}`,tabIndex:0,className:`flex-1 min-h-0 focus:outline-none ${b==="test"?"overflow-hidden":"overflow-y-auto"}`,"data-skip-target":!0,children:e.jsx("div",{className:b==="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(d.Suspense,{fallback:e.jsx(Ro,{}),children:b==="describe"?e.jsx(Ve,{onNavigateToTest:()=>p("test"),onNavigateToNext:R,onNavigateToKnowledge:()=>p("knowledge")}):e.jsx(u,{})})})}),M>0&&e.jsx("button",{type:"button",onClick:P,"aria-label":`Go to previous step: ${Y[M-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:C=>{C.currentTarget.style.background=t.isDark?`${t.surface}E6`:`${t.surface}E6`,C.currentTarget.style.transform="translateY(-50%) scale(1.05)"},onMouseLeave:C=>{C.currentTarget.style.background=t.isDark?`${t.surface}CC`:`${t.surface}CC`,C.currentTarget.style.transform="translateY(-50%) scale(1)"},onFocus:C=>{C.currentTarget.style.background=t.isDark?`${t.surface}E6`:`${t.surface}E6`,C.currentTarget.style.transform="translateY(-50%) scale(1.05)"},onBlur:C=>{C.currentTarget.style.background=t.isDark?`${t.surface}CC`:`${t.surface}CC`,C.currentTarget.style.transform="translateY(-50%) scale(1)"},title:`Previous: ${Y[M-1].label}`,children:e.jsx(Qs,{size:20})}),M<Y.length-1&&e.jsx("button",{type:"button",onClick:R,"aria-label":`Go to next step: ${Y[M+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:C=>{C.currentTarget.style.background=t.isDark?`${t.surface}E6`:`${t.surface}E6`,C.currentTarget.style.transform="translateY(-50%) scale(1.05)"},onMouseLeave:C=>{C.currentTarget.style.background=t.isDark?`${t.surface}CC`:`${t.surface}CC`,C.currentTarget.style.transform="translateY(-50%) scale(1)"},onFocus:C=>{C.currentTarget.style.background=t.isDark?`${t.surface}E6`:`${t.surface}E6`,C.currentTarget.style.transform="translateY(-50%) scale(1.05)"},onBlur:C=>{C.currentTarget.style.background=t.isDark?`${t.surface}CC`:`${t.surface}CC`,C.currentTarget.style.transform="translateY(-50%) scale(1)"},title:`Next: ${Y[M+1].label}`,children:e.jsx(Ie,{size:20})}),e.jsx($o,{onClick:B,isVisible:b!=="test"})]})}function Go(){const t=U(),[s,o]=d.useState("library"),n=A(u=>u.showFilePicker),a=A(u=>u.setShowFilePicker),r=A(u=>u.setShowSkillPicker),i=A(u=>u.setShowConnectionPicker),l=A(u=>u.setShowMarketplace),c=A(u=>u.run),g=A(u=>u.running),b=A(u=>u.showSettings),p=A(u=>u.setShowSettings),T=Q(u=>u.loadServers),S=A(u=>u.loadAgent),m=d.useRef(null),j=d.useCallback(u=>{const M=u.target.files?.[0];if(!M)return;const F=new FileReader;F.onload=R=>{const P=R.target?.result;if(!P)return;const B=po(P),_=A.getState();if(B.channels){_.clearChannels();for(const L of B.channels)_.addChannel(L)}B.selectedModel&&_.setModel(B.selectedModel),B.outputFormat&&_.setOutputFormat(B.outputFormat),B.prompt&&_.setPrompt(B.prompt),B.tokenBudget&&_.setTokenBudget(B.tokenBudget),B.agentMeta&&_.setAgentMeta(B.agentMeta),B.instructionState&&_.setInstructionState(B.instructionState),B.workflowSteps&&_.setWorkflowSteps(B.workflowSteps)},F.readAsText(M),u.target.value=""},[]);d.useEffect(()=>{const u=M=>{(M.metaKey||M.ctrlKey)&&M.key==="k"&&(M.preventDefault(),a(!n)),(M.metaKey||M.ctrlKey)&&M.key==="Enter"&&(M.preventDefault(),g||c()),M.key==="Escape"&&(a(!1),r(!1),i(!1),l(!1),p(!1),A.getState().setShowSaveModal(!1))};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[a,n,r,i,l,c,g]),d.useEffect(()=>{T()},[T]);const y=u=>{S(u),o("editor")},f=()=>{o("editor")},N=()=>{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:m,type:"file",accept:".md,.yaml,.yml,.json",onChange:j,style:{display:"none"},"aria-hidden":"true"}),s==="library"?e.jsx(lo,{onSelectAgent:y,onNewAgent:f}):e.jsxs(e.Fragment,{children:[e.jsx(xn,{onSettingsClick:()=>p(!0,"providers"),onBack:N}),e.jsx(Oo,{})]}),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(gn,{}),e.jsx(yn,{}),e.jsx(En,{}),e.jsx(An,{}),e.jsx(Tn,{}),e.jsx(Rn,{open:b,onClose:()=>p(!1)}),e.jsx(to,{})]})}ns.createRoot(document.getElementById("root")).render(e.jsx(d.StrictMode,{children:e.jsx(Go,{})}));export{_e as B,no as M,oo as S,_t as T,ko as a,de as b,ge as c,Yt as d,Vt as e,tt as f,Ho as g,Vo as h,Yn as i,U as u};
|