evals-lab 0.4.0 → 0.4.1

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/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@ Newest first. Read a release's **Upgrade notes** before installing it: an
5
5
  upgrade can rewrite what the lab keeps in your data directory, and an older
6
6
  version cannot always read it back.
7
7
 
8
+ ## 0.4.1
9
+
10
+ ### Changed
11
+
12
+ - The README is shorter, and describes the whole lab rather than one use
13
+ of it.
14
+
8
15
  ## 0.4.0
9
16
 
10
17
  ### Upgrade notes
package/README.md CHANGED
@@ -1,10 +1,15 @@
1
1
  # evals-lab
2
2
 
3
- A browser bench for grading what a model answers: two wordings side by side
4
- over a set of files, scored against answers fixed in advance.
3
+ A lab in the browser for evaluating prompts and models. A pipeline takes items
4
+ from a Source — uploaded files, a Power Automate flow's run history, or a
5
+ prompt alone — and sends each to one or more targets, every target a model
6
+ with its own prompt. Its evals score the replies with metrics — text and JSON
7
+ checks, item counts, agreement with production's reply, or a grading model —
8
+ and a dataset holds each item's expected answers. Every run is kept in
9
+ History, and every prompt version in the Library.
5
10
 
6
- This is an early test release. It runs on your own machine and talks to the
7
- models you point it at.
11
+ An early test release. It runs on your machine and talks only to the models
12
+ and services you connect it to.
8
13
 
9
14
  ## Install and run
10
15
 
@@ -13,31 +18,23 @@ npm install -g evals-lab
13
18
  evals-lab
14
19
  ```
15
20
 
16
- Then open <http://localhost:8080>. A new lab opens on two demo datasets, each
17
- with its images and a starter pipeline. The first start takes a little longer
18
- than later ones while it installs them.
21
+ Open <http://localhost:8080>. A new lab starts with two demo datasets and
22
+ their pipelines; the first start takes longer while it installs them. Without
23
+ installing: `npx evals-lab`.
19
24
 
20
- Without installing: `npx evals-lab`.
21
-
22
- ## What it needs
23
-
24
- | | | Windows | Linux |
25
- |---|---|---|---|
26
- | **Node.js** 22.18 or newer | runs the lab's worker | you have it if you have `npm` | same |
27
- | **Python** 3.10 or newer | runs the lab's server | `winget install Python.Python.3.13` | your distribution's `python3` |
28
- | **ImageMagick** | sizes images before a model is sent them, and makes thumbnails | `winget install ImageMagick.ImageMagick` | your distribution's `imagemagick` |
29
-
30
- `evals-lab` says which of these it could not find. It starts without
31
- ImageMagick, but a run that sends images needs it. Open a new terminal after
32
- installing one, so it is on your `PATH`.
25
+ | Needs | Windows | Linux |
26
+ |---|---|---|
27
+ | **Node.js** 22.18+ | comes with `npm` | same |
28
+ | **Python** 3.10+ | `winget install Python.Python.3.13` | your distribution's `python3` |
29
+ | **ImageMagick**, for runs that send images | `winget install ImageMagick.ImageMagick` | your distribution's `imagemagick` |
33
30
 
34
- macOS should work the same way and has not been tried.
31
+ `evals-lab` names anything it cannot find. Open a new terminal after
32
+ installing one. macOS should work and is untried.
35
33
 
36
34
  ## Where your data is kept
37
35
 
38
- Datasets, pipelines, Setup profiles (API keys among them), prompts, uploaded
39
- files and runs are kept on your machine, in one directory, so the lab opens
40
- as you left it:
36
+ Datasets, pipelines, Setup profiles (with their API keys), prompts, uploaded
37
+ files and runs are kept in one directory, which upgrades leave alone:
41
38
 
42
39
  | | |
43
40
  |---|---|
@@ -45,8 +42,7 @@ as you left it:
45
42
  | Linux | `~/.local/share/evals-lab` (or `$XDG_DATA_HOME/evals-lab`) |
46
43
  | macOS | `~/Library/Application Support/evals-lab` |
47
44
 
48
- Upgrading or reinstalling the package leaves it alone. Delete the directory
49
- to start again from a new lab.
45
+ Delete it to start again from a new lab.
50
46
 
51
47
  ## Options
52
48
 
@@ -61,125 +57,60 @@ evals-lab [--port <n>] [--host <address>] [--data-dir <dir>]
61
57
  | `--data-dir` | `DATA_DIR` | the directory above |
62
58
  | | `LAB_PASSWORD` | none |
63
59
  | | `OLLAMA_URL` | `http://127.0.0.1:11434` |
64
- | | `M365_CLIENT_ID`, `M365_TENANT` | none; see Power Automate below |
65
60
  | | `PYTHON` | `py -3`, `python` or `python3`, whichever is found |
66
61
 
67
- `OLLAMA_URL` is only the connection a new lab starts with. Every other
68
- connection — an OpenAI-compatible endpoint, Anthropic, llama.cpp — is a Setup
69
- profile you add in the page.
62
+ `--host 0.0.0.0` makes the lab reachable from your network and is refused
63
+ without `LAB_PASSWORD`. Never put it on the open internet: the lab holds your
64
+ API keys and forwards requests to any address a profile names.
65
+
66
+ ## Models
70
67
 
71
- ## Power Automate (Microsoft 365)
68
+ A model is a Setup profile: **Setup › Add profile**, then pick its type —
69
+ Ollama (local or cloud), OpenAI-compatible, Anthropic, llama.cpp or an HTTP
70
+ endpoint — and give its address, model and key. **Test connection** checks
71
+ it. An Ollama profile left without an address uses `OLLAMA_URL`.
72
72
 
73
- The lab can read a Power Automate cloud flow, and its run history, from your
74
- organisation's Microsoft 365 tenant, then grade the flow's HTTP step against
75
- the same model and prompt. The sign-in stays in your browser tab: the lab's
76
- server never receives a Microsoft token.
73
+ ## Power Automate
77
74
 
78
- It needs a work or school account. Microsoft retired cloud flows for personal
79
- accounts (outlook.com, hotmail.com) in July 2025, so a personal account cannot
80
- be used. For a small business, a trial or a Microsoft 365 Developer Program
81
- tenant, follow the same steps as a company.
75
+ The lab can read a Power Automate cloud flow and its run history from your
76
+ organisation's Microsoft 365 tenant, then grade the flow's HTTP step. It needs
77
+ a work or school account; personal accounts (outlook.com, hotmail.com) have no
78
+ cloud flows. A small business, a trial or a Microsoft 365 Developer Program
79
+ tenant follows the same steps. The sign-in stays in your browser tab.
82
80
 
83
- ### Register an app in your tenant
81
+ ### Register an app
84
82
 
85
- An administrator of the tenant registers it once, at
86
- <https://entra.microsoft.com>:
83
+ A tenant administrator does this once, at <https://entra.microsoft.com>:
87
84
 
88
85
  1. **App registrations › New registration.**
89
86
  - Supported account types: *Accounts in this organizational directory only*.
90
- - Redirect URI: platform **Single-page application**, value `http://localhost/`.
91
- Microsoft ignores the port on a `localhost` redirect, so this covers
92
- `--port` too. A lab served on another address needs that address here
93
- as well, over `https`.
94
- 2. **API permissions › Add a permission › APIs my organization uses.** Search
95
- for *Microsoft Flow Service* and add the delegated permission
96
- **Flows.Read.All**. If the service isn't listed, open
97
- <https://make.powerautomate.com> once, then search again.
98
- 3. **Grant admin consent** for the tenant.
99
- 4. No client secret or certificate is needed: the lab signs in as a public
100
- client.
101
-
102
- ### Tell the lab about it
103
-
104
- In the lab, open **Setup › Connections**, then use the Microsoft 365 row's
105
- menu › **Configure…**. Enter:
106
-
107
- | | |
108
- |---|---|
109
- | Client ID | the app's *Application (client) ID* |
110
- | Tenant | the *Directory (tenant) ID*, or one of the tenant's domains |
111
-
112
- Fill in Tenant for an app registered as above. Left empty, it means any
113
- organisation's tenant, which only a multitenant app accepts: Microsoft
114
- refuses the sign-in of a single-tenant app with `AADSTS50194`.
115
-
116
- Both are saved as you type, and neither is secret. **Sign in** from the same
117
- menu, then add a Source in the Sources tab with **Add source › Power Automate
118
- workflow**.
119
-
120
- To set the app for the whole machine instead, start the lab with
121
- `M365_CLIENT_ID` and `M365_TENANT` set. Setup then shows those values and
122
- can't change them.
123
-
124
- Open the lab at `localhost`, the address `evals-lab` prints. A sign-in begun
125
- at `127.0.0.1` reloads the page at `localhost`, the address registered above,
126
- and carries on from there. Anything open in the tab, such as an Add source
127
- dialog, does not carry over.
128
-
129
- ## Google Drive
130
-
131
- **Not usable yet.** The lab can sign in to Google Drive, but nothing reads
132
- from Drive yet: a Source made from a Drive folder is still to come. Until it
133
- arrives, there is no reason to set up a Google app, and the steps below are
134
- provisional. They haven't been tried against a real Google project.
135
-
136
- When it arrives, the sign-in will be held by the lab's server, on your
137
- machine. It will reach only the files you pick: the lab asks for
138
- `drive.file` access, never your whole Drive.
139
-
140
- To sign in, open **Setup › Connections**, then use the Google Drive row's
141
- menu › **Sign in**. If the row says *Not Configured*, give the lab a Google
142
- app first, once:
143
-
144
- 1. At <https://console.cloud.google.com>, make a project. Enable the
145
- **Google Drive API** and the **Google Picker API**.
146
- 2. **OAuth consent screen:** choose *External*. Give the app a name and your
147
- email, add the scope `.../auth/drive.file`, then **Publish app**. It needs
148
- no review from Google, because that scope is non-sensitive. Left in
149
- *Testing*, a sign-in lapses after 7 days.
150
- 3. **Credentials › Create credentials › OAuth client ID**, of type
151
- **Desktop app**. Download its JSON file.
152
- 4. **Credentials › Create credentials › API key.** Restrict it to the Google
153
- Picker API.
154
- 5. In the lab, use the Google Drive row's menu › **Configure…**, then
155
- **Load client file…**, and choose the file from step 3. Paste the key
156
- from step 4 into **API key**.
157
-
158
- A Desktop app needs no redirect registered: Google sends the browser back to
159
- any port on this machine. A lab you reach at its own address, from another
160
- machine, needs a *Web application* client instead. Choose that type in
161
- Configure…, then register the **Redirect URI** it shows with the client.
162
-
163
- Everything saves as you type. The client's secret is kept by the lab and
164
- never shown again. The window says only that one is saved.
165
-
166
- ## Reaching it from another machine
167
-
168
- By default only your own machine can reach the lab. That is deliberate: the
169
- lab's server forwards requests to whatever address a Setup profile names, so
170
- anyone who can reach the lab can reach those addresses through it, and the
171
- lab holds your API keys.
172
-
173
- `--host 0.0.0.0` makes it reachable from your network, and is refused unless
174
- `LAB_PASSWORD` is set. Do not put it on the open internet.
87
+ - Redirect URI: **Single-page application**, `http://localhost/`. This
88
+ covers any `--port`. A lab served elsewhere needs its own address here
89
+ too, over `https`.
90
+ 2. **API permissions › Add a permission › APIs my organization uses ›
91
+ Microsoft Flow Service**, delegated **Flows.Read.All**. If it isn't listed,
92
+ open <https://make.powerautomate.com> once and search again.
93
+ 3. **Grant admin consent.** No client secret is needed.
94
+
95
+ ### Connect the lab
96
+
97
+ 1. **Setup › Connections**, the Microsoft 365 row's menu › **Configure…**:
98
+ - Client ID: the app's *Application (client) ID*.
99
+ - Tenant: the *Directory (tenant) ID* or one of its domains. Left empty, a
100
+ single-tenant app's sign-in fails with `AADSTS50194`.
101
+ 2. The same menu › **Sign in**, with the lab open at `localhost`. A sign-in
102
+ from `127.0.0.1` reloads the page there and loses any open dialog.
103
+ 3. **Library › Sources › Add source › Power Automate workflow.**
104
+
105
+ Or set `M365_CLIENT_ID` and `M365_TENANT` when starting the lab, for the
106
+ whole machine; Setup then shows them read-only.
175
107
 
176
108
  ## Upgrading and removing
177
109
 
178
- Read `CHANGELOG.md` in the package, or on
179
- <https://www.npmjs.com/package/evals-lab?activeTab=code>, before upgrading.
180
- Its **Upgrade notes** say when a release rewrites what is in your data
181
- directory in a form an older version cannot read; copy the directory first
182
- if you may want to go back.
110
+ Read `CHANGELOG.md` first, in the package or on
111
+ <https://www.npmjs.com/package/evals-lab?activeTab=code>. When its
112
+ **Upgrade notes** say a release rewrites your data, copy the data directory
113
+ before upgrading if you may want to go back.
183
114
 
