import{o as e}from"./rolldown-runtime-BM3Ffeng.js";import{n as t}from"./useAnnotationQueues-DnoGcOPa.js";import{B_ as n,Hy as r,Ic as i,Lc as a,Rc as o,Ul as s,Wa as c,ap as l,jg as u,kp as d,lh as f,m_ as p,mv as m,ty as h,zh as g}from"./index-DDwwBb9e.js";import{t as _}from"./AnnotationsTable-CEsXi7KL.js";import{t as v}from"./getSingleQueryParam-Dsx5fDeS.js";var y=e(c()),b=r();function x(){let{project:e}=l(),r=d(),{filterParams:c,queryOpts:x,nonEmptyFilters:S}=i(),C=Object.keys(S).length>0,w=f.traces.getAllForProject.useQuery({...c,query:v(r.query.query),groupBy:`none`,pageOffset:0,pageSize:1e4,sortBy:v(r.query.sortBy),sortDirection:v(r.query.orderBy)},x),{period:{startDate:T,endDate:E},mode:D,setPeriod:O,setRelativePeriod:k}=o(),A=w.data?.groups.flatMap(e=>e.map(e=>e.trace_id))??[],j=s({projectId:e?.id??``,traceIds:A,enabled:C&&e?.id!==void 0}),M=f.annotation.getAll.useQuery({projectId:e?.id??``,startDate:T,endDate:E},{enabled:!C&&!!e}),N=C?j:M,P=C?w.isLoading||j.isLoading:M.isLoading,F=N.data?.map(e=>e.traceId),I=f.traces.getTracesWithSpans.useQuery({projectId:e?.id??``,traceIds:F??[]},{enabled:!!e?.id,refetchOnWindowFocus:!1}),L=(e=>{let t=e.reduce((e,t)=>{e[t.traceId]||(e[t.traceId]={traceId:t.traceId,annotations:[],trace:I.data?.find(e=>e.trace_id===t.traceId)});let n={...t,user:t.user},r=e[t.traceId];return r&&r.annotations.push(n),e},{});return Object.values(t)})(N.data??[]),R=()=>{let e=[`User`,`Input`,`Output`,`Expected Output`,`Comment`,`Trace ID`,`Rating`,`Scoring`,`Created At`],t=N?.data?.map(e=>{let t=I.data?.find(t=>t.trace_id===e.traceId);return[e.user?.name??``,t?.input?.value??``,t?.output?.value??``,e.expectedOutput??``,e.comment??``,e.traceId??``,e.isThumbsUp?`Thumbs Up`:`Thumbs Down`,JSON.stringify(e.scoreOptions??{}),e.createdAt?.toLocaleString()??``]})??[],n=y.default.unparse({fields:e,data:t}),r=window.URL.createObjectURL(new Blob([n])),i=document.createElement(`a`);i.href=r;let a=`Traces - ${new Date().toISOString().split(`T`)[0]}.csv`;i.setAttribute(`download`,a),document.body.appendChild(i),i.click(),i.remove()},z=(0,b.jsxs)(p,{width:`full`,align:`top`,children:[(0,b.jsx)(h,{as:`h1`,size:`lg`,paddingTop:1,children:`All Annotations`}),(0,b.jsx)(u,{}),(0,b.jsxs)(m,{minWidth:`fit-content`,variant:`ghost`,onClick:()=>R(),children:[`Export all `,(0,b.jsx)(g,{style:{marginLeft:`8px`}})]}),(0,b.jsx)(a,{period:{startDate:T,endDate:E},mode:D,setPeriod:O,setRelativePeriod:k})]});return(0,b.jsx)(t,{children:(0,b.jsx)(n,{maxW:`calc(100vw - 330px)`,padding:0,margin:0,children:(0,b.jsx)(_,{groupedAnnotations:L,allAnnotationsLoading:P||I.isLoading,heading:`Annotations`,isDone:!0,tableHeader:z,noDataTitle:`No recent annotations yet, change the date range to see more or annotate your messages`,noDataDescription:`Annotate your messages to add more context and improve your analysis.`})})})}export{x as default};
//# sourceMappingURL=all-DpGQ6UFh.js.map