1 line
6.1 KiB
JavaScript
1 line
6.1 KiB
JavaScript
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,9875,e=>{"use strict";var t=e.i(43476),s=e.i(46932),a=e.i(71645),n=e.i(47163);function l({entry:e}){let[s,l]=(0,a.useState)(!1),r="request"===e.direction,i="response"===e.direction,c="error"===e.direction,d="YES"===e.verdict,o="NO"===e.verdict,x=(e.tokens_prompt??0)+(e.tokens_completion??0);return(0,t.jsxs)("div",{className:(0,n.cn)("rounded-lg border text-sm transition-colors",c?"border-g-red/20 bg-g-red/4":d?"border-g-green/20 bg-g-green/4":o?"border-g-line":"border-g-border/60"),children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-3 flex-wrap px-3.5 py-2.5",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,t.jsx)("span",{className:(0,n.cn)("g-badge",r?"g-badge-neutral":i?d?"g-badge-green":o?"g-badge-red":"g-badge-neutral":"g-badge-red"),children:r?"→ Prompt":i?"← Response":"⚠ Error"}),(0,t.jsx)("span",{className:"g-badge g-badge-neutral",children:e.call_type}),e.provider&&(0,t.jsx)("span",{className:"text-xs text-g-faint",children:e.provider}),e.model&&(0,t.jsx)("span",{className:"text-xs text-g-faint truncate max-w-[160px]",children:e.model})]}),(0,t.jsx)("span",{className:"text-[11px] text-g-faint tabular-nums shrink-0",children:new Date(e.ts).toLocaleTimeString()})]}),(e.title||e.site)&&(0,t.jsxs)("div",{className:"px-3.5 pb-2 flex items-center gap-2 flex-wrap",children:[e.title&&(0,t.jsx)("span",{className:"text-xs text-g-text leading-relaxed",children:e.title.length>72?e.title.slice(0,72)+"…":e.title}),e.site&&(0,t.jsxs)("span",{className:"text-xs text-g-faint",children:["· ",e.site]})]}),i&&e.verdict&&(0,t.jsxs)("div",{className:(0,n.cn)("px-3.5 pb-2 flex items-center gap-1.5 text-xs font-medium",d?"text-g-green":"text-g-red"),children:[(0,t.jsx)("span",{className:(0,n.cn)("w-1.5 h-1.5 rounded-full flex-shrink-0",d?"bg-g-green":"bg-g-red")}),d?"Match — lot accepted":"Reject — lot filtered out"]}),e.content&&(0,t.jsxs)("div",{className:"px-3.5 pb-3",children:[(0,t.jsx)("pre",{className:(0,n.cn)("whitespace-pre-wrap break-words text-[11px] leading-relaxed font-mono","bg-g-base/80 border border-g-border/40 p-3 rounded-md",r?"text-g-faint":"text-g-muted",!s&&"max-h-20 overflow-hidden"),children:e.content}),e.content.length>180&&(0,t.jsx)("button",{onClick:()=>l(!s),className:"text-g-faint hover:text-g-muted text-[11px] mt-1 transition-colors",children:s?"▲ Collapse":`▼ Expand (${e.content.length} chars)`})]}),(null!=e.tokens_prompt||null!=e.tokens_completion)&&(0,t.jsx)("div",{className:"px-3.5 pb-2.5 flex items-center gap-2 text-[11px] text-g-faint",children:(0,t.jsxs)("span",{className:"g-badge g-badge-neutral",children:[e.tokens_prompt??"?"," + ",e.tokens_completion??"?"," = ",x," tokens"]})}),c&&e.status_code&&(0,t.jsxs)("div",{className:"px-3.5 pb-2 text-xs text-g-red font-mono",children:["HTTP ",e.status_code]})]})}let r="http://localhost:8000",i=async(e=50,t=0)=>{let s=await fetch(`${r}/api/ai/debug/log?limit=${e}&since_id=${t}`);if(!s.ok)throw Error("Failed to fetch AI log");return s.json()},c=async()=>{await fetch(`${r}/api/ai/debug/log`,{method:"DELETE"})},d={ALL:"All",FILTER:"Filter calls",ADAPT:"Adapt calls",ERRORS:"Errors"};function o(){let[e,s]=(0,a.useState)([]),[r,o]=(0,a.useState)(null),[x,g]=(0,a.useState)(0),[p,m]=(0,a.useState)("ALL"),[h,u]=(0,a.useState)(""),b=(0,a.useCallback)(async()=>{try{let e=await i(200);s(Array.isArray(e.entries)?e.entries:[]),o(e.debug_enabled??null),g(e.total_in_buffer??0)}catch{}},[]);(0,a.useEffect)(()=>{b();let e=setInterval(b,5e3);return()=>clearInterval(e)},[b]);let f=e.filter(e=>("FILTER"!==p||"filter"===e.call_type)&&("ADAPT"!==p||"adapt"===e.call_type)&&("ERRORS"!==p||"error"===e.direction)&&(!h||!!JSON.stringify(e).toLowerCase().includes(h.toLowerCase())));return(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("div",{className:"flex gap-2 flex-wrap items-center",children:[["ALL","FILTER","ADAPT","ERRORS"].map(e=>(0,t.jsx)("button",{onClick:()=>m(e),className:(0,n.cn)("g-btn text-xs h-8",p===e&&"!border-g-green/40 !text-g-green !bg-g-green/8"),children:d[e]},e)),(0,t.jsxs)("div",{className:"relative ml-auto",children:[(0,t.jsx)("span",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-g-faint text-xs",children:"⌕"}),(0,t.jsx)("input",{value:h,onChange:e=>u(e.target.value),placeholder:"Search log…",className:"g-input h-8 pl-7 text-xs w-44"})]}),(0,t.jsx)("button",{onClick:b,className:"g-btn text-xs h-8",children:"Refresh"}),(0,t.jsx)("button",{onClick:async()=>{await c(),s([]),g(0)},className:"g-btn-danger text-xs h-8",children:"Clear"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-4 text-xs text-g-faint",children:[!1===r&&(0,t.jsxs)("span",{className:"flex items-center gap-1.5 text-g-amber",children:[(0,t.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-g-amber flex-shrink-0"}),"AI Debug is off — enable it in Settings → AI Filter to capture logs"]}),!0===r&&(0,t.jsxs)("span",{className:"flex items-center gap-1.5 text-g-green",children:[(0,t.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-g-green animate-pulse flex-shrink-0"}),"AI Debug on"]}),x>0&&(0,t.jsxs)("span",{children:[x," entries · showing ",f.length]})]}),(0,t.jsx)("div",{className:"g-card overflow-hidden",children:(0,t.jsx)("div",{className:"max-h-[72vh] overflow-y-auto p-4 space-y-2",children:0===f.length?(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center py-14 text-g-faint gap-2",children:[(0,t.jsx)("span",{className:"text-3xl opacity-20",children:"◎"}),(0,t.jsx)("p",{className:"text-sm",children:!1===r?"Enable AI Debug in Settings to start capturing logs":"No AI log entries"})]}):[...f].reverse().map(e=>(0,t.jsx)(l,{entry:e},e.id))})})]})}function x(){return(0,t.jsxs)("div",{className:"space-y-5",children:[(0,t.jsxs)(s.motion.div,{initial:{opacity:1,y:-8},animate:{opacity:1,y:0},transition:{duration:.4},children:[(0,t.jsx)("h1",{className:"g-page-title",children:"AI Log"}),(0,t.jsx)("p",{className:"g-page-sub",children:"Live AI filter decisions and responses"})]}),(0,t.jsx)(o,{})]})}e.s(["default",()=>x],9875)}]); |