PageSourceSearch

https://procalc.ai/assets/AIModelsPage-Dw9fZZdZ.js

js procalc.ai collected 2026-10-05 14:09:44 UTC 42,232 bytes, 6 lines download raw bytes

1import{j as e}from"./vendor-ui-apakGoHS.js";import{r as T}from"./vendor-react-jvbcysPe.js";import{c as W,u as K,d as Ne}from"./vendor-data-8a2i1Wjw.js";import{s as I,m as C,X as we,n as ne,o as ie,p as oe,q as de,r as z,t as Y,v as U,b as ke,e as Ce}from"./index-C-zKQm9Z.js";import{B as A}from"./button-DFXx_IH3.js";import{I as Q}from"./input-D3dvjsgZ.js";import{D as ce,a as me,b as ue,c as xe,d as he}from"./dialog-DK_MGqOB.js";import{T as H,a as G,b as O,c as M,d as J,e as w}from"./table-C0twgINi.js";import{P as Se}from"./progress-CNbxHZ6d.js";import{C as Te,a as $e,b as Ae}from"./collapsible-COVgOnxX.js";import{S as pe}from"./switch-SRGiSWbx.js";import{B as Me}from"./bot-BilZeKje.js";import{T as ee}from"./test-tube-DjbABL4h.js";import{R as fe}from"./refresh-cw-DHq32wi4.js";import{T as ge}from"./triangle-alert-CUt6p2wz.js";import{S as Ie}from"./save-C6XL0tiZ.js";import{I as je}from"./info-DCujr6bb.js";import{C as be}from"./copy-CFwO1GUF.js";import{F as Oe}from"./file-text-CKB4fzMw.js";import{D as re}from"./download-Frl02w_C.js";import{C as ye}from"./circle-check-C--5T2Sh.js";import{P as ve}from"./plus-CiUoz_-I.js";import{P as De}from"./pencil-KpVDk0GL.js";const ae={"gpt-5":"Powerful all-rounder for complex reasoning","gpt-5.2":"Latest OpenAI with enhanced reasoning","gpt-5-mini":"Strong performance at lower cost","gpt-5-nano":"Cheapest option for high-volume workloads","gpt-4.1":"Reliable workhorse for everyday tasks","gpt-4.1-mini":"Fast and affordable for simple tasks","gpt-4.1-nano":"Cheapest option for high-volume workloads","gemini-2.5-flash":"Fast and affordable multimodal reasoning","gemini-2.5-pro":"Top-tier for complex reasoning and large context","gemini-3-flash-preview":"Next-gen speed for efficient tasks","gemini-3-pro-preview":"Next-gen reasoning and accuracy","gemini-3-pro-image-preview":"Next-gen image generation","claude-sonnet-4-6":"Most efficient for everyday tasks","claude-opus-4-6":"Most capable for ambitious projects","claude-haiku-4-5":"Fastest for quick answers",sonar:"Fast search-grounded answers","sonar-pro":"Multi-step reasoning with 2× citations","sonar-reasoning":"Chain-of-thought with real-time search","sonar-reasoning-pro":"Advanced reasoning with deep search","sonar-deep-research":"Expert multi-query research analysis"},Pe={"gpt-5":"Complex reasoning","gpt-5.2":"Latest reasoning","gpt-5-mini":"Fast, lower cost","gpt-5-nano":"Cheapest, fast","gpt-4.1":"Reliable workhorse","gpt-4.1-mini":"Fast, affordable","gpt-4.1-nano":"High-volume cheap","gemini-2.5-flash":"Fast multimodal","gemini-2.5-flash-lite":"Ultra-cheap fast","gemini-2.5-pro":"Top-tier reasoning","gemini-3-flash-preview":"Next-gen speed","gemini-3-pro-preview":"Next-gen reasoning","gemini-3-pro-image-preview":"Image generation","claude-sonnet-4-6":"Everyday tasks","claude-opus-4-6":"Most capable","claude-haiku-4-5":"Fastest, cheapest",sonar:"Search answers","sonar-pro":"Deep search","sonar-reasoning":"Search + reasoning","sonar-reasoning-pro":"Advanced search","sonar-deep-research":"Research analysis"},R={anthropic:{icon:"🔮",label:"Anthropic (Claude)",secretName:"ANTHROPIC_API_KEY"},google:{icon:"☁️",label:"Google (Direct)",secretName:"GEMINI_API_KEY"},openai:{icon:"⚡",label:"OpenAI (Direct)",secretName:"OPENAI_API_KEY"},perplexity:{icon:"🔍",label:"Perplexity",secretName:"PERPLEXITY_API_KEY"}},_e={user_chat:"💬",content_generation:"📝",build_intelligence:"🔍",validation:"✅"};function V(n){return n>=1e6?`${(n/1e6).toFixed(1)}M`:n>=1e3?`${Math.round(n/1e3)}K`:String(n)}function L(n){return`$${Number(n).toFixed(n<.01?6:2)}`}function qe(n){return n==="fastest"?"⚡⚡":n==="fast"?"⚡":"🐢"}function Fe(n){return n==="fastest"?"text-green-600 dark:text-green-400":n==="fast"?"text-blue-500":"text-muted-foreground"}function Ke({models:n,jobs:p,costData:_,onRefresh:m,refreshing:o}){const g=n.filter(t=>!t.deprecated),N=p.find(t=>t.job_type==="content_generation"),S=n.find(t=>t.model_id===(N==null?void 0:N.primary_model_id)),j=p.find(t=>t.job_type==="user_chat"),a=n.find(t=>t.model_id===(j==null?void 0:j.primary_model_id)),[c,y]=T.useState(null),[v,$]=T.useState(!1),d=async()=>{$(!0);try{const{data:t,error:u}=await I.functions.invoke("manage-api-key",{body:{action:"test_all"}});if(u)C.error(`Health check failed: ${u.message}`);else if(t!=null&&t.results){y(t.results);const x=Object.values(t.results).filter(l=>l.valid).length;C.success(`Health check complete: ${x}/${Object.keys(t.results).length} integrations healthy`)}}catch(t){C.error(t.message)}$(!1)},f=[];for(const t of p){const u=n.find(x=>x.model_id===t.primary_model_id);if(u!=null&&u.deprecated&&f.push(`${t.display_name} uses ${u.display_name} (deprecated)`),t.fallback_model_id){const x=n.find(l=>l.model_id===t.fallback_model_id);x!=null&&x.deprecated&&f.push(`${t.display_name} fallback uses ${x.display_name} (deprecated)`)}}const s=[{key:"google",label:"Google (Gemini)",icon:"🔵"},{key:"anthropic",label:"Anthropic (Claude)",icon:"🔮"},{key:"openai",label:"OpenAI",icon:"⚡"},{key:"perplexity",label:"Perplexity",icon:"🔍"}];return e.jsxs("section",{className:"rounded-xl border border-border bg-card p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4 flex-wrap gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Overview"}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs(A,{variant:"outline",size:"sm",onClick:d,disabled:v,className:"gap-2",children:[e.jsx(ee,{className:`h-4 w-4 ${v?"animate-pulse":""}`}),v?"Testing…":"Test All Keys"]}),e.jsxs(A,{size:"sm",onClick:m,disabled:o,className:"gap-2",children:[e.jsx(fe,{className:`h-4 w-4 ${o?"animate-spin":""}`}),o?"Refreshing…":"Refresh Models"]})]})]}),f.length>0&&e.jsxs("div",{className:"mb-4 rounded-lg bg-yellow-50 dark:bg-yellow-950/30 border border-yellow-200 dark:border-yellow-800 p-3 text-sm text-yellow-800 dark:text-yellow-200 flex items-start gap-2",children:[e.jsx(ge,{className:"h-4 w-4 shrink-0 mt-0.5"}),e.jsx("div",{children:f.map((t,u)=>e.jsxs("p",{children:["⚠️ ",t,". Update the assignment."]},u))})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-4 mb-4",children:[{label:"Models",value:g.length},{label:"Jobs",value:p.length},{label:"7d Cost",value:_?L(_.cost):"—"}
1,{label:"7d Calls",value:_?_.calls.toLocaleString():"—"}].map(t=>e.jsxs("div",{className:"text-center p-3 rounded-lg bg-muted/50",children:[e.jsx("div",{className:"text-2xl font-bold font-mono",children:t.value}),e.jsx("div",{className:"text-xs text-muted-foreground",children:t.label})]},t.label))}),c&&e.jsxs("div",{className:"mb-4 rounded-lg border border-border bg-muted/30 p-4",children:[e.jsx("h3",{className:"text-sm font-semibold mb-3",children:"🔌 Integration Status"}),e.jsx("div",{className:"space-y-2",children:s.map(({key:t,label:u,icon:x})=>{const l=c[t];if(!l)return null;const i=l.key_valid??l.valid,k=l.has_credits??l.valid,D=l.configured?i&&k?"🟢":i&&!k?"🟡":"🔴":"⚪",P=l.configured?i&&k?l.detail||"Healthy":i&&!k?"Key valid ✅ but no credits 💳":l.detail||l.error||"Key invalid":"Not configured";return e.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[e.jsx("span",{className:"text-base",children:D}),e.jsxs("span",{className:"w-40 font-medium",children:[x," ",u]}),e.jsx("span",{className:`flex-1 ${i&&k?"text-green-600 dark:text-green-400":i&&!k?"text-yellow-600 dark:text-yellow-400":l.configured?"text-red-600 dark:text-red-400":"text-muted-foreground"}`,children:P}),l.models_found!==void 0&&l.models_found>0&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[l.models_found," models"]})]},t)})})]}),e.jsxs("div",{className:"text-sm text-muted-foreground space-y-0.5",children:[e.jsxs("p",{children:["Active routing: User chat → ",(a==null?void 0:a.display_name)||"Gemini 2.5 Flash"," (Direct)"]}),S&&e.jsxs("p",{children:["Content gen → ",S.display_name," (Direct API)"]})]})]})}function Re({provider:n,secretName:p,onClose:_,onTestAndRefresh:m}){const o=R[n],[g,N]=T.useState(!1),[S,j]=T.useState(!1),a=()=>{navigator.clipboard.writeText(p),N(!0),setTimeout(()=>N(!1),2e3)},c=async()=>{m&&(j(!0),await m(n),j(!1),_())};return e.jsx(ce,{open:!0,onOpenChange:_,children:e.jsxs(me,{className:"max-w-md",children:[e.jsx(ue,{children:e.jsxs(xe,{children:[o==null?void 0:o.icon," ",o==null?void 0:o.label," API Key"]})}),e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsx("p",{className:"text-muted-foreground",children:"API keys are stored securely as backend secrets. To add or update your key:"}),e.jsxs("ol",{className:"list-decimal list-inside space-y-2 text-muted-foreground",children:[e.jsxs("li",{children:["Set in ",e.jsx("strong",{children:"Supabase Dashboard → Edge Functions → Secrets"})]}),e.jsxs("li",{children:["Set: ",e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-xs font-mono",children:p})," = your key"]}),e.jsx("li",{children:"Edge functions will automatically pick it up"}),e.jsxs("li",{children:["Click ",e.jsx("strong",{children:'"Test Key & Discover Models"'})," below"]})]}),e.jsxs("div",{className:"flex items-center gap-2 bg-muted/50 rounded-lg p-3",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Secret name:"}),e.jsx("code",{className:"font-mono text-sm font-medium flex-1",children:p}),e.jsx(A,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:a,children:g?e.jsx(ye,{className:"h-3.5 w-3.5 text-green-500"}):e.jsx(be,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs(he,{className:"flex gap-2",children:[e.jsx(A,{variant:"outline",onClick:_,children:"Close"}),m&&e.jsxs(A,{onClick:c,disabled:S,className:"gap-2",children:[e.jsx(ee,{className:`h-3.5 w-3.5 ${S?"animate-pulse":""}`}),S?"Testing & Discovering…":"Test Key & Discover Models"]})]})]})})}function le({providerId:n,models:p,jobs:_,keyStatus:m,onTestKey:o,testingKey:g,onRefresh:N,showDeprecated:S,onTestAndRefresh:j,onToggleCurated:a}){const c=R[n]||{icon:"🤖",label:n},y=S?p:p.filter(i=>!i.deprecated),v=y.length>0;p.some(i=>!i.deprecated);const[$,d]=T.useState(!1),f=new Set;for(const i of _)f.add(i.primary_model_id),i.fallback_model_id&&f.add(i.fallback_model_id);const[s,t]=T.useState(!1),u=[...y].sort((i,k)=>{if(i.deprecated!==k.deprecated)return i.deprecated?1:-1;const D=f.has(i.model_id),P=f.has(k.model_id);return D!==P?D?-1:1:i.display_name.localeCompare(k.display_name)});function x(){return m==="valid"?e.jsx("span",{className:"text-xs text-green-600 dark:text-green-400 font-medium",children:"✅ Key + Credits OK"}):m==="no_credits"?e.jsx("span",{className:"text-xs text-yellow-600 dark:text-yellow-400 font-medium",children:"✅ Key OK · 💳 No Credits"}):m==="invalid"?e.jsx("span",{className:"text-xs text-yellow-600 dark:text-yellow-400 font-medium",children:"⚠️ Invalid"}):m==="error"?e.jsx("span",{className:"text-xs text-yellow-600 dark:text-yellow-400 font-medium",children:"⚠️ Error"}):e.jsx("span",{className:"text-xs text-destructive font-medium",children:"❌ Not Set"})}function l(i){return i.deprecated?e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-yellow-100 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-300 font-medium",children:"⚠️ Deprecated"}):f.has(i.model_id)?e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300 font-medium",children:"🟢 Active"}):m!=="valid"&&m!=="no_credits"?e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300 font-medium",children:"❌ No Key"}):m==="no_credits"?e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-yellow-100 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-300 font-medium",children:"💳 No Credits"}):e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-muted text-muted-foreground font-medium",children:"⚪ Available"})}return e.jsxs(e.Fragment,{children:[e.jsx(Te,{open:s,onOpenChange:t,children:e.jsxs("div",{className:"rounded-2xl border border-border bg-card overflow-hidden",children:[e.jsx($e,{asChild:!0,children:e.jsxs("button",{className:"w-full flex items-center justify-between p-5 hover:bg-muted/30 transition-colors text-left",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-lg",children:c.icon}),e.jsx("h3",{className:"font-semibold text-base",children:c.label}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",p.filter(i=>!i.deprecated).length," models)"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:m==="valid"?"Your API key — 
1credits available":m==="no_credits"?"Key is valid but account has no credits — add billing credits":m==="invalid"?"Key set but failed validation — check your key":"Add an API key to discover available models"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[x(),e.jsx(ke,{className:`h-4 w-4 text-muted-foreground transition-transform ${s?"rotate-180":""}`})]})]})}),e.jsxs(Ae,{children:[e.jsx("div",{className:"px-5 pb-3 flex items-center gap-2 flex-wrap",children:m==="valid"||m==="no_credits"||m==="invalid"||m==="error"?e.jsxs(e.Fragment,{children:[e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>o(n),disabled:g,children:[e.jsx(ee,{className:"h-3.5 w-3.5 mr-1"})," ",g?"Testing…":"Test Key"]}),e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>d(!0),children:[e.jsx(De,{className:"h-3.5 w-3.5 mr-1"})," Update Key"]})]}):e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>d(!0),children:[e.jsx(ve,{className:"h-3.5 w-3.5 mr-1"})," Add Key"]})}),v?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(H,{children:[e.jsx(G,{children:e.jsxs(O,{children:[e.jsx(M,{className:"min-w-[200px]",children:"Model"}),e.jsx(M,{className:"w-20 text-center",children:"Speed"}),e.jsx(M,{className:"w-40",children:"Cost (In / Out per 1M)"}),e.jsx(M,{className:"w-24 text-center",children:"Curated"}),e.jsx(M,{className:"w-28 text-center",children:"Status"})]})}),e.jsx(J,{children:u.map(i=>e.jsxs(O,{className:i.deprecated?"bg-yellow-50/50 dark:bg-yellow-900/10":i.curated?"":"opacity-60",children:[e.jsxs(w,{children:[e.jsx("span",{className:`font-medium ${i.deprecated?"line-through text-muted-foreground":""}`,children:i.display_name}),e.jsx("span",{className:"block text-xs font-mono text-muted-foreground",children:i.model_id}),ae[i.model_id]&&e.jsx("span",{className:"block text-xs text-muted-foreground italic",children:ae[i.model_id]})]}),e.jsx(w,{className:"text-center",children:e.jsx("span",{className:Fe(i.speed_tier||"fast"),children:qe(i.speed_tier||"fast")})}),e.jsxs(w,{className:"font-mono text-sm",children:["$",Number(i.input_cost_per_1m).toFixed(2)," / $",Number(i.output_cost_per_1m).toFixed(2)]}),e.jsx(w,{className:"text-center",children:e.jsx(pe,{checked:i.curated,onCheckedChange:k=>a==null?void 0:a(i.model_id,k),className:"mx-auto"})}),e.jsx(w,{className:"text-center",children:l(i)})]},i.model_id))})]})}):e.jsx("div",{className:"px-5 pb-5 text-sm text-muted-foreground",children:m==="not_set"?"No models — add an API key to discover available models.":m==="invalid"?"Key validation failed. Check your API key and try again.":"No models discovered. Try refreshing."})]})]})}),$&&c.secretName&&e.jsx(Re,{provider:n,secretName:c.secretName,onClose:()=>d(!1),onTestAndRefresh:j})]})}function Le({models:n,jobs:p,keyStatuses:_,onRefresh:m,refreshing:o,onKeyStatusUpdate:g}){const[N,S]=T.useState(null),[j,a]=T.useState(!1),[c,y]=T.useState("curated"),v=W(),$=async(r,b)=>{const{error:h}=await I.from("ai_models").update({curated:b}).eq("model_id",r);if(h){C.error(`Failed: ${h.message}`);return}C.success(`${r} ${b?"curated ✅":"uncurated"}`),v.invalidateQueries({queryKey:["ai-models"]})},d=n.filter(r=>c==="curated"?r.curated:c==="uncurated"?!r.curated:!0),f=d.filter(r=>r.billing_path==="gateway"),s={};for(const r of d.filter(b=>b.billing_path==="api_key")){const b=r.provider_id||r.provider;s[b]||(s[b]=[]),s[b].push(r)}const t=["anthropic","google","openai","perplexity"];for(const r of t)s[r]||(s[r]=[]);const u=async r=>{var b;S(r);try{const{data:h,error:E}=await I.functions.invoke("manage-api-key",{body:{action:"test",provider:r}});if(E)C.error(`Test failed: ${E.message}`);else{const F=(h==null?void 0:h.key_valid)??(h==null?void 0:h.valid),B=(h==null?void 0:h.has_credits)??(h==null?void 0:h.valid),X=(h==null?void 0:h.detail)||"",Z=((b=R[r])==null?void 0:b.label)||r;F&&B?(C.success(`${Z}: Key valid ✅ Credits OK 💰
2${X}
2`),g==null||g(r,"valid"),v.invalidateQueries({queryKey:["api-key-status"]}),C.info("Discovering models…"),m()):F&&!B?(C.warning(`${Z}: Key valid ✅ but NO credits 💳
3${X}`,{duration:8e3}),g==null||g(r,"no_credits"),C.info("Discovering models…"),m()):(C.error(`${Z}: Key invalid ❌
4${X}`,{duration:6e3}),g==null||g(r,"invalid"))}}catch(h){C.error(h.message)}S(null)},x=async r=>{await u(r)},l=n.filter(r=>r.deprecated).length,i=j?n:n.filter(r=>!r.deprecated),k=new Set;for(const r of p)k.add(r.primary_model_id),r.fallback_model_id&&k.add(r.fallback_model_id);function D(r){return r.deprecated?"Deprecated":k.has(r.model_id)?"Active":"Available"}function P(){const r=i.map(b=>{var h;return`| ${b.display_name} | ${b.model_id} | ${((h=R[b.billing_path==="gateway"?"gateway":b.provider_id||b.provider])==null?void 0:h.label)||b.provider} | ${b.speed_tier||"—"} | $${Number(b.input_cost_per_1m).toFixed(2)} | $${Number(b.output_cost_per_1m).toFixed(2)} | ${D(b)} |`});return[`# AI Model Registry — ${new Date().toISOString().slice(0,10)}`,"","| Model | ID | Provider | Speed | In/1M | Out/1M | Status |","|-------|-----|----------|-------|-------|--------|--------|",...r,"",`_${i.length} models${l>0&&!j?` (${l} deprecated hidden)`:""}_`].join(`
5`)}function q(){const r="Model,ID,Provider,Speed,Input Cost/1M,Output Cost/1M,Status",b=i.map(h=>{var F;const E=((F=R[h.billing_path==="gateway"?"gateway":h.provider_id||h.provider])==null?void 0:F.label)||h.provider;return`"${h.display_name}","${h.model_id}","${E}","${h.speed_tier||""}","$${Number(h.input_cost_per_1m).toFixed(2)}","$${Number(h.output_cost_per_1m).toFixed(2)}","${D(h)}"`});return[r,...b].join(`
6`)}function se(r,b){navigator.clipboard.writeText(r),C.success(`${b} copied to clipboard`)}function te(r,b,h){const E=new Blob([r],{type:h}),F=URL.createObjectURL(E),B=document.createElement("a");B.href=F,B.download=b,B.click(),URL.revokeObjectURL(F),C.success(`Downloaded ${b}`)}return e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4 flex-wrap gap-2",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"AI Model Registry"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"All models available to ProCalc.ai — via direct provider API keys."})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[l>0&&e.jsxs("label",{className:"flex items-center gap-2 text-sm text-muted-foreground cursor-pointer mr-1",children:[e.jsx(pe,{checked:j,onCheckedChange:a}),"Show deprecated (",l,")"]}),e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>se(P(),"Markdown"),className:"gap-1.5",children:[e.jsx(be,{className:"h-3.5 w-3.5"})," Copy MD"]}),e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>se(q(),"CSV"),className:"gap-1.5",children:[e.jsx(Oe,{className:"h-3.5 w-3.5"})," Copy CSV"]}),e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>te(P(),`ai-models-${new Date().toISOString().slice(0,10)}.md`,"text/markdown"),className:"gap-1.5",children:[e.jsx(re,{className:"h-3.5 w-3.5"})," .md"]}),e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>te(q(),`ai-models-${new Date().toISOString().slice(0,10)}.csv`,"text/csv"),className:"gap-1.5",children:[e.jsx(re,{className:"h-3.5 w-3.5"})," .csv"]}),e.jsxs(A,{size:"sm",onClick:m,disabled:o,className:"gap-2",children:[e.jsx(fe,{className:`h-4 w-4 ${o?"animate-spin":""}`}),o?"Refreshing…":"Refresh Models"]})]})]}),n.filter(r=>!r.curated&&!r.deprecated).length>0&&c==="curated"&&e.jsxs("div",{className:"rounded-lg border border-border bg-muted/30 px-4 py-3 flex items-center gap-2 text-sm",children:[e.jsx(je,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsxs("span",{className:"text-muted-foreground",children:[n.filter(r=>!r.curated&&!r.deprecated).length,' uncurated models hidden — switch to "All" or "Uncurated" to see and curate them.']})]}),e.jsxs("div",{className:"rounded-xl border border-border bg-muted/30 p-4 flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ye,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("span",{className:"text-sm font-medium",children:[n.filter(r=>r.curated).length," curated / ",n.length," total models"]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"— toggle curated per model in the table below"})]}),e.jsx("div",{className:"flex items-center gap-1",children:["curated","all","uncurated"].map(r=>e.jsx(A,{variant:c===r?"default":"outline",size:"sm",onClick:()=>y(r),children:r==="curated"?"⭐ Curated":r==="all"?"All":"Uncurated"},r))})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(le,{providerId:"gateway",models:f,
6jobs:p,keyStatus:"n/a",onTestKey:()=>{},testingKey:!1,onRefresh:m,showDeprecated:j,onToggleCurated:$}),t.map(r=>e.jsx(le,{providerId:r,models:s[r],jobs:p,keyStatus:_[r]||"not_set",onTestKey:u,testingKey:N===r,onRefresh:m,showDeprecated:j,onTestAndRefresh:x,onToggleCurated:$},r))]})]})}function Ee({jobs:n,models:p,keyStatuses:_}){const m=W(),[o,g]=T.useState(n);T.useEffect(()=>{g(n)},[n]);const N=p.filter(s=>s.billing_path==="gateway"&&!s.deprecated&&s.status==="active"),S=p.filter(s=>s.billing_path==="api_key"&&!s.deprecated&&s.status==="active"),j={};for(const s of S){const t=s.provider_id||s.provider;(_[t]==="valid"||_[t]==="no_credits")&&(j[t]||(j[t]=[]),j[t].push(s))}const a=Ne({mutationFn:async()=>{for(const s of o){const{error:t}=await I.from("ai_job_config").update({primary_model_id:s.primary_model_id,fallback_model_id:s.fallback_model_id,max_tokens:s.max_tokens,temperature:s.temperature,timeout_ms:s.timeout_ms,daily_cost_limit:s.daily_cost_limit,updated_at:new Date().toISOString()}).eq("id",s.id);if(t)throw t}},onSuccess:()=>{C.success("Job configuration saved"),m.invalidateQueries({queryKey:["ai-job-config"]})},onError:s=>C.error(s.message)}),c=(s,t)=>{g(u=>u.map((x,l)=>l===s?{...x,...t}:x))},y=()=>{for(const s of o){if(!s.primary_model_id)return`${s.display_name}: primary model required`;if(s.primary_model_id===s.fallback_model_id)return`${s.display_name}: primary and fallback can't be the same`;if(s.temperature<0||s.temperature>2)return`${s.display_name}: temperature must be 0–2`;if(s.timeout_ms<1e3||s.timeout_ms>6e4)return`${s.display_name}: timeout must be 1000–60000ms`;if(s.daily_cost_limit<=0)return`${s.display_name}: daily cost limit must be > 0`}return null},v=()=>{const s=y();if(s){C.error(s);return}a.mutate()};function $(s){return s===0?"free":s<.01?`$${s.toFixed(4)}`:s<1?`$${s.toFixed(2)}`:`$${s.toFixed(1)}`}function d(s){const t=Pe[s.model_id],u=$(s.input_cost_per_1m),x=$(s.output_cost_per_1m);return`${s.display_name}${t?` — ${t}`:""} · in ${u} / out ${x}`}function f(s,t,u=!1){const x=N.filter(l=>l.curated);return e.jsxs(ne,{value:s||(u?"__none__":""),onValueChange:l=>t(l==="__none__"?"":l),children:[e.jsx(ie,{className:"h-9",children:e.jsx(oe,{})}),e.jsxs(de,{children:[u&&e.jsx(z,{value:"__none__",children:"None"}),x.length>0&&e.jsxs(Y,{children:[e.jsx(U,{children:"☁️ Gateway — price per 1M tokens sent / received"}),x.map(l=>e.jsx(z,{value:l.model_id,children:d(l)},l.model_id))]}),Object.entries(j).map(([l,i])=>{var D,P;const k=i.filter(q=>q.curated);return k.length>0&&e.jsxs(Y,{children:[e.jsxs(U,{children:[(D=R[l])==null?void 0:D.icon," ",((P=R[l])==null?void 0:P.label)||l," — price per 1M tokens sent / received"]}),k.map(q=>e.jsx(z,{value:q.model_id,children:d(q)},q.model_id))]},l)})]})]})}return e.jsxs("section",{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Job Assignments"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Assign models to server-side tasks. Models from all sources available."})]}),e.jsxs("div",{className:"space-y-4 rounded-xl border border-border bg-card p-5",children:[o.map((s,t)=>{const u=p.find(l=>l.model_id===s.primary_model_id),x=u==null?void 0:u.deprecated;return e.jsxs("div",{className:t>0?"pt-4 border-t border-border":"",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"text-lg",children:_e[s.job_type]||"🤖"}),e.jsx("span",{className:"font-semibold text-sm",children:s.display_name}),x&&e.jsxs("span",{className:"text-xs text-yellow-600 dark:text-yellow-400 font-medium flex items-center gap-1",children:[e.jsx(ge,{className:"h-3 w-3"})," Deprecated model"]})]}),s.description&&e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:s.description}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 mb-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground",children:"Primary"}),f(s.primary_model_id,l=>c(t,{primary_model_id:l}))]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground",children:"Fallback"}),f(s.fallback_model_id||"",l=>c(t,{fallback_model_id:l||null}),!0)]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground",children:"Temp"}),e.jsx(Q,{type:"number",step:"0.1",min:"0",max:"2",className:"h-9",value:s.temperature,onChange:l=>c(t,{temperature:+l.target.value})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground",children:"Timeout (ms)"}),e.jsx(Q,{type:"number",step:"1000",className:"h-9",value:s.timeout_ms,onChange:l=>c(t,{timeout_ms:+l.target.value})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground",children:"Max $/day"}),e.jsx(Q,{type:"number",step:"0.5",className:"h-9",value:s.daily_cost_limit,onChange:l=>c(t,{daily_cost_limit:+l.target.value})})]})]})]},s.id)}),e.jsxs(A,{onClick:v,disabled:a.isPending,className:"mt-2",children:[e.jsx(Ie,{className:"h-4 w-4 mr-1"})," ",a.isPending?"Saving…":"Save Job Config"]})]}),e.jsxs("div",{className:"rounded-lg border border-dashed border-border bg-muted/30 p-4 mt
6-4 flex items-start gap-2",children:[e.jsx(je,{className:"h-4 w-4 text-muted-foreground shrink-0 mt-0.5"}),e.jsx("p",{className:"text-xs text-muted-foreground leading-relaxed",children:'User-facing calculator chat uses the configured "User Chat" job model, which routes through direct provider APIs.'})]})]})}function Be({jobs:n}){const[p,_]=T.useState("7d"),m={"24h":1,"7d":7,"30d":30}[p],{data:o,isLoading:g}=K({queryKey:["ai-cost-dashboard",p],queryFn:async()=>{const a=new Date(Date.now()-m*864e5).toISOString(),{data:c}=await I.from("runtime_logs").select("details, source, calculator_slug, created_at").eq("log_type","ai_call").eq("severity","info").gte("created_at",a).order("created_at",{ascending:!1}).limit(5e3);if(!c||c.length===0)return{byModel:[],byJob:[],topCalcs:[],total:{calls:0,inputTokens:0,outputTokens:0,cost:0},dailySpend:{}};const y=new Map,v=new Map,$=new Map,d={},f=new Date().toISOString().slice(0,10);for(const s of c){const t=s.details;if(!(t!=null&&t.model_id))continue;const u=y.get(t.model_id)||{calls:0,inputTokens:0,outputTokens:0,cost:0};u.calls++,u.inputTokens+=t.input_tokens||0,u.outputTokens+=t.output_tokens||0,u.cost+=t.estimated_cost||0,y.set(t.model_id,u);const x=s.source||"unknown",l=x==="chat-ai"?"User Chat API":x==="log-build"?"Build Intelligence":x==="content-factory"?"Content Generation":x==="validation"?"Validation":x,i=v.get(l)||{calls:0,cost:0};if(i.calls++,i.cost+=t.estimated_cost||0,v.set(l,i),s.calculator_slug){const k=$.get(s.calculator_slug)||{calls:0,cost:0};k.calls++,k.cost+=t.estimated_cost||0,$.set(s.calculator_slug,k)}s.created_at&&s.created_at.slice(0,10)===f&&(d[x]=(d[x]||0)+(t.estimated_cost||0))}return{byModel:Array.from(y.entries()).map(([s,t])=>({model_id:s,...t})).sort((s,t)=>t.cost-s.cost),byJob:Array.from(v.entries()).map(([s,t])=>({job:s,...t})).sort((s,t)=>t.cost-s.cost),topCalcs:Array.from($.entries()).map(([s,t])=>({slug:s,...t})).sort((s,t)=>t.cost-s.cost).slice(0,10),total:Array.from(y.values()).reduce((s,t)=>({calls:s.calls+t.calls,inputTokens:s.inputTokens+t.inputTokens,outputTokens:s.outputTokens+t.outputTokens,cost:s.cost+t.cost}),{calls:0,inputTokens:0,outputTokens:0,cost:0}),dailySpend:d}},staleTime:6e4}),N=!o||o.total.calls===0,S={"chat-ai":"user_chat","content-factory":"content_generation","log-build":"build_intelligence",validation:"validation"},j=n.map(a=>{var d;const c=((d=Object.entries(S).find(([,f])=>f===a.job_type))==null?void 0:d[0])||"",y=(o==null?void 0:o.dailySpend[c])||0,v=a.daily_cost_limit,$=v>0?Math.min(y/v*100,100):0;return{label:a.display_name,icon:_e[a.job_type]||"🤖",spent:y,limit:v,pct:$}});return e.jsxs("section",{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Cost Dashboard"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Direct API costs from edge function calls."})]}),e.jsx("div",{className:"flex gap-2 mb-4",children:["24h","7d","30d"].map(a=>e.jsxs(A,{variant:p===a?"default":"outline",size:"sm",onClick:()=>_(a),children:["Last ",a]},a))}),g?e.jsx("div",{className:"rounded-xl border border-border bg-card p-8 text-center text-muted-foreground",children:"Loading cost data…"}):N?e.jsx("div",{className:"rounded-xl border border-border bg-card p-8 text-center text-muted-foreground",children:"No AI calls logged yet. Cost data appears after calculators process AI requests."}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-border bg-card overflow-hidden",children:[e.jsx("div",{className:"px-4 py-2 border-b border-border",children:e.jsx("span",{className:"text-sm font-semibold",children:"By Model"})}
6),e.jsxs(H,{children:[e.jsx(G,{children:e.jsxs(O,{children:[e.jsx(M,{children:"Model"}),e.jsx(M,{className:"text-right",children:"Calls"}),e.jsx(M,{className:"text-right",children:"Input Tk"}),e.jsx(M,{className:"text-right",children:"Output Tk"}),e.jsx(M,{className:"text-right",children:"Cost"})]})}),e.jsxs(J,{children:[o.byModel.map(a=>e.jsxs(O,{children:[e.jsx(w,{className:"font-medium",children:a.model_id}),e.jsx(w,{className:"text-right font-mono",children:a.calls.toLocaleString()}),e.jsx(w,{className:"text-right font-mono",children:V(a.inputTokens)}),e.jsx(w,{className:"text-right font-mono",children:V(a.outputTokens)}),e.jsx(w,{className:"text-right font-mono",children:L(a.cost)})]},a.model_id)),e.jsxs(O,{className:"font-bold border-t-2",children:[e.jsx(w,{children:"TOTAL"}),e.jsx(w,{className:"text-right font-mono",children:o.total.calls.toLocaleString()}),e.jsx(w,{className:"text-right font-mono",children:V(o.total.inputTokens)}),e.jsx(w,{className:"text-right font-mono",children:V(o.total.outputTokens)}),e.jsx(w,{className:"text-right font-mono",children:L(o.total.cost)})]})]})]})]}),e.jsxs("div",{className:"rounded-xl border border-border bg-card overflow-hidden",children:[e.jsx("div",{className:"px-4 py-2 border-b border-border",children:e.jsx("span",{className:"text-sm font-semibold",children:"By Job"})}
6),e.jsxs(H,{children:[e.jsx(G,{children:e.jsxs(O,{children:[e.jsx(M,{children:"Job"}),e.jsx(M,{className:"text-right",children:"Calls"}),e.jsx(M,{className:"text-right",children:"Cost"})]})}),e.jsx(J,{children:o.byJob.map(a=>e.jsxs(O,{children:[e.jsx(w,{className:"font-medium",children:a.job}),e.jsx(w,{className:"text-right font-mono",children:a.calls.toLocaleString()}),e.jsx(w,{className:"text-right font-mono",children:L(a.cost)})]},a.job))})]})]}),o.topCalcs.length>0&&e.jsxs("div",{className:"rounded-xl border border-border bg-card overflow-hidden",children:[e.jsx("div",{className:"px-4 py-2 border-b border-border",children:e.jsx("span",{className:"text-sm font-semibold",children:"Top Calculators by AI Cost"})}),e.jsxs(H,{children:[e.jsx(G,{children:e.jsxs(O,{children:[e.jsx(M,{children:"Calculator"}),e.jsx(M,{className:"text-right",children:"Calls"}),e.jsx(M,{className:"text-right",children:"Cost"})]})}),e.jsx(J,{children:o.topCalcs.map(a=>e.jsxs(O,{children:[e.jsx(w,{className:"font-mono text-sm",children:a.slug}),e.jsx(w,{className:"text-right font-mono",children:a.calls.toLocaleString()}),e.jsx(w,{className:"text-right font-mono",children:L(a.cost)})]},a.slug))})]})]}),e.jsxs("div",{className:"rounded-xl border border-border bg-card p-5",children:[e.jsx("h3",{className:"text-sm font-semibold mb-3",children:"Daily Budget Status"}),e.jsx("div",{className:"space-y-3",children:j.map(a=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsxs("span",{children:[a.icon," ",a.label]}),e.jsxs("span",{className:"font-mono text-muted-foreground",children:[L(a.spent)," / ",L(a.limit)]})]}),e.jsx(Se,{value:a.pct,className:`h-2 ${a.pct>80?"[&>div]:bg-destructive":a.pct>50?"[&>div]:bg-yellow-500":""}`})]},a.label))})]})]})]})}function ze(){return e.jsxs("section",{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Development & Co-Pilot"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"AI tools used in your development workflow — not called by ProCalc.ai code, but part of your complete toolkit."})]}),e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"rounded-xl border border-dashed border-border bg-muted/30 p-5 space-y-2",children:[e.jsxs("h3",{className:"font-semibold flex items-center gap-2",children:["🔵 Claude Opus 4.6 ",e.jsx("span",{className:"text-xs text-muted-foreground font-normal",children:"(via claude.ai)"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Your co-pilot for architecture, strategy, and planning. Used through claude.ai chat, not via API."}),e.jsxs("ul",{className:"text-xs text-muted-foreground list-disc list-inside space-y-0.5",children:[e.jsx("li",{children:"Architecture decisions & documentation"}),e.jsx("li",{children:"Writing build prompts"}),e.jsx("li",{children:"Content strategy & SEO planning"}),e.jsx("li",{children:"Business planning & analysis"}),e.jsx("li",{children:"Code review & debugging guidance"})]}),e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Claude Sonnet 4 is also available as a direct API model (see registry above)."})]})})]})}function He({models:n,keyStatuses:p}){const _=W(),[m,o]=T.useState(!1),g=n.filter(c=>!c.deprecated&&c.status==="active"),{data:N=[],isLoading:S}=K({queryKey:["calc-overrides"],queryFn:async()=>{const{data:c}=await I.from("calculators").select("id, name, slug, ai_model_override").not("ai_model_override","is",null).order("name");return c||[]}}),{data:j=0}=K({queryKey:["calc-total-count"],queryFn:async()=>{const{count:c}=await I.from("calculators").select("id",{count:"exact",head:!0});return c||0}}),a=async c=>{await I.from("calculators").update({ai_model_override:null}).eq("id",c),_.invalidateQueries({queryKey:["calc-overrides"]}),C.success("Override removed")};return e.jsxs("section",{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Per-Calculator Overrides"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Override the default model for specific calculators."})]}),e.jsxs("div",{className:"rounded-xl border border-border bg-card overflow-hidden",children:[S?e.jsx("div",{className:"p-8 text-center text-muted-foreground",children:"Loading…"}):N.length===0?e.jsx("div",{className:"p-8 text-center text-muted-foreground",children:"No overrides set. All calculators use the default."}
6):e.jsxs(H,{children:[e.jsx(G,{children:e.jsxs(O,{children:[e.jsx(M,{children:"Calculator"}),e.jsx(M,{children:"Override Model"}),e.jsx(M,{className:"w-10"})]})}),e.jsx(J,{children:N.map(c=>{const y=g.find(v=>v.model_id===c.ai_model_override);return e.jsxs(O,{children:[e.jsx(w,{className:"font-medium",children:c.name}),e.jsx(w,{children:(y==null?void 0:y.display_name)||c.ai_model_override}),e.jsx(w,{children:e.jsx(A,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>a(c.id),children:e.jsx(we,{className:"h-3.5 w-3.5"})})})]},c.id)})})]}),e.jsxs("div",{className:"p-4 border-t border-border flex items-center justify-between",children:[e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>o(!0),children:[e.jsx(ve,{className:"h-3.5 w-3.5 mr-1"})," Add Override"]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[j-N.length," calculators using default"]})]})]}),m&&e.jsx(Ge,{models:g,keyStatuses:p,onClose:()=>o(!1),onDone:()=>{_.invalidateQueries({queryKey:["calc-overrides"]}),o(!1)}})]})}function Ge({models:n,keyStatuses:p,onClose:_,onDone:m}){const[o,g]=T.useState(""),[N,S]=T.useState(""),[j,a]=T.useState(""),{data:c=[]}=K({queryKey:["ai-calcs-for-override",o],queryFn:async()=>{let d=I.from("calculators").select("id, name, slug").eq("compute_tier","ai").order("name").limit(50);o&&(d=d.ilike("name",`%${o}%`));const{data:f}=await d;return f||[]}}),y=n.filter(d=>d.billing_path==="gateway"),v={};for(const d of n.filter(f=>f.billing_path==="api_key")){const f=d.provider_id||d.provider;(p[f]==="valid"||p[f]==="no_credits")&&(v[f]||(v[f]=[]),v[f].push(d))}const $=async()=>{!N||!j||(await I.from("calculators").update({ai_model_override:j}).eq("id",N),C.success("Override added"),m())};return e.jsx(ce,{open:!0,onOpenChange:_,children:e.jsxs(me,{className:"max-w-md",children:[e.jsx(ue,{children:e.jsx(xe,{children:"Add Calculator Override"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Search Calculator"}),e.jsx(Q,{placeholder:"Search by name…",value:o,onChange:d=>g(d.target.value)}),c.length>0&&e.jsx("div",{className:"mt-2 max-h-40 overflow-y-auto border border-border rounded-lg",children:c.map(d=>e.jsx("button",{onClick:()=>S(d.id),className:`w-full text-left px-3 py-2 text-sm hover:bg-muted/50 ${N===d.id?"bg-primary/10 font-medium":""}`,children:d.name},d.id))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Override Model"}),e.jsxs(ne,{value:j,onValueChange:a,children:[e.jsx(ie,{children:e.jsx(oe,{placeholder:"Select model…"})}),e.jsxs(de,{children:[y.length>0&&e.jsxs(Y,{children:[e.jsx(U,{children:"Gateway"}),y.map(d=>e.jsx(z,{value:d.model_id,children:d.display_name},d.model_id))]}),Object.entries(v).map(([d,f])=>{var s;return f.length>0&&e.jsxs(Y,{children:[e.jsx(U,{children:((s=R[d])==null?void 0:s.label)||d}),f.map(t=>e.jsx(z,{value:t.model_id,children:t.display_name},t.model_id))]},d)})]})]})]})]}),e.jsxs(he,{children:[e.jsx(A,{variant:"outline",onClick:_,children:"Cancel"}),e.jsx(A,{onClick:$,disabled:!N||!j,children:"Add Override"})]})]})})}function ps(){const n=W(),[p,_]=T.useState(!1),{data:m=[],isLoading:o}=K({queryKey:["ai-models"],queryFn:async()=>{const{data:s}=await I.from("ai_models").select("*").order("provider, display_name");return s||[]}}),{data:g=[],isLoading:N}=K({queryKey:["ai-job-config"],queryFn:async()=>{const{data:s}=await I.from("ai_job_config").select("*").order("job_type");return s||[]}}),{data:S={},refetch:j}=K({queryKey:["api-key-status"],queryFn:async()=>{try{const{data:s,error:t}=await I.functions.invoke("manage-api-key",{body:{action:"status"}});return t?{}:(s==null?void 0:s.status)||{}}catch{return{}}},staleTime:Ce.CALCULATOR_TTL_MS,select:s=>{const t={};for(const[u,x]of Object.entries(s))t[u]=x?"valid":"not_set";return t}}),[a,c]=T.useState({}),y={...S,...a},{data:v}=K({queryKey:["ai-cost-summary-7d"],queryFn:async()=>{var x;const s=new Date(Date.now()-6048e5).toISOString(),{data:t}=await I.from("runtime_logs").select("details").eq("log_type","ai_call").eq("severity","info").gte("created_at",s).limit(5e3);if(!t)return{calls:0,cost:0};let u=0;for(const l of t)u+=((x=l.details)==null?void 0:x.estimated_cost)||0;return{calls:t.length,cost:u}},staleTime:12e4}),$=T.useCallback(()=>
6{if(m.length===0)return!0;const s=m.reduce((t,u)=>{const x=u.discovered_at?new Date(u.discovered_at).getTime():0;return x<t?x:t},1/0);return s===1/0||s===0?!0:Date.now()-s>30*24*60*60*1e3},[m]),d=T.useCallback(async()=>{_(!0);try{const{data:s,error:t}=await I.functions.invoke("refresh-ai-models");if(t)C.error(`Refresh failed: ${t.message}`);else if(s!=null&&s.success){const x=s.summary.new_uncurated||0;n.invalidateQueries({queryKey:["ai-models"]}),n.invalidateQueries({queryKey:["api-key-status"]})}else C.error((s==null?void 0:s.error)||"Refresh failed")}catch(s){C.error(s.message)}_(!1)},[n]);T.useEffect(()=>{!o&&$()&&!p&&d()},[o]);const f=o||N;return e.jsxs("div",{className:"max-w-5xl mx-auto space-y-10",children:[e.jsxs("header",{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[e.jsx(Me,{className:"h-6 w-6 text-primary"}),e.jsx("h1",{className:"text-2xl font-bold",children:"AI Models"})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Manage every AI model in your stack — direct API keys and development tools."})]}),f?e.jsx("div",{className:"text-center text-muted-foreground py-12",children:p?"Discovering available models…":"Loading AI configuration…"}):e.jsxs(e.Fragment,{children:[e.jsx(Ke,{models:m,jobs:g,costData:v||null,onRefresh:d,refreshing:p}),e.jsx("hr",{className:"border-border"}),e.jsx(Ee,{jobs:g,models:m,keyStatuses:y}),e.jsx("hr",{className:"border-border"}),e.jsx(Le,{models:m,jobs:g,keyStatuses:y,onRefresh:d,refreshing:p,onKeyStatusUpdate:(s,t)=>c(u=>({...u,[s]:t}))}),e.jsx("hr",{className:"border-border"}),e.jsx(Be,{jobs:g}),e.jsx("hr",{className:"border-border"}),e.jsx(He,{models:m,keyStatuses:y}),e.jsx("hr",{className:"border-border"}),e.jsx(ze,{})]})]})}export{ps as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.