184
115
  ```bash
185
116
  npm install -g evals-lab@latest # upgrade
@@ -188,13 +119,9 @@ npm uninstall -g evals-lab # remove; your data directory stays
188
119
 
189
120
  ## Licence
190
121
 
191
- Copyright 2026 Grainbox Limited. Licensed under the
122
+ Copyright 2026 Grainbox Limited, under the
192
123
  [PolyForm Internal Use License 1.0.0](https://polyformproject.org/licenses/internal-use/1.0.0)
193
- (`LICENSE.md` in the package): you and your company may use it, and change it,
194
- for your own internal business. You may not give it, or a changed copy, to
195
- anyone else, sell it, or offer it as a service.
196
-
197
- ## The demo images
198
-
199
- Every image in the demo datasets is in the public domain. Each has its line in
200
- `lab/demo/CREDITS.md` inside the package.
124
+ (`LICENSE.md`): you and your company may use and change it for your own
125
+ internal business, but not give it, or a changed copy, to anyone else, sell
126
+ it, or offer it as a service. The demo images are public domain; each is
127
+ credited in `lab/demo/CREDITS.md`.
package/lab/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0 (2026.10.02-361)
1
+ 0.4.1 (2026.10.03-363)
@@ -6,7 +6,7 @@ import{$ as e,A as t,B as n,C as r,D as i,E as a,F as o,G as s,H as c,I as l,J a
6
6
  `],{type:`application/json`}),t(r))}catch(e){W(e)}},ue=e=>{let t=G();t&&(je(n,B,t,`restore`),K(()=>structuredClone(e.doc)),C(!1),a.offer({label:`Restored the dataset`,restore:()=>K(()=>t)}))},de=!z,fe=[{label:`Rename`,icon:t,disabled:!V,onSelect:()=>d(!0)},{label:`Clone`,icon:y.clone,disabled:!V,onSelect:()=>void X()},{label:`Import JSON…`,icon:r,busy:j===`import`,onSelect:()=>N.current?.click()},{label:`Export JSON`,icon:g,disabled:de,busy:j===`export`,onSelect:()=>void Q()},{label:`Export all`,icon:rt,disabled:!o?.length,busy:j===`exportAll`,onSelect:()=>{M(`exportAll`),le(i.exportAllUrl(),e=>_r(`datasets`,`all`,e.version,`json`)).finally(()=>M(null))}},{label:`Restore…`,icon:I,disabled:!ae.length||!V,onSelect:()=>C(!0)},{label:`Edit raw…`,icon:et,disabled:!V,onSelect:()=>x(!0)},{label:`Delete`,icon:b,destructive:!0,disabled:!V,onSelect:()=>void ce()}],me=H?H.cases.filter(e=>!e.todo).length:0,he=(0,$.jsx)(`input`,{ref:N,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&&Z(t)}}),ve=H?.source?.name,ye=H?[`${H.cases.length} cases`,`${me} graded`,...ve?[`Source: ${ve}`]:[]].join(` · `):void 0;return(0,$.jsxs)(`div`,{className:`datasets`,children:[(0,$.jsx)(ee,{kind:`Dataset`,name:V?.name??z?.name??(o===null?`Loading…`:`None`),onPick:o?.length?()=>p(!0):void 0,meta:ye,primary:{label:`New dataset`,icon:h,onSelect:()=>void oe()},actions:fe}),m&&(0,$.jsx)(`p`,{className:`note${m.bad?` bad`:``}`,role:m.bad?`alert`:`status`,children:m.text}),he,o===null||o.length===0?o===null?(0,$.jsx)(k,{label:`Datasets`,error:s,onRetry:()=>void i.refresh()}):(0,$.jsx)(`p`,{className:`note`,children:`No datasets yet.`}):(0,$.jsxs)(U,{id:`dataset`,title:`Cases`,note:H?String(H.cases.length):void 0,actions:[{label:`Page size`,icon:y.pageSize,onSelect:()=>A(!0)}],children:[H&&(0,$.jsxs)(`div`,{className:`prop`,"data-control":`select`,children:[(0,$.jsx)(`span`,{className:`prop-name`,children:`Source`}),(0,$.jsx)(`span`,{className:`prop-value`,children:(0,$.jsxs)(`select`,{"aria-label":`Source`,value:H.source?.id??``,onChange:e=>{let t=L?.find(t=>t.id===e.target.value);K(e=>({...e,source:t?{id:t.id,name:t.name}:null}))},children:[(0,$.jsx)(`option`,{value:``,children:`None`}),H.source&&!L?.some(e=>e.id===H.source.id)&&(0,$.jsxs)(`option`,{value:H.source.id,children:[H.source.name,` (missing)`]}),(L??[]).map(e=>(0,$.jsx)(`option`,{value:e.id,children:e.name},e.id))]})})]}),(0,$.jsx)(Yr,{pageSize:w})]}),f&&o&&(0,$.jsx)(P,{kind:`Dataset`,value:B,onClose:()=>p(!1),options:o.map(e=>({id:e.id,label:e.name})),onPick:e=>{l(e),_(null)}}),u&&V&&(0,$.jsx)(re,{title:`Rename dataset`,value:V.name,onCommit:se,onClose:()=>d(!1)}),E&&(0,$.jsx)(te,{value:w,onChange:T,onClose:()=>A(!1)}),S&&V&&(0,$.jsx)(D,{title:`Restore dataset`,onClose:()=>C(!1),children:(0,$.jsxs)(`div`,{className:`version-list`,children:[ae.length===0&&(0,$.jsx)(`p`,{className:`note`,children:`No versions of this dataset yet.`}),ae.map((e,t)=>(0,$.jsxs)(`div`,{className:`version-row`,children:[(0,$.jsxs)(`span`,{className:`version-when`,children:[ei(e.at),` · `,$r(e.reason)]}),(0,$.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>ue(e),children:`Restore`})]},`${e.at}-${t}`))]})}),v&&V&&(0,$.jsx)(yr,{name:V.name,body:V.body,onSave:e=>{K(()=>e),x(!1)},onClose:()=>x(!1)}),(0,$.jsx)(O,{undo:a.undo,onUndo:a.undoNow,onDismiss:a.dismiss})]})}function Zr(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 Qr=(e,t)=>{if(!t.has(e))return e;for(let n=2;;n++)if(!t.has(`${e} ${n}`))return`${e} ${n}`},$r=e=>e===`idle`?`after editing`:e===`restore`?`before a restore`:e===`bulk`?`before a bulk edit`:e===`pack`?`before a pack update`:e,ei=e=>{let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()},ti=[{value:`all`,label:`All`},{value:`used`,label:`Used`},{value:`unused`,label:`Unused`}],ni=[{value:`all`,label:`All`},{value:`scenario`,label:`Used by this target`},{value:`scenarios`,label:`Used by all targets`}];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=Ge(),a=qe(e),{openRun:o}=Jt(),[s,c]=(0,J.useState)(new Set),[l,u]=(0,J.useState)(new Set),[d,f]=(0,J.useState)(null),m=a?.doc;if(!m)return(0,$.jsx)(j,{title:`Prompt`,sections:[{key:`loading`,children:(0,$.jsx)(k,{label:`Prompt`,error:a?.sync.state===`missing`?a.sync.message:null,onRetry:()=>i.load(e)})}],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=>m.versions.find(t=>t.version===e)?.text??``,v=m.uses.some(e=>e.job>0),b=[{key:`version`,header:`Version`,sort:e=>e.version,cell:e=>`v${e.version}${e.version===m.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,$.jsx)(G,{label:`v${t.version} actions`,actions:[{label:s.has(t.version)?`Hide words`:`Show words`,icon:p,onSelect:()=>h(s,t.version,c)},{label:`Restore`,icon:ae,disabled:t.version===m.version,onSelect:()=>{f(null),i.restoreVersion(e,t.version).catch(g)}}]})}],x=e=>`${e.runId}:${e.scenarioId}:${e.job}`,S=[{key:`run`,header:`Run`,sort:e=>e.submittedAt,cell:e=>(0,$.jsx)(`a`,{className:`pl-run`,href:`#/history`,onClick:n=>{n.preventDefault(),t(),o(e.runId,{at:e.submittedAt,from:`history`})},children:un(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,$.jsx)(G,{label:`${un(e.submittedAt)} ${e.scenarioName} actions`,actions:[{label:l.has(x(e))?`Hide words`:`Show words`,icon:p,onSelect:()=>h(l,x(e),u)}]})}],C=[{label:`Set as default`,icon:wt,disabled:m.default,onSelect:()=>{f(null),i.setDefault(e).catch(g)}},{label:`Duplicate`,icon:y.clone,onSelect:()=>n(m)},{label:`Delete`,icon:y.remove,destructive:!0,disabled:m.default,onSelect:()=>r(m)}],w=d??ze(a.sync),T=a.sync.state===`conflict`;return(0,$.jsx)(j,{title:Re(m),status:w??void 0,statusBad:!!w,menu:C,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:m.name,placeholder:`First line`,onChange:t=>i.edit(e,{name:t})}},{key:`version`,label:`Version`,required:!0,control:{type:`static`,text:`v${m.version}${m.default?` (Default)`:``}`}},{key:`text`,label:`Prompt`,required:!0,control:{type:`textarea`,value:m.text,placeholder:`None`,onChange:t=>i.edit(e,{text:t})}}]},{key:`versions`,title:`Versions`,children:(0,$.jsx)(A,{className:`pltable pl-versions`,label:`Versions`,rows:m.versions,rowKey:e=>String(e.version),columns:b,after:e=>s.has(e.version)&&(0,$.jsx)(`tr`,{className:`pl-words-row`,children:(0,$.jsx)(`td`,{colSpan:b.length,children:(0,$.jsx)(`pre`,{className:`pl-words`,children:e.text})})})})},{key:`uses`,title:`Uses`,children:m.uses.length===0?(0,$.jsx)(`p`,{className:`note`,children:`No uses yet.`}):(0,$.jsx)(A,{className:`pltable pl-uses`,label:`Uses`,rows:m.uses,rowKey:x,pageSize:10,columns:S,after:e=>l.has(x(e))&&(0,$.jsx)(`tr`,{className:`pl-words-row`,children:(0,$.jsx)(`td`,{colSpan:S.length,children:(0,$.jsx)(`pre`,{className:`pl-words`,children:_(e.version)})})})})}]})}function si(){let e=Ge(),{list:t,error:n}=Ke(),r=ne(),[i,a]=ie(`prompts`,20),[o,s]=(0,J.useState)(!1),[c,l]=(0,J.useState)(``),[u,d]=(0,J.useState)(`all`),[f,p]=(0,J.useState)(null),[m,g]=(0,J.useState)(null),_=t??[],v=_.filter(e=>ri(e,c,u)),b=e=>g(e instanceof Error?e.message:String(e)),x=async()=>{g(null);try{p((await e.create({name:``,text:``})).id)}catch(e){b(e)}},S=async t=>{g(null);try{await e.flush(t.id);let n=await e.create({name:`${Re(t)} copy`,text:e.entry(t.id)?.doc?.text??t.text});p(n.id)}catch(e){b(e)}},C=async t=>{g(null);try{let n=await e.remove(t.id);f===t.id&&p(null),r.offer({label:`Deleted ${Re(t)}`,restore:()=>{e.restore(n).catch(b)}})}catch(e){b(e)}},w=t=>{g(null),e.setDefault(t.id).catch(b)},T=e=>[{label:`Edit`,icon:y.edit,onSelect:()=>p(e.id)},{label:`Set as default`,icon:wt,disabled:e.default,onSelect:()=>w(e)},{label:`Duplicate`,icon:y.clone,onSelect:()=>void S(e)},{label:`Delete`,icon:y.remove,destructive:!0,disabled:e.default,onSelect:()=>void C(e)}];return(0,$.jsxs)(U,{id:`prompts`,title:`Prompt library`,note:t?`${_.length} ${_.length===1?`prompt`:`prompts`}`:void 0,actions:[{label:`Page size`,icon:y.pageSize,onSelect:()=>s(!0)}],about:`Wordings kept with every version and the runs that used them. The Default is the one a new target starts from.`,children:[t===null?(0,$.jsx)(k,{label:`Prompts`,error:n,onRetry:()=>void e.refresh()}):_.length===0?(0,$.jsx)(`p`,{className:`note`,children:`No prompts yet.`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(z,{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:v.length,total:_.length}}),v.length===0?(0,$.jsx)(`p`,{className:`note`,children:`No prompts match these filters.`}):(0,$.jsx)(A,{className:`pltable`,label:`Prompts`,rows:v,rowKey:e=>e.id,pageSize:i,rowProps:e=>({"data-default":e.default||void 0}),columns:[{key:`prompt`,header:`Prompt`,sort:e=>Re(e).toLowerCase(),cell:e=>(0,$.jsxs)(`button`,{type:`button`,className:`pl-open`,onClick:()=>p(e.id),children:[(0,$.jsxs)(`span`,{className:`pl-title`,children:[Re(e),e.default&&(0,$.jsx)(`span`,{className:`pl-default`,children:`Default`})]}),e.name.trim()&&e.text.trim()&&(0,$.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,$.jsx)(G,{label:`${Re(e)} actions`,actions:T(e)})}]})]}),m&&(0,$.jsx)(`p`,{className:`note bad`,role:`alert`,children:m}),(0,$.jsxs)(`button`,{type:`button`,className:`ghost pl-add`,onClick:()=>void x(),children:[(0,$.jsx)(h,{size:14,"aria-hidden":`true`}),`Add prompt`]}),f&&(0,$.jsx)(oi,{id:f,onClose:()=>p(null),onDuplicate:e=>void S(e),onDelete:e=>void C(e)}),o&&(0,$.jsx)(te,{value:i,onChange:a,onClose:()=>s(!1)}),(0,$.jsx)(O,{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:Z(()=>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}var Bi=`signin`;function Vi(e=window.location.href){let t=new URL(e);return t.hostname===`127.0.0.1`?(t.hostname=`localhost`,t.searchParams.set(Bi,`microsoft`),t.href):null}function Hi(){let e=new URL(window.location.href);return e.searchParams.get(`signin`)===`microsoft`&&(e.searchParams.delete(Bi),window.history.replaceState(window.history.state,``,e.href),!0)}async function Ui(e,t=window.location.href){let n=Vi();if(n){window.location.assign(n);return}await(await Ii(e)).loginRedirect({scopes:Pi,prompt:`select_account`,redirectStartPage:t})}async function Wi(e){let t=await Ii(e),n=t.getActiveAccount()??t.getAllAccounts()[0];n&&await t.clearCache({account:n})}async function Gi(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 Z(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}}var Ki=new EventTarget,qi=()=>Ki.dispatchEvent(new Event(`change`));function Ji(){let e=Y(),[t,n]=(0,J.useState)({cfg:void 0,editable:!1});return(0,J.useEffect)(()=>{let t=!0,r=()=>e.config().then(e=>{t&&n({cfg:e.microsoft??null,editable:!!e.microsoftEditable})},()=>{t&&n({cfg:null,editable:!1})});return r(),Ki.addEventListener(`change`,r),()=>{t=!1,Ki.removeEventListener(`change`,r)}},[e]),t}var Yi=()=>Ji().cfg,Xi=e=>Ni(()=>Gi(e));async function Zi(e,t,n){let r=await e.flow(t,n);return{name:r.name,definition:Di(r.definition).value}}function Qi({onMade:e}){let t=Y(),n=Yi(),r=(0,J.useMemo)(()=>n?Xi(n):null,[n]),[i,a]=(0,J.useState)(void 0),[o,s]=(0,J.useState)(null),[c,l]=(0,J.useState)(``),[u,d]=(0,J.useState)(null),[f,p]=(0,J.useState)(``),[m,h]=(0,J.useState)(``),[g,_]=(0,J.useState)(!1),[v,y]=(0,J.useState)(null),b=e=>y(e instanceof Error?e.message:String(e));if((0,J.useEffect)(()=>{n&&zi(n).then(a,()=>a(null))},[n]),(0,J.useEffect)(()=>{r&&i&&r.environments().then(e=>{s(e),l((e.find(e=>e.isDefault)??e[0])?.id??``)},b)},[r,i]),(0,J.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,$.jsx)(k,{label:`Account`});if(n===null)return(0,$.jsx)(`p`,{className:`note`,children:`Microsoft: Not Configured`});if(!i)return(0,$.jsxs)(`div`,{className:`sacts`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`ghost`,onClick:()=>void Ui(n).catch(b),children:[(0,$.jsx)(dt,{size:14,"aria-hidden":`true`}),` Sign in with Microsoft`]}),v&&(0,$.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 Zi(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,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{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,$.jsx)(`p`,{className:`note`,children:`No flows in this environment.`}),v&&(0,$.jsx)(`p`,{className:`note bad`,role:`alert`,children:v}),(0,$.jsx)(`div`,{className:`sacts`,children:(0,$.jsx)(`button`,{type:`button`,className:`ghost`,disabled:g||!f||!m.trim(),onClick:()=>void x(),children:`Add`})})]})}var $i=`evals-lab/record`,ea=e=>typeof e==`object`&&!!e&&!Array.isArray(e),ta=/\b(triggerBody|triggerOutputs|body|outputs|actions|variables|items|item|parameters)\(\s*(?:'((?:[^']|'')*)')?\s*\)/g;function na(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)na(n,t);else if(ea(e))for(let n of Object.values(e))na(n,t);return t}function ra(e,t=null){let n=new Map;for(let r of na(e))for(let e of r.matchAll(ta)){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 ia(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:$i,version:1,step:e,at:null,scope:n,request:null,result:null,origin:{kind:`hand`}}}function aa(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):ea(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 oa=Object.create(null);oa.Http={label:`HTTP`,template:({headers:e,authentication:t,...n})=>n};var sa=Object.create(null);sa.Foreach={loops:!0},sa.Until={loops:!0},sa.InitializeVariable={declares:e=>(Array.isArray(e.variables)?e.variables:[]).flatMap(e=>ea(e)&&typeof e.name==`string`?[e.name]:[])};var ca=e=>!!(e&&sa[e]?.loops);function la(e){let t=[],n=(e,r)=>{for(let[i,a]of Object.entries(e??{})){let e=a.type?oa[a.type]:void 0;if(e&&ea(a.inputs)){let n=e.template(a.inputs);t.push({name:i,kind:a.type,loops:r,template:n,reads:ra(n,r.at(-1)??null)})}let o=ca(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(ea(e)?e.actions:void 0,[]),t}function ua(e){let t={},n=(e,r)=>{for(let[i,a]of Object.entries(e??{})){t[i]={...a,loops:r};let e=ca(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(ea(e)?e.actions:void 0,[]),t}async function da(e,t,n,r){let i=ua(r),a={};for(let r of e.reads)if(r.from===`trigger`){let e=await n.triggerOutputs();a.trigger={body:ea(e)?e.body:e}}else if(r.from===`action`){let e=await n.actionOutputs(r.name,t.at);(a.actions??={})[r.name]=ea(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?sa[e.type]:void 0;return!!t?.declares&&ea(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=(ea(s)&&Array.isArray(s.variables)?s.variables:[]).find(e=>ea(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=ea(e)&&Array.isArray(e.foreachItems)?e.foreachItems:[];(a.items??={})[r.name]=i[t.at[r.name]??0]??null}let o=ea(t.inputs)?t.inputs:null,s=ea(t.outputs)?t.outputs:null;return{format:$i,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 fa(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 pa=e=>e.from===`trigger`?`trigger`:e.from===`parameter`?``:e.name,ma=e=>{if(typeof e!=`string`)return e;try{return JSON.parse(e)}catch{return e}};function ha(e,t){let n=[...new Set(t.flatMap(e=>Object.keys(e)))],r=new Set(e.reads.map(pa).filter(Boolean)),i=n.filter(e=>!r.has(e)&&!(r.has(`trigger`)&&e.startsWith(`trigger.`)));return{records:t.map(t=>{let n=ia(e.name,e.reads);n.origin={kind:`upload`};for(let r of e.reads){let e=pa(r);if(r.from===`trigger`){let r=Object.keys(t).filter(e=>e.startsWith(`trigger.`)),i=e in t?ma(t[e]):r.length?Object.fromEntries(r.map(e=>[e.slice(8),ma(t[e])])):null;n.scope.trigger={body:i}}else if(e in t){let i=ma(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 ga(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===`
7
7
  `||o===`\r`?(o===`\r`&&a[e+1]===`
8
8
  `&&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 _a(e,t,n){if(!t.request)return{match:null};let r=ea(n)&&ea(n.parameters)?Object.fromEntries(Object.entries(n.parameters).map(([e,t])=>[e,ea(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:_(a.method,n),uri:_(a.uri,n),body:_(a.body??null,n)}}catch(e){return{match:!1,where:e instanceof Error?e.message:String(e)}}let a=va(i,t.request,`request`);return a?{match:!1,where:a}:{match:!0}}function va(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=va(e[r],t[r],`${n}[${r}]`);if(i)return i}return null}if(ea(e)&&ea(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=va(e[i],t[i],`${n}.${i}`);if(r)return r}return null}return JSON.stringify(e)===JSON.stringify(t)?null:`${n}`}var ya=Object.create(null);ya.ParseJson={reads:e=>typeof e.content==`string`?e.content:null,schema:e=>e.schema??null};function ba(e,t){for(let[n,r]of Object.entries(ua(e))){let e=r.type?ya[r.type]:void 0,i=e&&ea(r.inputs)?e.reads(r.inputs):null;if(i&&ra(i).some(e=>e.from===`action`&&e.name===t))return{name:n,expression:i,schema:e.schema&&ea(r.inputs)?e.schema(r.inputs)??null:null}}return null}function xa(e,t){let n=JSON.stringify(ea(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 Sa(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 Ca(e,t){let n=x(),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 wa(e,t,n,r){let i=x(),a=n.template,o=String(a.uri??``),s=i.httpApiFor(o),c={type:`httpRequest`,api:s,method:String(a.method??`POST`).toUpperCase(),...Sa(o),body:a.body??null,...i.HTTP_APIS[s].cellOf(a.body??null)},l=ba(t,n.name),u=l?xa(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(`
9
- `)}]:[]],f=Ca(o,r),p=i.withOut({type:`job`,id:i.newId(),name:n.name,steps:[{type:`attachContent`,content:{type:`source`,ref:e,first:null,loops:1}},{type:`flowStep`,step:n.name,loop:n.loops.at(-1)??null,api:s},...l?.expression?[{type:`readAs`,readAs:l.expression}]:[]]},{kind:`text`,...i.OUTPUT_KINDS.text?.settingDefaults?.()??{},modifiers:i.OUTPUT_KINDS.text?.modifiers?.()??[]});return{version:i.PIPELINE_VERSION,id:i.newId(),name:`${e.name} · ${n.name}`,jobs:[p],targets:[{id:i.newId(),name:`Production`,profile:f,steps:[structuredClone(c)]},{id:i.newId(),name:`Edited`,profile:f,steps:[structuredClone(c)]}],evals:d.length?[i.newEval(`metrics`,``,{metrics:d})]:[]}}function Ta(e,t){let n=e.result;if(!n||!(`status`in n))return null;let r=la(t).find(t=>t.name===e.step);if(!r)return null;let i=String(r.template.uri??``),a={step:r.name,loop:r.loops.at(-1)??null,api:x().httpApiFor(i),readAs:ba(t,r.name)?.expression??null};try{return x().httpReplyOf(a,{prompt:``},n.body,n.status,{scope:e.scope,now:e.at}).raw}catch{return null}}function Ea(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 Da(e,t){let n=[],r=0;for(let{name:i,record:a}of e){let e=Ta(a,t);if(e==null){r++;continue}let o=ba(t,a.step),s=o?xa(t,o.name):[];n.push({id:i.replace(/\.json$/i,``).replace(/[^A-Za-z0-9._-]/g,`_`),item:i,todo:!0,note:``,metrics:Ea(e,s)})}return{cases:n,skipped:r}}async function Oa(e,t,n,r,i){let a=await e.run(t,n,r),o=ua(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 ka(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 Oa(e,t,n,o,a);for(let e of await r.callsOf(i)){let t=Di(await da(i,e,r,a)).value,n=aa(t);if(c.has(n)){u++;continue}c.add(n),l.push(t)}s?.(++d)}return{records:l,skipped:u}}var Aa=e=>e.name.toLowerCase().endsWith(`.json`),ja=e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result)),r.onerror=()=>n(r.error),r.readAsText(e)}),Ma=`evals-lab.flow.importing`;function Na(e){try{return sessionStorage.getItem(e)}catch{return null}}function Pa(e,t){try{t?sessionStorage.setItem(e,t):sessionStorage.removeItem(e)}catch{}}var Fa=e=>e instanceof Error?e.message:String(e);function Ia({source:e,definition:t,cfg:n}){let i=Y(),a=Fe(),o=ne(),[s,c]=(0,J.useState)(e.files.filter(Aa)),[l,u]=(0,J.useState)({}),[d,f]=(0,J.useState)(null),[m,_]=(0,J.useState)(()=>{let t=Na(Ma)===e.id;return t&&Pa(Ma,null),t?`import`:null}),[v,y]=(0,J.useState)(null),x=(0,J.useMemo)(()=>la(t),[t]),[S,C]=(0,J.useState)(!1),[w,T]=(0,J.useState)(null),E=(0,J.useCallback)(async()=>{let t=(await i.source(e.id)).files.filter(Aa);c(t);let n=await Promise.all(t.map(async t=>{try{return[t.name,JSON.parse(await ja(await i.file(e.id,t.name)))]}catch{return[t.name,null]}}));u(Object.fromEntries(n))},[i,e.id]),j=(0,J.useCallback)(()=>{T(null),E().then(()=>C(!0),e=>T(Fa(e)))},[E]);(0,J.useEffect)(j,[j]);let M=e=>{let n=l[e],r=n?x.find(e=>e.name===n.step):void 0;return n&&r?_a(r,n,t):null},N=(0,J.useMemo)(()=>new Set(s.flatMap(e=>l[e.name]?[aa(l[e.name])]:[])),[s,l]),P=async(t,n=0)=>{let r=0,a=[];for(let n of t)try{await i.upload(e.id,fa(n),new Blob([JSON.stringify(n,null,2)],{type:`application/json`})),r++}catch(e){a.push(e instanceof pe?e.message:Fa(e))}await E(),f([`Added ${r}`,n?`Skipped ${n}`:``,a.length?`Refused ${a.length}: ${a[0]}`:``].filter(Boolean).join(` · `))},ee=async()=>{let{cases:n,skipped:r}=Da(s.flatMap(e=>l[e.name]?[{name:e.name,record:l[e.name]}]:[]),t);if(!n.length)return f(`No record holds a production reply.`);try{let t=await a.create(`${e.name} · production`,{...be(),source:{id:e.id,name:e.name},cases:n});f([`Made ${t.name}: ${n.length} ${n.length===1?`case`:`cases`}`,r?`Skipped ${r}`:``].filter(Boolean).join(` · `))}catch(e){f(Fa(e))}},F=async t=>{try{let{trash:n}=await i.removeFiles(e.id,t);c(e=>e.filter(e=>!t.includes(e.name))),o.offer({label:`Removed ${t[0]}`,restore:()=>void i.restoreTrash(n).then(E,e=>f(Fa(e)))})}catch(e){f(Fa(e))}},L=async t=>{let n=URL.createObjectURL(await i.file(e.id,t)),r=document.createElement(`a`);r.href=n,r.download=t,document.body.append(r),r.click(),r.remove(),URL.revokeObjectURL(n)},te=e=>[{label:`View`,icon:p,onSelect:()=>y(e.name)},{label:`Download`,icon:g,onSelect:()=>void L(e.name).catch(e=>f(Fa(e)))},{label:`Remove`,icon:b,destructive:!0,onSelect:()=>void F([e.name])}],R=(0,J.useCallback)(()=>_(null),[]),z=(0,J.useCallback)(()=>y(null),[]),B=v?l[v]:null;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(U,{id:`flow-records`,title:`Records`,note:String(s.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:I,disabled:!x.length||!n,onSelect:()=>_(`import`)},{label:`Upload`,icon:r,disabled:!x.length,onSelect:()=>_(`upload`)},{label:`New dataset`,icon:Qe,disabled:!s.length,onSelect:()=>void ee()}],children:[d&&(0,$.jsx)(`p`,{className:`note`,role:`status`,children:d}),S?s.length?(0,$.jsx)(`div`,{className:`sflow`,children:(0,$.jsx)(A,{className:`slist`,label:`Records`,rows:s,rowKey:e=>e.name,columns:[{key:`name`,header:`Name`,sort:e=>e.name,cell:e=>(0,$.jsxs)($.Fragment,{children:[e.name,(0,$.jsx)(`span`,{className:`sflow-in`,children:za(l[e.name])})]})},{key:`result`,header:`Result`,sort:e=>Ba(l[e.name]),cell:e=>Ba(l[e.name])},{key:`request`,header:`Request`,sort:e=>La(M(e.name)),tdProps:e=>{let t=M(e.name);return t&&t.match===!1?{title:t.where}:{}},cell:e=>La(M(e.name))},{key:`menu`,header:``,className:`s-actions`,sort:null,cell:e=>(0,$.jsx)(G,{label:`${e.name} actions`,actions:te(e)})}]})}):(0,$.jsx)(`p`,{className:`note`,children:`No records yet. Import runs, in this group's menu, reads them from the flow's run history.`}):(0,$.jsx)(k,{label:`Records`,error:w,onRetry:j}),(0,$.jsxs)(`button`,{type:`button`,className:`ghost add-btn`,disabled:!x.length,onClick:()=>_(`hand`),children:[(0,$.jsx)(h,{size:14,"aria-hidden":`true`}),` Add record`]})]}),m===`import`&&n&&(0,$.jsx)(Ua,{cfg:n,source:e,steps:x,definition:t,held:N,onClose:R,onRead:async(e,t)=>{_(null),await P(e,t)}}),m===`hand`&&(0,$.jsx)(Wa,{steps:x,onClose:R,onAdd:async e=>{_(null),await P([e])}}),m===`upload`&&(0,$.jsx)(Ka,{steps:x,onClose:R,onRead:async e=>{_(null),await P(e)}}),v&&(0,$.jsx)(D,{title:v,onClose:z,wide:!0,children:(0,$.jsx)(`pre`,{className:`pl-words`,children:B?JSON.stringify(B,null,2):`Unreadable.`})}),(0,$.jsx)(O,{undo:o.undo,onUndo:o.undoNow,onDismiss:o.dismiss})]})}var La=e=>!e||e.match===null?`—`:e.match?`Match`:`Differs`,Ra={run:`Run`,hand:`Hand`,upload:`Upload`},za=e=>e?[e.step,Ra[e.origin.kind]??e.origin.kind,e.at?xi(Date.parse(e.at)/1e3):``].filter(Boolean).join(` · `):`Unreadable`;function Ba(e){let t=e?.result;return t?`error`in t?t.error.code||`Error`:String(t.status):`—`}var Va=e=>e.map(e=>({value:e.name,label:e.name})),Ha=e=>e.from===`trigger`?`Trigger body`:pa(e);function Ua({cfg:e,source:t,steps:n,definition:r,held:i,onClose:a,onRead:o}){let s=(0,J.useMemo)(()=>Xi(e),[e]),c=t.config??{},[l,u]=(0,J.useState)(void 0),[d,f]=(0,J.useState)(n[0]?.name??``),[p,m]=(0,J.useState)(null),[h,g]=(0,J.useState)(``),[_,v]=(0,J.useState)(new Set),[y,b]=(0,J.useState)(``),[x,S]=(0,J.useState)(null),[C,w]=(0,J.useState)(null),[T,E]=(0,J.useState)(null),[O,j]=(0,J.useState)(0);(0,J.useEffect)(()=>{zi(e).then(u,()=>u(null))},[e]),(0,J.useEffect)(()=>{l&&c.environment&&c.flow&&(E(null),s.runs(c.environment,c.flow).then(m,e=>E(Fa(e))))},[l,s,c.environment,c.flow,O]);let M=(0,J.useMemo)(()=>[...new Set((p??[]).map(e=>e.status))].sort(),[p]),P=(0,J.useMemo)(()=>(p??[]).filter(e=>!h||e.status===h),[p,h]),ee=e=>v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),F=P.length>0&&P.every(e=>_.has(e.id)),I=P.filter(e=>_.has(e.id)).map(e=>e.id),L=async()=>{let e=n.find(e=>e.name===d);if(!e||!c.environment||!c.flow)return;let t=I;w(null),S(`Reading 0 of ${t.length}`);try{let{records:n,skipped:a}=await ka(s,c.environment,c.flow,t,e,r,i,e=>S(`Reading ${e} of ${t.length}`));await o(n,a)}catch(e){w(Fa(e)),S(null)}};return(0,$.jsxs)(D,{title:`Import runs`,onClose:a,wide:!0,footer:(0,$.jsxs)(`div`,{className:`sacts`,children:[x&&(0,$.jsx)(`span`,{className:`note`,role:`status`,children:x}),(0,$.jsxs)(`button`,{type:`button`,className:`ghost`,disabled:!!x||!I.length||!d,"aria-busy":!!x||void 0,onClick:()=>void L(),children:[x&&(0,$.jsx)(W,{}),`Import `,I.length||``]})]}),children:[l===void 0?(0,$.jsx)(k,{label:`Account`}):l?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{label:`Import`,rows:[{key:`step`,label:`Step`,control:{type:`select`,value:d,options:Va(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(P.slice(0,t).map(e=>e.id)))}}}]}),p?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(z,{noun:`runs`,count:{shown:P.length,total:p.length},lead:(0,$.jsx)(`input`,{type:`checkbox`,"aria-label":`Select all shown`,checked:F,disabled:!P.length,onChange:()=>v(F?new Set:new Set(P.map(e=>e.id)))}),filters:[{key:`status`,label:`Status`,value:h,onChange:g,options:[{value:``,label:`All`},...M.map(e=>({value:e,label:e}))]}]}),P.length?(0,$.jsx)(`div`,{className:`sflow`,children:(0,$.jsx)(A,{className:`slist`,label:`Runs`,rows:P,rowKey:e=>e.id,pageSize:20,rowProps:e=>({onClick:()=>ee(e.id),"data-selected":_.has(e.id)||void 0}),columns:[{key:`pick`,header:``,sort:null,cell:e=>(0,$.jsx)(`input`,{type:`checkbox`,"aria-label":`Run ${e.id}`,checked:_.has(e.id),onChange:()=>ee(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,$.jsx)(`p`,{className:`note`,children:`No runs.`})]}):(0,$.jsx)(k,{label:`Runs`,error:T,onRetry:()=>j(e=>e+1)})]}):(0,$.jsx)(`div`,{className:`sacts`,children:(0,$.jsxs)(`button`,{type:`button`,className:`ghost`,onClick:()=>{Pa(Ma,t.id),Ui(e).catch(e=>{Pa(Ma,null),w(Fa(e))})},children:[(0,$.jsx)(dt,{size:14,"aria-hidden":`true`}),` Sign in with Microsoft`]})}),C&&(0,$.jsx)(`p`,{className:`note bad`,role:`alert`,children:C})]})}function Wa({steps:e,onClose:t,onAdd:n}){let[r,i]=(0,J.useState)(e[0]?.name??``),[a,o]=(0,J.useState)({}),s=e.find(e=>e.name===r),c=(s?.reads??[]).filter(e=>pa(e));return(0,$.jsxs)(D,{title:`Add record`,onClose:t,wide:!0,footer:(0,$.jsx)(`div`,{className:`sacts`,children:(0,$.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=>pa(t)===e))),[t]=ha(s,[e]).records;n({...t,origin:{kind:`hand`}})},children:`Add`})}),children:[(0,$.jsx)(N,{label:`Record`,rows:[{key:`step`,label:`Step`,control:{type:`select`,value:r,options:Va(e),onChange:e=>{i(e),o({})}}},...c.map(e=>({key:`read-${pa(e)}`,label:Ha(e),control:{type:`textarea`,value:a[pa(e)]??``,onChange:t=>o(n=>({...n,[pa(e)]:t}))}}))]}),s&&!c.length&&(0,$.jsx)(`p`,{className:`note`,children:`Reads nothing.`})]})}function Ga(e,t){if(e.toLowerCase().endsWith(`.csv`))return{rows:ga(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 Ka({steps:e,onClose:t,onRead:n}){let i=(0,J.useRef)(null),[a,o]=(0,J.useState)(e[0]?.name??``),[s,c]=(0,J.useState)(null),[l,u]=(0,J.useState)(null),d=e.find(e=>e.name===a),f=s&&d&&`rows`in s.parsed?ha(d,s.parsed.rows):null,p=s?`records`in s.parsed?s.parsed.records:f?.records??[]:[],m=async e=>{if(e){u(null);try{c({name:e.name,parsed:Ga(e.name,await ja(e))})}catch(t){c(null),u(`${e.name}: ${Fa(t)}`)}}};return(0,$.jsxs)(D,{title:`Upload`,onClose:t,wide:!0,footer:(0,$.jsx)(`div`,{className:`sacts`,children:(0,$.jsxs)(`button`,{type:`button`,className:`ghost`,disabled:!p.length,onClick:()=>void n(p),children:[`Add `,p.length||``]})}),children:[(0,$.jsx)(N,{label:`Upload`,rows:[...s&&`records`in s.parsed?[]:[{key:`step`,label:`Step`,control:{type:`select`,value:a,options:Va(e),onChange:o}}],{key:`file`,label:`File`,control:{type:`static`,text:s?.name??`—`}},...s?[{key:`count`,label:`records`in s.parsed?`Records`:`Rows`,control:{type:`static`,text:String(p.length)}}]:[],...f?.unmatched.length?[{key:`unmatched`,label:`Unmatched`,control:{type:`static`,text:f.unmatched.join(`, `)}}]:[]]}),(0,$.jsxs)(`div`,{className:`sacts`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`ghost`,onClick:()=>i.current?.click(),children:[(0,$.jsx)(r,{size:14,"aria-hidden":`true`}),` Choose file`]}),(0,$.jsx)(`input`,{ref:i,type:`file`,accept:`.json,.csv`,hidden:!0,"aria-hidden":`true`,onChange:e=>{m(e.target.files?.[0]),e.target.value=``}})]}),l&&(0,$.jsx)(`p`,{className:`note bad`,role:`alert`,children:l})]})}function qa({source:e}){let t=Y(),n=Yi(),[r,i]=(0,J.useState)(null),[a,o]=(0,J.useState)(null),[s,c]=(0,J.useState)(!1),[l,u]=(0,J.useState)(null),d=e.config??{},f=(0,J.useCallback)(()=>{u(null),t.definition(e.id).then(i,e=>{i(null),u(e instanceof Error?e.message:String(e))})},[t,e.id]);(0,J.useEffect)(f,[f]);let p=async()=>{if(n&&r&&d.environment&&d.flow){c(!0),o(null);try{if(!await zi(n)){await Ui(n);return}let a=await Zi(Xi(n),d.environment,d.flow);i(await t.saveDefinition(e.id,r.version,a.definition)),o(`Synced.`)}catch(e){e instanceof pe&&e.status===409?(f(),o(`It changed since: reloaded.`)):o(e instanceof Error?e.message:String(e))}finally{c(!1)}}},m=(0,J.useMemo)(()=>Ja(r?.body),[r]),h=(0,J.useMemo)(()=>la(r?.body),[r]),[g,_]=_e(`promptlab.workflows`),[v]=_e(`promptlab.profiles`),y=t=>{let n=h.find(e=>e.name===t);if(!n||!r)return;let i=wa({id:e.id,name:e.name},r.body,n,v.list),a={id:i.id,name:i.name,work:i};_({...g,list:[...g.list,a],at:a.id}),location.hash=`#/runs`};return(0,$.jsxs)(`div`,{className:`sources`,"data-level":`flow`,children:[a&&(0,$.jsx)(`p`,{className:`note`,role:`status`,children:a}),(0,$.jsxs)(U,{id:`flow-source`,title:`Flow`,note:d.displayName,actions:[{label:`Re-sync`,icon:_t,busy:s,disabled:!n||!r,onSelect:()=>void p()}],children:[(0,$.jsx)(N,{label:`Flow`,rows:[{key:`flow`,label:`Flow`,control:{type:`static`,text:d.displayName||d.flow||`—`}},{key:`env`,label:`Environment`,control:{type:`static`,text:d.environment||`—`}},...r?[{key:`version`,label:`Definition`,control:{type:`static`,text:r.version?`Version ${r.version}${r.at?` · ${xi(Date.parse(r.at)/1e3)}`:``}`:`None`}}]:[]]}),!r&&(0,$.jsx)(k,{label:`Definition`,error:l,onRetry:f})]}),(0,$.jsx)(Ia,{source:e,definition:r?.body??null,cfg:n}),(0,$.jsx)(U,{id:`flow-actions`,title:`Actions`,note:r?String(m.length):void 0,children:r?m.length?(0,$.jsx)(`div`,{className:`sflow`,children:(0,$.jsx)(A,{className:`slist`,label:`Actions`,rows:m,rowKey:e=>e.name,columns:[{key:`name`,header:`Name`,sort:e=>e.name,cell:e=>(0,$.jsxs)($.Fragment,{children:[e.name,e.in&&(0,$.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=>h.some(t=>t.name===e.name)?(0,$.jsx)(G,{label:`${e.name} actions`,actions:[{label:`New pipeline`,icon:gt,onSelect:()=>y(e.name)}]}):null}]})}):(0,$.jsx)(`p`,{className:`note`,children:`No actions.`}):(0,$.jsx)(k,{label:`Actions`,error:l,onRetry:f})})]})}function Ja(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 Ya={"power-automate":{Create:Qi,Level:qa}};function Xa({sourceId:e=null,onOpen:n,mode:a=`browse`,onPick:s,disabled:c}){let l=Y(),u=ne(),[d,f]=(0,J.useState)(null),[m,_]=(0,J.useState)(0),[y,S]=(0,J.useState)(0),[C,w]=(0,J.useState)(null),[T,E]=(0,J.useState)(ui),[j,M]=(0,J.useState)(``),[F,I]=(0,J.useState)(new Set),[L,te]=(0,J.useState)(null),[R,B]=(0,J.useState)(!1),[V,H]=(0,J.useState)(!1),[ie,U]=(0,J.useState)(()=>a===`browse`&&Qa()!==null),[ae,W]=(0,J.useState)(null),[K,q]=(0,J.useState)(null),[oe,se]=(0,J.useState)(!1),[X,ce]=(0,J.useState)(``),[Z,Q]=(0,J.useState)(()=>a===`browse`&&Qa()||x().DEFAULT_SOURCE_TYPE),[le,ue]=(0,J.useState)(``),[de,fe]=(0,J.useState)(``),[me,he]=(0,J.useState)(null),[ge,_e]=(0,J.useState)([]),[ve,ye]=(0,J.useState)(!1),[be,xe]=(0,J.useState)(!1),[Se,Ce]=(0,J.useState)(null),[we,Te]=(0,J.useState)(null),[Ee,De]=(0,J.useState)(0),[Oe,ke]=(0,J.useState)(0),Ae=(0,J.useRef)(null),je=(0,J.useRef)(1),{view:Me,sort:Ne,dir:Pe}=T,Fe=(0,J.useCallback)(()=>W(null),[]),Ie=(0,J.useCallback)(()=>U(!1),[]),Le=(0,J.useCallback)(()=>q(null),[]),Re=(0,J.useCallback)(()=>se(!1),[]);(0,J.useEffect)(()=>di(T),[T]),(0,J.useEffect)(()=>{a===`browse`&&$a(ie?Z:null)},[a,ie,Z]);let ze=async()=>{try{let e=await l.sources();f(e.sources),_(e.cap),S(e.used)}catch{}};(0,J.useEffect)(()=>{let e=!0;return l.sources().then(t=>{e&&(f(t.sources),_(t.cap),S(t.used))}).catch(t=>{e&&Ce(He(t))}),()=>{e=!1}},[l,Ee]),(0,J.useEffect)(()=>{I(new Set),_e([]);let t=!0;return Te(null),e?l.source(e).then(e=>{t&&w(e)}).catch(e=>{t&&(w(null),Te(He(e)))}):w(null),()=>{t=!1}},[e,Oe]);let Be=async()=>{if(!e){w(null);return}try{w(await l.source(e))}catch{w(null)}},Ve=e=>{he(e),e&&window.setTimeout(()=>he(null),6e3)},He=e=>e instanceof pe?e.message:`the request failed`,Ue=yi(vi(C?.files??[],Ne,Pe),j),We=e=>{I(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Ge=()=>I(new Set(Ue.map(e=>e.name))),Ke=()=>I(new Set),qe=async e=>{try{let{trash:t}=await l.removeSource(e.id);f(t=>(t??[]).filter(t=>t.id!==e.id)),u.offer({label:`Deleted ${e.name}`,restore:()=>void(async()=>{try{await l.restoreTrash(t),await ze()}catch(e){Ve(He(e))}})()})}catch(e){Ve(He(e))}},Je=async e=>{if(C)try{let{trash:t}=await l.removeFiles(C.id,e),n=new Set(e);w(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)}),I(e=>new Set([...e].filter(e=>!n.has(e)))),u.offer({label:e.length===1?`Removed ${e[0]}`:`Removed ${e.length} files`,restore:()=>void(async()=>{try{let e=await l.restoreTrash(t);w(e.source)}catch(e){Ve(He(e))}})()})}catch(e){Ve(He(e))}},Ye=(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)},Xe=async e=>{if(!C)return;let t=e.length===1?e[0]:null;xe(!0);try{let n=t?await l.file(C.id,t):await l.zip(C.id,e);Ye(n,t??`${C.name}.zip`)}catch(e){Ve(He(e))}finally{xe(!1)}},Ze=async e=>{if(!C||C.system)return;let t=[...e];if(!t.length)return;let n=t.map(e=>({id:je.current++,file:e,state:`uploading`}));_e(e=>[...e,...n]);for(let e of n)try{await l.upload(C.id,e.file.name,e.file),_e(t=>t.map(t=>t.id===e.id?{...t,state:`done`}:t))}catch(t){_e(n=>n.map(n=>n.id===e.id?{...n,state:`error`,error:He(t)}:n))}await Be()},Qe=e=>void Ze([e.file]),$e=async(e,t)=>{if(C&&K)try{await l.copyFiles(t.id,C.id,K.names,e===`move`),q(null),I(new Set),await Be(),Ve(e===`move`?`Moved to ${t.name}.`:`Copied to ${t.name}.`)}catch(e){Ve(He(e)),q(null)}},et=async()=>{if(C&&X.trim())try{let e=await l.createSource(X.trim(),C.type);try{await l.copyFiles(e.id,C.id,[...F],!1)}catch(t){throw await l.removeSource(e.id).catch(()=>{}),t}se(!1),ce(``),I(new Set),await ze(),Ve(`Made a new Source.`)}catch(e){Ve(He(e))}},tt=async()=>{if(X.trim())try{await l.createSource(X.trim(),Z),U(!1),ce(``),Q(x().DEFAULT_SOURCE_TYPE),await ze()}catch(e){Ve(He(e))}},nt=async(e,t)=>{try{let n=await l.renameSource(e.id,t);f(t=>(t??[]).map(t=>t.id===e.id?Si(n):t)),w(e=>e?.id===n.id?{...e,name:n.name}:e)}catch(e){Ve(He(e))}},rt=(e,n=()=>te(e.id),r)=>e.system?[]:[{label:`Rename`,icon:t,onSelect:n},{label:`Delete`,icon:b,destructive:!0,onSelect:()=>void qe(e).then(r)}],at=e=>[{label:`Preview`,icon:p,disabled:!hi(e.name),onSelect:()=>W(e)},{label:`Download`,icon:g,onSelect:()=>void Xe([e.name])},...C?.system?[]:[{label:`Remove`,icon:b,destructive:!0,onSelect:()=>void Je([e.name])}]],st=[...C?.system?[]:[{label:`Remove`,icon:b,destructive:!0,onSelect:()=>void Je([...F])}],{label:`Download`,icon:g,busy:be,onSelect:()=>void Xe([...F])},...C?.system?[]:[{label:`Move to…`,icon:it,onSelect:()=>q({kind:`move`,names:[...F]})}],{label:`Copy to…`,icon:o,onSelect:()=>q({kind:`copy`,names:[...F]})},...C?.system?[]:[{label:`New Source from selection`,icon:ot,onSelect:()=>se(!0)}]],ct=e=>{e.preventDefault(),ye(!1),C&&!C.system&&Ze(e.dataTransfer.files)},lt=(d??[]).filter(e=>(!de||e.type===de)&&e.name.toLowerCase().includes(le.trim().toLowerCase())),ut=(0,$.jsx)(z,{noun:`Sources`,search:{label:`Find a Source`,value:le,placeholder:`Name`,onChange:ue},filters:[{key:`type`,label:`Type`,value:de,onChange:fe,options:[{value:``,label:`All`},...co()]}],count:{shown:lt.length,total:(d??[]).length}}),dt=()=>(0,$.jsxs)(`div`,{className:`sources`,"data-level":`sources`,children:[me&&(0,$.jsx)(`p`,{className:`note`,role:`status`,children:me}),(0,$.jsxs)(`header`,{className:`shead`,children:[(0,$.jsx)(`h2`,{className:`shead-title`,children:`Sources`}),(0,$.jsx)(to,{view:Me,onChange:e=>E(t=>({...t,view:e}))})]}),d!==null&&d.length>0&&ut,d===null?(0,$.jsx)(k,{label:`Sources`,error:Se,onRetry:()=>{Ce(null),De(e=>e+1)}}):d.length===0?(0,$.jsx)(`p`,{className:`note`,children:`No Sources on the server yet.`}):Me===`thumbs`?(0,$.jsx)(`ul`,{className:`sfolders`,children:lt.map(e=>(0,$.jsx)(`li`,{className:`sfolder`,children:(0,$.jsxs)(`button`,{type:`button`,className:`sfolder-open${c?.(e)?` off`:``}`,disabled:c?.(e),onClick:()=>s?.(e),children:[(0,$.jsx)(io,{}),(0,$.jsx)(`span`,{className:`sfolder-name`,children:e.name}),(0,$.jsxs)(`span`,{className:`sfolder-meta`,children:[lo(e),` · `,uo(e)]})]})},e.id))}):(0,$.jsx)(A,{className:`slist slist-folders`,label:`Sources`,rows:lt,rowKey:e=>e.id,columns:[{key:`name`,header:`Name`,className:`sfile-name`,sort:e=>e.name,cell:e=>(0,$.jsxs)(`button`,{type:`button`,className:`srow-pick${c?.(e)?` off`:``}`,disabled:c?.(e),onClick:()=>s?.(e),children:[(0,$.jsx)(io,{}),` `,e.name]})},{key:`type`,header:`Type`,sort:e=>lo(e),cell:e=>lo(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 dt();if(e){if(!C)return(0,$.jsx)(`div`,{className:`sources`,children:(0,$.jsx)(k,{label:`Files`,error:we,onRetry:()=>ke(e=>e+1)})});let e=Ya[C.type]?.Level,t=!e&&!C.system,a=()=>n?.(null),o=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ee,{kind:`Source`,name:C.name,crumb:{label:`Sources`,onClick:a},onPick:d?.length?()=>H(!0):void 0,meta:[lo(Si(C)),uo(Si(C)),bi(C.bytes)].join(` · `),primary:t?{label:`Upload`,icon:r,onSelect:()=>Ae.current?.click()}:void 0,actions:rt(Si(C),()=>B(!0),a)}),V&&d&&(0,$.jsx)(P,{kind:`Source`,value:C.id,onPick:e=>n?.(e),onClose:()=>H(!1),options:d.map(e=>({id:e.id,label:e.name}))}),R&&(0,$.jsx)(re,{title:`Rename Source`,value:C.name,onCommit:e=>{e&&e!==C.name&&nt(C,e)},onClose:()=>B(!1)})]});return e?(0,$.jsxs)(`div`,{className:`sources`,children:[o,(0,$.jsx)(e,{source:C,onBack:a}),(0,$.jsx)(O,{undo:u.undo,onUndo:u.undoNow,onDismiss:u.dismiss})]}):(0,$.jsxs)(`div`,{className:`sources`,"data-level":`files`,children:[o,me&&(0,$.jsx)(`p`,{className:`note`,role:`status`,children:me}),(0,$.jsxs)(`header`,{className:`shead`,children:[(0,$.jsx)(to,{view:Me,onChange:e=>E(t=>({...t,view:e}))}),(0,$.jsx)(no,{sort:Ne,dir:Pe,onChange:(e,t)=>E(n=>({...n,sort:e,dir:t}))}),(0,$.jsxs)(`label`,{className:`sfilter`,children:[(0,$.jsx)(i,{size:14,"aria-hidden":`true`}),(0,$.jsx)(`input`,{type:`search`,"aria-label":`Filter by name`,placeholder:`Filter`,value:j,onChange:e=>M(e.target.value)})]})]}),F.size>0&&(0,$.jsxs)(`div`,{className:`sselect`,"data-selected":F.size,children:[(0,$.jsxs)(`span`,{className:`sselect-count`,children:[F.size,` selected`]}),(0,$.jsx)(`button`,{type:`button`,className:`ghost`,onClick:Ge,children:`Select all`}),(0,$.jsx)(`button`,{type:`button`,className:`ghost`,onClick:Ke,children:`None`}),(0,$.jsx)(G,{label:`Selection actions`,actions:st})]}),(0,$.jsx)(`div`,{className:`sfiles${ve?` drag`:``}`,onDragOver:e=>{e.preventDefault(),ye(!0)},onDragLeave:()=>ye(!1),onDrop:ct,children:Ue.length===0?(0,$.jsx)(`p`,{className:`note`,children:j?`No files match that name.`:`No files in this Source yet.`}):Me===`thumbs`?(0,$.jsx)(`ul`,{className:`stiles`,children:Ue.map(e=>(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,className:`stile${F.has(e.name)?` sel`:``}`,"aria-pressed":F.has(e.name),"aria-label":e.name,onClick:()=>We(e.name),children:[(0,$.jsx)(eo,{id:C.id,file:e}),(0,$.jsx)(`span`,{className:`stile-name`,children:e.name}),F.has(e.name)&&(0,$.jsx)(`span`,{className:`stile-check`,children:(0,$.jsx)(v,{size:12,"aria-hidden":`true`})})]})},e.name))}):(0,$.jsx)(A,{className:`slist`,label:`${C.name} files`,rows:Ue,rowKey:e=>e.name,rowProps:e=>({className:F.has(e.name)?`sel`:void 0,"data-selected":F.has(e.name)||void 0,onClick:()=>We(e.name)}),columns:[{key:`name`,header:`Name`,className:`sfile-name`,cell:e=>e.name},{key:`type`,header:`Type`,className:`stype`,cell:e=>ro(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,$.jsx)(G,{label:`${e.name} actions`,actions:at(e)})}]})}),t&&(0,$.jsxs)(`div`,{className:`supload`,children:[(0,$.jsx)(`input`,{ref:Ae,type:`file`,multiple:!0,hidden:!0,"aria-hidden":`true`,accept:x().sourceTypeOf(C)?.uploads?.join(`,`),onChange:e=>{e.target.files&&Ze(e.target.files),e.target.value=``}}),ge.length>0&&(0,$.jsx)(`ul`,{className:`suploads`,children:ge.map(e=>(0,$.jsxs)(`li`,{className:`supload ${e.state}`,children:[(0,$.jsx)(`span`,{className:`supload-name`,children:e.file.name}),e.state===`uploading`&&(0,$.jsx)(`span`,{className:`supload-bar`,role:`status`,children:`Uploading…`}),e.state===`done`&&(0,$.jsx)(`span`,{className:`note`,children:`Uploaded`}),e.state===`error`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`note bad`,children:e.error}),(0,$.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>Qe(e),children:`Retry`})]})]},e.id))})]}),ae&&(0,$.jsxs)(D,{title:ae.name,onClose:Fe,children:[hi(ae.name)?(0,$.jsx)(`img`,{className:`spreview-img`,src:_i(C.id,ae),alt:ae.name}):null,(0,$.jsx)(`p`,{className:`note`,children:bi(ae.bytes)})]}),K&&(0,$.jsx)(D,{title:K.kind===`move`?`Move to…`:`Copy to…`,onClose:Le,children:(0,$.jsx)(Xa,{mode:`pick`,disabled:e=>e.id===C.id||e.system||e.type!==C.type,onPick:e=>void $e(K.kind,e)})}),oe&&(0,$.jsxs)(D,{title:`New Source from selection`,onClose:Re,children:[(0,$.jsxs)(`label`,{className:`prompt`,children:[(0,$.jsx)(`span`,{className:`prop-name`,children:`Name`}),(0,$.jsx)(`input`,{"aria-label":`New Source name`,value:X,autoFocus:!0,onChange:e=>ce(e.target.value),onKeyDown:e=>{e.key===`Enter`&&et()}})]}),(0,$.jsxs)(`div`,{className:`sacts`,children:[(0,$.jsx)(`button`,{type:`button`,className:`ghost`,disabled:!X.trim(),onClick:()=>void et(),children:`Make`}),(0,$.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>se(!1),children:`Close`})]})]}),(0,$.jsx)(O,{undo:u.undo,onUndo:u.undoNow,onDismiss:u.dismiss})]})}return(0,$.jsxs)(`div`,{className:`sources`,"data-level":`sources`,children:[me&&(0,$.jsx)(`p`,{className:`note`,role:`status`,children:me}),(0,$.jsxs)(`header`,{className:`shead`,children:[(0,$.jsx)(`h2`,{className:`shead-title`,children:`Sources`}),(0,$.jsxs)(`p`,{className:`note suste`,children:[`Used `,bi(y),` of `,bi(m)]}),(0,$.jsx)(to,{view:Me,onChange:e=>E(t=>({...t,view:e}))})]}),d!==null&&d.length>0&&ut,d===null?(0,$.jsx)(k,{label:`Sources`,error:Se,onRetry:()=>{Ce(null),De(e=>e+1)}}):d.length===0?(0,$.jsx)(`p`,{className:`note`,children:`No Sources yet — Add source below.`}):Me===`thumbs`?(0,$.jsx)(`ul`,{className:`sfolders`,children:lt.map(e=>(0,$.jsxs)(`li`,{className:`sfolder`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`sfolder-open`,onClick:()=>n?.(e.id),children:[(0,$.jsx)(io,{}),(0,$.jsx)(`span`,{className:`sfolder-name`,children:e.name}),(0,$.jsxs)(`span`,{className:`sfolder-meta`,children:[lo(e),` · `,uo(e)]}),(0,$.jsx)(so,{source:e,cap:m,children:e.system?(0,$.jsx)(`span`,{className:`squota-none`,children:`—`}):(0,$.jsx)(`span`,{className:`squota-bar`,children:(0,$.jsx)(`span`,{className:`squota-fill`,style:{width:`${ao(e.bytes,m)}%`}})})})]}),(0,$.jsx)(`span`,{className:`sfolder-menu`,children:(0,$.jsx)(G,{label:`${e.name} actions`,actions:rt(e)})})]},e.id))}):(0,$.jsx)(`div`,{className:`sfiles`,children:(0,$.jsx)(A,{className:`slist slist-folders`,label:`Sources`,rows:lt,rowKey:e=>e.id,rowProps:e=>({"data-open":e.id,onClick:()=>n?.(e.id)}),columns:[{key:`name`,header:`Name`,className:`sfile-name`,sort:e=>e.name,cell:e=>(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(io,{}),` `,e.name]})},{key:`type`,header:`Type`,sort:e=>lo(e),cell:e=>lo(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,$.jsx)(so,{source:e,cap:m,children:e.system?`—`:`${ao(e.bytes,m)}%`})},{key:`menu`,header:``,className:`s-actions`,sort:null,tdProps:()=>({onClick:e=>e.stopPropagation()}),cell:e=>(0,$.jsx)(G,{label:`${e.name} actions`,actions:rt(e)})}]})}),L&&d&&(()=>{let e=d.find(e=>e.id===L);return e?(0,$.jsxs)(`label`,{className:`srename`,children:[(0,$.jsxs)(`span`,{className:`prop-name`,children:[`Rename `,e.name]}),(0,$.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&&nt(e,n),te(null)}t.key===`Escape`&&te(null)},onBlur:t=>{let n=t.target.value.trim();n&&n!==e.name&&nt(e,n),te(null)}})]}):null})(),(0,$.jsxs)(`button`,{type:`button`,className:`ghost add-btn`,onClick:()=>U(!0),children:[(0,$.jsx)(h,{size:14,"aria-hidden":`true`}),` Add source`]}),ie&&(0,$.jsxs)(D,{title:`Add source`,onClose:Ie,children:[(0,$.jsx)(N,{label:`New Source`,rows:[{key:`type`,label:`Type`,hint:x().SOURCE_TYPES[Z]?.description,control:{type:`select`,value:Z,options:co(),onChange:Q}}]}),(()=>{let e=Ya[Z]?.Create,t=(0,$.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>U(!1),children:`Close`});return e?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(e,{onMade:async()=>{U(!1),Q(x().DEFAULT_SOURCE_TYPE),await ze()}}),(0,$.jsx)(`div`,{className:`sacts`,children:t})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`label`,{className:`prompt`,children:[(0,$.jsx)(`span`,{className:`prop-name`,children:`Name`}),(0,$.jsx)(`input`,{"aria-label":`Source name`,value:X,autoFocus:!0,onChange:e=>ce(e.target.value),onKeyDown:e=>{e.key===`Enter`&&tt()}})]}),(0,$.jsxs)(`div`,{className:`sacts`,children:[(0,$.jsx)(`button`,{type:`button`,className:`ghost`,disabled:!X.trim(),onClick:()=>void tt(),children:`Add`}),t]})]})})()]}),(0,$.jsx)(O,{undo:u.undo,onUndo:u.undoNow,onDismiss:u.dismiss})]})}var Za=`evals-lab.sources.adding`;function Qa(){try{return sessionStorage.getItem(Za)}catch{return null}}function $a(e){try{e?sessionStorage.setItem(Za,e):sessionStorage.removeItem(Za)}catch{}}function eo({id:e,file:t}){let[n,r]=(0,J.useState)(!1);return!t.thumb||n?(0,$.jsx)(`span`,{className:`stile-type`,children:ro(t.name)||`FILE`}):(0,$.jsx)(`img`,{className:`stile-img`,src:gi(e,t),alt:``,loading:`lazy`,onError:()=>r(!0)})}function to({view:e,onChange:t}){return(0,$.jsxs)(`div`,{className:`sview`,role:`group`,"aria-label":`View`,children:[(0,$.jsx)(`button`,{type:`button`,className:e===`thumbs`?`on`:void 0,"aria-pressed":e===`thumbs`,onClick:()=>t(`thumbs`),children:`Thumbnails`}),(0,$.jsx)(`button`,{type:`button`,className:e===`list`?`on`:void 0,"aria-pressed":e===`list`,onClick:()=>t(`list`),children:`List`})]})}function no({sort:e,dir:t,onChange:r}){return(0,$.jsxs)(`div`,{className:`ssort`,role:`group`,"aria-label":`Sort`,children:[(0,$.jsxs)(`select`,{"aria-label":`Sort by`,value:e,onChange:e=>r(e.target.value,t),children:[(0,$.jsx)(`option`,{value:`name`,children:`Name`}),(0,$.jsx)(`option`,{value:`added`,children:`Date added`}),(0,$.jsx)(`option`,{value:`size`,children:`Size`})]}),(0,$.jsx)(`button`,{type:`button`,className:`icon-btn`,"aria-label":`Sort ${t===1?`ascending`:`descending`}`,onClick:()=>r(e,t===1?-1:1),children:(0,$.jsx)(t===1?K:n,{size:14,"aria-hidden":`true`})})]})}function ro(e){let t=e.lastIndexOf(`.`);return t<0?``:e.slice(t+1).toUpperCase()}function io(){return(0,$.jsx)(st,{size:16,"aria-hidden":`true`})}function ao(e,t){return t<=0?0:Math.max(0,Math.min(100,Math.round(e/t*100)))}function oo(e,t){return e.system?`Quota: not counted`:`Quota: ${bi(e.bytes)} of ${bi(t)}`}function so({source:e,cap:t,children:n}){let r=oo(e,t);return(0,$.jsxs)(`span`,{className:`squota`,role:`img`,"aria-label":r,children:[n,(0,$.jsx)(`span`,{className:`squota-pop`,"aria-hidden":`true`,children:r})]})}var co=()=>Object.entries(x().SOURCE_TYPES).map(([e,t])=>({value:e,label:t.label})),lo=e=>x().SOURCE_TYPES[e.type]?.label??e.type,uo=e=>{let t=x().sourceTypeOf(e)?.noun??`item`;return`${e.files} ${e.files===1?t:`${t}s`}`};function fo({sourceId:e}){let[t,n]=(0,J.useState)(e);return(0,J.useEffect)(()=>n(e),[e]),(0,$.jsx)(Xa,{sourceId:t,onOpen:e=>{n(e),e?location.hash=`/library/sources/${encodeURIComponent(e)}`:location.hash=`#/library/sources`}})}var po=[{id:`datasets`,label:`Datasets`,icon:Qe},{id:`prompts`,label:`Prompts`,icon:pt},{id:`sources`,label:`Sources`,icon:at}];function mo({section:e,sourceId:t}){return(0,$.jsxs)(`div`,{className:`library`,children:[(0,$.jsx)(`nav`,{className:`lib-sections`,"aria-label":`Library`,children:po.map(({id:t,label:n,icon:r})=>(0,$.jsxs)(`a`,{href:`#/library/${t}`,...t===e?{"aria-current":`page`}:{},className:t===e?`on`:void 0,children:[(0,$.jsx)(r,{size:16,"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:n})]},t))}),(0,$.jsx)(`section`,{className:`lib-section`,"data-section":e,children:e===`datasets`?(0,$.jsx)(Xr,{}):e===`prompts`?(0,$.jsx)(si,{}):(0,$.jsx)(fo,{sourceId:t})})]})}var ho=`0.4.0 (2026.10.02-361)`,go=3,_o=3,vo=e=>mr.find(t=>t.id===e),yo=e=>po.find(t=>t.id===e),bo=e=>new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`});function xo(){let e=Y(),[t]=_e(`promptlab.profiles`),[n,r]=_e(`promptlab.workflows`),i=Ie(),a=Ke(),{pickDataset:o}=Gt(),{openRun:s}=Jt(),c=Fe(),l=Ge(),[u,d]=(0,J.useState)(null),[f,p]=(0,J.useState)(null),[m,h]=(0,J.useState)(null),[g,_]=(0,J.useState)(null),[v,y]=(0,J.useState)(0),[b,x]=(0,J.useState)(0),S=e=>e instanceof Error?e.message:String(e);(0,J.useEffect)(()=>{let t=!0;return h(null),e.sources().then(e=>{t&&d(e.sources)},e=>{t&&h(S(e))}),()=>{t=!1}},[e,v]),(0,J.useEffect)(()=>{let t=!0;return _(null),e.queue({limit:_o}).then(e=>{t&&p(e.runs)},e=>{t&&_(S(e))}),()=>{t=!1}},[e,b]);let C=(0,J.useMemo)(()=>n.list.filter(e=>e.work?.version===12),[n.list]),w=i.list??[],T=w.reduce((e,t)=>e+t.cases,0),E=(f??[]).filter(e=>e.status===`queued`||e.status===`running`).length,D=t.list.length===0?`setup`:i.list===null?null:w.length===0||T===0?`datasets`:f!==null&&f.length===0?`runs`:null,O=(...e)=>e.filter(Boolean).join(` · `)||void 0,k=vo(`library`),A=k.icon;return(0,$.jsxs)(`div`,{className:`home`,children:[(0,$.jsxs)(`ol`,{className:`home-line`,"aria-label":`Lab`,children:[(0,$.jsx)(So,{id:`runs`,icon:vo(`runs`).icon,name:vo(`runs`).label,hub:!0,start:D===`runs`,fact:O(dn(C.length,`pipeline`),E>0&&`${E} running`),total:C.length,items:C.map(e=>({key:e.id,label:e.name,href:`#/runs`,onPick:()=>r({...n,at:e.id})}))}),(0,$.jsx)(So,{id:`history`,icon:vo(`history`).icon,name:vo(`history`).label,fact:f&&f.length===0?`No runs yet`:void 0,wait:f?void 0:{error:g,onRetry:()=>x(e=>e+1)},items:(f??[]).map(e=>{let t=Wn(e).scenarios.map(e=>e.percent==null?`–`:`${e.percent}%`).join(` · `);return{key:e.id,label:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`code`,{children:un(e.submittedAt)}),e.status!==`done`&&_n(e.status)]}),sub:O(bo(e.submittedAt),!!t&&t),href:`#/history`,onOpen:()=>s(e.id,{at:e.submittedAt,from:`home`})}})}),(0,$.jsxs)(`li`,{className:`home-stop home-fork`,"data-stop":`library`,children:[(0,$.jsxs)(`a`,{className:`home-name`,href:`#/library`,children:[(0,$.jsx)(`span`,{className:`home-mark`,"aria-hidden":`true`,children:(0,$.jsx)(A,{size:18})}),k.label]}),(0,$.jsxs)(`ol`,{className:`home-branch`,"aria-label":k.label,children:[(0,$.jsx)(So,{id:`datasets`,to:`library/datasets`,branch:!0,icon:yo(`datasets`).icon,name:yo(`datasets`).label,start:D===`datasets`,fact:i.list?O(dn(w.length,`dataset`),dn(T,`case`)):void 0,total:w.length,wait:i.list?void 0:{error:i.error,onRetry:()=>void c.refresh()},items:w.map(e=>({key:e.id,label:e.name,sub:dn(e.cases,`case`),href:`#/library/datasets`,onPick:()=>o(e.id)}))}),(0,$.jsx)(So,{id:`prompts`,to:`library/prompts`,branch:!0,icon:yo(`prompts`).icon,name:yo(`prompts`).label,fact:a.list?O(dn(a.list.length,`prompt`)):void 0,total:a.list?.length??0,wait:a.list?void 0:{error:a.error,onRetry:()=>void l.refresh()},items:(a.list??[]).map(e=>({key:e.id,label:e.name||e.text.split(`
9
+ `)}]:[]],f=Ca(o,r),p=i.withOut({type:`job`,id:i.newId(),name:n.name,steps:[{type:`attachContent`,content:{type:`source`,ref:e,first:null,loops:1}},{type:`flowStep`,step:n.name,loop:n.loops.at(-1)??null,api:s},...l?.expression?[{type:`readAs`,readAs:l.expression}]:[]]},{kind:`text`,...i.OUTPUT_KINDS.text?.settingDefaults?.()??{},modifiers:i.OUTPUT_KINDS.text?.modifiers?.()??[]});return{version:i.PIPELINE_VERSION,id:i.newId(),name:`${e.name} · ${n.name}`,jobs:[p],targets:[{id:i.newId(),name:`Production`,profile:f,steps:[structuredClone(c)]},{id:i.newId(),name:`Edited`,profile:f,steps:[structuredClone(c)]}],evals:d.length?[i.newEval(`metrics`,``,{metrics:d})]:[]}}function Ta(e,t){let n=e.result;if(!n||!(`status`in n))return null;let r=la(t).find(t=>t.name===e.step);if(!r)return null;let i=String(r.template.uri??``),a={step:r.name,loop:r.loops.at(-1)??null,api:x().httpApiFor(i),readAs:ba(t,r.name)?.expression??null};try{return x().httpReplyOf(a,{prompt:``},n.body,n.status,{scope:e.scope,now:e.at}).raw}catch{return null}}function Ea(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 Da(e,t){let n=[],r=0;for(let{name:i,record:a}of e){let e=Ta(a,t);if(e==null){r++;continue}let o=ba(t,a.step),s=o?xa(t,o.name):[];n.push({id:i.replace(/\.json$/i,``).replace(/[^A-Za-z0-9._-]/g,`_`),item:i,todo:!0,note:``,metrics:Ea(e,s)})}return{cases:n,skipped:r}}async function Oa(e,t,n,r,i){let a=await e.run(t,n,r),o=ua(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 ka(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 Oa(e,t,n,o,a);for(let e of await r.callsOf(i)){let t=Di(await da(i,e,r,a)).value,n=aa(t);if(c.has(n)){u++;continue}c.add(n),l.push(t)}s?.(++d)}return{records:l,skipped:u}}var Aa=e=>e.name.toLowerCase().endsWith(`.json`),ja=e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result)),r.onerror=()=>n(r.error),r.readAsText(e)}),Ma=`evals-lab.flow.importing`;function Na(e){try{return sessionStorage.getItem(e)}catch{return null}}function Pa(e,t){try{t?sessionStorage.setItem(e,t):sessionStorage.removeItem(e)}catch{}}var Fa=e=>e instanceof Error?e.message:String(e);function Ia({source:e,definition:t,cfg:n}){let i=Y(),a=Fe(),o=ne(),[s,c]=(0,J.useState)(e.files.filter(Aa)),[l,u]=(0,J.useState)({}),[d,f]=(0,J.useState)(null),[m,_]=(0,J.useState)(()=>{let t=Na(Ma)===e.id;return t&&Pa(Ma,null),t?`import`:null}),[v,y]=(0,J.useState)(null),x=(0,J.useMemo)(()=>la(t),[t]),[S,C]=(0,J.useState)(!1),[w,T]=(0,J.useState)(null),E=(0,J.useCallback)(async()=>{let t=(await i.source(e.id)).files.filter(Aa);c(t);let n=await Promise.all(t.map(async t=>{try{return[t.name,JSON.parse(await ja(await i.file(e.id,t.name)))]}catch{return[t.name,null]}}));u(Object.fromEntries(n))},[i,e.id]),j=(0,J.useCallback)(()=>{T(null),E().then(()=>C(!0),e=>T(Fa(e)))},[E]);(0,J.useEffect)(j,[j]);let M=e=>{let n=l[e],r=n?x.find(e=>e.name===n.step):void 0;return n&&r?_a(r,n,t):null},N=(0,J.useMemo)(()=>new Set(s.flatMap(e=>l[e.name]?[aa(l[e.name])]:[])),[s,l]),P=async(t,n=0)=>{let r=0,a=[];for(let n of t)try{await i.upload(e.id,fa(n),new Blob([JSON.stringify(n,null,2)],{type:`application/json`})),r++}catch(e){a.push(e instanceof pe?e.message:Fa(e))}await E(),f([`Added ${r}`,n?`Skipped ${n}`:``,a.length?`Refused ${a.length}: ${a[0]}`:``].filter(Boolean).join(` · `))},ee=async()=>{let{cases:n,skipped:r}=Da(s.flatMap(e=>l[e.name]?[{name:e.name,record:l[e.name]}]:[]),t);if(!n.length)return f(`No record holds a production reply.`);try{let t=await a.create(`${e.name} · production`,{...be(),source:{id:e.id,name:e.name},cases:n});f([`Made ${t.name}: ${n.length} ${n.length===1?`case`:`cases`}`,r?`Skipped ${r}`:``].filter(Boolean).join(` · `))}catch(e){f(Fa(e))}},F=async t=>{try{let{trash:n}=await i.removeFiles(e.id,t);c(e=>e.filter(e=>!t.includes(e.name))),o.offer({label:`Removed ${t[0]}`,restore:()=>void i.restoreTrash(n).then(E,e=>f(Fa(e)))})}catch(e){f(Fa(e))}},L=async t=>{let n=URL.createObjectURL(await i.file(e.id,t)),r=document.createElement(`a`);r.href=n,r.download=t,document.body.append(r),r.click(),r.remove(),URL.revokeObjectURL(n)},te=e=>[{label:`View`,icon:p,onSelect:()=>y(e.name)},{label:`Download`,icon:g,onSelect:()=>void L(e.name).catch(e=>f(Fa(e)))},{label:`Remove`,icon:b,destructive:!0,onSelect:()=>void F([e.name])}],R=(0,J.useCallback)(()=>_(null),[]),z=(0,J.useCallback)(()=>y(null),[]),B=v?l[v]:null;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(U,{id:`flow-records`,title:`Records`,note:String(s.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:I,disabled:!x.length||!n,onSelect:()=>_(`import`)},{label:`Upload`,icon:r,disabled:!x.length,onSelect:()=>_(`upload`)},{label:`New dataset`,icon:Qe,disabled:!s.length,onSelect:()=>void ee()}],children:[d&&(0,$.jsx)(`p`,{className:`note`,role:`status`,children:d}),S?s.length?(0,$.jsx)(`div`,{className:`sflow`,children:(0,$.jsx)(A,{className:`slist`,label:`Records`,rows:s,rowKey:e=>e.name,columns:[{key:`name`,header:`Name`,sort:e=>e.name,cell:e=>(0,$.jsxs)($.Fragment,{children:[e.name,(0,$.jsx)(`span`,{className:`sflow-in`,children:za(l[e.name])})]})},{key:`result`,header:`Result`,sort:e=>Ba(l[e.name]),cell:e=>Ba(l[e.name])},{key:`request`,header:`Request`,sort:e=>La(M(e.name)),tdProps:e=>{let t=M(e.name);return t&&t.match===!1?{title:t.where}:{}},cell:e=>La(M(e.name))},{key:`menu`,header:``,className:`s-actions`,sort:null,cell:e=>(0,$.jsx)(G,{label:`${e.name} actions`,actions:te(e)})}]})}):(0,$.jsx)(`p`,{className:`note`,children:`No records yet. Import runs, in this group's menu, reads them from the flow's run history.`}):(0,$.jsx)(k,{label:`Records`,error:w,onRetry:j}),(0,$.jsxs)(`button`,{type:`button`,className:`ghost add-btn`,disabled:!x.length,onClick:()=>_(`hand`),children:[(0,$.jsx)(h,{size:14,"aria-hidden":`true`}),` Add record`]})]}),m===`import`&&n&&(0,$.jsx)(Ua,{cfg:n,source:e,steps:x,definition:t,held:N,onClose:R,onRead:async(e,t)=>{_(null),await P(e,t)}}),m===`hand`&&(0,$.jsx)(Wa,{steps:x,onClose:R,onAdd:async e=>{_(null),await P([e])}}),m===`upload`&&(0,$.jsx)(Ka,{steps:x,onClose:R,onRead:async e=>{_(null),await P(e)}}),v&&(0,$.jsx)(D,{title:v,onClose:z,wide:!0,children:(0,$.jsx)(`pre`,{className:`pl-words`,children:B?JSON.stringify(B,null,2):`Unreadable.`})}),(0,$.jsx)(O,{undo:o.undo,onUndo:o.undoNow,onDismiss:o.dismiss})]})}var La=e=>!e||e.match===null?`—`:e.match?`Match`:`Differs`,Ra={run:`Run`,hand:`Hand`,upload:`Upload`},za=e=>e?[e.step,Ra[e.origin.kind]??e.origin.kind,e.at?xi(Date.parse(e.at)/1e3):``].filter(Boolean).join(` · `):`Unreadable`;function Ba(e){let t=e?.result;return t?`error`in t?t.error.code||`Error`:String(t.status):`—`}var Va=e=>e.map(e=>({value:e.name,label:e.name})),Ha=e=>e.from===`trigger`?`Trigger body`:pa(e);function Ua({cfg:e,source:t,steps:n,definition:r,held:i,onClose:a,onRead:o}){let s=(0,J.useMemo)(()=>Xi(e),[e]),c=t.config??{},[l,u]=(0,J.useState)(void 0),[d,f]=(0,J.useState)(n[0]?.name??``),[p,m]=(0,J.useState)(null),[h,g]=(0,J.useState)(``),[_,v]=(0,J.useState)(new Set),[y,b]=(0,J.useState)(``),[x,S]=(0,J.useState)(null),[C,w]=(0,J.useState)(null),[T,E]=(0,J.useState)(null),[O,j]=(0,J.useState)(0);(0,J.useEffect)(()=>{zi(e).then(u,()=>u(null))},[e]),(0,J.useEffect)(()=>{l&&c.environment&&c.flow&&(E(null),s.runs(c.environment,c.flow).then(m,e=>E(Fa(e))))},[l,s,c.environment,c.flow,O]);let M=(0,J.useMemo)(()=>[...new Set((p??[]).map(e=>e.status))].sort(),[p]),P=(0,J.useMemo)(()=>(p??[]).filter(e=>!h||e.status===h),[p,h]),ee=e=>v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),F=P.length>0&&P.every(e=>_.has(e.id)),I=P.filter(e=>_.has(e.id)).map(e=>e.id),L=async()=>{let e=n.find(e=>e.name===d);if(!e||!c.environment||!c.flow)return;let t=I;w(null),S(`Reading 0 of ${t.length}`);try{let{records:n,skipped:a}=await ka(s,c.environment,c.flow,t,e,r,i,e=>S(`Reading ${e} of ${t.length}`));await o(n,a)}catch(e){w(Fa(e)),S(null)}};return(0,$.jsxs)(D,{title:`Import runs`,onClose:a,wide:!0,footer:(0,$.jsxs)(`div`,{className:`sacts`,children:[x&&(0,$.jsx)(`span`,{className:`note`,role:`status`,children:x}),(0,$.jsxs)(`button`,{type:`button`,className:`ghost`,disabled:!!x||!I.length||!d,"aria-busy":!!x||void 0,onClick:()=>void L(),children:[x&&(0,$.jsx)(W,{}),`Import `,I.length||``]})]}),children:[l===void 0?(0,$.jsx)(k,{label:`Account`}):l?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{label:`Import`,rows:[{key:`step`,label:`Step`,control:{type:`select`,value:d,options:Va(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(P.slice(0,t).map(e=>e.id)))}}}]}),p?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(z,{noun:`runs`,count:{shown:P.length,total:p.length},lead:(0,$.jsx)(`input`,{type:`checkbox`,"aria-label":`Select all shown`,checked:F,disabled:!P.length,onChange:()=>v(F?new Set:new Set(P.map(e=>e.id)))}),filters:[{key:`status`,label:`Status`,value:h,onChange:g,options:[{value:``,label:`All`},...M.map(e=>({value:e,label:e}))]}]}),P.length?(0,$.jsx)(`div`,{className:`sflow`,children:(0,$.jsx)(A,{className:`slist`,label:`Runs`,rows:P,rowKey:e=>e.id,pageSize:20,rowProps:e=>({onClick:()=>ee(e.id),"data-selected":_.has(e.id)||void 0}),columns:[{key:`pick`,header:``,sort:null,cell:e=>(0,$.jsx)(`input`,{type:`checkbox`,"aria-label":`Run ${e.id}`,checked:_.has(e.id),onChange:()=>ee(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,$.jsx)(`p`,{className:`note`,children:`No runs.`})]}):(0,$.jsx)(k,{label:`Runs`,error:T,onRetry:()=>j(e=>e+1)})]}):(0,$.jsx)(`div`,{className:`sacts`,children:(0,$.jsxs)(`button`,{type:`button`,className:`ghost`,onClick:()=>{Pa(Ma,t.id),Ui(e).catch(e=>{Pa(Ma,null),w(Fa(e))})},children:[(0,$.jsx)(dt,{size:14,"aria-hidden":`true`}),` Sign in with Microsoft`]})}),C&&(0,$.jsx)(`p`,{className:`note bad`,role:`alert`,children:C})]})}function Wa({steps:e,onClose:t,onAdd:n}){let[r,i]=(0,J.useState)(e[0]?.name??``),[a,o]=(0,J.useState)({}),s=e.find(e=>e.name===r),c=(s?.reads??[]).filter(e=>pa(e));return(0,$.jsxs)(D,{title:`Add record`,onClose:t,wide:!0,footer:(0,$.jsx)(`div`,{className:`sacts`,children:(0,$.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=>pa(t)===e))),[t]=ha(s,[e]).records;n({...t,origin:{kind:`hand`}})},children:`Add`})}),children:[(0,$.jsx)(N,{label:`Record`,rows:[{key:`step`,label:`Step`,control:{type:`select`,value:r,options:Va(e),onChange:e=>{i(e),o({})}}},...c.map(e=>({key:`read-${pa(e)}`,label:Ha(e),control:{type:`textarea`,value:a[pa(e)]??``,onChange:t=>o(n=>({...n,[pa(e)]:t}))}}))]}),s&&!c.length&&(0,$.jsx)(`p`,{className:`note`,children:`Reads nothing.`})]})}function Ga(e,t){if(e.toLowerCase().endsWith(`.csv`))return{rows:ga(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 Ka({steps:e,onClose:t,onRead:n}){let i=(0,J.useRef)(null),[a,o]=(0,J.useState)(e[0]?.name??``),[s,c]=(0,J.useState)(null),[l,u]=(0,J.useState)(null),d=e.find(e=>e.name===a),f=s&&d&&`rows`in s.parsed?ha(d,s.parsed.rows):null,p=s?`records`in s.parsed?s.parsed.records:f?.records??[]:[],m=async e=>{if(e){u(null);try{c({name:e.name,parsed:Ga(e.name,await ja(e))})}catch(t){c(null),u(`${e.name}: ${Fa(t)}`)}}};return(0,$.jsxs)(D,{title:`Upload`,onClose:t,wide:!0,footer:(0,$.jsx)(`div`,{className:`sacts`,children:(0,$.jsxs)(`button`,{type:`button`,className:`ghost`,disabled:!p.length,onClick:()=>void n(p),children:[`Add `,p.length||``]})}),children:[(0,$.jsx)(N,{label:`Upload`,rows:[...s&&`records`in s.parsed?[]:[{key:`step`,label:`Step`,control:{type:`select`,value:a,options:Va(e),onChange:o}}],{key:`file`,label:`File`,control:{type:`static`,text:s?.name??`—`}},...s?[{key:`count`,label:`records`in s.parsed?`Records`:`Rows`,control:{type:`static`,text:String(p.length)}}]:[],...f?.unmatched.length?[{key:`unmatched`,label:`Unmatched`,control:{type:`static`,text:f.unmatched.join(`, `)}}]:[]]}),(0,$.jsxs)(`div`,{className:`sacts`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`ghost`,onClick:()=>i.current?.click(),children:[(0,$.jsx)(r,{size:14,"aria-hidden":`true`}),` Choose file`]}),(0,$.jsx)(`input`,{ref:i,type:`file`,accept:`.json,.csv`,hidden:!0,"aria-hidden":`true`,onChange:e=>{m(e.target.files?.[0]),e.target.value=``}})]}),l&&(0,$.jsx)(`p`,{className:`note bad`,role:`alert`,children:l})]})}function qa({source:e}){let t=Y(),n=Yi(),[r,i]=(0,J.useState)(null),[a,o]=(0,J.useState)(null),[s,c]=(0,J.useState)(!1),[l,u]=(0,J.useState)(null),d=e.config??{},f=(0,J.useCallback)(()=>{u(null),t.definition(e.id).then(i,e=>{i(null),u(e instanceof Error?e.message:String(e))})},[t,e.id]);(0,J.useEffect)(f,[f]);let p=async()=>{if(n&&r&&d.environment&&d.flow){c(!0),o(null);try{if(!await zi(n)){await Ui(n);return}let a=await Zi(Xi(n),d.environment,d.flow);i(await t.saveDefinition(e.id,r.version,a.definition)),o(`Synced.`)}catch(e){e instanceof pe&&e.status===409?(f(),o(`It changed since: reloaded.`)):o(e instanceof Error?e.message:String(e))}finally{c(!1)}}},m=(0,J.useMemo)(()=>Ja(r?.body),[r]),h=(0,J.useMemo)(()=>la(r?.body),[r]),[g,_]=_e(`promptlab.workflows`),[v]=_e(`promptlab.profiles`),y=t=>{let n=h.find(e=>e.name===t);if(!n||!r)return;let i=wa({id:e.id,name:e.name},r.body,n,v.list),a={id:i.id,name:i.name,work:i};_({...g,list:[...g.list,a],at:a.id}),location.hash=`#/runs`};return(0,$.jsxs)(`div`,{className:`sources`,"data-level":`flow`,children:[a&&(0,$.jsx)(`p`,{className:`note`,role:`status`,children:a}),(0,$.jsxs)(U,{id:`flow-source`,title:`Flow`,note:d.displayName,actions:[{label:`Re-sync`,icon:_t,busy:s,disabled:!n||!r,onSelect:()=>void p()}],children:[(0,$.jsx)(N,{label:`Flow`,rows:[{key:`flow`,label:`Flow`,control:{type:`static`,text:d.displayName||d.flow||`—`}},{key:`env`,label:`Environment`,control:{type:`static`,text:d.environment||`—`}},...r?[{key:`version`,label:`Definition`,control:{type:`static`,text:r.version?`Version ${r.version}${r.at?` · ${xi(Date.parse(r.at)/1e3)}`:``}`:`None`}}]:[]]}),!r&&(0,$.jsx)(k,{label:`Definition`,error:l,onRetry:f})]}),(0,$.jsx)(Ia,{source:e,definition:r?.body??null,cfg:n}),(0,$.jsx)(U,{id:`flow-actions`,title:`Actions`,note:r?String(m.length):void 0,children:r?m.length?(0,$.jsx)(`div`,{className:`sflow`,children:(0,$.jsx)(A,{className:`slist`,label:`Actions`,rows:m,rowKey:e=>e.name,columns:[{key:`name`,header:`Name`,sort:e=>e.name,cell:e=>(0,$.jsxs)($.Fragment,{children:[e.name,e.in&&(0,$.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=>h.some(t=>t.name===e.name)?(0,$.jsx)(G,{label:`${e.name} actions`,actions:[{label:`New pipeline`,icon:gt,onSelect:()=>y(e.name)}]}):null}]})}):(0,$.jsx)(`p`,{className:`note`,children:`No actions.`}):(0,$.jsx)(k,{label:`Actions`,error:l,onRetry:f})})]})}function Ja(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 Ya={"power-automate":{Create:Qi,Level:qa}};function Xa({sourceId:e=null,onOpen:n,mode:a=`browse`,onPick:s,disabled:c}){let l=Y(),u=ne(),[d,f]=(0,J.useState)(null),[m,_]=(0,J.useState)(0),[y,S]=(0,J.useState)(0),[C,w]=(0,J.useState)(null),[T,E]=(0,J.useState)(ui),[j,M]=(0,J.useState)(``),[F,I]=(0,J.useState)(new Set),[L,te]=(0,J.useState)(null),[R,B]=(0,J.useState)(!1),[V,H]=(0,J.useState)(!1),[ie,U]=(0,J.useState)(()=>a===`browse`&&Qa()!==null),[ae,W]=(0,J.useState)(null),[K,q]=(0,J.useState)(null),[oe,se]=(0,J.useState)(!1),[X,ce]=(0,J.useState)(``),[Z,Q]=(0,J.useState)(()=>a===`browse`&&Qa()||x().DEFAULT_SOURCE_TYPE),[le,ue]=(0,J.useState)(``),[de,fe]=(0,J.useState)(``),[me,he]=(0,J.useState)(null),[ge,_e]=(0,J.useState)([]),[ve,ye]=(0,J.useState)(!1),[be,xe]=(0,J.useState)(!1),[Se,Ce]=(0,J.useState)(null),[we,Te]=(0,J.useState)(null),[Ee,De]=(0,J.useState)(0),[Oe,ke]=(0,J.useState)(0),Ae=(0,J.useRef)(null),je=(0,J.useRef)(1),{view:Me,sort:Ne,dir:Pe}=T,Fe=(0,J.useCallback)(()=>W(null),[]),Ie=(0,J.useCallback)(()=>U(!1),[]),Le=(0,J.useCallback)(()=>q(null),[]),Re=(0,J.useCallback)(()=>se(!1),[]);(0,J.useEffect)(()=>di(T),[T]),(0,J.useEffect)(()=>{a===`browse`&&$a(ie?Z:null)},[a,ie,Z]);let ze=async()=>{try{let e=await l.sources();f(e.sources),_(e.cap),S(e.used)}catch{}};(0,J.useEffect)(()=>{let e=!0;return l.sources().then(t=>{e&&(f(t.sources),_(t.cap),S(t.used))}).catch(t=>{e&&Ce(He(t))}),()=>{e=!1}},[l,Ee]),(0,J.useEffect)(()=>{I(new Set),_e([]);let t=!0;return Te(null),e?l.source(e).then(e=>{t&&w(e)}).catch(e=>{t&&(w(null),Te(He(e)))}):w(null),()=>{t=!1}},[e,Oe]);let Be=async()=>{if(!e){w(null);return}try{w(await l.source(e))}catch{w(null)}},Ve=e=>{he(e),e&&window.setTimeout(()=>he(null),6e3)},He=e=>e instanceof pe?e.message:`the request failed`,Ue=yi(vi(C?.files??[],Ne,Pe),j),We=e=>{I(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Ge=()=>I(new Set(Ue.map(e=>e.name))),Ke=()=>I(new Set),qe=async e=>{try{let{trash:t}=await l.removeSource(e.id);f(t=>(t??[]).filter(t=>t.id!==e.id)),u.offer({label:`Deleted ${e.name}`,restore:()=>void(async()=>{try{await l.restoreTrash(t),await ze()}catch(e){Ve(He(e))}})()})}catch(e){Ve(He(e))}},Je=async e=>{if(C)try{let{trash:t}=await l.removeFiles(C.id,e),n=new Set(e);w(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)}),I(e=>new Set([...e].filter(e=>!n.has(e)))),u.offer({label:e.length===1?`Removed ${e[0]}`:`Removed ${e.length} files`,restore:()=>void(async()=>{try{let e=await l.restoreTrash(t);w(e.source)}catch(e){Ve(He(e))}})()})}catch(e){Ve(He(e))}},Ye=(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)},Xe=async e=>{if(!C)return;let t=e.length===1?e[0]:null;xe(!0);try{let n=t?await l.file(C.id,t):await l.zip(C.id,e);Ye(n,t??`${C.name}.zip`)}catch(e){Ve(He(e))}finally{xe(!1)}},Ze=async e=>{if(!C||C.system)return;let t=[...e];if(!t.length)return;let n=t.map(e=>({id:je.current++,file:e,state:`uploading`}));_e(e=>[...e,...n]);for(let e of n)try{await l.upload(C.id,e.file.name,e.file),_e(t=>t.map(t=>t.id===e.id?{...t,state:`done`}:t))}catch(t){_e(n=>n.map(n=>n.id===e.id?{...n,state:`error`,error:He(t)}:n))}await Be()},Qe=e=>void Ze([e.file]),$e=async(e,t)=>{if(C&&K)try{await l.copyFiles(t.id,C.id,K.names,e===`move`),q(null),I(new Set),await Be(),Ve(e===`move`?`Moved to ${t.name}.`:`Copied to ${t.name}.`)}catch(e){Ve(He(e)),q(null)}},et=async()=>{if(C&&X.trim())try{let e=await l.createSource(X.trim(),C.type);try{await l.copyFiles(e.id,C.id,[...F],!1)}catch(t){throw await l.removeSource(e.id).catch(()=>{}),t}se(!1),ce(``),I(new Set),await ze(),Ve(`Made a new Source.`)}catch(e){Ve(He(e))}},tt=async()=>{if(X.trim())try{await l.createSource(X.trim(),Z),U(!1),ce(``),Q(x().DEFAULT_SOURCE_TYPE),await ze()}catch(e){Ve(He(e))}},nt=async(e,t)=>{try{let n=await l.renameSource(e.id,t);f(t=>(t??[]).map(t=>t.id===e.id?Si(n):t)),w(e=>e?.id===n.id?{...e,name:n.name}:e)}catch(e){Ve(He(e))}},rt=(e,n=()=>te(e.id),r)=>e.system?[]:[{label:`Rename`,icon:t,onSelect:n},{label:`Delete`,icon:b,destructive:!0,onSelect:()=>void qe(e).then(r)}],at=e=>[{label:`Preview`,icon:p,disabled:!hi(e.name),onSelect:()=>W(e)},{label:`Download`,icon:g,onSelect:()=>void Xe([e.name])},...C?.system?[]:[{label:`Remove`,icon:b,destructive:!0,onSelect:()=>void Je([e.name])}]],st=[...C?.system?[]:[{label:`Remove`,icon:b,destructive:!0,onSelect:()=>void Je([...F])}],{label:`Download`,icon:g,busy:be,onSelect:()=>void Xe([...F])},...C?.system?[]:[{label:`Move to…`,icon:it,onSelect:()=>q({kind:`move`,names:[...F]})}],{label:`Copy to…`,icon:o,onSelect:()=>q({kind:`copy`,names:[...F]})},...C?.system?[]:[{label:`New Source from selection`,icon:ot,onSelect:()=>se(!0)}]],ct=e=>{e.preventDefault(),ye(!1),C&&!C.system&&Ze(e.dataTransfer.files)},lt=(d??[]).filter(e=>(!de||e.type===de)&&e.name.toLowerCase().includes(le.trim().toLowerCase())),ut=(0,$.jsx)(z,{noun:`Sources`,search:{label:`Find a Source`,value:le,placeholder:`Name`,onChange:ue},filters:[{key:`type`,label:`Type`,value:de,onChange:fe,options:[{value:``,label:`All`},...co()]}],count:{shown:lt.length,total:(d??[]).length}}),dt=()=>(0,$.jsxs)(`div`,{className:`sources`,"data-level":`sources`,children:[me&&(0,$.jsx)(`p`,{className:`note`,role:`status`,children:me}),(0,$.jsxs)(`header`,{className:`shead`,children:[(0,$.jsx)(`h2`,{className:`shead-title`,children:`Sources`}),(0,$.jsx)(to,{view:Me,onChange:e=>E(t=>({...t,view:e}))})]}),d!==null&&d.length>0&&ut,d===null?(0,$.jsx)(k,{label:`Sources`,error:Se,onRetry:()=>{Ce(null),De(e=>e+1)}}):d.length===0?(0,$.jsx)(`p`,{className:`note`,children:`No Sources on the server yet.`}):Me===`thumbs`?(0,$.jsx)(`ul`,{className:`sfolders`,children:lt.map(e=>(0,$.jsx)(`li`,{className:`sfolder`,children:(0,$.jsxs)(`button`,{type:`button`,className:`sfolder-open${c?.(e)?` off`:``}`,disabled:c?.(e),onClick:()=>s?.(e),children:[(0,$.jsx)(io,{}),(0,$.jsx)(`span`,{className:`sfolder-name`,children:e.name}),(0,$.jsxs)(`span`,{className:`sfolder-meta`,children:[lo(e),` · `,uo(e)]})]})},e.id))}):(0,$.jsx)(A,{className:`slist slist-folders`,label:`Sources`,rows:lt,rowKey:e=>e.id,columns:[{key:`name`,header:`Name`,className:`sfile-name`,sort:e=>e.name,cell:e=>(0,$.jsxs)(`button`,{type:`button`,className:`srow-pick${c?.(e)?` off`:``}`,disabled:c?.(e),onClick:()=>s?.(e),children:[(0,$.jsx)(io,{}),` `,e.name]})},{key:`type`,header:`Type`,sort:e=>lo(e),cell:e=>lo(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 dt();if(e){if(!C)return(0,$.jsx)(`div`,{className:`sources`,children:(0,$.jsx)(k,{label:`Files`,error:we,onRetry:()=>ke(e=>e+1)})});let e=Ya[C.type]?.Level,t=!e&&!C.system,a=()=>n?.(null),o=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ee,{kind:`Source`,name:C.name,crumb:{label:`Sources`,onClick:a},onPick:d?.length?()=>H(!0):void 0,meta:[lo(Si(C)),uo(Si(C)),bi(C.bytes)].join(` · `),primary:t?{label:`Upload`,icon:r,onSelect:()=>Ae.current?.click()}:void 0,actions:rt(Si(C),()=>B(!0),a)}),V&&d&&(0,$.jsx)(P,{kind:`Source`,value:C.id,onPick:e=>n?.(e),onClose:()=>H(!1),options:d.map(e=>({id:e.id,label:e.name}))}),R&&(0,$.jsx)(re,{title:`Rename Source`,value:C.name,onCommit:e=>{e&&e!==C.name&&nt(C,e)},onClose:()=>B(!1)})]});return e?(0,$.jsxs)(`div`,{className:`sources`,children:[o,(0,$.jsx)(e,{source:C,onBack:a}),(0,$.jsx)(O,{undo:u.undo,onUndo:u.undoNow,onDismiss:u.dismiss})]}):(0,$.jsxs)(`div`,{className:`sources`,"data-level":`files`,children:[o,me&&(0,$.jsx)(`p`,{className:`note`,role:`status`,children:me}),(0,$.jsxs)(`header`,{className:`shead`,children:[(0,$.jsx)(to,{view:Me,onChange:e=>E(t=>({...t,view:e}))}),(0,$.jsx)(no,{sort:Ne,dir:Pe,onChange:(e,t)=>E(n=>({...n,sort:e,dir:t}))}),(0,$.jsxs)(`label`,{className:`sfilter`,children:[(0,$.jsx)(i,{size:14,"aria-hidden":`true`}),(0,$.jsx)(`input`,{type:`search`,"aria-label":`Filter by name`,placeholder:`Filter`,value:j,onChange:e=>M(e.target.value)})]})]}),F.size>0&&(0,$.jsxs)(`div`,{className:`sselect`,"data-selected":F.size,children:[(0,$.jsxs)(`span`,{className:`sselect-count`,children:[F.size,` selected`]}),(0,$.jsx)(`button`,{type:`button`,className:`ghost`,onClick:Ge,children:`Select all`}),(0,$.jsx)(`button`,{type:`button`,className:`ghost`,onClick:Ke,children:`None`}),(0,$.jsx)(G,{label:`Selection actions`,actions:st})]}),(0,$.jsx)(`div`,{className:`sfiles${ve?` drag`:``}`,onDragOver:e=>{e.preventDefault(),ye(!0)},onDragLeave:()=>ye(!1),onDrop:ct,children:Ue.length===0?(0,$.jsx)(`p`,{className:`note`,children:j?`No files match that name.`:`No files in this Source yet.`}):Me===`thumbs`?(0,$.jsx)(`ul`,{className:`stiles`,children:Ue.map(e=>(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,className:`stile${F.has(e.name)?` sel`:``}`,"aria-pressed":F.has(e.name),"aria-label":e.name,onClick:()=>We(e.name),children:[(0,$.jsx)(eo,{id:C.id,file:e}),(0,$.jsx)(`span`,{className:`stile-name`,children:e.name}),F.has(e.name)&&(0,$.jsx)(`span`,{className:`stile-check`,children:(0,$.jsx)(v,{size:12,"aria-hidden":`true`})})]})},e.name))}):(0,$.jsx)(A,{className:`slist`,label:`${C.name} files`,rows:Ue,rowKey:e=>e.name,rowProps:e=>({className:F.has(e.name)?`sel`:void 0,"data-selected":F.has(e.name)||void 0,onClick:()=>We(e.name)}),columns:[{key:`name`,header:`Name`,className:`sfile-name`,cell:e=>e.name},{key:`type`,header:`Type`,className:`stype`,cell:e=>ro(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,$.jsx)(G,{label:`${e.name} actions`,actions:at(e)})}]})}),t&&(0,$.jsxs)(`div`,{className:`supload`,children:[(0,$.jsx)(`input`,{ref:Ae,type:`file`,multiple:!0,hidden:!0,"aria-hidden":`true`,accept:x().sourceTypeOf(C)?.uploads?.join(`,`),onChange:e=>{e.target.files&&Ze(e.target.files),e.target.value=``}}),ge.length>0&&(0,$.jsx)(`ul`,{className:`suploads`,children:ge.map(e=>(0,$.jsxs)(`li`,{className:`supload ${e.state}`,children:[(0,$.jsx)(`span`,{className:`supload-name`,children:e.file.name}),e.state===`uploading`&&(0,$.jsx)(`span`,{className:`supload-bar`,role:`status`,children:`Uploading…`}),e.state===`done`&&(0,$.jsx)(`span`,{className:`note`,children:`Uploaded`}),e.state===`error`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`note bad`,children:e.error}),(0,$.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>Qe(e),children:`Retry`})]})]},e.id))})]}),ae&&(0,$.jsxs)(D,{title:ae.name,onClose:Fe,children:[hi(ae.name)?(0,$.jsx)(`img`,{className:`spreview-img`,src:_i(C.id,ae),alt:ae.name}):null,(0,$.jsx)(`p`,{className:`note`,children:bi(ae.bytes)})]}),K&&(0,$.jsx)(D,{title:K.kind===`move`?`Move to…`:`Copy to…`,onClose:Le,children:(0,$.jsx)(Xa,{mode:`pick`,disabled:e=>e.id===C.id||e.system||e.type!==C.type,onPick:e=>void $e(K.kind,e)})}),oe&&(0,$.jsxs)(D,{title:`New Source from selection`,onClose:Re,children:[(0,$.jsxs)(`label`,{className:`prompt`,children:[(0,$.jsx)(`span`,{className:`prop-name`,children:`Name`}),(0,$.jsx)(`input`,{"aria-label":`New Source name`,value:X,autoFocus:!0,onChange:e=>ce(e.target.value),onKeyDown:e=>{e.key===`Enter`&&et()}})]}),(0,$.jsxs)(`div`,{className:`sacts`,children:[(0,$.jsx)(`button`,{type:`button`,className:`ghost`,disabled:!X.trim(),onClick:()=>void et(),children:`Make`}),(0,$.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>se(!1),children:`Close`})]})]}),(0,$.jsx)(O,{undo:u.undo,onUndo:u.undoNow,onDismiss:u.dismiss})]})}return(0,$.jsxs)(`div`,{className:`sources`,"data-level":`sources`,children:[me&&(0,$.jsx)(`p`,{className:`note`,role:`status`,children:me}),(0,$.jsxs)(`header`,{className:`shead`,children:[(0,$.jsx)(`h2`,{className:`shead-title`,children:`Sources`}),(0,$.jsxs)(`p`,{className:`note suste`,children:[`Used `,bi(y),` of `,bi(m)]}),(0,$.jsx)(to,{view:Me,onChange:e=>E(t=>({...t,view:e}))})]}),d!==null&&d.length>0&&ut,d===null?(0,$.jsx)(k,{label:`Sources`,error:Se,onRetry:()=>{Ce(null),De(e=>e+1)}}):d.length===0?(0,$.jsx)(`p`,{className:`note`,children:`No Sources yet — Add source below.`}):Me===`thumbs`?(0,$.jsx)(`ul`,{className:`sfolders`,children:lt.map(e=>(0,$.jsxs)(`li`,{className:`sfolder`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`sfolder-open`,onClick:()=>n?.(e.id),children:[(0,$.jsx)(io,{}),(0,$.jsx)(`span`,{className:`sfolder-name`,children:e.name}),(0,$.jsxs)(`span`,{className:`sfolder-meta`,children:[lo(e),` · `,uo(e)]}),(0,$.jsx)(so,{source:e,cap:m,children:e.system?(0,$.jsx)(`span`,{className:`squota-none`,children:`—`}):(0,$.jsx)(`span`,{className:`squota-bar`,children:(0,$.jsx)(`span`,{className:`squota-fill`,style:{width:`${ao(e.bytes,m)}%`}})})})]}),(0,$.jsx)(`span`,{className:`sfolder-menu`,children:(0,$.jsx)(G,{label:`${e.name} actions`,actions:rt(e)})})]},e.id))}):(0,$.jsx)(`div`,{className:`sfiles`,children:(0,$.jsx)(A,{className:`slist slist-folders`,label:`Sources`,rows:lt,rowKey:e=>e.id,rowProps:e=>({"data-open":e.id,onClick:()=>n?.(e.id)}),columns:[{key:`name`,header:`Name`,className:`sfile-name`,sort:e=>e.name,cell:e=>(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(io,{}),` `,e.name]})},{key:`type`,header:`Type`,sort:e=>lo(e),cell:e=>lo(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,$.jsx)(so,{source:e,cap:m,children:e.system?`—`:`${ao(e.bytes,m)}%`})},{key:`menu`,header:``,className:`s-actions`,sort:null,tdProps:()=>({onClick:e=>e.stopPropagation()}),cell:e=>(0,$.jsx)(G,{label:`${e.name} actions`,actions:rt(e)})}]})}),L&&d&&(()=>{let e=d.find(e=>e.id===L);return e?(0,$.jsxs)(`label`,{className:`srename`,children:[(0,$.jsxs)(`span`,{className:`prop-name`,children:[`Rename `,e.name]}),(0,$.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&&nt(e,n),te(null)}t.key===`Escape`&&te(null)},onBlur:t=>{let n=t.target.value.trim();n&&n!==e.name&&nt(e,n),te(null)}})]}):null})(),(0,$.jsxs)(`button`,{type:`button`,className:`ghost add-btn`,onClick:()=>U(!0),children:[(0,$.jsx)(h,{size:14,"aria-hidden":`true`}),` Add source`]}),ie&&(0,$.jsxs)(D,{title:`Add source`,onClose:Ie,children:[(0,$.jsx)(N,{label:`New Source`,rows:[{key:`type`,label:`Type`,hint:x().SOURCE_TYPES[Z]?.description,control:{type:`select`,value:Z,options:co(),onChange:Q}}]}),(()=>{let e=Ya[Z]?.Create,t=(0,$.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>U(!1),children:`Close`});return e?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(e,{onMade:async()=>{U(!1),Q(x().DEFAULT_SOURCE_TYPE),await ze()}}),(0,$.jsx)(`div`,{className:`sacts`,children:t})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`label`,{className:`prompt`,children:[(0,$.jsx)(`span`,{className:`prop-name`,children:`Name`}),(0,$.jsx)(`input`,{"aria-label":`Source name`,value:X,autoFocus:!0,onChange:e=>ce(e.target.value),onKeyDown:e=>{e.key===`Enter`&&tt()}})]}),(0,$.jsxs)(`div`,{className:`sacts`,children:[(0,$.jsx)(`button`,{type:`button`,className:`ghost`,disabled:!X.trim(),onClick:()=>void tt(),children:`Add`}),t]})]})})()]}),(0,$.jsx)(O,{undo:u.undo,onUndo:u.undoNow,onDismiss:u.dismiss})]})}var Za=`evals-lab.sources.adding`;function Qa(){try{return sessionStorage.getItem(Za)}catch{return null}}function $a(e){try{e?sessionStorage.setItem(Za,e):sessionStorage.removeItem(Za)}catch{}}function eo({id:e,file:t}){let[n,r]=(0,J.useState)(!1);return!t.thumb||n?(0,$.jsx)(`span`,{className:`stile-type`,children:ro(t.name)||`FILE`}):(0,$.jsx)(`img`,{className:`stile-img`,src:gi(e,t),alt:``,loading:`lazy`,onError:()=>r(!0)})}function to({view:e,onChange:t}){return(0,$.jsxs)(`div`,{className:`sview`,role:`group`,"aria-label":`View`,children:[(0,$.jsx)(`button`,{type:`button`,className:e===`thumbs`?`on`:void 0,"aria-pressed":e===`thumbs`,onClick:()=>t(`thumbs`),children:`Thumbnails`}),(0,$.jsx)(`button`,{type:`button`,className:e===`list`?`on`:void 0,"aria-pressed":e===`list`,onClick:()=>t(`list`),children:`List`})]})}function no({sort:e,dir:t,onChange:r}){return(0,$.jsxs)(`div`,{className:`ssort`,role:`group`,"aria-label":`Sort`,children:[(0,$.jsxs)(`select`,{"aria-label":`Sort by`,value:e,onChange:e=>r(e.target.value,t),children:[(0,$.jsx)(`option`,{value:`name`,children:`Name`}),(0,$.jsx)(`option`,{value:`added`,children:`Date added`}),(0,$.jsx)(`option`,{value:`size`,children:`Size`})]}),(0,$.jsx)(`button`,{type:`button`,className:`icon-btn`,"aria-label":`Sort ${t===1?`ascending`:`descending`}`,onClick:()=>r(e,t===1?-1:1),children:(0,$.jsx)(t===1?K:n,{size:14,"aria-hidden":`true`})})]})}function ro(e){let t=e.lastIndexOf(`.`);return t<0?``:e.slice(t+1).toUpperCase()}function io(){return(0,$.jsx)(st,{size:16,"aria-hidden":`true`})}function ao(e,t){return t<=0?0:Math.max(0,Math.min(100,Math.round(e/t*100)))}function oo(e,t){return e.system?`Quota: not counted`:`Quota: ${bi(e.bytes)} of ${bi(t)}`}function so({source:e,cap:t,children:n}){let r=oo(e,t);return(0,$.jsxs)(`span`,{className:`squota`,role:`img`,"aria-label":r,children:[n,(0,$.jsx)(`span`,{className:`squota-pop`,"aria-hidden":`true`,children:r})]})}var co=()=>Object.entries(x().SOURCE_TYPES).map(([e,t])=>({value:e,label:t.label})),lo=e=>x().SOURCE_TYPES[e.type]?.label??e.type,uo=e=>{let t=x().sourceTypeOf(e)?.noun??`item`;return`${e.files} ${e.files===1?t:`${t}s`}`};function fo({sourceId:e}){let[t,n]=(0,J.useState)(e);return(0,J.useEffect)(()=>n(e),[e]),(0,$.jsx)(Xa,{sourceId:t,onOpen:e=>{n(e),e?location.hash=`/library/sources/${encodeURIComponent(e)}`:location.hash=`#/library/sources`}})}var po=[{id:`datasets`,label:`Datasets`,icon:Qe},{id:`prompts`,label:`Prompts`,icon:pt},{id:`sources`,label:`Sources`,icon:at}];function mo({section:e,sourceId:t}){return(0,$.jsxs)(`div`,{className:`library`,children:[(0,$.jsx)(`nav`,{className:`lib-sections`,"aria-label":`Library`,children:po.map(({id:t,label:n,icon:r})=>(0,$.jsxs)(`a`,{href:`#/library/${t}`,...t===e?{"aria-current":`page`}:{},className:t===e?`on`:void 0,children:[(0,$.jsx)(r,{size:16,"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:n})]},t))}),(0,$.jsx)(`section`,{className:`lib-section`,"data-section":e,children:e===`datasets`?(0,$.jsx)(Xr,{}):e===`prompts`?(0,$.jsx)(si,{}):(0,$.jsx)(fo,{sourceId:t})})]})}var ho=`0.4.1 (2026.10.03-363)`,go=3,_o=3,vo=e=>mr.find(t=>t.id===e),yo=e=>po.find(t=>t.id===e),bo=e=>new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`});function xo(){let e=Y(),[t]=_e(`promptlab.profiles`),[n,r]=_e(`promptlab.workflows`),i=Ie(),a=Ke(),{pickDataset:o}=Gt(),{openRun:s}=Jt(),c=Fe(),l=Ge(),[u,d]=(0,J.useState)(null),[f,p]=(0,J.useState)(null),[m,h]=(0,J.useState)(null),[g,_]=(0,J.useState)(null),[v,y]=(0,J.useState)(0),[b,x]=(0,J.useState)(0),S=e=>e instanceof Error?e.message:String(e);(0,J.useEffect)(()=>{let t=!0;return h(null),e.sources().then(e=>{t&&d(e.sources)},e=>{t&&h(S(e))}),()=>{t=!1}},[e,v]),(0,J.useEffect)(()=>{let t=!0;return _(null),e.queue({limit:_o}).then(e=>{t&&p(e.runs)},e=>{t&&_(S(e))}),()=>{t=!1}},[e,b]);let C=(0,J.useMemo)(()=>n.list.filter(e=>e.work?.version===12),[n.list]),w=i.list??[],T=w.reduce((e,t)=>e+t.cases,0),E=(f??[]).filter(e=>e.status===`queued`||e.status===`running`).length,D=t.list.length===0?`setup`:i.list===null?null:w.length===0||T===0?`datasets`:f!==null&&f.length===0?`runs`:null,O=(...e)=>e.filter(Boolean).join(` · `)||void 0,k=vo(`library`),A=k.icon;return(0,$.jsxs)(`div`,{className:`home`,children:[(0,$.jsxs)(`ol`,{className:`home-line`,"aria-label":`Lab`,children:[(0,$.jsx)(So,{id:`runs`,icon:vo(`runs`).icon,name:vo(`runs`).label,hub:!0,start:D===`runs`,fact:O(dn(C.length,`pipeline`),E>0&&`${E} running`),total:C.length,items:C.map(e=>({key:e.id,label:e.name,href:`#/runs`,onPick:()=>r({...n,at:e.id})}))}),(0,$.jsx)(So,{id:`history`,icon:vo(`history`).icon,name:vo(`history`).label,fact:f&&f.length===0?`No runs yet`:void 0,wait:f?void 0:{error:g,onRetry:()=>x(e=>e+1)},items:(f??[]).map(e=>{let t=Wn(e).scenarios.map(e=>e.percent==null?`–`:`${e.percent}%`).join(` · `);return{key:e.id,label:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`code`,{children:un(e.submittedAt)}),e.status!==`done`&&_n(e.status)]}),sub:O(bo(e.submittedAt),!!t&&t),href:`#/history`,onOpen:()=>s(e.id,{at:e.submittedAt,from:`home`})}})}),(0,$.jsxs)(`li`,{className:`home-stop home-fork`,"data-stop":`library`,children:[(0,$.jsxs)(`a`,{className:`home-name`,href:`#/library`,children:[(0,$.jsx)(`span`,{className:`home-mark`,"aria-hidden":`true`,children:(0,$.jsx)(A,{size:18})}),k.label]}),(0,$.jsxs)(`ol`,{className:`home-branch`,"aria-label":k.label,children:[(0,$.jsx)(So,{id:`datasets`,to:`library/datasets`,branch:!0,icon:yo(`datasets`).icon,name:yo(`datasets`).label,start:D===`datasets`,fact:i.list?O(dn(w.length,`dataset`),dn(T,`case`)):void 0,total:w.length,wait:i.list?void 0:{error:i.error,onRetry:()=>void c.refresh()},items:w.map(e=>({key:e.id,label:e.name,sub:dn(e.cases,`case`),href:`#/library/datasets`,onPick:()=>o(e.id)}))}),(0,$.jsx)(So,{id:`prompts`,to:`library/prompts`,branch:!0,icon:yo(`prompts`).icon,name:yo(`prompts`).label,fact:a.list?O(dn(a.list.length,`prompt`)):void 0,total:a.list?.length??0,wait:a.list?void 0:{error:a.error,onRetry:()=>void l.refresh()},items:(a.list??[]).map(e=>({key:e.id,label:e.name||e.text.split(`
10
10
  `)[0]||`Untitled`,sub:e.default?`Default`:void 0,href:`#/library/prompts`}))}),(0,$.jsx)(So,{id:`sources`,to:`library/sources`,branch:!0,icon:yo(`sources`).icon,name:yo(`sources`).label,fact:u?O(dn(u.length,`source`)):void 0,total:u?.length??0,wait:u?void 0:{error:m,onRetry:()=>y(e=>e+1)},items:(u??[]).map(e=>({key:e.id,label:e.name,sub:dn(e.files,`file`),href:`#/library/sources/${encodeURIComponent(e.id)}`}))})]})]}),(0,$.jsx)(So,{id:`setup`,icon:vo(`setup`).icon,name:vo(`setup`).label,start:D===`setup`,fact:O(dn(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,$.jsxs)(`p`,{className:`home-version`,children:[`Evals Lab `,ho]})]})}function So({id:e,icon:t,name:n,to:r,fact:i,items:a,total:o=a.length,hub:s,start:c,branch:l,wait:u}){let d=o-Math.min(a.length,go);return(0,$.jsxs)(`li`,{className:[`home-stop`,s&&`hub`,c&&`start`,l&&`branch`].filter(Boolean).join(` `),"data-stop":e,children:[(0,$.jsxs)(`a`,{className:`home-name`,href:`#/${r??e}`,children:[(0,$.jsx)(`span`,{className:`home-mark`,"aria-hidden":`true`,children:(0,$.jsx)(t,{size:l?15:18})}),n]}),c&&(0,$.jsx)(`span`,{className:`home-start`,children:`Start Here`}),u&&(0,$.jsx)(k,{label:n,error:u.error,onRetry:u.onRetry}),!u&&i&&(0,$.jsx)(`span`,{className:`home-fact`,children:i}),!u&&a.length>0&&(0,$.jsxs)(`ul`,{className:`home-items`,children:[a.slice(0,go).map(e=>(0,$.jsx)(`li`,{children:(0,$.jsxs)(`a`,{href:e.href,onClick:t=>{e.onOpen?(t.preventDefault(),e.onOpen()):e.onPick?.()},children:[(0,$.jsx)(`span`,{className:`home-item`,children:e.label}),e.sub&&(0,$.jsx)(`span`,{className:`home-sub`,children:e.sub})]})},e.key)),d>0&&(0,$.jsx)(`li`,{children:(0,$.jsxs)(`a`,{className:`home-more`,href:`#/${r??e}`,children:[d,` more`]})})]})]})}function Co({list:e,at:n,canRestore:i,onSelect:a,onNew:s,onClone:c,onRename:l,onDelete:u,onRestore:d,onExport:f,onImport:p}){let[m,_]=(0,J.useState)(!1),[v,y]=(0,J.useState)(!1),x=e.find(e=>e.id===n),S=[{label:`Rename`,icon:t,onSelect:()=>_(!0)},{label:`Clone`,icon:o,onSelect:c},{label:`Export YAML`,icon:g,onSelect:f},{label:`Import YAML…`,icon:r,onSelect:p},{label:`Restore…`,icon:I,disabled:!i,onSelect:d},{label:`Delete`,icon:b,destructive:!0,onSelect:u}],C=x?.work.jobs?.length??0,w=x?.work.targets?.length??0;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ee,{kind:`Pipeline`,name:x?.name?.trim()||`Untitled`,onPick:()=>y(!0),meta:`${wo(C,`job`)} · ${wo(w,`Target`)}`,primary:{label:`New pipeline`,icon:h,onSelect:s},actions:S}),v&&(0,$.jsx)(P,{kind:`Pipeline`,value:n,onPick:a,onClose:()=>y(!1),options:e.map(e=>({id:e.id,label:e.name||`Untitled`}))}),m&&(0,$.jsx)(re,{title:`Rename pipeline`,value:x?.name??``,onCommit:l,onClose:()=>_(!1)})]})}var wo=(e,t)=>`${e} ${e===1?t:`${t}s`}`;function To({problems:e,error:t,run:n,submitting:r,onRun:i,onStop:a,onOpen:o}){let s=!!n&&!An(n.status),c=n?.progress?.total??0,l=n?.progress?.n??0,u=s&&c?Math.round(l/c*100):null,d=n&&(0,$.jsxs)(`button`,{type:`button`,className:`runbar-open`,title:`Open this run`,onClick:o,children:[(0,$.jsx)(`span`,{className:`runbar-word`,children:gn(n.status)}),Eo(n)&&(0,$.jsx)(`span`,{className:`runbar-detail`,children:Eo(n)})]}),f=s?d:e.length?(0,$.jsxs)(`span`,{className:`runbar-why`,children:[ko(e[0]),Oo(e[0])]}):t?(0,$.jsx)(`span`,{className:`runbar-why bad`,children:ko(t)}):d??(0,$.jsx)(`span`,{className:`runbar-why`,children:`Ready to run.`});return(0,$.jsxs)(`div`,{className:`runbar`,children:[(0,$.jsxs)(`div`,{className:`runbar-row`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`run`,disabled:e.length>0||r,"aria-busy":r||void 0,onClick:i,children:[r?(0,$.jsx)(W,{size:16}):(0,$.jsx)(gt,{size:16,"aria-hidden":`true`}),`Run`]}),(0,$.jsx)(`span`,{className:`runbar-line`,role:`status`,children:f}),s&&(0,$.jsxs)(`button`,{type:`button`,className:`ghost runbar-stop`,onClick:a,children:[(0,$.jsx)(Xe,{size:14,"aria-hidden":`true`}),`Stop`]})]}),u!=null&&(0,$.jsx)(`div`,{className:`runbar-meter`,role:`progressbar`,"aria-label":`Run progress`,"aria-valuenow":u,"aria-valuemin":0,"aria-valuemax":100,children:(0,$.jsx)(`div`,{className:`runbar-fill`,style:{width:`${u}%`}})})]})}function Eo(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 Do=[[/^Target profile .* not found$/,`#/setup`,`Open Setup`],[/^Source .* not found$/,`#/library/sources`,`Open Sources`],[/^Dataset .* not found$/,`#/library/datasets`,`Open Datasets`]];function Oo(e){let t=Do.find(([t])=>t.test(e.trim()));return t?(0,$.jsxs)($.Fragment,{children:[` `,(0,$.jsx)(`a`,{className:`runbar-fix`,href:t[1],children:t[2]})]}):null}var ko=e=>{let t=e.trim();if(!t)return t;let n=t[0].toUpperCase()+t.slice(1);return/[.!?]$/.test(n)?n:`${n}.`},Ao=10;function jo({onPick:e,onClose:t,used:n}){let{list:r,error:i}=Ke(),a=Ge(),[o,s]=(0,J.useState)(``),[c,l]=(0,J.useState)(`all`),[u,d]=(0,J.useState)(0),f=r??[],p=f.filter(e=>ii(e,o,c,n??{byScenario:new Set,byAll:new Set})).sort((e,t)=>Number(t.default)-Number(e.default)),m=Math.ceil(p.length/Ao),h=Math.min(u,Math.max(0,m-1)),g=p.slice(h*Ao,(h+1)*Ao);return(0,$.jsxs)(D,{title:`Select prompt`,onClose:t,className:`sp`,initialFocus:`.sp input[type=search]`,children:[(0,$.jsx)(z,{noun:`prompts`,search:{label:`Search prompts`,placeholder:`Search prompts`,value:o,onChange:e=>{s(e),d(0)}},filters:[{key:`show`,label:`Show`,value:c,onChange:e=>{l(e),d(0)},options:ni}],count:{shown:p.length,total:f.length}}),r===null?(0,$.jsx)(k,{label:`Prompts`,error:i,onRetry:()=>void a.refresh()}):f.length===0?(0,$.jsx)(`p`,{className:`note`,children:`No prompts yet.`}):p.length===0?(0,$.jsx)(`p`,{className:`note`,children:`No prompts match these filters.`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`ul`,{className:`sp-list`,"aria-label":`Prompts`,children:g.map(t=>(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,className:`sp-pick`,onClick:()=>e(t),children:[(0,$.jsxs)(`span`,{className:`sp-head`,children:[(0,$.jsx)(`span`,{className:`sp-title`,children:Re(t)}),t.default&&(0,$.jsx)(`span`,{className:`pl-default`,children:`Default`})]}),(0,$.jsx)(`span`,{className:`sp-text`,children:t.text.trim()||`—`}),(0,$.jsxs)(`span`,{className:`sp-meta`,children:[(0,$.jsx)(`span`,{children:t.useCount===1?`1 use`:`${t.useCount} uses`}),t.lastUsed&&(0,$.jsxs)(`span`,{children:[`last `,ai(t.lastUsed)]}),(0,$.jsxs)(`span`,{children:[`v`,t.version]})]})]})},t.id))}),m>1&&(0,$.jsxs)(`div`,{className:`sp-pager`,children:[(0,$.jsx)(`button`,{type:`button`,className:`ghost`,disabled:h===0,onClick:()=>d(h-1),children:`Back`}),(0,$.jsxs)(`span`,{className:`sp-page`,children:[h+1,` of `,m]}),(0,$.jsx)(`button`,{type:`button`,className:`ghost`,disabled:h>=m-1,onClick:()=>d(h+1),children:`Forward`})]})]})]})}function Mo(e){let t=x(),n=e.jobs.at(-1),r=s(t.defaultKind()),i=t.outOf(n),a=t.outOf(r),o=e=>!B(e.type)||B(e.type).includes(a.kind),c=i.modifiers.filter(o);return c.length&&(r=t.withOut(r,{...a,modifiers:c})),ls(e,[...e.jobs.slice(0,-1),t.withOut(n,{...i,modifiers:i.modifiers.filter(e=>!o(e))}),r],()=>({type:`prompt`,prompt:``}))}function No(e,t){if(e.jobs.length<2)return e;let n=e.jobs.slice();if(t===n.length-1){let e=x(),r=e.outOf(n[t]),i=e.outOf(n[t-1]),a=r.modifiers.filter(e=>!B(e.type)||B(e.type).includes(i.kind)),o=[...i.modifiers,...a];n[t-1]=e.withOut(n[t-1],{...i,modifiers:o.length?o:C(i.kind)})}return n.splice(t,1),{...e,jobs:n,targets:e.targets.map(e=>({...e,steps:e.steps.filter((e,n)=>n!==t)}))}}function Po(e,t){let n={...structuredClone(e.jobs[t]),id:x().newId()};n.name=`${x().jobLabel(e,t)} copy`;let r=[...e.jobs.slice(0,t+1),n,...e.jobs.slice(t+1)],i=e.targets.map(e=>({...e,steps:[...e.steps.slice(0,t+1),structuredClone(e.steps[t]),...e.steps.slice(t+1)]}));return{...e,jobs:r,targets:i}}function Fo(e,t,n){let r=e.jobs.map((e,r)=>r===t?{...e,name:n.trim()}:e);return{...e,jobs:r}}function Io(e,t,n){let r=x().outOf(e.jobs[t]);if(r.kind===n||!n)return e;let i=t===e.jobs.length-1,a=r.modifiers.filter(e=>!B(e.type)||B(e.type).includes(n));return{...e,jobs:e.jobs.map((e,r)=>r===t?x().withOut(e,{kind:n,...d(n),modifiers:i?a.length?a:C(n):[]}):e)}}var Lo=(e,t)=>({...e,evals:[...e.evals,t]}),Ro=(e,t)=>({...e,evals:e.evals.filter((e,n)=>n!==t)});function zo(e,t,n){let r=t+n;if(r<0||r>=e.evals.length)return e;let i=e.evals.slice();return[i[t],i[r]]=[i[r],i[t]],{...e,evals:i}}var Bo=(e,t,n)=>({...e,evals:e.evals.map((e,r)=>r===t?{...e,name:n.trim()}:e)}),Vo=(e,t,n)=>({...e,evals:e.evals.map((e,r)=>r===t?n:e)}),Ho=e=>e[0]?{id:e[0].id,name:e[0].name}:{id:``,name:``};function Uo(e,t,n=``){let r=x(),i=!!r.targetEntryOf(e,0,0)?.newStep,a={id:r.newId(),name:``,profile:i?e.targets.at(-1)?.profile??t:t,steps:e.jobs.map((t,i)=>{let a=r.targetStepOf(e,0,i),o=r.STEP_TYPES[r.jobTargetType(e,i)]?.local?`prompt`:r.jobTargetType(e,i);return a&&r.targetEntryOf(e,0,i)?.newStep?.(a)||{type:o,prompt:i===0?n:``}})};return{...e,targets:[...e.targets,a]}}function Wo(e){let t=new Set(e.map(e=>e.trim().toLowerCase())),n=1;for(;t.has(`pipeline ${n}`);)n+=1;return`Pipeline ${n}`}var Go={id:`samples`,name:`Sample library`};function Ko(e,t,n=``){let r=x().withContent({...x().blankPipeline({name:Wo([])}),evals:t?[x().newEval(`metrics`,``,{dataset:{id:t.id,name:t.name},metrics:[]})]:[]},{type:`source`,ref:{...Go},first:null,loops:1});if(t){let e=x();r={...r,jobs:[e.withTokens(e.withOut(r.jobs[0],{kind:`list`,...d(`list`),modifiers:[{type:`tidy`},{type:`dedupe`}]}),e.mappingsFor(n))]}}return r=Uo(r,e,n),Uo(r,e,n)}function qo(e,t){let n=e=>!!e.profile&&!e.profile.id;return!t.id||!e.targets.some(n)?e:{...e,targets:e.targets.map(e=>n(e)?{...e,profile:{...t}}:e)}}function Jo(e,t){let n={...structuredClone(e.targets[t]),id:x().newId(),name:`${x().targetLabel(e,t)} copy`};return{...e,targets:[...e.targets.slice(0,t+1),n,...e.targets.slice(t+1)]}}function Yo(e,t){return{...e,targets:e.targets.filter((e,n)=>n!==t)}}function Xo(e,t,n){return{...e,targets:e.targets.map((e,r)=>r===t?{...e,name:n.trim()}:e)}}function Zo(e,t,n,r){return n===0?{...e,targets:e.targets.map((e,n)=>n===t?{...e,profile:r??e.profile}:e)}:x().withTarget(e,t,n,e=>{if(r)return{...e,profile:r};let{profile:t,...n}=e;return n})}function Qo(e,t,n,r){return x().withTarget(e,t,n,{prompt:r})}function $o(e,t,n,r,i){return x().withTarget(e,t,n,{prompt:r,from:{...i}})}function es(e,t){return new Set(e.jobs.flatMap((n,r)=>x().targetStepOf(e,t,r)?.from?.id??[]))}function ts(e){let t=x().targetsOf(e).length,n=es(e,0);for(let r=1;r<t;r++){let t=es(e,r);for(let e of[...n])t.has(e)||n.delete(e)}return n}function ns(e,t,n,r){return cs(e,t,e=>e.map(e=>e.name===n?{...e,...r}:e))}function rs(e,t,n,r){let i=n.trim();return i?cs(e,t,e=>e.some(e=>e.name===i)?e:[...e,x().tokenMapping(i,r)]):e}function is(e,t,n,r){let i=r.name.trim();return i?cs(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}:x().tokenMapping(i,r.type):e)):e}function as(e,t,n){return cs(e,t,e=>e.filter(e=>e.name!==n))}var os=/^(?:text|reply|stage[1-9]\d*(?:\..*)?)$/;function ss(e,t,n,r){let i=n.trim();return i?/[{}\s]/.test(i)?`A name has no braces or spaces.`:os.test(i)?`{${i}} is filled in by the lab.`:i!==r&&x().tokensOf(e.jobs[t]).some(e=>e.name===i)?`{${i}} is already mapped.`:null:`A mapping needs a name.`}function cs(e,t,n){let r=x();return{...e,jobs:e.jobs.map((e,i)=>i===t?r.withTokens(e,n(r.tokensOf(e))):e)}}function ls(e,t,n){let r=t.length,i=e.targets.map(e=>{let t=e.steps.slice(0,r);for(;t.length<r;)t.push(n(t.length));return{...e,steps:t}});return{...e,jobs:t,targets:i}}var us=(e,t)=>(x().targetsOf(e)[t]?.name||``).trim()||`Target ${t+1}`;function ds(e,t){let n=x().STEP_TYPES;return t.includes(n[e]?.asks??`prompt`)?e:Object.entries(n).find(([,e])=>e.slot===`target`&&t.includes(e.asks??`prompt`))?.[0]??e}function fs(e,t,n,r){if(n.type===r)return n;let i={prompt:n.prompt,...n.profile?{profile:n.profile}:{},...n.from?{from:n.from}:{}},a=x();if(a.STEP_TYPES[r]?.asks!==`request`)return{type:r,...i};let o=a.targetsOf(e).map((n,r)=>a.targetStepOf(e,r,t)).find(e=>e?.type===r);return{type:r,...o?{api:o.api,method:o.method,path:o.path,query:structuredClone(o.query),body:structuredClone(o.body)}:{api:a.flowStepOf(e.jobs[t])?.api??`raw`,method:`POST`,path:`/`,query:{},body:null},...i}}function ps(e,t,n,r,i){let a=Zo(e,t,n,r),o=x();return a.jobs.forEach((e,n)=>{let r=o.targetProfileOf(a,t,n),s=r?i(r.id):void 0,c=o.targetStepOf(a,t,n);if(!s||!c)return;let l=ds(c.type,s);l!==c.type&&(a=o.withTarget(a,t,n,e=>fs(a,n,e,l)))}),a}var ms=(e,t,n)=>({...e,jobs:e.jobs.map((e,r)=>r===t?x().withImage(e,n):e)});function hs(e,t,n){let r=x();return{...e,jobs:e.jobs.map((e,i)=>{if(i!==t)return e;let a=e.steps.filter(e=>e.type!==`readAs`),o=a.findIndex(e=>r.STEP_TYPES[e.type]?.slot===`responses`);if(n==null)return{...e,steps:a};let s={type:`readAs`,readAs:n};return{...e,steps:o<0?[...a,s]:[...a.slice(0,o),s,...a.slice(o)]}})}}function gs(e,t){let n=x(),r=n.defaultKind(),i=n.outOf(e.jobs[t]).modifiers.filter(e=>!B(e.type)||B(e.type).includes(r));return{...e,jobs:e.jobs.map((e,a)=>a===t?n.withOut(e,{kind:r,...d(r),modifiers:i}):e)}}function _s(e,t){let n=x().outOf(e.jobs[t]).modifiers.filter(e=>!B(e.type)||B(e.type).includes(`text`));return{...e,jobs:e.jobs.map((e,r)=>{if(r!==t)return e;let i=e.steps.filter(e=>e.type!==`readReply`&&e.type!==`modifier`);return{...e,steps:[...i,...n.map(e=>({type:`modifier`,modifier:e}))]}})}}function vs(e,t){let n=x().withTarget(e,t,0,e=>({type:`echo`,prompt:e.prompt,...e.from?{from:e.from}:{}}));return e.jobs.length===1&&(n={...n,targets:n.targets.map((e,n)=>n===t?{...e,profile:null}:e)}),n}function ys({k:e,pipeline:t,sources:n,edit:r,offer:i}){let[a,o]=(0,J.useState)(!1),[s,c]=(0,J.useState)(null),l=x(),u=t.jobs[e],d=e===0?l.contentOf(t):null,f=l.flowStepOf(u),p=l.sendsImage(u),m=l.tokensOf(u),h=l.CONTENT_TYPES,g=l.targetsOf(t).some((n,r)=>l.STEP_TYPES[l.targetStepOf(t,r,e)?.type??``]?.asks===`request`)||e===0&&!!h[d?.type??``]?.inline,_=[...e>0?[{kind:`reply`}]:[],...d?[{kind:`attach`}]:[],...f?[{kind:`flow`}]:[],...p?[{kind:`image`}]:[],...m.map(e=>({kind:`mapping`,name:e.name}))],v=(e,n)=>{let a=t;r(n),i({label:e,restore:()=>r(a)})},b=(e,n)=>r(ms(l.withContent(t,e),0,n)),S=[...e===0&&!d?[{label:`Source…`,icon:y.add,onSelect:()=>o(!0)},{label:h.text?.label??`Text`,icon:y.add,onSelect:()=>b({type:`text`,text:``},!1)},{label:h.prompt?.label??`Prompt only`,icon:y.add,onSelect:()=>b({type:`prompt`},!1)}]:[],...!p&&!g?[{label:l.STEP_TYPES.attachImage?.label??`Image`,icon:y.add,onSelect:()=>r(ms(t,e,!0))}]:[],{label:`Token mapping`,icon:y.add,onSelect:()=>c({mode:`add`})}],C=n=>{n.kind===`attach`?v(`Removed the content`,l.withContent(t,null)):n.kind===`image`?v(`Stopped sending the image`,ms(t,e,!1)):n.kind===`mapping`&&v(`Removed {${n.name}}`,as(t,e,n.name))},T=s?.mode===`edit`?m.find(e=>e.name===s.name):void 0,O=n=>{let a=t;s?.mode===`add`?r(rs(a,e,n.name,n.type)):T&&(r(is(a,e,T.name,n)),n.type!==T.type&&T.value&&i({label:`Changed {${T.name}} to ${l.TOKEN_TYPES[n.type]?.label.toLowerCase()??n.type}`,restore:()=>r(a)})),c(null)},k=(i,a)=>{switch(i.kind){case`reply`:return[{key:`reply`,label:`${l.jobLabel(t,e-1)} reply`,locked:!0,control:{type:`static`,text:`Each target's ${w(l.outOf(t.jobs[e-1]).kind)}`}}];case`attach`:return[d?.type===`text`?{key:`attach`,label:l.STEP_TYPES.attachContent?.label??`Attach Content`,required:!0,actions:a,control:{type:`textarea`,value:d.text,placeholder:`The item every target is sent`,onChange:e=>r(l.withContent(t,{...d,text:e}))}}:{key:`attach`,label:l.STEP_TYPES.attachContent?.label??`Attach Content`,required:!0,actions:a,hint:h[d?.type??``]?.description,control:{type:`static`,text:Ss(d,n)}}];case`flow`:return[{key:`flow`,label:l.STEP_TYPES.flowStep?.label??`Flow step`,required:!0,actions:a,control:{type:`static`,text:f?.step??``}},{key:`api`,label:`API`,required:!0,control:{type:`select`,value:f?.api??``,onChange:n=>r({...t,jobs:t.jobs.map((t,r)=>r===e?{...t,steps:t.steps.map(e=>e.type===`flowStep`?{...e,api:n}:e)}:t)}),options:Object.entries(l.HTTP_APIS).map(([e,t])=>({value:e,label:t.label}))}}];case`image`:return[{key:`image`,label:l.STEP_TYPES.attachImage?.label??`Attach Image`,required:!0,actions:a,control:{type:`static`,text:`Each item`}}];case`mapping`:{let n=m.find(e=>e.name===i.name),o=l.TOKEN_TYPES[n.type],s=o?.fields??[];return[{key:`mapping-${n.name}`,label:o?o.notation(n.name):`{${n.name}}`,code:!0,required:!0,control:s.includes(`value`)?{type:`text`,value:n.value??``,onChange:i=>r(ns(t,e,n.name,{value:i}))}:{type:`static`,text:o?.label??n.type},...s.includes(`enabled`)?{enabled:{checked:!!n.enabled,onChange:i=>r(ns(t,e,n.name,{enabled:i}))}}:{},actions:[{label:`Edit`,icon:y.edit,onSelect:()=>c({mode:`edit`,name:n.name})},...a]}]}}},A=t=>t.kind===`reply`?`Job ${e+1} reply`:t.kind===`flow`?`Job ${e+1} flow step`:t.kind===`mapping`?`{${t.name}}`:t.kind===`attach`?`Content`:`Image`,j=_.map(r=>bs[r.kind](t,e,n)).join(`, `)||`none`;return(0,$.jsxs)(U,{id:`job-${e}-content`,title:`Content`,level:3,note:j,children:[(0,$.jsx)(R,{noun:`content`,items:_,onAdd:S,onRemove:e=>C(_[e]),locked:e=>e.kind===`reply`||e.kind===`flow`,extra:e=>e.kind===`attach`?[{label:`Change content`,icon:y.rename,onSelect:()=>o(!0)}]:[],empty:(0,$.jsx)(`p`,{className:`note`,children:`No content`}),renderItem:(t,n,r)=>(0,$.jsx)(`div`,{className:`stage-row`,id:t.kind===`mapping`?void 0:`job-${e}-${t.kind}`,children:(0,$.jsx)(N,{label:A(t),rows:k(t,r)})},t.kind===`mapping`?`m-${t.name}`:t.kind)}),s&&(s.mode===`add`||T)&&(0,$.jsx)(H,{title:T?l.TOKEN_TYPES[T.type]?.notation(T.name)??`{${T.name}}`:`New mapping`,initial:T?{name:T.name,type:T.type}:{name:``,type:`value`},problem:n=>ss(t,e,n,T?.name),onSave:O,onClose:()=>c(null)},s.mode===`edit`?s.name:`add`),a&&(0,$.jsxs)(D,{title:d?`Change content`:`Add content`,onClose:()=>o(!1),children:[(0,$.jsx)(Xa,{mode:`pick`,onPick:e=>{b({type:`source`,ref:E(e.id,e.name),first:null,loops:1},l.sourceTypeOf(e)?.sendsImage??!1),o(!1)}}),(0,$.jsxs)(`div`,{className:`pick-others`,children:[(0,$.jsx)(`h2`,{className:`shead-title`,children:`Without a Source`}),(0,$.jsxs)(`button`,{type:`button`,className:`ghost pick-item`,onClick:()=>{b({type:`text`,text:``},!1),o(!1)},children:[(0,$.jsx)(`span`,{children:h.text?.label??`Text`}),h.text?.description&&(0,$.jsx)(`span`,{className:`pick-about`,children:h.text.description})]}),(0,$.jsxs)(`button`,{type:`button`,className:`ghost pick-item`,onClick:()=>{b({type:`prompt`},!1),o(!1)},children:[(0,$.jsx)(`span`,{children:h.prompt?.label??`Prompt only`}),h.prompt?.description&&(0,$.jsx)(`span`,{className:`pick-about`,children:h.prompt.description})]})]})]})]})}var bs={reply:(e,t)=>`${x().jobLabel(e,t-1)} · ${w(x().outOf(e.jobs[t-1]).kind)}`,attach:(e,t,n)=>Ss(x().contentOf(e),n),flow:(e,t)=>x().flowStepOf(e.jobs[t])?.step??``,image:()=>`image`,mapping:()=>`token mapping`},xs=(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}`},Ss=(e,t)=>e?e.type===`source`?xs(e,t):x().CONTENT_TYPES[e.type]?.label??e.type:`none`;async function Cs(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}var ws={prompt:{actions:Ds,summary:Es},echo:{actions:Ds,summary:()=>`Each item`},httpRequest:{summary:e=>`${e.method} ${e.path}`,promptLabel:e=>Os(e)?.fields.length?`Prompt`:`Body`,rows:As,actions:Ns}},Ts=e=>ws[e??``]??ws.prompt;function Es(e){return e.from?.name||e.prompt.split(`
11
11
  `).find(e=>e.trim())?.trim()||`No prompt`}function Ds({pipeline:e,i:t,k:n,onSelectPrompt:r,onClearPrompt:i,defaultPrompt:a,onRevert:o}){let s=x().targetStepOf(e,t,n)?.prompt??``;return[{label:`Select prompt…`,icon:ut,onSelect:r},{label:`Clear prompt`,icon:y.clear,disabled:!s,onSelect:i},...o&&a!=null?[{label:`Revert to default`,icon:y.revert,disabled:s===a,onSelect:o}]:[]]}var Os=e=>x().HTTP_APIS[e?.api??``],ks=e=>{let t=Object.entries(e??{}).map(([e,t])=>`${e}=${t}`).join(`&`);return t?`?${t}`:``};function As(e,t){let n=e,r=[{key:`api`,label:`API`,control:t?{type:`select`,value:n.api,onChange:e=>t({api:e}),options:Object.entries(x().HTTP_APIS).map(([e,t])=>({value:e,label:t.label}))}:{type:`static`,text:Os(e)?.label??n.api}},{key:`request`,label:`Request`,control:{type:`code`,text:`${n.method} ${n.path}${ks(n.query)}`}},{key:`body`,label:`Template`,control:{type:`code`,text:JSON.stringify(n.body,null,2)}}],i=Os(e);if(!i)return r;let a=(n,r,i=!1)=>({key:n,label:r,control:t?i?{type:`textarea`,value:e[n]??``,onChange:e=>t({[n]:e})}:{type:`text`,value:e[n]??``,onChange:e=>t({[n]:e})}:{type:`static`,text:e[n]??`—`}});if(i.fields.includes(`system`)&&r.push(a(`system`,`System`,!0)),i.fields.includes(`model`)&&r.push(a(`model`,`Model`)),i.fields.includes(`settings`))for(let n of i.settings){let i=e.settings?.[n]??``;r.push({key:`setting-${n}`,label:n,control:t?{type:`text`,value:i,size:`num`,onChange:r=>t({settings:{...e.settings,[n]:r}})}:{type:`static`,text:i||`—`}})}return i.fields.includes(`prefill`)&&r.push(a(`prefill`,`Prefill`)),r}function js(e){return JSON.stringify((Os(e)??x().HTTP_APIS.raw).place(e.body,e),null,2)}function Ms(e,t,n){let r=x().targetStepOf(e,t,n);if(!r)return``;let i=Os(r),a=e.jobs[n],o=x().flowStepOf(a),s=x().readAsOf(a),c=x().contentOf(e),l=c?.type===`source`?c.ref.name:null,u=i?.cellOf(r.body),d=u?[`prompt`,`system`,`model`,`prefill`].filter(e=>(r[e]??``)!==(u[e]??``)).concat(Object.keys({...u.settings,...r.settings}).filter(e=>(r.settings?.[e]??``)!==(u.settings?.[e]??``))):[],f=[`In the Power Automate flow${l?` "${l}"`:``}, edit the HTTP action "${o?.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 d.length&&f.push(`What changes from the flow as it is: ${d.join(`, `)} (the lab's target "${us(e,t)}").`),r.prefill&&f.push(`The body ends with an assistant message, ${JSON.stringify(r.prefill)}, which starts the model's reply. The reply the action returns does not repeat it, so wherever the flow reads the reply`+(s?` (${s})`:``)+` put ${JSON.stringify(r.prefill)} back in front of the text, for example with concat('${r.prefill.replace(/'/g,`''`)}', …).`),f.push(``,`Body:`,"```json",js(r),"```"),f.join(`
12
12
  `)}function Ns({pipeline:e,i:t,k:n,say:r}){let i=x().targetStepOf(e,t,n);if(!i)return[];let a=async(e,t)=>r(await Cs(e)?`Copied ${t}.`:`Could not copy.`);return[{label:`Copy`,icon:o,onSelect:()=>void a(js(i),`the body`)},{label:`Copy as AI prompt`,icon:Ct,onSelect:()=>void a(Ms(e,t,n),`the AI prompt`)}]}function Ps({label:e,profile:t,prompt:n,onPrompt:r,rows:i=[],promptLabel:a=`Prompt`}){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{label:`${e} setup`,rows:[{key:`profile`,label:`Target profile`,control:t},...i]}),(0,$.jsxs)(`label`,{className:`prompt`,children:[(0,$.jsx)(`span`,{className:`prop-name`,children:a}),(0,$.jsx)(`textarea`,{value:n,"aria-label":`${e}, prompt`,rows:8,readOnly:!r,onChange:e=>r?.(e.target.value)})]})]})}function Fs({run:e,i:t,onClose:n}){let r=x(),i=r.targetLabel(e,t),a=r.targetsOf(e)[t],o=t=>t&&(e.profiles?.[t.id]?.name||t.name)||`—`,s=e.jobs.length;return(0,$.jsx)(j,{title:i,sections:e.jobs.flatMap((n,i)=>{let a=r.targetStepOf(e,t,i);return a?[{cell:a,k:i}]:[]}).map(({cell:t,k:n})=>({key:`job-${n}`,...s>1?{title:r.jobLabel(e,n)}:{},children:(0,$.jsx)(Ps,{label:s>1?`${i}, ${r.jobLabel(e,n)}`:i,profile:{type:`static`,text:n===0?r.STEP_TYPES[t.type]?.local?r.STEP_TYPES[t.type].label??`Echo`:o(a?.profile??void 0):t.profile?o(t.profile):`Same as ${r.jobLabel(e,0)}`},prompt:t.prompt,rows:Ts(t.type).rows?.(t)??[],promptLabel:Ts(t.type).promptLabel?.(t)??`Prompt`})})),closeLabel:`Close`,onClose:n})}function Is({index:e}){return(0,$.jsx)(`span`,{className:`target-badge`,"aria-hidden":`true`,children:String.fromCharCode(65+e)})}function Ls({k:e,pipeline:t,profiles:n,targetCap:r,onRequestRename:i,onAdd:a,onClone:o,onRemove:s,onProfile:c,onEcho:l,onPrompt:u,onStep:d,onSelectPrompt:f,onClearPrompt:p,defaultPrompt:m,onRevert:h,say:g=()=>{}}){let _=x(),v=_.targetsOf(t),y=v.length;return(0,$.jsx)(U,{id:`job-${e}-targets`,title:`Targets`,level:3,note:`${y} ${y===1?`target`:`targets`}`,children:(0,$.jsx)(R,{noun:`target`,items:v,min:1,max:r,onAdd:a,onClone:o,onRemove:s,onRename:i,extra:(n,r)=>Ts(_.targetStepOf(t,r,e)?.type).actions?.({pipeline:t,i:r,k:e,say:g,onSelectPrompt:()=>f(r),onClearPrompt:()=>p(r),defaultPrompt:m,onRevert:h&&(()=>h(r))})??[],empty:(0,$.jsx)(`p`,{className:`note`,children:`No targets`}),renderItem:(r,i,a)=>{let o=us(t,i),s=_.targetStepOf(t,i,e)??{type:`prompt`,prompt:``},f=Ts(s.type),p=_.STEP_TYPES[s.type],m=e>0&&!!p?.firstJobOnly,h=p?.local?null:s.profile??r.profile,g=h?n.find(e=>e.id===h.id)?.name||h.name||`—`:`No profile`;return(0,$.jsxs)(`div`,{className:`target`,id:`job-${e}-target-${i}`,children:[(0,$.jsxs)(`div`,{className:`target-head`,children:[(0,$.jsx)(Is,{index:i}),(0,$.jsxs)(`span`,{className:`target-who`,children:[(0,$.jsx)(`h4`,{className:`target-name`,children:o}),(0,$.jsx)(`span`,{className:`target-profile`,children:g})]}),(0,$.jsxs)(`span`,{className:`target-what`,children:[(0,$.jsx)(`span`,{className:`target-type`,children:p?.label??s.type}),(0,$.jsx)(`span`,{className:m?`target-value idle`:`target-value`,children:m?`Job 1 only`:f.summary?.(s)??s.prompt})]}),(0,$.jsx)(G,{actions:a,label:`${o} actions`})]}),!m&&(0,$.jsx)(Ps,{label:o,profile:e===0?{type:`select`,value:zs(s)?Rs:r.profile?.id??``,options:[...Bs(),...Vs(n,r.profile)],onChange:e=>e===Rs?l(i):c(i,Hs(n,e))}:{type:`select`,value:s.profile?.id??``,options:[{value:``,label:`Same as ${_.jobLabel(t,0)}`},...Vs(n,s.profile)],onChange:e=>c(i,e?Hs(n,e):null)},prompt:s.prompt,onPrompt:e=>u(i,e),rows:f.rows?.(s,e=>d(i,e))??[],promptLabel:f.promptLabel?.(s)??`Prompt`})]},`${i}-${e}`)}})})}var Rs=`#echo`,zs=e=>!!x().STEP_TYPES[e.type]?.local,Bs=()=>Object.entries(x().STEP_TYPES).filter(([,e])=>e.slot===`target`&&e.local).map(([,e])=>({value:Rs,label:e.label??`Echo`})),Vs=(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}))],Hs=(e,t)=>{let n=e.find(e=>e.id===t);return n?{id:n.id,name:n.name}:null};function Us({pipeline:e,profiles:t,sources:r,targetCap:i,prompt:a=``,defaultPrompt:o,protectedTerms:s,edit:c,offer:l}){let[d,f]=(0,J.useState)(null),[p,m]=(0,J.useState)(null),[h,g]=(0,J.useState)(null),_=(t,n)=>{let r=e;c(n),l({label:t,restore:()=>c(r)})},v=e=>{let n=t.find(t=>t.id===e);return n?x().CONNECTION_TYPES[x().typeOf(n)]?.answers??[`prompt`]:void 0},y=!x().targetsOf(e).length;return(0,$.jsxs)(`div`,{className:`jobs`,children:[h&&(0,$.jsx)(`p`,{className:`note`,role:`status`,children:h}),(0,$.jsx)(R,{noun:`job`,items:e.jobs,min:1,addDisabled:y,onAdd:()=>c(Mo(e)),onClone:t=>c(Po(e,t)),onRemove:t=>_(`Removed ${x().jobLabel(e,t)}`,No(e,t)),onRename:e=>f({job:e}),renderItem:(d,p,h)=>{let y=`Job ${p+1}${d.name?.trim()?` - ${d.name.trim()}`:``}`,b=x().flowStepOf(d)?x().readAsOf(d):void 0;return(0,$.jsxs)(J.Fragment,{children:[p>0&&(0,$.jsxs)(`div`,{className:`job-reply`,"aria-hidden":`true`,children:[(0,$.jsx)(n,{size:16}),(0,$.jsx)(`span`,{children:`Reply`})]}),(0,$.jsx)(U,{id:`job-${p}`,title:y,level:2,actions:h,note:Ws(e,p),children:(0,$.jsxs)(`div`,{className:`stages`,children:[(0,$.jsx)(ys,{k:p,pipeline:e,sources:r,edit:c,offer:l}),(0,$.jsx)(Ls,{k:p,pipeline:e,profiles:t,targetCap:i,onRequestRename:e=>f({job:p,scenario:e}),onAdd:()=>c(Uo(e,Ho(t),a)),onClone:t=>c(Jo(e,t)),onRemove:t=>_(`Removed ${us(e,t)}`,Yo(e,t)),onProfile:(t,n)=>c(ps(e,t,p,n,v)),onEcho:t=>c(vs(e,t)),onPrompt:(t,n)=>c(Qo(e,t,p,n)),onStep:(t,n)=>c(Gs(e,t,p,n)),say:g,onSelectPrompt:e=>m({i:e,k:p}),onClearPrompt:t=>_(`Cleared ${us(e,t)}'s prompt`,Qo(e,t,p,``)),...p===0&&o?{defaultPrompt:o.text,onRevert:t=>_(`Reverted ${us(e,t)} to the default`,$o(e,t,0,o.text,{id:o.id,name:Re(o)}))}:{}}),(0,$.jsx)(V,{id:`job-${p}-responses`,out:x().outOf(d),format:!!x().replyOf(d),readAs:b,outputKinds:T(),modifiers:u(),onKind:t=>c(Io(e,p,t)),onSetting:(t,n)=>c(Ks(e,p,e=>({...e,[t]:n}))),onAddFormat:()=>c(gs(e,p)),onRemoveFormat:()=>_(`Removed the format validation`,_s(e,p)),onReadAs:t=>t==null?_(`Removed Read as`,hs(e,p,null)):c(hs(e,p,t)),...s?{protectedTerms:s}:{},offer:l,onModifier:(t,n)=>c(qs(e,p,t,n)),onAddModifier:t=>c(Ks(e,p,e=>({...e,modifiers:[...e.modifiers,t]}))),onRemoveModifier:t=>_(`Removed a modifier`,Ks(e,p,e=>({...e,modifiers:e.modifiers.filter((e,n)=>n!==t)})))})]})})]},d.id||p)}}),y&&(0,$.jsx)(`p`,{className:`note add-why`,children:`Add a target first.`}),d&&`scenario`in d?(0,$.jsx)(re,{title:`Rename ${us(e,d.scenario)}`,value:x().targetsOf(e)[d.scenario]?.name??``,onCommit:t=>c(Xo(e,d.scenario,t)),onClose:()=>f(null)}):d?(0,$.jsx)(re,{title:`Rename ${x().jobLabel(e,d.job)}`,value:e.jobs[d.job]?.name??``,onCommit:t=>c(Fo(e,d.job,t)),onClose:()=>f(null)}):null,p&&(0,$.jsx)(jo,{onClose:()=>m(null),used:{byScenario:es(e,p.i),byAll:ts(e)},onPick:t=>{let n=e;c($o(n,p.i,p.k,t.text,{id:t.id,name:Re(t)})),m(null),l({label:`Picked ${Re(t)}`,restore:()=>c(n)})}})]})}function Ws(e,t){let n=x(),r=r=>e.jobs[t].steps.filter(e=>n.STEP_TYPES[e.type]?.slot===r).length,i=e.jobs[t],a=i.steps.filter(e=>e.type!==`tokenMappings`&&n.STEP_TYPES[e.type]?.slot===`content`).length+n.tokensOf(i).length;return`Content ${t>0&&!a?`Reply`:a} → Targets ${n.targetsOf(e).length} → Responses ${r(`responses`)}`}var Gs=(e,t,n,r)=>x().withTarget(e,t,n,e=>{let t={...e,...r};for(let[e,n]of Object.entries(r))n===``&&e!==`prompt`&&e!==`system`&&delete t[e];return t}),Ks=(e,t,n)=>({...e,jobs:e.jobs.map((e,r)=>r===t?x().withOut(e,n(x().outOf(e))):e)}),qs=(e,t,n,r)=>Ks(e,t,e=>({...e,modifiers:e.modifiers.map((e,t)=>t===n?r:e)})),Js={metrics:{Editor:e=>(0,$.jsx)($s,{...e}),actions:(e,t,n)=>`dataset`in e&&e.dataset&&n.length?[{label:`Edit`,icon:y.edit,onSelect:()=>t(n[0].item)}]:[]}};function Ys({pipeline:e,datasets:t,graded:n,edit:r,offer:i,openCaseEditor:a,children:o,profiles:s=[],labGrader:c=null}){let[l,u]=(0,J.useState)(!1),[d,f]=(0,J.useState)(null),p=e.evals,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,$.jsxs)(U,{id:`evals`,title:`Evals`,level:2,note:p.length?String(p.length):`None`,children:[(0,$.jsx)(R,{noun:`eval`,items:p,empty:(0,$.jsx)(`p`,{className:`note`,children:`No evals — the run is unscored.`}),onAdd:()=>u(!0),onRename:e=>f(e),onRemove:t=>h(Ro(e,t),`Removed ${x().evalLabel(e,t)}`),extra:(t,r)=>[...Js[t.type]?.actions?.(t,a,n)??[],...x().EVAL_TYPES[t.type]?.toMetrics?[{label:`Convert to Metrics`,icon:y.edit,onSelect:()=>h(Vo(e,r,x().EVAL_TYPES[t.type].toMetrics(t)),`Converted ${x().evalLabel(e,r)} to Metrics`)}]:[],{label:`Move up`,icon:y.moveUp,disabled:r===0,onSelect:()=>h(zo(e,r,-1),`Moved ${x().evalLabel(e,r)} up`)},{label:`Move down`,icon:y.moveDown,disabled:r===p.length-1,onSelect:()=>h(zo(e,r,1),`Moved ${x().evalLabel(e,r)} down`)}],renderItem:(n,i,a)=>{let l=x().evalLabel(e,i),u=t=>r(Vo(e,i,t));return(0,$.jsxs)(U,{id:`eval-${i}`,title:l,level:3,note:x().EVAL_TYPES[n.type]?.label??n.type,about:x().EVAL_TYPES[n.type]?.description,actions:a,...d===i?{rename:{value:n.name||l,onCommit:t=>{r(Bo(e,i,t)),f(null)},onCancel:()=>f(null)}}:{},children:[(()=>{let r=Js[n.type]?.Editor;return r?(0,$.jsx)(r,{ev:n,label:l,set:u,datasets:t,profiles:s,labGrader:c,undoable:(t,n)=>h(Vo(e,i,t),n)}):null})(),(0,$.jsx)(N,{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,$.jsx)(Qs,{pipeline:e,datasets:t,onClose:()=>u(!1),onAdd:t=>{r(Lo(e,t)),u(!1)}})]})}function Xs(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 Zs(e,t){let n=x().outOf(e.jobs.at(-1)).kind;return Object.entries(x().EVAL_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 Qs({pipeline:e,datasets:t,onAdd:n,onClose:r}){let i=Zs(e,t),[a,o]=(0,J.useState)(i[0]?.id??``),[s,c]=(0,J.useState)(``),l=x().evalsDataset(e),[u,d]=(0,J.useState)(l??null),f=i.find(e=>e.id===a),p=[{key:`type`,label:`Type`,hint:x().EVAL_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:`Eval ${e.evals.length+1}`,onChange:c}},...f?.dataset&&t.length?[Xs(u,t,d,!0)]:[]];return(0,$.jsx)(j,{title:`Add eval`,...i.length?{}:{status:`No eval type reads what the last job answers with.`,statusBad:!0},sections:[{key:`eval`,rows:p}],focusRow:`type`,closeLabel:`Cancel`,actions:[{label:`Add`,icon:y.add,disabled:!f,onSelect:()=>f&&n(x().newEval(f.id,s.trim(),f.dataset&&u?{dataset:{id:u.id,name:u.name},metrics:[]}:{}))}],onClose:r})}function $s({ev:e,label:t,set:n,undoable:r,profiles:i,datasets:a,labGrader:o}){let s=x(),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,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{label:t,rows:u}),(0,$.jsx)(wr,{label:t,metrics:e.metrics,over:e.over??`item`,set:t=>n({...e,metrics:t}),undoable:(t,n)=>r({...e,metrics:t},n)})]})}function ec({pipeline:e,sourceFiles:t,graded:n,openCaseEditor:r}){let[i,a]=(0,J.useState)({graded:!1,todo:!0,missing:!0});if((x().evalsDataset(e)?.id??null)===null)return null;let o=t??[],s=new Set(n.map(e=>e.item)),c=new Set(o),l=[{key:`graded`,label:`Graded`,tone:`ok`,files:o.filter(e=>s.has(e))},{key:`todo`,label:`To do`,tone:`todo`,files:o.filter(e=>!s.has(e))},{key:`missing`,label:`Missing`,tone:`missing`,files:n.filter(e=>!c.has(e.item)).map(e=>e.item)}],u=l[0].files.length,d=l[1].files.length+l[2].files.length,f=l.filter(e=>i[e.key]).flatMap(e=>e.files.map(t=>({file:t,tone:e.tone})));return(0,$.jsx)(U,{id:`mapping`,title:`Mapping`,level:3,note:p(),about:`Which of the content's items the dataset has a case for, and so which are graded.`,children:o.length?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`p`,{className:`note`,children:[dn(n.length,`case`),` · `,u,` of `,o.length,` content items matched.`]}),(0,$.jsx)(`div`,{className:`mkey`,children:l.filter(e=>e.files.length).map(e=>(0,$.jsxs)(`button`,{type:`button`,className:`ghost chip-key${i[e.key]?` on`:``}`,"aria-pressed":i[e.key],onClick:()=>a({...i,[e.key]:!i[e.key]}),children:[e.label,` `,e.files.length]},e.key))}),f.length?(0,$.jsx)(`div`,{className:`mchips`,children:f.map(({file:e,tone:t})=>(0,$.jsx)(`button`,{type:`button`,className:`mchip ${t}`,onClick:()=>r(e),children:e},`${t}-${e}`))}):(0,$.jsx)(`p`,{className:`note`,children:d?`Nothing shown.`:`Every content item is graded.`})]}):(0,$.jsx)(`p`,{className:`note`,children:`No items in the content to map against.`})});function p(){let r=x().contentOf(e),i=r?x().CONTENT_TYPES[r.type]:void 0;if(i?.inline)return i.label;let a=t??[],o=new Set(n.map(e=>e.item)),s=a.filter(e=>o.has(e)).length;return`${dn(n.length,`case`)} · ${s} of ${a.length} matched`}}function tc({pipeline:e,edit:t,comment:n,setComment:r,onClear:i,onCopyFailures:a}){let s=[{label:`Clear comment`,icon:m,destructive:!0,onSelect:i},{label:`Copy last run's failures`,icon:o,onSelect:a}],c=x().contentOf(e),l=c?.type===`source`?[{key:`first`,label:`Run first`,control:{type:`text`,value:c.first==null?``:String(c.first),placeholder:`all`,onChange:n=>t(x().withContent(e,{...c,first:n.trim()?nc(n):null}))}},{key:`loops`,label:`Loop`,control:{type:`text`,value:String(c.loops),placeholder:`1`,onChange:n=>t(x().withContent(e,{...c,loops:Math.max(1,nc(n)??1)}))}}]:[];return(0,$.jsx)(U,{id:`control`,title:`Run settings`,level:2,actions:s,children:(0,$.jsx)(N,{label:`Run settings`,rows:[...l,{key:`comment`,label:`Comment`,control:{type:`text`,value:n,placeholder:`A note to find this run by in History`,onChange:e=>r(e)}}]})})}var nc=e=>{let t=Number.parseInt(e,10);return Number.isNaN(t)?null:t};function rc(){let e=ge(),t=Y(),n=ne(),{openRun:r}=Jt(),{openCaseEditor:i}=Br(),[a,o]=_e(`promptlab.workflows`),[s]=_e(`promptlab.profiles`),[c,l]=_e(`promptlab.comment`),[u]=_e(`promptlab.versions`),[d,f]=(0,J.useState)([]),{list:p,error:m}=Ie(),{list:h,error:g}=Ke(),_=h?.find(e=>e.default)??null,v=Fe(),y=(0,J.useMemo)(()=>(p??[]).map(e=>E(e.id,e.name)),[p]),[b,S]=(0,J.useState)(4),[C,w]=(0,J.useState)(void 0),[T,A]=(0,J.useState)(null),[j,M]=(0,J.useState)(!1),[N,P]=(0,J.useState)(!1),[ee,F]=(0,J.useState)(null),I=(0,J.useRef)(null),[L,te]=(0,J.useState)(null),R=(0,J.useRef)(null);(0,J.useEffect)(()=>{let e=!0;return t.sources().then(t=>{e&&f(t.sources)}).catch(()=>{}),t.config().then(t=>{e&&S(t.targetCap)}).catch(()=>{}),()=>{e=!1}},[t]),(0,J.useEffect)(()=>{let e=!0,n,r=async()=>{let i=5e3;try{let n=(await t.queue({limit:1})).runs[0]??null;if(!e)return;!I.current&&n&&!An(n.status)&&(I.current=n.id),n&&n.id===I.current&&(F(n),An(n.status)||(i=1e3))}catch{}e&&(n=setTimeout(()=>void r(),i))};return r(),()=>{e=!1,n&&clearTimeout(n)}},[t]);let z=(0,J.useMemo)(()=>a.list.filter(e=>e.work?.version===12),[a.list]),B=z.find(e=>e.id===a.at)??z[0],V=B?.work,re=B?.id??``,H=V?x().evalsDataset(V)?.id??null:null,ie=Le(H),U=ie?.doc?.body.cases,ae=(0,J.useMemo)(()=>(U??[]).map(e=>({id:e.id??``,item:x().caseItem(e)})),[U]),W=ie?.doc?.body.cases,G=(0,J.useMemo)(()=>[...new Set((W??[]).flatMap(e=>(e.metrics??[]).filter(e=>!e.not&&e.weight!==0&&(e.type===`contains-all`||e.type===`contains-any`)).flatMap(e=>x().metricLines(e.values))))],[W]),K=_?.text||V&&x().targetStepOf(V,x().targetsOf(V).length-1,0)?.prompt||``,q=(0,J.useRef)(s.list);q.current=s.list;let oe=z.length?null:p?.[0]??null,se=p!==null||m!==null,X=h!==null||g!==null,ce=_?.text??``;(0,J.useEffect)(()=>{if(z.length||!se||!X)return;let e=ac(q.current,oe?{id:oe.id,name:oe.name}:void 0,ce);o({list:[e],at:e.id})},[z.length,o,se,X,oe,ce]);let Z=()=>{let e=v.list().list?.[0];return e?{id:e.id,name:e.name}:void 0},Q=(0,J.useRef)(a);Q.current=a;let le=(0,J.useRef)(B);le.current=B;let ue=(0,J.useRef)(V);ue.current=V;let de=(0,J.useRef)(null),fe=(0,J.useRef)(null),pe=(0,J.useCallback)(()=>{fe.current&&clearTimeout(fe.current);let t=le.current?.id,n=ue.current;t&&n&&(de.current={id:t,doc:n},fe.current=setTimeout(()=>{let t=de.current;t&&Ae(e,`pipeline`,t.id,t.doc,`idle`)},Ee))},[e]);(0,J.useEffect)(()=>()=>{fe.current&&clearTimeout(fe.current)},[]);let me=(0,J.useCallback)(e=>{let t=Q.current,n=le.current.id,r={...t,at:n,list:t.list.filter(e=>e.work?.version===12).map(t=>t.id===n?{...t,work:e}:t)};Q.current=r,o(r),pe(),A(null)},[o,pe]),he=s.list[0]?.id??``;(0,J.useEffect)(()=>{let e=ue.current,t=le.current?.id;if(!e||!t||!he)return;let n=qo(e,Ho(q.current));if(n===e)return;let r=Q.current,i={...r,list:r.list.map(e=>e.id===t?{...e,work:n}:e)};Q.current=i,o(i)},[he,re,o]),(0,J.useEffect)(()=>{let t=de.current;t&&t.id!==re&&(Ae(e,`pipeline`,t.id,t.doc,`idle`),de.current=null,fe.current&&=(clearTimeout(fe.current),null))},[re,e]);let ve=V?x().contentOf(V):null,ye=ve?.type===`source`?ve.ref.id:null;(0,J.useEffect)(()=>{if(ye===null){w(void 0);return}let e=!0;return t.source(ye).then(t=>{e&&w(t.files.map(e=>e.name))}).catch(()=>{}),()=>{e=!1}},[ye,t]);let be=(0,J.useCallback)(e=>{let t=d.find(t=>t.id===e);return t?{name:t.name,type:t.type,files:e===ye&&C?C:[]}:null},[d,ye,C]),xe=(0,J.useMemo)(()=>{let e=s.list.find(e=>e.id===s.grader);return e?{id:e.id,name:e.name}:null},[s]),Se=(0,J.useMemo)(()=>{if(!V)return[];if(!s.list.length&&x().targetsOf(V).length)return[`add a Target profile first`];let e={profiles:e=>s.list.find(t=>t.id===e)??null,sources:be,grader:xe,...p?{datasets:p}:{}};return x().validatePipeline(V,e)},[V,s.list,be,p,xe]),Ce=re?u.pipeline?.[re]??[]:[],we=(0,J.useCallback)(async()=>{let n=ue.current,i=le.current.id;Ae(e,`pipeline`,i,n,`run`);let a=x().resolvePipeline(n,{profiles:e=>s.list.find(t=>t.id===e)??null,grader:xe,...ye!==null&&C!==void 0?{files:C}:{},comment:c?.text??``});M(!0),A(null);try{let e=await t.submit(a);I.current=e.run.id,F(e.run),r(e.run.id,{at:e.run.submittedAt,from:`runs`})}catch(e){A(e instanceof Error?e.message:String(e)),I.current=null,F(null)}finally{M(!1)}},[t,c,ye,r,s.list,C,e,xe]),Te=(0,J.useCallback)(async()=>{let e=I.current;if(e)try{F((await t.cancel(e)).run)}catch{}},[t]),De=(0,J.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(x().failedScore))).map(e=>e.name??`an item`);n.length&&await navigator.clipboard?.writeText(n.join(`
@@ -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-DyDG-V9N.js"></script>
8
+ <script type="module" crossorigin src="/assets/main-BkZTEix2.js"></script>
9
9
  <link rel="modulepreload" crossorigin href="/assets/tokens-DLRdTFGY.js">
10
10
  <link rel="stylesheet" crossorigin href="/assets/tokens-BEn6_hVz.css">
11
11
  <link rel="stylesheet" crossorigin href="/assets/main-C_b7QoTv.css">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evals-lab",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
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",