diff --git "a/index.html" "b/index.html"
--- "a/index.html"
+++ "b/index.html"
@@ -1,9 +1,11 @@
-
+
evalcull
+
+
+`:``;t=l.encode(je(e)+n)}else t=r.lineWithEol(o);e.push(t),u+=t.length}o%Ol===0&&(await new Promise(e=>setTimeout(e,0)),i&&i(o,a.lineCount))}let d=new Uint8Array(u),f=0;for(let t of e)d.set(t,f),f+=t.length;u>0&&o.push(d)}return i&&i(a.lineCount,a.lineCount),new Blob(o,{type:`application/jsonl`})}var Al=5e3;async function jl(e,t,n,r){let i=[],a=We(t);for(let o=0;osetTimeout(e,0)),r&&r(o,e.count))}return r&&r(e.count,e.count),new Blob(i,{type:`application/jsonl`})}var Ml=5e3;function Nl(e){let t={status:e?.status??`unreviewed`};return e?.compare&&(t.compare=e.compare),e?.labels&&e.labels.length>0&&(t.labels=e.labels),e?.score!==void 0&&(t.score=e.score),e?.notes!==void 0&&(t.notes=e.notes),t.edited=!!(e?.edits&&Object.keys(e.edits).length>0),t.updatedAt=e?.updatedAt??0,t}function Pl(e,t,n){let r=new Map;if(e.kind!==`jsonl`||n.kind!==`candidates`&&n.kind!==`preference`)return r;for(let[n,i]of t){let t=n.indexOf(`:`);if(t===-1)continue;let a=Ue(n),o=Number(n.slice(t+1));if(a>=e.index.lineCount||o>=e.index.candidates[a])continue;let s=r.get(a)??[];s.push([o,i]),r.set(a,s)}for(let e of r.values())e.sort((e,t)=>e[0]-t[0]);return r}var Fl=new Set([32,9,10,13]),Il=new TextEncoder().encode(`"_triage"`);function Ll(e,t){outer:for(let n=0;n+t.length<=e.length;n++){for(let r=0;rt&&Fl.has(e[n]);)n--;if(n<=t||e[n]!==125)return null;for(let t=0;t+1{let n=Nl(t),r=c.get(e);if(r){let e={};for(let[t,n]of r){let{compare:r,...i}=n;e[String(t)]=Nl(i)}n.candidates=e}return n},d=(e,n)=>{let r=t.get(He(e));if(!n.ok)return je({_raw:n.raw,_triage:u(e,r)})??``;let i=Ge(t,l,e)?.edits??{},a=n.data;for(let[e,t]of Object.entries(i))a=Xn(a,Kn(e),t);let o=u(e,r);o.edited=Object.keys(i).length>0;let s=typeof a==`object`&&!!a&&!Array.isArray(a)&&!ne(a),c;if(s){let{_triage:e,...t}=a;c={...t,_triage:o}}else c={_value:a,_triage:o};return je(c)??``};if(e.kind===`jsonl`){let n=e.index,r=new Set(n.unparseable),c=new TextDecoder(`utf-8`,{ignoreBOM:!0});for await(let n of Dl(e)){let e=new zl(Math.ceil(n.bytes.length*1.75)+4096);for(let o=n.first;o<=n.last;o++){if(!a||a(o)){let i=n.line(o),a=Object.keys(Ge(t,l,o)?.edits??{}).length>0,s=r.has(o)||a?null:Rl(i);if(s){let r=u(o,t.get(He(o)));r.edited=!1,e.bytes(i.subarray(0,s.close)),e.text(`${s.empty?``:`,`}"_triage":${je(r)}}`),e.bytes(n.lineWithEol(o).subarray(i.length))}else{let t=c.decode(i),r;try{r={index:o,ok:!0,data:Pe(t)}}catch(e){r={index:o,ok:!1,error:String(e),raw:t}}e.text(d(o,r)),e.bytes(n.lineWithEol(o).subarray(i.length))}}o%Ml===0&&(await new Promise(e=>setTimeout(e,0)),i&&i(o,s))}o.push(e.result())}}else for(let e=0;esetTimeout(e,0)),i&&i(e,s));return i&&i(s,s),new Blob(o,{type:`application/jsonl`})}function Vl(e){let t=[];for(let n of e)t.push(je(n)+`
+`);return new Blob(t,{type:`application/jsonl`})}function Hl(e,t){let n=t.roleKey,r=t.contentKey,i=String(e[n]??``),a=String(e[r]??``);return t.roles.assistant.includes(i)?i=`assistant`:t.roles.user.includes(i)?i=`user`:t.roles.system.includes(i)&&(i=`system`),{role:i,content:a}}function Ul(e,t){try{return Yn(e,Kn(t))}catch{return}}function Wl(e,t,n,r){let i=[],a=[],o=0,s=0,c=0,l=0,u=[];for(let[t,n]of e)n.compare?.length&&u.push({ref:t,lineIdx:Ue(t),decision:n});u.sort((e,t)=>e.lineIdx-t.lineIdx);let d=e=>r&&r(e)?void 0:n(e);for(let{lineIdx:e,decision:n}of u)for(let r of n.compare){if(r.preference===`tie`){o++;continue}if(r.preference===`both_bad`){s++;continue}let n=d(e),a=r.preference===`left`?r.left:r.right,u=r.preference===`left`?r.right:r.left,f=d(Ue(a)),p=d(Ue(u));if(n===void 0||f===void 0||p===void 0){l++;continue}let m=Jl(n,{ref:a,record:f},{ref:u,record:p},t);m&&(`prompt`in m||c++,i.push(m))}let f=[];for(let[t,n]of e)n.edits&&Object.keys(n.edits).length>0&&f.push({ref:t,lineIdx:Ue(t),decision:n});f.sort((e,t)=>e.lineIdx-t.lineIdx);for(let{lineIdx:e,decision:i}of f){if(r&&r(e)){l++;continue}let o=n(e);if(o===void 0){l++;continue}let s=Xl(o,i.edits,t);s&&a.push(s)}return{pairs:i,editPairs:a,excludedTies:o,excludedBothBad:s,implicitPromptCount:c,skippedUnparseable:l}}function Gl(e,t){for(let n=e.length-1;n>=0;n--){let r=e[n],i=String(r[t.roleKey]??``);if(t.roles.assistant.includes(i))return n}return-1}function Kl(e){let t=e.indexOf(`:`);return t===-1?-1:parseInt(e.slice(t+1),10)}function ql(e,t,n){switch(n.kind){case`flat`:{let e=Ul(t,n.responsePath);return typeof e==`string`?{ok:!0,value:e}:{ok:!1}}case`messages`:{let e=Ul(t,n.path);if(!Array.isArray(e))return{ok:!1};let r=Gl(e,n);return r<0?{ok:!1}:{ok:!0,value:[Hl(e[r],n)]}}case`candidates`:{let r=Ul(t,n.candidatesPath),i=Kl(e);return!Array.isArray(r)||i<0||i>=r.length?{ok:!1}:{ok:!0,value:r[i]}}case`preference`:{let r=Kl(e);return r===0?{ok:!0,value:Ul(t,n.chosenPath)}:r===1?{ok:!0,value:Ul(t,n.rejectedPath)}:{ok:!1}}default:return{ok:!1}}}function Jl(e,t,n,r){let i=ql(t.ref,t.record,r),a=ql(n.ref,n.record,r);if(!i.ok||!a.ok)return null;switch(r.kind){case`messages`:{let t=Ul(e,r.path);if(!Array.isArray(t))return null;let n=Gl(t,r);return n<0?null:{prompt:t.slice(0,n).map(e=>Hl(e,r)),chosen:i.value,rejected:a.value}}case`flat`:case`candidates`:{let t=Ul(e,r.promptPath);return typeof t==`string`?{prompt:t,chosen:i.value,rejected:a.value}:null}case`preference`:if(r.promptPath){let t=Ul(e,r.promptPath);if(typeof t==`string`)return{prompt:t,chosen:i.value,rejected:a.value}}return{chosen:i.value,rejected:a.value};default:return null}}function Yl(e,t,n){let r=t.length;if(e.length!==r+2)return-1;for(let n=0;n=r.length)continue;let s=r[o][n.contentKey];return{prompt:r.map(e=>Hl(e,n)).slice(0,o),chosen:[{role:`assistant`,content:a}],rejected:[{role:`assistant`,content:s}]}}}else if(n.kind===`flat`){let r=Ul(e,n.promptPath),i=Ul(e,n.responsePath),a=t[n.responsePath];if(a===void 0)return null;if(typeof r==`string`)return{prompt:r,chosen:a,rejected:i}}return null}var Zl=5e3;async function Ql(e,t,n){let{source:r,decisions:i,format:a,record:o,opts:s={}}=t,c=s.bom??`keep`,l=s.excludeUnparseable??!1,u=new Set;if(r.kind===`jsonl`)for(let e of r.index.unparseable)u.add(e);let d=e=>u.has(e),f={name:e,byteExact:!1,lineCount:0,pairsCount:0,editPairsCount:0,tiesExcluded:0,bothBadExcluded:0,implicitPromptCount:0,editsExported:0,unparseableExcluded:0,skippedUnparseable:0},p;switch(e){case`pairs.vertex.jsonl`:throw Error(`pairs.vertex.jsonl not implemented until WP 12`);case`pairs.jsonl`:case`pairs.edits.jsonl`:{let t=new Set;for(let[e,n]of i){(n.compare?.length||n.edits&&Object.keys(n.edits).length>0)&&t.add(Ue(e));for(let e of n.compare??[])t.add(Ue(e.left)),t.add(Ue(e.right))}let r=new Map,s=Array.from(t).sort((e,t)=>e-t);for(let e=0;esetTimeout(e,0)),n&&n(e,s.length))}let c=Wl(i,a,e=>r.get(e),l?d:void 0);f.tiesExcluded=c.excludedTies,f.bothBadExcluded=c.excludedBothBad,f.implicitPromptCount=c.implicitPromptCount,f.skippedUnparseable=c.skippedUnparseable,e===`pairs.jsonl`?(p=Vl(c.pairs),f.pairsCount=c.pairs.length,f.lineCount=c.pairs.length):(p=Vl(c.editPairs),f.editPairsCount=c.editPairs.length,f.lineCount=c.editPairs.length);break}case`all.decisions.jsonl`:p=await Bl(r,i,o,a,n,l?e=>!d(e)||(f.unparseableExcluded++,!1):void 0),f.lineCount=(r.kind===`jsonl`?r.index.lineCount:r.count)-f.unparseableExcluded;for(let e of i.values())e.edits&&Object.keys(e.edits).length>0&&f.editsExported++;break;case`kept.jsonl`:case`rejected.jsonl`:case`skipped.jsonl`:{let t=e.replace(`.jsonl`,``),a=(e,n)=>{if(l&&d(e))return f.unparseableExcluded++,!1;let r=n?.status===t;return r&&(f.lineCount++,n?.edits&&Object.keys(n.edits).length>0&&f.editsExported++),r};r.kind===`jsonl`?(f.byteExact=!0,p=await kl(r,i,a,{bom:c},n)):p=await jl(r,i,a,n);break}default:throw Error(`Unknown export name: ${e}`)}return n&&n(f.lineCount,f.lineCount),{blob:p,stats:f}}function $l(e,t,n,r,i={}){let a=t.kind===`jsonl`?t.index.lineCount:t.count,o=We(n),s=new Set([`kept.jsonl`,`rejected.jsonl`,`skipped.jsonl`]).has(e)&&t.kind===`jsonl`,c=0,l=0,u=0,d=new Set;if(t.kind===`jsonl`)for(let e of t.index.unparseable)d.add(e);if(e===`kept.jsonl`||e===`rejected.jsonl`||e===`skipped.jsonl`){let t=e.replace(`.jsonl`,``);for(let e=0;e0&&l++)}}else if(e===`all.decisions.jsonl`){c=a,i.excludeUnparseable&&(u=d.size,c-=u);for(let e of n.values())e.edits&&Object.keys(e.edits).length>0&&l++}let f=0,p=0,m=0,h=0;if(e===`pairs.jsonl`){for(let[,e]of n)for(let t of e.compare??[])t.preference===`tie`?p++:t.preference===`both_bad`?m++:f++;r.kind===`preference`&&!r.promptPath&&(h=f)}let g=0;if(e===`pairs.edits.jsonl`)for(let[,e]of n)e.edits&&Object.keys(e.edits).length>0&&g++;return{name:e,byteExact:s,lineCount:c,pairsCount:f,editPairsCount:g,tiesExcluded:p,bothBadExcluded:m,implicitPromptCount:h,editsExported:l,unparseableExcluded:u,skippedUnparseable:0}}function eu(e,t,n){return`${e.toLocaleString(`en-US`)} ${e===1?t:n}`}var tu=[`pairs.jsonl`,`pairs.edits.jsonl`,`kept.jsonl`,`rejected.jsonl`,`skipped.jsonl`,`all.decisions.jsonl`],nu=`a DPO row needs one chosen and one rejected completion for the same prompt. Strength is carried in all.decisions.jsonl only.`,q=`Edit pairs are off-policy: the chosen side was written by a person, not sampled from the model. DPO is sensitive to that distribution shift, and human-written chosen text can teach a length or style bias. Use them knowingly.`,ru=`Browser storage is best-effort: Safari deletes it after seven days without a visit. Download the session to keep it.`;function iu(e,t,n){switch(e){case`pairs.jsonl`:{let e=[`${eu(t.pairsCount,`pair`,`pairs`)}. ${eu(t.tiesExcluded,`tie`,`ties`)} and ${eu(t.bothBadExcluded,`both-unacceptable pair`,`both-unacceptable pairs`)} were left out: ${nu}`];return t.implicitPromptCount>0&&e.push(`${eu(t.implicitPromptCount,`row has no prompt field and uses`,`rows have no prompt field and use`)} TRL's implicit-prompt format.`),e.push(`Keep and Reject decisions alone never produce a preference pair.`),e}case`pairs.edits.jsonl`:return[`${eu(t.editPairsCount,`pair`,`pairs`)} from edits.`,q];case`all.decisions.jsonl`:return[`${eu(t.lineCount,`line`,`lines`)}.`,`Every record with its edits applied and its _triage decisions. Re-serialised; the original stays in the source file.`];default:return[`${eu(t.lineCount,`line`,`lines`)}.`,n?`Unedited lines are copied byte for byte, including line endings. Only the lines you edited are re-serialised.`:`Rows are re-serialised as JSONL.`]}}function au(e){let t=V(e=>e.fingerprint);return(0,H.jsx)(ou,{...e},t)}function ou({open:e,onOpenChange:t}){let n=V(e=>e.source),r=V(e=>e.decisions),i=V(e=>e.format),a=V(e=>e.session),o=V(e=>e.newerLocalCopy),s=V(e=>e.switching.kind===`opening`),[c,l]=(0,_.useState)(`keep`),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)({}),[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)(null),[y,b]=(0,_.useState)(null),x=y!==null&&a.kind===`refused`&&a.reason===`fingerprint-mismatch`&&a.request===y,S=(0,_.useRef)(null),C=n?.kind===`jsonl`,ee=n?.kind===`jsonl`&&n.index.hasBom,w=n?.kind===`jsonl`?n.index.unparseable.length:0,T=(0,_.useMemo)(()=>{if(!e||!n)return null;let t={};for(let e of tu)t[e]=$l(e,n,r,i,{excludeUnparseable:u});return t},[e,n,r,i,u]);(0,_.useEffect)(()=>{p({})},[r,i,c,u]);let E=async e=>{let t=V.getState();if(t.source){h(e),v(null);try{let n=await Ql(e,{source:t.source,decisions:t.decisions,format:t.format,record:t.record,opts:{bom:c,excludeUnparseable:u}});hl(n.blob,e),p(t=>({...t,[e]:n.stats}))}catch(e){v(`Export failed: ${e instanceof Error?e.message:String(e)}`)}finally{h(null)}}},D=async e=>{if(!e)return;let t=await e.text(),n={text:t,name:e.name};(0,ti.flushSync)(()=>b(n)),await V.getState().importSession(t,{name:e.name,request:n})};return(0,H.jsx)(hc,{open:e,onOpenChange:t,children:(0,H.jsxs)(vc,{className:`max-w-dialog-wide dialog-max overflow-y-auto`,children:[(0,H.jsxs)(yc,{children:[(0,H.jsx)(xc,{children:`Export`}),(0,H.jsx)(Sc,{children:`Downloads are written by your browser; nothing is uploaded.`})]}),(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 text-chrome`,children:[ee&&(0,H.jsx)(ir,{tone:`quiet`,word:`BOM present`}),(0,H.jsxs)(`fieldset`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(`legend`,{className:`sr-only`,children:`Byte order mark`}),(0,H.jsx)(`span`,{className:`text-neutral-11`,children:`BOM:`}),[`keep`,`strip`,`add`].map(e=>(0,H.jsxs)(`label`,{className:`flex items-center gap-1`,children:[(0,H.jsx)(`input`,{type:`radio`,name:`bom`,value:e,checked:c===e,onChange:()=>l(e)}),e]},e))]}),w>0&&(0,H.jsxs)(`label`,{className:`flex items-center gap-1`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:u,onChange:e=>d(e.target.checked)}),`Exclude `,eu(w,`unparseable line`,`unparseable lines`)]})]}),g&&(0,H.jsx)(ar,{children:g}),(0,H.jsx)(`div`,{className:`flex flex-col gap-3`,children:T&&tu.map(e=>{let t=f[e]??T[e];return(0,H.jsxs)(`section`,{"aria-label":e,className:`rounded-panel border border-neutral-6 p-3`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,H.jsx)(`h3`,{className:`font-mono text-mono font-semibold`,children:e}),(0,H.jsx)(Xs,{size:`sm`,variant:`secondary`,disabled:m!==null,onClick:()=>E(e),"aria-label":`Download ${e}`,children:m===e?`Exporting…`:`Download`})]}),iu(e,t,C).map(e=>(0,H.jsx)(`p`,{className:`text-chrome text-neutral-11 mt-1`,children:e},e))]},e)})}),(0,H.jsxs)(`section`,{"aria-label":`Session`,className:`rounded-panel border border-neutral-6 p-3 flex flex-col gap-2`,children:[(0,H.jsx)(`h3`,{className:`label text-neutral-11`,children:`Session`}),(0,H.jsx)(`p`,{className:`text-chrome text-neutral-11`,children:ru}),(0,H.jsxs)(`div`,{className:`flex gap-2`,children:[(0,H.jsx)(Xs,{size:`sm`,variant:`secondary`,onClick:gl,children:`Download session`}),(0,H.jsx)(Xs,{size:`sm`,variant:`secondary`,disabled:s,onClick:()=>S.current?.click(),children:`Load session`}),(0,H.jsx)(`input`,{ref:S,type:`file`,accept:`.json`,className:`hidden`,"aria-label":`Session file`,onChange:e=>{D(e.target.files?.[0]),e.target.value=``}})]}),a.kind===`refused`&&(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(ar,{children:a.message}),x&&(0,H.jsx)(Xs,{size:`sm`,variant:`secondary`,disabled:s,onClick:async()=>{y!==null&&await V.getState().importSession(y.text,{force:!0,name:y.name})},children:`Load anyway`})]}),o&&(0,H.jsxs)(`div`,{className:`text-chrome text-neutral-12 flex items-center gap-2`,children:[(0,H.jsxs)(`span`,{children:[`A newer copy saved in this browser at `,new Date(o.savedAt).toLocaleString(`en-US`),` `,`differs from the session file.`]}),(0,H.jsx)(Xs,{size:`sm`,variant:`secondary`,disabled:s,onClick:()=>V.getState().applyNewerLocalCopy(),children:`Use the newer copy`})]})]})]})})}function su({open:e,onOpenChange:t,candidateRef:n,focusField:r}){let[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(``),f=(0,_.useRef)(null),p=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(!e)return;let t=V.getState().decisions.get(n);a(t?.labels??[]),s(``),l(t?.score===void 0?``:String(t.score)),d(t?.notes??``)},[e,n]);let m=()=>{let e=o.trim();e&&!i.includes(e)&&a([...i,e]),s(``)},h=()=>{let e=V.getState(),r=e.decisions.get(n),a=o.trim(),s=a&&!i.includes(a)?[...i,a]:i,l=c.trim()===``?void 0:Number(c),d=u===``?void 0:u;(r?.labels??[]).join(`\0`)!==s.join(`\0`)&&e.setLabels(n,s),r?.score!==l&&!(l!==void 0&&Number.isNaN(l))&&e.setScore(n,l),r?.notes!==d&&e.setNotes(n,d),t(!1)};return(0,H.jsx)(hc,{open:e,onOpenChange:t,children:(0,H.jsxs)(vc,{className:`max-w-panel-md`,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),h())},onOpenAutoFocus:e=>{e.preventDefault(),(r===`notes`?p.current:f.current)?.focus()},children:[(0,H.jsxs)(yc,{children:[(0,H.jsx)(xc,{children:`Labels and notes`}),(0,H.jsxs)(Sc,{children:[`For `,n,`. Mod+Enter saves, Esc closes without saving.`]})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-3 text-chrome`,children:[(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`label text-neutral-11`,children:`Labels`}),(0,H.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:i.map(e=>(0,H.jsxs)(`span`,{className:`flex items-center gap-1 rounded-control bg-neutral-3 px-2 py-1 text-neutral-12`,children:[e,(0,H.jsx)(`button`,{type:`button`,className:`rounded-control px-1`,"aria-label":`Remove label ${e}`,onClick:()=>a(i.filter(t=>t!==e)),children:`×`})]},e))}),(0,H.jsx)(`input`,{ref:f,"aria-label":`Labels`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.metaKey&&!e.ctrlKey||e.key===`,`?(e.preventDefault(),m()):e.key===`Backspace`&&o===``&&i.length&&a(i.slice(0,-1))},className:`rounded-control border border-neutral-9 bg-neutral-1 px-2 py-1 text-chrome text-neutral-12`})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`label text-neutral-11`,children:`Score`}),(0,H.jsx)(`input`,{"aria-label":`Score`,type:`number`,value:c,onChange:e=>l(e.target.value),className:`w-score rounded-control border border-neutral-9 bg-neutral-1 px-2 py-1 text-chrome text-neutral-12`,"data-numeric":!0})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`label text-neutral-11`,children:`Notes`}),(0,H.jsx)(`textarea`,{ref:p,"aria-label":`Notes`,value:u,onChange:e=>d(e.target.value),className:`field-min-sm rounded-control border border-neutral-9 bg-neutral-1 px-2 py-1 text-content text-neutral-12`})]})]}),(0,H.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,H.jsx)(Xs,{variant:`secondary`,onClick:()=>t(!1),children:`Cancel`}),(0,H.jsx)(Xs,{onClick:h,children:`Save`})]})]})})}function cu({open:e,onOpenChange:t,mode:n,total:r}){let[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(null),c=n===`compare`?`Go to prompt`:`Go to record`,l=e=>{e||(a(``),s(null)),t(e)},u=()=>{let e=V.getState();if(i.trim()===``){e.nextUnreviewed(),l(!1);return}let t=Number(i);!Number.isInteger(t)||t<1||t>r?s(`Enter 1 to ${r.toLocaleString(`en-US`)}.`):(e.goTo(t-1),l(!1))};return(0,H.jsx)(hc,{open:e,onOpenChange:l,children:(0,H.jsxs)(vc,{className:`max-w-goto`,children:[(0,H.jsxs)(yc,{children:[(0,H.jsx)(xc,{children:c}),(0,H.jsx)(Sc,{children:`Enter on an empty field goes to the next unreviewed.`})]}),(0,H.jsx)(`input`,{"aria-label":n===`compare`?`Prompt number`:`Record number`,type:`number`,autoFocus:!0,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),u())},className:`rounded-control border border-neutral-9 bg-neutral-1 px-2 py-1 text-chrome text-neutral-12`,"data-numeric":!0}),o&&(0,H.jsx)(ar,{children:o})]})})}var lu=5e3;async function uu(e,t){let{index:n}=e,r=n.lineCount,i=t.query.toLowerCase();if(r===0||i===``)return{kind:`none`};let a,o;if(t.mode===`compare`){let e=t.cursor;a=n.groups.indexOf(e),a===-1&&(a=0),o=t=>n.groups[t]===e}else a=t.cursor,o=e=>e===t.cursor;let s=new TextDecoder,c=!1,l=[];a+1<=r-1&&l.push([a+1,r-1]),l.push([0,Math.min(a,r-1)]);for(let[r,a]of l)for(let l=r;l<=a;l+=lu){let r=Math.min(l+lu-1,a),u=new Uint8Array(await(await e.readRawRange(l,r)).arrayBuffer()),d=n.starts[l];for(let e=l;e<=r;e++)if(s.decode(u.subarray(n.starts[e]-d,n.ends[e]-d)).toLowerCase().includes(i)){if(o(e))c=!0;else return{kind:`match`,line:e}}if(await new Promise(e=>setTimeout(e,0)),t.isStale())return{kind:`stale`}}return c?{kind:`only-current`}:{kind:`none`}}function du({onClose:e}){let t=V(e=>e.cursor),[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!1),c=(0,_.useRef)(0);(0,_.useEffect)(()=>{c.current++},[t]),(0,_.useEffect)(()=>()=>{c.current++},[]);let l=async()=>{let{source:e,mode:t,cursor:r,goTo:i}=V.getState();if(!e||e.kind!==`jsonl`||n===``)return;let o=++c.current;s(!0),a(null);let l=await uu(e,{query:n,mode:t,cursor:r,isStale:()=>c.current!==o});s(!1),c.current===o&&(l.kind===`match`?i(t===`compare`?e.index.groups[l.line]:l.line):l.kind===`only-current`?a(t===`compare`?`Only match is in this prompt.`:`Only match is in this record.`):l.kind===`none`&&a(`No match.`))};return(0,H.jsxs)(`div`,{role:`search`,className:`flex items-center gap-2 border-b border-neutral-6 bg-neutral-2 px-4 py-2 text-chrome text-neutral-12 animate-panel`,children:[(0,H.jsx)(`input`,{"aria-label":`Search`,autoFocus:!0,value:n,onChange:e=>r(e.target.value),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),l()):t.key===`Escape`&&(t.preventDefault(),c.current++,e())},className:`w-panel rounded-control border border-neutral-9 bg-neutral-1 px-2 py-1 text-chrome text-neutral-12`}),(0,H.jsx)(`span`,{className:`text-neutral-11`,children:`Searches the file's raw text.`}),o&&(0,H.jsx)(`span`,{className:`text-neutral-11`,children:`Searching…`}),i&&(0,H.jsx)(`span`,{role:`status`,children:i})]})}var fu=[`shift`,`alt`,`meta`,`mod`,`ctrl`,`control`];function pu(){return typeof navigator>`u`?!1:/mac/i.test(navigator.userAgent)&&!/iphone|ipad|ipod/i.test(navigator.userAgent)}var mu={esc:`escape`,return:`enter`,left:`arrowleft`,right:`arrowright`,up:`arrowup`,down:`arrowdown`,ShiftLeft:`shift`,ShiftRight:`shift`,AltLeft:`alt`,AltRight:`alt`,MetaLeft:`meta`,MetaRight:`meta`,OSLeft:`meta`,OSRight:`meta`,ControlLeft:`ctrl`,ControlRight:`ctrl`};function hu(e){return(mu[e.trim()]||e.trim()).toLowerCase().replace(/key|digit|numpad/,``)}function gu(e){return fu.includes(e)}function _u(e,t=`,`){return e.toLowerCase().split(t)}function vu(e,t=`+`,n=`>`,r=!1,i,a){let o=[],s=!1;e=e.trim(),e.includes(n)?(s=!0,o=e.toLocaleLowerCase().split(n).map(e=>hu(e))):o=e.toLocaleLowerCase().split(t).map(e=>hu(e));let c={alt:o.includes(`alt`),ctrl:o.includes(`ctrl`)||o.includes(`control`),shift:o.includes(`shift`),meta:o.includes(`meta`),mod:o.includes(`mod`),useKey:r},l=o.filter(e=>!fu.includes(e));return{...c,keys:l,description:i,isSequence:s,hotkey:e,metadata:a}}typeof document<`u`&&(document.addEventListener(`keydown`,e=>{e.code!==void 0&&Su([hu(e.code)])}),document.addEventListener(`keyup`,e=>{e.code!==void 0&&Cu([hu(e.code)])})),typeof window<`u`&&(window.addEventListener(`blur`,()=>{yu.clear()}),window.addEventListener(`focus`,()=>{yu.clear()}),window.addEventListener(`contextmenu`,()=>{setTimeout(()=>{yu.clear()},0)})),typeof document<`u`&&document.addEventListener(`visibilitychange`,()=>{yu.clear()});var yu=new Set;function bu(e){return Array.isArray(e)}function xu(e,t=`,`){return(bu(e)?e:e.split(t)).every(e=>yu.has(e.trim().toLowerCase()))}function Su(e){let t=Array.isArray(e)?e:[e];yu.has(`meta`)&&yu.forEach(e=>{gu(e)||yu.delete(e.toLowerCase())}),t.forEach(e=>{yu.add(e.toLowerCase())})}function Cu(e){e===`meta`?yu.clear():(Array.isArray(e)?e:[e]).forEach(e=>{yu.delete(e.toLowerCase())})}function wu(e,t,n){(typeof n==`function`&&n(e,t)||n===!0)&&e.preventDefault()}function Tu(e,t,n){return typeof n==`function`?n(e,t):n===!0||n===void 0}var Eu=[`input`,`textarea`,`select`,`searchbox`,`slider`,`spinbutton`,`menuitem`,`menuitemcheckbox`,`menuitemradio`,`option`,`radio`,`textbox`];function Du(e){return Ou(e,Eu)}function Ou(e,t=!1){let{target:n,composed:r}=e,i,a;return ku(n)&&r?(i=e.composedPath()[0]&&e.composedPath()[0].tagName,a=e.composedPath()[0]&&e.composedPath()[0].role):(i=n&&n.tagName,a=n&&n.role),bu(t)?!!(i&&t?.some(e=>e.toLowerCase()===i.toLowerCase()||e===a)):!!(i&&t&&t)}function ku(e){return!!e.tagName&&!e.tagName.startsWith(`-`)&&e.tagName.includes(`-`)}function Au(e,t){return e.length===0&&t?!1:!t||e.some(e=>t.includes(e))||e.includes(`*`)}var ju=(e,t,n=!1)=>{let{alt:r,meta:i,mod:a,shift:o,ctrl:s,keys:c,useKey:l}=t,{code:u,key:d,ctrlKey:f,metaKey:p,shiftKey:m,altKey:h}=e,g=hu(u),_=typeof e.getModifierState==`function`&&e.getModifierState(`AltGraph`);if(!l&&!c?.includes(g)&&![`ctrl`,`control`,`unknown`,`meta`,`alt`,`shift`,`os`].includes(g))return!1;if(!n){if(r!==h&&g!==`alt`||o!==m&&g!==`shift`)return!1;if(a){if(pu()?!p:!f)return!1}else if(i!==p&&g!==`meta`&&g!==`os`||s!==f&&g!==`ctrl`&&g!==`control`)return!1;if(_&&!r&&!s&&!a&&![`alt`,`ctrl`,`control`].includes(g))return!1}return l&&c?.length===1&&c.includes(d.toLowerCase())||c&&c.length===1&&c.includes(g)?!0:c&&c.length>0?c.includes(g)?xu(c):!1:!c||c.length===0},Mu=(0,_.createContext)(void 0),Nu=()=>(0,_.useContext)(Mu);function Pu(e,t){return e&&t&&typeof e==`object`&&typeof t==`object`?Object.keys(e).length===Object.keys(t).length&&Object.keys(e).reduce((n,r)=>n&&Pu(e[r],t[r]),!0):e===t}var Fu=(0,_.createContext)({hotkeys:[],activeScopes:[],toggleScope:()=>{},enableScope:()=>{},disableScope:()=>{}}),Iu=()=>(0,_.useContext)(Fu);function Lu(e){let t=(0,_.useRef)(void 0);return Pu(t.current,e)||(t.current=e),t.current}var Ru=e=>{e.stopPropagation(),e.preventDefault(),e.stopImmediatePropagation()},zu=typeof window<`u`?_.useLayoutEffect:_.useEffect;function Bu(e){if(!e)return;let{enabled:t,preventDefault:n,ignoreEventWhen:r,...i}=e;return typeof t==`function`?i:{...i,enabled:t}}function J(e,t,n,r){let[i,a]=(0,_.useState)(null),o=(0,_.useCallback)(e=>(a(e),()=>a(null)),[]),s=(0,_.useRef)(!1),c=Array.isArray(n)?Array.isArray(r)?void 0:r:n,l=bu(e)?e.join(c?.delimiter):e,u=Array.isArray(n)?n:Array.isArray(r)?r:void 0,d=(0,_.useCallback)(t,u??[]),f=(0,_.useRef)(d);f.current=u?d:t;let p=Lu(Bu(c)),m=(0,_.useRef)(c?.enabled);m.current=c?.enabled;let h=(0,_.useRef)(c?.preventDefault);h.current=c?.preventDefault;let g=(0,_.useRef)(c?.ignoreEventWhen);g.current=c?.ignoreEventWhen;let{activeScopes:v}=Iu(),y=Nu();return zu(()=>{if(m.current===!1||!Au(v,p?.scopes))return;let e=[],t,n=(n,r=!1)=>{if(!Du(n)||Ou(n,p?.enableOnFormTags)){if(i!==null){let e=i.getRootNode();if((e instanceof Document||e instanceof ShadowRoot)&&e.activeElement!==i&&!i.contains(e.activeElement)){Ru(n);return}}n.target?.isContentEditable&&!p?.enableOnContentEditable||_u(l,p?.delimiter).forEach(i=>{if(i.includes(p?.splitKey??`+`)&&i.includes(p?.sequenceSplitKey??`>`)){console.warn(`Hotkey ${i} contains both ${p?.splitKey??`+`} and ${p?.sequenceSplitKey??`>`} which is not supported.`);return}let a=vu(i,p?.splitKey,p?.sequenceSplitKey,p?.useKey,p?.description,p?.metadata);if(a.isSequence){t=setTimeout(()=>{e=[]},p?.sequenceTimeoutMs??1e3);let r=a.useKey?n.key:hu(n.code);if(gu(r.toLowerCase()))return;if(e.push(r),r!==a.keys?.[e.length-1]){e=[],t&&clearTimeout(t);return}e.length===a.keys?.length&&(f.current(n,a),t&&clearTimeout(t),e=[])}else if(ju(n,a,p?.ignoreModifiers)||a.keys?.includes(`*`)){if(g.current?.(n)||r&&s.current||(wu(n,a,h.current),!Tu(n,a,m.current)))return;f.current(n,a),r||(s.current=!0)}})}},r=e=>{e.code!==void 0&&(Su(hu(e.code)),(p?.keydown===void 0&&p?.keyup!==!0||p?.keydown)&&n(e))},a=e=>{e.code!==void 0&&(Cu(hu(e.code)),s.current=!1,p?.keyup&&n(e,!0))},o=i||c?.document||document;return o.addEventListener(`keyup`,a,c?.eventListenerOptions),o.addEventListener(`keydown`,r,c?.eventListenerOptions),y&&_u(l,p?.delimiter).forEach(e=>{y.addHotkey(vu(e,p?.splitKey,p?.sequenceSplitKey,p?.useKey,p?.description,p?.metadata))}),()=>{o.removeEventListener(`keyup`,a,c?.eventListenerOptions),o.removeEventListener(`keydown`,r,c?.eventListenerOptions),y&&_u(l,p?.delimiter).forEach(e=>{y.removeHotkey(vu(e,p?.splitKey,p?.sequenceSplitKey,p?.useKey,p?.description,p?.metadata))}),e=[],t&&clearTimeout(t)}},[i,p,v,l]),o}function Vu(e){let{prefer:t,setStrength:n,decide:r,getFocusedRef:i,next:a,prev:o,toggleFocus:s,openEditor:c,saveEditor:l,cancelEditor:u,editConfirmKeep:d,editConfirmDiscard:f,isEditConfirmOpen:p,undo:m,redo:h,toggleRaw:g,toggleWhitespace:v,toggleReadingStep:y,cycleFilter:b,showCheatSheet:x,scrollUp:S,scrollDown:C,toggleMetadata:ee,openLabels:w,openNotes:T,openGoTo:E,openSearch:D,mode:O,groupSize:k,isModalOpen:A,isEditorOpen:j,isEditPending:te=!1}=e,M=(0,_.useCallback)(e=>!A&&!!(e.modes.includes(`both`)||e.modes.includes(O)),[A,O]);J(`left`,()=>{p?f():M(wc[0])&&(k<=1||t(`left`))},{enableOnFormTags:!1}),J(`1`,()=>{p||M(wc[0])&&(k<=1||t(`left`))},{enableOnFormTags:!1,useKey:!0}),J(`right`,()=>{p?d():M(wc[1])&&(k<=1||t(`right`))},{enableOnFormTags:!1}),J(`2`,()=>{p||M(wc[1])&&(k<=1||t(`right`))},{enableOnFormTags:!1,useKey:!0}),J(`=, 0`,()=>{M(wc[2])&&(k<=1||t(`tie`))},{enableOnFormTags:!1,useKey:!0}),J(`x`,()=>{M(wc[3])&&(k<=1||t(`both_bad`))},{enableOnFormTags:!1,useKey:!0}),J(`shift+1`,()=>{M(wc[4])&&n(1)},{enableOnFormTags:!1}),J(`shift+2`,()=>{M(wc[5])&&n(2)},{enableOnFormTags:!1}),J(`shift+3`,()=>{M(wc[6])&&n(3)},{enableOnFormTags:!1}),J(`a`,()=>{A||r(i(),`kept`)},{enableOnFormTags:!1,useKey:!0}),J(`r`,()=>{A||r(i(),`rejected`)},{enableOnFormTags:!1,useKey:!0}),J(`s`,()=>{A||r(i(),`skipped`)},{enableOnFormTags:!1,useKey:!0}),J(`tab`,e=>{A||O!==`compare`||(e.preventDefault(),s())},{enableOnFormTags:!1}),J(`j`,()=>{A||a()},{enableOnFormTags:!1,useKey:!0}),J(`k`,()=>{A||o()},{enableOnFormTags:!1,useKey:!0}),J(`up`,()=>{A||S()},{enableOnFormTags:!1}),J(`down`,()=>{A||C()},{enableOnFormTags:!1}),J(`e`,e=>{A||(e.preventDefault(),c())},{enableOnFormTags:!1,useKey:!0}),J(`mod+enter`,()=>{j&&l()},{enableOnFormTags:[`textarea`]}),J(`escape`,()=>{(j||p||te)&&u()},{enableOnFormTags:[`textarea`]}),J(`u`,()=>{A||m()},{enableOnFormTags:!1,useKey:!0}),J(`shift+u`,()=>{A||h()},{enableOnFormTags:!1}),J(`t`,()=>{A||g()},{enableOnFormTags:!1,useKey:!0}),J(`w`,()=>{A||v()},{enableOnFormTags:!1,useKey:!0}),J(`z`,()=>{A||y()},{enableOnFormTags:!1,useKey:!0}),J(`f`,()=>{A||b()},{enableOnFormTags:!1,useKey:!0}),J(`shift+?`,()=>{A||x()},{enableOnFormTags:!1,useKey:!0}),J(`m`,()=>{A||ee?.()},{enableOnFormTags:!1,useKey:!0}),J(`l`,e=>{A||(e.preventDefault(),w?.())},{enableOnFormTags:!1,useKey:!0}),J(`n`,e=>{A||(e.preventDefault(),T?.())},{enableOnFormTags:!1,useKey:!0}),J(`g`,e=>{A||(e.preventDefault(),E?.())},{enableOnFormTags:!1,useKey:!0}),J(`/`,e=>{A||(e.preventDefault(),D?.())},{enableOnFormTags:!1,useKey:!0})}function Hu(e,t){if(t.kind!==`messages`)return[];let n=Yn(e,Kn(t.path));if(!Array.isArray(n))return[];let r=[];return n.forEach((e,n)=>{let i=e&&typeof e==`object`?e[t.roleKey]:void 0;typeof i==`string`&&t.roles.assistant.includes(i)&&r.push(n)}),r}function Uu(e,t){return Zn(Jn(Kn(e),e=>{let n=Yn(t,e);return Array.isArray(n)?n.length:0}))}function Wu(e,t){return`${e.path}[${t}].${e.contentKey}`}function Gu(e,t,n){let r=e.indexOf(`:`),i=r===-1?null:parseInt(e.slice(r+1),10);switch(t.kind){case`flat`:return t.responsePath;case`messages`:{let e=Hu(n,t);return e.length?Wu(t,e[e.length-1]):null}case`preference`:return i===1?t.rejectedPath:t.chosenPath;case`candidates`:return`${t.candidatesPath}[${i??0}]`;default:return null}}var Ku=[`all`,`unreviewed`,`kept`,`rejected`,`skipped`,`edited`,`unparseable`];function qu(e,t,n){return!e||!n?null:e.fingerprint===t&&e.line===Ue(n)?e:null}function Ju(){let e=V(e=>e.source),t=V(e=>e.format),n=V(e=>e.mode),r=V(e=>e.cursor),i=V(e=>e.focus),a=V(e=>e.decisions),o=V(e=>e.filter),s=V(e=>e.prefer),c=V(e=>e.setStrength),l=V(e=>e.decide),u=V(e=>e.edit),d=V(e=>e.undo),f=V(e=>e.redo),p=V(e=>e.next),m=V(e=>e.prev),h=V(e=>e.toggleFocus),g=V(e=>e.setFilter),v=V(e=>e.setFormat),y=V(e=>e.record),[b,x]=(0,_.useState)(!1),[S,C]=(0,_.useState)(!1),[ee,w]=(0,_.useState)(!1);(0,_.useEffect)(()=>{let e=document.documentElement;return ee?e.setAttribute(`data-reading-step`,``):e.removeAttribute(`data-reading-step`),()=>e.removeAttribute(`data-reading-step`)},[ee]);let[T,E]=(0,_.useState)(!1),[D,O]=(0,_.useState)(!1),[k,A]=(0,_.useState)(!1),j=(0,_.useRef)(null),[te,M]=(0,_.useState)(!1),[N,ne]=(0,_.useState)(null),[re,P]=(0,_.useState)(null),[F,ie]=(0,_.useState)(null),[ae,oe]=(0,_.useState)(null),[se,ce]=(0,_.useState)(null),[le,ue]=(0,_.useState)(null),[de,fe]=(0,_.useState)(null),pe=V(e=>e.storageState),me=V(e=>e.sourceName),I=V(e=>e.counts),[L,he]=(0,_.useState)(!1),[ge,_e]=(0,_.useState)(null),[ve,ye]=(0,_.useState)(!1),[R,be]=(0,_.useState)(!1),[xe,Se]=(0,_.useState)(!1),[Ce,we]=(0,_.useState)(!1),Te=V(e=>e.switching.kind===`opening`),Ee=V(e=>e.fingerprint);(0,_.useEffect)(()=>{ne(null),ie(null),P(null),_e(null),ye(!1),be(!1),O(!1)},[Ee]);let De=e?.kind===`jsonl`?e.index:null,Oe=De?.groups,ke=De?.groupCount??0,Ae=De?.candidates,Me=(0,_.useMemo)(()=>Oe?Fe(Oe,ke):null,[Oe,ke]),Ne=(0,_.useMemo)(()=>n!==`compare`||!Me||!Ae||r>=ke?null:Le(Me,Ae,t,r),[n,Me,Ae,ke,t,r]),Ie=(0,_.useMemo)(()=>Ne?ze(Ne.candidates,a.get(Ne.promptRef)?.compare):null,[Ne,a]),Re=Ne?.candidates.length??0,z=n===`single`||Re<2,Be=n===`compare`?Re:1,Ve=e?n===`single`?He(r):Ne?Ie?.shown?.left??Ne.candidates[0]??Ne.promptRef:``:``,We=!z&&Ie?.shown?Ie.shown.right:``,Ge=qu(le,Ee,Ve),Ke=qu(de,Ee,We),qe=Ge?.record??null,Je=Ke?.record??null,Ye=Ge?.text??``,Xe=Ke?.text??``;(0,_.useEffect)(()=>{if(!e||e.kind!==`jsonl`||!Ve)return;let t=!1,n=Ee;return(async()=>{try{let r=Ue(Ve),i=await y(r),a=await e.readText(r);if(t)return;if(ue({fingerprint:n,line:r,record:i,text:a}),We){let r=Ue(We),i=await y(r),a=await e.readText(r);if(t)return;fe({fingerprint:n,line:r,record:i,text:a})}else fe(null);ce(null)}catch(e){if(t)return;ce(`Failed to load records: ${e instanceof Error?e.message:String(e)}`)}})(),()=>{t=!0}},[e,Ee,Ve,We,y]),(0,_.useEffect)(()=>{e&&t.kind===`unknown`&&j.current!==Ee&&(j.current=Ee,O(!0))},[e,t.kind,Ee]),(0,_.useEffect)(()=>{D||A(!1)},[D]),(0,_.useEffect)(()=>{x(t.kind===`unknown`)},[t.kind]);let Ze=(0,_.useMemo)(()=>a.get(Ve)?.edits,[a,Ve]),Qe=(0,_.useMemo)(()=>a.get(We)?.edits,[a,We]),$e=(0,_.useCallback)(()=>z||i===0?Ve:We,[z,i,Ve,We]),et=(0,_.useCallback)((e,t,n)=>{try{let r=Uu(t,n),i=a.get(e)?.edits,o=i&&Object.prototype.hasOwnProperty.call(i,r)?i[r]:Yn(n,Kn(r)),s=o!==void 0&&typeof o!=`string`;ne({ref:e,path:r,initialValue:s?je(o)??``:o??``,isJson:s,data:n}),P(null),ce(null)}catch(e){ce(`Failed to open editor: ${e instanceof Error?e.message:String(e)}`)}},[a]),tt=(0,_.useCallback)(()=>{let e=i===0||z?qe:Je;if(!qe||!e){oe({fingerprint:Ee,cursor:r,focus:i});return}if(!qe.ok||!e.ok)return;let n=$e(),a=Gu(n,t,e.data);a===null?t.kind===`messages`&&ce(`No assistant turn to edit.`):et(n,a,e.data)},[qe,Je,i,z,t,$e,et,Ee,r]),nt=(0,_.useCallback)(()=>{},[N]),rt=(0,_.useCallback)(()=>{ne(null),ie(null),P(null),oe(null)},[]),it=D||T||ge!==null||ve||xe||Ce||Te;(0,_.useEffect)(()=>{ae&&(ae.fingerprint!==Ee||ae.cursor!==r||ae.focus!==i||it?oe(null):qe&&(i===0||z?qe:Je)&&(oe(null),tt()))},[ae,Ee,r,i,it,z,qe,Je,tt]),(0,_.useEffect)(()=>{oe(null)},[a]);let at=(0,_.useCallback)(e=>{if(N)try{let t=N.path,n=e;if(N.isJson)try{n=Pe(e)}catch{P(`Not valid JSON: not saved.`);return}let r=a.get(N.ref)?.edits,i=r&&Object.prototype.hasOwnProperty.call(r,t)?{value:r[t]}:null;u(N.ref,t,n),ie({ref:N.ref,path:t,originalValue:N.initialValue,previous:i}),ne(null),P(null),ce(null)}catch(e){ce(`Failed to save edit: ${e instanceof Error?e.message:String(e)}`)}},[N,u,a]),ot=(0,_.useCallback)(()=>{ie(null)},[]),st=(0,_.useCallback)(()=>{F&&(u(F.ref,F.path,F.previous?F.previous.value:void 0),ie(null))},[F,u]),ct=e=>{let t=document.querySelector(`[role="group"][aria-current="true"] [data-card-content]`);t&&(t.scrollTop+=e)},lt=(0,_.useCallback)(()=>ct(-40),[]),ut=(0,_.useCallback)(()=>ct(40),[]),dt=(0,_.useCallback)(()=>{let e=(Ku.indexOf(o)+1)%Ku.length;g(Ku[e])},[o,g]),ft=(0,_.useCallback)(()=>{E(e=>!e)},[]),pt=(0,_.useCallback)(async e=>{M(!0);try{await v(e)}finally{M(!1)}},[v]),mt=(0,_.useCallback)((e,t)=>{if(Te)return;let n=e===Ve?qe:e===We?Je:null;n&&n.ok&&et(e,t,n.data)},[Te,qe,Je,Ve,We,et]),[ht,gt]=(0,_.useState)([]);if((0,_.useEffect)(()=>{if(!D||!e||e.kind!==`jsonl`)return;let t=!1;return(async()=>{let n=[],r=Math.min(e.index.lineCount,1e3);for(let e=0;e{t=!0}},[D,e,y]),Vu({prefer:s,setStrength:c,decide:l,getFocusedRef:$e,next:p,prev:m,toggleFocus:h,openEditor:tt,saveEditor:nt,cancelEditor:rt,editConfirmKeep:ot,editConfirmDiscard:st,isEditConfirmOpen:F!==null,undo:d,redo:f,toggleRaw:()=>x(e=>!e),toggleWhitespace:()=>C(e=>!e),toggleReadingStep:()=>w(e=>!e),cycleFilter:dt,showCheatSheet:ft,scrollUp:lt,scrollDown:ut,toggleMetadata:()=>he(e=>!e),openLabels:()=>_e(`labels`),openNotes:()=>_e(`notes`),openGoTo:()=>ye(!0),openSearch:()=>be(!0),mode:n,groupSize:Be,isModalOpen:N!==null||F!==null||D||T||ge!==null||ve||xe||Ce||Te,isEditorOpen:N!==null,isEditPending:ae!==null}),!e)return(0,H.jsx)(fl,{loaded:!1});let _t=N||F?`Save or cancel the edit first.`:ge===null?D&&k?`Apply or cancel the format first.`:null:`Save or cancel the labels and notes first.`,vt=(0,H.jsx)(fl,{loaded:!0,onConfirmOpenChange:we,blockedReason:_t}),yt=(0,H.jsx)(dl,{side:`top`,className:`fixed top-2 right-4 rounded-panel bg-neutral-1 px-2 py-1`,children:(0,H.jsx)(vl,{state:pe,blockedReason:_t})}),bt=(e,t)=>(0,H.jsxs)(H.Fragment,{children:[e,t?yt:null,vt]});if(e.kind!==`jsonl`)return bt((0,H.jsxs)(`div`,{className:`min-h-screen bg-neutral-1 text-neutral-12 flex flex-col items-center justify-center gap-4`,children:[(0,H.jsx)(`h1`,{className:`text-heading font-semibold`,children:`evalcull`}),(0,H.jsxs)(`p`,{className:`text-chrome text-neutral-11`,children:[e.container,` files are not supported yet`]})]}),!0);if(te)return bt((0,H.jsx)(`div`,{className:`min-h-screen bg-neutral-1 text-neutral-12 flex items-center justify-center`,children:(0,H.jsx)(`p`,{role:`status`,className:`text-chrome text-neutral-11`,children:`Re-grouping records...`})}),!0);if(N){let e;if(t.kind===`messages`){let n=Hu(N.data,t),r=n.findIndex(e=>Uu(Wu(t,e),N.data)===N.path);if(r!==-1){let i=e=>{e>=0&&ei(r-1),onNext:()=>i(r+1)}}}return bt((0,H.jsx)(`div`,{"data-screen":`editor`,className:`min-h-screen bg-neutral-1 text-neutral-12 p-8`,children:(0,H.jsxs)(`div`,{className:`max-w-column mx-auto`,children:[(0,H.jsxs)(`h2`,{className:`text-heading font-semibold mb-4`,children:[`Editing `,N.ref]}),(0,H.jsxs)(`p`,{className:`text-chrome text-neutral-11 mb-4`,children:[`Path: `,(0,H.jsx)(`code`,{className:`font-mono text-mono`,children:N.path})]}),(0,H.jsx)(Er,{initialValue:N.initialValue,onSave:at,onCancel:rt,error:re,turnSwitch:e},`${N.ref} ${N.path}`)]})}),!0)}if(F){let e=(a.get(F.ref)?.edits??{})[F.path];return bt((0,H.jsx)(H.Fragment,{children:(0,H.jsx)(Qs,{originalValue:F.originalValue,editedValue:Qn(e),onKeep:ot,onDiscard:st,onDismiss:rt})}),!0)}return bt((0,H.jsxs)(`div`,{"data-screen":n,className:`min-h-screen bg-neutral-1 text-neutral-12`,children:[(0,H.jsxs)(`header`,{className:`border-b border-neutral-6 px-4 py-2 text-chrome`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,H.jsx)(`h1`,{className:`font-semibold`,children:`evalcull`}),(0,H.jsx)(`span`,{className:`text-neutral-12`,children:me}),(0,H.jsx)(ml,{counts:I(),mode:n}),(0,H.jsx)(vl,{state:pe,blockedReason:_t}),(0,H.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,H.jsxs)(`span`,{className:`text-neutral-11`,children:[`Filter: `,o]}),(0,H.jsx)(Xs,{variant:`secondary`,size:`sm`,disabled:Te,onClick:()=>O(!0),children:`Configure format`}),(0,H.jsx)(Xs,{variant:`secondary`,size:`sm`,onClick:()=>Se(!0),children:`Export`})]})]}),se&&(0,H.jsx)(ar,{className:`mt-1`,children:se})]}),R&&(0,H.jsx)(du,{onClose:()=>be(!1)}),(0,H.jsxs)(`main`,{className:`p-4`,children:[(0,H.jsx)(`div`,{className:`max-w-page mx-auto`,children:(0,H.jsx)(Kc,{record:qe,format:t,showWhitespace:S})}),n===`compare`?qe&&(z||Je)?z||!Ie?(0,H.jsxs)(`div`,{className:`max-w-column mx-auto`,children:[(0,H.jsx)(`div`,{className:`text-center text-chrome text-neutral-11 mb-4`,children:`Only one candidate for this prompt`}),(0,H.jsx)(Tr,{record:qe,rawText:Ye,candidateRef:Ve,format:t,showRaw:b,showWhitespace:S,edits:Ze,onEdit:e=>mt(Ve,e),status:a.get(Ve)?.status})]}):(0,H.jsx)(wr,{leftRecord:qe,rightRecord:Je,leftRef:Ve,rightRef:We,leftText:Ye,rightText:Xe,leftEdits:Ze,rightEdits:Qe,focus:i,format:t,showRaw:b,showWhitespace:S,knockout:Ie,candidateCount:Re,onEdit:mt,leftStatus:a.get(Ve)?.status,rightStatus:a.get(We)?.status}):(0,H.jsx)(`div`,{className:`text-center text-chrome text-neutral-11`,children:`Loading...`}):qe?(0,H.jsx)(Tr,{record:qe,rawText:Ye,candidateRef:Ve,format:t,showRaw:b,showWhitespace:S,edits:Ze,onEdit:e=>mt(Ve,e),status:a.get(Ve)?.status}):(0,H.jsx)(`div`,{className:`text-center text-chrome text-neutral-11`,children:`Loading...`}),(0,H.jsx)(`div`,{className:`mt-4 text-center text-chrome text-neutral-11`,"data-numeric":!0,children:n===`compare`?`Prompt ${r+1} of ${e.index.groupCount}`:`Record ${r+1} of ${e.index.lineCount}`}),L&&(0,H.jsx)(`div`,{className:`max-w-page mx-auto`,children:(0,H.jsx)(Tl,{record:!z&&i===1?Je:qe,format:t})})]}),(0,H.jsx)(au,{open:xe,onOpenChange:Se}),(0,H.jsx)(su,{open:ge!==null,onOpenChange:e=>!e&&_e(null),candidateRef:$e(),focusField:ge??`labels`}),(0,H.jsx)(cu,{open:ve,onOpenChange:ye,mode:n,total:n===`compare`?e.index.groupCount:e.index.lineCount}),(0,H.jsx)(Ec,{open:T,onOpenChange:E}),(0,H.jsx)(Gc,{open:D,onOpenChange:O,onDraftChange:()=>A(!0),currentFormat:t,sampleRecords:ht,onApply:pt},Ee)]}),!1)}(0,v.createRoot)(document.getElementById(`root`)).render((0,H.jsx)(_.StrictMode,{children:(0,H.jsx)(Ju,{})}));