1import{k as j,r as l,j as e,L as N}from"./react-vendor-_u6yc6G3.js";import{B as m,x as g,L as y,d as k}from"./home-shell-CTGrsjBA.js";import{u as v}from"./index-BNfarQ2j.js";import{api as w,ApiError as S}from"./api-BRbLmQ3u.js";import{b as A}from"./format-DqK-5hky.js";import"./adminToken-B_GNaCSP.js";function M(a){return a==="success"?"text-emerald-600 dark:text-emerald-400":a==="rate_limited"?"text-amber-600 dark:text-amber-400":"text-rose-600 dark:text-rose-400"}function u(a,t=140){if(!a?.trim())return"â";const d=a.replace(/<[^>]+>/g," ").replace(/\s+/g," ").trim();return d.length<=t?d:`${d.slice(0,t)}â¦`}const P=[{key:"",label:"All"},{key:"success",label:"Success"},{key:"rate_limited",label:"Rate limited"},{key:"failed",label:"Failed"}];function R(){const{push:a}=v(),[t,d]=j(),[b,f]=l.useState(!0),[x,h]=l.useState([]),i=l.useMemo(()=>{const s=Number(t.get("limit")??"50");return Number.isFinite(s)?Math.min(100,Math.max(10,s)):50},[t]),n=l.useMemo(()=>{const s=Number(t.get("offset")??"0");return Number.isFinite(s)?Math.max(0,s):0},[t]),o=l.useMemo(()=>(t.get("status")??"").trim(),[t]),p=l.useCallback(async()=>{f(!0);try{const s=await w.adminAiQueAns({limit:i,offset:n,status:o||void 0});h(s.items)}catch(s){const r=s instanceof S?s.message:"Could not load AI prompts.";a(r,"error"),h([])}finally{f(!1)}},[i,n,o,a]);l.useEffect(()=>{p()},[p]);const c=s=>{const r=new URLSearchParams(t);s.limit!==void 0&&r.set("limit",String(s.limit)),s.offset!==void 0&&r.set("offset",String(s.offset)),s.status!==void 0&&(s.status?r.set("status",s.status):r.delete("status")),d(r)};return e.jsxs("div",{className:"w-full min-w-0 space-y-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold text-slate-900 sm:text-2xl dark:text-white",children:"AI prompts & answers"}),e.jsxs("p",{className:"mt-1 text-sm text-slate-600 dark:text-slate-400",children:["User prompts and generated email drafts stored in ",e.jsx("code",{className:"text-xs",children:"ai_que_ans"}),"."]})]}),e.jsx(N,{to:"/admin/ai",children:e.jsx(m,{variant:"secondary",className:"py-2 text-sm",children:"Back to AI settings"})})]}),e.jsxs(g,{hover:!1,className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:"Status"}),e.jsx("select",{value:o,onChange:s=>c({status:s.target.value,offset:0}),className:"rounded-lg border border-slate-200 bg-white px-3 py-2 text-sm text-slate-700 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-200",children:P.map(s=>e.jsx("option",{value:s.key,children:s.label},s.key))}),e.jsx("label",{className:"ml-2 text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:"Page size"}),e.jsx("select",{value:String(i),onChange:s=>c({limit:Number(s.target.value),offset:0}),className:"rounded-lg border border-slate-200 bg-white px-3 py-2 text-sm text-slate-700 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-200",children:[10,25,50,100].map(s=>e.jsx("option",{value:String(s),children:s},s))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(m,{variant:"secondary",className:"py-2 text-sm",onClick:()=>void p(),children:"Refresh"}),e.jsx(m,{variant:"secondary",className:"py-2 text-sm",onClick:()=>c({offset:Math.max(0,n-i)}),disabled:n===0,children:"Prev"}),e.jsx(m,{variant:"secondary",className:"py-2 text-sm",onClick:()=>c({offset:n+i}),disabled:x.length<i,children:"Next"})]})]}),b?e.jsx("div",{className:"flex min-h-[14rem] items-center justify-center",children:e.jsx(y,{})}):x.length===0?e.jsx("p",{className:"text-sm text-slate-500",children:"No prompts found for this filter."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full text-left text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-slate-200 text-xs uppercase tracking-wide text-slate-500 dark:border-slate-700",children:[e.jsx("th",{className:"px-2 py-2 font-medium",children:"Time"}),e.jsx("th",{className:"px-2 py-2 font-medium",children:"User"}),e.jsx("th",{className:"px-2 py-2 font-medium",children:"Question"}),e.jsx("th",{className:"px-2 py-2 font-medium",children:"Answer"}),e.jsx("th",{className:"px-2 py-2 font-medium",children:"Model"}),e.jsx("th",{className:"px-2 py-2 font-medium",children:"Status"}),e.jsx("th",{className:"px-2 py-2 font-medium",children:"Error"})]})}),e.jsx("tbody",{children:x.map(s=>
1e.jsxs("tr",{className:"border-b border-slate-100 dark:border-slate-800",children:[e.jsx("td",{className:"whitespace-nowrap px-2 py-2 text-xs text-slate-500",children:A(s.createdAt)}),e.jsx("td",{className:"px-2 py-2 text-xs",children:s.userEmail??"â"}),e.jsx("td",{className:"max-w-xs px-2 py-2 text-xs text-slate-700 dark:text-slate-300",children:u(s.question)}),e.jsx("td",{className:"max-w-sm px-2 py-2 text-xs text-slate-700 dark:text-slate-300",children:s.status==="success"?e.jsxs("span",{title:u(s.answerBodyHtml,500),children:[e.jsx("span",{className:"font-medium",children:s.answerSubject??"â"}),e.jsx("span",{className:"mt-0.5 block text-slate-500",children:u(s.answerBodyHtml)})]}):"â"}),e.jsxs("td",{className:"px-2 py-2 font-mono text-xs",children:[s.modelUsed??"â",s.usedFallback?e.jsx("span",{className:"ml-1 rounded bg-amber-100 px-1.5 py-0.5 text-[10px] font-semibold uppercase text-amber-800 dark:bg-amber-900/40 dark:text-amber-300",children:"fallback"}):null]}),e.jsx("td",{className:k("px-2 py-2 text-xs font-medium capitalize",M(s.status)),children:s.status.replace(/_/g," ")}),e.jsx("td",{className:"max-w-xs px-2 py-2 text-xs text-slate-500",children:s.errorMessage||"â"})]},s.id))})]})})]})]})}export{R as AdminAiLogsPage};
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.