cartethyia 2.5.2 → 2.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dashboard/assets/{BannedPage-MsQaeQTs.js → BannedPage-hfCzi-Ux.js} +1 -1
- package/dist/dashboard/assets/BannedPage-hfCzi-Ux.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolDetailPage-BO9nKg9w.js → CliToolDetailPage-DLGqYEwI.js} +1 -1
- package/dist/dashboard/assets/CliToolDetailPage-DLGqYEwI.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolsPage-DfWHTJ7v.js → CliToolsPage-DEDyKBlC.js} +1 -1
- package/dist/dashboard/assets/CliToolsPage-DEDyKBlC.js.gz +0 -0
- package/dist/dashboard/assets/{CombosPage-BrCBQDAc.js → CombosPage-CfuYiQ8Z.js} +1 -1
- package/dist/dashboard/assets/CombosPage-CfuYiQ8Z.js.gz +0 -0
- package/dist/dashboard/assets/{ConsoleLogPage-C6Uh33er.js → ConsoleLogPage-bsLuZmYH.js} +1 -1
- package/dist/dashboard/assets/ConsoleLogPage-bsLuZmYH.js.gz +0 -0
- package/dist/dashboard/assets/{CustomizationPage-8aS9hyJu.js → CustomizationPage-_UWhwziJ.js} +1 -1
- package/dist/dashboard/assets/CustomizationPage-_UWhwziJ.js.gz +0 -0
- package/dist/dashboard/assets/{HealthEventsModal-qomXThxX.js → HealthEventsModal-Cjfc5WFS.js} +1 -1
- package/dist/dashboard/assets/HealthEventsModal-Cjfc5WFS.js.gz +0 -0
- package/dist/dashboard/assets/{LoginPage-C8hKyXBe.js → LoginPage-DDVIfZGW.js} +1 -1
- package/dist/dashboard/assets/LoginPage-DDVIfZGW.js.gz +0 -0
- package/dist/dashboard/assets/{OverviewPage-C-ExCy1V.js → OverviewPage-B53YYMng.js} +1 -1
- package/dist/dashboard/assets/OverviewPage-B53YYMng.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-B0KaAQf0.js +3 -0
- package/dist/dashboard/assets/ProviderDetailPage-B0KaAQf0.js.gz +0 -0
- package/dist/dashboard/assets/{ProvidersPage-BS9IEpvv.js → ProvidersPage-Dx31DgIO.js} +1 -1
- package/dist/dashboard/assets/ProvidersPage-Dx31DgIO.js.gz +0 -0
- package/dist/dashboard/assets/{ProxyPage-Rn_qXScb.js → ProxyPage-BpnR4kXT.js} +1 -1
- package/dist/dashboard/assets/ProxyPage-BpnR4kXT.js.gz +0 -0
- package/dist/dashboard/assets/{QuotaPage-BihkgQSq.js → QuotaPage-BpOQCnun.js} +1 -1
- package/dist/dashboard/assets/QuotaPage-BpOQCnun.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-DV1eo2J_.js +1 -0
- package/dist/dashboard/assets/SettingsPage-DV1eo2J_.js.gz +0 -0
- package/dist/dashboard/assets/{SetupPage-CXjUlfqr.js → SetupPage-D6pmQ86L.js} +1 -1
- package/dist/dashboard/assets/SetupPage-D6pmQ86L.js.gz +0 -0
- package/dist/dashboard/assets/{SortableList-C-_oD3F2.js → SortableList-DWvKiuSl.js} +1 -1
- package/dist/dashboard/assets/SortableList-DWvKiuSl.js.gz +0 -0
- package/dist/dashboard/assets/{StudioPage-u9IxmYOI.js → StudioPage-CmkUrgdj.js} +1 -1
- package/dist/dashboard/assets/StudioPage-CmkUrgdj.js.gz +0 -0
- package/dist/dashboard/assets/{UsagePage-BEVLVrwP.js → UsagePage-B47uOydr.js} +1 -1
- package/dist/dashboard/assets/UsagePage-B47uOydr.js.gz +0 -0
- package/dist/dashboard/assets/{entry-Dj9AR0gY.js → entry-CkryrIea.js} +3 -3
- package/dist/dashboard/assets/entry-CkryrIea.js.gz +0 -0
- package/dist/dashboard/assets/{index-DCBtROoK.js → index-BydyKaDz.js} +2 -2
- package/dist/dashboard/assets/index-BydyKaDz.js.gz +0 -0
- package/dist/dashboard/assets/{select-DsX5QT8K.js → select-BO6h8yNv.js} +1 -1
- package/dist/dashboard/assets/select-BO6h8yNv.js.gz +0 -0
- package/dist/dashboard/index.html +1 -1
- package/dist/dashboard/index.html.gz +0 -0
- package/dist/dashboard/precompressed-assets.json +21 -21
- package/package.json +1 -1
- package/scripts/cli/command/console-menu.ts +248 -246
- package/scripts/cli/command/tray.ts +208 -204
- package/src/config/spec.ts +26 -2
- package/src/console/backup/routes.ts +52 -1
- package/src/console/backup/service.ts +60 -4
- package/src/console/share/share-router.ts +6 -9
- package/src/observability/payload-capture.ts +366 -344
- package/src/observability/payload-store.ts +12 -2
- package/src/observability/telemetry-status.ts +28 -16
- package/src/persistence/stores/api-key-store.ts +6 -0
- package/src/persistence/stores/share-store.ts +583 -556
- package/src/persistence/stores/telemetry-store.ts +1 -1
- package/src/protocol/response/gemini.ts +18 -4
- package/src/providers/integrations/antigravity/antigravity-quota.ts +11 -3
- package/src/providers/integrations/buddy/buddy-catalog-shared.ts +4 -4
- package/src/providers/integrations/buddy/workbuddy/shared.ts +201 -200
- package/src/providers/integrations/cline/cline-quota.ts +8 -11
- package/src/providers/integrations/opencode/provider.ts +532 -532
- package/src/providers/integrations/tokenharbor.ts +2 -2
- package/src/providers/integrations/trae/trae-catalog.ts +5 -3
- package/src/providers/operations/account-health-service.ts +23 -0
- package/src/providers/operations/client-versions.ts +9 -2
- package/src/providers/provider-metadata.ts +7 -1
- package/src/transport/dispatch/attempt-finalize.ts +46 -5
- package/src/transport/dispatch/proxy-request.ts +9 -0
- package/src/transport/dispatch/streaming/stream.ts +16 -2
- package/src/transport/routing/route-catalog.ts +806 -799
- package/dist/dashboard/assets/BannedPage-MsQaeQTs.js.gz +0 -0
- package/dist/dashboard/assets/CliToolDetailPage-BO9nKg9w.js.gz +0 -0
- package/dist/dashboard/assets/CliToolsPage-DfWHTJ7v.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-BrCBQDAc.js.gz +0 -0
- package/dist/dashboard/assets/ConsoleLogPage-C6Uh33er.js.gz +0 -0
- package/dist/dashboard/assets/CustomizationPage-8aS9hyJu.js.gz +0 -0
- package/dist/dashboard/assets/HealthEventsModal-qomXThxX.js.gz +0 -0
- package/dist/dashboard/assets/LoginPage-C8hKyXBe.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-C-ExCy1V.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-tr811uaF.js +0 -3
- package/dist/dashboard/assets/ProviderDetailPage-tr811uaF.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-BS9IEpvv.js.gz +0 -0
- package/dist/dashboard/assets/ProxyPage-Rn_qXScb.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-BihkgQSq.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-DhiEjm6T.js +0 -1
- package/dist/dashboard/assets/SettingsPage-DhiEjm6T.js.gz +0 -0
- package/dist/dashboard/assets/SetupPage-CXjUlfqr.js.gz +0 -0
- package/dist/dashboard/assets/SortableList-C-_oD3F2.js.gz +0 -0
- package/dist/dashboard/assets/StudioPage-u9IxmYOI.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-BEVLVrwP.js.gz +0 -0
- package/dist/dashboard/assets/entry-Dj9AR0gY.js.gz +0 -0
- package/dist/dashboard/assets/index-DCBtROoK.js.gz +0 -0
- package/dist/dashboard/assets/select-DsX5QT8K.js.gz +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e,r as t,t as n}from"./jsx-runtime-CXUMngI_.js";import{d as r,l as i}from"./numbers-Bs4LOOuf.js";import{t as a}from"./eye-off-Bk5g2luF.js";import{t as o}from"./eye-C_hawfH4.js";import{n as s,r as c,t as l}from"./state-DYdQmdAl.js";import{t as u}from"./dialog-BtpsJU98.js";import{t as d}from"./plus-DIdX_g-x.js";import{t as f}from"./trash-Cppn5c3R.js";import{l as p}from"./query-keys-D7wX2vM5.js";import{t as m}from"./dialog-actions-B1axpEg7.js";import{C as ee,Z as h,_ as g,a as _,et as v,g as y,i as te,m as b,rt as x,s as S,st as C,w}from"./entry-Dj9AR0gY.js";import{n as T,r as E,t as D}from"./card--AtFedAq.js";import{t as O}from"./badge-6uzDDvqs.js";import{n as k}from"./input-BG41et9G.js";import{t as A}from"./select-DsX5QT8K.js";import{t as j}from"./ProviderIcon-CmfzxpVM.js";import{t as M}from"./switch-CidSfbG7.js";import{t as N}from"./stack-DwLmjUFK.js";import{n as P}from"./inline-BcNGF8Gr.js";import{t as F}from"./list-row-Gh_W4OR_.js";import{t as I}from"./privacy-mode-GM8bej85.js";import{t as L}from"./AccountCooldown-Bjo92Qat.js";var R=e(t(),1),z=n();function ne(e){let t={};for(let[n,r]of e)n.trim()&&(t[n.trim()]=r);return t}function re({pairs:e,onChange:t}){let n=(n,r)=>t(e.map((e,t)=>t===n?r:e)),r=n=>t(e.filter((e,t)=>t!==n));return(0,z.jsxs)(`div`,{className:`form-group`,children:[(0,z.jsxs)(`label`,{className:`form-label block`,children:[(0,z.jsx)(`span`,{className:`block`,children:`Custom Headers`}),(0,z.jsx)(`span`,{className:`form-hint block mt-1`,children:`Optional — sent with every request, override built-in headers on a name collision`})]}),(0,z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[e.map(([e,t],a)=>(0,z.jsxs)(`div`,{className:`flex min-w-0 gap-3`,children:[(0,z.jsx)(k,{placeholder:`Header-Name`,value:e,onChange:e=>n(a,[e.target.value,t]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,z.jsx)(k,{placeholder:`value`,value:t,onChange:t=>n(a,[e,t.target.value]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,z.jsx)(i,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Remove ${e||`header`}`,onClick:()=>r(a),children:(0,z.jsx)(f,{size:13})})]},a)),(0,z.jsxs)(i,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>t([...e,[``,``]]),children:[(0,z.jsx)(d,{size:13}),` Add header`]})]})]})}function B({children:e}){return(0,z.jsx)(`div`,{className:`provider-grid grid gap-6 w-full min-w-0`,children:e})}var V=r(`relative flex flex-col min-w-0 border border-inner-border rounded-card`,`transition-[transform,border-color,box-shadow]`),H=r(`block flex-1 p-6 no-underline text-inherit`),U=r(`text-body font-semibold overflow-hidden text-ellipsis whitespace-nowrap`);function W(e){let t=e.serviceKinds;return Array.isArray(t)&&t.length>0?t:[`llm`]}var G=/\/(?:v\d+\/)?(?:messages|chat\/completions|responses|completions|embeddings|images\/generations)$/;function ie(e){let t=e.trim().replace(/\/+$/,``);if(t===``)return null;let n,r;try{n=new URL(t),r=n.pathname.replace(/\/+$/,``)}catch{return null}return G.test(r)?n.origin:null}function K({variant:e,open:t,onClose:n}){let a=te(),o=_(),s=ee(),c=w(),[l,d]=(0,R.useState)(``),[f,m]=(0,R.useState)(``),[h,g]=(0,R.useState)(``),[v,y]=(0,R.useState)(``),[b,x]=(0,R.useState)(!1),[S,C]=(0,R.useState)(!0),[T,E]=(0,R.useState)([]),[D,O]=(0,R.useState)(null),[j,N]=(0,R.useState)(!1),[I,L]=(0,R.useState)(null),[B,V]=(0,R.useState)(!1),H=e===`anthropic-compatible`,U=H?`messages`:`chat`,[W,G]=(0,R.useState)(U),K=(0,R.useMemo)(()=>ie(h),[h]);(0,R.useEffect)(()=>{t&&(d(``),y(``),G(U),g(``),x(!1),C(!0),E([]),O(null),L(null))},[t]);let q=async e=>{try{let t=await navigator.clipboard.readText();t.trim()&&e(t.trim())}catch{O(`Clipboard access denied — paste manually instead.`)}},ae=async()=>{if(!h.trim()){L({ok:!1,message:`Base URL is required to test the connection.`});return}V(!0),L(null),O(null);try{let e=ne(T),t=await c.mutateAsync({baseUrl:h.trim(),apiKey:v.trim(),wireFamily:W,cliIdentity:S,...Object.keys(e).length>0?{extraHeaders:e}:{}});if(t.ok){let e=typeof t.modelCount==`number`?` — upstream advertised ${t.modelCount} model(s)`:``;L({ok:!0,message:`Connected successfully (${t.latencyMs}ms)${e}.`,...t.warning===void 0?{}:{warning:t.warning}})}else L({ok:!1,message:t.error??`Connection failed.`,...t.warning===void 0?{}:{warning:t.warning}})}catch(e){L({ok:!1,message:p(e,`Connection test failed`)})}finally{V(!1)}};return(0,z.jsx)(u,{open:t,onClose:n,title:H?`Add Custom Anthropic Provider`:`Add Custom OpenAI Provider`,footer:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(i,{variant:`secondary`,type:`button`,onClick:n,children:`Cancel`}),(0,z.jsx)(i,{variant:`primary`,type:`submit`,form:`add-compatible-provider`,disabled:j,children:j?`Creating...`:`Add Provider`})]}),children:(0,z.jsxs)(`form`,{id:`add-compatible-provider`,onSubmit:async e=>{if(e.preventDefault(),!l.trim()){O(`Display Name is required`);return}if(!f.trim()){O(`Provider ID (slug) is required`);return}if(!h.trim()){O(`Base URL is required`);return}let t=ne(T),r=f.trim().toLowerCase();N(!0),O(null);try{let e={providerId:r,label:l.trim(),baseUrl:h.trim(),wireFamily:W,compatibilityProfile:{cli_identity:S,...Object.keys(t).length>0?{extra_headers:t}:{}}};await a.mutateAsync(e),v.trim()&&await o.mutateAsync({providerId:r,request:{credentialKind:`api_key`,secret:v.trim()}}),b&&await s.mutateAsync(r),n()}catch(e){O(p(e,`Failed to create provider`))}finally{N(!1)}},className:`flex flex-col gap-6`,children:[D?(0,z.jsx)(`div`,{className:`text-red text-caption`,children:D}):null,(0,z.jsx)(k,{label:`Display Name`,hint:`Required. A friendly label for this node.`,id:`compat-label`,value:l,onChange:e=>d(e.target.value),placeholder:H?`Anthropic Compatible (Prod)`:`OpenAI Compatible (Prod)`,required:!0}),(0,z.jsx)(k,{label:`Provider ID / Slug`,hint:`Required. Used as the provider prefix for model IDs.`,id:`compat-slug`,value:f,onChange:e=>m(e.target.value),placeholder:H?`ac-prod`:`oc-prod`,required:!0}),(0,z.jsxs)(`div`,{className:`form-group`,children:[(0,z.jsxs)(`label`,{className:`form-label`,htmlFor:`compat-url`,children:[(0,z.jsx)(`span`,{children:`Base URL`}),(0,z.jsxs)(`span`,{className:`form-hint`,children:[`The root only. Do not paste the full endpoint — leave off`,H?" `/v1/messages`.":" `/chat/completions`."]})]}),(0,z.jsxs)(P,{gap:`8px`,children:[(0,z.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,z.jsx)(k,{id:`compat-url`,value:h,onChange:e=>g(e.target.value),placeholder:H?`https://api.anthropic.com/v1`:`https://api.openai.com/v1`,required:!0})}),(0,z.jsx)(i,{type:`button`,variant:`secondary`,onClick:()=>q(g),children:`Paste`})]}),K===null?null:(0,z.jsxs)(`p`,{className:`mt-1.5 text-caption text-orange`,children:[`That looks like a full endpoint. Use`,` `,(0,z.jsx)(`code`,{className:`font-mono`,children:K}),` instead — Cartethyia appends the endpoint path itself.`]})]}),H?null:(0,z.jsx)(A,{id:`compat-wire`,label:`API format`,value:W,onValueChange:e=>G(e),options:[{value:`chat`,label:`Chat completions`},{value:`responses`,label:`Responses`}]}),(0,z.jsxs)(`div`,{className:`form-group`,children:[(0,z.jsxs)(`label`,{className:`form-label`,htmlFor:`compat-credential`,children:[(0,z.jsx)(`span`,{children:`API Key`}),(0,z.jsx)(`span`,{className:`form-hint`,children:`Optional — saved with this provider and used to authenticate every request.`})]}),(0,z.jsxs)(P,{gap:`8px`,children:[(0,z.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,z.jsx)(k,{id:`compat-credential`,type:`password`,placeholder:`sk-...`,value:v,onChange:e=>y(e.target.value)})}),(0,z.jsx)(i,{type:`button`,variant:`secondary`,disabled:B,onClick:()=>void ae(),children:B?`Testing...`:`Test connection`}),(0,z.jsx)(i,{type:`button`,variant:`secondary`,onClick:()=>q(y),children:`Paste`})]}),I?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:r(`mt-3 text-caption leading-[1.4] break-words`,I.ok?`text-green`:`text-red`),children:[I.ok?`✓ `:`✗ `,I.message]}),I.warning?(0,z.jsxs)(`div`,{className:`mt-2 text-caption leading-snug break-words text-orange`,children:[`⚠ `,I.warning]}):null]}):null]}),(0,z.jsx)(F,{actions:(0,z.jsx)(M,{checked:b,onChange:x,id:`compat-autofetch`}),children:(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-body font-semibold`,children:`Auto-fetch models`}),(0,z.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Discover this provider's model list automatically after creation`})]})}),(0,z.jsx)(F,{actions:(0,z.jsx)(M,{checked:S,onChange:C,id:`compat-cli-identity`}),children:(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-body font-semibold`,children:H?`Send request as Claude CLI`:`Send request as Codex CLI`}),(0,z.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:H?`Emits official Claude CLI User-Agent and Stainless headers to upstream`:`Emits official codex_cli_rs User-Agent and originator headers to upstream`})]})}),(0,z.jsx)(re,{pairs:T,onChange:E})]})})}function q({customProvider:e}){let t=S(),[n,a]=(0,R.useState)(!1),o=y(e.providerId),s=o.data?.length,c=b(e.providerId),l=c.data,d=Q(l??[]);return(0,z.jsxs)(D,{className:V,children:[(0,z.jsx)(ce,{clientVersion:e.clientVersion}),(0,z.jsx)(h,{to:`/providers/${encodeURIComponent(e.providerId)}`,className:r(H,`pr-20 min-h-38`),children:(0,z.jsxs)(P,{gap:`10px`,children:[(0,z.jsx)(j,{icon:e.wireFamilyDefault===`messages`?`anthropic`:`openai`,name:e.label||e.providerId,size:32,imageSize:24}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`div`,{className:U,children:e.label||e.providerId}),e.baseUrl?(0,z.jsxs)(`div`,{className:`mt-1 min-w-0 truncate font-mono text-micro text-text-tertiary`,title:e.baseUrl,children:[(0,z.jsx)(`span`,{className:`font-semibold text-text-secondary`,children:`Base URL`}),` `,e.baseUrl]}):null,(0,z.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2`,children:[l===void 0?(0,z.jsx)($,{kind:`accounts`,isPending:c.isPending,isError:c.isError,hasData:!1}):l.length===0?e.requiresAccount===!1?(0,z.jsx)(O,{tone:`ok`,children:`Free Endpoint`}):(0,z.jsx)(O,{children:`No connections`}):(0,z.jsx)(se,{counts:d,total:l.length}),c.isError&&l!==void 0?(0,z.jsx)(O,{tone:`warn`,children:`Connections unavailable`}):null]})]}),(0,z.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5 shrink-0`,children:[(0,z.jsxs)(`span`,{className:`font-mono tabular-nums text-micro font-semibold bg-kbd-bg px-2.5 py-0.5 rounded-chip text-text-secondary`,children:[e.providerId,`/`]}),s!==void 0&&s>0?(0,z.jsxs)(O,{tone:`info`,children:[s,` models`]}):null,o.isError?(0,z.jsx)(O,{tone:`warn`,children:`Models unavailable`}):s===void 0?(0,z.jsx)($,{kind:`models`,isPending:o.isPending,isError:!1,hasData:!1}):s===0?(0,z.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})}),(0,z.jsx)(i,{variant:`ghost`,size:`sm`,icon:(0,z.jsx)(f,{size:12}),onClick:()=>a(!0),className:`absolute top-2 right-2 p-2 text-text-tertiary`,title:`Delete ${e.label||e.providerId}`}),(0,z.jsx)(u,{open:n,onClose:()=>a(!1),title:`Delete Custom Provider`,children:(0,z.jsxs)(N,{gap:`12px`,children:[(0,z.jsxs)(`p`,{className:`text-body text-text-secondary`,children:[`Are you sure you want to delete custom provider`,` `,(0,z.jsx)(`strong`,{children:e.label||e.providerId}),`? Its models, accounts, and routing preferences are deleted together, and requests to this provider will no longer route.`]}),t.isError?(0,z.jsx)(`p`,{className:`text-caption text-red`,children:p(t.error,`Delete failed`)}):null,(0,z.jsxs)(m,{children:[(0,z.jsx)(i,{variant:`secondary`,onClick:()=>a(!1),children:`Cancel`}),(0,z.jsx)(i,{variant:`danger`,onClick:()=>{t.mutate(e.providerId,{onSuccess:()=>a(!1),onError:()=>void 0})},disabled:t.isPending,children:t.isPending?`Deleting...`:`Delete Provider`})]})]})})]})}function ae({customProviders:e}){let[t,n]=(0,R.useState)(!1),[r,s]=(0,R.useState)(!1),[c,l]=(0,R.useState)(()=>{try{return window.localStorage.getItem(`cartethyia.customProvidersHidden`)===`1`}catch{return!1}});function u(){l(e=>{let t=!e;try{window.localStorage.setItem(`cartethyia.customProvidersHidden`,t?`1`:`0`)}catch{}return t})}return(0,z.jsxs)(`section`,{className:`flex flex-col gap-5`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-4`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:u,"aria-expanded":!c,title:c?`Show custom providers`:`Hide custom providers`,className:`inline-flex items-center gap-3 bg-transparent border-none p-0 cursor-pointer text-inherit`,children:[(0,z.jsxs)(`h2`,{className:`text-body-lg font-bold tracking-[-0.01em]`,children:[`Custom Providers`,e.length>0?` (${e.length})`:``]}),(0,z.jsx)(C,{size:14,className:`text-text-tertiary transition-transform`,style:{transform:c?`rotate(-90deg)`:void 0}})]}),(0,z.jsxs)(P,{gap:`8px`,children:[(0,z.jsx)(i,{size:`sm`,variant:`ghost`,icon:c?(0,z.jsx)(o,{size:13}):(0,z.jsx)(a,{size:13}),onClick:u,title:c?`Show custom providers`:`Hide custom providers`,children:c?`Show`:`Hide`}),(0,z.jsx)(i,{size:`sm`,variant:`secondary`,icon:(0,z.jsx)(d,{size:13}),onClick:()=>n(!0),children:`Custom Anthropic`}),(0,z.jsx)(i,{size:`sm`,variant:`secondary`,icon:(0,z.jsx)(d,{size:13}),onClick:()=>s(!0),children:`Custom OpenAI`})]})]}),c?null:e.length===0?(0,z.jsx)(D,{children:(0,z.jsxs)(T,{className:`text-center px-7 py-10 border border-dashed border-inner-border rounded-card`,children:[(0,z.jsx)(`p`,{className:`text-body font-semibold text-text-primary`,children:`No custom providers yet`}),(0,z.jsx)(`p`,{className:`text-badge text-text-tertiary mt-1`,children:`Add an OpenAI- or Anthropic-compatible endpoint with the buttons above.`})]})}):(0,z.jsx)(B,{children:e.map(e=>(0,z.jsx)(q,{customProvider:e},e.providerId))}),(0,z.jsx)(K,{variant:`anthropic-compatible`,open:t,onClose:()=>n(!1)}),(0,z.jsx)(K,{variant:`openai-compatible`,open:r,onClose:()=>s(!1)})]})}var J=new Set([`inferhub`]),Y=new Set([`grok`,`opencode`,`cline`,`hermes`,`kilo`]),oe=new Set([`anthropic`,`openai`,`gemini`,`alibabacp`,`ollamacloud`,`opencode-zen`,`opencode-go`,`mistral`,`meta`,`deepseek`,`commandcode`,`dashscope`]);function X(e){return e.oauthFlows?.browser===!0||e.oauthFlows?.device===!0}function Z(e){return e.oauthFlows?.refreshable===!0}function Q(e){let t=e=>e.status===`cooldown`||L(e)!==void 0;return{healthy:e.filter(e=>e.status===`active`&&!t(e)).length,throttled:e.filter(t).length,disabled:e.filter(e=>e.status===`disabled`).length,cooling:e.filter(e=>e.status!==`cooldown`&&L(e)!==void 0).length}}function se({counts:e,total:t}){if(!(e.healthy>0||e.throttled>0||e.disabled>0))return(0,z.jsxs)(O,{tone:`warn`,dot:!0,children:[t,` Connected`]});let n=e.throttled===e.cooling?`Cooling`:`Cooldown`;return(0,z.jsxs)(z.Fragment,{children:[e.healthy>0?(0,z.jsxs)(O,{tone:`ok`,dot:!0,children:[e.healthy,` Healthy`]}):null,e.throttled>0?(0,z.jsxs)(O,{tone:`warn`,dot:!0,children:[e.throttled,` `,n]}):null,e.disabled>0?(0,z.jsxs)(O,{tone:`warn`,dot:!0,children:[e.disabled,` Unhealthy`]}):null]})}function $({kind:e,isPending:t,isError:n,hasData:r,isEmpty:i=!1}){let a=e===`models`?`Models`:`Connections`;return n?(0,z.jsxs)(O,{tone:`warn`,children:[a,` unavailable`]}):t&&!r?(0,z.jsxs)(O,{tone:`info`,children:[`Loading `,a.toLowerCase(),`…`]}):i?(0,z.jsx)(O,{children:e===`models`?`No models`:`No connections`}):null}function ce({clientVersion:e}){return e?(0,z.jsxs)(O,{className:`provider-version-badge absolute -top-4.5 left-5 right-auto z-chip max-w-[calc(100%-var(--spacing)*10)] truncate px-3 py-1 text-micro leading-[1.15] shadow-card max-small:left-4 max-small:max-w-[calc(100%-var(--spacing)*8)]`,tone:e.source===`latest`?`teal`:`default`,title:e.source===`latest`?`Latest discovered client version`:`Pinned fallback; background discovery has not succeeded yet`,children:[`v`,e.version,` · `,e.source]}):null}var le=(0,R.memo)(function({provider:e,serviceKind:t}){let n=J.has(e.providerId.toLowerCase()),i=e.label||e.displayName,a=y(e.providerId),o=a.data?.filter(e=>t===void 0||e.serviceKind===t||t===`llm`&&e.serviceKind===void 0).length,s=b(e.providerId),c=s.data,l=Q(c??[]);return(0,z.jsxs)(D,{className:V,children:[(0,z.jsx)(ce,{clientVersion:e.clientVersion}),n?(0,z.jsx)(`span`,{"aria-label":`Friend sponsor`,title:`Friend sponsor`,className:`absolute top-0 right-0 z-2 w-36 h-36 overflow-hidden pointer-events-none`,children:(0,z.jsx)(`span`,{className:r(`absolute top-9 -right-11 w-38 py-1 rotate-45 bg-accent-soft`,`text-accent text-micro font-extrabold tracking-tight leading-[1.05]`,`text-center uppercase shadow-ribbon`),children:`Friend`})}):null,(0,z.jsx)(h,{to:`/providers/${encodeURIComponent(e.providerId)}${t===void 0?``:`?service=${t}`}`,className:H,children:(0,z.jsxs)(P,{gap:`10px`,children:[(0,z.jsx)(j,{icon:e.providerId,name:i,size:32,imageSize:24}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`div`,{className:U,children:i}),(0,z.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2`,children:[c===void 0?(0,z.jsx)($,{kind:`accounts`,isPending:s.isPending,isError:s.isError,hasData:!1}):c.length===0?e.requiresAccount===!1?(0,z.jsx)(O,{tone:`ok`,children:`Free Endpoint`}):(0,z.jsx)(O,{children:`No connections`}):(0,z.jsx)(se,{counts:l,total:c.length}),s.isError&&c!==void 0?(0,z.jsx)(O,{tone:`warn`,children:`Connections unavailable`}):null]})]}),(0,z.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5 shrink-0`,children:[(0,z.jsxs)(`span`,{className:`font-mono tabular-nums text-micro font-semibold bg-kbd-bg px-2.5 py-0.5 rounded-chip text-text-secondary`,children:[e.providerId,`/`]}),o!==void 0&&o>0?(0,z.jsxs)(O,{tone:`info`,children:[o,` models`]}):null,a.isError?(0,z.jsx)(O,{tone:`warn`,children:`Models unavailable`}):o===void 0?(0,z.jsx)($,{kind:`models`,isPending:a.isPending,isError:!1,hasData:!1}):o===0?(0,z.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})})]})});function ue(e,t){let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n}var de=`cartethyia.providerSectionsCollapsed`;function fe(){try{let e=window.localStorage.getItem(de),t=e?JSON.parse(e):[];return new Set(Array.isArray(t)?t.filter(e=>typeof e==`string`):[])}catch{return new Set}}var pe=[{title:`Founding Friend & Sponsors`,subtitle:`Super Cheap inference pool`,filter:e=>J.has(e.providerId.toLowerCase())},{title:`Free Limited Providers`,filter:e=>Y.has(e.providerId.toLowerCase())},{title:`OAuth & Agent Providers`,filter:e=>(X(e)||Z(e))&&!Y.has(e.providerId.toLowerCase())},{title:`Well Known API Key Providers`,subtitle:`The household names — sign up with a key and go`,filter:e=>e.isBuiltIn&&oe.has(e.providerId.toLowerCase())&&!J.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X(e)&&!Z(e)},{title:`Other API Key Providers`,subtitle:`Free tier friendly — no credit card`,filter:e=>e.isBuiltIn&&!oe.has(e.providerId.toLowerCase())&&!J.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X(e)&&!Z(e)}];function me(){let[e,t]=(0,R.useState)(fe),n=g(),u=I(),d=u.enabled,f=e=>!d||e.configured===!0||e.requiresAccount===!1,m=(0,R.useMemo)(()=>n.data??[],[n.data]),ee=(0,R.useMemo)(()=>[...m.filter(e=>!e.isBuiltIn&&f(e))].sort(ue),[m,d]),h=(0,R.useMemo)(()=>m.filter(e=>W(e).includes(`websearch`)&&f(e)),[m,d]),_=(0,R.useMemo)(()=>m.filter(e=>W(e).includes(`llm`)&&f(e)),[m,d]),[y,te]=v(),b=y.get(`tab`),S=b===`search`||b===`media`?b:`llm`,w=e=>{te(t=>{let n=new URLSearchParams(t);return e===`llm`?n.delete(`tab`):n.set(`tab`,e),n})},O=(0,R.useMemo)(()=>m.filter(e=>(W(e).includes(`imageGeneration`)||W(e).includes(`videoGeneration`))&&f(e)),[m,d]),k=(0,R.useMemo)(()=>[...h].sort((e,t)=>(e.label||e.displayName).localeCompare(t.label||t.displayName)),[h]),A=(e,t)=>{let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n},j=(0,R.useMemo)(()=>{if(S===`media`)return[{title:`Media Generation`,subtitle:`Providers that can return an image or a video`,providers:O}].filter(e=>e.providers.length>0);if(S===`search`)return[{title:`Search Providers`,subtitle:`Providers that can answer a web search request`,providers:k}].filter(e=>e.providers.length>0);let e=_;return pe.map(t=>({...t,providers:e.filter(t.filter).sort(A)})).filter(e=>e.providers.length>0)},[_,k,O,S]),M=n.isPending&&!n.data?(0,z.jsx)(c,{label:`Loading providers...`}):n.isError?(0,z.jsx)(s,{message:p(n.error,`Failed to load providers`),onRetry:()=>n.refetch()}):null;return M?(0,z.jsxs)(D,{children:[(0,z.jsx)(E,{title:`Providers`,icon:(0,z.jsx)(x,{size:16})}),(0,z.jsx)(T,{className:`flex flex-1`,children:M})]}):(0,z.jsx)(N,{gap:`24px`,children:(0,z.jsxs)(D,{children:[(0,z.jsx)(E,{title:`Providers`,subtitle:`Connected pinned first · A–Z`,icon:(0,z.jsx)(x,{size:16})}),(0,z.jsxs)(T,{className:`flex flex-col gap-8`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,z.jsx)(`div`,{className:`flex gap-2`,children:[`llm`,`search`,`media`].map(e=>(0,z.jsxs)(`button`,{onClick:()=>w(e),className:r(`px-6 py-3 rounded-inset text-caption font-semibold border cursor-pointer`,S===e?`border-accent bg-accent-soft text-accent`:`border-inner-border bg-surface-1 text-text-secondary`),children:[e===`llm`?`LLM`:e===`search`?`Search`:`Media`,e===`search`?` (${h.length})`:e===`media`?` (${O.length})`:` (${_.length})`]},e))}),(0,z.jsx)(i,{variant:`ghost`,size:`sm`,icon:d?(0,z.jsx)(a,{size:12}):(0,z.jsx)(o,{size:12}),onClick:()=>u.setEnabled(!d),title:d?`Show providers that have no account yet`:`Hide providers that have no account yet`,children:d?`Show unconfigured`:`Hide unconfigured`}),(0,z.jsx)(`span`,{className:`ml-auto text-micro text-text-tertiary`,children:S===`search`?`Fallback runs only when the model invokes Websearch`:S===`media`?`Image and video generation`:`Connected pinned first · A–Z`})]}),S===`llm`?(0,z.jsx)(ae,{customProviders:ee}):null,j.length===0?(0,z.jsx)(D,{children:(0,z.jsx)(T,{children:(0,z.jsx)(l,{title:`No providers found`,message:`No providers available.`})})}):j.map(n=>{let i=e.has(n.title);return(0,z.jsxs)(`section`,{className:`flex flex-col gap-6`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`flex items-start gap-4 border-0 bg-transparent p-0 text-left text-inherit`,"aria-expanded":!i,onClick:()=>t(e=>{let t=new Set(e);t.has(n.title)?t.delete(n.title):t.add(n.title);try{window.localStorage.setItem(de,JSON.stringify([...t]))}catch{}return t}),children:[(0,z.jsx)(C,{size:15,className:r(`mt-1 shrink-0 transition-transform`,i&&`-rotate-90`)}),(0,z.jsxs)(N,{gap:`1px`,children:[(0,z.jsxs)(`h2`,{className:`text-body font-bold tracking-[-0.01em]`,children:[n.title,` (`,n.providers.length,`)`,i?` (Hidden)`:``]}),!i&&n.subtitle?(0,z.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:n.subtitle}):null]})]}),i?null:(0,z.jsx)(B,{children:n.providers.map(e=>(0,z.jsx)(le,{provider:e,serviceKind:S===`search`?`websearch`:S===`media`?W(e).includes(`imageGeneration`)?`imageGeneration`:`videoGeneration`:`llm`},e.providerId))})]},n.title)})]})]})})}export{me as default,Q as summarizeAccounts};
|
|
1
|
+
import{o as e,r as t,t as n}from"./jsx-runtime-CXUMngI_.js";import{d as r,l as i}from"./numbers-Bs4LOOuf.js";import{t as a}from"./eye-off-Bk5g2luF.js";import{t as o}from"./eye-C_hawfH4.js";import{n as s,r as c,t as l}from"./state-DYdQmdAl.js";import{t as u}from"./dialog-BtpsJU98.js";import{t as d}from"./plus-DIdX_g-x.js";import{t as f}from"./trash-Cppn5c3R.js";import{l as p}from"./query-keys-D7wX2vM5.js";import{t as m}from"./dialog-actions-B1axpEg7.js";import{C as ee,Z as h,_ as g,a as _,et as v,g as y,i as te,m as b,rt as x,s as S,st as C,w}from"./entry-CkryrIea.js";import{n as T,r as E,t as D}from"./card--AtFedAq.js";import{t as O}from"./badge-6uzDDvqs.js";import{n as k}from"./input-BG41et9G.js";import{t as A}from"./select-BO6h8yNv.js";import{t as j}from"./ProviderIcon-CmfzxpVM.js";import{t as M}from"./switch-CidSfbG7.js";import{t as N}from"./stack-DwLmjUFK.js";import{n as P}from"./inline-BcNGF8Gr.js";import{t as F}from"./list-row-Gh_W4OR_.js";import{t as I}from"./privacy-mode-GM8bej85.js";import{t as L}from"./AccountCooldown-Bjo92Qat.js";var R=e(t(),1),z=n();function ne(e){let t={};for(let[n,r]of e)n.trim()&&(t[n.trim()]=r);return t}function re({pairs:e,onChange:t}){let n=(n,r)=>t(e.map((e,t)=>t===n?r:e)),r=n=>t(e.filter((e,t)=>t!==n));return(0,z.jsxs)(`div`,{className:`form-group`,children:[(0,z.jsxs)(`label`,{className:`form-label block`,children:[(0,z.jsx)(`span`,{className:`block`,children:`Custom Headers`}),(0,z.jsx)(`span`,{className:`form-hint block mt-1`,children:`Optional — sent with every request, override built-in headers on a name collision`})]}),(0,z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[e.map(([e,t],a)=>(0,z.jsxs)(`div`,{className:`flex min-w-0 gap-3`,children:[(0,z.jsx)(k,{placeholder:`Header-Name`,value:e,onChange:e=>n(a,[e.target.value,t]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,z.jsx)(k,{placeholder:`value`,value:t,onChange:t=>n(a,[e,t.target.value]),className:`font-mono tabular-nums min-w-0 flex-1 text-caption`}),(0,z.jsx)(i,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Remove ${e||`header`}`,onClick:()=>r(a),children:(0,z.jsx)(f,{size:13})})]},a)),(0,z.jsxs)(i,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>t([...e,[``,``]]),children:[(0,z.jsx)(d,{size:13}),` Add header`]})]})]})}function B({children:e}){return(0,z.jsx)(`div`,{className:`provider-grid grid gap-6 w-full min-w-0`,children:e})}var V=r(`relative flex flex-col min-w-0 border border-inner-border rounded-card`,`transition-[transform,border-color,box-shadow]`),H=r(`block flex-1 p-6 no-underline text-inherit`),U=r(`text-body font-semibold overflow-hidden text-ellipsis whitespace-nowrap`);function W(e){let t=e.serviceKinds;return Array.isArray(t)&&t.length>0?t:[`llm`]}var G=/\/(?:v\d+\/)?(?:messages|chat\/completions|responses|completions|embeddings|images\/generations)$/;function ie(e){let t=e.trim().replace(/\/+$/,``);if(t===``)return null;let n,r;try{n=new URL(t),r=n.pathname.replace(/\/+$/,``)}catch{return null}return G.test(r)?n.origin:null}function K({variant:e,open:t,onClose:n}){let a=te(),o=_(),s=ee(),c=w(),[l,d]=(0,R.useState)(``),[f,m]=(0,R.useState)(``),[h,g]=(0,R.useState)(``),[v,y]=(0,R.useState)(``),[b,x]=(0,R.useState)(!1),[S,C]=(0,R.useState)(!0),[T,E]=(0,R.useState)([]),[D,O]=(0,R.useState)(null),[j,N]=(0,R.useState)(!1),[I,L]=(0,R.useState)(null),[B,V]=(0,R.useState)(!1),H=e===`anthropic-compatible`,U=H?`messages`:`chat`,[W,G]=(0,R.useState)(U),K=(0,R.useMemo)(()=>ie(h),[h]);(0,R.useEffect)(()=>{t&&(d(``),y(``),G(U),g(``),x(!1),C(!0),E([]),O(null),L(null))},[t]);let q=async e=>{try{let t=await navigator.clipboard.readText();t.trim()&&e(t.trim())}catch{O(`Clipboard access denied — paste manually instead.`)}},ae=async()=>{if(!h.trim()){L({ok:!1,message:`Base URL is required to test the connection.`});return}V(!0),L(null),O(null);try{let e=ne(T),t=await c.mutateAsync({baseUrl:h.trim(),apiKey:v.trim(),wireFamily:W,cliIdentity:S,...Object.keys(e).length>0?{extraHeaders:e}:{}});if(t.ok){let e=typeof t.modelCount==`number`?` — upstream advertised ${t.modelCount} model(s)`:``;L({ok:!0,message:`Connected successfully (${t.latencyMs}ms)${e}.`,...t.warning===void 0?{}:{warning:t.warning}})}else L({ok:!1,message:t.error??`Connection failed.`,...t.warning===void 0?{}:{warning:t.warning}})}catch(e){L({ok:!1,message:p(e,`Connection test failed`)})}finally{V(!1)}};return(0,z.jsx)(u,{open:t,onClose:n,title:H?`Add Custom Anthropic Provider`:`Add Custom OpenAI Provider`,footer:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(i,{variant:`secondary`,type:`button`,onClick:n,children:`Cancel`}),(0,z.jsx)(i,{variant:`primary`,type:`submit`,form:`add-compatible-provider`,disabled:j,children:j?`Creating...`:`Add Provider`})]}),children:(0,z.jsxs)(`form`,{id:`add-compatible-provider`,onSubmit:async e=>{if(e.preventDefault(),!l.trim()){O(`Display Name is required`);return}if(!f.trim()){O(`Provider ID (slug) is required`);return}if(!h.trim()){O(`Base URL is required`);return}let t=ne(T),r=f.trim().toLowerCase();N(!0),O(null);try{let e={providerId:r,label:l.trim(),baseUrl:h.trim(),wireFamily:W,compatibilityProfile:{cli_identity:S,...Object.keys(t).length>0?{extra_headers:t}:{}}};await a.mutateAsync(e),v.trim()&&await o.mutateAsync({providerId:r,request:{credentialKind:`api_key`,secret:v.trim()}}),b&&await s.mutateAsync(r),n()}catch(e){O(p(e,`Failed to create provider`))}finally{N(!1)}},className:`flex flex-col gap-6`,children:[D?(0,z.jsx)(`div`,{className:`text-red text-caption`,children:D}):null,(0,z.jsx)(k,{label:`Display Name`,hint:`Required. A friendly label for this node.`,id:`compat-label`,value:l,onChange:e=>d(e.target.value),placeholder:H?`Anthropic Compatible (Prod)`:`OpenAI Compatible (Prod)`,required:!0}),(0,z.jsx)(k,{label:`Provider ID / Slug`,hint:`Required. Used as the provider prefix for model IDs.`,id:`compat-slug`,value:f,onChange:e=>m(e.target.value),placeholder:H?`ac-prod`:`oc-prod`,required:!0}),(0,z.jsxs)(`div`,{className:`form-group`,children:[(0,z.jsxs)(`label`,{className:`form-label`,htmlFor:`compat-url`,children:[(0,z.jsx)(`span`,{children:`Base URL`}),(0,z.jsxs)(`span`,{className:`form-hint`,children:[`The root only. Do not paste the full endpoint — leave off`,H?" `/v1/messages`.":" `/chat/completions`."]})]}),(0,z.jsxs)(P,{gap:`8px`,children:[(0,z.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,z.jsx)(k,{id:`compat-url`,value:h,onChange:e=>g(e.target.value),placeholder:H?`https://api.anthropic.com/v1`:`https://api.openai.com/v1`,required:!0})}),(0,z.jsx)(i,{type:`button`,variant:`secondary`,onClick:()=>q(g),children:`Paste`})]}),K===null?null:(0,z.jsxs)(`p`,{className:`mt-1.5 text-caption text-orange`,children:[`That looks like a full endpoint. Use`,` `,(0,z.jsx)(`code`,{className:`font-mono`,children:K}),` instead — Cartethyia appends the endpoint path itself.`]})]}),H?null:(0,z.jsx)(A,{id:`compat-wire`,label:`API format`,value:W,onValueChange:e=>G(e),options:[{value:`chat`,label:`Chat completions`},{value:`responses`,label:`Responses`}]}),(0,z.jsxs)(`div`,{className:`form-group`,children:[(0,z.jsxs)(`label`,{className:`form-label`,htmlFor:`compat-credential`,children:[(0,z.jsx)(`span`,{children:`API Key`}),(0,z.jsx)(`span`,{className:`form-hint`,children:`Optional — saved with this provider and used to authenticate every request.`})]}),(0,z.jsxs)(P,{gap:`8px`,children:[(0,z.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,z.jsx)(k,{id:`compat-credential`,type:`password`,placeholder:`sk-...`,value:v,onChange:e=>y(e.target.value)})}),(0,z.jsx)(i,{type:`button`,variant:`secondary`,disabled:B,onClick:()=>void ae(),children:B?`Testing...`:`Test connection`}),(0,z.jsx)(i,{type:`button`,variant:`secondary`,onClick:()=>q(y),children:`Paste`})]}),I?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:r(`mt-3 text-caption leading-[1.4] break-words`,I.ok?`text-green`:`text-red`),children:[I.ok?`✓ `:`✗ `,I.message]}),I.warning?(0,z.jsxs)(`div`,{className:`mt-2 text-caption leading-snug break-words text-orange`,children:[`⚠ `,I.warning]}):null]}):null]}),(0,z.jsx)(F,{actions:(0,z.jsx)(M,{checked:b,onChange:x,id:`compat-autofetch`}),children:(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-body font-semibold`,children:`Auto-fetch models`}),(0,z.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Discover this provider's model list automatically after creation`})]})}),(0,z.jsx)(F,{actions:(0,z.jsx)(M,{checked:S,onChange:C,id:`compat-cli-identity`}),children:(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`text-body font-semibold`,children:H?`Send request as Claude CLI`:`Send request as Codex CLI`}),(0,z.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:H?`Emits official Claude CLI User-Agent and Stainless headers to upstream`:`Emits official codex_cli_rs User-Agent and originator headers to upstream`})]})}),(0,z.jsx)(re,{pairs:T,onChange:E})]})})}function q({customProvider:e}){let t=S(),[n,a]=(0,R.useState)(!1),o=y(e.providerId),s=o.data?.length,c=b(e.providerId),l=c.data,d=Q(l??[]);return(0,z.jsxs)(D,{className:V,children:[(0,z.jsx)(ce,{clientVersion:e.clientVersion}),(0,z.jsx)(h,{to:`/providers/${encodeURIComponent(e.providerId)}`,className:r(H,`pr-20 min-h-38`),children:(0,z.jsxs)(P,{gap:`10px`,children:[(0,z.jsx)(j,{icon:e.wireFamilyDefault===`messages`?`anthropic`:`openai`,name:e.label||e.providerId,size:32,imageSize:24}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`div`,{className:U,children:e.label||e.providerId}),e.baseUrl?(0,z.jsxs)(`div`,{className:`mt-1 min-w-0 truncate font-mono text-micro text-text-tertiary`,title:e.baseUrl,children:[(0,z.jsx)(`span`,{className:`font-semibold text-text-secondary`,children:`Base URL`}),` `,e.baseUrl]}):null,(0,z.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2`,children:[l===void 0?(0,z.jsx)($,{kind:`accounts`,isPending:c.isPending,isError:c.isError,hasData:!1}):l.length===0?e.requiresAccount===!1?(0,z.jsx)(O,{tone:`ok`,children:`Free Endpoint`}):(0,z.jsx)(O,{children:`No connections`}):(0,z.jsx)(se,{counts:d,total:l.length}),c.isError&&l!==void 0?(0,z.jsx)(O,{tone:`warn`,children:`Connections unavailable`}):null]})]}),(0,z.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5 shrink-0`,children:[(0,z.jsxs)(`span`,{className:`font-mono tabular-nums text-micro font-semibold bg-kbd-bg px-2.5 py-0.5 rounded-chip text-text-secondary`,children:[e.providerId,`/`]}),s!==void 0&&s>0?(0,z.jsxs)(O,{tone:`info`,children:[s,` models`]}):null,o.isError?(0,z.jsx)(O,{tone:`warn`,children:`Models unavailable`}):s===void 0?(0,z.jsx)($,{kind:`models`,isPending:o.isPending,isError:!1,hasData:!1}):s===0?(0,z.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})}),(0,z.jsx)(i,{variant:`ghost`,size:`sm`,icon:(0,z.jsx)(f,{size:12}),onClick:()=>a(!0),className:`absolute top-2 right-2 p-2 text-text-tertiary`,title:`Delete ${e.label||e.providerId}`}),(0,z.jsx)(u,{open:n,onClose:()=>a(!1),title:`Delete Custom Provider`,children:(0,z.jsxs)(N,{gap:`12px`,children:[(0,z.jsxs)(`p`,{className:`text-body text-text-secondary`,children:[`Are you sure you want to delete custom provider`,` `,(0,z.jsx)(`strong`,{children:e.label||e.providerId}),`? Its models, accounts, and routing preferences are deleted together, and requests to this provider will no longer route.`]}),t.isError?(0,z.jsx)(`p`,{className:`text-caption text-red`,children:p(t.error,`Delete failed`)}):null,(0,z.jsxs)(m,{children:[(0,z.jsx)(i,{variant:`secondary`,onClick:()=>a(!1),children:`Cancel`}),(0,z.jsx)(i,{variant:`danger`,onClick:()=>{t.mutate(e.providerId,{onSuccess:()=>a(!1),onError:()=>void 0})},disabled:t.isPending,children:t.isPending?`Deleting...`:`Delete Provider`})]})]})})]})}function ae({customProviders:e}){let[t,n]=(0,R.useState)(!1),[r,s]=(0,R.useState)(!1),[c,l]=(0,R.useState)(()=>{try{return window.localStorage.getItem(`cartethyia.customProvidersHidden`)===`1`}catch{return!1}});function u(){l(e=>{let t=!e;try{window.localStorage.setItem(`cartethyia.customProvidersHidden`,t?`1`:`0`)}catch{}return t})}return(0,z.jsxs)(`section`,{className:`flex flex-col gap-5`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-4`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:u,"aria-expanded":!c,title:c?`Show custom providers`:`Hide custom providers`,className:`inline-flex items-center gap-3 bg-transparent border-none p-0 cursor-pointer text-inherit`,children:[(0,z.jsxs)(`h2`,{className:`text-body-lg font-bold tracking-[-0.01em]`,children:[`Custom Providers`,e.length>0?` (${e.length})`:``]}),(0,z.jsx)(C,{size:14,className:`text-text-tertiary transition-transform`,style:{transform:c?`rotate(-90deg)`:void 0}})]}),(0,z.jsxs)(P,{gap:`8px`,children:[(0,z.jsx)(i,{size:`sm`,variant:`ghost`,icon:c?(0,z.jsx)(o,{size:13}):(0,z.jsx)(a,{size:13}),onClick:u,title:c?`Show custom providers`:`Hide custom providers`,children:c?`Show`:`Hide`}),(0,z.jsx)(i,{size:`sm`,variant:`secondary`,icon:(0,z.jsx)(d,{size:13}),onClick:()=>n(!0),children:`Custom Anthropic`}),(0,z.jsx)(i,{size:`sm`,variant:`secondary`,icon:(0,z.jsx)(d,{size:13}),onClick:()=>s(!0),children:`Custom OpenAI`})]})]}),c?null:e.length===0?(0,z.jsx)(D,{children:(0,z.jsxs)(T,{className:`text-center px-7 py-10 border border-dashed border-inner-border rounded-card`,children:[(0,z.jsx)(`p`,{className:`text-body font-semibold text-text-primary`,children:`No custom providers yet`}),(0,z.jsx)(`p`,{className:`text-badge text-text-tertiary mt-1`,children:`Add an OpenAI- or Anthropic-compatible endpoint with the buttons above.`})]})}):(0,z.jsx)(B,{children:e.map(e=>(0,z.jsx)(q,{customProvider:e},e.providerId))}),(0,z.jsx)(K,{variant:`anthropic-compatible`,open:t,onClose:()=>n(!1)}),(0,z.jsx)(K,{variant:`openai-compatible`,open:r,onClose:()=>s(!1)})]})}var J=new Set([`inferhub`]),Y=new Set([`grok`,`opencode`,`cline`,`hermes`,`kilo`]),oe=new Set([`anthropic`,`openai`,`gemini`,`alibabacp`,`ollamacloud`,`opencode-zen`,`opencode-go`,`mistral`,`meta`,`deepseek`,`commandcode`,`dashscope`]);function X(e){return e.oauthFlows?.browser===!0||e.oauthFlows?.device===!0}function Z(e){return e.oauthFlows?.refreshable===!0}function Q(e){let t=e=>e.status===`cooldown`||L(e)!==void 0;return{healthy:e.filter(e=>e.status===`active`&&!t(e)).length,throttled:e.filter(t).length,disabled:e.filter(e=>e.status===`disabled`).length,cooling:e.filter(e=>e.status!==`cooldown`&&L(e)!==void 0).length}}function se({counts:e,total:t}){if(!(e.healthy>0||e.throttled>0||e.disabled>0))return(0,z.jsxs)(O,{tone:`warn`,dot:!0,children:[t,` Connected`]});let n=e.throttled===e.cooling?`Cooling`:`Cooldown`;return(0,z.jsxs)(z.Fragment,{children:[e.healthy>0?(0,z.jsxs)(O,{tone:`ok`,dot:!0,children:[e.healthy,` Healthy`]}):null,e.throttled>0?(0,z.jsxs)(O,{tone:`warn`,dot:!0,children:[e.throttled,` `,n]}):null,e.disabled>0?(0,z.jsxs)(O,{tone:`warn`,dot:!0,children:[e.disabled,` Unhealthy`]}):null]})}function $({kind:e,isPending:t,isError:n,hasData:r,isEmpty:i=!1}){let a=e===`models`?`Models`:`Connections`;return n?(0,z.jsxs)(O,{tone:`warn`,children:[a,` unavailable`]}):t&&!r?(0,z.jsxs)(O,{tone:`info`,children:[`Loading `,a.toLowerCase(),`…`]}):i?(0,z.jsx)(O,{children:e===`models`?`No models`:`No connections`}):null}function ce({clientVersion:e}){return e?(0,z.jsxs)(O,{className:`provider-version-badge absolute -top-4.5 left-5 right-auto z-chip max-w-[calc(100%-var(--spacing)*10)] truncate px-3 py-1 text-micro leading-[1.15] shadow-card max-small:left-4 max-small:max-w-[calc(100%-var(--spacing)*8)]`,tone:e.source===`latest`?`teal`:`default`,title:e.source===`latest`?`Latest discovered client version`:`Pinned fallback; background discovery has not succeeded yet`,children:[`v`,e.version,` · `,e.source]}):null}var le=(0,R.memo)(function({provider:e,serviceKind:t}){let n=J.has(e.providerId.toLowerCase()),i=e.label||e.displayName,a=y(e.providerId),o=a.data?.filter(e=>t===void 0||e.serviceKind===t||t===`llm`&&e.serviceKind===void 0).length,s=b(e.providerId),c=s.data,l=Q(c??[]);return(0,z.jsxs)(D,{className:V,children:[(0,z.jsx)(ce,{clientVersion:e.clientVersion}),n?(0,z.jsx)(`span`,{"aria-label":`Friend sponsor`,title:`Friend sponsor`,className:`absolute top-0 right-0 z-2 w-36 h-36 overflow-hidden pointer-events-none`,children:(0,z.jsx)(`span`,{className:r(`absolute top-9 -right-11 w-38 py-1 rotate-45 bg-accent-soft`,`text-accent text-micro font-extrabold tracking-tight leading-[1.05]`,`text-center uppercase shadow-ribbon`),children:`Friend`})}):null,(0,z.jsx)(h,{to:`/providers/${encodeURIComponent(e.providerId)}${t===void 0?``:`?service=${t}`}`,className:H,children:(0,z.jsxs)(P,{gap:`10px`,children:[(0,z.jsx)(j,{icon:e.providerId,name:i,size:32,imageSize:24}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`div`,{className:U,children:i}),(0,z.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-2`,children:[c===void 0?(0,z.jsx)($,{kind:`accounts`,isPending:s.isPending,isError:s.isError,hasData:!1}):c.length===0?e.requiresAccount===!1?(0,z.jsx)(O,{tone:`ok`,children:`Free Endpoint`}):(0,z.jsx)(O,{children:`No connections`}):(0,z.jsx)(se,{counts:l,total:c.length}),s.isError&&c!==void 0?(0,z.jsx)(O,{tone:`warn`,children:`Connections unavailable`}):null]})]}),(0,z.jsxs)(`div`,{className:`flex flex-col items-end gap-1.5 shrink-0`,children:[(0,z.jsxs)(`span`,{className:`font-mono tabular-nums text-micro font-semibold bg-kbd-bg px-2.5 py-0.5 rounded-chip text-text-secondary`,children:[e.providerId,`/`]}),o!==void 0&&o>0?(0,z.jsxs)(O,{tone:`info`,children:[o,` models`]}):null,a.isError?(0,z.jsx)(O,{tone:`warn`,children:`Models unavailable`}):o===void 0?(0,z.jsx)($,{kind:`models`,isPending:a.isPending,isError:!1,hasData:!1}):o===0?(0,z.jsx)($,{kind:`models`,isPending:!1,isError:!1,hasData:!0,isEmpty:!0}):null]})]})})]})});function ue(e,t){let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n}var de=`cartethyia.providerSectionsCollapsed`;function fe(){try{let e=window.localStorage.getItem(de),t=e?JSON.parse(e):[];return new Set(Array.isArray(t)?t.filter(e=>typeof e==`string`):[])}catch{return new Set}}var pe=[{title:`Founding Friend & Sponsors`,subtitle:`Super Cheap inference pool`,filter:e=>J.has(e.providerId.toLowerCase())},{title:`Free Limited Providers`,filter:e=>Y.has(e.providerId.toLowerCase())},{title:`OAuth & Agent Providers`,filter:e=>(X(e)||Z(e))&&!Y.has(e.providerId.toLowerCase())},{title:`Well Known API Key Providers`,subtitle:`The household names — sign up with a key and go`,filter:e=>e.isBuiltIn&&oe.has(e.providerId.toLowerCase())&&!J.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X(e)&&!Z(e)},{title:`Other API Key Providers`,subtitle:`Free tier friendly — no credit card`,filter:e=>e.isBuiltIn&&!oe.has(e.providerId.toLowerCase())&&!J.has(e.providerId.toLowerCase())&&!Y.has(e.providerId.toLowerCase())&&!X(e)&&!Z(e)}];function me(){let[e,t]=(0,R.useState)(fe),n=g(),u=I(),d=u.enabled,f=e=>!d||e.configured===!0||e.requiresAccount===!1,m=(0,R.useMemo)(()=>n.data??[],[n.data]),ee=(0,R.useMemo)(()=>[...m.filter(e=>!e.isBuiltIn&&f(e))].sort(ue),[m,d]),h=(0,R.useMemo)(()=>m.filter(e=>W(e).includes(`websearch`)&&f(e)),[m,d]),_=(0,R.useMemo)(()=>m.filter(e=>W(e).includes(`llm`)&&f(e)),[m,d]),[y,te]=v(),b=y.get(`tab`),S=b===`search`||b===`media`?b:`llm`,w=e=>{te(t=>{let n=new URLSearchParams(t);return e===`llm`?n.delete(`tab`):n.set(`tab`,e),n})},O=(0,R.useMemo)(()=>m.filter(e=>(W(e).includes(`imageGeneration`)||W(e).includes(`videoGeneration`))&&f(e)),[m,d]),k=(0,R.useMemo)(()=>[...h].sort((e,t)=>(e.label||e.displayName).localeCompare(t.label||t.displayName)),[h]),A=(e,t)=>{let n=Number(!!t.configured)-Number(!!e.configured);return n===0?(e.label||e.displayName).localeCompare(t.label||t.displayName):n},j=(0,R.useMemo)(()=>{if(S===`media`)return[{title:`Media Generation`,subtitle:`Providers that can return an image or a video`,providers:O}].filter(e=>e.providers.length>0);if(S===`search`)return[{title:`Search Providers`,subtitle:`Providers that can answer a web search request`,providers:k}].filter(e=>e.providers.length>0);let e=_;return pe.map(t=>({...t,providers:e.filter(t.filter).sort(A)})).filter(e=>e.providers.length>0)},[_,k,O,S]),M=n.isPending&&!n.data?(0,z.jsx)(c,{label:`Loading providers...`}):n.isError?(0,z.jsx)(s,{message:p(n.error,`Failed to load providers`),onRetry:()=>n.refetch()}):null;return M?(0,z.jsxs)(D,{children:[(0,z.jsx)(E,{title:`Providers`,icon:(0,z.jsx)(x,{size:16})}),(0,z.jsx)(T,{className:`flex flex-1`,children:M})]}):(0,z.jsx)(N,{gap:`24px`,children:(0,z.jsxs)(D,{children:[(0,z.jsx)(E,{title:`Providers`,subtitle:`Connected pinned first · A–Z`,icon:(0,z.jsx)(x,{size:16})}),(0,z.jsxs)(T,{className:`flex flex-col gap-8`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,z.jsx)(`div`,{className:`flex gap-2`,children:[`llm`,`search`,`media`].map(e=>(0,z.jsxs)(`button`,{onClick:()=>w(e),className:r(`px-6 py-3 rounded-inset text-caption font-semibold border cursor-pointer`,S===e?`border-accent bg-accent-soft text-accent`:`border-inner-border bg-surface-1 text-text-secondary`),children:[e===`llm`?`LLM`:e===`search`?`Search`:`Media`,e===`search`?` (${h.length})`:e===`media`?` (${O.length})`:` (${_.length})`]},e))}),(0,z.jsx)(i,{variant:`ghost`,size:`sm`,icon:d?(0,z.jsx)(a,{size:12}):(0,z.jsx)(o,{size:12}),onClick:()=>u.setEnabled(!d),title:d?`Show providers that have no account yet`:`Hide providers that have no account yet`,children:d?`Show unconfigured`:`Hide unconfigured`}),(0,z.jsx)(`span`,{className:`ml-auto text-micro text-text-tertiary`,children:S===`search`?`Fallback runs only when the model invokes Websearch`:S===`media`?`Image and video generation`:`Connected pinned first · A–Z`})]}),S===`llm`?(0,z.jsx)(ae,{customProviders:ee}):null,j.length===0?(0,z.jsx)(D,{children:(0,z.jsx)(T,{children:(0,z.jsx)(l,{title:`No providers found`,message:`No providers available.`})})}):j.map(n=>{let i=e.has(n.title);return(0,z.jsxs)(`section`,{className:`flex flex-col gap-6`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`flex items-start gap-4 border-0 bg-transparent p-0 text-left text-inherit`,"aria-expanded":!i,onClick:()=>t(e=>{let t=new Set(e);t.has(n.title)?t.delete(n.title):t.add(n.title);try{window.localStorage.setItem(de,JSON.stringify([...t]))}catch{}return t}),children:[(0,z.jsx)(C,{size:15,className:r(`mt-1 shrink-0 transition-transform`,i&&`-rotate-90`)}),(0,z.jsxs)(N,{gap:`1px`,children:[(0,z.jsxs)(`h2`,{className:`text-body font-bold tracking-[-0.01em]`,children:[n.title,` (`,n.providers.length,`)`,i?` (Hidden)`:``]}),!i&&n.subtitle?(0,z.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:n.subtitle}):null]})]}),i?null:(0,z.jsx)(B,{children:n.providers.map(e=>(0,z.jsx)(le,{provider:e,serviceKind:S===`search`?`websearch`:S===`media`?W(e).includes(`imageGeneration`)?`imageGeneration`:`videoGeneration`:`llm`},e.providerId))})]},n.title)})]})]})})}export{me as default,Q as summarizeAccounts};
|
|
Binary file
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{r as i}from"./terminal-Bd4ee8TA.js";import{C as a,T as o,b as s,l as c,s as l,t as u}from"./numbers-Bs4LOOuf.js";import{t as d}from"./download-A0SW9OCW.js";import{t as f}from"./eye-off-Bk5g2luF.js";import{t as p}from"./eye-C_hawfH4.js";import{t as m}from"./gauge-BbIMy7MB.js";import{n as h,r as g,t as _}from"./state-DYdQmdAl.js";import{t as v}from"./dialog-BtpsJU98.js";import{t as y}from"./pencil-768ysRAr.js";import{t as ee}from"./plus-DIdX_g-x.js";import{t as b}from"./power-off-Yjw9GMJh.js";import{t as x}from"./rotate-ccw-CufcqITi.js";import{t as S}from"./shield-check-DVS0Foqh.js";import{t as C}from"./trash-Cppn5c3R.js";import{C as w,T,c as E,v as D,y as O}from"./assert-NHwYq95t.js";import{a as k,i as A,l as j,o as M,t as N}from"./query-keys-D7wX2vM5.js";import{t as P}from"./useMutation-w4u4CVue.js";import{R as te,rt as ne}from"./entry-Dj9AR0gY.js";import{n as re,r as ie,t as ae}from"./card--AtFedAq.js";import{n as oe}from"./download-dRFo5_Wu.js";import{t as F}from"./badge-6uzDDvqs.js";import{n as I}from"./input-BG41et9G.js";import{t as se}from"./select-DsX5QT8K.js";import{t as L}from"./switch-CidSfbG7.js";import{t as ce}from"./stack-DwLmjUFK.js";import{n as le}from"./inline-BcNGF8Gr.js";import{r as R,t as ue}from"./layout-C8mer_Ak.js";import{i as de,n as fe}from"./privacy-mode-GM8bej85.js";import{n as z}from"./live-BJGYRBnR.js";var pe=e(`cloud`,[[`path`,{d:`M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z`,key:`p7xjir`}]]),me=e(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),he=1e6,ge=1e8,_e=5e6,ve=`sin1`,ye=[{label:`Asia Pacific`,regions:[{id:`sin1`,label:`Singapore`},{id:`hkg1`,label:`Hong Kong`},{id:`icn1`,label:`Seoul`},{id:`hnd1`,label:`Tokyo`},{id:`kix1`,label:`Osaka`},{id:`bom1`,label:`Mumbai`},{id:`syd1`,label:`Sydney`}]},{label:`Europe`,regions:[{id:`fra1`,label:`Frankfurt`},{id:`cdg1`,label:`Paris`},{id:`lhr1`,label:`London`},{id:`arn1`,label:`Stockholm`},{id:`dub1`,label:`Dublin`}]},{label:`North America`,regions:[{id:`iad1`,label:`Washington, D.C.`},{id:`sfo1`,label:`San Francisco`},{id:`pdx1`,label:`Portland`},{id:`cle1`,label:`Cleveland`},{id:`yul1`,label:`Montréal`}]},{label:`Other`,regions:[{id:`gru1`,label:`São Paulo`},{id:`cpt1`,label:`Cape Town`},{id:`dxb1`,label:`Dubai`}]}];function be(){return w({queryKey:N.network.pools,queryFn:e=>M(`/network/pools`,{signal:D(e)}).then(E),staleTime:A.staleTime,gcTime:A.gcTime})}function xe(){let e=T();return P({mutationFn:e=>M(`/network/pools`,{method:`POST`,body:JSON.stringify(e)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),l.success(`Proxy pool created`)},onError:e=>{l.error(`Could not create the proxy pool.`,j(e))}})}function Se(){let e=T();return P({mutationFn:e=>M(`/network/pools/relay/deploy`,{method:`POST`,body:JSON.stringify(e)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools})}})}function Ce(){return P({mutationFn:e=>M(`/network/pools/test-batch`,{method:`POST`,body:JSON.stringify({targets:e})})})}function we(){let e=T();return P({mutationFn:({poolId:e,request:t})=>M(`/network/pools/${encodeURIComponent(e)}`,{method:`PATCH`,body:JSON.stringify(t)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),l.success(`Proxy updated`)},onError:e=>{l.error(`Could not update the proxy pool.`,j(e))}})}function Te(e){return w({queryKey:[...N.network.pools,e,`health-events`],queryFn:t=>M(`/network/pools/${encodeURIComponent(e??``)}/health-events`,{signal:D(t)}),enabled:!!e,...A,refetchInterval:k.status})}function Ee(){let e=T();return P({mutationFn:e=>M(`/network/pools/${encodeURIComponent(e)}/recover`,{method:`POST`,body:`{}`}),onSuccess:async(t,n)=>{await Promise.all([e.invalidateQueries({queryKey:N.network.pools}),e.invalidateQueries({queryKey:[...N.network.pools,n,`health-events`]})]),l.success(`Proxy pool recovered`)},onError:e=>{l.error(`Could not recover the proxy pool.`,j(e))}})}function De(){let e=T();return P({mutationFn:e=>M(`/network/pools/${encodeURIComponent(e)}`,{method:`DELETE`}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),l.success(`Proxy pool deleted`)},onError:e=>{l.error(`Could not delete the proxy pool.`,j(e))}})}function Oe(){let e=T();return P({mutationFn:({poolId:e,providerId:t})=>M(`/network/pools/${encodeURIComponent(e)}/provider-probe`,{method:`POST`,body:JSON.stringify({providerId:t})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools})}})}function ke(){return P({mutationFn:({providerId:e,targets:t})=>M(`/network/pools/test-batch/provider`,{method:`POST`,body:JSON.stringify({providerId:e,targets:t})})})}function Ae(){let e=T();return P({mutationFn:e=>M(`/network/pools/${encodeURIComponent(e)}/health-check`,{method:`POST`,body:`{}`}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),l.success(`Health check complete`)},onError:e=>{l.error(`Health check failed.`,j(e))}})}function je(){let e=T();return P({mutationFn:({poolId:e,bytes:t})=>M(`/network/pools/${encodeURIComponent(e)}/speed-test`,{method:`POST`,body:JSON.stringify({bytes:t})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools})}})}function Me(){let e=T();return P({mutationFn:({poolId:e,providerId:t})=>M(`/network/pools/${encodeURIComponent(e)}/cooldowns/clear`,{method:`POST`,body:JSON.stringify(t?{providerId:t}:{})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),l.success(`Provider cooldowns cleared`)},onError:e=>{l.error(`Could not clear provider cooldowns.`,j(e))}})}var B=t(n(),1),V=r(),H={cloudflare:{label:`Cloudflare Workers`,tokenLabel:`Cloudflare API token`,needsAccount:!0,host:`*.workers.dev`,hasRegion:!1},vercel:{label:`Vercel`,tokenLabel:`Vercel API token`,needsAccount:!1,host:`*.vercel.app`,hasRegion:!0},deno:{label:`Deno Deploy`,tokenLabel:`Deno Deploy token`,needsAccount:!1,host:`*.deno.dev`,hasRegion:!1}},Ne=ye.flatMap(e=>e.regions.map(t=>({value:t.id,label:`${e.label} — ${t.label}`})));function Pe({onClose:e}){let t=Se(),[n,r]=(0,B.useState)(`cloudflare`),[i,a]=(0,B.useState)(ve),[o,u]=(0,B.useState)(``),[d,f]=(0,B.useState)(``),[p,m]=(0,B.useState)(``),[h,g]=(0,B.useState)(null),_=H[n],y=o.trim().length>0&&(!_.needsAccount||d.trim().length>0);return(0,V.jsx)(v,{open:!0,onClose:e,title:`Deploy Relay`,description:`Run outbound traffic through a hosted relay (Cloudflare, Vercel, Deno).`,size:`md`,children:(0,V.jsxs)(ce,{gap:`12px`,children:[(0,V.jsxs)(`p`,{className:`text-badge text-text-tertiary m-0 flex gap-3`,children:[(0,V.jsx)(ne,{size:13,className:`shrink-0 mt-0.5`}),(0,V.jsxs)(`span`,{children:[`Deploys a small relay worker to your own `,_.label,` account and registers its URL (`,(0,V.jsx)(`code`,{children:_.host}),`) as an active HTTP pool. Your API token is used only for the deploy and is never stored.`]})]}),(0,V.jsx)(se,{label:`Relay host`,id:`relay-target`,value:n,onValueChange:e=>r(e),options:O.map(e=>({value:e,label:H[e].label}))}),(0,V.jsx)(I,{label:_.tokenLabel,id:`relay-token`,type:`password`,value:o,placeholder:`Paste a deploy token`,onChange:e=>u(e.target.value)}),_.needsAccount?(0,V.jsx)(I,{label:`Account ID`,id:`relay-account`,value:d,placeholder:`Cloudflare account id`,onChange:e=>f(e.target.value)}):null,(0,V.jsx)(I,{label:`Project name (optional)`,id:`relay-project`,value:p,placeholder:`e.g. cartethyia-relay`,onChange:e=>m(e.target.value)}),_.hasRegion?(0,V.jsx)(se,{label:`Deploy region`,id:`relay-region`,value:i,onValueChange:e=>a(e),options:Ne}):null,_.hasRegion?(0,V.jsx)(`p`,{className:`text-badge text-text-tertiary m-0`,children:`Sets the region on the Vercel project, which is what decides the country outbound traffic leaves from. A region sent on the deployment alone is accepted but does not move the Function.`}):null,(0,V.jsxs)(`div`,{className:`flex items-center gap-5`,children:[(0,V.jsx)(c,{variant:`primary`,size:`sm`,onClick:()=>{y&&t.mutate({target:n,token:o.trim(),..._.needsAccount&&d.trim()?{accountId:d.trim()}:{},...p.trim()?{projectName:p.trim()}:{},..._.hasRegion?{region:i}:{}},{onSuccess:e=>{g(e.relayUrl),u(``),l.success(`Relay deployed to ${e.relayUrl} and registered as a pool.`)},onError:e=>l.error(j(e,`Relay deploy failed.`))})},disabled:!y||t.isPending,children:t.isPending?`Deploying…`:`Deploy relay`}),h?(0,V.jsxs)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Registered pool at `,(0,V.jsx)(`code`,{children:h})]}):null]}),t.isError?(0,V.jsxs)(`p`,{className:`text-badge text-red m-0 flex gap-3`,children:[(0,V.jsx)(s,{size:13,className:`shrink-0 mt-0.5`}),(0,V.jsx)(`span`,{children:j(t.error,`Relay deploy failed.`)})]}):null]})})}function Fe(e,t){if(e!==void 0)return e.endpoint===``||e.endpoint===(t??``)?e.result:void 0}function Ie(e,t,n){switch(t){case`name`:return(e.label||e.endpoint).toLowerCase();case`family`:return e.family===void 0||e.family===null||e.family===``?null:e.family.toLowerCase();case`address`:return e.egressIp??null;case`load`:return n??null}}function Le(e,t,n,r){let i=n===`asc`?1:-1;return[...e].sort((e,n)=>{let a=Ie(e,t,r(e)),o=Ie(n,t,r(n));return a===null&&o===null?0:a===null?1:o===null?-1:typeof a==`number`&&typeof o==`number`?(a-o)*i:String(a).localeCompare(String(o))*i})}function U(e,t){let n=e.filter(e=>e.status===`active`),r=n.reduce((e,t)=>e+t.maxInflight,0),i=t===void 0?n.reduce((e,t)=>e+(t.inflight??0),0):n.reduce((e,n)=>e+(t.get(n.id)??0),0),a=0,o=0;for(let e of n)(t===void 0?e.inflight??0:t.get(e.id)??0)>=e.maxInflight?o+=1:a+=1;let s=null,c=Date.now(),l=e=>{if(!e)return;let t=Date.parse(e);if(Number.isNaN(t))return;let n=t-c;n<=0||(s===null||n<s)&&(s=n)};for(let t of e){l(t.cooldownUntil);for(let e of t.providerCooldowns??[])l(e.until)}let u=n.filter(e=>e.lastLatencyMs!==void 0&&Number.isFinite(e.lastLatencyMs)),d=u.length===0?null:Math.round(u.reduce((e,t)=>e+(t.lastLatencyMs??0),0)/u.length);return{totalPools:e.length,active:n.length,cooldown:e.filter(e=>e.status===`cooldown`).length,totalMaxConcurrency:r,usedInflight:i,availableCapacity:Math.max(0,r-i),routablePools:a,saturatedPools:o,soonestCooldownMs:s,avgLatencyMs:d,measuredPools:u.length}}var W=[`http`,`https`,`socks5`];function G(e){return/^[a-z][a-z0-9+.-]*:\/\//i.test(e.trim())}function Re(e,t){let n=e.trim();return t===null||G(n)?n:`${t}://${n}`}function K(e){return e.find(e=>e.trim()!==``)}function q(e){let t=e.trim().toLowerCase();return t.startsWith(`https://`)?`https`:t.startsWith(`socks5://`)||t.startsWith(`socks://`)?`socks5`:`http`}var ze=1024**3;function Be(e){let t=e.trim();if(t===``)return null;let n=Number(t);return!Number.isFinite(n)||n<=0?null:Math.max(1,Math.round(n*ze))}function J(e,t,n){let r=new Map;if(t.trim().toLowerCase()===``||n<=0)return r;let i=Math.floor(e/n),a=e-i*n;for(let e=0;e<n;e+=1){let t=e===n-1?a:0;r.set(e,i+t)}return r}var Ve=4,He=`cartethyia_proxy_test_payload`,Ue=`cartethyia_proxy_check_results`,We=[{value:`url`,label:`Test URL`},{value:`opencode`,label:`Test OpenCode`}],Ge=`opencode`,Ke=4,qe=`Mysterious Proxy`;function Y(e){return e.avgLatencyMs===null?`no measurement yet`:`avg across ${e.measuredPools} enabled ${e.measuredPools===1?`pool`:`pools`}`}function Je(e){let t=e.endpoint||``,n=t.includes(`://`)?t:`${e.kind}://${t}`,r={"https:":`443`,"http:":`80`,"socks5:":`1080`,"socks:":`1080`};try{let e=new URL(n),t=e.port||r[e.protocol]||``,i=`${e.hostname}${t?`:${t}`:``}`;return{name:i,endpoint:`${e.protocol}//${i}${e.pathname===`/`?``:e.pathname}${e.search}`}}catch{return{name:e.label||t,endpoint:t}}}function X(e){return e.label||Je(e).name||e.id}var Z=1024**3;function Ye(e){if(e.lastSpeedtestStatus===void 0||e.lastSpeedtestAt===void 0)return;let t=e.lastSpeedtestDurationMs??0,n=e.lastSpeedtestBytes??0,r=t>0?n/(t/1e3):void 0;return{poolId:e.id,status:e.lastSpeedtestStatus,bytes:n,durationMs:t,...r===void 0?{}:{bytesPerSecond:r,megabitsPerSecond:r*8/1e6},...e.lastSpeedtestError?{errorMessage:e.lastSpeedtestError}:{},measuredAt:e.lastSpeedtestAt}}function Xe(e,t){if(!e)return t;if(!t)return e;let n=e.measuredAt?new Date(e.measuredAt).getTime():0;return(t.measuredAt?new Date(t.measuredAt).getTime():0)>=n?t:e}var Ze=[{value:String(he),label:`1 MB`},{value:String(_e),label:`5 MB`},{value:`50000000`,label:`50 MB`},{value:String(ge),label:`100 MB`}];function Qe({pool:e,onClose:t,actionsRef:n}){let r=we(),i=ke(),s=Ae(),[d,f]=(0,B.useState)(e.label??``),[p,m]=(0,B.useState)(e.family??``),[h,g]=(0,B.useState)(e.endpoint??``),[_,v]=(0,B.useState)(String(e.maxInflight??10)),[y,ee]=(0,B.useState)(String(e.weight??100)),[b,x]=(0,B.useState)(e.quotaBytes?String(Math.round(e.quotaBytes/Z*1e3)/1e3):``),[S,C]=(0,B.useState)(null),[w,T]=(0,B.useState)(!1),E=h.trim()===e.endpoint,D=async()=>{T(!0),C(null);try{if(E){let t=await s.mutateAsync(e.id),n=t.status===`healthy`||t.status===`reachable`;C({ok:n,message:t.status===`healthy`?`Connected in ${t.latencyMs??0}ms`:t.errorMessage??`Connection failed`});return}let t=[{kind:e.kind,endpoint:h.trim(),...e.family===null||e.family===void 0?{}:{family:e.family}}],[n]=await i.mutateAsync({providerId:Ge,targets:t}),r=n?.result;if(!r){C({ok:!1,message:`Probe returned no result`});return}let a=r.status===`allowed`||r.status===`throttled`;C({ok:a,message:r.reason??(r.status===`allowed`?`Reachable${r.latencyMs===void 0?``:` in ${r.latencyMs}ms`}`:r.status===`throttled`?`Reachable; rate limit spent`:`Probe could not complete`)})}catch(e){C({ok:!1,message:j(e,`Connection failed`)})}finally{T(!1)}},O=Be(b),k=async()=>{await r.mutateAsync({poolId:e.id,request:{...d.trim()===e.label?{}:{label:d.trim()||void 0},...p.trim()===(e.family??``)?{}:{family:p.trim()||null},...h.trim()!==e.endpoint&&h.trim()!==``?{endpoint:h.trim()}:{},...Number(_)===e.maxInflight?{}:{maxInflight:Number(_)},...Number(y)===e.weight?{}:{weight:Number(y)},...O===(e.quotaBytes??null)?{}:{quotaBytes:O}}}),l.success(`Proxy updated`),t()};return(0,B.useEffect)(()=>{n?.((0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(c,{variant:`secondary`,size:`sm`,onClick:t,children:`Cancel`}),(0,V.jsx)(c,{variant:`primary`,size:`sm`,disabled:r.isPending||!h.trim(),onClick:()=>void k(),children:`Save`})]}))}),(0,V.jsxs)(ce,{gap:`12px`,children:[(0,V.jsx)(`div`,{children:(0,V.jsx)(I,{label:`Name`,value:d,onChange:e=>f(e.target.value)})}),(0,V.jsx)(`div`,{children:(0,V.jsx)(I,{label:`Family`,value:p,placeholder:`e.g. residential-id`,onChange:e=>m(e.target.value)})}),(0,V.jsx)(`div`,{children:(0,V.jsx)(I,{label:`Endpoint`,value:h,onChange:e=>g(e.target.value),className:`font-mono tabular-nums`})}),(0,V.jsxs)(`div`,{className:`grid grid-cols-2 gap-5`,children:[(0,V.jsx)(`div`,{children:(0,V.jsx)(I,{label:`Max concurrent`,type:`number`,min:1,value:_,onChange:e=>v(e.target.value)})}),(0,V.jsx)(`div`,{children:(0,V.jsx)(I,{label:`Weight`,type:`number`,min:1,value:y,onChange:e=>ee(e.target.value)})})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(I,{label:`Bandwidth quota (GB, blank = unmetered)`,type:`number`,min:.001,step:`0.1`,value:b,onChange:e=>x(e.target.value)}),(0,V.jsx)(`div`,{className:`text-micro text-text-tertiary mt-2`,children:O===null?`No quota — the bar shows a running total only.`:`Bar turns orange at 80% and red once ${u(O)} is exceeded.`})]}),S&&(0,V.jsx)(`div`,{className:`rounded-inset px-6 py-4 text-badge font-semibold ${S.ok?`bg-green-soft text-green`:`bg-red-soft text-red`}`,children:S.message}),(0,V.jsx)(`div`,{children:(0,V.jsx)(c,{variant:`secondary`,size:`sm`,disabled:w,icon:w?(0,V.jsx)(a,{size:13,className:`animate-spin`}):(0,V.jsx)(o,{size:13}),onClick:()=>void D(),children:w?`Testing…`:`Test connection`})})]})}function $e({endpoint:e,chip:t,onChipChange:n}){return(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,role:`group`,"aria-label":`Scheme for the first endpoint`,children:[(0,V.jsx)(`span`,{className:`text-badge text-text-secondary`,children:`Scheme`}),W.map(r=>{let i=t===r;return(0,V.jsxs)(c,{type:`button`,variant:i?`primary`:`secondary`,size:`sm`,disabled:e===void 0,"aria-pressed":i,"data-scheme":r,onClick:()=>n(i?null:r),className:`font-mono`,children:[r,`://`]},r)}),t!==null&&(0,V.jsxs)(`span`,{className:`text-badge text-text-tertiary`,children:[`→ `,Re(e??``,t)]})]})}function et({onClose:e,actionsRef:t,onProbeResult:n,onHealthResult:r}){let i=xe(),a=Ce(),o=ke(),[s,u]=(0,B.useState)(``),[d,f]=(0,B.useState)(``),[p,m]=(0,B.useState)(``),[h,g]=(0,B.useState)(null),[_,v]=(0,B.useState)([]),[y,ee]=(0,B.useState)({}),[b,x]=(0,B.useState)({}),[S,C]=(0,B.useState)(!1),[w,T]=(0,B.useState)(null),E=s.split(`
|
|
1
|
+
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{r as i}from"./terminal-Bd4ee8TA.js";import{C as a,T as o,b as s,l as c,s as l,t as u}from"./numbers-Bs4LOOuf.js";import{t as d}from"./download-A0SW9OCW.js";import{t as f}from"./eye-off-Bk5g2luF.js";import{t as p}from"./eye-C_hawfH4.js";import{t as m}from"./gauge-BbIMy7MB.js";import{n as h,r as g,t as _}from"./state-DYdQmdAl.js";import{t as v}from"./dialog-BtpsJU98.js";import{t as y}from"./pencil-768ysRAr.js";import{t as ee}from"./plus-DIdX_g-x.js";import{t as b}from"./power-off-Yjw9GMJh.js";import{t as x}from"./rotate-ccw-CufcqITi.js";import{t as S}from"./shield-check-DVS0Foqh.js";import{t as C}from"./trash-Cppn5c3R.js";import{C as w,T,c as E,v as D,y as O}from"./assert-NHwYq95t.js";import{a as k,i as A,l as j,o as M,t as N}from"./query-keys-D7wX2vM5.js";import{t as P}from"./useMutation-w4u4CVue.js";import{R as te,rt as ne}from"./entry-CkryrIea.js";import{n as re,r as ie,t as ae}from"./card--AtFedAq.js";import{n as oe}from"./download-dRFo5_Wu.js";import{t as F}from"./badge-6uzDDvqs.js";import{n as I}from"./input-BG41et9G.js";import{t as se}from"./select-BO6h8yNv.js";import{t as L}from"./switch-CidSfbG7.js";import{t as ce}from"./stack-DwLmjUFK.js";import{n as le}from"./inline-BcNGF8Gr.js";import{r as R,t as ue}from"./layout-C8mer_Ak.js";import{i as de,n as fe}from"./privacy-mode-GM8bej85.js";import{n as z}from"./live-BJGYRBnR.js";var pe=e(`cloud`,[[`path`,{d:`M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z`,key:`p7xjir`}]]),me=e(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),he=1e6,ge=1e8,_e=5e6,ve=`sin1`,ye=[{label:`Asia Pacific`,regions:[{id:`sin1`,label:`Singapore`},{id:`hkg1`,label:`Hong Kong`},{id:`icn1`,label:`Seoul`},{id:`hnd1`,label:`Tokyo`},{id:`kix1`,label:`Osaka`},{id:`bom1`,label:`Mumbai`},{id:`syd1`,label:`Sydney`}]},{label:`Europe`,regions:[{id:`fra1`,label:`Frankfurt`},{id:`cdg1`,label:`Paris`},{id:`lhr1`,label:`London`},{id:`arn1`,label:`Stockholm`},{id:`dub1`,label:`Dublin`}]},{label:`North America`,regions:[{id:`iad1`,label:`Washington, D.C.`},{id:`sfo1`,label:`San Francisco`},{id:`pdx1`,label:`Portland`},{id:`cle1`,label:`Cleveland`},{id:`yul1`,label:`Montréal`}]},{label:`Other`,regions:[{id:`gru1`,label:`São Paulo`},{id:`cpt1`,label:`Cape Town`},{id:`dxb1`,label:`Dubai`}]}];function be(){return w({queryKey:N.network.pools,queryFn:e=>M(`/network/pools`,{signal:D(e)}).then(E),staleTime:A.staleTime,gcTime:A.gcTime})}function xe(){let e=T();return P({mutationFn:e=>M(`/network/pools`,{method:`POST`,body:JSON.stringify(e)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),l.success(`Proxy pool created`)},onError:e=>{l.error(`Could not create the proxy pool.`,j(e))}})}function Se(){let e=T();return P({mutationFn:e=>M(`/network/pools/relay/deploy`,{method:`POST`,body:JSON.stringify(e)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools})}})}function Ce(){return P({mutationFn:e=>M(`/network/pools/test-batch`,{method:`POST`,body:JSON.stringify({targets:e})})})}function we(){let e=T();return P({mutationFn:({poolId:e,request:t})=>M(`/network/pools/${encodeURIComponent(e)}`,{method:`PATCH`,body:JSON.stringify(t)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),l.success(`Proxy updated`)},onError:e=>{l.error(`Could not update the proxy pool.`,j(e))}})}function Te(e){return w({queryKey:[...N.network.pools,e,`health-events`],queryFn:t=>M(`/network/pools/${encodeURIComponent(e??``)}/health-events`,{signal:D(t)}),enabled:!!e,...A,refetchInterval:k.status})}function Ee(){let e=T();return P({mutationFn:e=>M(`/network/pools/${encodeURIComponent(e)}/recover`,{method:`POST`,body:`{}`}),onSuccess:async(t,n)=>{await Promise.all([e.invalidateQueries({queryKey:N.network.pools}),e.invalidateQueries({queryKey:[...N.network.pools,n,`health-events`]})]),l.success(`Proxy pool recovered`)},onError:e=>{l.error(`Could not recover the proxy pool.`,j(e))}})}function De(){let e=T();return P({mutationFn:e=>M(`/network/pools/${encodeURIComponent(e)}`,{method:`DELETE`}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),l.success(`Proxy pool deleted`)},onError:e=>{l.error(`Could not delete the proxy pool.`,j(e))}})}function Oe(){let e=T();return P({mutationFn:({poolId:e,providerId:t})=>M(`/network/pools/${encodeURIComponent(e)}/provider-probe`,{method:`POST`,body:JSON.stringify({providerId:t})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools})}})}function ke(){return P({mutationFn:({providerId:e,targets:t})=>M(`/network/pools/test-batch/provider`,{method:`POST`,body:JSON.stringify({providerId:e,targets:t})})})}function Ae(){let e=T();return P({mutationFn:e=>M(`/network/pools/${encodeURIComponent(e)}/health-check`,{method:`POST`,body:`{}`}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),l.success(`Health check complete`)},onError:e=>{l.error(`Health check failed.`,j(e))}})}function je(){let e=T();return P({mutationFn:({poolId:e,bytes:t})=>M(`/network/pools/${encodeURIComponent(e)}/speed-test`,{method:`POST`,body:JSON.stringify({bytes:t})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools})}})}function Me(){let e=T();return P({mutationFn:({poolId:e,providerId:t})=>M(`/network/pools/${encodeURIComponent(e)}/cooldowns/clear`,{method:`POST`,body:JSON.stringify(t?{providerId:t}:{})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),l.success(`Provider cooldowns cleared`)},onError:e=>{l.error(`Could not clear provider cooldowns.`,j(e))}})}var B=t(n(),1),V=r(),H={cloudflare:{label:`Cloudflare Workers`,tokenLabel:`Cloudflare API token`,needsAccount:!0,host:`*.workers.dev`,hasRegion:!1},vercel:{label:`Vercel`,tokenLabel:`Vercel API token`,needsAccount:!1,host:`*.vercel.app`,hasRegion:!0},deno:{label:`Deno Deploy`,tokenLabel:`Deno Deploy token`,needsAccount:!1,host:`*.deno.dev`,hasRegion:!1}},Ne=ye.flatMap(e=>e.regions.map(t=>({value:t.id,label:`${e.label} — ${t.label}`})));function Pe({onClose:e}){let t=Se(),[n,r]=(0,B.useState)(`cloudflare`),[i,a]=(0,B.useState)(ve),[o,u]=(0,B.useState)(``),[d,f]=(0,B.useState)(``),[p,m]=(0,B.useState)(``),[h,g]=(0,B.useState)(null),_=H[n],y=o.trim().length>0&&(!_.needsAccount||d.trim().length>0);return(0,V.jsx)(v,{open:!0,onClose:e,title:`Deploy Relay`,description:`Run outbound traffic through a hosted relay (Cloudflare, Vercel, Deno).`,size:`md`,children:(0,V.jsxs)(ce,{gap:`12px`,children:[(0,V.jsxs)(`p`,{className:`text-badge text-text-tertiary m-0 flex gap-3`,children:[(0,V.jsx)(ne,{size:13,className:`shrink-0 mt-0.5`}),(0,V.jsxs)(`span`,{children:[`Deploys a small relay worker to your own `,_.label,` account and registers its URL (`,(0,V.jsx)(`code`,{children:_.host}),`) as an active HTTP pool. Your API token is used only for the deploy and is never stored.`]})]}),(0,V.jsx)(se,{label:`Relay host`,id:`relay-target`,value:n,onValueChange:e=>r(e),options:O.map(e=>({value:e,label:H[e].label}))}),(0,V.jsx)(I,{label:_.tokenLabel,id:`relay-token`,type:`password`,value:o,placeholder:`Paste a deploy token`,onChange:e=>u(e.target.value)}),_.needsAccount?(0,V.jsx)(I,{label:`Account ID`,id:`relay-account`,value:d,placeholder:`Cloudflare account id`,onChange:e=>f(e.target.value)}):null,(0,V.jsx)(I,{label:`Project name (optional)`,id:`relay-project`,value:p,placeholder:`e.g. cartethyia-relay`,onChange:e=>m(e.target.value)}),_.hasRegion?(0,V.jsx)(se,{label:`Deploy region`,id:`relay-region`,value:i,onValueChange:e=>a(e),options:Ne}):null,_.hasRegion?(0,V.jsx)(`p`,{className:`text-badge text-text-tertiary m-0`,children:`Sets the region on the Vercel project, which is what decides the country outbound traffic leaves from. A region sent on the deployment alone is accepted but does not move the Function.`}):null,(0,V.jsxs)(`div`,{className:`flex items-center gap-5`,children:[(0,V.jsx)(c,{variant:`primary`,size:`sm`,onClick:()=>{y&&t.mutate({target:n,token:o.trim(),..._.needsAccount&&d.trim()?{accountId:d.trim()}:{},...p.trim()?{projectName:p.trim()}:{},..._.hasRegion?{region:i}:{}},{onSuccess:e=>{g(e.relayUrl),u(``),l.success(`Relay deployed to ${e.relayUrl} and registered as a pool.`)},onError:e=>l.error(j(e,`Relay deploy failed.`))})},disabled:!y||t.isPending,children:t.isPending?`Deploying…`:`Deploy relay`}),h?(0,V.jsxs)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Registered pool at `,(0,V.jsx)(`code`,{children:h})]}):null]}),t.isError?(0,V.jsxs)(`p`,{className:`text-badge text-red m-0 flex gap-3`,children:[(0,V.jsx)(s,{size:13,className:`shrink-0 mt-0.5`}),(0,V.jsx)(`span`,{children:j(t.error,`Relay deploy failed.`)})]}):null]})})}function Fe(e,t){if(e!==void 0)return e.endpoint===``||e.endpoint===(t??``)?e.result:void 0}function Ie(e,t,n){switch(t){case`name`:return(e.label||e.endpoint).toLowerCase();case`family`:return e.family===void 0||e.family===null||e.family===``?null:e.family.toLowerCase();case`address`:return e.egressIp??null;case`load`:return n??null}}function Le(e,t,n,r){let i=n===`asc`?1:-1;return[...e].sort((e,n)=>{let a=Ie(e,t,r(e)),o=Ie(n,t,r(n));return a===null&&o===null?0:a===null?1:o===null?-1:typeof a==`number`&&typeof o==`number`?(a-o)*i:String(a).localeCompare(String(o))*i})}function U(e,t){let n=e.filter(e=>e.status===`active`),r=n.reduce((e,t)=>e+t.maxInflight,0),i=t===void 0?n.reduce((e,t)=>e+(t.inflight??0),0):n.reduce((e,n)=>e+(t.get(n.id)??0),0),a=0,o=0;for(let e of n)(t===void 0?e.inflight??0:t.get(e.id)??0)>=e.maxInflight?o+=1:a+=1;let s=null,c=Date.now(),l=e=>{if(!e)return;let t=Date.parse(e);if(Number.isNaN(t))return;let n=t-c;n<=0||(s===null||n<s)&&(s=n)};for(let t of e){l(t.cooldownUntil);for(let e of t.providerCooldowns??[])l(e.until)}let u=n.filter(e=>e.lastLatencyMs!==void 0&&Number.isFinite(e.lastLatencyMs)),d=u.length===0?null:Math.round(u.reduce((e,t)=>e+(t.lastLatencyMs??0),0)/u.length);return{totalPools:e.length,active:n.length,cooldown:e.filter(e=>e.status===`cooldown`).length,totalMaxConcurrency:r,usedInflight:i,availableCapacity:Math.max(0,r-i),routablePools:a,saturatedPools:o,soonestCooldownMs:s,avgLatencyMs:d,measuredPools:u.length}}var W=[`http`,`https`,`socks5`];function G(e){return/^[a-z][a-z0-9+.-]*:\/\//i.test(e.trim())}function Re(e,t){let n=e.trim();return t===null||G(n)?n:`${t}://${n}`}function K(e){return e.find(e=>e.trim()!==``)}function q(e){let t=e.trim().toLowerCase();return t.startsWith(`https://`)?`https`:t.startsWith(`socks5://`)||t.startsWith(`socks://`)?`socks5`:`http`}var ze=1024**3;function Be(e){let t=e.trim();if(t===``)return null;let n=Number(t);return!Number.isFinite(n)||n<=0?null:Math.max(1,Math.round(n*ze))}function J(e,t,n){let r=new Map;if(t.trim().toLowerCase()===``||n<=0)return r;let i=Math.floor(e/n),a=e-i*n;for(let e=0;e<n;e+=1){let t=e===n-1?a:0;r.set(e,i+t)}return r}var Ve=4,He=`cartethyia_proxy_test_payload`,Ue=`cartethyia_proxy_check_results`,We=[{value:`url`,label:`Test URL`},{value:`opencode`,label:`Test OpenCode`}],Ge=`opencode`,Ke=4,qe=`Mysterious Proxy`;function Y(e){return e.avgLatencyMs===null?`no measurement yet`:`avg across ${e.measuredPools} enabled ${e.measuredPools===1?`pool`:`pools`}`}function Je(e){let t=e.endpoint||``,n=t.includes(`://`)?t:`${e.kind}://${t}`,r={"https:":`443`,"http:":`80`,"socks5:":`1080`,"socks:":`1080`};try{let e=new URL(n),t=e.port||r[e.protocol]||``,i=`${e.hostname}${t?`:${t}`:``}`;return{name:i,endpoint:`${e.protocol}//${i}${e.pathname===`/`?``:e.pathname}${e.search}`}}catch{return{name:e.label||t,endpoint:t}}}function X(e){return e.label||Je(e).name||e.id}var Z=1024**3;function Ye(e){if(e.lastSpeedtestStatus===void 0||e.lastSpeedtestAt===void 0)return;let t=e.lastSpeedtestDurationMs??0,n=e.lastSpeedtestBytes??0,r=t>0?n/(t/1e3):void 0;return{poolId:e.id,status:e.lastSpeedtestStatus,bytes:n,durationMs:t,...r===void 0?{}:{bytesPerSecond:r,megabitsPerSecond:r*8/1e6},...e.lastSpeedtestError?{errorMessage:e.lastSpeedtestError}:{},measuredAt:e.lastSpeedtestAt}}function Xe(e,t){if(!e)return t;if(!t)return e;let n=e.measuredAt?new Date(e.measuredAt).getTime():0;return(t.measuredAt?new Date(t.measuredAt).getTime():0)>=n?t:e}var Ze=[{value:String(he),label:`1 MB`},{value:String(_e),label:`5 MB`},{value:`50000000`,label:`50 MB`},{value:String(ge),label:`100 MB`}];function Qe({pool:e,onClose:t,actionsRef:n}){let r=we(),i=ke(),s=Ae(),[d,f]=(0,B.useState)(e.label??``),[p,m]=(0,B.useState)(e.family??``),[h,g]=(0,B.useState)(e.endpoint??``),[_,v]=(0,B.useState)(String(e.maxInflight??10)),[y,ee]=(0,B.useState)(String(e.weight??100)),[b,x]=(0,B.useState)(e.quotaBytes?String(Math.round(e.quotaBytes/Z*1e3)/1e3):``),[S,C]=(0,B.useState)(null),[w,T]=(0,B.useState)(!1),E=h.trim()===e.endpoint,D=async()=>{T(!0),C(null);try{if(E){let t=await s.mutateAsync(e.id),n=t.status===`healthy`||t.status===`reachable`;C({ok:n,message:t.status===`healthy`?`Connected in ${t.latencyMs??0}ms`:t.errorMessage??`Connection failed`});return}let t=[{kind:e.kind,endpoint:h.trim(),...e.family===null||e.family===void 0?{}:{family:e.family}}],[n]=await i.mutateAsync({providerId:Ge,targets:t}),r=n?.result;if(!r){C({ok:!1,message:`Probe returned no result`});return}let a=r.status===`allowed`||r.status===`throttled`;C({ok:a,message:r.reason??(r.status===`allowed`?`Reachable${r.latencyMs===void 0?``:` in ${r.latencyMs}ms`}`:r.status===`throttled`?`Reachable; rate limit spent`:`Probe could not complete`)})}catch(e){C({ok:!1,message:j(e,`Connection failed`)})}finally{T(!1)}},O=Be(b),k=async()=>{await r.mutateAsync({poolId:e.id,request:{...d.trim()===e.label?{}:{label:d.trim()||void 0},...p.trim()===(e.family??``)?{}:{family:p.trim()||null},...h.trim()!==e.endpoint&&h.trim()!==``?{endpoint:h.trim()}:{},...Number(_)===e.maxInflight?{}:{maxInflight:Number(_)},...Number(y)===e.weight?{}:{weight:Number(y)},...O===(e.quotaBytes??null)?{}:{quotaBytes:O}}}),l.success(`Proxy updated`),t()};return(0,B.useEffect)(()=>{n?.((0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(c,{variant:`secondary`,size:`sm`,onClick:t,children:`Cancel`}),(0,V.jsx)(c,{variant:`primary`,size:`sm`,disabled:r.isPending||!h.trim(),onClick:()=>void k(),children:`Save`})]}))}),(0,V.jsxs)(ce,{gap:`12px`,children:[(0,V.jsx)(`div`,{children:(0,V.jsx)(I,{label:`Name`,value:d,onChange:e=>f(e.target.value)})}),(0,V.jsx)(`div`,{children:(0,V.jsx)(I,{label:`Family`,value:p,placeholder:`e.g. residential-id`,onChange:e=>m(e.target.value)})}),(0,V.jsx)(`div`,{children:(0,V.jsx)(I,{label:`Endpoint`,value:h,onChange:e=>g(e.target.value),className:`font-mono tabular-nums`})}),(0,V.jsxs)(`div`,{className:`grid grid-cols-2 gap-5`,children:[(0,V.jsx)(`div`,{children:(0,V.jsx)(I,{label:`Max concurrent`,type:`number`,min:1,value:_,onChange:e=>v(e.target.value)})}),(0,V.jsx)(`div`,{children:(0,V.jsx)(I,{label:`Weight`,type:`number`,min:1,value:y,onChange:e=>ee(e.target.value)})})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(I,{label:`Bandwidth quota (GB, blank = unmetered)`,type:`number`,min:.001,step:`0.1`,value:b,onChange:e=>x(e.target.value)}),(0,V.jsx)(`div`,{className:`text-micro text-text-tertiary mt-2`,children:O===null?`No quota — the bar shows a running total only.`:`Bar turns orange at 80% and red once ${u(O)} is exceeded.`})]}),S&&(0,V.jsx)(`div`,{className:`rounded-inset px-6 py-4 text-badge font-semibold ${S.ok?`bg-green-soft text-green`:`bg-red-soft text-red`}`,children:S.message}),(0,V.jsx)(`div`,{children:(0,V.jsx)(c,{variant:`secondary`,size:`sm`,disabled:w,icon:w?(0,V.jsx)(a,{size:13,className:`animate-spin`}):(0,V.jsx)(o,{size:13}),onClick:()=>void D(),children:w?`Testing…`:`Test connection`})})]})}function $e({endpoint:e,chip:t,onChipChange:n}){return(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,role:`group`,"aria-label":`Scheme for the first endpoint`,children:[(0,V.jsx)(`span`,{className:`text-badge text-text-secondary`,children:`Scheme`}),W.map(r=>{let i=t===r;return(0,V.jsxs)(c,{type:`button`,variant:i?`primary`:`secondary`,size:`sm`,disabled:e===void 0,"aria-pressed":i,"data-scheme":r,onClick:()=>n(i?null:r),className:`font-mono`,children:[r,`://`]},r)}),t!==null&&(0,V.jsxs)(`span`,{className:`text-badge text-text-tertiary`,children:[`→ `,Re(e??``,t)]})]})}function et({onClose:e,actionsRef:t,onProbeResult:n,onHealthResult:r}){let i=xe(),a=Ce(),o=ke(),[s,u]=(0,B.useState)(``),[d,f]=(0,B.useState)(``),[p,m]=(0,B.useState)(``),[h,g]=(0,B.useState)(null),[_,v]=(0,B.useState)([]),[y,ee]=(0,B.useState)({}),[b,x]=(0,B.useState)({}),[S,C]=(0,B.useState)(!1),[w,T]=(0,B.useState)(null),E=s.split(`
|
|
2
2
|
`).map(e=>e.trim()).filter(Boolean),D=K(E),O=(0,B.useMemo)(()=>w===null||D===void 0?E:E.map((e,t)=>e===D&&t===0?Re(e,w):e),[E,w,D]),k=E.length>100,A=Be(p),M=(0,B.useMemo)(()=>O.map(e=>({kind:q(e),endpoint:e})),[O]),N=async()=>{try{let e=await navigator.clipboard.readText();e&&u(t=>t?`${t}\n${e}`:e)}catch{l.error(`Paste failed`,`Clipboard access denied`)}},P=async()=>{if(M.length!==0){v([`Testing ${M.length} proxy target(s)…`]);try{let e=await a.mutateAsync(M),t=e.map(e=>{let t=e.result.status===`healthy`||e.result.status===`reachable`,n=e.result.latencyMs===void 0?``:` · ${e.result.latencyMs}ms`,r=e.result.egressIp?` · ${e.result.egressIp}`:``,i=t?``:` · ${e.result.errorMessage??e.result.status}`;return`${t?`OK `:`FAIL`} ${e.endpoint}${n}${r}${i}`}),n=e.filter(e=>e.result.status===`healthy`||e.result.status===`reachable`).length;x(t=>{let n={...t};for(let t of e)n[t.endpoint]=t.result;return n}),v([`${n}/${e.length} reachable`,...t]),n===e.length?l.success(`All ${e.length} proxies reachable`):l.error(`${e.length-n} of ${e.length} proxies failed`)}catch(e){v([`Test failed: ${j(e,`batch probe failed`)}`]),l.error(`Test failed`,j(e,`batch probe failed`))}}},te=async()=>{if(M.length!==0){v([`Testing ${M.length} proxy target(s) against OpenCode…`]);try{let e=await o.mutateAsync({providerId:Ge,targets:M}),t=e.map(e=>{let{status:t,latencyMs:n,reason:r}=e.result,i=n===void 0?``:` · ${n}ms`,a=r===void 0?``:` · ${r}`;return`${t===`allowed`?`OK `:t===`blocked`?`BLOCK`:`FAIL`} ${e.endpoint}${i}${a}`});ee(t=>{let n={...t};for(let t of e)n[t.endpoint]=t.result;return n});let n=e.filter(e=>e.result.status===`allowed`).length,r=e.filter(e=>e.result.status===`blocked`).length;v([`${n}/${e.length} allowed · ${r} blocked`,...t]),r===0&&n===e.length?l.success(`OpenCode accepted all ${e.length} proxies`):l.error(`OpenCode: ${n} allowed · ${r} blocked`)}catch(e){v([`Test failed: ${j(e,`provider probe failed`)}`]),l.error(`Test failed`,j(e,`provider probe failed`))}}};return(0,B.useEffect)(()=>{t?.((0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(c,{variant:`secondary`,type:`button`,onClick:e,children:`Cancel`}),(0,V.jsx)(c,{variant:`primary`,type:`submit`,form:`add-proxy-form`,disabled:S||E.length===0,children:S?`Adding…`:`Add ${E.length} Prox${E.length===1?`y`:`ies`}`})]}))},[t,S,E.length,e]),(0,V.jsxs)(`form`,{id:`add-proxy-form`,onSubmit:async t=>{if(t.preventDefault(),E.length!==0){g(null),C(!0);try{let t=A===null?new Map:J(A,d,O.length),a=Array(E.length),o=0,s=async()=>{for(;o<E.length;){let e=o++,s=O[e];try{let o=await i.mutateAsync({kind:q(s),endpoint:s,...t.has(e)?{quotaBytes:t.get(e)}:{},...d.trim()===``?{}:{family:d.trim()}}),c=y[s],l=b[s];o?.id&&(l!==void 0&&r?.(o.id,l),c!==void 0&&n?.(o.id,c)),a[e]={ok:!0}}catch(t){a[e]={ok:!1,error:j(t,`Proxy pool creation failed`)}}}};await Promise.all(Array.from({length:Math.min(Ve,E.length)},()=>s()));let c=[],f=0;for(let[e,t]of a.entries())t.ok?f++:c.length<3&&c.push(`${E[e].slice(0,48)}…: ${t.error}`);let p=E.length-f,m=a.find(e=>!e.ok)?.error;f>0&&l.success(`Added ${f} proxy pool(s)`,p?`${p} failed: ${m??`see the import details`}`:void 0),p>0&&f===0&&l.error(`Failed to create pool`,m??`See the import details`),p>0&&g(c.join(`
|
|
3
3
|
`)),f>0&&(u(``),e())}finally{C(!1)}}},className:`flex flex-col gap-4`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,V.jsx)(`label`,{htmlFor:`proxy-endpoints`,className:`text-caption font-semibold text-text-primary`,children:`Proxy endpoints`}),(0,V.jsx)(c,{variant:`secondary`,size:`sm`,type:`button`,onClick:N,children:`Paste`})]}),(0,V.jsx)(`textarea`,{id:`proxy-endpoints`,value:s,onChange:e=>u(e.target.value),placeholder:`http://proxy.example:8080
|
|
4
4
|
https://proxy.example:8443
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{r as i}from"./terminal-Bd4ee8TA.js";import{C as a,O as o,b as s,l as c,s as l}from"./numbers-Bs4LOOuf.js";import{t as ee}from"./chevron-right-BXIy5l3h.js";import{t as u}from"./eye-off-Bk5g2luF.js";import{i as d,n as f,r as p,t as m}from"./state-DYdQmdAl.js";import{t as h}from"./dialog-BtpsJU98.js";import{t as g}from"./refresh-cw-BqJFk4sU.js";import{t as _}from"./rotate-ccw-CufcqITi.js";import{t as te}from"./trash-Cppn5c3R.js";import{l as v}from"./query-keys-D7wX2vM5.js";import{R as y}from"./entry-Dj9AR0gY.js";import{n as b,t as ne}from"./card--AtFedAq.js";import{t as x}from"./badge-6uzDDvqs.js";import{t as S}from"./select-DsX5QT8K.js";import{t as C}from"./ProviderIcon-CmfzxpVM.js";import{t as w}from"./switch-CidSfbG7.js";import{t as T}from"./stack-DwLmjUFK.js";import{n as E}from"./inline-BcNGF8Gr.js";import{t as D}from"./layout-C8mer_Ak.js";import{a as O,i as k,n as A,o as j,r as M,s as N,t as P}from"./quota-DZGyp0N5.js";import{a as F,c as I,d as L,f as R,i as z,l as B,n as V,o as H,p as U,r as W,s as G,t as K,u as q}from"./HealthEventsModal-qomXThxX.js";var re=e(`calendar-check`,[[`path`,{d:`M8 2v3`,key:`1ioesn`}],[`path`,{d:`M16 2v3`,key:`otl347`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}],[`path`,{d:`M3 9h18`,key:`1pudct`}],[`path`,{d:`m9 15 2 2 4-4`,key:`1grp1n`}]]),ie=e(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]),J=e(`clock-3`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6h4`,key:`135r8i`}]]),Y=e(`zap`,[[`path`,{d:`M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z`,key:`1v7up4`}]]),X=t(n(),1),Z=r();function Q(e){return!!(e.quota?.windows.length&&e.quota.windows.every(e=>e.remainingPercent!==null&&e.remainingPercent<=0))}function $(e){let t=e.quota?.windows.map(e=>e.resetsAt?new Date(e.resetsAt).getTime():1/0)??[];return Math.min(...t,1/0)}function ae({account:e,onClose:t}){let n=z(e.id,!0),r=q(e.id),i=n.data?.credits??[],a=e=>e?new Date(e).toLocaleString():`—`,o=e=>e?new Date(e).toLocaleString():`—`,s=e=>{if(!e)return``;let t=new Date(e).getTime()-Date.now();if(!Number.isFinite(t))return``;if(t<=0)return`expired`;let n=Math.floor(t/864e5);if(n>=1)return`in ${n}d`;let r=Math.floor(t/36e5);return r>=1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))}m`};return(0,Z.jsx)(h,{open:!0,onClose:t,size:`lg`,title:`Saved Rate-Limit Resets — ${e.name}`,children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-6 rounded-control border border-inner-border bg-surface-2 px-8 py-6`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Z.jsx)(Y,{size:14,className:`text-status-success`}),(0,Z.jsx)(`span`,{className:`text-body font-semibold`,children:`Available resets`})]}),(0,Z.jsx)(`p`,{className:`mt-2 text-text-tertiary text-badge leading-normal`,children:`Each credit lifts a spent rate-limit window before its natural reset.`})]}),(0,Z.jsxs)(x,{tone:n.data&&n.data.availableCount>0?`ok`:`disabled`,dot:!0,children:[n.data?.availableCount??0,` reset`,(n.data?.availableCount??0)===1?``:`s`]})]}),n.isPending?(0,Z.jsx)(p,{compact:!0,label:`Reading saved resets…`}):n.isError?(0,Z.jsx)(f,{compact:!0,message:`Failed to read saved resets`,onRetry:()=>void n.refetch()}):i.length===0?(0,Z.jsx)(m,{compact:!0,title:`No saved resets`,message:`This account has no saved rate-limit reset credits right now.`,icon:(0,Z.jsx)(Y,{size:20})}):(0,Z.jsx)(`div`,{className:`max-h-170 overflow-y-auto rounded-control border border-inner-border`,children:(0,Z.jsx)(D,{headers:[`Status`,`Title`,`Granted`,`Expires`,``],children:i.map(e=>{let t=(e.status??`available`)===`available`,n=s(e.expiresAt);return(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`td`,{className:`whitespace-nowrap align-middle`,children:(0,Z.jsx)(x,{tone:t?`ok`:e.status===`expired`?`disabled`:`warn`,children:e.status??`available`})}),(0,Z.jsx)(`td`,{className:`text-caption font-medium whitespace-nowrap align-middle text-text-primary`,children:e.title??`Rate-limit reset`}),(0,Z.jsx)(`td`,{className:`text-badge whitespace-nowrap tabular-nums align-middle text-text-secondary`,children:a(e.grantedAt)}),(0,Z.jsxs)(`td`,{className:`text-badge whitespace-nowrap tabular-nums align-middle text-text-secondary`,children:[o(e.expiresAt),n&&(0,Z.jsxs)(`span`,{className:`ml-3 text-text-tertiary`,children:[`(`,n,`)`]})]}),(0,Z.jsx)(`td`,{className:`whitespace-nowrap text-right align-middle`,children:(0,Z.jsx)(c,{size:`sm`,variant:t?`primary`:`secondary`,disabled:!t||r.isPending,onClick:()=>r.mutate({creditId:e.id},{onSuccess:e=>{e.ok?l.success(e.message??`Rate limit reset applied`):l.error(e.message??`Rate limit reset failed`)},onError:e=>{l.error(v(e,`Unable to redeem rate-limit reset`))}}),children:`Use`})})]},e.id)})})}),(0,Z.jsx)(E,{justify:`flex-end`,gap:`0px`,children:(0,Z.jsx)(c,{variant:`secondary`,size:`sm`,onClick:t,children:`Close`})})]})})}function oe({accounts:e}){let t=(0,X.useMemo)(()=>{let t=new Map;for(let n of e){if(!V(n.provider))continue;let e=t.get(n.provider);e?e.count+=1:t.set(n.provider,{id:n.provider,label:n.providerName||n.provider,count:1})}return[...t.values()]},[e]),[n,r]=(0,X.useState)(``),i=(t.find(e=>e.id===n)??t[0])?.id??``,o=R(i),s=i.length===0||o.isPending||t.length===0;return(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2.5`,"aria-label":`Daily growth actions`,children:[(0,Z.jsx)(`div`,{className:`min-w-0 w-67.5`,children:(0,Z.jsx)(S,{"aria-label":`Provider for the daily growth pass`,value:i,onValueChange:r,className:`w-full h-16`,options:t.length>0?t.map(e=>({value:e.id,label:`${e.label} · ${e.count}`})):[{value:``,label:`No buddy providers`}]})}),(0,Z.jsx)(c,{variant:`secondary`,size:`sm`,title:`Send the activity report, then claim the daily check-in, for every account of this provider`,"aria-label":`Run the daily growth pass for this provider`,disabled:s,className:`shrink-0`,icon:o.isPending?(0,Z.jsx)(a,{size:13,className:`animate-spin`}):(0,Z.jsx)(re,{size:13}),onClick:()=>o.mutate(void 0,{onSuccess:e=>{let t=e.data.filter(e=>!e.report.ok).length;t===0?l.success(e.message):l.error(`${e.message} — ${t} report${t===1?``:`s`} failed`)},onError:e=>l.error(v(e,`Unable to run the daily growth pass`))}),children:`Daily growth`})]})}function se({account:e,onToggle:t,onDelete:n,onShowHealth:r,onShowResets:o}){let u=G(e.id),d=L(e.id),f=V(e.provider),p=W(e.provider),m=z(e.id,p),h=e.quota,[g,y]=(0,X.useState)(0),b=h?.windows??[],x=j(b,g),S=x.pageCount;(0,X.useEffect)(()=>{y(e=>Math.min(e,Math.max(0,S-1)))},[S]);let T=u.isPending||d.isPending,E=m.data?.availableCount??0,[D,F]=(0,X.useState)(null),[I,R]=(0,X.useState)(!1),B=e.checkin?.attemptedToday??!1,H=`${D?D.state===`claimed`?`Checked in${D.credit===null?``:` +${D.credit}`}${D.streakDays===null?``:` · ${D.streakDays}d streak`}`:D.state===`already_claimed`?`Check-in attempted · already claimed`:D.state===`not_eligible`?`Check-in attempted · not eligible`:D.state===`event_ended`?`Check-in attempted · event ended`:`Check-in attempted · unavailable`:B?`Check-in attempted today`:`Check-in due`}${I?` · Reported today`:``}`,U=b.reduce((e,t)=>{let n=t.limit;if(typeof n!=`number`||!Number.isFinite(n))return e;let r=typeof t.remaining==`number`&&Number.isFinite(t.remaining)?t.remaining:typeof t.used==`number`&&Number.isFinite(t.used)?n-t.used:typeof t.remainingPercent==`number`&&Number.isFinite(t.remainingPercent)?n*t.remainingPercent/100:null;return r===null?e:e+Math.max(0,r)},0),K=(u.error?v(u.error,`Unable to refresh this account`):null)??h?.refreshError??h?.error??e.health?.sanitizedMessage,q=O(K),J=q===`Quota tracking is not supported for this provider`?null:q,Q=P(e.credentialHint,e.name),$=e.health?.status??`unknown`;return(0,Z.jsxs)(ne,{className:`flex h-full flex-col overflow-hidden`,"aria-busy":T,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5 px-7 py-4`,children:[(0,Z.jsx)(C,{icon:e.providerIcon,name:e.providerName,size:32}),(0,Z.jsxs)(`div`,{className:`flex-[1_1_160px]`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-4`,children:[(0,Z.jsx)(`div`,{className:`truncate text-caption font-bold text-text-primary text-body`,children:e.providerName}),h?.plan&&(0,Z.jsx)(`span`,{className:`shrink-0 rounded-chip bg-accent-soft px-4 py-1 text-micro font-semibold text-accent`,children:h.plan})]}),(0,Z.jsx)(`div`,{className:`truncate text-badge text-text-secondary`,children:Q.primary}),Q.secondary!==null&&(0,Z.jsx)(`div`,{className:`truncate text-micro text-text-tertiary`,children:Q.secondary}),h&&(0,Z.jsx)(`div`,{className:`truncate text-micro text-text-tertiary`,children:A(h.lastSuccessAt??h.fetchedAt)}),p&&(0,Z.jsx)(`div`,{className:`truncate text-micro flex items-center gap-2 text-text-tertiary`,title:`Saved rate-limit reset credits available on this account`,children:m.isPending?`Checking saved resets…`:E>0?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Y,{size:10,className:`text-status-success shrink-0`,"aria-hidden":`true`}),(0,Z.jsxs)(`span`,{className:`reset-credit-live`,children:[E,` rate-limit reset`,E===1?``:`s`,` available`]})]}):`No rate-limit resets available`}),f&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{title:`Daily growth state: manual pass result, else the sweep ledger for today`,className:`truncate text-micro text-text-tertiary`,children:d.isPending?`Running growth pass…`:H}),b.some(e=>typeof e.limit==`number`&&Number.isFinite(e.limit))&&(0,Z.jsxs)(`div`,{className:`truncate text-micro text-text-tertiary`,children:[`Total credits: `,U.toLocaleString(void 0,{maximumFractionDigits:2})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.75 gap-3 ml-auto`,children:[p&&(0,Z.jsx)(c,{variant:`ghost`,size:`icon`,className:`w-16 h-16 p-0`,title:m.isPending?`Checking saved rate-limit resets…`:E>0?`Saved rate-limit resets (${E} available)`:`Saved rate-limit resets`,"aria-label":`Open saved rate-limit resets for ${e.name}`,disabled:T,onClick:()=>o(e),children:(0,Z.jsx)(Y,{size:14})}),f&&(0,Z.jsx)(c,{variant:`ghost`,size:`icon`,className:`w-16 h-16 p-0`,title:`Daily growth pass (check-in + activity report) — ${H}`,"aria-label":`Run daily growth pass for ${e.name}`,disabled:T,onClick:()=>d.mutate(void 0,{onSuccess:e=>{let t=e.checkin.data;t&&F({state:t.state,credit:t.credit,streakDays:t.streakDays}),e.report.ok&&R(!0),e.ok?l.success(e.message):l.error(e.message)},onError:e=>{l.error(v(e,`Unable to run daily growth pass`))}}),children:d.isPending?(0,Z.jsx)(a,{size:14,className:`animate-spin`}):(0,Z.jsx)(re,{size:14})}),(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,title:$===`active`?`Health & Error Log`:`${$} — Inspect account health details`,"aria-label":$===`active`?`Health log for ${e.name}`:`Account is ${$} — inspect health details for ${e.name}`,disabled:T,onClick:()=>r(e),icon:(0,Z.jsx)(i,{size:12})}),(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,title:`Refresh quota`,"aria-label":`Refresh ${e.name} quota`,disabled:T,onClick:()=>u.mutate(),icon:u.isPending?(0,Z.jsx)(a,{size:12,className:`animate-spin`}):(0,Z.jsx)(_,{size:12})}),(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,title:`Delete account`,"aria-label":`Delete ${e.name}`,onClick:()=>n(e),className:`text-red`,icon:(0,Z.jsx)(te,{size:12})}),(0,Z.jsx)(w,{checked:e.active,disabled:u.isPending,onChange:n=>t(e,n),label:``,id:`switch-${e.id}`})]})]}),J&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-4 border-t border-inner-border px-8 py-5 text-center text-badge text-red`,role:`alert`,children:[(0,Z.jsx)(s,{size:13,className:`shrink-0`}),(0,Z.jsx)(`span`,{children:J})]}),h?.windows.length?(0,Z.jsxs)(`div`,{className:`quota-window-list flex flex-1 flex-col gap-4 border-t border-inner-border px-7 py-4.5`,children:[(0,Z.jsx)(`div`,{className:`quota-window-section-label text-micro font-bold tracking-label text-text-tertiary`,children:`QUOTA WINDOWS`}),x.items.map((e,t)=>{let n=e.remainingPercent??null,r=typeof e.limit==`number`&&Number.isFinite(e.limit)?e.limit:null,i=typeof e.used==`number`&&Number.isFinite(e.used)?e.used:r!==null&&e.usedPercent!==null&&e.usedPercent!==void 0?r*e.usedPercent/100:null,a=N(n),o=n===null?0:Math.max(0,Math.min(100,n)),s=e=>e.toLocaleString(void 0,{maximumFractionDigits:2}),c=e=>{let t=Math.round(e*10)/10;return t>0&&t<.1?`<0.1`:t.toLocaleString(void 0,{maximumFractionDigits:1})},l=M(e.label);return(0,Z.jsxs)(`div`,{className:`quota-window-row grid grid-cols-quota-window min-w-0 items-center gap-x-6 gap-y-2 max-small:grid-cols-[minmax(0,1fr)_auto] max-small:gap-x-4 max-small:gap-y-2.5`,children:[(0,Z.jsx)(`div`,{className:`quota-window-heading min-w-0 max-small:col-start-1`,children:(0,Z.jsx)(`span`,{className:`text-badge font-semibold text-text-primary`,children:l})}),(0,Z.jsx)(`div`,{className:`quota-bar-track quota-window-bar min-w-0 w-full h-5 rounded-tiny bg-inner-border overflow-hidden max-small:col-span-full max-small:row-start-2`,role:`progressbar`,"aria-label":`${l} remaining quota`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":n===null?void 0:o,"aria-valuetext":n===null?`Quota only`:`${c(n)}% remaining`,children:(0,Z.jsx)(`div`,{className:`quota-bar-fill h-full rounded-tiny transition-[width] duration-(--dur-macro) ease-spring`,style:{width:`${o}%`,background:a.bar}})}),(0,Z.jsx)(`span`,{className:`quota-window-remaining whitespace-nowrap text-badge font-bold tabular-nums max-small:col-start-2 max-small:row-start-1`,style:{color:a.text},children:n===null?`—`:`${c(n)}%`}),(0,Z.jsxs)(`div`,{className:`quota-window-details col-span-full flex min-w-0 items-center justify-end gap-6 text-micro text-text-tertiary max-small:row-start-3 max-small:flex-wrap max-small:justify-between max-small:gap-4`,children:[(0,Z.jsx)(`span`,{className:`quota-window-usage mr-auto tabular-nums max-small:min-w-0`,children:i!==null&&r!==null?`${s(i)} / ${s(r)} Credits`:`Quota only`}),e.resetsAt&&(0,Z.jsx)(`span`,{className:`quota-window-reset whitespace-nowrap tabular-nums text-right max-small:ml-auto`,children:k(e.resetsAt,e.recurring)})]})]},`${e.kind??e.label}:${e.resetsAt??`none`}:${t}`)}),x.pageCount>1&&(0,Z.jsxs)(`nav`,{"aria-label":`Quota windows for ${e.name}`,className:`quota-window-pagination mt-auto flex items-center justify-between gap-4 border-t border-inner-border pt-4 max-small:flex-wrap`,children:[(0,Z.jsxs)(`span`,{"aria-live":`polite`,className:`text-micro text-text-tertiary`,children:[`Showing `,x.startIndex+1,`–`,x.startIndex+x.items.length,` of `,b.length]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,"aria-label":`Previous quota windows for ${e.name}`,disabled:x.page===0,icon:(0,Z.jsx)(ie,{size:13}),onClick:()=>y(x.page-1),className:`h-14 px-4 py-0`,children:`Previous`}),(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,"aria-label":`Next quota windows for ${e.name}`,disabled:x.page>=x.pageCount-1,icon:(0,Z.jsx)(ee,{size:13}),onClick:()=>y(x.page+1),className:`h-14 px-4 py-0`,children:`Next`})]})]})]}):J?null:(0,Z.jsx)(`div`,{className:`border-t border-inner-border px-7 py-9 text-center text-badge text-text-tertiary`,children:T||e.pending?`Fetching quota…`:`No quota data`})]})}function ce(){let[e,t]=(0,X.useState)(`all`),[n,r]=(0,X.useState)(`all`),[i,a]=(0,X.useState)(!1),{data:s,isLoading:ee,isError:f,error:p,isFetching:h,dataUpdatedAt:_,refetch:te}=H(),v=(0,X.useMemo)(()=>[...s?.providers??[]].sort((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:`base`})),[s?.providers]),x=(0,X.useMemo)(()=>s?.accounts??[],[s?.accounts]),C=s?.refreshing??0,w=I(),E=U(),D=B(),O=F(),[k,A]=(0,X.useState)(null),[j,M]=(0,X.useState)(null),[N,P]=(0,X.useState)(null),L=(0,X.useMemo)(()=>{let t=x.filter(t=>{if(e!==`all`&&t.provider!==e)return!1;let r=!!t.quota?.windows.length;return n===`untracked`?!r:!(!r||n===`active`&&!t.active||n===`disabled`&&t.active)}),r=(e,t)=>e.providerName.localeCompare(t.providerName,void 0,{sensitivity:`base`})||e.name.localeCompare(t.name,void 0,{sensitivity:`base`});return[...t].sort(i?(e,t)=>$(e)-$(t)||r(e,t):r)},[n,x,i,e]),R=async(e,t)=>{try{await E.mutateAsync({id:e.id,active:t}),l.success(`${e.name} ${t?`enabled`:`disabled`}`)}catch(e){l.error(e instanceof Error?e.message:`Unable to update account`)}},z=async()=>{let e=x.filter(e=>e.active&&Q(e));await D.mutateAsync({ids:e.map(e=>e.id),active:!1}),l.success(`Disabled ${e.length} empty accounts`)},V=async()=>{let e=x.filter(e=>!e.active&&e.quota?.windows.some(e=>e.remainingPercent!==null&&e.remainingPercent>0));await D.mutateAsync({ids:e.map(e=>e.id),active:!0}),l.success(`Enabled ${e.length} available accounts`)},W=async e=>{await O.mutateAsync(e.id),l.success(`${e.name} deleted`)},G=_>0?new Date(_).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):`Not updated`,q=x.filter(Q).length;return(0,Z.jsxs)(T,{gap:`16px`,className:`dashboard-page min-h-0 flex-1`,children:[(0,Z.jsx)(ne,{children:(0,Z.jsxs)(b,{className:`flex flex-col gap-5`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-5`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-4`,children:[(0,Z.jsx)(S,{"aria-label":`Filter quota by provider`,value:e,onValueChange:t,className:`w-full h-16 max-small:w-80`,options:[{value:`all`,label:`All Providers`},...v.map(e=>({value:e.id,label:e.name}))]}),(0,Z.jsx)(S,{"aria-label":`Filter quota by account`,value:n,onValueChange:r,className:`w-full h-16 max-small:w-67.5`,options:[{value:`all`,label:`With quota`},{value:`active`,label:`Active`},{value:`disabled`,label:`Disabled`},{value:`untracked`,label:`No quota`}]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,Z.jsx)(c,{variant:i?`secondary`:`ghost`,size:`sm`,onClick:()=>a(e=>!e),"aria-pressed":i,icon:(0,Z.jsx)(J,{size:13}),children:`Expiring first`}),(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,className:`text-red`,disabled:q===0||h,onClick:()=>void z(),icon:(0,Z.jsx)(u,{size:13}),children:`Turn off Empty`}),(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,className:`text-green`,disabled:h,onClick:()=>void V(),icon:(0,Z.jsx)(o,{size:13}),children:`Turn on Available`})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-4 border-t border-inner-border pt-5`,children:[(0,Z.jsxs)(`span`,{className:`text-badge text-text-tertiary`,children:[L.length,` shown`,q>0?` · ${q} empty`:``]}),(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-x-5 gap-y-3 text-badge text-text-tertiary`,children:[C>0?`Refreshing ${C} account${C===1?``:`s`}…`:`Auto-refresh 60s · ${G}`,(0,Z.jsx)(oe,{accounts:x}),(0,Z.jsx)(c,{variant:`secondary`,size:`sm`,title:`Queue quota refresh`,"aria-label":`Queue quota refresh`,disabled:h||w.isPending||x.length===0,icon:(0,Z.jsx)(g,{size:13,className:w.isPending?`animate-spin`:void 0}),onClick:()=>w.mutate(x.map(e=>e.id),{onSuccess:e=>{l.success(e.failed===0?`Refreshed ${e.succeeded} quota${e.succeeded===1?``:`s`}`:`Refreshed ${e.succeeded}, ${e.failed} failed`)},onError:e=>l.error(e instanceof Error?e.message:`Unable to refresh quota`)}),children:`Refresh`})]})]})]})}),(0,Z.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-6`,children:ee?(0,Z.jsx)(d,{className:`min-h-0 flex flex-1 flex-col items-center justify-center`,kind:`loading`,title:`Loading quota data`,description:`Reading provider account limits…`}):f?(0,Z.jsx)(d,{className:`min-h-0 flex flex-1 flex-col items-center justify-center`,kind:`error`,title:`Unable to load quota data`,description:p instanceof Error?p.message:`Check the console session and retry.`,action:(0,Z.jsx)(c,{variant:`secondary`,onClick:()=>void te(),children:`Retry`})}):L.length===0?(0,Z.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-12 border border-dashed border-transparent rounded-card bg-transparent text-center`,children:(0,Z.jsx)(m,{title:`No account quota data`,message:`Nothing is reporting a quota window yet. Add a provider account and its limits will appear here.`})}):(0,Z.jsx)(`div`,{className:`quota-account-grid scroll-region min-h-0 flex-1 gap-6 [align-content:start]`,children:L.map(e=>(0,Z.jsx)(se,{account:e,onToggle:(e,t)=>void R(e,t),onDelete:e=>A(e),onShowHealth:e=>M(e),onShowResets:e=>P(e)},e.id))})}),j&&(0,Z.jsx)(K,{summary:{providerId:j.provider,accountId:j.id,title:j.name,status:j.health?.status??`unknown`,errorCategory:j.health?.lastErrorCategory??void 0,errorMessage:j.health?.sanitizedMessage??void 0,emptyMessage:`Status transitions, rate limits, quota refreshes, check-ins, and auto-recoveries will appear here.`},onClose:()=>M(null)}),N&&(0,Z.jsx)(ae,{account:N,onClose:()=>P(null)}),(0,Z.jsx)(y,{open:k!==null,onClose:()=>A(null),onConfirm:async()=>{k&&await W(k)},title:`Delete account?`,message:`Delete "${k?.name}"? This cannot be undone.`,confirmLabel:`Delete`,danger:!0})]})}export{ce as default};
|
|
1
|
+
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{r as i}from"./terminal-Bd4ee8TA.js";import{C as a,O as o,b as s,l as c,s as l}from"./numbers-Bs4LOOuf.js";import{t as ee}from"./chevron-right-BXIy5l3h.js";import{t as u}from"./eye-off-Bk5g2luF.js";import{i as d,n as f,r as p,t as m}from"./state-DYdQmdAl.js";import{t as h}from"./dialog-BtpsJU98.js";import{t as g}from"./refresh-cw-BqJFk4sU.js";import{t as _}from"./rotate-ccw-CufcqITi.js";import{t as te}from"./trash-Cppn5c3R.js";import{l as v}from"./query-keys-D7wX2vM5.js";import{R as y}from"./entry-CkryrIea.js";import{n as b,t as ne}from"./card--AtFedAq.js";import{t as x}from"./badge-6uzDDvqs.js";import{t as S}from"./select-BO6h8yNv.js";import{t as C}from"./ProviderIcon-CmfzxpVM.js";import{t as w}from"./switch-CidSfbG7.js";import{t as T}from"./stack-DwLmjUFK.js";import{n as E}from"./inline-BcNGF8Gr.js";import{t as D}from"./layout-C8mer_Ak.js";import{a as O,i as k,n as A,o as j,r as M,s as N,t as P}from"./quota-DZGyp0N5.js";import{a as F,c as I,d as L,f as R,i as z,l as B,n as V,o as H,p as U,r as W,s as G,t as K,u as q}from"./HealthEventsModal-Cjfc5WFS.js";var re=e(`calendar-check`,[[`path`,{d:`M8 2v3`,key:`1ioesn`}],[`path`,{d:`M16 2v3`,key:`otl347`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}],[`path`,{d:`M3 9h18`,key:`1pudct`}],[`path`,{d:`m9 15 2 2 4-4`,key:`1grp1n`}]]),ie=e(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]),J=e(`clock-3`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6h4`,key:`135r8i`}]]),Y=e(`zap`,[[`path`,{d:`M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z`,key:`1v7up4`}]]),X=t(n(),1),Z=r();function Q(e){return!!(e.quota?.windows.length&&e.quota.windows.every(e=>e.remainingPercent!==null&&e.remainingPercent<=0))}function $(e){let t=e.quota?.windows.map(e=>e.resetsAt?new Date(e.resetsAt).getTime():1/0)??[];return Math.min(...t,1/0)}function ae({account:e,onClose:t}){let n=z(e.id,!0),r=q(e.id),i=n.data?.credits??[],a=e=>e?new Date(e).toLocaleString():`—`,o=e=>e?new Date(e).toLocaleString():`—`,s=e=>{if(!e)return``;let t=new Date(e).getTime()-Date.now();if(!Number.isFinite(t))return``;if(t<=0)return`expired`;let n=Math.floor(t/864e5);if(n>=1)return`in ${n}d`;let r=Math.floor(t/36e5);return r>=1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))}m`};return(0,Z.jsx)(h,{open:!0,onClose:t,size:`lg`,title:`Saved Rate-Limit Resets — ${e.name}`,children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-6 rounded-control border border-inner-border bg-surface-2 px-8 py-6`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Z.jsx)(Y,{size:14,className:`text-status-success`}),(0,Z.jsx)(`span`,{className:`text-body font-semibold`,children:`Available resets`})]}),(0,Z.jsx)(`p`,{className:`mt-2 text-text-tertiary text-badge leading-normal`,children:`Each credit lifts a spent rate-limit window before its natural reset.`})]}),(0,Z.jsxs)(x,{tone:n.data&&n.data.availableCount>0?`ok`:`disabled`,dot:!0,children:[n.data?.availableCount??0,` reset`,(n.data?.availableCount??0)===1?``:`s`]})]}),n.isPending?(0,Z.jsx)(p,{compact:!0,label:`Reading saved resets…`}):n.isError?(0,Z.jsx)(f,{compact:!0,message:`Failed to read saved resets`,onRetry:()=>void n.refetch()}):i.length===0?(0,Z.jsx)(m,{compact:!0,title:`No saved resets`,message:`This account has no saved rate-limit reset credits right now.`,icon:(0,Z.jsx)(Y,{size:20})}):(0,Z.jsx)(`div`,{className:`max-h-170 overflow-y-auto rounded-control border border-inner-border`,children:(0,Z.jsx)(D,{headers:[`Status`,`Title`,`Granted`,`Expires`,``],children:i.map(e=>{let t=(e.status??`available`)===`available`,n=s(e.expiresAt);return(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`td`,{className:`whitespace-nowrap align-middle`,children:(0,Z.jsx)(x,{tone:t?`ok`:e.status===`expired`?`disabled`:`warn`,children:e.status??`available`})}),(0,Z.jsx)(`td`,{className:`text-caption font-medium whitespace-nowrap align-middle text-text-primary`,children:e.title??`Rate-limit reset`}),(0,Z.jsx)(`td`,{className:`text-badge whitespace-nowrap tabular-nums align-middle text-text-secondary`,children:a(e.grantedAt)}),(0,Z.jsxs)(`td`,{className:`text-badge whitespace-nowrap tabular-nums align-middle text-text-secondary`,children:[o(e.expiresAt),n&&(0,Z.jsxs)(`span`,{className:`ml-3 text-text-tertiary`,children:[`(`,n,`)`]})]}),(0,Z.jsx)(`td`,{className:`whitespace-nowrap text-right align-middle`,children:(0,Z.jsx)(c,{size:`sm`,variant:t?`primary`:`secondary`,disabled:!t||r.isPending,onClick:()=>r.mutate({creditId:e.id},{onSuccess:e=>{e.ok?l.success(e.message??`Rate limit reset applied`):l.error(e.message??`Rate limit reset failed`)},onError:e=>{l.error(v(e,`Unable to redeem rate-limit reset`))}}),children:`Use`})})]},e.id)})})}),(0,Z.jsx)(E,{justify:`flex-end`,gap:`0px`,children:(0,Z.jsx)(c,{variant:`secondary`,size:`sm`,onClick:t,children:`Close`})})]})})}function oe({accounts:e}){let t=(0,X.useMemo)(()=>{let t=new Map;for(let n of e){if(!V(n.provider))continue;let e=t.get(n.provider);e?e.count+=1:t.set(n.provider,{id:n.provider,label:n.providerName||n.provider,count:1})}return[...t.values()]},[e]),[n,r]=(0,X.useState)(``),i=(t.find(e=>e.id===n)??t[0])?.id??``,o=R(i),s=i.length===0||o.isPending||t.length===0;return(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2.5`,"aria-label":`Daily growth actions`,children:[(0,Z.jsx)(`div`,{className:`min-w-0 w-67.5`,children:(0,Z.jsx)(S,{"aria-label":`Provider for the daily growth pass`,value:i,onValueChange:r,className:`w-full h-16`,options:t.length>0?t.map(e=>({value:e.id,label:`${e.label} · ${e.count}`})):[{value:``,label:`No buddy providers`}]})}),(0,Z.jsx)(c,{variant:`secondary`,size:`sm`,title:`Send the activity report, then claim the daily check-in, for every account of this provider`,"aria-label":`Run the daily growth pass for this provider`,disabled:s,className:`shrink-0`,icon:o.isPending?(0,Z.jsx)(a,{size:13,className:`animate-spin`}):(0,Z.jsx)(re,{size:13}),onClick:()=>o.mutate(void 0,{onSuccess:e=>{let t=e.data.filter(e=>!e.report.ok).length;t===0?l.success(e.message):l.error(`${e.message} — ${t} report${t===1?``:`s`} failed`)},onError:e=>l.error(v(e,`Unable to run the daily growth pass`))}),children:`Daily growth`})]})}function se({account:e,onToggle:t,onDelete:n,onShowHealth:r,onShowResets:o}){let u=G(e.id),d=L(e.id),f=V(e.provider),p=W(e.provider),m=z(e.id,p),h=e.quota,[g,y]=(0,X.useState)(0),b=h?.windows??[],x=j(b,g),S=x.pageCount;(0,X.useEffect)(()=>{y(e=>Math.min(e,Math.max(0,S-1)))},[S]);let T=u.isPending||d.isPending,E=m.data?.availableCount??0,[D,F]=(0,X.useState)(null),[I,R]=(0,X.useState)(!1),B=e.checkin?.attemptedToday??!1,H=`${D?D.state===`claimed`?`Checked in${D.credit===null?``:` +${D.credit}`}${D.streakDays===null?``:` · ${D.streakDays}d streak`}`:D.state===`already_claimed`?`Check-in attempted · already claimed`:D.state===`not_eligible`?`Check-in attempted · not eligible`:D.state===`event_ended`?`Check-in attempted · event ended`:`Check-in attempted · unavailable`:B?`Check-in attempted today`:`Check-in due`}${I?` · Reported today`:``}`,U=b.reduce((e,t)=>{let n=t.limit;if(typeof n!=`number`||!Number.isFinite(n))return e;let r=typeof t.remaining==`number`&&Number.isFinite(t.remaining)?t.remaining:typeof t.used==`number`&&Number.isFinite(t.used)?n-t.used:typeof t.remainingPercent==`number`&&Number.isFinite(t.remainingPercent)?n*t.remainingPercent/100:null;return r===null?e:e+Math.max(0,r)},0),K=(u.error?v(u.error,`Unable to refresh this account`):null)??h?.refreshError??h?.error??e.health?.sanitizedMessage,q=O(K),J=q===`Quota tracking is not supported for this provider`?null:q,Q=P(e.credentialHint,e.name),$=e.health?.status??`unknown`;return(0,Z.jsxs)(ne,{className:`flex h-full flex-col overflow-hidden`,"aria-busy":T,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5 px-7 py-4`,children:[(0,Z.jsx)(C,{icon:e.providerIcon,name:e.providerName,size:32}),(0,Z.jsxs)(`div`,{className:`flex-[1_1_160px]`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-4`,children:[(0,Z.jsx)(`div`,{className:`truncate text-caption font-bold text-text-primary text-body`,children:e.providerName}),h?.plan&&(0,Z.jsx)(`span`,{className:`shrink-0 rounded-chip bg-accent-soft px-4 py-1 text-micro font-semibold text-accent`,children:h.plan})]}),(0,Z.jsx)(`div`,{className:`truncate text-badge text-text-secondary`,children:Q.primary}),Q.secondary!==null&&(0,Z.jsx)(`div`,{className:`truncate text-micro text-text-tertiary`,children:Q.secondary}),h&&(0,Z.jsx)(`div`,{className:`truncate text-micro text-text-tertiary`,children:A(h.lastSuccessAt??h.fetchedAt)}),p&&(0,Z.jsx)(`div`,{className:`truncate text-micro flex items-center gap-2 text-text-tertiary`,title:`Saved rate-limit reset credits available on this account`,children:m.isPending?`Checking saved resets…`:E>0?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Y,{size:10,className:`text-status-success shrink-0`,"aria-hidden":`true`}),(0,Z.jsxs)(`span`,{className:`reset-credit-live`,children:[E,` rate-limit reset`,E===1?``:`s`,` available`]})]}):`No rate-limit resets available`}),f&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{title:`Daily growth state: manual pass result, else the sweep ledger for today`,className:`truncate text-micro text-text-tertiary`,children:d.isPending?`Running growth pass…`:H}),b.some(e=>typeof e.limit==`number`&&Number.isFinite(e.limit))&&(0,Z.jsxs)(`div`,{className:`truncate text-micro text-text-tertiary`,children:[`Total credits: `,U.toLocaleString(void 0,{maximumFractionDigits:2})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.75 gap-3 ml-auto`,children:[p&&(0,Z.jsx)(c,{variant:`ghost`,size:`icon`,className:`w-16 h-16 p-0`,title:m.isPending?`Checking saved rate-limit resets…`:E>0?`Saved rate-limit resets (${E} available)`:`Saved rate-limit resets`,"aria-label":`Open saved rate-limit resets for ${e.name}`,disabled:T,onClick:()=>o(e),children:(0,Z.jsx)(Y,{size:14})}),f&&(0,Z.jsx)(c,{variant:`ghost`,size:`icon`,className:`w-16 h-16 p-0`,title:`Daily growth pass (check-in + activity report) — ${H}`,"aria-label":`Run daily growth pass for ${e.name}`,disabled:T,onClick:()=>d.mutate(void 0,{onSuccess:e=>{let t=e.checkin.data;t&&F({state:t.state,credit:t.credit,streakDays:t.streakDays}),e.report.ok&&R(!0),e.ok?l.success(e.message):l.error(e.message)},onError:e=>{l.error(v(e,`Unable to run daily growth pass`))}}),children:d.isPending?(0,Z.jsx)(a,{size:14,className:`animate-spin`}):(0,Z.jsx)(re,{size:14})}),(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,title:$===`active`?`Health & Error Log`:`${$} — Inspect account health details`,"aria-label":$===`active`?`Health log for ${e.name}`:`Account is ${$} — inspect health details for ${e.name}`,disabled:T,onClick:()=>r(e),icon:(0,Z.jsx)(i,{size:12})}),(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,title:`Refresh quota`,"aria-label":`Refresh ${e.name} quota`,disabled:T,onClick:()=>u.mutate(),icon:u.isPending?(0,Z.jsx)(a,{size:12,className:`animate-spin`}):(0,Z.jsx)(_,{size:12})}),(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,title:`Delete account`,"aria-label":`Delete ${e.name}`,onClick:()=>n(e),className:`text-red`,icon:(0,Z.jsx)(te,{size:12})}),(0,Z.jsx)(w,{checked:e.active,disabled:u.isPending,onChange:n=>t(e,n),label:``,id:`switch-${e.id}`})]})]}),J&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-4 border-t border-inner-border px-8 py-5 text-center text-badge text-red`,role:`alert`,children:[(0,Z.jsx)(s,{size:13,className:`shrink-0`}),(0,Z.jsx)(`span`,{children:J})]}),h?.windows.length?(0,Z.jsxs)(`div`,{className:`quota-window-list flex flex-1 flex-col gap-4 border-t border-inner-border px-7 py-4.5`,children:[(0,Z.jsx)(`div`,{className:`quota-window-section-label text-micro font-bold tracking-label text-text-tertiary`,children:`QUOTA WINDOWS`}),x.items.map((e,t)=>{let n=e.remainingPercent??null,r=typeof e.limit==`number`&&Number.isFinite(e.limit)?e.limit:null,i=typeof e.used==`number`&&Number.isFinite(e.used)?e.used:r!==null&&e.usedPercent!==null&&e.usedPercent!==void 0?r*e.usedPercent/100:null,a=N(n),o=n===null?0:Math.max(0,Math.min(100,n)),s=e=>e.toLocaleString(void 0,{maximumFractionDigits:2}),c=e=>{let t=Math.round(e*10)/10;return t>0&&t<.1?`<0.1`:t.toLocaleString(void 0,{maximumFractionDigits:1})},l=M(e.label);return(0,Z.jsxs)(`div`,{className:`quota-window-row grid grid-cols-quota-window min-w-0 items-center gap-x-6 gap-y-2 max-small:grid-cols-[minmax(0,1fr)_auto] max-small:gap-x-4 max-small:gap-y-2.5`,children:[(0,Z.jsx)(`div`,{className:`quota-window-heading min-w-0 max-small:col-start-1`,children:(0,Z.jsx)(`span`,{className:`text-badge font-semibold text-text-primary`,children:l})}),(0,Z.jsx)(`div`,{className:`quota-bar-track quota-window-bar min-w-0 w-full h-5 rounded-tiny bg-inner-border overflow-hidden max-small:col-span-full max-small:row-start-2`,role:`progressbar`,"aria-label":`${l} remaining quota`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":n===null?void 0:o,"aria-valuetext":n===null?`Quota only`:`${c(n)}% remaining`,children:(0,Z.jsx)(`div`,{className:`quota-bar-fill h-full rounded-tiny transition-[width] duration-(--dur-macro) ease-spring`,style:{width:`${o}%`,background:a.bar}})}),(0,Z.jsx)(`span`,{className:`quota-window-remaining whitespace-nowrap text-badge font-bold tabular-nums max-small:col-start-2 max-small:row-start-1`,style:{color:a.text},children:n===null?`—`:`${c(n)}%`}),(0,Z.jsxs)(`div`,{className:`quota-window-details col-span-full flex min-w-0 items-center justify-end gap-6 text-micro text-text-tertiary max-small:row-start-3 max-small:flex-wrap max-small:justify-between max-small:gap-4`,children:[(0,Z.jsx)(`span`,{className:`quota-window-usage mr-auto tabular-nums max-small:min-w-0`,children:i!==null&&r!==null?`${s(i)} / ${s(r)} Credits`:`Quota only`}),e.resetsAt&&(0,Z.jsx)(`span`,{className:`quota-window-reset whitespace-nowrap tabular-nums text-right max-small:ml-auto`,children:k(e.resetsAt,e.recurring)})]})]},`${e.kind??e.label}:${e.resetsAt??`none`}:${t}`)}),x.pageCount>1&&(0,Z.jsxs)(`nav`,{"aria-label":`Quota windows for ${e.name}`,className:`quota-window-pagination mt-auto flex items-center justify-between gap-4 border-t border-inner-border pt-4 max-small:flex-wrap`,children:[(0,Z.jsxs)(`span`,{"aria-live":`polite`,className:`text-micro text-text-tertiary`,children:[`Showing `,x.startIndex+1,`–`,x.startIndex+x.items.length,` of `,b.length]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,"aria-label":`Previous quota windows for ${e.name}`,disabled:x.page===0,icon:(0,Z.jsx)(ie,{size:13}),onClick:()=>y(x.page-1),className:`h-14 px-4 py-0`,children:`Previous`}),(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,"aria-label":`Next quota windows for ${e.name}`,disabled:x.page>=x.pageCount-1,icon:(0,Z.jsx)(ee,{size:13}),onClick:()=>y(x.page+1),className:`h-14 px-4 py-0`,children:`Next`})]})]})]}):J?null:(0,Z.jsx)(`div`,{className:`border-t border-inner-border px-7 py-9 text-center text-badge text-text-tertiary`,children:T||e.pending?`Fetching quota…`:`No quota data`})]})}function ce(){let[e,t]=(0,X.useState)(`all`),[n,r]=(0,X.useState)(`all`),[i,a]=(0,X.useState)(!1),{data:s,isLoading:ee,isError:f,error:p,isFetching:h,dataUpdatedAt:_,refetch:te}=H(),v=(0,X.useMemo)(()=>[...s?.providers??[]].sort((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:`base`})),[s?.providers]),x=(0,X.useMemo)(()=>s?.accounts??[],[s?.accounts]),C=s?.refreshing??0,w=I(),E=U(),D=B(),O=F(),[k,A]=(0,X.useState)(null),[j,M]=(0,X.useState)(null),[N,P]=(0,X.useState)(null),L=(0,X.useMemo)(()=>{let t=x.filter(t=>{if(e!==`all`&&t.provider!==e)return!1;let r=!!t.quota?.windows.length;return n===`untracked`?!r:!(!r||n===`active`&&!t.active||n===`disabled`&&t.active)}),r=(e,t)=>e.providerName.localeCompare(t.providerName,void 0,{sensitivity:`base`})||e.name.localeCompare(t.name,void 0,{sensitivity:`base`});return[...t].sort(i?(e,t)=>$(e)-$(t)||r(e,t):r)},[n,x,i,e]),R=async(e,t)=>{try{await E.mutateAsync({id:e.id,active:t}),l.success(`${e.name} ${t?`enabled`:`disabled`}`)}catch(e){l.error(e instanceof Error?e.message:`Unable to update account`)}},z=async()=>{let e=x.filter(e=>e.active&&Q(e));await D.mutateAsync({ids:e.map(e=>e.id),active:!1}),l.success(`Disabled ${e.length} empty accounts`)},V=async()=>{let e=x.filter(e=>!e.active&&e.quota?.windows.some(e=>e.remainingPercent!==null&&e.remainingPercent>0));await D.mutateAsync({ids:e.map(e=>e.id),active:!0}),l.success(`Enabled ${e.length} available accounts`)},W=async e=>{await O.mutateAsync(e.id),l.success(`${e.name} deleted`)},G=_>0?new Date(_).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):`Not updated`,q=x.filter(Q).length;return(0,Z.jsxs)(T,{gap:`16px`,className:`dashboard-page min-h-0 flex-1`,children:[(0,Z.jsx)(ne,{children:(0,Z.jsxs)(b,{className:`flex flex-col gap-5`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-5`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-4`,children:[(0,Z.jsx)(S,{"aria-label":`Filter quota by provider`,value:e,onValueChange:t,className:`w-full h-16 max-small:w-80`,options:[{value:`all`,label:`All Providers`},...v.map(e=>({value:e.id,label:e.name}))]}),(0,Z.jsx)(S,{"aria-label":`Filter quota by account`,value:n,onValueChange:r,className:`w-full h-16 max-small:w-67.5`,options:[{value:`all`,label:`With quota`},{value:`active`,label:`Active`},{value:`disabled`,label:`Disabled`},{value:`untracked`,label:`No quota`}]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,Z.jsx)(c,{variant:i?`secondary`:`ghost`,size:`sm`,onClick:()=>a(e=>!e),"aria-pressed":i,icon:(0,Z.jsx)(J,{size:13}),children:`Expiring first`}),(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,className:`text-red`,disabled:q===0||h,onClick:()=>void z(),icon:(0,Z.jsx)(u,{size:13}),children:`Turn off Empty`}),(0,Z.jsx)(c,{variant:`ghost`,size:`sm`,className:`text-green`,disabled:h,onClick:()=>void V(),icon:(0,Z.jsx)(o,{size:13}),children:`Turn on Available`})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-4 border-t border-inner-border pt-5`,children:[(0,Z.jsxs)(`span`,{className:`text-badge text-text-tertiary`,children:[L.length,` shown`,q>0?` · ${q} empty`:``]}),(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-x-5 gap-y-3 text-badge text-text-tertiary`,children:[C>0?`Refreshing ${C} account${C===1?``:`s`}…`:`Auto-refresh 60s · ${G}`,(0,Z.jsx)(oe,{accounts:x}),(0,Z.jsx)(c,{variant:`secondary`,size:`sm`,title:`Queue quota refresh`,"aria-label":`Queue quota refresh`,disabled:h||w.isPending||x.length===0,icon:(0,Z.jsx)(g,{size:13,className:w.isPending?`animate-spin`:void 0}),onClick:()=>w.mutate(x.map(e=>e.id),{onSuccess:e=>{l.success(e.failed===0?`Refreshed ${e.succeeded} quota${e.succeeded===1?``:`s`}`:`Refreshed ${e.succeeded}, ${e.failed} failed`)},onError:e=>l.error(e instanceof Error?e.message:`Unable to refresh quota`)}),children:`Refresh`})]})]})]})}),(0,Z.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-6`,children:ee?(0,Z.jsx)(d,{className:`min-h-0 flex flex-1 flex-col items-center justify-center`,kind:`loading`,title:`Loading quota data`,description:`Reading provider account limits…`}):f?(0,Z.jsx)(d,{className:`min-h-0 flex flex-1 flex-col items-center justify-center`,kind:`error`,title:`Unable to load quota data`,description:p instanceof Error?p.message:`Check the console session and retry.`,action:(0,Z.jsx)(c,{variant:`secondary`,onClick:()=>void te(),children:`Retry`})}):L.length===0?(0,Z.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-12 border border-dashed border-transparent rounded-card bg-transparent text-center`,children:(0,Z.jsx)(m,{title:`No account quota data`,message:`Nothing is reporting a quota window yet. Add a provider account and its limits will appear here.`})}):(0,Z.jsx)(`div`,{className:`quota-account-grid scroll-region min-h-0 flex-1 gap-6 [align-content:start]`,children:L.map(e=>(0,Z.jsx)(se,{account:e,onToggle:(e,t)=>void R(e,t),onDelete:e=>A(e),onShowHealth:e=>M(e),onShowResets:e=>P(e)},e.id))})}),j&&(0,Z.jsx)(K,{summary:{providerId:j.provider,accountId:j.id,title:j.name,status:j.health?.status??`unknown`,errorCategory:j.health?.lastErrorCategory??void 0,errorMessage:j.health?.sanitizedMessage??void 0,emptyMessage:`Status transitions, rate limits, quota refreshes, check-ins, and auto-recoveries will appear here.`},onClose:()=>M(null)}),N&&(0,Z.jsx)(ae,{account:N,onClose:()=>P(null)}),(0,Z.jsx)(y,{open:k!==null,onClose:()=>A(null),onConfirm:async()=>{k&&await W(k)},title:`Delete account?`,message:`Delete "${k?.name}"? This cannot be undone.`,confirmLabel:`Delete`,danger:!0})]})}export{ce as default};
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{l as i,s as a}from"./numbers-Bs4LOOuf.js";import{t as o}from"./download-A0SW9OCW.js";import{t as s}from"./eye-C_hawfH4.js";import{n as c,r as l}from"./state-DYdQmdAl.js";import{t as u}from"./dialog-BtpsJU98.js";import{n as d,r as f,t as p}from"./settings-mpmXTgUa.js";import{t as m}from"./trash-Cppn5c3R.js";import{T as h}from"./assert-NHwYq95t.js";import{l as g,o as _,s as v}from"./query-keys-D7wX2vM5.js";import{t as y}from"./useMutation-w4u4CVue.js";import{n as b,r as x,t as S}from"./card--AtFedAq.js";import{n as ee,t as te}from"./download-dRFo5_Wu.js";import{n as C}from"./input-BG41et9G.js";import{t as w}from"./select-BO6h8yNv.js";import{t as ne}from"./switch-CidSfbG7.js";import{t as T}from"./stack-DwLmjUFK.js";import{t as E}from"./banner-4_WNg2WZ.js";import{t as D}from"./backup-file-gdKIlg8U.js";var re=e(`database-backup`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 12a9 3 0 0 0 5 2.69`,key:`1ui2ym`}],[`path`,{d:`M21 9.3V5`,key:`6k6cib`}],[`path`,{d:`M3 5v14a9 3 0 0 0 6.47 2.88`,key:`i62tjy`}],[`path`,{d:`M12 12v4h4`,key:`1bxaet`}],[`path`,{d:`M13 20a5 5 0 0 0 9-3 4.5 4.5 0 0 0-4.5-4.5c-1.33 0-2.54.54-3.41 1.41L12 16`,key:`1f4ei9`}]]),ie=e(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),O=t(n(),1);function ae(){return y({mutationFn:async({password:e,sections:t,compressed:n,onProgress:r})=>{let i=new URLSearchParams({password:e});t!==void 0&&t.length>0&&i.set(`sections`,t),n===!0&&i.set(`compressed`,`1`);let a=`/backup/export?${i.toString()}`;if(n!==!0)return _(a);let o=await _(a),s=atob(o.bytes),c=Uint8Array.from(s,e=>e.charCodeAt(0));return r?.({loaded:c.byteLength,total:c.byteLength}),c}})}function oe(){let e=h();return y({mutationFn:({password:e,scopes:t})=>_(`/backup/delete-all`,{method:`POST`,body:JSON.stringify({password:e,scopes:t})}),onSuccess:async()=>{await e.invalidateQueries()}})}function se(){let e=h();return y({mutationFn:({password:e,backup:t,tables:n,onProgress:r})=>v(`/backup/import`,JSON.stringify({password:e,backup:t,...n===void 0||n.length===0?{}:{tables:[...n]}}),r),onSuccess:async()=>{await e.invalidateQueries()}})}function ce(){return y({mutationFn:({backup:e})=>_(`/backup/inspect`,{method:`POST`,body:JSON.stringify({backup:e})})})}var k=r();function le({report:e}){let t=Object.entries(e.imported).filter(([,e])=>e>0);return(0,k.jsxs)(T,{gap:`8px`,children:[t.length>0?(0,k.jsxs)(`p`,{className:`text-caption`,children:[`Imported: `,t.map(([e,t])=>`${t} ${e}`).join(`, `)]}):null,e.remapped.length>0?(0,k.jsxs)(`p`,{className:`text-caption text-text-secondary`,children:[`Remapped provider ids: `,e.remapped.join(`, `)]}):null,e.skipped.length>0?(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`p`,{className:`text-caption text-yellow`,children:[`Skipped (`,e.skipped.length,`) — nothing was guessed:`]}),(0,k.jsx)(`ul`,{className:`text-badge text-text-tertiary mt-2 ml-8`,children:e.skipped.map(e=>(0,k.jsx)(`li`,{children:e},e))})]}):null,e.warnings.length>0?(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`p`,{className:`text-caption text-text-secondary`,children:`Warnings:`}),(0,k.jsx)(`ul`,{className:`text-badge text-text-tertiary mt-2 ml-8`,children:e.warnings.map(e=>(0,k.jsx)(`li`,{children:e},e))})]}):null]})}function ue({warnings:e}){return e.length===0?null:(0,k.jsxs)(E,{tone:`warning`,surface:`raised`,live:`status`,children:[(0,k.jsxs)(`strong`,{children:[`Restore completed with `,e.length,` warning`,e.length===1?``:`s`]}),(0,k.jsx)(`ul`,{className:`mt-2 ml-8`,children:e.map((e,t)=>(0,k.jsxs)(`li`,{children:[e.table?`${e.table}${e.column?`.${e.column}`:``}: `:``,e.reason]},`${e.table??`backup`}:${e.column??`general`}:${t}`))})]})}function A(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function j(e,t){if(e===null)return t;let n=Math.max((Date.now()-e.startedAt)/1e3,.1),r=A(e.loaded/n);return`${e.total===null?A(e.loaded):`${A(e.loaded)} / ${A(e.total)}`} · ${r}/s`}function M(){let[e,t]=(0,O.useState)(``),[n,r]=(0,O.useState)(null),[s,c]=(0,O.useState)(!0),[l,d]=(0,O.useState)(!1),[f,p]=(0,O.useState)(!0),[h,_]=(0,O.useState)(null),[v,y]=(0,O.useState)(null),[w,A]=(0,O.useState)(null),[M,N]=(0,O.useState)(null),[P,F]=(0,O.useState)(null),[I,L]=(0,O.useState)(null),[R,z]=(0,O.useState)(new Set),[B,V]=(0,O.useState)(null),[H,U]=(0,O.useState)(null),[W,G]=(0,O.useState)(new Set),[K,q]=(0,O.useState)(null),J=(0,O.useRef)(null),Y=ae(),X=se(),Z=oe(),de=ce(),fe=e=>{z(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Q=()=>{r(null),t(``)},pe=()=>{R.size!==0&&(t(``),r(`delete`))},me=async()=>{if(e.length===0)return;let t=await Z.mutateAsync({password:e,scopes:[...R]});z(new Set),Q(),a.success(`Selected configuration deleted.`,Object.entries(t.deleted).map(([e,t])=>`${e}: ${t}`).join(` · `))},he=()=>{let t=[...s?[`config`]:[],...l?[`telemetry`]:[]].join(`,`);if(t.length===0){a.error(`Select at least one backup section.`);return}Y.mutate({password:e,sections:t,compressed:f,onProgress:e=>_(t=>({...e,startedAt:t?.startedAt??Date.now()}))},{onSuccess:e=>{let t=new Date().toISOString().slice(0,19).replace(/[:T]/g,`-`);e instanceof Uint8Array?te(`cartethyia_backup_${t}.json.gz`,e,`application/gzip`):ee(`cartethyia_backup_${t}.json`,JSON.stringify(e,null,2),`application/json`),Q(),a.success(`Backup downloaded.`)},onError:e=>a.error(g(e,`Backup export failed.`))})},ge=async e=>{y(null),A(null),N(null),F(null),L(null),q(null),U(null),G(new Set),V(e);try{let t=await D(e),n=await de.mutateAsync({backup:t});U(n),G(new Set(n.rows.filter(e=>e.supported).map(e=>e.table)))}catch(e){V(null),a.error(`Could not read that backup`,g(e,`The file is not a readable backup.`))}},_e=e=>{G(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},$=()=>{U(null),V(null),q(null)},ve=()=>{B!==null&&W.size!==0&&(t(``),N(null),r(`restore`))},ye=async()=>{let t=B;if(t!==null){N(null);try{let n=await D(t),r=await X.mutateAsync({password:e,backup:n,tables:[...W],onProgress:e=>_(t=>({...e,startedAt:t?.startedAt??Date.now()}))});y(r.restored),A(r.warnings),F(r.report??null),L(r.format),Q(),V(null),U(null),a.success(r.warnings.length===0?`Restore complete.`:`Restore completed with warnings.`,r.warnings.length===0?null:`${r.warnings.length} item(s) need attention. See the restore report below.`)}catch(e){let t=g(e,`Backup restore failed.`);N(t),a.error(`Backup restore failed`,t)}}},be=v===null?[]:Object.entries(v);return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:`grid grid-cols-2 gap-8 w-full min-w-0 max-medium:grid-cols-1`,children:[(0,k.jsxs)(S,{className:`h-full`,children:[(0,k.jsx)(x,{title:`Backup`,subtitle:`Download a JSON snapshot, or restore one you already trust`,icon:(0,k.jsx)(re,{size:16})}),(0,k.jsx)(b,{className:`flex flex-1 flex-col`,children:(0,k.jsxs)(T,{gap:`14px`,className:`flex-1`,children:[(0,k.jsxs)(`fieldset`,{className:`grid grid-cols-2 gap-5 min-w-0 border-0 m-0 p-0 max-medium:grid-cols-1`,children:[(0,k.jsx)(`legend`,{className:`mb-4 text-text-secondary text-badge font-semibold`,children:`Include in the download`}),(0,k.jsxs)(`label`,{className:`flex items-start gap-5 min-h-21 px-6 py-5 border border-inner-border rounded-control bg-surface-2 text-text-primary text-caption leading-snug cursor-pointer hover:border-border-strong hover:bg-hover has-checked:border-accent has-checked:bg-accent-soft`,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked)}),(0,k.jsxs)(`span`,{className:`flex flex-col gap-1 min-w-0`,children:[(0,k.jsx)(`strong`,{children:`Account, proxy & settings`}),(0,k.jsx)(`small`,{className:`text-text-tertiary text-badge`,children:`Credentials, API-key hashes, routing, and settings`})]})]}),(0,k.jsxs)(`label`,{className:`flex items-start gap-5 min-h-21 px-6 py-5 border border-inner-border rounded-control bg-surface-2 text-text-primary text-caption leading-snug cursor-pointer hover:border-border-strong hover:bg-hover has-checked:border-accent has-checked:bg-accent-soft`,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:l,onChange:e=>d(e.target.checked)}),(0,k.jsxs)(`span`,{className:`flex flex-col gap-1 min-w-0`,children:[(0,k.jsx)(`strong`,{children:`Telemetry history`}),(0,k.jsx)(`small`,{className:`text-text-tertiary text-badge`,children:`Status, tokens, cost, latency — never prompt bodies`})]})]})]}),(0,k.jsxs)(`div`,{className:`flex items-center justify-between gap-6 rounded-control border border-inner-border px-6 py-5`,children:[(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{className:`block text-body`,children:`Highly Compress Backup`}),(0,k.jsx)(`small`,{className:`text-badge text-text-tertiary`,children:`Makes the download smaller.`})]}),(0,k.jsx)(ne,{checked:f,onChange:p,"aria-label":`Highly Compress Backup`})]}),(0,k.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`The file contains provider credentials. Treat it like the database. Prompt and response bodies, health-event history, and console sessions are left out.`}),(0,k.jsxs)(`div`,{className:`mt-auto flex justify-end gap-4`,children:[(0,k.jsx)(i,{variant:`primary`,size:`sm`,onClick:()=>{t(``),r(`download`)},disabled:!s&&!l,icon:(0,k.jsx)(o,{size:13}),children:`Download backup`}),(0,k.jsx)(i,{variant:`secondary`,size:`sm`,onClick:()=>J.current?.click(),icon:(0,k.jsx)(ie,{size:13}),children:`Restore from file`}),(0,k.jsx)(`input`,{ref:J,type:`file`,accept:`application/json,.json,.gz,application/gzip`,className:`sr-only`,onChange:e=>{let t=e.target.files?.[0];t&&ge(t),e.target.value=``}})]}),I===null?null:(0,k.jsxs)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Detected format: `,I===`nine_router`?`router export`:`Cartethyia backup`]}),v===null?null:(0,k.jsxs)(E,{tone:`success`,surface:`raised`,live:`status`,children:[(0,k.jsx)(`strong`,{children:`Restore complete`}),be.length>0?(0,k.jsx)(`ul`,{children:be.map(([e,t])=>(0,k.jsxs)(`li`,{children:[e,`: `,t]},e))}):(0,k.jsx)(`p`,{children:`No rows were imported.`})]}),w===null?null:(0,k.jsx)(ue,{warnings:w}),P===null?null:(0,k.jsx)(le,{report:P})]})})]}),(0,k.jsxs)(S,{className:`settings-danger h-full`,children:[(0,k.jsx)(x,{title:`Delete data`,subtitle:`Removes the scopes you check. Console users, sessions, and audit history stay.`,icon:(0,k.jsx)(m,{size:16})}),(0,k.jsx)(b,{className:`flex flex-1 flex-col`,children:(0,k.jsxs)(T,{gap:`12px`,className:`flex-1`,children:[(0,k.jsxs)(`fieldset`,{className:`grid grid-cols-1 gap-5 min-w-0 border-0 m-0 p-0`,children:[(0,k.jsx)(`legend`,{className:`mb-4 text-text-secondary text-badge font-semibold`,children:`Delete`}),[[`providers`,`Providers`,`Accounts, credentials, tenant models, routing, and account health`],[`proxies`,`Proxies`,`Network pools, pool settings, and pool health`],[`configuration`,`All configuration`,`Providers, proxies, aliases, combos, API keys, CLI tools, and settings`]].map(([e,t,n])=>(0,k.jsxs)(`label`,{className:`flex items-start gap-5 min-h-21 px-6 py-5 border border-inner-border rounded-control bg-surface-2 text-text-primary text-caption leading-snug cursor-pointer hover:border-border-strong hover:bg-hover has-checked:border-accent has-checked:bg-accent-soft`,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:R.has(e),onChange:()=>fe(e)}),(0,k.jsxs)(`span`,{className:`flex flex-col gap-1 min-w-0`,children:[(0,k.jsx)(`strong`,{children:t}),(0,k.jsx)(`small`,{className:`text-text-tertiary text-badge`,children:n})]})]},e))]}),(0,k.jsx)(`div`,{className:`mt-auto flex justify-end`,children:(0,k.jsx)(i,{variant:`danger`,size:`sm`,icon:(0,k.jsx)(m,{size:14}),disabled:R.size===0,onClick:pe,children:`Delete selected`})})]})})]})]}),(0,k.jsx)(u,{open:H!==null,onClose:$,title:`Restore from backup`,description:`Choose which parts of this file to restore, then confirm with your console password.`,size:`md`,footer:(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(i,{variant:`secondary`,size:`sm`,onClick:$,children:`Cancel`}),(0,k.jsx)(i,{variant:`primary`,size:`sm`,disabled:W.size===0,onClick:ve,children:`Restore now`})]}),children:(0,k.jsx)(T,{gap:`12px`,children:H===null?null:(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`p`,{className:`text-badge text-text-tertiary`,children:H.format===`nine_router`?`Router export — it is converted at restore time, so every table it produces is restored.`:`${H.total} rows · exported ${H.exportedAt||`unknown date`}`}),H.rows.length>0?(0,k.jsxs)(`fieldset`,{className:`grid grid-cols-1 gap-4 min-w-0 border-0 m-0 p-0`,children:[(0,k.jsx)(`legend`,{className:`mb-3 text-text-secondary text-badge font-semibold`,children:`Restore these tables`}),(0,k.jsxs)(`div`,{className:`flex justify-end gap-4`,children:[(0,k.jsx)(`button`,{type:`button`,className:`text-badge text-accent hover:underline`,onClick:()=>G(new Set(H.rows.filter(e=>e.supported).map(e=>e.table))),children:`Select all`}),(0,k.jsx)(`button`,{type:`button`,className:`text-badge text-text-secondary hover:underline`,onClick:()=>G(new Set),children:`Select none`})]}),H.rows.map(e=>(0,k.jsxs)(`label`,{className:`flex items-start gap-4 px-5 py-4 border border-inner-border rounded-control bg-surface-2 text-caption leading-snug cursor-pointer hover:border-border-strong hover:bg-hover has-checked:border-accent has-checked:bg-accent-soft`,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:W.has(e.table),disabled:!e.supported,onChange:()=>_e(e.table)}),(0,k.jsxs)(`span`,{className:`flex flex-col gap-1 min-w-0`,children:[(0,k.jsx)(`strong`,{className:`text-text-primary`,children:e.table}),(0,k.jsxs)(`small`,{className:`text-text-tertiary text-badge`,children:[e.count,` rows · `,e.section,e.supported?``:` · not in the current schema, will be skipped`]})]})]},`${e.section}:${e.table}`))]}):null,K===null?null:(0,k.jsx)(`p`,{role:`alert`,className:`text-caption text-red`,children:K})]})})}),(0,k.jsx)(u,{open:n!==null,onClose:Q,title:n===`delete`?`Confirm deletion`:n===`restore`?`Restore backup`:`Download backup`,description:`The console password is checked again before this runs.`,size:`sm`,footer:(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(i,{variant:`secondary`,size:`sm`,onClick:Q,children:`Cancel`}),(0,k.jsx)(i,{variant:n===`delete`?`danger`:`primary`,size:`sm`,loading:Y.isPending||X.isPending||Z.isPending,disabled:e.length===0||Y.isPending||X.isPending||Z.isPending,onClick:()=>{_(null),n===`download`?he():n===`restore`?ye():me()},children:Y.isPending?j(h,`Downloading…`):X.isPending?j(h,`Uploading…`):Z.isPending?`Working…`:n===`delete`?`Delete permanently`:n===`restore`?`Restore`:`Download`})]}),children:(0,k.jsxs)(T,{gap:`10px`,children:[n===`restore`&&M!==null?(0,k.jsx)(`p`,{role:`alert`,className:`text-caption text-red`,children:M}):null,(0,k.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:n===`delete`?`This cannot be undone. The password is verified again before anything is removed.`:n===`restore`?`Restore replaces the tenant configuration in this file. Continue only if the file is trusted.`:`The export is plain JSON and contains provider credentials.`}),(0,k.jsx)(C,{label:`Console password`,type:`password`,value:e,onChange:e=>t(e.target.value),autoComplete:`current-password`,"data-autofocus":!0})]})})]})}function N(){return y({mutationFn:e=>_(`/auth/change-password`,{method:`POST`,body:JSON.stringify(e)})})}function P(){let e=p(),t=d(),n=e.data;return e.isPending?(0,k.jsx)(l,{label:`Loading privacy settings…`}):e.isError||!n?(0,k.jsx)(c,{message:g(e.error,`Failed to load runtime settings`),onRetry:()=>void e.refetch()}):(0,k.jsxs)(S,{className:`h-full`,children:[(0,k.jsx)(x,{title:`Privacy`,subtitle:`What request telemetry stores, and how client addresses are shown`,icon:(0,k.jsx)(s,{size:16})}),(0,k.jsx)(b,{children:(0,k.jsxs)(T,{gap:`16px`,children:[(0,k.jsxs)(`div`,{className:`settings-field`,children:[(0,k.jsx)(w,{label:`Telemetry payloads`,id:`privacy-payloads`,value:n.telemetryPayloads,onValueChange:e=>t.mutate({telemetryPayloads:e===`full`||e===`metadata`?e:`none`},{onSuccess:()=>a.success(`Payload capture updated`),onError:e=>a.error(g(e,`Could not update payload capture.`))}),options:[{value:`none`,label:`Off — no payload capture`},{value:`metadata`,label:`Metadata — method and headers, 15 minutes`},{value:`full`,label:`Full — redacted bodies, 15 minutes`}]}),(0,k.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Request metadata is always kept. Bodies stay off until you turn them on, and anything captured is redacted and deleted after 15 minutes.`})]}),n.telemetryPayloads===`full`?(0,k.jsxs)(`div`,{className:`settings-field`,children:[(0,k.jsx)(w,{label:`Capture depth`,id:`privacy-payload-depth`,value:n.telemetryPayloadDepth,onValueChange:e=>t.mutate({telemetryPayloadDepth:e===`moderate`||e===`maximum`?e:`minimum`},{onSuccess:()=>a.success(`Capture depth updated`),onError:e=>a.error(g(e,`Could not update capture depth.`))}),options:[{value:`minimum`,label:`Minimum — 1 MiB cap`},{value:`moderate`,label:`Moderate — 8 MiB cap`},{value:`maximum`,label:`Maximum — 16 MiB cap`}]}),n.telemetryPayloadDepth===`minimum`?null:(0,k.jsxs)(E,{tone:`warning`,surface:`raised`,className:`text-text-secondary`,children:[(0,k.jsx)(`strong`,{children:`High CPU and memory while this is on.`}),` Use it to debug, then switch back to Metadata or Minimum.`]})]}):null,(0,k.jsxs)(`div`,{className:`settings-field`,children:[(0,k.jsx)(w,{label:`Client IP display`,id:`privacy-ip`,value:n.privacyMode,onValueChange:e=>t.mutate({privacyMode:e===`full`?`full`:`masked`},{onSuccess:()=>a.success(`IP display updated`),onError:e=>a.error(g(e,`Could not update IP display.`))}),options:[{value:`masked`,label:`Masked — recommended`},{value:`full`,label:`Show full IP`}]}),(0,k.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Raw addresses stay stored. This only changes how they are shown.`})]})]})})]})}function F(){let e=N(),[t,n]=(0,O.useState)(``),[r,a]=(0,O.useState)(``),[o,s]=(0,O.useState)(``),[c,l]=(0,O.useState)(null),[u,d]=(0,O.useState)(!1);return(0,k.jsxs)(T,{gap:`12px`,className:`flex-1`,children:[(0,k.jsx)(C,{id:`current-password`,label:`Current password`,type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:`current-password`}),(0,k.jsxs)(`div`,{className:`settings-pair settings-pair-tight`,children:[(0,k.jsx)(C,{id:`new-password`,label:`New password`,type:`password`,value:r,onChange:e=>a(e.target.value),autoComplete:`new-password`}),(0,k.jsx)(C,{id:`confirm-password`,label:`Confirm new password`,type:`password`,value:o,onChange:e=>s(e.target.value),autoComplete:`new-password`})]}),c?(0,k.jsx)(`p`,{role:`alert`,className:`settings-feedback`,"data-tone":`err`,children:c}):null,u?(0,k.jsx)(`p`,{role:`status`,className:`settings-feedback`,"data-tone":`ok`,children:`Password updated.`}):null,(0,k.jsx)(`div`,{className:`mt-auto flex justify-end`,children:(0,k.jsx)(i,{variant:`primary`,size:`sm`,onClick:()=>{if(d(!1),r.length<8){l(`New password must be at least 8 characters.`);return}if(r!==o){l(`New password and confirmation do not match.`);return}l(null),e.mutate({currentPassword:t,newPassword:r},{onSuccess:()=>{d(!0),n(``),a(``),s(``)},onError:e=>l(g(e,`Password change failed.`))})},disabled:e.isPending||!t||!r||!o,children:e.isPending?`Updating…`:`Update password`})})]})}function I(){return(0,k.jsxs)(S,{children:[(0,k.jsx)(x,{title:`Settings`,subtitle:`Account security, privacy, and tenant data`,icon:(0,k.jsx)(f,{size:16})}),(0,k.jsxs)(b,{className:`flex flex-col gap-10`,children:[(0,k.jsxs)(`section`,{className:`flex flex-col gap-5`,children:[(0,k.jsx)(`h2`,{className:`text-badge font-bold uppercase tracking-label text-text-tertiary`,children:`Account`}),(0,k.jsxs)(`div`,{className:`grid grid-cols-2 gap-8 w-full min-w-0 max-medium:grid-cols-1`,children:[(0,k.jsxs)(S,{className:`h-full`,children:[(0,k.jsx)(x,{title:`Security`,subtitle:`Change the password used to sign in to this console`,icon:(0,k.jsx)(f,{size:16})}),(0,k.jsx)(b,{className:`flex flex-1 flex-col`,children:(0,k.jsx)(F,{})})]}),(0,k.jsx)(P,{})]})]}),(0,k.jsxs)(`section`,{className:`flex flex-col gap-5`,children:[(0,k.jsx)(`h2`,{className:`text-badge font-bold uppercase tracking-label text-text-tertiary`,children:`Data`}),(0,k.jsx)(M,{})]})]})]})}export{I as default};
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{l as i}from"./numbers-Bs4LOOuf.js";import{o as a,t as o}from"./query-keys-D7wX2vM5.js";import{I as s,Q as c,Z as l}from"./entry-
|
|
1
|
+
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{l as i}from"./numbers-Bs4LOOuf.js";import{o as a,t as o}from"./query-keys-D7wX2vM5.js";import{I as s,Q as c,Z as l}from"./entry-CkryrIea.js";import{n as u}from"./input-BG41et9G.js";import{t as d}from"./layout-C8mer_Ak.js";import{t as f}from"./backup-file-gdKIlg8U.js";var p=e(`user-plus`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`19`,x2:`19`,y1:`8`,y2:`14`,key:`1bvyxn`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]),m=t(n(),1),h=r();function g(){let e=c(),[t,n]=(0,m.useState)(null),[r,d]=(0,m.useState)(`admin`),[g,y]=(0,m.useState)(``),[b,x]=(0,m.useState)(``),[S,C]=(0,m.useState)(``),[w,T]=(0,m.useState)(null),[E,D]=(0,m.useState)(!1),[O,k]=(0,m.useState)(`create`),[A,j]=(0,m.useState)(null),[M,N]=(0,m.useState)(null),P=(0,m.useRef)(null);(0,m.useEffect)(()=>{let t=!0;return a(`/auth/first-boot`).then(r=>{t&&(n(r.requires_setup),r.requires_setup||e(`/login`,{replace:!0}))}).catch(()=>{t&&n(!0)}),()=>{t=!1}},[e]);let F=async n=>{if(n.preventDefault(),t===!1){T(`This console already has an account. Sign in instead.`);return}if(!r.trim()){T(`Administrator username is required.`);return}if(b.length<8){T(`Administrator password must be at least 8 characters.`);return}if(b!==S){T(`Passwords do not match.`);return}D(!0),T(null);try{let t=await a(`/auth/setup`,{method:`POST`,body:JSON.stringify({username:r.trim(),password:b,...g.trim()?{display_name:g.trim()}:{}})});if(t.status!==`success`){T(t.message??`Setup failed. Please try again.`);return}s.removeQueries({queryKey:o.session.current}),e(`/login`,{replace:!0})}catch(e){if(e&&typeof e==`object`&&`message`in e){let t=e.message;if(typeof t==`string`){T(t);return}}T(`An unexpected network error occurred.`)}finally{D(!1)}},I=async t=>{D(!0),T(null);try{if(b.length<8){T(`Administrator password must be at least 8 characters.`);return}if(b!==S){T(`Passwords do not match.`);return}let n=await f(t),i=await a(`/auth/setup/restore`,{method:`POST`,body:JSON.stringify({backup:n,username:r.trim(),password:b,...g.trim()?{display_name:g.trim()}:{}})});if(i.status!==`success`){T(i.message??`Restore failed. Please try again.`);return}s.removeQueries({queryKey:o.session.current}),e(`/login`,{replace:!0})}catch(e){if(e instanceof Error){T(e.message);return}T(`An unexpected network error occurred.`)}finally{D(!1)}},L=e=>{if(j(e),T(null),e===null){N(null);return}f(e).then(async t=>{try{let n=await a(`/auth/setup/inspect`,{method:`POST`,body:JSON.stringify({backup:t})});if(n.status!==`success`){N(null),T(n.message??`Could not read that backup.`);return}N({fileName:e.name,version:n.version??0,exportedAt:n.exportedAt??``,rows:n.rows??[],total:n.total??0,warnings:n.warnings??[]})}catch{N(null)}}).catch(e=>{N(null),T(e instanceof Error?e.message:`That file is not a JSON backup.`)})};return t===!1?(0,h.jsx)(`main`,{className:`auth-viewport`,children:(0,h.jsxs)(`div`,{className:`card-solid auth-window`,children:[(0,h.jsxs)(`div`,{className:`auth-header`,children:[(0,h.jsx)(`div`,{className:`auth-logo`,"aria-hidden":`true`}),(0,h.jsx)(`h1`,{className:`auth-title`,children:`Account Already Registered`}),(0,h.jsx)(`p`,{className:`auth-desc`,children:`This console already has an administrator account, so setup is closed. Sign in with the account that was created.`})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,h.jsx)(v,{message:`Setup is already finished. Creating a second administrator is not possible from here.`}),(0,h.jsx)(l,{to:`/login`,className:`no-underline`,children:(0,h.jsx)(i,{variant:`primary`,type:`button`,className:`w-full h-20`,children:`Go to sign in`})})]})]})}):(0,h.jsx)(`main`,{className:`auth-viewport`,children:(0,h.jsxs)(`div`,{className:`card-solid auth-window`,children:[(0,h.jsxs)(`div`,{className:`auth-header`,children:[(0,h.jsx)(`div`,{className:`auth-logo`,"aria-hidden":`true`}),(0,h.jsx)(`h1`,{className:`auth-title`,children:`Cartethyia Console Setup`}),O===`create`?(0,h.jsx)(`p`,{className:`auth-desc`,children:`Configure the administrator account for Cartethyia AI Gateway`}):null]}),(0,h.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 mb-7`,children:[(0,h.jsx)(i,{type:`button`,variant:O===`create`?`primary`:`secondary`,onClick:()=>k(`create`),children:`New account`}),(0,h.jsx)(i,{type:`button`,variant:O===`restore`?`primary`:`secondary`,onClick:()=>k(`restore`),children:`Restore`})]}),O===`restore`?(0,h.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`text-text-secondary text-caption`,children:`Backup file`}),(0,h.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border border-border-subtle px-3 py-2.5`,children:[(0,h.jsx)(i,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>P.current?.click(),disabled:E||t===null,children:`Choose file…`}),(0,h.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-caption text-text-secondary`,children:A?.name??`No file chosen`})]})]}),(0,h.jsx)(`input`,{ref:P,id:`setup-backup`,type:`file`,accept:`application/json,.json,.gz,application/gzip`,disabled:E,className:`hidden`,onChange:e=>{let t=e.target.files?.[0]??null;L(t),e.target.value=``}}),M?(0,h.jsx)(_,{preview:M}):null,(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(`p`,{className:`m-0 text-text-secondary text-caption`,children:`Backups carry settings only — no logins. Create the administrator for this install.`}),(0,h.jsx)(u,{label:`Administrator Username`,id:`restore-username`,value:r,onChange:e=>d(e.target.value),required:!0,autoComplete:`username`}),(0,h.jsx)(u,{label:`Master Password`,hint:`(min. 8 chars)`,id:`restore-password`,type:`password`,required:!0,minLength:8,value:b,onChange:e=>x(e.target.value),autoComplete:`new-password`}),(0,h.jsx)(u,{label:`Confirm Password`,id:`restore-confirm`,type:`password`,required:!0,minLength:8,value:S,onChange:e=>C(e.target.value),autoComplete:`new-password`})]}),w?(0,h.jsx)(v,{message:w}):null,(0,h.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,h.jsx)(i,{type:`button`,variant:`secondary`,onClick:()=>k(`create`),disabled:E,children:`Cancel`}),(0,h.jsx)(i,{type:`button`,variant:`primary`,disabled:E||t===null||A===null,onClick:()=>{A&&I(A)},children:E?`Restoring…`:`Restore this backup`})]})]}):(0,h.jsxs)(`form`,{onSubmit:F,className:`flex flex-col gap-7`,children:[(0,h.jsx)(u,{label:`Administrator Username`,id:`setup-username`,value:r,onChange:e=>d(e.target.value),required:!0,autoComplete:`username`,placeholder:`e.g. admin, risun`}),(0,h.jsx)(u,{label:`Display Name`,hint:`(optional)`,id:`display-name`,value:g,onChange:e=>y(e.target.value),autoComplete:`name`,placeholder:`e.g. Administrator, risun`}),(0,h.jsx)(u,{label:`Master Password`,hint:`(min. 8 chars)`,id:`setup-password`,type:`password`,required:!0,minLength:8,value:b,onChange:e=>x(e.target.value),autoComplete:`new-password`}),(0,h.jsx)(u,{label:`Confirm Password`,id:`setup-confirm`,type:`password`,required:!0,minLength:8,value:S,onChange:e=>C(e.target.value),autoComplete:`new-password`}),w?(0,h.jsx)(v,{message:w}):null,(0,h.jsx)(i,{variant:`primary`,type:`submit`,disabled:E||t===null,className:`w-full mt-3 h-20`,icon:(0,h.jsx)(p,{size:15}),children:E?`Initializing…`:`Complete Setup`})]})]})})}function _({preview:e}){let t=e.rows.filter(e=>!e.supported),n=e.rows.filter(e=>e.supported),r=e.exportedAt?e.exportedAt.replace(`T`,` `).slice(0,19):`unknown`;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 p-3 border border-inner-border rounded-control bg-surface-2`,children:[(0,h.jsxs)(`div`,{className:`flex items-center flex-wrap gap-1.5`,children:[(0,h.jsx)(`span`,{className:`min-w-0 overflow-hidden whitespace-nowrap text-ellipsis text-body font-semibold`,title:e.fileName,children:e.fileName}),(0,h.jsxs)(`span`,{className:`inline-flex items-center flex-none px-3.5 py-px border border-inner-border rounded-md bg-surface-2 text-text-secondary text-badge tabular-nums`,children:[`v`,e.version]}),t.length>0?(0,h.jsxs)(`span`,{className:`inline-flex items-center flex-none px-3.5 py-px border rounded-md bg-surface-2 text-badge tabular-nums border-warning-line text-status-warning`,children:[t.length,` unsupported`]}):null]}),(0,h.jsxs)(`p`,{className:`m-0 text-text-secondary text-caption`,children:[e.total,` rows across `,e.rows.length,` tables · exported `,r]}),t.length>0?(0,h.jsx)(`p`,{className:`m-0 text-caption text-status-warning`,children:t.length===e.rows.length?`None of these tables exist in this build, so nothing can be restored.`:`This build no longer has some of these tables. The rest still restores.`}):null,e.rows.length===0?(0,h.jsx)(`p`,{className:`m-0 text-text-secondary text-caption`,children:`This backup is empty.`}):(0,h.jsx)(`div`,{className:`max-h-110 overflow-auto`,children:(0,h.jsx)(d,{headers:[`Table`,`Section`,`Rows`],dense:!0,children:[...n,...t].map(e=>(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`td`,{children:e.table}),(0,h.jsx)(`td`,{children:e.section}),(0,h.jsx)(`td`,{className:`text-right`,children:e.supported?e.count:(0,h.jsx)(`span`,{className:`inline-flex items-center flex-none px-3.5 py-px border rounded-md bg-surface-2 text-badge tabular-nums border-warning-line text-status-warning`,children:`unsupported`})})]},`${e.section}/${e.table}`))})})]})}function v({message:e}){return(0,h.jsx)(`div`,{className:`py-5 px-7 rounded-control bg-red-soft text-red text-caption font-medium`,role:`alert`,children:e})}export{g as default};
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{d as i}from"./numbers-Bs4LOOuf.js";import{st as a}from"./entry-
|
|
1
|
+
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{d as i}from"./numbers-Bs4LOOuf.js";import{st as a}from"./entry-CkryrIea.js";import{n as o}from"./stack-DwLmjUFK.js";var s=e(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),c=e(`grip-vertical`,[[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}],[`circle`,{cx:`9`,cy:`5`,r:`1`,key:`hp0tcf`}],[`circle`,{cx:`9`,cy:`19`,r:`1`,key:`fkjjf6`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`15`,cy:`5`,r:`1`,key:`19l28e`}],[`circle`,{cx:`15`,cy:`19`,r:`1`,key:`f4zoj3`}]]),l=t(n(),1),u=r();function d({items:e,onReorder:t,disabled:n=!1,gap:r=`10px`,renderItem:d,label:f}){let[p,m]=(0,l.useState)(null),[h,g]=(0,l.useState)(null),_=(0,l.useRef)(null),v=()=>{_.current=null,m(null),g(null)},y=(n,r)=>{if(n===r)return;let i=e.map(e=>e.id),a=i.indexOf(n),o=i.indexOf(r);a!==-1&&o!==-1&&(i.splice(o,0,...i.splice(a,1)),t(i))};return(0,u.jsx)(`div`,{role:`list`,"aria-label":f,className:i(`flex flex-col min-w-0`,o(r)??`gap-5`),children:e.map((r,o)=>{let l=p===r.id,f=h===r.id&&p!==null&&p!==r.id,b=r=>{let i=o+r;if(n||i<0||i>=e.length)return;let a=e.map(e=>e.id),[s]=a.splice(o,1);s!==void 0&&(a.splice(i,0,s),t(a))};return(0,u.jsxs)(`div`,{role:`listitem`,className:i(`relative flex items-stretch gap-5 min-w-0 rounded-card transition-opacity duration-150 ease-spring`,l&&`opacity-50`,f&&`before:absolute before:inset-x-0 before:top-0 before:h-0.5 before:bg-accent before:content-['']`),"data-dragging":l?`true`:void 0,"data-drop-target":f?`true`:void 0,onDragOver:e=>{n||_.current===null||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,h!==r.id&&g(r.id))},onDrop:e=>{e.preventDefault();let t=_.current;t!==null&&y(t,r.id),v()},children:[(0,u.jsxs)(`div`,{className:`flex flex-none flex-col items-center gap-1 pt-4 text-text-tertiary select-none`,children:[(0,u.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,u.jsx)(`span`,{className:`font-mono text-badge tabular-nums leading-none`,children:o+1}),(0,u.jsx)(`button`,{type:`button`,draggable:!n,"aria-label":`Drag item at position ${o+1} to reorder`,title:`Drag to reorder`,disabled:n,onDragStart:e=>{_.current=r.id,m(r.id),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,r.id)},onDragEnd:v,className:`grid size-7 cursor-grab place-items-center rounded-control text-text-tertiary hover:bg-hover active:cursor-grabbing disabled:cursor-not-allowed`,children:(0,u.jsx)(c,{size:14})})]}),(0,u.jsxs)(`div`,{className:`flex gap-1`,children:[(0,u.jsx)(`button`,{type:`button`,"aria-label":`Move item ${o+1} up`,title:`Move up`,disabled:n||o===0,onClick:()=>b(-1),className:`grid size-7 place-items-center rounded-control text-text-tertiary hover:bg-hover disabled:cursor-not-allowed disabled:opacity-40`,children:(0,u.jsx)(s,{size:14})}),(0,u.jsx)(`button`,{type:`button`,"aria-label":`Move item ${o+1} down`,title:`Move down`,disabled:n||o===e.length-1,onClick:()=>b(1),className:`grid size-7 place-items-center rounded-control text-text-tertiary hover:bg-hover disabled:cursor-not-allowed disabled:opacity-40`,children:(0,u.jsx)(a,{size:14})})]})]}),(0,u.jsx)(`div`,{className:`flex-auto min-w-0`,children:d(r,o)})]},r.id)})})}export{d as t};
|
|
Binary file
|