@nextclaw/ui 0.12.35-beta.7 → 0.12.35

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 (27) hide show
  1. package/CHANGELOG.md +419 -0
  2. package/dist/assets/{channels-list-page-D-tv11dc.js → channels-list-page-DXH1qYLs.js} +1 -1
  3. package/dist/assets/{chat-page-MyXEZI8R.js → chat-page-Cpo0AFHb.js} +1 -1
  4. package/dist/assets/{desktop-update-config-oZpIKKtS.js → desktop-update-config-Be8x1jNy.js} +1 -1
  5. package/dist/assets/doc-browser-BI7HSaMK.js +3 -0
  6. package/dist/assets/doc-browser-yTfN7UBH.js +1 -0
  7. package/dist/assets/{index-D2H2CKYR.js → index-GVTiCf1s.js} +4 -4
  8. package/dist/assets/{mcp-marketplace-page-CegP14Hl.js → mcp-marketplace-page-DDjeHd1I.js} +1 -1
  9. package/dist/assets/mcp-marketplace-page-WUkc7n94.js +1 -0
  10. package/dist/assets/{model-config-fIE_Asps.js → model-config-BjXMpU9U.js} +1 -1
  11. package/dist/assets/{provider-scoped-model-input-D4zRsGZ6.js → provider-scoped-model-input-t1tCP5y5.js} +1 -1
  12. package/dist/assets/{providers-list-CqsOk2hr.js → providers-list-C1D5p9kK.js} +1 -1
  13. package/dist/assets/remote-BHeENKxL.js +1 -0
  14. package/dist/assets/{runtime-config-page-BJ86cC8a.js → runtime-config-page--O0Wq01S.js} +1 -1
  15. package/dist/assets/{search-config-TbCPlRE7.js → search-config-Dzpizo-_.js} +1 -1
  16. package/dist/assets/{secrets-config-DBIEKP_V.js → secrets-config-D1AUSEXX.js} +1 -1
  17. package/dist/index.html +2 -2
  18. package/package.json +8 -8
  19. package/src/features/panel-apps/managers/panel-app-bridge.manager.test.ts +68 -0
  20. package/src/features/panel-apps/managers/panel-app-bridge.manager.ts +3 -3
  21. package/src/shared/components/doc-browser/doc-browser-panel-parts.tsx +3 -7
  22. package/src/shared/components/doc-browser/doc-browser-renderer.types.ts +1 -0
  23. package/src/shared/components/doc-browser/doc-browser.tsx +4 -4
  24. package/dist/assets/doc-browser-B2OFjScU.js +0 -3
  25. package/dist/assets/doc-browser-BrUQEZ1j.js +0 -1
  26. package/dist/assets/mcp-marketplace-page-MjpFEEkY.js +0 -1
  27. package/dist/assets/remote-BMWQUPDW.js +0 -1
