evals-lab 0.1.2 → 0.1.3
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.
package/bin/evals-lab.js
CHANGED
|
@@ -32,7 +32,7 @@ const USAGE = `Usage: evals-lab [options]
|
|
|
32
32
|
127.0.0.1. Anything but loopback needs LAB_PASSWORD set.
|
|
33
33
|
--data-dir <dir> where the lab keeps its datasets, pipelines, profiles and
|
|
34
34
|
runs. Default: $DATA_DIR, else a per-user directory.
|
|
35
|
-
--version the package's version.
|
|
35
|
+
--version the package's version, and the lab build it was made from.
|
|
36
36
|
--help this.
|
|
37
37
|
|
|
38
38
|
Environment: LAB_PASSWORD puts a password in front of the lab, OLLAMA_URL is
|
|
@@ -129,6 +129,16 @@ function answers(url) {
|
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
// What the Home tab's footer says: "0.1.2 (2026.10.01-284)" -- the package,
|
|
133
|
+
// and the Image build of the same commit (npm/build.js).
|
|
134
|
+
function version() {
|
|
135
|
+
try {
|
|
136
|
+
return fs.readFileSync(path.join(LAB, "VERSION"), "utf8").trim();
|
|
137
|
+
} catch {
|
|
138
|
+
return `${require("../package.json").version} (dev)`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
132
142
|
function fail(message) {
|
|
133
143
|
console.error(`evals-lab: ${message}`);
|
|
134
144
|
process.exit(1);
|
|
@@ -138,10 +148,11 @@ async function main() {
|
|
|
138
148
|
let o;
|
|
139
149
|
try { o = options(process.argv.slice(2)); } catch (e) { fail(`${e.message}\n\n${USAGE}`); }
|
|
140
150
|
if (o.help) return console.log(USAGE);
|
|
141
|
-
if (o.version) return console.log(
|
|
151
|
+
if (o.version) return console.log(version());
|
|
142
152
|
if (!fs.existsSync(path.join(LAB, "server.py"))) {
|
|
143
153
|
fail(`no ${path.join(LAB, "server.py")} -- in a checkout the package is staged by \`node npm/build.js\``);
|
|
144
154
|
}
|
|
155
|
+
console.log(`evals-lab ${version()}`);
|
|
145
156
|
const python = findPython(pythonCandidates());
|
|
146
157
|
if (!python.cmd) {
|
|
147
158
|
const floor = PYTHON_FLOOR.join(".");
|
|
@@ -184,7 +195,7 @@ async function main() {
|
|
|
184
195
|
// than any later one.
|
|
185
196
|
for (let i = 0; i < 1200; i++) {
|
|
186
197
|
if (await answers(`${address}/healthz`)) {
|
|
187
|
-
console.log(`\nevals-lab is running at ${address}\n data: ${o.dataDir}\n stop: Ctrl+C`);
|
|
198
|
+
console.log(`\nevals-lab ${version()} is running at ${address}\n data: ${o.dataDir}\n stop: Ctrl+C`);
|
|
188
199
|
return;
|
|
189
200
|
}
|
|
190
201
|
await new Promise(r => setTimeout(r, 250));
|
package/lab/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.3 (2026.10.01-289)
|
|
@@ -4,7 +4,7 @@ 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 a
|
|
|
4
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
5
|
`||o===`\r`?(o===`\r`&&a[e+1]===`
|
|
6
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(`
|
|
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.3 (2026.10.01-289)`,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
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
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
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(`
|
package/lab/web/dist/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
6
|
<meta name="color-scheme" content="dark light">
|
|
7
7
|
<title>Evals Lab</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/main-
|
|
8
|
+
<script type="module" crossorigin src="/assets/main-HJGRUBM-.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/assets/tokens-B9intIuT.js">
|
|
10
10
|
<link rel="stylesheet" crossorigin href="/assets/tokens-s6I-RMVq.css">
|
|
11
11
|
<link rel="stylesheet" crossorigin href="/assets/main-DjQQums6.css">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "evals-lab",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "A browser bench for grading what a model answers: two wordings side by side over a set of files, scored against answers fixed in advance.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"author": "Grainbox Limited",
|