@chenpu17/cc-gw 0.9.0-beta.0 → 0.9.0-beta.1
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-DY21fypB.js → About-WPCkWxkz.js} +1 -1
- package/src/web/dist/assets/{ApiKeys-FWkRLPTy.js → ApiKeys-Q-EteBox.js} +1 -1
- package/src/web/dist/assets/{ConfirmDialog-CyTpXZeT.js → ConfirmDialog-CvC_VLb2.js} +1 -1
- package/src/web/dist/assets/{Dashboard-FKM-9UNt.js → Dashboard-Q99L2W8N.js} +1 -1
- package/src/web/dist/assets/{Events-x_fSf1mz.js → Events-CBVp1fVz.js} +1 -1
- package/src/web/dist/assets/{Help-BMgllYJq.js → Help-M3pIEoJN.js} +1 -1
- package/src/web/dist/assets/{Login-DrtDFqbk.js → Login-DtAkFJMT.js} +1 -1
- package/src/web/dist/assets/{Logs-18flgbiW.js → Logs-CIPbrHMJ.js} +1 -1
- package/src/web/dist/assets/{ProvidersWorkbench-aHO5-ApY.js → ProvidersWorkbench-DvlPlloy.js} +1 -1
- package/src/web/dist/assets/{Settings-iEjCAGgm.js → Settings-CNI4qHrl.js} +1 -1
- package/src/web/dist/assets/{Setup-B1j2zExa.js → Setup-CfD6U8Nf.js} +1 -1
- package/src/web/dist/assets/{apiKeys-k1jIJuDa.js → apiKeys-CoQ69TK_.js} +1 -1
- package/src/web/dist/assets/{app-Citq5KW4.js → app-czRBzLXv.js} +2 -2
- package/src/web/dist/assets/{gateway-i49olSPp.js → gateway-Dxoj2rj4.js} +1 -1
- package/src/web/dist/assets/{landing-W4f2Nx8j.js → landing-DBrU8FIr.js} +1 -1
- package/src/web/dist/assets/package-BXeeAB6b.js +1 -0
- package/src/web/dist/assets/{shared-Cuakym23.js → shared-HT9X1BTy.js} +1 -1
- package/src/web/dist/assets/{useAppMutation-CEN5Oa4S.js → useAppMutation-DbIs5qvT.js} +1 -1
- package/src/web/dist/assets/{useProviderForm-DZEYuRhD.js → useProviderForm-BiVzWP3H.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-B2CgmdJ7.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as w,j as s,$ as le}from"./vendor-CITafuNQ.js";import{u as ne}from"./query-DZF7K6hv.js";import{a as oe,c as ie,q as G,e as ce,i as V,d as O,B as A}from"./app-Citq5KW4.js";import{g as ue}from"./gateway-i49olSPp.js";import{u as P}from"./i18n-PeX9kBVO.js";import{c as T}from"./global-BCehxTGJ.js";import{D as X}from"./disclosure-l5qsWhr7.js";import{L as M,I as C}from"./label-DSVzZIex.js";import{S as me,a as pe,b as he,c as xe,d as L}from"./select-sOwKYsgI.js";import{S as Q}from"./switch-7PH_rDz6.js";import{B as fe}from"./badge-DpUlf_NW.js";const ze=["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 be(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function R(e,a){var t;return(t=e==null?void 0:e.customEndpoints)!=null&&t.length?e.customEndpoints:a}function B(e){return e?Object.entries(e).map(([a,t])=>({id:be(),source:a,target:t})):[]}function Ge(e,a){var r,n,p;if(!e)return{};const t={},o=e.endpointRouting??{};t.anthropic=B(((r=o.anthropic)==null?void 0:r.modelRoutes)??e.modelRoutes??{}),t.openai=B(((n=o.openai)==null?void 0:n.modelRoutes)??{});for(const u of R(e,a))(p=u.routing)!=null&&p.modelRoutes?t[u.id]=B(u.routing.modelRoutes):t[u.id]=[];return t}function ge(e,a,t){var n,p,u;const o=R(e,a).find(y=>y.id===t);if(o)return((n=o.routing)==null?void 0:n.modelRoutes)??{};const r=e.endpointRouting??{};return t==="anthropic"?((p=r.anthropic)==null?void 0:p.modelRoutes)??e.modelRoutes??{}:t==="openai"?((u=r.openai)==null?void 0:u.modelRoutes)??{}:{}}function F(e,a,t){var r,n,p;if(t==="anthropic"||t==="openai")return((n=(r=e.endpointRouting)==null?void 0:r[t])==null?void 0:n.defaults)??e.defaults;const o=R(e,a).find(u=>u.id===t);return((p=o==null?void 0:o.routing)==null?void 0:p.defaults)??e.defaults}function Qe(e,a){if(!e)return{};const t={anthropic:F(e,a,"anthropic"),openai:F(e,a,"openai")};for(const o of R(e,a))t[o.id]=F(e,a,o.id);return t}function ve(e){const a={};for(const t of e){const o=t.source.trim(),r=t.target.trim();o&&r&&(a[o]=r)}return a}function Je(e,a){return JSON.stringify(ve(e))!==JSON.stringify(a)}function Xe(e,a,t){var r,n,p;if(!a)return;if(e==="anthropic"||e==="openai")return(n=(r=a.endpointRouting)==null?void 0:r[e])==null?void 0:n.compatibility;const o=R(a,t).find(u=>u.id===e);return(p=o==null?void 0:o.routing)==null?void 0:p.compatibility}function Ye(e,a){var o,r;const t={anthropic:((o=e.routingPresets)==null?void 0:o.anthropic)??[],openai:((r=e.routingPresets)==null?void 0:r.openai)??[]};for(const n of R(e,a))t[n.id]=n.routingPresets??[];return t}function ye(e,a){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"]}],o=a.map(r=>{let n=e("modelManagement.tabs.customEndpoint"),p=[];if(r.paths&&r.paths.length>0)n=`${e("modelManagement.tabs.customEndpoint")}: ${r.paths.map(u=>`${u.path} (${u.protocol})`).join(", ")}`,p=[...new Set(r.paths.map(u=>u.protocol))];else if(r.path){const u=r.protocol||"anthropic";n=`${e("modelManagement.tabs.customEndpoint")}: ${r.path} (${u})`,p=[u]}return{key:r.id,label:r.label||r.id,description:n,isSystem:!1,canDelete:r.deletable!==!1,protocols:p}});return[...t,...o]}function We(e){return e.label&&e.label.trim().length>0?`${e.label} (${e.id})`:e.id}function je(e,a){if(!e)return!1;const[t]=e.split(":");return t===a||e===a}function Ne(e,a,t){if(!e)return[];const o=["anthropic","openai",...R(e,a).map(n=>n.id)],r=[];for(const n of o){const p=ge(e,a,n);for(const[u,y]of Object.entries(p))je(y,t)&&r.push({endpoint:n,source:u,target:y})}return r}function Ze(e,a,t){return Ne(e,a,t).length}function es(){var N;const{t:e}=P(),{pushToast:a}=oe(),t=ie(G.config.full(),ue.configRequest()),o=ne({queryKey:G.customEndpoints.all(),queryFn:ce.list,refetchInterval:1e4}),r=w.useMemo(()=>{var g;return((g=o.data)==null?void 0:g.endpoints)??[]},[(N=o.data)==null?void 0:N.endpoints]),n=w.useMemo(()=>ye(e,r),[r,e]),[p,u]=w.useState(null);return w.useEffect(()=>{t.data&&u(t.data)},[t.data]),w.useEffect(()=>{!t.isError||!t.error||a({title:e("providers.toast.loadFailure",{message:t.error.message}),variant:"error"})},[t.error,t.isError,a,e]),{t:e,pushToast:a,config:p,setConfig:u,configQuery:t,customEndpoints:r,customEndpointsQuery:o,tabs:n,ensureConfig:()=>p?!0:(a({title:e("settings.toast.missingConfig"),variant:"error"}),t.refetch(),!1)}}const ss={savePreset(e,a){return V(O.post(`/api/routing-presets/${e}`,{name:a}))},applyPreset(e,a){return V(O.post(`/api/routing-presets/${e}/apply`,{name:a}))},deletePreset(e,a){return V(O.delete(`/api/routing-presets/${e}/${encodeURIComponent(a)}`))},testProvider(e,a){return V(O.post(`/api/providers/${e}/test`,a??{}))}},we={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"},Se={complete:"text-foreground",current:"text-foreground font-medium",error:"text-destructive font-medium",upcoming:"text-muted-foreground"};function rs({steps:e,current:a,onSelect:t,className:o}){return s.jsx("nav",{"aria-label":"steps",className:T("flex items-start",o),children:e.map((r,n)=>{const p=t&&(r.status==="complete"||r.status==="current"),u=n===e.length-1,y=r.status==="complete"?"bg-primary/40":"bg-border",N=s.jsx("span",{className:T("motion-surface flex h-7 w-7 shrink-0 items-center justify-center rounded-lg border text-xs font-semibold",we[r.status]),"aria-current":r.id===a?"step":void 0,children:r.status==="complete"?s.jsx(le,{className:"h-3.5 w-3.5","aria-hidden":!0}):n+1}),g=`stepnav-${r.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:[p?s.jsx("button",{type:"button",onClick:()=>t==null?void 0:t(r.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:T("text-center text-[11px] leading-tight",Se[r.status]),children:r.label})]}),u?null:s.jsx("span",{"aria-hidden":!0,className:T("mx-1.5 mt-3.5 h-px flex-1",y)})]},r.id)})})}function Me({result:e,className:a}){const{t}=P();return s.jsxs("div",{className:T("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",a),children:[s.jsx(fe,{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 D(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function ke(){return{_key:D(),id:"",label:""}}function Ce(){return{_key:D(),name:"",value:""}}const K={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:{}},Ue=[{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"}],as=[{id:"basics",labelKey:"providers.drawer.steps.basics"},{id:"models",labelKey:"providers.drawer.steps.modelsVerify"}];function _(e){return e==="anthropic"?"authToken":"apiKey"}function Re(e,a,t){return t(a==="authToken"?"providers.drawer.fields.authModeAuthToken":a==="xAuthToken"?"providers.drawer.fields.authModeXAuthToken":e==="anthropic"?"providers.drawer.fields.authModeApiKey":"providers.drawer.fields.authModeProviderDefault")}function J(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(a=>({...a,_key:D()})),authMode:e.authMode??_(e.type??"custom"),nonStreamViaStream:e.nonStreamViaStream??!1,useAbsoluteUrl:e.useAbsoluteUrl??!1,extraHeaders:Object.entries(e.extraHeaders??{}).map(([a,t])=>({name:a,value:t,_key:D()}))}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:_("custom"),nonStreamViaStream:!1,useAbsoluteUrl:!1,extraHeaders:[]}}function Te(e){return{_key:D(),id:e.id,label:e.label,nonStreamViaStream:e.nonStreamViaStream}}function ts({form:e,errors:a,isCreate:t,advancedOpen:o,onAdvancedOpenChange:r,idInputRef:n,onProviderIdChange:p,onFieldChange:u,onTypeChange:y,onAuthModeChange:N,onNonStreamViaStreamChange:g,onUseAbsoluteUrlChange:m,onAddHeader:E,onRemoveHeader:j,onHeaderChange:S}){const{t:i}=P();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:i("providers.drawer.sections.type")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:i("providers.drawer.hints.type")})]}),s.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:Ue.map(b=>{var k;const U=b.value===e.type;return s.jsxs("button",{type:"button",onClick:()=>y(b.value),className:T("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",U?"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:((k=K[b.value??"custom"])==null?void 0:k.baseUrl)??i("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:i("providers.drawer.sections.basic")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:i("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:i("providers.drawer.fields.id")}),s.jsx(C,{value:e.id,ref:n,onChange:b=>p(b.target.value),disabled:!t,placeholder:i("providers.drawer.fields.idPlaceholder"),"aria-invalid":!!a.id}),a.id?s.jsx("span",{className:"text-xs text-destructive",children:a.id}):null]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:i("providers.drawer.fields.label")}),s.jsx(C,{value:e.label,onChange:b=>u("label")(b.target.value),placeholder:i("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:i("providers.drawer.fields.baseUrl")}),s.jsx(C,{value:e.baseUrl,onChange:b=>u("baseUrl")(b.target.value),placeholder:i("providers.drawer.fields.baseUrlPlaceholder"),"aria-invalid":!!a.baseUrl}),a.baseUrl?s.jsx("span",{className:"text-xs text-destructive",children:a.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:i("providers.drawer.sections.auth")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:i("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:i("providers.drawer.fields.apiKey")}),s.jsx(C,{value:e.apiKey,onChange:b=>u("apiKey")(b.target.value),placeholder:i("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:i("providers.drawer.fields.authMode")}),s.jsx("p",{className:"text-[11px] text-muted-foreground",children:i("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:Re(e.type,"apiKey",i)})]}),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:i("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:i("providers.drawer.fields.authModeXAuthToken")})]})]}),s.jsxs(X,{open:o,onOpenChange:r,summary:i("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:i("providers.drawer.fields.nonStreamViaStream")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:i("providers.drawer.fields.nonStreamViaStreamHint")})]}),s.jsx(Q,{checked:e.nonStreamViaStream,onCheckedChange:g,"aria-label":i("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:i("providers.drawer.fields.useAbsoluteUrl")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:i("providers.drawer.fields.useAbsoluteUrlHint")})]}),s.jsx(Q,{checked:e.useAbsoluteUrl,onCheckedChange:m,"aria-label":i("providers.drawer.fields.useAbsoluteUrl")})]})}),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:i("providers.drawer.fields.extraHeaders")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:i("providers.drawer.fields.extraHeadersHint")})]}),s.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:E,className:"bg-card text-xs",children:i("providers.drawer.fields.addHeader")})]}),a.extraHeaders?s.jsx("p",{className:"mt-2 text-xs text-destructive",children:a.extraHeaders}):null,e.extraHeaders.length>0?s.jsx("div",{className:"mt-3 space-y-3",children:e.extraHeaders.map((b,U)=>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:i("providers.drawer.fields.headerName")}),s.jsx(C,{value:b.name,onChange:k=>S(U,{name:k.target.value}),placeholder:i("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:i("providers.drawer.fields.headerValue")}),s.jsx(C,{value:b.value,onChange:k=>S(U,{value:k.target.value}),placeholder:i("providers.drawer.fields.headerValuePlaceholder")})]})]}),s.jsx("div",{className:"mt-2 flex justify-end",children:s.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-auto px-2 text-destructive",onClick:()=>j(U),children:i("providers.drawer.fields.removeHeader")})})]},b._key))}):null]})]})]})]})}function ds({form:e,errors:a,advancedOpen:t,onAdvancedOpenChange:o,onModelIdChange:r,onModelChange:n,onAddModel:p,onRemoveModel:u,onModelNonStreamViaStreamChange:y,onSetDefaultModel:N,testVerification:g}){const{t:m}=P(),E=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.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:p,className:"bg-card text-xs",children:m("providers.drawer.fields.addModel")})]}),a.models?s.jsx("p",{className:"text-xs text-destructive",children:a.models}):null,s.jsxs("div",{className:"space-y-4",children:[e.models.map((j,S)=>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:i=>r(S,i.target.value),placeholder:m("providers.drawer.fields.modelIdPlaceholder")})]})}),s.jsxs(X,{open:t,onOpenChange:o,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:i=>n(S,{label:i.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(me,{value:j.nonStreamViaStream===void 0?"inherit":j.nonStreamViaStream?"enabled":"disabled",onValueChange:i=>y(S,i),children:[s.jsx(pe,{children:s.jsx(he,{})}),s.jsxs(xe,{children:[s.jsx(L,{value:"inherit",children:m("providers.drawer.fields.modelNonStreamViaStreamInherit")}),s.jsx(L,{value:"enabled",children:m("providers.drawer.fields.modelNonStreamViaStreamEnabled")}),s.jsx(L,{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(A,{type:"button",variant:"ghost",size:"sm",className:"h-auto px-2 text-destructive",onClick:()=>u(S),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]}),E.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(A,{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(Me,{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 Ee=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;function ls({mode:e,provider:a,existingProviderIds:t}){const{t:o}=P(),[r,n]=w.useState(()=>J(a)),[p,u]=w.useState({}),[y,N]=w.useState(e==="edit"),g=w.useRef(null),m=w.useCallback(()=>{n(J(a)),u({}),N(e==="edit")},[a,e]),E=d=>l=>{n(h=>({...h,[d]:l}))},j=d=>{n(l=>{const c=!y||l.label.trim().length===0||l.label===l.id?d:l.label;return{...l,id:d,label:c}})},S=d=>{n(l=>{var q;const c=K[d??"custom"]??K.custom,x=_(l.type),f=_(d),v=Object.values(K).map(H=>H.baseUrl).filter(H=>!!H),$=!l.baseUrl||v.includes(l.baseUrl),de=e==="create"&&(l.models.length===0||l.models.every(H=>H.id.trim().length===0)),I={...l,type:d,authMode:l.authMode===x?f:l.authMode};return c!=null&&c.baseUrl&&$&&(I.baseUrl=c.baseUrl),c!=null&&c.models&&de&&(I.models=c.models.map(Te),I.defaultModel=c.defaultModel??((q=c.models[0])==null?void 0:q.id)??""),I})},i=(d,l)=>{n(h=>{const c=[...h.models];return c[d]={...c[d],...l},{...h,models:c}})},b=(d,l)=>{n(h=>{const c=[...h.models],x=c[d];if(!x)return h;const f=!y||!x.label||x.label===x.id,v={...x,id:l,label:f?l:x.label};c[d]=v;const $=h.defaultModel===x.id?l:h.defaultModel;return{...h,models:c,defaultModel:$}})},U=d=>{n(l=>{if(d<0||d>=l.models.length)return l;const h=l.models.filter((x,f)=>f!==d);let c=l.defaultModel;return h.some(x=>x.id===c)||(c=""),{...l,models:h,defaultModel:c}})},k=()=>{n(d=>({...d,models:[...d.models,ke()]}))},Y=(d,l)=>{n(h=>{const c=[...h.extraHeaders];return c[d]={...c[d],...l},{...h,extraHeaders:c}})},W=()=>{n(d=>({...d,extraHeaders:[...d.extraHeaders,Ce()]}))},Z=d=>{n(l=>{if(d<0||d>=l.extraHeaders.length)return l;const h=l.extraHeaders.filter((c,x)=>x!==d);return{...l,extraHeaders:h}})},ee=d=>{n(l=>({...l,authMode:d}))},se=d=>{n(l=>({...l,nonStreamViaStream:d}))},re=d=>{n(l=>({...l,useAbsoluteUrl:d}))},ae=(d,l)=>{i(d,{nonStreamViaStream:l==="inherit"?void 0:l==="enabled"})},te=d=>{n(l=>({...l,defaultModel:d}))},z=()=>{const d={},l=r.id.trim(),h=r.baseUrl.trim();if(e==="create"&&(l.length===0?d.id=o("providers.drawer.errors.idRequired"):t.includes(l)&&(d.id=o("providers.drawer.errors.idDuplicate"))),e==="edit"&&l.length===0&&(d.id=o("providers.drawer.errors.idRequired")),h.length===0)d.baseUrl=o("providers.drawer.errors.baseUrlInvalid");else try{new URL(h)}catch{d.baseUrl=o("providers.drawer.errors.baseUrlInvalid")}if(r.models.length>0){const c=new Set;r.models.some(f=>{const v=f.id.trim();return v.length===0||c.has(v)?!0:(c.add(v),!1)})&&(d.models=o("providers.drawer.errors.modelInvalid"))}if(r.defaultModel&&!r.models.some(c=>c.id===r.defaultModel)&&(d.models=o("providers.drawer.errors.defaultInvalid")),r.extraHeaders.length>0){const c=new Set;for(const x of r.extraHeaders){const f=x.name.trim();if(f.length===0)continue;if(!Ee.test(f)){d.extraHeaders=o("providers.drawer.errors.headerNameInvalid");break}const v=f.toLowerCase();if(c.has(v)){d.extraHeaders=o("providers.drawer.errors.headerNameDuplicate");break}c.add(v)}}return u(d),d};return{form:r,errors:p,advancedOpen:y,setAdvancedOpen:N,providerIdRef:g,isCreate:e==="create",resetForm:m,validate:()=>Object.keys(z()).length===0,validateErrors:z,serialize:()=>{const d=r.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),l={};for(const f of r.extraHeaders){const v=f.name.trim();v.length>0&&(l[v]=f.value)}const h=Object.keys(l).length>0,c=r.authMode==="apiKey"&&r.type!=="anthropic"?void 0:r.authMode,x={id:r.id.trim(),label:r.label.trim()||r.id.trim(),baseUrl:r.baseUrl.trim(),apiKey:r.apiKey.trim()||void 0,type:r.type??"custom",defaultModel:r.defaultModel||void 0,models:d.length>0?d:void 0,extraHeaders:h?l:void 0,authMode:c};return r.nonStreamViaStream&&(x.nonStreamViaStream=!0),r.useAbsoluteUrl&&(x.useAbsoluteUrl=!0),x},handleFieldChange:E,handleProviderIdChange:j,handleTypeChange:S,handleModelChange:i,handleModelIdChange:b,handleRemoveModel:U,handleAddModel:k,handleHeaderChange:Y,handleAddHeader:W,handleRemoveHeader:Z,handleAuthModeChange:ee,handleProviderNonStreamViaStreamChange:se,handleUseAbsoluteUrlChange:re,handleModelNonStreamViaStreamChange:ae,handleSetDefaultModel:te}}export{ts as B,ze as C,ds as M,qe as O,Ue as P,rs as S,Me as T,Je as a,Qe as b,F as c,Ge as d,Ye as e,be as f,ge as g,We as h,Re as i,as as j,Ne as k,Xe as l,ss as m,es as n,Ze as o,je as r,ls as u};
|
|
1
|
+
import{r as w,j as s,$ as le}from"./vendor-CITafuNQ.js";import{u as ne}from"./query-DZF7K6hv.js";import{a as oe,c as ie,q as G,e as ce,i as V,d as O,B as A}from"./app-czRBzLXv.js";import{g as ue}from"./gateway-Dxoj2rj4.js";import{u as P}from"./i18n-PeX9kBVO.js";import{c as T}from"./global-BCehxTGJ.js";import{D as X}from"./disclosure-l5qsWhr7.js";import{L as M,I as C}from"./label-DSVzZIex.js";import{S as me,a as pe,b as he,c as xe,d as L}from"./select-sOwKYsgI.js";import{S as Q}from"./switch-7PH_rDz6.js";import{B as fe}from"./badge-DpUlf_NW.js";const ze=["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 be(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function R(e,a){var t;return(t=e==null?void 0:e.customEndpoints)!=null&&t.length?e.customEndpoints:a}function B(e){return e?Object.entries(e).map(([a,t])=>({id:be(),source:a,target:t})):[]}function Ge(e,a){var r,n,p;if(!e)return{};const t={},o=e.endpointRouting??{};t.anthropic=B(((r=o.anthropic)==null?void 0:r.modelRoutes)??e.modelRoutes??{}),t.openai=B(((n=o.openai)==null?void 0:n.modelRoutes)??{});for(const u of R(e,a))(p=u.routing)!=null&&p.modelRoutes?t[u.id]=B(u.routing.modelRoutes):t[u.id]=[];return t}function ge(e,a,t){var n,p,u;const o=R(e,a).find(y=>y.id===t);if(o)return((n=o.routing)==null?void 0:n.modelRoutes)??{};const r=e.endpointRouting??{};return t==="anthropic"?((p=r.anthropic)==null?void 0:p.modelRoutes)??e.modelRoutes??{}:t==="openai"?((u=r.openai)==null?void 0:u.modelRoutes)??{}:{}}function F(e,a,t){var r,n,p;if(t==="anthropic"||t==="openai")return((n=(r=e.endpointRouting)==null?void 0:r[t])==null?void 0:n.defaults)??e.defaults;const o=R(e,a).find(u=>u.id===t);return((p=o==null?void 0:o.routing)==null?void 0:p.defaults)??e.defaults}function Qe(e,a){if(!e)return{};const t={anthropic:F(e,a,"anthropic"),openai:F(e,a,"openai")};for(const o of R(e,a))t[o.id]=F(e,a,o.id);return t}function ve(e){const a={};for(const t of e){const o=t.source.trim(),r=t.target.trim();o&&r&&(a[o]=r)}return a}function Je(e,a){return JSON.stringify(ve(e))!==JSON.stringify(a)}function Xe(e,a,t){var r,n,p;if(!a)return;if(e==="anthropic"||e==="openai")return(n=(r=a.endpointRouting)==null?void 0:r[e])==null?void 0:n.compatibility;const o=R(a,t).find(u=>u.id===e);return(p=o==null?void 0:o.routing)==null?void 0:p.compatibility}function Ye(e,a){var o,r;const t={anthropic:((o=e.routingPresets)==null?void 0:o.anthropic)??[],openai:((r=e.routingPresets)==null?void 0:r.openai)??[]};for(const n of R(e,a))t[n.id]=n.routingPresets??[];return t}function ye(e,a){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"]}],o=a.map(r=>{let n=e("modelManagement.tabs.customEndpoint"),p=[];if(r.paths&&r.paths.length>0)n=`${e("modelManagement.tabs.customEndpoint")}: ${r.paths.map(u=>`${u.path} (${u.protocol})`).join(", ")}`,p=[...new Set(r.paths.map(u=>u.protocol))];else if(r.path){const u=r.protocol||"anthropic";n=`${e("modelManagement.tabs.customEndpoint")}: ${r.path} (${u})`,p=[u]}return{key:r.id,label:r.label||r.id,description:n,isSystem:!1,canDelete:r.deletable!==!1,protocols:p}});return[...t,...o]}function We(e){return e.label&&e.label.trim().length>0?`${e.label} (${e.id})`:e.id}function je(e,a){if(!e)return!1;const[t]=e.split(":");return t===a||e===a}function Ne(e,a,t){if(!e)return[];const o=["anthropic","openai",...R(e,a).map(n=>n.id)],r=[];for(const n of o){const p=ge(e,a,n);for(const[u,y]of Object.entries(p))je(y,t)&&r.push({endpoint:n,source:u,target:y})}return r}function Ze(e,a,t){return Ne(e,a,t).length}function es(){var N;const{t:e}=P(),{pushToast:a}=oe(),t=ie(G.config.full(),ue.configRequest()),o=ne({queryKey:G.customEndpoints.all(),queryFn:ce.list,refetchInterval:1e4}),r=w.useMemo(()=>{var g;return((g=o.data)==null?void 0:g.endpoints)??[]},[(N=o.data)==null?void 0:N.endpoints]),n=w.useMemo(()=>ye(e,r),[r,e]),[p,u]=w.useState(null);return w.useEffect(()=>{t.data&&u(t.data)},[t.data]),w.useEffect(()=>{!t.isError||!t.error||a({title:e("providers.toast.loadFailure",{message:t.error.message}),variant:"error"})},[t.error,t.isError,a,e]),{t:e,pushToast:a,config:p,setConfig:u,configQuery:t,customEndpoints:r,customEndpointsQuery:o,tabs:n,ensureConfig:()=>p?!0:(a({title:e("settings.toast.missingConfig"),variant:"error"}),t.refetch(),!1)}}const ss={savePreset(e,a){return V(O.post(`/api/routing-presets/${e}`,{name:a}))},applyPreset(e,a){return V(O.post(`/api/routing-presets/${e}/apply`,{name:a}))},deletePreset(e,a){return V(O.delete(`/api/routing-presets/${e}/${encodeURIComponent(a)}`))},testProvider(e,a){return V(O.post(`/api/providers/${e}/test`,a??{}))}},we={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"},Se={complete:"text-foreground",current:"text-foreground font-medium",error:"text-destructive font-medium",upcoming:"text-muted-foreground"};function rs({steps:e,current:a,onSelect:t,className:o}){return s.jsx("nav",{"aria-label":"steps",className:T("flex items-start",o),children:e.map((r,n)=>{const p=t&&(r.status==="complete"||r.status==="current"),u=n===e.length-1,y=r.status==="complete"?"bg-primary/40":"bg-border",N=s.jsx("span",{className:T("motion-surface flex h-7 w-7 shrink-0 items-center justify-center rounded-lg border text-xs font-semibold",we[r.status]),"aria-current":r.id===a?"step":void 0,children:r.status==="complete"?s.jsx(le,{className:"h-3.5 w-3.5","aria-hidden":!0}):n+1}),g=`stepnav-${r.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:[p?s.jsx("button",{type:"button",onClick:()=>t==null?void 0:t(r.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:T("text-center text-[11px] leading-tight",Se[r.status]),children:r.label})]}),u?null:s.jsx("span",{"aria-hidden":!0,className:T("mx-1.5 mt-3.5 h-px flex-1",y)})]},r.id)})})}function Me({result:e,className:a}){const{t}=P();return s.jsxs("div",{className:T("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",a),children:[s.jsx(fe,{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 D(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function ke(){return{_key:D(),id:"",label:""}}function Ce(){return{_key:D(),name:"",value:""}}const K={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:{}},Ue=[{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"}],as=[{id:"basics",labelKey:"providers.drawer.steps.basics"},{id:"models",labelKey:"providers.drawer.steps.modelsVerify"}];function _(e){return e==="anthropic"?"authToken":"apiKey"}function Re(e,a,t){return t(a==="authToken"?"providers.drawer.fields.authModeAuthToken":a==="xAuthToken"?"providers.drawer.fields.authModeXAuthToken":e==="anthropic"?"providers.drawer.fields.authModeApiKey":"providers.drawer.fields.authModeProviderDefault")}function J(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(a=>({...a,_key:D()})),authMode:e.authMode??_(e.type??"custom"),nonStreamViaStream:e.nonStreamViaStream??!1,useAbsoluteUrl:e.useAbsoluteUrl??!1,extraHeaders:Object.entries(e.extraHeaders??{}).map(([a,t])=>({name:a,value:t,_key:D()}))}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:_("custom"),nonStreamViaStream:!1,useAbsoluteUrl:!1,extraHeaders:[]}}function Te(e){return{_key:D(),id:e.id,label:e.label,nonStreamViaStream:e.nonStreamViaStream}}function ts({form:e,errors:a,isCreate:t,advancedOpen:o,onAdvancedOpenChange:r,idInputRef:n,onProviderIdChange:p,onFieldChange:u,onTypeChange:y,onAuthModeChange:N,onNonStreamViaStreamChange:g,onUseAbsoluteUrlChange:m,onAddHeader:E,onRemoveHeader:j,onHeaderChange:S}){const{t:i}=P();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:i("providers.drawer.sections.type")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:i("providers.drawer.hints.type")})]}),s.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:Ue.map(b=>{var k;const U=b.value===e.type;return s.jsxs("button",{type:"button",onClick:()=>y(b.value),className:T("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",U?"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:((k=K[b.value??"custom"])==null?void 0:k.baseUrl)??i("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:i("providers.drawer.sections.basic")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:i("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:i("providers.drawer.fields.id")}),s.jsx(C,{value:e.id,ref:n,onChange:b=>p(b.target.value),disabled:!t,placeholder:i("providers.drawer.fields.idPlaceholder"),"aria-invalid":!!a.id}),a.id?s.jsx("span",{className:"text-xs text-destructive",children:a.id}):null]}),s.jsxs(M,{className:"flex flex-col gap-2 text-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground",children:i("providers.drawer.fields.label")}),s.jsx(C,{value:e.label,onChange:b=>u("label")(b.target.value),placeholder:i("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:i("providers.drawer.fields.baseUrl")}),s.jsx(C,{value:e.baseUrl,onChange:b=>u("baseUrl")(b.target.value),placeholder:i("providers.drawer.fields.baseUrlPlaceholder"),"aria-invalid":!!a.baseUrl}),a.baseUrl?s.jsx("span",{className:"text-xs text-destructive",children:a.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:i("providers.drawer.sections.auth")}),s.jsx("p",{className:"text-xs text-muted-foreground",children:i("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:i("providers.drawer.fields.apiKey")}),s.jsx(C,{value:e.apiKey,onChange:b=>u("apiKey")(b.target.value),placeholder:i("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:i("providers.drawer.fields.authMode")}),s.jsx("p",{className:"text-[11px] text-muted-foreground",children:i("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:Re(e.type,"apiKey",i)})]}),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:i("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:i("providers.drawer.fields.authModeXAuthToken")})]})]}),s.jsxs(X,{open:o,onOpenChange:r,summary:i("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:i("providers.drawer.fields.nonStreamViaStream")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:i("providers.drawer.fields.nonStreamViaStreamHint")})]}),s.jsx(Q,{checked:e.nonStreamViaStream,onCheckedChange:g,"aria-label":i("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:i("providers.drawer.fields.useAbsoluteUrl")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:i("providers.drawer.fields.useAbsoluteUrlHint")})]}),s.jsx(Q,{checked:e.useAbsoluteUrl,onCheckedChange:m,"aria-label":i("providers.drawer.fields.useAbsoluteUrl")})]})}),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:i("providers.drawer.fields.extraHeaders")}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:i("providers.drawer.fields.extraHeadersHint")})]}),s.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:E,className:"bg-card text-xs",children:i("providers.drawer.fields.addHeader")})]}),a.extraHeaders?s.jsx("p",{className:"mt-2 text-xs text-destructive",children:a.extraHeaders}):null,e.extraHeaders.length>0?s.jsx("div",{className:"mt-3 space-y-3",children:e.extraHeaders.map((b,U)=>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:i("providers.drawer.fields.headerName")}),s.jsx(C,{value:b.name,onChange:k=>S(U,{name:k.target.value}),placeholder:i("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:i("providers.drawer.fields.headerValue")}),s.jsx(C,{value:b.value,onChange:k=>S(U,{value:k.target.value}),placeholder:i("providers.drawer.fields.headerValuePlaceholder")})]})]}),s.jsx("div",{className:"mt-2 flex justify-end",children:s.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-auto px-2 text-destructive",onClick:()=>j(U),children:i("providers.drawer.fields.removeHeader")})})]},b._key))}):null]})]})]})]})}function ds({form:e,errors:a,advancedOpen:t,onAdvancedOpenChange:o,onModelIdChange:r,onModelChange:n,onAddModel:p,onRemoveModel:u,onModelNonStreamViaStreamChange:y,onSetDefaultModel:N,testVerification:g}){const{t:m}=P(),E=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.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:p,className:"bg-card text-xs",children:m("providers.drawer.fields.addModel")})]}),a.models?s.jsx("p",{className:"text-xs text-destructive",children:a.models}):null,s.jsxs("div",{className:"space-y-4",children:[e.models.map((j,S)=>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:i=>r(S,i.target.value),placeholder:m("providers.drawer.fields.modelIdPlaceholder")})]})}),s.jsxs(X,{open:t,onOpenChange:o,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:i=>n(S,{label:i.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(me,{value:j.nonStreamViaStream===void 0?"inherit":j.nonStreamViaStream?"enabled":"disabled",onValueChange:i=>y(S,i),children:[s.jsx(pe,{children:s.jsx(he,{})}),s.jsxs(xe,{children:[s.jsx(L,{value:"inherit",children:m("providers.drawer.fields.modelNonStreamViaStreamInherit")}),s.jsx(L,{value:"enabled",children:m("providers.drawer.fields.modelNonStreamViaStreamEnabled")}),s.jsx(L,{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(A,{type:"button",variant:"ghost",size:"sm",className:"h-auto px-2 text-destructive",onClick:()=>u(S),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]}),E.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(A,{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(Me,{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 Ee=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;function ls({mode:e,provider:a,existingProviderIds:t}){const{t:o}=P(),[r,n]=w.useState(()=>J(a)),[p,u]=w.useState({}),[y,N]=w.useState(e==="edit"),g=w.useRef(null),m=w.useCallback(()=>{n(J(a)),u({}),N(e==="edit")},[a,e]),E=d=>l=>{n(h=>({...h,[d]:l}))},j=d=>{n(l=>{const c=!y||l.label.trim().length===0||l.label===l.id?d:l.label;return{...l,id:d,label:c}})},S=d=>{n(l=>{var q;const c=K[d??"custom"]??K.custom,x=_(l.type),f=_(d),v=Object.values(K).map(H=>H.baseUrl).filter(H=>!!H),$=!l.baseUrl||v.includes(l.baseUrl),de=e==="create"&&(l.models.length===0||l.models.every(H=>H.id.trim().length===0)),I={...l,type:d,authMode:l.authMode===x?f:l.authMode};return c!=null&&c.baseUrl&&$&&(I.baseUrl=c.baseUrl),c!=null&&c.models&&de&&(I.models=c.models.map(Te),I.defaultModel=c.defaultModel??((q=c.models[0])==null?void 0:q.id)??""),I})},i=(d,l)=>{n(h=>{const c=[...h.models];return c[d]={...c[d],...l},{...h,models:c}})},b=(d,l)=>{n(h=>{const c=[...h.models],x=c[d];if(!x)return h;const f=!y||!x.label||x.label===x.id,v={...x,id:l,label:f?l:x.label};c[d]=v;const $=h.defaultModel===x.id?l:h.defaultModel;return{...h,models:c,defaultModel:$}})},U=d=>{n(l=>{if(d<0||d>=l.models.length)return l;const h=l.models.filter((x,f)=>f!==d);let c=l.defaultModel;return h.some(x=>x.id===c)||(c=""),{...l,models:h,defaultModel:c}})},k=()=>{n(d=>({...d,models:[...d.models,ke()]}))},Y=(d,l)=>{n(h=>{const c=[...h.extraHeaders];return c[d]={...c[d],...l},{...h,extraHeaders:c}})},W=()=>{n(d=>({...d,extraHeaders:[...d.extraHeaders,Ce()]}))},Z=d=>{n(l=>{if(d<0||d>=l.extraHeaders.length)return l;const h=l.extraHeaders.filter((c,x)=>x!==d);return{...l,extraHeaders:h}})},ee=d=>{n(l=>({...l,authMode:d}))},se=d=>{n(l=>({...l,nonStreamViaStream:d}))},re=d=>{n(l=>({...l,useAbsoluteUrl:d}))},ae=(d,l)=>{i(d,{nonStreamViaStream:l==="inherit"?void 0:l==="enabled"})},te=d=>{n(l=>({...l,defaultModel:d}))},z=()=>{const d={},l=r.id.trim(),h=r.baseUrl.trim();if(e==="create"&&(l.length===0?d.id=o("providers.drawer.errors.idRequired"):t.includes(l)&&(d.id=o("providers.drawer.errors.idDuplicate"))),e==="edit"&&l.length===0&&(d.id=o("providers.drawer.errors.idRequired")),h.length===0)d.baseUrl=o("providers.drawer.errors.baseUrlInvalid");else try{new URL(h)}catch{d.baseUrl=o("providers.drawer.errors.baseUrlInvalid")}if(r.models.length>0){const c=new Set;r.models.some(f=>{const v=f.id.trim();return v.length===0||c.has(v)?!0:(c.add(v),!1)})&&(d.models=o("providers.drawer.errors.modelInvalid"))}if(r.defaultModel&&!r.models.some(c=>c.id===r.defaultModel)&&(d.models=o("providers.drawer.errors.defaultInvalid")),r.extraHeaders.length>0){const c=new Set;for(const x of r.extraHeaders){const f=x.name.trim();if(f.length===0)continue;if(!Ee.test(f)){d.extraHeaders=o("providers.drawer.errors.headerNameInvalid");break}const v=f.toLowerCase();if(c.has(v)){d.extraHeaders=o("providers.drawer.errors.headerNameDuplicate");break}c.add(v)}}return u(d),d};return{form:r,errors:p,advancedOpen:y,setAdvancedOpen:N,providerIdRef:g,isCreate:e==="create",resetForm:m,validate:()=>Object.keys(z()).length===0,validateErrors:z,serialize:()=>{const d=r.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),l={};for(const f of r.extraHeaders){const v=f.name.trim();v.length>0&&(l[v]=f.value)}const h=Object.keys(l).length>0,c=r.authMode==="apiKey"&&r.type!=="anthropic"?void 0:r.authMode,x={id:r.id.trim(),label:r.label.trim()||r.id.trim(),baseUrl:r.baseUrl.trim(),apiKey:r.apiKey.trim()||void 0,type:r.type??"custom",defaultModel:r.defaultModel||void 0,models:d.length>0?d:void 0,extraHeaders:h?l:void 0,authMode:c};return r.nonStreamViaStream&&(x.nonStreamViaStream=!0),r.useAbsoluteUrl&&(x.useAbsoluteUrl=!0),x},handleFieldChange:E,handleProviderIdChange:j,handleTypeChange:S,handleModelChange:i,handleModelIdChange:b,handleRemoveModel:U,handleAddModel:k,handleHeaderChange:Y,handleAddHeader:W,handleRemoveHeader:Z,handleAuthModeChange:ee,handleProviderNonStreamViaStreamChange:se,handleUseAbsoluteUrlChange:re,handleModelNonStreamViaStreamChange:ae,handleSetDefaultModel:te}}export{ts as B,ze as C,ds as M,qe as O,Ue as P,rs as S,Me as T,Je as a,Qe as b,F as c,Ge as d,Ye as e,be as f,ge as g,We as h,Re as i,as as j,Ne as k,Xe as l,ss as m,es as n,Ze as o,je as r,ls 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-czRBzLXv.js"></script>
|
|
18
18
|
<link rel="modulepreload" crossorigin href="/assets/vendor-CITafuNQ.js">
|
|
19
19
|
<link rel="modulepreload" crossorigin href="/assets/global-BCehxTGJ.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-DBrU8FIr.js"></script>
|
|
46
46
|
<link rel="modulepreload" crossorigin href="/assets/vendor-CITafuNQ.js">
|
|
47
47
|
<link rel="modulepreload" crossorigin href="/assets/global-BCehxTGJ.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-BXeeAB6b.js">
|
|
50
50
|
<link rel="stylesheet" crossorigin href="/assets/global-CIVH6GQV.css">
|
|
51
51
|
</head>
|
|
52
52
|
<body class="bg-slate-50 text-slate-900">
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const o="0.9.0-beta.0",s={version:o};export{s as p};
|