@nextclaw/ui 0.9.4 → 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/assets/{ChannelsList-DDfZIiJa.js → ChannelsList-Byfj2R01.js} +1 -1
  3. package/dist/assets/{ChatPage-FpRraTxm.js → ChatPage-DM1ewbWf.js} +1 -1
  4. package/dist/assets/{DocBrowser-Kndx8OJj.js → DocBrowser-BLv77lJ0.js} +1 -1
  5. package/dist/assets/{LogoBadge-hKHoLH9n.js → LogoBadge-D7j1al-w.js} +1 -1
  6. package/dist/assets/{MarketplacePage-CZIJyfjK.js → MarketplacePage-DuskLKYh.js} +1 -1
  7. package/dist/assets/{McpMarketplacePage-BGrAMA37.js → McpMarketplacePage-DpMjaD3m.js} +1 -1
  8. package/dist/assets/{ModelConfig-BpKQeGfb.js → ModelConfig-ubaecweS.js} +1 -1
  9. package/dist/assets/{ProvidersList-qfUL6mrW.js → ProvidersList-w8MJH2LI.js} +1 -1
  10. package/dist/assets/RemoteAccessPage-D79_5Kbn.js +1 -0
  11. package/dist/assets/{RuntimeConfig-CVlqNWKO.js → RuntimeConfig-BbX4yFKy.js} +1 -1
  12. package/dist/assets/{SearchConfig-DXFV6Mvx.js → SearchConfig-BmmmeyJd.js} +1 -1
  13. package/dist/assets/{SecretsConfig-BGW9aUqv.js → SecretsConfig-CWG8J01H.js} +1 -1
  14. package/dist/assets/{SessionsConfig-BByfa1ke.js → SessionsConfig-D-vg_Lgv.js} +1 -1
  15. package/dist/assets/{chat-message-ZwnDwDuQ.js → chat-message-CGXiVhyN.js} +1 -1
  16. package/dist/assets/{index-BWvap_iq.js → index-CeRbsQ90.js} +2 -2
  17. package/dist/assets/{label-Bklr3fXc.js → label-CCSffS1D.js} +1 -1
  18. package/dist/assets/{page-layout-sNhcbwtm.js → page-layout-ud8wZ8gX.js} +1 -1
  19. package/dist/assets/{popover-C3rJrJJG.js → popover-Bfoe6YBX.js} +1 -1
  20. package/dist/assets/{security-config-BueosYw1.js → security-config-DJJUCMov.js} +1 -1
  21. package/dist/assets/{skeleton-CiG6msbm.js → skeleton-IOOTmHzP.js} +1 -1
  22. package/dist/assets/{status-dot-CsIV5YrS.js → status-dot-Fz9-eKsl.js} +1 -1
  23. package/dist/assets/{switch-DSdHSIsC.js → switch-B-_SrMSL.js} +1 -1
  24. package/dist/assets/{tabs-custom-BB-VjdL2.js → tabs-custom-6Tm1ZHfS.js} +1 -1
  25. package/dist/assets/{useConfirmDialog-BL5s8KDC.js → useConfirmDialog-BeOW2bOI.js} +1 -1
  26. package/dist/index.html +1 -1
  27. package/package.json +4 -4
  28. package/src/components/remote/RemoteAccessPage.tsx +334 -241
  29. package/dist/assets/RemoteAccessPage-BQuMsngI.js +0 -1
