nextclaw 0.27.1 → 0.27.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/app/index.js.map +1 -1
- package/package.json +16 -16
- package/ui-dist/assets/{api-DGG69ZcJ.js → api-D5UCLVE_.js} +3 -3
- package/ui-dist/assets/app-presenter-provider-DcpcRgLn.js +106 -0
- package/ui-dist/assets/{appearance-settings-page-Byr55LGb.js → appearance-settings-page-yJR6Kt9c.js} +1 -1
- package/ui-dist/assets/{book-open-BhaS5BJv.js → book-open-WsEnuW9P.js} +1 -1
- package/ui-dist/assets/{card-Bcr5YM8F.js → card-xVrS1b1T.js} +1 -1
- package/ui-dist/assets/{channels-list-page-C_x83ZCT.js → channels-list-page-CAWuTHSM.js} +1 -1
- package/ui-dist/assets/{chat-page-CEavSS6B.js → chat-page-CXYXMIQQ.js} +1 -1
- package/ui-dist/assets/{config-split-page-RXAoLeNv.js → config-split-page-xj0UtMow.js} +1 -1
- package/ui-dist/assets/{confirm-dialog-o_VPKvVD.js → confirm-dialog-e2YCUzt1.js} +1 -1
- package/ui-dist/assets/{desktop-update-config-DEOMOsDN.js → desktop-update-config-D5NIaimo.js} +1 -1
- package/ui-dist/assets/{dist-C87P4QWA.js → dist-Ca-jiFrK.js} +1 -1
- package/ui-dist/assets/doc-browser-B2tNEKrJ.js +1 -0
- package/ui-dist/assets/{doc-browser-DQ75iUkA.js → doc-browser-CZX6I6CU.js} +1 -1
- package/ui-dist/assets/{doc-browser-context-tE0--wSa.js → doc-browser-context-CGz0LULR.js} +1 -1
- package/ui-dist/assets/{eye-DL9QkrKg.js → eye-B30J471A.js} +1 -1
- package/ui-dist/assets/{form-actions-J0tIaUdK.js → form-actions-CnSzu3WD.js} +1 -1
- package/ui-dist/assets/{index-BFIZUZP3.js → index-6Esxu-Pp.js} +2 -2
- package/ui-dist/assets/index-BzSgA8tR.css +1 -0
- package/ui-dist/assets/loader-circle-DjwSRQHW.js +1 -0
- package/ui-dist/assets/{logo-badge-BYTbZbOF.js → logo-badge-CISsltAo.js} +1 -1
- package/ui-dist/assets/mcp-marketplace-page-BZa7p7Qf.js +1 -0
- package/ui-dist/assets/{mcp-marketplace-page-COWlzeP1.js → mcp-marketplace-page-CPcPzMUQ.js} +1 -1
- package/ui-dist/assets/{model-config-page-oNqnMXNY.js → model-config-page-D6ex3_NM.js} +1 -1
- package/ui-dist/assets/{navigation-link-Dk6VdDkc.js → navigation-link-qPPUiLt0.js} +1 -1
- package/ui-dist/assets/plus-C45awBb1.js +1 -0
- package/ui-dist/assets/{popover-Txwrum65.js → popover-DHx55dbc.js} +1 -1
- package/ui-dist/assets/{provider-scoped-model-input-B7rQM4b6.js → provider-scoped-model-input-1TJxAhx6.js} +1 -1
- package/ui-dist/assets/{providers-config-page-CP-OnvLK.js → providers-config-page-BwHtHIPe.js} +1 -1
- package/ui-dist/assets/{react-B0LbRnAE.js → react-DerwD2EA.js} +1 -1
- package/ui-dist/assets/{refresh-cw-C84mMku5.js → refresh-cw-C7bynrWX.js} +1 -1
- package/ui-dist/assets/remote-CPpTKDgX.js +1 -0
- package/ui-dist/assets/rotate-cw-Bhx0XkQP.js +1 -0
- package/ui-dist/assets/{runtime-config-page-CIGtssWi.js → runtime-config-page-CMLVC5UV.js} +1 -1
- package/ui-dist/assets/{save-R_qyrHpa.js → save-CsRsFtHS.js} +1 -1
- package/ui-dist/assets/{search-UKxiouNi.js → search-D0HtJIL-.js} +1 -1
- package/ui-dist/assets/{search-config-page-DzkpSGFH.js → search-config-page-n1GElgij.js} +1 -1
- package/ui-dist/assets/{secrets-config-page-DhoLYm7Z.js → secrets-config-page-DbUc3Ggi.js} +1 -1
- package/ui-dist/assets/security-config-n2WHhHXV.js +1 -0
- package/ui-dist/assets/{select-CYHT8P5S.js → select-C1zfp9zM.js} +1 -1
- package/ui-dist/assets/{settings-2-DGh4bGSi.js → settings-2-Ba3cLSN2.js} +1 -1
- package/ui-dist/assets/skeleton-DL5npsVL.js +1 -0
- package/ui-dist/assets/{tabs-BCihm1zK.js → tabs-DmKgMKzb.js} +1 -1
- package/ui-dist/assets/{tag-chip-De0iz4o2.js → tag-chip-2vwlVUwM.js} +1 -1
- package/ui-dist/assets/{trash-2-Bo3DWiju.js → trash-2-CUpWjNHu.js} +1 -1
- package/ui-dist/assets/{use-config-DCzwgChy.js → use-config-BvxDWV-M.js} +1 -1
- package/ui-dist/assets/{use-confirm-dialog-WZ94CehU.js → use-confirm-dialog-CeUEE4p5.js} +1 -1
- package/ui-dist/assets/{use-viewport-layout-CZ-3pMne.js → use-viewport-layout-DaKJ-kap.js} +1 -1
- package/ui-dist/assets/x-DGdYT7rH.js +1 -0
- package/ui-dist/index.html +28 -28
- package/ui-dist/assets/app-presenter-provider-Dp90n1Va.js +0 -106
- package/ui-dist/assets/doc-browser-BuGh646I.js +0 -1
- package/ui-dist/assets/index-B2YF-7Yw.css +0 -1
- package/ui-dist/assets/loader-circle-CAnHHSrY.js +0 -1
- package/ui-dist/assets/mcp-marketplace-page-CaUFv37E.js +0 -1
- package/ui-dist/assets/plus-DjdTWPjQ.js +0 -1
- package/ui-dist/assets/remote-_L4pTEaW.js +0 -1
- package/ui-dist/assets/rotate-cw-DQJhDnjg.js +0 -1
- package/ui-dist/assets/security-config-yraYoy9s.js +0 -1
- package/ui-dist/assets/skeleton-BQuylYFO.js +0 -1
- package/ui-dist/assets/x-NZxXyqW1.js +0 -1
package/ui-dist/assets/{providers-config-page-CP-OnvLK.js → providers-config-page-BwHtHIPe.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e}from"./chunk-DseTPa7n.js";import{a as t,h as n,p as r,r as i,u as a}from"./react-B0LbRnAE.js";import{Qt as o,en as s,nn as c,on as l,tn as u,wt as d,yn as f}from"./api-DGG69ZcJ.js";import{c as p}from"./dist-C87P4QWA.js";import{i as m,r as h,t as g}from"./popover-Txwrum65.js";import{t as _}from"./confirm-dialog-o_VPKvVD.js";import{t as v}from"./search-UKxiouNi.js";import{C as y,a as b,i as x,n as S,r as C,t as w}from"./select-CYHT8P5S.js";import{n as T,t as E}from"./eye-DL9QkrKg.js";import{i as D,t as O}from"./use-viewport-layout-CZ-3pMne.js";import{t as k}from"./plus-DjdTWPjQ.js";import{t as A}from"./settings-2-DGh4bGSi.js";import{t as j}from"./trash-2-Bo3DWiju.js";import{t as M}from"./x-NZxXyqW1.js";import{n as N,t as P}from"./logo-badge-BYTbZbOF.js";import{t as F}from"./host-capabilities-B-TtABsP.js";import{a as I,o as L,s as R,t as z}from"./provider-models-CXUgDxGR.js";import{t as ee}from"./form-actions-J0tIaUdK.js";import{a as B,c as V,d as te,f as ne,h as H,i as U,l as re,r as ie,s as W,u as ae}from"./use-config-DCzwgChy.js";import{t as G}from"./config-hints-S3g-UVZb.js";import{a as K,c as q,i as J,l as oe,n as se,o as ce,r as le,s as ue}from"./config-split-page-RXAoLeNv.js";var de=p(`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`}]]),fe=p(`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`}]]),Y=e(n(),1),X=r();function pe({isSet:e,className:t,value:n,onChange:r,placeholder:i,...o}){let[s,l]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(!1),p=typeof n==`string`&&n.length>0;return(0,X.jsxs)(`div`,{className:`relative`,children:[e&&!p&&!d?(0,X.jsx)(`div`,{onClick:()=>f(!0),className:a(`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`,t),children:`••••••••••••`}):(0,X.jsx)(u,{type:s?`text`:`password`,className:a(`pr-12`,t),value:n,onChange:r,onBlur:()=>{p||f(!1)},placeholder:i,autoFocus:d,...o}),(0,X.jsx)(`div`,{className:`absolute right-2 top-1/2 -translate-y-1/2 flex gap-1`,children:(e||p)&&(0,X.jsx)(c,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>l(!s),children:s?(0,X.jsx)(fe,{className:`h-4 w-4`}):(0,X.jsx)(E,{className:`h-4 w-4`})})})]})}function me({value:e,onChange:t,className:n}){let r=e?Object.entries(e):[],o=(e,n,i)=>{let a=[...r];a[e]=[n,i],t(Object.fromEntries(a))},s=()=>{t({...e,"":``})},l=e=>{let n=r.filter((t,n)=>n!==e);t(Object.fromEntries(n))};return(0,X.jsxs)(`div`,{className:a(`space-y-2`,n),children:[r.map(([e,t],n)=>(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(u,{type:`text`,value:e,onChange:e=>o(n,e.target.value,t),placeholder:i(`headerName`),className:`flex-1`}),(0,X.jsx)(u,{type:`text`,value:t,onChange:t=>o(n,e,t.target.value),placeholder:i(`headerValue`),className:`flex-1`}),(0,X.jsx)(c,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>l(n),children:(0,X.jsx)(j,{className:`h-4 w-4 text-red-500`})})]},n)),(0,X.jsxs)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:s,children:[(0,X.jsx)(k,{className:`h-4 w-4 mr-2`}),i(`add`)]})]})}function he(e){let{value:t,onChange:n,options:r}=e;return(0,X.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:r.map(e=>{let r=e.value===t;return(0,X.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-foreground/15 bg-foreground text-background`:`border-border/55 bg-muted/50 text-muted-foreground hover:border-border hover:bg-muted hover:text-foreground`}`,children:e.label},e.value)})})}function ge(e){let{showAdvanced:t,onShowAdvancedChange:n,supportsWireApi:r,wireApiLabel:a,wireApi:o,onWireApiChange:c,shouldUseWireApiPills:l,wireApiSelectOptions:u,extraHeadersLabel:d,extraHeaders:f,onExtraHeadersChange:p}=e;return(0,X.jsxs)(`div`,{className:`border-t border-border/70 pt-4`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>n(!t),className:`flex w-full items-center justify-between text-sm text-muted-foreground transition-colors hover:text-foreground`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(A,{className:`h-3.5 w-3.5`}),i(`providerAdvancedSettings`)]}),(0,X.jsx)(y,{className:`h-4 w-4 transition-transform ${t?`rotate-180`:``}`})]}),t?(0,X.jsxs)(`div`,{className:`mt-4 space-y-5`,children:[r?(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(s,{htmlFor:`wireApi`,className:`text-sm font-medium text-foreground`,children:a}),l?(0,X.jsx)(he,{value:o,onChange:e=>c(e),options:u}):(0,X.jsxs)(w,{value:o,onValueChange:e=>c(e),children:[(0,X.jsx)(x,{className:`rounded-xl`,children:(0,X.jsx)(b,{})}),(0,X.jsx)(S,{children:u.map(e=>(0,X.jsx)(C,{value:e.value,children:e.label},e.value))})]})]}):null,(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(s,{className:`text-sm font-medium text-foreground`,children:d}),(0,X.jsx)(me,{value:f,onChange:p}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`providerExtraHeadersHelpShort`)})]})]}):null]})}function _e(e){let{providerAuth:t,providerAuthNote:n,providerAuthMethodOptions:r,providerAuthMethodsCount:a,selectedAuthMethodHint:o,shouldUseAuthMethodPills:l,resolvedAuthMethodId:u,onAuthMethodChange:d,onStartProviderAuth:f,onImportProviderAuthFromCli:p,startPending:m,importPending:h,authSessionId:g,authStatusMessage:_}=e;return t?.kind===`device_code`?(0,X.jsxs)(`div`,{className:`space-y-2 rounded-xl bg-muted/45 p-3`,children:[(0,X.jsx)(s,{className:`text-sm font-medium text-foreground`,children:t.displayName||i(`providerAuthSectionTitle`)}),n?(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n}):null,a>1?(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(s,{className:`text-xs font-medium text-foreground`,children:i(`providerAuthMethodLabel`)}),l?(0,X.jsx)(he,{value:u,onChange:d,options:r}):(0,X.jsxs)(w,{value:u,onValueChange:d,children:[(0,X.jsx)(x,{className:`h-8 rounded-lg`,children:(0,X.jsx)(b,{placeholder:i(`providerAuthMethodPlaceholder`)})}),(0,X.jsx)(S,{children:r.map(e=>(0,X.jsx)(C,{value:e.value,children:e.label},e.value))})]}),o?(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o}):null]}):null,(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:f,disabled:m||!!g,children:i(m?`providerAuthStarting`:g?`providerAuthAuthorizing`:`providerAuthAuthorizeInBrowser`)}),t.supportsCliImport?(0,X.jsx)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:p,disabled:h,children:i(h?`providerAuthImporting`:`providerAuthImportFromCli`)}):null,g?(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[i(`providerAuthSessionLabel`),`: `,g.slice(0,8),`…`]}):null]}),_?(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:_}):null]}):null}var ve={providerId:``,providerType:null,isBuiltInType:!1,isCustom:!0,enabled:!0,displayName:``,apiKeySet:!1,apiKeyMasked:void 0,apiBase:null,extraHeaders:null,wireApi:null,models:[],modelConfig:{}};function Z(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 ye(e,t){let n=Z(e),r=Z(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 Q(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 be(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 $(e,t){let n=e.trim();if(!n)return``;for(let e of t){let t=e.trim();t&&(n=be(n,t))}return n.trim()}function xe(e,t){return e.length===t.length?e.every((e,n)=>e===t[n]):!1}function Se(e,t){return Q(t)}function Ce(e,t){return Q(e).map(e=>{let n=e.trim();return!n||n.startsWith(`${t}/`)?n:`${t}/${n}`})}function we(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=L(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 Te(e,t,n){return{...I(e,n),...I(t,n)}}function Ee(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||!xe([...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 De(e){return e.providerName?e.apiKey.trim().length>0||e.apiBase.trim()!==e.currentApiBase.trim()||!ye(e.extraHeaders,e.currentHeaders)||e.supportsWireApi&&e.wireApi!==e.currentWireApi||!xe(e.models,e.currentEditableModels)||!Ee(e.modelConfig,e.currentModelConfig)||e.providerDisplayName.trim()!==e.effectiveDisplayName:!1}function Oe(e){let t={},n=e.apiKey.trim(),r=e.apiBase.trim(),i=Z(e.extraHeaders),a=e.providerDisplayName.trim();return a!==e.effectiveDisplayName&&(t.displayName=a.length>0?a:null),n.length>0&&(t.apiKey=n),r!==e.currentApiBase.trim()&&(t.apiBase=r.length>0&&r!==e.defaultApiBase?r:null),ye(i,e.currentHeaders)||(t.extraHeaders=i),e.supportsWireApi&&e.wireApi!==e.currentWireApi&&(t.wireApi=e.wireApi),xe(e.models,e.currentEditableModels)||(t.models=Ce(e.models,e.providerName??``)),Ee(e.modelConfig,e.currentModelConfig)||(t.modelConfig=we(e.modelConfig,e.models)),t}function ke(e){let t=$(e.models.find(e=>e.trim().length>0)??``,e.providerModelAliases),n={apiBase:e.apiBase.trim(),extraHeaders:Z(e.extraHeaders),model:t||null};return e.apiKey.trim().length>0&&(n.apiKey=e.apiKey.trim()),e.supportsWireApi&&(n.wireApi=e.wireApi),n}function Ae(e){return i(e===`off`?`chatThinkingLevelOff`:e===`minimal`?`chatThinkingLevelMinimal`:e===`low`?`chatThinkingLevelLow`:e===`medium`?`chatThinkingLevelMedium`:e===`high`?`chatThinkingLevelHigh`:e===`adaptive`?`chatThinkingLevelAdaptive`:`chatThinkingLevelXhigh`)}function je(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 Me(e){let{required:t,hasDefault:n,optionCount:r}=e;return t&&n&&r>1&&r<=3}function Ne(e,t,n){let r=$(t,n);return r?e.includes(r)?{models:e,draft:``}:{models:[...e,r],draft:``}:{models:e,draft:t}}function Pe(e,t,n){let r={...t};return delete r[n],{models:e.filter(e=>e!==n),modelConfig:r}}function Fe(e,t,n){let r=e[t],i=r?.thinking?.supported??[],a=i.includes(n)?i.filter(e=>e!==n):z.filter(e=>e===n||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={...e};return s.thinking||s.vision===!0?c[t]=s:delete c[t],c}function Ie(e,t,n){let r=e[t],i=r?.thinking;return!i||i.supported.length===0||n&&!i.supported.includes(n)?e:{...e,[t]:{...r,thinking:n?{supported:i.supported,default:n}:{supported:i.supported}}}}function Le(e,t,n){let r={...e[t],vision:n?!0:void 0},i={...e};return r.thinking||r.vision===!0?i[t]=r:delete i[t],i}function Re(e){let{providerName:t,providerSpec:n,language:r}=e,i=n?.auth,a=i?.methods??[];return{providerAuth:i,providerAuthMethodOptions:a.map(e=>({value:e.id,label:e.label?.[r]||e.label?.en||e.id})),providerAuthMethods:a,preferredAuthMethodId:je({providerName:n?.providerType??t,methods:a,defaultMethodId:i?.defaultMethodId,language:r}),shouldUseAuthMethodPills:Me({required:i?.kind===`device_code`,hasDefault:!!i?.defaultMethodId?.trim(),optionCount:a.length})}}function ze(e,t){let n=!!e?.supportsWireApi||t,r=(e?.wireApiOptions||[`auto`,`chat`,`responses`]).map(e=>({value:e,label:i(e===`chat`?`wireApiChat`:e===`responses`?`wireApiResponses`:`wireApiAuto`)}));return{shouldUseWireApiPills:Me({required:n,hasDefault:typeof e?.defaultWireApi==`string`&&e.defaultWireApi.length>0,optionCount:r.length}),supportsWireApi:n,wireApiSelectOptions:r}}function Be(e){let{providerName:t,providersView:n,templatesView:r,schema:a,language:o}=e,s=t?n?.providers[t]:null,c=r?.providerTemplates.find(e=>e.providerType===s?.providerType),l=s??ve,u=a?.uiHints,d=!!s?.isCustom,f=t?G(`providers.${t}.apiKey`,u):void 0,p=t?G(`providers.${t}.apiBase`,u):void 0,m=t?G(`providers.${t}.extraHeaders`,u):void 0,h=t?G(`providers.${t}.wireApi`,u):void 0,g=c?.displayName||s?.displayName||t||``,_=(l.displayName||``).trim()||g,v=l.enabled!==!1,y=Q([c?.modelPrefix||c?.providerType||``,t||``]),b=c?.defaultApiBase||``,x=l.apiBase||b,S=Z(l.extraHeaders||null),C=l.wireApi||c?.defaultWireApi||`auto`,w=Se(Q((c?.defaultModels??[]).map(e=>$(e,y))),Q((l.models??[]).map(e=>$(e,y)))),T=we(Te(c?.modelConfig,l.modelConfig,y),w),E=c?.apiBaseHelp?.[o]||c?.apiBaseHelp?.en||p?.help||i(`providerApiBaseHelp`),D=Re({providerName:t,providerSpec:c,language:o}),O=ze(c,d);return{apiBaseHelpText:E,apiBaseHint:p,apiKeyHint:f,currentApiBase:x,currentEditableModels:w,currentEnabled:v,currentHeaders:S,currentModelConfig:T,currentWireApi:C,defaultApiBase:b,defaultDisplayName:g,effectiveDisplayName:_,extraHeadersHint:m,...D,providerConfig:s,providerModelAliases:y,resolvedProviderConfig:l,wireApiHint:h,...O}}function Ve(e){let{models:t,modelConfig:n,modelDraft:r,showModelInput:a,onModelDraftChange:o,onShowModelInputChange:l,onAddModel:f,onRemoveModel:p,onToggleModelThinkingLevel:_,onSetModelThinkingDefault:v,onSetModelVision:y,thinkingLevels:T,formatThinkingLevelLabel:E}=e;return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(s,{className:`text-sm font-medium text-foreground`,children:i(`providerModelsTitle`)}),a?null:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>l(!0),className:`flex items-center gap-1 text-xs font-medium text-primary hover:text-primary/80`,children:[(0,X.jsx)(k,{className:`h-3 w-3`}),i(`providerAddModel`)]})]}),a?(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(u,{value:r,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),f()),e.key===`Escape`&&(l(!1),o(``))},placeholder:i(`providerModelInputPlaceholder`),className:`flex-1 rounded-xl`,autoFocus:!0}),(0,X.jsx)(c,{type:`button`,size:`sm`,onClick:f,disabled:r.trim().length===0,children:i(`add`)}),(0,X.jsx)(c,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>{l(!1),o(``)},children:(0,X.jsx)(M,{className:`h-4 w-4`})})]}):null,t.length===0?(0,X.jsxs)(`div`,{className:`rounded-xl bg-muted/35 px-4 py-6 text-center`,children:[(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`providerModelsEmptyShort`)}),a?null:(0,X.jsx)(`button`,{type:`button`,onClick:()=>l(!0),className:`mt-2 text-sm font-medium text-primary hover:text-primary/80`,children:i(`providerAddFirstModel`)})]}):(0,X.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:t.map(e=>{let t=n[e],r=t?.thinking,a=r?.supported??[],o=r?.default??null,c=t?.vision===!0;return(0,X.jsxs)(`div`,{className:`group inline-flex max-w-full items-center gap-1 rounded-full border border-border/55 bg-muted/45 px-3 py-1.5`,children:[(0,X.jsx)(`span`,{className:`max-w-[140px] truncate text-sm text-foreground sm:max-w-[220px]`,children:e}),(0,X.jsxs)(g,{children:[(0,X.jsx)(m,{asChild:!0,children:(0,X.jsx)(`button`,{type:`button`,className:`inline-flex h-5 w-5 items-center justify-center rounded-full text-muted-foreground/70 opacity-100 transition-opacity hover:bg-muted hover:text-foreground md:opacity-0 md:group-hover:opacity-100 md:group-focus-within:opacity-100`,"aria-label":i(`providerModelThinkingTitle`),title:i(`providerModelThinkingTitle`),children:(0,X.jsx)(A,{className:`h-3 w-3`})})}),(0,X.jsxs)(h,{className:`w-80 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-lg bg-muted/50 px-3 py-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`p`,{className:`text-xs font-semibold text-foreground`,children:i(`providerModelVisionTitle`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`providerModelVisionHint`)})]}),(0,X.jsx)(d,{checked:c,onCheckedChange:t=>y(e,t)})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`p`,{className:`text-xs font-semibold text-foreground`,children:i(`providerModelThinkingTitle`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`providerModelThinkingHint`)})]}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:T.map(t=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>_(e,t),className:`rounded-full border px-2.5 py-1 text-xs font-medium transition-colors ${a.includes(t)?`border-foreground/15 bg-foreground text-background`:`border-border/55 bg-muted/50 text-muted-foreground hover:border-border hover:bg-muted hover:text-foreground`}`,children:E(t)},t))}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(s,{className:`text-xs font-medium text-foreground`,children:i(`providerModelThinkingDefault`)}),(0,X.jsxs)(w,{value:o??`__none__`,onValueChange:t=>v(e,t===`__none__`?null:t),disabled:a.length===0,children:[(0,X.jsx)(x,{className:`h-8 rounded-lg text-xs`,children:(0,X.jsx)(b,{})}),(0,X.jsxs)(S,{children:[(0,X.jsx)(C,{value:`__none__`,children:i(`providerModelThinkingDefaultNone`)}),a.map(e=>(0,X.jsx)(C,{value:e,children:E(e)},e))]})]}),a.length===0?(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`providerModelThinkingNoSupported`)}):null]})]})]}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>p(e),className:`inline-flex h-5 w-5 items-center justify-center rounded-full text-muted-foreground/70 opacity-100 transition-opacity hover:bg-muted hover:text-foreground md:opacity-0 md:group-hover:opacity-100 md:group-focus-within:opacity-100`,"aria-label":i(`remove`),children:(0,X.jsx)(M,{className:`h-3 w-3`})})]},e)})})]})}function He({apiKeySet:e,className:t,enabled:n}){return n?(0,X.jsx)(N,{status:e?`ready`:`setup`,label:i(e?`statusReady`:`statusSetup`),className:t}):(0,X.jsx)(N,{status:`inactive`,label:i(`disabled`),className:t})}function Ue(e){let{providerName:t,providerAuth:n,resolvedAuthMethodId:r}=e,a=f(),o=te(),s=V(),c=W(),[u,d]=(0,Y.useState)(``),[p,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(``),_=(0,Y.useRef)(null),v=(0,Y.useCallback)(()=>{_.current!==null&&(window.clearTimeout(_.current),_.current=null)},[]),y=(0,Y.useCallback)((e,n)=>{v(),_.current=window.setTimeout(()=>{(async()=>{if(t)try{let r=await s.mutateAsync({provider:t,data:{sessionId:e}});if(r.status===`pending`){g(i(`providerAuthWaitingBrowser`)),y(e,r.nextPollMs??n);return}if(r.status===`authorized`){m(null),v(),g(i(`providerAuthCompleted`)),l.success(i(`providerAuthCompleted`)),a.invalidateQueries({queryKey:[`config`]}),a.invalidateQueries({queryKey:[`providers`]});return}m(null),v(),g(r.message||`Authorization ${r.status}.`),l.error(r.message||`Authorization ${r.status}.`)}catch(e){m(null),v();let t=e instanceof Error?e.message:String(e);g(t),l.error(`Authorization failed: ${t}`)}})()},Math.max(1e3,n))},[v,s,t,a]),b=(0,Y.useCallback)(async()=>{if(!(!t||n?.kind!==`device_code`))try{d(t),g(``);let e=await o.mutateAsync({provider:t,data:r?{methodId:r}:{}});if(!e.sessionId||!e.verificationUri)throw Error(i(`providerAuthStartFailed`));m(e.sessionId),g(`${i(`providerAuthOpenPrompt`)}${e.userCode}${i(`providerAuthOpenPromptSuffix`)}`),await F.openExternalUrl(e.verificationUri),y(e.sessionId,e.intervalMs)}catch(e){let t=e instanceof Error?e.message:String(e);m(null),v(),g(t),l.error(`${i(`providerAuthStartFailed`)}: ${t}`)}},[v,n?.kind,t,r,y,o]),x=(0,Y.useCallback)(async()=>{if(!(!t||n?.kind!==`device_code`))try{d(t),v(),m(null);let e=await c.mutateAsync({provider:t});g(`${i(`providerAuthImportStatusPrefix`)}${e.expiresAt?` (expires: ${e.expiresAt})`:``}`),l.success(i(`providerAuthImportSuccess`)),a.invalidateQueries({queryKey:[`config`]}),a.invalidateQueries({queryKey:[`providers`]})}catch(e){let t=e instanceof Error?e.message:String(e);g(t),l.error(`${i(`providerAuthImportFailed`)}: ${t}`)}},[v,c,n?.kind,t,a]);return(0,Y.useEffect)(()=>{v()},[v,t]),(0,Y.useEffect)(()=>()=>v(),[v]),{authSessionId:u===t?p:null,authStatusMessage:u===t?h:``,importAuthFromCli:x,importPending:c.isPending,startAuth:b,startPending:o.isPending}}function We({providerName:e,onProviderDeleted:n}){let{data:r}=ae(),{data:a}=re(),{data:o}=ie(),s=H(),c=B(),u=ne(),[d,f]=(0,Y.useState)(``),[p,m]=(0,Y.useState)(``),[h,g]=(0,Y.useState)(null),[_,v]=(0,Y.useState)(`auto`),[y,b]=(0,Y.useState)([]),[x,S]=(0,Y.useState)({}),[C,w]=(0,Y.useState)(``),[T,E]=(0,Y.useState)(``),[D,O]=(0,Y.useState)(!1),[k,A]=(0,Y.useState)(!1),[j,M]=(0,Y.useState)(``),N=t(),P=(0,Y.useMemo)(()=>Be({providerName:e,providersView:r,templatesView:a,schema:o,language:N}),[N,e,r,o,a]),{currentApiBase:F,currentEditableModels:I,currentHeaders:L,currentModelConfig:R,currentWireApi:z,defaultApiBase:ee,effectiveDisplayName:V,providerAuth:te,providerAuthMethods:U,providerConfig:W,providerModelAliases:G,resolvedProviderConfig:K,preferredAuthMethodId:q,supportsWireApi:J}=P,oe=T.trim()||V||e||i(`providersSelectPlaceholder`),se=(0,Y.useMemo)(()=>{if(!U.length)return``;let e=j.trim();return e&&U.some(t=>t.id===e)?e:q||U[0]?.id||``},[j,q,U]),{authSessionId:ce,authStatusMessage:ue,importAuthFromCli:de,importPending:fe,startAuth:pe,startPending:me}=Ue({providerName:e,providerAuth:te,resolvedAuthMethodId:se});(0,Y.useEffect)(()=>{if(!e){f(``),m(``),g(null),v(`auto`),b([]),S({}),w(``),E(``),M(``);return}f(``),m(F),g(K.extraHeaders||null),v(z),b(I),S(R),w(``),E(V),M(q)},[e,F,K.extraHeaders,z,I,R,V,q]),(0,Y.useEffect)(()=>S(e=>we(e,y)),[y]);let he=(0,Y.useMemo)(()=>De({providerName:e,apiKey:d,apiBase:p,currentApiBase:F,extraHeaders:h,currentHeaders:L,supportsWireApi:J,wireApi:_,currentWireApi:z,models:y,currentEditableModels:I,modelConfig:x,currentModelConfig:R,providerDisplayName:T,effectiveDisplayName:V}),[e,d,p,F,h,L,J,_,z,y,I,x,R,T,V]);return!e||!W?(0,X.jsx)(le,{children:(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:i(`providersSelectTitle`)}),(0,X.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:i(`providersSelectDescription`)})]})}):(0,X.jsx)(Ge,{context:P,language:N,providerTitle:oe,providerDisplayName:T,apiKey:d,apiBase:p,extraHeaders:h,wireApi:_,models:y,modelConfig:x,modelDraft:C,showAdvanced:D,showModelInput:k,resolvedAuthMethodId:se,authSessionId:ce,authStatusMessage:ue,hasChanges:he,isDeletePending:c.isPending,isUpdatePending:s.isPending,isTestPending:u.isPending,startPending:me,importPending:fe,onProviderDisplayNameChange:E,onApiKeyChange:f,onApiBaseChange:m,onAuthMethodChange:M,onStartProviderAuth:pe,onImportProviderAuthFromCli:de,onModelDraftChange:w,onShowModelInputChange:A,onAddModel:()=>{let e=Ne(y,C,G);b(e.models),w(e.draft)},onRemoveModel:e=>{let t=Pe(y,x,e);b(t.models),S(t.modelConfig)},onToggleModelThinkingLevel:(e,t)=>{S(n=>Fe(n,e,t))},onSetModelThinkingDefault:(e,t)=>{S(n=>Ie(n,e,t))},onSetModelVision:(e,t)=>{S(n=>Le(n,e,t))},onShowAdvancedChange:O,onWireApiChange:v,onExtraHeadersChange:g,onDeleteProvider:async()=>{if(e&&window.confirm(i(`providerDeleteConfirm`)))try{await c.mutateAsync({provider:e}),n?.(e)}catch{}},onSubmit:t=>{t.preventDefault(),e&&s.mutate({provider:e,data:Oe({providerName:e,apiKey:d,apiBase:p,currentApiBase:F,defaultApiBase:ee,extraHeaders:h,currentHeaders:L,supportsWireApi:J,wireApi:_,currentWireApi:z,models:y,currentEditableModels:I,modelConfig:x,currentModelConfig:R,providerDisplayName:T,effectiveDisplayName:V})})},onTestConnection:async()=>{if(e)try{let t=await u.mutateAsync({provider:e,data:ke({apiKey:d,apiBase:p,extraHeaders:h,supportsWireApi:J,wireApi:_,models:y,providerModelAliases:G})});if(t.success){l.success(`${i(`providerTestConnectionSuccess`)} (${t.latencyMs}ms)`);return}let n=[`provider=${t.provider}`,`latency=${t.latencyMs}ms`];t.model&&n.push(`model=${t.model}`),l.error(`${i(`providerTestConnectionFailed`)}: ${t.message} | ${n.join(` | `)}`)}catch(e){let t=e instanceof Error?e.message:String(e);l.error(`${i(`providerTestConnectionFailed`)}: ${t}`)}}})}function Ge(e){let{context:t,language:n,providerTitle:r,providerDisplayName:a,apiKey:o,apiBase:l,extraHeaders:d,wireApi:f,models:p,modelConfig:m,modelDraft:h,showAdvanced:g,showModelInput:_,resolvedAuthMethodId:v,authSessionId:y,authStatusMessage:b,hasChanges:x,isDeletePending:S,isUpdatePending:C,isTestPending:w,startPending:T,importPending:E,onProviderDisplayNameChange:D,onApiKeyChange:O,onApiBaseChange:k,onAuthMethodChange:A,onStartProviderAuth:M,onImportProviderAuthFromCli:N,onModelDraftChange:P,onShowModelInputChange:F,onAddModel:I,onRemoveModel:L,onToggleModelThinkingLevel:R,onSetModelThinkingDefault:B,onSetModelVision:V,onShowAdvancedChange:te,onWireApiChange:ne,onExtraHeadersChange:H,onDeleteProvider:U,onSubmit:re,onTestConnection:ie}=e,W=t.providerAuthMethods.find(e=>e.id===v);return(0,X.jsxs)(se,{children:[(0,X.jsx)(q,{className:`px-5 py-4`,children:(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(`h3`,{className:`truncate text-lg font-semibold text-foreground`,children:r}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:U,disabled:S,className:`text-muted-foreground/70 transition-colors hover:text-red-500`,title:i(`providerDelete`),children:(0,X.jsx)(j,{className:`h-4 w-4`})}),(0,X.jsx)(He,{enabled:t.currentEnabled,apiKeySet:t.resolvedProviderConfig.apiKeySet})]})]})}),(0,X.jsxs)(`form`,{onSubmit:re,className:`flex min-h-0 flex-1 flex-col`,children:[(0,X.jsxs)(ce,{className:`space-y-4 px-5 py-4`,children:[(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(s,{htmlFor:`providerDisplayName`,className:`text-sm font-medium text-foreground`,children:i(`providerDisplayName`)}),(0,X.jsx)(u,{id:`providerDisplayName`,type:`text`,value:a,onChange:e=>D(e.target.value),placeholder:t.defaultDisplayName||i(`providerDisplayNamePlaceholder`),className:`rounded-xl`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`providerDisplayNameHelpShort`)})]}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(s,{htmlFor:`apiKey`,className:`text-sm font-medium text-foreground`,children:i(`apiKey`)}),(0,X.jsx)(pe,{id:`apiKey`,value:o,isSet:t.resolvedProviderConfig.apiKeySet,onChange:e=>O(e.target.value),placeholder:t.apiKeyHint?.placeholder??i(`enterApiKey`),className:`rounded-xl`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`leaveBlankToKeepUnchanged`)})]}),(0,X.jsx)(_e,{providerAuth:t.providerAuth,providerAuthNote:t.providerAuth?.note?.[n]||t.providerAuth?.note?.en||t.providerAuth?.displayName||``,providerAuthMethodOptions:t.providerAuthMethodOptions,providerAuthMethodsCount:t.providerAuthMethods.length,selectedAuthMethodHint:W?.hint?.[n]||W?.hint?.en||``,shouldUseAuthMethodPills:t.shouldUseAuthMethodPills,resolvedAuthMethodId:v,onAuthMethodChange:A,onStartProviderAuth:M,onImportProviderAuthFromCli:N,startPending:T,importPending:E,authSessionId:y,authStatusMessage:b}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(s,{htmlFor:`apiBase`,className:`text-sm font-medium text-foreground`,children:i(`apiBase`)}),(0,X.jsx)(u,{id:`apiBase`,type:`text`,value:l,onChange:e=>k(e.target.value),placeholder:t.defaultApiBase||t.apiBaseHint?.placeholder||`https://api.example.com`,className:`rounded-xl`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t.apiBaseHelpText})]}),(0,X.jsx)(Ve,{models:p,modelConfig:m,modelDraft:h,showModelInput:_,onModelDraftChange:P,onShowModelInputChange:F,onAddModel:I,onRemoveModel:L,onToggleModelThinkingLevel:R,onSetModelThinkingDefault:B,onSetModelVision:V,thinkingLevels:z,formatThinkingLevelLabel:Ae}),(0,X.jsx)(ge,{showAdvanced:g,onShowAdvancedChange:te,supportsWireApi:t.supportsWireApi,wireApiLabel:i(`wireApi`),wireApi:f,onWireApiChange:ne,shouldUseWireApiPills:t.shouldUseWireApiPills,wireApiSelectOptions:t.wireApiSelectOptions,extraHeadersLabel:i(`extraHeaders`),extraHeaders:d,onExtraHeadersChange:H})]}),(0,X.jsx)(ue,{children:(0,X.jsxs)(ee,{align:`between`,children:[(0,X.jsxs)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:ie,disabled:w,children:[(0,X.jsx)(de,{className:`mr-1.5 h-3.5 w-3.5`}),i(w?`providerTestingConnection`:`providerTestConnection`)]}),(0,X.jsx)(c,{type:`submit`,size:`sm`,disabled:C||!x,children:i(C?`saving`:x?`save`:`unchanged`)})]})})]})]})}function Ke(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 qe(e,t=[]){let n=new Map(t.map((e,t)=>[e,t]));return e.map((e,t)=>({provider:e,index:t})).sort((e,t)=>{let r=n.get(e.provider.providerId),i=n.get(t.provider.providerId);if(r!==void 0||i!==void 0)return(r??2**53-1)-(i??2**53-1);let a=e.provider.providerType===`nextclaw`?1:0,o=t.provider.providerType===`nextclaw`?1:0;return a===o?e.index-t.index:a-o}).map(({provider:e})=>e)}function Je(e){let t=e.findIndex(e=>e.providerType===`zhipu`),n=e.findIndex(e=>e.providerType===`dashscope-coding-plan`);return e.map((e,t)=>({template:e,index:t})).sort((e,r)=>{let i=({template:e,index:r})=>e.providerType===`nextclaw`?2**53-1:e.providerType===`deepseek`&&n>=0?n-.5:e.providerType===`mimo`&&t>=0?t+.5:r;return i(e)-i(r)}).map(({template:e})=>e)}function Ye(){let{isMobile:e}=O(),{data:t}=ae(),{data:n}=re(),r=U(),s=B(),l=H(),[f,p]=(0,Y.useState)(null),[y,b]=(0,Y.useState)(null),[x,S]=(0,Y.useState)(!1),[C,w]=(0,Y.useState)([]),[E,A]=(0,Y.useState)(``),M=(0,Y.useMemo)(()=>qe(Object.values(t?.providers??{}),C),[t?.providers,C]),F=(0,Y.useMemo)(()=>n?.providerTemplates??[],[n?.providerTemplates]),I=(0,Y.useMemo)(()=>Je(F),[F]),L=(0,Y.useMemo)(()=>new Map(F.map(e=>[e.providerType,e])),[F]),R=(0,Y.useMemo)(()=>{let e=E.trim().toLowerCase();return M.filter(t=>{if(!e)return!0;let n=t.providerType?L.get(t.providerType):null;return(t.displayName?.trim()||n?.displayName||t.providerId).toLowerCase().includes(e)||t.providerId.toLowerCase().includes(e)})},[M,E,L]),z=(0,Y.useMemo)(()=>f&&R.some(e=>e.providerId===f)?f:e?null:R[0]?.providerId??null,[R,e,f]);return!t||!n?(0,X.jsx)(o,{title:i(`providersPageTitle`),description:i(`providersPageDescription`),layout:`split`,children:(0,X.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:i(`providersLoading`)})}):(0,X.jsxs)(o,{title:i(`providersPageTitle`),description:i(`providersPageDescription`),layout:`split`,children:[(0,X.jsxs)(K,{className:`md:min-h-0`,compactView:f?`detail`:`list`,onMobileBack:()=>p(null),mobileListLabel:i(`providersPageTitle`),children:[(0,X.jsxs)(oe,{children:[(0,X.jsx)(q,{className:`space-y-3 px-4 pb-3 pt-4`,children:(0,X.jsxs)(g,{open:x,onOpenChange:S,children:[(0,X.jsx)(m,{asChild:!0,children:(0,X.jsxs)(c,{type:`button`,variant:`outline`,className:`w-full justify-center`,disabled:r.isPending,children:[(0,X.jsx)(k,{className:`mr-2 h-4 w-4`}),r.isPending?i(`saving`):i(`providerAdd`)]})}),(0,X.jsxs)(h,{className:`w-[42rem] max-w-[calc(100vw-2rem)] p-3`,align:`start`,children:[(0,X.jsx)(`div`,{className:`mb-2 px-1 text-xs font-semibold text-muted-foreground`,children:i(`providerTemplatePickerTitle`)}),(0,X.jsxs)(`div`,{className:`grid max-h-[24rem] grid-cols-2 gap-2 overflow-y-auto sm:grid-cols-3`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`flex min-h-20 w-full flex-col items-start gap-2 rounded-lg border border-dashed border-border/70 bg-muted/20 px-3 py-2 text-left transition-colors hover:border-border hover:bg-muted/45`,onClick:async()=>{try{let e=await r.mutateAsync({data:{providerType:null}});A(``),p(e.providerId),w(t=>[e.providerId,...t.filter(t=>t!==e.providerId)]),S(!1)}catch{}},children:[(0,X.jsx)(P,{name:`custom`,className:`h-8 w-8 rounded-lg border border-border/60 bg-muted/50`}),(0,X.jsx)(`span`,{className:`line-clamp-2 min-w-0 text-xs font-semibold leading-4 text-foreground`,children:i(`providerAddCustom`)})]}),I.map(e=>(0,X.jsxs)(`button`,{type:`button`,className:`flex min-h-20 w-full flex-col items-start gap-2 rounded-lg border border-border/55 bg-muted/15 px-3 py-2 text-left transition-colors hover:border-border/80 hover:bg-muted/40`,onClick:async()=>{try{let t=await r.mutateAsync({data:{providerType:e.providerType}});A(``),p(t.providerId),w(e=>[t.providerId,...e.filter(e=>e!==t.providerId)]),S(!1)}catch{}},children:[(0,X.jsx)(P,{name:e.providerType,src:e.logo?`/logos/${e.logo}`:null,className:`h-8 w-8 rounded-lg border border-border/55 bg-background`,imgClassName:`h-4 w-4 object-contain`}),(0,X.jsx)(`span`,{className:`line-clamp-2 min-w-0 text-xs font-semibold leading-4 text-foreground`,children:e.displayName||e.providerType})]},e.providerType))]})]})]})}),(0,X.jsx)(`div`,{className:`border-b border-border/70 px-4 py-3`,children:(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(v,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/70`}),(0,X.jsx)(u,{value:E,onChange:e=>A(e.target.value),placeholder:i(`providersFilterPlaceholder`),className:`h-10 rounded-xl pl-9`})]})}),(0,X.jsxs)(ce,{className:`space-y-2 p-3`,children:[R.map(e=>{let t=e.providerType?L.get(e.providerType):null,n=e.enabled!==!1,r=!!(n&&e.apiKeySet),o=e.displayName?.trim()||t?.displayName||e.providerId,s=Ke(e.apiBase||t?.defaultApiBase||``)||i(`providersDefaultDescription`);return(0,X.jsx)(`div`,{onClick:()=>p(e.providerId),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),p(e.providerId))},role:`button`,tabIndex:0,className:a(`group w-full rounded-xl p-2.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40`,z===e.providerId?`bg-background/95 text-foreground shadow-sm`:`bg-transparent text-muted-foreground hover:bg-background/65 hover:text-foreground`),children:(0,X.jsxs)(`div`,{className:`relative min-h-10`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3 pr-20`,children:[(0,X.jsx)(P,{name:e.providerType??e.providerId,src:t?.logo?`/logos/${t.logo}`:null,className:`h-10 w-10 rounded-lg bg-background/80`,imgClassName:`h-5 w-5 object-contain`,fallback:(0,X.jsx)(`span`,{className:`text-sm font-semibold uppercase text-muted-foreground`,children:e.providerId[0]})}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`p`,{className:`truncate text-sm font-semibold text-foreground`,children:o}),(0,X.jsx)(`p`,{className:`truncate font-mono text-[10px] text-muted-foreground/65`,children:e.providerId}),(0,X.jsxs)(`p`,{className:`line-clamp-1 text-[11px] text-muted-foreground`,children:[s,` · `,e.models?.length??0]})]})]}),(0,X.jsxs)(`div`,{className:`absolute right-0 top-0 flex items-center gap-1.5 opacity-70 transition-opacity group-hover:opacity-100`,children:[(0,X.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,X.jsx)(d,{checked:n,disabled:l.isPending,title:i(n?`disabled`:`enabled`),className:`h-[18px] w-8`,thumbClassName:`h-4 w-4 data-[state=checked]:translate-x-4`,onCheckedChange:t=>{l.mutateAsync({provider:e.providerId,data:{enabled:t},silentSuccess:!0})}})}),(0,X.jsxs)(g,{children:[(0,X.jsx)(m,{asChild:!0,children:(0,X.jsx)(`button`,{type:`button`,className:`inline-flex h-7 w-7 items-center justify-center rounded-lg text-muted-foreground/70 hover:bg-muted hover:text-foreground`,onClick:e=>e.stopPropagation(),title:i(`more`),children:(0,X.jsx)(T,{className:`h-4 w-4`})})}),(0,X.jsx)(h,{className:`w-40 p-1`,align:`end`,onClick:e=>e.stopPropagation(),children:(0,X.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-md px-2 py-2 text-sm text-red-600 hover:bg-red-50`,onClick:()=>b(e.providerId),children:[(0,X.jsx)(j,{className:`h-4 w-4`}),i(`providerDelete`)]})})]})]}),(0,X.jsx)(N,{status:n?r?`ready`:`setup`:`inactive`,label:i(n?r?`statusReady`:`statusSetup`:`disabled`),className:`absolute bottom-0 right-0 justify-end`})]})},e.providerId)}),R.length===0?(0,X.jsx)(J,{icon:D,title:i(`providersNoMatch`)}):null]})]}),(0,X.jsx)(We,{providerName:z??void 0,onProviderDeleted:e=>{w(t=>t.filter(t=>t!==e)),e===z&&p(null)}})]}),(0,X.jsx)(_,{open:!!y,onOpenChange:e=>{e||b(null)},title:i(`providerDelete`),description:y??void 0,confirmLabel:i(`delete`),variant:`destructive`,onCancel:()=>b(null),onConfirm:()=>{y&&s.mutateAsync({provider:y}).then(()=>{w(e=>e.filter(e=>e!==y)),y===z&&p(null),b(null)})}})]})}export{Ye as ProvidersConfigPage};
|
|
1
|
+
import{i as e}from"./chunk-DseTPa7n.js";import{a as t,h as n,p as r,r as i,u as a}from"./react-DerwD2EA.js";import{Qt as o,en as s,nn as c,on as l,tn as u,wt as d,yn as f}from"./api-D5UCLVE_.js";import{c as p}from"./dist-Ca-jiFrK.js";import{i as m,r as h,t as g}from"./popover-DHx55dbc.js";import{t as _}from"./confirm-dialog-e2YCUzt1.js";import{t as v}from"./search-D0HtJIL-.js";import{C as y,a as b,i as x,n as S,r as C,t as w}from"./select-C1zfp9zM.js";import{n as T,t as E}from"./eye-B30J471A.js";import{i as D,t as O}from"./use-viewport-layout-DaKJ-kap.js";import{t as k}from"./plus-C45awBb1.js";import{t as A}from"./settings-2-Ba3cLSN2.js";import{t as j}from"./trash-2-CUpWjNHu.js";import{t as M}from"./x-DGdYT7rH.js";import{n as N,t as P}from"./logo-badge-CISsltAo.js";import{t as F}from"./host-capabilities-B-TtABsP.js";import{a as I,o as L,s as R,t as z}from"./provider-models-CXUgDxGR.js";import{t as ee}from"./form-actions-CnSzu3WD.js";import{a as B,c as V,d as te,f as ne,h as H,i as U,l as re,r as ie,s as W,u as ae}from"./use-config-BvxDWV-M.js";import{t as G}from"./config-hints-S3g-UVZb.js";import{a as K,c as q,i as J,l as oe,n as se,o as ce,r as le,s as ue}from"./config-split-page-xj0UtMow.js";var de=p(`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`}]]),fe=p(`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`}]]),Y=e(n(),1),X=r();function pe({isSet:e,className:t,value:n,onChange:r,placeholder:i,...o}){let[s,l]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(!1),p=typeof n==`string`&&n.length>0;return(0,X.jsxs)(`div`,{className:`relative`,children:[e&&!p&&!d?(0,X.jsx)(`div`,{onClick:()=>f(!0),className:a(`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`,t),children:`••••••••••••`}):(0,X.jsx)(u,{type:s?`text`:`password`,className:a(`pr-12`,t),value:n,onChange:r,onBlur:()=>{p||f(!1)},placeholder:i,autoFocus:d,...o}),(0,X.jsx)(`div`,{className:`absolute right-2 top-1/2 -translate-y-1/2 flex gap-1`,children:(e||p)&&(0,X.jsx)(c,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>l(!s),children:s?(0,X.jsx)(fe,{className:`h-4 w-4`}):(0,X.jsx)(E,{className:`h-4 w-4`})})})]})}function me({value:e,onChange:t,className:n}){let r=e?Object.entries(e):[],o=(e,n,i)=>{let a=[...r];a[e]=[n,i],t(Object.fromEntries(a))},s=()=>{t({...e,"":``})},l=e=>{let n=r.filter((t,n)=>n!==e);t(Object.fromEntries(n))};return(0,X.jsxs)(`div`,{className:a(`space-y-2`,n),children:[r.map(([e,t],n)=>(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(u,{type:`text`,value:e,onChange:e=>o(n,e.target.value,t),placeholder:i(`headerName`),className:`flex-1`}),(0,X.jsx)(u,{type:`text`,value:t,onChange:t=>o(n,e,t.target.value),placeholder:i(`headerValue`),className:`flex-1`}),(0,X.jsx)(c,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>l(n),children:(0,X.jsx)(j,{className:`h-4 w-4 text-red-500`})})]},n)),(0,X.jsxs)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:s,children:[(0,X.jsx)(k,{className:`h-4 w-4 mr-2`}),i(`add`)]})]})}function he(e){let{value:t,onChange:n,options:r}=e;return(0,X.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:r.map(e=>{let r=e.value===t;return(0,X.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-foreground/15 bg-foreground text-background`:`border-border/55 bg-muted/50 text-muted-foreground hover:border-border hover:bg-muted hover:text-foreground`}`,children:e.label},e.value)})})}function ge(e){let{showAdvanced:t,onShowAdvancedChange:n,supportsWireApi:r,wireApiLabel:a,wireApi:o,onWireApiChange:c,shouldUseWireApiPills:l,wireApiSelectOptions:u,extraHeadersLabel:d,extraHeaders:f,onExtraHeadersChange:p}=e;return(0,X.jsxs)(`div`,{className:`border-t border-border/70 pt-4`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>n(!t),className:`flex w-full items-center justify-between text-sm text-muted-foreground transition-colors hover:text-foreground`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(A,{className:`h-3.5 w-3.5`}),i(`providerAdvancedSettings`)]}),(0,X.jsx)(y,{className:`h-4 w-4 transition-transform ${t?`rotate-180`:``}`})]}),t?(0,X.jsxs)(`div`,{className:`mt-4 space-y-5`,children:[r?(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(s,{htmlFor:`wireApi`,className:`text-sm font-medium text-foreground`,children:a}),l?(0,X.jsx)(he,{value:o,onChange:e=>c(e),options:u}):(0,X.jsxs)(w,{value:o,onValueChange:e=>c(e),children:[(0,X.jsx)(x,{className:`rounded-xl`,children:(0,X.jsx)(b,{})}),(0,X.jsx)(S,{children:u.map(e=>(0,X.jsx)(C,{value:e.value,children:e.label},e.value))})]})]}):null,(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(s,{className:`text-sm font-medium text-foreground`,children:d}),(0,X.jsx)(me,{value:f,onChange:p}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`providerExtraHeadersHelpShort`)})]})]}):null]})}function _e(e){let{providerAuth:t,providerAuthNote:n,providerAuthMethodOptions:r,providerAuthMethodsCount:a,selectedAuthMethodHint:o,shouldUseAuthMethodPills:l,resolvedAuthMethodId:u,onAuthMethodChange:d,onStartProviderAuth:f,onImportProviderAuthFromCli:p,startPending:m,importPending:h,authSessionId:g,authStatusMessage:_}=e;return t?.kind===`device_code`?(0,X.jsxs)(`div`,{className:`space-y-2 rounded-xl bg-muted/45 p-3`,children:[(0,X.jsx)(s,{className:`text-sm font-medium text-foreground`,children:t.displayName||i(`providerAuthSectionTitle`)}),n?(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n}):null,a>1?(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(s,{className:`text-xs font-medium text-foreground`,children:i(`providerAuthMethodLabel`)}),l?(0,X.jsx)(he,{value:u,onChange:d,options:r}):(0,X.jsxs)(w,{value:u,onValueChange:d,children:[(0,X.jsx)(x,{className:`h-8 rounded-lg`,children:(0,X.jsx)(b,{placeholder:i(`providerAuthMethodPlaceholder`)})}),(0,X.jsx)(S,{children:r.map(e=>(0,X.jsx)(C,{value:e.value,children:e.label},e.value))})]}),o?(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o}):null]}):null,(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:f,disabled:m||!!g,children:i(m?`providerAuthStarting`:g?`providerAuthAuthorizing`:`providerAuthAuthorizeInBrowser`)}),t.supportsCliImport?(0,X.jsx)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:p,disabled:h,children:i(h?`providerAuthImporting`:`providerAuthImportFromCli`)}):null,g?(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[i(`providerAuthSessionLabel`),`: `,g.slice(0,8),`…`]}):null]}),_?(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:_}):null]}):null}var ve={providerId:``,providerType:null,isBuiltInType:!1,isCustom:!0,enabled:!0,displayName:``,apiKeySet:!1,apiKeyMasked:void 0,apiBase:null,extraHeaders:null,wireApi:null,models:[],modelConfig:{}};function Z(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 ye(e,t){let n=Z(e),r=Z(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 Q(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 be(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 $(e,t){let n=e.trim();if(!n)return``;for(let e of t){let t=e.trim();t&&(n=be(n,t))}return n.trim()}function xe(e,t){return e.length===t.length?e.every((e,n)=>e===t[n]):!1}function Se(e,t){return Q(t)}function Ce(e,t){return Q(e).map(e=>{let n=e.trim();return!n||n.startsWith(`${t}/`)?n:`${t}/${n}`})}function we(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=L(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 Te(e,t,n){return{...I(e,n),...I(t,n)}}function Ee(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||!xe([...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 De(e){return e.providerName?e.apiKey.trim().length>0||e.apiBase.trim()!==e.currentApiBase.trim()||!ye(e.extraHeaders,e.currentHeaders)||e.supportsWireApi&&e.wireApi!==e.currentWireApi||!xe(e.models,e.currentEditableModels)||!Ee(e.modelConfig,e.currentModelConfig)||e.providerDisplayName.trim()!==e.effectiveDisplayName:!1}function Oe(e){let t={},n=e.apiKey.trim(),r=e.apiBase.trim(),i=Z(e.extraHeaders),a=e.providerDisplayName.trim();return a!==e.effectiveDisplayName&&(t.displayName=a.length>0?a:null),n.length>0&&(t.apiKey=n),r!==e.currentApiBase.trim()&&(t.apiBase=r.length>0&&r!==e.defaultApiBase?r:null),ye(i,e.currentHeaders)||(t.extraHeaders=i),e.supportsWireApi&&e.wireApi!==e.currentWireApi&&(t.wireApi=e.wireApi),xe(e.models,e.currentEditableModels)||(t.models=Ce(e.models,e.providerName??``)),Ee(e.modelConfig,e.currentModelConfig)||(t.modelConfig=we(e.modelConfig,e.models)),t}function ke(e){let t=$(e.models.find(e=>e.trim().length>0)??``,e.providerModelAliases),n={apiBase:e.apiBase.trim(),extraHeaders:Z(e.extraHeaders),model:t||null};return e.apiKey.trim().length>0&&(n.apiKey=e.apiKey.trim()),e.supportsWireApi&&(n.wireApi=e.wireApi),n}function Ae(e){return i(e===`off`?`chatThinkingLevelOff`:e===`minimal`?`chatThinkingLevelMinimal`:e===`low`?`chatThinkingLevelLow`:e===`medium`?`chatThinkingLevelMedium`:e===`high`?`chatThinkingLevelHigh`:e===`adaptive`?`chatThinkingLevelAdaptive`:`chatThinkingLevelXhigh`)}function je(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 Me(e){let{required:t,hasDefault:n,optionCount:r}=e;return t&&n&&r>1&&r<=3}function Ne(e,t,n){let r=$(t,n);return r?e.includes(r)?{models:e,draft:``}:{models:[...e,r],draft:``}:{models:e,draft:t}}function Pe(e,t,n){let r={...t};return delete r[n],{models:e.filter(e=>e!==n),modelConfig:r}}function Fe(e,t,n){let r=e[t],i=r?.thinking?.supported??[],a=i.includes(n)?i.filter(e=>e!==n):z.filter(e=>e===n||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={...e};return s.thinking||s.vision===!0?c[t]=s:delete c[t],c}function Ie(e,t,n){let r=e[t],i=r?.thinking;return!i||i.supported.length===0||n&&!i.supported.includes(n)?e:{...e,[t]:{...r,thinking:n?{supported:i.supported,default:n}:{supported:i.supported}}}}function Le(e,t,n){let r={...e[t],vision:n?!0:void 0},i={...e};return r.thinking||r.vision===!0?i[t]=r:delete i[t],i}function Re(e){let{providerName:t,providerSpec:n,language:r}=e,i=n?.auth,a=i?.methods??[];return{providerAuth:i,providerAuthMethodOptions:a.map(e=>({value:e.id,label:e.label?.[r]||e.label?.en||e.id})),providerAuthMethods:a,preferredAuthMethodId:je({providerName:n?.providerType??t,methods:a,defaultMethodId:i?.defaultMethodId,language:r}),shouldUseAuthMethodPills:Me({required:i?.kind===`device_code`,hasDefault:!!i?.defaultMethodId?.trim(),optionCount:a.length})}}function ze(e,t){let n=!!e?.supportsWireApi||t,r=(e?.wireApiOptions||[`auto`,`chat`,`responses`]).map(e=>({value:e,label:i(e===`chat`?`wireApiChat`:e===`responses`?`wireApiResponses`:`wireApiAuto`)}));return{shouldUseWireApiPills:Me({required:n,hasDefault:typeof e?.defaultWireApi==`string`&&e.defaultWireApi.length>0,optionCount:r.length}),supportsWireApi:n,wireApiSelectOptions:r}}function Be(e){let{providerName:t,providersView:n,templatesView:r,schema:a,language:o}=e,s=t?n?.providers[t]:null,c=r?.providerTemplates.find(e=>e.providerType===s?.providerType),l=s??ve,u=a?.uiHints,d=!!s?.isCustom,f=t?G(`providers.${t}.apiKey`,u):void 0,p=t?G(`providers.${t}.apiBase`,u):void 0,m=t?G(`providers.${t}.extraHeaders`,u):void 0,h=t?G(`providers.${t}.wireApi`,u):void 0,g=c?.displayName||s?.displayName||t||``,_=(l.displayName||``).trim()||g,v=l.enabled!==!1,y=Q([c?.modelPrefix||c?.providerType||``,t||``]),b=c?.defaultApiBase||``,x=l.apiBase||b,S=Z(l.extraHeaders||null),C=l.wireApi||c?.defaultWireApi||`auto`,w=Se(Q((c?.defaultModels??[]).map(e=>$(e,y))),Q((l.models??[]).map(e=>$(e,y)))),T=we(Te(c?.modelConfig,l.modelConfig,y),w),E=c?.apiBaseHelp?.[o]||c?.apiBaseHelp?.en||p?.help||i(`providerApiBaseHelp`),D=Re({providerName:t,providerSpec:c,language:o}),O=ze(c,d);return{apiBaseHelpText:E,apiBaseHint:p,apiKeyHint:f,currentApiBase:x,currentEditableModels:w,currentEnabled:v,currentHeaders:S,currentModelConfig:T,currentWireApi:C,defaultApiBase:b,defaultDisplayName:g,effectiveDisplayName:_,extraHeadersHint:m,...D,providerConfig:s,providerModelAliases:y,resolvedProviderConfig:l,wireApiHint:h,...O}}function Ve(e){let{models:t,modelConfig:n,modelDraft:r,showModelInput:a,onModelDraftChange:o,onShowModelInputChange:l,onAddModel:f,onRemoveModel:p,onToggleModelThinkingLevel:_,onSetModelThinkingDefault:v,onSetModelVision:y,thinkingLevels:T,formatThinkingLevelLabel:E}=e;return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(s,{className:`text-sm font-medium text-foreground`,children:i(`providerModelsTitle`)}),a?null:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>l(!0),className:`flex items-center gap-1 text-xs font-medium text-primary hover:text-primary/80`,children:[(0,X.jsx)(k,{className:`h-3 w-3`}),i(`providerAddModel`)]})]}),a?(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(u,{value:r,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),f()),e.key===`Escape`&&(l(!1),o(``))},placeholder:i(`providerModelInputPlaceholder`),className:`flex-1 rounded-xl`,autoFocus:!0}),(0,X.jsx)(c,{type:`button`,size:`sm`,onClick:f,disabled:r.trim().length===0,children:i(`add`)}),(0,X.jsx)(c,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>{l(!1),o(``)},children:(0,X.jsx)(M,{className:`h-4 w-4`})})]}):null,t.length===0?(0,X.jsxs)(`div`,{className:`rounded-xl bg-muted/35 px-4 py-6 text-center`,children:[(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`providerModelsEmptyShort`)}),a?null:(0,X.jsx)(`button`,{type:`button`,onClick:()=>l(!0),className:`mt-2 text-sm font-medium text-primary hover:text-primary/80`,children:i(`providerAddFirstModel`)})]}):(0,X.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:t.map(e=>{let t=n[e],r=t?.thinking,a=r?.supported??[],o=r?.default??null,c=t?.vision===!0;return(0,X.jsxs)(`div`,{className:`group inline-flex max-w-full items-center gap-1 rounded-full border border-border/55 bg-muted/45 px-3 py-1.5`,children:[(0,X.jsx)(`span`,{className:`max-w-[140px] truncate text-sm text-foreground sm:max-w-[220px]`,children:e}),(0,X.jsxs)(g,{children:[(0,X.jsx)(m,{asChild:!0,children:(0,X.jsx)(`button`,{type:`button`,className:`inline-flex h-5 w-5 items-center justify-center rounded-full text-muted-foreground/70 opacity-100 transition-opacity hover:bg-muted hover:text-foreground md:opacity-0 md:group-hover:opacity-100 md:group-focus-within:opacity-100`,"aria-label":i(`providerModelThinkingTitle`),title:i(`providerModelThinkingTitle`),children:(0,X.jsx)(A,{className:`h-3 w-3`})})}),(0,X.jsxs)(h,{className:`w-80 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-lg bg-muted/50 px-3 py-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`p`,{className:`text-xs font-semibold text-foreground`,children:i(`providerModelVisionTitle`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`providerModelVisionHint`)})]}),(0,X.jsx)(d,{checked:c,onCheckedChange:t=>y(e,t)})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`p`,{className:`text-xs font-semibold text-foreground`,children:i(`providerModelThinkingTitle`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`providerModelThinkingHint`)})]}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:T.map(t=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>_(e,t),className:`rounded-full border px-2.5 py-1 text-xs font-medium transition-colors ${a.includes(t)?`border-foreground/15 bg-foreground text-background`:`border-border/55 bg-muted/50 text-muted-foreground hover:border-border hover:bg-muted hover:text-foreground`}`,children:E(t)},t))}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(s,{className:`text-xs font-medium text-foreground`,children:i(`providerModelThinkingDefault`)}),(0,X.jsxs)(w,{value:o??`__none__`,onValueChange:t=>v(e,t===`__none__`?null:t),disabled:a.length===0,children:[(0,X.jsx)(x,{className:`h-8 rounded-lg text-xs`,children:(0,X.jsx)(b,{})}),(0,X.jsxs)(S,{children:[(0,X.jsx)(C,{value:`__none__`,children:i(`providerModelThinkingDefaultNone`)}),a.map(e=>(0,X.jsx)(C,{value:e,children:E(e)},e))]})]}),a.length===0?(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`providerModelThinkingNoSupported`)}):null]})]})]}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>p(e),className:`inline-flex h-5 w-5 items-center justify-center rounded-full text-muted-foreground/70 opacity-100 transition-opacity hover:bg-muted hover:text-foreground md:opacity-0 md:group-hover:opacity-100 md:group-focus-within:opacity-100`,"aria-label":i(`remove`),children:(0,X.jsx)(M,{className:`h-3 w-3`})})]},e)})})]})}function He({apiKeySet:e,className:t,enabled:n}){return n?(0,X.jsx)(N,{status:e?`ready`:`setup`,label:i(e?`statusReady`:`statusSetup`),className:t}):(0,X.jsx)(N,{status:`inactive`,label:i(`disabled`),className:t})}function Ue(e){let{providerName:t,providerAuth:n,resolvedAuthMethodId:r}=e,a=f(),o=te(),s=V(),c=W(),[u,d]=(0,Y.useState)(``),[p,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(``),_=(0,Y.useRef)(null),v=(0,Y.useCallback)(()=>{_.current!==null&&(window.clearTimeout(_.current),_.current=null)},[]),y=(0,Y.useCallback)((e,n)=>{v(),_.current=window.setTimeout(()=>{(async()=>{if(t)try{let r=await s.mutateAsync({provider:t,data:{sessionId:e}});if(r.status===`pending`){g(i(`providerAuthWaitingBrowser`)),y(e,r.nextPollMs??n);return}if(r.status===`authorized`){m(null),v(),g(i(`providerAuthCompleted`)),l.success(i(`providerAuthCompleted`)),a.invalidateQueries({queryKey:[`config`]}),a.invalidateQueries({queryKey:[`providers`]});return}m(null),v(),g(r.message||`Authorization ${r.status}.`),l.error(r.message||`Authorization ${r.status}.`)}catch(e){m(null),v();let t=e instanceof Error?e.message:String(e);g(t),l.error(`Authorization failed: ${t}`)}})()},Math.max(1e3,n))},[v,s,t,a]),b=(0,Y.useCallback)(async()=>{if(!(!t||n?.kind!==`device_code`))try{d(t),g(``);let e=await o.mutateAsync({provider:t,data:r?{methodId:r}:{}});if(!e.sessionId||!e.verificationUri)throw Error(i(`providerAuthStartFailed`));m(e.sessionId),g(`${i(`providerAuthOpenPrompt`)}${e.userCode}${i(`providerAuthOpenPromptSuffix`)}`),await F.openExternalUrl(e.verificationUri),y(e.sessionId,e.intervalMs)}catch(e){let t=e instanceof Error?e.message:String(e);m(null),v(),g(t),l.error(`${i(`providerAuthStartFailed`)}: ${t}`)}},[v,n?.kind,t,r,y,o]),x=(0,Y.useCallback)(async()=>{if(!(!t||n?.kind!==`device_code`))try{d(t),v(),m(null);let e=await c.mutateAsync({provider:t});g(`${i(`providerAuthImportStatusPrefix`)}${e.expiresAt?` (expires: ${e.expiresAt})`:``}`),l.success(i(`providerAuthImportSuccess`)),a.invalidateQueries({queryKey:[`config`]}),a.invalidateQueries({queryKey:[`providers`]})}catch(e){let t=e instanceof Error?e.message:String(e);g(t),l.error(`${i(`providerAuthImportFailed`)}: ${t}`)}},[v,c,n?.kind,t,a]);return(0,Y.useEffect)(()=>{v()},[v,t]),(0,Y.useEffect)(()=>()=>v(),[v]),{authSessionId:u===t?p:null,authStatusMessage:u===t?h:``,importAuthFromCli:x,importPending:c.isPending,startAuth:b,startPending:o.isPending}}function We({providerName:e,onProviderDeleted:n}){let{data:r}=ae(),{data:a}=re(),{data:o}=ie(),s=H(),c=B(),u=ne(),[d,f]=(0,Y.useState)(``),[p,m]=(0,Y.useState)(``),[h,g]=(0,Y.useState)(null),[_,v]=(0,Y.useState)(`auto`),[y,b]=(0,Y.useState)([]),[x,S]=(0,Y.useState)({}),[C,w]=(0,Y.useState)(``),[T,E]=(0,Y.useState)(``),[D,O]=(0,Y.useState)(!1),[k,A]=(0,Y.useState)(!1),[j,M]=(0,Y.useState)(``),N=t(),P=(0,Y.useMemo)(()=>Be({providerName:e,providersView:r,templatesView:a,schema:o,language:N}),[N,e,r,o,a]),{currentApiBase:F,currentEditableModels:I,currentHeaders:L,currentModelConfig:R,currentWireApi:z,defaultApiBase:ee,effectiveDisplayName:V,providerAuth:te,providerAuthMethods:U,providerConfig:W,providerModelAliases:G,resolvedProviderConfig:K,preferredAuthMethodId:q,supportsWireApi:J}=P,oe=T.trim()||V||e||i(`providersSelectPlaceholder`),se=(0,Y.useMemo)(()=>{if(!U.length)return``;let e=j.trim();return e&&U.some(t=>t.id===e)?e:q||U[0]?.id||``},[j,q,U]),{authSessionId:ce,authStatusMessage:ue,importAuthFromCli:de,importPending:fe,startAuth:pe,startPending:me}=Ue({providerName:e,providerAuth:te,resolvedAuthMethodId:se});(0,Y.useEffect)(()=>{if(!e){f(``),m(``),g(null),v(`auto`),b([]),S({}),w(``),E(``),M(``);return}f(``),m(F),g(K.extraHeaders||null),v(z),b(I),S(R),w(``),E(V),M(q)},[e,F,K.extraHeaders,z,I,R,V,q]),(0,Y.useEffect)(()=>S(e=>we(e,y)),[y]);let he=(0,Y.useMemo)(()=>De({providerName:e,apiKey:d,apiBase:p,currentApiBase:F,extraHeaders:h,currentHeaders:L,supportsWireApi:J,wireApi:_,currentWireApi:z,models:y,currentEditableModels:I,modelConfig:x,currentModelConfig:R,providerDisplayName:T,effectiveDisplayName:V}),[e,d,p,F,h,L,J,_,z,y,I,x,R,T,V]);return!e||!W?(0,X.jsx)(le,{children:(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:i(`providersSelectTitle`)}),(0,X.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:i(`providersSelectDescription`)})]})}):(0,X.jsx)(Ge,{context:P,language:N,providerTitle:oe,providerDisplayName:T,apiKey:d,apiBase:p,extraHeaders:h,wireApi:_,models:y,modelConfig:x,modelDraft:C,showAdvanced:D,showModelInput:k,resolvedAuthMethodId:se,authSessionId:ce,authStatusMessage:ue,hasChanges:he,isDeletePending:c.isPending,isUpdatePending:s.isPending,isTestPending:u.isPending,startPending:me,importPending:fe,onProviderDisplayNameChange:E,onApiKeyChange:f,onApiBaseChange:m,onAuthMethodChange:M,onStartProviderAuth:pe,onImportProviderAuthFromCli:de,onModelDraftChange:w,onShowModelInputChange:A,onAddModel:()=>{let e=Ne(y,C,G);b(e.models),w(e.draft)},onRemoveModel:e=>{let t=Pe(y,x,e);b(t.models),S(t.modelConfig)},onToggleModelThinkingLevel:(e,t)=>{S(n=>Fe(n,e,t))},onSetModelThinkingDefault:(e,t)=>{S(n=>Ie(n,e,t))},onSetModelVision:(e,t)=>{S(n=>Le(n,e,t))},onShowAdvancedChange:O,onWireApiChange:v,onExtraHeadersChange:g,onDeleteProvider:async()=>{if(e&&window.confirm(i(`providerDeleteConfirm`)))try{await c.mutateAsync({provider:e}),n?.(e)}catch{}},onSubmit:t=>{t.preventDefault(),e&&s.mutate({provider:e,data:Oe({providerName:e,apiKey:d,apiBase:p,currentApiBase:F,defaultApiBase:ee,extraHeaders:h,currentHeaders:L,supportsWireApi:J,wireApi:_,currentWireApi:z,models:y,currentEditableModels:I,modelConfig:x,currentModelConfig:R,providerDisplayName:T,effectiveDisplayName:V})})},onTestConnection:async()=>{if(e)try{let t=await u.mutateAsync({provider:e,data:ke({apiKey:d,apiBase:p,extraHeaders:h,supportsWireApi:J,wireApi:_,models:y,providerModelAliases:G})});if(t.success){l.success(`${i(`providerTestConnectionSuccess`)} (${t.latencyMs}ms)`);return}let n=[`provider=${t.provider}`,`latency=${t.latencyMs}ms`];t.model&&n.push(`model=${t.model}`),l.error(`${i(`providerTestConnectionFailed`)}: ${t.message} | ${n.join(` | `)}`)}catch(e){let t=e instanceof Error?e.message:String(e);l.error(`${i(`providerTestConnectionFailed`)}: ${t}`)}}})}function Ge(e){let{context:t,language:n,providerTitle:r,providerDisplayName:a,apiKey:o,apiBase:l,extraHeaders:d,wireApi:f,models:p,modelConfig:m,modelDraft:h,showAdvanced:g,showModelInput:_,resolvedAuthMethodId:v,authSessionId:y,authStatusMessage:b,hasChanges:x,isDeletePending:S,isUpdatePending:C,isTestPending:w,startPending:T,importPending:E,onProviderDisplayNameChange:D,onApiKeyChange:O,onApiBaseChange:k,onAuthMethodChange:A,onStartProviderAuth:M,onImportProviderAuthFromCli:N,onModelDraftChange:P,onShowModelInputChange:F,onAddModel:I,onRemoveModel:L,onToggleModelThinkingLevel:R,onSetModelThinkingDefault:B,onSetModelVision:V,onShowAdvancedChange:te,onWireApiChange:ne,onExtraHeadersChange:H,onDeleteProvider:U,onSubmit:re,onTestConnection:ie}=e,W=t.providerAuthMethods.find(e=>e.id===v);return(0,X.jsxs)(se,{children:[(0,X.jsx)(q,{className:`px-5 py-4`,children:(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(`h3`,{className:`truncate text-lg font-semibold text-foreground`,children:r}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:U,disabled:S,className:`text-muted-foreground/70 transition-colors hover:text-red-500`,title:i(`providerDelete`),children:(0,X.jsx)(j,{className:`h-4 w-4`})}),(0,X.jsx)(He,{enabled:t.currentEnabled,apiKeySet:t.resolvedProviderConfig.apiKeySet})]})]})}),(0,X.jsxs)(`form`,{onSubmit:re,className:`flex min-h-0 flex-1 flex-col`,children:[(0,X.jsxs)(ce,{className:`space-y-4 px-5 py-4`,children:[(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(s,{htmlFor:`providerDisplayName`,className:`text-sm font-medium text-foreground`,children:i(`providerDisplayName`)}),(0,X.jsx)(u,{id:`providerDisplayName`,type:`text`,value:a,onChange:e=>D(e.target.value),placeholder:t.defaultDisplayName||i(`providerDisplayNamePlaceholder`),className:`rounded-xl`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`providerDisplayNameHelpShort`)})]}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(s,{htmlFor:`apiKey`,className:`text-sm font-medium text-foreground`,children:i(`apiKey`)}),(0,X.jsx)(pe,{id:`apiKey`,value:o,isSet:t.resolvedProviderConfig.apiKeySet,onChange:e=>O(e.target.value),placeholder:t.apiKeyHint?.placeholder??i(`enterApiKey`),className:`rounded-xl`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`leaveBlankToKeepUnchanged`)})]}),(0,X.jsx)(_e,{providerAuth:t.providerAuth,providerAuthNote:t.providerAuth?.note?.[n]||t.providerAuth?.note?.en||t.providerAuth?.displayName||``,providerAuthMethodOptions:t.providerAuthMethodOptions,providerAuthMethodsCount:t.providerAuthMethods.length,selectedAuthMethodHint:W?.hint?.[n]||W?.hint?.en||``,shouldUseAuthMethodPills:t.shouldUseAuthMethodPills,resolvedAuthMethodId:v,onAuthMethodChange:A,onStartProviderAuth:M,onImportProviderAuthFromCli:N,startPending:T,importPending:E,authSessionId:y,authStatusMessage:b}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(s,{htmlFor:`apiBase`,className:`text-sm font-medium text-foreground`,children:i(`apiBase`)}),(0,X.jsx)(u,{id:`apiBase`,type:`text`,value:l,onChange:e=>k(e.target.value),placeholder:t.defaultApiBase||t.apiBaseHint?.placeholder||`https://api.example.com`,className:`rounded-xl`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t.apiBaseHelpText})]}),(0,X.jsx)(Ve,{models:p,modelConfig:m,modelDraft:h,showModelInput:_,onModelDraftChange:P,onShowModelInputChange:F,onAddModel:I,onRemoveModel:L,onToggleModelThinkingLevel:R,onSetModelThinkingDefault:B,onSetModelVision:V,thinkingLevels:z,formatThinkingLevelLabel:Ae}),(0,X.jsx)(ge,{showAdvanced:g,onShowAdvancedChange:te,supportsWireApi:t.supportsWireApi,wireApiLabel:i(`wireApi`),wireApi:f,onWireApiChange:ne,shouldUseWireApiPills:t.shouldUseWireApiPills,wireApiSelectOptions:t.wireApiSelectOptions,extraHeadersLabel:i(`extraHeaders`),extraHeaders:d,onExtraHeadersChange:H})]}),(0,X.jsx)(ue,{children:(0,X.jsxs)(ee,{align:`between`,children:[(0,X.jsxs)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:ie,disabled:w,children:[(0,X.jsx)(de,{className:`mr-1.5 h-3.5 w-3.5`}),i(w?`providerTestingConnection`:`providerTestConnection`)]}),(0,X.jsx)(c,{type:`submit`,size:`sm`,disabled:C||!x,children:i(C?`saving`:x?`save`:`unchanged`)})]})})]})]})}function Ke(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 qe(e,t=[]){let n=new Map(t.map((e,t)=>[e,t]));return e.map((e,t)=>({provider:e,index:t})).sort((e,t)=>{let r=n.get(e.provider.providerId),i=n.get(t.provider.providerId);if(r!==void 0||i!==void 0)return(r??2**53-1)-(i??2**53-1);let a=e.provider.providerType===`nextclaw`?1:0,o=t.provider.providerType===`nextclaw`?1:0;return a===o?e.index-t.index:a-o}).map(({provider:e})=>e)}function Je(e){let t=e.findIndex(e=>e.providerType===`zhipu`),n=e.findIndex(e=>e.providerType===`dashscope-coding-plan`);return e.map((e,t)=>({template:e,index:t})).sort((e,r)=>{let i=({template:e,index:r})=>e.providerType===`nextclaw`?2**53-1:e.providerType===`deepseek`&&n>=0?n-.5:e.providerType===`mimo`&&t>=0?t+.5:r;return i(e)-i(r)}).map(({template:e})=>e)}function Ye(){let{isMobile:e}=O(),{data:t}=ae(),{data:n}=re(),r=U(),s=B(),l=H(),[f,p]=(0,Y.useState)(null),[y,b]=(0,Y.useState)(null),[x,S]=(0,Y.useState)(!1),[C,w]=(0,Y.useState)([]),[E,A]=(0,Y.useState)(``),M=(0,Y.useMemo)(()=>qe(Object.values(t?.providers??{}),C),[t?.providers,C]),F=(0,Y.useMemo)(()=>n?.providerTemplates??[],[n?.providerTemplates]),I=(0,Y.useMemo)(()=>Je(F),[F]),L=(0,Y.useMemo)(()=>new Map(F.map(e=>[e.providerType,e])),[F]),R=(0,Y.useMemo)(()=>{let e=E.trim().toLowerCase();return M.filter(t=>{if(!e)return!0;let n=t.providerType?L.get(t.providerType):null;return(t.displayName?.trim()||n?.displayName||t.providerId).toLowerCase().includes(e)||t.providerId.toLowerCase().includes(e)})},[M,E,L]),z=(0,Y.useMemo)(()=>f&&R.some(e=>e.providerId===f)?f:e?null:R[0]?.providerId??null,[R,e,f]);return!t||!n?(0,X.jsx)(o,{title:i(`providersPageTitle`),description:i(`providersPageDescription`),layout:`split`,children:(0,X.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:i(`providersLoading`)})}):(0,X.jsxs)(o,{title:i(`providersPageTitle`),description:i(`providersPageDescription`),layout:`split`,children:[(0,X.jsxs)(K,{className:`md:min-h-0`,compactView:f?`detail`:`list`,onMobileBack:()=>p(null),mobileListLabel:i(`providersPageTitle`),children:[(0,X.jsxs)(oe,{children:[(0,X.jsx)(q,{className:`space-y-3 px-4 pb-3 pt-4`,children:(0,X.jsxs)(g,{open:x,onOpenChange:S,children:[(0,X.jsx)(m,{asChild:!0,children:(0,X.jsxs)(c,{type:`button`,variant:`outline`,className:`w-full justify-center`,disabled:r.isPending,children:[(0,X.jsx)(k,{className:`mr-2 h-4 w-4`}),r.isPending?i(`saving`):i(`providerAdd`)]})}),(0,X.jsxs)(h,{className:`w-[42rem] max-w-[calc(100vw-2rem)] p-3`,align:`start`,children:[(0,X.jsx)(`div`,{className:`mb-2 px-1 text-xs font-semibold text-muted-foreground`,children:i(`providerTemplatePickerTitle`)}),(0,X.jsxs)(`div`,{className:`grid max-h-[24rem] grid-cols-2 gap-2 overflow-y-auto sm:grid-cols-3`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`flex min-h-20 w-full flex-col items-start gap-2 rounded-lg border border-dashed border-border/70 bg-muted/20 px-3 py-2 text-left transition-colors hover:border-border hover:bg-muted/45`,onClick:async()=>{try{let e=await r.mutateAsync({data:{providerType:null}});A(``),p(e.providerId),w(t=>[e.providerId,...t.filter(t=>t!==e.providerId)]),S(!1)}catch{}},children:[(0,X.jsx)(P,{name:`custom`,className:`h-8 w-8 rounded-lg border border-border/60 bg-muted/50`}),(0,X.jsx)(`span`,{className:`line-clamp-2 min-w-0 text-xs font-semibold leading-4 text-foreground`,children:i(`providerAddCustom`)})]}),I.map(e=>(0,X.jsxs)(`button`,{type:`button`,className:`flex min-h-20 w-full flex-col items-start gap-2 rounded-lg border border-border/55 bg-muted/15 px-3 py-2 text-left transition-colors hover:border-border/80 hover:bg-muted/40`,onClick:async()=>{try{let t=await r.mutateAsync({data:{providerType:e.providerType}});A(``),p(t.providerId),w(e=>[t.providerId,...e.filter(e=>e!==t.providerId)]),S(!1)}catch{}},children:[(0,X.jsx)(P,{name:e.providerType,src:e.logo?`/logos/${e.logo}`:null,className:`h-8 w-8 rounded-lg border border-border/55 bg-background`,imgClassName:`h-4 w-4 object-contain`}),(0,X.jsx)(`span`,{className:`line-clamp-2 min-w-0 text-xs font-semibold leading-4 text-foreground`,children:e.displayName||e.providerType})]},e.providerType))]})]})]})}),(0,X.jsx)(`div`,{className:`border-b border-border/70 px-4 py-3`,children:(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(v,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/70`}),(0,X.jsx)(u,{value:E,onChange:e=>A(e.target.value),placeholder:i(`providersFilterPlaceholder`),className:`h-10 rounded-xl pl-9`})]})}),(0,X.jsxs)(ce,{className:`space-y-2 p-3`,children:[R.map(e=>{let t=e.providerType?L.get(e.providerType):null,n=e.enabled!==!1,r=!!(n&&e.apiKeySet),o=e.displayName?.trim()||t?.displayName||e.providerId,s=Ke(e.apiBase||t?.defaultApiBase||``)||i(`providersDefaultDescription`);return(0,X.jsx)(`div`,{onClick:()=>p(e.providerId),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),p(e.providerId))},role:`button`,tabIndex:0,className:a(`group w-full rounded-xl p-2.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40`,z===e.providerId?`bg-background/95 text-foreground shadow-sm`:`bg-transparent text-muted-foreground hover:bg-background/65 hover:text-foreground`),children:(0,X.jsxs)(`div`,{className:`relative min-h-10`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3 pr-20`,children:[(0,X.jsx)(P,{name:e.providerType??e.providerId,src:t?.logo?`/logos/${t.logo}`:null,className:`h-10 w-10 rounded-lg bg-background/80`,imgClassName:`h-5 w-5 object-contain`,fallback:(0,X.jsx)(`span`,{className:`text-sm font-semibold uppercase text-muted-foreground`,children:e.providerId[0]})}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`p`,{className:`truncate text-sm font-semibold text-foreground`,children:o}),(0,X.jsx)(`p`,{className:`truncate font-mono text-[10px] text-muted-foreground/65`,children:e.providerId}),(0,X.jsxs)(`p`,{className:`line-clamp-1 text-[11px] text-muted-foreground`,children:[s,` · `,e.models?.length??0]})]})]}),(0,X.jsxs)(`div`,{className:`absolute right-0 top-0 flex items-center gap-1.5 opacity-70 transition-opacity group-hover:opacity-100`,children:[(0,X.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,X.jsx)(d,{checked:n,disabled:l.isPending,title:i(n?`disabled`:`enabled`),className:`h-[18px] w-8`,thumbClassName:`h-4 w-4 data-[state=checked]:translate-x-4`,onCheckedChange:t=>{l.mutateAsync({provider:e.providerId,data:{enabled:t},silentSuccess:!0})}})}),(0,X.jsxs)(g,{children:[(0,X.jsx)(m,{asChild:!0,children:(0,X.jsx)(`button`,{type:`button`,className:`inline-flex h-7 w-7 items-center justify-center rounded-lg text-muted-foreground/70 hover:bg-muted hover:text-foreground`,onClick:e=>e.stopPropagation(),title:i(`more`),children:(0,X.jsx)(T,{className:`h-4 w-4`})})}),(0,X.jsx)(h,{className:`w-40 p-1`,align:`end`,onClick:e=>e.stopPropagation(),children:(0,X.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-md px-2 py-2 text-sm text-red-600 hover:bg-red-50`,onClick:()=>b(e.providerId),children:[(0,X.jsx)(j,{className:`h-4 w-4`}),i(`providerDelete`)]})})]})]}),(0,X.jsx)(N,{status:n?r?`ready`:`setup`:`inactive`,label:i(n?r?`statusReady`:`statusSetup`:`disabled`),className:`absolute bottom-0 right-0 justify-end`})]})},e.providerId)}),R.length===0?(0,X.jsx)(J,{icon:D,title:i(`providersNoMatch`)}):null]})]}),(0,X.jsx)(We,{providerName:z??void 0,onProviderDeleted:e=>{w(t=>t.filter(t=>t!==e)),e===z&&p(null)}})]}),(0,X.jsx)(_,{open:!!y,onOpenChange:e=>{e||b(null)},title:i(`providerDelete`),description:y??void 0,confirmLabel:i(`delete`),variant:`destructive`,onCancel:()=>b(null),onConfirm:()=>{y&&s.mutateAsync({provider:y}).then(()=>{w(e=>e.filter(e=>e!==y)),y===z&&p(null),b(null)})}})]})}export{Ye as ProvidersConfigPage};
|