@chenpu17/cc-gw 0.10.2 → 0.10.3
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/package.json +5 -5
- package/src/web/dist/assets/{About-CcTMpvYw.js → About-BlRwok0C.js} +1 -1
- package/src/web/dist/assets/{ApiKeys-Dbteu5ri.js → ApiKeys-__yoww1B.js} +1 -1
- package/src/web/dist/assets/{ConfirmDialog-Cc9UQTDU.js → ConfirmDialog-MfZNB6Df.js} +1 -1
- package/src/web/dist/assets/{Dashboard-B5QF-lmL.js → Dashboard-DW5yhjz2.js} +1 -1
- package/src/web/dist/assets/{Events-BFIgKbWf.js → Events-DIHxXK2c.js} +1 -1
- package/src/web/dist/assets/{Help-C8IpZL_I.js → Help-53lFT60j.js} +1 -1
- package/src/web/dist/assets/{Login-hQw0WqP_.js → Login-wXXmJSKA.js} +1 -1
- package/src/web/dist/assets/{Logs-Cq3T-TNv.js → Logs-DlUZYPnC.js} +1 -1
- package/src/web/dist/assets/{ProvidersWorkbench-D4h3nYno.js → ProvidersWorkbench-B30mrfQ5.js} +1 -1
- package/src/web/dist/assets/{Settings-CQ6tvunu.js → Settings-DRW9xcJ_.js} +1 -1
- package/src/web/dist/assets/{Setup-BpNWz4e5.js → Setup-Du0PQb1-.js} +1 -1
- package/src/web/dist/assets/{apiKeys-Dvp0S9i6.js → apiKeys-CQ7yz9uu.js} +1 -1
- package/src/web/dist/assets/{app-DmrDy3E3.js → app-CDdTBXQ0.js} +4 -4
- package/src/web/dist/assets/{gateway-DypmM2yK.js → gateway-CbmElcXM.js} +1 -1
- package/src/web/dist/assets/{landing-CXkPmDBs.js → landing-Cra6nfAd.js} +1 -1
- package/src/web/dist/assets/package-B8-r92OZ.js +1 -0
- package/src/web/dist/assets/{shared-BzlaTM1w.js → shared-ByllZUE0.js} +1 -1
- package/src/web/dist/assets/{useAppMutation-CErBrMAz.js → useAppMutation-BebVa-9_.js} +1 -1
- package/src/web/dist/assets/{useProviderForm-DruDgLK_.js → useProviderForm-Y_sOoFFu.js} +1 -1
- package/src/web/dist/index.html +1 -1
- package/src/web/dist/landing.html +2 -2
- package/src/web/dist/assets/package-CKunvygM.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as o,d as i,r as e}from"./app-
|
|
1
|
+
import{i as o,d as i,r as e}from"./app-CDdTBXQ0.js";const r={configRequest(){return{url:"/api/config",method:"GET"}},configInfoRequest(){return{url:"/api/config/info",method:"GET"}},providersRequest(){return{url:"/api/providers",method:"GET"}},configInfo:async()=>e(r.configInfoRequest()),providers:async()=>e(r.providersRequest()),saveConfig:async n=>{await o(i.put("/api/config",n))}};export{r as g};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{B as v,c as g}from"./global-D5dyWHqO.js";import{r as u,j as e,a4 as O,a9 as L,aa as N,ab as p,ac as b,ad as j,P as K,ae as T,af as P,ag as R,ah as E,ai as D,aj as q,ak as k,a8 as U,q as B}from"./vendor-CITafuNQ.js";import{c as A}from"./clipboard-BnAnBk_-.js";import{p as G}from"./package-
|
|
1
|
+
import{B as v,c as g}from"./global-D5dyWHqO.js";import{r as u,j as e,a4 as O,a9 as L,aa as N,ab as p,ac as b,ad as j,P as K,ae as T,af as P,ag as R,ah as E,ai as D,aj as q,ak as k,a8 as U,q as B}from"./vendor-CITafuNQ.js";import{c as A}from"./clipboard-BnAnBk_-.js";import{p as G}from"./package-B8-r92OZ.js";const S="/assets/live-dashboard-B7vLOY_S.png",_="/assets/live-logs-PRpgTV6S.png",F="/assets/live-model-management-xkBDeuLk.png",W="/assets/live-api-keys-CJUuaCev.png",C="/assets/live-en-dashboard-CJoX7IQT.png",Y="/assets/live-en-logs-BGGL53ab.png",H="/assets/live-en-model-management-BpjNblfR.png",$="/assets/live-en-api-keys-Bx8N-eoh.png",w=G.version,Q=(o,a)=>a[o],t={nav:{why:{zh:"现状",en:"The mess"},how:{zh:"怎么用",en:"How"},debug:{zh:"排查",en:"Debug"},local:{zh:"本地优先",en:"Local-first"},start:{zh:"开始",en:"Start"},faq:{zh:"FAQ",en:"FAQ"}},ctaConsole:{zh:"打开控制台",en:"Open console"},ctaInstall:{zh:"立即安装",en:"Install now"},ctaPreview:{zh:"看看控制台长什么样",en:"Preview the console"},hero:{badge:{zh:"v"+w+" · Rust 内核 · 完全开源",en:"v"+w+" · Rust core · Open source"},h1Top:{zh:"你的 API Key",en:"Your API key"},h1Bottom:{zh:"不该躺在 30 个 .env 里",en:"shouldn’t live in 30 .env files"},lead:{zh:"cc-gw 在你的机器上跑一个本地网关。Claude Code、OpenAI SDK、Anthropic SDK 全部指向同一个地址。换模型、换 provider、查日志,再也不用翻业务代码。",en:"cc-gw runs a small gateway right on your machine. Point Claude Code, the OpenAI SDK, and the Anthropic SDK at one address — then swap models, switch providers, and trace requests without touching your app code."},note:{zh:"不需要本机有 Rust 环境,npm 自动拉对应平台的预编译二进制。",en:"No Rust toolchain needed — npm pulls the right prebuilt binary for your platform."},proof:[{zh:"一条命令装好,本机就能跑",en:"One command to install, runs on your laptop"},{zh:"客户端只改 baseURL,不动业务逻辑",en:"Clients only change baseURL — your code stays put"},{zh:"所有数据都在 ~/.cc-gw 下,不走云",en:"Everything lives under ~/.cc-gw — nothing leaves your box"}],works:{zh:"已经在以下客户端里跑通",en:"Tested with"}},why:{eyebrow:{zh:"现状",en:"The mess"},title:{zh:"AI 接进来不难,难的是接进来之后",en:"Wiring up AI is easy. Living with it isn’t."},description:{zh:"你大概率已经踩过下面这三件事里的至少两件。这就是为什么有了 cc-gw。",en:"You’ve probably hit at least two of these. That’s why cc-gw exists."},cards:[{title:{zh:"Key 散在各个 .env 里",en:"Keys scattered across .env files"},body:{zh:"每个项目自己一份 baseURL、自己一份 key、自己一份模型名。时间一长,没人敢动,也没人记得清。",en:"Every project keeps its own baseURL, its own key, its own model name. Six months in, nobody dares touch it."},sample:`OPENAI_BASE_URL=https://...
|
|
2
2
|
ANTHROPIC_API_KEY=sk-ant-...
|
|
3
3
|
MODEL=gpt-4o-2024-08-06`},{title:{zh:"出错只能猜",en:"Debugging is just guessing"},body:{zh:"是 payload 错?协议不对?上游挂了?key 被收回了?没有统一日志,只能 curl 一遍试一遍。",en:"Bad payload? Wrong protocol? Upstream down? Key revoked? Without one log to look at, you curl your way through every theory."},sample:`$ curl ... 401
|
|
4
4
|
# 是 key 过期?还是 endpoint 写错了?
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o="0.10.3",s={version:o};export{s as p};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as p,j as e}from"./vendor-CITafuNQ.js";import{c as u,q as m}from"./app-
|
|
1
|
+
import{r as p,j as e}from"./vendor-CITafuNQ.js";import{c as u,q as m}from"./app-CDdTBXQ0.js";import{a as b}from"./apiKeys-CQ7yz9uu.js";import{u as x}from"./i18n-PeX9kBVO.js";const j=[{value:1,labelKey:"apiKeys.analytics.range.today"},{value:7,labelKey:"apiKeys.analytics.range.week"},{value:30,labelKey:"apiKeys.analytics.range.month"}];function v(){var s;const l=[{id:"anthropic",label:"Anthropic"},{id:"openai",label:"OpenAI"}],t=u(m.customEndpoints.all(),b.customEndpointOptionsRequest());return p.useMemo(()=>{var n;const a=(((n=t.data)==null?void 0:n.endpoints)??[]).map(o=>({id:o.id,label:o.label||o.id}));return[...l,...a]},[(s=t.data)==null?void 0:s.endpoints])}function N({available:l,hint:t,onChange:s,selected:a}){const{t:n}=x(),o=a.length===0,i=()=>{s([])},c=r=>{if(a.includes(r)){s(a.filter(d=>d!==r));return}s([...a,r])};return e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-3 text-xs text-muted-foreground",children:t}),e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-lg border border-border bg-card px-3 py-2.5 transition-colors hover:border-primary/20 hover:bg-accent/50",children:[e.jsx("input",{type:"checkbox",checked:o,onChange:i,className:"h-4 w-4 rounded border-input accent-primary"}),e.jsx("span",{className:"text-sm font-medium",children:n("apiKeys.allEndpoints")})]}),e.jsx("div",{className:"grid max-h-40 gap-1 overflow-y-auto",children:l.map(r=>e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-lg border border-border bg-card px-3 py-2.5 transition-colors hover:border-primary/20 hover:bg-accent/50",children:[e.jsx("input",{type:"checkbox",checked:!o&&a.includes(r.id),onChange:()=>c(r.id),className:"h-4 w-4 rounded border-input accent-primary"}),e.jsx("span",{className:"text-sm",children:r.label}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",r.id,")"]})]},r.id))})]})}export{N as E,j as R,v as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o,b as q}from"./query-DZF7K6hv.js";import{a as x,t as y}from"./app-
|
|
1
|
+
import{a as o,b as q}from"./query-DZF7K6hv.js";import{a as x,t as y}from"./app-CDdTBXQ0.js";function j({mutationFn:C,successToast:u,errorToast:p,invalidateKeys:n,onSuccess:m,onError:f,...M}){const Q=o(),{pushToast:A}=x();return q({...M,mutationFn:async t=>{try{return await C(t)}catch(a){throw y(a)}},onSuccess:async(t,a,w,h)=>{n!=null&&n.length&&await Promise.all(n.map(g=>Q.invalidateQueries({queryKey:g})));const i=u==null?void 0:u(t,a);i&&A({...i,variant:"success"}),await(m==null?void 0:m(t,a,w,h))},onError:async(t,a,w,h)=>{const i=p==null?void 0:p(t,a);i&&A({...i,variant:"error"}),await(f==null?void 0:f(t,a,w,h))}})}export{j as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as S,j as s,$ as oe}from"./vendor-CITafuNQ.js";import{u as ce}from"./query-DZF7K6hv.js";import{a as ue,c as me,q as J,e as pe,i as P,d as I,B as E}from"./app-DmrDy3E3.js";import{g as he}from"./gateway-DypmM2yK.js";import{u as O}from"./i18n-PeX9kBVO.js";import{c as H}from"./global-D5dyWHqO.js";import{D as W}from"./disclosure-Dpus5Sms.js";import{L as M,I as C}from"./label-Dg8bOG83.js";import{S as xe,a as fe,b as be,c as ge,d as B}from"./select-BMTHg2Ox.js";import{S as F}from"./switch-BjJJ5nhB.js";import{B as ve}from"./badge-DMgopDMC.js";const Ge=["claude-sonnet-4-5-20250929","claude-sonnet-4-5-20250929-thinking","claude-sonnet-4-20250514","claude-opus-4-1-20250805","claude-opus-4-1-20250805-thinking","claude-haiku-4-5-20251001","claude-haiku-4-5-20251001-thinking","claude-3-5-haiku-20241022"],Qe=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function ye(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function T(e,r){var t;return(t=e==null?void 0:e.customEndpoints)!=null&&t.length?e.customEndpoints:r}function z(e){return e?Object.entries(e).map(([r,t])=>({id:ye(),source:r,target:t})):[]}function Je(e,r){var a,n,h;if(!e)return{};const t={},i=e.endpointRouting??{};t.anthropic=z(((a=i.anthropic)==null?void 0:a.modelRoutes)??e.modelRoutes??{}),t.openai=z(((n=i.openai)==null?void 0:n.modelRoutes)??{});for(const u of T(e,r))(h=u.routing)!=null&&h.modelRoutes?t[u.id]=z(u.routing.modelRoutes):t[u.id]=[];return t}function je(e,r,t){var n,h,u;const i=T(e,r).find(y=>y.id===t);if(i)return((n=i.routing)==null?void 0:n.modelRoutes)??{};const a=e.endpointRouting??{};return t==="anthropic"?((h=a.anthropic)==null?void 0:h.modelRoutes)??e.modelRoutes??{}:t==="openai"?((u=a.openai)==null?void 0:u.modelRoutes)??{}:{}}function q(e,r,t){var a,n,h;if(t==="anthropic"||t==="openai")return((n=(a=e.endpointRouting)==null?void 0:a[t])==null?void 0:n.defaults)??e.defaults;const i=T(e,r).find(u=>u.id===t);return((h=i==null?void 0:i.routing)==null?void 0:h.defaults)??{completion:null,reasoning:null,background:null,longContextThreshold:e.defaults.longContextThreshold}}function Xe(e,r){if(!e)return{};const t={anthropic:q(e,r,"anthropic"),openai:q(e,r,"openai")};for(const i of T(e,r))t[i.id]=q(e,r,i.id);return t}function Ne(e){const r={};for(const t of e){const i=t.source.trim(),a=t.target.trim();i&&a&&(r[i]=a)}return r}function Ye(e,r){return JSON.stringify(Ne(e))!==JSON.stringify(r)}function We(e,r,t){var a,n,h;if(!r)return;if(e==="anthropic"||e==="openai")return(n=(a=r.endpointRouting)==null?void 0:a[e])==null?void 0:n.compatibility;const i=T(r,t).find(u=>u.id===e);return(h=i==null?void 0:i.routing)==null?void 0:h.compatibility}function Ze(e,r){var i,a;const t={anthropic:((i=e.routingPresets)==null?void 0:i.anthropic)??[],openai:((a=e.routingPresets)==null?void 0:a.openai)??[]};for(const n of T(e,r))t[n.id]=n.routingPresets??[];return t}function we(e,r){const t=[{key:"providers",label:e("modelManagement.tabs.providers"),description:e("modelManagement.tabs.providersDesc"),isSystem:!0,canDelete:!1},{key:"anthropic",label:e("modelManagement.tabs.anthropic"),description:e("modelManagement.tabs.anthropicDesc"),isSystem:!0,canDelete:!1,protocols:["anthropic"]},{key:"openai",label:e("modelManagement.tabs.openai"),description:e("modelManagement.tabs.openaiDesc"),isSystem:!0,canDelete:!1,protocols:["openai-auto","openai-chat","openai-responses"]}],i=r.map(a=>{let n=e("modelManagement.tabs.customEndpoint"),h=[];if(a.paths&&a.paths.length>0)n=`${e("modelManagement.tabs.customEndpoint")}: ${a.paths.map(u=>`${u.path} (${u.protocol})`).join(", ")}`,h=[...new Set(a.paths.map(u=>u.protocol))];else if(a.path){const u=a.protocol||"anthropic";n=`${e("modelManagement.tabs.customEndpoint")}: ${a.path} (${u})`,h=[u]}return{key:a.id,label:a.label||a.id,description:n,isSystem:!1,canDelete:a.deletable!==!1,protocols:h}});return[...t,...i]}function es(e){return e.label&&e.label.trim().length>0?`${e.label} (${e.id})`:e.id}function Se(e,r){if(!e)return!1;const[t]=e.split(":");return t===r||e===r}function Me(e,r,t){if(!e)return[];const i=["anthropic","openai",...T(e,r).map(n=>n.id)],a=[];for(const n of i){const h=je(e,r,n);for(const[u,y]of Object.entries(h))Se(y,t)&&a.push({endpoint:n,source:u,target:y})}return a}function ss(e,r,t){return Me(e,r,t).length}function rs(){var N;const{t:e}=O(),{pushToast:r}=ue(),t=me(J.config.full(),he.configRequest()),i=ce({queryKey:J.customEndpoints.all(),queryFn:pe.list,refetchInterval:1e4}),a=S.useMemo(()=>{var g;return((g=i.data)==null?void 0:g.endpoints)??[]},[(N=i.data)==null?void 0:N.endpoints]),n=S.useMemo(()=>we(e,a),[a,e]),[h,u]=S.useState(null);return S.useEffect(()=>{t.data&&u(t.data)},[t.data]),S.useEffect(()=>{!t.isError||!t.error||r({title:e("providers.toast.loadFailure",{message:t.error.message}),variant:"error"})},[t.error,t.isError,r,e]),{t:e,pushToast:r,config:h,setConfig:u,configQuery:t,customEndpoints:a,customEndpointsQuery:i,tabs:n,ensureConfig:()=>h?!0:(r({title:e("settings.toast.missingConfig"),variant:"error"}),t.refetch(),!1)}}const as={savePreset(e,r){return P(I.post(`/api/routing-presets/${e}`,{name:r}))},applyPreset(e,r){return P(I.post(`/api/routing-presets/${e}/apply`,{name:r}))},deletePreset(e,r){return P(I.delete(`/api/routing-presets/${e}/${encodeURIComponent(r)}`))},testProvider(e,r){return P(I.post(`/api/providers/${e}/test`,r??{}))},probeModels(e,r){return P(I.post(`/api/providers/${e}/models/probe`,r?{provider:r}:{}))}},ke={complete:"border-primary bg-primary text-primary-foreground",current:"border-primary bg-card text-primary ring-2 ring-primary/20",error:"border-destructive bg-card text-destructive ring-2 ring-destructive/20",upcoming:"border-border bg-card text-muted-foreground"},Ue={complete:"text-foreground",current:"text-foreground font-medium",error:"text-destructive font-medium",upcoming:"text-muted-foreground"};function ts({steps:e,current:r,onSelect:t,className:i}){return s.jsx("nav",{"aria-label":"steps",className:H("flex items-start",i),children:e.map((a,n)=>{const h=t&&(a.status==="complete"||a.status==="current"),u=n===e.length-1,y=a.status==="complete"?"bg-primary/40":"bg-border",N=s.jsx("span",{className:H("motion-surface flex h-7 w-7 shrink-0 items-center justify-center rounded-lg border text-xs font-semibold",ke[a.status]),"aria-current":a.id===r?"step":void 0,children:a.status==="complete"?s.jsx(oe,{className:"h-3.5 w-3.5","aria-hidden":!0}):n+1}),g=`stepnav-${a.id}-label`;return s.jsxs("div",{className:"flex flex-1 items-start",children:[s.jsxs("div",{className:"flex min-w-0 flex-col items-center gap-1.5",children:[h?s.jsx("button",{type:"button",onClick:()=>t==null?void 0:t(a.id),"aria-labelledby":g,className:"rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-background motion-surface",children:N}):N,s.jsx("span",{id:g,className:H("text-center text-[11px] leading-tight",Ue[a.status]),children:a.label})]}),u?null:s.jsx("span",{"aria-hidden":!0,className:H("mx-1.5 mt-3.5 h-px flex-1",y)})]},a.id)})})}function Ce({result:e,className:r}){const{t}=O();return s.jsxs("div",{className:H("flex flex-wrap items-center gap-2 rounded-lg px-3 py-2 text-xs",e.ok?"bg-success-bg text-success":"bg-destructive/10 text-destructive",r),children:[s.jsx(ve,{variant:e.ok?"success":"destructive",className:"shrink-0",children:e.ok?t("workbench.testResult.success"):t("workbench.testResult.failure")}),e.status?s.jsx("span",{className:"shrink-0",children:t("workbench.testResult.status",{status:e.status})}):null,e.durationMs?s.jsx("span",{className:"shrink-0",children:t("workbench.testResult.duration",{duration:`${e.durationMs} ms`})}):null,e.message?s.jsx("span",{className:"min-w-0 truncate",title:e.message,children:e.message}):null]})}function V(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function X(){return{_key:V(),id:"",label:""}}function Re(){return{_key:V(),name:"",value:""}}const _={openai:{baseUrl:"https://api.openai.com/v1"},deepseek:{baseUrl:"https://api.deepseek.com/v1"},huawei:{baseUrl:"https://api.modelarts-maas.com/v1"},kimi:{baseUrl:"https://api.moonshot.cn/v1"},anthropic:{baseUrl:"https://api.anthropic.com/v1"},custom:{}},Te=[{value:"openai",label:"OpenAI"},{value:"deepseek",label:"DeepSeek"},{value:"huawei",label:"Huawei Cloud"},{value:"kimi",label:"Kimi"},{value:"anthropic",label:"Anthropic"},{value:"custom",label:"Custom"}],ds=[{id:"basics",labelKey:"providers.drawer.steps.basics"},{id:"models",labelKey:"providers.drawer.steps.modelsVerify"}];function $(e){return e==="anthropic"?"authToken":"apiKey"}function Ee(e,r,t){return t(r==="authToken"?"providers.drawer.fields.authModeAuthToken":r==="xAuthToken"?"providers.drawer.fields.authModeXAuthToken":e==="anthropic"?"providers.drawer.fields.authModeApiKey":"providers.drawer.fields.authModeProviderDefault")}function Y(e){return e?{id:e.id,label:e.label??e.id,baseUrl:e.baseUrl,apiKey:e.apiKey??"",type:e.type??"custom",defaultModel:e.defaultModel??"",models:(e.models??[]).map(r=>({...r,_key:V()})),authMode:e.authMode??$(e.type??"custom"),nonStreamViaStream:e.nonStreamViaStream??!1,useAbsoluteUrl:e.useAbsoluteUrl??!1,streamUsage:e.streamUsage===!0,extraHeaders:Object.entries(e.extraHeaders??{}).map(([r,t])=>({name:r,value:t,_key:V()}))}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:$("custom"),nonStreamViaStream:!1,useAbsoluteUrl:!1,streamUsage:!1,extraHeaders:[]}}function He(e){return{_key:V(),id:e.id,label:e.label,nonStreamViaStream:e.nonStreamViaStream}}function ls({form:e,errors:r,isCreate:t,advancedOpen:i,onAdvancedOpenChange:a,idInputRef:n,onProviderIdChange:h,onFieldChange:u,onTypeChange:y,onAuthModeChange:N,onNonStreamViaStreamChange:g,onUseAbsoluteUrlChange:k,onStreamUsageChange:m,onAddHeader:A,onRemoveHeader:j,onHeaderChange:w}){const{t:o}=O();return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("section",{className:"space-y-5","aria-labelledby":"provider-type-fields",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-type-fields",className:"text-sm font-semibold",children:o("providers.drawer.sections.type")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:o("providers.drawer.hints.type")})]}),s.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:Te.map(b=>{var U;const R=b.value===e.type;return s.jsxs("button",{type:"button",onClick:()=>y(b.value),className:H("rounded-2xl border px-4 py-3 text-left transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",R?"border-primary bg-primary/10 text-primary":"border-border bg-card text-foreground hover:border-primary/20 hover:bg-accent/50"),children:[s.jsx("div",{className:"text-sm font-semibold",children:b.label}),s.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:((U=_[b.value??"custom"])==null?void 0:U.baseUrl)??o("providers.drawer.hints.customProvider")})]},b.value??"custom")})})]}),s.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-basic-info",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-basic-info",className:"text-sm font-semibold",children:o("providers.drawer.sections.basic")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:o("providers.drawer.hints.basic")})]}),s.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:o("providers.drawer.fields.id")}),s.jsx(C,{value:e.id,ref:n,onChange:b=>h(b.target.value),disabled:!t,placeholder:o("providers.drawer.fields.idPlaceholder"),"aria-invalid":!!r.id}),r.id?s.jsx("span",{className:"text-xs text-destructive",children:r.id}):null]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:o("providers.drawer.fields.label")}),s.jsx(C,{value:e.label,onChange:b=>u("label")(b.target.value),placeholder:o("providers.drawer.fields.labelPlaceholder")})]})]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:o("providers.drawer.fields.baseUrl")}),s.jsx(C,{value:e.baseUrl,onChange:b=>u("baseUrl")(b.target.value),placeholder:o("providers.drawer.fields.baseUrlPlaceholder"),"aria-invalid":!!r.baseUrl}),r.baseUrl?s.jsx("span",{className:"text-xs text-destructive",children:r.baseUrl}):null]})]}),s.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-auth-fields",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-auth-fields",className:"text-sm font-semibold",children:o("providers.drawer.sections.auth")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:o("providers.drawer.hints.auth")})]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:o("providers.drawer.fields.apiKey")}),s.jsx(C,{value:e.apiKey,onChange:b=>u("apiKey")(b.target.value),placeholder:o("providers.drawer.fields.apiKeyPlaceholder")})]}),s.jsxs("fieldset",{className:"grid gap-2 rounded-xl border border-transparent bg-card p-4 text-xs shadow-[var(--surface-shadow)]",children:[s.jsx("legend",{className:"px-1 text-muted-foreground",children:o("providers.drawer.fields.authMode")}),s.jsx("p",{className:"text-[11px] text-muted-foreground",children:o("providers.drawer.fields.authModeHint")}),s.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[s.jsx("input",{type:"radio",name:"provider-auth-mode",value:"apiKey",checked:e.authMode==="apiKey",onChange:()=>N("apiKey"),className:"mt-0.5 h-4 w-4 accent-primary"}),s.jsx("span",{children:Ee(e.type,"apiKey",o)})]}),s.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[s.jsx("input",{type:"radio",name:"provider-auth-mode",value:"authToken",checked:e.authMode==="authToken",onChange:()=>N("authToken"),className:"mt-0.5 h-4 w-4 accent-primary"}),s.jsx("span",{children:o("providers.drawer.fields.authModeAuthToken")})]}),s.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[s.jsx("input",{type:"radio",name:"provider-auth-mode",value:"xAuthToken",checked:e.authMode==="xAuthToken",onChange:()=>N("xAuthToken"),className:"mt-0.5 h-4 w-4 accent-primary"}),s.jsx("span",{children:o("providers.drawer.fields.authModeXAuthToken")})]})]}),s.jsxs(W,{open:i,onOpenChange:a,summary:o("providers.drawer.fields.advancedOptions"),className:"rounded-xl border border-transparent bg-card shadow-[var(--surface-shadow)]",summaryClassName:"px-4 py-3 text-sm font-medium",contentClassName:"border-t border-border px-4 py-4",children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium",children:o("providers.drawer.fields.nonStreamViaStream")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:o("providers.drawer.fields.nonStreamViaStreamHint")})]}),s.jsx(F,{checked:e.nonStreamViaStream,onCheckedChange:g,"aria-label":o("providers.drawer.fields.nonStreamViaStream")})]}),s.jsx("div",{className:"mt-4 border-t border-border pt-4",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium",children:o("providers.drawer.fields.useAbsoluteUrl")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:o("providers.drawer.fields.useAbsoluteUrlHint")})]}),s.jsx(F,{checked:e.useAbsoluteUrl,onCheckedChange:k,"aria-label":o("providers.drawer.fields.useAbsoluteUrl")})]})}),s.jsx("div",{className:"mt-4 border-t border-border pt-4",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium",children:o("providers.drawer.fields.streamUsage")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:o("providers.drawer.fields.streamUsageHint")})]}),s.jsx(F,{checked:e.streamUsage,onCheckedChange:m,"aria-label":o("providers.drawer.fields.streamUsage")})]})}),s.jsxs("div",{className:"mt-4 border-t border-border pt-4",children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium",children:o("providers.drawer.fields.extraHeaders")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:o("providers.drawer.fields.extraHeadersHint")})]}),s.jsx(E,{type:"button",variant:"outline",size:"sm",onClick:A,className:"bg-card text-xs",children:o("providers.drawer.fields.addHeader")})]}),r.extraHeaders?s.jsx("p",{className:"mt-2 text-xs text-destructive",children:r.extraHeaders}):null,e.extraHeaders.length>0?s.jsx("div",{className:"mt-3 space-y-3",children:e.extraHeaders.map((b,R)=>s.jsxs("div",{className:"rounded-xl border border-transparent bg-secondary/40 p-3",children:[s.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[s.jsxs(M,{className:"flex flex-col gap-1.5 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:o("providers.drawer.fields.headerName")}),s.jsx(C,{value:b.name,onChange:U=>w(R,{name:U.target.value}),placeholder:o("providers.drawer.fields.headerNamePlaceholder")})]}),s.jsxs(M,{className:"flex flex-col gap-1.5 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:o("providers.drawer.fields.headerValue")}),s.jsx(C,{value:b.value,onChange:U=>w(R,{value:U.target.value}),placeholder:o("providers.drawer.fields.headerValuePlaceholder")})]})]}),s.jsx("div",{className:"mt-2 flex justify-end",children:s.jsx(E,{type:"button",variant:"ghost",size:"sm",className:"h-auto px-2 text-destructive",onClick:()=>j(R),children:o("providers.drawer.fields.removeHeader")})})]},b._key))}):null]})]})]})]})}function ns({form:e,errors:r,advancedOpen:t,onAdvancedOpenChange:i,onModelIdChange:a,onModelChange:n,onAddModel:h,onRemoveModel:u,onModelNonStreamViaStreamChange:y,onSetDefaultModel:N,testVerification:g,probeModels:k}){const{t:m}=O(),A=e.models.filter(j=>j.id.trim().length>0);return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-model-fields",children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-model-fields",className:"text-sm font-semibold",children:m("providers.drawer.fields.models")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:m("providers.drawer.modelsDescription")})]}),s.jsxs("div",{className:"flex shrink-0 gap-2",children:[k?s.jsx(E,{type:"button",variant:"outline",size:"sm",onClick:k.onProbe,disabled:!k.available,title:k.available?void 0:m("providers.drawer.probe.needsBaseUrl"),className:"bg-card text-xs",children:m("providers.drawer.probe.button")}):null,s.jsx(E,{type:"button",variant:"outline",size:"sm",onClick:h,className:"bg-card text-xs",children:m("providers.drawer.fields.addModel")})]})]}),r.models?s.jsx("p",{className:"text-xs text-destructive",children:r.models}):null,s.jsxs("div",{className:"space-y-4",children:[e.models.map((j,w)=>s.jsxs("div",{className:"rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[s.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:m("providers.drawer.fields.modelId")}),s.jsx(C,{value:j.id,onChange:o=>a(w,o.target.value),placeholder:m("providers.drawer.fields.modelIdPlaceholder")})]})}),s.jsxs(W,{open:t,onOpenChange:i,summary:m("providers.drawer.fields.advancedOptions"),className:"mt-4 rounded-xl bg-secondary/50",summaryClassName:"px-3 py-2 text-xs font-medium",contentClassName:"space-y-4 px-3 py-3",children:[s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:m("providers.drawer.fields.modelLabel")}),s.jsx(C,{value:j.label??"",onChange:o=>n(w,{label:o.target.value}),placeholder:m("providers.drawer.fields.modelLabelPlaceholder")})]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:m("providers.drawer.fields.modelNonStreamViaStream")}),s.jsxs(xe,{value:j.nonStreamViaStream===void 0?"inherit":j.nonStreamViaStream?"enabled":"disabled",onValueChange:o=>y(w,o),children:[s.jsx(fe,{children:s.jsx(be,{})}),s.jsxs(ge,{children:[s.jsx(B,{value:"inherit",children:m("providers.drawer.fields.modelNonStreamViaStreamInherit")}),s.jsx(B,{value:"enabled",children:m("providers.drawer.fields.modelNonStreamViaStreamEnabled")}),s.jsx(B,{value:"disabled",children:m("providers.drawer.fields.modelNonStreamViaStreamDisabled")})]})]})]})]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3 text-xs",children:[s.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx("input",{type:"radio",name:"defaultModel",value:j.id,"aria-label":m("providers.drawer.fields.setDefault"),checked:e.defaultModel===j.id,onChange:()=>N(j.id),disabled:j.id.trim().length===0,className:"h-4 w-4 accent-primary"}),m("providers.drawer.fields.setDefault")]}),s.jsx(E,{type:"button",variant:"ghost",size:"sm",className:"h-auto px-2 text-destructive",onClick:()=>u(w),disabled:e.models.length===0,children:m("providers.drawer.fields.removeModel")})]})]},j._key)),e.models.length===0?s.jsx("div",{className:"rounded-xl border border-warning/30 bg-warning-bg p-5",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"text-sm font-semibold text-warning",children:m("providers.drawer.noModelsTitle")}),s.jsx("p",{className:"text-xs leading-relaxed text-warning",children:m("providers.drawer.noModelsHint",{providerId:e.id||"provider-id"})}),s.jsxs("div",{className:"rounded-lg bg-secondary/50 p-2.5",children:[s.jsx("p",{className:"mb-1.5 text-xs font-medium text-foreground",children:m("providers.drawer.routeExample")}),s.jsxs("code",{className:"block rounded-lg border border-transparent bg-card px-2.5 py-1.5 font-mono text-xs text-foreground shadow-[var(--surface-shadow)]",children:['"claude-*": "',(e.id||"provider-id").trim()||"provider-id",':*"']})]})]})}):null]}),A.length>1?s.jsx("div",{className:"text-xs text-muted-foreground",children:m("providers.drawer.defaultHint",{model:e.defaultModel||m("providers.card.noDefault")})}):null]}),g?s.jsxs("section",{className:"space-y-3","aria-labelledby":"provider-verify-fields",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-verify-fields",className:"text-sm font-semibold",children:m("workbench.drawer.verifyTitle")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:m("workbench.drawer.verifyHint")})]}),g.available?s.jsxs("div",{className:"space-y-3 rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[s.jsx(E,{type:"button",variant:"outline",size:"sm",onClick:g.onTest,disabled:g.testing,children:g.testing?m("common.actions.testingConnection"):m("workbench.drawer.verifyRun")}),g.result?s.jsx(Ce,{result:g.result}):null]}):s.jsx("p",{className:"rounded-xl bg-secondary/50 px-4 py-3 text-xs text-muted-foreground",children:m("workbench.drawer.verifySaveFirst")})]}):null]})}const Ae=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;function is({mode:e,provider:r,existingProviderIds:t}){const{t:i}=O(),[a,n]=S.useState(()=>Y(r)),[h,u]=S.useState({}),[y,N]=S.useState(e==="edit"),g=S.useRef(null),k=S.useCallback(()=>{n(Y(r)),u({}),N(e==="edit")},[r,e]),m=l=>d=>{n(x=>({...x,[l]:d}))},A=l=>{n(d=>{const c=!y||d.label.trim().length===0||d.label===d.id?l:d.label;return{...d,id:l,label:c}})},j=l=>{n(d=>{var Q;const c=_[l??"custom"]??_.custom,p=$(d.type),f=$(l),v=Object.values(_).map(D=>D.baseUrl).filter(D=>!!D),L=!d.baseUrl||v.includes(d.baseUrl),ie=e==="create"&&(d.models.length===0||d.models.every(D=>D.id.trim().length===0)),K={...d,type:l,authMode:d.authMode===p?f:d.authMode};return c!=null&&c.baseUrl&&L&&(K.baseUrl=c.baseUrl),c!=null&&c.models&&ie&&(K.models=c.models.map(He),K.defaultModel=c.defaultModel??((Q=c.models[0])==null?void 0:Q.id)??""),K})},w=(l,d)=>{n(x=>{const c=[...x.models];return c[l]={...c[l],...d},{...x,models:c}})},o=(l,d)=>{n(x=>{const c=[...x.models],p=c[l];if(!p)return x;const f=!y||!p.label||p.label===p.id,v={...p,id:d,label:f?d:p.label};c[l]=v;const L=x.defaultModel===p.id?d:x.defaultModel;return{...x,models:c,defaultModel:L}})},b=l=>{n(d=>{if(l<0||l>=d.models.length)return d;const x=d.models.filter((p,f)=>f!==l);let c=d.defaultModel;return x.some(p=>p.id===c)||(c=""),{...d,models:x,defaultModel:c}})},R=()=>{n(l=>({...l,models:[...l.models,X()]}))},U=l=>{n(d=>{const x=new Set(d.models.map(p=>p.id.trim())),c=l.filter(p=>p.id.trim().length>0&&!x.has(p.id.trim())).map(p=>{var f;return{...X(),id:p.id.trim(),label:((f=p.label)==null?void 0:f.trim())??""}});return c.length===0?d:{...d,models:[...d.models,...c]}})},Z=(l,d)=>{n(x=>{const c=[...x.extraHeaders];return c[l]={...c[l],...d},{...x,extraHeaders:c}})},ee=()=>{n(l=>({...l,extraHeaders:[...l.extraHeaders,Re()]}))},se=l=>{n(d=>{if(l<0||l>=d.extraHeaders.length)return d;const x=d.extraHeaders.filter((c,p)=>p!==l);return{...d,extraHeaders:x}})},re=l=>{n(d=>({...d,authMode:l}))},ae=l=>{n(d=>({...d,nonStreamViaStream:l}))},te=l=>{n(d=>({...d,useAbsoluteUrl:l}))},de=l=>{n(d=>({...d,streamUsage:l}))},le=(l,d)=>{w(l,{nonStreamViaStream:d==="inherit"?void 0:d==="enabled"})},ne=l=>{n(d=>({...d,defaultModel:l}))},G=()=>{const l={},d=a.id.trim(),x=a.baseUrl.trim();if(e==="create"&&(d.length===0?l.id=i("providers.drawer.errors.idRequired"):t.includes(d)&&(l.id=i("providers.drawer.errors.idDuplicate"))),e==="edit"&&d.length===0&&(l.id=i("providers.drawer.errors.idRequired")),x.length===0)l.baseUrl=i("providers.drawer.errors.baseUrlInvalid");else try{new URL(x)}catch{l.baseUrl=i("providers.drawer.errors.baseUrlInvalid")}if(a.models.length>0){const c=new Set;a.models.some(f=>{const v=f.id.trim();return v.length===0||c.has(v)?!0:(c.add(v),!1)})&&(l.models=i("providers.drawer.errors.modelInvalid"))}if(a.defaultModel&&!a.models.some(c=>c.id===a.defaultModel)&&(l.models=i("providers.drawer.errors.defaultInvalid")),a.extraHeaders.length>0){const c=new Set;for(const p of a.extraHeaders){const f=p.name.trim();if(f.length===0)continue;if(!Ae.test(f)){l.extraHeaders=i("providers.drawer.errors.headerNameInvalid");break}const v=f.toLowerCase();if(c.has(v)){l.extraHeaders=i("providers.drawer.errors.headerNameDuplicate");break}c.add(v)}}return u(l),l};return{form:a,errors:h,advancedOpen:y,setAdvancedOpen:N,providerIdRef:g,isCreate:e==="create",resetForm:k,validate:()=>Object.keys(G()).length===0,validateErrors:G,serialize:()=>{const l=a.models.map(f=>{var v;return{id:f.id.trim(),label:(v=f.label)!=null&&v.trim()?f.label.trim():void 0,nonStreamViaStream:f.nonStreamViaStream}}).filter(f=>f.id.length>0),d={};for(const f of a.extraHeaders){const v=f.name.trim();v.length>0&&(d[v]=f.value)}const x=Object.keys(d).length>0,c=a.authMode==="apiKey"&&a.type!=="anthropic"?void 0:a.authMode,p={id:a.id.trim(),label:a.label.trim()||a.id.trim(),baseUrl:a.baseUrl.trim(),apiKey:a.apiKey.trim()||void 0,type:a.type??"custom",defaultModel:a.defaultModel||void 0,models:l.length>0?l:void 0,extraHeaders:x?d:void 0,authMode:c};return a.nonStreamViaStream&&(p.nonStreamViaStream=!0),a.useAbsoluteUrl&&(p.useAbsoluteUrl=!0),a.streamUsage&&(p.streamUsage=!0),p},handleFieldChange:m,handleProviderIdChange:A,handleTypeChange:j,handleModelChange:w,handleModelIdChange:o,handleRemoveModel:b,handleAddModel:R,handleImportModels:U,handleHeaderChange:Z,handleAddHeader:ee,handleRemoveHeader:se,handleAuthModeChange:re,handleProviderNonStreamViaStreamChange:ae,handleUseAbsoluteUrlChange:te,handleStreamUsageChange:de,handleModelNonStreamViaStreamChange:le,handleSetDefaultModel:ne}}export{ls as B,Ge as C,ns as M,Qe as O,Te as P,ts as S,Ce as T,Ye as a,Xe as b,q as c,Je as d,Ze as e,ye as f,je as g,es as h,Ee as i,ds as j,Me as k,We as l,as as m,rs as n,ss as o,Se as r,is as u};
|
|
1
|
+
import{r as S,j as s,$ as oe}from"./vendor-CITafuNQ.js";import{u as ce}from"./query-DZF7K6hv.js";import{a as ue,c as me,q as J,e as pe,i as P,d as I,B as E}from"./app-CDdTBXQ0.js";import{g as he}from"./gateway-CbmElcXM.js";import{u as O}from"./i18n-PeX9kBVO.js";import{c as H}from"./global-D5dyWHqO.js";import{D as W}from"./disclosure-Dpus5Sms.js";import{L as M,I as C}from"./label-Dg8bOG83.js";import{S as xe,a as fe,b as be,c as ge,d as B}from"./select-BMTHg2Ox.js";import{S as F}from"./switch-BjJJ5nhB.js";import{B as ve}from"./badge-DMgopDMC.js";const Ge=["claude-sonnet-4-5-20250929","claude-sonnet-4-5-20250929-thinking","claude-sonnet-4-20250514","claude-opus-4-1-20250805","claude-opus-4-1-20250805-thinking","claude-haiku-4-5-20251001","claude-haiku-4-5-20251001-thinking","claude-3-5-haiku-20241022"],Qe=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function ye(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function T(e,r){var t;return(t=e==null?void 0:e.customEndpoints)!=null&&t.length?e.customEndpoints:r}function z(e){return e?Object.entries(e).map(([r,t])=>({id:ye(),source:r,target:t})):[]}function Je(e,r){var a,n,h;if(!e)return{};const t={},i=e.endpointRouting??{};t.anthropic=z(((a=i.anthropic)==null?void 0:a.modelRoutes)??e.modelRoutes??{}),t.openai=z(((n=i.openai)==null?void 0:n.modelRoutes)??{});for(const u of T(e,r))(h=u.routing)!=null&&h.modelRoutes?t[u.id]=z(u.routing.modelRoutes):t[u.id]=[];return t}function je(e,r,t){var n,h,u;const i=T(e,r).find(y=>y.id===t);if(i)return((n=i.routing)==null?void 0:n.modelRoutes)??{};const a=e.endpointRouting??{};return t==="anthropic"?((h=a.anthropic)==null?void 0:h.modelRoutes)??e.modelRoutes??{}:t==="openai"?((u=a.openai)==null?void 0:u.modelRoutes)??{}:{}}function q(e,r,t){var a,n,h;if(t==="anthropic"||t==="openai")return((n=(a=e.endpointRouting)==null?void 0:a[t])==null?void 0:n.defaults)??e.defaults;const i=T(e,r).find(u=>u.id===t);return((h=i==null?void 0:i.routing)==null?void 0:h.defaults)??{completion:null,reasoning:null,background:null,longContextThreshold:e.defaults.longContextThreshold}}function Xe(e,r){if(!e)return{};const t={anthropic:q(e,r,"anthropic"),openai:q(e,r,"openai")};for(const i of T(e,r))t[i.id]=q(e,r,i.id);return t}function Ne(e){const r={};for(const t of e){const i=t.source.trim(),a=t.target.trim();i&&a&&(r[i]=a)}return r}function Ye(e,r){return JSON.stringify(Ne(e))!==JSON.stringify(r)}function We(e,r,t){var a,n,h;if(!r)return;if(e==="anthropic"||e==="openai")return(n=(a=r.endpointRouting)==null?void 0:a[e])==null?void 0:n.compatibility;const i=T(r,t).find(u=>u.id===e);return(h=i==null?void 0:i.routing)==null?void 0:h.compatibility}function Ze(e,r){var i,a;const t={anthropic:((i=e.routingPresets)==null?void 0:i.anthropic)??[],openai:((a=e.routingPresets)==null?void 0:a.openai)??[]};for(const n of T(e,r))t[n.id]=n.routingPresets??[];return t}function we(e,r){const t=[{key:"providers",label:e("modelManagement.tabs.providers"),description:e("modelManagement.tabs.providersDesc"),isSystem:!0,canDelete:!1},{key:"anthropic",label:e("modelManagement.tabs.anthropic"),description:e("modelManagement.tabs.anthropicDesc"),isSystem:!0,canDelete:!1,protocols:["anthropic"]},{key:"openai",label:e("modelManagement.tabs.openai"),description:e("modelManagement.tabs.openaiDesc"),isSystem:!0,canDelete:!1,protocols:["openai-auto","openai-chat","openai-responses"]}],i=r.map(a=>{let n=e("modelManagement.tabs.customEndpoint"),h=[];if(a.paths&&a.paths.length>0)n=`${e("modelManagement.tabs.customEndpoint")}: ${a.paths.map(u=>`${u.path} (${u.protocol})`).join(", ")}`,h=[...new Set(a.paths.map(u=>u.protocol))];else if(a.path){const u=a.protocol||"anthropic";n=`${e("modelManagement.tabs.customEndpoint")}: ${a.path} (${u})`,h=[u]}return{key:a.id,label:a.label||a.id,description:n,isSystem:!1,canDelete:a.deletable!==!1,protocols:h}});return[...t,...i]}function es(e){return e.label&&e.label.trim().length>0?`${e.label} (${e.id})`:e.id}function Se(e,r){if(!e)return!1;const[t]=e.split(":");return t===r||e===r}function Me(e,r,t){if(!e)return[];const i=["anthropic","openai",...T(e,r).map(n=>n.id)],a=[];for(const n of i){const h=je(e,r,n);for(const[u,y]of Object.entries(h))Se(y,t)&&a.push({endpoint:n,source:u,target:y})}return a}function ss(e,r,t){return Me(e,r,t).length}function rs(){var N;const{t:e}=O(),{pushToast:r}=ue(),t=me(J.config.full(),he.configRequest()),i=ce({queryKey:J.customEndpoints.all(),queryFn:pe.list,refetchInterval:1e4}),a=S.useMemo(()=>{var g;return((g=i.data)==null?void 0:g.endpoints)??[]},[(N=i.data)==null?void 0:N.endpoints]),n=S.useMemo(()=>we(e,a),[a,e]),[h,u]=S.useState(null);return S.useEffect(()=>{t.data&&u(t.data)},[t.data]),S.useEffect(()=>{!t.isError||!t.error||r({title:e("providers.toast.loadFailure",{message:t.error.message}),variant:"error"})},[t.error,t.isError,r,e]),{t:e,pushToast:r,config:h,setConfig:u,configQuery:t,customEndpoints:a,customEndpointsQuery:i,tabs:n,ensureConfig:()=>h?!0:(r({title:e("settings.toast.missingConfig"),variant:"error"}),t.refetch(),!1)}}const as={savePreset(e,r){return P(I.post(`/api/routing-presets/${e}`,{name:r}))},applyPreset(e,r){return P(I.post(`/api/routing-presets/${e}/apply`,{name:r}))},deletePreset(e,r){return P(I.delete(`/api/routing-presets/${e}/${encodeURIComponent(r)}`))},testProvider(e,r){return P(I.post(`/api/providers/${e}/test`,r??{}))},probeModels(e,r){return P(I.post(`/api/providers/${e}/models/probe`,r?{provider:r}:{}))}},ke={complete:"border-primary bg-primary text-primary-foreground",current:"border-primary bg-card text-primary ring-2 ring-primary/20",error:"border-destructive bg-card text-destructive ring-2 ring-destructive/20",upcoming:"border-border bg-card text-muted-foreground"},Ue={complete:"text-foreground",current:"text-foreground font-medium",error:"text-destructive font-medium",upcoming:"text-muted-foreground"};function ts({steps:e,current:r,onSelect:t,className:i}){return s.jsx("nav",{"aria-label":"steps",className:H("flex items-start",i),children:e.map((a,n)=>{const h=t&&(a.status==="complete"||a.status==="current"),u=n===e.length-1,y=a.status==="complete"?"bg-primary/40":"bg-border",N=s.jsx("span",{className:H("motion-surface flex h-7 w-7 shrink-0 items-center justify-center rounded-lg border text-xs font-semibold",ke[a.status]),"aria-current":a.id===r?"step":void 0,children:a.status==="complete"?s.jsx(oe,{className:"h-3.5 w-3.5","aria-hidden":!0}):n+1}),g=`stepnav-${a.id}-label`;return s.jsxs("div",{className:"flex flex-1 items-start",children:[s.jsxs("div",{className:"flex min-w-0 flex-col items-center gap-1.5",children:[h?s.jsx("button",{type:"button",onClick:()=>t==null?void 0:t(a.id),"aria-labelledby":g,className:"rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-background motion-surface",children:N}):N,s.jsx("span",{id:g,className:H("text-center text-[11px] leading-tight",Ue[a.status]),children:a.label})]}),u?null:s.jsx("span",{"aria-hidden":!0,className:H("mx-1.5 mt-3.5 h-px flex-1",y)})]},a.id)})})}function Ce({result:e,className:r}){const{t}=O();return s.jsxs("div",{className:H("flex flex-wrap items-center gap-2 rounded-lg px-3 py-2 text-xs",e.ok?"bg-success-bg text-success":"bg-destructive/10 text-destructive",r),children:[s.jsx(ve,{variant:e.ok?"success":"destructive",className:"shrink-0",children:e.ok?t("workbench.testResult.success"):t("workbench.testResult.failure")}),e.status?s.jsx("span",{className:"shrink-0",children:t("workbench.testResult.status",{status:e.status})}):null,e.durationMs?s.jsx("span",{className:"shrink-0",children:t("workbench.testResult.duration",{duration:`${e.durationMs} ms`})}):null,e.message?s.jsx("span",{className:"min-w-0 truncate",title:e.message,children:e.message}):null]})}function V(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function X(){return{_key:V(),id:"",label:""}}function Re(){return{_key:V(),name:"",value:""}}const _={openai:{baseUrl:"https://api.openai.com/v1"},deepseek:{baseUrl:"https://api.deepseek.com/v1"},huawei:{baseUrl:"https://api.modelarts-maas.com/v1"},kimi:{baseUrl:"https://api.moonshot.cn/v1"},anthropic:{baseUrl:"https://api.anthropic.com/v1"},custom:{}},Te=[{value:"openai",label:"OpenAI"},{value:"deepseek",label:"DeepSeek"},{value:"huawei",label:"Huawei Cloud"},{value:"kimi",label:"Kimi"},{value:"anthropic",label:"Anthropic"},{value:"custom",label:"Custom"}],ds=[{id:"basics",labelKey:"providers.drawer.steps.basics"},{id:"models",labelKey:"providers.drawer.steps.modelsVerify"}];function $(e){return e==="anthropic"?"authToken":"apiKey"}function Ee(e,r,t){return t(r==="authToken"?"providers.drawer.fields.authModeAuthToken":r==="xAuthToken"?"providers.drawer.fields.authModeXAuthToken":e==="anthropic"?"providers.drawer.fields.authModeApiKey":"providers.drawer.fields.authModeProviderDefault")}function Y(e){return e?{id:e.id,label:e.label??e.id,baseUrl:e.baseUrl,apiKey:e.apiKey??"",type:e.type??"custom",defaultModel:e.defaultModel??"",models:(e.models??[]).map(r=>({...r,_key:V()})),authMode:e.authMode??$(e.type??"custom"),nonStreamViaStream:e.nonStreamViaStream??!1,useAbsoluteUrl:e.useAbsoluteUrl??!1,streamUsage:e.streamUsage===!0,extraHeaders:Object.entries(e.extraHeaders??{}).map(([r,t])=>({name:r,value:t,_key:V()}))}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:$("custom"),nonStreamViaStream:!1,useAbsoluteUrl:!1,streamUsage:!1,extraHeaders:[]}}function He(e){return{_key:V(),id:e.id,label:e.label,nonStreamViaStream:e.nonStreamViaStream}}function ls({form:e,errors:r,isCreate:t,advancedOpen:i,onAdvancedOpenChange:a,idInputRef:n,onProviderIdChange:h,onFieldChange:u,onTypeChange:y,onAuthModeChange:N,onNonStreamViaStreamChange:g,onUseAbsoluteUrlChange:k,onStreamUsageChange:m,onAddHeader:A,onRemoveHeader:j,onHeaderChange:w}){const{t:o}=O();return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("section",{className:"space-y-5","aria-labelledby":"provider-type-fields",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-type-fields",className:"text-sm font-semibold",children:o("providers.drawer.sections.type")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:o("providers.drawer.hints.type")})]}),s.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:Te.map(b=>{var U;const R=b.value===e.type;return s.jsxs("button",{type:"button",onClick:()=>y(b.value),className:H("rounded-2xl border px-4 py-3 text-left transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",R?"border-primary bg-primary/10 text-primary":"border-border bg-card text-foreground hover:border-primary/20 hover:bg-accent/50"),children:[s.jsx("div",{className:"text-sm font-semibold",children:b.label}),s.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:((U=_[b.value??"custom"])==null?void 0:U.baseUrl)??o("providers.drawer.hints.customProvider")})]},b.value??"custom")})})]}),s.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-basic-info",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-basic-info",className:"text-sm font-semibold",children:o("providers.drawer.sections.basic")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:o("providers.drawer.hints.basic")})]}),s.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:o("providers.drawer.fields.id")}),s.jsx(C,{value:e.id,ref:n,onChange:b=>h(b.target.value),disabled:!t,placeholder:o("providers.drawer.fields.idPlaceholder"),"aria-invalid":!!r.id}),r.id?s.jsx("span",{className:"text-xs text-destructive",children:r.id}):null]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:o("providers.drawer.fields.label")}),s.jsx(C,{value:e.label,onChange:b=>u("label")(b.target.value),placeholder:o("providers.drawer.fields.labelPlaceholder")})]})]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:o("providers.drawer.fields.baseUrl")}),s.jsx(C,{value:e.baseUrl,onChange:b=>u("baseUrl")(b.target.value),placeholder:o("providers.drawer.fields.baseUrlPlaceholder"),"aria-invalid":!!r.baseUrl}),r.baseUrl?s.jsx("span",{className:"text-xs text-destructive",children:r.baseUrl}):null]})]}),s.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-auth-fields",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-auth-fields",className:"text-sm font-semibold",children:o("providers.drawer.sections.auth")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:o("providers.drawer.hints.auth")})]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:o("providers.drawer.fields.apiKey")}),s.jsx(C,{value:e.apiKey,onChange:b=>u("apiKey")(b.target.value),placeholder:o("providers.drawer.fields.apiKeyPlaceholder")})]}),s.jsxs("fieldset",{className:"grid gap-2 rounded-xl border border-transparent bg-card p-4 text-xs shadow-[var(--surface-shadow)]",children:[s.jsx("legend",{className:"px-1 text-muted-foreground",children:o("providers.drawer.fields.authMode")}),s.jsx("p",{className:"text-[11px] text-muted-foreground",children:o("providers.drawer.fields.authModeHint")}),s.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[s.jsx("input",{type:"radio",name:"provider-auth-mode",value:"apiKey",checked:e.authMode==="apiKey",onChange:()=>N("apiKey"),className:"mt-0.5 h-4 w-4 accent-primary"}),s.jsx("span",{children:Ee(e.type,"apiKey",o)})]}),s.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[s.jsx("input",{type:"radio",name:"provider-auth-mode",value:"authToken",checked:e.authMode==="authToken",onChange:()=>N("authToken"),className:"mt-0.5 h-4 w-4 accent-primary"}),s.jsx("span",{children:o("providers.drawer.fields.authModeAuthToken")})]}),s.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[s.jsx("input",{type:"radio",name:"provider-auth-mode",value:"xAuthToken",checked:e.authMode==="xAuthToken",onChange:()=>N("xAuthToken"),className:"mt-0.5 h-4 w-4 accent-primary"}),s.jsx("span",{children:o("providers.drawer.fields.authModeXAuthToken")})]})]}),s.jsxs(W,{open:i,onOpenChange:a,summary:o("providers.drawer.fields.advancedOptions"),className:"rounded-xl border border-transparent bg-card shadow-[var(--surface-shadow)]",summaryClassName:"px-4 py-3 text-sm font-medium",contentClassName:"border-t border-border px-4 py-4",children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium",children:o("providers.drawer.fields.nonStreamViaStream")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:o("providers.drawer.fields.nonStreamViaStreamHint")})]}),s.jsx(F,{checked:e.nonStreamViaStream,onCheckedChange:g,"aria-label":o("providers.drawer.fields.nonStreamViaStream")})]}),s.jsx("div",{className:"mt-4 border-t border-border pt-4",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium",children:o("providers.drawer.fields.useAbsoluteUrl")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:o("providers.drawer.fields.useAbsoluteUrlHint")})]}),s.jsx(F,{checked:e.useAbsoluteUrl,onCheckedChange:k,"aria-label":o("providers.drawer.fields.useAbsoluteUrl")})]})}),s.jsx("div",{className:"mt-4 border-t border-border pt-4",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium",children:o("providers.drawer.fields.streamUsage")}),s.jsx("p",{className:"text-xs leading-relaxed text-warning",children:o("providers.drawer.fields.streamUsageHint")})]}),s.jsx(F,{checked:e.streamUsage,onCheckedChange:m,"aria-label":o("providers.drawer.fields.streamUsage")})]})}),s.jsxs("div",{className:"mt-4 border-t border-border pt-4",children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium",children:o("providers.drawer.fields.extraHeaders")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:o("providers.drawer.fields.extraHeadersHint")})]}),s.jsx(E,{type:"button",variant:"outline",size:"sm",onClick:A,className:"bg-card text-xs",children:o("providers.drawer.fields.addHeader")})]}),r.extraHeaders?s.jsx("p",{className:"mt-2 text-xs text-destructive",children:r.extraHeaders}):null,e.extraHeaders.length>0?s.jsx("div",{className:"mt-3 space-y-3",children:e.extraHeaders.map((b,R)=>s.jsxs("div",{className:"rounded-xl border border-transparent bg-secondary/40 p-3",children:[s.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[s.jsxs(M,{className:"flex flex-col gap-1.5 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:o("providers.drawer.fields.headerName")}),s.jsx(C,{value:b.name,onChange:U=>w(R,{name:U.target.value}),placeholder:o("providers.drawer.fields.headerNamePlaceholder")})]}),s.jsxs(M,{className:"flex flex-col gap-1.5 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:o("providers.drawer.fields.headerValue")}),s.jsx(C,{value:b.value,onChange:U=>w(R,{value:U.target.value}),placeholder:o("providers.drawer.fields.headerValuePlaceholder")})]})]}),s.jsx("div",{className:"mt-2 flex justify-end",children:s.jsx(E,{type:"button",variant:"ghost",size:"sm",className:"h-auto px-2 text-destructive",onClick:()=>j(R),children:o("providers.drawer.fields.removeHeader")})})]},b._key))}):null]})]})]})]})}function ns({form:e,errors:r,advancedOpen:t,onAdvancedOpenChange:i,onModelIdChange:a,onModelChange:n,onAddModel:h,onRemoveModel:u,onModelNonStreamViaStreamChange:y,onSetDefaultModel:N,testVerification:g,probeModels:k}){const{t:m}=O(),A=e.models.filter(j=>j.id.trim().length>0);return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-model-fields",children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-model-fields",className:"text-sm font-semibold",children:m("providers.drawer.fields.models")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:m("providers.drawer.modelsDescription")})]}),s.jsxs("div",{className:"flex shrink-0 gap-2",children:[k?s.jsx(E,{type:"button",variant:"outline",size:"sm",onClick:k.onProbe,disabled:!k.available,title:k.available?void 0:m("providers.drawer.probe.needsBaseUrl"),className:"bg-card text-xs",children:m("providers.drawer.probe.button")}):null,s.jsx(E,{type:"button",variant:"outline",size:"sm",onClick:h,className:"bg-card text-xs",children:m("providers.drawer.fields.addModel")})]})]}),r.models?s.jsx("p",{className:"text-xs text-destructive",children:r.models}):null,s.jsxs("div",{className:"space-y-4",children:[e.models.map((j,w)=>s.jsxs("div",{className:"rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[s.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:m("providers.drawer.fields.modelId")}),s.jsx(C,{value:j.id,onChange:o=>a(w,o.target.value),placeholder:m("providers.drawer.fields.modelIdPlaceholder")})]})}),s.jsxs(W,{open:t,onOpenChange:i,summary:m("providers.drawer.fields.advancedOptions"),className:"mt-4 rounded-xl bg-secondary/50",summaryClassName:"px-3 py-2 text-xs font-medium",contentClassName:"space-y-4 px-3 py-3",children:[s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:m("providers.drawer.fields.modelLabel")}),s.jsx(C,{value:j.label??"",onChange:o=>n(w,{label:o.target.value}),placeholder:m("providers.drawer.fields.modelLabelPlaceholder")})]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:m("providers.drawer.fields.modelNonStreamViaStream")}),s.jsxs(xe,{value:j.nonStreamViaStream===void 0?"inherit":j.nonStreamViaStream?"enabled":"disabled",onValueChange:o=>y(w,o),children:[s.jsx(fe,{children:s.jsx(be,{})}),s.jsxs(ge,{children:[s.jsx(B,{value:"inherit",children:m("providers.drawer.fields.modelNonStreamViaStreamInherit")}),s.jsx(B,{value:"enabled",children:m("providers.drawer.fields.modelNonStreamViaStreamEnabled")}),s.jsx(B,{value:"disabled",children:m("providers.drawer.fields.modelNonStreamViaStreamDisabled")})]})]})]})]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3 text-xs",children:[s.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx("input",{type:"radio",name:"defaultModel",value:j.id,"aria-label":m("providers.drawer.fields.setDefault"),checked:e.defaultModel===j.id,onChange:()=>N(j.id),disabled:j.id.trim().length===0,className:"h-4 w-4 accent-primary"}),m("providers.drawer.fields.setDefault")]}),s.jsx(E,{type:"button",variant:"ghost",size:"sm",className:"h-auto px-2 text-destructive",onClick:()=>u(w),disabled:e.models.length===0,children:m("providers.drawer.fields.removeModel")})]})]},j._key)),e.models.length===0?s.jsx("div",{className:"rounded-xl border border-warning/30 bg-warning-bg p-5",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"text-sm font-semibold text-warning",children:m("providers.drawer.noModelsTitle")}),s.jsx("p",{className:"text-xs leading-relaxed text-warning",children:m("providers.drawer.noModelsHint",{providerId:e.id||"provider-id"})}),s.jsxs("div",{className:"rounded-lg bg-secondary/50 p-2.5",children:[s.jsx("p",{className:"mb-1.5 text-xs font-medium text-foreground",children:m("providers.drawer.routeExample")}),s.jsxs("code",{className:"block rounded-lg border border-transparent bg-card px-2.5 py-1.5 font-mono text-xs text-foreground shadow-[var(--surface-shadow)]",children:['"claude-*": "',(e.id||"provider-id").trim()||"provider-id",':*"']})]})]})}):null]}),A.length>1?s.jsx("div",{className:"text-xs text-muted-foreground",children:m("providers.drawer.defaultHint",{model:e.defaultModel||m("providers.card.noDefault")})}):null]}),g?s.jsxs("section",{className:"space-y-3","aria-labelledby":"provider-verify-fields",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h3",{id:"provider-verify-fields",className:"text-sm font-semibold",children:m("workbench.drawer.verifyTitle")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:m("workbench.drawer.verifyHint")})]}),g.available?s.jsxs("div",{className:"space-y-3 rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[s.jsx(E,{type:"button",variant:"outline",size:"sm",onClick:g.onTest,disabled:g.testing,children:g.testing?m("common.actions.testingConnection"):m("workbench.drawer.verifyRun")}),g.result?s.jsx(Ce,{result:g.result}):null]}):s.jsx("p",{className:"rounded-xl bg-secondary/50 px-4 py-3 text-xs text-muted-foreground",children:m("workbench.drawer.verifySaveFirst")})]}):null]})}const Ae=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;function is({mode:e,provider:r,existingProviderIds:t}){const{t:i}=O(),[a,n]=S.useState(()=>Y(r)),[h,u]=S.useState({}),[y,N]=S.useState(e==="edit"),g=S.useRef(null),k=S.useCallback(()=>{n(Y(r)),u({}),N(e==="edit")},[r,e]),m=l=>d=>{n(x=>({...x,[l]:d}))},A=l=>{n(d=>{const c=!y||d.label.trim().length===0||d.label===d.id?l:d.label;return{...d,id:l,label:c}})},j=l=>{n(d=>{var Q;const c=_[l??"custom"]??_.custom,p=$(d.type),f=$(l),v=Object.values(_).map(D=>D.baseUrl).filter(D=>!!D),L=!d.baseUrl||v.includes(d.baseUrl),ie=e==="create"&&(d.models.length===0||d.models.every(D=>D.id.trim().length===0)),K={...d,type:l,authMode:d.authMode===p?f:d.authMode};return c!=null&&c.baseUrl&&L&&(K.baseUrl=c.baseUrl),c!=null&&c.models&&ie&&(K.models=c.models.map(He),K.defaultModel=c.defaultModel??((Q=c.models[0])==null?void 0:Q.id)??""),K})},w=(l,d)=>{n(x=>{const c=[...x.models];return c[l]={...c[l],...d},{...x,models:c}})},o=(l,d)=>{n(x=>{const c=[...x.models],p=c[l];if(!p)return x;const f=!y||!p.label||p.label===p.id,v={...p,id:d,label:f?d:p.label};c[l]=v;const L=x.defaultModel===p.id?d:x.defaultModel;return{...x,models:c,defaultModel:L}})},b=l=>{n(d=>{if(l<0||l>=d.models.length)return d;const x=d.models.filter((p,f)=>f!==l);let c=d.defaultModel;return x.some(p=>p.id===c)||(c=""),{...d,models:x,defaultModel:c}})},R=()=>{n(l=>({...l,models:[...l.models,X()]}))},U=l=>{n(d=>{const x=new Set(d.models.map(p=>p.id.trim())),c=l.filter(p=>p.id.trim().length>0&&!x.has(p.id.trim())).map(p=>{var f;return{...X(),id:p.id.trim(),label:((f=p.label)==null?void 0:f.trim())??""}});return c.length===0?d:{...d,models:[...d.models,...c]}})},Z=(l,d)=>{n(x=>{const c=[...x.extraHeaders];return c[l]={...c[l],...d},{...x,extraHeaders:c}})},ee=()=>{n(l=>({...l,extraHeaders:[...l.extraHeaders,Re()]}))},se=l=>{n(d=>{if(l<0||l>=d.extraHeaders.length)return d;const x=d.extraHeaders.filter((c,p)=>p!==l);return{...d,extraHeaders:x}})},re=l=>{n(d=>({...d,authMode:l}))},ae=l=>{n(d=>({...d,nonStreamViaStream:l}))},te=l=>{n(d=>({...d,useAbsoluteUrl:l}))},de=l=>{n(d=>({...d,streamUsage:l}))},le=(l,d)=>{w(l,{nonStreamViaStream:d==="inherit"?void 0:d==="enabled"})},ne=l=>{n(d=>({...d,defaultModel:l}))},G=()=>{const l={},d=a.id.trim(),x=a.baseUrl.trim();if(e==="create"&&(d.length===0?l.id=i("providers.drawer.errors.idRequired"):t.includes(d)&&(l.id=i("providers.drawer.errors.idDuplicate"))),e==="edit"&&d.length===0&&(l.id=i("providers.drawer.errors.idRequired")),x.length===0)l.baseUrl=i("providers.drawer.errors.baseUrlInvalid");else try{new URL(x)}catch{l.baseUrl=i("providers.drawer.errors.baseUrlInvalid")}if(a.models.length>0){const c=new Set;a.models.some(f=>{const v=f.id.trim();return v.length===0||c.has(v)?!0:(c.add(v),!1)})&&(l.models=i("providers.drawer.errors.modelInvalid"))}if(a.defaultModel&&!a.models.some(c=>c.id===a.defaultModel)&&(l.models=i("providers.drawer.errors.defaultInvalid")),a.extraHeaders.length>0){const c=new Set;for(const p of a.extraHeaders){const f=p.name.trim();if(f.length===0)continue;if(!Ae.test(f)){l.extraHeaders=i("providers.drawer.errors.headerNameInvalid");break}const v=f.toLowerCase();if(c.has(v)){l.extraHeaders=i("providers.drawer.errors.headerNameDuplicate");break}c.add(v)}}return u(l),l};return{form:a,errors:h,advancedOpen:y,setAdvancedOpen:N,providerIdRef:g,isCreate:e==="create",resetForm:k,validate:()=>Object.keys(G()).length===0,validateErrors:G,serialize:()=>{const l=a.models.map(f=>{var v;return{id:f.id.trim(),label:(v=f.label)!=null&&v.trim()?f.label.trim():void 0,nonStreamViaStream:f.nonStreamViaStream}}).filter(f=>f.id.length>0),d={};for(const f of a.extraHeaders){const v=f.name.trim();v.length>0&&(d[v]=f.value)}const x=Object.keys(d).length>0,c=a.authMode==="apiKey"&&a.type!=="anthropic"?void 0:a.authMode,p={id:a.id.trim(),label:a.label.trim()||a.id.trim(),baseUrl:a.baseUrl.trim(),apiKey:a.apiKey.trim()||void 0,type:a.type??"custom",defaultModel:a.defaultModel||void 0,models:l.length>0?l:void 0,extraHeaders:x?d:void 0,authMode:c};return a.nonStreamViaStream&&(p.nonStreamViaStream=!0),a.useAbsoluteUrl&&(p.useAbsoluteUrl=!0),a.streamUsage&&(p.streamUsage=!0),p},handleFieldChange:m,handleProviderIdChange:A,handleTypeChange:j,handleModelChange:w,handleModelIdChange:o,handleRemoveModel:b,handleAddModel:R,handleImportModels:U,handleHeaderChange:Z,handleAddHeader:ee,handleRemoveHeader:se,handleAuthModeChange:re,handleProviderNonStreamViaStreamChange:ae,handleUseAbsoluteUrlChange:te,handleStreamUsageChange:de,handleModelNonStreamViaStreamChange:le,handleSetDefaultModel:ne}}export{ls as B,Ge as C,ns as M,Qe as O,Te as P,ts as S,Ce as T,Ye as a,Xe as b,q as c,Je as d,Ze as e,ye as f,je as g,es as h,Ee as i,ds as j,Me as k,We as l,as as m,rs as n,ss as o,Se as r,is as u};
|
package/src/web/dist/index.html
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
rel="stylesheet"
|
|
15
15
|
/>
|
|
16
16
|
<title>cc-gw 控制台</title>
|
|
17
|
-
<script type="module" crossorigin src="/assets/app-
|
|
17
|
+
<script type="module" crossorigin src="/assets/app-CDdTBXQ0.js"></script>
|
|
18
18
|
<link rel="modulepreload" crossorigin href="/assets/vendor-CITafuNQ.js">
|
|
19
19
|
<link rel="modulepreload" crossorigin href="/assets/global-D5dyWHqO.js">
|
|
20
20
|
<link rel="modulepreload" crossorigin href="/assets/query-DZF7K6hv.js">
|
|
@@ -42,11 +42,11 @@
|
|
|
42
42
|
}
|
|
43
43
|
</script>
|
|
44
44
|
<title>cc-gw | 你的 API Key 不该躺在 30 个 .env 里 · local-first AI gateway</title>
|
|
45
|
-
<script type="module" crossorigin src="/assets/landing-
|
|
45
|
+
<script type="module" crossorigin src="/assets/landing-Cra6nfAd.js"></script>
|
|
46
46
|
<link rel="modulepreload" crossorigin href="/assets/vendor-CITafuNQ.js">
|
|
47
47
|
<link rel="modulepreload" crossorigin href="/assets/global-D5dyWHqO.js">
|
|
48
48
|
<link rel="modulepreload" crossorigin href="/assets/clipboard-BnAnBk_-.js">
|
|
49
|
-
<link rel="modulepreload" crossorigin href="/assets/package-
|
|
49
|
+
<link rel="modulepreload" crossorigin href="/assets/package-B8-r92OZ.js">
|
|
50
50
|
<link rel="stylesheet" crossorigin href="/assets/global-CjRN4Kqi.css">
|
|
51
51
|
</head>
|
|
52
52
|
<body class="bg-slate-50 text-slate-900">
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const o="0.10.2",s={version:o};export{s as p};
|