@botbuddy/react 0.13.0 → 0.15.0
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 +35 -0
- package/README.md +93 -1
- package/dist/index.cjs +12 -11
- package/dist/index.d.cts +47 -4
- package/dist/index.d.ts +47 -4
- package/dist/index.js +12 -11
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @botbuddy/react — Changelog
|
|
2
2
|
|
|
3
|
+
## 0.15.0
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **Drafts on your own branch (BOT-3169).** `ReleaseNoteDeliveryBadge` gains
|
|
8
|
+
`draft_on_your_branch` and `in_this_preview`. A local or preview viewer
|
|
9
|
+
token that names its branch gets that branch's draft notes with the copy
|
|
10
|
+
"Draft on your branch" or "In this preview"; the component shows the copy in
|
|
11
|
+
the `delivery` slot, and `data-bbrn-delivery` carries the badge for styling.
|
|
12
|
+
|
|
13
|
+
## 0.14.0
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- **`ReleaseNotes` styling: tokens, class slots and component overrides
|
|
18
|
+
(BOT-3159).** Tokens `--bbrn-accent`, `--bbrn-fg`, `--bbrn-bg`,
|
|
19
|
+
`--bbrn-muted`, `--bbrn-border`, `--bbrn-radius` and `--bbrn-font` (or the
|
|
20
|
+
`theme` prop with the same names unprefixed) default to the host's shadcn
|
|
21
|
+
variables (`--primary`, `--foreground`, `--card`, `--muted-foreground`,
|
|
22
|
+
`--border`, `--radius`) and otherwise to neutral values derived from the text
|
|
23
|
+
colour. `classNames` slots: `root`, `entry`, `head`, `title`, `badge`, `delivery`, `meta`,
|
|
24
|
+
`body`, `links`, `link`, `status`, `retry`. `components`: `Empty`, `Link`.
|
|
25
|
+
Token and slot names are a public interface; see the README.
|
|
26
|
+
- **The state badge** now shows next to the type badge, as text.
|
|
27
|
+
- **`useReleaseNotes` returns `stale`** and accepts `timeoutMs` (default 10000).
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
|
|
31
|
+
- The stylesheet is injected once per page as the first `<style>` in `<head>`
|
|
32
|
+
(it was one `<style>` inside each component). Every rule stays under
|
|
33
|
+
`.bbrn-root` inside `@layer bbrn`, so host rules win without `!important`.
|
|
34
|
+
- A feed that fails or takes longer than `timeoutMs` keeps showing the last good
|
|
35
|
+
feed for that endpoint and bearer from this page load; a refusal (401, 403, rejected
|
|
36
|
+
`getToken`) never does. A throwing override is contained inside the component.
|
|
37
|
+
|
|
3
38
|
## 0.13.0
|
|
4
39
|
|
|
5
40
|
### Added
|
package/README.md
CHANGED
|
@@ -139,9 +139,101 @@ const { run, widgetState, setVerdict, markComplete } = useTestRun({
|
|
|
139
139
|
const { pos, onPointerDown, onPointerMove, onPointerUp } = useDraggable(16, 600);
|
|
140
140
|
```
|
|
141
141
|
|
|
142
|
+
## Release notes
|
|
143
|
+
|
|
144
|
+
`ReleaseNotes` renders your tenant's BotBuddy release-notes feed. Note bodies
|
|
145
|
+
arrive as a syntax tree and render as React elements; there is no raw-HTML path.
|
|
146
|
+
|
|
147
|
+
```tsx
|
|
148
|
+
import { ReleaseNotes } from "@botbuddy/react";
|
|
149
|
+
|
|
150
|
+
<ReleaseNotes
|
|
151
|
+
endpoint={`${BOTBUDDY_API_URL}/functions/v1/mcp-server/release-notes/feed?tenant=acme`}
|
|
152
|
+
getToken={async () => mintViewerToken()}
|
|
153
|
+
onNavigate={(path) => router.push(path)}
|
|
154
|
+
/>;
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Styling
|
|
158
|
+
|
|
159
|
+
Three depths, from least to most control. Styling props change appearance only;
|
|
160
|
+
nothing about styling is sent to or stored by BotBuddy.
|
|
161
|
+
|
|
162
|
+
**1. Tokens.** Set `--bbrn-*` CSS variables on `.bbrn-root` (or any ancestor),
|
|
163
|
+
or pass the same names without the prefix in `theme`:
|
|
164
|
+
|
|
165
|
+
| Token | `theme` key | Controls | Default when the host defines it | Neutral default |
|
|
166
|
+
|---|---|---|---|---|
|
|
167
|
+
| `--bbrn-accent` | `accent` | badges, links, Retry | `hsl(var(--primary))` | the text colour |
|
|
168
|
+
| `--bbrn-fg` | `fg` | text | `hsl(var(--foreground))` | inherited |
|
|
169
|
+
| `--bbrn-bg` | `bg` | entry background | `hsl(var(--card))` | transparent |
|
|
170
|
+
| `--bbrn-muted` | `muted` | meta and status lines | `hsl(var(--muted-foreground))` | text colour at 72% |
|
|
171
|
+
| `--bbrn-border` | `border` | entry border, code background | `hsl(var(--border))` | text colour at 22% |
|
|
172
|
+
| `--bbrn-radius` | `radius` | entry corner radius | `var(--radius)` | `.5rem` |
|
|
173
|
+
| `--bbrn-font` | `font` | font family | — | inherited |
|
|
174
|
+
|
|
175
|
+
The host defaults read shadcn-style variables holding HSL triples
|
|
176
|
+
(`--primary: 262 83% 58%`), so a shadcn app's light and dark themes apply with no
|
|
177
|
+
props. The neutral defaults derive from the inherited text colour, so they stay
|
|
178
|
+
readable on a light or a dark page.
|
|
179
|
+
|
|
180
|
+
```tsx
|
|
181
|
+
<ReleaseNotes {...props} theme={{ accent: "#0a7", radius: "4px" }} />
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**2. Slots.** `classNames` adds your classes to each part (the component's own
|
|
185
|
+
`bbrn-*` class stays):
|
|
186
|
+
|
|
187
|
+
| Slot | Part |
|
|
188
|
+
|---|---|
|
|
189
|
+
| `root` | the `<section class="bbrn-root">` |
|
|
190
|
+
| `entry` | each `<article>` |
|
|
191
|
+
| `head` | the row holding title, badges and meta |
|
|
192
|
+
| `title` | each note title (`<h2>`) |
|
|
193
|
+
| `badge` | the type badge and the state badge (both always show their text) |
|
|
194
|
+
| `delivery` | where the note's change is ("Draft on PR #12", "Merged, not yet deployed") |
|
|
195
|
+
| `meta` | the source key and revision line |
|
|
196
|
+
| `body` | the wrapper around the note text |
|
|
197
|
+
| `links` | the row of links |
|
|
198
|
+
| `link` | each link |
|
|
199
|
+
| `status` | the loading, empty, unavailable and stale lines |
|
|
200
|
+
| `retry` | the Retry buttons |
|
|
201
|
+
|
|
202
|
+
`components` replaces whole parts:
|
|
203
|
+
|
|
204
|
+
| Component | Replaces | Props |
|
|
205
|
+
|---|---|---|
|
|
206
|
+
| `Empty` | the "No release notes yet" line | none |
|
|
207
|
+
| `Link` | each safe link's `<a>` | `href`, `external`, `kind`, `className`, `children`, `onClick` (app paths, when `onNavigate` is set) |
|
|
208
|
+
|
|
209
|
+
Unsafe links are dropped before `Link` is called.
|
|
210
|
+
|
|
211
|
+
**3. Headless.** `useReleaseNotes({ endpoint, getToken, timeoutMs? })` returns
|
|
212
|
+
`{ feed, error, loading, stale, reload }` for your own markup; it renders the same
|
|
213
|
+
entries in the same order as `ReleaseNotes`.
|
|
214
|
+
|
|
215
|
+
**Isolation.** Every rule is under `.bbrn-root` inside `@layer bbrn`, injected
|
|
216
|
+
once per page as the first `<style>` in `<head>`. Nothing outside the component
|
|
217
|
+
is styled, and any rule of yours beats the component's without `!important`.
|
|
218
|
+
That includes unlayered resets: Tailwind v3's preflight removes the entry
|
|
219
|
+
border, list bullets and title weight, so a Tailwind v3 host restores what it
|
|
220
|
+
wants through the slots, for example
|
|
221
|
+
`classNames={{ entry: "border", title: "font-semibold", body: "[&_ul]:list-disc [&_ul]:pl-5" }}`.
|
|
222
|
+
|
|
223
|
+
### Failure
|
|
224
|
+
|
|
225
|
+
The component never throws into your app and never blocks its render. A feed
|
|
226
|
+
that fails, takes longer than `timeoutMs` (default 10 seconds) or cannot be
|
|
227
|
+
parsed shows "Release notes could not be loaded." with a Retry button, or, if
|
|
228
|
+
the same endpoint loaded earlier in this page load with the same bearer, that
|
|
229
|
+
last good feed with a "could not be refreshed" line. A different bearer (another
|
|
230
|
+
signed-in user) never sees a cached feed. A refusal (401, 403 or a rejected `getToken`)
|
|
231
|
+
always shows the unavailable line and never a cached feed. An override that
|
|
232
|
+
throws is contained the same way; Retry or new overrides try it again.
|
|
233
|
+
|
|
142
234
|
## Zero Dependencies
|
|
143
235
|
|
|
144
|
-
The widget uses inline styles and inline SVG icons — no Tailwind, no icon library, no CSS imports needed.
|
|
236
|
+
The widget uses inline styles and inline SVG icons, and `ReleaseNotes` injects its own plain-CSS sheet — no Tailwind, no icon library, no CSS imports needed. React is the only peer dependency.
|
|
145
237
|
|
|
146
238
|
## License
|
|
147
239
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
'use strict';var react=require('react'),reactDom=require('react-dom'),jsxRuntime=require('react/jsx-runtime');var Se=8;function qe(e,n,i,d,a,s){let _=Math.max(Se,a-i-Se),k=Math.max(Se,s-d-Se);return {x:Math.min(Math.max(e,Se),_),y:Math.min(Math.max(n,Se),k)}}function Ge(e,n){let[i,d]=react.useState({x:e,y:n}),a=react.useRef(false),s=react.useRef({x:0,y:0}),_=react.useRef(false),k=react.useCallback(h=>{a.current=true,_.current=false,s.current={x:h.clientX-i.x,y:h.clientY-i.y},h.target.setPointerCapture(h.pointerId);},[i]),y=react.useCallback(h=>{a.current&&(_.current=true,d({x:h.clientX-s.current.x,y:h.clientY-s.current.y}));},[]),p=react.useCallback(()=>{a.current=false;},[]);return {pos:i,setPos:d,onPointerDown:k,onPointerMove:y,onPointerUp:p,didDrag:_}}function Xe(e,n,i){let d=react.useRef(i);d.current=i,react.useEffect(()=>{if(!n)return;if(e.supabaseUrl){let s=false,_=null,k=()=>{s||_||(_=setInterval(()=>d.current(),15e3));},y=null;try{let x=new URL(e.supabaseUrl),r=["localhost","127.0.0.1","::1"].includes(x.hostname);if(x.protocol==="http:"&&!r)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");x.protocol=x.protocol==="https:"?"wss:":"ws:",y=x.toString().replace(/\/$/,"");}catch{k();}let p=null,h=null,T=null,V=0,M=()=>{if(!(s||!y)){try{p=new WebSocket(`${y}/realtime/v1/websocket?apikey=${e.anonKey}&vsn=1.0.0`);}catch{k();return}p.onopen=()=>{if(s||!p)return;let x={topic:`realtime:public:test_run_cases:test_run_id=eq.${n}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_run_cases",filter:`test_run_id=eq.${n}`}]}},ref:String(++V)};p.send(JSON.stringify(x));let r={topic:`realtime:public:test_runs:id=eq.${n}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_runs",filter:`id=eq.${n}`}]}},ref:String(++V)};p.send(JSON.stringify(r)),h=setInterval(()=>{p?.readyState===WebSocket.OPEN&&p.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++V)}));},3e4);},p.onmessage=x=>{try{JSON.parse(x.data).event==="postgres_changes"&&d.current();}catch{}},p.onclose=()=>{v(),s||(T=setTimeout(M,3e3));},p.onerror=()=>{p?.close();};}},v=()=>{h&&(clearInterval(h),h=null);};return M(),()=>{s=true,v(),T&&clearTimeout(T),_&&clearInterval(_),p&&(p.onclose=null,p.onerror=null,p.close());}}let a=setInterval(()=>d.current(),15e3);return ()=>clearInterval(a)},[e.supabaseUrl,e.anonKey,n]);}var Qt="botbuddy:created-test-run:";function en(e){if(!e)return "";try{return new URL(e).origin}catch{return e}}function tn(e){return `${Qt}${encodeURIComponent([e.appSlug,e.environment||"",e.ticketId||"",en(e.targetUrl),e.branchName||""].join("|"))}`}function Ue(e,n){let i={apikey:e.anonKey};return n?i.Authorization=`Bearer ${n}`:e.apiKey?i.Authorization=`Bearer ${e.apiKey}`:i.Authorization=`Bearer ${e.anonKey}`,i}async function nn(e){if(e)return e;try{let n=await fetch("/.botbuddy-token",{cache:"no-store"});if(n.ok){let i=(await n.text()).trim();if(i.startsWith("public_"))return i}}catch{}try{let n=undefined?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(n&&typeof n=="string"&&n.startsWith("public_"))return n}catch{}return null}function Qe(e){let[n,i]=react.useState(null),[d,a]=react.useState("loading"),s=tn(e),[_,k]=react.useState(()=>{if(e.testRunId)return e.testRunId;try{return localStorage.getItem(s)||void 0}catch{return}}),y=e.testRunId||_,p=react.useCallback(v=>{if(i(v),!!v?.id){k(v.id);try{localStorage.setItem(s,v.id);}catch{}}},[s]),h=react.useCallback(async()=>{try{let v=await nn(e.testRunToken);if(!v&&!y){a("no-match"),i(null);return}if(v&&!e.ticketId){a("no-match"),i(null);return}let x=new URLSearchParams;v&&x.set("token",v),e.ticketId&&x.set("ticket_id",e.ticketId),x.set("app_slug",e.appSlug),e.environment&&x.set("environment",e.environment),y&&x.set("test_run_id",y),e.targetUrl&&x.set("target_url",e.targetUrl),e.version&&x.set("version",e.version),e.commitSha&&x.set("commit_sha",e.commitSha),e.prNumber&&x.set("pr_number",String(e.prNumber)),e.branchName&&x.set("branch_name",e.branchName);let r=await fetch(`${e.config.serverUrl}/widget/test-run?${x.toString()}`,{headers:Ue(e.config,e.authToken)});if(r.status===404){a("no-match"),i(null);return}if(r.status===401||r.status===403){e.authToken&&e.onAuthExpired&&e.onAuthExpired(),a("error");return}if(!r.ok){a("error");return}let u=await r.json();if(!u||u.run===null){a("no-match"),i(null);return}p(u),a(u.status==="completed"?"completed":"ready");}catch{a("error");}},[e.config.serverUrl,e.config.anonKey,e.config.apiKey,e.authToken,e.appSlug,e.environment,e.ticketId,y,e.testRunToken,e.targetUrl,e.version,e.commitSha,e.branchName,e.prNumber,e.onAuthExpired,p]);return react.useEffect(()=>{h();},[h]),Xe(e.config,n?.id,h),{run:n,widgetState:d,fetchRun:h,setVerdict:async(v,x,r,u="human")=>(i(U=>{if(!U)return null;let q=U.test_cases.map(I=>I.id===v?{...I,verdict:x,fail_reason:x==="fail"&&r||null,verdict_by_display_name:u,verdict_at:new Date().toISOString()}:I),Y={total:q.length,pending:0,pass:0,fail:0,skip:0};return q.forEach(I=>{I.verdict in Y&&Y[I.verdict]++;}),{...U,test_cases:q,summary:Y}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${v}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...Ue(e.config,e.authToken)},body:JSON.stringify({verdict:x,fail_reason:r,display_name:u})})).ok),markComplete:async()=>n?(i(x=>x?{...x,status:"completed"}:null),a("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${n.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...Ue(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!n)return false;let v=await fetch(`${e.config.serverUrl}/widget/test-runs/${n.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...Ue(e.config,e.authToken)}});return v.ok&&h(),v.ok},setRun:p}}var nt="botbuddy-widget-auth-token",rt="botbuddy-widget-auth-name";function Ee(e){if(!e)return null;try{let n=e.split(".")[1];if(!n)return null;let i=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(n.length/4)*4,"="),d=atob(i),a=JSON.parse(d);return typeof a.exp=="number"?a.exp*1e3:null}catch{return null}}var on=2500,sn=6e4;function ot(e){let[n,i]=react.useState(()=>{try{return localStorage.getItem(nt)}catch(M){return console.warn("Unable to read BotBuddy widget auth token",M),null}}),[d,a]=react.useState(()=>{try{return localStorage.getItem(rt)}catch(M){return console.warn("Unable to read BotBuddy widget display name",M),null}}),s=react.useRef(null),_=react.useCallback((M,v)=>{i(M),v&&a(v);try{localStorage.setItem(nt,M),v&&localStorage.setItem(rt,v);}catch(x){console.warn("Unable to persist BotBuddy widget auth token",x);}},[]);react.useEffect(()=>{let M=new URL(e).origin,v=x=>{x.origin===M&&x.data?.type==="botbuddy-widget-auth"&&x.data.token&&_(x.data.token,x.data.displayName||"human");};return window.addEventListener("message",v),()=>window.removeEventListener("message",v)},[e,_]);let k=react.useCallback(()=>{if(s.current)return s.current;if(typeof window>"u"||typeof document>"u")return Promise.resolve(null);let M=new URL(e).origin,v=new URL("/widget-auth",e);v.searchParams.set("silent","1"),v.searchParams.set("origin",window.location.origin);let x=new Promise(r=>{let u=document.createElement("iframe");u.setAttribute("aria-hidden","true"),u.style.position="fixed",u.style.width="1px",u.style.height="1px",u.style.opacity="0",u.style.pointerEvents="none",u.style.border="0",u.style.left="-9999px",u.style.top="-9999px",u.src=v.toString();let J=false,U=()=>{window.removeEventListener("message",q),clearTimeout(Y);try{u.remove();}catch{}s.current=null;},q=I=>{if(I.origin===M){if(I.data?.type==="botbuddy-widget-auth-failed"){if(J)return;J=true,r(null),U();return}I.data?.type!=="botbuddy-widget-auth"||!I.data.token||J||(J=true,r(String(I.data.token)),U());}},Y=setTimeout(()=>{J||(J=true,r(null),U());},on);window.addEventListener("message",q),document.body.appendChild(u);});return s.current=x,x},[e]);react.useEffect(()=>{if(!n)return;let M=Ee(n);if(!M)return;let v=M-Date.now()-sn,x=window.setTimeout(()=>{k();},Math.max(0,v));return ()=>window.clearTimeout(x)},[n,k]);let y=react.useCallback(()=>{let M=new URL("/widget-auth",e);M.searchParams.set("origin",window.location.origin);let v=420,x=520,r=window.screenX+(window.innerWidth-v)/2,u=window.screenY+(window.innerHeight-x)/2;window.open(M.toString(),"botbuddy-auth",`width=${v},height=${x},left=${r},top=${u},popup=yes`);},[e]),[,p]=react.useState(0);react.useEffect(()=>{let M=Ee(n);if(!M)return;let v=M-Date.now();if(v<=0)return;let x=window.setTimeout(()=>p(r=>r+1),v);return ()=>window.clearTimeout(x)},[n]);let h=react.useCallback(()=>{i(null),a(null);try{localStorage.removeItem(nt),localStorage.removeItem(rt);}catch(M){console.warn("Unable to clear BotBuddy widget auth token",M);}},[]),T=Ee(n),V=T!==null&&T<=Date.now();return {token:n,displayName:d,isAuthenticated:!!n,isExpired:V,openLogin:y,refreshNow:k,logout:h}}var Ie=null;function an(){try{if(typeof document<"u"){let e=document.querySelector("base[href]");if(e)return new URL(".botbuddy-totp.json",e.href).toString()}}catch{}return "/.botbuddy-totp.json"}function Fe(){return Ie||(Ie=(async()=>{if(typeof fetch>"u")return null;try{let e=await fetch(an(),{cache:"no-store"});if(!e.ok)return null;let n=await e.json();if(!n||typeof n!="object"||Array.isArray(n))return null;let i={};for(let[d,a]of Object.entries(n))typeof a=="string"&&a.length>0&&(i[d]=a);return i}catch{return null}})(),Ie)}async function Pt(e){return (await Fe())?.[e]??null}function ln(e){let n=e.replace(/=+$/,"").replace(/\s+/g,"").toUpperCase(),i="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",d=[],a=0,s=0;for(let _ of n){let k=i.indexOf(_);if(k<0)throw new Error("Invalid Base32 character in TOTP secret");s=s<<5|k,a+=5,a>=8&&(a-=8,d.push(s>>>a&255));}return Uint8Array.from(d)}async function Et(e,n=Date.now()){if(typeof crypto>"u"||!crypto.subtle)throw new Error("Web Crypto unavailable");let i=ln(e),d=new Uint8Array(i.byteLength);d.set(i);let a=Math.floor(n/1e3/30),s=new Uint8Array(8),_=Math.floor(a/4294967296),k=a>>>0;s[0]=_>>>24&255,s[1]=_>>>16&255,s[2]=_>>>8&255,s[3]=_&255,s[4]=k>>>24&255,s[5]=k>>>16&255,s[6]=k>>>8&255,s[7]=k&255;let y=await crypto.subtle.importKey("raw",d,{name:"HMAC",hash:"SHA-1"},false,["sign"]),p=await crypto.subtle.sign("HMAC",y,s),h=new Uint8Array(p),T=h[h.length-1]&15;return (((h[T]&127)<<24|(h[T+1]&255)<<16|(h[T+2]&255)<<8|h[T+3]&255)%1e6).toString().padStart(6,"0")}var Lt="0.11.0";function cn(e){let n=new Date(e),d=Date.now()-n.getTime();if(d<6e4)return "just now";if(d<36e5)return `${Math.floor(d/6e4)}m ago`;if(d<864e5)return `${Math.floor(d/36e5)}h ago`;let a=n.getDate(),s=n.toLocaleString("en",{month:"short"}),_=n.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${s} ${a}, ${_}`}var S=({d:e,className:n,size:i=14})=>jsxRuntime.jsx("svg",{className:n,width:i,height:i,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:e})}),m={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01",bot:"M12 8V4H8M2 14h2M20 14h2M15 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M9 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M18 10a6 6 0 0 0-12 0v4a6 6 0 0 0 12 0Z",terminal:"M4 17l6-6-6-6M12 19h8",key:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4",shield:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10",copy:"M20 9h-9a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2-2v-9a2 2 0 0 0-2-2ZM5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1",search:"M11 17.25a6.25 6.25 0 1 1 0-12.5 6.25 6.25 0 0 1 0 12.5ZM16 16l4.5 4.5"};function un(){let[e,n]=react.useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return react.useEffect(()=>{if(typeof window>"u")return;let i=document.documentElement,d=()=>i.classList.contains("dark")?"dark":i.classList.contains("light")?"light":null,a=d();a&&n(a);let s=window.matchMedia("(prefers-color-scheme: dark)"),_=y=>{let p=d();n(p||(y.matches?"dark":"light"));};s.addEventListener("change",_);let k=new MutationObserver(()=>{let y=d();n(y||(s.matches?"dark":"light"));});return k.observe(i,{attributes:true,attributeFilter:["class"]}),()=>{s.removeEventListener("change",_),k.disconnect();}},[]),e}function pn(e){let n=e==="dark";return {bg:n?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:n?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:n?"#e5e5e5":"#1a1a1a",textMuted:n?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:n?"#555":"#999",border:n?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:n?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:n?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:n?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:n?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:n?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:n?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:n?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:n?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:n?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:n?"#888":"#aaa",btnHover:n?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var gn={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},fn={pending:m.circle,pass:m.check,fail:m.x,skip:m.skip},Nt={local:{bg:"rgba(59,130,246,0.15)",text:"#60a5fa",border:"rgba(59,130,246,0.3)"},preview:{bg:"rgba(168,85,247,0.15)",text:"#c084fc",border:"rgba(168,85,247,0.3)"},staging:{bg:"rgba(245,158,11,0.15)",text:"#fbbf24",border:"rgba(245,158,11,0.3)"},production:{bg:"rgba(239,68,68,0.15)",text:"#f87171",border:"rgba(239,68,68,0.3)"},custom:{bg:"rgba(128,128,128,0.15)",text:"#888",border:"rgba(128,128,128,0.3)"}},bn=["app.supply-guard.io"];function mn(e,n=[]){if(!e)return false;let i=e.toLowerCase();return [...bn,...n].map(a=>a.toLowerCase()).includes(i)}var yn=e=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:n=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:e.bg,border:n?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:n?`0 4px 12px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 4px 12px ${e.shadow}`,cursor:"pointer",fontSize:"9px",color:e.text}),card:(n,i)=>({width:`${n}px`,borderRadius:"8px",background:e.bg,border:i?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:i?`0 8px 24px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 8px 24px ${e.shadow}`,overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:`1px solid ${e.borderSubtle}`},title:{fontSize:"10px",fontWeight:600,color:e.text,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:e.textMuted,display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:e.gripColor,display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:`1px solid ${e.borderSubtle}`},badge:n=>{let i=Nt[n]||Nt.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:i.bg,color:i.text,border:`1px solid ${i.border}`,lineHeight:"14px"}},progress:{height:"2px",background:e.borderSubtle,flexShrink:0},progressBar:n=>({height:"100%",width:`${n}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:n=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${n}15`,color:n,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${e.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(n,i)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:n?`${i}33`:"transparent",color:n?i:e.gripColor,transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:e.inputBg,border:`1px solid ${e.inputBorder}`,borderRadius:"4px",padding:"2px 6px",color:e.text,outline:"none"},humanBanner:{padding:"6px 12px",fontSize:"11px",fontWeight:600,color:e.green,borderBottom:`1px solid ${e.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",background:e.greenBg,cursor:"pointer",textDecoration:"none"}});function it(e){return e.split("/")[0].trim()}async function hn(e){try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}try{if(typeof document>"u")return !1;let n=document.createElement("textarea");n.value=e,n.setAttribute("readonly",""),n.style.position="fixed",n.style.top="0",n.style.left="0",n.style.opacity="0",n.style.pointerEvents="none",document.body.appendChild(n),n.focus(),n.select(),n.setSelectionRange(0,e.length);let i=document.execCommand("copy");return document.body.removeChild(n),i}catch{return false}}function Le({config:e,appSlug:n,environment:i,seededUsers:d,authToken:a,tk:s,compact:_=false,onExpand:k,onAuthExpired:y,refreshAuth:p,requestLogin:h,testRunId:T,testRunToken:V,ticketId:M,targetUrl:v,version:x,commitSha:r,prNumber:u,branchName:J}){let[U,q]=react.useState(false),[Y,I]=react.useState(null),[$,Me]=react.useState(null),[se,f]=react.useState(null),[Ne,ae]=react.useState(null),[ne,X]=react.useState(null),[Z,le]=react.useState(null);react.useEffect(()=>{i==="local"&&Fe();},[i]);let ye=react.useCallback(c=>{I(c),f(null),ae(null),le(null);let L=Ee(a);if(i!=="local"&&h&&L!==null&&L<=Date.now()){X({slug:c,token:a||null}),le(c),I(null),h();return}let P=C=>{f(C),ae(c),window.setTimeout(()=>{ae(E=>E===c?null:E),f(E=>E===C?null:E);},3e3);},R=new URLSearchParams({app_slug:n,seed_user_slug:c,environment:i});T&&R.set("test_run_id",T),V&&R.set("public_token",V),M&&R.set("ticket_id",M),v&&R.set("target_url",v),x&&R.set("version",x),r&&R.set("commit_sha",r),u&&R.set("pr_number",String(u)),J&&R.set("branch_name",J);let N=async C=>{let E={apikey:e.anonKey,Authorization:`Bearer ${C}`};try{let z=await fetch(`${e.serverUrl}/widget/totp-code?${R}`,{headers:E});if(!z.ok){let fe=await z.json().catch(()=>({error:`HTTP ${z.status}`}));return {ok:!1,status:z.status,error:fe.error||`HTTP ${z.status}`}}let G=await z.json();return {ok:!0,code:String(G.code)}}catch{return {ok:false,status:0,error:"Network error"}}},D=(async()=>{if(i==="local"){let z=await Pt(c);if(z)try{return {ok:!0,code:await Et(z)}}catch{}}let C=await N(a||e.anonKey);if(C.ok||C.status!==401||!p)return C;let E=await p();return E?N(E):{ok:false,status:401,error:"Sign in to BotBuddy to refresh 2FA"}})(),A=null;try{if(typeof ClipboardItem<"u"&&navigator.clipboard?.write){let C=D.then(E=>{if(!E.ok)throw new Error(E.error);return new Blob([E.code],{type:"text/plain"})});A=navigator.clipboard.write([new ClipboardItem({"text/plain":C})]).then(()=>!0).catch(()=>!1);}}catch{}(async()=>{let C=await D;if(!C.ok){C.status===401?(X({slug:c,token:a||null}),le(c)):P(C.status===404?"No 2FA seed registered":C.error),I(null);return}let E=A?await A:false,z=E?true:await hn(C.code),G=E||z;Me({slug:c,code:C.code,copied:G}),window.setTimeout(()=>Me(fe=>fe?.slug===c?null:fe),G?2500:6e3),q(false),I(null);})();},[e.serverUrl,e.anonKey,a,n,i,T,V,M,v,x,r,u,J,p,h]),oe=react.useCallback(c=>{X({slug:c,token:a||null}),h?.();},[a,h]),he=react.useCallback(c=>{Z===c?oe(c):ye(c);},[Z,oe,ye]);react.useEffect(()=>{if(!ne||!a||a===ne.token)return;let c=ne.slug;X(null),ye(c);},[a,ye,ne]);let xe=react.useRef(null),Ce=react.useRef(null);if(react.useLayoutEffect(()=>{if(!U)return;let c=xe.current,L=Ce.current;if(!c||!L||typeof window>"u")return;let P=()=>{let R=c.getBoundingClientRect(),N=L.getBoundingClientRect(),D=window.innerWidth,A=window.innerHeight,C=R.left,E=R.top-N.height-6;E<8&&(E=R.bottom+6);let z=Math.max(8,D-N.width-8),G=Math.max(8,A-N.height-8);C=Math.min(Math.max(C,8),z),E=Math.min(Math.max(E,8),G),L.style.left=`${Math.round(C)}px`,L.style.top=`${Math.round(E)}px`;};return P(),window.addEventListener("scroll",P,true),window.addEventListener("resize",P),()=>{window.removeEventListener("scroll",P,true),window.removeEventListener("resize",P);}},[U,d.length,se]),react.useEffect(()=>{if(!U)return;let c=L=>{let P=L.target;Ce.current?.contains(P)||xe.current?.contains(P)||q(false);};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[U]),d.length===0)return null;if(_){let c=d.length>1,L=d[0],P=!c&&Z===L,R=z=>{if(z.stopPropagation(),c&&k){k();return}he(L);},N=!!Ne,D=!!$,A=D&&$.copied,C=D&&!$.copied,E=P?s.blue:N?s.red:A?s.green:C?s.amber:s.purple;return jsxRuntime.jsxs("span",{onPointerDown:z=>z.stopPropagation(),onPointerUp:z=>z.stopPropagation(),onPointerMove:z=>z.stopPropagation(),onClick:R,style:{display:"inline-flex",alignItems:"center",gap:"3px",color:E,fontWeight:600,cursor:"pointer",letterSpacing:C?"0.08em":void 0},title:P?"Sign in to BotBuddy to refresh 2FA":N?se||"Failed":C?`Clipboard blocked \u2014 code: ${$.code}`:c?`${d.length} 2FA personas`:`Copy 2FA code for ${d[0]}`,children:[jsxRuntime.jsx(S,{d:P?m.key:N?m.alert:A?m.check:C?m.copy:m.shield,size:10}),P?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Sign in"}):A?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Copied"}):C?jsxRuntime.jsx(jsxRuntime.Fragment,{children:$.code}):N?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Failed"}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["2FA",c&&` \xB7${d.length}`]})]})}if(d.length===1){let c=d[0],L=Y===c,P=$?.slug===c,R=P&&$.copied,N=P&&!$.copied,D=Ne===c,A=Z===c,C=A?s.blue:D?s.red:R?s.green:N?s.amber:s.purple;return jsxRuntime.jsxs("button",{onClick:E=>{E.stopPropagation(),he(c);},disabled:L,style:{...Bt(C),cursor:L?"wait":"pointer",opacity:L?.6:1},title:A?"Sign in to BotBuddy to refresh 2FA":D?se||"Failed":N?`Clipboard blocked \u2014 code: ${$.code}`:`Copy 2FA code for ${c}`,children:[jsxRuntime.jsx(S,{d:A?m.key:D?m.alert:R?m.check:N?m.copy:m.shield,size:12}),A?"Sign in":R?"Copied":N?$.code:D?"Failed":L?"\u2026":`2FA \xB7 ${c}`]})}let de=!!Z&&!U,Q=!!Ne&&!U,ve=!!$&&$.copied,we=!!$&&!$.copied,Oe=de?s.blue:Q?s.red:ve?s.green:we?s.amber:s.purple,He=U&&typeof document<"u"?reactDom.createPortal(jsxRuntime.jsxs("div",{ref:Ce,onPointerDown:c=>c.stopPropagation(),onMouseDown:c=>c.stopPropagation(),style:{position:"fixed",left:-9999,top:-9999,background:s.bg,border:`1px solid ${s.border}`,borderRadius:6,boxShadow:`0 8px 24px ${s.shadow}`,padding:4,minWidth:220,maxWidth:typeof window<"u"?Math.min(420,window.innerWidth-16):420,zIndex:1e5,fontFamily:"ui-monospace, SFMono-Regular, monospace"},children:[d.map(c=>{let L=Y===c,P=Z===c;return jsxRuntime.jsxs("button",{onClick:R=>{R.stopPropagation(),he(c);},disabled:L,style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 8px",background:"transparent",border:"none",borderRadius:4,cursor:L?"wait":"pointer",fontSize:"10px",color:P?s.blue:s.text,textAlign:"left",fontFamily:"ui-monospace, SFMono-Regular, monospace"},title:P?"Sign in to BotBuddy to refresh 2FA":void 0,onMouseEnter:R=>R.currentTarget.style.background=s.btnHover,onMouseLeave:R=>R.currentTarget.style.background="transparent",children:[jsxRuntime.jsx(S,{d:P?m.key:m.shield,size:10}),jsxRuntime.jsx("span",{style:{flex:1,overflowWrap:"anywhere",lineHeight:1.3},children:c}),P?jsxRuntime.jsx("span",{style:{color:s.blue,fontSize:9},children:"Sign in"}):L?jsxRuntime.jsx("span",{style:{color:s.textMuted,fontSize:9},children:"\u2026"}):null]},c)}),se&&jsxRuntime.jsx("div",{style:{padding:"4px 8px",fontSize:9,color:s.red},children:se})]}),document.body):null;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("button",{ref:xe,onClick:c=>{if(c.stopPropagation(),de&&Z){oe(Z);return}q(L=>!L),f(null),ae(null);},style:{...Bt(Oe),cursor:"pointer"},title:de?"Sign in to BotBuddy to refresh 2FA":Q?se||"Failed":we?`Clipboard blocked \u2014 code: ${$.code}`:"Choose a persona to copy a 2FA code for",children:[jsxRuntime.jsx(S,{d:de?m.key:Q?m.alert:ve?m.check:we?m.copy:m.shield,size:12}),de?"Sign in":ve?"Copied":we?$.code:Q?"Failed":`2FA \xB7 ${d.length}`,!de&&jsxRuntime.jsx(S,{d:U?m.chevronUp:m.chevronDown,size:8})]}),He]})}function Bt(e){return {display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${e}15`,color:e,textDecoration:"none",border:`1px solid ${e}30`}}var zt="botbuddy-widget-state";function xn({config:e,appSlug:n,environment:i,ticketId:d,testRunId:a,testRunToken:s,targetUrl:_,version:k,commitSha:y,prNumber:p,branchName:h,onNavigate:T,displayName:V="human",defaultMode:M="mini",defaultPosition:v}){let x=un(),r=react.useMemo(()=>pn(x),[x]),u=react.useMemo(()=>yn(r),[r]),[J,U]=react.useState(false),[q,Y]=react.useState(false),[I,$]=react.useState(false),Me=react.useRef(false),se=e.dashboardUrl||"https://app.bot-buddy.ai",f=ot(se),ae=(()=>{try{let t=typeof window<"u"?localStorage.getItem(zt):null;if(t)return JSON.parse(t)}catch{}return null})(),[ne,X]=react.useState(ae?.mode||M),[Z,le]=react.useState(""),[ye,oe]=react.useState(null),[he,xe]=react.useState(null),[Ce,de]=react.useState(new Set),[Q,ve]=react.useState(""),we=react.useCallback(t=>{de(g=>{let w=new Set(g);return w.has(t)?w.delete(t):w.add(t),w});},[]),Oe=ae?.x??v?.x??16,He=ae?.y??v?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:c,setPos:L,onPointerDown:P,onPointerMove:R,onPointerUp:N,didDrag:D}=Ge(Oe,He),A=react.useRef(null);react.useEffect(()=>{try{localStorage.setItem(zt,JSON.stringify({mode:ne,x:c.x,y:c.y}));}catch{}},[ne,c.x,c.y]),react.useLayoutEffect(()=>{if(typeof window>"u")return;let t=A.current;if(!t)return;let g=t.getBoundingClientRect(),w=qe(c.x,c.y,g.width,g.height,window.innerWidth,window.innerHeight);(w.x!==c.x||w.y!==c.y)&&L(w);}),react.useEffect(()=>{if(typeof window>"u")return;let t=()=>{let g=A.current;if(!g)return;let w=g.getBoundingClientRect(),W=qe(c.x,c.y,w.width,w.height,window.innerWidth,window.innerHeight);(W.x!==c.x||W.y!==c.y)&&L(W);};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[c.x,c.y,L]);let C=react.useRef(f.isAuthenticated);react.useEffect(()=>{!C.current&&f.isAuthenticated&&X("max"),C.current=f.isAuthenticated;},[f.isAuthenticated]);let E="botbuddy-widget-max-size",z=()=>{try{let t=localStorage.getItem(E);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[G,fe]=react.useState(z),Te=react.useRef(false),Pe=react.useRef({x:0,y:0,w:0,h:0}),It=react.useCallback(t=>{t.stopPropagation(),Te.current=true,Pe.current={x:t.clientX,y:t.clientY,w:G.w,h:G.h},t.target.setPointerCapture(t.pointerId);},[G]),Ft=react.useCallback(t=>{if(!Te.current)return;let g=Math.max(280,Math.min(600,Pe.current.w+(t.clientX-Pe.current.x))),w=Math.max(300,Math.min(window.innerHeight*.9,Pe.current.h+(t.clientY-Pe.current.y)));fe({w:g,h:w});},[]),Dt=react.useCallback(()=>{Te.current&&(Te.current=false,fe(t=>(localStorage.setItem(E,JSON.stringify(t)),t)));},[]),ee=_??(typeof window<"u"?window.location.href:void 0),at=f.displayName||V,[ie,lt]=react.useState(null);react.useEffect(()=>{if(f.isAuthenticated)return;let t=new URLSearchParams;s&&t.set("token",s),d&&t.set("ticket_id",d),t.set("app_slug",n),i&&t.set("environment",i),a&&t.set("test_run_id",a),ee&&t.set("target_url",ee),k&&t.set("version",k),y&&t.set("commit_sha",y),p&&t.set("pr_number",String(p)),h&&t.set("branch_name",h),fetch(`${e.serverUrl}/widget/preview?${t}`,{headers:{apikey:e.anonKey}}).then(g=>g.json()).then(g=>lt(g)).catch(()=>lt(null));},[f.isAuthenticated,e.serverUrl,e.anonKey,n,i,d,a,s,ee,k,y,p,h]);let dt=react.useRef(false),Ot=react.useCallback(()=>{dt.current||f.logout();},[f.logout]),{run:b,widgetState:be,fetchRun:Ht,setVerdict:ct,markComplete:Kt,resetRun:jt,setRun:ut}=Qe({config:e,appSlug:n,environment:i,ticketId:d,testRunId:a,testRunToken:s,targetUrl:ee,version:k,commitSha:y,prNumber:p?String(p):void 0,branchName:h,authToken:f.token,onAuthExpired:Ot});dt.current=!!b;let[pt,gt]=react.useState([]),[ft,Be]=react.useState([]),[Ke,bt]=react.useState(false),[mt,yt]=react.useState(null),[Vt,ze]=react.useState(false),ce=mn(typeof window<"u"?window.location.hostname:void 0,e.productionHostnames||[]);react.useEffect(()=>{if((i??"local")!=="local"||ce){gt([]);return}let t=true;return Fe().then(g=>{t&>(Object.keys(g||{}));}),()=>{t=false;}},[i,ce]);let Yt=react.useCallback(async()=>{if(!(!f.isAuthenticated||!f.token)){bt(true),yt(null);try{let t=await fetch(`${e.serverUrl}/widget/test-runs`,{method:"POST",headers:{"Content-Type":"application/json",apikey:e.anonKey,Authorization:`Bearer ${f.token}`},body:JSON.stringify({app_slug:n,environment:i||"local",target_url:ee,branch_name:h,commit_sha:y,pr_number:p,ticket_id:d,title:`${d||n} local validation`})}),g=await t.json().catch(()=>({}));if(!t.ok)throw new Error(g.error||`HTTP ${t.status}`);ut(g),X("max");}catch(t){yt(t.message);}finally{bt(false);}}},[f.isAuthenticated,f.token,e.serverUrl,e.anonKey,n,i,ee,h,y,p,d,ut]),$e=react.useCallback(async(t,g,w)=>{xe(t);try{await ct(t,g,w,at);}finally{xe(null),oe(null),le("");}},[ct,at]),F=b?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},Jt=F.total>0&&F.pending===0,ke=be==="completed",Ae=react.useMemo(()=>{let t=b?.test_cases||[];if(!Q.trim())return t;let g=Q.toLowerCase();return t.filter(w=>w.title.toLowerCase().includes(g)||w.description&&w.description.toLowerCase().includes(g)||w.url_path&&w.url_path.toLowerCase().includes(g)||w.seed_user&&w.seed_user.toLowerCase().includes(g))},[b?.test_cases,Q]),ht=react.useMemo(()=>{let t=Ae,g=b?.test_cases||[];if(new Set(g.map(j=>j.source_pr_number)).size<=1)return null;let W=[],pe=new Map;t.forEach(j=>{let H=j.source_pr_number;pe.has(H)||pe.set(H,[]),pe.get(H).push(j);});let Mt=[...pe.keys()].sort((j,H)=>j===null?1:H===null?-1:H-j);for(let j of Mt){let H=pe.get(j),Ve={total:H.length,pass:0,fail:0,skip:0,pending:0};H.forEach(Ct=>{Ct.verdict in Ve&&Ve[Ct.verdict]++;}),W.push({key:j!=null?`pr-${j}`:"general",label:j!=null?`PR #${j}`:"General",cases:H,summary:Ve});}return W.filter(j=>j.cases.length>0)},[Ae,b?.test_cases]),xt=F.total>0?(F.pass+F.fail)/F.total*100:0,O=i??b?.environment??null,ue=react.useMemo(()=>{if(!O||O==="production"||ce)return [];let t=b?.test_cases||[],g=new Set;for(let w of t)w.seed_user&&g.add(it(w.seed_user));if(O==="local")for(let w of pt)g.add(it(w));for(let w of ft)g.add(it(w));return [...g]},[b?.test_cases,O,pt,ft,ce]);react.useEffect(()=>{if(!O||O==="production"||ce||!f.isAuthenticated||!f.token){Be([]);return}let t=true,g=`${e.serverUrl}/widget/totp-seeds?${new URLSearchParams({app_slug:n,environment:O})}`,w=W=>fetch(g,{headers:{apikey:e.anonKey,Authorization:`Bearer ${W}`}});return (async()=>{try{let W=await w(f.token);if(W.status===401&&f.refreshNow){let H=await f.refreshNow();H&&(W=await w(H));}if(!t)return;if(!W.ok){Be([]);return}let pe=await W.json().catch(()=>null),j=(Array.isArray(pe?.seeds)?pe.seeds:[]).map(H=>H?.seed_user_slug).filter(H=>typeof H=="string"&&H.length>0);Be(j);}catch{t&&Be([]);}})(),()=>{t=false;}},[O,ce,f.isAuthenticated,f.token,f.refreshNow,n,e.serverUrl,e.anonKey]);let je=react.useMemo(()=>{let t=b?.auto_tooltip_seconds??ie?.auto_tooltip_seconds;return t!=null&&t>0?t*1e3:0},[b,ie]),vt=be==="ready"||be==="completed"||ie?.enabled&&ie.run;react.useEffect(()=>{if(!vt||Me.current||je<=0)return;Me.current=true,Y(true);let t=window.setTimeout(()=>Y(false),je);return ()=>window.clearTimeout(t)},[vt,je]);let wt=t=>jsxRuntime.jsxs("div",{style:u.caseRow,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsx("div",{style:{marginTop:"2px",flexShrink:0,color:gn[t.verdict]},children:he===t.id?jsxRuntime.jsx(S,{d:m.loader,className:""}):jsxRuntime.jsx(S,{d:fn[t.verdict],className:""})}),jsxRuntime.jsxs("div",{style:{minWidth:0,flex:1},children:[jsxRuntime.jsx("div",{style:{fontSize:"10px",color:r.text,lineHeight:1.3},children:t.title}),t.description&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:r.gripColor,marginTop:"2px"},children:t.description}),t.seed_user&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:r.amber,marginTop:"3px",display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",background:`${r.amber}12`,border:`1px solid ${r.amber}30`},children:[jsxRuntime.jsx(S,{d:m.key,size:10}),jsxRuntime.jsx("span",{children:t.seed_user})]}),t.url_path&&jsxRuntime.jsxs("a",{href:t.url_path,target:"_blank",rel:"noopener noreferrer",onClick:g=>{g.stopPropagation(),T&&(g.preventDefault(),T(t.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsxRuntime.jsx(S,{d:m.externalLink,size:10}),t.url_path]}),t.verdict==="fail"&&t.fail_reason&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:r.red,marginTop:"2px"},children:["\u2717 ",t.fail_reason]})]})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(g=>jsxRuntime.jsx("button",{onClick:()=>{if(t.verdict===g){$e(t.id,"pending"),oe(null);return}if(g==="fail"){oe(t.id),le("");return}oe(null),$e(t.id,g);},disabled:he!==null,style:u.verdictBtn(t.verdict===g,g==="pass"?r.green:g==="fail"?r.red:r.amber),children:g.toUpperCase()},g)),t.created_by_agent_name&&jsxRuntime.jsxs("span",{style:{fontSize:"8px",color:r.purple,marginLeft:"4px",display:"inline-flex",alignItems:"center",gap:"2px"},children:[jsxRuntime.jsx(S,{d:m.bot,size:8}),t.created_by_agent_name]}),t.verdict_by_display_name&&jsxRuntime.jsxs("span",{style:{fontSize:"8px",color:r.textFaint,marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:"3px"},children:[t.verdict_by_display_name,t.verdict_at&&jsxRuntime.jsx("span",{style:{opacity:.7},children:cn(t.verdict_at)})]})]}),ye===t.id&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:Z,onChange:g=>le(g.target.value),onKeyDown:g=>{g.key==="Enter"&&$e(t.id,"fail",Z.trim()||void 0),g.key==="Escape"&&(oe(null),le(""));},placeholder:"Reason (optional)...",style:u.input}),jsxRuntime.jsx("button",{onClick:()=>{$e(t.id,"fail",Z.trim()||void 0);},style:u.verdictBtn(true,r.red),children:"\u2713"})]})]},t.id);if((be==="no-match"||be==="loading")&&!(!f.isAuthenticated&&ie?.enabled&&ie.run)){if(!(O==="local"&&!ce))return null}if(!f.isAuthenticated&&ie?.enabled&&ie.run){let t=ie.run,g=t.summary,w=t.status==="completed";return jsxRuntime.jsx("div",{ref:A,style:{...u.root,left:c.x,top:c.y},children:jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>U(true),onMouseLeave:()=>{U(false),$(false),Y(false);},children:[jsxRuntime.jsxs("div",{style:{...u.pill(w),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:P,onPointerMove:R,onPointerUp:()=>{N();},children:[jsxRuntime.jsx(S,{d:m.grip,size:10,className:""}),t.ticket_id&&t.ticket_url?jsxRuntime.jsx("a",{href:t.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:r.amber,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:t.ticket_id}):null,t.pr_url?jsxRuntime.jsxs("a",{href:t.pr_url,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:r.blue,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:["PR#",t.pr_number??t.pr_id]}):null,t.created_by_agent_name?t.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${t.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:r.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(S,{d:m.terminal,size:10}),t.created_by_agent_name]}):jsxRuntime.jsxs("span",{style:{color:r.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(S,{d:m.bot,size:10}),t.created_by_agent_name]}):null,jsxRuntime.jsxs("span",{style:w?{color:r.green}:void 0,children:[g.pass,"/",g.total]}),g.fail>0&&jsxRuntime.jsxs("span",{style:{color:r.red},children:[g.fail,"\u2717"]}),jsxRuntime.jsx("span",{onClick:W=>{W.stopPropagation(),f.openLogin();},style:{color:r.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!I&&(J||q)&&t.title&&jsxRuntime.jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsxRuntime.jsx("div",{style:{fontSize:"11px",fontWeight:700,color:r.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:t.title}),(t.description||t.intro_notes)&&jsxRuntime.jsx("div",{style:{fontSize:"10px",color:r.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:t.description||t.intro_notes}),jsxRuntime.jsx("div",{style:{marginTop:"4px",fontSize:"9px",color:r.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!f.isAuthenticated)return jsxRuntime.jsxs("div",{ref:A,style:{...u.root,left:c.x,top:c.y,width:220,minHeight:0,cursor:"move",userSelect:"none",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`},onPointerDown:P,onPointerMove:R,onPointerUp:N,children:[jsxRuntime.jsx("div",{style:{...u.handle,borderBottom:"none"},children:jsxRuntime.jsxs("div",{style:u.sub,children:[jsxRuntime.jsx(S,{d:m.grip,size:10,className:""}),jsxRuntime.jsx(S,{d:m.clipboard,size:12,className:""}),jsxRuntime.jsx("span",{style:{fontWeight:600},children:"BotBuddy"})]})}),jsxRuntime.jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[jsxRuntime.jsx("div",{style:{fontSize:"9px",color:r.textMuted,marginBottom:"8px"},children:"Sign in to access test cases"}),O==="local"&&ue.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsxRuntime.jsx(Le,{config:e,appSlug:n,environment:O,seededUsers:ue,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:r,testRunId:b?.id||a,testRunToken:s,ticketId:d,targetUrl:ee,version:k,commitSha:y,prNumber:p,branchName:h,onAuthExpired:f.logout})}),jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),f.openLogin();},style:{fontSize:"10px",fontWeight:600,padding:"6px 16px",borderRadius:"6px",border:`1px solid ${r.green}`,background:`${r.green}22`,color:r.green,cursor:"pointer",width:"100%"},children:"Sign in to test"})]})]});if(!b&&O==="local"&&!ce)return Vt?jsxRuntime.jsx("div",{ref:A,style:{...u.root,left:c.x,top:c.y},children:jsxRuntime.jsxs("div",{style:u.card(240,false),children:[jsxRuntime.jsxs("div",{style:u.handle,onPointerDown:P,onPointerMove:R,onPointerUp:N,onClick:()=>{D.current||ze(false);},children:[jsxRuntime.jsx(S,{d:m.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:u.title,children:"BotBuddy"}),h&&jsxRuntime.jsx("div",{style:u.sub,children:jsxRuntime.jsxs("span",{children:["\u2387 ",h]})})]}),jsxRuntime.jsx(S,{d:m.chevronUp,className:""}),jsxRuntime.jsx("button",{style:u.btn,onClick:t=>{t.stopPropagation(),ze(false);},children:jsxRuntime.jsx(S,{d:m.minus,className:""})})]}),jsxRuntime.jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[ue.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsxRuntime.jsx(Le,{config:e,appSlug:n,environment:O,seededUsers:ue,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:r,testRunId:a,testRunToken:s,ticketId:d,targetUrl:ee,version:k,commitSha:y,prNumber:p,branchName:h,onAuthExpired:f.logout})}),jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),Yt();},disabled:Ke,style:{fontSize:"10px",fontWeight:600,padding:"6px 12px",borderRadius:"6px",border:`1px solid ${r.green}`,background:`${r.green}22`,color:r.green,cursor:Ke?"wait":"pointer",width:"100%"},children:Ke?"Creating...":"Create test run for this branch"}),mt&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:r.red,marginTop:"8px"},children:mt})]})]})}):jsxRuntime.jsx("div",{ref:A,style:{...u.root,left:c.x,top:c.y},children:jsxRuntime.jsxs("div",{style:{...u.pill(false),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:P,onPointerMove:R,onPointerUp:()=>{N(),D.current||ze(true);},children:[jsxRuntime.jsx(S,{d:m.grip,size:9,className:""}),jsxRuntime.jsx("span",{style:{fontWeight:600},children:"BotBuddy"}),ue.length>0&&jsxRuntime.jsx(Le,{config:e,appSlug:n,environment:O,seededUsers:ue,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:r,compact:true,onExpand:()=>ze(true),testRunId:a,testRunToken:s,ticketId:d,targetUrl:ee,version:k,commitSha:y,prNumber:p,branchName:h,onAuthExpired:f.logout})]})});let kt=()=>{D.current||(Y(false),X(t=>{let g=t==="mini"?"max":"mini";return $(g==="mini"),g}));},St=({icon:t,onClick:g})=>jsxRuntime.jsx("button",{style:u.btn,onClick:w=>{w.stopPropagation(),g(w);},children:jsxRuntime.jsx(S,{d:t,className:""})}),_t=()=>jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${r.borderSubtle}`,flexShrink:0},children:[b?.pr_url&&jsxRuntime.jsxs("a",{href:b.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...u.link(r.blue),textDecoration:"none"},children:[jsxRuntime.jsx(S,{d:m.pr,size:12}),b.pr_number?`PR#${b.pr_number}`:b.pr_id||"PR",jsxRuntime.jsx(S,{d:m.externalLink,size:8})]}),b?.ticket_url&&jsxRuntime.jsxs("a",{href:b.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...u.link(r.amber),textDecoration:"none"},children:[jsxRuntime.jsx(S,{d:m.ticket,size:12}),b.ticket_id||"Ticket",jsxRuntime.jsx(S,{d:m.externalLink,size:8})]}),b?.created_by_agent_name&&(b.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${b.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:{...u.link(r.purple),textDecoration:"none"},children:[jsxRuntime.jsx(S,{d:m.bot,size:12}),b.created_by_agent_name,jsxRuntime.jsx(S,{d:m.externalLink,size:8})]}):jsxRuntime.jsxs("span",{style:{...u.link(r.purple)},children:[jsxRuntime.jsx(S,{d:m.bot,size:12}),b.created_by_agent_name]})),O&&jsxRuntime.jsx(Le,{config:e,appSlug:n,environment:O,seededUsers:ue,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:r,testRunId:b?.id||a,testRunToken:s,ticketId:d,targetUrl:ee,version:k,commitSha:y,prNumber:p,branchName:h,onAuthExpired:f.logout}),jsxRuntime.jsx("span",{style:{...u.badge(b?.environment||"custom"),marginLeft:"auto"},children:b?.environment})]}),Rt=()=>jsxRuntime.jsxs("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:`1px solid ${r.borderSubtle}`,background:r.bgSoft,flexShrink:0},children:[jsxRuntime.jsxs("button",{onClick:()=>{navigator.clipboard.writeText(Lt);},style:{fontSize:"9px",fontWeight:600,color:r.versionText,letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsxRuntime.jsxs("span",{style:{color:r.versionNum},children:["v",Lt]})]}),f.isAuthenticated&&(f.isExpired?jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),f.openLogin();},style:{fontSize:"8px",color:r.blue,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Widget session expired \u2014 sign in to refresh",children:"sign in"}):jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),f.logout();},style:{fontSize:"8px",color:r.textFaint,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Sign out of widget",children:"sign out"}))]});return jsxRuntime.jsxs("div",{ref:A,style:{...u.root,left:c.x,top:c.y},children:[ne==="mini"&&jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>U(true),onMouseLeave:()=>{U(false),$(false),Y(false);},children:[jsxRuntime.jsxs("div",{style:{...u.pill(ke),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:P,onPointerMove:R,onPointerUp:()=>{N(),D.current||kt();},children:[jsxRuntime.jsx(S,{d:m.grip,size:9,className:""}),b?.ticket_id&&jsxRuntime.jsx("span",{style:{color:r.amber,fontWeight:600},children:b.ticket_id}),b?.pr_number&&jsxRuntime.jsxs("span",{style:{color:r.blue,fontWeight:600},children:["PR#",b.pr_number]}),jsxRuntime.jsxs("span",{style:ke?{color:r.green}:void 0,children:[F.pass,"/",F.total]}),F.fail>0&&jsxRuntime.jsxs("span",{style:{color:r.red},children:[F.fail,"\u2717"]}),O&&jsxRuntime.jsx(Le,{config:e,appSlug:n,environment:O,seededUsers:ue,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:r,compact:true,onExpand:()=>X("expanded"),testRunId:b?.id||a,testRunToken:s,ticketId:d,targetUrl:ee,version:k,commitSha:y,prNumber:p,branchName:h,onAuthExpired:f.logout})]}),!I&&(J||q)&&b?.title&&jsxRuntime.jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsxRuntime.jsx("div",{style:{fontSize:"11px",fontWeight:700,color:r.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:b.title}),(b.description||b.intro_notes)&&jsxRuntime.jsx("div",{style:{fontSize:"10px",color:r.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:b.description||b.intro_notes})]})]}),ne==="expanded"&&jsxRuntime.jsxs("div",{style:u.card(300,ke),children:[jsxRuntime.jsxs("div",{style:u.handle,onPointerDown:P,onPointerMove:R,onPointerUp:N,onClick:kt,children:[jsxRuntime.jsx(S,{d:m.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:u.title,children:b?.title}),jsxRuntime.jsx("div",{style:u.sub,children:b?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",b.branch_name]})})]}),jsxRuntime.jsx(S,{d:m.chevronUp,className:""}),jsxRuntime.jsx(St,{icon:m.minus,onClick:()=>{Y(false),$(true),X("mini");}})]}),jsxRuntime.jsxs("div",{style:u.stats,children:[jsxRuntime.jsxs("span",{style:{color:r.green},children:[F.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:r.red},children:[F.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:r.amber},children:[F.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:r.gripColor},children:[F.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:F.total})]}),b?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:r.gripColor,borderBottom:`1px solid ${r.borderSubtle}`,flexShrink:0},children:b.description}),_t(),Rt(),jsxRuntime.jsx("div",{style:u.progress,children:jsxRuntime.jsx("div",{style:u.progressBar(xt)})})]}),ne==="max"&&jsxRuntime.jsxs("div",{style:{...u.card(G.w,ke),height:G.h,position:"relative"},children:[jsxRuntime.jsxs("div",{style:u.handle,onPointerDown:P,onPointerMove:R,onPointerUp:N,onClick:()=>{D.current||X("expanded");},children:[jsxRuntime.jsx(S,{d:m.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:u.title,children:b?.title}),jsxRuntime.jsx("div",{style:u.sub,children:b?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",b.branch_name]})})]}),jsxRuntime.jsx(S,{d:m.chevronDown,className:""}),jsxRuntime.jsx(St,{icon:m.minus,onClick:()=>{Y(false),$(true),X("mini");}})]}),jsxRuntime.jsxs("div",{style:u.stats,children:[jsxRuntime.jsxs("span",{style:{color:r.green},children:[F.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:r.red},children:[F.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:r.amber},children:[F.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:r.gripColor},children:[F.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:F.total})]}),b?.intro_notes&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${r.borderSubtle}`,fontSize:"10px",color:r.textMuted,fontStyle:"italic",flexShrink:0},children:b.intro_notes}),(b?.test_cases||[]).length>5&&jsxRuntime.jsxs("div",{style:{padding:"4px 12px",borderBottom:`1px solid ${r.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[jsxRuntime.jsx(S,{d:m.search,size:11,className:""}),jsxRuntime.jsx("input",{value:Q,onChange:t=>ve(t.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:r.text,fontFamily:"monospace"}}),Q&&jsxRuntime.jsx("button",{onClick:()=>ve(""),style:{background:"none",border:"none",cursor:"pointer",color:r.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),be==="error"&&jsxRuntime.jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsxRuntime.jsx(S,{d:m.alert,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:r.red},children:"Failed to load"}),jsxRuntime.jsx("button",{onClick:Ht,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),ke&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg},children:[jsxRuntime.jsx(S,{d:m.checkAll,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",color:r.green,flex:1},children:"Run completed"}),jsxRuntime.jsx("button",{onClick:jt,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),be!=="error"&&jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(b?.test_cases||[]).length===0?jsxRuntime.jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:r.gripColor},children:"No test cases"}):Ae.length===0?jsxRuntime.jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:r.gripColor},children:['No matches for "',Q,'"']}):ht?ht.map(t=>{let g=Ce.has(t.key);return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>we(t.key),style:{width:"100%",display:"flex",alignItems:"center",gap:"6px",padding:"5px 12px",background:r.bgSoft,cursor:"pointer",border:"none",borderLeft:"none",borderRight:"none",borderBottomStyle:"solid",borderTopStyle:"solid",borderBottomWidth:"1px",borderTopWidth:"1px",borderBottomColor:r.borderSubtle,borderTopColor:r.borderSubtle,backgroundColor:r.bgSoft},children:[jsxRuntime.jsx(S,{d:g?m.chevronDown:m.chevronUp,size:10,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",fontWeight:700,color:r.blue,flex:1,textAlign:"left"},children:t.label}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:r.green},children:[t.summary.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:r.red},children:[t.summary.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:r.gripColor},children:[t.summary.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{fontSize:"9px",color:r.textFaint},children:t.summary.total})]}),!g&&t.cases.map(w=>wt(w))]},t.key)}):Ae.map(t=>wt(t))}),Jt&&!ke&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",borderTop:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg,display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsxRuntime.jsx("span",{style:{fontSize:"9px",color:r.green},children:"All resolved"}),jsxRuntime.jsx("button",{onClick:Kt,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:r.green,border:`1px solid ${r.greenBorderSubtle}`,cursor:"pointer"},children:"COMPLETE"})]}),_t(),Rt(),jsxRuntime.jsx("div",{style:u.progress,children:jsxRuntime.jsx("div",{style:u.progressBar(xt)})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:0,right:0,width:16,height:16,cursor:"se-resize",zIndex:10,display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:"2px",opacity:.3},onPointerDown:It,onPointerMove:Ft,onPointerUp:Dt,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{Te.current||(t.currentTarget.style.opacity="0.3");},children:jsxRuntime.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsxRuntime.jsx("path",{d:"M7 1v6H1",fill:"none",stroke:r.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}function Sn(e){let n=e;return !!n&&typeof n=="object"&&typeof n.tenant=="string"&&Array.isArray(n.entries)&&n.entries.every(i=>!!i&&typeof i.id=="string"&&typeof i.title=="string"&&!!i.body&&Array.isArray(i.body.ast)&&Array.isArray(i.links))}function st({endpoint:e,getToken:n}){let[i,d]=react.useState({feed:null,error:null,loading:true}),[a,s]=react.useState(0),_=react.useRef(n);_.current=n,react.useEffect(()=>{let y=true;return d(p=>({...p,error:null,loading:true})),(async()=>{try{let p=await _.current(),h=await fetch(e,{headers:{authorization:`Bearer ${p}`}}),T=null;try{T=await h.json();}catch{T=null;}if(!y)return;if(h.ok)Sn(T)?d({feed:T,error:null,loading:!1}):d({feed:null,error:"invalid_feed",loading:!1});else {let V=T?.error;d({feed:null,error:typeof V=="string"?V:`http_${h.status}`,loading:!1});}}catch(p){y&&d({feed:null,error:p instanceof Error&&p.message||"unavailable",loading:false});}})(),()=>{y=false;}},[e,a]);let k=react.useCallback(()=>s(y=>y+1),[]);return {...i,reload:k}}function Ut(e){if(typeof e!="string"||/[\s\\]/.test(e))return null;if(e.startsWith("/"))return e.startsWith("//")?null:{kind:"internal",href:e};try{return new URL(e).protocol==="https:"?{kind:"external",href:e}:null}catch{return null}}function De(e,n=""){return e.map((i,d)=>{let a=`${n}${d}`;switch(i.t){case "text":return i.v;case "code":return jsxRuntime.jsx("code",{className:"bbrn-code",children:i.v},a);case "strong":return jsxRuntime.jsx("strong",{children:De(i.c,`${a}.`)},a);case "em":return jsxRuntime.jsx("em",{children:De(i.c,`${a}.`)},a);default:return null}})}function Wt({ast:e}){return jsxRuntime.jsx(jsxRuntime.Fragment,{children:e.map((n,i)=>n.t==="list"?jsxRuntime.jsx("ul",{className:"bbrn-list",children:n.items.map((d,a)=>jsxRuntime.jsx("li",{children:De(d)},a))},i):n.t==="p"?jsxRuntime.jsx("p",{className:"bbrn-p",children:De(n.c)},i):null)})}var _n=`@layer bbrn {
|
|
2
|
-
.bbrn-root{display:grid;gap:12px;color
|
|
3
|
-
.bbrn-root .bbrn-entry{border:1px solid
|
|
1
|
+
'use strict';var react=require('react'),reactDom=require('react-dom'),jsxRuntime=require('react/jsx-runtime');var Te=8;function Qe(e,n,s,d,a,l){let _=Math.max(Te,a-s-Te),v=Math.max(Te,l-d-Te);return {x:Math.min(Math.max(e,Te),_),y:Math.min(Math.max(n,Te),v)}}function et(e,n){let[s,d]=react.useState({x:e,y:n}),a=react.useRef(false),l=react.useRef({x:0,y:0}),_=react.useRef(false),v=react.useCallback(h=>{a.current=true,_.current=false,l.current={x:h.clientX-s.x,y:h.clientY-s.y},h.target.setPointerCapture(h.pointerId);},[s]),R=react.useCallback(h=>{a.current&&(_.current=true,d({x:h.clientX-l.current.x,y:h.clientY-l.current.y}));},[]),y=react.useCallback(()=>{a.current=false;},[]);return {pos:s,setPos:d,onPointerDown:v,onPointerMove:R,onPointerUp:y,didDrag:_}}function tt(e,n,s){let d=react.useRef(s);d.current=s,react.useEffect(()=>{if(!n)return;if(e.supabaseUrl){let l=false,_=null,v=()=>{l||_||(_=setInterval(()=>d.current(),15e3));},R=null;try{let g=new URL(e.supabaseUrl),t=["localhost","127.0.0.1","::1"].includes(g.hostname);if(g.protocol==="http:"&&!t)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");g.protocol=g.protocol==="https:"?"wss:":"ws:",R=g.toString().replace(/\/$/,"");}catch{v();}let y=null,h=null,B=null,j=0,k=()=>{if(!(l||!R)){try{y=new WebSocket(`${R}/realtime/v1/websocket?apikey=${e.anonKey}&vsn=1.0.0`);}catch{v();return}y.onopen=()=>{if(l||!y)return;let g={topic:`realtime:public:test_run_cases:test_run_id=eq.${n}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_run_cases",filter:`test_run_id=eq.${n}`}]}},ref:String(++j)};y.send(JSON.stringify(g));let t={topic:`realtime:public:test_runs:id=eq.${n}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_runs",filter:`id=eq.${n}`}]}},ref:String(++j)};y.send(JSON.stringify(t)),h=setInterval(()=>{y?.readyState===WebSocket.OPEN&&y.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++j)}));},3e4);},y.onmessage=g=>{try{JSON.parse(g.data).event==="postgres_changes"&&d.current();}catch{}},y.onclose=()=>{x(),l||(B=setTimeout(k,3e3));},y.onerror=()=>{y?.close();};}},x=()=>{h&&(clearInterval(h),h=null);};return k(),()=>{l=true,x(),B&&clearTimeout(B),_&&clearInterval(_),y&&(y.onclose=null,y.onerror=null,y.close());}}let a=setInterval(()=>d.current(),15e3);return ()=>clearInterval(a)},[e.supabaseUrl,e.anonKey,n]);}var cn="botbuddy:created-test-run:";function un(e){if(!e)return "";try{return new URL(e).origin}catch{return e}}function pn(e){return `${cn}${encodeURIComponent([e.appSlug,e.environment||"",e.ticketId||"",un(e.targetUrl),e.branchName||""].join("|"))}`}function Fe(e,n){let s={apikey:e.anonKey};return n?s.Authorization=`Bearer ${n}`:e.apiKey?s.Authorization=`Bearer ${e.apiKey}`:s.Authorization=`Bearer ${e.anonKey}`,s}async function gn(e){if(e)return e;try{let n=await fetch("/.botbuddy-token",{cache:"no-store"});if(n.ok){let s=(await n.text()).trim();if(s.startsWith("public_"))return s}}catch{}try{let n=undefined?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(n&&typeof n=="string"&&n.startsWith("public_"))return n}catch{}return null}function rt(e){let[n,s]=react.useState(null),[d,a]=react.useState("loading"),l=pn(e),[_,v]=react.useState(()=>{if(e.testRunId)return e.testRunId;try{return localStorage.getItem(l)||void 0}catch{return}}),R=e.testRunId||_,y=react.useCallback(x=>{if(s(x),!!x?.id){v(x.id);try{localStorage.setItem(l,x.id);}catch{}}},[l]),h=react.useCallback(async()=>{try{let x=await gn(e.testRunToken);if(!x&&!R){a("no-match"),s(null);return}if(x&&!e.ticketId){a("no-match"),s(null);return}let g=new URLSearchParams;x&&g.set("token",x),e.ticketId&&g.set("ticket_id",e.ticketId),g.set("app_slug",e.appSlug),e.environment&&g.set("environment",e.environment),R&&g.set("test_run_id",R),e.targetUrl&&g.set("target_url",e.targetUrl),e.version&&g.set("version",e.version),e.commitSha&&g.set("commit_sha",e.commitSha),e.prNumber&&g.set("pr_number",String(e.prNumber)),e.branchName&&g.set("branch_name",e.branchName);let t=await fetch(`${e.config.serverUrl}/widget/test-run?${g.toString()}`,{headers:Fe(e.config,e.authToken)});if(t.status===404){a("no-match"),s(null);return}if(t.status===401||t.status===403){e.authToken&&e.onAuthExpired&&e.onAuthExpired(),a("error");return}if(!t.ok){a("error");return}let i=await t.json();if(!i||i.run===null){a("no-match"),s(null);return}y(i),a(i.status==="completed"?"completed":"ready");}catch{a("error");}},[e.config.serverUrl,e.config.anonKey,e.config.apiKey,e.authToken,e.appSlug,e.environment,e.ticketId,R,e.testRunToken,e.targetUrl,e.version,e.commitSha,e.branchName,e.prNumber,e.onAuthExpired,y]);return react.useEffect(()=>{h();},[h]),tt(e.config,n?.id,h),{run:n,widgetState:d,fetchRun:h,setVerdict:async(x,g,t,i="human")=>(s(N=>{if(!N)return null;let z=N.test_cases.map(C=>C.id===x?{...C,verdict:g,fail_reason:g==="fail"&&t||null,verdict_by_display_name:i,verdict_at:new Date().toISOString()}:C),T={total:z.length,pending:0,pass:0,fail:0,skip:0};return z.forEach(C=>{C.verdict in T&&T[C.verdict]++;}),{...N,test_cases:z,summary:T}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${x}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...Fe(e.config,e.authToken)},body:JSON.stringify({verdict:g,fail_reason:t,display_name:i})})).ok),markComplete:async()=>n?(s(g=>g?{...g,status:"completed"}:null),a("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${n.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...Fe(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!n)return false;let x=await fetch(`${e.config.serverUrl}/widget/test-runs/${n.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...Fe(e.config,e.authToken)}});return x.ok&&h(),x.ok},setRun:y}}var it="botbuddy-widget-auth-token",at="botbuddy-widget-auth-name";function Le(e){if(!e)return null;try{let n=e.split(".")[1];if(!n)return null;let s=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(n.length/4)*4,"="),d=atob(s),a=JSON.parse(d);return typeof a.exp=="number"?a.exp*1e3:null}catch{return null}}var bn=2500,mn=6e4;function lt(e){let[n,s]=react.useState(()=>{try{return localStorage.getItem(it)}catch(k){return console.warn("Unable to read BotBuddy widget auth token",k),null}}),[d,a]=react.useState(()=>{try{return localStorage.getItem(at)}catch(k){return console.warn("Unable to read BotBuddy widget display name",k),null}}),l=react.useRef(null),_=react.useCallback((k,x)=>{s(k),x&&a(x);try{localStorage.setItem(it,k),x&&localStorage.setItem(at,x);}catch(g){console.warn("Unable to persist BotBuddy widget auth token",g);}},[]);react.useEffect(()=>{let k=new URL(e).origin,x=g=>{g.origin===k&&g.data?.type==="botbuddy-widget-auth"&&g.data.token&&_(g.data.token,g.data.displayName||"human");};return window.addEventListener("message",x),()=>window.removeEventListener("message",x)},[e,_]);let v=react.useCallback(()=>{if(l.current)return l.current;if(typeof window>"u"||typeof document>"u")return Promise.resolve(null);let k=new URL(e).origin,x=new URL("/widget-auth",e);x.searchParams.set("silent","1"),x.searchParams.set("origin",window.location.origin);let g=new Promise(t=>{let i=document.createElement("iframe");i.setAttribute("aria-hidden","true"),i.style.position="fixed",i.style.width="1px",i.style.height="1px",i.style.opacity="0",i.style.pointerEvents="none",i.style.border="0",i.style.left="-9999px",i.style.top="-9999px",i.src=x.toString();let U=false,N=()=>{window.removeEventListener("message",z),clearTimeout(T);try{i.remove();}catch{}l.current=null;},z=C=>{if(C.origin===k){if(C.data?.type==="botbuddy-widget-auth-failed"){if(U)return;U=true,t(null),N();return}C.data?.type!=="botbuddy-widget-auth"||!C.data.token||U||(U=true,t(String(C.data.token)),N());}},T=setTimeout(()=>{U||(U=true,t(null),N());},bn);window.addEventListener("message",z),document.body.appendChild(i);});return l.current=g,g},[e]);react.useEffect(()=>{if(!n)return;let k=Le(n);if(!k)return;let x=k-Date.now()-mn,g=window.setTimeout(()=>{v();},Math.max(0,x));return ()=>window.clearTimeout(g)},[n,v]);let R=react.useCallback(()=>{let k=new URL("/widget-auth",e);k.searchParams.set("origin",window.location.origin);let x=420,g=520,t=window.screenX+(window.innerWidth-x)/2,i=window.screenY+(window.innerHeight-g)/2;window.open(k.toString(),"botbuddy-auth",`width=${x},height=${g},left=${t},top=${i},popup=yes`);},[e]),[,y]=react.useState(0);react.useEffect(()=>{let k=Le(n);if(!k)return;let x=k-Date.now();if(x<=0)return;let g=window.setTimeout(()=>y(t=>t+1),x);return ()=>window.clearTimeout(g)},[n]);let h=react.useCallback(()=>{s(null),a(null);try{localStorage.removeItem(it),localStorage.removeItem(at);}catch(k){console.warn("Unable to clear BotBuddy widget auth token",k);}},[]),B=Le(n),j=B!==null&&B<=Date.now();return {token:n,displayName:d,isAuthenticated:!!n,isExpired:j,openLogin:R,refreshNow:v,logout:h}}var Oe=null;function yn(){try{if(typeof document<"u"){let e=document.querySelector("base[href]");if(e)return new URL(".botbuddy-totp.json",e.href).toString()}}catch{}return "/.botbuddy-totp.json"}function He(){return Oe||(Oe=(async()=>{if(typeof fetch>"u")return null;try{let e=await fetch(yn(),{cache:"no-store"});if(!e.ok)return null;let n=await e.json();if(!n||typeof n!="object"||Array.isArray(n))return null;let s={};for(let[d,a]of Object.entries(n))typeof a=="string"&&a.length>0&&(s[d]=a);return s}catch{return null}})(),Oe)}async function Ut(e){return (await He())?.[e]??null}function hn(e){let n=e.replace(/=+$/,"").replace(/\s+/g,"").toUpperCase(),s="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",d=[],a=0,l=0;for(let _ of n){let v=s.indexOf(_);if(v<0)throw new Error("Invalid Base32 character in TOTP secret");l=l<<5|v,a+=5,a>=8&&(a-=8,d.push(l>>>a&255));}return Uint8Array.from(d)}async function It(e,n=Date.now()){if(typeof crypto>"u"||!crypto.subtle)throw new Error("Web Crypto unavailable");let s=hn(e),d=new Uint8Array(s.byteLength);d.set(s);let a=Math.floor(n/1e3/30),l=new Uint8Array(8),_=Math.floor(a/4294967296),v=a>>>0;l[0]=_>>>24&255,l[1]=_>>>16&255,l[2]=_>>>8&255,l[3]=_&255,l[4]=v>>>24&255,l[5]=v>>>16&255,l[6]=v>>>8&255,l[7]=v&255;let R=await crypto.subtle.importKey("raw",d,{name:"HMAC",hash:"SHA-1"},false,["sign"]),y=await crypto.subtle.sign("HMAC",R,l),h=new Uint8Array(y),B=h[h.length-1]&15;return (((h[B]&127)<<24|(h[B+1]&255)<<16|(h[B+2]&255)<<8|h[B+3]&255)%1e6).toString().padStart(6,"0")}var Wt="0.11.0";function vn(e){let n=new Date(e),d=Date.now()-n.getTime();if(d<6e4)return "just now";if(d<36e5)return `${Math.floor(d/6e4)}m ago`;if(d<864e5)return `${Math.floor(d/36e5)}h ago`;let a=n.getDate(),l=n.toLocaleString("en",{month:"short"}),_=n.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${l} ${a}, ${_}`}var S=({d:e,className:n,size:s=14})=>jsxRuntime.jsx("svg",{className:n,width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:e})}),m={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01",bot:"M12 8V4H8M2 14h2M20 14h2M15 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M9 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M18 10a6 6 0 0 0-12 0v4a6 6 0 0 0 12 0Z",terminal:"M4 17l6-6-6-6M12 19h8",key:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4",shield:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10",copy:"M20 9h-9a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2-2v-9a2 2 0 0 0-2-2ZM5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1",search:"M11 17.25a6.25 6.25 0 1 1 0-12.5 6.25 6.25 0 0 1 0 12.5ZM16 16l4.5 4.5"};function wn(){let[e,n]=react.useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return react.useEffect(()=>{if(typeof window>"u")return;let s=document.documentElement,d=()=>s.classList.contains("dark")?"dark":s.classList.contains("light")?"light":null,a=d();a&&n(a);let l=window.matchMedia("(prefers-color-scheme: dark)"),_=R=>{let y=d();n(y||(R.matches?"dark":"light"));};l.addEventListener("change",_);let v=new MutationObserver(()=>{let R=d();n(R||(l.matches?"dark":"light"));});return v.observe(s,{attributes:true,attributeFilter:["class"]}),()=>{l.removeEventListener("change",_),v.disconnect();}},[]),e}function kn(e){let n=e==="dark";return {bg:n?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:n?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:n?"#e5e5e5":"#1a1a1a",textMuted:n?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:n?"#555":"#999",border:n?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:n?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:n?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:n?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:n?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:n?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:n?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:n?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:n?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:n?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:n?"#888":"#aaa",btnHover:n?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var Sn={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},_n={pending:m.circle,pass:m.check,fail:m.x,skip:m.skip},Ft={local:{bg:"rgba(59,130,246,0.15)",text:"#60a5fa",border:"rgba(59,130,246,0.3)"},preview:{bg:"rgba(168,85,247,0.15)",text:"#c084fc",border:"rgba(168,85,247,0.3)"},staging:{bg:"rgba(245,158,11,0.15)",text:"#fbbf24",border:"rgba(245,158,11,0.3)"},production:{bg:"rgba(239,68,68,0.15)",text:"#f87171",border:"rgba(239,68,68,0.3)"},custom:{bg:"rgba(128,128,128,0.15)",text:"#888",border:"rgba(128,128,128,0.3)"}},Rn=["app.supply-guard.io"];function Tn(e,n=[]){if(!e)return false;let s=e.toLowerCase();return [...Rn,...n].map(a=>a.toLowerCase()).includes(s)}var Cn=e=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:n=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:e.bg,border:n?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:n?`0 4px 12px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 4px 12px ${e.shadow}`,cursor:"pointer",fontSize:"9px",color:e.text}),card:(n,s)=>({width:`${n}px`,borderRadius:"8px",background:e.bg,border:s?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:s?`0 8px 24px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 8px 24px ${e.shadow}`,overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:`1px solid ${e.borderSubtle}`},title:{fontSize:"10px",fontWeight:600,color:e.text,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:e.textMuted,display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:e.gripColor,display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:`1px solid ${e.borderSubtle}`},badge:n=>{let s=Ft[n]||Ft.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:s.bg,color:s.text,border:`1px solid ${s.border}`,lineHeight:"14px"}},progress:{height:"2px",background:e.borderSubtle,flexShrink:0},progressBar:n=>({height:"100%",width:`${n}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:n=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${n}15`,color:n,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${e.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(n,s)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:n?`${s}33`:"transparent",color:n?s:e.gripColor,transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:e.inputBg,border:`1px solid ${e.inputBorder}`,borderRadius:"4px",padding:"2px 6px",color:e.text,outline:"none"},humanBanner:{padding:"6px 12px",fontSize:"11px",fontWeight:600,color:e.green,borderBottom:`1px solid ${e.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",background:e.greenBg,cursor:"pointer",textDecoration:"none"}});function dt(e){return e.split("/")[0].trim()}async function Mn(e){try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}try{if(typeof document>"u")return !1;let n=document.createElement("textarea");n.value=e,n.setAttribute("readonly",""),n.style.position="fixed",n.style.top="0",n.style.left="0",n.style.opacity="0",n.style.pointerEvents="none",document.body.appendChild(n),n.focus(),n.select(),n.setSelectionRange(0,e.length);let s=document.execCommand("copy");return document.body.removeChild(n),s}catch{return false}}function $e({config:e,appSlug:n,environment:s,seededUsers:d,authToken:a,tk:l,compact:_=false,onExpand:v,onAuthExpired:R,refreshAuth:y,requestLogin:h,testRunId:B,testRunToken:j,ticketId:k,targetUrl:x,version:g,commitSha:t,prNumber:i,branchName:U}){let[N,z]=react.useState(false),[T,C]=react.useState(null),[A,X]=react.useState(null),[Q,f]=react.useState(null),[ze,de]=react.useState(null),[se,ee]=react.useState(null),[te,ce]=react.useState(null);react.useEffect(()=>{s==="local"&&He();},[s]);let ve=react.useCallback(u=>{C(u),f(null),de(null),ce(null);let $=Le(a);if(s!=="local"&&h&&$!==null&&$<=Date.now()){ee({slug:u,token:a||null}),ce(u),C(null),h();return}let P=E=>{f(E),de(u),window.setTimeout(()=>{de(L=>L===u?null:L),f(L=>L===E?null:L);},3e3);},M=new URLSearchParams({app_slug:n,seed_user_slug:u,environment:s});B&&M.set("test_run_id",B),j&&M.set("public_token",j),k&&M.set("ticket_id",k),x&&M.set("target_url",x),g&&M.set("version",g),t&&M.set("commit_sha",t),i&&M.set("pr_number",String(i)),U&&M.set("branch_name",U);let I=async E=>{let L={apikey:e.anonKey,Authorization:`Bearer ${E}`};try{let F=await fetch(`${e.serverUrl}/widget/totp-code?${M}`,{headers:L});if(!F.ok){let ye=await F.json().catch(()=>({error:`HTTP ${F.status}`}));return {ok:!1,status:F.status,error:ye.error||`HTTP ${F.status}`}}let Z=await F.json();return {ok:!0,code:String(Z.code)}}catch{return {ok:false,status:0,error:"Network error"}}},V=(async()=>{if(s==="local"){let F=await Ut(u);if(F)try{return {ok:!0,code:await It(F)}}catch{}}let E=await I(a||e.anonKey);if(E.ok||E.status!==401||!y)return E;let L=await y();return L?I(L):{ok:false,status:401,error:"Sign in to BotBuddy to refresh 2FA"}})(),D=null;try{if(typeof ClipboardItem<"u"&&navigator.clipboard?.write){let E=V.then(L=>{if(!L.ok)throw new Error(L.error);return new Blob([L.code],{type:"text/plain"})});D=navigator.clipboard.write([new ClipboardItem({"text/plain":E})]).then(()=>!0).catch(()=>!1);}}catch{}(async()=>{let E=await V;if(!E.ok){E.status===401?(ee({slug:u,token:a||null}),ce(u)):P(E.status===404?"No 2FA seed registered":E.error),C(null);return}let L=D?await D:false,F=L?true:await Mn(E.code),Z=L||F;X({slug:u,code:E.code,copied:Z}),window.setTimeout(()=>X(ye=>ye?.slug===u?null:ye),Z?2500:6e3),z(false),C(null);})();},[e.serverUrl,e.anonKey,a,n,s,B,j,k,x,g,t,i,U,y,h]),ae=react.useCallback(u=>{ee({slug:u,token:a||null}),h?.();},[a,h]),we=react.useCallback(u=>{te===u?ae(u):ve(u);},[te,ae,ve]);react.useEffect(()=>{if(!se||!a||a===se.token)return;let u=se.slug;ee(null),ve(u);},[a,ve,se]);let ke=react.useRef(null),Ee=react.useRef(null);if(react.useLayoutEffect(()=>{if(!N)return;let u=ke.current,$=Ee.current;if(!u||!$||typeof window>"u")return;let P=()=>{let M=u.getBoundingClientRect(),I=$.getBoundingClientRect(),V=window.innerWidth,D=window.innerHeight,E=M.left,L=M.top-I.height-6;L<8&&(L=M.bottom+6);let F=Math.max(8,V-I.width-8),Z=Math.max(8,D-I.height-8);E=Math.min(Math.max(E,8),F),L=Math.min(Math.max(L,8),Z),$.style.left=`${Math.round(E)}px`,$.style.top=`${Math.round(L)}px`;};return P(),window.addEventListener("scroll",P,true),window.addEventListener("resize",P),()=>{window.removeEventListener("scroll",P,true),window.removeEventListener("resize",P);}},[N,d.length,Q]),react.useEffect(()=>{if(!N)return;let u=$=>{let P=$.target;Ee.current?.contains(P)||ke.current?.contains(P)||z(false);};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[N]),d.length===0)return null;if(_){let u=d.length>1,$=d[0],P=!u&&te===$,M=F=>{if(F.stopPropagation(),u&&v){v();return}we($);},I=!!ze,V=!!A,D=V&&A.copied,E=V&&!A.copied,L=P?l.blue:I?l.red:D?l.green:E?l.amber:l.purple;return jsxRuntime.jsxs("span",{onPointerDown:F=>F.stopPropagation(),onPointerUp:F=>F.stopPropagation(),onPointerMove:F=>F.stopPropagation(),onClick:M,style:{display:"inline-flex",alignItems:"center",gap:"3px",color:L,fontWeight:600,cursor:"pointer",letterSpacing:E?"0.08em":void 0},title:P?"Sign in to BotBuddy to refresh 2FA":I?Q||"Failed":E?`Clipboard blocked \u2014 code: ${A.code}`:u?`${d.length} 2FA personas`:`Copy 2FA code for ${d[0]}`,children:[jsxRuntime.jsx(S,{d:P?m.key:I?m.alert:D?m.check:E?m.copy:m.shield,size:10}),P?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Sign in"}):D?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Copied"}):E?jsxRuntime.jsx(jsxRuntime.Fragment,{children:A.code}):I?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Failed"}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["2FA",u&&` \xB7${d.length}`]})]})}if(d.length===1){let u=d[0],$=T===u,P=A?.slug===u,M=P&&A.copied,I=P&&!A.copied,V=ze===u,D=te===u,E=D?l.blue:V?l.red:M?l.green:I?l.amber:l.purple;return jsxRuntime.jsxs("button",{onClick:L=>{L.stopPropagation(),we(u);},disabled:$,style:{...Dt(E),cursor:$?"wait":"pointer",opacity:$?.6:1},title:D?"Sign in to BotBuddy to refresh 2FA":V?Q||"Failed":I?`Clipboard blocked \u2014 code: ${A.code}`:`Copy 2FA code for ${u}`,children:[jsxRuntime.jsx(S,{d:D?m.key:V?m.alert:M?m.check:I?m.copy:m.shield,size:12}),D?"Sign in":M?"Copied":I?A.code:V?"Failed":$?"\u2026":`2FA \xB7 ${u}`]})}let ue=!!te&&!N,ne=!!ze&&!N,Se=!!A&&A.copied,_e=!!A&&!A.copied,Ve=ue?l.blue:ne?l.red:Se?l.green:_e?l.amber:l.purple,Ye=N&&typeof document<"u"?reactDom.createPortal(jsxRuntime.jsxs("div",{ref:Ee,onPointerDown:u=>u.stopPropagation(),onMouseDown:u=>u.stopPropagation(),style:{position:"fixed",left:-9999,top:-9999,background:l.bg,border:`1px solid ${l.border}`,borderRadius:6,boxShadow:`0 8px 24px ${l.shadow}`,padding:4,minWidth:220,maxWidth:typeof window<"u"?Math.min(420,window.innerWidth-16):420,zIndex:1e5,fontFamily:"ui-monospace, SFMono-Regular, monospace"},children:[d.map(u=>{let $=T===u,P=te===u;return jsxRuntime.jsxs("button",{onClick:M=>{M.stopPropagation(),we(u);},disabled:$,style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 8px",background:"transparent",border:"none",borderRadius:4,cursor:$?"wait":"pointer",fontSize:"10px",color:P?l.blue:l.text,textAlign:"left",fontFamily:"ui-monospace, SFMono-Regular, monospace"},title:P?"Sign in to BotBuddy to refresh 2FA":void 0,onMouseEnter:M=>M.currentTarget.style.background=l.btnHover,onMouseLeave:M=>M.currentTarget.style.background="transparent",children:[jsxRuntime.jsx(S,{d:P?m.key:m.shield,size:10}),jsxRuntime.jsx("span",{style:{flex:1,overflowWrap:"anywhere",lineHeight:1.3},children:u}),P?jsxRuntime.jsx("span",{style:{color:l.blue,fontSize:9},children:"Sign in"}):$?jsxRuntime.jsx("span",{style:{color:l.textMuted,fontSize:9},children:"\u2026"}):null]},u)}),Q&&jsxRuntime.jsx("div",{style:{padding:"4px 8px",fontSize:9,color:l.red},children:Q})]}),document.body):null;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("button",{ref:ke,onClick:u=>{if(u.stopPropagation(),ue&&te){ae(te);return}z($=>!$),f(null),de(null);},style:{...Dt(Ve),cursor:"pointer"},title:ue?"Sign in to BotBuddy to refresh 2FA":ne?Q||"Failed":_e?`Clipboard blocked \u2014 code: ${A.code}`:"Choose a persona to copy a 2FA code for",children:[jsxRuntime.jsx(S,{d:ue?m.key:ne?m.alert:Se?m.check:_e?m.copy:m.shield,size:12}),ue?"Sign in":Se?"Copied":_e?A.code:ne?"Failed":`2FA \xB7 ${d.length}`,!ue&&jsxRuntime.jsx(S,{d:N?m.chevronUp:m.chevronDown,size:8})]}),Ye]})}function Dt(e){return {display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${e}15`,color:e,textDecoration:"none",border:`1px solid ${e}30`}}var Ot="botbuddy-widget-state";function En({config:e,appSlug:n,environment:s,ticketId:d,testRunId:a,testRunToken:l,targetUrl:_,version:v,commitSha:R,prNumber:y,branchName:h,onNavigate:B,displayName:j="human",defaultMode:k="mini",defaultPosition:x}){let g=wn(),t=react.useMemo(()=>kn(g),[g]),i=react.useMemo(()=>Cn(t),[t]),[U,N]=react.useState(false),[z,T]=react.useState(false),[C,A]=react.useState(false),X=react.useRef(false),Q=e.dashboardUrl||"https://app.bot-buddy.ai",f=lt(Q),de=(()=>{try{let r=typeof window<"u"?localStorage.getItem(Ot):null;if(r)return JSON.parse(r)}catch{}return null})(),[se,ee]=react.useState(de?.mode||k),[te,ce]=react.useState(""),[ve,ae]=react.useState(null),[we,ke]=react.useState(null),[Ee,ue]=react.useState(new Set),[ne,Se]=react.useState(""),_e=react.useCallback(r=>{ue(p=>{let w=new Set(p);return w.has(r)?w.delete(r):w.add(r),w});},[]),Ve=de?.x??x?.x??16,Ye=de?.y??x?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:u,setPos:$,onPointerDown:P,onPointerMove:M,onPointerUp:I,didDrag:V}=et(Ve,Ye),D=react.useRef(null);react.useEffect(()=>{try{localStorage.setItem(Ot,JSON.stringify({mode:se,x:u.x,y:u.y}));}catch{}},[se,u.x,u.y]),react.useLayoutEffect(()=>{if(typeof window>"u")return;let r=D.current;if(!r)return;let p=r.getBoundingClientRect(),w=Qe(u.x,u.y,p.width,p.height,window.innerWidth,window.innerHeight);(w.x!==u.x||w.y!==u.y)&&$(w);}),react.useEffect(()=>{if(typeof window>"u")return;let r=()=>{let p=D.current;if(!p)return;let w=p.getBoundingClientRect(),H=Qe(u.x,u.y,w.width,w.height,window.innerWidth,window.innerHeight);(H.x!==u.x||H.y!==u.y)&&$(H);};return window.addEventListener("resize",r),()=>window.removeEventListener("resize",r)},[u.x,u.y,$]);let E=react.useRef(f.isAuthenticated);react.useEffect(()=>{!E.current&&f.isAuthenticated&&ee("max"),E.current=f.isAuthenticated;},[f.isAuthenticated]);let L="botbuddy-widget-max-size",F=()=>{try{let r=localStorage.getItem(L);if(r)return JSON.parse(r)}catch{}return {w:340,h:500}},[Z,ye]=react.useState(F),Ne=react.useRef(false),Pe=react.useRef({x:0,y:0,w:0,h:0}),Jt=react.useCallback(r=>{r.stopPropagation(),Ne.current=true,Pe.current={x:r.clientX,y:r.clientY,w:Z.w,h:Z.h},r.target.setPointerCapture(r.pointerId);},[Z]),Gt=react.useCallback(r=>{if(!Ne.current)return;let p=Math.max(280,Math.min(600,Pe.current.w+(r.clientX-Pe.current.x))),w=Math.max(300,Math.min(window.innerHeight*.9,Pe.current.h+(r.clientY-Pe.current.y)));ye({w:p,h:w});},[]),Xt=react.useCallback(()=>{Ne.current&&(Ne.current=false,ye(r=>(localStorage.setItem(L,JSON.stringify(r)),r)));},[]),re=_??(typeof window<"u"?window.location.href:void 0),bt=f.displayName||j,[le,mt]=react.useState(null);react.useEffect(()=>{if(f.isAuthenticated)return;let r=new URLSearchParams;l&&r.set("token",l),d&&r.set("ticket_id",d),r.set("app_slug",n),s&&r.set("environment",s),a&&r.set("test_run_id",a),re&&r.set("target_url",re),v&&r.set("version",v),R&&r.set("commit_sha",R),y&&r.set("pr_number",String(y)),h&&r.set("branch_name",h),fetch(`${e.serverUrl}/widget/preview?${r}`,{headers:{apikey:e.anonKey}}).then(p=>p.json()).then(p=>mt(p)).catch(()=>mt(null));},[f.isAuthenticated,e.serverUrl,e.anonKey,n,s,d,a,l,re,v,R,y,h]);let yt=react.useRef(false),Zt=react.useCallback(()=>{yt.current||f.logout();},[f.logout]),{run:b,widgetState:he,fetchRun:Qt,setVerdict:ht,markComplete:en,resetRun:tn,setRun:xt}=rt({config:e,appSlug:n,environment:s,ticketId:d,testRunId:a,testRunToken:l,targetUrl:re,version:v,commitSha:R,prNumber:y?String(y):void 0,branchName:h,authToken:f.token,onAuthExpired:Zt});yt.current=!!b;let[vt,wt]=react.useState([]),[kt,Ae]=react.useState([]),[qe,St]=react.useState(false),[_t,Rt]=react.useState(null),[nn,Ue]=react.useState(false),pe=Tn(typeof window<"u"?window.location.hostname:void 0,e.productionHostnames||[]);react.useEffect(()=>{if((s??"local")!=="local"||pe){wt([]);return}let r=true;return He().then(p=>{r&&wt(Object.keys(p||{}));}),()=>{r=false;}},[s,pe]);let rn=react.useCallback(async()=>{if(!(!f.isAuthenticated||!f.token)){St(true),Rt(null);try{let r=await fetch(`${e.serverUrl}/widget/test-runs`,{method:"POST",headers:{"Content-Type":"application/json",apikey:e.anonKey,Authorization:`Bearer ${f.token}`},body:JSON.stringify({app_slug:n,environment:s||"local",target_url:re,branch_name:h,commit_sha:R,pr_number:y,ticket_id:d,title:`${d||n} local validation`})}),p=await r.json().catch(()=>({}));if(!r.ok)throw new Error(p.error||`HTTP ${r.status}`);xt(p),ee("max");}catch(r){Rt(r.message);}finally{St(false);}}},[f.isAuthenticated,f.token,e.serverUrl,e.anonKey,n,s,re,h,R,y,d,xt]),Ie=react.useCallback(async(r,p,w)=>{ke(r);try{await ht(r,p,w,bt);}finally{ke(null),ae(null),ce("");}},[ht,bt]),K=b?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},on=K.total>0&&K.pending===0,Re=he==="completed",We=react.useMemo(()=>{let r=b?.test_cases||[];if(!ne.trim())return r;let p=ne.toLowerCase();return r.filter(w=>w.title.toLowerCase().includes(p)||w.description&&w.description.toLowerCase().includes(p)||w.url_path&&w.url_path.toLowerCase().includes(p)||w.seed_user&&w.seed_user.toLowerCase().includes(p))},[b?.test_cases,ne]),Tt=react.useMemo(()=>{let r=We,p=b?.test_cases||[];if(new Set(p.map(J=>J.source_pr_number)).size<=1)return null;let H=[],fe=new Map;r.forEach(J=>{let q=J.source_pr_number;fe.has(q)||fe.set(q,[]),fe.get(q).push(J);});let Bt=[...fe.keys()].sort((J,q)=>J===null?1:q===null?-1:q-J);for(let J of Bt){let q=fe.get(J),Ge={total:q.length,pass:0,fail:0,skip:0,pending:0};q.forEach(zt=>{zt.verdict in Ge&&Ge[zt.verdict]++;}),H.push({key:J!=null?`pr-${J}`:"general",label:J!=null?`PR #${J}`:"General",cases:q,summary:Ge});}return H.filter(J=>J.cases.length>0)},[We,b?.test_cases]),Ct=K.total>0?(K.pass+K.fail)/K.total*100:0,Y=s??b?.environment??null,ge=react.useMemo(()=>{if(!Y||Y==="production"||pe)return [];let r=b?.test_cases||[],p=new Set;for(let w of r)w.seed_user&&p.add(dt(w.seed_user));if(Y==="local")for(let w of vt)p.add(dt(w));for(let w of kt)p.add(dt(w));return [...p]},[b?.test_cases,Y,vt,kt,pe]);react.useEffect(()=>{if(!Y||Y==="production"||pe||!f.isAuthenticated||!f.token){Ae([]);return}let r=true,p=`${e.serverUrl}/widget/totp-seeds?${new URLSearchParams({app_slug:n,environment:Y})}`,w=H=>fetch(p,{headers:{apikey:e.anonKey,Authorization:`Bearer ${H}`}});return (async()=>{try{let H=await w(f.token);if(H.status===401&&f.refreshNow){let q=await f.refreshNow();q&&(H=await w(q));}if(!r)return;if(!H.ok){Ae([]);return}let fe=await H.json().catch(()=>null),J=(Array.isArray(fe?.seeds)?fe.seeds:[]).map(q=>q?.seed_user_slug).filter(q=>typeof q=="string"&&q.length>0);Ae(J);}catch{r&&Ae([]);}})(),()=>{r=false;}},[Y,pe,f.isAuthenticated,f.token,f.refreshNow,n,e.serverUrl,e.anonKey]);let Je=react.useMemo(()=>{let r=b?.auto_tooltip_seconds??le?.auto_tooltip_seconds;return r!=null&&r>0?r*1e3:0},[b,le]),Mt=he==="ready"||he==="completed"||le?.enabled&&le.run;react.useEffect(()=>{if(!Mt||X.current||Je<=0)return;X.current=true,T(true);let r=window.setTimeout(()=>T(false),Je);return ()=>window.clearTimeout(r)},[Mt,Je]);let Et=r=>jsxRuntime.jsxs("div",{style:i.caseRow,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsx("div",{style:{marginTop:"2px",flexShrink:0,color:Sn[r.verdict]},children:we===r.id?jsxRuntime.jsx(S,{d:m.loader,className:""}):jsxRuntime.jsx(S,{d:_n[r.verdict],className:""})}),jsxRuntime.jsxs("div",{style:{minWidth:0,flex:1},children:[jsxRuntime.jsx("div",{style:{fontSize:"10px",color:t.text,lineHeight:1.3},children:r.title}),r.description&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:t.gripColor,marginTop:"2px"},children:r.description}),r.seed_user&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:t.amber,marginTop:"3px",display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",background:`${t.amber}12`,border:`1px solid ${t.amber}30`},children:[jsxRuntime.jsx(S,{d:m.key,size:10}),jsxRuntime.jsx("span",{children:r.seed_user})]}),r.url_path&&jsxRuntime.jsxs("a",{href:r.url_path,target:"_blank",rel:"noopener noreferrer",onClick:p=>{p.stopPropagation(),B&&(p.preventDefault(),B(r.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsxRuntime.jsx(S,{d:m.externalLink,size:10}),r.url_path]}),r.verdict==="fail"&&r.fail_reason&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:t.red,marginTop:"2px"},children:["\u2717 ",r.fail_reason]})]})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(p=>jsxRuntime.jsx("button",{onClick:()=>{if(r.verdict===p){Ie(r.id,"pending"),ae(null);return}if(p==="fail"){ae(r.id),ce("");return}ae(null),Ie(r.id,p);},disabled:we!==null,style:i.verdictBtn(r.verdict===p,p==="pass"?t.green:p==="fail"?t.red:t.amber),children:p.toUpperCase()},p)),r.created_by_agent_name&&jsxRuntime.jsxs("span",{style:{fontSize:"8px",color:t.purple,marginLeft:"4px",display:"inline-flex",alignItems:"center",gap:"2px"},children:[jsxRuntime.jsx(S,{d:m.bot,size:8}),r.created_by_agent_name]}),r.verdict_by_display_name&&jsxRuntime.jsxs("span",{style:{fontSize:"8px",color:t.textFaint,marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:"3px"},children:[r.verdict_by_display_name,r.verdict_at&&jsxRuntime.jsx("span",{style:{opacity:.7},children:vn(r.verdict_at)})]})]}),ve===r.id&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:te,onChange:p=>ce(p.target.value),onKeyDown:p=>{p.key==="Enter"&&Ie(r.id,"fail",te.trim()||void 0),p.key==="Escape"&&(ae(null),ce(""));},placeholder:"Reason (optional)...",style:i.input}),jsxRuntime.jsx("button",{onClick:()=>{Ie(r.id,"fail",te.trim()||void 0);},style:i.verdictBtn(true,t.red),children:"\u2713"})]})]},r.id);if((he==="no-match"||he==="loading")&&!(!f.isAuthenticated&&le?.enabled&&le.run)){if(!(Y==="local"&&!pe))return null}if(!f.isAuthenticated&&le?.enabled&&le.run){let r=le.run,p=r.summary,w=r.status==="completed";return jsxRuntime.jsx("div",{ref:D,style:{...i.root,left:u.x,top:u.y},children:jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>N(true),onMouseLeave:()=>{N(false),A(false),T(false);},children:[jsxRuntime.jsxs("div",{style:{...i.pill(w),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:P,onPointerMove:M,onPointerUp:()=>{I();},children:[jsxRuntime.jsx(S,{d:m.grip,size:10,className:""}),r.ticket_id&&r.ticket_url?jsxRuntime.jsx("a",{href:r.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:H=>H.stopPropagation(),style:{color:t.amber,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:r.ticket_id}):null,r.pr_url?jsxRuntime.jsxs("a",{href:r.pr_url,target:"_blank",rel:"noopener noreferrer",onClick:H=>H.stopPropagation(),style:{color:t.blue,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:["PR#",r.pr_number??r.pr_id]}):null,r.created_by_agent_name?r.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${r.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",onClick:H=>H.stopPropagation(),style:{color:t.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(S,{d:m.terminal,size:10}),r.created_by_agent_name]}):jsxRuntime.jsxs("span",{style:{color:t.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(S,{d:m.bot,size:10}),r.created_by_agent_name]}):null,jsxRuntime.jsxs("span",{style:w?{color:t.green}:void 0,children:[p.pass,"/",p.total]}),p.fail>0&&jsxRuntime.jsxs("span",{style:{color:t.red},children:[p.fail,"\u2717"]}),jsxRuntime.jsx("span",{onClick:H=>{H.stopPropagation(),f.openLogin();},style:{color:t.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!C&&(U||z)&&r.title&&jsxRuntime.jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:t.bg,border:`1px solid ${t.border}`,boxShadow:`0 8px 24px ${t.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsxRuntime.jsx("div",{style:{fontSize:"11px",fontWeight:700,color:t.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:r.title}),(r.description||r.intro_notes)&&jsxRuntime.jsx("div",{style:{fontSize:"10px",color:t.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:r.description||r.intro_notes}),jsxRuntime.jsx("div",{style:{marginTop:"4px",fontSize:"9px",color:t.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!f.isAuthenticated)return jsxRuntime.jsxs("div",{ref:D,style:{...i.root,left:u.x,top:u.y,width:220,minHeight:0,cursor:"move",userSelect:"none",borderRadius:"8px",background:t.bg,border:`1px solid ${t.border}`,boxShadow:`0 8px 24px ${t.shadow}`},onPointerDown:P,onPointerMove:M,onPointerUp:I,children:[jsxRuntime.jsx("div",{style:{...i.handle,borderBottom:"none"},children:jsxRuntime.jsxs("div",{style:i.sub,children:[jsxRuntime.jsx(S,{d:m.grip,size:10,className:""}),jsxRuntime.jsx(S,{d:m.clipboard,size:12,className:""}),jsxRuntime.jsx("span",{style:{fontWeight:600},children:"BotBuddy"})]})}),jsxRuntime.jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[jsxRuntime.jsx("div",{style:{fontSize:"9px",color:t.textMuted,marginBottom:"8px"},children:"Sign in to access test cases"}),Y==="local"&&ge.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsxRuntime.jsx($e,{config:e,appSlug:n,environment:Y,seededUsers:ge,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:t,testRunId:b?.id||a,testRunToken:l,ticketId:d,targetUrl:re,version:v,commitSha:R,prNumber:y,branchName:h,onAuthExpired:f.logout})}),jsxRuntime.jsx("button",{onClick:r=>{r.stopPropagation(),f.openLogin();},style:{fontSize:"10px",fontWeight:600,padding:"6px 16px",borderRadius:"6px",border:`1px solid ${t.green}`,background:`${t.green}22`,color:t.green,cursor:"pointer",width:"100%"},children:"Sign in to test"})]})]});if(!b&&Y==="local"&&!pe)return nn?jsxRuntime.jsx("div",{ref:D,style:{...i.root,left:u.x,top:u.y},children:jsxRuntime.jsxs("div",{style:i.card(240,false),children:[jsxRuntime.jsxs("div",{style:i.handle,onPointerDown:P,onPointerMove:M,onPointerUp:I,onClick:()=>{V.current||Ue(false);},children:[jsxRuntime.jsx(S,{d:m.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:i.title,children:"BotBuddy"}),h&&jsxRuntime.jsx("div",{style:i.sub,children:jsxRuntime.jsxs("span",{children:["\u2387 ",h]})})]}),jsxRuntime.jsx(S,{d:m.chevronUp,className:""}),jsxRuntime.jsx("button",{style:i.btn,onClick:r=>{r.stopPropagation(),Ue(false);},children:jsxRuntime.jsx(S,{d:m.minus,className:""})})]}),jsxRuntime.jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[ge.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsxRuntime.jsx($e,{config:e,appSlug:n,environment:Y,seededUsers:ge,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:t,testRunId:a,testRunToken:l,ticketId:d,targetUrl:re,version:v,commitSha:R,prNumber:y,branchName:h,onAuthExpired:f.logout})}),jsxRuntime.jsx("button",{onClick:r=>{r.stopPropagation(),rn();},disabled:qe,style:{fontSize:"10px",fontWeight:600,padding:"6px 12px",borderRadius:"6px",border:`1px solid ${t.green}`,background:`${t.green}22`,color:t.green,cursor:qe?"wait":"pointer",width:"100%"},children:qe?"Creating...":"Create test run for this branch"}),_t&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:t.red,marginTop:"8px"},children:_t})]})]})}):jsxRuntime.jsx("div",{ref:D,style:{...i.root,left:u.x,top:u.y},children:jsxRuntime.jsxs("div",{style:{...i.pill(false),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:P,onPointerMove:M,onPointerUp:()=>{I(),V.current||Ue(true);},children:[jsxRuntime.jsx(S,{d:m.grip,size:9,className:""}),jsxRuntime.jsx("span",{style:{fontWeight:600},children:"BotBuddy"}),ge.length>0&&jsxRuntime.jsx($e,{config:e,appSlug:n,environment:Y,seededUsers:ge,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:t,compact:true,onExpand:()=>Ue(true),testRunId:a,testRunToken:l,ticketId:d,targetUrl:re,version:v,commitSha:R,prNumber:y,branchName:h,onAuthExpired:f.logout})]})});let Nt=()=>{V.current||(T(false),ee(r=>{let p=r==="mini"?"max":"mini";return A(p==="mini"),p}));},Pt=({icon:r,onClick:p})=>jsxRuntime.jsx("button",{style:i.btn,onClick:w=>{w.stopPropagation(),p(w);},children:jsxRuntime.jsx(S,{d:r,className:""})}),Lt=()=>jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${t.borderSubtle}`,flexShrink:0},children:[b?.pr_url&&jsxRuntime.jsxs("a",{href:b.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link(t.blue),textDecoration:"none"},children:[jsxRuntime.jsx(S,{d:m.pr,size:12}),b.pr_number?`PR#${b.pr_number}`:b.pr_id||"PR",jsxRuntime.jsx(S,{d:m.externalLink,size:8})]}),b?.ticket_url&&jsxRuntime.jsxs("a",{href:b.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link(t.amber),textDecoration:"none"},children:[jsxRuntime.jsx(S,{d:m.ticket,size:12}),b.ticket_id||"Ticket",jsxRuntime.jsx(S,{d:m.externalLink,size:8})]}),b?.created_by_agent_name&&(b.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${b.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:{...i.link(t.purple),textDecoration:"none"},children:[jsxRuntime.jsx(S,{d:m.bot,size:12}),b.created_by_agent_name,jsxRuntime.jsx(S,{d:m.externalLink,size:8})]}):jsxRuntime.jsxs("span",{style:{...i.link(t.purple)},children:[jsxRuntime.jsx(S,{d:m.bot,size:12}),b.created_by_agent_name]})),Y&&jsxRuntime.jsx($e,{config:e,appSlug:n,environment:Y,seededUsers:ge,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:t,testRunId:b?.id||a,testRunToken:l,ticketId:d,targetUrl:re,version:v,commitSha:R,prNumber:y,branchName:h,onAuthExpired:f.logout}),jsxRuntime.jsx("span",{style:{...i.badge(b?.environment||"custom"),marginLeft:"auto"},children:b?.environment})]}),$t=()=>jsxRuntime.jsxs("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:`1px solid ${t.borderSubtle}`,background:t.bgSoft,flexShrink:0},children:[jsxRuntime.jsxs("button",{onClick:()=>{navigator.clipboard.writeText(Wt);},style:{fontSize:"9px",fontWeight:600,color:t.versionText,letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsxRuntime.jsxs("span",{style:{color:t.versionNum},children:["v",Wt]})]}),f.isAuthenticated&&(f.isExpired?jsxRuntime.jsx("button",{onClick:r=>{r.stopPropagation(),f.openLogin();},style:{fontSize:"8px",color:t.blue,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Widget session expired \u2014 sign in to refresh",children:"sign in"}):jsxRuntime.jsx("button",{onClick:r=>{r.stopPropagation(),f.logout();},style:{fontSize:"8px",color:t.textFaint,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Sign out of widget",children:"sign out"}))]});return jsxRuntime.jsxs("div",{ref:D,style:{...i.root,left:u.x,top:u.y},children:[se==="mini"&&jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>N(true),onMouseLeave:()=>{N(false),A(false),T(false);},children:[jsxRuntime.jsxs("div",{style:{...i.pill(Re),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:P,onPointerMove:M,onPointerUp:()=>{I(),V.current||Nt();},children:[jsxRuntime.jsx(S,{d:m.grip,size:9,className:""}),b?.ticket_id&&jsxRuntime.jsx("span",{style:{color:t.amber,fontWeight:600},children:b.ticket_id}),b?.pr_number&&jsxRuntime.jsxs("span",{style:{color:t.blue,fontWeight:600},children:["PR#",b.pr_number]}),jsxRuntime.jsxs("span",{style:Re?{color:t.green}:void 0,children:[K.pass,"/",K.total]}),K.fail>0&&jsxRuntime.jsxs("span",{style:{color:t.red},children:[K.fail,"\u2717"]}),Y&&jsxRuntime.jsx($e,{config:e,appSlug:n,environment:Y,seededUsers:ge,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:t,compact:true,onExpand:()=>ee("expanded"),testRunId:b?.id||a,testRunToken:l,ticketId:d,targetUrl:re,version:v,commitSha:R,prNumber:y,branchName:h,onAuthExpired:f.logout})]}),!C&&(U||z)&&b?.title&&jsxRuntime.jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:t.bg,border:`1px solid ${t.border}`,boxShadow:`0 8px 24px ${t.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsxRuntime.jsx("div",{style:{fontSize:"11px",fontWeight:700,color:t.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:b.title}),(b.description||b.intro_notes)&&jsxRuntime.jsx("div",{style:{fontSize:"10px",color:t.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:b.description||b.intro_notes})]})]}),se==="expanded"&&jsxRuntime.jsxs("div",{style:i.card(300,Re),children:[jsxRuntime.jsxs("div",{style:i.handle,onPointerDown:P,onPointerMove:M,onPointerUp:I,onClick:Nt,children:[jsxRuntime.jsx(S,{d:m.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:i.title,children:b?.title}),jsxRuntime.jsx("div",{style:i.sub,children:b?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",b.branch_name]})})]}),jsxRuntime.jsx(S,{d:m.chevronUp,className:""}),jsxRuntime.jsx(Pt,{icon:m.minus,onClick:()=>{T(false),A(true),ee("mini");}})]}),jsxRuntime.jsxs("div",{style:i.stats,children:[jsxRuntime.jsxs("span",{style:{color:t.green},children:[K.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:t.red},children:[K.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:t.amber},children:[K.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:t.gripColor},children:[K.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:t.textFaint,marginLeft:"auto"},children:K.total})]}),b?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:t.gripColor,borderBottom:`1px solid ${t.borderSubtle}`,flexShrink:0},children:b.description}),Lt(),$t(),jsxRuntime.jsx("div",{style:i.progress,children:jsxRuntime.jsx("div",{style:i.progressBar(Ct)})})]}),se==="max"&&jsxRuntime.jsxs("div",{style:{...i.card(Z.w,Re),height:Z.h,position:"relative"},children:[jsxRuntime.jsxs("div",{style:i.handle,onPointerDown:P,onPointerMove:M,onPointerUp:I,onClick:()=>{V.current||ee("expanded");},children:[jsxRuntime.jsx(S,{d:m.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:i.title,children:b?.title}),jsxRuntime.jsx("div",{style:i.sub,children:b?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",b.branch_name]})})]}),jsxRuntime.jsx(S,{d:m.chevronDown,className:""}),jsxRuntime.jsx(Pt,{icon:m.minus,onClick:()=>{T(false),A(true),ee("mini");}})]}),jsxRuntime.jsxs("div",{style:i.stats,children:[jsxRuntime.jsxs("span",{style:{color:t.green},children:[K.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:t.red},children:[K.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:t.amber},children:[K.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:t.gripColor},children:[K.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:t.textFaint,marginLeft:"auto"},children:K.total})]}),b?.intro_notes&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${t.borderSubtle}`,fontSize:"10px",color:t.textMuted,fontStyle:"italic",flexShrink:0},children:b.intro_notes}),(b?.test_cases||[]).length>5&&jsxRuntime.jsxs("div",{style:{padding:"4px 12px",borderBottom:`1px solid ${t.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[jsxRuntime.jsx(S,{d:m.search,size:11,className:""}),jsxRuntime.jsx("input",{value:ne,onChange:r=>Se(r.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:t.text,fontFamily:"monospace"}}),ne&&jsxRuntime.jsx("button",{onClick:()=>Se(""),style:{background:"none",border:"none",cursor:"pointer",color:t.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),he==="error"&&jsxRuntime.jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsxRuntime.jsx(S,{d:m.alert,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:t.red},children:"Failed to load"}),jsxRuntime.jsx("button",{onClick:Qt,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),Re&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${t.greenBorderSubtle}`,background:t.greenBg},children:[jsxRuntime.jsx(S,{d:m.checkAll,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",color:t.green,flex:1},children:"Run completed"}),jsxRuntime.jsx("button",{onClick:tn,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),he!=="error"&&jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(b?.test_cases||[]).length===0?jsxRuntime.jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:t.gripColor},children:"No test cases"}):We.length===0?jsxRuntime.jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:t.gripColor},children:['No matches for "',ne,'"']}):Tt?Tt.map(r=>{let p=Ee.has(r.key);return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>_e(r.key),style:{width:"100%",display:"flex",alignItems:"center",gap:"6px",padding:"5px 12px",background:t.bgSoft,cursor:"pointer",border:"none",borderLeft:"none",borderRight:"none",borderBottomStyle:"solid",borderTopStyle:"solid",borderBottomWidth:"1px",borderTopWidth:"1px",borderBottomColor:t.borderSubtle,borderTopColor:t.borderSubtle,backgroundColor:t.bgSoft},children:[jsxRuntime.jsx(S,{d:p?m.chevronDown:m.chevronUp,size:10,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",fontWeight:700,color:t.blue,flex:1,textAlign:"left"},children:r.label}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:t.green},children:[r.summary.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:t.red},children:[r.summary.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:t.gripColor},children:[r.summary.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{fontSize:"9px",color:t.textFaint},children:r.summary.total})]}),!p&&r.cases.map(w=>Et(w))]},r.key)}):We.map(r=>Et(r))}),on&&!Re&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",borderTop:`1px solid ${t.greenBorderSubtle}`,background:t.greenBg,display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsxRuntime.jsx("span",{style:{fontSize:"9px",color:t.green},children:"All resolved"}),jsxRuntime.jsx("button",{onClick:en,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:t.green,border:`1px solid ${t.greenBorderSubtle}`,cursor:"pointer"},children:"COMPLETE"})]}),Lt(),$t(),jsxRuntime.jsx("div",{style:i.progress,children:jsxRuntime.jsx("div",{style:i.progressBar(Ct)})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:0,right:0,width:16,height:16,cursor:"se-resize",zIndex:10,display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:"2px",opacity:.3},onPointerDown:Jt,onPointerMove:Gt,onPointerUp:Xt,onPointerEnter:r=>r.currentTarget.style.opacity="0.7",onPointerLeave:r=>{Ne.current||(r.currentTarget.style.opacity="0.3");},children:jsxRuntime.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsxRuntime.jsx("path",{d:"M7 1v6H1",fill:"none",stroke:t.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}var $n=1e4,Be=new Map;var Ke=class extends Error{};async function Bn(e,n,s){let d={headers:{authorization:`Bearer ${n}`}};try{return await fetch(e,{...d,signal:s})}catch(a){if(a instanceof TypeError&&/signal/i.test(a.message)&&!s.aborted)return fetch(e,d);throw a}}function zn(e){let n=e;return !!n&&typeof n=="object"&&typeof n.tenant=="string"&&Array.isArray(n.entries)&&n.entries.every(s=>!!s&&typeof s.id=="string"&&typeof s.title=="string"&&!!s.body&&Array.isArray(s.body.ast)&&Array.isArray(s.links))}function ct({endpoint:e,getToken:n,timeoutMs:s=$n}){let[d,a]=react.useState(()=>({feed:null,error:null,loading:true,stale:false})),[l,_]=react.useState(0),v=react.useRef(n);v.current=n,react.useEffect(()=>{let y=new AbortController,h=true,B=false,j=setTimeout(()=>{B=true,y.abort();},s),k=new Promise((t,i)=>{y.signal.addEventListener("abort",()=>i(new Error("timeout")),{once:true});});k.catch(()=>{}),a(t=>({...t,error:null,loading:true}));let x=null,g=(t,i)=>{if(i&&Be.delete(e),!h)return;let U=i||x===null?void 0:Be.get(e)?.get(x);a({feed:U??null,error:t,loading:false,stale:!!U});};return (async()=>{try{let t;try{t=await Promise.race([Promise.resolve().then(()=>v.current()),k]);}catch(z){throw B||y.signal.aborted?z:new Ke("token_unavailable")}x=t;let i=await Promise.race([Bn(e,t,y.signal),k]),U=i.status===401||i.status===403;U&&Be.delete(e);let N=null;try{N=await Promise.race([i.json(),k]);}catch(z){if(B&&!U)throw z;N=null;}if(!h)return;if(i.ok)if(!zn(N))g("invalid_feed",!1);else {let z=Be.get(e)??new Map;z.set(t,N),Be.set(e,z),a({feed:N,error:null,loading:!1,stale:!1});}else {let z=N?.error;g(typeof z=="string"?z:`http_${i.status}`,U);}}catch(t){t instanceof Ke?g(t.message,true):g(B?"timeout":t instanceof Error&&t.message||"unavailable",false);}finally{clearTimeout(j);}})(),()=>{h=false,clearTimeout(j),y.abort();}},[e,l,s]);let R=react.useCallback(()=>_(y=>y+1),[]);return {...d,reload:R}}var gt=["accent","fg","bg","muted","border","radius","font"],An={accent:"hsl(var(--primary))",fg:"hsl(var(--foreground))",bg:"hsl(var(--card))",muted:"hsl(var(--muted-foreground))",border:"hsl(var(--border))",radius:"var(--radius)",font:"inherit"},Me=(e,n)=>n===void 0?`var(--bbrn-${e},var(--_bbrn-${e}))`:`var(--bbrn-${e},var(--_bbrn-${e},${n}))`,ut=Me("accent","currentColor"),Un=Me("muted","color-mix(in srgb,currentColor 72%,transparent)"),pt=Me("border","color-mix(in srgb,currentColor 22%,transparent)"),In=`@layer bbrn{
|
|
2
|
+
.bbrn-root{${gt.filter(e=>e!=="font").map(e=>`--_bbrn-${e}:${An[e]};`).join("")}display:grid;gap:12px;color:${Me("fg")};font-family:var(--bbrn-font)}
|
|
3
|
+
.bbrn-root .bbrn-entry{background:${Me("bg","transparent")};border:1px solid ${pt};border-radius:${Me("radius",".5rem")};padding:16px}
|
|
4
4
|
.bbrn-root .bbrn-head{display:flex;gap:8px;align-items:baseline;flex-wrap:wrap}
|
|
5
|
-
.bbrn-root .bbrn-title{font-weight:600;font-size:1rem;margin:0}
|
|
6
|
-
.bbrn-root .bbrn-badge{font-size:.75rem;border:1px solid currentColor;border-radius:999px;padding:0 8px}
|
|
7
|
-
.bbrn-root .bbrn-delivery{font-size:.75rem;border-radius:999px;padding:0 8px;background:
|
|
8
|
-
.bbrn-root .bbrn-meta{color
|
|
5
|
+
.bbrn-root .bbrn-title{font-weight:600;font-size:1rem;line-height:1.4;margin:0}
|
|
6
|
+
.bbrn-root .bbrn-badge{font-size:.75rem;line-height:1.4;color:${ut};border:1px solid currentColor;border-radius:999px;padding:0 8px}
|
|
7
|
+
.bbrn-root .bbrn-delivery{font-size:.75rem;line-height:1.4;border-radius:999px;padding:0 8px;background:color-mix(in srgb,${pt} 60%,transparent)}
|
|
8
|
+
.bbrn-root .bbrn-meta,.bbrn-root .bbrn-status{color:${Un};font-size:.8rem;margin:0}
|
|
9
9
|
.bbrn-root .bbrn-p{margin:.5em 0}
|
|
10
10
|
.bbrn-root .bbrn-list{margin:.5em 0;padding-left:1.25em;list-style:disc}
|
|
11
|
-
.bbrn-root .bbrn-code{font-family:ui-monospace,monospace;font-size:.85em;padding:0 4px;border-radius:4px;background:
|
|
11
|
+
.bbrn-root .bbrn-code{font-family:ui-monospace,monospace;font-size:.85em;padding:0 4px;border-radius:4px;background:color-mix(in srgb,${pt} 60%,transparent)}
|
|
12
12
|
.bbrn-root .bbrn-links{display:flex;gap:12px;flex-wrap:wrap;margin-top:8px;font-size:.85rem}
|
|
13
|
-
.bbrn-root .bbrn-link{text-decoration:underline}
|
|
14
|
-
.bbrn-root .bbrn-retry{margin-left:8px;text-decoration:underline;background:none;border:0;padding:0;color
|
|
15
|
-
}`;function
|
|
13
|
+
.bbrn-root .bbrn-link{color:${ut};text-decoration:underline}
|
|
14
|
+
.bbrn-root .bbrn-retry{margin-left:8px;text-decoration:underline;background:none;border:0;padding:0;color:${ut};cursor:pointer;font:inherit}
|
|
15
|
+
}`;function jt(e=typeof document>"u"?void 0:document){if(!e?.head||e.head.querySelector("style[data-bbrn-styles]"))return;let n=e.createElement("style");n.setAttribute("data-bbrn-styles",""),n.textContent=In,e.head.prepend(n);}function Vt(e){if(!e)return;let n={};for(let s of gt){let d=e[s];typeof d=="string"&&d.trim()&&(n[`--bbrn-${s}`]=d);}return Object.keys(n).length?n:void 0}function Yt(e){if(typeof e!="string"||/[\s\\]/.test(e))return null;if(e.startsWith("/"))return e.startsWith("//")?null:{kind:"internal",href:e};try{return new URL(e).protocol==="https:"?{kind:"external",href:e}:null}catch{return null}}function je(e,n=""){return e.map((s,d)=>{let a=`${n}${d}`;switch(s.t){case "text":return s.v;case "code":return jsxRuntime.jsx("code",{className:"bbrn-code",children:s.v},a);case "strong":return jsxRuntime.jsx("strong",{children:je(s.c,`${a}.`)},a);case "em":return jsxRuntime.jsx("em",{children:je(s.c,`${a}.`)},a);default:return null}})}function qt({ast:e}){return jsxRuntime.jsx(jsxRuntime.Fragment,{children:e.map((n,s)=>n.t==="list"?jsxRuntime.jsx("ul",{className:"bbrn-list",children:n.items.map((d,a)=>jsxRuntime.jsx("li",{children:je(d)},a))},s):n.t==="p"?jsxRuntime.jsx("p",{className:"bbrn-p",children:je(n.c)},s):null)})}var G=(...e)=>e.filter(Boolean).join(" "),Kn=react.useInsertionEffect??react.useLayoutEffect,ft=class extends react.Component{constructor(){super(...arguments);this.state={failed:false,keys:this.props.resetKeys};}static getDerivedStateFromError(){return {failed:true}}static getDerivedStateFromProps(s,d){return s.resetKeys.length!==d.keys.length||s.resetKeys.some((l,_)=>!Object.is(l,d.keys[_]))?{failed:false,keys:s.resetKeys}:null}componentDidCatch(){}render(){return this.state.failed?this.props.fallback:this.props.children}};function jn({endpoint:e,getToken:n,onNavigate:s,theme:d,classNames:a,components:l,timeoutMs:_}){Kn(()=>{jt();},[]);let{feed:v,error:R,loading:y,stale:h,reload:B}=ct({endpoint:e,getToken:n,timeoutMs:_}),[j,k]=react.useState(0),x=()=>{k(T=>T+1),B();},g=react.useMemo(()=>Vt(d),[d]),t=a??{},i=l?.Empty,U=l?.Link,N=T=>C=>{!s||C.defaultPrevented||C.button!==0||C.metaKey||C.ctrlKey||C.shiftKey||C.altKey||(C.preventDefault(),s(T));},z=jsxRuntime.jsxs("p",{className:G("bbrn-status",t.status),role:"alert","data-bbrn-error":R??"render_failed",children:["Release notes could not be loaded.",jsxRuntime.jsx("button",{type:"button",className:G("bbrn-retry",t.retry),onClick:x,children:"Retry"})]});return jsxRuntime.jsxs("section",{className:G("bbrn-root",t.root),style:g,"aria-label":"Release notes","aria-busy":y,"data-bbrn-audience":v?.audience,children:[y&&!v&&jsxRuntime.jsx("p",{className:G("bbrn-status",t.status),role:"status",children:"Loading release notes\u2026"}),!y&&R&&!v&&z,h&&jsxRuntime.jsxs("p",{className:G("bbrn-status",t.status),role:"status","data-bbrn-stale":"",children:["Showing the last loaded notes; they could not be refreshed.",jsxRuntime.jsx("button",{type:"button",className:G("bbrn-retry",t.retry),onClick:x,children:"Retry"})]}),v&&jsxRuntime.jsxs(ft,{resetKeys:[v,i,U,j],fallback:z,children:[v.entries.length===0&&(i?jsxRuntime.jsx(i,{}):jsxRuntime.jsxs("p",{className:G("bbrn-status",t.status),children:["No release notes yet. Submit one with ",jsxRuntime.jsx("code",{className:"bbrn-code",children:"bb release-notes submit"}),"."]})),v.entries.map(T=>jsxRuntime.jsxs("article",{className:G("bbrn-entry",t.entry),"data-entry-id":T.id,"data-source-key":T.source_key,children:[jsxRuntime.jsxs("div",{className:G("bbrn-head",t.head),children:[jsxRuntime.jsx("h2",{className:G("bbrn-title",t.title),children:T.title}),jsxRuntime.jsx("span",{className:G("bbrn-badge",t.badge),"data-bbrn-type":T.type,children:T.type}),jsxRuntime.jsx("span",{className:G("bbrn-badge",t.badge),"data-bbrn-state":T.state,children:T.state}),jsxRuntime.jsxs("span",{className:G("bbrn-meta",t.meta),children:[T.source_key," \xB7 revision ",T.revision]}),T.delivery_copy&&jsxRuntime.jsx("span",{className:G("bbrn-delivery",t.delivery),"data-bbrn-delivery":T.delivery_badge,children:T.delivery_copy})]}),jsxRuntime.jsx("div",{className:G("bbrn-body",t.body),children:jsxRuntime.jsx(qt,{ast:T.body.ast})}),T.links.length>0&&jsxRuntime.jsx("div",{className:G("bbrn-links",t.links),children:T.links.map((C,A)=>{let X=Yt(C.url);if(!X)return null;let Q=G("bbrn-link",t.link),f=C.kind??null;return U?jsxRuntime.jsx(U,{href:X.href,external:X.kind==="external",kind:f,className:Q,onClick:X.kind==="internal"&&s?N(X.href):void 0,children:C.name},A):X.kind==="external"?jsxRuntime.jsx("a",{className:Q,href:X.href,target:"_blank",rel:"noopener noreferrer","data-link-kind":f??void 0,children:C.name},A):jsxRuntime.jsx("a",{className:Q,href:X.href,onClick:N(X.href),"data-link-kind":f??void 0,children:C.name},A)})})]},T.id))]})]})}
|
|
16
|
+
exports.RELEASE_NOTES_TOKENS=gt;exports.ReleaseNoteBody=qt;exports.ReleaseNotes=jn;exports.TestRunWidget=En;exports.safeHref=Yt;exports.useDraggable=et;exports.useRealtimeRefresh=tt;exports.useReleaseNotes=ct;exports.useTestRun=rt;exports.useWidgetAuth=lt;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
|
+
import { ReactNode, MouseEvent, ComponentType } from 'react';
|
|
3
4
|
|
|
4
5
|
interface TestRun {
|
|
5
6
|
id: string;
|
|
@@ -136,7 +137,8 @@ interface ReleaseNoteLink {
|
|
|
136
137
|
url: string;
|
|
137
138
|
kind: string | null;
|
|
138
139
|
}
|
|
139
|
-
|
|
140
|
+
/** BOT-3169: `draft_on_your_branch` (local) and `in_this_preview` (preview) mark the viewer's own branch drafts. */
|
|
141
|
+
type ReleaseNoteDeliveryBadge = "not_bound" | "draft_on_branch" | "draft_on_pr" | "merged" | "draft_on_your_branch" | "in_this_preview";
|
|
140
142
|
interface ReleaseNoteEntry {
|
|
141
143
|
id: string;
|
|
142
144
|
source_key: string;
|
|
@@ -158,6 +160,33 @@ interface ReleaseNotesFeed {
|
|
|
158
160
|
audience: "internal";
|
|
159
161
|
entries: ReleaseNoteEntry[];
|
|
160
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* BOT-3159 depth 1: design tokens. Each key is written as the `--bbrn-<key>`
|
|
165
|
+
* CSS variable on the component root. The same variables can be set from the
|
|
166
|
+
* host's own CSS instead (on `.bbrn-root` or any ancestor).
|
|
167
|
+
*/
|
|
168
|
+
type ReleaseNotesTheme = Partial<Record<ReleaseNotesToken, string>>;
|
|
169
|
+
type ReleaseNotesToken = "accent" | "fg" | "bg" | "muted" | "border" | "radius" | "font";
|
|
170
|
+
/** BOT-3159 depth 2: class names added (never replacing the `bbrn-*` class) to each part. */
|
|
171
|
+
type ReleaseNotesClassNames = Partial<Record<ReleaseNotesSlot, string>>;
|
|
172
|
+
type ReleaseNotesSlot = "root" | "entry" | "head" | "title" | "badge" | "delivery" | "meta" | "body" | "links" | "link" | "status" | "retry";
|
|
173
|
+
/** Props the `components.Link` override receives. `className` already holds the link slot. */
|
|
174
|
+
interface ReleaseNoteLinkProps {
|
|
175
|
+
href: string;
|
|
176
|
+
/** true for an https link (new tab); false for an app path. */
|
|
177
|
+
external: boolean;
|
|
178
|
+
kind: string | null;
|
|
179
|
+
className: string;
|
|
180
|
+
children: ReactNode;
|
|
181
|
+
/** Present for an app path when `onNavigate` is set: routes a plain click through it. */
|
|
182
|
+
onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
|
|
183
|
+
}
|
|
184
|
+
interface ReleaseNotesComponents {
|
|
185
|
+
/** Rendered instead of the default line when the feed has no entries. */
|
|
186
|
+
Empty?: ComponentType;
|
|
187
|
+
/** Rendered for each safe link instead of the default anchor. */
|
|
188
|
+
Link?: ComponentType<ReleaseNoteLinkProps>;
|
|
189
|
+
}
|
|
161
190
|
interface ReleaseNotesProps {
|
|
162
191
|
/** The feed URL, e.g. `${MCP_URL}/release-notes/feed?tenant=<slug>`. */
|
|
163
192
|
endpoint: string;
|
|
@@ -165,6 +194,14 @@ interface ReleaseNotesProps {
|
|
|
165
194
|
getToken: () => Promise<string>;
|
|
166
195
|
/** Called with an app path (a link starting with one /) instead of a full page load. */
|
|
167
196
|
onNavigate?: (path: string) => void;
|
|
197
|
+
/** Token values; each becomes `--bbrn-<key>` on the root. Appearance only. */
|
|
198
|
+
theme?: ReleaseNotesTheme;
|
|
199
|
+
/** Extra class names per part. Host rules win over the component's without `!important`. */
|
|
200
|
+
classNames?: ReleaseNotesClassNames;
|
|
201
|
+
/** Replacement parts. */
|
|
202
|
+
components?: ReleaseNotesComponents;
|
|
203
|
+
/** Abort the feed request after this many milliseconds (default 10000). */
|
|
204
|
+
timeoutMs?: number;
|
|
168
205
|
}
|
|
169
206
|
|
|
170
207
|
declare function safeHref(url: string): {
|
|
@@ -174,7 +211,7 @@ declare function safeHref(url: string): {
|
|
|
174
211
|
declare function ReleaseNoteBody({ ast }: {
|
|
175
212
|
ast: ReleaseNoteBlock[];
|
|
176
213
|
}): react_jsx_runtime.JSX.Element;
|
|
177
|
-
declare function ReleaseNotes({ endpoint, getToken, onNavigate }: ReleaseNotesProps): react_jsx_runtime.JSX.Element;
|
|
214
|
+
declare function ReleaseNotes({ endpoint, getToken, onNavigate, theme, classNames, components, timeoutMs }: ReleaseNotesProps): react_jsx_runtime.JSX.Element;
|
|
178
215
|
|
|
179
216
|
declare function useDraggable(initialX: number, initialY: number): {
|
|
180
217
|
pos: {
|
|
@@ -263,13 +300,19 @@ declare function useRealtimeRefresh(config: BotBuddyConfig, testRunId: string |
|
|
|
263
300
|
interface UseReleaseNotesOptions {
|
|
264
301
|
endpoint: string;
|
|
265
302
|
getToken: () => Promise<string>;
|
|
303
|
+
/** Abort the attempt after this many milliseconds (default 10000). */
|
|
304
|
+
timeoutMs?: number;
|
|
266
305
|
}
|
|
267
306
|
interface UseReleaseNotesState {
|
|
268
307
|
feed: ReleaseNotesFeed | null;
|
|
269
308
|
error: string | null;
|
|
270
309
|
loading: boolean;
|
|
310
|
+
/** true when `feed` is the last good feed from this page load and the latest attempt failed. */
|
|
311
|
+
stale: boolean;
|
|
271
312
|
reload: () => void;
|
|
272
313
|
}
|
|
273
|
-
declare function useReleaseNotes({ endpoint, getToken }: UseReleaseNotesOptions): UseReleaseNotesState;
|
|
314
|
+
declare function useReleaseNotes({ endpoint, getToken, timeoutMs }: UseReleaseNotesOptions): UseReleaseNotesState;
|
|
315
|
+
|
|
316
|
+
declare const RELEASE_NOTES_TOKENS: readonly ReleaseNotesToken[];
|
|
274
317
|
|
|
275
|
-
export { type BotBuddyConfig, type ReleaseNoteBlock, ReleaseNoteBody, type ReleaseNoteBody$1 as ReleaseNoteBodyData, type ReleaseNoteEntry, type ReleaseNoteInline, type ReleaseNoteLink, ReleaseNotes, type ReleaseNotesFeed, type ReleaseNotesProps, type TestCase, type TestRun, type TestRunSummary, TestRunWidget, type TestRunWidgetProps, type UseReleaseNotesOptions, type UseReleaseNotesState, type Verdict, type WidgetMode, type WidgetState, safeHref, useDraggable, useRealtimeRefresh, useReleaseNotes, useTestRun, useWidgetAuth };
|
|
318
|
+
export { type BotBuddyConfig, RELEASE_NOTES_TOKENS, type ReleaseNoteBlock, ReleaseNoteBody, type ReleaseNoteBody$1 as ReleaseNoteBodyData, type ReleaseNoteEntry, type ReleaseNoteInline, type ReleaseNoteLink, type ReleaseNoteLinkProps, ReleaseNotes, type ReleaseNotesClassNames, type ReleaseNotesComponents, type ReleaseNotesFeed, type ReleaseNotesProps, type ReleaseNotesSlot, type ReleaseNotesTheme, type ReleaseNotesToken, type TestCase, type TestRun, type TestRunSummary, TestRunWidget, type TestRunWidgetProps, type UseReleaseNotesOptions, type UseReleaseNotesState, type Verdict, type WidgetMode, type WidgetState, safeHref, useDraggable, useRealtimeRefresh, useReleaseNotes, useTestRun, useWidgetAuth };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
|
+
import { ReactNode, MouseEvent, ComponentType } from 'react';
|
|
3
4
|
|
|
4
5
|
interface TestRun {
|
|
5
6
|
id: string;
|
|
@@ -136,7 +137,8 @@ interface ReleaseNoteLink {
|
|
|
136
137
|
url: string;
|
|
137
138
|
kind: string | null;
|
|
138
139
|
}
|
|
139
|
-
|
|
140
|
+
/** BOT-3169: `draft_on_your_branch` (local) and `in_this_preview` (preview) mark the viewer's own branch drafts. */
|
|
141
|
+
type ReleaseNoteDeliveryBadge = "not_bound" | "draft_on_branch" | "draft_on_pr" | "merged" | "draft_on_your_branch" | "in_this_preview";
|
|
140
142
|
interface ReleaseNoteEntry {
|
|
141
143
|
id: string;
|
|
142
144
|
source_key: string;
|
|
@@ -158,6 +160,33 @@ interface ReleaseNotesFeed {
|
|
|
158
160
|
audience: "internal";
|
|
159
161
|
entries: ReleaseNoteEntry[];
|
|
160
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* BOT-3159 depth 1: design tokens. Each key is written as the `--bbrn-<key>`
|
|
165
|
+
* CSS variable on the component root. The same variables can be set from the
|
|
166
|
+
* host's own CSS instead (on `.bbrn-root` or any ancestor).
|
|
167
|
+
*/
|
|
168
|
+
type ReleaseNotesTheme = Partial<Record<ReleaseNotesToken, string>>;
|
|
169
|
+
type ReleaseNotesToken = "accent" | "fg" | "bg" | "muted" | "border" | "radius" | "font";
|
|
170
|
+
/** BOT-3159 depth 2: class names added (never replacing the `bbrn-*` class) to each part. */
|
|
171
|
+
type ReleaseNotesClassNames = Partial<Record<ReleaseNotesSlot, string>>;
|
|
172
|
+
type ReleaseNotesSlot = "root" | "entry" | "head" | "title" | "badge" | "delivery" | "meta" | "body" | "links" | "link" | "status" | "retry";
|
|
173
|
+
/** Props the `components.Link` override receives. `className` already holds the link slot. */
|
|
174
|
+
interface ReleaseNoteLinkProps {
|
|
175
|
+
href: string;
|
|
176
|
+
/** true for an https link (new tab); false for an app path. */
|
|
177
|
+
external: boolean;
|
|
178
|
+
kind: string | null;
|
|
179
|
+
className: string;
|
|
180
|
+
children: ReactNode;
|
|
181
|
+
/** Present for an app path when `onNavigate` is set: routes a plain click through it. */
|
|
182
|
+
onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
|
|
183
|
+
}
|
|
184
|
+
interface ReleaseNotesComponents {
|
|
185
|
+
/** Rendered instead of the default line when the feed has no entries. */
|
|
186
|
+
Empty?: ComponentType;
|
|
187
|
+
/** Rendered for each safe link instead of the default anchor. */
|
|
188
|
+
Link?: ComponentType<ReleaseNoteLinkProps>;
|
|
189
|
+
}
|
|
161
190
|
interface ReleaseNotesProps {
|
|
162
191
|
/** The feed URL, e.g. `${MCP_URL}/release-notes/feed?tenant=<slug>`. */
|
|
163
192
|
endpoint: string;
|
|
@@ -165,6 +194,14 @@ interface ReleaseNotesProps {
|
|
|
165
194
|
getToken: () => Promise<string>;
|
|
166
195
|
/** Called with an app path (a link starting with one /) instead of a full page load. */
|
|
167
196
|
onNavigate?: (path: string) => void;
|
|
197
|
+
/** Token values; each becomes `--bbrn-<key>` on the root. Appearance only. */
|
|
198
|
+
theme?: ReleaseNotesTheme;
|
|
199
|
+
/** Extra class names per part. Host rules win over the component's without `!important`. */
|
|
200
|
+
classNames?: ReleaseNotesClassNames;
|
|
201
|
+
/** Replacement parts. */
|
|
202
|
+
components?: ReleaseNotesComponents;
|
|
203
|
+
/** Abort the feed request after this many milliseconds (default 10000). */
|
|
204
|
+
timeoutMs?: number;
|
|
168
205
|
}
|
|
169
206
|
|
|
170
207
|
declare function safeHref(url: string): {
|
|
@@ -174,7 +211,7 @@ declare function safeHref(url: string): {
|
|
|
174
211
|
declare function ReleaseNoteBody({ ast }: {
|
|
175
212
|
ast: ReleaseNoteBlock[];
|
|
176
213
|
}): react_jsx_runtime.JSX.Element;
|
|
177
|
-
declare function ReleaseNotes({ endpoint, getToken, onNavigate }: ReleaseNotesProps): react_jsx_runtime.JSX.Element;
|
|
214
|
+
declare function ReleaseNotes({ endpoint, getToken, onNavigate, theme, classNames, components, timeoutMs }: ReleaseNotesProps): react_jsx_runtime.JSX.Element;
|
|
178
215
|
|
|
179
216
|
declare function useDraggable(initialX: number, initialY: number): {
|
|
180
217
|
pos: {
|
|
@@ -263,13 +300,19 @@ declare function useRealtimeRefresh(config: BotBuddyConfig, testRunId: string |
|
|
|
263
300
|
interface UseReleaseNotesOptions {
|
|
264
301
|
endpoint: string;
|
|
265
302
|
getToken: () => Promise<string>;
|
|
303
|
+
/** Abort the attempt after this many milliseconds (default 10000). */
|
|
304
|
+
timeoutMs?: number;
|
|
266
305
|
}
|
|
267
306
|
interface UseReleaseNotesState {
|
|
268
307
|
feed: ReleaseNotesFeed | null;
|
|
269
308
|
error: string | null;
|
|
270
309
|
loading: boolean;
|
|
310
|
+
/** true when `feed` is the last good feed from this page load and the latest attempt failed. */
|
|
311
|
+
stale: boolean;
|
|
271
312
|
reload: () => void;
|
|
272
313
|
}
|
|
273
|
-
declare function useReleaseNotes({ endpoint, getToken }: UseReleaseNotesOptions): UseReleaseNotesState;
|
|
314
|
+
declare function useReleaseNotes({ endpoint, getToken, timeoutMs }: UseReleaseNotesOptions): UseReleaseNotesState;
|
|
315
|
+
|
|
316
|
+
declare const RELEASE_NOTES_TOKENS: readonly ReleaseNotesToken[];
|
|
274
317
|
|
|
275
|
-
export { type BotBuddyConfig, type ReleaseNoteBlock, ReleaseNoteBody, type ReleaseNoteBody$1 as ReleaseNoteBodyData, type ReleaseNoteEntry, type ReleaseNoteInline, type ReleaseNoteLink, ReleaseNotes, type ReleaseNotesFeed, type ReleaseNotesProps, type TestCase, type TestRun, type TestRunSummary, TestRunWidget, type TestRunWidgetProps, type UseReleaseNotesOptions, type UseReleaseNotesState, type Verdict, type WidgetMode, type WidgetState, safeHref, useDraggable, useRealtimeRefresh, useReleaseNotes, useTestRun, useWidgetAuth };
|
|
318
|
+
export { type BotBuddyConfig, RELEASE_NOTES_TOKENS, type ReleaseNoteBlock, ReleaseNoteBody, type ReleaseNoteBody$1 as ReleaseNoteBodyData, type ReleaseNoteEntry, type ReleaseNoteInline, type ReleaseNoteLink, type ReleaseNoteLinkProps, ReleaseNotes, type ReleaseNotesClassNames, type ReleaseNotesComponents, type ReleaseNotesFeed, type ReleaseNotesProps, type ReleaseNotesSlot, type ReleaseNotesTheme, type ReleaseNotesToken, type TestCase, type TestRun, type TestRunSummary, TestRunWidget, type TestRunWidgetProps, type UseReleaseNotesOptions, type UseReleaseNotesState, type Verdict, type WidgetMode, type WidgetState, safeHref, useDraggable, useRealtimeRefresh, useReleaseNotes, useTestRun, useWidgetAuth };
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {useState,useRef,useCallback,useEffect,useMemo,useLayoutEffect}from'react';import {createPortal}from'react-dom';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var Se=8;function qe(e,n,i,d,a,s){let _=Math.max(Se,a-i-Se),k=Math.max(Se,s-d-Se);return {x:Math.min(Math.max(e,Se),_),y:Math.min(Math.max(n,Se),k)}}function Ge(e,n){let[i,d]=useState({x:e,y:n}),a=useRef(false),s=useRef({x:0,y:0}),_=useRef(false),k=useCallback(h=>{a.current=true,_.current=false,s.current={x:h.clientX-i.x,y:h.clientY-i.y},h.target.setPointerCapture(h.pointerId);},[i]),y=useCallback(h=>{a.current&&(_.current=true,d({x:h.clientX-s.current.x,y:h.clientY-s.current.y}));},[]),p=useCallback(()=>{a.current=false;},[]);return {pos:i,setPos:d,onPointerDown:k,onPointerMove:y,onPointerUp:p,didDrag:_}}function Xe(e,n,i){let d=useRef(i);d.current=i,useEffect(()=>{if(!n)return;if(e.supabaseUrl){let s=false,_=null,k=()=>{s||_||(_=setInterval(()=>d.current(),15e3));},y=null;try{let x=new URL(e.supabaseUrl),r=["localhost","127.0.0.1","::1"].includes(x.hostname);if(x.protocol==="http:"&&!r)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");x.protocol=x.protocol==="https:"?"wss:":"ws:",y=x.toString().replace(/\/$/,"");}catch{k();}let p=null,h=null,T=null,V=0,M=()=>{if(!(s||!y)){try{p=new WebSocket(`${y}/realtime/v1/websocket?apikey=${e.anonKey}&vsn=1.0.0`);}catch{k();return}p.onopen=()=>{if(s||!p)return;let x={topic:`realtime:public:test_run_cases:test_run_id=eq.${n}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_run_cases",filter:`test_run_id=eq.${n}`}]}},ref:String(++V)};p.send(JSON.stringify(x));let r={topic:`realtime:public:test_runs:id=eq.${n}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_runs",filter:`id=eq.${n}`}]}},ref:String(++V)};p.send(JSON.stringify(r)),h=setInterval(()=>{p?.readyState===WebSocket.OPEN&&p.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++V)}));},3e4);},p.onmessage=x=>{try{JSON.parse(x.data).event==="postgres_changes"&&d.current();}catch{}},p.onclose=()=>{v(),s||(T=setTimeout(M,3e3));},p.onerror=()=>{p?.close();};}},v=()=>{h&&(clearInterval(h),h=null);};return M(),()=>{s=true,v(),T&&clearTimeout(T),_&&clearInterval(_),p&&(p.onclose=null,p.onerror=null,p.close());}}let a=setInterval(()=>d.current(),15e3);return ()=>clearInterval(a)},[e.supabaseUrl,e.anonKey,n]);}var Qt="botbuddy:created-test-run:";function en(e){if(!e)return "";try{return new URL(e).origin}catch{return e}}function tn(e){return `${Qt}${encodeURIComponent([e.appSlug,e.environment||"",e.ticketId||"",en(e.targetUrl),e.branchName||""].join("|"))}`}function Ue(e,n){let i={apikey:e.anonKey};return n?i.Authorization=`Bearer ${n}`:e.apiKey?i.Authorization=`Bearer ${e.apiKey}`:i.Authorization=`Bearer ${e.anonKey}`,i}async function nn(e){if(e)return e;try{let n=await fetch("/.botbuddy-token",{cache:"no-store"});if(n.ok){let i=(await n.text()).trim();if(i.startsWith("public_"))return i}}catch{}try{let n=import.meta?.env?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(n&&typeof n=="string"&&n.startsWith("public_"))return n}catch{}return null}function Qe(e){let[n,i]=useState(null),[d,a]=useState("loading"),s=tn(e),[_,k]=useState(()=>{if(e.testRunId)return e.testRunId;try{return localStorage.getItem(s)||void 0}catch{return}}),y=e.testRunId||_,p=useCallback(v=>{if(i(v),!!v?.id){k(v.id);try{localStorage.setItem(s,v.id);}catch{}}},[s]),h=useCallback(async()=>{try{let v=await nn(e.testRunToken);if(!v&&!y){a("no-match"),i(null);return}if(v&&!e.ticketId){a("no-match"),i(null);return}let x=new URLSearchParams;v&&x.set("token",v),e.ticketId&&x.set("ticket_id",e.ticketId),x.set("app_slug",e.appSlug),e.environment&&x.set("environment",e.environment),y&&x.set("test_run_id",y),e.targetUrl&&x.set("target_url",e.targetUrl),e.version&&x.set("version",e.version),e.commitSha&&x.set("commit_sha",e.commitSha),e.prNumber&&x.set("pr_number",String(e.prNumber)),e.branchName&&x.set("branch_name",e.branchName);let r=await fetch(`${e.config.serverUrl}/widget/test-run?${x.toString()}`,{headers:Ue(e.config,e.authToken)});if(r.status===404){a("no-match"),i(null);return}if(r.status===401||r.status===403){e.authToken&&e.onAuthExpired&&e.onAuthExpired(),a("error");return}if(!r.ok){a("error");return}let u=await r.json();if(!u||u.run===null){a("no-match"),i(null);return}p(u),a(u.status==="completed"?"completed":"ready");}catch{a("error");}},[e.config.serverUrl,e.config.anonKey,e.config.apiKey,e.authToken,e.appSlug,e.environment,e.ticketId,y,e.testRunToken,e.targetUrl,e.version,e.commitSha,e.branchName,e.prNumber,e.onAuthExpired,p]);return useEffect(()=>{h();},[h]),Xe(e.config,n?.id,h),{run:n,widgetState:d,fetchRun:h,setVerdict:async(v,x,r,u="human")=>(i(U=>{if(!U)return null;let q=U.test_cases.map(I=>I.id===v?{...I,verdict:x,fail_reason:x==="fail"&&r||null,verdict_by_display_name:u,verdict_at:new Date().toISOString()}:I),Y={total:q.length,pending:0,pass:0,fail:0,skip:0};return q.forEach(I=>{I.verdict in Y&&Y[I.verdict]++;}),{...U,test_cases:q,summary:Y}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${v}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...Ue(e.config,e.authToken)},body:JSON.stringify({verdict:x,fail_reason:r,display_name:u})})).ok),markComplete:async()=>n?(i(x=>x?{...x,status:"completed"}:null),a("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${n.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...Ue(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!n)return false;let v=await fetch(`${e.config.serverUrl}/widget/test-runs/${n.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...Ue(e.config,e.authToken)}});return v.ok&&h(),v.ok},setRun:p}}var nt="botbuddy-widget-auth-token",rt="botbuddy-widget-auth-name";function Ee(e){if(!e)return null;try{let n=e.split(".")[1];if(!n)return null;let i=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(n.length/4)*4,"="),d=atob(i),a=JSON.parse(d);return typeof a.exp=="number"?a.exp*1e3:null}catch{return null}}var on=2500,sn=6e4;function ot(e){let[n,i]=useState(()=>{try{return localStorage.getItem(nt)}catch(M){return console.warn("Unable to read BotBuddy widget auth token",M),null}}),[d,a]=useState(()=>{try{return localStorage.getItem(rt)}catch(M){return console.warn("Unable to read BotBuddy widget display name",M),null}}),s=useRef(null),_=useCallback((M,v)=>{i(M),v&&a(v);try{localStorage.setItem(nt,M),v&&localStorage.setItem(rt,v);}catch(x){console.warn("Unable to persist BotBuddy widget auth token",x);}},[]);useEffect(()=>{let M=new URL(e).origin,v=x=>{x.origin===M&&x.data?.type==="botbuddy-widget-auth"&&x.data.token&&_(x.data.token,x.data.displayName||"human");};return window.addEventListener("message",v),()=>window.removeEventListener("message",v)},[e,_]);let k=useCallback(()=>{if(s.current)return s.current;if(typeof window>"u"||typeof document>"u")return Promise.resolve(null);let M=new URL(e).origin,v=new URL("/widget-auth",e);v.searchParams.set("silent","1"),v.searchParams.set("origin",window.location.origin);let x=new Promise(r=>{let u=document.createElement("iframe");u.setAttribute("aria-hidden","true"),u.style.position="fixed",u.style.width="1px",u.style.height="1px",u.style.opacity="0",u.style.pointerEvents="none",u.style.border="0",u.style.left="-9999px",u.style.top="-9999px",u.src=v.toString();let J=false,U=()=>{window.removeEventListener("message",q),clearTimeout(Y);try{u.remove();}catch{}s.current=null;},q=I=>{if(I.origin===M){if(I.data?.type==="botbuddy-widget-auth-failed"){if(J)return;J=true,r(null),U();return}I.data?.type!=="botbuddy-widget-auth"||!I.data.token||J||(J=true,r(String(I.data.token)),U());}},Y=setTimeout(()=>{J||(J=true,r(null),U());},on);window.addEventListener("message",q),document.body.appendChild(u);});return s.current=x,x},[e]);useEffect(()=>{if(!n)return;let M=Ee(n);if(!M)return;let v=M-Date.now()-sn,x=window.setTimeout(()=>{k();},Math.max(0,v));return ()=>window.clearTimeout(x)},[n,k]);let y=useCallback(()=>{let M=new URL("/widget-auth",e);M.searchParams.set("origin",window.location.origin);let v=420,x=520,r=window.screenX+(window.innerWidth-v)/2,u=window.screenY+(window.innerHeight-x)/2;window.open(M.toString(),"botbuddy-auth",`width=${v},height=${x},left=${r},top=${u},popup=yes`);},[e]),[,p]=useState(0);useEffect(()=>{let M=Ee(n);if(!M)return;let v=M-Date.now();if(v<=0)return;let x=window.setTimeout(()=>p(r=>r+1),v);return ()=>window.clearTimeout(x)},[n]);let h=useCallback(()=>{i(null),a(null);try{localStorage.removeItem(nt),localStorage.removeItem(rt);}catch(M){console.warn("Unable to clear BotBuddy widget auth token",M);}},[]),T=Ee(n),V=T!==null&&T<=Date.now();return {token:n,displayName:d,isAuthenticated:!!n,isExpired:V,openLogin:y,refreshNow:k,logout:h}}var Ie=null;function an(){try{if(typeof document<"u"){let e=document.querySelector("base[href]");if(e)return new URL(".botbuddy-totp.json",e.href).toString()}}catch{}return "/.botbuddy-totp.json"}function Fe(){return Ie||(Ie=(async()=>{if(typeof fetch>"u")return null;try{let e=await fetch(an(),{cache:"no-store"});if(!e.ok)return null;let n=await e.json();if(!n||typeof n!="object"||Array.isArray(n))return null;let i={};for(let[d,a]of Object.entries(n))typeof a=="string"&&a.length>0&&(i[d]=a);return i}catch{return null}})(),Ie)}async function Pt(e){return (await Fe())?.[e]??null}function ln(e){let n=e.replace(/=+$/,"").replace(/\s+/g,"").toUpperCase(),i="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",d=[],a=0,s=0;for(let _ of n){let k=i.indexOf(_);if(k<0)throw new Error("Invalid Base32 character in TOTP secret");s=s<<5|k,a+=5,a>=8&&(a-=8,d.push(s>>>a&255));}return Uint8Array.from(d)}async function Et(e,n=Date.now()){if(typeof crypto>"u"||!crypto.subtle)throw new Error("Web Crypto unavailable");let i=ln(e),d=new Uint8Array(i.byteLength);d.set(i);let a=Math.floor(n/1e3/30),s=new Uint8Array(8),_=Math.floor(a/4294967296),k=a>>>0;s[0]=_>>>24&255,s[1]=_>>>16&255,s[2]=_>>>8&255,s[3]=_&255,s[4]=k>>>24&255,s[5]=k>>>16&255,s[6]=k>>>8&255,s[7]=k&255;let y=await crypto.subtle.importKey("raw",d,{name:"HMAC",hash:"SHA-1"},false,["sign"]),p=await crypto.subtle.sign("HMAC",y,s),h=new Uint8Array(p),T=h[h.length-1]&15;return (((h[T]&127)<<24|(h[T+1]&255)<<16|(h[T+2]&255)<<8|h[T+3]&255)%1e6).toString().padStart(6,"0")}var Lt="0.11.0";function cn(e){let n=new Date(e),d=Date.now()-n.getTime();if(d<6e4)return "just now";if(d<36e5)return `${Math.floor(d/6e4)}m ago`;if(d<864e5)return `${Math.floor(d/36e5)}h ago`;let a=n.getDate(),s=n.toLocaleString("en",{month:"short"}),_=n.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${s} ${a}, ${_}`}var S=({d:e,className:n,size:i=14})=>jsx("svg",{className:n,width:i,height:i,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:e})}),m={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01",bot:"M12 8V4H8M2 14h2M20 14h2M15 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M9 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M18 10a6 6 0 0 0-12 0v4a6 6 0 0 0 12 0Z",terminal:"M4 17l6-6-6-6M12 19h8",key:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4",shield:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10",copy:"M20 9h-9a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2-2v-9a2 2 0 0 0-2-2ZM5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1",search:"M11 17.25a6.25 6.25 0 1 1 0-12.5 6.25 6.25 0 0 1 0 12.5ZM16 16l4.5 4.5"};function un(){let[e,n]=useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return useEffect(()=>{if(typeof window>"u")return;let i=document.documentElement,d=()=>i.classList.contains("dark")?"dark":i.classList.contains("light")?"light":null,a=d();a&&n(a);let s=window.matchMedia("(prefers-color-scheme: dark)"),_=y=>{let p=d();n(p||(y.matches?"dark":"light"));};s.addEventListener("change",_);let k=new MutationObserver(()=>{let y=d();n(y||(s.matches?"dark":"light"));});return k.observe(i,{attributes:true,attributeFilter:["class"]}),()=>{s.removeEventListener("change",_),k.disconnect();}},[]),e}function pn(e){let n=e==="dark";return {bg:n?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:n?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:n?"#e5e5e5":"#1a1a1a",textMuted:n?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:n?"#555":"#999",border:n?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:n?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:n?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:n?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:n?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:n?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:n?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:n?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:n?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:n?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:n?"#888":"#aaa",btnHover:n?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var gn={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},fn={pending:m.circle,pass:m.check,fail:m.x,skip:m.skip},Nt={local:{bg:"rgba(59,130,246,0.15)",text:"#60a5fa",border:"rgba(59,130,246,0.3)"},preview:{bg:"rgba(168,85,247,0.15)",text:"#c084fc",border:"rgba(168,85,247,0.3)"},staging:{bg:"rgba(245,158,11,0.15)",text:"#fbbf24",border:"rgba(245,158,11,0.3)"},production:{bg:"rgba(239,68,68,0.15)",text:"#f87171",border:"rgba(239,68,68,0.3)"},custom:{bg:"rgba(128,128,128,0.15)",text:"#888",border:"rgba(128,128,128,0.3)"}},bn=["app.supply-guard.io"];function mn(e,n=[]){if(!e)return false;let i=e.toLowerCase();return [...bn,...n].map(a=>a.toLowerCase()).includes(i)}var yn=e=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:n=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:e.bg,border:n?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:n?`0 4px 12px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 4px 12px ${e.shadow}`,cursor:"pointer",fontSize:"9px",color:e.text}),card:(n,i)=>({width:`${n}px`,borderRadius:"8px",background:e.bg,border:i?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:i?`0 8px 24px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 8px 24px ${e.shadow}`,overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:`1px solid ${e.borderSubtle}`},title:{fontSize:"10px",fontWeight:600,color:e.text,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:e.textMuted,display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:e.gripColor,display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:`1px solid ${e.borderSubtle}`},badge:n=>{let i=Nt[n]||Nt.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:i.bg,color:i.text,border:`1px solid ${i.border}`,lineHeight:"14px"}},progress:{height:"2px",background:e.borderSubtle,flexShrink:0},progressBar:n=>({height:"100%",width:`${n}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:n=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${n}15`,color:n,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${e.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(n,i)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:n?`${i}33`:"transparent",color:n?i:e.gripColor,transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:e.inputBg,border:`1px solid ${e.inputBorder}`,borderRadius:"4px",padding:"2px 6px",color:e.text,outline:"none"},humanBanner:{padding:"6px 12px",fontSize:"11px",fontWeight:600,color:e.green,borderBottom:`1px solid ${e.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",background:e.greenBg,cursor:"pointer",textDecoration:"none"}});function it(e){return e.split("/")[0].trim()}async function hn(e){try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}try{if(typeof document>"u")return !1;let n=document.createElement("textarea");n.value=e,n.setAttribute("readonly",""),n.style.position="fixed",n.style.top="0",n.style.left="0",n.style.opacity="0",n.style.pointerEvents="none",document.body.appendChild(n),n.focus(),n.select(),n.setSelectionRange(0,e.length);let i=document.execCommand("copy");return document.body.removeChild(n),i}catch{return false}}function Le({config:e,appSlug:n,environment:i,seededUsers:d,authToken:a,tk:s,compact:_=false,onExpand:k,onAuthExpired:y,refreshAuth:p,requestLogin:h,testRunId:T,testRunToken:V,ticketId:M,targetUrl:v,version:x,commitSha:r,prNumber:u,branchName:J}){let[U,q]=useState(false),[Y,I]=useState(null),[$,Me]=useState(null),[se,f]=useState(null),[Ne,ae]=useState(null),[ne,X]=useState(null),[Z,le]=useState(null);useEffect(()=>{i==="local"&&Fe();},[i]);let ye=useCallback(c=>{I(c),f(null),ae(null),le(null);let L=Ee(a);if(i!=="local"&&h&&L!==null&&L<=Date.now()){X({slug:c,token:a||null}),le(c),I(null),h();return}let P=C=>{f(C),ae(c),window.setTimeout(()=>{ae(E=>E===c?null:E),f(E=>E===C?null:E);},3e3);},R=new URLSearchParams({app_slug:n,seed_user_slug:c,environment:i});T&&R.set("test_run_id",T),V&&R.set("public_token",V),M&&R.set("ticket_id",M),v&&R.set("target_url",v),x&&R.set("version",x),r&&R.set("commit_sha",r),u&&R.set("pr_number",String(u)),J&&R.set("branch_name",J);let N=async C=>{let E={apikey:e.anonKey,Authorization:`Bearer ${C}`};try{let z=await fetch(`${e.serverUrl}/widget/totp-code?${R}`,{headers:E});if(!z.ok){let fe=await z.json().catch(()=>({error:`HTTP ${z.status}`}));return {ok:!1,status:z.status,error:fe.error||`HTTP ${z.status}`}}let G=await z.json();return {ok:!0,code:String(G.code)}}catch{return {ok:false,status:0,error:"Network error"}}},D=(async()=>{if(i==="local"){let z=await Pt(c);if(z)try{return {ok:!0,code:await Et(z)}}catch{}}let C=await N(a||e.anonKey);if(C.ok||C.status!==401||!p)return C;let E=await p();return E?N(E):{ok:false,status:401,error:"Sign in to BotBuddy to refresh 2FA"}})(),A=null;try{if(typeof ClipboardItem<"u"&&navigator.clipboard?.write){let C=D.then(E=>{if(!E.ok)throw new Error(E.error);return new Blob([E.code],{type:"text/plain"})});A=navigator.clipboard.write([new ClipboardItem({"text/plain":C})]).then(()=>!0).catch(()=>!1);}}catch{}(async()=>{let C=await D;if(!C.ok){C.status===401?(X({slug:c,token:a||null}),le(c)):P(C.status===404?"No 2FA seed registered":C.error),I(null);return}let E=A?await A:false,z=E?true:await hn(C.code),G=E||z;Me({slug:c,code:C.code,copied:G}),window.setTimeout(()=>Me(fe=>fe?.slug===c?null:fe),G?2500:6e3),q(false),I(null);})();},[e.serverUrl,e.anonKey,a,n,i,T,V,M,v,x,r,u,J,p,h]),oe=useCallback(c=>{X({slug:c,token:a||null}),h?.();},[a,h]),he=useCallback(c=>{Z===c?oe(c):ye(c);},[Z,oe,ye]);useEffect(()=>{if(!ne||!a||a===ne.token)return;let c=ne.slug;X(null),ye(c);},[a,ye,ne]);let xe=useRef(null),Ce=useRef(null);if(useLayoutEffect(()=>{if(!U)return;let c=xe.current,L=Ce.current;if(!c||!L||typeof window>"u")return;let P=()=>{let R=c.getBoundingClientRect(),N=L.getBoundingClientRect(),D=window.innerWidth,A=window.innerHeight,C=R.left,E=R.top-N.height-6;E<8&&(E=R.bottom+6);let z=Math.max(8,D-N.width-8),G=Math.max(8,A-N.height-8);C=Math.min(Math.max(C,8),z),E=Math.min(Math.max(E,8),G),L.style.left=`${Math.round(C)}px`,L.style.top=`${Math.round(E)}px`;};return P(),window.addEventListener("scroll",P,true),window.addEventListener("resize",P),()=>{window.removeEventListener("scroll",P,true),window.removeEventListener("resize",P);}},[U,d.length,se]),useEffect(()=>{if(!U)return;let c=L=>{let P=L.target;Ce.current?.contains(P)||xe.current?.contains(P)||q(false);};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[U]),d.length===0)return null;if(_){let c=d.length>1,L=d[0],P=!c&&Z===L,R=z=>{if(z.stopPropagation(),c&&k){k();return}he(L);},N=!!Ne,D=!!$,A=D&&$.copied,C=D&&!$.copied,E=P?s.blue:N?s.red:A?s.green:C?s.amber:s.purple;return jsxs("span",{onPointerDown:z=>z.stopPropagation(),onPointerUp:z=>z.stopPropagation(),onPointerMove:z=>z.stopPropagation(),onClick:R,style:{display:"inline-flex",alignItems:"center",gap:"3px",color:E,fontWeight:600,cursor:"pointer",letterSpacing:C?"0.08em":void 0},title:P?"Sign in to BotBuddy to refresh 2FA":N?se||"Failed":C?`Clipboard blocked \u2014 code: ${$.code}`:c?`${d.length} 2FA personas`:`Copy 2FA code for ${d[0]}`,children:[jsx(S,{d:P?m.key:N?m.alert:A?m.check:C?m.copy:m.shield,size:10}),P?jsx(Fragment,{children:"Sign in"}):A?jsx(Fragment,{children:"Copied"}):C?jsx(Fragment,{children:$.code}):N?jsx(Fragment,{children:"Failed"}):jsxs(Fragment,{children:["2FA",c&&` \xB7${d.length}`]})]})}if(d.length===1){let c=d[0],L=Y===c,P=$?.slug===c,R=P&&$.copied,N=P&&!$.copied,D=Ne===c,A=Z===c,C=A?s.blue:D?s.red:R?s.green:N?s.amber:s.purple;return jsxs("button",{onClick:E=>{E.stopPropagation(),he(c);},disabled:L,style:{...Bt(C),cursor:L?"wait":"pointer",opacity:L?.6:1},title:A?"Sign in to BotBuddy to refresh 2FA":D?se||"Failed":N?`Clipboard blocked \u2014 code: ${$.code}`:`Copy 2FA code for ${c}`,children:[jsx(S,{d:A?m.key:D?m.alert:R?m.check:N?m.copy:m.shield,size:12}),A?"Sign in":R?"Copied":N?$.code:D?"Failed":L?"\u2026":`2FA \xB7 ${c}`]})}let de=!!Z&&!U,Q=!!Ne&&!U,ve=!!$&&$.copied,we=!!$&&!$.copied,Oe=de?s.blue:Q?s.red:ve?s.green:we?s.amber:s.purple,He=U&&typeof document<"u"?createPortal(jsxs("div",{ref:Ce,onPointerDown:c=>c.stopPropagation(),onMouseDown:c=>c.stopPropagation(),style:{position:"fixed",left:-9999,top:-9999,background:s.bg,border:`1px solid ${s.border}`,borderRadius:6,boxShadow:`0 8px 24px ${s.shadow}`,padding:4,minWidth:220,maxWidth:typeof window<"u"?Math.min(420,window.innerWidth-16):420,zIndex:1e5,fontFamily:"ui-monospace, SFMono-Regular, monospace"},children:[d.map(c=>{let L=Y===c,P=Z===c;return jsxs("button",{onClick:R=>{R.stopPropagation(),he(c);},disabled:L,style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 8px",background:"transparent",border:"none",borderRadius:4,cursor:L?"wait":"pointer",fontSize:"10px",color:P?s.blue:s.text,textAlign:"left",fontFamily:"ui-monospace, SFMono-Regular, monospace"},title:P?"Sign in to BotBuddy to refresh 2FA":void 0,onMouseEnter:R=>R.currentTarget.style.background=s.btnHover,onMouseLeave:R=>R.currentTarget.style.background="transparent",children:[jsx(S,{d:P?m.key:m.shield,size:10}),jsx("span",{style:{flex:1,overflowWrap:"anywhere",lineHeight:1.3},children:c}),P?jsx("span",{style:{color:s.blue,fontSize:9},children:"Sign in"}):L?jsx("span",{style:{color:s.textMuted,fontSize:9},children:"\u2026"}):null]},c)}),se&&jsx("div",{style:{padding:"4px 8px",fontSize:9,color:s.red},children:se})]}),document.body):null;return jsxs(Fragment,{children:[jsxs("button",{ref:xe,onClick:c=>{if(c.stopPropagation(),de&&Z){oe(Z);return}q(L=>!L),f(null),ae(null);},style:{...Bt(Oe),cursor:"pointer"},title:de?"Sign in to BotBuddy to refresh 2FA":Q?se||"Failed":we?`Clipboard blocked \u2014 code: ${$.code}`:"Choose a persona to copy a 2FA code for",children:[jsx(S,{d:de?m.key:Q?m.alert:ve?m.check:we?m.copy:m.shield,size:12}),de?"Sign in":ve?"Copied":we?$.code:Q?"Failed":`2FA \xB7 ${d.length}`,!de&&jsx(S,{d:U?m.chevronUp:m.chevronDown,size:8})]}),He]})}function Bt(e){return {display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${e}15`,color:e,textDecoration:"none",border:`1px solid ${e}30`}}var zt="botbuddy-widget-state";function xn({config:e,appSlug:n,environment:i,ticketId:d,testRunId:a,testRunToken:s,targetUrl:_,version:k,commitSha:y,prNumber:p,branchName:h,onNavigate:T,displayName:V="human",defaultMode:M="mini",defaultPosition:v}){let x=un(),r=useMemo(()=>pn(x),[x]),u=useMemo(()=>yn(r),[r]),[J,U]=useState(false),[q,Y]=useState(false),[I,$]=useState(false),Me=useRef(false),se=e.dashboardUrl||"https://app.bot-buddy.ai",f=ot(se),ae=(()=>{try{let t=typeof window<"u"?localStorage.getItem(zt):null;if(t)return JSON.parse(t)}catch{}return null})(),[ne,X]=useState(ae?.mode||M),[Z,le]=useState(""),[ye,oe]=useState(null),[he,xe]=useState(null),[Ce,de]=useState(new Set),[Q,ve]=useState(""),we=useCallback(t=>{de(g=>{let w=new Set(g);return w.has(t)?w.delete(t):w.add(t),w});},[]),Oe=ae?.x??v?.x??16,He=ae?.y??v?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:c,setPos:L,onPointerDown:P,onPointerMove:R,onPointerUp:N,didDrag:D}=Ge(Oe,He),A=useRef(null);useEffect(()=>{try{localStorage.setItem(zt,JSON.stringify({mode:ne,x:c.x,y:c.y}));}catch{}},[ne,c.x,c.y]),useLayoutEffect(()=>{if(typeof window>"u")return;let t=A.current;if(!t)return;let g=t.getBoundingClientRect(),w=qe(c.x,c.y,g.width,g.height,window.innerWidth,window.innerHeight);(w.x!==c.x||w.y!==c.y)&&L(w);}),useEffect(()=>{if(typeof window>"u")return;let t=()=>{let g=A.current;if(!g)return;let w=g.getBoundingClientRect(),W=qe(c.x,c.y,w.width,w.height,window.innerWidth,window.innerHeight);(W.x!==c.x||W.y!==c.y)&&L(W);};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[c.x,c.y,L]);let C=useRef(f.isAuthenticated);useEffect(()=>{!C.current&&f.isAuthenticated&&X("max"),C.current=f.isAuthenticated;},[f.isAuthenticated]);let E="botbuddy-widget-max-size",z=()=>{try{let t=localStorage.getItem(E);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[G,fe]=useState(z),Te=useRef(false),Pe=useRef({x:0,y:0,w:0,h:0}),It=useCallback(t=>{t.stopPropagation(),Te.current=true,Pe.current={x:t.clientX,y:t.clientY,w:G.w,h:G.h},t.target.setPointerCapture(t.pointerId);},[G]),Ft=useCallback(t=>{if(!Te.current)return;let g=Math.max(280,Math.min(600,Pe.current.w+(t.clientX-Pe.current.x))),w=Math.max(300,Math.min(window.innerHeight*.9,Pe.current.h+(t.clientY-Pe.current.y)));fe({w:g,h:w});},[]),Dt=useCallback(()=>{Te.current&&(Te.current=false,fe(t=>(localStorage.setItem(E,JSON.stringify(t)),t)));},[]),ee=_??(typeof window<"u"?window.location.href:void 0),at=f.displayName||V,[ie,lt]=useState(null);useEffect(()=>{if(f.isAuthenticated)return;let t=new URLSearchParams;s&&t.set("token",s),d&&t.set("ticket_id",d),t.set("app_slug",n),i&&t.set("environment",i),a&&t.set("test_run_id",a),ee&&t.set("target_url",ee),k&&t.set("version",k),y&&t.set("commit_sha",y),p&&t.set("pr_number",String(p)),h&&t.set("branch_name",h),fetch(`${e.serverUrl}/widget/preview?${t}`,{headers:{apikey:e.anonKey}}).then(g=>g.json()).then(g=>lt(g)).catch(()=>lt(null));},[f.isAuthenticated,e.serverUrl,e.anonKey,n,i,d,a,s,ee,k,y,p,h]);let dt=useRef(false),Ot=useCallback(()=>{dt.current||f.logout();},[f.logout]),{run:b,widgetState:be,fetchRun:Ht,setVerdict:ct,markComplete:Kt,resetRun:jt,setRun:ut}=Qe({config:e,appSlug:n,environment:i,ticketId:d,testRunId:a,testRunToken:s,targetUrl:ee,version:k,commitSha:y,prNumber:p?String(p):void 0,branchName:h,authToken:f.token,onAuthExpired:Ot});dt.current=!!b;let[pt,gt]=useState([]),[ft,Be]=useState([]),[Ke,bt]=useState(false),[mt,yt]=useState(null),[Vt,ze]=useState(false),ce=mn(typeof window<"u"?window.location.hostname:void 0,e.productionHostnames||[]);useEffect(()=>{if((i??"local")!=="local"||ce){gt([]);return}let t=true;return Fe().then(g=>{t&>(Object.keys(g||{}));}),()=>{t=false;}},[i,ce]);let Yt=useCallback(async()=>{if(!(!f.isAuthenticated||!f.token)){bt(true),yt(null);try{let t=await fetch(`${e.serverUrl}/widget/test-runs`,{method:"POST",headers:{"Content-Type":"application/json",apikey:e.anonKey,Authorization:`Bearer ${f.token}`},body:JSON.stringify({app_slug:n,environment:i||"local",target_url:ee,branch_name:h,commit_sha:y,pr_number:p,ticket_id:d,title:`${d||n} local validation`})}),g=await t.json().catch(()=>({}));if(!t.ok)throw new Error(g.error||`HTTP ${t.status}`);ut(g),X("max");}catch(t){yt(t.message);}finally{bt(false);}}},[f.isAuthenticated,f.token,e.serverUrl,e.anonKey,n,i,ee,h,y,p,d,ut]),$e=useCallback(async(t,g,w)=>{xe(t);try{await ct(t,g,w,at);}finally{xe(null),oe(null),le("");}},[ct,at]),F=b?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},Jt=F.total>0&&F.pending===0,ke=be==="completed",Ae=useMemo(()=>{let t=b?.test_cases||[];if(!Q.trim())return t;let g=Q.toLowerCase();return t.filter(w=>w.title.toLowerCase().includes(g)||w.description&&w.description.toLowerCase().includes(g)||w.url_path&&w.url_path.toLowerCase().includes(g)||w.seed_user&&w.seed_user.toLowerCase().includes(g))},[b?.test_cases,Q]),ht=useMemo(()=>{let t=Ae,g=b?.test_cases||[];if(new Set(g.map(j=>j.source_pr_number)).size<=1)return null;let W=[],pe=new Map;t.forEach(j=>{let H=j.source_pr_number;pe.has(H)||pe.set(H,[]),pe.get(H).push(j);});let Mt=[...pe.keys()].sort((j,H)=>j===null?1:H===null?-1:H-j);for(let j of Mt){let H=pe.get(j),Ve={total:H.length,pass:0,fail:0,skip:0,pending:0};H.forEach(Ct=>{Ct.verdict in Ve&&Ve[Ct.verdict]++;}),W.push({key:j!=null?`pr-${j}`:"general",label:j!=null?`PR #${j}`:"General",cases:H,summary:Ve});}return W.filter(j=>j.cases.length>0)},[Ae,b?.test_cases]),xt=F.total>0?(F.pass+F.fail)/F.total*100:0,O=i??b?.environment??null,ue=useMemo(()=>{if(!O||O==="production"||ce)return [];let t=b?.test_cases||[],g=new Set;for(let w of t)w.seed_user&&g.add(it(w.seed_user));if(O==="local")for(let w of pt)g.add(it(w));for(let w of ft)g.add(it(w));return [...g]},[b?.test_cases,O,pt,ft,ce]);useEffect(()=>{if(!O||O==="production"||ce||!f.isAuthenticated||!f.token){Be([]);return}let t=true,g=`${e.serverUrl}/widget/totp-seeds?${new URLSearchParams({app_slug:n,environment:O})}`,w=W=>fetch(g,{headers:{apikey:e.anonKey,Authorization:`Bearer ${W}`}});return (async()=>{try{let W=await w(f.token);if(W.status===401&&f.refreshNow){let H=await f.refreshNow();H&&(W=await w(H));}if(!t)return;if(!W.ok){Be([]);return}let pe=await W.json().catch(()=>null),j=(Array.isArray(pe?.seeds)?pe.seeds:[]).map(H=>H?.seed_user_slug).filter(H=>typeof H=="string"&&H.length>0);Be(j);}catch{t&&Be([]);}})(),()=>{t=false;}},[O,ce,f.isAuthenticated,f.token,f.refreshNow,n,e.serverUrl,e.anonKey]);let je=useMemo(()=>{let t=b?.auto_tooltip_seconds??ie?.auto_tooltip_seconds;return t!=null&&t>0?t*1e3:0},[b,ie]),vt=be==="ready"||be==="completed"||ie?.enabled&&ie.run;useEffect(()=>{if(!vt||Me.current||je<=0)return;Me.current=true,Y(true);let t=window.setTimeout(()=>Y(false),je);return ()=>window.clearTimeout(t)},[vt,je]);let wt=t=>jsxs("div",{style:u.caseRow,children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsx("div",{style:{marginTop:"2px",flexShrink:0,color:gn[t.verdict]},children:he===t.id?jsx(S,{d:m.loader,className:""}):jsx(S,{d:fn[t.verdict],className:""})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"10px",color:r.text,lineHeight:1.3},children:t.title}),t.description&&jsx("div",{style:{fontSize:"9px",color:r.gripColor,marginTop:"2px"},children:t.description}),t.seed_user&&jsxs("div",{style:{fontSize:"9px",color:r.amber,marginTop:"3px",display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",background:`${r.amber}12`,border:`1px solid ${r.amber}30`},children:[jsx(S,{d:m.key,size:10}),jsx("span",{children:t.seed_user})]}),t.url_path&&jsxs("a",{href:t.url_path,target:"_blank",rel:"noopener noreferrer",onClick:g=>{g.stopPropagation(),T&&(g.preventDefault(),T(t.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsx(S,{d:m.externalLink,size:10}),t.url_path]}),t.verdict==="fail"&&t.fail_reason&&jsxs("div",{style:{fontSize:"9px",color:r.red,marginTop:"2px"},children:["\u2717 ",t.fail_reason]})]})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(g=>jsx("button",{onClick:()=>{if(t.verdict===g){$e(t.id,"pending"),oe(null);return}if(g==="fail"){oe(t.id),le("");return}oe(null),$e(t.id,g);},disabled:he!==null,style:u.verdictBtn(t.verdict===g,g==="pass"?r.green:g==="fail"?r.red:r.amber),children:g.toUpperCase()},g)),t.created_by_agent_name&&jsxs("span",{style:{fontSize:"8px",color:r.purple,marginLeft:"4px",display:"inline-flex",alignItems:"center",gap:"2px"},children:[jsx(S,{d:m.bot,size:8}),t.created_by_agent_name]}),t.verdict_by_display_name&&jsxs("span",{style:{fontSize:"8px",color:r.textFaint,marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:"3px"},children:[t.verdict_by_display_name,t.verdict_at&&jsx("span",{style:{opacity:.7},children:cn(t.verdict_at)})]})]}),ye===t.id&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:Z,onChange:g=>le(g.target.value),onKeyDown:g=>{g.key==="Enter"&&$e(t.id,"fail",Z.trim()||void 0),g.key==="Escape"&&(oe(null),le(""));},placeholder:"Reason (optional)...",style:u.input}),jsx("button",{onClick:()=>{$e(t.id,"fail",Z.trim()||void 0);},style:u.verdictBtn(true,r.red),children:"\u2713"})]})]},t.id);if((be==="no-match"||be==="loading")&&!(!f.isAuthenticated&&ie?.enabled&&ie.run)){if(!(O==="local"&&!ce))return null}if(!f.isAuthenticated&&ie?.enabled&&ie.run){let t=ie.run,g=t.summary,w=t.status==="completed";return jsx("div",{ref:A,style:{...u.root,left:c.x,top:c.y},children:jsxs("div",{style:{position:"relative"},onMouseEnter:()=>U(true),onMouseLeave:()=>{U(false),$(false),Y(false);},children:[jsxs("div",{style:{...u.pill(w),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:P,onPointerMove:R,onPointerUp:()=>{N();},children:[jsx(S,{d:m.grip,size:10,className:""}),t.ticket_id&&t.ticket_url?jsx("a",{href:t.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:r.amber,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:t.ticket_id}):null,t.pr_url?jsxs("a",{href:t.pr_url,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:r.blue,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:["PR#",t.pr_number??t.pr_id]}):null,t.created_by_agent_name?t.codex_thread_id?jsxs("a",{href:`codex://threads/${t.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:r.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(S,{d:m.terminal,size:10}),t.created_by_agent_name]}):jsxs("span",{style:{color:r.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(S,{d:m.bot,size:10}),t.created_by_agent_name]}):null,jsxs("span",{style:w?{color:r.green}:void 0,children:[g.pass,"/",g.total]}),g.fail>0&&jsxs("span",{style:{color:r.red},children:[g.fail,"\u2717"]}),jsx("span",{onClick:W=>{W.stopPropagation(),f.openLogin();},style:{color:r.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!I&&(J||q)&&t.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsx("div",{style:{fontSize:"11px",fontWeight:700,color:r.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:t.title}),(t.description||t.intro_notes)&&jsx("div",{style:{fontSize:"10px",color:r.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:t.description||t.intro_notes}),jsx("div",{style:{marginTop:"4px",fontSize:"9px",color:r.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!f.isAuthenticated)return jsxs("div",{ref:A,style:{...u.root,left:c.x,top:c.y,width:220,minHeight:0,cursor:"move",userSelect:"none",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`},onPointerDown:P,onPointerMove:R,onPointerUp:N,children:[jsx("div",{style:{...u.handle,borderBottom:"none"},children:jsxs("div",{style:u.sub,children:[jsx(S,{d:m.grip,size:10,className:""}),jsx(S,{d:m.clipboard,size:12,className:""}),jsx("span",{style:{fontWeight:600},children:"BotBuddy"})]})}),jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[jsx("div",{style:{fontSize:"9px",color:r.textMuted,marginBottom:"8px"},children:"Sign in to access test cases"}),O==="local"&&ue.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx(Le,{config:e,appSlug:n,environment:O,seededUsers:ue,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:r,testRunId:b?.id||a,testRunToken:s,ticketId:d,targetUrl:ee,version:k,commitSha:y,prNumber:p,branchName:h,onAuthExpired:f.logout})}),jsx("button",{onClick:t=>{t.stopPropagation(),f.openLogin();},style:{fontSize:"10px",fontWeight:600,padding:"6px 16px",borderRadius:"6px",border:`1px solid ${r.green}`,background:`${r.green}22`,color:r.green,cursor:"pointer",width:"100%"},children:"Sign in to test"})]})]});if(!b&&O==="local"&&!ce)return Vt?jsx("div",{ref:A,style:{...u.root,left:c.x,top:c.y},children:jsxs("div",{style:u.card(240,false),children:[jsxs("div",{style:u.handle,onPointerDown:P,onPointerMove:R,onPointerUp:N,onClick:()=>{D.current||ze(false);},children:[jsx(S,{d:m.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:u.title,children:"BotBuddy"}),h&&jsx("div",{style:u.sub,children:jsxs("span",{children:["\u2387 ",h]})})]}),jsx(S,{d:m.chevronUp,className:""}),jsx("button",{style:u.btn,onClick:t=>{t.stopPropagation(),ze(false);},children:jsx(S,{d:m.minus,className:""})})]}),jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[ue.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx(Le,{config:e,appSlug:n,environment:O,seededUsers:ue,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:r,testRunId:a,testRunToken:s,ticketId:d,targetUrl:ee,version:k,commitSha:y,prNumber:p,branchName:h,onAuthExpired:f.logout})}),jsx("button",{onClick:t=>{t.stopPropagation(),Yt();},disabled:Ke,style:{fontSize:"10px",fontWeight:600,padding:"6px 12px",borderRadius:"6px",border:`1px solid ${r.green}`,background:`${r.green}22`,color:r.green,cursor:Ke?"wait":"pointer",width:"100%"},children:Ke?"Creating...":"Create test run for this branch"}),mt&&jsx("div",{style:{fontSize:"9px",color:r.red,marginTop:"8px"},children:mt})]})]})}):jsx("div",{ref:A,style:{...u.root,left:c.x,top:c.y},children:jsxs("div",{style:{...u.pill(false),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:P,onPointerMove:R,onPointerUp:()=>{N(),D.current||ze(true);},children:[jsx(S,{d:m.grip,size:9,className:""}),jsx("span",{style:{fontWeight:600},children:"BotBuddy"}),ue.length>0&&jsx(Le,{config:e,appSlug:n,environment:O,seededUsers:ue,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:r,compact:true,onExpand:()=>ze(true),testRunId:a,testRunToken:s,ticketId:d,targetUrl:ee,version:k,commitSha:y,prNumber:p,branchName:h,onAuthExpired:f.logout})]})});let kt=()=>{D.current||(Y(false),X(t=>{let g=t==="mini"?"max":"mini";return $(g==="mini"),g}));},St=({icon:t,onClick:g})=>jsx("button",{style:u.btn,onClick:w=>{w.stopPropagation(),g(w);},children:jsx(S,{d:t,className:""})}),_t=()=>jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${r.borderSubtle}`,flexShrink:0},children:[b?.pr_url&&jsxs("a",{href:b.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...u.link(r.blue),textDecoration:"none"},children:[jsx(S,{d:m.pr,size:12}),b.pr_number?`PR#${b.pr_number}`:b.pr_id||"PR",jsx(S,{d:m.externalLink,size:8})]}),b?.ticket_url&&jsxs("a",{href:b.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...u.link(r.amber),textDecoration:"none"},children:[jsx(S,{d:m.ticket,size:12}),b.ticket_id||"Ticket",jsx(S,{d:m.externalLink,size:8})]}),b?.created_by_agent_name&&(b.codex_thread_id?jsxs("a",{href:`codex://threads/${b.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:{...u.link(r.purple),textDecoration:"none"},children:[jsx(S,{d:m.bot,size:12}),b.created_by_agent_name,jsx(S,{d:m.externalLink,size:8})]}):jsxs("span",{style:{...u.link(r.purple)},children:[jsx(S,{d:m.bot,size:12}),b.created_by_agent_name]})),O&&jsx(Le,{config:e,appSlug:n,environment:O,seededUsers:ue,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:r,testRunId:b?.id||a,testRunToken:s,ticketId:d,targetUrl:ee,version:k,commitSha:y,prNumber:p,branchName:h,onAuthExpired:f.logout}),jsx("span",{style:{...u.badge(b?.environment||"custom"),marginLeft:"auto"},children:b?.environment})]}),Rt=()=>jsxs("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:`1px solid ${r.borderSubtle}`,background:r.bgSoft,flexShrink:0},children:[jsxs("button",{onClick:()=>{navigator.clipboard.writeText(Lt);},style:{fontSize:"9px",fontWeight:600,color:r.versionText,letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsxs("span",{style:{color:r.versionNum},children:["v",Lt]})]}),f.isAuthenticated&&(f.isExpired?jsx("button",{onClick:t=>{t.stopPropagation(),f.openLogin();},style:{fontSize:"8px",color:r.blue,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Widget session expired \u2014 sign in to refresh",children:"sign in"}):jsx("button",{onClick:t=>{t.stopPropagation(),f.logout();},style:{fontSize:"8px",color:r.textFaint,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Sign out of widget",children:"sign out"}))]});return jsxs("div",{ref:A,style:{...u.root,left:c.x,top:c.y},children:[ne==="mini"&&jsxs("div",{style:{position:"relative"},onMouseEnter:()=>U(true),onMouseLeave:()=>{U(false),$(false),Y(false);},children:[jsxs("div",{style:{...u.pill(ke),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:P,onPointerMove:R,onPointerUp:()=>{N(),D.current||kt();},children:[jsx(S,{d:m.grip,size:9,className:""}),b?.ticket_id&&jsx("span",{style:{color:r.amber,fontWeight:600},children:b.ticket_id}),b?.pr_number&&jsxs("span",{style:{color:r.blue,fontWeight:600},children:["PR#",b.pr_number]}),jsxs("span",{style:ke?{color:r.green}:void 0,children:[F.pass,"/",F.total]}),F.fail>0&&jsxs("span",{style:{color:r.red},children:[F.fail,"\u2717"]}),O&&jsx(Le,{config:e,appSlug:n,environment:O,seededUsers:ue,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:r,compact:true,onExpand:()=>X("expanded"),testRunId:b?.id||a,testRunToken:s,ticketId:d,targetUrl:ee,version:k,commitSha:y,prNumber:p,branchName:h,onAuthExpired:f.logout})]}),!I&&(J||q)&&b?.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsx("div",{style:{fontSize:"11px",fontWeight:700,color:r.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:b.title}),(b.description||b.intro_notes)&&jsx("div",{style:{fontSize:"10px",color:r.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:b.description||b.intro_notes})]})]}),ne==="expanded"&&jsxs("div",{style:u.card(300,ke),children:[jsxs("div",{style:u.handle,onPointerDown:P,onPointerMove:R,onPointerUp:N,onClick:kt,children:[jsx(S,{d:m.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:u.title,children:b?.title}),jsx("div",{style:u.sub,children:b?.branch_name&&jsxs("span",{children:["\u2387 ",b.branch_name]})})]}),jsx(S,{d:m.chevronUp,className:""}),jsx(St,{icon:m.minus,onClick:()=>{Y(false),$(true),X("mini");}})]}),jsxs("div",{style:u.stats,children:[jsxs("span",{style:{color:r.green},children:[F.pass,"\u2713"]}),jsxs("span",{style:{color:r.red},children:[F.fail,"\u2717"]}),jsxs("span",{style:{color:r.amber},children:[F.skip,"\u23ED"]}),jsxs("span",{style:{color:r.gripColor},children:[F.pending,"\u25CC"]}),jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:F.total})]}),b?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:r.gripColor,borderBottom:`1px solid ${r.borderSubtle}`,flexShrink:0},children:b.description}),_t(),Rt(),jsx("div",{style:u.progress,children:jsx("div",{style:u.progressBar(xt)})})]}),ne==="max"&&jsxs("div",{style:{...u.card(G.w,ke),height:G.h,position:"relative"},children:[jsxs("div",{style:u.handle,onPointerDown:P,onPointerMove:R,onPointerUp:N,onClick:()=>{D.current||X("expanded");},children:[jsx(S,{d:m.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:u.title,children:b?.title}),jsx("div",{style:u.sub,children:b?.branch_name&&jsxs("span",{children:["\u2387 ",b.branch_name]})})]}),jsx(S,{d:m.chevronDown,className:""}),jsx(St,{icon:m.minus,onClick:()=>{Y(false),$(true),X("mini");}})]}),jsxs("div",{style:u.stats,children:[jsxs("span",{style:{color:r.green},children:[F.pass,"\u2713"]}),jsxs("span",{style:{color:r.red},children:[F.fail,"\u2717"]}),jsxs("span",{style:{color:r.amber},children:[F.skip,"\u23ED"]}),jsxs("span",{style:{color:r.gripColor},children:[F.pending,"\u25CC"]}),jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:F.total})]}),b?.intro_notes&&jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${r.borderSubtle}`,fontSize:"10px",color:r.textMuted,fontStyle:"italic",flexShrink:0},children:b.intro_notes}),(b?.test_cases||[]).length>5&&jsxs("div",{style:{padding:"4px 12px",borderBottom:`1px solid ${r.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[jsx(S,{d:m.search,size:11,className:""}),jsx("input",{value:Q,onChange:t=>ve(t.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:r.text,fontFamily:"monospace"}}),Q&&jsx("button",{onClick:()=>ve(""),style:{background:"none",border:"none",cursor:"pointer",color:r.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),be==="error"&&jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsx(S,{d:m.alert,className:""}),jsx("div",{style:{fontSize:"10px",color:r.red},children:"Failed to load"}),jsx("button",{onClick:Ht,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),ke&&jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg},children:[jsx(S,{d:m.checkAll,className:""}),jsx("span",{style:{fontSize:"10px",color:r.green,flex:1},children:"Run completed"}),jsx("button",{onClick:jt,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),be!=="error"&&jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(b?.test_cases||[]).length===0?jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:r.gripColor},children:"No test cases"}):Ae.length===0?jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:r.gripColor},children:['No matches for "',Q,'"']}):ht?ht.map(t=>{let g=Ce.has(t.key);return jsxs("div",{children:[jsxs("button",{onClick:()=>we(t.key),style:{width:"100%",display:"flex",alignItems:"center",gap:"6px",padding:"5px 12px",background:r.bgSoft,cursor:"pointer",border:"none",borderLeft:"none",borderRight:"none",borderBottomStyle:"solid",borderTopStyle:"solid",borderBottomWidth:"1px",borderTopWidth:"1px",borderBottomColor:r.borderSubtle,borderTopColor:r.borderSubtle,backgroundColor:r.bgSoft},children:[jsx(S,{d:g?m.chevronDown:m.chevronUp,size:10,className:""}),jsx("span",{style:{fontSize:"10px",fontWeight:700,color:r.blue,flex:1,textAlign:"left"},children:t.label}),jsxs("span",{style:{fontSize:"9px",color:r.green},children:[t.summary.pass,"\u2713"]}),jsxs("span",{style:{fontSize:"9px",color:r.red},children:[t.summary.fail,"\u2717"]}),jsxs("span",{style:{fontSize:"9px",color:r.gripColor},children:[t.summary.pending,"\u25CC"]}),jsx("span",{style:{fontSize:"9px",color:r.textFaint},children:t.summary.total})]}),!g&&t.cases.map(w=>wt(w))]},t.key)}):Ae.map(t=>wt(t))}),Jt&&!ke&&jsxs("div",{style:{padding:"6px 12px",borderTop:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg,display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsx("span",{style:{fontSize:"9px",color:r.green},children:"All resolved"}),jsx("button",{onClick:Kt,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:r.green,border:`1px solid ${r.greenBorderSubtle}`,cursor:"pointer"},children:"COMPLETE"})]}),_t(),Rt(),jsx("div",{style:u.progress,children:jsx("div",{style:u.progressBar(xt)})}),jsx("div",{style:{position:"absolute",bottom:0,right:0,width:16,height:16,cursor:"se-resize",zIndex:10,display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:"2px",opacity:.3},onPointerDown:It,onPointerMove:Ft,onPointerUp:Dt,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{Te.current||(t.currentTarget.style.opacity="0.3");},children:jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsx("path",{d:"M7 1v6H1",fill:"none",stroke:r.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}function Sn(e){let n=e;return !!n&&typeof n=="object"&&typeof n.tenant=="string"&&Array.isArray(n.entries)&&n.entries.every(i=>!!i&&typeof i.id=="string"&&typeof i.title=="string"&&!!i.body&&Array.isArray(i.body.ast)&&Array.isArray(i.links))}function st({endpoint:e,getToken:n}){let[i,d]=useState({feed:null,error:null,loading:true}),[a,s]=useState(0),_=useRef(n);_.current=n,useEffect(()=>{let y=true;return d(p=>({...p,error:null,loading:true})),(async()=>{try{let p=await _.current(),h=await fetch(e,{headers:{authorization:`Bearer ${p}`}}),T=null;try{T=await h.json();}catch{T=null;}if(!y)return;if(h.ok)Sn(T)?d({feed:T,error:null,loading:!1}):d({feed:null,error:"invalid_feed",loading:!1});else {let V=T?.error;d({feed:null,error:typeof V=="string"?V:`http_${h.status}`,loading:!1});}}catch(p){y&&d({feed:null,error:p instanceof Error&&p.message||"unavailable",loading:false});}})(),()=>{y=false;}},[e,a]);let k=useCallback(()=>s(y=>y+1),[]);return {...i,reload:k}}function Ut(e){if(typeof e!="string"||/[\s\\]/.test(e))return null;if(e.startsWith("/"))return e.startsWith("//")?null:{kind:"internal",href:e};try{return new URL(e).protocol==="https:"?{kind:"external",href:e}:null}catch{return null}}function De(e,n=""){return e.map((i,d)=>{let a=`${n}${d}`;switch(i.t){case "text":return i.v;case "code":return jsx("code",{className:"bbrn-code",children:i.v},a);case "strong":return jsx("strong",{children:De(i.c,`${a}.`)},a);case "em":return jsx("em",{children:De(i.c,`${a}.`)},a);default:return null}})}function Wt({ast:e}){return jsx(Fragment,{children:e.map((n,i)=>n.t==="list"?jsx("ul",{className:"bbrn-list",children:n.items.map((d,a)=>jsx("li",{children:De(d)},a))},i):n.t==="p"?jsx("p",{className:"bbrn-p",children:De(n.c)},i):null)})}var _n=`@layer bbrn {
|
|
2
|
-
.bbrn-root{display:grid;gap:12px;color
|
|
3
|
-
.bbrn-root .bbrn-entry{border:1px solid
|
|
1
|
+
import {useState,useRef,useCallback,useEffect,useMemo,useLayoutEffect,useInsertionEffect,Component}from'react';import {createPortal}from'react-dom';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var Te=8;function Qe(e,n,s,d,a,l){let _=Math.max(Te,a-s-Te),v=Math.max(Te,l-d-Te);return {x:Math.min(Math.max(e,Te),_),y:Math.min(Math.max(n,Te),v)}}function et(e,n){let[s,d]=useState({x:e,y:n}),a=useRef(false),l=useRef({x:0,y:0}),_=useRef(false),v=useCallback(h=>{a.current=true,_.current=false,l.current={x:h.clientX-s.x,y:h.clientY-s.y},h.target.setPointerCapture(h.pointerId);},[s]),R=useCallback(h=>{a.current&&(_.current=true,d({x:h.clientX-l.current.x,y:h.clientY-l.current.y}));},[]),y=useCallback(()=>{a.current=false;},[]);return {pos:s,setPos:d,onPointerDown:v,onPointerMove:R,onPointerUp:y,didDrag:_}}function tt(e,n,s){let d=useRef(s);d.current=s,useEffect(()=>{if(!n)return;if(e.supabaseUrl){let l=false,_=null,v=()=>{l||_||(_=setInterval(()=>d.current(),15e3));},R=null;try{let g=new URL(e.supabaseUrl),t=["localhost","127.0.0.1","::1"].includes(g.hostname);if(g.protocol==="http:"&&!t)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");g.protocol=g.protocol==="https:"?"wss:":"ws:",R=g.toString().replace(/\/$/,"");}catch{v();}let y=null,h=null,B=null,j=0,k=()=>{if(!(l||!R)){try{y=new WebSocket(`${R}/realtime/v1/websocket?apikey=${e.anonKey}&vsn=1.0.0`);}catch{v();return}y.onopen=()=>{if(l||!y)return;let g={topic:`realtime:public:test_run_cases:test_run_id=eq.${n}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_run_cases",filter:`test_run_id=eq.${n}`}]}},ref:String(++j)};y.send(JSON.stringify(g));let t={topic:`realtime:public:test_runs:id=eq.${n}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_runs",filter:`id=eq.${n}`}]}},ref:String(++j)};y.send(JSON.stringify(t)),h=setInterval(()=>{y?.readyState===WebSocket.OPEN&&y.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++j)}));},3e4);},y.onmessage=g=>{try{JSON.parse(g.data).event==="postgres_changes"&&d.current();}catch{}},y.onclose=()=>{x(),l||(B=setTimeout(k,3e3));},y.onerror=()=>{y?.close();};}},x=()=>{h&&(clearInterval(h),h=null);};return k(),()=>{l=true,x(),B&&clearTimeout(B),_&&clearInterval(_),y&&(y.onclose=null,y.onerror=null,y.close());}}let a=setInterval(()=>d.current(),15e3);return ()=>clearInterval(a)},[e.supabaseUrl,e.anonKey,n]);}var cn="botbuddy:created-test-run:";function un(e){if(!e)return "";try{return new URL(e).origin}catch{return e}}function pn(e){return `${cn}${encodeURIComponent([e.appSlug,e.environment||"",e.ticketId||"",un(e.targetUrl),e.branchName||""].join("|"))}`}function Fe(e,n){let s={apikey:e.anonKey};return n?s.Authorization=`Bearer ${n}`:e.apiKey?s.Authorization=`Bearer ${e.apiKey}`:s.Authorization=`Bearer ${e.anonKey}`,s}async function gn(e){if(e)return e;try{let n=await fetch("/.botbuddy-token",{cache:"no-store"});if(n.ok){let s=(await n.text()).trim();if(s.startsWith("public_"))return s}}catch{}try{let n=import.meta?.env?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(n&&typeof n=="string"&&n.startsWith("public_"))return n}catch{}return null}function rt(e){let[n,s]=useState(null),[d,a]=useState("loading"),l=pn(e),[_,v]=useState(()=>{if(e.testRunId)return e.testRunId;try{return localStorage.getItem(l)||void 0}catch{return}}),R=e.testRunId||_,y=useCallback(x=>{if(s(x),!!x?.id){v(x.id);try{localStorage.setItem(l,x.id);}catch{}}},[l]),h=useCallback(async()=>{try{let x=await gn(e.testRunToken);if(!x&&!R){a("no-match"),s(null);return}if(x&&!e.ticketId){a("no-match"),s(null);return}let g=new URLSearchParams;x&&g.set("token",x),e.ticketId&&g.set("ticket_id",e.ticketId),g.set("app_slug",e.appSlug),e.environment&&g.set("environment",e.environment),R&&g.set("test_run_id",R),e.targetUrl&&g.set("target_url",e.targetUrl),e.version&&g.set("version",e.version),e.commitSha&&g.set("commit_sha",e.commitSha),e.prNumber&&g.set("pr_number",String(e.prNumber)),e.branchName&&g.set("branch_name",e.branchName);let t=await fetch(`${e.config.serverUrl}/widget/test-run?${g.toString()}`,{headers:Fe(e.config,e.authToken)});if(t.status===404){a("no-match"),s(null);return}if(t.status===401||t.status===403){e.authToken&&e.onAuthExpired&&e.onAuthExpired(),a("error");return}if(!t.ok){a("error");return}let i=await t.json();if(!i||i.run===null){a("no-match"),s(null);return}y(i),a(i.status==="completed"?"completed":"ready");}catch{a("error");}},[e.config.serverUrl,e.config.anonKey,e.config.apiKey,e.authToken,e.appSlug,e.environment,e.ticketId,R,e.testRunToken,e.targetUrl,e.version,e.commitSha,e.branchName,e.prNumber,e.onAuthExpired,y]);return useEffect(()=>{h();},[h]),tt(e.config,n?.id,h),{run:n,widgetState:d,fetchRun:h,setVerdict:async(x,g,t,i="human")=>(s(N=>{if(!N)return null;let z=N.test_cases.map(C=>C.id===x?{...C,verdict:g,fail_reason:g==="fail"&&t||null,verdict_by_display_name:i,verdict_at:new Date().toISOString()}:C),T={total:z.length,pending:0,pass:0,fail:0,skip:0};return z.forEach(C=>{C.verdict in T&&T[C.verdict]++;}),{...N,test_cases:z,summary:T}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${x}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...Fe(e.config,e.authToken)},body:JSON.stringify({verdict:g,fail_reason:t,display_name:i})})).ok),markComplete:async()=>n?(s(g=>g?{...g,status:"completed"}:null),a("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${n.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...Fe(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!n)return false;let x=await fetch(`${e.config.serverUrl}/widget/test-runs/${n.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...Fe(e.config,e.authToken)}});return x.ok&&h(),x.ok},setRun:y}}var it="botbuddy-widget-auth-token",at="botbuddy-widget-auth-name";function Le(e){if(!e)return null;try{let n=e.split(".")[1];if(!n)return null;let s=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(n.length/4)*4,"="),d=atob(s),a=JSON.parse(d);return typeof a.exp=="number"?a.exp*1e3:null}catch{return null}}var bn=2500,mn=6e4;function lt(e){let[n,s]=useState(()=>{try{return localStorage.getItem(it)}catch(k){return console.warn("Unable to read BotBuddy widget auth token",k),null}}),[d,a]=useState(()=>{try{return localStorage.getItem(at)}catch(k){return console.warn("Unable to read BotBuddy widget display name",k),null}}),l=useRef(null),_=useCallback((k,x)=>{s(k),x&&a(x);try{localStorage.setItem(it,k),x&&localStorage.setItem(at,x);}catch(g){console.warn("Unable to persist BotBuddy widget auth token",g);}},[]);useEffect(()=>{let k=new URL(e).origin,x=g=>{g.origin===k&&g.data?.type==="botbuddy-widget-auth"&&g.data.token&&_(g.data.token,g.data.displayName||"human");};return window.addEventListener("message",x),()=>window.removeEventListener("message",x)},[e,_]);let v=useCallback(()=>{if(l.current)return l.current;if(typeof window>"u"||typeof document>"u")return Promise.resolve(null);let k=new URL(e).origin,x=new URL("/widget-auth",e);x.searchParams.set("silent","1"),x.searchParams.set("origin",window.location.origin);let g=new Promise(t=>{let i=document.createElement("iframe");i.setAttribute("aria-hidden","true"),i.style.position="fixed",i.style.width="1px",i.style.height="1px",i.style.opacity="0",i.style.pointerEvents="none",i.style.border="0",i.style.left="-9999px",i.style.top="-9999px",i.src=x.toString();let U=false,N=()=>{window.removeEventListener("message",z),clearTimeout(T);try{i.remove();}catch{}l.current=null;},z=C=>{if(C.origin===k){if(C.data?.type==="botbuddy-widget-auth-failed"){if(U)return;U=true,t(null),N();return}C.data?.type!=="botbuddy-widget-auth"||!C.data.token||U||(U=true,t(String(C.data.token)),N());}},T=setTimeout(()=>{U||(U=true,t(null),N());},bn);window.addEventListener("message",z),document.body.appendChild(i);});return l.current=g,g},[e]);useEffect(()=>{if(!n)return;let k=Le(n);if(!k)return;let x=k-Date.now()-mn,g=window.setTimeout(()=>{v();},Math.max(0,x));return ()=>window.clearTimeout(g)},[n,v]);let R=useCallback(()=>{let k=new URL("/widget-auth",e);k.searchParams.set("origin",window.location.origin);let x=420,g=520,t=window.screenX+(window.innerWidth-x)/2,i=window.screenY+(window.innerHeight-g)/2;window.open(k.toString(),"botbuddy-auth",`width=${x},height=${g},left=${t},top=${i},popup=yes`);},[e]),[,y]=useState(0);useEffect(()=>{let k=Le(n);if(!k)return;let x=k-Date.now();if(x<=0)return;let g=window.setTimeout(()=>y(t=>t+1),x);return ()=>window.clearTimeout(g)},[n]);let h=useCallback(()=>{s(null),a(null);try{localStorage.removeItem(it),localStorage.removeItem(at);}catch(k){console.warn("Unable to clear BotBuddy widget auth token",k);}},[]),B=Le(n),j=B!==null&&B<=Date.now();return {token:n,displayName:d,isAuthenticated:!!n,isExpired:j,openLogin:R,refreshNow:v,logout:h}}var Oe=null;function yn(){try{if(typeof document<"u"){let e=document.querySelector("base[href]");if(e)return new URL(".botbuddy-totp.json",e.href).toString()}}catch{}return "/.botbuddy-totp.json"}function He(){return Oe||(Oe=(async()=>{if(typeof fetch>"u")return null;try{let e=await fetch(yn(),{cache:"no-store"});if(!e.ok)return null;let n=await e.json();if(!n||typeof n!="object"||Array.isArray(n))return null;let s={};for(let[d,a]of Object.entries(n))typeof a=="string"&&a.length>0&&(s[d]=a);return s}catch{return null}})(),Oe)}async function Ut(e){return (await He())?.[e]??null}function hn(e){let n=e.replace(/=+$/,"").replace(/\s+/g,"").toUpperCase(),s="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",d=[],a=0,l=0;for(let _ of n){let v=s.indexOf(_);if(v<0)throw new Error("Invalid Base32 character in TOTP secret");l=l<<5|v,a+=5,a>=8&&(a-=8,d.push(l>>>a&255));}return Uint8Array.from(d)}async function It(e,n=Date.now()){if(typeof crypto>"u"||!crypto.subtle)throw new Error("Web Crypto unavailable");let s=hn(e),d=new Uint8Array(s.byteLength);d.set(s);let a=Math.floor(n/1e3/30),l=new Uint8Array(8),_=Math.floor(a/4294967296),v=a>>>0;l[0]=_>>>24&255,l[1]=_>>>16&255,l[2]=_>>>8&255,l[3]=_&255,l[4]=v>>>24&255,l[5]=v>>>16&255,l[6]=v>>>8&255,l[7]=v&255;let R=await crypto.subtle.importKey("raw",d,{name:"HMAC",hash:"SHA-1"},false,["sign"]),y=await crypto.subtle.sign("HMAC",R,l),h=new Uint8Array(y),B=h[h.length-1]&15;return (((h[B]&127)<<24|(h[B+1]&255)<<16|(h[B+2]&255)<<8|h[B+3]&255)%1e6).toString().padStart(6,"0")}var Wt="0.11.0";function vn(e){let n=new Date(e),d=Date.now()-n.getTime();if(d<6e4)return "just now";if(d<36e5)return `${Math.floor(d/6e4)}m ago`;if(d<864e5)return `${Math.floor(d/36e5)}h ago`;let a=n.getDate(),l=n.toLocaleString("en",{month:"short"}),_=n.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${l} ${a}, ${_}`}var S=({d:e,className:n,size:s=14})=>jsx("svg",{className:n,width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:e})}),m={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01",bot:"M12 8V4H8M2 14h2M20 14h2M15 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M9 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M18 10a6 6 0 0 0-12 0v4a6 6 0 0 0 12 0Z",terminal:"M4 17l6-6-6-6M12 19h8",key:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4",shield:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10",copy:"M20 9h-9a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2-2v-9a2 2 0 0 0-2-2ZM5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1",search:"M11 17.25a6.25 6.25 0 1 1 0-12.5 6.25 6.25 0 0 1 0 12.5ZM16 16l4.5 4.5"};function wn(){let[e,n]=useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return useEffect(()=>{if(typeof window>"u")return;let s=document.documentElement,d=()=>s.classList.contains("dark")?"dark":s.classList.contains("light")?"light":null,a=d();a&&n(a);let l=window.matchMedia("(prefers-color-scheme: dark)"),_=R=>{let y=d();n(y||(R.matches?"dark":"light"));};l.addEventListener("change",_);let v=new MutationObserver(()=>{let R=d();n(R||(l.matches?"dark":"light"));});return v.observe(s,{attributes:true,attributeFilter:["class"]}),()=>{l.removeEventListener("change",_),v.disconnect();}},[]),e}function kn(e){let n=e==="dark";return {bg:n?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:n?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:n?"#e5e5e5":"#1a1a1a",textMuted:n?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:n?"#555":"#999",border:n?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:n?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:n?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:n?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:n?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:n?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:n?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:n?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:n?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:n?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:n?"#888":"#aaa",btnHover:n?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var Sn={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},_n={pending:m.circle,pass:m.check,fail:m.x,skip:m.skip},Ft={local:{bg:"rgba(59,130,246,0.15)",text:"#60a5fa",border:"rgba(59,130,246,0.3)"},preview:{bg:"rgba(168,85,247,0.15)",text:"#c084fc",border:"rgba(168,85,247,0.3)"},staging:{bg:"rgba(245,158,11,0.15)",text:"#fbbf24",border:"rgba(245,158,11,0.3)"},production:{bg:"rgba(239,68,68,0.15)",text:"#f87171",border:"rgba(239,68,68,0.3)"},custom:{bg:"rgba(128,128,128,0.15)",text:"#888",border:"rgba(128,128,128,0.3)"}},Rn=["app.supply-guard.io"];function Tn(e,n=[]){if(!e)return false;let s=e.toLowerCase();return [...Rn,...n].map(a=>a.toLowerCase()).includes(s)}var Cn=e=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:n=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:e.bg,border:n?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:n?`0 4px 12px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 4px 12px ${e.shadow}`,cursor:"pointer",fontSize:"9px",color:e.text}),card:(n,s)=>({width:`${n}px`,borderRadius:"8px",background:e.bg,border:s?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:s?`0 8px 24px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 8px 24px ${e.shadow}`,overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:`1px solid ${e.borderSubtle}`},title:{fontSize:"10px",fontWeight:600,color:e.text,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:e.textMuted,display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:e.gripColor,display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:`1px solid ${e.borderSubtle}`},badge:n=>{let s=Ft[n]||Ft.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:s.bg,color:s.text,border:`1px solid ${s.border}`,lineHeight:"14px"}},progress:{height:"2px",background:e.borderSubtle,flexShrink:0},progressBar:n=>({height:"100%",width:`${n}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:n=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${n}15`,color:n,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${e.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(n,s)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:n?`${s}33`:"transparent",color:n?s:e.gripColor,transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:e.inputBg,border:`1px solid ${e.inputBorder}`,borderRadius:"4px",padding:"2px 6px",color:e.text,outline:"none"},humanBanner:{padding:"6px 12px",fontSize:"11px",fontWeight:600,color:e.green,borderBottom:`1px solid ${e.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",background:e.greenBg,cursor:"pointer",textDecoration:"none"}});function dt(e){return e.split("/")[0].trim()}async function Mn(e){try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}try{if(typeof document>"u")return !1;let n=document.createElement("textarea");n.value=e,n.setAttribute("readonly",""),n.style.position="fixed",n.style.top="0",n.style.left="0",n.style.opacity="0",n.style.pointerEvents="none",document.body.appendChild(n),n.focus(),n.select(),n.setSelectionRange(0,e.length);let s=document.execCommand("copy");return document.body.removeChild(n),s}catch{return false}}function $e({config:e,appSlug:n,environment:s,seededUsers:d,authToken:a,tk:l,compact:_=false,onExpand:v,onAuthExpired:R,refreshAuth:y,requestLogin:h,testRunId:B,testRunToken:j,ticketId:k,targetUrl:x,version:g,commitSha:t,prNumber:i,branchName:U}){let[N,z]=useState(false),[T,C]=useState(null),[A,X]=useState(null),[Q,f]=useState(null),[ze,de]=useState(null),[se,ee]=useState(null),[te,ce]=useState(null);useEffect(()=>{s==="local"&&He();},[s]);let ve=useCallback(u=>{C(u),f(null),de(null),ce(null);let $=Le(a);if(s!=="local"&&h&&$!==null&&$<=Date.now()){ee({slug:u,token:a||null}),ce(u),C(null),h();return}let P=E=>{f(E),de(u),window.setTimeout(()=>{de(L=>L===u?null:L),f(L=>L===E?null:L);},3e3);},M=new URLSearchParams({app_slug:n,seed_user_slug:u,environment:s});B&&M.set("test_run_id",B),j&&M.set("public_token",j),k&&M.set("ticket_id",k),x&&M.set("target_url",x),g&&M.set("version",g),t&&M.set("commit_sha",t),i&&M.set("pr_number",String(i)),U&&M.set("branch_name",U);let I=async E=>{let L={apikey:e.anonKey,Authorization:`Bearer ${E}`};try{let F=await fetch(`${e.serverUrl}/widget/totp-code?${M}`,{headers:L});if(!F.ok){let ye=await F.json().catch(()=>({error:`HTTP ${F.status}`}));return {ok:!1,status:F.status,error:ye.error||`HTTP ${F.status}`}}let Z=await F.json();return {ok:!0,code:String(Z.code)}}catch{return {ok:false,status:0,error:"Network error"}}},V=(async()=>{if(s==="local"){let F=await Ut(u);if(F)try{return {ok:!0,code:await It(F)}}catch{}}let E=await I(a||e.anonKey);if(E.ok||E.status!==401||!y)return E;let L=await y();return L?I(L):{ok:false,status:401,error:"Sign in to BotBuddy to refresh 2FA"}})(),D=null;try{if(typeof ClipboardItem<"u"&&navigator.clipboard?.write){let E=V.then(L=>{if(!L.ok)throw new Error(L.error);return new Blob([L.code],{type:"text/plain"})});D=navigator.clipboard.write([new ClipboardItem({"text/plain":E})]).then(()=>!0).catch(()=>!1);}}catch{}(async()=>{let E=await V;if(!E.ok){E.status===401?(ee({slug:u,token:a||null}),ce(u)):P(E.status===404?"No 2FA seed registered":E.error),C(null);return}let L=D?await D:false,F=L?true:await Mn(E.code),Z=L||F;X({slug:u,code:E.code,copied:Z}),window.setTimeout(()=>X(ye=>ye?.slug===u?null:ye),Z?2500:6e3),z(false),C(null);})();},[e.serverUrl,e.anonKey,a,n,s,B,j,k,x,g,t,i,U,y,h]),ae=useCallback(u=>{ee({slug:u,token:a||null}),h?.();},[a,h]),we=useCallback(u=>{te===u?ae(u):ve(u);},[te,ae,ve]);useEffect(()=>{if(!se||!a||a===se.token)return;let u=se.slug;ee(null),ve(u);},[a,ve,se]);let ke=useRef(null),Ee=useRef(null);if(useLayoutEffect(()=>{if(!N)return;let u=ke.current,$=Ee.current;if(!u||!$||typeof window>"u")return;let P=()=>{let M=u.getBoundingClientRect(),I=$.getBoundingClientRect(),V=window.innerWidth,D=window.innerHeight,E=M.left,L=M.top-I.height-6;L<8&&(L=M.bottom+6);let F=Math.max(8,V-I.width-8),Z=Math.max(8,D-I.height-8);E=Math.min(Math.max(E,8),F),L=Math.min(Math.max(L,8),Z),$.style.left=`${Math.round(E)}px`,$.style.top=`${Math.round(L)}px`;};return P(),window.addEventListener("scroll",P,true),window.addEventListener("resize",P),()=>{window.removeEventListener("scroll",P,true),window.removeEventListener("resize",P);}},[N,d.length,Q]),useEffect(()=>{if(!N)return;let u=$=>{let P=$.target;Ee.current?.contains(P)||ke.current?.contains(P)||z(false);};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[N]),d.length===0)return null;if(_){let u=d.length>1,$=d[0],P=!u&&te===$,M=F=>{if(F.stopPropagation(),u&&v){v();return}we($);},I=!!ze,V=!!A,D=V&&A.copied,E=V&&!A.copied,L=P?l.blue:I?l.red:D?l.green:E?l.amber:l.purple;return jsxs("span",{onPointerDown:F=>F.stopPropagation(),onPointerUp:F=>F.stopPropagation(),onPointerMove:F=>F.stopPropagation(),onClick:M,style:{display:"inline-flex",alignItems:"center",gap:"3px",color:L,fontWeight:600,cursor:"pointer",letterSpacing:E?"0.08em":void 0},title:P?"Sign in to BotBuddy to refresh 2FA":I?Q||"Failed":E?`Clipboard blocked \u2014 code: ${A.code}`:u?`${d.length} 2FA personas`:`Copy 2FA code for ${d[0]}`,children:[jsx(S,{d:P?m.key:I?m.alert:D?m.check:E?m.copy:m.shield,size:10}),P?jsx(Fragment,{children:"Sign in"}):D?jsx(Fragment,{children:"Copied"}):E?jsx(Fragment,{children:A.code}):I?jsx(Fragment,{children:"Failed"}):jsxs(Fragment,{children:["2FA",u&&` \xB7${d.length}`]})]})}if(d.length===1){let u=d[0],$=T===u,P=A?.slug===u,M=P&&A.copied,I=P&&!A.copied,V=ze===u,D=te===u,E=D?l.blue:V?l.red:M?l.green:I?l.amber:l.purple;return jsxs("button",{onClick:L=>{L.stopPropagation(),we(u);},disabled:$,style:{...Dt(E),cursor:$?"wait":"pointer",opacity:$?.6:1},title:D?"Sign in to BotBuddy to refresh 2FA":V?Q||"Failed":I?`Clipboard blocked \u2014 code: ${A.code}`:`Copy 2FA code for ${u}`,children:[jsx(S,{d:D?m.key:V?m.alert:M?m.check:I?m.copy:m.shield,size:12}),D?"Sign in":M?"Copied":I?A.code:V?"Failed":$?"\u2026":`2FA \xB7 ${u}`]})}let ue=!!te&&!N,ne=!!ze&&!N,Se=!!A&&A.copied,_e=!!A&&!A.copied,Ve=ue?l.blue:ne?l.red:Se?l.green:_e?l.amber:l.purple,Ye=N&&typeof document<"u"?createPortal(jsxs("div",{ref:Ee,onPointerDown:u=>u.stopPropagation(),onMouseDown:u=>u.stopPropagation(),style:{position:"fixed",left:-9999,top:-9999,background:l.bg,border:`1px solid ${l.border}`,borderRadius:6,boxShadow:`0 8px 24px ${l.shadow}`,padding:4,minWidth:220,maxWidth:typeof window<"u"?Math.min(420,window.innerWidth-16):420,zIndex:1e5,fontFamily:"ui-monospace, SFMono-Regular, monospace"},children:[d.map(u=>{let $=T===u,P=te===u;return jsxs("button",{onClick:M=>{M.stopPropagation(),we(u);},disabled:$,style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 8px",background:"transparent",border:"none",borderRadius:4,cursor:$?"wait":"pointer",fontSize:"10px",color:P?l.blue:l.text,textAlign:"left",fontFamily:"ui-monospace, SFMono-Regular, monospace"},title:P?"Sign in to BotBuddy to refresh 2FA":void 0,onMouseEnter:M=>M.currentTarget.style.background=l.btnHover,onMouseLeave:M=>M.currentTarget.style.background="transparent",children:[jsx(S,{d:P?m.key:m.shield,size:10}),jsx("span",{style:{flex:1,overflowWrap:"anywhere",lineHeight:1.3},children:u}),P?jsx("span",{style:{color:l.blue,fontSize:9},children:"Sign in"}):$?jsx("span",{style:{color:l.textMuted,fontSize:9},children:"\u2026"}):null]},u)}),Q&&jsx("div",{style:{padding:"4px 8px",fontSize:9,color:l.red},children:Q})]}),document.body):null;return jsxs(Fragment,{children:[jsxs("button",{ref:ke,onClick:u=>{if(u.stopPropagation(),ue&&te){ae(te);return}z($=>!$),f(null),de(null);},style:{...Dt(Ve),cursor:"pointer"},title:ue?"Sign in to BotBuddy to refresh 2FA":ne?Q||"Failed":_e?`Clipboard blocked \u2014 code: ${A.code}`:"Choose a persona to copy a 2FA code for",children:[jsx(S,{d:ue?m.key:ne?m.alert:Se?m.check:_e?m.copy:m.shield,size:12}),ue?"Sign in":Se?"Copied":_e?A.code:ne?"Failed":`2FA \xB7 ${d.length}`,!ue&&jsx(S,{d:N?m.chevronUp:m.chevronDown,size:8})]}),Ye]})}function Dt(e){return {display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${e}15`,color:e,textDecoration:"none",border:`1px solid ${e}30`}}var Ot="botbuddy-widget-state";function En({config:e,appSlug:n,environment:s,ticketId:d,testRunId:a,testRunToken:l,targetUrl:_,version:v,commitSha:R,prNumber:y,branchName:h,onNavigate:B,displayName:j="human",defaultMode:k="mini",defaultPosition:x}){let g=wn(),t=useMemo(()=>kn(g),[g]),i=useMemo(()=>Cn(t),[t]),[U,N]=useState(false),[z,T]=useState(false),[C,A]=useState(false),X=useRef(false),Q=e.dashboardUrl||"https://app.bot-buddy.ai",f=lt(Q),de=(()=>{try{let r=typeof window<"u"?localStorage.getItem(Ot):null;if(r)return JSON.parse(r)}catch{}return null})(),[se,ee]=useState(de?.mode||k),[te,ce]=useState(""),[ve,ae]=useState(null),[we,ke]=useState(null),[Ee,ue]=useState(new Set),[ne,Se]=useState(""),_e=useCallback(r=>{ue(p=>{let w=new Set(p);return w.has(r)?w.delete(r):w.add(r),w});},[]),Ve=de?.x??x?.x??16,Ye=de?.y??x?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:u,setPos:$,onPointerDown:P,onPointerMove:M,onPointerUp:I,didDrag:V}=et(Ve,Ye),D=useRef(null);useEffect(()=>{try{localStorage.setItem(Ot,JSON.stringify({mode:se,x:u.x,y:u.y}));}catch{}},[se,u.x,u.y]),useLayoutEffect(()=>{if(typeof window>"u")return;let r=D.current;if(!r)return;let p=r.getBoundingClientRect(),w=Qe(u.x,u.y,p.width,p.height,window.innerWidth,window.innerHeight);(w.x!==u.x||w.y!==u.y)&&$(w);}),useEffect(()=>{if(typeof window>"u")return;let r=()=>{let p=D.current;if(!p)return;let w=p.getBoundingClientRect(),H=Qe(u.x,u.y,w.width,w.height,window.innerWidth,window.innerHeight);(H.x!==u.x||H.y!==u.y)&&$(H);};return window.addEventListener("resize",r),()=>window.removeEventListener("resize",r)},[u.x,u.y,$]);let E=useRef(f.isAuthenticated);useEffect(()=>{!E.current&&f.isAuthenticated&&ee("max"),E.current=f.isAuthenticated;},[f.isAuthenticated]);let L="botbuddy-widget-max-size",F=()=>{try{let r=localStorage.getItem(L);if(r)return JSON.parse(r)}catch{}return {w:340,h:500}},[Z,ye]=useState(F),Ne=useRef(false),Pe=useRef({x:0,y:0,w:0,h:0}),Jt=useCallback(r=>{r.stopPropagation(),Ne.current=true,Pe.current={x:r.clientX,y:r.clientY,w:Z.w,h:Z.h},r.target.setPointerCapture(r.pointerId);},[Z]),Gt=useCallback(r=>{if(!Ne.current)return;let p=Math.max(280,Math.min(600,Pe.current.w+(r.clientX-Pe.current.x))),w=Math.max(300,Math.min(window.innerHeight*.9,Pe.current.h+(r.clientY-Pe.current.y)));ye({w:p,h:w});},[]),Xt=useCallback(()=>{Ne.current&&(Ne.current=false,ye(r=>(localStorage.setItem(L,JSON.stringify(r)),r)));},[]),re=_??(typeof window<"u"?window.location.href:void 0),bt=f.displayName||j,[le,mt]=useState(null);useEffect(()=>{if(f.isAuthenticated)return;let r=new URLSearchParams;l&&r.set("token",l),d&&r.set("ticket_id",d),r.set("app_slug",n),s&&r.set("environment",s),a&&r.set("test_run_id",a),re&&r.set("target_url",re),v&&r.set("version",v),R&&r.set("commit_sha",R),y&&r.set("pr_number",String(y)),h&&r.set("branch_name",h),fetch(`${e.serverUrl}/widget/preview?${r}`,{headers:{apikey:e.anonKey}}).then(p=>p.json()).then(p=>mt(p)).catch(()=>mt(null));},[f.isAuthenticated,e.serverUrl,e.anonKey,n,s,d,a,l,re,v,R,y,h]);let yt=useRef(false),Zt=useCallback(()=>{yt.current||f.logout();},[f.logout]),{run:b,widgetState:he,fetchRun:Qt,setVerdict:ht,markComplete:en,resetRun:tn,setRun:xt}=rt({config:e,appSlug:n,environment:s,ticketId:d,testRunId:a,testRunToken:l,targetUrl:re,version:v,commitSha:R,prNumber:y?String(y):void 0,branchName:h,authToken:f.token,onAuthExpired:Zt});yt.current=!!b;let[vt,wt]=useState([]),[kt,Ae]=useState([]),[qe,St]=useState(false),[_t,Rt]=useState(null),[nn,Ue]=useState(false),pe=Tn(typeof window<"u"?window.location.hostname:void 0,e.productionHostnames||[]);useEffect(()=>{if((s??"local")!=="local"||pe){wt([]);return}let r=true;return He().then(p=>{r&&wt(Object.keys(p||{}));}),()=>{r=false;}},[s,pe]);let rn=useCallback(async()=>{if(!(!f.isAuthenticated||!f.token)){St(true),Rt(null);try{let r=await fetch(`${e.serverUrl}/widget/test-runs`,{method:"POST",headers:{"Content-Type":"application/json",apikey:e.anonKey,Authorization:`Bearer ${f.token}`},body:JSON.stringify({app_slug:n,environment:s||"local",target_url:re,branch_name:h,commit_sha:R,pr_number:y,ticket_id:d,title:`${d||n} local validation`})}),p=await r.json().catch(()=>({}));if(!r.ok)throw new Error(p.error||`HTTP ${r.status}`);xt(p),ee("max");}catch(r){Rt(r.message);}finally{St(false);}}},[f.isAuthenticated,f.token,e.serverUrl,e.anonKey,n,s,re,h,R,y,d,xt]),Ie=useCallback(async(r,p,w)=>{ke(r);try{await ht(r,p,w,bt);}finally{ke(null),ae(null),ce("");}},[ht,bt]),K=b?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},on=K.total>0&&K.pending===0,Re=he==="completed",We=useMemo(()=>{let r=b?.test_cases||[];if(!ne.trim())return r;let p=ne.toLowerCase();return r.filter(w=>w.title.toLowerCase().includes(p)||w.description&&w.description.toLowerCase().includes(p)||w.url_path&&w.url_path.toLowerCase().includes(p)||w.seed_user&&w.seed_user.toLowerCase().includes(p))},[b?.test_cases,ne]),Tt=useMemo(()=>{let r=We,p=b?.test_cases||[];if(new Set(p.map(J=>J.source_pr_number)).size<=1)return null;let H=[],fe=new Map;r.forEach(J=>{let q=J.source_pr_number;fe.has(q)||fe.set(q,[]),fe.get(q).push(J);});let Bt=[...fe.keys()].sort((J,q)=>J===null?1:q===null?-1:q-J);for(let J of Bt){let q=fe.get(J),Ge={total:q.length,pass:0,fail:0,skip:0,pending:0};q.forEach(zt=>{zt.verdict in Ge&&Ge[zt.verdict]++;}),H.push({key:J!=null?`pr-${J}`:"general",label:J!=null?`PR #${J}`:"General",cases:q,summary:Ge});}return H.filter(J=>J.cases.length>0)},[We,b?.test_cases]),Ct=K.total>0?(K.pass+K.fail)/K.total*100:0,Y=s??b?.environment??null,ge=useMemo(()=>{if(!Y||Y==="production"||pe)return [];let r=b?.test_cases||[],p=new Set;for(let w of r)w.seed_user&&p.add(dt(w.seed_user));if(Y==="local")for(let w of vt)p.add(dt(w));for(let w of kt)p.add(dt(w));return [...p]},[b?.test_cases,Y,vt,kt,pe]);useEffect(()=>{if(!Y||Y==="production"||pe||!f.isAuthenticated||!f.token){Ae([]);return}let r=true,p=`${e.serverUrl}/widget/totp-seeds?${new URLSearchParams({app_slug:n,environment:Y})}`,w=H=>fetch(p,{headers:{apikey:e.anonKey,Authorization:`Bearer ${H}`}});return (async()=>{try{let H=await w(f.token);if(H.status===401&&f.refreshNow){let q=await f.refreshNow();q&&(H=await w(q));}if(!r)return;if(!H.ok){Ae([]);return}let fe=await H.json().catch(()=>null),J=(Array.isArray(fe?.seeds)?fe.seeds:[]).map(q=>q?.seed_user_slug).filter(q=>typeof q=="string"&&q.length>0);Ae(J);}catch{r&&Ae([]);}})(),()=>{r=false;}},[Y,pe,f.isAuthenticated,f.token,f.refreshNow,n,e.serverUrl,e.anonKey]);let Je=useMemo(()=>{let r=b?.auto_tooltip_seconds??le?.auto_tooltip_seconds;return r!=null&&r>0?r*1e3:0},[b,le]),Mt=he==="ready"||he==="completed"||le?.enabled&&le.run;useEffect(()=>{if(!Mt||X.current||Je<=0)return;X.current=true,T(true);let r=window.setTimeout(()=>T(false),Je);return ()=>window.clearTimeout(r)},[Mt,Je]);let Et=r=>jsxs("div",{style:i.caseRow,children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsx("div",{style:{marginTop:"2px",flexShrink:0,color:Sn[r.verdict]},children:we===r.id?jsx(S,{d:m.loader,className:""}):jsx(S,{d:_n[r.verdict],className:""})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"10px",color:t.text,lineHeight:1.3},children:r.title}),r.description&&jsx("div",{style:{fontSize:"9px",color:t.gripColor,marginTop:"2px"},children:r.description}),r.seed_user&&jsxs("div",{style:{fontSize:"9px",color:t.amber,marginTop:"3px",display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",background:`${t.amber}12`,border:`1px solid ${t.amber}30`},children:[jsx(S,{d:m.key,size:10}),jsx("span",{children:r.seed_user})]}),r.url_path&&jsxs("a",{href:r.url_path,target:"_blank",rel:"noopener noreferrer",onClick:p=>{p.stopPropagation(),B&&(p.preventDefault(),B(r.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsx(S,{d:m.externalLink,size:10}),r.url_path]}),r.verdict==="fail"&&r.fail_reason&&jsxs("div",{style:{fontSize:"9px",color:t.red,marginTop:"2px"},children:["\u2717 ",r.fail_reason]})]})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(p=>jsx("button",{onClick:()=>{if(r.verdict===p){Ie(r.id,"pending"),ae(null);return}if(p==="fail"){ae(r.id),ce("");return}ae(null),Ie(r.id,p);},disabled:we!==null,style:i.verdictBtn(r.verdict===p,p==="pass"?t.green:p==="fail"?t.red:t.amber),children:p.toUpperCase()},p)),r.created_by_agent_name&&jsxs("span",{style:{fontSize:"8px",color:t.purple,marginLeft:"4px",display:"inline-flex",alignItems:"center",gap:"2px"},children:[jsx(S,{d:m.bot,size:8}),r.created_by_agent_name]}),r.verdict_by_display_name&&jsxs("span",{style:{fontSize:"8px",color:t.textFaint,marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:"3px"},children:[r.verdict_by_display_name,r.verdict_at&&jsx("span",{style:{opacity:.7},children:vn(r.verdict_at)})]})]}),ve===r.id&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:te,onChange:p=>ce(p.target.value),onKeyDown:p=>{p.key==="Enter"&&Ie(r.id,"fail",te.trim()||void 0),p.key==="Escape"&&(ae(null),ce(""));},placeholder:"Reason (optional)...",style:i.input}),jsx("button",{onClick:()=>{Ie(r.id,"fail",te.trim()||void 0);},style:i.verdictBtn(true,t.red),children:"\u2713"})]})]},r.id);if((he==="no-match"||he==="loading")&&!(!f.isAuthenticated&&le?.enabled&&le.run)){if(!(Y==="local"&&!pe))return null}if(!f.isAuthenticated&&le?.enabled&&le.run){let r=le.run,p=r.summary,w=r.status==="completed";return jsx("div",{ref:D,style:{...i.root,left:u.x,top:u.y},children:jsxs("div",{style:{position:"relative"},onMouseEnter:()=>N(true),onMouseLeave:()=>{N(false),A(false),T(false);},children:[jsxs("div",{style:{...i.pill(w),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:P,onPointerMove:M,onPointerUp:()=>{I();},children:[jsx(S,{d:m.grip,size:10,className:""}),r.ticket_id&&r.ticket_url?jsx("a",{href:r.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:H=>H.stopPropagation(),style:{color:t.amber,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:r.ticket_id}):null,r.pr_url?jsxs("a",{href:r.pr_url,target:"_blank",rel:"noopener noreferrer",onClick:H=>H.stopPropagation(),style:{color:t.blue,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:["PR#",r.pr_number??r.pr_id]}):null,r.created_by_agent_name?r.codex_thread_id?jsxs("a",{href:`codex://threads/${r.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",onClick:H=>H.stopPropagation(),style:{color:t.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(S,{d:m.terminal,size:10}),r.created_by_agent_name]}):jsxs("span",{style:{color:t.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(S,{d:m.bot,size:10}),r.created_by_agent_name]}):null,jsxs("span",{style:w?{color:t.green}:void 0,children:[p.pass,"/",p.total]}),p.fail>0&&jsxs("span",{style:{color:t.red},children:[p.fail,"\u2717"]}),jsx("span",{onClick:H=>{H.stopPropagation(),f.openLogin();},style:{color:t.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!C&&(U||z)&&r.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:t.bg,border:`1px solid ${t.border}`,boxShadow:`0 8px 24px ${t.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsx("div",{style:{fontSize:"11px",fontWeight:700,color:t.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:r.title}),(r.description||r.intro_notes)&&jsx("div",{style:{fontSize:"10px",color:t.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:r.description||r.intro_notes}),jsx("div",{style:{marginTop:"4px",fontSize:"9px",color:t.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!f.isAuthenticated)return jsxs("div",{ref:D,style:{...i.root,left:u.x,top:u.y,width:220,minHeight:0,cursor:"move",userSelect:"none",borderRadius:"8px",background:t.bg,border:`1px solid ${t.border}`,boxShadow:`0 8px 24px ${t.shadow}`},onPointerDown:P,onPointerMove:M,onPointerUp:I,children:[jsx("div",{style:{...i.handle,borderBottom:"none"},children:jsxs("div",{style:i.sub,children:[jsx(S,{d:m.grip,size:10,className:""}),jsx(S,{d:m.clipboard,size:12,className:""}),jsx("span",{style:{fontWeight:600},children:"BotBuddy"})]})}),jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[jsx("div",{style:{fontSize:"9px",color:t.textMuted,marginBottom:"8px"},children:"Sign in to access test cases"}),Y==="local"&&ge.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx($e,{config:e,appSlug:n,environment:Y,seededUsers:ge,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:t,testRunId:b?.id||a,testRunToken:l,ticketId:d,targetUrl:re,version:v,commitSha:R,prNumber:y,branchName:h,onAuthExpired:f.logout})}),jsx("button",{onClick:r=>{r.stopPropagation(),f.openLogin();},style:{fontSize:"10px",fontWeight:600,padding:"6px 16px",borderRadius:"6px",border:`1px solid ${t.green}`,background:`${t.green}22`,color:t.green,cursor:"pointer",width:"100%"},children:"Sign in to test"})]})]});if(!b&&Y==="local"&&!pe)return nn?jsx("div",{ref:D,style:{...i.root,left:u.x,top:u.y},children:jsxs("div",{style:i.card(240,false),children:[jsxs("div",{style:i.handle,onPointerDown:P,onPointerMove:M,onPointerUp:I,onClick:()=>{V.current||Ue(false);},children:[jsx(S,{d:m.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:i.title,children:"BotBuddy"}),h&&jsx("div",{style:i.sub,children:jsxs("span",{children:["\u2387 ",h]})})]}),jsx(S,{d:m.chevronUp,className:""}),jsx("button",{style:i.btn,onClick:r=>{r.stopPropagation(),Ue(false);},children:jsx(S,{d:m.minus,className:""})})]}),jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[ge.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx($e,{config:e,appSlug:n,environment:Y,seededUsers:ge,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:t,testRunId:a,testRunToken:l,ticketId:d,targetUrl:re,version:v,commitSha:R,prNumber:y,branchName:h,onAuthExpired:f.logout})}),jsx("button",{onClick:r=>{r.stopPropagation(),rn();},disabled:qe,style:{fontSize:"10px",fontWeight:600,padding:"6px 12px",borderRadius:"6px",border:`1px solid ${t.green}`,background:`${t.green}22`,color:t.green,cursor:qe?"wait":"pointer",width:"100%"},children:qe?"Creating...":"Create test run for this branch"}),_t&&jsx("div",{style:{fontSize:"9px",color:t.red,marginTop:"8px"},children:_t})]})]})}):jsx("div",{ref:D,style:{...i.root,left:u.x,top:u.y},children:jsxs("div",{style:{...i.pill(false),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:P,onPointerMove:M,onPointerUp:()=>{I(),V.current||Ue(true);},children:[jsx(S,{d:m.grip,size:9,className:""}),jsx("span",{style:{fontWeight:600},children:"BotBuddy"}),ge.length>0&&jsx($e,{config:e,appSlug:n,environment:Y,seededUsers:ge,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:t,compact:true,onExpand:()=>Ue(true),testRunId:a,testRunToken:l,ticketId:d,targetUrl:re,version:v,commitSha:R,prNumber:y,branchName:h,onAuthExpired:f.logout})]})});let Nt=()=>{V.current||(T(false),ee(r=>{let p=r==="mini"?"max":"mini";return A(p==="mini"),p}));},Pt=({icon:r,onClick:p})=>jsx("button",{style:i.btn,onClick:w=>{w.stopPropagation(),p(w);},children:jsx(S,{d:r,className:""})}),Lt=()=>jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${t.borderSubtle}`,flexShrink:0},children:[b?.pr_url&&jsxs("a",{href:b.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link(t.blue),textDecoration:"none"},children:[jsx(S,{d:m.pr,size:12}),b.pr_number?`PR#${b.pr_number}`:b.pr_id||"PR",jsx(S,{d:m.externalLink,size:8})]}),b?.ticket_url&&jsxs("a",{href:b.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link(t.amber),textDecoration:"none"},children:[jsx(S,{d:m.ticket,size:12}),b.ticket_id||"Ticket",jsx(S,{d:m.externalLink,size:8})]}),b?.created_by_agent_name&&(b.codex_thread_id?jsxs("a",{href:`codex://threads/${b.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:{...i.link(t.purple),textDecoration:"none"},children:[jsx(S,{d:m.bot,size:12}),b.created_by_agent_name,jsx(S,{d:m.externalLink,size:8})]}):jsxs("span",{style:{...i.link(t.purple)},children:[jsx(S,{d:m.bot,size:12}),b.created_by_agent_name]})),Y&&jsx($e,{config:e,appSlug:n,environment:Y,seededUsers:ge,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:t,testRunId:b?.id||a,testRunToken:l,ticketId:d,targetUrl:re,version:v,commitSha:R,prNumber:y,branchName:h,onAuthExpired:f.logout}),jsx("span",{style:{...i.badge(b?.environment||"custom"),marginLeft:"auto"},children:b?.environment})]}),$t=()=>jsxs("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:`1px solid ${t.borderSubtle}`,background:t.bgSoft,flexShrink:0},children:[jsxs("button",{onClick:()=>{navigator.clipboard.writeText(Wt);},style:{fontSize:"9px",fontWeight:600,color:t.versionText,letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsxs("span",{style:{color:t.versionNum},children:["v",Wt]})]}),f.isAuthenticated&&(f.isExpired?jsx("button",{onClick:r=>{r.stopPropagation(),f.openLogin();},style:{fontSize:"8px",color:t.blue,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Widget session expired \u2014 sign in to refresh",children:"sign in"}):jsx("button",{onClick:r=>{r.stopPropagation(),f.logout();},style:{fontSize:"8px",color:t.textFaint,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Sign out of widget",children:"sign out"}))]});return jsxs("div",{ref:D,style:{...i.root,left:u.x,top:u.y},children:[se==="mini"&&jsxs("div",{style:{position:"relative"},onMouseEnter:()=>N(true),onMouseLeave:()=>{N(false),A(false),T(false);},children:[jsxs("div",{style:{...i.pill(Re),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:P,onPointerMove:M,onPointerUp:()=>{I(),V.current||Nt();},children:[jsx(S,{d:m.grip,size:9,className:""}),b?.ticket_id&&jsx("span",{style:{color:t.amber,fontWeight:600},children:b.ticket_id}),b?.pr_number&&jsxs("span",{style:{color:t.blue,fontWeight:600},children:["PR#",b.pr_number]}),jsxs("span",{style:Re?{color:t.green}:void 0,children:[K.pass,"/",K.total]}),K.fail>0&&jsxs("span",{style:{color:t.red},children:[K.fail,"\u2717"]}),Y&&jsx($e,{config:e,appSlug:n,environment:Y,seededUsers:ge,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:t,compact:true,onExpand:()=>ee("expanded"),testRunId:b?.id||a,testRunToken:l,ticketId:d,targetUrl:re,version:v,commitSha:R,prNumber:y,branchName:h,onAuthExpired:f.logout})]}),!C&&(U||z)&&b?.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:t.bg,border:`1px solid ${t.border}`,boxShadow:`0 8px 24px ${t.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsx("div",{style:{fontSize:"11px",fontWeight:700,color:t.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:b.title}),(b.description||b.intro_notes)&&jsx("div",{style:{fontSize:"10px",color:t.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:b.description||b.intro_notes})]})]}),se==="expanded"&&jsxs("div",{style:i.card(300,Re),children:[jsxs("div",{style:i.handle,onPointerDown:P,onPointerMove:M,onPointerUp:I,onClick:Nt,children:[jsx(S,{d:m.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:i.title,children:b?.title}),jsx("div",{style:i.sub,children:b?.branch_name&&jsxs("span",{children:["\u2387 ",b.branch_name]})})]}),jsx(S,{d:m.chevronUp,className:""}),jsx(Pt,{icon:m.minus,onClick:()=>{T(false),A(true),ee("mini");}})]}),jsxs("div",{style:i.stats,children:[jsxs("span",{style:{color:t.green},children:[K.pass,"\u2713"]}),jsxs("span",{style:{color:t.red},children:[K.fail,"\u2717"]}),jsxs("span",{style:{color:t.amber},children:[K.skip,"\u23ED"]}),jsxs("span",{style:{color:t.gripColor},children:[K.pending,"\u25CC"]}),jsx("span",{style:{color:t.textFaint,marginLeft:"auto"},children:K.total})]}),b?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:t.gripColor,borderBottom:`1px solid ${t.borderSubtle}`,flexShrink:0},children:b.description}),Lt(),$t(),jsx("div",{style:i.progress,children:jsx("div",{style:i.progressBar(Ct)})})]}),se==="max"&&jsxs("div",{style:{...i.card(Z.w,Re),height:Z.h,position:"relative"},children:[jsxs("div",{style:i.handle,onPointerDown:P,onPointerMove:M,onPointerUp:I,onClick:()=>{V.current||ee("expanded");},children:[jsx(S,{d:m.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:i.title,children:b?.title}),jsx("div",{style:i.sub,children:b?.branch_name&&jsxs("span",{children:["\u2387 ",b.branch_name]})})]}),jsx(S,{d:m.chevronDown,className:""}),jsx(Pt,{icon:m.minus,onClick:()=>{T(false),A(true),ee("mini");}})]}),jsxs("div",{style:i.stats,children:[jsxs("span",{style:{color:t.green},children:[K.pass,"\u2713"]}),jsxs("span",{style:{color:t.red},children:[K.fail,"\u2717"]}),jsxs("span",{style:{color:t.amber},children:[K.skip,"\u23ED"]}),jsxs("span",{style:{color:t.gripColor},children:[K.pending,"\u25CC"]}),jsx("span",{style:{color:t.textFaint,marginLeft:"auto"},children:K.total})]}),b?.intro_notes&&jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${t.borderSubtle}`,fontSize:"10px",color:t.textMuted,fontStyle:"italic",flexShrink:0},children:b.intro_notes}),(b?.test_cases||[]).length>5&&jsxs("div",{style:{padding:"4px 12px",borderBottom:`1px solid ${t.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[jsx(S,{d:m.search,size:11,className:""}),jsx("input",{value:ne,onChange:r=>Se(r.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:t.text,fontFamily:"monospace"}}),ne&&jsx("button",{onClick:()=>Se(""),style:{background:"none",border:"none",cursor:"pointer",color:t.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),he==="error"&&jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsx(S,{d:m.alert,className:""}),jsx("div",{style:{fontSize:"10px",color:t.red},children:"Failed to load"}),jsx("button",{onClick:Qt,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),Re&&jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${t.greenBorderSubtle}`,background:t.greenBg},children:[jsx(S,{d:m.checkAll,className:""}),jsx("span",{style:{fontSize:"10px",color:t.green,flex:1},children:"Run completed"}),jsx("button",{onClick:tn,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),he!=="error"&&jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(b?.test_cases||[]).length===0?jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:t.gripColor},children:"No test cases"}):We.length===0?jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:t.gripColor},children:['No matches for "',ne,'"']}):Tt?Tt.map(r=>{let p=Ee.has(r.key);return jsxs("div",{children:[jsxs("button",{onClick:()=>_e(r.key),style:{width:"100%",display:"flex",alignItems:"center",gap:"6px",padding:"5px 12px",background:t.bgSoft,cursor:"pointer",border:"none",borderLeft:"none",borderRight:"none",borderBottomStyle:"solid",borderTopStyle:"solid",borderBottomWidth:"1px",borderTopWidth:"1px",borderBottomColor:t.borderSubtle,borderTopColor:t.borderSubtle,backgroundColor:t.bgSoft},children:[jsx(S,{d:p?m.chevronDown:m.chevronUp,size:10,className:""}),jsx("span",{style:{fontSize:"10px",fontWeight:700,color:t.blue,flex:1,textAlign:"left"},children:r.label}),jsxs("span",{style:{fontSize:"9px",color:t.green},children:[r.summary.pass,"\u2713"]}),jsxs("span",{style:{fontSize:"9px",color:t.red},children:[r.summary.fail,"\u2717"]}),jsxs("span",{style:{fontSize:"9px",color:t.gripColor},children:[r.summary.pending,"\u25CC"]}),jsx("span",{style:{fontSize:"9px",color:t.textFaint},children:r.summary.total})]}),!p&&r.cases.map(w=>Et(w))]},r.key)}):We.map(r=>Et(r))}),on&&!Re&&jsxs("div",{style:{padding:"6px 12px",borderTop:`1px solid ${t.greenBorderSubtle}`,background:t.greenBg,display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsx("span",{style:{fontSize:"9px",color:t.green},children:"All resolved"}),jsx("button",{onClick:en,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:t.green,border:`1px solid ${t.greenBorderSubtle}`,cursor:"pointer"},children:"COMPLETE"})]}),Lt(),$t(),jsx("div",{style:i.progress,children:jsx("div",{style:i.progressBar(Ct)})}),jsx("div",{style:{position:"absolute",bottom:0,right:0,width:16,height:16,cursor:"se-resize",zIndex:10,display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:"2px",opacity:.3},onPointerDown:Jt,onPointerMove:Gt,onPointerUp:Xt,onPointerEnter:r=>r.currentTarget.style.opacity="0.7",onPointerLeave:r=>{Ne.current||(r.currentTarget.style.opacity="0.3");},children:jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsx("path",{d:"M7 1v6H1",fill:"none",stroke:t.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}var $n=1e4,Be=new Map;var Ke=class extends Error{};async function Bn(e,n,s){let d={headers:{authorization:`Bearer ${n}`}};try{return await fetch(e,{...d,signal:s})}catch(a){if(a instanceof TypeError&&/signal/i.test(a.message)&&!s.aborted)return fetch(e,d);throw a}}function zn(e){let n=e;return !!n&&typeof n=="object"&&typeof n.tenant=="string"&&Array.isArray(n.entries)&&n.entries.every(s=>!!s&&typeof s.id=="string"&&typeof s.title=="string"&&!!s.body&&Array.isArray(s.body.ast)&&Array.isArray(s.links))}function ct({endpoint:e,getToken:n,timeoutMs:s=$n}){let[d,a]=useState(()=>({feed:null,error:null,loading:true,stale:false})),[l,_]=useState(0),v=useRef(n);v.current=n,useEffect(()=>{let y=new AbortController,h=true,B=false,j=setTimeout(()=>{B=true,y.abort();},s),k=new Promise((t,i)=>{y.signal.addEventListener("abort",()=>i(new Error("timeout")),{once:true});});k.catch(()=>{}),a(t=>({...t,error:null,loading:true}));let x=null,g=(t,i)=>{if(i&&Be.delete(e),!h)return;let U=i||x===null?void 0:Be.get(e)?.get(x);a({feed:U??null,error:t,loading:false,stale:!!U});};return (async()=>{try{let t;try{t=await Promise.race([Promise.resolve().then(()=>v.current()),k]);}catch(z){throw B||y.signal.aborted?z:new Ke("token_unavailable")}x=t;let i=await Promise.race([Bn(e,t,y.signal),k]),U=i.status===401||i.status===403;U&&Be.delete(e);let N=null;try{N=await Promise.race([i.json(),k]);}catch(z){if(B&&!U)throw z;N=null;}if(!h)return;if(i.ok)if(!zn(N))g("invalid_feed",!1);else {let z=Be.get(e)??new Map;z.set(t,N),Be.set(e,z),a({feed:N,error:null,loading:!1,stale:!1});}else {let z=N?.error;g(typeof z=="string"?z:`http_${i.status}`,U);}}catch(t){t instanceof Ke?g(t.message,true):g(B?"timeout":t instanceof Error&&t.message||"unavailable",false);}finally{clearTimeout(j);}})(),()=>{h=false,clearTimeout(j),y.abort();}},[e,l,s]);let R=useCallback(()=>_(y=>y+1),[]);return {...d,reload:R}}var gt=["accent","fg","bg","muted","border","radius","font"],An={accent:"hsl(var(--primary))",fg:"hsl(var(--foreground))",bg:"hsl(var(--card))",muted:"hsl(var(--muted-foreground))",border:"hsl(var(--border))",radius:"var(--radius)",font:"inherit"},Me=(e,n)=>n===void 0?`var(--bbrn-${e},var(--_bbrn-${e}))`:`var(--bbrn-${e},var(--_bbrn-${e},${n}))`,ut=Me("accent","currentColor"),Un=Me("muted","color-mix(in srgb,currentColor 72%,transparent)"),pt=Me("border","color-mix(in srgb,currentColor 22%,transparent)"),In=`@layer bbrn{
|
|
2
|
+
.bbrn-root{${gt.filter(e=>e!=="font").map(e=>`--_bbrn-${e}:${An[e]};`).join("")}display:grid;gap:12px;color:${Me("fg")};font-family:var(--bbrn-font)}
|
|
3
|
+
.bbrn-root .bbrn-entry{background:${Me("bg","transparent")};border:1px solid ${pt};border-radius:${Me("radius",".5rem")};padding:16px}
|
|
4
4
|
.bbrn-root .bbrn-head{display:flex;gap:8px;align-items:baseline;flex-wrap:wrap}
|
|
5
|
-
.bbrn-root .bbrn-title{font-weight:600;font-size:1rem;margin:0}
|
|
6
|
-
.bbrn-root .bbrn-badge{font-size:.75rem;border:1px solid currentColor;border-radius:999px;padding:0 8px}
|
|
7
|
-
.bbrn-root .bbrn-delivery{font-size:.75rem;border-radius:999px;padding:0 8px;background:
|
|
8
|
-
.bbrn-root .bbrn-meta{color
|
|
5
|
+
.bbrn-root .bbrn-title{font-weight:600;font-size:1rem;line-height:1.4;margin:0}
|
|
6
|
+
.bbrn-root .bbrn-badge{font-size:.75rem;line-height:1.4;color:${ut};border:1px solid currentColor;border-radius:999px;padding:0 8px}
|
|
7
|
+
.bbrn-root .bbrn-delivery{font-size:.75rem;line-height:1.4;border-radius:999px;padding:0 8px;background:color-mix(in srgb,${pt} 60%,transparent)}
|
|
8
|
+
.bbrn-root .bbrn-meta,.bbrn-root .bbrn-status{color:${Un};font-size:.8rem;margin:0}
|
|
9
9
|
.bbrn-root .bbrn-p{margin:.5em 0}
|
|
10
10
|
.bbrn-root .bbrn-list{margin:.5em 0;padding-left:1.25em;list-style:disc}
|
|
11
|
-
.bbrn-root .bbrn-code{font-family:ui-monospace,monospace;font-size:.85em;padding:0 4px;border-radius:4px;background:
|
|
11
|
+
.bbrn-root .bbrn-code{font-family:ui-monospace,monospace;font-size:.85em;padding:0 4px;border-radius:4px;background:color-mix(in srgb,${pt} 60%,transparent)}
|
|
12
12
|
.bbrn-root .bbrn-links{display:flex;gap:12px;flex-wrap:wrap;margin-top:8px;font-size:.85rem}
|
|
13
|
-
.bbrn-root .bbrn-link{text-decoration:underline}
|
|
14
|
-
.bbrn-root .bbrn-retry{margin-left:8px;text-decoration:underline;background:none;border:0;padding:0;color
|
|
15
|
-
}`;function
|
|
13
|
+
.bbrn-root .bbrn-link{color:${ut};text-decoration:underline}
|
|
14
|
+
.bbrn-root .bbrn-retry{margin-left:8px;text-decoration:underline;background:none;border:0;padding:0;color:${ut};cursor:pointer;font:inherit}
|
|
15
|
+
}`;function jt(e=typeof document>"u"?void 0:document){if(!e?.head||e.head.querySelector("style[data-bbrn-styles]"))return;let n=e.createElement("style");n.setAttribute("data-bbrn-styles",""),n.textContent=In,e.head.prepend(n);}function Vt(e){if(!e)return;let n={};for(let s of gt){let d=e[s];typeof d=="string"&&d.trim()&&(n[`--bbrn-${s}`]=d);}return Object.keys(n).length?n:void 0}function Yt(e){if(typeof e!="string"||/[\s\\]/.test(e))return null;if(e.startsWith("/"))return e.startsWith("//")?null:{kind:"internal",href:e};try{return new URL(e).protocol==="https:"?{kind:"external",href:e}:null}catch{return null}}function je(e,n=""){return e.map((s,d)=>{let a=`${n}${d}`;switch(s.t){case "text":return s.v;case "code":return jsx("code",{className:"bbrn-code",children:s.v},a);case "strong":return jsx("strong",{children:je(s.c,`${a}.`)},a);case "em":return jsx("em",{children:je(s.c,`${a}.`)},a);default:return null}})}function qt({ast:e}){return jsx(Fragment,{children:e.map((n,s)=>n.t==="list"?jsx("ul",{className:"bbrn-list",children:n.items.map((d,a)=>jsx("li",{children:je(d)},a))},s):n.t==="p"?jsx("p",{className:"bbrn-p",children:je(n.c)},s):null)})}var G=(...e)=>e.filter(Boolean).join(" "),Kn=useInsertionEffect??useLayoutEffect,ft=class extends Component{constructor(){super(...arguments);this.state={failed:false,keys:this.props.resetKeys};}static getDerivedStateFromError(){return {failed:true}}static getDerivedStateFromProps(s,d){return s.resetKeys.length!==d.keys.length||s.resetKeys.some((l,_)=>!Object.is(l,d.keys[_]))?{failed:false,keys:s.resetKeys}:null}componentDidCatch(){}render(){return this.state.failed?this.props.fallback:this.props.children}};function jn({endpoint:e,getToken:n,onNavigate:s,theme:d,classNames:a,components:l,timeoutMs:_}){Kn(()=>{jt();},[]);let{feed:v,error:R,loading:y,stale:h,reload:B}=ct({endpoint:e,getToken:n,timeoutMs:_}),[j,k]=useState(0),x=()=>{k(T=>T+1),B();},g=useMemo(()=>Vt(d),[d]),t=a??{},i=l?.Empty,U=l?.Link,N=T=>C=>{!s||C.defaultPrevented||C.button!==0||C.metaKey||C.ctrlKey||C.shiftKey||C.altKey||(C.preventDefault(),s(T));},z=jsxs("p",{className:G("bbrn-status",t.status),role:"alert","data-bbrn-error":R??"render_failed",children:["Release notes could not be loaded.",jsx("button",{type:"button",className:G("bbrn-retry",t.retry),onClick:x,children:"Retry"})]});return jsxs("section",{className:G("bbrn-root",t.root),style:g,"aria-label":"Release notes","aria-busy":y,"data-bbrn-audience":v?.audience,children:[y&&!v&&jsx("p",{className:G("bbrn-status",t.status),role:"status",children:"Loading release notes\u2026"}),!y&&R&&!v&&z,h&&jsxs("p",{className:G("bbrn-status",t.status),role:"status","data-bbrn-stale":"",children:["Showing the last loaded notes; they could not be refreshed.",jsx("button",{type:"button",className:G("bbrn-retry",t.retry),onClick:x,children:"Retry"})]}),v&&jsxs(ft,{resetKeys:[v,i,U,j],fallback:z,children:[v.entries.length===0&&(i?jsx(i,{}):jsxs("p",{className:G("bbrn-status",t.status),children:["No release notes yet. Submit one with ",jsx("code",{className:"bbrn-code",children:"bb release-notes submit"}),"."]})),v.entries.map(T=>jsxs("article",{className:G("bbrn-entry",t.entry),"data-entry-id":T.id,"data-source-key":T.source_key,children:[jsxs("div",{className:G("bbrn-head",t.head),children:[jsx("h2",{className:G("bbrn-title",t.title),children:T.title}),jsx("span",{className:G("bbrn-badge",t.badge),"data-bbrn-type":T.type,children:T.type}),jsx("span",{className:G("bbrn-badge",t.badge),"data-bbrn-state":T.state,children:T.state}),jsxs("span",{className:G("bbrn-meta",t.meta),children:[T.source_key," \xB7 revision ",T.revision]}),T.delivery_copy&&jsx("span",{className:G("bbrn-delivery",t.delivery),"data-bbrn-delivery":T.delivery_badge,children:T.delivery_copy})]}),jsx("div",{className:G("bbrn-body",t.body),children:jsx(qt,{ast:T.body.ast})}),T.links.length>0&&jsx("div",{className:G("bbrn-links",t.links),children:T.links.map((C,A)=>{let X=Yt(C.url);if(!X)return null;let Q=G("bbrn-link",t.link),f=C.kind??null;return U?jsx(U,{href:X.href,external:X.kind==="external",kind:f,className:Q,onClick:X.kind==="internal"&&s?N(X.href):void 0,children:C.name},A):X.kind==="external"?jsx("a",{className:Q,href:X.href,target:"_blank",rel:"noopener noreferrer","data-link-kind":f??void 0,children:C.name},A):jsx("a",{className:Q,href:X.href,onClick:N(X.href),"data-link-kind":f??void 0,children:C.name},A)})})]},T.id))]})]})}
|
|
16
|
+
export{gt as RELEASE_NOTES_TOKENS,qt as ReleaseNoteBody,jn as ReleaseNotes,En as TestRunWidget,Yt as safeHref,et as useDraggable,tt as useRealtimeRefresh,ct as useReleaseNotes,rt as useTestRun,lt as useWidgetAuth};
|
package/package.json
CHANGED