@maxceem/agw 0.1.4 → 0.1.5

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.
@@ -72,7 +72,7 @@ Please change the parent <Route path="${e}"> to <Route path="${e===`/`?`*`:`${e}
72
72
  `,Mw=`<svg height="1em" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M23.197 4.503A6 6 0 0015 2.307a5.973 5.973 0 00-2.995 4.933l5.996.008v.515h-5.996c.039.937.298 1.87.8 2.74a6 6 0 1010.39-6z" fill="#EF2CC1"></path><path d="M.805 4.5A6 6 0 003 12.697a5.972 5.972 0 005.77.127L5.779 7.627l.446-.257 2.997 5.192A6 6 0 10.804 4.5z" fill="#CAAEF5"></path><path d="M12 23.894a6 6 0 005.999-6c0-2.13-1.1-3.996-2.775-5.06l-3.005 5.189-.444-.258 2.997-5.192A6 6 0 1012 23.894z" fill="#FC4C02"></path></svg>
73
73
  `,Nw=`<svg fill="currentColor" fill-rule="evenodd" height="1em" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M12 0l12 20.785H0L12 0z"></path></svg>
74
74
  `,Pw=`<svg fill="currentColor" fill-rule="evenodd" height="1em" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M6.469 8.776L16.512 23h-4.464L2.005 8.776H6.47zm-.004 7.9l2.233 3.164L6.467 23H2l4.465-6.324zM22 2.582V23h-3.659V7.764L22 2.582zM22 1l-9.952 14.095-2.233-3.163L17.533 1H22z"></path></svg>
75
- `,Fw=[`openai`,`anthropic`,`xai`,`gemini`,`perplexity`,`deepseek`,`groq`,`mistral`,`together`,`fireworks`,`cerebras`,`moonshot`,`huggingface`,`baseten`,`bytedance`,`openrouter`],Iw=[`responses`,`chat_completions`,`anthropic_messages`,`gemini_native`,`audio_transcription`,`other`],Lw={responses:`v1/responses`,chat_completions:`v1/chat/completions`,anthropic_messages:`v1/messages`,gemini_native:`v1beta/models/{model}:generateContent`,audio_transcription:`v1/audio/transcriptions`},Rw=[`responses`,`transcription`],zw={responses:`responses`,transcription:`audio_transcription`},Bw=[`responses`,`chat_completions`,`gemini_native`,`anthropic`,`none`],Vw={apiStyles:Iw,endpointStyles:[]},Hw={openai:{apiStyles:Iw,endpointStyles:[`responses`,`transcription`]},xai:{apiStyles:Iw,endpointStyles:[`responses`,`transcription`]},openrouter:{apiStyles:[`chat_completions`],endpointStyles:[]}};function Uw(e){return Hw[e]??Vw}var Ww=Fw.filter(e=>Uw(e).endpointStyles.length>0);function Gw(e){return Ww.filter(t=>Uw(t).endpointStyles.includes(e))}var Kw={openai:{slug:`openai`,stripPathPrefix:`v1/`},anthropic:{slug:`anthropic`},xai:{slug:`grok`},gemini:{slug:`google-ai-studio`},perplexity:{slug:`perplexity-ai`}},qw=[`responses`,`chat_completions`,`anthropic_messages`],Jw=[`responses`];function Yw(e){return{modelPrefix:e,apiStyles:qw,endpointStyles:Jw}}var Xw={cf_aig:Kw,vercel:{openai:Yw(`openai/`),anthropic:Yw(`anthropic/`),gemini:Yw(`google/`),xai:Yw(`spacexai/`),perplexity:Yw(`perplexity/`),deepseek:Yw(`deepseek/`),moonshot:Yw(`moonshotai/`)}},Zw=[`openrouter`];function Qw(e){return Zw.includes(e)}var $w=Fw,eT={openai:`OpenAI`,anthropic:`Anthropic`,xai:`xAI`,gemini:`Gemini`,perplexity:`Perplexity`,deepseek:`DeepSeek`,groq:`Groq`,mistral:`Mistral`,together:`Together AI`,fireworks:`Fireworks AI`,cerebras:`Cerebras`,moonshot:`Moonshot AI`,huggingface:`Hugging Face`,baseten:`Baseten`,bytedance:`ByteDance Ark`,openrouter:`OpenRouter`},tT={cf_aig:`Cloudflare AI Gateway`,vercel:`Vercel AI Gateway`},nT=[{value:`cf_aig`,label:tT.cf_aig,defaultName:`Our CF gateway`,tokenDocsUrl:`https://developers.cloudflare.com/ai-gateway/configuration/authentication/`,needsCloudflareIds:!0,credentialNote:`Requests use the provider keys stored in your Cloudflare AI Gateway's own key store.`},{value:`vercel`,label:tT.vercel,defaultName:`Our Vercel gateway`,tokenDocsUrl:`https://vercel.com/docs/ai-gateway/authentication-and-byok/api-keys`,needsCloudflareIds:!1,credentialNote:`Your provider credential stored in Vercel is preferred. Vercel may fall back to system credentials.`}],rT=Bw,iT=`x-end-user-id`;function aT(e,t){let n=Object.keys(t?.[e.type]??{}),r=Object.keys(e.pricing??{});return[...n,...r.filter(e=>!n.includes(e))]}var oT=Gw;function sT(e,t,n){let r=oT(e);return t.filter(t=>r.includes(t.type)&&(n?.(t,e)??!0))}var cT=/^[a-z0-9-]{1,64}$/,lT=e=>e.end_user?.source===`issuer`?e.end_user.issuer:void 0;function uT(){return{provider:`firebase`,jwks_url:``,issuer:``,audience:``,user_id_claim:`sub`,required_claims:[],max_token_lifetime_seconds:86400}}function dT(e,t){if(e.type===`apple_app_attest`)return{...e,end_user:{source:`issuer`,issuer:t??lT(e)??uT()}};if(!t){let{end_user:t,...n}=e;return n}return{...e,end_user:{source:`issuer`,issuer:t}}}var fT=e=>typeof e==`string`?{path:e}:e;function pT(e){return!e.fixed_model&&(!e.clamp||e.clamp===void 0)?e.path:{path:e.path,...e.fixed_model?{fixed_model:e.fixed_model}:{},...e.clamp?{clamp:e.clamp}:{}}}function mT(){return{allowed_paths:[],allowed_models:[]}}function hT(e=`openai`){return{api_style:`responses`,provider:e,model:``}}function gT(e,t=`endpoint`){if(e[t]===void 0)return t;for(let n=2;n<1e3;n+=1){let r=`${t}-${n}`;if(e[r]===void 0)return r}return`${t}-${Date.now()}`}function _T(e,t,n){return Object.fromEntries(Object.entries(e).map(([e,r])=>[e===t?n:e,r]))}function vT(e,t,n){return cT.test(e)?e!==n&&t[e]!==void 0?`Another endpoint already uses this slug`:null:`Use 1-64 characters from a-z, 0-9, and -`}function yT(e){return e.providers.mode}function bT(e){if(yT(e)===`all`)return[];let t=e.providers.selected??{};return Object.keys(t).filter(e=>t[e]!==void 0)}function xT(e){return $w.includes(e)}function ST(e){return Object.hasOwn(tT,e)}function CT(e,t){if(yT(e)===`all`)return[...$w];let n=new Map(t.map(e=>[e.slug,e.type])),r=new Set(bT(e).flatMap(e=>{let t=n.get(e);return t?[t]:xT(e)?[e]:[]}));return $w.filter(e=>r.has(e))}var wT=`size-full text-current`;function TT(e){return e.trim().replace(`<svg`,`<svg class="${wT}"`)}function ET(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,TT(t)]))}var DT=ET({openai:Dw,anthropic:dw,xai:Pw,gemini:Sw,perplexity:kw,deepseek:yw,groq:Cw,mistral:Tw,together:Mw,fireworks:xw,cerebras:gw,moonshot:Ew,huggingface:ww,baseten:mw,bytedance:hw,openrouter:Ow}),OT=ET({cf_aig:_w,vercel:Nw}),kT=ET({firebase:bw,supabase:jw,auth0:pw,clerk:vw,apple:fw,revenuecat:Aw});function AT(e){return Object.hasOwn(kT,e)}function jT({svg:e,className:t}){return(0,I.jsx)(`span`,{"aria-hidden":!0,className:H(`inline-flex size-[1.15em] shrink-0`,t),dangerouslySetInnerHTML:{__html:e}})}function MT({type:e,className:t}){return(0,I.jsx)(jT,{svg:DT[e],className:t})}function NT({type:e,className:t}){return(0,I.jsx)(jT,{svg:OT[e],className:t})}function PT({type:e,className:t}){return(0,I.jsx)(jT,{svg:kT[e],className:t})}function FT({type:e,className:t}){return(0,I.jsxs)(`span`,{className:H(`inline-flex items-center gap-1.5`,t),children:[(0,I.jsx)(MT,{type:e}),eT[e]]})}function IT({type:e,className:t}){return(0,I.jsxs)(`span`,{className:H(`inline-flex items-center gap-1.5`,t),children:[(0,I.jsx)(NT,{type:e}),tT[e]]})}function LT(e,t){if(yT(e)===`all`)return[];let n=t.filter(e=>e.status===`active`),r=new Set(n.map(e=>e.type));return CT(e,n).filter(e=>!r.has(e))}function RT({proxy:e}){let t=dS();if(!t.data)return null;let n=LT(e,t.data.providers);return n.length===0?null:(0,I.jsxs)(Ds,{children:[(0,I.jsx)(ca,{}),(0,I.jsxs)(Os,{children:[`No credential for`,` `,n.map((e,t)=>(0,I.jsxs)(v.Fragment,{children:[t>0?`, `:null,(0,I.jsx)(FT,{type:e,className:`align-middle`})]},e))]}),(0,I.jsxs)(ks,{children:[`This app allows`,` `,n.length===1?`a provider`:`providers`,` you have not configured, so those requests fail with `,(0,I.jsx)(`code`,{className:`font-mono text-xs`,children:`provider_not_configured`}),`.`,` `,(0,I.jsx)(Pn,{to:`/providers`,className:`text-primary-ink underline underline-offset-4`,children:`Add a provider key`}),`.`]})]})}function zT({...e}){return(0,I.jsx)(hv,{"data-slot":`select`,...e})}function BT({...e}){return(0,I.jsx)(yv,{"data-slot":`select-value`,...e})}function VT({className:e,size:t=`default`,children:n,...r}){return(0,I.jsxs)(_v,{"data-slot":`select-trigger`,"data-size":t,className:H(`flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground`,e),...r,children:[n,(0,I.jsx)(bv,{asChild:!0,children:(0,I.jsx)(ia,{className:`size-4 opacity-50`})})]})}function HT({className:e,children:t,position:n=`item-aligned`,align:r=`center`,...i}){return(0,I.jsx)(Cv,{children:(0,I.jsxs)(Tv,{"data-slot":`select-content`,className:H(`relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,n===`popper`&&`data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1`,e),position:n,align:r,...i,children:[(0,I.jsx)(GT,{}),(0,I.jsx)(Lv,{className:H(`p-1`,n===`popper`&&`h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1`),children:t}),(0,I.jsx)(KT,{})]})})}function UT({className:e,children:t,...n}){return(0,I.jsxs)(Uv,{"data-slot":`select-item`,className:H(`relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2`,e),...n,children:[(0,I.jsx)(`span`,{"data-slot":`select-item-indicator`,className:`absolute right-2 flex size-3.5 items-center justify-center`,children:(0,I.jsx)(qv,{children:(0,I.jsx)(ra,{className:`size-4`})})}),(0,I.jsx)(Gv,{children:t})]})}function WT({className:e,...t}){return(0,I.jsx)($v,{"data-slot":`select-separator`,className:H(`pointer-events-none -mx-1 my-1 h-px bg-border`,e),...t})}function GT({className:e,...t}){return(0,I.jsx)(Yv,{"data-slot":`select-scroll-up-button`,className:H(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,I.jsx)(oa,{className:`size-4`})})}function KT({className:e,...t}){return(0,I.jsx)(Zv,{"data-slot":`select-scroll-down-button`,className:H(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,I.jsx)(ia,{className:`size-4`})})}function qT({value:e,onChange:t,months:n=12}){let r=CC(n);return(0,I.jsxs)(zT,{value:e,onValueChange:t,children:[(0,I.jsx)(VT,{className:`w-[180px]`,size:`sm`,"aria-label":`Month`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:r.map(e=>(0,I.jsx)(UT,{value:e,children:SC(e)},e))})]})}var JT=[{value:`7`,label:`Last 7 days`},{value:`30`,label:`Last 30 days`},{value:`90`,label:`Last 90 days`}];function YT({value:e,onChange:t}){return(0,I.jsxs)(zT,{value:e,onValueChange:t,children:[(0,I.jsx)(VT,{className:`w-[150px]`,size:`sm`,"aria-label":`Date range`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:JT.map(e=>(0,I.jsx)(UT,{value:e.value,children:e.label},e.value))})]})}function XT(e){return{name:e.name,config:e.config,status:e.status}}var ZT=e=>e;function QT(e){let t=MS(e),n=NS(e),[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(null),d=(0,v.useRef)(null),f=t.data?.app;(0,v.useEffect)(()=>{if(!f||l===e&&r!==null&&a!==null&&JSON.stringify(r)!==a)return;let t=XT(f);d.current=lT(t.config.authentication)??null,i(t),o(JSON.stringify(t)),c(f.revision),u(e)},[e,f]);let p=l===e?r:null,m=l===e?a:null,h=p!==null&&m!==null&&JSON.stringify(p)!==m,g=(0,v.useCallback)(e=>{i(t=>t&&{...t,...e})},[]),_=(0,v.useCallback)(e=>{i(t=>t&&{...t,config:{...t.config,...e}})},[]);return{query:t,draft:p,dirty:h,update:g,updateConfig:_,updateAuthentication:(0,v.useCallback)(e=>{_({authentication:e})},[_]),updateIssuer:(0,v.useCallback)(e=>{i(t=>{if(!t)return t;let n=t.config.authentication,r=lT(n)??(n.type===`apple_app_attest`?uT():void 0);return r?{...t,config:{...t.config,authentication:dT(n,{...r,...e})}}:t})},[]),setEndUserSource:(0,v.useCallback)(e=>{i(t=>{if(!t)return t;let n=t.config.authentication,r=lT(n);r&&(d.current=r);let i=e===`issuer`?dT(n,r??d.current??uT()):e===`app_install`?n.type===`apple_app_attest`?{...n,end_user:{source:`app_install`}}:n:e===`header`?n.type===`api_key`?{...n,end_user:{source:`header`,header:n.end_user?.source===`header`?n.end_user.header:iT}}:n:dT(n,void 0),a=i.type!==`api_key`||i.end_user!==void 0||t.config.limits===void 0?t.config:{...t.config,limits:{...t.config.limits,per_user:{requests:{per_minute:null,per_day:null},spending:{monthly_usd:null}}}};return{...t,config:{...a,authentication:i}}})},[]),updateEndUserHeader:(0,v.useCallback)(e=>{i(t=>{if(!t)return t;let n=t.config.authentication;return n.type!==`api_key`||n.end_user?.source!==`header`?t:{...t,config:{...t.config,authentication:{...n,end_user:{source:`header`,header:e}}}}})},[]),updateProxy:(0,v.useCallback)(e=>{i(t=>t&&{...t,config:{...t.config,routing:{...t.config.routing,...e}}})},[]),updateLimits:(0,v.useCallback)(e=>_({limits:e}),[_]),updateEndpoints:(0,v.useCallback)(e=>{i(t=>{if(!t)return t;let{endpoints:n,...r}=t.config;return{...t,config:Object.keys(e).length===0?r:{...r,endpoints:e}}})},[]),reset:(0,v.useCallback)(()=>{if(!m)return;let e=JSON.parse(m);d.current=lT(e.config.authentication)??null,i(e)},[m]),save:(0,v.useCallback)(async()=>{if(!p||s===null)return!1;try{let e=await n.mutateAsync({body:ZT(p),revision:s});return c(e.app.revision),o(JSON.stringify(p)),U.success(`Configuration saved`,{description:`The gateway picks it up within the 60 second config cache TTL.`}),!0}catch(e){return U.error(`Save rejected`,{description:e instanceof Error?e.message:`Unknown error`}),!1}},[p,s,n]),saving:n.isPending}}function $T(e){let t=e=>Array.isArray(e)?e.length>0&&e.every(Boolean):!!e;return(e.jwks_url??``).startsWith(`https://`)&&t(e.issuer)&&t(e.audience)}function eE(e){return e.path.trim()?e.equals===void 0?Array.isArray(e.contains)?e.contains.length>0&&e.contains.every(e=>e.trim().length>0):!!e.contains?.trim():String(e.equals).length>0:!1}function tE(e){let t=e.config.authentication;if(!e.name.trim())return`Give the app a name.`;if(t.type===`apple_app_attest`){let{team_id:e,bundle_id:n}=t.app_attest;if(!e.trim()||!n.trim())return`Enter the Apple Team ID and Bundle ID.`}if(t.type===`api_key`&&t.end_user?.source===`header`&&!t.end_user.header.trim())return`Enter the header name.`;let n=lT(t);if(n){if(!$T(n))return`Finish the identity provider details.`;if(!(n.required_claims??[]).every(eE))return`Finish the subscription check.`}return null}function nE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`card`,className:H(`flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm`,e),...t})}function rE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`card-header`,className:H(`@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6`,e),...t})}function iE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`card-title`,className:H(`leading-none font-semibold`,e),...t})}function aE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`card-description`,className:H(`text-sm text-muted-foreground`,e),...t})}function oE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`card-content`,className:H(`px-6`,e),...t})}function sE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`table-container`,className:`relative w-full overflow-x-auto`,children:(0,I.jsx)(`table`,{"data-slot":`table`,className:H(`w-full caption-bottom text-sm [--table-inset:1.5rem]`,`[&_tr>*:first-child]:pl-(--table-inset) [&_tr>*:last-child]:pr-(--table-inset)`,e),...t})})}function cE({className:e,...t}){return(0,I.jsx)(`thead`,{"data-slot":`table-header`,className:H(`[&_tr]:border-b`,e),...t})}function lE({className:e,...t}){return(0,I.jsx)(`tbody`,{"data-slot":`table-body`,className:H(`[&_tr:last-child]:border-0`,e),...t})}function uE({className:e,...t}){return(0,I.jsx)(`tr`,{"data-slot":`table-row`,className:H(`border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted`,e),...t})}function Z({className:e,...t}){return(0,I.jsx)(`th`,{"data-slot":`table-head`,className:H(`h-11 px-3 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t})}function Q({className:e,...t}){return(0,I.jsx)(`td`,{"data-slot":`table-cell`,className:H(`px-3 py-2.5 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t})}function dE({label:e,value:t,detail:n}){return(0,I.jsx)(nE,{className:`gap-0 py-4`,children:(0,I.jsxs)(oE,{className:`px-4`,children:[(0,I.jsx)(`p`,{className:`text-xs font-medium tracking-wide text-muted-foreground uppercase`,children:e}),(0,I.jsx)(`p`,{className:`tabular mt-1.5 text-2xl leading-none font-semibold`,children:t}),n?(0,I.jsx)(`p`,{className:`mt-1.5 text-xs text-muted-foreground`,children:n}):null]})})}function fE(e){return e==null?`—`:e<1e3?`${Math.round(e)} ms`:e<6e4?`${(e/1e3).toFixed(1)} s`:e<36e5?`${Math.round(e/6e4)} min`:`${(e/36e5).toFixed(1)} h`}function pE(e){let t=new Map,n=(e,n,r,i,a)=>{let o=t.get(e)??{outcome:n,reason:r,days:new Map};o.days.set(i,(o.days.get(i)??0)+a),t.set(e,o)};for(let t of e?.daily??[])t.outcome!==`ok`&&n(`auth:${t.outcome}:${t.reason??``}`,t.outcome,t.reason,t.date,t.count);for(let t of e?.usage_failures??[])n(`proxy:${t.status}`,t.status,`proxied request`,t.date,t.count);return[...t.values()].map(e=>({outcome:e.outcome,reason:e.reason,total:[...e.days.values()].reduce((e,t)=>e+t,0),days:[...e.days.entries()].map(([e,t])=>({date:e,count:t})).sort((e,t)=>e.date<t.date?-1:+(e.date>t.date))})).sort((e,t)=>t.total-e.total||(e.outcome<t.outcome?-1:+(e.outcome>t.outcome)))}var mE=[`issuer_claims_missing`,`issuer_token_rejected`,`issuer_verification_unavailable`,`attest_failed`,`auth_required`,`ok`];function hE({appId:e}){let[t,n]=(0,v.useState)(`30`),[r,i]=(0,v.useState)(`all`),[a,o]=(0,v.useState)([]),s=GS(e,Number(t)),c=KS(e,{limit:25,outcome:r===`all`?void 0:r,before_id:a.at(-1)}),l=(0,v.useMemo)(()=>pE(s.data),[s.data]),u=s.data?.claim_delay,d=s.data?.pending_users??0;return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,I.jsx)(dE,{label:`Exchange success`,value:uC(s.data?.token_exchange.success_rate),detail:`${cC(s.data?.token_exchange.total??0)} attempts`}),(0,I.jsx)(dE,{label:`Claim delay p50`,value:fE(u?.p50_ms),detail:`${cC(u?.count??0)} measured`}),(0,I.jsx)(dE,{label:`Claim delay p95`,value:fE(u?.p95_ms),detail:`avg ${fE(u?.avg_ms)}`}),(0,I.jsx)(dE,{label:`Pending activations`,value:cC(d),detail:d>0?`waiting on a claim now`:`none waiting`})]}),(0,I.jsxs)(nE,{className:`py-0`,children:[(0,I.jsx)(rE,{className:`pt-6`,children:(0,I.jsx)(lw,{title:`Failures by cause`,description:`Refused authentication attempts and non-ok proxied requests, busiest first.`,action:(0,I.jsx)(YT,{value:t,onChange:n})})}),(0,I.jsx)(oE,{className:`px-0 pb-0`,children:s.isPending?(0,I.jsx)(`div`,{className:`px-6 pb-6`,children:(0,I.jsx)(aw,{className:`h-24 w-full`})}):l.length===0?(0,I.jsx)(`div`,{className:`px-6 pb-6`,children:(0,I.jsx)(uw,{children:`No failed requests in this range.`})}):(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{className:`hover:bg-transparent`,children:[(0,I.jsx)(Z,{children:`Outcome`}),(0,I.jsx)(Z,{children:`Reason`}),(0,I.jsx)(Z,{className:`text-right`,children:`Count`}),(0,I.jsx)(Z,{className:`text-right`,children:`Days affected`}),(0,I.jsx)(Z,{children:`Last seen`})]})}),(0,I.jsx)(lE,{children:l.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{children:(0,I.jsx)(eC,{outcome:e.outcome})}),(0,I.jsx)(Q,{className:`font-mono text-xs text-muted-foreground`,children:e.reason??`—`}),(0,I.jsx)(Q,{className:`tabular text-right`,children:cC(e.total)}),(0,I.jsx)(Q,{className:`tabular text-right`,children:cC(e.days.length)}),(0,I.jsx)(Q,{className:`text-xs whitespace-nowrap text-muted-foreground`,children:e.days.at(-1)?.date??`—`})]},`${e.outcome}-${e.reason??``}`))})]})})]}),(0,I.jsxs)(nE,{className:`py-0`,children:[(0,I.jsx)(rE,{className:`pt-6`,children:(0,I.jsx)(lw,{title:`Recent attempts`,description:`Every token exchange and key registration, newest first.`,action:(0,I.jsxs)(zT,{value:r,onValueChange:e=>{i(e),o([])},children:[(0,I.jsx)(VT,{className:`w-[210px]`,size:`sm`,"aria-label":`Outcome`,children:(0,I.jsx)(BT,{})}),(0,I.jsxs)(HT,{children:[(0,I.jsx)(UT,{value:`all`,children:`All outcomes`}),mE.map(e=>(0,I.jsx)(UT,{value:e,children:e},e))]})]})})}),(0,I.jsxs)(oE,{className:`px-0 pb-0`,children:[(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{className:`hover:bg-transparent`,children:[(0,I.jsx)(Z,{children:`When`}),(0,I.jsx)(Z,{children:`User`}),(0,I.jsx)(Z,{children:`Call`}),(0,I.jsx)(Z,{children:`Outcome`}),(0,I.jsx)(Z,{children:`Reason`}),(0,I.jsx)(Z,{children:`App version`}),(0,I.jsx)(Z,{className:`text-right`,children:`Latency`}),(0,I.jsx)(Z,{className:`text-right`,children:`Claim delay`})]})}),(0,I.jsx)(lE,{children:c.isPending?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:8,children:(0,I.jsx)(aw,{className:`h-8 w-full`})})}):c.data?.events.length===0?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:8,className:`py-8 text-center text-sm text-muted-foreground`,children:`No attempts.`})}):c.data?.events.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{className:`text-xs whitespace-nowrap text-muted-foreground`,children:mC(e.created_at)}),(0,I.jsx)(Q,{className:`font-mono text-xs`,children:e.user_id??(0,I.jsx)(`span`,{className:`text-muted-foreground`,children:`unknown`})}),(0,I.jsxs)(Q,{className:`font-mono text-xs text-muted-foreground`,children:[e.event,e.auth_method?(0,I.jsx)(`span`,{className:`block`,children:e.auth_method}):null]}),(0,I.jsx)(Q,{children:(0,I.jsx)(eC,{outcome:e.outcome})}),(0,I.jsx)(Q,{className:`font-mono text-xs text-muted-foreground`,children:e.reason??`—`}),(0,I.jsx)(Q,{className:`font-mono text-xs text-muted-foreground`,children:e.app_version??`—`}),(0,I.jsx)(Q,{className:`tabular text-right text-xs`,children:e.latency_ms===null?`—`:`${cC(e.latency_ms)} ms`}),(0,I.jsx)(Q,{className:`tabular text-right text-xs`,children:e.claim_delay_ms===null?`—`:(0,I.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400`,title:`This exchange ended a wait for an entitlement claim to propagate.`,children:fE(e.claim_delay_ms)})})]},e.id))})]}),(0,I.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t px-6 py-3`,children:[(0,I.jsx)(J,{variant:`outline`,size:`sm`,disabled:a.length===0,onClick:()=>o(e=>e.slice(0,-1)),children:`Newer`}),(0,I.jsx)(J,{variant:`outline`,size:`sm`,disabled:!c.data?.next_before_id,onClick:()=>o(e=>[...e,c.data.next_before_id]),children:`Older`})]})]})]})]})}function $({className:e,type:t,...n}){return(0,I.jsx)(`input`,{type:t,"data-slot":`input`,className:H(`h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:bg-input/30`,`focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50`,`aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40`,e),...n})}function gE({className:e,...t}){return(0,I.jsx)(Mf,{"data-slot":`checkbox`,className:H(`peer size-4 shrink-0 rounded-[4px] border border-input shadow-xs transition-shadow outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:bg-input/30 dark:aria-invalid:ring-destructive/40 dark:data-[state=checked]:bg-primary`,e),...t,children:(0,I.jsx)(Pf,{"data-slot":`checkbox-indicator`,className:`grid place-content-center text-current transition-none`,children:(0,I.jsx)(ra,{className:`size-3.5`})})})}var _E=[{value:`production`,label:`Production`,hint:`Builds signed for TestFlight and the App Store.`},{value:`development`,label:`Development`,hint:`Builds run from Xcode, which attest in Apple's development environment.`}];function vE({value:e,onChange:t,compact:n=!1,disabled:r=!1}){let i=e??[`production`],a=i.includes(`development`),o=(e,n)=>{let r=_E.map(e=>e.value).filter(t=>t===e?n:i.includes(t));r.length!==0&&t(r)};return(0,I.jsx)(sw,{label:`iOS app environment`,hint:n?void 0:`Which of Apple's two environments this app accepts attestations from. Removing one also stops the keys it already registered.`,children:(0,I.jsxs)(`div`,{className:`space-y-2`,children:[_E.map(e=>{let t=i.includes(e.value);return(0,I.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,I.jsx)(gE,{id:`env-${e.value}`,checked:t,disabled:r||t&&i.length===1,onCheckedChange:t=>o(e.value,t===!0)}),(0,I.jsxs)(`div`,{className:`-mt-0.5`,children:[(0,I.jsx)(ow,{htmlFor:`env-${e.value}`,className:`text-sm font-normal`,children:e.label}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.hint})]})]},e.value)}),a&&!n?(0,I.jsxs)(`p`,{className:`flex items-start gap-2 rounded-md bg-amber-500/[0.08] p-2.5 text-xs leading-relaxed text-amber-700 dark:text-amber-400`,children:[(0,I.jsx)(Ka,{className:`mt-0.5 size-3.5 shrink-0`}),(0,I.jsx)(`span`,{children:`Any device carrying your team's provisioning profile can attest against this app. Keep this on a development bundle id rather than the one you ship.`})]}):null]})})}function yE({label:e,choices:t,value:n,disabled:r=!1,describedBy:i,onChange:a}){return(0,I.jsx)(`div`,{role:`radiogroup`,"aria-label":e,"aria-describedby":i,className:`space-y-1`,children:t.map(e=>{let t=e.value===n;return(0,I.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":t,disabled:r,onClick:()=>a(e.value),className:H(`flex w-full items-start gap-3.5 rounded-lg px-3 py-3 text-left transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,r?`cursor-not-allowed opacity-60`:`hover:bg-muted/50`),children:[(0,I.jsx)(`span`,{"aria-hidden":`true`,className:H(`mt-0.5 flex size-4.5 shrink-0 items-center justify-center rounded-full border transition-colors`,t?`border-primary`:`border-muted-foreground/50`),children:t?(0,I.jsx)(`span`,{className:`size-2.5 rounded-full bg-primary`}):null}),(0,I.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`span`,{className:`block text-sm font-medium`,children:e.label}),(0,I.jsx)(`span`,{className:`mt-0.5 block text-sm text-muted-foreground`,children:e.description})]})]},e.value)})})}function bE({href:e,children:t}){return(0,I.jsxs)(`a`,{href:e,target:`_blank`,rel:`noreferrer noopener`,className:`inline-flex items-center gap-0.5 underline decoration-border underline-offset-4 transition-colors hover:text-foreground hover:decoration-foreground`,children:[t,(0,I.jsx)(va,{className:`size-3`})]})}function xE({label:e,presets:t,selected:n,values:r,onSelect:i,onValueChange:a,idPrefix:o,compact:s=!1,disabled:c=!1}){let l=!s&&`warning`in n?n.warning:void 0,u=!s&&`note`in n?n.note:void 0,d=`docs`in n?n.docs:void 0,f=n.vendor??n.label;return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`${o}-preset`,children:e}),(0,I.jsxs)(zT,{value:n.id,disabled:c,onValueChange:e=>{let n=t.find(t=>t.id===e);n&&i(n)},children:[(0,I.jsx)(VT,{id:`${o}-preset`,className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:t.map(e=>(0,I.jsx)(UT,{value:e.id,children:(0,I.jsx)(SE,{preset:e})},e.id))})]}),n.description?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n.description}):null]}),n.inputs.map(e=>(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`${o}-${e.key}`,children:e.label}),(0,I.jsx)($,{id:`${o}-${e.key}`,value:r[e.key]??``,placeholder:e.placeholder,className:`font-mono text-xs`,disabled:c,onChange:t=>a(e.key,t.target.value)}),e.hint||e.docs?(0,I.jsxs)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:[e.hint,e.docs?(0,I.jsxs)(I.Fragment,{children:[e.hint?` `:null,(0,I.jsx)(bE,{href:e.docs.href,children:e.docs.label})]}):null]}):null]},e.key)),l?(0,I.jsxs)(`div`,{className:`flex gap-2 rounded-md border border-amber-500/40 bg-amber-500/10 p-3 text-xs leading-relaxed text-amber-700 dark:text-amber-400`,children:[(0,I.jsx)(Ka,{className:`mt-0.5 size-3.5 shrink-0`}),(0,I.jsx)(`span`,{children:l})]}):null,u?(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:u}):null,d?(0,I.jsxs)(`a`,{href:d,target:`_blank`,rel:`noreferrer noopener`,className:`inline-flex items-center gap-1 text-xs text-muted-foreground underline underline-offset-4 hover:text-foreground`,children:[f,` documentation`,(0,I.jsx)(va,{className:`size-3`})]}):null]})}function SE({preset:e,className:t}){return(0,I.jsxs)(`span`,{className:H(`inline-flex items-center gap-1.5`,t),children:[AT(e.id)?(0,I.jsx)(PT,{type:e.id}):null,e.id===`custom`?(0,I.jsx)(ea,{"aria-hidden":!0,className:`size-[1.15em] shrink-0 text-current`,strokeWidth:1.8}):null,e.label]})}var CE=e=>e.replace(/^https?:\/\//u,``).replace(/\/+$/u,``);function wE(e,t){return Object.fromEntries(e.inputs.map(e=>[e.key,(t[e.key]??``).trim()]))}var TE=(e,t)=>e.build(wE(e,t)),EE=(e,t)=>e.build(wE(e,t)),DE=[{id:`firebase`,label:`Firebase Authentication`,vendor:`Firebase`,description:`Google-signed ID tokens. Scoped to your project by the aud and iss claims.`,inputs:[{key:`project_id`,label:`Firebase project id`,placeholder:`my-app-1a2b3`,hint:`Found in Project settings. Not the project number.`}],warning:`Firebase signs every project's tokens with one shared key set, so the JWKS URL alone identifies nobody. The issuer and audience below are what scope this app to your project — without them the gateway would accept a token from any Firebase project in the world.`,docs:`https://firebase.google.com/docs/auth/admin/verify-id-tokens`,build:({project_id:e})=>({jwks_url:`https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com`,issuer:`https://securetoken.google.com/${e}`,audience:e,user_id_claim:`sub`,required_claims:[]}),read:({audience:e})=>({project_id:e})},{id:`supabase`,label:`Supabase Auth`,vendor:`Supabase`,description:`Per-project JWKS. Requires asymmetric signing keys.`,inputs:[{key:`project_ref`,label:`Project ref`,placeholder:`abcdefghijklmnop`,hint:`The subdomain of your project URL: https://<ref>.supabase.co`}],warning:`Only projects migrated to asymmetric JWT signing keys can be verified. A legacy HS256 project publishes no public keys, so its JWKS endpoint returns an empty set and every token is rejected.`,docs:`https://supabase.com/docs/guides/auth/signing-keys`,build:({project_ref:e})=>{let t=CE(e).replace(/\.supabase\.co$/u,``);return{jwks_url:`https://${t}.supabase.co/auth/v1/.well-known/jwks.json`,issuer:`https://${t}.supabase.co/auth/v1`,audience:`authenticated`,user_id_claim:`sub`,required_claims:[]}},read:({issuer:e})=>({project_ref:CE(e).replace(/\.supabase\.co\/auth\/v1$/u,``)})},{id:`auth0`,label:`Auth0`,vendor:`Auth0`,description:`Per-tenant JWKS, with the API identifier as the audience.`,inputs:[{key:`domain`,label:`Tenant domain`,placeholder:`my-tenant.us.auth0.com`,hint:`Your Auth0 domain or custom domain, without https://`},{key:`audience`,label:`API identifier`,placeholder:`https://api.my-app.com`,hint:`The Identifier of the API you registered in Auth0. It is not a URL that has to resolve.`}],warning:`Auth0 puts a trailing slash in the iss claim. The preset writes it for you; do not remove it or every token is rejected.`,docs:`https://auth0.com/docs/secure/tokens/access-tokens/validate-access-tokens`,build:({domain:e,audience:t})=>{let n=CE(e);return{jwks_url:`https://${n}/.well-known/jwks.json`,issuer:`https://${n}/`,audience:t,user_id_claim:`sub`,required_claims:[]}},read:({issuer:e,audience:t})=>({domain:CE(e),audience:t})},{id:`clerk`,label:`Clerk`,vendor:`Clerk`,description:`Session tokens verified against your Frontend API JWKS.`,inputs:[{key:`frontend_api`,label:`Frontend API host`,placeholder:`clean-mayfly-62.clerk.accounts.dev`,hint:`Your Clerk Frontend API URL or custom domain, without https://`},{key:`audience`,label:`Audience`,placeholder:`my-app`,hint:`The aud your Clerk JWT template sets. Clerk's default session token has none — add one in the template, because the gateway requires it.`}],warning:`Clerk's own guidance also checks the azp claim against your permitted origins. This gateway serves native apps, where there is no origin to bind to, so the preset omits it — add an azp requirement manually if your tokens carry one.`,docs:`https://clerk.com/docs/guides/sessions/manual-jwt-verification`,build:({frontend_api:e,audience:t})=>{let n=CE(e);return{jwks_url:`https://${n}/.well-known/jwks.json`,issuer:`https://${n}`,audience:t,user_id_claim:`sub`,required_claims:[]}},read:({issuer:e,audience:t})=>({frontend_api:CE(e),audience:t})},{id:`custom`,label:`Custom issuer`,description:`Any issuer publishing a JWKS document over HTTPS.`,inputs:[{key:`jwks_url`,label:`JWKS URL`,placeholder:`https://issuer.example.com/.well-known/jwks.json`,hint:`If this issuer signs tokens for more than one service, add a claim requirement under Subscription check too.`},{key:`issuer`,label:`Issuer (iss)`,placeholder:`https://issuer.example.com`,hint:`Exactly the iss claim your tokens carry, trailing slash included.`},{key:`audience`,label:`Audience (aud)`,placeholder:`https://api.my-app.com`,hint:`Exactly one aud value your tokens carry.`}],build:({jwks_url:e,issuer:t,audience:n})=>({jwks_url:e,issuer:t,audience:n,user_id_claim:`sub`,required_claims:[]}),read:e=>({...e})}],OE=DE.find(e=>e.id===`custom`),kE=e=>DE.find(t=>t.id===e)??OE;function AE(e){let t=e=>Array.isArray(e)?e[0]??``:e??``;return{jwks_url:e.jwks_url??``,issuer:t(e.issuer),audience:t(e.audience)}}function jE(e){let t=AE(e);if(e.provider){let n=kE(e.provider);return{preset:n,values:n.read(t)}}let n={preset:OE,values:{...t}},r=e=>Array.isArray(e)&&e.length>1;if(r(e.issuer)||r(e.audience))return n;for(let e of DE){if(e===OE)continue;let n=e.read(t);if(!LE(e,n))continue;let r=TE(e,n);if(r.jwks_url===t.jwks_url&&r.issuer===t.issuer&&r.audience===t.audience)return{preset:e,values:n}}return n}var ME=`revenueCatEntitlements`;function NE(e){let t=e.split(`,`).map(e=>e.trim());return{path:ME,contains:t.length>1?t:e}}function PE(e){if(e.length===0)return``;let[t,...n]=e;return!t||n.length>0||t.contains===void 0?null:Array.isArray(t.contains)?t.contains.join(`, `):t.contains}var FE=`Which claim says the user has paid`,IE=[{id:`none`,label:`No entitlement check`,description:`Any user the issuer signs a token for may call the gateway.`,inputs:[],build:()=>[]},{id:`revenuecat`,label:`RevenueCat entitlement`,vendor:`RevenueCat`,inputs:[{key:`entitlement`,label:`Entitlement identifier`,placeholder:`pro`,hint:`In RevenueCat, under Product catalog → Entitlements: the identifier, not the display name. Several, comma separated, admit a user carrying any one of them.`,docs:{href:`https://www.revenuecat.com/docs/getting-started/entitlements`,label:`RevenueCat documentation`}}],build:({entitlement:e})=>e?[NE(e)]:[]},{id:`custom`,label:`Custom claim`,description:`Any single claim requirement. More can be added under Subscription check.`,inputs:[{key:`path`,label:`Claim path`,placeholder:`scope`},{key:`value`,label:`Required value`,placeholder:`ai.invoke`}],build:({path:e,value:t})=>e&&t?[{path:e,contains:t}]:[]}],LE=(e,t)=>e.inputs.every(e=>(t[e.key]??``).trim().length>0);function RE({issuer:e,disabled:t=!1,onChange:n}){let{preset:r,values:i}=jE(e),a=(t,r)=>{let i=TE(t,r);n({provider:t.id,jwks_url:i.jwks_url,issuer:i.issuer,audience:i.audience,user_id_claim:e.user_id_claim??i.user_id_claim})};return(0,I.jsx)(xE,{idPrefix:`issuer`,label:`Identity provider`,presets:DE,selected:r,values:i,compact:!0,disabled:t,onSelect:e=>a(e,{}),onValueChange:(e,t)=>a(r,{...i,[e]:t})})}function zE({claims:e,disabled:t=!1,onChange:n}){let r=(t,r)=>n(e.map((e,n)=>n===t?{...e,...r}:e));return(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Claims the sign-in token must carry. Dot paths; contains matches arrays and space-delimited scopes, equals compares exactly.`}),(0,I.jsxs)(J,{variant:`outline`,size:`sm`,disabled:t,onClick:()=>n([...e,{path:``,contains:``}]),children:[(0,I.jsx)(Na,{className:`size-3.5`}),`Add claim`]})]}),e.length===0?(0,I.jsx)(uw,{children:`No claim requirements.`}):e.map((i,a)=>{let o=i.equals===void 0?`contains`:`equals`;return(0,I.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,I.jsxs)(`div`,{className:`min-w-[180px] flex-1`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Path`}),(0,I.jsx)($,{value:i.path,placeholder:`claims.entitlements`,className:`font-mono text-xs`,disabled:t,onChange:e=>r(a,{path:e.target.value})})]}),(0,I.jsxs)(`div`,{className:`w-[140px]`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Match`}),(0,I.jsxs)(zT,{value:o,disabled:t,onValueChange:t=>n(e.map((e,n)=>n===a?t===`equals`?{path:e.path,equals:Array.isArray(e.contains)?e.contains[0]??``:e.contains??``}:{path:e.path,contains:String(e.equals??``)}:e)),children:[(0,I.jsx)(VT,{className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsxs)(HT,{children:[(0,I.jsx)(UT,{value:`contains`,children:`contains`}),(0,I.jsx)(UT,{value:`equals`,children:`equals`})]})]})]}),(0,I.jsxs)(`div`,{className:`min-w-[180px] flex-1`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Value`}),(0,I.jsx)($,{value:o===`contains`&&Array.isArray(i.contains)?i.contains.join(`, `):String(i.equals??i.contains??``),placeholder:o===`contains`?`pro, pro_test`:`pro`,className:`font-mono text-xs`,disabled:t,onChange:e=>{if(o===`equals`){r(a,{equals:e.target.value});return}let t=e.target.value.split(`,`).map(e=>e.trim());r(a,{contains:t.length>1?t:e.target.value})}})]}),(0,I.jsx)(J,{variant:`ghost`,size:`icon`,"aria-label":`Remove claim`,disabled:t,onClick:()=>n(e.filter((e,t)=>t!==a)),children:(0,I.jsx)(Ga,{className:`size-4`})})]},a)})]})}var BE=IE.filter(e=>e.id!==`none`),VE=NE(``);function HE({issuer:e,disabled:t=!1,onChange:n}){let r=e.required_claims??[],i=PE(r),a=(e.entitlement??(r[0]?.path===`revenueCatEntitlements`?`revenuecat`:`custom`))===`revenuecat`&&i!==null?`revenuecat`:`custom`,o=BE.find(e=>e.id===a)??BE[0],s=e=>{e!==a&&n({entitlement:e,required_claims:e===`revenuecat`?[NE(i??``)]:r})};return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`entitlement-check`,children:FE}),(0,I.jsxs)(zT,{value:a,disabled:t,onValueChange:e=>s(e),children:[(0,I.jsx)(VT,{id:`entitlement-check`,className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:BE.map(e=>(0,I.jsx)(UT,{value:e.id,children:(0,I.jsx)(SE,{preset:e})},e.id))})]}),o.description?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o.description}):null]}),a===`revenuecat`?(0,I.jsx)(UE,{input:o.inputs[0],entitlement:i??``,disabled:t,onChange:e=>n({required_claims:[NE(e)]})}):(0,I.jsx)(zE,{claims:r,disabled:t,onChange:e=>n({required_claims:e})})]})}function UE({input:e,entitlement:t,disabled:n,onChange:r}){return(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`entitlement-value`,children:e.label}),(0,I.jsx)($,{id:`entitlement-value`,value:t,placeholder:e.placeholder,className:`max-w-[320px] font-mono text-xs`,disabled:n,onChange:e=>r(e.target.value)}),(0,I.jsxs)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:[e.hint,e.docs?(0,I.jsxs)(I.Fragment,{children:[` `,(0,I.jsx)(bE,{href:e.docs.href,children:e.docs.label})]}):null]})]})}var WE=[{value:`issuer`,label:`Signed-in users only`,description:`Users sign in through your identity provider, and the gateway verifies it.`},{value:`app_install`,label:`Unauthenticated users`,description:`Anyone with your app can call. Each installation counts as one user.`}],GE=[{value:`issuer`,label:`Signed-in users only`,description:`Your backend forwards each user's sign-in token, and the gateway verifies it.`},{value:`header`,label:`Your backend sends the user id`,description:`In the ${iT} header on every request.`},{value:`none`,label:`No user identity`,description:`Requests are not linked to any user.`}];function KE({...e}){return(0,I.jsx)(Yd,{"data-slot":`dialog`,...e})}function qE({...e}){return(0,I.jsx)(Zd,{"data-slot":`dialog-trigger`,...e})}function JE({...e}){return(0,I.jsx)(tf,{"data-slot":`dialog-portal`,...e})}function YE({className:e,...t}){return(0,I.jsx)(rf,{"data-slot":`dialog-overlay`,className:H(`fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`,e),...t})}function XE({className:e,children:t,showCloseButton:n=!0,dismissOnOutsideInteraction:r=!1,onInteractOutside:i,...a}){return(0,I.jsxs)(JE,{"data-slot":`dialog-portal`,children:[(0,I.jsx)(YE,{}),(0,I.jsxs)(cf,{"data-slot":`dialog-content`,className:H(`fixed top-[50%] left-[50%] z-50 flex max-h-[calc(100dvh-4rem)] w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] flex-col overflow-hidden rounded-lg border bg-background shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg`,n&&`[&_[data-slot=dialog-header]]:pr-14`,e),onInteractOutside:e=>{i?.(e),r||e.preventDefault()},...a,children:[t,n&&(0,I.jsxs)(_f,{"data-slot":`dialog-close`,className:`absolute top-5 right-4 inline-flex size-8 items-center justify-center rounded-md text-muted-foreground opacity-70 ring-offset-background transition-[opacity,background-color,color] hover:bg-muted hover:text-foreground hover:opacity-100 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,children:[(0,I.jsx)(Ya,{}),(0,I.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function ZE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`dialog-header`,className:H(`flex shrink-0 flex-col gap-2 border-b p-6 text-center sm:text-left`,e),...t})}function QE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`dialog-body`,className:H(`min-h-0 flex-1 overflow-y-auto px-6 py-5`,e),...t})}function $E({className:e,showCloseButton:t=!1,children:n,...r}){return(0,I.jsxs)(`div`,{"data-slot":`dialog-footer`,className:H(`flex shrink-0 flex-col-reverse gap-2 border-t px-6 py-4 sm:flex-row sm:justify-end`,e),...r,children:[n,t&&(0,I.jsx)(_f,{asChild:!0,children:(0,I.jsx)(J,{variant:`outline`,children:`Close`})})]})}function eD({className:e,...t}){return(0,I.jsx)(pf,{"data-slot":`dialog-title`,className:H(`text-lg leading-6 font-semibold`,e),...t})}function tD({className:e,...t}){return(0,I.jsx)(hf,{"data-slot":`dialog-description`,className:H(`text-sm text-muted-foreground`,e),...t})}function nD({open:e,onOpenChange:t,title:n,description:r,submitLabel:i,pending:a,disabled:o,onSubmit:s,secondaryAction:c,className:l,children:u}){let{readOnly:d}=sx(),f=d||o||a;return(0,I.jsx)(KE,{open:e,onOpenChange:t,children:(0,I.jsx)(XE,{className:l??`sm:max-w-md`,...r?{}:{"aria-describedby":void 0},children:(0,I.jsxs)(`form`,{className:`flex min-h-0 flex-1 flex-col`,autoComplete:`off`,onSubmit:e=>{e.preventDefault(),!f&&s()},children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{className:`text-balance`,children:n})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[r?(0,I.jsx)(tD,{className:`text-pretty`,children:r}):null,u]}),(0,I.jsxs)($E,{children:[c,(0,I.jsx)(J,{type:`button`,variant:`outline`,onClick:()=>t(!1),children:`Cancel`}),(0,I.jsxs)(iw,{type:`submit`,disabled:o||a,children:[a?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,i]})]})]})})})}function rD({open:e,title:t,description:n,label:r,secret:i,acknowledgeLabel:a=`I’ve saved this key`,footnote:o,onAcknowledge:s}){let[c,l]=(0,v.useState)(!1),u=async()=>{try{await navigator.clipboard.writeText(i),l(!0),U.success(`Copied to clipboard`)}catch{U.error(`Could not copy. Select the value and copy it manually.`)}},d=()=>{l(!1),s()};return(0,I.jsx)(KE,{open:e,onOpenChange:e=>{e||d()},children:(0,I.jsxs)(XE,{showCloseButton:!1,className:`sm:max-w-lg`,onEscapeKeyDown:e=>e.preventDefault(),children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{className:`text-balance`,children:t})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[(0,I.jsx)(tD,{className:`text-pretty`,children:n}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`revealed-secret`,children:r}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)($,{id:`revealed-secret`,value:i,readOnly:!0,className:`font-mono text-xs`,onFocus:e=>e.currentTarget.select()}),(0,I.jsxs)(J,{type:`button`,variant:`outline`,className:`min-w-24`,onClick:()=>void u(),children:[c?(0,I.jsx)(ra,{className:`size-4`}):(0,I.jsx)(ha,{className:`size-4`}),c?`Copied`:`Copy`]})]}),o?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o}):null]})]}),(0,I.jsx)($E,{children:(0,I.jsx)(J,{onClick:d,children:a})})]})})}function iD({appId:e,exchanged:t=!1,title:n=`Server API keys`,description:r}){let i=IS(e),a=LS(e),o=RS(e),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(null),p=async()=>{if(l.trim())try{let e=await a.mutateAsync(l.trim());c(!1),u(``),f(e)}catch(e){U.error(e instanceof Error?e.message:`Could not create the API key`)}},m=async e=>{try{await o.mutateAsync(e),U.success(`API key revoked`)}catch(e){U.error(e instanceof Error?e.message:`Could not revoke the API key`)}};return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:n,description:r,action:(0,I.jsxs)(iw,{size:`sm`,onClick:()=>{u(``),c(!0)},children:[(0,I.jsx)(Na,{className:`size-4`}),`New key`]})})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[t?null:(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Your backend sends one of these keys as an Authorization bearer credential. Revoking takes effect within a minute.`}),(0,I.jsx)(`div`,{className:`overflow-hidden rounded-md border`,children:(0,I.jsxs)(sE,{className:`[--table-inset:1rem]`,children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{children:[(0,I.jsx)(Z,{children:`Name`}),(0,I.jsx)(Z,{children:`Prefix`}),(0,I.jsx)(Z,{children:`Last used`}),(0,I.jsx)(Z,{children:`Status`}),(0,I.jsx)(Z,{className:`w-24`})]})}),(0,I.jsx)(lE,{children:i.data?.keys.length?i.data.keys.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{children:e.name}),(0,I.jsxs)(Q,{className:`font-mono text-xs`,children:[e.key_prefix,`…`]}),(0,I.jsx)(Q,{className:`text-xs text-muted-foreground`,children:hC(e.last_used_at)}),(0,I.jsx)(Q,{children:(0,I.jsx)(Lb,{variant:e.status===`active`?`secondary`:`outline`,children:e.status})}),(0,I.jsx)(Q,{className:`text-right`,children:(0,I.jsxs)(iw,{variant:`ghost`,size:`sm`,className:`text-destructive`,disabled:e.status===`revoked`||o.isPending,onClick:()=>void m(e.id),children:[(0,I.jsx)(Va,{className:`size-3.5`}),`Revoke`]})})]},e.id)):(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:5,className:`py-8 text-center text-sm text-muted-foreground`,children:`No API keys yet.`})})})]})})]})]}),(0,I.jsx)(nD,{open:s,onOpenChange:c,title:`Create an API key`,submitLabel:`Create key`,pending:a.isPending,disabled:!l.trim(),onSubmit:()=>void p(),children:(0,I.jsx)(sw,{label:`Key name`,htmlFor:`api-key-name`,hint:`Name it so you can tell keys apart in the list.`,children:(0,I.jsx)($,{id:`api-key-name`,value:l,placeholder:`Production Worker`,maxLength:100,autoFocus:!0,autoComplete:`off`,onChange:e=>u(e.target.value)})})}),(0,I.jsx)(rD,{open:d!==null,title:`Copy your new key now`,description:(0,I.jsxs)(I.Fragment,{children:[`This is the only time the plaintext for`,` `,(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:d?.name}),` is available — you will not see it again. The gateway stores only a hash.`]}),label:`API key`,secret:d?.key??``,onAcknowledge:()=>{f(null),a.reset()}})]})}var aD=`identity`,oD=[{slug:`identity`,label:`Application identity`},{slug:`users`,label:`User authentication`},{slug:`subscription`,label:`Subscription check`}],sD={secure:{icon:la,className:`text-emerald-600 dark:text-emerald-400`},weak:{icon:za,className:`text-amber-600 dark:text-amber-400`},incomplete:{icon:ca,className:`text-destructive`},off:{icon:ua,className:`text-muted-foreground/60`}},cD=[{value:`paid`,label:`Paid users only`,description:`The sign-in token must carry a claim that says the user has paid.`},{value:`any`,label:`Any signed-in user`,description:`Signing in is enough. Nothing about payment is checked.`}],lD=e=>(e.required_claims??[]).length>0||e.entitlement!==void 0?`paid`:`any`;function uD(e,t){let n=e.config.authentication,r=lT(n);return{identity:n.type===`apple_app_attest`?!n.app_attest.team_id.trim()||!n.app_attest.bundle_id.trim()?{tone:`incomplete`,text:`Team or bundle id missing`}:{tone:`secure`,text:`Verified with App Attest`}:t===!1?{tone:`incomplete`,text:`No active API key`}:{tone:`secure`,text:`Verified with API keys`},users:(()=>{switch(n.end_user?.source??`none`){case`issuer`:return r&&$T(r)?{tone:`secure`,text:`Signed-in users only`}:{tone:`incomplete`,text:`Identity provider not finished`};case`header`:return n.type===`api_key`&&n.end_user?.source===`header`&&!n.end_user.header.trim()?{tone:`incomplete`,text:`Header name missing`}:{tone:`weak`,text:`Your backend names the user`};case`app_install`:return{tone:`weak`,text:`Unauthenticated users allowed`};default:return{tone:`weak`,text:`No user identity`}}})(),subscription:r?lD(r)===`paid`?(r.required_claims??[]).every(eE)&&(r.required_claims??[]).length>0?{tone:`secure`,text:`Paid users only`}:{tone:`incomplete`,text:`Paid check not finished`}:{tone:`weak`,text:`Any signed-in user`}:{tone:`off`,text:`Needs signed-in users`}}}function dD({appId:e,level:t,state:n}){let r=n.draft,i=r.config.authentication,{readOnly:a}=sx(),o=IS(e,i.type===`api_key`),s=uD(r,o.data?o.data.keys.some(e=>e.status===`active`):void 0),c=oD.some(e=>e.slug===t)&&s[t].tone!==`off`?t:aD;return(0,I.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[16rem_minmax(0,1fr)]`,children:[(0,I.jsx)(`nav`,{"aria-label":`Auth policy levels`,className:`flex flex-col gap-1 lg:sticky lg:top-6 lg:self-start`,children:oD.map(t=>(0,I.jsx)(fD,{to:`/apps/${e}/auth/${t.slug}`,label:t.label,status:s[t.slug],current:t.slug===c},t.slug))}),(0,I.jsx)(`div`,{className:`min-w-0 space-y-4`,children:c===`identity`?i.type===`apple_app_attest`?(0,I.jsx)(pD,{authentication:i,readOnly:a,state:n}):(0,I.jsx)(iD,{appId:e,exchanged:lT(i)!==void 0,title:`Application identity`,description:`A server application. Your backend proves itself with one of these API keys.`}):c===`users`?(0,I.jsx)(mD,{authentication:i,readOnly:a,state:n}):(0,I.jsx)(hD,{issuer:lT(i)??uT(),readOnly:a,state:n})})]})}function fD({to:e,label:t,status:n,current:r}){let{icon:i,className:a}=sD[n.tone],o=(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(i,{className:H(`mt-0.5 size-4 shrink-0`,a),"aria-hidden":`true`}),(0,I.jsxs)(`span`,{className:`min-w-0`,children:[(0,I.jsx)(`span`,{className:`block text-sm font-medium`,children:t}),(0,I.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:n.text})]})]}),s=`flex items-start gap-3 rounded-lg px-3 py-2.5 text-left transition-colors`;return n.tone===`off`?(0,I.jsx)(`div`,{"aria-disabled":`true`,className:H(s,`opacity-60`),children:o}):(0,I.jsx)(Pn,{to:e,"aria-current":r?`page`:void 0,className:H(s,`outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50`,r?`bg-muted`:`hover:bg-muted/60`),children:o})}function pD({authentication:e,readOnly:t,state:n}){let r=e.app_attest,i=t=>n.updateAuthentication({...e,app_attest:{...r,...t}});return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Application identity`,description:`An iOS application. Only builds signed with this team and bundle id can call AI providers through this gateway.`})}),(0,I.jsxs)(oE,{className:`space-y-6`,children:[(0,I.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,I.jsx)(ow,{htmlFor:`apple-team-id`,children:`Apple Team ID`}),(0,I.jsx)($,{id:`apple-team-id`,value:r.team_id,placeholder:`ABCDE12345`,className:`font-mono text-xs`,disabled:t,onChange:e=>i({team_id:e.target.value})}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`In your Apple Developer account under`,` `,(0,I.jsx)(bE,{href:`https://developer.apple.com/account#MembershipDetailsCard`,children:`Membership details`}),`.`]})]}),(0,I.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,I.jsx)(ow,{htmlFor:`apple-bundle-id`,children:`Bundle ID`}),(0,I.jsx)($,{id:`apple-bundle-id`,value:r.bundle_id,placeholder:`com.example.app`,className:`font-mono text-xs`,disabled:t,onChange:e=>i({bundle_id:e.target.value})}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`In Xcode, on your target's`,` `,(0,I.jsx)(bE,{href:`https://developer.apple.com/documentation/xcode/configuring-the-build-settings-of-a-target#Set-the-bundle-ID`,children:`Signing & Capabilities`}),` `,`tab.`]})]})]}),(0,I.jsx)(vE,{value:r.environments,compact:!0,disabled:t,onChange:t=>n.updateAuthentication({...e,app_attest:{team_id:r.team_id,bundle_id:r.bundle_id,...t.length===1&&t[0]===`production`?{}:{environments:t}}})})]})]})}function mD({authentication:e,readOnly:t,state:n}){let r=(0,v.useId)(),i=e.end_user?.source??`none`,a=lT(e),o=e.type===`api_key`?GE:WE;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`User authentication`,description:`Choose whether only users signed in to your app can call AI through this gateway.`})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[t?(0,I.jsx)(rw,{reason:rx,reasonId:r,className:`w-full`,children:(0,I.jsx)(yE,{label:`User authentication`,choices:o,value:i,disabled:!0,describedBy:r,onChange:()=>{}})}):(0,I.jsx)(yE,{label:`User authentication`,choices:o,value:i,onChange:e=>n.setEndUserSource(e===`none`?void 0:e)}),e.type===`api_key`&&e.end_user?.source===`header`?(0,I.jsx)(sw,{label:`Header name`,htmlFor:`end-user-header`,hint:`Lowercased, and removed before the request reaches the provider. Defaults to ${iT}.`,children:(0,I.jsx)($,{id:`end-user-header`,value:e.end_user.header,placeholder:iT,className:`max-w-[320px] font-mono text-xs`,disabled:t,onChange:e=>n.updateEndUserHeader(e.target.value)})}):null]})]}),i===`issuer`?(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Identity provider`,description:`Where your users sign in. The gateway verifies their sign-in tokens against it.`})}),(0,I.jsx)(oE,{children:(0,I.jsx)(RE,{issuer:a??uT(),disabled:t,onChange:n.updateIssuer})})]}):null]})}function hD({issuer:e,readOnly:t,state:n}){let r=(0,v.useId)(),i=lD(e);return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Subscription check`,description:`Check that the user has paid for the app before they can call AI providers through this gateway.`})}),(0,I.jsxs)(oE,{className:`space-y-6`,children:[t?(0,I.jsx)(rw,{reason:rx,reasonId:r,className:`w-full`,children:(0,I.jsx)(yE,{label:`Subscription check`,choices:cD,value:i,disabled:!0,describedBy:r,onChange:()=>{}})}):(0,I.jsx)(yE,{label:`Subscription check`,choices:cD,value:i,onChange:e=>{e!==i&&n.updateIssuer(e===`any`?{entitlement:void 0,required_claims:[]}:{entitlement:`revenuecat`,required_claims:[VE]})}}),i===`paid`?(0,I.jsx)(`div`,{className:`border-t pt-6`,children:(0,I.jsx)(HE,{issuer:e,disabled:t,onChange:n.updateIssuer})}):null]})]})}var gD={requests:{per_minute:null,per_day:null},spending:{monthly_usd:null}},_D={per_user:gD,per_app:gD},vD=e=>e===``?null:Number(e);function yD({state:e}){let t=e.draft,n=t.config.limits??_D,r=t.config.authentication.type!==`api_key`||t.config.authentication.end_user!==void 0,i=(t,r)=>e.updateLimits({...n,[t]:{...n[t],...r}});return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`p`,{className:`text-sm leading-relaxed text-muted-foreground`,children:[`Limits you set on `,(0,I.jsx)(`strong`,{className:`font-medium text-foreground`,children:`your app's end users`}),`. They are unrelated to your own`,` `,(0,I.jsx)(Pn,{to:`/billing`,className:`text-primary-ink underline underline-offset-4`,children:`plan allowance`}),`, which meters all your apps together: a request refused here never spends it. Edits take up to a minute to apply everywhere.`]}),(0,I.jsxs)(`div`,{className:r?`grid gap-4 lg:grid-cols-2`:`grid gap-4`,children:[r?(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(iE,{className:`text-sm`,children:`Per-user limits`})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Applied independently to every authenticated user. Rate limits return`,` `,(0,I.jsx)(`code`,{className:`font-mono`,children:`app_rate_limited`}),`; exhausting the monthly spend returns `,(0,I.jsx)(`code`,{className:`font-mono`,children:`app_budget_exhausted`}),`.`]}),(0,I.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,I.jsx)(sw,{label:`Requests per minute`,htmlFor:`rpm`,hint:`Leave empty for unlimited.`,children:(0,I.jsx)($,{id:`rpm`,type:`number`,min:1,value:n.per_user.requests.per_minute??``,placeholder:`Unlimited`,onChange:e=>i(`per_user`,{requests:{...n.per_user.requests,per_minute:vD(e.target.value)}})})}),(0,I.jsx)(sw,{label:`Requests per day`,htmlFor:`rpd`,hint:`Leave empty for unlimited.`,children:(0,I.jsx)($,{id:`rpd`,type:`number`,min:1,value:n.per_user.requests.per_day??``,placeholder:`Unlimited`,onChange:e=>i(`per_user`,{requests:{...n.per_user.requests,per_day:vD(e.target.value)}})})})]}),(0,I.jsx)(`div`,{className:`border-t pt-4`,children:(0,I.jsx)(sw,{label:`Monthly spending budget (USD)`,htmlFor:`budget`,hint:n.per_user.spending.monthly_usd===null?`Unlimited`:`${dC(n.per_user.spending.monthly_usd)} per user per month. Settled from completed requests, so it stops the request after the one that crosses it.`,children:(0,I.jsx)($,{id:`budget`,type:`number`,min:0,step:`0.01`,value:n.per_user.spending.monthly_usd??``,placeholder:`Unlimited`,onChange:e=>i(`per_user`,{spending:{monthly_usd:vD(e.target.value)}})})})})]})]}):(0,I.jsx)(nE,{children:(0,I.jsx)(oE,{className:`pt-6`,children:(0,I.jsx)(uw,{children:`This application identifies no end users, so there is nobody for a per-user limit to apply to. Choose a user authentication method on the Auth policy tab to set them, or use the application limits below.`})})}),(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(iE,{className:`text-sm`,children:`Application limits`})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Shared across all users and credentials for this application. Leave a field empty to keep that application-wide limit unrestricted.`}),(0,I.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,I.jsx)(sw,{label:`Requests per minute`,htmlFor:`app-rpm`,hint:`Leave empty for unlimited.`,children:(0,I.jsx)($,{id:`app-rpm`,type:`number`,min:1,value:n.per_app.requests.per_minute??``,placeholder:`Unlimited`,onChange:e=>i(`per_app`,{requests:{...n.per_app.requests,per_minute:vD(e.target.value)}})})}),(0,I.jsx)(sw,{label:`Requests per day`,htmlFor:`app-rpd`,hint:`Leave empty for unlimited.`,children:(0,I.jsx)($,{id:`app-rpd`,type:`number`,min:1,value:n.per_app.requests.per_day??``,placeholder:`Unlimited`,onChange:e=>i(`per_app`,{requests:{...n.per_app.requests,per_day:vD(e.target.value)}})})})]}),(0,I.jsx)(`div`,{className:`border-t pt-4`,children:(0,I.jsx)(sw,{label:`Monthly spending budget (USD)`,htmlFor:`app-budget`,hint:n.per_app.spending.monthly_usd===null?`Unlimited`:`${dC(n.per_app.spending.monthly_usd)} per application per month. Settled from completed requests, so it stops the request after the one that crosses it.`,children:(0,I.jsx)($,{id:`app-budget`,type:`number`,min:0,step:`0.01`,value:n.per_app.spending.monthly_usd??``,placeholder:`Unlimited`,onChange:e=>i(`per_app`,{spending:{monthly_usd:vD(e.target.value)}})})})})]})]})]})]})}function bD(e){return e?.apiBaseUrl??window.location.origin}function xD({appId:e,month:t,state:n}){let{capabilities:r}=sx(),i=VS(e,t),a=zS(e,{month:t,limit:1}),o=n.draft.config.authentication,s=(i.data?.input_tokens??0)+(i.data?.cached_input_tokens??0)+(i.data?.cache_write_tokens??0)+(i.data?.output_tokens??0),c=lT(o);return(0,I.jsxs)(`div`,{className:`space-y-6`,children:[o.type===`api_key`?(0,I.jsx)(SD,{appId:e}):null,(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,I.jsx)(dE,{label:`Spend`,value:i.isPending?(0,I.jsx)(aw,{className:`h-6 w-20`}):dC(i.data?.cost_usd??0),detail:`month to date`}),(0,I.jsx)(dE,{label:`Users`,value:a.isPending?(0,I.jsx)(aw,{className:`h-6 w-12`}):cC(a.data?.total??0),detail:`all time`}),(0,I.jsx)(dE,{label:`Requests`,value:i.isPending?(0,I.jsx)(aw,{className:`h-6 w-16`}):cC(i.data?.requests??0),detail:`month to date`}),(0,I.jsx)(dE,{label:`Tokens`,value:i.isPending?(0,I.jsx)(aw,{className:`h-6 w-16`}):lC(s),detail:`all buckets`})]}),(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(iE,{className:`text-sm`,children:`Client base URL`})}),(0,I.jsxs)(oE,{children:[(0,I.jsxs)(`code`,{className:`block rounded-md bg-muted px-3 py-2 font-mono text-xs break-all`,children:[bD(r),`/v1/apps/`,e,`/proxy/{provider}/{provider_path}`]}),(0,I.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:c?(0,I.jsxs)(I.Fragment,{children:[`Auth exchange lives at`,` `,(0,I.jsxs)(`span`,{className:`font-mono`,children:[`/v1/apps/`,e,`/auth/token`]}),`.`]}):(0,I.jsxs)(I.Fragment,{children:[`Clients send their API key as the`,` `,(0,I.jsx)(`span`,{className:`font-mono`,children:`Authorization`}),` bearer credential; this app has no token exchange.`]})})]})]})]})}function SD({appId:e}){let t=IS(e);return!t.data||t.data.keys.some(e=>e.status===`active`)?null:(0,I.jsxs)(Ds,{children:[(0,I.jsx)(Sa,{}),(0,I.jsx)(Os,{children:`This app has no active API key`}),(0,I.jsxs)(ks,{children:[`Nothing can call it until one is created.`,` `,(0,I.jsx)(Pn,{to:`/apps/${e}/auth/identity`,className:`text-primary-ink underline underline-offset-4`,children:`Create an API key`})]})]})}function CD({className:e,size:t=`default`,...n}){return(0,I.jsx)(_y,{"data-slot":`switch`,"data-size":t,className:H(`peer group/switch inline-flex shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-[1.15rem] data-[size=default]:w-8 data-[size=sm]:h-3.5 data-[size=sm]:w-6 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input dark:data-[state=unchecked]:bg-input/80`,e),...n,children:(0,I.jsx)(yy,{"data-slot":`switch-thumb`,className:H(`pointer-events-none block rounded-full bg-background ring-0 transition-transform group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0 dark:data-[state=checked]:bg-primary-foreground dark:data-[state=unchecked]:bg-foreground`)})})}function wD({values:e,onChange:t,placeholder:n,suggestions:r=[],warn:i,warnTitle:a}){let[o,s]=(0,v.useState)(``),c=`suggestions-${Math.abs(TD(r.join(`,`)+n))}`,l=n=>{let r=n.trim();if(!r||e.includes(r))return s(``);t([...e,r]),s(``)};return(0,I.jsxs)(`div`,{className:`space-y-2`,children:[e.length>0?(0,I.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(n=>{let r=i?.(n)??!1;return(0,I.jsxs)(`span`,{title:r?a:void 0,className:H(`inline-flex items-center gap-1 rounded-md border py-1 pr-1 pl-2 font-mono text-xs`,r?`border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-400`:`bg-muted/50`),children:[n,(0,I.jsx)(`button`,{type:`button`,"aria-label":`Remove ${n}`,className:`rounded p-0.5 text-muted-foreground transition-colors hover:bg-background hover:text-foreground`,onClick:()=>t(e.filter(e=>e!==n)),children:(0,I.jsx)(Ya,{className:`size-3`})})]},n)})}):null,(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)($,{value:o,list:r.length>0?c:void 0,placeholder:n,className:`h-8 font-mono text-xs`,onChange:e=>s(e.target.value),onKeyDown:n=>{(n.key===`Enter`||n.key===`,`)&&(n.preventDefault(),l(o)),n.key===`Backspace`&&o===``&&e.length>0&&t(e.slice(0,-1))}}),r.length>0?(0,I.jsx)(`datalist`,{id:c,children:r.map(e=>(0,I.jsx)(`option`,{value:e},e))}):null,(0,I.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,className:`h-8`,onClick:()=>l(o),children:[(0,I.jsx)(Na,{className:`size-3.5`}),`Add`]})]})]})}function TD(e){let t=0;for(let n=0;n<e.length;n+=1)t=t*31+e.charCodeAt(n)|0;return t}var ED={responses:`Responses`,chat_completions:`Chat Completions`,anthropic_messages:`Anthropic Messages`,gemini_native:`Gemini generateContent`,audio_transcription:`Transcription`};function DD(e){return Object.hasOwn(ED,e)}var OD={gemini:[`gemini_native`],openai:[`audio_transcription`],xai:[`audio_transcription`]};function kD(e){return{style:e,label:ED[e],path:Lw[e]}}function AD(e,t){let n=Xw[e]?.[t];if(!n)return null;let r=OD[t]??[],i=n.apiStyles?.filter(DD);return{narrowed:i!==void 0,available:(i??[]).map(kD),unavailable:i?r.filter(e=>!i.includes(e)).map(kD):[],modelIds:n.modelPrefix?`${eT[t]} model IDs with no "${n.modelPrefix}" prefix — the gateway adds it upstream`:`${eT[t]} model IDs, unchanged`}}function jD(e,t,n){if(e===null)return!0;let r=AD(e,t);if(!r)return!1;if(!r.narrowed)return!0;let i=zw[n];return r.available.some(e=>e.style===i)}var MD={openai:`Forwarded with the leading v1/ stripped, matching Cloudflare's provider-native URL.`,anthropic:`Forwarded with the v1/ prefix retained.`,xai:`Routed to Cloudflare's grok slug; the tenant path stays /proxy/xai/...`,gemini:`Use the OpenAI-compatible path v1beta/openai/chat/completions.`,perplexity:`Routed to Cloudflare's perplexity-ai slug; use chat/completions for Sonar models.`,deepseek:`Direct only. DeepSeek's base URL has no v1/, so the path is chat/completions.`,groq:`Direct only. Groq namespaces its OpenAI API: use openai/v1/chat/completions.`,mistral:`Direct only. Use v1/chat/completions.`,together:`Direct only. Use v1/chat/completions; models are namespaced, e.g. openai/gpt-oss-120b.`,fireworks:`Direct only. Use inference/v1/chat/completions. Models are account-scoped (accounts/…/models/…), so price them under custom model pricing.`,cerebras:`Direct only. Use v1/chat/completions.`,moonshot:`Direct only. Use v1/chat/completions on the international api.moonshot.ai host.`,huggingface:`Direct only. Use v1/chat/completions on the Inference Providers router. Pin the upstream in the model ID (author/model:provider) — otherwise the router picks one and the price varies with it.`,baseten:`Direct only. Use v1/chat/completions on the Model APIs host.`,bytedance:`Direct only. BytePlus ModelArk's version segment is already in the base URL: the path is chat/completions. Models must be activated in your ModelArk console first.`,openrouter:`Direct only, chat completions only. Models are OpenRouter slugs, e.g. google/gemini-3.6-flash, and need no local price: cost is reported by OpenRouter per request.`};function ND(e,t){if(e.providerGatewayId===null)return null;let n=t.find(t=>t.id===e.providerGatewayId),r=n?AD(n.type,e.type):null;if(!r?.narrowed)return null;let i=r.available.map(e=>`${e.label} at ${e.path}`).join(`, `),a=r.unavailable.length>0?` Not available on this route: ${r.unavailable.map(e=>e.label).join(`, `)}.`:``;return`Routed through ${n.name}: ${i}.${a} Models: ${r.modelIds}.`}function PD({state:e}){return(0,I.jsx)(Lb,{variant:`outline`,className:`border-muted-foreground/30 text-[11px] font-normal text-muted-foreground`,children:e})}function FD({row:e,config:t,onChange:n}){let r=(t?.allowed_paths??[]).map(fT),i=e.knownModels,a=e=>n({...mT(),...t,allowed_paths:e.map(pT)});return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:(0,I.jsxs)(`span`,{className:`flex items-center gap-2`,children:[e.title,e.badge?(0,I.jsx)(PD,{state:e.badge}):null]}),description:e.description,action:(0,I.jsx)(CD,{"aria-label":`Enable ${e.slug}`,checked:t!==void 0,onCheckedChange:e=>n(e?mT():void 0)})})}),t?(0,I.jsxs)(oE,{className:`space-y-5`,children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsx)(ow,{className:`text-sm`,children:`Allowed paths`}),(0,I.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>a([...r,{path:``}]),children:[(0,I.jsx)(Na,{className:`size-3.5`}),`Add path`]})]}),r.length===0?(0,I.jsx)(uw,{children:`Every path is allowed. Add one or more paths to restrict this provider.`}):(0,I.jsx)(`div`,{className:`space-y-2`,children:r.map((e,t)=>(0,I.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,I.jsxs)(`div`,{className:`min-w-[200px] flex-[2]`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Path`}),(0,I.jsx)($,{value:e.path,placeholder:`v1/responses`,className:`font-mono text-xs`,onChange:e=>a(r.map((n,r)=>r===t?{...n,path:e.target.value}:n))})]}),(0,I.jsxs)(`div`,{className:`min-w-[150px] flex-1`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Fixed model`}),(0,I.jsx)($,{value:e.fixed_model??``,placeholder:`none`,className:`font-mono text-xs`,onChange:e=>a(r.map((n,r)=>r===t?{...n,fixed_model:e.target.value||void 0}:n))})]}),(0,I.jsxs)(`div`,{className:`w-[170px]`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Output cap style`}),(0,I.jsxs)(zT,{value:e.clamp??`auto`,onValueChange:e=>a(r.map((n,r)=>r===t?{...n,clamp:e===`auto`?void 0:e}:n)),children:[(0,I.jsx)(VT,{className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsxs)(HT,{children:[(0,I.jsx)(UT,{value:`auto`,children:`auto (by body)`}),rT.map(e=>(0,I.jsx)(UT,{value:e,children:e},e))]})]})]}),(0,I.jsx)(J,{variant:`ghost`,size:`icon`,"aria-label":`Remove path`,onClick:()=>a(r.filter((e,n)=>n!==t)),children:(0,I.jsx)(Ga,{className:`size-4`})})]},t))}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Leave this list empty to allow every path. A fixed model applies to transcription-style routes with no model in the body; it is never injected upstream. Leave the output cap style on auto unless the route needs an exception.`})]}),(0,I.jsx)(sw,{label:`Allowed models`,hint:`Leave empty to allow every model with configured pricing. A non-empty list restricts this provider; rewrites are resolved before pricing is checked.`,children:(0,I.jsx)(wD,{values:t.allowed_models??[],suggestions:i,placeholder:`gpt-5.6-terra`,onChange:e=>n({...t,allowed_models:e})})}),(0,I.jsx)(sw,{label:`Max output tokens`,hint:`Empty = unrestricted. If set, requests above this are rejected; requests without an output-limit parameter get this value injected. Transcription routes ignore this cap.`,children:(0,I.jsx)($,{type:`number`,min:1,className:`max-w-[200px]`,value:t.max_output_tokens??``,placeholder:`8192`,onChange:e=>n({...t,max_output_tokens:e.target.value?Number(e.target.value):void 0})})})]}):null]})}function ID(e,t,n,r){let i=e.map(e=>({slug:e.slug,title:e.name,description:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`span`,{className:`font-mono`,children:[`/proxy/`,e.slug,`/…`]}),` ·`,` `,(0,I.jsx)(FT,{type:e.type,className:`align-middle`}),` —`,` `,ND(e,t)??MD[e.type]]}),knownModels:aT(e,r),...e.status===`disabled`?{badge:`disabled`}:{}})),a=n.filter(t=>!e.some(e=>e.slug===t)).map(e=>({slug:e,title:e,description:`No instance answers for this slug. Recreate it on the Providers page, or turn this off.`,knownModels:[],badge:`deleted`}));return[...i,...a]}var LD=e=>e.filter(([e,t])=>e!==``&&t!==``),RD=e=>Object.fromEntries(LD(e));function zD({rewrites:e,onChange:t}){let[n,r]=(0,v.useState)(()=>Object.entries(e)),i=JSON.stringify(e),[a,o]=(0,v.useState)(i);i!==a&&(o(i),i!==JSON.stringify(RD(n))&&r(Object.entries(e)));let s=e=>{r(e),t(RD(e))},c=(e,t)=>s(n.map((n,r)=>r===e?t:n)),l=LD(n).length<n.length;return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Model rewrites`,description:`Server-side remap applied after the allowlist check, so a target need not be client-allowlisted. Usage records the rewritten model.`,action:(0,I.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>s([...n,[``,``]]),children:[(0,I.jsx)(Na,{className:`size-3.5`}),`Add rewrite`]})})}),(0,I.jsxs)(oE,{className:`space-y-2`,children:[n.length===0?(0,I.jsx)(uw,{children:`No rewrites. Clients get exactly the model they ask for.`}):n.map(([e,t],r)=>(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)($,{value:e,"aria-label":`Rewrite ${r+1} source model`,placeholder:`gpt-5.6-terra`,className:`flex-1 font-mono text-xs`,onChange:e=>c(r,[e.target.value,t])}),(0,I.jsx)(Zi,{className:`size-4 shrink-0 text-muted-foreground`}),(0,I.jsx)($,{value:t,"aria-label":`Rewrite ${r+1} target model`,placeholder:`gpt-5.7`,className:`flex-1 font-mono text-xs`,onChange:t=>c(r,[e,t.target.value])}),(0,I.jsx)(J,{variant:`ghost`,size:`icon`,"aria-label":`Remove rewrite ${r+1}`,onClick:()=>s(n.filter((e,t)=>t!==r)),children:(0,I.jsx)(Ga,{className:`size-4`})})]},r)),l?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`A rewrite is saved once both sides are filled in. A row left half-finished is dropped.`}):null]})]})}function BD({state:e}){let t=e.draft.config.routing,n=yT(t),r=bT(t),i=fS().data??[],a=_S().data?.gateways??[],o=qS().data?.prices,s=ID(i,a,r,o);return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(nE,{className:n===`all`?`border-emerald-500/30`:void 0,children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Provider access`,description:`Choose whether this application can use every provider supported by the gateway or only providers you select.`,action:(0,I.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,I.jsx)(ow,{htmlFor:`configure-providers`,className:`text-xs text-muted-foreground`,children:`Configure individually`}),(0,I.jsx)(CD,{id:`configure-providers`,"aria-label":`Configure providers individually`,checked:n===`selected`,onCheckedChange:t=>{e.updateProxy(t?{providers:{mode:`selected`,selected:(()=>{let e=i.find(e=>e.status===`active`)??i[0];return e?{[e.slug]:mT()}:{}})()}}:{providers:{mode:`all`}})}})]})})}),(0,I.jsx)(oE,{children:n===`all`?(0,I.jsx)(`div`,{className:`rounded-xl border border-emerald-500/25 bg-emerald-500/[0.06] p-4`,children:(0,I.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,I.jsx)(`span`,{className:`mt-0.5 flex size-9 shrink-0 items-center justify-center rounded-lg bg-emerald-500/12 text-emerald-600 dark:text-emerald-400`,children:(0,I.jsx)(la,{className:`size-5`})}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`p`,{className:`text-sm font-semibold`,children:`Every configured instance is allowed`}),(0,I.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:`New provider instances, paths, and models are available automatically. Turn on individual configuration only when this application needs restrictions.`}),(0,I.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:i.length===0?(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`No provider instances yet.`}):i.map(e=>(0,I.jsx)(Lb,{variant:`secondary`,className:H(`bg-background/75 font-mono text-[11px] font-normal`,e.status===`disabled`&&`text-muted-foreground line-through decoration-muted-foreground/50`),title:e.status===`disabled`?`${e.slug} is disabled and serves no traffic`:void 0,children:e.slug},e.slug))})]})]})}):(0,I.jsxs)(`div`,{className:`flex items-start gap-3 rounded-xl bg-muted/45 p-4 ring-1 ring-border/70`,children:[(0,I.jsx)(`span`,{className:`mt-0.5 flex size-9 shrink-0 items-center justify-center rounded-lg bg-background text-muted-foreground shadow-sm ring-1 ring-border`,children:(0,I.jsx)(Ha,{className:`size-4`})}),(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`p`,{className:`text-sm font-medium`,children:[r.length,` of `,i.length,` provider instances enabled`]}),(0,I.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:`Use the switches below. An enabled instance allows every path and model until you add a restriction, and clients reach it at its own slug.`})]})]})})]}),n===`selected`&&s.length===0?(0,I.jsx)(nE,{children:(0,I.jsx)(oE,{children:(0,I.jsx)(uw,{children:`No provider instances to choose from. Add one on the Providers page, then come back to restrict this app to it.`})})}):null,n===`selected`?s.map(n=>(0,I.jsx)(FD,{row:n,config:t.providers.selected?.[n.slug],onChange:r=>e.updateProxy({providers:{mode:`selected`,selected:{...t.providers.selected,[n.slug]:r}}})},n.slug)):null,(0,I.jsx)(zD,{rewrites:t.model_rewrites??{},onChange:t=>e.updateProxy({model_rewrites:t})})]})}function VD({open:e,onOpenChange:t,title:n,description:r,confirmLabel:i=`Confirm`,confirmWord:a,destructive:o,pending:s,onConfirm:c}){let[l,u]=(0,v.useState)(``);return(0,I.jsx)(KE,{open:e,onOpenChange:e=>{e||u(``),t(e)},children:(0,I.jsxs)(XE,{className:`sm:max-w-md`,children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{children:n})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[(0,I.jsx)(tD,{asChild:!0,children:(0,I.jsx)(`div`,{className:`space-y-2 text-sm text-muted-foreground`,children:r})}),a?(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsxs)(ow,{htmlFor:`confirm-word`,className:`text-xs`,children:[`Type `,(0,I.jsx)(`span`,{className:`font-mono text-foreground`,children:a}),` to continue`]}),(0,I.jsx)($,{id:`confirm-word`,value:l,autoComplete:`off`,className:`font-mono`,onChange:e=>u(e.target.value)})]}):null]}),(0,I.jsxs)($E,{children:[(0,I.jsx)(J,{variant:`outline`,onClick:()=>t(!1),children:`Cancel`}),(0,I.jsx)(J,{variant:o?`destructive`:`default`,disabled:!(!a||l===a)||s,onClick:c,children:i})]})]})})}function HD({appId:e,state:t}){let n=t.draft,r=ht(),i=FS(),{readOnly:a}=sx(),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(!1),u=async()=>{try{await navigator.clipboard.writeText(e),l(!0),U.success(`Application id copied`)}catch{U.error(`Could not copy the application id`)}},d=async()=>{try{let t=await i.mutateAsync(e);U.success(`Deleted ${n.name}`,{description:`${t.removed_users} users removed. Usage history was kept.`}),r(`/apps`)}catch(e){U.error(e instanceof Error?e.message:`Could not delete the app`)}};return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsx)(nE,{children:(0,I.jsxs)(oE,{className:`space-y-5`,children:[(0,I.jsx)(sw,{label:`Name`,htmlFor:`app-name`,children:(0,I.jsx)($,{id:`app-name`,value:n.name,maxLength:100,disabled:a,className:`max-w-md`,onChange:e=>t.update({name:e.target.value})})}),(0,I.jsx)(sw,{label:`Application id`,htmlFor:`app-id`,hint:`Fixed when the app was created. It is part of every URL your clients call.`,children:(0,I.jsxs)(`div`,{className:`flex max-w-md gap-2`,children:[(0,I.jsx)($,{id:`app-id`,value:e,readOnly:!0,className:`font-mono text-xs`}),(0,I.jsxs)(J,{type:`button`,variant:`outline`,className:`min-w-24`,onClick:()=>void u(),children:[c?(0,I.jsx)(ra,{className:`size-4`}):(0,I.jsx)(ha,{className:`size-4`}),c?`Copied`:`Copy`]})]})})]})}),(0,I.jsx)(nE,{children:(0,I.jsx)(oE,{children:(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:`App enabled`}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Turned off, this app refuses every request. Nothing is deleted, and turning it back on restores it as it was.`})]}),(0,I.jsx)(CD,{"aria-label":`App enabled`,checked:n.status===`active`,disabled:a,onCheckedChange:e=>t.update({status:e?`active`:`disabled`})})]})})}),(0,I.jsx)(nE,{className:`border-destructive/40`,children:(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Delete this app`,description:`Clients of this app stop working immediately. Registered users and App Attest keys are removed. Usage history is kept for accounting.`,action:(0,I.jsx)(iw,{variant:`destructive`,size:`sm`,disabled:i.isPending,onClick:()=>s(!0),children:`Delete app`})})})}),(0,I.jsx)(VD,{open:o,onOpenChange:s,title:`Delete ${n.name}?`,description:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`p`,{children:`Clients of this app stop working immediately. Registered users and App Attest keys are removed; usage history is kept for accounting.`}),(0,I.jsx)(`p`,{children:`This cannot be undone.`})]}),confirmWord:e,confirmLabel:`Delete app`,destructive:!0,pending:i.isPending,onConfirm:()=>void d()})]})}var UD=25;function WD({appId:e}){let[t,n]=(0,v.useState)(yC()),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(`all`),[s,c]=(0,v.useState)(0),[l,u]=(0,v.useState)(null),d=zS(e,{month:t,query:r||void 0,status:a===`all`?void 0:a,limit:UD,offset:s*UD}),f=BS(e),p=async()=>{if(!l)return;let e=l.status===`active`;try{await f.mutateAsync({userId:l.id,blocked:e}),U.success(e?`Blocked ${l.id}`:`Unblocked ${l.id}`,{description:e?`Their Durable Object was updated, so it applies even to a live gateway token.`:void 0}),u(null)}catch(e){U.error(e instanceof Error?e.message:`Could not update the user`)}},m=d.data?.total??0,h=Math.max(1,Math.ceil(m/UD));return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,I.jsxs)(`div`,{className:`relative min-w-[220px] flex-1`,children:[(0,I.jsx)(Ia,{className:`absolute top-1/2 left-2.5 size-3.5 -translate-y-1/2 text-muted-foreground`}),(0,I.jsx)($,{value:r,placeholder:`Search user id`,className:`h-9 pl-8 font-mono text-xs`,onChange:e=>{i(e.target.value),c(0)}})]}),(0,I.jsxs)(zT,{value:a,onValueChange:e=>{o(e),c(0)},children:[(0,I.jsx)(VT,{className:`w-[140px]`,size:`sm`,children:(0,I.jsx)(BT,{})}),(0,I.jsxs)(HT,{children:[(0,I.jsx)(UT,{value:`all`,children:`All users`}),(0,I.jsx)(UT,{value:`active`,children:`Active`}),(0,I.jsx)(UT,{value:`blocked`,children:`Blocked`})]})]}),(0,I.jsx)(qT,{value:t,onChange:n})]}),(0,I.jsx)(nE,{className:`overflow-hidden py-0`,children:(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{className:`hover:bg-transparent`,children:[(0,I.jsx)(Z,{children:`User`}),(0,I.jsx)(Z,{children:`Attestation`}),(0,I.jsx)(Z,{children:`Last seen`}),(0,I.jsx)(Z,{className:`text-right`,children:`Requests`}),(0,I.jsx)(Z,{className:`text-right`,children:`Tokens`}),(0,I.jsx)(Z,{className:`text-right`,children:`Cost`}),(0,I.jsx)(Z,{className:`w-24`})]})}),(0,I.jsx)(lE,{children:d.isPending?[0,1,2].map(e=>(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:7,children:(0,I.jsx)(aw,{className:`h-8 w-full`})})},e)):d.data?.users.length===0?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:7,className:`py-10 text-center text-sm text-muted-foreground`,children:`No users yet. A row appears once a client completes its first token exchange.`})}):d.data?.users.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{children:(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(`span`,{className:`font-mono text-xs`,children:e.id}),e.status===`blocked`?(0,I.jsx)(tC,{status:`blocked`}):null]})}),(0,I.jsx)(Q,{children:e.attest_registered?(0,I.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,I.jsx)(Lb,{variant:`secondary`,className:`text-[11px] font-normal`,children:`registered`}),(0,I.jsxs)(`span`,{className:`tabular text-[11px] text-muted-foreground`,children:[`counter `,e.attest_counter]})]}):(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.is_virtual?`server attributed`:`issuer token`})}),(0,I.jsx)(Q,{className:`text-xs text-muted-foreground`,children:hC(e.last_seen_at)}),(0,I.jsx)(Q,{className:`tabular text-right`,children:cC(e.usage.requests)}),(0,I.jsx)(Q,{className:`tabular text-right`,children:lC(vC(e.usage))}),(0,I.jsx)(Q,{className:`tabular text-right`,children:dC(e.usage.cost_usd)}),(0,I.jsx)(Q,{className:`text-right`,children:(0,I.jsx)(iw,{variant:`ghost`,size:`sm`,disabled:e.is_virtual,onClick:()=>u(e),className:e.status===`active`?`text-destructive`:void 0,children:e.status===`active`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)($i,{className:`size-3.5`}),`Block`]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(la,{className:`size-3.5`}),`Unblock`]})})})]},e.id))})]})}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-muted-foreground`,children:[(0,I.jsxs)(`span`,{children:[cC(m),` users · page `,s+1,` of `,h]}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(J,{variant:`outline`,size:`sm`,disabled:s===0,onClick:()=>c(e=>e-1),children:`Previous`}),(0,I.jsx)(J,{variant:`outline`,size:`sm`,disabled:s+1>=h,onClick:()=>c(e=>e+1),children:`Next`})]})]}),(0,I.jsx)(VD,{open:l!==null,onOpenChange:e=>!e&&u(null),title:l?.status===`active`?`Block ${l?.id}?`:`Unblock ${l?.id}?`,description:l?.status===`active`?(0,I.jsx)(`p`,{children:`Their requests are refused immediately, even with an unexpired gateway token, because the block is written to their Durable Object as well as D1.`}):(0,I.jsx)(`p`,{children:`Their requests resume as soon as the Durable Object is updated.`}),confirmLabel:l?.status===`active`?`Block user`:`Unblock user`,destructive:l?.status===`active`,pending:f.isPending,onConfirm:()=>void p()})]})}var GD=(0,v.lazy)(()=>w(()=>import(`./usage-CzdJHSbn.js`).then(e=>({default:e.UsageTab})),[])),KD=(0,v.lazy)(()=>w(()=>import(`./endpoints-BNTBSczQ.js`).then(e=>({default:e.EndpointsTab})),[]));function qD(){let{appId:e=``,tab:t=`overview`,section:n}=_t(),r=QT(e),[i,a]=(0,v.useState)(yC()),o=iC.find(e=>e.slug===t),{query:s,draft:c,dirty:l}=r,u=c?tE(c):null;return s.isError?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`Could not load this app`}),(0,I.jsxs)(ks,{children:[s.error instanceof Error?s.error.message:`Unknown error`,(0,I.jsx)(Pn,{to:`/apps`,className:`underline underline-offset-4`,children:`Back to apps`})]})]}):(0,I.jsxs)(`div`,{className:`space-y-6 pb-24`,children:[(0,I.jsx)(cw,{title:o?.label??`Overview`,action:t===`overview`?(0,I.jsx)(qT,{value:i,onChange:a}):void 0}),s.data?.config_error?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`The stored configuration is invalid`}),(0,I.jsxs)(ks,{children:[s.data.config_error,`. The gateway rejects requests for this app until it is fixed.`]})]}):null,c?(0,I.jsx)(RT,{proxy:c.config.routing}):null,s.isPending||!c?(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(aw,{className:`h-32 w-full`}),(0,I.jsx)(aw,{className:`h-64 w-full`})]}):t===`overview`?(0,I.jsx)(xD,{appId:e,month:i,state:r}):t===`auth`?(0,I.jsx)(dD,{appId:e,level:n,state:r}):t===`proxy`?(0,I.jsx)(BD,{state:r}):t===`limits`?(0,I.jsx)(yD,{state:r}):t===`users`?(0,I.jsx)(WD,{appId:e}):t===`auth-events`?(0,I.jsx)(hE,{appId:e}):t===`settings`?(0,I.jsx)(HD,{appId:e,state:r}):(0,I.jsx)(v.Suspense,{fallback:(0,I.jsx)(aw,{className:`h-64 w-full`}),children:t===`usage`?(0,I.jsx)(GD,{appId:e}):(0,I.jsx)(KD,{appId:e,state:r})}),l?(0,I.jsx)(`div`,{className:`fixed inset-x-0 bottom-0 z-40 border-t bg-background/95 backdrop-blur`,children:(0,I.jsxs)(`div`,{className:`mx-auto flex max-w-7xl items-center gap-3 px-4 py-3 sm:px-6`,children:[(0,I.jsxs)(`span`,{className:`text-sm`,children:[(0,I.jsx)(`span`,{className:`mr-2 inline-block size-2 rounded-full bg-amber-500 align-middle`}),`Unsaved changes to `,(0,I.jsx)(`span`,{className:`font-medium`,children:c?.name??e})]}),(0,I.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,I.jsx)(J,{variant:`ghost`,size:`sm`,onClick:r.reset,disabled:r.saving,children:`Discard`}),(0,I.jsxs)(iw,{size:`sm`,reason:u??void 0,onClick:()=>void r.save(),disabled:r.saving,children:[r.saving?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Save changes`]})]})]})}):null]})}var JD=[{id:`ios`,label:`iOS application`,description:`Calls AI providers straight from the app.`,icon:Ua},{id:`server`,label:`Server`,description:`A backend you run, using a private API key.`,icon:La}],YD={basics:{id:`basics`,label:`Basics`},app_identity:{id:`app_identity`,label:`Application identity`,subtitle:`Application identity`,text:`Set your app's identity so that only this app can call AI providers through this gateway.`},users:{id:`users`,label:`User authentication`,subtitle:`User authentication`,text:`Choose whether only users signed in to your app can call AI through this gateway.`},identity_provider:{id:`identity_provider`,label:`Identity provider`,subtitle:`Identity provider`,text:`Where your users sign in. The gateway verifies their sign-in tokens against it.`},subscription:{id:`subscription`,label:`Subscription check`,subtitle:`Subscription check`,text:`Check that the user has paid for the app before they can call AI providers through this gateway.`}},XD=IE.find(e=>e.id===`none`);function ZD({trigger:e}={}){let{capabilities:t}=sx(),[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(0),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(void 0),[g,_]=(0,v.useState)(null),[y,b]=(0,v.useState)(DE[0]),[x,S]=(0,v.useState)({}),[C,w]=(0,v.useState)(XD),[T,E]=(0,v.useState)({}),[ee,D]=(0,v.useState)(null),[O,k]=(0,v.useState)(``),[A,j]=(0,v.useState)(!1),[te,ne]=(0,v.useState)(!1),M=ht(),N=PS(),P=(0,v.useMemo)(()=>{let e=[YD.basics];return c===`ios`&&e.push(YD.app_identity),e.push(YD.users),g===`issuer`&&e.push(YD.identity_provider,YD.subscription),e},[c,g]),re=P[Math.min(i,P.length-1)],ie=i>=P.length-1,ae=(0,v.useMemo)(()=>TE(y,x),[y,x]),oe=LE(y,x)&&ae.jwks_url.startsWith(`https://`)&&ae.issuer.length>0&&ae.audience.length>0,F=(()=>{switch(re.id){case`basics`:return o.trim().length>0&&c!==null;case`app_identity`:return u.trim().length>0&&f.trim().length>0;case`users`:return g!==null;case`identity_provider`:return oe;case`subscription`:return LE(C,T)}})(),se=()=>{a(0),s(``),l(null),d(``),p(``),h(void 0),_(null),b(DE[0]),S({}),w(XD),E({})},ce=e=>{e&&se(),r(e)},le=e=>{e!==c&&(l(e),_(null))},ue=()=>{let e=g===`issuer`?{source:`issuer`,issuer:{provider:y.id,jwks_url:ae.jwks_url,issuer:ae.issuer,audience:ae.audience,user_id_claim:ae.user_id_claim,required_claims:EE(C,T),max_token_lifetime_seconds:86400,...C.id===`none`?{}:{entitlement:C.id}}}:null;return c===`ios`?{type:`apple_app_attest`,app_attest:{team_id:u.trim(),bundle_id:f.trim(),...m?.includes(`development`)?{environments:m}:{}},end_user:e??{source:`app_install`}}:e?{type:`api_key`,end_user:e}:g===`header`?{type:`api_key`,end_user:{source:`header`,header:iT}}:{type:`api_key`}},de=async()=>{if(c)try{let e=await N.mutateAsync({name:o.trim(),config:{authentication:ue(),routing:{providers:{mode:`all`},model_rewrites:{}},...c===`server`?{}:{limits:{per_user:{requests:{per_minute:10,per_day:300},spending:{monthly_usd:null}},per_app:{requests:{per_minute:null,per_day:null},spending:{monthly_usd:null}}}}},status:`active`});if(r(!1),c===`server`){if(!e.api_key)throw Error(`The app was created without its initial API key`);k(e.app.id),D(e.api_key),ne(!1),j(!0);return}U.success(`Created ${e.app.id}`),M(`/apps/${e.app.id}/proxy`)}catch(e){U.error(e instanceof Error?e.message:`Could not create the app`)}},fe=()=>{_(c===`ios`?`app_install`:`none`),a(P.findIndex(e=>e.id===`users`))},pe=()=>{if(ie){de();return}a(e=>e+1)},me=async()=>{if(ee)try{await navigator.clipboard.writeText(ee.key),ne(!0),U.success(`API key copied`)}catch{U.error(`Could not copy the API key`)}},he=()=>{j(!1),U.success(`Created ${O}`),M(`/apps/${O}/proxy`)};return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(KE,{open:n,onOpenChange:ce,children:[(0,I.jsx)(qE,{asChild:!0,children:e??(0,I.jsxs)(iw,{size:`sm`,children:[(0,I.jsx)(Na,{className:`size-4`}),`New app`]})}),(0,I.jsxs)(XE,{className:`sm:max-w-2xl`,children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{children:`Create a new application`})}),(0,I.jsxs)(QE,{className:`space-y-6`,children:[re.subtitle?(0,I.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,I.jsx)(`h3`,{className:`text-base font-semibold`,children:re.subtitle}),re.text?(0,I.jsx)(`p`,{className:`text-sm text-pretty text-muted-foreground`,children:re.text}):null]}):null,re.id===`basics`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,I.jsx)(ow,{htmlFor:`app-name`,children:`Application name`}),(0,I.jsx)($,{id:`app-name`,value:o,placeholder:`Calorie Tracker`,maxLength:100,autoFocus:!0,onChange:e=>s(e.target.value)})]}),(0,I.jsxs)(`fieldset`,{className:`space-y-3`,children:[(0,I.jsx)(`legend`,{className:`text-sm font-medium`,children:`Application type`}),(0,I.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2`,role:`radiogroup`,children:JD.map(e=>{let t=e.icon,n=c===e.id;return(0,I.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":n,className:H(`group min-h-32 rounded-xl bg-background p-5 text-left shadow-sm ring-1 ring-border transition-[box-shadow,background-color] hover:bg-muted/40 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,n&&`bg-primary/[0.04] shadow-md ring-2 ring-primary`),onClick:()=>le(e.id),children:[(0,I.jsx)(`span`,{className:H(`mb-3 flex size-10 items-center justify-center rounded-lg bg-muted text-muted-foreground transition-[background-color,color]`,n&&`bg-primary text-primary-foreground`),children:(0,I.jsx)(t,{className:`size-5`})}),(0,I.jsx)(`span`,{className:`block text-sm font-semibold`,children:e.label}),(0,I.jsx)(`span`,{className:`mt-1 block text-xs leading-relaxed text-muted-foreground`,children:e.description})]},e.id)})})]})]}):null,re.id===`app_identity`?(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,I.jsx)(ow,{htmlFor:`apple-team-id`,children:`Apple Team ID`}),(0,I.jsx)($,{id:`apple-team-id`,value:u,placeholder:`ABCDE12345`,className:`font-mono text-xs`,autoFocus:!0,onChange:e=>d(e.target.value)}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`In your Apple Developer account under`,` `,(0,I.jsx)(bE,{href:`https://developer.apple.com/account#MembershipDetailsCard`,children:`Membership details`}),`.`]})]}),(0,I.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,I.jsx)(ow,{htmlFor:`apple-bundle-id`,children:`Bundle ID`}),(0,I.jsx)($,{id:`apple-bundle-id`,value:f,placeholder:`com.example.calorietracker`,className:`font-mono text-xs`,onChange:e=>p(e.target.value)}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`In Xcode, on your target's`,` `,(0,I.jsx)(bE,{href:`https://developer.apple.com/documentation/xcode/configuring-the-build-settings-of-a-target#Set-the-bundle-ID`,children:`Signing & Capabilities`}),` `,`tab.`]})]})]}),(0,I.jsx)(vE,{value:m,onChange:h,compact:!0})]}):null,re.id===`users`?(0,I.jsx)(yE,{label:`User authentication`,choices:c===`ios`?WE:GE,value:g,onChange:_}):null,re.id===`identity_provider`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(xE,{idPrefix:`issuer`,label:`Identity provider`,presets:DE,selected:y,values:x,compact:!0,onSelect:e=>{b(e),S({})},onValueChange:(e,t)=>S(n=>({...n,[e]:t}))}),(0,I.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Don't have these details yet?`,` `,(0,I.jsx)(`button`,{type:`button`,className:`font-medium text-primary-ink underline decoration-primary-ink/40 underline-offset-4 transition-colors hover:decoration-primary-ink`,onClick:fe,children:c===`ios`?`Allow unauthenticated users for now`:`Continue without user identity for now`}),` `,`and set this up later.`]})]}):null,re.id===`subscription`?(0,I.jsx)(xE,{idPrefix:`entitlement`,label:FE,presets:IE,selected:C,values:T,compact:!0,onSelect:e=>{w(e),E({})},onValueChange:(e,t)=>E(n=>({...n,[e]:t}))}):null]}),(0,I.jsxs)($E,{className:`items-center sm:justify-between`,children:[i>0?(0,I.jsxs)(J,{variant:`ghost`,onClick:()=>a(e=>e-1),disabled:N.isPending,children:[(0,I.jsx)(Xi,{className:`size-4`}),`Back`]}):(0,I.jsx)(J,{variant:`outline`,onClick:()=>r(!1),children:`Cancel`}),(0,I.jsx)(QD,{steps:P,current:i,onSelect:a}),(0,I.jsxs)(J,{disabled:!F||N.isPending,onClick:pe,children:[N.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,ie?`Create app`:`Next`]})]})]})]}),(0,I.jsx)(KE,{open:A,onOpenChange:e=>{e||he()},children:(0,I.jsxs)(XE,{showCloseButton:!1,className:`sm:max-w-lg`,onEscapeKeyDown:e=>e.preventDefault(),children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{className:`text-balance`,children:`Your application is ready`})}),(0,I.jsxs)(QE,{className:`space-y-5`,children:[(0,I.jsxs)(tD,{className:`text-pretty`,children:[`This is the API key for`,` `,(0,I.jsx)(`span`,{className:`font-mono text-foreground`,children:O}),`. It is shown only once, so copy it now.`]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`created-api-key`,children:`API key`}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)($,{id:`created-api-key`,value:ee?.key??``,readOnly:!0,className:`font-mono text-xs`}),(0,I.jsxs)(J,{type:`button`,variant:`outline`,className:`min-w-24`,onClick:()=>void me(),children:[te?(0,I.jsx)(ra,{className:`size-4`}):(0,I.jsx)(ha,{className:`size-4`}),te?`Copied`:`Copy`]})]})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:`Base URL`}),(0,I.jsxs)(`code`,{className:`block rounded-md bg-muted px-3 py-2 font-mono text-xs break-all text-muted-foreground`,children:[bD(t),`/v1/apps/`,(0,I.jsx)(`span`,{className:`text-foreground`,children:O}),`/proxy/{provider}/{provider_path}`]})]})]}),(0,I.jsx)($E,{children:(0,I.jsx)(J,{onClick:he,children:`I’ve saved this key`})})]})})]})}function QD({steps:e,current:t,onSelect:n}){return(0,I.jsx)(`ol`,{className:`flex items-center gap-2`,"aria-label":`Steps`,children:e.map((e,r)=>{let i=r<t,a=r===t,o=(0,I.jsx)(`span`,{className:H(`block size-2 rounded-full transition-colors`,a?`bg-primary`:i?`bg-primary/40`:`bg-border`)});return(0,I.jsx)(`li`,{"aria-current":a?`step`:void 0,children:i?(0,I.jsx)(`button`,{type:`button`,"aria-label":`Back to ${e.label}`,className:`flex size-5 items-center justify-center rounded-full hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,onClick:()=>n(r),children:o}):(0,I.jsx)(`span`,{className:`flex size-5 items-center justify-center`,"aria-label":`${e.label}${a?`, current step`:``}`,children:o})},e.id)})})}function $D({label:e,children:t}){return(0,I.jsxs)(Rb,{children:[(0,I.jsx)(zb,{asChild:!0,children:(0,I.jsx)(J,{variant:`ghost`,size:`icon-sm`,"aria-label":`Actions for ${e}`,children:(0,I.jsx)(_a,{})})}),(0,I.jsx)(Bb,{align:`end`,className:`min-w-44`,children:t})]})}function eO({reason:e,destructive:t,onSelect:n,children:r}){let{readOnly:i}=sx(),a=(0,v.useId)(),o=e??(i?`Your role is read-only. Ask an owner or admin to make this change.`:void 0),s=t?`destructive`:`default`;return o?(0,I.jsx)(rw,{reason:o,reasonId:a,className:`w-full`,children:(0,I.jsx)(Vb,{variant:s,disabled:!0,"aria-describedby":a,className:`w-full`,children:r})}):(0,I.jsx)(Vb,{variant:s,onSelect:n,children:r})}var tO={"data-1p-ignore":`true`,"data-lpignore":`true`},nO={autoComplete:`off`,...tO},rO={type:`password`,autoComplete:`new-password`,spellCheck:!1,...tO};function iO(e){return Object.entries(e??{}).map(([e,t])=>({model:e,input:String(t.input),output:String(t.output)}))}function aO(e){let t={};for(let n of e){let e=n.model.trim(),r=n.input.trim(),i=n.output.trim();if(!e&&!r&&!i)continue;if(!e)return{error:`Every pricing row needs a model name`};if(!r||!i)return{error:`Enter both prices for ${e} — use 0 only if it is genuinely free`};let a=Number(r),o=Number(i);if(!Number.isFinite(a)||a<0||!Number.isFinite(o)||o<0)return{error:`Prices for ${e} must be numbers of 0 or more`};if(Object.hasOwn(t,e))return{error:`${e} is priced twice — remove the duplicate row`};t[e]={input:a,output:o}}return{pricing:t}}function oO(e,t){return e instanceof Error?e.message:t}var sO=e=>`gateway-${e}`,cO=`/providers/gateways`;function lO(e){if(e.referencedCount!==0)return e.providerCount===0?`Disabled provider instances still reference this gateway; delete them to release it`:e.referencedCount>e.providerCount?`Delete the active and disabled provider instances routed through this gateway first`:`Delete every active provider instance routed through this gateway first`}function uO({label:e,value:t}){return(0,I.jsxs)(`div`,{children:[e,`: `,(0,I.jsx)(`span`,{className:`font-mono text-xs`,children:t})]})}function dO({row:e,gateways:t}){if(e.providerGatewayId===null)return(0,I.jsxs)(`div`,{className:`space-y-0.5`,children:[e.secretHint===null?(0,I.jsx)(`div`,{children:`API key`}):(0,I.jsx)(uO,{label:`API key`,value:`…${e.secretHint}`}),e.baseUrl===null?null:(0,I.jsx)(uO,{label:`Base URL`,value:e.baseUrl})]});let n=t.find(t=>t.id===e.providerGatewayId);return n?(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[`Gateway:`,(0,I.jsx)(NT,{type:n.type}),(0,I.jsx)(Pn,{className:`text-primary-ink underline underline-offset-4`,to:`${cO}#${sO(n.id)}`,children:n.name})]}):(0,I.jsx)(I.Fragment,{children:`Gateway`})}function fO({gateway:e}){return(0,I.jsxs)(`div`,{className:`space-y-0.5`,children:[e.type===`cf_aig`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(uO,{label:`Account ID`,value:e.config.accountId}),(0,I.jsx)(uO,{label:`Gateway ID`,value:e.config.gatewayId})]}):null,(0,I.jsx)(uO,{label:`API key`,value:`…${e.secretHint}`})]})}var pO=[{slug:`providers`,path:`/providers`,Component:vO},{slug:`gateways`,path:cO,Component:OO}],mO=pO[0];function hO(){return(0,I.jsx)(Lb,{variant:`outline`,className:`border-muted-foreground/30 text-muted-foreground`,children:`disabled`})}function gO({slug:e,names:t}){return t.length===0?null:(0,I.jsxs)(`p`,{children:[(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:t.join(`, `)}),` `,t.length===1?`names`:`name`,` `,(0,I.jsx)(`span`,{className:`font-mono text-foreground`,children:e}),` in its configuration.`]})}function _O(){let{section:e}=_t(),t=e===void 0?mO:pO.find(t=>t.slug===e);return t?(0,I.jsx)(t.Component,{}):(0,I.jsx)(Vt,{to:mO.path,replace:!0})}function vO(){let{readOnly:e}=sx(),t=dS(),n=_S(),r=wS(),i=CS(),a=jS(yC()),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(null),g=t.data?.providers??[],_=n.data?.gateways??[],y=e=>(a.data?.apps??[]).filter(t=>t.referenced_providers.includes(e)).map(e=>e.name),b=async()=>{if(f)try{await r.mutateAsync(f.id),U.success(`Deleted ${f.name}`),p(null)}catch(e){U.error(oO(e,`Could not delete the provider`))}},x=async()=>{if(m)try{await i.mutateAsync({id:m.id,body:{status:`disabled`}}),U.success(`Disabled ${m.name}`),h(null)}catch(e){U.error(oO(e,`Could not disable the provider`))}},S=async e=>{try{await i.mutateAsync({id:e.id,body:{status:`active`}}),U.success(`Enabled ${e.name}`)}catch(e){U.error(oO(e,`Could not enable the provider`))}};return(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsx)(cw,{title:`Providers`,description:`Set up the AI providers your apps use.`,action:(0,I.jsxs)(iw,{size:`sm`,onClick:()=>s(!0),children:[(0,I.jsx)(Na,{className:`size-4`}),`Add provider`]})}),t.isError?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`Could not load providers`}),(0,I.jsx)(ks,{children:oO(t.error,`Unknown error`)})]}):null,(0,I.jsx)(nE,{className:`overflow-hidden py-0`,children:(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{children:[(0,I.jsx)(Z,{children:`Name`}),(0,I.jsx)(Z,{children:`Provider`}),(0,I.jsx)(Z,{children:`Slug`}),(0,I.jsx)(Z,{children:`Auth`}),(0,I.jsx)(Z,{className:`text-right`,children:`Actions`})]})}),(0,I.jsx)(lE,{children:t.isPending?[0,1,2].map(e=>(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:5,children:(0,I.jsx)(aw,{className:`h-5 w-full`})})},e)):g.length===0?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:5,className:`py-10 text-center text-sm text-muted-foreground`,children:`No providers yet. Add a key per provider, or route one through a gateway.`})}):g.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{className:`font-medium`,children:(0,I.jsxs)(`span`,{className:`flex items-center gap-2`,children:[e.name,e.status===`disabled`?(0,I.jsx)(hO,{}):null]})}),(0,I.jsx)(Q,{children:(0,I.jsxs)(Lb,{variant:`secondary`,children:[(0,I.jsx)(MT,{type:e.type}),eT[e.type]]})}),(0,I.jsx)(Q,{className:`font-mono text-xs`,children:e.slug}),(0,I.jsx)(Q,{className:`text-sm text-muted-foreground`,children:(0,I.jsx)(dO,{row:e,gateways:_})}),(0,I.jsx)(Q,{className:`text-right`,children:(0,I.jsxs)($D,{label:e.name,children:[(0,I.jsxs)(Vb,{onSelect:()=>l(e),children:[(0,I.jsx)(da,{}),`Pricing`]}),(0,I.jsxs)(eO,{reason:e.providerGatewayId===null?void 0:`This instance authenticates with the gateway token — update the gateway's token instead`,onSelect:()=>d(e),children:[(0,I.jsx)(Pa,{}),`Update key`]}),(0,I.jsx)(Gb,{}),e.status===`disabled`?(0,I.jsxs)(eO,{onSelect:()=>void S(e),children:[(0,I.jsx)(fa,{}),`Enable provider`]}):(0,I.jsxs)(eO,{onSelect:()=>h(e),children:[(0,I.jsx)(pa,{}),`Disable provider`]}),(0,I.jsxs)(eO,{destructive:!0,onSelect:()=>p(e),children:[(0,I.jsx)(Ga,{}),`Delete provider`]})]})})]},e.id))})]})}),(0,I.jsx)(EO,{open:o,onOpenChange:s,providers:g,gateways:_}),(0,I.jsx)(MO,{provider:u,onClose:()=>d(null)},u?.id),(0,I.jsx)(NO,{provider:c,onClose:()=>l(null),readOnly:e}),(0,I.jsx)(VD,{open:f!==null,onOpenChange:e=>{e||p(null)},title:`Delete provider`,description:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`p`,{children:[`Apps using`,` `,(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:f?eT[f.type]:``}),` `,`start failing within a minute, and any custom pricing on this provider is deleted with it.`]}),f?(0,I.jsx)(gO,{slug:f.slug,names:y(f.slug)}):null,(0,I.jsx)(`p`,{children:`This cannot be undone. Update the key instead if you only want to replace it, or disable the provider to pause it and keep the key.`})]}),confirmLabel:`Delete provider`,destructive:!0,pending:r.isPending,onConfirm:()=>void b()}),(0,I.jsx)(VD,{open:m!==null,onOpenChange:e=>{e||h(null)},title:`Disable provider`,description:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`p`,{children:[`Requests to`,` `,(0,I.jsx)(`span`,{className:`font-mono text-foreground`,children:m?.slug??``}),` start failing within a minute.`]}),m?(0,I.jsx)(gO,{slug:m.slug,names:y(m.slug)}):null]}),confirmLabel:`Disable provider`,pending:i.isPending,onConfirm:()=>void x()})]})}var yO=`__new__`,bO={works:{icon:la,className:`bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`},unconfirmed:{icon:xa,className:`bg-muted text-muted-foreground`},failed:{icon:ca,className:`bg-destructive/10 text-destructive`}};function xO(e){return e.reason===`unexpected_status`&&e.status!==void 0&&e.status<500&&e.status!==429}function SO(e,t,n){let r=eT[t],i=n?`The gateway`:r;switch(e.reason){case`no_probe`:return`There is no test call for ${r}, so nothing was checked. Add it if you know it is right.`;case`unreachable`:return`${i} did not answer in time, so nothing is proven either way.`;case`unexpected_status`:return xO(e)?n?`The gateway answered with HTTP ${e.status}. Check that it holds a stored key for ${r}.`:`${r} answered with HTTP ${e.status}, so this key could not be used.`:`${i} answered with HTTP ${e.status}, so nothing is proven either way.`;default:return`Nothing is proven either way. Add it if you know it is right.`}}function CO(e,t,n){if(e.validated)return{status:`works`,message:`Works. The provider accepted this credential.`};let r=SO(e,t,n);return xO(e)?{status:`failed`,message:r}:{status:`unconfirmed`,message:r}}function wO(e){if(e.validated)return{status:`works`,message:`Works. The gateway accepted this token.`};if(e.reason===`rejected`)return{status:`failed`,message:`The gateway refused this token (HTTP ${e.status}). Check the token itself, that authentication is turned on, and that the gateway holds a key for OpenAI.`};if(e.reason===`unreachable`)return{status:`unconfirmed`,message:`The gateway did not answer in time, so nothing is proven either way.`};let t=e.reason===`unexpected_status`?`The gateway answered with HTTP ${e.status}. Check the account and gateway IDs.`:`Nothing is proven either way. Add it if you know it is right.`;return{status:xO(e)?`failed`:`unconfirmed`,message:t}}function TO({outcome:e}){let{icon:t,className:n}=bO[e.status];return(0,I.jsxs)(`p`,{"aria-live":`polite`,className:H(`flex items-start gap-2 rounded-md px-3 py-2 text-xs`,n),children:[(0,I.jsx)(t,{className:`mt-px size-3.5 shrink-0`}),e.message]})}function EO({open:e,onOpenChange:t,providers:n,gateways:r}){let i=mS(),a=hS(),[o,s]=(0,v.useState)(`openai`),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(`key`),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(``),[g,_]=(0,v.useState)(``),[y,b]=(0,v.useState)(``),[x,S]=(0,v.useState)(!1),[C,w]=(0,v.useState)(!1),[T,E]=(0,v.useState)(null),[ee,D]=(0,v.useState)(null),O=(0,v.useRef)(null),k=(0,v.useRef)(!1);(0,v.useEffect)(()=>{!k.current||!O.current||(k.current=!1,O.current.focus())});let A=r.filter(e=>e.status===`active`),j=T&&!A.some(e=>e.id===T.id)?[...A,T]:A,te=e=>n.some(t=>t.slug===e),ne=x||te(o),M=e=>{s(e),S(!1),D(null),te(e)?k.current=!0:b(``)},N=u===`key`?!!f:!!g,P=!!c.trim()&&N&&(!ne||!!y.trim()),re=()=>{s(`openai`),l(``),d(`key`),p(``),h(``),_(``),b(``),S(!1),E(null),D(null),i.reset(),a.reset()},ie=()=>{re(),t(!1)},ae=u===`key`&&m.trim()?{baseUrl:m.trim()}:{},oe=async()=>{if(N){D(null);try{let e=await a.mutateAsync({type:o,...u===`key`?{secret:f,...ae}:{providerGatewayId:g}});D(CO(e,o,u===`gateway`))}catch(e){D({status:`failed`,message:oO(e,`The credential could not be checked`)})}finally{a.reset()}}},F=async()=>{if(P)try{await i.mutateAsync({type:o,name:c.trim(),...y.trim()?{slug:y.trim()}:{},...u===`key`?{secret:f,...ae}:{providerGatewayId:g}}),ie(),U.success(`Added ${eT[o]}`)}catch(e){p(``),e instanceof ux&&e.code===`slug_taken`&&(S(!0),k.current=!0),U.error(oO(e,`Could not store the credential`))}};return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(nD,{open:e,onOpenChange:e=>e?t(!0):ie(),title:`Add a provider`,submitLabel:`Add provider`,pending:i.isPending,disabled:!P,onSubmit:()=>void F(),secondaryAction:(0,I.jsxs)(J,{type:`button`,variant:`secondary`,className:`sm:mr-auto`,disabled:!N||a.isPending,onClick:()=>void oe(),children:[a.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Test provider`]}),children:(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsx)(sw,{label:`Name`,htmlFor:`provider-name`,hint:`How this provider is named in the list.`,children:(0,I.jsx)($,{id:`provider-name`,...nO,value:c,placeholder:`Prod OpenAI`,autoFocus:!0,onChange:e=>l(e.target.value)})}),(0,I.jsx)(sw,{label:`Provider`,htmlFor:`provider-type`,children:(0,I.jsxs)(zT,{value:o,onValueChange:e=>M(e),children:[(0,I.jsx)(VT,{id:`provider-type`,className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:$w.map(e=>(0,I.jsx)(UT,{value:e,children:(0,I.jsx)(FT,{type:e})},e))})]})}),(0,I.jsx)(sw,{label:`Authentication`,htmlFor:`provider-authentication`,hint:`Call the provider directly, or route through a gateway.`,children:(0,I.jsxs)(zT,{value:u,onValueChange:e=>{d(e),e===`gateway`&&h(``),D(null)},children:[(0,I.jsx)(VT,{id:`provider-authentication`,className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsxs)(HT,{children:[(0,I.jsxs)(UT,{value:`key`,children:[(0,I.jsx)(Sa,{}),`API key`]}),(0,I.jsxs)(UT,{value:`gateway`,children:[(0,I.jsx)(ta,{}),`Use gateway`]})]})]})}),u===`key`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(sw,{label:`API key`,htmlFor:`provider-secret`,children:(0,I.jsx)($,{id:`provider-secret`,...rO,value:f,placeholder:`sk-…`,onChange:e=>{p(e.target.value),D(null)}})}),(0,I.jsx)(sw,{label:`Base URL (optional)`,htmlFor:`provider-base-url`,hint:`Point this instance at an OpenAI-compatible endpoint you control — Azure OpenAI, vLLM, a proxy. HTTPS, port 443, no path-only tweaks beyond the base. Leave empty to use the provider's own API.`,children:(0,I.jsx)($,{id:`provider-base-url`,...nO,className:`font-mono`,value:m,placeholder:`https://my-vllm.example.com/v1/`,onChange:e=>{h(e.target.value),D(null)}})})]}):(0,I.jsx)(sw,{label:`Gateway`,htmlFor:`provider-gateway`,hint:`The provider's own key lives in that gateway; this row carries no secret.`,children:(0,I.jsxs)(zT,{value:g,onValueChange:e=>{if(e){if(e===yO){w(!0);return}_(e),D(null)}},children:[(0,I.jsx)(VT,{id:`provider-gateway`,className:`w-full`,children:(0,I.jsx)(BT,{placeholder:j.length?`Choose a gateway`:`No gateways yet`})}),(0,I.jsxs)(HT,{children:[j.map(e=>(0,I.jsx)(UT,{value:e.id,children:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,I.jsx)(NT,{type:e.type}),e.name]})},e.id)),j.length?(0,I.jsx)(WT,{}):null,(0,I.jsxs)(UT,{value:yO,className:`font-medium text-primary-ink focus:text-primary-ink`,children:[(0,I.jsx)(Na,{className:`size-4 text-primary-ink`}),`New gateway…`]})]})]})}),ne?(0,I.jsx)(sw,{label:`Slug`,htmlFor:`provider-slug`,hint:(0,I.jsxs)(I.Fragment,{children:[`Another instance already uses `,(0,I.jsx)(`code`,{className:`font-mono`,children:o}),`, so this one needs its own `,(0,I.jsx)(`code`,{className:`font-mono`,children:`/proxy/<slug>/…`}),` `,`segment.`]}),children:(0,I.jsx)($,{id:`provider-slug`,ref:O,...nO,className:`font-mono`,value:y,placeholder:`${o}-dev`,onChange:e=>b(e.target.value)})}):null,ee?(0,I.jsx)(TO,{outcome:ee}):null]})}),(0,I.jsx)(kO,{open:C,onOpenChange:w,onCreated:e=>{E(e),_(e.id)}})]})}function DO({label:e=`Add provider`}){let[t,n]=(0,v.useState)(!1),r=dS(),i=_S(t);return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(iw,{size:`sm`,onClick:()=>n(!0),children:e}),(0,I.jsx)(EO,{open:t,onOpenChange:n,providers:r.data?.providers??[],gateways:i.data?.gateways??[]})]})}function OO(){let e=_S(),[t,n]=(0,v.useState)(!1),[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(null),l=SS(),u=e.data?.gateways??[],d=e.isError?e.error:null,{hash:f}=dt();(0,v.useEffect)(()=>{f&&document.getElementById(f.slice(1))?.scrollIntoView({behavior:`smooth`,block:`center`})},[f,e.data]);let p=async()=>{if(s)try{await l.mutateAsync(s.id),U.success(`Deleted ${s.name}`),c(null)}catch(e){U.error(oO(e,`Could not delete the gateway`))}};return(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsx)(cw,{title:`Gateways`,description:`Set up the gateways you use to reach AI providers.`,action:(0,I.jsxs)(iw,{size:`sm`,onClick:()=>n(!0),children:[(0,I.jsx)(Na,{className:`size-4`}),`Add gateway`]})}),d?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`Could not load gateways`}),(0,I.jsx)(ks,{children:oO(d,`Unknown error`)})]}):null,(0,I.jsx)(nE,{className:`overflow-hidden py-0`,children:(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{children:[(0,I.jsx)(Z,{children:`Name`}),(0,I.jsx)(Z,{children:`Type`}),(0,I.jsx)(Z,{children:`Auth`}),(0,I.jsx)(Z,{className:`text-right`,children:`Actions`})]})}),(0,I.jsx)(lE,{children:e.isPending?[0,1].map(e=>(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:4,children:(0,I.jsx)(aw,{className:`h-5 w-full`})})},e)):u.length===0?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:4,className:`py-10 text-center text-sm text-muted-foreground`,children:`No gateways yet. Add one to route providers through it.`})}):u.map(e=>(0,I.jsxs)(uE,{id:sO(e.id),children:[(0,I.jsx)(Q,{className:`font-medium`,children:e.name}),(0,I.jsx)(Q,{children:(0,I.jsxs)(Lb,{variant:`secondary`,children:[(0,I.jsx)(NT,{type:e.type}),tT[e.type]]})}),(0,I.jsx)(Q,{className:`text-sm text-muted-foreground`,children:(0,I.jsx)(fO,{gateway:e})}),(0,I.jsx)(Q,{className:`text-right`,children:(0,I.jsxs)($D,{label:e.name,children:[(0,I.jsxs)(eO,{onSelect:()=>o(e),children:[(0,I.jsx)(Pa,{}),`Update token`]}),(0,I.jsxs)(eO,{onSelect:()=>i(e),children:[(0,I.jsx)(ja,{}),`Rename`]}),(0,I.jsx)(Gb,{}),(0,I.jsxs)(eO,{destructive:!0,reason:lO(e),onSelect:()=>c(e),children:[(0,I.jsx)(Ga,{}),`Delete gateway`]})]})})]},e.id))})]})}),(0,I.jsx)(kO,{open:t,onOpenChange:n}),(0,I.jsx)(AO,{gateway:r,onClose:()=>i(null)}),(0,I.jsx)(jO,{gateway:a,onClose:()=>o(null)}),(0,I.jsx)(VD,{open:s!==null,onOpenChange:e=>{e||c(null)},title:`Delete gateway`,description:(0,I.jsxs)(`p`,{children:[`The stored token for`,` `,(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:s?.name}),` is destroyed. Nothing routes through it, so no traffic changes.`]}),confirmLabel:`Delete gateway`,destructive:!0,pending:l.isPending,onConfirm:()=>void p()})]})}function kO({open:e,onOpenChange:t,onCreated:n}){let r=yS(),i=gS(),[a,o]=(0,v.useState)(nT[0].value),s=nT.find(e=>e.value===a)??nT[0],[c,l]=(0,v.useState)(s.defaultName),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(``),[g,_]=(0,v.useState)(null),y=!!(m&&(!s.needsCloudflareIds||u.trim()&&f.trim())),b=!!c.trim()&&y,x=()=>{o(nT[0].value),l(nT[0].defaultName),d(``),p(``),h(``),_(null),r.reset(),i.reset()},S=async()=>{if(y){_(null);try{let e=await i.mutateAsync(s.value===`cf_aig`?{type:`cf_aig`,accountId:u.trim(),gatewayId:f.trim(),token:m}:{type:`vercel`,token:m});_(wO(e))}catch(e){_({status:`failed`,message:oO(e,`The connection could not be checked`)})}finally{i.reset()}}},C=e=>{let t=nT.find(t=>t.value===e);t&&(o(e),l(t.defaultName),d(``),p(``),h(``),_(null))},w=()=>{x(),t(!1)},T=async()=>{if(b)try{let e=await r.mutateAsync(s.value===`cf_aig`?{type:`cf_aig`,name:c.trim(),accountId:u.trim(),gatewayId:f.trim(),token:m}:{type:`vercel`,name:c.trim(),token:m});x(),U.success(`Added ${e.gateway.name}`),n?.(e.gateway),t(!1)}catch(e){h(``),U.error(oO(e,`Could not add the gateway`))}};return(0,I.jsx)(nD,{open:e,onOpenChange:e=>e?t(!0):w(),title:`Add gateway`,submitLabel:`Add gateway`,pending:r.isPending,disabled:!b,onSubmit:()=>void T(),secondaryAction:(0,I.jsxs)(J,{type:`button`,variant:`secondary`,className:`sm:mr-auto`,disabled:!y||i.isPending,onClick:()=>void S(),children:[i.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Test gateway`]}),children:(0,I.jsxs)(`div`,{className:`space-y-4`,children:[nT.length>1?(0,I.jsx)(sw,{label:`Gateway type`,htmlFor:`gateway-type`,children:(0,I.jsxs)(zT,{value:a,onValueChange:e=>C(e),children:[(0,I.jsx)(VT,{id:`gateway-type`,className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:nT.map(e=>(0,I.jsx)(UT,{value:e.value,children:(0,I.jsx)(IT,{type:e.value})},e.value))})]})}):null,(0,I.jsx)(sw,{label:`Name`,htmlFor:`gateway-name`,children:(0,I.jsx)($,{id:`gateway-name`,...nO,value:c,onChange:e=>l(e.target.value)})}),s.needsCloudflareIds?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(sw,{label:`Cloudflare Account ID`,htmlFor:`gateway-account`,children:(0,I.jsx)($,{id:`gateway-account`,...nO,value:u,onChange:e=>{d(e.target.value),_(null)}})}),(0,I.jsx)(sw,{label:`Cloudflare Gateway ID`,htmlFor:`gateway-gateway`,children:(0,I.jsx)($,{id:`gateway-gateway`,...nO,value:f,onChange:e=>{p(e.target.value),_(null)}})})]}):null,(0,I.jsx)(sw,{label:`Gateway token`,htmlFor:`gateway-token`,hint:(0,I.jsx)(`a`,{className:`underline underline-offset-4`,href:s.tokenDocsUrl,target:`_blank`,rel:`noreferrer`,children:`How to create the token`}),children:(0,I.jsx)($,{id:`gateway-token`,...rO,value:m,onChange:e=>{h(e.target.value),_(null)}})}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:s.credentialNote}),g?(0,I.jsx)(TO,{outcome:g}):null]})})}function AO({gateway:e,onClose:t}){let n=bS(),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(null);e&&a!==e.id&&(o(e.id),i(e.name));let s=()=>{o(null),t()},c=async()=>{if(!(!e||!r.trim()))try{await n.mutateAsync({id:e.id,name:r.trim()}),U.success(`Renamed to ${r.trim()}`),s()}catch(e){U.error(oO(e,`Could not rename the gateway`))}};return(0,I.jsx)(KE,{open:e!==null,onOpenChange:e=>e?void 0:s(),children:(0,I.jsxs)(XE,{className:`sm:max-w-md`,children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{children:`Rename gateway`})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[(0,I.jsx)(tD,{children:`Only the display name changes. Nothing about the connection or the providers routed through it moves.`}),(0,I.jsx)(sw,{label:`Name`,htmlFor:`gateway-rename`,children:(0,I.jsx)($,{id:`gateway-rename`,...nO,value:r,onChange:e=>i(e.target.value)})})]}),(0,I.jsxs)($E,{children:[(0,I.jsx)(J,{variant:`outline`,onClick:s,children:`Cancel`}),(0,I.jsxs)(J,{disabled:!r.trim()||n.isPending,onClick:()=>void c(),children:[n.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Save name`]})]})]})})}function jO({gateway:e,onClose:t}){let n=xS(),r=gS(),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(null),c=()=>{a(``),s(null),n.reset(),r.reset(),t()},l=async()=>{if(!(!e||!i)){s(null);try{let t=await r.mutateAsync(e.type===`cf_aig`?{type:`cf_aig`,accountId:e.config.accountId,gatewayId:e.config.gatewayId,token:i}:{type:`vercel`,token:i});s(wO(t))}catch(e){s({status:`failed`,message:oO(e,`The connection could not be checked`)})}finally{r.reset()}}},u=async()=>{if(!(!e||!i))try{await n.mutateAsync({id:e.id,token:i}),a(``),s(null),n.reset(),U.success(`Updated the token for ${e.name}`),t()}catch(e){a(``),U.error(oO(e,`Could not update the gateway token`))}};return(0,I.jsx)(KE,{open:e!==null,onOpenChange:e=>e?void 0:c(),children:(0,I.jsxs)(XE,{className:`sm:max-w-md`,children:[(0,I.jsx)(ZE,{children:(0,I.jsxs)(eD,{children:[`Update the token for `,e?.name]})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[(0,I.jsxs)(tD,{children:[`One token authenticates every provider routed through this gateway, so all`,` `,e?.providerCount??0,` of them pick the new one up within a minute.`]}),(0,I.jsx)(sw,{label:`New gateway token`,htmlFor:`gateway-rotate-token`,children:(0,I.jsx)($,{id:`gateway-rotate-token`,...rO,value:i,onChange:e=>{a(e.target.value),s(null)}})}),o?(0,I.jsx)(TO,{outcome:o}):null]}),(0,I.jsxs)($E,{children:[(0,I.jsxs)(J,{type:`button`,variant:`secondary`,className:`sm:mr-auto`,disabled:!i||r.isPending,onClick:()=>void l(),children:[r.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Test token`]}),(0,I.jsx)(J,{variant:`outline`,onClick:c,children:`Cancel`}),(0,I.jsxs)(J,{disabled:!i||n.isPending,onClick:()=>void u(),children:[n.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Update token`]})]})]})})}function MO({provider:e,onClose:t}){let n=CS(),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(e?.baseUrl??``),s=()=>{i(``),n.reset(),t()},c=a.trim(),l=e&&c!==(e.baseUrl??``)?{baseUrl:c===``?null:c}:{},u=async()=>{if(!(!e||!r))try{await n.mutateAsync({id:e.id,body:{secret:r,...l}}),i(``),n.reset(),U.success(`Updated the key for ${e.name}`),t()}catch(e){i(``),U.error(oO(e,`Could not update the credential`))}};return(0,I.jsx)(KE,{open:e!==null,onOpenChange:e=>e?void 0:s(),children:(0,I.jsxs)(XE,{className:`sm:max-w-md`,children:[(0,I.jsx)(ZE,{children:(0,I.jsxs)(eD,{children:[`Update the key for `,e?.name]})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[(0,I.jsx)(tD,{children:`The new credential replaces the old one in place. Custom pricing is kept, and requests pick it up within a minute.`}),(0,I.jsx)(sw,{label:`New API key`,htmlFor:`rotate-secret`,children:(0,I.jsx)($,{id:`rotate-secret`,...rO,value:r,onChange:e=>i(e.target.value)})}),(0,I.jsx)(sw,{label:`Base URL`,htmlFor:`rotate-base-url`,hint:`Changing the origin needs the key above, because the stored key is never sent to a new origin. Leave empty to use the provider's own API.`,children:(0,I.jsx)($,{id:`rotate-base-url`,...nO,className:`font-mono`,value:a,placeholder:`https://my-vllm.example.com/v1/`,onChange:e=>o(e.target.value)})})]}),(0,I.jsxs)($E,{children:[(0,I.jsx)(J,{variant:`outline`,onClick:s,children:`Cancel`}),(0,I.jsxs)(J,{disabled:!r||n.isPending,onClick:()=>void u(),children:[n.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Update key`]})]})]})})}function NO({provider:e,onClose:t,readOnly:n}){let r=CS(),[i,a]=(0,v.useState)([]),[o,s]=(0,v.useState)(null);e&&o!==e.id&&(s(e.id),a(iO(e.pricing)));let c=(e,t)=>{a(n=>n.map((n,r)=>r===e?{...n,...t}:n))},l=async()=>{if(!e)return;let n=aO(i);if(`error`in n){U.error(n.error);return}try{await r.mutateAsync({id:e.id,body:{pricing:Object.keys(n.pricing).length?n.pricing:null}}),U.success(`Updated pricing for ${e.name}`),t()}catch(e){U.error(oO(e,`Could not save the pricing`))}};return(0,I.jsx)(KE,{open:e!==null,onOpenChange:e=>{e||(s(null),t())},children:(0,I.jsxs)(XE,{className:`sm:max-w-2xl`,children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{children:`Custom model pricing`})}),(0,I.jsxs)(QE,{className:`space-y-3`,children:[(0,I.jsxs)(tD,{children:[`For models the built-in catalog does not cover, or prices it in a way you disagree with.`,e&&Qw(e.type)?` ${eT[e.type]??e.type} reports the cost of
75
+ `,Fw=[`openai`,`anthropic`,`xai`,`gemini`,`perplexity`,`deepseek`,`groq`,`mistral`,`together`,`fireworks`,`cerebras`,`moonshot`,`huggingface`,`baseten`,`bytedance`,`openrouter`],Iw=[`responses`,`chat_completions`,`anthropic_messages`,`gemini_native`,`audio_transcription`,`other`],Lw={responses:`v1/responses`,chat_completions:`v1/chat/completions`,anthropic_messages:`v1/messages`,gemini_native:`v1beta/models/{model}:generateContent`,audio_transcription:`v1/audio/transcriptions`},Rw=[`responses`,`transcription`],zw={responses:`responses`,transcription:`audio_transcription`},Bw=[`responses`,`chat_completions`,`gemini_native`,`anthropic`,`none`],Vw={apiStyles:Iw,endpointStyles:[]},Hw={openai:{apiStyles:Iw,endpointStyles:[`responses`,`transcription`]},xai:{apiStyles:Iw,endpointStyles:[`responses`,`transcription`]},openrouter:{apiStyles:[`chat_completions`],endpointStyles:[]}};function Uw(e){return Hw[e]??Vw}var Ww=Fw.filter(e=>Uw(e).endpointStyles.length>0);function Gw(e){return Ww.filter(t=>Uw(t).endpointStyles.includes(e))}var Kw={openai:{slug:`openai`,stripPathPrefix:`v1/`},anthropic:{slug:`anthropic`},xai:{slug:`grok`},gemini:{slug:`google-ai-studio`},perplexity:{slug:`perplexity-ai`}},qw=[`responses`,`chat_completions`,`anthropic_messages`],Jw=[`responses`];function Yw(e){return{modelPrefix:e,apiStyles:qw,endpointStyles:Jw}}var Xw={cf_aig:Kw,vercel:{openai:Yw(`openai/`),anthropic:Yw(`anthropic/`),gemini:Yw(`google/`),xai:Yw(`spacexai/`),perplexity:Yw(`perplexity/`),deepseek:Yw(`deepseek/`),moonshot:Yw(`moonshotai/`)}},Zw=[`openrouter`];function Qw(e){return Zw.includes(e)}var $w=Fw,eT={openai:`OpenAI`,anthropic:`Anthropic`,xai:`xAI`,gemini:`Gemini`,perplexity:`Perplexity`,deepseek:`DeepSeek`,groq:`Groq`,mistral:`Mistral`,together:`Together AI`,fireworks:`Fireworks AI`,cerebras:`Cerebras`,moonshot:`Moonshot AI`,huggingface:`Hugging Face`,baseten:`Baseten`,bytedance:`ByteDance Ark`,openrouter:`OpenRouter`},tT={cf_aig:`Cloudflare AI Gateway`,vercel:`Vercel AI Gateway`},nT=[{value:`cf_aig`,label:tT.cf_aig,defaultName:`Our CF gateway`,tokenDocsUrl:`https://developers.cloudflare.com/ai-gateway/configuration/authentication/`,needsCloudflareIds:!0,credentialNote:`Requests use the provider keys stored in your Cloudflare AI Gateway's own key store.`},{value:`vercel`,label:tT.vercel,defaultName:`Our Vercel gateway`,tokenDocsUrl:`https://vercel.com/docs/ai-gateway/authentication-and-byok/api-keys`,needsCloudflareIds:!1,credentialNote:`Your provider credential stored in Vercel is preferred. Vercel may fall back to system credentials.`}],rT=Bw,iT=`x-end-user-id`;function aT(e,t){let n=Object.keys(t?.[e.type]??{}),r=Object.keys(e.pricing??{});return[...n,...r.filter(e=>!n.includes(e))]}var oT=Gw;function sT(e,t,n){let r=oT(e);return t.filter(t=>r.includes(t.type)&&(n?.(t,e)??!0))}var cT=/^[a-z0-9-]{1,64}$/,lT=e=>e.end_user?.source===`issuer`?e.end_user.issuer:void 0;function uT(){return{provider:`firebase`,jwks_url:``,issuer:``,audience:``,user_id_claim:`sub`,required_claims:[],max_token_lifetime_seconds:86400}}function dT(e,t){if(e.type===`apple_app_attest`)return{...e,end_user:{source:`issuer`,issuer:t??lT(e)??uT()}};if(!t){let{end_user:t,...n}=e;return n}return{...e,end_user:{source:`issuer`,issuer:t}}}var fT=e=>typeof e==`string`?{path:e}:e;function pT(e){return!e.fixed_model&&(!e.clamp||e.clamp===void 0)?e.path:{path:e.path,...e.fixed_model?{fixed_model:e.fixed_model}:{},...e.clamp?{clamp:e.clamp}:{}}}function mT(){return{allowed_paths:[],allowed_models:[]}}function hT(e=`openai`){return{api_style:`responses`,provider:e,model:``}}function gT(e,t=`endpoint`){if(e[t]===void 0)return t;for(let n=2;n<1e3;n+=1){let r=`${t}-${n}`;if(e[r]===void 0)return r}return`${t}-${Date.now()}`}function _T(e,t,n){return Object.fromEntries(Object.entries(e).map(([e,r])=>[e===t?n:e,r]))}function vT(e,t,n){return cT.test(e)?e!==n&&t[e]!==void 0?`Another endpoint already uses this slug`:null:`Use 1-64 characters from a-z, 0-9, and -`}function yT(e){return e.providers.mode}function bT(e){if(yT(e)===`all`)return[];let t=e.providers.selected??{};return Object.keys(t).filter(e=>t[e]!==void 0)}function xT(e){return $w.includes(e)}function ST(e){return Object.hasOwn(tT,e)}function CT(e,t){if(yT(e)===`all`)return[...$w];let n=new Map(t.map(e=>[e.slug,e.type])),r=new Set(bT(e).flatMap(e=>{let t=n.get(e);return t?[t]:xT(e)?[e]:[]}));return $w.filter(e=>r.has(e))}var wT=`size-full text-current`;function TT(e){return e.trim().replace(`<svg`,`<svg class="${wT}"`)}function ET(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,TT(t)]))}var DT=ET({openai:Dw,anthropic:dw,xai:Pw,gemini:Sw,perplexity:kw,deepseek:yw,groq:Cw,mistral:Tw,together:Mw,fireworks:xw,cerebras:gw,moonshot:Ew,huggingface:ww,baseten:mw,bytedance:hw,openrouter:Ow}),OT=ET({cf_aig:_w,vercel:Nw}),kT=ET({firebase:bw,supabase:jw,auth0:pw,clerk:vw,apple:fw,revenuecat:Aw});function AT(e){return Object.hasOwn(kT,e)}function jT({svg:e,className:t}){return(0,I.jsx)(`span`,{"aria-hidden":!0,className:H(`inline-flex size-[1.15em] shrink-0`,t),dangerouslySetInnerHTML:{__html:e}})}function MT({type:e,className:t}){return(0,I.jsx)(jT,{svg:DT[e],className:t})}function NT({type:e,className:t}){return(0,I.jsx)(jT,{svg:OT[e],className:t})}function PT({type:e,className:t}){return(0,I.jsx)(jT,{svg:kT[e],className:t})}function FT({type:e,className:t}){return(0,I.jsxs)(`span`,{className:H(`inline-flex items-center gap-1.5`,t),children:[(0,I.jsx)(MT,{type:e}),eT[e]]})}function IT({type:e,className:t}){return(0,I.jsxs)(`span`,{className:H(`inline-flex items-center gap-1.5`,t),children:[(0,I.jsx)(NT,{type:e}),tT[e]]})}function LT(e,t){if(yT(e)===`all`)return[];let n=t.filter(e=>e.status===`active`),r=new Set(n.map(e=>e.type));return CT(e,n).filter(e=>!r.has(e))}function RT({proxy:e}){let t=dS();if(!t.data)return null;let n=LT(e,t.data.providers);return n.length===0?null:(0,I.jsxs)(Ds,{children:[(0,I.jsx)(ca,{}),(0,I.jsxs)(Os,{children:[`No credential for`,` `,n.map((e,t)=>(0,I.jsxs)(v.Fragment,{children:[t>0?`, `:null,(0,I.jsx)(FT,{type:e,className:`align-middle`})]},e))]}),(0,I.jsxs)(ks,{children:[`This app allows`,` `,n.length===1?`a provider`:`providers`,` you have not configured, so those requests fail with `,(0,I.jsx)(`code`,{className:`font-mono text-xs`,children:`provider_not_configured`}),`.`,` `,(0,I.jsx)(Pn,{to:`/providers`,className:`text-primary-ink underline underline-offset-4`,children:`Add a provider key`}),`.`]})]})}function zT({...e}){return(0,I.jsx)(hv,{"data-slot":`select`,...e})}function BT({...e}){return(0,I.jsx)(yv,{"data-slot":`select-value`,...e})}function VT({className:e,size:t=`default`,children:n,...r}){return(0,I.jsxs)(_v,{"data-slot":`select-trigger`,"data-size":t,className:H(`flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground`,e),...r,children:[n,(0,I.jsx)(bv,{asChild:!0,children:(0,I.jsx)(ia,{className:`size-4 opacity-50`})})]})}function HT({className:e,children:t,position:n=`item-aligned`,align:r=`center`,...i}){return(0,I.jsx)(Cv,{children:(0,I.jsxs)(Tv,{"data-slot":`select-content`,className:H(`relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,n===`popper`&&`data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1`,e),position:n,align:r,...i,children:[(0,I.jsx)(GT,{}),(0,I.jsx)(Lv,{className:H(`p-1`,n===`popper`&&`h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1`),children:t}),(0,I.jsx)(KT,{})]})})}function UT({className:e,children:t,...n}){return(0,I.jsxs)(Uv,{"data-slot":`select-item`,className:H(`relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2`,e),...n,children:[(0,I.jsx)(`span`,{"data-slot":`select-item-indicator`,className:`absolute right-2 flex size-3.5 items-center justify-center`,children:(0,I.jsx)(qv,{children:(0,I.jsx)(ra,{className:`size-4`})})}),(0,I.jsx)(Gv,{children:t})]})}function WT({className:e,...t}){return(0,I.jsx)($v,{"data-slot":`select-separator`,className:H(`pointer-events-none -mx-1 my-1 h-px bg-border`,e),...t})}function GT({className:e,...t}){return(0,I.jsx)(Yv,{"data-slot":`select-scroll-up-button`,className:H(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,I.jsx)(oa,{className:`size-4`})})}function KT({className:e,...t}){return(0,I.jsx)(Zv,{"data-slot":`select-scroll-down-button`,className:H(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,I.jsx)(ia,{className:`size-4`})})}function qT({value:e,onChange:t,months:n=12}){let r=CC(n);return(0,I.jsxs)(zT,{value:e,onValueChange:t,children:[(0,I.jsx)(VT,{className:`w-[180px]`,size:`sm`,"aria-label":`Month`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:r.map(e=>(0,I.jsx)(UT,{value:e,children:SC(e)},e))})]})}var JT=[{value:`7`,label:`Last 7 days`},{value:`30`,label:`Last 30 days`},{value:`90`,label:`Last 90 days`}];function YT({value:e,onChange:t}){return(0,I.jsxs)(zT,{value:e,onValueChange:t,children:[(0,I.jsx)(VT,{className:`w-[150px]`,size:`sm`,"aria-label":`Date range`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:JT.map(e=>(0,I.jsx)(UT,{value:e.value,children:e.label},e.value))})]})}function XT(e){return{name:e.name,config:e.config,status:e.status}}var ZT=e=>e;function QT(e){let t=MS(e),n=NS(e),[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(null),d=(0,v.useRef)(null),f=t.data?.app;(0,v.useEffect)(()=>{if(!f||l===e&&r!==null&&a!==null&&JSON.stringify(r)!==a)return;let t=XT(f);d.current=lT(t.config.authentication)??null,i(t),o(JSON.stringify(t)),c(f.revision),u(e)},[e,f]);let p=l===e?r:null,m=l===e?a:null,h=p!==null&&m!==null&&JSON.stringify(p)!==m,g=(0,v.useCallback)(e=>{i(t=>t&&{...t,...e})},[]),_=(0,v.useCallback)(e=>{i(t=>t&&{...t,config:{...t.config,...e}})},[]);return{query:t,draft:p,dirty:h,update:g,updateConfig:_,updateAuthentication:(0,v.useCallback)(e=>{_({authentication:e})},[_]),updateIssuer:(0,v.useCallback)(e=>{i(t=>{if(!t)return t;let n=t.config.authentication,r=lT(n)??(n.type===`apple_app_attest`?uT():void 0);return r?{...t,config:{...t.config,authentication:dT(n,{...r,...e})}}:t})},[]),setEndUserSource:(0,v.useCallback)(e=>{i(t=>{if(!t)return t;let n=t.config.authentication,r=lT(n);r&&(d.current=r);let i=e===`issuer`?dT(n,r??d.current??uT()):e===`app_install`?n.type===`apple_app_attest`?{...n,end_user:{source:`app_install`}}:n:e===`header`?n.type===`api_key`?{...n,end_user:{source:`header`,header:n.end_user?.source===`header`?n.end_user.header:iT}}:n:dT(n,void 0),a=i.type!==`api_key`||i.end_user!==void 0||t.config.limits===void 0?t.config:{...t.config,limits:{...t.config.limits,per_user:{requests:{per_minute:null,per_day:null},spending:{monthly_usd:null}}}};return{...t,config:{...a,authentication:i}}})},[]),updateEndUserHeader:(0,v.useCallback)(e=>{i(t=>{if(!t)return t;let n=t.config.authentication;return n.type!==`api_key`||n.end_user?.source!==`header`?t:{...t,config:{...t.config,authentication:{...n,end_user:{source:`header`,header:e}}}}})},[]),updateProxy:(0,v.useCallback)(e=>{i(t=>t&&{...t,config:{...t.config,routing:{...t.config.routing,...e}}})},[]),updateLimits:(0,v.useCallback)(e=>_({limits:e}),[_]),updateEndpoints:(0,v.useCallback)(e=>{i(t=>{if(!t)return t;let{endpoints:n,...r}=t.config;return{...t,config:Object.keys(e).length===0?r:{...r,endpoints:e}}})},[]),reset:(0,v.useCallback)(()=>{if(!m)return;let e=JSON.parse(m);d.current=lT(e.config.authentication)??null,i(e)},[m]),save:(0,v.useCallback)(async()=>{if(!p||s===null)return!1;try{let e=await n.mutateAsync({body:ZT(p),revision:s});return c(e.app.revision),o(JSON.stringify(p)),U.success(`Configuration saved`,{description:`The gateway picks it up within the 60 second config cache TTL.`}),!0}catch(e){return U.error(`Save rejected`,{description:e instanceof Error?e.message:`Unknown error`}),!1}},[p,s,n]),saving:n.isPending}}function $T(e){let t=e=>Array.isArray(e)?e.length>0&&e.every(Boolean):!!e;return(e.jwks_url??``).startsWith(`https://`)&&t(e.issuer)&&t(e.audience)}function eE(e){return e.path.trim()?e.equals===void 0?Array.isArray(e.contains)?e.contains.length>0&&e.contains.every(e=>e.trim().length>0):!!e.contains?.trim():String(e.equals).length>0:!1}function tE(e){let t=e.config.authentication;if(!e.name.trim())return`Give the app a name.`;if(t.type===`apple_app_attest`){let{team_id:e,bundle_id:n}=t.app_attest;if(!e.trim()||!n.trim())return`Enter the Apple Team ID and Bundle ID.`}if(t.type===`api_key`&&t.end_user?.source===`header`&&!t.end_user.header.trim())return`Enter the header name.`;let n=lT(t);if(n){if(!$T(n))return`Finish the identity provider details.`;if(!(n.required_claims??[]).every(eE))return`Finish the subscription check.`}return null}function nE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`card`,className:H(`flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm`,e),...t})}function rE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`card-header`,className:H(`@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6`,e),...t})}function iE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`card-title`,className:H(`leading-none font-semibold`,e),...t})}function aE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`card-description`,className:H(`text-sm text-muted-foreground`,e),...t})}function oE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`card-content`,className:H(`px-6`,e),...t})}function sE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`table-container`,className:`relative w-full overflow-x-auto`,children:(0,I.jsx)(`table`,{"data-slot":`table`,className:H(`w-full caption-bottom text-sm [--table-inset:1.5rem]`,`[&_tr>*:first-child]:pl-(--table-inset) [&_tr>*:last-child]:pr-(--table-inset)`,e),...t})})}function cE({className:e,...t}){return(0,I.jsx)(`thead`,{"data-slot":`table-header`,className:H(`[&_tr]:border-b`,e),...t})}function lE({className:e,...t}){return(0,I.jsx)(`tbody`,{"data-slot":`table-body`,className:H(`[&_tr:last-child]:border-0`,e),...t})}function uE({className:e,...t}){return(0,I.jsx)(`tr`,{"data-slot":`table-row`,className:H(`border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted`,e),...t})}function Z({className:e,...t}){return(0,I.jsx)(`th`,{"data-slot":`table-head`,className:H(`h-11 px-3 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t})}function Q({className:e,...t}){return(0,I.jsx)(`td`,{"data-slot":`table-cell`,className:H(`px-3 py-2.5 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t})}function dE({label:e,value:t,detail:n}){return(0,I.jsx)(nE,{className:`gap-0 py-4`,children:(0,I.jsxs)(oE,{className:`px-4`,children:[(0,I.jsx)(`p`,{className:`text-xs font-medium tracking-wide text-muted-foreground uppercase`,children:e}),(0,I.jsx)(`p`,{className:`tabular mt-1.5 text-2xl leading-none font-semibold`,children:t}),n?(0,I.jsx)(`p`,{className:`mt-1.5 text-xs text-muted-foreground`,children:n}):null]})})}function fE(e){return e==null?`—`:e<1e3?`${Math.round(e)} ms`:e<6e4?`${(e/1e3).toFixed(1)} s`:e<36e5?`${Math.round(e/6e4)} min`:`${(e/36e5).toFixed(1)} h`}function pE(e){let t=new Map,n=(e,n,r,i,a)=>{let o=t.get(e)??{outcome:n,reason:r,days:new Map};o.days.set(i,(o.days.get(i)??0)+a),t.set(e,o)};for(let t of e?.daily??[])t.outcome!==`ok`&&n(`auth:${t.outcome}:${t.reason??``}`,t.outcome,t.reason,t.date,t.count);for(let t of e?.usage_failures??[])n(`proxy:${t.status}`,t.status,`proxied request`,t.date,t.count);return[...t.values()].map(e=>({outcome:e.outcome,reason:e.reason,total:[...e.days.values()].reduce((e,t)=>e+t,0),days:[...e.days.entries()].map(([e,t])=>({date:e,count:t})).sort((e,t)=>e.date<t.date?-1:+(e.date>t.date))})).sort((e,t)=>t.total-e.total||(e.outcome<t.outcome?-1:+(e.outcome>t.outcome)))}var mE=[`issuer_claims_missing`,`issuer_token_rejected`,`issuer_verification_unavailable`,`attest_failed`,`auth_required`,`ok`];function hE({appId:e}){let[t,n]=(0,v.useState)(`30`),[r,i]=(0,v.useState)(`all`),[a,o]=(0,v.useState)([]),s=GS(e,Number(t)),c=KS(e,{limit:25,outcome:r===`all`?void 0:r,before_id:a.at(-1)}),l=(0,v.useMemo)(()=>pE(s.data),[s.data]),u=s.data?.claim_delay,d=s.data?.pending_users??0;return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,I.jsx)(dE,{label:`Exchange success`,value:uC(s.data?.token_exchange.success_rate),detail:`${cC(s.data?.token_exchange.total??0)} attempts`}),(0,I.jsx)(dE,{label:`Claim delay p50`,value:fE(u?.p50_ms),detail:`${cC(u?.count??0)} measured`}),(0,I.jsx)(dE,{label:`Claim delay p95`,value:fE(u?.p95_ms),detail:`avg ${fE(u?.avg_ms)}`}),(0,I.jsx)(dE,{label:`Pending activations`,value:cC(d),detail:d>0?`waiting on a claim now`:`none waiting`})]}),(0,I.jsxs)(nE,{className:`py-0`,children:[(0,I.jsx)(rE,{className:`pt-6`,children:(0,I.jsx)(lw,{title:`Failures by cause`,description:`Refused authentication attempts and non-ok proxied requests, busiest first.`,action:(0,I.jsx)(YT,{value:t,onChange:n})})}),(0,I.jsx)(oE,{className:`px-0 pb-0`,children:s.isPending?(0,I.jsx)(`div`,{className:`px-6 pb-6`,children:(0,I.jsx)(aw,{className:`h-24 w-full`})}):l.length===0?(0,I.jsx)(`div`,{className:`px-6 pb-6`,children:(0,I.jsx)(uw,{children:`No failed requests in this range.`})}):(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{className:`hover:bg-transparent`,children:[(0,I.jsx)(Z,{children:`Outcome`}),(0,I.jsx)(Z,{children:`Reason`}),(0,I.jsx)(Z,{className:`text-right`,children:`Count`}),(0,I.jsx)(Z,{className:`text-right`,children:`Days affected`}),(0,I.jsx)(Z,{children:`Last seen`})]})}),(0,I.jsx)(lE,{children:l.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{children:(0,I.jsx)(eC,{outcome:e.outcome})}),(0,I.jsx)(Q,{className:`font-mono text-xs text-muted-foreground`,children:e.reason??`—`}),(0,I.jsx)(Q,{className:`tabular text-right`,children:cC(e.total)}),(0,I.jsx)(Q,{className:`tabular text-right`,children:cC(e.days.length)}),(0,I.jsx)(Q,{className:`text-xs whitespace-nowrap text-muted-foreground`,children:e.days.at(-1)?.date??`—`})]},`${e.outcome}-${e.reason??``}`))})]})})]}),(0,I.jsxs)(nE,{className:`py-0`,children:[(0,I.jsx)(rE,{className:`pt-6`,children:(0,I.jsx)(lw,{title:`Recent attempts`,description:`Every token exchange and key registration, newest first.`,action:(0,I.jsxs)(zT,{value:r,onValueChange:e=>{i(e),o([])},children:[(0,I.jsx)(VT,{className:`w-[210px]`,size:`sm`,"aria-label":`Outcome`,children:(0,I.jsx)(BT,{})}),(0,I.jsxs)(HT,{children:[(0,I.jsx)(UT,{value:`all`,children:`All outcomes`}),mE.map(e=>(0,I.jsx)(UT,{value:e,children:e},e))]})]})})}),(0,I.jsxs)(oE,{className:`px-0 pb-0`,children:[(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{className:`hover:bg-transparent`,children:[(0,I.jsx)(Z,{children:`When`}),(0,I.jsx)(Z,{children:`User`}),(0,I.jsx)(Z,{children:`Call`}),(0,I.jsx)(Z,{children:`Outcome`}),(0,I.jsx)(Z,{children:`Reason`}),(0,I.jsx)(Z,{children:`App version`}),(0,I.jsx)(Z,{className:`text-right`,children:`Latency`}),(0,I.jsx)(Z,{className:`text-right`,children:`Claim delay`})]})}),(0,I.jsx)(lE,{children:c.isPending?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:8,children:(0,I.jsx)(aw,{className:`h-8 w-full`})})}):c.data?.events.length===0?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:8,className:`py-8 text-center text-sm text-muted-foreground`,children:`No attempts.`})}):c.data?.events.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{className:`text-xs whitespace-nowrap text-muted-foreground`,children:mC(e.created_at)}),(0,I.jsx)(Q,{className:`font-mono text-xs`,children:e.user_id??(0,I.jsx)(`span`,{className:`text-muted-foreground`,children:`unknown`})}),(0,I.jsxs)(Q,{className:`font-mono text-xs text-muted-foreground`,children:[e.event,e.auth_method?(0,I.jsx)(`span`,{className:`block`,children:e.auth_method}):null]}),(0,I.jsx)(Q,{children:(0,I.jsx)(eC,{outcome:e.outcome})}),(0,I.jsx)(Q,{className:`font-mono text-xs text-muted-foreground`,children:e.reason??`—`}),(0,I.jsx)(Q,{className:`font-mono text-xs text-muted-foreground`,children:e.app_version??`—`}),(0,I.jsx)(Q,{className:`tabular text-right text-xs`,children:e.latency_ms===null?`—`:`${cC(e.latency_ms)} ms`}),(0,I.jsx)(Q,{className:`tabular text-right text-xs`,children:e.claim_delay_ms===null?`—`:(0,I.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400`,title:`This exchange ended a wait for an entitlement claim to propagate.`,children:fE(e.claim_delay_ms)})})]},e.id))})]}),(0,I.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t px-6 py-3`,children:[(0,I.jsx)(J,{variant:`outline`,size:`sm`,disabled:a.length===0,onClick:()=>o(e=>e.slice(0,-1)),children:`Newer`}),(0,I.jsx)(J,{variant:`outline`,size:`sm`,disabled:!c.data?.next_before_id,onClick:()=>o(e=>[...e,c.data.next_before_id]),children:`Older`})]})]})]})]})}function $({className:e,type:t,...n}){return(0,I.jsx)(`input`,{type:t,"data-slot":`input`,className:H(`h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:bg-input/30`,`focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50`,`aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40`,e),...n})}function gE({className:e,...t}){return(0,I.jsx)(Mf,{"data-slot":`checkbox`,className:H(`peer size-4 shrink-0 rounded-[4px] border border-input shadow-xs transition-shadow outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:bg-input/30 dark:aria-invalid:ring-destructive/40 dark:data-[state=checked]:bg-primary`,e),...t,children:(0,I.jsx)(Pf,{"data-slot":`checkbox-indicator`,className:`grid place-content-center text-current transition-none`,children:(0,I.jsx)(ra,{className:`size-3.5`})})})}var _E=[{value:`production`,label:`Production`,hint:`Builds signed for TestFlight and the App Store.`},{value:`development`,label:`Development`,hint:`Builds run from Xcode, which attest in Apple's development environment.`}];function vE({value:e,onChange:t,compact:n=!1,disabled:r=!1}){let i=e??[`production`],a=i.includes(`development`),o=(e,n)=>{let r=_E.map(e=>e.value).filter(t=>t===e?n:i.includes(t));r.length!==0&&t(r)};return(0,I.jsx)(sw,{label:`iOS app environment`,hint:n?void 0:`Which of Apple's two environments this app accepts attestations from. Removing one also stops the keys it already registered.`,children:(0,I.jsxs)(`div`,{className:`space-y-2`,children:[_E.map(e=>{let t=i.includes(e.value);return(0,I.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,I.jsx)(gE,{id:`env-${e.value}`,checked:t,disabled:r||t&&i.length===1,onCheckedChange:t=>o(e.value,t===!0)}),(0,I.jsxs)(`div`,{className:`-mt-0.5`,children:[(0,I.jsx)(ow,{htmlFor:`env-${e.value}`,className:`text-sm font-normal`,children:e.label}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.hint})]})]},e.value)}),a&&!n?(0,I.jsxs)(`p`,{className:`flex items-start gap-2 rounded-md bg-amber-500/[0.08] p-2.5 text-xs leading-relaxed text-amber-700 dark:text-amber-400`,children:[(0,I.jsx)(Ka,{className:`mt-0.5 size-3.5 shrink-0`}),(0,I.jsx)(`span`,{children:`Any device carrying your team's provisioning profile can attest against this app. Keep this on a development bundle id rather than the one you ship.`})]}):null]})})}function yE({label:e,choices:t,value:n,disabled:r=!1,describedBy:i,onChange:a}){return(0,I.jsx)(`div`,{role:`radiogroup`,"aria-label":e,"aria-describedby":i,className:`space-y-1`,children:t.map(e=>{let t=e.value===n;return(0,I.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":t,disabled:r,onClick:()=>a(e.value),className:H(`flex w-full items-start gap-3.5 rounded-lg px-3 py-3 text-left transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,r?`cursor-not-allowed opacity-60`:`hover:bg-muted/50`),children:[(0,I.jsx)(`span`,{"aria-hidden":`true`,className:H(`mt-0.5 flex size-4.5 shrink-0 items-center justify-center rounded-full border transition-colors`,t?`border-primary`:`border-muted-foreground/50`),children:t?(0,I.jsx)(`span`,{className:`size-2.5 rounded-full bg-primary`}):null}),(0,I.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`span`,{className:`block text-sm font-medium`,children:e.label}),(0,I.jsx)(`span`,{className:`mt-0.5 block text-sm text-muted-foreground`,children:e.description})]})]},e.value)})})}function bE({href:e,children:t}){return(0,I.jsxs)(`a`,{href:e,target:`_blank`,rel:`noreferrer noopener`,className:`inline-flex items-center gap-0.5 underline decoration-border underline-offset-4 transition-colors hover:text-foreground hover:decoration-foreground`,children:[t,(0,I.jsx)(va,{className:`size-3`})]})}function xE({label:e,presets:t,selected:n,values:r,onSelect:i,onValueChange:a,idPrefix:o,compact:s=!1,disabled:c=!1}){let l=!s&&`warning`in n?n.warning:void 0,u=!s&&`note`in n?n.note:void 0,d=`docs`in n?n.docs:void 0,f=n.vendor??n.label;return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`${o}-preset`,children:e}),(0,I.jsxs)(zT,{value:n.id,disabled:c,onValueChange:e=>{let n=t.find(t=>t.id===e);n&&i(n)},children:[(0,I.jsx)(VT,{id:`${o}-preset`,className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:t.map(e=>(0,I.jsx)(UT,{value:e.id,children:(0,I.jsx)(SE,{preset:e})},e.id))})]}),n.description?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n.description}):null]}),n.inputs.map(e=>(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`${o}-${e.key}`,children:e.label}),(0,I.jsx)($,{id:`${o}-${e.key}`,value:r[e.key]??``,placeholder:e.placeholder,className:`font-mono text-xs`,disabled:c,onChange:t=>a(e.key,t.target.value)}),e.hint||e.docs?(0,I.jsxs)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:[e.hint,e.docs?(0,I.jsxs)(I.Fragment,{children:[e.hint?` `:null,(0,I.jsx)(bE,{href:e.docs.href,children:e.docs.label})]}):null]}):null]},e.key)),l?(0,I.jsxs)(`div`,{className:`flex gap-2 rounded-md border border-amber-500/40 bg-amber-500/10 p-3 text-xs leading-relaxed text-amber-700 dark:text-amber-400`,children:[(0,I.jsx)(Ka,{className:`mt-0.5 size-3.5 shrink-0`}),(0,I.jsx)(`span`,{children:l})]}):null,u?(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:u}):null,d?(0,I.jsxs)(`a`,{href:d,target:`_blank`,rel:`noreferrer noopener`,className:`inline-flex items-center gap-1 text-xs text-muted-foreground underline underline-offset-4 hover:text-foreground`,children:[f,` documentation`,(0,I.jsx)(va,{className:`size-3`})]}):null]})}function SE({preset:e,className:t}){return(0,I.jsxs)(`span`,{className:H(`inline-flex items-center gap-1.5`,t),children:[AT(e.id)?(0,I.jsx)(PT,{type:e.id}):null,e.id===`custom`?(0,I.jsx)(ea,{"aria-hidden":!0,className:`size-[1.15em] shrink-0 text-current`,strokeWidth:1.8}):null,e.label]})}var CE=e=>e.replace(/^https?:\/\//u,``).replace(/\/+$/u,``);function wE(e,t){return Object.fromEntries(e.inputs.map(e=>[e.key,(t[e.key]??``).trim()]))}var TE=(e,t)=>e.build(wE(e,t)),EE=(e,t)=>e.build(wE(e,t)),DE=[{id:`firebase`,label:`Firebase Authentication`,vendor:`Firebase`,description:`Google-signed ID tokens. Scoped to your project by the aud and iss claims.`,inputs:[{key:`project_id`,label:`Firebase project id`,placeholder:`my-app-1a2b3`,hint:`Found in Project settings. Not the project number.`}],warning:`Firebase signs every project's tokens with one shared key set, so the JWKS URL alone identifies nobody. The issuer and audience below are what scope this app to your project — without them the gateway would accept a token from any Firebase project in the world.`,docs:`https://firebase.google.com/docs/auth/admin/verify-id-tokens`,build:({project_id:e})=>({jwks_url:`https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com`,issuer:`https://securetoken.google.com/${e}`,audience:e,user_id_claim:`sub`,required_claims:[]}),read:({audience:e})=>({project_id:e})},{id:`supabase`,label:`Supabase Auth`,vendor:`Supabase`,description:`Per-project JWKS. Requires asymmetric signing keys.`,inputs:[{key:`project_ref`,label:`Project ref`,placeholder:`abcdefghijklmnop`,hint:`The subdomain of your project URL: https://<ref>.supabase.co`}],warning:`Only projects migrated to asymmetric JWT signing keys can be verified. A legacy HS256 project publishes no public keys, so its JWKS endpoint returns an empty set and every token is rejected.`,docs:`https://supabase.com/docs/guides/auth/signing-keys`,build:({project_ref:e})=>{let t=CE(e).replace(/\.supabase\.co$/u,``);return{jwks_url:`https://${t}.supabase.co/auth/v1/.well-known/jwks.json`,issuer:`https://${t}.supabase.co/auth/v1`,audience:`authenticated`,user_id_claim:`sub`,required_claims:[]}},read:({issuer:e})=>({project_ref:CE(e).replace(/\.supabase\.co\/auth\/v1$/u,``)})},{id:`auth0`,label:`Auth0`,vendor:`Auth0`,description:`Per-tenant JWKS, with the API identifier as the audience.`,inputs:[{key:`domain`,label:`Tenant domain`,placeholder:`my-tenant.us.auth0.com`,hint:`Your Auth0 domain or custom domain, without https://`},{key:`audience`,label:`API identifier`,placeholder:`https://api.my-app.com`,hint:`The Identifier of the API you registered in Auth0. It is not a URL that has to resolve.`}],warning:`Auth0 puts a trailing slash in the iss claim. The preset writes it for you; do not remove it or every token is rejected.`,docs:`https://auth0.com/docs/secure/tokens/access-tokens/validate-access-tokens`,build:({domain:e,audience:t})=>{let n=CE(e);return{jwks_url:`https://${n}/.well-known/jwks.json`,issuer:`https://${n}/`,audience:t,user_id_claim:`sub`,required_claims:[]}},read:({issuer:e,audience:t})=>({domain:CE(e),audience:t})},{id:`clerk`,label:`Clerk`,vendor:`Clerk`,description:`Session tokens verified against your Frontend API JWKS.`,inputs:[{key:`frontend_api`,label:`Frontend API host`,placeholder:`clean-mayfly-62.clerk.accounts.dev`,hint:`Your Clerk Frontend API URL or custom domain, without https://`},{key:`audience`,label:`Audience`,placeholder:`my-app`,hint:`The aud your Clerk JWT template sets. Clerk's default session token has none — add one in the template, because the gateway requires it.`}],warning:`Clerk's own guidance also checks the azp claim against your permitted origins. This gateway serves native apps, where there is no origin to bind to, so the preset omits it — add an azp requirement manually if your tokens carry one.`,docs:`https://clerk.com/docs/guides/sessions/manual-jwt-verification`,build:({frontend_api:e,audience:t})=>{let n=CE(e);return{jwks_url:`https://${n}/.well-known/jwks.json`,issuer:`https://${n}`,audience:t,user_id_claim:`sub`,required_claims:[]}},read:({issuer:e,audience:t})=>({frontend_api:CE(e),audience:t})},{id:`custom`,label:`Custom issuer`,description:`Any issuer publishing a JWKS document over HTTPS.`,inputs:[{key:`jwks_url`,label:`JWKS URL`,placeholder:`https://issuer.example.com/.well-known/jwks.json`,hint:`If this issuer signs tokens for more than one service, add a claim requirement under Subscription check too.`},{key:`issuer`,label:`Issuer (iss)`,placeholder:`https://issuer.example.com`,hint:`Exactly the iss claim your tokens carry, trailing slash included.`},{key:`audience`,label:`Audience (aud)`,placeholder:`https://api.my-app.com`,hint:`Exactly one aud value your tokens carry.`}],build:({jwks_url:e,issuer:t,audience:n})=>({jwks_url:e,issuer:t,audience:n,user_id_claim:`sub`,required_claims:[]}),read:e=>({...e})}],OE=DE.find(e=>e.id===`custom`),kE=e=>DE.find(t=>t.id===e)??OE;function AE(e){let t=e=>Array.isArray(e)?e[0]??``:e??``;return{jwks_url:e.jwks_url??``,issuer:t(e.issuer),audience:t(e.audience)}}function jE(e){let t=AE(e);if(e.provider){let n=kE(e.provider);return{preset:n,values:n.read(t)}}let n={preset:OE,values:{...t}},r=e=>Array.isArray(e)&&e.length>1;if(r(e.issuer)||r(e.audience))return n;for(let e of DE){if(e===OE)continue;let n=e.read(t);if(!LE(e,n))continue;let r=TE(e,n);if(r.jwks_url===t.jwks_url&&r.issuer===t.issuer&&r.audience===t.audience)return{preset:e,values:n}}return n}var ME=`revenueCatEntitlements`;function NE(e){let t=e.split(`,`).map(e=>e.trim());return{path:ME,contains:t.length>1?t:e}}function PE(e){if(e.length===0)return``;let[t,...n]=e;return!t||n.length>0||t.contains===void 0?null:Array.isArray(t.contains)?t.contains.join(`, `):t.contains}var FE=`Which claim says the user has paid`,IE=[{id:`none`,label:`No entitlement check`,description:`Any user the issuer signs a token for may call the gateway.`,inputs:[],build:()=>[]},{id:`revenuecat`,label:`RevenueCat entitlement`,vendor:`RevenueCat`,inputs:[{key:`entitlement`,label:`Entitlement identifier`,placeholder:`pro`,hint:`In RevenueCat, under Product catalog → Entitlements: the identifier, not the display name. Several, comma separated, admit a user carrying any one of them.`,docs:{href:`https://www.revenuecat.com/docs/getting-started/entitlements`,label:`RevenueCat documentation`}}],build:({entitlement:e})=>e?[NE(e)]:[]},{id:`custom`,label:`Custom claim`,description:`Any single claim requirement. More can be added under Subscription check.`,inputs:[{key:`path`,label:`Claim path`,placeholder:`scope`},{key:`value`,label:`Required value`,placeholder:`ai.invoke`}],build:({path:e,value:t})=>e&&t?[{path:e,contains:t}]:[]}],LE=(e,t)=>e.inputs.every(e=>(t[e.key]??``).trim().length>0);function RE({issuer:e,disabled:t=!1,onChange:n}){let{preset:r,values:i}=jE(e),a=(t,r)=>{let i=TE(t,r);n({provider:t.id,jwks_url:i.jwks_url,issuer:i.issuer,audience:i.audience,user_id_claim:e.user_id_claim??i.user_id_claim})};return(0,I.jsx)(xE,{idPrefix:`issuer`,label:`Identity provider`,presets:DE,selected:r,values:i,compact:!0,disabled:t,onSelect:e=>a(e,{}),onValueChange:(e,t)=>a(r,{...i,[e]:t})})}function zE({claims:e,disabled:t=!1,onChange:n}){let r=(t,r)=>n(e.map((e,n)=>n===t?{...e,...r}:e));return(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Claims the sign-in token must carry. Dot paths; contains matches arrays and space-delimited scopes, equals compares exactly.`}),(0,I.jsxs)(J,{variant:`outline`,size:`sm`,disabled:t,onClick:()=>n([...e,{path:``,contains:``}]),children:[(0,I.jsx)(Na,{className:`size-3.5`}),`Add claim`]})]}),e.length===0?(0,I.jsx)(uw,{children:`No claim requirements.`}):e.map((i,a)=>{let o=i.equals===void 0?`contains`:`equals`;return(0,I.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,I.jsxs)(`div`,{className:`min-w-[180px] flex-1`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Path`}),(0,I.jsx)($,{value:i.path,placeholder:`claims.entitlements`,className:`font-mono text-xs`,disabled:t,onChange:e=>r(a,{path:e.target.value})})]}),(0,I.jsxs)(`div`,{className:`w-[140px]`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Match`}),(0,I.jsxs)(zT,{value:o,disabled:t,onValueChange:t=>n(e.map((e,n)=>n===a?t===`equals`?{path:e.path,equals:Array.isArray(e.contains)?e.contains[0]??``:e.contains??``}:{path:e.path,contains:String(e.equals??``)}:e)),children:[(0,I.jsx)(VT,{className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsxs)(HT,{children:[(0,I.jsx)(UT,{value:`contains`,children:`contains`}),(0,I.jsx)(UT,{value:`equals`,children:`equals`})]})]})]}),(0,I.jsxs)(`div`,{className:`min-w-[180px] flex-1`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Value`}),(0,I.jsx)($,{value:o===`contains`&&Array.isArray(i.contains)?i.contains.join(`, `):String(i.equals??i.contains??``),placeholder:o===`contains`?`pro, pro_test`:`pro`,className:`font-mono text-xs`,disabled:t,onChange:e=>{if(o===`equals`){r(a,{equals:e.target.value});return}let t=e.target.value.split(`,`).map(e=>e.trim());r(a,{contains:t.length>1?t:e.target.value})}})]}),(0,I.jsx)(J,{variant:`ghost`,size:`icon`,"aria-label":`Remove claim`,disabled:t,onClick:()=>n(e.filter((e,t)=>t!==a)),children:(0,I.jsx)(Ga,{className:`size-4`})})]},a)})]})}var BE=IE.filter(e=>e.id!==`none`),VE=NE(``);function HE({issuer:e,disabled:t=!1,onChange:n}){let r=e.required_claims??[],i=PE(r),a=(e.entitlement??(r[0]?.path===`revenueCatEntitlements`?`revenuecat`:`custom`))===`revenuecat`&&i!==null?`revenuecat`:`custom`,o=BE.find(e=>e.id===a)??BE[0],s=e=>{e!==a&&n({entitlement:e,required_claims:e===`revenuecat`?[NE(i??``)]:r})};return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`entitlement-check`,children:FE}),(0,I.jsxs)(zT,{value:a,disabled:t,onValueChange:e=>s(e),children:[(0,I.jsx)(VT,{id:`entitlement-check`,className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:BE.map(e=>(0,I.jsx)(UT,{value:e.id,children:(0,I.jsx)(SE,{preset:e})},e.id))})]}),o.description?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o.description}):null]}),a===`revenuecat`?(0,I.jsx)(UE,{input:o.inputs[0],entitlement:i??``,disabled:t,onChange:e=>n({required_claims:[NE(e)]})}):(0,I.jsx)(zE,{claims:r,disabled:t,onChange:e=>n({required_claims:e})})]})}function UE({input:e,entitlement:t,disabled:n,onChange:r}){return(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`entitlement-value`,children:e.label}),(0,I.jsx)($,{id:`entitlement-value`,value:t,placeholder:e.placeholder,className:`max-w-[320px] font-mono text-xs`,disabled:n,onChange:e=>r(e.target.value)}),(0,I.jsxs)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:[e.hint,e.docs?(0,I.jsxs)(I.Fragment,{children:[` `,(0,I.jsx)(bE,{href:e.docs.href,children:e.docs.label})]}):null]})]})}var WE=[{value:`issuer`,label:`Signed-in users only`,description:`Users sign in through your identity provider, and the gateway verifies it.`},{value:`app_install`,label:`Unauthenticated users`,description:`Anyone with your app can call. Each installation counts as one user.`}],GE=[{value:`issuer`,label:`Signed-in users only`,description:`Your backend forwards each user's sign-in token, and the gateway verifies it.`},{value:`header`,label:`Your backend sends the user id`,description:`In the ${iT} header on every request.`},{value:`none`,label:`No user identity`,description:`Requests are not linked to any user.`}];function KE({...e}){return(0,I.jsx)(Yd,{"data-slot":`dialog`,...e})}function qE({...e}){return(0,I.jsx)(Zd,{"data-slot":`dialog-trigger`,...e})}function JE({...e}){return(0,I.jsx)(tf,{"data-slot":`dialog-portal`,...e})}function YE({className:e,...t}){return(0,I.jsx)(rf,{"data-slot":`dialog-overlay`,className:H(`fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`,e),...t})}function XE({className:e,children:t,showCloseButton:n=!0,dismissOnOutsideInteraction:r=!1,onInteractOutside:i,...a}){return(0,I.jsxs)(JE,{"data-slot":`dialog-portal`,children:[(0,I.jsx)(YE,{}),(0,I.jsxs)(cf,{"data-slot":`dialog-content`,className:H(`fixed top-[50%] left-[50%] z-50 flex max-h-[calc(100dvh-4rem)] w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] flex-col overflow-hidden rounded-lg border bg-background shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg`,n&&`[&_[data-slot=dialog-header]]:pr-14`,e),onInteractOutside:e=>{i?.(e),r||e.preventDefault()},...a,children:[t,n&&(0,I.jsxs)(_f,{"data-slot":`dialog-close`,className:`absolute top-5 right-4 inline-flex size-8 items-center justify-center rounded-md text-muted-foreground opacity-70 ring-offset-background transition-[opacity,background-color,color] hover:bg-muted hover:text-foreground hover:opacity-100 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,children:[(0,I.jsx)(Ya,{}),(0,I.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function ZE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`dialog-header`,className:H(`flex shrink-0 flex-col gap-2 border-b p-6 text-center sm:text-left`,e),...t})}function QE({className:e,...t}){return(0,I.jsx)(`div`,{"data-slot":`dialog-body`,className:H(`min-h-0 flex-1 overflow-y-auto px-6 py-5`,e),...t})}function $E({className:e,showCloseButton:t=!1,children:n,...r}){return(0,I.jsxs)(`div`,{"data-slot":`dialog-footer`,className:H(`flex shrink-0 flex-col-reverse gap-2 border-t px-6 py-4 sm:flex-row sm:justify-end`,e),...r,children:[n,t&&(0,I.jsx)(_f,{asChild:!0,children:(0,I.jsx)(J,{variant:`outline`,children:`Close`})})]})}function eD({className:e,...t}){return(0,I.jsx)(pf,{"data-slot":`dialog-title`,className:H(`text-lg leading-6 font-semibold`,e),...t})}function tD({className:e,...t}){return(0,I.jsx)(hf,{"data-slot":`dialog-description`,className:H(`text-sm text-muted-foreground`,e),...t})}function nD({open:e,onOpenChange:t,title:n,description:r,submitLabel:i,pending:a,disabled:o,onSubmit:s,secondaryAction:c,className:l,children:u}){let{readOnly:d}=sx(),f=d||o||a;return(0,I.jsx)(KE,{open:e,onOpenChange:t,children:(0,I.jsx)(XE,{className:l??`sm:max-w-md`,...r?{}:{"aria-describedby":void 0},children:(0,I.jsxs)(`form`,{className:`flex min-h-0 flex-1 flex-col`,autoComplete:`off`,onSubmit:e=>{e.preventDefault(),!f&&s()},children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{className:`text-balance`,children:n})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[r?(0,I.jsx)(tD,{className:`text-pretty`,children:r}):null,u]}),(0,I.jsxs)($E,{children:[c,(0,I.jsx)(J,{type:`button`,variant:`outline`,onClick:()=>t(!1),children:`Cancel`}),(0,I.jsxs)(iw,{type:`submit`,disabled:o||a,children:[a?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,i]})]})]})})})}function rD({open:e,title:t,description:n,label:r,secret:i,acknowledgeLabel:a=`I’ve saved this key`,footnote:o,onAcknowledge:s}){let[c,l]=(0,v.useState)(!1),u=async()=>{try{await navigator.clipboard.writeText(i),l(!0),U.success(`Copied to clipboard`)}catch{U.error(`Could not copy. Select the value and copy it manually.`)}},d=()=>{l(!1),s()};return(0,I.jsx)(KE,{open:e,onOpenChange:e=>{e||d()},children:(0,I.jsxs)(XE,{showCloseButton:!1,className:`sm:max-w-lg`,onEscapeKeyDown:e=>e.preventDefault(),children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{className:`text-balance`,children:t})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[(0,I.jsx)(tD,{className:`text-pretty`,children:n}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`revealed-secret`,children:r}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)($,{id:`revealed-secret`,value:i,readOnly:!0,className:`font-mono text-xs`,onFocus:e=>e.currentTarget.select()}),(0,I.jsxs)(J,{type:`button`,variant:`outline`,className:`min-w-24`,onClick:()=>void u(),children:[c?(0,I.jsx)(ra,{className:`size-4`}):(0,I.jsx)(ha,{className:`size-4`}),c?`Copied`:`Copy`]})]}),o?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o}):null]})]}),(0,I.jsx)($E,{children:(0,I.jsx)(J,{onClick:d,children:a})})]})})}function iD({appId:e,exchanged:t=!1,title:n=`Server API keys`,description:r}){let i=IS(e),a=LS(e),o=RS(e),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(null),p=async()=>{if(l.trim())try{let e=await a.mutateAsync(l.trim());c(!1),u(``),f(e)}catch(e){U.error(e instanceof Error?e.message:`Could not create the API key`)}},m=async e=>{try{await o.mutateAsync(e),U.success(`API key revoked`)}catch(e){U.error(e instanceof Error?e.message:`Could not revoke the API key`)}};return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:n,description:r,action:(0,I.jsxs)(iw,{size:`sm`,onClick:()=>{u(``),c(!0)},children:[(0,I.jsx)(Na,{className:`size-4`}),`New key`]})})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[t?null:(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Your backend sends one of these keys as an Authorization bearer credential. Revoking takes effect within a minute.`}),(0,I.jsx)(`div`,{className:`overflow-hidden rounded-md border`,children:(0,I.jsxs)(sE,{className:`[--table-inset:1rem]`,children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{children:[(0,I.jsx)(Z,{children:`Name`}),(0,I.jsx)(Z,{children:`Prefix`}),(0,I.jsx)(Z,{children:`Last used`}),(0,I.jsx)(Z,{children:`Status`}),(0,I.jsx)(Z,{className:`w-24`})]})}),(0,I.jsx)(lE,{children:i.data?.keys.length?i.data.keys.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{children:e.name}),(0,I.jsxs)(Q,{className:`font-mono text-xs`,children:[e.key_prefix,`…`]}),(0,I.jsx)(Q,{className:`text-xs text-muted-foreground`,children:hC(e.last_used_at)}),(0,I.jsx)(Q,{children:(0,I.jsx)(Lb,{variant:e.status===`active`?`secondary`:`outline`,children:e.status})}),(0,I.jsx)(Q,{className:`text-right`,children:(0,I.jsxs)(iw,{variant:`ghost`,size:`sm`,className:`text-destructive`,disabled:e.status===`revoked`||o.isPending,onClick:()=>void m(e.id),children:[(0,I.jsx)(Va,{className:`size-3.5`}),`Revoke`]})})]},e.id)):(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:5,className:`py-8 text-center text-sm text-muted-foreground`,children:`No API keys yet.`})})})]})})]})]}),(0,I.jsx)(nD,{open:s,onOpenChange:c,title:`Create an API key`,submitLabel:`Create key`,pending:a.isPending,disabled:!l.trim(),onSubmit:()=>void p(),children:(0,I.jsx)(sw,{label:`Key name`,htmlFor:`api-key-name`,hint:`Name it so you can tell keys apart in the list.`,children:(0,I.jsx)($,{id:`api-key-name`,value:l,placeholder:`Production Worker`,maxLength:100,autoFocus:!0,autoComplete:`off`,onChange:e=>u(e.target.value)})})}),(0,I.jsx)(rD,{open:d!==null,title:`Copy your new key now`,description:(0,I.jsxs)(I.Fragment,{children:[`This is the only time the plaintext for`,` `,(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:d?.name}),` is available — you will not see it again. The gateway stores only a hash.`]}),label:`API key`,secret:d?.key??``,onAcknowledge:()=>{f(null),a.reset()}})]})}var aD=`identity`,oD=[{slug:`identity`,label:`Application identity`},{slug:`users`,label:`User authentication`},{slug:`subscription`,label:`Subscription check`}],sD={secure:{icon:la,className:`text-emerald-600 dark:text-emerald-400`},weak:{icon:za,className:`text-amber-600 dark:text-amber-400`},incomplete:{icon:ca,className:`text-destructive`},off:{icon:ua,className:`text-muted-foreground/60`}},cD=[{value:`paid`,label:`Paid users only`,description:`The sign-in token must carry a claim that says the user has paid.`},{value:`any`,label:`Any signed-in user`,description:`Signing in is enough. Nothing about payment is checked.`}],lD=e=>(e.required_claims??[]).length>0||e.entitlement!==void 0?`paid`:`any`;function uD(e,t){let n=e.config.authentication,r=lT(n);return{identity:n.type===`apple_app_attest`?!n.app_attest.team_id.trim()||!n.app_attest.bundle_id.trim()?{tone:`incomplete`,text:`Team or bundle id missing`}:{tone:`secure`,text:`Verified with App Attest`}:t===!1?{tone:`incomplete`,text:`No active API key`}:{tone:`secure`,text:`Verified with API keys`},users:(()=>{switch(n.end_user?.source??`none`){case`issuer`:return r&&$T(r)?{tone:`secure`,text:`Signed-in users only`}:{tone:`incomplete`,text:`Identity provider not finished`};case`header`:return n.type===`api_key`&&n.end_user?.source===`header`&&!n.end_user.header.trim()?{tone:`incomplete`,text:`Header name missing`}:{tone:`weak`,text:`Your backend names the user`};case`app_install`:return{tone:`weak`,text:`Unauthenticated users allowed`};default:return{tone:`weak`,text:`No user identity`}}})(),subscription:r?lD(r)===`paid`?(r.required_claims??[]).every(eE)&&(r.required_claims??[]).length>0?{tone:`secure`,text:`Paid users only`}:{tone:`incomplete`,text:`Paid check not finished`}:{tone:`weak`,text:`Any signed-in user`}:{tone:`off`,text:`Needs signed-in users`}}}function dD({appId:e,level:t,state:n}){let r=n.draft,i=r.config.authentication,{readOnly:a}=sx(),o=IS(e,i.type===`api_key`),s=uD(r,o.data?o.data.keys.some(e=>e.status===`active`):void 0),c=oD.some(e=>e.slug===t)&&s[t].tone!==`off`?t:aD;return(0,I.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[16rem_minmax(0,1fr)]`,children:[(0,I.jsx)(`nav`,{"aria-label":`Auth policy levels`,className:`flex flex-col gap-1 lg:sticky lg:top-6 lg:self-start`,children:oD.map(t=>(0,I.jsx)(fD,{to:`/apps/${e}/auth/${t.slug}`,label:t.label,status:s[t.slug],current:t.slug===c},t.slug))}),(0,I.jsx)(`div`,{className:`min-w-0 space-y-4`,children:c===`identity`?i.type===`apple_app_attest`?(0,I.jsx)(pD,{authentication:i,readOnly:a,state:n}):(0,I.jsx)(iD,{appId:e,exchanged:lT(i)!==void 0,title:`Application identity`,description:`A server application. Your backend proves itself with one of these API keys.`}):c===`users`?(0,I.jsx)(mD,{authentication:i,readOnly:a,state:n}):(0,I.jsx)(hD,{issuer:lT(i)??uT(),readOnly:a,state:n})})]})}function fD({to:e,label:t,status:n,current:r}){let{icon:i,className:a}=sD[n.tone],o=(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(i,{className:H(`mt-0.5 size-4 shrink-0`,a),"aria-hidden":`true`}),(0,I.jsxs)(`span`,{className:`min-w-0`,children:[(0,I.jsx)(`span`,{className:`block text-sm font-medium`,children:t}),(0,I.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:n.text})]})]}),s=`flex items-start gap-3 rounded-lg px-3 py-2.5 text-left transition-colors`;return n.tone===`off`?(0,I.jsx)(`div`,{"aria-disabled":`true`,className:H(s,`opacity-60`),children:o}):(0,I.jsx)(Pn,{to:e,"aria-current":r?`page`:void 0,className:H(s,`outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50`,r?`bg-muted`:`hover:bg-muted/60`),children:o})}function pD({authentication:e,readOnly:t,state:n}){let r=e.app_attest,i=t=>n.updateAuthentication({...e,app_attest:{...r,...t}});return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Application identity`,description:`An iOS application. Only builds signed with this team and bundle id can call AI providers through this gateway.`})}),(0,I.jsxs)(oE,{className:`space-y-6`,children:[(0,I.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,I.jsx)(ow,{htmlFor:`apple-team-id`,children:`Apple Team ID`}),(0,I.jsx)($,{id:`apple-team-id`,value:r.team_id,placeholder:`ABCDE12345`,className:`font-mono text-xs`,disabled:t,onChange:e=>i({team_id:e.target.value})}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`In your Apple Developer account under`,` `,(0,I.jsx)(bE,{href:`https://developer.apple.com/account#MembershipDetailsCard`,children:`Membership details`}),`.`]})]}),(0,I.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,I.jsx)(ow,{htmlFor:`apple-bundle-id`,children:`Bundle ID`}),(0,I.jsx)($,{id:`apple-bundle-id`,value:r.bundle_id,placeholder:`com.example.app`,className:`font-mono text-xs`,disabled:t,onChange:e=>i({bundle_id:e.target.value})}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`In Xcode, on your target's`,` `,(0,I.jsx)(bE,{href:`https://developer.apple.com/documentation/xcode/configuring-the-build-settings-of-a-target#Set-the-bundle-ID`,children:`Signing & Capabilities`}),` `,`tab.`]})]})]}),(0,I.jsx)(vE,{value:r.environments,compact:!0,disabled:t,onChange:t=>n.updateAuthentication({...e,app_attest:{team_id:r.team_id,bundle_id:r.bundle_id,...t.length===1&&t[0]===`production`?{}:{environments:t}}})})]})]})}function mD({authentication:e,readOnly:t,state:n}){let r=(0,v.useId)(),i=e.end_user?.source??`none`,a=lT(e),o=e.type===`api_key`?GE:WE;return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`User authentication`,description:`Choose whether only users signed in to your app can call AI through this gateway.`})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[t?(0,I.jsx)(rw,{reason:rx,reasonId:r,className:`w-full`,children:(0,I.jsx)(yE,{label:`User authentication`,choices:o,value:i,disabled:!0,describedBy:r,onChange:()=>{}})}):(0,I.jsx)(yE,{label:`User authentication`,choices:o,value:i,onChange:e=>n.setEndUserSource(e===`none`?void 0:e)}),e.type===`api_key`&&e.end_user?.source===`header`?(0,I.jsx)(sw,{label:`Header name`,htmlFor:`end-user-header`,hint:`Lowercased, and removed before the request reaches the provider. Defaults to ${iT}.`,children:(0,I.jsx)($,{id:`end-user-header`,value:e.end_user.header,placeholder:iT,className:`max-w-[320px] font-mono text-xs`,disabled:t,onChange:e=>n.updateEndUserHeader(e.target.value)})}):null]})]}),i===`issuer`?(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Identity provider`,description:`Where your users sign in. The gateway verifies their sign-in tokens against it.`})}),(0,I.jsx)(oE,{children:(0,I.jsx)(RE,{issuer:a??uT(),disabled:t,onChange:n.updateIssuer})})]}):null]})}function hD({issuer:e,readOnly:t,state:n}){let r=(0,v.useId)(),i=lD(e);return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Subscription check`,description:`Check that the user has paid for the app before they can call AI providers through this gateway.`})}),(0,I.jsxs)(oE,{className:`space-y-6`,children:[t?(0,I.jsx)(rw,{reason:rx,reasonId:r,className:`w-full`,children:(0,I.jsx)(yE,{label:`Subscription check`,choices:cD,value:i,disabled:!0,describedBy:r,onChange:()=>{}})}):(0,I.jsx)(yE,{label:`Subscription check`,choices:cD,value:i,onChange:e=>{e!==i&&n.updateIssuer(e===`any`?{entitlement:void 0,required_claims:[]}:{entitlement:`revenuecat`,required_claims:[VE]})}}),i===`paid`?(0,I.jsx)(`div`,{className:`border-t pt-6`,children:(0,I.jsx)(HE,{issuer:e,disabled:t,onChange:n.updateIssuer})}):null]})]})}var gD={requests:{per_minute:null,per_day:null},spending:{monthly_usd:null}},_D={per_user:gD,per_app:gD},vD=e=>e===``?null:Number(e);function yD({state:e}){let t=e.draft,n=t.config.limits??_D,r=t.config.authentication.type!==`api_key`||t.config.authentication.end_user!==void 0,i=(t,r)=>e.updateLimits({...n,[t]:{...n[t],...r}});return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`p`,{className:`text-sm leading-relaxed text-muted-foreground`,children:[`Limits you set on `,(0,I.jsx)(`strong`,{className:`font-medium text-foreground`,children:`your app's end users`}),`. They are unrelated to your own`,` `,(0,I.jsx)(Pn,{to:`/billing`,className:`text-primary-ink underline underline-offset-4`,children:`plan allowance`}),`, which meters all your apps together: a request refused here never spends it. Edits take up to a minute to apply everywhere.`]}),(0,I.jsxs)(`div`,{className:r?`grid gap-4 lg:grid-cols-2`:`grid gap-4`,children:[r?(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(iE,{className:`text-sm`,children:`Per-user limits`})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Applied independently to every authenticated user. Rate limits return`,` `,(0,I.jsx)(`code`,{className:`font-mono`,children:`app_rate_limited`}),`; exhausting the monthly spend returns `,(0,I.jsx)(`code`,{className:`font-mono`,children:`app_budget_exhausted`}),`.`]}),(0,I.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,I.jsx)(sw,{label:`Requests per minute`,htmlFor:`rpm`,hint:`Leave empty for unlimited.`,children:(0,I.jsx)($,{id:`rpm`,type:`number`,min:1,value:n.per_user.requests.per_minute??``,placeholder:`Unlimited`,onChange:e=>i(`per_user`,{requests:{...n.per_user.requests,per_minute:vD(e.target.value)}})})}),(0,I.jsx)(sw,{label:`Requests per day`,htmlFor:`rpd`,hint:`Leave empty for unlimited.`,children:(0,I.jsx)($,{id:`rpd`,type:`number`,min:1,value:n.per_user.requests.per_day??``,placeholder:`Unlimited`,onChange:e=>i(`per_user`,{requests:{...n.per_user.requests,per_day:vD(e.target.value)}})})})]}),(0,I.jsx)(`div`,{className:`border-t pt-4`,children:(0,I.jsx)(sw,{label:`Monthly spending budget (USD)`,htmlFor:`budget`,hint:n.per_user.spending.monthly_usd===null?`Unlimited`:`${dC(n.per_user.spending.monthly_usd)} per user per month. Settled from completed requests, so it stops the request after the one that crosses it.`,children:(0,I.jsx)($,{id:`budget`,type:`number`,min:0,step:`0.01`,value:n.per_user.spending.monthly_usd??``,placeholder:`Unlimited`,onChange:e=>i(`per_user`,{spending:{monthly_usd:vD(e.target.value)}})})})})]})]}):(0,I.jsx)(nE,{children:(0,I.jsx)(oE,{className:`pt-6`,children:(0,I.jsx)(uw,{children:`This application identifies no end users, so there is nobody for a per-user limit to apply to. Choose a user authentication method on the Auth policy tab to set them, or use the application limits below.`})})}),(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(iE,{className:`text-sm`,children:`Application limits`})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Shared across all users and credentials for this application. Leave a field empty to keep that application-wide limit unrestricted.`}),(0,I.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,I.jsx)(sw,{label:`Requests per minute`,htmlFor:`app-rpm`,hint:`Leave empty for unlimited.`,children:(0,I.jsx)($,{id:`app-rpm`,type:`number`,min:1,value:n.per_app.requests.per_minute??``,placeholder:`Unlimited`,onChange:e=>i(`per_app`,{requests:{...n.per_app.requests,per_minute:vD(e.target.value)}})})}),(0,I.jsx)(sw,{label:`Requests per day`,htmlFor:`app-rpd`,hint:`Leave empty for unlimited.`,children:(0,I.jsx)($,{id:`app-rpd`,type:`number`,min:1,value:n.per_app.requests.per_day??``,placeholder:`Unlimited`,onChange:e=>i(`per_app`,{requests:{...n.per_app.requests,per_day:vD(e.target.value)}})})})]}),(0,I.jsx)(`div`,{className:`border-t pt-4`,children:(0,I.jsx)(sw,{label:`Monthly spending budget (USD)`,htmlFor:`app-budget`,hint:n.per_app.spending.monthly_usd===null?`Unlimited`:`${dC(n.per_app.spending.monthly_usd)} per application per month. Settled from completed requests, so it stops the request after the one that crosses it.`,children:(0,I.jsx)($,{id:`app-budget`,type:`number`,min:0,step:`0.01`,value:n.per_app.spending.monthly_usd??``,placeholder:`Unlimited`,onChange:e=>i(`per_app`,{spending:{monthly_usd:vD(e.target.value)}})})})})]})]})]})]})}function bD(e){return e?.apiBaseUrl??window.location.origin}function xD({appId:e,month:t,state:n}){let{capabilities:r}=sx(),i=VS(e,t),a=zS(e,{month:t,limit:1}),o=n.draft.config.authentication,s=(i.data?.input_tokens??0)+(i.data?.cached_input_tokens??0)+(i.data?.cache_write_tokens??0)+(i.data?.output_tokens??0),c=lT(o);return(0,I.jsxs)(`div`,{className:`space-y-6`,children:[o.type===`api_key`?(0,I.jsx)(SD,{appId:e}):null,(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,I.jsx)(dE,{label:`Spend`,value:i.isPending?(0,I.jsx)(aw,{className:`h-6 w-20`}):dC(i.data?.cost_usd??0),detail:`month to date`}),(0,I.jsx)(dE,{label:`Users`,value:a.isPending?(0,I.jsx)(aw,{className:`h-6 w-12`}):cC(a.data?.total??0),detail:`all time`}),(0,I.jsx)(dE,{label:`Requests`,value:i.isPending?(0,I.jsx)(aw,{className:`h-6 w-16`}):cC(i.data?.requests??0),detail:`month to date`}),(0,I.jsx)(dE,{label:`Tokens`,value:i.isPending?(0,I.jsx)(aw,{className:`h-6 w-16`}):lC(s),detail:`all buckets`})]}),(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(iE,{className:`text-sm`,children:`Client base URL`})}),(0,I.jsxs)(oE,{children:[(0,I.jsxs)(`code`,{className:`block rounded-md bg-muted px-3 py-2 font-mono text-xs break-all`,children:[bD(r),`/v1/apps/`,e,`/proxy/{provider}/{provider_path}`]}),(0,I.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:c?(0,I.jsxs)(I.Fragment,{children:[`Auth exchange lives at`,` `,(0,I.jsxs)(`span`,{className:`font-mono`,children:[`/v1/apps/`,e,`/auth/token`]}),`.`]}):(0,I.jsxs)(I.Fragment,{children:[`Clients send their API key as the`,` `,(0,I.jsx)(`span`,{className:`font-mono`,children:`Authorization`}),` bearer credential; this app has no token exchange.`]})})]})]})]})}function SD({appId:e}){let t=IS(e);return!t.data||t.data.keys.some(e=>e.status===`active`)?null:(0,I.jsxs)(Ds,{children:[(0,I.jsx)(Sa,{}),(0,I.jsx)(Os,{children:`This app has no active API key`}),(0,I.jsxs)(ks,{children:[`Nothing can call it until one is created.`,` `,(0,I.jsx)(Pn,{to:`/apps/${e}/auth/identity`,className:`text-primary-ink underline underline-offset-4`,children:`Create an API key`})]})]})}function CD({className:e,size:t=`default`,...n}){return(0,I.jsx)(_y,{"data-slot":`switch`,"data-size":t,className:H(`peer group/switch inline-flex shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-[1.15rem] data-[size=default]:w-8 data-[size=sm]:h-3.5 data-[size=sm]:w-6 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input dark:data-[state=unchecked]:bg-input/80`,e),...n,children:(0,I.jsx)(yy,{"data-slot":`switch-thumb`,className:H(`pointer-events-none block rounded-full bg-background ring-0 transition-transform group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0 dark:data-[state=checked]:bg-primary-foreground dark:data-[state=unchecked]:bg-foreground`)})})}function wD({values:e,onChange:t,placeholder:n,suggestions:r=[],warn:i,warnTitle:a}){let[o,s]=(0,v.useState)(``),c=`suggestions-${Math.abs(TD(r.join(`,`)+n))}`,l=n=>{let r=n.trim();if(!r||e.includes(r))return s(``);t([...e,r]),s(``)};return(0,I.jsxs)(`div`,{className:`space-y-2`,children:[e.length>0?(0,I.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(n=>{let r=i?.(n)??!1;return(0,I.jsxs)(`span`,{title:r?a:void 0,className:H(`inline-flex items-center gap-1 rounded-md border py-1 pr-1 pl-2 font-mono text-xs`,r?`border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-400`:`bg-muted/50`),children:[n,(0,I.jsx)(`button`,{type:`button`,"aria-label":`Remove ${n}`,className:`rounded p-0.5 text-muted-foreground transition-colors hover:bg-background hover:text-foreground`,onClick:()=>t(e.filter(e=>e!==n)),children:(0,I.jsx)(Ya,{className:`size-3`})})]},n)})}):null,(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)($,{value:o,list:r.length>0?c:void 0,placeholder:n,className:`h-8 font-mono text-xs`,onChange:e=>s(e.target.value),onKeyDown:n=>{(n.key===`Enter`||n.key===`,`)&&(n.preventDefault(),l(o)),n.key===`Backspace`&&o===``&&e.length>0&&t(e.slice(0,-1))}}),r.length>0?(0,I.jsx)(`datalist`,{id:c,children:r.map(e=>(0,I.jsx)(`option`,{value:e},e))}):null,(0,I.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,className:`h-8`,onClick:()=>l(o),children:[(0,I.jsx)(Na,{className:`size-3.5`}),`Add`]})]})]})}function TD(e){let t=0;for(let n=0;n<e.length;n+=1)t=t*31+e.charCodeAt(n)|0;return t}var ED={responses:`Responses`,chat_completions:`Chat Completions`,anthropic_messages:`Anthropic Messages`,gemini_native:`Gemini generateContent`,audio_transcription:`Transcription`};function DD(e){return Object.hasOwn(ED,e)}var OD={gemini:[`gemini_native`],openai:[`audio_transcription`],xai:[`audio_transcription`]};function kD(e){return{style:e,label:ED[e],path:Lw[e]}}function AD(e,t){let n=Xw[e]?.[t];if(!n)return null;let r=OD[t]??[],i=n.apiStyles?.filter(DD);return{narrowed:i!==void 0,available:(i??[]).map(kD),unavailable:i?r.filter(e=>!i.includes(e)).map(kD):[],modelIds:n.modelPrefix?`${eT[t]} model IDs with no "${n.modelPrefix}" prefix — the gateway adds it upstream`:`${eT[t]} model IDs, unchanged`}}function jD(e,t,n){if(e===null)return!0;let r=AD(e,t);if(!r)return!1;if(!r.narrowed)return!0;let i=zw[n];return r.available.some(e=>e.style===i)}var MD={openai:`Forwarded with the leading v1/ stripped, matching Cloudflare's provider-native URL.`,anthropic:`Forwarded with the v1/ prefix retained.`,xai:`Routed to Cloudflare's grok slug; the tenant path stays /proxy/xai/...`,gemini:`Use the OpenAI-compatible path v1beta/openai/chat/completions.`,perplexity:`Routed to Cloudflare's perplexity-ai slug; use chat/completions for Sonar models.`,deepseek:`Direct only. DeepSeek's base URL has no v1/, so the path is chat/completions.`,groq:`Direct only. Groq namespaces its OpenAI API: use openai/v1/chat/completions.`,mistral:`Direct only. Use v1/chat/completions.`,together:`Direct only. Use v1/chat/completions; models are namespaced, e.g. openai/gpt-oss-120b.`,fireworks:`Direct only. Use inference/v1/chat/completions. Models are account-scoped (accounts/…/models/…), so price them under custom model pricing.`,cerebras:`Direct only. Use v1/chat/completions.`,moonshot:`Direct only. Use v1/chat/completions on the international api.moonshot.ai host.`,huggingface:`Direct only. Use v1/chat/completions on the Inference Providers router. Pin the upstream in the model ID (author/model:provider) — otherwise the router picks one and the price varies with it.`,baseten:`Direct only. Use v1/chat/completions on the Model APIs host.`,bytedance:`Direct only. BytePlus ModelArk's version segment is already in the base URL: the path is chat/completions. Models must be activated in your ModelArk console first.`,openrouter:`Direct only, chat completions only. Models are OpenRouter slugs, e.g. google/gemini-3.6-flash, and need no local price: cost is reported by OpenRouter per request.`};function ND(e,t){if(e.providerGatewayId===null)return null;let n=t.find(t=>t.id===e.providerGatewayId),r=n?AD(n.type,e.type):null;if(!r?.narrowed)return null;let i=r.available.map(e=>`${e.label} at ${e.path}`).join(`, `),a=r.unavailable.length>0?` Not available on this route: ${r.unavailable.map(e=>e.label).join(`, `)}.`:``;return`Routed through ${n.name}: ${i}.${a} Models: ${r.modelIds}.`}function PD({state:e}){return(0,I.jsx)(Lb,{variant:`outline`,className:`border-muted-foreground/30 text-[11px] font-normal text-muted-foreground`,children:e})}function FD({row:e,config:t,onChange:n}){let r=(t?.allowed_paths??[]).map(fT),i=e.knownModels,a=e=>n({...mT(),...t,allowed_paths:e.map(pT)});return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:(0,I.jsxs)(`span`,{className:`flex items-center gap-2`,children:[e.title,e.badge?(0,I.jsx)(PD,{state:e.badge}):null]}),description:e.description,action:(0,I.jsx)(CD,{"aria-label":`Enable ${e.slug}`,checked:t!==void 0,onCheckedChange:e=>n(e?mT():void 0)})})}),t?(0,I.jsxs)(oE,{className:`space-y-5`,children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsx)(ow,{className:`text-sm`,children:`Allowed paths`}),(0,I.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>a([...r,{path:``}]),children:[(0,I.jsx)(Na,{className:`size-3.5`}),`Add path`]})]}),r.length===0?(0,I.jsx)(uw,{children:`Every path is allowed. Add one or more paths to restrict this provider.`}):(0,I.jsx)(`div`,{className:`space-y-2`,children:r.map((e,t)=>(0,I.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,I.jsxs)(`div`,{className:`min-w-[200px] flex-[2]`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Path`}),(0,I.jsx)($,{value:e.path,placeholder:`v1/responses`,className:`font-mono text-xs`,onChange:e=>a(r.map((n,r)=>r===t?{...n,path:e.target.value}:n))})]}),(0,I.jsxs)(`div`,{className:`min-w-[150px] flex-1`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Fixed model`}),(0,I.jsx)($,{value:e.fixed_model??``,placeholder:`none`,className:`font-mono text-xs`,onChange:e=>a(r.map((n,r)=>r===t?{...n,fixed_model:e.target.value||void 0}:n))})]}),(0,I.jsxs)(`div`,{className:`w-[170px]`,children:[(0,I.jsx)(ow,{className:`mb-1.5 text-xs text-muted-foreground`,children:`Output cap style`}),(0,I.jsxs)(zT,{value:e.clamp??`auto`,onValueChange:e=>a(r.map((n,r)=>r===t?{...n,clamp:e===`auto`?void 0:e}:n)),children:[(0,I.jsx)(VT,{className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsxs)(HT,{children:[(0,I.jsx)(UT,{value:`auto`,children:`auto (by body)`}),rT.map(e=>(0,I.jsx)(UT,{value:e,children:e},e))]})]})]}),(0,I.jsx)(J,{variant:`ghost`,size:`icon`,"aria-label":`Remove path`,onClick:()=>a(r.filter((e,n)=>n!==t)),children:(0,I.jsx)(Ga,{className:`size-4`})})]},t))}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Leave this list empty to allow every path. A fixed model applies to transcription-style routes with no model in the body; it is never injected upstream. Leave the output cap style on auto unless the route needs an exception.`})]}),(0,I.jsx)(sw,{label:`Allowed models`,hint:`Leave empty to allow every model with configured pricing. A non-empty list restricts this provider; rewrites are resolved before pricing is checked.`,children:(0,I.jsx)(wD,{values:t.allowed_models??[],suggestions:i,placeholder:`gpt-5.6-terra`,onChange:e=>n({...t,allowed_models:e})})}),(0,I.jsx)(sw,{label:`Max output tokens`,hint:`Empty = unrestricted. If set, requests above this are rejected; requests without an output-limit parameter get this value injected. Transcription routes ignore this cap.`,children:(0,I.jsx)($,{type:`number`,min:1,className:`max-w-[200px]`,value:t.max_output_tokens??``,placeholder:`8192`,onChange:e=>n({...t,max_output_tokens:e.target.value?Number(e.target.value):void 0})})})]}):null]})}function ID(e,t,n,r){let i=e.map(e=>({slug:e.slug,title:e.name,description:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`span`,{className:`font-mono`,children:[`/proxy/`,e.slug,`/…`]}),` ·`,` `,(0,I.jsx)(FT,{type:e.type,className:`align-middle`}),` —`,` `,ND(e,t)??MD[e.type]]}),knownModels:aT(e,r),...e.status===`disabled`?{badge:`disabled`}:{}})),a=n.filter(t=>!e.some(e=>e.slug===t)).map(e=>({slug:e,title:e,description:`No instance answers for this slug. Recreate it on the Providers page, or turn this off.`,knownModels:[],badge:`deleted`}));return[...i,...a]}var LD=e=>e.filter(([e,t])=>e!==``&&t!==``),RD=e=>Object.fromEntries(LD(e));function zD({rewrites:e,onChange:t}){let[n,r]=(0,v.useState)(()=>Object.entries(e)),i=JSON.stringify(e),[a,o]=(0,v.useState)(i);i!==a&&(o(i),i!==JSON.stringify(RD(n))&&r(Object.entries(e)));let s=e=>{r(e),t(RD(e))},c=(e,t)=>s(n.map((n,r)=>r===e?t:n)),l=LD(n).length<n.length;return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Model rewrites`,description:`Server-side remap applied after the allowlist check, so a target need not be client-allowlisted. Usage records the rewritten model.`,action:(0,I.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>s([...n,[``,``]]),children:[(0,I.jsx)(Na,{className:`size-3.5`}),`Add rewrite`]})})}),(0,I.jsxs)(oE,{className:`space-y-2`,children:[n.length===0?(0,I.jsx)(uw,{children:`No rewrites. Clients get exactly the model they ask for.`}):n.map(([e,t],r)=>(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)($,{value:e,"aria-label":`Rewrite ${r+1} source model`,placeholder:`gpt-5.6-terra`,className:`flex-1 font-mono text-xs`,onChange:e=>c(r,[e.target.value,t])}),(0,I.jsx)(Zi,{className:`size-4 shrink-0 text-muted-foreground`}),(0,I.jsx)($,{value:t,"aria-label":`Rewrite ${r+1} target model`,placeholder:`gpt-5.7`,className:`flex-1 font-mono text-xs`,onChange:t=>c(r,[e,t.target.value])}),(0,I.jsx)(J,{variant:`ghost`,size:`icon`,"aria-label":`Remove rewrite ${r+1}`,onClick:()=>s(n.filter((e,t)=>t!==r)),children:(0,I.jsx)(Ga,{className:`size-4`})})]},r)),l?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`A rewrite is saved once both sides are filled in. A row left half-finished is dropped.`}):null]})]})}function BD({state:e}){let t=e.draft.config.routing,n=yT(t),r=bT(t),i=fS().data??[],a=_S().data?.gateways??[],o=qS().data?.prices,s=ID(i,a,r,o);return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(nE,{className:n===`all`?`border-emerald-500/30`:void 0,children:[(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Provider access`,description:`Choose whether this application can use every provider supported by the gateway or only providers you select.`,action:(0,I.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,I.jsx)(ow,{htmlFor:`configure-providers`,className:`text-xs text-muted-foreground`,children:`Configure individually`}),(0,I.jsx)(CD,{id:`configure-providers`,"aria-label":`Configure providers individually`,checked:n===`selected`,onCheckedChange:t=>{e.updateProxy(t?{providers:{mode:`selected`,selected:(()=>{let e=i.find(e=>e.status===`active`)??i[0];return e?{[e.slug]:mT()}:{}})()}}:{providers:{mode:`all`}})}})]})})}),(0,I.jsx)(oE,{children:n===`all`?(0,I.jsx)(`div`,{className:`rounded-xl border border-emerald-500/25 bg-emerald-500/[0.06] p-4`,children:(0,I.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,I.jsx)(`span`,{className:`mt-0.5 flex size-9 shrink-0 items-center justify-center rounded-lg bg-emerald-500/12 text-emerald-600 dark:text-emerald-400`,children:(0,I.jsx)(la,{className:`size-5`})}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`p`,{className:`text-sm font-semibold`,children:`Every configured instance is allowed`}),(0,I.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:`New provider instances, paths, and models are available automatically. Turn on individual configuration only when this application needs restrictions.`}),(0,I.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:i.length===0?(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`No provider instances yet.`}):i.map(e=>(0,I.jsx)(Lb,{variant:`secondary`,className:H(`bg-background/75 font-mono text-[11px] font-normal`,e.status===`disabled`&&`text-muted-foreground line-through decoration-muted-foreground/50`),title:e.status===`disabled`?`${e.slug} is disabled and serves no traffic`:void 0,children:e.slug},e.slug))})]})]})}):(0,I.jsxs)(`div`,{className:`flex items-start gap-3 rounded-xl bg-muted/45 p-4 ring-1 ring-border/70`,children:[(0,I.jsx)(`span`,{className:`mt-0.5 flex size-9 shrink-0 items-center justify-center rounded-lg bg-background text-muted-foreground shadow-sm ring-1 ring-border`,children:(0,I.jsx)(Ha,{className:`size-4`})}),(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`p`,{className:`text-sm font-medium`,children:[r.length,` of `,i.length,` provider instances enabled`]}),(0,I.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:`Use the switches below. An enabled instance allows every path and model until you add a restriction, and clients reach it at its own slug.`})]})]})})]}),n===`selected`&&s.length===0?(0,I.jsx)(nE,{children:(0,I.jsx)(oE,{children:(0,I.jsx)(uw,{children:`No provider instances to choose from. Add one on the Providers page, then come back to restrict this app to it.`})})}):null,n===`selected`?s.map(n=>(0,I.jsx)(FD,{row:n,config:t.providers.selected?.[n.slug],onChange:r=>e.updateProxy({providers:{mode:`selected`,selected:{...t.providers.selected,[n.slug]:r}}})},n.slug)):null,(0,I.jsx)(zD,{rewrites:t.model_rewrites??{},onChange:t=>e.updateProxy({model_rewrites:t})})]})}function VD({open:e,onOpenChange:t,title:n,description:r,confirmLabel:i=`Confirm`,confirmWord:a,destructive:o,pending:s,onConfirm:c}){let[l,u]=(0,v.useState)(``);return(0,I.jsx)(KE,{open:e,onOpenChange:e=>{e||u(``),t(e)},children:(0,I.jsxs)(XE,{className:`sm:max-w-md`,children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{children:n})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[(0,I.jsx)(tD,{asChild:!0,children:(0,I.jsx)(`div`,{className:`space-y-2 text-sm text-muted-foreground`,children:r})}),a?(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsxs)(ow,{htmlFor:`confirm-word`,className:`text-xs`,children:[`Type `,(0,I.jsx)(`span`,{className:`font-mono text-foreground`,children:a}),` to continue`]}),(0,I.jsx)($,{id:`confirm-word`,value:l,autoComplete:`off`,className:`font-mono`,onChange:e=>u(e.target.value)})]}):null]}),(0,I.jsxs)($E,{children:[(0,I.jsx)(J,{variant:`outline`,onClick:()=>t(!1),children:`Cancel`}),(0,I.jsx)(J,{variant:o?`destructive`:`default`,disabled:!(!a||l===a)||s,onClick:c,children:i})]})]})})}function HD({appId:e,state:t}){let n=t.draft,r=ht(),i=FS(),{readOnly:a}=sx(),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(!1),u=async()=>{try{await navigator.clipboard.writeText(e),l(!0),U.success(`Application id copied`)}catch{U.error(`Could not copy the application id`)}},d=async()=>{try{let t=await i.mutateAsync(e);U.success(`Deleted ${n.name}`,{description:`${t.removed_users} users removed. Usage history was kept.`}),r(`/apps`)}catch(e){U.error(e instanceof Error?e.message:`Could not delete the app`)}};return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsx)(nE,{children:(0,I.jsxs)(oE,{className:`space-y-5`,children:[(0,I.jsx)(sw,{label:`Name`,htmlFor:`app-name`,children:(0,I.jsx)($,{id:`app-name`,value:n.name,maxLength:100,disabled:a,className:`max-w-md`,onChange:e=>t.update({name:e.target.value})})}),(0,I.jsx)(sw,{label:`Application id`,htmlFor:`app-id`,hint:`Fixed when the app was created. It is part of every URL your clients call.`,children:(0,I.jsxs)(`div`,{className:`flex max-w-md gap-2`,children:[(0,I.jsx)($,{id:`app-id`,value:e,readOnly:!0,className:`font-mono text-xs`}),(0,I.jsxs)(J,{type:`button`,variant:`outline`,className:`min-w-24`,onClick:()=>void u(),children:[c?(0,I.jsx)(ra,{className:`size-4`}):(0,I.jsx)(ha,{className:`size-4`}),c?`Copied`:`Copy`]})]})})]})}),(0,I.jsx)(nE,{children:(0,I.jsx)(oE,{children:(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-1`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:`App enabled`}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Turned off, this app refuses every request. Nothing is deleted, and turning it back on restores it as it was.`})]}),(0,I.jsx)(CD,{"aria-label":`App enabled`,checked:n.status===`active`,disabled:a,onCheckedChange:e=>t.update({status:e?`active`:`disabled`})})]})})}),(0,I.jsx)(nE,{className:`border-destructive/40`,children:(0,I.jsx)(rE,{children:(0,I.jsx)(lw,{title:`Delete this app`,description:`Clients of this app stop working immediately. Registered users and App Attest keys are removed. Usage history is kept for accounting.`,action:(0,I.jsx)(iw,{variant:`destructive`,size:`sm`,disabled:i.isPending,onClick:()=>s(!0),children:`Delete app`})})})}),(0,I.jsx)(VD,{open:o,onOpenChange:s,title:`Delete ${n.name}?`,description:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`p`,{children:`Clients of this app stop working immediately. Registered users and App Attest keys are removed; usage history is kept for accounting.`}),(0,I.jsx)(`p`,{children:`This cannot be undone.`})]}),confirmWord:e,confirmLabel:`Delete app`,destructive:!0,pending:i.isPending,onConfirm:()=>void d()})]})}var UD=25;function WD({appId:e}){let[t,n]=(0,v.useState)(yC()),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(`all`),[s,c]=(0,v.useState)(0),[l,u]=(0,v.useState)(null),d=zS(e,{month:t,query:r||void 0,status:a===`all`?void 0:a,limit:UD,offset:s*UD}),f=BS(e),p=async()=>{if(!l)return;let e=l.status===`active`;try{await f.mutateAsync({userId:l.id,blocked:e}),U.success(e?`Blocked ${l.id}`:`Unblocked ${l.id}`,{description:e?`Their Durable Object was updated, so it applies even to a live gateway token.`:void 0}),u(null)}catch(e){U.error(e instanceof Error?e.message:`Could not update the user`)}},m=d.data?.total??0,h=Math.max(1,Math.ceil(m/UD));return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,I.jsxs)(`div`,{className:`relative min-w-[220px] flex-1`,children:[(0,I.jsx)(Ia,{className:`absolute top-1/2 left-2.5 size-3.5 -translate-y-1/2 text-muted-foreground`}),(0,I.jsx)($,{value:r,placeholder:`Search user id`,className:`h-9 pl-8 font-mono text-xs`,onChange:e=>{i(e.target.value),c(0)}})]}),(0,I.jsxs)(zT,{value:a,onValueChange:e=>{o(e),c(0)},children:[(0,I.jsx)(VT,{className:`w-[140px]`,size:`sm`,children:(0,I.jsx)(BT,{})}),(0,I.jsxs)(HT,{children:[(0,I.jsx)(UT,{value:`all`,children:`All users`}),(0,I.jsx)(UT,{value:`active`,children:`Active`}),(0,I.jsx)(UT,{value:`blocked`,children:`Blocked`})]})]}),(0,I.jsx)(qT,{value:t,onChange:n})]}),(0,I.jsx)(nE,{className:`overflow-hidden py-0`,children:(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{className:`hover:bg-transparent`,children:[(0,I.jsx)(Z,{children:`User`}),(0,I.jsx)(Z,{children:`Attestation`}),(0,I.jsx)(Z,{children:`Last seen`}),(0,I.jsx)(Z,{className:`text-right`,children:`Requests`}),(0,I.jsx)(Z,{className:`text-right`,children:`Tokens`}),(0,I.jsx)(Z,{className:`text-right`,children:`Cost`}),(0,I.jsx)(Z,{className:`w-24`})]})}),(0,I.jsx)(lE,{children:d.isPending?[0,1,2].map(e=>(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:7,children:(0,I.jsx)(aw,{className:`h-8 w-full`})})},e)):d.data?.users.length===0?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:7,className:`py-10 text-center text-sm text-muted-foreground`,children:`No users yet. A row appears once a client completes its first token exchange.`})}):d.data?.users.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{children:(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(`span`,{className:`font-mono text-xs`,children:e.id}),e.status===`blocked`?(0,I.jsx)(tC,{status:`blocked`}):null]})}),(0,I.jsx)(Q,{children:e.attest_registered?(0,I.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,I.jsx)(Lb,{variant:`secondary`,className:`text-[11px] font-normal`,children:`registered`}),(0,I.jsxs)(`span`,{className:`tabular text-[11px] text-muted-foreground`,children:[`counter `,e.attest_counter]})]}):(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.is_virtual?`server attributed`:`issuer token`})}),(0,I.jsx)(Q,{className:`text-xs text-muted-foreground`,children:hC(e.last_seen_at)}),(0,I.jsx)(Q,{className:`tabular text-right`,children:cC(e.usage.requests)}),(0,I.jsx)(Q,{className:`tabular text-right`,children:lC(vC(e.usage))}),(0,I.jsx)(Q,{className:`tabular text-right`,children:dC(e.usage.cost_usd)}),(0,I.jsx)(Q,{className:`text-right`,children:(0,I.jsx)(iw,{variant:`ghost`,size:`sm`,disabled:e.is_virtual,onClick:()=>u(e),className:e.status===`active`?`text-destructive`:void 0,children:e.status===`active`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)($i,{className:`size-3.5`}),`Block`]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(la,{className:`size-3.5`}),`Unblock`]})})})]},e.id))})]})}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-muted-foreground`,children:[(0,I.jsxs)(`span`,{children:[cC(m),` users · page `,s+1,` of `,h]}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(J,{variant:`outline`,size:`sm`,disabled:s===0,onClick:()=>c(e=>e-1),children:`Previous`}),(0,I.jsx)(J,{variant:`outline`,size:`sm`,disabled:s+1>=h,onClick:()=>c(e=>e+1),children:`Next`})]})]}),(0,I.jsx)(VD,{open:l!==null,onOpenChange:e=>!e&&u(null),title:l?.status===`active`?`Block ${l?.id}?`:`Unblock ${l?.id}?`,description:l?.status===`active`?(0,I.jsx)(`p`,{children:`Their requests are refused immediately, even with an unexpired gateway token, because the block is written to their Durable Object as well as D1.`}):(0,I.jsx)(`p`,{children:`Their requests resume as soon as the Durable Object is updated.`}),confirmLabel:l?.status===`active`?`Block user`:`Unblock user`,destructive:l?.status===`active`,pending:f.isPending,onConfirm:()=>void p()})]})}var GD=(0,v.lazy)(()=>w(()=>import(`./usage-D26T_dIp.js`).then(e=>({default:e.UsageTab})),[])),KD=(0,v.lazy)(()=>w(()=>import(`./endpoints-DApt6mPC.js`).then(e=>({default:e.EndpointsTab})),[]));function qD(){let{appId:e=``,tab:t=`overview`,section:n}=_t(),r=QT(e),[i,a]=(0,v.useState)(yC()),o=iC.find(e=>e.slug===t),{query:s,draft:c,dirty:l}=r,u=c?tE(c):null;return s.isError?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`Could not load this app`}),(0,I.jsxs)(ks,{children:[s.error instanceof Error?s.error.message:`Unknown error`,(0,I.jsx)(Pn,{to:`/apps`,className:`underline underline-offset-4`,children:`Back to apps`})]})]}):(0,I.jsxs)(`div`,{className:`space-y-6 pb-24`,children:[(0,I.jsx)(cw,{title:o?.label??`Overview`,action:t===`overview`?(0,I.jsx)(qT,{value:i,onChange:a}):void 0}),s.data?.config_error?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`The stored configuration is invalid`}),(0,I.jsxs)(ks,{children:[s.data.config_error,`. The gateway rejects requests for this app until it is fixed.`]})]}):null,c?(0,I.jsx)(RT,{proxy:c.config.routing}):null,s.isPending||!c?(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(aw,{className:`h-32 w-full`}),(0,I.jsx)(aw,{className:`h-64 w-full`})]}):t===`overview`?(0,I.jsx)(xD,{appId:e,month:i,state:r}):t===`auth`?(0,I.jsx)(dD,{appId:e,level:n,state:r}):t===`proxy`?(0,I.jsx)(BD,{state:r}):t===`limits`?(0,I.jsx)(yD,{state:r}):t===`users`?(0,I.jsx)(WD,{appId:e}):t===`auth-events`?(0,I.jsx)(hE,{appId:e}):t===`settings`?(0,I.jsx)(HD,{appId:e,state:r}):(0,I.jsx)(v.Suspense,{fallback:(0,I.jsx)(aw,{className:`h-64 w-full`}),children:t===`usage`?(0,I.jsx)(GD,{appId:e}):(0,I.jsx)(KD,{appId:e,state:r})}),l?(0,I.jsx)(`div`,{className:`fixed inset-x-0 bottom-0 z-40 border-t bg-background/95 backdrop-blur`,children:(0,I.jsxs)(`div`,{className:`mx-auto flex max-w-7xl items-center gap-3 px-4 py-3 sm:px-6`,children:[(0,I.jsxs)(`span`,{className:`text-sm`,children:[(0,I.jsx)(`span`,{className:`mr-2 inline-block size-2 rounded-full bg-amber-500 align-middle`}),`Unsaved changes to `,(0,I.jsx)(`span`,{className:`font-medium`,children:c?.name??e})]}),(0,I.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,I.jsx)(J,{variant:`ghost`,size:`sm`,onClick:r.reset,disabled:r.saving,children:`Discard`}),(0,I.jsxs)(iw,{size:`sm`,reason:u??void 0,onClick:()=>void r.save(),disabled:r.saving,children:[r.saving?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Save changes`]})]})]})}):null]})}var JD=[{id:`ios`,label:`iOS application`,description:`Calls AI providers straight from the app.`,icon:Ua},{id:`server`,label:`Server`,description:`A backend you run, using a private API key.`,icon:La}],YD={basics:{id:`basics`,label:`Basics`},app_identity:{id:`app_identity`,label:`Application identity`,subtitle:`Application identity`,text:`Set your app's identity so that only this app can call AI providers through this gateway.`},users:{id:`users`,label:`User authentication`,subtitle:`User authentication`,text:`Choose whether only users signed in to your app can call AI through this gateway.`},identity_provider:{id:`identity_provider`,label:`Identity provider`,subtitle:`Identity provider`,text:`Where your users sign in. The gateway verifies their sign-in tokens against it.`},subscription:{id:`subscription`,label:`Subscription check`,subtitle:`Subscription check`,text:`Check that the user has paid for the app before they can call AI providers through this gateway.`}},XD=IE.find(e=>e.id===`none`);function ZD({trigger:e}={}){let{capabilities:t}=sx(),[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(0),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(void 0),[g,_]=(0,v.useState)(null),[y,b]=(0,v.useState)(DE[0]),[x,S]=(0,v.useState)({}),[C,w]=(0,v.useState)(XD),[T,E]=(0,v.useState)({}),[ee,D]=(0,v.useState)(null),[O,k]=(0,v.useState)(``),[A,j]=(0,v.useState)(!1),[te,ne]=(0,v.useState)(!1),M=ht(),N=PS(),P=(0,v.useMemo)(()=>{let e=[YD.basics];return c===`ios`&&e.push(YD.app_identity),e.push(YD.users),g===`issuer`&&e.push(YD.identity_provider,YD.subscription),e},[c,g]),re=P[Math.min(i,P.length-1)],ie=i>=P.length-1,ae=(0,v.useMemo)(()=>TE(y,x),[y,x]),oe=LE(y,x)&&ae.jwks_url.startsWith(`https://`)&&ae.issuer.length>0&&ae.audience.length>0,F=(()=>{switch(re.id){case`basics`:return o.trim().length>0&&c!==null;case`app_identity`:return u.trim().length>0&&f.trim().length>0;case`users`:return g!==null;case`identity_provider`:return oe;case`subscription`:return LE(C,T)}})(),se=()=>{a(0),s(``),l(null),d(``),p(``),h(void 0),_(null),b(DE[0]),S({}),w(XD),E({})},ce=e=>{e&&se(),r(e)},le=e=>{e!==c&&(l(e),_(null))},ue=()=>{let e=g===`issuer`?{source:`issuer`,issuer:{provider:y.id,jwks_url:ae.jwks_url,issuer:ae.issuer,audience:ae.audience,user_id_claim:ae.user_id_claim,required_claims:EE(C,T),max_token_lifetime_seconds:86400,...C.id===`none`?{}:{entitlement:C.id}}}:null;return c===`ios`?{type:`apple_app_attest`,app_attest:{team_id:u.trim(),bundle_id:f.trim(),...m?.includes(`development`)?{environments:m}:{}},end_user:e??{source:`app_install`}}:e?{type:`api_key`,end_user:e}:g===`header`?{type:`api_key`,end_user:{source:`header`,header:iT}}:{type:`api_key`}},de=async()=>{if(c)try{let e=await N.mutateAsync({name:o.trim(),config:{authentication:ue(),routing:{providers:{mode:`all`},model_rewrites:{}},...c===`server`?{}:{limits:{per_user:{requests:{per_minute:10,per_day:300},spending:{monthly_usd:null}},per_app:{requests:{per_minute:null,per_day:null},spending:{monthly_usd:null}}}}},status:`active`});if(r(!1),c===`server`){if(!e.api_key)throw Error(`The app was created without its initial API key`);k(e.app.id),D(e.api_key),ne(!1),j(!0);return}U.success(`Created ${e.app.id}`),M(`/apps/${e.app.id}/proxy`)}catch(e){U.error(e instanceof Error?e.message:`Could not create the app`)}},fe=()=>{_(c===`ios`?`app_install`:`none`),a(P.findIndex(e=>e.id===`users`))},pe=()=>{if(ie){de();return}a(e=>e+1)},me=async()=>{if(ee)try{await navigator.clipboard.writeText(ee.key),ne(!0),U.success(`API key copied`)}catch{U.error(`Could not copy the API key`)}},he=()=>{j(!1),U.success(`Created ${O}`),M(`/apps/${O}/proxy`)};return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(KE,{open:n,onOpenChange:ce,children:[(0,I.jsx)(qE,{asChild:!0,children:e??(0,I.jsxs)(iw,{size:`sm`,children:[(0,I.jsx)(Na,{className:`size-4`}),`New app`]})}),(0,I.jsxs)(XE,{className:`sm:max-w-2xl`,children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{children:`Create a new application`})}),(0,I.jsxs)(QE,{className:`space-y-6`,children:[re.subtitle?(0,I.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,I.jsx)(`h3`,{className:`text-base font-semibold`,children:re.subtitle}),re.text?(0,I.jsx)(`p`,{className:`text-sm text-pretty text-muted-foreground`,children:re.text}):null]}):null,re.id===`basics`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,I.jsx)(ow,{htmlFor:`app-name`,children:`Application name`}),(0,I.jsx)($,{id:`app-name`,value:o,placeholder:`Calorie Tracker`,maxLength:100,autoFocus:!0,onChange:e=>s(e.target.value)})]}),(0,I.jsxs)(`fieldset`,{className:`space-y-3`,children:[(0,I.jsx)(`legend`,{className:`text-sm font-medium`,children:`Application type`}),(0,I.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2`,role:`radiogroup`,children:JD.map(e=>{let t=e.icon,n=c===e.id;return(0,I.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":n,className:H(`group min-h-32 rounded-xl bg-background p-5 text-left shadow-sm ring-1 ring-border transition-[box-shadow,background-color] hover:bg-muted/40 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,n&&`bg-primary/[0.04] shadow-md ring-2 ring-primary`),onClick:()=>le(e.id),children:[(0,I.jsx)(`span`,{className:H(`mb-3 flex size-10 items-center justify-center rounded-lg bg-muted text-muted-foreground transition-[background-color,color]`,n&&`bg-primary text-primary-foreground`),children:(0,I.jsx)(t,{className:`size-5`})}),(0,I.jsx)(`span`,{className:`block text-sm font-semibold`,children:e.label}),(0,I.jsx)(`span`,{className:`mt-1 block text-xs leading-relaxed text-muted-foreground`,children:e.description})]},e.id)})})]})]}):null,re.id===`app_identity`?(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,I.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,I.jsx)(ow,{htmlFor:`apple-team-id`,children:`Apple Team ID`}),(0,I.jsx)($,{id:`apple-team-id`,value:u,placeholder:`ABCDE12345`,className:`font-mono text-xs`,autoFocus:!0,onChange:e=>d(e.target.value)}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`In your Apple Developer account under`,` `,(0,I.jsx)(bE,{href:`https://developer.apple.com/account#MembershipDetailsCard`,children:`Membership details`}),`.`]})]}),(0,I.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,I.jsx)(ow,{htmlFor:`apple-bundle-id`,children:`Bundle ID`}),(0,I.jsx)($,{id:`apple-bundle-id`,value:f,placeholder:`com.example.calorietracker`,className:`font-mono text-xs`,onChange:e=>p(e.target.value)}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`In Xcode, on your target's`,` `,(0,I.jsx)(bE,{href:`https://developer.apple.com/documentation/xcode/configuring-the-build-settings-of-a-target#Set-the-bundle-ID`,children:`Signing & Capabilities`}),` `,`tab.`]})]})]}),(0,I.jsx)(vE,{value:m,onChange:h,compact:!0})]}):null,re.id===`users`?(0,I.jsx)(yE,{label:`User authentication`,choices:c===`ios`?WE:GE,value:g,onChange:_}):null,re.id===`identity_provider`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(xE,{idPrefix:`issuer`,label:`Identity provider`,presets:DE,selected:y,values:x,compact:!0,onSelect:e=>{b(e),S({})},onValueChange:(e,t)=>S(n=>({...n,[e]:t}))}),(0,I.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Don't have these details yet?`,` `,(0,I.jsx)(`button`,{type:`button`,className:`font-medium text-primary-ink underline decoration-primary-ink/40 underline-offset-4 transition-colors hover:decoration-primary-ink`,onClick:fe,children:c===`ios`?`Allow unauthenticated users for now`:`Continue without user identity for now`}),` `,`and set this up later.`]})]}):null,re.id===`subscription`?(0,I.jsx)(xE,{idPrefix:`entitlement`,label:FE,presets:IE,selected:C,values:T,compact:!0,onSelect:e=>{w(e),E({})},onValueChange:(e,t)=>E(n=>({...n,[e]:t}))}):null]}),(0,I.jsxs)($E,{className:`items-center sm:justify-between`,children:[i>0?(0,I.jsxs)(J,{variant:`ghost`,onClick:()=>a(e=>e-1),disabled:N.isPending,children:[(0,I.jsx)(Xi,{className:`size-4`}),`Back`]}):(0,I.jsx)(J,{variant:`outline`,onClick:()=>r(!1),children:`Cancel`}),(0,I.jsx)(QD,{steps:P,current:i,onSelect:a}),(0,I.jsxs)(J,{disabled:!F||N.isPending,onClick:pe,children:[N.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,ie?`Create app`:`Next`]})]})]})]}),(0,I.jsx)(KE,{open:A,onOpenChange:e=>{e||he()},children:(0,I.jsxs)(XE,{showCloseButton:!1,className:`sm:max-w-lg`,onEscapeKeyDown:e=>e.preventDefault(),children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{className:`text-balance`,children:`Your application is ready`})}),(0,I.jsxs)(QE,{className:`space-y-5`,children:[(0,I.jsxs)(tD,{className:`text-pretty`,children:[`This is the API key for`,` `,(0,I.jsx)(`span`,{className:`font-mono text-foreground`,children:O}),`. It is shown only once, so copy it now.`]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`created-api-key`,children:`API key`}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)($,{id:`created-api-key`,value:ee?.key??``,readOnly:!0,className:`font-mono text-xs`}),(0,I.jsxs)(J,{type:`button`,variant:`outline`,className:`min-w-24`,onClick:()=>void me(),children:[te?(0,I.jsx)(ra,{className:`size-4`}):(0,I.jsx)(ha,{className:`size-4`}),te?`Copied`:`Copy`]})]})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:`Base URL`}),(0,I.jsxs)(`code`,{className:`block rounded-md bg-muted px-3 py-2 font-mono text-xs break-all text-muted-foreground`,children:[bD(t),`/v1/apps/`,(0,I.jsx)(`span`,{className:`text-foreground`,children:O}),`/proxy/{provider}/{provider_path}`]})]})]}),(0,I.jsx)($E,{children:(0,I.jsx)(J,{onClick:he,children:`I’ve saved this key`})})]})})]})}function QD({steps:e,current:t,onSelect:n}){return(0,I.jsx)(`ol`,{className:`flex items-center gap-2`,"aria-label":`Steps`,children:e.map((e,r)=>{let i=r<t,a=r===t,o=(0,I.jsx)(`span`,{className:H(`block size-2 rounded-full transition-colors`,a?`bg-primary`:i?`bg-primary/40`:`bg-border`)});return(0,I.jsx)(`li`,{"aria-current":a?`step`:void 0,children:i?(0,I.jsx)(`button`,{type:`button`,"aria-label":`Back to ${e.label}`,className:`flex size-5 items-center justify-center rounded-full hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,onClick:()=>n(r),children:o}):(0,I.jsx)(`span`,{className:`flex size-5 items-center justify-center`,"aria-label":`${e.label}${a?`, current step`:``}`,children:o})},e.id)})})}function $D({label:e,children:t}){return(0,I.jsxs)(Rb,{children:[(0,I.jsx)(zb,{asChild:!0,children:(0,I.jsx)(J,{variant:`ghost`,size:`icon-sm`,"aria-label":`Actions for ${e}`,children:(0,I.jsx)(_a,{})})}),(0,I.jsx)(Bb,{align:`end`,className:`min-w-44`,children:t})]})}function eO({reason:e,destructive:t,onSelect:n,children:r}){let{readOnly:i}=sx(),a=(0,v.useId)(),o=e??(i?`Your role is read-only. Ask an owner or admin to make this change.`:void 0),s=t?`destructive`:`default`;return o?(0,I.jsx)(rw,{reason:o,reasonId:a,className:`w-full`,children:(0,I.jsx)(Vb,{variant:s,disabled:!0,"aria-describedby":a,className:`w-full`,children:r})}):(0,I.jsx)(Vb,{variant:s,onSelect:n,children:r})}var tO={"data-1p-ignore":`true`,"data-lpignore":`true`},nO={autoComplete:`off`,...tO},rO={type:`password`,autoComplete:`new-password`,spellCheck:!1,...tO};function iO(e){return Object.entries(e??{}).map(([e,t])=>({model:e,input:String(t.input),output:String(t.output)}))}function aO(e){let t={};for(let n of e){let e=n.model.trim(),r=n.input.trim(),i=n.output.trim();if(!e&&!r&&!i)continue;if(!e)return{error:`Every pricing row needs a model name`};if(!r||!i)return{error:`Enter both prices for ${e} — use 0 only if it is genuinely free`};let a=Number(r),o=Number(i);if(!Number.isFinite(a)||a<0||!Number.isFinite(o)||o<0)return{error:`Prices for ${e} must be numbers of 0 or more`};if(Object.hasOwn(t,e))return{error:`${e} is priced twice — remove the duplicate row`};t[e]={input:a,output:o}}return{pricing:t}}function oO(e,t){return e instanceof Error?e.message:t}var sO=e=>`gateway-${e}`,cO=`/providers/gateways`;function lO(e){if(e.referencedCount!==0)return e.providerCount===0?`Disabled provider instances still reference this gateway; delete them to release it`:e.referencedCount>e.providerCount?`Delete the active and disabled provider instances routed through this gateway first`:`Delete every active provider instance routed through this gateway first`}function uO({label:e,value:t}){return(0,I.jsxs)(`div`,{children:[e,`: `,(0,I.jsx)(`span`,{className:`font-mono text-xs`,children:t})]})}function dO({row:e,gateways:t}){if(e.providerGatewayId===null)return(0,I.jsxs)(`div`,{className:`space-y-0.5`,children:[e.secretHint===null?(0,I.jsx)(`div`,{children:`API key`}):(0,I.jsx)(uO,{label:`API key`,value:`…${e.secretHint}`}),e.baseUrl===null?null:(0,I.jsx)(uO,{label:`Base URL`,value:e.baseUrl})]});let n=t.find(t=>t.id===e.providerGatewayId);return n?(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[`Gateway:`,(0,I.jsx)(NT,{type:n.type}),(0,I.jsx)(Pn,{className:`text-primary-ink underline underline-offset-4`,to:`${cO}#${sO(n.id)}`,children:n.name})]}):(0,I.jsx)(I.Fragment,{children:`Gateway`})}function fO({gateway:e}){return(0,I.jsxs)(`div`,{className:`space-y-0.5`,children:[e.type===`cf_aig`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(uO,{label:`Account ID`,value:e.config.accountId}),(0,I.jsx)(uO,{label:`Gateway ID`,value:e.config.gatewayId})]}):null,(0,I.jsx)(uO,{label:`API key`,value:`…${e.secretHint}`})]})}var pO=[{slug:`providers`,path:`/providers`,Component:vO},{slug:`gateways`,path:cO,Component:OO}],mO=pO[0];function hO(){return(0,I.jsx)(Lb,{variant:`outline`,className:`border-muted-foreground/30 text-muted-foreground`,children:`disabled`})}function gO({slug:e,names:t}){return t.length===0?null:(0,I.jsxs)(`p`,{children:[(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:t.join(`, `)}),` `,t.length===1?`names`:`name`,` `,(0,I.jsx)(`span`,{className:`font-mono text-foreground`,children:e}),` in its configuration.`]})}function _O(){let{section:e}=_t(),t=e===void 0?mO:pO.find(t=>t.slug===e);return t?(0,I.jsx)(t.Component,{}):(0,I.jsx)(Vt,{to:mO.path,replace:!0})}function vO(){let{readOnly:e}=sx(),t=dS(),n=_S(),r=wS(),i=CS(),a=jS(yC()),[o,s]=(0,v.useState)(!1),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(null),g=t.data?.providers??[],_=n.data?.gateways??[],y=e=>(a.data?.apps??[]).filter(t=>t.referenced_providers.includes(e)).map(e=>e.name),b=async()=>{if(f)try{await r.mutateAsync(f.id),U.success(`Deleted ${f.name}`),p(null)}catch(e){U.error(oO(e,`Could not delete the provider`))}},x=async()=>{if(m)try{await i.mutateAsync({id:m.id,body:{status:`disabled`}}),U.success(`Disabled ${m.name}`),h(null)}catch(e){U.error(oO(e,`Could not disable the provider`))}},S=async e=>{try{await i.mutateAsync({id:e.id,body:{status:`active`}}),U.success(`Enabled ${e.name}`)}catch(e){U.error(oO(e,`Could not enable the provider`))}};return(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsx)(cw,{title:`Providers`,description:`Set up the AI providers your apps use.`,action:(0,I.jsxs)(iw,{size:`sm`,onClick:()=>s(!0),children:[(0,I.jsx)(Na,{className:`size-4`}),`Add provider`]})}),t.isError?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`Could not load providers`}),(0,I.jsx)(ks,{children:oO(t.error,`Unknown error`)})]}):null,(0,I.jsx)(nE,{className:`overflow-hidden py-0`,children:(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{children:[(0,I.jsx)(Z,{children:`Name`}),(0,I.jsx)(Z,{children:`Provider`}),(0,I.jsx)(Z,{children:`Slug`}),(0,I.jsx)(Z,{children:`Auth`}),(0,I.jsx)(Z,{className:`text-right`,children:`Actions`})]})}),(0,I.jsx)(lE,{children:t.isPending?[0,1,2].map(e=>(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:5,children:(0,I.jsx)(aw,{className:`h-5 w-full`})})},e)):g.length===0?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:5,className:`py-10 text-center text-sm text-muted-foreground`,children:`No providers yet. Add a key per provider, or route one through a gateway.`})}):g.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{className:`font-medium`,children:(0,I.jsxs)(`span`,{className:`flex items-center gap-2`,children:[e.name,e.status===`disabled`?(0,I.jsx)(hO,{}):null]})}),(0,I.jsx)(Q,{children:(0,I.jsxs)(Lb,{variant:`secondary`,children:[(0,I.jsx)(MT,{type:e.type}),eT[e.type]]})}),(0,I.jsx)(Q,{className:`font-mono text-xs`,children:e.slug}),(0,I.jsx)(Q,{className:`text-sm text-muted-foreground`,children:(0,I.jsx)(dO,{row:e,gateways:_})}),(0,I.jsx)(Q,{className:`text-right`,children:(0,I.jsxs)($D,{label:e.name,children:[(0,I.jsxs)(Vb,{onSelect:()=>l(e),children:[(0,I.jsx)(da,{}),`Pricing`]}),(0,I.jsxs)(eO,{reason:e.providerGatewayId===null?void 0:`This instance authenticates with the gateway token — update the gateway's token instead`,onSelect:()=>d(e),children:[(0,I.jsx)(Pa,{}),`Update key`]}),(0,I.jsx)(Gb,{}),e.status===`disabled`?(0,I.jsxs)(eO,{onSelect:()=>void S(e),children:[(0,I.jsx)(fa,{}),`Enable provider`]}):(0,I.jsxs)(eO,{onSelect:()=>h(e),children:[(0,I.jsx)(pa,{}),`Disable provider`]}),(0,I.jsxs)(eO,{destructive:!0,onSelect:()=>p(e),children:[(0,I.jsx)(Ga,{}),`Delete provider`]})]})})]},e.id))})]})}),(0,I.jsx)(EO,{open:o,onOpenChange:s,providers:g,gateways:_}),(0,I.jsx)(MO,{provider:u,onClose:()=>d(null)},u?.id),(0,I.jsx)(NO,{provider:c,onClose:()=>l(null),readOnly:e}),(0,I.jsx)(VD,{open:f!==null,onOpenChange:e=>{e||p(null)},title:`Delete provider`,description:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`p`,{children:[`Apps using`,` `,(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:f?eT[f.type]:``}),` `,`start failing within a minute, and any custom pricing on this provider is deleted with it.`]}),f?(0,I.jsx)(gO,{slug:f.slug,names:y(f.slug)}):null,(0,I.jsx)(`p`,{children:`This cannot be undone. Update the key instead if you only want to replace it, or disable the provider to pause it and keep the key.`})]}),confirmLabel:`Delete provider`,destructive:!0,pending:r.isPending,onConfirm:()=>void b()}),(0,I.jsx)(VD,{open:m!==null,onOpenChange:e=>{e||h(null)},title:`Disable provider`,description:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`p`,{children:[`Requests to`,` `,(0,I.jsx)(`span`,{className:`font-mono text-foreground`,children:m?.slug??``}),` start failing within a minute.`]}),m?(0,I.jsx)(gO,{slug:m.slug,names:y(m.slug)}):null]}),confirmLabel:`Disable provider`,pending:i.isPending,onConfirm:()=>void x()})]})}var yO=`__new__`,bO={works:{icon:la,className:`bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`},unconfirmed:{icon:xa,className:`bg-muted text-muted-foreground`},failed:{icon:ca,className:`bg-destructive/10 text-destructive`}};function xO(e){return e.reason===`unexpected_status`&&e.status!==void 0&&e.status<500&&e.status!==429}function SO(e,t,n){let r=eT[t],i=n?`The gateway`:r;switch(e.reason){case`no_probe`:return`There is no test call for ${r}, so nothing was checked. Add it if you know it is right.`;case`unreachable`:return`${i} did not answer in time, so nothing is proven either way.`;case`unexpected_status`:return xO(e)?n?`The gateway answered with HTTP ${e.status}. Check that it holds a stored key for ${r}.`:`${r} answered with HTTP ${e.status}, so this key could not be used.`:`${i} answered with HTTP ${e.status}, so nothing is proven either way.`;default:return`Nothing is proven either way. Add it if you know it is right.`}}function CO(e,t,n){if(e.validated)return{status:`works`,message:`Works. The provider accepted this credential.`};let r=SO(e,t,n);return xO(e)?{status:`failed`,message:r}:{status:`unconfirmed`,message:r}}function wO(e){if(e.validated)return{status:`works`,message:`Works. The gateway accepted this token.`};if(e.reason===`rejected`)return{status:`failed`,message:`The gateway refused this token (HTTP ${e.status}). Check the token itself, that authentication is turned on, and that the gateway holds a key for OpenAI.`};if(e.reason===`unreachable`)return{status:`unconfirmed`,message:`The gateway did not answer in time, so nothing is proven either way.`};let t=e.reason===`unexpected_status`?`The gateway answered with HTTP ${e.status}. Check the account and gateway IDs.`:`Nothing is proven either way. Add it if you know it is right.`;return{status:xO(e)?`failed`:`unconfirmed`,message:t}}function TO({outcome:e}){let{icon:t,className:n}=bO[e.status];return(0,I.jsxs)(`p`,{"aria-live":`polite`,className:H(`flex items-start gap-2 rounded-md px-3 py-2 text-xs`,n),children:[(0,I.jsx)(t,{className:`mt-px size-3.5 shrink-0`}),e.message]})}function EO({open:e,onOpenChange:t,providers:n,gateways:r}){let i=mS(),a=hS(),[o,s]=(0,v.useState)(`openai`),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(`key`),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(``),[g,_]=(0,v.useState)(``),[y,b]=(0,v.useState)(``),[x,S]=(0,v.useState)(!1),[C,w]=(0,v.useState)(!1),[T,E]=(0,v.useState)(null),[ee,D]=(0,v.useState)(null),O=(0,v.useRef)(null),k=(0,v.useRef)(!1);(0,v.useEffect)(()=>{!k.current||!O.current||(k.current=!1,O.current.focus())});let A=r.filter(e=>e.status===`active`),j=T&&!A.some(e=>e.id===T.id)?[...A,T]:A,te=e=>n.some(t=>t.slug===e),ne=x||te(o),M=e=>{s(e),S(!1),D(null),te(e)?k.current=!0:b(``)},N=u===`key`?!!f:!!g,P=!!c.trim()&&N&&(!ne||!!y.trim()),re=()=>{s(`openai`),l(``),d(`key`),p(``),h(``),_(``),b(``),S(!1),E(null),D(null),i.reset(),a.reset()},ie=()=>{re(),t(!1)},ae=u===`key`&&m.trim()?{baseUrl:m.trim()}:{},oe=async()=>{if(N){D(null);try{let e=await a.mutateAsync({type:o,...u===`key`?{secret:f,...ae}:{providerGatewayId:g}});D(CO(e,o,u===`gateway`))}catch(e){D({status:`failed`,message:oO(e,`The credential could not be checked`)})}finally{a.reset()}}},F=async()=>{if(P)try{await i.mutateAsync({type:o,name:c.trim(),...y.trim()?{slug:y.trim()}:{},...u===`key`?{secret:f,...ae}:{providerGatewayId:g}}),ie(),U.success(`Added ${eT[o]}`)}catch(e){p(``),e instanceof ux&&e.code===`slug_taken`&&(S(!0),k.current=!0),U.error(oO(e,`Could not store the credential`))}};return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(nD,{open:e,onOpenChange:e=>e?t(!0):ie(),title:`Add a provider`,submitLabel:`Add provider`,pending:i.isPending,disabled:!P,onSubmit:()=>void F(),secondaryAction:(0,I.jsxs)(J,{type:`button`,variant:`secondary`,className:`sm:mr-auto`,disabled:!N||a.isPending,onClick:()=>void oe(),children:[a.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Test provider`]}),children:(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsx)(sw,{label:`Name`,htmlFor:`provider-name`,hint:`How this provider is named in the list.`,children:(0,I.jsx)($,{id:`provider-name`,...nO,value:c,placeholder:`Prod OpenAI`,autoFocus:!0,onChange:e=>l(e.target.value)})}),(0,I.jsx)(sw,{label:`Provider`,htmlFor:`provider-type`,children:(0,I.jsxs)(zT,{value:o,onValueChange:e=>M(e),children:[(0,I.jsx)(VT,{id:`provider-type`,className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:$w.map(e=>(0,I.jsx)(UT,{value:e,children:(0,I.jsx)(FT,{type:e})},e))})]})}),(0,I.jsx)(sw,{label:`Authentication`,htmlFor:`provider-authentication`,hint:`Call the provider directly, or route through a gateway.`,children:(0,I.jsxs)(zT,{value:u,onValueChange:e=>{d(e),e===`gateway`&&h(``),D(null)},children:[(0,I.jsx)(VT,{id:`provider-authentication`,className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsxs)(HT,{children:[(0,I.jsxs)(UT,{value:`key`,children:[(0,I.jsx)(Sa,{}),`API key`]}),(0,I.jsxs)(UT,{value:`gateway`,children:[(0,I.jsx)(ta,{}),`Use gateway`]})]})]})}),u===`key`?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(sw,{label:`API key`,htmlFor:`provider-secret`,children:(0,I.jsx)($,{id:`provider-secret`,...rO,value:f,placeholder:`sk-…`,onChange:e=>{p(e.target.value),D(null)}})}),(0,I.jsx)(sw,{label:`Base URL (optional)`,htmlFor:`provider-base-url`,hint:`Point this instance at an OpenAI-compatible endpoint you control — Azure OpenAI, vLLM, a proxy. HTTPS, port 443, no path-only tweaks beyond the base. Leave empty to use the provider's own API.`,children:(0,I.jsx)($,{id:`provider-base-url`,...nO,className:`font-mono`,value:m,placeholder:`https://my-vllm.example.com/v1/`,onChange:e=>{h(e.target.value),D(null)}})})]}):(0,I.jsx)(sw,{label:`Gateway`,htmlFor:`provider-gateway`,hint:`The provider's own key lives in that gateway; this row carries no secret.`,children:(0,I.jsxs)(zT,{value:g,onValueChange:e=>{if(e){if(e===yO){w(!0);return}_(e),D(null)}},children:[(0,I.jsx)(VT,{id:`provider-gateway`,className:`w-full`,children:(0,I.jsx)(BT,{placeholder:j.length?`Choose a gateway`:`No gateways yet`})}),(0,I.jsxs)(HT,{children:[j.map(e=>(0,I.jsx)(UT,{value:e.id,children:(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,I.jsx)(NT,{type:e.type}),e.name]})},e.id)),j.length?(0,I.jsx)(WT,{}):null,(0,I.jsxs)(UT,{value:yO,className:`font-medium text-primary-ink focus:text-primary-ink`,children:[(0,I.jsx)(Na,{className:`size-4 text-primary-ink`}),`New gateway…`]})]})]})}),ne?(0,I.jsx)(sw,{label:`Slug`,htmlFor:`provider-slug`,hint:(0,I.jsxs)(I.Fragment,{children:[`Another instance already uses `,(0,I.jsx)(`code`,{className:`font-mono`,children:o}),`, so this one needs its own `,(0,I.jsx)(`code`,{className:`font-mono`,children:`/proxy/<slug>/…`}),` `,`segment.`]}),children:(0,I.jsx)($,{id:`provider-slug`,ref:O,...nO,className:`font-mono`,value:y,placeholder:`${o}-dev`,onChange:e=>b(e.target.value)})}):null,ee?(0,I.jsx)(TO,{outcome:ee}):null]})}),(0,I.jsx)(kO,{open:C,onOpenChange:w,onCreated:e=>{E(e),_(e.id)}})]})}function DO({label:e=`Add provider`}){let[t,n]=(0,v.useState)(!1),r=dS(),i=_S(t);return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(iw,{size:`sm`,onClick:()=>n(!0),children:e}),(0,I.jsx)(EO,{open:t,onOpenChange:n,providers:r.data?.providers??[],gateways:i.data?.gateways??[]})]})}function OO(){let e=_S(),[t,n]=(0,v.useState)(!1),[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(null),l=SS(),u=e.data?.gateways??[],d=e.isError?e.error:null,{hash:f}=dt();(0,v.useEffect)(()=>{f&&document.getElementById(f.slice(1))?.scrollIntoView({behavior:`smooth`,block:`center`})},[f,e.data]);let p=async()=>{if(s)try{await l.mutateAsync(s.id),U.success(`Deleted ${s.name}`),c(null)}catch(e){U.error(oO(e,`Could not delete the gateway`))}};return(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsx)(cw,{title:`Gateways`,description:`Set up the gateways you use to reach AI providers.`,action:(0,I.jsxs)(iw,{size:`sm`,onClick:()=>n(!0),children:[(0,I.jsx)(Na,{className:`size-4`}),`Add gateway`]})}),d?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`Could not load gateways`}),(0,I.jsx)(ks,{children:oO(d,`Unknown error`)})]}):null,(0,I.jsx)(nE,{className:`overflow-hidden py-0`,children:(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{children:[(0,I.jsx)(Z,{children:`Name`}),(0,I.jsx)(Z,{children:`Type`}),(0,I.jsx)(Z,{children:`Auth`}),(0,I.jsx)(Z,{className:`text-right`,children:`Actions`})]})}),(0,I.jsx)(lE,{children:e.isPending?[0,1].map(e=>(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:4,children:(0,I.jsx)(aw,{className:`h-5 w-full`})})},e)):u.length===0?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:4,className:`py-10 text-center text-sm text-muted-foreground`,children:`No gateways yet. Add one to route providers through it.`})}):u.map(e=>(0,I.jsxs)(uE,{id:sO(e.id),children:[(0,I.jsx)(Q,{className:`font-medium`,children:e.name}),(0,I.jsx)(Q,{children:(0,I.jsxs)(Lb,{variant:`secondary`,children:[(0,I.jsx)(NT,{type:e.type}),tT[e.type]]})}),(0,I.jsx)(Q,{className:`text-sm text-muted-foreground`,children:(0,I.jsx)(fO,{gateway:e})}),(0,I.jsx)(Q,{className:`text-right`,children:(0,I.jsxs)($D,{label:e.name,children:[(0,I.jsxs)(eO,{onSelect:()=>o(e),children:[(0,I.jsx)(Pa,{}),`Update token`]}),(0,I.jsxs)(eO,{onSelect:()=>i(e),children:[(0,I.jsx)(ja,{}),`Rename`]}),(0,I.jsx)(Gb,{}),(0,I.jsxs)(eO,{destructive:!0,reason:lO(e),onSelect:()=>c(e),children:[(0,I.jsx)(Ga,{}),`Delete gateway`]})]})})]},e.id))})]})}),(0,I.jsx)(kO,{open:t,onOpenChange:n}),(0,I.jsx)(AO,{gateway:r,onClose:()=>i(null)}),(0,I.jsx)(jO,{gateway:a,onClose:()=>o(null)}),(0,I.jsx)(VD,{open:s!==null,onOpenChange:e=>{e||c(null)},title:`Delete gateway`,description:(0,I.jsxs)(`p`,{children:[`The stored token for`,` `,(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:s?.name}),` is destroyed. Nothing routes through it, so no traffic changes.`]}),confirmLabel:`Delete gateway`,destructive:!0,pending:l.isPending,onConfirm:()=>void p()})]})}function kO({open:e,onOpenChange:t,onCreated:n}){let r=yS(),i=gS(),[a,o]=(0,v.useState)(nT[0].value),s=nT.find(e=>e.value===a)??nT[0],[c,l]=(0,v.useState)(s.defaultName),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(``),[m,h]=(0,v.useState)(``),[g,_]=(0,v.useState)(null),y=!!(m&&(!s.needsCloudflareIds||u.trim()&&f.trim())),b=!!c.trim()&&y,x=()=>{o(nT[0].value),l(nT[0].defaultName),d(``),p(``),h(``),_(null),r.reset(),i.reset()},S=async()=>{if(y){_(null);try{let e=await i.mutateAsync(s.value===`cf_aig`?{type:`cf_aig`,accountId:u.trim(),gatewayId:f.trim(),token:m}:{type:`vercel`,token:m});_(wO(e))}catch(e){_({status:`failed`,message:oO(e,`The connection could not be checked`)})}finally{i.reset()}}},C=e=>{let t=nT.find(t=>t.value===e);t&&(o(e),l(t.defaultName),d(``),p(``),h(``),_(null))},w=()=>{x(),t(!1)},T=async()=>{if(b)try{let e=await r.mutateAsync(s.value===`cf_aig`?{type:`cf_aig`,name:c.trim(),accountId:u.trim(),gatewayId:f.trim(),token:m}:{type:`vercel`,name:c.trim(),token:m});x(),U.success(`Added ${e.gateway.name}`),n?.(e.gateway),t(!1)}catch(e){h(``),U.error(oO(e,`Could not add the gateway`))}};return(0,I.jsx)(nD,{open:e,onOpenChange:e=>e?t(!0):w(),title:`Add gateway`,submitLabel:`Add gateway`,pending:r.isPending,disabled:!b,onSubmit:()=>void T(),secondaryAction:(0,I.jsxs)(J,{type:`button`,variant:`secondary`,className:`sm:mr-auto`,disabled:!y||i.isPending,onClick:()=>void S(),children:[i.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Test gateway`]}),children:(0,I.jsxs)(`div`,{className:`space-y-4`,children:[nT.length>1?(0,I.jsx)(sw,{label:`Gateway type`,htmlFor:`gateway-type`,children:(0,I.jsxs)(zT,{value:a,onValueChange:e=>C(e),children:[(0,I.jsx)(VT,{id:`gateway-type`,className:`w-full`,children:(0,I.jsx)(BT,{})}),(0,I.jsx)(HT,{children:nT.map(e=>(0,I.jsx)(UT,{value:e.value,children:(0,I.jsx)(IT,{type:e.value})},e.value))})]})}):null,(0,I.jsx)(sw,{label:`Name`,htmlFor:`gateway-name`,children:(0,I.jsx)($,{id:`gateway-name`,...nO,value:c,onChange:e=>l(e.target.value)})}),s.needsCloudflareIds?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(sw,{label:`Cloudflare Account ID`,htmlFor:`gateway-account`,children:(0,I.jsx)($,{id:`gateway-account`,...nO,value:u,onChange:e=>{d(e.target.value),_(null)}})}),(0,I.jsx)(sw,{label:`Cloudflare Gateway ID`,htmlFor:`gateway-gateway`,children:(0,I.jsx)($,{id:`gateway-gateway`,...nO,value:f,onChange:e=>{p(e.target.value),_(null)}})})]}):null,(0,I.jsx)(sw,{label:`Gateway token`,htmlFor:`gateway-token`,hint:(0,I.jsx)(`a`,{className:`underline underline-offset-4`,href:s.tokenDocsUrl,target:`_blank`,rel:`noreferrer`,children:`How to create the token`}),children:(0,I.jsx)($,{id:`gateway-token`,...rO,value:m,onChange:e=>{h(e.target.value),_(null)}})}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:s.credentialNote}),g?(0,I.jsx)(TO,{outcome:g}):null]})})}function AO({gateway:e,onClose:t}){let n=bS(),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(null);e&&a!==e.id&&(o(e.id),i(e.name));let s=()=>{o(null),t()},c=async()=>{if(!(!e||!r.trim()))try{await n.mutateAsync({id:e.id,name:r.trim()}),U.success(`Renamed to ${r.trim()}`),s()}catch(e){U.error(oO(e,`Could not rename the gateway`))}};return(0,I.jsx)(KE,{open:e!==null,onOpenChange:e=>e?void 0:s(),children:(0,I.jsxs)(XE,{className:`sm:max-w-md`,children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{children:`Rename gateway`})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[(0,I.jsx)(tD,{children:`Only the display name changes. Nothing about the connection or the providers routed through it moves.`}),(0,I.jsx)(sw,{label:`Name`,htmlFor:`gateway-rename`,children:(0,I.jsx)($,{id:`gateway-rename`,...nO,value:r,onChange:e=>i(e.target.value)})})]}),(0,I.jsxs)($E,{children:[(0,I.jsx)(J,{variant:`outline`,onClick:s,children:`Cancel`}),(0,I.jsxs)(J,{disabled:!r.trim()||n.isPending,onClick:()=>void c(),children:[n.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Save name`]})]})]})})}function jO({gateway:e,onClose:t}){let n=xS(),r=gS(),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(null),c=()=>{a(``),s(null),n.reset(),r.reset(),t()},l=async()=>{if(!(!e||!i)){s(null);try{let t=await r.mutateAsync(e.type===`cf_aig`?{type:`cf_aig`,accountId:e.config.accountId,gatewayId:e.config.gatewayId,token:i}:{type:`vercel`,token:i});s(wO(t))}catch(e){s({status:`failed`,message:oO(e,`The connection could not be checked`)})}finally{r.reset()}}},u=async()=>{if(!(!e||!i))try{await n.mutateAsync({id:e.id,token:i}),a(``),s(null),n.reset(),U.success(`Updated the token for ${e.name}`),t()}catch(e){a(``),U.error(oO(e,`Could not update the gateway token`))}};return(0,I.jsx)(KE,{open:e!==null,onOpenChange:e=>e?void 0:c(),children:(0,I.jsxs)(XE,{className:`sm:max-w-md`,children:[(0,I.jsx)(ZE,{children:(0,I.jsxs)(eD,{children:[`Update the token for `,e?.name]})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[(0,I.jsxs)(tD,{children:[`One token authenticates every provider routed through this gateway, so all`,` `,e?.providerCount??0,` of them pick the new one up within a minute.`]}),(0,I.jsx)(sw,{label:`New gateway token`,htmlFor:`gateway-rotate-token`,children:(0,I.jsx)($,{id:`gateway-rotate-token`,...rO,value:i,onChange:e=>{a(e.target.value),s(null)}})}),o?(0,I.jsx)(TO,{outcome:o}):null]}),(0,I.jsxs)($E,{children:[(0,I.jsxs)(J,{type:`button`,variant:`secondary`,className:`sm:mr-auto`,disabled:!i||r.isPending,onClick:()=>void l(),children:[r.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Test token`]}),(0,I.jsx)(J,{variant:`outline`,onClick:c,children:`Cancel`}),(0,I.jsxs)(J,{disabled:!i||n.isPending,onClick:()=>void u(),children:[n.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Update token`]})]})]})})}function MO({provider:e,onClose:t}){let n=CS(),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(e?.baseUrl??``),s=()=>{i(``),n.reset(),t()},c=a.trim(),l=e&&c!==(e.baseUrl??``)?{baseUrl:c===``?null:c}:{},u=async()=>{if(!(!e||!r))try{await n.mutateAsync({id:e.id,body:{secret:r,...l}}),i(``),n.reset(),U.success(`Updated the key for ${e.name}`),t()}catch(e){i(``),U.error(oO(e,`Could not update the credential`))}};return(0,I.jsx)(KE,{open:e!==null,onOpenChange:e=>e?void 0:s(),children:(0,I.jsxs)(XE,{className:`sm:max-w-md`,children:[(0,I.jsx)(ZE,{children:(0,I.jsxs)(eD,{children:[`Update the key for `,e?.name]})}),(0,I.jsxs)(QE,{className:`space-y-4`,children:[(0,I.jsx)(tD,{children:`The new credential replaces the old one in place. Custom pricing is kept, and requests pick it up within a minute.`}),(0,I.jsx)(sw,{label:`New API key`,htmlFor:`rotate-secret`,children:(0,I.jsx)($,{id:`rotate-secret`,...rO,value:r,onChange:e=>i(e.target.value)})}),(0,I.jsx)(sw,{label:`Base URL`,htmlFor:`rotate-base-url`,hint:`Changing the origin needs the key above, because the stored key is never sent to a new origin. Leave empty to use the provider's own API.`,children:(0,I.jsx)($,{id:`rotate-base-url`,...nO,className:`font-mono`,value:a,placeholder:`https://my-vllm.example.com/v1/`,onChange:e=>o(e.target.value)})})]}),(0,I.jsxs)($E,{children:[(0,I.jsx)(J,{variant:`outline`,onClick:s,children:`Cancel`}),(0,I.jsxs)(J,{disabled:!r||n.isPending,onClick:()=>void u(),children:[n.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Update key`]})]})]})})}function NO({provider:e,onClose:t,readOnly:n}){let r=CS(),[i,a]=(0,v.useState)([]),[o,s]=(0,v.useState)(null);e&&o!==e.id&&(s(e.id),a(iO(e.pricing)));let c=(e,t)=>{a(n=>n.map((n,r)=>r===e?{...n,...t}:n))},l=async()=>{if(!e)return;let n=aO(i);if(`error`in n){U.error(n.error);return}try{await r.mutateAsync({id:e.id,body:{pricing:Object.keys(n.pricing).length?n.pricing:null}}),U.success(`Updated pricing for ${e.name}`),t()}catch(e){U.error(oO(e,`Could not save the pricing`))}};return(0,I.jsx)(KE,{open:e!==null,onOpenChange:e=>{e||(s(null),t())},children:(0,I.jsxs)(XE,{className:`sm:max-w-2xl`,children:[(0,I.jsx)(ZE,{children:(0,I.jsx)(eD,{children:`Custom model pricing`})}),(0,I.jsxs)(QE,{className:`space-y-3`,children:[(0,I.jsxs)(tD,{children:[`For models the built-in catalog does not cover, or prices it in a way you disagree with.`,e&&Qw(e.type)?` ${eT[e.type]??e.type} reports the cost of
76
76
  every request, so its models proxy with no price here; a price entered here is
77
77
  only used if a response ever comes back without one.`:` Requests for unpriced models are rejected until a price is set here.`,` `,`Enter $0 for a model that is genuinely free.`]}),i.length===0?(0,I.jsx)(uw,{children:`No custom prices for this provider.`}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`div`,{"aria-hidden":!0,className:`grid grid-cols-[2fr_1fr_1fr_auto] gap-2 text-xs text-muted-foreground`,children:[(0,I.jsx)(`span`,{children:`Model`}),(0,I.jsx)(`span`,{children:`Input $/1M`}),(0,I.jsx)(`span`,{children:`Output $/1M`}),(0,I.jsx)(`span`,{className:`w-9`})]}),i.map((e,t)=>(0,I.jsxs)(`div`,{className:`grid grid-cols-[2fr_1fr_1fr_auto] items-center gap-2`,children:[(0,I.jsx)($,{"aria-label":`Model ${t+1}`,value:e.model,placeholder:`gpt-brand-new`,disabled:n,onChange:e=>c(t,{model:e.target.value})}),(0,I.jsx)($,{"aria-label":`Input price ${t+1}`,inputMode:`decimal`,value:e.input,placeholder:`1.25`,disabled:n,onChange:e=>c(t,{input:e.target.value})}),(0,I.jsx)($,{"aria-label":`Output price ${t+1}`,inputMode:`decimal`,value:e.output,placeholder:`10`,disabled:n,onChange:e=>c(t,{output:e.target.value})}),(0,I.jsx)(J,{variant:`ghost`,size:`icon`,"aria-label":`Remove pricing row ${t+1}`,disabled:n,onClick:()=>a(e=>e.filter((e,n)=>n!==t)),children:(0,I.jsx)(Ga,{className:`size-4`})})]},t))]}),(0,I.jsxs)(J,{variant:`outline`,size:`sm`,disabled:n,onClick:()=>a(e=>[...e,{model:``,input:``,output:``}]),children:[(0,I.jsx)(Na,{className:`size-4`}),`Add model`]})]}),(0,I.jsxs)($E,{children:[(0,I.jsx)(J,{variant:`outline`,onClick:t,children:`Cancel`}),(0,I.jsxs)(iw,{disabled:r.isPending,onClick:()=>void l(),children:[r.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Save pricing`]})]})]})})}var PO=4e3;function FO(){let e=dt(),t=ht(),n=ui(),r=(0,v.useRef)(!1),i=(0,v.useRef)(void 0),a=Bx(e.search);(0,v.useEffect)(()=>()=>clearTimeout(i.current),[]),(0,v.useEffect)(()=>{if(!a||r.current)return;r.current=!0,U.success(`Payment complete`,{description:`Your new plan is being activated.`}),_x.capture(`subscription_started`,{plan:Nx(e.search)??`unknown`});let o=()=>void n.invalidateQueries({queryKey:eS.billingStatus});o(),i.current=setTimeout(o,PO),t(Vx(e.pathname,e.search),{replace:!0})},[a,n,t,e.pathname,e.search])}function IO(e,t,n){let r=e.resolved?.routing;if(!r)return null;for(let e of t){if(e.status!==`active`)continue;let t=r.providers?.[e.slug];if(r.providerMode===`selected`&&!t)continue;let i=t?.allowed_models?.length?t.allowed_models:[...Object.keys(e.pricing??{}),...Object.entries(n[e.type]??{}).filter(([,e])=>e.output!==void 0).map(([e])=>e)],a=e.type===`openai`?`v1/responses`:e.type===`anthropic`?`v1/messages`:e.type===`gemini`?`v1beta/models/${i[0]}:generateContent`:!e.providerGatewayId&&e.type===`groq`?`openai/v1/chat/completions`:!e.providerGatewayId&&e.type===`fireworks`?`inference/v1/chat/completions`:!e.providerGatewayId&&[`deepseek`,`bytedance`].includes(e.type)?`chat/completions`:`v1/chat/completions`,o=t?.allowed_paths?.length?t.allowed_paths:[a];for(let t of o){let n=typeof t==`string`?t:t.path;if(n.includes(`*`))continue;let r=typeof t!=`string`&&t.fixed_model?t.fixed_model:i[0];if(!r)continue;let a=[{role:`user`,content:`Say hello.`}],o=n.endsWith(`responses`)?{model:r,input:`Say hello.`}:n.endsWith(`chat/completions`)?{model:r,messages:a}:n.endsWith(`messages`)?{model:r,max_tokens:128,messages:a}:n.endsWith(`:generateContent`)?{contents:[{parts:[{text:`Say hello.`}]}]}:null;if(o)return{provider:e.slug,path:n,body:o,anthropic:n.endsWith(`messages`)}}}return null}var LO=`https://docs.appaigateway.com/quickstart/`,RO=15e3;function zO({index:e,title:t,description:n,done:r,completedLabel:i,action:a,status:o}){return(0,I.jsxs)(`li`,{className:`grid grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-x-3 gap-y-2 sm:gap-x-4`,children:[(0,I.jsx)(`span`,{"aria-hidden":!0,className:`grid size-6 shrink-0 place-items-center rounded-full bg-muted text-xs font-semibold tabular`,children:e}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-0.5`,children:[(0,I.jsxs)(`p`,{className:H(`text-sm font-medium`,r&&`text-muted-foreground`),children:[t,r?(0,I.jsx)(`span`,{className:`sr-only`,children:` — done`}):null]}),(0,I.jsx)(`p`,{className:`text-sm text-pretty text-muted-foreground`,children:n})]}),(0,I.jsx)(`div`,{className:`shrink-0 sm:pt-0.5`,children:r?(0,I.jsx)(`span`,{className:`flex size-8 items-center justify-center text-primary`,role:`img`,"aria-label":i,children:(0,I.jsx)(ra,{className:`size-5`,"aria-hidden":!0})}):a}),o?(0,I.jsx)(`div`,{className:`col-span-2 col-start-2 min-w-0`,children:o}):null]})}function BO(){return(0,I.jsxs)(`p`,{className:`flex items-center gap-2 pt-1 text-xs text-muted-foreground`,role:`status`,"aria-label":`Waiting for your first request`,children:[(0,I.jsxs)(`span`,{className:`relative flex size-2`,"aria-hidden":!0,children:[(0,I.jsx)(`span`,{className:`absolute inline-flex size-full animate-ping rounded-full bg-primary opacity-60`}),(0,I.jsx)(`span`,{className:`relative inline-flex size-2 rounded-full bg-primary`})]}),`Waiting…`]})}function VO({app:e}){let t=MS(e.id),n=dS(),r=qS(),i=e.authentication_type===`apple_app_attest`;if(t.isPending||n.isPending||r.isPending)return(0,I.jsx)(aw,{className:`mt-4 h-32`});let a=t.data&&n.data&&r.data?IO(t.data,n.data.providers,r.data.prices):null;if(!a)return(0,I.jsx)(`p`,{className:`mt-3 text-sm text-muted-foreground`,children:`No text request example is available for this app’s current provider and model settings.`});let{provider:o,path:s,body:c,anthropic:l}=a,u=e=>`'${e.replaceAll(`'`,`'\\''`)}'`,d=window.location.origin;return(0,I.jsx)(`div`,{className:`mt-4 min-w-0 overflow-hidden rounded-lg border bg-muted/40`,children:(0,I.jsx)(`pre`,{className:`overflow-x-auto p-4 text-xs leading-relaxed`,children:(0,I.jsx)(`code`,{children:i?`import Foundation
78
78
  import AppAIGateway
@@ -95,4 +95,4 @@ print(String(decoding: data, as: UTF8.self))`:`curl --fail-with-body ${u(`${d}/v
95
95
  -H 'Authorization: Bearer API_KEY' \\
96
96
  -H 'Content-Type: application/json' \\
97
97
  ${l?` -H 'anthropic-version: 2023-06-01' \\
98
- `:``} -d ${u(JSON.stringify(c))}`})})})}function HO({hasProvider:e,firstApp:t}){return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(iE,{className:`text-base`,children:`Start proxying in three steps`})}),(0,I.jsx)(oE,{className:`space-y-6`,children:(0,I.jsxs)(`ol`,{className:`space-y-5`,children:[(0,I.jsx)(zO,{index:1,title:`Add a provider key`,description:`Your own OpenAI, Anthropic or Gemini key. It is encrypted on arrival and never shown again.`,done:e,completedLabel:`Added`,action:(0,I.jsx)(DO,{label:`Add a provider`})}),(0,I.jsx)(zO,{index:2,title:`Create an app`,description:`One app per iOS app or backend. It decides who may call the gateway and what they may spend.`,done:!!t,completedLabel:`Created`,action:(0,I.jsx)(ZD,{trigger:(0,I.jsx)(iw,{size:`sm`,children:`Create an app`})})}),(0,I.jsx)(zO,{index:3,title:`Send your first request`,description:t?.authentication_type===`api_key`?(0,I.jsxs)(I.Fragment,{children:[`Replace `,(0,I.jsx)(`code`,{children:`API_KEY`}),` with `,(0,I.jsx)(Pn,{className:`text-primary-ink underline underline-offset-4`,to:`/apps/${encodeURIComponent(t.id)}/auth/identity`,children:`your API key`}),`.`]}):`Run this example in your iOS app using the AppAIGateway Swift package.`,done:!1,completedLabel:`Received`,status:e&&t?(0,I.jsx)(VO,{app:t}):void 0,action:e&&t?(0,I.jsx)(BO,{}):(0,I.jsx)(J,{asChild:!0,size:`sm`,variant:`outline`,children:(0,I.jsx)(`a`,{href:LO,target:`_blank`,rel:`noopener`,children:`Quickstart`})})})]})})]})}function UO(){let[e,t]=(0,v.useState)(yC());FO();let n=(0,v.useRef)(!1),r=jS(e,n.current?RO:void 0),i=dS(),a=r.isSuccess&&!r.data.has_proxied_requests;n.current=a;let{organization:o}=sx(),s=o?.id,c=r.data?.has_proxied_requests;(0,v.useEffect)(()=>{},[s,c]);let l=(r.data?.apps.length??0)>0,u=(r.data?.apps??[]).reduce((e,t)=>({requests:e.requests+t.usage.requests,tokens:e.tokens+vC(t.usage),cost:e.cost+t.usage.cost_usd,users:e.users+t.users.total,errors:e.errors+t.usage.errors}),{requests:0,tokens:0,cost:0,users:0,errors:0});return(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsx)(cw,{title:`Apps`,action:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(qT,{value:e,onChange:t}),(0,I.jsx)(ZD,{})]})}),r.isError?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`Could not load apps`}),(0,I.jsx)(ks,{children:r.error instanceof Error?r.error.message:`Unknown error`})]}):null,(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,I.jsx)(dE,{label:`Spend`,value:r.isPending?(0,I.jsx)(aw,{className:`h-6 w-20`}):dC(u.cost),detail:`month to date`}),(0,I.jsx)(dE,{label:`Users`,value:r.isPending?(0,I.jsx)(aw,{className:`h-6 w-12`}):cC(u.users),detail:`${r.data?.apps.length??0} apps`}),(0,I.jsx)(dE,{label:`Requests`,value:r.isPending?(0,I.jsx)(aw,{className:`h-6 w-16`}):cC(u.requests),detail:u.errors>0?`${cC(u.errors)} provider errors`:`month to date`}),(0,I.jsx)(dE,{label:`Tokens`,value:r.isPending?(0,I.jsx)(aw,{className:`h-6 w-16`}):lC(u.tokens),detail:`all buckets`})]}),r.isPending||l?(0,I.jsx)(nE,{className:`overflow-hidden py-0`,children:(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{className:`hover:bg-transparent`,children:[(0,I.jsx)(Z,{children:`App`}),(0,I.jsx)(Z,{className:`text-right`,children:`Budget`}),(0,I.jsx)(Z,{className:`text-right`,children:`Users`}),(0,I.jsx)(Z,{className:`text-right`,children:`Requests`}),(0,I.jsx)(Z,{className:`text-right`,children:`Tokens`}),(0,I.jsx)(Z,{className:`w-8`})]})}),(0,I.jsx)(lE,{children:r.isPending?[0,1,2].map(e=>(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:6,children:(0,I.jsx)(aw,{className:`h-8 w-full`})})},e)):r.data?.apps.map(e=>(0,I.jsxs)(uE,{className:`group relative h-13`,children:[(0,I.jsx)(Q,{children:(0,I.jsx)(Pn,{to:`/apps/${e.id}/overview`,className:`block after:absolute after:inset-0 after:content-['']`,children:(0,I.jsxs)(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.name,(0,I.jsx)(YS,{status:e.status})]})})}),(0,I.jsxs)(Q,{className:`tabular text-right`,children:[dC(e.usage.cost_usd),(0,I.jsxs)(`span`,{className:`text-muted-foreground`,children:[` / `,e.monthly_budget_usd===null?(0,I.jsx)(`span`,{title:`No monthly budget`,children:`∞`}):dC(e.monthly_budget_usd)]})]}),(0,I.jsxs)(Q,{className:`tabular text-right`,children:[cC(e.users.total),e.users.blocked>0?(0,I.jsxs)(`span`,{className:`block text-[11px] text-destructive`,children:[e.users.blocked,` blocked`]}):null]}),(0,I.jsxs)(Q,{className:`tabular text-right`,children:[cC(e.usage.requests),e.usage.errors>0?(0,I.jsxs)(`span`,{className:`block text-[11px] text-amber-600 dark:text-amber-400`,children:[e.usage.errors,` errors`]}):null]}),(0,I.jsx)(Q,{className:`tabular text-right`,children:lC(vC(e.usage))}),(0,I.jsx)(Q,{children:(0,I.jsx)(aa,{className:`size-4 text-muted-foreground transition-transform group-hover:translate-x-0.5`})})]},e.id))})]})}):null,a?(0,I.jsx)(HO,{hasProvider:(i.data?.providers.length??0)>0,firstApp:r.data?.apps.reduce((e,t)=>!e||t.created_at<e.created_at?t:e,void 0)}):null]})}function WO({className:e,orientation:t=`horizontal`,...n}){return(0,I.jsx)(zy,{"data-slot":`tabs`,"data-orientation":t,orientation:t,className:H(`group/tabs flex gap-2 data-[orientation=horizontal]:flex-col`,e),...n})}var GO=eo(`group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-[orientation=horizontal]/tabs:h-9 group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col data-[variant=line]:rounded-none`,{variants:{variant:{default:`bg-muted`,line:`gap-1 bg-transparent`}},defaultVariants:{variant:`default`}});function KO({className:e,variant:t=`default`,...n}){return(0,I.jsx)(By,{"data-slot":`tabs-list`,"data-variant":t,className:H(GO({variant:t}),e),...n})}function qO({className:e,...t}){return(0,I.jsx)(Vy,{"data-slot":`tabs-trigger`,className:H(`relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-[orientation=vertical]/tabs:w-full group-data-[orientation=vertical]/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 group-data-[variant=default]/tabs-list:data-[state=active]:shadow-sm group-data-[variant=line]/tabs-list:data-[state=active]:shadow-none dark:text-muted-foreground dark:hover:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,`group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:border-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent`,`data-[state=active]:bg-background data-[state=active]:text-foreground dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 dark:data-[state=active]:text-foreground`,`after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-[orientation=horizontal]/tabs:after:inset-x-0 group-data-[orientation=horizontal]/tabs:after:bottom-[-5px] group-data-[orientation=horizontal]/tabs:after:h-0.5 group-data-[orientation=vertical]/tabs:after:inset-y-0 group-data-[orientation=vertical]/tabs:after:-right-1 group-data-[orientation=vertical]/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-[state=active]:after:opacity-100`,e),...t})}function JO(){let{capabilities:e,organization:t}=sx(),[n,r]=(0,v.useState)(`month`),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(null),c=TS(e.billing),l=ES(e.billing),u=DS(),d=OS(),f=kS(),p=AS(),m=c.data?.access,h=c.data?.quota,g=l.data?.plans??[],_=async e=>{try{let{url:t}=await u.mutateAsync({planKey:e.planKey,billingPeriod:n});window.location.assign(t)}catch(e){U.error(e instanceof Error?e.message:`Could not start checkout`)}},y=async()=>{if(o)try{let e=await d.mutateAsync({planKey:o.planKey,billingPeriod:TC(m)?.billingPeriod??n});if(s(null),e.requiredActionUrl){window.location.assign(e.requiredActionUrl);return}U.success(`Moved to ${o.name}`)}catch(e){U.error(e instanceof Error?e.message:`Could not change the plan`)}},b=(e,t)=>{if(t.intent===`checkout`)return void _(e);if(t.intent===`change`)return s(e);if(t.intent===`cancel`)return a(!0)},x=async()=>{try{await f.mutateAsync(),U.success(`Subscription canceled`),a(!1)}catch(e){U.error(e instanceof Error?e.message:`Could not cancel the subscription`)}},S=async()=>{let e=TC(m);if(e)try{let t=await p.mutateAsync({planKey:e.planKey,billingPeriod:e.billingPeriod??n});if(t.requiredActionUrl){window.location.assign(t.requiredActionUrl);return}U.success(`Subscription resumed`)}catch(e){U.error(e instanceof Error?e.message:`Could not resume the subscription`)}},C=AC(t)??OC(m);return(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsx)(cw,{title:`Billing`}),c.isError?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`Could not load billing status`}),(0,I.jsx)(ks,{children:c.error instanceof Error?c.error.message:`Unknown error`})]}):null,C?(0,I.jsxs)(Ds,{variant:C.tone===`destructive`?`destructive`:`default`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:C.title}),(0,I.jsx)(ks,{children:C.description})]}):null,(0,I.jsx)(YO,{access:m,quota:h,pending:c.isPending,cancelPending:f.isPending,resumePending:p.isPending,onCancel:()=>a(!0),onResume:()=>void S()}),(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,I.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Plans`}),g.some(e=>IC(e,`year`))?(0,I.jsx)(WO,{value:n,onValueChange:e=>r(e),children:(0,I.jsxs)(KO,{children:[(0,I.jsx)(qO,{value:`month`,children:`Monthly`}),(0,I.jsx)(qO,{value:`year`,children:`Yearly`})]})}):null]}),l.isPending?(0,I.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:[0,1,2].map(e=>(0,I.jsx)(aw,{className:`h-52 w-full`},e))}):(0,I.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:g.map(e=>{let t=UC(e,g,m);return(0,I.jsx)(QO,{plan:e,period:n,action:t,pending:u.isPending||d.isPending,onAct:()=>b(e,t)},e.planKey)})}),(0,I.jsx)(VD,{open:o!==null,onOpenChange:e=>s(e?o:null),title:`Move to ${o?.name??``}`,description:(0,I.jsx)(`p`,{children:`Your subscription changes to this plan and its allowance applies from the change. The billing provider settles the difference, charging an upgrade right away and putting a downgrade on your next invoice.`}),confirmLabel:`Change plan`,pending:d.isPending,onConfirm:()=>void y()}),(0,I.jsx)(VD,{open:i,onOpenChange:a,title:`Cancel subscription`,description:(0,I.jsx)(`p`,{children:`Gateway traffic keeps working until the end of the current period, then stops until you resubscribe.`}),confirmLabel:`Cancel subscription`,destructive:!0,pending:f.isPending,onConfirm:()=>void x()})]})}function YO({access:e,quota:t,pending:n,cancelPending:r,resumePending:i,onCancel:a,onResume:o}){let s=wC(e),c=TC(e),l=c?LC(c):null,{organization:u}=sx(),d=jC(t,u);return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsxs)(iE,{className:`flex items-center gap-1.5 text-sm`,children:[`Current plan:`,n?(0,I.jsx)(aw,{className:`h-4 w-24`}):(0,I.jsx)(`span`,{children:s?.planName??`No plan`})]})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[n?(0,I.jsx)(aw,{className:`h-6 w-40`}):null,d&&!n?(0,I.jsx)(XO,{meter:d,timeline:l}):null,!d&&!n&&l?(0,I.jsx)(ZO,{timeline:l}):null,!n&&c?(0,I.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:BC(c)?(0,I.jsxs)(iw,{variant:`outline`,size:`sm`,disabled:i,onClick:o,children:[i?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Resume subscription`]}):zC(c)?(0,I.jsx)(iw,{variant:`outline`,size:`sm`,disabled:r,onClick:a,children:`Cancel subscription`}):null}):null]})]})}function XO({meter:e,timeline:t}){return(0,I.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,I.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`Requests this period`}),(0,I.jsx)(`span`,{className:`tabular text-sm font-medium`,children:e.label})]}),(0,I.jsx)(qb,{meter:e}),t?(0,I.jsx)(ZO,{timeline:t}):null]})}function ZO({timeline:e}){return(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[e.label,` `,(0,I.jsx)(`span`,{className:`tabular text-foreground`,children:e.value})]})}function QO({plan:e,period:t,action:n,pending:r,onAct:i}){let a=IC(e,t),o=e.prices.length===0,s=n.intent===`current`;return(0,I.jsxs)(nE,{className:H(`h-full`,s&&`border-primary`),children:[(0,I.jsxs)(rE,{children:[(0,I.jsx)(iE,{className:`text-sm`,children:e.name}),(0,I.jsx)(aE,{children:e.description})]}),(0,I.jsxs)(oE,{className:`flex flex-1 flex-col gap-4`,children:[(0,I.jsx)(`p`,{className:`tabular text-2xl font-semibold`,children:o?`Free`:a?FC(a):`—`}),e.trialDays>0&&!s?(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[e.trialDays,`-day free trial`]}):null,e.features.length>0?(0,I.jsx)(`ul`,{className:`space-y-1.5`,children:e.features.map(e=>(0,I.jsxs)(`li`,{className:`flex items-start gap-2 text-sm text-muted-foreground`,children:[(0,I.jsx)(ra,{className:`mt-0.5 size-3.5 shrink-0 text-foreground`}),e]},e))}):null,(0,I.jsx)(`div`,{className:`mt-auto pt-2`,children:s?(0,I.jsx)(J,{className:`w-full`,variant:`outline`,disabled:!0,children:n.label}):(0,I.jsxs)(iw,{className:`w-full`,wrapperClassName:`w-full`,variant:n.variant,disabled:r||!o&&!a,...n.reason?{reason:n.reason}:{},onClick:i,children:[r?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,n.label]})})]})]})}var $O=`/billing`;function ek(){let e=dt(),{capabilities:t,billing:n,canManage:r}=sx(),i=ES(t.billing),{mutateAsync:a}=DS(),o=(0,v.useRef)(!1),[s,c]=(0,v.useState)(null),l=Nx(e.search),u=i.data?.plans??[],d=l===null?void 0:u.find(e=>e.planKey===l),f=wC(n),p=!t.billing||l===`free`?Cx:l===null||!r||f?.planKey===l?$O:null,m=p===null&&i.isSuccess&&!d,h=p===null&&d!==void 0&&s===null;return(0,v.useEffect)(()=>{if(!h||o.current||d===void 0)return;o.current=!0;let e=IC(d,`month`)?`month`:`year`;a({planKey:d.planKey,billingPeriod:e}).then(({url:e})=>window.location.assign(e)).catch(e=>{c(e instanceof Error?e.message:`Could not start checkout`)})},[h,d,a]),p===null?m?(0,I.jsx)(Vt,{to:$O,replace:!0}):s===null?(0,I.jsxs)(`div`,{className:`flex min-h-60 flex-col items-center justify-center gap-3 py-10 text-center`,children:[(0,I.jsx)(wa,{className:`size-5 animate-spin text-muted-foreground`}),(0,I.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:d?`Redirecting you to checkout for ${d.name}…`:`Preparing your checkout…`})]}):(0,I.jsx)(`div`,{className:`mx-auto max-w-lg py-10`,children:(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`Could not start checkout`}),(0,I.jsxs)(ks,{className:`flex flex-wrap items-center gap-3`,children:[(0,I.jsx)(`span`,{children:s}),(0,I.jsx)(J,{asChild:!0,size:`sm`,variant:`outline`,children:(0,I.jsx)(Pn,{to:$O,children:`Go to plans`})})]})]})}):(0,I.jsx)(Vt,{to:p,replace:!0})}var tk={INVALID_EMAIL_OR_PASSWORD:`That email and password combination is not correct.`,INVALID_EMAIL:`Enter a valid email address.`,INVALID_PASSWORD:`That password is not correct.`,USER_ALREADY_EXISTS:`An account with that email already exists.`,USER_NOT_FOUND:`No account exists for that email.`,PASSWORD_TOO_SHORT:`Choose a longer password.`,PASSWORD_TOO_LONG:`Choose a shorter password.`,EMAIL_NOT_VERIFIED:`Verify your email address before signing in.`,CREDENTIAL_ACCOUNT_NOT_FOUND:`This account signs in with Google.`,SESSION_EXPIRED:`Your session expired. Sign in again.`,registration_disabled:`Public registration is disabled for this deployment.`};function nk(e){return e instanceof ux&&e.code===`registration_disabled`}function rk(e,t=`Something went wrong. Try again.`){return e instanceof ux?tk[e.code]||(e.message&&!e.message.startsWith(`Request failed with status`)?e.message:t):e instanceof Error&&e.message?e.message:t}function ik({children:e}){return(0,I.jsxs)(`div`,{className:`flex min-h-dvh flex-col items-center justify-center gap-6 px-4 py-10`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-1.5 text-lg font-semibold tracking-tight`,children:[(0,I.jsx)(`span`,{children:`App`}),(0,I.jsx)($b,{size:26}),(0,I.jsx)(`span`,{children:`Gateway`})]}),e]})}function ak({label:e=`Continue with Google`,returnPath:t,onStart:n}){let[r,i]=(0,v.useState)(!1),a=async()=>{i(!0);try{await(n?n():Zx(t))}catch(e){i(!1),U.error(rk(e,`Could not start Google sign-in`))}};return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(J,{type:`button`,variant:`outline`,className:`w-full`,disabled:r,onClick:()=>void a(),children:[r?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):(0,I.jsx)(ok,{}),e]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,I.jsx)(`span`,{className:`h-px flex-1 bg-border`}),(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`or`}),(0,I.jsx)(`span`,{className:`h-px flex-1 bg-border`})]})]})}function ok(){return(0,I.jsxs)(`svg`,{className:`size-4`,viewBox:`0 0 24 24`,"aria-hidden":`true`,children:[(0,I.jsx)(`path`,{fill:`#4285F4`,d:`M23.52 12.27c0-.85-.08-1.67-.22-2.45H12v4.64h6.46a5.52 5.52 0 0 1-2.4 3.62v3h3.88c2.27-2.09 3.58-5.17 3.58-8.81Z`}),(0,I.jsx)(`path`,{fill:`#34A853`,d:`M12 24c3.24 0 5.96-1.08 7.94-2.92l-3.88-3c-1.08.72-2.45 1.15-4.06 1.15-3.13 0-5.78-2.11-6.73-4.95H1.26v3.09A12 12 0 0 0 12 24Z`}),(0,I.jsx)(`path`,{fill:`#FBBC05`,d:`M5.27 14.28a7.2 7.2 0 0 1 0-4.56v-3.1H1.26a12 12 0 0 0 0 10.76l4.01-3.1Z`}),(0,I.jsx)(`path`,{fill:`#EA4335`,d:`M12 4.77c1.76 0 3.35.61 4.6 1.8l3.44-3.44C17.95 1.19 15.24 0 12 0A12 12 0 0 0 1.26 6.62l4.01 3.1C6.22 6.88 8.87 4.77 12 4.77Z`})]})}function sk(e){return`app-ai-gateway:cli-approve:${e}`}function ck(e){let t=null;try{t=JSON.parse(sessionStorage.getItem(e)??`null`)}catch{t=null}if(!t||typeof t.token!=`string`)return null;if(!(t.expiresAt>Date.now())){try{sessionStorage.removeItem(e)}catch{}return null}return t}function lk(e,t){try{sessionStorage.setItem(e,JSON.stringify(t))}catch{}}function uk(e){try{sessionStorage.removeItem(e)}catch{}}function dk(e){if(e===`claim`)return`Claim your account`;let[t,n]=e.split(`.`),r=t===`provider-gateway`?`provider gateway`:`provider`;return n===`add`?`Add a ${r}`:n===`rotate-key`?`Rotate the ${r} credential`:n===`update`?`Update the ${r}`:`Approve a ${r} change`}function fk(e){return e.length>18?`${e.slice(0,10)}…${e.slice(-6)}`:e}function pk(e){return e.kind!==`claim`&&!(e.kind===`provider.add`&&e.payload.providerGatewayId)}function mk(){let{id:e=``}=_t(),t=dt(),n=ht(),r=sk(t.pathname),[i]=(0,v.useState)(()=>t.hash.replace(/^#/,``)||ck(r)?.token||``);(0,v.useEffect)(()=>{t.hash&&n(`${t.pathname}${t.search}`,{replace:!0})},[t.hash,t.pathname,t.search,n]);let a=Ti({queryKey:[`cli-approve`,e],queryFn:()=>hx(X.cliBrowserDetails,[e],{submissionToken:i}),enabled:!!i,retry:!1,staleTime:1/0}),o=a.data;(0,v.useEffect)(()=>{o&&lk(r,{token:i,expiresAt:Date.parse(o.expiresAt)})},[o,r,i]);let[s,c]=(0,v.useState)(!1),l=Ei({mutationFn:t=>hx(X.cliBrowserSubmit,[e],{submissionToken:i,...t}),onSuccess:()=>{uk(r),c(!0)}});if(!i)return(0,I.jsx)(hk,{children:(0,I.jsxs)(Ds,{variant:`destructive`,role:`alert`,children:[(0,I.jsx)(Os,{children:`This link is missing its proof`}),(0,I.jsx)(ks,{children:`Open the full link your CLI printed, or rerun the command to get a new one.`})]})});if(a.isPending)return(0,I.jsx)(hk,{children:(0,I.jsx)(`div`,{className:`flex justify-center py-6`,children:(0,I.jsx)(wa,{className:`size-5 animate-spin text-muted-foreground`})})});if(a.isError||!o)return(0,I.jsx)(hk,{children:(0,I.jsxs)(Ds,{variant:`destructive`,role:`alert`,children:[(0,I.jsx)(Os,{children:`This request can no longer be approved`}),(0,I.jsxs)(ks,{children:[rk(a.error,`The link has expired or was already used.`),` Rerun the command in your CLI to start a new one.`]})]})});if(s)return(0,I.jsx)(hk,{title:dk(o.kind),children:(0,I.jsxs)(Ds,{role:`status`,children:[(0,I.jsx)(la,{className:`size-4`}),(0,I.jsx)(Os,{children:`Approved`}),(0,I.jsx)(ks,{children:`Return to your CLI.`})]})});let u=o.kind===`claim`;return(0,I.jsxs)(hk,{title:dk(o.kind),children:[(0,I.jsx)(gk,{details:o}),u&&!o.signedIn?(0,I.jsx)(vk,{id:e,token:i,googleEnabled:o.googleEnabled,onDone:()=>void a.refetch()}):(0,I.jsx)(yk,{details:o,pending:l.isPending,error:l.isError?rk(l.error,`Approval failed`):null,onSubmit:e=>l.mutate(e)}),(0,I.jsx)(_k,{details:o,id:e})]})}function hk({title:e,children:t}){return(0,I.jsx)(ik,{children:(0,I.jsxs)(nE,{className:`w-full max-w-sm`,children:[(0,I.jsx)(rE,{className:`grid-rows-[auto] gap-0`,children:(0,I.jsx)(iE,{children:e??`Approve a CLI request`})}),(0,I.jsx)(oE,{className:`space-y-4`,children:t})]})})}function gk({details:e}){let t=e.kind===`claim`||Object.keys(e.payload).length===0?null:JSON.stringify(e.payload,null,2);return(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsxs)(`div`,{className:`rounded-md border bg-muted/40 px-3 py-2`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:e.account.name}),(0,I.jsx)(`p`,{className:`font-mono text-xs text-muted-foreground`,children:fk(e.account.id)})]}),t?(0,I.jsx)(`pre`,{className:`max-h-56 overflow-auto rounded-md border bg-muted/40 px-3 py-2 font-mono text-xs whitespace-pre-wrap`,children:t}):null]})}function _k({details:e,id:t}){return(0,I.jsxs)(`div`,{className:`space-y-1 text-xs text-muted-foreground`,children:[(0,I.jsx)(`p`,{className:`font-mono break-all`,children:t}),(0,I.jsxs)(`p`,{children:[`Expires `,new Date(e.expiresAt).toLocaleString(),`.`]}),(0,I.jsx)(`p`,{children:`This page never displays management credentials. Provider credentials are submitted directly to your gateway.`})]})}function vk({id:e,token:t,googleEnabled:n,onDone:r}){let[i,a]=(0,v.useState)(!1),o=rS(),s=Ei({mutationFn:n=>hx(X.cliBrowserRegister,[e],{submissionToken:t,...n})}),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(``),m=i?s:o,h=async e=>{e.preventDefault();try{i?await s.mutateAsync({name:c.trim(),email:u.trim(),password:f}):await o.mutateAsync({email:u.trim(),password:f}),p(``),r()}catch{}};return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Sign in to confirm who is claiming this account.`}),n?(0,I.jsx)(ak,{label:i?`Sign up with Google`:`Continue with Google`,onStart:async()=>{let n=await hx(X.cliBrowserGoogle,[e],{submissionToken:t});if(!n.url)throw Error(`Google sign-in is unavailable right now.`);window.location.assign(n.url)}}):null,(0,I.jsxs)(`form`,{onSubmit:e=>void h(e),className:`space-y-4`,children:[i?(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`claim-name`,children:`Name`}),(0,I.jsx)($,{id:`claim-name`,value:c,required:!0,autoComplete:`name`,placeholder:`Ada Lovelace`,onChange:e=>l(e.target.value)})]}):null,(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`claim-email`,children:`Email`}),(0,I.jsx)($,{id:`claim-email`,type:`email`,value:u,required:!0,autoComplete:`username`,placeholder:`you@example.com`,onChange:e=>d(e.target.value)})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`claim-password`,children:`Password`}),(0,I.jsx)($,{id:`claim-password`,type:`password`,value:f,required:!0,autoComplete:i?`new-password`:`current-password`,placeholder:`••••••••••••`,onChange:e=>p(e.target.value)})]}),m.isError?(0,I.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:rk(m.error,i?`Sign-up failed`:`Sign-in failed`)}):null,(0,I.jsxs)(J,{type:`submit`,className:`w-full`,disabled:m.isPending,children:[m.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,i?`Create account`:`Sign in`]})]}),(0,I.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[i?`Already have an account? `:`No account? `,(0,I.jsx)(`button`,{type:`button`,className:`text-primary-ink underline underline-offset-4`,onClick:()=>a(e=>!e),children:i?`Sign in`:`Create one`})]})]})}function yk({details:e,pending:t,error:n,onSubmit:r}){let i=e.kind===`claim`,a=pk(e),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(!0);return(0,I.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),!(!c||a&&!o)&&(r({approve:!0,...i?{allowServiceAccess:u}:{},...a?{secret:o}:{}}),s(``))},className:`space-y-4`,children:[a?(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`approve-secret`,children:`Provider credential`}),(0,I.jsx)($,{id:`approve-secret`,type:`password`,value:o,required:!0,autoComplete:`off`,spellCheck:!1,placeholder:`••••••••••••`,onChange:e=>s(e.target.value)})]}):null,(0,I.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,I.jsx)(gE,{id:`approve-confirm`,checked:c,onCheckedChange:e=>l(e===!0)}),(0,I.jsx)(ow,{htmlFor:`approve-confirm`,className:`text-sm leading-snug font-normal`,children:`I approve this action for the account shown above`})]}),i?(0,I.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,I.jsx)(gE,{id:`approve-service-access`,checked:u,onCheckedChange:e=>d(e===!0)}),(0,I.jsx)(ow,{htmlFor:`approve-service-access`,className:`text-sm leading-snug font-normal`,children:`Keep this service identity and its role-based management access`})]}):null,n?(0,I.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:n}):null,(0,I.jsxs)(J,{type:`submit`,className:`w-full`,disabled:t||!c||a&&!o,children:[t?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Approve request`]})]})}function bk(){let e=ht(),t=dt(),n=tS(),r=rS(),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(``),c=Gx(t.search),l=Ix(t.search),u=Nx(t.search),d=async t=>{if(t.preventDefault(),!(!i.trim()||!o))try{await r.mutateAsync({email:i.trim(),password:o}),await e(l,{replace:!0})}catch{}};return(0,I.jsx)(ik,{children:(0,I.jsxs)(nE,{className:`w-full max-w-sm`,children:[(0,I.jsx)(rE,{className:`grid-rows-[auto] gap-0`,children:(0,I.jsx)(iE,{children:`Sign in`})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[c?(0,I.jsxs)(Ds,{variant:c.tone,role:`alert`,children:[(0,I.jsx)(Os,{children:c.title}),(0,I.jsx)(ks,{children:c.description})]}):null,n.data?.googleAuth?(0,I.jsx)(ak,{returnPath:l}):null,(0,I.jsxs)(`form`,{onSubmit:e=>void d(e),className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`email`,children:`Email`}),(0,I.jsx)($,{id:`email`,type:`email`,value:i,autoFocus:!0,required:!0,autoComplete:`username`,placeholder:`operator@example.com`,onChange:e=>a(e.target.value)})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`password`,children:`Password`}),(0,I.jsx)($,{id:`password`,type:`password`,value:o,required:!0,autoComplete:`current-password`,placeholder:`••••••••••••`,onChange:e=>s(e.target.value)})]}),r.isError?(0,I.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:rk(r.error,`Sign-in failed`)}):null,(0,I.jsxs)(J,{type:`submit`,className:`w-full`,disabled:r.isPending||!i.trim()||!o,children:[r.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Sign in`]})]}),n.data?.registrationOpen?(0,I.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[`No account?`,` `,(0,I.jsx)(Pn,{to:Fx(Sx,u),className:`text-primary-ink underline underline-offset-4`,children:`Create one`})]}):null]})]})})}function xk(){let e=cS(),t=lS(),n=uS(),[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(null),d=async()=>{if(a.trim())try{let e=await t.mutateAsync(a.trim());i(!1),o(``),c(e.key)}catch(e){U.error(e instanceof Error?e.message:`Could not create the key`)}},f=async()=>{if(l)try{await n.mutateAsync(l.id),U.success(`Management key revoked`),u(null)}catch(e){U.error(e instanceof Error?e.message:`Could not revoke the key`)}},p=e.data?.keys??[];return(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsx)(cw,{title:`Management keys`,description:`Management keys let you manage everything in this console through the API — from CI, scripts, or an AI agent.`,action:(0,I.jsxs)(iw,{size:`sm`,onClick:()=>{o(``),i(!0)},children:[(0,I.jsx)(Na,{className:`size-4`}),`New key`]})}),e.isError?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`Could not load management keys`}),(0,I.jsx)(ks,{children:e.error instanceof Error?e.error.message:`Unknown error`})]}):null,(0,I.jsx)(nE,{className:`overflow-hidden py-0`,children:(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{children:[(0,I.jsx)(Z,{children:`Name`}),(0,I.jsx)(Z,{children:`Key`}),(0,I.jsx)(Z,{children:`Created`}),(0,I.jsx)(Z,{children:`Status`}),(0,I.jsx)(Z,{className:`text-right`,children:`Actions`})]})}),(0,I.jsx)(lE,{children:e.isPending?[0,1,2].map(e=>(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:5,children:(0,I.jsx)(aw,{className:`h-5 w-full`})})},e)):p.length===0?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:5,className:`py-10 text-center text-sm text-muted-foreground`,children:`No management keys yet.`})}):p.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{className:`font-medium`,children:e.name}),(0,I.jsx)(Q,{className:`font-mono text-xs text-muted-foreground`,children:e.tokenHint===null?`—`:`…${e.tokenHint}`}),(0,I.jsx)(Q,{className:`tabular text-muted-foreground`,children:mC(e.createdAt)}),(0,I.jsx)(Q,{children:e.revokedAt?(0,I.jsxs)(`span`,{className:`text-muted-foreground`,children:[`Revoked `,mC(e.revokedAt)]}):e.enabled?(0,I.jsx)(`span`,{className:`text-foreground`,children:`Active`}):(0,I.jsx)(`span`,{className:`text-muted-foreground`,children:`Not yet active`})}),(0,I.jsx)(Q,{className:`text-right`,children:e.revokedAt?null:(0,I.jsx)($D,{label:e.name,children:(0,I.jsxs)(eO,{destructive:!0,onSelect:()=>u(e),children:[(0,I.jsx)($i,{}),`Revoke key`]})})})]},e.id))})]})}),(0,I.jsx)(nD,{open:r,onOpenChange:i,title:`Create a management key`,submitLabel:`Create key`,pending:t.isPending,disabled:!a.trim(),onSubmit:()=>void d(),children:(0,I.jsx)(sw,{label:`Key name`,htmlFor:`management-key-name`,hint:`Name it so you can tell keys apart in the list.`,children:(0,I.jsx)($,{id:`management-key-name`,value:a,placeholder:`CI deploy`,maxLength:100,autoFocus:!0,autoComplete:`off`,onChange:e=>o(e.target.value)})})}),(0,I.jsx)(rD,{open:s!==null,title:`Copy your new key now`,description:(0,I.jsxs)(I.Fragment,{children:[`This is the only time the plaintext for`,` `,(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:s?.name}),` is available — you will not see it again. The gateway stores only a hash.`]}),label:`Management key`,secret:s?.plaintext??``,footnote:`Store it in your secret manager. It acts with full authority over every app and provider key here.`,onAcknowledge:()=>{c(null),t.reset()}}),(0,I.jsx)(VD,{open:l!==null,onOpenChange:e=>{e||u(null)},title:`Revoke management key`,description:(0,I.jsxs)(`p`,{children:[`Anything using `,(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:l?.name}),` `,`will immediately lose access. This cannot be undone.`]}),confirmLabel:`Revoke key`,destructive:!0,pending:n.isPending,onConfirm:()=>void f()})]})}var Sk=8,Ck=[{slug:`account`,label:`Account`,Component:Ek},{slug:`password`,label:`Change password`,Component:Ok}],wk=Ck[0].slug;function Tk(){let{section:e=wk}=_t(),t=Ck.find(t=>t.slug===e);return t?(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsx)(cw,{title:`Settings`}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-6 lg:flex-row`,children:[(0,I.jsx)(`nav`,{"aria-label":`Settings sections`,className:`flex gap-1 overflow-x-auto lg:w-56 lg:shrink-0 lg:flex-col`,children:Ck.map(e=>{let n=e.slug===t.slug;return(0,I.jsx)(Pn,{to:`/settings/${e.slug}`,"aria-current":n?`page`:void 0,className:H(`flex h-9 shrink-0 items-center rounded-lg px-3 text-sm font-medium transition-colors`,`outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50`,n?`bg-accent text-accent-foreground`:`text-muted-foreground hover:bg-accent/60 hover:text-accent-foreground`),children:e.label},e.slug)})}),(0,I.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,I.jsx)(t.Component,{})})]})]}):(0,I.jsx)(Vt,{to:`/settings/${wk}`,replace:!0})}function Ek(){let{session:e}=sx(),t=e.user;return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(iE,{className:`text-sm`,children:`Account`})}),(0,I.jsxs)(oE,{className:`space-y-3 text-sm`,children:[(0,I.jsx)(Dk,{label:`Name`,value:t?.name||`—`}),(0,I.jsx)(Dk,{label:`Email`,value:t?.email??`—`}),(0,I.jsx)(Dk,{label:`Member since`,value:mC(t?.createdAt??null)})]})]})}function Dk({label:e,value:t}){return(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b pb-3 last:border-0 last:pb-0`,children:[(0,I.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,I.jsx)(`span`,{className:`font-medium`,children:t})]})}function Ok(){let e=oS(),[t,n]=(0,v.useState)(``),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(``),s=a.length>0&&r!==a,c=t.length>0&&r.length>=Sk&&!s,l=async a=>{if(a.preventDefault(),c)try{await e.mutateAsync({currentPassword:t,newPassword:r}),U.success(`Password changed. Other sessions were signed out.`),n(``),i(``),o(``)}catch(e){U.error(rk(e,`Could not change the password`))}};return(0,I.jsxs)(nE,{children:[(0,I.jsxs)(rE,{children:[(0,I.jsx)(iE,{className:`text-sm`,children:`Change password`}),(0,I.jsx)(aE,{children:`Changing your password signs out your other sessions.`})]}),(0,I.jsx)(oE,{children:(0,I.jsxs)(`form`,{onSubmit:e=>void l(e),className:`max-w-sm space-y-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`current-password`,children:`Current password`}),(0,I.jsx)($,{id:`current-password`,type:`password`,value:t,autoComplete:`current-password`,onChange:e=>n(e.target.value)})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`new-password`,children:`New password`}),(0,I.jsx)($,{id:`new-password`,type:`password`,value:r,autoComplete:`new-password`,onChange:e=>i(e.target.value)}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`At least `,Sk,` characters.`]})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`confirm-password`,children:`Confirm new password`}),(0,I.jsx)($,{id:`confirm-password`,type:`password`,value:a,autoComplete:`new-password`,onChange:e=>o(e.target.value)})]}),s?(0,I.jsx)(`p`,{className:`text-sm text-destructive`,children:`Passwords do not match.`}):null,(0,I.jsxs)(J,{type:`submit`,disabled:!c||e.isPending,children:[e.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Change password`]})]})})]})}var kk=8;function Ak(){let e=ht(),t=dt(),n=tS(),r=iS(),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(``),u=Nx(t.search),d=Ix(t.search);if(n.isPending)return(0,I.jsx)(`div`,{className:`flex h-dvh items-center justify-center`,children:(0,I.jsx)(wa,{className:`size-5 animate-spin text-muted-foreground`})});if(n.data&&!n.data.registrationOpen)return(0,I.jsx)(jk,{googleAuth:n.data.googleAuth});let f=c.length>0&&c.length<kk,p=i.trim()&&o.trim()&&c.length>=kk,m=async t=>{if(t.preventDefault(),p)try{await r.mutateAsync({name:i.trim(),email:o.trim(),password:c}),await e(d,{replace:!0})}catch{}};return nk(r.error)?(0,I.jsx)(jk,{googleAuth:n.data?.googleAuth??!1}):(0,I.jsxs)(ik,{children:[(0,I.jsxs)(nE,{className:`w-full max-w-sm`,children:[(0,I.jsx)(rE,{className:`grid-rows-[auto] gap-0`,children:(0,I.jsx)(iE,{children:`Create an account`})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[n.data?.googleAuth?(0,I.jsx)(ak,{label:`Sign up with Google`,returnPath:d}):null,(0,I.jsxs)(`form`,{onSubmit:e=>void m(e),className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`name`,children:`Name`}),(0,I.jsx)($,{id:`name`,value:i,autoFocus:!0,required:!0,autoComplete:`name`,placeholder:`Ada Lovelace`,onChange:e=>a(e.target.value)})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`email`,children:`Email`}),(0,I.jsx)($,{id:`email`,type:`email`,value:o,required:!0,autoComplete:`username`,placeholder:`operator@example.com`,onChange:e=>s(e.target.value)})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`password`,children:`Password`}),(0,I.jsx)($,{id:`password`,type:`password`,value:c,required:!0,autoComplete:`new-password`,placeholder:`••••••••••••`,onChange:e=>l(e.target.value)}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`At least `,kk,` characters.`]})]}),f?(0,I.jsxs)(`p`,{className:`text-sm text-destructive`,children:[`Use at least `,kk,` characters.`]}):null,r.isError?(0,I.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:rk(r.error,`Sign-up failed`)}):null,(0,I.jsxs)(J,{type:`submit`,className:`w-full`,disabled:r.isPending||!p,children:[r.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Create account`]})]}),(0,I.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[`Already have an account?`,` `,(0,I.jsx)(Pn,{to:Fx(xx,u),className:`text-primary-ink underline underline-offset-4`,children:`Sign in`})]})]})]}),n.data?.billing?(0,I.jsxs)(`p`,{className:`max-w-sm text-center text-xs text-balance text-muted-foreground`,children:[`By creating an account you agree to the`,` `,(0,I.jsx)(`a`,{href:`https://appaigateway.com/terms/`,target:`_blank`,rel:`noopener`,className:`underline underline-offset-4 hover:text-foreground`,children:`Terms of Service`}),` `,`and`,` `,(0,I.jsx)(`a`,{href:`https://appaigateway.com/privacy/`,target:`_blank`,rel:`noopener`,className:`underline underline-offset-4 hover:text-foreground`,children:`Privacy Policy`}),`.`]}):null]})}function jk({googleAuth:e}){return(0,I.jsx)(ik,{children:(0,I.jsxs)(nE,{className:`w-full max-w-sm`,children:[(0,I.jsxs)(rE,{children:[(0,I.jsx)(`div`,{className:`mb-2 grid size-9 place-items-center rounded-md bg-muted text-muted-foreground`,children:(0,I.jsx)(Ta,{className:`size-4`})}),(0,I.jsx)(iE,{children:`Registration is closed`})]}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[(0,I.jsxs)(Ds,{children:[(0,I.jsx)(Os,{children:`This gateway does not accept public sign-ups`}),(0,I.jsx)(ks,{children:`Sign in with an existing account. If this gateway was initialized from the CLI, finish its protected account claim from that CLI.`})]}),e?(0,I.jsx)(ak,{label:`Continue with Google`}):null,(0,I.jsx)(J,{asChild:!0,variant:`outline`,className:`w-full`,children:(0,I.jsx)(Pn,{to:`/login`,children:`Back to sign in`})})]})]})})}function Mk(){return(0,I.jsx)(`div`,{className:`flex h-dvh items-center justify-center`,children:(0,I.jsx)(wa,{className:`size-5 animate-spin text-muted-foreground`})})}function Nk(){let e=tS(),t=nS(),n=dt(),r=TS(!!e.data?.billing&&t.isSuccess),i=t.data?.user?.id,a=t.data?.user?.createdAt,o=t.data?.organization?.id??null,s=t.data?.role,c=r.data?.access.state===`billed`?r.data.access.plan?.planKey??null:null;return(0,v.useEffect)(()=>{!i||!a||!s||_x.identify(i,s,a)},[i,a,s]),(0,v.useEffect)(()=>{o&&_x.group(o,c===null?void 0:{plan:c})},[o,c]),t.isPending||e.isPending?(0,I.jsx)(Mk,{}):t.isError||!t.data?(0,I.jsx)(Vt,{to:Lx(`${n.pathname}${n.search}`),replace:!0}):e.data?(0,I.jsx)(ox,{session:t.data,capabilities:e.data,billing:r.data?.access,quota:r.data?.quota,children:(0,I.jsx)(nw,{children:(0,I.jsxs)(Wt,{children:[(0,I.jsx)(Ht,{path:`/`,element:(0,I.jsx)(Vt,{to:Cx,replace:!0})}),(0,I.jsx)(Ht,{path:`/apps`,element:(0,I.jsx)(UO,{})}),(0,I.jsx)(Ht,{path:`/apps/:appId`,element:(0,I.jsx)(Vt,{to:`overview`,replace:!0})}),(0,I.jsx)(Ht,{path:`/apps/:appId/:tab`,element:(0,I.jsx)(qD,{})}),(0,I.jsx)(Ht,{path:`/apps/:appId/:tab/:section`,element:(0,I.jsx)(qD,{})}),(0,I.jsx)(Ht,{path:`/providers`,element:(0,I.jsx)(_O,{})}),(0,I.jsx)(Ht,{path:`/providers/:section`,element:(0,I.jsx)(_O,{})}),(0,I.jsx)(Ht,{path:`/keys`,element:(0,I.jsx)(xk,{})}),(0,I.jsx)(Ht,{path:`/settings`,element:(0,I.jsx)(Vt,{to:`/settings/${wk}`,replace:!0})}),(0,I.jsx)(Ht,{path:`/settings/:section`,element:(0,I.jsx)(Tk,{})}),e.data.billing?(0,I.jsx)(Ht,{path:`/billing`,element:(0,I.jsx)(JO,{})}):null,(0,I.jsx)(Ht,{path:`/checkout`,element:(0,I.jsx)(ek,{})}),(0,I.jsx)(Ht,{path:`*`,element:(0,I.jsx)(Vt,{to:Cx,replace:!0})})]})})}):(0,I.jsx)(`div`,{className:`mx-auto max-w-lg px-4 py-16`,children:(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(Os,{children:`Could not reach the gateway`}),(0,I.jsx)(ks,{children:`The console could not load deployment capabilities. Reload to try again.`})]})})}function Pk({children:e}){let t=nS(),n=dt();return t.isPending?(0,I.jsx)(Mk,{}):t.isSuccess&&t.data?(0,I.jsx)(Vt,{to:Ix(n.search),replace:!0}):(0,I.jsx)(I.Fragment,{children:e})}function Fk(){return bx(),(0,I.jsxs)(Db,{children:[(0,I.jsxs)(Wt,{children:[(0,I.jsx)(Ht,{path:`/login`,element:(0,I.jsx)(Pk,{children:(0,I.jsx)(bk,{})})}),(0,I.jsx)(Ht,{path:`/signup`,element:(0,I.jsx)(Pk,{children:(0,I.jsx)(Ak,{})})}),(0,I.jsx)(Ht,{path:`/cli/approve/:id`,element:(0,I.jsx)(mk,{})}),(0,I.jsx)(Ht,{path:`*`,element:(0,I.jsx)(Nk,{})})]}),(0,I.jsx)(ac,{position:`top-center`})]})}function Ik(e){window.history.pushState({},``,e),window.dispatchEvent(new PopStateEvent(`popstate`))}function Lk(){return{pathname:window.location.pathname,search:window.location.search}}function Rk(e={}){let t=e.redirectToLogin??Ik,n=e.currentPath??Lk,r=e=>{if(fx(e)){i.invalidateQueries({queryKey:eS.billingStatus});return}if(!dx(e))return;i.setQueryData(eS.session,null);let{pathname:r,search:a}=n();Tx.has(r)||t(Lx(`${r}${a}`))},i=new oi({defaultOptions:{queries:{refetchOnWindowFocus:!1,staleTime:1e4,retry:(e,t)=>Ox(t)&&e<2}},queryCache:new ai({onError:r}),mutationCache:new ni({onError:r})});return i}var zk=Rk();(0,b.createRoot)(document.getElementById(`root`)).render((0,I.jsx)(v.StrictMode,{children:(0,I.jsx)(di,{client:zk,children:(0,I.jsx)(Pi,{attribute:`class`,defaultTheme:`system`,enableSystem:!0,children:(0,I.jsx)(Mn,{children:(0,I.jsx)(Fk,{})})})})}));export{fS as $,Rw as A,dC as B,sT as C,xT as D,ST as E,aw as F,gC as G,mC as H,rw as I,QS as J,bC as K,_C as L,sw as M,lw as N,gT as O,ow as P,_S as Q,xC as R,hT as S,aT as T,cC as U,fC as V,uC as W,WS as X,US as Y,qS as Z,BT as _,Q as a,Na as at,FT as b,uE as c,h as ct,rE as d,s as dt,HS as et,YT as f,l as ft,VT as g,UT as h,lE as i,Ga as it,uw as j,_T as k,nE as l,d as lt,HT as m,$ as n,H as nt,Z as o,Ni as ot,zT as p,vC as q,sE as r,Za as rt,cE as s,ci as st,jD as t,J as tt,oE as u,o as ut,NT as v,vT as w,eT as x,MT as y,lC as z};
98
+ `:``} -d ${u(JSON.stringify(c))}`})})})}function HO({hasProvider:e,firstApp:t}){return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(iE,{className:`text-base`,children:`Start proxying in three steps`})}),(0,I.jsx)(oE,{className:`space-y-6`,children:(0,I.jsxs)(`ol`,{className:`space-y-5`,children:[(0,I.jsx)(zO,{index:1,title:`Add a provider key`,description:`Your own OpenAI, Anthropic or Gemini key. It is encrypted on arrival and never shown again.`,done:e,completedLabel:`Added`,action:(0,I.jsx)(DO,{label:`Add a provider`})}),(0,I.jsx)(zO,{index:2,title:`Create an app`,description:`One app per iOS app or backend. It decides who may call the gateway and what they may spend.`,done:!!t,completedLabel:`Created`,action:(0,I.jsx)(ZD,{trigger:(0,I.jsx)(iw,{size:`sm`,children:`Create an app`})})}),(0,I.jsx)(zO,{index:3,title:`Send your first request`,description:t?.authentication_type===`api_key`?(0,I.jsxs)(I.Fragment,{children:[`Replace `,(0,I.jsx)(`code`,{children:`API_KEY`}),` with `,(0,I.jsx)(Pn,{className:`text-primary-ink underline underline-offset-4`,to:`/apps/${encodeURIComponent(t.id)}/auth/identity`,children:`your API key`}),`.`]}):`Run this example in your iOS app using the AppAIGateway Swift package.`,done:!1,completedLabel:`Received`,status:e&&t?(0,I.jsx)(VO,{app:t}):void 0,action:e&&t?(0,I.jsx)(BO,{}):(0,I.jsx)(J,{asChild:!0,size:`sm`,variant:`outline`,children:(0,I.jsx)(`a`,{href:LO,target:`_blank`,rel:`noopener`,children:`Quickstart`})})})]})})]})}function UO(){let[e,t]=(0,v.useState)(yC());FO();let n=(0,v.useRef)(!1),r=jS(e,n.current?RO:void 0),i=dS(),a=r.isSuccess&&!r.data.has_proxied_requests;n.current=a;let{organization:o}=sx(),s=o?.id,c=r.data?.has_proxied_requests;(0,v.useEffect)(()=>{},[s,c]);let l=(r.data?.apps.length??0)>0,u=(r.data?.apps??[]).reduce((e,t)=>({requests:e.requests+t.usage.requests,tokens:e.tokens+vC(t.usage),cost:e.cost+t.usage.cost_usd,users:e.users+t.users.total,errors:e.errors+t.usage.errors}),{requests:0,tokens:0,cost:0,users:0,errors:0});return(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsx)(cw,{title:`Apps`,action:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(qT,{value:e,onChange:t}),(0,I.jsx)(ZD,{})]})}),r.isError?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`Could not load apps`}),(0,I.jsx)(ks,{children:r.error instanceof Error?r.error.message:`Unknown error`})]}):null,(0,I.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,I.jsx)(dE,{label:`Spend`,value:r.isPending?(0,I.jsx)(aw,{className:`h-6 w-20`}):dC(u.cost),detail:`month to date`}),(0,I.jsx)(dE,{label:`Users`,value:r.isPending?(0,I.jsx)(aw,{className:`h-6 w-12`}):cC(u.users),detail:`${r.data?.apps.length??0} apps`}),(0,I.jsx)(dE,{label:`Requests`,value:r.isPending?(0,I.jsx)(aw,{className:`h-6 w-16`}):cC(u.requests),detail:u.errors>0?`${cC(u.errors)} provider errors`:`month to date`}),(0,I.jsx)(dE,{label:`Tokens`,value:r.isPending?(0,I.jsx)(aw,{className:`h-6 w-16`}):lC(u.tokens),detail:`all buckets`})]}),r.isPending||l?(0,I.jsx)(nE,{className:`overflow-hidden py-0`,children:(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{className:`hover:bg-transparent`,children:[(0,I.jsx)(Z,{children:`App`}),(0,I.jsx)(Z,{className:`text-right`,children:`Budget`}),(0,I.jsx)(Z,{className:`text-right`,children:`Users`}),(0,I.jsx)(Z,{className:`text-right`,children:`Requests`}),(0,I.jsx)(Z,{className:`text-right`,children:`Tokens`}),(0,I.jsx)(Z,{className:`w-8`})]})}),(0,I.jsx)(lE,{children:r.isPending?[0,1,2].map(e=>(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:6,children:(0,I.jsx)(aw,{className:`h-8 w-full`})})},e)):r.data?.apps.map(e=>(0,I.jsxs)(uE,{className:`group relative h-13`,children:[(0,I.jsx)(Q,{children:(0,I.jsx)(Pn,{to:`/apps/${e.id}/overview`,className:`block after:absolute after:inset-0 after:content-['']`,children:(0,I.jsxs)(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.name,(0,I.jsx)(YS,{status:e.status})]})})}),(0,I.jsxs)(Q,{className:`tabular text-right`,children:[dC(e.usage.cost_usd),(0,I.jsxs)(`span`,{className:`text-muted-foreground`,children:[` / `,e.monthly_budget_usd===null?(0,I.jsx)(`span`,{title:`No monthly budget`,children:`∞`}):dC(e.monthly_budget_usd)]})]}),(0,I.jsxs)(Q,{className:`tabular text-right`,children:[cC(e.users.total),e.users.blocked>0?(0,I.jsxs)(`span`,{className:`block text-[11px] text-destructive`,children:[e.users.blocked,` blocked`]}):null]}),(0,I.jsxs)(Q,{className:`tabular text-right`,children:[cC(e.usage.requests),e.usage.errors>0?(0,I.jsxs)(`span`,{className:`block text-[11px] text-amber-600 dark:text-amber-400`,children:[e.usage.errors,` errors`]}):null]}),(0,I.jsx)(Q,{className:`tabular text-right`,children:lC(vC(e.usage))}),(0,I.jsx)(Q,{children:(0,I.jsx)(aa,{className:`size-4 text-muted-foreground transition-transform group-hover:translate-x-0.5`})})]},e.id))})]})}):null,a?(0,I.jsx)(HO,{hasProvider:(i.data?.providers.length??0)>0,firstApp:r.data?.apps.reduce((e,t)=>!e||t.created_at<e.created_at?t:e,void 0)}):null]})}function WO({className:e,orientation:t=`horizontal`,...n}){return(0,I.jsx)(zy,{"data-slot":`tabs`,"data-orientation":t,orientation:t,className:H(`group/tabs flex gap-2 data-[orientation=horizontal]:flex-col`,e),...n})}var GO=eo(`group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-[orientation=horizontal]/tabs:h-9 group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col data-[variant=line]:rounded-none`,{variants:{variant:{default:`bg-muted`,line:`gap-1 bg-transparent`}},defaultVariants:{variant:`default`}});function KO({className:e,variant:t=`default`,...n}){return(0,I.jsx)(By,{"data-slot":`tabs-list`,"data-variant":t,className:H(GO({variant:t}),e),...n})}function qO({className:e,...t}){return(0,I.jsx)(Vy,{"data-slot":`tabs-trigger`,className:H(`relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-[orientation=vertical]/tabs:w-full group-data-[orientation=vertical]/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 group-data-[variant=default]/tabs-list:data-[state=active]:shadow-sm group-data-[variant=line]/tabs-list:data-[state=active]:shadow-none dark:text-muted-foreground dark:hover:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,`group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:border-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent`,`data-[state=active]:bg-background data-[state=active]:text-foreground dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 dark:data-[state=active]:text-foreground`,`after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-[orientation=horizontal]/tabs:after:inset-x-0 group-data-[orientation=horizontal]/tabs:after:bottom-[-5px] group-data-[orientation=horizontal]/tabs:after:h-0.5 group-data-[orientation=vertical]/tabs:after:inset-y-0 group-data-[orientation=vertical]/tabs:after:-right-1 group-data-[orientation=vertical]/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-[state=active]:after:opacity-100`,e),...t})}function JO(){let{capabilities:e,organization:t}=sx(),[n,r]=(0,v.useState)(`month`),[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(null),c=TS(e.billing),l=ES(e.billing),u=DS(),d=OS(),f=kS(),p=AS(),m=c.data?.access,h=c.data?.quota,g=l.data?.plans??[],_=async e=>{try{let{url:t}=await u.mutateAsync({planKey:e.planKey,billingPeriod:n});window.location.assign(t)}catch(e){U.error(e instanceof Error?e.message:`Could not start checkout`)}},y=async()=>{if(o)try{let e=await d.mutateAsync({planKey:o.planKey,billingPeriod:TC(m)?.billingPeriod??n});if(s(null),e.requiredActionUrl){window.location.assign(e.requiredActionUrl);return}U.success(`Moved to ${o.name}`)}catch(e){U.error(e instanceof Error?e.message:`Could not change the plan`)}},b=(e,t)=>{if(t.intent===`checkout`)return void _(e);if(t.intent===`change`)return s(e);if(t.intent===`cancel`)return a(!0)},x=async()=>{try{await f.mutateAsync(),U.success(`Subscription canceled`),a(!1)}catch(e){U.error(e instanceof Error?e.message:`Could not cancel the subscription`)}},S=async()=>{let e=TC(m);if(e)try{let t=await p.mutateAsync({planKey:e.planKey,billingPeriod:e.billingPeriod??n});if(t.requiredActionUrl){window.location.assign(t.requiredActionUrl);return}U.success(`Subscription resumed`)}catch(e){U.error(e instanceof Error?e.message:`Could not resume the subscription`)}},C=AC(t)??OC(m);return(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsx)(cw,{title:`Billing`}),c.isError?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`Could not load billing status`}),(0,I.jsx)(ks,{children:c.error instanceof Error?c.error.message:`Unknown error`})]}):null,C?(0,I.jsxs)(Ds,{variant:C.tone===`destructive`?`destructive`:`default`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:C.title}),(0,I.jsx)(ks,{children:C.description})]}):null,(0,I.jsx)(YO,{access:m,quota:h,pending:c.isPending,cancelPending:f.isPending,resumePending:p.isPending,onCancel:()=>a(!0),onResume:()=>void S()}),(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,I.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Plans`}),g.some(e=>IC(e,`year`))?(0,I.jsx)(WO,{value:n,onValueChange:e=>r(e),children:(0,I.jsxs)(KO,{children:[(0,I.jsx)(qO,{value:`month`,children:`Monthly`}),(0,I.jsx)(qO,{value:`year`,children:`Yearly`})]})}):null]}),l.isPending?(0,I.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:[0,1,2].map(e=>(0,I.jsx)(aw,{className:`h-52 w-full`},e))}):(0,I.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:g.map(e=>{let t=UC(e,g,m);return(0,I.jsx)(QO,{plan:e,period:n,action:t,pending:u.isPending||d.isPending,onAct:()=>b(e,t)},e.planKey)})}),(0,I.jsx)(VD,{open:o!==null,onOpenChange:e=>s(e?o:null),title:`Move to ${o?.name??``}`,description:(0,I.jsx)(`p`,{children:`Your subscription changes to this plan and its allowance applies from the change. The billing provider settles the difference, charging an upgrade right away and putting a downgrade on your next invoice.`}),confirmLabel:`Change plan`,pending:d.isPending,onConfirm:()=>void y()}),(0,I.jsx)(VD,{open:i,onOpenChange:a,title:`Cancel subscription`,description:(0,I.jsx)(`p`,{children:`Gateway traffic keeps working until the end of the current period, then stops until you resubscribe.`}),confirmLabel:`Cancel subscription`,destructive:!0,pending:f.isPending,onConfirm:()=>void x()})]})}function YO({access:e,quota:t,pending:n,cancelPending:r,resumePending:i,onCancel:a,onResume:o}){let s=wC(e),c=TC(e),l=c?LC(c):null,{organization:u}=sx(),d=jC(t,u);return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsxs)(iE,{className:`flex items-center gap-1.5 text-sm`,children:[`Current plan:`,n?(0,I.jsx)(aw,{className:`h-4 w-24`}):(0,I.jsx)(`span`,{children:s?.planName??`No plan`})]})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[n?(0,I.jsx)(aw,{className:`h-6 w-40`}):null,d&&!n?(0,I.jsx)(XO,{meter:d,timeline:l}):null,!d&&!n&&l?(0,I.jsx)(ZO,{timeline:l}):null,!n&&c?(0,I.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:BC(c)?(0,I.jsxs)(iw,{variant:`outline`,size:`sm`,disabled:i,onClick:o,children:[i?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Resume subscription`]}):zC(c)?(0,I.jsx)(iw,{variant:`outline`,size:`sm`,disabled:r,onClick:a,children:`Cancel subscription`}):null}):null]})]})}function XO({meter:e,timeline:t}){return(0,I.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[(0,I.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`Requests this period`}),(0,I.jsx)(`span`,{className:`tabular text-sm font-medium`,children:e.label})]}),(0,I.jsx)(qb,{meter:e}),t?(0,I.jsx)(ZO,{timeline:t}):null]})}function ZO({timeline:e}){return(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[e.label,` `,(0,I.jsx)(`span`,{className:`tabular text-foreground`,children:e.value})]})}function QO({plan:e,period:t,action:n,pending:r,onAct:i}){let a=IC(e,t),o=e.prices.length===0,s=n.intent===`current`;return(0,I.jsxs)(nE,{className:H(`h-full`,s&&`border-primary`),children:[(0,I.jsxs)(rE,{children:[(0,I.jsx)(iE,{className:`text-sm`,children:e.name}),(0,I.jsx)(aE,{children:e.description})]}),(0,I.jsxs)(oE,{className:`flex flex-1 flex-col gap-4`,children:[(0,I.jsx)(`p`,{className:`tabular text-2xl font-semibold`,children:o?`Free`:a?FC(a):`—`}),e.trialDays>0&&!s?(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[e.trialDays,`-day free trial`]}):null,e.features.length>0?(0,I.jsx)(`ul`,{className:`space-y-1.5`,children:e.features.map(e=>(0,I.jsxs)(`li`,{className:`flex items-start gap-2 text-sm text-muted-foreground`,children:[(0,I.jsx)(ra,{className:`mt-0.5 size-3.5 shrink-0 text-foreground`}),e]},e))}):null,(0,I.jsx)(`div`,{className:`mt-auto pt-2`,children:s?(0,I.jsx)(J,{className:`w-full`,variant:`outline`,disabled:!0,children:n.label}):(0,I.jsxs)(iw,{className:`w-full`,wrapperClassName:`w-full`,variant:n.variant,disabled:r||!o&&!a,...n.reason?{reason:n.reason}:{},onClick:i,children:[r?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,n.label]})})]})]})}var $O=`/billing`;function ek(){let e=dt(),{capabilities:t,billing:n,canManage:r}=sx(),i=ES(t.billing),{mutateAsync:a}=DS(),o=(0,v.useRef)(!1),[s,c]=(0,v.useState)(null),l=Nx(e.search),u=i.data?.plans??[],d=l===null?void 0:u.find(e=>e.planKey===l),f=wC(n),p=!t.billing||l===`free`?Cx:l===null||!r||f?.planKey===l?$O:null,m=p===null&&i.isSuccess&&!d,h=p===null&&d!==void 0&&s===null;return(0,v.useEffect)(()=>{if(!h||o.current||d===void 0)return;o.current=!0;let e=IC(d,`month`)?`month`:`year`;a({planKey:d.planKey,billingPeriod:e}).then(({url:e})=>window.location.assign(e)).catch(e=>{c(e instanceof Error?e.message:`Could not start checkout`)})},[h,d,a]),p===null?m?(0,I.jsx)(Vt,{to:$O,replace:!0}):s===null?(0,I.jsxs)(`div`,{className:`flex min-h-60 flex-col items-center justify-center gap-3 py-10 text-center`,children:[(0,I.jsx)(wa,{className:`size-5 animate-spin text-muted-foreground`}),(0,I.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:d?`Redirecting you to checkout for ${d.name}…`:`Preparing your checkout…`})]}):(0,I.jsx)(`div`,{className:`mx-auto max-w-lg py-10`,children:(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`Could not start checkout`}),(0,I.jsxs)(ks,{className:`flex flex-wrap items-center gap-3`,children:[(0,I.jsx)(`span`,{children:s}),(0,I.jsx)(J,{asChild:!0,size:`sm`,variant:`outline`,children:(0,I.jsx)(Pn,{to:$O,children:`Go to plans`})})]})]})}):(0,I.jsx)(Vt,{to:p,replace:!0})}var tk={INVALID_EMAIL_OR_PASSWORD:`That email and password combination is not correct.`,INVALID_EMAIL:`Enter a valid email address.`,INVALID_PASSWORD:`That password is not correct.`,USER_ALREADY_EXISTS:`An account with that email already exists.`,USER_NOT_FOUND:`No account exists for that email.`,PASSWORD_TOO_SHORT:`Choose a longer password.`,PASSWORD_TOO_LONG:`Choose a shorter password.`,EMAIL_NOT_VERIFIED:`Verify your email address before signing in.`,CREDENTIAL_ACCOUNT_NOT_FOUND:`This account signs in with Google.`,SESSION_EXPIRED:`Your session expired. Sign in again.`,registration_disabled:`Public registration is disabled for this deployment.`,session_required:`Sign in as a person before approving this request.`,account_exists:`This sign-in already has an account. Sign out, then create a new sign-in to claim this one.`};function nk(e){return e instanceof ux&&e.code===`registration_disabled`}function rk(e,t=`Something went wrong. Try again.`){return e instanceof ux?tk[e.code]||(e.message&&!e.message.startsWith(`Request failed with status`)?e.message:t):e instanceof Error&&e.message?e.message:t}function ik({children:e}){return(0,I.jsxs)(`div`,{className:`flex min-h-dvh flex-col items-center justify-center gap-6 px-4 py-10`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-1.5 text-lg font-semibold tracking-tight`,children:[(0,I.jsx)(`span`,{children:`App`}),(0,I.jsx)($b,{size:26}),(0,I.jsx)(`span`,{children:`Gateway`})]}),e]})}function ak({label:e=`Continue with Google`,returnPath:t,onStart:n}){let[r,i]=(0,v.useState)(!1),a=async()=>{i(!0);try{await(n?n():Zx(t))}catch(e){i(!1),U.error(rk(e,`Could not start Google sign-in`))}};return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(J,{type:`button`,variant:`outline`,className:`w-full`,disabled:r,onClick:()=>void a(),children:[r?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):(0,I.jsx)(ok,{}),e]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,I.jsx)(`span`,{className:`h-px flex-1 bg-border`}),(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`or`}),(0,I.jsx)(`span`,{className:`h-px flex-1 bg-border`})]})]})}function ok(){return(0,I.jsxs)(`svg`,{className:`size-4`,viewBox:`0 0 24 24`,"aria-hidden":`true`,children:[(0,I.jsx)(`path`,{fill:`#4285F4`,d:`M23.52 12.27c0-.85-.08-1.67-.22-2.45H12v4.64h6.46a5.52 5.52 0 0 1-2.4 3.62v3h3.88c2.27-2.09 3.58-5.17 3.58-8.81Z`}),(0,I.jsx)(`path`,{fill:`#34A853`,d:`M12 24c3.24 0 5.96-1.08 7.94-2.92l-3.88-3c-1.08.72-2.45 1.15-4.06 1.15-3.13 0-5.78-2.11-6.73-4.95H1.26v3.09A12 12 0 0 0 12 24Z`}),(0,I.jsx)(`path`,{fill:`#FBBC05`,d:`M5.27 14.28a7.2 7.2 0 0 1 0-4.56v-3.1H1.26a12 12 0 0 0 0 10.76l4.01-3.1Z`}),(0,I.jsx)(`path`,{fill:`#EA4335`,d:`M12 4.77c1.76 0 3.35.61 4.6 1.8l3.44-3.44C17.95 1.19 15.24 0 12 0A12 12 0 0 0 1.26 6.62l4.01 3.1C6.22 6.88 8.87 4.77 12 4.77Z`})]})}function sk(e){return`app-ai-gateway:cli-approve:${e}`}function ck(e){let t=null;try{t=JSON.parse(sessionStorage.getItem(e)??`null`)}catch{t=null}if(!t||typeof t.token!=`string`)return null;if(!(t.expiresAt>Date.now())){try{sessionStorage.removeItem(e)}catch{}return null}return t}function lk(e,t){try{sessionStorage.setItem(e,JSON.stringify(t))}catch{}}function uk(e){try{sessionStorage.removeItem(e)}catch{}}function dk(e){if(e===`claim`)return`Claim your account`;let[t,n]=e.split(`.`),r=t===`provider-gateway`?`provider gateway`:`provider`;return n===`add`?`Add a ${r}`:n===`rotate-key`?`Rotate the ${r} credential`:n===`update`?`Update the ${r}`:`Approve a ${r} change`}function fk(e){return e.length>18?`${e.slice(0,10)}…${e.slice(-6)}`:e}function pk(e){return e.kind!==`claim`&&!(e.kind===`provider.add`&&e.payload.providerGatewayId)}function mk(){let{id:e=``}=_t(),t=dt(),n=ht(),r=sk(t.pathname),[i]=(0,v.useState)(()=>t.hash.replace(/^#/,``)||ck(r)?.token||``);(0,v.useEffect)(()=>{t.hash&&n(`${t.pathname}${t.search}`,{replace:!0})},[t.hash,t.pathname,t.search,n]);let a=Ti({queryKey:[`cli-approve`,e],queryFn:()=>hx(X.cliBrowserDetails,[e],{submissionToken:i}),enabled:!!i,retry:!1,staleTime:1/0}),o=a.data;(0,v.useEffect)(()=>{o&&lk(r,{token:i,expiresAt:Date.parse(o.expiresAt)})},[o,r,i]);let[s,c]=(0,v.useState)(!1),l=Ei({mutationFn:t=>hx(X.cliBrowserSubmit,[e],{submissionToken:i,...t}),onSuccess:()=>{uk(r),c(!0)}});return i?a.isPending?(0,I.jsx)(hk,{id:e,children:(0,I.jsx)(`div`,{className:`flex justify-center py-6`,children:(0,I.jsx)(wa,{className:`size-5 animate-spin text-muted-foreground`})})}):a.isError||!o?(0,I.jsx)(hk,{id:e,children:(0,I.jsxs)(Ds,{variant:`destructive`,role:`alert`,children:[(0,I.jsx)(Os,{children:`This request can no longer be approved`}),(0,I.jsxs)(ks,{children:[rk(a.error,`The link has expired or was already used.`),` Rerun the command in your CLI to start a new one.`]})]})}):s?(0,I.jsx)(hk,{title:dk(o.kind),id:e,expiresAt:o.expiresAt,children:(0,I.jsxs)(Ds,{role:`status`,children:[(0,I.jsx)(la,{className:`size-4`}),(0,I.jsx)(Os,{children:`Approved`}),(0,I.jsx)(ks,{children:`Return to your CLI.`})]})}):(0,I.jsxs)(hk,{title:dk(o.kind),id:e,expiresAt:o.expiresAt,children:[(0,I.jsx)(gk,{details:o}),o.blockedBy===`session_required`?(0,I.jsx)(yk,{id:e,token:i,googleEnabled:o.googleEnabled,onDone:()=>void a.refetch()}):o.blockedBy===`account_exists`?(0,I.jsx)(bk,{viewer:o.viewer,onDone:()=>void a.refetch()}):(0,I.jsx)(xk,{details:o,pending:l.isPending,error:l.isError?rk(l.error,`Approval failed`):null,onSubmit:e=>l.mutate(e)})]}):(0,I.jsx)(hk,{id:e,children:(0,I.jsxs)(Ds,{variant:`destructive`,role:`alert`,children:[(0,I.jsx)(Os,{children:`This link is missing its proof`}),(0,I.jsx)(ks,{children:`Open the full link your CLI printed, or rerun the command to get a new one.`})]})})}function hk({title:e,id:t,expiresAt:n,children:r}){return(0,I.jsx)(ik,{children:(0,I.jsxs)(`div`,{className:`w-full max-w-sm space-y-3`,children:[(0,I.jsxs)(nE,{className:`w-full`,children:[(0,I.jsx)(rE,{className:`grid-rows-[auto] gap-0`,children:(0,I.jsx)(iE,{children:e??`Approve a CLI request`})}),(0,I.jsx)(oE,{className:`space-y-4`,children:r})]}),(0,I.jsx)(vk,{id:t,expiresAt:n})]})})}function gk({details:e}){let t=e.kind===`claim`||Object.keys(e.payload).length===0?null:JSON.stringify(e.payload,null,2);return(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsxs)(_k,{label:`Account`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:e.account.name}),(0,I.jsx)(`p`,{className:`font-mono text-xs text-muted-foreground`,children:fk(e.account.id)})]}),e.viewer?(0,I.jsxs)(_k,{label:`Approving as`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:e.viewer.name??`Signed-in user`}),e.viewer.email?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.viewer.email}):null]}):null,t?(0,I.jsx)(`pre`,{className:`max-h-56 overflow-auto rounded-md border bg-muted/40 px-3 py-2 font-mono text-xs whitespace-pre-wrap`,children:t}):null]})}function _k({label:e,children:t}){return(0,I.jsxs)(`div`,{className:`rounded-md border bg-muted/40 px-3 py-2`,children:[(0,I.jsx)(`p`,{className:`text-[11px] tracking-wide text-muted-foreground uppercase`,children:e}),t]})}function vk({id:e,expiresAt:t}){return(0,I.jsxs)(`div`,{className:`space-y-0.5 px-1 text-xs text-muted-foreground`,children:[(0,I.jsx)(`p`,{className:`font-mono break-all`,children:e}),t?(0,I.jsxs)(`p`,{children:[`Expires `,new Date(t).toLocaleString(),`.`]}):null]})}function yk({id:e,token:t,googleEnabled:n,onDone:r}){let[i,a]=(0,v.useState)(!0),o=rS(),s=Ei({mutationFn:n=>hx(X.cliBrowserRegister,[e],{submissionToken:t,...n})}),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(``),m=i?s:o,h=async e=>{e.preventDefault();try{i?await s.mutateAsync({name:c.trim(),email:u.trim(),password:f}):await o.mutateAsync({email:u.trim(),password:f}),p(``),r()}catch{}};return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Claim this account as a new person. Create your sign-in here, or sign in if you already created one for this claim.`}),n?(0,I.jsx)(ak,{label:i?`Sign up with Google`:`Continue with Google`,onStart:async()=>{let n=await hx(X.cliBrowserGoogle,[e],{submissionToken:t});if(!n.url)throw Error(`Google sign-in is unavailable right now.`);window.location.assign(n.url)}}):null,(0,I.jsxs)(`form`,{onSubmit:e=>void h(e),className:`space-y-4`,children:[i?(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`claim-name`,children:`Name`}),(0,I.jsx)($,{id:`claim-name`,value:c,required:!0,autoComplete:`name`,placeholder:`Ada Lovelace`,onChange:e=>l(e.target.value)})]}):null,(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`claim-email`,children:`Email`}),(0,I.jsx)($,{id:`claim-email`,type:`email`,value:u,required:!0,autoComplete:`username`,placeholder:`you@example.com`,onChange:e=>d(e.target.value)})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`claim-password`,children:`Password`}),(0,I.jsx)($,{id:`claim-password`,type:`password`,value:f,required:!0,autoComplete:i?`new-password`:`current-password`,placeholder:`••••••••••••`,onChange:e=>p(e.target.value)})]}),m.isError?(0,I.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:rk(m.error,i?`Sign-up failed`:`Sign-in failed`)}):null,(0,I.jsxs)(J,{type:`submit`,className:`w-full`,disabled:m.isPending,children:[m.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,i?`Create account`:`Sign in`]})]}),(0,I.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[i?`Already created a sign-in for this claim? `:`No sign-in yet? `,(0,I.jsx)(`button`,{type:`button`,className:`text-primary-ink underline underline-offset-4`,onClick:()=>a(e=>!e),children:i?`Sign in`:`Create one`})]})]})}function bk({viewer:e,onDone:t}){let n=aS();return(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[e?.name??e?.email,` is signed in and already has an account. This one must be claimed by a new person, so sign out first, then create a sign-in on this page.`]}),(0,I.jsxs)(J,{type:`button`,className:`w-full`,disabled:n.isPending,onClick:()=>n.mutate(void 0,{onSettled:t}),children:[n.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Sign out`]})]})}function xk({details:e,pending:t,error:n,onSubmit:r}){let i=pk(e),[a,o]=(0,v.useState)(``);return(0,I.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),!(i&&!a)&&(r({approve:!0,...i?{secret:a}:{}}),o(``))},className:`space-y-4`,children:[i?(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`approve-secret`,children:`Provider credential`}),(0,I.jsx)($,{id:`approve-secret`,type:`password`,value:a,required:!0,autoComplete:`off`,spellCheck:!1,placeholder:`••••••••••••`,onChange:e=>o(e.target.value)}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Submitted directly to your gateway and stored encrypted. Only a hint of it is ever shown again.`})]}):null,n?(0,I.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:n}):null,(0,I.jsxs)(J,{type:`submit`,className:`w-full`,disabled:t||i&&!a,children:[t?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Approve request`]})]})}function Sk(){let e=ht(),t=dt(),n=tS(),r=rS(),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(``),c=Gx(t.search),l=Ix(t.search),u=Nx(t.search),d=async t=>{if(t.preventDefault(),!(!i.trim()||!o))try{await r.mutateAsync({email:i.trim(),password:o}),await e(l,{replace:!0})}catch{}};return(0,I.jsx)(ik,{children:(0,I.jsxs)(nE,{className:`w-full max-w-sm`,children:[(0,I.jsx)(rE,{className:`grid-rows-[auto] gap-0`,children:(0,I.jsx)(iE,{children:`Sign in`})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[c?(0,I.jsxs)(Ds,{variant:c.tone,role:`alert`,children:[(0,I.jsx)(Os,{children:c.title}),(0,I.jsx)(ks,{children:c.description})]}):null,n.data?.googleAuth?(0,I.jsx)(ak,{returnPath:l}):null,(0,I.jsxs)(`form`,{onSubmit:e=>void d(e),className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`email`,children:`Email`}),(0,I.jsx)($,{id:`email`,type:`email`,value:i,autoFocus:!0,required:!0,autoComplete:`username`,placeholder:`operator@example.com`,onChange:e=>a(e.target.value)})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`password`,children:`Password`}),(0,I.jsx)($,{id:`password`,type:`password`,value:o,required:!0,autoComplete:`current-password`,placeholder:`••••••••••••`,onChange:e=>s(e.target.value)})]}),r.isError?(0,I.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:rk(r.error,`Sign-in failed`)}):null,(0,I.jsxs)(J,{type:`submit`,className:`w-full`,disabled:r.isPending||!i.trim()||!o,children:[r.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Sign in`]})]}),n.data?.registrationOpen?(0,I.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[`No account?`,` `,(0,I.jsx)(Pn,{to:Fx(Sx,u),className:`text-primary-ink underline underline-offset-4`,children:`Create one`})]}):null]})]})})}function Ck(){let e=cS(),t=lS(),n=uS(),[r,i]=(0,v.useState)(!1),[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(null),d=async()=>{if(a.trim())try{let e=await t.mutateAsync(a.trim());i(!1),o(``),c(e.key)}catch(e){U.error(e instanceof Error?e.message:`Could not create the key`)}},f=async()=>{if(l)try{await n.mutateAsync(l.id),U.success(`Management key revoked`),u(null)}catch(e){U.error(e instanceof Error?e.message:`Could not revoke the key`)}},p=e.data?.keys??[];return(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsx)(cw,{title:`Management keys`,description:`Management keys let you manage everything in this console through the API — from CI, scripts, or an AI agent.`,action:(0,I.jsxs)(iw,{size:`sm`,onClick:()=>{o(``),i(!0)},children:[(0,I.jsx)(Na,{className:`size-4`}),`New key`]})}),e.isError?(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(ca,{}),(0,I.jsx)(Os,{children:`Could not load management keys`}),(0,I.jsx)(ks,{children:e.error instanceof Error?e.error.message:`Unknown error`})]}):null,(0,I.jsx)(nE,{className:`overflow-hidden py-0`,children:(0,I.jsxs)(sE,{children:[(0,I.jsx)(cE,{children:(0,I.jsxs)(uE,{children:[(0,I.jsx)(Z,{children:`Name`}),(0,I.jsx)(Z,{children:`Key`}),(0,I.jsx)(Z,{children:`Created`}),(0,I.jsx)(Z,{children:`Status`}),(0,I.jsx)(Z,{className:`text-right`,children:`Actions`})]})}),(0,I.jsx)(lE,{children:e.isPending?[0,1,2].map(e=>(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:5,children:(0,I.jsx)(aw,{className:`h-5 w-full`})})},e)):p.length===0?(0,I.jsx)(uE,{children:(0,I.jsx)(Q,{colSpan:5,className:`py-10 text-center text-sm text-muted-foreground`,children:`No management keys yet.`})}):p.map(e=>(0,I.jsxs)(uE,{children:[(0,I.jsx)(Q,{className:`font-medium`,children:e.name}),(0,I.jsx)(Q,{className:`font-mono text-xs text-muted-foreground`,children:e.tokenHint===null?`—`:`…${e.tokenHint}`}),(0,I.jsx)(Q,{className:`tabular text-muted-foreground`,children:mC(e.createdAt)}),(0,I.jsx)(Q,{children:e.revokedAt?(0,I.jsxs)(`span`,{className:`text-muted-foreground`,children:[`Revoked `,mC(e.revokedAt)]}):e.enabled?(0,I.jsx)(`span`,{className:`text-foreground`,children:`Active`}):(0,I.jsx)(`span`,{className:`text-muted-foreground`,children:`Not yet active`})}),(0,I.jsx)(Q,{className:`text-right`,children:e.revokedAt?null:(0,I.jsx)($D,{label:e.name,children:(0,I.jsxs)(eO,{destructive:!0,onSelect:()=>u(e),children:[(0,I.jsx)($i,{}),`Revoke key`]})})})]},e.id))})]})}),(0,I.jsx)(nD,{open:r,onOpenChange:i,title:`Create a management key`,submitLabel:`Create key`,pending:t.isPending,disabled:!a.trim(),onSubmit:()=>void d(),children:(0,I.jsx)(sw,{label:`Key name`,htmlFor:`management-key-name`,hint:`Name it so you can tell keys apart in the list.`,children:(0,I.jsx)($,{id:`management-key-name`,value:a,placeholder:`CI deploy`,maxLength:100,autoFocus:!0,autoComplete:`off`,onChange:e=>o(e.target.value)})})}),(0,I.jsx)(rD,{open:s!==null,title:`Copy your new key now`,description:(0,I.jsxs)(I.Fragment,{children:[`This is the only time the plaintext for`,` `,(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:s?.name}),` is available — you will not see it again. The gateway stores only a hash.`]}),label:`Management key`,secret:s?.plaintext??``,footnote:`Store it in your secret manager. It acts with full authority over every app and provider key here.`,onAcknowledge:()=>{c(null),t.reset()}}),(0,I.jsx)(VD,{open:l!==null,onOpenChange:e=>{e||u(null)},title:`Revoke management key`,description:(0,I.jsxs)(`p`,{children:[`Anything using `,(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:l?.name}),` `,`will immediately lose access. This cannot be undone.`]}),confirmLabel:`Revoke key`,destructive:!0,pending:n.isPending,onConfirm:()=>void f()})]})}var wk=8,Tk=[{slug:`account`,label:`Account`,Component:Ok},{slug:`password`,label:`Change password`,Component:Ak}],Ek=Tk[0].slug;function Dk(){let{section:e=Ek}=_t(),t=Tk.find(t=>t.slug===e);return t?(0,I.jsxs)(`div`,{className:`space-y-6`,children:[(0,I.jsx)(cw,{title:`Settings`}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-6 lg:flex-row`,children:[(0,I.jsx)(`nav`,{"aria-label":`Settings sections`,className:`flex gap-1 overflow-x-auto lg:w-56 lg:shrink-0 lg:flex-col`,children:Tk.map(e=>{let n=e.slug===t.slug;return(0,I.jsx)(Pn,{to:`/settings/${e.slug}`,"aria-current":n?`page`:void 0,className:H(`flex h-9 shrink-0 items-center rounded-lg px-3 text-sm font-medium transition-colors`,`outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50`,n?`bg-accent text-accent-foreground`:`text-muted-foreground hover:bg-accent/60 hover:text-accent-foreground`),children:e.label},e.slug)})}),(0,I.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,I.jsx)(t.Component,{})})]})]}):(0,I.jsx)(Vt,{to:`/settings/${Ek}`,replace:!0})}function Ok(){let{session:e}=sx(),t=e.user;return(0,I.jsxs)(nE,{children:[(0,I.jsx)(rE,{children:(0,I.jsx)(iE,{className:`text-sm`,children:`Account`})}),(0,I.jsxs)(oE,{className:`space-y-3 text-sm`,children:[(0,I.jsx)(kk,{label:`Name`,value:t?.name||`—`}),(0,I.jsx)(kk,{label:`Email`,value:t?.email??`—`}),(0,I.jsx)(kk,{label:`Member since`,value:mC(t?.createdAt??null)})]})]})}function kk({label:e,value:t}){return(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b pb-3 last:border-0 last:pb-0`,children:[(0,I.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,I.jsx)(`span`,{className:`font-medium`,children:t})]})}function Ak(){let e=oS(),[t,n]=(0,v.useState)(``),[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(``),s=a.length>0&&r!==a,c=t.length>0&&r.length>=wk&&!s,l=async a=>{if(a.preventDefault(),c)try{await e.mutateAsync({currentPassword:t,newPassword:r}),U.success(`Password changed. Other sessions were signed out.`),n(``),i(``),o(``)}catch(e){U.error(rk(e,`Could not change the password`))}};return(0,I.jsxs)(nE,{children:[(0,I.jsxs)(rE,{children:[(0,I.jsx)(iE,{className:`text-sm`,children:`Change password`}),(0,I.jsx)(aE,{children:`Changing your password signs out your other sessions.`})]}),(0,I.jsx)(oE,{children:(0,I.jsxs)(`form`,{onSubmit:e=>void l(e),className:`max-w-sm space-y-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`current-password`,children:`Current password`}),(0,I.jsx)($,{id:`current-password`,type:`password`,value:t,autoComplete:`current-password`,onChange:e=>n(e.target.value)})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`new-password`,children:`New password`}),(0,I.jsx)($,{id:`new-password`,type:`password`,value:r,autoComplete:`new-password`,onChange:e=>i(e.target.value)}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`At least `,wk,` characters.`]})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`confirm-password`,children:`Confirm new password`}),(0,I.jsx)($,{id:`confirm-password`,type:`password`,value:a,autoComplete:`new-password`,onChange:e=>o(e.target.value)})]}),s?(0,I.jsx)(`p`,{className:`text-sm text-destructive`,children:`Passwords do not match.`}):null,(0,I.jsxs)(J,{type:`submit`,disabled:!c||e.isPending,children:[e.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Change password`]})]})})]})}var jk=8;function Mk(){let e=ht(),t=dt(),n=tS(),r=iS(),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(``),u=Nx(t.search),d=Ix(t.search);if(n.isPending)return(0,I.jsx)(`div`,{className:`flex h-dvh items-center justify-center`,children:(0,I.jsx)(wa,{className:`size-5 animate-spin text-muted-foreground`})});if(n.data&&!n.data.registrationOpen)return(0,I.jsx)(Nk,{googleAuth:n.data.googleAuth});let f=c.length>0&&c.length<jk,p=i.trim()&&o.trim()&&c.length>=jk,m=async t=>{if(t.preventDefault(),p)try{await r.mutateAsync({name:i.trim(),email:o.trim(),password:c}),await e(d,{replace:!0})}catch{}};return nk(r.error)?(0,I.jsx)(Nk,{googleAuth:n.data?.googleAuth??!1}):(0,I.jsxs)(ik,{children:[(0,I.jsxs)(nE,{className:`w-full max-w-sm`,children:[(0,I.jsx)(rE,{className:`grid-rows-[auto] gap-0`,children:(0,I.jsx)(iE,{children:`Create an account`})}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[n.data?.googleAuth?(0,I.jsx)(ak,{label:`Sign up with Google`,returnPath:d}):null,(0,I.jsxs)(`form`,{onSubmit:e=>void m(e),className:`space-y-4`,children:[(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`name`,children:`Name`}),(0,I.jsx)($,{id:`name`,value:i,autoFocus:!0,required:!0,autoComplete:`name`,placeholder:`Ada Lovelace`,onChange:e=>a(e.target.value)})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`email`,children:`Email`}),(0,I.jsx)($,{id:`email`,type:`email`,value:o,required:!0,autoComplete:`username`,placeholder:`operator@example.com`,onChange:e=>s(e.target.value)})]}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(ow,{htmlFor:`password`,children:`Password`}),(0,I.jsx)($,{id:`password`,type:`password`,value:c,required:!0,autoComplete:`new-password`,placeholder:`••••••••••••`,onChange:e=>l(e.target.value)}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`At least `,jk,` characters.`]})]}),f?(0,I.jsxs)(`p`,{className:`text-sm text-destructive`,children:[`Use at least `,jk,` characters.`]}):null,r.isError?(0,I.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:rk(r.error,`Sign-up failed`)}):null,(0,I.jsxs)(J,{type:`submit`,className:`w-full`,disabled:r.isPending||!p,children:[r.isPending?(0,I.jsx)(wa,{className:`size-4 animate-spin`}):null,`Create account`]})]}),(0,I.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[`Already have an account?`,` `,(0,I.jsx)(Pn,{to:Fx(xx,u),className:`text-primary-ink underline underline-offset-4`,children:`Sign in`})]})]})]}),n.data?.billing?(0,I.jsxs)(`p`,{className:`max-w-sm text-center text-xs text-balance text-muted-foreground`,children:[`By creating an account you agree to the`,` `,(0,I.jsx)(`a`,{href:`https://appaigateway.com/terms/`,target:`_blank`,rel:`noopener`,className:`underline underline-offset-4 hover:text-foreground`,children:`Terms of Service`}),` `,`and`,` `,(0,I.jsx)(`a`,{href:`https://appaigateway.com/privacy/`,target:`_blank`,rel:`noopener`,className:`underline underline-offset-4 hover:text-foreground`,children:`Privacy Policy`}),`.`]}):null]})}function Nk({googleAuth:e}){return(0,I.jsx)(ik,{children:(0,I.jsxs)(nE,{className:`w-full max-w-sm`,children:[(0,I.jsxs)(rE,{children:[(0,I.jsx)(`div`,{className:`mb-2 grid size-9 place-items-center rounded-md bg-muted text-muted-foreground`,children:(0,I.jsx)(Ta,{className:`size-4`})}),(0,I.jsx)(iE,{children:`Registration is closed`})]}),(0,I.jsxs)(oE,{className:`space-y-4`,children:[(0,I.jsxs)(Ds,{children:[(0,I.jsx)(Os,{children:`This gateway does not accept public sign-ups`}),(0,I.jsx)(ks,{children:`Sign in with an existing account. If this gateway was initialized from the CLI, finish its protected account claim from that CLI.`})]}),e?(0,I.jsx)(ak,{label:`Continue with Google`}):null,(0,I.jsx)(J,{asChild:!0,variant:`outline`,className:`w-full`,children:(0,I.jsx)(Pn,{to:`/login`,children:`Back to sign in`})})]})]})})}function Pk(){return(0,I.jsx)(`div`,{className:`flex h-dvh items-center justify-center`,children:(0,I.jsx)(wa,{className:`size-5 animate-spin text-muted-foreground`})})}function Fk(){let e=tS(),t=nS(),n=dt(),r=TS(!!e.data?.billing&&t.isSuccess),i=t.data?.user?.id,a=t.data?.user?.createdAt,o=t.data?.organization?.id??null,s=t.data?.role,c=r.data?.access.state===`billed`?r.data.access.plan?.planKey??null:null;return(0,v.useEffect)(()=>{!i||!a||!s||_x.identify(i,s,a)},[i,a,s]),(0,v.useEffect)(()=>{o&&_x.group(o,c===null?void 0:{plan:c})},[o,c]),t.isPending||e.isPending?(0,I.jsx)(Pk,{}):t.isError||!t.data?(0,I.jsx)(Vt,{to:Lx(`${n.pathname}${n.search}`),replace:!0}):e.data?(0,I.jsx)(ox,{session:t.data,capabilities:e.data,billing:r.data?.access,quota:r.data?.quota,children:(0,I.jsx)(nw,{children:(0,I.jsxs)(Wt,{children:[(0,I.jsx)(Ht,{path:`/`,element:(0,I.jsx)(Vt,{to:Cx,replace:!0})}),(0,I.jsx)(Ht,{path:`/apps`,element:(0,I.jsx)(UO,{})}),(0,I.jsx)(Ht,{path:`/apps/:appId`,element:(0,I.jsx)(Vt,{to:`overview`,replace:!0})}),(0,I.jsx)(Ht,{path:`/apps/:appId/:tab`,element:(0,I.jsx)(qD,{})}),(0,I.jsx)(Ht,{path:`/apps/:appId/:tab/:section`,element:(0,I.jsx)(qD,{})}),(0,I.jsx)(Ht,{path:`/providers`,element:(0,I.jsx)(_O,{})}),(0,I.jsx)(Ht,{path:`/providers/:section`,element:(0,I.jsx)(_O,{})}),(0,I.jsx)(Ht,{path:`/keys`,element:(0,I.jsx)(Ck,{})}),(0,I.jsx)(Ht,{path:`/settings`,element:(0,I.jsx)(Vt,{to:`/settings/${Ek}`,replace:!0})}),(0,I.jsx)(Ht,{path:`/settings/:section`,element:(0,I.jsx)(Dk,{})}),e.data.billing?(0,I.jsx)(Ht,{path:`/billing`,element:(0,I.jsx)(JO,{})}):null,(0,I.jsx)(Ht,{path:`/checkout`,element:(0,I.jsx)(ek,{})}),(0,I.jsx)(Ht,{path:`*`,element:(0,I.jsx)(Vt,{to:Cx,replace:!0})})]})})}):(0,I.jsx)(`div`,{className:`mx-auto max-w-lg px-4 py-16`,children:(0,I.jsxs)(Ds,{variant:`destructive`,children:[(0,I.jsx)(Os,{children:`Could not reach the gateway`}),(0,I.jsx)(ks,{children:`The console could not load deployment capabilities. Reload to try again.`})]})})}function Ik({children:e}){let t=nS(),n=dt();return t.isPending?(0,I.jsx)(Pk,{}):t.isSuccess&&t.data?(0,I.jsx)(Vt,{to:Ix(n.search),replace:!0}):(0,I.jsx)(I.Fragment,{children:e})}function Lk(){return bx(),(0,I.jsxs)(Db,{children:[(0,I.jsxs)(Wt,{children:[(0,I.jsx)(Ht,{path:`/login`,element:(0,I.jsx)(Ik,{children:(0,I.jsx)(Sk,{})})}),(0,I.jsx)(Ht,{path:`/signup`,element:(0,I.jsx)(Ik,{children:(0,I.jsx)(Mk,{})})}),(0,I.jsx)(Ht,{path:`/cli/approve/:id`,element:(0,I.jsx)(mk,{})}),(0,I.jsx)(Ht,{path:`*`,element:(0,I.jsx)(Fk,{})})]}),(0,I.jsx)(ac,{position:`top-center`})]})}function Rk(e){window.history.pushState({},``,e),window.dispatchEvent(new PopStateEvent(`popstate`))}function zk(){return{pathname:window.location.pathname,search:window.location.search}}function Bk(e={}){let t=e.redirectToLogin??Rk,n=e.currentPath??zk,r=e=>{if(fx(e)){i.invalidateQueries({queryKey:eS.billingStatus});return}if(!dx(e))return;i.setQueryData(eS.session,null);let{pathname:r,search:a}=n();Tx.has(r)||t(Lx(`${r}${a}`))},i=new oi({defaultOptions:{queries:{refetchOnWindowFocus:!1,staleTime:1e4,retry:(e,t)=>Ox(t)&&e<2}},queryCache:new ai({onError:r}),mutationCache:new ni({onError:r})});return i}var Vk=Bk();(0,b.createRoot)(document.getElementById(`root`)).render((0,I.jsx)(v.StrictMode,{children:(0,I.jsx)(di,{client:Vk,children:(0,I.jsx)(Pi,{attribute:`class`,defaultTheme:`system`,enableSystem:!0,children:(0,I.jsx)(Mn,{children:(0,I.jsx)(Lk,{})})})})}));export{fS as $,Rw as A,dC as B,sT as C,xT as D,ST as E,aw as F,gC as G,mC as H,rw as I,QS as J,bC as K,_C as L,sw as M,lw as N,gT as O,ow as P,_S as Q,xC as R,hT as S,aT as T,cC as U,fC as V,uC as W,WS as X,US as Y,qS as Z,BT as _,Q as a,Na as at,FT as b,uE as c,h as ct,rE as d,s as dt,HS as et,YT as f,l as ft,VT as g,UT as h,lE as i,Ga as it,uw as j,_T as k,nE as l,d as lt,HT as m,$ as n,H as nt,Z as o,Ni as ot,zT as p,vC as q,sE as r,Za as rt,cE as s,ci as st,jD as t,J as tt,oE as u,o as ut,NT as v,vT as w,eT as x,MT as y,lC as z};