@kaitranntt/ccs 7.54.0-dev.7 → 7.54.0-dev.8
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/commands/api-command/copy-command.d.ts.map +1 -1
- package/dist/commands/api-command/copy-command.js +3 -4
- package/dist/commands/api-command/copy-command.js.map +1 -1
- package/dist/commands/api-command/discover-command.d.ts.map +1 -1
- package/dist/commands/api-command/discover-command.js +8 -0
- package/dist/commands/api-command/discover-command.js.map +1 -1
- package/dist/commands/api-command/export-command.d.ts.map +1 -1
- package/dist/commands/api-command/export-command.js +11 -2
- package/dist/commands/api-command/export-command.js.map +1 -1
- package/dist/commands/api-command/import-command.d.ts.map +1 -1
- package/dist/commands/api-command/import-command.js +14 -4
- package/dist/commands/api-command/import-command.js.map +1 -1
- package/dist/commands/api-command/index.js +1 -1
- package/dist/commands/api-command/index.js.map +1 -1
- package/dist/commands/api-command/list-command.d.ts +1 -1
- package/dist/commands/api-command/list-command.d.ts.map +1 -1
- package/dist/commands/api-command/list-command.js +9 -1
- package/dist/commands/api-command/list-command.js.map +1 -1
- package/dist/commands/api-command/shared.d.ts +12 -1
- package/dist/commands/api-command/shared.d.ts.map +1 -1
- package/dist/commands/api-command/shared.js +30 -10
- package/dist/commands/api-command/shared.js.map +1 -1
- package/dist/commands/api-command.d.ts +2 -0
- package/dist/commands/api-command.d.ts.map +1 -0
- package/dist/commands/api-command.js +18 -0
- package/dist/commands/api-command.js.map +1 -0
- package/dist/commands/arg-extractor.d.ts +15 -0
- package/dist/commands/arg-extractor.d.ts.map +1 -1
- package/dist/commands/arg-extractor.js +48 -2
- package/dist/commands/arg-extractor.js.map +1 -1
- package/dist/commands/config-auth/index.d.ts.map +1 -1
- package/dist/commands/config-auth/index.js +24 -19
- package/dist/commands/config-auth/index.js.map +1 -1
- package/dist/commands/config-command-options.d.ts.map +1 -1
- package/dist/commands/config-command-options.js +14 -0
- package/dist/commands/config-command-options.js.map +1 -1
- package/dist/commands/config-command.d.ts.map +1 -1
- package/dist/commands/config-command.js +5 -0
- package/dist/commands/config-command.js.map +1 -1
- package/dist/shared/provider-preset-catalog.d.ts +1 -1
- package/dist/shared/provider-preset-catalog.d.ts.map +1 -1
- package/dist/shared/provider-preset-catalog.js +16 -15
- package/dist/shared/provider-preset-catalog.js.map +1 -1
- package/dist/ui/assets/{accounts-CpqdW0_w.js → accounts-DwcZCyS5.js} +1 -1
- package/dist/ui/assets/{alert-dialog-C2kpeUmy.js → alert-dialog-B2hyK6AP.js} +1 -1
- package/dist/ui/assets/{api-A4Julmmi.js → api-qU_bc9BM.js} +1 -1
- package/dist/ui/assets/{auth-section-BikPcP2d.js → auth-section-BPkTuOTf.js} +1 -1
- package/dist/ui/assets/{backups-section-BHu3D40s.js → backups-section-CeYlXizh.js} +1 -1
- package/dist/ui/assets/{checkbox-DnXEP66k.js → checkbox-CpTns8kD.js} +1 -1
- package/dist/ui/assets/{claude-extension-wV9N452h.js → claude-extension-DON0t7Fm.js} +1 -1
- package/dist/ui/assets/cliproxy-CVg2BCbP.js +3 -0
- package/dist/ui/assets/{cliproxy-control-panel-C89BN089.js → cliproxy-control-panel-7zmRoGkw.js} +1 -1
- package/dist/ui/assets/{confirm-dialog-Caa-t7ys.js → confirm-dialog-1fHP9ADM.js} +1 -1
- package/dist/ui/assets/{copilot-Bgu53vgq.js → copilot-CgZIsLcU.js} +1 -1
- package/dist/ui/assets/{cursor-ZChzmf7Q.js → cursor-3B9jIxVF.js} +1 -1
- package/dist/ui/assets/{droid-DszHiQa0.js → droid-3UY521J3.js} +2 -2
- package/dist/ui/assets/{globalenv-section-CSBCCjgB.js → globalenv-section-DHDrZkJ1.js} +1 -1
- package/dist/ui/assets/{health-CSvvjVV2.js → health-C2THW9ym.js} +1 -1
- package/dist/ui/assets/{index-Do_SlOTb.js → index-BnHfOIfl.js} +1 -1
- package/dist/ui/assets/{index-faayS7V6.js → index-C7jJyg77.js} +1 -1
- package/dist/ui/assets/{index-DluWJK6_.js → index-DPWpIhxa.js} +1 -1
- package/dist/ui/assets/index-Dz76Rk36.js +47 -0
- package/dist/ui/assets/{index-Bi5fEiUi.js → index-MPOI0EJ5.js} +1 -1
- package/dist/ui/assets/index-OMV20t-1.css +1 -0
- package/dist/ui/assets/{proxy-status-widget-DDqnLj1A.js → proxy-status-widget-BZfWhofZ.js} +1 -1
- package/dist/ui/assets/{searchable-select-DnAlFkH9.js → searchable-select-CzYKeWKI.js} +1 -1
- package/dist/ui/assets/{separator-Dn2TUYHv.js → separator-dTvIQkrw.js} +1 -1
- package/dist/ui/assets/{shared-BOOrRRmV.js → shared-Ccidnid7.js} +1 -1
- package/dist/ui/assets/{switch-CSo86CGn.js → switch-Bsk1Z1Fy.js} +1 -1
- package/dist/ui/assets/{updates-N5ILgIIx.js → updates-DmT2FBqm.js} +1 -1
- package/dist/ui/index.html +2 -2
- package/package.json +2 -1
- package/dist/ui/assets/cliproxy-CHERj-xQ.js +0 -3
- package/dist/ui/assets/index-BSxYTtfG.css +0 -1
- package/dist/ui/assets/index-ByjiTTw6.js +0 -47
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-Dt3edmE5.js";import{r as M}from"./react-vendor-CNOkPC89.js";import{t as p}from"./notifications-B2HqRBj7.js";import{b0 as ee,b1 as ke,B as S,d as V,c as de,b7 as Se,W as Ce,C as b,j as v,k as y,b as N,r as q,s as W,t as Y,v as G,w as k,I as ce,a as Ee,b8 as Pe,b9 as ie,ba as Te,Q as Ae,R as Re,U as z,V as $,n as D,b2 as _e}from"./index-ByjiTTw6.js";import{a as De,u as oe,b as Oe}from"./tanstack-B8i0evp-.js";import{aE as Be,L as X,aj as Me,n as Fe,R as Le,aF as Ie,aG as Ke,D as Ue,S as Ve,aH as ze,v as $e,w as Je,T as He,a6 as Qe,aC as qe,o as le}from"./icons-DtwH984l.js";import{S as O}from"./separator-Dn2TUYHv.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function We(s){try{const r=JSON.parse(s);return!r||typeof r!="object"||Array.isArray(r)?{settings:null,parseError:"JSON root must be an object."}:{settings:r,parseError:null}}catch(r){return{settings:null,parseError:r.message}}}async function Ye(){const s=await fetch(ee("/droid/diagnostics"));if(!s.ok)throw new Error("Failed to fetch Droid diagnostics");return s.json()}async function Ge(){const s=await fetch(ee("/droid/settings/raw"));if(!s.ok)throw new Error("Failed to fetch Droid raw settings");return s.json()}async function Xe(s){const r=await fetch(ee("/droid/settings/raw"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(r.status===409)throw new ke("Droid raw settings changed externally");if(!r.ok){const n=await r.json().catch(()=>null);throw new Error(n?.error||"Failed to save Droid raw settings")}return r.json()}function Ze(){const s=De(),r=oe({queryKey:["droid-diagnostics"],queryFn:Ye,refetchInterval:1e4}),n=oe({queryKey:["droid-raw-settings"],queryFn:Ge}),o=Oe({mutationFn:Xe,onSuccess:(l,d)=>{s.setQueryData(["droid-raw-settings"],t=>{const a=t?.path??"~/.factory/settings.json",u=t?.resolvedPath??a,x=We(d.rawText);return{path:a,resolvedPath:u,exists:!0,mtime:l.mtime,rawText:d.rawText,settings:x.settings,parseError:x.parseError}}),s.invalidateQueries({queryKey:["droid-diagnostics"]})}});return M.useMemo(()=>({diagnostics:r.data,diagnosticsLoading:r.isLoading,diagnosticsError:r.error,refetchDiagnostics:r.refetch,rawSettings:n.data,rawSettingsLoading:n.isLoading,rawSettingsError:n.error,refetchRawSettings:n.refetch,saveRawSettings:o.mutate,saveRawSettingsAsync:o.mutateAsync,isSavingRawSettings:o.isPending}),[r.data,r.isLoading,r.error,r.refetch,n.data,n.isLoading,n.error,n.refetch,o.mutate,o.mutateAsync,o.isPending])}function es({title:s,pathLabel:r,loading:n,parseWarning:o,value:l,dirty:d,saving:t,saveDisabled:a,onChange:u,onSave:x,onRefresh:P}){const[T,C]=M.useState(!1),A=async()=>{l&&(await navigator.clipboard.writeText(l),C(!0),p.success(Ce.t("commonToast.settingsCopied")),window.setTimeout(()=>C(!1),1500))};return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"p-4 border-b bg-background flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h2",{className:"font-semibold flex items-center gap-2",children:[e.jsx(Be,{className:"h-4 w-4 text-primary"}),s,d&&e.jsx(S,{variant:"secondary",className:"text-[10px]",children:"Unsaved"})]}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono truncate",children:r})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(V,{size:"sm",onClick:x,disabled:a,children:[t?e.jsx(X,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(Me,{className:"h-4 w-4 mr-1"}),"Save"]}),e.jsxs(V,{variant:"outline",size:"sm",onClick:A,disabled:!l,children:[e.jsx(Fe,{className:"h-4 w-4 mr-1"}),T?"Copied":"Copy"]}),e.jsx(V,{variant:"outline",size:"sm",onClick:P,children:e.jsx(Le,{className:de("h-4 w-4",n?"animate-spin":"")})})]})]}),e.jsx("div",{className:"flex-1 overflow-auto",children:n?e.jsxs("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:[e.jsx(X,{className:"h-5 w-5 animate-spin mr-2"}),"Loading settings.json..."]}):e.jsxs("div",{className:"h-full flex flex-col",children:[o&&e.jsxs("div",{className:"mx-4 mt-4 rounded-md border border-amber-300 bg-amber-50 px-3 py-2 text-sm text-amber-800 dark:bg-amber-950/20 dark:text-amber-300",children:["Parse warning: ",o]}),e.jsx("div",{className:"flex-1 p-4 pt-3",children:e.jsx("div",{className:"h-full rounded-md border overflow-hidden bg-background",children:e.jsx(Se,{value:l,onChange:u,language:"json",minHeight:"100%"})})})]})})]})}const ss=["customModels","custom_models"],rs={low:4e3,medium:12e3,high:3e4,max:5e4,xhigh:64e3},ts=["low","medium","high","max","xhigh"];function h(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function j(s){return typeof s=="string"&&s.trim()?s.trim():null}function F(s){return typeof s=="number"&&Number.isFinite(s)?s:null}function Z(s){if(!s)return"unknown";const r=s.toLowerCase();return r==="anthropic"?"anthropic":r==="openai"?"openai":r==="generic-chat-completion-api"?"generic-chat-completion-api":"unknown"}function ns(s,r,n){return`${s}:${r}:${encodeURIComponent(String(n))}`}function as(s){const r=s.indexOf(":"),n=s.indexOf(":",r+1);if(r<=0||n<=r+1)return null;const o=s.slice(0,r),l=s.slice(r+1,n),d=s.slice(n+1);if(o!=="customModels"&&o!=="custom_models"||l!=="array"&&l!=="object")return null;const t=decodeURIComponent(d);if(l==="array"){const a=Number.parseInt(t,10);return!Number.isInteger(a)||a<0?null:{rootKey:o,locationType:l,locationKey:a}}return{rootKey:o,locationType:l,locationKey:t}}function is(s){return!s||s<=0?null:s<=4e3?"low":s<=12e3?"medium":s<=3e4?"high":s<=5e4?"max":"xhigh"}function os(s){return Object.prototype.hasOwnProperty.call(s,"extraArgs")?"extraArgs":Object.prototype.hasOwnProperty.call(s,"extra_args")?"extra_args":"extraArgs"}function ue(s){return JSON.parse(JSON.stringify(s))}function ls(s){const r=[];for(const n of ss){const o=s[n];if(Array.isArray(o)){o.forEach((l,d)=>{h(l)&&r.push({rootKey:n,locationType:"array",locationKey:d,entry:l})});continue}if(h(o))for(const[l,d]of Object.entries(o))h(d)&&r.push({rootKey:n,locationType:"object",locationKey:l,entry:d})}return r}function me(s,r){const n=as(r);if(!n)return null;const o=s[n.rootKey];if(n.locationType==="array"){if(!Array.isArray(o))return null;const t=o[n.locationKey];if(!h(t))return null;const a=j(t.provider);return{entry:t,providerKind:Z(a)}}if(!h(o))return null;const l=o[n.locationKey];if(!h(l))return null;const d=j(l.provider);return{entry:l,providerKind:Z(d)}}function ds(s,r){const n=r.extraArgs??r.extra_args,o=h(n)?n:null;if(!o)return{effort:null,anthropicBudgetTokens:null};const l=j(o.reasoning_effort)??j(o.reasoningEffort),d=h(o.reasoning)?o.reasoning:null,t=d?j(d.effort):null,a=h(o.thinking)?o.thinking:null,u=a?j(a.type):null,x=a?F(a.budget_tokens)??F(a.budgetTokens):null;return s==="openai"?{effort:t??l,anthropicBudgetTokens:null}:s==="anthropic"?u==="enabled"?{effort:is(x)??"high",anthropicBudgetTokens:x}:{effort:t??l,anthropicBudgetTokens:x}:{effort:l??t,anthropicBudgetTokens:null}}function cs(s){if(!s)return null;const r=s.trim().toLowerCase();return!r||r==="default"||r==="unset"||r==="off"||r==="none"||r==="disabled"?null:r}function xe(s){const r=os(s),n=s[r],o=h(n)?{...n}:{};return{extraArgsKey:r,extraArgs:o}}function ge(s,r,n){if(Object.keys(n).length===0){delete s[r];return}s[r]=n}function us(s){return ls(s).map(({rootKey:r,locationType:n,locationKey:o,entry:l})=>{const d=j(l.displayName)??j(l.model_display_name)??"Unnamed model",t=j(l.model)??"",a=j(l.provider)??"unknown",u=Z(a),x=ds(u,l);return{id:ns(r,n,o),rootKey:r,locationType:n,locationKey:o,displayName:d,model:t,provider:a,providerKind:u,effort:x.effort,anthropicBudgetTokens:x.anthropicBudgetTokens}})}function ms(s,r,n){const o=ue(s),l=me(o,r);if(!l)return null;const d=cs(n),{extraArgsKey:t,extraArgs:a}=xe(l.entry);if(l.providerKind==="openai")if(delete a.reasoning_effort,delete a.reasoningEffort,!d)delete a.reasoning;else{const u=h(a.reasoning)?a.reasoning:{};a.reasoning={...u,effort:d}}else if(l.providerKind==="anthropic")if(delete a.reasoning_effort,delete a.reasoningEffort,delete a.reasoning,!d)delete a.thinking;else{const u=h(a.thinking)?{...a.thinking}:{},x=F(u.budget_tokens)??F(u.budgetTokens);delete u.budgetTokens,a.thinking={...u,type:"enabled",budget_tokens:x??rs[d]??3e4}}else delete a.reasoning,delete a.reasoningEffort,d?a.reasoning_effort=d:delete a.reasoning_effort;return ge(l.entry,t,a),o}function xs(s,r,n){const o=ue(s),l=me(o,r);if(!l||l.providerKind!=="anthropic")return null;const{extraArgsKey:d,extraArgs:t}=xe(l.entry),a=h(t.thinking)?{...t.thinking}:{};if(a.type="enabled",n===null)delete a.budget_tokens,delete a.budgetTokens;else{const u=Math.max(1024,Math.floor(n));a.budget_tokens=u,delete a.budgetTokens}return t.thinking=a,ge(l.entry,d,t),o}const J="__unset__";function gs(s){return s.providerKind==="openai"?"Writes: extraArgs.reasoning.effort":s.providerKind==="anthropic"?"Writes: extraArgs.thinking.{type,budget_tokens}":"Writes: extraArgs.reasoning_effort"}function fs({models:s,disabled:r,disabledReason:n,onEffortChange:o,onAnthropicBudgetChange:l}){return e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(Ie,{className:"h-4 w-4"}),"BYOK Reasoning / Thinking",e.jsx(S,{variant:"outline",className:"text-[10px] font-normal",children:"customModels"})]})}),e.jsxs(N,{className:"space-y-3",children:[n&&e.jsx("p",{className:"text-xs text-amber-600",children:n}),s.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No BYOK custom models found in settings.json (`customModels` or `custom_models`)."}):e.jsx("div",{className:"space-y-2",children:s.map(d=>e.jsxs("div",{className:"rounded-md border p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-medium truncate",children:d.displayName}),e.jsx("p",{className:"text-[11px] font-mono text-muted-foreground truncate",children:d.model||"(missing model id)"})]}),e.jsx(S,{variant:"outline",className:"font-mono text-[10px] shrink-0",children:d.provider})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-medium",children:"Reasoning Effort"}),e.jsxs(q,{value:d.effort??J,onValueChange:t=>o(d.id,t===J?null:t),disabled:r,children:[e.jsx(W,{className:"h-8 text-xs",children:e.jsx(Y,{placeholder:"Use provider default"})}),e.jsxs(G,{children:[e.jsx(k,{value:J,children:"Use provider default"}),ts.map(t=>e.jsx(k,{value:t,children:t},t))]})]})]}),d.providerKind==="anthropic"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-medium",children:"Thinking Budget Tokens"}),e.jsx(ce,{type:"number",min:1024,step:1024,value:d.anthropicBudgetTokens??"",placeholder:"auto",className:"h-8 text-xs",disabled:r,onChange:t=>{const a=t.target.value.trim();if(!a){l(d.id,null);return}const u=Number.parseInt(a,10);Number.isFinite(u)&&l(d.id,Math.max(1024,u))}})]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:gs(d)})]},d.id))})]})]})}const _="__unset__",hs=[{key:"reasoningEffort",label:"Reasoning Effort",description:"none | medium | high | max",options:[{value:"none",label:"none"},{value:"medium",label:"medium"},{value:"high",label:"high"},{value:"max",label:"max"}]},{key:"autonomyLevel",label:"Autonomy Level",description:"suggest | aggressive | full",options:[{value:"suggest",label:"suggest"},{value:"aggressive",label:"aggressive"},{value:"full",label:"full"}]},{key:"diffMode",label:"Diff Mode",description:"auto | none | inline | split",options:[{value:"auto",label:"auto"},{value:"none",label:"none"},{value:"inline",label:"inline"},{value:"split",label:"split"}]}],ps=[{key:"todoEnabled",label:"Todo Enabled"},{key:"todoAutoRefresh",label:"Todo Auto Refresh"},{key:"autoCompactEnabled",label:"Auto Compact Enabled"},{key:"soundEnabled",label:"Sound Enabled"}],js=[{key:"maxTurns",label:"Max Turns",min:1,step:1},{key:"maxToolCalls",label:"Max Tool Calls",min:1,step:1},{key:"autoCompactThreshold",label:"Auto Compact Threshold",min:1e3,step:1e3}];function bs(s){return s===!0?"true":s===!1?"false":_}function vs(s){return s==="true"?!0:s==="false"?!1:null}function ys({values:s,disabled:r,disabledReason:n,onEnumSettingChange:o,onBooleanSettingChange:l,onNumberSettingChange:d}){return e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(Ke,{className:"h-4 w-4"}),"Quick Settings",e.jsx(S,{variant:"outline",className:"text-[10px] font-normal",children:"settings.json"})]})}),e.jsxs(N,{className:"space-y-4",children:[n&&e.jsx("p",{className:"text-xs text-amber-600",children:n}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[hs.map(t=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:t.label}),e.jsxs(q,{value:s[t.key]??_,onValueChange:a=>o(t.key,a===_?null:a),disabled:r,children:[e.jsx(W,{className:"h-8 text-xs",children:e.jsx(Y,{placeholder:"Use default"})}),e.jsxs(G,{children:[e.jsx(k,{value:_,children:"Use default"}),t.options.map(a=>e.jsx(k,{value:a.value,children:a.label},a.value))]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:t.description})]},t.key)),js.map(t=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:t.label}),e.jsx(ce,{type:"number",min:t.min,step:t.step,value:s[t.key]??"",onChange:a=>{const u=a.target.value.trim();if(!u){d(t.key,null);return}const x=Number.parseInt(u,10);Number.isFinite(x)&&d(t.key,Math.max(t.min,x))},className:"h-8 text-xs",disabled:r})]},t.key)),ps.map(t=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:t.label}),e.jsxs(q,{value:bs(s[t.key]),onValueChange:a=>l(t.key,vs(a)),disabled:r,children:[e.jsx(W,{className:"h-8 text-xs",children:e.jsx(Y,{placeholder:"Use default"})}),e.jsxs(G,{children:[e.jsx(k,{value:_,children:"Use default"}),e.jsx(k,{value:"true",children:"true"}),e.jsx(k,{value:"false",children:"false"})]})]})]},t.key))]})]})]})}const Ns=[{id:"droid-cli-overview",label:"Droid CLI Overview",url:"https://docs.factory.ai/cli/",description:"Primary entry docs for setup, auth, and core CLI usage."},{id:"droid-byok-overview",label:"BYOK Overview",url:"https://docs.factory.ai/cli/byok/overview/",description:"BYOK model/provider shape, provider values, and migration notes."},{id:"droid-settings-reference",label:"settings.json Reference",url:"https://docs.factory.ai/cli/configuration/settings/",description:"Supported settings keys, defaults, and allowed values."}],ws=[{provider:"anthropic",label:"Anthropic Messages API",apiFormat:"Messages API",url:"https://docs.anthropic.com/en/api/messages"},{provider:"openai",label:"OpenAI Responses API",apiFormat:"Responses API",url:"https://platform.openai.com/docs/api-reference/responses"},{provider:"generic-chat-completion-api",label:"OpenAI Chat Completions Spec",apiFormat:"Chat Completions API",url:"https://platform.openai.com/docs/api-reference/chat"}];function ks(s){const r=/https?:\/\/[^\s)]+/g,n=[];let o=0,l;for(;(l=r.exec(s))!==null;){const[d]=l,t=l.index;t>o&&n.push(s.slice(o,t)),n.push(e.jsx("a",{href:d,target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-foreground",children:d},`${d}-${t}`)),o=t+d.length}return o<s.length&&n.push(s.slice(o)),n.length>0?n:[s]}function Ss(s){return!s||!Number.isFinite(s)?"N/A":new Date(s).toLocaleString()}function Cs(s){return!s||s<=0?"0 B":s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(1)} KB`:`${(s/(1024*1024)).toFixed(2)} MB`}function Es(s){try{const r=JSON.parse(s);return!r||typeof r!="object"||Array.isArray(r)?{valid:!1,error:"JSON root must be an object."}:{valid:!0,value:r}}catch(r){return{valid:!1,error:r.message}}}function H(s){return typeof s=="string"?s:null}function Q(s){return typeof s=="number"&&Number.isFinite(s)?s:null}function B(s){return typeof s=="boolean"?s:null}function g({label:s,value:r,mono:n=!1}){return e.jsxs("div",{className:"flex items-start justify-between gap-3 text-sm",children:[e.jsx("span",{className:"text-muted-foreground shrink-0",children:s}),e.jsx("span",{className:de("text-right break-all",n&&"font-mono text-xs"),children:r})]})}function Ls(){const{t:s}=Ee(),{diagnostics:r,diagnosticsLoading:n,diagnosticsError:o,refetchDiagnostics:l,rawSettings:d,rawSettingsLoading:t,refetchRawSettings:a,saveRawSettingsAsync:u,isSavingRawSettings:x}=Ze(),[P,T]=M.useState(null),C=d?.rawText??"{}",A=P??C,se=P!==null&&P!==C,c=Es(A),L=c.valid?{valid:!0}:{valid:!1,error:c.error},re=m=>{if(m===C){T(null);return}T(m)},I=m=>{re(JSON.stringify(m,null,2)+`
|
|
2
|
-
`)},K=(m,w)=>{if(!c.valid){p.error(s("droidPage.fixJsonBeforeQuickSettings"));return}const E={...c.value};w==null?delete E[m]:E[m]=w,I(E)},fe=c.valid?{reasoningEffort:H(c.value.reasoningEffort),autonomyLevel:H(c.value.autonomyLevel),diffMode:H(c.value.diffMode),maxTurns:Q(c.value.maxTurns),maxToolCalls:Q(c.value.maxToolCalls),autoCompactThreshold:Q(c.value.autoCompactThreshold),todoEnabled:B(c.value.todoEnabled),todoAutoRefresh:B(c.value.todoAutoRefresh),autoCompactEnabled:B(c.value.autoCompactEnabled),soundEnabled:B(c.value.soundEnabled)}:{reasoningEffort:null,autonomyLevel:null,diffMode:null,maxTurns:null,maxToolCalls:null,autoCompactThreshold:null,todoEnabled:null,todoAutoRefresh:null,autoCompactEnabled:null,soundEnabled:null},he=c.valid?us(c.value):[],pe=async()=>{await Promise.all([l(),a()])},je=async()=>{if(!L.valid){p.error(s("droidPage.invalidJson",{value:L.error}));return}try{await u({rawText:A,expectedMtime:d?.exists?d.mtime:void 0}),T(null),p.success(s("droidPage.saved"))}catch(m){_e(m)?p.error(s("droidPage.changedExternally")):p.error(m.message||s("droidPage.failedSave"))}},te=r?.byok.customModels??[],ne=M.useMemo(()=>Object.entries(r?.byok.providerBreakdown??{}).sort((m,w)=>w[1]-m[1]),[r?.byok.providerBreakdown]),be=()=>{if(n)return e.jsxs("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:[e.jsx(X,{className:"h-5 w-5 animate-spin mr-2"}),s("droidPage.loadingDiagnostics")]});if(o||!r)return e.jsx("div",{className:"flex h-full items-center justify-center text-destructive px-6 text-center",children:s("droidPage.failedDiagnostics")});const m=r.docsReference??{notes:[],links:[],providerDocs:[],providerValues:[],settingsHierarchy:[]},w=m.notes??[],E=m.links??[],ae=m.providerDocs??[],ve=E.length>0?E:Ns,ye=ae.length>0?ae:ws,Ne=m.providerValues??[],we=m.settingsHierarchy??[],U="mt-0 h-full border-0 p-0 data-[state=inactive]:hidden";return e.jsxs(Ae,{defaultValue:"byok",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(Re,{className:"grid w-full grid-cols-3",children:[e.jsx(z,{value:"overview",children:s("droidPage.overview")}),e.jsx(z,{value:"byok",children:s("droidPage.byok")}),e.jsx(z,{value:"docs",children:s("droidPage.docs")})]})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden px-4 pb-4 pt-3",children:[e.jsx($,{value:"overview",className:U,children:e.jsx(D,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 pr-1",children:[e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(Ve,{className:"h-4 w-4"}),s("droidPage.runtimeInstall")]})}),e.jsxs(N,{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("droidPage.status")}),e.jsx(S,{variant:r.binary.installed?"default":"secondary",children:r.binary.installed?s("droidPage.detected"):s("droidPage.notFound")})]}),e.jsx(g,{label:s("droidPage.detectionSource"),value:r.binary.source,mono:!0}),e.jsx(g,{label:s("droidPage.binaryPath"),value:r.binary.path||s("droidPage.notFound"),mono:!0}),e.jsx(g,{label:s("droidPage.installDirectory"),value:r.binary.installDir||"N/A",mono:!0}),e.jsx(g,{label:s("droidPage.version"),value:r.binary.version||"Unknown",mono:!0}),e.jsx(g,{label:s("droidPage.overridePath"),value:r.binary.overridePath||"Not set",mono:!0})]})]}),e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(ze,{className:"h-4 w-4"}),s("droidPage.configFiles")]})}),e.jsx(N,{className:"space-y-3",children:[r.files.settings,r.files.legacyConfig].map(i=>e.jsxs("div",{className:"rounded-md border p-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"font-medium text-sm",children:i.label}),i.exists?e.jsx($e,{className:"h-4 w-4 text-green-600"}):e.jsx(Je,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(g,{label:s("droidPage.path"),value:i.path,mono:!0}),e.jsx(g,{label:s("droidPage.resolved"),value:i.resolvedPath,mono:!0}),e.jsx(g,{label:s("droidPage.size"),value:Cs(i.sizeBytes)}),e.jsx(g,{label:s("droidPage.lastModified"),value:Ss(i.mtimeMs)}),i.parseError&&e.jsx("p",{className:"text-xs text-amber-600",children:s("droidPage.parseWarning",{value:i.parseError})}),i.readError&&e.jsx("p",{className:"text-xs text-destructive",children:s("droidPage.readWarning",{value:i.readError})})]},i.label))})]}),r.warnings.length>0&&e.jsxs(b,{className:"border-amber-200 bg-amber-50/50 dark:bg-amber-950/20",children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(He,{className:"h-4 w-4 text-amber-600"}),s("droidPage.warnings")]})}),e.jsx(N,{className:"space-y-1.5",children:r.warnings.map(i=>e.jsxs("p",{className:"text-sm text-amber-800 dark:text-amber-300",children:["- ",i]},i))})]})]})})}),e.jsx($,{value:"byok",className:U,children:e.jsx(D,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 pr-1",children:[e.jsx(ys,{values:fe,disabled:t||!c.valid,disabledReason:c.valid?null:`Quick settings disabled: ${c.error}`,onEnumSettingChange:(i,f)=>{K(i,f)},onBooleanSettingChange:(i,f)=>{K(i,f)},onNumberSettingChange:(i,f)=>{K(i,f)}}),e.jsx(fs,{models:he,disabled:t||!c.valid,disabledReason:c.valid?null:`${s("droidPage.byok")}: ${c.error}`,onEffortChange:(i,f)=>{if(!c.valid){p.error(s("droidPage.fixJsonBeforeReasoning"));return}const R=ms(c.value,i,f);if(!R){p.error(s("droidPage.unableUpdateReasoning"));return}I(R)},onAnthropicBudgetChange:(i,f)=>{if(!c.valid){p.error(s("droidPage.fixJsonBeforeBudget"));return}const R=xs(c.value,i,f);if(!R){p.error(s("droidPage.anthropicOnlyBudget"));return}I(R)}}),e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(Qe,{className:"h-4 w-4"}),s("droidPage.byokSummary")]})}),e.jsxs(N,{className:"space-y-2",children:[e.jsx(g,{label:s("droidPage.activeModelSelector"),value:r.byok.activeModelSelector||"Not set",mono:!0}),e.jsx(g,{label:s("droidPage.customModels"),value:String(r.byok.customModelCount)}),e.jsx(g,{label:s("droidPage.ccsManaged"),value:String(r.byok.ccsManagedCount)}),e.jsx(g,{label:s("droidPage.userManaged"),value:String(r.byok.userManagedCount)}),e.jsx(g,{label:s("droidPage.malformedEntries"),value:String(r.byok.invalidModelEntryCount)}),e.jsx(O,{}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("droidPage.providers")}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[ne.length===0&&e.jsx(S,{variant:"secondary",className:"font-mono",children:s("droidPage.none")}),ne.map(([i,f])=>e.jsxs(S,{variant:"outline",className:"font-mono text-xs",children:[i,": ",f]},i))]})]})]})]}),e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsx(y,{className:"text-base",children:s("droidPage.customModelsTitle")})}),e.jsx(N,{children:e.jsxs("div",{className:"rounded-md border overflow-hidden",children:[e.jsxs("div",{className:"grid grid-cols-[2fr_1fr_2fr] bg-muted/40 px-3 py-2 text-xs font-medium",children:[e.jsx("span",{children:s("droidPage.modelName")}),e.jsx("span",{children:s("droidPage.provider")}),e.jsx("span",{children:s("droidPage.baseUrl")})]}),e.jsx(D,{className:"h-52",children:e.jsxs("div",{className:"divide-y",children:[te.length===0&&e.jsx("div",{className:"px-3 py-4 text-xs text-muted-foreground",children:s("droidPage.noCustomModels")}),te.map(i=>e.jsxs("div",{className:"grid grid-cols-[2fr_1fr_2fr] gap-2 px-3 py-2 text-xs",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:i.displayName}),e.jsx("p",{className:"text-muted-foreground font-mono truncate",children:i.model})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate",children:i.provider}),e.jsx("p",{className:"text-muted-foreground",children:i.apiKeyPreview||"no-key"})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate",title:i.baseUrl,children:i.host||i.baseUrl}),e.jsx("p",{className:"text-muted-foreground font-mono truncate",children:i.baseUrl})]})]},`${i.displayName}-${i.model}-${i.baseUrl}`))]})})]})})]})]})})}),e.jsx($,{value:"docs",className:U,children:e.jsx(D,{className:"h-full",children:e.jsx("div",{className:"space-y-4 pr-1",children:e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(qe,{className:"h-4 w-4"}),s("droidPage.docsAlignedNotes")]})}),e.jsxs(N,{className:"space-y-2 text-sm",children:[w.map((i,f)=>e.jsxs("p",{className:"text-muted-foreground",children:["- ",ks(i)]},`${f}-${i}`)),e.jsx(O,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:s("droidPage.factoryDocs")}),e.jsx("div",{className:"space-y-1.5",children:ve.map(i=>e.jsxs("a",{href:i.url,target:"_blank",rel:"noreferrer",className:"block rounded-md border px-2.5 py-2 transition-colors hover:bg-muted/50",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs font-medium",children:i.label}),e.jsx(le,{className:"h-3.5 w-3.5 text-muted-foreground"})]}),e.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:i.description}),e.jsx("p",{className:"mt-1 break-all font-mono text-[11px] text-muted-foreground/90 underline underline-offset-2",children:i.url})]},i.id))})]}),e.jsx(O,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:s("droidPage.providerFactCheckDocs")}),e.jsx("div",{className:"space-y-1.5",children:ye.map(i=>e.jsxs("a",{href:i.url,target:"_blank",rel:"noreferrer",className:"block rounded-md border px-2.5 py-2 transition-colors hover:bg-muted/50",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs font-medium",children:i.label}),e.jsx(le,{className:"h-3.5 w-3.5 text-muted-foreground"})]}),e.jsxs("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:["provider: ",i.provider," | format: ",i.apiFormat]}),e.jsx("p",{className:"mt-1 break-all font-mono text-[11px] text-muted-foreground/90 underline underline-offset-2",children:i.url})]},`${i.provider}-${i.url}`))})]}),e.jsx(O,{}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("droidPage.providerValues",{value:Ne.join(", ")})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("droidPage.settingsHierarchy",{value:we.join(" -> ")})})]})]})})})})]})]})};return e.jsx("div",{className:"h-[calc(100vh-100px)] overflow-hidden",children:e.jsxs(Pe,{direction:"horizontal",className:"h-full",children:[e.jsx(ie,{defaultSize:45,minSize:35,children:e.jsx("div",{className:"h-full border-r bg-muted/20",children:be()})}),e.jsx(Te,{className:"w-2 bg-border hover:bg-primary/20 transition-colors cursor-col-resize flex items-center justify-center group",children:e.jsx(Ue,{className:"w-3 h-3 text-muted-foreground group-hover:text-primary"})}),e.jsx(ie,{defaultSize:55,minSize:35,children:e.jsx(es,{title:s("droidPage.settingsTitle"),pathLabel:d?.path||"~/.factory/settings.json",loading:t,parseWarning:d?.parseError,value:A,dirty:se,saving:x,saveDisabled:!se||x||t||!L.valid,onChange:m=>{re(m)},onSave:je,onRefresh:pe})})]})})}export{Ls as DroidPage};
|
|
1
|
+
import{j as e}from"./radix-ui-Dt3edmE5.js";import{r as M}from"./react-vendor-CNOkPC89.js";import{t as p}from"./notifications-B2HqRBj7.js";import{a_ as ee,a$ as ke,B as S,d as V,c as de,b5 as Se,W as Ce,C as b,j as v,k as y,b as N,r as q,s as W,t as Y,v as G,w as k,I as ce,a as Ee,b6 as Pe,b7 as ie,b8 as Te,Q as Ae,R as Re,U as $,V as z,n as D,b0 as _e}from"./index-Dz76Rk36.js";import{a as De,u as oe,b as Oe}from"./tanstack-B8i0evp-.js";import{aE as Be,L as X,aj as Me,n as Fe,R as Le,aF as Ie,aG as Ke,D as Ue,S as Ve,aH as $e,v as ze,w as Je,T as He,a6 as Qe,aC as qe,o as le}from"./icons-DtwH984l.js";import{S as O}from"./separator-dTvIQkrw.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function We(s){try{const r=JSON.parse(s);return!r||typeof r!="object"||Array.isArray(r)?{settings:null,parseError:"JSON root must be an object."}:{settings:r,parseError:null}}catch(r){return{settings:null,parseError:r.message}}}async function Ye(){const s=await fetch(ee("/droid/diagnostics"));if(!s.ok)throw new Error("Failed to fetch Droid diagnostics");return s.json()}async function Ge(){const s=await fetch(ee("/droid/settings/raw"));if(!s.ok)throw new Error("Failed to fetch Droid raw settings");return s.json()}async function Xe(s){const r=await fetch(ee("/droid/settings/raw"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(r.status===409)throw new ke("Droid raw settings changed externally");if(!r.ok){const n=await r.json().catch(()=>null);throw new Error(n?.error||"Failed to save Droid raw settings")}return r.json()}function Ze(){const s=De(),r=oe({queryKey:["droid-diagnostics"],queryFn:Ye,refetchInterval:1e4}),n=oe({queryKey:["droid-raw-settings"],queryFn:Ge}),o=Oe({mutationFn:Xe,onSuccess:(l,d)=>{s.setQueryData(["droid-raw-settings"],t=>{const a=t?.path??"~/.factory/settings.json",u=t?.resolvedPath??a,x=We(d.rawText);return{path:a,resolvedPath:u,exists:!0,mtime:l.mtime,rawText:d.rawText,settings:x.settings,parseError:x.parseError}}),s.invalidateQueries({queryKey:["droid-diagnostics"]})}});return M.useMemo(()=>({diagnostics:r.data,diagnosticsLoading:r.isLoading,diagnosticsError:r.error,refetchDiagnostics:r.refetch,rawSettings:n.data,rawSettingsLoading:n.isLoading,rawSettingsError:n.error,refetchRawSettings:n.refetch,saveRawSettings:o.mutate,saveRawSettingsAsync:o.mutateAsync,isSavingRawSettings:o.isPending}),[r.data,r.isLoading,r.error,r.refetch,n.data,n.isLoading,n.error,n.refetch,o.mutate,o.mutateAsync,o.isPending])}function es({title:s,pathLabel:r,loading:n,parseWarning:o,value:l,dirty:d,saving:t,saveDisabled:a,onChange:u,onSave:x,onRefresh:P}){const[T,C]=M.useState(!1),A=async()=>{l&&(await navigator.clipboard.writeText(l),C(!0),p.success(Ce.t("commonToast.settingsCopied")),window.setTimeout(()=>C(!1),1500))};return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"p-4 border-b bg-background flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h2",{className:"font-semibold flex items-center gap-2",children:[e.jsx(Be,{className:"h-4 w-4 text-primary"}),s,d&&e.jsx(S,{variant:"secondary",className:"text-[10px]",children:"Unsaved"})]}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono truncate",children:r})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(V,{size:"sm",onClick:x,disabled:a,children:[t?e.jsx(X,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(Me,{className:"h-4 w-4 mr-1"}),"Save"]}),e.jsxs(V,{variant:"outline",size:"sm",onClick:A,disabled:!l,children:[e.jsx(Fe,{className:"h-4 w-4 mr-1"}),T?"Copied":"Copy"]}),e.jsx(V,{variant:"outline",size:"sm",onClick:P,children:e.jsx(Le,{className:de("h-4 w-4",n?"animate-spin":"")})})]})]}),e.jsx("div",{className:"flex-1 overflow-auto",children:n?e.jsxs("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:[e.jsx(X,{className:"h-5 w-5 animate-spin mr-2"}),"Loading settings.json..."]}):e.jsxs("div",{className:"h-full flex flex-col",children:[o&&e.jsxs("div",{className:"mx-4 mt-4 rounded-md border border-amber-300 bg-amber-50 px-3 py-2 text-sm text-amber-800 dark:bg-amber-950/20 dark:text-amber-300",children:["Parse warning: ",o]}),e.jsx("div",{className:"flex-1 p-4 pt-3",children:e.jsx("div",{className:"h-full rounded-md border overflow-hidden bg-background",children:e.jsx(Se,{value:l,onChange:u,language:"json",minHeight:"100%"})})})]})})]})}const ss=["customModels","custom_models"],rs={low:4e3,medium:12e3,high:3e4,max:5e4,xhigh:64e3},ts=["low","medium","high","max","xhigh"];function h(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function j(s){return typeof s=="string"&&s.trim()?s.trim():null}function F(s){return typeof s=="number"&&Number.isFinite(s)?s:null}function Z(s){if(!s)return"unknown";const r=s.toLowerCase();return r==="anthropic"?"anthropic":r==="openai"?"openai":r==="generic-chat-completion-api"?"generic-chat-completion-api":"unknown"}function ns(s,r,n){return`${s}:${r}:${encodeURIComponent(String(n))}`}function as(s){const r=s.indexOf(":"),n=s.indexOf(":",r+1);if(r<=0||n<=r+1)return null;const o=s.slice(0,r),l=s.slice(r+1,n),d=s.slice(n+1);if(o!=="customModels"&&o!=="custom_models"||l!=="array"&&l!=="object")return null;const t=decodeURIComponent(d);if(l==="array"){const a=Number.parseInt(t,10);return!Number.isInteger(a)||a<0?null:{rootKey:o,locationType:l,locationKey:a}}return{rootKey:o,locationType:l,locationKey:t}}function is(s){return!s||s<=0?null:s<=4e3?"low":s<=12e3?"medium":s<=3e4?"high":s<=5e4?"max":"xhigh"}function os(s){return Object.prototype.hasOwnProperty.call(s,"extraArgs")?"extraArgs":Object.prototype.hasOwnProperty.call(s,"extra_args")?"extra_args":"extraArgs"}function ue(s){return JSON.parse(JSON.stringify(s))}function ls(s){const r=[];for(const n of ss){const o=s[n];if(Array.isArray(o)){o.forEach((l,d)=>{h(l)&&r.push({rootKey:n,locationType:"array",locationKey:d,entry:l})});continue}if(h(o))for(const[l,d]of Object.entries(o))h(d)&&r.push({rootKey:n,locationType:"object",locationKey:l,entry:d})}return r}function me(s,r){const n=as(r);if(!n)return null;const o=s[n.rootKey];if(n.locationType==="array"){if(!Array.isArray(o))return null;const t=o[n.locationKey];if(!h(t))return null;const a=j(t.provider);return{entry:t,providerKind:Z(a)}}if(!h(o))return null;const l=o[n.locationKey];if(!h(l))return null;const d=j(l.provider);return{entry:l,providerKind:Z(d)}}function ds(s,r){const n=r.extraArgs??r.extra_args,o=h(n)?n:null;if(!o)return{effort:null,anthropicBudgetTokens:null};const l=j(o.reasoning_effort)??j(o.reasoningEffort),d=h(o.reasoning)?o.reasoning:null,t=d?j(d.effort):null,a=h(o.thinking)?o.thinking:null,u=a?j(a.type):null,x=a?F(a.budget_tokens)??F(a.budgetTokens):null;return s==="openai"?{effort:t??l,anthropicBudgetTokens:null}:s==="anthropic"?u==="enabled"?{effort:is(x)??"high",anthropicBudgetTokens:x}:{effort:t??l,anthropicBudgetTokens:x}:{effort:l??t,anthropicBudgetTokens:null}}function cs(s){if(!s)return null;const r=s.trim().toLowerCase();return!r||r==="default"||r==="unset"||r==="off"||r==="none"||r==="disabled"?null:r}function xe(s){const r=os(s),n=s[r],o=h(n)?{...n}:{};return{extraArgsKey:r,extraArgs:o}}function ge(s,r,n){if(Object.keys(n).length===0){delete s[r];return}s[r]=n}function us(s){return ls(s).map(({rootKey:r,locationType:n,locationKey:o,entry:l})=>{const d=j(l.displayName)??j(l.model_display_name)??"Unnamed model",t=j(l.model)??"",a=j(l.provider)??"unknown",u=Z(a),x=ds(u,l);return{id:ns(r,n,o),rootKey:r,locationType:n,locationKey:o,displayName:d,model:t,provider:a,providerKind:u,effort:x.effort,anthropicBudgetTokens:x.anthropicBudgetTokens}})}function ms(s,r,n){const o=ue(s),l=me(o,r);if(!l)return null;const d=cs(n),{extraArgsKey:t,extraArgs:a}=xe(l.entry);if(l.providerKind==="openai")if(delete a.reasoning_effort,delete a.reasoningEffort,!d)delete a.reasoning;else{const u=h(a.reasoning)?a.reasoning:{};a.reasoning={...u,effort:d}}else if(l.providerKind==="anthropic")if(delete a.reasoning_effort,delete a.reasoningEffort,delete a.reasoning,!d)delete a.thinking;else{const u=h(a.thinking)?{...a.thinking}:{},x=F(u.budget_tokens)??F(u.budgetTokens);delete u.budgetTokens,a.thinking={...u,type:"enabled",budget_tokens:x??rs[d]??3e4}}else delete a.reasoning,delete a.reasoningEffort,d?a.reasoning_effort=d:delete a.reasoning_effort;return ge(l.entry,t,a),o}function xs(s,r,n){const o=ue(s),l=me(o,r);if(!l||l.providerKind!=="anthropic")return null;const{extraArgsKey:d,extraArgs:t}=xe(l.entry),a=h(t.thinking)?{...t.thinking}:{};if(a.type="enabled",n===null)delete a.budget_tokens,delete a.budgetTokens;else{const u=Math.max(1024,Math.floor(n));a.budget_tokens=u,delete a.budgetTokens}return t.thinking=a,ge(l.entry,d,t),o}const J="__unset__";function gs(s){return s.providerKind==="openai"?"Writes: extraArgs.reasoning.effort":s.providerKind==="anthropic"?"Writes: extraArgs.thinking.{type,budget_tokens}":"Writes: extraArgs.reasoning_effort"}function fs({models:s,disabled:r,disabledReason:n,onEffortChange:o,onAnthropicBudgetChange:l}){return e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(Ie,{className:"h-4 w-4"}),"BYOK Reasoning / Thinking",e.jsx(S,{variant:"outline",className:"text-[10px] font-normal",children:"customModels"})]})}),e.jsxs(N,{className:"space-y-3",children:[n&&e.jsx("p",{className:"text-xs text-amber-600",children:n}),s.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No BYOK custom models found in settings.json (`customModels` or `custom_models`)."}):e.jsx("div",{className:"space-y-2",children:s.map(d=>e.jsxs("div",{className:"rounded-md border p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-medium truncate",children:d.displayName}),e.jsx("p",{className:"text-[11px] font-mono text-muted-foreground truncate",children:d.model||"(missing model id)"})]}),e.jsx(S,{variant:"outline",className:"font-mono text-[10px] shrink-0",children:d.provider})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-medium",children:"Reasoning Effort"}),e.jsxs(q,{value:d.effort??J,onValueChange:t=>o(d.id,t===J?null:t),disabled:r,children:[e.jsx(W,{className:"h-8 text-xs",children:e.jsx(Y,{placeholder:"Use provider default"})}),e.jsxs(G,{children:[e.jsx(k,{value:J,children:"Use provider default"}),ts.map(t=>e.jsx(k,{value:t,children:t},t))]})]})]}),d.providerKind==="anthropic"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-medium",children:"Thinking Budget Tokens"}),e.jsx(ce,{type:"number",min:1024,step:1024,value:d.anthropicBudgetTokens??"",placeholder:"auto",className:"h-8 text-xs",disabled:r,onChange:t=>{const a=t.target.value.trim();if(!a){l(d.id,null);return}const u=Number.parseInt(a,10);Number.isFinite(u)&&l(d.id,Math.max(1024,u))}})]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:gs(d)})]},d.id))})]})]})}const _="__unset__",hs=[{key:"reasoningEffort",label:"Reasoning Effort",description:"none | medium | high | max",options:[{value:"none",label:"none"},{value:"medium",label:"medium"},{value:"high",label:"high"},{value:"max",label:"max"}]},{key:"autonomyLevel",label:"Autonomy Level",description:"suggest | aggressive | full",options:[{value:"suggest",label:"suggest"},{value:"aggressive",label:"aggressive"},{value:"full",label:"full"}]},{key:"diffMode",label:"Diff Mode",description:"auto | none | inline | split",options:[{value:"auto",label:"auto"},{value:"none",label:"none"},{value:"inline",label:"inline"},{value:"split",label:"split"}]}],ps=[{key:"todoEnabled",label:"Todo Enabled"},{key:"todoAutoRefresh",label:"Todo Auto Refresh"},{key:"autoCompactEnabled",label:"Auto Compact Enabled"},{key:"soundEnabled",label:"Sound Enabled"}],js=[{key:"maxTurns",label:"Max Turns",min:1,step:1},{key:"maxToolCalls",label:"Max Tool Calls",min:1,step:1},{key:"autoCompactThreshold",label:"Auto Compact Threshold",min:1e3,step:1e3}];function bs(s){return s===!0?"true":s===!1?"false":_}function vs(s){return s==="true"?!0:s==="false"?!1:null}function ys({values:s,disabled:r,disabledReason:n,onEnumSettingChange:o,onBooleanSettingChange:l,onNumberSettingChange:d}){return e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(Ke,{className:"h-4 w-4"}),"Quick Settings",e.jsx(S,{variant:"outline",className:"text-[10px] font-normal",children:"settings.json"})]})}),e.jsxs(N,{className:"space-y-4",children:[n&&e.jsx("p",{className:"text-xs text-amber-600",children:n}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[hs.map(t=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:t.label}),e.jsxs(q,{value:s[t.key]??_,onValueChange:a=>o(t.key,a===_?null:a),disabled:r,children:[e.jsx(W,{className:"h-8 text-xs",children:e.jsx(Y,{placeholder:"Use default"})}),e.jsxs(G,{children:[e.jsx(k,{value:_,children:"Use default"}),t.options.map(a=>e.jsx(k,{value:a.value,children:a.label},a.value))]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:t.description})]},t.key)),js.map(t=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:t.label}),e.jsx(ce,{type:"number",min:t.min,step:t.step,value:s[t.key]??"",onChange:a=>{const u=a.target.value.trim();if(!u){d(t.key,null);return}const x=Number.parseInt(u,10);Number.isFinite(x)&&d(t.key,Math.max(t.min,x))},className:"h-8 text-xs",disabled:r})]},t.key)),ps.map(t=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:t.label}),e.jsxs(q,{value:bs(s[t.key]),onValueChange:a=>l(t.key,vs(a)),disabled:r,children:[e.jsx(W,{className:"h-8 text-xs",children:e.jsx(Y,{placeholder:"Use default"})}),e.jsxs(G,{children:[e.jsx(k,{value:_,children:"Use default"}),e.jsx(k,{value:"true",children:"true"}),e.jsx(k,{value:"false",children:"false"})]})]})]},t.key))]})]})]})}const Ns=[{id:"droid-cli-overview",label:"Droid CLI Overview",url:"https://docs.factory.ai/cli/",description:"Primary entry docs for setup, auth, and core CLI usage."},{id:"droid-byok-overview",label:"BYOK Overview",url:"https://docs.factory.ai/cli/byok/overview/",description:"BYOK model/provider shape, provider values, and migration notes."},{id:"droid-settings-reference",label:"settings.json Reference",url:"https://docs.factory.ai/cli/configuration/settings/",description:"Supported settings keys, defaults, and allowed values."}],ws=[{provider:"anthropic",label:"Anthropic Messages API",apiFormat:"Messages API",url:"https://docs.anthropic.com/en/api/messages"},{provider:"openai",label:"OpenAI Responses API",apiFormat:"Responses API",url:"https://platform.openai.com/docs/api-reference/responses"},{provider:"generic-chat-completion-api",label:"OpenAI Chat Completions Spec",apiFormat:"Chat Completions API",url:"https://platform.openai.com/docs/api-reference/chat"}];function ks(s){const r=/https?:\/\/[^\s)]+/g,n=[];let o=0,l;for(;(l=r.exec(s))!==null;){const[d]=l,t=l.index;t>o&&n.push(s.slice(o,t)),n.push(e.jsx("a",{href:d,target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-foreground",children:d},`${d}-${t}`)),o=t+d.length}return o<s.length&&n.push(s.slice(o)),n.length>0?n:[s]}function Ss(s){return!s||!Number.isFinite(s)?"N/A":new Date(s).toLocaleString()}function Cs(s){return!s||s<=0?"0 B":s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(1)} KB`:`${(s/(1024*1024)).toFixed(2)} MB`}function Es(s){try{const r=JSON.parse(s);return!r||typeof r!="object"||Array.isArray(r)?{valid:!1,error:"JSON root must be an object."}:{valid:!0,value:r}}catch(r){return{valid:!1,error:r.message}}}function H(s){return typeof s=="string"?s:null}function Q(s){return typeof s=="number"&&Number.isFinite(s)?s:null}function B(s){return typeof s=="boolean"?s:null}function g({label:s,value:r,mono:n=!1}){return e.jsxs("div",{className:"flex items-start justify-between gap-3 text-sm",children:[e.jsx("span",{className:"text-muted-foreground shrink-0",children:s}),e.jsx("span",{className:de("text-right break-all",n&&"font-mono text-xs"),children:r})]})}function Ls(){const{t:s}=Ee(),{diagnostics:r,diagnosticsLoading:n,diagnosticsError:o,refetchDiagnostics:l,rawSettings:d,rawSettingsLoading:t,refetchRawSettings:a,saveRawSettingsAsync:u,isSavingRawSettings:x}=Ze(),[P,T]=M.useState(null),C=d?.rawText??"{}",A=P??C,se=P!==null&&P!==C,c=Es(A),L=c.valid?{valid:!0}:{valid:!1,error:c.error},re=m=>{if(m===C){T(null);return}T(m)},I=m=>{re(JSON.stringify(m,null,2)+`
|
|
2
|
+
`)},K=(m,w)=>{if(!c.valid){p.error(s("droidPage.fixJsonBeforeQuickSettings"));return}const E={...c.value};w==null?delete E[m]:E[m]=w,I(E)},fe=c.valid?{reasoningEffort:H(c.value.reasoningEffort),autonomyLevel:H(c.value.autonomyLevel),diffMode:H(c.value.diffMode),maxTurns:Q(c.value.maxTurns),maxToolCalls:Q(c.value.maxToolCalls),autoCompactThreshold:Q(c.value.autoCompactThreshold),todoEnabled:B(c.value.todoEnabled),todoAutoRefresh:B(c.value.todoAutoRefresh),autoCompactEnabled:B(c.value.autoCompactEnabled),soundEnabled:B(c.value.soundEnabled)}:{reasoningEffort:null,autonomyLevel:null,diffMode:null,maxTurns:null,maxToolCalls:null,autoCompactThreshold:null,todoEnabled:null,todoAutoRefresh:null,autoCompactEnabled:null,soundEnabled:null},he=c.valid?us(c.value):[],pe=async()=>{await Promise.all([l(),a()])},je=async()=>{if(!L.valid){p.error(s("droidPage.invalidJson",{value:L.error}));return}try{await u({rawText:A,expectedMtime:d?.exists?d.mtime:void 0}),T(null),p.success(s("droidPage.saved"))}catch(m){_e(m)?p.error(s("droidPage.changedExternally")):p.error(m.message||s("droidPage.failedSave"))}},te=r?.byok.customModels??[],ne=M.useMemo(()=>Object.entries(r?.byok.providerBreakdown??{}).sort((m,w)=>w[1]-m[1]),[r?.byok.providerBreakdown]),be=()=>{if(n)return e.jsxs("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:[e.jsx(X,{className:"h-5 w-5 animate-spin mr-2"}),s("droidPage.loadingDiagnostics")]});if(o||!r)return e.jsx("div",{className:"flex h-full items-center justify-center text-destructive px-6 text-center",children:s("droidPage.failedDiagnostics")});const m=r.docsReference??{notes:[],links:[],providerDocs:[],providerValues:[],settingsHierarchy:[]},w=m.notes??[],E=m.links??[],ae=m.providerDocs??[],ve=E.length>0?E:Ns,ye=ae.length>0?ae:ws,Ne=m.providerValues??[],we=m.settingsHierarchy??[],U="mt-0 h-full border-0 p-0 data-[state=inactive]:hidden";return e.jsxs(Ae,{defaultValue:"byok",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(Re,{className:"grid w-full grid-cols-3",children:[e.jsx($,{value:"overview",children:s("droidPage.overview")}),e.jsx($,{value:"byok",children:s("droidPage.byok")}),e.jsx($,{value:"docs",children:s("droidPage.docs")})]})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden px-4 pb-4 pt-3",children:[e.jsx(z,{value:"overview",className:U,children:e.jsx(D,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 pr-1",children:[e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(Ve,{className:"h-4 w-4"}),s("droidPage.runtimeInstall")]})}),e.jsxs(N,{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("droidPage.status")}),e.jsx(S,{variant:r.binary.installed?"default":"secondary",children:r.binary.installed?s("droidPage.detected"):s("droidPage.notFound")})]}),e.jsx(g,{label:s("droidPage.detectionSource"),value:r.binary.source,mono:!0}),e.jsx(g,{label:s("droidPage.binaryPath"),value:r.binary.path||s("droidPage.notFound"),mono:!0}),e.jsx(g,{label:s("droidPage.installDirectory"),value:r.binary.installDir||"N/A",mono:!0}),e.jsx(g,{label:s("droidPage.version"),value:r.binary.version||"Unknown",mono:!0}),e.jsx(g,{label:s("droidPage.overridePath"),value:r.binary.overridePath||"Not set",mono:!0})]})]}),e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx($e,{className:"h-4 w-4"}),s("droidPage.configFiles")]})}),e.jsx(N,{className:"space-y-3",children:[r.files.settings,r.files.legacyConfig].map(i=>e.jsxs("div",{className:"rounded-md border p-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"font-medium text-sm",children:i.label}),i.exists?e.jsx(ze,{className:"h-4 w-4 text-green-600"}):e.jsx(Je,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(g,{label:s("droidPage.path"),value:i.path,mono:!0}),e.jsx(g,{label:s("droidPage.resolved"),value:i.resolvedPath,mono:!0}),e.jsx(g,{label:s("droidPage.size"),value:Cs(i.sizeBytes)}),e.jsx(g,{label:s("droidPage.lastModified"),value:Ss(i.mtimeMs)}),i.parseError&&e.jsx("p",{className:"text-xs text-amber-600",children:s("droidPage.parseWarning",{value:i.parseError})}),i.readError&&e.jsx("p",{className:"text-xs text-destructive",children:s("droidPage.readWarning",{value:i.readError})})]},i.label))})]}),r.warnings.length>0&&e.jsxs(b,{className:"border-amber-200 bg-amber-50/50 dark:bg-amber-950/20",children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(He,{className:"h-4 w-4 text-amber-600"}),s("droidPage.warnings")]})}),e.jsx(N,{className:"space-y-1.5",children:r.warnings.map(i=>e.jsxs("p",{className:"text-sm text-amber-800 dark:text-amber-300",children:["- ",i]},i))})]})]})})}),e.jsx(z,{value:"byok",className:U,children:e.jsx(D,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 pr-1",children:[e.jsx(ys,{values:fe,disabled:t||!c.valid,disabledReason:c.valid?null:`Quick settings disabled: ${c.error}`,onEnumSettingChange:(i,f)=>{K(i,f)},onBooleanSettingChange:(i,f)=>{K(i,f)},onNumberSettingChange:(i,f)=>{K(i,f)}}),e.jsx(fs,{models:he,disabled:t||!c.valid,disabledReason:c.valid?null:`${s("droidPage.byok")}: ${c.error}`,onEffortChange:(i,f)=>{if(!c.valid){p.error(s("droidPage.fixJsonBeforeReasoning"));return}const R=ms(c.value,i,f);if(!R){p.error(s("droidPage.unableUpdateReasoning"));return}I(R)},onAnthropicBudgetChange:(i,f)=>{if(!c.valid){p.error(s("droidPage.fixJsonBeforeBudget"));return}const R=xs(c.value,i,f);if(!R){p.error(s("droidPage.anthropicOnlyBudget"));return}I(R)}}),e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(Qe,{className:"h-4 w-4"}),s("droidPage.byokSummary")]})}),e.jsxs(N,{className:"space-y-2",children:[e.jsx(g,{label:s("droidPage.activeModelSelector"),value:r.byok.activeModelSelector||"Not set",mono:!0}),e.jsx(g,{label:s("droidPage.customModels"),value:String(r.byok.customModelCount)}),e.jsx(g,{label:s("droidPage.ccsManaged"),value:String(r.byok.ccsManagedCount)}),e.jsx(g,{label:s("droidPage.userManaged"),value:String(r.byok.userManagedCount)}),e.jsx(g,{label:s("droidPage.malformedEntries"),value:String(r.byok.invalidModelEntryCount)}),e.jsx(O,{}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("droidPage.providers")}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[ne.length===0&&e.jsx(S,{variant:"secondary",className:"font-mono",children:s("droidPage.none")}),ne.map(([i,f])=>e.jsxs(S,{variant:"outline",className:"font-mono text-xs",children:[i,": ",f]},i))]})]})]})]}),e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsx(y,{className:"text-base",children:s("droidPage.customModelsTitle")})}),e.jsx(N,{children:e.jsxs("div",{className:"rounded-md border overflow-hidden",children:[e.jsxs("div",{className:"grid grid-cols-[2fr_1fr_2fr] bg-muted/40 px-3 py-2 text-xs font-medium",children:[e.jsx("span",{children:s("droidPage.modelName")}),e.jsx("span",{children:s("droidPage.provider")}),e.jsx("span",{children:s("droidPage.baseUrl")})]}),e.jsx(D,{className:"h-52",children:e.jsxs("div",{className:"divide-y",children:[te.length===0&&e.jsx("div",{className:"px-3 py-4 text-xs text-muted-foreground",children:s("droidPage.noCustomModels")}),te.map(i=>e.jsxs("div",{className:"grid grid-cols-[2fr_1fr_2fr] gap-2 px-3 py-2 text-xs",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:i.displayName}),e.jsx("p",{className:"text-muted-foreground font-mono truncate",children:i.model})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate",children:i.provider}),e.jsx("p",{className:"text-muted-foreground",children:i.apiKeyPreview||"no-key"})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate",title:i.baseUrl,children:i.host||i.baseUrl}),e.jsx("p",{className:"text-muted-foreground font-mono truncate",children:i.baseUrl})]})]},`${i.displayName}-${i.model}-${i.baseUrl}`))]})})]})})]})]})})}),e.jsx(z,{value:"docs",className:U,children:e.jsx(D,{className:"h-full",children:e.jsx("div",{className:"space-y-4 pr-1",children:e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(qe,{className:"h-4 w-4"}),s("droidPage.docsAlignedNotes")]})}),e.jsxs(N,{className:"space-y-2 text-sm",children:[w.map((i,f)=>e.jsxs("p",{className:"text-muted-foreground",children:["- ",ks(i)]},`${f}-${i}`)),e.jsx(O,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:s("droidPage.factoryDocs")}),e.jsx("div",{className:"space-y-1.5",children:ve.map(i=>e.jsxs("a",{href:i.url,target:"_blank",rel:"noreferrer",className:"block rounded-md border px-2.5 py-2 transition-colors hover:bg-muted/50",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs font-medium",children:i.label}),e.jsx(le,{className:"h-3.5 w-3.5 text-muted-foreground"})]}),e.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:i.description}),e.jsx("p",{className:"mt-1 break-all font-mono text-[11px] text-muted-foreground/90 underline underline-offset-2",children:i.url})]},i.id))})]}),e.jsx(O,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:s("droidPage.providerFactCheckDocs")}),e.jsx("div",{className:"space-y-1.5",children:ye.map(i=>e.jsxs("a",{href:i.url,target:"_blank",rel:"noreferrer",className:"block rounded-md border px-2.5 py-2 transition-colors hover:bg-muted/50",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs font-medium",children:i.label}),e.jsx(le,{className:"h-3.5 w-3.5 text-muted-foreground"})]}),e.jsxs("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:["provider: ",i.provider," | format: ",i.apiFormat]}),e.jsx("p",{className:"mt-1 break-all font-mono text-[11px] text-muted-foreground/90 underline underline-offset-2",children:i.url})]},`${i.provider}-${i.url}`))})]}),e.jsx(O,{}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("droidPage.providerValues",{value:Ne.join(", ")})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("droidPage.settingsHierarchy",{value:we.join(" -> ")})})]})]})})})})]})]})};return e.jsx("div",{className:"h-[calc(100vh-100px)] overflow-hidden",children:e.jsxs(Pe,{direction:"horizontal",className:"h-full",children:[e.jsx(ie,{defaultSize:45,minSize:35,children:e.jsx("div",{className:"h-full border-r bg-muted/20",children:be()})}),e.jsx(Te,{className:"w-2 bg-border hover:bg-primary/20 transition-colors cursor-col-resize flex items-center justify-center group",children:e.jsx(Ue,{className:"w-3 h-3 text-muted-foreground group-hover:text-primary"})}),e.jsx(ie,{defaultSize:55,minSize:35,children:e.jsx(es,{title:s("droidPage.settingsTitle"),pathLabel:d?.path||"~/.factory/settings.json",loading:t,parseWarning:d?.parseError,value:A,dirty:se,saving:x,saveDisabled:!se||x||t||!L.valid,onChange:m=>{re(m)},onSave:je,onRefresh:pe})})]})})}export{Ls as DroidPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-Dt3edmE5.js";import{r as m}from"./react-vendor-CNOkPC89.js";import{
|
|
1
|
+
import{j as e}from"./radix-ui-Dt3edmE5.js";import{r as m}from"./react-vendor-CNOkPC89.js";import{bg as C,bh as w,a as G,bi as y,b1 as S,b3 as k,n as R,d as f,I as j}from"./index-Dz76Rk36.js";import{S as A}from"./switch-Bsk1Z1Fy.js";import{R as N,x as D,v as L,ai as T,a3 as I}from"./icons-DtwH984l.js";import"./tanstack-B8i0evp-.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function _(){const{state:s}=C(),n=w(),[o,r]=m.useState(""),[c,g]=m.useState(""),b=m.useCallback(async()=>{try{n.setGlobalEnvLoading(!0),n.setGlobalEnvError(null);const a=await fetch("/api/global-env");if(!a.ok)throw new Error("Failed to load Global Env config");const l=await a.json();n.setGlobalEnvConfig(l)}catch(a){n.setGlobalEnvError(a.message)}finally{n.setGlobalEnvLoading(!1)}},[n]),i=m.useCallback(async a=>{const l=s.globalEnvConfig;if(!l)return;const x={...l,...a};n.setGlobalEnvConfig(x);try{n.setGlobalEnvSaving(!0),n.setGlobalEnvError(null);const d=await fetch("/api/global-env",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(x)});if(!d.ok){const E=await d.json();throw new Error(E.error||"Failed to save")}const v=await d.json();n.setGlobalEnvConfig(v.config),n.setGlobalEnvSuccess(!0),setTimeout(()=>n.setGlobalEnvSuccess(!1),1500)}catch(d){n.setGlobalEnvConfig(l),n.setGlobalEnvError(d.message)}finally{n.setGlobalEnvSaving(!1)}},[s.globalEnvConfig,n]),h=m.useCallback(()=>{if(!o.trim()||!s.globalEnvConfig)return;const a={...s.globalEnvConfig.env,[o.trim()]:c};i({env:a}),r(""),g("")},[o,c,s.globalEnvConfig,i]),u=m.useCallback(a=>{if(!s.globalEnvConfig)return;const l={...s.globalEnvConfig.env};delete l[a],i({env:l})},[s.globalEnvConfig,i]);return{config:s.globalEnvConfig,loading:s.globalEnvLoading,saving:s.globalEnvSaving,error:s.globalEnvError,success:s.globalEnvSuccess,newEnvKey:o,setNewEnvKey:r,newEnvValue:c,setNewEnvValue:g,fetchConfig:b,saveConfig:i,addEnvVar:h,removeEnvVar:u}}function $(){const{t:s}=G(),{config:n,loading:o,saving:r,error:c,success:g,newEnvKey:b,setNewEnvKey:i,newEnvValue:h,setNewEnvValue:u,fetchConfig:a,saveConfig:l,addEnvVar:x,removeEnvVar:d}=_(),{fetchRawConfig:v}=y();m.useEffect(()=>{a(),v()},[a,v]);const E=()=>{l({enabled:!n?.enabled})};return o?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(N,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:s("settings.loading")})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${c||g?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[c&&e.jsxs(S,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(D,{className:"h-4 w-4"}),e.jsx(k,{children:c})]}),g&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(L,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:s("settings.saved")})]})]}),e.jsx(R,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settingsGlobalEnv.description")}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:n?.enabled?s("settingsGlobalEnv.enabled"):s("settingsGlobalEnv.disabled")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n?.enabled?s("settingsGlobalEnv.enabledDesc"):s("settingsGlobalEnv.disabledDesc")})]}),e.jsx(A,{checked:n?.enabled??!0,onCheckedChange:E})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsGlobalEnv.envVars")}),n?.env&&Object.keys(n.env).length>0?e.jsx("div",{className:"space-y-2",children:Object.entries(n.env).map(([t,p])=>e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg border bg-background",children:[e.jsx("code",{className:"flex-1 font-mono text-sm truncate",children:t}),e.jsx("span",{className:"text-muted-foreground",children:"="}),e.jsx("code",{className:"font-mono text-sm px-2 py-1 bg-muted rounded",children:p}),e.jsx(f,{variant:"ghost",size:"sm",onClick:()=>d(t),disabled:r,className:"h-8 w-8 p-0 text-destructive hover:text-destructive hover:bg-destructive/10",children:e.jsx(T,{className:"w-4 h-4"})})]},t))}):e.jsx("div",{className:"p-4 rounded-lg border border-dashed text-center text-muted-foreground",children:e.jsx("p",{children:s("settingsGlobalEnv.noneConfigured")})}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-3",children:s("settingsGlobalEnv.addNew")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{value:b,onChange:t=>i(t.target.value.toUpperCase()),placeholder:s("settingsGlobalEnv.keyName"),className:"flex-1 font-mono text-sm h-9",disabled:r}),e.jsx("span",{className:"flex items-center text-muted-foreground",children:"="}),e.jsx(j,{value:h,onChange:t=>u(t.target.value),placeholder:s("settingsGlobalEnv.value"),className:"flex-1 font-mono text-sm h-9",disabled:r}),e.jsxs(f,{size:"sm",onClick:x,disabled:r||!b.trim(),className:"h-9",children:[e.jsx(I,{className:"w-4 h-4 mr-1"}),s("settingsGlobalEnv.add")]})]})]}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-3",children:s("settingsGlobalEnv.quickAdd")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[[{key:"DISABLE_BUG_COMMAND",value:"1"},{key:"DISABLE_ERROR_REPORTING",value:"1"},{key:"DISABLE_TELEMETRY",value:"1"}].map(({key:t,value:p})=>!n?.env?.[t]&&e.jsxs(f,{variant:"outline",size:"sm",onClick:()=>{i(t),u(p)},className:"text-xs font-mono",children:["+ ",t]},t)),n?.env&&["DISABLE_BUG_COMMAND","DISABLE_ERROR_REPORTING","DISABLE_TELEMETRY"].every(t=>n.env[t])&&e.jsx("span",{className:"text-sm text-muted-foreground",children:s("settingsGlobalEnv.allConfigured")})]})]})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(f,{variant:"outline",size:"sm",onClick:()=>{a(),v()},disabled:o||r,className:"w-full",children:[e.jsx(N,{className:`w-4 h-4 mr-2 ${o?"animate-spin":""}`}),s("settings.refresh")]})})]})}export{$ as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-Dt3edmE5.js";import{a as N,c as l,d as p,M as k,N as C,O as S,B as R,S as h}from"./index-ByjiTTw6.js";import{u as W,a as E,b as O}from"./tanstack-B8i0evp-.js";import{t as g}from"./notifications-B2HqRBj7.js";import{r as j}from"./react-vendor-CNOkPC89.js";import{aP as y,C as P,Q as I,n as M,Z as T,h as H,U as $,d as A,aQ as z,r as F,N as B,R as D}from"./icons-DtwH984l.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const Q={sm:{dimension:80,strokeWidth:6,fontSize:"text-lg",labelSize:"text-[10px]"},md:{dimension:120,strokeWidth:8,fontSize:"text-3xl",labelSize:"text-xs"},lg:{dimension:160,strokeWidth:10,fontSize:"text-4xl",labelSize:"text-sm"}},q={ok:{stroke:"#22C55E",glow:"rgba(34, 197, 94, 0.4)"},warning:{stroke:"#EAB308",glow:"rgba(234, 179, 8, 0.4)"},error:{stroke:"#EF4444",glow:"rgba(239, 68, 68, 0.4)"}};function G({passed:s,total:t,status:a,size:r="md"}){const{t:i}=N(),o=Q[r],c=q[a],n=t>0?Math.round(s/t*100):0,d=(o.dimension-o.strokeWidth)/2,u=2*Math.PI*d,f=u-n/100*u,x=o.dimension/2;return e.jsxs("div",{className:"relative inline-flex items-center justify-center",children:[e.jsxs("svg",{width:o.dimension,height:o.dimension,className:"transform -rotate-90",style:{filter:`drop-shadow(0 0 8px ${c.glow})`},children:[e.jsx("circle",{cx:x,cy:x,r:d,fill:"none",stroke:"currentColor",strokeWidth:o.strokeWidth,className:"text-muted/30"}),e.jsx("circle",{cx:x,cy:x,r:d,fill:"none",stroke:c.stroke,strokeWidth:o.strokeWidth,strokeLinecap:"round",strokeDasharray:u,strokeDashoffset:f,className:"transition-all duration-1000 ease-out"}),n>0&&e.jsx("circle",{cx:x+d*Math.cos(n/100*2*Math.PI-Math.PI/2),cy:x+d*Math.sin(n/100*2*Math.PI-Math.PI/2),r:o.strokeWidth/2,fill:c.stroke,className:"animate-pulse",style:{filter:`drop-shadow(0 0 4px ${c.glow})`}})]}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsx("span",{className:l("font-mono font-bold tracking-tight",o.fontSize),children:n}),e.jsx("span",{className:l("font-mono uppercase tracking-widest text-muted-foreground",o.labelSize),children:i("health.healthLabel")})]})]})}function b({label:s,value:t,color:a,bgColor:r}){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full animate-pulse",r)}),e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:s}),e.jsx("span",{className:l("font-mono font-bold text-sm",a),children:t})]})}function K({total:s,passed:t,warnings:a,errors:r,info:i}){const{t:o}=N(),c=t/s*100,n=a/s*100,d=r/s*100,u=i/s*100;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"h-2 rounded-full overflow-hidden bg-muted/50 flex",children:[d>0&&e.jsx("div",{className:"h-full bg-red-500 transition-all duration-500",style:{width:`${d}%`}}),n>0&&e.jsx("div",{className:"h-full bg-yellow-500 transition-all duration-500",style:{width:`${n}%`}}),u>0&&e.jsx("div",{className:"h-full bg-blue-500 transition-all duration-500",style:{width:`${u}%`}}),c>0&&e.jsx("div",{className:"h-full bg-green-500 transition-all duration-500",style:{width:`${c}%`}})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:o("health.checks")}),e.jsx("span",{className:"font-mono font-bold text-lg",children:s})]}),e.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[e.jsx(b,{label:"OK",value:t,color:"text-green-500",bgColor:"bg-green-500"}),e.jsx(b,{label:"WARN",value:a,color:"text-yellow-500",bgColor:"bg-yellow-500"}),e.jsx(b,{label:"ERR",value:r,color:"text-red-500",bgColor:"bg-red-500"}),e.jsx(b,{label:"INFO",value:i,color:"text-blue-500",bgColor:"bg-blue-500"})]})]})]})}function L(){return W({queryKey:["health"],queryFn:async()=>(await fetch("/api/health")).json(),refetchInterval:3e4})}function U(){const s=E();return O({mutationFn:async t=>{const a=await fetch(`/api/health/fix/${t}`,{method:"POST"}),r=await a.json();if(!a.ok)throw new Error(r.message);return r},onSuccess:t=>{s.invalidateQueries({queryKey:["health"]}),g.success(t.message)},onError:t=>{g.error(t.message)}})}const Z={ok:{dot:"bg-green-500",label:"OK",labelColor:"text-green-500"},warning:{dot:"bg-yellow-500",label:"WARN",labelColor:"text-yellow-500"},error:{dot:"bg-red-500",label:"ERR",labelColor:"text-red-500"},info:{dot:"bg-blue-500",label:"INFO",labelColor:"text-blue-500"}};function J({check:s}){const{t}=N(),a=U(),r=Z[s.status],[i,o]=j.useState(!1),c=s.details||s.fix,n=d=>{navigator.clipboard.writeText(d),g.success(t("health.copied"))};return c?e.jsx(k,{open:i,onOpenChange:o,children:e.jsxs("div",{className:l("group rounded-lg border transition-all duration-150",i?"border-border bg-muted/30":"border-transparent hover:border-border/50 hover:bg-muted/50"),children:[e.jsx(C,{asChild:!0,children:e.jsxs("button",{className:"w-full flex items-center gap-3 px-3 py-2 text-left",children:[e.jsxs("div",{className:"relative flex items-center justify-center w-4 h-4",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full",r.dot)}),s.status!=="ok"&&e.jsx("div",{className:l("absolute w-2 h-2 rounded-full animate-ping opacity-75",r.dot)})]}),e.jsx("span",{className:"flex-1 text-sm font-medium truncate",children:s.name}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",r.labelColor),children:["[",r.label,"]"]}),e.jsx(P,{className:l("w-4 h-4 text-muted-foreground transition-transform duration-200",i&&"rotate-90")})]})}),e.jsx(S,{children:e.jsxs("div",{className:"px-3 pb-3 pt-1 space-y-2 ml-7",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s.message}),s.details&&e.jsx("pre",{className:"text-xs font-mono text-muted-foreground bg-background/50 rounded p-2 overflow-x-auto border border-border/50",children:s.details}),s.fix&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 bg-background/50 rounded px-2 py-1.5 border border-border/50",children:[e.jsx(I,{className:"w-3 h-3 text-muted-foreground shrink-0"}),e.jsx("code",{className:"text-xs font-mono flex-1 truncate",children:s.fix}),e.jsx(p,{variant:"ghost",size:"sm",onClick:()=>s.fix&&n(s.fix),className:"h-5 w-5 p-0",children:e.jsx(M,{className:"w-3 h-3"})})]}),s.fixable&&s.status!=="ok"&&e.jsxs(p,{size:"sm",onClick:()=>a.mutate(s.id),disabled:a.isPending,className:"h-7 px-3 text-xs",children:[e.jsx(y,{className:"w-3 h-3 mr-1"}),t("health.applyFix")]})]})]})})]})}):e.jsxs("div",{className:l("group flex items-center gap-3 px-3 py-2 rounded-lg","hover:bg-muted/50 transition-colors duration-150","border border-transparent hover:border-border/50"),children:[e.jsxs("div",{className:"relative flex items-center justify-center w-4 h-4",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full",r.dot)}),s.status!=="ok"&&e.jsx("div",{className:l("absolute w-2 h-2 rounded-full animate-ping opacity-75",r.dot)})]}),e.jsx("span",{className:"flex-1 text-sm font-medium truncate",children:s.name}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",r.labelColor),children:["[",r.label,"]"]}),s.fixable&&s.status!=="ok"&&e.jsxs(p,{size:"sm",variant:"ghost",onClick:()=>a.mutate(s.id),disabled:a.isPending,className:"h-6 px-2 text-xs opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx(y,{className:"w-3 h-3 mr-1"}),t("health.fix")]})]})}const V={Monitor:z,Settings:A,Users:$,Shield:H,Zap:T};function X({group:s,defaultOpen:t=!0}){const[a,r]=j.useState(t),i=V[s.icon]||z,o=s.checks.filter(m=>m.status==="ok").length,c=s.checks.length,n=s.checks.some(m=>m.status==="error"),d=s.checks.some(m=>m.status==="warning"),u=Math.round(o/c*100),f=n?"text-red-500":d?"text-yellow-500":"text-green-500",x=n?"bg-red-500":d?"bg-yellow-500":"bg-green-500";return e.jsx(k,{open:a,onOpenChange:r,children:e.jsxs("div",{className:l("rounded-lg border transition-all duration-200",n?"border-red-500/30":d?"border-yellow-500/30":"border-border"),children:[e.jsx(C,{asChild:!0,children:e.jsxs("button",{className:l("w-full flex items-center gap-3 p-3 text-left rounded-lg","hover:bg-muted/50 transition-colors duration-150",a&&"rounded-b-none border-b border-border/50"),children:[e.jsx("div",{className:l("p-1.5 rounded-md",n?"bg-red-500/10 text-red-500":d?"bg-yellow-500/10 text-yellow-500":"bg-muted text-muted-foreground"),children:e.jsx(i,{className:"w-4 h-4"})}),e.jsx("span",{className:"flex-1 text-sm font-semibold",children:s.name}),!a&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("div",{className:"w-16 h-1.5 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:l("h-full transition-all duration-500",x),style:{width:`${u}%`}})})}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",f),children:[o,"/",c]}),e.jsx(F,{className:l("w-4 h-4 text-muted-foreground transition-transform duration-200",a&&"rotate-180")})]})}),e.jsx(S,{children:e.jsx("div",{className:"p-2 space-y-0.5",children:s.checks.map(m=>e.jsx(J,{check:m},m.id))})})]})})}function Y(s){return s.errors>0?"error":s.warnings>0?"warning":"ok"}function _(s,t){const a=Math.floor((Date.now()-s)/1e3);if(a<5)return t("health.justNow");if(a<60)return t("health.secondsAgo",{count:a});const r=Math.floor(a/60);if(r<60)return t("health.minutesAgo",{count:r});const i=Math.floor(r/60);return t("health.hoursAgo",{count:i})}function ee(s){return[...s].sort((t,a)=>{const r=t.checks.filter(n=>n.status==="error").length,i=a.checks.filter(n=>n.status==="error").length,o=t.checks.filter(n=>n.status==="warning").length,c=a.checks.filter(n=>n.status==="warning").length;return r!==i?i-r:c-o})}function se(){return e.jsxs("div",{className:"font-mono text-sm text-muted-foreground flex items-center gap-2",children:[e.jsx("span",{className:"text-green-500",children:"$"}),e.jsx("span",{children:"ccs doctor"})]})}function te(){return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-6",children:[e.jsx("div",{className:"rounded-xl border bg-gradient-to-br from-background to-muted/20 p-6",children:e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsx(h,{className:"w-[120px] h-[120px] rounded-full"}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx(h,{className:"h-5 w-48"}),e.jsx(h,{className:"h-8 w-64"}),e.jsx(h,{className:"h-4 w-32"})]})]})}),e.jsx(h,{className:"h-16 w-full rounded-lg"}),e.jsx("div",{className:"space-y-3",children:[1,2,3,4].map(s=>e.jsx(h,{className:"h-20 rounded-lg"},s))})]})}function xe(){const{t:s}=N(),{data:t,isLoading:a,refetch:r,dataUpdatedAt:i}=L(),o=i,[c,n]=j.useState(0);j.useEffect(()=>{const m=setInterval(()=>n(v=>v+1),1e3);return()=>clearInterval(m)},[]);const d=()=>{navigator.clipboard.writeText("ccs doctor"),g.success(s("health.copied"))},u=()=>{r(),g.info(s("health.refreshing"))};if(a&&!t)return e.jsx(te,{});const f=t?Y(t.summary):"ok",x=t?.groups?ee(t.groups):[];return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-6",children:[e.jsxs("div",{className:l("relative overflow-hidden rounded-xl border p-6","bg-gradient-to-br from-background via-background to-muted/30"),children:[e.jsx("div",{className:"absolute inset-0 opacity-[0.02] pointer-events-none",style:{backgroundImage:"repeating-linear-gradient(0deg, transparent, transparent 2px, currentColor 2px, currentColor 3px)"}}),e.jsx("div",{className:"absolute inset-0 opacity-[0.03] pointer-events-none",children:e.jsx("div",{className:"absolute inset-0",style:{backgroundImage:"radial-gradient(circle at 1px 1px, currentColor 1px, transparent 0)",backgroundSize:"24px 24px"}})}),e.jsxs("div",{className:"relative flex flex-col md:flex-row items-start md:items-center gap-6",children:[t&&e.jsx("div",{className:"shrink-0",children:e.jsx(G,{passed:t.summary.passed,total:t.summary.total-t.summary.info,status:f,size:"md"})}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx(se,{}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx("h1",{className:"text-2xl font-bold font-mono tracking-tight",children:s("health.systemHealth")}),t?.version&&e.jsx(R,{variant:"outline",className:"font-mono text-xs bg-muted/50",children:s("health.build",{version:t.version})})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(B,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:s("health.lastScan")}),e.jsx("span",{className:"font-mono",children:o?_(o,s):"--"}),e.jsx("span",{className:"text-muted-foreground",children:"|"}),e.jsx("span",{className:"text-muted-foreground",children:s("health.autoRefresh")}),e.jsx("span",{className:"font-mono text-green-500",children:"30s"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs(p,{variant:"outline",size:"sm",onClick:d,className:"gap-2 font-mono text-xs",children:[e.jsx(I,{className:"w-3 h-3"}),"ccs doctor",e.jsx(M,{className:"w-3 h-3 opacity-50"})]}),e.jsxs(p,{variant:"outline",size:"sm",onClick:u,disabled:a,className:"gap-2",children:[e.jsx(D,{className:l("w-4 h-4",a&&"animate-spin")}),e.jsx("span",{className:"hidden sm:inline",children:s("health.refresh")}),e.jsx("kbd",{className:"hidden md:inline-flex h-5 items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium text-muted-foreground",children:"R"})]})]})]})]}),t&&e.jsx("div",{className:"rounded-lg border bg-card p-4",children:e.jsx(K,{total:t.summary.total,passed:t.summary.passed,warnings:t.summary.warnings,errors:t.summary.errors,info:t.summary.info})}),x.length>0&&e.jsx("div",{className:"space-y-3",children:x.map((m,v)=>e.jsx(X,{group:m,defaultOpen:v<2||m.checks.some(w=>w.status==="error"||w.status==="warning")},m.id))}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground border-t pt-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{children:[s("health.version")," ",e.jsx("span",{className:"font-mono",children:t?.version??"--"})]}),e.jsxs("span",{children:[s("health.platform")," ",e.jsx("span",{className:"font-mono",children:typeof navigator<"u"?navigator.platform:"linux"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-green-500 animate-pulse"}),e.jsx("span",{children:s("health.liveMonitoring")})]})]})]})}export{xe as HealthPage};
|
|
1
|
+
import{j as e}from"./radix-ui-Dt3edmE5.js";import{a as N,c as l,d as p,M as k,N as C,O as S,B as R,S as h}from"./index-Dz76Rk36.js";import{u as W,a as E,b as O}from"./tanstack-B8i0evp-.js";import{t as g}from"./notifications-B2HqRBj7.js";import{r as j}from"./react-vendor-CNOkPC89.js";import{aP as y,C as P,Q as I,n as M,Z as T,h as H,U as $,d as A,aQ as z,r as F,N as B,R as D}from"./icons-DtwH984l.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const Q={sm:{dimension:80,strokeWidth:6,fontSize:"text-lg",labelSize:"text-[10px]"},md:{dimension:120,strokeWidth:8,fontSize:"text-3xl",labelSize:"text-xs"},lg:{dimension:160,strokeWidth:10,fontSize:"text-4xl",labelSize:"text-sm"}},q={ok:{stroke:"#22C55E",glow:"rgba(34, 197, 94, 0.4)"},warning:{stroke:"#EAB308",glow:"rgba(234, 179, 8, 0.4)"},error:{stroke:"#EF4444",glow:"rgba(239, 68, 68, 0.4)"}};function G({passed:s,total:t,status:a,size:r="md"}){const{t:i}=N(),o=Q[r],c=q[a],n=t>0?Math.round(s/t*100):0,d=(o.dimension-o.strokeWidth)/2,u=2*Math.PI*d,f=u-n/100*u,x=o.dimension/2;return e.jsxs("div",{className:"relative inline-flex items-center justify-center",children:[e.jsxs("svg",{width:o.dimension,height:o.dimension,className:"transform -rotate-90",style:{filter:`drop-shadow(0 0 8px ${c.glow})`},children:[e.jsx("circle",{cx:x,cy:x,r:d,fill:"none",stroke:"currentColor",strokeWidth:o.strokeWidth,className:"text-muted/30"}),e.jsx("circle",{cx:x,cy:x,r:d,fill:"none",stroke:c.stroke,strokeWidth:o.strokeWidth,strokeLinecap:"round",strokeDasharray:u,strokeDashoffset:f,className:"transition-all duration-1000 ease-out"}),n>0&&e.jsx("circle",{cx:x+d*Math.cos(n/100*2*Math.PI-Math.PI/2),cy:x+d*Math.sin(n/100*2*Math.PI-Math.PI/2),r:o.strokeWidth/2,fill:c.stroke,className:"animate-pulse",style:{filter:`drop-shadow(0 0 4px ${c.glow})`}})]}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsx("span",{className:l("font-mono font-bold tracking-tight",o.fontSize),children:n}),e.jsx("span",{className:l("font-mono uppercase tracking-widest text-muted-foreground",o.labelSize),children:i("health.healthLabel")})]})]})}function b({label:s,value:t,color:a,bgColor:r}){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full animate-pulse",r)}),e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:s}),e.jsx("span",{className:l("font-mono font-bold text-sm",a),children:t})]})}function K({total:s,passed:t,warnings:a,errors:r,info:i}){const{t:o}=N(),c=t/s*100,n=a/s*100,d=r/s*100,u=i/s*100;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"h-2 rounded-full overflow-hidden bg-muted/50 flex",children:[d>0&&e.jsx("div",{className:"h-full bg-red-500 transition-all duration-500",style:{width:`${d}%`}}),n>0&&e.jsx("div",{className:"h-full bg-yellow-500 transition-all duration-500",style:{width:`${n}%`}}),u>0&&e.jsx("div",{className:"h-full bg-blue-500 transition-all duration-500",style:{width:`${u}%`}}),c>0&&e.jsx("div",{className:"h-full bg-green-500 transition-all duration-500",style:{width:`${c}%`}})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:o("health.checks")}),e.jsx("span",{className:"font-mono font-bold text-lg",children:s})]}),e.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[e.jsx(b,{label:"OK",value:t,color:"text-green-500",bgColor:"bg-green-500"}),e.jsx(b,{label:"WARN",value:a,color:"text-yellow-500",bgColor:"bg-yellow-500"}),e.jsx(b,{label:"ERR",value:r,color:"text-red-500",bgColor:"bg-red-500"}),e.jsx(b,{label:"INFO",value:i,color:"text-blue-500",bgColor:"bg-blue-500"})]})]})]})}function L(){return W({queryKey:["health"],queryFn:async()=>(await fetch("/api/health")).json(),refetchInterval:3e4})}function U(){const s=E();return O({mutationFn:async t=>{const a=await fetch(`/api/health/fix/${t}`,{method:"POST"}),r=await a.json();if(!a.ok)throw new Error(r.message);return r},onSuccess:t=>{s.invalidateQueries({queryKey:["health"]}),g.success(t.message)},onError:t=>{g.error(t.message)}})}const Z={ok:{dot:"bg-green-500",label:"OK",labelColor:"text-green-500"},warning:{dot:"bg-yellow-500",label:"WARN",labelColor:"text-yellow-500"},error:{dot:"bg-red-500",label:"ERR",labelColor:"text-red-500"},info:{dot:"bg-blue-500",label:"INFO",labelColor:"text-blue-500"}};function J({check:s}){const{t}=N(),a=U(),r=Z[s.status],[i,o]=j.useState(!1),c=s.details||s.fix,n=d=>{navigator.clipboard.writeText(d),g.success(t("health.copied"))};return c?e.jsx(k,{open:i,onOpenChange:o,children:e.jsxs("div",{className:l("group rounded-lg border transition-all duration-150",i?"border-border bg-muted/30":"border-transparent hover:border-border/50 hover:bg-muted/50"),children:[e.jsx(C,{asChild:!0,children:e.jsxs("button",{className:"w-full flex items-center gap-3 px-3 py-2 text-left",children:[e.jsxs("div",{className:"relative flex items-center justify-center w-4 h-4",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full",r.dot)}),s.status!=="ok"&&e.jsx("div",{className:l("absolute w-2 h-2 rounded-full animate-ping opacity-75",r.dot)})]}),e.jsx("span",{className:"flex-1 text-sm font-medium truncate",children:s.name}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",r.labelColor),children:["[",r.label,"]"]}),e.jsx(P,{className:l("w-4 h-4 text-muted-foreground transition-transform duration-200",i&&"rotate-90")})]})}),e.jsx(S,{children:e.jsxs("div",{className:"px-3 pb-3 pt-1 space-y-2 ml-7",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s.message}),s.details&&e.jsx("pre",{className:"text-xs font-mono text-muted-foreground bg-background/50 rounded p-2 overflow-x-auto border border-border/50",children:s.details}),s.fix&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 bg-background/50 rounded px-2 py-1.5 border border-border/50",children:[e.jsx(I,{className:"w-3 h-3 text-muted-foreground shrink-0"}),e.jsx("code",{className:"text-xs font-mono flex-1 truncate",children:s.fix}),e.jsx(p,{variant:"ghost",size:"sm",onClick:()=>s.fix&&n(s.fix),className:"h-5 w-5 p-0",children:e.jsx(M,{className:"w-3 h-3"})})]}),s.fixable&&s.status!=="ok"&&e.jsxs(p,{size:"sm",onClick:()=>a.mutate(s.id),disabled:a.isPending,className:"h-7 px-3 text-xs",children:[e.jsx(y,{className:"w-3 h-3 mr-1"}),t("health.applyFix")]})]})]})})]})}):e.jsxs("div",{className:l("group flex items-center gap-3 px-3 py-2 rounded-lg","hover:bg-muted/50 transition-colors duration-150","border border-transparent hover:border-border/50"),children:[e.jsxs("div",{className:"relative flex items-center justify-center w-4 h-4",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full",r.dot)}),s.status!=="ok"&&e.jsx("div",{className:l("absolute w-2 h-2 rounded-full animate-ping opacity-75",r.dot)})]}),e.jsx("span",{className:"flex-1 text-sm font-medium truncate",children:s.name}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",r.labelColor),children:["[",r.label,"]"]}),s.fixable&&s.status!=="ok"&&e.jsxs(p,{size:"sm",variant:"ghost",onClick:()=>a.mutate(s.id),disabled:a.isPending,className:"h-6 px-2 text-xs opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx(y,{className:"w-3 h-3 mr-1"}),t("health.fix")]})]})}const V={Monitor:z,Settings:A,Users:$,Shield:H,Zap:T};function X({group:s,defaultOpen:t=!0}){const[a,r]=j.useState(t),i=V[s.icon]||z,o=s.checks.filter(m=>m.status==="ok").length,c=s.checks.length,n=s.checks.some(m=>m.status==="error"),d=s.checks.some(m=>m.status==="warning"),u=Math.round(o/c*100),f=n?"text-red-500":d?"text-yellow-500":"text-green-500",x=n?"bg-red-500":d?"bg-yellow-500":"bg-green-500";return e.jsx(k,{open:a,onOpenChange:r,children:e.jsxs("div",{className:l("rounded-lg border transition-all duration-200",n?"border-red-500/30":d?"border-yellow-500/30":"border-border"),children:[e.jsx(C,{asChild:!0,children:e.jsxs("button",{className:l("w-full flex items-center gap-3 p-3 text-left rounded-lg","hover:bg-muted/50 transition-colors duration-150",a&&"rounded-b-none border-b border-border/50"),children:[e.jsx("div",{className:l("p-1.5 rounded-md",n?"bg-red-500/10 text-red-500":d?"bg-yellow-500/10 text-yellow-500":"bg-muted text-muted-foreground"),children:e.jsx(i,{className:"w-4 h-4"})}),e.jsx("span",{className:"flex-1 text-sm font-semibold",children:s.name}),!a&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("div",{className:"w-16 h-1.5 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:l("h-full transition-all duration-500",x),style:{width:`${u}%`}})})}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",f),children:[o,"/",c]}),e.jsx(F,{className:l("w-4 h-4 text-muted-foreground transition-transform duration-200",a&&"rotate-180")})]})}),e.jsx(S,{children:e.jsx("div",{className:"p-2 space-y-0.5",children:s.checks.map(m=>e.jsx(J,{check:m},m.id))})})]})})}function Y(s){return s.errors>0?"error":s.warnings>0?"warning":"ok"}function _(s,t){const a=Math.floor((Date.now()-s)/1e3);if(a<5)return t("health.justNow");if(a<60)return t("health.secondsAgo",{count:a});const r=Math.floor(a/60);if(r<60)return t("health.minutesAgo",{count:r});const i=Math.floor(r/60);return t("health.hoursAgo",{count:i})}function ee(s){return[...s].sort((t,a)=>{const r=t.checks.filter(n=>n.status==="error").length,i=a.checks.filter(n=>n.status==="error").length,o=t.checks.filter(n=>n.status==="warning").length,c=a.checks.filter(n=>n.status==="warning").length;return r!==i?i-r:c-o})}function se(){return e.jsxs("div",{className:"font-mono text-sm text-muted-foreground flex items-center gap-2",children:[e.jsx("span",{className:"text-green-500",children:"$"}),e.jsx("span",{children:"ccs doctor"})]})}function te(){return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-6",children:[e.jsx("div",{className:"rounded-xl border bg-gradient-to-br from-background to-muted/20 p-6",children:e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsx(h,{className:"w-[120px] h-[120px] rounded-full"}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx(h,{className:"h-5 w-48"}),e.jsx(h,{className:"h-8 w-64"}),e.jsx(h,{className:"h-4 w-32"})]})]})}),e.jsx(h,{className:"h-16 w-full rounded-lg"}),e.jsx("div",{className:"space-y-3",children:[1,2,3,4].map(s=>e.jsx(h,{className:"h-20 rounded-lg"},s))})]})}function xe(){const{t:s}=N(),{data:t,isLoading:a,refetch:r,dataUpdatedAt:i}=L(),o=i,[c,n]=j.useState(0);j.useEffect(()=>{const m=setInterval(()=>n(v=>v+1),1e3);return()=>clearInterval(m)},[]);const d=()=>{navigator.clipboard.writeText("ccs doctor"),g.success(s("health.copied"))},u=()=>{r(),g.info(s("health.refreshing"))};if(a&&!t)return e.jsx(te,{});const f=t?Y(t.summary):"ok",x=t?.groups?ee(t.groups):[];return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-6",children:[e.jsxs("div",{className:l("relative overflow-hidden rounded-xl border p-6","bg-gradient-to-br from-background via-background to-muted/30"),children:[e.jsx("div",{className:"absolute inset-0 opacity-[0.02] pointer-events-none",style:{backgroundImage:"repeating-linear-gradient(0deg, transparent, transparent 2px, currentColor 2px, currentColor 3px)"}}),e.jsx("div",{className:"absolute inset-0 opacity-[0.03] pointer-events-none",children:e.jsx("div",{className:"absolute inset-0",style:{backgroundImage:"radial-gradient(circle at 1px 1px, currentColor 1px, transparent 0)",backgroundSize:"24px 24px"}})}),e.jsxs("div",{className:"relative flex flex-col md:flex-row items-start md:items-center gap-6",children:[t&&e.jsx("div",{className:"shrink-0",children:e.jsx(G,{passed:t.summary.passed,total:t.summary.total-t.summary.info,status:f,size:"md"})}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx(se,{}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx("h1",{className:"text-2xl font-bold font-mono tracking-tight",children:s("health.systemHealth")}),t?.version&&e.jsx(R,{variant:"outline",className:"font-mono text-xs bg-muted/50",children:s("health.build",{version:t.version})})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(B,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:s("health.lastScan")}),e.jsx("span",{className:"font-mono",children:o?_(o,s):"--"}),e.jsx("span",{className:"text-muted-foreground",children:"|"}),e.jsx("span",{className:"text-muted-foreground",children:s("health.autoRefresh")}),e.jsx("span",{className:"font-mono text-green-500",children:"30s"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs(p,{variant:"outline",size:"sm",onClick:d,className:"gap-2 font-mono text-xs",children:[e.jsx(I,{className:"w-3 h-3"}),"ccs doctor",e.jsx(M,{className:"w-3 h-3 opacity-50"})]}),e.jsxs(p,{variant:"outline",size:"sm",onClick:u,disabled:a,className:"gap-2",children:[e.jsx(D,{className:l("w-4 h-4",a&&"animate-spin")}),e.jsx("span",{className:"hidden sm:inline",children:s("health.refresh")}),e.jsx("kbd",{className:"hidden md:inline-flex h-5 items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium text-muted-foreground",children:"R"})]})]})]})]}),t&&e.jsx("div",{className:"rounded-lg border bg-card p-4",children:e.jsx(K,{total:t.summary.total,passed:t.summary.passed,warnings:t.summary.warnings,errors:t.summary.errors,info:t.summary.info})}),x.length>0&&e.jsx("div",{className:"space-y-3",children:x.map((m,v)=>e.jsx(X,{group:m,defaultOpen:v<2||m.checks.some(w=>w.status==="error"||w.status==="warning")},m.id))}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground border-t pt-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{children:[s("health.version")," ",e.jsx("span",{className:"font-mono",children:t?.version??"--"})]}),e.jsxs("span",{children:[s("health.platform")," ",e.jsx("span",{className:"font-mono",children:typeof navigator<"u"?navigator.platform:"linux"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-green-500 animate-pulse"}),e.jsx("span",{children:s("health.liveMonitoring")})]})]})]})}export{xe as HealthPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-Dt3edmE5.js";import{r as c}from"./react-vendor-CNOkPC89.js";import{bi as U,bj as F,a as A,I as K,bk as _,b3 as z,b5 as B,n as D,d as T}from"./index-ByjiTTw6.js";import{S as q}from"./switch-CSo86CGn.js";import{Q as Y,l as J,s as Q,r as X,o as Z,R as y,x as V,v as ee,aU as se}from"./icons-DtwH984l.js";import"./tanstack-B8i0evp-.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function te(){const{state:s}=U(),t=F(),[o,g]=c.useState(""),[n,d]=c.useState(""),[x,p]=c.useState(!1),[j,f]=c.useState(!1),S=c.useCallback(async()=>{try{t.setWebSearchLoading(!0),t.setWebSearchError(null);const a=await fetch("/api/websearch");if(!a.ok)throw new Error("Failed to load WebSearch config");const r=await a.json();t.setWebSearchConfig(r)}catch(a){t.setWebSearchError(a.message)}finally{t.setWebSearchLoading(!1)}},[t]),v=c.useCallback(async()=>{try{t.setWebSearchStatusLoading(!0);const a=await fetch("/api/websearch/status");if(!a.ok)throw new Error("Failed to load status");const r=await a.json();t.setWebSearchStatus(r)}catch{}finally{t.setWebSearchStatusLoading(!1)}},[t]),b=c.useCallback(async a=>{const r=s.webSearchConfig;if(!r)return;const w={...r,...a};t.setWebSearchConfig(w);try{t.setWebSearchSaving(!0),t.setWebSearchError(null);const l=await fetch("/api/websearch",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(w)});if(!l.ok){const k=await l.json();throw new Error(k.error||"Failed to save")}const i=await l.json();t.setWebSearchConfig(i.websearch),t.setWebSearchSuccess(!0),setTimeout(()=>t.setWebSearchSuccess(!1),1500)}catch(l){t.setWebSearchConfig(r),t.setWebSearchError(l.message)}finally{t.setWebSearchSaving(!1)}},[s.webSearchConfig,t]);c.useEffect(()=>{s.webSearchConfig&&(g(s.webSearchConfig.providers?.gemini?.model??"gemini-2.5-flash"),d(s.webSearchConfig.providers?.opencode?.model??"opencode/grok-code"))},[s.webSearchConfig]);const C=c.useCallback(async()=>{const a=s.webSearchConfig?.providers?.gemini?.model??"gemini-2.5-flash";if(o!==a){const r=s.webSearchConfig?.providers||{};await b({providers:{...r,gemini:{...r.gemini,model:o}}}),p(!0),setTimeout(()=>p(!1),2e3)}},[o,s.webSearchConfig,b]),h=c.useCallback(async()=>{const a=s.webSearchConfig?.providers?.opencode?.model??"opencode/grok-code";if(n!==a){const r=s.webSearchConfig?.providers||{};await b({providers:{...r,opencode:{...r.opencode,model:n}}}),f(!0),setTimeout(()=>f(!1),2e3)}},[n,s.webSearchConfig,b]);return{config:s.webSearchConfig,status:s.webSearchStatus,loading:s.webSearchLoading,statusLoading:s.webSearchStatusLoading,saving:s.webSearchSaving,error:s.webSearchError,success:s.webSearchSuccess,geminiModelInput:o,setGeminiModelInput:g,opencodeModelInput:n,setOpencodeModelInput:d,geminiModelSaved:x,opencodeModelSaved:j,fetchConfig:S,fetchStatus:v,saveConfig:b,saveGeminiModel:C,saveOpencodeModel:h}}function H({name:s,label:t,badge:o,badgeColor:g,enabled:n,installed:d,statusLoading:x,saving:p,onToggle:j,modelInput:f,setModelInput:S,onModelBlur:v,modelSaved:b,modelPlaceholder:C,showHint:h,setShowHint:a,installCmd:r,docsUrl:w,hintColor:l}){const{t:i}=A(),k=g==="green"?"bg-green-500/10 text-green-600":g==="blue"?"bg-blue-500/10 text-blue-600":"bg-purple-500/10 text-purple-600",W=l==="amber"?"bg-amber-50 dark:bg-amber-900/20 text-amber-700 dark:text-amber-300":l==="blue"?"bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300":"bg-purple-50 dark:bg-purple-900/20 text-purple-700 dark:text-purple-300",E=l==="amber"?"bg-amber-100 dark:bg-amber-900/40":l==="blue"?"bg-blue-100 dark:bg-blue-900/40":"bg-purple-100 dark:bg-purple-900/40",M=l==="amber"?"text-amber-600 dark:text-amber-400":l==="blue"?"text-blue-600 dark:text-blue-400":"text-purple-600 dark:text-purple-400",G=s==="opencode"?"OpenCode":s.charAt(0).toUpperCase()+s.slice(1);return e.jsxs("div",{className:`rounded-lg border transition-colors ${n?"border-primary border-l-4":"border-border"}`,children:[e.jsxs("div",{className:"flex items-center justify-between p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Y,{className:`w-5 h-5 ${n?"text-primary":"text-muted-foreground"}`}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-mono font-medium",children:s}),e.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded font-medium ${k}`,children:o}),d?e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/10 text-green-600 font-medium",children:i("settingsWebsearch.installed")}):e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-600 font-medium",children:i("settingsWebsearch.notInstalled")})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t})]})]}),e.jsx(q,{checked:n,onCheckedChange:j,disabled:p||!d})]}),n&&f!==void 0&&S&&v&&e.jsx("div",{className:"px-4 pb-4 pt-0",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground whitespace-nowrap",children:i("settingsWebsearch.model")}),e.jsx(K,{value:f,onChange:I=>S(I.target.value),onBlur:v,placeholder:C,className:"h-8 text-sm font-mono",disabled:p}),b&&e.jsxs("span",{className:"flex items-center gap-1 text-green-600 dark:text-green-400 text-xs animate-in fade-in duration-200",children:[e.jsx(J,{className:"w-3.5 h-3.5"}),i("settings.saved")]})]})}),!d&&!x&&e.jsxs("div",{className:"px-4 pb-4 pt-0 border-t border-border/50",children:[e.jsxs("button",{onClick:()=>a(!h),className:`flex items-center gap-2 text-sm hover:underline w-full py-2 ${M}`,children:[h?e.jsx(Q,{className:"w-4 h-4"}):e.jsx(X,{className:"w-4 h-4"}),i("settingsWebsearch.howInstall",{name:G})]}),h&&e.jsxs("div",{className:`mt-2 p-3 rounded-md text-sm ${W}`,children:[e.jsxs("p",{className:"mb-2",children:[i("settingsWebsearch.installGlobally")," ",i(o==="GROK_API_KEY"?"settingsWebsearch.requiresKey":"settingsWebsearch.freeTier"),":"]}),e.jsx("code",{className:`text-sm px-2 py-1 rounded font-mono block mb-2 ${E}`,children:r}),e.jsxs("a",{href:w,target:"_blank",rel:"noopener noreferrer",className:"hover:underline inline-flex items-center gap-1",children:[e.jsx(Z,{className:"w-3 h-3"}),i("settingsWebsearch.viewDocs")]})]})]})]})}function be(){const{t:s}=A(),{config:t,status:o,loading:g,statusLoading:n,saving:d,error:x,success:p,geminiModelInput:j,setGeminiModelInput:f,opencodeModelInput:S,setOpencodeModelInput:v,geminiModelSaved:b,opencodeModelSaved:C,fetchConfig:h,fetchStatus:a,saveConfig:r,saveGeminiModel:w,saveOpencodeModel:l}=te(),{fetchRawConfig:i}=_(),[k,W]=c.useState(!1),[E,M]=c.useState(!1),[G,I]=c.useState(!1);c.useEffect(()=>{h(),a(),i()},[h,a,i]);const N=t?.providers?.gemini?.enabled??!1,O=t?.providers?.grok?.enabled??!1,L=t?.providers?.opencode?.enabled??!1,R=()=>{const m=t?.providers||{},u=m.gemini?.enabled??!1;r({enabled:!u||O||L,providers:{...m,gemini:{...m.gemini,enabled:!u}}})},$=()=>{const m=t?.providers||{},u=m.grok?.enabled??!1;r({enabled:N||!u||L,providers:{...m,grok:{...m.grok,enabled:!u}}})},P=()=>{const m=t?.providers||{},u=m.opencode?.enabled??!1;r({enabled:N||O||!u,providers:{...m,opencode:{...m.opencode,enabled:!u}}})};return g?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(y,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:s("settings.loading")})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${x||p?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[x&&e.jsxs(z,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(V,{className:"h-4 w-4"}),e.jsx(B,{children:x})]}),p&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(ee,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:s("settings.saved")})]})]}),e.jsx(D,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settingsWebsearch.description")}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:s(N?"settingsWebsearch.enabled":"settingsWebsearch.disabled")}),n?e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settingsWebsearch.checking")}):o?.readiness?e.jsx("p",{className:"text-sm text-muted-foreground",children:o.readiness.message}):null]}),e.jsx(T,{variant:"ghost",size:"sm",onClick:a,disabled:n,children:e.jsx(y,{className:`w-4 h-4 ${n?"animate-spin":""}`})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsWebsearch.providers")}),!o?.geminiCli&&!o?.opencodeCli&&!o?.grokCli&&!n&&e.jsxs("div",{className:"flex flex-col items-center justify-center p-8 border-2 border-dashed rounded-lg text-center bg-muted/30",children:[e.jsx(se,{className:"w-12 h-12 text-muted-foreground mb-3 opacity-30"}),e.jsx("p",{className:"font-medium text-foreground mb-1",children:s("settingsWebsearch.noneConfigured")}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:s("settingsWebsearch.noneConfiguredHint")}),e.jsxs(T,{variant:"outline",size:"sm",onClick:a,children:[e.jsx(y,{className:"w-4 h-4 mr-2"}),s("settingsWebsearch.checkProviders")]})]}),e.jsx(H,{name:"gemini",label:"Google Gemini CLI (1000 req/day free)",badge:"FREE",badgeColor:"green",enabled:N,installed:o?.geminiCli?.installed??!1,statusLoading:n,saving:d,onToggle:R,modelInput:j,setModelInput:f,onModelBlur:w,modelSaved:b,modelPlaceholder:"gemini-2.5-flash",showHint:k,setShowHint:W,installCmd:"npm install -g @google/gemini-cli",docsUrl:"https://github.com/google-gemini/gemini-cli",hintColor:"amber"}),e.jsx(H,{name:"opencode",label:"OpenCode (web search via Zen)",badge:"FREE",badgeColor:"green",enabled:L,installed:o?.opencodeCli?.installed??!1,statusLoading:n,saving:d,onToggle:P,modelInput:S,setModelInput:v,onModelBlur:l,modelSaved:C,modelPlaceholder:"opencode/grok-code",showHint:E,setShowHint:M,installCmd:"curl -fsSL https://opencode.ai/install | bash",docsUrl:"https://github.com/sst/opencode",hintColor:"purple"}),e.jsx(H,{name:"grok",label:"xAI Grok CLI (web + X search)",badge:"GROK_API_KEY",badgeColor:"blue",enabled:O,installed:o?.grokCli?.installed??!1,statusLoading:n,saving:d,onToggle:$,showHint:G,setShowHint:I,installCmd:"npm install -g @vibe-kit/grok-cli",docsUrl:"https://github.com/superagent-ai/grok-cli",hintColor:"blue"})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(T,{variant:"outline",size:"sm",onClick:()=>{h(),i()},disabled:g||d,className:"w-full",children:[e.jsx(y,{className:`w-4 h-4 mr-2 ${g?"animate-spin":""}`}),s("settings.refresh")]})})]})}export{be as default};
|
|
1
|
+
import{j as e}from"./radix-ui-Dt3edmE5.js";import{r as c}from"./react-vendor-CNOkPC89.js";import{bg as U,bh as F,a as A,I as K,bi as _,b1 as z,b3 as B,n as D,d as T}from"./index-Dz76Rk36.js";import{S as q}from"./switch-Bsk1Z1Fy.js";import{Q as Y,l as J,s as Q,r as X,o as Z,R as y,x as V,v as ee,aU as se}from"./icons-DtwH984l.js";import"./tanstack-B8i0evp-.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function te(){const{state:s}=U(),t=F(),[o,g]=c.useState(""),[n,d]=c.useState(""),[x,p]=c.useState(!1),[j,f]=c.useState(!1),S=c.useCallback(async()=>{try{t.setWebSearchLoading(!0),t.setWebSearchError(null);const a=await fetch("/api/websearch");if(!a.ok)throw new Error("Failed to load WebSearch config");const r=await a.json();t.setWebSearchConfig(r)}catch(a){t.setWebSearchError(a.message)}finally{t.setWebSearchLoading(!1)}},[t]),v=c.useCallback(async()=>{try{t.setWebSearchStatusLoading(!0);const a=await fetch("/api/websearch/status");if(!a.ok)throw new Error("Failed to load status");const r=await a.json();t.setWebSearchStatus(r)}catch{}finally{t.setWebSearchStatusLoading(!1)}},[t]),b=c.useCallback(async a=>{const r=s.webSearchConfig;if(!r)return;const w={...r,...a};t.setWebSearchConfig(w);try{t.setWebSearchSaving(!0),t.setWebSearchError(null);const l=await fetch("/api/websearch",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(w)});if(!l.ok){const k=await l.json();throw new Error(k.error||"Failed to save")}const i=await l.json();t.setWebSearchConfig(i.websearch),t.setWebSearchSuccess(!0),setTimeout(()=>t.setWebSearchSuccess(!1),1500)}catch(l){t.setWebSearchConfig(r),t.setWebSearchError(l.message)}finally{t.setWebSearchSaving(!1)}},[s.webSearchConfig,t]);c.useEffect(()=>{s.webSearchConfig&&(g(s.webSearchConfig.providers?.gemini?.model??"gemini-2.5-flash"),d(s.webSearchConfig.providers?.opencode?.model??"opencode/grok-code"))},[s.webSearchConfig]);const C=c.useCallback(async()=>{const a=s.webSearchConfig?.providers?.gemini?.model??"gemini-2.5-flash";if(o!==a){const r=s.webSearchConfig?.providers||{};await b({providers:{...r,gemini:{...r.gemini,model:o}}}),p(!0),setTimeout(()=>p(!1),2e3)}},[o,s.webSearchConfig,b]),h=c.useCallback(async()=>{const a=s.webSearchConfig?.providers?.opencode?.model??"opencode/grok-code";if(n!==a){const r=s.webSearchConfig?.providers||{};await b({providers:{...r,opencode:{...r.opencode,model:n}}}),f(!0),setTimeout(()=>f(!1),2e3)}},[n,s.webSearchConfig,b]);return{config:s.webSearchConfig,status:s.webSearchStatus,loading:s.webSearchLoading,statusLoading:s.webSearchStatusLoading,saving:s.webSearchSaving,error:s.webSearchError,success:s.webSearchSuccess,geminiModelInput:o,setGeminiModelInput:g,opencodeModelInput:n,setOpencodeModelInput:d,geminiModelSaved:x,opencodeModelSaved:j,fetchConfig:S,fetchStatus:v,saveConfig:b,saveGeminiModel:C,saveOpencodeModel:h}}function H({name:s,label:t,badge:o,badgeColor:g,enabled:n,installed:d,statusLoading:x,saving:p,onToggle:j,modelInput:f,setModelInput:S,onModelBlur:v,modelSaved:b,modelPlaceholder:C,showHint:h,setShowHint:a,installCmd:r,docsUrl:w,hintColor:l}){const{t:i}=A(),k=g==="green"?"bg-green-500/10 text-green-600":g==="blue"?"bg-blue-500/10 text-blue-600":"bg-purple-500/10 text-purple-600",W=l==="amber"?"bg-amber-50 dark:bg-amber-900/20 text-amber-700 dark:text-amber-300":l==="blue"?"bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300":"bg-purple-50 dark:bg-purple-900/20 text-purple-700 dark:text-purple-300",E=l==="amber"?"bg-amber-100 dark:bg-amber-900/40":l==="blue"?"bg-blue-100 dark:bg-blue-900/40":"bg-purple-100 dark:bg-purple-900/40",M=l==="amber"?"text-amber-600 dark:text-amber-400":l==="blue"?"text-blue-600 dark:text-blue-400":"text-purple-600 dark:text-purple-400",G=s==="opencode"?"OpenCode":s.charAt(0).toUpperCase()+s.slice(1);return e.jsxs("div",{className:`rounded-lg border transition-colors ${n?"border-primary border-l-4":"border-border"}`,children:[e.jsxs("div",{className:"flex items-center justify-between p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Y,{className:`w-5 h-5 ${n?"text-primary":"text-muted-foreground"}`}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-mono font-medium",children:s}),e.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded font-medium ${k}`,children:o}),d?e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/10 text-green-600 font-medium",children:i("settingsWebsearch.installed")}):e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-600 font-medium",children:i("settingsWebsearch.notInstalled")})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t})]})]}),e.jsx(q,{checked:n,onCheckedChange:j,disabled:p||!d})]}),n&&f!==void 0&&S&&v&&e.jsx("div",{className:"px-4 pb-4 pt-0",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground whitespace-nowrap",children:i("settingsWebsearch.model")}),e.jsx(K,{value:f,onChange:I=>S(I.target.value),onBlur:v,placeholder:C,className:"h-8 text-sm font-mono",disabled:p}),b&&e.jsxs("span",{className:"flex items-center gap-1 text-green-600 dark:text-green-400 text-xs animate-in fade-in duration-200",children:[e.jsx(J,{className:"w-3.5 h-3.5"}),i("settings.saved")]})]})}),!d&&!x&&e.jsxs("div",{className:"px-4 pb-4 pt-0 border-t border-border/50",children:[e.jsxs("button",{onClick:()=>a(!h),className:`flex items-center gap-2 text-sm hover:underline w-full py-2 ${M}`,children:[h?e.jsx(Q,{className:"w-4 h-4"}):e.jsx(X,{className:"w-4 h-4"}),i("settingsWebsearch.howInstall",{name:G})]}),h&&e.jsxs("div",{className:`mt-2 p-3 rounded-md text-sm ${W}`,children:[e.jsxs("p",{className:"mb-2",children:[i("settingsWebsearch.installGlobally")," ",i(o==="GROK_API_KEY"?"settingsWebsearch.requiresKey":"settingsWebsearch.freeTier"),":"]}),e.jsx("code",{className:`text-sm px-2 py-1 rounded font-mono block mb-2 ${E}`,children:r}),e.jsxs("a",{href:w,target:"_blank",rel:"noopener noreferrer",className:"hover:underline inline-flex items-center gap-1",children:[e.jsx(Z,{className:"w-3 h-3"}),i("settingsWebsearch.viewDocs")]})]})]})]})}function be(){const{t:s}=A(),{config:t,status:o,loading:g,statusLoading:n,saving:d,error:x,success:p,geminiModelInput:j,setGeminiModelInput:f,opencodeModelInput:S,setOpencodeModelInput:v,geminiModelSaved:b,opencodeModelSaved:C,fetchConfig:h,fetchStatus:a,saveConfig:r,saveGeminiModel:w,saveOpencodeModel:l}=te(),{fetchRawConfig:i}=_(),[k,W]=c.useState(!1),[E,M]=c.useState(!1),[G,I]=c.useState(!1);c.useEffect(()=>{h(),a(),i()},[h,a,i]);const N=t?.providers?.gemini?.enabled??!1,O=t?.providers?.grok?.enabled??!1,L=t?.providers?.opencode?.enabled??!1,R=()=>{const m=t?.providers||{},u=m.gemini?.enabled??!1;r({enabled:!u||O||L,providers:{...m,gemini:{...m.gemini,enabled:!u}}})},$=()=>{const m=t?.providers||{},u=m.grok?.enabled??!1;r({enabled:N||!u||L,providers:{...m,grok:{...m.grok,enabled:!u}}})},P=()=>{const m=t?.providers||{},u=m.opencode?.enabled??!1;r({enabled:N||O||!u,providers:{...m,opencode:{...m.opencode,enabled:!u}}})};return g?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(y,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:s("settings.loading")})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${x||p?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[x&&e.jsxs(z,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(V,{className:"h-4 w-4"}),e.jsx(B,{children:x})]}),p&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(ee,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:s("settings.saved")})]})]}),e.jsx(D,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settingsWebsearch.description")}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:s(N?"settingsWebsearch.enabled":"settingsWebsearch.disabled")}),n?e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settingsWebsearch.checking")}):o?.readiness?e.jsx("p",{className:"text-sm text-muted-foreground",children:o.readiness.message}):null]}),e.jsx(T,{variant:"ghost",size:"sm",onClick:a,disabled:n,children:e.jsx(y,{className:`w-4 h-4 ${n?"animate-spin":""}`})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:s("settingsWebsearch.providers")}),!o?.geminiCli&&!o?.opencodeCli&&!o?.grokCli&&!n&&e.jsxs("div",{className:"flex flex-col items-center justify-center p-8 border-2 border-dashed rounded-lg text-center bg-muted/30",children:[e.jsx(se,{className:"w-12 h-12 text-muted-foreground mb-3 opacity-30"}),e.jsx("p",{className:"font-medium text-foreground mb-1",children:s("settingsWebsearch.noneConfigured")}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:s("settingsWebsearch.noneConfiguredHint")}),e.jsxs(T,{variant:"outline",size:"sm",onClick:a,children:[e.jsx(y,{className:"w-4 h-4 mr-2"}),s("settingsWebsearch.checkProviders")]})]}),e.jsx(H,{name:"gemini",label:"Google Gemini CLI (1000 req/day free)",badge:"FREE",badgeColor:"green",enabled:N,installed:o?.geminiCli?.installed??!1,statusLoading:n,saving:d,onToggle:R,modelInput:j,setModelInput:f,onModelBlur:w,modelSaved:b,modelPlaceholder:"gemini-2.5-flash",showHint:k,setShowHint:W,installCmd:"npm install -g @google/gemini-cli",docsUrl:"https://github.com/google-gemini/gemini-cli",hintColor:"amber"}),e.jsx(H,{name:"opencode",label:"OpenCode (web search via Zen)",badge:"FREE",badgeColor:"green",enabled:L,installed:o?.opencodeCli?.installed??!1,statusLoading:n,saving:d,onToggle:P,modelInput:S,setModelInput:v,onModelBlur:l,modelSaved:C,modelPlaceholder:"opencode/grok-code",showHint:E,setShowHint:M,installCmd:"curl -fsSL https://opencode.ai/install | bash",docsUrl:"https://github.com/sst/opencode",hintColor:"purple"}),e.jsx(H,{name:"grok",label:"xAI Grok CLI (web + X search)",badge:"GROK_API_KEY",badgeColor:"blue",enabled:O,installed:o?.grokCli?.installed??!1,statusLoading:n,saving:d,onToggle:$,showHint:G,setShowHint:I,installCmd:"npm install -g @vibe-kit/grok-cli",docsUrl:"https://github.com/superagent-ai/grok-cli",hintColor:"blue"})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(T,{variant:"outline",size:"sm",onClick:()=>{h(),i()},disabled:g||d,className:"w-full",children:[e.jsx(y,{className:`w-4 h-4 mr-2 ${g?"animate-spin":""}`}),s("settings.refresh")]})})]})}export{be as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-Dt3edmE5.js";import{r as f,c as pe}from"./react-vendor-CNOkPC89.js";import{u as M,a as ee,C as p,b as g,S as h,c,P as N,B as I,d as H,e as se,f as ge,g as te,h as je,i as ae,j as y,k as D,l as ye,m as Ne,n as we,o as be}from"./index-ByjiTTw6.js";import{$ as ve,ab as re,ac as z,ad as ne,Y as le,a4 as ke,G as Ce,ae as Se,R as De,Q,U as Le,Z as ie,u as $e,a6 as G,af as Te,N as Fe,C as Re,ag as Me,ah as Pe}from"./icons-DtwH984l.js";import{a as Be,u as P}from"./tanstack-B8i0evp-.js";import{K as $,L as Y,f as k,H as Ae}from"./utils-CzKF5WmX.js";import{R as oe,A as Ue,C as qe,X as Ie,Y as V,T as ce,a as Z,P as Oe,b as Ke,c as Ee}from"./charts-BBPXh0Ar.js";import"./notifications-B2HqRBj7.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function Ge({data:s,isLoading:t}){const{privacyMode:r}=M(),{t:n}=ee();if(t)return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4",children:[1,2,3,4,5].map(a=>e.jsx(p,{children:e.jsx(g,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-4 w-[100px]"}),e.jsx(h,{className:"h-8 w-[80px]"})]}),e.jsx(h,{className:"h-8 w-8 rounded-lg"})]})})},a))});const l=(s?.tokenBreakdown?.cacheCreation?.cost??0)+(s?.tokenBreakdown?.cacheRead?.cost??0),i=s?.totalCost?Math.round(l/s.totalCost*100):0,x=[{title:n("analyticsSummary.totalTokens"),value:s?.totalTokens??0,icon:ve,format:a=>R(a),color:"text-blue-600",bgColor:"bg-blue-100 dark:bg-blue-900/20",subtitle:n("analyticsSummary.totalTokensSubtitle",{input:R(s?.totalInputTokens??0),output:R(s?.totalOutputTokens??0)})},{title:n("analyticsSummary.totalCost"),value:s?.totalCost??0,icon:re,format:a=>`$${a.toFixed(2)}`,color:"text-green-600",bgColor:"bg-green-100 dark:bg-green-900/20",subtitle:n("analyticsSummary.totalCostSubtitle",{value:s?.averageCostPerDay?.toFixed(2)??"0.00"})},{title:n("analyticsSummary.cacheTokens"),value:s?.totalCacheTokens??0,icon:z,format:a=>R(a),color:"text-cyan-600",bgColor:"bg-cyan-100 dark:bg-cyan-900/20",subtitle:n("analyticsSummary.cacheTokensSubtitle",{cost:l.toFixed(2),percent:i})},{title:n("analyticsSummary.inputCost"),value:s?.tokenBreakdown?.input?.cost??0,icon:ne,format:a=>`$${a.toFixed(2)}`,color:"text-purple-600",bgColor:"bg-purple-100 dark:bg-purple-900/20",subtitle:n("analyticsSummary.tokensSubtitle",{value:R(s?.tokenBreakdown?.input?.tokens??0)})},{title:n("analyticsSummary.outputCost"),value:s?.tokenBreakdown?.output?.cost??0,icon:le,format:a=>`$${a.toFixed(2)}`,color:"text-orange-600",bgColor:"bg-orange-100 dark:bg-orange-900/20",subtitle:n("analyticsSummary.tokensSubtitle",{value:R(s?.tokenBreakdown?.output?.tokens??0)})}];return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4",children:x.map((a,o)=>{const d=a.icon;return e.jsx(p,{className:"hover:shadow-md transition-shadow",children:e.jsx(g,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between space-x-2",children:[e.jsxs("div",{className:"space-y-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground truncate",children:a.title}),e.jsx("p",{className:c("text-xl font-bold truncate",r&&N),children:a.format(a.value)}),a.subtitle&&e.jsx("p",{className:c("text-[10px] text-muted-foreground truncate",r&&N),children:a.subtitle})]}),e.jsx("div",{className:c("p-2 rounded-lg shrink-0",a.bgColor),children:e.jsx(d,{className:c("h-4 w-4",a.color)})})]})})},o)})})}function R(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function We({model:s}){const{privacyMode:t}=M(),r=He(s.ioRatio);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ke,{className:"h-4 w-4 text-primary shrink-0"}),e.jsx("h4",{className:"font-semibold leading-none truncate",title:s.model,children:s.model})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(I,{variant:"secondary",className:"text-[10px] h-5 px-1.5",children:[s.percentage.toFixed(1),"% usage"]}),e.jsxs(I,{variant:r.variant,className:"text-[10px] h-5 px-1.5",children:[s.ioRatio.toFixed(0),":1 I/O"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("p",{className:c("text-lg font-bold",t&&N),children:["$",s.cost.toFixed(2)]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:"Total Cost"})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsx("p",{className:c("text-lg font-bold",t&&N),children:ze(s.tokens)}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:"Total Tokens"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:"Token Breakdown"}),e.jsxs("div",{className:c("space-y-1",t&&N),children:[e.jsx(W,{label:"Input",tokens:s.inputTokens,cost:s.costBreakdown.input.cost,color:"#335c67",icon:ne}),e.jsx(W,{label:"Output",tokens:s.outputTokens,cost:s.costBreakdown.output.cost,color:"#fff3b0",icon:le}),e.jsx(W,{label:"Cache Write",tokens:s.cacheCreationTokens,cost:s.costBreakdown.cacheCreation.cost,color:"#e09f3e",icon:z}),e.jsx(W,{label:"Cache Read",tokens:s.cacheReadTokens,cost:s.costBreakdown.cacheRead.cost,color:"#9e2a2b",icon:z})]})]}),e.jsxs("div",{className:"p-2.5 rounded-md border bg-muted/20 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ce,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs font-medium",children:"Input/Output Ratio"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-snug",children:r.description})]})]})}function W({label:s,tokens:t,cost:r,color:n,icon:l}){return t===0?null:e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:"w-1 h-6 rounded-full shrink-0",style:{backgroundColor:n}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium truncate",children:s}),e.jsxs("span",{className:"font-mono text-muted-foreground",children:["$",r.toFixed(3)]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx(l,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:_e(t)})]})]})]})}function He(s){return s>=200?{variant:"destructive",description:"Extended thinking or large context loading. Expected for reasoning models."}:s>=50?{variant:"secondary",description:"More input than output. Typical for analysis tasks."}:s>=5?{variant:"outline",description:"Balanced input/output ratio for typical coding tasks."}:{variant:"default",description:"More output than input. Generation-heavy workload."}}function _e(s){return s.toLocaleString()}function ze(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}const Ye="/api";function b(s){const t=s.getFullYear(),r=String(s.getMonth()+1).padStart(2,"0"),n=String(s.getDate()).padStart(2,"0");return`${t}${r}${n}`}const T={summary:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),L(`/usage/summary?${t}`)},trends:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),L(`/usage/daily?${t}`)},hourly:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),L(`/usage/hourly?${t}`)},models:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),L(`/usage/models?${t}`)},sessions:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),s?.limit&&t.append("limit",s.limit.toString()),s?.offset&&t.append("offset",s.offset.toString()),L(`/usage/sessions?${t}`)},monthly:(s,t)=>{const r=new URLSearchParams;return s&&r.append("months",s.toString()),t&&r.append("profile",t),L(`/usage/monthly?${r}`)},refresh:async()=>{if(!(await fetch(`${Ye}/usage/refresh`,{method:"POST",headers:{"Content-Type":"application/json"}})).ok)throw new Error("Failed to refresh usage cache")},status:()=>L("/usage/status"),insights:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),L(`/usage/insights?${t}`)}};async function L(s){const r=await fetch(`/api${s}`,{headers:{"Content-Type":"application/json"}});if(!r.ok){const l=await r.json().catch(()=>({error:"Unknown error"}));throw new Error(l.error||r.statusText)}const n=await r.json();return n.data||n}function Qe(s){return P({queryKey:["usage","summary",s],queryFn:()=>T.summary(s),staleTime:60*1e3})}function Ve(s){return P({queryKey:["usage","trends",s],queryFn:()=>T.trends(s),staleTime:60*1e3})}function Ze(s){return P({queryKey:["usage","hourly",s],queryFn:()=>T.hourly(s),staleTime:60*1e3})}function Xe(s){return P({queryKey:["usage","models",s],queryFn:()=>T.models(s),staleTime:60*1e3})}function Je(){const s=Be();return f.useCallback(async()=>{await T.refresh(),await s.invalidateQueries({queryKey:["usage"]})},[s])}function es(){return P({queryKey:["usage","status"],queryFn:()=>T.status(),staleTime:10*1e3,refetchInterval:30*1e3})}function ss(s){return P({queryKey:["usage","sessions",s],queryFn:()=>T.sessions(s),staleTime:60*1e3})}function ts(){const[s,t]=f.useState({from:$(new Date,30),to:new Date}),[r,n]=f.useState(!1),[l,i]=f.useState(null),[x,a]=f.useState(null),[o,d]=f.useState("daily"),u=Je(),m=f.useCallback(async()=>{n(!0);try{await u()}finally{n(!1)}},[u]),j=f.useMemo(()=>({startDate:s?.from,endDate:s?.to}),[s?.from,s?.to]),{data:w,isLoading:v}=Qe(j),{data:C,isLoading:S}=Ve(j),{data:B,isLoading:A}=Ze(j),{data:U,isLoading:q}=Xe(j),{data:_,isLoading:O}=ss({...j,limit:3}),{data:K}=es(),de=f.useCallback(()=>{const F=new Date;t({from:$(F,1),to:F}),d("hourly")},[]),xe=f.useCallback(F=>{t(F),d("daily")},[]),ue=f.useMemo(()=>K?.lastFetch?Y(new Date(K.lastFetch),{addSuffix:!0}):null,[K?.lastFetch]),me=f.useCallback((F,fe)=>{const E=fe.currentTarget.getBoundingClientRect();a({x:E.left+E.width/2,y:E.top+E.height/2}),i(F)},[]),he=f.useCallback(()=>{i(null),a(null)},[]);return{dateRange:s,isRefreshing:r,viewMode:o,selectedModel:l,popoverPosition:x,summary:w,trends:C,hourlyData:B,models:U,sessions:_,status:K,isSummaryLoading:v,isTrendsLoading:S,isHourlyLoading:A,isModelsLoading:q,isSessionsLoading:O,isLoading:v||S||q||O,handleRefresh:m,handleTodayClick:de,handleDateRangeChange:xe,handleModelClick:me,handlePopoverClose:he,lastUpdatedText:ue}}function as({value:s,onChange:t,presets:r=[{label:"Last 7 days",range:{from:$(new Date,7),to:new Date}},{label:"Last 30 days",range:{from:$(new Date,30),to:new Date}},{label:"Last 90 days",range:{from:$(new Date,90),to:new Date}}],className:n}){const[l,i]=pe.useState(!1),x=a=>!s||!s.from||!s.to||!a.from||!a.to?!1:k(s.from,"yyyy-MM-dd")===k(a.from,"yyyy-MM-dd")&&k(s.to,"yyyy-MM-dd")===k(a.to,"yyyy-MM-dd");return e.jsxs("div",{className:c("flex flex-wrap items-center gap-2",n),children:[r.map(a=>e.jsx(H,{variant:x(a.range)?"default":"outline",size:"sm",onClick:()=>t(a.range),children:a.label},a.label)),e.jsxs(se,{open:l,onOpenChange:i,children:[e.jsx(ge,{asChild:!0,children:e.jsxs(H,{id:"date",variant:"outline",className:c("w-auto min-w-[200px] sm:min-w-[240px] justify-start text-left font-normal",!s&&"text-muted-foreground"),children:[e.jsx(Se,{className:"mr-2 h-4 w-4"}),s?.from?s.to?e.jsxs(e.Fragment,{children:[k(s.from,"LLL dd, y")," - ",k(s.to,"LLL dd, y")]}):k(s.from,"LLL dd, y"):e.jsx("span",{children:"Pick a date"})]})}),e.jsx(te,{className:"w-auto p-0",align:"end",children:e.jsx(je,{initialFocus:!0,mode:"range",defaultMonth:s?.from,selected:s,onSelect:t,numberOfMonths:2})})]})]})}function rs({dateRange:s,onDateRangeChange:t,onTodayClick:r,onRefresh:n,isRefreshing:l,lastUpdatedText:i,viewMode:x}){const{t:a}=ee();return e.jsxs("div",{className:"flex flex-col gap-3 shrink-0 xl:flex-row xl:items-center xl:justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold",children:a("analytics.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a("analytics.subtitle")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 xl:justify-end",children:[e.jsx(H,{variant:x==="hourly"?"default":"outline",size:"sm",className:"h-8",onClick:r,children:"24H"}),e.jsx(as,{className:"flex-wrap",value:s,onChange:t,presets:[{label:"7D",range:{from:$(new Date,7),to:new Date}},{label:"30D",range:{from:$(new Date,30),to:new Date}},{label:a("analytics.month"),range:{from:Ae(new Date),to:new Date}},{label:a("analytics.allTime"),range:{from:void 0,to:new Date}}]}),i&&e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:a("analytics.updated",{value:i})}),e.jsx(H,{variant:"outline",size:"sm",className:"gap-2 h-8",onClick:n,disabled:l,children:e.jsx(De,{className:`w-3.5 h-3.5 ${l?"animate-spin":""}`})})]})]})}function ns({data:s,isLoading:t,granularity:r="daily",className:n}){const{privacyMode:l}=M(),i=f.useMemo(()=>!s||s.length===0?[]:(r==="hourly"?s:[...s].reverse()).map(o=>{const d="hour"in o?o.hour:o.date;return{...o,dateFormatted:ls(d,r),costRounded:Number(o.cost.toFixed(4))}}),[s,r]);if(t)return e.jsx(h,{className:c("h-full w-full",n)});if(!s||s.length===0)return e.jsx("div",{className:c("h-full flex items-center justify-center",n),children:e.jsx("p",{className:"text-muted-foreground",children:r==="hourly"?"No usage data for today":"No usage data available"})});const x=({x:a,y:o,payload:d,isRight:u})=>{const m=u?`$${d.value}`:X(Number(d.value));return e.jsx("text",{x:a,y:o,dy:4,textAnchor:u?"start":"end",fontSize:12,fill:"currentColor",className:c("fill-muted-foreground",l&&"blur-[4px]"),children:m})};return e.jsx("div",{className:c("w-full h-full",n),children:e.jsx(oe,{width:"100%",height:"100%",children:e.jsxs(Ue,{data:i,margin:{top:5,right:30,left:20,bottom:5},children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"tokenGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#0080FF",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#0080FF",stopOpacity:.1})]}),e.jsxs("linearGradient",{id:"costGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#00C49F",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#00C49F",stopOpacity:.1})]})]}),e.jsx(qe,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Ie,{dataKey:"dateFormatted",tick:{fontSize:12},tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(V,{yAxisId:"left",orientation:"left",tick:a=>e.jsx(x,{...a,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(V,{yAxisId:"right",orientation:"right",tick:a=>e.jsx(x,{...a,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(ce,{content:({active:a,payload:o,label:d})=>{if(!a||!o||!o.length)return null;const u=o[0].payload;return e.jsxs("div",{className:"rounded-lg border bg-background p-3 shadow-lg",children:[e.jsx("p",{className:"font-medium mb-2",children:d}),o.map((m,j)=>e.jsxs("p",{className:c("text-sm",l&&N),style:{color:m.color},children:[m.name,":"," ",m.name==="Tokens"?X(Number(m.value)||0):`$${m.value}`]},j)),"requests"in u&&e.jsxs("p",{className:c("text-sm text-muted-foreground mt-1",l&&N),children:["Requests: ",u.requests]})]})}}),e.jsx(Z,{yAxisId:"left",type:"monotone",dataKey:"tokens",stroke:"#0080FF",strokeWidth:2,fillOpacity:1,fill:"url(#tokenGradient)",name:"Tokens"}),e.jsx(Z,{yAxisId:"right",type:"monotone",dataKey:"costRounded",stroke:"#00C49F",strokeWidth:2,fillOpacity:1,fill:"url(#costGradient)",name:"Cost"})]})})})}function ls(s,t){if(t==="hourly"){const[n,l]=s.split(" ");if(n&&l){const i=new Date(`${n}T${l}:00Z`);return k(i,"HH:mm")}return s}const r=new Date(s);return t==="monthly"?k(r,"MMM yyyy"):k(r,"MMM dd")}function X(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function is({data:s,isLoading:t,className:r}){const{privacyMode:n}=M(),l=f.useMemo(()=>!s||s.length===0?[]:s.map(a=>({name:a.model,value:a.tokens,cost:a.cost,percentage:a.percentage,fill:ae(a.model)})),[s]);if(t)return e.jsx(h,{className:c("h-full min-h-[100px] w-full",r)});if(!s||s.length===0)return e.jsx("div",{className:c("h-full min-h-[100px] flex items-center justify-center",r),children:e.jsx("p",{className:"text-muted-foreground",children:"No model data available"})});const i=({active:a,payload:o})=>{if(!a||!o)return null;const d=o;if(!d.length)return null;const u=d[0].payload;return e.jsxs("div",{className:"rounded-lg border bg-background p-2 shadow-lg text-xs",children:[e.jsx("p",{className:"font-medium mb-1",children:u.name}),e.jsxs("p",{className:c("text-muted-foreground",n&&N),children:[os(u.value)," (",u.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:c("text-muted-foreground",n&&N),children:["$",u.cost.toFixed(4)]})]})},x=a=>a.percentage>5?`${a.percentage.toFixed(1)}%`:"";return e.jsx("div",{className:c("w-full h-full min-h-[100px]",r),children:e.jsx(oe,{width:"100%",height:"100%",children:e.jsxs(Oe,{children:[e.jsx(Ke,{data:l,cx:"50%",cy:"50%",labelLine:!1,label:x,innerRadius:50,outerRadius:70,paddingAngle:2,dataKey:"value",children:l.map((a,o)=>e.jsx(Ee,{fill:a.fill,strokeWidth:1},`cell-${o}`))}),e.jsx(ce,{content:i})]})})})}function os(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function cs(s){if(!s)return"";const r=s.replace(/^\/|\/$/g,"").split("/").filter(n=>n.length>0);return r[r.length-1]||""}function ds({data:s,isLoading:t,className:r}){const{privacyMode:n}=M(),l=f.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const i=s.sessions,x=s.total,a=i.reduce((w,v)=>w+(v.inputTokens+v.outputTokens),0),o=Math.round(a/i.length),u=i.reduce((w,v)=>w+v.cost,0)/i.length,m=i[0],j=m?Y(new Date(m.lastActivity),{addSuffix:!0}):"N/A";return{totalSessions:x,avgTokens:o,avgCost:u,lastActive:j,recentSessions:i.slice(0,3)}},[s]);return t?e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",r),children:[e.jsx(y,{className:"px-3 py-2",children:e.jsx(h,{className:"h-5 w-32"})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(h,{className:"h-full w-full"})})]}):l?e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm",r),children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Q,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsxs(g,{className:"px-3 pb-3 pt-0 flex-1 min-h-0 flex flex-col gap-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-blue-600 dark:text-blue-400",children:[e.jsx(Le,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xl font-bold",children:l.totalSessions})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:"Total Sessions"})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-green-600 dark:text-green-400",children:[e.jsx(ie,{className:"w-4 h-4"}),e.jsxs("span",{className:c("text-xl font-bold",n&&N),children:["$",l.avgCost.toFixed(2)]})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:"Avg Cost/Session"})]})]}),e.jsxs("div",{className:"flex-1 min-h-0 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground font-medium mb-1",children:[e.jsx($e,{className:"w-3 h-3"}),"Recent Activity"]}),e.jsx("div",{className:"space-y-1.5 max-h-full overflow-y-auto pr-1",children:l.recentSessions.map(i=>e.jsxs("div",{className:"flex items-center justify-between text-xs p-1.5 rounded bg-muted/30 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex flex-col min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium truncate",title:i.projectPath,children:cs(i.projectPath)}),(i.target??"claude")!=="claude"&&e.jsx("span",{className:"shrink-0 px-1 py-0 text-[9px] font-medium rounded bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-300 uppercase",children:i.target})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:Y(new Date(i.lastActivity),{addSuffix:!0})})]}),e.jsxs("div",{className:c("text-right shrink-0 ml-2",n&&N),children:[e.jsxs("div",{className:"font-mono",children:["$",i.cost.toFixed(2)]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[xs(i.inputTokens+i.outputTokens)," toks"]})]})]},i.sessionId))})]})]})]}):e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",r),children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Q,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-sm text-muted-foreground text-center",children:"No session data available"})})]})}function xs(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}function us({className:s,isLoading:t}){const{data:r,isLoading:n}=ye(),{data:l,isLoading:i,error:x}=Ne(r?.running);if(t||n||r?.running&&i)return e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",s),children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"CLIProxy Stats"]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(h,{className:"h-4 w-[100px]"}),e.jsx(h,{className:"h-16 w-full"})]})})]});if(!r?.running)return e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 border-dashed",s),children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4 text-muted-foreground"}),"CLIProxy Stats"]}),e.jsx(I,{variant:"secondary",className:"text-[10px] h-5",children:"Offline"})]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"Start a CLIProxy session (gemini, codex, agy) to collect stats."})})]});if(x)return e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 border-destructive/50",s),children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsx(I,{variant:"destructive",className:"text-[10px] h-5",children:"Error"})]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx("p",{className:"text-xs text-destructive",children:x.message})})]});const o=l?.totalRequests??0,d=l?.quotaExceededCount??0,u=o-d,m=o>0?Math.round(u/o*100):100,j=l?.tokens?.total??0,w=Object.entries(l?.requestsByModel??{}).sort((C,S)=>S[1]-C[1]).slice(0,4),v=w.length>0?w[0][1]:1;return e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",s),children:[e.jsx(y,{className:"px-3 py-2 border-b bg-muted/5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsxs(I,{variant:"outline",className:"text-[10px] h-5 text-green-600 border-green-200 bg-green-50 dark:bg-green-900/10 dark:border-green-800",children:[e.jsx(ie,{className:"h-3 w-3 mr-0.5"}),"Running"]})]})}),e.jsx(g,{className:"p-0 flex-1 min-h-0",children:e.jsx(we,{className:"h-full",children:e.jsxs("div",{className:"p-3 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsxs("div",{className:"relative",children:[e.jsxs("svg",{className:"w-10 h-10 -rotate-90",viewBox:"0 0 36 36",children:[e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",className:"text-muted/30"}),e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeDasharray:`${m*.88} 88`,strokeLinecap:"round",className:m>=90?"text-green-500":"text-amber-500"})]}),e.jsxs("span",{className:"absolute inset-0 flex items-center justify-center text-[8px] font-bold",children:[m,"%"]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:J(o)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:d>0?`${d} failed`:"All success"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsx("div",{className:"p-1.5 rounded-md bg-purple-100 dark:bg-purple-900/20",children:e.jsx(Te,{className:"h-4 w-4 text-purple-600"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:J(j)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:"Total tokens"})]})]})]}),w.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-medium text-muted-foreground",children:[e.jsx(Fe,{className:"h-3 w-3"}),"Models Used"]}),e.jsx("div",{className:"space-y-1",children:w.map(([C,S])=>{const B=Math.round(S/v*100),A=ms(C);return e.jsxs("div",{className:"group",children:[e.jsxs("div",{className:"flex items-center justify-between text-[10px] mb-0.5",children:[e.jsx("span",{className:"truncate font-medium",title:C,children:A}),e.jsx("span",{className:"text-muted-foreground shrink-0 ml-2",children:S})]}),e.jsx("div",{className:"h-1 bg-muted/50 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-accent/70 rounded-full transition-all",style:{width:`${B}%`}})})]},C)})})]})]})})})]})}function J(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function ms(s){let t=s.replace(/^gemini-claude-/,"").replace(/^gemini-/,"").replace(/^claude-/,"").replace(/^anthropic\./,"").replace(/-thinking$/," Thinking");return t=t.split(/[-_]/).map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" "),t.length>20&&(t=t.slice(0,18)+"..."),t}function hs(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(0)}K`:s.toString()}function fs({models:s,isLoading:t,onModelClick:r,privacyMode:n}){return e.jsxs(p,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-4",children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(re,{className:"w-4 h-4"}),"Cost by Model"]})}),e.jsx(g,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 overflow-y-auto",children:t?e.jsx(h,{className:"h-full w-full"}):e.jsxs("div",{className:"space-y-0.5",children:[[...s||[]].sort((l,i)=>i.cost-l.cost).map(l=>e.jsxs("button",{className:"group flex items-center text-xs w-full hover:bg-muted/50 rounded px-2 py-1.5 transition-colors cursor-pointer gap-3",onClick:i=>r(l,i),title:"Click for details",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 w-[180px] shrink-0",children:[e.jsx("div",{className:"w-2 h-2 rounded-full shrink-0",style:{backgroundColor:ae(l.model)}}),e.jsx("span",{className:"font-medium truncate group-hover:underline underline-offset-2",children:l.model})]}),e.jsx(ps,{model:l}),e.jsx("span",{className:c("text-[10px] text-muted-foreground w-14 text-right shrink-0",n&&N),children:hs(l.tokens)}),e.jsxs("span",{className:c("font-mono font-medium w-16 text-right shrink-0",n&&N),children:["$",l.cost.toFixed(2)]}),e.jsx(Re,{className:"w-3 h-3 opacity-0 group-hover:opacity-50 transition-opacity shrink-0"})]},l.model)),e.jsx(gs,{})]})})]})}function ps({model:s}){const t={input:"#335c67",output:"#fff3b0",cacheWrite:"#e09f3e",cacheRead:"#9e2a2b"},r=n=>s.cost>0?n/s.cost*100:0;return e.jsx("div",{className:"flex-1 flex items-center gap-1 min-w-0",children:e.jsxs("div",{className:"flex-1 h-2 bg-muted rounded-full overflow-hidden flex",children:[e.jsx("div",{className:"h-full",style:{backgroundColor:t.input,width:`${r(s.costBreakdown.input.cost)}%`},title:`Input: $${s.costBreakdown.input.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.output,width:`${r(s.costBreakdown.output.cost)}%`},title:`Output: $${s.costBreakdown.output.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheWrite,width:`${r(s.costBreakdown.cacheCreation.cost)}%`},title:`Cache Write: $${s.costBreakdown.cacheCreation.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheRead,width:`${r(s.costBreakdown.cacheRead.cost)}%`},title:`Cache Read: $${s.costBreakdown.cacheRead.cost.toFixed(2)}`})]})})}function gs(){const s=[{color:"#335c67",label:"Input"},{color:"#fff3b0",label:"Output",hasBorder:!0},{color:"#e09f3e",label:"Cache Write"},{color:"#9e2a2b",label:"Cache Read"}];return e.jsx("div",{className:"flex items-center gap-3 pt-2 px-2 text-[10px] text-muted-foreground border-t mt-2",children:s.map(({color:t,label:r,hasBorder:n})=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:c("w-2 h-2 rounded-full",n&&"border border-muted-foreground/30"),style:{backgroundColor:t}}),r]},r))})}function js({viewMode:s,trends:t,hourlyData:r,models:n,sessions:l,isTrendsLoading:i,isHourlyLoading:x,isModelsLoading:a,isSessionsLoading:o,isSummaryLoading:d,onModelClick:u}){const{privacyMode:m}=M();return e.jsxs("div",{className:"min-h-0 grid gap-4 lg:grid-rows-[minmax(260px,1.2fr)_minmax(220px,0.9fr)]",children:[e.jsxs(p,{className:"flex flex-col h-full min-h-[220px] lg:min-h-[240px] overflow-hidden gap-0 py-0 shadow-sm",children:[e.jsx(y,{className:"px-3 py-2 shrink-0",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Me,{className:"w-4 h-4"}),s==="hourly"?"Last 24 Hours":"Usage Trends"]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1 min-h-0",children:e.jsx(ns,{data:s==="hourly"?r||[]:t||[],isLoading:s==="hourly"?x:i,granularity:s==="hourly"?"hourly":"daily"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-10 gap-4 h-auto min-h-[220px] lg:h-full lg:min-h-[220px] lg:grid-rows-[minmax(0,1fr)] lg:[&>*]:min-h-0",children:[e.jsx(fs,{models:n,isLoading:a,onModelClick:u,privacyMode:m}),e.jsxs(p,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-2",children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Pe,{className:"w-4 h-4"}),"Model Usage"]})}),e.jsx(g,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 flex items-center justify-center",children:e.jsx(is,{data:n||[],isLoading:a,className:"h-full w-full"})})]}),e.jsx(ds,{data:l,isLoading:o,className:"lg:col-span-2"}),e.jsx(us,{isLoading:d,className:"lg:col-span-2"})]})]})}function $s(){return e.jsxs("div",{className:"space-y-4 h-full overflow-hidden",children:[e.jsxs(p,{className:"flex flex-col min-h-[300px]",children:[e.jsx(y,{className:"p-4 pb-2",children:e.jsx(h,{className:"h-4 w-32"})}),e.jsx(g,{className:"p-4 pt-0 flex-1",children:e.jsx(h,{className:"h-full w-full"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs(p,{className:"flex flex-col min-h-[250px]",children:[e.jsx(y,{className:"p-4 pb-2",children:e.jsx(h,{className:"h-4 w-28"})}),e.jsx(g,{className:"p-4 pt-2",children:e.jsx("div",{className:"space-y-3",children:[1,2,3,4,5].map(s=>e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{className:"w-2.5 h-2.5 rounded-full"}),e.jsx(h,{className:"h-3 w-24"})]}),e.jsx(h,{className:"h-3 w-16"})]},s))})})]}),e.jsxs(p,{className:"flex flex-col min-h-[250px]",children:[e.jsx(y,{className:"p-4 pb-2",children:e.jsx(h,{className:"h-4 w-28"})}),e.jsx(g,{className:"p-4 pt-0 flex-1",children:e.jsxs("div",{className:"flex w-full h-full items-center",children:[e.jsx("div",{className:"flex-1 flex justify-center",children:e.jsx(h,{className:"h-[180px] w-[180px] rounded-full"})}),e.jsx("div",{className:"w-[140px] shrink-0 pl-2 space-y-2",children:[1,2,3,4].map(s=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{className:"w-2 h-2 rounded-full"}),e.jsx(h,{className:"h-3 w-20"})]},s))})]})})]})]})]})}function Ts(){const s=f.useRef(null),{dateRange:t,handleDateRangeChange:r,handleTodayClick:n,handleRefresh:l,isRefreshing:i,lastUpdatedText:x,viewMode:a,summary:o,isSummaryLoading:d,trends:u,hourlyData:m,models:j,sessions:w,isTrendsLoading:v,isHourlyLoading:C,isModelsLoading:S,isSessionsLoading:B,handleModelClick:A,selectedModel:U,popoverPosition:q,handlePopoverClose:_}=ts();return e.jsxs("div",{className:"grid h-full min-h-0 grid-rows-[auto_auto_minmax(0,1fr)] gap-4 overflow-y-auto px-4 py-4",children:[e.jsx(rs,{dateRange:t,onDateRangeChange:r,onTodayClick:n,onRefresh:l,isRefreshing:i,lastUpdatedText:x,viewMode:a}),e.jsx(Ge,{data:o,isLoading:d}),e.jsx(js,{viewMode:a,trends:u,hourlyData:m,models:j,sessions:w,isTrendsLoading:v,isHourlyLoading:C,isModelsLoading:S,isSessionsLoading:B,isSummaryLoading:d,onModelClick:A}),e.jsxs(se,{open:!!U,onOpenChange:O=>!O&&_(),children:[e.jsx(be,{asChild:!0,children:e.jsx("div",{ref:s,className:"fixed pointer-events-none",style:{left:q?.x??0,top:q?.y??0,width:1,height:1}})}),e.jsx(te,{className:"w-80 p-3",side:"top",align:"center",children:U&&e.jsx(We,{model:U})})]})]})}export{Ts as AnalyticsPage,$s as AnalyticsSkeleton};
|
|
1
|
+
import{j as e}from"./radix-ui-Dt3edmE5.js";import{r as f,c as pe}from"./react-vendor-CNOkPC89.js";import{u as M,a as ee,C as p,b as g,S as h,c,P as N,B as I,d as H,e as se,f as ge,g as te,h as je,i as ae,j as y,k as D,l as ye,m as Ne,n as we,o as be}from"./index-Dz76Rk36.js";import{$ as ve,ab as re,ac as z,ad as ne,Y as le,a4 as ke,G as Ce,ae as Se,R as De,Q,U as Le,Z as ie,u as $e,a6 as G,af as Te,N as Fe,C as Re,ag as Me,ah as Pe}from"./icons-DtwH984l.js";import{a as Be,u as P}from"./tanstack-B8i0evp-.js";import{K as $,L as Y,f as k,H as Ae}from"./utils-CzKF5WmX.js";import{R as oe,A as Ue,C as qe,X as Ie,Y as V,T as ce,a as Z,P as Oe,b as Ke,c as Ee}from"./charts-BBPXh0Ar.js";import"./notifications-B2HqRBj7.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function Ge({data:s,isLoading:t}){const{privacyMode:r}=M(),{t:n}=ee();if(t)return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4",children:[1,2,3,4,5].map(a=>e.jsx(p,{children:e.jsx(g,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-4 w-[100px]"}),e.jsx(h,{className:"h-8 w-[80px]"})]}),e.jsx(h,{className:"h-8 w-8 rounded-lg"})]})})},a))});const l=(s?.tokenBreakdown?.cacheCreation?.cost??0)+(s?.tokenBreakdown?.cacheRead?.cost??0),i=s?.totalCost?Math.round(l/s.totalCost*100):0,x=[{title:n("analyticsSummary.totalTokens"),value:s?.totalTokens??0,icon:ve,format:a=>R(a),color:"text-blue-600",bgColor:"bg-blue-100 dark:bg-blue-900/20",subtitle:n("analyticsSummary.totalTokensSubtitle",{input:R(s?.totalInputTokens??0),output:R(s?.totalOutputTokens??0)})},{title:n("analyticsSummary.totalCost"),value:s?.totalCost??0,icon:re,format:a=>`$${a.toFixed(2)}`,color:"text-green-600",bgColor:"bg-green-100 dark:bg-green-900/20",subtitle:n("analyticsSummary.totalCostSubtitle",{value:s?.averageCostPerDay?.toFixed(2)??"0.00"})},{title:n("analyticsSummary.cacheTokens"),value:s?.totalCacheTokens??0,icon:z,format:a=>R(a),color:"text-cyan-600",bgColor:"bg-cyan-100 dark:bg-cyan-900/20",subtitle:n("analyticsSummary.cacheTokensSubtitle",{cost:l.toFixed(2),percent:i})},{title:n("analyticsSummary.inputCost"),value:s?.tokenBreakdown?.input?.cost??0,icon:ne,format:a=>`$${a.toFixed(2)}`,color:"text-purple-600",bgColor:"bg-purple-100 dark:bg-purple-900/20",subtitle:n("analyticsSummary.tokensSubtitle",{value:R(s?.tokenBreakdown?.input?.tokens??0)})},{title:n("analyticsSummary.outputCost"),value:s?.tokenBreakdown?.output?.cost??0,icon:le,format:a=>`$${a.toFixed(2)}`,color:"text-orange-600",bgColor:"bg-orange-100 dark:bg-orange-900/20",subtitle:n("analyticsSummary.tokensSubtitle",{value:R(s?.tokenBreakdown?.output?.tokens??0)})}];return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4",children:x.map((a,o)=>{const d=a.icon;return e.jsx(p,{className:"hover:shadow-md transition-shadow",children:e.jsx(g,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between space-x-2",children:[e.jsxs("div",{className:"space-y-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground truncate",children:a.title}),e.jsx("p",{className:c("text-xl font-bold truncate",r&&N),children:a.format(a.value)}),a.subtitle&&e.jsx("p",{className:c("text-[10px] text-muted-foreground truncate",r&&N),children:a.subtitle})]}),e.jsx("div",{className:c("p-2 rounded-lg shrink-0",a.bgColor),children:e.jsx(d,{className:c("h-4 w-4",a.color)})})]})})},o)})})}function R(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function We({model:s}){const{privacyMode:t}=M(),r=He(s.ioRatio);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ke,{className:"h-4 w-4 text-primary shrink-0"}),e.jsx("h4",{className:"font-semibold leading-none truncate",title:s.model,children:s.model})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(I,{variant:"secondary",className:"text-[10px] h-5 px-1.5",children:[s.percentage.toFixed(1),"% usage"]}),e.jsxs(I,{variant:r.variant,className:"text-[10px] h-5 px-1.5",children:[s.ioRatio.toFixed(0),":1 I/O"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("p",{className:c("text-lg font-bold",t&&N),children:["$",s.cost.toFixed(2)]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:"Total Cost"})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsx("p",{className:c("text-lg font-bold",t&&N),children:ze(s.tokens)}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:"Total Tokens"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:"Token Breakdown"}),e.jsxs("div",{className:c("space-y-1",t&&N),children:[e.jsx(W,{label:"Input",tokens:s.inputTokens,cost:s.costBreakdown.input.cost,color:"#335c67",icon:ne}),e.jsx(W,{label:"Output",tokens:s.outputTokens,cost:s.costBreakdown.output.cost,color:"#fff3b0",icon:le}),e.jsx(W,{label:"Cache Write",tokens:s.cacheCreationTokens,cost:s.costBreakdown.cacheCreation.cost,color:"#e09f3e",icon:z}),e.jsx(W,{label:"Cache Read",tokens:s.cacheReadTokens,cost:s.costBreakdown.cacheRead.cost,color:"#9e2a2b",icon:z})]})]}),e.jsxs("div",{className:"p-2.5 rounded-md border bg-muted/20 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ce,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs font-medium",children:"Input/Output Ratio"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-snug",children:r.description})]})]})}function W({label:s,tokens:t,cost:r,color:n,icon:l}){return t===0?null:e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:"w-1 h-6 rounded-full shrink-0",style:{backgroundColor:n}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium truncate",children:s}),e.jsxs("span",{className:"font-mono text-muted-foreground",children:["$",r.toFixed(3)]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx(l,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:_e(t)})]})]})]})}function He(s){return s>=200?{variant:"destructive",description:"Extended thinking or large context loading. Expected for reasoning models."}:s>=50?{variant:"secondary",description:"More input than output. Typical for analysis tasks."}:s>=5?{variant:"outline",description:"Balanced input/output ratio for typical coding tasks."}:{variant:"default",description:"More output than input. Generation-heavy workload."}}function _e(s){return s.toLocaleString()}function ze(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}const Ye="/api";function b(s){const t=s.getFullYear(),r=String(s.getMonth()+1).padStart(2,"0"),n=String(s.getDate()).padStart(2,"0");return`${t}${r}${n}`}const T={summary:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),L(`/usage/summary?${t}`)},trends:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),L(`/usage/daily?${t}`)},hourly:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),L(`/usage/hourly?${t}`)},models:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),L(`/usage/models?${t}`)},sessions:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),s?.limit&&t.append("limit",s.limit.toString()),s?.offset&&t.append("offset",s.offset.toString()),L(`/usage/sessions?${t}`)},monthly:(s,t)=>{const r=new URLSearchParams;return s&&r.append("months",s.toString()),t&&r.append("profile",t),L(`/usage/monthly?${r}`)},refresh:async()=>{if(!(await fetch(`${Ye}/usage/refresh`,{method:"POST",headers:{"Content-Type":"application/json"}})).ok)throw new Error("Failed to refresh usage cache")},status:()=>L("/usage/status"),insights:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),L(`/usage/insights?${t}`)}};async function L(s){const r=await fetch(`/api${s}`,{headers:{"Content-Type":"application/json"}});if(!r.ok){const l=await r.json().catch(()=>({error:"Unknown error"}));throw new Error(l.error||r.statusText)}const n=await r.json();return n.data||n}function Qe(s){return P({queryKey:["usage","summary",s],queryFn:()=>T.summary(s),staleTime:60*1e3})}function Ve(s){return P({queryKey:["usage","trends",s],queryFn:()=>T.trends(s),staleTime:60*1e3})}function Ze(s){return P({queryKey:["usage","hourly",s],queryFn:()=>T.hourly(s),staleTime:60*1e3})}function Xe(s){return P({queryKey:["usage","models",s],queryFn:()=>T.models(s),staleTime:60*1e3})}function Je(){const s=Be();return f.useCallback(async()=>{await T.refresh(),await s.invalidateQueries({queryKey:["usage"]})},[s])}function es(){return P({queryKey:["usage","status"],queryFn:()=>T.status(),staleTime:10*1e3,refetchInterval:30*1e3})}function ss(s){return P({queryKey:["usage","sessions",s],queryFn:()=>T.sessions(s),staleTime:60*1e3})}function ts(){const[s,t]=f.useState({from:$(new Date,30),to:new Date}),[r,n]=f.useState(!1),[l,i]=f.useState(null),[x,a]=f.useState(null),[o,d]=f.useState("daily"),u=Je(),m=f.useCallback(async()=>{n(!0);try{await u()}finally{n(!1)}},[u]),j=f.useMemo(()=>({startDate:s?.from,endDate:s?.to}),[s?.from,s?.to]),{data:w,isLoading:v}=Qe(j),{data:C,isLoading:S}=Ve(j),{data:B,isLoading:A}=Ze(j),{data:U,isLoading:q}=Xe(j),{data:_,isLoading:O}=ss({...j,limit:3}),{data:K}=es(),de=f.useCallback(()=>{const F=new Date;t({from:$(F,1),to:F}),d("hourly")},[]),xe=f.useCallback(F=>{t(F),d("daily")},[]),ue=f.useMemo(()=>K?.lastFetch?Y(new Date(K.lastFetch),{addSuffix:!0}):null,[K?.lastFetch]),me=f.useCallback((F,fe)=>{const E=fe.currentTarget.getBoundingClientRect();a({x:E.left+E.width/2,y:E.top+E.height/2}),i(F)},[]),he=f.useCallback(()=>{i(null),a(null)},[]);return{dateRange:s,isRefreshing:r,viewMode:o,selectedModel:l,popoverPosition:x,summary:w,trends:C,hourlyData:B,models:U,sessions:_,status:K,isSummaryLoading:v,isTrendsLoading:S,isHourlyLoading:A,isModelsLoading:q,isSessionsLoading:O,isLoading:v||S||q||O,handleRefresh:m,handleTodayClick:de,handleDateRangeChange:xe,handleModelClick:me,handlePopoverClose:he,lastUpdatedText:ue}}function as({value:s,onChange:t,presets:r=[{label:"Last 7 days",range:{from:$(new Date,7),to:new Date}},{label:"Last 30 days",range:{from:$(new Date,30),to:new Date}},{label:"Last 90 days",range:{from:$(new Date,90),to:new Date}}],className:n}){const[l,i]=pe.useState(!1),x=a=>!s||!s.from||!s.to||!a.from||!a.to?!1:k(s.from,"yyyy-MM-dd")===k(a.from,"yyyy-MM-dd")&&k(s.to,"yyyy-MM-dd")===k(a.to,"yyyy-MM-dd");return e.jsxs("div",{className:c("flex flex-wrap items-center gap-2",n),children:[r.map(a=>e.jsx(H,{variant:x(a.range)?"default":"outline",size:"sm",onClick:()=>t(a.range),children:a.label},a.label)),e.jsxs(se,{open:l,onOpenChange:i,children:[e.jsx(ge,{asChild:!0,children:e.jsxs(H,{id:"date",variant:"outline",className:c("w-auto min-w-[200px] sm:min-w-[240px] justify-start text-left font-normal",!s&&"text-muted-foreground"),children:[e.jsx(Se,{className:"mr-2 h-4 w-4"}),s?.from?s.to?e.jsxs(e.Fragment,{children:[k(s.from,"LLL dd, y")," - ",k(s.to,"LLL dd, y")]}):k(s.from,"LLL dd, y"):e.jsx("span",{children:"Pick a date"})]})}),e.jsx(te,{className:"w-auto p-0",align:"end",children:e.jsx(je,{initialFocus:!0,mode:"range",defaultMonth:s?.from,selected:s,onSelect:t,numberOfMonths:2})})]})]})}function rs({dateRange:s,onDateRangeChange:t,onTodayClick:r,onRefresh:n,isRefreshing:l,lastUpdatedText:i,viewMode:x}){const{t:a}=ee();return e.jsxs("div",{className:"flex flex-col gap-3 shrink-0 xl:flex-row xl:items-center xl:justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold",children:a("analytics.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a("analytics.subtitle")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 xl:justify-end",children:[e.jsx(H,{variant:x==="hourly"?"default":"outline",size:"sm",className:"h-8",onClick:r,children:"24H"}),e.jsx(as,{className:"flex-wrap",value:s,onChange:t,presets:[{label:"7D",range:{from:$(new Date,7),to:new Date}},{label:"30D",range:{from:$(new Date,30),to:new Date}},{label:a("analytics.month"),range:{from:Ae(new Date),to:new Date}},{label:a("analytics.allTime"),range:{from:void 0,to:new Date}}]}),i&&e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:a("analytics.updated",{value:i})}),e.jsx(H,{variant:"outline",size:"sm",className:"gap-2 h-8",onClick:n,disabled:l,children:e.jsx(De,{className:`w-3.5 h-3.5 ${l?"animate-spin":""}`})})]})]})}function ns({data:s,isLoading:t,granularity:r="daily",className:n}){const{privacyMode:l}=M(),i=f.useMemo(()=>!s||s.length===0?[]:(r==="hourly"?s:[...s].reverse()).map(o=>{const d="hour"in o?o.hour:o.date;return{...o,dateFormatted:ls(d,r),costRounded:Number(o.cost.toFixed(4))}}),[s,r]);if(t)return e.jsx(h,{className:c("h-full w-full",n)});if(!s||s.length===0)return e.jsx("div",{className:c("h-full flex items-center justify-center",n),children:e.jsx("p",{className:"text-muted-foreground",children:r==="hourly"?"No usage data for today":"No usage data available"})});const x=({x:a,y:o,payload:d,isRight:u})=>{const m=u?`$${d.value}`:X(Number(d.value));return e.jsx("text",{x:a,y:o,dy:4,textAnchor:u?"start":"end",fontSize:12,fill:"currentColor",className:c("fill-muted-foreground",l&&"blur-[4px]"),children:m})};return e.jsx("div",{className:c("w-full h-full",n),children:e.jsx(oe,{width:"100%",height:"100%",children:e.jsxs(Ue,{data:i,margin:{top:5,right:30,left:20,bottom:5},children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"tokenGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#0080FF",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#0080FF",stopOpacity:.1})]}),e.jsxs("linearGradient",{id:"costGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#00C49F",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#00C49F",stopOpacity:.1})]})]}),e.jsx(qe,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Ie,{dataKey:"dateFormatted",tick:{fontSize:12},tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(V,{yAxisId:"left",orientation:"left",tick:a=>e.jsx(x,{...a,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(V,{yAxisId:"right",orientation:"right",tick:a=>e.jsx(x,{...a,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(ce,{content:({active:a,payload:o,label:d})=>{if(!a||!o||!o.length)return null;const u=o[0].payload;return e.jsxs("div",{className:"rounded-lg border bg-background p-3 shadow-lg",children:[e.jsx("p",{className:"font-medium mb-2",children:d}),o.map((m,j)=>e.jsxs("p",{className:c("text-sm",l&&N),style:{color:m.color},children:[m.name,":"," ",m.name==="Tokens"?X(Number(m.value)||0):`$${m.value}`]},j)),"requests"in u&&e.jsxs("p",{className:c("text-sm text-muted-foreground mt-1",l&&N),children:["Requests: ",u.requests]})]})}}),e.jsx(Z,{yAxisId:"left",type:"monotone",dataKey:"tokens",stroke:"#0080FF",strokeWidth:2,fillOpacity:1,fill:"url(#tokenGradient)",name:"Tokens"}),e.jsx(Z,{yAxisId:"right",type:"monotone",dataKey:"costRounded",stroke:"#00C49F",strokeWidth:2,fillOpacity:1,fill:"url(#costGradient)",name:"Cost"})]})})})}function ls(s,t){if(t==="hourly"){const[n,l]=s.split(" ");if(n&&l){const i=new Date(`${n}T${l}:00Z`);return k(i,"HH:mm")}return s}const r=new Date(s);return t==="monthly"?k(r,"MMM yyyy"):k(r,"MMM dd")}function X(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function is({data:s,isLoading:t,className:r}){const{privacyMode:n}=M(),l=f.useMemo(()=>!s||s.length===0?[]:s.map(a=>({name:a.model,value:a.tokens,cost:a.cost,percentage:a.percentage,fill:ae(a.model)})),[s]);if(t)return e.jsx(h,{className:c("h-full min-h-[100px] w-full",r)});if(!s||s.length===0)return e.jsx("div",{className:c("h-full min-h-[100px] flex items-center justify-center",r),children:e.jsx("p",{className:"text-muted-foreground",children:"No model data available"})});const i=({active:a,payload:o})=>{if(!a||!o)return null;const d=o;if(!d.length)return null;const u=d[0].payload;return e.jsxs("div",{className:"rounded-lg border bg-background p-2 shadow-lg text-xs",children:[e.jsx("p",{className:"font-medium mb-1",children:u.name}),e.jsxs("p",{className:c("text-muted-foreground",n&&N),children:[os(u.value)," (",u.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:c("text-muted-foreground",n&&N),children:["$",u.cost.toFixed(4)]})]})},x=a=>a.percentage>5?`${a.percentage.toFixed(1)}%`:"";return e.jsx("div",{className:c("w-full h-full min-h-[100px]",r),children:e.jsx(oe,{width:"100%",height:"100%",children:e.jsxs(Oe,{children:[e.jsx(Ke,{data:l,cx:"50%",cy:"50%",labelLine:!1,label:x,innerRadius:50,outerRadius:70,paddingAngle:2,dataKey:"value",children:l.map((a,o)=>e.jsx(Ee,{fill:a.fill,strokeWidth:1},`cell-${o}`))}),e.jsx(ce,{content:i})]})})})}function os(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function cs(s){if(!s)return"";const r=s.replace(/^\/|\/$/g,"").split("/").filter(n=>n.length>0);return r[r.length-1]||""}function ds({data:s,isLoading:t,className:r}){const{privacyMode:n}=M(),l=f.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const i=s.sessions,x=s.total,a=i.reduce((w,v)=>w+(v.inputTokens+v.outputTokens),0),o=Math.round(a/i.length),u=i.reduce((w,v)=>w+v.cost,0)/i.length,m=i[0],j=m?Y(new Date(m.lastActivity),{addSuffix:!0}):"N/A";return{totalSessions:x,avgTokens:o,avgCost:u,lastActive:j,recentSessions:i.slice(0,3)}},[s]);return t?e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",r),children:[e.jsx(y,{className:"px-3 py-2",children:e.jsx(h,{className:"h-5 w-32"})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(h,{className:"h-full w-full"})})]}):l?e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm",r),children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Q,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsxs(g,{className:"px-3 pb-3 pt-0 flex-1 min-h-0 flex flex-col gap-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-blue-600 dark:text-blue-400",children:[e.jsx(Le,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xl font-bold",children:l.totalSessions})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:"Total Sessions"})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-green-600 dark:text-green-400",children:[e.jsx(ie,{className:"w-4 h-4"}),e.jsxs("span",{className:c("text-xl font-bold",n&&N),children:["$",l.avgCost.toFixed(2)]})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:"Avg Cost/Session"})]})]}),e.jsxs("div",{className:"flex-1 min-h-0 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground font-medium mb-1",children:[e.jsx($e,{className:"w-3 h-3"}),"Recent Activity"]}),e.jsx("div",{className:"space-y-1.5 max-h-full overflow-y-auto pr-1",children:l.recentSessions.map(i=>e.jsxs("div",{className:"flex items-center justify-between text-xs p-1.5 rounded bg-muted/30 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex flex-col min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium truncate",title:i.projectPath,children:cs(i.projectPath)}),(i.target??"claude")!=="claude"&&e.jsx("span",{className:"shrink-0 px-1 py-0 text-[9px] font-medium rounded bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-300 uppercase",children:i.target})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:Y(new Date(i.lastActivity),{addSuffix:!0})})]}),e.jsxs("div",{className:c("text-right shrink-0 ml-2",n&&N),children:[e.jsxs("div",{className:"font-mono",children:["$",i.cost.toFixed(2)]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[xs(i.inputTokens+i.outputTokens)," toks"]})]})]},i.sessionId))})]})]})]}):e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",r),children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Q,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-sm text-muted-foreground text-center",children:"No session data available"})})]})}function xs(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}function us({className:s,isLoading:t}){const{data:r,isLoading:n}=ye(),{data:l,isLoading:i,error:x}=Ne(r?.running);if(t||n||r?.running&&i)return e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",s),children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"CLIProxy Stats"]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(h,{className:"h-4 w-[100px]"}),e.jsx(h,{className:"h-16 w-full"})]})})]});if(!r?.running)return e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 border-dashed",s),children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4 text-muted-foreground"}),"CLIProxy Stats"]}),e.jsx(I,{variant:"secondary",className:"text-[10px] h-5",children:"Offline"})]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"Start a CLIProxy session (gemini, codex, agy) to collect stats."})})]});if(x)return e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 border-destructive/50",s),children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsx(I,{variant:"destructive",className:"text-[10px] h-5",children:"Error"})]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx("p",{className:"text-xs text-destructive",children:x.message})})]});const o=l?.totalRequests??0,d=l?.quotaExceededCount??0,u=o-d,m=o>0?Math.round(u/o*100):100,j=l?.tokens?.total??0,w=Object.entries(l?.requestsByModel??{}).sort((C,S)=>S[1]-C[1]).slice(0,4),v=w.length>0?w[0][1]:1;return e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",s),children:[e.jsx(y,{className:"px-3 py-2 border-b bg-muted/5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsxs(I,{variant:"outline",className:"text-[10px] h-5 text-green-600 border-green-200 bg-green-50 dark:bg-green-900/10 dark:border-green-800",children:[e.jsx(ie,{className:"h-3 w-3 mr-0.5"}),"Running"]})]})}),e.jsx(g,{className:"p-0 flex-1 min-h-0",children:e.jsx(we,{className:"h-full",children:e.jsxs("div",{className:"p-3 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsxs("div",{className:"relative",children:[e.jsxs("svg",{className:"w-10 h-10 -rotate-90",viewBox:"0 0 36 36",children:[e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",className:"text-muted/30"}),e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeDasharray:`${m*.88} 88`,strokeLinecap:"round",className:m>=90?"text-green-500":"text-amber-500"})]}),e.jsxs("span",{className:"absolute inset-0 flex items-center justify-center text-[8px] font-bold",children:[m,"%"]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:J(o)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:d>0?`${d} failed`:"All success"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsx("div",{className:"p-1.5 rounded-md bg-purple-100 dark:bg-purple-900/20",children:e.jsx(Te,{className:"h-4 w-4 text-purple-600"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:J(j)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:"Total tokens"})]})]})]}),w.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-medium text-muted-foreground",children:[e.jsx(Fe,{className:"h-3 w-3"}),"Models Used"]}),e.jsx("div",{className:"space-y-1",children:w.map(([C,S])=>{const B=Math.round(S/v*100),A=ms(C);return e.jsxs("div",{className:"group",children:[e.jsxs("div",{className:"flex items-center justify-between text-[10px] mb-0.5",children:[e.jsx("span",{className:"truncate font-medium",title:C,children:A}),e.jsx("span",{className:"text-muted-foreground shrink-0 ml-2",children:S})]}),e.jsx("div",{className:"h-1 bg-muted/50 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-accent/70 rounded-full transition-all",style:{width:`${B}%`}})})]},C)})})]})]})})})]})}function J(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function ms(s){let t=s.replace(/^gemini-claude-/,"").replace(/^gemini-/,"").replace(/^claude-/,"").replace(/^anthropic\./,"").replace(/-thinking$/," Thinking");return t=t.split(/[-_]/).map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" "),t.length>20&&(t=t.slice(0,18)+"..."),t}function hs(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(0)}K`:s.toString()}function fs({models:s,isLoading:t,onModelClick:r,privacyMode:n}){return e.jsxs(p,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-4",children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(re,{className:"w-4 h-4"}),"Cost by Model"]})}),e.jsx(g,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 overflow-y-auto",children:t?e.jsx(h,{className:"h-full w-full"}):e.jsxs("div",{className:"space-y-0.5",children:[[...s||[]].sort((l,i)=>i.cost-l.cost).map(l=>e.jsxs("button",{className:"group flex items-center text-xs w-full hover:bg-muted/50 rounded px-2 py-1.5 transition-colors cursor-pointer gap-3",onClick:i=>r(l,i),title:"Click for details",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 w-[180px] shrink-0",children:[e.jsx("div",{className:"w-2 h-2 rounded-full shrink-0",style:{backgroundColor:ae(l.model)}}),e.jsx("span",{className:"font-medium truncate group-hover:underline underline-offset-2",children:l.model})]}),e.jsx(ps,{model:l}),e.jsx("span",{className:c("text-[10px] text-muted-foreground w-14 text-right shrink-0",n&&N),children:hs(l.tokens)}),e.jsxs("span",{className:c("font-mono font-medium w-16 text-right shrink-0",n&&N),children:["$",l.cost.toFixed(2)]}),e.jsx(Re,{className:"w-3 h-3 opacity-0 group-hover:opacity-50 transition-opacity shrink-0"})]},l.model)),e.jsx(gs,{})]})})]})}function ps({model:s}){const t={input:"#335c67",output:"#fff3b0",cacheWrite:"#e09f3e",cacheRead:"#9e2a2b"},r=n=>s.cost>0?n/s.cost*100:0;return e.jsx("div",{className:"flex-1 flex items-center gap-1 min-w-0",children:e.jsxs("div",{className:"flex-1 h-2 bg-muted rounded-full overflow-hidden flex",children:[e.jsx("div",{className:"h-full",style:{backgroundColor:t.input,width:`${r(s.costBreakdown.input.cost)}%`},title:`Input: $${s.costBreakdown.input.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.output,width:`${r(s.costBreakdown.output.cost)}%`},title:`Output: $${s.costBreakdown.output.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheWrite,width:`${r(s.costBreakdown.cacheCreation.cost)}%`},title:`Cache Write: $${s.costBreakdown.cacheCreation.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheRead,width:`${r(s.costBreakdown.cacheRead.cost)}%`},title:`Cache Read: $${s.costBreakdown.cacheRead.cost.toFixed(2)}`})]})})}function gs(){const s=[{color:"#335c67",label:"Input"},{color:"#fff3b0",label:"Output",hasBorder:!0},{color:"#e09f3e",label:"Cache Write"},{color:"#9e2a2b",label:"Cache Read"}];return e.jsx("div",{className:"flex items-center gap-3 pt-2 px-2 text-[10px] text-muted-foreground border-t mt-2",children:s.map(({color:t,label:r,hasBorder:n})=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:c("w-2 h-2 rounded-full",n&&"border border-muted-foreground/30"),style:{backgroundColor:t}}),r]},r))})}function js({viewMode:s,trends:t,hourlyData:r,models:n,sessions:l,isTrendsLoading:i,isHourlyLoading:x,isModelsLoading:a,isSessionsLoading:o,isSummaryLoading:d,onModelClick:u}){const{privacyMode:m}=M();return e.jsxs("div",{className:"min-h-0 grid gap-4 lg:grid-rows-[minmax(260px,1.2fr)_minmax(220px,0.9fr)]",children:[e.jsxs(p,{className:"flex flex-col h-full min-h-[220px] lg:min-h-[240px] overflow-hidden gap-0 py-0 shadow-sm",children:[e.jsx(y,{className:"px-3 py-2 shrink-0",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Me,{className:"w-4 h-4"}),s==="hourly"?"Last 24 Hours":"Usage Trends"]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1 min-h-0",children:e.jsx(ns,{data:s==="hourly"?r||[]:t||[],isLoading:s==="hourly"?x:i,granularity:s==="hourly"?"hourly":"daily"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-10 gap-4 h-auto min-h-[220px] lg:h-full lg:min-h-[220px] lg:grid-rows-[minmax(0,1fr)] lg:[&>*]:min-h-0",children:[e.jsx(fs,{models:n,isLoading:a,onModelClick:u,privacyMode:m}),e.jsxs(p,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-2",children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Pe,{className:"w-4 h-4"}),"Model Usage"]})}),e.jsx(g,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 flex items-center justify-center",children:e.jsx(is,{data:n||[],isLoading:a,className:"h-full w-full"})})]}),e.jsx(ds,{data:l,isLoading:o,className:"lg:col-span-2"}),e.jsx(us,{isLoading:d,className:"lg:col-span-2"})]})]})}function $s(){return e.jsxs("div",{className:"space-y-4 h-full overflow-hidden",children:[e.jsxs(p,{className:"flex flex-col min-h-[300px]",children:[e.jsx(y,{className:"p-4 pb-2",children:e.jsx(h,{className:"h-4 w-32"})}),e.jsx(g,{className:"p-4 pt-0 flex-1",children:e.jsx(h,{className:"h-full w-full"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs(p,{className:"flex flex-col min-h-[250px]",children:[e.jsx(y,{className:"p-4 pb-2",children:e.jsx(h,{className:"h-4 w-28"})}),e.jsx(g,{className:"p-4 pt-2",children:e.jsx("div",{className:"space-y-3",children:[1,2,3,4,5].map(s=>e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{className:"w-2.5 h-2.5 rounded-full"}),e.jsx(h,{className:"h-3 w-24"})]}),e.jsx(h,{className:"h-3 w-16"})]},s))})})]}),e.jsxs(p,{className:"flex flex-col min-h-[250px]",children:[e.jsx(y,{className:"p-4 pb-2",children:e.jsx(h,{className:"h-4 w-28"})}),e.jsx(g,{className:"p-4 pt-0 flex-1",children:e.jsxs("div",{className:"flex w-full h-full items-center",children:[e.jsx("div",{className:"flex-1 flex justify-center",children:e.jsx(h,{className:"h-[180px] w-[180px] rounded-full"})}),e.jsx("div",{className:"w-[140px] shrink-0 pl-2 space-y-2",children:[1,2,3,4].map(s=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{className:"w-2 h-2 rounded-full"}),e.jsx(h,{className:"h-3 w-20"})]},s))})]})})]})]})]})}function Ts(){const s=f.useRef(null),{dateRange:t,handleDateRangeChange:r,handleTodayClick:n,handleRefresh:l,isRefreshing:i,lastUpdatedText:x,viewMode:a,summary:o,isSummaryLoading:d,trends:u,hourlyData:m,models:j,sessions:w,isTrendsLoading:v,isHourlyLoading:C,isModelsLoading:S,isSessionsLoading:B,handleModelClick:A,selectedModel:U,popoverPosition:q,handlePopoverClose:_}=ts();return e.jsxs("div",{className:"grid h-full min-h-0 grid-rows-[auto_auto_minmax(0,1fr)] gap-4 overflow-y-auto px-4 py-4",children:[e.jsx(rs,{dateRange:t,onDateRangeChange:r,onTodayClick:n,onRefresh:l,isRefreshing:i,lastUpdatedText:x,viewMode:a}),e.jsx(Ge,{data:o,isLoading:d}),e.jsx(js,{viewMode:a,trends:u,hourlyData:m,models:j,sessions:w,isTrendsLoading:v,isHourlyLoading:C,isModelsLoading:S,isSessionsLoading:B,isSummaryLoading:d,onModelClick:A}),e.jsxs(se,{open:!!U,onOpenChange:O=>!O&&_(),children:[e.jsx(be,{asChild:!0,children:e.jsx("div",{ref:s,className:"fixed pointer-events-none",style:{left:q?.x??0,top:q?.y??0,width:1,height:1}})}),e.jsx(te,{className:"w-80 p-3",side:"top",align:"center",children:U&&e.jsx(We,{model:U})})]})]})}export{Ts as AnalyticsPage,$s as AnalyticsSkeleton};
|