@@ -1,4 +1,4 @@
1
- import{d as e,h as t,i as n,m as r,v as i}from"./react-B2X_ph0a.js";import{$t as a,At as o,Bt as s,C as c,Lt as l,Mt as u,Nt as d,Qt as f,Rt as p,S as m,T as h,Xt as g,Zt as _,b as ee,en as v,ft as y,w as b,x as te,zt as x}from"./api-DruAcori.js";import{a as S,c as C,i as w,n as T,o as E,r as D,s as O}from"./confirm-dialog-B0TP-vPd.js";import{t as k}from"./createLucideIcon-Br1EFMEr.js";import{n as ne}from"./doc-browser-context-DB6TTHeE.js";import{J as A,Jt as re,K as j,St as ie,X as M,Y as N,h as ae,q as P,u as F}from"./index-D2H2CKYR.js";import{t as I}from"./tag-chip-ix15P-r4.js";var oe=class extends v{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){super.setOptions({...e,behavior:a()})}getOptimisticResult(e){return e.behavior=a(),super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`forward`}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`backward`}}})}createResult(e,t){let{state:n}=e,r=super.createResult(e,t),{isFetching:i,isRefetching:a,isError:o,isRefetchError:s}=r,c=n.fetchMeta?.fetchMore?.direction,l=o&&c===`forward`,u=i&&c===`forward`,d=o&&c===`backward`,p=i&&c===`backward`;return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:_(t,n.data),hasPreviousPage:f(t,n.data),isFetchNextPageError:l,isFetchingNextPage:u,isFetchPreviousPageError:d,isFetchingPreviousPage:p,isRefetchError:s&&!l&&!d,isRefetching:a&&!u&&!p}}};function L(e,t){return s(e,oe,t)}var se=k(`PackageCheck`,[[`path`,{d:`m16 16 2 2 4-4`,key:`gfu2re`}],[`path`,{d:`M21 10V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l2-1.14`,key:`e7tb2h`}],[`path`,{d:`m7.5 4.27 9 5.15`,key:`1c824w`}],[`polyline`,{points:`3.29 7 12 12 20.71 7`,key:`ousv84`}],[`line`,{x1:`12`,x2:`12`,y1:`22`,y2:`12`,key:`a4e8g8`}]]),ce=k(`PackageSearch`,[[`path`,{d:`M21 10V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l2-1.14`,key:`e7tb2h`}],[`path`,{d:`m7.5 4.27 9 5.15`,key:`1c824w`}],[`polyline`,{points:`3.29 7 12 12 20.71 7`,key:`ousv84`}],[`line`,{x1:`12`,x2:`12`,y1:`22`,y2:`12`,key:`a4e8g8`}],[`circle`,{cx:`18.5`,cy:`15.5`,r:`2.5`,key:`b5zd12`}],[`path`,{d:`M20.27 17.27 22 19`,key:`1l4muz`}]]);function R(e){if(!e||e.pages.length===0)return;let t=e.pages.flatMap(e=>e.items);return{...e.pages[e.pages.length-1],items:t,pages:e.pages,loadedItems:t.length,loadedPages:e.pages.length}}var z=r();function B({scope:e,searchText:t,searchPlaceholder:r,sort:i,onSearchTextChange:a,onSortChange:o}){return(0,z.jsx)(`div`,{className:`mb-4`,children:(0,z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,z.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,z.jsx)(ce,{className:`absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,z.jsx)(`input`,{value:t,onChange:e=>a(e.target.value),placeholder:r,className:`h-9 w-full rounded-xl border border-gray-200/80 pl-9 pr-3 text-sm focus:outline-none focus:ring-1 focus:ring-primary/40`})]}),e===`all`&&(0,z.jsxs)(j,{value:i,onValueChange:e=>o(e),children:[(0,z.jsx)(N,{className:`h-9 w-[150px] shrink-0 rounded-lg`,children:(0,z.jsx)(M,{})}),(0,z.jsxs)(P,{children:[(0,z.jsx)(A,{value:`relevance`,children:n(`marketplaceSortRelevance`)}),(0,z.jsx)(A,{value:`updated`,children:n(`marketplaceSortUpdated`)})]})]})]})})}function V({count:e}){return(0,z.jsx)(z.Fragment,{children:Array.from({length:e},(e,t)=>(0,z.jsx)(`article`,{className:`h-full rounded-2xl border border-gray-200/40 bg-white px-5 py-4 shadow-sm`,children:(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3.5`,children:[(0,z.jsxs)(`div`,{className:`flex min-w-0 flex-1 gap-3`,children:[(0,z.jsx)(F,{className:`h-10 w-10 shrink-0 rounded-xl`}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-2 pt-0.5`,children:[(0,z.jsx)(F,{className:`h-4 w-32 max-w-[70%]`}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(F,{className:`h-3 w-12`}),(0,z.jsx)(F,{className:`h-3 w-24`})]}),(0,z.jsx)(F,{className:`h-3 w-full`})]})]}),(0,z.jsx)(F,{className:`h-8 w-20 shrink-0 rounded-xl`})]})},`marketplace-skeleton-${t}`))})}function H({hasMore:e,loading:t,sentinelRef:r}){return!e&&!t?null:(0,z.jsxs)(`div`,{className:`py-4`,children:[e&&(0,z.jsx)(`div`,{ref:r,className:`h-1 w-full`,"aria-hidden":`true`}),t&&(0,z.jsx)(`div`,{"data-testid":`marketplace-loading-more`,className:`pt-3 text-center text-xs text-gray-500`,children:n(`loading`)})]})}function U(e){let t=e.trim().toLowerCase().replace(/_/g,`-`),n=[t,t.split(`-`)[0],`en`];return Array.from(new Set(n.filter(Boolean)))}function W(e){return e.trim().toLowerCase().replace(/_/g,`-`)}function G(e,t,n){if(e){let t=Object.entries(e).map(([e,t])=>({locale:W(e),text:typeof t==`string`?t.trim():``})).filter(e=>e.text.length>0);if(t.length>0){let e=new Map(t.map(e=>[e.locale,e.text]));for(let t of n){let n=W(t),r=e.get(n);if(r)return r}for(let e of n){let n=W(e).split(`-`)[0];if(!n)continue;let r=t.find(e=>e.locale===n||e.locale.startsWith(`${n}-`));if(r)return r.text}return t[0]?.text??``}}return t?.trim()??``}function le(e,t){if(!e)return``;for(let n of t)if(W(n).split(`-`)[0]===`zh`&&e.descriptionZh?.trim())return e.descriptionZh.trim();return e.description?.trim()?e.description.trim():e.descriptionZh?.trim()?e.descriptionZh.trim():``}var K=i(t(),1),ue=160;function q(e){let t=(0,K.useRef)(null),n=(0,K.useRef)(null),r=(0,K.useRef)(e.onLoadMore),i=(0,K.useRef)(!1);return(0,K.useEffect)(()=>{r.current=e.onLoadMore},[e.onLoadMore]),(0,K.useEffect)(()=>{e.disabled&&(i.current=!1)},[e.disabled]),(0,K.useEffect)(()=>{let a=t.current,o=n.current,s=e.thresholdPx??ue;if(e.disabled||!a||!o)return;let c=()=>{i.current||e.disabled||(i.current=!0,Promise.resolve(r.current()).finally(()=>{i.current=!1}))},l=()=>{o.getBoundingClientRect().top-a.getBoundingClientRect().bottom<=s&&c()};if(typeof IntersectionObserver==`function`){let e=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&c()},{root:a,rootMargin:`0px 0px ${s}px 0px`});return e.observe(o),l(),()=>{e.disconnect()}}return a.addEventListener(`scroll`,l,{passive:!0}),l(),()=>{a.removeEventListener(`scroll`,l)}},[e.disabled,e.thresholdPx,e.watchValue]),{containerRef:t,sentinelRef:n}}function J(e){return(e??``).trim().toLowerCase()}function de(e){let t=new Map;for(let n of e){let e=[n.catalogSlug,n.spec,n.id,n.label];for(let r of e){let e=J(r);!e||t.has(e)||t.set(e,n)}}return t}function fe(e,t){let n=[e.slug,e.install.spec,e.id,e.name];for(let e of n){let n=J(e);if(!n)continue;let r=t.get(n);if(r)return r}}function Y(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`)}function X(e,t,n,r,i){let a=`<!doctype html>
1
+ import{d as e,h as t,i as n,m as r,v as i}from"./react-B2X_ph0a.js";import{$t as a,At as o,Bt as s,C as c,Lt as l,Mt as u,Nt as d,Qt as f,Rt as p,S as m,T as h,Xt as g,Zt as _,b as ee,en as v,ft as y,w as b,x as te,zt as x}from"./api-DruAcori.js";import{a as S,c as C,i as w,n as T,o as E,r as D,s as O}from"./confirm-dialog-B0TP-vPd.js";import{t as k}from"./createLucideIcon-Br1EFMEr.js";import{n as ne}from"./doc-browser-context-DB6TTHeE.js";import{J as A,Jt as re,K as j,St as ie,X as M,Y as N,h as ae,q as P,u as F}from"./index-GVTiCf1s.js";import{t as I}from"./tag-chip-ix15P-r4.js";var oe=class extends v{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){super.setOptions({...e,behavior:a()})}getOptimisticResult(e){return e.behavior=a(),super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`forward`}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`backward`}}})}createResult(e,t){let{state:n}=e,r=super.createResult(e,t),{isFetching:i,isRefetching:a,isError:o,isRefetchError:s}=r,c=n.fetchMeta?.fetchMore?.direction,l=o&&c===`forward`,u=i&&c===`forward`,d=o&&c===`backward`,p=i&&c===`backward`;return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:_(t,n.data),hasPreviousPage:f(t,n.data),isFetchNextPageError:l,isFetchingNextPage:u,isFetchPreviousPageError:d,isFetchingPreviousPage:p,isRefetchError:s&&!l&&!d,isRefetching:a&&!u&&!p}}};function L(e,t){return s(e,oe,t)}var se=k(`PackageCheck`,[[`path`,{d:`m16 16 2 2 4-4`,key:`gfu2re`}],[`path`,{d:`M21 10V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l2-1.14`,key:`e7tb2h`}],[`path`,{d:`m7.5 4.27 9 5.15`,key:`1c824w`}],[`polyline`,{points:`3.29 7 12 12 20.71 7`,key:`ousv84`}],[`line`,{x1:`12`,x2:`12`,y1:`22`,y2:`12`,key:`a4e8g8`}]]),ce=k(`PackageSearch`,[[`path`,{d:`M21 10V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l2-1.14`,key:`e7tb2h`}],[`path`,{d:`m7.5 4.27 9 5.15`,key:`1c824w`}],[`polyline`,{points:`3.29 7 12 12 20.71 7`,key:`ousv84`}],[`line`,{x1:`12`,x2:`12`,y1:`22`,y2:`12`,key:`a4e8g8`}],[`circle`,{cx:`18.5`,cy:`15.5`,r:`2.5`,key:`b5zd12`}],[`path`,{d:`M20.27 17.27 22 19`,key:`1l4muz`}]]);function R(e){if(!e||e.pages.length===0)return;let t=e.pages.flatMap(e=>e.items);return{...e.pages[e.pages.length-1],items:t,pages:e.pages,loadedItems:t.length,loadedPages:e.pages.length}}var z=r();function B({scope:e,searchText:t,searchPlaceholder:r,sort:i,onSearchTextChange:a,onSortChange:o}){return(0,z.jsx)(`div`,{className:`mb-4`,children:(0,z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,z.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,z.jsx)(ce,{className:`absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,z.jsx)(`input`,{value:t,onChange:e=>a(e.target.value),placeholder:r,className:`h-9 w-full rounded-xl border border-gray-200/80 pl-9 pr-3 text-sm focus:outline-none focus:ring-1 focus:ring-primary/40`})]}),e===`all`&&(0,z.jsxs)(j,{value:i,onValueChange:e=>o(e),children:[(0,z.jsx)(N,{className:`h-9 w-[150px] shrink-0 rounded-lg`,children:(0,z.jsx)(M,{})}),(0,z.jsxs)(P,{children:[(0,z.jsx)(A,{value:`relevance`,children:n(`marketplaceSortRelevance`)}),(0,z.jsx)(A,{value:`updated`,children:n(`marketplaceSortUpdated`)})]})]})]})})}function V({count:e}){return(0,z.jsx)(z.Fragment,{children:Array.from({length:e},(e,t)=>(0,z.jsx)(`article`,{className:`h-full rounded-2xl border border-gray-200/40 bg-white px-5 py-4 shadow-sm`,children:(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-3.5`,children:[(0,z.jsxs)(`div`,{className:`flex min-w-0 flex-1 gap-3`,children:[(0,z.jsx)(F,{className:`h-10 w-10 shrink-0 rounded-xl`}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-2 pt-0.5`,children:[(0,z.jsx)(F,{className:`h-4 w-32 max-w-[70%]`}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(F,{className:`h-3 w-12`}),(0,z.jsx)(F,{className:`h-3 w-24`})]}),(0,z.jsx)(F,{className:`h-3 w-full`})]})]}),(0,z.jsx)(F,{className:`h-8 w-20 shrink-0 rounded-xl`})]})},`marketplace-skeleton-${t}`))})}function H({hasMore:e,loading:t,sentinelRef:r}){return!e&&!t?null:(0,z.jsxs)(`div`,{className:`py-4`,children:[e&&(0,z.jsx)(`div`,{ref:r,className:`h-1 w-full`,"aria-hidden":`true`}),t&&(0,z.jsx)(`div`,{"data-testid":`marketplace-loading-more`,className:`pt-3 text-center text-xs text-gray-500`,children:n(`loading`)})]})}function U(e){let t=e.trim().toLowerCase().replace(/_/g,`-`),n=[t,t.split(`-`)[0],`en`];return Array.from(new Set(n.filter(Boolean)))}function W(e){return e.trim().toLowerCase().replace(/_/g,`-`)}function G(e,t,n){if(e){let t=Object.entries(e).map(([e,t])=>({locale:W(e),text:typeof t==`string`?t.trim():``})).filter(e=>e.text.length>0);if(t.length>0){let e=new Map(t.map(e=>[e.locale,e.text]));for(let t of n){let n=W(t),r=e.get(n);if(r)return r}for(let e of n){let n=W(e).split(`-`)[0];if(!n)continue;let r=t.find(e=>e.locale===n||e.locale.startsWith(`${n}-`));if(r)return r.text}return t[0]?.text??``}}return t?.trim()??``}function le(e,t){if(!e)return``;for(let n of t)if(W(n).split(`-`)[0]===`zh`&&e.descriptionZh?.trim())return e.descriptionZh.trim();return e.description?.trim()?e.description.trim():e.descriptionZh?.trim()?e.descriptionZh.trim():``}var K=i(t(),1),ue=160;function q(e){let t=(0,K.useRef)(null),n=(0,K.useRef)(null),r=(0,K.useRef)(e.onLoadMore),i=(0,K.useRef)(!1);return(0,K.useEffect)(()=>{r.current=e.onLoadMore},[e.onLoadMore]),(0,K.useEffect)(()=>{e.disabled&&(i.current=!1)},[e.disabled]),(0,K.useEffect)(()=>{let a=t.current,o=n.current,s=e.thresholdPx??ue;if(e.disabled||!a||!o)return;let c=()=>{i.current||e.disabled||(i.current=!0,Promise.resolve(r.current()).finally(()=>{i.current=!1}))},l=()=>{o.getBoundingClientRect().top-a.getBoundingClientRect().bottom<=s&&c()};if(typeof IntersectionObserver==`function`){let e=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&c()},{root:a,rootMargin:`0px 0px ${s}px 0px`});return e.observe(o),l(),()=>{e.disconnect()}}return a.addEventListener(`scroll`,l,{passive:!0}),l(),()=>{a.removeEventListener(`scroll`,l)}},[e.disabled,e.thresholdPx,e.watchValue]),{containerRef:t,sentinelRef:n}}function J(e){return(e??``).trim().toLowerCase()}function de(e){let t=new Map;for(let n of e){let e=[n.catalogSlug,n.spec,n.id,n.label];for(let r of e){let e=J(r);!e||t.has(e)||t.set(e,n)}}return t}function fe(e,t){let n=[e.slug,e.install.spec,e.id,e.name];for(let e of n){let n=J(e);if(!n)continue;let r=t.get(n);if(r)return r}}function Y(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`)}function X(e,t,n,r,i){let a=`<!doctype html>
2
2
  <html>
3
3
  <head>
4
4
  <meta charset="utf-8" />
@@ -0,0 +1 @@
1
+ import{t as e}from"./mcp-marketplace-page-DDjeHd1I.js";export{e as McpMarketplacePage};
@@ -1 +1 @@
1
- import{h as e,i as t,m as n,v as r}from"./react-B2X_ph0a.js";import{At as i,Mt as a,Nt as o,jt as s,kt as c,wt as l}from"./api-DruAcori.js";import{t as u}from"./book-open-cPX0Za7Z.js";import{n as d,t as f}from"./provider-scoped-model-input-D4zRsGZ6.js";import{a as p}from"./doc-browser-route-registry.utils-x5ijvk0u.js";import"./doc-browser-context-DB6TTHeE.js";import{$ as m,Jt as h,Q as g,Z as _,mt as v,nn as y,on as b,u as x}from"./index-D2H2CKYR.js";import{t as S}from"./config-hints-CY1lg9IE.js";var C=r(e(),1),w=n(),T=`provider/model`;function E(e){let{initialModel:n,initialWorkspace:r,isPending:i,modelHelpText:c,modelLabel:l,modelPlaceholder:d,onSubmit:m,providerCatalog:g,workspaceLabel:_,workspacePlaceholder:v}=e,[x,S]=(0,C.useState)(n),[T,E]=(0,C.useState)(r);return(0,w.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m({model:x,workspace:T})},className:`space-y-8`,children:[(0,w.jsxs)(`div`,{className:`grid grid-cols-1 gap-8 md:grid-cols-2`,children:[(0,w.jsxs)(`div`,{className:`rounded-2xl border border-gray-200 bg-white p-8 shadow-card`,children:[(0,w.jsxs)(`div`,{className:`mb-8 flex items-center gap-4`,children:[(0,w.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-primary text-white`,children:(0,w.jsx)(h,{className:`h-5 w-5`})}),(0,w.jsx)(`h3`,{className:`text-lg font-bold text-gray-900`,children:t(`defaultModel`)})]}),(0,w.jsxs)(`div`,{className:`space-y-2`,children:[(0,w.jsx)(s,{htmlFor:`model`,className:`text-xs font-semibold uppercase tracking-wider text-gray-500`,children:l}),(0,w.jsx)(f,{id:`model`,value:x,onChange:S,providerCatalog:g,modelPlaceholder:d}),(0,w.jsx)(`p`,{className:`text-xs text-gray-400`,children:c}),(0,w.jsxs)(`a`,{href:`${p}/guide/model-selection`,className:`inline-flex items-center gap-1.5 text-xs text-primary transition-colors hover:text-primary-hover`,children:[(0,w.jsx)(u,{className:`h-3.5 w-3.5`}),t(`channelsGuideTitle`)]})]})]}),(0,w.jsxs)(`div`,{className:`rounded-2xl border border-gray-200 bg-white p-8 shadow-card`,children:[(0,w.jsxs)(`div`,{className:`mb-8 flex items-center gap-4`,children:[(0,w.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-primary text-white`,children:(0,w.jsx)(b,{className:`h-5 w-5`})}),(0,w.jsx)(`h3`,{className:`text-lg font-bold text-gray-900`,children:t(`workspace`)})]}),(0,w.jsxs)(`div`,{className:`space-y-2`,children:[(0,w.jsx)(s,{htmlFor:`workspace`,className:`text-xs font-semibold uppercase tracking-wider text-gray-500`,children:_}),(0,w.jsx)(a,{id:`workspace`,value:T,onChange:e=>E(e.target.value),placeholder:v,className:`rounded-xl`})]})]})]}),(0,w.jsx)(`div`,{className:`flex justify-end pt-4`,children:(0,w.jsx)(o,{type:`submit`,disabled:i,size:`lg`,children:i?(0,w.jsx)(y,{className:`h-5 w-5 animate-spin`}):t(`saveChanges`)})})]})}function D(){let{data:e,isLoading:n}=_(),{data:r}=g(),{data:a}=m(),o=v(),s=a?.uiHints,u=S(`agents.defaults.model`,s),f=S(`agents.defaults.workspace`,s),p=(0,C.useMemo)(()=>d({meta:r,config:e,onlyConfigured:!0}),[e,r]),h=t(`modelIdentifierHelp`)||u?.help||``,y=(e?.agents?.defaults?.model||``).trim(),b=e?.agents?.defaults?.workspace||``;return n?(0,w.jsxs)(`div`,{className:`max-w-2xl space-y-6`,children:[(0,w.jsxs)(`div`,{className:`space-y-2`,children:[(0,w.jsx)(x,{className:`h-8 w-32`}),(0,w.jsx)(x,{className:`h-4 w-48`})]}),(0,w.jsxs)(l,{className:`rounded-2xl border-gray-200 p-6`,children:[(0,w.jsxs)(`div`,{className:`mb-6 flex items-center gap-4`,children:[(0,w.jsx)(x,{className:`h-12 w-12 rounded-xl`}),(0,w.jsxs)(`div`,{className:`space-y-2`,children:[(0,w.jsx)(x,{className:`h-5 w-24`}),(0,w.jsx)(x,{className:`h-3 w-32`})]})]}),(0,w.jsx)(x,{className:`mb-2 h-4 w-20`}),(0,w.jsx)(x,{className:`h-10 w-full rounded-xl`})]}),(0,w.jsxs)(l,{className:`rounded-2xl border-gray-200 p-6`,children:[(0,w.jsx)(x,{className:`mb-2 h-5 w-24`}),(0,w.jsx)(x,{className:`h-10 w-full rounded-xl`})]})]}):(0,w.jsxs)(i,{children:[(0,w.jsx)(c,{title:t(`modelPageTitle`),description:t(`modelPageDescription`)}),(0,w.jsx)(E,{initialModel:y,initialWorkspace:b,isPending:o.isPending,modelHelpText:h,modelLabel:u?.label??`Model Name`,modelPlaceholder:u?.placeholder??T,onSubmit:({model:e,workspace:t})=>o.mutate({model:e,workspace:t}),providerCatalog:p,workspaceLabel:f?.label??`Default Path`,workspacePlaceholder:f?.placeholder??`/path/to/workspace`},`${y}::${b}`)]})}export{D as ModelConfig};
1
+ import{h as e,i as t,m as n,v as r}from"./react-B2X_ph0a.js";import{At as i,Mt as a,Nt as o,jt as s,kt as c,wt as l}from"./api-DruAcori.js";import{t as u}from"./book-open-cPX0Za7Z.js";import{n as d,t as f}from"./provider-scoped-model-input-t1tCP5y5.js";import{a as p}from"./doc-browser-route-registry.utils-x5ijvk0u.js";import"./doc-browser-context-DB6TTHeE.js";import{$ as m,Jt as h,Q as g,Z as _,mt as v,nn as y,on as b,u as x}from"./index-GVTiCf1s.js";import{t as S}from"./config-hints-CY1lg9IE.js";var C=r(e(),1),w=n(),T=`provider/model`;function E(e){let{initialModel:n,initialWorkspace:r,isPending:i,modelHelpText:c,modelLabel:l,modelPlaceholder:d,onSubmit:m,providerCatalog:g,workspaceLabel:_,workspacePlaceholder:v}=e,[x,S]=(0,C.useState)(n),[T,E]=(0,C.useState)(r);return(0,w.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m({model:x,workspace:T})},className:`space-y-8`,children:[(0,w.jsxs)(`div`,{className:`grid grid-cols-1 gap-8 md:grid-cols-2`,children:[(0,w.jsxs)(`div`,{className:`rounded-2xl border border-gray-200 bg-white p-8 shadow-card`,children:[(0,w.jsxs)(`div`,{className:`mb-8 flex items-center gap-4`,children:[(0,w.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-primary text-white`,children:(0,w.jsx)(h,{className:`h-5 w-5`})}),(0,w.jsx)(`h3`,{className:`text-lg font-bold text-gray-900`,children:t(`defaultModel`)})]}),(0,w.jsxs)(`div`,{className:`space-y-2`,children:[(0,w.jsx)(s,{htmlFor:`model`,className:`text-xs font-semibold uppercase tracking-wider text-gray-500`,children:l}),(0,w.jsx)(f,{id:`model`,value:x,onChange:S,providerCatalog:g,modelPlaceholder:d}),(0,w.jsx)(`p`,{className:`text-xs text-gray-400`,children:c}),(0,w.jsxs)(`a`,{href:`${p}/guide/model-selection`,className:`inline-flex items-center gap-1.5 text-xs text-primary transition-colors hover:text-primary-hover`,children:[(0,w.jsx)(u,{className:`h-3.5 w-3.5`}),t(`channelsGuideTitle`)]})]})]}),(0,w.jsxs)(`div`,{className:`rounded-2xl border border-gray-200 bg-white p-8 shadow-card`,children:[(0,w.jsxs)(`div`,{className:`mb-8 flex items-center gap-4`,children:[(0,w.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-primary text-white`,children:(0,w.jsx)(b,{className:`h-5 w-5`})}),(0,w.jsx)(`h3`,{className:`text-lg font-bold text-gray-900`,children:t(`workspace`)})]}),(0,w.jsxs)(`div`,{className:`space-y-2`,children:[(0,w.jsx)(s,{htmlFor:`workspace`,className:`text-xs font-semibold uppercase tracking-wider text-gray-500`,children:_}),(0,w.jsx)(a,{id:`workspace`,value:T,onChange:e=>E(e.target.value),placeholder:v,className:`rounded-xl`})]})]})]}),(0,w.jsx)(`div`,{className:`flex justify-end pt-4`,children:(0,w.jsx)(o,{type:`submit`,disabled:i,size:`lg`,children:i?(0,w.jsx)(y,{className:`h-5 w-5 animate-spin`}):t(`saveChanges`)})})]})}function D(){let{data:e,isLoading:n}=_(),{data:r}=g(),{data:a}=m(),o=v(),s=a?.uiHints,u=S(`agents.defaults.model`,s),f=S(`agents.defaults.workspace`,s),p=(0,C.useMemo)(()=>d({meta:r,config:e,onlyConfigured:!0}),[e,r]),h=t(`modelIdentifierHelp`)||u?.help||``,y=(e?.agents?.defaults?.model||``).trim(),b=e?.agents?.defaults?.workspace||``;return n?(0,w.jsxs)(`div`,{className:`max-w-2xl space-y-6`,children:[(0,w.jsxs)(`div`,{className:`space-y-2`,children:[(0,w.jsx)(x,{className:`h-8 w-32`}),(0,w.jsx)(x,{className:`h-4 w-48`})]}),(0,w.jsxs)(l,{className:`rounded-2xl border-gray-200 p-6`,children:[(0,w.jsxs)(`div`,{className:`mb-6 flex items-center gap-4`,children:[(0,w.jsx)(x,{className:`h-12 w-12 rounded-xl`}),(0,w.jsxs)(`div`,{className:`space-y-2`,children:[(0,w.jsx)(x,{className:`h-5 w-24`}),(0,w.jsx)(x,{className:`h-3 w-32`})]})]}),(0,w.jsx)(x,{className:`mb-2 h-4 w-20`}),(0,w.jsx)(x,{className:`h-10 w-full rounded-xl`})]}),(0,w.jsxs)(l,{className:`rounded-2xl border-gray-200 p-6`,children:[(0,w.jsx)(x,{className:`mb-2 h-5 w-24`}),(0,w.jsx)(x,{className:`h-10 w-full rounded-xl`})]})]}):(0,w.jsxs)(i,{children:[(0,w.jsx)(c,{title:t(`modelPageTitle`),description:t(`modelPageDescription`)}),(0,w.jsx)(E,{initialModel:y,initialWorkspace:b,isPending:o.isPending,modelHelpText:h,modelLabel:u?.label??`Model Name`,modelPlaceholder:u?.placeholder??T,onSubmit:({model:e,workspace:t})=>o.mutate({model:e,workspace:t}),providerCatalog:p,workspaceLabel:f?.label??`Default Path`,workspacePlaceholder:f?.placeholder??`/path/to/workspace`},`${y}::${b}`)]})}export{D as ModelConfig};
@@ -1 +1 @@
1
- import{d as e,h as t,i as n,m as r,v as i}from"./react-B2X_ph0a.js";import{Mt as a}from"./api-DruAcori.js";import{t as o}from"./createLucideIcon-Br1EFMEr.js";import{J as s,K as c,X as l,Y as u,q as d,un as f}from"./index-D2H2CKYR.js";var p=o(`ChevronsUpDown`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),m=i(t(),1),h=r();function g(e){let t=new Set;for(let n of e){let e=n.trim();e.length>0&&t.add(e)}return[...t]}function _({id:t,value:n,onChange:r,options:i,disabled:o=!1,placeholder:s,className:c,inputClassName:l,emptyText:u,createText:d,maxItems:_=1/0,onEnter:v}){let[y,b]=(0,m.useState)(!1);(0,m.useEffect)(()=>{o&&y&&b(!1)},[o,y]);let x=(0,m.useMemo)(()=>g(i),[i]),S=n.trim().toLowerCase(),C=(0,m.useMemo)(()=>{let e=x.map((e,t)=>({option:e,index:t}));S.length>0&&e.sort((e,t)=>{let n=e.option.toLowerCase(),r=t.option.toLowerCase(),i=n===S?0:n.startsWith(S)?1:n.includes(S)?2:3,a=r===S?0:r.startsWith(S)?1:r.includes(S)?2:3;return i===a?e.index-t.index:i-a});let t=e.map(e=>e.option);return Number.isFinite(_)?t.slice(0,Math.max(1,_)):t},[x,S,_]),w=n.trim().length>0&&x.some(e=>e===n.trim());return(0,h.jsxs)(`div`,{className:e(`relative`,c),onBlur:()=>{setTimeout(()=>b(!1),120)},children:[(0,h.jsx)(a,{id:t,value:n,disabled:o,onFocus:()=>{o||b(!0)},onChange:e=>{r(e.target.value),!y&&!o&&b(!0)},onKeyDown:e=>{e.key===`Enter`&&(v&&(e.preventDefault(),v()),b(!1))},placeholder:s,className:e(`pr-10`,l)}),(0,h.jsx)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>b(e=>!e),disabled:o,className:e(`absolute inset-y-0 right-0 inline-flex w-10 items-center justify-center`,o?`cursor-not-allowed text-gray-300`:`text-gray-400 hover:text-gray-600`),"aria-label":`toggle model options`,children:(0,h.jsx)(p,{className:`h-4 w-4`})}),y&&!o&&(0,h.jsx)(`div`,{className:`absolute z-20 mt-1 w-full overflow-hidden rounded-xl border border-gray-200 bg-white shadow-lg`,children:(0,h.jsxs)(`div`,{className:`max-h-60 overflow-y-auto py-1`,children:[!w&&n.trim().length>0&&(0,h.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{r(n.trim()),b(!1)},className:`flex w-full items-center gap-2 px-3 py-2 text-left text-sm hover:bg-gray-50`,children:[(0,h.jsx)(f,{className:`h-4 w-4 text-transparent`}),(0,h.jsx)(`span`,{className:`truncate text-gray-700`,children:d?d.replace(`{value}`,n.trim()):n.trim()})]}),C.map(t=>(0,h.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{r(t),b(!1)},className:`flex w-full items-center gap-2 px-3 py-2 text-left text-sm hover:bg-gray-50`,children:[(0,h.jsx)(f,{className:e(`h-4 w-4`,t===n.trim()?`text-primary`:`text-transparent`)}),(0,h.jsx)(`span`,{className:`truncate text-gray-700`,children:t})]},t)),C.length===0&&n.trim().length===0&&(0,h.jsx)(`div`,{className:`px-3 py-2 text-sm text-gray-500`,children:u??`No models available`})]})})]})}var v=new Set([`off`,`minimal`,`low`,`medium`,`high`,`adaptive`,`xhigh`]);function y(e){if(!e||e.length===0)return[];let t=new Set;for(let n of e){let e=n.trim();e&&t.add(e)}return[...t]}function b(e,t){let n=e.trim(),r=t.trim();if(!n||!r)return n;let i=`${r}/`;return n.startsWith(i)?n.slice(i.length):n}function x(e,t){let n=e.trim();if(!n)return``;for(let e of t)n=b(n,e);return n.trim()}function S(e,t){let n=t.trim(),r=e.trim();return n?r?`${r}/${n}`:n:``}function C(e){if(typeof e!=`string`)return null;let t=e.trim().toLowerCase();return t&&v.has(t)?t:null}function w(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){let e=C(n);!e||t.includes(e)||t.push(e)}return t}function T(e,t){if(!e)return{};let n={};for(let[r,i]of Object.entries(e)){let e=x(r,t);if(!e)continue;let a={},o=w(i?.thinking?.supported);if(o.length>0){let e=C(i?.thinking?.default);a.thinking=e&&o.includes(e)?{supported:o,default:e}:{supported:o}}i?.vision===!0&&(a.vision=!0),(a.thinking||a.vision===!0)&&(n[e]=a)}return n}function E(e,t){let n=T(e,t);return Object.fromEntries(Object.entries(n).filter(e=>!!e[1].thinking).map(([e,t])=>[e,t.thinking]))}function D(e,t,n){let r=x(t,n);return r?e[r]??null:null}function O(e,t){let n=e.trim();if(!n)return null;let r=null;for(let e of t)for(let t of e.aliases){let i=t.trim();i&&(n===i||n.startsWith(`${i}/`))&&(!r||i.length>r.score)&&(r={name:e.name,score:i.length})}if(r)return r.name;for(let e of t){let t=x(n,e.aliases);if(t&&y(e.models??[]).some(e=>e===t))return e.name}return null}function k(e){return e?e.enabled!==!1&&e.apiKeySet===!0:!1}function A(e){let{meta:t,config:n,onlyConfigured:r=!1}=e,i=(t?.providers??[]).map(e=>{let t=n?.providers?.[e.name],r=(e.modelPrefix||e.name||``).trim(),i=y([e.modelPrefix||``,e.name||``]),a=y((t?.models??[]).map(e=>x(e,i))),o=t?.modelConfig??e.modelConfig,s=T(o,i),c=E(o,i),l=t?.displayName?.trim(),u=k(t);return{name:e.name,displayName:l||e.displayName||e.name,prefix:r,aliases:i,models:a,modelConfig:s,modelThinking:c,configured:u}});return r?i.filter(e=>e.configured&&e.models.length>0):i}var j=`provider/model`;function M(e){let t=new Set;for(let n of e){let e=n.trim();e&&t.add(e)}return[...t]}function N({id:e,value:t,onChange:r,providerCatalog:i,disabled:o=!1,providerPlaceholder:f,modelPlaceholder:p,className:g}){let[v,y]=(0,m.useState)(``),[b,C]=(0,m.useState)(``),w=i.length>0,T=p??j,E=(0,m.useMemo)(()=>new Map(i.map(e=>[e.name,e])),[i]),D=E.get(v),k=(0,m.useMemo)(()=>D?.aliases??[],[D]),A=(0,m.useMemo)(()=>M(D?.models??[]),[D]);return(0,m.useEffect)(()=>{let e=t.trim();if(!w){y(``),C(e);return}if(!e){C(``),y(e=>E.has(e)?e:``);return}let n=O(e,i)??``,r=E.get(n)?.aliases??[];y(n),C(n?x(e,r):e)},[w,i,E,t]),w?(0,h.jsxs)(`div`,{className:g,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center`,children:[(0,h.jsx)(`div`,{className:`sm:w-[38%] sm:min-w-[170px]`,children:(0,h.jsxs)(c,{value:v,onValueChange:e=>{let t=M(E.get(e)?.models??[])[0]??``;if(y(e),C(t),!t){r(``);return}r(S(E.get(e)?.prefix??e,t))},disabled:o,children:[(0,h.jsx)(u,{className:`h-10 w-full rounded-xl`,children:(0,h.jsx)(l,{placeholder:f??n(`providersSelectPlaceholder`)})}),(0,h.jsx)(d,{children:i.map(e=>(0,h.jsx)(s,{value:e.name,children:e.displayName},e.name))})]})}),(0,h.jsx)(`span`,{className:`hidden h-10 items-center justify-center leading-none text-lg font-semibold text-gray-300 sm:inline-flex`,children:`/`}),(0,h.jsx)(_,{id:e,value:b,onChange:e=>{if(!D){let t=e.trim();C(t),r(t);return}let t=x(e,k);C(t),r(t?S(D.prefix,t):``)},options:A,disabled:o||!v,placeholder:T,className:`sm:flex-1`,inputClassName:`h-10 rounded-xl`,emptyText:n(`modelPickerNoOptions`),createText:n(`modelPickerUseCustom`)},v)]}),(0,h.jsx)(`p`,{className:`mt-2 text-xs text-gray-500`,children:n(`modelInputCustomHint`)})]}):(0,h.jsxs)(`div`,{className:g,children:[(0,h.jsxs)(`div`,{className:`rounded-2xl border border-amber-200 bg-amber-50/70 px-4 py-3`,children:[(0,h.jsx)(`p`,{className:`text-sm font-semibold text-amber-950`,children:n(`providersEmptyTitle`)}),(0,h.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-amber-900`,children:n(`providersEmptyDescription`)})]}),(0,h.jsx)(a,{id:e,value:t,disabled:o,onChange:e=>r(e.target.value),placeholder:T,className:`mt-3 h-10 rounded-xl`}),(0,h.jsx)(`p`,{className:`mt-2 text-xs text-gray-500`,children:n(`modelInputCustomHint`)})]})}export{D as i,A as n,S as r,N as t};
1
+ import{d as e,h as t,i as n,m as r,v as i}from"./react-B2X_ph0a.js";import{Mt as a}from"./api-DruAcori.js";import{t as o}from"./createLucideIcon-Br1EFMEr.js";import{J as s,K as c,X as l,Y as u,q as d,un as f}from"./index-GVTiCf1s.js";var p=o(`ChevronsUpDown`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),m=i(t(),1),h=r();function g(e){let t=new Set;for(let n of e){let e=n.trim();e.length>0&&t.add(e)}return[...t]}function _({id:t,value:n,onChange:r,options:i,disabled:o=!1,placeholder:s,className:c,inputClassName:l,emptyText:u,createText:d,maxItems:_=1/0,onEnter:v}){let[y,b]=(0,m.useState)(!1);(0,m.useEffect)(()=>{o&&y&&b(!1)},[o,y]);let x=(0,m.useMemo)(()=>g(i),[i]),S=n.trim().toLowerCase(),C=(0,m.useMemo)(()=>{let e=x.map((e,t)=>({option:e,index:t}));S.length>0&&e.sort((e,t)=>{let n=e.option.toLowerCase(),r=t.option.toLowerCase(),i=n===S?0:n.startsWith(S)?1:n.includes(S)?2:3,a=r===S?0:r.startsWith(S)?1:r.includes(S)?2:3;return i===a?e.index-t.index:i-a});let t=e.map(e=>e.option);return Number.isFinite(_)?t.slice(0,Math.max(1,_)):t},[x,S,_]),w=n.trim().length>0&&x.some(e=>e===n.trim());return(0,h.jsxs)(`div`,{className:e(`relative`,c),onBlur:()=>{setTimeout(()=>b(!1),120)},children:[(0,h.jsx)(a,{id:t,value:n,disabled:o,onFocus:()=>{o||b(!0)},onChange:e=>{r(e.target.value),!y&&!o&&b(!0)},onKeyDown:e=>{e.key===`Enter`&&(v&&(e.preventDefault(),v()),b(!1))},placeholder:s,className:e(`pr-10`,l)}),(0,h.jsx)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>b(e=>!e),disabled:o,className:e(`absolute inset-y-0 right-0 inline-flex w-10 items-center justify-center`,o?`cursor-not-allowed text-gray-300`:`text-gray-400 hover:text-gray-600`),"aria-label":`toggle model options`,children:(0,h.jsx)(p,{className:`h-4 w-4`})}),y&&!o&&(0,h.jsx)(`div`,{className:`absolute z-20 mt-1 w-full overflow-hidden rounded-xl border border-gray-200 bg-white shadow-lg`,children:(0,h.jsxs)(`div`,{className:`max-h-60 overflow-y-auto py-1`,children:[!w&&n.trim().length>0&&(0,h.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{r(n.trim()),b(!1)},className:`flex w-full items-center gap-2 px-3 py-2 text-left text-sm hover:bg-gray-50`,children:[(0,h.jsx)(f,{className:`h-4 w-4 text-transparent`}),(0,h.jsx)(`span`,{className:`truncate text-gray-700`,children:d?d.replace(`{value}`,n.trim()):n.trim()})]}),C.map(t=>(0,h.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{r(t),b(!1)},className:`flex w-full items-center gap-2 px-3 py-2 text-left text-sm hover:bg-gray-50`,children:[(0,h.jsx)(f,{className:e(`h-4 w-4`,t===n.trim()?`text-primary`:`text-transparent`)}),(0,h.jsx)(`span`,{className:`truncate text-gray-700`,children:t})]},t)),C.length===0&&n.trim().length===0&&(0,h.jsx)(`div`,{className:`px-3 py-2 text-sm text-gray-500`,children:u??`No models available`})]})})]})}var v=new Set([`off`,`minimal`,`low`,`medium`,`high`,`adaptive`,`xhigh`]);function y(e){if(!e||e.length===0)return[];let t=new Set;for(let n of e){let e=n.trim();e&&t.add(e)}return[...t]}function b(e,t){let n=e.trim(),r=t.trim();if(!n||!r)return n;let i=`${r}/`;return n.startsWith(i)?n.slice(i.length):n}function x(e,t){let n=e.trim();if(!n)return``;for(let e of t)n=b(n,e);return n.trim()}function S(e,t){let n=t.trim(),r=e.trim();return n?r?`${r}/${n}`:n:``}function C(e){if(typeof e!=`string`)return null;let t=e.trim().toLowerCase();return t&&v.has(t)?t:null}function w(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){let e=C(n);!e||t.includes(e)||t.push(e)}return t}function T(e,t){if(!e)return{};let n={};for(let[r,i]of Object.entries(e)){let e=x(r,t);if(!e)continue;let a={},o=w(i?.thinking?.supported);if(o.length>0){let e=C(i?.thinking?.default);a.thinking=e&&o.includes(e)?{supported:o,default:e}:{supported:o}}i?.vision===!0&&(a.vision=!0),(a.thinking||a.vision===!0)&&(n[e]=a)}return n}function E(e,t){let n=T(e,t);return Object.fromEntries(Object.entries(n).filter(e=>!!e[1].thinking).map(([e,t])=>[e,t.thinking]))}function D(e,t,n){let r=x(t,n);return r?e[r]??null:null}function O(e,t){let n=e.trim();if(!n)return null;let r=null;for(let e of t)for(let t of e.aliases){let i=t.trim();i&&(n===i||n.startsWith(`${i}/`))&&(!r||i.length>r.score)&&(r={name:e.name,score:i.length})}if(r)return r.name;for(let e of t){let t=x(n,e.aliases);if(t&&y(e.models??[]).some(e=>e===t))return e.name}return null}function k(e){return e?e.enabled!==!1&&e.apiKeySet===!0:!1}function A(e){let{meta:t,config:n,onlyConfigured:r=!1}=e,i=(t?.providers??[]).map(e=>{let t=n?.providers?.[e.name],r=(e.modelPrefix||e.name||``).trim(),i=y([e.modelPrefix||``,e.name||``]),a=y((t?.models??[]).map(e=>x(e,i))),o=t?.modelConfig??e.modelConfig,s=T(o,i),c=E(o,i),l=t?.displayName?.trim(),u=k(t);return{name:e.name,displayName:l||e.displayName||e.name,prefix:r,aliases:i,models:a,modelConfig:s,modelThinking:c,configured:u}});return r?i.filter(e=>e.configured&&e.models.length>0):i}var j=`provider/model`;function M(e){let t=new Set;for(let n of e){let e=n.trim();e&&t.add(e)}return[...t]}function N({id:e,value:t,onChange:r,providerCatalog:i,disabled:o=!1,providerPlaceholder:f,modelPlaceholder:p,className:g}){let[v,y]=(0,m.useState)(``),[b,C]=(0,m.useState)(``),w=i.length>0,T=p??j,E=(0,m.useMemo)(()=>new Map(i.map(e=>[e.name,e])),[i]),D=E.get(v),k=(0,m.useMemo)(()=>D?.aliases??[],[D]),A=(0,m.useMemo)(()=>M(D?.models??[]),[D]);return(0,m.useEffect)(()=>{let e=t.trim();if(!w){y(``),C(e);return}if(!e){C(``),y(e=>E.has(e)?e:``);return}let n=O(e,i)??``,r=E.get(n)?.aliases??[];y(n),C(n?x(e,r):e)},[w,i,E,t]),w?(0,h.jsxs)(`div`,{className:g,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center`,children:[(0,h.jsx)(`div`,{className:`sm:w-[38%] sm:min-w-[170px]`,children:(0,h.jsxs)(c,{value:v,onValueChange:e=>{let t=M(E.get(e)?.models??[])[0]??``;if(y(e),C(t),!t){r(``);return}r(S(E.get(e)?.prefix??e,t))},disabled:o,children:[(0,h.jsx)(u,{className:`h-10 w-full rounded-xl`,children:(0,h.jsx)(l,{placeholder:f??n(`providersSelectPlaceholder`)})}),(0,h.jsx)(d,{children:i.map(e=>(0,h.jsx)(s,{value:e.name,children:e.displayName},e.name))})]})}),(0,h.jsx)(`span`,{className:`hidden h-10 items-center justify-center leading-none text-lg font-semibold text-gray-300 sm:inline-flex`,children:`/`}),(0,h.jsx)(_,{id:e,value:b,onChange:e=>{if(!D){let t=e.trim();C(t),r(t);return}let t=x(e,k);C(t),r(t?S(D.prefix,t):``)},options:A,disabled:o||!v,placeholder:T,className:`sm:flex-1`,inputClassName:`h-10 rounded-xl`,emptyText:n(`modelPickerNoOptions`),createText:n(`modelPickerUseCustom`)},v)]}),(0,h.jsx)(`p`,{className:`mt-2 text-xs text-gray-500`,children:n(`modelInputCustomHint`)})]}):(0,h.jsxs)(`div`,{className:g,children:[(0,h.jsxs)(`div`,{className:`rounded-2xl border border-amber-200 bg-amber-50/70 px-4 py-3`,children:[(0,h.jsx)(`p`,{className:`text-sm font-semibold text-amber-950`,children:n(`providersEmptyTitle`)}),(0,h.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-amber-900`,children:n(`providersEmptyDescription`)})]}),(0,h.jsx)(a,{id:e,value:t,disabled:o,onChange:e=>r(e.target.value),placeholder:T,className:`mt-3 h-10 rounded-xl`}),(0,h.jsx)(`p`,{className:`mt-2 text-xs text-gray-500`,children:n(`modelInputCustomHint`)})]})}export{D as i,A as n,S as r,N as t};
@@ -1 +1 @@
1
- import{d as e,h as t,i as n,m as r,o as i,v as a}from"./react-B2X_ph0a.js";import{At as o,Lt as s,Mt as c,Nt as l,Xt as u,ft as d,jt as f,kt as p}from"./api-DruAcori.js";import{t as m}from"./createLucideIcon-Br1EFMEr.js";import{t as h}from"./search-CdhgFNwf.js";import{t as g}from"./plus-BcIC8dG1.js";import{t as _}from"./x-Chb07O-Y.js";import{$ as ee,Gt as v,J as y,K as b,Kt as x,Mt as S,Nt as C,Q as te,U as w,X as T,Y as E,Z as ne,at as re,ct as ie,dt as ae,et as oe,ht as se,jt as D,ln as ce,q as O,rn as le,rt as ue,ut as de,xt as k}from"./index-D2H2CKYR.js";import{t as A}from"./tabs-custom-BBXu1OGs.js";import{t as fe}from"./config-hints-CY1lg9IE.js";import{a as pe,c as me,i as he,n as ge,o as _e,r as j,s as ve,t as M}from"./config-split-page-BFh_Qixx.js";import{t as ye}from"./setting-row-8VkukJoH.js";var be=m(`CircleDotDashed`,[[`path`,{d:`M10.1 2.18a9.93 9.93 0 0 1 3.8 0`,key:`1qdqn0`}],[`path`,{d:`M17.6 3.71a9.95 9.95 0 0 1 2.69 2.7`,key:`1bq7p6`}],[`path`,{d:`M21.82 10.1a9.93 9.93 0 0 1 0 3.8`,key:`1rlaqf`}],[`path`,{d:`M20.29 17.6a9.95 9.95 0 0 1-2.7 2.69`,key:`1xk03u`}],[`path`,{d:`M13.9 21.82a9.94 9.94 0 0 1-3.8 0`,key:`l7re25`}],[`path`,{d:`M6.4 20.29a9.95 9.95 0 0 1-2.69-2.7`,key:`1v18p6`}],[`path`,{d:`M2.18 13.9a9.93 9.93 0 0 1 0-3.8`,key:`xdo6bj`}],[`path`,{d:`M3.71 6.4a9.95 9.95 0 0 1 2.7-2.69`,key:`1jjmaz`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),xe=m(`EyeOff`,[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`,key:`ct8e1f`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`,key:`151rxh`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`,key:`13bj9a`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),Se=m(`Eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),Ce=m(`Settings2`,[[`path`,{d:`M20 7h-9`,key:`3s1dr2`}],[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),N=a(t(),1),P=r();function we({isSet:t,className:n,value:r,onChange:i,placeholder:a,...o}){let[s,u]=(0,N.useState)(!1),[d,f]=(0,N.useState)(!1),p=typeof r==`string`&&r.length>0;return(0,P.jsxs)(`div`,{className:`relative`,children:[t&&!p&&!d?(0,P.jsx)(`div`,{onClick:()=>f(!0),className:e(`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`,n),children:`••••••••••••`}):(0,P.jsx)(c,{type:s?`text`:`password`,className:e(`pr-12`,n),value:r,onChange:i,onBlur:()=>{p||f(!1)},placeholder:a,autoFocus:d,...o}),(0,P.jsx)(`div`,{className:`absolute right-2 top-1/2 -translate-y-1/2 flex gap-1`,children:(t||p)&&(0,P.jsx)(l,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>u(!s),children:s?(0,P.jsx)(xe,{className:`h-4 w-4`}):(0,P.jsx)(Se,{className:`h-4 w-4`})})})]})}function Te({value:t,onChange:r,className:i}){let a=t?Object.entries(t):[],o=(e,t,n)=>{let i=[...a];i[e]=[t,n],r(Object.fromEntries(i))},s=()=>{r({...t,"":``})},u=e=>{let t=a.filter((t,n)=>n!==e);r(Object.fromEntries(t))};return(0,P.jsxs)(`div`,{className:e(`space-y-2`,i),children:[a.map(([e,t],r)=>(0,P.jsxs)(`div`,{className:`flex gap-2`,children:[(0,P.jsx)(c,{type:`text`,value:e,onChange:e=>o(r,e.target.value,t),placeholder:n(`headerName`),className:`flex-1`}),(0,P.jsx)(c,{type:`text`,value:t,onChange:t=>o(r,e,t.target.value),placeholder:n(`headerValue`),className:`flex-1`}),(0,P.jsx)(l,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>u(r),children:(0,P.jsx)(x,{className:`h-4 w-4 text-red-500`})})]},r)),(0,P.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,onClick:s,children:[(0,P.jsx)(g,{className:`h-4 w-4 mr-2`}),n(`add`)]})]})}function Ee(e){let{value:t,onChange:n,options:r}=e;return(0,P.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:r.map(e=>{let r=e.value===t;return(0,P.jsx)(`button`,{type:`button`,onClick:()=>n(e.value),"aria-pressed":r,className:`rounded-full border px-3 py-1.5 text-xs font-medium transition-colors ${r?`border-primary bg-primary text-white shadow-sm`:`border-gray-200 bg-white text-gray-700 hover:border-primary/40 hover:text-primary`}`,children:e.label},e.value)})})}function De(e){let{showAdvanced:t,onShowAdvancedChange:r,supportsWireApi:i,wireApiLabel:a,wireApi:o,onWireApiChange:s,shouldUseWireApiPills:c,wireApiSelectOptions:l,extraHeadersLabel:u,extraHeaders:d,onExtraHeadersChange:p}=e;return(0,P.jsxs)(`div`,{className:`border-t border-gray-100 pt-4`,children:[(0,P.jsxs)(`button`,{type:`button`,onClick:()=>r(!t),className:`flex w-full items-center justify-between text-sm text-gray-600 transition-colors hover:text-gray-900`,children:[(0,P.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,P.jsx)(Ce,{className:`h-3.5 w-3.5`}),n(`providerAdvancedSettings`)]}),(0,P.jsx)(ce,{className:`h-4 w-4 transition-transform ${t?`rotate-180`:``}`})]}),t?(0,P.jsxs)(`div`,{className:`mt-4 space-y-5`,children:[i?(0,P.jsxs)(`div`,{className:`space-y-2`,children:[(0,P.jsx)(f,{htmlFor:`wireApi`,className:`text-sm font-medium text-gray-900`,children:a}),c?(0,P.jsx)(Ee,{value:o,onChange:e=>s(e),options:l}):(0,P.jsxs)(b,{value:o,onValueChange:e=>s(e),children:[(0,P.jsx)(E,{className:`rounded-xl`,children:(0,P.jsx)(T,{})}),(0,P.jsx)(O,{children:l.map(e=>(0,P.jsx)(y,{value:e.value,children:e.label},e.value))})]})]}):null,(0,P.jsxs)(`div`,{className:`space-y-2`,children:[(0,P.jsx)(f,{className:`text-sm font-medium text-gray-900`,children:u}),(0,P.jsx)(Te,{value:d,onChange:p}),(0,P.jsx)(`p`,{className:`text-xs text-gray-500`,children:n(`providerExtraHeadersHelpShort`)})]})]}):null]})}function Oe(e){let{providerAuth:t,providerAuthNote:r,providerAuthMethodOptions:i,providerAuthMethodsCount:a,selectedAuthMethodHint:o,shouldUseAuthMethodPills:s,resolvedAuthMethodId:c,onAuthMethodChange:u,onStartProviderAuth:d,onImportProviderAuthFromCli:p,startPending:m,importPending:h,authSessionId:g,authStatusMessage:_}=e;return t?.kind===`device_code`?(0,P.jsxs)(`div`,{className:`space-y-2 rounded-xl border border-primary/20 bg-primary-50/50 p-3`,children:[(0,P.jsx)(f,{className:`text-sm font-medium text-gray-900`,children:t.displayName||n(`providerAuthSectionTitle`)}),r?(0,P.jsx)(`p`,{className:`text-xs text-gray-600`,children:r}):null,a>1?(0,P.jsxs)(`div`,{className:`space-y-2`,children:[(0,P.jsx)(f,{className:`text-xs font-medium text-gray-700`,children:n(`providerAuthMethodLabel`)}),s?(0,P.jsx)(Ee,{value:c,onChange:u,options:i}):(0,P.jsxs)(b,{value:c,onValueChange:u,children:[(0,P.jsx)(E,{className:`h-8 rounded-lg bg-white`,children:(0,P.jsx)(T,{placeholder:n(`providerAuthMethodPlaceholder`)})}),(0,P.jsx)(O,{children:i.map(e=>(0,P.jsx)(y,{value:e.value,children:e.label},e.value))})]}),o?(0,P.jsx)(`p`,{className:`text-xs text-gray-500`,children:o}):null]}):null,(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(l,{type:`button`,variant:`outline`,size:`sm`,onClick:d,disabled:m||!!g,children:n(m?`providerAuthStarting`:g?`providerAuthAuthorizing`:`providerAuthAuthorizeInBrowser`)}),t.supportsCliImport?(0,P.jsx)(l,{type:`button`,variant:`outline`,size:`sm`,onClick:p,disabled:h,children:n(h?`providerAuthImporting`:`providerAuthImportFromCli`)}):null,g?(0,P.jsxs)(`span`,{className:`text-xs text-gray-500`,children:[n(`providerAuthSessionLabel`),`: `,g.slice(0,8),`…`]}):null]}),_?(0,P.jsx)(`p`,{className:`text-xs text-gray-600`,children:_}):null]}):null}function ke(e){let{enabled:t,onChange:r}=e;return(0,P.jsx)(ye,{tone:`muted`,title:n(`enabled`),control:(0,P.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,P.jsx)(`span`,{className:`text-xs text-gray-500`,children:n(t?`enabled`:`disabled`)}),(0,P.jsx)(d,{checked:t,onCheckedChange:r})]})})}var Ae={enabled:!0,displayName:``,apiKeySet:!1,apiKeyMasked:void 0,apiBase:null,extraHeaders:null,wireApi:null,models:[],modelConfig:{}},je=[`off`,`minimal`,`low`,`medium`,`high`,`adaptive`,`xhigh`],F=new Set(je);function I(e){if(!e)return null;let t=Object.entries(e).map(([e,t])=>[e.trim(),t]).filter(([e])=>e.length>0);return t.length===0?null:Object.fromEntries(t)}function Me(e,t){let n=I(e),r=I(t);if(n===null&&r===null)return!0;if(!n||!r)return!1;let i=Object.entries(n).sort(([e],[t])=>e.localeCompare(t)),a=Object.entries(r).sort(([e],[t])=>e.localeCompare(t));return i.length===a.length?i.every(([e,t],n)=>e===a[n][0]&&t===a[n][1]):!1}function Ne(e){if(!e||e.length===0)return[];let t=new Set;for(let n of e){let e=n.trim();e&&t.add(e)}return[...t]}function Pe(e,t){let n=e.trim();if(!n||!t.trim())return n;let r=`${t.trim()}/`;return n.startsWith(r)?n.slice(r.length):n}function L(e,t){let n=e.trim();if(!n)return``;for(let e of t){let t=e.trim();t&&(n=Pe(n,t))}return n.trim()}function Fe(e,t){return e.length===t.length?e.every((e,n)=>e===t[n]):!1}function Ie(e,t){return t}function Le(e,t){return e}function Re(e,t,n){t!==n&&(e.enabled=t)}function R(e){if(typeof e!=`string`)return null;let t=e.trim().toLowerCase();return t&&F.has(t)?t:null}function ze(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){let e=R(n);!e||t.includes(e)||t.push(e)}return t}function Be(e,t){if(!e)return{};let n={};for(let[r,i]of Object.entries(e)){let e=L(r,t);if(!e)continue;let a={},o=ze(i?.thinking?.supported);if(o.length>0){let e=R(i?.thinking?.default);a.thinking=e&&o.includes(e)?{supported:o,default:e}:{supported:o}}i?.vision===!0&&(a.vision=!0),(a.thinking||a.vision===!0)&&(n[e]=a)}return n}function Ve(e,t){let n=new Set(t.map(e=>e.trim()).filter(Boolean)),r={};for(let[t,i]of Object.entries(e)){if(!n.has(t))continue;let e={},a=ze(i.thinking?.supported);if(a.length>0){let t=R(i.thinking?.default);e.thinking=t&&a.includes(t)?{supported:a,default:t}:{supported:a}}i.vision===!0&&(e.vision=!0),(e.thinking||e.vision===!0)&&(r[t]=e)}return r}function He(e,t){let n=Object.keys(e).sort(),r=Object.keys(t).sort();if(n.length!==r.length)return!1;for(let i=0;i<n.length;i+=1){let a=n[i];if(a!==r[i])return!1;let o=e[a],s=t[a];if(!o||!s||!Fe([...o.thinking?.supported??[]].sort(),[...s.thinking?.supported??[]].sort())||(o.thinking?.default??null)!==(s.thinking?.default??null)||(o.vision??!1)!==(s.vision??!1))return!1}return!0}function Ue(e){return n(e===`off`?`chatThinkingLevelOff`:e===`minimal`?`chatThinkingLevelMinimal`:e===`low`?`chatThinkingLevelLow`:e===`medium`?`chatThinkingLevelMedium`:e===`high`?`chatThinkingLevelHigh`:e===`adaptive`?`chatThinkingLevelAdaptive`:`chatThinkingLevelXhigh`)}function We(e){let{providerName:t,methods:n,defaultMethodId:r,language:i}=e;if(n.length===0)return``;let a=new Map;for(let e of n){let t=e.id.trim();t&&a.set(t.toLowerCase(),t)}let o=(...e)=>{for(let t of e){let e=a.get(t.toLowerCase());if(e)return e}},s=r?.trim();if(t===`minimax-portal`){if(i===`zh`)return o(`cn`,`china-mainland`)??o(s??``)??n[0]?.id??``;if(i===`en`)return o(`global`,`intl`,`international`)??o(s??``)??n[0]?.id??``}if(s){let e=o(s);if(e)return e}return i===`zh`?o(`cn`)??n[0]?.id??``:i===`en`?o(`global`)??n[0]?.id??``:n[0]?.id??``}function Ge(e){return e.required&&e.hasDefault&&e.optionCount>1&&e.optionCount<=3}function Ke(e){let{models:t,modelConfig:r,modelDraft:i,showModelInput:a,onModelDraftChange:o,onShowModelInputChange:s,onAddModel:u,onRemoveModel:p,onToggleModelThinkingLevel:m,onSetModelThinkingDefault:h,onSetModelVision:ee,thinkingLevels:v,formatThinkingLevelLabel:x}=e;return(0,P.jsxs)(`div`,{className:`space-y-2`,children:[(0,P.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,P.jsx)(f,{className:`text-sm font-medium text-gray-900`,children:n(`providerModelsTitle`)}),a?null:(0,P.jsxs)(`button`,{type:`button`,onClick:()=>s(!0),className:`flex items-center gap-1 text-xs font-medium text-primary hover:text-primary/80`,children:[(0,P.jsx)(g,{className:`h-3 w-3`}),n(`providerAddModel`)]})]}),a?(0,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,P.jsx)(c,{value:i,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),u()),e.key===`Escape`&&(s(!1),o(``))},placeholder:n(`providerModelInputPlaceholder`),className:`flex-1 rounded-xl`,autoFocus:!0}),(0,P.jsx)(l,{type:`button`,size:`sm`,onClick:u,disabled:i.trim().length===0,children:n(`add`)}),(0,P.jsx)(l,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>{s(!1),o(``)},children:(0,P.jsx)(_,{className:`h-4 w-4`})})]}):null,t.length===0?(0,P.jsxs)(`div`,{className:`rounded-xl border border-dashed border-gray-200 bg-gray-50 px-4 py-6 text-center`,children:[(0,P.jsx)(`p`,{className:`text-sm text-gray-500`,children:n(`providerModelsEmptyShort`)}),a?null:(0,P.jsx)(`button`,{type:`button`,onClick:()=>s(!0),className:`mt-2 text-sm font-medium text-primary hover:text-primary/80`,children:n(`providerAddFirstModel`)})]}):(0,P.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:t.map(e=>{let t=r[e],i=t?.thinking,a=i?.supported??[],o=i?.default??null,s=t?.vision===!0;return(0,P.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:[(0,P.jsx)(`span`,{className:`max-w-[140px] truncate text-sm text-gray-800 sm:max-w-[220px]`,children:e}),(0,P.jsxs)(D,{children:[(0,P.jsx)(C,{asChild:!0,children:(0,P.jsx)(`button`,{type:`button`,className:`inline-flex h-5 w-5 items-center justify-center rounded-full text-gray-400 opacity-100 transition-opacity hover:bg-gray-100 hover:text-gray-600 md:opacity-0 md:group-hover:opacity-100 md:group-focus-within:opacity-100`,"aria-label":n(`providerModelThinkingTitle`),title:n(`providerModelThinkingTitle`),children:(0,P.jsx)(Ce,{className:`h-3 w-3`})})}),(0,P.jsxs)(S,{className:`w-80 space-y-3`,children:[(0,P.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-lg border border-gray-100 bg-gray-50 px-3 py-2`,children:[(0,P.jsxs)(`div`,{className:`min-w-0`,children:[(0,P.jsx)(`p`,{className:`text-xs font-semibold text-gray-800`,children:n(`providerModelVisionTitle`)}),(0,P.jsx)(`p`,{className:`text-xs text-gray-500`,children:n(`providerModelVisionHint`)})]}),(0,P.jsx)(d,{checked:s,onCheckedChange:t=>ee(e,t)})]}),(0,P.jsxs)(`div`,{className:`space-y-1`,children:[(0,P.jsx)(`p`,{className:`text-xs font-semibold text-gray-800`,children:n(`providerModelThinkingTitle`)}),(0,P.jsx)(`p`,{className:`text-xs text-gray-500`,children:n(`providerModelThinkingHint`)})]}),(0,P.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:v.map(t=>(0,P.jsx)(`button`,{type:`button`,onClick:()=>m(e,t),className:`rounded-full border px-2.5 py-1 text-xs font-medium transition-colors ${a.includes(t)?`border-primary bg-primary text-white`:`border-gray-200 bg-white text-gray-600 hover:border-primary/40 hover:text-primary`}`,children:x(t)},t))}),(0,P.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,P.jsx)(f,{className:`text-xs font-medium text-gray-700`,children:n(`providerModelThinkingDefault`)}),(0,P.jsxs)(b,{value:o??`__none__`,onValueChange:t=>h(e,t===`__none__`?null:t),disabled:a.length===0,children:[(0,P.jsx)(E,{className:`h-8 rounded-lg bg-white text-xs`,children:(0,P.jsx)(T,{})}),(0,P.jsxs)(O,{children:[(0,P.jsx)(y,{value:`__none__`,children:n(`providerModelThinkingDefaultNone`)}),a.map(e=>(0,P.jsx)(y,{value:e,children:x(e)},e))]})]}),a.length===0?(0,P.jsx)(`p`,{className:`text-xs text-gray-500`,children:n(`providerModelThinkingNoSupported`)}):null]})]})]}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>p(e),className:`inline-flex h-5 w-5 items-center justify-center rounded-full text-gray-400 opacity-100 transition-opacity hover:bg-gray-100 hover:text-gray-600 md:opacity-0 md:group-hover:opacity-100 md:group-focus-within:opacity-100`,"aria-label":n(`remove`),children:(0,P.jsx)(_,{className:`h-3 w-3`})})]},e)})})]})}function qe(e){return e.enabled?(0,P.jsx)(v,{status:e.apiKeySet?`ready`:`setup`,label:e.apiKeySet?n(`statusReady`):n(`statusSetup`),className:e.className}):(0,P.jsx)(v,{status:`inactive`,label:n(`disabled`),className:e.className})}function Je({providerName:e,onProviderDeleted:t}){let r=u(),{data:a}=ne(),{data:o}=te(),{data:d}=ee(),p=se(),m=ue(),h=ae(),g=de(),_=ie(),v=re(),[y,b]=(0,N.useState)(``),[S,C]=(0,N.useState)(!0),[w,T]=(0,N.useState)(``),[E,oe]=(0,N.useState)(null),[D,ce]=(0,N.useState)(`auto`),[O,le]=(0,N.useState)([]),[k,A]=(0,N.useState)({}),[he,j]=(0,N.useState)(``),[M,ye]=(0,N.useState)(``),[xe,Se]=(0,N.useState)(!1),[Ce,Te]=(0,N.useState)(!1),[Ee,F]=(0,N.useState)(null),[Pe,R]=(0,N.useState)(``),[ze,Je]=(0,N.useState)(``),z=(0,N.useRef)(null),B=o?.providers.find(t=>t.name===e),V=(e?a?.providers[e]:null)??Ae,Ye=d?.uiHints,H=!!B?.isCustom,Xe=e?fe(`providers.${e}.apiKey`,Ye):void 0,Ze=e?fe(`providers.${e}.apiBase`,Ye):void 0,Qe=e?fe(`providers.${e}.extraHeaders`,Ye):void 0,$e=e?fe(`providers.${e}.wireApi`,Ye):void 0,et=B?.displayName||e||``,U=(V.displayName||``).trim()||et,W=V.enabled!==!1,tt=M.trim()||U||e||n(`providersSelectPlaceholder`),G=(0,N.useMemo)(()=>Ne([B?.modelPrefix||e||``,e||``]),[e,B?.modelPrefix]),nt=B?.defaultApiBase||``,rt=V.apiBase||nt,it=I(V.extraHeaders||null),at=V.wireApi||B?.defaultWireApi||`auto`,ot=(0,N.useMemo)(()=>Ne((B?.defaultModels??[]).map(e=>L(e,G))),[B?.defaultModels,G]),st=(0,N.useMemo)(()=>Ne((V.models??[]).map(e=>L(e,G))),[V.models,G]),K=(0,N.useMemo)(()=>Ie(ot,st),[ot,st]),q=(0,N.useMemo)(()=>Ve(Be(V.modelConfig??B?.modelConfig,G),K),[K,G,B?.modelConfig,V.modelConfig]),J=i(),ct=B?.apiBaseHelp?.[J]||B?.apiBaseHelp?.en||Ze?.help||n(`providerApiBaseHelp`),Y=B?.auth,X=Y?.methods??[],Z=!!B?.supportsWireApi||H,lt=(0,N.useMemo)(()=>X.map(e=>({value:e.id,label:e.label?.[J]||e.label?.en||e.id})),[X,J]),ut=(0,N.useMemo)(()=>We({providerName:e,methods:X,defaultMethodId:Y?.defaultMethodId,language:J}),[e,Y?.defaultMethodId,X,J]),Q=(0,N.useMemo)(()=>{if(!X.length)return``;let e=ze.trim();return e&&X.some(t=>t.id===e)?e:ut||X[0]?.id||``},[ze,ut,X]),dt=(0,N.useMemo)(()=>X.find(e=>e.id===Q),[X,Q]),ft=Ge({required:Y?.kind===`device_code`,hasDefault:!!Y?.defaultMethodId?.trim(),optionCount:X.length}),pt=(B?.wireApiOptions||[`auto`,`chat`,`responses`]).map(e=>({value:e,label:n(e===`chat`?`wireApiChat`:e===`responses`?`wireApiResponses`:`wireApiAuto`)})),mt=Ge({required:Z,hasDefault:typeof B?.defaultWireApi==`string`&&B.defaultWireApi.length>0,optionCount:pt.length}),$=(0,N.useCallback)(()=>{z.current!==null&&(window.clearTimeout(z.current),z.current=null)},[]),ht=(0,N.useCallback)((t,i)=>{$(),z.current=window.setTimeout(()=>{(async()=>{if(e)try{let a=await _.mutateAsync({provider:e,data:{sessionId:t}});if(a.status===`pending`){R(n(`providerAuthWaitingBrowser`)),ht(t,a.nextPollMs??i);return}if(a.status===`authorized`){F(null),$(),R(n(`providerAuthCompleted`)),s.success(n(`providerAuthCompleted`)),r.invalidateQueries({queryKey:[`config`]}),r.invalidateQueries({queryKey:[`config-meta`]});return}F(null),$(),R(a.message||`Authorization ${a.status}.`),s.error(a.message||`Authorization ${a.status}.`)}catch(e){F(null),$();let t=e instanceof Error?e.message:String(e);R(t),s.error(`Authorization failed: ${t}`)}})()},Math.max(1e3,i))},[$,_,e,r]);(0,N.useEffect)(()=>{if(!e){b(``),C(!0),T(``),oe(null),ce(`auto`),le([]),A({}),j(``),ye(``),F(null),R(``),Je(``),$();return}b(``),C(W),T(rt),oe(V.extraHeaders||null),ce(at),le(K),A(q),j(``),ye(U),F(null),R(``),Je(ut),$()},[e,rt,W,V.extraHeaders,at,K,q,U,ut,$]),(0,N.useEffect)(()=>()=>$(),[$]),(0,N.useEffect)(()=>A(e=>Ve(e,O)),[O]);let gt=(0,N.useMemo)(()=>e?y.trim().length>0||S!==W||w.trim()!==rt.trim()||!Me(E,it)||Z&&D!==at||!Fe(O,K)||!He(k,q)||H&&M.trim()!==U:!1,[e,y,S,W,w,rt,E,it,Z,D,at,O,K,k,q,H,M,U]);return!e||!B?(0,P.jsx)(ge,{children:(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`h3`,{className:`text-base font-semibold text-gray-900`,children:n(`providersSelectTitle`)}),(0,P.jsx)(`p`,{className:`mt-2 text-sm text-gray-500`,children:n(`providersSelectDescription`)})]})}):(0,P.jsxs)(pe,{children:[(0,P.jsx)(me,{className:`px-6 py-4`,children:(0,P.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,P.jsx)(`h3`,{className:`truncate text-lg font-semibold text-gray-900`,children:tt}),(0,P.jsxs)(`div`,{className:`flex items-center gap-3`,children:[H&&(0,P.jsx)(`button`,{type:`button`,onClick:async()=>{if(!(!e||!H)&&window.confirm(n(`providerDeleteConfirm`)))try{await m.mutateAsync({provider:e}),t?.(e)}catch{}},disabled:m.isPending,className:`text-gray-400 transition-colors hover:text-red-500`,title:n(`providerDelete`),children:(0,P.jsx)(x,{className:`h-4 w-4`})}),(0,P.jsx)(qe,{enabled:W,apiKeySet:V.apiKeySet})]})]})}),(0,P.jsxs)(`form`,{onSubmit:t=>{if(t.preventDefault(),!e)return;let n={},r=y.trim(),i=w.trim(),a=I(E),o=M.trim();H&&o!==U&&(n.displayName=o.length>0?o:null),r.length>0&&(n.apiKey=r),Re(n,S,W),i!==rt.trim()&&(n.apiBase=i.length>0&&i!==nt?i:null),Me(a,it)||(n.extraHeaders=a),Z&&D!==at&&(n.wireApi=D),Fe(O,K)||(n.models=Le(O,ot)),He(k,q)||(n.modelConfig=Ve(k,O)),p.mutate({provider:e,data:n})},className:`flex min-h-0 flex-1 flex-col`,children:[(0,P.jsxs)(_e,{className:`space-y-5 px-6 py-5`,children:[(0,P.jsx)(ke,{enabled:S,onChange:C}),H&&(0,P.jsxs)(`div`,{className:`space-y-2`,children:[(0,P.jsx)(f,{htmlFor:`providerDisplayName`,className:`text-sm font-medium text-gray-900`,children:n(`providerDisplayName`)}),(0,P.jsx)(c,{id:`providerDisplayName`,type:`text`,value:M,onChange:e=>ye(e.target.value),placeholder:et||n(`providerDisplayNamePlaceholder`),className:`rounded-xl`}),(0,P.jsx)(`p`,{className:`text-xs text-gray-500`,children:n(`providerDisplayNameHelpShort`)})]}),(0,P.jsxs)(`div`,{className:`space-y-2`,children:[(0,P.jsx)(f,{htmlFor:`apiKey`,className:`text-sm font-medium text-gray-900`,children:Xe?.label??n(`apiKey`)}),(0,P.jsx)(we,{id:`apiKey`,value:y,isSet:V.apiKeySet,onChange:e=>b(e.target.value),placeholder:Xe?.placeholder??n(`enterApiKey`),className:`rounded-xl`}),(0,P.jsx)(`p`,{className:`text-xs text-gray-500`,children:n(`leaveBlankToKeepUnchanged`)})]}),(0,P.jsx)(Oe,{providerAuth:Y,providerAuthNote:Y?.note?.[J]||Y?.note?.en||Y?.displayName||``,providerAuthMethodOptions:lt,providerAuthMethodsCount:X.length,selectedAuthMethodHint:dt?.hint?.[J]||dt?.hint?.en||``,shouldUseAuthMethodPills:ft,resolvedAuthMethodId:Q,onAuthMethodChange:Je,onStartProviderAuth:async()=>{if(!(!e||Y?.kind!==`device_code`))try{R(``);let t=await g.mutateAsync({provider:e,data:Q?{methodId:Q}:{}});if(!t.sessionId||!t.verificationUri)throw Error(n(`providerAuthStartFailed`));F(t.sessionId),R(`${n(`providerAuthOpenPrompt`)}${t.userCode}${n(`providerAuthOpenPromptSuffix`)}`),window.open(t.verificationUri,`_blank`,`noopener,noreferrer`),ht(t.sessionId,t.intervalMs)}catch(e){let t=e instanceof Error?e.message:String(e);F(null),$(),R(t),s.error(`${n(`providerAuthStartFailed`)}: ${t}`)}},onImportProviderAuthFromCli:async()=>{if(!(!e||Y?.kind!==`device_code`))try{$(),F(null);let t=await v.mutateAsync({provider:e});R(`${n(`providerAuthImportStatusPrefix`)}${t.expiresAt?` (expires: ${t.expiresAt})`:``}`),s.success(n(`providerAuthImportSuccess`)),r.invalidateQueries({queryKey:[`config`]}),r.invalidateQueries({queryKey:[`config-meta`]})}catch(e){let t=e instanceof Error?e.message:String(e);R(t),s.error(`${n(`providerAuthImportFailed`)}: ${t}`)}},startPending:g.isPending,importPending:v.isPending,authSessionId:Ee,authStatusMessage:Pe}),(0,P.jsxs)(`div`,{className:`space-y-2`,children:[(0,P.jsx)(f,{htmlFor:`apiBase`,className:`text-sm font-medium text-gray-900`,children:Ze?.label??n(`apiBase`)}),(0,P.jsx)(c,{id:`apiBase`,type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:nt||Ze?.placeholder||`https://api.example.com`,className:`rounded-xl`}),(0,P.jsx)(`p`,{className:`text-xs text-gray-500`,children:ct})]}),(0,P.jsx)(Ke,{models:O,modelConfig:k,modelDraft:he,showModelInput:Ce,onModelDraftChange:j,onShowModelInputChange:Te,onAddModel:()=>{let e=L(he,G);if(e){if(O.includes(e)){j(``);return}le(t=>[...t,e]),j(``)}},onRemoveModel:e=>{le(t=>t.filter(t=>t!==e)),A(t=>{let n={...t};return delete n[e],n})},onToggleModelThinkingLevel:(e,t)=>{A(n=>{let r=n[e],i=r?.thinking?.supported??[],a=i.includes(t)?i.filter(e=>e!==t):je.filter(e=>e===t||i.includes(e)),o=r?.thinking?.default&&a.includes(r.thinking.default)?r.thinking.default:void 0,s={...r,thinking:a.length>0?o?{supported:a,default:o}:{supported:a}:void 0},c={...n};return s.thinking||s.vision===!0?c[e]=s:delete c[e],c})},onSetModelThinkingDefault:(e,t)=>{A(n=>{let r=n[e],i=r?.thinking;return!i||i.supported.length===0||t&&!i.supported.includes(t)?n:{...n,[e]:{...r,thinking:t?{supported:i.supported,default:t}:{supported:i.supported}}}})},onSetModelVision:(e,t)=>{A(n=>{let r={...n[e],vision:t?!0:void 0},i={...n};return r.thinking||r.vision===!0?i[e]=r:delete i[e],i})},thinkingLevels:je,formatThinkingLevelLabel:Ue}),(0,P.jsx)(De,{showAdvanced:xe,onShowAdvancedChange:Se,supportsWireApi:Z,wireApiLabel:$e?.label??n(`wireApi`),wireApi:D,onWireApiChange:ce,shouldUseWireApiPills:mt,wireApiSelectOptions:pt,extraHeadersLabel:Qe?.label??n(`extraHeaders`),extraHeaders:E,onExtraHeadersChange:oe})]}),(0,P.jsxs)(ve,{className:`flex items-center justify-between px-6 py-4`,children:[(0,P.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,onClick:async()=>{if(!e)return;let t=L(O.find(e=>e.trim().length>0)??``,G),r={apiBase:w.trim(),extraHeaders:I(E),model:t||null};y.trim().length>0&&(r.apiKey=y.trim()),Z&&(r.wireApi=D);try{let t=await h.mutateAsync({provider:e,data:r});if(t.success){s.success(`${n(`providerTestConnectionSuccess`)} (${t.latencyMs}ms)`);return}let i=[`provider=${t.provider}`,`latency=${t.latencyMs}ms`];t.model&&i.push(`model=${t.model}`),s.error(`${n(`providerTestConnectionFailed`)}: ${t.message} | ${i.join(` | `)}`)}catch(e){let t=e instanceof Error?e.message:String(e);s.error(`${n(`providerTestConnectionFailed`)}: ${t}`)}},disabled:h.isPending,children:[(0,P.jsx)(be,{className:`mr-1.5 h-4 w-4`}),h.isPending?n(`providerTestingConnection`):n(`providerTestConnection`)]}),(0,P.jsx)(l,{type:`submit`,disabled:p.isPending||!gt,children:p.isPending?n(`saving`):n(gt?`save`:`unchanged`)})]})]})]})}function z(e){if(!e)return null;try{let t=new URL(e);return`${t.host}${t.pathname&&t.pathname!==`/`?t.pathname:``}`}catch{return e.replace(/^https?:\/\//,``)}}function B(e){return e.map((e,t)=>({provider:e,index:t})).sort((e,t)=>{let n=e.provider.name===`nextclaw`?1:0,r=t.provider.name===`nextclaw`?1:0;return n===r?e.index-t.index:n-r}).map(({provider:e})=>e)}function V(){let{isMobile:t}=k(),{data:r}=ne(),{data:i}=te(),{data:a}=ee(),s=oe(),[u,d]=(0,N.useState)(`installed`),[f,m]=(0,N.useState)(null),[_,y]=(0,N.useState)(``),b=(0,N.useMemo)(()=>B(i?.providers??[]),[i?.providers]),x=r?.providers??{},S=(0,N.useMemo)(()=>{let e=_.trim().toLowerCase();return b.filter(e=>u!==`installed`||!!(x[e.name]?.enabled!==!1&&x[e.name]?.apiKeySet)).filter(t=>e?(x[t.name]?.displayName?.trim()||t.displayName||t.name).toLowerCase().includes(e)||t.name.toLowerCase().includes(e):!0)},[u,b,x,_]),C=(0,N.useMemo)(()=>f&&S.some(e=>e.name===f)?f:t?null:S[0]?.name??null,[S,t,f]);return!r||!i?(0,P.jsx)(`div`,{className:`p-8`,children:n(`providersLoading`)}):(0,P.jsxs)(o,{className:`pb-0 xl:flex xl:h-full xl:min-h-0 xl:flex-col`,children:[(0,P.jsx)(p,{title:n(`providersPageTitle`),description:n(`providersPageDescription`)}),(0,P.jsxs)(he,{className:`xl:min-h-0`,mobileView:t?C?`detail`:`list`:void 0,onMobileBack:()=>m(null),mobileListLabel:n(`providersPageTitle`),children:[(0,P.jsxs)(pe,{children:[(0,P.jsxs)(me,{className:`space-y-3 px-4 pb-3 pt-4`,children:[(0,P.jsx)(A,{tabs:[{id:`installed`,label:n(`providersTabConfigured`),count:b.filter(e=>x[e.name]?.enabled!==!1&&x[e.name]?.apiKeySet).length},{id:`all`,label:n(`providersTabAll`),count:b.length}],activeTab:u,onChange:d,className:`mb-0`}),(0,P.jsxs)(l,{type:`button`,variant:`outline`,className:`w-full justify-center`,onClick:async()=>{try{let e=await s.mutateAsync({data:{}});d(`all`),y(``),m(e.name)}catch{}},disabled:s.isPending,children:[(0,P.jsx)(g,{className:`mr-2 h-4 w-4`}),s.isPending?n(`saving`):n(`providerAddCustom`)]})]}),(0,P.jsx)(`div`,{className:`border-b border-gray-100 px-4 py-3`,children:(0,P.jsxs)(`div`,{className:`relative`,children:[(0,P.jsx)(h,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,P.jsx)(c,{value:_,onChange:e=>y(e.target.value),placeholder:n(`providersFilterPlaceholder`),className:`h-10 rounded-xl pl-9`})]})}),(0,P.jsxs)(_e,{className:`space-y-2 p-3`,children:[S.map(t=>{let r=x[t.name],i=r?.enabled!==!1,o=!!(i&&r?.apiKeySet),s=r?.displayName?.trim()||t.displayName||t.name,c=z(r?.apiBase||t.defaultApiBase||``)||fe(`providers.${t.name}`,a?.uiHints)?.help||n(`providersDefaultDescription`);return(0,P.jsx)(M,{onClick:()=>m(t.name),active:C===t.name,children:(0,P.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,P.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,P.jsx)(w,{name:t.name,src:t.logo?`/logos/${t.logo}`:null,className:e(`h-10 w-10 rounded-lg border`,o?`border-primary/30 bg-white`:`border-gray-200/70 bg-white`),imgClassName:`h-5 w-5 object-contain`,fallback:(0,P.jsx)(`span`,{className:`text-sm font-semibold uppercase text-gray-500`,children:t.name[0]})}),(0,P.jsxs)(`div`,{className:`min-w-0`,children:[(0,P.jsx)(`p`,{className:`truncate text-sm font-semibold text-gray-900`,children:s}),(0,P.jsx)(`p`,{className:`line-clamp-1 text-[11px] text-gray-500`,children:c})]})]}),(0,P.jsx)(v,{status:i?o?`ready`:`setup`:`inactive`,label:n(i?o?`statusReady`:`statusSetup`:`disabled`),className:`min-w-[56px] justify-center`})]})},t.name)}),S.length===0?(0,P.jsx)(j,{icon:le,title:n(`providersNoMatch`)}):null]})]}),(0,P.jsx)(Je,{providerName:C??void 0,onProviderDeleted:e=>{e===C&&m(null)}})]})]})}export{V as ProvidersList};
1
+ import{d as e,h as t,i as n,m as r,o as i,v as a}from"./react-B2X_ph0a.js";import{At as o,Lt as s,Mt as c,Nt as l,Xt as u,ft as d,jt as f,kt as p}from"./api-DruAcori.js";import{t as m}from"./createLucideIcon-Br1EFMEr.js";import{t as h}from"./search-CdhgFNwf.js";import{t as g}from"./plus-BcIC8dG1.js";import{t as _}from"./x-Chb07O-Y.js";import{$ as ee,Gt as v,J as y,K as b,Kt as x,Mt as S,Nt as C,Q as te,U as w,X as T,Y as E,Z as ne,at as re,ct as ie,dt as ae,et as oe,ht as se,jt as D,ln as ce,q as O,rn as le,rt as ue,ut as de,xt as k}from"./index-GVTiCf1s.js";import{t as A}from"./tabs-custom-BBXu1OGs.js";import{t as fe}from"./config-hints-CY1lg9IE.js";import{a as pe,c as me,i as he,n as ge,o as _e,r as j,s as ve,t as M}from"./config-split-page-BFh_Qixx.js";import{t as ye}from"./setting-row-8VkukJoH.js";var be=m(`CircleDotDashed`,[[`path`,{d:`M10.1 2.18a9.93 9.93 0 0 1 3.8 0`,key:`1qdqn0`}],[`path`,{d:`M17.6 3.71a9.95 9.95 0 0 1 2.69 2.7`,key:`1bq7p6`}],[`path`,{d:`M21.82 10.1a9.93 9.93 0 0 1 0 3.8`,key:`1rlaqf`}],[`path`,{d:`M20.29 17.6a9.95 9.95 0 0 1-2.7 2.69`,key:`1xk03u`}],[`path`,{d:`M13.9 21.82a9.94 9.94 0 0 1-3.8 0`,key:`l7re25`}],[`path`,{d:`M6.4 20.29a9.95 9.95 0 0 1-2.69-2.7`,key:`1v18p6`}],[`path`,{d:`M2.18 13.9a9.93 9.93 0 0 1 0-3.8`,key:`xdo6bj`}],[`path`,{d:`M3.71 6.4a9.95 9.95 0 0 1 2.7-2.69`,key:`1jjmaz`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),xe=m(`EyeOff`,[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`,key:`ct8e1f`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`,key:`151rxh`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`,key:`13bj9a`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),Se=m(`Eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),Ce=m(`Settings2`,[[`path`,{d:`M20 7h-9`,key:`3s1dr2`}],[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),N=a(t(),1),P=r();function we({isSet:t,className:n,value:r,onChange:i,placeholder:a,...o}){let[s,u]=(0,N.useState)(!1),[d,f]=(0,N.useState)(!1),p=typeof r==`string`&&r.length>0;return(0,P.jsxs)(`div`,{className:`relative`,children:[t&&!p&&!d?(0,P.jsx)(`div`,{onClick:()=>f(!0),className:e(`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`,n),children:`••••••••••••`}):(0,P.jsx)(c,{type:s?`text`:`password`,className:e(`pr-12`,n),value:r,onChange:i,onBlur:()=>{p||f(!1)},placeholder:a,autoFocus:d,...o}),(0,P.jsx)(`div`,{className:`absolute right-2 top-1/2 -translate-y-1/2 flex gap-1`,children:(t||p)&&(0,P.jsx)(l,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>u(!s),children:s?(0,P.jsx)(xe,{className:`h-4 w-4`}):(0,P.jsx)(Se,{className:`h-4 w-4`})})})]})}function Te({value:t,onChange:r,className:i}){let a=t?Object.entries(t):[],o=(e,t,n)=>{let i=[...a];i[e]=[t,n],r(Object.fromEntries(i))},s=()=>{r({...t,"":``})},u=e=>{let t=a.filter((t,n)=>n!==e);r(Object.fromEntries(t))};return(0,P.jsxs)(`div`,{className:e(`space-y-2`,i),children:[a.map(([e,t],r)=>(0,P.jsxs)(`div`,{className:`flex gap-2`,children:[(0,P.jsx)(c,{type:`text`,value:e,onChange:e=>o(r,e.target.value,t),placeholder:n(`headerName`),className:`flex-1`}),(0,P.jsx)(c,{type:`text`,value:t,onChange:t=>o(r,e,t.target.value),placeholder:n(`headerValue`),className:`flex-1`}),(0,P.jsx)(l,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>u(r),children:(0,P.jsx)(x,{className:`h-4 w-4 text-red-500`})})]},r)),(0,P.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,onClick:s,children:[(0,P.jsx)(g,{className:`h-4 w-4 mr-2`}),n(`add`)]})]})}function Ee(e){let{value:t,onChange:n,options:r}=e;return(0,P.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:r.map(e=>{let r=e.value===t;return(0,P.jsx)(`button`,{type:`button`,onClick:()=>n(e.value),"aria-pressed":r,className:`rounded-full border px-3 py-1.5 text-xs font-medium transition-colors ${r?`border-primary bg-primary text-white shadow-sm`:`border-gray-200 bg-white text-gray-700 hover:border-primary/40 hover:text-primary`}`,children:e.label},e.value)})})}function De(e){let{showAdvanced:t,onShowAdvancedChange:r,supportsWireApi:i,wireApiLabel:a,wireApi:o,onWireApiChange:s,shouldUseWireApiPills:c,wireApiSelectOptions:l,extraHeadersLabel:u,extraHeaders:d,onExtraHeadersChange:p}=e;return(0,P.jsxs)(`div`,{className:`border-t border-gray-100 pt-4`,children:[(0,P.jsxs)(`button`,{type:`button`,onClick:()=>r(!t),className:`flex w-full items-center justify-between text-sm text-gray-600 transition-colors hover:text-gray-900`,children:[(0,P.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,P.jsx)(Ce,{className:`h-3.5 w-3.5`}),n(`providerAdvancedSettings`)]}),(0,P.jsx)(ce,{className:`h-4 w-4 transition-transform ${t?`rotate-180`:``}`})]}),t?(0,P.jsxs)(`div`,{className:`mt-4 space-y-5`,children:[i?(0,P.jsxs)(`div`,{className:`space-y-2`,children:[(0,P.jsx)(f,{htmlFor:`wireApi`,className:`text-sm font-medium text-gray-900`,children:a}),c?(0,P.jsx)(Ee,{value:o,onChange:e=>s(e),options:l}):(0,P.jsxs)(b,{value:o,onValueChange:e=>s(e),children:[(0,P.jsx)(E,{className:`rounded-xl`,children:(0,P.jsx)(T,{})}),(0,P.jsx)(O,{children:l.map(e=>(0,P.jsx)(y,{value:e.value,children:e.label},e.value))})]})]}):null,(0,P.jsxs)(`div`,{className:`space-y-2`,children:[(0,P.jsx)(f,{className:`text-sm font-medium text-gray-900`,children:u}),(0,P.jsx)(Te,{value:d,onChange:p}),(0,P.jsx)(`p`,{className:`text-xs text-gray-500`,children:n(`providerExtraHeadersHelpShort`)})]})]}):null]})}function Oe(e){let{providerAuth:t,providerAuthNote:r,providerAuthMethodOptions:i,providerAuthMethodsCount:a,selectedAuthMethodHint:o,shouldUseAuthMethodPills:s,resolvedAuthMethodId:c,onAuthMethodChange:u,onStartProviderAuth:d,onImportProviderAuthFromCli:p,startPending:m,importPending:h,authSessionId:g,authStatusMessage:_}=e;return t?.kind===`device_code`?(0,P.jsxs)(`div`,{className:`space-y-2 rounded-xl border border-primary/20 bg-primary-50/50 p-3`,children:[(0,P.jsx)(f,{className:`text-sm font-medium text-gray-900`,children:t.displayName||n(`providerAuthSectionTitle`)}),r?(0,P.jsx)(`p`,{className:`text-xs text-gray-600`,children:r}):null,a>1?(0,P.jsxs)(`div`,{className:`space-y-2`,children:[(0,P.jsx)(f,{className:`text-xs font-medium text-gray-700`,children:n(`providerAuthMethodLabel`)}),s?(0,P.jsx)(Ee,{value:c,onChange:u,options:i}):(0,P.jsxs)(b,{value:c,onValueChange:u,children:[(0,P.jsx)(E,{className:`h-8 rounded-lg bg-white`,children:(0,P.jsx)(T,{placeholder:n(`providerAuthMethodPlaceholder`)})}),(0,P.jsx)(O,{children:i.map(e=>(0,P.jsx)(y,{value:e.value,children:e.label},e.value))})]}),o?(0,P.jsx)(`p`,{className:`text-xs text-gray-500`,children:o}):null]}):null,(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(l,{type:`button`,variant:`outline`,size:`sm`,onClick:d,disabled:m||!!g,children:n(m?`providerAuthStarting`:g?`providerAuthAuthorizing`:`providerAuthAuthorizeInBrowser`)}),t.supportsCliImport?(0,P.jsx)(l,{type:`button`,variant:`outline`,size:`sm`,onClick:p,disabled:h,children:n(h?`providerAuthImporting`:`providerAuthImportFromCli`)}):null,g?(0,P.jsxs)(`span`,{className:`text-xs text-gray-500`,children:[n(`providerAuthSessionLabel`),`: `,g.slice(0,8),`…`]}):null]}),_?(0,P.jsx)(`p`,{className:`text-xs text-gray-600`,children:_}):null]}):null}function ke(e){let{enabled:t,onChange:r}=e;return(0,P.jsx)(ye,{tone:`muted`,title:n(`enabled`),control:(0,P.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,P.jsx)(`span`,{className:`text-xs text-gray-500`,children:n(t?`enabled`:`disabled`)}),(0,P.jsx)(d,{checked:t,onCheckedChange:r})]})})}var Ae={enabled:!0,displayName:``,apiKeySet:!1,apiKeyMasked:void 0,apiBase:null,extraHeaders:null,wireApi:null,models:[],modelConfig:{}},je=[`off`,`minimal`,`low`,`medium`,`high`,`adaptive`,`xhigh`],F=new Set(je);function I(e){if(!e)return null;let t=Object.entries(e).map(([e,t])=>[e.trim(),t]).filter(([e])=>e.length>0);return t.length===0?null:Object.fromEntries(t)}function Me(e,t){let n=I(e),r=I(t);if(n===null&&r===null)return!0;if(!n||!r)return!1;let i=Object.entries(n).sort(([e],[t])=>e.localeCompare(t)),a=Object.entries(r).sort(([e],[t])=>e.localeCompare(t));return i.length===a.length?i.every(([e,t],n)=>e===a[n][0]&&t===a[n][1]):!1}function Ne(e){if(!e||e.length===0)return[];let t=new Set;for(let n of e){let e=n.trim();e&&t.add(e)}return[...t]}function Pe(e,t){let n=e.trim();if(!n||!t.trim())return n;let r=`${t.trim()}/`;return n.startsWith(r)?n.slice(r.length):n}function L(e,t){let n=e.trim();if(!n)return``;for(let e of t){let t=e.trim();t&&(n=Pe(n,t))}return n.trim()}function Fe(e,t){return e.length===t.length?e.every((e,n)=>e===t[n]):!1}function Ie(e,t){return t}function Le(e,t){return e}function Re(e,t,n){t!==n&&(e.enabled=t)}function R(e){if(typeof e!=`string`)return null;let t=e.trim().toLowerCase();return t&&F.has(t)?t:null}function ze(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){let e=R(n);!e||t.includes(e)||t.push(e)}return t}function Be(e,t){if(!e)return{};let n={};for(let[r,i]of Object.entries(e)){let e=L(r,t);if(!e)continue;let a={},o=ze(i?.thinking?.supported);if(o.length>0){let e=R(i?.thinking?.default);a.thinking=e&&o.includes(e)?{supported:o,default:e}:{supported:o}}i?.vision===!0&&(a.vision=!0),(a.thinking||a.vision===!0)&&(n[e]=a)}return n}function Ve(e,t){let n=new Set(t.map(e=>e.trim()).filter(Boolean)),r={};for(let[t,i]of Object.entries(e)){if(!n.has(t))continue;let e={},a=ze(i.thinking?.supported);if(a.length>0){let t=R(i.thinking?.default);e.thinking=t&&a.includes(t)?{supported:a,default:t}:{supported:a}}i.vision===!0&&(e.vision=!0),(e.thinking||e.vision===!0)&&(r[t]=e)}return r}function He(e,t){let n=Object.keys(e).sort(),r=Object.keys(t).sort();if(n.length!==r.length)return!1;for(let i=0;i<n.length;i+=1){let a=n[i];if(a!==r[i])return!1;let o=e[a],s=t[a];if(!o||!s||!Fe([...o.thinking?.supported??[]].sort(),[...s.thinking?.supported??[]].sort())||(o.thinking?.default??null)!==(s.thinking?.default??null)||(o.vision??!1)!==(s.vision??!1))return!1}return!0}function Ue(e){return n(e===`off`?`chatThinkingLevelOff`:e===`minimal`?`chatThinkingLevelMinimal`:e===`low`?`chatThinkingLevelLow`:e===`medium`?`chatThinkingLevelMedium`:e===`high`?`chatThinkingLevelHigh`:e===`adaptive`?`chatThinkingLevelAdaptive`:`chatThinkingLevelXhigh`)}function We(e){let{providerName:t,methods:n,defaultMethodId:r,language:i}=e;if(n.length===0)return``;let a=new Map;for(let e of n){let t=e.id.trim();t&&a.set(t.toLowerCase(),t)}let o=(...e)=>{for(let t of e){let e=a.get(t.toLowerCase());if(e)return e}},s=r?.trim();if(t===`minimax-portal`){if(i===`zh`)return o(`cn`,`china-mainland`)??o(s??``)??n[0]?.id??``;if(i===`en`)return o(`global`,`intl`,`international`)??o(s??``)??n[0]?.id??``}if(s){let e=o(s);if(e)return e}return i===`zh`?o(`cn`)??n[0]?.id??``:i===`en`?o(`global`)??n[0]?.id??``:n[0]?.id??``}function Ge(e){return e.required&&e.hasDefault&&e.optionCount>1&&e.optionCount<=3}function Ke(e){let{models:t,modelConfig:r,modelDraft:i,showModelInput:a,onModelDraftChange:o,onShowModelInputChange:s,onAddModel:u,onRemoveModel:p,onToggleModelThinkingLevel:m,onSetModelThinkingDefault:h,onSetModelVision:ee,thinkingLevels:v,formatThinkingLevelLabel:x}=e;return(0,P.jsxs)(`div`,{className:`space-y-2`,children:[(0,P.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,P.jsx)(f,{className:`text-sm font-medium text-gray-900`,children:n(`providerModelsTitle`)}),a?null:(0,P.jsxs)(`button`,{type:`button`,onClick:()=>s(!0),className:`flex items-center gap-1 text-xs font-medium text-primary hover:text-primary/80`,children:[(0,P.jsx)(g,{className:`h-3 w-3`}),n(`providerAddModel`)]})]}),a?(0,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,P.jsx)(c,{value:i,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),u()),e.key===`Escape`&&(s(!1),o(``))},placeholder:n(`providerModelInputPlaceholder`),className:`flex-1 rounded-xl`,autoFocus:!0}),(0,P.jsx)(l,{type:`button`,size:`sm`,onClick:u,disabled:i.trim().length===0,children:n(`add`)}),(0,P.jsx)(l,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>{s(!1),o(``)},children:(0,P.jsx)(_,{className:`h-4 w-4`})})]}):null,t.length===0?(0,P.jsxs)(`div`,{className:`rounded-xl border border-dashed border-gray-200 bg-gray-50 px-4 py-6 text-center`,children:[(0,P.jsx)(`p`,{className:`text-sm text-gray-500`,children:n(`providerModelsEmptyShort`)}),a?null:(0,P.jsx)(`button`,{type:`button`,onClick:()=>s(!0),className:`mt-2 text-sm font-medium text-primary hover:text-primary/80`,children:n(`providerAddFirstModel`)})]}):(0,P.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:t.map(e=>{let t=r[e],i=t?.thinking,a=i?.supported??[],o=i?.default??null,s=t?.vision===!0;return(0,P.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:[(0,P.jsx)(`span`,{className:`max-w-[140px] truncate text-sm text-gray-800 sm:max-w-[220px]`,children:e}),(0,P.jsxs)(D,{children:[(0,P.jsx)(C,{asChild:!0,children:(0,P.jsx)(`button`,{type:`button`,className:`inline-flex h-5 w-5 items-center justify-center rounded-full text-gray-400 opacity-100 transition-opacity hover:bg-gray-100 hover:text-gray-600 md:opacity-0 md:group-hover:opacity-100 md:group-focus-within:opacity-100`,"aria-label":n(`providerModelThinkingTitle`),title:n(`providerModelThinkingTitle`),children:(0,P.jsx)(Ce,{className:`h-3 w-3`})})}),(0,P.jsxs)(S,{className:`w-80 space-y-3`,children:[(0,P.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-lg border border-gray-100 bg-gray-50 px-3 py-2`,children:[(0,P.jsxs)(`div`,{className:`min-w-0`,children:[(0,P.jsx)(`p`,{className:`text-xs font-semibold text-gray-800`,children:n(`providerModelVisionTitle`)}),(0,P.jsx)(`p`,{className:`text-xs text-gray-500`,children:n(`providerModelVisionHint`)})]}),(0,P.jsx)(d,{checked:s,onCheckedChange:t=>ee(e,t)})]}),(0,P.jsxs)(`div`,{className:`space-y-1`,children:[(0,P.jsx)(`p`,{className:`text-xs font-semibold text-gray-800`,children:n(`providerModelThinkingTitle`)}),(0,P.jsx)(`p`,{className:`text-xs text-gray-500`,children:n(`providerModelThinkingHint`)})]}),(0,P.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:v.map(t=>(0,P.jsx)(`button`,{type:`button`,onClick:()=>m(e,t),className:`rounded-full border px-2.5 py-1 text-xs font-medium transition-colors ${a.includes(t)?`border-primary bg-primary text-white`:`border-gray-200 bg-white text-gray-600 hover:border-primary/40 hover:text-primary`}`,children:x(t)},t))}),(0,P.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,P.jsx)(f,{className:`text-xs font-medium text-gray-700`,children:n(`providerModelThinkingDefault`)}),(0,P.jsxs)(b,{value:o??`__none__`,onValueChange:t=>h(e,t===`__none__`?null:t),disabled:a.length===0,children:[(0,P.jsx)(E,{className:`h-8 rounded-lg bg-white text-xs`,children:(0,P.jsx)(T,{})}),(0,P.jsxs)(O,{children:[(0,P.jsx)(y,{value:`__none__`,children:n(`providerModelThinkingDefaultNone`)}),a.map(e=>(0,P.jsx)(y,{value:e,children:x(e)},e))]})]}),a.length===0?(0,P.jsx)(`p`,{className:`text-xs text-gray-500`,children:n(`providerModelThinkingNoSupported`)}):null]})]})]}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>p(e),className:`inline-flex h-5 w-5 items-center justify-center rounded-full text-gray-400 opacity-100 transition-opacity hover:bg-gray-100 hover:text-gray-600 md:opacity-0 md:group-hover:opacity-100 md:group-focus-within:opacity-100`,"aria-label":n(`remove`),children:(0,P.jsx)(_,{className:`h-3 w-3`})})]},e)})})]})}function qe(e){return e.enabled?(0,P.jsx)(v,{status:e.apiKeySet?`ready`:`setup`,label:e.apiKeySet?n(`statusReady`):n(`statusSetup`),className:e.className}):(0,P.jsx)(v,{status:`inactive`,label:n(`disabled`),className:e.className})}function Je({providerName:e,onProviderDeleted:t}){let r=u(),{data:a}=ne(),{data:o}=te(),{data:d}=ee(),p=se(),m=ue(),h=ae(),g=de(),_=ie(),v=re(),[y,b]=(0,N.useState)(``),[S,C]=(0,N.useState)(!0),[w,T]=(0,N.useState)(``),[E,oe]=(0,N.useState)(null),[D,ce]=(0,N.useState)(`auto`),[O,le]=(0,N.useState)([]),[k,A]=(0,N.useState)({}),[he,j]=(0,N.useState)(``),[M,ye]=(0,N.useState)(``),[xe,Se]=(0,N.useState)(!1),[Ce,Te]=(0,N.useState)(!1),[Ee,F]=(0,N.useState)(null),[Pe,R]=(0,N.useState)(``),[ze,Je]=(0,N.useState)(``),z=(0,N.useRef)(null),B=o?.providers.find(t=>t.name===e),V=(e?a?.providers[e]:null)??Ae,Ye=d?.uiHints,H=!!B?.isCustom,Xe=e?fe(`providers.${e}.apiKey`,Ye):void 0,Ze=e?fe(`providers.${e}.apiBase`,Ye):void 0,Qe=e?fe(`providers.${e}.extraHeaders`,Ye):void 0,$e=e?fe(`providers.${e}.wireApi`,Ye):void 0,et=B?.displayName||e||``,U=(V.displayName||``).trim()||et,W=V.enabled!==!1,tt=M.trim()||U||e||n(`providersSelectPlaceholder`),G=(0,N.useMemo)(()=>Ne([B?.modelPrefix||e||``,e||``]),[e,B?.modelPrefix]),nt=B?.defaultApiBase||``,rt=V.apiBase||nt,it=I(V.extraHeaders||null),at=V.wireApi||B?.defaultWireApi||`auto`,ot=(0,N.useMemo)(()=>Ne((B?.defaultModels??[]).map(e=>L(e,G))),[B?.defaultModels,G]),st=(0,N.useMemo)(()=>Ne((V.models??[]).map(e=>L(e,G))),[V.models,G]),K=(0,N.useMemo)(()=>Ie(ot,st),[ot,st]),q=(0,N.useMemo)(()=>Ve(Be(V.modelConfig??B?.modelConfig,G),K),[K,G,B?.modelConfig,V.modelConfig]),J=i(),ct=B?.apiBaseHelp?.[J]||B?.apiBaseHelp?.en||Ze?.help||n(`providerApiBaseHelp`),Y=B?.auth,X=Y?.methods??[],Z=!!B?.supportsWireApi||H,lt=(0,N.useMemo)(()=>X.map(e=>({value:e.id,label:e.label?.[J]||e.label?.en||e.id})),[X,J]),ut=(0,N.useMemo)(()=>We({providerName:e,methods:X,defaultMethodId:Y?.defaultMethodId,language:J}),[e,Y?.defaultMethodId,X,J]),Q=(0,N.useMemo)(()=>{if(!X.length)return``;let e=ze.trim();return e&&X.some(t=>t.id===e)?e:ut||X[0]?.id||``},[ze,ut,X]),dt=(0,N.useMemo)(()=>X.find(e=>e.id===Q),[X,Q]),ft=Ge({required:Y?.kind===`device_code`,hasDefault:!!Y?.defaultMethodId?.trim(),optionCount:X.length}),pt=(B?.wireApiOptions||[`auto`,`chat`,`responses`]).map(e=>({value:e,label:n(e===`chat`?`wireApiChat`:e===`responses`?`wireApiResponses`:`wireApiAuto`)})),mt=Ge({required:Z,hasDefault:typeof B?.defaultWireApi==`string`&&B.defaultWireApi.length>0,optionCount:pt.length}),$=(0,N.useCallback)(()=>{z.current!==null&&(window.clearTimeout(z.current),z.current=null)},[]),ht=(0,N.useCallback)((t,i)=>{$(),z.current=window.setTimeout(()=>{(async()=>{if(e)try{let a=await _.mutateAsync({provider:e,data:{sessionId:t}});if(a.status===`pending`){R(n(`providerAuthWaitingBrowser`)),ht(t,a.nextPollMs??i);return}if(a.status===`authorized`){F(null),$(),R(n(`providerAuthCompleted`)),s.success(n(`providerAuthCompleted`)),r.invalidateQueries({queryKey:[`config`]}),r.invalidateQueries({queryKey:[`config-meta`]});return}F(null),$(),R(a.message||`Authorization ${a.status}.`),s.error(a.message||`Authorization ${a.status}.`)}catch(e){F(null),$();let t=e instanceof Error?e.message:String(e);R(t),s.error(`Authorization failed: ${t}`)}})()},Math.max(1e3,i))},[$,_,e,r]);(0,N.useEffect)(()=>{if(!e){b(``),C(!0),T(``),oe(null),ce(`auto`),le([]),A({}),j(``),ye(``),F(null),R(``),Je(``),$();return}b(``),C(W),T(rt),oe(V.extraHeaders||null),ce(at),le(K),A(q),j(``),ye(U),F(null),R(``),Je(ut),$()},[e,rt,W,V.extraHeaders,at,K,q,U,ut,$]),(0,N.useEffect)(()=>()=>$(),[$]),(0,N.useEffect)(()=>A(e=>Ve(e,O)),[O]);let gt=(0,N.useMemo)(()=>e?y.trim().length>0||S!==W||w.trim()!==rt.trim()||!Me(E,it)||Z&&D!==at||!Fe(O,K)||!He(k,q)||H&&M.trim()!==U:!1,[e,y,S,W,w,rt,E,it,Z,D,at,O,K,k,q,H,M,U]);return!e||!B?(0,P.jsx)(ge,{children:(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`h3`,{className:`text-base font-semibold text-gray-900`,children:n(`providersSelectTitle`)}),(0,P.jsx)(`p`,{className:`mt-2 text-sm text-gray-500`,children:n(`providersSelectDescription`)})]})}):(0,P.jsxs)(pe,{children:[(0,P.jsx)(me,{className:`px-6 py-4`,children:(0,P.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,P.jsx)(`h3`,{className:`truncate text-lg font-semibold text-gray-900`,children:tt}),(0,P.jsxs)(`div`,{className:`flex items-center gap-3`,children:[H&&(0,P.jsx)(`button`,{type:`button`,onClick:async()=>{if(!(!e||!H)&&window.confirm(n(`providerDeleteConfirm`)))try{await m.mutateAsync({provider:e}),t?.(e)}catch{}},disabled:m.isPending,className:`text-gray-400 transition-colors hover:text-red-500`,title:n(`providerDelete`),children:(0,P.jsx)(x,{className:`h-4 w-4`})}),(0,P.jsx)(qe,{enabled:W,apiKeySet:V.apiKeySet})]})]})}),(0,P.jsxs)(`form`,{onSubmit:t=>{if(t.preventDefault(),!e)return;let n={},r=y.trim(),i=w.trim(),a=I(E),o=M.trim();H&&o!==U&&(n.displayName=o.length>0?o:null),r.length>0&&(n.apiKey=r),Re(n,S,W),i!==rt.trim()&&(n.apiBase=i.length>0&&i!==nt?i:null),Me(a,it)||(n.extraHeaders=a),Z&&D!==at&&(n.wireApi=D),Fe(O,K)||(n.models=Le(O,ot)),He(k,q)||(n.modelConfig=Ve(k,O)),p.mutate({provider:e,data:n})},className:`flex min-h-0 flex-1 flex-col`,children:[(0,P.jsxs)(_e,{className:`space-y-5 px-6 py-5`,children:[(0,P.jsx)(ke,{enabled:S,onChange:C}),H&&(0,P.jsxs)(`div`,{className:`space-y-2`,children:[(0,P.jsx)(f,{htmlFor:`providerDisplayName`,className:`text-sm font-medium text-gray-900`,children:n(`providerDisplayName`)}),(0,P.jsx)(c,{id:`providerDisplayName`,type:`text`,value:M,onChange:e=>ye(e.target.value),placeholder:et||n(`providerDisplayNamePlaceholder`),className:`rounded-xl`}),(0,P.jsx)(`p`,{className:`text-xs text-gray-500`,children:n(`providerDisplayNameHelpShort`)})]}),(0,P.jsxs)(`div`,{className:`space-y-2`,children:[(0,P.jsx)(f,{htmlFor:`apiKey`,className:`text-sm font-medium text-gray-900`,children:Xe?.label??n(`apiKey`)}),(0,P.jsx)(we,{id:`apiKey`,value:y,isSet:V.apiKeySet,onChange:e=>b(e.target.value),placeholder:Xe?.placeholder??n(`enterApiKey`),className:`rounded-xl`}),(0,P.jsx)(`p`,{className:`text-xs text-gray-500`,children:n(`leaveBlankToKeepUnchanged`)})]}),(0,P.jsx)(Oe,{providerAuth:Y,providerAuthNote:Y?.note?.[J]||Y?.note?.en||Y?.displayName||``,providerAuthMethodOptions:lt,providerAuthMethodsCount:X.length,selectedAuthMethodHint:dt?.hint?.[J]||dt?.hint?.en||``,shouldUseAuthMethodPills:ft,resolvedAuthMethodId:Q,onAuthMethodChange:Je,onStartProviderAuth:async()=>{if(!(!e||Y?.kind!==`device_code`))try{R(``);let t=await g.mutateAsync({provider:e,data:Q?{methodId:Q}:{}});if(!t.sessionId||!t.verificationUri)throw Error(n(`providerAuthStartFailed`));F(t.sessionId),R(`${n(`providerAuthOpenPrompt`)}${t.userCode}${n(`providerAuthOpenPromptSuffix`)}`),window.open(t.verificationUri,`_blank`,`noopener,noreferrer`),ht(t.sessionId,t.intervalMs)}catch(e){let t=e instanceof Error?e.message:String(e);F(null),$(),R(t),s.error(`${n(`providerAuthStartFailed`)}: ${t}`)}},onImportProviderAuthFromCli:async()=>{if(!(!e||Y?.kind!==`device_code`))try{$(),F(null);let t=await v.mutateAsync({provider:e});R(`${n(`providerAuthImportStatusPrefix`)}${t.expiresAt?` (expires: ${t.expiresAt})`:``}`),s.success(n(`providerAuthImportSuccess`)),r.invalidateQueries({queryKey:[`config`]}),r.invalidateQueries({queryKey:[`config-meta`]})}catch(e){let t=e instanceof Error?e.message:String(e);R(t),s.error(`${n(`providerAuthImportFailed`)}: ${t}`)}},startPending:g.isPending,importPending:v.isPending,authSessionId:Ee,authStatusMessage:Pe}),(0,P.jsxs)(`div`,{className:`space-y-2`,children:[(0,P.jsx)(f,{htmlFor:`apiBase`,className:`text-sm font-medium text-gray-900`,children:Ze?.label??n(`apiBase`)}),(0,P.jsx)(c,{id:`apiBase`,type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:nt||Ze?.placeholder||`https://api.example.com`,className:`rounded-xl`}),(0,P.jsx)(`p`,{className:`text-xs text-gray-500`,children:ct})]}),(0,P.jsx)(Ke,{models:O,modelConfig:k,modelDraft:he,showModelInput:Ce,onModelDraftChange:j,onShowModelInputChange:Te,onAddModel:()=>{let e=L(he,G);if(e){if(O.includes(e)){j(``);return}le(t=>[...t,e]),j(``)}},onRemoveModel:e=>{le(t=>t.filter(t=>t!==e)),A(t=>{let n={...t};return delete n[e],n})},onToggleModelThinkingLevel:(e,t)=>{A(n=>{let r=n[e],i=r?.thinking?.supported??[],a=i.includes(t)?i.filter(e=>e!==t):je.filter(e=>e===t||i.includes(e)),o=r?.thinking?.default&&a.includes(r.thinking.default)?r.thinking.default:void 0,s={...r,thinking:a.length>0?o?{supported:a,default:o}:{supported:a}:void 0},c={...n};return s.thinking||s.vision===!0?c[e]=s:delete c[e],c})},onSetModelThinkingDefault:(e,t)=>{A(n=>{let r=n[e],i=r?.thinking;return!i||i.supported.length===0||t&&!i.supported.includes(t)?n:{...n,[e]:{...r,thinking:t?{supported:i.supported,default:t}:{supported:i.supported}}}})},onSetModelVision:(e,t)=>{A(n=>{let r={...n[e],vision:t?!0:void 0},i={...n};return r.thinking||r.vision===!0?i[e]=r:delete i[e],i})},thinkingLevels:je,formatThinkingLevelLabel:Ue}),(0,P.jsx)(De,{showAdvanced:xe,onShowAdvancedChange:Se,supportsWireApi:Z,wireApiLabel:$e?.label??n(`wireApi`),wireApi:D,onWireApiChange:ce,shouldUseWireApiPills:mt,wireApiSelectOptions:pt,extraHeadersLabel:Qe?.label??n(`extraHeaders`),extraHeaders:E,onExtraHeadersChange:oe})]}),(0,P.jsxs)(ve,{className:`flex items-center justify-between px-6 py-4`,children:[(0,P.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,onClick:async()=>{if(!e)return;let t=L(O.find(e=>e.trim().length>0)??``,G),r={apiBase:w.trim(),extraHeaders:I(E),model:t||null};y.trim().length>0&&(r.apiKey=y.trim()),Z&&(r.wireApi=D);try{let t=await h.mutateAsync({provider:e,data:r});if(t.success){s.success(`${n(`providerTestConnectionSuccess`)} (${t.latencyMs}ms)`);return}let i=[`provider=${t.provider}`,`latency=${t.latencyMs}ms`];t.model&&i.push(`model=${t.model}`),s.error(`${n(`providerTestConnectionFailed`)}: ${t.message} | ${i.join(` | `)}`)}catch(e){let t=e instanceof Error?e.message:String(e);s.error(`${n(`providerTestConnectionFailed`)}: ${t}`)}},disabled:h.isPending,children:[(0,P.jsx)(be,{className:`mr-1.5 h-4 w-4`}),h.isPending?n(`providerTestingConnection`):n(`providerTestConnection`)]}),(0,P.jsx)(l,{type:`submit`,disabled:p.isPending||!gt,children:p.isPending?n(`saving`):n(gt?`save`:`unchanged`)})]})]})]})}function z(e){if(!e)return null;try{let t=new URL(e);return`${t.host}${t.pathname&&t.pathname!==`/`?t.pathname:``}`}catch{return e.replace(/^https?:\/\//,``)}}function B(e){return e.map((e,t)=>({provider:e,index:t})).sort((e,t)=>{let n=e.provider.name===`nextclaw`?1:0,r=t.provider.name===`nextclaw`?1:0;return n===r?e.index-t.index:n-r}).map(({provider:e})=>e)}function V(){let{isMobile:t}=k(),{data:r}=ne(),{data:i}=te(),{data:a}=ee(),s=oe(),[u,d]=(0,N.useState)(`installed`),[f,m]=(0,N.useState)(null),[_,y]=(0,N.useState)(``),b=(0,N.useMemo)(()=>B(i?.providers??[]),[i?.providers]),x=r?.providers??{},S=(0,N.useMemo)(()=>{let e=_.trim().toLowerCase();return b.filter(e=>u!==`installed`||!!(x[e.name]?.enabled!==!1&&x[e.name]?.apiKeySet)).filter(t=>e?(x[t.name]?.displayName?.trim()||t.displayName||t.name).toLowerCase().includes(e)||t.name.toLowerCase().includes(e):!0)},[u,b,x,_]),C=(0,N.useMemo)(()=>f&&S.some(e=>e.name===f)?f:t?null:S[0]?.name??null,[S,t,f]);return!r||!i?(0,P.jsx)(`div`,{className:`p-8`,children:n(`providersLoading`)}):(0,P.jsxs)(o,{className:`pb-0 xl:flex xl:h-full xl:min-h-0 xl:flex-col`,children:[(0,P.jsx)(p,{title:n(`providersPageTitle`),description:n(`providersPageDescription`)}),(0,P.jsxs)(he,{className:`xl:min-h-0`,mobileView:t?C?`detail`:`list`:void 0,onMobileBack:()=>m(null),mobileListLabel:n(`providersPageTitle`),children:[(0,P.jsxs)(pe,{children:[(0,P.jsxs)(me,{className:`space-y-3 px-4 pb-3 pt-4`,children:[(0,P.jsx)(A,{tabs:[{id:`installed`,label:n(`providersTabConfigured`),count:b.filter(e=>x[e.name]?.enabled!==!1&&x[e.name]?.apiKeySet).length},{id:`all`,label:n(`providersTabAll`),count:b.length}],activeTab:u,onChange:d,className:`mb-0`}),(0,P.jsxs)(l,{type:`button`,variant:`outline`,className:`w-full justify-center`,onClick:async()=>{try{let e=await s.mutateAsync({data:{}});d(`all`),y(``),m(e.name)}catch{}},disabled:s.isPending,children:[(0,P.jsx)(g,{className:`mr-2 h-4 w-4`}),s.isPending?n(`saving`):n(`providerAddCustom`)]})]}),(0,P.jsx)(`div`,{className:`border-b border-gray-100 px-4 py-3`,children:(0,P.jsxs)(`div`,{className:`relative`,children:[(0,P.jsx)(h,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,P.jsx)(c,{value:_,onChange:e=>y(e.target.value),placeholder:n(`providersFilterPlaceholder`),className:`h-10 rounded-xl pl-9`})]})}),(0,P.jsxs)(_e,{className:`space-y-2 p-3`,children:[S.map(t=>{let r=x[t.name],i=r?.enabled!==!1,o=!!(i&&r?.apiKeySet),s=r?.displayName?.trim()||t.displayName||t.name,c=z(r?.apiBase||t.defaultApiBase||``)||fe(`providers.${t.name}`,a?.uiHints)?.help||n(`providersDefaultDescription`);return(0,P.jsx)(M,{onClick:()=>m(t.name),active:C===t.name,children:(0,P.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,P.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,P.jsx)(w,{name:t.name,src:t.logo?`/logos/${t.logo}`:null,className:e(`h-10 w-10 rounded-lg border`,o?`border-primary/30 bg-white`:`border-gray-200/70 bg-white`),imgClassName:`h-5 w-5 object-contain`,fallback:(0,P.jsx)(`span`,{className:`text-sm font-semibold uppercase text-gray-500`,children:t.name[0]})}),(0,P.jsxs)(`div`,{className:`min-w-0`,children:[(0,P.jsx)(`p`,{className:`truncate text-sm font-semibold text-gray-900`,children:s}),(0,P.jsx)(`p`,{className:`line-clamp-1 text-[11px] text-gray-500`,children:c})]})]}),(0,P.jsx)(v,{status:i?o?`ready`:`setup`:`inactive`,label:n(i?o?`statusReady`:`statusSetup`:`disabled`),className:`min-w-[56px] justify-center`})]})},t.name)}),S.length===0?(0,P.jsx)(j,{icon:le,title:n(`providersNoMatch`)}):null]})]}),(0,P.jsx)(Je,{providerName:C??void 0,onProviderDeleted:e=>{e===C&&m(null)}})]})]})}export{V as ProvidersList};
@@ -0,0 +1 @@
1
+ import{Ut as e}from"./index-GVTiCf1s.js";export{e as RemoteAccessPage};
@@ -1 +1 @@
1
- import{h as e,i as t,m as n,v as r}from"./react-B2X_ph0a.js";import{At as i,Dt as a,Et as o,Lt as s,Mt as c,Nt as l,Ot as u,Tt as d,_t as f,bt as p,ft as m,ht as h,kt as g,wt as _,yt as v}from"./api-DruAcori.js";import{n as y}from"./confirm-dialog-B0TP-vPd.js";import{t as b}from"./play-CqNi0u02.js";import{t as x}from"./plus-BcIC8dG1.js";import{t as S}from"./save-D10M5vQg.js";import{G as ee,J as C,K as w,Kt as T,X as E,Y as D,Z as O,Zt as te,bt as k,gt as ne,nn as A,q as j,qt as M,yt as N}from"./index-D2H2CKYR.js";import{t as P}from"./setting-row-8VkukJoH.js";var F=r(e(),1),I=n(),L={healthy:`runtimeControlHealthy`,"starting-service":`runtimeControlStartingService`,"restarting-service":`runtimeControlRestartingService`,"stopping-service":`runtimeControlStoppingService`,"restarting-app":`runtimeControlRestartingApp`,recovering:`runtimeControlRecovering`,failed:`runtimeControlFailed`},R={running:`runtimeControlServiceRunning`,stopped:`runtimeControlServiceStopped`,starting:`runtimeControlServiceStarting`,stopping:`runtimeControlServiceStopping`,restarting:`runtimeControlServiceRestarting`},z={"desktop-embedded":`runtimeControlEnvironmentDesktop`,"managed-local-service":`runtimeControlEnvironmentManagedService`,"self-hosted-web":`runtimeControlEnvironmentSelfHosted`,"shared-web":`runtimeControlEnvironmentSharedWeb`};function B(e){return t(L[e]??`runtimeControlUnavailable`)}function V(e){return t(R[e]??`runtimeControlServiceUnknown`)}function H(e){return t(z[e.environment])}function U(e,t){return t===`start-service`?e?.canStartService:t===`stop-service`?e?.canStopService:e?.canRestartService}function W(e){return e?[{action:`start-service`,capability:e.canStartService,label:t(`runtimeControlStartService`),icon:`play`},{action:`restart-service`,capability:e.canRestartService,label:t(`runtimeControlRestartService`),icon:`rotate`},{action:`stop-service`,capability:e.canStopService,label:t(`runtimeControlStopService`),icon:`square`,variant:`destructive`},{action:`restart-app`,capability:e.canRestartApp,label:t(`runtimeControlRestartApp`),icon:`rotate`,variant:`secondary`}].filter(e=>e.capability.available||!!e.capability.reasonIfUnavailable):[]}function G(e){let{busy:t,icon:n}=e;return t?(0,I.jsx)(A,{className:`mr-2 h-4 w-4 animate-spin`}):n===`play`?(0,I.jsx)(b,{className:`mr-2 h-4 w-4`}):n===`square`?(0,I.jsx)(M,{className:`mr-2 h-4 w-4`}):(0,I.jsx)(te,{className:`mr-2 h-4 w-4`})}function K(){let{busy:e,busyAction:n,controlView:r,errorMessage:i,pendingRestart:c,visibleLifecycle:f,visibleMessage:m,visibleServiceState:g}=h(),y=W(r??void 0),b=async e=>{let n=U(r,e);if(!n?.available){s.error(p(n?.reasonIfUnavailable)??t(`runtimeControlLoadFailed`));return}if(!(e===`stop-service`&&n.requiresConfirmation&&!window.confirm(t(`runtimeControlStopServiceConfirm`))))try{let t=await v.runRuntimeControlAction(e);s.success(p(t.message)??t.message)}catch(e){let n=e instanceof Error?e.message:t(`runtimeControlActionFailed`);s.error(`${t(`runtimeControlActionFailed`)}: ${n}`)}},x=async()=>{if(!r?.canRestartApp.available){s.error(p(r?.canRestartApp.reasonIfUnavailable)??t(`runtimeRestartAppUnavailable`));return}if(window.confirm(t(`runtimeControlRestartAppConfirm`)))try{let e=await v.runRuntimeControlAction(`restart-app`);s.success(p(e.message)??e.message)}catch(e){let n=e instanceof Error?e.message:t(`runtimeControlActionFailed`);s.error(`${t(`runtimeControlActionFailed`)}: ${n}`)}};return(0,I.jsxs)(_,{children:[(0,I.jsxs)(a,{children:[(0,I.jsx)(u,{children:t(`runtimeControlTitle`)}),(0,I.jsx)(o,{children:t(`runtimeControlDescription`)})]}),(0,I.jsxs)(d,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-3 rounded-xl border border-gray-200 bg-gray-50 p-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1 md:flex-row md:items-center md:justify-between`,children:[(0,I.jsx)(`div`,{className:`text-sm font-medium text-gray-900`,children:V(g)}),(0,I.jsx)(`div`,{className:`text-xs text-gray-500`,children:r?H(r):t(`runtimeControlLoading`)})]}),(0,I.jsx)(`p`,{className:`text-sm text-gray-600`,children:m}),(0,I.jsx)(`div`,{className:`text-xs text-gray-500`,children:B(f)}),r?.managementHint?(0,I.jsx)(`p`,{className:`text-xs text-gray-500`,children:p(r.managementHint)}):null,i&&!e?(0,I.jsx)(`p`,{className:`text-sm text-amber-700`,children:i}):null]}),c?(0,I.jsxs)(`div`,{className:`space-y-3 rounded-xl border border-amber-200 bg-amber-50 p-4`,children:[(0,I.jsx)(`div`,{className:`text-sm font-medium text-amber-900`,children:t(`runtimeControlPendingRestartTitle`)}),(0,I.jsx)(`p`,{className:`text-sm text-amber-800`,children:t(`runtimeControlPendingRestartDescription`)}),c.changedPaths.length>0?(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-[0.08em] text-amber-700`,children:t(`runtimeControlPendingRestartPaths`)}),(0,I.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:c.changedPaths.map(e=>(0,I.jsx)(`span`,{className:`rounded-full border border-amber-200 bg-white px-2.5 py-1 text-xs text-amber-800`,children:e},e))})]}):null]}):null,(0,I.jsx)(`div`,{className:`flex flex-col gap-3 md:flex-row md:flex-wrap`,children:y.map(t=>(0,I.jsxs)(l,{type:`button`,variant:t.variant??`default`,onClick:()=>{if(t.action===`restart-app`){x();return}b(t.action)},disabled:!t.capability.available||e,children:[(0,I.jsx)(G,{icon:t.icon,busy:n===t.action}),t.label]},t.action))}),y.filter(e=>!e.capability.available&&e.capability.reasonIfUnavailable).map(e=>(0,I.jsx)(`p`,{className:`text-xs text-gray-500`,children:p(e.capability.reasonIfUnavailable)},`${e.action}-reason`))]})]})}function q(e){let{description:t,title:n}=e;return(0,I.jsx)(y,{tone:`neutral`,title:n,description:t})}function J(e){let{children:n}=e;return(0,I.jsxs)(_,{children:[(0,I.jsxs)(a,{children:[(0,I.jsx)(u,{children:t(`runtimePresenceTitle`)}),(0,I.jsx)(o,{children:t(`runtimePresenceDescription`)})]}),(0,I.jsx)(d,{children:n})]})}function Y(){let e=f().runtimeControlView?.environment,n=k(e=>e.supported),r=k(e=>e.initialized),i=k(e=>e.busyAction),a=k(e=>e.snapshot);return(0,F.useEffect)(()=>{if(e===`desktop-embedded`){N.start();return}N.markUnsupported()},[e]),e===`desktop-embedded`?(0,I.jsx)(J,{children:(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsx)(y,{tone:`neutral`,title:t(`runtimePresenceBehaviorLabel`),description:a?.closeToBackground?t(`runtimePresenceBehaviorBackground`):t(`runtimePresenceBehaviorQuit`),className:`rounded-xl`}),!r||n&&!a?(0,I.jsx)(`p`,{className:`text-sm text-gray-500`,children:t(`runtimePresenceLoading`)}):null,a?(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsx)(P,{title:t(`runtimePresenceCloseToBackground`),description:t(`runtimePresenceCloseToBackgroundHelp`),control:(0,I.jsx)(m,{id:`runtime-presence-close-background`,"aria-label":t(`runtimePresenceCloseToBackground`),checked:a.closeToBackground,disabled:i===`saving-preferences`,onCheckedChange:e=>{N.updatePreferences({closeToBackground:e})}})}),(0,I.jsx)(P,{title:t(`runtimePresenceLaunchAtLogin`),description:a.supportsLaunchAtLogin?t(`runtimePresenceLaunchAtLoginHelp`):a.launchAtLoginReason??t(`runtimePresenceLaunchAtLoginUnavailable`),control:(0,I.jsx)(m,{id:`runtime-presence-launch-login`,"aria-label":t(`runtimePresenceLaunchAtLogin`),checked:a.launchAtLogin,disabled:!a.supportsLaunchAtLogin||i===`saving-preferences`,onCheckedChange:e=>{N.updatePreferences({launchAtLogin:e})}})})]}):null]})}):e===`managed-local-service`?(0,I.jsx)(J,{children:(0,I.jsx)(q,{title:t(`runtimePresenceManagedLocalTitle`),description:t(`runtimePresenceManagedLocalDescription`)})}):e===`self-hosted-web`?(0,I.jsx)(J,{children:(0,I.jsx)(q,{title:t(`runtimePresenceSelfHostedTitle`),description:t(`runtimePresenceSelfHostedDescription`)})}):e===`shared-web`?(0,I.jsx)(J,{children:(0,I.jsx)(q,{title:t(`runtimePresenceSharedTitle`),description:t(`runtimePresenceSharedDescription`)})}):(0,I.jsx)(J,{children:(0,I.jsx)(`p`,{className:`text-sm text-gray-500`,children:t(`runtimePresenceLoading`)})})}function X(){return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(g,{title:t(`runtimePageTitle`),description:t(`runtimePageDescription`)}),(0,I.jsx)(K,{}),(0,I.jsx)(Y,{}),(0,I.jsx)(ee,{})]})}var Z={wireDialect:`acp`,processScope:`per-session`,command:``,args:[`acp`],env:{},cwd:``,startupTimeoutMs:8e3,probeTimeoutMs:3e3,requestTimeoutMs:12e4};function re(){return{id:``,default:!1,workspace:``,model:``,runtime:``,contextTokens:void 0,maxToolIterations:void 0}}function ie(){return{agentId:``,match:{channel:``,accountId:``}}}function ae(){return{id:``,enabled:!0,label:``,type:`narp-stdio`,config:Z,configText:JSON.stringify(Z,null,2)}}function oe(e){return{id:e.id??``,default:!!e.default,displayName:e.displayName??``,description:e.description??``,avatar:e.avatar??``,workspace:e.workspace??``,model:e.model??``,runtime:e.runtime??e.engine??``,contextTokens:e.contextTokens,maxToolIterations:e.maxToolIterations}}function se(e){return{agentId:e.agentId??``,match:{channel:e.match?.channel??``,accountId:e.match?.accountId??``,peer:e.match?.peer?{kind:e.match.peer.kind,id:e.match.peer.id}:void 0}}}function Q(e){let t=e.trim();if(!t)return;let n=Number.parseInt(t,10);return Number.isFinite(n)?n:void 0}function ce(e){return{companionEnabled:e.companion?.enabled===!0,agents:(e.agents.list??[]).map(oe),bindings:(e.bindings??[]).map(se),runtimeEntries:Object.entries(e.agents.runtimes?.entries??{}).map(([e,t])=>({id:e,enabled:t.enabled!==!1,label:t.label??``,type:t.type,config:t.config??{},configText:JSON.stringify(t.config??{},null,2)})),dmScope:e.session?.dmScope??`per-channel-peer`,defaultContextTokens:e.agents.defaults.contextTokens??2e5,defaultEngine:e.agents.defaults.engine??`native`}}function le(e){let t={id:e.id.trim()};e.default&&(t.default=!0),e.displayName?.trim()&&(t.displayName=e.displayName.trim()),e.description?.trim()&&(t.description=e.description.trim()),e.avatar?.trim()&&(t.avatar=e.avatar.trim()),e.workspace?.trim()&&(t.workspace=e.workspace.trim()),e.model?.trim()&&(t.model=e.model.trim());let n=e.runtime?.trim()??e.engine?.trim();return n&&(t.engine=n),typeof e.contextTokens==`number`&&(t.contextTokens=Math.max(1e3,e.contextTokens)),typeof e.maxToolIterations==`number`&&(t.maxToolIterations=e.maxToolIterations),t}function $(e){let n=e.agents.map((e,n)=>{if(!e.id.trim())throw Error(t(`agentIdRequiredError`).replace(`{index}`,String(n)));return le(e)}),r=n.map(e=>e.id).filter((e,t,n)=>n.indexOf(e)!==t);if(r.length>0)throw Error(`${t(`duplicateAgentId`)}: ${r[0]}`);let i=e.bindings.map((n,r)=>{let i=n.agentId.trim(),a=n.match.channel.trim(),o=n.match.accountId?.trim()??``,s=n.match.peer?.kind,c=n.match.peer?.id?.trim()??``;if(!i)throw Error(t(`bindingAgentIdRequired`).replace(`{index}`,String(r)));if(!e.knownAgentIds.has(i))throw Error(`${t(`bindingAgentIdNotFound`).replace(`{index}`,String(r))}: ${i}`);if(!a)throw Error(t(`bindingChannelRequired`).replace(`{index}`,String(r)));let l={agentId:i,match:{channel:a}};if(o&&(l.match.accountId=o),s){if(!c)throw Error(t(`bindingPeerIdRequired`).replace(`{index}`,String(r)));l.match.peer={kind:s,id:c}}return l}),a=e.runtimeEntries.reduce((e,n,r)=>{let i=n.id.trim(),a=n.type.trim();if(!i)throw Error(t(`runtimeEntryIdRequired`).replace(`{index}`,String(r)));if(!a)throw Error(t(`runtimeEntryTypeRequired`).replace(`{id}`,i));if(e[i])throw Error(`${t(`runtimeEntryDuplicate`)}: ${i}`);let o=n.configText.trim()?JSON.parse(n.configText):{};if(o&&(typeof o!=`object`||Array.isArray(o)))throw Error(t(`runtimeEntryConfigObjectRequired`).replace(`{id}`,i));return e[i]={enabled:n.enabled!==!1,...n.label?.trim()?{label:n.label.trim()}:{},type:a,config:o??{}},e},{});return{companion:{enabled:e.companionEnabled},agents:{defaults:{contextTokens:Math.max(1e3,e.defaultContextTokens),engine:e.defaultEngine.trim()||`native`},list:n,runtimes:{entries:a}},bindings:i,session:{dmScope:e.dmScope}}}function ue(e){return(0,I.jsxs)(_,{children:[(0,I.jsxs)(a,{children:[(0,I.jsx)(u,{children:t(`agentList`)}),(0,I.jsx)(o,{children:t(`agentListHelp`)})]}),(0,I.jsxs)(d,{className:`space-y-3`,children:[e.agents.map((n,r)=>(0,I.jsxs)(`div`,{className:`rounded-xl border border-gray-200 p-3 space-y-3`,children:[(0,I.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,I.jsx)(c,{value:n.id,onChange:t=>e.onUpdateAgent(r,{id:t.target.value}),placeholder:t(`agentIdPlaceholder`)}),(0,I.jsx)(c,{value:n.workspace??``,onChange:t=>e.onUpdateAgent(r,{workspace:t.target.value}),placeholder:t(`workspaceOverridePlaceholder`)}),(0,I.jsx)(c,{value:n.model??``,onChange:t=>e.onUpdateAgent(r,{model:t.target.value}),placeholder:t(`modelOverridePlaceholder`)}),(0,I.jsx)(c,{value:n.runtime??n.engine??``,onChange:t=>e.onUpdateAgent(r,{runtime:t.target.value}),placeholder:t(`engineOverridePlaceholder`)}),(0,I.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-2`,children:[(0,I.jsx)(c,{type:`number`,min:1e3,step:1e3,value:n.contextTokens??``,onChange:t=>e.onUpdateAgent(r,{contextTokens:Q(t.target.value)}),placeholder:t(`contextTokensPlaceholder`)}),(0,I.jsx)(c,{type:`number`,min:1,value:n.maxToolIterations??``,onChange:t=>e.onUpdateAgent(r,{maxToolIterations:Q(t.target.value)}),placeholder:t(`maxToolsPlaceholder`)})]})]}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-600`,children:[(0,I.jsx)(m,{checked:!!n.default,onCheckedChange:t=>e.onSetDefaultAgent(r,t)}),(0,I.jsx)(`span`,{children:t(`defaultAgent`)})]}),(0,I.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>e.onRemoveAgent(r),children:[(0,I.jsx)(T,{className:`h-4 w-4 mr-1`}),t(`remove`)]})]})]},`${r}-${n.id}`)),(0,I.jsxs)(l,{type:`button`,variant:`outline`,onClick:e.onAddAgent,children:[(0,I.jsx)(x,{className:`h-4 w-4 mr-2`}),t(`addAgent`)]})]})]})}function de(e){return(0,I.jsxs)(_,{children:[(0,I.jsxs)(a,{children:[(0,I.jsx)(u,{children:t(`bindings`)}),(0,I.jsx)(o,{children:t(`bindingsHelp`)})]}),(0,I.jsxs)(d,{className:`space-y-3`,children:[e.bindings.map((n,r)=>{let i=n.match.peer?.kind??``;return(0,I.jsxs)(`div`,{className:`rounded-xl border border-gray-200 p-3 space-y-3`,children:[(0,I.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3`,children:[(0,I.jsx)(c,{value:n.agentId,onChange:t=>e.onUpdateBinding(r,{...n,agentId:t.target.value}),placeholder:t(`targetAgentIdPlaceholder`)}),(0,I.jsx)(c,{value:n.match.channel,onChange:t=>e.onUpdateBinding(r,{...n,match:{...n.match,channel:t.target.value}}),placeholder:t(`channelPlaceholder`)}),(0,I.jsx)(c,{value:n.match.accountId??``,onChange:t=>e.onUpdateBinding(r,{...n,match:{...n.match,accountId:t.target.value}}),placeholder:t(`accountIdOptionalPlaceholder`)}),(0,I.jsxs)(w,{value:i||`__none__`,onValueChange:t=>{let i=t===`__none__`?``:t;e.onUpdateBinding(r,i?{...n,match:{...n.match,peer:{kind:i,id:n.match.peer?.id??``}}}:{...n,match:{...n.match,peer:void 0}})},children:[(0,I.jsx)(D,{children:(0,I.jsx)(E,{})}),(0,I.jsxs)(j,{children:[(0,I.jsx)(C,{value:`__none__`,children:t(`peerKindOptional`)}),(0,I.jsx)(C,{value:`direct`,children:t(`peerKindDirect`)}),(0,I.jsx)(C,{value:`group`,children:t(`peerKindGroup`)}),(0,I.jsx)(C,{value:`channel`,children:t(`peerKindChannel`)})]})]}),(0,I.jsx)(c,{value:n.match.peer?.id??``,onChange:t=>e.onUpdateBinding(r,{...n,match:{...n.match,peer:i?{kind:i,id:t.target.value}:void 0}}),placeholder:t(`peerIdPlaceholder`)})]}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>e.onRemoveBinding(r),children:[(0,I.jsx)(T,{className:`h-4 w-4 mr-1`}),t(`remove`)]})})]},`${r}-${n.agentId}`)}),(0,I.jsxs)(l,{type:`button`,variant:`outline`,onClick:e.onAddBinding,children:[(0,I.jsx)(x,{className:`h-4 w-4 mr-2`}),t(`addBinding`)]})]})]})}function fe(e){return(0,I.jsxs)(_,{children:[(0,I.jsxs)(a,{children:[(0,I.jsx)(u,{children:t(`runtimeEntries`)}),(0,I.jsx)(o,{children:t(`runtimeEntriesHelp`)})]}),(0,I.jsxs)(d,{className:`space-y-3`,children:[e.entries.map((n,r)=>(0,I.jsxs)(`div`,{className:`rounded-xl border border-gray-200 p-3 space-y-3`,children:[(0,I.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,I.jsx)(c,{value:n.id,onChange:t=>e.onUpdateEntry(r,{id:t.target.value}),placeholder:t(`runtimeEntryIdPlaceholder`)}),(0,I.jsx)(c,{value:n.label??``,onChange:t=>e.onUpdateEntry(r,{label:t.target.value}),placeholder:t(`runtimeEntryLabelPlaceholder`)}),(0,I.jsx)(c,{value:n.type,onChange:t=>e.onUpdateEntry(r,{type:t.target.value}),placeholder:t(`runtimeEntryTypePlaceholder`)}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between rounded-lg border border-gray-200 px-3 py-2`,children:[(0,I.jsx)(`span`,{className:`text-sm text-gray-700`,children:t(`enabled`)}),(0,I.jsx)(m,{checked:n.enabled!==!1,onCheckedChange:t=>e.onUpdateEntry(r,{enabled:t})})]})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(`label`,{className:`text-sm font-medium text-gray-800`,children:t(`runtimeEntryConfigJson`)}),(0,I.jsx)(`textarea`,{className:`min-h-32 w-full rounded-md border border-gray-200 px-3 py-2 text-sm font-mono`,value:n.configText,onChange:t=>e.onUpdateEntry(r,{configText:t.target.value}),spellCheck:!1})]}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsxs)(l,{type:`button`,variant:`outline`,onClick:()=>e.onRemoveEntry(r),children:[(0,I.jsx)(T,{className:`mr-2 h-4 w-4`}),t(`delete`)]})})]},`${r}-${n.id||`runtime-entry`}`)),(0,I.jsxs)(l,{type:`button`,variant:`outline`,onClick:e.onAddEntry,children:[(0,I.jsx)(x,{className:`mr-2 h-4 w-4`}),t(`addRuntimeEntry`)]})]})]})}var pe=[{value:`main`,labelKey:`dmScopeMain`},{value:`per-peer`,labelKey:`dmScopePerPeer`},{value:`per-channel-peer`,labelKey:`dmScopePerChannelPeer`},{value:`per-account-channel-peer`,labelKey:`dmScopePerAccountChannelPeer`}];function me(e){return(0,I.jsxs)(_,{children:[(0,I.jsxs)(a,{children:[(0,I.jsx)(u,{children:t(`dmScope`)}),(0,I.jsx)(o,{children:t(`dmScopeHelp`)})]}),(0,I.jsxs)(d,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`flex items-start justify-between gap-4 rounded-md border border-gray-200 px-4 py-3`,children:[(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsx)(`div`,{className:`text-sm font-medium text-gray-800`,children:t(`runtimeCompanionEnabled`)}),(0,I.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`runtimeCompanionEnabledHelp`)})]}),(0,I.jsx)(m,{checked:e.companionEnabled,onCheckedChange:e.onCompanionEnabledChange})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(`label`,{className:`text-sm font-medium text-gray-800`,children:t(`defaultContextTokens`)}),(0,I.jsx)(c,{type:`number`,min:1e3,step:1e3,value:e.defaultContextTokens,onChange:t=>e.onDefaultContextTokensChange(Math.max(1e3,Number.parseInt(t.target.value,10)||1e3))}),(0,I.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`defaultContextTokensHelp`)})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(`label`,{className:`text-sm font-medium text-gray-800`,children:t(`defaultEngine`)}),(0,I.jsx)(c,{value:e.defaultEngine,onChange:t=>e.onDefaultEngineChange(t.target.value),placeholder:t(`defaultEnginePlaceholder`)}),(0,I.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`defaultEngineHelp`)})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(`label`,{className:`text-sm font-medium text-gray-800`,children:t(`dmScope`)}),(0,I.jsxs)(w,{value:e.dmScope,onValueChange:t=>e.onDmScopeChange(t),children:[(0,I.jsx)(D,{children:(0,I.jsx)(E,{})}),(0,I.jsx)(j,{children:pe.map(e=>(0,I.jsx)(C,{value:e.value,children:t(e.labelKey)},e.value))})]})]})]})]})}function he(e){let n=(0,F.useMemo)(()=>ce(e.config),[e.config]),[r,a]=(0,F.useState)(n.agents),[o,c]=(0,F.useState)(n.bindings),[u,d]=(0,F.useState)(n.runtimeEntries),[f,p]=(0,F.useState)(n.dmScope),[m,h]=(0,F.useState)(n.companionEnabled),[g,_]=(0,F.useState)(n.defaultContextTokens),[v,y]=(0,F.useState)(n.defaultEngine),b=(0,F.useMemo)(()=>{let e=new Set([`main`]);return r.forEach(t=>{let n=t.id.trim();n&&e.add(n)}),e},[r]);return(0,I.jsxs)(i,{className:`space-y-6`,children:[(0,I.jsx)(X,{}),(0,I.jsx)(me,{companionEnabled:m,dmScope:f,defaultContextTokens:g,defaultEngine:v,onCompanionEnabledChange:h,onDmScopeChange:p,onDefaultContextTokensChange:_,onDefaultEngineChange:y}),(0,I.jsx)(fe,{entries:u,onUpdateEntry:(e,t)=>d(n=>n.map((n,r)=>r===e?{...n,...t}:n)),onRemoveEntry:e=>d(t=>t.filter((t,n)=>n!==e)),onAddEntry:()=>d(e=>[...e,ae()])}),(0,I.jsx)(ue,{agents:r,onUpdateAgent:(e,t)=>{a(n=>n.map((n,r)=>r===e?{...n,...t}:n))},onRemoveAgent:e=>a(t=>t.filter((t,n)=>n!==e)),onAddAgent:()=>a(e=>[...e,re()]),onSetDefaultAgent:(e,t)=>a(n=>t?n.map((t,n)=>({...t,default:n===e})):n.map((t,n)=>n===e?{...t,default:!1}:t))}),(0,I.jsx)(de,{bindings:o,onUpdateBinding:(e,t)=>{c(n=>n.map((n,r)=>r===e?t:n))},onRemoveBinding:e=>c(t=>t.filter((t,n)=>n!==e)),onAddBinding:()=>c(e=>[...e,ie()])}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsxs)(l,{type:`button`,onClick:()=>{try{let t=$({companionEnabled:m,agents:r,bindings:o,runtimeEntries:u,dmScope:f,defaultContextTokens:g,defaultEngine:v,knownAgentIds:b});e.updateRuntime.mutate({data:t})}catch(e){s.error(e instanceof Error?e.message:String(e))}},disabled:e.updateRuntime.isPending,children:[(0,I.jsx)(S,{className:`h-4 w-4 mr-2`}),e.updateRuntime.isPending?t(`saving`):t(`saveRuntimeSettings`)]})})]})}function ge(){let{data:e,isLoading:n}=O(),r=ne();return n||!e?(0,I.jsx)(`div`,{className:`p-8 text-gray-400`,children:t(`runtimeLoading`)}):(0,I.jsx)(he,{config:e,updateRuntime:r})}export{ge as RuntimeConfig};
1
+ import{h as e,i as t,m as n,v as r}from"./react-B2X_ph0a.js";import{At as i,Dt as a,Et as o,Lt as s,Mt as c,Nt as l,Ot as u,Tt as d,_t as f,bt as p,ft as m,ht as h,kt as g,wt as _,yt as v}from"./api-DruAcori.js";import{n as y}from"./confirm-dialog-B0TP-vPd.js";import{t as b}from"./play-CqNi0u02.js";import{t as x}from"./plus-BcIC8dG1.js";import{t as S}from"./save-D10M5vQg.js";import{G as ee,J as C,K as w,Kt as T,X as E,Y as D,Z as O,Zt as te,bt as k,gt as ne,nn as A,q as j,qt as M,yt as N}from"./index-GVTiCf1s.js";import{t as P}from"./setting-row-8VkukJoH.js";var F=r(e(),1),I=n(),L={healthy:`runtimeControlHealthy`,"starting-service":`runtimeControlStartingService`,"restarting-service":`runtimeControlRestartingService`,"stopping-service":`runtimeControlStoppingService`,"restarting-app":`runtimeControlRestartingApp`,recovering:`runtimeControlRecovering`,failed:`runtimeControlFailed`},R={running:`runtimeControlServiceRunning`,stopped:`runtimeControlServiceStopped`,starting:`runtimeControlServiceStarting`,stopping:`runtimeControlServiceStopping`,restarting:`runtimeControlServiceRestarting`},z={"desktop-embedded":`runtimeControlEnvironmentDesktop`,"managed-local-service":`runtimeControlEnvironmentManagedService`,"self-hosted-web":`runtimeControlEnvironmentSelfHosted`,"shared-web":`runtimeControlEnvironmentSharedWeb`};function B(e){return t(L[e]??`runtimeControlUnavailable`)}function V(e){return t(R[e]??`runtimeControlServiceUnknown`)}function H(e){return t(z[e.environment])}function U(e,t){return t===`start-service`?e?.canStartService:t===`stop-service`?e?.canStopService:e?.canRestartService}function W(e){return e?[{action:`start-service`,capability:e.canStartService,label:t(`runtimeControlStartService`),icon:`play`},{action:`restart-service`,capability:e.canRestartService,label:t(`runtimeControlRestartService`),icon:`rotate`},{action:`stop-service`,capability:e.canStopService,label:t(`runtimeControlStopService`),icon:`square`,variant:`destructive`},{action:`restart-app`,capability:e.canRestartApp,label:t(`runtimeControlRestartApp`),icon:`rotate`,variant:`secondary`}].filter(e=>e.capability.available||!!e.capability.reasonIfUnavailable):[]}function G(e){let{busy:t,icon:n}=e;return t?(0,I.jsx)(A,{className:`mr-2 h-4 w-4 animate-spin`}):n===`play`?(0,I.jsx)(b,{className:`mr-2 h-4 w-4`}):n===`square`?(0,I.jsx)(M,{className:`mr-2 h-4 w-4`}):(0,I.jsx)(te,{className:`mr-2 h-4 w-4`})}function K(){let{busy:e,busyAction:n,controlView:r,errorMessage:i,pendingRestart:c,visibleLifecycle:f,visibleMessage:m,visibleServiceState:g}=h(),y=W(r??void 0),b=async e=>{let n=U(r,e);if(!n?.available){s.error(p(n?.reasonIfUnavailable)??t(`runtimeControlLoadFailed`));return}if(!(e===`stop-service`&&n.requiresConfirmation&&!window.confirm(t(`runtimeControlStopServiceConfirm`))))try{let t=await v.runRuntimeControlAction(e);s.success(p(t.message)??t.message)}catch(e){let n=e instanceof Error?e.message:t(`runtimeControlActionFailed`);s.error(`${t(`runtimeControlActionFailed`)}: ${n}`)}},x=async()=>{if(!r?.canRestartApp.available){s.error(p(r?.canRestartApp.reasonIfUnavailable)??t(`runtimeRestartAppUnavailable`));return}if(window.confirm(t(`runtimeControlRestartAppConfirm`)))try{let e=await v.runRuntimeControlAction(`restart-app`);s.success(p(e.message)??e.message)}catch(e){let n=e instanceof Error?e.message:t(`runtimeControlActionFailed`);s.error(`${t(`runtimeControlActionFailed`)}: ${n}`)}};return(0,I.jsxs)(_,{children:[(0,I.jsxs)(a,{children:[(0,I.jsx)(u,{children:t(`runtimeControlTitle`)}),(0,I.jsx)(o,{children:t(`runtimeControlDescription`)})]}),(0,I.jsxs)(d,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-3 rounded-xl border border-gray-200 bg-gray-50 p-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-1 md:flex-row md:items-center md:justify-between`,children:[(0,I.jsx)(`div`,{className:`text-sm font-medium text-gray-900`,children:V(g)}),(0,I.jsx)(`div`,{className:`text-xs text-gray-500`,children:r?H(r):t(`runtimeControlLoading`)})]}),(0,I.jsx)(`p`,{className:`text-sm text-gray-600`,children:m}),(0,I.jsx)(`div`,{className:`text-xs text-gray-500`,children:B(f)}),r?.managementHint?(0,I.jsx)(`p`,{className:`text-xs text-gray-500`,children:p(r.managementHint)}):null,i&&!e?(0,I.jsx)(`p`,{className:`text-sm text-amber-700`,children:i}):null]}),c?(0,I.jsxs)(`div`,{className:`space-y-3 rounded-xl border border-amber-200 bg-amber-50 p-4`,children:[(0,I.jsx)(`div`,{className:`text-sm font-medium text-amber-900`,children:t(`runtimeControlPendingRestartTitle`)}),(0,I.jsx)(`p`,{className:`text-sm text-amber-800`,children:t(`runtimeControlPendingRestartDescription`)}),c.changedPaths.length>0?(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-[0.08em] text-amber-700`,children:t(`runtimeControlPendingRestartPaths`)}),(0,I.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:c.changedPaths.map(e=>(0,I.jsx)(`span`,{className:`rounded-full border border-amber-200 bg-white px-2.5 py-1 text-xs text-amber-800`,children:e},e))})]}):null]}):null,(0,I.jsx)(`div`,{className:`flex flex-col gap-3 md:flex-row md:flex-wrap`,children:y.map(t=>(0,I.jsxs)(l,{type:`button`,variant:t.variant??`default`,onClick:()=>{if(t.action===`restart-app`){x();return}b(t.action)},disabled:!t.capability.available||e,children:[(0,I.jsx)(G,{icon:t.icon,busy:n===t.action}),t.label]},t.action))}),y.filter(e=>!e.capability.available&&e.capability.reasonIfUnavailable).map(e=>(0,I.jsx)(`p`,{className:`text-xs text-gray-500`,children:p(e.capability.reasonIfUnavailable)},`${e.action}-reason`))]})]})}function q(e){let{description:t,title:n}=e;return(0,I.jsx)(y,{tone:`neutral`,title:n,description:t})}function J(e){let{children:n}=e;return(0,I.jsxs)(_,{children:[(0,I.jsxs)(a,{children:[(0,I.jsx)(u,{children:t(`runtimePresenceTitle`)}),(0,I.jsx)(o,{children:t(`runtimePresenceDescription`)})]}),(0,I.jsx)(d,{children:n})]})}function Y(){let e=f().runtimeControlView?.environment,n=k(e=>e.supported),r=k(e=>e.initialized),i=k(e=>e.busyAction),a=k(e=>e.snapshot);return(0,F.useEffect)(()=>{if(e===`desktop-embedded`){N.start();return}N.markUnsupported()},[e]),e===`desktop-embedded`?(0,I.jsx)(J,{children:(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsx)(y,{tone:`neutral`,title:t(`runtimePresenceBehaviorLabel`),description:a?.closeToBackground?t(`runtimePresenceBehaviorBackground`):t(`runtimePresenceBehaviorQuit`),className:`rounded-xl`}),!r||n&&!a?(0,I.jsx)(`p`,{className:`text-sm text-gray-500`,children:t(`runtimePresenceLoading`)}):null,a?(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsx)(P,{title:t(`runtimePresenceCloseToBackground`),description:t(`runtimePresenceCloseToBackgroundHelp`),control:(0,I.jsx)(m,{id:`runtime-presence-close-background`,"aria-label":t(`runtimePresenceCloseToBackground`),checked:a.closeToBackground,disabled:i===`saving-preferences`,onCheckedChange:e=>{N.updatePreferences({closeToBackground:e})}})}),(0,I.jsx)(P,{title:t(`runtimePresenceLaunchAtLogin`),description:a.supportsLaunchAtLogin?t(`runtimePresenceLaunchAtLoginHelp`):a.launchAtLoginReason??t(`runtimePresenceLaunchAtLoginUnavailable`),control:(0,I.jsx)(m,{id:`runtime-presence-launch-login`,"aria-label":t(`runtimePresenceLaunchAtLogin`),checked:a.launchAtLogin,disabled:!a.supportsLaunchAtLogin||i===`saving-preferences`,onCheckedChange:e=>{N.updatePreferences({launchAtLogin:e})}})})]}):null]})}):e===`managed-local-service`?(0,I.jsx)(J,{children:(0,I.jsx)(q,{title:t(`runtimePresenceManagedLocalTitle`),description:t(`runtimePresenceManagedLocalDescription`)})}):e===`self-hosted-web`?(0,I.jsx)(J,{children:(0,I.jsx)(q,{title:t(`runtimePresenceSelfHostedTitle`),description:t(`runtimePresenceSelfHostedDescription`)})}):e===`shared-web`?(0,I.jsx)(J,{children:(0,I.jsx)(q,{title:t(`runtimePresenceSharedTitle`),description:t(`runtimePresenceSharedDescription`)})}):(0,I.jsx)(J,{children:(0,I.jsx)(`p`,{className:`text-sm text-gray-500`,children:t(`runtimePresenceLoading`)})})}function X(){return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(g,{title:t(`runtimePageTitle`),description:t(`runtimePageDescription`)}),(0,I.jsx)(K,{}),(0,I.jsx)(Y,{}),(0,I.jsx)(ee,{})]})}var Z={wireDialect:`acp`,processScope:`per-session`,command:``,args:[`acp`],env:{},cwd:``,startupTimeoutMs:8e3,probeTimeoutMs:3e3,requestTimeoutMs:12e4};function re(){return{id:``,default:!1,workspace:``,model:``,runtime:``,contextTokens:void 0,maxToolIterations:void 0}}function ie(){return{agentId:``,match:{channel:``,accountId:``}}}function ae(){return{id:``,enabled:!0,label:``,type:`narp-stdio`,config:Z,configText:JSON.stringify(Z,null,2)}}function oe(e){return{id:e.id??``,default:!!e.default,displayName:e.displayName??``,description:e.description??``,avatar:e.avatar??``,workspace:e.workspace??``,model:e.model??``,runtime:e.runtime??e.engine??``,contextTokens:e.contextTokens,maxToolIterations:e.maxToolIterations}}function se(e){return{agentId:e.agentId??``,match:{channel:e.match?.channel??``,accountId:e.match?.accountId??``,peer:e.match?.peer?{kind:e.match.peer.kind,id:e.match.peer.id}:void 0}}}function Q(e){let t=e.trim();if(!t)return;let n=Number.parseInt(t,10);return Number.isFinite(n)?n:void 0}function ce(e){return{companionEnabled:e.companion?.enabled===!0,agents:(e.agents.list??[]).map(oe),bindings:(e.bindings??[]).map(se),runtimeEntries:Object.entries(e.agents.runtimes?.entries??{}).map(([e,t])=>({id:e,enabled:t.enabled!==!1,label:t.label??``,type:t.type,config:t.config??{},configText:JSON.stringify(t.config??{},null,2)})),dmScope:e.session?.dmScope??`per-channel-peer`,defaultContextTokens:e.agents.defaults.contextTokens??2e5,defaultEngine:e.agents.defaults.engine??`native`}}function le(e){let t={id:e.id.trim()};e.default&&(t.default=!0),e.displayName?.trim()&&(t.displayName=e.displayName.trim()),e.description?.trim()&&(t.description=e.description.trim()),e.avatar?.trim()&&(t.avatar=e.avatar.trim()),e.workspace?.trim()&&(t.workspace=e.workspace.trim()),e.model?.trim()&&(t.model=e.model.trim());let n=e.runtime?.trim()??e.engine?.trim();return n&&(t.engine=n),typeof e.contextTokens==`number`&&(t.contextTokens=Math.max(1e3,e.contextTokens)),typeof e.maxToolIterations==`number`&&(t.maxToolIterations=e.maxToolIterations),t}function $(e){let n=e.agents.map((e,n)=>{if(!e.id.trim())throw Error(t(`agentIdRequiredError`).replace(`{index}`,String(n)));return le(e)}),r=n.map(e=>e.id).filter((e,t,n)=>n.indexOf(e)!==t);if(r.length>0)throw Error(`${t(`duplicateAgentId`)}: ${r[0]}`);let i=e.bindings.map((n,r)=>{let i=n.agentId.trim(),a=n.match.channel.trim(),o=n.match.accountId?.trim()??``,s=n.match.peer?.kind,c=n.match.peer?.id?.trim()??``;if(!i)throw Error(t(`bindingAgentIdRequired`).replace(`{index}`,String(r)));if(!e.knownAgentIds.has(i))throw Error(`${t(`bindingAgentIdNotFound`).replace(`{index}`,String(r))}: ${i}`);if(!a)throw Error(t(`bindingChannelRequired`).replace(`{index}`,String(r)));let l={agentId:i,match:{channel:a}};if(o&&(l.match.accountId=o),s){if(!c)throw Error(t(`bindingPeerIdRequired`).replace(`{index}`,String(r)));l.match.peer={kind:s,id:c}}return l}),a=e.runtimeEntries.reduce((e,n,r)=>{let i=n.id.trim(),a=n.type.trim();if(!i)throw Error(t(`runtimeEntryIdRequired`).replace(`{index}`,String(r)));if(!a)throw Error(t(`runtimeEntryTypeRequired`).replace(`{id}`,i));if(e[i])throw Error(`${t(`runtimeEntryDuplicate`)}: ${i}`);let o=n.configText.trim()?JSON.parse(n.configText):{};if(o&&(typeof o!=`object`||Array.isArray(o)))throw Error(t(`runtimeEntryConfigObjectRequired`).replace(`{id}`,i));return e[i]={enabled:n.enabled!==!1,...n.label?.trim()?{label:n.label.trim()}:{},type:a,config:o??{}},e},{});return{companion:{enabled:e.companionEnabled},agents:{defaults:{contextTokens:Math.max(1e3,e.defaultContextTokens),engine:e.defaultEngine.trim()||`native`},list:n,runtimes:{entries:a}},bindings:i,session:{dmScope:e.dmScope}}}function ue(e){return(0,I.jsxs)(_,{children:[(0,I.jsxs)(a,{children:[(0,I.jsx)(u,{children:t(`agentList`)}),(0,I.jsx)(o,{children:t(`agentListHelp`)})]}),(0,I.jsxs)(d,{className:`space-y-3`,children:[e.agents.map((n,r)=>(0,I.jsxs)(`div`,{className:`rounded-xl border border-gray-200 p-3 space-y-3`,children:[(0,I.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,I.jsx)(c,{value:n.id,onChange:t=>e.onUpdateAgent(r,{id:t.target.value}),placeholder:t(`agentIdPlaceholder`)}),(0,I.jsx)(c,{value:n.workspace??``,onChange:t=>e.onUpdateAgent(r,{workspace:t.target.value}),placeholder:t(`workspaceOverridePlaceholder`)}),(0,I.jsx)(c,{value:n.model??``,onChange:t=>e.onUpdateAgent(r,{model:t.target.value}),placeholder:t(`modelOverridePlaceholder`)}),(0,I.jsx)(c,{value:n.runtime??n.engine??``,onChange:t=>e.onUpdateAgent(r,{runtime:t.target.value}),placeholder:t(`engineOverridePlaceholder`)}),(0,I.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-2`,children:[(0,I.jsx)(c,{type:`number`,min:1e3,step:1e3,value:n.contextTokens??``,onChange:t=>e.onUpdateAgent(r,{contextTokens:Q(t.target.value)}),placeholder:t(`contextTokensPlaceholder`)}),(0,I.jsx)(c,{type:`number`,min:1,value:n.maxToolIterations??``,onChange:t=>e.onUpdateAgent(r,{maxToolIterations:Q(t.target.value)}),placeholder:t(`maxToolsPlaceholder`)})]})]}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-600`,children:[(0,I.jsx)(m,{checked:!!n.default,onCheckedChange:t=>e.onSetDefaultAgent(r,t)}),(0,I.jsx)(`span`,{children:t(`defaultAgent`)})]}),(0,I.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>e.onRemoveAgent(r),children:[(0,I.jsx)(T,{className:`h-4 w-4 mr-1`}),t(`remove`)]})]})]},`${r}-${n.id}`)),(0,I.jsxs)(l,{type:`button`,variant:`outline`,onClick:e.onAddAgent,children:[(0,I.jsx)(x,{className:`h-4 w-4 mr-2`}),t(`addAgent`)]})]})]})}function de(e){return(0,I.jsxs)(_,{children:[(0,I.jsxs)(a,{children:[(0,I.jsx)(u,{children:t(`bindings`)}),(0,I.jsx)(o,{children:t(`bindingsHelp`)})]}),(0,I.jsxs)(d,{className:`space-y-3`,children:[e.bindings.map((n,r)=>{let i=n.match.peer?.kind??``;return(0,I.jsxs)(`div`,{className:`rounded-xl border border-gray-200 p-3 space-y-3`,children:[(0,I.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3`,children:[(0,I.jsx)(c,{value:n.agentId,onChange:t=>e.onUpdateBinding(r,{...n,agentId:t.target.value}),placeholder:t(`targetAgentIdPlaceholder`)}),(0,I.jsx)(c,{value:n.match.channel,onChange:t=>e.onUpdateBinding(r,{...n,match:{...n.match,channel:t.target.value}}),placeholder:t(`channelPlaceholder`)}),(0,I.jsx)(c,{value:n.match.accountId??``,onChange:t=>e.onUpdateBinding(r,{...n,match:{...n.match,accountId:t.target.value}}),placeholder:t(`accountIdOptionalPlaceholder`)}),(0,I.jsxs)(w,{value:i||`__none__`,onValueChange:t=>{let i=t===`__none__`?``:t;e.onUpdateBinding(r,i?{...n,match:{...n.match,peer:{kind:i,id:n.match.peer?.id??``}}}:{...n,match:{...n.match,peer:void 0}})},children:[(0,I.jsx)(D,{children:(0,I.jsx)(E,{})}),(0,I.jsxs)(j,{children:[(0,I.jsx)(C,{value:`__none__`,children:t(`peerKindOptional`)}),(0,I.jsx)(C,{value:`direct`,children:t(`peerKindDirect`)}),(0,I.jsx)(C,{value:`group`,children:t(`peerKindGroup`)}),(0,I.jsx)(C,{value:`channel`,children:t(`peerKindChannel`)})]})]}),(0,I.jsx)(c,{value:n.match.peer?.id??``,onChange:t=>e.onUpdateBinding(r,{...n,match:{...n.match,peer:i?{kind:i,id:t.target.value}:void 0}}),placeholder:t(`peerIdPlaceholder`)})]}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>e.onRemoveBinding(r),children:[(0,I.jsx)(T,{className:`h-4 w-4 mr-1`}),t(`remove`)]})})]},`${r}-${n.agentId}`)}),(0,I.jsxs)(l,{type:`button`,variant:`outline`,onClick:e.onAddBinding,children:[(0,I.jsx)(x,{className:`h-4 w-4 mr-2`}),t(`addBinding`)]})]})]})}function fe(e){return(0,I.jsxs)(_,{children:[(0,I.jsxs)(a,{children:[(0,I.jsx)(u,{children:t(`runtimeEntries`)}),(0,I.jsx)(o,{children:t(`runtimeEntriesHelp`)})]}),(0,I.jsxs)(d,{className:`space-y-3`,children:[e.entries.map((n,r)=>(0,I.jsxs)(`div`,{className:`rounded-xl border border-gray-200 p-3 space-y-3`,children:[(0,I.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,I.jsx)(c,{value:n.id,onChange:t=>e.onUpdateEntry(r,{id:t.target.value}),placeholder:t(`runtimeEntryIdPlaceholder`)}),(0,I.jsx)(c,{value:n.label??``,onChange:t=>e.onUpdateEntry(r,{label:t.target.value}),placeholder:t(`runtimeEntryLabelPlaceholder`)}),(0,I.jsx)(c,{value:n.type,onChange:t=>e.onUpdateEntry(r,{type:t.target.value}),placeholder:t(`runtimeEntryTypePlaceholder`)}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between rounded-lg border border-gray-200 px-3 py-2`,children:[(0,I.jsx)(`span`,{className:`text-sm text-gray-700`,children:t(`enabled`)}),(0,I.jsx)(m,{checked:n.enabled!==!1,onCheckedChange:t=>e.onUpdateEntry(r,{enabled:t})})]})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(`label`,{className:`text-sm font-medium text-gray-800`,children:t(`runtimeEntryConfigJson`)}),(0,I.jsx)(`textarea`,{className:`min-h-32 w-full rounded-md border border-gray-200 px-3 py-2 text-sm font-mono`,value:n.configText,onChange:t=>e.onUpdateEntry(r,{configText:t.target.value}),spellCheck:!1})]}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsxs)(l,{type:`button`,variant:`outline`,onClick:()=>e.onRemoveEntry(r),children:[(0,I.jsx)(T,{className:`mr-2 h-4 w-4`}),t(`delete`)]})})]},`${r}-${n.id||`runtime-entry`}`)),(0,I.jsxs)(l,{type:`button`,variant:`outline`,onClick:e.onAddEntry,children:[(0,I.jsx)(x,{className:`mr-2 h-4 w-4`}),t(`addRuntimeEntry`)]})]})]})}var pe=[{value:`main`,labelKey:`dmScopeMain`},{value:`per-peer`,labelKey:`dmScopePerPeer`},{value:`per-channel-peer`,labelKey:`dmScopePerChannelPeer`},{value:`per-account-channel-peer`,labelKey:`dmScopePerAccountChannelPeer`}];function me(e){return(0,I.jsxs)(_,{children:[(0,I.jsxs)(a,{children:[(0,I.jsx)(u,{children:t(`dmScope`)}),(0,I.jsx)(o,{children:t(`dmScopeHelp`)})]}),(0,I.jsxs)(d,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`flex items-start justify-between gap-4 rounded-md border border-gray-200 px-4 py-3`,children:[(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsx)(`div`,{className:`text-sm font-medium text-gray-800`,children:t(`runtimeCompanionEnabled`)}),(0,I.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`runtimeCompanionEnabledHelp`)})]}),(0,I.jsx)(m,{checked:e.companionEnabled,onCheckedChange:e.onCompanionEnabledChange})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(`label`,{className:`text-sm font-medium text-gray-800`,children:t(`defaultContextTokens`)}),(0,I.jsx)(c,{type:`number`,min:1e3,step:1e3,value:e.defaultContextTokens,onChange:t=>e.onDefaultContextTokensChange(Math.max(1e3,Number.parseInt(t.target.value,10)||1e3))}),(0,I.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`defaultContextTokensHelp`)})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(`label`,{className:`text-sm font-medium text-gray-800`,children:t(`defaultEngine`)}),(0,I.jsx)(c,{value:e.defaultEngine,onChange:t=>e.onDefaultEngineChange(t.target.value),placeholder:t(`defaultEnginePlaceholder`)}),(0,I.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`defaultEngineHelp`)})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(`label`,{className:`text-sm font-medium text-gray-800`,children:t(`dmScope`)}),(0,I.jsxs)(w,{value:e.dmScope,onValueChange:t=>e.onDmScopeChange(t),children:[(0,I.jsx)(D,{children:(0,I.jsx)(E,{})}),(0,I.jsx)(j,{children:pe.map(e=>(0,I.jsx)(C,{value:e.value,children:t(e.labelKey)},e.value))})]})]})]})]})}function he(e){let n=(0,F.useMemo)(()=>ce(e.config),[e.config]),[r,a]=(0,F.useState)(n.agents),[o,c]=(0,F.useState)(n.bindings),[u,d]=(0,F.useState)(n.runtimeEntries),[f,p]=(0,F.useState)(n.dmScope),[m,h]=(0,F.useState)(n.companionEnabled),[g,_]=(0,F.useState)(n.defaultContextTokens),[v,y]=(0,F.useState)(n.defaultEngine),b=(0,F.useMemo)(()=>{let e=new Set([`main`]);return r.forEach(t=>{let n=t.id.trim();n&&e.add(n)}),e},[r]);return(0,I.jsxs)(i,{className:`space-y-6`,children:[(0,I.jsx)(X,{}),(0,I.jsx)(me,{companionEnabled:m,dmScope:f,defaultContextTokens:g,defaultEngine:v,onCompanionEnabledChange:h,onDmScopeChange:p,onDefaultContextTokensChange:_,onDefaultEngineChange:y}),(0,I.jsx)(fe,{entries:u,onUpdateEntry:(e,t)=>d(n=>n.map((n,r)=>r===e?{...n,...t}:n)),onRemoveEntry:e=>d(t=>t.filter((t,n)=>n!==e)),onAddEntry:()=>d(e=>[...e,ae()])}),(0,I.jsx)(ue,{agents:r,onUpdateAgent:(e,t)=>{a(n=>n.map((n,r)=>r===e?{...n,...t}:n))},onRemoveAgent:e=>a(t=>t.filter((t,n)=>n!==e)),onAddAgent:()=>a(e=>[...e,re()]),onSetDefaultAgent:(e,t)=>a(n=>t?n.map((t,n)=>({...t,default:n===e})):n.map((t,n)=>n===e?{...t,default:!1}:t))}),(0,I.jsx)(de,{bindings:o,onUpdateBinding:(e,t)=>{c(n=>n.map((n,r)=>r===e?t:n))},onRemoveBinding:e=>c(t=>t.filter((t,n)=>n!==e)),onAddBinding:()=>c(e=>[...e,ie()])}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsxs)(l,{type:`button`,onClick:()=>{try{let t=$({companionEnabled:m,agents:r,bindings:o,runtimeEntries:u,dmScope:f,defaultContextTokens:g,defaultEngine:v,knownAgentIds:b});e.updateRuntime.mutate({data:t})}catch(e){s.error(e instanceof Error?e.message:String(e))}},disabled:e.updateRuntime.isPending,children:[(0,I.jsx)(S,{className:`h-4 w-4 mr-2`}),e.updateRuntime.isPending?t(`saving`):t(`saveRuntimeSettings`)]})})]})}function ge(){let{data:e,isLoading:n}=O(),r=ne();return n||!e?(0,I.jsx)(`div`,{className:`p-8 text-gray-400`,children:t(`runtimeLoading`)}):(0,I.jsx)(he,{config:e,updateRuntime:r})}export{ge as RuntimeConfig};
@@ -1 +1 @@
1
- import{h as e,i as t,m as n,v as r}from"./react-B2X_ph0a.js";import{At as i,Mt as a,Nt as o,jt as s,kt as c}from"./api-DruAcori.js";import{t as l}from"./search-CdhgFNwf.js";import{t as u}from"./external-link-C3usm3se.js";import{J as d,K as f,Q as p,X as m,Y as h,Z as g,_t as _,q as v,rn as y,xt as b}from"./index-D2H2CKYR.js";import{a as x,c as S,i as C,n as w,o as T,s as E,t as D}from"./config-split-page-BFh_Qixx.js";var O=r(e(),1),k=n(),A=[{value:`noLimit`,label:`searchFreshnessNoLimit`},{value:`oneDay`,label:`searchFreshnessOneDay`},{value:`oneWeek`,label:`searchFreshnessOneWeek`},{value:`oneMonth`,label:`searchFreshnessOneMonth`},{value:`oneYear`,label:`searchFreshnessOneYear`}],j=[{value:`basic`,label:`searchDepthBasic`},{value:`advanced`,label:`searchDepthAdvanced`}],M=[{value:`true`,label:`enabled`},{value:`false`,label:`disabled`}],N={bocha:`searchProviderBochaDescription`,tavily:`searchProviderTavilyDescription`,brave:`searchProviderBraveDescription`};function P(e){return{activeProvider:e.provider,enabledProviders:e.enabledProviders,maxResults:String(e.defaults.maxResults),providers:{bocha:{apiKey:``,baseUrl:e.providers.bocha.baseUrl,summary:!!e.providers.bocha.summary,freshness:e.providers.bocha.freshness??`noLimit`},tavily:{apiKey:``,baseUrl:e.providers.tavily.baseUrl,searchDepth:e.providers.tavily.searchDepth??`basic`,includeAnswer:!!e.providers.tavily.includeAnswer},brave:{apiKey:``,baseUrl:e.providers.brave.baseUrl}}}}function F(e){return{provider:e.activeProvider,enabledProviders:e.enabledProviders,defaults:{maxResults:Number(e.maxResults)||10},providers:{bocha:{apiKey:e.providers.bocha.apiKey||void 0,baseUrl:e.providers.bocha.baseUrl,summary:e.providers.bocha.summary,freshness:e.providers.bocha.freshness},tavily:{apiKey:e.providers.tavily.apiKey||void 0,baseUrl:e.providers.tavily.baseUrl,searchDepth:e.providers.tavily.searchDepth,includeAnswer:e.providers.tavily.includeAnswer},brave:{apiKey:e.providers.brave.apiKey||void 0,baseUrl:e.providers.brave.baseUrl}}}}function I(e){let{label:t,value:n,onChange:r,placeholder:i,type:o=`text`,inputMode:c}=e;return(0,k.jsxs)(`div`,{className:`space-y-2`,children:[(0,k.jsx)(s,{children:t}),(0,k.jsx)(a,{type:o,value:n,onChange:e=>r(e.target.value),placeholder:i,inputMode:c,className:`rounded-xl`})]})}function L(e){let{label:n,value:r,options:i,onChange:a}=e;return(0,k.jsxs)(`div`,{className:`space-y-2`,children:[(0,k.jsx)(s,{children:n}),(0,k.jsxs)(f,{value:r,onValueChange:a,children:[(0,k.jsx)(h,{className:`rounded-xl`,children:(0,k.jsx)(m,{})}),(0,k.jsx)(v,{children:i.map(e=>(0,k.jsx)(d,{value:e.value,children:t(e.label)},e.value))})]})]})}function R({docsUrl:e}){return e?(0,k.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,children:(0,k.jsxs)(o,{type:`button`,variant:`outline`,className:`rounded-xl`,children:[(0,k.jsx)(u,{className:`mr-2 h-4 w-4`}),t(`searchProviderOpenDocs`)]})}):null}function z(e){let{draft:n,provider:r,search:i,selectedDocsUrl:a,updateProviderDraft:o}=e;if(r===`bocha`){let{bocha:e}=n.providers;return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(I,{label:t(`apiKey`),value:e.apiKey,onChange:e=>o(`bocha`,{apiKey:e}),placeholder:i.providers.bocha.apiKeyMasked||t(`enterApiKey`),type:`password`}),(0,k.jsx)(I,{label:t(`searchProviderBaseUrl`),value:e.baseUrl,onChange:e=>o(`bocha`,{baseUrl:e})}),(0,k.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,k.jsx)(L,{label:t(`searchProviderSummary`),value:e.summary?`true`:`false`,options:M,onChange:e=>o(`bocha`,{summary:e===`true`})}),(0,k.jsx)(L,{label:t(`searchProviderFreshness`),value:e.freshness,options:A,onChange:e=>o(`bocha`,{freshness:e})})]}),(0,k.jsx)(R,{docsUrl:a??`https://open.bocha.cn`})]})}if(r===`tavily`){let{tavily:e}=n.providers;return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(I,{label:t(`apiKey`),value:e.apiKey,onChange:e=>o(`tavily`,{apiKey:e}),placeholder:i.providers.tavily.apiKeyMasked||t(`enterApiKey`),type:`password`}),(0,k.jsx)(I,{label:t(`searchProviderBaseUrl`),value:e.baseUrl,onChange:e=>o(`tavily`,{baseUrl:e})}),(0,k.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,k.jsx)(L,{label:t(`searchProviderSearchDepth`),value:e.searchDepth,options:j,onChange:e=>o(`tavily`,{searchDepth:e})}),(0,k.jsx)(L,{label:t(`searchProviderIncludeAnswer`),value:e.includeAnswer?`true`:`false`,options:M,onChange:e=>o(`tavily`,{includeAnswer:e===`true`})})]}),(0,k.jsx)(R,{docsUrl:a})]})}let{brave:s}=n.providers;return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(I,{label:t(`apiKey`),value:s.apiKey,onChange:e=>o(`brave`,{apiKey:e}),placeholder:i.providers.brave.apiKeyMasked||t(`enterApiKey`),type:`password`}),(0,k.jsx)(I,{label:t(`searchProviderBaseUrl`),value:s.baseUrl,onChange:e=>o(`brave`,{baseUrl:e})})]})}function B(e){let{draft:n,providers:r,search:i,selectedProvider:a,onSelect:o}=e;return(0,k.jsxs)(x,{children:[(0,k.jsx)(S,{className:`px-4 py-4`,children:(0,k.jsx)(`p`,{className:`text-xs font-semibold uppercase tracking-[0.16em] text-gray-500`,children:t(`searchChannels`)})}),(0,k.jsx)(T,{className:`space-y-2 p-3`,children:r.map(e=>{let r=i.providers[e.name],s=n.enabledProviders.includes(e.name);return(0,k.jsx)(D,{onClick:()=>o(e.name),active:a===e.name,className:`p-3`,children:(0,k.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,k.jsxs)(`div`,{className:`min-w-0`,children:[(0,k.jsx)(`p`,{className:`truncate text-sm font-semibold text-gray-900`,children:e.displayName}),(0,k.jsx)(`p`,{className:`line-clamp-2 text-[11px] text-gray-500`,children:t(N[e.name])})]}),(0,k.jsxs)(`div`,{className:`flex flex-col items-end gap-1`,children:[(0,k.jsx)(`span`,{className:`rounded-full bg-gray-100 px-2 py-0.5 text-[11px] font-medium text-gray-600`,children:r.apiKeySet?t(`searchStatusConfigured`):t(`searchStatusNeedsSetup`)}),s?(0,k.jsx)(`span`,{className:`rounded-full bg-emerald-50 px-2 py-0.5 text-[11px] font-medium text-emerald-700`,children:t(`searchProviderActivated`)}):null]})]})},e.name)})})]})}function V(e){let{initialDraft:n,providers:r,search:i,onSubmit:a,isPending:s}=e,{isMobile:c}=b(),[u,d]=(0,O.useState)(c?null:i.provider),[f,p]=(0,O.useState)(n),m=u&&r.some(e=>e.name===u)?u:c?null:i.provider,h=r.find(e=>e.name===m)??null,g=m?i.providers[m]:null,_=m?f.enabledProviders.includes(m):!1,v=g?.docsUrl??h?.docsUrl;return(0,k.jsxs)(C,{className:`xl:min-h-0`,mobileView:c?m?`detail`:`list`:void 0,onMobileBack:()=>d(null),mobileListLabel:t(`searchPageTitle`),children:[(0,k.jsx)(B,{draft:f,providers:r,search:i,selectedProvider:m??i.provider,onSelect:d}),h?(0,k.jsx)(x,{children:(0,k.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),a(f)},className:`flex min-h-0 flex-1 flex-col`,children:[(0,k.jsx)(S,{className:`px-6 py-5`,children:(0,k.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,k.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-primary text-white`,children:(0,k.jsx)(l,{className:`h-5 w-5`})}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900`,children:h.displayName}),(0,k.jsx)(`p`,{className:`text-sm text-gray-500`,children:h.description})]})]}),(0,k.jsx)(o,{type:`button`,variant:_?`secondary`:`outline`,className:`rounded-xl`,onClick:()=>{let e=_?f.enabledProviders.filter(e=>e!==m):m?[...f.enabledProviders,m]:f.enabledProviders,t={...f,enabledProviders:e};p(t),a(t)},children:t(_?`searchProviderDeactivate`:`searchProviderActivate`)})]})}),(0,k.jsxs)(T,{className:`space-y-6 px-6 py-5`,children:[(0,k.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,k.jsx)(L,{label:t(`searchActiveProvider`),value:f.activeProvider,options:r.map(e=>({value:e.name,label:e.displayName})),onChange:e=>p({...f,activeProvider:e})}),(0,k.jsx)(I,{label:t(`searchDefaultMaxResults`),value:f.maxResults,onChange:e=>p({...f,maxResults:e}),inputMode:`numeric`})]}),(0,k.jsx)(z,{draft:f,provider:m,search:i,selectedDocsUrl:v,updateProviderDraft:(e,t)=>{p(n=>({...n,providers:{...n.providers,[e]:{...n.providers[e],...t}}}))}})]}),(0,k.jsx)(E,{className:`flex justify-end px-6 py-4`,children:(0,k.jsxs)(o,{type:`submit`,disabled:s,children:[(0,k.jsx)(y,{className:`mr-2 h-4 w-4`}),t(s?`saving`:`saveChanges`)]})})]})}):(0,k.jsx)(w,{children:(0,k.jsx)(`p`,{className:`text-sm text-gray-500`,children:t(`searchNoProviderSelected`)})})]})}function H(){let{data:e}=g(),{data:n}=p(),r=_(),a=n?.search??[],o=e?.search;return!o||a.length===0?(0,k.jsx)(`div`,{className:`p-8`,children:t(`loading`)}):(0,k.jsxs)(i,{className:`pb-0 xl:flex xl:h-full xl:min-h-0 xl:flex-col`,children:[(0,k.jsx)(c,{title:t(`searchPageTitle`),description:t(`searchPageDescription`)}),(0,k.jsx)(V,{initialDraft:P(o),providers:a,search:o,onSubmit:e=>r.mutate({data:F(e)}),isPending:r.isPending},JSON.stringify(o))]})}export{H as SearchConfig};
1
+ import{h as e,i as t,m as n,v as r}from"./react-B2X_ph0a.js";import{At as i,Mt as a,Nt as o,jt as s,kt as c}from"./api-DruAcori.js";import{t as l}from"./search-CdhgFNwf.js";import{t as u}from"./external-link-C3usm3se.js";import{J as d,K as f,Q as p,X as m,Y as h,Z as g,_t as _,q as v,rn as y,xt as b}from"./index-GVTiCf1s.js";import{a as x,c as S,i as C,n as w,o as T,s as E,t as D}from"./config-split-page-BFh_Qixx.js";var O=r(e(),1),k=n(),A=[{value:`noLimit`,label:`searchFreshnessNoLimit`},{value:`oneDay`,label:`searchFreshnessOneDay`},{value:`oneWeek`,label:`searchFreshnessOneWeek`},{value:`oneMonth`,label:`searchFreshnessOneMonth`},{value:`oneYear`,label:`searchFreshnessOneYear`}],j=[{value:`basic`,label:`searchDepthBasic`},{value:`advanced`,label:`searchDepthAdvanced`}],M=[{value:`true`,label:`enabled`},{value:`false`,label:`disabled`}],N={bocha:`searchProviderBochaDescription`,tavily:`searchProviderTavilyDescription`,brave:`searchProviderBraveDescription`};function P(e){return{activeProvider:e.provider,enabledProviders:e.enabledProviders,maxResults:String(e.defaults.maxResults),providers:{bocha:{apiKey:``,baseUrl:e.providers.bocha.baseUrl,summary:!!e.providers.bocha.summary,freshness:e.providers.bocha.freshness??`noLimit`},tavily:{apiKey:``,baseUrl:e.providers.tavily.baseUrl,searchDepth:e.providers.tavily.searchDepth??`basic`,includeAnswer:!!e.providers.tavily.includeAnswer},brave:{apiKey:``,baseUrl:e.providers.brave.baseUrl}}}}function F(e){return{provider:e.activeProvider,enabledProviders:e.enabledProviders,defaults:{maxResults:Number(e.maxResults)||10},providers:{bocha:{apiKey:e.providers.bocha.apiKey||void 0,baseUrl:e.providers.bocha.baseUrl,summary:e.providers.bocha.summary,freshness:e.providers.bocha.freshness},tavily:{apiKey:e.providers.tavily.apiKey||void 0,baseUrl:e.providers.tavily.baseUrl,searchDepth:e.providers.tavily.searchDepth,includeAnswer:e.providers.tavily.includeAnswer},brave:{apiKey:e.providers.brave.apiKey||void 0,baseUrl:e.providers.brave.baseUrl}}}}function I(e){let{label:t,value:n,onChange:r,placeholder:i,type:o=`text`,inputMode:c}=e;return(0,k.jsxs)(`div`,{className:`space-y-2`,children:[(0,k.jsx)(s,{children:t}),(0,k.jsx)(a,{type:o,value:n,onChange:e=>r(e.target.value),placeholder:i,inputMode:c,className:`rounded-xl`})]})}function L(e){let{label:n,value:r,options:i,onChange:a}=e;return(0,k.jsxs)(`div`,{className:`space-y-2`,children:[(0,k.jsx)(s,{children:n}),(0,k.jsxs)(f,{value:r,onValueChange:a,children:[(0,k.jsx)(h,{className:`rounded-xl`,children:(0,k.jsx)(m,{})}),(0,k.jsx)(v,{children:i.map(e=>(0,k.jsx)(d,{value:e.value,children:t(e.label)},e.value))})]})]})}function R({docsUrl:e}){return e?(0,k.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,children:(0,k.jsxs)(o,{type:`button`,variant:`outline`,className:`rounded-xl`,children:[(0,k.jsx)(u,{className:`mr-2 h-4 w-4`}),t(`searchProviderOpenDocs`)]})}):null}function z(e){let{draft:n,provider:r,search:i,selectedDocsUrl:a,updateProviderDraft:o}=e;if(r===`bocha`){let{bocha:e}=n.providers;return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(I,{label:t(`apiKey`),value:e.apiKey,onChange:e=>o(`bocha`,{apiKey:e}),placeholder:i.providers.bocha.apiKeyMasked||t(`enterApiKey`),type:`password`}),(0,k.jsx)(I,{label:t(`searchProviderBaseUrl`),value:e.baseUrl,onChange:e=>o(`bocha`,{baseUrl:e})}),(0,k.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,k.jsx)(L,{label:t(`searchProviderSummary`),value:e.summary?`true`:`false`,options:M,onChange:e=>o(`bocha`,{summary:e===`true`})}),(0,k.jsx)(L,{label:t(`searchProviderFreshness`),value:e.freshness,options:A,onChange:e=>o(`bocha`,{freshness:e})})]}),(0,k.jsx)(R,{docsUrl:a??`https://open.bocha.cn`})]})}if(r===`tavily`){let{tavily:e}=n.providers;return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(I,{label:t(`apiKey`),value:e.apiKey,onChange:e=>o(`tavily`,{apiKey:e}),placeholder:i.providers.tavily.apiKeyMasked||t(`enterApiKey`),type:`password`}),(0,k.jsx)(I,{label:t(`searchProviderBaseUrl`),value:e.baseUrl,onChange:e=>o(`tavily`,{baseUrl:e})}),(0,k.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,k.jsx)(L,{label:t(`searchProviderSearchDepth`),value:e.searchDepth,options:j,onChange:e=>o(`tavily`,{searchDepth:e})}),(0,k.jsx)(L,{label:t(`searchProviderIncludeAnswer`),value:e.includeAnswer?`true`:`false`,options:M,onChange:e=>o(`tavily`,{includeAnswer:e===`true`})})]}),(0,k.jsx)(R,{docsUrl:a})]})}let{brave:s}=n.providers;return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(I,{label:t(`apiKey`),value:s.apiKey,onChange:e=>o(`brave`,{apiKey:e}),placeholder:i.providers.brave.apiKeyMasked||t(`enterApiKey`),type:`password`}),(0,k.jsx)(I,{label:t(`searchProviderBaseUrl`),value:s.baseUrl,onChange:e=>o(`brave`,{baseUrl:e})})]})}function B(e){let{draft:n,providers:r,search:i,selectedProvider:a,onSelect:o}=e;return(0,k.jsxs)(x,{children:[(0,k.jsx)(S,{className:`px-4 py-4`,children:(0,k.jsx)(`p`,{className:`text-xs font-semibold uppercase tracking-[0.16em] text-gray-500`,children:t(`searchChannels`)})}),(0,k.jsx)(T,{className:`space-y-2 p-3`,children:r.map(e=>{let r=i.providers[e.name],s=n.enabledProviders.includes(e.name);return(0,k.jsx)(D,{onClick:()=>o(e.name),active:a===e.name,className:`p-3`,children:(0,k.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,k.jsxs)(`div`,{className:`min-w-0`,children:[(0,k.jsx)(`p`,{className:`truncate text-sm font-semibold text-gray-900`,children:e.displayName}),(0,k.jsx)(`p`,{className:`line-clamp-2 text-[11px] text-gray-500`,children:t(N[e.name])})]}),(0,k.jsxs)(`div`,{className:`flex flex-col items-end gap-1`,children:[(0,k.jsx)(`span`,{className:`rounded-full bg-gray-100 px-2 py-0.5 text-[11px] font-medium text-gray-600`,children:r.apiKeySet?t(`searchStatusConfigured`):t(`searchStatusNeedsSetup`)}),s?(0,k.jsx)(`span`,{className:`rounded-full bg-emerald-50 px-2 py-0.5 text-[11px] font-medium text-emerald-700`,children:t(`searchProviderActivated`)}):null]})]})},e.name)})})]})}function V(e){let{initialDraft:n,providers:r,search:i,onSubmit:a,isPending:s}=e,{isMobile:c}=b(),[u,d]=(0,O.useState)(c?null:i.provider),[f,p]=(0,O.useState)(n),m=u&&r.some(e=>e.name===u)?u:c?null:i.provider,h=r.find(e=>e.name===m)??null,g=m?i.providers[m]:null,_=m?f.enabledProviders.includes(m):!1,v=g?.docsUrl??h?.docsUrl;return(0,k.jsxs)(C,{className:`xl:min-h-0`,mobileView:c?m?`detail`:`list`:void 0,onMobileBack:()=>d(null),mobileListLabel:t(`searchPageTitle`),children:[(0,k.jsx)(B,{draft:f,providers:r,search:i,selectedProvider:m??i.provider,onSelect:d}),h?(0,k.jsx)(x,{children:(0,k.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),a(f)},className:`flex min-h-0 flex-1 flex-col`,children:[(0,k.jsx)(S,{className:`px-6 py-5`,children:(0,k.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,k.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-primary text-white`,children:(0,k.jsx)(l,{className:`h-5 w-5`})}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900`,children:h.displayName}),(0,k.jsx)(`p`,{className:`text-sm text-gray-500`,children:h.description})]})]}),(0,k.jsx)(o,{type:`button`,variant:_?`secondary`:`outline`,className:`rounded-xl`,onClick:()=>{let e=_?f.enabledProviders.filter(e=>e!==m):m?[...f.enabledProviders,m]:f.enabledProviders,t={...f,enabledProviders:e};p(t),a(t)},children:t(_?`searchProviderDeactivate`:`searchProviderActivate`)})]})}),(0,k.jsxs)(T,{className:`space-y-6 px-6 py-5`,children:[(0,k.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,k.jsx)(L,{label:t(`searchActiveProvider`),value:f.activeProvider,options:r.map(e=>({value:e.name,label:e.displayName})),onChange:e=>p({...f,activeProvider:e})}),(0,k.jsx)(I,{label:t(`searchDefaultMaxResults`),value:f.maxResults,onChange:e=>p({...f,maxResults:e}),inputMode:`numeric`})]}),(0,k.jsx)(z,{draft:f,provider:m,search:i,selectedDocsUrl:v,updateProviderDraft:(e,t)=>{p(n=>({...n,providers:{...n.providers,[e]:{...n.providers[e],...t}}}))}})]}),(0,k.jsx)(E,{className:`flex justify-end px-6 py-4`,children:(0,k.jsxs)(o,{type:`submit`,disabled:s,children:[(0,k.jsx)(y,{className:`mr-2 h-4 w-4`}),t(s?`saving`:`saveChanges`)]})})]})}):(0,k.jsx)(w,{children:(0,k.jsx)(`p`,{className:`text-sm text-gray-500`,children:t(`searchNoProviderSelected`)})})]})}function H(){let{data:e}=g(),{data:n}=p(),r=_(),a=n?.search??[],o=e?.search;return!o||a.length===0?(0,k.jsx)(`div`,{className:`p-8`,children:t(`loading`)}):(0,k.jsxs)(i,{className:`pb-0 xl:flex xl:h-full xl:min-h-0 xl:flex-col`,children:[(0,k.jsx)(c,{title:t(`searchPageTitle`),description:t(`searchPageDescription`)}),(0,k.jsx)(V,{initialDraft:P(o),providers:a,search:o,onSubmit:e=>r.mutate({data:F(e)}),isPending:r.isPending},JSON.stringify(o))]})}export{H as SearchConfig};
@@ -1,3 +1,3 @@
1
- import{h as e,i as t,m as n,v as r}from"./react-B2X_ph0a.js";import{At as i,Dt as a,Et as o,Lt as s,Mt as c,Nt as l,Ot as u,Tt as d,ft as f,jt as p,kt as m,wt as h}from"./api-DruAcori.js";import{t as g}from"./plus-BcIC8dG1.js";import{t as _}from"./save-D10M5vQg.js";import{J as v,K as y,Kt as b,X as x,Y as S,Z as C,q as w,vt as T}from"./index-D2H2CKYR.js";var E=r(e(),1),D=n(),O=[`env`,`file`,`exec`];function k(e=``){return{alias:e,source:`env`,prefix:``,path:``,command:``,argsText:``,cwd:``,timeoutMs:5e3}}function A(){return{path:``,source:`env`,provider:``,id:``}}function j(e,t){return t.source===`env`?{...k(e),source:`env`,prefix:t.prefix??``}:t.source===`file`?{...k(e),source:`file`,path:t.path}:{...k(e),source:`exec`,command:t.command,argsText:(t.args??[]).join(`
1
+ import{h as e,i as t,m as n,v as r}from"./react-B2X_ph0a.js";import{At as i,Dt as a,Et as o,Lt as s,Mt as c,Nt as l,Ot as u,Tt as d,ft as f,jt as p,kt as m,wt as h}from"./api-DruAcori.js";import{t as g}from"./plus-BcIC8dG1.js";import{t as _}from"./save-D10M5vQg.js";import{J as v,K as y,Kt as b,X as x,Y as S,Z as C,q as w,vt as T}from"./index-GVTiCf1s.js";var E=r(e(),1),D=n(),O=[`env`,`file`,`exec`];function k(e=``){return{alias:e,source:`env`,prefix:``,path:``,command:``,argsText:``,cwd:``,timeoutMs:5e3}}function A(){return{path:``,source:`env`,provider:``,id:``}}function j(e,t){return t.source===`env`?{...k(e),source:`env`,prefix:t.prefix??``}:t.source===`file`?{...k(e),source:`file`,path:t.path}:{...k(e),source:`exec`,command:t.command,argsText:(t.args??[]).join(`
2
2
  `),cwd:t.cwd??``,timeoutMs:t.timeoutMs??5e3}}function M(e){return e.source===`env`?{source:`env`,...e.prefix.trim()?{prefix:e.prefix.trim()}:{}}:e.source===`file`?{source:`file`,path:e.path.trim(),format:`json`}:{source:`exec`,command:e.command.trim(),args:e.argsText.split(`
3
3
  `).map(e=>e.trim()).filter(Boolean),...e.cwd.trim()?{cwd:e.cwd.trim()}:{},timeoutMs:Math.max(1,Math.trunc(e.timeoutMs||5e3))}}function N(e){return e?{enabled:!!e.enabled,defaultEnv:e.defaults.env??``,defaultFile:e.defaults.file??``,defaultExec:e.defaults.exec??``,providers:Object.entries(e.providers).map(([e,t])=>j(e,t)),refs:Object.entries(e.refs).map(([e,t])=>({path:e,source:t.source,provider:t.provider??``,id:t.id}))}:{enabled:!0,defaultEnv:``,defaultFile:``,defaultExec:``,providers:[],refs:[]}}function P(e){return{enabled:e.enabled,defaults:{env:e.defaultEnv||null,file:e.defaultFile||null,exec:e.defaultExec||null},providers:Object.fromEntries(e.providers.map(e=>[e.alias.trim(),M(e)]).filter(([e])=>e)),refs:Object.fromEntries(e.refs.map(e=>[e.path.trim(),{source:e.source,...e.provider.trim()?{provider:e.provider.trim()}:{},id:e.id.trim()}]).filter(([e,t])=>e&&t.id))}}function F(e){let{defaultEnv:n,defaultFile:r,defaultExec:i,providerAliases:s,onChange:c}=e;return(0,D.jsxs)(h,{children:[(0,D.jsxs)(a,{children:[(0,D.jsx)(u,{children:t(`secrets`)}),(0,D.jsx)(o,{children:t(`secretsEnabledHelp`)})]}),(0,D.jsx)(d,{className:`space-y-4`,children:[{label:t(`defaultEnvProvider`),value:n,key:`defaultEnv`},{label:t(`defaultFileProvider`),value:r,key:`defaultFile`},{label:t(`defaultExecProvider`),value:i,key:`defaultExec`}].map(e=>(0,D.jsxs)(`div`,{className:`space-y-2`,children:[(0,D.jsx)(p,{children:e.label}),(0,D.jsxs)(y,{value:e.value||`__none__`,onValueChange:t=>c(e.key,t===`__none__`?``:t),children:[(0,D.jsx)(S,{children:(0,D.jsx)(x,{placeholder:t(`noneOption`)})}),(0,D.jsxs)(w,{children:[(0,D.jsx)(v,{value:`__none__`,children:t(`noneOption`)}),s.map(e=>(0,D.jsx)(v,{value:e,children:e},e))]})]})]},e.key))})]})}function I(e){let{providers:n,onUpdate:r,onRemove:i,onAdd:s}=e;return(0,D.jsxs)(h,{children:[(0,D.jsxs)(a,{children:[(0,D.jsx)(u,{children:t(`secretProvidersTitle`)}),(0,D.jsx)(o,{children:t(`secretProvidersDescription`)})]}),(0,D.jsxs)(d,{className:`space-y-3`,children:[n.map((e,n)=>(0,D.jsxs)(`div`,{className:`space-y-3 rounded-xl border border-gray-200 p-3`,children:[(0,D.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-3`,children:[(0,D.jsx)(c,{value:e.alias,onChange:e=>r(n,{alias:e.target.value}),placeholder:t(`providerAlias`)}),(0,D.jsxs)(y,{value:e.source,onValueChange:e=>r(n,{source:e}),children:[(0,D.jsx)(S,{children:(0,D.jsx)(x,{})}),(0,D.jsx)(w,{children:O.map(e=>(0,D.jsx)(v,{value:e,children:e},e))})]}),(0,D.jsxs)(l,{type:`button`,variant:`outline`,onClick:()=>i(n),children:[(0,D.jsx)(b,{className:`mr-2 h-4 w-4`}),t(`removeProvider`)]})]}),e.source===`env`?(0,D.jsx)(c,{value:e.prefix,onChange:e=>r(n,{prefix:e.target.value}),placeholder:t(`envPrefix`)}):null,e.source===`file`?(0,D.jsx)(c,{value:e.path,onChange:e=>r(n,{path:e.target.value}),placeholder:t(`secretFilePath`)}):null,e.source===`exec`?(0,D.jsxs)(`div`,{className:`space-y-2`,children:[(0,D.jsx)(c,{value:e.command,onChange:e=>r(n,{command:e.target.value}),placeholder:t(`secretExecCommand`)}),(0,D.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:e.argsText,onChange:e=>r(n,{argsText:e.target.value}),placeholder:t(`secretExecArgs`)}),(0,D.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 md:grid-cols-2`,children:[(0,D.jsx)(c,{value:e.cwd,onChange:e=>r(n,{cwd:e.target.value}),placeholder:t(`secretExecCwd`)}),(0,D.jsx)(c,{type:`number`,min:1,value:e.timeoutMs,onChange:e=>r(n,{timeoutMs:Number.parseInt(e.target.value,10)||5e3}),placeholder:t(`secretExecTimeoutMs`)})]})]}):null]},`provider-${n}`)),(0,D.jsxs)(l,{type:`button`,variant:`outline`,onClick:s,children:[(0,D.jsx)(g,{className:`mr-2 h-4 w-4`}),t(`addSecretProvider`)]})]})]})}function L(e){let{refs:n,providerAliases:r,onUpdate:i,onRemove:s,onAdd:f}=e;return(0,D.jsxs)(h,{children:[(0,D.jsxs)(a,{children:[(0,D.jsx)(u,{children:t(`secretRefsTitle`)}),(0,D.jsx)(o,{children:t(`secretRefsDescription`)})]}),(0,D.jsxs)(d,{className:`space-y-3`,children:[n.map((e,n)=>(0,D.jsx)(`div`,{className:`space-y-3 rounded-xl border border-gray-200 p-3`,children:(0,D.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:[(0,D.jsx)(c,{value:e.path,onChange:e=>i(n,{path:e.target.value}),placeholder:t(`secretConfigPath`)}),(0,D.jsx)(c,{value:e.id,onChange:e=>i(n,{id:e.target.value}),placeholder:t(`secretId`)}),(0,D.jsxs)(y,{value:e.source,onValueChange:e=>i(n,{source:e}),children:[(0,D.jsx)(S,{children:(0,D.jsx)(x,{})}),(0,D.jsx)(w,{children:O.map(e=>(0,D.jsx)(v,{value:e,children:e},e))})]}),(0,D.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto] gap-2`,children:[(0,D.jsxs)(y,{value:e.provider||`__none__`,onValueChange:e=>i(n,{provider:e===`__none__`?``:e}),children:[(0,D.jsx)(S,{children:(0,D.jsx)(x,{placeholder:t(`secretProviderAlias`)})}),(0,D.jsxs)(w,{children:[(0,D.jsx)(v,{value:`__none__`,children:t(`noneOption`)}),r.map(e=>(0,D.jsx)(v,{value:e,children:e},e))]})]}),(0,D.jsx)(l,{type:`button`,variant:`outline`,onClick:()=>s(n),children:(0,D.jsx)(b,{className:`h-4 w-4`})})]})]})},`ref-${n}`)),(0,D.jsxs)(l,{type:`button`,variant:`outline`,onClick:f,children:[(0,D.jsx)(g,{className:`mr-2 h-4 w-4`}),t(`addSecretRef`)]})]})]})}function R(e){let{initialState:n,isPending:r,onSubmit:c}=e,[p,g]=(0,E.useState)(n),v=(0,E.useMemo)(()=>{let e=p.providers.map(e=>e.alias.trim()).filter(Boolean);return Array.from(new Set(e))},[p.providers]);return(0,D.jsxs)(i,{className:`space-y-6`,children:[(0,D.jsx)(m,{title:t(`secretsPageTitle`),description:t(`secretsPageDescription`)}),(0,D.jsxs)(h,{children:[(0,D.jsxs)(a,{children:[(0,D.jsx)(u,{children:t(`secrets`)}),(0,D.jsx)(o,{children:t(`secretsEnabledHelp`)})]}),(0,D.jsxs)(d,{className:`space-y-4`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between rounded-xl border border-gray-200 p-3`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`p`,{className:`text-sm font-medium text-gray-800`,children:t(`enabled`)}),(0,D.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`secretsEnabledHelp`)})]}),(0,D.jsx)(f,{checked:p.enabled,onCheckedChange:e=>g(t=>({...t,enabled:e}))})]}),(0,D.jsx)(F,{defaultEnv:p.defaultEnv,defaultFile:p.defaultFile,defaultExec:p.defaultExec,providerAliases:v,onChange:(e,t)=>g(n=>({...n,[e]:t}))})]})]}),(0,D.jsx)(I,{providers:p.providers,onUpdate:(e,t)=>{g(n=>({...n,providers:n.providers.map((n,r)=>r===e?{...n,...t}:n)}))},onRemove:e=>g(t=>({...t,providers:t.providers.filter((t,n)=>n!==e)})),onAdd:()=>g(e=>({...e,providers:[...e.providers,k()]}))}),(0,D.jsx)(L,{refs:p.refs,providerAliases:v,onUpdate:(e,t)=>{g(n=>({...n,refs:n.refs.map((n,r)=>r===e?{...n,...t}:n)}))},onRemove:e=>g(t=>({...t,refs:t.refs.filter((t,n)=>n!==e)})),onAdd:()=>g(e=>({...e,refs:[...e.refs,A()]}))}),(0,D.jsx)(`div`,{className:`flex justify-end`,children:(0,D.jsxs)(l,{type:`button`,onClick:()=>{try{let e={};for(let[n,r]of p.providers.entries()){let i=r.alias.trim();if(!i)throw Error(`${t(`providerAlias`)} #${n+1} ${t(`isRequired`)}`);if(e[i])throw Error(`${t(`providerAlias`)}: ${i} (${t(`duplicate`)})`);if(r.source===`file`&&!r.path.trim())throw Error(`${t(`secretFilePath`)} #${n+1} ${t(`isRequired`)}`);if(r.source===`exec`&&!r.command.trim())throw Error(`${t(`secretExecCommand`)} #${n+1} ${t(`isRequired`)}`);e[i]=M(r)}let n={};for(let[r,i]of p.refs.entries()){let a=i.path.trim(),o=i.id.trim();if(!a)throw Error(`${t(`secretConfigPath`)} #${r+1} ${t(`isRequired`)}`);if(!o)throw Error(`${t(`secretId`)} #${r+1} ${t(`isRequired`)}`);let s=i.provider.trim();if(s&&!e[s])throw Error(`${t(`secretProviderAlias`)}: ${s} ${t(`notFound`)}`);n[a]={source:i.source,...s?{provider:s}:{},id:o}}c({enabled:p.enabled,defaultEnv:p.defaultEnv.trim(),defaultFile:p.defaultFile.trim(),defaultExec:p.defaultExec.trim(),providers:Object.entries(e).map(([e,t])=>j(e,t)),refs:Object.entries(n).map(([e,t])=>({path:e,source:t.source,provider:t.provider??``,id:t.id}))})}catch(e){s.error(e instanceof Error?e.message:String(e))}},disabled:r,children:[(0,D.jsx)(_,{className:`mr-2 h-4 w-4`}),t(r?`saving`:`save`)]})})]})}function z(){let{data:e,isLoading:n}=C(),r=T();return n?(0,D.jsx)(`div`,{className:`p-8 text-gray-400`,children:t(`loading`)}):(0,D.jsx)(R,{initialState:N(e?.secrets),isPending:r.isPending,onSubmit:e=>r.mutate({data:P(e)})},JSON.stringify(e?.secrets??null))}export{z as SecretsConfig};
package/dist/index.html CHANGED
@@ -78,7 +78,7 @@
78
78
  })();
79
79
  </script>
80
80
  <title>NextClaw</title>
81
- <script type="module" crossorigin src="/assets/index-D2H2CKYR.js"></script>
81
+ <script type="module" crossorigin src="/assets/index-GVTiCf1s.js"></script>
82
82
  <link rel="modulepreload" crossorigin href="/assets/react-B2X_ph0a.js">
83
83
  <link rel="modulepreload" crossorigin href="/assets/createLucideIcon-Br1EFMEr.js">
84
84
  <link rel="modulepreload" crossorigin href="/assets/search-CdhgFNwf.js">
@@ -89,7 +89,7 @@
89
89
  <link rel="modulepreload" crossorigin href="/assets/x-Chb07O-Y.js">
90
90
  <link rel="modulepreload" crossorigin href="/assets/doc-browser-route-registry.utils-x5ijvk0u.js">
91
91
  <link rel="modulepreload" crossorigin href="/assets/doc-browser-context-DB6TTHeE.js">
92
- <link rel="modulepreload" crossorigin href="/assets/doc-browser-B2OFjScU.js">
92
+ <link rel="modulepreload" crossorigin href="/assets/doc-browser-BI7HSaMK.js">
93
93
  <link rel="modulepreload" crossorigin href="/assets/api-DruAcori.js">
94
94
  <link rel="modulepreload" crossorigin href="/assets/dist-rzakR_bu.js">
95
95
  <link rel="modulepreload" crossorigin href="/assets/dist-CpwDZDtv.js">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/ui",
3
- "version": "0.12.35-beta.7",
3
+ "version": "0.12.35",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -28,13 +28,13 @@
28
28
  "tailwind-merge": "^2.5.4",
29
29
  "zod": "^3.23.8",
30
30
  "zustand": "^5.0.2",
31
- "@nextclaw/client-sdk": "0.1.14-beta.7",
32
- "@nextclaw/ncp-http-agent-client": "0.3.30-beta.7",
33
- "@nextclaw/ncp-react": "0.4.38-beta.7",
34
- "@nextclaw/shared": "0.1.12-beta.7",
35
- "@nextclaw/agent-chat-ui": "0.3.25-beta.7",
36
- "@nextclaw/ncp": "0.5.18-beta.7",
37
- "@nextclaw/agent-chat": "0.1.23-beta.7"
31
+ "@nextclaw/agent-chat": "0.1.23",
32
+ "@nextclaw/agent-chat-ui": "0.3.25",
33
+ "@nextclaw/client-sdk": "0.1.14",
34
+ "@nextclaw/ncp": "0.5.18",
35
+ "@nextclaw/ncp-http-agent-client": "0.3.30",
36
+ "@nextclaw/shared": "0.1.12",
37
+ "@nextclaw/ncp-react": "0.4.38"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@testing-library/react": "^16.3.0",
@@ -87,6 +87,7 @@ describe('PanelAppBridgeManager', () => {
87
87
  source: contentWindow,
88
88
  } as MessageEvent,
89
89
  iframe,
90
+ iframeInstanceId: 'tab-1:0:0',
90
91
  tab: {
91
92
  currentUrl: '/api/panel-apps/mood-calendar/content',
92
93
  history: [],
@@ -163,6 +164,7 @@ describe('PanelAppBridgeManager', () => {
163
164
  source: contentWindow,
164
165
  } as MessageEvent,
165
166
  iframe,
167
+ iframeInstanceId: 'tab-1:0:0',
166
168
  tab: {
167
169
  currentUrl: '/api/panel-apps/mood-calendar/content',
168
170
  history: [],
@@ -192,4 +194,70 @@ describe('PanelAppBridgeManager', () => {
192
194
  type: 'nextclaw:panel-app-service-actions:response',
193
195
  }, '*');
194
196
  });
197
+
198
+ it('creates a fresh bridge session for each iframe instance', async () => {
199
+ const manager = new PanelAppBridgeManager({
200
+ requestAuthorization: mocks.requestAuthorization,
201
+ } as unknown as ServiceActionAuthorizationManager);
202
+ const postMessage = vi.fn();
203
+ const contentWindow = { postMessage } as unknown as Window;
204
+ const iframe = { contentWindow } as HTMLIFrameElement;
205
+ mocks.createBridgeSession
206
+ .mockResolvedValueOnce({
207
+ expiresAt: '2026-05-28T00:00:00.000Z',
208
+ id: 'session-1',
209
+ panelAppId: 'mood-calendar',
210
+ tabId: 'tab-1',
211
+ token: 'token-1',
212
+ })
213
+ .mockResolvedValueOnce({
214
+ expiresAt: '2026-05-28T00:00:00.000Z',
215
+ id: 'session-2',
216
+ panelAppId: 'mood-calendar',
217
+ tabId: 'tab-1',
218
+ token: 'token-2',
219
+ });
220
+ mocks.listServiceActions.mockResolvedValue({ actions: [] });
221
+
222
+ for (const [requestId, iframeInstanceId] of [
223
+ ['request-1', 'tab-1:0:0'],
224
+ ['request-2', 'tab-1:0:0'],
225
+ ['request-3', 'tab-1:0:1'],
226
+ ]) {
227
+ manager.handleIframeMessage({
228
+ event: {
229
+ data: {
230
+ method: 'list',
231
+ requestId,
232
+ type: 'nextclaw:panel-app-service-actions:request',
233
+ },
234
+ source: contentWindow,
235
+ } as MessageEvent,
236
+ iframe,
237
+ iframeInstanceId,
238
+ tab: {
239
+ currentUrl: '/api/panel-apps/mood-calendar/content',
240
+ history: [],
241
+ historyIndex: 0,
242
+ id: 'tab-1',
243
+ kind: 'content',
244
+ navVersion: 0,
245
+ title: 'Mood Calendar',
246
+ },
247
+ });
248
+ }
249
+
250
+ await waitFor(() => expect(postMessage).toHaveBeenCalledTimes(3));
251
+
252
+ expect(mocks.createBridgeSession).toHaveBeenCalledTimes(2);
253
+ expect(mocks.listServiceActions).toHaveBeenNthCalledWith(1, {
254
+ bridgeSessionToken: 'token-1',
255
+ });
256
+ expect(mocks.listServiceActions).toHaveBeenNthCalledWith(2, {
257
+ bridgeSessionToken: 'token-1',
258
+ });
259
+ expect(mocks.listServiceActions).toHaveBeenNthCalledWith(3, {
260
+ bridgeSessionToken: 'token-2',
261
+ });
262
+ });
195
263
  });
@@ -55,14 +55,14 @@ export class PanelAppBridgeManager {
55
55
 
56
56
  constructor(private readonly authorizationManager: ServiceActionAuthorizationManager) {}
57
57
 
58
- handleIframeMessage = ({ event, iframe, tab }: DocBrowserIframeMessageParams): void => {
58
+ handleIframeMessage = ({ event, iframe, iframeInstanceId, tab }: DocBrowserIframeMessageParams): void => {
59
59
  if (!this.isBridgeRequest(event.data)) {
60
60
  return;
61
61
  }
62
62
  if (!iframe?.contentWindow || event.source !== iframe.contentWindow) {
63
63
  return;
64
64
  }
65
- void this.handleBridgeRequest({ event, iframe, tab }, event.data);
65
+ void this.handleBridgeRequest({ event, iframe, iframeInstanceId, tab }, event.data);
66
66
  };
67
67
 
68
68
  private handleBridgeRequest = async (
@@ -268,7 +268,7 @@ export class PanelAppBridgeManager {
268
268
  params: DocBrowserIframeMessageParams,
269
269
  ): Promise<PanelAppBridgeSessionView> => {
270
270
  const panelAppId = this.readPanelAppId(params.tab.currentUrl);
271
- const key = `${params.tab.id}:${panelAppId}`;
271
+ const key = `${params.iframeInstanceId}:${panelAppId}`;
272
272
  let session = this.sessions.get(key);
273
273
  if (!session) {
274
274
  session = nextclawClient.panelApps.createBridgeSession({