evals-lab 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +0,0 @@
1
- import{A as e,B as t,C as n,D as r,E as i,F as a,G as o,H as s,I as c,J as l,K as u,L as d,M as f,N as p,O as m,P as h,R as g,S as _,T as v,U as y,V as b,W as x,X as S,Y as C,_ as w,a as T,b as E,c as D,d as O,f as k,g as A,h as j,i as M,j as N,k as P,l as F,m as ee,n as I,o as te,p as L,q as R,r as z,s as B,t as V,u as H,v as U,w as W,x as ne,y as G,z as K}from"./tokens-B9intIuT.js";var re=C(),q=S(),ie=(0,q.createContext)(null);function J(){let e=(0,q.useContext)(ie);if(!e)throw Error(`useApi outside an ApiContext: main.tsx mounts one at the root`);return e}var ae=`modulepreload`,oe=function(e){return`/`+e},se={},ce=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=oe(t,n),t=s(t),t in se)return;se[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:ae,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},le={},ue=new Set,Y=e=>`/plugins/${encodeURIComponent(e.id)}/${encodeURIComponent(e.version)}/${e.entry.split(`/`).map(encodeURIComponent).join(`/`)}`;async function de(e){if(!ue.has(e.id))try{let t=await ce(()=>import(Y(e)),[]);if(typeof t.default!=`function`)throw Error(`its entry exports no register function`);await t.default(K().pluginHost(e.id)),ue.add(e.id),delete le[e.id]}catch(t){le[e.id]=t instanceof Error?t.message:String(t)}}async function fe(e){let t=[];try{t=(await e.plugins()).plugins}catch{return}for(let e of t)await de(e)}var pe=class extends Error{status;body;constructor(e,t,n=null){super(t),this.name=`ApiError`,this.status=e,this.body=n}};function me(e=(...e)=>fetch(...e)){async function t(e){let t=await e.text(),n=t;try{n=t?JSON.parse(t):null}catch{}if(!e.ok){let t=n&&typeof n==`object`&&`error`in n?n.error:null,r=typeof t==`string`?t:t&&typeof t==`object`&&typeof t.message==`string`?`${t.type?`${t.type}: `:``}${t.message}`:t==null?``:JSON.stringify(t);throw new pe(e.status,r||`HTTP ${e.status}`,n)}return n}async function n(n,r){return t(await e(n,r?.body===void 0?{method:r?.method??`GET`}:{method:r.method??`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(r.body),...r.keepalive?{keepalive:!0}:{}}))}let r=e=>({...e,snapshot:K().upgradePipeline(e.snapshot),results:K().upgradeResults(e.results)}),i=async e=>{let t=await e;return{...t,run:r(t.run)}};return{config:()=>n(`/api/config`),state:()=>n(`/api/state`),writeState:(e,t=!1)=>n(`/api/state`,{body:{docs:e},keepalive:t}),queue:(e={})=>{let t=new URLSearchParams;return e.limit&&t.set(`limit`,String(e.limit)),e.before&&t.set(`before`,e.before),n(`/api/queue${t.size?`?${t}`:``}`).then(e=>({...e,runs:e.runs.map(r)}))},run:e=>n(`/api/queue/${encodeURIComponent(e)}`).then(r),setComment:(e,t)=>n(`/api/queue/${encodeURIComponent(e)}`,{method:`PATCH`,body:{comment:t}}).then(r),submit:e=>i(n(`/api/queue`,{body:e})),cancel:e=>i(n(`/api/queue/${encodeURIComponent(e)}/cancel`,{body:{}})),resume:e=>i(n(`/api/queue/${encodeURIComponent(e)}/resume`,{body:{}})),rerun:(e,t)=>i(n(`/api/queue/${encodeURIComponent(e)}/items/${t}`,{body:{}})),rescore:(e,t)=>i(n(`/api/queue/${encodeURIComponent(e)}/rescore/${t}`,{body:{}})),clear:()=>n(`/api/queue`,{method:`DELETE`}),sources:()=>n(`/api/sources`),source:e=>n(`/api/sources/${encodeURIComponent(e)}`),datasets:()=>n(`/api/datasets`),dataset:e=>n(`/api/datasets/${encodeURIComponent(e)}`),archivedRules:()=>n(`/api/datasets/archived-rules`),createDataset:e=>n(`/api/datasets`,{body:e}),renameDataset:(e,t)=>n(`/api/datasets/${encodeURIComponent(e)}`,{method:`PATCH`,body:{name:t}}),saveDataset:(e,t,r)=>n(`/api/datasets/${encodeURIComponent(e)}`,{method:`PUT`,body:{version:t,body:r}}),deleteDataset:e=>n(`/api/datasets/${encodeURIComponent(e)}`,{method:`DELETE`}),restoreDataset:e=>n(`/api/datasets/trash/${encodeURIComponent(e)}/restore`,{body:{}}),exportDatasetUrl:e=>`/api/datasets/${encodeURIComponent(e)}/export`,exportAllDatasetsUrl:()=>`/api/datasets/export`,importDatasets:e=>n(`/api/datasets/import`,{body:e}),runDataset:e=>n(`/api/queue/${encodeURIComponent(e)}/dataset`),prompts:()=>n(`/api/prompts`),prompt:e=>n(`/api/prompts/${encodeURIComponent(e)}`),createPrompt:e=>n(`/api/prompts`,{body:e}),editPrompt:(e,t,r)=>n(`/api/prompts/${encodeURIComponent(e)}`,{method:`PUT`,body:{base:t,...r}}),setDefaultPrompt:e=>n(`/api/prompts/${encodeURIComponent(e)}/default`,{body:{}}),restorePromptVersion:(e,t)=>n(`/api/prompts/${encodeURIComponent(e)}/versions/${t}/restore`,{body:{}}),deletePrompt:e=>n(`/api/prompts/${encodeURIComponent(e)}`,{method:`DELETE`}),restorePrompt:e=>n(`/api/prompts/trash/${encodeURIComponent(e)}/restore`,{body:{}}),createSource:(e,t,r)=>n(`/api/sources`,{body:{name:e,type:t,...r?{config:r}:{}}}),definition:e=>n(`/api/sources/${encodeURIComponent(e)}/definition`),saveDefinition:(e,t,r)=>n(`/api/sources/${encodeURIComponent(e)}/definition`,{method:`PUT`,body:{version:t,body:r}}),renameSource:(e,t)=>n(`/api/sources/${encodeURIComponent(e)}`,{method:`PATCH`,body:{name:t}}),removeSource:e=>n(`/api/sources/${encodeURIComponent(e)}`,{method:`DELETE`}),removeFiles:(e,t)=>n(`/api/sources/${encodeURIComponent(e)}/remove`,{body:{names:t}}),restoreTrash:e=>n(`/api/sources/trash/${encodeURIComponent(e)}/restore`,{body:{}}),copyFiles:(e,t,r,i=!1)=>n(`/api/sources/${encodeURIComponent(e)}/copy`,{body:{from:t,names:r,move:i}}),upload:async(n,r,i)=>t(await e(`/api/sources/${encodeURIComponent(n)}`,{method:`POST`,headers:{"X-File-Name":r},body:i})),zip:async(n,r)=>{let i=await e(`/api/sources/${encodeURIComponent(n)}/zip`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({names:r})});return i.ok||await t(i),i.blob()},file:async(n,r)=>{let i=await e(`/api/sources/${encodeURIComponent(n)}/files/${encodeURIComponent(r)}`);return i.ok||await t(i),i.blob()},samples:()=>n(`/api/samples`),presets:()=>n(`/api/presets`),plugins:()=>n(`/api/plugins`),installPlugin:async n=>t(await e(`/api/plugins`,{method:`POST`,headers:{"Content-Type":`application/zip`},body:n})),removePlugin:e=>n(`/api/plugins/${encodeURIComponent(e)}`,{method:`DELETE`}),restorePlugin:e=>n(`/api/plugins/trash/${encodeURIComponent(e)}/restore`,{body:{}}),connections:()=>n(`/api/connections`),signIn:e=>n(`/api/connections/${encodeURIComponent(e)}/start`,{body:{}}),signOut:e=>n(`/api/connections/${encodeURIComponent(e)}`,{method:`DELETE`}),packs:()=>n(`/api/packs`),installPack:async n=>t(await e(`/api/packs`,{method:`POST`,headers:{"Content-Type":`application/zip`},body:n})),removePack:e=>n(`/api/packs/${encodeURIComponent(e)}`,{method:`DELETE`}),restorePack:e=>n(`/api/packs/trash/${encodeURIComponent(e)}/restore`,{body:{}}),models:e=>n(`/api/models`,{body:e}),modelsAsk:e=>n(`/api/models/ask`,{body:e})}}var he=(0,q.createContext)(null);function ge(){let e=(0,q.useContext)(he);if(!e)throw Error(`useStore outside a StoreContext: the app mounts one at its root`);return e}function _e(e){let t=ge();return[(0,q.useSyncExternalStore)(t.subscribe,()=>t.get(e)),(0,q.useCallback)(n=>t.set(e,n),[t,e])]}function ve(){let e=ge();return{sync:(0,q.useSyncExternalStore)(e.subscribe,e.sync),resolve:e.resolve}}var ye=e=>e,be=e=>e?.state===`conflict`?`Not saved: changed in another browser.`:e?.state===`offline`?`Not saved: ${e.message}`:null,xe=(e,t)=>JSON.stringify(e)===JSON.stringify(t),Se=e=>e instanceof Error?e.message:String(e),Ce=({body:e,...t})=>t;function we({api:e,pause:t=800,idle:n}){let r=ye(e),i={list:null,error:null},a=new Map,o=new Set,s=new Map,c=new Map,l=new Map,u=new Set,d=null,f=()=>{d=null,u.forEach(e=>e())},p=(e,t)=>{let n=a.get(e)??{id:e,doc:null,sync:{state:`loading`}};a.set(e,{...n,...t,id:e}),f()},m=e=>{i={list:e,error:null},f()},h=e=>{if(!i.list)return;let t=i.list.findIndex(t=>t.id===e.id);m(t<0?[...i.list,e]:i.list.map((n,r)=>r===t?e:n))},g=e=>{for(let t of[s,c]){let n=t.get(e);n&&clearTimeout(n),t.delete(e)}o.delete(e),a.delete(e),i.list?m(i.list.filter(t=>t.id!==e)):f()},_=e=>{p(e.id,{doc:e,sync:{state:`saved`}}),h(Ce(e))};async function v(e){let t=a.get(e);if(!t?.doc||!o.has(e)||t.sync.state===`conflict`)return;let{body:n,version:i}=t.doc;p(e,{sync:{state:`saving`}});try{let t=await r.saveDataset(e,i,n),s=a.get(e);if(!s?.doc)return;s.doc.body===n&&o.delete(e);let c={...s.doc,version:t.version,cases:n.cases.length};if(p(e,{doc:c,sync:{state:`saved`}}),h(Ce(c)),o.has(e))return v(e)}catch(t){let n=a.get(e);if(!n?.doc)return;let r=t instanceof pe&&t.status===409?t.body?.current??null:null;if(r){if(xe(r.body,n.doc.body)){o.delete(e),p(e,{doc:{...n.doc,version:r.version},sync:{state:`saved`}});return}p(e,{sync:{state:`conflict`,theirs:r}});return}p(e,{sync:{state:`offline`,message:Se(t)}})}}function y(e){let t=s.get(e);t&&(clearTimeout(t),s.delete(e));let n=l.get(e);return n||(n=v(e).finally(()=>l.delete(e)),l.set(e,n)),n}return{list:()=>i,entry:e=>a.get(e),held:()=>d??=[...a.values()],async refresh(){try{let e=(await r.datasets()).datasets;m(e);for(let t of e){let e=a.get(t.id);e?.doc&&!o.has(t.id)&&t.version>e.doc.version&&r.dataset(t.id).then(e=>{a.has(t.id)&&!o.has(t.id)&&_(e)},()=>{})}}catch(e){i={list:i.list,error:Se(e)},f()}},load(e){a.has(e)||(p(e,{sync:{state:`loading`}}),r.dataset(e).then(t=>{a.has(e)&&p(e,{doc:t,sync:{state:`saved`}})},t=>{a.has(e)&&p(e,{sync:{state:`missing`,message:Se(t)}})}))},edit(e,r){let i=a.get(e);if(!i?.doc)return;let l=r(i.doc.body);if(l===i.doc.body)return;p(e,{doc:{...i.doc,body:l,cases:l.cases.length}}),o.add(e);let u=s.get(e);if(u&&clearTimeout(u),s.set(e,setTimeout(()=>{s.delete(e),y(e)},t)),n){let t=c.get(e);t&&clearTimeout(t),c.set(e,setTimeout(()=>{c.delete(e);let t=a.get(e)?.doc;t&&n.cut(e,t.body)},n.ms))}},async flush(e){await Promise.all((e?[e]:[...o]).map(y))},async resolve(e,t){let n=a.get(e);if(!n?.doc||n.sync.state!==`conflict`)return;let r=n.sync.theirs;if(t===`theirs`){o.delete(e),_(r);return}p(e,{doc:{...n.doc,version:r.version},sync:{state:`saved`}}),o.add(e),await y(e)},async create(e,t){let n=await r.createDataset(t?{name:e,body:t}:{name:e});return _(n),n},async rename(e,t){let n=await r.renameDataset(e,t),i=a.get(e)?.doc;i&&p(e,{doc:{...i,name:n.name,version:n.version,updated:n.updated}}),h({...Ce(n),cases:i?.body.cases.length??n.cases})},async remove(e){let{trash:t}=await r.deleteDataset(e);return g(e),t},async restore(e){let t=await r.restoreDataset(e);return _(t),t},async importFile(e){let{created:t}=await r.importDatasets(e);for(let e of t)h(e);return t},exportUrl:e=>r.exportDatasetUrl(e),exportAllUrl:()=>r.exportAllDatasetsUrl(),subscribe(e){return u.add(e),()=>{u.delete(e)}}}}var Te=3e4,Ee=(e,t)=>e.get(`promptlab.versions`)[t]??{};function De(e,t){return(e.get(`promptlab.versions`).dataset?.[t]??[]).map(e=>({...e,doc:K().upgradeDatasetBody(e?.doc)})).filter(e=>Oe(e.doc))}var Oe=e=>!!e&&typeof e==`object`&&Array.isArray(e.cases);function ke(e,t,n,r,i){let a=e.get(`promptlab.versions`),o=Ee(e,t),s=(o[n]??[]).slice(),c=structuredClone(r);s[0]&&je(s[0].doc,c)||(s.unshift({at:new Date().toISOString(),doc:c,reason:i}),s.length>10&&(s.length=10),e.set(`promptlab.versions`,{...a,[t]:{...o,[n]:s}}))}function Ae(e,t,n,r){let i=e.get(`promptlab.versions`),a=(i.dataset?.[t]??[]).slice(),o=structuredClone(n);a[0]&&je(a[0].doc,o)||(a.unshift({at:new Date().toISOString(),doc:o,reason:r}),a.length>10&&(a.length=10),e.set(`promptlab.versions`,{...i,dataset:{...i.dataset??{},[t]:a}}))}var je=(e,t)=>JSON.stringify(e)===JSON.stringify(t),X=g(),Me=(0,q.createContext)(null);function Ne({children:e,pause:t}){let n=J(),r=ge(),i=(0,q.useMemo)(()=>we({api:n,...t==null?{}:{pause:t},idle:{ms:Te,cut:(e,t)=>Ae(r,e,t,`idle`)}}),[n,r,t]);return(0,q.useEffect)(()=>{let e=()=>{i.flush()};return addEventListener(`pagehide`,e),()=>removeEventListener(`pagehide`,e)},[i]),(0,X.jsx)(Me.Provider,{value:i,children:e})}function Pe(){let e=(0,q.useContext)(Me);if(!e)throw Error(`useDatasets outside a DatasetsProvider: the app mounts one at its root`);return e}function Fe(){let e=Pe(),t=(0,q.useSyncExternalStore)(e.subscribe,e.list);return(0,q.useEffect)(()=>{e.list().list===null&&e.refresh()},[e]),t}function Ie(e){let t=Pe(),n=(0,q.useSyncExternalStore)(t.subscribe,()=>e?t.entry(e):void 0);return(0,q.useEffect)(()=>{e&&t.load(e)},[t,e]),n}var Le=e=>e.name.trim()||e.text.trim().split(`
2
- `)[0].trim()||`Untitled prompt`,Re=e=>e?.state===`conflict`?`Not saved: changed in another browser.`:e?.state===`offline`?`Not saved: ${e.message}`:null,ze=e=>e instanceof Error?e.message:String(e),Be=({versions:e,uses:t,...n})=>n;function Ve({api:e,pause:t=800}){let n={list:null,error:null},r=new Map,i=new Set,a=new Map,o=new Map,s=new Set,c=()=>s.forEach(e=>e()),l=(e,t)=>{let n=r.get(e)??{id:e,doc:null,sync:{state:`loading`}};r.set(e,{...n,...t,id:e}),c()},u=e=>{n={list:e,error:null},c()},d=e=>{if(!n.list)return;let t=n.list.findIndex(t=>t.id===e.id),r=e.default?n.list.map(t=>t.default&&t.id!==e.id?{...t,default:!1}:t):n.list;u(t<0?[e,...r]:r.map((n,r)=>r===t?e:n))},f=e=>{l(e.id,{doc:e,sync:{state:`saved`}}),d(Be(e))};async function p(t){let n=r.get(t);if(!n?.doc||!i.has(t)||n.sync.state===`conflict`)return;let{name:a,text:o,version:s}=n.doc;l(t,{sync:{state:`saving`}});try{let n=await e.editPrompt(t,s,{name:a,text:o}),c=r.get(t);if(!c?.doc)return;let u=c.doc.name!==a||c.doc.text!==o;u||i.delete(t);let f=u?{...n,name:c.doc.name,text:c.doc.text}:n;if(l(t,{doc:f,sync:{state:u?`saving`:`saved`}}),d(Be(f)),u)return p(t)}catch(e){let n=r.get(t);if(!n?.doc)return;let a=e instanceof pe&&e.status===409?e.body?.current??null:null;if(a){if(a.text===n.doc.text&&a.name===n.doc.name){i.delete(t),f(a);return}l(t,{sync:{state:`conflict`,theirs:a}});return}l(t,{sync:{state:`offline`,message:ze(e)}})}}function m(e){let t=a.get(e);t&&(clearTimeout(t),a.delete(e));let n=o.get(e);return n||(n=p(e).finally(()=>o.delete(e)),o.set(e,n)),n}return{list:()=>n,entry:e=>r.get(e),async refresh(){try{u((await e.prompts()).prompts)}catch(e){n={list:n.list,error:ze(e)},c()}},load(t){i.has(t)||(r.has(t)||l(t,{sync:{state:`loading`}}),e.prompt(t).then(e=>{r.has(t)&&!i.has(t)&&f(e)},e=>{r.has(t)&&l(t,{sync:{state:`missing`,message:ze(e)}})}))},edit(e,n){let o=r.get(e);if(!o?.doc)return;let s={...o.doc,...n};if(s.name===o.doc.name&&s.text===o.doc.text)return;l(e,{doc:s}),d(Be(s)),i.add(e);let c=a.get(e);c&&clearTimeout(c),a.set(e,setTimeout(()=>{a.delete(e),m(e)},t))},async flush(e){await Promise.all((e?[e]:[...i]).map(m))},async resolve(e,t){let n=r.get(e);if(!n?.doc||n.sync.state!==`conflict`)return;let a=n.sync.theirs;if(t===`theirs`){i.delete(e),f(a);return}l(e,{doc:{...n.doc,version:a.version},sync:{state:`saved`}}),i.add(e),await m(e)},async create(t={}){let n=await e.createPrompt(t);return f(n),n},async setDefault(t){await m(t),f(await e.setDefaultPrompt(t))},async restoreVersion(t,n){await m(t),f(await e.restorePromptVersion(t,n))},async remove(t){await m(t);let{trash:o}=await e.deletePrompt(t),s=a.get(t);return s&&clearTimeout(s),a.delete(t),i.delete(t),r.delete(t),n.list?u(n.list.filter(e=>e.id!==t)):c(),o},async restore(t){let n=await e.restorePrompt(t);return f(n),n},subscribe(e){return s.add(e),()=>{s.delete(e)}}}}var He=(0,q.createContext)(null);function Ue({children:e,pause:t}){let n=J(),r=(0,q.useMemo)(()=>Ve({api:n,...t==null?{}:{pause:t}}),[n,t]);return(0,q.useEffect)(()=>{let e=()=>{r.flush()};return addEventListener(`pagehide`,e),()=>removeEventListener(`pagehide`,e)},[r]),(0,X.jsx)(He.Provider,{value:r,children:e})}function We(){let e=(0,q.useContext)(He);if(!e)throw Error(`usePrompts outside a PromptsProvider: the app mounts one at its root`);return e}function Ge(){let e=We(),t=(0,q.useSyncExternalStore)(e.subscribe,e.list);return(0,q.useEffect)(()=>{e.refresh()},[e]),t}function Ke(e){let t=We(),n=(0,q.useSyncExternalStore)(t.subscribe,()=>e?t.entry(e):void 0);return(0,q.useEffect)(()=>{e&&t.load(e)},[t,e]),n}var Z=e=>(typeof e.id==`string`?e.id.trim():``)||`file:${K().caseFile(e)}`,qe=(e,t)=>e.trim().toLowerCase()===t.trim().toLowerCase();function Je(e,t){switch(t.type){case`bounds`:{let n=(e,t)=>e.kind===`keep`?t??null:e.kind===`clear`?null:e.n,r=n(t.min,e.minCount),i=n(t.max,e.maxCount);return r===(e.minCount??null)&&i===(e.maxCount??null)?e:{...e,minCount:r,maxCount:i}}case`addTerm`:{let n=t.term.trim(),r=e[t.list]??[];return!n||r.some(e=>qe(e,n))?e:{...e,[t.list]:[...r,n]}}case`removeTerm`:{let n=t.term.trim();if(!n)return e;let r=e=>(e??[]).filter(e=>!qe(e,n)),i=r(e.expect),a=r(e.forbid),o=r(e.allow),s=(e.anyOf??[]).map(r).filter(e=>e.length);return i.length===(e.expect??[]).length&&a.length===(e.forbid??[]).length&&o.length===(e.allow??[]).length&&JSON.stringify(s)===JSON.stringify(e.anyOf??[])?e:{...e,...e.expect?{expect:i}:{},...e.forbid?{forbid:a}:{},...e.allow?{allow:o}:{},...e.anyOf?{anyOf:s}:{}}}case`status`:return!!e.todo===t.todo?e:{...e,todo:t.todo}}}function Ye(e,t,n){let r=[];return n.type===`delete`?{next:e.filter(e=>{let n=t.has(Z(e));return n&&r.push(Z(e)),!n}),changed:r}:{next:e.map(e=>{if(!t.has(Z(e)))return e;let i=Je(e,n);return i!==e&&r.push(Z(e)),i}),changed:r}}function Xe(e,t,n){let r=new Map(e.map(e=>[Z(e),e])),i=new Map(t.map(e=>[Z(e),e])),a=[];for(let e of n){let t=r.get(e),n=i.get(e);if(!t||!n)continue;let o=new Set(K().validateEvals({cases:[t]})),s=`${n.id}: `,c=K().validateEvals({cases:[n]}).filter(e=>!o.has(e)).map(e=>e.startsWith(s)?e.slice(s.length):e);c.length&&a.push({key:e,file:K().caseFile(n),reasons:c})}return{cases:a}}var Ze={expect:`Expect`,forbid:`Forbid`,allow:`Except`},Qe=e=>Ze[e],$e=e=>`${e} ${e===1?`case`:`cases`}`;function et(e,t){let n=$e(t);switch(e.type){case`bounds`:{let t=[];return e.min.kind!==`keep`&&t.push({verb:e.min.kind===`set`?`Set`:`Cleared`,what:`Min`}),e.max.kind!==`keep`&&t.push({verb:e.max.kind===`set`?`Set`:`Cleared`,what:`Max`}),t.length===2&&t[0].verb===t[1].verb?`${t[0].verb} Min and Max items on ${n}`:t.length===2?`${t[0].verb} Min items and ${t[1].verb.toLowerCase()} Max items on ${n}`:t[0]?`${t[0].verb} ${t[0].what} items on ${n}`:`Changed ${n}`}case`addTerm`:return`Added ${e.term.trim()} to ${Ze[e.list]} on ${n}`;case`removeTerm`:return`Removed ${e.term.trim()} from ${n}`;case`status`:return`Marked ${n} ${e.todo?`Todo`:`graded`}`;case`delete`:return`Deleted ${n}`}}var tt={file:``,status:`all`,show:`all`};function nt(e,t,n){let r=t.file.trim().toLowerCase();return e.filter(e=>(!r||K().caseFile(e).toLowerCase().includes(r))&&(t.status===`all`||t.status===`todo`==!!e.todo)&&(t.show===`all`||n.has(Z(e))))}var rt=(0,q.createContext)(null);function it({children:e}){let[t,n]=(0,q.useState)(null),[r,i]=(0,q.useState)(new Set),[a,o]=(0,q.useState)(tt),[s,c]=(0,q.useState)(null),[l,u]=(0,q.useState)(null),d=Ie(l?.dataset??null),f=(0,q.useRef)(null),p=(0,q.useCallback)(e=>{e!==f.current&&(f.current=e,n(e),i(new Set),o(tt),c(null))},[]),m=(0,q.useCallback)(e=>{i(e)},[]),h=(0,q.useCallback)(e=>{o(t=>({...t,...e}))},[]),g=(0,q.useCallback)((e,t,r)=>{f.current=e,n(e),i(new Set),o({...tt,show:`selected`}),c(null),u({dataset:e,files:t,from:r}),location.hash===`#/library/datasets`?window.dispatchEvent(new HashChangeEvent(`hashchange`)):location.hash=`#/library/datasets`},[]),_=d?.doc?.body??null,v=d?.sync.state===`missing`;(0,q.useEffect)(()=>{if(!l||!_&&!v)return;let e=new Set(l.files),t=(_?.cases??[]).filter(t=>e.has(K().caseFile(t))).map(Z);i(new Set(t)),c({from:l.from,wanted:e.size,found:t.length}),u(null)},[l,_,v]);let y=(0,q.useMemo)(()=>({datasetId:t,pickDataset:p,selected:r,setSelected:m,filters:a,setFilters:h,handedOver:s,showCases:g}),[t,p,r,m,a,h,s,g]);return(0,X.jsx)(rt.Provider,{value:y,children:e})}function at(){let e=(0,q.useContext)(rt);if(!e)throw Error(`useEvals outside an EvalsProvider: the app mounts one at its root`);return e}var ot=(0,q.createContext)(null);function st({children:e}){let[t,n]=(0,q.useState)([]),[r,i]=(0,q.useState)(null),a=(0,q.useRef)(t);a.current=t;let o=(0,q.useRef)(r);o.current=r;let s=(0,q.useRef)(0),c=(0,q.useCallback)((e,t)=>{a.current=e,n(e),o.current=t,i(t)},[]),l=(0,q.useCallback)((e,t={})=>{let n=++s.current,r=a.current,i=r.find(t=>t.id===e),o;if(i)o=r.map(r=>r.id===e?{...r,from:t.from??r.from,last:n}:r);else if(o=[...r,{id:e,at:t.at??``,from:t.from??`runs`,show:`all`,last:n}],o.length>4){let e=o.reduce((e,t)=>e.last<t.last?e:t);o=o.filter(t=>t.id!==e.id)}c(o,e)},[c]),u=(0,q.useCallback)(e=>{let t=a.current,n=t.findIndex(t=>t.id===e);if(n<0)return;let r=t[n].from,i=t.filter(t=>t.id!==e);if(i.length===0){c(i,null),window.location.hash=`#/${r}`;return}c(i,o.current===e?i[Math.min(n,i.length-1)].id:o.current)},[c]),d=(0,q.useCallback)((e,t)=>{let n=++s.current;c(a.current.map(r=>r.id===e?{...r,from:t??r.from,last:n}:r),e)},[c]),f=(0,q.useCallback)((e,t)=>{c(a.current.map(n=>n.id===e?{...n,show:t}:n),o.current)},[c]),p=(0,q.useCallback)(()=>{c(a.current,null)},[c]),m=(0,q.useCallback)(()=>{let e=a.current.find(e=>e.id===o.current);window.location.hash=`#/${e?.from??`runs`}`,p()},[p]),h=(0,q.useMemo)(()=>({tabs:t,focusedId:r,openRun:l,closeRun:u,focusRun:d,setShow:f,goBack:m,hide:p}),[t,r,l,u,d,f,m,p]);return(0,X.jsx)(ot.Provider,{value:h,children:e})}function ct(){let e=(0,q.useContext)(ot);if(!e)throw Error(`useResults outside a ResultsProvider: the app mounts one at its root`);return e}function lt({n:e,of:t}){return(0,X.jsxs)(`span`,{className:`fig-part`,children:[e,(0,X.jsxs)(`span`,{className:`fig-of`,children:[`/`,t]})]})}var ut=e=>e===`good`?` fig-good`:e===`bad`?` fig-bad`:``;function dt({fig:e}){return(0,X.jsx)(`span`,{className:`fig-value${ut(e.tone)}`,children:e.value??(e.of?(0,X.jsx)(lt,{n:e.of[0],of:e.of[1]}):`—`)})}function ft({fig:e}){return(0,X.jsxs)(`div`,{className:`fig`,children:[(0,X.jsx)(`span`,{className:`fig-label`,children:e.label}),(0,X.jsx)(dt,{fig:e})]},e.key)}function pt({label:e,lead:t,rest:n,dense:r}){return(0,X.jsxs)(`div`,{className:`figures${r?` dense`:``}`,role:`group`,"aria-label":e,children:[(0,X.jsxs)(`div`,{className:`fig fig-lead`,children:[(0,X.jsx)(`span`,{className:`fig-label`,children:t.label}),(0,X.jsxs)(`div`,{className:`fig-headline`,children:[(0,X.jsx)(dt,{fig:t}),t.under&&(0,X.jsx)(`span`,{className:`fig-under`,children:(0,X.jsx)(lt,{n:t.under[0],of:t.under[1]})})]})]}),!!n.length&&(0,X.jsx)(`div`,{className:`fig-rest`,children:n.map(e=>(0,X.jsx)(ft,{fig:e},e.key))})]})}var mt={type:`Connection type`,profile:`Request profile`,px:`Resolution`,format:`Image format`,quality:`Image quality`,seed:`Seed`,nPredict:`Reply tokens`,repeatPenalty:`Repeat penalty`,frequencyPenalty:`Frequency penalty`,presencePenalty:`Presence penalty`,dryMultiplier:`DRY multiplier`,dryBase:`DRY base`,dryAllowedLength:`DRY allowed length`,grammar:`Grammar`,url:`Address`,model:`Model`,temperature:`Temperature`,imagePosition:`Image position`,cachePrompt:`Cache prompt`,thinking:`Thinking`,rejectLoops:`Reject looping replies`,maxTokens:`Reply tokens`},ht={format:`image/jpeg`,quality:`0.92`,seed:``,nPredict:``,repeatPenalty:``,frequencyPenalty:``,presencePenalty:``,dryMultiplier:``,dryBase:``,dryAllowedLength:``,grammar:``,px:`921600`},gt=[`type`,`profile`,`px`,`format`,`quality`,`seed`,`nPredict`,`repeatPenalty`,`frequencyPenalty`,`presencePenalty`,`dryMultiplier`,`dryBase`,`dryAllowedLength`,`grammar`,`imagePosition`,`cachePrompt`,`thinking`,`rejectLoops`,`url`,`model`,`temperature`];function _t(e){let t=(t,n)=>String(e[t]??``).trim()?[`${n} ${e[t]}`]:[];return[...t(`frequencyPenalty`,`frequency`),...t(`presencePenalty`,`presence`),...String(e.dryMultiplier??``).trim()?[`DRY ${e.dryMultiplier} / ${e.dryBase||`·`} / ${e.dryAllowedLength||`·`}`]:[],...String(e.grammar??``).trim()?[`grammar`]:[]].join(` · `)}var vt=(e,t)=>({...ht,...t?.setupProfile?.settings||{}});function yt(e){return mt[e]??e}function bt(e,t){return e===`type`?xt(String(t)):e===`profile`?t===`speed`?`Speed`:`Quality`:e===`px`?K().budgetLabel(t):e===`format`?String(t).replace(`image/`,``).toUpperCase():String(t)}function xt(e){return K().CONNECTION_TYPES[e]?.label??e}var St=e=>e.content?e.content!==`text`:null,Ct=e=>Number(new Date(e)).toString(36).slice(-6).toUpperCase(),wt=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`,Tt=e=>{let t=e?e.timed??e.ran:0;return t?e.ms/t:null};function Et(e,t){let n=e.scenarios.map(()=>0);for(let e of t.results||[])e&&!e.unrun&&(e.scenarios||[]).forEach((e,t)=>{t<n.length&&typeof e?.res?.ms==`number`&&n[t]++});return{...e,scenarios:e.scenarios.map((e,t)=>({...e,timed:n[t]??0}))}}var Dt=e=>new Date(e).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}),Ot={queued:`Queued`,running:`Running`,done:`Done`,incomplete:`Incomplete`,cancelled:`Cancelled`,failed:`Failed`,interrupted:`Interrupted`},kt=e=>Ot[e]??e;function At(e){return Ot[e]?(0,X.jsx)(`span`,{className:`rchip ${e}`,children:Ot[e]}):null}var jt=e=>e.length?e.reduce((e,t)=>e+t,0)/e.length:null;function Mt(e){if(Math.round(e)<1e3)return`${Math.max(0,Math.round(e))} ms`;let t=Math.round(e/100);if(t<600)return`${(t/10).toFixed(1)}s`;let n=Math.round(e/1e3),r=Math.floor(n/60),i=n%60;if(r<60)return i?`${r}m ${i}s`:`${r}m`;let a=Math.floor(r/60),o=r%60;return o?`${a}hr ${o}`:`${a}hr`}function Nt(e,t){if(!e)return null;let n=new Date(e).getTime();if(Number.isNaN(n))return null;let r=t?new Date(t).getTime():Date.now();return Number.isNaN(r)?null:Math.max(0,r-n)}var Pt=e=>{let t=(e.scenarios||[]).filter(Boolean),n=t.reduce((e,t)=>e+(t.passed||0),0),r=t.reduce((e,t)=>e+(t.cases||0),0),i=t.map(e=>e.percent).filter(e=>e!=null),a=t.map(Tt).filter(e=>e!=null);return{pct:r?Math.round(100*n/r):null,avgScore:i.length?Math.round(jt(i)):null,avgTime:a.length?jt(a):null}},Ft=e=>{let t=Pt(e);return{pct:t.pct==null?`—`:`${t.pct}%`,avgScore:t.avgScore==null?`—`:`${t.avgScore}%`,avgTime:t.avgTime==null?`—`:Mt(t.avgTime)}},It=e=>e.run&&(e.status===`cancelled`||e.status===`interrupted`)?(0,X.jsx)(`button`,{type:`button`,className:`ghost linkish`,"data-resume":e.run,children:`Resume`}):null,Lt=[{key:`runid`,label:`Run ID`,on:!0,sort:e=>e.at,get:e=>(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`code`,{className:`runlink`,"data-openrun":e.run??void 0,children:Ct(e.at)}),It(e)]})},{key:`date`,label:`Date`,on:!0,sort:e=>e.at,get:e=>(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`time`,{dateTime:e.at,title:new Date(e.at).toLocaleString(),children:Dt(e.at)}),e.cancelled&&(0,X.jsx)(`span`,{className:`err`,children:` cancelled`})]})},{key:`state`,label:`State`,on:!0,sort:e=>kt(e.status),get:e=>At(e.status)},{key:`content`,label:`Content`,on:!0,get:e=>e.content||`—`},{key:`pct`,label:`% Passed Items`,on:!0,numeric:!0,sort:e=>Pt(e).pct,get:e=>Ft(e).pct},{key:`avgscore`,label:`Avg Score`,on:!0,numeric:!0,sort:e=>Pt(e).avgScore,get:e=>Ft(e).avgScore},{key:`avgtime`,label:`Avg Time`,on:!0,numeric:!0,sort:e=>Pt(e).avgTime,get:e=>Ft(e).avgTime},{key:`duration`,label:`Duration`,on:!1,numeric:!0,sort:e=>Nt(e.startedAt,e.finishedAt),get:e=>{let t=Nt(e.startedAt,e.finishedAt);return t==null?`—`:Mt(t)}},{key:`ran`,label:`Ran`,on:!1,numeric:!0,sort:e=>e.done,get:e=>(0,X.jsx)(lt,{n:e.done,of:e.total})},{key:`setup`,label:`Pipeline`,on:!1,get:e=>e.setup||`—`},{key:`plugins`,label:`Plugins`,on:!1,get:e=>e.plugins||`—`},{key:`comment`,label:`Comment`,on:!1,sort:e=>e.comment,get:e=>(0,X.jsx)(`button`,{type:`button`,className:`ghost linkish hcomment-btn`,"data-editcomment":e.run??void 0,"aria-label":e.comment?void 0:`Add a comment`,children:e.comment?(0,X.jsx)(`span`,{className:`hcomment`,title:e.comment,children:e.comment}):(0,X.jsx)(`span`,{className:`hcomment empty`,children:`——`})})}],Rt=[{key:`name`,label:`Name`,on:!0,sort:(e,t)=>e?.name||`Scenario ${t+1}`,get:(e,t,n)=>(0,X.jsx)(`button`,{type:`button`,className:`ghost linkish`,"data-scenario":n,children:t?.name||`Scenario ${n+1}`})},{key:`outcome`,label:`Outcome`,on:!0,sort:e=>e.pass,get:(e,t)=>t.pass==null?(0,X.jsx)(`span`,{className:`note`,children:`—`}):(0,X.jsx)(`b`,{className:t.pass?`hit`:`fault`,children:t.pass?`Pass`:`Fail`})},{key:`tests`,label:`Tests`,on:!0,sort:e=>e.tests||null,get:(e,t)=>t.tests||`—`},{key:`profile`,label:`Setup Profile`,on:!0,sort:e=>e?.setupProfile?.name,get:(e,t,n)=>t?.setupProfile?.name?(0,X.jsx)(`button`,{type:`button`,className:`ghost linkish`,"data-prof":n,children:t.setupProfile.name}):`—`},{key:`passed`,label:`Passed Items`,on:!0,numeric:!0,sort:e=>e.cases?e.passed/e.cases:null,get:(e,t)=>t.cases?(0,X.jsx)(lt,{n:t.passed,of:t.cases}):`—`},{key:`score`,label:`Score`,on:!0,numeric:!0,sort:e=>e.percent,get:(e,t)=>t.percent==null?`—`:`${t.percent}%`},{key:`avgtime`,label:`Avg Time`,on:!0,numeric:!0,sort:e=>Tt(e),get:(e,t)=>{let n=Tt(t);return n==null?`—`:Mt(n)}},{key:`total`,label:`Total`,on:!1,numeric:!0,sort:e=>e.ms||null,get:(e,t)=>t.ms?Mt(t.ms):`—`},{key:`model`,label:`Model`,on:!1,get:(e,t)=>t.model||`—`},{key:`res`,label:`Resolution`,on:!1,image:!0,get:(e,t)=>String(K().budgetLabel(vt(e,t).px))},{key:`format`,label:`Format`,on:!1,image:!0,get:(e,t)=>String(vt(e,t).format).replace(`image/`,``).toUpperCase()},{key:`quality`,label:`Quality`,on:!1,image:!0,get:(e,t)=>vt(e,t).format===`image/png`?`—`:String(vt(e,t).quality)},{key:`seed`,label:`Seed`,on:!1,get:(e,t)=>String(vt(e,t).seed||`1234`)},{key:`predict`,label:`Reply tokens`,on:!1,get:(e,t)=>String(vt(e,t).nPredict||vt(e,t).maxTokens||`—`)},{key:`penalty`,label:`Repeat penalty`,on:!1,get:(e,t)=>String(vt(e,t).repeatPenalty||`—`)},{key:`decoding`,label:`Decoding`,on:!1,get:(e,t)=>_t(vt(e,t))||`—`},...Object.entries(K().MODIFIERS).map(([e,t])=>({key:`modifier-${e}`,label:t.label||e,on:!1,get:(t,n)=>n.modifiers?.[e]||`—`}))],zt=[[`Runs`,Lt],[`Run Scenarios`,Rt]],Bt=e=>![`queued`,`running`].includes(e),Vt=()=>({ran:0,passed:0,found:0,of:0,ms:0,timed:0,share:0,shared:0});function Ht(e){return e.of?Math.round(100*e.found/e.of):e.shared?Math.round(100*e.share/e.shared):null}var Ut=(e,t)=>e.filter(e=>!e.whole).map(e=>e.items[t]).filter(e=>!!e&&!K().isSkipped(e));function Wt(e,t){let n=t.map(Vt);return(e||[]).forEach((e,r)=>{e&&!e.unrun&&(e.scenarios||[]).forEach((e,i)=>{let a=n[i];if(!a||!e)return;let o=Ut(t[i],r);if(o.length){a.ran++,o.every(e=>e.pass)&&a.passed++;for(let e of o)a.found+=(e.found||[]).length,a.of+=(e.found||[]).length+(e.missed||[]).length+(e.invented||[]).length,!e.found&&!e.missed&&typeof e.score==`number`&&!e.points&&(a.share+=e.score,a.shared++)}e.res&&(a.timed++,a.ms+=e.res.ms||0)})}),n}var Gt=(e,t,n)=>(e.scenarios||[]).map((r,i)=>K().scenarioTests(e,i,t,Bt(n))),Kt=(e,t,n)=>(e.outcomes[n]??[]).some(e=>!e.whole&&K().failedScore(e.items[t]));function qt(e){return e.skipped?`Skipped`:e.whole?e.verdict?.ran?e.verdict.pass?`✓`:`✗`:`—`:e.ran?`${e.passed}/${e.ran}`:e.skippedItems?`Skipped`:`—`}var Jt=e=>e.map(e=>`${e.label} ${qt(e)}`).join(` · `),Yt={state:`pending`,value:`—`},Xt={state:`skipped`,value:`Skipped`,note:`an earlier test failed`};function Zt(e){let t=[];return e.tests.forEach((n,r)=>{let i=e.scenarios.map((t,n)=>e.outcomes[n]?.[r]),a=i.find(Boolean);if(!a)return;let o=K().TEST_TYPES[n.type]?.label??n.type,s=`dataset`in n&&n.dataset?.name?`${o} · ${n.dataset.name}`:o,c=[],l=(e,t,r,o)=>c.push({key:`${n.id}-${e}`,test:a.label,type:s,first:!c.length,rule:t,want:r,cells:i.map(e=>e?e.skipped?Xt:o(e):Yt)}),u=K().TEST_TYPES[n.type]?.ruleOf;if(a.rules.length)for(let e of a.rules)l(e.key,e.label,e.want||null,t=>{if(!t.whole&&u){let r=t.items.flatMap(t=>t&&!K().isSkipped(t)?[u(t,e.key,n)]:[]).filter(e=>e!=null);if(!r.length)return Yt;let i=r.filter(Boolean).length;return{state:i===r.length?`met`:`not`,value:`${i} of ${r.length}`}}let r=t.verdict?.ran?t.verdict.checks?.find(t=>t.key===e.key):void 0;return r?r.pass?{state:`met`,value:`Met`}:{state:`not`,value:`Not Met`,note:r.note}:Yt});a.rules.length&&a.whole||(a.whole?l(`verdict`,`Verdict`,null,e=>e.verdict?.ran?e.verdict.pass?{state:`met`,value:`Pass`}:{state:`not`,value:`Fail`,note:e.verdict.detail}:Yt):l(`items`,`Items passed`,null,e=>{if(!e.ran)return e.skippedItems?Xt:Yt;let t=e.skippedItems?`${e.skippedItems} skipped`:void 0;return{state:e.passed===e.ran?`met`:`not`,value:`${e.passed} of ${e.ran}`,note:t}})),t.push(...c)}),t}function Qt(e){let t=e.snapshot||{},n=K().contentOf(t),r=!!(n&&K().CONTENT_TYPES[n.type]?.inline),i=K().lastKind(t),a=e.results||[],o=Gt(t,a,e.status);return{id:e.id,status:e.status,at:e.submittedAt,behind:e.behind,name:t.name||`Run`,error:e.error,progress:e.progress||{current:null,n:0,total:0},scenarios:(t.scenarios||[]).map((e,n)=>({id:e?.id||`scenario-${n}`,name:K().scenarioLabel(t,n),kind:i,plain:!(i&&K().OUTPUT_KINDS[i]?.terms)})),items:r?[null]:n?.type===`source`&&n.files||[],content:r?{type:`text`,text:n.text??``}:{type:`source`,source:n?.ref?.id??``,sourceName:n?.ref?.name??``},tests:K().testsOf(t),snapshot:t,results:a,outcomes:o,tallies:Wt(a,o),startedAt:e.startedAt,finishedAt:e.finishedAt}}function $t(e){let t=e.snapshot||{},n=K().contentOf(t),r=e.results||[],i=t.scenarios||[],a=t.jobs||[],o=Gt(t,r,e.status),s=Wt(r,o),c=i.map((e,n)=>{let r=s[n]??Vt(),i=(a.length?K().stagesFor(t,n).connections:[]).map(e=>String(e.model||``)),c=i[0]?new Set(i).size===1?i[0]:i.join(` → `):``,l=Ht(r),u=K().scenarioPasses(o[n]??[]);return{name:K().scenarioLabel(t,n),id:e?.id,model:c,setupProfile:K().scenarioProfile(t,n),modifiers:Object.fromEntries((K().outOf(t.jobs?.at(-1))?.modifiers||[]).map(e=>[e.type,K().modifierSummary(e)])),percent:l,passed:r.passed,cases:r.ran,pass:u,detail:u==null?`not graded`:Jt(o[n]??[]),tests:Jt(o[n]??[]),ms:r.ms,ran:r.ran}}),l=e.progress||{},u=l.n??l.total??0;return{at:e.submittedAt,run:e.id,status:e.status,cancelled:e.status===`cancelled`,startedAt:e.startedAt,finishedAt:e.finishedAt,setup:t.name||``,comment:t.comment||``,plugins:(t.plugins||[]).map(e=>`${e.id} ${e.version}`).join(`, `),done:u,total:l.total??u,content:n&&K().CONTENT_TYPES[n.type]?.inline?`text`:n?.type===`source`&&(n.ref?.name||n.ref?.id)||``,scenarios:c}}var en=e=>({key:`state`,label:`State`,value:kt(e),tone:e===`done`?`good`:[`failed`,`incomplete`,`cancelled`,`interrupted`].includes(e)?`bad`:null}),tn=e=>e.length?e.reduce((e,t)=>e+t,0)/e.length:null;function nn(e){let t=0,n=0;for(let r of e||[])for(let e of r?.scenarios||[])for(let r of Object.values(e?.scores||{}))if(r&&!K().isSkipped(r))for(let e of r.metrics||[])typeof e.asked==`number`&&(t++,n+=e.asked);return{calls:t,ms:n}}function rn(e){let t=e.tallies,n=t.reduce((e,t)=>e+t.passed,0),r=t.reduce((e,t)=>e+t.ran,0),i=t.map(Ht).filter(e=>e!=null),a=i.length?`${Math.round(tn(i))}%`:`—`,o=Nt(e.startedAt,e.finishedAt),s=nn(e.results),c={key:`ran`,label:`Run Items`,of:e.progress.total?[e.progress.n,e.progress.total]:null};return{lead:r?{key:`pct`,label:`% Passed Items`,value:`${Math.round(100*n/r)}%`,under:[n,r]}:{...c,key:`lead-ran`},rest:[{key:`run`,label:`Run ID`,value:e.at?(0,q.createElement)(`code`,null,Ct(e.at)):`—`},en(e.status),{key:`score`,label:`Avg Score`,value:a},{key:`duration`,label:`Duration`,value:o==null?`—`:Mt(o)},...s.calls?[{key:`grader`,label:`Grader`,value:`${s.calls} ${s.calls===1?`call`:`calls`} · ${Mt(s.ms)}`}]:[],...r?[c]:[],{key:`start`,label:`Start Date`,value:e.at?cn(e.at):`—`},{key:`comment`,label:`Comment`,value:e.snapshot.comment?(0,q.createElement)(`span`,{className:`fig-comment`,title:e.snapshot.comment},e.snapshot.comment):`—`}]}}var an=e=>e.tests.length&&Bt(e.status)?`No assertions`:`—`;function on(e,t){let n=e.tallies[t],r=un(e,t),i={key:`state`,label:`State`,value:r==null?an(e):r?`Pass`:`Fail`,tone:r==null?null:r?`good`:`bad`},a={key:`time`,label:`Avg Time`,value:sn(n)??`—`},o=e.outcomes[t]??[],s=o.length>1?o.map(e=>({key:`test-${e.id}`,label:e.label,value:qt(e),tone:e.skipped?null:e.whole?e.verdict?.ran?e.verdict.pass?`good`:`bad`:null:e.ran?e.passed===e.ran?`good`:`bad`:null})):[];return n?.ran?{lead:{key:`pct`,label:`% Passed Items`,value:`${Math.round(100*n.passed/n.ran)}%`,under:[n.passed,n.ran]},rest:[i,...s,{key:`score`,label:`Score`,value:Ht(n)==null?`—`:`${Ht(n)}%`},a]}:{lead:i,rest:[...s,a]}}function sn(e){return e?.timed?Mt(e.ms/e.timed):null}function cn(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return`—`;let n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}function ln(e){let t=kt(e.status);return e.status===`queued`?{state:t,detail:e.behind?`behind ${e.behind}`:`next in line`}:e.status===`running`?{state:t,detail:e.progress.current||``}:null}function un(e,t){return K().scenarioPasses(e.outcomes[t]??[])}function dn(e,t){let n=e.content?.type===`source`?e.content.source:null;return n===`samples`?`/api/samples/thumbs/${encodeURIComponent(t)}`:n?`/api/sources/${encodeURIComponent(n)}/thumbs/${encodeURIComponent(t)}`:``}function fn(e,t){let n=e.content?.type===`source`?e.content.source:null;return n===`samples`?`/api/samples/zoom/${encodeURIComponent(t)}`:n?`/api/sources/${encodeURIComponent(n)}/zoom/${encodeURIComponent(t)}`:`/api/samples/zoom/${encodeURIComponent(t)}`}var Q=(e,t)=>t==null||t===``?null:`${e}: ${t}`,pn=e=>(e||[]).map(String).join(`, `),mn=e=>e.length?e.every(t=>t===e[0])?String(e[0]):e.join(` → `):``;function hn(e,t,n,r){let i=K().scoreCase(t,n),{stages:a,connections:o}=K().stagesFor(e,r),s=o.map(e=>K().connectionSettings(e)),c=e=>mn(s.map(e)),l=K().testsDataset(e);return[`An eval case is failing.`,``,`## The case`,Q(`file`,K().caseFile(t)),Q(`case id`,t.id),Q(`why it is graded`,t.why),Q(`expected, all of`,pn(t.expect)),...(t.anyOf||[]).map((e,t)=>Q(`expected, any of group ${t+1}`,pn(e))),Q(`forbidden`,pn(t.forbid)),Q(`allowed despite a forbidden word`,pn(t.allow)),Q(`watch for, not scored`,pn(t.watch)),``,`## What came back`,Q(`verdict`,i.pass?`pass`:`fail`),Q(`score`,i.score==null?`—`:`${Math.round(i.score*100)}%`),Q(`items`,pn(n?.terms)||`(none)`),Q(`missed`,pn(i.missed.map(e=>Array.isArray(e)?e.join(` / `):e))),Q(`invented`,pn(i.invented)),Q(`dropped`,pn((n?.dropped||[]).map(e=>`${e.item} (${e.by})`))),Q(`reasons`,pn(i.reasons)),Q(`error`,n?.error),Q(`took`,n?.ms==null?null:`${n.ms} ms`),``,`## How it was asked`,Q(`scenario`,`${r+1} of ${e.scenarios.length}`),Q(`model`,c(e=>e.model)),Q(`endpoint`,c(e=>e.url||`(the lab's own Ollama)`)),Q(`connection type`,c(e=>xt(String(e.type??``)))),Q(`image`,a[0]?.withImage?gn(s[0]):`no image`),Q(`seed`,c(e=>e.seed||`1234`)),Q(`reply tokens`,c(e=>e.nPredict||e.maxTokens||`not set`)),Q(`repeat penalty`,c(e=>e.repeatPenalty||`(profile default)`)),Q(`other decoding`,_n(s.at(-1))),Q(`modifiers`,(K().outOf(e.jobs.at(-1))?.modifiers||[]).map(e=>`${K().MODIFIERS[e.type]?.label??e.type}: ${K().modifierSummary(e)}`).join(`; `)||`none`),``,`## The prompt`,...a.flatMap((e,t)=>[a.length>1?`job ${t+1}${e.withImage?` (with image)`:``}, answering as ${e.kind}, on ${String(o[t]?.name||`unnamed`)}:`:null,e.text]),``,`## Where things live`,l?`the graded set: ${l.name||l.id} (this case is id "${t.id}")`:null,`the parser and scorer, shared by the lab, the CLI and CI: evals-core.ts`,`what the grading means: the dataset's README`].filter(e=>e!==null).join(`
3
- `)}function gn(e){let{px:t,format:n}=K().connectionImage(e);return`${t==null?`default budget`:K().budgetLabel(t)} · ${n.replace(`image/`,``).toUpperCase()}`}function _n(e){let t=(t,n)=>String(e?.[t]??``).trim()?[`${n} ${e?.[t]}`]:[];return[...t(`frequencyPenalty`,`frequency`),...t(`presencePenalty`,`presence`),...String(e?.dryMultiplier??``).trim()?[`DRY`]:[],...String(e?.grammar??``).trim()?[`grammar`]:[]].join(` · `)}function vn(e,t){let n=[];return!Bt(e.status)||!K().testsDataset(e.snapshot)||(e.results||[]).forEach((r,i)=>{r&&!r.unrun&&(r.scenarios||[]).forEach((a,o)=>{let s=t.find(e=>K().caseFile(e)===r.name);Kt(e,i,o)&&s&&a.res&&n.push({kase:s,res:a.res,scenarioIndex:o,item:r.name??``})})}),n}var yn=e=>{let t=Math.min(...e),n=Math.max(...e);return t===n?String(t):`${t}–${n}`};function bn(e,t,n){let r=K().testsDataset(e.snapshot);if(!Bt(e.status)||!r)return[];let i=e.outcomes[n]?.find(t=>e.tests.find(e=>e.id===t.id&&`dataset`in e)),a=new Map(t.map(e=>[K().caseFile(e),e])),o=new Map,s=(e,t,n,r,i,a)=>{let s=o.get(e);s||(s={key:e,label:n,note:null,files:[],rank:t,counts:[],limits:[]},o.set(e,s)),s.files.includes(r)||s.files.push(r),i!=null&&s.counts.push(i),a!=null&&s.limits.push(a)};return e.results.forEach((e,t)=>{if(!e||e.unrun||!e.name)return;let r=a.get(e.name),o=e.scenarios?.[n]?.res;if(!r||r.todo||!o||K().isSkipped(i?.items[t]))return;let c=K().scoreCase(r,o);if(c.pass)return;let l=e.name;if(c.discarded){s(`error`,6,`Error`,l);return}c.over&&s(`over`,0,`Too many items`,l,c.count,r.maxCount),c.under&&s(`under`,1,`Too few items`,l,c.count,r.minCount);for(let e of c.missed)Array.isArray(e)?s(`none:${e.join(`/`)}`,3,`None of ${e.join(` / `)}`,l):s(`missed:${e}`,2,`Missed ${e}`,l);for(let e of c.invented)s(`invented:${e}`,4,`Invented ${e}`,l)}),[...o.values()].sort((e,t)=>e.rank-t.rank||t.files.length-e.files.length||e.label.localeCompare(t.label)).map(({key:e,label:t,files:n,counts:r,limits:i})=>({key:e,label:t,files:n,note:r.length&&i.length?`${yn(r)}, ${e===`over`?`max`:`min`} ${yn(i)}`:null}))}var xn=d(`ban`,[[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),Sn=d(`circle-check`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),Cn=d(`circle-stop`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`rect`,{x:`9`,y:`9`,width:`6`,height:`6`,rx:`1`,key:`1ssd4o`}]]),wn=d(`columns-3`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),Tn=d(`database`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]),En=d(`file-code-corner`,[[`path`,{d:`M4 12.15V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2h-3.35`,key:`1wthlu`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`m5 16-3 3 3 3`,key:`331omg`}],[`path`,{d:`m9 22 3-3-3-3`,key:`lsp7cz`}]]),Dn=d(`flask-conical`,[[`path`,{d:`M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2`,key:`18mbvz`}],[`path`,{d:`M6.453 15h11.094`,key:`3shlmq`}],[`path`,{d:`M8.5 2h7`,key:`csnxdl`}]]),On=d(`folder-down`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}],[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`m15 13-3 3-3-3`,key:`6j2sf0`}]]),kn=d(`folder-input`,[[`path`,{d:`M2 9V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-1`,key:`fm4g5t`}],[`path`,{d:`M2 13h10`,key:`pgb2dq`}],[`path`,{d:`m9 16 3-3-3-3`,key:`6m91ic`}]]),An=d(`folder-open`,[[`path`,{d:`m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2`,key:`usdka0`}]]),jn=d(`folder-plus`,[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),Mn=d(`folder`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),Nn=d(`gavel`,[[`path`,{d:`m14 13-8.381 8.38a1 1 0 0 1-3.001-3l8.384-8.381`,key:`pgg06f`}],[`path`,{d:`m16 16 6-6`,key:`vzrcl6`}],[`path`,{d:`m21.5 10.5-8-8`,key:`a17d9x`}],[`path`,{d:`m8 8 6-6`,key:`18bi4p`}],[`path`,{d:`m8.5 7.5 8 8`,key:`1oyaui`}]]),Pn=d(`house`,[[`path`,{d:`M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8`,key:`5wwlr5`}],[`path`,{d:`M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z`,key:`r6nss1`}]]),Fn=d(`library`,[[`path`,{d:`m16 6 4 14`,key:`ji33uf`}],[`path`,{d:`M12 6v14`,key:`1n7gus`}],[`path`,{d:`M8 8v12`,key:`1gg7y9`}],[`path`,{d:`M4 4v16`,key:`6qkkli`}]]),In=d(`link-2`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]),Ln=d(`log-in`,[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]),Rn=d(`log-out`,[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]),zn=d(`message-square-text`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M7 11h10`,key:`1twpyw`}],[`path`,{d:`M7 15h6`,key:`d9of3u`}],[`path`,{d:`M7 7h8`,key:`af5zfr`}]]),Bn=d(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),Vn=d(`moon`,[[`path`,{d:`M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401`,key:`kfwtm`}]]),Hn=d(`play`,[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]),Un=d(`refresh-cw`,[[`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`,key:`v9h5vc`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}],[`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`,key:`3uifl3`}],[`path`,{d:`M8 16H3v5`,key:`1cv678`}]]),Wn=d(`settings`,[[`path`,{d:`M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915`,key:`1i5ecw`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),Gn=d(`sparkles`,[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]]),Kn=d(`star`,[[`path`,{d:`M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z`,key:`r04s7s`}]]),qn=d(`sun`,[[`circle`,{cx:`12`,cy:`12`,r:`4`,key:`4exip2`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`m4.93 4.93 1.41 1.41`,key:`149t6j`}],[`path`,{d:`m17.66 17.66 1.41 1.41`,key:`ptbguv`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`m6.34 17.66-1.41 1.41`,key:`1m8zz5`}],[`path`,{d:`m19.07 4.93-1.41 1.41`,key:`1shlcs`}]]),Jn=d(`waypoints`,[[`circle`,{cx:`12`,cy:`4.5`,r:`2.5`,key:`r5ysbb`}],[`path`,{d:`m10.2 6.3-3.9 3.9`,key:`1nzqf6`}],[`circle`,{cx:`4.5`,cy:`12`,r:`2.5`,key:`jydg6v`}],[`path`,{d:`M7 12h10`,key:`b7w52i`}],[`circle`,{cx:`19.5`,cy:`12`,r:`2.5`,key:`1piiel`}],[`path`,{d:`m13.8 17.7 3.9-3.9`,key:`1wyg1y`}],[`circle`,{cx:`12`,cy:`19.5`,r:`2.5`,key:`13o1pw`}]]),Yn=[{id:`home`,label:`Home`,icon:Pn,built:!0},{id:`runs`,label:`Runs`,icon:Dn,built:!0},{id:`history`,label:`History`,icon:r,built:!0},{id:`library`,label:`Library`,icon:Fn,built:!0},{id:`setup`,label:`Setup`,icon:Wn,built:!0}],Xn=e=>e.replace(/[^A-Za-z0-9._-]+/g,`-`).replace(/^[-.]+|[-.]+$/g,``);function Zn(e=new Date){let t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}${t(e.getMonth()+1)}${t(e.getDate())}-${t(e.getHours())}${t(e.getMinutes())}`}function Qn(e,t,n,r,i=new Date){return`${e}-${Xn(t)||e}-v${n}-${Zn(i)}.${r}`}function $n(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(n),0)}function er({name:e,body:t,onSave:n,onClose:r}){let[i,a]=(0,q.useState)(()=>JSON.stringify(t,null,2)),[o,s]=(0,q.useState)(()=>nr(i));(0,q.useEffect)(()=>{let e=setTimeout(()=>s(nr(i)),400);return()=>clearTimeout(e)},[i]);let c=o.problems;return(0,X.jsxs)(L,{title:`Edit raw… ${e}`,onClose:r,wide:!0,children:[(0,X.jsx)(`textarea`,{className:`raw-content`,"aria-label":`Dataset JSON`,spellCheck:!1,value:i,onChange:e=>a(e.target.value)}),(0,X.jsxs)(`div`,{className:`raw-foot`,children:[(0,X.jsx)(`span`,{className:`note ${c.length?` bad`:``}`,role:c.length?`alert`:void 0,children:c.length?`${c.length} to fix — ${c.join(` · `)}`:`Validated before it is accepted.`}),(0,X.jsx)(`button`,{type:`button`,className:`run`,onClick:()=>{let e=nr(i);e.body?n(e.body):s(e)},disabled:c.length>0,children:`Save`}),(0,X.jsx)(`button`,{type:`button`,className:`ghost`,onClick:r,children:`Close`})]})]})}var tr=[`cases`];function nr(e){let t;try{t=JSON.parse(e)}catch(e){return{body:null,problems:[`Not JSON: ${e instanceof Error?e.message:String(e)}`]}}if(!t||typeof t!=`object`||Array.isArray(t))return{body:null,problems:[`a dataset has to be a JSON object`]};let n=t,r=[];for(let e of Object.keys(n))tr.includes(e)||r.push(`${e} is not part of a dataset`);return Array.isArray(n.cases)||r.push(`cases has to be a list`),r.length||(r.push(...K().validateEvals({cases:n.cases})),r.length)?{body:null,problems:r}:{body:{cases:n.cases},problems:[]}}function rr(){let t=ge(),n=Pe(),a=te(),{list:o,error:s}=Fe(),{datasetId:c,pickDataset:l}=at(),[u,d]=(0,q.useState)(!1),[f,p]=(0,q.useState)(null),[m,h]=(0,q.useState)(!1),[g,_]=(0,q.useState)(!1),v=(0,q.useRef)(null),[y]=_e(`promptlab.versions`),b=o?.find(e=>e.id===c)??o?.[0]??null,x=b?.id??``,S=Ie(x||null),C=S?.doc??null;C?.body;let w=(0,q.useMemo)(()=>x?De(t,x):[],[t,x,y]),E=e=>p({text:e instanceof Error?e.message:String(e),bad:!0}),D=(0,q.useCallback)(()=>n.entry(x)?.doc?.body??null,[n,x]),O=(0,q.useCallback)(e=>{x&&n.edit(x,e)},[n,x]),k=()=>new Set((n.list().list??[]).map(e=>e.name)),j=async()=>{p(null);try{let e=await n.create(ar(`Untitled dataset`,k()));l(e.id),d(!0)}catch(e){E(e)}},M=e=>{d(!1);let t=e.trim();C&&t&&t!==C.name&&(p(null),n.rename(x,t).catch(e=>{e instanceof pe&&e.status===409?p({text:`A dataset is already called ${t}.`,bad:!0}):E(e)}))},N=async()=>{if(C){p(null);try{await n.flush(x);let e=await n.create(ar(`${C.name} copy`,k()),structuredClone(C.body));l(e.id)}catch(e){E(e)}}},P=async()=>{if(!C)return;p(null);let{name:e}=C,t=o?.findIndex(e=>e.id===x)??-1;try{await n.flush(x);let r=await n.remove(x),i=n.list().list??[];l(i[Math.min(Math.max(t,0),i.length-1)]?.id??null),a.offer({label:`Deleted ${e}`,restore:()=>{n.restore(r).then(t=>{l(t.id),t.name!==e&&p({text:`Restored as ${t.name}.`,bad:!1})}).catch(E)}})}catch(e){E(e)}},F=async e=>{p(null);let t;try{t=await ir(e)}catch(e){E(e);return}let r;try{r=JSON.parse(t)}catch(e){p({text:`Not JSON: ${e instanceof Error?e.message:String(e)}`,bad:!0});return}try{let e=await n.importFile(r);e[0]&&l(e[0].id),p({text:`Imported ${e.map(e=>e.name).join(`, `)}.`,bad:!1})}catch(e){E(e)}},ee=async()=>{x&&(await n.flush(x).catch(()=>{}),await I(n.exportUrl(x),e=>Qn(`dataset`,e.dataset?.name??``,e.version,`json`)))},I=async(e,t)=>{try{let n=await fetch(e);if(!n.ok)throw Error(`the export answered ${n.status}`);let r=await n.json();$n(new Blob([JSON.stringify(r,null,2)+`
4
- `],{type:`application/json`}),t(r))}catch(e){E(e)}},R=e=>{let n=D();n&&(Ae(t,x,n,`restore`),O(()=>structuredClone(e.doc)),_(!1),a.offer({label:`Restored the dataset`,restore:()=>O(()=>n)}))},z=!b,B=[{label:`New dataset`,icon:W,onSelect:()=>void j()},{label:`Rename`,icon:i,disabled:!C,onSelect:()=>d(!0)},{label:`Clone`,icon:U.clone,disabled:!C,onSelect:()=>void N()},{label:`Import JSON…`,icon:G,onSelect:()=>v.current?.click()},{label:`Export JSON`,icon:e,disabled:z,onSelect:()=>void ee()},{label:`Export all`,icon:On,disabled:!o?.length,onSelect:()=>void I(n.exportAllUrl(),e=>Qn(`datasets`,`all`,e.version,`json`))},{label:`Restore…`,icon:r,disabled:!w.length||!C,onSelect:()=>_(!0)},{label:`Edit raw…`,icon:En,disabled:!C,onSelect:()=>h(!0)},{label:`Delete`,icon:ne,destructive:!0,disabled:!C,onSelect:()=>void P()}];return(0,X.jsxs)(`div`,{className:`datasets`,children:[(0,X.jsxs)(A,{id:`datasets`,title:`Datasets`,actions:B,about:`Answers fixed in advance: a case for each item, saying what a reply to it should hold. A test grades against one.`,children:[o===null?(0,X.jsx)(`p`,{className:`note${s?` bad`:``}`,role:s?`alert`:void 0,children:s??`Loading…`}):o.length===0?(0,X.jsxs)(`div`,{className:`ds-empty`,children:[(0,X.jsx)(`p`,{className:`note`,children:`No datasets yet.`}),(0,X.jsxs)(`div`,{className:`ds-empty-actions`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`ghost ds-add`,onClick:()=>void j(),children:[(0,X.jsx)(W,{size:14,"aria-hidden":`true`}),`New dataset`]}),(0,X.jsxs)(`button`,{type:`button`,className:`ghost ds-add`,onClick:()=>v.current?.click(),children:[(0,X.jsx)(G,{size:14,"aria-hidden":`true`}),`Import JSON…`]})]})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`prop`,"data-control":u?`text`:`select`,children:[(0,X.jsx)(`span`,{className:`prop-name`,children:`Dataset`}),(0,X.jsx)(`span`,{className:`prop-value`,children:u&&C?(0,X.jsx)(`input`,{type:`text`,"aria-label":`Name`,defaultValue:C.name,autoFocus:!0,onFocus:e=>e.currentTarget.select(),onKeyDown:e=>{e.key===`Enter`?M(e.currentTarget.value):e.key===`Escape`&&d(!1)},onBlur:e=>{u&&M(e.currentTarget.value)}}):(0,X.jsx)(`select`,{"aria-label":`Dataset`,value:x,onChange:e=>{l(e.target.value),p(null)},children:o.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})})]}),b&&(0,X.jsxs)(`p`,{className:`ds-meta note`,children:[(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`b`,{children:b.cases}),` cases`]}),b.updated&&(0,X.jsxs)(`span`,{children:[`updated `,(0,X.jsx)(`b`,{children:sr(b.updated)})]})]})]}),f&&(0,X.jsx)(`p`,{className:`note${f.bad?` bad`:``}`,role:f.bad?`alert`:`status`,children:f.text}),S?.sync.state===`missing`&&(0,X.jsx)(`p`,{className:`note bad`,role:`alert`,children:S.sync.message}),(0,X.jsx)(`input`,{ref:v,type:`file`,accept:`.json,application/json`,hidden:!0,"aria-label":`Import JSON file`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&F(t)}})]}),g&&C&&(0,X.jsx)(L,{title:`Restore dataset`,onClose:()=>_(!1),children:(0,X.jsxs)(`div`,{className:`version-list`,children:[w.length===0&&(0,X.jsx)(`p`,{className:`note`,children:`No versions of this dataset yet.`}),w.map((e,t)=>(0,X.jsxs)(`div`,{className:`version-row`,children:[(0,X.jsxs)(`span`,{className:`version-when`,children:[sr(e.at),` · `,or(e.reason)]}),(0,X.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>R(e),children:`Restore`})]},`${e.at}-${t}`))]})}),m&&C&&(0,X.jsx)(er,{name:C.name,body:C.body,onSave:e=>{O(()=>e),h(!1)},onClose:()=>h(!1)}),(0,X.jsx)(T,{undo:a.undo,onUndo:a.undoNow,onDismiss:a.dismiss})]})}function ir(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result??``)),r.onerror=()=>n(r.error??Error(`The file could not be read.`)),r.readAsText(e)})}var ar=(e,t)=>{if(!t.has(e))return e;for(let n=2;;n++)if(!t.has(`${e} ${n}`))return`${e} ${n}`},or=e=>e===`idle`?`after editing`:e===`restore`?`before a restore`:e===`bulk`?`before a bulk edit`:e===`pack`?`before a pack update`:e,sr=e=>{let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()},cr={"promptlab.workflows":{list:[],at:``},"promptlab.profiles":{list:[],at:``},"promptlab.comment":null,"promptlab.versions":lr(),"promptlab.history.columns":null,"promptlab.tokens":null,"promptlab.mappings":ur()};function lr(){return{pipeline:{},profile:{},dataset:{}}}function ur(){return{datasets:{}}}var dr=[`promptlab.workflows`,`promptlab.profiles`,`promptlab.versions`,`promptlab.tokens`,`promptlab.mappings`],fr=16;function pr(e,t){if(!e)return null;let n=t.find(t=>t===e);if(n)return n;let r=e.toLowerCase();return t.find(e=>e.toLowerCase()===r)??null}function mr(e,t){return`/api/sources/${encodeURIComponent(e)}/thumbs/${encodeURIComponent(t)}`}function hr(e){return/\.(?:jpe?g|png|gif|webp|bmp|heic|heif|dng|tiff?)$/i.test(e)}function gr(e){return e?e.file?`mapped`:`nomatch`:`none`}async function _r(e,t,n,r){let i=new Date().toISOString(),a={id:n.id,name:n.name},o={},s=e.length;r?.(0,s);for(let n=0;n<s;n+=fr){for(let r of e.slice(n,n+fr))o[r]={source:a,at:i,file:pr(r,t)};r?.(Math.min(n+fr,s),s),await new Promise(e=>{setTimeout(e,0)})}return o}async function vr(e,t,n,r,i,a){let o=await _r(i,(await e.source(r.id)).files.map(e=>e.name),r,a);return xr(t,n,r,o),o}function yr(e,t){let n=e.get(`promptlab.mappings`).datasets?.[t];return{recents:n?.recents??[],cases:n?.cases??{}}}function br(e,t){return e.cases[t]??null}function xr(e,t,n,r){let i=e.get(`promptlab.mappings`),a=i.datasets??ur().datasets,o=a[t]??{recents:[],cases:{}},s=[{id:n.id,name:n.name,at:new Date().toISOString()},...o.recents.filter(e=>e.id!==n.id)].slice(0,5);e.set(`promptlab.mappings`,{...i,datasets:{...a,[t]:{recents:s,cases:{...o.cases,...r}}}})}function Sr(e,t,n){let r=e.get(`promptlab.mappings`),i=r.datasets??ur().datasets,a=i[t];if(!a||!(n in a.cases))return;let o={...a.cases};delete o[n],e.set(`promptlab.mappings`,{...r,datasets:{...i,[t]:{...a,cases:o}}})}function Cr(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function wr(e){return[e.every&&`Every reply`,e.not&&`Not`,e.of===`said`&&`API text`,e.weight!=null&&`Weight ${e.weight}`,e.metric&&`Group ${e.metric}`].filter(Boolean).join(`, `)}function Tr({label:e,metrics:t,set:n,undoable:r,over:i=`item`}){let a=K(),o=Object.entries(a.METRICS).map(([e,t])=>({value:e,label:t.label})),s=(e,r)=>n(t.map((t,n)=>n===e?r:t));return(0,X.jsx)(j,{noun:`metric`,items:[...t],empty:(0,X.jsx)(`p`,{className:`note`,children:`No metrics.`}),onAdd:()=>n([...t,{type:`contains`,...a.METRICS.contains.defaults()}]),onRemove:e=>r(t.filter((t,n)=>n!==e),`Removed a metric`),renderItem:(t,n,r)=>{let c=a.METRICS[t.type],l=(t.metric||c?.label||t.type)+(t.not?` (not)`:``),u=`${e.replace(/\W+/g,`-`).toLowerCase()}-metric-${n}`,d=!!(t.every||t.not||t.of||t.weight!=null||t.metric);return(0,X.jsxs)(A,{id:u,title:l,level:3,actions:r,about:c?.description,children:[(0,X.jsx)(k,{label:`${e}, metric ${n+1}`,rows:[{key:`type`,label:`Type`,control:{type:`select`,value:t.type,options:o,onChange:e=>s(n,{type:e,...a.METRICS[e].defaults(),...t.weight==null?{}:{weight:t.weight},...t.not?{not:!0}:{}})}},...(c?.options??[]).map(e=>M(e,t,e=>s(n,e)))]}),(0,X.jsx)(A,{id:`${u}-counts`,title:`How it counts`,level:3,open:d,note:d?wr(t):`Defaults`,children:(0,X.jsx)(k,{label:`${e}, metric ${n+1}, how it counts`,rows:[...i===`run`?[{key:`every`,label:`Every reply`,control:{type:`checkbox`,checked:!!t.every,onChange:e=>{let{every:r,...i}=t;s(n,e?{...i,every:!0}:i)}}}]:[],{key:`not`,label:`Not`,control:{type:`checkbox`,checked:!!t.not,onChange:e=>{let{not:r,...i}=t;s(n,e?{...i,not:!0}:i)}}},{key:`of`,label:`Grades`,control:{type:`select`,value:t.of??`reply`,options:[{value:`reply`,label:`Reply`},{value:`said`,label:`API text`}],onChange:e=>{let{of:r,...i}=t;s(n,e===`said`?{...i,of:`said`}:i)}}},{key:`weight`,label:`Weight`,control:{type:`text`,size:`num`,value:t.weight==null?``:String(t.weight),placeholder:`1`,onChange:e=>{let{weight:r,...i}=t;s(n,e.trim()?{...i,weight:/^-?\d+(\.\d+)?$/.test(e.trim())?Number(e):e}:i)}}},{key:`metric`,label:`Group`,control:{type:`text`,value:t.metric??``,onChange:e=>{let{metric:r,...i}=t;s(n,e.trim()?{...i,metric:e}:i)}}}]})})]},n)}})}var Er=[`expect`,`anyOf`,`forbid`,`allow`,`watch`],Dr={expect:`Expect`,anyOf:`Any of`,forbid:`Forbid`,allow:`Except`,minCount:`Min items`,maxCount:`Max items`,watch:`Watch for`,traits:`Traits`,discarded:`Discarded`,todo:`Todo`,why:`Why`},Or=600,kr=2e3,Ar=e=>({id:``,filename:e,todo:!0,traits:[],why:``,expect:[],anyOf:[],forbid:[],allow:[],minCount:null,maxCount:null,watch:[]}),jr=e=>{let t=e.map(e=>/^sample-(\d+)$/.exec(String(e?.id??``))?.[1]??0);return`sample-${String(Math.max(0,...t.map(Number))+1).padStart(3,`0`)}`};function Mr({filename:e,cases:t,onWrite:n,problem:r,resultFor:i,scenarioCount:a,files:o,onFile:s,onClose:c,run:l,preview:u,onRemove:d}){let m=t.findIndex(t=>K().caseFile(t)===e),h=m>=0?t[m]:Ar(e),[g,_]=(0,q.useState)(()=>structuredClone(h)),[v,y]=(0,q.useState)(0),[b,x]=(0,q.useState)(null),[S,C]=(0,q.useState)(null),[w,T]=(0,q.useState)(!1),[E,D]=(0,q.useState)(!1),k=(0,q.useRef)(g);k.current=g;let A=(0,q.useRef)(t);A.current=t;let j=(0,q.useRef)(null),M=(0,q.useRef)(null),N=(0,q.useCallback)(()=>{let t=k.current;A.current.findIndex(t=>K().caseFile(t)===e)<0&&!t.id&&(t={...t,id:jr(A.current)},k.current=t,_(t));let r=t;n(t=>Lr({cases:t},e,r))},[n,e]),P=(0,q.useCallback)(()=>{j.current&&clearTimeout(j.current),j.current=setTimeout(()=>{N(),D(!0),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>D(!1),kr)},Or)},[N]);(0,q.useEffect)(()=>()=>{j.current&&clearTimeout(j.current),M.current&&clearTimeout(M.current)},[]);let F=e=>{_(e),P()},ee=(e,t,n)=>{let r=t.trim();if(!r)return;let i=structuredClone(k.current);if(e===`anyOf`){let e=n??i.anyOf.length;(i.anyOf[e]||=[]).push(r)}else{let t=i[e];t&&!t.includes(r)&&(i[e]=[...t,r])}i.todo&&(e===`expect`||e===`anyOf`)&&(i.todo=!1),F(i)},I=(e,t,n)=>{let r=structuredClone(k.current);if(e===`anyOf`){let e=r.anyOf[n];e&&(e.splice(t,1),e.length||r.anyOf.splice(n,1))}else r[e].splice(t,1);F(r)},te=e=>g[e]??[],L=S&&S[v]?S[v]:i(v),R=!L||g.todo||L.error&&!g.discarded?null:K().scoreCase(g,L).pass,z=async()=>{if(l&&!w){T(!0),x(null);try{let t=await l(e);C(t),x(t.length?null:`No reply to grade.`)}catch(e){x(e instanceof Error?e.message:String(e))}finally{T(!1)}}},B=o.indexOf(e),V=e=>{let t=B<0?null:o[B+e];t&&s(t)};(0,q.useEffect)(()=>{let e=e=>{(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&(e.target?.closest?.(`input, textarea, select, [contenteditable]`)||(e.preventDefault(),V(e.key===`ArrowRight`?1:-1)))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)});let H=()=>{j.current&&(clearTimeout(j.current),j.current=null,N()),c()},U=[{key:`minCount`,label:Dr.minCount,control:{type:`text`,value:g.minCount==null?``:String(g.minCount),size:`num`,onChange:e=>F({...k.current,minCount:Pr(e)})}},{key:`maxCount`,label:Dr.maxCount,control:{type:`text`,value:g.maxCount==null?``:String(g.maxCount),size:`num`,onChange:e=>F({...k.current,maxCount:Pr(e)})}},{key:`discarded`,label:Dr.discarded,control:{type:`checkbox`,checked:!!g.discarded,label:`Expected`,onChange:e=>{let{discarded:t,...n}=k.current;F(e?{...n,discarded:!0}:n)}}},{key:`todo`,label:Dr.todo,control:{type:`checkbox`,checked:!!g.todo,label:`Not graded yet`,onChange:e=>F({...k.current,todo:e})}},{key:`why`,label:Dr.why,control:{type:`textarea`,value:g.why??``,onChange:e=>F({...k.current,why:e})}}],W=[];a>1&&W.push({key:`scenario`,label:`Show result of`,control:{type:`select`,value:String(v),options:Array.from({length:a},(e,t)=>({value:String(t),label:`Scenario ${t+1}`})),onChange:e=>y(Number(e))}}),R!=null&&W.push({key:`verdict`,label:`Result`,control:{type:`static`,text:R?`Pass`:`Fail`}});let G=[...u?[{key:`preview`,title:`Preview`,children:(0,X.jsxs)(`div`,{className:`cf-preview`,children:[(0,X.jsx)(`img`,{src:u.src,alt:u.file,loading:`lazy`}),(0,X.jsxs)(`p`,{className:`note`,children:[u.file,` in `,u.source]})]})}]:[],{key:`terms`,title:`Expectations`,children:(0,X.jsx)(`div`,{className:`caseform`,children:Er.map(e=>{let t=Dr[e];if(e===`anyOf`){let n=g.anyOf;return(0,X.jsxs)(`div`,{className:`cfrow`,children:[(0,X.jsx)(`span`,{className:`cflabel`,children:t}),(0,X.jsx)(`div`,{className:`cfgroups`,children:[...n??[],[]].map((t,r)=>(0,X.jsx)(Fr,{label:r===n?.length?`New group`:``,terms:t,stateFor:t=>Ir(g,e,t,r,L),onAdd:t=>ee(e,t,r),onDrop:t=>I(e,t,r)},r))})]},e)}return(0,X.jsxs)(`div`,{className:`cfrow`,children:[(0,X.jsx)(`span`,{className:`cflabel`,children:t}),(0,X.jsx)(Fr,{terms:te(e),stateFor:t=>Ir(g,e,t,void 0,L),onAdd:t=>ee(e,t),onDrop:t=>I(e,t)})]},e)})})},{key:`metrics`,title:`Metrics`,children:(0,X.jsx)(Tr,{label:`${e} metrics`,metrics:g.metrics??[],set:e=>{let{metrics:t,...n}=k.current;F(e.length?{...n,metrics:e}:n)},undoable:e=>{let{metrics:t,...n}=k.current;F(e.length?{...n,metrics:e}:n)}})},{key:`limits`,title:`Limits`,rows:U},...W.length?[{key:`result`,title:`Result`,rows:W}]:[]],re=[{label:`Previous`,icon:p,disabled:B<=0,onSelect:()=>V(-1)},{label:`Next`,icon:f,disabled:B<0||B>=o.length-1,onSelect:()=>V(1)},...l?[{label:`Run`,icon:Un,disabled:w,onSelect:()=>void z()}]:[]],ie=d?[{label:`Remove`,icon:ne,destructive:!0,onSelect:()=>{d(e),c()}}]:[],J=b??r??null;return(0,X.jsx)(O,{title:e||`Case`,status:J??(w?`Running…`:E?`Saved.`:Nr),...J?{statusBad:!0}:{},sections:G,...ie.length?{menu:ie}:{},actions:re,onClose:H})}var Nr=`Saved to the dataset as you edit.`,Pr=e=>{let t=e.trim();if(!t)return null;let n=Number(t);return Number.isInteger(n)&&n>0?n:null};function Fr({terms:e,stateFor:t,onAdd:n,onDrop:r,label:i}){let[a,o]=(0,q.useState)(``);return(0,X.jsxs)(`div`,{className:`cfchips`,children:[i&&(0,X.jsx)(`span`,{className:`cf-group-note`,children:i}),e.map((e,n)=>(0,X.jsxs)(`span`,{className:`chip${t(e)?` ${t(e)}`:``}`,children:[e,(0,X.jsx)(`button`,{type:`button`,className:`chipx`,"aria-label":`Remove ${e}`,onClick:()=>r(n),children:`×`})]},n)),(0,X.jsxs)(`form`,{className:`cfadd`,onSubmit:e=>{e.preventDefault(),n(a),o(``)},children:[(0,X.jsx)(`input`,{type:`text`,value:a,"aria-label":i||`Add`,placeholder:i||`Add`,autoComplete:`off`,spellCheck:!1,onChange:e=>o(e.target.value)}),(0,X.jsx)(`button`,{type:`submit`,className:`ghost`,"aria-label":`Add`,children:`+`})]})]})}function Ir(e,t,n,r,i){if(!i||i.error)return``;let a=i.terms||[];return t===`expect`||t===`watch`?K().termIn(a,n)?`met`:`unmet`:t===`forbid`?K().forbiddenIn(a,n,e.allow||[])?`unmet`:`met`:t===`anyOf`?K().termIn(a,n)?`met`:(e.anyOf?.[r??0]||[]).some(e=>K().termIn(a,e))?``:`unmet`:``}function Lr(e,t,n){let r=e.cases.findIndex(e=>K().caseFile(e)===t),i=structuredClone(e.cases);return r>=0?i[r]=structuredClone(n):i.push(structuredClone(n)),i}function Rr(e,t){return structuredClone(e.cases).filter(e=>K().caseFile(e)!==t)}var zr=(0,q.createContext)(null);function Br({children:e}){let t=Pe(),[n,r]=(0,q.useState)(null),i=Ie(n?.dataset??null),a=(0,q.useCallback)((e,t)=>{r({filename:e,...t})},[]),o=(0,q.useCallback)(e=>{r(t=>t&&{...t,filename:e})},[]),s=ge(),[c]=_e(`promptlab.mappings`),l=(0,q.useMemo)(()=>{if(!n)return;let e=br(yr(s,n.dataset),n.filename);return e?.file&&hr(e.file)?{src:mr(e.source.id,e.file),file:e.file,source:e.source.name}:void 0},[s,n,c]),u=n?.dataset??``,d=(0,q.useCallback)(e=>{t.edit(u,t=>({...t,cases:e(t.cases)}))},[t,u]),f=(0,q.useMemo)(()=>({openCaseEditor:a}),[a]),p=i?.doc;return(0,X.jsxs)(zr.Provider,{value:f,children:[e,n&&p&&(0,X.jsx)(Mr,{filename:n.filename,cases:p.body.cases,onWrite:d,problem:be(i.sync),resultFor:n.resultFor??(()=>null),scenarioCount:n.scenarioCount??0,files:n.files??[],onFile:o,...n.run?{run:n.run}:{},...l?{preview:l}:{},...n.onRemove?{onRemove:n.onRemove}:{},onClose:()=>r(null)},n.filename)]})}function Vr(){let e=(0,q.useContext)(zr);if(!e)throw Error(`useCaseEditor outside a CaseEditorProvider: the app mounts one at its root`);return e}function Hr({sources:e,recents:t,onPick:n,onClose:r}){let i=t.find(t=>e.some(e=>e.id===t.id))?.id??e[0]?.id??``,[a,o]=(0,q.useState)(i);(0,q.useEffect)(()=>{o(e=>e||i)},[i]);let s=t.filter(t=>e.some(e=>e.id===t.id));return(0,X.jsx)(L,{title:`Map against Source`,onClose:r,children:e.length===0?(0,X.jsx)(`p`,{className:`note`,children:`The lab holds no Sources to map against.`}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`prop`,children:[(0,X.jsx)(`span`,{className:`prop-name`,children:`Source`}),(0,X.jsx)(`span`,{className:`prop-value`,children:(0,X.jsx)(`select`,{"aria-label":`Source`,value:a,onChange:e=>o(e.target.value),children:e.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})})]}),s.length>0&&(0,X.jsxs)(`div`,{className:`ds-recents`,children:[(0,X.jsx)(`h3`,{className:`edit-section-title`,children:`Recent`}),(0,X.jsx)(`div`,{className:`ds-recent-list`,children:s.map(e=>(0,X.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>n({id:e.id,name:e.name}),children:e.name},e.id))})]}),(0,X.jsx)(`div`,{className:`ds-picker-actions`,children:(0,X.jsx)(`button`,{type:`button`,className:`edit-done`,onClick:()=>{let t=e.find(e=>e.id===a);t&&n({id:t.id,name:t.name})},disabled:!a,children:`Map`})})]})})}function Ur({filename:e,mapped:t,onClose:n}){let r=[{key:`source`,label:`Source`,required:!0,control:{type:`static`,text:t.source.name}},{key:`when`,label:`Mapped`,required:!0,control:{type:`static`,text:Cr(t.at)}},{key:`file`,label:`File`,required:!0,control:{type:`code`,text:t.file??``}}];return(0,X.jsx)(O,{title:e,sections:[{key:`mapping`,title:`Mapping`,rows:r}],onClose:n})}function Wr({rows:e,shown:t,filters:n,onFilters:r,selected:i,onSelect:a,selectionActions:o,mapping:s,onEdit:c,onAdd:l,onRemove:u,onMap:d,progress:f,onMapDetails:p,children:m}){let[h,g]=H(`dataset-cases`,20),[_,v]=(0,q.useState)(!1),y=e.filter(e=>!e.todo).length,b=[{label:`Map against Source…`,icon:Jn,disabled:!!f,onSelect:d},{label:`Page size`,icon:U.pageSize,onSelect:()=>v(!0)}],x=t.map(Z),S=new Set(x),C=[...i].filter(e=>!S.has(e)).length,T=x.filter(e=>i.has(e)).length,E=T>0&&T===x.length,O=e=>a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),k=[{key:`status`,label:`Status`,value:n.status,onChange:e=>r({status:e}),options:[{value:`all`,label:`All`},{value:`graded`,label:`Graded`},{value:`todo`,label:`Todo`}]},{key:`show`,label:`Show`,value:n.show,onChange:e=>r({show:e}),options:[{value:`all`,label:`All`},{value:`selected`,label:`Selected`}]}];return(0,X.jsxs)(A,{id:`cases`,title:`Cases`,note:`${y} graded · ${e.length-y} todo`,actions:b,children:[(0,X.jsx)(ee,{noun:`cases`,search:{label:`File`,placeholder:`Search files`,value:n.file,onChange:e=>r({file:e})},filters:k,count:{shown:t.length,total:e.length},lead:e.length>0&&(0,X.jsx)(`label`,{className:`ev-check ev-all`,children:(0,X.jsx)(Gr,{all:E,some:T>0,disabled:!t.length,onChange:()=>a(e=>{let t=new Set(e);for(let e of x)E?t.delete(e):t.add(e);return t})})})}),m,f&&(0,X.jsxs)(`p`,{className:`note ds-progress`,role:`status`,children:[`Mapping against `,f.source,`… `,f.done,` of `,f.total]}),e.length===0?(0,X.jsx)(`p`,{className:`note`,children:`No cases yet.`}):(0,X.jsxs)(X.Fragment,{children:[i.size>0&&(0,X.jsxs)(`div`,{className:`ev-select on`,"data-selected":i.size,children:[(0,X.jsxs)(`span`,{className:`ev-count`,children:[i.size,` selected`]}),C>0&&(0,X.jsxs)(`span`,{className:`ev-hidden`,children:[C,` hidden`]}),(0,X.jsxs)(`span`,{className:`ev-select-acts`,children:[(0,X.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>a(()=>new Set),children:`None`}),(0,X.jsx)(w,{label:`Selection actions`,actions:o})]})]}),t.length===0?(0,X.jsx)(`p`,{className:`note`,children:`No cases match these filters.`}):(0,X.jsx)(`div`,{className:`ds-cases`,children:(0,X.jsx)(D,{className:`dstable`,label:`Cases`,rows:t,pageSize:h,rowKey:e=>Z(e),rowProps:e=>({"data-selected":i.has(Z(e))||void 0}),columns:Kr(s,i,O,c,u,p)})})]}),(0,X.jsxs)(`button`,{type:`button`,className:`ghost ds-add`,onClick:l,children:[(0,X.jsx)(W,{size:14,"aria-hidden":`true`}),`Add case`]}),_&&(0,X.jsx)(F,{value:h,onChange:g,onClose:()=>v(!1)})]})}function Gr({all:e,some:t,disabled:n,onChange:r}){let i=(0,q.useRef)(null);return(0,q.useEffect)(()=>{i.current&&(i.current.indeterminate=t&&!e)},[t,e]),(0,X.jsx)(`input`,{ref:i,type:`checkbox`,"aria-label":`Select all shown`,checked:e,disabled:n,onChange:r})}function Kr(e,t,n,r,i,a){let o=t=>gr(e.cases[t.filename]??null),s=Object.values(e.cases).some(e=>gr(e??null)!==`none`),c=[{key:`pick`,header:(0,X.jsx)(`span`,{className:`ev-vh`,children:`Selected`}),label:``,className:`ev-pick`,sort:null,cell:e=>(0,X.jsx)(`label`,{className:`ev-check`,children:(0,X.jsx)(`input`,{type:`checkbox`,checked:t.has(Z(e)),onChange:()=>n(Z(e)),"aria-label":`Select ${e.filename}`})})},{key:`file`,header:`File`,sort:e=>e.filename,cell:e=>(0,X.jsx)(`button`,{type:`button`,className:`ds-file`,onClick:()=>r(e.filename),children:e.filename})},{key:`expectations`,header:`Expectations`,cell:e=>qr(e)},{key:`bounds`,header:`Count`,sort:e=>e.maxCount??e.minCount??null,tdProps:e=>({"data-state":Jr(e)?void 0:`none`}),cell:e=>Jr(e)??`—`},{key:`status`,header:`Status`,sort:e=>e.todo?`Todo`:`Graded`,cell:e=>(0,X.jsx)(`span`,{className:e.todo?`ds-todo`:void 0,children:e.todo?`Todo`:`Graded`})},{key:`map`,header:`Map`,sort:e=>({nomatch:`No match`,mapped:`Mapped`})[o(e)]??null,tdProps:e=>({"data-state":o(e)}),cell:e=>{let t=o(e);return t===`nomatch`?(0,X.jsx)(`span`,{className:`ds-nomatch`,children:`No match`}):t===`mapped`?(0,X.jsx)(`button`,{type:`button`,className:`ds-mapped`,onClick:()=>a(e.filename),children:`Mapped`}):null}},{key:`menu`,header:``,label:``,className:`ds-menu`,sort:null,cell:e=>(0,X.jsx)(w,{label:`${e.filename} actions`,actions:[{label:`Edit`,icon:U.edit,onSelect:()=>r(e.filename)},{label:`Remove`,icon:U.remove,destructive:!0,onSelect:()=>i(e.filename)}]})}];return s?c:c.filter(e=>e.key!==`map`)}var qr=e=>(e.expect??[]).length+(e.anyOf??[]).length+(e.metrics??[]).length,Jr=e=>{let t=e.minCount??null,n=e.maxCount??null;return t!=null&&n!=null?`${t}–${n}`:t==null?n==null?null:`≤${n}`:`≥${t}`},Yr={bounds:`Set count`,addTerm:`Add term`,removeTerm:`Remove term`,todo:`Mark Todo`,graded:`Mark graded`},Xr=[{value:`keep`,label:`Keep`},{value:`set`,label:`Set`},{value:`clear`,label:`Clear`}],Zr=e=>/^\s*\d+\s*$/.test(e)?Number(e):null;function Qr({kind:e,cases:t,keys:n,onApply:r,onClose:i}){let[a,o]=(0,q.useState)(`keep`),[s,c]=(0,q.useState)(`keep`),[l,u]=(0,q.useState)(``),[d,f]=(0,q.useState)(``),[p,m]=(0,q.useState)(`expect`),[h,g]=(0,q.useState)(``),[_,v]=(0,q.useState)(null),y=(0,q.useMemo)(()=>{switch(e){case`bounds`:{let e=a===`set`?Zr(l):null,t=s===`set`?Zr(d):null;return a===`set`&&e==null?`Min items needs a whole number.`:s===`set`&&t==null?`Max items needs a whole number.`:{type:`bounds`,min:a===`set`?{kind:`set`,n:e}:{kind:a},max:s===`set`?{kind:`set`,n:t}:{kind:s}}}case`addTerm`:return h.trim()?{type:`addTerm`,list:p,term:h}:`Name the term.`;case`removeTerm`:return h.trim()?{type:`removeTerm`,term:h}:`Name the term.`;case`todo`:return{type:`status`,todo:!0};case`graded`:return{type:`status`,todo:!1}}},[e,a,s,l,d,p,h]),b=(0,q.useMemo)(()=>{if(typeof y==`string`)return null;let{next:e,changed:r}=Ye(t,n,y);return{changed:r,problems:Xe(t,e,r)}},[y,t,n]),x=_??b?.problems??null,S=!!x&&x.cases.length>0,C=b?.changed.length??0,w=(0,q.useCallback)(()=>{if(typeof y==`string`)return;let e=r(y);e&&v(e)},[y,r]),T=e=>t=>{v(null),e(t)},E=[];return e===`bounds`&&(E.push({key:`min`,label:`Min items`,required:!0,control:{type:`select`,value:a,options:Xr,onChange:T(e=>o(e))}}),a===`set`&&E.push({key:`minN`,label:`Min`,required:!0,control:{type:`text`,value:l,size:`num`,onChange:T(u)}}),E.push({key:`max`,label:`Max items`,required:!0,control:{type:`select`,value:s,options:Xr,onChange:T(e=>c(e))}}),s===`set`&&E.push({key:`maxN`,label:`Max`,required:!0,control:{type:`text`,value:d,size:`num`,onChange:T(f)}})),e===`addTerm`&&E.push({key:`list`,label:`List`,required:!0,control:{type:`select`,value:p,onChange:T(e=>m(e)),options:[`expect`,`forbid`,`allow`].map(e=>({value:e,label:Qe(e)}))}}),(e===`addTerm`||e===`removeTerm`)&&E.push({key:`term`,label:`Term`,required:!0,control:{type:`text`,value:h,onChange:T(g)}}),(0,X.jsxs)(L,{title:Yr[e],onClose:i,className:`ev-bulk`,footer:(0,X.jsx)(`div`,{className:`edit-actions`,children:(0,X.jsx)(`button`,{type:`button`,className:`edit-done`,disabled:!C||S,onClick:w,children:`Apply`})}),children:[E.length>0&&(0,X.jsx)(k,{label:Yr[e],rows:E}),(0,X.jsx)(`p`,{className:`note ev-changes`,role:`status`,children:typeof y==`string`?y:`Changes ${C} of ${n.size}`}),S&&x&&(0,X.jsx)(`div`,{className:`ev-refusal`,role:`alert`,children:x.cases.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`p`,{className:`ev-refusal-head`,children:[x.cases.length,` of `,n.size,` would break`]}),(0,X.jsx)(`ul`,{children:x.cases.map(e=>(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`b`,{children:e.file}),` `,e.reasons.join(`; `)]},e.key))})]})})]})}function $r(){let e=J(),t=ge(),n=Pe(),r=te(),{openCaseEditor:i}=Vr(),{list:a}=Fe(),{datasetId:o,selected:s,setSelected:c,filters:l,setFilters:u,handedOver:d}=at(),[f,p]=(0,q.useState)([]),[m,h]=(0,q.useState)(!1),[g,v]=(0,q.useState)(null),[y,b]=(0,q.useState)(null),[x,S]=(0,q.useState)(null),[C,w]=(0,q.useState)(null),E=(0,q.useCallback)(()=>w(null),[]),[D]=_e(`promptlab.mappings`);(0,q.useEffect)(()=>{let t=!0;return e.sources().then(e=>{t&&p(e.sources)}).catch(()=>{}),()=>{t=!1}},[e]);let O=a?.find(e=>e.id===o)??a?.[0]??null,k=O?.id??``,A=Ie(k||null),j=A?.doc?.body??null,M=j?.cases,N=(0,q.useMemo)(()=>M?K().gradedSetFrom({cases:M}):[],[M]),P=(0,q.useMemo)(()=>yr(t,k),[t,k,D]),F=(0,q.useMemo)(()=>new Set(N.map(Z)),[N]),ee=(0,q.useMemo)(()=>new Set([...s].filter(e=>F.has(e))),[s,F]),I=(0,q.useMemo)(()=>nt(N,l,ee),[N,l,ee]),L=(0,q.useCallback)(()=>n.entry(k)?.doc?.body??null,[n,k]),R=(0,q.useCallback)(e=>{k&&n.edit(k,t=>({...t,cases:e}))},[n,k]),z=e=>{i(e,{dataset:k,files:I.map(e=>e.filename),onRemove:V})},B=()=>{let e=L()?.cases??[],t=ei(e);R([...e,{id:jr(e),filename:t,todo:!0,traits:[],why:``,expect:[],anyOf:[],forbid:[],allow:[],minCount:null,maxCount:null,watch:[]}]),i(t,{dataset:k,files:[...N.map(e=>e.filename),t],onRemove:V})};function V(e){let n=L()?.cases??[];R(Rr({cases:n},e)),k&&Sr(t,k,e),r.offer({label:`Removed ${e}`,restore:()=>R(n)})}let H=e=>{let i=L();if(!k||!i)return null;let{next:a,changed:o}=Ye(i.cases,ee,e);if(!o.length)return w(null),null;if(e.type!==`delete`){let e=Xe(i.cases,a,o);if(e.cases.length)return e}Ae(t,k,i,`bulk`);let s=i.cases;if(n.edit(k,e=>({...e,cases:a})),e.type===`delete`){let e=new Set(o);for(let n of s)e.has(Z(n))&&Sr(t,k,K().caseFile(n));c(t=>new Set([...t].filter(t=>!e.has(t))))}return r.offer({label:et(e,o.length),restore:()=>n.edit(k,e=>({...e,cases:s}))}),w(null),null},W=ee.size===0,ne=[{label:`Set count…`,icon:_,disabled:W,onSelect:()=>w(`bounds`)},{label:`Add term…`,icon:U.add,disabled:W,onSelect:()=>w(`addTerm`)},{label:`Remove term…`,icon:Bn,disabled:W,onSelect:()=>w(`removeTerm`)},{label:`Mark Todo…`,icon:xn,disabled:W,onSelect:()=>w(`todo`)},{label:`Mark graded…`,icon:Sn,disabled:W,onSelect:()=>w(`graded`)},{label:`Delete`,icon:U.remove,destructive:!0,disabled:W,onSelect:()=>void H({type:`delete`})}],G=async n=>{h(!1),S(null),b({done:0,total:N.length,source:n.name});try{await vr(e,t,k,n,N.map(e=>e.filename),(e,t)=>b({done:e,total:t,source:n.name}))}catch(e){S(e instanceof Error?e.message:String(e))}finally{b(null)}};return(0,X.jsxs)(`div`,{className:`evals`,children:[a?.length?(0,X.jsxs)(Wr,{rows:N,shown:I,filters:l,onFilters:u,selected:ee,onSelect:c,selectionActions:ne,mapping:P,onEdit:z,onAdd:B,onRemove:V,onMap:()=>h(!0),...y?{progress:y}:{},onMapDetails:v,children:[d&&O&&(0,X.jsxs)(`p`,{className:`note ev-from`,role:`status`,children:[(0,X.jsxs)(`span`,{children:[`From `,d.from]}),d.found<d.wanted&&(0,X.jsxs)(`span`,{children:[d.found,` of `,d.wanted,` are in `,O.name,` now`]})]}),A?.sync.state===`missing`&&(0,X.jsx)(`p`,{className:`note bad`,role:`alert`,children:A.sync.message}),x&&(0,X.jsx)(`p`,{className:`note bad ds-map-say`,role:`alert`,children:x})]}):null,C&&j&&(0,X.jsx)(Qr,{kind:C,cases:j.cases,keys:ee,onApply:H,onClose:E}),m&&(0,X.jsx)(Hr,{sources:f,recents:P.recents,onPick:e=>void G(e),onClose:()=>h(!1)}),g&&P.cases[g]&&(0,X.jsx)(Ur,{filename:g,mapped:P.cases[g],onClose:()=>v(null)}),(0,X.jsx)(T,{undo:r.undo,onUndo:r.undoNow,onDismiss:r.dismiss})]})}var ei=e=>{let t=new Set(e.map(e=>K().caseFile(e)));for(let e=1;;e++){let n=e===1?`untitled`:`untitled-${e}`;if(!t.has(n))return n}},ti=[{value:`all`,label:`All`},{value:`used`,label:`Used`},{value:`unused`,label:`Unused`}],ni=[{value:`all`,label:`All`},{value:`scenario`,label:`Used by this scenario`},{value:`scenarios`,label:`Used by all scenarios`}];function ri(e,t,n){let r=t.trim().toLowerCase();return r&&!e.name.toLowerCase().includes(r)&&!e.text.toLowerCase().includes(r)?!1:n===`all`||n===`used`==e.useCount>0}function ii(e,t,n,r){let i=t.trim().toLowerCase();return i&&!e.name.toLowerCase().includes(i)&&!e.text.toLowerCase().includes(i)?!1:n===`scenario`?r.byScenario.has(e.id):n!==`scenarios`||r.byAll.has(e.id)}var ai=e=>{let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()};function oi({id:e,onClose:t,onDuplicate:n,onDelete:r}){let i=We(),a=Ke(e),{openRun:o}=ct(),[s,c]=(0,q.useState)(new Set),[l,u]=(0,q.useState)(new Set),[d,f]=(0,q.useState)(null),p=a?.doc;if(!p)return(0,X.jsx)(O,{title:`Prompt`,status:a?.sync.state===`missing`?a.sync.message:`Loading…`,statusBad:a?.sync.state===`missing`,sections:[],onClose:t});let h=(e,t,n)=>{let r=new Set(e);r.has(t)?r.delete(t):r.add(t),n(r)},g=e=>f(e instanceof Error?e.message:String(e)),_=e=>p.versions.find(t=>t.version===e)?.text??``,v=p.uses.some(e=>e.job>0),y=[{key:`version`,header:`Version`,sort:e=>e.version,cell:e=>`v${e.version}${e.version===p.version?` (newest)`:``}`},{key:`created`,header:`Made`,sort:e=>e.created,cell:e=>ai(e.created)},{key:`uses`,header:`Uses`,className:`pl-num`,sort:e=>e.uses,cell:e=>e.uses},{key:`menu`,header:``,label:``,className:`pl-menu`,sort:null,cell:t=>(0,X.jsx)(w,{label:`v${t.version} actions`,actions:[{label:s.has(t.version)?`Hide words`:`Show words`,icon:m,onSelect:()=>h(s,t.version,c)},{label:`Restore`,icon:E,disabled:t.version===p.version,onSelect:()=>{f(null),i.restoreVersion(e,t.version).catch(g)}}]})}],b=e=>`${e.runId}:${e.scenarioId}:${e.job}`,x=[{key:`run`,header:`Run`,sort:e=>e.submittedAt,cell:e=>(0,X.jsx)(`a`,{className:`pl-run`,href:`#/history`,onClick:n=>{n.preventDefault(),t(),o(e.runId,{at:e.submittedAt,from:`history`})},children:Ct(e.submittedAt)})},{key:`scenario`,header:`Scenario`,sort:e=>e.scenarioName,cell:e=>e.scenarioName},...v?[{key:`job`,header:`Job`,className:`pl-num`,sort:e=>e.job,cell:e=>e.job+1}]:[],{key:`version`,header:`Version`,sort:e=>e.version,cell:e=>`v${e.version}`},{key:`when`,header:`When`,sort:e=>e.submittedAt,cell:e=>ai(e.submittedAt)},{key:`menu`,header:``,label:``,className:`pl-menu`,sort:null,cell:e=>(0,X.jsx)(w,{label:`${Ct(e.submittedAt)} ${e.scenarioName} actions`,actions:[{label:l.has(b(e))?`Hide words`:`Show words`,icon:m,onSelect:()=>h(l,b(e),u)}]})}],S=[{label:`Set as default`,icon:Kn,disabled:p.default,onSelect:()=>{f(null),i.setDefault(e).catch(g)}},{label:`Duplicate`,icon:U.clone,onSelect:()=>n(p)},{label:`Delete`,icon:U.remove,destructive:!0,disabled:p.default,onSelect:()=>r(p)}],C=d??Re(a.sync),T=a.sync.state===`conflict`;return(0,X.jsx)(O,{title:Le(p),status:C??void 0,statusBad:!!C,menu:S,wide:!0,actions:T?[{label:`Take theirs`,onSelect:()=>void i.resolve(e,`theirs`)},{label:`Keep mine`,onSelect:()=>void i.resolve(e,`mine`)}]:[],onClose:()=>{i.flush(e),t()},sections:[{key:`prompt`,rows:[{key:`name`,label:`Name`,control:{type:`text`,value:p.name,placeholder:`First line`,onChange:t=>i.edit(e,{name:t})}},{key:`version`,label:`Version`,required:!0,control:{type:`static`,text:`v${p.version}${p.default?` (Default)`:``}`}},{key:`text`,label:`Prompt`,required:!0,control:{type:`textarea`,value:p.text,placeholder:`None`,onChange:t=>i.edit(e,{text:t})}}]},{key:`versions`,title:`Versions`,children:(0,X.jsx)(D,{className:`pltable pl-versions`,label:`Versions`,rows:p.versions,rowKey:e=>String(e.version),columns:y,after:e=>s.has(e.version)&&(0,X.jsx)(`tr`,{className:`pl-words-row`,children:(0,X.jsx)(`td`,{colSpan:y.length,children:(0,X.jsx)(`pre`,{className:`pl-words`,children:e.text})})})})},{key:`uses`,title:`Uses`,children:p.uses.length===0?(0,X.jsx)(`p`,{className:`note`,children:`No uses yet.`}):(0,X.jsx)(D,{className:`pltable pl-uses`,label:`Uses`,rows:p.uses,rowKey:b,pageSize:10,columns:x,after:e=>l.has(b(e))&&(0,X.jsx)(`tr`,{className:`pl-words-row`,children:(0,X.jsx)(`td`,{colSpan:x.length,children:(0,X.jsx)(`pre`,{className:`pl-words`,children:_(e.version)})})})})}]})}function si(){let e=We(),{list:t,error:n}=Ge(),r=te(),[i,a]=H(`prompts`,20),[o,s]=(0,q.useState)(!1),[c,l]=(0,q.useState)(``),[u,d]=(0,q.useState)(`all`),[f,p]=(0,q.useState)(null),[m,h]=(0,q.useState)(null),g=t??[],_=g.filter(e=>ri(e,c,u)),v=e=>h(e instanceof Error?e.message:String(e)),y=async()=>{h(null);try{p((await e.create({name:``,text:``})).id)}catch(e){v(e)}},b=async t=>{h(null);try{await e.flush(t.id);let n=await e.create({name:`${Le(t)} copy`,text:e.entry(t.id)?.doc?.text??t.text});p(n.id)}catch(e){v(e)}},x=async t=>{h(null);try{let n=await e.remove(t.id);f===t.id&&p(null),r.offer({label:`Deleted ${Le(t)}`,restore:()=>{e.restore(n).catch(v)}})}catch(e){v(e)}},S=t=>{h(null),e.setDefault(t.id).catch(v)},C=e=>[{label:`Edit`,icon:U.edit,onSelect:()=>p(e.id)},{label:`Set as default`,icon:Kn,disabled:e.default,onSelect:()=>S(e)},{label:`Duplicate`,icon:U.clone,onSelect:()=>void b(e)},{label:`Delete`,icon:U.remove,destructive:!0,disabled:e.default,onSelect:()=>void x(e)}];return(0,X.jsxs)(A,{id:`prompts`,title:`Prompt library`,note:t?`${g.length} ${g.length===1?`prompt`:`prompts`}`:void 0,actions:[{label:`Page size`,icon:U.pageSize,onSelect:()=>s(!0)}],about:`Wordings kept with every version and the runs that used them. The Default is the one a new scenario starts from.`,children:[t===null?(0,X.jsx)(`p`,{className:`note${n?` bad`:``}`,role:n?`alert`:void 0,children:n??`Loading…`}):g.length===0?(0,X.jsx)(`p`,{className:`note`,children:`No prompts yet.`}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ee,{noun:`prompts`,search:{label:`Search prompts`,placeholder:`Search prompts`,value:c,onChange:l},filters:[{key:`show`,label:`Show`,value:u,onChange:e=>d(e),options:ti}],count:{shown:_.length,total:g.length}}),_.length===0?(0,X.jsx)(`p`,{className:`note`,children:`No prompts match these filters.`}):(0,X.jsx)(D,{className:`pltable`,label:`Prompts`,rows:_,rowKey:e=>e.id,pageSize:i,rowProps:e=>({"data-default":e.default||void 0}),columns:[{key:`prompt`,header:`Prompt`,sort:e=>Le(e).toLowerCase(),cell:e=>(0,X.jsxs)(`button`,{type:`button`,className:`pl-open`,onClick:()=>p(e.id),children:[(0,X.jsxs)(`span`,{className:`pl-title`,children:[Le(e),e.default&&(0,X.jsx)(`span`,{className:`pl-default`,children:`Default`})]}),e.name.trim()&&e.text.trim()&&(0,X.jsx)(`span`,{className:`pl-preview`,children:e.text.trim()})]})},{key:`version`,header:`Version`,className:`pl-num`,sort:e=>e.version,cell:e=>`v${e.version}`},{key:`uses`,header:`Uses`,className:`pl-num`,sort:e=>e.useCount,cell:e=>e.useCount},{key:`last`,header:`Last used`,sort:e=>e.lastUsed??null,tdProps:e=>({"data-state":e.lastUsed?void 0:`none`}),cell:e=>e.lastUsed?ai(e.lastUsed):`—`},{key:`menu`,header:``,label:``,className:`pl-menu`,sort:null,cell:e=>(0,X.jsx)(w,{label:`${Le(e)} actions`,actions:C(e)})}]})]}),m&&(0,X.jsx)(`p`,{className:`note bad`,role:`alert`,children:m}),(0,X.jsxs)(`button`,{type:`button`,className:`ghost pl-add`,onClick:()=>void y(),children:[(0,X.jsx)(W,{size:14,"aria-hidden":`true`}),`Add prompt`]}),f&&(0,X.jsx)(oi,{id:f,onClose:()=>p(null),onDuplicate:e=>void b(e),onDelete:e=>void x(e)}),o&&(0,X.jsx)(F,{value:i,onChange:a,onClose:()=>s(!1)}),(0,X.jsx)(T,{undo:r.undo,onUndo:r.undoNow,onDismiss:r.dismiss})]})}var ci=`evals-lab.sources`,li={view:`thumbs`,sort:`name`,dir:1};function ui(){try{let e=window.localStorage.getItem(ci);if(e){let t=JSON.parse(e);if(t.view===`thumbs`||t.view===`list`)return{view:t.view,sort:t.sort===`added`||t.sort===`size`?t.sort:`name`,dir:t.dir===-1?-1:1}}}catch{}return li}function di(e){try{window.localStorage.setItem(ci,JSON.stringify(e))}catch{}}var fi=e=>{let t=e.lastIndexOf(`.`);return t<0?``:e.slice(t).toLowerCase()},pi=[`.heic`,`.heif`,`.dng`,`.tif`,`.tiff`],mi=[`.jpg`,`.jpeg`,`.png`],hi=e=>mi.includes(fi(e))||pi.includes(fi(e)),gi=(e,t)=>`/api/sources/${encodeURIComponent(e)}/thumbs/${encodeURIComponent(t.name)}${t.v?`?v=${t.v}`:``}`,_i=(e,t)=>pi.includes(fi(t.name))?`/api/sources/${encodeURIComponent(e)}/zoom/${encodeURIComponent(t.name)}`:`/api/sources/${encodeURIComponent(e)}/files/${encodeURIComponent(t.name)}`;function vi(e,t,n){let r=[...e];return r.sort((e,r)=>{let i;return i=t===`size`?e.bytes-r.bytes:t===`added`?(e.added??0)-(r.added??0):e.name.localeCompare(r.name,void 0,{numeric:!0,sensitivity:`base`}),i*n}),r}function yi(e,t){let n=t.trim().toLowerCase();return n?e.filter(e=>e.name.toLowerCase().includes(n)):[...e]}function bi(e){if(e<1024)return`${e} B`;let t=[`KB`,`MB`,`GB`,`TB`],n=e,r=-1;do n/=1024,r+=1;while(n>=1024&&r<t.length-1);let i=Math.round(n*10)/10;return`${Number.isInteger(i)?i:i.toFixed(1)} ${t[r]}`}function xi(e){return new Date(e*1e3).toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`})}function Si(e){return{id:e.id,name:e.name,system:e.system,type:e.type,files:e.files.length,bytes:e.bytes}}var Ci=`[redacted]`,wi=/^(?:api[-_]?key|x-api-key|authorization|ocp-apim-subscription-key|password|secret|client[-_]?secret|token|access[-_]?token|refresh[-_]?token|sig)$/i,Ti=/^(?:headers|authentication)$/,Ei=[[/sk-ant-[A-Za-z0-9_-]+/g,Ci],[/sk-[A-Za-z0-9_-]{20,}/g,Ci],[/Bearer\s+[A-Za-z0-9._~+/=-]+/g,`Bearer ${Ci}`],[/eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g,Ci],[/([?&](?:sig|code)=)[^&"\s]+/g,`$1${Ci}`]];function Di(e){let t=0,n=e=>{let n=e;for(let[e,r]of Ei)n=n.replace(e,(...e)=>(t++,r.replace(`$1`,e[1]??``)));return n},r=e=>{if(Array.isArray(e))return e.map(r);if(e&&typeof e==`object`){let n={};for(let[i,a]of Object.entries(e))Ti.test(i)&&a&&typeof a==`object`&&!Array.isArray(a)?n[i]=Object.fromEntries(Object.keys(a).map(e=>(t++,[e,Ci]))):Ti.test(i)&&typeof a==`string`||wi.test(i)&&a!=null&&typeof a!=`object`?(t++,n[i]=Ci):n[i]=r(a);return n}return typeof e==`string`?n(e):e};return{value:r(e),count:t}}var Oi=`https://api.flow.microsoft.com/providers/Microsoft.ProcessSimple`,ki=`api-version=2016-11-01`,Ai=/\.powerplatformusercontent\.com$/,ji=4,Mi=4;function Ni(e,t=(e,t)=>fetch(e,t)){let n=async n=>{let r=`${Oi}${n}${n.includes(`?`)?`&`:`?`}${ki}`;if(!r.startsWith(`https://api.flow.microsoft.com/providers/Microsoft.ProcessSimple/`))throw Error(`the Flow API is the only address a Microsoft token goes to`);let i=await t(r,{headers:{Authorization:`Bearer ${await e()}`}}),a=await i.text(),o=null;try{o=JSON.parse(a)}catch{}if(!i.ok){let e=o?.error?.code;throw Error(`Power Automate answered ${i.status}${e?` (${e})`:``}`)}return o},r=encodeURIComponent,i=e=>({status:e?.status??``,startTime:e?.startTime??null,error:e?.error??null,inputsLink:e?.inputsLink?.uri??null,outputsLink:e?.outputsLink?.uri??null,at:Object.fromEntries((e?.repetitionIndexes??[]).filter(e=>e.scopeName&&typeof e.itemIndex==`number`).map(e=>[e.scopeName,e.itemIndex]))}),a=e=>{let t=new URL(e);return t.searchParams.delete(`api-version`),`${t.pathname.slice(new URL(Oi).pathname.length)}${t.search}`},o=(e,t)=>`/environments/${r(e)}/flows/${r(t)}/runs`,s=0,c=[],l=async()=>{if(s<ji){s++;return}await new Promise(e=>c.push(e))},u=()=>{let e=c.shift();e?e():s--};return{environments:async()=>((await n(`/environments`)).value??[]).map(e=>({id:e.name,name:e.properties?.displayName||e.name,isDefault:!!e.properties?.isDefault})),flows:async e=>((await n(`/environments/${r(e)}/flows`)).value??[]).map(e=>({id:e.name,name:e.properties?.displayName||e.name,state:e.properties?.state??``})),flow:async(e,t)=>{let i=await n(`/environments/${r(e)}/flows/${r(t)}`);return{id:i.name,name:i.properties?.displayName||i.name,definition:i.properties?.definition??{}}},runs:async(e,t,r=250)=>{let i=[],s=o(e,t);for(;s&&i.length<r;){let e=await n(s);for(let t of e.value??[])i.push({id:t.name,status:t.properties?.status??``,startTime:t.properties?.startTime??null,error:t.properties?.error??null});s=e.nextLink?.startsWith(`https://api.flow.microsoft.com/providers/Microsoft.ProcessSimple/`)?a(e.nextLink):null}return i.slice(0,r)},run:async(e,t,a)=>{let s=await n(`${o(e,t)}/${r(a)}?$expand=properties/actions`),c=s.properties??{};return{run:{id:s.name,status:c.status??``,startTime:c.startTime??null,error:c.error??null},trigger:c.trigger?i(c.trigger):null,actions:Object.fromEntries(Object.entries(c.actions??{}).map(([e,t])=>[e,i(t)]))}},repetitions:async(e,t,a,s)=>((await n(`${o(e,t)}/${r(a)}/actions/${r(s)}/repetitions`)).value??[]).map(e=>i(e.properties)),content:async e=>{let n=new URL(e);if(n.protocol!==`https:`||!Ai.test(n.hostname))throw Error(`that is not run history's content`);await l();try{for(let n=1;;n++){let r=await t(e,{});if(r.status===429&&n<Mi){let e=Number(r.headers.get(`Retry-After`));await new Promise(t=>setTimeout(t,(e>0?e:n)*1e3));continue}if(!r.ok)throw Error(`run history answered ${r.status}`);let i=await r.text();try{return JSON.parse(i)}catch{return i}}}finally{u()}}}}var Pi=[`https://service.flow.microsoft.com//.default`],Fi=null;function Ii(e){let t=`${e.clientId}/${e.tenant}`;return Fi?.key!==t&&(Fi={key:t,pca:ce(()=>import(`./dist-DI3ewZYj.js`).then(async t=>{let n=await t.createStandardPublicClientApplication({auth:{clientId:e.clientId,authority:`https://login.microsoftonline.com/${e.tenant}`,redirectUri:`${window.location.origin}/`,OIDCOptions:{responseMode:t.ResponseMode.QUERY}},cache:{cacheLocation:`sessionStorage`}}),r=await n.handleRedirectPromise();return r?.account&&n.setActiveAccount(r.account),n}),[])}),Fi.pca}var Li=()=>{let e=new URLSearchParams(window.location.search);return e.has(`state`)&&(e.has(`code`)||e.has(`error`))};async function Ri(e){await Ii(e)}async function zi(e){let t=await Ii(e);return(t.getActiveAccount()??t.getAllAccounts()[0]??null)?.username??null}async function Bi(e,t=window.location.href){await(await Ii(e)).loginRedirect({scopes:Pi,prompt:`select_account`,redirectStartPage:t})}async function Vi(e){let t=await Ii(e),n=t.getActiveAccount()??t.getAllAccounts()[0];n&&await t.clearCache({account:n})}async function Hi(e){let t=await Ii(e),n=t.getActiveAccount()??t.getAllAccounts()[0];if(!n)throw Error(`sign in to Microsoft first`);try{return(await t.acquireTokenSilent({scopes:Pi,account:n})).accessToken}catch(e){let{InteractionRequiredAuthError:r}=await ce(async()=>{let{InteractionRequiredAuthError:e}=await import(`./dist-DI3ewZYj.js`);return{InteractionRequiredAuthError:e}},[]);throw e instanceof r&&await t.acquireTokenRedirect({scopes:Pi,account:n,redirectStartPage:window.location.href}),e}}function Ui(){let e=J(),[t,n]=(0,q.useState)(void 0);return(0,q.useEffect)(()=>{let t=!0;return e.config().then(e=>{t&&n(e.microsoft??null)},()=>{t&&n(null)}),()=>{t=!1}},[e]),t}var Wi=e=>Ni(()=>Hi(e));async function Gi(e,t,n){let r=await e.flow(t,n);return{name:r.name,definition:Di(r.definition).value}}function Ki({onMade:e}){let t=J(),n=Ui(),r=(0,q.useMemo)(()=>n?Wi(n):null,[n]),[i,a]=(0,q.useState)(void 0),[o,s]=(0,q.useState)(null),[c,l]=(0,q.useState)(``),[u,d]=(0,q.useState)(null),[f,p]=(0,q.useState)(``),[m,h]=(0,q.useState)(``),[g,_]=(0,q.useState)(!1),[v,y]=(0,q.useState)(null),b=e=>y(e instanceof Error?e.message:String(e));if((0,q.useEffect)(()=>{n&&zi(n).then(a,()=>a(null))},[n]),(0,q.useEffect)(()=>{r&&i&&r.environments().then(e=>{s(e),l((e.find(e=>e.isDefault)??e[0])?.id??``)},b)},[r,i]),(0,q.useEffect)(()=>{r&&c&&(d(null),p(``),r.flows(c).then(e=>{d(e),p(e[0]?.id??``),h(e[0]?.name??``)},b))},[r,c]),n===void 0||n&&i===void 0)return(0,X.jsx)(`p`,{className:`note`,children:`Loading…`});if(n===null)return(0,X.jsx)(`p`,{className:`note`,children:`Microsoft: Not Configured`});if(!i)return(0,X.jsxs)(`div`,{className:`sacts`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`ghost`,onClick:()=>void Bi(n).catch(b),children:[(0,X.jsx)(Ln,{size:14,"aria-hidden":`true`}),` Sign in with Microsoft`]}),v&&(0,X.jsx)(`p`,{className:`note bad`,role:`alert`,children:v})]});let x=async()=>{if(!r||!f||!m.trim())return;_(!0),y(null);let n=null;try{let i=u?.find(e=>e.id===f),a=await t.createSource(m.trim(),`power-automate`,{environment:c,flow:f,displayName:i?.name??f});n=a.id;let o=await Gi(r,c,f);await t.saveDefinition(a.id,0,o.definition),await e()}catch(e){n&&await t.removeSource(n).catch(()=>{}),b(e instanceof pe?Error(e.message):e)}finally{_(!1)}};return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(k,{label:`Flow`,rows:[{key:`account`,label:`Account`,control:{type:`static`,text:i}},{key:`env`,label:`Environment`,control:o?{type:`select`,value:c,options:o.map(e=>({value:e.id,label:e.name})),onChange:l}:{type:`static`,text:`Loading…`}},{key:`flow`,label:`Flow`,control:u?{type:`select`,value:f,options:u.map(e=>({value:e.id,label:e.name})),onChange:e=>{p(e),h(u.find(t=>t.id===e)?.name??``)}}:{type:`static`,text:c?`Loading…`:`—`}},{key:`name`,label:`Name`,control:{type:`text`,value:m,onChange:h}}]}),u&&!u.length&&(0,X.jsx)(`p`,{className:`note`,children:`No flows in this environment.`}),v&&(0,X.jsx)(`p`,{className:`note bad`,role:`alert`,children:v}),(0,X.jsx)(`div`,{className:`sacts`,children:(0,X.jsx)(`button`,{type:`button`,className:`ghost`,disabled:g||!f||!m.trim(),onClick:()=>void x(),children:`Add`})})]})}var qi=`evals-lab/record`,$=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Ji=/\b(triggerBody|triggerOutputs|body|outputs|actions|variables|items|item|parameters)\(\s*(?:'((?:[^']|'')*)')?\s*\)/g;function Yi(e,t=[]){if(typeof e==`string`){e.startsWith(`@`)&&!e.startsWith(`@@`)&&!e.startsWith(`@{`)&&t.push(e.slice(1));for(let n of e.matchAll(/@\{([^}]*)\}/g))t.push(n[1])}else if(Array.isArray(e))for(let n of e)Yi(n,t);else if($(e))for(let n of Object.values(e))Yi(n,t);return t}function Xi(e,t=null){let n=new Map;for(let r of Yi(e))for(let e of r.matchAll(Ji)){let r=e[1],i=(e[2]??``).replace(/''/g,`'`),a=r===`triggerBody`||r===`triggerOutputs`?{from:`trigger`}:r===`body`||r===`outputs`||r===`actions`?i?{from:`action`,name:i}:null:r===`variables`?i?{from:`variable`,name:i}:null:r===`items`?i?{from:`item`,name:i}:null:r===`item`?t?{from:`item`,name:t}:null:i?{from:`parameter`,name:i}:null;a&&n.set(JSON.stringify(a),a)}return[...n.values()]}function Zi(e,t){let n={};for(let e of t)e.from===`trigger`?n.trigger={body:null}:e.from===`action`?(n.actions??={})[e.name]={body:null}:e.from===`variable`?(n.variables??={})[e.name]=null:e.from===`item`&&((n.items??={})[e.name]=null);return{format:qi,version:1,step:e,at:null,scope:n,request:null,result:null,origin:{kind:`hand`}}}function Qi(e){if(e.origin?.kind===`run`&&e.origin.run)return JSON.stringify({step:e.step,run:e.origin.run,iteration:e.origin.iteration??``});let t=e=>Array.isArray(e)?e.map(t):$(e)?Object.fromEntries(Object.keys(e).sort().map(n=>[n,t(e[n])])):e;return JSON.stringify(t({step:e.step,scope:e.scope,request:e.request}))}var $i=Object.create(null);$i.Http={label:`HTTP`,template:({headers:e,authentication:t,...n})=>n};var ea=Object.create(null);ea.Foreach={loops:!0},ea.Until={loops:!0},ea.InitializeVariable={declares:e=>(Array.isArray(e.variables)?e.variables:[]).flatMap(e=>$(e)&&typeof e.name==`string`?[e.name]:[])};var ta=e=>!!(e&&ea[e]?.loops);function na(e){let t=[],n=(e,r)=>{for(let[i,a]of Object.entries(e??{})){let e=a.type?$i[a.type]:void 0;if(e&&$(a.inputs)){let n=e.template(a.inputs);t.push({name:i,kind:a.type,loops:r,template:n,reads:Xi(n,r.at(-1)??null)})}let o=ta(a.type)?[...r,i]:r;n(a.actions,o),n(a.else?.actions,o);for(let e of Object.values(a.cases??{}))n(e.actions,o);n(a.default?.actions,o)}};return n($(e)?e.actions:void 0,[]),t}function ra(e){let t={},n=(e,r)=>{for(let[i,a]of Object.entries(e??{})){t[i]={...a,loops:r};let e=ta(a.type)?[...r,i]:r;n(a.actions,e),n(a.else?.actions,e);for(let t of Object.values(a.cases??{}))n(t.actions,e);n(a.default?.actions,e)}};return n($(e)?e.actions:void 0,[]),t}async function ia(e,t,n,r){let i=ra(r),a={};for(let r of e.reads)if(r.from===`trigger`){let e=await n.triggerOutputs();a.trigger={body:$(e)?e.body:e}}else if(r.from===`action`){let e=await n.actionOutputs(r.name,t.at);(a.actions??={})[r.name]=$(e)?{body:e.body,...typeof e.statusCode==`number`?{statusCode:e.statusCode}:{}}:{body:e}}else if(r.from===`variable`){let e=e=>{let t=e.type?ea[e.type]:void 0;return!!t?.declares&&$(e.inputs)&&t.declares(e.inputs).includes(r.name)},o=Object.entries(i).find(([,t])=>e(t)),s=o?await n.actionInputs(o[0],t.at):null,c=($(s)&&Array.isArray(s.variables)?s.variables:[]).find(e=>$(e)&&e.name===r.name);(a.variables??={})[r.name]=c?c.value:null}else if(r.from===`item`){let e=await n.actionInputs(r.name,t.at),i=$(e)&&Array.isArray(e.foreachItems)?e.foreachItems:[];(a.items??={})[r.name]=i[t.at[r.name]??0]??null}let o=$(t.inputs)?t.inputs:null,s=$(t.outputs)?t.outputs:null;return{format:qi,version:1,step:e.name,at:t.startTime,scope:a,request:o?{method:String(o.method??``),uri:String(o.uri??``),body:o.body??null}:null,result:t.error&&!s?{error:t.error}:s?{status:typeof s.statusCode==`number`?s.statusCode:0,body:s.body??null}:null,origin:{kind:`run`,run:t.run,...Object.keys(t.at).length?{iteration:Object.entries(t.at).map(([e,t])=>`${e}[${t}]`).join(`,`)}:{}}}}function aa(e){let t=e.origin.kind===`run`?`${(e.origin.run??``).slice(-8)}${e.origin.iteration?`-${e.origin.iteration.replace(/.*\[(\d+)\]$/,`$1`)}`:``}`:new Date().toISOString().replace(/\D/g,``).slice(0,14);return`${e.step}-${t}.json`.replace(/[^A-Za-z0-9._-]/g,`_`)}var oa=e=>e.from===`trigger`?`trigger`:e.from===`parameter`?``:e.name,sa=e=>{if(typeof e!=`string`)return e;try{return JSON.parse(e)}catch{return e}};function ca(e,t){let n=[...new Set(t.flatMap(e=>Object.keys(e)))],r=new Set(e.reads.map(oa).filter(Boolean)),i=n.filter(e=>!r.has(e)&&!(r.has(`trigger`)&&e.startsWith(`trigger.`)));return{records:t.map(t=>{let n=Zi(e.name,e.reads);n.origin={kind:`upload`};for(let r of e.reads){let e=oa(r);if(r.from===`trigger`){let r=Object.keys(t).filter(e=>e.startsWith(`trigger.`)),i=e in t?sa(t[e]):r.length?Object.fromEntries(r.map(e=>[e.slice(8),sa(t[e])])):null;n.scope.trigger={body:i}}else if(e in t){let i=sa(t[e]);r.from===`action`?n.scope.actions[r.name]={body:i}:r.from===`variable`?n.scope.variables[r.name]=i:r.from===`item`&&(n.scope.items[r.name]=i)}}return n}),unmatched:i}}function la(e){let t=[],n=[],r=``,i=!1,a=e.replace(/^/,``);for(let e=0;e<a.length;e++){let o=a[e];i?o===`"`&&a[e+1]===`"`?(r+=`"`,e++):o===`"`?i=!1:r+=o:o===`"`?i=!0:o===`,`?(n.push(r),r=``):o===`
5
- `||o===`\r`?(o===`\r`&&a[e+1]===`
6
- `&&e++,n.push(r),t.push(n),n=[],r=``):r+=o}(r||n.length)&&(n.push(r),t.push(n));let[o,...s]=t.filter(e=>e.some(e=>e!==``));return o?s.map(e=>Object.fromEntries(o.map((t,n)=>[t.trim(),e[n]??``]))):[]}function ua(e,t,n){if(!t.request)return{match:null};let r=$(n)&&$(n.parameters)?Object.fromEntries(Object.entries(n.parameters).map(([e,t])=>[e,$(t)?t.defaultValue:void 0])):{},i;try{let n={scope:t.scope,loop:e.loops.at(-1)??null,now:t.at,parameters:r},a=e.template;i={method:l(a.method,n),uri:l(a.uri,n),body:l(a.body??null,n)}}catch(e){return{match:!1,where:e instanceof Error?e.message:String(e)}}let a=da(i,t.request,`request`);return a?{match:!1,where:a}:{match:!0}}function da(e,t,n){if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return`${n} has ${e.length} entries, production ${t.length}`;for(let r=0;r<e.length;r++){let i=da(e[r],t[r],`${n}[${r}]`);if(i)return i}return null}if($(e)&&$(t)){let r=Object.keys(e),i=Object.keys(t);if(r.join()!==i.join())return`${n} has keys ${r.join(`, `)}, production ${i.join(`, `)}`;for(let i of r){let r=da(e[i],t[i],`${n}.${i}`);if(r)return r}return null}return JSON.stringify(e)===JSON.stringify(t)?null:`${n}`}var fa=Object.create(null);fa.ParseJson={reads:e=>typeof e.content==`string`?e.content:null,schema:e=>e.schema??null};function pa(e,t){for(let[n,r]of Object.entries(ra(e))){let e=r.type?fa[r.type]:void 0,i=e&&$(r.inputs)?e.reads(r.inputs):null;if(i&&Xi(i).some(e=>e.from===`action`&&e.name===t))return{name:n,expression:i,schema:e.schema&&$(r.inputs)?e.schema(r.inputs)??null:null}}return null}function ma(e,t){let n=JSON.stringify($(e)?e.actions??{}:{}),r=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`).replace(/'/g,`''`),i=new Set;for(let e of n.matchAll(RegExp(`body\\('${r}'\\)\\??\\['((?:[^']|'')*)'\\]`,`g`)))i.add(e[1].replace(/''/g,`'`));return[...i]}function ha(e){let t=/^https?:\/\/[^/?#]+(\/[^?#]*)?(?:\?([^#]*))?/i.exec(e);if(!t)return{path:e,query:{}};let n={};for(let e of(t[2]??``).split(`&`).filter(Boolean)){let t=e.indexOf(`=`);n[t<0?e:e.slice(0,t)]=t<0?``:e.slice(t+1)}return{path:t[1]||`/`,query:n}}function ga(e,t){let n=K(),r=t.filter(e=>(n.CONNECTION_TYPES[e.type??``]?.answers??[`prompt`]).includes(`request`)),i=(()=>{try{return new URL(e).host}catch{return null}})(),a=r.find(e=>{try{return new URL(n.connectionBase(e)).host===i}catch{return!1}})??r[0];return a?{id:a.id,name:a.name??``}:{id:`http-endpoint`,name:`HTTP endpoint`}}function _a(e,t,n,r){let i=K(),a=n.template,o=String(a.uri??``),s=i.httpApiFor(o),c={type:`httpRequest`,step:n.name,api:s,method:String(a.method??`POST`).toUpperCase(),...ha(o),body:a.body??null,readAs:null,loop:n.loops.at(-1)??null},l=pa(t,n.name);c.readAs=l?.expression??null;let u=l?ma(t,l.name):[],d=[...l?[{type:`is-json`,schema:l.schema?JSON.stringify(l.schema,null,2):``}]:[],...u.length?[{type:`fields-equal-production`,fields:u.join(`
7
- `)}]:[]],f=i.HTTP_APIS[s].cellOf(c.body),p=ga(o,r);return{version:i.PIPELINE_VERSION,id:i.newId(),name:`${e.name} · ${n.name}`,jobs:[{type:`job`,id:i.newId(),name:n.name,steps:[{type:`attachContent`,content:{type:`source`,ref:e,first:null,loops:1}},c,{type:`readReply`,out:{kind:`text`,...i.OUTPUT_KINDS.text?.settingDefaults?.()??{},modifiers:i.OUTPUT_KINDS.text?.modifiers?.()??[]}}]}],scenarios:[{id:i.newId(),name:`Production`,profile:p,stages:[structuredClone(f)]},{id:i.newId(),name:`Edited`,profile:p,stages:[structuredClone(f)]}],tests:d.length?[i.newTest(`metrics`,``,{metrics:d})]:[]}}function va(e,t){let n=e.result;if(!n||!(`status`in n))return null;let r=na(t).find(t=>t.name===e.step);if(!r)return null;let i=String(r.template.uri??``),a={type:`httpRequest`,step:r.name,api:K().httpApiFor(i),method:`POST`,...ha(i),body:null,readAs:pa(t,r.name)?.expression??null,loop:r.loops.at(-1)??null};try{return K().httpReplyOf(a,{prompt:``},n.body,n.status,{scope:e.scope,now:e.at}).raw}catch{return null}}function ya(e,t){let n;try{n=JSON.parse(e)}catch{return[{type:`equals`,value:e,json:!1}]}if(!n||typeof n!=`object`||Array.isArray(n))return[{type:`equals`,value:e,json:!0}];let r=n,i=t.length?t.filter(e=>e in r):Object.keys(r).filter(e=>r[e]==null||typeof r[e]!=`object`);return i.length?i.map(e=>({type:`json-field`,path:e,op:`equals`,value:typeof r[e]==`string`?r[e]:JSON.stringify(r[e])})):[{type:`equals`,value:e,json:!0}]}function ba(e,t){let n=[],r=0;for(let{name:i,record:a}of e){let e=va(a,t);if(e==null){r++;continue}let o=pa(t,a.step),s=o?ma(t,o.name):[];n.push({id:i.replace(/\.json$/i,``).replace(/[^A-Za-z0-9._-]/g,`_`),filename:i,todo:!0,metrics:ya(e,s)})}return{cases:n,skipped:r}}async function xa(e,t,n,r,i){let a=await e.run(t,n,r),o=ra(i),s=new Map,c=new Map,l=t=>t?(c.has(t)||c.set(t,e.content(t)),c.get(t)):Promise.resolve(null),u=i=>(s.has(i)||s.set(i,e.repetitions(t,n,r,i)),s.get(i)),d=async(e,t)=>{let n=o[e]?.loops??[];return n.length?(await u(e)).find(e=>n.every(n=>!(n in t)||e.at[n]===t[n]))??null:a.actions[e]??null},f=e=>e.status!==`Skipped`&&(e.inputsLink||e.outputsLink||e.error),p=async e=>({run:r,at:e.at,startTime:e.startTime,inputs:await l(e.inputsLink),outputs:await l(e.outputsLink),error:e.error});return{detail:a,triggerOutputs:()=>l(a.trigger?.outputsLink??null),actionInputs:async(e,t)=>l((await d(e,t))?.inputsLink??null),actionOutputs:async(e,t)=>l((await d(e,t))?.outputsLink??null),callsOf:async e=>{let t=e.loops.length?await u(e.name):[a.actions[e.name]].filter(e=>!!e);return Promise.all(t.filter(f).map(p))}}}async function Sa(e,t,n,r,i,a,o,s){let c=new Set(o),l=[],u=0,d=0;for(let o of r){let r=await xa(e,t,n,o,a);for(let e of await r.callsOf(i)){let t=Di(await ia(i,e,r,a)).value,n=Qi(t);if(c.has(n)){u++;continue}c.add(n),l.push(t)}s?.(++d)}return{records:l,skipped:u}}var Ca=e=>e.name.toLowerCase().endsWith(`.json`),wa=e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result)),r.onerror=()=>n(r.error),r.readAsText(e)}),Ta=`evals-lab.flow.importing`;function Ea(e){try{return sessionStorage.getItem(e)}catch{return null}}function Da(e,t){try{t?sessionStorage.setItem(e,t):sessionStorage.removeItem(e)}catch{}}var Oa=e=>e instanceof Error?e.message:String(e);function ka({source:t,definition:n,cfg:i}){let a=J(),o=Pe(),s=te(),[c,l]=(0,q.useState)(t.files.filter(Ca)),[u,d]=(0,q.useState)({}),[f,p]=(0,q.useState)(null),[h,g]=(0,q.useState)(()=>{let e=Ea(Ta)===t.id;return e&&Da(Ta,null),e?`import`:null}),[_,v]=(0,q.useState)(null),y=(0,q.useMemo)(()=>na(n),[n]),b=(0,q.useCallback)(async()=>{let e=(await a.source(t.id)).files.filter(Ca);l(e);let n=await Promise.all(e.map(async e=>{try{return[e.name,JSON.parse(await wa(await a.file(t.id,e.name)))]}catch{return[e.name,null]}}));d(Object.fromEntries(n))},[a,t.id]);(0,q.useEffect)(()=>{b().catch(e=>p(Oa(e)))},[b]);let x=e=>{let t=u[e],r=t?y.find(e=>e.name===t.step):void 0;return t&&r?ua(r,t,n):null},S=(0,q.useMemo)(()=>new Set(c.flatMap(e=>u[e.name]?[Qi(u[e.name])]:[])),[c,u]),C=async(e,n=0)=>{let r=0,i=[];for(let n of e)try{await a.upload(t.id,aa(n),new Blob([JSON.stringify(n,null,2)],{type:`application/json`})),r++}catch(e){i.push(e instanceof pe?e.message:Oa(e))}await b(),p([`Added ${r}`,n?`Skipped ${n}`:``,i.length?`Refused ${i.length}: ${i[0]}`:``].filter(Boolean).join(` · `))},E=async()=>{let{cases:e,skipped:r}=ba(c.flatMap(e=>u[e.name]?[{name:e.name,record:u[e.name]}]:[]),n);if(!e.length)return p(`No record holds a production reply.`);try{let n=await o.create(`${t.name} · production`,{cases:e});p([`Made ${n.name}: ${e.length} ${e.length===1?`case`:`cases`}`,r?`Skipped ${r}`:``].filter(Boolean).join(` · `))}catch(e){p(Oa(e))}},O=async e=>{try{let{trash:n}=await a.removeFiles(t.id,e);l(t=>t.filter(t=>!e.includes(t.name))),s.offer({label:`Removed ${e[0]}`,restore:()=>void a.restoreTrash(n).then(b,e=>p(Oa(e)))})}catch(e){p(Oa(e))}},k=async e=>{let n=URL.createObjectURL(await a.file(t.id,e)),r=document.createElement(`a`);r.href=n,r.download=e,document.body.append(r),r.click(),r.remove(),URL.revokeObjectURL(n)},j=t=>[{label:`View`,icon:m,onSelect:()=>v(t.name)},{label:`Download`,icon:e,onSelect:()=>void k(t.name).catch(e=>p(Oa(e)))},{label:`Remove`,icon:ne,destructive:!0,onSelect:()=>void O([t.name])}],M=(0,q.useCallback)(()=>g(null),[]),N=(0,q.useCallback)(()=>v(null),[]),P=_?u[_]:null;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(A,{id:`flow-records`,title:`Records`,note:String(c.length),about:`Each is one call of a Power Automate step: what it read, the request it sent and the reply it got. Request says whether the lab rebuilds that request exactly.`,actions:[{label:`Import runs`,icon:r,disabled:!y.length||!i,onSelect:()=>g(`import`)},{label:`Upload`,icon:G,disabled:!y.length,onSelect:()=>g(`upload`)},{label:`New dataset`,icon:Tn,disabled:!c.length,onSelect:()=>void E()}],children:[f&&(0,X.jsx)(`p`,{className:`note`,role:`status`,children:f}),c.length?(0,X.jsx)(`div`,{className:`sflow`,children:(0,X.jsx)(D,{className:`slist`,label:`Records`,rows:c,rowKey:e=>e.name,columns:[{key:`name`,header:`Name`,sort:e=>e.name,cell:e=>(0,X.jsxs)(X.Fragment,{children:[e.name,(0,X.jsx)(`span`,{className:`sflow-in`,children:Ma(u[e.name])})]})},{key:`result`,header:`Result`,sort:e=>Na(u[e.name]),cell:e=>Na(u[e.name])},{key:`request`,header:`Request`,sort:e=>Aa(x(e.name)),tdProps:e=>{let t=x(e.name);return t&&t.match===!1?{title:t.where}:{}},cell:e=>Aa(x(e.name))},{key:`menu`,header:``,className:`s-actions`,sort:null,cell:e=>(0,X.jsx)(w,{label:`${e.name} actions`,actions:j(e)})}]})}):(0,X.jsx)(`p`,{className:`note`,children:`No records yet. Import runs, in this group's menu, reads them from the flow's run history.`}),(0,X.jsxs)(`button`,{type:`button`,className:`ghost add-btn`,disabled:!y.length,onClick:()=>g(`hand`),children:[(0,X.jsx)(W,{size:14,"aria-hidden":`true`}),` Add record`]})]}),h===`import`&&i&&(0,X.jsx)(Ia,{cfg:i,source:t,steps:y,definition:n,held:S,onClose:M,onRead:async(e,t)=>{g(null),await C(e,t)}}),h===`hand`&&(0,X.jsx)(La,{steps:y,onClose:M,onAdd:async e=>{g(null),await C([e])}}),h===`upload`&&(0,X.jsx)(za,{steps:y,onClose:M,onRead:async e=>{g(null),await C(e)}}),_&&(0,X.jsx)(L,{title:_,onClose:N,wide:!0,children:(0,X.jsx)(`pre`,{className:`pl-words`,children:P?JSON.stringify(P,null,2):`Unreadable.`})}),(0,X.jsx)(T,{undo:s.undo,onUndo:s.undoNow,onDismiss:s.dismiss})]})}var Aa=e=>!e||e.match===null?`—`:e.match?`Match`:`Differs`,ja={run:`Run`,hand:`Hand`,upload:`Upload`},Ma=e=>e?[e.step,ja[e.origin.kind]??e.origin.kind,e.at?xi(Date.parse(e.at)/1e3):``].filter(Boolean).join(` · `):`Unreadable`;function Na(e){let t=e?.result;return t?`error`in t?t.error.code||`Error`:String(t.status):`—`}var Pa=e=>e.map(e=>({value:e.name,label:e.name})),Fa=e=>e.from===`trigger`?`Trigger body`:oa(e);function Ia({cfg:e,source:t,steps:n,definition:r,held:i,onClose:a,onRead:o}){let s=(0,q.useMemo)(()=>Wi(e),[e]),c=t.config??{},[l,u]=(0,q.useState)(void 0),[d,f]=(0,q.useState)(n[0]?.name??``),[p,m]=(0,q.useState)(null),[h,g]=(0,q.useState)(``),[_,v]=(0,q.useState)(new Set),[y,b]=(0,q.useState)(``),[x,S]=(0,q.useState)(null),[C,w]=(0,q.useState)(null);(0,q.useEffect)(()=>{zi(e).then(u,()=>u(null))},[e]),(0,q.useEffect)(()=>{l&&c.environment&&c.flow&&s.runs(c.environment,c.flow).then(m,e=>w(Oa(e)))},[l,s,c.environment,c.flow]);let T=(0,q.useMemo)(()=>[...new Set((p??[]).map(e=>e.status))].sort(),[p]),E=(0,q.useMemo)(()=>(p??[]).filter(e=>!h||e.status===h),[p,h]),O=e=>v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),A=E.length>0&&E.every(e=>_.has(e.id)),j=E.filter(e=>_.has(e.id)).map(e=>e.id),M=async()=>{let e=n.find(e=>e.name===d);if(!e||!c.environment||!c.flow)return;let t=j;w(null),S(`Reading 0 of ${t.length}`);try{let{records:n,skipped:a}=await Sa(s,c.environment,c.flow,t,e,r,i,e=>S(`Reading ${e} of ${t.length}`));await o(n,a)}catch(e){w(Oa(e)),S(null)}};return(0,X.jsxs)(L,{title:`Import runs`,onClose:a,wide:!0,footer:(0,X.jsxs)(`div`,{className:`sacts`,children:[x&&(0,X.jsx)(`span`,{className:`note`,role:`status`,children:x}),(0,X.jsxs)(`button`,{type:`button`,className:`ghost`,disabled:!!x||!j.length||!d,onClick:()=>void M(),children:[`Import `,j.length||``]})]}),children:[l===void 0?(0,X.jsx)(`p`,{className:`note`,children:`Loading…`}):l?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(k,{label:`Import`,rows:[{key:`step`,label:`Step`,control:{type:`select`,value:d,options:Pa(n),onChange:f}},{key:`latest`,label:`Latest`,control:{type:`text`,value:y,size:`num`,placeholder:`N`,onChange:e=>{b(e);let t=Number.parseInt(e,10);t>0&&v(new Set(E.slice(0,t).map(e=>e.id)))}}}]}),p?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ee,{noun:`runs`,count:{shown:E.length,total:p.length},lead:(0,X.jsx)(`input`,{type:`checkbox`,"aria-label":`Select all shown`,checked:A,disabled:!E.length,onChange:()=>v(A?new Set:new Set(E.map(e=>e.id)))}),filters:[{key:`status`,label:`Status`,value:h,onChange:g,options:[{value:``,label:`All`},...T.map(e=>({value:e,label:e}))]}]}),E.length?(0,X.jsx)(`div`,{className:`sflow`,children:(0,X.jsx)(D,{className:`slist`,label:`Runs`,rows:E,rowKey:e=>e.id,pageSize:20,rowProps:e=>({onClick:()=>O(e.id),"data-selected":_.has(e.id)||void 0}),columns:[{key:`pick`,header:``,sort:null,cell:e=>(0,X.jsx)(`input`,{type:`checkbox`,"aria-label":`Run ${e.id}`,checked:_.has(e.id),onChange:()=>O(e.id),onClick:e=>e.stopPropagation()})},{key:`start`,header:`Started`,sort:e=>e.startTime??``,cell:e=>e.startTime?xi(Date.parse(e.startTime)/1e3):`—`},{key:`status`,header:`Status`,sort:e=>e.status,cell:e=>e.status}]})}):(0,X.jsx)(`p`,{className:`note`,children:`No runs.`})]}):(0,X.jsx)(`p`,{className:`note`,children:`Loading…`})]}):(0,X.jsx)(`div`,{className:`sacts`,children:(0,X.jsxs)(`button`,{type:`button`,className:`ghost`,onClick:()=>{Da(Ta,t.id),Bi(e).catch(e=>{Da(Ta,null),w(Oa(e))})},children:[(0,X.jsx)(Ln,{size:14,"aria-hidden":`true`}),` Sign in with Microsoft`]})}),C&&(0,X.jsx)(`p`,{className:`note bad`,role:`alert`,children:C})]})}function La({steps:e,onClose:t,onAdd:n}){let[r,i]=(0,q.useState)(e[0]?.name??``),[a,o]=(0,q.useState)({}),s=e.find(e=>e.name===r),c=(s?.reads??[]).filter(e=>oa(e));return(0,X.jsxs)(L,{title:`Add record`,onClose:t,wide:!0,footer:(0,X.jsx)(`div`,{className:`sacts`,children:(0,X.jsx)(`button`,{type:`button`,className:`ghost`,disabled:!s,onClick:()=>{if(!s)return;let e=Object.fromEntries(Object.entries(a).filter(([e,t])=>t!==``&&c.some(t=>oa(t)===e))),[t]=ca(s,[e]).records;n({...t,origin:{kind:`hand`}})},children:`Add`})}),children:[(0,X.jsx)(k,{label:`Record`,rows:[{key:`step`,label:`Step`,control:{type:`select`,value:r,options:Pa(e),onChange:e=>{i(e),o({})}}},...c.map(e=>({key:`read-${oa(e)}`,label:Fa(e),control:{type:`textarea`,value:a[oa(e)]??``,onChange:t=>o(n=>({...n,[oa(e)]:t}))}}))]}),s&&!c.length&&(0,X.jsx)(`p`,{className:`note`,children:`Reads nothing.`})]})}function Ra(e,t){if(e.toLowerCase().endsWith(`.csv`))return{rows:la(t)};let n=JSON.parse(t),r=Array.isArray(n)?n:[n];if(r.length&&r.every(e=>!!e&&typeof e==`object`&&e.format===`evals-lab/record`))return{records:r};if(r.every(e=>e&&typeof e==`object`&&!Array.isArray(e)))return{rows:r};throw Error(`a file of records, or rows of objects`)}function za({steps:e,onClose:t,onRead:n}){let r=(0,q.useRef)(null),[i,a]=(0,q.useState)(e[0]?.name??``),[o,s]=(0,q.useState)(null),[c,l]=(0,q.useState)(null),u=e.find(e=>e.name===i),d=o&&u&&`rows`in o.parsed?ca(u,o.parsed.rows):null,f=o?`records`in o.parsed?o.parsed.records:d?.records??[]:[],p=async e=>{if(e){l(null);try{s({name:e.name,parsed:Ra(e.name,await wa(e))})}catch(t){s(null),l(`${e.name}: ${Oa(t)}`)}}};return(0,X.jsxs)(L,{title:`Upload`,onClose:t,wide:!0,footer:(0,X.jsx)(`div`,{className:`sacts`,children:(0,X.jsxs)(`button`,{type:`button`,className:`ghost`,disabled:!f.length,onClick:()=>void n(f),children:[`Add `,f.length||``]})}),children:[(0,X.jsx)(k,{label:`Upload`,rows:[...o&&`records`in o.parsed?[]:[{key:`step`,label:`Step`,control:{type:`select`,value:i,options:Pa(e),onChange:a}}],{key:`file`,label:`File`,control:{type:`static`,text:o?.name??`—`}},...o?[{key:`count`,label:`records`in o.parsed?`Records`:`Rows`,control:{type:`static`,text:String(f.length)}}]:[],...d?.unmatched.length?[{key:`unmatched`,label:`Unmatched`,control:{type:`static`,text:d.unmatched.join(`, `)}}]:[]]}),(0,X.jsxs)(`div`,{className:`sacts`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`ghost`,onClick:()=>r.current?.click(),children:[(0,X.jsx)(G,{size:14,"aria-hidden":`true`}),` Choose file`]}),(0,X.jsx)(`input`,{ref:r,type:`file`,accept:`.json,.csv`,hidden:!0,"aria-hidden":`true`,onChange:e=>{p(e.target.files?.[0]),e.target.value=``}})]}),c&&(0,X.jsx)(`p`,{className:`note bad`,role:`alert`,children:c})]})}function Ba({source:e,onBack:t}){let n=J(),r=Ui(),[i,a]=(0,q.useState)(null),[o,s]=(0,q.useState)(null),[c,l]=(0,q.useState)(!1),u=e.config??{},d=(0,q.useCallback)(()=>{n.definition(e.id).then(a,()=>a(null))},[n,e.id]);(0,q.useEffect)(d,[d]);let f=async()=>{if(r&&i&&u.environment&&u.flow){l(!0),s(null);try{if(!await zi(r)){await Bi(r);return}let t=await Gi(Wi(r),u.environment,u.flow);a(await n.saveDefinition(e.id,i.version,t.definition)),s(`Synced.`)}catch(e){e instanceof pe&&e.status===409?(d(),s(`It changed since: reloaded.`)):s(e instanceof Error?e.message:String(e))}finally{l(!1)}}},p=(0,q.useMemo)(()=>Va(i?.body),[i]),m=(0,q.useMemo)(()=>na(i?.body),[i]),[h,g]=_e(`promptlab.workflows`),[_]=_e(`promptlab.profiles`),v=t=>{let n=m.find(e=>e.name===t);if(!n||!i)return;let r=_a({id:e.id,name:e.name},i.body,n,_.list),a={id:r.id,name:r.name,work:r};g({...h,list:[...h.list,a],at:a.id}),location.hash=`#/runs`};return(0,X.jsxs)(`div`,{className:`sources`,"data-level":`flow`,children:[(0,X.jsx)(`header`,{className:`shead`,children:(0,X.jsxs)(`nav`,{className:`scrumb`,"aria-label":`Breadcrumb`,children:[(0,X.jsx)(`button`,{type:`button`,className:`ghost crumb`,onClick:t,children:`Sources`}),(0,X.jsxs)(`span`,{className:`crumb-cur`,"aria-current":`page`,children:[`› `,e.name]})]})}),o&&(0,X.jsx)(`p`,{className:`note`,role:`status`,children:o}),(0,X.jsx)(A,{id:`flow-source`,title:`Flow`,note:u.displayName,actions:[{label:`Re-sync`,icon:Un,disabled:c||!r||!i,onSelect:()=>void f()}],children:(0,X.jsx)(k,{label:`Flow`,rows:[{key:`flow`,label:`Flow`,control:{type:`static`,text:u.displayName||u.flow||`—`}},{key:`env`,label:`Environment`,control:{type:`static`,text:u.environment||`—`}},{key:`version`,label:`Definition`,control:{type:`static`,text:i?i.version?`Version ${i.version}${i.at?` · ${xi(Date.parse(i.at)/1e3)}`:``}`:`None`:`Loading…`}}]})}),(0,X.jsx)(ka,{source:e,definition:i?.body??null,cfg:r}),(0,X.jsx)(A,{id:`flow-actions`,title:`Actions`,note:i?String(p.length):void 0,children:i&&!p.length?(0,X.jsx)(`p`,{className:`note`,children:`No actions.`}):(0,X.jsx)(`div`,{className:`sflow`,children:(0,X.jsx)(D,{className:`slist`,label:`Actions`,rows:p,rowKey:e=>e.name,columns:[{key:`name`,header:`Name`,sort:e=>e.name,cell:e=>(0,X.jsxs)(X.Fragment,{children:[e.name,e.in&&(0,X.jsxs)(`span`,{className:`sflow-in`,children:[`in `,e.in]})]})},{key:`type`,header:`Type`,sort:e=>e.type,cell:e=>e.type},{key:`calls`,header:`Calls`,cell:e=>e.calls||`—`},{key:`menu`,header:``,className:`s-actions`,sort:null,cell:e=>m.some(t=>t.name===e.name)?(0,X.jsx)(w,{label:`${e.name} actions`,actions:[{label:`New pipeline`,icon:Hn,onSelect:()=>v(e.name)}]}):null}]})})})]})}function Va(e){let t=[],n=(e,i)=>{for(let[a,o]of Object.entries(e??{})){t.push({name:a,type:o.type??``,in:i,calls:r(o)}),n(o.actions,a),n(o.else?.actions,`${a} (else)`);for(let[e,t]of Object.entries(o.cases??{}))n(t.actions,`${a} (${e})`);n(o.default?.actions,`${a} (default)`)}},r=e=>{if(e.type===`Http`&&typeof e.inputs?.uri==`string`)try{return new URL(e.inputs.uri).host}catch{return e.inputs.uri.startsWith(`@`)?`(expression)`:``}let t=e.inputs?.host?.apiId??e.inputs?.host?.connectionName;return t?t.split(`/`).pop()??``:``};return n(e?.actions,``),t}var Ha={"power-automate":{Create:Ki,Level:Ba}};function Ua({sourceId:t=null,onOpen:r,mode:a=`browse`,onPick:o,disabled:s}){let c=J(),l=te(),[u,d]=(0,q.useState)(null),[f,p]=(0,q.useState)(0),[g,_]=(0,q.useState)(0),[v,y]=(0,q.useState)(null),[b,x]=(0,q.useState)(ui),[S,C]=(0,q.useState)(``),[E,O]=(0,q.useState)(new Set),[A,j]=(0,q.useState)(null),[M,P]=(0,q.useState)(()=>a===`browse`&&Ga()!==null),[F,I]=(0,q.useState)(null),[R,z]=(0,q.useState)(null),[B,V]=(0,q.useState)(!1),[H,U]=(0,q.useState)(``),[G,re]=(0,q.useState)(()=>a===`browse`&&Ga()||K().DEFAULT_SOURCE_TYPE),[ie,ae]=(0,q.useState)(``),[oe,se]=(0,q.useState)(``),[ce,le]=(0,q.useState)(null),[ue,Y]=(0,q.useState)([]),[de,fe]=(0,q.useState)(!1),[me,he]=(0,q.useState)(!1),ge=(0,q.useRef)(null),_e=(0,q.useRef)(1),{view:ve,sort:ye,dir:be}=b,xe=(0,q.useCallback)(()=>I(null),[]),Se=(0,q.useCallback)(()=>P(!1),[]),Ce=(0,q.useCallback)(()=>z(null),[]),we=(0,q.useCallback)(()=>V(!1),[]);(0,q.useEffect)(()=>di(b),[b]),(0,q.useEffect)(()=>{a===`browse`&&Ka(M?G:null)},[a,M,G]);let Te=async()=>{try{let e=await c.sources();d(e.sources),p(e.cap),_(e.used)}catch{}};(0,q.useEffect)(()=>{let e=!0;return c.sources().then(t=>{e&&(d(t.sources),p(t.cap),_(t.used))}).catch(()=>{}),()=>{e=!1}},[c]),(0,q.useEffect)(()=>{O(new Set),Y([]);let e=!0;return t?c.source(t).then(t=>{e&&y(t)}).catch(()=>{e&&y(null)}):y(null),()=>{e=!1}},[t]);let Ee=async()=>{if(!t){y(null);return}try{y(await c.source(t))}catch{y(null)}},De=e=>{le(e),e&&window.setTimeout(()=>le(null),6e3)},Oe=e=>e instanceof pe?e.message:`the request failed`,ke=yi(vi(v?.files??[],ye,be),S),Ae=e=>{O(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},je=()=>O(new Set(ke.map(e=>e.name))),Me=()=>O(new Set),Ne=async e=>{try{let{trash:t}=await c.removeSource(e.id);d(t=>(t??[]).filter(t=>t.id!==e.id)),l.offer({label:`Deleted ${e.name}`,restore:()=>void(async()=>{try{await c.restoreTrash(t),await Te()}catch(e){De(Oe(e))}})()})}catch(e){De(Oe(e))}},Pe=async e=>{if(v)try{let{trash:t}=await c.removeFiles(v.id,e),n=new Set(e);y(t=>t&&{...t,files:t.files.filter(e=>!n.has(e.name)),bytes:t.bytes-e.reduce((e,n)=>e+(t.files.find(e=>e.name===n)?.bytes??0),0)}),O(e=>new Set([...e].filter(e=>!n.has(e)))),l.offer({label:e.length===1?`Removed ${e[0]}`:`Removed ${e.length} files`,restore:()=>void(async()=>{try{let e=await c.restoreTrash(t);y(e.source)}catch(e){De(Oe(e))}})()})}catch(e){De(Oe(e))}},Fe=(e,t)=>{let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,document.body.append(r),r.click(),r.remove(),URL.revokeObjectURL(n)},Ie=async e=>{if(!v)return;let t=e.length===1?e[0]:null;he(!0);try{let n=t?await c.file(v.id,t):await c.zip(v.id,e);Fe(n,t??`${v.name}.zip`)}catch(e){De(Oe(e))}finally{he(!1)}},Le=async e=>{if(!v||v.system)return;let t=[...e];if(!t.length)return;let n=t.map(e=>({id:_e.current++,file:e,state:`uploading`}));Y(e=>[...e,...n]);for(let e of n)try{await c.upload(v.id,e.file.name,e.file),Y(t=>t.map(t=>t.id===e.id?{...t,state:`done`}:t))}catch(t){Y(n=>n.map(n=>n.id===e.id?{...n,state:`error`,error:Oe(t)}:n))}await Ee()},Re=e=>void Le([e.file]),ze=async(e,t)=>{if(v&&R)try{await c.copyFiles(t.id,v.id,R.names,e===`move`),z(null),O(new Set),await Ee(),De(e===`move`?`Moved to ${t.name}.`:`Copied to ${t.name}.`)}catch(e){De(Oe(e)),z(null)}},Be=async()=>{if(v&&H.trim())try{let e=await c.createSource(H.trim(),v.type);try{await c.copyFiles(e.id,v.id,[...E],!1)}catch(t){throw await c.removeSource(e.id).catch(()=>{}),t}V(!1),U(``),O(new Set),await Te(),De(`Made a new Source.`)}catch(e){De(Oe(e))}},Ve=async()=>{if(H.trim())try{await c.createSource(H.trim(),G),P(!1),U(``),re(K().DEFAULT_SOURCE_TYPE),await Te()}catch(e){De(Oe(e))}},He=async(e,t)=>{try{let n=await c.renameSource(e.id,t);d(t=>(t??[]).map(t=>t.id===e.id?Si(n):t))}catch(e){De(Oe(e))}},Ue=e=>e.system?[]:[{label:`Rename`,icon:i,onSelect:()=>j(e.id)},{label:`Delete`,icon:ne,destructive:!0,onSelect:()=>void Ne(e)}],We=t=>[{label:`Preview`,icon:m,disabled:!hi(t.name),onSelect:()=>I(t)},{label:`Download`,icon:e,onSelect:()=>void Ie([t.name])},...v?.system?[]:[{label:`Remove`,icon:ne,destructive:!0,onSelect:()=>void Pe([t.name])}]],Ge=[...v?.system?[]:[{label:`Remove`,icon:ne,destructive:!0,onSelect:()=>void Pe([...E])}],{label:`Download`,icon:e,disabled:me,onSelect:()=>void Ie([...E])},...v?.system?[]:[{label:`Move to…`,icon:kn,onSelect:()=>z({kind:`move`,names:[...E]})}],{label:`Copy to…`,icon:N,onSelect:()=>z({kind:`copy`,names:[...E]})},...v?.system?[]:[{label:`New Source from selection`,icon:jn,onSelect:()=>V(!0)}]],Ke=e=>{e.preventDefault(),fe(!1),v&&!v.system&&Le(e.dataTransfer.files)},Z=(u??[]).filter(e=>(!oe||e.type===oe)&&e.name.toLowerCase().includes(ie.trim().toLowerCase())),qe=(0,X.jsx)(ee,{noun:`Sources`,search:{label:`Find a Source`,value:ie,placeholder:`Name`,onChange:ae},filters:[{key:`type`,label:`Type`,value:oe,onChange:se,options:[{value:``,label:`All`},...to()]}],count:{shown:Z.length,total:(u??[]).length}}),Je=()=>(0,X.jsxs)(`div`,{className:`sources`,"data-level":`sources`,children:[ce&&(0,X.jsx)(`p`,{className:`note`,role:`status`,children:ce}),(0,X.jsxs)(`header`,{className:`shead`,children:[(0,X.jsx)(`h2`,{className:`shead-title`,children:`Sources`}),(0,X.jsx)(Ja,{view:ve,onChange:e=>x(t=>({...t,view:e}))})]}),u!==null&&u.length>0&&qe,u===null?(0,X.jsx)(`p`,{className:`note`,children:`Loading…`}):u.length===0?(0,X.jsx)(`p`,{className:`note`,children:`No Sources on the server yet.`}):ve===`thumbs`?(0,X.jsx)(`ul`,{className:`sfolders`,children:Z.map(e=>(0,X.jsx)(`li`,{className:`sfolder`,children:(0,X.jsxs)(`button`,{type:`button`,className:`sfolder-open${s?.(e)?` off`:``}`,disabled:s?.(e),onClick:()=>o?.(e),children:[(0,X.jsx)(Za,{}),(0,X.jsx)(`span`,{className:`sfolder-name`,children:e.name}),(0,X.jsxs)(`span`,{className:`sfolder-meta`,children:[no(e),` · `,ro(e)]})]})},e.id))}):(0,X.jsx)(D,{className:`slist slist-folders`,label:`Sources`,rows:Z,rowKey:e=>e.id,columns:[{key:`name`,header:`Name`,className:`sfile-name`,sort:e=>e.name,cell:e=>(0,X.jsxs)(`button`,{type:`button`,className:`srow-pick${s?.(e)?` off`:``}`,disabled:s?.(e),onClick:()=>o?.(e),children:[(0,X.jsx)(Za,{}),` `,e.name]})},{key:`type`,header:`Type`,sort:e=>no(e),cell:e=>no(e)},{key:`files`,header:`Items`,cell:e=>e.files},{key:`size`,header:`Size`,sort:e=>e.bytes,cell:e=>bi(e.bytes)}]})]});if(a===`pick`)return Je();if(t){if(!v)return(0,X.jsx)(`div`,{className:`sources`,children:(0,X.jsx)(`p`,{className:`note`,children:`Loading…`})});let e=Ha[v.type]?.Level;return e?(0,X.jsx)(e,{source:v,onBack:()=>r?.(null)}):(0,X.jsxs)(`div`,{className:`sources`,"data-level":`files`,children:[ce&&(0,X.jsx)(`p`,{className:`note`,role:`status`,children:ce}),(0,X.jsxs)(`header`,{className:`shead`,children:[(0,X.jsxs)(`nav`,{className:`scrumb`,"aria-label":`Breadcrumb`,children:[(0,X.jsx)(`button`,{type:`button`,className:`ghost crumb`,onClick:()=>r?.(null),children:`Sources`}),(0,X.jsxs)(`span`,{className:`crumb-cur`,"aria-current":`page`,children:[`› `,v.name]})]}),(0,X.jsx)(Ja,{view:ve,onChange:e=>x(t=>({...t,view:e}))}),(0,X.jsx)(Ya,{sort:ye,dir:be,onChange:(e,t)=>x(n=>({...n,sort:e,dir:t}))}),(0,X.jsxs)(`label`,{className:`sfilter`,children:[(0,X.jsx)(n,{size:14,"aria-hidden":`true`}),(0,X.jsx)(`input`,{type:`search`,"aria-label":`Filter by name`,placeholder:`Filter`,value:S,onChange:e=>C(e.target.value)})]})]}),E.size>0&&(0,X.jsxs)(`div`,{className:`sselect`,"data-selected":E.size,children:[(0,X.jsxs)(`span`,{className:`sselect-count`,children:[E.size,` selected`]}),(0,X.jsx)(`button`,{type:`button`,className:`ghost`,onClick:je,children:`Select all`}),(0,X.jsx)(`button`,{type:`button`,className:`ghost`,onClick:Me,children:`None`}),(0,X.jsx)(w,{label:`Selection actions`,actions:Ge})]}),(0,X.jsx)(`div`,{className:`sfiles${de?` drag`:``}`,onDragOver:e=>{e.preventDefault(),fe(!0)},onDragLeave:()=>fe(!1),onDrop:Ke,children:ke.length===0?(0,X.jsx)(`p`,{className:`note`,children:S?`No files match that name.`:`No files in this Source yet.`}):ve===`thumbs`?(0,X.jsx)(`ul`,{className:`stiles`,children:ke.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,className:`stile${E.has(e.name)?` sel`:``}`,"aria-pressed":E.has(e.name),"aria-label":e.name,onClick:()=>Ae(e.name),children:[(0,X.jsx)(qa,{id:v.id,file:e}),(0,X.jsx)(`span`,{className:`stile-name`,children:e.name}),E.has(e.name)&&(0,X.jsx)(`span`,{className:`stile-check`,children:(0,X.jsx)(h,{size:12,"aria-hidden":`true`})})]})},e.name))}):(0,X.jsx)(D,{className:`slist`,label:`${v.name} files`,rows:ke,rowKey:e=>e.name,rowProps:e=>({className:E.has(e.name)?`sel`:void 0,"data-selected":E.has(e.name)||void 0,onClick:()=>Ae(e.name)}),columns:[{key:`name`,header:`Name`,className:`sfile-name`,cell:e=>e.name},{key:`type`,header:`Type`,className:`stype`,cell:e=>Xa(e.name)},{key:`size`,header:`Size`,sort:e=>e.bytes,cell:e=>bi(e.bytes)},{key:`added`,header:`Added`,sort:e=>e.added,cell:e=>e.added?xi(e.added):`—`},{key:`menu`,header:``,className:`s-actions`,sort:null,tdProps:()=>({onClick:e=>e.stopPropagation()}),cell:e=>(0,X.jsx)(w,{label:`${e.name} actions`,actions:We(e)})}]})}),!v.system&&(0,X.jsxs)(`div`,{className:`supload`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`ghost add-btn`,onClick:()=>ge.current?.click(),children:[(0,X.jsx)(W,{size:14,"aria-hidden":`true`}),` Add files`]}),(0,X.jsx)(`input`,{ref:ge,type:`file`,multiple:!0,hidden:!0,"aria-hidden":`true`,accept:K().sourceTypeOf(v)?.uploads?.join(`,`),onChange:e=>{e.target.files&&Le(e.target.files),e.target.value=``}}),ue.length>0&&(0,X.jsx)(`ul`,{className:`suploads`,children:ue.map(e=>(0,X.jsxs)(`li`,{className:`supload ${e.state}`,children:[(0,X.jsx)(`span`,{className:`supload-name`,children:e.file.name}),e.state===`uploading`&&(0,X.jsx)(`span`,{className:`supload-bar`,role:`status`,children:`Uploading…`}),e.state===`done`&&(0,X.jsx)(`span`,{className:`note`,children:`Uploaded`}),e.state===`error`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`note bad`,children:e.error}),(0,X.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>Re(e),children:`Retry`})]})]},e.id))}),(0,X.jsx)(`p`,{className:`note sudrop`,children:`…or drop them onto the Source.`})]}),F&&(0,X.jsxs)(L,{title:F.name,onClose:xe,children:[hi(F.name)?(0,X.jsx)(`img`,{className:`spreview-img`,src:_i(v.id,F),alt:F.name}):null,(0,X.jsx)(`p`,{className:`note`,children:bi(F.bytes)})]}),R&&(0,X.jsx)(L,{title:R.kind===`move`?`Move to…`:`Copy to…`,onClose:Ce,children:(0,X.jsx)(Ua,{mode:`pick`,disabled:e=>e.id===v.id||e.system||e.type!==v.type,onPick:e=>void ze(R.kind,e)})}),B&&(0,X.jsxs)(L,{title:`New Source from selection`,onClose:we,children:[(0,X.jsxs)(`label`,{className:`prompt`,children:[(0,X.jsx)(`span`,{className:`prop-name`,children:`Name`}),(0,X.jsx)(`input`,{"aria-label":`New Source name`,value:H,autoFocus:!0,onChange:e=>U(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Be()}})]}),(0,X.jsxs)(`div`,{className:`sacts`,children:[(0,X.jsx)(`button`,{type:`button`,className:`ghost`,disabled:!H.trim(),onClick:()=>void Be(),children:`Make`}),(0,X.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>V(!1),children:`Close`})]})]}),(0,X.jsx)(T,{undo:l.undo,onUndo:l.undoNow,onDismiss:l.dismiss})]})}return(0,X.jsxs)(`div`,{className:`sources`,"data-level":`sources`,children:[ce&&(0,X.jsx)(`p`,{className:`note`,role:`status`,children:ce}),(0,X.jsxs)(`header`,{className:`shead`,children:[(0,X.jsx)(`h2`,{className:`shead-title`,children:`Sources`}),(0,X.jsxs)(`p`,{className:`note suste`,children:[`Used `,bi(g),` of `,bi(f)]}),(0,X.jsx)(Ja,{view:ve,onChange:e=>x(t=>({...t,view:e}))})]}),u!==null&&u.length>0&&qe,u===null?(0,X.jsx)(`p`,{className:`note`,children:`Loading…`}):u.length===0?(0,X.jsx)(`p`,{className:`note`,children:`No Sources yet — Add source below.`}):ve===`thumbs`?(0,X.jsx)(`ul`,{className:`sfolders`,children:Z.map(e=>(0,X.jsxs)(`li`,{className:`sfolder`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`sfolder-open`,onClick:()=>r?.(e.id),children:[(0,X.jsx)(Za,{}),(0,X.jsx)(`span`,{className:`sfolder-name`,children:e.name}),(0,X.jsxs)(`span`,{className:`sfolder-meta`,children:[no(e),` · `,ro(e)]}),(0,X.jsx)(eo,{source:e,cap:f,children:e.system?(0,X.jsx)(`span`,{className:`squota-none`,children:`—`}):(0,X.jsx)(`span`,{className:`squota-bar`,children:(0,X.jsx)(`span`,{className:`squota-fill`,style:{width:`${Qa(e.bytes,f)}%`}})})})]}),(0,X.jsx)(`span`,{className:`sfolder-menu`,children:(0,X.jsx)(w,{label:`${e.name} actions`,actions:Ue(e)})})]},e.id))}):(0,X.jsx)(`div`,{className:`sfiles`,children:(0,X.jsx)(D,{className:`slist slist-folders`,label:`Sources`,rows:Z,rowKey:e=>e.id,rowProps:e=>({"data-open":e.id,onClick:()=>r?.(e.id)}),columns:[{key:`name`,header:`Name`,className:`sfile-name`,sort:e=>e.name,cell:e=>(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Za,{}),` `,e.name]})},{key:`type`,header:`Type`,sort:e=>no(e),cell:e=>no(e)},{key:`files`,header:`Items`,cell:e=>e.files},{key:`size`,header:`Size`,sort:e=>e.bytes,cell:e=>bi(e.bytes)},{key:`used`,header:`Used`,sort:e=>e.system?null:e.bytes,cell:e=>(0,X.jsx)(eo,{source:e,cap:f,children:e.system?`—`:`${Qa(e.bytes,f)}%`})},{key:`menu`,header:``,className:`s-actions`,sort:null,tdProps:()=>({onClick:e=>e.stopPropagation()}),cell:e=>(0,X.jsx)(w,{label:`${e.name} actions`,actions:Ue(e)})}]})}),A&&u&&(()=>{let e=u.find(e=>e.id===A);return e?(0,X.jsxs)(`label`,{className:`srename`,children:[(0,X.jsxs)(`span`,{className:`prop-name`,children:[`Rename `,e.name]}),(0,X.jsx)(`input`,{"aria-label":`Rename ${e.name}`,defaultValue:e.name,autoFocus:!0,onKeyDown:t=>{if(t.key===`Enter`){let n=t.target.value.trim();n&&n!==e.name&&He(e,n),j(null)}t.key===`Escape`&&j(null)},onBlur:t=>{let n=t.target.value.trim();n&&n!==e.name&&He(e,n),j(null)}})]}):null})(),(0,X.jsxs)(`button`,{type:`button`,className:`ghost add-btn`,onClick:()=>P(!0),children:[(0,X.jsx)(W,{size:14,"aria-hidden":`true`}),` Add source`]}),M&&(0,X.jsxs)(L,{title:`Add source`,onClose:Se,children:[(0,X.jsx)(k,{label:`New Source`,rows:[{key:`type`,label:`Type`,hint:K().SOURCE_TYPES[G]?.description,control:{type:`select`,value:G,options:to(),onChange:re}}]}),(()=>{let e=Ha[G]?.Create,t=(0,X.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>P(!1),children:`Close`});return e?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(e,{onMade:async()=>{P(!1),re(K().DEFAULT_SOURCE_TYPE),await Te()}}),(0,X.jsx)(`div`,{className:`sacts`,children:t})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`label`,{className:`prompt`,children:[(0,X.jsx)(`span`,{className:`prop-name`,children:`Name`}),(0,X.jsx)(`input`,{"aria-label":`Source name`,value:H,autoFocus:!0,onChange:e=>U(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Ve()}})]}),(0,X.jsxs)(`div`,{className:`sacts`,children:[(0,X.jsx)(`button`,{type:`button`,className:`ghost`,disabled:!H.trim(),onClick:()=>void Ve(),children:`Add`}),t]})]})})()]}),(0,X.jsx)(T,{undo:l.undo,onUndo:l.undoNow,onDismiss:l.dismiss})]})}var Wa=`evals-lab.sources.adding`;function Ga(){try{return sessionStorage.getItem(Wa)}catch{return null}}function Ka(e){try{e?sessionStorage.setItem(Wa,e):sessionStorage.removeItem(Wa)}catch{}}function qa({id:e,file:t}){let[n,r]=(0,q.useState)(!1);return!t.thumb||n?(0,X.jsx)(`span`,{className:`stile-type`,children:Xa(t.name)||`FILE`}):(0,X.jsx)(`img`,{className:`stile-img`,src:gi(e,t),alt:``,loading:`lazy`,onError:()=>r(!0)})}function Ja({view:e,onChange:t}){return(0,X.jsxs)(`div`,{className:`sview`,role:`group`,"aria-label":`View`,children:[(0,X.jsx)(`button`,{type:`button`,className:e===`thumbs`?`on`:void 0,"aria-pressed":e===`thumbs`,onClick:()=>t(`thumbs`),children:`Thumbnails`}),(0,X.jsx)(`button`,{type:`button`,className:e===`list`?`on`:void 0,"aria-pressed":e===`list`,onClick:()=>t(`list`),children:`List`})]})}function Ya({sort:e,dir:t,onChange:n}){return(0,X.jsxs)(`div`,{className:`ssort`,role:`group`,"aria-label":`Sort`,children:[(0,X.jsxs)(`select`,{"aria-label":`Sort by`,value:e,onChange:e=>n(e.target.value,t),children:[(0,X.jsx)(`option`,{value:`name`,children:`Name`}),(0,X.jsx)(`option`,{value:`added`,children:`Date added`}),(0,X.jsx)(`option`,{value:`size`,children:`Size`})]}),(0,X.jsx)(`button`,{type:`button`,className:`icon-btn`,"aria-label":`Sort ${t===1?`ascending`:`descending`}`,onClick:()=>n(e,t===1?-1:1),children:(0,X.jsx)(t===1?a:c,{size:14,"aria-hidden":`true`})})]})}function Xa(e){let t=e.lastIndexOf(`.`);return t<0?``:e.slice(t+1).toUpperCase()}function Za(){return(0,X.jsx)(Mn,{size:16,"aria-hidden":`true`})}function Qa(e,t){return t<=0?0:Math.max(0,Math.min(100,Math.round(e/t*100)))}function $a(e,t){return e.system?`Quota: not counted`:`Quota: ${bi(e.bytes)} of ${bi(t)}`}function eo({source:e,cap:t,children:n}){let r=$a(e,t);return(0,X.jsxs)(`span`,{className:`squota`,role:`img`,"aria-label":r,children:[n,(0,X.jsx)(`span`,{className:`squota-pop`,"aria-hidden":`true`,children:r})]})}var to=()=>Object.entries(K().SOURCE_TYPES).map(([e,t])=>({value:e,label:t.label})),no=e=>K().SOURCE_TYPES[e.type]?.label??e.type,ro=e=>{let t=K().sourceTypeOf(e)?.noun??`item`;return`${e.files} ${e.files===1?t:`${t}s`}`};function io({sourceId:e}){let[t,n]=(0,q.useState)(e);return(0,q.useEffect)(()=>n(e),[e]),(0,X.jsx)(Ua,{sourceId:t,onOpen:e=>{n(e),e?location.hash=`/library/sources/${encodeURIComponent(e)}`:location.hash=`#/library/sources`}})}var ao=[{id:`datasets`,label:`Datasets`,icon:Tn},{id:`prompts`,label:`Prompts`,icon:zn},{id:`sources`,label:`Sources`,icon:An}];function oo({section:e,sourceId:t}){return(0,X.jsxs)(`div`,{className:`library`,children:[(0,X.jsx)(`nav`,{className:`lib-sections`,"aria-label":`Library`,children:ao.map(({id:t,label:n,icon:r})=>(0,X.jsxs)(`a`,{href:`#/library/${t}`,...t===e?{"aria-current":`page`}:{},className:t===e?`on`:void 0,children:[(0,X.jsx)(r,{size:16,"aria-hidden":`true`}),(0,X.jsx)(`span`,{children:n})]},t))}),(0,X.jsx)(`section`,{className:`lib-section`,"data-section":e,children:e===`datasets`?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(rr,{}),(0,X.jsx)($r,{})]}):e===`prompts`?(0,X.jsx)(si,{}):(0,X.jsx)(io,{sourceId:t})})]})}var so=`0.1.2`,co=3,lo=3,uo=e=>Yn.find(t=>t.id===e),fo=e=>ao.find(t=>t.id===e),po=e=>new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`});function mo(){let e=J(),[t]=_e(`promptlab.profiles`),[n,r]=_e(`promptlab.workflows`),i=Fe(),a=Ge(),{pickDataset:o}=at(),{openRun:s}=ct(),[c,l]=(0,q.useState)(null),[u,d]=(0,q.useState)(null);(0,q.useEffect)(()=>{let t=!0;return e.sources().then(e=>{t&&l(e.sources)},()=>{t&&l([])}),e.queue({limit:lo}).then(e=>{t&&d(e.runs)},()=>{t&&d([])}),()=>{t=!1}},[e]);let f=(0,q.useMemo)(()=>n.list.filter(e=>e.work?.version===9),[n.list]),p=i.list??[],m=p.reduce((e,t)=>e+t.cases,0),h=(u??[]).filter(e=>e.status===`queued`||e.status===`running`).length,g=t.list.length===0?`setup`:i.list===null?null:p.length===0||m===0?`datasets`:u!==null&&u.length===0?`runs`:null,_=(...e)=>e.filter(Boolean).join(` · `)||void 0,v=uo(`library`),y=v.icon;return(0,X.jsxs)(`div`,{className:`home`,children:[(0,X.jsxs)(`ol`,{className:`home-line`,"aria-label":`Lab`,children:[(0,X.jsx)(ho,{id:`runs`,icon:uo(`runs`).icon,name:uo(`runs`).label,hub:!0,start:g===`runs`,fact:_(wt(f.length,`pipeline`),h>0&&`${h} running`),total:f.length,items:f.map(e=>({key:e.id,label:e.name,href:`#/runs`,onPick:()=>r({...n,at:e.id})}))}),(0,X.jsx)(ho,{id:`history`,icon:uo(`history`).icon,name:uo(`history`).label,fact:u&&u.length===0?`No runs yet`:void 0,items:(u??[]).map(e=>{let t=$t(e).scenarios.map(e=>e.percent==null?`–`:`${e.percent}%`).join(` · `);return{key:e.id,label:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`code`,{children:Ct(e.submittedAt)}),e.status!==`done`&&At(e.status)]}),sub:_(po(e.submittedAt),!!t&&t),href:`#/history`,onOpen:()=>s(e.id,{at:e.submittedAt,from:`home`})}})}),(0,X.jsxs)(`li`,{className:`home-stop home-fork`,"data-stop":`library`,children:[(0,X.jsxs)(`a`,{className:`home-name`,href:`#/library`,children:[(0,X.jsx)(`span`,{className:`home-mark`,"aria-hidden":`true`,children:(0,X.jsx)(y,{size:18})}),v.label]}),(0,X.jsxs)(`ol`,{className:`home-branch`,"aria-label":v.label,children:[(0,X.jsx)(ho,{id:`datasets`,to:`library/datasets`,branch:!0,icon:fo(`datasets`).icon,name:fo(`datasets`).label,start:g===`datasets`,fact:i.list?_(wt(p.length,`dataset`),wt(m,`case`)):void 0,total:p.length,items:p.map(e=>({key:e.id,label:e.name,sub:wt(e.cases,`case`),href:`#/library/datasets`,onPick:()=>o(e.id)}))}),(0,X.jsx)(ho,{id:`prompts`,to:`library/prompts`,branch:!0,icon:fo(`prompts`).icon,name:fo(`prompts`).label,fact:a.list?_(wt(a.list.length,`prompt`)):void 0,total:a.list?.length??0,items:(a.list??[]).map(e=>({key:e.id,label:e.name||e.text.split(`
8
- `)[0]||`Untitled`,sub:e.default?`Default`:void 0,href:`#/library/prompts`}))}),(0,X.jsx)(ho,{id:`sources`,to:`library/sources`,branch:!0,icon:fo(`sources`).icon,name:fo(`sources`).label,fact:c?_(wt(c.length,`source`)):void 0,total:c?.length??0,items:(c??[]).map(e=>({key:e.id,label:e.name,sub:wt(e.files,`file`),href:`#/library/sources/${encodeURIComponent(e.id)}`}))})]})]}),(0,X.jsx)(ho,{id:`setup`,icon:uo(`setup`).icon,name:uo(`setup`).label,start:g===`setup`,fact:_(wt(t.list.length,`profile`)),total:t.list.length,items:t.list.map(e=>({key:e.id,label:e.name||`Untitled`,sub:e.model,href:`#/setup`}))})]}),(0,X.jsxs)(`p`,{className:`home-version`,children:[`Evals Lab `,so]})]})}function ho({id:e,icon:t,name:n,to:r,fact:i,items:a,total:o=a.length,hub:s,start:c,branch:l}){let u=o-Math.min(a.length,co);return(0,X.jsxs)(`li`,{className:[`home-stop`,s&&`hub`,c&&`start`,l&&`branch`].filter(Boolean).join(` `),"data-stop":e,children:[(0,X.jsxs)(`a`,{className:`home-name`,href:`#/${r??e}`,children:[(0,X.jsx)(`span`,{className:`home-mark`,"aria-hidden":`true`,children:(0,X.jsx)(t,{size:l?15:18})}),n]}),c&&(0,X.jsx)(`span`,{className:`home-start`,children:`Start Here`}),i&&(0,X.jsx)(`span`,{className:`home-fact`,children:i}),a.length>0&&(0,X.jsxs)(`ul`,{className:`home-items`,children:[a.slice(0,co).map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`a`,{href:e.href,onClick:t=>{e.onOpen?(t.preventDefault(),e.onOpen()):e.onPick?.()},children:[(0,X.jsx)(`span`,{className:`home-item`,children:e.label}),e.sub&&(0,X.jsx)(`span`,{className:`home-sub`,children:e.sub})]})},e.key)),u>0&&(0,X.jsx)(`li`,{children:(0,X.jsxs)(`a`,{className:`home-more`,href:`#/${r??e}`,children:[u,` more`]})})]})]})}function go({list:t,at:n,canRestore:a,onSelect:o,onNew:s,onClone:c,onRename:l,onDelete:u,onRestore:d,onExport:f,onImport:p}){let[m,h]=(0,q.useState)(!1),g=t.find(e=>e.id===n),_=`Pipeline - ${g?.name?.trim()||`Untitled`}`;return(0,X.jsxs)(A,{id:`pipelines`,title:_,actions:[{label:`Rename`,icon:i,onSelect:()=>h(!0)},{label:`Clone`,icon:N,onSelect:c},{label:`Export YAML`,icon:e,onSelect:f},{label:`Import YAML…`,icon:G,onSelect:p},{label:`Restore…`,icon:r,disabled:!a,onSelect:d},{label:`Delete`,icon:ne,destructive:!0,onSelect:u}],children:[(0,X.jsxs)(`div`,{className:`prop`,children:[(0,X.jsx)(`span`,{className:`prop-name`,children:`Pipeline`}),(0,X.jsx)(`span`,{className:`prop-value`,children:(0,X.jsx)(`select`,{"aria-label":`Pipeline`,value:n,onChange:e=>o(e.target.value),children:t.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name||`Untitled`},e.id))})})]}),(0,X.jsxs)(`button`,{type:`button`,className:`ghost add-btn`,onClick:s,children:[(0,X.jsx)(W,{size:14,"aria-hidden":`true`}),`New pipeline`]}),m&&(0,X.jsx)(B,{title:`Rename pipeline`,value:g?.name??``,onCommit:l,onClose:()=>h(!1)})]})}function _o({problems:e,error:t,run:n,submitting:r,onRun:i,onStop:a,onOpen:o}){let s=!!n&&!Bt(n.status),c=n?.progress?.total??0,l=n?.progress?.n??0,u=s&&c?Math.round(l/c*100):null,d=n&&(0,X.jsxs)(`button`,{type:`button`,className:`runbar-open`,title:`Open this run`,onClick:o,children:[(0,X.jsx)(`span`,{className:`runbar-word`,children:kt(n.status)}),vo(n)&&(0,X.jsx)(`span`,{className:`runbar-detail`,children:vo(n)})]}),f=s?d:e.length?(0,X.jsxs)(`span`,{className:`runbar-why`,children:[xo(e[0]),bo(e[0])]}):t?(0,X.jsx)(`span`,{className:`runbar-why bad`,children:xo(t)}):d??(0,X.jsx)(`span`,{className:`runbar-why`,children:`Ready to run.`});return(0,X.jsxs)(`div`,{className:`runbar`,children:[(0,X.jsxs)(`div`,{className:`runbar-row`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`run`,disabled:e.length>0||r,onClick:i,children:[(0,X.jsx)(Hn,{size:16,"aria-hidden":`true`}),`Run`]}),(0,X.jsx)(`span`,{className:`runbar-line`,role:`status`,children:f}),s&&(0,X.jsxs)(`button`,{type:`button`,className:`ghost runbar-stop`,onClick:a,children:[(0,X.jsx)(Cn,{size:14,"aria-hidden":`true`}),`Stop`]})]}),u!=null&&(0,X.jsx)(`div`,{className:`runbar-meter`,role:`progressbar`,"aria-label":`Run progress`,"aria-valuenow":u,"aria-valuemin":0,"aria-valuemax":100,children:(0,X.jsx)(`div`,{className:`runbar-fill`,style:{width:`${u}%`}})})]})}function vo(e){return e.status===`queued`?e.behind?`behind ${e.behind}`:`next in line`:e.status===`running`&&e.progress?.total?`${e.progress.n} of ${e.progress.total}`:``}var yo=[[/^Setup profile .* not found$/,`#/setup`,`Open Setup`],[/^Source .* not found$/,`#/library/sources`,`Open Sources`],[/^Dataset .* not found$/,`#/library/datasets`,`Open Datasets`]];function bo(e){let t=yo.find(([t])=>t.test(e.trim()));return t?(0,X.jsxs)(X.Fragment,{children:[` `,(0,X.jsx)(`a`,{className:`runbar-fix`,href:t[1],children:t[2]})]}):null}var xo=e=>{let t=e.trim();if(!t)return t;let n=t[0].toUpperCase()+t.slice(1);return/[.!?]$/.test(n)?n:`${n}.`},So=10;function Co({onPick:e,onClose:t,used:n}){let{list:r,error:i}=Ge(),[a,o]=(0,q.useState)(``),[s,c]=(0,q.useState)(`all`),[l,u]=(0,q.useState)(0),d=r??[],f=d.filter(e=>ii(e,a,s,n??{byScenario:new Set,byAll:new Set})).sort((e,t)=>Number(t.default)-Number(e.default)),p=Math.ceil(f.length/So),m=Math.min(l,Math.max(0,p-1)),h=f.slice(m*So,(m+1)*So);return(0,X.jsxs)(L,{title:`Select prompt`,onClose:t,className:`sp`,initialFocus:`.sp input[type=search]`,children:[(0,X.jsx)(ee,{noun:`prompts`,search:{label:`Search prompts`,placeholder:`Search prompts`,value:a,onChange:e=>{o(e),u(0)}},filters:[{key:`show`,label:`Show`,value:s,onChange:e=>{c(e),u(0)},options:ni}],count:{shown:f.length,total:d.length}}),r===null?(0,X.jsx)(`p`,{className:`note${i?` bad`:``}`,role:i?`alert`:void 0,children:i??`Loading…`}):d.length===0?(0,X.jsx)(`p`,{className:`note`,children:`No prompts yet.`}):f.length===0?(0,X.jsx)(`p`,{className:`note`,children:`No prompts match these filters.`}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`ul`,{className:`sp-list`,"aria-label":`Prompts`,children:h.map(t=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,className:`sp-pick`,onClick:()=>e(t),children:[(0,X.jsxs)(`span`,{className:`sp-head`,children:[(0,X.jsx)(`span`,{className:`sp-title`,children:Le(t)}),t.default&&(0,X.jsx)(`span`,{className:`pl-default`,children:`Default`})]}),(0,X.jsx)(`span`,{className:`sp-text`,children:t.text.trim()||`—`}),(0,X.jsxs)(`span`,{className:`sp-meta`,children:[(0,X.jsx)(`span`,{children:t.useCount===1?`1 use`:`${t.useCount} uses`}),t.lastUsed&&(0,X.jsxs)(`span`,{children:[`last `,ai(t.lastUsed)]}),(0,X.jsxs)(`span`,{children:[`v`,t.version]})]})]})},t.id))}),p>1&&(0,X.jsxs)(`div`,{className:`sp-pager`,children:[(0,X.jsx)(`button`,{type:`button`,className:`ghost`,disabled:m===0,onClick:()=>u(m-1),children:`Back`}),(0,X.jsxs)(`span`,{className:`sp-page`,children:[m+1,` of `,p]}),(0,X.jsx)(`button`,{type:`button`,className:`ghost`,disabled:m>=p-1,onClick:()=>u(m+1),children:`Forward`})]})]})]})}function wo(e){let t=K(),n=e.jobs.at(-1),r=b(t.defaultKind()),i=t.outOf(n),a=t.outOf(r),o=e=>!y(e.type)||y(e.type).includes(a.kind),s=i.modifiers.filter(o);return s.length&&(r=t.withOut(r,{...a,modifiers:s})),ts(e,[...e.jobs.slice(0,-1),t.withOut(n,{...i,modifiers:i.modifiers.filter(e=>!o(e))}),r],()=>({prompt:``}))}function To(e,n){if(e.jobs.length<2)return e;let r=e.jobs.slice();if(n===r.length-1){let e=K(),i=e.outOf(r[n]),a=e.outOf(r[n-1]),o=i.modifiers.filter(e=>!y(e.type)||y(e.type).includes(a.kind)),s=[...a.modifiers,...o];r[n-1]=e.withOut(r[n-1],{...a,modifiers:s.length?s:t(a.kind)})}return r.splice(n,1),{...e,jobs:r,scenarios:e.scenarios.map(e=>({...e,stages:e.stages.filter((e,t)=>t!==n)}))}}function Eo(e,t){let n={...structuredClone(e.jobs[t]),id:K().newId()};n.name=`${K().jobLabel(e,t)} copy`;let r=[...e.jobs.slice(0,t+1),n,...e.jobs.slice(t+1)],i=e.scenarios.map(e=>({...e,stages:[...e.stages.slice(0,t+1),{...e.stages[t]},...e.stages.slice(t+1)]}));return{...e,jobs:r,scenarios:i}}function Do(e,t,n){let r=e.jobs.map((e,r)=>r===t?{...e,name:n.trim()}:e);return{...e,jobs:r}}function Oo(e,n,r){let i=K().outOf(e.jobs[n]);if(i.kind===r||!r)return e;let a=n===e.jobs.length-1,o=i.modifiers.filter(e=>!y(e.type)||y(e.type).includes(r));return{...e,jobs:e.jobs.map((e,i)=>i===n?K().withOut(e,{kind:r,...s(r),modifiers:a?o.length?o:t(r):[]}):e)}}var ko=(e,t)=>({...e,tests:[...e.tests,t]}),Ao=(e,t)=>({...e,tests:e.tests.filter((e,n)=>n!==t)});function jo(e,t,n){let r=t+n;if(r<0||r>=e.tests.length)return e;let i=e.tests.slice();return[i[t],i[r]]=[i[r],i[t]],{...e,tests:i}}var Mo=(e,t,n)=>({...e,tests:e.tests.map((e,r)=>r===t?{...e,name:n.trim()}:e)}),No=(e,t,n)=>({...e,tests:e.tests.map((e,r)=>r===t?n:e)}),Po=e=>e[0]?{id:e[0].id,name:e[0].name}:{id:``,name:``};function Fo(e,t,n=``){let r=K(),i=!!r.callEntryOf(e.jobs[0])?.newCell,a={id:r.newId(),name:``,profile:i?e.scenarios.at(-1)?.profile??t:t,stages:e.jobs.map((e,t)=>r.callEntryOf(e)?.newCell?.(r.callOf(e))??{prompt:t===0?n:``})};return{...e,scenarios:[...e.scenarios,a]}}function Io(e){let t=new Set(e.map(e=>e.trim().toLowerCase())),n=1;for(;t.has(`pipeline ${n}`);)n+=1;return`Pipeline ${n}`}var Lo={id:`samples`,name:`Sample library`};function Ro(e,t,n=``){let r=K().withContent({...K().blankPipeline({name:`Evals`}),tests:t?[K().newTest(`metrics`,``,{dataset:{id:t.id,name:t.name},metrics:[{type:`case`}]})]:[]},{type:`source`,ref:{...Lo},first:null,loops:1});if(t){let e=K();r={...r,jobs:[e.withCall(e.withOut(r.jobs[0],{kind:`list`,...s(`list`),modifiers:[{type:`tidy`},{type:`dedupe`}]}),{tokenMappings:e.mappingsFor(n)})]}}return r=Fo(r,e,n),Fo(r,e,n)}function zo(e,t){return!t.id||!e.scenarios.some(e=>!e.profile.id)?e:{...e,scenarios:e.scenarios.map(e=>e.profile.id?e:{...e,profile:{...t}})}}function Bo(e,t){let n={...structuredClone(e.scenarios[t]),id:K().newId(),name:`${K().scenarioLabel(e,t)} copy`};return{...e,scenarios:[...e.scenarios.slice(0,t+1),n,...e.scenarios.slice(t+1)]}}function Vo(e,t){return{...e,scenarios:e.scenarios.filter((e,n)=>n!==t)}}function Ho(e,t,n){return{...e,scenarios:e.scenarios.map((e,r)=>r===t?{...e,name:n.trim()}:e)}}function Uo(e,t,n,r){let i=e.scenarios.map((e,i)=>{if(i!==t)return e;if(n===0)return{...e,profile:r??e.profile};let a=e.stages.map((e,t)=>{if(t!==n)return e;if(r)return{...e,profile:r};let{profile:i,...a}=e;return a});return{...e,stages:a}});return{...e,scenarios:i}}function Wo(e,t,n,r){return{...e,scenarios:e.scenarios.map((e,i)=>i===t?{...e,stages:e.stages.map((e,t)=>t===n?{...e,prompt:r}:e)}:e)}}function Go(e,t,n,r,i){return{...e,scenarios:e.scenarios.map((e,a)=>a===t?{...e,stages:e.stages.map((e,t)=>t===n?{...e,prompt:r,from:{...i}}:e)}:e)}}function Ko(e){return new Set((e?.stages??[]).flatMap(e=>e.from?.id?[e.from.id]:[]))}function qo(e){let t=Ko(e[0]);for(let n of e.slice(1)){let e=Ko(n);for(let n of[...t])e.has(n)||t.delete(n)}return t}function Jo(e,t,n,r){return es(e,t,e=>e.map(e=>e.name===n?{...e,...r}:e))}function Yo(e,t,n,r){let i=n.trim();return i?es(e,t,e=>e.some(e=>e.name===i)?e:[...e,K().tokenMapping(i,r)]):e}function Xo(e,t,n,r){let i=r.name.trim();return i?es(e,t,e=>i!==n&&e.some(e=>e.name===i)?e:e.map(e=>e.name===n?e.type===r.type?{...e,name:i}:K().tokenMapping(i,r.type):e)):e}function Zo(e,t,n){return es(e,t,e=>e.filter(e=>e.name!==n))}var Qo=/^(?:text|reply|stage[1-9]\d*(?:\..*)?)$/;function $o(e,t,n,r){let i=n.trim();return i?/[{}\s]/.test(i)?`A name has no braces or spaces.`:Qo.test(i)?`{${i}} is filled in by the lab.`:i!==r&&K().callOf(e.jobs[t]).tokenMappings.some(e=>e.name===i)?`{${i}} is already mapped.`:null:`A mapping needs a name.`}function es(e,t,n){let r=K();return{...e,jobs:e.jobs.map((e,i)=>i===t?r.withCall(e,{tokenMappings:n(r.callOf(e).tokenMappings)}):e)}}function ts(e,t,n){let r=t.length,i=e.scenarios.map(e=>{let t=e.stages.slice(0,r);for(;t.length<r;)t.push(n(t.length));return{...e,stages:t}});return{...e,jobs:t,scenarios:i}}async function ns(e){try{return await navigator.clipboard.writeText(e),!0}catch{}let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=!1;try{n=document.execCommand(`copy`)}catch{n=!1}return t.remove(),n}function rs({k:e,pipeline:t,sources:n,edit:r,offer:i}){let[a,o]=(0,q.useState)(!1),s=K().contentOf(t),c=e=>r(K().withContent(t,e)),l=()=>{let e=t;r(K().withContent(e,null)),i({label:`Removed the content`,restore:()=>r(e)})},u=K().CONTENT_TYPES,d=K().slotEntry(`content`)?.entry,f=s===null?[]:[{label:`Change content`,icon:U.rename,onSelect:()=>o(!0)},{label:`Remove content`,icon:U.remove,destructive:!0,onSelect:l}];return(0,X.jsxs)(A,{id:`job-0-content`,title:d?.label??`Content`,level:3,note:ls(s,n),actions:f,about:d?.description,children:[s===null?(0,X.jsx)(`p`,{className:`note`,children:`No content.`}):s.type===`source`?(0,X.jsx)(k,{label:`Content`,rows:[{key:`source`,label:`Source`,hint:u.source?.description,control:{type:`static`,text:cs(s,n)}},{key:`first`,label:`Run first`,control:{type:`text`,value:s.first==null?``:String(s.first),placeholder:`all`,onChange:e=>c({...s,first:e.trim()?ss(e):null})}},{key:`loops`,label:`Loop`,control:{type:`text`,value:String(s.loops),placeholder:`1`,onChange:e=>c({...s,loops:Math.max(1,ss(e)??1)})}}]}):s.type===`text`?(0,X.jsxs)(`label`,{className:`prompt`,children:[(0,X.jsx)(`span`,{className:`prop-name`,children:`Text`}),(0,X.jsx)(`textarea`,{value:s.text,"aria-label":`Content text`,placeholder:`The item every scenario is sent`,onChange:e=>c({...s,text:e.target.value})})]}):(0,X.jsx)(k,{label:`Content`,rows:[{key:`items`,label:`Items`,hint:u[s.type]?.description,control:{type:`static`,text:`None`}}]}),s===null&&(0,X.jsxs)(`button`,{type:`button`,className:`ghost add-btn`,onClick:()=>o(!0),children:[(0,X.jsx)(U.add,{size:14,"aria-hidden":`true`}),`Add content`]}),a&&(0,X.jsxs)(L,{title:s===null?`Add content`:`Change content`,onClose:()=>o(!1),children:[(0,X.jsx)(Ua,{mode:`pick`,onPick:e=>{r(os(K().withContent(t,{type:`source`,ref:R(e.id,e.name),first:null,loops:1}),K().sourceTypeOf(e)?.sendsImage??!1)),o(!1)}}),(0,X.jsxs)(`div`,{className:`pick-others`,children:[(0,X.jsx)(`h2`,{className:`shead-title`,children:`Without a Source`}),(0,X.jsxs)(`button`,{type:`button`,className:`ghost pick-item`,onClick:()=>{r(os(K().withContent(t,{type:`text`,text:``}),!1)),o(!1)},children:[(0,X.jsx)(`span`,{children:u.text?.label??`Text`}),u.text?.description&&(0,X.jsx)(`span`,{className:`pick-about`,children:u.text.description})]}),(0,X.jsxs)(`button`,{type:`button`,className:`ghost pick-item`,onClick:()=>{r(os(K().withContent(t,{type:`prompt`}),!1)),o(!1)},children:[(0,X.jsx)(`span`,{children:u.prompt?.label??`Prompt only`}),u.prompt?.description&&(0,X.jsx)(`span`,{className:`pick-about`,children:u.prompt.description})]})]})]})]})}function is({k:e,pipeline:t,edit:n}){let r=K().CONTENT_TYPES[K().contentOf(t)?.type??``]?.inline,i=e>0?`${K().jobLabel(t,e-1)} · ${u(K().outOf(t.jobs[e-1]).kind)}`:null,a=[...i?[{key:`input`,label:`Input`,control:{type:`static`,text:i}}]:[],...r?[]:[as(t,e,n)]];return a.length?(0,X.jsx)(k,{label:`Job ${e+1} call`,rows:a}):null}var as=(e,t,n)=>({key:`image`,label:`Image`,control:{type:`checkbox`,checked:K().callOf(e.jobs[t]).withImage,label:`Send`,onChange:r=>n({...e,jobs:e.jobs.map((e,n)=>n===t?K().withCall(e,{withImage:r}):e)})}}),os=(e,t)=>({...e,jobs:e.jobs.map((e,n)=>n===0?K().withCall(e,{withImage:t}):e)}),ss=e=>{let t=Number.parseInt(e,10);return Number.isNaN(t)?null:t},cs=(e,t)=>{let n=t.find(t=>t.id===e.ref.id);return n?`${n.name}, ${n.files} ${n.files===1?`file`:`files`}`:`A Source that is gone: ${e.ref.name}`},ls=(e,t)=>e?e.type===`source`?cs(e,t):K().CONTENT_TYPES[e.type]?.label??e.type:`none`,us={prompt:{Settings:is},httpRequest:{Settings:ps,promptLabel:e=>fs(e)?.fields.length?`Prompt`:`Body`,cellRows:hs,scenarioActions:vs}},ds=(e,t)=>us[K().callOf(e.jobs[t])?.type??``]??us.prompt,fs=e=>K().HTTP_APIS[e?.api??``];function ps({k:e,pipeline:t,edit:n}){let r=K().callOf(t.jobs[e]),i=[{key:`step`,label:`Step`,control:{type:`static`,text:r.step}},{key:`api`,label:`API`,control:{type:`select`,value:r.api,onChange:r=>n({...t,jobs:t.jobs.map((t,n)=>n===e?K().withCall(t,{api:r}):t)}),options:Object.entries(K().HTTP_APIS).map(([e,t])=>({value:e,label:t.label}))}},{key:`request`,label:`Request`,control:{type:`code`,text:`${r.method} ${r.path}${ms(r.query)}`}},{key:`readAs`,label:`Read as`,control:r.readAs?{type:`code`,text:r.readAs}:{type:`static`,text:`Reply text`}},{key:`body`,label:`Body`,control:{type:`code`,text:JSON.stringify(r.body,null,2)}}];return(0,X.jsx)(k,{label:`Job ${e+1} HTTP Request`,rows:i})}var ms=e=>{let t=Object.entries(e).map(([e,t])=>`${e}=${t}`).join(`&`);return t?`?${t}`:``};function hs(e,t,n){let r=fs(e);if(!r)return[];let i=(e,r,i=!1)=>({key:e,label:r,control:n?i?{type:`textarea`,value:t[e]??``,onChange:t=>n({[e]:t})}:{type:`text`,value:t[e]??``,onChange:t=>n({[e]:t})}:{type:`static`,text:t[e]??`—`}}),a=[];if(r.fields.includes(`system`)&&a.push(i(`system`,`System`,!0)),r.fields.includes(`model`)&&a.push(i(`model`,`Model`)),r.fields.includes(`settings`))for(let e of r.settings){let r=t.settings?.[e]??``;a.push({key:`setting-${e}`,label:e,control:n?{type:`text`,value:r,size:`num`,onChange:r=>n({settings:{...t.settings,[e]:r}})}:{type:`static`,text:r||`—`}})}return r.fields.includes(`prefill`)&&a.push(i(`prefill`,`Prefill`)),a}function gs(e,t){return JSON.stringify((fs(e)??K().HTTP_APIS.raw).place(e.body,t),null,2)}function _s(e,t,n,r){let i=fs(t),a=K().contentOf(e),o=a?.type===`source`?a.ref.name:null,s=i?.cellOf(t.body),c=s?[`prompt`,`system`,`model`,`prefill`].filter(e=>(n[e]??``)!==(s[e]??``)).concat(Object.keys({...s.settings,...n.settings}).filter(e=>(n.settings?.[e]??``)!==(s.settings?.[e]??``))):[],l=[`In the Power Automate flow${o?` "${o}"`:``}, edit the HTTP action "${t.step}".`,`Replace its Body with the JSON below, exactly as written. Leave its URI, method and headers as they are.`,`Expressions such as @{items('Apply_to_each')} are Power Automate's own; keep them as they are.`];return c.length&&l.push(`What changes from the flow as it is: ${c.join(`, `)} (the lab's scenario "${r}").`),n.prefill&&l.push(`The body ends with an assistant message, ${JSON.stringify(n.prefill)}, which starts the model's reply. The reply the action returns does not repeat it, so wherever the flow reads the reply`+(t.readAs?` (${t.readAs})`:``)+` put ${JSON.stringify(n.prefill)} back in front of the text, for example with concat('${n.prefill.replace(/'/g,`''`)}', …).`),l.push(``,`Body:`,"```json",gs(t,n),"```"),l.join(`
9
- `)}function vs(e,t,n,r){let i=K().callOf(e.jobs[n]),a=e.scenarios[t]?.stages[n];if(!a)return[];let o=async(e,t)=>r(await ns(e)?`Copied ${t}.`:`Could not copy.`);return[{label:`Copy`,icon:N,onSelect:()=>void o(gs(i,a),`the body`)},{label:`Copy as AI prompt`,icon:Gn,onSelect:()=>void o(_s(e,i,a,K().scenarioLabel(e,t)),`the AI prompt`)}]}function ys({label:e,profile:t,prompt:n,onPrompt:r,rows:i=[],promptLabel:a=`Prompt`}){return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(k,{label:`${e} setup`,rows:[{key:`profile`,label:`Setup profile`,control:t},...i]}),(0,X.jsxs)(`label`,{className:`prompt`,children:[(0,X.jsx)(`span`,{className:`prop-name`,children:a}),(0,X.jsx)(`textarea`,{value:n,"aria-label":`${e}, prompt`,rows:8,readOnly:!r,onChange:e=>r?.(e.target.value)})]})]})}function bs({run:e,i:t,onClose:n}){let r=K(),i=r.scenarioLabel(e,t),a=e.scenarios[t],o=t=>t&&(e.profiles?.[t.id]?.name||t.name)||`—`,s=e.jobs.length;return(0,X.jsx)(O,{title:i,sections:(a?.stages??[]).map((t,n)=>({key:`job-${n}`,...s>1?{title:r.jobLabel(e,n)}:{},children:(0,X.jsx)(ys,{label:s>1?`${i}, ${r.jobLabel(e,n)}`:i,profile:{type:`static`,text:n===0?o(a.profile):t.profile?o(t.profile):`Same as ${r.jobLabel(e,0)}`},prompt:t.prompt,rows:us[r.callOf(e.jobs[n])?.type??``]?.cellRows?.(r.callOf(e.jobs[n]),t)??[],promptLabel:us[r.callOf(e.jobs[n])?.type??``]?.promptLabel?.(r.callOf(e.jobs[n]))??`Prompt`})})),closeLabel:`Close`,onClose:n})}function xs({k:e,pipeline:t,profiles:n,scenarioCap:r,onRequestRename:i,onAdd:a,onClone:o,onRemove:s,onProfile:c,onPrompt:l,onSelectPrompt:u,onClearPrompt:d,defaultPrompt:f,onRevert:p,onCell:m,say:h=()=>{}}){let g=t.scenarios.length,_=ds(t,e),v=K().callOf(t.jobs[e]);return(0,X.jsx)(A,{id:`job-${e}-scenarios`,title:`Scenarios`,level:3,note:`${g} ${g===1?`scenario`:`scenarios`}`,children:(0,X.jsx)(j,{noun:`scenario`,items:t.scenarios,min:1,max:r,onAdd:a,onClone:o,onRemove:s,onRename:i,extra:(n,r)=>[{label:`Select prompt…`,icon:Fn,onSelect:()=>u(r)},{label:`Clear prompt`,icon:U.clear,disabled:!n.stages[e]?.prompt,onSelect:()=>d(r)},...p?[{label:`Revert to default`,icon:U.revert,disabled:(n.stages[e]?.prompt??``)===f,onSelect:()=>p(r)}]:[],..._.scenarioActions?.(t,r,e,h)??[]],empty:(0,X.jsx)(`p`,{className:`note`,children:`No scenarios yet.`}),renderItem:(r,i,a)=>{let o=K().scenarioLabel(t,i),s=r.stages[e]??{prompt:``};return(0,X.jsx)(A,{id:`job-${e}-scenario-${i}`,title:o,level:3,actions:a,children:(0,X.jsx)(ys,{label:o,profile:e===0?{type:`select`,value:r.profile.id,options:Ss(n,r.profile),onChange:e=>c(i,Cs(n,e))}:{type:`select`,value:s.profile?.id??``,options:[{value:``,label:`Same as ${K().jobLabel(t,0)}`},...Ss(n,s.profile)],onChange:e=>c(i,e?Cs(n,e):null)},prompt:s.prompt,onPrompt:e=>l(i,e),rows:_.cellRows?.(v,s,m?e=>m(i,e):void 0)??[],promptLabel:_.promptLabel?.(v)??`Prompt`})},`${i}-${e}`)}})})}var Ss=(e,t)=>[...t?.id&&!e.some(e=>e.id===t.id)?[{value:t.id,label:`${t.name||t.id} (missing)`}]:[],...e.map(e=>({value:e.id,label:e.name}))],Cs=(e,t)=>{let n=e.find(e=>e.id===t);return n?{id:n.id,name:n.name}:null};function ws({k:e,pipeline:t,edit:n,offer:r}){let[i,a]=(0,q.useState)(null),o=K().callOf(t.jobs[e]).tokenMappings,s=i?.mode===`edit`?o.find(e=>e.name===i.name):void 0;return(0,X.jsxs)(A,{id:`job-${e}-tokens`,title:`Token mappings`,level:3,note:Ts(o),about:`A {name} in a prompt is replaced by its value here, the same for every scenario; a {name}…{/name} passage is kept only while ticked.`,children:[(0,X.jsx)(I,{mappings:o,onValue:(r,i)=>n(Jo(t,e,r,{value:i})),onEnabled:(r,i)=>n(Jo(t,e,r,{enabled:i})),onEdit:e=>a({mode:`edit`,name:e}),onRemove:i=>{let a=t;n(Zo(a,e,i)),r({label:`Removed {${i}}`,restore:()=>n(a)})},onAdd:()=>a({mode:`add`})}),i&&(i.mode===`add`||s)&&(0,X.jsx)(V,{title:s?K().TOKEN_TYPES[s.type]?.notation(s.name)??`{${s.name}}`:`New mapping`,initial:s?{name:s.name,type:s.type}:{name:``,type:`value`},problem:n=>$o(t,e,n,s?.name),onSave:o=>{let c=t;i?.mode===`add`?n(Yo(c,e,o.name,o.type)):s&&(n(Xo(c,e,s.name,o)),o.type!==s.type&&s.value&&r({label:`Changed {${s.name}} to ${K().TOKEN_TYPES[o.type]?.label.toLowerCase()??o.type}`,restore:()=>n(c)})),a(null)},onClose:()=>a(null)},i.mode===`edit`?i.name:`add`)]})}function Ts(e){let t=K().TOKEN_TYPES,n=new Map;for(let t of e)n.set(t.type,(n.get(t.type)??0)+1);let r=[...n].map(([e,n])=>`${n} ${(t[e]?.label??e).toLowerCase()}${n===1?``:`s`}`);return r.length?r.join(`, `):`No mappings`}function Es({pipeline:e,profiles:t,sources:n,scenarioCap:r,prompt:i=``,defaultPrompt:a,protectedTerms:s,edit:c,offer:l}){let[u,d]=(0,q.useState)(null),[f,p]=(0,q.useState)(null),[m,h]=(0,q.useState)(null),g=t=>{let n=e,r=`Removed ${K().jobLabel(n,t)}`;c(To(n,t)),l({label:r,restore:()=>c(n)})},_=!e.scenarios.length;return(0,X.jsxs)(`div`,{className:`jobs`,children:[m&&(0,X.jsx)(`p`,{className:`note`,role:`status`,children:m}),(0,X.jsx)(j,{noun:`job`,items:e.jobs,min:1,addDisabled:_,onAdd:()=>c(wo(e)),onClone:t=>c(Eo(e,t)),onRemove:g,onRename:e=>d({job:e}),renderItem:(u,f,m)=>{let g=`Job ${f+1}${u.name?.trim()?` - ${u.name.trim()}`:``}`;return(0,X.jsxs)(A,{id:`job-${f}`,title:g,level:2,actions:m,children:[f===0&&(0,X.jsx)(rs,{k:f,pipeline:e,sources:n,edit:c,offer:l}),(0,X.jsxs)(A,{id:`job-${f}-call`,title:K().STEP_TYPES[K().callOf(u)?.type]?.label??`Call`,level:3,about:K().STEP_TYPES[K().callOf(u)?.type]?.description,children:[(()=>{let{Settings:t}=ds(e,f);return(0,X.jsx)(t,{k:f,pipeline:e,edit:c})})(),(0,X.jsx)(xs,{k:f,pipeline:e,profiles:t,scenarioCap:r,onRequestRename:e=>d({job:f,scenario:e}),onAdd:()=>c(Fo(e,Po(t),i)),onClone:t=>c(Bo(e,t)),onRemove:t=>{let n=e,r=`Removed ${K().scenarioLabel(n,t)}`;c(Vo(n,t)),l({label:r,restore:()=>c(n)})},onProfile:(t,n)=>c(Uo(e,t,f,n)),onPrompt:(t,n)=>c(Wo(e,t,f,n)),onCell:(t,n)=>c(Ds(e,t,f,n)),say:h,onSelectPrompt:e=>p({i:e,k:f}),onClearPrompt:t=>{let n=e;c(Wo(n,t,f,``)),l({label:`Cleared ${K().scenarioLabel(n,t)}'s prompt`,restore:()=>c(n)})},...f===0&&a?{defaultPrompt:a.text,onRevert:t=>{let n=e;c(Go(n,t,0,a.text,{id:a.id,name:Le(a)})),l({label:`Reverted ${K().scenarioLabel(n,t)} to the default`,restore:()=>c(n)})}}:{}}),!K().callEntryOf(u)?.verbatim&&(0,X.jsx)(ws,{k:f,pipeline:e,edit:c,offer:l})]}),(0,X.jsx)(z,{id:`job-${f}-output`,title:K().STEP_TYPES[K().replyOf(u)?.type]?.label??`Reply`,about:K().STEP_TYPES[K().replyOf(u)?.type]?.description,out:K().outOf(u),outputKinds:o(),modifiers:x(),onKind:t=>c(Oo(e,f,t)),onSetting:(t,n)=>c(Os(e,f,e=>({...e,[t]:n}))),...s?{protectedTerms:s}:{},offer:l,onModifier:(t,n)=>c(ks(e,f,t,n)),onAddModifier:t=>c(Os(e,f,e=>({...e,modifiers:[...e.modifiers,t]}))),onRemoveModifier:t=>{let n=e;c(Os(n,f,e=>({...e,modifiers:e.modifiers.filter((e,n)=>n!==t)}))),l({label:`Removed a modifier`,restore:()=>c(n)})}})]},f)}}),_&&(0,X.jsx)(`p`,{className:`note add-why`,children:`Add a scenario first.`}),u&&`scenario`in u?(0,X.jsx)(B,{title:`Rename ${K().scenarioLabel(e,u.scenario)}`,value:e.scenarios[u.scenario]?.name??``,onCommit:t=>c(Ho(e,u.scenario,t)),onClose:()=>d(null)}):u?(0,X.jsx)(B,{title:`Rename ${K().jobLabel(e,u.job)}`,value:e.jobs[u.job]?.name??``,onCommit:t=>c(Do(e,u.job,t)),onClose:()=>d(null)}):null,f&&(0,X.jsx)(Co,{onClose:()=>p(null),used:{byScenario:Ko(e.scenarios[f.i]),byAll:qo(e.scenarios)},onPick:t=>{let n=e;c(Go(n,f.i,f.k,t.text,{id:t.id,name:Le(t)})),p(null),l({label:`Picked ${Le(t)}`,restore:()=>c(n)})}})]})}var Ds=(e,t,n,r)=>({...e,scenarios:e.scenarios.map((e,i)=>i===t?{...e,stages:e.stages.map((e,t)=>{if(t!==n)return e;let i={...e,...r};for(let[e,t]of Object.entries(r))t===``&&e!==`prompt`&&e!==`system`&&delete i[e];return i})}:e)}),Os=(e,t,n)=>({...e,jobs:e.jobs.map((e,r)=>r===t?K().withOut(e,n(K().outOf(e))):e)}),ks=(e,t,n,r)=>Os(e,t,e=>({...e,modifiers:e.modifiers.map((e,t)=>t===n?r:e)})),As={metrics:{Editor:e=>(0,X.jsx)(Fs,{...e}),actions:(e,t,n)=>`dataset`in e&&e.dataset&&n.length?[{label:`Edit`,icon:U.edit,onSelect:()=>t(n[0].filename)}]:[]}};function js({pipeline:e,datasets:t,graded:n,edit:r,offer:i,openCaseEditor:a,children:o,profiles:s=[],labGrader:c=null}){let[l,u]=(0,q.useState)(!1),[d,f]=(0,q.useState)(null),p=e.tests,m=p.findIndex(e=>`dataset`in e&&e.dataset),h=(t,n)=>{let a=e;r(t),i({label:n,restore:()=>r(a)})};return(0,X.jsxs)(A,{id:`tests`,title:`Tests`,level:2,note:p.length?String(p.length):`None`,children:[(0,X.jsx)(j,{noun:`test`,items:p,empty:(0,X.jsx)(`p`,{className:`note`,children:`No tests — the run is unscored.`}),onAdd:()=>u(!0),onRename:e=>f(e),onRemove:t=>h(Ao(e,t),`Removed ${K().testLabel(e,t)}`),extra:(t,r)=>[...As[t.type]?.actions?.(t,a,n)??[],...K().TEST_TYPES[t.type]?.toMetrics?[{label:`Convert to Metrics`,icon:U.edit,onSelect:()=>h(No(e,r,K().TEST_TYPES[t.type].toMetrics(t)),`Converted ${K().testLabel(e,r)} to Metrics`)}]:[],{label:`Move up`,icon:U.moveUp,disabled:r===0,onSelect:()=>h(jo(e,r,-1),`Moved ${K().testLabel(e,r)} up`)},{label:`Move down`,icon:U.moveDown,disabled:r===p.length-1,onSelect:()=>h(jo(e,r,1),`Moved ${K().testLabel(e,r)} down`)}],renderItem:(n,i,a)=>{let l=K().testLabel(e,i),u=t=>r(No(e,i,t));return(0,X.jsxs)(A,{id:`test-${i}`,title:l,level:3,note:K().TEST_TYPES[n.type]?.label??n.type,about:K().TEST_TYPES[n.type]?.description,actions:a,...d===i?{rename:{value:n.name||l,onCommit:t=>{r(Mo(e,i,t)),f(null)},onCancel:()=>f(null)}}:{},children:[(()=>{let r=As[n.type]?.Editor;return r?(0,X.jsx)(r,{test:n,label:l,set:u,datasets:t,profiles:s,labGrader:c,undoable:(t,n)=>h(No(e,i,t),n)}):null})(),(0,X.jsx)(k,{label:`${l} on failure`,rows:[{key:`continue`,label:`Continue on failure`,control:{type:`checkbox`,checked:n.continueOnFailure,onChange:e=>u({...n,continueOnFailure:e})}}]}),i===m&&o]},n.id)}}),l&&(0,X.jsx)(Ps,{pipeline:e,datasets:t,onClose:()=>u(!1),onAdd:t=>{r(ko(e,t)),u(!1)}})]})}function Ms(e,t,n,r=!1){let i=e&&!t.some(t=>t.id===e.id)?[...t,e]:t;return{key:`dataset`,label:`Dataset`,control:{type:`select`,value:e?.id??``,options:[...r?[{value:``,label:`—`}]:[],...i.map(e=>({value:e.id,label:e.name||e.id}))],onChange:e=>{let r=t.find(t=>t.id===e);n(r?{id:r.id,name:r.name}:null)}}}}function Ns(e,t){let n=K().outOf(e.jobs.at(-1)).kind;return Object.entries(K().TEST_TYPES).flatMap(([e,t])=>{let r=typeof t.accepts==`function`?t.accepts({type:e}):t.accepts,i=t.fields.includes(`dataset`);return r&&!r.includes(n)?[]:[{id:e,label:t.label,dataset:i}]})}function Ps({pipeline:e,datasets:t,onAdd:n,onClose:r}){let i=Ns(e,t),[a,o]=(0,q.useState)(i[0]?.id??``),[s,c]=(0,q.useState)(``),l=K().testsDataset(e),[u,d]=(0,q.useState)(l??null),f=i.find(e=>e.id===a),p=[{key:`type`,label:`Type`,hint:K().TEST_TYPES[a]?.description,control:{type:`select`,value:a,options:i.map(e=>({value:e.id,label:e.label})),onChange:o}},{key:`name`,label:`Name`,control:{type:`text`,value:s,placeholder:`Test ${e.tests.length+1}`,onChange:c}},...f?.dataset&&t.length?[Ms(u,t,d,!0)]:[]];return(0,X.jsx)(O,{title:`Add test`,...i.length?{}:{status:`No test type reads what the last job answers with.`,statusBad:!0},sections:[{key:`test`,rows:p}],focusRow:`type`,closeLabel:`Cancel`,actions:[{label:`Add`,icon:U.add,disabled:!f,onSelect:()=>f&&n(K().newTest(f.id,s.trim(),f.dataset&&u?{dataset:{id:u.id,name:u.name},metrics:[{type:`case`}]}:{}))}],onClose:r})}function Fs({test:e,label:t,set:n,undoable:r,profiles:i,datasets:a,labGrader:o}){let s=K(),c=e.metrics.some(e=>s.METRICS[e.type]?.graded),l=i.filter(e=>(s.CONNECTION_TYPES[e.type??``]?.answers??[`prompt`]).includes(`prompt`)),u=[{key:`mode`,label:`Scored`,control:{type:`select`,value:e.mode,options:[{value:`all`,label:`All must pass`},{value:`weighted`,label:`Weighted points`}],onChange:t=>n({...e,mode:t,threshold:t===`weighted`?e.threshold??1:e.threshold})}},...e.mode===`weighted`?[{key:`threshold`,label:`Pass at`,control:{type:`text`,size:`num`,value:e.threshold==null?``:String(e.threshold),onChange:t=>n({...e,threshold:t.trim()?/^-?\d+(\.\d+)?$/.test(t.trim())?Number(t):t:null})}}]:[],{key:`over`,label:`Reads`,control:{type:`select`,value:e.over??`item`,options:[{value:`item`,label:`Each item`},{value:`run`,label:`Whole run`}],onChange:t=>n({...e,over:t===`run`?`run`:`item`})}},{key:`dataset`,label:`Dataset`,control:{type:`select`,value:e.dataset?.id??``,options:[{value:``,label:`—`},...(e.dataset&&!a.some(t=>t.id===e.dataset.id)?[e.dataset]:a).map(e=>({value:e.id,label:e.name||e.id}))],onChange:t=>{let r=a.find(e=>e.id===t);n({...e,dataset:r?{id:r.id,name:r.name}:null})}}},...c||e.grader?[{key:`grader`,label:`Grader`,control:{type:`select`,value:e.grader?.id??``,options:[{value:``,label:o?`Lab (${o.name})`:`—`},...l.map(e=>({value:e.id,label:e.name}))],onChange:t=>{let r=i.find(e=>e.id===t);n({...e,grader:r?{id:r.id,name:r.name}:null})}}}]:[]];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(k,{label:t,rows:u}),(0,X.jsx)(Tr,{label:t,metrics:e.metrics,over:e.over??`item`,set:t=>n({...e,metrics:t}),undoable:(t,n)=>r({...e,metrics:t},n)})]})}function Is({pipeline:e,sourceFiles:t,graded:n,sources:r,openCaseEditor:i}){let a=J(),o=ge(),[s]=_e(`promptlab.mappings`),[c,l]=(0,q.useState)({graded:!1,todo:!0,missing:!0}),[u,d]=(0,q.useState)(!1),[f,p]=(0,q.useState)(null),[m,h]=(0,q.useState)(null),g=K().testsDataset(e)?.id??null,_=(0,q.useMemo)(()=>g?yr(o,g):null,[o,g,s]);if(g===null)return null;let v=t??[],y=new Set(n.map(e=>e.filename)),b=new Set(v),x=[{key:`graded`,label:`Graded`,tone:`ok`,files:v.filter(e=>y.has(e))},{key:`todo`,label:`Todo`,tone:`todo`,files:v.filter(e=>!y.has(e))},{key:`missing`,label:`Missing`,tone:`missing`,files:n.filter(e=>!b.has(e.filename)).map(e=>e.filename)}],S=x[0].files.length,C=x[1].files.length+x[2].files.length,w=x.filter(e=>c[e.key]).flatMap(e=>e.files.map(t=>({file:t,tone:e.tone}))),T=async e=>{if(g){d(!1),h(null),p({done:0,total:n.length,source:e.name});try{await vr(a,o,g,e,n.map(e=>e.filename),(t,n)=>p({done:t,total:n,source:e.name}))}catch(e){h(e instanceof Error?e.message:String(e))}finally{p(null)}}},E=_?.recents[0]??null,D=_?n.map(e=>br(_,e.filename)).filter(e=>e!==null):[],O=D.filter(e=>e.file!==null).length,k=[{label:`Map against Source…`,icon:Jn,disabled:!!f||!r.length||!n.length,onSelect:()=>d(!0)}];return(0,X.jsxs)(A,{id:`mapping`,title:`Mapping`,level:3,note:j(),actions:k,about:`Which of the content's files the dataset has a case for, and so which are graded.`,children:[f&&(0,X.jsxs)(`p`,{className:`note`,role:`status`,children:[`Mapping against `,f.source,`… `,f.done,` of `,f.total]}),m&&(0,X.jsx)(`p`,{className:`note fault`,role:`alert`,children:m}),E&&!f&&(0,X.jsxs)(`p`,{className:`note mapped-line`,children:[`Mapped against `,E.name,`, `,Cr(E.at),`: `,O,` matched, `,D.length-O,` with no match.`]}),v.length?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`p`,{className:`note`,children:[n.length,` expectations · `,S,` of `,v.length,` content files matched.`]}),(0,X.jsx)(`div`,{className:`mkey`,children:x.filter(e=>e.files.length).map(e=>(0,X.jsxs)(`button`,{type:`button`,className:`ghost chip-key${c[e.key]?` on`:``}`,"aria-pressed":c[e.key],onClick:()=>l({...c,[e.key]:!c[e.key]}),children:[e.label,` `,e.files.length]},e.key))}),w.length?(0,X.jsx)(`div`,{className:`mchips`,children:w.map(({file:e,tone:t})=>{let n=_?br(_,e):null,r=!!n?.file;return(0,X.jsxs)(`button`,{type:`button`,className:`mchip ${t}${r?` linked`:``}`,...r?{title:`Mapped to ${n.file} in ${n.source.name}`}:{},onClick:()=>i(e),children:[r&&(0,X.jsx)(In,{size:12,"aria-label":`Mapped`}),e]},`${t}-${e}`)})}):(0,X.jsx)(`p`,{className:`note`,children:C?`Nothing shown.`:`Every content file is graded.`})]}):(0,X.jsx)(`p`,{className:`note`,children:`No files in the content to map against.`}),u&&g&&(0,X.jsx)(Hr,{sources:r,recents:_?.recents??[],onPick:e=>void T(e),onClose:()=>d(!1)})]});function j(){let r=K().contentOf(e),i=r?K().CONTENT_TYPES[r.type]:void 0;if(i?.inline)return i.label;let a=t??[],o=new Set(n.map(e=>e.filename)),s=a.filter(e=>o.has(e)).length;return`${n.length} expectations · ${s} of ${a.length} matched`}}function Ls({comment:e,setComment:t,onClear:n,onCopyFailures:r}){return(0,X.jsx)(A,{id:`control`,title:`Next run`,level:2,actions:[{label:`Clear comment`,icon:P,destructive:!0,onSelect:n},{label:`Copy last run's failures`,icon:N,onSelect:r}],children:(0,X.jsx)(k,{label:`Next run`,rows:[{key:`comment`,label:`Comment`,control:{type:`text`,value:e,placeholder:`A note to find this run by in History`,onChange:e=>t(e)}}]})})}function Rs(){let e=ge(),t=J(),n=te(),{openRun:r}=ct(),{openCaseEditor:i}=Vr(),[a,o]=_e(`promptlab.workflows`),[s]=_e(`promptlab.profiles`),[c,l]=_e(`promptlab.comment`),[u]=_e(`promptlab.versions`),[d,f]=(0,q.useState)([]),{list:p,error:m}=Fe(),{list:h,error:g}=Ge(),_=h?.find(e=>e.default)??null,v=Pe(),y=(0,q.useMemo)(()=>(p??[]).map(e=>R(e.id,e.name)),[p]),[b,x]=(0,q.useState)(4),[S,C]=(0,q.useState)(void 0),[w,E]=(0,q.useState)(null),[D,O]=(0,q.useState)(!1),[k,A]=(0,q.useState)(!1),[j,M]=(0,q.useState)(null),N=(0,q.useRef)(null),[P,F]=(0,q.useState)(null),ee=(0,q.useRef)(null);(0,q.useEffect)(()=>{let e=!0;return t.sources().then(t=>{e&&f(t.sources)}).catch(()=>{}),t.config().then(t=>{e&&x(t.scenarioCap)}).catch(()=>{}),()=>{e=!1}},[t]),(0,q.useEffect)(()=>{let e=!0,n,r=async()=>{let i=5e3;try{let n=(await t.queue({limit:1})).runs[0]??null;if(!e)return;!N.current&&n&&!Bt(n.status)&&(N.current=n.id),n&&n.id===N.current&&(M(n),Bt(n.status)||(i=1e3))}catch{}e&&(n=setTimeout(()=>void r(),i))};return r(),()=>{e=!1,n&&clearTimeout(n)}},[t]);let I=(0,q.useMemo)(()=>a.list.filter(e=>e.work?.version===9),[a.list]),z=I.find(e=>e.id===a.at)??I[0],B=z?.work,V=z?.id??``,H=B?K().testsDataset(B)?.id??null:null,U=Ie(H),W=U?.doc?.body.cases,ne=(0,q.useMemo)(()=>(W??[]).map(e=>({id:e.id??``,filename:K().caseFile(e)})),[W]),G=U?.doc?.body.cases,re=(0,q.useMemo)(()=>[...new Set((G??[]).flatMap(e=>[...e.expect??[],...(e.anyOf??[]).flat()]))],[G]),ie=_?.text||B?.scenarios.at(-1)?.stages[0]?.prompt||``,ae=(0,q.useRef)(s.list);ae.current=s.list;let oe=I.length?null:p?.[0]??null,se=p!==null||m!==null,ce=h!==null||g!==null,le=_?.text??``;(0,q.useEffect)(()=>{if(I.length||!se||!ce)return;let e=Bs(ae.current,oe?{id:oe.id,name:oe.name}:void 0,le);o({list:[e],at:e.id})},[I.length,o,se,ce,oe,le]);let ue=()=>{let e=v.list().list?.[0];return e?{id:e.id,name:e.name}:void 0},Y=(0,q.useRef)(a);Y.current=a;let de=(0,q.useRef)(z);de.current=z;let fe=(0,q.useRef)(B);fe.current=B;let pe=(0,q.useRef)(null),me=(0,q.useRef)(null),he=(0,q.useCallback)(()=>{me.current&&clearTimeout(me.current);let t=de.current?.id,n=fe.current;t&&n&&(pe.current={id:t,doc:n},me.current=setTimeout(()=>{let t=pe.current;t&&ke(e,`pipeline`,t.id,t.doc,`idle`)},Te))},[e]);(0,q.useEffect)(()=>()=>{me.current&&clearTimeout(me.current)},[]);let ve=(0,q.useCallback)(e=>{let t=Y.current,n=de.current.id,r={...t,at:n,list:t.list.filter(e=>e.work?.version===9).map(t=>t.id===n?{...t,work:e}:t)};Y.current=r,o(r),he(),E(null)},[o,he]),ye=s.list[0]?.id??``;(0,q.useEffect)(()=>{let e=fe.current,t=de.current?.id;if(!e||!t||!ye)return;let n=zo(e,Po(ae.current));if(n===e)return;let r=Y.current,i={...r,list:r.list.map(e=>e.id===t?{...e,work:n}:e)};Y.current=i,o(i)},[ye,V,o]),(0,q.useEffect)(()=>{let t=pe.current;t&&t.id!==V&&(ke(e,`pipeline`,t.id,t.doc,`idle`),pe.current=null,me.current&&=(clearTimeout(me.current),null))},[V,e]);let be=B?K().contentOf(B):null,xe=be?.type===`source`?be.ref.id:null;(0,q.useEffect)(()=>{if(xe===null){C(void 0);return}let e=!0;return t.source(xe).then(t=>{e&&C(t.files.map(e=>e.name))}).catch(()=>{}),()=>{e=!1}},[xe,t]);let Se=(0,q.useCallback)(e=>{let t=d.find(t=>t.id===e);return t?{name:t.name,type:t.type,files:e===xe&&S?S:[]}:null},[d,xe,S]),Ce=(0,q.useMemo)(()=>{let e=s.list.find(e=>e.id===s.grader);return e?{id:e.id,name:e.name}:null},[s]),we=(0,q.useMemo)(()=>{if(!B)return[];if(!s.list.length&&B.scenarios.length)return[`add a Setup profile first`];let e={profiles:e=>s.list.find(t=>t.id===e)??null,sources:Se,grader:Ce,...p?{datasets:p}:{}};return K().validatePipeline(B,e)},[B,s.list,Se,p,Ce]),Ee=V?u.pipeline?.[V]??[]:[],De=(0,q.useCallback)(async()=>{let n=fe.current,i=de.current.id;ke(e,`pipeline`,i,n,`run`);let a=K().resolvePipeline(n,{profiles:e=>s.list.find(t=>t.id===e)??null,grader:Ce,...xe!==null&&S!==void 0?{files:S}:{},comment:c?.text??``});O(!0),E(null);try{let e=await t.submit(a);N.current=e.run.id,M(e.run),r(e.run.id,{at:e.run.submittedAt,from:`runs`})}catch(e){E(e instanceof Error?e.message:String(e)),N.current=null,M(null)}finally{O(!1)}},[t,c,xe,r,s.list,S,e,Ce]),Oe=(0,q.useCallback)(async()=>{let e=N.current;if(e)try{M((await t.cancel(e)).run)}catch{}},[t]),Ae=(0,q.useCallback)(async()=>{try{let e=(await t.queue({limit:1})).runs[0];if(!e)return;let n=(e.results??[]).filter(e=>(e.scenarios??[]).some(e=>Object.values(e?.scores??{}).some(K().failedScore))).map(e=>e.name??`an item`);n.length&&await navigator.clipboard?.writeText(n.join(`
10
- `))}catch{}},[t]),je=(0,q.useCallback)(async n=>{let r=fe.current,i=de.current.id;ke(e,`pipeline`,i,r,`run`);let a=K().resolvePipeline(r,{profiles:e=>s.list.find(t=>t.id===e)??null,grader:Ce,files:[n],comment:c?.text??``}),o=await t.submit(a),l=o.run;for(;l.status===`queued`||l.status===`running`;)await new Promise(e=>setTimeout(e,500)),l=await t.run(o.run.id);return((l.results??[]).find(e=>e.name===n)?.scenarios??[]).map(e=>e.res??null)},[t,c,s.list,e]),Me=(0,q.useCallback)(e=>{H&&i(e,{dataset:H,files:S??[],run:je})},[i,S,je,H]),Ne=(0,q.useCallback)(()=>{let e=c?.text??``;l({text:``}),n.offer({label:`Cleared the comment`,restore:()=>l({text:e})})},[c,l,n]),Le=(0,q.useCallback)(()=>{let e=K().pipelineToYaml(fe.current);$n(new Blob([e],{type:`text/yaml`}),Qn(`pipeline`,fe.current.name||`pipeline`,9,`yml`))},[]),Re=(0,q.useCallback)(async e=>{let n=await t.archivedRules().then(e=>e.rules,()=>({})),r=K().yamlToPipeline(e,{profiles:ae.current,sources:d,datasets:y,rulesFor:e=>n[e]??null});if(`error`in r){F(r);return}let{doc:i,missing:a}=r,s={id:Vs(),name:i.name||`Imported`,work:i},c={...Y.current,at:s.id,list:[...I,s]};Y.current=c,o(c),F({doc:i,missing:a})},[t,I,o,d,y]);if(!z||!B)return null;let ze=t=>{let n=de.current.id;ke(e,`pipeline`,n,fe.current,`restore`),ve(t.doc),A(!1)};return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(_o,{problems:we,error:w,run:j,submitting:D,onRun:()=>void De(),onStop:()=>void Oe(),onOpen:()=>{j&&r(j.id,{at:j.submittedAt,from:`runs`})}}),(0,X.jsxs)(`div`,{className:`runs`,children:[(0,X.jsx)(go,{list:I,at:V,canRestore:Ee.length>0,onSelect:e=>o({...Y.current,at:e}),onNew:()=>{let e=zs(I.map(e=>e.name));if(o({...Y.current,list:[...I,e],at:e.id}),c?.text){let e=c.text;l({text:``}),n.offer({label:`Cleared the comment`,restore:()=>l({text:e})})}},onClone:()=>{let e={id:Vs(),name:`${z.name} copy`,work:structuredClone(B)};o({...Y.current,list:[...I,e],at:e.id})},onRename:e=>{let t=e.trim(),n=Y.current,r=de.current.id,i={...n,at:r,list:n.list.filter(e=>e.work?.version===9).map(e=>e.id===r?{...e,name:t,work:{...e.work,name:t}}:e)};Y.current=i,o(i),he()},onDelete:()=>{let e=Y.current,t=I.filter(e=>e.id!==V),r=t.length?t:[Bs(s.list,ue(),le)],i=t.length?t[0].id:r[0].id;o({...Y.current,list:r,at:i}),n.offer({label:`Deleted ${z.name||`the pipeline`}`,restore:()=>{Y.current=e,o(e)}})},onRestore:()=>A(!0),onExport:Le,onImport:()=>ee.current?.click()}),(0,X.jsx)(`input`,{ref:ee,type:`file`,accept:`.yml,.yaml`,hidden:!0,"aria-hidden":`true`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&t.text().then(Re).catch(()=>F({error:`the file could not be read`}))}}),(0,X.jsx)(Ls,{comment:c?.text??``,setComment:e=>l({text:e}),onClear:Ne,onCopyFailures:()=>void Ae()}),(0,X.jsx)(Es,{pipeline:B,profiles:s.list,sources:d,scenarioCap:b,prompt:ie,..._?{defaultPrompt:_}:{},protectedTerms:re,edit:ve,offer:n.offer}),(0,X.jsx)(js,{profiles:s.list,labGrader:Ce,pipeline:B,datasets:y,graded:ne,edit:ve,offer:n.offer,openCaseEditor:Me,children:(0,X.jsx)(Is,{pipeline:B,sourceFiles:S,graded:ne,sources:d,openCaseEditor:Me})}),(0,X.jsx)(T,{undo:n.undo,onUndo:n.undoNow,onDismiss:n.dismiss}),k&&(0,X.jsx)(L,{title:`Restore pipeline`,onClose:()=>A(!1),children:(0,X.jsxs)(`div`,{className:`version-list`,children:[Ee.length===0&&(0,X.jsx)(`p`,{className:`note`,children:`No versions of this pipeline yet.`}),Ee.map((e,t)=>(0,X.jsxs)(`div`,{className:`version-row`,children:[(0,X.jsxs)(`span`,{className:`version-when`,children:[Us(e.at),` · `,Hs(e.reason)]}),(0,X.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>ze(e),children:`Restore`})]},`${e.at}-${t}`))]})}),P&&(`doc`in P?(0,X.jsx)(L,{title:`Imported ${P.doc.name||`Untitled`}`,onClose:()=>F(null),children:P.missing.length>0?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`p`,{className:`note`,children:`A run is blocked until each of these exists here — create it, or pick a replacement in the Content and Setup profile rows:`}),(0,X.jsx)(`ul`,{className:`import-missing`,children:P.missing.map(e=>(0,X.jsx)(`li`,{children:e},e))})]}):(0,X.jsx)(`p`,{className:`note`,children:`Ready to run.`})}):(0,X.jsx)(L,{title:`Nothing imported`,onClose:()=>F(null),children:(0,X.jsx)(`p`,{className:`note`,children:P.error})}))]})]})}var zs=e=>{let t=Io(e);return{id:Vs(),name:t,work:K().blankPipeline({name:t})}},Bs=(e,t,n)=>({id:Vs(),name:`Evals`,work:Ro(Po(e),t,n)}),Vs=()=>`w${Date.now().toString(36)}${Math.random().toString(36).slice(2,8)}`,Hs=e=>e===`run`?`before a run`:e===`restore`?`before a restore`:e===`pack`?`before a pack update`:`after editing`,Us=e=>{let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()},Ws=25,Gs=[``,`queued`,`running`,`done`,`cancelled`,`failed`,`incomplete`,`interrupted`],Ks=e=>e.numeric?`hnum`:void 0,qs=e=>[...new Map(e.map(e=>[e.submittedAt,e])).values()].sort((e,t)=>String(t.submittedAt).localeCompare(String(e.submittedAt)));function Js(){let t=J(),n=te(),{openRun:r}=ct(),[i,a]=_e(`promptlab.history.columns`),[o,s]=(0,q.useState)([]),[c,l]=(0,q.useState)(!1),[u,d]=(0,q.useState)(``),[p,m]=(0,q.useState)(new Set),[h,g]=(0,q.useState)(!1),[_,v]=(0,q.useState)(null),[y,b]=(0,q.useState)(null),[x,S]=(0,q.useState)(null),[C,w]=(0,q.useState)(null),[E,O]=(0,q.useState)(!1),k=(0,q.useRef)(o);k.current=o;let j=(0,q.useMemo)(()=>o.map(e=>Et($t(e),e)),[o]),M=(0,q.useMemo)(()=>Zs(i),[i]),N=(0,q.useCallback)(async e=>{try{return await t.queue(e?{limit:Ws,before:e}:{limit:Ws})}catch{return null}},[t]),F=(0,q.useCallback)(e=>{let t=new Set(e.runs.map(e=>e.submittedAt));s(n=>qs([...n.filter(e=>!t.has(e.submittedAt)),...e.runs])),l(e.more)},[]);(0,q.useEffect)(()=>{let e=!0,t,n=async()=>{let r=await N();e&&(r&&F(r),k.current.some(e=>[`queued`,`running`].includes(e.status))&&(t=setTimeout(()=>void n(),3e3)))};return n(),()=>{e=!1,t&&clearTimeout(t)}},[N,F]);let I=(0,q.useMemo)(()=>j.filter(e=>!u||(e.status||`done`)===u),[j,u]),R=(e=>({Runs:Lt.filter(t=>e.Runs.has(t.key)),"Run Scenarios":Rt.filter(t=>e[`Run Scenarios`].has(t.key))}))(M),z=(0,q.useCallback)(e=>{m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),B=(0,q.useCallback)((e,t)=>{r(e,{at:t,from:`history`})},[r]),V=(0,q.useCallback)(async e=>{try{let n=await t.resume(e),r={runs:[n.run],more:k.current.length>Ws};F(r),B(e,n.run.submittedAt)}catch{}},[t,F,B]),H=(0,q.useCallback)(async()=>{let e=k.current;try{await t.clear()}catch{w(`Not cleared: server unreachable.`);return}s([]),l(!1),n.offer({label:`Cleared ${wt(e.length,`run`)}`,restore:()=>{for(let n of e)t.submit(K().upgradePipeline(n.snapshot)).catch(()=>{})}})},[t,n]),U=(0,q.useCallback)(async()=>{O(!0);let e=[...k.current],t=!1,n;for(let r=0;;r++){let i=await N(n);if(!i){t=!0;break}if(e=qs([...e,...i.runs]),n=i.runs.at(-1)?.submittedAt,!i.more||!n||r>100)break}if(O(!1),!e.length){w(`Nothing to export yet.`);return}$n(new Blob([JSON.stringify({exported:new Date().toISOString(),runs:e},null,2)],{type:`application/json`}),Qn(`runs`,`all`,9,`json`)),w(t?`Exported ${wt(e.length,`run`)}. Server unreachable, so only those this browser had.`:`Exported ${wt(e.length,`run`)}.`)},[t,N]),W=[{label:`Select Columns`,icon:wn,onSelect:()=>g(!0)},{label:`Export JSON`,icon:e,onSelect:()=>void U()},{label:`Clear`,icon:P,destructive:!0,onSelect:()=>void H()}],ne=(0,q.useCallback)(e=>{let t=e.target.closest(`[data-resume]`);if(t){e.stopPropagation(),V(t.getAttribute(`data-resume`));return}let n=e.target.closest(`[data-openrun]`);if(n){e.stopPropagation();let t=n.closest(`tr[data-run]`),r=t?I[Number(t.getAttribute(`data-run`))]:null;r?.run&&B(r.run,r.at);return}let r=e.target.closest(`[data-editcomment]`);if(r){e.stopPropagation();let t=r.closest(`tr[data-run]`),n=t?I[Number(t.getAttribute(`data-run`))]:null;n?.run&&b({id:n.run,comment:n.comment});return}let i=e.target.closest(`[data-scenario]`);if(i){e.stopPropagation();let t=i.closest(`tr[data-scen]`)?.previousElementSibling,n=t?I[Number(t.getAttribute(`data-run`))]:null,r=n?.run?k.current.find(e=>e.id===n.run):null;r?.snapshot&&S({run:r.snapshot,i:Number(i.getAttribute(`data-scenario`))});return}let a=e.target.closest(`[data-prof]`);if(a){e.stopPropagation();let t=a.closest(`tr[data-scen]`)?.previousElementSibling,n=t?I[Number(t.getAttribute(`data-run`))]:null,r=a.getAttribute(`data-prof`);if(n&&r!=null){let e=n.scenarios[Number(r)];v({name:e?.setupProfile?.name??``,settings:vt(n,e??{})})}}},[I,B,V]),G=(0,q.useCallback)((e,t)=>{s(n=>n.map(n=>n.id===e?{...n,snapshot:{...n.snapshot,comment:t}}:n)),b(null)},[]),re=(e,t)=>e.image&&St(t)!==!0?(0,X.jsx)(`span`,{className:`note`,children:`—`}):e.get(t),ie=(e,t,n,r)=>n?e.image&&St(t)!==!0?(0,X.jsx)(`span`,{className:`note`,children:`—`}):e.get(t,n,r):`—`;return(0,X.jsxs)(`div`,{className:`history`,children:[(0,X.jsxs)(A,{id:`history`,title:`History`,actions:W,children:[(j.length>0||u)&&(0,X.jsx)(ee,{noun:`runs`,lead:I.length>0&&(0,X.jsx)(`p`,{className:`note hstatus`,role:`status`,children:wt(I.length,`run`)}),filters:[{key:`show`,label:`Show`,value:u,onChange:d,options:Gs.map(e=>({value:e,label:e?kt(e):`All`}))}]}),C&&(0,X.jsx)(`p`,{className:`note hstatus`,role:`status`,children:C}),I.length?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`scrollx`,onClick:ne,children:(0,X.jsx)(D,{className:`htable`,label:`Runs`,rows:I,rowKey:e=>e.at,rowProps:(e,t)=>({className:`runrow${p.has(e.at)?` open`:``}`,"data-run":t}),columns:[{key:`expand`,header:(0,X.jsx)(`span`,{className:`hvh`,children:`Scenarios`}),label:``,className:`hexpand`,sort:null,cell:(e,t)=>{let n=p.has(e.at);return(0,X.jsx)(`button`,{type:`button`,className:`icon-btn`,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,"aria-controls":n?`hscen-${t}`:void 0,onClick:()=>z(e.at),children:(0,X.jsx)(f,{size:16,"aria-hidden":`true`})})}},...R.Runs.map(e=>({key:e.key,header:e.label,className:Ks(e),sort:e.sort??(t=>{let n=e.get(t);return typeof n==`string`?n:null}),cell:t=>(0,X.jsx)(`span`,{className:`hval`,children:re(e,t)})}))],after:(e,t)=>p.has(e.at)&&(0,X.jsx)(`tr`,{className:`scenrows`,id:`hscen-${t}`,"data-run":t,"data-scen":e.at,children:(0,X.jsx)(`td`,{colSpan:R.Runs.length+1,children:(0,X.jsx)(D,{className:`scen-table`,label:`Scenarios`,rows:((e.scenarios||[]).length?e.scenarios:[null]).map((e,t)=>({sc:e,n:t})),rowKey:({sc:e,n:t})=>e?.id??String(t),columns:R[`Run Scenarios`].map(t=>({key:t.key,header:t.label,className:Ks(t),sort:({sc:n,n:r})=>{if(!n)return null;if(t.sort)return t.sort(n,r);let i=t.get(e,n,r);return typeof i==`string`?i:null},cell:({sc:n,n:r})=>(0,X.jsx)(`span`,{className:`hval`,children:ie(t,e,n,r)})}))})})})})}),c&&(0,X.jsx)(`button`,{type:`button`,className:`ghost older-btn`,disabled:E,onClick:async()=>{O(!0);let e=await N(k.current.at(-1)?.submittedAt);if(O(!1),!e){w(`Server unreachable.`);return}F(e)},children:`Older`})]}):(0,X.jsx)(`p`,{className:`note`,children:C??(j.length?`No runs match this filter.`:(0,X.jsxs)(X.Fragment,{children:[`No runs yet. `,(0,X.jsx)(`a`,{href:`#/runs`,children:`Start one in Runs`})]}))})]}),(0,X.jsx)(T,{undo:n.undo,onUndo:n.undoNow,onDismiss:n.dismiss}),h&&(0,X.jsx)($s,{cols:M,onSave:e=>{a(Qs(e)),g(!1)},onClose:()=>g(!1)}),x&&(0,X.jsx)(bs,{run:x.run,i:x.i,onClose:()=>S(null)}),_&&(0,X.jsx)(L,{title:_.name||`Settings`,onClose:()=>v(null),children:(0,X.jsx)(Ys,{settings:_.settings})}),y&&(0,X.jsx)(Xs,{runId:y.id,comment:y.comment,onSaved:e=>G(y.id,e),onClose:()=>b(null)})]})}function Ys({settings:e}){let t=gt.filter(t=>String(e[t]??``)!==``).map(t=>({key:t,label:yt(t),control:{type:`static`,text:bt(t,e[t])}}));return t.length?(0,X.jsx)(k,{label:`Setup profile`,rows:t}):(0,X.jsx)(`p`,{className:`note`,children:`No settings recorded.`})}function Xs({runId:e,comment:t,onSaved:n,onClose:r}){let i=J(),[a,o]=(0,q.useState)(t),[s,c]=(0,q.useState)(null),[l,u]=(0,q.useState)(!1);return(0,X.jsx)(O,{title:`Run comment`,...s?{status:s,statusBad:!0}:{},sections:[{key:`comment`,rows:[{key:`comment`,label:`Comment`,control:{type:`text`,value:a,onChange:o,placeholder:`optional`}}]}],actions:[{label:`Save`,icon:h,disabled:l,onSelect:async()=>{u(!0),c(null);try{await i.setComment(e,a),n(a)}catch{c(`Not saved: the server is unreachable.`),u(!1)}}}],closeLabel:`Close`,focusRow:`comment`,onClose:r})}function Zs(e){let t=()=>({Runs:new Set(Lt.filter(e=>e.on).map(e=>e.key)),"Run Scenarios":new Set(Rt.filter(e=>e.on).map(e=>e.key))});if(!e)return t();let n=t();for(let t of zt){let r=t[0],i=e[r],a=new Set(t[1].map(e=>e.key)),o=new Set(i?.seen??[...a]),s=[...(i?.on??[]).filter(e=>a.has(e)),...t[1].filter(e=>e.on&&!o.has(e.key)).map(e=>e.key)];s.length&&(n[r]=new Set(s))}return n}function Qs(e){return{Runs:{on:[...e.Runs],seen:Lt.map(e=>e.key)},"Run Scenarios":{on:[...e[`Run Scenarios`]],seen:Rt.map(e=>e.key)}}}function $s({cols:e,onSave:t,onClose:n}){let[r,i]=(0,q.useState)(()=>({Runs:new Set(e.Runs),"Run Scenarios":new Set(e[`Run Scenarios`])})),[a,o]=(0,q.useState)(null);return(0,X.jsx)(L,{title:`Select Columns`,onClose:n,children:(0,X.jsxs)(`div`,{className:`hcols`,children:[zt.map(([e,t])=>(0,X.jsxs)(`div`,{className:`groups`,children:[(0,X.jsx)(`h3`,{children:e}),t.map(t=>(0,X.jsxs)(`label`,{children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:r[e].has(t.key),onChange:n=>{let a=new Set(r[e]);n.target.checked?a.add(t.key):a.delete(t.key),i({...r,[e]:a}),o(null)}}),` `,t.label]},t.key))]},e)),a&&(0,X.jsx)(`p`,{className:`note bad`,children:a}),(0,X.jsxs)(`div`,{className:`hcols-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`run`,onClick:()=>{if(!r.Runs.size){o(`the Runs group needs at least one column`);return}t(r)},children:`Save`}),(0,X.jsx)(`button`,{type:`button`,className:`ghost`,onClick:n,children:`Close`})]})]})})}var ec=[`px`,`format`,`quality`],tc=[{value:`200704`,label:`448 square`},{value:`edge448`,label:`448 edge`},{value:`409920`,label:`480p`},{value:`518400`,label:`540p`},{value:`921600`,label:`720p`},{value:`1440000`,label:`900p`},{value:`2073600`,label:`1080p`},{value:`3686400`,label:`1440p`}],nc={"image/jpeg":`JPEG`,"image/webp":`WebP`,"image/png":`PNG`},rc=e=>nc[e]??e.replace(`image/`,``).toUpperCase(),ic={px:`921600`,quality:`0.92`};function ac(e,t){let n=K().connectionImage({}).format,r=String(e.px??``),i=String(e.format??``),a=String(e.quality??``),o=(tc.some(e=>e.value===r)||!r?tc:[...tc,{value:r,label:K().budgetLabel(r)}]).map(e=>e.value===ic.px?{value:``,label:`${e.label} (default)`}:e),s=K().IMAGE_FORMATS.map(e=>e===n?{value:``,label:`${rc(e)} (default)`}:{value:e,label:rc(e)}),c=(i||n)===`image/png`,l={type:`text`,value:a,onChange:t(`quality`),size:`num`,...c?{marker:`unused`}:a?{}:{placeholder:ic.quality,marker:`default`}};return[{key:`px`,label:`Resolution`,control:{type:`select`,value:r===ic.px?``:r,options:o,onChange:t(`px`)}},{key:`format`,label:`Format`,control:{type:`select`,value:i===n?``:i,options:s,onChange:t(`format`)}},{key:`quality`,label:`Quality`,control:l}]}function oc(e){let{px:t,format:n,quality:r}=K().connectionImage(e),i=n===`image/png`?``:` q${r??ic.quality}`;return`${K().budgetLabel(t??Number(ic.px))} · ${rc(n)}${i}`}function sc({offer:e}){let t=J(),n=ge(),r=Pe(),i=We(),[a,o]=(0,q.useState)(null),[s,c]=(0,q.useState)(null),l=(0,q.useRef)(null),u=e=>c({text:e instanceof Error?e.message:String(e),bad:!0}),d=(0,q.useCallback)(()=>{t.packs().then(e=>o(e.packs),u)},[t]);(0,q.useEffect)(d,[d]);let f=async()=>{await Promise.all([n.refresh(),r.refresh(),i.refresh()]),d()},p=async e=>{c({text:`Installing ${e.name}…`,bad:!1});try{let n=await t.installPack(e);await f();let r=(await t.packs()).packs.find(e=>e.id===n.pack),i=r?`${r.name} ${r.version}`:n.pack;c({text:n.installed?`Installed ${i}.`:`${i} is up to date.`,bad:!1})}catch(e){u(e)}},m=async n=>{try{let{trash:r}=await t.removePack(n.id);await f(),e({label:`Removed ${n.name}`,restore:()=>{t.restorePack(r).then(f)}})}catch(e){u(e)}};return a===null&&!s?null:(0,X.jsxs)(A,{id:`setup-packs`,title:`Packs`,note:a?cc(a.length,`pack`):``,actions:[{label:`Install pack…`,icon:G,onSelect:()=>l.current?.click()}],children:[a&&!a.length&&(0,X.jsx)(`p`,{className:`note`,children:`No packs installed.`}),a&&a.length>0&&(0,X.jsx)(D,{className:`setup-table`,cards:!0,label:`Packs`,rows:a,rowKey:e=>e.id,columns:[{key:`name`,header:`Pack`,role:`title`,cell:e=>e.name},{key:`version`,header:`Version`,cell:e=>e.version},{key:`made`,header:`Made`,sort:null,cell:e=>lc(e)},{key:`menu`,header:``,className:`ds-menu`,role:`menu`,sort:null,cell:e=>(0,X.jsx)(w,{label:`${e.name} actions`,actions:[{label:`Remove`,icon:U.remove,destructive:!0,onSelect:()=>void m(e)}]})}]}),s&&(0,X.jsx)(`p`,{className:`note${s.bad?` bad`:``}`,role:s.bad?`alert`:`status`,children:s.text}),(0,X.jsx)(`input`,{ref:l,type:`file`,accept:`.labpack,.zip,application/zip`,hidden:!0,"aria-label":`Install pack file`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&p(t)}})]})}var cc=(e,t)=>`${e} ${t}${e===1?``:`s`}`,lc=e=>[cc(e.datasets.length,`dataset`),cc(e.pipelines.length,`pipeline`),cc(e.sources.length,`Source`),cc(e.presets,`preset`)].join(` · `);function uc({offer:e}){let t=J(),[n,r]=(0,q.useState)(null),[i,a]=(0,q.useState)(null),o=(0,q.useRef)(null),s=(0,q.useCallback)(()=>{t.plugins().then(e=>r(e.plugins),e=>a({text:e instanceof Error?e.message:String(e),bad:!0}))},[t]);(0,q.useEffect)(s,[s]);let c=async e=>{a(null);try{let n=await t.installPlugin(e),i=(await t.plugins()).plugins;r(i);let o=i.find(e=>e.id===n.plugin);o&&n.installed&&await de(o),a({text:n.installed?le[n.plugin]?`Installed ${n.plugin}, and it did not load: ${le[n.plugin]}`:`Installed ${n.plugin}.`:`${n.plugin} is up to date.`,bad:!!le[n.plugin]})}catch(e){a({text:e instanceof Error?e.message:String(e),bad:!0})}},l=async n=>{try{let{trash:r}=await t.removePlugin(n.id);s(),e({label:`Removed ${n.id}`,restore:()=>{t.restorePlugin(r).then(s)}})}catch(e){a({text:e instanceof Error?e.message:String(e),bad:!0})}};return n===null&&!i?null:(0,X.jsxs)(A,{id:`setup-plugins`,title:`Plugins`,note:n?`${n.length} ${n.length===1?`plugin`:`plugins`}`:``,actions:[{label:`Install plugin…`,icon:G,onSelect:()=>o.current?.click()}],children:[n&&!n.length&&(0,X.jsx)(`p`,{className:`note`,children:`No plugins installed.`}),n&&n.length>0&&(0,X.jsx)(D,{className:`setup-table`,cards:!0,label:`Plugins`,rows:n,rowKey:e=>e.id,columns:[{key:`id`,header:`Plugin`,role:`title`,cell:e=>e.id},{key:`version`,header:`Version`,cell:e=>e.version},{key:`sha`,header:`SHA-256`,sort:null,cell:e=>(0,X.jsx)(`code`,{title:e.sha256,children:e.sha256.slice(0,12)})},{key:`registers`,header:`Registers`,sort:null,cell:e=>dc(e)||`—`},{key:`state`,header:`State`,cell:e=>fc(e)},{key:`menu`,header:``,className:`ds-menu`,role:`menu`,sort:null,cell:e=>(0,X.jsx)(w,{label:`${e.id} actions`,actions:[{label:`Remove`,icon:U.remove,destructive:!0,onSelect:()=>void l(e)}]})}]}),i&&(0,X.jsx)(`p`,{className:`note${i.bad?` bad`:``}`,role:i.bad?`alert`:`status`,children:i.text}),(0,X.jsx)(`input`,{ref:o,type:`file`,accept:`.labplugin,.zip,application/zip`,hidden:!0,"aria-label":`Install plugin file`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&c(t)}})]})}var dc=e=>[...e.registers.outputKinds??[],...e.registers.modifiers??[],...e.registers.testTypes??[],...(e.registers.connectionTypes??[]).map(e=>e.id)].join(`, `),fc=e=>le[e.id]?`Failed: ${le[e.id]}`:ue.has(e.id)?`Loaded`:`Not Loaded`,pc=`microsoft`;function mc(){let e=J(),t=Ui(),[n,r]=(0,q.useState)(null),[i,a]=(0,q.useState)(void 0),[o,s]=(0,q.useState)(null),c=(0,q.useCallback)(()=>{e.connections().then(e=>r(e.connections),()=>r([]))},[e]);(0,q.useEffect)(c,[c]),(0,q.useEffect)(()=>{t&&zi(t).then(a,()=>a(null))},[t]);let l=[...n??[],...t?[{id:pc,label:`Microsoft 365`,configured:!0,signedIn:!!i,account:i??null,problem:null}]:[]],u=async n=>{s(null);try{n.id===pc&&t?await Bi(t):window.location.assign((await e.signIn(n.id)).url)}catch(e){s(e instanceof Error?e.message:String(e))}},d=async n=>{s(null);try{n.id===pc&&t?(await Vi(t),a(null)):r((await e.signOut(n.id)).connections)}catch(e){s(e instanceof Error?e.message:String(e))}};if(!l.length)return null;let f=l.filter(e=>e.problem);return(0,X.jsxs)(A,{id:`setup-connections`,title:`Connections`,note:`${l.filter(e=>e.signedIn).length} of ${l.length}`,children:[(0,X.jsx)(D,{className:`setup-table`,cards:!0,label:`Connections`,rows:l,rowKey:e=>e.id,columns:[{key:`label`,header:`Connection`,role:`title`,cell:e=>e.label},{key:`status`,header:`Status`,cell:e=>hc(e)},{key:`account`,header:`Account`,cell:e=>e.account||`—`},{key:`menu`,header:``,className:`ds-menu`,role:`menu`,sort:null,cell:e=>(0,X.jsx)(w,{label:`${e.label} actions`,actions:e.signedIn?[{label:`Sign out`,icon:Rn,onSelect:()=>void d(e)}]:[{label:`Sign in`,icon:Ln,disabled:!e.configured,onSelect:()=>void u(e)}]})}]}),f.map(e=>(0,X.jsxs)(`p`,{className:`note bad`,role:`alert`,children:[e.label,`: `,e.problem]},e.id)),o&&(0,X.jsx)(`p`,{className:`note bad`,role:`alert`,children:o})]})}var hc=e=>e.configured?e.signedIn?`Signed In`:`Signed Out`:`Not Configured`;function gc(){let e=ge(),t=J(),n=te(),[r,i]=_e(`promptlab.profiles`),[a]=_e(`promptlab.versions`),[o,s]=(0,q.useState)(null),[c,l]=(0,q.useState)(null),[u,d]=(0,q.useState)(null),[f,p]=(0,q.useState)({}),[m,h]=(0,q.useState)(``),[g,_]=(0,q.useState)(``),[v,y]=(0,q.useState)(``),[b,x]=(0,q.useState)(null),[S,C]=(0,q.useState)([]),[w,E]=(0,q.useState)({});(0,q.useEffect)(()=>{let e=!0;return t.presets().then(t=>{e&&C(t)}).catch(()=>{}),()=>{e=!1}},[t]);let O=(0,q.useRef)(r);O.current=r;let k=(0,q.useCallback)(e=>{let t=O.current,n={...t,list:t.list.map(t=>t.id===e.id?e:t)};O.current=n,i(n),N(e)},[i]),j=(0,q.useRef)(null),M=(0,q.useRef)(null),N=(0,q.useCallback)(t=>{M.current&&clearTimeout(M.current),j.current={p:t},M.current=setTimeout(()=>{let t=j.current;t&&ke(e,`profile`,t.p.id,t.p,`idle`)},Te)},[e]);(0,q.useEffect)(()=>()=>{M.current&&clearTimeout(M.current)},[]);let P=(0,q.useCallback)(()=>{let e=Pc(),t=O.current,n={...t,list:[...t.list,e],at:e.id};O.current=n,i(n),s({id:e.id,focus:`name`})},[i]),F=(0,q.useCallback)(e=>{let t=O.current.list.find(t=>t.id===e);if(!t)return;let n={...structuredClone(t),id:Nc(),name:`${t.name||`Profile`} copy`,key:t.key},r={...O.current,list:[...O.current.list,n]};O.current=r,i(r)},[i]),I=(0,q.useCallback)(e=>{let t=O.current,r=t.list.filter(t=>t.id!==e);if(!r.length)return;let a={list:r,at:r[0].id};O.current=a,i(a),s(null);let o=t.list.find(t=>t.id===e);n.offer({label:`Deleted ${o?.name||`the profile`}`,restore:()=>{O.current=t,i(t)}})},[i,n]),L=(0,q.useCallback)(t=>{let n=t.doc.id,r=O.current.list.find(e=>e.id===n);r&&ke(e,`profile`,n,r,`restore`);let a=O.current,o={...a,list:a.list.map(e=>e.id===n?t.doc:e)};O.current=o,i(o),R()},[e,i]),R=(0,q.useCallback)(()=>{l(e=>(e?.back&&s({id:e.id}),null))},[]),z=(0,q.useCallback)(async e=>{let n=O.current.list.find(t=>t.id===e);if(!n)return;let r=K().CONNECTION_TYPES[n.type];if(r?.local){p(t=>({...t,[e]:{phase:`connected`,ms:0,lines:[`${r.label} answers each text item with its own text, and sends nothing anywhere.`]}}));return}let i=r?.keyless?``:n.key,a=n.url.trim()||r?.url||`the lab's Ollama`,o=performance.now(),s=()=>Math.round(performance.now()-o),c=[];p(t=>({...t,[e]:{phase:`checking`,lines:[`Checking…`]}}));try{let o=Object.fromEntries((r?.settings??[]).map(e=>[e.key,String(n[e.key]??``)]));if(`testPath`in o&&!o.testPath.trim()){let e=r?.templates?.find(e=>Dc(e.settings.url,n.url));e?.settings.testPath&&(o.testPath=e.settings.testPath)}let l=((await t.models({url:n.url,key:i,type:n.type,settings:o})).data||[]).map(e=>e.id).sort();if(E(t=>({...t,[e]:l})),c.push(`Reached ${a}.`,`${l.length} ${l.length===1?`model`:`models`}: ${l.join(`, `)||`none`}.`),(r?.answers??[`prompt`]).includes(`prompt`)){if(n.model.trim()){let e=K().apiBase(n.url||r?.url||``),a=K().connectionRequest(n,`hi`,null,e,i),o=await t.modelsAsk({url:n.url,key:i,type:n.type,body:a.body}),{raw:s}=K().connectionReply(n,o);c.push(``,`Asked ${n.model} “hi”; it replied:`,s||`(an empty reply)`)}else c.push(``,`No model is picked, so nothing was asked.`)}p(t=>({...t,[e]:{phase:`connected`,lines:c,ms:s()}}))}catch(t){c.push(...c.length?[``]:[],t instanceof Error?t.message:String(t)),p(t=>({...t,[e]:{phase:`error`,lines:c,ms:s()}}))}},[t]),B=o?r.list.find(e=>e.id===o.id):void 0,V=B?JSON.stringify([B.id,B.url,B.type,B.key]):``;(0,q.useEffect)(()=>{if(!B)return;let e=B;if(K().CONNECTION_TYPES[e.type]?.local||K().CONNECTION_TYPES[e.type]?.lists===!1)return;let n=K().CONNECTION_TYPES[e.type]?.keyless,r=!0,i=setTimeout(()=>{t.models({url:e.url,key:n?``:e.key,type:e.type,quiet:!0}).then(t=>{r&&E(n=>({...n,[e.id]:(t.data||[]).map(e=>e.id).sort()}))}).catch(()=>{r&&E(t=>({...t,[e.id]:[]}))})},400);return()=>{r=!1,clearTimeout(i)}},[t,V]);let H=(0,q.useCallback)((e,t)=>{let n=O.current.list.find(t=>t.id===e);if(!n)return;let r={...n};for(let e of Ac(n.type))r[e]=``;for(let[e,n]of Object.entries(t.opts))r[e]=n;O.current={...O.current,list:O.current.list.map(t=>t.id===e?r:t)},i(O.current),N(r)},[i,N]),U=(0,q.useCallback)(e=>{p(t=>{if(!(e in t))return t;let{[e]:n,...r}=t;return r})},[]),ne=(0,q.useCallback)((e,t,n)=>{let r=O.current.list.find(t=>t.id===e);r&&([`url`,`key`,`model`].includes(t)&&U(e),k({...r,[t]:n}))},[k,U]),G=(0,q.useCallback)((e,t)=>{let n=O.current.list.find(t=>t.id===e);if(!n)return;let r={...n,type:t};U(e),E(t=>({...t,[e]:[]}));let i=K().CONNECTION_TYPES[t];i?.keyless&&(r.key=``),i?.url&&!r.url.trim()&&(r.url=i.url);for(let e of Object.keys(r))[`id`,`name`,`url`,`model`,`key`,`temperature`,`type`,...ec].includes(e)||jc(t).includes(e)||delete r[e];k(r)},[k,U]),re=(0,q.useCallback)((e,t)=>{s(t?{id:e,focus:t}:{id:e})},[]),ie=(0,q.useCallback)(e=>a.profile?.[e]??[],[a]),ae=o?r.list.find(e=>e.id===o.id)??null:null,oe=[...new Set(r.list.map(e=>e.type))],se=m.trim().toLowerCase(),ce=r.list.filter(e=>(!g||e.type===g)&&(!v||v===`set`==!!e.key)&&(!se||[e.name,e.url,e.model].some(e=>String(e??``).toLowerCase().includes(se))));return(0,X.jsxs)(`div`,{className:`setup`,children:[(0,X.jsxs)(A,{id:`setup-profiles`,title:`Setup profiles`,note:Mc(r.list.length),children:[(0,X.jsx)(`p`,{className:`note`,children:`A profile is how the lab reaches a model or an API: its type, address, key and settings. A scenario picks one.`}),r.list.length>0&&(0,X.jsx)(ee,{noun:`profiles`,search:{label:`Search profiles`,placeholder:`Name, address or model`,value:m,onChange:h},filters:[{key:`type`,label:`Type`,value:g,onChange:_,options:[{value:``,label:`All`},...oe.map(e=>({value:e,label:K().CONNECTION_TYPES[e]?.label??e}))]},{key:`key`,label:`Key`,value:v,onChange:y,options:[{value:``,label:`All`},{value:`set`,label:`Set`},{value:`unset`,label:`Not set`}]},{key:`sort`,label:`Sort`,value:b?.key??``,onChange:e=>x(e?{key:e,dir:`asc`}:null),options:[{value:``,label:`As added`},{value:`name`,label:`Name`},{value:`type`,label:`Type`},{value:`url`,label:`Address`},{value:`model`,label:`Model`}]}],count:{shown:ce.length,total:r.list.length}}),r.list.length===0?(0,X.jsx)(`p`,{className:`note`,children:`No profiles yet.`}):ce.length===0?(0,X.jsx)(`p`,{className:`note`,children:`No profiles match these filters.`}):(0,X.jsx)(D,{className:`setup-table`,cards:!0,label:`Setup profiles`,sort:b,onSort:x,rows:ce,rowKey:e=>e.id,rowProps:e=>({className:`setup-row`,onClick:t=>{t.target.closest(`button, a, .menu`)||re(e.id)}}),columns:_c({tests:f,only:r.list.length===1,grader:r.grader??null,onGrader:e=>{let t=O.current,n={...t,grader:t.grader===e?``:e};O.current=n,i(n)},onOpen:re,onClone:F,onRemove:I,onTest:z,onResult:e=>d({id:e,back:!1})})}),(0,X.jsxs)(`button`,{type:`button`,className:`ghost add-btn`,onClick:P,children:[(0,X.jsx)(W,{size:14,"aria-hidden":`true`}),`Add profile`]})]}),(0,X.jsx)(mc,{}),(0,X.jsx)(uc,{offer:n.offer}),(0,X.jsx)(sc,{offer:n.offer}),(0,X.jsx)(T,{undo:n.undo,onUndo:n.undoNow,onDismiss:n.dismiss}),ae&&(0,X.jsx)(vc,{profile:ae,...o?.focus?{focus:o.focus}:{},test:f[ae.id],models:w[ae.id]??[],presets:S.filter(e=>(e.type??`llama.cpp`)===ae.type),canRestore:!!ie(ae.id).length,onClose:()=>s(null),onSetting:ne,onType:G,onTest:z,onResult:()=>{s(null),d({id:ae.id,back:!0})},onRestore:()=>{s(null),l({id:ae.id,back:!0})},onApplyPreset:e=>H(ae.id,e)}),u&&f[u.id]&&(0,X.jsx)(Ec,{test:f[u.id],onClose:()=>{u.back&&s({id:u.id}),d(null)}}),c&&(0,X.jsx)(wc,{versions:ie(c.id),onClose:R,onRestore:L})]})}function _c({tests:e,only:t,grader:n,onGrader:r,onOpen:i,onClone:a,onRemove:o,onTest:s,onResult:c}){let l=e=>e.name||`Unnamed profile`,u=e=>[{label:`Edit…`,icon:U.edit,onSelect:()=>i(e.id)},{label:`Rename`,icon:U.rename,onSelect:()=>i(e.id,`name`)},{label:`Clone`,icon:U.clone,onSelect:()=>a(e.id)},{label:`Test connection`,icon:v,onSelect:()=>void s(e.id)},...(K().CONNECTION_TYPES[e.type]?.answers??[`prompt`]).includes(`prompt`)&&!K().CONNECTION_TYPES[e.type]?.local?[{label:n===e.id?`Stop grading`:`Make grader`,icon:Nn,onSelect:()=>r(e.id)}]:[],...t?[]:[{label:`Remove`,icon:U.remove,destructive:!0,onSelect:()=>o(e.id)}]];return[{key:`name`,header:`Profile`,role:`title`,sort:l,cell:t=>{let r=e[t.id];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{type:`button`,className:`setup-open`,onClick:()=>i(t.id),children:l(t)}),n===t.id&&(0,X.jsx)(`span`,{className:`setup-note`,children:`Grader`}),r&&(0,X.jsx)(`button`,{type:`button`,className:`edit-outcome setup-note${r.phase===`error`?` bad`:``}`,"aria-label":`Test connection: ${Tc[r.phase]}`,onClick:()=>c(t.id),children:Tc[r.phase]})]})}},{key:`type`,header:`Type`,label:``,cell:e=>K().CONNECTION_TYPES[e.type]?.label??e.type},{key:`url`,header:`Address`,sort:e=>e.url.trim(),cell:e=>K().CONNECTION_TYPES[e.type]?.local?(0,X.jsx)(`span`,{className:`setup-unset`,children:`—`}):e.url.trim()||(0,X.jsx)(`span`,{className:`setup-unset`,children:`(server)`})},{key:`model`,header:`Model`,sort:e=>e.model.trim(),cell:e=>K().CONNECTION_TYPES[e.type]?.local?(0,X.jsx)(`span`,{className:`setup-unset`,children:`—`}):e.model.trim()||(0,X.jsx)(`span`,{className:`setup-unset`,children:`Not set`})},{key:`key`,header:`Key`,sort:e=>e.key?`Set`:``,cell:e=>K().CONNECTION_TYPES[e.type]?.keyless?(0,X.jsx)(`span`,{className:`setup-unset`,children:`—`}):e.key?`Set`:(0,X.jsx)(`span`,{className:`setup-unset`,children:`Not set`})},{key:`menu`,header:``,label:``,className:`setup-menu`,role:`menu`,sort:null,cell:e=>(0,X.jsx)(w,{actions:u(e),label:`${l(e)} actions`})}]}function vc({profile:e,focus:t,test:n,models:i,presets:a,canRestore:o,onClose:s,onSetting:c,onType:l,onTest:u,onResult:d,onRestore:f,onApplyPreset:p}){let m=K().CONNECTION_TYPES[e.type],h=(m?.answers??[`prompt`]).includes(`prompt`),g=(0,q.useMemo)(()=>Cc(e),[e]),_=t=>n=>c(e.id,t,n),y=[{key:`name`,label:`Name`,required:!0,control:{type:`text`,value:e.name,onChange:_(`name`)}},{key:`type`,label:`Type`,required:!0,hint:m?.description,control:{type:`select`,value:e.type,onChange:t=>l(e.id,t),options:Object.entries(K().CONNECTION_TYPES).map(([e,t])=>({value:e,label:t.label}))}},...m?.local?[]:[{key:`url`,label:`Address`,control:{type:`text`,value:e.url,placeholder:m?.url??`the lab's Ollama`,onChange:_(`url`)}},...m?.keyless?[]:[{key:`key`,label:`Key`,control:{type:`secret`,value:e.key,onChange:_(`key`)}}],...h?[{key:`model`,label:`Model`,control:kc(e.model,i,_(`model`))}]:[]]],b=(m?.settings??[]).map(t=>yc(e,t,_(t.key))),x=[{key:`identity`,rows:y},...b.length?[{key:`settings`,title:`Settings`,rows:b}]:[],...m?.local||!h?[]:[{key:`image`,title:`Image`,rows:ac(e,_)},{key:`debug`,title:`Debug`,rows:g,folded:!0}]],S=[{label:`Restore…`,icon:r,disabled:!o,onSelect:f},...a.map(e=>({label:`Apply preset: ${e.label}`,icon:U.preset,onSelect:()=>p(e)})),...(m?.templates??[]).map(t=>({label:`Apply template: ${t.label}`,icon:U.preset,onSelect:()=>p({id:t.id,label:t.label,type:e.type,opts:t.settings})}))];return(0,X.jsx)(O,{title:e.name||`Unnamed profile`,...t?{focusRow:t}:{},sections:x,menu:S,actions:m?.tests===!1?[]:[{label:`Test connection`,icon:v,onSelect:()=>u(e.id),outcome:n?{label:Tc[n.phase],bad:n.phase===`error`,onOpen:d}:void 0}],onClose:s})}function yc(e,t,n){let r=e[t.key]??t.default??``;if(t.control===`select`&&t.choices)return{key:t.key,label:t.label,control:{type:`select`,value:r,options:t.choices,onChange:n}};if(t.key===`grammar`)return{key:t.key,label:t.label,control:{type:`textarea`,value:r,onChange:n}};let i=r?null:xc(e,t.key),a={type:`text`,value:r,onChange:n,...i?.placeholder?{placeholder:i.placeholder}:{},...i?{marker:i.marker}:{},...i?.numeric?{size:`num`}:{}};return{key:t.key,label:t.label,control:a}}var bc=`424242`;function xc(e,t){let n=K().apiBase(e.url),r,i;try{r=Sc(K().connectionRequest({...e,[t]:``},`(prompt)`,null,n).body),i=Sc(K().connectionRequest({...e,[t]:bc},`(prompt)`,null,n).body)}catch{return null}let a=Object.keys(i).find(e=>i[e]===bc||i[e]===JSON.stringify(bc));if(a===void 0)return null;let o=i[a]===bc,s=a in r?JSON.parse(r[a]):null;return s===null?{marker:`server`,numeric:o}:{placeholder:String(s),marker:`default`,numeric:o}}function Sc(e,t=``,n={}){if(e&&typeof e==`object`&&!Array.isArray(e))for(let[r,i]of Object.entries(e))Sc(i,t?`${t}.${r}`:r,n);else n[t]=JSON.stringify(e)??`null`;return n}function Cc(e){let t=K().apiBase(e.url),n=[];try{let{url:r,body:i}=K().connectionRequest(e,`(prompt)`,null,t);n.push({key:`endpoint`,label:`Endpoint`,required:!0,control:{type:`code`,text:r}});let a=i,o=a.messages,s=Array.isArray(o?.[0]?.content)?o[0].content.find(e=>e.type===`text`)?.text??``:o?.[0]?.content??``;n.push({key:`prompt`,label:`Prompt`,required:!0,control:{type:`static`,text:String(s).slice(0,40)}}),n.push({key:`image`,label:`Image`,required:!0,control:{type:`code`,text:oc(e)}});for(let[e,t]of Object.entries(a))e!==`messages`&&n.push({key:e,label:e,control:{type:`code`,text:typeof t==`object`?JSON.stringify(t):String(t)}})}catch(e){n.push({key:`error`,label:`Error`,required:!0,control:{type:`static`,text:e instanceof Error?e.message:String(e)}})}return n}function wc({versions:e,onClose:t,onRestore:n}){return(0,X.jsx)(L,{title:`Restore profile`,onClose:t,children:(0,X.jsxs)(`div`,{className:`version-list`,children:[e.length===0&&(0,X.jsx)(`p`,{className:`note`,children:`No versions of this profile yet.`}),e.map((e,t)=>(0,X.jsxs)(`div`,{className:`version-row`,children:[(0,X.jsxs)(`span`,{className:`version-when`,children:[Ic(e.at),` · `,Fc(e.reason)]}),(0,X.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>n(e),children:`Restore`})]},`${e.at}-${t}`))]})})}var Tc={checking:`Checking…`,connected:`Connected`,error:`Error`};function Ec({test:e,onClose:t}){return(0,X.jsx)(O,{title:`Test connection`,sections:[{key:`result`,rows:[{key:`time`,label:`Time`,required:!0,control:{type:`static`,text:e.ms==null?`—`:Oc(e.ms)}},{key:`result`,label:`Result`,required:!0,control:{type:`textarea`,value:e.lines.join(`
11
- `)}}]}],closeLabel:`Close`,onClose:t})}function Dc(e,t){let n=e=>{let t=String(e??``).trim();if(!t)return``;try{return new URL(/^https?:\/\//.test(t)?t:`https://${t}`).origin}catch{return``}},r=n(e);return!!r&&r===n(t)}var Oc=e=>e<1e3?`${e} ms`:`${(e/1e3).toFixed(1)}s`;function kc(e,t,n){if(!t.length)return{type:`text`,value:e,placeholder:`model name`,onChange:n};let r=e&&!t.includes(e)?[e,...t]:[...t];return{type:`select`,value:e,onChange:n,options:[...e?[]:[{value:``,label:`Pick a model`}],...r.map(e=>({value:e,label:e}))]}}function Ac(e){return K().CONNECTION_TYPES[e]?.settings.map(e=>e.key).filter(e=>e!==`temperature`)??[]}function jc(e){return K().CONNECTION_TYPES[e]?.settings.map(e=>e.key)??[]}var Mc=e=>e===1?`1 profile`:`${e} profiles`,Nc=()=>`p${Date.now().toString(36)}${Math.random().toString(36).slice(2,6)}`,Pc=()=>({id:Nc(),name:`New profile`,url:``,model:``,key:``,temperature:``,nPredict:``,maxTokens:``,type:`ollama`}),Fc=e=>e===`run`?`before a run`:e===`restore`?`before a restore`:`after editing`,Ic=e=>{let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()},Lc=[];function Rc(e,t){let n=J(),[r,i]=(0,q.useState)(null);(0,q.useEffect)(()=>{if(t===null)return;let r=!0,a=ye(n);return a.runDataset(e).then(n=>{if(n){r&&i({run:e,cases:n.cases,current:!1});return}return a.dataset(t).then(t=>{r&&i({run:e,cases:t.body.cases,current:!0})}).catch(()=>{})}).catch(()=>{}),()=>{r=!1}},[n,e,t]);let a=t!==null&&r?.run===e?r:null;return{cases:a?a.cases:Lc,current:a?.current??!1}}var zc=e=>e==null?`—`:Mt(e);function Bc(e){return e?.transcript||[]}function Vc(e,t){return t.flatMap((n,r)=>{let i=Bc(e?.scenarios?.[r]?.res);return t.length>1?i.map(e=>({...e,scenario:n.name})):i})}function Hc({stages:e}){if(!e.length)return null;let t=!e.some(e=>e.scenario)&&e.length>1?` · ${e.map(e=>zc(e.ms)).join(` + `)}`:``;return(0,X.jsxs)(`div`,{className:`transcript`,children:[(0,X.jsxs)(`div`,{className:`meta`,children:[`Transcript`,t]}),e.map((e,t)=>(0,X.jsxs)(`pre`,{children:[(0,X.jsxs)(`b`,{children:[e.scenario?`${e.scenario} · `:``,`job `,e.n,` `,e.withImage?`(with image)`:`(text only)`,e.kind?` · ${e.kind}`:``,e.conn?` · ${e.conn}`:``,` · `,zc(e.ms),` — sent`]}),`
12
- `,e.sent,`
13
- `,(0,X.jsx)(`b`,{children:`— returned`}),`
14
- `,e.got||(e.error?`(nothing)`:``),e.error?`\n<b className="fault">Error - ${e.error}</b>`:``]},t))]})}function Uc({text:e,kind:t}){return(0,X.jsx)(`span`,{className:`term${t?` ${t}`:``}`,children:e})}function Wc({res:e,kase:t}){let n=e?.dropped||[];if(!n.length)return null;let r=e=>t?[...t.expect||[],...(t.anyOf||[]).flat()].some(t=>K().termIn([e],t)):!1;return(0,X.jsxs)(`details`,{className:`dropped`,children:[(0,X.jsxs)(`summary`,{children:[`Dropped `,n.length]}),n.map((e,t)=>(0,X.jsxs)(`div`,{className:`droppedrow`,children:[(0,X.jsx)(Uc,{text:e.item,kind:`no`}),(0,X.jsxs)(`span`,{className:`note`,children:[e.by,r(e.item)&&(0,X.jsx)(`b`,{className:`fault`,children:` · wanted`})]})]},t))]})}function Gc({kase:e}){let t=(e,t,n)=>t?.length?(0,X.jsxs)(`div`,{className:`wants`,children:[(0,X.jsx)(`b`,{children:e}),t.map((e,t)=>(0,X.jsx)(Uc,{text:e,kind:n},t))]}):null,n=e.minCount!=null||e.maxCount!=null?[e.minCount,e.maxCount].filter(e=>e!=null).map(String).join(`–`):``;return(0,X.jsxs)(X.Fragment,{children:[t(`All of`,e.expect),(e.anyOf||[]).map((e,n)=>t(`Any of`,e,`any`)),t(`None of`,e.forbid,`no`),t(`Except`,e.allow),n&&t(`Count`,[n]),e.discarded&&t(`Discarded`,[`expected`]),t(`Watch for`,e.watch||[],`txt`),(e.metrics??[]).map((e,t)=>(0,X.jsxs)(`div`,{className:`wants`,children:[(0,X.jsx)(`b`,{children:K().METRICS[e.type]?.label??e.type}),`${e.not?`not `:``}${K().metricSummary(e)}`]},`m${t}`))]})}function Kc({kase:e,res:t}){if(!e.watch?.length)return null;let n=K().scoreCase(e,t);if(!n.watchTotal)return null;let r=e=>n.discarded?`txt`:n.watchFound.includes(e)?`met`:`unmet`;return(0,X.jsxs)(`div`,{className:`wants`,children:[(0,X.jsxs)(`b`,{children:[`Watch for, `,n.watchFound.length,` of `,n.watchTotal,` found`]}),e.watch.map((e,t)=>(0,X.jsx)(Uc,{text:e,kind:r(e)},t)),(0,X.jsx)(`span`,{className:`note`,children:`Not scored`})]})}function qc({kase:e,res:t,scenarioIndex:n}){let r=K().scoreCase(e,t),i=t=>{if((e.expect||[]).some(e=>K().termIn([t],e))||(e.anyOf||[]).some(e=>e.some(e=>K().termIn([t],e))))return` met`;let n=n=>(e.allow||[]).some(e=>K().termIn([e],n)&&K().termIn([t],e));return(e.forbid||[]).some(e=>K().termIn([t],e)&&!n(e))?` unmet`:``},a=(t?.terms||[]).length,o=r.discarded?`${a} items, none kept`:`${a} items`;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`verdict ${r.pass?`pass`:`fail`}`,children:r.pass?`pass`:`fail`}),(0,X.jsx)(`span`,{className:`pct`,children:r.score==null?`—`:Math.round(r.score*100)+`%`}),r.reasons.length?(0,X.jsx)(`div`,{className:`reasons fault`,children:r.reasons.map((e,t)=>(0,X.jsx)(`div`,{children:e},t))}):(0,X.jsx)(`div`,{className:`reasons hit`,children:`All matched`}),(0,X.jsxs)(`div`,{className:`meta`,children:[o,` · `,zc(t?.ms)]}),(0,X.jsx)(`div`,{className:`chips`,children:(t?.terms||[]).map((e,t)=>(0,X.jsx)(Uc,{text:String(e),kind:r.discarded?`drop`:i(String(e))},t))}),(0,X.jsx)(Wc,{res:t,kase:e})]})}var Jc=e=>e?.transcript?.at(-1)?.kind===`text`;function Yc({res:e}){return e?.error?(0,X.jsx)(`span`,{className:`err`,children:e.error}):Jc(e)?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`pre`,{children:e?.transcript?.at(-1)?.got||`(empty)`}),(0,X.jsx)(`div`,{className:`meta`,children:zc(e?.ms)})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`chips`,children:(e?.terms||[]).map((e,t)=>(0,X.jsx)(Uc,{text:String(e)},t))}),(0,X.jsx)(Wc,{res:e,kase:null}),(0,X.jsxs)(`div`,{className:`meta`,children:[(e?.terms||[]).length,` items · `,zc(e?.ms)]})]})}function Xc({res:e}){if(e?.error)return(0,X.jsx)(`span`,{className:`err`,children:e.error});let t=e?.transcript?.at(-1)?.got??e?.raw??``;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`pre`,{children:t||`(empty)`}),(0,X.jsxs)(`div`,{className:`meta`,children:[zc(e?.ms),` · `,Jc(e)?`answered as text`:`read as ${(e?.terms||[]).length} items`]})]})}function Zc({tab:e}){let t=J(),{setShow:n}=ct(),{openCaseEditor:r}=Vr(),[i,a]=(0,q.useState)(null),[o,s]=(0,q.useState)(!1),[c,l]=(0,q.useState)(null),[u,d]=(0,q.useState)(new Set),[f,p]=(0,q.useState)(new Set),[h,g]=(0,q.useState)(!1),[_,v]=(0,q.useState)(null);(0,q.useEffect)(()=>{let n=!0,r,i=async()=>{try{let o=await t.run(e.id);if(!n)return;a(o),Bt(o.status)||(r=setTimeout(()=>void i(),1e3))}catch{n&&(r=setTimeout(()=>void i(),1e3))}};return i(),()=>{n=!1,r&&clearTimeout(r)}},[t,e.id]);let y=(0,q.useMemo)(()=>i?Qt(i):null,[i]),b=y?K().testsDataset(y.snapshot)?.id??null:null,x=Rc(e.id,b),S=(0,q.useMemo)(()=>new Map(x.cases.map(e=>[K().caseFile(e),e])),[x.cases]),C=(0,q.useCallback)(async()=>{s(!0);try{await t.cancel(e.id)}catch{}s(!1)},[t,e.id]);if(!y)return(0,X.jsx)(A,{id:`run-${e.id}`,title:Ct(e.at)||`Run`,children:(0,X.jsx)(`p`,{className:`note`,children:`Loading…`})});let T=y.progress,E=T.n??T.total??0,O=!Bt(y.status),k=T.total&&E!=null&&O?Math.round(E/T.total*100):null,j=vn(y,x.cases),M=y.scenarios.map((e,t)=>bn(y,x.cases,t)),P=ln(y),F=(e,t,n)=>{let r=new Set(e);r.has(t)?r.delete(t):r.add(t),n(r)},I=async(e,t,n)=>{let r=Math.max(0,y.scenarios.findIndex((t,n)=>Kt(y,e,n))),i=(t.scenarios??[])[r]?.res;i&&await ns(hn(y.snapshot,n,i,r))&&(g(!0),setTimeout(()=>g(!1),1600))},te=async()=>{await ns(j.map(e=>hn(y.snapshot,e.kase,e.res,e.scenarioIndex)).join(`
15
-
16
- `+`-`.repeat(60)+`
17
-
18
- `))&&(g(!0),setTimeout(()=>g(!1),1600))},L=j.length?[{label:`Copy all failures`,icon:N,onSelect:()=>void te()}]:[],R={key:`show`,label:`Show`,value:e.show,onChange:t=>n(e.id,t),options:[{value:`all`,label:`All`},{value:`failed`,label:`Failed`}]},z=!!b,B=y.tests.find(e=>`dataset`in e&&e.dataset)?.id??null,V=!!(y.content&&K().CONTENT_TYPES[y.content.type]?.inline),H=e=>{let t=y.results[e]?.name;return t?S.get(t):void 0},W=n=>{let i=y.results[n],o=H(n),s=!!i&&!i.unrun&&Bt(y.status),c=(i?.scenarios??[]).some(e=>e?.res?.transcript?.length),l=[];return c&&l.push({label:`Show details`,icon:m,onSelect:()=>F(u,n,d)}),o?.watch?.length&&l.push({label:`Watch for`,icon:m,onSelect:()=>F(f,n,p)}),s&&i?.name&&o&&l.push({label:`Edit case`,icon:U.edit,onSelect:()=>b&&r(i.name,{dataset:b,resultFor:e=>y.results[n]?.scenarios?.[e]?.res??null,scenarioCount:y.scenarios.length,files:y.results.filter(e=>e.kind!==`text`).map(e=>e.name??``)})}),s&&y.id&&l.push({label:`Re-run row`,icon:Hn,onSelect:()=>void t.rerun(e.id,n).then(e=>a(e.run)).catch(()=>{})}),s&&o&&Qc(y,n)&&l.push({label:`Copy as AI prompt`,icon:N,onSelect:()=>void I(n,i,o)}),l};return(0,X.jsxs)(`div`,{className:`runview`,children:[(0,X.jsxs)(A,{id:`run-${e.id}`,title:y.name||Ct(e.at),actions:L,children:[(0,X.jsxs)(`div`,{className:`runhead`,children:[P&&(0,X.jsxs)(`span`,{className:`note run-queue`,children:[(0,X.jsx)(`span`,{className:`run-state`,children:P.state}),P.detail&&(0,X.jsx)(`span`,{className:`run-item`,children:P.detail})]}),O&&(0,X.jsxs)(`button`,{type:`button`,className:`ghost stop-btn`,disabled:o,onClick:()=>void C(),children:[(0,X.jsx)(Cn,{size:14,"aria-hidden":`true`}),`Stop`]})]}),O&&(0,X.jsx)(`div`,{className:`rrbar`,children:k==null?(0,X.jsx)(`span`,{className:`rrprogress`,children:`Waiting`}):(0,X.jsxs)(`div`,{className:`rrmeter`,role:`progressbar`,"aria-valuenow":k,"aria-valuemin":0,"aria-valuemax":100,children:[(0,X.jsx)(`div`,{className:`rrbarfill`,style:{width:`${k}%`}}),(0,X.jsxs)(`span`,{className:`rrpct`,style:{"--pct":`${k}%`},children:[k,`%`]})]})}),y.error&&(0,X.jsx)(`p`,{className:`note bad rrstatus`,role:`status`,children:y.error}),(0,X.jsx)(`div`,{id:`run-${e.id}-stats`,className:`runstats`,children:(0,X.jsx)(pt,{label:`Run Statistics`,...rn(y)})}),y.tests.length>0&&(0,X.jsx)(el,{id:`run-${e.id}-tests`,rows:Zt(y),scenarios:y.scenarios,onScenario:v}),(0,X.jsxs)(A,{id:`run-${e.id}-results`,title:`Results`,level:3,children:[(0,X.jsx)(ee,{noun:`results`,filters:[R],lead:(0,X.jsx)(`p`,{className:`note`,children:wt(y.items.length,`item`)}),count:{total:y.items.length,shown:e.show===`failed`?y.items.filter((e,t)=>Qc(y,t)).length:y.items.length}}),x.current&&(0,X.jsx)(`p`,{className:`note`,children:`Graded before the lab kept a copy of its dataset: the expectations are the dataset as it is now.`}),(0,X.jsx)(`div`,{className:`scrollx`,style:{"--scenarios":y.scenarios.length},children:(0,X.jsx)(D,{className:z?`rrtable graded`:`rrtable`,label:`Results`,rows:y.items.map((e,t)=>t),rowKey:e=>`${y.items[e]}-${e}`,pinned:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`tr`,{className:`scenstats`,children:[(0,X.jsx)(`td`,{className:`scenstats-label`,children:`Statistics`}),z&&(0,X.jsx)(`td`,{className:`scenstats-blank`}),y.scenarios.map((e,t)=>(0,X.jsx)(`td`,{className:`scenstat`,"data-label":e.name,children:(0,X.jsx)(pt,{dense:!0,label:`${e.name} statistics`,...on(y,t)})},e.id))]}),M.some(e=>e.length>0)&&b&&(0,X.jsx)($c,{from:Ct(e.at)||y.name,datasetId:b,failing:M,scenarios:y.scenarios,items:y.items.length,graded:z})]}),rowProps:t=>({"data-item":t,className:u.has(t)?`hasdetail`:void 0,hidden:e.show===`failed`&&!Qc(y,t)}),after:t=>u.has(t)&&(0,X.jsx)(`tr`,{className:`rrdetail`,"data-detail":t,hidden:e.show===`failed`&&!Qc(y,t),children:(0,X.jsx)(`td`,{colSpan:1+ +!!z+y.scenarios.length,children:(0,X.jsx)(Hc,{stages:Vc(y.results[t],y.scenarios)})})}),columns:[{key:`item`,header:V?`Text`:`Item`,label:``,className:`col-item`,sort:e=>y.items[e]||``,cell:e=>{let t=y.results[e],n=y.items[e];return(0,X.jsxs)(X.Fragment,{children:[t?.name&&!V&&hr(t.name)?(0,X.jsx)(`button`,{type:`button`,className:`thumb`,"aria-label":`Open ${t.name}`,onClick:()=>l(t.name),children:(0,X.jsx)(`img`,{src:dn(y,t.name),alt:``,loading:`lazy`,"data-name":t.name})}):null,(0,X.jsxs)(`div`,{className:`rritem`,children:[(0,X.jsx)(`div`,{className:`meta`,children:n||``}),(0,X.jsx)(w,{actions:W(e),label:`${n||`row`} actions`})]})]})}},...z?[{key:`expected`,header:`Expected`,className:`col-expected`,sort:e=>{let t=H(e);return t&&!t.todo?(t.expect??[]).length+(t.anyOf??[]).length+(t.metrics?.length??0):null},cell:e=>{let t=H(e);return y.results[e]?t&&!t.todo?(0,X.jsx)(Gc,{kase:t}):(0,X.jsx)(`span`,{className:`note`,children:`n/a`}):``}}]:[],...y.scenarios.map((e,t)=>({key:`scenario-${t}`,header:e.name,label:e.name,onHeader:()=>v(t),cell:e=>(0,X.jsx)(tl,{item:y.results[e],i:t,graded:z,cases:S,watched:f.has(e),readings:(y.outcomes[t]??[]).filter(e=>!e.whole).map(t=>({label:t.label,dataset:t.id===B,score:t.items[e]??null}))})}))]})})]}),h&&(0,X.jsx)(`p`,{className:`note`,role:`status`,children:`Copied to clipboard.`})]}),_!=null&&(0,X.jsx)(bs,{run:y.snapshot,i:_,onClose:()=>v(null)}),c&&(0,X.jsx)(sl,{src:fn(y,c),name:c,onClose:()=>l(null)})]})}var Qc=(e,t)=>{let n=e.results[t];return!!n&&(!!n.unrun||(n.scenarios??[]).some((n,r)=>Kt(e,t,r)||!!n?.res?.error))};function $c({from:e,datasetId:t,failing:n,scenarios:r,items:i,graded:a}){let{showCases:o}=at(),{list:s}=Fe(),c=s!==null&&!s.some(e=>e.id===t),l=r.length>1;return(0,X.jsxs)(`tr`,{className:`reasons`,children:[(0,X.jsx)(`td`,{className:`scenstats-label`,children:`Reasons`}),a&&(0,X.jsx)(`td`,{className:`scenstats-blank`}),r.map((r,a)=>{let s=r.name,u=n[a]??[];return(0,X.jsx)(`td`,{className:`reasons-cell`,"data-label":s,children:u.length===0?(0,X.jsx)(`span`,{className:`reasons-none`,children:`No failures`}):(0,X.jsx)(`ul`,{className:`reasons-list`,"aria-label":`${s} reasons`,children:u.map(n=>{let r=n.files.length,a=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`reason-n`,children:r}),(0,X.jsxs)(`span`,{className:`reason-t`,children:[n.label,n.note&&(0,X.jsxs)(`span`,{className:`reason-note`,children:[` `,n.note]})]})]});return(0,X.jsx)(`li`,{"data-group":n.key,style:{"--share":`${Math.round(r/Math.max(i,1)*100)}%`},children:c?(0,X.jsx)(`span`,{className:`reason`,children:a}):(0,X.jsx)(`a`,{className:`reason`,href:`#/library/datasets`,title:`${n.label}${n.note?` (${n.note})`:``}: open ${wt(r,`case`)} in the Library`,"aria-label":`${n.label}: open ${wt(r,`case`)} in the Library`,onClick:r=>{r.preventDefault(),o(t,n.files,`${e}${l?` · ${s}`:``} · ${n.label}`)},children:a})},n.key)})})},r.id)})]})}function el({id:e,rows:t,scenarios:n,onScenario:r}){return(0,X.jsx)(A,{id:e,title:`Tests`,level:3,children:(0,X.jsx)(`div`,{className:`scrollx`,style:{"--scenarios":n.length},children:(0,X.jsx)(D,{className:`ruletable`,label:`Tests`,rows:t,rowKey:e=>e.key,rowProps:e=>({className:e.first?`rule-first`:void 0,"data-rule":e.key}),columns:[{key:`test`,header:`Test`,label:``,sort:null,className:`col-test rule-test`,cell:e=>e.first&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`rule-test-name`,children:e.test}),` `,(0,X.jsx)(`span`,{className:`rule-type`,children:e.type})]})},{key:`rule`,header:`Rule`,label:``,sort:null,className:`col-rule`,cell:e=>(0,X.jsxs)(X.Fragment,{children:[e.rule,e.want!=null&&(0,X.jsxs)(X.Fragment,{children:[` `,(0,X.jsx)(`code`,{className:`rule-want`,children:e.want})]})]})},...n.map((e,t)=>({key:`scenario-${t}`,header:e.name,label:e.name,sort:null,onHeader:()=>r(t),cell:e=>{let n=e.cells[t];if(!n)return null;let r=n.state===`met`?`✓ `:n.state===`not`?`✗ `:``;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`span`,{className:`rule-state ${n.state}`,children:[r,n.value]}),n.note&&(0,X.jsx)(`span`,{className:`rule-note`,children:n.note})]})}}))]})})})}function tl({item:e,i:t,graded:n,cases:r,watched:i,readings:a}){let o=e?.scenarios?.[t]?.res;if(e?.unrun)return(0,X.jsx)(`span`,{className:`err`,children:e.unrun});if(!o)return(0,X.jsx)(`span`,{className:`spin`,"aria-hidden":`true`});let s=e?.name?r.get(e.name):void 0,c=n&&!!s&&!s.todo&&e?.kind!==`text`&&nl(s),l=a.map(e=>!c||!e.score||K().isSkipped(e.score)||!e.score.metrics?e:{...e,score:{...e.score,metrics:e.score.metrics.filter(e=>!e.found&&!e.missed&&!e.invented)}}),u=l.some(e=>e.score&&!K().isSkipped(e.score)&&e.score.metrics?.length),d=a.length>1||u?(0,X.jsxs)(X.Fragment,{children:[a.length>1&&(0,X.jsx)(al,{readings:a}),(0,X.jsx)(rl,{readings:l})]}):null;if(e?.kind===`text`)return(0,X.jsxs)(X.Fragment,{children:[d,(0,X.jsx)(Xc,{res:o})]});let f=K().isSkipped(a.find(e=>e.dataset)?.score);return!c||f?(0,X.jsxs)(X.Fragment,{children:[f&&!d&&(0,X.jsx)(`span`,{className:`verdict skipped`,children:`Skipped`}),d,(0,X.jsx)(Yc,{res:o})]}):(0,X.jsxs)(X.Fragment,{children:[d,(0,X.jsx)(qc,{kase:s,res:o,scenarioIndex:t}),i&&(0,X.jsx)(ol,{kase:s,res:o})]})}var nl=e=>!!(e.expect?.length||e.anyOf?.length||e.forbid?.length||e.minCount!=null||e.maxCount!=null||e.discarded);function rl({readings:e}){let t=e.flatMap(e=>e.score&&!K().isSkipped(e.score)&&e.score.metrics?.length?[{...e,score:e.score}]:[]);return t.length?(0,X.jsx)(X.Fragment,{children:t.map((e,t)=>(0,X.jsxs)(`div`,{className:`metric-readings`,children:[(0,X.jsx)(`span`,{className:`verdict ${e.score.pass?`pass`:`fail`}`,children:e.score.pass?`Pass`:`Fail`}),e.score.score!=null&&(0,X.jsx)(`span`,{className:`metric-score`,children:il(e.score.score,!!e.score.points)}),(0,X.jsx)(`ul`,{children:e.score.metrics.map((e,t)=>(0,X.jsxs)(`li`,{className:e.pass?`pass`:`fail`,children:[(0,X.jsx)(`span`,{className:`test-name`,children:e.label}),` `,(0,X.jsx)(`span`,{className:`metric-reason`,children:e.reason})]},t))})]},t))}):null}var il=(e,t)=>t?`${Math.round(e*100)/100} points`:`${Math.round(e*100)}%`;function al({readings:e}){return(0,X.jsx)(`ul`,{className:`test-verdicts`,children:e.map((e,t)=>{let n=e.score?K().isSkipped(e.score)?`Skipped`:e.score.pass?`Pass`:`Fail`:null;return n&&(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`span`,{className:`test-name`,children:e.label}),(0,X.jsx)(`span`,{className:`verdict ${n.toLowerCase()}`,children:n})]},t)})})}function ol({kase:e,res:t}){return(0,X.jsx)(Kc,{kase:e,res:t})}function sl({src:e,name:t,onClose:n}){return(0,X.jsx)(L,{title:t||`Image`,onClose:n,children:(0,X.jsx)(`img`,{className:`lightbox-img`,src:e,alt:t})})}function cl(){let{tabs:e,focusedId:t,closeRun:n,focusRun:r,goBack:i}=ct(),a=e.find(e=>e.id===t);return a?(0,X.jsxs)(`div`,{className:`results`,role:`region`,"aria-label":`Open runs`,children:[(0,X.jsxs)(`div`,{className:`results-bar`,children:[(0,X.jsx)(`button`,{type:`button`,className:`ghost icon-btn rrback`,onClick:i,"aria-label":`Back`,children:(0,X.jsx)(p,{size:18,"aria-hidden":`true`})}),(0,X.jsx)(`code`,{className:`rrcode`,children:Ct(a.at)||`…`}),(0,X.jsx)(`div`,{className:`rtabs`,role:`tablist`,"aria-label":`Open runs`,children:e.map(e=>(0,X.jsxs)(`div`,{className:`rtab${e.id===t?` on`:``}`,children:[(0,X.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":e.id===t,className:`rname`,title:Ct(e.at)||`run`,onClick:()=>r(e.id),children:Ct(e.at)||`…`}),(0,X.jsx)(`button`,{type:`button`,className:`rx`,"aria-label":`Close`,onClick:()=>n(e.id),children:`×`})]},e.id))})]}),(0,X.jsx)(Zc,{tab:a})]}):null}function ll(){let e=Pe(),t=(0,q.useSyncExternalStore)(e.subscribe,e.held),n=t.filter(e=>e.sync.state===`conflict`),r=t.filter(e=>e.sync.state===`offline`);return!n.length&&!r.length?null:(0,X.jsxs)(X.Fragment,{children:[n.map(t=>(0,X.jsxs)(`div`,{className:`sync bad`,role:`alert`,children:[(0,X.jsxs)(`span`,{children:[t.doc?.name??t.id,` changed in another browser.`]}),(0,X.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>void e.resolve(t.id,`theirs`),children:`Use theirs`}),(0,X.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>void e.resolve(t.id,`mine`),children:`Keep mine`})]},t.id)),r.map(t=>(0,X.jsxs)(`div`,{className:`sync bad`,role:`status`,children:[(0,X.jsxs)(`span`,{children:[t.doc?.name??t.id,` not saved: `,t.sync.state===`offline`?t.sync.message.replace(/\.$/,``):``,`.`]}),(0,X.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>void e.flush(t.id),children:`Retry`})]},t.id))]})}var ul=`promptlab.theme`,dl=typeof matchMedia==`function`?matchMedia(`(prefers-color-scheme: light)`):null;function fl(){try{let e=JSON.parse(localStorage.getItem(ul)||`null`)?.choice;return e===`light`||e===`dark`?e:null}catch{return null}}var pl=()=>fl()??(dl?.matches?`light`:`dark`),ml=()=>{let e=pl();return document.documentElement.setAttribute(`data-theme`,e),e};ml();function hl(){let[e,t]=(0,q.useState)(pl);(0,q.useEffect)(()=>{let e=()=>t(ml());return dl?.addEventListener?.(`change`,e),()=>dl?.removeEventListener?.(`change`,e)},[]);let n=e===`light`?`dark`:`light`,r=n===`light`?`Light mode`:`Dark mode`;return(0,X.jsx)(`button`,{type:`button`,className:`icon-btn`,title:r,"aria-label":r,onClick:()=>{try{localStorage.setItem(ul,JSON.stringify({choice:n}))}catch{}document.documentElement.setAttribute(`data-theme`,n),t(n)},children:(0,X.jsx)(n===`light`?qn:Vn,{size:16,"aria-hidden":`true`})})}var gl=()=>{let e=decodeURIComponent(location.hash.replace(/^#\/?/,``)),t=e.match(/^(evals|datasets|sources)(\/.*)?$/);t&&(e=`library/${t[1]===`sources`?`sources`:`datasets`}${t[1]===`sources`?t[2]??``:``}`,history.replaceState(null,``,`#/${e.split(`/`).map(encodeURIComponent).join(`/`)}`));let n=e.match(/^library(?:\/(datasets|prompts|sources))?(?:\/(.+))?$/);if(n){let e=n[1]??`datasets`;return{tab:`library`,section:e,src:e===`sources`?n[2]??null:null}}return{tab:Yn.find(t=>t.id===e)?.id??`home`,section:`datasets`,src:null}};function _l(){return(0,X.jsx)(Ne,{children:(0,X.jsx)(Ue,{children:(0,X.jsx)(st,{children:(0,X.jsx)(it,{children:(0,X.jsx)(Br,{children:(0,X.jsx)(vl,{})})})})})})}function vl(){let[e,t]=(0,q.useState)(gl),{hide:n}=ct();(0,q.useEffect)(()=>{let e=()=>{t(gl()),n()};return window.addEventListener(`hashchange`,e),()=>window.removeEventListener(`hashchange`,e)},[n]);let r=Yn.find(t=>t.id===e.tab);return(0,X.jsxs)(`div`,{className:`app`,children:[(0,X.jsxs)(`header`,{className:`app-head`,children:[(0,X.jsx)(`h1`,{children:`Evals Lab`}),(0,X.jsx)(bl,{}),(0,X.jsx)(ll,{}),(0,X.jsx)(hl,{})]}),(0,X.jsx)(`nav`,{className:`app-tabs`,role:`tablist`,"aria-label":`Lab`,children:Yn.map(t=>(0,X.jsxs)(`a`,{role:`tab`,id:`tab-${t.id}`,href:`#/${t.id}`,"aria-selected":t.id===e.tab,"aria-controls":`panel-${t.id}`,className:t.id===e.tab?`on`:void 0,children:[(0,X.jsx)(t.icon,{size:18,"aria-hidden":`true`,className:`tab-icon`}),(0,X.jsx)(`span`,{className:`tab-word`,children:t.label})]},t.id))}),(0,X.jsx)(yl,{tab:r,section:e.section,src:e.src})]})}function yl({tab:e,section:t,src:n}){let{focusedId:r}=ct(),i=r?(0,X.jsx)(cl,{}):e.id===`home`?(0,X.jsx)(mo,{}):e.id===`runs`?(0,X.jsx)(Rs,{}):e.id===`history`?(0,X.jsx)(Js,{}):e.id===`library`?(0,X.jsx)(oo,{section:t,sourceId:n}):(0,X.jsx)(gc,{});return(0,X.jsx)(`main`,{role:`tabpanel`,id:`panel-${e.id}`,"aria-labelledby":`tab-${e.id}`,"data-tab":e.id,children:i})}function bl(){let{sync:e,resolve:t}=ve();return e.state===`offline`?(0,X.jsxs)(`p`,{className:`sync bad`,role:`status`,children:[`Not saved to the server: `,e.message,`. Kept in this browser.`]}):e.state===`conflict`?(0,X.jsxs)(`div`,{className:`sync bad`,role:`alert`,children:[(0,X.jsx)(`span`,{children:`Changed on another device.`}),(0,X.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>void t(`theirs`),children:`Use theirs`}),(0,X.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>void t(`mine`),children:`Keep mine`})]}):null}var xl=`promptlab.sync`,Sl=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Cl=(e,t)=>{let n=cr[e];return Sl(n)&&Sl(t)?{...n,...t}:t};function wl({api:e,storage:t,server:n,pause:r=800}){let i=e=>{try{return t.getItem(e)}catch{return null}},a=new Map,o=(e,n)=>{a.delete(e);try{n==null?t.removeItem(e):t.setItem(e,JSON.stringify(n))}catch{}a.set(e,n??null)},s=e=>{try{return JSON.parse(i(e)??`null`)}catch{return null}},c=(e,t)=>i(e)===(t==null?null:JSON.stringify(t)),l=n!==null,u=s(xl)??{},d={},f=new Set,p=()=>o(xl,{versions:d,dirty:[...f]}),m=new Set,h=()=>m.forEach(e=>e()),g=l?{state:`saved`}:{state:`local`},_=null,v=null,y=e=>{g=e,h()};if(n){for(let e of dr){let t=n[e];t&&c(e,t.body)?d[e]=t.version:u.dirty?.includes(e)?(d[e]=u.versions?.[e]??0,f.add(e)):t?(d[e]=t.version,o(e,t.body)):(d[e]=0,i(e)!=null&&f.add(e))}p()}async function b(t=!1){if(!l||g.state===`conflict`)return;if(!f.size){g.state===`saving`&&y({state:`saved`});return}let n=[...f],r=Object.fromEntries(n.map(e=>[e,{version:d[e]??0,body:s(e)}]));y({state:`saving`});try{let{versions:i}=await e.writeState(r,t);Object.assign(d,i);for(let e of n)c(e,r[e].body)&&f.delete(e);if(p(),y({state:`saved`}),f.size)return b(t)}catch(e){if(e instanceof pe&&e.status===409){let t=e.body?.stale??{};for(let[e,n]of Object.entries(t))d[e]=n.version;let n=Object.keys(t).filter(e=>!c(e,t[e].body));for(let e of Object.keys(t))n.includes(e)||f.delete(e);return p(),n.length?(x=t,y({state:`conflict`,keys:n})):b()}y({state:`offline`,message:e instanceof Error?e.message:String(e)})}}let x={};function S(e=!1){return _&&=(clearTimeout(_),null),v??=b(e).finally(()=>{v=null}),v}return f.size&&(_=setTimeout(()=>{S()},0)),{get(e){return a.has(e)||a.set(e,Cl(e,s(e))),a.get(e)??cr[e]},set(e,t){o(e,t),l&&dr.includes(e)&&(f.add(e),p(),_&&clearTimeout(_),_=setTimeout(()=>{S()},r)),h()},subscribe(e){return m.add(e),()=>{m.delete(e)}},sync:()=>g,async resolve(e){if(g.state!==`conflict`)return;let t=g.keys;if(e===`theirs`){for(let e of t)o(e,x[e]?.body??null),f.delete(e);p()}x={},y({state:`saved`}),await S()},flush:S,async refresh(){if(!l)return;await S();let{docs:t}=await e.state(),n=!1;for(let e of dr){let r=t[e];!r||f.has(e)||r.version<=(d[e]??0)||(d[e]=r.version,o(e,r.body),n=!0)}n&&(p(),h())}}}var Tl=e=>[1,2,3,4,5,6,7,8].includes(e?.version)||K().fatProfileRef(e),El=e=>e?.version===1||e?.version===2;function Dl(e){let t=[...e.get(`promptlab.workflows`).list.map(e=>e.work),...Object.values(e.get(`promptlab.versions`).pipeline??{}).flat().map(e=>e.doc)].filter(El).map(e=>e?.tests?.type===`graded`?e.tests.dataset?.id:void 0);return[...new Set(t.filter(e=>!!e))]}function Ol(e,t={}){let n=e=>K().upgradePipeline(e,{rulesFor:e=>t[e]??null}),r=e.get(`promptlab.workflows`);r.list.some(e=>Tl(e.work))&&e.set(`promptlab.workflows`,{...r,list:r.list.map(e=>({...e,work:n(e.work)}))});let i=e.get(`promptlab.versions`),a=i.pipeline??{};Object.values(a).some(e=>e.some(e=>Tl(e.doc)))&&e.set(`promptlab.versions`,{...i,pipeline:Object.fromEntries(Object.entries(a).map(([e,t])=>[e,t.map(e=>({...e,doc:n(e.doc)}))]))})}async function kl(e){let t=document.getElementById(`labstate`)?.textContent;if(t)try{return JSON.parse(t).docs??null}catch{return null}try{return(await e.state()).docs}catch{return null}}async function Al(){K();let e=me();if(Li())try{let t=(await e.config()).microsoft;t&&await Ri(t)}catch{}await fe(e);let t=wl({api:e,storage:localStorage,server:await kl(e)}),n=t.get(`promptlab.profiles`);n.list.some(e=>`profile`in e)&&t.set(`promptlab.profiles`,{...n,list:n.list.map(e=>K().convertProfile(e))});let r=t.get(`promptlab.profiles`),i=e=>K().pinReplyTokens(K().splitOllama(e));r.list.some(e=>i(e)!==e)&&t.set(`promptlab.profiles`,{...r,list:r.list.map(e=>i(e))});let a={};if(Dl(t).length)try{a=(await e.archivedRules()).rules}catch{}Ol(t,a),addEventListener(`pagehide`,()=>{t.flush(!0)}),(0,re.createRoot)(document.getElementById(`root`)).render((0,X.jsx)(q.StrictMode,{children:(0,X.jsx)(he.Provider,{value:t,children:(0,X.jsx)(ie.Provider,{value:e,children:(0,X.jsx)(_l,{})})})}))}Al();