@@ -1 +1 @@
1
- import{r as s,j as t,J as oe,b7 as ae,b8 as ne,ax as W,aj as ie,z as le,b9 as ce,s as de,a7 as ue,ba as me}from"./vendor-CwsIoNvJ.js";import{n as xe,D as Y,t as i,c as X,ah as we}from"./index-BWvap_iq.js";function pe(){const{isOpen:T,mode:g,tabs:F,activeTabId:N,currentTab:w,currentUrl:l,navVersion:p,close:A,toggleMode:I,goBack:$,goForward:O,canGoBack:_,canGoForward:G,navigate:y,syncUrl:S,setActiveTab:V,closeTab:H,openNewTab:J}=xe(),[k,j]=s.useState(""),[E,C]=s.useState(!1),[q,h]=s.useState(!1),[d,D]=s.useState(()=>({x:Math.max(40,window.innerWidth-520),y:80})),[n,B]=s.useState({w:480,h:600}),[L,K]=s.useState(420),u=s.useRef(null),m=s.useRef(null),b=s.useRef(null),z=s.useRef(null),P=s.useRef(p),a=(w==null?void 0:w.kind)==="docs";s.useEffect(()=>{if(!a){j("");return}try{const e=new URL(l);j(e.pathname)}catch{j(l)}},[l,N,a]),s.useEffect(()=>{var e;if(a){if(p!==P.current){P.current=p;return}if((e=z.current)!=null&&e.contentWindow)try{const r=new URL(l).pathname;z.current.contentWindow.postMessage({type:"docs-navigate",path:r},"*")}catch{}}},[l,p,a]),s.useEffect(()=>{g==="floating"&&D(e=>({x:Math.max(40,window.innerWidth-n.w-40),y:e.y}))},[g,n.w]),s.useEffect(()=>{const e=r=>{var o;a&&((o=r.data)==null?void 0:o.type)==="docs-route-change"&&typeof r.data.url=="string"&&S(r.data.url)};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[S,a]);const Q=s.useCallback(e=>{if(e.preventDefault(),!a)return;const r=k.trim();r&&(r.startsWith("/")?y(`${Y}${r}`):r.startsWith("http")?y(r):y(`${Y}/${r}`))},[k,y,a]),Z=s.useCallback(e=>{g==="floating"&&(C(!0),u.current={startX:e.clientX,startY:e.clientY,startPosX:d.x,startPosY:d.y})},[g,d]);s.useEffect(()=>{if(!E)return;const e=o=>{u.current&&D({x:u.current.startPosX+(o.clientX-u.current.startX),y:u.current.startPosY+(o.clientY-u.current.startY)})},r=()=>{C(!1),u.current=null};return window.addEventListener("mousemove",e),window.addEventListener("mouseup",r),()=>{window.removeEventListener("mousemove",e),window.removeEventListener("mouseup",r)}},[E]);const M=s.useCallback(e=>{e.preventDefault(),e.stopPropagation(),h(!0);const r=e.currentTarget.dataset.axis;m.current={startX:e.clientX,startY:e.clientY,startW:n.w,startH:n.h};const o=x=>{m.current&&B(v=>({w:r==="y"?v.w:Math.max(360,m.current.startW+(x.clientX-m.current.startX)),h:r==="x"?v.h:Math.max(400,m.current.startH+(x.clientY-m.current.startY))}))},f=()=>{h(!1),m.current=null,window.removeEventListener("mousemove",o),window.removeEventListener("mouseup",f)};window.addEventListener("mousemove",o),window.addEventListener("mouseup",f)},[n]),ee=s.useCallback(e=>{e.preventDefault(),e.stopPropagation(),h(!0),b.current={startX:e.clientX,startW:L};const r=f=>{if(!b.current)return;const x=b.current.startX-f.clientX;K(Math.max(320,Math.min(860,b.current.startW+x)))},o=()=>{h(!1),b.current=null,window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",o)};window.addEventListener("mousemove",r),window.addEventListener("mouseup",o)},[L]),te=s.useCallback(e=>{e.preventDefault(),e.stopPropagation(),h(!0);const r=e.clientX,o=n.w,f=d.x,x=re=>{const se=r-re.clientX,U=Math.max(360,o+se);B(R=>({...R,w:U})),D(R=>({...R,x:f-(U-o)}))},v=()=>{h(!1),window.removeEventListener("mousemove",x),window.removeEventListener("mouseup",v)};window.addEventListener("mousemove",x),window.addEventListener("mouseup",v)},[n.w,d.x]);if(!T)return null;const c=g==="docked";return t.jsxs("div",{className:X("flex flex-col bg-white overflow-hidden relative",c?"h-full border-l border-gray-200 shrink-0":"rounded-2xl shadow-2xl border border-gray-200"),style:c?{width:L}:{position:"fixed",left:d.x,top:d.y,width:n.w,height:n.h,zIndex:9999},children:[c&&t.jsx("div",{className:"absolute top-0 left-0 w-1.5 h-full cursor-ew-resize z-20 hover:bg-primary/10 transition-colors",onMouseDown:ee}),t.jsxs("div",{className:X("flex items-center justify-between px-4 py-2.5 bg-gray-50 border-b border-gray-200 shrink-0 select-none",!c&&"cursor-grab active:cursor-grabbing"),onMouseDown:c?void 0:Z,children:[t.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[t.jsx(oe,{className:"w-4 h-4 text-primary shrink-0"}),t.jsx("span",{className:"text-sm font-semibold text-gray-900 truncate",children:i("docBrowserTitle")})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("button",{onClick:I,className:"hover:bg-gray-200 rounded-md p-1.5 text-gray-500 hover:text-gray-700 transition-colors",title:c?i("docBrowserFloatMode"):i("docBrowserDockMode"),children:c?t.jsx(ae,{className:"w-3.5 h-3.5"}):t.jsx(ne,{className:"w-3.5 h-3.5"})}),t.jsx("button",{onClick:A,className:"hover:bg-gray-200 rounded-md p-1.5 text-gray-500 hover:text-gray-700 transition-colors",title:i("docBrowserClose"),children:t.jsx(W,{className:"w-3.5 h-3.5"})})]})]}),t.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-2 bg-white border-b border-gray-100 overflow-x-auto custom-scrollbar",children:[F.map(e=>{const r=e.id===N;return t.jsxs("div",{className:X("inline-flex items-center gap-1 h-7 px-1.5 rounded-lg text-xs border max-w-[220px] shrink-0 transition-colors",r?"bg-blue-50 border-blue-300 text-blue-700":"bg-gray-50 border-gray-200 text-gray-600 hover:bg-gray-100"),children:[t.jsx("button",{type:"button",onClick:()=>V(e.id),className:"truncate text-left px-1",title:e.title,children:e.title||i("docBrowserTabUntitled")}),t.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),H(e.id)},className:"rounded p-0.5 hover:bg-black/10","aria-label":i("docBrowserCloseTab"),children:t.jsx(W,{className:"w-3 h-3"})})]},e.id)}),t.jsx("button",{onClick:()=>J(void 0,{kind:"docs",title:"Docs"}),className:"inline-flex items-center justify-center w-7 h-7 rounded-lg border border-gray-200 bg-white text-gray-600 hover:bg-gray-100 shrink-0",title:i("docBrowserNewTab"),children:t.jsx(ie,{className:"w-3.5 h-3.5"})})]}),a&&t.jsxs("div",{className:"flex items-center gap-2 px-3.5 py-2 bg-white border-b border-gray-100 shrink-0",children:[t.jsx("button",{onClick:$,disabled:!_,className:"p-1.5 rounded-md hover:bg-gray-100 disabled:opacity-30 disabled:cursor-not-allowed text-gray-600 transition-colors",children:t.jsx(le,{className:"w-4 h-4"})}),t.jsx("button",{onClick:O,disabled:!G,className:"p-1.5 rounded-md hover:bg-gray-100 disabled:opacity-30 disabled:cursor-not-allowed text-gray-600 transition-colors",children:t.jsx(ce,{className:"w-4 h-4"})}),t.jsxs("form",{onSubmit:Q,className:"flex-1 relative",children:[t.jsx(de,{className:"w-3.5 h-3.5 absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"}),t.jsx("input",{type:"text",value:k,onChange:e=>j(e.target.value),placeholder:i("docBrowserSearchPlaceholder"),className:"w-full h-8 pl-8 pr-3 rounded-lg bg-gray-50 border border-gray-200 text-xs text-gray-700 focus:outline-none focus:ring-1 focus:ring-primary/30 focus:border-primary/40 transition-colors placeholder:text-gray-400"})]})]}),t.jsxs("div",{className:"flex-1 relative overflow-hidden",children:[t.jsx("iframe",{ref:z,src:l,className:"absolute inset-0 w-full h-full border-0",title:(w==null?void 0:w.title)||"NextClaw Docs",sandbox:"allow-same-origin allow-scripts allow-popups allow-forms",allow:"clipboard-read; clipboard-write"},`${N}:${p}`),(q||E)&&t.jsx("div",{className:"absolute inset-0 z-10"})]}),a&&we(l)&&t.jsx("div",{className:"flex items-center justify-between px-4 py-2 bg-gray-50 border-t border-gray-200 shrink-0",children:t.jsxs("a",{href:l,target:"_blank",rel:"noopener noreferrer","data-doc-external":!0,className:"flex items-center gap-1.5 text-xs text-primary hover:text-primary-hover font-medium transition-colors",children:[i("docBrowserOpenExternal"),t.jsx(ue,{className:"w-3 h-3"})]})}),!c&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"absolute top-0 left-0 w-1.5 h-full cursor-ew-resize z-20 hover:bg-primary/10 transition-colors",onMouseDown:te}),t.jsx("div",{className:"absolute top-0 right-0 w-1.5 h-full cursor-ew-resize z-20 hover:bg-primary/10 transition-colors",onMouseDown:M,"data-axis":"x"}),t.jsx("div",{className:"absolute bottom-0 left-0 h-1.5 w-full cursor-ns-resize z-20 hover:bg-primary/10 transition-colors",onMouseDown:M,"data-axis":"y"}),t.jsx("div",{className:"absolute bottom-0 right-0 w-4 h-4 cursor-se-resize z-30 flex items-center justify-center text-gray-300 hover:text-gray-500 transition-colors",onMouseDown:M,children:t.jsx(me,{className:"w-3 h-3 rotate-[-45deg]"})})]})]})}export{pe as DocBrowser};
1
+ import{r as s,j as t,J as oe,b7 as ae,b8 as ne,ax as W,aj as ie,z as le,b9 as ce,s as de,a7 as ue,ba as me}from"./vendor-CwsIoNvJ.js";import{n as xe,D as Y,t as i,c as X,ah as we}from"./index-CeRbsQ90.js";function pe(){const{isOpen:T,mode:g,tabs:F,activeTabId:N,currentTab:w,currentUrl:l,navVersion:p,close:A,toggleMode:I,goBack:$,goForward:O,canGoBack:_,canGoForward:G,navigate:y,syncUrl:S,setActiveTab:V,closeTab:H,openNewTab:J}=xe(),[k,j]=s.useState(""),[E,C]=s.useState(!1),[q,h]=s.useState(!1),[d,D]=s.useState(()=>({x:Math.max(40,window.innerWidth-520),y:80})),[n,B]=s.useState({w:480,h:600}),[L,K]=s.useState(420),u=s.useRef(null),m=s.useRef(null),b=s.useRef(null),z=s.useRef(null),P=s.useRef(p),a=(w==null?void 0:w.kind)==="docs";s.useEffect(()=>{if(!a){j("");return}try{const e=new URL(l);j(e.pathname)}catch{j(l)}},[l,N,a]),s.useEffect(()=>{var e;if(a){if(p!==P.current){P.current=p;return}if((e=z.current)!=null&&e.contentWindow)try{const r=new URL(l).pathname;z.current.contentWindow.postMessage({type:"docs-navigate",path:r},"*")}catch{}}},[l,p,a]),s.useEffect(()=>{g==="floating"&&D(e=>({x:Math.max(40,window.innerWidth-n.w-40),y:e.y}))},[g,n.w]),s.useEffect(()=>{const e=r=>{var o;a&&((o=r.data)==null?void 0:o.type)==="docs-route-change"&&typeof r.data.url=="string"&&S(r.data.url)};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[S,a]);const Q=s.useCallback(e=>{if(e.preventDefault(),!a)return;const r=k.trim();r&&(r.startsWith("/")?y(`${Y}${r}`):r.startsWith("http")?y(r):y(`${Y}/${r}`))},[k,y,a]),Z=s.useCallback(e=>{g==="floating"&&(C(!0),u.current={startX:e.clientX,startY:e.clientY,startPosX:d.x,startPosY:d.y})},[g,d]);s.useEffect(()=>{if(!E)return;const e=o=>{u.current&&D({x:u.current.startPosX+(o.clientX-u.current.startX),y:u.current.startPosY+(o.clientY-u.current.startY)})},r=()=>{C(!1),u.current=null};return window.addEventListener("mousemove",e),window.addEventListener("mouseup",r),()=>{window.removeEventListener("mousemove",e),window.removeEventListener("mouseup",r)}},[E]);const M=s.useCallback(e=>{e.preventDefault(),e.stopPropagation(),h(!0);const r=e.currentTarget.dataset.axis;m.current={startX:e.clientX,startY:e.clientY,startW:n.w,startH:n.h};const o=x=>{m.current&&B(v=>({w:r==="y"?v.w:Math.max(360,m.current.startW+(x.clientX-m.current.startX)),h:r==="x"?v.h:Math.max(400,m.current.startH+(x.clientY-m.current.startY))}))},f=()=>{h(!1),m.current=null,window.removeEventListener("mousemove",o),window.removeEventListener("mouseup",f)};window.addEventListener("mousemove",o),window.addEventListener("mouseup",f)},[n]),ee=s.useCallback(e=>{e.preventDefault(),e.stopPropagation(),h(!0),b.current={startX:e.clientX,startW:L};const r=f=>{if(!b.current)return;const x=b.current.startX-f.clientX;K(Math.max(320,Math.min(860,b.current.startW+x)))},o=()=>{h(!1),b.current=null,window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",o)};window.addEventListener("mousemove",r),window.addEventListener("mouseup",o)},[L]),te=s.useCallback(e=>{e.preventDefault(),e.stopPropagation(),h(!0);const r=e.clientX,o=n.w,f=d.x,x=re=>{const se=r-re.clientX,U=Math.max(360,o+se);B(R=>({...R,w:U})),D(R=>({...R,x:f-(U-o)}))},v=()=>{h(!1),window.removeEventListener("mousemove",x),window.removeEventListener("mouseup",v)};window.addEventListener("mousemove",x),window.addEventListener("mouseup",v)},[n.w,d.x]);if(!T)return null;const c=g==="docked";return t.jsxs("div",{className:X("flex flex-col bg-white overflow-hidden relative",c?"h-full border-l border-gray-200 shrink-0":"rounded-2xl shadow-2xl border border-gray-200"),style:c?{width:L}:{position:"fixed",left:d.x,top:d.y,width:n.w,height:n.h,zIndex:9999},children:[c&&t.jsx("div",{className:"absolute top-0 left-0 w-1.5 h-full cursor-ew-resize z-20 hover:bg-primary/10 transition-colors",onMouseDown:ee}),t.jsxs("div",{className:X("flex items-center justify-between px-4 py-2.5 bg-gray-50 border-b border-gray-200 shrink-0 select-none",!c&&"cursor-grab active:cursor-grabbing"),onMouseDown:c?void 0:Z,children:[t.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[t.jsx(oe,{className:"w-4 h-4 text-primary shrink-0"}),t.jsx("span",{className:"text-sm font-semibold text-gray-900 truncate",children:i("docBrowserTitle")})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("button",{onClick:I,className:"hover:bg-gray-200 rounded-md p-1.5 text-gray-500 hover:text-gray-700 transition-colors",title:c?i("docBrowserFloatMode"):i("docBrowserDockMode"),children:c?t.jsx(ae,{className:"w-3.5 h-3.5"}):t.jsx(ne,{className:"w-3.5 h-3.5"})}),t.jsx("button",{onClick:A,className:"hover:bg-gray-200 rounded-md p-1.5 text-gray-500 hover:text-gray-700 transition-colors",title:i("docBrowserClose"),children:t.jsx(W,{className:"w-3.5 h-3.5"})})]})]}),t.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-2 bg-white border-b border-gray-100 overflow-x-auto custom-scrollbar",children:[F.map(e=>{const r=e.id===N;return t.jsxs("div",{className:X("inline-flex items-center gap-1 h-7 px-1.5 rounded-lg text-xs border max-w-[220px] shrink-0 transition-colors",r?"bg-blue-50 border-blue-300 text-blue-700":"bg-gray-50 border-gray-200 text-gray-600 hover:bg-gray-100"),children:[t.jsx("button",{type:"button",onClick:()=>V(e.id),className:"truncate text-left px-1",title:e.title,children:e.title||i("docBrowserTabUntitled")}),t.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),H(e.id)},className:"rounded p-0.5 hover:bg-black/10","aria-label":i("docBrowserCloseTab"),children:t.jsx(W,{className:"w-3 h-3"})})]},e.id)}),t.jsx("button",{onClick:()=>J(void 0,{kind:"docs",title:"Docs"}),className:"inline-flex items-center justify-center w-7 h-7 rounded-lg border border-gray-200 bg-white text-gray-600 hover:bg-gray-100 shrink-0",title:i("docBrowserNewTab"),children:t.jsx(ie,{className:"w-3.5 h-3.5"})})]}),a&&t.jsxs("div",{className:"flex items-center gap-2 px-3.5 py-2 bg-white border-b border-gray-100 shrink-0",children:[t.jsx("button",{onClick:$,disabled:!_,className:"p-1.5 rounded-md hover:bg-gray-100 disabled:opacity-30 disabled:cursor-not-allowed text-gray-600 transition-colors",children:t.jsx(le,{className:"w-4 h-4"})}),t.jsx("button",{onClick:O,disabled:!G,className:"p-1.5 rounded-md hover:bg-gray-100 disabled:opacity-30 disabled:cursor-not-allowed text-gray-600 transition-colors",children:t.jsx(ce,{className:"w-4 h-4"})}),t.jsxs("form",{onSubmit:Q,className:"flex-1 relative",children:[t.jsx(de,{className:"w-3.5 h-3.5 absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"}),t.jsx("input",{type:"text",value:k,onChange:e=>j(e.target.value),placeholder:i("docBrowserSearchPlaceholder"),className:"w-full h-8 pl-8 pr-3 rounded-lg bg-gray-50 border border-gray-200 text-xs text-gray-700 focus:outline-none focus:ring-1 focus:ring-primary/30 focus:border-primary/40 transition-colors placeholder:text-gray-400"})]})]}),t.jsxs("div",{className:"flex-1 relative overflow-hidden",children:[t.jsx("iframe",{ref:z,src:l,className:"absolute inset-0 w-full h-full border-0",title:(w==null?void 0:w.title)||"NextClaw Docs",sandbox:"allow-same-origin allow-scripts allow-popups allow-forms",allow:"clipboard-read; clipboard-write"},`${N}:${p}`),(q||E)&&t.jsx("div",{className:"absolute inset-0 z-10"})]}),a&&we(l)&&t.jsx("div",{className:"flex items-center justify-between px-4 py-2 bg-gray-50 border-t border-gray-200 shrink-0",children:t.jsxs("a",{href:l,target:"_blank",rel:"noopener noreferrer","data-doc-external":!0,className:"flex items-center gap-1.5 text-xs text-primary hover:text-primary-hover font-medium transition-colors",children:[i("docBrowserOpenExternal"),t.jsx(ue,{className:"w-3 h-3"})]})}),!c&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"absolute top-0 left-0 w-1.5 h-full cursor-ew-resize z-20 hover:bg-primary/10 transition-colors",onMouseDown:te}),t.jsx("div",{className:"absolute top-0 right-0 w-1.5 h-full cursor-ew-resize z-20 hover:bg-primary/10 transition-colors",onMouseDown:M,"data-axis":"x"}),t.jsx("div",{className:"absolute bottom-0 left-0 h-1.5 w-full cursor-ns-resize z-20 hover:bg-primary/10 transition-colors",onMouseDown:M,"data-axis":"y"}),t.jsx("div",{className:"absolute bottom-0 right-0 w-4 h-4 cursor-se-resize z-30 flex items-center justify-center text-gray-300 hover:text-gray-500 transition-colors",onMouseDown:M,children:t.jsx(me,{className:"w-3 h-3 rotate-[-45deg]"})})]})]})}export{pe as DocBrowser};
@@ -1 +1 @@
1
- import{r as d,j as e}from"./vendor-CwsIoNvJ.js";import{c as t}from"./index-BWvap_iq.js";function x({name:s,src:o,className:a,imgClassName:r,fallback:l}){const[n,i]=d.useState(!1),c=!!o&&!n;return e.jsx("div",{className:t("inline-flex shrink-0 items-center justify-center overflow-hidden",a),children:c?e.jsx("img",{src:o,alt:`${s} logo`,className:t("block h-6 w-6 object-contain",r),onError:()=>i(!0),draggable:!1}):l??e.jsx("span",{className:"text-lg font-bold uppercase",children:s.slice(0,1)})})}export{x as L};
1
+ import{r as d,j as e}from"./vendor-CwsIoNvJ.js";import{c as t}from"./index-CeRbsQ90.js";function x({name:s,src:o,className:a,imgClassName:r,fallback:l}){const[n,i]=d.useState(!1),c=!!o&&!n;return e.jsx("div",{className:t("inline-flex shrink-0 items-center justify-center overflow-hidden",a),children:c?e.jsx("img",{src:o,alt:`${s} logo`,className:t("block h-6 w-6 object-contain",r),onError:()=>i(!0),draggable:!1}):l??e.jsx("span",{className:"text-lg font-bold uppercase",children:s.slice(0,1)})})}export{x as L};
@@ -1,4 +1,4 @@
1
- import{u as Ie,b as Ne,d as Re,e as J,r as i,j as s,aC as et,aA as tt,aB as nt,aD as Ee,aG as at,aE as st,aF as O,aH as Me,aI as rt,aJ as lt,aP as ot,aQ as it,b2 as ct,b3 as ut,aR as dt,b4 as pt,at as ft,au as gt}from"./vendor-CwsIoNvJ.js";import{af as z,t as c,c as Le,S as mt,e as xt,f as ht,g as yt,h as Ce,p as bt,n as kt}from"./index-BWvap_iq.js";import{T as vt}from"./tabs-custom-BB-VjdL2.js";import{P as De}from"./index-Ct7FQpxN.js";import{u as wt}from"./useConfirmDialog-BL5s8KDC.js";import{S as F}from"./skeleton-CiG6msbm.js";import{b as Tt,p as oe}from"./marketplace-localization-Dk31LJJJ.js";import{P as St,a as Ct}from"./page-layout-sNhcbwtm.js";function ne(e){return Array.from(new Set(e.map(t=>t.spec).filter(Boolean)))}function Pt(e){const t=new Date().toISOString();return e.result.type==="skill"?{type:"skill",spec:e.result.spec,id:e.request.skill??e.result.spec,label:e.request.skill??e.result.name??e.result.spec,source:"workspace",installPath:e.request.installPath,installedAt:t}:{type:e.result.type,spec:e.result.spec,id:e.result.name??e.result.spec,label:e.result.name??e.result.spec,source:"marketplace",origin:"marketplace",enabled:e.request.enabled??!0,runtimeStatus:e.request.enabled===!1?"disabled":"ready",installedAt:t}}function ae(e,t){return!!(t.spec&&e.spec===t.spec||t.id&&e.id===t.id)}function $e(e,t){return t??{type:e,total:0,specs:[],records:[]}}function jt(e){const t=$e(e.result.type,e.view),n=Pt(e),a=t.records.findIndex(l=>ae(l,{id:n.id,spec:n.spec})),r=[...t.records];return a>=0?r[a]={...r[a],...n}:r.unshift(n),{...t,type:e.result.type,records:r,specs:ne(r),total:r.length}}function It(e){const t=$e(e.result.type,e.view);if(e.result.action==="uninstall"||e.result.action==="remove"){const a=t.records.filter(r=>!ae(r,{id:e.result.id,spec:e.request.spec}));return{...t,records:a,specs:ne(a),total:a.length}}const n=t.records.map(a=>ae(a,{id:e.result.id,spec:e.request.spec})?e.result.action==="disable"?{...a,enabled:!1,runtimeStatus:"disabled"}:{...a,enabled:!0,runtimeStatus:"ready"}:a);return{...t,records:n,specs:ne(n),total:n.length}}function Y(e){return e==="plugin"?"plugins":e==="skill"?"skills":"mcp"}async function Nt(e){var l,f;const t=new URLSearchParams,n=Y(e.type);(l=e.q)!=null&&l.trim()&&t.set("q",e.q.trim()),(f=e.tag)!=null&&f.trim()&&t.set("tag",e.tag.trim()),e.sort&&t.set("sort",e.sort),typeof e.page=="number"&&Number.isFinite(e.page)&&t.set("page",String(Math.max(1,Math.trunc(e.page)))),typeof e.pageSize=="number"&&Number.isFinite(e.pageSize)&&t.set("pageSize",String(Math.max(1,Math.trunc(e.pageSize))));const a=t.toString(),r=await z.get(a?`/api/marketplace/${n}/items?${a}`:`/api/marketplace/${n}/items`);if(!r.ok)throw new Error(r.error.message);return r.data}async function Rt(e){const t=await z.get(`/api/marketplace/skills/items/${encodeURIComponent(e)}/content`);if(!t.ok)throw new Error(t.error.message);return t.data}async function Et(e){const t=await z.get(`/api/marketplace/plugins/items/${encodeURIComponent(e)}/content`);if(!t.ok)throw new Error(t.error.message);return t.data}async function Mt(e){const t=Y(e.type),n=await z.post(`/api/marketplace/${t}/install`,e);if(!n.ok)throw new Error(n.error.message);return n.data}async function Lt(e){const t=Y(e),n=await z.get(`/api/marketplace/${t}/installed`);if(!n.ok)throw new Error(n.error.message);return n.data}async function Dt(e){const t=Y(e.type),n=await z.post(`/api/marketplace/${t}/manage`,e);if(!n.ok)throw new Error(n.error.message);return n.data}function $t(e){return Ie({queryKey:["marketplace-items",e],queryFn:()=>Nt(e),placeholderData:(t,n)=>{var l;const a=(l=n==null?void 0:n.queryKey)==null?void 0:l[1];return!a||typeof a!="object"||a===null?void 0:("type"in a?a.type:void 0)===e.type?t:void 0},staleTime:15e3})}function _t(e){return Ie({queryKey:["marketplace-installed",e],queryFn:()=>Lt(e),staleTime:1e4})}function At(){const e=Ne();return Re({mutationFn:t=>Mt(t),onSuccess:(t,n)=>{e.setQueryData(["marketplace-installed",t.type],r=>jt({view:r,request:n,result:t})),e.invalidateQueries({queryKey:["marketplace-installed",t.type],refetchType:"inactive"}),t.type==="plugin"&&e.invalidateQueries({queryKey:["ncp-session-types"]});const a=t.type==="plugin"?c("marketplaceInstallSuccessPlugin"):c("marketplaceInstallSuccessSkill");J.success(t.message||a)},onError:t=>{J.error(t.message||c("marketplaceInstallFailed"))}})}function Ot(){const e=Ne();return Re({mutationFn:t=>Dt(t),onSuccess:(t,n)=>{e.setQueryData(["marketplace-installed",t.type],r=>It({view:r,request:n,result:t})),e.invalidateQueries({queryKey:["marketplace-installed",t.type],refetchType:"inactive"}),t.type==="plugin"&&e.invalidateQueries({queryKey:["ncp-session-types"]});const a=t.action==="enable"?c("marketplaceEnableSuccess"):t.action==="disable"?c("marketplaceDisableSuccess"):c("marketplaceUninstallSuccess");J.success(t.message||a)},onError:t=>{J.error(t.message||c("marketplaceOperationFailed"))}})}var[X]=lt("Tooltip",[Me]),W=Me(),_e="TooltipProvider",Ft=700,se="tooltip.open",[Ut,ie]=X(_e),Ae=e=>{const{__scopeTooltip:t,delayDuration:n=Ft,skipDelayDuration:a=300,disableHoverableContent:r=!1,children:l}=e,f=i.useRef(!0),g=i.useRef(!1),d=i.useRef(0);return i.useEffect(()=>{const k=d.current;return()=>window.clearTimeout(k)},[]),s.jsx(Ut,{scope:t,isOpenDelayedRef:f,delayDuration:n,onOpen:i.useCallback(()=>{window.clearTimeout(d.current),f.current=!1},[]),onClose:i.useCallback(()=>{window.clearTimeout(d.current),d.current=window.setTimeout(()=>f.current=!0,a)},[a]),isPointerInTransitRef:g,onPointerInTransitChange:i.useCallback(k=>{g.current=k},[]),disableHoverableContent:r,children:l})};Ae.displayName=_e;var K="Tooltip",[qt,G]=X(K),Oe=e=>{const{__scopeTooltip:t,children:n,open:a,defaultOpen:r,onOpenChange:l,disableHoverableContent:f,delayDuration:g}=e,d=ie(K,e.__scopeTooltip),k=W(t),[u,b]=i.useState(null),v=et(),h=i.useRef(0),w=f??d.disableHoverableContent,m=g??d.delayDuration,S=i.useRef(!1),[j,P]=tt({prop:a,defaultProp:r??!1,onChange:M=>{M?(d.onOpen(),document.dispatchEvent(new CustomEvent(se))):d.onClose(),l==null||l(M)},caller:K}),L=i.useMemo(()=>j?S.current?"delayed-open":"instant-open":"closed",[j]),C=i.useCallback(()=>{window.clearTimeout(h.current),h.current=0,S.current=!1,P(!0)},[P]),E=i.useCallback(()=>{window.clearTimeout(h.current),h.current=0,P(!1)},[P]),$=i.useCallback(()=>{window.clearTimeout(h.current),h.current=window.setTimeout(()=>{S.current=!0,P(!0),h.current=0},m)},[m,P]);return i.useEffect(()=>()=>{h.current&&(window.clearTimeout(h.current),h.current=0)},[]),s.jsx(nt,{...k,children:s.jsx(qt,{scope:t,contentId:v,open:j,stateAttribute:L,trigger:u,onTriggerChange:b,onTriggerEnter:i.useCallback(()=>{d.isOpenDelayedRef.current?$():C()},[d.isOpenDelayedRef,$,C]),onTriggerLeave:i.useCallback(()=>{w?E():(window.clearTimeout(h.current),h.current=0)},[E,w]),onOpen:C,onClose:E,disableHoverableContent:w,children:n})})};Oe.displayName=K;var re="TooltipTrigger",Fe=i.forwardRef((e,t)=>{const{__scopeTooltip:n,...a}=e,r=G(re,n),l=ie(re,n),f=W(n),g=i.useRef(null),d=Ee(t,g,r.onTriggerChange),k=i.useRef(!1),u=i.useRef(!1),b=i.useCallback(()=>k.current=!1,[]);return i.useEffect(()=>()=>document.removeEventListener("pointerup",b),[b]),s.jsx(at,{asChild:!0,...f,children:s.jsx(st.button,{"aria-describedby":r.open?r.contentId:void 0,"data-state":r.stateAttribute,...a,ref:d,onPointerMove:O(e.onPointerMove,v=>{v.pointerType!=="touch"&&!u.current&&!l.isPointerInTransitRef.current&&(r.onTriggerEnter(),u.current=!0)}),onPointerLeave:O(e.onPointerLeave,()=>{r.onTriggerLeave(),u.current=!1}),onPointerDown:O(e.onPointerDown,()=>{r.open&&r.onClose(),k.current=!0,document.addEventListener("pointerup",b,{once:!0})}),onFocus:O(e.onFocus,()=>{k.current||r.onOpen()}),onBlur:O(e.onBlur,r.onClose),onClick:O(e.onClick,r.onClose)})})});Fe.displayName=re;var ce="TooltipPortal",[zt,Ht]=X(ce,{forceMount:void 0}),Ue=e=>{const{__scopeTooltip:t,forceMount:n,children:a,container:r}=e,l=G(ce,t);return s.jsx(zt,{scope:t,forceMount:n,children:s.jsx(De,{present:n||l.open,children:s.jsx(rt,{asChild:!0,container:r,children:a})})})};Ue.displayName=ce;var q="TooltipContent",qe=i.forwardRef((e,t)=>{const n=Ht(q,e.__scopeTooltip),{forceMount:a=n.forceMount,side:r="top",...l}=e,f=G(q,e.__scopeTooltip);return s.jsx(De,{present:a||f.open,children:f.disableHoverableContent?s.jsx(ze,{side:r,...l,ref:t}):s.jsx(Bt,{side:r,...l,ref:t})})}),Bt=i.forwardRef((e,t)=>{const n=G(q,e.__scopeTooltip),a=ie(q,e.__scopeTooltip),r=i.useRef(null),l=Ee(t,r),[f,g]=i.useState(null),{trigger:d,onClose:k}=n,u=r.current,{onPointerInTransitChange:b}=a,v=i.useCallback(()=>{g(null),b(!1)},[b]),h=i.useCallback((w,m)=>{const S=w.currentTarget,j={x:w.clientX,y:w.clientY},P=Jt(j,S.getBoundingClientRect()),L=Yt(j,P),C=Xt(m.getBoundingClientRect()),E=Zt([...L,...C]);g(E),b(!0)},[b]);return i.useEffect(()=>()=>v(),[v]),i.useEffect(()=>{if(d&&u){const w=S=>h(S,u),m=S=>h(S,d);return d.addEventListener("pointerleave",w),u.addEventListener("pointerleave",m),()=>{d.removeEventListener("pointerleave",w),u.removeEventListener("pointerleave",m)}}},[d,u,h,v]),i.useEffect(()=>{if(f){const w=m=>{const S=m.target,j={x:m.clientX,y:m.clientY},P=(d==null?void 0:d.contains(S))||(u==null?void 0:u.contains(S)),L=!Wt(j,f);P?v():L&&(v(),k())};return document.addEventListener("pointermove",w),()=>document.removeEventListener("pointermove",w)}},[d,u,f,k,v]),s.jsx(ze,{...e,ref:l})}),[Kt,Gt]=X(K,{isInside:!1}),Vt=ut("TooltipContent"),ze=i.forwardRef((e,t)=>{const{__scopeTooltip:n,children:a,"aria-label":r,onEscapeKeyDown:l,onPointerDownOutside:f,...g}=e,d=G(q,n),k=W(n),{onClose:u}=d;return i.useEffect(()=>(document.addEventListener(se,u),()=>document.removeEventListener(se,u)),[u]),i.useEffect(()=>{if(d.trigger){const b=v=>{const h=v.target;h!=null&&h.contains(d.trigger)&&u()};return window.addEventListener("scroll",b,{capture:!0}),()=>window.removeEventListener("scroll",b,{capture:!0})}},[d.trigger,u]),s.jsx(ot,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:l,onPointerDownOutside:f,onFocusOutside:b=>b.preventDefault(),onDismiss:u,children:s.jsxs(it,{"data-state":d.stateAttribute,...k,...g,ref:t,style:{...g.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[s.jsx(Vt,{children:a}),s.jsx(Kt,{scope:n,isInside:!0,children:s.jsx(ct,{id:d.contentId,role:"tooltip",children:r||a})})]})})});qe.displayName=q;var He="TooltipArrow",Qt=i.forwardRef((e,t)=>{const{__scopeTooltip:n,...a}=e,r=W(n);return Gt(He,n).isInside?null:s.jsx(dt,{...r,...a,ref:t})});Qt.displayName=He;function Jt(e,t){const n=Math.abs(t.top-e.y),a=Math.abs(t.bottom-e.y),r=Math.abs(t.right-e.x),l=Math.abs(t.left-e.x);switch(Math.min(n,a,r,l)){case l:return"left";case r:return"right";case n:return"top";case a:return"bottom";default:throw new Error("unreachable")}}function Yt(e,t,n=5){const a=[];switch(t){case"top":a.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case"bottom":a.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case"left":a.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case"right":a.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return a}function Xt(e){const{top:t,right:n,bottom:a,left:r}=e;return[{x:r,y:t},{x:n,y:t},{x:n,y:a},{x:r,y:a}]}function Wt(e,t){const{x:n,y:a}=e;let r=!1;for(let l=0,f=t.length-1;l<t.length;f=l++){const g=t[l],d=t[f],k=g.x,u=g.y,b=d.x,v=d.y;u>a!=v>a&&n<(b-k)*(a-u)/(v-u)+k&&(r=!r)}return r}function Zt(e){const t=e.slice();return t.sort((n,a)=>n.x<a.x?-1:n.x>a.x?1:n.y<a.y?-1:n.y>a.y?1:0),en(t)}function en(e){if(e.length<=1)return e.slice();const t=[];for(let a=0;a<e.length;a++){const r=e[a];for(;t.length>=2;){const l=t[t.length-1],f=t[t.length-2];if((l.x-f.x)*(r.y-f.y)>=(l.y-f.y)*(r.x-f.x))t.pop();else break}t.push(r)}t.pop();const n=[];for(let a=e.length-1;a>=0;a--){const r=e[a];for(;n.length>=2;){const l=n[n.length-1],f=n[n.length-2];if((l.x-f.x)*(r.y-f.y)>=(l.y-f.y)*(r.x-f.x))n.pop();else break}n.push(r)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}var tn=Ae,nn=Oe,an=Fe,sn=Ue,Be=qe;const rn=tn,ee=nn,te=an,Q=i.forwardRef(({className:e,sideOffset:t=4,...n},a)=>s.jsx(sn,{children:s.jsx(Be,{ref:a,sideOffset:t,className:Le("z-[var(--z-tooltip)] overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));Q.displayName=Be.displayName;function ln(e){return s.jsx("div",{className:"mb-4",children:s.jsxs("div",{className:"flex gap-3 items-center",children:[s.jsxs("div",{className:"flex-1 min-w-0 relative",children:[s.jsx(pt,{className:"h-4 w-4 text-gray-400 absolute left-3 top-1/2 -translate-y-1/2"}),s.jsx("input",{value:e.searchText,onChange:t=>e.onSearchTextChange(t.target.value),placeholder:e.searchPlaceholder,className:"w-full h-9 border border-gray-200/80 rounded-xl pl-9 pr-3 text-sm focus:outline-none focus:ring-1 focus:ring-primary/40"})]}),e.scope==="all"&&s.jsxs(mt,{value:e.sort,onValueChange:t=>e.onSortChange(t),children:[s.jsx(xt,{className:"h-9 w-[150px] shrink-0 rounded-lg",children:s.jsx(ht,{})}),s.jsxs(yt,{children:[s.jsx(Ce,{value:"relevance",children:c("marketplaceSortRelevance")}),s.jsx(Ce,{value:"updated",children:c("marketplaceSortUpdated")})]})]})]})})}function on(e){return s.jsx(s.Fragment,{children:Array.from({length:e.count},(t,n)=>s.jsx("article",{className:"rounded-2xl border border-gray-200/40 bg-white px-5 py-4 shadow-sm",children:s.jsxs("div",{className:"flex items-start gap-3.5 justify-between",children:[s.jsxs("div",{className:"flex min-w-0 flex-1 gap-3",children:[s.jsx(F,{className:"h-10 w-10 shrink-0 rounded-xl"}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-2 pt-0.5",children:[s.jsx(F,{className:"h-4 w-32 max-w-[70%]"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(F,{className:"h-3 w-12"}),s.jsx(F,{className:"h-3 w-24"})]}),s.jsx(F,{className:"h-3 w-full"})]})]}),s.jsx(F,{className:"h-8 w-20 shrink-0 rounded-xl"})]})},`marketplace-skeleton-${n}`))})}function cn(e){return s.jsxs("div",{className:"mt-4 flex items-center justify-end gap-2",children:[s.jsx("button",{className:"h-8 px-3 rounded-xl border border-gray-200/80 text-sm text-gray-600 disabled:opacity-40",onClick:e.onPrev,disabled:e.page<=1||e.busy,children:c("prev")}),s.jsx("div",{className:"text-sm text-gray-600 min-w-20 text-center",children:e.totalPages===0?"0 / 0":`${e.page} / ${e.totalPages}`}),s.jsx("button",{className:"h-8 px-3 rounded-xl border border-gray-200/80 text-sm text-gray-600 disabled:opacity-40",onClick:e.onNext,disabled:e.totalPages===0||e.page>=e.totalPages||e.busy,children:c("next")})]})}const Ke=12,un=Ke;function le(e){return(e??"").trim().toLowerCase()}function U(e,t){const n=le(t);return n.length>0?`${e}:${n}`:""}function dn(e){const t=new Map;for(const n of e){const a=[n.install.spec,n.slug,n.id];for(const r of a){const l=U(n.type,r);!l||t.has(l)||t.set(l,n)}}return t}function pn(e){const t=new Map;for(const n of e){const a=[n.spec,n.id,n.label];for(const r of a){const l=U(n.type,r);!l||t.has(l)||t.set(l,n)}}return t}function Pe(e,t){const n=[e.install.spec,e.slug,e.id];for(const a of n){const r=U(e.type,a);if(!r)continue;const l=t.get(r);if(l)return l}}function fn(e,t){const n=t.get(U(e.type,e.spec));if(n)return n;const a=t.get(U(e.type,e.id));return a||t.get(U(e.type,e.label))}function gn(e,t,n,a){const r=le(n);if(!r)return!0;const l=oe(t==null?void 0:t.summaryI18n,t==null?void 0:t.summary,a);return[e.id,e.spec,e.label,t==null?void 0:t.name,t==null?void 0:t.slug,t==null?void 0:t.summary,l,...(t==null?void 0:t.tags)??[]].map(g=>le(g)).filter(Boolean).some(g=>g.includes(r))}function mn(e){const t=["bg-amber-600","bg-orange-500","bg-yellow-600","bg-emerald-600","bg-teal-600","bg-cyan-600","bg-stone-600","bg-rose-500","bg-violet-500"];let n=0;for(let a=0;a<e.length;a++)n=e.charCodeAt(a)+((n<<5)-n);return t[Math.abs(n)%t.length]}function xn({name:e,fallback:t}){const n=e||t,a=n.substring(0,2).toUpperCase(),r=mn(n);return s.jsx("div",{className:Le("flex items-center justify-center w-10 h-10 rounded-xl text-white font-semibold text-sm shrink-0",r),children:a})}function I(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function B(e){var g,d,k,u;const t=((g=e.metadataRaw)==null?void 0:g.trim())||"-",n=((d=e.contentRaw)==null?void 0:d.trim())||"-",a=(k=e.summary)==null?void 0:k.trim(),r=(u=e.description)==null?void 0:u.trim(),l=!!r&&r!==a,f=`<!doctype html>
1
+ import{u as Ie,b as Ne,d as Re,e as J,r as i,j as s,aC as et,aA as tt,aB as nt,aD as Ee,aG as at,aE as st,aF as O,aH as Me,aI as rt,aJ as lt,aP as ot,aQ as it,b2 as ct,b3 as ut,aR as dt,b4 as pt,at as ft,au as gt}from"./vendor-CwsIoNvJ.js";import{af as z,t as c,c as Le,S as mt,e as xt,f as ht,g as yt,h as Ce,p as bt,n as kt}from"./index-CeRbsQ90.js";import{T as vt}from"./tabs-custom-6Tm1ZHfS.js";import{P as De}from"./index-Ct7FQpxN.js";import{u as wt}from"./useConfirmDialog-BeOW2bOI.js";import{S as F}from"./skeleton-IOOTmHzP.js";import{b as Tt,p as oe}from"./marketplace-localization-Dk31LJJJ.js";import{P as St,a as Ct}from"./page-layout-ud8wZ8gX.js";function ne(e){return Array.from(new Set(e.map(t=>t.spec).filter(Boolean)))}function Pt(e){const t=new Date().toISOString();return e.result.type==="skill"?{type:"skill",spec:e.result.spec,id:e.request.skill??e.result.spec,label:e.request.skill??e.result.name??e.result.spec,source:"workspace",installPath:e.request.installPath,installedAt:t}:{type:e.result.type,spec:e.result.spec,id:e.result.name??e.result.spec,label:e.result.name??e.result.spec,source:"marketplace",origin:"marketplace",enabled:e.request.enabled??!0,runtimeStatus:e.request.enabled===!1?"disabled":"ready",installedAt:t}}function ae(e,t){return!!(t.spec&&e.spec===t.spec||t.id&&e.id===t.id)}function $e(e,t){return t??{type:e,total:0,specs:[],records:[]}}function jt(e){const t=$e(e.result.type,e.view),n=Pt(e),a=t.records.findIndex(l=>ae(l,{id:n.id,spec:n.spec})),r=[...t.records];return a>=0?r[a]={...r[a],...n}:r.unshift(n),{...t,type:e.result.type,records:r,specs:ne(r),total:r.length}}function It(e){const t=$e(e.result.type,e.view);if(e.result.action==="uninstall"||e.result.action==="remove"){const a=t.records.filter(r=>!ae(r,{id:e.result.id,spec:e.request.spec}));return{...t,records:a,specs:ne(a),total:a.length}}const n=t.records.map(a=>ae(a,{id:e.result.id,spec:e.request.spec})?e.result.action==="disable"?{...a,enabled:!1,runtimeStatus:"disabled"}:{...a,enabled:!0,runtimeStatus:"ready"}:a);return{...t,records:n,specs:ne(n),total:n.length}}function Y(e){return e==="plugin"?"plugins":e==="skill"?"skills":"mcp"}async function Nt(e){var l,f;const t=new URLSearchParams,n=Y(e.type);(l=e.q)!=null&&l.trim()&&t.set("q",e.q.trim()),(f=e.tag)!=null&&f.trim()&&t.set("tag",e.tag.trim()),e.sort&&t.set("sort",e.sort),typeof e.page=="number"&&Number.isFinite(e.page)&&t.set("page",String(Math.max(1,Math.trunc(e.page)))),typeof e.pageSize=="number"&&Number.isFinite(e.pageSize)&&t.set("pageSize",String(Math.max(1,Math.trunc(e.pageSize))));const a=t.toString(),r=await z.get(a?`/api/marketplace/${n}/items?${a}`:`/api/marketplace/${n}/items`);if(!r.ok)throw new Error(r.error.message);return r.data}async function Rt(e){const t=await z.get(`/api/marketplace/skills/items/${encodeURIComponent(e)}/content`);if(!t.ok)throw new Error(t.error.message);return t.data}async function Et(e){const t=await z.get(`/api/marketplace/plugins/items/${encodeURIComponent(e)}/content`);if(!t.ok)throw new Error(t.error.message);return t.data}async function Mt(e){const t=Y(e.type),n=await z.post(`/api/marketplace/${t}/install`,e);if(!n.ok)throw new Error(n.error.message);return n.data}async function Lt(e){const t=Y(e),n=await z.get(`/api/marketplace/${t}/installed`);if(!n.ok)throw new Error(n.error.message);return n.data}async function Dt(e){const t=Y(e.type),n=await z.post(`/api/marketplace/${t}/manage`,e);if(!n.ok)throw new Error(n.error.message);return n.data}function $t(e){return Ie({queryKey:["marketplace-items",e],queryFn:()=>Nt(e),placeholderData:(t,n)=>{var l;const a=(l=n==null?void 0:n.queryKey)==null?void 0:l[1];return!a||typeof a!="object"||a===null?void 0:("type"in a?a.type:void 0)===e.type?t:void 0},staleTime:15e3})}function _t(e){return Ie({queryKey:["marketplace-installed",e],queryFn:()=>Lt(e),staleTime:1e4})}function At(){const e=Ne();return Re({mutationFn:t=>Mt(t),onSuccess:(t,n)=>{e.setQueryData(["marketplace-installed",t.type],r=>jt({view:r,request:n,result:t})),e.invalidateQueries({queryKey:["marketplace-installed",t.type],refetchType:"inactive"}),t.type==="plugin"&&e.invalidateQueries({queryKey:["ncp-session-types"]});const a=t.type==="plugin"?c("marketplaceInstallSuccessPlugin"):c("marketplaceInstallSuccessSkill");J.success(t.message||a)},onError:t=>{J.error(t.message||c("marketplaceInstallFailed"))}})}function Ot(){const e=Ne();return Re({mutationFn:t=>Dt(t),onSuccess:(t,n)=>{e.setQueryData(["marketplace-installed",t.type],r=>It({view:r,request:n,result:t})),e.invalidateQueries({queryKey:["marketplace-installed",t.type],refetchType:"inactive"}),t.type==="plugin"&&e.invalidateQueries({queryKey:["ncp-session-types"]});const a=t.action==="enable"?c("marketplaceEnableSuccess"):t.action==="disable"?c("marketplaceDisableSuccess"):c("marketplaceUninstallSuccess");J.success(t.message||a)},onError:t=>{J.error(t.message||c("marketplaceOperationFailed"))}})}var[X]=lt("Tooltip",[Me]),W=Me(),_e="TooltipProvider",Ft=700,se="tooltip.open",[Ut,ie]=X(_e),Ae=e=>{const{__scopeTooltip:t,delayDuration:n=Ft,skipDelayDuration:a=300,disableHoverableContent:r=!1,children:l}=e,f=i.useRef(!0),g=i.useRef(!1),d=i.useRef(0);return i.useEffect(()=>{const k=d.current;return()=>window.clearTimeout(k)},[]),s.jsx(Ut,{scope:t,isOpenDelayedRef:f,delayDuration:n,onOpen:i.useCallback(()=>{window.clearTimeout(d.current),f.current=!1},[]),onClose:i.useCallback(()=>{window.clearTimeout(d.current),d.current=window.setTimeout(()=>f.current=!0,a)},[a]),isPointerInTransitRef:g,onPointerInTransitChange:i.useCallback(k=>{g.current=k},[]),disableHoverableContent:r,children:l})};Ae.displayName=_e;var K="Tooltip",[qt,G]=X(K),Oe=e=>{const{__scopeTooltip:t,children:n,open:a,defaultOpen:r,onOpenChange:l,disableHoverableContent:f,delayDuration:g}=e,d=ie(K,e.__scopeTooltip),k=W(t),[u,b]=i.useState(null),v=et(),h=i.useRef(0),w=f??d.disableHoverableContent,m=g??d.delayDuration,S=i.useRef(!1),[j,P]=tt({prop:a,defaultProp:r??!1,onChange:M=>{M?(d.onOpen(),document.dispatchEvent(new CustomEvent(se))):d.onClose(),l==null||l(M)},caller:K}),L=i.useMemo(()=>j?S.current?"delayed-open":"instant-open":"closed",[j]),C=i.useCallback(()=>{window.clearTimeout(h.current),h.current=0,S.current=!1,P(!0)},[P]),E=i.useCallback(()=>{window.clearTimeout(h.current),h.current=0,P(!1)},[P]),$=i.useCallback(()=>{window.clearTimeout(h.current),h.current=window.setTimeout(()=>{S.current=!0,P(!0),h.current=0},m)},[m,P]);return i.useEffect(()=>()=>{h.current&&(window.clearTimeout(h.current),h.current=0)},[]),s.jsx(nt,{...k,children:s.jsx(qt,{scope:t,contentId:v,open:j,stateAttribute:L,trigger:u,onTriggerChange:b,onTriggerEnter:i.useCallback(()=>{d.isOpenDelayedRef.current?$():C()},[d.isOpenDelayedRef,$,C]),onTriggerLeave:i.useCallback(()=>{w?E():(window.clearTimeout(h.current),h.current=0)},[E,w]),onOpen:C,onClose:E,disableHoverableContent:w,children:n})})};Oe.displayName=K;var re="TooltipTrigger",Fe=i.forwardRef((e,t)=>{const{__scopeTooltip:n,...a}=e,r=G(re,n),l=ie(re,n),f=W(n),g=i.useRef(null),d=Ee(t,g,r.onTriggerChange),k=i.useRef(!1),u=i.useRef(!1),b=i.useCallback(()=>k.current=!1,[]);return i.useEffect(()=>()=>document.removeEventListener("pointerup",b),[b]),s.jsx(at,{asChild:!0,...f,children:s.jsx(st.button,{"aria-describedby":r.open?r.contentId:void 0,"data-state":r.stateAttribute,...a,ref:d,onPointerMove:O(e.onPointerMove,v=>{v.pointerType!=="touch"&&!u.current&&!l.isPointerInTransitRef.current&&(r.onTriggerEnter(),u.current=!0)}),onPointerLeave:O(e.onPointerLeave,()=>{r.onTriggerLeave(),u.current=!1}),onPointerDown:O(e.onPointerDown,()=>{r.open&&r.onClose(),k.current=!0,document.addEventListener("pointerup",b,{once:!0})}),onFocus:O(e.onFocus,()=>{k.current||r.onOpen()}),onBlur:O(e.onBlur,r.onClose),onClick:O(e.onClick,r.onClose)})})});Fe.displayName=re;var ce="TooltipPortal",[zt,Ht]=X(ce,{forceMount:void 0}),Ue=e=>{const{__scopeTooltip:t,forceMount:n,children:a,container:r}=e,l=G(ce,t);return s.jsx(zt,{scope:t,forceMount:n,children:s.jsx(De,{present:n||l.open,children:s.jsx(rt,{asChild:!0,container:r,children:a})})})};Ue.displayName=ce;var q="TooltipContent",qe=i.forwardRef((e,t)=>{const n=Ht(q,e.__scopeTooltip),{forceMount:a=n.forceMount,side:r="top",...l}=e,f=G(q,e.__scopeTooltip);return s.jsx(De,{present:a||f.open,children:f.disableHoverableContent?s.jsx(ze,{side:r,...l,ref:t}):s.jsx(Bt,{side:r,...l,ref:t})})}),Bt=i.forwardRef((e,t)=>{const n=G(q,e.__scopeTooltip),a=ie(q,e.__scopeTooltip),r=i.useRef(null),l=Ee(t,r),[f,g]=i.useState(null),{trigger:d,onClose:k}=n,u=r.current,{onPointerInTransitChange:b}=a,v=i.useCallback(()=>{g(null),b(!1)},[b]),h=i.useCallback((w,m)=>{const S=w.currentTarget,j={x:w.clientX,y:w.clientY},P=Jt(j,S.getBoundingClientRect()),L=Yt(j,P),C=Xt(m.getBoundingClientRect()),E=Zt([...L,...C]);g(E),b(!0)},[b]);return i.useEffect(()=>()=>v(),[v]),i.useEffect(()=>{if(d&&u){const w=S=>h(S,u),m=S=>h(S,d);return d.addEventListener("pointerleave",w),u.addEventListener("pointerleave",m),()=>{d.removeEventListener("pointerleave",w),u.removeEventListener("pointerleave",m)}}},[d,u,h,v]),i.useEffect(()=>{if(f){const w=m=>{const S=m.target,j={x:m.clientX,y:m.clientY},P=(d==null?void 0:d.contains(S))||(u==null?void 0:u.contains(S)),L=!Wt(j,f);P?v():L&&(v(),k())};return document.addEventListener("pointermove",w),()=>document.removeEventListener("pointermove",w)}},[d,u,f,k,v]),s.jsx(ze,{...e,ref:l})}),[Kt,Gt]=X(K,{isInside:!1}),Vt=ut("TooltipContent"),ze=i.forwardRef((e,t)=>{const{__scopeTooltip:n,children:a,"aria-label":r,onEscapeKeyDown:l,onPointerDownOutside:f,...g}=e,d=G(q,n),k=W(n),{onClose:u}=d;return i.useEffect(()=>(document.addEventListener(se,u),()=>document.removeEventListener(se,u)),[u]),i.useEffect(()=>{if(d.trigger){const b=v=>{const h=v.target;h!=null&&h.contains(d.trigger)&&u()};return window.addEventListener("scroll",b,{capture:!0}),()=>window.removeEventListener("scroll",b,{capture:!0})}},[d.trigger,u]),s.jsx(ot,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:l,onPointerDownOutside:f,onFocusOutside:b=>b.preventDefault(),onDismiss:u,children:s.jsxs(it,{"data-state":d.stateAttribute,...k,...g,ref:t,style:{...g.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[s.jsx(Vt,{children:a}),s.jsx(Kt,{scope:n,isInside:!0,children:s.jsx(ct,{id:d.contentId,role:"tooltip",children:r||a})})]})})});qe.displayName=q;var He="TooltipArrow",Qt=i.forwardRef((e,t)=>{const{__scopeTooltip:n,...a}=e,r=W(n);return Gt(He,n).isInside?null:s.jsx(dt,{...r,...a,ref:t})});Qt.displayName=He;function Jt(e,t){const n=Math.abs(t.top-e.y),a=Math.abs(t.bottom-e.y),r=Math.abs(t.right-e.x),l=Math.abs(t.left-e.x);switch(Math.min(n,a,r,l)){case l:return"left";case r:return"right";case n:return"top";case a:return"bottom";default:throw new Error("unreachable")}}function Yt(e,t,n=5){const a=[];switch(t){case"top":a.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case"bottom":a.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case"left":a.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case"right":a.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return a}function Xt(e){const{top:t,right:n,bottom:a,left:r}=e;return[{x:r,y:t},{x:n,y:t},{x:n,y:a},{x:r,y:a}]}function Wt(e,t){const{x:n,y:a}=e;let r=!1;for(let l=0,f=t.length-1;l<t.length;f=l++){const g=t[l],d=t[f],k=g.x,u=g.y,b=d.x,v=d.y;u>a!=v>a&&n<(b-k)*(a-u)/(v-u)+k&&(r=!r)}return r}function Zt(e){const t=e.slice();return t.sort((n,a)=>n.x<a.x?-1:n.x>a.x?1:n.y<a.y?-1:n.y>a.y?1:0),en(t)}function en(e){if(e.length<=1)return e.slice();const t=[];for(let a=0;a<e.length;a++){const r=e[a];for(;t.length>=2;){const l=t[t.length-1],f=t[t.length-2];if((l.x-f.x)*(r.y-f.y)>=(l.y-f.y)*(r.x-f.x))t.pop();else break}t.push(r)}t.pop();const n=[];for(let a=e.length-1;a>=0;a--){const r=e[a];for(;n.length>=2;){const l=n[n.length-1],f=n[n.length-2];if((l.x-f.x)*(r.y-f.y)>=(l.y-f.y)*(r.x-f.x))n.pop();else break}n.push(r)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}var tn=Ae,nn=Oe,an=Fe,sn=Ue,Be=qe;const rn=tn,ee=nn,te=an,Q=i.forwardRef(({className:e,sideOffset:t=4,...n},a)=>s.jsx(sn,{children:s.jsx(Be,{ref:a,sideOffset:t,className:Le("z-[var(--z-tooltip)] overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));Q.displayName=Be.displayName;function ln(e){return s.jsx("div",{className:"mb-4",children:s.jsxs("div",{className:"flex gap-3 items-center",children:[s.jsxs("div",{className:"flex-1 min-w-0 relative",children:[s.jsx(pt,{className:"h-4 w-4 text-gray-400 absolute left-3 top-1/2 -translate-y-1/2"}),s.jsx("input",{value:e.searchText,onChange:t=>e.onSearchTextChange(t.target.value),placeholder:e.searchPlaceholder,className:"w-full h-9 border border-gray-200/80 rounded-xl pl-9 pr-3 text-sm focus:outline-none focus:ring-1 focus:ring-primary/40"})]}),e.scope==="all"&&s.jsxs(mt,{value:e.sort,onValueChange:t=>e.onSortChange(t),children:[s.jsx(xt,{className:"h-9 w-[150px] shrink-0 rounded-lg",children:s.jsx(ht,{})}),s.jsxs(yt,{children:[s.jsx(Ce,{value:"relevance",children:c("marketplaceSortRelevance")}),s.jsx(Ce,{value:"updated",children:c("marketplaceSortUpdated")})]})]})]})})}function on(e){return s.jsx(s.Fragment,{children:Array.from({length:e.count},(t,n)=>s.jsx("article",{className:"rounded-2xl border border-gray-200/40 bg-white px-5 py-4 shadow-sm",children:s.jsxs("div",{className:"flex items-start gap-3.5 justify-between",children:[s.jsxs("div",{className:"flex min-w-0 flex-1 gap-3",children:[s.jsx(F,{className:"h-10 w-10 shrink-0 rounded-xl"}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-2 pt-0.5",children:[s.jsx(F,{className:"h-4 w-32 max-w-[70%]"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(F,{className:"h-3 w-12"}),s.jsx(F,{className:"h-3 w-24"})]}),s.jsx(F,{className:"h-3 w-full"})]})]}),s.jsx(F,{className:"h-8 w-20 shrink-0 rounded-xl"})]})},`marketplace-skeleton-${n}`))})}function cn(e){return s.jsxs("div",{className:"mt-4 flex items-center justify-end gap-2",children:[s.jsx("button",{className:"h-8 px-3 rounded-xl border border-gray-200/80 text-sm text-gray-600 disabled:opacity-40",onClick:e.onPrev,disabled:e.page<=1||e.busy,children:c("prev")}),s.jsx("div",{className:"text-sm text-gray-600 min-w-20 text-center",children:e.totalPages===0?"0 / 0":`${e.page} / ${e.totalPages}`}),s.jsx("button",{className:"h-8 px-3 rounded-xl border border-gray-200/80 text-sm text-gray-600 disabled:opacity-40",onClick:e.onNext,disabled:e.totalPages===0||e.page>=e.totalPages||e.busy,children:c("next")})]})}const Ke=12,un=Ke;function le(e){return(e??"").trim().toLowerCase()}function U(e,t){const n=le(t);return n.length>0?`${e}:${n}`:""}function dn(e){const t=new Map;for(const n of e){const a=[n.install.spec,n.slug,n.id];for(const r of a){const l=U(n.type,r);!l||t.has(l)||t.set(l,n)}}return t}function pn(e){const t=new Map;for(const n of e){const a=[n.spec,n.id,n.label];for(const r of a){const l=U(n.type,r);!l||t.has(l)||t.set(l,n)}}return t}function Pe(e,t){const n=[e.install.spec,e.slug,e.id];for(const a of n){const r=U(e.type,a);if(!r)continue;const l=t.get(r);if(l)return l}}function fn(e,t){const n=t.get(U(e.type,e.spec));if(n)return n;const a=t.get(U(e.type,e.id));return a||t.get(U(e.type,e.label))}function gn(e,t,n,a){const r=le(n);if(!r)return!0;const l=oe(t==null?void 0:t.summaryI18n,t==null?void 0:t.summary,a);return[e.id,e.spec,e.label,t==null?void 0:t.name,t==null?void 0:t.slug,t==null?void 0:t.summary,l,...(t==null?void 0:t.tags)??[]].map(g=>le(g)).filter(Boolean).some(g=>g.includes(r))}function mn(e){const t=["bg-amber-600","bg-orange-500","bg-yellow-600","bg-emerald-600","bg-teal-600","bg-cyan-600","bg-stone-600","bg-rose-500","bg-violet-500"];let n=0;for(let a=0;a<e.length;a++)n=e.charCodeAt(a)+((n<<5)-n);return t[Math.abs(n)%t.length]}function xn({name:e,fallback:t}){const n=e||t,a=n.substring(0,2).toUpperCase(),r=mn(n);return s.jsx("div",{className:Le("flex items-center justify-center w-10 h-10 rounded-xl text-white font-semibold text-sm shrink-0",r),children:a})}function I(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function B(e){var g,d,k,u;const t=((g=e.metadataRaw)==null?void 0:g.trim())||"-",n=((d=e.contentRaw)==null?void 0:d.trim())||"-",a=(k=e.summary)==null?void 0:k.trim(),r=(u=e.description)==null?void 0:u.trim(),l=!!r&&r!==a,f=`<!doctype html>
2
2
  <html>
3
3
  <head>
4
4
  <meta charset="utf-8" />
@@ -1,4 +1,4 @@
1
- import{u as ae,b as te,d as R,e as C,r as m,j as a}from"./vendor-CwsIoNvJ.js";import{P as he,a as fe}from"./page-layout-sNhcbwtm.js";import{T as ye}from"./tabs-custom-BB-VjdL2.js";import{af as v,t as n,p as be,n as ke,I as P,S as je,e as ve,f as we,g as Me,h as X,c as Ne,B as Y}from"./index-BWvap_iq.js";import{S as Se}from"./switch-DSdHSIsC.js";import{u as Ce,D as se,a as ne,b as re,c as le,d as ce,e as Ie}from"./useConfirmDialog-BL5s8KDC.js";import{S}from"./skeleton-CiG6msbm.js";import{b as De,p as Te,a as Pe}from"./marketplace-localization-Dk31LJJJ.js";import"./index-Ct7FQpxN.js";async function Re(e){var d,o;const t=new URLSearchParams;(d=e.q)!=null&&d.trim()&&t.set("q",e.q.trim()),(o=e.tag)!=null&&o.trim()&&t.set("tag",e.tag.trim()),e.sort&&t.set("sort",e.sort),typeof e.page=="number"&&Number.isFinite(e.page)&&t.set("page",String(Math.max(1,Math.trunc(e.page)))),typeof e.pageSize=="number"&&Number.isFinite(e.pageSize)&&t.set("pageSize",String(Math.max(1,Math.trunc(e.pageSize))));const c=t.toString(),i=await v.get(c?`/api/marketplace/mcp/items?${c}`:"/api/marketplace/mcp/items");if(!i.ok)throw new Error(i.error.message);return i.data}async function qe(){const e=await v.get("/api/marketplace/mcp/installed");if(!e.ok)throw new Error(e.error.message);return e.data}async function Ee(e){const t=await v.get(`/api/marketplace/mcp/items/${encodeURIComponent(e)}/content`);if(!t.ok)throw new Error(t.error.message);return t.data}async function Fe(e){const t=await v.post("/api/marketplace/mcp/install",{type:"mcp",...e});if(!t.ok)throw new Error(t.error.message);return t.data}async function $e(e){const t=await v.post("/api/marketplace/mcp/manage",{type:"mcp",...e});if(!t.ok)throw new Error(t.error.message);return t.data}async function Le(e){const t=await v.post("/api/marketplace/mcp/doctor",{name:e});if(!t.ok)throw new Error(t.error.message);return t.data}function ze(e){return ae({queryKey:["marketplace-mcp-items",e],queryFn:()=>Re(e),staleTime:15e3})}function Ae(){return ae({queryKey:["marketplace-mcp-installed"],queryFn:()=>qe(),staleTime:1e4})}function Oe(){const e=te();return R({mutationFn:Fe,onSuccess:t=>{e.invalidateQueries({queryKey:["marketplace-mcp-installed"]}),e.invalidateQueries({queryKey:["marketplace-mcp-items"]}),e.invalidateQueries({queryKey:["marketplace-mcp-doctor"]}),C.success(t.message||n("marketplaceInstallSuccessMcp"))},onError:t=>{C.error(t.message||n("marketplaceInstallFailed"))}})}function Qe(){const e=te();return R({mutationFn:$e,onSuccess:t=>{e.invalidateQueries({queryKey:["marketplace-mcp-installed"]}),e.invalidateQueries({queryKey:["marketplace-mcp-items"]}),e.invalidateQueries({queryKey:["marketplace-mcp-doctor"]}),C.success(t.message||n("marketplaceMcpManageSuccess"))},onError:t=>{C.error(t.message||n("marketplaceOperationFailed"))}})}const Ke=12;function oe(e){return(e??"").trim().toLowerCase()}function Ue(e){const t=new Map;for(const c of e){const i=[c.catalogSlug,c.spec,c.id,c.label];for(const d of i){const o=oe(d);!o||t.has(o)||t.set(o,c)}}return t}function Be(e,t){const c=[e.slug,e.install.spec,e.id,e.name];for(const i of c){const d=oe(i);if(!d)continue;const o=t.get(d);if(o)return o}}function T(e,t,c,i,d){const o=k=>k.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"),y=`<!doctype html>
1
+ import{u as ae,b as te,d as R,e as C,r as m,j as a}from"./vendor-CwsIoNvJ.js";import{P as he,a as fe}from"./page-layout-ud8wZ8gX.js";import{T as ye}from"./tabs-custom-6Tm1ZHfS.js";import{af as v,t as n,p as be,n as ke,I as P,S as je,e as ve,f as we,g as Me,h as X,c as Ne,B as Y}from"./index-CeRbsQ90.js";import{S as Se}from"./switch-B-_SrMSL.js";import{u as Ce,D as se,a as ne,b as re,c as le,d as ce,e as Ie}from"./useConfirmDialog-BeOW2bOI.js";import{S}from"./skeleton-IOOTmHzP.js";import{b as De,p as Te,a as Pe}from"./marketplace-localization-Dk31LJJJ.js";import"./index-Ct7FQpxN.js";async function Re(e){var d,o;const t=new URLSearchParams;(d=e.q)!=null&&d.trim()&&t.set("q",e.q.trim()),(o=e.tag)!=null&&o.trim()&&t.set("tag",e.tag.trim()),e.sort&&t.set("sort",e.sort),typeof e.page=="number"&&Number.isFinite(e.page)&&t.set("page",String(Math.max(1,Math.trunc(e.page)))),typeof e.pageSize=="number"&&Number.isFinite(e.pageSize)&&t.set("pageSize",String(Math.max(1,Math.trunc(e.pageSize))));const c=t.toString(),i=await v.get(c?`/api/marketplace/mcp/items?${c}`:"/api/marketplace/mcp/items");if(!i.ok)throw new Error(i.error.message);return i.data}async function qe(){const e=await v.get("/api/marketplace/mcp/installed");if(!e.ok)throw new Error(e.error.message);return e.data}async function Ee(e){const t=await v.get(`/api/marketplace/mcp/items/${encodeURIComponent(e)}/content`);if(!t.ok)throw new Error(t.error.message);return t.data}async function Fe(e){const t=await v.post("/api/marketplace/mcp/install",{type:"mcp",...e});if(!t.ok)throw new Error(t.error.message);return t.data}async function $e(e){const t=await v.post("/api/marketplace/mcp/manage",{type:"mcp",...e});if(!t.ok)throw new Error(t.error.message);return t.data}async function Le(e){const t=await v.post("/api/marketplace/mcp/doctor",{name:e});if(!t.ok)throw new Error(t.error.message);return t.data}function ze(e){return ae({queryKey:["marketplace-mcp-items",e],queryFn:()=>Re(e),staleTime:15e3})}function Ae(){return ae({queryKey:["marketplace-mcp-installed"],queryFn:()=>qe(),staleTime:1e4})}function Oe(){const e=te();return R({mutationFn:Fe,onSuccess:t=>{e.invalidateQueries({queryKey:["marketplace-mcp-installed"]}),e.invalidateQueries({queryKey:["marketplace-mcp-items"]}),e.invalidateQueries({queryKey:["marketplace-mcp-doctor"]}),C.success(t.message||n("marketplaceInstallSuccessMcp"))},onError:t=>{C.error(t.message||n("marketplaceInstallFailed"))}})}function Qe(){const e=te();return R({mutationFn:$e,onSuccess:t=>{e.invalidateQueries({queryKey:["marketplace-mcp-installed"]}),e.invalidateQueries({queryKey:["marketplace-mcp-items"]}),e.invalidateQueries({queryKey:["marketplace-mcp-doctor"]}),C.success(t.message||n("marketplaceMcpManageSuccess"))},onError:t=>{C.error(t.message||n("marketplaceOperationFailed"))}})}const Ke=12;function oe(e){return(e??"").trim().toLowerCase()}function Ue(e){const t=new Map;for(const c of e){const i=[c.catalogSlug,c.spec,c.id,c.label];for(const d of i){const o=oe(d);!o||t.has(o)||t.set(o,c)}}return t}function Be(e,t){const c=[e.slug,e.install.spec,e.id,e.name];for(const i of c){const d=oe(i);if(!d)continue;const o=t.get(d);if(o)return o}}function T(e,t,c,i,d){const o=k=>k.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"),y=`<!doctype html>
2
2
  <html>
3
3
  <head>
4
4
  <meta charset="utf-8" />
@@ -1 +1 @@
1
- import{r as n,j as e,a2 as W,l as z,q,J as G,a3 as J,a4 as K}from"./vendor-CwsIoNvJ.js";import{I as A,c as L,u as Y,a as $,b as Q,d as X,t as m,C as U,S as Z,e as H,f as ee,g as se,h as te,D as ae,B as re}from"./index-BWvap_iq.js";import{L as R}from"./label-Bklr3fXc.js";import{S as u}from"./skeleton-CiG6msbm.js";import{h as _}from"./config-hints-CApS3K_7.js";import{b as le,f as oe,t as O,c as ne}from"./provider-models-D3B_xWXx.js";import{P as ie,a as ce}from"./page-layout-sNhcbwtm.js";function de(i){const r=new Set;for(const p of i){const x=p.trim();x.length>0&&r.add(x)}return[...r]}function me({id:i,value:r,onChange:p,options:x,disabled:c=!1,placeholder:T,className:P,inputClassName:b,emptyText:j,createText:k,maxItems:N=Number.POSITIVE_INFINITY,onEnter:v}){const[o,l]=n.useState(!1);n.useEffect(()=>{c&&o&&l(!1)},[c,o]);const h=n.useMemo(()=>de(x),[x]),d=r.trim().toLowerCase(),a=n.useMemo(()=>{const s=h.map((f,w)=>({option:f,index:w}));d.length>0&&s.sort((f,w)=>{const C=f.option.toLowerCase(),S=w.option.toLowerCase(),D=C===d?0:C.startsWith(d)?1:C.includes(d)?2:3,I=S===d?0:S.startsWith(d)?1:S.includes(d)?2:3;return D!==I?D-I:f.index-w.index});const g=s.map(f=>f.option);return Number.isFinite(N)?g.slice(0,Math.max(1,N)):g},[h,d,N]),M=r.trim().length>0&&h.some(s=>s===r.trim());return e.jsxs("div",{className:L("relative",P),onBlur:()=>{setTimeout(()=>l(!1),120)},children:[e.jsx(A,{id:i,value:r,disabled:c,onFocus:()=>{c||l(!0)},onChange:s=>{p(s.target.value),!o&&!c&&l(!0)},onKeyDown:s=>{s.key==="Enter"&&(v&&(s.preventDefault(),v()),l(!1))},placeholder:T,className:L("pr-10",b)}),e.jsx("button",{type:"button",onMouseDown:s=>s.preventDefault(),onClick:()=>l(s=>!s),disabled:c,className:L("absolute inset-y-0 right-0 inline-flex w-10 items-center justify-center",c?"cursor-not-allowed text-gray-300":"text-gray-400 hover:text-gray-600"),"aria-label":"toggle model options",children:e.jsx(W,{className:"h-4 w-4"})}),o&&!c&&e.jsx("div",{className:"absolute z-20 mt-1 w-full overflow-hidden rounded-xl border border-gray-200 bg-white shadow-lg",children:e.jsxs("div",{className:"max-h-60 overflow-y-auto py-1",children:[!M&&r.trim().length>0&&e.jsxs("button",{type:"button",onMouseDown:s=>s.preventDefault(),onClick:()=>{p(r.trim()),l(!1)},className:"flex w-full items-center gap-2 px-3 py-2 text-left text-sm hover:bg-gray-50",children:[e.jsx(z,{className:"h-4 w-4 text-transparent"}),e.jsx("span",{className:"truncate text-gray-700",children:k?k.replace("{value}",r.trim()):r.trim()})]}),a.map(s=>e.jsxs("button",{type:"button",onMouseDown:g=>g.preventDefault(),onClick:()=>{p(s),l(!1)},className:"flex w-full items-center gap-2 px-3 py-2 text-left text-sm hover:bg-gray-50",children:[e.jsx(z,{className:L("h-4 w-4",s===r.trim()?"text-primary":"text-transparent")}),e.jsx("span",{className:"truncate text-gray-700",children:s})]},s)),a.length===0&&r.trim().length===0&&e.jsx("div",{className:"px-3 py-2 text-sm text-gray-500",children:j??"No models available"})]})})]})}function Ne(){const{data:i,isLoading:r}=Y(),{data:p}=$(),{data:x}=Q(),c=X(),[T,P]=n.useState(""),[b,j]=n.useState(""),[k,N]=n.useState(""),v=x==null?void 0:x.uiHints,o=_("agents.defaults.model",v),l=_("agents.defaults.workspace",v),h=n.useMemo(()=>le({meta:p,config:i,onlyConfigured:!0}),[i,p]),d=n.useMemo(()=>new Map(h.map(t=>[t.name,t])),[h]),a=d.get(T),M=(a==null?void 0:a.name)??"",s=n.useMemo(()=>(a==null?void 0:a.aliases)??[],[a]),g=n.useMemo(()=>(a==null?void 0:a.models)??[],[a]);n.useEffect(()=>{var F,B;if(!((F=i==null?void 0:i.agents)!=null&&F.defaults))return;const t=(i.agents.defaults.model||"").trim(),y=oe(t,h)??"",V=((B=d.get(y))==null?void 0:B.aliases)??[];P(y),j(y?O(t,V):""),N(i.agents.defaults.workspace||"")},[i,h,d]);const f=n.useMemo(()=>{const t=new Set;for(const E of g){const y=E.trim();y&&t.add(y)}return[...t]},[g]),w=n.useMemo(()=>{if(!a)return"";const t=O(b,s);return t?ne(a.prefix,t):""},[b,a,s]),C=m("modelIdentifierHelp")||(o==null?void 0:o.help)||"",S=t=>{P(t),j("")},D=t=>{if(!a){j("");return}j(O(t,s))},I=t=>{t.preventDefault(),c.mutate({model:w})};return r?e.jsxs("div",{className:"max-w-2xl space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{className:"h-8 w-32"}),e.jsx(u,{className:"h-4 w-48"})]}),e.jsxs(U,{className:"rounded-2xl border-gray-200 p-6",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[e.jsx(u,{className:"h-12 w-12 rounded-xl"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{className:"h-5 w-24"}),e.jsx(u,{className:"h-3 w-32"})]})]}),e.jsx(u,{className:"h-4 w-20 mb-2"}),e.jsx(u,{className:"h-10 w-full rounded-xl"})]}),e.jsxs(U,{className:"rounded-2xl border-gray-200 p-6",children:[e.jsx(u,{className:"h-5 w-24 mb-2"}),e.jsx(u,{className:"h-10 w-full rounded-xl"})]})]}):e.jsxs(ie,{children:[e.jsx(ce,{title:m("modelPageTitle"),description:m("modelPageDescription")}),e.jsxs("form",{onSubmit:I,className:"space-y-8",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-8",children:[e.jsxs("div",{className:"p-8 rounded-2xl bg-white border border-gray-200 shadow-card",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-8",children:[e.jsx("div",{className:"h-10 w-10 rounded-xl bg-primary flex items-center justify-center text-white",children:e.jsx(q,{className:"h-5 w-5"})}),e.jsx("h3",{className:"text-lg font-bold text-gray-900",children:m("defaultModel")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(R,{htmlFor:"model",className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:(o==null?void 0:o.label)??"Model Name"}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center",children:[e.jsx("div",{className:"sm:w-[38%] sm:min-w-[170px]",children:e.jsxs(Z,{value:M,onValueChange:S,children:[e.jsx(H,{className:"h-10 w-full rounded-xl",children:e.jsx(ee,{placeholder:m("providersSelectPlaceholder")})}),e.jsx(se,{children:h.map(t=>e.jsx(te,{value:t.name,children:t.displayName},t.name))})]})}),e.jsx("span",{className:"hidden h-10 items-center justify-center leading-none text-lg font-semibold text-gray-300 sm:inline-flex",children:"/"}),e.jsx(me,{id:"model",value:b,onChange:D,options:f,disabled:!M,placeholder:(o==null?void 0:o.placeholder)??"gpt-5.1",className:"sm:flex-1",inputClassName:"h-10 rounded-xl",emptyText:m("modelPickerNoOptions"),createText:m("modelPickerUseCustom")},M)]}),e.jsx("p",{className:"text-xs text-gray-400",children:C}),e.jsx("p",{className:"text-xs text-gray-500",children:m("modelInputCustomHint")}),e.jsxs("a",{href:`${ae}/guide/model-selection`,className:"inline-flex items-center gap-1.5 text-xs text-primary hover:text-primary-hover transition-colors",children:[e.jsx(G,{className:"h-3.5 w-3.5"}),m("channelsGuideTitle")]})]})]}),e.jsxs("div",{className:"p-8 rounded-2xl bg-white border border-gray-200 shadow-card",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-8",children:[e.jsx("div",{className:"h-10 w-10 rounded-xl bg-primary flex items-center justify-center text-white",children:e.jsx(J,{className:"h-5 w-5"})}),e.jsx("h3",{className:"text-lg font-bold text-gray-900",children:m("workspace")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(R,{htmlFor:"workspace",className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:(l==null?void 0:l.label)??"Default Path"}),e.jsx(A,{id:"workspace",value:k,onChange:t=>N(t.target.value),placeholder:(l==null?void 0:l.placeholder)??"/path/to/workspace",className:"rounded-xl"})]})]})]}),e.jsx("div",{className:"flex justify-end pt-4",children:e.jsx(re,{type:"submit",disabled:c.isPending,size:"lg",children:c.isPending?e.jsx(K,{className:"h-5 w-5 animate-spin"}):m("saveChanges")})})]})]})}export{Ne as ModelConfig};
1
+ import{r as n,j as e,a2 as W,l as z,q,J as G,a3 as J,a4 as K}from"./vendor-CwsIoNvJ.js";import{I as A,c as L,u as Y,a as $,b as Q,d as X,t as m,C as U,S as Z,e as H,f as ee,g as se,h as te,D as ae,B as re}from"./index-CeRbsQ90.js";import{L as R}from"./label-CCSffS1D.js";import{S as u}from"./skeleton-IOOTmHzP.js";import{h as _}from"./config-hints-CApS3K_7.js";import{b as le,f as oe,t as O,c as ne}from"./provider-models-D3B_xWXx.js";import{P as ie,a as ce}from"./page-layout-ud8wZ8gX.js";function de(i){const r=new Set;for(const p of i){const x=p.trim();x.length>0&&r.add(x)}return[...r]}function me({id:i,value:r,onChange:p,options:x,disabled:c=!1,placeholder:T,className:P,inputClassName:b,emptyText:j,createText:k,maxItems:N=Number.POSITIVE_INFINITY,onEnter:v}){const[o,l]=n.useState(!1);n.useEffect(()=>{c&&o&&l(!1)},[c,o]);const h=n.useMemo(()=>de(x),[x]),d=r.trim().toLowerCase(),a=n.useMemo(()=>{const s=h.map((f,w)=>({option:f,index:w}));d.length>0&&s.sort((f,w)=>{const C=f.option.toLowerCase(),S=w.option.toLowerCase(),D=C===d?0:C.startsWith(d)?1:C.includes(d)?2:3,I=S===d?0:S.startsWith(d)?1:S.includes(d)?2:3;return D!==I?D-I:f.index-w.index});const g=s.map(f=>f.option);return Number.isFinite(N)?g.slice(0,Math.max(1,N)):g},[h,d,N]),M=r.trim().length>0&&h.some(s=>s===r.trim());return e.jsxs("div",{className:L("relative",P),onBlur:()=>{setTimeout(()=>l(!1),120)},children:[e.jsx(A,{id:i,value:r,disabled:c,onFocus:()=>{c||l(!0)},onChange:s=>{p(s.target.value),!o&&!c&&l(!0)},onKeyDown:s=>{s.key==="Enter"&&(v&&(s.preventDefault(),v()),l(!1))},placeholder:T,className:L("pr-10",b)}),e.jsx("button",{type:"button",onMouseDown:s=>s.preventDefault(),onClick:()=>l(s=>!s),disabled:c,className:L("absolute inset-y-0 right-0 inline-flex w-10 items-center justify-center",c?"cursor-not-allowed text-gray-300":"text-gray-400 hover:text-gray-600"),"aria-label":"toggle model options",children:e.jsx(W,{className:"h-4 w-4"})}),o&&!c&&e.jsx("div",{className:"absolute z-20 mt-1 w-full overflow-hidden rounded-xl border border-gray-200 bg-white shadow-lg",children:e.jsxs("div",{className:"max-h-60 overflow-y-auto py-1",children:[!M&&r.trim().length>0&&e.jsxs("button",{type:"button",onMouseDown:s=>s.preventDefault(),onClick:()=>{p(r.trim()),l(!1)},className:"flex w-full items-center gap-2 px-3 py-2 text-left text-sm hover:bg-gray-50",children:[e.jsx(z,{className:"h-4 w-4 text-transparent"}),e.jsx("span",{className:"truncate text-gray-700",children:k?k.replace("{value}",r.trim()):r.trim()})]}),a.map(s=>e.jsxs("button",{type:"button",onMouseDown:g=>g.preventDefault(),onClick:()=>{p(s),l(!1)},className:"flex w-full items-center gap-2 px-3 py-2 text-left text-sm hover:bg-gray-50",children:[e.jsx(z,{className:L("h-4 w-4",s===r.trim()?"text-primary":"text-transparent")}),e.jsx("span",{className:"truncate text-gray-700",children:s})]},s)),a.length===0&&r.trim().length===0&&e.jsx("div",{className:"px-3 py-2 text-sm text-gray-500",children:j??"No models available"})]})})]})}function Ne(){const{data:i,isLoading:r}=Y(),{data:p}=$(),{data:x}=Q(),c=X(),[T,P]=n.useState(""),[b,j]=n.useState(""),[k,N]=n.useState(""),v=x==null?void 0:x.uiHints,o=_("agents.defaults.model",v),l=_("agents.defaults.workspace",v),h=n.useMemo(()=>le({meta:p,config:i,onlyConfigured:!0}),[i,p]),d=n.useMemo(()=>new Map(h.map(t=>[t.name,t])),[h]),a=d.get(T),M=(a==null?void 0:a.name)??"",s=n.useMemo(()=>(a==null?void 0:a.aliases)??[],[a]),g=n.useMemo(()=>(a==null?void 0:a.models)??[],[a]);n.useEffect(()=>{var F,B;if(!((F=i==null?void 0:i.agents)!=null&&F.defaults))return;const t=(i.agents.defaults.model||"").trim(),y=oe(t,h)??"",V=((B=d.get(y))==null?void 0:B.aliases)??[];P(y),j(y?O(t,V):""),N(i.agents.defaults.workspace||"")},[i,h,d]);const f=n.useMemo(()=>{const t=new Set;for(const E of g){const y=E.trim();y&&t.add(y)}return[...t]},[g]),w=n.useMemo(()=>{if(!a)return"";const t=O(b,s);return t?ne(a.prefix,t):""},[b,a,s]),C=m("modelIdentifierHelp")||(o==null?void 0:o.help)||"",S=t=>{P(t),j("")},D=t=>{if(!a){j("");return}j(O(t,s))},I=t=>{t.preventDefault(),c.mutate({model:w})};return r?e.jsxs("div",{className:"max-w-2xl space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{className:"h-8 w-32"}),e.jsx(u,{className:"h-4 w-48"})]}),e.jsxs(U,{className:"rounded-2xl border-gray-200 p-6",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[e.jsx(u,{className:"h-12 w-12 rounded-xl"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{className:"h-5 w-24"}),e.jsx(u,{className:"h-3 w-32"})]})]}),e.jsx(u,{className:"h-4 w-20 mb-2"}),e.jsx(u,{className:"h-10 w-full rounded-xl"})]}),e.jsxs(U,{className:"rounded-2xl border-gray-200 p-6",children:[e.jsx(u,{className:"h-5 w-24 mb-2"}),e.jsx(u,{className:"h-10 w-full rounded-xl"})]})]}):e.jsxs(ie,{children:[e.jsx(ce,{title:m("modelPageTitle"),description:m("modelPageDescription")}),e.jsxs("form",{onSubmit:I,className:"space-y-8",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-8",children:[e.jsxs("div",{className:"p-8 rounded-2xl bg-white border border-gray-200 shadow-card",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-8",children:[e.jsx("div",{className:"h-10 w-10 rounded-xl bg-primary flex items-center justify-center text-white",children:e.jsx(q,{className:"h-5 w-5"})}),e.jsx("h3",{className:"text-lg font-bold text-gray-900",children:m("defaultModel")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(R,{htmlFor:"model",className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:(o==null?void 0:o.label)??"Model Name"}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center",children:[e.jsx("div",{className:"sm:w-[38%] sm:min-w-[170px]",children:e.jsxs(Z,{value:M,onValueChange:S,children:[e.jsx(H,{className:"h-10 w-full rounded-xl",children:e.jsx(ee,{placeholder:m("providersSelectPlaceholder")})}),e.jsx(se,{children:h.map(t=>e.jsx(te,{value:t.name,children:t.displayName},t.name))})]})}),e.jsx("span",{className:"hidden h-10 items-center justify-center leading-none text-lg font-semibold text-gray-300 sm:inline-flex",children:"/"}),e.jsx(me,{id:"model",value:b,onChange:D,options:f,disabled:!M,placeholder:(o==null?void 0:o.placeholder)??"gpt-5.1",className:"sm:flex-1",inputClassName:"h-10 rounded-xl",emptyText:m("modelPickerNoOptions"),createText:m("modelPickerUseCustom")},M)]}),e.jsx("p",{className:"text-xs text-gray-400",children:C}),e.jsx("p",{className:"text-xs text-gray-500",children:m("modelInputCustomHint")}),e.jsxs("a",{href:`${ae}/guide/model-selection`,className:"inline-flex items-center gap-1.5 text-xs text-primary hover:text-primary-hover transition-colors",children:[e.jsx(G,{className:"h-3.5 w-3.5"}),m("channelsGuideTitle")]})]})]}),e.jsxs("div",{className:"p-8 rounded-2xl bg-white border border-gray-200 shadow-card",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-8",children:[e.jsx("div",{className:"h-10 w-10 rounded-xl bg-primary flex items-center justify-center text-white",children:e.jsx(J,{className:"h-5 w-5"})}),e.jsx("h3",{className:"text-lg font-bold text-gray-900",children:m("workspace")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(R,{htmlFor:"workspace",className:"text-xs font-semibold text-gray-500 uppercase tracking-wider",children:(l==null?void 0:l.label)??"Default Path"}),e.jsx(A,{id:"workspace",value:k,onChange:t=>N(t.target.value),placeholder:(l==null?void 0:l.placeholder)??"/path/to/workspace",className:"rounded-xl"})]})]})]}),e.jsx("div",{className:"flex justify-end pt-4",children:e.jsx(re,{type:"submit",disabled:c.isPending,size:"lg",children:c.isPending?e.jsx(K,{className:"h-5 w-5 animate-spin"}):m("saveChanges")})})]})]})}export{Ne as ModelConfig};
@@ -1 +1 @@
1
- import{r as x,j as e,av as Mt,aw as Tt,ap as ot,aj as _e,b as kt,e as F,ax as tt,ay as st,C as St,az as Lt,s as It,K as Dt}from"./vendor-CwsIoNvJ.js";import{c as de,I as X,B as z,t as n,u as ct,a as dt,b as ut,U as Et,V as _t,W as $t,X as Bt,Y as zt,Z as Kt,_ as Ft,S as Te,e as ke,f as Se,g as Le,h as ye,$ as Ot}from"./index-BWvap_iq.js";import{L as O}from"./label-Bklr3fXc.js";import{a as Ht,b as Rt,c as Wt}from"./popover-C3rJrJJG.js";import{S as mt}from"./status-dot-CsIV5YrS.js";import{h as le}from"./config-hints-CApS3K_7.js";import{c as qt,b as Ut,C as Gt,a as Vt}from"./config-layout-BHnOoweL.js";import{T as Qt}from"./tabs-custom-BB-VjdL2.js";import{L as Xt}from"./LogoBadge-hKHoLH9n.js";import{P as Yt,a as Zt}from"./page-layout-sNhcbwtm.js";import"./index-Ct7FQpxN.js";function Jt({isSet:t,className:r,value:a,onChange:l,placeholder:c,...g}){const[d,u]=x.useState(!1),[j,b]=x.useState(!1),w=typeof a=="string"&&a.length>0,I=t&&!w&&!j;return e.jsxs("div",{className:"relative",children:[I?e.jsx("div",{onClick:()=>b(!0),className:de("flex h-9 w-full rounded-xl border border-gray-200/80 bg-white px-3.5 py-2 text-sm text-gray-500 cursor-text items-center pr-12",r),children:"••••••••••••"}):e.jsx(X,{type:d?"text":"password",className:de("pr-12",r),value:a,onChange:l,onBlur:()=>{w||b(!1)},placeholder:c,autoFocus:j,...g}),e.jsx("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex gap-1",children:(t||w)&&e.jsx(z,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>u(!d),children:d?e.jsx(Mt,{className:"h-4 w-4"}):e.jsx(Tt,{className:"h-4 w-4"})})})]})}function es({value:t,onChange:r,className:a}){const l=t?Object.entries(t):[],c=(u,j,b)=>{const w=[...l];w[u]=[j,b],r(Object.fromEntries(w))},g=()=>{r({...t,"":""})},d=u=>{const j=l.filter((b,w)=>w!==u);r(Object.fromEntries(j))};return e.jsxs("div",{className:de("space-y-2",a),children:[l.map(([u,j],b)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(X,{type:"text",value:u,onChange:w=>c(b,w.target.value,j),placeholder:n("headerName"),className:"flex-1"}),e.jsx(X,{type:"text",value:j,onChange:w=>c(b,u,w.target.value),placeholder:n("headerValue"),className:"flex-1"}),e.jsx(z,{type:"button",variant:"ghost",size:"icon",onClick:()=>d(b),children:e.jsx(ot,{className:"h-4 w-4 text-red-500"})})]},b)),e.jsxs(z,{type:"button",variant:"outline",size:"sm",onClick:g,children:[e.jsx(_e,{className:"h-4 w-4 mr-2"}),n("add")]})]})}const ts={displayName:"",apiKeySet:!1,apiBase:null,extraHeaders:null,wireApi:null,models:[],modelThinking:{}},Ee=["off","minimal","low","medium","high","adaptive","xhigh"],ss=new Set(Ee);function ce(t){if(!t)return null;const r=Object.entries(t).map(([a,l])=>[a.trim(),l]).filter(([a])=>a.length>0);return r.length===0?null:Object.fromEntries(r)}function nt(t,r){const a=ce(t),l=ce(r);if(a===null&&l===null)return!0;if(!a||!l)return!1;const c=Object.entries(a).sort(([d],[u])=>d.localeCompare(u)),g=Object.entries(l).sort(([d],[u])=>d.localeCompare(u));return c.length!==g.length?!1:c.every(([d,u],j)=>d===g[j][0]&&u===g[j][1])}function Ie(t){if(!t||t.length===0)return[];const r=new Set;for(const a of t){const l=a.trim();l&&r.add(l)}return[...r]}function ns(t,r){const a=t.trim();if(!a||!r.trim())return a;const l=`${r.trim()}/`;return a.startsWith(l)?a.slice(l.length):a}function oe(t,r){let a=t.trim();if(!a)return"";for(const l of r){const c=l.trim();c&&(a=ns(a,c))}return a.trim()}function je(t,r){return t.length!==r.length?!1:t.every((a,l)=>a===r[l])}function rs(t,r){const a=[...t];for(const l of r)a.includes(l)||a.push(l);return a}function as(t,r){return r.length===0?t:r.every(l=>!t.includes(l))?rs(t,r):r}function is(t,r){return je(t,r)?[]:t}function $e(t){if(typeof t!="string")return null;const r=t.trim().toLowerCase();return r&&ss.has(r)?r:null}function ht(t){if(!Array.isArray(t))return[];const r=[];for(const a of t){const l=$e(a);!l||r.includes(l)||r.push(l)}return r}function ls(t,r){if(!t)return{};const a={};for(const[l,c]of Object.entries(t)){const g=oe(l,r);if(!g)continue;const d=ht(c==null?void 0:c.supported);if(d.length===0)continue;const u=$e(c==null?void 0:c.default);a[g]=u&&d.includes(u)?{supported:d,default:u}:{supported:d}}return a}function De(t,r){const a=new Set(r.map(c=>c.trim()).filter(Boolean)),l={};for(const[c,g]of Object.entries(t)){if(!a.has(c))continue;const d=ht(g.supported);if(d.length===0)continue;const u=$e(g.default);l[c]=u&&d.includes(u)?{supported:d,default:u}:{supported:d}}return l}function rt(t,r){const a=Object.keys(t).sort(),l=Object.keys(r).sort();if(a.length!==l.length)return!1;for(let c=0;c<a.length;c+=1){const g=a[c];if(g!==l[c])return!1;const d=t[g],u=r[g];if(!d||!u)return!1;const j=[...d.supported].sort(),b=[...u.supported].sort();if(!je(j,b)||(d.default??null)!==(u.default??null))return!1}return!0}function at(t){return t==="off"?n("chatThinkingLevelOff"):t==="minimal"?n("chatThinkingLevelMinimal"):t==="low"?n("chatThinkingLevelLow"):t==="medium"?n("chatThinkingLevelMedium"):t==="high"?n("chatThinkingLevelHigh"):t==="adaptive"?n("chatThinkingLevelAdaptive"):n("chatThinkingLevelXhigh")}function os(t){var j,b,w,I,D;const{providerName:r,methods:a,defaultMethodId:l,language:c}=t;if(a.length===0)return"";const g=new Map;for(const k of a){const A=k.id.trim();A&&g.set(A.toLowerCase(),A)}const d=(...k)=>{for(const A of k){const P=g.get(A.toLowerCase());if(P)return P}},u=l==null?void 0:l.trim();if(r==="minimax-portal"){if(c==="zh")return d("cn","china-mainland")??d(u??"")??((j=a[0])==null?void 0:j.id)??"";if(c==="en")return d("global","intl","international")??d(u??"")??((b=a[0])==null?void 0:b.id)??""}if(u){const k=d(u);if(k)return k}return c==="zh"?d("cn")??((w=a[0])==null?void 0:w.id)??"":c==="en"?d("global")??((I=a[0])==null?void 0:I.id)??"":((D=a[0])==null?void 0:D.id)??""}function it(t){return t.required&&t.hasDefault&&t.optionCount>1&&t.optionCount<=3}function lt(t){const{value:r,onChange:a,options:l}=t;return e.jsx("div",{className:"flex flex-wrap gap-2",children:l.map(c=>{const g=c.value===r;return e.jsx("button",{type:"button",onClick:()=>a(c.value),"aria-pressed":g,className:`rounded-full border px-3 py-1.5 text-xs font-medium transition-colors ${g?"border-primary bg-primary text-white shadow-sm":"border-gray-200 bg-white text-gray-700 hover:border-primary/40 hover:text-primary"}`,children:c.label},c.value)})})}function cs({providerName:t,onProviderDeleted:r}){var Ve,Qe,Xe,Ye,Ze,Je,et;const a=kt(),{data:l}=ct(),{data:c}=dt(),{data:g}=ut(),d=Et(),u=_t(),j=$t(),b=Bt(),w=zt(),I=Kt(),[D,k]=x.useState(""),[A,P]=x.useState(""),[H,ne]=x.useState(null),[f,v]=x.useState("auto"),[N,M]=x.useState([]),[E,_]=x.useState({}),[R,$]=x.useState(""),[U,Y]=x.useState(""),[be,pt]=x.useState(!1),[ve,ue]=x.useState(!1),[me,W]=x.useState(null),[Be,B]=x.useState(""),[ze,he]=x.useState(""),pe=x.useRef(null),i=c==null?void 0:c.providers.find(s=>s.name===t),T=(t?l==null?void 0:l.providers[t]:null)??ts,xe=g==null?void 0:g.uiHints,Z=!!(i!=null&&i.isCustom),J=t?le(`providers.${t}.apiKey`,xe):void 0,K=t?le(`providers.${t}.apiBase`,xe):void 0,we=t?le(`providers.${t}.extraHeaders`,xe):void 0,Ne=t?le(`providers.${t}.wireApi`,xe):void 0,Ke=(i==null?void 0:i.displayName)||t||"",ee=(T.displayName||"").trim()||Ke,xt=U.trim()||ee||t||n("providersSelectPlaceholder"),Fe=(i==null?void 0:i.modelPrefix)||t||"",q=x.useMemo(()=>Ie([Fe,t||""]),[Fe,t]),Ce=(i==null?void 0:i.defaultApiBase)||"",re=T.apiBase||Ce,Ae=ce(T.extraHeaders||null),ae=T.wireApi||(i==null?void 0:i.defaultWireApi)||"auto",Pe=x.useMemo(()=>Ie(((i==null?void 0:i.defaultModels)??[]).map(s=>oe(s,q))),[i==null?void 0:i.defaultModels,q]),Oe=x.useMemo(()=>Ie((T.models??[]).map(s=>oe(s,q))),[T.models,q]),G=x.useMemo(()=>as(Pe,Oe),[Pe,Oe]),ie=x.useMemo(()=>De(ls(T.modelThinking,q),G),[G,q,T.modelThinking]),V=Ft(),ft=((Ve=i==null?void 0:i.apiBaseHelp)==null?void 0:Ve[V])||((Qe=i==null?void 0:i.apiBaseHelp)==null?void 0:Qe.en)||(K==null?void 0:K.help)||n("providerApiBaseHelp"),p=i==null?void 0:i.auth,S=x.useMemo(()=>(p==null?void 0:p.methods)??[],[p==null?void 0:p.methods]),He=x.useMemo(()=>S.map(s=>{var o,h;return{value:s.id,label:((o=s.label)==null?void 0:o[V])||((h=s.label)==null?void 0:h.en)||s.id}}),[S,V]),fe=x.useMemo(()=>os({providerName:t,methods:S,defaultMethodId:p==null?void 0:p.defaultMethodId,language:V}),[t,p==null?void 0:p.defaultMethodId,S,V]),te=x.useMemo(()=>{var o;if(!S.length)return"";const s=ze.trim();return s&&S.some(h=>h.id===s)?s:fe||((o=S[0])==null?void 0:o.id)||""},[ze,fe,S]),se=x.useMemo(()=>S.find(s=>s.id===te),[S,te]),Re=((Xe=se==null?void 0:se.hint)==null?void 0:Xe[V])||((Ye=se==null?void 0:se.hint)==null?void 0:Ye.en)||"",gt=it({required:(p==null?void 0:p.kind)==="device_code",hasDefault:!!((Ze=p==null?void 0:p.defaultMethodId)!=null&&Ze.trim()),optionCount:S.length}),We=((Je=p==null?void 0:p.note)==null?void 0:Je[V])||((et=p==null?void 0:p.note)==null?void 0:et.en)||(p==null?void 0:p.displayName)||"",Me=((i==null?void 0:i.wireApiOptions)||["auto","chat","responses"]).map(s=>({value:s,label:s==="chat"?n("wireApiChat"):s==="responses"?n("wireApiResponses"):n("wireApiAuto")})),yt=it({required:!!(i!=null&&i.supportsWireApi),hasDefault:typeof(i==null?void 0:i.defaultWireApi)=="string"&&i.defaultWireApi.length>0,optionCount:Me.length}),L=x.useCallback(()=>{pe.current!==null&&(window.clearTimeout(pe.current),pe.current=null)},[]),qe=x.useCallback((s,o)=>{L(),pe.current=window.setTimeout(()=>{(async()=>{if(t)try{const h=await w.mutateAsync({provider:t,data:{sessionId:s}});if(h.status==="pending"){B(n("providerAuthWaitingBrowser")),qe(s,h.nextPollMs??o);return}if(h.status==="authorized"){W(null),L(),B(n("providerAuthCompleted")),F.success(n("providerAuthCompleted")),a.invalidateQueries({queryKey:["config"]}),a.invalidateQueries({queryKey:["config-meta"]});return}W(null),L(),B(h.message||`Authorization ${h.status}.`),F.error(h.message||`Authorization ${h.status}.`)}catch(h){W(null),L();const m=h instanceof Error?h.message:String(h);B(m),F.error(`Authorization failed: ${m}`)}})()},Math.max(1e3,o))},[L,w,t,a]);x.useEffect(()=>{if(!t){k(""),P(""),ne(null),v("auto"),M([]),_({}),$(""),Y(""),W(null),B(""),he(""),L();return}k(""),P(re),ne(T.extraHeaders||null),v(ae),M(G),_(ie),$(""),Y(ee),W(null),B(""),he(fe),L()},[t,re,T.extraHeaders,ae,G,ie,ee,fe,L]),x.useEffect(()=>()=>L(),[L]),x.useEffect(()=>{_(s=>De(s,N))},[N]);const Ue=x.useMemo(()=>{if(!t)return!1;const s=D.trim().length>0,o=A.trim()!==re.trim(),h=!nt(H,Ae),m=i!=null&&i.supportsWireApi?f!==ae:!1,y=!je(N,G),C=!rt(E,ie),ge=Z?U.trim()!==ee:!1;return s||o||h||m||y||C||ge},[t,Z,U,ee,D,A,re,H,Ae,i==null?void 0:i.supportsWireApi,f,ae,N,G,E,ie]),Ge=()=>{const s=oe(R,q);if(s){if(N.includes(s)){$("");return}M(o=>[...o,s]),$("")}},jt=(s,o)=>{_(h=>{const m=h[s],y=(m==null?void 0:m.supported)??[],C=y.includes(o)?y.filter(Q=>Q!==o):Ee.filter(Q=>Q===o||y.includes(Q));if(C.length===0){const Q={...h};return delete Q[s],Q}const ge=m!=null&&m.default&&C.includes(m.default)?m.default:void 0;return{...h,[s]:ge?{supported:C,default:ge}:{supported:C}}})},bt=(s,o)=>{_(h=>{const m=h[s];return!m||m.supported.length===0||o&&!m.supported.includes(o)?h:{...h,[s]:o?{supported:m.supported,default:o}:{supported:m.supported}}})},vt=s=>{if(s.preventDefault(),!t)return;const o={},h=D.trim(),m=A.trim(),y=ce(H),C=U.trim();Z&&C!==ee&&(o.displayName=C.length>0?C:null),h.length>0&&(o.apiKey=h),m!==re.trim()&&(o.apiBase=m.length>0&&m!==Ce?m:null),nt(y,Ae)||(o.extraHeaders=y),i!=null&&i.supportsWireApi&&f!==ae&&(o.wireApi=f),je(N,G)||(o.models=is(N,Pe)),rt(E,ie)||(o.modelThinking=De(E,N)),d.mutate({provider:t,data:o})},wt=async()=>{if(!t)return;const s=N.find(m=>m.trim().length>0)??"",o=oe(s,q),h={apiBase:A.trim(),extraHeaders:ce(H),model:o||null};D.trim().length>0&&(h.apiKey=D.trim()),i!=null&&i.supportsWireApi&&(h.wireApi=f);try{const m=await j.mutateAsync({provider:t,data:h});if(m.success){F.success(`${n("providerTestConnectionSuccess")} (${m.latencyMs}ms)`);return}const y=[`provider=${m.provider}`,`latency=${m.latencyMs}ms`];m.model&&y.push(`model=${m.model}`),F.error(`${n("providerTestConnectionFailed")}: ${m.message} | ${y.join(" | ")}`)}catch(m){const y=m instanceof Error?m.message:String(m);F.error(`${n("providerTestConnectionFailed")}: ${y}`)}},Nt=async()=>{if(!(!t||!Z||!window.confirm(n("providerDeleteConfirm"))))try{await u.mutateAsync({provider:t}),r==null||r(t)}catch{}},Ct=async()=>{if(!(!t||(p==null?void 0:p.kind)!=="device_code"))try{B("");const s=await b.mutateAsync({provider:t,data:te?{methodId:te}:{}});if(!s.sessionId||!s.verificationUri)throw new Error(n("providerAuthStartFailed"));W(s.sessionId),B(`${n("providerAuthOpenPrompt")}${s.userCode}${n("providerAuthOpenPromptSuffix")}`),window.open(s.verificationUri,"_blank","noopener,noreferrer"),qe(s.sessionId,s.intervalMs)}catch(s){const o=s instanceof Error?s.message:String(s);W(null),L(),B(o),F.error(`${n("providerAuthStartFailed")}: ${o}`)}},At=async()=>{if(!(!t||(p==null?void 0:p.kind)!=="device_code"))try{L(),W(null);const s=await I.mutateAsync({provider:t}),o=s.expiresAt?` (expires: ${s.expiresAt})`:"";B(`${n("providerAuthImportStatusPrefix")}${o}`),F.success(n("providerAuthImportSuccess")),a.invalidateQueries({queryKey:["config"]}),a.invalidateQueries({queryKey:["config-meta"]})}catch(s){const o=s instanceof Error?s.message:String(s);B(o),F.error(`${n("providerAuthImportFailed")}: ${o}`)}};if(!t||!i)return e.jsx("div",{className:qt,children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-gray-900",children:n("providersSelectTitle")}),e.jsx("p",{className:"mt-2 text-sm text-gray-500",children:n("providersSelectDescription")})]})});const Pt=T.apiKeySet?n("statusReady"):n("statusSetup");return e.jsxs("div",{className:Ut,children:[e.jsx("div",{className:"border-b border-gray-100 px-6 py-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"truncate text-lg font-semibold text-gray-900",children:xt}),e.jsxs("div",{className:"flex items-center gap-3",children:[Z&&e.jsx("button",{type:"button",onClick:Nt,disabled:u.isPending,className:"text-gray-400 hover:text-red-500 transition-colors",title:n("providerDelete"),children:e.jsx(ot,{className:"h-4 w-4"})}),e.jsx(mt,{status:T.apiKeySet?"ready":"setup",label:Pt})]})]})}),e.jsxs("form",{onSubmit:vt,className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-6 py-5",children:[Z&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"providerDisplayName",className:"text-sm font-medium text-gray-900",children:n("providerDisplayName")}),e.jsx(X,{id:"providerDisplayName",type:"text",value:U,onChange:s=>Y(s.target.value),placeholder:Ke||n("providerDisplayNamePlaceholder"),className:"rounded-xl"}),e.jsx("p",{className:"text-xs text-gray-500",children:n("providerDisplayNameHelpShort")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"apiKey",className:"text-sm font-medium text-gray-900",children:(J==null?void 0:J.label)??n("apiKey")}),e.jsx(Jt,{id:"apiKey",value:D,isSet:T.apiKeySet,onChange:s=>k(s.target.value),placeholder:(J==null?void 0:J.placeholder)??n("enterApiKey"),className:"rounded-xl"}),e.jsx("p",{className:"text-xs text-gray-500",children:n("leaveBlankToKeepUnchanged")})]}),(p==null?void 0:p.kind)==="device_code"&&e.jsxs("div",{className:"space-y-2 rounded-xl border border-primary/20 bg-primary-50/50 p-3",children:[e.jsx(O,{className:"text-sm font-medium text-gray-900",children:p.displayName||n("providerAuthSectionTitle")}),We?e.jsx("p",{className:"text-xs text-gray-600",children:We}):null,S.length>1?e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{className:"text-xs font-medium text-gray-700",children:n("providerAuthMethodLabel")}),gt?e.jsx(lt,{value:te,onChange:he,options:He}):e.jsxs(Te,{value:te,onValueChange:he,children:[e.jsx(ke,{className:"h-8 rounded-lg bg-white",children:e.jsx(Se,{placeholder:n("providerAuthMethodPlaceholder")})}),e.jsx(Le,{children:He.map(s=>e.jsx(ye,{value:s.value,children:s.label},s.value))})]}),Re?e.jsx("p",{className:"text-xs text-gray-500",children:Re}):null]}):null,e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(z,{type:"button",variant:"outline",size:"sm",onClick:Ct,disabled:b.isPending||!!me,children:b.isPending?n("providerAuthStarting"):me?n("providerAuthAuthorizing"):n("providerAuthAuthorizeInBrowser")}),p.supportsCliImport?e.jsx(z,{type:"button",variant:"outline",size:"sm",onClick:At,disabled:I.isPending,children:I.isPending?n("providerAuthImporting"):n("providerAuthImportFromCli")}):null,me?e.jsxs("span",{className:"text-xs text-gray-500",children:[n("providerAuthSessionLabel"),": ",me.slice(0,8),"…"]}):null]}),Be?e.jsx("p",{className:"text-xs text-gray-600",children:Be}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"apiBase",className:"text-sm font-medium text-gray-900",children:(K==null?void 0:K.label)??n("apiBase")}),e.jsx(X,{id:"apiBase",type:"text",value:A,onChange:s=>P(s.target.value),placeholder:Ce||(K==null?void 0:K.placeholder)||"https://api.example.com",className:"rounded-xl"}),e.jsx("p",{className:"text-xs text-gray-500",children:ft})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(O,{className:"text-sm font-medium text-gray-900",children:n("providerModelsTitle")}),!ve&&e.jsxs("button",{type:"button",onClick:()=>ue(!0),className:"text-xs text-primary hover:text-primary/80 font-medium flex items-center gap-1",children:[e.jsx(_e,{className:"h-3 w-3"}),n("providerAddModel")]})]}),ve&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{value:R,onChange:s=>$(s.target.value),onKeyDown:s=>{s.key==="Enter"&&(s.preventDefault(),Ge()),s.key==="Escape"&&(ue(!1),$(""))},placeholder:n("providerModelInputPlaceholder"),className:"flex-1 rounded-xl",autoFocus:!0}),e.jsx(z,{type:"button",size:"sm",onClick:Ge,disabled:R.trim().length===0,children:n("add")}),e.jsx(z,{type:"button",size:"sm",variant:"ghost",onClick:()=>{ue(!1),$("")},children:e.jsx(tt,{className:"h-4 w-4"})})]}),N.length===0?e.jsxs("div",{className:"rounded-xl border border-dashed border-gray-200 bg-gray-50 px-4 py-6 text-center",children:[e.jsx("p",{className:"text-sm text-gray-500",children:n("providerModelsEmptyShort")}),!ve&&e.jsx("button",{type:"button",onClick:()=>ue(!0),className:"mt-2 text-sm text-primary hover:text-primary/80 font-medium",children:n("providerAddFirstModel")})]}):e.jsx("div",{className:"flex flex-wrap gap-2",children:N.map(s=>{const o=E[s],h=(o==null?void 0:o.supported)??[],m=(o==null?void 0:o.default)??null;return e.jsxs("div",{className:"group inline-flex max-w-full items-center gap-1 rounded-full border border-gray-200 bg-white px-3 py-1.5",children:[e.jsx("span",{className:"max-w-[140px] truncate text-sm text-gray-800 sm:max-w-[220px]",children:s}),e.jsxs(Ht,{children:[e.jsx(Rt,{asChild:!0,children:e.jsx("button",{type:"button",className:"inline-flex h-5 w-5 items-center justify-center rounded-full text-gray-400 transition-opacity hover:bg-gray-100 hover:text-gray-600 opacity-100 md:opacity-0 md:group-hover:opacity-100 md:group-focus-within:opacity-100","aria-label":n("providerModelThinkingTitle"),title:n("providerModelThinkingTitle"),children:e.jsx(st,{className:"h-3 w-3"})})}),e.jsxs(Wt,{className:"w-80 space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-semibold text-gray-800",children:n("providerModelThinkingTitle")}),e.jsx("p",{className:"text-xs text-gray-500",children:n("providerModelThinkingHint")})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Ee.map(y=>{const C=h.includes(y);return e.jsx("button",{type:"button",onClick:()=>jt(s,y),className:`rounded-full border px-2.5 py-1 text-xs font-medium transition-colors ${C?"border-primary bg-primary text-white":"border-gray-200 bg-white text-gray-600 hover:border-primary/40 hover:text-primary"}`,children:at(y)},y)})}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(O,{className:"text-xs font-medium text-gray-700",children:n("providerModelThinkingDefault")}),e.jsxs(Te,{value:m??"__none__",onValueChange:y=>bt(s,y==="__none__"?null:y),disabled:h.length===0,children:[e.jsx(ke,{className:"h-8 rounded-lg bg-white text-xs",children:e.jsx(Se,{})}),e.jsxs(Le,{children:[e.jsx(ye,{value:"__none__",children:n("providerModelThinkingDefaultNone")}),h.map(y=>e.jsx(ye,{value:y,children:at(y)},y))]})]}),h.length===0?e.jsx("p",{className:"text-xs text-gray-500",children:n("providerModelThinkingNoSupported")}):null]})]})]}),e.jsx("button",{type:"button",onClick:()=>{M(y=>y.filter(C=>C!==s)),_(y=>{const C={...y};return delete C[s],C})},className:"inline-flex h-5 w-5 items-center justify-center rounded-full text-gray-400 transition-opacity hover:bg-gray-100 hover:text-gray-600 opacity-100 md:opacity-0 md:group-hover:opacity-100 md:group-focus-within:opacity-100","aria-label":n("remove"),children:e.jsx(tt,{className:"h-3 w-3"})})]},s)})})]}),e.jsxs("div",{className:"border-t border-gray-100 pt-4",children:[e.jsxs("button",{type:"button",onClick:()=>pt(!be),className:"flex w-full items-center justify-between text-sm text-gray-600 hover:text-gray-900 transition-colors",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(st,{className:"h-3.5 w-3.5"}),n("providerAdvancedSettings")]}),e.jsx(St,{className:`h-4 w-4 transition-transform ${be?"rotate-180":""}`})]}),be&&e.jsxs("div",{className:"mt-4 space-y-5",children:[i.supportsWireApi&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"wireApi",className:"text-sm font-medium text-gray-900",children:(Ne==null?void 0:Ne.label)??n("wireApi")}),yt?e.jsx(lt,{value:f,onChange:s=>v(s),options:Me}):e.jsxs(Te,{value:f,onValueChange:s=>v(s),children:[e.jsx(ke,{className:"rounded-xl",children:e.jsx(Se,{})}),e.jsx(Le,{children:Me.map(s=>e.jsx(ye,{value:s.value,children:s.label},s.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{className:"text-sm font-medium text-gray-900",children:(we==null?void 0:we.label)??n("extraHeaders")}),e.jsx(es,{value:H,onChange:ne}),e.jsx("p",{className:"text-xs text-gray-500",children:n("providerExtraHeadersHelpShort")})]})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between border-t border-gray-100 px-6 py-4",children:[e.jsxs(z,{type:"button",variant:"outline",size:"sm",onClick:wt,disabled:j.isPending,children:[e.jsx(Lt,{className:"mr-1.5 h-4 w-4"}),j.isPending?n("providerTestingConnection"):n("providerTestConnection")]}),e.jsx(z,{type:"submit",disabled:d.isPending||!Ue,children:d.isPending?n("saving"):Ue?n("save"):n("unchanged")})]})]})]})}function ds(t){if(!t)return null;try{const r=new URL(t),a=r.pathname&&r.pathname!=="/"?r.pathname:"";return`${r.host}${a}`}catch{return t.replace(/^https?:\/\//,"")}}function As(){const{data:t}=ct(),{data:r}=dt(),{data:a}=ut(),l=Ot(),[c,g]=x.useState("installed"),[d,u]=x.useState(),[j,b]=x.useState(""),w=a==null?void 0:a.uiHints,I=(r==null?void 0:r.providers)??[],D=(t==null?void 0:t.providers)??{},k=I.filter(f=>{var v;return(v=D[f.name])==null?void 0:v.apiKeySet}).length,A=[{id:"installed",label:n("providersTabConfigured"),count:k},{id:"all",label:n("providersTabAll"),count:I.length}],P=x.useMemo(()=>{const f=(r==null?void 0:r.providers)??[],v=(t==null?void 0:t.providers)??{},N=j.trim().toLowerCase();return f.filter(M=>{var E;return c==="installed"?!!((E=v[M.name])!=null&&E.apiKeySet):!0}).filter(M=>{var R,$;return N?((($=(R=v[M.name])==null?void 0:R.displayName)==null?void 0:$.trim())||M.displayName||M.name).toLowerCase().includes(N)||M.name.toLowerCase().includes(N):!0})},[r,t,c,j]);x.useEffect(()=>{if(P.length===0){u(void 0);return}P.some(v=>v.name===d)||u(P[0].name)},[P,d]);const H=d,ne=async()=>{try{const f=await l.mutateAsync({data:{}});g("all"),b(""),u(f.name)}catch{}};return!t||!r?e.jsx("div",{className:"p-8",children:n("providersLoading")}):e.jsxs(Yt,{children:[e.jsx(Zt,{title:n("providersPageTitle"),description:n("providersPageDescription")}),e.jsxs("div",{className:Gt,children:[e.jsxs("section",{className:Vt,children:[e.jsxs("div",{className:"border-b border-gray-100 px-4 pt-4 pb-3 space-y-3",children:[e.jsx(Qt,{tabs:A,activeTab:c,onChange:g,className:"mb-0"}),e.jsxs(z,{type:"button",variant:"outline",className:"w-full justify-center",onClick:ne,disabled:l.isPending,children:[e.jsx(_e,{className:"mr-2 h-4 w-4"}),l.isPending?n("saving"):n("providerAddCustom")]})]}),e.jsx("div",{className:"border-b border-gray-100 px-4 py-3",children:e.jsxs("div",{className:"relative",children:[e.jsx(It,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx(X,{value:j,onChange:f=>b(f.target.value),placeholder:n("providersFilterPlaceholder"),className:"h-10 rounded-xl pl-9"})]})}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-2 overflow-y-auto p-3",children:[P.map(f=>{var Y;const v=t.providers[f.name],N=!!(v!=null&&v.apiKeySet),M=H===f.name,E=((Y=v==null?void 0:v.displayName)==null?void 0:Y.trim())||f.displayName||f.name,_=le(`providers.${f.name}`,w),R=(v==null?void 0:v.apiBase)||f.defaultApiBase||"",U=ds(R)||(_==null?void 0:_.help)||n("providersDefaultDescription");return e.jsx("button",{type:"button",onClick:()=>u(f.name),className:de("w-full rounded-xl border p-2.5 text-left transition-all",M?"border-primary/30 bg-primary-50/40 shadow-sm":"border-gray-200/70 bg-white hover:border-gray-300 hover:bg-gray-50/70"),children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(Xt,{name:f.name,src:f.logo?`/logos/${f.logo}`:null,className:de("h-10 w-10 rounded-lg border",N?"border-primary/30 bg-white":"border-gray-200/70 bg-white"),imgClassName:"h-5 w-5 object-contain",fallback:e.jsx("span",{className:"text-sm font-semibold uppercase text-gray-500",children:f.name[0]})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-semibold text-gray-900",children:E}),e.jsx("p",{className:"line-clamp-1 text-[11px] text-gray-500",children:U})]})]}),e.jsx(mt,{status:N?"ready":"setup",label:N?n("statusReady"):n("statusSetup"),className:"min-w-[56px] justify-center"})]})},f.name)}),P.length===0&&e.jsxs("div",{className:"flex h-full min-h-[220px] flex-col items-center justify-center rounded-xl border border-dashed border-gray-200 bg-gray-50/70 py-10 text-center",children:[e.jsx("div",{className:"mb-3 flex h-10 w-10 items-center justify-center rounded-lg bg-white",children:e.jsx(Dt,{className:"h-5 w-5 text-gray-300"})}),e.jsx("p",{className:"text-sm font-medium text-gray-700",children:n("providersNoMatch")})]})]})]}),e.jsx(cs,{providerName:H,onProviderDeleted:f=>{f===d&&u(void 0)}})]})]})}export{As as ProvidersList};
1
+ import{r as x,j as e,av as Mt,aw as Tt,ap as ot,aj as _e,b as kt,e as F,ax as tt,ay as st,C as St,az as Lt,s as It,K as Dt}from"./vendor-CwsIoNvJ.js";import{c as de,I as X,B as z,t as n,u as ct,a as dt,b as ut,U as Et,V as _t,W as $t,X as Bt,Y as zt,Z as Kt,_ as Ft,S as Te,e as ke,f as Se,g as Le,h as ye,$ as Ot}from"./index-CeRbsQ90.js";import{L as O}from"./label-CCSffS1D.js";import{a as Ht,b as Rt,c as Wt}from"./popover-Bfoe6YBX.js";import{S as mt}from"./status-dot-Fz9-eKsl.js";import{h as le}from"./config-hints-CApS3K_7.js";import{c as qt,b as Ut,C as Gt,a as Vt}from"./config-layout-BHnOoweL.js";import{T as Qt}from"./tabs-custom-6Tm1ZHfS.js";import{L as Xt}from"./LogoBadge-D7j1al-w.js";import{P as Yt,a as Zt}from"./page-layout-ud8wZ8gX.js";import"./index-Ct7FQpxN.js";function Jt({isSet:t,className:r,value:a,onChange:l,placeholder:c,...g}){const[d,u]=x.useState(!1),[j,b]=x.useState(!1),w=typeof a=="string"&&a.length>0,I=t&&!w&&!j;return e.jsxs("div",{className:"relative",children:[I?e.jsx("div",{onClick:()=>b(!0),className:de("flex h-9 w-full rounded-xl border border-gray-200/80 bg-white px-3.5 py-2 text-sm text-gray-500 cursor-text items-center pr-12",r),children:"••••••••••••"}):e.jsx(X,{type:d?"text":"password",className:de("pr-12",r),value:a,onChange:l,onBlur:()=>{w||b(!1)},placeholder:c,autoFocus:j,...g}),e.jsx("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex gap-1",children:(t||w)&&e.jsx(z,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>u(!d),children:d?e.jsx(Mt,{className:"h-4 w-4"}):e.jsx(Tt,{className:"h-4 w-4"})})})]})}function es({value:t,onChange:r,className:a}){const l=t?Object.entries(t):[],c=(u,j,b)=>{const w=[...l];w[u]=[j,b],r(Object.fromEntries(w))},g=()=>{r({...t,"":""})},d=u=>{const j=l.filter((b,w)=>w!==u);r(Object.fromEntries(j))};return e.jsxs("div",{className:de("space-y-2",a),children:[l.map(([u,j],b)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(X,{type:"text",value:u,onChange:w=>c(b,w.target.value,j),placeholder:n("headerName"),className:"flex-1"}),e.jsx(X,{type:"text",value:j,onChange:w=>c(b,u,w.target.value),placeholder:n("headerValue"),className:"flex-1"}),e.jsx(z,{type:"button",variant:"ghost",size:"icon",onClick:()=>d(b),children:e.jsx(ot,{className:"h-4 w-4 text-red-500"})})]},b)),e.jsxs(z,{type:"button",variant:"outline",size:"sm",onClick:g,children:[e.jsx(_e,{className:"h-4 w-4 mr-2"}),n("add")]})]})}const ts={displayName:"",apiKeySet:!1,apiBase:null,extraHeaders:null,wireApi:null,models:[],modelThinking:{}},Ee=["off","minimal","low","medium","high","adaptive","xhigh"],ss=new Set(Ee);function ce(t){if(!t)return null;const r=Object.entries(t).map(([a,l])=>[a.trim(),l]).filter(([a])=>a.length>0);return r.length===0?null:Object.fromEntries(r)}function nt(t,r){const a=ce(t),l=ce(r);if(a===null&&l===null)return!0;if(!a||!l)return!1;const c=Object.entries(a).sort(([d],[u])=>d.localeCompare(u)),g=Object.entries(l).sort(([d],[u])=>d.localeCompare(u));return c.length!==g.length?!1:c.every(([d,u],j)=>d===g[j][0]&&u===g[j][1])}function Ie(t){if(!t||t.length===0)return[];const r=new Set;for(const a of t){const l=a.trim();l&&r.add(l)}return[...r]}function ns(t,r){const a=t.trim();if(!a||!r.trim())return a;const l=`${r.trim()}/`;return a.startsWith(l)?a.slice(l.length):a}function oe(t,r){let a=t.trim();if(!a)return"";for(const l of r){const c=l.trim();c&&(a=ns(a,c))}return a.trim()}function je(t,r){return t.length!==r.length?!1:t.every((a,l)=>a===r[l])}function rs(t,r){const a=[...t];for(const l of r)a.includes(l)||a.push(l);return a}function as(t,r){return r.length===0?t:r.every(l=>!t.includes(l))?rs(t,r):r}function is(t,r){return je(t,r)?[]:t}function $e(t){if(typeof t!="string")return null;const r=t.trim().toLowerCase();return r&&ss.has(r)?r:null}function ht(t){if(!Array.isArray(t))return[];const r=[];for(const a of t){const l=$e(a);!l||r.includes(l)||r.push(l)}return r}function ls(t,r){if(!t)return{};const a={};for(const[l,c]of Object.entries(t)){const g=oe(l,r);if(!g)continue;const d=ht(c==null?void 0:c.supported);if(d.length===0)continue;const u=$e(c==null?void 0:c.default);a[g]=u&&d.includes(u)?{supported:d,default:u}:{supported:d}}return a}function De(t,r){const a=new Set(r.map(c=>c.trim()).filter(Boolean)),l={};for(const[c,g]of Object.entries(t)){if(!a.has(c))continue;const d=ht(g.supported);if(d.length===0)continue;const u=$e(g.default);l[c]=u&&d.includes(u)?{supported:d,default:u}:{supported:d}}return l}function rt(t,r){const a=Object.keys(t).sort(),l=Object.keys(r).sort();if(a.length!==l.length)return!1;for(let c=0;c<a.length;c+=1){const g=a[c];if(g!==l[c])return!1;const d=t[g],u=r[g];if(!d||!u)return!1;const j=[...d.supported].sort(),b=[...u.supported].sort();if(!je(j,b)||(d.default??null)!==(u.default??null))return!1}return!0}function at(t){return t==="off"?n("chatThinkingLevelOff"):t==="minimal"?n("chatThinkingLevelMinimal"):t==="low"?n("chatThinkingLevelLow"):t==="medium"?n("chatThinkingLevelMedium"):t==="high"?n("chatThinkingLevelHigh"):t==="adaptive"?n("chatThinkingLevelAdaptive"):n("chatThinkingLevelXhigh")}function os(t){var j,b,w,I,D;const{providerName:r,methods:a,defaultMethodId:l,language:c}=t;if(a.length===0)return"";const g=new Map;for(const k of a){const A=k.id.trim();A&&g.set(A.toLowerCase(),A)}const d=(...k)=>{for(const A of k){const P=g.get(A.toLowerCase());if(P)return P}},u=l==null?void 0:l.trim();if(r==="minimax-portal"){if(c==="zh")return d("cn","china-mainland")??d(u??"")??((j=a[0])==null?void 0:j.id)??"";if(c==="en")return d("global","intl","international")??d(u??"")??((b=a[0])==null?void 0:b.id)??""}if(u){const k=d(u);if(k)return k}return c==="zh"?d("cn")??((w=a[0])==null?void 0:w.id)??"":c==="en"?d("global")??((I=a[0])==null?void 0:I.id)??"":((D=a[0])==null?void 0:D.id)??""}function it(t){return t.required&&t.hasDefault&&t.optionCount>1&&t.optionCount<=3}function lt(t){const{value:r,onChange:a,options:l}=t;return e.jsx("div",{className:"flex flex-wrap gap-2",children:l.map(c=>{const g=c.value===r;return e.jsx("button",{type:"button",onClick:()=>a(c.value),"aria-pressed":g,className:`rounded-full border px-3 py-1.5 text-xs font-medium transition-colors ${g?"border-primary bg-primary text-white shadow-sm":"border-gray-200 bg-white text-gray-700 hover:border-primary/40 hover:text-primary"}`,children:c.label},c.value)})})}function cs({providerName:t,onProviderDeleted:r}){var Ve,Qe,Xe,Ye,Ze,Je,et;const a=kt(),{data:l}=ct(),{data:c}=dt(),{data:g}=ut(),d=Et(),u=_t(),j=$t(),b=Bt(),w=zt(),I=Kt(),[D,k]=x.useState(""),[A,P]=x.useState(""),[H,ne]=x.useState(null),[f,v]=x.useState("auto"),[N,M]=x.useState([]),[E,_]=x.useState({}),[R,$]=x.useState(""),[U,Y]=x.useState(""),[be,pt]=x.useState(!1),[ve,ue]=x.useState(!1),[me,W]=x.useState(null),[Be,B]=x.useState(""),[ze,he]=x.useState(""),pe=x.useRef(null),i=c==null?void 0:c.providers.find(s=>s.name===t),T=(t?l==null?void 0:l.providers[t]:null)??ts,xe=g==null?void 0:g.uiHints,Z=!!(i!=null&&i.isCustom),J=t?le(`providers.${t}.apiKey`,xe):void 0,K=t?le(`providers.${t}.apiBase`,xe):void 0,we=t?le(`providers.${t}.extraHeaders`,xe):void 0,Ne=t?le(`providers.${t}.wireApi`,xe):void 0,Ke=(i==null?void 0:i.displayName)||t||"",ee=(T.displayName||"").trim()||Ke,xt=U.trim()||ee||t||n("providersSelectPlaceholder"),Fe=(i==null?void 0:i.modelPrefix)||t||"",q=x.useMemo(()=>Ie([Fe,t||""]),[Fe,t]),Ce=(i==null?void 0:i.defaultApiBase)||"",re=T.apiBase||Ce,Ae=ce(T.extraHeaders||null),ae=T.wireApi||(i==null?void 0:i.defaultWireApi)||"auto",Pe=x.useMemo(()=>Ie(((i==null?void 0:i.defaultModels)??[]).map(s=>oe(s,q))),[i==null?void 0:i.defaultModels,q]),Oe=x.useMemo(()=>Ie((T.models??[]).map(s=>oe(s,q))),[T.models,q]),G=x.useMemo(()=>as(Pe,Oe),[Pe,Oe]),ie=x.useMemo(()=>De(ls(T.modelThinking,q),G),[G,q,T.modelThinking]),V=Ft(),ft=((Ve=i==null?void 0:i.apiBaseHelp)==null?void 0:Ve[V])||((Qe=i==null?void 0:i.apiBaseHelp)==null?void 0:Qe.en)||(K==null?void 0:K.help)||n("providerApiBaseHelp"),p=i==null?void 0:i.auth,S=x.useMemo(()=>(p==null?void 0:p.methods)??[],[p==null?void 0:p.methods]),He=x.useMemo(()=>S.map(s=>{var o,h;return{value:s.id,label:((o=s.label)==null?void 0:o[V])||((h=s.label)==null?void 0:h.en)||s.id}}),[S,V]),fe=x.useMemo(()=>os({providerName:t,methods:S,defaultMethodId:p==null?void 0:p.defaultMethodId,language:V}),[t,p==null?void 0:p.defaultMethodId,S,V]),te=x.useMemo(()=>{var o;if(!S.length)return"";const s=ze.trim();return s&&S.some(h=>h.id===s)?s:fe||((o=S[0])==null?void 0:o.id)||""},[ze,fe,S]),se=x.useMemo(()=>S.find(s=>s.id===te),[S,te]),Re=((Xe=se==null?void 0:se.hint)==null?void 0:Xe[V])||((Ye=se==null?void 0:se.hint)==null?void 0:Ye.en)||"",gt=it({required:(p==null?void 0:p.kind)==="device_code",hasDefault:!!((Ze=p==null?void 0:p.defaultMethodId)!=null&&Ze.trim()),optionCount:S.length}),We=((Je=p==null?void 0:p.note)==null?void 0:Je[V])||((et=p==null?void 0:p.note)==null?void 0:et.en)||(p==null?void 0:p.displayName)||"",Me=((i==null?void 0:i.wireApiOptions)||["auto","chat","responses"]).map(s=>({value:s,label:s==="chat"?n("wireApiChat"):s==="responses"?n("wireApiResponses"):n("wireApiAuto")})),yt=it({required:!!(i!=null&&i.supportsWireApi),hasDefault:typeof(i==null?void 0:i.defaultWireApi)=="string"&&i.defaultWireApi.length>0,optionCount:Me.length}),L=x.useCallback(()=>{pe.current!==null&&(window.clearTimeout(pe.current),pe.current=null)},[]),qe=x.useCallback((s,o)=>{L(),pe.current=window.setTimeout(()=>{(async()=>{if(t)try{const h=await w.mutateAsync({provider:t,data:{sessionId:s}});if(h.status==="pending"){B(n("providerAuthWaitingBrowser")),qe(s,h.nextPollMs??o);return}if(h.status==="authorized"){W(null),L(),B(n("providerAuthCompleted")),F.success(n("providerAuthCompleted")),a.invalidateQueries({queryKey:["config"]}),a.invalidateQueries({queryKey:["config-meta"]});return}W(null),L(),B(h.message||`Authorization ${h.status}.`),F.error(h.message||`Authorization ${h.status}.`)}catch(h){W(null),L();const m=h instanceof Error?h.message:String(h);B(m),F.error(`Authorization failed: ${m}`)}})()},Math.max(1e3,o))},[L,w,t,a]);x.useEffect(()=>{if(!t){k(""),P(""),ne(null),v("auto"),M([]),_({}),$(""),Y(""),W(null),B(""),he(""),L();return}k(""),P(re),ne(T.extraHeaders||null),v(ae),M(G),_(ie),$(""),Y(ee),W(null),B(""),he(fe),L()},[t,re,T.extraHeaders,ae,G,ie,ee,fe,L]),x.useEffect(()=>()=>L(),[L]),x.useEffect(()=>{_(s=>De(s,N))},[N]);const Ue=x.useMemo(()=>{if(!t)return!1;const s=D.trim().length>0,o=A.trim()!==re.trim(),h=!nt(H,Ae),m=i!=null&&i.supportsWireApi?f!==ae:!1,y=!je(N,G),C=!rt(E,ie),ge=Z?U.trim()!==ee:!1;return s||o||h||m||y||C||ge},[t,Z,U,ee,D,A,re,H,Ae,i==null?void 0:i.supportsWireApi,f,ae,N,G,E,ie]),Ge=()=>{const s=oe(R,q);if(s){if(N.includes(s)){$("");return}M(o=>[...o,s]),$("")}},jt=(s,o)=>{_(h=>{const m=h[s],y=(m==null?void 0:m.supported)??[],C=y.includes(o)?y.filter(Q=>Q!==o):Ee.filter(Q=>Q===o||y.includes(Q));if(C.length===0){const Q={...h};return delete Q[s],Q}const ge=m!=null&&m.default&&C.includes(m.default)?m.default:void 0;return{...h,[s]:ge?{supported:C,default:ge}:{supported:C}}})},bt=(s,o)=>{_(h=>{const m=h[s];return!m||m.supported.length===0||o&&!m.supported.includes(o)?h:{...h,[s]:o?{supported:m.supported,default:o}:{supported:m.supported}}})},vt=s=>{if(s.preventDefault(),!t)return;const o={},h=D.trim(),m=A.trim(),y=ce(H),C=U.trim();Z&&C!==ee&&(o.displayName=C.length>0?C:null),h.length>0&&(o.apiKey=h),m!==re.trim()&&(o.apiBase=m.length>0&&m!==Ce?m:null),nt(y,Ae)||(o.extraHeaders=y),i!=null&&i.supportsWireApi&&f!==ae&&(o.wireApi=f),je(N,G)||(o.models=is(N,Pe)),rt(E,ie)||(o.modelThinking=De(E,N)),d.mutate({provider:t,data:o})},wt=async()=>{if(!t)return;const s=N.find(m=>m.trim().length>0)??"",o=oe(s,q),h={apiBase:A.trim(),extraHeaders:ce(H),model:o||null};D.trim().length>0&&(h.apiKey=D.trim()),i!=null&&i.supportsWireApi&&(h.wireApi=f);try{const m=await j.mutateAsync({provider:t,data:h});if(m.success){F.success(`${n("providerTestConnectionSuccess")} (${m.latencyMs}ms)`);return}const y=[`provider=${m.provider}`,`latency=${m.latencyMs}ms`];m.model&&y.push(`model=${m.model}`),F.error(`${n("providerTestConnectionFailed")}: ${m.message} | ${y.join(" | ")}`)}catch(m){const y=m instanceof Error?m.message:String(m);F.error(`${n("providerTestConnectionFailed")}: ${y}`)}},Nt=async()=>{if(!(!t||!Z||!window.confirm(n("providerDeleteConfirm"))))try{await u.mutateAsync({provider:t}),r==null||r(t)}catch{}},Ct=async()=>{if(!(!t||(p==null?void 0:p.kind)!=="device_code"))try{B("");const s=await b.mutateAsync({provider:t,data:te?{methodId:te}:{}});if(!s.sessionId||!s.verificationUri)throw new Error(n("providerAuthStartFailed"));W(s.sessionId),B(`${n("providerAuthOpenPrompt")}${s.userCode}${n("providerAuthOpenPromptSuffix")}`),window.open(s.verificationUri,"_blank","noopener,noreferrer"),qe(s.sessionId,s.intervalMs)}catch(s){const o=s instanceof Error?s.message:String(s);W(null),L(),B(o),F.error(`${n("providerAuthStartFailed")}: ${o}`)}},At=async()=>{if(!(!t||(p==null?void 0:p.kind)!=="device_code"))try{L(),W(null);const s=await I.mutateAsync({provider:t}),o=s.expiresAt?` (expires: ${s.expiresAt})`:"";B(`${n("providerAuthImportStatusPrefix")}${o}`),F.success(n("providerAuthImportSuccess")),a.invalidateQueries({queryKey:["config"]}),a.invalidateQueries({queryKey:["config-meta"]})}catch(s){const o=s instanceof Error?s.message:String(s);B(o),F.error(`${n("providerAuthImportFailed")}: ${o}`)}};if(!t||!i)return e.jsx("div",{className:qt,children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-gray-900",children:n("providersSelectTitle")}),e.jsx("p",{className:"mt-2 text-sm text-gray-500",children:n("providersSelectDescription")})]})});const Pt=T.apiKeySet?n("statusReady"):n("statusSetup");return e.jsxs("div",{className:Ut,children:[e.jsx("div",{className:"border-b border-gray-100 px-6 py-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"truncate text-lg font-semibold text-gray-900",children:xt}),e.jsxs("div",{className:"flex items-center gap-3",children:[Z&&e.jsx("button",{type:"button",onClick:Nt,disabled:u.isPending,className:"text-gray-400 hover:text-red-500 transition-colors",title:n("providerDelete"),children:e.jsx(ot,{className:"h-4 w-4"})}),e.jsx(mt,{status:T.apiKeySet?"ready":"setup",label:Pt})]})]})}),e.jsxs("form",{onSubmit:vt,className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto px-6 py-5",children:[Z&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"providerDisplayName",className:"text-sm font-medium text-gray-900",children:n("providerDisplayName")}),e.jsx(X,{id:"providerDisplayName",type:"text",value:U,onChange:s=>Y(s.target.value),placeholder:Ke||n("providerDisplayNamePlaceholder"),className:"rounded-xl"}),e.jsx("p",{className:"text-xs text-gray-500",children:n("providerDisplayNameHelpShort")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"apiKey",className:"text-sm font-medium text-gray-900",children:(J==null?void 0:J.label)??n("apiKey")}),e.jsx(Jt,{id:"apiKey",value:D,isSet:T.apiKeySet,onChange:s=>k(s.target.value),placeholder:(J==null?void 0:J.placeholder)??n("enterApiKey"),className:"rounded-xl"}),e.jsx("p",{className:"text-xs text-gray-500",children:n("leaveBlankToKeepUnchanged")})]}),(p==null?void 0:p.kind)==="device_code"&&e.jsxs("div",{className:"space-y-2 rounded-xl border border-primary/20 bg-primary-50/50 p-3",children:[e.jsx(O,{className:"text-sm font-medium text-gray-900",children:p.displayName||n("providerAuthSectionTitle")}),We?e.jsx("p",{className:"text-xs text-gray-600",children:We}):null,S.length>1?e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{className:"text-xs font-medium text-gray-700",children:n("providerAuthMethodLabel")}),gt?e.jsx(lt,{value:te,onChange:he,options:He}):e.jsxs(Te,{value:te,onValueChange:he,children:[e.jsx(ke,{className:"h-8 rounded-lg bg-white",children:e.jsx(Se,{placeholder:n("providerAuthMethodPlaceholder")})}),e.jsx(Le,{children:He.map(s=>e.jsx(ye,{value:s.value,children:s.label},s.value))})]}),Re?e.jsx("p",{className:"text-xs text-gray-500",children:Re}):null]}):null,e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(z,{type:"button",variant:"outline",size:"sm",onClick:Ct,disabled:b.isPending||!!me,children:b.isPending?n("providerAuthStarting"):me?n("providerAuthAuthorizing"):n("providerAuthAuthorizeInBrowser")}),p.supportsCliImport?e.jsx(z,{type:"button",variant:"outline",size:"sm",onClick:At,disabled:I.isPending,children:I.isPending?n("providerAuthImporting"):n("providerAuthImportFromCli")}):null,me?e.jsxs("span",{className:"text-xs text-gray-500",children:[n("providerAuthSessionLabel"),": ",me.slice(0,8),"…"]}):null]}),Be?e.jsx("p",{className:"text-xs text-gray-600",children:Be}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"apiBase",className:"text-sm font-medium text-gray-900",children:(K==null?void 0:K.label)??n("apiBase")}),e.jsx(X,{id:"apiBase",type:"text",value:A,onChange:s=>P(s.target.value),placeholder:Ce||(K==null?void 0:K.placeholder)||"https://api.example.com",className:"rounded-xl"}),e.jsx("p",{className:"text-xs text-gray-500",children:ft})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(O,{className:"text-sm font-medium text-gray-900",children:n("providerModelsTitle")}),!ve&&e.jsxs("button",{type:"button",onClick:()=>ue(!0),className:"text-xs text-primary hover:text-primary/80 font-medium flex items-center gap-1",children:[e.jsx(_e,{className:"h-3 w-3"}),n("providerAddModel")]})]}),ve&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{value:R,onChange:s=>$(s.target.value),onKeyDown:s=>{s.key==="Enter"&&(s.preventDefault(),Ge()),s.key==="Escape"&&(ue(!1),$(""))},placeholder:n("providerModelInputPlaceholder"),className:"flex-1 rounded-xl",autoFocus:!0}),e.jsx(z,{type:"button",size:"sm",onClick:Ge,disabled:R.trim().length===0,children:n("add")}),e.jsx(z,{type:"button",size:"sm",variant:"ghost",onClick:()=>{ue(!1),$("")},children:e.jsx(tt,{className:"h-4 w-4"})})]}),N.length===0?e.jsxs("div",{className:"rounded-xl border border-dashed border-gray-200 bg-gray-50 px-4 py-6 text-center",children:[e.jsx("p",{className:"text-sm text-gray-500",children:n("providerModelsEmptyShort")}),!ve&&e.jsx("button",{type:"button",onClick:()=>ue(!0),className:"mt-2 text-sm text-primary hover:text-primary/80 font-medium",children:n("providerAddFirstModel")})]}):e.jsx("div",{className:"flex flex-wrap gap-2",children:N.map(s=>{const o=E[s],h=(o==null?void 0:o.supported)??[],m=(o==null?void 0:o.default)??null;return e.jsxs("div",{className:"group inline-flex max-w-full items-center gap-1 rounded-full border border-gray-200 bg-white px-3 py-1.5",children:[e.jsx("span",{className:"max-w-[140px] truncate text-sm text-gray-800 sm:max-w-[220px]",children:s}),e.jsxs(Ht,{children:[e.jsx(Rt,{asChild:!0,children:e.jsx("button",{type:"button",className:"inline-flex h-5 w-5 items-center justify-center rounded-full text-gray-400 transition-opacity hover:bg-gray-100 hover:text-gray-600 opacity-100 md:opacity-0 md:group-hover:opacity-100 md:group-focus-within:opacity-100","aria-label":n("providerModelThinkingTitle"),title:n("providerModelThinkingTitle"),children:e.jsx(st,{className:"h-3 w-3"})})}),e.jsxs(Wt,{className:"w-80 space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-semibold text-gray-800",children:n("providerModelThinkingTitle")}),e.jsx("p",{className:"text-xs text-gray-500",children:n("providerModelThinkingHint")})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Ee.map(y=>{const C=h.includes(y);return e.jsx("button",{type:"button",onClick:()=>jt(s,y),className:`rounded-full border px-2.5 py-1 text-xs font-medium transition-colors ${C?"border-primary bg-primary text-white":"border-gray-200 bg-white text-gray-600 hover:border-primary/40 hover:text-primary"}`,children:at(y)},y)})}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(O,{className:"text-xs font-medium text-gray-700",children:n("providerModelThinkingDefault")}),e.jsxs(Te,{value:m??"__none__",onValueChange:y=>bt(s,y==="__none__"?null:y),disabled:h.length===0,children:[e.jsx(ke,{className:"h-8 rounded-lg bg-white text-xs",children:e.jsx(Se,{})}),e.jsxs(Le,{children:[e.jsx(ye,{value:"__none__",children:n("providerModelThinkingDefaultNone")}),h.map(y=>e.jsx(ye,{value:y,children:at(y)},y))]})]}),h.length===0?e.jsx("p",{className:"text-xs text-gray-500",children:n("providerModelThinkingNoSupported")}):null]})]})]}),e.jsx("button",{type:"button",onClick:()=>{M(y=>y.filter(C=>C!==s)),_(y=>{const C={...y};return delete C[s],C})},className:"inline-flex h-5 w-5 items-center justify-center rounded-full text-gray-400 transition-opacity hover:bg-gray-100 hover:text-gray-600 opacity-100 md:opacity-0 md:group-hover:opacity-100 md:group-focus-within:opacity-100","aria-label":n("remove"),children:e.jsx(tt,{className:"h-3 w-3"})})]},s)})})]}),e.jsxs("div",{className:"border-t border-gray-100 pt-4",children:[e.jsxs("button",{type:"button",onClick:()=>pt(!be),className:"flex w-full items-center justify-between text-sm text-gray-600 hover:text-gray-900 transition-colors",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(st,{className:"h-3.5 w-3.5"}),n("providerAdvancedSettings")]}),e.jsx(St,{className:`h-4 w-4 transition-transform ${be?"rotate-180":""}`})]}),be&&e.jsxs("div",{className:"mt-4 space-y-5",children:[i.supportsWireApi&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"wireApi",className:"text-sm font-medium text-gray-900",children:(Ne==null?void 0:Ne.label)??n("wireApi")}),yt?e.jsx(lt,{value:f,onChange:s=>v(s),options:Me}):e.jsxs(Te,{value:f,onValueChange:s=>v(s),children:[e.jsx(ke,{className:"rounded-xl",children:e.jsx(Se,{})}),e.jsx(Le,{children:Me.map(s=>e.jsx(ye,{value:s.value,children:s.label},s.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{className:"text-sm font-medium text-gray-900",children:(we==null?void 0:we.label)??n("extraHeaders")}),e.jsx(es,{value:H,onChange:ne}),e.jsx("p",{className:"text-xs text-gray-500",children:n("providerExtraHeadersHelpShort")})]})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between border-t border-gray-100 px-6 py-4",children:[e.jsxs(z,{type:"button",variant:"outline",size:"sm",onClick:wt,disabled:j.isPending,children:[e.jsx(Lt,{className:"mr-1.5 h-4 w-4"}),j.isPending?n("providerTestingConnection"):n("providerTestConnection")]}),e.jsx(z,{type:"submit",disabled:d.isPending||!Ue,children:d.isPending?n("saving"):Ue?n("save"):n("unchanged")})]})]})]})}function ds(t){if(!t)return null;try{const r=new URL(t),a=r.pathname&&r.pathname!=="/"?r.pathname:"";return`${r.host}${a}`}catch{return t.replace(/^https?:\/\//,"")}}function As(){const{data:t}=ct(),{data:r}=dt(),{data:a}=ut(),l=Ot(),[c,g]=x.useState("installed"),[d,u]=x.useState(),[j,b]=x.useState(""),w=a==null?void 0:a.uiHints,I=(r==null?void 0:r.providers)??[],D=(t==null?void 0:t.providers)??{},k=I.filter(f=>{var v;return(v=D[f.name])==null?void 0:v.apiKeySet}).length,A=[{id:"installed",label:n("providersTabConfigured"),count:k},{id:"all",label:n("providersTabAll"),count:I.length}],P=x.useMemo(()=>{const f=(r==null?void 0:r.providers)??[],v=(t==null?void 0:t.providers)??{},N=j.trim().toLowerCase();return f.filter(M=>{var E;return c==="installed"?!!((E=v[M.name])!=null&&E.apiKeySet):!0}).filter(M=>{var R,$;return N?((($=(R=v[M.name])==null?void 0:R.displayName)==null?void 0:$.trim())||M.displayName||M.name).toLowerCase().includes(N)||M.name.toLowerCase().includes(N):!0})},[r,t,c,j]);x.useEffect(()=>{if(P.length===0){u(void 0);return}P.some(v=>v.name===d)||u(P[0].name)},[P,d]);const H=d,ne=async()=>{try{const f=await l.mutateAsync({data:{}});g("all"),b(""),u(f.name)}catch{}};return!t||!r?e.jsx("div",{className:"p-8",children:n("providersLoading")}):e.jsxs(Yt,{children:[e.jsx(Zt,{title:n("providersPageTitle"),description:n("providersPageDescription")}),e.jsxs("div",{className:Gt,children:[e.jsxs("section",{className:Vt,children:[e.jsxs("div",{className:"border-b border-gray-100 px-4 pt-4 pb-3 space-y-3",children:[e.jsx(Qt,{tabs:A,activeTab:c,onChange:g,className:"mb-0"}),e.jsxs(z,{type:"button",variant:"outline",className:"w-full justify-center",onClick:ne,disabled:l.isPending,children:[e.jsx(_e,{className:"mr-2 h-4 w-4"}),l.isPending?n("saving"):n("providerAddCustom")]})]}),e.jsx("div",{className:"border-b border-gray-100 px-4 py-3",children:e.jsxs("div",{className:"relative",children:[e.jsx(It,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx(X,{value:j,onChange:f=>b(f.target.value),placeholder:n("providersFilterPlaceholder"),className:"h-10 rounded-xl pl-9"})]})}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-2 overflow-y-auto p-3",children:[P.map(f=>{var Y;const v=t.providers[f.name],N=!!(v!=null&&v.apiKeySet),M=H===f.name,E=((Y=v==null?void 0:v.displayName)==null?void 0:Y.trim())||f.displayName||f.name,_=le(`providers.${f.name}`,w),R=(v==null?void 0:v.apiBase)||f.defaultApiBase||"",U=ds(R)||(_==null?void 0:_.help)||n("providersDefaultDescription");return e.jsx("button",{type:"button",onClick:()=>u(f.name),className:de("w-full rounded-xl border p-2.5 text-left transition-all",M?"border-primary/30 bg-primary-50/40 shadow-sm":"border-gray-200/70 bg-white hover:border-gray-300 hover:bg-gray-50/70"),children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(Xt,{name:f.name,src:f.logo?`/logos/${f.logo}`:null,className:de("h-10 w-10 rounded-lg border",N?"border-primary/30 bg-white":"border-gray-200/70 bg-white"),imgClassName:"h-5 w-5 object-contain",fallback:e.jsx("span",{className:"text-sm font-semibold uppercase text-gray-500",children:f.name[0]})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-semibold text-gray-900",children:E}),e.jsx("p",{className:"line-clamp-1 text-[11px] text-gray-500",children:U})]})]}),e.jsx(mt,{status:N?"ready":"setup",label:N?n("statusReady"):n("statusSetup"),className:"min-w-[56px] justify-center"})]})},f.name)}),P.length===0&&e.jsxs("div",{className:"flex h-full min-h-[220px] flex-col items-center justify-center rounded-xl border border-dashed border-gray-200 bg-gray-50/70 py-10 text-center",children:[e.jsx("div",{className:"mb-3 flex h-10 w-10 items-center justify-center rounded-lg bg-white",children:e.jsx(Dt,{className:"h-5 w-5 text-gray-300"})}),e.jsx("p",{className:"text-sm font-medium text-gray-700",children:n("providersNoMatch")})]})]})]}),e.jsx(cs,{providerName:H,onProviderDeleted:f=>{f===d&&u(void 0)}})]})]})}export{As as ProvidersList};
@@ -0,0 +1 @@
1
+ import{u as q,d as b,b as D,e as m,r as o,j as t,aY as U,aZ as K,a_ as H,K as O,a$ as Q,b0 as V,b1 as _}from"./vendor-CwsIoNvJ.js";import{af as y,t as r,C as N,a3 as B,a4 as p,a5 as C,z as M,s as I,I as L,B as g}from"./index-CeRbsQ90.js";import{P as z,a as W}from"./page-layout-ud8wZ8gX.js";import{L as $}from"./label-CCSffS1D.js";import{S as E}from"./status-dot-Fz9-eKsl.js";import{S as G}from"./switch-B-_SrMSL.js";async function Y(){const e=await y.get("/api/remote/status");if(!e.ok)throw new Error(e.error.message);return e.data}async function Z(){const e=await y.get("/api/remote/doctor");if(!e.ok)throw new Error(e.error.message);return e.data}async function J(e){const s=await y.post("/api/remote/auth/start",e);if(!s.ok)throw new Error(s.error.message);return s.data}async function X(e){const s=await y.post("/api/remote/auth/poll",e);if(!s.ok)throw new Error(s.error.message);return s.data}async function ee(){const e=await y.post("/api/remote/logout",{});if(!e.ok)throw new Error(e.error.message);return e.data}async function te(e){const s=await y.put("/api/remote/settings",e);if(!s.ok)throw new Error(s.error.message);return s.data}async function re(e){const s=await y.post(`/api/remote/service/${e}`,{});if(!s.ok)throw new Error(s.error.message);return s.data}function se(){return q({queryKey:["remote-status"],queryFn:Y,staleTime:5e3,refetchOnWindowFocus:!0})}function ae(){return b({mutationFn:J,onError:e=>{m.error(`${r("remoteBrowserAuthStartFailed")}: ${e.message}`)}})}function ne(){const e=D();return b({mutationFn:X,onSuccess:s=>{s.status==="authorized"&&(e.invalidateQueries({queryKey:["remote-status"]}),m.success(r("remoteLoginSuccess")))},onError:s=>{m.error(`${r("remoteBrowserAuthPollFailed")}: ${s.message}`)}})}function ie(){const e=D();return b({mutationFn:ee,onSuccess:()=>{e.invalidateQueries({queryKey:["remote-status"]}),m.success(r("remoteLogoutSuccess"))},onError:s=>{m.error(`${r("remoteLogoutFailed")}: ${s.message}`)}})}function oe(){const e=D();return b({mutationFn:te,onSuccess:()=>{e.invalidateQueries({queryKey:["remote-status"]}),m.success(r("remoteSettingsSaved"))},onError:s=>{m.error(`${r("remoteSettingsSaveFailed")}: ${s.message}`)}})}function ce(){return b({mutationFn:Z,onSuccess:()=>{m.success(r("remoteDoctorCompleted"))},onError:e=>{m.error(`${r("remoteDoctorFailed")}: ${e.message}`)}})}function le(){const e=D();return b({mutationFn:re,onSuccess:s=>{e.invalidateQueries({queryKey:["remote-status"]}),m.success(s.message)},onError:s=>{m.error(`${r("remoteServiceActionFailed")}: ${s.message}`)}})}function ue(e){return e?e.state==="connected"?{status:"ready",label:r("remoteStateConnected")}:e.state==="connecting"?{status:"warning",label:r("remoteStateConnecting")}:e.state==="error"?{status:"warning",label:r("remoteStateError")}:e.state==="disconnected"?{status:"warning",label:r("remoteStateDisconnected")}:{status:"inactive",label:r("remoteStateDisabled")}:{status:"inactive",label:r("remoteRuntimeMissing")}}function me(e){return e.running?e.currentProcess?{status:"ready",label:r("remoteServiceManagedRunning")}:{status:"active",label:r("remoteServiceRunning")}:{status:"inactive",label:r("remoteServiceStopped")}}function n(e){const s=e.value===void 0||e.value===null||e.value===""?"-":String(e.value);return t.jsxs("div",{className:"flex items-start justify-between gap-4 py-2 text-sm",children:[t.jsx("span",{className:"text-gray-500",children:e.label}),t.jsx("span",{className:e.muted?"text-right text-gray-500":"text-right text-gray-800",children:s})]})}function T(e,s){return e.trim()||(s==null?void 0:s.settings.platformApiBase)||(s==null?void 0:s.account.apiBase)||void 0}function de(e){const{status:s,platformApiBase:i,startBrowserAuth:c,pollBrowserAuth:v}=e,[x,l]=o.useState(null),[a,d]=o.useState(null),[S,u]=o.useState(""),[f,P]=o.useState(null),[A,j]=o.useState(1500);return o.useEffect(()=>{s!=null&&s.account.loggedIn&&(l(null),d(null),P(null),u(""),j(1500))},[s==null?void 0:s.account.loggedIn]),o.useEffect(()=>{if(!x||s!=null&&s.account.loggedIn)return;let h=!1;const F=window.setTimeout(async()=>{try{const R=await v.mutateAsync({sessionId:x,apiBase:T(i,s)});if(h)return;if(R.status==="pending"){u(r("remoteBrowserAuthWaiting")),j(R.nextPollMs??1500);return}if(R.status==="authorized"){u(r("remoteBrowserAuthCompleted")),l(null),d(null);return}u(R.message||r("remoteBrowserAuthExpired")),l(null),d(null)}catch{if(h)return;l(null),d(null)}},A);return()=>{h=!0,window.clearTimeout(F)}},[A,x,i,v,s]),{authExpiresAt:f,authSessionId:x,authStatusMessage:S,authVerificationUri:a,resume:()=>{a&&window.open(a,"_blank","noopener,noreferrer")},start:async()=>{const h=await c.mutateAsync({apiBase:T(i,s)});l(h.sessionId),d(h.verificationUri),P(h.expiresAt),j(h.intervalMs),u(r("remoteBrowserAuthWaiting")),window.open(h.verificationUri,"_blank","noopener,noreferrer")||u(r("remoteBrowserAuthPopupBlocked"))}}}function xe(e){var s,i,c,v,x,l,a,d,S,u,f;return t.jsxs(N,{children:[t.jsxs(B,{children:[t.jsxs(p,{className:"flex items-center gap-2",children:[t.jsx(U,{className:"h-4 w-4 text-primary"}),r("remoteOverviewTitle")]}),t.jsx(C,{children:r("remoteOverviewDescription")})]}),t.jsxs(M,{className:"space-y-5",children:[t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(E,{status:(s=e.status)!=null&&s.account.loggedIn?"ready":"inactive",label:(i=e.status)!=null&&i.account.loggedIn?r("remoteAccountConnected"):r("remoteAccountNotConnected")}),t.jsx(E,{status:e.serviceStatus.status,label:e.serviceStatus.label}),t.jsx(E,{status:e.runtimeStatus.status,label:e.runtimeStatus.label})]}),t.jsxs("div",{className:"rounded-2xl border border-gray-200/70 bg-gray-50/70 px-4 py-3",children:[t.jsx(n,{label:r("remoteLocalOrigin"),value:(c=e.status)==null?void 0:c.localOrigin}),t.jsx(n,{label:r("remotePublicPlatform"),value:((v=e.status)==null?void 0:v.platformBase)??((x=e.status)==null?void 0:x.account.platformBase)}),t.jsx(n,{label:r("remoteDeviceId"),value:(a=(l=e.status)==null?void 0:l.runtime)==null?void 0:a.deviceId,muted:!0}),t.jsx(n,{label:r("remoteLastConnectedAt"),value:(S=(d=e.status)==null?void 0:d.runtime)!=null&&S.lastConnectedAt?I(e.status.runtime.lastConnectedAt):"-",muted:!0}),t.jsx(n,{label:r("remoteLastError"),value:(f=(u=e.status)==null?void 0:u.runtime)==null?void 0:f.lastError,muted:!0})]})]})]})}function he(e){return t.jsxs(N,{children:[t.jsxs(B,{children:[t.jsxs(p,{className:"flex items-center gap-2",children:[t.jsx(K,{className:"h-4 w-4 text-primary"}),r("remoteDeviceTitle")]}),t.jsx(C,{children:r("remoteDeviceDescription")})]}),t.jsxs(M,{className:"space-y-4",children:[t.jsx("div",{className:"space-y-2",children:t.jsxs("div",{className:"flex items-center justify-between rounded-2xl border border-gray-200/70 px-4 py-3",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-sm font-medium text-gray-900",children:r("remoteEnabled")}),t.jsx("p",{className:"mt-1 text-xs text-gray-500",children:r("remoteEnabledHelp")})]}),t.jsx(G,{checked:e.enabled,onCheckedChange:e.setEnabled})]})}),t.jsxs("div",{className:"space-y-2",children:[t.jsx($,{htmlFor:"remote-device-name",children:r("remoteDeviceName")}),t.jsx(L,{id:"remote-device-name",value:e.deviceName,onChange:s=>e.setDeviceName(s.target.value),placeholder:r("remoteDeviceNamePlaceholder")})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx($,{htmlFor:"remote-platform-api-base",children:r("remotePlatformApiBase")}),t.jsx(L,{id:"remote-platform-api-base",value:e.platformApiBase,onChange:s=>e.setPlatformApiBase(s.target.value),placeholder:"https://ai-gateway-api.nextclaw.io/v1"}),t.jsx("p",{className:"text-xs text-gray-500",children:r("remotePlatformApiBaseHelp")})]}),t.jsxs("div",{className:"flex flex-wrap gap-3",children:[t.jsx(g,{onClick:()=>e.settingsMutation.mutate({enabled:e.enabled,deviceName:e.deviceName,platformApiBase:e.platformApiBase}),disabled:e.settingsMutation.isPending,children:e.settingsMutation.isPending?r("saving"):r("remoteSaveSettings")}),t.jsxs(g,{variant:"outline",onClick:()=>e.serviceMutation.mutate("restart"),disabled:e.serviceMutation.isPending,children:[t.jsx(H,{className:"mr-2 h-4 w-4"}),r("remoteRestartService")]})]}),t.jsx("p",{className:"text-xs text-gray-500",children:r("remoteSaveHint")})]})]})}function ge(e){var s,i,c;return t.jsxs(N,{children:[t.jsxs(B,{children:[t.jsxs(p,{className:"flex items-center gap-2",children:[t.jsx(O,{className:"h-4 w-4 text-primary"}),r("remoteAccountTitle")]}),t.jsx(C,{children:r("remoteAccountDescription")})]}),t.jsx(M,{className:"space-y-4",children:(s=e.status)!=null&&s.account.loggedIn?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"rounded-2xl border border-gray-200/70 bg-gray-50/70 px-4 py-3",children:[t.jsx(n,{label:r("remoteAccountEmail"),value:e.status.account.email}),t.jsx(n,{label:r("remoteAccountRole"),value:e.status.account.role}),t.jsx(n,{label:r("remoteApiBase"),value:e.status.account.apiBase})]}),t.jsx(g,{variant:"outline",onClick:()=>e.logoutMutation.mutate(),disabled:e.logoutMutation.isPending,children:e.logoutMutation.isPending?r("remoteLoggingOut"):r("remoteLogout")})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"rounded-2xl border border-gray-200/70 bg-gray-50/70 px-4 py-3",children:[t.jsx("p",{className:"text-sm font-medium text-gray-900",children:r("remoteBrowserAuthTitle")}),t.jsx("p",{className:"mt-1 text-sm text-gray-600",children:r("remoteBrowserAuthDescription")}),t.jsxs("div",{className:"mt-3 border-t border-white/80 pt-3",children:[t.jsx(n,{label:r("remoteApiBase"),value:e.platformApiBase||((i=e.status)==null?void 0:i.settings.platformApiBase)||((c=e.status)==null?void 0:c.account.apiBase),muted:!0}),t.jsx(n,{label:r("remoteBrowserAuthSession"),value:e.authSessionId,muted:!0}),t.jsx(n,{label:r("remoteBrowserAuthExpiresAt"),value:e.authExpiresAt?I(e.authExpiresAt):"-",muted:!0})]})]}),e.authStatusMessage?t.jsx("p",{className:"text-sm text-gray-600",children:e.authStatusMessage}):null,t.jsxs("div",{className:"flex flex-wrap gap-3",children:[t.jsx(g,{onClick:e.onStartBrowserAuth,disabled:e.browserAuthStartMutation.isPending||!!e.authSessionId,children:e.browserAuthStartMutation.isPending?r("remoteBrowserAuthStarting"):e.authSessionId?r("remoteBrowserAuthAuthorizing"):r("remoteBrowserAuthAction")}),e.authVerificationUri?t.jsx(g,{variant:"outline",onClick:e.onResumeBrowserAuth,children:r("remoteBrowserAuthResume")}):null]}),t.jsx("p",{className:"text-xs text-gray-500",children:r("remoteBrowserAuthHint")})]})})]})}function ve(e){var s,i,c;return t.jsxs(N,{children:[t.jsxs(B,{children:[t.jsxs(p,{className:"flex items-center gap-2",children:[t.jsx(Q,{className:"h-4 w-4 text-primary"}),r("remoteServiceTitle")]}),t.jsx(C,{children:r("remoteServiceDescription")})]}),t.jsxs(M,{className:"space-y-4",children:[t.jsxs("div",{className:"rounded-2xl border border-gray-200/70 bg-gray-50/70 px-4 py-3",children:[t.jsx(n,{label:r("remoteServicePid"),value:(s=e.status)==null?void 0:s.service.pid}),t.jsx(n,{label:r("remoteServiceUiUrl"),value:(i=e.status)==null?void 0:i.service.uiUrl}),t.jsx(n,{label:r("remoteServiceCurrentProcess"),value:(c=e.status)!=null&&c.service.currentProcess?r("yes"):r("no")})]}),t.jsxs("div",{className:"flex flex-wrap gap-3",children:[t.jsx(g,{variant:"primary",onClick:()=>e.serviceMutation.mutate("start"),disabled:e.serviceMutation.isPending,children:r("remoteStartService")}),t.jsx(g,{variant:"outline",onClick:()=>e.serviceMutation.mutate("restart"),disabled:e.serviceMutation.isPending,children:r("remoteRestartService")}),t.jsx(g,{variant:"outline",onClick:()=>e.serviceMutation.mutate("stop"),disabled:e.serviceMutation.isPending,children:r("remoteStopService")})]}),t.jsx("p",{className:"text-xs text-gray-500",children:r("remoteServiceHint")})]})]})}function fe(e){return t.jsxs(N,{children:[t.jsxs(B,{children:[t.jsxs(p,{className:"flex items-center gap-2",children:[t.jsx(V,{className:"h-4 w-4 text-primary"}),r("remoteDoctorTitle")]}),t.jsx(C,{children:r("remoteDoctorDescription")})]}),t.jsxs(M,{className:"space-y-4",children:[t.jsx("div",{className:"flex flex-wrap gap-3",children:t.jsxs(g,{variant:"outline",onClick:()=>e.doctorMutation.mutate(),disabled:e.doctorMutation.isPending,children:[t.jsx(_,{className:"mr-2 h-4 w-4"}),e.doctorMutation.isPending?r("remoteDoctorRunning"):r("remoteRunDoctor")]})}),e.doctorMutation.data?t.jsx(je,{doctor:e.doctorMutation.data}):t.jsx("p",{className:"text-sm text-gray-500",children:r("remoteDoctorEmpty")})]})]})}function je(e){return t.jsxs("div",{className:"rounded-2xl border border-gray-200/70 bg-gray-50/70 px-4 py-3",children:[t.jsx(n,{label:r("remoteDoctorGeneratedAt"),value:I(e.doctor.generatedAt),muted:!0}),t.jsx("div",{className:"mt-3 space-y-2",children:e.doctor.checks.map(s=>t.jsxs("div",{className:"rounded-xl border border-white bg-white px-3 py-3",children:[t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx("span",{className:"text-sm font-medium text-gray-900",children:s.name}),t.jsx(E,{status:s.ok?"ready":"warning",label:s.ok?r("remoteCheckPassed"):r("remoteCheckFailed")})]}),t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:s.detail})]},s.name))})]})}function Be(){const e=se(),s=ae(),i=ne(),c=ie(),v=oe(),x=ce(),l=le(),a=e.data,d=o.useMemo(()=>ue((a==null?void 0:a.runtime)??null),[a==null?void 0:a.runtime]),S=o.useMemo(()=>me((a==null?void 0:a.service)??{running:!1,currentProcess:!1}),[a==null?void 0:a.service]),[u,f]=o.useState(!1),[P,A]=o.useState(""),[j,k]=o.useState(""),w=de({status:a,platformApiBase:j,startBrowserAuth:s,pollBrowserAuth:i});return o.useEffect(()=>{a&&(f(a.settings.enabled),A(a.settings.deviceName),k(a.settings.platformApiBase))},[a]),e.isLoading&&!a?t.jsx("div",{className:"p-8 text-gray-400",children:r("remoteLoading")}):t.jsxs(z,{className:"space-y-6",children:[t.jsx(W,{title:r("remotePageTitle"),description:r("remotePageDescription")}),t.jsxs("div",{className:"grid gap-6 xl:grid-cols-[1.35fr_0.95fr]",children:[t.jsx(xe,{status:a,runtimeStatus:d,serviceStatus:S}),t.jsx(he,{enabled:u,setEnabled:f,deviceName:P,setDeviceName:A,platformApiBase:j,setPlatformApiBase:k,settingsMutation:v,serviceMutation:l})]}),t.jsxs("div",{className:"grid gap-6 xl:grid-cols-[1fr_1fr]",children:[t.jsx(ge,{status:a,platformApiBase:j,browserAuthStartMutation:s,logoutMutation:c,authSessionId:w.authSessionId,authExpiresAt:w.authExpiresAt,authStatusMessage:w.authStatusMessage,authVerificationUri:w.authVerificationUri,onStartBrowserAuth:w.start,onResumeBrowserAuth:w.resume}),t.jsx(ve,{status:a,serviceMutation:l})]}),t.jsx(fe,{doctorMutation:x})]})}export{Be as RemoteAccessPage};
@@ -1 +1 @@
1
- import{r as p,j as e,ap as ee,aj as ae,aV as de,e as se}from"./vendor-CwsIoNvJ.js";import{u as me,b as he,a2 as ue,t,C as R,a3 as $,a4 as z,a5 as D,z as L,I as i,S as te,e as re,f as ne,g as le,h as S,B as w}from"./index-BWvap_iq.js";import{S as pe}from"./switch-DSdHSIsC.js";import{h as x}from"./config-hints-CApS3K_7.js";import{P as xe,a as ge}from"./page-layout-sNhcbwtm.js";const je=[{value:"main",label:"main"},{value:"per-peer",label:"per-peer"},{value:"per-channel-peer",label:"per-channel-peer"},{value:"per-account-channel-peer",label:"per-account-channel-peer"}];function ve(){return{id:"",default:!1,workspace:"",model:"",engine:"",contextTokens:void 0,maxToolIterations:void 0}}function fe(){return{agentId:"",match:{channel:"",accountId:""}}}function ce(d){const b=d.trim();if(!b)return;const j=Number.parseInt(b,10);return Number.isFinite(j)?j:void 0}function Ce(){const{data:d,isLoading:b}=me(),{data:j}=he(),A=ue(),[_,N]=p.useState([]),[q,E]=p.useState([]),[K,V]=p.useState("per-channel-peer"),[F,U]=p.useState(0),[G,J]=p.useState(2e5),[Q,W]=p.useState("native");p.useEffect(()=>{var a,r,n;d&&(N((d.agents.list??[]).map(s=>({id:s.id??"",default:!!s.default,workspace:s.workspace??"",model:s.model??"",engine:s.engine??"",contextTokens:s.contextTokens,maxToolIterations:s.maxToolIterations}))),E((d.bindings??[]).map(s=>{var c,l,o;return{agentId:s.agentId??"",match:{channel:((c=s.match)==null?void 0:c.channel)??"",accountId:((l=s.match)==null?void 0:l.accountId)??"",peer:(o=s.match)!=null&&o.peer?{kind:s.match.peer.kind,id:s.match.peer.id}:void 0}}})),V(((a=d.session)==null?void 0:a.dmScope)??"per-channel-peer"),U(((n=(r=d.session)==null?void 0:r.agentToAgent)==null?void 0:n.maxPingPongTurns)??0),J(d.agents.defaults.contextTokens??2e5),W(d.agents.defaults.engine??"native"))},[d]);const u=j==null?void 0:j.uiHints,h=x("session.dmScope",u),v=x("session.agentToAgent.maxPingPongTurns",u),f=x("agents.defaults.contextTokens",u),I=x("agents.defaults.engine",u),O=x("agents.list.*.contextTokens",u),B=x("agents.list.*.engine",u),y=x("agents.list",u),k=x("bindings",u),oe=p.useMemo(()=>{const a=new Set(["main"]);return _.forEach(r=>{const n=r.id.trim();n&&a.add(n)}),a},[_]),g=(a,r)=>{N(n=>n.map((s,c)=>c===a?{...s,...r}:s))},T=(a,r)=>{E(n=>n.map((s,c)=>c===a?r:s))},ie=()=>{try{const a=_.map((s,c)=>{var m,C,P;const l=s.id.trim();if(!l)throw new Error(t("agentIdRequiredError").replace("{index}",String(c)));const o={id:l};return s.default&&(o.default=!0),(m=s.workspace)!=null&&m.trim()&&(o.workspace=s.workspace.trim()),(C=s.model)!=null&&C.trim()&&(o.model=s.model.trim()),(P=s.engine)!=null&&P.trim()&&(o.engine=s.engine.trim()),typeof s.contextTokens=="number"&&(o.contextTokens=Math.max(1e3,s.contextTokens)),typeof s.maxToolIterations=="number"&&(o.maxToolIterations=s.maxToolIterations),o}),r=a.map(s=>s.id).filter((s,c,l)=>l.indexOf(s)!==c);if(r.length>0){se.error(`${t("duplicateAgentId")}: ${r[0]}`);return}const n=q.map((s,c)=>{var X,Y,Z,H;const l=s.agentId.trim(),o=s.match.channel.trim(),m=((X=s.match.accountId)==null?void 0:X.trim())??"",C=(Y=s.match.peer)==null?void 0:Y.kind,P=((H=(Z=s.match.peer)==null?void 0:Z.id)==null?void 0:H.trim())??"";if(!l)throw new Error(t("bindingAgentIdRequired").replace("{index}",String(c)));if(!oe.has(l))throw new Error(`${t("bindingAgentIdNotFound").replace("{index}",String(c))}: ${l}`);if(!o)throw new Error(t("bindingChannelRequired").replace("{index}",String(c)));const M={agentId:l,match:{channel:o}};if(m&&(M.match.accountId=m),C){if(!P)throw new Error(t("bindingPeerIdRequired").replace("{index}",String(c)));M.match.peer={kind:C,id:P}}return M});A.mutate({data:{agents:{defaults:{contextTokens:Math.max(1e3,G),engine:Q.trim()||"native"},list:a},bindings:n,session:{dmScope:K,agentToAgent:{maxPingPongTurns:Math.min(5,Math.max(0,F))}}}})}catch(a){const r=a instanceof Error?a.message:String(a);se.error(r)}};return b||!d?e.jsx("div",{className:"p-8 text-gray-400",children:t("runtimeLoading")}):e.jsxs(xe,{className:"space-y-6",children:[e.jsx(ge,{title:t("runtimePageTitle"),description:t("runtimePageDescription")}),e.jsxs(R,{children:[e.jsxs($,{children:[e.jsx(z,{children:(h==null?void 0:h.label)??t("dmScope")}),e.jsx(D,{children:(h==null?void 0:h.help)??t("dmScopeHelp")})]}),e.jsxs(L,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-gray-800",children:(f==null?void 0:f.label)??t("defaultContextTokens")}),e.jsx(i,{type:"number",min:1e3,step:1e3,value:G,onChange:a=>J(Math.max(1e3,Number.parseInt(a.target.value,10)||1e3))}),e.jsx("p",{className:"text-xs text-gray-500",children:(f==null?void 0:f.help)??t("defaultContextTokensHelp")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-gray-800",children:(I==null?void 0:I.label)??t("defaultEngine")}),e.jsx(i,{value:Q,onChange:a=>W(a.target.value),placeholder:t("defaultEnginePlaceholder")}),e.jsx("p",{className:"text-xs text-gray-500",children:(I==null?void 0:I.help)??t("defaultEngineHelp")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-gray-800",children:(h==null?void 0:h.label)??t("dmScope")}),e.jsxs(te,{value:K,onValueChange:a=>V(a),children:[e.jsx(re,{children:e.jsx(ne,{})}),e.jsx(le,{children:je.map(a=>e.jsx(S,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-gray-800",children:(v==null?void 0:v.label)??t("maxPingPongTurns")}),e.jsx(i,{type:"number",min:0,max:5,value:F,onChange:a=>U(Math.max(0,Number.parseInt(a.target.value,10)||0))}),e.jsx("p",{className:"text-xs text-gray-500",children:(v==null?void 0:v.help)??t("maxPingPongTurnsHelp")})]})]})]}),e.jsxs(R,{children:[e.jsxs($,{children:[e.jsx(z,{children:(y==null?void 0:y.label)??t("agentList")}),e.jsx(D,{children:(y==null?void 0:y.help)??t("agentListHelp")})]}),e.jsxs(L,{className:"space-y-3",children:[_.map((a,r)=>e.jsxs("div",{className:"rounded-xl border border-gray-200 p-3 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsx(i,{value:a.id,onChange:n=>g(r,{id:n.target.value}),placeholder:t("agentIdPlaceholder")}),e.jsx(i,{value:a.workspace??"",onChange:n=>g(r,{workspace:n.target.value}),placeholder:t("workspaceOverridePlaceholder")}),e.jsx(i,{value:a.model??"",onChange:n=>g(r,{model:n.target.value}),placeholder:t("modelOverridePlaceholder")}),e.jsx(i,{value:a.engine??"",onChange:n=>g(r,{engine:n.target.value}),placeholder:(B==null?void 0:B.label)??t("engineOverridePlaceholder")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2",children:[e.jsx(i,{type:"number",min:1e3,step:1e3,value:a.contextTokens??"",onChange:n=>g(r,{contextTokens:ce(n.target.value)}),placeholder:(O==null?void 0:O.label)??t("contextTokensPlaceholder")}),e.jsx(i,{type:"number",min:1,value:a.maxToolIterations??"",onChange:n=>g(r,{maxToolIterations:ce(n.target.value)}),placeholder:t("maxToolsPlaceholder")})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-600",children:[e.jsx(pe,{checked:!!a.default,onCheckedChange:n=>{if(!n){g(r,{default:!1});return}N(s=>s.map((c,l)=>({...c,default:l===r})))}}),e.jsx("span",{children:t("defaultAgent")})]}),e.jsxs(w,{type:"button",variant:"outline",size:"sm",onClick:()=>N(n=>n.filter((s,c)=>c!==r)),children:[e.jsx(ee,{className:"h-4 w-4 mr-1"}),t("remove")]})]})]},`${r}-${a.id}`)),e.jsxs(w,{type:"button",variant:"outline",onClick:()=>N(a=>[...a,ve()]),children:[e.jsx(ae,{className:"h-4 w-4 mr-2"}),t("addAgent")]})]})]}),e.jsxs(R,{children:[e.jsxs($,{children:[e.jsx(z,{children:(k==null?void 0:k.label)??t("bindings")}),e.jsx(D,{children:(k==null?void 0:k.help)??t("bindingsHelp")})]}),e.jsxs(L,{className:"space-y-3",children:[q.map((a,r)=>{var s,c;const n=((s=a.match.peer)==null?void 0:s.kind)??"";return e.jsxs("div",{className:"rounded-xl border border-gray-200 p-3 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:[e.jsx(i,{value:a.agentId,onChange:l=>T(r,{...a,agentId:l.target.value}),placeholder:t("targetAgentIdPlaceholder")}),e.jsx(i,{value:a.match.channel,onChange:l=>T(r,{...a,match:{...a.match,channel:l.target.value}}),placeholder:t("channelPlaceholder")}),e.jsx(i,{value:a.match.accountId??"",onChange:l=>T(r,{...a,match:{...a.match,accountId:l.target.value}}),placeholder:t("accountIdOptionalPlaceholder")}),e.jsxs(te,{value:n||"__none__",onValueChange:l=>{var m;const o=l==="__none__"?"":l;if(!o){T(r,{...a,match:{...a.match,peer:void 0}});return}T(r,{...a,match:{...a.match,peer:{kind:o,id:((m=a.match.peer)==null?void 0:m.id)??""}}})},children:[e.jsx(re,{children:e.jsx(ne,{})}),e.jsxs(le,{children:[e.jsx(S,{value:"__none__",children:t("peerKindOptional")}),e.jsx(S,{value:"direct",children:"direct"}),e.jsx(S,{value:"group",children:"group"}),e.jsx(S,{value:"channel",children:"channel"})]})]}),e.jsx(i,{value:((c=a.match.peer)==null?void 0:c.id)??"",onChange:l=>T(r,{...a,match:{...a.match,peer:n?{kind:n,id:l.target.value}:void 0}}),placeholder:t("peerIdPlaceholder")})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(w,{type:"button",variant:"outline",size:"sm",onClick:()=>E(l=>l.filter((o,m)=>m!==r)),children:[e.jsx(ee,{className:"h-4 w-4 mr-1"}),t("remove")]})})]},`${r}-${a.agentId}`)}),e.jsxs(w,{type:"button",variant:"outline",onClick:()=>E(a=>[...a,fe()]),children:[e.jsx(ae,{className:"h-4 w-4 mr-2"}),t("addBinding")]})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(w,{type:"button",onClick:ie,disabled:A.isPending,children:[e.jsx(de,{className:"h-4 w-4 mr-2"}),A.isPending?t("saving"):t("saveRuntimeSettings")]})})]})}export{Ce as RuntimeConfig};
1
+ import{r as p,j as e,ap as ee,aj as ae,aV as de,e as se}from"./vendor-CwsIoNvJ.js";import{u as me,b as he,a2 as ue,t,C as R,a3 as $,a4 as z,a5 as D,z as L,I as i,S as te,e as re,f as ne,g as le,h as S,B as w}from"./index-CeRbsQ90.js";import{S as pe}from"./switch-B-_SrMSL.js";import{h as x}from"./config-hints-CApS3K_7.js";import{P as xe,a as ge}from"./page-layout-ud8wZ8gX.js";const je=[{value:"main",label:"main"},{value:"per-peer",label:"per-peer"},{value:"per-channel-peer",label:"per-channel-peer"},{value:"per-account-channel-peer",label:"per-account-channel-peer"}];function ve(){return{id:"",default:!1,workspace:"",model:"",engine:"",contextTokens:void 0,maxToolIterations:void 0}}function fe(){return{agentId:"",match:{channel:"",accountId:""}}}function ce(d){const b=d.trim();if(!b)return;const j=Number.parseInt(b,10);return Number.isFinite(j)?j:void 0}function Ce(){const{data:d,isLoading:b}=me(),{data:j}=he(),A=ue(),[_,N]=p.useState([]),[q,E]=p.useState([]),[K,V]=p.useState("per-channel-peer"),[F,U]=p.useState(0),[G,J]=p.useState(2e5),[Q,W]=p.useState("native");p.useEffect(()=>{var a,r,n;d&&(N((d.agents.list??[]).map(s=>({id:s.id??"",default:!!s.default,workspace:s.workspace??"",model:s.model??"",engine:s.engine??"",contextTokens:s.contextTokens,maxToolIterations:s.maxToolIterations}))),E((d.bindings??[]).map(s=>{var c,l,o;return{agentId:s.agentId??"",match:{channel:((c=s.match)==null?void 0:c.channel)??"",accountId:((l=s.match)==null?void 0:l.accountId)??"",peer:(o=s.match)!=null&&o.peer?{kind:s.match.peer.kind,id:s.match.peer.id}:void 0}}})),V(((a=d.session)==null?void 0:a.dmScope)??"per-channel-peer"),U(((n=(r=d.session)==null?void 0:r.agentToAgent)==null?void 0:n.maxPingPongTurns)??0),J(d.agents.defaults.contextTokens??2e5),W(d.agents.defaults.engine??"native"))},[d]);const u=j==null?void 0:j.uiHints,h=x("session.dmScope",u),v=x("session.agentToAgent.maxPingPongTurns",u),f=x("agents.defaults.contextTokens",u),I=x("agents.defaults.engine",u),O=x("agents.list.*.contextTokens",u),B=x("agents.list.*.engine",u),y=x("agents.list",u),k=x("bindings",u),oe=p.useMemo(()=>{const a=new Set(["main"]);return _.forEach(r=>{const n=r.id.trim();n&&a.add(n)}),a},[_]),g=(a,r)=>{N(n=>n.map((s,c)=>c===a?{...s,...r}:s))},T=(a,r)=>{E(n=>n.map((s,c)=>c===a?r:s))},ie=()=>{try{const a=_.map((s,c)=>{var m,C,P;const l=s.id.trim();if(!l)throw new Error(t("agentIdRequiredError").replace("{index}",String(c)));const o={id:l};return s.default&&(o.default=!0),(m=s.workspace)!=null&&m.trim()&&(o.workspace=s.workspace.trim()),(C=s.model)!=null&&C.trim()&&(o.model=s.model.trim()),(P=s.engine)!=null&&P.trim()&&(o.engine=s.engine.trim()),typeof s.contextTokens=="number"&&(o.contextTokens=Math.max(1e3,s.contextTokens)),typeof s.maxToolIterations=="number"&&(o.maxToolIterations=s.maxToolIterations),o}),r=a.map(s=>s.id).filter((s,c,l)=>l.indexOf(s)!==c);if(r.length>0){se.error(`${t("duplicateAgentId")}: ${r[0]}`);return}const n=q.map((s,c)=>{var X,Y,Z,H;const l=s.agentId.trim(),o=s.match.channel.trim(),m=((X=s.match.accountId)==null?void 0:X.trim())??"",C=(Y=s.match.peer)==null?void 0:Y.kind,P=((H=(Z=s.match.peer)==null?void 0:Z.id)==null?void 0:H.trim())??"";if(!l)throw new Error(t("bindingAgentIdRequired").replace("{index}",String(c)));if(!oe.has(l))throw new Error(`${t("bindingAgentIdNotFound").replace("{index}",String(c))}: ${l}`);if(!o)throw new Error(t("bindingChannelRequired").replace("{index}",String(c)));const M={agentId:l,match:{channel:o}};if(m&&(M.match.accountId=m),C){if(!P)throw new Error(t("bindingPeerIdRequired").replace("{index}",String(c)));M.match.peer={kind:C,id:P}}return M});A.mutate({data:{agents:{defaults:{contextTokens:Math.max(1e3,G),engine:Q.trim()||"native"},list:a},bindings:n,session:{dmScope:K,agentToAgent:{maxPingPongTurns:Math.min(5,Math.max(0,F))}}}})}catch(a){const r=a instanceof Error?a.message:String(a);se.error(r)}};return b||!d?e.jsx("div",{className:"p-8 text-gray-400",children:t("runtimeLoading")}):e.jsxs(xe,{className:"space-y-6",children:[e.jsx(ge,{title:t("runtimePageTitle"),description:t("runtimePageDescription")}),e.jsxs(R,{children:[e.jsxs($,{children:[e.jsx(z,{children:(h==null?void 0:h.label)??t("dmScope")}),e.jsx(D,{children:(h==null?void 0:h.help)??t("dmScopeHelp")})]}),e.jsxs(L,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-gray-800",children:(f==null?void 0:f.label)??t("defaultContextTokens")}),e.jsx(i,{type:"number",min:1e3,step:1e3,value:G,onChange:a=>J(Math.max(1e3,Number.parseInt(a.target.value,10)||1e3))}),e.jsx("p",{className:"text-xs text-gray-500",children:(f==null?void 0:f.help)??t("defaultContextTokensHelp")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-gray-800",children:(I==null?void 0:I.label)??t("defaultEngine")}),e.jsx(i,{value:Q,onChange:a=>W(a.target.value),placeholder:t("defaultEnginePlaceholder")}),e.jsx("p",{className:"text-xs text-gray-500",children:(I==null?void 0:I.help)??t("defaultEngineHelp")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-gray-800",children:(h==null?void 0:h.label)??t("dmScope")}),e.jsxs(te,{value:K,onValueChange:a=>V(a),children:[e.jsx(re,{children:e.jsx(ne,{})}),e.jsx(le,{children:je.map(a=>e.jsx(S,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-gray-800",children:(v==null?void 0:v.label)??t("maxPingPongTurns")}),e.jsx(i,{type:"number",min:0,max:5,value:F,onChange:a=>U(Math.max(0,Number.parseInt(a.target.value,10)||0))}),e.jsx("p",{className:"text-xs text-gray-500",children:(v==null?void 0:v.help)??t("maxPingPongTurnsHelp")})]})]})]}),e.jsxs(R,{children:[e.jsxs($,{children:[e.jsx(z,{children:(y==null?void 0:y.label)??t("agentList")}),e.jsx(D,{children:(y==null?void 0:y.help)??t("agentListHelp")})]}),e.jsxs(L,{className:"space-y-3",children:[_.map((a,r)=>e.jsxs("div",{className:"rounded-xl border border-gray-200 p-3 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsx(i,{value:a.id,onChange:n=>g(r,{id:n.target.value}),placeholder:t("agentIdPlaceholder")}),e.jsx(i,{value:a.workspace??"",onChange:n=>g(r,{workspace:n.target.value}),placeholder:t("workspaceOverridePlaceholder")}),e.jsx(i,{value:a.model??"",onChange:n=>g(r,{model:n.target.value}),placeholder:t("modelOverridePlaceholder")}),e.jsx(i,{value:a.engine??"",onChange:n=>g(r,{engine:n.target.value}),placeholder:(B==null?void 0:B.label)??t("engineOverridePlaceholder")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2",children:[e.jsx(i,{type:"number",min:1e3,step:1e3,value:a.contextTokens??"",onChange:n=>g(r,{contextTokens:ce(n.target.value)}),placeholder:(O==null?void 0:O.label)??t("contextTokensPlaceholder")}),e.jsx(i,{type:"number",min:1,value:a.maxToolIterations??"",onChange:n=>g(r,{maxToolIterations:ce(n.target.value)}),placeholder:t("maxToolsPlaceholder")})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-600",children:[e.jsx(pe,{checked:!!a.default,onCheckedChange:n=>{if(!n){g(r,{default:!1});return}N(s=>s.map((c,l)=>({...c,default:l===r})))}}),e.jsx("span",{children:t("defaultAgent")})]}),e.jsxs(w,{type:"button",variant:"outline",size:"sm",onClick:()=>N(n=>n.filter((s,c)=>c!==r)),children:[e.jsx(ee,{className:"h-4 w-4 mr-1"}),t("remove")]})]})]},`${r}-${a.id}`)),e.jsxs(w,{type:"button",variant:"outline",onClick:()=>N(a=>[...a,ve()]),children:[e.jsx(ae,{className:"h-4 w-4 mr-2"}),t("addAgent")]})]})]}),e.jsxs(R,{children:[e.jsxs($,{children:[e.jsx(z,{children:(k==null?void 0:k.label)??t("bindings")}),e.jsx(D,{children:(k==null?void 0:k.help)??t("bindingsHelp")})]}),e.jsxs(L,{className:"space-y-3",children:[q.map((a,r)=>{var s,c;const n=((s=a.match.peer)==null?void 0:s.kind)??"";return e.jsxs("div",{className:"rounded-xl border border-gray-200 p-3 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:[e.jsx(i,{value:a.agentId,onChange:l=>T(r,{...a,agentId:l.target.value}),placeholder:t("targetAgentIdPlaceholder")}),e.jsx(i,{value:a.match.channel,onChange:l=>T(r,{...a,match:{...a.match,channel:l.target.value}}),placeholder:t("channelPlaceholder")}),e.jsx(i,{value:a.match.accountId??"",onChange:l=>T(r,{...a,match:{...a.match,accountId:l.target.value}}),placeholder:t("accountIdOptionalPlaceholder")}),e.jsxs(te,{value:n||"__none__",onValueChange:l=>{var m;const o=l==="__none__"?"":l;if(!o){T(r,{...a,match:{...a.match,peer:void 0}});return}T(r,{...a,match:{...a.match,peer:{kind:o,id:((m=a.match.peer)==null?void 0:m.id)??""}}})},children:[e.jsx(re,{children:e.jsx(ne,{})}),e.jsxs(le,{children:[e.jsx(S,{value:"__none__",children:t("peerKindOptional")}),e.jsx(S,{value:"direct",children:"direct"}),e.jsx(S,{value:"group",children:"group"}),e.jsx(S,{value:"channel",children:"channel"})]})]}),e.jsx(i,{value:((c=a.match.peer)==null?void 0:c.id)??"",onChange:l=>T(r,{...a,match:{...a.match,peer:n?{kind:n,id:l.target.value}:void 0}}),placeholder:t("peerIdPlaceholder")})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(w,{type:"button",variant:"outline",size:"sm",onClick:()=>E(l=>l.filter((o,m)=>m!==r)),children:[e.jsx(ee,{className:"h-4 w-4 mr-1"}),t("remove")]})})]},`${r}-${a.agentId}`)}),e.jsxs(w,{type:"button",variant:"outline",onClick:()=>E(a=>[...a,fe()]),children:[e.jsx(ae,{className:"h-4 w-4 mr-2"}),t("addBinding")]})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(w,{type:"button",onClick:ie,disabled:A.isPending,children:[e.jsx(de,{className:"h-4 w-4 mr-2"}),A.isPending?t("saving"):t("saveRuntimeSettings")]})})]})}export{Ce as RuntimeConfig};
@@ -1 +1 @@
1
- import{r as l,j as e,s as X,a7 as Z,K as $}from"./vendor-CwsIoNvJ.js";import{P as ee,a as se}from"./page-layout-sNhcbwtm.js";import{u as ae,a as re,R as le,t as a,c as k,B as j,S as b,e as y,f as g,g as N,h as m,I as h}from"./index-BWvap_iq.js";import{L as c}from"./label-Bklr3fXc.js";import{C as te,a as ce,b as ne}from"./config-layout-BHnOoweL.js";const ie=[{value:"noLimit",label:"searchFreshnessNoLimit"},{value:"oneDay",label:"searchFreshnessOneDay"},{value:"oneWeek",label:"searchFreshnessOneWeek"},{value:"oneMonth",label:"searchFreshnessOneMonth"},{value:"oneYear",label:"searchFreshnessOneYear"}];function ue(){var O;const{data:u}=ae(),{data:n}=re(),x=le(),i=(n==null?void 0:n.search)??[],r=u==null?void 0:u.search,[t,f]=l.useState("bocha"),[S,P]=l.useState("bocha"),[d,C]=l.useState(["bocha"]),[w,B]=l.useState("10"),[A,T]=l.useState(""),[D,K]=l.useState("https://api.bocha.cn/v1/web-search"),[L,U]=l.useState(!0),[E,R]=l.useState("noLimit"),[F,V]=l.useState(""),[I,_]=l.useState("https://api.search.brave.com/res/v1/web/search");l.useEffect(()=>{r&&(f(r.provider),P(r.provider),C(r.enabledProviders),B(String(r.defaults.maxResults)),K(r.providers.bocha.baseUrl),U(!!r.providers.bocha.summary),R(r.providers.bocha.freshness??"noLimit"),_(r.providers.brave.baseUrl))},[r]);const v=l.useMemo(()=>i.find(s=>s.name===t),[i,t]),G=r==null?void 0:r.providers[t],p=d.includes(t),H=(r==null?void 0:r.providers.bocha.docsUrl)??((O=n==null?void 0:n.search.find(s=>s.name==="bocha"))==null?void 0:O.docsUrl)??"https://open.bocha.cn",W=p?a("searchProviderDeactivate"):a("searchProviderActivate"),M=(s=d,o=S)=>({provider:o,enabledProviders:s,defaults:{maxResults:Number(w)||10},providers:{bocha:{apiKey:A||void 0,baseUrl:D,summary:L,freshness:E},brave:{apiKey:F||void 0,baseUrl:I}}}),Y=()=>{const s=p?d.filter(o=>o!==t):[...d,t];C(s),x.mutate({data:M(s)})},q=s=>{P(s)},z=s=>{s.preventDefault(),x.mutate({data:M()})};return!r||i.length===0?e.jsx("div",{className:"p-8",children:a("loading")}):e.jsxs(ee,{children:[e.jsx(se,{title:a("searchPageTitle"),description:a("searchPageDescription")}),e.jsxs("div",{className:te,children:[e.jsxs("section",{className:ce,children:[e.jsx("div",{className:"border-b border-gray-100 px-4 py-4",children:e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.16em] text-gray-500",children:a("searchChannels")})}),e.jsx("div",{className:"min-h-0 flex-1 space-y-2 overflow-y-auto p-3",children:i.map(s=>{const o=r.providers[s.name],J=d.includes(s.name),Q=t===s.name;return e.jsx("button",{type:"button",onClick:()=>f(s.name),className:k("w-full rounded-xl border p-3 text-left transition-all",Q?"border-primary/30 bg-primary-50/40 shadow-sm":"border-gray-200/70 bg-white hover:border-gray-300 hover:bg-gray-50/70"),children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-semibold text-gray-900",children:s.displayName}),e.jsx("p",{className:"line-clamp-2 text-[11px] text-gray-500",children:s.name==="bocha"?a("searchProviderBochaDescription"):a("searchProviderBraveDescription")})]}),e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("span",{className:"rounded-full bg-gray-100 px-2 py-0.5 text-[11px] font-medium text-gray-600",children:o.apiKeySet?a("searchStatusConfigured"):a("searchStatusNeedsSetup")}),J?e.jsx("span",{className:"rounded-full bg-emerald-50 px-2 py-0.5 text-[11px] font-medium text-emerald-700",children:a("searchProviderActivated")}):null]})]})},s.name)})})]}),e.jsx("form",{onSubmit:z,className:k(ne,"p-6"),children:!v||!G?e.jsx("div",{className:"flex h-full items-center justify-center text-sm text-gray-500",children:a("searchNoProviderSelected")}):e.jsxs("div",{className:"space-y-6 overflow-y-auto",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-xl bg-primary text-white",children:e.jsx(X,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:v.displayName}),e.jsx("p",{className:"text-sm text-gray-500",children:v.description})]})]}),e.jsx(j,{type:"button",variant:p?"secondary":"outline",className:"rounded-xl",onClick:Y,children:W})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:a("searchActiveProvider")}),e.jsxs(b,{value:S,onValueChange:q,children:[e.jsx(y,{className:"rounded-xl",children:e.jsx(g,{})}),e.jsx(N,{children:i.map(s=>e.jsx(m,{value:s.name,children:s.displayName},s.name))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:a("searchDefaultMaxResults")}),e.jsx(h,{value:w,onChange:s=>B(s.target.value),inputMode:"numeric",className:"rounded-xl"})]})]}),t==="bocha"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:a("apiKey")}),e.jsx(h,{type:"password",value:A,onChange:s=>T(s.target.value),placeholder:r.providers.bocha.apiKeyMasked||a("enterApiKey"),className:"rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:a("searchProviderBaseUrl")}),e.jsx(h,{value:D,onChange:s=>K(s.target.value),className:"rounded-xl"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:a("searchProviderSummary")}),e.jsxs(b,{value:L?"true":"false",onValueChange:s=>U(s==="true"),children:[e.jsx(y,{className:"rounded-xl",children:e.jsx(g,{})}),e.jsxs(N,{children:[e.jsx(m,{value:"true",children:a("enabled")}),e.jsx(m,{value:"false",children:a("disabled")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:a("searchProviderFreshness")}),e.jsxs(b,{value:E,onValueChange:R,children:[e.jsx(y,{className:"rounded-xl",children:e.jsx(g,{})}),e.jsx(N,{children:ie.map(s=>e.jsx(m,{value:s.value,children:a(s.label)},s.value))})]})]})]}),e.jsx("div",{className:"space-y-2",children:e.jsx("a",{href:H,target:"_blank",rel:"noreferrer",children:e.jsxs(j,{type:"button",variant:"outline",className:"rounded-xl",children:[e.jsx(Z,{className:"mr-2 h-4 w-4"}),a("searchProviderOpenDocs")]})})})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:a("apiKey")}),e.jsx(h,{type:"password",value:F,onChange:s=>V(s.target.value),placeholder:r.providers.brave.apiKeyMasked||a("enterApiKey"),className:"rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:a("searchProviderBaseUrl")}),e.jsx(h,{value:I,onChange:s=>_(s.target.value),className:"rounded-xl"})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(j,{type:"submit",disabled:x.isPending,children:[e.jsx($,{className:"mr-2 h-4 w-4"}),x.isPending?a("saving"):a("saveChanges")]})})]})})]})]})}export{ue as SearchConfig};
1
+ import{r as l,j as e,s as X,a7 as Z,K as $}from"./vendor-CwsIoNvJ.js";import{P as ee,a as se}from"./page-layout-ud8wZ8gX.js";import{u as ae,a as re,R as le,t as a,c as k,B as j,S as b,e as y,f as g,g as N,h as m,I as h}from"./index-CeRbsQ90.js";import{L as c}from"./label-CCSffS1D.js";import{C as te,a as ce,b as ne}from"./config-layout-BHnOoweL.js";const ie=[{value:"noLimit",label:"searchFreshnessNoLimit"},{value:"oneDay",label:"searchFreshnessOneDay"},{value:"oneWeek",label:"searchFreshnessOneWeek"},{value:"oneMonth",label:"searchFreshnessOneMonth"},{value:"oneYear",label:"searchFreshnessOneYear"}];function ue(){var O;const{data:u}=ae(),{data:n}=re(),x=le(),i=(n==null?void 0:n.search)??[],r=u==null?void 0:u.search,[t,f]=l.useState("bocha"),[S,P]=l.useState("bocha"),[d,C]=l.useState(["bocha"]),[w,B]=l.useState("10"),[A,T]=l.useState(""),[D,K]=l.useState("https://api.bocha.cn/v1/web-search"),[L,U]=l.useState(!0),[E,R]=l.useState("noLimit"),[F,V]=l.useState(""),[I,_]=l.useState("https://api.search.brave.com/res/v1/web/search");l.useEffect(()=>{r&&(f(r.provider),P(r.provider),C(r.enabledProviders),B(String(r.defaults.maxResults)),K(r.providers.bocha.baseUrl),U(!!r.providers.bocha.summary),R(r.providers.bocha.freshness??"noLimit"),_(r.providers.brave.baseUrl))},[r]);const v=l.useMemo(()=>i.find(s=>s.name===t),[i,t]),G=r==null?void 0:r.providers[t],p=d.includes(t),H=(r==null?void 0:r.providers.bocha.docsUrl)??((O=n==null?void 0:n.search.find(s=>s.name==="bocha"))==null?void 0:O.docsUrl)??"https://open.bocha.cn",W=p?a("searchProviderDeactivate"):a("searchProviderActivate"),M=(s=d,o=S)=>({provider:o,enabledProviders:s,defaults:{maxResults:Number(w)||10},providers:{bocha:{apiKey:A||void 0,baseUrl:D,summary:L,freshness:E},brave:{apiKey:F||void 0,baseUrl:I}}}),Y=()=>{const s=p?d.filter(o=>o!==t):[...d,t];C(s),x.mutate({data:M(s)})},q=s=>{P(s)},z=s=>{s.preventDefault(),x.mutate({data:M()})};return!r||i.length===0?e.jsx("div",{className:"p-8",children:a("loading")}):e.jsxs(ee,{children:[e.jsx(se,{title:a("searchPageTitle"),description:a("searchPageDescription")}),e.jsxs("div",{className:te,children:[e.jsxs("section",{className:ce,children:[e.jsx("div",{className:"border-b border-gray-100 px-4 py-4",children:e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.16em] text-gray-500",children:a("searchChannels")})}),e.jsx("div",{className:"min-h-0 flex-1 space-y-2 overflow-y-auto p-3",children:i.map(s=>{const o=r.providers[s.name],J=d.includes(s.name),Q=t===s.name;return e.jsx("button",{type:"button",onClick:()=>f(s.name),className:k("w-full rounded-xl border p-3 text-left transition-all",Q?"border-primary/30 bg-primary-50/40 shadow-sm":"border-gray-200/70 bg-white hover:border-gray-300 hover:bg-gray-50/70"),children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-semibold text-gray-900",children:s.displayName}),e.jsx("p",{className:"line-clamp-2 text-[11px] text-gray-500",children:s.name==="bocha"?a("searchProviderBochaDescription"):a("searchProviderBraveDescription")})]}),e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("span",{className:"rounded-full bg-gray-100 px-2 py-0.5 text-[11px] font-medium text-gray-600",children:o.apiKeySet?a("searchStatusConfigured"):a("searchStatusNeedsSetup")}),J?e.jsx("span",{className:"rounded-full bg-emerald-50 px-2 py-0.5 text-[11px] font-medium text-emerald-700",children:a("searchProviderActivated")}):null]})]})},s.name)})})]}),e.jsx("form",{onSubmit:z,className:k(ne,"p-6"),children:!v||!G?e.jsx("div",{className:"flex h-full items-center justify-center text-sm text-gray-500",children:a("searchNoProviderSelected")}):e.jsxs("div",{className:"space-y-6 overflow-y-auto",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-xl bg-primary text-white",children:e.jsx(X,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:v.displayName}),e.jsx("p",{className:"text-sm text-gray-500",children:v.description})]})]}),e.jsx(j,{type:"button",variant:p?"secondary":"outline",className:"rounded-xl",onClick:Y,children:W})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:a("searchActiveProvider")}),e.jsxs(b,{value:S,onValueChange:q,children:[e.jsx(y,{className:"rounded-xl",children:e.jsx(g,{})}),e.jsx(N,{children:i.map(s=>e.jsx(m,{value:s.name,children:s.displayName},s.name))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:a("searchDefaultMaxResults")}),e.jsx(h,{value:w,onChange:s=>B(s.target.value),inputMode:"numeric",className:"rounded-xl"})]})]}),t==="bocha"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:a("apiKey")}),e.jsx(h,{type:"password",value:A,onChange:s=>T(s.target.value),placeholder:r.providers.bocha.apiKeyMasked||a("enterApiKey"),className:"rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:a("searchProviderBaseUrl")}),e.jsx(h,{value:D,onChange:s=>K(s.target.value),className:"rounded-xl"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:a("searchProviderSummary")}),e.jsxs(b,{value:L?"true":"false",onValueChange:s=>U(s==="true"),children:[e.jsx(y,{className:"rounded-xl",children:e.jsx(g,{})}),e.jsxs(N,{children:[e.jsx(m,{value:"true",children:a("enabled")}),e.jsx(m,{value:"false",children:a("disabled")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:a("searchProviderFreshness")}),e.jsxs(b,{value:E,onValueChange:R,children:[e.jsx(y,{className:"rounded-xl",children:e.jsx(g,{})}),e.jsx(N,{children:ie.map(s=>e.jsx(m,{value:s.value,children:a(s.label)},s.value))})]})]})]}),e.jsx("div",{className:"space-y-2",children:e.jsx("a",{href:H,target:"_blank",rel:"noreferrer",children:e.jsxs(j,{type:"button",variant:"outline",className:"rounded-xl",children:[e.jsx(Z,{className:"mr-2 h-4 w-4"}),a("searchProviderOpenDocs")]})})})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:a("apiKey")}),e.jsx(h,{type:"password",value:F,onChange:s=>V(s.target.value),placeholder:r.providers.brave.apiKeyMasked||a("enterApiKey"),className:"rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:a("searchProviderBaseUrl")}),e.jsx(h,{value:I,onChange:s=>_(s.target.value),className:"rounded-xl"})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(j,{type:"submit",disabled:x.isPending,children:[e.jsx($,{className:"mr-2 h-4 w-4"}),x.isPending?a("saving"):a("saveChanges")]})})]})})]})]})}export{ue as SearchConfig};
@@ -1,3 +1,3 @@
1
- import{r as u,j as e,ap as H,aj as L,aV as G,e as J}from"./vendor-CwsIoNvJ.js";import{u as K,ae as Q,t as a,C as R,a3 as T,a4 as M,a5 as O,z as A,S as x,e as m,f as p,g as j,h as o,I as h,B as _}from"./index-BWvap_iq.js";import{L as V}from"./label-Bklr3fXc.js";import{S as W}from"./switch-DSdHSIsC.js";import{P as X,a as Y}from"./page-layout-sNhcbwtm.js";const U=["env","file","exec"];function P(n=""){return{alias:n,source:"env",prefix:"",path:"",command:"",argsText:"",cwd:"",timeoutMs:5e3}}function Z(){return{path:"",source:"env",provider:"",id:""}}function ee(n,l){return l.source==="env"?{...P(n),source:"env",prefix:l.prefix??""}:l.source==="file"?{...P(n),source:"file",path:l.path}:{...P(n),source:"exec",command:l.command,argsText:(l.args??[]).join(`
1
+ import{r as u,j as e,ap as H,aj as L,aV as G,e as J}from"./vendor-CwsIoNvJ.js";import{u as K,ae as Q,t as a,C as R,a3 as T,a4 as M,a5 as O,z as A,S as x,e as m,f as p,g as j,h as o,I as h,B as _}from"./index-CeRbsQ90.js";import{L as V}from"./label-CCSffS1D.js";import{S as W}from"./switch-B-_SrMSL.js";import{P as X,a as Y}from"./page-layout-ud8wZ8gX.js";const U=["env","file","exec"];function P(n=""){return{alias:n,source:"env",prefix:"",path:"",command:"",argsText:"",cwd:"",timeoutMs:5e3}}function Z(){return{path:"",source:"env",provider:"",id:""}}function ee(n,l){return l.source==="env"?{...P(n),source:"env",prefix:l.prefix??""}:l.source==="file"?{...P(n),source:"file",path:l.path}:{...P(n),source:"exec",command:l.command,argsText:(l.args??[]).join(`
2
2
  `),cwd:l.cwd??"",timeoutMs:l.timeoutMs??5e3}}function se(n){return n.source==="env"?{source:"env",...n.prefix.trim()?{prefix:n.prefix.trim()}:{}}:n.source==="file"?{source:"file",path:n.path.trim(),format:"json"}:{source:"exec",command:n.command.trim(),args:n.argsText.split(`
3
3
  `).map(l=>l.trim()).filter(Boolean),...n.cwd.trim()?{cwd:n.cwd.trim()}:{},timeoutMs:Math.max(1,Math.trunc(n.timeoutMs||5e3))}}function ie(){const{data:n,isLoading:l}=K(),b=Q(),[k,y]=u.useState(!0),[D,E]=u.useState(""),[I,S]=u.useState(""),[F,$]=u.useState(""),[C,f]=u.useState([]),[q,v]=u.useState([]);u.useEffect(()=>{const s=n==null?void 0:n.secrets;if(!s){y(!0),E(""),S(""),$(""),f([]),v([]);return}y(!!s.enabled),E(s.defaults.env??""),S(s.defaults.file??""),$(s.defaults.exec??"");const t=Object.entries(s.providers).map(([c,i])=>ee(c,i)),r=Object.entries(s.refs).map(([c,i])=>({path:c,source:i.source,provider:i.provider??"",id:i.id}));f(t),v(r)},[n==null?void 0:n.secrets]);const w=u.useMemo(()=>{const s=C.map(t=>t.alias.trim()).filter(Boolean);return Array.from(new Set(s))},[C]),d=(s,t)=>{f(r=>r.map((c,i)=>i===s?{...c,...t}:c))},N=(s,t)=>{v(r=>r.map((c,i)=>i===s?{...c,...t}:c))},z=()=>{try{const s={};for(const[r,c]of C.entries()){const i=c.alias.trim();if(!i)throw new Error(`${a("providerAlias")} #${r+1} ${a("isRequired")}`);if(s[i])throw new Error(`${a("providerAlias")}: ${i} (${a("duplicate")})`);if(c.source==="file"&&!c.path.trim())throw new Error(`${a("secretFilePath")} #${r+1} ${a("isRequired")}`);if(c.source==="exec"&&!c.command.trim())throw new Error(`${a("secretExecCommand")} #${r+1} ${a("isRequired")}`);s[i]=se(c)}const t={};for(const[r,c]of q.entries()){const i=c.path.trim(),B=c.id.trim();if(!i)throw new Error(`${a("secretConfigPath")} #${r+1} ${a("isRequired")}`);if(!B)throw new Error(`${a("secretId")} #${r+1} ${a("isRequired")}`);const g=c.provider.trim();if(g&&!s[g])throw new Error(`${a("secretProviderAlias")}: ${g} ${a("notFound")}`);t[i]={source:c.source,...g?{provider:g}:{},id:B}}b.mutate({data:{enabled:k,defaults:{env:D.trim()||null,file:I.trim()||null,exec:F.trim()||null},providers:s,refs:t}})}catch(s){const t=s instanceof Error?s.message:String(s);J.error(t)}};return l?e.jsx("div",{className:"p-8 text-gray-400",children:a("loading")}):e.jsxs(X,{className:"space-y-6",children:[e.jsx(Y,{title:a("secretsPageTitle"),description:a("secretsPageDescription")}),e.jsxs(R,{children:[e.jsxs(T,{children:[e.jsx(M,{children:a("secrets")}),e.jsx(O,{children:a("secretsEnabledHelp")})]}),e.jsxs(A,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-xl border border-gray-200 p-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-800",children:a("enabled")}),e.jsx("p",{className:"text-xs text-gray-500",children:a("secretsEnabledHelp")})]}),e.jsx(W,{checked:k,onCheckedChange:y})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{children:a("defaultEnvProvider")}),e.jsxs(x,{value:D||"__none__",onValueChange:s=>E(s==="__none__"?"":s),children:[e.jsx(m,{children:e.jsx(p,{placeholder:a("noneOption")})}),e.jsxs(j,{children:[e.jsx(o,{value:"__none__",children:a("noneOption")}),w.map(s=>e.jsx(o,{value:s,children:s},s))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{children:a("defaultFileProvider")}),e.jsxs(x,{value:I||"__none__",onValueChange:s=>S(s==="__none__"?"":s),children:[e.jsx(m,{children:e.jsx(p,{placeholder:a("noneOption")})}),e.jsxs(j,{children:[e.jsx(o,{value:"__none__",children:a("noneOption")}),w.map(s=>e.jsx(o,{value:s,children:s},s))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{children:a("defaultExecProvider")}),e.jsxs(x,{value:F||"__none__",onValueChange:s=>$(s==="__none__"?"":s),children:[e.jsx(m,{children:e.jsx(p,{placeholder:a("noneOption")})}),e.jsxs(j,{children:[e.jsx(o,{value:"__none__",children:a("noneOption")}),w.map(s=>e.jsx(o,{value:s,children:s},s))]})]})]})]})]})]}),e.jsxs(R,{children:[e.jsxs(T,{children:[e.jsx(M,{children:a("secretProvidersTitle")}),e.jsx(O,{children:a("secretProvidersDescription")})]}),e.jsxs(A,{className:"space-y-3",children:[C.map((s,t)=>e.jsxs("div",{className:"rounded-xl border border-gray-200 p-3 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[e.jsx(h,{value:s.alias,onChange:r=>d(t,{alias:r.target.value}),placeholder:a("providerAlias")}),e.jsxs(x,{value:s.source,onValueChange:r=>d(t,{source:r}),children:[e.jsx(m,{children:e.jsx(p,{})}),e.jsx(j,{children:U.map(r=>e.jsx(o,{value:r,children:r},r))})]}),e.jsxs(_,{type:"button",variant:"outline",onClick:()=>f(r=>r.filter((c,i)=>i!==t)),children:[e.jsx(H,{className:"h-4 w-4 mr-2"}),a("removeProvider")]})]}),s.source==="env"&&e.jsx(h,{value:s.prefix,onChange:r=>d(t,{prefix:r.target.value}),placeholder:a("envPrefix")}),s.source==="file"&&e.jsx(h,{value:s.path,onChange:r=>d(t,{path:r.target.value}),placeholder:a("secretFilePath")}),s.source==="exec"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{value:s.command,onChange:r=>d(t,{command:r.target.value}),placeholder:a("secretExecCommand")}),e.jsx("textarea",{className:"min-h-[84px] w-full rounded-lg border border-gray-200 bg-white px-3 py-2 text-xs font-mono",value:s.argsText,onChange:r=>d(t,{argsText:r.target.value}),placeholder:a("secretExecArgs")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2",children:[e.jsx(h,{value:s.cwd,onChange:r=>d(t,{cwd:r.target.value}),placeholder:a("secretExecCwd")}),e.jsx(h,{type:"number",min:1,value:s.timeoutMs,onChange:r=>d(t,{timeoutMs:Number.parseInt(r.target.value,10)||5e3}),placeholder:a("secretExecTimeoutMs")})]})]})]},`provider-${t}`)),e.jsxs(_,{type:"button",variant:"outline",onClick:()=>f(s=>[...s,P()]),children:[e.jsx(L,{className:"h-4 w-4 mr-2"}),a("addSecretProvider")]})]})]}),e.jsxs(R,{children:[e.jsxs(T,{children:[e.jsx(M,{children:a("secretRefsTitle")}),e.jsx(O,{children:a("secretRefsDescription")})]}),e.jsxs(A,{className:"space-y-3",children:[q.map((s,t)=>e.jsx("div",{className:"rounded-xl border border-gray-200 p-3 space-y-3",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsx(h,{value:s.path,onChange:r=>N(t,{path:r.target.value}),placeholder:a("secretConfigPath")}),e.jsx(h,{value:s.id,onChange:r=>N(t,{id:r.target.value}),placeholder:a("secretId")}),e.jsxs(x,{value:s.source,onValueChange:r=>N(t,{source:r}),children:[e.jsx(m,{children:e.jsx(p,{})}),e.jsx(j,{children:U.map(r=>e.jsx(o,{value:r,children:r},r))})]}),e.jsxs("div",{className:"grid grid-cols-[1fr_auto] gap-2",children:[e.jsxs(x,{value:s.provider||"__none__",onValueChange:r=>N(t,{provider:r==="__none__"?"":r}),children:[e.jsx(m,{children:e.jsx(p,{placeholder:a("secretProviderAlias")})}),e.jsxs(j,{children:[e.jsx(o,{value:"__none__",children:a("noneOption")}),w.map(r=>e.jsx(o,{value:r,children:r},r))]})]}),e.jsx(_,{type:"button",variant:"outline",onClick:()=>v(r=>r.filter((c,i)=>i!==t)),children:e.jsx(H,{className:"h-4 w-4"})})]})]})},`ref-${t}`)),e.jsxs(_,{type:"button",variant:"outline",onClick:()=>v(s=>[...s,Z()]),children:[e.jsx(L,{className:"h-4 w-4 mr-2"}),a("addSecretRef")]})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(_,{type:"button",onClick:z,disabled:b.isPending,children:[e.jsx(G,{className:"h-4 w-4 mr-2"}),b.isPending?a("saving"):a("save")]})})]})}export{ie as SecretsConfig};