import{c as e,aI as s,r as t,bl as a,bm as r,t as n,bn as l,bo as i,bp as c,ak as d,bq as o,j as m,B as x,aD as u,d as p,I as h,T as g,q as f,D as j,aE as b,aF as N,A as y,ap as v,av as k}from"./index-nYsy3LMF.js";import{S as w}from"./search-B9B3Cq4V.js";import{C}from"./chevron-down-B3q2CU-d.js";
/**
 * @license lucide-react v0.309.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const S=e("Power",[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]]),P=e("Puzzle",[["path",{d:"M19.439 7.85c-.049.322.059.648.289.878l1.568 1.568c.47.47.706 1.087.706 1.704s-.235 1.233-.706 1.704l-1.611 1.611a.98.98 0 0 1-.837.276c-.47-.07-.802-.48-.968-.925a2.501 2.501 0 1 0-3.214 3.214c.446.166.855.497.925.968a.979.979 0 0 1-.276.837l-1.61 1.61a2.404 2.404 0 0 1-1.705.707 2.402 2.402 0 0 1-1.704-.706l-1.568-1.568a1.026 1.026 0 0 0-.877-.29c-.493.074-.84.504-1.02.968a2.5 2.5 0 1 1-3.237-3.237c.464-.18.894-.527.967-1.02a1.026 1.026 0 0 0-.289-.877l-1.568-1.568A2.402 2.402 0 0 1 1.998 12c0-.617.236-1.234.706-1.704L4.23 8.77c.24-.24.581-.353.917-.303.515.077.877.528 1.073 1.01a2.5 2.5 0 1 0 3.259-3.259c-.482-.196-.933-.558-1.01-1.073-.05-.336.062-.676.303-.917l1.525-1.525A2.402 2.402 0 0 1 12 1.998c.617 0 1.234.236 1.704.706l1.568 1.568c.23.23.556.338.877.29.493-.074.84-.504 1.02-.968a2.5 2.5 0 1 1 3.237 3.237c-.464.18-.894.527-.967 1.02Z",key:"i0oyt7"}]]),q=e("Tag",[["path",{d:"M12 2H2v10l9.29 9.29c.94.94 2.48.94 3.42 0l6.58-6.58c.94-.94.94-2.48 0-3.42L12 2Z",key:"14b2ls"}],["path",{d:"M7 7h.01",key:"7u93v4"}]]),E=e("User",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);
/**
 * @license lucide-react v0.309.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */function z(){const e=s(),[z,M]=t.useState("prompts"),[H,F]=t.useState(""),[_,I]=t.useState([]),[Q,W]=t.useState([]),[D,O]=t.useState(!1),[T,U]=t.useState(null);t.useEffect(()=>{"plugins"===z&&(O(!0),Promise.all([a().catch(()=>[]),fetch("/api/skillhub/plugins").then(e=>e.ok?e.json():[]).catch(()=>[])]).then(([e,s])=>{I(e),W(s)}).finally(()=>O(!1)))},[z]);const Z=t.useCallback(async e=>{if(!T){U(e.id);try{await r(e.downloadUrl),n.success(`已安装 ${e.name}`);const s=await a().catch(()=>[]);I(s)}catch(s){n.error(s instanceof Error?s.message:"安装失败")}finally{U(null)}}},[T]),B=t.useCallback(async e=>{try{await l(e),I(s=>s.filter(s=>s.id!==e)),n.success("已卸载")}catch(s){n.error(s instanceof Error?s.message:"卸载失败")}},[]),$=t.useCallback(async(e,s)=>{try{await i(e,s),I(t=>t.map(t=>t.id===e?{...t,enabled:s}:t))}catch(t){n.error(t instanceof Error?t.message:"操作失败")}},[]),[G,J]=t.useState([]),[K,R]=t.useState(!0),[V,X]=t.useState(null),[Y,ee]=t.useState("all"),[se,te]=t.useState(null),[ae,re]=t.useState(null),[ne,le]=t.useState(new Set),[ie,ce]=t.useState(null);t.useEffect(()=>{Promise.all([c(),d().catch(()=>[]),o().catch(()=>[])]).then(([e,s,t])=>{J(e);const a=new Set;for(const r of e)"quick-prompt"===r.kind?s.some(e=>e.label===r.label&&e.command===r.body)&&a.add(r.id):t.some(e=>e.label===r.label&&e.command===r.body)&&a.add(r.id);le(a)}).catch(e=>X(e instanceof Error?e.message:"Failed to load CCWeb Hub")).finally(()=>R(!1))},[]);const de=t.useMemo(()=>{const e=new Set;return G.forEach(s=>{var t;return null==(t=s.tags)?void 0:t.forEach(s=>e.add(s))}),[...e].sort()},[G]),oe=t.useMemo(()=>{let e=G;"all"!==Y&&(e=e.filter(e=>e.kind===Y)),"__untagged__"===se?e=e.filter(e=>!e.tags||0===e.tags.length):se&&(e=e.filter(e=>{var s;return null==(s=e.tags)?void 0:s.includes(se)}));const s=H.trim().toLowerCase();return s&&(e=e.filter(e=>e.label.toLowerCase().includes(s)||e.body.toLowerCase().includes(s)||(e.description??"").toLowerCase().includes(s)||(e.author??"").toLowerCase().includes(s)||(e.tags??[]).some(e=>e.toLowerCase().includes(s)))),e},[G,Y,se,H]);return m.jsxs("div",{className:"min-h-screen bg-background",children:[m.jsx("header",{className:"border-b sticky top-0 bg-background z-10",children:m.jsxs("div",{className:"max-w-4xl mx-auto px-4 h-14 flex items-center gap-4",children:[m.jsxs(x,{variant:"ghost",size:"sm",onClick:()=>e("/"),children:[m.jsx(u,{className:"h-4 w-4 mr-1"}),"返回"]}),m.jsx("h1",{className:"font-semibold text-lg",children:"CCWeb Hub"}),m.jsxs("div",{className:"flex items-center gap-1 ml-4",children:[m.jsx("button",{onClick:()=>M("prompts"),className:p("px-3 py-1 rounded-md text-sm transition-colors","prompts"===z?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-accent"),children:"Prompts"}),m.jsxs("button",{onClick:()=>M("plugins"),className:p("px-3 py-1 rounded-md text-sm transition-colors flex items-center gap-1","plugins"===z?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-accent"),children:[m.jsx(P,{className:"h-3.5 w-3.5"}),"插件"]})]}),m.jsx("div",{className:"flex-1"}),m.jsxs("div",{className:"relative w-64",children:[m.jsx(w,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),m.jsx(h,{placeholder:"prompts"===z?"搜索 prompt...":"搜索插件...",value:H,onChange:e=>F(e.target.value),className:"pl-8 h-9"})]})]})}),m.jsxs("main",{className:"max-w-4xl mx-auto px-4 py-6",children:["plugins"===z&&m.jsxs("div",{children:[D&&m.jsx("div",{className:"text-center text-muted-foreground py-20",children:"加载中..."}),!D&&m.jsxs(m.Fragment,{children:[_.length>0&&m.jsxs("div",{className:"mb-8",children:[m.jsx("h2",{className:"text-sm font-medium text-muted-foreground mb-3",children:"已安装"}),m.jsx("div",{className:"space-y-2",children:_.map(e=>m.jsxs("div",{className:"rounded-xl border bg-card p-4 flex items-center gap-4",children:[m.jsxs("div",{className:"flex-1 min-w-0",children:[m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx("span",{className:"font-medium text-sm",children:e.name}),m.jsxs("span",{className:"text-xs text-muted-foreground",children:["v",e.version]}),m.jsx("span",{className:p("text-xs px-1.5 py-0.5 rounded",e.enabled?"bg-green-500/10 text-green-500":"bg-muted text-muted-foreground"),children:e.enabled?"启用":"禁用"})]}),m.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:e.description}),e.permissions.length>0&&m.jsx("div",{className:"flex gap-1 mt-1 flex-wrap",children:e.permissions.map(e=>m.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-400",children:e},e))})]}),m.jsx(x,{size:"sm",variant:"ghost",onClick:()=>$(e.id,!e.enabled),title:e.enabled?"禁用":"启用",children:m.jsx(S,{className:p("h-4 w-4",e.enabled?"text-green-500":"text-muted-foreground")})}),m.jsx(x,{size:"sm",variant:"ghost",onClick:()=>B(e.id),title:"卸载",children:m.jsx(g,{className:"h-4 w-4 text-red-400"})})]},e.id))})]}),m.jsxs("div",{children:[m.jsx("h2",{className:"text-sm font-medium text-muted-foreground mb-3",children:_.length>0?"更多插件":"可用插件"}),0===Q.length&&m.jsxs("div",{className:"text-center text-muted-foreground py-20",children:[m.jsx(P,{className:"h-10 w-10 mx-auto mb-3 opacity-30"}),m.jsx("p",{className:"text-sm",children:"Hub 暂无可用插件"})]}),m.jsx("div",{className:"space-y-2",children:Q.filter(e=>!_.some(s=>s.id===e.id)).map((e,s)=>{const t=T===e.id;return m.jsxs(f.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.25,delay:.03*s},className:"rounded-xl border bg-card p-4 flex items-center gap-4",children:[m.jsxs("div",{className:"flex-1 min-w-0",children:[m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx("span",{className:"font-medium text-sm",children:e.name}),m.jsxs("span",{className:"text-xs text-muted-foreground",children:["v",e.version]}),m.jsxs("span",{className:"text-xs text-muted-foreground",children:["by ",e.author]})]}),m.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:e.description}),e.permissions.length>0&&m.jsx("div",{className:"flex gap-1 mt-1 flex-wrap",children:e.permissions.map(e=>m.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-400",children:e},e))})]}),m.jsxs(x,{size:"sm",disabled:t,onClick:()=>Z(e),children:[m.jsx(j,{className:"h-3.5 w-3.5 mr-1"}),t?"安装中...":"安装"]})]},e.id)})})]})]})]}),"prompts"===z&&m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex flex-wrap gap-2 mb-3",children:[m.jsx(A,{active:"all"===Y,onClick:()=>ee("all"),children:"全部"}),m.jsxs(A,{active:"quick-prompt"===Y,onClick:()=>ee("quick-prompt"),children:[m.jsx(b,{className:"h-3 w-3"}),"Quick Prompts"]}),m.jsxs(A,{active:"agent-prompt"===Y,onClick:()=>ee("agent-prompt"),children:[m.jsx(N,{className:"h-3 w-3"}),"Agent Prompts"]})]}),de.length>0&&m.jsxs("div",{className:"flex flex-wrap gap-2 mb-6",children:[m.jsx(L,{active:null===se,onClick:()=>te(null),children:"全部标签"}),de.map(e=>m.jsx(L,{active:se===e,onClick:()=>te(se===e?null:e),children:e},e))]}),K&&m.jsx("div",{className:"text-center text-muted-foreground py-20",children:"加载中..."}),V&&m.jsx("div",{className:"text-center text-destructive py-20",children:V}),!K&&!V&&0===G.length&&m.jsxs("div",{className:"text-center text-muted-foreground py-20",children:[m.jsx("p",{className:"text-lg mb-2",children:"CCWeb Hub 还没有 prompt"}),m.jsx("p",{className:"text-sm",children:'在 Quick Prompts 或 Agent Prompts 卡片上右键选择"共享"来提交第一个吧！'})]}),!K&&!V&&G.length>0&&0===oe.length&&m.jsx("div",{className:"text-center text-muted-foreground py-20",children:"没有匹配的 prompt"}),m.jsx("div",{className:"space-y-3",children:oe.map((e,s)=>{var t;const a=ae===e.id,r=ne.has(e.id),l=ie===e.id;return m.jsxs(f.div,{layout:!0,initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.25,delay:.03*s,ease:"easeOut"},className:"rounded-xl border bg-card p-4 cursor-pointer hover:border-muted-foreground/30 transition-colors",onClick:()=>re(a?null:e.id),children:[m.jsxs("div",{className:"flex items-start justify-between gap-4",children:[m.jsxs("div",{className:"flex-1 min-w-0",children:[m.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[m.jsxs("span",{className:p("inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium","quick-prompt"===e.kind?"bg-blue-500/15 text-blue-400":"bg-green-500/15 text-green-500"),children:["quick-prompt"===e.kind?m.jsx(b,{className:"h-2.5 w-2.5"}):m.jsx(N,{className:"h-2.5 w-2.5"}),"quick-prompt"===e.kind?"Quick":"Agent"]}),m.jsx("h3",{className:"font-medium text-sm truncate",children:e.label}),null==(t=e.tags)?void 0:t.map(e=>m.jsxs("span",{className:"inline-flex items-center gap-0.5 px-2 py-0.5 rounded-full text-xs bg-muted text-muted-foreground",children:[m.jsx(q,{className:"h-2.5 w-2.5"}),e]},e))]}),e.description&&m.jsx("p",{className:"text-xs text-muted-foreground mt-1 truncate",children:e.description}),m.jsxs("div",{className:"flex items-center gap-3 mt-2 text-xs text-muted-foreground",children:[e.author&&m.jsxs("span",{className:"flex items-center gap-1",children:[m.jsx(E,{className:"h-3 w-3"}),e.author]}),m.jsx("code",{className:"text-[10px] opacity-60",children:e.file})]})]}),m.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[m.jsxs(x,{size:"sm",variant:r?"ghost":"outline",disabled:l||r,onClick:s=>{(async(e,s)=>{if(s.stopPropagation(),!ie&&!ne.has(e.id)){ce(e.id);try{"quick-prompt"===e.kind?(await v({label:e.label,command:e.body}),n.success("已导入到全局快捷 Prompts")):(await k({label:e.label,command:e.body}),n.success("已导入到全局 Agent Prompts")),le(s=>new Set(s).add(e.id))}catch(t){n.error(t instanceof Error?t.message:"导入失败")}finally{ce(null)}}})(e,s)},title:"quick-prompt"===e.kind?"导入到全局快捷 Prompts":"导入到全局 Agent Prompts",children:[m.jsx(j,{className:"h-3.5 w-3.5 mr-1"}),r?"已导入":l?"导入中...":"导入"]}),m.jsx(f.span,{animate:{rotate:a?180:0},transition:{duration:.2},children:m.jsx(C,{className:"h-4 w-4 text-muted-foreground"})})]})]}),m.jsx(y,{children:a&&m.jsx(f.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2,ease:"easeInOut"},className:"overflow-hidden",children:m.jsx("div",{className:"mt-3 pt-3 border-t",children:m.jsx("pre",{className:"text-xs font-mono bg-muted rounded p-3 whitespace-pre-wrap break-words max-h-64 overflow-y-auto",children:e.body})})})})]},e.id)})})]})]})]})}function A({active:e,onClick:s,children:t}){return m.jsx("button",{onClick:s,className:p("flex items-center gap-1 px-3 py-1 rounded-full text-xs font-medium transition-colors",e?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-accent"),children:t})}function L({active:e,onClick:s,children:t}){return m.jsx("button",{onClick:s,className:p("px-3 py-1 rounded-full text-xs font-medium transition-colors",e?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-accent"),children:t})}export{z as SkillHubPage};
