From baa0c41c63655ee1f7aad3b5707b6d77f555c4a3 Mon Sep 17 00:00:00 2001 From: Nitin Goyal Date: Mon, 23 Nov 2026 20:02:49 +0530 Subject: [PATCH 1/2] fix(approval): always tell the CLI whether to withdraw approvals code-review-bot 0.6 turns --approve-withdraw on by default and also withdraws when a new commit can't be judged (divmora/code-review-bot#22). The console only passed the flag when withdrawing was on, so "Leave it" would start withdrawing; it now passes --approve-withdraw=true or =false (older CLIs accept both). The Settings note and docs describe the new behaviour. Co-Authored-By: Claude Opus 5.5 --- docs/admin.md | 2 +- .../ui/assets/{index-CndQO-XM.js => index-BC4KGOvB.js} | 2 +- internal/admin/ui/index.html | 2 +- internal/executor/executor.go | 6 +++--- internal/executor/executor_test.go | 6 +++--- web/src/pages/Settings.tsx | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) rename internal/admin/ui/assets/{index-CndQO-XM.js => index-BC4KGOvB.js} (94%) diff --git a/docs/admin.md b/docs/admin.md index 64815a7..ffe288f 100644 --- a/docs/admin.md +++ b/docs/admin.md @@ -99,7 +99,7 @@ once to the approving admin. 5. **Executor** shows where reviews run (from the config file, read-only) and manages the review image's version, resources and, for Kubernetes, scheduling, pod labels and annotations, the CA bundle and the job TTL. Changes apply to the next review. See [deploy.md](deploy.md#settings-in-the-admin-panel). 6. **Settings → Admin sessions → Sign out after inactivity** ends a session that has made no request for that long (60 minutes by default, 0 for never; the panel's own refreshes don't count), recorded as `session.ended` with reason `idle`. **Settings → Signed-in admins** lists every admin session. Sign one out, or **Sign out everyone else** (after offboarding someone, or if a session may be compromised). Every request is also checked against the current sign-in rules and license, so an admin removed from `allowed_emails`, `allowed_domains` or `allowed_groups` (after the restart that applies the change) is signed out at once. Group membership comes from the identity provider at sign-in: a group removed there applies when the session ends (`session_ttl`) or when you sign the session out here. 7. **Review scores.** Every review the CLI scores (quality, security, maintainability, 1 to 100) keeps its scores, whether or not score labels are on. **Reviews** shows them per review, banded like the labels (80 and up, 50 to 79, below 50), filters by them ("security below 60" searches all reviews) and sorts the loaded reviews by them. With the metrics feature, it also shows the period's average scores and a trend chart; **Repositories** shows each repository's latest scores with a 30-day sparkline, and a repository's **Settings** panel charts its scores over 30 days, 12 months or all its history. Reviews stored before the upgrade get their scores from the stored result. The filters, sort, chart period and the open review are kept in the address (for example `/admin/reviews?score_kind=security&score_below=60&sort=security`, with the same names as `/admin/api/reviews`), so a reload or Back keeps the view and a filtered view can be bookmarked or shared. A review that approved the merge request on the code host is marked **✓ approved** on Reviews and on the status dashboard (or **approval withdrawn** / **approval failed**), and Reviews filters by it (`approval=approved`); this is the bot approving merge requests, set under Settings, not operator change requests. -8. **Approve merge requests** (Settings) has the bot approve a merge request whose review passes, as its token's user (or the GitHub App). Choose which findings block approval (critical; major or critical, the default; minor or above; any finding; or none, to approve whatever it found), an optional lowest score for all three scores, and whether a later review that doesn't pass withdraws the bot's approval (on by default) or leaves it. New findings, ones beyond the comment limit and ones still open from an earlier review count; questions don't. A partial or too-large review leaves the approval as it is. **Rules** turn approval on or off for a host, group or pattern (**Approve MRs**), and **Repositories** shows where it applies. A review's details show what happened ("approved", "withdrawn", "not approved"…), and a refusal from the code host shows on the review as "could not approve". It needs code-review-bot 0.5 or later (the CLI version on **Executor**). On GitLab the bot's user must be allowed to approve and can't approve its own merge requests; on GitHub, withdrawing dismisses the bot's review, which branch protection can restrict. +8. **Approve merge requests** (Settings) has the bot approve a merge request whose review passes, as its token's user (or the GitHub App). Choose which findings block approval (critical; major or critical, the default; minor or above; any finding; or none, to approve whatever it found), an optional lowest score for all three scores, and whether a later review that doesn't pass withdraws the bot's approval (on by default) or leaves it. New findings, ones beyond the comment limit and ones still open from an earlier review count; questions don't. A review that can't decide (partial, too large) of a new commit also withdraws the bot's approval when withdrawing is on (code-review-bot 0.6 or later), so an approval never carries over to code that wasn't fully reviewed; a re-review of the same commit leaves it. The console always tells the CLI which you chose. **Rules** turn approval on or off for a host, group or pattern (**Approve MRs**), and **Repositories** shows where it applies. A review's details show what happened ("approved", "withdrawn", "not approved"…), and a refusal from the code host shows on the review as "could not approve". It needs code-review-bot 0.5 or later (the CLI version on **Executor**). On GitLab the bot's user must be allowed to approve and can't approve its own merge requests; on GitHub, withdrawing dismisses the bot's review, which branch protection can restrict. 9. **Impact** shows what the console has done for this installation, from its own database only (nothing leaves it): merge requests reviewed and review runs, findings raised by severity, security findings, the median time to first review (from the webhook to the first review's comments, including the wait after a push), active repositories, comments posted and average scores. Questions aren't counted as findings. The last 30 days are free; with the metrics feature, choose 90 days, 12 months or all history, see the trends, findings by category, the top repositories by reviews and by findings, and **Export CSV** or **Export JSON** for reports (exports are audited as `impact.export`). Periods are whole UTC days or months. The numbers come from rollups kept for good, like the review charts; on upgrade they are filled in from the reviews still stored. **Approvals by the bot** counts merge requests the bot approved on the code host (a review that approved; one already approved isn't counted again), and is in the exports as `approvals_by_the_bot`. The numbers link to **Reviews** with the matching filters and period: merge requests reviewed, findings raised (`severity=any`), security findings (`category=security`), each severity and category, and each top repository. Reviews can also be filtered by finding severity and category directly; `/admin/api/reviews` takes `severity` (or `any`) and `category`, counted the way Impact counts them (questions aren't findings). How many findings were acted on (fixed, resolved or dismissed) isn't tracked yet and isn't shown. Periods are whole UTC days or months; the label ends on the last day (or month) included, and the API and exports give that day as `through` next to the exclusive end (`to`, `to_exclusive` in the CSV). 10. **Webhooks** shows every delivery. A delivery whose body was already received (a retry, an event arriving through two GitLab hooks, a replay) shows as a duplicate and is not processed again, for 7 days. Redelivering an old webhook from the code host therefore does nothing; use **Review now** on the Repositories page instead. The project and outcome filters are kept in the address. 11. **Audit log** lists sign-ins, denied sign-ins, sign-outs and every change, newest first, with who made it and from which address and browser. Each change shows only the fields that changed (old → new), with the raw entry one click away; secret changes are named without their values (`token:changed`, `signing_tokens:+1`). Filter by who, action (`host.*` matches every host action), target, a text search and dates; **Older entries** pages back through everything, and **Export CSV** or **Export JSON Lines** downloads the filtered view (up to 100,000 entries; exports are audited too). The applied filter is kept in the address (`/admin/audit?action=host.*`). Times are shown as `23 Nov 2026, 09:33:38 IST` in your browser's time zone, with UTC on hover. diff --git a/internal/admin/ui/assets/index-CndQO-XM.js b/internal/admin/ui/assets/index-BC4KGOvB.js similarity index 94% rename from internal/admin/ui/assets/index-CndQO-XM.js rename to internal/admin/ui/assets/index-BC4KGOvB.js index 82007c8..588477e 100644 --- a/internal/admin/ui/assets/index-CndQO-XM.js +++ b/internal/admin/ui/assets/index-BC4KGOvB.js @@ -330,6 +330,6 @@ Error generating stack: `+p.message+` .block-interactivity-`.concat(t,` {pointer-events: none;} .allow-interactivity-`).concat(t,` {pointer-events: all;} `)},qC=0,Zo=[];function YC(t){var o=m.useRef([]),s=m.useRef([0,0]),a=m.useRef(),l=m.useState(qC++)[0],u=m.useState(Xx)[0],d=m.useRef(t);m.useEffect(function(){d.current=t},[t]),m.useEffect(function(){if(t.inert){document.body.classList.add("block-interactivity-".concat(l));var b=vC([t.lockRef.current],(t.shards||[]).map(fg),!0).filter(Boolean);return b.forEach(function(j){return j.classList.add("allow-interactivity-".concat(l))}),function(){document.body.classList.remove("block-interactivity-".concat(l)),b.forEach(function(j){return j.classList.remove("allow-interactivity-".concat(l))})}}},[t.inert,t.lockRef.current,t.shards]);var h=m.useCallback(function(b,j){if("touches"in b&&b.touches.length===2||b.type==="wheel"&&b.ctrlKey)return!d.current.allowPinchZoom;var S=Fa(b),R=s.current,N="deltaX"in b?b.deltaX:R[0]-S[0],E="deltaY"in b?b.deltaY:R[1]-S[1],P,I=b.target,F=Math.abs(N)>Math.abs(E)?"h":"v";if("touches"in b&&F==="h"&&I.type==="range")return!1;var A=window.getSelection(),q=A&&A.anchorNode,B=q?q===I||q.contains(I):!1;if(B)return!1;var z=ug(F,I);if(!z)return!0;if(z?P=F:(P=F==="v"?"h":"v",z=ug(F,I)),!z)return!1;if(!a.current&&"changedTouches"in b&&(N||E)&&(a.current=P),!P)return!0;var Z=a.current||P;return HC(Z,j,b,Z==="h"?N:E)},[]),g=m.useCallback(function(b){var j=b;if(!(!Zo.length||Zo[Zo.length-1]!==u)){var S="deltaY"in j?dg(j):Fa(j),R=o.current.filter(function(P){return P.name===j.type&&(P.target===j.target||j.target===P.shadowParent)&&GC(P.delta,S)})[0];if(R&&R.should){j.cancelable&&j.preventDefault();return}if(!R){var N=(d.current.shards||[]).map(fg).filter(Boolean).filter(function(P){return P.contains(j.target)}),E=N.length>0?h(j,N[0]):!d.current.noIsolation;E&&j.cancelable&&j.preventDefault()}}},[]),v=m.useCallback(function(b,j,S,R){var N={name:b,delta:j,target:S,should:R,shadowParent:QC(S)};o.current.push(N),setTimeout(function(){o.current=o.current.filter(function(E){return E!==N})},1)},[]),w=m.useCallback(function(b){s.current=Fa(b),a.current=void 0},[]),x=m.useCallback(function(b){v(b.type,dg(b),b.target,h(b,t.lockRef.current))},[]),C=m.useCallback(function(b){v(b.type,Fa(b),b.target,h(b,t.lockRef.current))},[]);m.useEffect(function(){return Zo.push(u),t.setCallbacks({onScrollCapture:x,onWheelCapture:x,onTouchMoveCapture:C}),document.addEventListener("wheel",g,Jo),document.addEventListener("touchmove",g,Jo),document.addEventListener("touchstart",w,Jo),function(){Zo=Zo.filter(function(b){return b!==u}),document.removeEventListener("wheel",g,Jo),document.removeEventListener("touchmove",g,Jo),document.removeEventListener("touchstart",w,Jo)}},[]);var y=t.removeScrollBar,_=t.inert;return m.createElement(m.Fragment,null,_?m.createElement(u,{styles:KC(l)}):null,y?m.createElement(zC,{noRelative:t.noRelative,gapMode:t.gapMode}):null)}function QC(t){for(var o=null;t!==null;)t instanceof ShadowRoot&&(o=t.host,t=t.host),t=t.parentNode;return o}const XC=_C(Qx,YC);var qd=m.forwardRef(function(t,o){return m.createElement(xl,Dn({},t,{ref:o,sideCar:XC}))});qd.classNames=xl.classNames;var JC=function(t){if(typeof document>"u")return null;var o=Array.isArray(t)?t[0]:t;return o.ownerDocument.body},es=new WeakMap,$a=new WeakMap,Ua={},Mu=0,ty=function(t){return t&&(t.host||ty(t.parentNode))},ZC=function(t,o){return o.map(function(s){if(t.contains(s))return s;var a=ty(s);return a&&t.contains(a)?a:(console.error("aria-hidden",s,"in not contained inside",t,". Doing nothing"),null)}).filter(function(s){return!!s})},eS=function(t,o,s,a){var l=ZC(o,Array.isArray(t)?t:[t]);Ua[s]||(Ua[s]=new WeakMap);var u=Ua[s],d=[],h=new Set,g=new Set(l),v=function(x){!x||h.has(x)||(h.add(x),v(x.parentNode))};l.forEach(v);var w=function(x){!x||g.has(x)||Array.prototype.forEach.call(x.children,function(C){if(h.has(C))w(C);else try{var y=C.getAttribute(a),_=y!==null&&y!=="false",b=(es.get(C)||0)+1,j=(u.get(C)||0)+1;es.set(C,b),u.set(C,j),d.push(C),b===1&&_&&$a.set(C,!0),j===1&&C.setAttribute(s,"true"),_||C.setAttribute(a,"true")}catch(S){console.error("aria-hidden: cannot operate on ",C,S)}})};return w(o),h.clear(),Mu++,function(){d.forEach(function(x){var C=es.get(x)-1,y=u.get(x)-1;es.set(x,C),u.set(x,y),C||($a.has(x)||x.removeAttribute(a),$a.delete(x)),y||x.removeAttribute(s)}),Mu--,Mu||(es=new WeakMap,es=new WeakMap,$a=new WeakMap,Ua={})}},ny=function(t,o,s){s===void 0&&(s="data-aria-hidden");var a=Array.from(Array.isArray(t)?t:[t]),l=JC(t);return l?(a.push.apply(a,Array.from(l.querySelectorAll("[aria-live], script"))),eS(a,l,s,"aria-hidden")):function(){return null}},tS=Object.defineProperty,Ut=(t,o)=>tS(t,"name",{value:o,configurable:!0}),Yd="Dialog",[ry,oy]=jn(Yd),[nS,kn]=ry(Yd),Qd=Ut(t=>{const{__scopeDialog:o,children:s,open:a,defaultOpen:l,onOpenChange:u,modal:d=!0}=t,h=m.useRef(null),g=m.useRef(null),{nodes:v,registry:w}=Wd(),[x,C]=gs({prop:a,defaultProp:l??!1,onChange:u,caller:Yd}),[y,_]=m.useState(0),[b,j]=m.useState(0);return r.jsx(nS,{scope:o,triggerRef:h,contentRef:g,contentId:Gr(),titleId:Gr(),descriptionId:Gr(),titlePresent:y>0,descriptionPresent:b>0,setTitleCount:_,setDescriptionCount:j,open:x,onOpenChange:C,onOpenToggle:m.useCallback(()=>C(S=>!S),[C]),modal:d,branchNodes:v,branchRegistry:w,children:s})},"Dialog"),rS="DialogTrigger",oS=m.forwardRef(Ut(function(o,s){const{__scopeDialog:a,...l}=o,u=kn(rS,a),d=Fe(s,u.triggerRef);return r.jsx(Ue.button,{type:"button","aria-haspopup":"dialog","aria-expanded":u.open,"aria-controls":u.open?u.contentId:void 0,"data-state":yl(u.open),...l,ref:d,onClick:Pe(o.onClick,u.onOpenToggle)})},"DialogTrigger")),sy="DialogPortal",[sS,iy]=ry(sy,{forceMount:void 0}),Xd=Ut(t=>{const{__scopeDialog:o,forceMount:s,children:a,container:l}=t,u=kn(sy,o);return r.jsx(sS,{scope:o,forceMount:s,children:m.Children.map(a,d=>r.jsx(ur,{present:s||u.open,children:r.jsx(Gd,{asChild:!0,container:l,children:d})}))})},"DialogPortal"),hd="DialogOverlay",Jd=m.forwardRef(Ut(function(o,s){const a=iy(hd,o.__scopeDialog),{forceMount:l=a.forceMount,...u}=o,d=kn(hd,o.__scopeDialog);return d.modal?r.jsx(ur,{present:l||d.open,children:r.jsx(aS,{...u,ref:s})}):null},"DialogOverlay")),iS=or("DialogOverlay.RemoveScroll"),aS=m.forwardRef(Ut(function(o,s){const{__scopeDialog:a,...l}=o,u=kn(hd,a),d=Ix(),h=Fe(s,d);return r.jsx(qd,{as:iS,allowPinchZoom:!0,shards:m.useMemo(()=>[u.contentRef,...u.branchNodes.map(g=>({current:g}))],[u.contentRef,u.branchNodes]),children:r.jsx(Ue.div,{"data-state":yl(u.open),...l,ref:h,style:{pointerEvents:"auto",...l.style}})})},"DialogOverlayImpl")),fi="DialogContent",Zd=m.forwardRef(Ut(function(o,s){const a=iy(fi,o.__scopeDialog),{forceMount:l=a.forceMount,...u}=o,d=kn(fi,o.__scopeDialog);return r.jsx(ur,{present:l||d.open,children:d.modal?r.jsx(lS,{...u,ref:s}):r.jsx(cS,{...u,ref:s})})},"DialogContent")),lS=m.forwardRef(Ut(function(o,s){const a=kn(fi,o.__scopeDialog),l=m.useRef(null),u=Fe(s,a.contentRef,l);return m.useEffect(()=>{const d=l.current;if(d)return ny(d)},[]),r.jsx(ay,{...o,ref:u,trapFocus:a.open,disableOutsidePointerEvents:a.open,onCloseAutoFocus:Pe(o.onCloseAutoFocus,d=>{var h;d.preventDefault(),(h=a.triggerRef.current)==null||h.focus()}),onPointerDownOutside:Pe(o.onPointerDownOutside,d=>{const h=d.detail.originalEvent,g=h.button===0&&h.ctrlKey===!0;(h.button===2||g)&&d.preventDefault()}),onFocusOutside:Pe(o.onFocusOutside,d=>d.preventDefault())})},"DialogContentModal")),cS=m.forwardRef(Ut(function(o,s){const a=kn(fi,o.__scopeDialog),l=m.useRef(!1),u=m.useRef(!1);return r.jsx(ay,{...o,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:d=>{var h,g;(h=o.onCloseAutoFocus)==null||h.call(o,d),d.defaultPrevented||(l.current||(g=a.triggerRef.current)==null||g.focus(),d.preventDefault()),l.current=!1,u.current=!1},onInteractOutside:d=>{var v,w;(v=o.onInteractOutside)==null||v.call(o,d),d.defaultPrevented||(l.current=!0,d.detail.originalEvent.type==="pointerdown"&&(u.current=!0));const h=d.target;((w=a.triggerRef.current)==null?void 0:w.contains(h))&&d.preventDefault(),d.detail.originalEvent.type==="focusin"&&u.current&&d.preventDefault()}})},"DialogContentNonModal")),ay=m.forwardRef(Ut(function(o,s){const{__scopeDialog:a,trapFocus:l,onOpenAutoFocus:u,onCloseAutoFocus:d,"aria-describedby":h,children:g,...v}=o,w=kn(fi,a);return vl(),r.jsx(Bd,{registry:w.branchRegistry,children:r.jsx($x,{asChild:!0,loop:!0,trapped:l,branches:w.branchNodes,onMountAutoFocus:u,onUnmountAutoFocus:d,children:r.jsx($d,{role:"dialog",id:w.contentId,"aria-labelledby":w.titlePresent?w.titleId:void 0,"aria-describedby":w.descriptionPresent?ly(h,w.descriptionId):h,"data-state":yl(w.open),...v,ref:s,deferPointerDownOutside:!0,onDismiss:()=>w.onOpenChange(!1),children:g})})})},"DialogContentImpl")),ef=m.forwardRef(Ut(function(o,s){const{__scopeDialog:a,...l}=o,u=kn("DialogTitle",a),{setTitleCount:d}=u;return Rt(()=>(d(h=>h+1),()=>d(h=>h-1)),[d]),r.jsx(Ue.h2,{id:u.titleId,...l,ref:s})},"DialogTitle")),tf=m.forwardRef(Ut(function(o,s){const{__scopeDialog:a,...l}=o,u=kn("DialogDescription",a),{setDescriptionCount:d}=u;return Rt(()=>(d(h=>h+1),()=>d(h=>h-1)),[d]),r.jsx(Ue.p,{id:u.descriptionId,...l,ref:s})},"DialogDescription")),uS="DialogClose",xi=m.forwardRef(Ut(function(o,s){const{__scopeDialog:a,...l}=o,u=kn(uS,a);return r.jsx(Ue.button,{type:"button",...l,ref:s,onClick:Pe(o.onClick,()=>u.onOpenChange(!1))})},"DialogClose"));function ly(...t){const o=new Set;for(const s of t)if(typeof s=="string")for(const a of String(s).trim().split(/\s+/))a&&o.add(a);return o.size>0?Array.from(o).join(" "):void 0}Ut(ly,"concatAriaDescribedby");function yl(t){return t?"open":"closed"}Ut(yl,"getState");var dS=Object.defineProperty,dr=(t,o)=>dS(t,"name",{value:o,configurable:!0}),fS="AlertDialog",[hS,AR]=jn(fS,[oy]),fr=oy(),pS=dr(t=>{const{__scopeAlertDialog:o,...s}=t,a=fr(o);return r.jsx(Qd,{...a,...s,modal:!0})},"AlertDialog");m.forwardRef(dr(function(o,s){const{__scopeAlertDialog:a,...l}=o,u=fr(a);return r.jsx(oS,{...u,...l,ref:s})},"AlertDialogTrigger"));var mS=dr(t=>{const{__scopeAlertDialog:o,...s}=t,a=fr(o);return r.jsx(Xd,{...a,...s})},"AlertDialogPortal"),gS=m.forwardRef(dr(function(o,s){const{__scopeAlertDialog:a,...l}=o,u=fr(a);return r.jsx(Jd,{...u,...l,ref:s})},"AlertDialogOverlay")),vS="AlertDialogContent",[xS,yS]=hS(vS),wS=m.forwardRef(dr(function(o,s){const{__scopeAlertDialog:a,children:l,...u}=o,d=fr(a),h=m.useRef(null),g=Fe(s,h),v=m.useRef(null);return r.jsx(xS,{scope:a,cancelRef:v,children:r.jsx(Zd,{role:"alertdialog",...d,...u,ref:g,onOpenAutoFocus:Pe(u.onOpenAutoFocus,w=>{var x;w.preventDefault(),(x=v.current)==null||x.focus({preventScroll:!0})}),onPointerDownOutside:w=>w.preventDefault(),onInteractOutside:w=>w.preventDefault(),children:l})})},"AlertDialogContent")),bS=m.forwardRef(dr(function(o,s){const{__scopeAlertDialog:a,...l}=o,u=fr(a);return r.jsx(ef,{...u,...l,ref:s})},"AlertDialogTitle")),jS=m.forwardRef(dr(function(o,s){const{__scopeAlertDialog:a,...l}=o,u=fr(a);return r.jsx(tf,{...u,...l,ref:s})},"AlertDialogDescription")),kS=m.forwardRef(dr(function(o,s){const{__scopeAlertDialog:a,...l}=o,u=fr(a);return r.jsx(xi,{...u,...l,ref:s})},"AlertDialogAction")),CS="AlertDialogCancel",SS=m.forwardRef(dr(function(o,s){const{__scopeAlertDialog:a,...l}=o,{cancelRef:u}=yS(CS,a),d=fr(a),h=Fe(s,u);return r.jsx(xi,{...d,...l,ref:h})},"AlertDialogCancel")),_S=Object.defineProperty,NS=(t,o)=>_S(t,"name",{value:o,configurable:!0});function nf(t){const[o,s]=m.useState(void 0);return Rt(()=>{if(t){s({width:t.offsetWidth,height:t.offsetHeight});let a=0;const l=new ResizeObserver(u=>{if(!Array.isArray(u)||!u.length)return;const d=u[0];window.cancelAnimationFrame(a),a=window.requestAnimationFrame(()=>{let h,g;if("borderBoxSize"in d){const v=d.borderBoxSize,w=Array.isArray(v)?v[0]:v;h=w.inlineSize,g=w.blockSize}else h=t.offsetWidth,g=t.offsetHeight;s({width:h,height:g})})});return l.observe(t,{box:"border-box"}),()=>{window.cancelAnimationFrame(a),l.unobserve(t)}}else s(void 0)},[t]),o}NS(nf,"useSize");var ES=Object.defineProperty,ir=(t,o)=>ES(t,"name",{value:o,configurable:!0}),rf="Checkbox",[RS,LR]=jn(rf),[PS,of]=RS(rf);function cy(t){const{__scopeCheckbox:o,checked:s,children:a,defaultChecked:l,disabled:u,form:d,name:h,onCheckedChange:g,required:v,value:w="on",internal_do_not_use_render:x}=t,[C,y]=gs({prop:s,defaultProp:l??!1,onChange:g,caller:rf}),[_,b]=m.useState(null),[j,S]=m.useState(null),[R,N]=m.useState(null),E=_?!!d||!!_.closest("form"):!0,P={checked:C,disabled:u,setChecked:y,control:_,setControl:b,name:h,form:d,value:w,userClick:R,onUserClick:N,required:v,defaultChecked:sn(l)?!1:l,isFormControl:E,bubbleInput:j,setBubbleInput:S};return r.jsx(PS,{scope:o,...P,children:uy(x)?x(P):a})}ir(cy,"CheckboxProvider");var TS="CheckboxTrigger",DS=m.forwardRef(ir(function({__scopeCheckbox:o,onKeyDown:s,onClick:a,...l},u){const{control:d,value:h,disabled:g,checked:v,required:w,setControl:x,setChecked:C,onUserClick:y,isFormControl:_,bubbleInput:b}=of(TS,o),j=Fe(u,x),S=m.useRef(v);return m.useEffect(()=>{const R=d==null?void 0:d.form;if(R){const N=ir(()=>C(S.current),"reset");return R.addEventListener("reset",N),()=>R.removeEventListener("reset",N)}},[d,C]),r.jsx(Ue.button,{type:"button",role:"checkbox","aria-checked":sn(v)?"mixed":v,"aria-required":w,"data-state":sf(v),"data-disabled":g?"":void 0,disabled:g,value:h,...l,ref:j,onKeyDown:Pe(s,R=>{R.key==="Enter"&&R.preventDefault()}),onClick:Pe(a,R=>{const N=R.isPropagationStopped();y({requestedChecked:sn(v)?!0:!v,hasConsumerStoppedPropagation:N}),C(E=>sn(E)?!0:!E),b&&_&&(N||R.stopPropagation())})})},"CheckboxTrigger")),OS=m.forwardRef(ir(function(o,s){const{__scopeCheckbox:a,name:l,checked:u,defaultChecked:d,required:h,disabled:g,value:v,onCheckedChange:w,form:x,...C}=o;return r.jsx(cy,{__scopeCheckbox:a,checked:u,defaultChecked:d,disabled:g,required:h,onCheckedChange:w,name:l,form:x,value:v,internal_do_not_use_render:({isFormControl:y})=>r.jsxs(r.Fragment,{children:[r.jsx(DS,{...C,ref:s,__scopeCheckbox:a}),y&&r.jsx(IS,{__scopeCheckbox:a})]})})},"Checkbox")),MS="CheckboxIndicator",AS=m.forwardRef(ir(function(o,s){const{__scopeCheckbox:a,forceMount:l,...u}=o,d=of(MS,a);return r.jsx(ur,{present:l||sn(d.checked)||d.checked===!0,children:r.jsx(Ue.span,{"data-state":sf(d.checked),"data-disabled":d.disabled?"":void 0,...u,ref:s,style:{pointerEvents:"none",...o.style}})})},"CheckboxIndicator")),LS="CheckboxBubbleInput",IS=m.forwardRef(ir(function({__scopeCheckbox:o,onClick:s,...a},l){const{control:u,userClick:d,checked:h,defaultChecked:g,required:v,disabled:w,name:x,value:C,form:y,bubbleInput:_,setBubbleInput:b}=of(LS,o),j=Fe(l,b),S=nf(u),R=m.useRef(!1),N=m.useRef(h),E=m.useRef(d),P=m.useRef(null);m.useEffect(()=>{const F=_;if(!F)return;const A=window.HTMLInputElement.prototype,B=Object.getOwnPropertyDescriptor(A,"checked").set;if(!B)return;const z=N.current!==h;N.current=h;const Z=d!==null&&d!==E.current;if(E.current=d,Z)P.current=z?null:d,z&&(F.indeterminate=sn(h),B.call(F,sn(h)?!1:h)),F.dispatchEvent(new Event("click",{bubbles:!d.hasConsumerStoppedPropagation}));else if(z){const se=P.current;P.current=null;const he=(se==null?void 0:se.requestedChecked)===h;R.current=!0,F.indeterminate=sn(h),B.call(F,sn(h)?!1:h),F.dispatchEvent(new Event("click",{bubbles:!(he&&se.hasConsumerStoppedPropagation)})),R.current=!1}},[_,h,d]);const I=m.useRef(sn(h)?!1:h);return r.jsx(Ue.input,{type:"checkbox","aria-hidden":!0,defaultChecked:g??I.current,required:v,disabled:w,name:x,value:C,form:y,...a,tabIndex:-1,ref:j,onClick:Pe(s,F=>{R.current&&F.stopPropagation()}),style:{...a.style,...S,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})},"CheckboxBubbleInput"));function uy(t){return typeof t=="function"}ir(uy,"isFunction");function sn(t){return t==="indeterminate"}ir(sn,"isIndeterminate");function sf(t){return sn(t)?"indeterminate":t?"checked":"unchecked"}ir(sf,"getState");const zS=["top","right","bottom","left"],Yr=Math.min,tr=Math.max,nl=Math.round,Ba=Math.floor,nr=t=>({x:t,y:t}),FS={left:"right",right:"left",bottom:"top",top:"bottom"};function dy(t,o,s){return tr(t,Yr(o,s))}function ar(t,o){return typeof t=="function"?t(o):t}function Qr(t){return t.split("-")[0]}function vs(t){return t.split("-")[1]}function af(t){return t==="x"?"y":"x"}function lf(t){return t==="y"?"height":"width"}function On(t){const o=t[0];return o==="t"||o==="b"?"y":"x"}function cf(t){return af(On(t))}function $S(t,o,s){s===void 0&&(s=!1);const a=vs(t),l=cf(t),u=lf(l);let d=l==="x"?a===(s?"end":"start")?"right":"left":a==="start"?"bottom":"top";return o.reference[u]>o.floating[u]&&(d=rl(d)),[d,rl(d)]}function US(t){const o=rl(t);return[pd(t),o,pd(o)]}function pd(t){return t.includes("start")?t.replace("start","end"):t.replace("end","start")}const hg=["left","right"],pg=["right","left"],BS=["top","bottom"],WS=["bottom","top"];function VS(t,o,s){switch(t){case"top":case"bottom":return s?o?pg:hg:o?hg:pg;case"left":case"right":return o?BS:WS;default:return[]}}function HS(t,o,s,a){const l=vs(t);let u=VS(Qr(t),s==="start",a);return l&&(u=u.map(d=>d+"-"+l),o&&(u=u.concat(u.map(pd)))),u}function rl(t){const o=Qr(t);return FS[o]+t.slice(o.length)}function GS(t){var o,s,a,l;return{top:(o=t.top)!=null?o:0,right:(s=t.right)!=null?s:0,bottom:(a=t.bottom)!=null?a:0,left:(l=t.left)!=null?l:0}}function fy(t){return typeof t!="number"?GS(t):{top:t,right:t,bottom:t,left:t}}function ol(t){const{x:o,y:s,width:a,height:l}=t;return{width:a,height:l,top:s,left:o,right:o+a,bottom:s+l,x:o,y:s}}function mg(t,o,s){let{reference:a,floating:l}=t;const u=On(o),d=cf(o),h=lf(d),g=Qr(o),v=u==="y",w=a.x+a.width/2-l.width/2,x=a.y+a.height/2-l.height/2,C=a[h]/2-l[h]/2;let y;switch(g){case"top":y={x:w,y:a.y-l.height};break;case"bottom":y={x:w,y:a.y+a.height};break;case"right":y={x:a.x+a.width,y:x};break;case"left":y={x:a.x-l.width,y:x};break;default:y={x:a.x,y:a.y}}const _=vs(o);return _&&(y[d]+=C*(_==="end"?1:-1)*(s&&v?-1:1)),y}async function KS(t,o){var s;o===void 0&&(o={});const{x:a,y:l,platform:u,rects:d,elements:h,strategy:g}=t,{boundary:v="clippingAncestors",rootBoundary:w="viewport",elementContext:x="floating",altBoundary:C=!1,padding:y=0}=ar(o,t),_=fy(y),j=h[C?x==="floating"?"reference":"floating":x],S=ol(await u.getClippingRect({element:(s=await(u.isElement==null?void 0:u.isElement(j)))==null||s?j:j.contextElement||await(u.getDocumentElement==null?void 0:u.getDocumentElement(h.floating)),boundary:v,rootBoundary:w,strategy:g})),R=x==="floating"?{x:a,y:l,width:d.floating.width,height:d.floating.height}:d.reference,N=await(u.getOffsetParent==null?void 0:u.getOffsetParent(h.floating)),E=await(u.isElement==null?void 0:u.isElement(N))&&await(u.getScale==null?void 0:u.getScale(N))||{x:1,y:1},P=ol(u.convertOffsetParentRelativeRectToViewportRelativeRect?await u.convertOffsetParentRelativeRectToViewportRelativeRect({elements:h,rect:R,offsetParent:N,strategy:g}):R);return{top:(S.top-P.top+_.top)/E.y,bottom:(P.bottom-S.bottom+_.bottom)/E.y,left:(S.left-P.left+_.left)/E.x,right:(P.right-S.right+_.right)/E.x}}const qS=50,YS=async(t,o,s)=>{const{placement:a="bottom",strategy:l="absolute",middleware:u=[],platform:d}=s,h=d.detectOverflow?d:{...d,detectOverflow:KS},g=await(d.isRTL==null?void 0:d.isRTL(o));let v=await d.getElementRects({reference:t,floating:o,strategy:l}),{x:w,y:x}=mg(v,a,g),C=a,y=0;const _={};for(let b=0;b({name:"arrow",options:t,async fn(o){const{x:s,y:a,placement:l,rects:u,platform:d,elements:h,middlewareData:g}=o,{element:v,padding:w=0}=ar(t,o)||{};if(v==null)return{};const x=fy(w),C={x:s,y:a},y=cf(l),_=lf(y),b=await d.getDimensions(v),j=y==="y",S=j?"top":"left",R=j?"bottom":"right",N=j?"clientHeight":"clientWidth",E=u.reference[_]+u.reference[y]-C[y]-u.floating[_],P=C[y]-u.reference[y],I=await(d.getOffsetParent==null?void 0:d.getOffsetParent(v));let F=I?I[N]:0;(!F||!await(d.isElement==null?void 0:d.isElement(I)))&&(F=h.floating[N]||u.floating[_]);const A=E/2-P/2,q=F/2-b[_]/2-1,B=Yr(x[S],q),z=Yr(x[R],q),Z=F-b[_]-z,se=F/2-b[_]/2+A,he=dy(B,se,Z),ye=!g.arrow&&vs(l)!=null&&se!==he&&u.reference[_]/2-(sehe<=0)){var z,Z;const he=(((z=u.flip)==null?void 0:z.index)||0)+1,ye=F[he];if(ye&&(!(x==="alignment"?R!==On(ye):!1)||B.every(H=>On(H.placement)===R?H.overflows[0]>0:!0)))return{data:{index:he,overflows:B},reset:{placement:ye}};let ae=(Z=B.filter(oe=>oe.overflows[0]<=0).sort((oe,H)=>oe.overflows[1]-H.overflows[1])[0])==null?void 0:Z.placement;if(!ae)switch(y){case"bestFit":{var se;const oe=(se=B.filter(H=>{if(I){const J=On(H.placement);return J===R||J==="y"}return!0}).map(H=>[H.placement,H.overflows.filter(J=>J>0).reduce((J,$)=>J+$,0)]).sort((H,J)=>H[1]-J[1])[0])==null?void 0:se[0];oe&&(ae=oe);break}case"initialPlacement":ae=h;break}if(l!==ae)return{reset:{placement:ae}}}return{}}}};function gg(t,o){return{top:t.top-o.height,right:t.right-o.width,bottom:t.bottom-o.height,left:t.left-o.width}}function vg(t){return zS.some(o=>t[o]>=0)}const JS=function(t){return t===void 0&&(t={}),{name:"hide",options:t,async fn(o){const{rects:s,platform:a}=o,{strategy:l="referenceHidden",...u}=ar(t,o);switch(l){case"referenceHidden":{const d=await a.detectOverflow(o,{...u,elementContext:"reference"}),h=gg(d,s.reference);return{data:{referenceHiddenOffsets:h,referenceHidden:vg(h)}}}case"escaped":{const d=await a.detectOverflow(o,{...u,altBoundary:!0}),h=gg(d,s.floating);return{data:{escapedOffsets:h,escaped:vg(h)}}}default:return{}}}}},hy=new Set(["left","top"]);async function ZS(t,o){const{placement:s,platform:a,elements:l}=t,u=await(a.isRTL==null?void 0:a.isRTL(l.floating)),d=Qr(s),h=vs(s),g=On(s)==="y",v=hy.has(d)?-1:1,w=u&&g?-1:1,x=ar(o,t);let{mainAxis:C,crossAxis:y,alignmentAxis:_}=typeof x=="number"?{mainAxis:x,crossAxis:0,alignmentAxis:null}:{mainAxis:x.mainAxis||0,crossAxis:x.crossAxis||0,alignmentAxis:x.alignmentAxis};return h&&typeof _=="number"&&(y=h==="end"?_*-1:_),g?{x:y*w,y:C*v}:{x:C*v,y:y*w}}const e_=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(o){var s,a;const{x:l,y:u,placement:d,middlewareData:h}=o,g=await ZS(o,t);return d===((s=h.offset)==null?void 0:s.placement)&&(a=h.arrow)!=null&&a.alignmentOffset?{}:{x:l+g.x,y:u+g.y,data:{...g,placement:d}}}}},t_=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(o){const{x:s,y:a,placement:l,platform:u}=o,{mainAxis:d=!0,crossAxis:h=!1,limiter:g={fn:R=>{let{x:N,y:E}=R;return{x:N,y:E}}},...v}=ar(t,o),w={x:s,y:a},x=await u.detectOverflow(o,v),C=On(l),y=af(C);let _=w[y],b=w[C];const j=(R,N)=>dy(N+x[R==="y"?"top":"left"],N,N-x[R==="y"?"bottom":"right"]);d&&(_=j(y,_)),h&&(b=j(C,b));const S=g.fn({...o,[y]:_,[C]:b});return{...S,data:{x:S.x-s,y:S.y-a,enabled:{[y]:d,[C]:h}}}}}},n_=function(t){return t===void 0&&(t={}),{options:t,fn(o){var s,a;const{x:l,y:u,placement:d,rects:h,middlewareData:g}=o,{offset:v=0,mainAxis:w=!0,crossAxis:x=!0}=ar(t,o),C={x:l,y:u},y=On(d),_=af(y);let b=C[_],j=C[y];const S=ar(v,o),R=typeof S=="number"?{mainAxis:S,crossAxis:0}:{mainAxis:(s=S.mainAxis)!=null?s:0,crossAxis:(a=S.crossAxis)!=null?a:0};if(w){const P=_==="y"?"height":"width",I=h.reference[_]-h.floating[P]+R.mainAxis,F=h.reference[_]+h.reference[P]-R.mainAxis;bF&&(b=F)}if(x){var N,E;const P=_==="y"?"width":"height",I=hy.has(Qr(d)),F=h.reference[y]-h.floating[P]+(I&&((N=g.offset)==null?void 0:N[y])||0)+(I?0:R.crossAxis),A=h.reference[y]+h.reference[P]+(I?0:((E=g.offset)==null?void 0:E[y])||0)-(I?R.crossAxis:0);jA&&(j=A)}return{[_]:b,[y]:j}}}},r_=function(t){return t===void 0&&(t={}),{name:"size",options:t,async fn(o){const{placement:s,rects:a,platform:l,elements:u}=o,{apply:d=()=>{},...h}=ar(t,o),g=await l.detectOverflow(o,h),v=Qr(s),w=vs(s),x=On(s)==="y",{width:C,height:y}=a.floating;let _,b;v==="top"||v==="bottom"?(_=v,b=w===(await(l.isRTL==null?void 0:l.isRTL(u.floating))?"start":"end")?"left":"right"):(b=v,_=w==="end"?"top":"bottom");const j=y-g.top-g.bottom,S=C-g.left-g.right,R=Yr(y-g[_],j),N=Yr(C-g[b],S),E=o.middlewareData.shift,P=!E;let I=R,F=N;E!=null&&E.enabled.x&&(F=S),E!=null&&E.enabled.y&&(I=j),P&&!w&&(x?F=C-2*tr(g.left,g.right):I=y-2*tr(g.top,g.bottom)),await d({...o,availableWidth:F,availableHeight:I});const A=await l.getDimensions(u.floating);return C!==A.width||y!==A.height?{reset:{rects:!0}}:{}}}};function wl(){return typeof window<"u"}function xs(t){return py(t)?(t.nodeName||"").toLowerCase():"#document"}function $t(t){var o;return(t==null||(o=t.ownerDocument)==null?void 0:o.defaultView)||window}function hr(t){var o;return(o=(py(t)?t.ownerDocument:t.document)||window.document)==null?void 0:o.documentElement}function py(t){return wl()?t instanceof Node||t instanceof $t(t).Node:!1}function An(t){return wl()?t instanceof Element||t instanceof $t(t).Element:!1}function eo(t){return wl()?t instanceof HTMLElement||t instanceof $t(t).HTMLElement:!1}function xg(t){return!wl()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof $t(t).ShadowRoot}function bl(t){const{overflow:o,overflowX:s,overflowY:a,display:l}=Ln(t);return/auto|scroll|overlay|hidden|clip/.test(o+a+s)&&l!=="inline"&&l!=="contents"}function o_(t){return/^(table|td|th)$/.test(xs(t))}function jl(t){try{if(t.matches(":popover-open"))return!0}catch{}try{return t.matches(":modal")}catch{return!1}}const s_=/transform|translate|scale|rotate|perspective|filter/,i_=/paint|layout|strict|content/,wo=t=>!!t&&t!=="none";let Au;function uf(t){const o=An(t)?Ln(t):t;return wo(o.transform)||wo(o.translate)||wo(o.scale)||wo(o.rotate)||wo(o.perspective)||!df()&&(wo(o.backdropFilter)||wo(o.filter))||s_.test(o.willChange||"")||i_.test(o.contain||"")}function a_(t){let o=bo(t);for(;eo(o)&&!hi(o);){if(uf(o))return o;if(jl(o))return null;o=bo(o)}return null}function df(){return Au==null&&(Au=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Au}function hi(t){return/^(html|body|#document)$/.test(xs(t))}function Ln(t){return $t(t).getComputedStyle(t)}function kl(t){return An(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function bo(t){if(xs(t)==="html")return t;const o=t.assignedSlot||t.parentNode||xg(t)&&t.host||hr(t);return xg(o)?o.host:o}function my(t){const o=bo(t);return hi(o)?(t.ownerDocument||t).body:eo(o)&&bl(o)?o:my(o)}function pi(t,o,s){var a;o===void 0&&(o=[]),s===void 0&&(s=!0);const l=my(t),u=l===((a=t.ownerDocument)==null?void 0:a.body),d=$t(l);if(u){const h=md(d);return o.concat(d,d.visualViewport||[],bl(l)?l:[],h&&s?pi(h):[])}else return o.concat(l,pi(l,[],s))}function md(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function gy(t){const o=Ln(t);let s=parseFloat(o.width)||0,a=parseFloat(o.height)||0;const l=eo(t),u=l?t.offsetWidth:s,d=l?t.offsetHeight:a,h=nl(s)!==u||nl(a)!==d;return h&&(s=u,a=d),{width:s,height:a,$:h}}function ff(t){return An(t)?t:t.contextElement}function ls(t){const o=ff(t);if(!eo(o))return nr(1);const s=o.getBoundingClientRect(),{width:a,height:l,$:u}=gy(o);let d=(u?nl(s.width):s.width)/a,h=(u?nl(s.height):s.height)/l;return(!d||!Number.isFinite(d))&&(d=1),(!h||!Number.isFinite(h))&&(h=1),{x:d,y:h}}const l_=nr(0);function vy(t){const o=$t(t);return!df()||!o.visualViewport?l_:{x:o.visualViewport.offsetLeft,y:o.visualViewport.offsetTop}}function c_(t,o,s){return o===void 0&&(o=!1),!!s&&o&&s===$t(t)}function jo(t,o,s,a){o===void 0&&(o=!1),s===void 0&&(s=!1);const l=t.getBoundingClientRect(),u=ff(t);let d=nr(1);o&&(a?An(a)&&(d=ls(a)):d=ls(t));const h=c_(u,s,a)?vy(u):nr(0);let g=(l.left+h.x)/d.x,v=(l.top+h.y)/d.y,w=l.width/d.x,x=l.height/d.y;if(u&&a){const C=$t(u),y=An(a)?$t(a):a;let _=C,b=md(_);for(;b&&y!==_;){const j=ls(b),S=b.getBoundingClientRect(),R=Ln(b),N=S.left+(b.clientLeft+parseFloat(R.paddingLeft))*j.x,E=S.top+(b.clientTop+parseFloat(R.paddingTop))*j.y;g*=j.x,v*=j.y,w*=j.x,x*=j.y,g+=N,v+=E,_=$t(b),b=md(_)}}return ol({width:w,height:x,x:g,y:v})}function Cl(t,o){const s=kl(t).scrollLeft;return o?o.left+s:jo(hr(t)).left+s}function xy(t,o){const s=t.getBoundingClientRect(),a=s.left+o.scrollLeft-Cl(t,s),l=s.top+o.scrollTop;return{x:a,y:l}}function u_(t){let{elements:o,rect:s,offsetParent:a,strategy:l}=t;const u=l==="fixed",d=hr(a),h=o?jl(o.floating):!1;if(a===d||h&&u)return s;let g={scrollLeft:0,scrollTop:0},v=nr(1);const w=nr(0),x=eo(a);if((x||!u)&&((xs(a)!=="body"||bl(d))&&(g=kl(a)),x)){const y=jo(a);v=ls(a),w.x=y.x+a.clientLeft,w.y=y.y+a.clientTop}const C=d&&!x&&!u?xy(d,g):nr(0);return{width:s.width*v.x,height:s.height*v.y,x:s.x*v.x-g.scrollLeft*v.x+w.x+C.x,y:s.y*v.y-g.scrollTop*v.y+w.y+C.y}}function d_(t){return t.getClientRects?Array.from(t.getClientRects()):[]}function f_(t){const o=kl(t),s=t.ownerDocument.body,a=tr(t.scrollWidth,t.clientWidth,s.scrollWidth,s.clientWidth),l=tr(t.scrollHeight,t.clientHeight,s.scrollHeight,s.clientHeight);let u=-o.scrollLeft+Cl(t);const d=-o.scrollTop;return Ln(s).direction==="rtl"&&(u+=tr(t.clientWidth,s.clientWidth)-a),{width:a,height:l,x:u,y:d}}const h_=25;function p_(t,o,s){s===void 0&&(s="viewport");const a=s==="layoutViewport",l=$t(t),u=hr(t),d=l.visualViewport;let h=u.clientWidth,g=u.clientHeight,v=0,w=0;if(d){const C=!df()||o==="fixed";a?C||(v=-d.offsetLeft,w=-d.offsetTop):(h=d.width,g=d.height,C&&(v=d.offsetLeft,w=d.offsetTop))}if(Cl(u)<=0){const C=u.ownerDocument,y=C.body,_=getComputedStyle(y),b=C.compatMode==="CSS1Compat"&&parseFloat(_.marginLeft)+parseFloat(_.marginRight)||0,j=Math.abs(u.clientWidth-y.clientWidth-b),S=getComputedStyle(u).scrollbarGutter==="stable both-edges"?j/2:j;S<=h_&&(h-=S)}return{width:h,height:g,x:v,y:w}}function m_(t,o){const s=jo(t,!0,o==="fixed"),a=s.top+t.clientTop,l=s.left+t.clientLeft,u=ls(t),d=t.clientWidth*u.x,h=t.clientHeight*u.y,g=l*u.x,v=a*u.y;return{width:d,height:h,x:g,y:v}}function yg(t,o,s){let a;if(o==="viewport"||o==="layoutViewport")a=p_(t,s,o);else if(o==="document")a=f_(hr(t));else if(An(o))a=m_(o,s);else{const l=vy(t);a={x:o.x-l.x,y:o.y-l.y,width:o.width,height:o.height}}return ol(a)}function g_(t,o){const s=o.get(t);if(s)return s;let a=pi(t,[],!1).filter(h=>An(h)&&xs(h)!=="body"),l=null;const u=Ln(t).position==="fixed";let d=u?bo(t):t;for(;An(d)&&!hi(d);){const h=Ln(d),g=uf(d),v=l?l.position:u?"fixed":"";!g&&(v==="fixed"||v==="absolute"&&h.position==="static")?a=a.filter(x=>x!==d):l=h,d=bo(d)}return o.set(t,a),a}function v_(t){let{element:o,boundary:s,rootBoundary:a,strategy:l}=t;const d=[...s==="clippingAncestors"?jl(o)?[]:g_(o,this._c):[].concat(s),a],h=yg(o,d[0],l);let g=h.top,v=h.right,w=h.bottom,x=h.left;for(let C=1;C{h(!1,1e-7)},1e3)}F=!1}try{a=new IntersectionObserver(A,{...I,root:u.ownerDocument})}catch{a=new IntersectionObserver(A,I)}a.observe(t)}const g=$t(t),v=()=>h(s);return g.addEventListener("resize",v),h(!0),()=>{g.removeEventListener("resize",v),d()}}function C_(t,o,s,a){a===void 0&&(a={});const{ancestorScroll:l=!0,ancestorResize:u=!0,elementResize:d=typeof ResizeObserver=="function",layoutShift:h=typeof IntersectionObserver=="function",animationFrame:g=!1}=a,v=ff(t),w=l||u?[...v?pi(v):[],...o?pi(o):[]]:[];w.forEach(S=>{l&&S.addEventListener("scroll",s),u&&S.addEventListener("resize",s)});const x=v&&h?k_(v,s,u):null;let C=-1,y=null;d&&(y=new ResizeObserver(S=>{let[R]=S;R&&R.target===v&&y&&o&&(y.unobserve(o),cancelAnimationFrame(C),C=requestAnimationFrame(()=>{var N;(N=y)==null||N.observe(o)})),s()}),v&&!g&&y.observe(v),o&&y.observe(o));let _,b=g?jo(t):null;g&&j();function j(){const S=jo(t);b&&!wy(b,S)&&s(),b=S,_=requestAnimationFrame(j)}return s(),()=>{var S;w.forEach(R=>{l&&R.removeEventListener("scroll",s),u&&R.removeEventListener("resize",s)}),x==null||x(),(S=y)==null||S.disconnect(),y=null,g&&cancelAnimationFrame(_)}}const S_=e_,__=t_,N_=XS,E_=r_,R_=JS,bg=QS,P_=n_,T_=(t,o,s)=>{const a=new Map,l=s??{},u={...j_,...l.platform,_c:a};return YS(t,o,{...l,platform:u})};var D_=typeof document<"u",O_=function(){},Ya=D_?m.useLayoutEffect:O_;function sl(t,o){if(t===o)return!0;if(typeof t!=typeof o)return!1;if(typeof t=="function"&&t.toString()===o.toString())return!0;let s,a,l;if(t&&o&&typeof t=="object"){if(Array.isArray(t)){if(s=t.length,s!==o.length)return!1;for(a=s;a--!==0;)if(!sl(t[a],o[a]))return!1;return!0}if(l=Object.keys(t),s=l.length,s!==Object.keys(o).length)return!1;for(a=s;a--!==0;)if(!{}.hasOwnProperty.call(o,l[a]))return!1;for(a=s;a--!==0;){const u=l[a];if(!(u==="_owner"&&t.$$typeof)&&!sl(t[u],o[u]))return!1}return!0}return t!==t&&o!==o}function by(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function jg(t,o){const s=by(t);return Math.round(o*s)/s}function Iu(t){const o=m.useRef(t);return Ya(()=>{o.current=t}),o}function M_(t){t===void 0&&(t={});const{placement:o="bottom",strategy:s="absolute",middleware:a=[],platform:l,elements:{reference:u,floating:d}={},transform:h=!0,whileElementsMounted:g,open:v}=t,[w,x]=m.useState({x:0,y:0,strategy:s,placement:o,middlewareData:{},isPositioned:!1}),[C,y]=m.useState(a);sl(C,a)||y(a);const[_,b]=m.useState(null),[j,S]=m.useState(null),R=m.useCallback(H=>{H!==I.current&&(I.current=H,b(H))},[]),N=m.useCallback(H=>{H!==F.current&&(F.current=H,S(H))},[]),E=u||_,P=d||j,I=m.useRef(null),F=m.useRef(null),A=m.useRef(w),q=g!=null,B=Iu(g),z=Iu(l),Z=Iu(v),se=m.useCallback(()=>{if(!I.current||!F.current)return;const H={placement:o,strategy:s,middleware:C};z.current&&(H.platform=z.current),T_(I.current,F.current,H).then(J=>{const $={...J,isPositioned:Z.current!==!1};he.current&&!sl(A.current,$)&&(A.current=$,_d.flushSync(()=>{x($)}))})},[C,o,s,z,Z]);Ya(()=>{v===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,x(H=>({...H,isPositioned:!1})))},[v]);const he=m.useRef(!1);Ya(()=>(he.current=!0,()=>{he.current=!1}),[]),Ya(()=>{if(E&&(I.current=E),P&&(F.current=P),E&&P){if(B.current)return B.current(E,P,se);se()}},[E,P,se,B,q]);const ye=m.useMemo(()=>({reference:I,floating:F,setReference:R,setFloating:N}),[R,N]),ae=m.useMemo(()=>({reference:E,floating:P}),[E,P]),oe=m.useMemo(()=>{const H={position:s,left:0,top:0};if(!ae.floating)return H;const J=jg(ae.floating,w.x),$=jg(ae.floating,w.y);return h?{...H,transform:"translate("+J+"px, "+$+"px)",...by(ae.floating)>=1.5&&{willChange:"transform"}}:{position:s,left:J,top:$}},[s,h,ae.floating,w.x,w.y]);return m.useMemo(()=>({...w,update:se,refs:ye,elements:ae,floatingStyles:oe}),[w,se,ye,ae,oe])}const A_=t=>{function o(s){return{}.hasOwnProperty.call(s,"current")}return{name:"arrow",options:t,fn(s){const{element:a,padding:l}=typeof t=="function"?t(s):t;return a&&o(a)?a.current!=null?bg({element:a.current,padding:l}).fn(s):{}:a?bg({element:a,padding:l}).fn(s):{}}}},L_=(t,o)=>{const s=S_(t);return{name:s.name,fn:s.fn,options:[t,o]}},I_=(t,o)=>{const s=__(t);return{name:s.name,fn:s.fn,options:[t,o]}},z_=(t,o)=>({fn:P_(t).fn,options:[t,o]}),F_=(t,o)=>{const s=N_(t);return{name:s.name,fn:s.fn,options:[t,o]}},$_=(t,o)=>{const s=E_(t);return{name:s.name,fn:s.fn,options:[t,o]}},U_=(t,o)=>{const s=R_(t);return{name:s.name,fn:s.fn,options:[t,o]}},B_=(t,o)=>{const s=A_(t);return{name:s.name,fn:s.fn,options:[t,o]}};var W_=Object.defineProperty,V_=(t,o)=>W_(t,"name",{value:o,configurable:!0}),H_=m.forwardRef(V_(function(o,s){const{children:a,width:l=10,height:u=5,...d}=o;return r.jsx(Ue.svg,{...d,ref:s,width:l,height:u,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:o.asChild?a:r.jsx("polygon",{points:"0,0 30,0 15,10"})})},"Arrow")),G_=Object.defineProperty,rr=(t,o)=>G_(t,"name",{value:o,configurable:!0}),kg={Partial:"partial"},Cg={Optimized:"optimized",Always:"always"},jy="Popper",[ky,Sl]=jn(jy),[K_,Cy]=ky(jy),Sy=rr(t=>{const{__scopePopper:o,children:s}=t,[a,l]=m.useState(null),[u,d]=m.useState(void 0);return r.jsx(K_,{scope:o,anchor:a,onAnchorChange:l,placementState:u,setPlacementState:d,children:s})},"Popper"),q_="PopperAnchor",_y=m.forwardRef(rr(function(o,s){const{__scopePopper:a,virtualRef:l,...u}=o,d=Cy(q_,a),h=m.useRef(null),g=d.onAnchorChange,v=m.useCallback(b=>{h.current=b,b&&g(b)},[g]),w=Fe(s,v),x=m.useRef(null);m.useEffect(()=>{if(!l)return;const b=x.current;x.current=l.current,b!==x.current&&g(x.current)});const C=d.placementState&&_l(d.placementState),y=C==null?void 0:C[0],_=C==null?void 0:C[1];return l?null:r.jsx(Ue.div,{"data-radix-popper-side":y,"data-radix-popper-align":_,...u,ref:w})},"PopperAnchor")),Ny="PopperContent",[Y_,Q_]=ky(Ny),Ey=m.forwardRef(rr(function(o,s){var be,Ye,Ct,Bt,yt,ut,gr;const{__scopePopper:a,side:l="bottom",sideOffset:u=0,align:d="center",alignOffset:h=0,arrowPadding:g=0,avoidCollisions:v=!0,collisionBoundary:w=[],collisionPadding:x=0,sticky:C=kg.Partial,hideWhenDetached:y=!1,updatePositionStrategy:_=Cg.Optimized,onPlaced:b,...j}=o,S=Cy(Ny,a),[R,N]=m.useState(null),E=Fe(s,N),[P,I]=m.useState(null),F=nf(P),A=(F==null?void 0:F.width)??0,q=(F==null?void 0:F.height)??0,B=l+(d!=="center"?"-"+d:""),z=typeof x=="number"?x:{top:0,right:0,bottom:0,left:0,...x},Z=Array.isArray(w)?w:[w],se=Z.length>0,he={padding:z,boundary:Z.filter(Ry),altBoundary:se},{refs:ye,floatingStyles:ae,placement:oe,isPositioned:H,middlewareData:J}=M_({strategy:"fixed",placement:B,whileElementsMounted:rr((...Un)=>C_(...Un,{animationFrame:_===Cg.Always}),"whileElementsMounted"),elements:{reference:S.anchor},middleware:[L_({mainAxis:u+q,alignmentAxis:h}),v&&I_({mainAxis:!0,crossAxis:!1,...C===kg.Partial?{limiter:z_()}:{},...he}),v&&F_({...he}),$_({...he,apply:rr(({elements:Un,rects:wt,availableWidth:Ci,availableHeight:ys})=>{const{width:ro,height:vr}=wt.reference,xr=Un.floating.style;xr.setProperty("--radix-popper-available-width",`${Ci}px`),xr.setProperty("--radix-popper-available-height",`${ys}px`),xr.setProperty("--radix-popper-anchor-width",`${ro}px`),xr.setProperty("--radix-popper-anchor-height",`${vr}px`)},"apply")}),P&&B_({element:P,padding:g}),eN({arrowWidth:A,arrowHeight:q}),y&&U_(se?{strategy:"referenceHidden",...he}:{strategy:"referenceHidden",padding:he.padding,altBoundary:he.altBoundary})]}),$=S.setPlacementState;Rt(()=>($(oe),()=>{$(void 0)}),[oe,$]);const[O,G]=_l(oe),ce=Mn(b);Rt(()=>{H&&(ce==null||ce())},[H,ce]);const we=(be=J.arrow)==null?void 0:be.x,L=(Ye=J.arrow)==null?void 0:Ye.y,K=((Ct=J.arrow)==null?void 0:Ct.centerOffset)!==0,[ge,Ce]=m.useState();return Rt(()=>{R&&Ce(window.getComputedStyle(R).zIndex)},[R]),r.jsx("div",{ref:ye.setFloating,"data-radix-popper-content-wrapper":"",style:{...ae,transform:H?ae.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ge,"--radix-popper-transform-origin":[(Bt=J.transformOrigin)==null?void 0:Bt.x,(yt=J.transformOrigin)==null?void 0:yt.y].join(" "),...((ut=J.hide)==null?void 0:ut.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:o.dir,children:r.jsx(Y_,{scope:a,placedSide:O,placedAlign:G,onArrowChange:I,arrowX:we,arrowY:L,shouldHideArrow:K,children:r.jsx(Ue.div,{"data-side":O,"data-align":G,...j,ref:E,style:{...j.style,animation:H?(gr=j.style)==null?void 0:gr.animation:"none"}})})})},"PopperContent")),X_="PopperArrow",J_={top:"bottom",right:"left",bottom:"top",left:"right"},Z_=m.forwardRef(rr(function(o,s){const{__scopePopper:a,...l}=o,u=Q_(X_,a),d=J_[u.placedSide];return r.jsx("span",{ref:u.onArrowChange,style:{position:"absolute",left:u.arrowX,top:u.arrowY,[d]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[u.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[u.placedSide],visibility:u.shouldHideArrow?"hidden":void 0},children:r.jsx(H_,{...l,ref:s,style:{...l.style,display:"block"}})})},"PopperArrow"));function Ry(t){return t!==null}rr(Ry,"isNotNull");var eN=rr(t=>({name:"transformOrigin",options:t,fn(o){var j,S,R;const{placement:s,rects:a,middlewareData:l}=o,d=((j=l.arrow)==null?void 0:j.centerOffset)!==0,h=d?0:t.arrowWidth,g=d?0:t.arrowHeight,[v,w]=_l(s),x={start:"0%",center:"50%",end:"100%"}[w],C=(((S=l.arrow)==null?void 0:S.x)??0)+h/2,y=(((R=l.arrow)==null?void 0:R.y)??0)+g/2;let _="",b="";return v==="bottom"?(_=d?x:`${C}px`,b=`${-g}px`):v==="top"?(_=d?x:`${C}px`,b=`${a.floating.height+g}px`):v==="right"?(_=`${-g}px`,b=d?x:`${y}px`):v==="left"&&(_=`${a.floating.width+g}px`,b=d?x:`${y}px`),{data:{x:_,y:b}}}}),"transformOrigin");function _l(t){const[o,s="center"]=t.split("-");return[o,s]}rr(_l,"getSideAndAlignFromPlacement");var tN=Object.defineProperty,hf=(t,o)=>tN(t,"name",{value:o,configurable:!0}),zu=!1;function Py(){const[t,o]=m.useState(zu);return m.useEffect(()=>{zu||(zu=!0,o(!0))},[]),t}hf(Py,"useIsHydrated");var Ty=Xr[" useSyncExternalStore ".trim().toString()];function Dy(){return()=>{}}hf(Dy,"subscribe");function Oy(){return Ty(Dy,()=>!0,()=>!1)}hf(Oy,"useIsHydratedModern");var nN=typeof Ty=="function"?Oy:Py,rN=Object.defineProperty,_o=(t,o)=>rN(t,"name",{value:o,configurable:!0}),Fu="rovingFocusGroup.onEntryFocus",oN={bubbles:!1,cancelable:!0},Nl="RovingFocusGroup",[gd,My,sN]=Id(Nl),[iN,Ay]=jn(Nl,[sN]),Sg={Vertical:"vertical",Horizontal:"horizontal"},aN={RTL:"rtl"},[lN,cN]=iN(Nl),uN=m.forwardRef(_o(function(o,s){return r.jsx(gd.Provider,{scope:o.__scopeRovingFocusGroup,children:r.jsx(gd.Slot,{scope:o.__scopeRovingFocusGroup,children:r.jsx(dN,{...o,ref:s})})})},"RovingFocusGroup")),dN=m.forwardRef(_o(function(o,s){const{__scopeRovingFocusGroup:a,orientation:l,loop:u=!1,dir:d,currentTabStopId:h,defaultCurrentTabStopId:g,onCurrentTabStopIdChange:v,onEntryFocus:w,preventScrollOnEntryFocus:x=!1,...C}=o,y=m.useRef(null),_=Fe(s,y),b=Fd(d),[j,S]=gs({prop:h,defaultProp:g??null,onChange:v,caller:Nl}),[R,N]=m.useState(!1),E=Mn(w),P=My(a),I=m.useRef(!1),[F,A]=m.useState(0);return m.useEffect(()=>{const q=y.current;if(q)return q.addEventListener(Fu,E),()=>q.removeEventListener(Fu,E)},[E]),r.jsx(lN,{scope:a,orientation:l,dir:b,loop:u,currentTabStopId:j,onItemFocus:m.useCallback(q=>S(q),[S]),onItemShiftTab:m.useCallback(()=>N(!0),[]),onFocusableItemAdd:m.useCallback(()=>A(q=>q+1),[]),onFocusableItemRemove:m.useCallback(()=>A(q=>q-1),[]),children:r.jsx(Ue.div,{tabIndex:R||F===0?-1:0,"data-orientation":l,...C,ref:_,style:{outline:"none",...o.style},onMouseDown:Pe(o.onMouseDown,()=>{I.current=!0}),onFocus:Pe(o.onFocus,q=>{const B=!I.current;if(q.target===q.currentTarget&&B&&!R){const z=new CustomEvent(Fu,oN);if(q.currentTarget.dispatchEvent(z),!z.defaultPrevented){const Z=P().filter(oe=>oe.focusable),se=Z.find(oe=>oe.active),he=Z.find(oe=>oe.id===j),ae=[se,he,...Z].filter(Boolean).map(oe=>oe.ref.current);pf(ae,x)}}I.current=!1}),onBlur:Pe(o.onBlur,()=>N(!1))})})},"RovingFocusGroupImpl")),fN="RovingFocusGroupItem",hN=m.forwardRef(_o(function(o,s){const{__scopeRovingFocusGroup:a,focusable:l=!0,active:u=!1,tabStopId:d,children:h,...g}=o,v=Gr(),w=d||v,x=cN(fN,a),C=x.currentTabStopId===w,y=My(a),{onFocusableItemAdd:_,onFocusableItemRemove:b,currentTabStopId:j}=x,S=nN();return Rt(()=>{if(!(!S||!l))return _(),()=>b()},[S,l,_,b]),m.useEffect(()=>{if(!(S||!l))return _(),()=>b()},[S,l,_,b]),r.jsx(gd.ItemSlot,{scope:a,id:w,focusable:l,active:u,children:r.jsx(Ue.span,{tabIndex:C?0:-1,"data-orientation":x.orientation,...g,ref:s,onMouseDown:Pe(o.onMouseDown,R=>{l?x.onItemFocus(w):R.preventDefault()}),onFocus:Pe(o.onFocus,()=>x.onItemFocus(w)),onKeyDown:Pe(o.onKeyDown,R=>{if(R.key==="Tab"&&R.shiftKey){x.onItemShiftTab();return}if(R.target!==R.currentTarget)return;const N=Iy(R,x.orientation,x.dir);if(N!==void 0){if(R.metaKey||R.ctrlKey||R.altKey||R.shiftKey)return;R.preventDefault();let P=y().filter(I=>I.focusable).map(I=>I.ref.current);if(N==="last")P.reverse();else if(N==="prev"||N==="next"){N==="prev"&&P.reverse();const I=P.indexOf(R.currentTarget);P=x.loop?zy(P,I+1):P.slice(I+1)}setTimeout(()=>pf(P))}}),children:typeof h=="function"?h({isCurrentTabStop:C,hasTabStop:j!=null}):h})})},"RovingFocusGroupItem")),pN={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Ly(t,o){return o!==aN.RTL?t:t==="ArrowLeft"?"ArrowRight":t==="ArrowRight"?"ArrowLeft":t}_o(Ly,"getDirectionAwareKey");function Iy(t,o,s){const a=Ly(t.key,s);if(!(o===Sg.Vertical&&["ArrowLeft","ArrowRight"].includes(a))&&!(o===Sg.Horizontal&&["ArrowUp","ArrowDown"].includes(a)))return pN[a]}_o(Iy,"getFocusIntent");function pf(t,o=!1){const s=document.activeElement;for(const a of t)if(a===s||(a.focus({preventScroll:o}),document.activeElement!==s))return}_o(pf,"focusFirst");function zy(t,o){return t.map((s,a)=>t[(o+a)%t.length])}_o(zy,"wrapArray");var mN=Object.defineProperty,Le=(t,o)=>mN(t,"name",{value:o,configurable:!0}),gN=["Enter"," "],vN=["ArrowDown","PageUp","Home"],Fy=["ArrowUp","PageDown","End"],xN=[...vN,...Fy],El="Menu",[vd,yN,wN]=Id(El),[No,$y]=jn(El,[wN,Sl,Ay]),mf=Sl(),Uy=Ay(),[bN,yi]=No(El),[jN,gf]=No(El),kN=Le(t=>{const{__scopeMenu:o,open:s=!1,children:a,dir:l,onOpenChange:u,modal:d=!0}=t,h=mf(o),[g,v]=m.useState(null),w=m.useRef(!1),x=Mn(u),C=Fd(l);return m.useEffect(()=>{const y=Le(()=>{w.current=!0,document.addEventListener("pointerdown",_,{capture:!0,once:!0}),document.addEventListener("pointermove",_,{capture:!0,once:!0})},"handleKeyDown"),_=Le(()=>w.current=!1,"handlePointer");return document.addEventListener("keydown",y,{capture:!0}),()=>{document.removeEventListener("keydown",y,{capture:!0}),document.removeEventListener("pointerdown",_,{capture:!0}),document.removeEventListener("pointermove",_,{capture:!0})}},[]),m.useEffect(()=>{if(!s)return;const y=Le(()=>x(!1),"handleBlur");return window.addEventListener("blur",y),()=>window.removeEventListener("blur",y)},[s,x]),r.jsx(Sy,{...h,children:r.jsx(bN,{scope:o,open:s,onOpenChange:x,content:g,onContentChange:v,children:r.jsx(jN,{scope:o,onClose:m.useCallback(()=>x(!1),[x]),isUsingKeyboardRef:w,dir:C,modal:d,children:a})})})},"Menu"),CN=m.forwardRef(Le(function(o,s){const{__scopeMenu:a,...l}=o,u=mf(a);return r.jsx(_y,{...u,...l,ref:s})},"MenuAnchor")),By="MenuPortal",[SN,_N]=No(By,{forceMount:void 0}),NN=Le(t=>{const{__scopeMenu:o,forceMount:s,children:a,container:l}=t,u=yi(By,o);return r.jsx(SN,{scope:o,forceMount:s,children:r.jsx(ur,{present:s||u.open,children:r.jsx(Gd,{asChild:!0,container:l,children:a})})})},"MenuPortal"),Kr="MenuContent",[EN,Wy]=No(Kr),RN=m.forwardRef(Le(function(o,s){const a=_N(Kr,o.__scopeMenu),{forceMount:l=a.forceMount,...u}=o,d=yi(Kr,o.__scopeMenu),h=gf(Kr,o.__scopeMenu);return r.jsx(vd.Provider,{scope:o.__scopeMenu,children:r.jsx(ur,{present:l||d.open,children:r.jsx(vd.Slot,{scope:o.__scopeMenu,children:h.modal?r.jsx(PN,{...u,ref:s}):r.jsx(TN,{...u,ref:s})})})})},"MenuContent")),PN=m.forwardRef(Le(function(o,s){const a=yi(Kr,o.__scopeMenu),l=m.useRef(null),u=Fe(s,l);return m.useEffect(()=>{const d=l.current;if(d)return ny(d)},[]),r.jsx(Vy,{...o,ref:u,trapFocus:a.open,disableOutsidePointerEvents:a.open,disableOutsideScroll:!0,onFocusOutside:Pe(o.onFocusOutside,d=>d.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>a.onOpenChange(!1)})},"MenuRootContentModal")),TN=m.forwardRef(Le(function(o,s){const a=yi(Kr,o.__scopeMenu);return r.jsx(Vy,{...o,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>a.onOpenChange(!1)})},"MenuRootContentNonModal")),DN=or("MenuContent.ScrollLock"),Vy=m.forwardRef(Le(function(o,s){const{__scopeMenu:a,loop:l=!1,trapFocus:u,onOpenAutoFocus:d,onCloseAutoFocus:h,disableOutsidePointerEvents:g,onEntryFocus:v,onEscapeKeyDown:w,onPointerDownOutside:x,onFocusOutside:C,onInteractOutside:y,onDismiss:_,disableOutsideScroll:b,...j}=o,S=yi(Kr,a),R=gf(Kr,a),N=mf(a),E=Uy(a),P=yN(a),[I,F]=m.useState(null),A=m.useRef(null),[q,B]=m.useState(null);Vd(q);const{nodes:z,registry:Z}=Wd(),se=!!(u||b),he=Fe(s,A,S.onContentChange,B),ye=m.useRef(0),ae=m.useRef(""),oe=m.useRef(0),H=m.useRef(null),J=m.useRef("right"),$=m.useRef(0),O=m.useMemo(()=>b?[A,...z.map(K=>({current:K}))]:[],[A,z,b]),G=b?qd:m.Fragment,ce=b?{as:DN,allowPinchZoom:!0,shards:O}:void 0,we=Le(K=>{var gr,Un;const ge=ae.current+K,Ce=P().filter(wt=>!wt.disabled),be=document.activeElement,Ye=(gr=Ce.find(wt=>wt.ref.current===be))==null?void 0:gr.textValue,Ct=Ce.map(wt=>wt.textValue),Bt=Yy(Ct,ge,Ye),yt=(Un=Ce.find(wt=>wt.textValue===Bt))==null?void 0:Un.ref.current;function ut(wt){ae.current=wt,window.clearTimeout(ye.current),wt!==""&&(ye.current=window.setTimeout(()=>ut(""),1e3))}Le(ut,"updateSearch"),ut(ge),yt&&setTimeout(()=>yt.focus())},"handleTypeaheadSearch");m.useEffect(()=>()=>window.clearTimeout(ye.current),[]),vl();const L=m.useCallback(K=>{var Ce,be;return J.current===((Ce=H.current)==null?void 0:Ce.side)&&Xy(K,(be=H.current)==null?void 0:be.area)},[]);return r.jsx(EN,{scope:a,searchRef:ae,onItemEnter:m.useCallback(K=>{L(K)&&K.preventDefault()},[L]),onItemLeave:m.useCallback(K=>{var ge;L(K)||((ge=A.current)==null||ge.focus(),F(null))},[L]),onTriggerLeave:m.useCallback(K=>{L(K)&&K.preventDefault()},[L]),pointerGraceTimerRef:oe,onPointerGraceIntentChange:m.useCallback(K=>{H.current=K},[]),children:r.jsx(Bd,{registry:se?Z:null,children:r.jsx(G,{...ce,children:r.jsx($x,{asChild:!0,trapped:u,branches:z,onMountAutoFocus:Pe(d,K=>{var ge;K.preventDefault(),(ge=A.current)==null||ge.focus({preventScroll:!0})}),onUnmountAutoFocus:h,children:r.jsx($d,{asChild:!0,disableOutsidePointerEvents:g,onEscapeKeyDown:w,onPointerDownOutside:x,onFocusOutside:C,onInteractOutside:y,onDismiss:_,children:r.jsx(uN,{asChild:!0,...E,dir:R.dir,orientation:"vertical",loop:l,currentTabStopId:I,onCurrentTabStopIdChange:F,onEntryFocus:Pe(v,K=>{R.isUsingKeyboardRef.current||K.preventDefault()}),preventScrollOnEntryFocus:!0,children:r.jsx(Ey,{role:"menu","aria-orientation":"vertical","data-state":Gy(S.open),"data-radix-menu-content":"",dir:R.dir,...N,...j,ref:he,style:{outline:"none",...j.style},onKeyDown:Pe(j.onKeyDown,K=>{const Ce=K.target.closest("[data-radix-menu-content]")===K.currentTarget,be=K.ctrlKey||K.altKey||K.metaKey,Ye=K.key.length===1;Ce&&(K.key==="Tab"&&K.preventDefault(),!be&&Ye&&we(K.key));const Ct=A.current;if(K.target!==Ct||!xN.includes(K.key))return;K.preventDefault();const yt=P().filter(ut=>!ut.disabled).map(ut=>ut.ref.current);Fy.includes(K.key)&&yt.reverse(),Ky(yt)}),onBlur:Pe(o.onBlur,K=>{K.currentTarget.contains(K.target)||(window.clearTimeout(ye.current),ae.current="")}),onPointerMove:Pe(o.onPointerMove,il(K=>{const ge=K.target,Ce=$.current!==K.clientX;if(K.currentTarget.contains(ge)&&Ce){const be=K.clientX>$.current?"right":"left";J.current=be,$.current=K.clientX}}))})})})})})})})},"MenuContentImpl")),ON=m.forwardRef(Le(function(o,s){const{__scopeMenu:a,...l}=o;return r.jsx(Ue.div,{role:"group",...l,ref:s})},"MenuGroup")),MN=m.forwardRef(Le(function(o,s){const{__scopeMenu:a,...l}=o;return r.jsx(Ue.div,{...l,ref:s})},"MenuLabel")),xd="MenuItem",_g="menu.itemSelect",AN=m.forwardRef(Le(function(o,s){const{disabled:a=!1,onSelect:l,...u}=o,d=m.useRef(null),h=gf(xd,o.__scopeMenu),g=Wy(xd,o.__scopeMenu),v=Fe(s,d),w=m.useRef(!1),x=Le(()=>{const C=d.current;if(!a&&C){const y=new CustomEvent(_g,{bubbles:!0,cancelable:!0});C.addEventListener(_g,_=>l==null?void 0:l(_),{once:!0}),Ld(C,y),y.defaultPrevented?w.current=!1:h.onClose()}},"handleSelect");return r.jsx(LN,{...u,ref:v,disabled:a,onClick:Pe(o.onClick,x),onPointerDown:C=>{var y;(y=o.onPointerDown)==null||y.call(o,C),w.current=!0},onPointerUp:Pe(o.onPointerUp,C=>{var y;w.current||(y=C.currentTarget)==null||y.click()}),onKeyDown:Pe(o.onKeyDown,C=>{a||C.target!==C.currentTarget||g.searchRef.current!==""&&C.key===" "||gN.includes(C.key)&&(C.currentTarget.click(),C.preventDefault())})})},"MenuItem")),LN=m.forwardRef(Le(function(o,s){const{__scopeMenu:a,disabled:l=!1,textValue:u,...d}=o,h=Wy(xd,a),g=Uy(a),v=m.useRef(null),w=Fe(s,v),[x,C]=m.useState(!1),[y,_]=m.useState("");return m.useEffect(()=>{const b=v.current;b&&_((b.textContent??"").trim())},[d.children]),r.jsx(vd.ItemSlot,{scope:a,disabled:l,textValue:u??y,children:r.jsx(hN,{asChild:!0,...g,focusable:!l,children:r.jsx(Ue.div,{role:"menuitem","data-highlighted":x?"":void 0,"aria-disabled":l||void 0,"data-disabled":l?"":void 0,...d,ref:w,onPointerMove:Pe(o.onPointerMove,il(b=>{l?h.onItemLeave(b):(h.onItemEnter(b),b.defaultPrevented||b.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Pe(o.onPointerLeave,il(b=>h.onItemLeave(b))),onFocus:Pe(o.onFocus,()=>C(!0)),onBlur:Pe(o.onBlur,()=>C(!1))})})})},"MenuItemImpl")),IN="MenuRadioGroup",[zN,FN]=No(IN,{value:void 0,onValueChange:Le(()=>{},"onValueChange")}),$N=m.forwardRef(Le(function(o,s){const{value:a,onValueChange:l,...u}=o,d=Mn(l);return r.jsx(zN,{scope:o.__scopeMenu,value:a,onValueChange:d,children:r.jsx(ON,{...u,ref:s})})},"MenuRadioGroup")),UN="MenuRadioItem",BN=m.forwardRef(Le(function(o,s){const{value:a,...l}=o,u=FN(UN,o.__scopeMenu),d=a===u.value;return r.jsx(WN,{scope:o.__scopeMenu,checked:d,children:r.jsx(AN,{role:"menuitemradio","aria-checked":d,...l,ref:s,"data-state":xf(d),onSelect:Pe(l.onSelect,()=>{var h;return(h=u.onValueChange)==null?void 0:h.call(u,a)},{checkForDefaultPrevented:!1})})})},"MenuRadioItem")),Hy="MenuItemIndicator",[WN,VN]=No(Hy,{checked:!1}),HN=m.forwardRef(Le(function(o,s){const{__scopeMenu:a,forceMount:l,...u}=o,d=VN(Hy,a);return r.jsx(ur,{present:l||vf(d.checked)||d.checked===!0,children:r.jsx(Ue.span,{...u,ref:s,"data-state":xf(d.checked)})})},"MenuItemIndicator")),GN=m.forwardRef(Le(function(o,s){const{__scopeMenu:a,...l}=o;return r.jsx(Ue.div,{role:"separator","aria-orientation":"horizontal",...l,ref:s})},"MenuSeparator")),KN="MenuSub",[IR,zR]=No(KN);function Gy(t){return t?"open":"closed"}Le(Gy,"getOpenState");function vf(t){return t==="indeterminate"}Le(vf,"isIndeterminate");function xf(t){return vf(t)?"indeterminate":t?"checked":"unchecked"}Le(xf,"getCheckedState");function Ky(t){const o=document.activeElement;for(const s of t)if(s===o||(s.focus(),document.activeElement!==o))return}Le(Ky,"focusFirst");function qy(t,o){return t.map((s,a)=>t[(o+a)%t.length])}Le(qy,"wrapArray");function Yy(t,o,s){const l=o.length>1&&Array.from(o).every(v=>v===o[0])?o[0]:o,u=s?t.indexOf(s):-1;let d=qy(t,Math.max(u,0));l.length===1&&(d=d.filter(v=>v!==s));const g=d.find(v=>v.toLowerCase().startsWith(l.toLowerCase()));return g!==s?g:void 0}Le(Yy,"getNextMatch");function Qy(t,o){const{x:s,y:a}=t;let l=!1;for(let u=0,d=o.length-1;ua!=C>a&&s<(x-v)*(a-w)/(C-w)+v&&(l=!l)}return l}Le(Qy,"isPointInPolygon");function Xy(t,o){if(!o)return!1;const s={x:t.clientX,y:t.clientY};return Qy(s,o)}Le(Xy,"isPointerInGraceArea");function il(t){return o=>o.pointerType==="mouse"?t(o):void 0}Le(il,"whenMouse");var qN=Object.defineProperty,pr=(t,o)=>qN(t,"name",{value:o,configurable:!0}),yf="DropdownMenu",[YN,FR]=jn(yf,[$y]),mr=$y(),[QN,Jy]=YN(yf),XN=pr(t=>{const{__scopeDropdownMenu:o,children:s,dir:a,open:l,defaultOpen:u,onOpenChange:d,modal:h=!0}=t,g=mr(o),v=m.useRef(null),[w,x]=gs({prop:l,defaultProp:u??!1,onChange:d,caller:yf});return r.jsx(QN,{scope:o,triggerId:Gr(),triggerRef:v,contentId:Gr(),open:w,onOpenChange:x,onOpenToggle:m.useCallback(()=>x(C=>!C),[x]),modal:h,children:r.jsx(kN,{...g,open:w,onOpenChange:x,dir:a,modal:h,children:s})})},"DropdownMenu"),JN="DropdownMenuTrigger",ZN=m.forwardRef(pr(function(o,s){const{__scopeDropdownMenu:a,disabled:l=!1,...u}=o,d=Jy(JN,a),h=mr(a),g=Fe(s,d.triggerRef);return r.jsx(CN,{asChild:!0,...h,children:r.jsx(Ue.button,{type:"button",id:d.triggerId,"aria-haspopup":"menu","aria-expanded":d.open,"aria-controls":d.open?d.contentId:void 0,"data-state":d.open?"open":"closed","data-disabled":l?"":void 0,disabled:l,...u,ref:g,onPointerDown:Pe(o.onPointerDown,v=>{!l&&v.button===0&&v.ctrlKey===!1&&(d.onOpenToggle(),d.open||v.preventDefault())}),onKeyDown:Pe(o.onKeyDown,v=>{l||(["Enter"," "].includes(v.key)&&d.onOpenToggle(),v.key==="ArrowDown"&&d.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(v.key)&&v.preventDefault())})})})},"DropdownMenuTrigger")),eE=pr(t=>{const{__scopeDropdownMenu:o,...s}=t,a=mr(o);return r.jsx(NN,{...a,...s})},"DropdownMenuPortal"),tE="DropdownMenuContent",nE=m.forwardRef(pr(function(o,s){const{__scopeDropdownMenu:a,...l}=o,u=Jy(tE,a),d=mr(a),h=m.useRef(!1);return r.jsx(RN,{id:u.contentId,"aria-labelledby":u.triggerId,...d,...l,ref:s,onCloseAutoFocus:Pe(o.onCloseAutoFocus,g=>{var v;h.current||(v=u.triggerRef.current)==null||v.focus(),h.current=!1,g.preventDefault()}),onInteractOutside:Pe(o.onInteractOutside,g=>{const v=g.detail.originalEvent,w=v.button===0&&v.ctrlKey===!0,x=v.button===2||w;(!u.modal||x)&&(h.current=!0)}),style:{...o.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})},"DropdownMenuContent")),rE=m.forwardRef(pr(function(o,s){const{__scopeDropdownMenu:a,...l}=o,u=mr(a);return r.jsx(MN,{...u,...l,ref:s})},"DropdownMenuLabel")),oE=m.forwardRef(pr(function(o,s){const{__scopeDropdownMenu:a,...l}=o,u=mr(a);return r.jsx($N,{...u,...l,ref:s})},"DropdownMenuRadioGroup")),sE=m.forwardRef(pr(function(o,s){const{__scopeDropdownMenu:a,...l}=o,u=mr(a);return r.jsx(BN,{...u,...l,ref:s})},"DropdownMenuRadioItem")),iE=m.forwardRef(pr(function(o,s){const{__scopeDropdownMenu:a,...l}=o,u=mr(a);return r.jsx(HN,{...u,...l,ref:s})},"DropdownMenuItemIndicator")),aE=m.forwardRef(pr(function(o,s){const{__scopeDropdownMenu:a,...l}=o,u=mr(a);return r.jsx(GN,{...u,...l,ref:s})},"DropdownMenuSeparator")),lE=Object.defineProperty,cE=(t,o)=>lE(t,"name",{value:o,configurable:!0}),uE=m.forwardRef(cE(function(o,s){return r.jsx(Ue.label,{...o,ref:s,onMouseDown:a=>{var u;a.target.closest("button, input, select, textarea")||((u=o.onMouseDown)==null||u.call(o,a),!a.defaultPrevented&&a.detail>1&&a.preventDefault())}})},"Label")),dE=Object.defineProperty,Zy=(t,o)=>dE(t,"name",{value:o,configurable:!0}),wf={Horizontal:"horizontal",Vertical:"vertical"},Ng=wf.Horizontal,fE=Object.values(wf),hE=m.forwardRef(Zy(function(o,s){const{decorative:a,orientation:l=Ng,...u}=o,d=ew(l)?l:Ng,h=d===wf.Vertical?d:void 0,g=a?{role:"none"}:{"aria-orientation":h,role:"separator"};return r.jsx(Ue.div,{"data-orientation":d,...g,...u,ref:s})},"Separator"));function ew(t){return fE.includes(t)}Zy(ew,"isValidOrientation");var pE=Object.defineProperty,at=(t,o)=>pE(t,"name",{value:o,configurable:!0}),[bf,$R]=jn("Tooltip",[Sl]),Rl=Sl(),mE="TooltipProvider",gE=700,yd="tooltip.open",[vE,jf]=bf(mE),xE=at(t=>{const{__scopeTooltip:o,delayDuration:s=gE,skipDelayDuration:a=300,disableHoverableContent:l=!1,children:u}=t,d=m.useRef(!0),h=m.useRef(!1),g=m.useRef(0);return m.useEffect(()=>{const v=g.current;return()=>window.clearTimeout(v)},[]),r.jsx(vE,{scope:o,isOpenDelayedRef:d,delayDuration:s,onOpen:m.useCallback(()=>{a<=0||(window.clearTimeout(g.current),d.current=!1)},[a]),onClose:m.useCallback(()=>{a<=0||(window.clearTimeout(g.current),g.current=window.setTimeout(()=>d.current=!0,a))},[a]),isPointerInTransitRef:h,onPointerInTransitChange:m.useCallback(v=>{h.current=v},[]),disableHoverableContent:l,children:u})},"TooltipProvider"),wd="Tooltip",[yE,wi]=bf(wd),wE=at(t=>{const{__scopeTooltip:o,children:s,open:a,defaultOpen:l,onOpenChange:u,disableHoverableContent:d,delayDuration:h}=t,g=jf(wd,t.__scopeTooltip),v=Rl(o),[w,x]=m.useState(null),[C,y]=m.useState(void 0),_=Gr(),b=m.useRef(0),j=d??g.disableHoverableContent,S=h??g.delayDuration,R=m.useRef(!1),[N,E]=gs({prop:a,defaultProp:l??!1,onChange:at(B=>{B?(g.onOpen(),document.dispatchEvent(new CustomEvent(yd))):g.onClose(),u==null||u(B)},"onChange"),caller:wd}),P=m.useMemo(()=>N?R.current?"delayed-open":"instant-open":"closed",[N]),I=m.useCallback(()=>{window.clearTimeout(b.current),b.current=0,R.current=!1,E(!0)},[E]),F=m.useCallback(()=>{window.clearTimeout(b.current),b.current=0,E(!1)},[E]),A=m.useCallback(()=>{window.clearTimeout(b.current),b.current=window.setTimeout(()=>{R.current=!0,E(!0),b.current=0},S)},[S,E]);m.useEffect(()=>()=>{b.current&&(window.clearTimeout(b.current),b.current=0)},[]);const q=C??_;return r.jsx(Sy,{...v,children:r.jsx(yE,{scope:o,contentId:q,setContentId:y,open:N,stateAttribute:P,trigger:w,onTriggerChange:x,onTriggerEnter:m.useCallback(()=>{g.isOpenDelayedRef.current?A():I()},[g.isOpenDelayedRef,A,I]),onTriggerLeave:m.useCallback(()=>{j?F():(window.clearTimeout(b.current),b.current=0)},[F,j]),onOpen:I,onClose:F,disableHoverableContent:j,children:s})})},"Tooltip"),Eg="TooltipTrigger",bE=m.forwardRef(at(function(o,s){const{__scopeTooltip:a,"aria-describedby":l,...u}=o,d=wi(Eg,a),h=jf(Eg,a),g=Rl(a),v=m.useRef(null),w=Fe(s,v,d.onTriggerChange),x=m.useRef(!1),C=m.useRef(!1),y=m.useCallback(()=>x.current=!1,[]);return m.useEffect(()=>()=>document.removeEventListener("pointerup",y),[y]),r.jsx(_y,{asChild:!0,...g,children:r.jsx(Ue.button,{"aria-describedby":d.open?cw(l,d.contentId):l,"data-state":d.stateAttribute,...u,ref:w,onPointerMove:Pe(o.onPointerMove,_=>{_.pointerType!=="touch"&&!C.current&&!h.isPointerInTransitRef.current&&(d.onTriggerEnter(),C.current=!0)}),onPointerLeave:Pe(o.onPointerLeave,()=>{d.onTriggerLeave(),C.current=!1}),onPointerDown:Pe(o.onPointerDown,()=>{d.open&&d.onClose(),x.current=!0,document.addEventListener("pointerup",y,{once:!0})}),onFocus:Pe(o.onFocus,()=>{x.current||d.onOpen()}),onBlur:Pe(o.onBlur,d.onClose),onClick:Pe(o.onClick,d.onClose)})})},"TooltipTrigger")),tw="TooltipPortal",[jE,kE]=bf(tw,{forceMount:void 0}),CE=at(t=>{const{__scopeTooltip:o,forceMount:s,children:a,container:l}=t,u=wi(tw,o);return r.jsx(jE,{scope:o,forceMount:s,children:r.jsx(ur,{present:s||u.open,children:r.jsx(Gd,{asChild:!0,container:l,children:a})})})},"TooltipPortal"),mi="TooltipContent",SE=m.forwardRef(at(function(o,s){const a=kE(mi,o.__scopeTooltip),{forceMount:l=a.forceMount,side:u="top",...d}=o,h=wi(mi,o.__scopeTooltip);return r.jsx(ur,{present:l||h.open,children:h.disableHoverableContent?r.jsx(nw,{side:u,...d,ref:s}):r.jsx(_E,{side:u,...d,ref:s})})},"TooltipContent")),_E=m.forwardRef(at(function(o,s){const a=wi(mi,o.__scopeTooltip),l=jf(mi,o.__scopeTooltip),u=m.useRef(null),d=Fe(s,u),[h,g]=m.useState(null),{trigger:v,onClose:w}=a,x=u.current,{onPointerInTransitChange:C}=l,y=m.useCallback(()=>{g(null),C(!1)},[C]),_=m.useCallback((b,j)=>{const S=b.currentTarget,R={x:b.clientX,y:b.clientY},N=rw(R,S.getBoundingClientRect()),E=ow(R,N),P=sw(j.getBoundingClientRect()),I=aw([...E,...P]);g(I),C(!0)},[C]);return m.useEffect(()=>()=>y(),[y]),m.useEffect(()=>{if(v&&x){const b=at(S=>_(S,x),"handleTriggerLeave"),j=at(S=>_(S,v),"handleContentLeave");return v.addEventListener("pointerleave",b),x.addEventListener("pointerleave",j),()=>{v.removeEventListener("pointerleave",b),x.removeEventListener("pointerleave",j)}}},[v,x,_,y]),m.useEffect(()=>{if(h){const b=at(j=>{const S=j.target,R={x:j.clientX,y:j.clientY},N=(v==null?void 0:v.contains(S))||(x==null?void 0:x.contains(S)),E=!iw(R,h);N?y():E&&(y(),w())},"handleTrackPointerGrace");return document.addEventListener("pointermove",b),()=>document.removeEventListener("pointermove",b)}},[v,x,h,w,y]),r.jsx(nw,{...o,ref:d})},"TooltipContentHoverable")),NE=hx("TooltipContent"),nw=m.forwardRef(at(function(o,s){const{__scopeTooltip:a,children:l,"aria-label":u,id:d,onEscapeKeyDown:h,onPointerDownOutside:g,...v}=o,w=wi(mi,a),x=Rl(a),{onClose:C}=w,[y,_]=m.useState(null),b=Fe(s,_);Vd(y),m.useEffect(()=>(document.addEventListener(yd,C),()=>document.removeEventListener(yd,C)),[C]),m.useEffect(()=>{if(w.trigger){const S=at(R=>{R.target instanceof Node&&R.target.contains(w.trigger)&&C()},"handleScroll");return window.addEventListener("scroll",S,{capture:!0}),()=>window.removeEventListener("scroll",S,{capture:!0})}},[w.trigger,C]);const{setContentId:j}=w;return Rt(()=>(j(d),()=>{j(void 0)}),[d,j]),r.jsx($d,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:h,onPointerDownOutside:g,onFocusOutside:S=>S.preventDefault(),onDismiss:C,children:r.jsxs(Ey,{"data-state":w.stateAttribute,role:u?void 0:"tooltip",id:u?void 0:w.contentId,...x,...v,ref:b,style:{...v.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[r.jsx(NE,{children:l}),u?r.jsx(F1,{id:w.contentId,role:"tooltip",children:u}):null]})})},"TooltipContentImpl")),EE=m.forwardRef(at(function(o,s){const{__scopeTooltip:a,...l}=o,u=Rl(a);return r.jsx(Z_,{...u,...l,ref:s})},"TooltipArrow"));function rw(t,o){const s=Math.abs(o.top-t.y),a=Math.abs(o.bottom-t.y),l=Math.abs(o.right-t.x),u=Math.abs(o.left-t.x);switch(Math.min(s,a,l,u)){case u:return"left";case l:return"right";case s:return"top";case a:return"bottom";default:throw new Error("unreachable")}}at(rw,"getExitSideFromRect");function ow(t,o,s=5){const a=[];switch(o){case"top":a.push({x:t.x-s,y:t.y+s},{x:t.x+s,y:t.y+s});break;case"bottom":a.push({x:t.x-s,y:t.y-s},{x:t.x+s,y:t.y-s});break;case"left":a.push({x:t.x+s,y:t.y-s},{x:t.x+s,y:t.y+s});break;case"right":a.push({x:t.x-s,y:t.y-s},{x:t.x-s,y:t.y+s});break}return a}at(ow,"getPaddedExitPoints");function sw(t){const{top:o,right:s,bottom:a,left:l}=t;return[{x:l,y:o},{x:s,y:o},{x:s,y:a},{x:l,y:a}]}at(sw,"getPointsFromRect");function iw(t,o){const{x:s,y:a}=t;let l=!1;for(let u=0,d=o.length-1;ua!=C>a&&s<(x-v)*(a-w)/(C-w)+v&&(l=!l)}return l}at(iw,"isPointInPolygon");function aw(t){const o=t.slice();return o.sort((s,a)=>s.xa.x?1:s.ya.y?1:0),lw(o)}at(aw,"getHull");function lw(t){if(t.length<=1)return t.slice();const o=[];for(let a=0;a=2;){const u=o[o.length-1],d=o[o.length-2];if((u.x-d.x)*(l.y-d.y)>=(u.y-d.y)*(l.x-d.x))o.pop();else break}o.push(l)}o.pop();const s=[];for(let a=t.length-1;a>=0;a--){const l=t[a];for(;s.length>=2;){const u=s[s.length-1],d=s[s.length-2];if((u.x-d.x)*(l.y-d.y)>=(u.y-d.y)*(l.x-d.x))s.pop();else break}s.push(l)}return s.pop(),o.length===1&&s.length===1&&o[0].x===s[0].x&&o[0].y===s[0].y?o:o.concat(s)}at(lw,"getHullPresorted");function cw(...t){const o=new Set;for(const s of t)if(typeof s=="string")for(const a of String(s).trim().split(/\s+/))a&&o.add(a);return o.size>0?Array.from(o).join(" "):void 0}at(cw,"concatAriaDescribedby");const RE=gl("inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",xs:"h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",sm:"h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9","icon-xs":"size-6 rounded-md [&_svg:not([class*='size-'])]:size-3","icon-sm":"size-8","icon-lg":"size-10"}},defaultVariants:{variant:"default",size:"default"}});function re({className:t,variant:o="default",size:s="default",asChild:a=!1,...l}){const u=a?Md:"button";return r.jsx(u,{"data-slot":"button","data-variant":o,"data-size":s,className:ie(RE({variant:o,size:s,className:t})),...l})}function PE({...t}){return r.jsx(pS,{"data-slot":"alert-dialog",...t})}function TE({...t}){return r.jsx(mS,{"data-slot":"alert-dialog-portal",...t})}function DE({className:t,...o}){return r.jsx(gS,{"data-slot":"alert-dialog-overlay",className:ie("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",t),...o})}function OE({className:t,size:o="default",...s}){return r.jsxs(TE,{children:[r.jsx(DE,{}),r.jsx(wS,{"data-slot":"alert-dialog-content","data-size":o,className:ie("group/alert-dialog-content fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 data-[size=sm]:max-w-xs data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[size=default]:sm:max-w-lg",t),...s})]})}function ME({className:t,...o}){return r.jsx("div",{"data-slot":"alert-dialog-header",className:ie("grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-6 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",t),...o})}function AE({className:t,...o}){return r.jsx("div",{"data-slot":"alert-dialog-footer",className:ie("flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end",t),...o})}function LE({className:t,...o}){return r.jsx(bS,{"data-slot":"alert-dialog-title",className:ie("text-lg font-semibold sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",t),...o})}function IE({className:t,...o}){return r.jsx(jS,{"data-slot":"alert-dialog-description",className:ie("text-sm text-muted-foreground",t),...o})}function zE({className:t,variant:o="default",size:s="default",...a}){return r.jsx(re,{variant:o,size:s,asChild:!0,children:r.jsx(kS,{"data-slot":"alert-dialog-action",className:ie(t),...a})})}function FE({className:t,variant:o="outline",size:s="default",...a}){return r.jsx(re,{variant:o,size:s,asChild:!0,children:r.jsx(SS,{"data-slot":"alert-dialog-cancel",className:ie(t),...a})})}const $E=gl("inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-full border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3",{variants:{variant:{default:"bg-primary text-primary-foreground [a&]:hover:bg-primary/90",secondary:"bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",destructive:"bg-destructive text-white focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40 [a&]:hover:bg-destructive/90",outline:"border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",ghost:"[a&]:hover:bg-accent [a&]:hover:text-accent-foreground",link:"text-primary underline-offset-4 [a&]:hover:underline"}},defaultVariants:{variant:"default"}});function Tt({className:t,variant:o="default",asChild:s=!1,...a}){const l=s?Md:"span";return r.jsx(l,{"data-slot":"badge","data-variant":o,className:ie($E({variant:o}),t),...a})}function ve({className:t,type:o,...s}){return r.jsx("input",{type:o,"data-slot":"input",className:ie("h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:bg-input/30","focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50","aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40",t),...s})}function uw({className:t,...o}){return r.jsx(uE,{"data-slot":"label",className:ie("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",t),...o})}function lt({className:t,...o}){return r.jsx("div",{"data-slot":"card",className:ie("flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm",t),...o})}function cn({className:t,...o}){return r.jsx("div",{"data-slot":"card-header",className:ie("@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",t),...o})}function yn({className:t,...o}){return r.jsx("div",{"data-slot":"card-title",className:ie("leading-none font-semibold",t),...o})}function wn({className:t,...o}){return r.jsx("div",{"data-slot":"card-description",className:ie("text-sm text-muted-foreground",t),...o})}function Pt({className:t,...o}){return r.jsx("div",{"data-slot":"card-content",className:ie("px-6",t),...o})}function dw({className:t,...o}){return r.jsx("div",{"data-slot":"card-footer",className:ie("flex items-center px-6 [.border-t]:pt-6",t),...o})}function fw({...t}){return r.jsx(Qd,{"data-slot":"sheet",...t})}function UE({...t}){return r.jsx(Xd,{"data-slot":"sheet-portal",...t})}function BE({className:t,...o}){return r.jsx(Jd,{"data-slot":"sheet-overlay",className:ie("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",t),...o})}function hw({className:t,children:o,side:s="right",showCloseButton:a=!0,...l}){return r.jsxs(UE,{children:[r.jsx(BE,{}),r.jsxs(Zd,{"data-slot":"sheet-content",className:ie("fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500",s==="right"&&"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",s==="left"&&"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",s==="top"&&"inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",s==="bottom"&&"inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",t),...l,children:[o,a&&r.jsxs(xi,{className:"absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-secondary",children:[r.jsx(Pd,{className:"size-4"}),r.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function pw({className:t,...o}){return r.jsx("div",{"data-slot":"sheet-header",className:ie("flex flex-col gap-1.5 p-4",t),...o})}function mw({className:t,...o}){return r.jsx(ef,{"data-slot":"sheet-title",className:ie("font-semibold text-foreground",t),...o})}function gw({className:t,...o}){return r.jsx(tf,{"data-slot":"sheet-description",className:ie("text-sm text-muted-foreground",t),...o})}function an({className:t,...o}){return r.jsx("textarea",{"data-slot":"textarea",className:ie("flex field-sizing-content min-h-16 w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:aria-invalid:ring-destructive/40",t),...o})}const vw=m.createContext(()=>{}),et=()=>m.useContext(vw);function WE({children:t}){const[o,s]=m.useState(null),a=m.useRef(),l=m.useCallback((u,d=!1)=>{u&&(s(h=>({msg:u,err:d,n:((h==null?void 0:h.n)??0)+1})),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s(null),u.length>80?7e3:4e3))},[]);return m.useEffect(()=>{const u=d=>l(String(d.detail||""));return window.addEventListener("crc-notice",u),()=>window.removeEventListener("crc-notice",u)},[l]),r.jsxs(vw.Provider,{value:l,children:[t,r.jsx("div",{"aria-live":"polite",className:"pointer-events-none fixed right-4 bottom-4 left-4 z-50 flex justify-end sm:left-auto",children:o&&r.jsxs("div",{id:"toast",role:"status",className:ie("pointer-events-auto flex max-w-md items-start gap-2 rounded-lg border bg-popover px-4 py-3 text-sm text-popover-foreground shadow-lg animate-in fade-in slide-in-from-bottom-2",o.err&&"border-destructive/40"),children:[o.err?r.jsx(dv,{className:"mt-0.5 size-4 shrink-0 text-destructive"}):r.jsx(ik,{className:"mt-0.5 size-4 shrink-0 text-success"}),r.jsx("span",{children:o.msg})]},o.n)})]})}const Ee=t=>t instanceof Error?t.message:String(t),xw=m.createContext(async()=>!1),to=()=>m.useContext(xw);function VE({children:t}){const[o,s]=m.useState(null),a=m.useRef(),l=m.useCallback(d=>(s(d),new Promise(h=>a.current=h)),[]),u=d=>{var h;(h=a.current)==null||h.call(a,d),s(null)};return r.jsxs(xw.Provider,{value:l,children:[t,r.jsx(PE,{open:!!o,onOpenChange:d=>!d&&u(!1),children:r.jsxs(OE,{children:[r.jsxs(ME,{children:[r.jsx(LE,{children:o==null?void 0:o.title}),(o==null?void 0:o.description)&&r.jsx(IE,{children:o.description})]}),r.jsxs(AE,{children:[r.jsx(FE,{onClick:()=>u(!1),children:"Cancel"}),r.jsx(zE,{className:ie((o==null?void 0:o.danger)&&"bg-destructive text-white hover:bg-destructive/90"),onClick:()=>u(!0),children:(o==null?void 0:o.action)??"Continue"})]})]})})]})}const yw=m.createContext(null),no=()=>m.useContext(yw),ww=m.createContext(()=>{}),bi=()=>m.useContext(ww),al={hosts:"Multiple code hosts and bot identities",rules:"Group and pattern rules",learnings:"Team learnings",executors:"Docker and Kubernetes executors",budgets:"Token budgets",metrics:"Metrics and long history",audit:"Audit log",branch_sync:"Branch-sync skip",sso_rules:"SSO domain and group rules"};function qt(t){return no().license.features.includes(t)}function ji({feature:t,children:o}){return r.jsxs(Zn,{role:"note",className:"locked border-dashed border-primary/60",children:[r.jsx(Cv,{className:"text-primary"}),r.jsxs(ux,{className:"flex items-center gap-2",children:[al[t],r.jsx(Tt,{variant:"secondary",children:"licensed"})]}),r.jsx(er,{children:r.jsxs("p",{children:[o??"This is part of the licensed Divmora console."," ",r.jsx(Yt,{className:"font-medium text-primary underline-offset-4 hover:underline",to:"/license",children:"Install a license"})," ","or contact"," ",r.jsx("a",{className:"font-medium text-primary underline-offset-4 hover:underline",href:"mailto:licensing@divmora.com",children:"licensing@divmora.com"}),"."]})})]})}function Qa({feature:t}){return qt(t)?null:r.jsxs("span",{className:"locknote block text-xs leading-snug text-warning",children:[r.jsx(Cv,{className:"mr-1 inline size-3 align-[-2px]"}),"Needs a license with ",al[t].toLowerCase()," ·"," ",r.jsx(Yt,{to:"/license",className:"underline underline-offset-2",children:"License"})]})}function un({children:t,className:o}){return r.jsx(lt,{className:ie("gap-0 overflow-hidden py-0",o),children:t})}function ko({open:t,onClose:o,title:s,description:a,children:l,wide:u}){return r.jsx(fw,{open:t,onOpenChange:d=>!d&&o(),children:r.jsxs(hw,{className:ie("w-full gap-0 overflow-y-auto sm:max-w-xl",u&&"sm:max-w-3xl"),children:[r.jsxs(pw,{className:"border-b pr-10",children:[r.jsx(mw,{children:s}),a&&r.jsx(gw,{children:a})]}),r.jsx("div",{className:"p-4",children:l})]})})}function lr({children:t,className:o}){return r.jsx("div",{className:ie("flex flex-wrap items-center gap-2",o),children:t})}function He({children:t,className:o}){return r.jsx("p",{className:ie("max-w-4xl text-sm leading-relaxed text-muted-foreground",o),children:t})}function qe({children:t}){return r.jsx("div",{className:"px-4 py-10 text-center text-sm text-muted-foreground",children:t})}function ee({label:t,children:o,hint:s,className:a}){return r.jsxs("div",{className:ie("grid content-start gap-1.5",a),children:[r.jsx(uw,{className:"text-xs font-medium text-muted-foreground",children:t}),o,s]})}function Ge({children:t,className:o}){return r.jsx("div",{className:ie("grid gap-4 sm:grid-cols-2 lg:grid-cols-3",o),children:t})}function Ne({className:t,...o}){return r.jsx("select",{className:ie("h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-xs outline-none transition-[color,box-shadow] dark:bg-input/30","focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50",t),...o})}const HE={on:"border-transparent bg-success-soft text-success",off:"border-transparent bg-danger-soft text-destructive",idle:"border-transparent bg-muted text-muted-foreground",warn:"border-transparent bg-warning-soft text-warning"};function Je({kind:t,children:o,className:s,title:a}){return r.jsx(Tt,{className:ie("state",t,HE[t],s),title:a,children:o})}function bd({items:t,empty:o}){return t.length?r.jsx("span",{className:"flex flex-wrap gap-1",children:t.map(s=>r.jsx(Tt,{variant:"outline",className:"chip font-normal text-muted-foreground",children:s},s))}):r.jsx("span",{className:"text-sm text-muted-foreground",children:o??"defaults"})}function ne({children:t,className:o,title:s}){return r.jsx("div",{title:s,className:ie("mt-0.5 text-xs text-muted-foreground",o),children:t})}function bw(t={}){const o=[];return t.profile&&o.push(t.profile),t.max_comments&&o.push("max "+t.max_comments),t.min_severity&&o.push("≥ "+t.min_severity),t.model&&o.push("model "+t.model),t.auto_review===!1&&o.push("auto review off"),t.auto_review===!0&&o.push("auto review on"),t.drafts===!0&&o.push("drafts"),t.instructions&&o.push("instructions"),o}function ll({value:t,onChange:o,on:s,off:a,inherit:l="Inherit",label:u,disabled:d}){const h=t==null?"":String(t);return r.jsxs(Ne,{"aria-label":u,value:h,disabled:d,onChange:g=>o(g.target.value===""?null:g.target.value==="true"),children:[r.jsx("option",{value:"",children:l}),r.jsx("option",{value:"true",children:s}),r.jsx("option",{value:"false",children:a})]})}function kf({value:t,onSave:o,onCancel:s,extra:a,inheritModel:l="Server default",saveLabel:u="Save settings",danger:d}){const h=no(),g=t??{},[v,w]=m.useState(g.profile??""),[x,C]=m.useState(g.max_comments?String(g.max_comments):""),[y,_]=m.useState(g.min_severity??""),[b,j]=m.useState(g.model??""),[S,R]=m.useState(g.auto_review??null),[N,E]=m.useState(g.drafts??null),[P,I]=m.useState(g.instructions??""),F=()=>{const A={};v&&(A.profile=v),x&&(A.max_comments=parseInt(x,10)),y&&(A.min_severity=y),b&&(A.model=b),S!==null&&(A.auto_review=S),N!==null&&(A.drafts=N),P.trim()&&(A.instructions=P.trim()),o(A)};return r.jsxs("div",{className:"grid gap-5",children:[a,r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ee,{label:"Review profile",children:r.jsxs(Ne,{value:v,onChange:A=>w(A.target.value),children:[r.jsx("option",{value:"",children:"Inherit"}),r.jsx("option",{value:"chill",children:"Chill"}),r.jsx("option",{value:"balanced",children:"Balanced"}),r.jsx("option",{value:"assertive",children:"Assertive"})]})}),r.jsx(ee,{label:"Max inline comments",children:r.jsx(ve,{type:"number",min:0,max:200,value:x,placeholder:"Inherit",onChange:A=>C(A.target.value)})}),r.jsx(ee,{label:"Minimum severity",children:r.jsxs(Ne,{value:y,onChange:A=>_(A.target.value),children:[r.jsx("option",{value:"",children:"Inherit"}),r.jsx("option",{value:"critical",children:"Critical"}),r.jsx("option",{value:"major",children:"Major"}),r.jsx("option",{value:"minor",children:"Minor"}),r.jsx("option",{value:"nitpick",children:"Nitpick"})]})}),r.jsx(ee,{label:"Model profile",children:r.jsxs(Ne,{value:b,onChange:A=>j(A.target.value),children:[r.jsx("option",{value:"",children:l}),h.profiles.map(A=>r.jsx("option",{value:A,children:A},A))]})}),r.jsx(ee,{label:"Auto review on push",children:r.jsx(ll,{value:S,onChange:R,on:"On",off:"Off"})}),r.jsx(ee,{label:"Review draft PRs",children:r.jsx(ll,{value:N,onChange:E,on:"On",off:"Off"})})]}),r.jsx(ee,{label:"Extra review instructions",children:r.jsx(an,{rows:4,maxLength:8e3,placeholder:"Appended to the repository's own instructions",value:P,onChange:A=>I(A.target.value)})}),r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx(re,{onClick:F,children:u}),s&&r.jsx(re,{variant:"outline",onClick:s,children:"Cancel"}),r.jsx("span",{className:"flex-1"}),d]})]})}function jw(t){if(!t)return"";const o=/Edg\//.test(t)?"Edge":/OPR\//.test(t)?"Opera":/Firefox\//.test(t)?"Firefox":/Chrome\//.test(t)?"Chrome":/Safari\//.test(t)?"Safari":"",s=/Android/.test(t)?"Android":/iPhone|iPad/.test(t)?"iOS":/Windows/.test(t)?"Windows":/Mac OS X|Macintosh/.test(t)?"macOS":/Linux/.test(t)?"Linux":"";return o?s?o+" on "+s:o:t.length>40?t.slice(0,40)+"…":t}let jd=class extends m.Component{constructor(){super(...arguments),this.state={}}static getDerivedStateFromError(o){return{error:o}}componentDidCatch(o){console.error(`${this.props.name} failed to render`,o)}render(){return this.state.error?r.jsxs(Zn,{variant:"destructive",children:[r.jsx(dv,{}),r.jsxs(ux,{children:[this.props.name," could not be shown"]}),r.jsxs(er,{children:[this.state.error.message,". Reload the page; if it happens again, report it with the browser console output."]})]}):this.props.children}};function GE({...t}){return r.jsx(XN,{"data-slot":"dropdown-menu",...t})}function KE({...t}){return r.jsx(ZN,{"data-slot":"dropdown-menu-trigger",...t})}function qE({className:t,sideOffset:o=4,...s}){return r.jsx(eE,{children:r.jsx(nE,{"data-slot":"dropdown-menu-content",sideOffset:o,className:ie("z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",t),...s})})}function YE({...t}){return r.jsx(oE,{"data-slot":"dropdown-menu-radio-group",...t})}function $u({className:t,children:o,...s}){return r.jsxs(sE,{"data-slot":"dropdown-menu-radio-item",className:ie("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",t),...s,children:[r.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:r.jsx(iE,{children:r.jsx(hv,{className:"size-2 fill-current"})})}),o]})}function QE({className:t,inset:o,...s}){return r.jsx(rE,{"data-slot":"dropdown-menu-label","data-inset":o,className:ie("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",t),...s})}function XE({className:t,...o}){return r.jsx(aE,{"data-slot":"dropdown-menu-separator",className:ie("-mx-1 my-1 h-px bg-border",t),...o})}function cs({className:t,orientation:o="horizontal",decorative:s=!0,...a}){return r.jsx(hE,{"data-slot":"separator",decorative:s,orientation:o,className:ie("shrink-0 bg-border data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",t),...a})}const Uu=768;function JE(){const[t,o]=m.useState(void 0);return m.useEffect(()=>{const s=window.matchMedia(`(max-width: ${Uu-1}px)`),a=()=>{o(window.innerWidths.removeEventListener("change",a)},[]),!!t}function kw({delayDuration:t=0,...o}){return r.jsx(xE,{"data-slot":"tooltip-provider",delayDuration:t,...o})}function ZE({...t}){return r.jsx(wE,{"data-slot":"tooltip",...t})}function e2({...t}){return r.jsx(bE,{"data-slot":"tooltip-trigger",...t})}function t2({className:t,sideOffset:o=0,children:s,...a}){return r.jsx(CE,{children:r.jsxs(SE,{"data-slot":"tooltip-content",sideOffset:o,className:ie("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",t),...a,children:[s,r.jsx(EE,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}const n2="sidebar_state",r2=3600*24*7,o2="16rem",s2="18rem",i2="3rem",a2="b",Cw=m.createContext(null);function ki(){const t=m.useContext(Cw);if(!t)throw new Error("useSidebar must be used within a SidebarProvider.");return t}function l2({defaultOpen:t=!0,open:o,onOpenChange:s,className:a,style:l,children:u,...d}){const h=JE(),[g,v]=m.useState(!1),[w,x]=m.useState(t),C=o??w,y=m.useCallback(S=>{const R=typeof S=="function"?S(C):S;s?s(R):x(R),document.cookie=`${n2}=${R}; path=/; max-age=${r2}`},[s,C]),_=m.useCallback(()=>h?v(S=>!S):y(S=>!S),[h,y,v]);m.useEffect(()=>{const S=R=>{R.key===a2&&(R.metaKey||R.ctrlKey)&&(R.preventDefault(),_())};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[_]);const b=C?"expanded":"collapsed",j=m.useMemo(()=>({state:b,open:C,setOpen:y,isMobile:h,openMobile:g,setOpenMobile:v,toggleSidebar:_}),[b,C,y,h,g,v,_]);return r.jsx(Cw.Provider,{value:j,children:r.jsx(kw,{delayDuration:0,children:r.jsx("div",{"data-slot":"sidebar-wrapper",style:{"--sidebar-width":o2,"--sidebar-width-icon":i2,...l},className:ie("group/sidebar-wrapper flex min-h-svh w-full has-data-[variant=inset]:bg-sidebar",a),...d,children:u})})})}function c2({side:t="left",variant:o="sidebar",collapsible:s="offcanvas",className:a,children:l,...u}){const{isMobile:d,state:h,openMobile:g,setOpenMobile:v}=ki();return s==="none"?r.jsx("div",{"data-slot":"sidebar",className:ie("flex h-full w-(--sidebar-width) flex-col bg-sidebar text-sidebar-foreground",a),...u,children:l}):d?r.jsx(fw,{open:g,onOpenChange:v,...u,children:r.jsxs(hw,{"data-sidebar":"sidebar","data-slot":"sidebar","data-mobile":"true",className:"w-(--sidebar-width) bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden",style:{"--sidebar-width":s2},side:t,children:[r.jsxs(pw,{className:"sr-only",children:[r.jsx(mw,{children:"Sidebar"}),r.jsx(gw,{children:"Displays the mobile sidebar."})]}),r.jsx("div",{className:"flex h-full w-full flex-col",children:l})]})}):r.jsxs("div",{className:"group peer hidden text-sidebar-foreground md:block","data-state":h,"data-collapsible":h==="collapsed"?s:"","data-variant":o,"data-side":t,"data-slot":"sidebar",children:[r.jsx("div",{"data-slot":"sidebar-gap",className:ie("relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear","group-data-[collapsible=offcanvas]:w-0","group-data-[side=right]:rotate-180",o==="floating"||o==="inset"?"group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]":"group-data-[collapsible=icon]:w-(--sidebar-width-icon)")}),r.jsx("div",{"data-slot":"sidebar-container",className:ie("fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear md:flex",t==="left"?"left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]":"right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",o==="floating"||o==="inset"?"p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]":"group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",a),...u,children:r.jsx("div",{"data-sidebar":"sidebar","data-slot":"sidebar-inner",className:"flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow-sm",children:l})})]})}function u2({className:t,onClick:o,...s}){const{toggleSidebar:a}=ki();return r.jsxs(re,{"data-sidebar":"trigger","data-slot":"sidebar-trigger",variant:"ghost",size:"icon",className:ie("size-7",t),onClick:l=>{o==null||o(l),a()},...s,children:[r.jsx(gk,{}),r.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})}function d2({className:t,...o}){const{toggleSidebar:s}=ki();return r.jsx("button",{"data-sidebar":"rail","data-slot":"sidebar-rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:s,title:"Toggle Sidebar",className:ie("absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border sm:flex","in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize","[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize","group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full hover:group-data-[collapsible=offcanvas]:bg-sidebar","[[data-side=left][data-collapsible=offcanvas]_&]:-right-2","[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",t),...o})}function f2({className:t,...o}){return r.jsx("main",{"data-slot":"sidebar-inset",className:ie("relative flex w-full flex-1 flex-col bg-background","md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2",t),...o})}function h2({className:t,...o}){return r.jsx("div",{"data-slot":"sidebar-header","data-sidebar":"header",className:ie("flex flex-col gap-2 p-2",t),...o})}function p2({className:t,...o}){return r.jsx("div",{"data-slot":"sidebar-footer","data-sidebar":"footer",className:ie("flex flex-col gap-2 p-2",t),...o})}function m2({className:t,...o}){return r.jsx("div",{"data-slot":"sidebar-content","data-sidebar":"content",className:ie("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",t),...o})}function g2({className:t,...o}){return r.jsx("div",{"data-slot":"sidebar-group","data-sidebar":"group",className:ie("relative flex w-full min-w-0 flex-col p-2",t),...o})}function v2({className:t,...o}){return r.jsx("div",{"data-slot":"sidebar-group-content","data-sidebar":"group-content",className:ie("w-full text-sm",t),...o})}function Rg({className:t,...o}){return r.jsx("ul",{"data-slot":"sidebar-menu","data-sidebar":"menu",className:ie("flex w-full min-w-0 flex-col gap-1",t),...o})}function Pg({className:t,...o}){return r.jsx("li",{"data-slot":"sidebar-menu-item","data-sidebar":"menu-item",className:ie("group/menu-item relative",t),...o})}const x2=gl("peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm ring-sidebar-ring outline-hidden transition-[width,height,padding] group-has-data-[sidebar=menu-action]/menu-item:pr-8 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",{variants:{variant:{default:"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",outline:"bg-background shadow-[0_0_0_1px_var(--sidebar-border)] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_var(--sidebar-accent)]"},size:{default:"h-8 text-sm",sm:"h-7 text-xs",lg:"h-12 text-sm group-data-[collapsible=icon]:p-0!"}},defaultVariants:{variant:"default",size:"default"}});function Tg({asChild:t=!1,isActive:o=!1,variant:s="default",size:a="default",tooltip:l,className:u,...d}){const h=t?Md:"button",{isMobile:g,state:v}=ki(),w=r.jsx(h,{"data-slot":"sidebar-menu-button","data-sidebar":"menu-button","data-size":a,"data-active":o,className:ie(x2({variant:s,size:a}),u),...d});return l?(typeof l=="string"&&(l={children:l}),r.jsxs(ZE,{children:[r.jsx(e2,{asChild:!0,children:w}),r.jsx(t2,{side:"right",align:"center",hidden:v!=="collapsed"||g,...l})]})):w}function Bu({className:t,...o}){return r.jsx("div",{"data-slot":"sidebar-menu-badge","data-sidebar":"menu-badge",className:ie("pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium text-sidebar-foreground tabular-nums select-none","peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",t),...o})}function y2({className:t,title:o}){return r.jsxs("svg",{viewBox:"0 0 32 32",fill:"none",className:ie("size-8 shrink-0",t),role:o?"img":void 0,"aria-hidden":o?void 0:!0,children:[o&&r.jsx("title",{children:o}),r.jsx("rect",{x:"0.5",y:"0.5",width:"31",height:"31",rx:"6.5",className:"fill-[#0F172A] stroke-[#0F172A] dark:fill-[#1E293B] dark:stroke-[#334155]"}),r.jsx("path",{d:"M10 10 5 16l5 6M22 10l5 6-5 6",stroke:"#60A5FA",strokeWidth:"2.6",strokeLinecap:"round",strokeLinejoin:"round"}),r.jsx("path",{d:"m12 16.5 3 3 5.5-7",stroke:"#FFFFFF",strokeWidth:"2.6",strokeLinecap:"round",strokeLinejoin:"round"})]})}const Sw=[["done","Reviewed","--st-done"],["skipped","Skipped","--st-skip"],["failed","Failed","--st-fail"]];function Cf(t){const o=[],s={};t.points.forEach(h=>s[new Date(h.bucket).toISOString()]=h);const a=new Date(t.to),l=new Date(t.from);if(t.granularity==="month"){let h=new Date(Date.UTC(l.getUTCFullYear(),l.getUTCMonth(),1));for(;htypeof t[o]=="number"?t[o]:0;function kd({points:t,granularity:o,series:s,label:a}){const l=!!s,u=s??Sw,d=m.useRef(null),[h,g]=m.useState(900),[v,w]=m.useState(null);m.useEffect(()=>{const B=d.current;if(!B)return;const z=new ResizeObserver(()=>g(Math.max(320,B.clientWidth||900)));return z.observe(B),()=>z.disconnect()},[]);const x=h,C=200,y=34,_=8,b=8,j=24;let S=0;t.forEach(B=>S=Math.max(S,u.reduce((z,[Z])=>z+ts(B,Z),0)));const R=S<=4?4:Math.pow(10,Math.floor(Math.log10(S))),N=Math.ceil(S/R)*R||4,E=(x-y-_)/Math.max(1,t.length),P=Math.min(24,Math.max(2,E*.7)),I=B=>b+(C-b-j)*(1-B/N),F=Math.ceil(t.length/Math.max(2,Math.floor((x-y-_)/70))),A=v!==null?t[v]:null,q=v!==null?Math.min(x-170,Math.max(0,y+E*v+E/2+12)):0;return r.jsxs("div",{className:"chart relative w-full",ref:d,children:[r.jsxs("svg",{className:"block h-auto w-full",viewBox:`0 0 ${x} ${C}`,role:"img","aria-label":a??`Jobs per ${o}: reviewed, skipped and failed`,children:[t.map((B,z)=>r.jsx("rect",{x:y+E*z,y:b,width:E,height:C-b-j,fill:v===z?"var(--muted)":"transparent",fillOpacity:.5,tabIndex:0,onMouseEnter:()=>w(z),onMouseLeave:()=>w(null),onFocus:()=>w(z),onBlur:()=>w(null)},"h"+z)),[0,N/2,N].map(B=>r.jsxs("g",{pointerEvents:"none",children:[r.jsx("line",{x1:y,x2:x-_,y1:I(B),y2:I(B),stroke:"var(--grid)",strokeWidth:1}),r.jsx("text",{x:y-6,y:I(B)+4,textAnchor:"end",fontSize:11,fill:"var(--muted-foreground)",children:ze(B)})]},"g"+B)),t.map((B,z)=>{const Z=y+E*z+(E-P)/2,se=u.map(([ye,,ae])=>[ts(B,ye),ae]).filter(([ye])=>ye>0);let he=0;return r.jsxs("g",{pointerEvents:"none",children:[se.map(([ye,ae],oe)=>{let H=I(he+ye);const J=I(he)-(oe>0?2:0);J-H<1&&(H=J-1);const $=oe===se.length-1?Math.min(4,P/2,J-H):0;he+=ye;const O=`M${Z},${J}V${H+$}Q${Z},${H} ${Z+$},${H}H${Z+P-$}Q${Z+P},${H} ${Z+P},${H+$}V${J}Z`;return r.jsx("path",{d:O,fill:`var(${ae})`},oe)}),z%F===0&&r.jsx("text",{x:y+E*z+E/2,y:C-j+16,textAnchor:"middle",fontSize:11,fill:"var(--muted-foreground)",children:cl(B.bucket,o)})]},"b"+z)}),r.jsx("line",{x1:y,x2:x-_,y1:C-j,y2:C-j,stroke:"var(--grid)",strokeWidth:1,pointerEvents:"none"})]}),r.jsx("div",{className:"tip pointer-events-none absolute z-10 w-40 rounded-md border bg-popover p-2.5 text-xs text-popover-foreground shadow-md [&>div]:flex [&>div]:justify-between [&>div]:gap-3 [&>div>span:first-child]:text-muted-foreground "+(A?"show block":"hidden"),id:"mTip",ref:B=>B&&(B.style.left=q+"px",B.style.top="28px"),children:A&&r.jsxs(r.Fragment,{children:[r.jsx("b",{className:"mb-1 block font-semibold",children:cl(A.bucket,o,!0)}),u.map(([B,z])=>r.jsxs("div",{children:[r.jsx("span",{children:z}),r.jsx("span",{children:ts(A,B)})]},B)),!l&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{children:[r.jsx("span",{children:"Comments"}),r.jsx("span",{children:ts(A,"comments")})]}),r.jsxs("div",{children:[r.jsx("span",{children:"Tokens"}),r.jsx("span",{children:ze(ts(A,"tokens_in")+ts(A,"tokens_out"))})]})]})]})})]})}const ln=[["quality","Quality","--sc-quality"],["security","Security","--sc-security"],["maintainability","Maintainability","--sc-maintainability"]];function ds(t,o){const s=t.scored||0;return s?(t[o+"_sum"]||0)/s:null}function w2(t){return t>=80?"bg-success-soft text-success":t>=50?"bg-warning-soft text-warning":"bg-danger-soft text-destructive"}function _w({s:t,className:o}){return t?r.jsx("span",{className:ie("inline-flex gap-1",o),children:ln.map(([s,a])=>r.jsxs("span",{title:`${a} ${t[s]}`,className:ie("inline-flex min-w-9 items-center justify-center rounded px-1.5 py-0.5 text-xs font-medium tabular-nums",w2(t[s])),children:[r.jsx("span",{className:"mr-0.5 opacity-70",children:a[0]}),t[s]]},s))}):r.jsx("span",{className:"text-xs text-muted-foreground",children:"–"})}function Nw(t,o,s,a){let l="",u=!1;return t.forEach((d,h)=>{const g=ds(d,o);if(g===null){u=!1;return}l+=(u?"L":"M")+s(h).toFixed(1)+","+a(g).toFixed(1),u=!0}),l}function b2({points:t,label:o}){if(t.filter(d=>d.scored).length<2)return r.jsx("span",{className:"text-xs text-muted-foreground",children:"–"});const l=d=>t.length<2?96/2:2+92*d/(t.length-1),u=d=>2+20*(1-d/100);return r.jsx("svg",{width:96,height:24,viewBox:"0 0 96 24",role:"img","aria-label":o,className:"block",children:ln.map(([d,,h])=>{const g=Nw(t,d,l,u);return g.includes("L")?r.jsx("path",{d:g,fill:"none",stroke:`var(${h})`,strokeWidth:1.5,strokeLinejoin:"round"},d):null})})}function Sf({points:t,granularity:o}){const s=m.useRef(null),[a,l]=m.useState(900),[u,d]=m.useState(null);m.useEffect(()=>{const N=s.current;if(!N)return;const E=new ResizeObserver(()=>l(Math.max(320,N.clientWidth||900)));return E.observe(N),()=>E.disconnect()},[]);const h=a,g=160,v=34,w=8,x=8,C=24,y=(h-v-w)/Math.max(1,t.length),_=N=>v+y*N+y/2,b=N=>x+(g-x-C)*(1-N/100),j=Math.ceil(t.length/Math.max(2,Math.floor((h-v-w)/70))),S=u!==null?t[u]:null,R=u!==null?Math.min(h-170,Math.max(0,_(u)+12)):0;return r.jsxs("div",{className:"relative w-full",ref:s,children:[r.jsxs("svg",{className:"block h-auto w-full",viewBox:`0 0 ${h} ${g}`,role:"img","aria-label":`Average review scores per ${o}`,children:[t.map((N,E)=>r.jsx("rect",{x:v+y*E,y:x,width:y,height:g-x-C,fill:u===E?"var(--muted)":"transparent",fillOpacity:.5,tabIndex:0,onMouseEnter:()=>d(E),onMouseLeave:()=>d(null),onFocus:()=>d(E),onBlur:()=>d(null)},"h"+E)),[0,50,80,100].map(N=>r.jsxs("g",{pointerEvents:"none",children:[r.jsx("line",{x1:v,x2:h-w,y1:b(N),y2:b(N),stroke:"var(--grid)",strokeWidth:1,strokeDasharray:N===50||N===80?"3 3":void 0}),r.jsx("text",{x:v-6,y:b(N)+4,textAnchor:"end",fontSize:11,fill:"var(--muted-foreground)",children:N})]},"g"+N)),ln.map(([N,,E])=>r.jsxs("g",{pointerEvents:"none",children:[r.jsx("path",{d:Nw(t,N,_,b),fill:"none",stroke:`var(${E})`,strokeWidth:2,strokeLinejoin:"round"}),t.map((P,I)=>{const F=ds(P,N);return F===null?null:r.jsx("circle",{cx:_(I),cy:b(F),r:u===I?3.5:2,fill:`var(${E})`},I)})]},N)),t.map((N,E)=>E%j===0?r.jsx("text",{x:_(E),y:g-C+16,textAnchor:"middle",fontSize:11,fill:"var(--muted-foreground)",pointerEvents:"none",children:cl(N.bucket,o)},"t"+E):null)]}),r.jsx("div",{className:"pointer-events-none absolute z-10 w-40 rounded-md border bg-popover p-2.5 text-xs text-popover-foreground shadow-md [&>div]:flex [&>div]:justify-between [&>div]:gap-3 [&>div>span:first-child]:text-muted-foreground "+(S?"block":"hidden"),ref:N=>N&&(N.style.left=R+"px",N.style.top="20px"),children:S&&r.jsxs(r.Fragment,{children:[r.jsx("b",{className:"mb-1 block font-semibold",children:cl(S.bucket,o,!0)}),ln.map(([N,E])=>{const P=ds(S,N);return r.jsxs("div",{children:[r.jsx("span",{children:E}),r.jsx("span",{children:P===null?"–":Math.round(P)})]},N)}),r.jsxs("div",{children:[r.jsx("span",{children:"Scored reviews"}),r.jsx("span",{children:S.scored||0})]})]})})]})}function _f({values:t}){return r.jsx("div",{className:"flex flex-wrap gap-4 text-xs text-muted-foreground",children:ln.map(([o,s,a])=>r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"h-0.5 w-3 rounded-sm",ref:l=>l==null?void 0:l.style.setProperty("background",`var(${a})`)}),s,t&&t[o]!=null?" "+Math.round(t[o]):""]},o))})}function Nf({...t}){return r.jsx(Qd,{"data-slot":"dialog",...t})}function j2({...t}){return r.jsx(Xd,{"data-slot":"dialog-portal",...t})}function k2({className:t,...o}){return r.jsx(Jd,{"data-slot":"dialog-overlay",className:ie("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",t),...o})}function Ef({className:t,children:o,showCloseButton:s=!0,...a}){return r.jsxs(j2,{"data-slot":"dialog-portal",children:[r.jsx(k2,{}),r.jsxs(Zd,{"data-slot":"dialog-content",className:ie("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",t),...a,children:[o,s&&r.jsxs(xi,{"data-slot":"dialog-close",className:"absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[r.jsx(Pd,{}),r.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Rf({className:t,...o}){return r.jsx("div",{"data-slot":"dialog-header",className:ie("flex flex-col gap-2 text-center sm:text-left",t),...o})}function Pf({className:t,showCloseButton:o=!1,children:s,...a}){return r.jsxs("div",{"data-slot":"dialog-footer",className:ie("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",t),...a,children:[s,o&&r.jsx(xi,{asChild:!0,children:r.jsx(re,{variant:"outline",children:"Close"})})]})}function Tf({className:t,...o}){return r.jsx(ef,{"data-slot":"dialog-title",className:ie("text-lg leading-none font-semibold",t),...o})}function Df({className:t,...o}){return r.jsx(tf,{"data-slot":"dialog-description",className:ie("text-sm text-muted-foreground",t),...o})}function zn({className:t,...o}){return r.jsx("div",{"data-slot":"table-container",className:"relative w-full overflow-x-auto",children:r.jsx("table",{"data-slot":"table",className:ie("w-full caption-bottom text-sm",t),...o})})}function Fn({className:t,...o}){return r.jsx("thead",{"data-slot":"table-header",className:ie("[&_tr]:border-b",t),...o})}function $n({className:t,...o}){return r.jsx("tbody",{"data-slot":"table-body",className:ie("[&_tr:last-child]:border-0",t),...o})}function ct({className:t,...o}){return r.jsx("tr",{"data-slot":"table-row",className:ie("border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted",t),...o})}function je({className:t,...o}){return r.jsx("th",{"data-slot":"table-head",className:ie("h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",t),...o})}function ke({className:t,...o}){return r.jsx("td",{"data-slot":"table-cell",className:ie("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",t),...o})}function C2(t,o,s){const a={};s.forEach(d=>a[new Date(d.bucket).toISOString().slice(0,10)]=d);const l=[],u=new Date(t).getTime();for(let d=0;d{const h=new URLSearchParams({platform:t.platform,host:t.host,repo:t.path,granularity:o==="30d"?"day":"month"});o==="all"&&h.set("from","2000-01-01"),Ke("/admin/api/metrics?"+h.toString()).then(l).catch(()=>l(null))},[t.id,o]);let u=a?Cf(a):[];o==="all"&&(u=u.slice(Math.max(0,u.findIndex(h=>h.scored))));const d=u.reduce((h,g)=>({bucket:"",scored:(h.scored||0)+(g.scored||0),quality_sum:(h.quality_sum||0)+(g.quality_sum||0),security_sum:(h.security_sum||0)+(g.security_sum||0),maintainability_sum:(h.maintainability_sum||0)+(g.maintainability_sum||0)}),{bucket:""});return r.jsxs("div",{className:"mb-6 grid gap-3",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[r.jsx("h3",{className:"text-xs font-semibold tracking-wide text-muted-foreground uppercase",children:"Review scores"}),r.jsx("span",{className:"flex-1"}),r.jsxs(Ne,{className:"w-auto","aria-label":"Period",value:o,onChange:h=>s(h.target.value),children:[r.jsx("option",{value:"30d",children:"Last 30 days"}),r.jsx("option",{value:"12m",children:"Last 12 months"}),r.jsx("option",{value:"all",children:"All history"})]})]}),a?d.scored?r.jsxs(r.Fragment,{children:[r.jsx(_f,{values:Object.fromEntries(ln.map(([h])=>[h,ds(d,h)]))}),r.jsx(Sf,{points:u,granularity:a.granularity}),r.jsxs(ne,{children:[d.scored," scored reviews; the numbers above are the period's averages."]})]}):r.jsx(ne,{children:"No scored reviews in this period."}):r.jsx(ne,{children:"Loading…"})]})}function N2(){const t=no(),o=et(),s=to(),[a,l]=m.useState(null),[u,d]=m.useState(""),[h,g]=m.useState("all"),[v,w]=m.useState(null),[x,C]=m.useState(!1),[y,_]=m.useState({platform:"github",host:"",path:"",mode:"enabled"}),b=()=>Ke("/admin/api/repos").then(l).catch(B=>o(Ee(B),!0));m.useEffect(()=>{b()},[]);const j=qt("metrics"),[S,R]=m.useState(null);m.useEffect(()=>{j&&Ke("/admin/api/repos/scores?days=30").then(B=>R({since:B.since,days:B.days,by:Object.fromEntries(B.repos.map(z=>[z.platform+"|"+z.host+"|"+z.repo,z]))})).catch(()=>{})},[j]);const N=B=>S==null?void 0:S.by[B.platform+"|"+B.host.toLowerCase()+"|"+B.path.toLowerCase()],E=(B,z,Z)=>bn("/admin/api/repos/"+B.id,{mode:z,settings:Z}).then(se=>(l(he=>(he||[]).map(ye=>ye.id===se.id?se:ye)),o(se.path+": reviews "+(se.effective.enabled?"on":"off")+" ("+se.effective.source+")"),se)),P=()=>Qt("/admin/api/repos",{...y,host:y.host.trim(),path:y.path.trim()}).then(B=>{l(z=>(z||[]).filter(Z=>Z.id!==B.id).concat([B])),_({...y,path:""}),C(!1),o("Added "+B.path)}).catch(B=>o(Ee(B),!0)),I=async B=>{await s({title:"Remove "+B.path+"?",description:"It reappears, set to Inherit, if it sends another webhook.",action:"Remove",danger:!0})&&Co("/admin/api/repos/"+B.id).then(()=>{l(z=>(z||[]).filter(Z=>Z.id!==B.id)),w(null),o("Removed "+B.path)}).catch(z=>o(Ee(z),!0))},F=(a||[]).filter(B=>h==="on"&&!B.effective.enabled||h==="off"&&B.effective.enabled?!1:!u||(B.host+"/"+B.path).toLowerCase().includes(u.toLowerCase())),A=(a||[]).filter(B=>B.effective.enabled).length,q=(a==null?void 0:a.find(B=>B.id===v))??null;return r.jsxs("section",{className:"grid gap-4",children:[r.jsxs(lr,{children:[r.jsxs("div",{className:"relative w-full sm:w-64",children:[r.jsx(pl,{className:"pointer-events-none absolute top-2.5 left-2.5 size-4 text-muted-foreground"}),r.jsx(ve,{type:"search",className:"pl-8",placeholder:"Filter repositories","aria-label":"Filter repositories",value:u,onChange:B=>d(B.target.value)})]}),r.jsxs(Ne,{className:"w-auto","aria-label":"Show",value:h,onChange:B=>g(B.target.value),children:[r.jsx("option",{value:"all",children:"All"}),r.jsx("option",{value:"on",children:"Reviewed"}),r.jsx("option",{value:"off",children:"Not reviewed"})]}),r.jsx("span",{className:"text-sm text-muted-foreground",children:a&&A+" reviewed · "+(a.length-A)+" not reviewed"}),r.jsx("span",{className:"flex-1"}),r.jsxs(re,{variant:"outline",onClick:()=>C(!0),children:[r.jsx(ps,{})," Add repository"]})]}),r.jsx(un,{children:a?F.length?r.jsxs(zn,{children:[r.jsx(Fn,{children:r.jsxs(ct,{children:[r.jsx(je,{className:"pl-4",children:"Reviews"}),r.jsx(je,{children:"Repository"}),r.jsx(je,{children:"Last webhook"}),j&&r.jsx(je,{children:"Scores · 30 days"}),r.jsx(je,{children:"Effective settings"}),r.jsx(je,{children:"Last changed"}),r.jsx(je,{})]})}),r.jsx($n,{children:F.map(B=>{const z=B.effective,Z=[z.require_reviewer&&"reviewer required",z.skip_branch_sync&&"skips branch syncs",z.score_labels&&"score labels",z.commit_status&&"commit status",z.approve&&"approves when it passes"].filter(Boolean);return r.jsxs(ct,{children:[r.jsxs(ke,{className:"w-44 pl-4 align-top whitespace-normal",children:[r.jsxs(Ne,{"aria-label":"Reviews for "+B.path,value:B.mode,onChange:se=>E(B,se.target.value,B.settings||{}).catch(he=>o(Ee(he),!0)),children:[r.jsx("option",{value:"inherit",children:"Inherit"}),r.jsx("option",{value:"enabled",children:"Enabled"}),r.jsx("option",{value:"disabled",children:"Disabled"})]}),r.jsx("div",{className:"mt-1.5",children:r.jsx(Je,{kind:z.enabled?"on":"off",children:z.enabled?"Reviewed":"Not reviewed"})}),r.jsx(ne,{children:S2(z)}),Z.length>0&&r.jsx(ne,{children:Z.join(" · ")})]}),r.jsxs(ke,{className:"align-top",children:[r.jsx("div",{className:"font-medium",children:B.path}),r.jsxs(ne,{children:[B.platform," · ",B.host]})]}),r.jsx(ke,{className:"align-top text-muted-foreground",children:Hr(B.last_seen)}),j&&r.jsx(ke,{className:"align-top",children:(()=>{const se=N(B);return se?r.jsxs("div",{className:"grid gap-1",children:[r.jsx(_w,{s:se.latest}),r.jsx(b2,{points:C2(S.since,S.days,se.trend),label:"Daily average scores of "+B.path+", last 30 days"}),r.jsxs(ne,{children:["latest: #",se.number," · ",Hr(se.at)]})]}):r.jsx(ne,{children:"No scored review yet"})})()}),r.jsxs(ke,{className:"align-top whitespace-normal",children:[r.jsx(bd,{items:bw(z.settings)}),(z.rules||[]).length>0&&JSON.stringify(z.settings)!==JSON.stringify(B.settings||{})&&r.jsx(ne,{children:"includes rule settings"})]}),r.jsx(ke,{className:"align-top text-muted-foreground",children:B.updated_by?B.updated_by+" · "+Hr(B.updated_at):"—"}),r.jsx(ke,{className:"pr-4 text-right align-top",children:r.jsxs(re,{variant:"ghost",size:"sm",onClick:()=>w(B.id),children:[r.jsx(jk,{})," Settings"]})})]},B.id)})})]}):r.jsx(qe,{children:a.length?"No repositories match.":"No repositories yet. They appear when they send their first webhook, or add one above."}):r.jsx(qe,{children:"Loading…"})}),r.jsxs(He,{children:["Repositories appear here automatically when they send their first webhook, set to ",r.jsx("b",{children:"Inherit"}),": they follow the most specific group or pattern rule, and otherwise the default (",t.allowlist?"not reviewed, because the allowlist is on":"reviewed, because the allowlist is off","). Choosing Enabled or Disabled here overrides every rule. Settings here override the rules' settings and the repository's own ",r.jsx("code",{children:".codereview.yaml"}),"."]}),t.require_reviewer&&r.jsxs(He,{children:[r.jsx("b",{children:"Reviewer required:"})," even in an enabled repository, a merge request is reviewed only when the bot user is one of its reviewers. Adding the bot as a reviewer starts a review; ",r.jsx("code",{children:"@bot review"})," comments still work."]}),r.jsxs(ko,{open:!!q,onClose:()=>w(null),title:(q==null?void 0:q.path)??"",description:q?`${q.platform} · ${q.host} · review settings for this repository`:void 0,children:[q&&j&&r.jsx(_2,{repo:q},q.id),q&&r.jsx(kf,{value:q.settings,onSave:B=>E(q,q.mode,B).then(()=>w(null)).catch(z=>o(Ee(z),!0)),onCancel:()=>w(null),danger:r.jsx(re,{variant:"ghost",className:"text-destructive hover:text-destructive",onClick:()=>I(q),children:"Remove"})},q.id)]}),r.jsx(Nf,{open:x,onOpenChange:C,children:r.jsxs(Ef,{className:"sm:max-w-lg",children:[r.jsxs(Rf,{children:[r.jsx(Tf,{children:"Add repository"}),r.jsx(Df,{children:"Repositories also appear by themselves when they send their first webhook."})]}),r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ee,{label:"Platform",children:r.jsxs(Ne,{value:y.platform,onChange:B=>_({...y,platform:B.target.value}),children:[r.jsx("option",{value:"github",children:"GitHub"}),r.jsx("option",{value:"gitlab",children:"GitLab"})]})}),r.jsx(ee,{label:"Host",children:r.jsx(ve,{placeholder:"github.com",value:y.host,onChange:B=>_({...y,host:B.target.value})})}),r.jsx(ee,{label:"Repository path",className:"sm:col-span-2",children:r.jsx(ve,{placeholder:"owner/repo or group/sub/project",value:y.path,onChange:B=>_({...y,path:B.target.value})})}),r.jsx(ee,{label:"Reviews",children:r.jsxs(Ne,{value:y.mode,onChange:B=>_({...y,mode:B.target.value}),children:[r.jsx("option",{value:"enabled",children:"Enabled"}),r.jsx("option",{value:"disabled",children:"Disabled"}),r.jsx("option",{value:"inherit",children:"Inherit from rules"})]})})]}),r.jsxs(Pf,{children:[r.jsx(re,{variant:"outline",onClick:()=>C(!1),children:"Cancel"}),r.jsx(re,{onClick:P,children:"Add"})]})]})})]})}function Of(t){const[o,s]=Bj(),a=o.toString(),l=m.useMemo(()=>{const d={...t};for(const h of Object.keys(t)){const g=o.get(h);g!==null&&(d[h]=g)}return d},[a]),u=m.useCallback(d=>s(h=>{const g=new URLSearchParams(h);for(const[v,w]of Object.entries(d))w===void 0||w===""||w===t[v]?g.delete(v):g.set(v,w);return g},{replace:!0}),[s]);return[l,u]}function E2({className:t,...o}){return r.jsx(OS,{"data-slot":"checkbox",className:ie("peer size-4 shrink-0 rounded-[4px] border border-input shadow-xs transition-shadow outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:bg-input/30 dark:aria-invalid:ring-destructive/40 dark:data-[state=checked]:bg-primary",t),...o,children:r.jsx(AS,{"data-slot":"checkbox-indicator",className:"grid place-content-center text-current transition-none",children:r.jsx(hl,{className:"size-3.5"})})})}function R2({a:t}){return t==="approved"||t==="already_approved"?r.jsx(Je,{kind:"on",className:"ml-1",title:t==="approved"?"The bot approved the merge request":"The bot had already approved this head",children:"✓ approved"}):t==="withdrawn"?r.jsx(Je,{kind:"warn",className:"ml-1",title:"The bot withdrew its approval",children:"approval withdrawn"}):t==="failed"?r.jsx(Je,{kind:"off",className:"ml-1",title:"The code host refused the approval",children:"approval failed"}):null}const P2={critical:"off",major:"warn",minor:"idle",nitpick:"idle"};function T2({job:t,onRerun:o}){const s=et(),[a,l]=m.useState(null);if(m.useEffect(()=>{Ke("/admin/api/reviews/"+t.id).then(l).catch(h=>s(Ee(h),!0))},[t.id]),!a)return r.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading…"});let u=null;try{u=a.result?typeof a.result=="string"?JSON.parse(a.result):a.result:null}catch{u=null}const d=u==null?void 0:u.verification;return r.jsxs("div",{className:"grid gap-5 text-sm",children:[a.error&&r.jsxs("div",{className:"rounded-md border border-destructive/40 bg-danger-soft p-3",children:[r.jsx("div",{className:"mb-1 font-medium text-destructive",children:"Error"}),r.jsx("pre",{className:"font-mono text-xs whitespace-pre-wrap text-destructive",children:a.error})]}),u?r.jsxs(r.Fragment,{children:[u.summary&&r.jsxs("div",{children:[r.jsx("h3",{className:"mb-1 font-semibold",children:"Summary"}),r.jsx("p",{className:"leading-relaxed text-muted-foreground",children:u.summary})]}),u.scores&&r.jsx("div",{className:"grid grid-cols-3 gap-2",children:["quality","security","maintainability"].map(h=>r.jsxs("div",{className:"rounded-md border p-2.5",children:[r.jsx("div",{className:"text-lg font-semibold",children:u.scores[h]}),r.jsx("div",{className:"text-xs text-muted-foreground capitalize",children:h})]},h))}),r.jsxs("div",{children:[r.jsx("h3",{className:"mb-2 font-semibold",children:(u.findings||[]).length?`Findings (${u.findings.length})`:"No findings"}),r.jsx("div",{className:"grid gap-2",children:(u.findings||[]).map((h,g)=>r.jsxs("div",{className:"finding rounded-md border p-3",children:[r.jsx("div",{className:"font-medium",children:(h.kind==="question"?"❓ ":"")+h.title}),r.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground",children:[r.jsx(Je,{kind:P2[h.severity]??"idle",children:h.severity}),r.jsx(Tt,{variant:"outline",className:"font-normal",children:h.category}),r.jsxs("span",{className:"font-mono",children:[h.path,":",h.end_line]})]})]},g))})]}),u.approval&&r.jsxs("p",{className:"text-muted-foreground",children:["Approval: ",r.jsx("span",{className:"text-foreground",children:{approved:"approved",already_approved:"already approved",withdrawn:"withdrawn",not_approved:"not approved",unchanged:"left as it was",failed:"failed"}[u.approval]||u.approval}),u.approval_reason?" — "+u.approval_reason:""]}),(d==null?void 0:d.ran)&&r.jsxs("p",{className:"text-muted-foreground",children:["Verification (",d.model,"): ",d.confirmed||0," confirmed · ",d.false_positives||0," removed · ",d.questions||0," questions"]}),((d==null?void 0:d.removed)||[]).length>0&&r.jsx("div",{className:"grid gap-1.5",children:d.removed.map((h,g)=>r.jsxs("p",{className:"text-xs text-muted-foreground",children:["Removed: ",r.jsx("span",{className:"text-foreground",children:h.title})," — ",h.reason]},"r"+g))})]}):!a.error&&r.jsx("p",{className:"text-muted-foreground",children:a.note||"No review result stored for this job."}),r.jsx(cs,{}),r.jsxs("p",{className:"text-xs text-muted-foreground",children:["Model ",a.model||"—"," · ",a.comments," comments · ",a.files," files"]}),t.kind.includes("review")&&r.jsxs("div",{className:"flex flex-wrap gap-2",children:[r.jsx(re,{variant:"outline",onClick:()=>o(!1),children:"Re-run (new changes)"}),r.jsx(re,{variant:"outline",onClick:()=>o(!0),children:"Re-run full review"})]})]})}const D2=["bug","security","performance","reliability","maintainability","style","docs","tests"],Dg=["host","repo","state","kind","trigger","from","to","score_kind","score_below","severity","category","approval"],O2={host:"",repo:"",state:"",kind:"",trigger:"",from:"",to:"",score_kind:"",score_below:"",severity:"",category:"",approval:"",sort:"",granularity:"day",review:""};function M2(){const t=et(),[o,s]=Of(O2),a=o.granularity,l=L=>s({granularity:L}),u=m.useMemo(()=>Object.fromEntries(Dg.map(L=>[L,o[L]])),Dg.map(L=>o[L])),d=L=>s(L),h=o.sort,g=L=>s({sort:L}),v=o.review?Number(o.review):null,w=L=>s({review:L?String(L):""}),[x,C]=m.useState(null),[y,_]=m.useState([]),[b,j]=m.useState(o.repo),[S,R]=m.useState(null),[N,E]=m.useState(!1),[P,I]=m.useState(null),[F,A]=m.useState(""),[q,B]=m.useState(!1);m.useEffect(()=>{Ke("/admin/api/hosts").then(L=>_(L.hosts||[])).catch(()=>{})},[]);const z=qt("metrics"),Z=no();m.useEffect(()=>{z&&Ke("/admin/api/metrics"+td({granularity:a,host:u.host})).then(C).catch(L=>t(Ee(L),!0))},[a,u.host,z]),m.useEffect(()=>{const L=window.setTimeout(()=>d({repo:b.trim()}),300);return()=>window.clearTimeout(L)},[b]),m.useEffect(()=>{o.repo!==b.trim()&&j(o.repo)},[o.repo]),m.useEffect(()=>{!v||!S||S.some(L=>L.id===v)||(P==null?void 0:P.id)===v||Ke("/admin/api/reviews/"+v).then(I).catch(L=>t(Ee(L),!0))},[v,S]);const se=L=>Ke("/admin/api/reviews"+td({limit:100,...u,before:L})).then(K=>{R(ge=>L?(ge||[]).concat(K.reviews):K.reviews),E(K.reviews.length>=100)}).catch(K=>t(Ee(K),!0));m.useEffect(()=>{se()},[u]);const he=()=>{if(!F.trim())return t("Paste a pull request or merge request URL",!0);Qt("/admin/api/reviews",{url:F.trim(),full:q}).then(L=>{A(""),t("Queued "+L.pr+" — it appears here when it finishes")}).catch(L=>t(Ee(L),!0))},ye=(L,K)=>Qt(`/admin/api/reviews/${L.id}/rerun`,{full:K}).then(ge=>t("Queued "+ge.pr)).catch(ge=>t(Ee(ge),!0)),ae=x?Cf(x):[],oe={jobs:0,done:0,skipped:0,failed:0,comments:0,tokens_in:0,tokens_out:0,duration_ms:0,scored:0,quality_sum:0,security_sum:0,maintainability_sum:0};ae.forEach(L=>Object.keys(oe).forEach(K=>oe[K]+=L[K]||0));const H=oe.done+oe.failed,J=[["Jobs",ze(oe.jobs)],["Reviewed",ze(oe.done)],["Skipped",ze(oe.skipped)],["Failed",ze(oe.failed)+(H?" · "+Math.round(100*oe.failed/H)+"%":"")],["Comments posted",ze(oe.comments)],["Tokens in / out",ze(oe.tokens_in)+" / "+ze(oe.tokens_out)],["Avg time",nd(H?oe.duration_ms/Math.max(1,oe.jobs):0)],["Tokens today (UTC)",ze((x==null?void 0:x.today_tokens)||0)+(x!=null&&x.daily_token_budget?" of "+ze(x.daily_token_budget):"")]],$=Object.fromEntries(ln.map(([L])=>[L,ds({bucket:"",...oe},L)]));oe.scored&&J.push(["Avg scores (Q / S / M)",ln.map(([L])=>Math.round($[L]||0)).join(" / ")],["Scored reviews",ze(oe.scored)]);const O=L=>L.scores?Math.min(L.scores.quality,L.scores.security,L.scores.maintainability):101,G=!S||!h?S:[...S].sort((L,K)=>{var ge,Ce;return h==="lowest"?O(L)-O(K):(((ge=L.scores)==null?void 0:ge[h])??101)-(((Ce=K.scores)==null?void 0:Ce[h])??101)}),ce=L=>K=>d({[L]:K.target.value}),we=(S==null?void 0:S.find(L=>L.id===v))??((P==null?void 0:P.id)===v?P:null);return r.jsxs("section",{className:"grid gap-4",children:[r.jsxs(lr,{children:[z&&r.jsxs(Ne,{className:"w-auto","aria-label":"Period",value:a,onChange:L=>l(L.target.value),children:[r.jsx("option",{value:"hour",children:"Last 48 hours"}),r.jsx("option",{value:"day",children:"Last 30 days"}),r.jsx("option",{value:"month",children:"Last 12 months"})]}),r.jsx("span",{className:"flex-1"}),r.jsx(ve,{type:"url",className:"rn-url w-full sm:w-80",placeholder:"Paste a PR/MR URL to review it now","aria-label":"Pull request URL",value:F,onChange:L=>A(L.target.value),onKeyDown:L=>L.key==="Enter"&&he()}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(E2,{id:"rnFull",checked:q,onCheckedChange:L=>B(L===!0)}),r.jsx(uw,{htmlFor:"rnFull",className:"text-sm font-normal text-muted-foreground",children:"Full"})]}),r.jsxs(re,{onClick:he,children:[r.jsx(vk,{})," Review now"]})]}),!z&&r.jsxs(ji,{feature:"metrics",children:["Totals, charts and token use, and history kept longer than ",Z.free_retention_days," days, are part of the licensed console. Every review is listed below."]}),z&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"tiles grid grid-cols-2 gap-3 md:grid-cols-4",children:J.map(([L,K])=>r.jsx(lt,{className:"tile gap-1 py-4",children:r.jsxs(Pt,{className:"px-4",children:[r.jsx("div",{className:"text-xl font-semibold tabular-nums",children:K}),r.jsx("div",{className:"text-xs text-muted-foreground",children:L})]})},L))}),r.jsx(lt,{className:"py-4",children:r.jsxs(Pt,{className:"grid gap-3 px-4",children:[r.jsx("div",{className:"flex flex-wrap gap-4 text-xs text-muted-foreground",children:Sw.map(([L,K,ge])=>r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"size-2.5 rounded-sm",ref:Ce=>Ce==null?void 0:Ce.style.setProperty("background",`var(${ge})`)}),K," ",ze(oe[L]||0)]},L))}),x&&r.jsx(kd,{points:ae,granularity:x.granularity})]})}),oe.scored>0&&x&&r.jsx(lt,{className:"py-4",children:r.jsxs(Pt,{className:"grid gap-3 px-4",children:[r.jsx(_f,{values:$}),r.jsx(Sf,{points:ae,granularity:x.granularity}),r.jsxs(ne,{children:["Average scores of the reviews in each ",x.granularity,". Dashed lines at 80 and 50 are the bands of the score labels."]})]})})]}),r.jsxs(lr,{children:[r.jsxs(Ne,{className:"w-auto","aria-label":"Host",value:u.host,onChange:ce("host"),children:[r.jsx("option",{value:"",children:"All hosts"}),y.map(L=>r.jsx("option",{value:L.host,children:L.name},L.host))]}),r.jsxs("div",{className:"relative w-full sm:w-52",children:[r.jsx(pl,{className:"pointer-events-none absolute top-2.5 left-2.5 size-4 text-muted-foreground"}),r.jsx(ve,{type:"search",className:"pl-8",placeholder:"Repository","aria-label":"Repository",value:b,onChange:L=>j(L.target.value)})]}),r.jsxs(Ne,{className:"w-auto","aria-label":"State",value:u.state,onChange:ce("state"),children:[r.jsx("option",{value:"",children:"Any state"}),r.jsx("option",{value:"done",children:"Done"}),r.jsx("option",{value:"skipped",children:"Skipped"}),r.jsx("option",{value:"failed",children:"Failed"})]}),r.jsxs(Ne,{className:"w-auto","aria-label":"Kind",value:u.kind,onChange:ce("kind"),children:[r.jsx("option",{value:"",children:"Any kind"}),r.jsx("option",{value:"review",children:"Review"}),r.jsx("option",{value:"full review",children:"Full review"}),r.jsx("option",{value:"answer",children:"Answer"}),r.jsx("option",{value:"help",children:"Help"}),r.jsx("option",{value:"learn",children:"Learn"}),r.jsx("option",{value:"remember",children:"Remember"})]}),r.jsxs(Ne,{className:"w-auto","aria-label":"Trigger",value:u.trigger,onChange:ce("trigger"),children:[r.jsx("option",{value:"",children:"Any trigger"}),r.jsx("option",{value:"push",children:"Push"}),r.jsx("option",{value:"command",children:"Command"}),r.jsx("option",{value:"reply",children:"Reply"}),r.jsx("option",{value:"ui",children:"Admin panel"})]}),r.jsx(ve,{type:"date",className:"w-auto","aria-label":"From",value:u.from,onChange:ce("from")}),r.jsx(ve,{type:"date",className:"w-auto","aria-label":"To",value:u.to,onChange:ce("to")}),r.jsxs(Ne,{className:"w-auto","aria-label":"Merge request approval",value:u.approval,onChange:ce("approval"),children:[r.jsx("option",{value:"",children:"Any approval"}),r.jsx("option",{value:"approved",children:"Approved by the bot"}),r.jsx("option",{value:"already_approved",children:"Already approved"}),r.jsx("option",{value:"withdrawn",children:"Approval withdrawn"}),r.jsx("option",{value:"not_approved",children:"Not approved"}),r.jsx("option",{value:"failed",children:"Approval failed"})]}),r.jsxs(Ne,{className:"w-auto","aria-label":"Finding severity",value:u.severity,onChange:ce("severity"),children:[r.jsx("option",{value:"",children:"Any findings"}),r.jsx("option",{value:"any",children:"With findings"}),r.jsx("option",{value:"critical",children:"Critical finding"}),r.jsx("option",{value:"major",children:"Major finding"}),r.jsx("option",{value:"minor",children:"Minor finding"}),r.jsx("option",{value:"nitpick",children:"Nitpick"})]}),r.jsxs(Ne,{className:"w-auto","aria-label":"Finding category",value:u.category,onChange:ce("category"),children:[r.jsx("option",{value:"",children:"Any category"}),Array.from(new Set([...D2,...u.category?[u.category]:[]])).map(L=>r.jsx("option",{value:L,className:"capitalize",children:L[0].toUpperCase()+L.slice(1)},L))]}),r.jsxs(Ne,{className:"w-auto","aria-label":"Score",value:u.score_kind,onChange:ce("score_kind"),children:[r.jsx("option",{value:"",children:"Any score"}),r.jsx("option",{value:"any",children:"Lowest score"}),ln.map(([L,K])=>r.jsx("option",{value:L,children:K},L))]}),u.score_kind&&r.jsxs(Ne,{className:"w-auto","aria-label":"Score below",value:u.score_below,onChange:ce("score_below"),children:[r.jsx("option",{value:"",children:"at any value"}),r.jsx("option",{value:"50",children:"below 50"}),r.jsx("option",{value:"60",children:"below 60"}),r.jsx("option",{value:"70",children:"below 70"}),r.jsx("option",{value:"80",children:"below 80"}),r.jsx("option",{value:"90",children:"below 90"})]}),r.jsxs(Ne,{className:"w-auto","aria-label":"Sort",value:h,onChange:L=>g(L.target.value),children:[r.jsx("option",{value:"",children:"Newest first"}),r.jsx("option",{value:"lowest",children:"Lowest score first"}),ln.map(([L,K])=>r.jsxs("option",{value:L,children:["Lowest ",K.toLowerCase()," first"]},L))]})]}),r.jsx(un,{children:S?!G||!G.length?r.jsx(qe,{children:"No reviews match."}):r.jsxs(zn,{children:[r.jsx(Fn,{children:r.jsxs(ct,{children:[r.jsx(je,{className:"pl-4",children:"Finished"}),r.jsx(je,{children:"Pull request"}),r.jsx(je,{children:"Job"}),r.jsx(je,{children:"State"}),r.jsx(je,{children:"Scores"}),r.jsx(je,{className:"text-right",children:"Comments / files"}),r.jsx(je,{className:"text-right",children:"Tokens in / out"}),r.jsx(je,{className:"text-right",children:"Took"}),r.jsx(je,{})]})}),r.jsx($n,{children:G.map(L=>{const K=L.started&&!L.started.startsWith("0001-")?new Date(L.finished).getTime()-new Date(L.started).getTime():0;return r.jsxs(ct,{className:"cursor-pointer",onClick:()=>w(L.id),children:[r.jsx(ke,{className:"pl-4 text-muted-foreground",title:qr(L.finished,!0)+" · "+ml(L.finished),children:Hr(L.finished)}),r.jsxs(ke,{children:[r.jsx("div",{className:"font-medium",children:L.url?r.jsxs("a",{className:"inline-flex items-center gap-1 hover:underline",href:L.url,target:"_blank",rel:"noopener noreferrer",onClick:ge=>ge.stopPropagation(),children:[L.repo," #",L.number," ",r.jsx(xv,{className:"size-3 text-muted-foreground"})]}):`${L.repo} #${L.number}`}),r.jsxs(ne,{children:[L.platform," · ",L.host]})]}),r.jsxs(ke,{children:[r.jsx("div",{children:L.kind}),r.jsx(ne,{children:L.trigger+(L.requested_by?" · "+L.requested_by:"")})]}),r.jsxs(ke,{className:"max-w-64 whitespace-normal",children:[r.jsx(Je,{kind:L.state==="done"?"on":L.state==="failed"?"off":"idle",children:L.state}),r.jsx(R2,{a:L.approval}),(L.error||L.note)&&r.jsx(ne,{className:"line-clamp-2",children:L.error?L.error.slice(0,120):L.note})]}),r.jsx(ke,{children:r.jsx(_w,{s:L.scores})}),r.jsxs(ke,{className:"text-right tabular-nums",children:[L.comments," / ",L.files]}),r.jsxs(ke,{className:"text-right text-muted-foreground tabular-nums",children:[ze(L.tokens_in)," / ",ze(L.tokens_out)]}),r.jsx(ke,{className:"text-right text-muted-foreground tabular-nums",children:nd(K)}),r.jsx(ke,{className:"pr-4 text-right",children:r.jsx(re,{variant:"ghost",size:"sm",onClick:ge=>(ge.stopPropagation(),w(L.id)),children:"Details"})})]},L.id)})})]}):r.jsx(qe,{children:"Loading…"})}),N&&r.jsx("div",{children:r.jsx(re,{variant:"outline",onClick:()=>S&&se(S[S.length-1].id),children:"Load older"})}),r.jsx(He,{children:"Every finished review, answer, help and learning job. Charts read hourly, daily and monthly rollups that are updated as each job finishes. Reviews are kept for the retention set in Settings; hourly detail for 3 days, daily and monthly totals for good. Scores (quality, security, maintainability, 1 to 100) come from the review; sorting by score orders the reviews loaded so far, and the score filter searches all of them."}),r.jsx(ko,{wide:!0,open:!!we,onClose:()=>w(null),title:we?`${we.repo} #${we.number}`:"",description:we?`${we.kind} · ${we.trigger} · ${we.state} · ${Hr(we.finished)}`:void 0,children:we&&r.jsx(T2,{job:we,onRerun:L=>ye(we,L)},we.id)})]})}const A2={reply:"from a reply",command:"@bot remember",manual:"added here"};function L2({l:t,onSave:o,onCancel:s,onDelete:a}){const[l,u]=m.useState(t.scope),[d,h]=m.useState(t.path),[g,v]=m.useState(t.text);return r.jsxs("div",{className:"grid gap-4",children:[r.jsx(ee,{label:"Applies to",children:r.jsx(ve,{value:l,placeholder:"empty = whole host · group · group/repo",onChange:w=>u(w.target.value)})}),r.jsx(ee,{label:"Only files matching",children:r.jsx(ve,{value:d,placeholder:"optional glob",onChange:w=>h(w.target.value)})}),r.jsx(ee,{label:"Learning",children:r.jsx(an,{rows:5,maxLength:600,value:g,onChange:w=>v(w.target.value)})}),r.jsxs("div",{className:"flex flex-wrap gap-2",children:[r.jsx(re,{onClick:()=>o({scope:l.trim(),path:d.trim(),text:g.trim()}),children:"Save"}),r.jsx(re,{variant:"outline",onClick:s,children:"Cancel"}),r.jsx("span",{className:"flex-1"}),r.jsx(re,{variant:"ghost",className:"text-destructive hover:text-destructive",onClick:a,children:"Delete"})]})]})}function I2(){const t=et(),o=to(),s=qt("learnings"),[a,l]=m.useState(null),[u,d]=m.useState(""),[h,g]=m.useState(""),[v,w]=m.useState(null),[x,C]=m.useState(!1),[y,_]=m.useState({platform:"gitlab",host:"",scope:"",path:"",text:""});m.useEffect(()=>{Ke("/admin/api/learnings").then(P=>l(P.learnings||[])).catch(P=>t(Ee(P),!0))},[]);const b=(P,I)=>bn("/admin/api/learnings/"+P.id,{scope:P.scope,text:P.text,path:P.path,status:P.status,...I}).then(F=>(l(A=>(A||[]).map(q=>q.id===F.id?F:q)),F)),j=()=>Qt("/admin/api/learnings",y).then(P=>{l(I=>(I||[]).concat([P])),_({...y,text:""}),C(!1),t("Learning added")}).catch(P=>t(Ee(P),!0)),S=async P=>{await o({title:"Delete this learning?",description:P.text,action:"Delete",danger:!0})&&Co("/admin/api/learnings/"+P.id).then(()=>{l(I=>(I||[]).filter(F=>F.id!==P.id)),w(null),t("Deleted")}).catch(I=>t(Ee(I),!0))},R={active:0,pending:0,disabled:0};(a||[]).forEach(P=>R[P.status]+=1);const N=(a||[]).filter(P=>(!h||P.status===h)&&(!u||(P.text+" "+P.scope+" "+P.host+" "+P.path).toLowerCase().includes(u.toLowerCase()))),E=(a==null?void 0:a.find(P=>P.id===v))??null;return r.jsxs("section",{className:"grid gap-4",children:[!s&&r.jsxs(ji,{feature:"learnings",children:["Capturing team decisions from review replies, ",r.jsx("code",{children:"@bot remember"}),", and applying them to reviews are part of the licensed console. Without a license nothing new is learned and existing learnings are not applied."]}),r.jsxs(lr,{children:[r.jsxs("div",{className:"relative w-full sm:w-64",children:[r.jsx(pl,{className:"pointer-events-none absolute top-2.5 left-2.5 size-4 text-muted-foreground"}),r.jsx(ve,{type:"search",className:"pl-8",placeholder:"Search learnings","aria-label":"Search learnings",value:u,onChange:P=>d(P.target.value)})]}),r.jsxs(Ne,{className:"w-auto","aria-label":"Status",value:h,onChange:P=>g(P.target.value),children:[r.jsx("option",{value:"",children:"Any status"}),r.jsx("option",{value:"active",children:"Active"}),r.jsx("option",{value:"pending",children:"Waiting for approval"}),r.jsx("option",{value:"disabled",children:"Disabled"})]}),r.jsx("span",{className:"text-sm text-muted-foreground",children:a&&`${R.active} active · ${R.pending} waiting · ${R.disabled} disabled`}),r.jsx("span",{className:"flex-1"}),s&&r.jsxs(re,{variant:"outline",onClick:()=>C(!0),children:[r.jsx(ps,{})," Add learning"]})]}),r.jsx(un,{children:a?N.length?r.jsxs(zn,{children:[r.jsx(Fn,{children:r.jsxs(ct,{children:[r.jsx(je,{className:"pl-4",children:"Applies to"}),r.jsx(je,{children:"Learning"}),r.jsx(je,{children:"Status"}),r.jsx(je,{children:"Source"}),r.jsx(je,{})]})}),r.jsx($n,{children:N.map(P=>r.jsxs(ct,{children:[r.jsxs(ke,{className:"pl-4 align-top",children:[r.jsx("div",{children:P.scope?r.jsx("code",{children:P.scope}):r.jsx("b",{children:"Whole host"})}),r.jsxs(ne,{children:[P.platform," · ",P.host]})]}),r.jsxs(ke,{className:"min-w-64 align-top whitespace-normal",children:[r.jsx("div",{children:P.text}),P.path&&r.jsxs(Tt,{variant:"outline",className:"mt-1 font-normal text-muted-foreground",children:["files: ",P.path]})]}),r.jsx(ke,{className:"w-36 align-top",children:r.jsxs(Ne,{"aria-label":"Status",value:P.status,disabled:!s,onChange:I=>b(P,{status:I.target.value}).then(F=>t("Learning "+F.status)).catch(F=>t(Ee(F),!0)),children:[r.jsx("option",{value:"active",children:"Active"}),r.jsx("option",{value:"pending",children:"Waiting"}),r.jsx("option",{value:"disabled",children:"Disabled"})]})}),r.jsxs(ke,{className:"align-top text-muted-foreground",children:[r.jsx("div",{children:(A2[P.source]||P.source)+(P.source_author?" · "+P.source_author:"")+(P.source_role?" ("+P.source_role+")":"")}),P.source_url&&r.jsxs("a",{className:"inline-flex items-center gap-1 text-xs hover:text-foreground hover:underline",href:P.source_url,target:"_blank",rel:"noopener noreferrer",children:["open PR ",r.jsx(xv,{className:"size-3"})]}),r.jsx(ne,{children:Hr(P.updated_at)})]}),r.jsx(ke,{className:"pr-4 text-right align-top",children:s?r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>w(P.id),children:"Edit"}):r.jsx(re,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>S(P),children:"Delete"})})]},P.id))})]}):r.jsx(qe,{children:a.length?"No learnings match.":"No learnings yet. Reply to one of the bot's comments with a team decision, or use @bot remember."}):r.jsx(qe,{children:"Loading…"})}),r.jsxs(He,{children:["Learnings are team decisions from review discussions. When someone replies to one of the bot's comments, the bot reacts 👀, asks the model whether the reply states a rule for future reviews, and if so saves it here (✅ on GitLab, 🎉 on GitHub). ",r.jsx("code",{children:"@bot remember "})," saves one directly. Each starts scoped to its repository; widen ",r.jsx("b",{children:"Applies to"})," to a group or the whole host so one standard covers many repositories. Matching active learnings go with every review: the reviewer follows them and the verifier drops findings they rule out."]}),r.jsx(ko,{open:!!E,onClose:()=>w(null),title:"Edit learning",description:E?`${E.platform} · ${E.host}`:void 0,children:E&&r.jsx(L2,{l:E,onCancel:()=>w(null),onDelete:()=>S(E),onSave:P=>b(E,P).then(()=>{w(null),t("Saved")}).catch(I=>t(Ee(I),!0))},E.id)}),r.jsx(Nf,{open:x,onOpenChange:C,children:r.jsxs(Ef,{className:"sm:max-w-xl",children:[r.jsxs(Rf,{children:[r.jsx(Tf,{children:"Add learning"}),r.jsx(Df,{children:"A rule future reviews should follow."})]}),r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ee,{label:"Platform",children:r.jsxs(Ne,{value:y.platform,onChange:P=>_({...y,platform:P.target.value}),children:[r.jsx("option",{value:"gitlab",children:"GitLab"}),r.jsx("option",{value:"github",children:"GitHub"}),r.jsx("option",{value:"bitbucket",children:"Bitbucket"})]})}),r.jsx(ee,{label:"Host",children:r.jsx(ve,{placeholder:"gitlab.example.com",value:y.host,onChange:P=>_({...y,host:P.target.value})})}),r.jsx(ee,{label:"Applies to",children:r.jsx(ve,{placeholder:"empty = whole host · group · group/repo",value:y.scope,onChange:P=>_({...y,scope:P.target.value})})}),r.jsx(ee,{label:"Only files matching",children:r.jsx(ve,{placeholder:"optional glob, e.g. api/legacy/**",value:y.path,onChange:P=>_({...y,path:P.target.value})})})]}),r.jsx(ee,{label:"Learning",children:r.jsx(an,{rows:4,maxLength:600,placeholder:"e.g. Account numbers are compared without leading zeros on purpose.",value:y.text,onChange:P=>_({...y,text:P.target.value})})}),r.jsxs(Pf,{children:[r.jsx(re,{variant:"outline",onClick:()=>C(!1),children:"Cancel"}),r.jsx(re,{onClick:j,children:"Add learning"})]})]})})]})}const z2={github:"GitHub",gitlab:"GitLab",bitbucket:"Bitbucket"},F2={github:"https://api.github.com",gitlab:"https://gitlab.com",bitbucket:"https://api.bitbucket.org/2.0"};function ii({label:t,set:o,multi:s,help:a,value:l,onChange:u}){const d=o?"Set ✓ — leave blank to keep":"";return r.jsx(ee,{label:t+(a?" — "+a:""),children:s?r.jsx(an,{rows:3,className:"font-mono text-xs",placeholder:d,autoComplete:"off",spellCheck:!1,value:l,onChange:h=>u(h.target.value)}):r.jsx(ve,{type:"password",placeholder:d,autoComplete:"new-password",value:l,onChange:h=>u(h.target.value)})})}function Ew({text:t,label:o="Copy"}){const s=et(),[a,l]=m.useState(!1),u=()=>navigator.clipboard.writeText(t).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>s("Copy failed: select the text and copy it",!0));return r.jsxs(re,{variant:"ghost",size:"sm",onClick:u,"aria-label":o,children:[a?r.jsx(hl,{}):r.jsx(ck,{})," ",o]})}function Rw({secret:t,platform:o,onDone:s}){const a=o==="gitlab"?"GitLab's Secret token field":"the webhook's Secret field";return r.jsxs("div",{className:"grid gap-2 rounded-lg border border-warning/40 bg-warning-soft p-3",children:[r.jsx("div",{className:"text-sm font-medium",children:"Copy the secret now: it is not shown again."}),r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx("code",{className:"min-w-0 flex-1 break-all font-mono text-xs",children:t}),r.jsx(Ew,{text:t})]}),r.jsxs(ne,{children:["Paste it into ",a,", together with the URL."]}),r.jsx("div",{children:r.jsx(re,{size:"sm",variant:"outline",onClick:s,children:"I've copied it"})})]})}function $2({hook:t,platform:o,onChanged:s}){const a=et(),l=to(),[u,d]=m.useState(""),[h,g]=m.useState(t.name),[v,w]=m.useState(""),x=(_,b)=>bn("/admin/api/webhooks/"+t.id,_).then(j=>{a(b),j.secret&&d(j.secret),s()}).catch(j=>a(Ee(j),!0)),C=async()=>{await l({title:"Replace the secret of "+t.name+"?",description:"Deliveries signed with the old secret are rejected until you paste the new one into the code host.",action:"Replace secret",danger:!0})&&x({regenerate_secret:!0},"New secret for "+t.name)},y=async()=>{await l({title:"Delete "+t.name+"?",description:"Its URL stops working at once. Remove the webhook from the code host too.",action:"Delete webhook",danger:!0})&&Co("/admin/api/webhooks/"+t.id).then(()=>{a("Deleted "+t.name),s()}).catch(_=>a(Ee(_),!0))};return r.jsxs("div",{className:"grid gap-3 rounded-lg border p-3",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx(ve,{className:"h-8 max-w-64",value:h,onChange:_=>g(_.target.value),onBlur:()=>h.trim()!==t.name&&x({name:h},"Renamed")}),r.jsx(Je,{kind:t.enabled?"on":"idle",children:t.enabled?"Enabled":"Disabled"}),o==="gitlab"&&t.accepts&&r.jsxs(Tt,{variant:"outline",className:t.accepts==="signature"?"font-normal text-muted-foreground":"font-normal text-warning",title:"What this webhook accepts",children:["accepts: ",t.accepts]}),r.jsx("span",{className:"flex-1"}),r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>x({enabled:!t.enabled},t.enabled?"Disabled "+t.name:"Enabled "+t.name),children:t.enabled?"Disable":"Enable"}),r.jsx(re,{variant:"ghost",size:"sm",onClick:C,children:"New secret"}),r.jsx(re,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:y,children:"Delete"})]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx("code",{className:"hosturl min-w-0 flex-1 break-all",children:t.url}),r.jsx(Ew,{text:t.url,label:"Copy URL"})]}),u&&r.jsx(Rw,{secret:u,platform:o,onDone:()=>d("")}),o==="gitlab"&&r.jsx(ee,{label:"Signing token (whsec_…) — GitLab 19.0+, "+(t.secrets.signing_tokens?"set ✓, paste to replace":"optional: copy it from the webhook in GitLab"),children:r.jsxs("div",{className:"flex gap-2",children:[r.jsx(ve,{type:"password",autoComplete:"off",value:v,placeholder:t.secrets.signing_tokens?"Set ✓":"",onChange:_=>w(_.target.value)}),r.jsx(re,{variant:"outline",size:"sm",disabled:!v.trim(),onClick:()=>x({signing_tokens:[v.trim()]},"Saved signing token").then(()=>w("")),children:"Save"}),t.secrets.signing_tokens>0&&r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>x({signing_tokens:[]},"Removed signing token"),children:"Remove"})]})}),o==="gitlab"&&t.secrets.signing_tokens>0&&r.jsx(ee,{label:"Unsigned deliveries with the secret token",hint:r.jsx(ne,{children:"With a signing token, only signed deliveries are accepted, so the old secret token alone can't be used to send events. Accept both only while hooks still send unsigned events."}),children:r.jsxs(Ne,{className:"max-w-sm",value:String(!!t.accept_secret_token),onChange:_=>x({accept_secret_token:_.target.value==="true"},_.target.value==="true"?"Also accepting the secret token":"Signed deliveries only"),children:[r.jsx("option",{value:"false",children:"Reject (signed deliveries only)"}),r.jsx("option",{value:"true",children:"Accept too (while migrating)"})]})}),r.jsxs(ne,{children:["Added ",di(t.created_at),t.created_by?" by "+t.created_by:""]})]})}function U2({text:t}){return r.jsx("div",{role:"status",className:"rounded-lg border border-warning/40 bg-warning-soft p-3 text-sm text-warning",children:t})}function B2({host:t,managed:o,onChanged:s}){const a=et(),[l,u]=m.useState(""),[d,h]=m.useState(null),g=()=>Qt(`/admin/api/hosts/${t.id}/webhooks`,{name:l.trim()}).then(v=>{u(""),h({id:v.webhook.id,secret:v.secret}),a("Added "+v.webhook.name),s()}).catch(v=>a(Ee(v),!0));return r.jsxs("div",{className:"grid gap-6",children:[t.comment_warning&&r.jsx(U2,{text:t.comment_warning}),o&&r.jsxs(is,{title:"Add a webhook",children:[r.jsxs("div",{className:"flex flex-wrap gap-2",children:[r.jsx(ve,{className:"max-w-80",value:l,placeholder:t.platform==="gitlab"?"e.g. the group it's for":"e.g. where it's set up",onChange:v=>u(v.target.value)}),r.jsxs(re,{onClick:g,children:[r.jsx(ps,{})," Add webhook"]})]}),r.jsxs(ne,{children:["The console generates a URL and a secret. Set the code host's webhook to them, with these events: ",t.events.join(", "),".",t.platform==="gitlab"&&" A system hook alone isn't enough: it doesn't send comments, so @bot commands need a group or project webhook with Comments."]})]}),r.jsx(is,{title:`Webhooks (${t.webhooks.length})`,children:t.webhooks.length?t.webhooks.map(v=>r.jsxs("div",{className:"grid gap-2",children:[(d==null?void 0:d.id)===v.id&&r.jsx(Rw,{secret:d.secret,platform:t.platform,onDone:()=>h(null)}),r.jsx($2,{hook:v,platform:t.platform,onChanged:s})]},v.id)):r.jsxs(ne,{children:["No webhooks yet",o?": add one above.":"."]})})]})}function is({title:t,children:o}){return r.jsxs("div",{className:"grid gap-3",children:[r.jsx("h3",{className:"text-xs font-semibold tracking-wide text-muted-foreground uppercase",children:t}),o]})}function W2({host:t,onSaved:o,onCancel:s}){const a=et(),l=qt("hosts"),u=(t==null?void 0:t.settings)??{},d=(t==null?void 0:t.secrets)??{token:!1,app_private_key:!1,api_token:!1},[h,g]=m.useState((t==null?void 0:t.platform)??"gitlab"),[v,w]=m.useState({base:(t==null?void 0:t.base_url)??"",name:(t==null?void 0:t.name)??"",enabled:t?t.enabled:!0,token:"",appID:u.app_id?String(u.app_id):"",appKey:"",email:u.email??"",apiToken:"",reqSig:!!u.require_signature,skipTLS:!!u.skip_tls_verify,bot:u.bot_name??"",reviewer:u.reviewer??""}),x=y=>_=>w({...v,[y]:typeof _=="object"&&(_!=null&&_.target)?_.target.value:_}),C=()=>{const y={platform:h,base_url:v.base.trim(),name:v.name.trim(),enabled:v.enabled,settings:{bot_name:v.bot.trim(),reviewer:v.reviewer.trim()}};h==="github"&&(y.settings.app_id=parseInt(v.appID||"0",10)),h==="gitlab"&&Object.assign(y.settings,{skip_tls_verify:v.skipTLS,require_signature:v.reqSig}),h==="bitbucket"&&(y.settings.email=v.email.trim()),v.token.trim()&&(y.token=v.token.trim()),v.appKey.trim()&&(y.app_private_key=v.appKey),v.apiToken.trim()&&(y.api_token=v.apiToken.trim()),(t?bn("/admin/api/hosts/"+t.id,y):Qt("/admin/api/hosts",y)).then(_=>{a("Saved "+_.name),o(_)}).catch(_=>a(Ee(_),!0))};return r.jsxs("div",{className:"grid gap-6",children:[r.jsx(is,{title:"Host",children:r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ee,{label:"Platform",children:r.jsxs(Ne,{id:"hPlat",value:h,disabled:!!t,onChange:y=>g(y.target.value),children:[r.jsx("option",{value:"gitlab",children:"GitLab"}),r.jsx("option",{value:"github",children:"GitHub"}),r.jsx("option",{value:"bitbucket",children:"Bitbucket Cloud"})]})}),r.jsx(ee,{label:"Status",children:r.jsxs(Ne,{value:String(v.enabled),onChange:y=>w({...v,enabled:y.target.value==="true"}),children:[r.jsx("option",{value:"true",children:"Enabled"}),r.jsx("option",{value:"false",children:"Disabled"})]})}),r.jsx(ee,{label:h==="gitlab"?"Instance URL":"API URL",children:r.jsx(ve,{value:v.base,placeholder:F2[h],onChange:x("base")})}),r.jsx(ee,{label:"Name",children:r.jsx(ve,{value:v.name,placeholder:"shown in the console",onChange:x("name")})})]})}),r.jsx(cs,{}),r.jsx(is,{title:"API access",children:r.jsxs("div",{className:"grid gap-4",children:[h==="github"&&r.jsxs(r.Fragment,{children:[r.jsx(ii,{label:"Token",help:"or use a GitHub App below",set:d.token,value:v.token,onChange:x("token")}),r.jsx(ee,{label:"GitHub App ID",children:r.jsx(ve,{type:"number",value:v.appID,onChange:x("appID")})}),r.jsx(ii,{label:"GitHub App private key (PEM)",set:d.app_private_key,multi:!0,value:v.appKey,onChange:x("appKey")})]}),h==="gitlab"&&r.jsxs(r.Fragment,{children:[r.jsx(ii,{label:"Access token (api scope)",set:d.token,value:v.token,onChange:x("token")}),r.jsx(ee,{label:"TLS",children:r.jsxs(Ne,{value:String(v.skipTLS),onChange:y=>w({...v,skipTLS:y.target.value==="true"}),children:[r.jsx("option",{value:"false",children:"Verify certificates"}),r.jsx("option",{value:"true",children:"Skip verification (self-signed)"})]})})]}),h==="bitbucket"&&r.jsxs(r.Fragment,{children:[r.jsx(ii,{label:"Access token",help:"repository or workspace token",set:d.token,value:v.token,onChange:x("token")}),r.jsx(ee,{label:"Account email",children:r.jsx(ve,{value:v.email,placeholder:"with an API token instead",onChange:x("email")})}),r.jsx(ii,{label:"Atlassian API token",set:d.api_token,value:v.apiToken,onChange:x("apiToken")})]})]})}),r.jsx(cs,{}),h==="gitlab"&&r.jsxs(r.Fragment,{children:[r.jsxs(is,{title:"Webhooks",children:[r.jsx(ne,{children:"Each webhook has its own URL and secrets: add them under Manage webhooks once the host is saved."}),r.jsx(ee,{label:"Unsigned deliveries (every webhook of this host)",hint:r.jsx(ne,{children:"A webhook with its own signing token rejects unsigned deliveries either way, unless it is set to accept both."}),children:r.jsxs(Ne,{value:String(v.reqSig),onChange:y=>w({...v,reqSig:y.target.value==="true"}),children:[r.jsx("option",{value:"false",children:"Accept with a secret token (unless the webhook has a signing token)"}),r.jsx("option",{value:"true",children:"Reject everywhere (signed deliveries only)"})]})})]}),r.jsx(cs,{})]}),r.jsx(is,{title:"Bot identity",children:r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ee,{label:"Mention name",hint:r.jsx(Qa,{feature:"hosts"}),children:r.jsx(ve,{value:v.bot,placeholder:"default: the token's user",disabled:!l&&!v.bot,onChange:x("bot")})}),r.jsx(ee,{label:"Reviewer username",children:r.jsx(ve,{value:v.reviewer,placeholder:"default: the token's user",disabled:!l&&!v.reviewer,onChange:x("reviewer")})})]})}),r.jsxs("div",{className:"flex flex-wrap gap-2",children:[r.jsx(re,{onClick:C,children:t?"Save host":"Add host"}),r.jsx(re,{variant:"outline",onClick:s,children:"Cancel"})]})]})}function V2(){const t=et(),o=to(),s=qt("hosts"),[a,l]=m.useState(null),[u,d]=m.useState(null),[h,g]=m.useState(null),[v,w]=m.useState({}),x=()=>Ke("/admin/api/hosts").then(l).catch(S=>t(Ee(S),!0));m.useEffect(()=>{x()},[]);const C=S=>{w(R=>({...R,[S.id]:{ok:!1,pending:!0}})),Qt(`/admin/api/hosts/${S.id}/test`).then(R=>w(N=>({...N,[S.id]:R}))).catch(R=>w(N=>({...N,[S.id]:{ok:!1,summary:"Check failed",message:Ee(R)}})))},y=async S=>{await o({title:"Delete "+S.name+"?",description:"Webhooks from it will be rejected and its stored tokens removed.",action:"Delete host",danger:!0})&&Co("/admin/api/hosts/"+S.id).then(()=>{t("Deleted "+S.name),x()}).catch(R=>t(Ee(R),!0))},_=(a==null?void 0:a.mode)==="database",b=u?(a==null?void 0:a.hosts.find(S=>S.id===u))??null:null,j=h?(a==null?void 0:a.hosts.find(S=>S.id===h))??null:null;return r.jsxs("section",{className:"grid gap-4",children:[r.jsxs(lr,{children:[r.jsxs("span",{className:"text-sm text-muted-foreground",children:[a&&(_?"Managed here; stored encrypted in the database.":`Hosts come from the config file (read-only). Set ${a.key_env||"CODEREVIEW_CONSOLE_SECRET_KEY"} to manage them here.`),a&&!s&&" Free: one host per platform."]}),r.jsx("span",{className:"flex-1"}),_&&r.jsxs(re,{variant:"outline",onClick:()=>d(0),children:[r.jsx(ps,{})," Add host"]})]}),r.jsx(un,{children:a?a.hosts.length?r.jsxs(zn,{children:[r.jsx(Fn,{children:r.jsxs(ct,{children:[r.jsx(je,{className:"pl-4",children:"Host"}),r.jsx(je,{children:"Credentials"}),r.jsx(je,{children:"Webhooks"}),r.jsx(je,{children:"Check"}),r.jsx(je,{})]})}),r.jsx($n,{children:a.hosts.map(S=>{const R=S.secrets,N=[R.token&&"token set",S.settings.app_id&&`App ${S.settings.app_id}${R.app_private_key?", key set":" (no key)"}`,R.api_token&&"API token set"].filter(Boolean),E=v[S.id]||S.check;return r.jsxs(ct,{children:[r.jsxs(ke,{className:"pl-4 align-top",children:[r.jsx("div",{className:"font-medium",children:S.name}),r.jsxs(ne,{children:[z2[S.platform]," · ",S.host]}),r.jsx("div",{className:"mt-1.5",children:S.licensed?r.jsx(Je,{kind:S.enabled?"on":"idle",children:S.enabled?"Enabled":"Disabled"}):r.jsx(Je,{kind:"warn",children:"Inactive: needs a license"})}),S.enabled&&r.jsx(H2,{e:S.token_expiry})]}),r.jsxs(ke,{className:"align-top whitespace-normal",children:[r.jsx("div",{className:"flex flex-wrap gap-1",children:N.map(P=>r.jsx(Tt,{variant:"outline",className:"font-normal text-muted-foreground",children:P},P))}),r.jsxs(ne,{children:["mention: ",S.settings.bot_name?"@"+S.settings.bot_name:"token user",S.settings.reviewer?" · reviewer: "+S.settings.reviewer:""]})]}),r.jsxs(ke,{className:"max-w-80 align-top whitespace-normal",children:[S.webhooks.length?r.jsx("div",{className:"grid gap-0.5 text-sm",children:S.webhooks.map(P=>r.jsx("div",{className:P.enabled?"":"text-muted-foreground line-through",children:P.name},P.id))}):r.jsx(ne,{children:"None yet"}),S.comment_warning&&r.jsx("div",{className:"mt-1.5",children:r.jsx(Je,{kind:"warn",children:"No comment events"})}),r.jsxs(re,{variant:"link",size:"sm",className:"h-auto px-0",onClick:()=>g(S.id),children:[r.jsx(Vv,{})," ",_?"Manage webhooks":"Show URLs"]})]}),r.jsx(ke,{className:"w-56 max-w-56 align-top whitespace-normal",children:r.jsx(G2,{t:E})}),r.jsx(ke,{className:"pr-4 text-right align-top",children:r.jsxs("div",{className:"flex justify-end gap-1",children:[r.jsxs(re,{variant:"ghost",size:"sm",onClick:()=>C(S),children:[r.jsx(xk,{})," Test"]}),_&&r.jsxs(r.Fragment,{children:[r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>d(S.id),children:"Edit"}),r.jsx(re,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>y(S),children:"Delete"})]})]})})]},S.id)})})]}):r.jsx(qe,{children:"No code hosts yet. Add GitHub, GitLab or Bitbucket."}):r.jsx(qe,{children:"Loading…"})}),r.jsxs(He,{children:["Each host is a GitHub (github.com or Enterprise), GitLab (gitlab.com or self-managed) or Bitbucket Cloud account the console reviews for. Tokens and webhook secrets are encrypted with ",r.jsx("code",{children:"CODEREVIEW_CONSOLE_SECRET_KEY"})," before they are stored and are never shown again: leave a secret blank to keep it. Under ",r.jsx("b",{children:"Manage webhooks"}),", add one webhook per hook you set up (a GitLab system hook, each group hook): each gets its own URL and secret, so one can be replaced or removed without touching the others."]}),r.jsx(ko,{open:j!==null,onClose:()=>g(null),title:j?"Webhooks: "+j.name:"",description:"Each webhook has its own URL and secret.",wide:!0,children:j&&r.jsx(B2,{host:j,managed:_,onChanged:x},j.id)}),r.jsx(ko,{open:u!==null,onClose:()=>d(null),title:b?"Edit "+b.name:"New host",description:"Credentials are encrypted before they are stored.",children:u!==null&&r.jsx(W2,{host:b,onCancel:()=>d(null),onSaved:S=>{d(null),x().then(()=>C(S))}},u)})]})}function H2({e:t}){if(!t)return null;if(t.error)return r.jsxs(ne,{className:"text-destructive",children:["Token: ",t.error]});if(!t.known)return null;if(!t.expires)return r.jsx(ne,{children:"Token never expires"});const o=new Date(t.expires),s=Math.ceil((o.getTime()-Date.now())/864e5),a=di(o);return s<=0?r.jsx("div",{className:"mt-1",children:r.jsxs(Je,{kind:"warn",children:["Token expired ",a]})}):s<=14?r.jsx("div",{className:"mt-1",children:r.jsxs(Je,{kind:"warn",children:["Token expires in ",s," ",s===1?"day":"days"]})}):r.jsxs(ne,{children:["Token expires ",a]})}function G2({t}){const[o,s]=m.useState(!1);if(!t)return r.jsx(ne,{children:"Not tested"});if(t.pending)return r.jsx("span",{className:"text-sm text-muted-foreground",children:"testing…"});const a=t.summary||(t.ok?"OK":"Check failed");return r.jsxs("div",{className:"grid min-w-0 gap-1",title:t.message,children:[r.jsx("div",{children:r.jsx(Je,{kind:t.ok?"on":"off",children:a})}),t.at&&r.jsx(ne,{children:qr(t.at)}),t.message&&t.message!==a&&r.jsxs(r.Fragment,{children:[r.jsx("button",{type:"button",className:"w-fit text-xs text-muted-foreground underline-offset-2 hover:underline",onClick:()=>s(!o),children:o?"Hide details":"Details"}),o&&r.jsx("div",{className:"text-xs break-words text-muted-foreground",children:t.message})]})]})}const Cd=[["enabled","Reviews","Enabled","Disabled"],["require_reviewer","Reviewer required","On","Off"],["skip_branch_sync","Branch syncs","Skip","Review"],["score_labels","Score labels","On","Off"],["commit_status","Commit status","On","Off"],["approve","Approve MRs","On","Off"]],ai=t=>t.pattern||"Whole host";function K2({rule:t,onSave:o,onDelete:s}){const[a,l]=m.useState(()=>Object.fromEntries(Cd.map(([u])=>[u,t[u]??null])));return r.jsx(kf,{value:t.settings,inheritModel:"Inherit",onSave:u=>o({...a,settings:u}),danger:r.jsx(re,{variant:"ghost",className:"text-destructive hover:text-destructive",onClick:s,children:"Delete rule"}),extra:r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"grid gap-3",children:[r.jsx("h3",{className:"text-xs font-semibold tracking-wide text-muted-foreground uppercase",children:"Settings for this level"}),r.jsx(Ge,{className:"lg:grid-cols-2",children:Cd.map(([u,d,h,g])=>r.jsx(ee,{label:d,children:r.jsx(ll,{value:a[u],on:h,off:g,onChange:v=>l({...a,[u]:v})})},u))})]}),r.jsx(cs,{}),r.jsx("h3",{className:"text-xs font-semibold tracking-wide text-muted-foreground uppercase",children:"Review settings"})]})})}function q2(){const t=et(),o=to(),s=qt("rules"),[a,l]=m.useState(null),[u,d]=m.useState([]),[h,g]=m.useState(null),[v,w]=m.useState(!1),[x,C]=m.useState({platform:"gitlab",host:"",pattern:"",enabled:null}),y=()=>Ke("/admin/api/repos").then(E=>d(E||[]));m.useEffect(()=>{Ke("/admin/api/rules").then(E=>l(E||[])).catch(E=>t(Ee(E),!0)),y().catch(()=>{})},[]);const _=E=>{const P=E.pattern?E.pattern:"host "+E.host;return u.filter(I=>(I.effective.rules||[]).includes(P)&&I.platform===E.platform&&I.host===E.host).length},b=()=>{const E={platform:x.platform,host:x.host.trim(),pattern:x.pattern.trim()};x.enabled!==null&&(E.enabled=x.enabled),Qt("/admin/api/rules",E).then(P=>(l(I=>(I||[]).filter(F=>F.id!==P.id).concat([P])),C({...x,pattern:""}),w(!1),g(P.id),t("Saved rule "+ai(P)+" — set its options"),y())).catch(P=>t(Ee(P),!0))},j=(E,P)=>bn("/admin/api/rules/"+E.id,P).then(I=>(l(F=>(F||[]).map(A=>A.id===I.id?I:A)),g(null),t("Saved "+ai(I)),y())).catch(I=>t(Ee(I),!0)),S=async E=>{await o({title:"Delete the rule for "+ai(E)+"?",description:"On "+E.host+". Repositories fall back to the level above.",action:"Delete rule",danger:!0})&&Co("/admin/api/rules/"+E.id).then(()=>(l(P=>(P||[]).filter(I=>I.id!==E.id)),g(null),t("Deleted rule "+ai(E)),y())).catch(P=>t(Ee(P),!0))},R=(a||[]).slice().sort((E,P)=>(E.platform+E.host).localeCompare(P.platform+P.host)||(E.pattern?1:0)-(P.pattern?1:0)||E.pattern.localeCompare(P.pattern)),N=(a==null?void 0:a.find(E=>E.id===h))??null;return r.jsxs("section",{className:"grid gap-4",children:[!s&&r.jsx(ji,{feature:"rules",children:"Settings for a whole host, a group or a name pattern are part of the licensed console. Without a license, repositories follow the global settings and their own mode; any rules below are kept but ignored."}),r.jsxs(lr,{children:[r.jsx("span",{className:"text-sm text-muted-foreground",children:"Settings for a whole host, or for a group, organisation or name pattern on a host."}),r.jsx("span",{className:"flex-1"}),s&&r.jsxs(re,{variant:"outline",onClick:()=>w(!0),children:[r.jsx(ps,{})," Add rule"]})]}),r.jsx(un,{children:a?a.length?r.jsxs(zn,{children:[r.jsx(Fn,{children:r.jsxs(ct,{children:[r.jsx(je,{className:"pl-4",children:"Scope"}),r.jsx(je,{children:"Sets"}),r.jsx(je,{children:"Covers"}),r.jsx(je,{children:"Last changed"}),r.jsx(je,{})]})}),r.jsx($n,{children:R.map(E=>{const P=_(E),I=Cd.filter(([F])=>E[F]!==null&&E[F]!==void 0).map(([F,A,q,B])=>A+": "+(E[F]?q:B));return r.jsxs(ct,{children:[r.jsxs(ke,{className:"pl-4 align-top",children:[r.jsx("div",{children:E.pattern?r.jsx("code",{children:E.pattern}):r.jsx("b",{children:"Whole host"})}),r.jsxs(ne,{children:[E.platform," · ",E.host]})]}),r.jsxs(ke,{className:"align-top whitespace-normal",children:[r.jsx(bd,{items:I,empty:"inherits everything"}),r.jsx("div",{className:"mt-1",children:r.jsx(bd,{items:bw(E.settings)})})]}),r.jsx(ke,{className:"align-top text-muted-foreground",children:P+(P===1?" known repository":" known repositories")}),r.jsx(ke,{className:"align-top text-muted-foreground",children:E.updated_by?E.updated_by+" · "+Hr(E.updated_at):"—"}),r.jsx(ke,{className:"pr-4 text-right align-top",children:s?r.jsx(re,{variant:"ghost",size:"sm",onClick:()=>g(E.id),children:"Edit"}):r.jsx(re,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>S(E),children:"Delete"})})]},E.id)})})]}):r.jsx(qe,{children:"No rules yet. Add one for a whole host, a group or a name pattern."}):r.jsx(qe,{children:"Loading…"})}),r.jsxs(He,{children:["Levels, broadest first: ",r.jsx("b",{children:"Settings"})," (everything) → ",r.jsx("b",{children:"whole host"})," (empty pattern) → ",r.jsx("b",{children:"group or owner"})," (",r.jsx("code",{children:"acme"}),", ",r.jsx("code",{children:"acme/platform"}),", subgroups included) or ",r.jsx("b",{children:"pattern"})," (",r.jsx("code",{children:"acme/svc-*"}),"; ",r.jsx("code",{children:"*"})," stays within one level) → ",r.jsx("b",{children:"repository"}),". For each setting the most specific level that sets it wins; ",r.jsx("b",{children:"Inherit"}),' means "use the level above". Review settings add up the same way. Hosts are separate: a rule for ',r.jsx("code",{children:"acme"})," on one host never touches ",r.jsx("code",{children:"acme"})," on another."]}),r.jsx(ko,{open:!!N,onClose:()=>g(null),title:N?ai(N):"",description:N?`${N.platform} · ${N.host}`:void 0,children:N&&r.jsx(K2,{rule:N,onSave:E=>j(N,E),onDelete:()=>S(N)},N.id)}),r.jsx(Nf,{open:v,onOpenChange:w,children:r.jsxs(Ef,{className:"sm:max-w-lg",children:[r.jsxs(Rf,{children:[r.jsx(Tf,{children:"Add rule"}),r.jsx(Df,{children:"After adding it, set its options."})]}),r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ee,{label:"Platform",children:r.jsxs(Ne,{value:x.platform,onChange:E=>C({...x,platform:E.target.value}),children:[r.jsx("option",{value:"gitlab",children:"GitLab"}),r.jsx("option",{value:"github",children:"GitHub"})]})}),r.jsx(ee,{label:"Host",children:r.jsx(ve,{placeholder:"gitlab.com",value:x.host,onChange:E=>C({...x,host:E.target.value})})}),r.jsx(ee,{label:"Group, owner or pattern",className:"sm:col-span-2",children:r.jsx(ve,{placeholder:"empty = whole host · acme · acme/svc-*",value:x.pattern,onChange:E=>C({...x,pattern:E.target.value})})}),r.jsx(ee,{label:"Reviews",children:r.jsx(ll,{value:x.enabled,on:"Enabled",off:"Disabled",onChange:E=>C({...x,enabled:E})})})]}),r.jsxs(Pf,{children:[r.jsx(re,{variant:"outline",onClick:()=>w(!1),children:"Cancel"}),r.jsx(re,{onClick:b,children:"Add rule"})]})]})})]})}const Og=["queued","ignored","duplicate","rejected","error"],Y2=t=>({queued:"on",rejected:"off",error:"off"})[t]||"idle";function Q2(){const t=et(),[o,s]=m.useState(null),[a,l]=m.useState({}),[u,d]=m.useState(!1),[h,g]=Of({project:"",outcome:""}),[v,w]=m.useState(h.project),x=h.outcome,C=j=>g({outcome:j}),[y,_]=m.useState({});m.useEffect(()=>{Ke("/admin/api/hosts").then(j=>_(Object.fromEntries(j.hosts.flatMap(S=>(S.webhooks||[]).map(R=>[R.id,R.name]))))).catch(()=>{})},[]);const b=j=>{const S=j&&(o!=null&&o.length)?o[o.length-1].id:void 0;Ke("/admin/api/webhooks"+td({limit:100,project:v.trim(),outcome:x,before:S})).then(R=>{s(N=>j?(N||[]).concat(R.events):R.events),l(R.counts_24h||{}),d(R.events.length>=100)}).catch(R=>t(Ee(R),!0))};return m.useEffect(()=>{const j=window.setTimeout(()=>(b(),g({project:v.trim()})),v?250:0);return()=>window.clearTimeout(j)},[v,x]),m.useEffect(()=>{h.project!==v.trim()&&w(h.project)},[h.project]),r.jsxs("section",{className:"grid gap-4",children:[r.jsxs(lr,{children:[r.jsxs("div",{className:"relative w-full sm:w-64",children:[r.jsx(pl,{className:"pointer-events-none absolute top-2.5 left-2.5 size-4 text-muted-foreground"}),r.jsx(ve,{type:"search",className:"pl-8",placeholder:"Filter by project","aria-label":"Filter webhooks by project",value:v,onChange:j=>w(j.target.value)})]}),r.jsxs(Ne,{className:"w-auto","aria-label":"Outcome",value:x,onChange:j=>C(j.target.value),children:[r.jsx("option",{value:"",children:"All outcomes"}),Og.map(j=>r.jsx("option",{value:j,children:j[0].toUpperCase()+j.slice(1)},j))]}),r.jsxs("span",{className:"text-sm text-muted-foreground",children:["Last 24 h: ",Og.map(j=>(a[j]||0)+" "+j).join(" · ")]}),r.jsx("span",{className:"flex-1"}),r.jsxs(re,{variant:"outline",onClick:()=>b(),children:[r.jsx(Mv,{})," Refresh"]})]}),r.jsx(un,{children:o?o.length?r.jsxs(zn,{children:[r.jsx(Fn,{children:r.jsxs(ct,{children:[r.jsx(je,{className:"pl-4",children:"When"}),r.jsx(je,{children:"Project"}),r.jsx(je,{children:"Event"}),r.jsx(je,{children:"Outcome"}),r.jsx(je,{children:"Reason"}),r.jsx(je,{className:"pr-4",children:"Via"})]})}),r.jsx($n,{children:o.map(j=>{const S=[j.kind||j.event,j.action].filter(Boolean).join(" · ")+(j.number?" · !"+j.number:"");return r.jsxs(ct,{children:[r.jsx(ke,{className:"pl-4 align-top text-muted-foreground",title:qr(j.received_at,!0)+" · "+ml(j.received_at),children:Hr(j.received_at)}),r.jsxs(ke,{className:"align-top",children:[r.jsx("div",{className:"font-medium",children:j.project||"—"}),r.jsx(ne,{children:j.platform+(j.host?" · "+j.host:"")})]}),r.jsxs(ke,{className:"align-top",children:[r.jsx("div",{children:S||"—"}),r.jsx(ne,{children:j.event+(j.sender?" · by "+j.sender:"")})]}),r.jsx(ke,{className:"align-top",children:r.jsx(Je,{kind:Y2(j.outcome),children:j.outcome})}),r.jsx(ke,{className:"reason min-w-64 align-top text-sm whitespace-normal text-muted-foreground",children:j.reason}),r.jsxs(ke,{className:"pr-4 align-top text-muted-foreground",children:[r.jsx("div",{children:j.endpoint?y[j.endpoint]||"unknown webhook":"shared URL (removed)"}),r.jsxs(ne,{className:j.auth==="token-unsigned"?"text-warning":"",title:j.auth==="token-unsigned"?"Accepted by the secret token although a signing token is set: the delivery wasn't signed":void 0,children:[j.auth==="token-unsigned"?"secret token, not signed":j.auth,j.source_ip?" · from "+j.source_ip:""]})]})]},j.id)})})]}):r.jsx(qe,{children:"No webhook deliveries match."}):r.jsx(qe,{children:"Loading…"})}),u&&r.jsx("div",{children:r.jsx(re,{variant:"outline",onClick:()=>b(!0),children:"Load older"})}),r.jsxs(He,{children:["Every webhook delivery and what the console did with it. ",r.jsx("b",{children:"Ignored"})," is normal for events that should not start a review (approvals, label or reviewer changes, edits without new commits) and for repositories that are not enabled. ",r.jsx("b",{children:"Rejected"})," means the signature or token did not match. History is kept for the days set in Settings (14 by default)."]})]})}function li({title:t,description:o,children:s}){return r.jsxs(lt,{children:[r.jsxs(cn,{children:[r.jsx(yn,{className:"h2",children:t}),o&&r.jsx(wn,{children:o})]}),r.jsx(Pt,{children:s})]})}function Xn({label:t,value:o,onChange:s,hint:a,placeholder:l,min:u,max:d}){return r.jsx(ee,{label:t,hint:a,children:r.jsx(ve,{type:"number",min:u,max:d,placeholder:l,value:o||"",onChange:h=>s(parseInt(h.target.value||"0",10))})})}function X2(t,o,s){return t==="public"?"Anyone who can reach the console's URL sees it. Hide repository names unless that is intended.":t==="token"?s||!o?"Set a token first: without one, only admins can open it.":"Admins at /admin/dashboard, and anyone with the token at /dashboard.":"Admins open it at /admin/dashboard (the sidebar link). /dashboard sends everyone else to sign in."}function Mg(t,o){const s=new URL(location.origin),a=["- job_name: code-review-console"," scheme: "+s.protocol.replace(":","")," metrics_path: /metrics"," static_configs:",' - targets: ["'+s.host+'"]'];return t==="token"&&a.push(" authorization:"," credentials: "+(o||"")),a.join(` -`)}function Ag(t){return location.origin+"/dashboard?token="+encodeURIComponent(t)}const J2=1440*60*1e3;function Z2({v:t,clearing:o,replacing:s}){if(o)return r.jsx(ne,{children:"The token is removed when you save."});if(s)return r.jsx(ne,{children:"The new token replaces the current one when you save; the old link stops working."});if(!t.dashboard_token_set)return r.jsx(ne,{children:"No token."});if(t.dashboard_token_expired)return r.jsx(Je,{kind:"warn",children:"Expired: generate a new token"});if(!t.dashboard_token_expires)return r.jsx(Je,{kind:"on",children:"Set, never expires"});const a=new Date(t.dashboard_token_expires),l=di(a);return a.getTime()-Date.now()<7*J2?r.jsxs(Je,{kind:"warn",children:["Expires soon: ",l]}):r.jsxs(Je,{kind:"on",children:["Set, expires ",l]})}function Lg(){const t=new Uint8Array(16);return crypto.getRandomValues(t),Array.from(t,o=>o.toString(16).padStart(2,"0")).join("")}function eR(){const t=et(),o=no(),[s,a]=m.useState(null),[l,u]=m.useState(""),[d,h]=m.useState(""),[g,v]=m.useState(""),[w,x]=m.useState(!1),[C,y]=m.useState(90),[_,b]=m.useState(!1),[j,S]=m.useState(""),[R,N]=m.useState(!1),[E,P]=m.useState(!1),I=z=>{const Z={...z,extra_env:z.extra_env??[],engine:z.engine??{},env_set:z.env_set??{}};a(Z),u(Z.extra_env.join(", ")),h(Z.engine.defaults?JSON.stringify(Z.engine.defaults,null,2):""),v(""),x(!1),b(!1),S(""),N(!1),P(!1)};if(m.useEffect(()=>{Ke("/admin/api/tuning").then(I).catch(z=>t(Ee(z),!0))},[]),!s)return r.jsx(qe,{children:"Loading…"});const F=z=>Z=>a({...s,[z]:Z}),A=z=>Z=>a({...s,engine:{...s.engine,[z]:Z}}),q=async()=>{let z;if(d.trim())try{z=JSON.parse(d)}catch{t("Repository defaults: not valid JSON",!0);return}const Z={...s,engine:{...s.engine,defaults:z},extra_env:l.split(/[\s,]+/).map(se=>se.trim()).filter(Boolean),dashboard_token:g,clear_dashboard_token:w,dashboard_token_valid_days:C,metrics_token:j,clear_metrics_token:R};try{I(await bn("/admin/api/tuning",Z)),t("Settings saved")}catch(se){t(Ee(se),!0)}},B=s.engine.verify===void 0||s.engine.verify===null?"":String(s.engine.verify);return r.jsxs("section",{className:"grid gap-4",children:[r.jsx(li,{title:"Queue",description:"How many reviews run at once and how long they may take. Changes apply at once; running reviews finish with their old timeout.",children:r.jsxs(Ge,{className:"lg:grid-cols-3",children:[r.jsx(Xn,{label:"Reviews at once",min:1,max:64,value:s.workers,onChange:F("workers"),hint:r.jsx(ne,{children:"Each one is a container or pod with the Executor page's resources."})}),r.jsx(Xn,{label:"Waiting reviews (queue size)",min:1,max:1e4,value:s.queue_size,onChange:F("queue_size"),hint:r.jsx(ne,{children:"More webhooks get HTTP 503 and the code host retries."})}),r.jsx(ee,{label:"Review timeout",hint:r.jsx(ne,{children:"Between 1m and 6h."}),children:r.jsx(ve,{value:s.job_timeout,placeholder:"20m",onChange:z=>F("job_timeout")(z.target.value)})}),r.jsx(ee,{label:"Wait after a push",hint:r.jsx(ne,{children:"Pushes within this time become one review. 0s reviews at once."}),children:r.jsx(ve,{value:s.debounce,placeholder:"30s",onChange:z=>F("debounce")(z.target.value)})}),r.jsx(Xn,{label:"Jobs on the dashboard",min:10,max:5e3,value:s.history,onChange:F("history")})]})}),r.jsx(li,{title:"Review engine",description:"The codereview CLI's review settings. Leave a field empty for the CLI's default.",children:r.jsxs(Ge,{className:"lg:grid-cols-3",children:[r.jsx(Xn,{label:"Model calls at once, per review",placeholder:"4",min:0,max:32,value:s.engine.concurrency,onChange:A("concurrency")}),r.jsx(Xn,{label:"Tokens per model call",placeholder:"40000",min:0,value:s.engine.batch_tokens,onChange:A("batch_tokens")}),r.jsx(Xn,{label:"Skip reviews with more files than",placeholder:"150",min:0,value:s.engine.max_files,onChange:A("max_files")}),r.jsx(Xn,{label:"Send whole files up to (lines)",placeholder:"800",min:0,value:s.engine.full_file_max_lines,onChange:A("full_file_max_lines")}),r.jsx(Xn,{label:"Context lines around changes",placeholder:"60",min:0,value:s.engine.context_lines,onChange:A("context_lines")}),r.jsx(Xn,{label:"Review passes",placeholder:"1",min:0,max:3,value:s.engine.passes,onChange:A("passes"),hint:r.jsx(ne,{children:"2 or 3 catch more, for one more model call each."})}),r.jsx(ee,{label:"Verification pass",children:r.jsxs(Ne,{value:B,onChange:z=>A("verify")(z.target.value===""?null:z.target.value==="true"),children:[r.jsx("option",{value:"",children:"CLI default (on)"}),r.jsx("option",{value:"true",children:"On"}),r.jsx("option",{value:"false",children:"Off"})]})}),r.jsx(ee,{label:"Verification model",children:r.jsxs(Ne,{value:s.engine.verify_model||"",onChange:z=>A("verify_model")(z.target.value),children:[r.jsx("option",{value:"",children:"The review model"}),s.engine.verify_model&&!o.profiles.includes(s.engine.verify_model)&&r.jsx("option",{value:s.engine.verify_model,children:s.engine.verify_model}),o.profiles.map(z=>r.jsx("option",{value:z,children:z},z))]})}),r.jsx(ee,{label:"The verifier may drop",children:r.jsxs(Ne,{value:s.engine.verify_can_drop||"",onChange:z=>A("verify_can_drop")(z.target.value),children:[r.jsx("option",{value:"",children:"CLI default (confident)"}),r.jsx("option",{value:"confident",children:"Minor findings, and major ones it is sure are wrong"}),r.jsx("option",{value:"minor",children:"Only minor and nitpick findings"}),r.jsx("option",{value:"all",children:"Anything it disputes"})]})}),r.jsx(ee,{label:"The verifier may add findings",children:r.jsxs(Ne,{value:String(!!s.engine.verify_can_add),onChange:z=>A("verify_can_add")(z.target.value==="true"),children:[r.jsx("option",{value:"false",children:"No"}),r.jsx("option",{value:"true",children:"Yes"})]})}),r.jsx(ee,{label:"Repository config file",children:r.jsx(ve,{placeholder:".codereview.yaml",value:s.engine.repo_config_file||"",onChange:z=>A("repo_config_file")(z.target.value)})}),r.jsx(ee,{label:"Repositories may pick a model",children:r.jsxs(Ne,{value:String(s.allow_repo_model),onChange:z=>F("allow_repo_model")(z.target.value==="true"),children:[r.jsx("option",{value:"false",children:"No"}),r.jsx("option",{value:"true",children:"Yes, with model: in their config file"})]})}),r.jsx(ee,{label:"Repository defaults (JSON)",className:"lg:col-span-3",hint:r.jsx(ne,{children:"Keys of a repository config file (language, path_filters, path_instructions, guidelines, high_level_summary…), applied under each repository's own file. The profile, comment limit and severity are under Default review settings."}),children:r.jsx(an,{rows:4,spellCheck:!1,className:"font-mono text-xs",placeholder:'{"language": "English", "path_filters": ["!**/*.lock"]}',value:d,onChange:z=>h(z.target.value)})})]})}),r.jsx(li,{title:"Bot and review jobs",children:r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ee,{label:"Default bot name",hint:r.jsx(ne,{children:"The mention handle (@name review) for hosts that set none. Empty: each host's token user."}),children:r.jsx(ve,{placeholder:"codereview",value:s.bot_name||"",onChange:z=>F("bot_name")(z.target.value)})}),r.jsx(ee,{label:"Extra environment variables for reviews",hint:r.jsxs("span",{className:"grid gap-1",children:[r.jsx(ne,{children:"Names of the console's variables to pass to every review (model key variables are passed already). The console's own secrets can't be passed."}),s.extra_env.length>0&&r.jsx("span",{className:"flex flex-wrap gap-1.5",children:s.extra_env.map(z=>r.jsxs(Je,{kind:s.env_set[z]?"on":"warn",children:[z,s.env_set[z]?"":": not set"]},z))})]}),children:r.jsx(ve,{placeholder:"MY_PROXY_CA, SSL_CERT_DIR",value:l,onChange:z=>u(z.target.value)})})]})}),r.jsx(li,{title:"Status dashboard access",description:"The status dashboard shows every running and recent review, with repository names unless they are hidden under Status dashboard above.",children:r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ee,{label:"Who can open it",hint:r.jsx(ne,{children:X2(s.dashboard_access,s.dashboard_token_set||!!g,w)}),children:r.jsxs(Ne,{value:s.dashboard_access,onChange:z=>F("dashboard_access")(z.target.value),children:[r.jsx("option",{value:"admins",children:"Signed-in admins only"}),r.jsx("option",{value:"token",children:"Admins, and anyone with the token"}),r.jsx("option",{value:"public",children:"Anyone who can reach the console"})]})}),r.jsx(ee,{label:"Dashboard token",hint:r.jsx(ne,{children:"For screens and people without an admin sign-in: /dashboard?token=… or a Bearer header. Stored hashed and never shown again."}),children:r.jsxs("div",{className:"grid gap-2",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx(ve,{className:"max-w-sm font-mono",placeholder:s.dashboard_token_set?"Set (leave empty to keep it)":"Not set",value:g,onChange:z=>{v(z.target.value),x(!1),b(!1)}}),r.jsx(re,{variant:"outline",onClick:()=>{v(Lg()),x(!1),b(!1)},children:"Generate"}),s.dashboard_token_set&&r.jsx(re,{variant:"ghost",className:"text-destructive",onClick:()=>{v(""),x(!0)},disabled:w,children:w?"Removed on save":"Remove"})]}),r.jsx(Z2,{v:s,clearing:w,replacing:!!g})]})}),g&&r.jsxs(r.Fragment,{children:[r.jsx(ee,{label:"New token valid for",hint:r.jsx(ne,{children:"Counted from when you save. After that the link stops working until a new token is generated."}),children:r.jsxs(Ne,{value:String(C),onChange:z=>y(parseInt(z.target.value,10)),children:[r.jsx("option",{value:"7",children:"7 days"}),r.jsx("option",{value:"30",children:"30 days"}),r.jsx("option",{value:"90",children:"90 days"}),r.jsx("option",{value:"365",children:"1 year"}),r.jsx("option",{value:"0",children:"Never expires"})]})}),r.jsx(ee,{label:"Link to share",hint:r.jsx(ne,{className:"text-warning",children:"Copy it now: once saved, the token can't be shown again."}),children:r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx(ve,{readOnly:!0,className:"font-mono text-xs",value:Ag(g),onFocus:z=>z.target.select()}),r.jsx(re,{variant:"outline",onClick:()=>{var z;(z=navigator.clipboard)==null||z.writeText(Ag(g)).then(()=>b(!0),()=>t("Copy failed: select the link and copy it",!0))},children:_?"Copied":"Copy link"})]})})]})]})}),r.jsx(li,{title:"Prometheus metrics",description:"/metrics in the Prometheus text format: queue, reviews by kind and result, durations, tokens, webhooks by outcome, and when the license and host tokens expire. No repository names.",children:r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ee,{label:"Who can read /metrics",hint:r.jsx(ne,{children:s.metrics_access==="public"?"Anyone who can reach the console's URL. Fine on a private network the scraper shares.":s.metrics_access==="token"?"Scrapers send the token as a bearer token.":"Off: /metrics answers 404."}),children:r.jsxs(Ne,{value:s.metrics_access,onChange:z=>F("metrics_access")(z.target.value),children:[r.jsx("option",{value:"off",children:"Off"}),r.jsx("option",{value:"token",children:"Scrapers with the token"}),r.jsx("option",{value:"public",children:"Anyone who can reach the console"})]})}),r.jsx(ee,{label:"Metrics token",hint:r.jsx(ne,{children:R?"Removed when you save.":j?"Replaces the current token when you save.":s.metrics_token_set?"Set. Stored hashed and never shown again.":"No token."}),children:r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx(ve,{className:"max-w-sm font-mono",placeholder:s.metrics_token_set?"Set (leave empty to keep it)":"Not set",value:j,onChange:z=>{S(z.target.value),N(!1),P(!1)}}),r.jsx(re,{variant:"outline",onClick:()=>{S(Lg()),N(!1),P(!1)},children:"Generate"}),s.metrics_token_set&&r.jsx(re,{variant:"ghost",className:"text-destructive",onClick:()=>{S(""),N(!0)},disabled:R,children:R?"Removed on save":"Remove"})]})}),s.metrics_access!=="off"&&r.jsx(ee,{label:"Prometheus scrape config",className:"lg:col-span-2",hint:j?r.jsx(ne,{className:"text-warning",children:"Copy it now: once saved, the token can't be shown again."}):r.jsx(ne,{children:"Generate a token to fill it in."}),children:r.jsxs("div",{className:"grid gap-2",children:[r.jsx(an,{readOnly:!0,rows:s.metrics_access==="token"?7:5,className:"font-mono text-xs",value:Mg(s.metrics_access,j),onFocus:z=>z.target.select()}),r.jsx("div",{children:r.jsx(re,{variant:"outline",size:"sm",onClick:()=>{var z;(z=navigator.clipboard)==null||z.writeText(Mg(s.metrics_access,j)).then(()=>P(!0),()=>t("Copy failed: select the text and copy it",!0))},children:E?"Copied":"Copy"})})]})})]})}),r.jsx(lt,{className:"py-4",children:r.jsxs(dw,{className:"flex flex-wrap items-center gap-3",children:[r.jsx(re,{onClick:q,children:"Save queue and review settings"}),r.jsx(He,{children:"Applies to the next review, without a restart."})]})})]})}const Wu=t=>qr(t),tR={allowlist:"Repositories no rule matches",require_reviewer:"Who asks for a review",skip_branch_sync:"Branch syncs",sync_source_branches:"Also treat these source branches as syncs",score_labels:"Score labels",commit_status:"Commit status",approve:"Approve merge requests",approve_block:"Findings that block approval",approve_min_score:"Lowest score to approve",approve_withdraw:"When a later review doesn't pass",command_access:"Who can run review and question commands",learnings_enabled:"Learn from replies to the bot",learnings_auto_activate:"New learnings",daily_token_budget:"Daily tokens, all repositories",repo_daily_token_budget:"Daily tokens, per repository",review_retention_days:"Keep reviews",webhook_retention_days:"Keep webhook deliveries",dashboard_enabled:"Dashboard",hide_repos:"Repository names",dashboard_title:"Dashboard title",session_idle_minutes:"Sign out after inactivity"};function nR(){const t=et(),o=to(),[s,a]=m.useState(null);m.useEffect(()=>{Ke("/admin/api/sessions").then(a).catch(h=>t(Ee(h),!0))},[]);const l=async h=>{if(h.current){if(!await o({title:"Sign yourself out?",description:"This is the session you are using now.",action:"Sign out"}))return;Qt("/admin/logout").finally(()=>location.href="/admin/login");return}if(await o({title:"Sign out "+(h.name||h.email)+"?",description:"They can sign in again if the sign-in rules still allow them.",action:"Sign out",danger:!0}))try{a(await Co("/admin/api/sessions/"+h.id)),t("Signed out "+h.email)}catch(g){t(Ee(g),!0)}},u=async()=>{if(await o({title:"Sign out everyone else?",description:"Every other admin session ends now. Use it after removing someone from the sign-in rules or if a session may be compromised.",action:"Sign out others",danger:!0}))try{a(await Qt("/admin/api/sessions/end-others")),t("Signed out every other session")}catch(h){t(Ee(h),!0)}},d=s?s.filter(h=>!h.current).length:0;return r.jsxs(lt,{className:"gap-0 overflow-hidden pb-0",children:[r.jsxs(cn,{className:"pb-4",children:[r.jsx(yn,{className:"h2",children:"Signed-in admins"}),r.jsx(wn,{children:"Every request is checked against the current sign-in rules, so someone removed from them is signed out at once. Group changes at the identity provider apply when the session ends (session_ttl) or here."}),d>0&&r.jsx("div",{children:r.jsx(re,{variant:"outline",size:"sm",onClick:u,children:"Sign out everyone else"})})]}),s?r.jsxs(zn,{children:[r.jsx(Fn,{children:r.jsxs(ct,{children:[r.jsx(je,{className:"pl-6",children:"Admin"}),r.jsx(je,{children:"From"}),r.jsx(je,{children:"Signed in"}),r.jsx(je,{children:"Last active"}),r.jsx(je,{children:"Expires"}),r.jsx(je,{})]})}),r.jsx($n,{children:s.map(h=>r.jsxs(ct,{children:[r.jsxs(ke,{className:"pl-6",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[r.jsx("span",{className:"font-medium",children:h.name||h.email}),h.current&&r.jsx(Tt,{variant:"secondary",children:"you, this browser"})]}),h.name&&r.jsx(ne,{children:h.email})]}),r.jsxs(ke,{children:[r.jsx("div",{className:"font-mono text-xs",children:h.ip||"—"}),h.user_agent&&r.jsx(ne,{title:h.user_agent,children:jw(h.user_agent)})]}),r.jsx(ke,{children:Wu(h.created)}),r.jsx(ke,{children:h.last_seen?Wu(h.last_seen):"—"}),r.jsx(ke,{children:Wu(h.expires)}),r.jsx(ke,{className:"pr-6 text-right",children:r.jsx(re,{size:"sm",variant:"ghost",className:h.current?"":"text-destructive",onClick:()=>l(h),children:"Sign out"})})]},h.id))})]}):r.jsx(qe,{children:"Loading…"})]})}function xn({label:t,value:o,onChange:s,yes:a,no:l,disabled:u,note:d}){return r.jsx(ee,{label:t,hint:d,children:r.jsxs(Ne,{value:String(o),disabled:u,onChange:h=>s(h.target.value==="true"),children:[r.jsx("option",{value:"true",children:a}),r.jsx("option",{value:"false",children:l})]})})}function ns({label:t,value:o,onChange:s,note:a,...l}){return r.jsx(ee,{label:t,hint:a,children:r.jsx(ve,{type:"number",value:o||"",...l,onChange:u=>s(parseInt(u.target.value||"0",10))})})}function Fr({title:t,description:o,children:s}){return r.jsxs(lt,{children:[r.jsxs(cn,{children:[r.jsx(yn,{className:"h2",children:t}),o&&r.jsx(wn,{children:o})]}),r.jsx(Pt,{children:s})]})}function rR(){const t=et(),o=bi(),s=no(),a={learnings:qt("learnings"),budgets:qt("budgets"),sync:qt("branch_sync"),metrics:qt("metrics")},[l,u]=m.useState(null),[d,h]=m.useState(null),[g,v]=m.useState(""),[w,x]=m.useState(0),C=j=>{u(j),h(j),v((j.sync_source_branches||[]).join(", "))};if(m.useEffect(()=>{Ke("/admin/api/settings").then(C).catch(j=>t(Ee(j),!0))},[]),!l||!d)return r.jsx(qe,{children:"Loading…"});const y=j=>S=>h({...d,[j]:S}),_=j=>{const{source:S,...R}={...d,review_defaults:j,dashboard_title:d.dashboard_title.trim(),sync_source_branches:g.split(",").map(N=>N.trim()).filter(Boolean)};bn("/admin/api/settings",R).then(N=>{C(N),x(E=>E+1),o(),t("Settings saved")}).catch(N=>t(Ee(N),!0))},b=Object.keys(l.source||{}).filter(j=>l.source[j]==="config").map(j=>tR[j]||j.replace(/_/g," "));return r.jsxs("section",{className:"grid gap-4",children:[r.jsx(Fr,{title:"Repository access",description:"Which repositories are reviewed, and when.",children:r.jsxs(Ge,{children:[r.jsx(xn,{label:"Repositories no rule matches",value:d.allowlist,onChange:y("allowlist"),yes:"Not reviewed (allowlist on)",no:"Reviewed (allowlist off)"}),r.jsx(xn,{label:"Who asks for a review",value:d.require_reviewer,onChange:y("require_reviewer"),yes:"Only when the bot is a reviewer",no:"Any opened MR or push"}),r.jsx(xn,{label:"Branch syncs (source is the default branch)",value:d.skip_branch_sync,onChange:y("skip_branch_sync"),yes:"Skip",no:"Review",disabled:!a.sync,note:r.jsx(Qa,{feature:"branch_sync"})}),r.jsx(ee,{label:"Also treat these source branches as syncs",children:r.jsx(ve,{placeholder:"develop, release/*",value:g,disabled:!a.sync,onChange:j=>v(j.target.value)})}),r.jsx(xn,{label:"Score labels on MRs/PRs",value:d.score_labels,onChange:y("score_labels"),yes:"On",no:"Off"}),r.jsx(xn,{label:"Commit status on the reviewed commit",value:d.commit_status,onChange:y("commit_status"),yes:"On",no:"Off"}),r.jsx(ee,{label:"Who can run review and question commands",hint:r.jsx(He,{className:"text-xs",children:"Commands that run the model spend tokens. Write access means GitLab Developer or higher, GitHub write or above, Bitbucket write or admin (the Bitbucket token needs admin on the repository to check). @bot help works for everyone, and each person is limited to a few commands an hour."}),children:r.jsxs(Ne,{value:d.command_access||"write",onChange:j=>y("command_access")(j.target.value),children:[r.jsx("option",{value:"write",children:"People who can push to the repository"}),r.jsx("option",{value:"anyone",children:"Anyone who can comment"})]})})]})}),r.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[r.jsxs(Fr,{title:"Approve merge requests",description:"The bot approves a merge request whose review passes, as its token's user (or the GitHub App). Rules can turn this on or off for groups and repositories. Needs code-review-bot 0.5 or later on the Executor page.",children:[r.jsxs(Ge,{children:[r.jsx(xn,{label:"Approve when the review passes",value:d.approve,onChange:y("approve"),yes:"On",no:"Off"}),r.jsx(ee,{label:"Findings that block approval",hint:r.jsx(He,{className:"text-xs",children:"New findings, ones beyond the comment limit and ones still open from an earlier review all count; questions don't."}),children:r.jsxs(Ne,{value:d.approve_block||"major",onChange:j=>y("approve_block")(j.target.value),children:[r.jsx("option",{value:"critical",children:"Critical"}),r.jsx("option",{value:"major",children:"Major or critical"}),r.jsx("option",{value:"minor",children:"Minor or above"}),r.jsx("option",{value:"nitpick",children:"Any finding (nitpicks too)"}),r.jsx("option",{value:"none",children:"None: approve whatever it found"})]})}),r.jsx(ns,{label:"Lowest score to approve",value:d.approve_min_score,onChange:y("approve_min_score"),min:0,max:100,placeholder:"0",note:r.jsx(He,{className:"text-xs",children:"Every score (quality, security, maintainability) must be at least this. 0 ignores the scores."})}),r.jsx(xn,{label:"When a later review doesn't pass",value:d.approve_withdraw,onChange:y("approve_withdraw"),yes:"Withdraw the bot's approval",no:"Leave it"})]}),r.jsx(He,{className:"text-xs",children:"A partial or too-large review leaves the approval as it is. GitLab: the bot's user must be allowed to approve. GitHub: withdrawing dismisses the bot's review, which branch protection may restrict."})]}),r.jsx(Fr,{title:"Learnings",children:r.jsxs(Ge,{children:[r.jsx(xn,{label:"Learn from replies to the bot",value:d.learnings_enabled,onChange:y("learnings_enabled"),yes:"On",no:"Off",disabled:!a.learnings,note:r.jsx(Qa,{feature:"learnings"})}),r.jsx(xn,{label:"New learnings",value:d.learnings_auto_activate,onChange:y("learnings_auto_activate"),yes:"Apply at once",no:"Wait for an admin's approval",disabled:!a.learnings,note:r.jsx(He,{className:"text-xs",children:"Even when set to apply at once, a learning only applies right away if its author can push to the repository (GitLab Developer or higher, GitHub write or above). Anyone else's waits for approval, and so does every learning from Bitbucket."})})]})}),r.jsxs(Fr,{title:"Budgets",description:'Input plus output tokens of finished jobs in the current UTC day. When a budget is used up, automatic reviews and chat commands wait until the next day; "Review now" and re-runs from this panel still run.',children:[r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ns,{label:"Daily tokens, all repositories",min:0,step:1e4,placeholder:"0 = no limit",value:d.daily_token_budget,onChange:y("daily_token_budget"),disabled:!a.budgets,note:r.jsx(Qa,{feature:"budgets"})}),r.jsx(ns,{label:"Daily tokens per repository",min:0,step:1e4,placeholder:"0 = no limit",value:d.repo_daily_token_budget,onChange:y("repo_daily_token_budget"),disabled:!a.budgets})]}),a.budgets&&!d.daily_token_budget&&!d.repo_daily_token_budget&&r.jsx(He,{className:"text-warning",children:"No daily limit is set: reviews and commands spend tokens without a cap. Set a budget to bound what a busy day, or misuse, can cost."})]}),r.jsx(Fr,{title:"History",children:r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ns,{label:"Keep reviews (days)",min:1,max:3650,value:d.review_retention_days,onChange:y("review_retention_days"),note:!a.metrics&&d.review_retention_days>s.free_retention_days?r.jsxs("span",{className:"locknote text-xs text-warning",children:["Without a license with metrics and long history, reviews are kept ",s.free_retention_days," days."]}):null}),r.jsx(ns,{label:"Keep webhook deliveries (days)",min:1,max:3650,value:d.webhook_retention_days,onChange:y("webhook_retention_days")})]})}),r.jsx(Fr,{title:"Admin sessions",description:"Every admin session also ends after session_ttl (12 hours by default), whatever happens.",children:r.jsx(Ge,{children:r.jsx(ns,{label:"Sign out after inactivity (minutes)",min:0,max:1440,placeholder:"0 = never",value:d.session_idle_minutes,onChange:y("session_idle_minutes"),note:r.jsx(He,{className:"text-xs",children:"A session that makes no request for this long is signed out, so a browser left open on a shared machine doesn't keep admin rights. The panel's own refreshes (Setup, the dashboard) don't count as activity. 5 to 1440, or 0 for never."})})})}),r.jsx(Fr,{title:"Status dashboard",description:"Who can open it is set under Status dashboard access, further down.",children:r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(xn,{label:"Dashboard",value:d.dashboard_enabled,onChange:y("dashboard_enabled"),yes:"On",no:"Off"}),r.jsx(xn,{label:"Repository names",value:!d.hide_repos,onChange:j=>y("hide_repos")(!j),yes:"Shown",no:"Hidden"}),r.jsx(ee,{label:"Title",className:"sm:col-span-2",children:r.jsx(ve,{maxLength:120,value:d.dashboard_title,onChange:j=>y("dashboard_title")(j.target.value)})})]})})]}),r.jsx(lt,{className:"py-4",children:r.jsxs(dw,{className:"flex flex-wrap items-center gap-3",children:[r.jsx(re,{onClick:()=>_(l.review_defaults),children:"Save settings"}),r.jsx("span",{className:"text-sm text-muted-foreground",children:b.length?"Showing defaults for: "+b.join("; ")+". Save to keep them.":""})]})}),r.jsx(Fr,{title:"Default review settings",description:"Apply to every repository. Group and pattern rules, then repository settings, override them.",children:r.jsx(kf,{value:l.review_defaults,onSave:_,saveLabel:"Save default review settings"},w)}),r.jsx(jd,{name:"Queue, review engine and access settings",children:r.jsx(eR,{})}),r.jsx(jd,{name:"Sign-in sessions",children:r.jsx(nR,{})}),r.jsx(He,{children:"These settings are kept in the database and apply without a restart. Every change is in the audit log."})]})}const Wa={actor:"",action:"",target:"",q:"",from:"",to:""},oR=["login","login.denied","logout","session.*","session.ended","session.revoke","setting.put","host.*","host.put","host.delete","webhook.*","webhook.put","webhook.delete","repo.*","rule.*","learning.*","model.*","audit.export"];function $r(t,o){const s=new URLSearchParams;for(const[a,l]of Object.entries(t))l.trim()&&s.set(a,l.trim());return o&&s.set("before",String(o)),s.toString()}function Xa(t,o="",s={}){if(t&&typeof t=="object"&&!Array.isArray(t)){for(const[a,l]of Object.entries(t))Xa(l,o?o+"."+a:a,s);!Object.keys(t).length&&o&&(s[o]="{}")}else o&&(s[o]=t===void 0?"":typeof t=="string"?t:JSON.stringify(t));return s}const sR=t=>{const[o,s]=t.split(":");return o.replace(/_/g," ")+" "+(s||"changed")};function Pw({detail:t}){const[o,s]=m.useState(!1),a=t&&typeof t=="object"?t:{},l="before"in a||"after"in a,u=Array.isArray(a.secrets_changed)?a.secrets_changed:[];let d=[],h="";if(l){const g=Xa(a.before),v=Xa(a.after);a.before==null&&"after"in a&&(h="created"),"after"in a||(h="deleted");for(const w of Array.from(new Set([...Object.keys(g),...Object.keys(v)])).sort())g[w]!==v[w]&&d.push({key:w,old:a.before==null?void 0:g[w],now:"after"in a?v[w]:void 0})}else d=Object.entries(Xa(t)).map(([g,v])=>({key:g,now:v}));return r.jsxs("div",{className:"grid gap-1 text-xs",children:[h&&r.jsx("span",{className:"text-muted-foreground",children:h}),d.length===0&&!u.length&&!h&&r.jsx("span",{className:"text-muted-foreground",children:l?"no visible change":"—"}),d.slice(0,20).map(g=>r.jsxs("div",{className:"break-all",children:[r.jsx("span",{className:"font-medium",children:g.key}),": ",g.old!==void 0&&r.jsx("span",{className:"text-destructive line-through",children:g.old||"∅"}),g.old!==void 0&&g.now!==void 0&&" → ",g.now!==void 0&&r.jsx("span",{className:l?"text-success":"",children:g.now||"∅"})]},g.key)),d.length>20&&r.jsxs("span",{className:"text-muted-foreground",children:["and ",d.length-20," more (see raw)"]}),u.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1",children:u.map(g=>r.jsx(Tt,{variant:"outline",className:"font-normal",children:sR(g)},g))}),r.jsx("div",{children:r.jsx("button",{type:"button",className:"text-muted-foreground underline-offset-2 hover:underline",onClick:()=>s(!o),children:o?"Hide raw":"Raw"})}),o&&r.jsx("pre",{className:"max-h-60 overflow-auto rounded-md bg-muted p-2 font-mono whitespace-pre-wrap break-all",children:JSON.stringify(t,null,2)})]})}function iR(){const t=et(),o=qt("audit"),[s,a]=Of(Wa),[l,u]=m.useState(s),[d,h]=m.useState(null),[g,v]=m.useState(0),[w,x]=m.useState(!1),C=(S,R)=>{x(!0),Ke("/admin/api/audit?"+$r(S,R)).then(N=>{h(E=>R&&E?[...E,...N.entries]:N.entries),v(N.next)}).catch(N=>t(Ee(N),!0)).finally(()=>x(!1))};if(m.useEffect(()=>{o&&(u(s),C(s))},[o,$r(s)]),!o)return r.jsx("section",{children:r.jsx(ji,{feature:"audit",children:"Every admin change is still recorded; viewing the audit log is part of the licensed console."})});const y=S=>R=>u({...l,[S]:R.target.value}),_=S=>{S==null||S.preventDefault();const R=Object.fromEntries(Object.entries(l).map(([N,E])=>[N,E.trim()]));$r(R)===$r(s)?C(R):a(R)},b=()=>{u(Wa),$r(s)?a(Wa):C(Wa)},j=S=>"/admin/api/audit/export?"+$r(s)+($r(s)?"&":"")+"format="+S;return r.jsxs("section",{className:"grid gap-4",children:[r.jsx(un,{children:r.jsxs("form",{onSubmit:_,className:"grid gap-3 p-4 sm:grid-cols-2 lg:grid-cols-6",children:[r.jsx(ee,{label:"Who",children:r.jsx(ve,{placeholder:"email",value:l.actor,onChange:y("actor")})}),r.jsxs(ee,{label:"Action",children:[r.jsx(ve,{list:"audit-actions",placeholder:"host.* or login.denied",value:l.action,onChange:y("action")}),r.jsx("datalist",{id:"audit-actions",children:oR.map(S=>r.jsx("option",{value:S},S))})]}),r.jsx(ee,{label:"Target",children:r.jsx(ve,{placeholder:"gitlab:group/project",value:l.target,onChange:y("target")})}),r.jsx(ee,{label:"Search",children:r.jsx(ve,{placeholder:"in targets and details",value:l.q,onChange:y("q")})}),r.jsx(ee,{label:"From",children:r.jsx(ve,{type:"date",value:l.from,onChange:y("from")})}),r.jsx(ee,{label:"To",children:r.jsx(ve,{type:"date",value:l.to,onChange:y("to")})}),r.jsxs("div",{className:"flex flex-wrap items-center gap-2 lg:col-span-6",children:[r.jsx(re,{type:"submit",children:"Apply"}),r.jsx(re,{type:"button",variant:"ghost",onClick:b,children:"Clear"}),r.jsx("span",{className:"flex-1"}),r.jsx(re,{asChild:!0,variant:"outline",size:"sm",children:r.jsx("a",{href:j("csv"),children:"Export CSV"})}),r.jsx(re,{asChild:!0,variant:"outline",size:"sm",children:r.jsx("a",{href:j("jsonl"),children:"Export JSON Lines"})})]})]})}),r.jsxs(un,{children:[d?d.length?r.jsxs(zn,{children:[r.jsx(Fn,{children:r.jsxs(ct,{children:[r.jsx(je,{className:"pl-4",children:"When"}),r.jsx(je,{children:"Who"}),r.jsx(je,{children:"Action"}),r.jsx(je,{children:"Target"}),r.jsx(je,{className:"pr-4",children:"Changes"})]})}),r.jsx($n,{children:d.map(S=>r.jsxs(ct,{children:[r.jsx(ke,{className:"pl-4 align-top whitespace-nowrap text-muted-foreground",title:ml(S.at),children:qr(S.at,!0)}),r.jsxs(ke,{className:"align-top",children:[S.actor,S.ip&&r.jsxs(ne,{title:S.user_agent,children:[S.ip,S.user_agent?" · "+jw(S.user_agent):""]})]}),r.jsx(ke,{className:"align-top",children:r.jsx("code",{children:S.action})}),r.jsx(ke,{className:"max-w-56 align-top break-all whitespace-normal",children:S.target}),r.jsx(ke,{className:"max-w-xl min-w-64 pr-4 align-top whitespace-normal",children:r.jsx(Pw,{detail:S.detail})})]},S.id))})]}):r.jsx(qe,{children:$r(s)?"Nothing matches these filters.":"No admin activity yet."}):r.jsx(qe,{children:"Loading…"}),g>0&&r.jsx("div",{className:"flex justify-center p-3",children:r.jsx(re,{variant:"outline",disabled:w,onClick:()=>C(s,g),children:w?"Loading…":"Older entries"})})]})]})}const aR=t=>t==="applied"?"on":t==="pending"?"warn":t==="failed"?"off":"idle";function lR(){const t=et(),o=no(),s=bi(),[a,l]=m.useState("pending"),[u,d]=m.useState(null),[h,g]=m.useState({}),[v,w]=m.useState(null),x=o.role==="admin",C=(b=a)=>Ke("/admin/api/approvals"+(b==="all"?"":"?status="+b)).then(d).catch(j=>t(Ee(j),!0));m.useEffect(()=>{C()},[a]);const y=async(b,j)=>{var S,R;try{const N=await Qt(`/admin/api/approvals/${b.id}/${j}`,j==="reject"?{reason:h[b.id]||""}:void 0);if(j==="approve"){const E=(S=N.request)==null?void 0:S.status;t(E==="applied"?"Applied: "+b.summary:"Failed: "+(((R=N.request)==null?void 0:R.result)||""),E!=="applied"),E==="applied"&&N.response&&JSON.stringify(N.response).includes('"secret"')&&w({summary:b.summary,response:N.response})}else t(j==="reject"?"Rejected":"Cancelled");C(),s()}catch(N){t(Ee(N),!0)}},_=(u||[]).filter(b=>x||b.requested_by===o.email);return r.jsxs("section",{className:"grid gap-4",children:[r.jsx(He,{children:x?"Operators change repositories, rules and learnings and run reviews directly. Their other changes (code hosts, webhooks, settings, models, the executor, the license) wait here for an admin. Approving runs the change as the operator, with the same checks, and the audit log names both of you. Requests expire after 7 days. Merge requests the bot approved are marked on Reviews.":"Changes to code hosts, webhooks, settings, models, the executor and the license wait for an admin. Your requests are listed here; they expire after 7 days."}),v&&r.jsx(un,{children:r.jsxs("div",{className:"grid gap-2 p-4",children:[r.jsxs("div",{className:"font-medium",children:[v.summary,": copy the new secret now, it isn't shown again"]}),r.jsx("pre",{className:"max-h-60 overflow-auto rounded-md bg-muted p-2 font-mono text-xs whitespace-pre-wrap break-all",children:JSON.stringify(v.response,null,2)}),r.jsx("div",{children:r.jsx(re,{variant:"outline",size:"sm",onClick:()=>w(null),children:"Done"})})]})}),r.jsx("div",{className:"flex items-center gap-2",children:r.jsxs(Ne,{className:"w-48",value:a,onChange:b=>l(b.target.value),children:[r.jsx("option",{value:"pending",children:"Waiting"}),r.jsx("option",{value:"all",children:"All requests"})]})}),r.jsx(un,{children:u?_.length?r.jsx("ul",{className:"divide-y",children:_.map(b=>r.jsxs("li",{className:"grid gap-2 p-4 md:grid-cols-[1fr_minmax(16rem,28rem)]",children:[r.jsxs("div",{className:"grid gap-1",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx("span",{className:"font-medium",children:b.summary}),r.jsx(Je,{kind:aR(b.status),children:b.status==="pending"?"waiting":b.status})]}),r.jsxs(ne,{children:["asked by ",b.requested_by," · ",r.jsx("span",{title:ml(b.requested_at),children:qr(b.requested_at)}),b.decided_by&&b.status!=="pending"&&r.jsxs(r.Fragment,{children:[" · ",b.status," by ",b.decided_by,b.decided_at?" "+qr(b.decided_at):""]})]}),b.result&&b.status!=="applied"&&r.jsx(ne,{className:b.status==="failed"?"text-destructive":"",children:b.result}),b.status==="pending"&&r.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2",children:[x&&r.jsx(re,{size:"sm",onClick:()=>y(b,"approve"),children:"Approve"}),x&&r.jsxs(r.Fragment,{children:[r.jsx(ve,{className:"h-8 max-w-60",placeholder:"Reason (optional)",value:h[b.id]||"",onChange:j=>g({...h,[b.id]:j.target.value})}),r.jsx(re,{size:"sm",variant:"outline",onClick:()=>y(b,"reject"),children:"Reject"})]}),b.requested_by===o.email&&r.jsx(re,{size:"sm",variant:"ghost",onClick:()=>y(b,"cancel"),children:"Cancel request"})]})]}),r.jsx("div",{className:"min-w-0",children:r.jsx(Pw,{detail:b.preview})})]},b.id))}):r.jsx(qe,{children:a==="pending"?"No change requests wait for an admin.":"No requests yet."}):r.jsx(qe,{children:"Loading…"})})]})}const cR={none:["Free core","idle"],active:["Active","on"],grace:["Expired — grace period","warn"],expired:["Expired","off"],invalid:["Not valid","off"]};function uR(){const t=no(),o=bi(),s=et(),a=to(),l=t.license,[u,d]=m.useState(""),[h,g]=cR[l.state],v=x=>bn("/admin/api/license",{key:x}).then(()=>{d(""),o(),s(x?"License installed":"License removed")}).catch(C=>s(Ee(C),!0)),w=async()=>{await a({title:"Remove the license?",description:"Paid features turn off at once.",action:"Remove license",danger:!0})&&v("")};return r.jsxs("section",{className:"grid gap-4",children:[r.jsxs(lt,{children:[r.jsx(cn,{children:r.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[r.jsx(Je,{kind:g,children:h}),l.customer&&r.jsxs("span",{className:"text-sm",children:[r.jsx("b",{children:l.customer})," · ",l.plan]}),r.jsx("span",{className:"flex-1"}),l.expires_at&&r.jsxs("span",{className:"text-sm text-muted-foreground",children:["expires ",Hm(l.expires_at)]})]})}),r.jsxs(Pt,{className:"grid gap-4",children:[l.error&&r.jsx(Zn,{variant:"destructive",className:"banner bad",children:r.jsx(er,{children:l.error})}),l.state==="grace"&&r.jsx(Zn,{className:"banner border-warning/40 bg-warning-soft",children:r.jsxs(er,{className:"text-warning",children:["The license has expired. Paid features keep working until ",Hm(l.grace_until),"; renew it to keep them."]})}),r.jsxs("div",{children:[r.jsx("h2",{className:"h2 mb-3 text-sm font-semibold",children:"Features"}),r.jsx("ul",{className:"feats grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:Object.keys(al).map(x=>{const C=l.features.includes(x);return r.jsxs("li",{className:"flex items-center gap-2 text-sm",children:[r.jsx("span",{className:"flex size-5 items-center justify-center rounded-full "+(C?"bg-success-soft text-success":"bg-muted text-muted-foreground"),children:C?r.jsx(hl,{className:"size-3"}):r.jsx(hk,{className:"size-3"})}),r.jsx("span",{className:C?"":"text-muted-foreground",children:al[x]}),r.jsx("span",{className:"sr-only",children:C?"on":"off"})]},x)})})]}),r.jsxs(He,{children:["Free without a license: reviews for one GitHub, GitLab and Bitbucket host each, the local executor, repository on/off, ",r.jsx("code",{children:"@bot"})," commands, review history for ",t.free_retention_days," days, the status dashboard and admin sign-in by email."]})]})]}),r.jsxs(lt,{children:[r.jsxs(cn,{children:[r.jsxs(yn,{className:"flex items-center gap-2",children:[r.jsx(bv,{className:"size-4"}),l.state==="none"?"Install a license":"Replace the license"]}),r.jsx(wn,{children:"Keys are verified offline; the console never calls home."})]}),r.jsx(Pt,{className:"grid gap-4",children:l.managed?r.jsx("p",{className:"text-sm text-muted-foreground",children:l.source==="env"?r.jsxs(r.Fragment,{children:["This license comes from ",r.jsx("code",{children:"CODEREVIEW_CONSOLE_LICENSE"}),", which overrides the one managed here. Remove the variable and restart to manage the license here."]}):r.jsxs(r.Fragment,{children:["This license comes from ",r.jsx("code",{children:"license.file"})," because the console has no database. With ",r.jsx("code",{children:"database.url"})," set, the key is copied into the database and managed here."]})}):r.jsxs(r.Fragment,{children:[r.jsx(ee,{label:"License key",children:r.jsx(an,{className:"key min-h-28 font-mono text-xs",placeholder:"DIV1.… or the -----BEGIN DIVMORA LICENSE KEY----- block",autoComplete:"off",spellCheck:!1,value:u,onChange:x=>d(x.target.value)})}),r.jsxs("div",{className:"flex flex-wrap gap-2",children:[r.jsx(re,{disabled:!u.trim(),onClick:()=>v(u.trim()),children:"Install"}),l.source==="database"&&r.jsx(re,{variant:"ghost",className:"text-destructive hover:text-destructive",onClick:w,children:"Remove license"})]}),r.jsx(He,{children:"A pasted key is stored in the database and applies at once, except the executor, which is chosen when the console starts."})]})})]}),r.jsxs(He,{children:["Every use of a paid feature needs a license from Divmora, in development, CI and production alike. For a license or a trial, contact"," ",r.jsx("a",{className:"text-primary underline-offset-4 hover:underline",href:"mailto:licensing@divmora.com",children:"licensing@divmora.com"}),"."]})]})}const dR={openai:"OPENAI_API_KEY",anthropic:"ANTHROPIC_API_KEY",gemini:"GEMINI_API_KEY",bedrock:"",azure:"AZURE_OPENAI_API_KEY",ollama:"",openrouter:"OPENROUTER_API_KEY",groq:"GROQ_API_KEY",deepseek:"DEEPSEEK_API_KEY",mistral:"MISTRAL_API_KEY",xai:"XAI_API_KEY",together:"TOGETHER_API_KEY",litellm:"LITELLM_API_KEY","openai-compatible":"OPENAI_COMPATIBLE_API_KEY"},Ig=t=>t==="azure"||t==="openai-compatible",Tn=t=>typeof t=="string"?t:t==null?"":String(t),fR=["provider","model","api_key_env","base_url","region","timeout"];function hR({profile:t,providers:o,onSaved:s,onCancel:a}){const l=et(),u=()=>{const y=(t==null?void 0:t.config)??{};return{name:(t==null?void 0:t.name)??"",provider:Tn(y.provider)||"anthropic",model:Tn(y.model),api_key_env:Tn(y.api_key_env),base_url:Tn(y.base_url),region:Tn(y.region),timeout:Tn(y.timeout)}},[d,h]=m.useState(u),[g,v]=m.useState(!1),w=y=>_=>h({...d,[y]:_.target.value}),x=async()=>{const y={...(t==null?void 0:t.config)??{}};for(const _ of fR)y[_]=d[_].trim();v(!0);try{s(await bn("/admin/api/models/"+encodeURIComponent(d.name.trim()),{config:y})),l("Saved "+d.name.trim())}catch(_){l(Ee(_),!0)}finally{v(!1)}},C=dR[d.provider];return r.jsxs("div",{className:"grid gap-4",children:[r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ee,{label:"Name",hint:r.jsx(ne,{children:"Repositories and the default refer to it by this name. Lowercase, e.g. claude or fast."}),children:r.jsx(ve,{value:d.name,onChange:w("name"),disabled:!!t,placeholder:"claude",autoFocus:!t})}),r.jsx(ee,{label:"Provider",children:r.jsx(Ne,{value:d.provider,onChange:w("provider"),children:o.map(y=>r.jsx("option",{value:y,children:y},y))})}),r.jsx(ee,{label:"Model",className:"lg:col-span-2",hint:r.jsxs(ne,{children:["The provider's model ID",d.provider==="bedrock"?" or inference profile ID":"","."]}),children:r.jsx(ve,{value:d.model,onChange:w("model"),placeholder:d.provider==="ollama"?"qwen2.5-coder:14b":""})}),C!==""&&r.jsx(ee,{label:"API key: environment variable",className:"lg:col-span-2",hint:r.jsxs(ne,{children:["The console never stores API keys. Set the key in this environment variable of the console (for example in its Kubernetes Secret) and restart it once; the console passes it to review jobs. Empty means ",C,"."]}),children:r.jsx(ve,{value:d.api_key_env,onChange:w("api_key_env"),placeholder:C,spellCheck:!1})}),r.jsx(ee,{label:Ig(d.provider)?"Base URL":"Base URL (optional)",className:"lg:col-span-2",hint:r.jsx(ne,{children:Ig(d.provider)?"Required for this provider.":"Only for a proxy or a self-hosted endpoint."}),children:r.jsx(ve,{value:d.base_url,onChange:w("base_url"),placeholder:"https://",spellCheck:!1})}),d.provider==="bedrock"&&r.jsx(ee,{label:"AWS region",hint:r.jsx(ne,{children:"Credentials come from the AWS chain (IRSA, instance role, env)."}),children:r.jsx(ve,{value:d.region,onChange:w("region"),placeholder:"us-east-1"})}),r.jsx(ee,{label:"Timeout (optional)",hint:r.jsx(ne,{children:"Per request, e.g. 2m or 10m for slow local models."}),children:r.jsx(ve,{value:d.timeout,onChange:w("timeout"),placeholder:"default"})})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx(re,{onClick:x,disabled:g||!d.name.trim()||!d.model.trim(),children:t?"Save profile":"Add profile"}),r.jsx(re,{variant:"outline",onClick:a,children:"Cancel"})]})]})}function pR({p:t}){return t.key_env?r.jsxs("span",{className:"grid gap-1",children:[r.jsx("code",{className:"text-xs",children:t.key_env}),t.key_set?r.jsx(Je,{kind:"on",children:"set"}):r.jsx(Je,{kind:"warn",children:"not set in the console"})]}):r.jsx("span",{className:"text-sm text-muted-foreground",children:"none needed"})}function mR({v:t,onSaved:o}){const s=et(),[a,l]=m.useState(t.default),[u,d]=m.useState(t.fallback),[h,g]=m.useState("");m.useEffect(()=>{l(t.default),d(t.fallback)},[t.default,t.fallback.join(",")]);const v=t.profiles.map(y=>y.name),w=v.filter(y=>y!==a&&!u.includes(y)),x=a!==t.default||u.join(",")!==t.fallback.join(","),C=async()=>{try{o(await bn("/admin/api/model-choice",{default:a,fallback:u.filter(y=>y!==a)})),s("Default model saved")}catch(y){s(Ee(y),!0)}};return r.jsxs(lt,{children:[r.jsxs(cn,{children:[r.jsx(yn,{className:"h2",children:"Default model"}),r.jsx(wn,{children:"Reviews use the default unless a repository picks another profile. When it fails, the fallbacks are tried in order."})]}),r.jsxs(Pt,{className:"grid gap-4",children:[r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ee,{label:"Default",children:r.jsxs(Ne,{value:v.includes(a)?a:"",onChange:y=>l(y.target.value),children:[r.jsx("option",{value:"",disabled:!0,children:"Choose a profile"}),v.map(y=>r.jsx("option",{value:y,children:y},y))]})}),r.jsx(ee,{label:"Fallbacks, in order",children:r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[u.map((y,_)=>r.jsxs(Tt,{variant:"secondary",className:"gap-1",children:[_+1,". ",y,r.jsx("button",{type:"button","aria-label":"Remove "+y,className:"rounded-sm hover:text-destructive",onClick:()=>d(u.filter(b=>b!==y)),children:r.jsx(Pd,{className:"size-3"})})]},y)),w.length>0&&r.jsxs(Ne,{className:"h-8 w-auto",value:h,onChange:y=>{y.target.value&&d([...u,y.target.value]),g("")},"aria-label":"Add a fallback",children:[r.jsx("option",{value:"",children:u.length?"Add another…":"Add a fallback…"}),w.map(y=>r.jsx("option",{value:y,children:y},y))]}),!u.length&&!w.length&&r.jsx("span",{className:"text-sm text-muted-foreground",children:"add another profile to use one"})]})})]}),r.jsx("div",{children:r.jsx(re,{onClick:C,disabled:!x||!v.includes(a),children:"Save default"})})]})]})}function gR(){const t=et(),o=to(),s=bi(),[a,l]=m.useState(null),[u,d]=m.useState(null),h=()=>Ke("/admin/api/models").then(l).catch(x=>t(Ee(x),!0));m.useEffect(()=>{h()},[]);const g=x=>{l(x),d(null),s()},v=async x=>{if(await o({title:"Delete "+x.name+"?",description:"Repositories can't pick it any more.",action:"Delete profile",danger:!0}))try{g(await Co("/admin/api/models/"+encodeURIComponent(x.name))),t("Deleted "+x.name)}catch(C){t(Ee(C),!0)}};if(!a)return r.jsx(qe,{children:"Loading…"});const w=u===null?"":u==="new"?"Add a model profile":"Edit "+u.name;return r.jsxs("section",{className:"grid gap-4",children:[r.jsx(lr,{children:r.jsxs(re,{onClick:()=>d("new"),children:[r.jsx(ps,{})," Add profile"]})}),r.jsx(un,{children:a.profiles.length===0?r.jsx(qe,{children:"No model profiles yet. Add one to start reviewing."}):r.jsxs(zn,{children:[r.jsx(Fn,{children:r.jsxs(ct,{children:[r.jsx(je,{className:"pl-4",children:"Profile"}),r.jsx(je,{children:"Provider and model"}),r.jsx(je,{children:"API key"}),r.jsx(je,{})]})}),r.jsx($n,{children:a.profiles.map(x=>r.jsxs(ct,{children:[r.jsxs(ke,{className:"pl-4 align-top",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[r.jsx("span",{className:"font-medium",children:x.name}),x.name===a.default&&r.jsx(Tt,{children:"default"}),a.fallback.includes(x.name)&&r.jsxs(Tt,{variant:"secondary",children:["fallback ",a.fallback.indexOf(x.name)+1]})]}),r.jsxs(ne,{children:["by ",x.updated_by||"—"]})]}),r.jsxs(ke,{className:"align-top whitespace-normal",children:[r.jsxs("code",{className:"text-xs",children:[Tn(x.config.provider),":",Tn(x.config.model)]}),!!x.config.base_url&&r.jsx(ne,{children:Tn(x.config.base_url)}),!!x.config.region&&r.jsx(ne,{children:Tn(x.config.region)})]}),r.jsx(ke,{className:"align-top",children:r.jsx(pR,{p:x})}),r.jsx(ke,{className:"pr-4 text-right align-top",children:r.jsxs("div",{className:"flex justify-end gap-2",children:[r.jsx(re,{size:"sm",variant:"outline",onClick:()=>d(x),children:"Edit"}),r.jsx(re,{size:"sm",variant:"ghost",className:"text-destructive",onClick:()=>v(x),children:"Delete"})]})})]},x.name))})]})}),a.profiles.length>0&&r.jsx(mR,{v:a,onSaved:g}),r.jsx(He,{children:"API keys are never stored in the console: each profile names an environment variable of the console that holds its key, and the console hands that key to each review job."}),r.jsx(ko,{open:u!==null,onClose:()=>d(null),title:w,description:"A provider, a model and where its API key comes from.",children:u!==null&&r.jsx(hR,{profile:u==="new"?null:u,providers:a.providers,onSaved:g,onCancel:()=>d(null)},u==="new"?"new":u.name)})]})}const Vu=t=>Object.entries(t??{}).map(([o,s])=>o+"="+s).join(` +`)}function Ag(t){return location.origin+"/dashboard?token="+encodeURIComponent(t)}const J2=1440*60*1e3;function Z2({v:t,clearing:o,replacing:s}){if(o)return r.jsx(ne,{children:"The token is removed when you save."});if(s)return r.jsx(ne,{children:"The new token replaces the current one when you save; the old link stops working."});if(!t.dashboard_token_set)return r.jsx(ne,{children:"No token."});if(t.dashboard_token_expired)return r.jsx(Je,{kind:"warn",children:"Expired: generate a new token"});if(!t.dashboard_token_expires)return r.jsx(Je,{kind:"on",children:"Set, never expires"});const a=new Date(t.dashboard_token_expires),l=di(a);return a.getTime()-Date.now()<7*J2?r.jsxs(Je,{kind:"warn",children:["Expires soon: ",l]}):r.jsxs(Je,{kind:"on",children:["Set, expires ",l]})}function Lg(){const t=new Uint8Array(16);return crypto.getRandomValues(t),Array.from(t,o=>o.toString(16).padStart(2,"0")).join("")}function eR(){const t=et(),o=no(),[s,a]=m.useState(null),[l,u]=m.useState(""),[d,h]=m.useState(""),[g,v]=m.useState(""),[w,x]=m.useState(!1),[C,y]=m.useState(90),[_,b]=m.useState(!1),[j,S]=m.useState(""),[R,N]=m.useState(!1),[E,P]=m.useState(!1),I=z=>{const Z={...z,extra_env:z.extra_env??[],engine:z.engine??{},env_set:z.env_set??{}};a(Z),u(Z.extra_env.join(", ")),h(Z.engine.defaults?JSON.stringify(Z.engine.defaults,null,2):""),v(""),x(!1),b(!1),S(""),N(!1),P(!1)};if(m.useEffect(()=>{Ke("/admin/api/tuning").then(I).catch(z=>t(Ee(z),!0))},[]),!s)return r.jsx(qe,{children:"Loading…"});const F=z=>Z=>a({...s,[z]:Z}),A=z=>Z=>a({...s,engine:{...s.engine,[z]:Z}}),q=async()=>{let z;if(d.trim())try{z=JSON.parse(d)}catch{t("Repository defaults: not valid JSON",!0);return}const Z={...s,engine:{...s.engine,defaults:z},extra_env:l.split(/[\s,]+/).map(se=>se.trim()).filter(Boolean),dashboard_token:g,clear_dashboard_token:w,dashboard_token_valid_days:C,metrics_token:j,clear_metrics_token:R};try{I(await bn("/admin/api/tuning",Z)),t("Settings saved")}catch(se){t(Ee(se),!0)}},B=s.engine.verify===void 0||s.engine.verify===null?"":String(s.engine.verify);return r.jsxs("section",{className:"grid gap-4",children:[r.jsx(li,{title:"Queue",description:"How many reviews run at once and how long they may take. Changes apply at once; running reviews finish with their old timeout.",children:r.jsxs(Ge,{className:"lg:grid-cols-3",children:[r.jsx(Xn,{label:"Reviews at once",min:1,max:64,value:s.workers,onChange:F("workers"),hint:r.jsx(ne,{children:"Each one is a container or pod with the Executor page's resources."})}),r.jsx(Xn,{label:"Waiting reviews (queue size)",min:1,max:1e4,value:s.queue_size,onChange:F("queue_size"),hint:r.jsx(ne,{children:"More webhooks get HTTP 503 and the code host retries."})}),r.jsx(ee,{label:"Review timeout",hint:r.jsx(ne,{children:"Between 1m and 6h."}),children:r.jsx(ve,{value:s.job_timeout,placeholder:"20m",onChange:z=>F("job_timeout")(z.target.value)})}),r.jsx(ee,{label:"Wait after a push",hint:r.jsx(ne,{children:"Pushes within this time become one review. 0s reviews at once."}),children:r.jsx(ve,{value:s.debounce,placeholder:"30s",onChange:z=>F("debounce")(z.target.value)})}),r.jsx(Xn,{label:"Jobs on the dashboard",min:10,max:5e3,value:s.history,onChange:F("history")})]})}),r.jsx(li,{title:"Review engine",description:"The codereview CLI's review settings. Leave a field empty for the CLI's default.",children:r.jsxs(Ge,{className:"lg:grid-cols-3",children:[r.jsx(Xn,{label:"Model calls at once, per review",placeholder:"4",min:0,max:32,value:s.engine.concurrency,onChange:A("concurrency")}),r.jsx(Xn,{label:"Tokens per model call",placeholder:"40000",min:0,value:s.engine.batch_tokens,onChange:A("batch_tokens")}),r.jsx(Xn,{label:"Skip reviews with more files than",placeholder:"150",min:0,value:s.engine.max_files,onChange:A("max_files")}),r.jsx(Xn,{label:"Send whole files up to (lines)",placeholder:"800",min:0,value:s.engine.full_file_max_lines,onChange:A("full_file_max_lines")}),r.jsx(Xn,{label:"Context lines around changes",placeholder:"60",min:0,value:s.engine.context_lines,onChange:A("context_lines")}),r.jsx(Xn,{label:"Review passes",placeholder:"1",min:0,max:3,value:s.engine.passes,onChange:A("passes"),hint:r.jsx(ne,{children:"2 or 3 catch more, for one more model call each."})}),r.jsx(ee,{label:"Verification pass",children:r.jsxs(Ne,{value:B,onChange:z=>A("verify")(z.target.value===""?null:z.target.value==="true"),children:[r.jsx("option",{value:"",children:"CLI default (on)"}),r.jsx("option",{value:"true",children:"On"}),r.jsx("option",{value:"false",children:"Off"})]})}),r.jsx(ee,{label:"Verification model",children:r.jsxs(Ne,{value:s.engine.verify_model||"",onChange:z=>A("verify_model")(z.target.value),children:[r.jsx("option",{value:"",children:"The review model"}),s.engine.verify_model&&!o.profiles.includes(s.engine.verify_model)&&r.jsx("option",{value:s.engine.verify_model,children:s.engine.verify_model}),o.profiles.map(z=>r.jsx("option",{value:z,children:z},z))]})}),r.jsx(ee,{label:"The verifier may drop",children:r.jsxs(Ne,{value:s.engine.verify_can_drop||"",onChange:z=>A("verify_can_drop")(z.target.value),children:[r.jsx("option",{value:"",children:"CLI default (confident)"}),r.jsx("option",{value:"confident",children:"Minor findings, and major ones it is sure are wrong"}),r.jsx("option",{value:"minor",children:"Only minor and nitpick findings"}),r.jsx("option",{value:"all",children:"Anything it disputes"})]})}),r.jsx(ee,{label:"The verifier may add findings",children:r.jsxs(Ne,{value:String(!!s.engine.verify_can_add),onChange:z=>A("verify_can_add")(z.target.value==="true"),children:[r.jsx("option",{value:"false",children:"No"}),r.jsx("option",{value:"true",children:"Yes"})]})}),r.jsx(ee,{label:"Repository config file",children:r.jsx(ve,{placeholder:".codereview.yaml",value:s.engine.repo_config_file||"",onChange:z=>A("repo_config_file")(z.target.value)})}),r.jsx(ee,{label:"Repositories may pick a model",children:r.jsxs(Ne,{value:String(s.allow_repo_model),onChange:z=>F("allow_repo_model")(z.target.value==="true"),children:[r.jsx("option",{value:"false",children:"No"}),r.jsx("option",{value:"true",children:"Yes, with model: in their config file"})]})}),r.jsx(ee,{label:"Repository defaults (JSON)",className:"lg:col-span-3",hint:r.jsx(ne,{children:"Keys of a repository config file (language, path_filters, path_instructions, guidelines, high_level_summary…), applied under each repository's own file. The profile, comment limit and severity are under Default review settings."}),children:r.jsx(an,{rows:4,spellCheck:!1,className:"font-mono text-xs",placeholder:'{"language": "English", "path_filters": ["!**/*.lock"]}',value:d,onChange:z=>h(z.target.value)})})]})}),r.jsx(li,{title:"Bot and review jobs",children:r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ee,{label:"Default bot name",hint:r.jsx(ne,{children:"The mention handle (@name review) for hosts that set none. Empty: each host's token user."}),children:r.jsx(ve,{placeholder:"codereview",value:s.bot_name||"",onChange:z=>F("bot_name")(z.target.value)})}),r.jsx(ee,{label:"Extra environment variables for reviews",hint:r.jsxs("span",{className:"grid gap-1",children:[r.jsx(ne,{children:"Names of the console's variables to pass to every review (model key variables are passed already). The console's own secrets can't be passed."}),s.extra_env.length>0&&r.jsx("span",{className:"flex flex-wrap gap-1.5",children:s.extra_env.map(z=>r.jsxs(Je,{kind:s.env_set[z]?"on":"warn",children:[z,s.env_set[z]?"":": not set"]},z))})]}),children:r.jsx(ve,{placeholder:"MY_PROXY_CA, SSL_CERT_DIR",value:l,onChange:z=>u(z.target.value)})})]})}),r.jsx(li,{title:"Status dashboard access",description:"The status dashboard shows every running and recent review, with repository names unless they are hidden under Status dashboard above.",children:r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ee,{label:"Who can open it",hint:r.jsx(ne,{children:X2(s.dashboard_access,s.dashboard_token_set||!!g,w)}),children:r.jsxs(Ne,{value:s.dashboard_access,onChange:z=>F("dashboard_access")(z.target.value),children:[r.jsx("option",{value:"admins",children:"Signed-in admins only"}),r.jsx("option",{value:"token",children:"Admins, and anyone with the token"}),r.jsx("option",{value:"public",children:"Anyone who can reach the console"})]})}),r.jsx(ee,{label:"Dashboard token",hint:r.jsx(ne,{children:"For screens and people without an admin sign-in: /dashboard?token=… or a Bearer header. Stored hashed and never shown again."}),children:r.jsxs("div",{className:"grid gap-2",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx(ve,{className:"max-w-sm font-mono",placeholder:s.dashboard_token_set?"Set (leave empty to keep it)":"Not set",value:g,onChange:z=>{v(z.target.value),x(!1),b(!1)}}),r.jsx(re,{variant:"outline",onClick:()=>{v(Lg()),x(!1),b(!1)},children:"Generate"}),s.dashboard_token_set&&r.jsx(re,{variant:"ghost",className:"text-destructive",onClick:()=>{v(""),x(!0)},disabled:w,children:w?"Removed on save":"Remove"})]}),r.jsx(Z2,{v:s,clearing:w,replacing:!!g})]})}),g&&r.jsxs(r.Fragment,{children:[r.jsx(ee,{label:"New token valid for",hint:r.jsx(ne,{children:"Counted from when you save. After that the link stops working until a new token is generated."}),children:r.jsxs(Ne,{value:String(C),onChange:z=>y(parseInt(z.target.value,10)),children:[r.jsx("option",{value:"7",children:"7 days"}),r.jsx("option",{value:"30",children:"30 days"}),r.jsx("option",{value:"90",children:"90 days"}),r.jsx("option",{value:"365",children:"1 year"}),r.jsx("option",{value:"0",children:"Never expires"})]})}),r.jsx(ee,{label:"Link to share",hint:r.jsx(ne,{className:"text-warning",children:"Copy it now: once saved, the token can't be shown again."}),children:r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx(ve,{readOnly:!0,className:"font-mono text-xs",value:Ag(g),onFocus:z=>z.target.select()}),r.jsx(re,{variant:"outline",onClick:()=>{var z;(z=navigator.clipboard)==null||z.writeText(Ag(g)).then(()=>b(!0),()=>t("Copy failed: select the link and copy it",!0))},children:_?"Copied":"Copy link"})]})})]})]})}),r.jsx(li,{title:"Prometheus metrics",description:"/metrics in the Prometheus text format: queue, reviews by kind and result, durations, tokens, webhooks by outcome, and when the license and host tokens expire. No repository names.",children:r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ee,{label:"Who can read /metrics",hint:r.jsx(ne,{children:s.metrics_access==="public"?"Anyone who can reach the console's URL. Fine on a private network the scraper shares.":s.metrics_access==="token"?"Scrapers send the token as a bearer token.":"Off: /metrics answers 404."}),children:r.jsxs(Ne,{value:s.metrics_access,onChange:z=>F("metrics_access")(z.target.value),children:[r.jsx("option",{value:"off",children:"Off"}),r.jsx("option",{value:"token",children:"Scrapers with the token"}),r.jsx("option",{value:"public",children:"Anyone who can reach the console"})]})}),r.jsx(ee,{label:"Metrics token",hint:r.jsx(ne,{children:R?"Removed when you save.":j?"Replaces the current token when you save.":s.metrics_token_set?"Set. Stored hashed and never shown again.":"No token."}),children:r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx(ve,{className:"max-w-sm font-mono",placeholder:s.metrics_token_set?"Set (leave empty to keep it)":"Not set",value:j,onChange:z=>{S(z.target.value),N(!1),P(!1)}}),r.jsx(re,{variant:"outline",onClick:()=>{S(Lg()),N(!1),P(!1)},children:"Generate"}),s.metrics_token_set&&r.jsx(re,{variant:"ghost",className:"text-destructive",onClick:()=>{S(""),N(!0)},disabled:R,children:R?"Removed on save":"Remove"})]})}),s.metrics_access!=="off"&&r.jsx(ee,{label:"Prometheus scrape config",className:"lg:col-span-2",hint:j?r.jsx(ne,{className:"text-warning",children:"Copy it now: once saved, the token can't be shown again."}):r.jsx(ne,{children:"Generate a token to fill it in."}),children:r.jsxs("div",{className:"grid gap-2",children:[r.jsx(an,{readOnly:!0,rows:s.metrics_access==="token"?7:5,className:"font-mono text-xs",value:Mg(s.metrics_access,j),onFocus:z=>z.target.select()}),r.jsx("div",{children:r.jsx(re,{variant:"outline",size:"sm",onClick:()=>{var z;(z=navigator.clipboard)==null||z.writeText(Mg(s.metrics_access,j)).then(()=>P(!0),()=>t("Copy failed: select the text and copy it",!0))},children:E?"Copied":"Copy"})})]})})]})}),r.jsx(lt,{className:"py-4",children:r.jsxs(dw,{className:"flex flex-wrap items-center gap-3",children:[r.jsx(re,{onClick:q,children:"Save queue and review settings"}),r.jsx(He,{children:"Applies to the next review, without a restart."})]})})]})}const Wu=t=>qr(t),tR={allowlist:"Repositories no rule matches",require_reviewer:"Who asks for a review",skip_branch_sync:"Branch syncs",sync_source_branches:"Also treat these source branches as syncs",score_labels:"Score labels",commit_status:"Commit status",approve:"Approve merge requests",approve_block:"Findings that block approval",approve_min_score:"Lowest score to approve",approve_withdraw:"When a later review doesn't pass",command_access:"Who can run review and question commands",learnings_enabled:"Learn from replies to the bot",learnings_auto_activate:"New learnings",daily_token_budget:"Daily tokens, all repositories",repo_daily_token_budget:"Daily tokens, per repository",review_retention_days:"Keep reviews",webhook_retention_days:"Keep webhook deliveries",dashboard_enabled:"Dashboard",hide_repos:"Repository names",dashboard_title:"Dashboard title",session_idle_minutes:"Sign out after inactivity"};function nR(){const t=et(),o=to(),[s,a]=m.useState(null);m.useEffect(()=>{Ke("/admin/api/sessions").then(a).catch(h=>t(Ee(h),!0))},[]);const l=async h=>{if(h.current){if(!await o({title:"Sign yourself out?",description:"This is the session you are using now.",action:"Sign out"}))return;Qt("/admin/logout").finally(()=>location.href="/admin/login");return}if(await o({title:"Sign out "+(h.name||h.email)+"?",description:"They can sign in again if the sign-in rules still allow them.",action:"Sign out",danger:!0}))try{a(await Co("/admin/api/sessions/"+h.id)),t("Signed out "+h.email)}catch(g){t(Ee(g),!0)}},u=async()=>{if(await o({title:"Sign out everyone else?",description:"Every other admin session ends now. Use it after removing someone from the sign-in rules or if a session may be compromised.",action:"Sign out others",danger:!0}))try{a(await Qt("/admin/api/sessions/end-others")),t("Signed out every other session")}catch(h){t(Ee(h),!0)}},d=s?s.filter(h=>!h.current).length:0;return r.jsxs(lt,{className:"gap-0 overflow-hidden pb-0",children:[r.jsxs(cn,{className:"pb-4",children:[r.jsx(yn,{className:"h2",children:"Signed-in admins"}),r.jsx(wn,{children:"Every request is checked against the current sign-in rules, so someone removed from them is signed out at once. Group changes at the identity provider apply when the session ends (session_ttl) or here."}),d>0&&r.jsx("div",{children:r.jsx(re,{variant:"outline",size:"sm",onClick:u,children:"Sign out everyone else"})})]}),s?r.jsxs(zn,{children:[r.jsx(Fn,{children:r.jsxs(ct,{children:[r.jsx(je,{className:"pl-6",children:"Admin"}),r.jsx(je,{children:"From"}),r.jsx(je,{children:"Signed in"}),r.jsx(je,{children:"Last active"}),r.jsx(je,{children:"Expires"}),r.jsx(je,{})]})}),r.jsx($n,{children:s.map(h=>r.jsxs(ct,{children:[r.jsxs(ke,{className:"pl-6",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[r.jsx("span",{className:"font-medium",children:h.name||h.email}),h.current&&r.jsx(Tt,{variant:"secondary",children:"you, this browser"})]}),h.name&&r.jsx(ne,{children:h.email})]}),r.jsxs(ke,{children:[r.jsx("div",{className:"font-mono text-xs",children:h.ip||"—"}),h.user_agent&&r.jsx(ne,{title:h.user_agent,children:jw(h.user_agent)})]}),r.jsx(ke,{children:Wu(h.created)}),r.jsx(ke,{children:h.last_seen?Wu(h.last_seen):"—"}),r.jsx(ke,{children:Wu(h.expires)}),r.jsx(ke,{className:"pr-6 text-right",children:r.jsx(re,{size:"sm",variant:"ghost",className:h.current?"":"text-destructive",onClick:()=>l(h),children:"Sign out"})})]},h.id))})]}):r.jsx(qe,{children:"Loading…"})]})}function xn({label:t,value:o,onChange:s,yes:a,no:l,disabled:u,note:d}){return r.jsx(ee,{label:t,hint:d,children:r.jsxs(Ne,{value:String(o),disabled:u,onChange:h=>s(h.target.value==="true"),children:[r.jsx("option",{value:"true",children:a}),r.jsx("option",{value:"false",children:l})]})})}function ns({label:t,value:o,onChange:s,note:a,...l}){return r.jsx(ee,{label:t,hint:a,children:r.jsx(ve,{type:"number",value:o||"",...l,onChange:u=>s(parseInt(u.target.value||"0",10))})})}function Fr({title:t,description:o,children:s}){return r.jsxs(lt,{children:[r.jsxs(cn,{children:[r.jsx(yn,{className:"h2",children:t}),o&&r.jsx(wn,{children:o})]}),r.jsx(Pt,{children:s})]})}function rR(){const t=et(),o=bi(),s=no(),a={learnings:qt("learnings"),budgets:qt("budgets"),sync:qt("branch_sync"),metrics:qt("metrics")},[l,u]=m.useState(null),[d,h]=m.useState(null),[g,v]=m.useState(""),[w,x]=m.useState(0),C=j=>{u(j),h(j),v((j.sync_source_branches||[]).join(", "))};if(m.useEffect(()=>{Ke("/admin/api/settings").then(C).catch(j=>t(Ee(j),!0))},[]),!l||!d)return r.jsx(qe,{children:"Loading…"});const y=j=>S=>h({...d,[j]:S}),_=j=>{const{source:S,...R}={...d,review_defaults:j,dashboard_title:d.dashboard_title.trim(),sync_source_branches:g.split(",").map(N=>N.trim()).filter(Boolean)};bn("/admin/api/settings",R).then(N=>{C(N),x(E=>E+1),o(),t("Settings saved")}).catch(N=>t(Ee(N),!0))},b=Object.keys(l.source||{}).filter(j=>l.source[j]==="config").map(j=>tR[j]||j.replace(/_/g," "));return r.jsxs("section",{className:"grid gap-4",children:[r.jsx(Fr,{title:"Repository access",description:"Which repositories are reviewed, and when.",children:r.jsxs(Ge,{children:[r.jsx(xn,{label:"Repositories no rule matches",value:d.allowlist,onChange:y("allowlist"),yes:"Not reviewed (allowlist on)",no:"Reviewed (allowlist off)"}),r.jsx(xn,{label:"Who asks for a review",value:d.require_reviewer,onChange:y("require_reviewer"),yes:"Only when the bot is a reviewer",no:"Any opened MR or push"}),r.jsx(xn,{label:"Branch syncs (source is the default branch)",value:d.skip_branch_sync,onChange:y("skip_branch_sync"),yes:"Skip",no:"Review",disabled:!a.sync,note:r.jsx(Qa,{feature:"branch_sync"})}),r.jsx(ee,{label:"Also treat these source branches as syncs",children:r.jsx(ve,{placeholder:"develop, release/*",value:g,disabled:!a.sync,onChange:j=>v(j.target.value)})}),r.jsx(xn,{label:"Score labels on MRs/PRs",value:d.score_labels,onChange:y("score_labels"),yes:"On",no:"Off"}),r.jsx(xn,{label:"Commit status on the reviewed commit",value:d.commit_status,onChange:y("commit_status"),yes:"On",no:"Off"}),r.jsx(ee,{label:"Who can run review and question commands",hint:r.jsx(He,{className:"text-xs",children:"Commands that run the model spend tokens. Write access means GitLab Developer or higher, GitHub write or above, Bitbucket write or admin (the Bitbucket token needs admin on the repository to check). @bot help works for everyone, and each person is limited to a few commands an hour."}),children:r.jsxs(Ne,{value:d.command_access||"write",onChange:j=>y("command_access")(j.target.value),children:[r.jsx("option",{value:"write",children:"People who can push to the repository"}),r.jsx("option",{value:"anyone",children:"Anyone who can comment"})]})})]})}),r.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[r.jsxs(Fr,{title:"Approve merge requests",description:"The bot approves a merge request whose review passes, as its token's user (or the GitHub App). Rules can turn this on or off for groups and repositories. Needs code-review-bot 0.5 or later on the Executor page.",children:[r.jsxs(Ge,{children:[r.jsx(xn,{label:"Approve when the review passes",value:d.approve,onChange:y("approve"),yes:"On",no:"Off"}),r.jsx(ee,{label:"Findings that block approval",hint:r.jsx(He,{className:"text-xs",children:"New findings, ones beyond the comment limit and ones still open from an earlier review all count; questions don't."}),children:r.jsxs(Ne,{value:d.approve_block||"major",onChange:j=>y("approve_block")(j.target.value),children:[r.jsx("option",{value:"critical",children:"Critical"}),r.jsx("option",{value:"major",children:"Major or critical"}),r.jsx("option",{value:"minor",children:"Minor or above"}),r.jsx("option",{value:"nitpick",children:"Any finding (nitpicks too)"}),r.jsx("option",{value:"none",children:"None: approve whatever it found"})]})}),r.jsx(ns,{label:"Lowest score to approve",value:d.approve_min_score,onChange:y("approve_min_score"),min:0,max:100,placeholder:"0",note:r.jsx(He,{className:"text-xs",children:"Every score (quality, security, maintainability) must be at least this. 0 ignores the scores."})}),r.jsx(xn,{label:"When a later review doesn't pass",value:d.approve_withdraw,onChange:y("approve_withdraw"),yes:"Withdraw the bot's approval",no:"Leave it"})]}),r.jsx(He,{className:"text-xs",children:"With withdrawing on, a review that can't judge a new commit (partial, too large) also withdraws the approval (CLI 0.6 or later). GitLab: the bot's user must be allowed to approve. GitHub: withdrawing dismisses the bot's review, which branch protection may restrict."})]}),r.jsx(Fr,{title:"Learnings",children:r.jsxs(Ge,{children:[r.jsx(xn,{label:"Learn from replies to the bot",value:d.learnings_enabled,onChange:y("learnings_enabled"),yes:"On",no:"Off",disabled:!a.learnings,note:r.jsx(Qa,{feature:"learnings"})}),r.jsx(xn,{label:"New learnings",value:d.learnings_auto_activate,onChange:y("learnings_auto_activate"),yes:"Apply at once",no:"Wait for an admin's approval",disabled:!a.learnings,note:r.jsx(He,{className:"text-xs",children:"Even when set to apply at once, a learning only applies right away if its author can push to the repository (GitLab Developer or higher, GitHub write or above). Anyone else's waits for approval, and so does every learning from Bitbucket."})})]})}),r.jsxs(Fr,{title:"Budgets",description:'Input plus output tokens of finished jobs in the current UTC day. When a budget is used up, automatic reviews and chat commands wait until the next day; "Review now" and re-runs from this panel still run.',children:[r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ns,{label:"Daily tokens, all repositories",min:0,step:1e4,placeholder:"0 = no limit",value:d.daily_token_budget,onChange:y("daily_token_budget"),disabled:!a.budgets,note:r.jsx(Qa,{feature:"budgets"})}),r.jsx(ns,{label:"Daily tokens per repository",min:0,step:1e4,placeholder:"0 = no limit",value:d.repo_daily_token_budget,onChange:y("repo_daily_token_budget"),disabled:!a.budgets})]}),a.budgets&&!d.daily_token_budget&&!d.repo_daily_token_budget&&r.jsx(He,{className:"text-warning",children:"No daily limit is set: reviews and commands spend tokens without a cap. Set a budget to bound what a busy day, or misuse, can cost."})]}),r.jsx(Fr,{title:"History",children:r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ns,{label:"Keep reviews (days)",min:1,max:3650,value:d.review_retention_days,onChange:y("review_retention_days"),note:!a.metrics&&d.review_retention_days>s.free_retention_days?r.jsxs("span",{className:"locknote text-xs text-warning",children:["Without a license with metrics and long history, reviews are kept ",s.free_retention_days," days."]}):null}),r.jsx(ns,{label:"Keep webhook deliveries (days)",min:1,max:3650,value:d.webhook_retention_days,onChange:y("webhook_retention_days")})]})}),r.jsx(Fr,{title:"Admin sessions",description:"Every admin session also ends after session_ttl (12 hours by default), whatever happens.",children:r.jsx(Ge,{children:r.jsx(ns,{label:"Sign out after inactivity (minutes)",min:0,max:1440,placeholder:"0 = never",value:d.session_idle_minutes,onChange:y("session_idle_minutes"),note:r.jsx(He,{className:"text-xs",children:"A session that makes no request for this long is signed out, so a browser left open on a shared machine doesn't keep admin rights. The panel's own refreshes (Setup, the dashboard) don't count as activity. 5 to 1440, or 0 for never."})})})}),r.jsx(Fr,{title:"Status dashboard",description:"Who can open it is set under Status dashboard access, further down.",children:r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(xn,{label:"Dashboard",value:d.dashboard_enabled,onChange:y("dashboard_enabled"),yes:"On",no:"Off"}),r.jsx(xn,{label:"Repository names",value:!d.hide_repos,onChange:j=>y("hide_repos")(!j),yes:"Shown",no:"Hidden"}),r.jsx(ee,{label:"Title",className:"sm:col-span-2",children:r.jsx(ve,{maxLength:120,value:d.dashboard_title,onChange:j=>y("dashboard_title")(j.target.value)})})]})})]}),r.jsx(lt,{className:"py-4",children:r.jsxs(dw,{className:"flex flex-wrap items-center gap-3",children:[r.jsx(re,{onClick:()=>_(l.review_defaults),children:"Save settings"}),r.jsx("span",{className:"text-sm text-muted-foreground",children:b.length?"Showing defaults for: "+b.join("; ")+". Save to keep them.":""})]})}),r.jsx(Fr,{title:"Default review settings",description:"Apply to every repository. Group and pattern rules, then repository settings, override them.",children:r.jsx(kf,{value:l.review_defaults,onSave:_,saveLabel:"Save default review settings"},w)}),r.jsx(jd,{name:"Queue, review engine and access settings",children:r.jsx(eR,{})}),r.jsx(jd,{name:"Sign-in sessions",children:r.jsx(nR,{})}),r.jsx(He,{children:"These settings are kept in the database and apply without a restart. Every change is in the audit log."})]})}const Wa={actor:"",action:"",target:"",q:"",from:"",to:""},oR=["login","login.denied","logout","session.*","session.ended","session.revoke","setting.put","host.*","host.put","host.delete","webhook.*","webhook.put","webhook.delete","repo.*","rule.*","learning.*","model.*","audit.export"];function $r(t,o){const s=new URLSearchParams;for(const[a,l]of Object.entries(t))l.trim()&&s.set(a,l.trim());return o&&s.set("before",String(o)),s.toString()}function Xa(t,o="",s={}){if(t&&typeof t=="object"&&!Array.isArray(t)){for(const[a,l]of Object.entries(t))Xa(l,o?o+"."+a:a,s);!Object.keys(t).length&&o&&(s[o]="{}")}else o&&(s[o]=t===void 0?"":typeof t=="string"?t:JSON.stringify(t));return s}const sR=t=>{const[o,s]=t.split(":");return o.replace(/_/g," ")+" "+(s||"changed")};function Pw({detail:t}){const[o,s]=m.useState(!1),a=t&&typeof t=="object"?t:{},l="before"in a||"after"in a,u=Array.isArray(a.secrets_changed)?a.secrets_changed:[];let d=[],h="";if(l){const g=Xa(a.before),v=Xa(a.after);a.before==null&&"after"in a&&(h="created"),"after"in a||(h="deleted");for(const w of Array.from(new Set([...Object.keys(g),...Object.keys(v)])).sort())g[w]!==v[w]&&d.push({key:w,old:a.before==null?void 0:g[w],now:"after"in a?v[w]:void 0})}else d=Object.entries(Xa(t)).map(([g,v])=>({key:g,now:v}));return r.jsxs("div",{className:"grid gap-1 text-xs",children:[h&&r.jsx("span",{className:"text-muted-foreground",children:h}),d.length===0&&!u.length&&!h&&r.jsx("span",{className:"text-muted-foreground",children:l?"no visible change":"—"}),d.slice(0,20).map(g=>r.jsxs("div",{className:"break-all",children:[r.jsx("span",{className:"font-medium",children:g.key}),": ",g.old!==void 0&&r.jsx("span",{className:"text-destructive line-through",children:g.old||"∅"}),g.old!==void 0&&g.now!==void 0&&" → ",g.now!==void 0&&r.jsx("span",{className:l?"text-success":"",children:g.now||"∅"})]},g.key)),d.length>20&&r.jsxs("span",{className:"text-muted-foreground",children:["and ",d.length-20," more (see raw)"]}),u.length>0&&r.jsx("div",{className:"flex flex-wrap gap-1",children:u.map(g=>r.jsx(Tt,{variant:"outline",className:"font-normal",children:sR(g)},g))}),r.jsx("div",{children:r.jsx("button",{type:"button",className:"text-muted-foreground underline-offset-2 hover:underline",onClick:()=>s(!o),children:o?"Hide raw":"Raw"})}),o&&r.jsx("pre",{className:"max-h-60 overflow-auto rounded-md bg-muted p-2 font-mono whitespace-pre-wrap break-all",children:JSON.stringify(t,null,2)})]})}function iR(){const t=et(),o=qt("audit"),[s,a]=Of(Wa),[l,u]=m.useState(s),[d,h]=m.useState(null),[g,v]=m.useState(0),[w,x]=m.useState(!1),C=(S,R)=>{x(!0),Ke("/admin/api/audit?"+$r(S,R)).then(N=>{h(E=>R&&E?[...E,...N.entries]:N.entries),v(N.next)}).catch(N=>t(Ee(N),!0)).finally(()=>x(!1))};if(m.useEffect(()=>{o&&(u(s),C(s))},[o,$r(s)]),!o)return r.jsx("section",{children:r.jsx(ji,{feature:"audit",children:"Every admin change is still recorded; viewing the audit log is part of the licensed console."})});const y=S=>R=>u({...l,[S]:R.target.value}),_=S=>{S==null||S.preventDefault();const R=Object.fromEntries(Object.entries(l).map(([N,E])=>[N,E.trim()]));$r(R)===$r(s)?C(R):a(R)},b=()=>{u(Wa),$r(s)?a(Wa):C(Wa)},j=S=>"/admin/api/audit/export?"+$r(s)+($r(s)?"&":"")+"format="+S;return r.jsxs("section",{className:"grid gap-4",children:[r.jsx(un,{children:r.jsxs("form",{onSubmit:_,className:"grid gap-3 p-4 sm:grid-cols-2 lg:grid-cols-6",children:[r.jsx(ee,{label:"Who",children:r.jsx(ve,{placeholder:"email",value:l.actor,onChange:y("actor")})}),r.jsxs(ee,{label:"Action",children:[r.jsx(ve,{list:"audit-actions",placeholder:"host.* or login.denied",value:l.action,onChange:y("action")}),r.jsx("datalist",{id:"audit-actions",children:oR.map(S=>r.jsx("option",{value:S},S))})]}),r.jsx(ee,{label:"Target",children:r.jsx(ve,{placeholder:"gitlab:group/project",value:l.target,onChange:y("target")})}),r.jsx(ee,{label:"Search",children:r.jsx(ve,{placeholder:"in targets and details",value:l.q,onChange:y("q")})}),r.jsx(ee,{label:"From",children:r.jsx(ve,{type:"date",value:l.from,onChange:y("from")})}),r.jsx(ee,{label:"To",children:r.jsx(ve,{type:"date",value:l.to,onChange:y("to")})}),r.jsxs("div",{className:"flex flex-wrap items-center gap-2 lg:col-span-6",children:[r.jsx(re,{type:"submit",children:"Apply"}),r.jsx(re,{type:"button",variant:"ghost",onClick:b,children:"Clear"}),r.jsx("span",{className:"flex-1"}),r.jsx(re,{asChild:!0,variant:"outline",size:"sm",children:r.jsx("a",{href:j("csv"),children:"Export CSV"})}),r.jsx(re,{asChild:!0,variant:"outline",size:"sm",children:r.jsx("a",{href:j("jsonl"),children:"Export JSON Lines"})})]})]})}),r.jsxs(un,{children:[d?d.length?r.jsxs(zn,{children:[r.jsx(Fn,{children:r.jsxs(ct,{children:[r.jsx(je,{className:"pl-4",children:"When"}),r.jsx(je,{children:"Who"}),r.jsx(je,{children:"Action"}),r.jsx(je,{children:"Target"}),r.jsx(je,{className:"pr-4",children:"Changes"})]})}),r.jsx($n,{children:d.map(S=>r.jsxs(ct,{children:[r.jsx(ke,{className:"pl-4 align-top whitespace-nowrap text-muted-foreground",title:ml(S.at),children:qr(S.at,!0)}),r.jsxs(ke,{className:"align-top",children:[S.actor,S.ip&&r.jsxs(ne,{title:S.user_agent,children:[S.ip,S.user_agent?" · "+jw(S.user_agent):""]})]}),r.jsx(ke,{className:"align-top",children:r.jsx("code",{children:S.action})}),r.jsx(ke,{className:"max-w-56 align-top break-all whitespace-normal",children:S.target}),r.jsx(ke,{className:"max-w-xl min-w-64 pr-4 align-top whitespace-normal",children:r.jsx(Pw,{detail:S.detail})})]},S.id))})]}):r.jsx(qe,{children:$r(s)?"Nothing matches these filters.":"No admin activity yet."}):r.jsx(qe,{children:"Loading…"}),g>0&&r.jsx("div",{className:"flex justify-center p-3",children:r.jsx(re,{variant:"outline",disabled:w,onClick:()=>C(s,g),children:w?"Loading…":"Older entries"})})]})]})}const aR=t=>t==="applied"?"on":t==="pending"?"warn":t==="failed"?"off":"idle";function lR(){const t=et(),o=no(),s=bi(),[a,l]=m.useState("pending"),[u,d]=m.useState(null),[h,g]=m.useState({}),[v,w]=m.useState(null),x=o.role==="admin",C=(b=a)=>Ke("/admin/api/approvals"+(b==="all"?"":"?status="+b)).then(d).catch(j=>t(Ee(j),!0));m.useEffect(()=>{C()},[a]);const y=async(b,j)=>{var S,R;try{const N=await Qt(`/admin/api/approvals/${b.id}/${j}`,j==="reject"?{reason:h[b.id]||""}:void 0);if(j==="approve"){const E=(S=N.request)==null?void 0:S.status;t(E==="applied"?"Applied: "+b.summary:"Failed: "+(((R=N.request)==null?void 0:R.result)||""),E!=="applied"),E==="applied"&&N.response&&JSON.stringify(N.response).includes('"secret"')&&w({summary:b.summary,response:N.response})}else t(j==="reject"?"Rejected":"Cancelled");C(),s()}catch(N){t(Ee(N),!0)}},_=(u||[]).filter(b=>x||b.requested_by===o.email);return r.jsxs("section",{className:"grid gap-4",children:[r.jsx(He,{children:x?"Operators change repositories, rules and learnings and run reviews directly. Their other changes (code hosts, webhooks, settings, models, the executor, the license) wait here for an admin. Approving runs the change as the operator, with the same checks, and the audit log names both of you. Requests expire after 7 days. Merge requests the bot approved are marked on Reviews.":"Changes to code hosts, webhooks, settings, models, the executor and the license wait for an admin. Your requests are listed here; they expire after 7 days."}),v&&r.jsx(un,{children:r.jsxs("div",{className:"grid gap-2 p-4",children:[r.jsxs("div",{className:"font-medium",children:[v.summary,": copy the new secret now, it isn't shown again"]}),r.jsx("pre",{className:"max-h-60 overflow-auto rounded-md bg-muted p-2 font-mono text-xs whitespace-pre-wrap break-all",children:JSON.stringify(v.response,null,2)}),r.jsx("div",{children:r.jsx(re,{variant:"outline",size:"sm",onClick:()=>w(null),children:"Done"})})]})}),r.jsx("div",{className:"flex items-center gap-2",children:r.jsxs(Ne,{className:"w-48",value:a,onChange:b=>l(b.target.value),children:[r.jsx("option",{value:"pending",children:"Waiting"}),r.jsx("option",{value:"all",children:"All requests"})]})}),r.jsx(un,{children:u?_.length?r.jsx("ul",{className:"divide-y",children:_.map(b=>r.jsxs("li",{className:"grid gap-2 p-4 md:grid-cols-[1fr_minmax(16rem,28rem)]",children:[r.jsxs("div",{className:"grid gap-1",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx("span",{className:"font-medium",children:b.summary}),r.jsx(Je,{kind:aR(b.status),children:b.status==="pending"?"waiting":b.status})]}),r.jsxs(ne,{children:["asked by ",b.requested_by," · ",r.jsx("span",{title:ml(b.requested_at),children:qr(b.requested_at)}),b.decided_by&&b.status!=="pending"&&r.jsxs(r.Fragment,{children:[" · ",b.status," by ",b.decided_by,b.decided_at?" "+qr(b.decided_at):""]})]}),b.result&&b.status!=="applied"&&r.jsx(ne,{className:b.status==="failed"?"text-destructive":"",children:b.result}),b.status==="pending"&&r.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2",children:[x&&r.jsx(re,{size:"sm",onClick:()=>y(b,"approve"),children:"Approve"}),x&&r.jsxs(r.Fragment,{children:[r.jsx(ve,{className:"h-8 max-w-60",placeholder:"Reason (optional)",value:h[b.id]||"",onChange:j=>g({...h,[b.id]:j.target.value})}),r.jsx(re,{size:"sm",variant:"outline",onClick:()=>y(b,"reject"),children:"Reject"})]}),b.requested_by===o.email&&r.jsx(re,{size:"sm",variant:"ghost",onClick:()=>y(b,"cancel"),children:"Cancel request"})]})]}),r.jsx("div",{className:"min-w-0",children:r.jsx(Pw,{detail:b.preview})})]},b.id))}):r.jsx(qe,{children:a==="pending"?"No change requests wait for an admin.":"No requests yet."}):r.jsx(qe,{children:"Loading…"})})]})}const cR={none:["Free core","idle"],active:["Active","on"],grace:["Expired — grace period","warn"],expired:["Expired","off"],invalid:["Not valid","off"]};function uR(){const t=no(),o=bi(),s=et(),a=to(),l=t.license,[u,d]=m.useState(""),[h,g]=cR[l.state],v=x=>bn("/admin/api/license",{key:x}).then(()=>{d(""),o(),s(x?"License installed":"License removed")}).catch(C=>s(Ee(C),!0)),w=async()=>{await a({title:"Remove the license?",description:"Paid features turn off at once.",action:"Remove license",danger:!0})&&v("")};return r.jsxs("section",{className:"grid gap-4",children:[r.jsxs(lt,{children:[r.jsx(cn,{children:r.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[r.jsx(Je,{kind:g,children:h}),l.customer&&r.jsxs("span",{className:"text-sm",children:[r.jsx("b",{children:l.customer})," · ",l.plan]}),r.jsx("span",{className:"flex-1"}),l.expires_at&&r.jsxs("span",{className:"text-sm text-muted-foreground",children:["expires ",Hm(l.expires_at)]})]})}),r.jsxs(Pt,{className:"grid gap-4",children:[l.error&&r.jsx(Zn,{variant:"destructive",className:"banner bad",children:r.jsx(er,{children:l.error})}),l.state==="grace"&&r.jsx(Zn,{className:"banner border-warning/40 bg-warning-soft",children:r.jsxs(er,{className:"text-warning",children:["The license has expired. Paid features keep working until ",Hm(l.grace_until),"; renew it to keep them."]})}),r.jsxs("div",{children:[r.jsx("h2",{className:"h2 mb-3 text-sm font-semibold",children:"Features"}),r.jsx("ul",{className:"feats grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:Object.keys(al).map(x=>{const C=l.features.includes(x);return r.jsxs("li",{className:"flex items-center gap-2 text-sm",children:[r.jsx("span",{className:"flex size-5 items-center justify-center rounded-full "+(C?"bg-success-soft text-success":"bg-muted text-muted-foreground"),children:C?r.jsx(hl,{className:"size-3"}):r.jsx(hk,{className:"size-3"})}),r.jsx("span",{className:C?"":"text-muted-foreground",children:al[x]}),r.jsx("span",{className:"sr-only",children:C?"on":"off"})]},x)})})]}),r.jsxs(He,{children:["Free without a license: reviews for one GitHub, GitLab and Bitbucket host each, the local executor, repository on/off, ",r.jsx("code",{children:"@bot"})," commands, review history for ",t.free_retention_days," days, the status dashboard and admin sign-in by email."]})]})]}),r.jsxs(lt,{children:[r.jsxs(cn,{children:[r.jsxs(yn,{className:"flex items-center gap-2",children:[r.jsx(bv,{className:"size-4"}),l.state==="none"?"Install a license":"Replace the license"]}),r.jsx(wn,{children:"Keys are verified offline; the console never calls home."})]}),r.jsx(Pt,{className:"grid gap-4",children:l.managed?r.jsx("p",{className:"text-sm text-muted-foreground",children:l.source==="env"?r.jsxs(r.Fragment,{children:["This license comes from ",r.jsx("code",{children:"CODEREVIEW_CONSOLE_LICENSE"}),", which overrides the one managed here. Remove the variable and restart to manage the license here."]}):r.jsxs(r.Fragment,{children:["This license comes from ",r.jsx("code",{children:"license.file"})," because the console has no database. With ",r.jsx("code",{children:"database.url"})," set, the key is copied into the database and managed here."]})}):r.jsxs(r.Fragment,{children:[r.jsx(ee,{label:"License key",children:r.jsx(an,{className:"key min-h-28 font-mono text-xs",placeholder:"DIV1.… or the -----BEGIN DIVMORA LICENSE KEY----- block",autoComplete:"off",spellCheck:!1,value:u,onChange:x=>d(x.target.value)})}),r.jsxs("div",{className:"flex flex-wrap gap-2",children:[r.jsx(re,{disabled:!u.trim(),onClick:()=>v(u.trim()),children:"Install"}),l.source==="database"&&r.jsx(re,{variant:"ghost",className:"text-destructive hover:text-destructive",onClick:w,children:"Remove license"})]}),r.jsx(He,{children:"A pasted key is stored in the database and applies at once, except the executor, which is chosen when the console starts."})]})})]}),r.jsxs(He,{children:["Every use of a paid feature needs a license from Divmora, in development, CI and production alike. For a license or a trial, contact"," ",r.jsx("a",{className:"text-primary underline-offset-4 hover:underline",href:"mailto:licensing@divmora.com",children:"licensing@divmora.com"}),"."]})]})}const dR={openai:"OPENAI_API_KEY",anthropic:"ANTHROPIC_API_KEY",gemini:"GEMINI_API_KEY",bedrock:"",azure:"AZURE_OPENAI_API_KEY",ollama:"",openrouter:"OPENROUTER_API_KEY",groq:"GROQ_API_KEY",deepseek:"DEEPSEEK_API_KEY",mistral:"MISTRAL_API_KEY",xai:"XAI_API_KEY",together:"TOGETHER_API_KEY",litellm:"LITELLM_API_KEY","openai-compatible":"OPENAI_COMPATIBLE_API_KEY"},Ig=t=>t==="azure"||t==="openai-compatible",Tn=t=>typeof t=="string"?t:t==null?"":String(t),fR=["provider","model","api_key_env","base_url","region","timeout"];function hR({profile:t,providers:o,onSaved:s,onCancel:a}){const l=et(),u=()=>{const y=(t==null?void 0:t.config)??{};return{name:(t==null?void 0:t.name)??"",provider:Tn(y.provider)||"anthropic",model:Tn(y.model),api_key_env:Tn(y.api_key_env),base_url:Tn(y.base_url),region:Tn(y.region),timeout:Tn(y.timeout)}},[d,h]=m.useState(u),[g,v]=m.useState(!1),w=y=>_=>h({...d,[y]:_.target.value}),x=async()=>{const y={...(t==null?void 0:t.config)??{}};for(const _ of fR)y[_]=d[_].trim();v(!0);try{s(await bn("/admin/api/models/"+encodeURIComponent(d.name.trim()),{config:y})),l("Saved "+d.name.trim())}catch(_){l(Ee(_),!0)}finally{v(!1)}},C=dR[d.provider];return r.jsxs("div",{className:"grid gap-4",children:[r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ee,{label:"Name",hint:r.jsx(ne,{children:"Repositories and the default refer to it by this name. Lowercase, e.g. claude or fast."}),children:r.jsx(ve,{value:d.name,onChange:w("name"),disabled:!!t,placeholder:"claude",autoFocus:!t})}),r.jsx(ee,{label:"Provider",children:r.jsx(Ne,{value:d.provider,onChange:w("provider"),children:o.map(y=>r.jsx("option",{value:y,children:y},y))})}),r.jsx(ee,{label:"Model",className:"lg:col-span-2",hint:r.jsxs(ne,{children:["The provider's model ID",d.provider==="bedrock"?" or inference profile ID":"","."]}),children:r.jsx(ve,{value:d.model,onChange:w("model"),placeholder:d.provider==="ollama"?"qwen2.5-coder:14b":""})}),C!==""&&r.jsx(ee,{label:"API key: environment variable",className:"lg:col-span-2",hint:r.jsxs(ne,{children:["The console never stores API keys. Set the key in this environment variable of the console (for example in its Kubernetes Secret) and restart it once; the console passes it to review jobs. Empty means ",C,"."]}),children:r.jsx(ve,{value:d.api_key_env,onChange:w("api_key_env"),placeholder:C,spellCheck:!1})}),r.jsx(ee,{label:Ig(d.provider)?"Base URL":"Base URL (optional)",className:"lg:col-span-2",hint:r.jsx(ne,{children:Ig(d.provider)?"Required for this provider.":"Only for a proxy or a self-hosted endpoint."}),children:r.jsx(ve,{value:d.base_url,onChange:w("base_url"),placeholder:"https://",spellCheck:!1})}),d.provider==="bedrock"&&r.jsx(ee,{label:"AWS region",hint:r.jsx(ne,{children:"Credentials come from the AWS chain (IRSA, instance role, env)."}),children:r.jsx(ve,{value:d.region,onChange:w("region"),placeholder:"us-east-1"})}),r.jsx(ee,{label:"Timeout (optional)",hint:r.jsx(ne,{children:"Per request, e.g. 2m or 10m for slow local models."}),children:r.jsx(ve,{value:d.timeout,onChange:w("timeout"),placeholder:"default"})})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx(re,{onClick:x,disabled:g||!d.name.trim()||!d.model.trim(),children:t?"Save profile":"Add profile"}),r.jsx(re,{variant:"outline",onClick:a,children:"Cancel"})]})]})}function pR({p:t}){return t.key_env?r.jsxs("span",{className:"grid gap-1",children:[r.jsx("code",{className:"text-xs",children:t.key_env}),t.key_set?r.jsx(Je,{kind:"on",children:"set"}):r.jsx(Je,{kind:"warn",children:"not set in the console"})]}):r.jsx("span",{className:"text-sm text-muted-foreground",children:"none needed"})}function mR({v:t,onSaved:o}){const s=et(),[a,l]=m.useState(t.default),[u,d]=m.useState(t.fallback),[h,g]=m.useState("");m.useEffect(()=>{l(t.default),d(t.fallback)},[t.default,t.fallback.join(",")]);const v=t.profiles.map(y=>y.name),w=v.filter(y=>y!==a&&!u.includes(y)),x=a!==t.default||u.join(",")!==t.fallback.join(","),C=async()=>{try{o(await bn("/admin/api/model-choice",{default:a,fallback:u.filter(y=>y!==a)})),s("Default model saved")}catch(y){s(Ee(y),!0)}};return r.jsxs(lt,{children:[r.jsxs(cn,{children:[r.jsx(yn,{className:"h2",children:"Default model"}),r.jsx(wn,{children:"Reviews use the default unless a repository picks another profile. When it fails, the fallbacks are tried in order."})]}),r.jsxs(Pt,{className:"grid gap-4",children:[r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ee,{label:"Default",children:r.jsxs(Ne,{value:v.includes(a)?a:"",onChange:y=>l(y.target.value),children:[r.jsx("option",{value:"",disabled:!0,children:"Choose a profile"}),v.map(y=>r.jsx("option",{value:y,children:y},y))]})}),r.jsx(ee,{label:"Fallbacks, in order",children:r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[u.map((y,_)=>r.jsxs(Tt,{variant:"secondary",className:"gap-1",children:[_+1,". ",y,r.jsx("button",{type:"button","aria-label":"Remove "+y,className:"rounded-sm hover:text-destructive",onClick:()=>d(u.filter(b=>b!==y)),children:r.jsx(Pd,{className:"size-3"})})]},y)),w.length>0&&r.jsxs(Ne,{className:"h-8 w-auto",value:h,onChange:y=>{y.target.value&&d([...u,y.target.value]),g("")},"aria-label":"Add a fallback",children:[r.jsx("option",{value:"",children:u.length?"Add another…":"Add a fallback…"}),w.map(y=>r.jsx("option",{value:y,children:y},y))]}),!u.length&&!w.length&&r.jsx("span",{className:"text-sm text-muted-foreground",children:"add another profile to use one"})]})})]}),r.jsx("div",{children:r.jsx(re,{onClick:C,disabled:!x||!v.includes(a),children:"Save default"})})]})]})}function gR(){const t=et(),o=to(),s=bi(),[a,l]=m.useState(null),[u,d]=m.useState(null),h=()=>Ke("/admin/api/models").then(l).catch(x=>t(Ee(x),!0));m.useEffect(()=>{h()},[]);const g=x=>{l(x),d(null),s()},v=async x=>{if(await o({title:"Delete "+x.name+"?",description:"Repositories can't pick it any more.",action:"Delete profile",danger:!0}))try{g(await Co("/admin/api/models/"+encodeURIComponent(x.name))),t("Deleted "+x.name)}catch(C){t(Ee(C),!0)}};if(!a)return r.jsx(qe,{children:"Loading…"});const w=u===null?"":u==="new"?"Add a model profile":"Edit "+u.name;return r.jsxs("section",{className:"grid gap-4",children:[r.jsx(lr,{children:r.jsxs(re,{onClick:()=>d("new"),children:[r.jsx(ps,{})," Add profile"]})}),r.jsx(un,{children:a.profiles.length===0?r.jsx(qe,{children:"No model profiles yet. Add one to start reviewing."}):r.jsxs(zn,{children:[r.jsx(Fn,{children:r.jsxs(ct,{children:[r.jsx(je,{className:"pl-4",children:"Profile"}),r.jsx(je,{children:"Provider and model"}),r.jsx(je,{children:"API key"}),r.jsx(je,{})]})}),r.jsx($n,{children:a.profiles.map(x=>r.jsxs(ct,{children:[r.jsxs(ke,{className:"pl-4 align-top",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[r.jsx("span",{className:"font-medium",children:x.name}),x.name===a.default&&r.jsx(Tt,{children:"default"}),a.fallback.includes(x.name)&&r.jsxs(Tt,{variant:"secondary",children:["fallback ",a.fallback.indexOf(x.name)+1]})]}),r.jsxs(ne,{children:["by ",x.updated_by||"—"]})]}),r.jsxs(ke,{className:"align-top whitespace-normal",children:[r.jsxs("code",{className:"text-xs",children:[Tn(x.config.provider),":",Tn(x.config.model)]}),!!x.config.base_url&&r.jsx(ne,{children:Tn(x.config.base_url)}),!!x.config.region&&r.jsx(ne,{children:Tn(x.config.region)})]}),r.jsx(ke,{className:"align-top",children:r.jsx(pR,{p:x})}),r.jsx(ke,{className:"pr-4 text-right align-top",children:r.jsxs("div",{className:"flex justify-end gap-2",children:[r.jsx(re,{size:"sm",variant:"outline",onClick:()=>d(x),children:"Edit"}),r.jsx(re,{size:"sm",variant:"ghost",className:"text-destructive",onClick:()=>v(x),children:"Delete"})]})})]},x.name))})]})}),a.profiles.length>0&&r.jsx(mR,{v:a,onSaved:g}),r.jsx(He,{children:"API keys are never stored in the console: each profile names an environment variable of the console that holds its key, and the console hands that key to each review job."}),r.jsx(ko,{open:u!==null,onClose:()=>d(null),title:w,description:"A provider, a model and where its API key comes from.",children:u!==null&&r.jsx(hR,{profile:u==="new"?null:u,providers:a.providers,onSaved:g,onCancel:()=>d(null)},u==="new"?"new":u.name)})]})}const Vu=t=>Object.entries(t??{}).map(([o,s])=>o+"="+s).join(` `);function Hu(t,o){const s={};for(const a of o.split(` `)){const l=a.trim();if(!l)continue;const u=l.indexOf("=");if(u<=0)throw new Error(t+": write each entry as key=value ("+l+")");s[l.slice(0,u).trim()]=l.slice(u+1).trim()}return s}const zg=t=>t&&Object.keys(t).length?JSON.stringify(t,null,2):"";function Fg(t,o,s){if(!o.trim())return;let a;try{a=JSON.parse(o)}catch{throw new Error(t+" is not valid JSON")}if(s?!Array.isArray(a):typeof a!="object"||a===null||Array.isArray(a))throw new Error(t+(s?" must be a JSON list":" must be a JSON object"));return a}const vR={binary:"Binary",network:"Docker network",namespace:"Namespace",service_account:"Service account",automount_service_account_token:"Kubernetes API token in pods",cluster:"Cluster connection",env:"Passed-through env vars"},xR={local:"Local",docker:"Docker",kubernetes:"Kubernetes"};function $g(t){const o=t.ca_bundle??{};return{version:t.version??"",cpu:t.cpu??"",memory:t.memory??"",ttl:t.ttl??"",priority:t.priority_class_name??"",storage:t.ephemeral_storage??"",tmp:t.tmp_size_limit??"",nodeSelector:Vu(t.node_selector),labels:Vu(t.pod_labels),annotations:Vu(t.pod_annotations),tolerations:zg(t.tolerations),affinity:zg(t.affinity),caKind:o.config_map?"config_map":o.secret?"secret":"",caName:o.config_map||o.secret||"",caKey:o.key??""}}function yR(t){return{version:t.version.trim(),cpu:t.cpu.trim(),memory:t.memory.trim(),ttl:t.ttl.trim(),priority_class_name:t.priority.trim(),ephemeral_storage:t.storage.trim(),tmp_size_limit:t.tmp.trim(),node_selector:Hu("Node selector",t.nodeSelector),pod_labels:Hu("Pod labels",t.labels),pod_annotations:Hu("Pod annotations",t.annotations),tolerations:Fg("Tolerations",t.tolerations,!0),affinity:Fg("Affinity",t.affinity,!1),ca_bundle:t.caKind?{[t.caKind]:t.caName.trim(),key:t.caKey.trim()}:{}}}const Gu="__other__";function wR({v:t,version:o,custom:s}){const a=/^v?\d+\.\d+\.\d+$/.test(o)?o.replace(/^v/,""):"";return r.jsxs(ne,{children:[t.tags.length>0?s?"A tag, a sha256: digest, or both to pin it (0.5.0@sha256:…). ":"Versions found in the image repository. ":t.tags_error?"Couldn't list the versions in the image repository ("+t.tags_error+"), so type one: a tag, a sha256: digest, or both (0.5.0@sha256:…). ":"A tag, a sha256: digest, or both to pin it (0.5.0@sha256:…). ","The console needs code-review-bot ",t.min_cli_version," or later. Now running ",r.jsx("code",{className:"break-all",children:t.image}),".",a&&r.jsxs(r.Fragment,{children:[" ",r.jsxs("a",{className:"underline underline-offset-2",href:"https://github.com/divmora/code-review-bot/releases/tag/v"+a,target:"_blank",rel:"noreferrer",children:["Release notes for ",a]})]})]})}function bR(){const t=et(),[o,s]=m.useState(null),[a,l]=m.useState(null),[u,d]=m.useState(!1),[h,g]=m.useState(!1),v=b=>{s(b),l($g(b.settings)),g(!b.tags.includes(b.settings.version))};if(m.useEffect(()=>{Ke("/admin/api/executor").then(v).catch(b=>t(Ee(b),!0))},[]),!o||!a)return r.jsx(qe,{children:"Loading…"});const w=b=>j=>l({...a,[b]:j.target.value}),x=o.type==="kubernetes",C=JSON.stringify(a)!==JSON.stringify($g(o.settings)),y=async()=>{let b;try{b=yR(a)}catch(j){t(Ee(j),!0);return}d(!0);try{v(await bn("/admin/api/executor",b)),t("Saved: the next review uses these settings")}catch(j){t(Ee(j),!0)}finally{d(!1)}},_=Object.entries(o.fixed);return r.jsxs("section",{className:"grid max-w-4xl gap-4",children:[r.jsxs(lt,{children:[r.jsxs(cn,{children:[r.jsxs(yn,{className:"h2 flex flex-wrap items-center gap-2",children:["Reviews run with ",xR[o.type]??o.type,!o.licensed&&r.jsx(Tt,{variant:"destructive",children:"paused: needs a license"})]}),r.jsx(wn,{children:o.type==="local"?"Each review runs the codereview binary on the console host. There is nothing to change here; switching to Docker or Kubernetes is done in the config file.":"Where reviews run and what they can reach is set in the config file (below, read-only). The settings further down are managed here and apply to the next review, without a restart."})]}),(_.length>0||o.image_repo)&&r.jsx(Pt,{children:r.jsxs("dl",{className:"grid gap-x-6 gap-y-2 text-sm sm:grid-cols-[max-content_1fr]",children:[o.image_repo&&r.jsxs(r.Fragment,{children:[r.jsx("dt",{className:"text-muted-foreground",children:"Image repository"}),r.jsx("dd",{children:r.jsx("code",{className:"text-xs break-all",children:o.image_repo})})]}),_.map(([b,j])=>r.jsxs("div",{className:"contents",children:[r.jsx("dt",{className:"text-muted-foreground",children:vR[b]??b}),r.jsx("dd",{children:b==="env"||b==="service_account"||b==="namespace"?r.jsx("code",{className:"text-xs break-all",children:j}):j})]},b))]})})]}),o.editable&&r.jsxs(lt,{children:[r.jsxs(cn,{children:[r.jsxs(yn,{className:"h2",children:["Review ",x?"pods":"containers"]}),r.jsx(wn,{children:o.source==="config"?"Not saved yet: showing the starting values; saving stores them in the console.":"Saved in the console."})]}),r.jsxs(Pt,{className:"grid gap-5",children:[r.jsxs(Ge,{children:[r.jsx(ee,{label:"Version",className:"lg:col-span-3",hint:r.jsx(wR,{v:o,version:a.version,custom:h}),children:r.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[r.jsxs("code",{className:"hidden shrink truncate text-xs text-muted-foreground sm:block",children:[o.image_repo,a.version.startsWith("sha256:")?"@":":"]}),o.tags.length>0&&r.jsxs(Ne,{"aria-label":"Version",className:"w-auto min-w-36",value:h?Gu:a.version,onChange:b=>{b.target.value===Gu?g(!0):(g(!1),l({...a,version:b.target.value}))},children:[o.tags.map((b,j)=>r.jsxs("option",{value:b,children:[b,j===0?" (newest)":"",b===o.settings.version?" (current)":""]},b)),r.jsx("option",{value:Gu,children:"Other: tag or digest…"})]}),(h||o.tags.length===0)&&r.jsx(ve,{value:a.version,onChange:w("version"),placeholder:"0.5.0",spellCheck:!1,"aria-label":o.tags.length?"Other version":"Version",className:"sm:max-w-64"})]})}),r.jsx(ee,{label:"CPU",hint:r.jsxs(ne,{children:[x?"Request and limit, e.g. 500m or 1.":"docker --cpus, e.g. 1.5."," Empty = no limit."]}),children:r.jsx(ve,{value:a.cpu,onChange:w("cpu"),placeholder:x?"500m":"1"})}),r.jsx(ee,{label:"Memory",hint:r.jsxs(ne,{children:[x?"Request and limit, e.g. 1Gi.":"docker --memory, e.g. 2g."," Empty = no limit."]}),children:r.jsx(ve,{value:a.memory,onChange:w("memory"),placeholder:x?"1Gi":"2g"})}),x&&r.jsx(ee,{label:"Disk (ephemeral storage)",hint:r.jsx(ne,{children:"Request and limit for the pod's local disk, /tmp included. Empty = 2Gi; none = no limit."}),children:r.jsx(ve,{value:a.storage,onChange:w("storage"),placeholder:"2Gi"})}),x&&r.jsx(ee,{label:"/tmp size",hint:r.jsx(ne,{children:"A review writing more is evicted instead of filling the node's disk. Empty = 1Gi; none = no limit."}),children:r.jsx(ve,{value:a.tmp,onChange:w("tmp"),placeholder:"1Gi"})}),x&&r.jsx(ee,{label:"Keep finished jobs for",hint:r.jsx(ne,{children:"For debugging with kubectl, e.g. 10m or 1h."}),children:r.jsx(ve,{value:a.ttl,onChange:w("ttl"),placeholder:"10m"})})]}),x&&r.jsxs(r.Fragment,{children:[r.jsxs(Ge,{className:"lg:grid-cols-2",children:[r.jsx(ee,{label:"Node selector",hint:r.jsx(ne,{children:"One key=value per line."}),children:r.jsx(an,{rows:3,value:a.nodeSelector,onChange:w("nodeSelector"),placeholder:"workload=batch",spellCheck:!1,className:"font-mono text-xs"})}),r.jsx(ee,{label:"Priority class",hint:r.jsx(ne,{children:"An existing PriorityClass, e.g. for low-priority batch work."}),children:r.jsx(ve,{value:a.priority,onChange:w("priority"),placeholder:"batch-low"})}),r.jsx(ee,{label:"Pod labels",hint:r.jsx(ne,{children:"key=value per line. The console's own labels win on a clash."}),children:r.jsx(an,{rows:3,value:a.labels,onChange:w("labels"),placeholder:"team=platform",spellCheck:!1,className:"font-mono text-xs"})}),r.jsx(ee,{label:"Pod annotations",hint:r.jsx(ne,{children:"key=value per line, e.g. karpenter.sh/do-not-disrupt=true."}),children:r.jsx(an,{rows:3,value:a.annotations,onChange:w("annotations"),spellCheck:!1,className:"font-mono text-xs"})}),r.jsx(ee,{label:"Tolerations (JSON)",hint:r.jsx(ne,{children:"A list in the Kubernetes format."}),children:r.jsx(an,{rows:5,value:a.tolerations,onChange:w("tolerations"),placeholder:'[{"key": "spot", "operator": "Exists", "effect": "NoSchedule"}]',spellCheck:!1,className:"font-mono text-xs"})}),r.jsx(ee,{label:"Affinity (JSON)",hint:r.jsx(ne,{children:"An object in the Kubernetes format (nodeAffinity, podAntiAffinity…)."}),children:r.jsx(an,{rows:5,value:a.affinity,onChange:w("affinity"),placeholder:'{"nodeAffinity": {…}}',spellCheck:!1,className:"font-mono text-xs"})})]}),r.jsxs(Ge,{children:[r.jsx(ee,{label:"Extra CA certificates",hint:r.jsx(ne,{children:"For a code host or model endpoint behind a private CA. Trusted in addition to the system CAs."}),children:r.jsxs(Ne,{value:a.caKind,onChange:w("caKind"),children:[r.jsx("option",{value:"",children:"None"}),r.jsx("option",{value:"config_map",children:"From a ConfigMap"}),r.jsx("option",{value:"secret",children:"From a Secret"})]})}),a.caKind&&r.jsxs(r.Fragment,{children:[r.jsx(ee,{label:a.caKind==="secret"?"Secret name":"ConfigMap name",hint:r.jsxs(ne,{children:["In the ",o.fixed.namespace," namespace."]}),children:r.jsx(ve,{value:a.caName,onChange:w("caName"),placeholder:"corp-ca"})}),r.jsx(ee,{label:"Key",hint:r.jsx(ne,{children:"The PEM file inside it."}),children:r.jsx(ve,{value:a.caKey,onChange:w("caKey"),placeholder:"ca.crt"})})]})]})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx(re,{onClick:y,disabled:u||!C&&o.source==="console",children:"Save settings"}),C&&r.jsx(re,{variant:"outline",onClick:()=>v(o),children:"Discard changes"})]})]})]}),r.jsx(He,{children:"The executor type, the image repository, the cluster connection, namespace and service account stay in the config file: they decide what review jobs, which carry the code host tokens and model keys, can reach. Changing them needs a restart."})]})}const jR={"/license":"Open License","/hosts":"Open Code hosts","/webhooks":"Open Webhooks","/models":"Open Models","/settings":"Open Settings","/repositories":"Open Repositories","/reviews":"Open Reviews"};function kR(){const t=et(),o=bi(),[s,a]=m.useState(null),l=m.useRef(""),u=(g=!1)=>(g?Nk:Ke)("/admin/api/setup").then(v=>{a(v);const w=v.done+"/"+v.complete;l.current!==w&&(l.current!==""&&o(),l.current=w)}).catch(v=>t(Ee(v),!0));if(m.useEffect(()=>{u();const g=window.setInterval(()=>u(!0),15e3);return()=>window.clearInterval(g)},[]),!s)return r.jsx(qe,{children:"Loading…"});const d=s.steps.find(g=>!g.done&&!g.optional),h=s.total?Math.round(s.done/s.total*100):100;return r.jsxs("section",{className:"grid max-w-3xl gap-4",children:[r.jsxs(lt,{children:[r.jsxs(cn,{children:[r.jsx(yn,{className:"h2",children:s.complete?"All set":"Get your first review"}),r.jsx(wn,{children:s.complete?"Everything needed for reviews is in place. This page stays here for when you add more.":`${s.done} of ${s.total} required steps done${s.steps.some(g=>g.optional)?" (optional steps aren't counted)":""}. Each step is checked against what is configured right now.`})]}),r.jsxs(Pt,{className:"grid gap-3",children:[r.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-muted",role:"progressbar","aria-valuenow":h,"aria-valuemin":0,"aria-valuemax":100,"aria-label":"Setup progress",children:r.jsx("div",{className:"h-full rounded-full bg-primary transition-all",style:{width:h+"%"}})}),r.jsx("div",{children:r.jsxs(re,{variant:"outline",size:"sm",onClick:()=>u(),children:[r.jsx(Mv,{})," Check again"]})})]})]}),r.jsx("ol",{className:"grid gap-3",children:s.steps.map((g,v)=>{const w=(d==null?void 0:d.id)===g.id;return r.jsx("li",{children:r.jsx(lt,{className:ie("gap-3 py-4",w&&"border-primary ring-1 ring-primary/40"),children:r.jsxs(Pt,{className:"flex gap-3 px-4",children:[r.jsx("div",{className:ie("mt-0.5 flex size-7 shrink-0 items-center justify-center rounded-full border text-xs font-semibold",g.done&&g.warning?"border-warning bg-warning-soft text-warning":g.done?"border-success bg-success-soft text-success":w?"border-primary text-primary":"text-muted-foreground"),"aria-hidden":!0,children:g.done?r.jsx(hl,{className:"size-4"}):w?v+1:r.jsx(hv,{className:"size-3"})}),r.jsxs("div",{className:"grid min-w-0 flex-1 gap-1.5",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx("span",{className:"font-medium",children:g.title}),g.optional&&r.jsx(Tt,{variant:"outline",className:"font-normal text-muted-foreground",children:"optional"}),w&&r.jsx(Tt,{children:"next"}),r.jsx("span",{className:"sr-only",children:g.done?"done":"not done"})]}),g.warning&&r.jsx("div",{className:"text-sm text-warning",children:g.warning}),g.detail&&r.jsx("div",{className:ie("text-sm",g.done&&!g.warning?"text-success":g.done?"text-muted-foreground":/rejected|failed|expired|not valid|won't work|not set/.test(g.detail)?"text-destructive":"text-muted-foreground"),children:g.detail}),(!g.done||w)&&r.jsx("p",{className:"text-sm leading-relaxed text-muted-foreground",children:g.help}),g.link&&!g.done&&r.jsx("div",{children:r.jsx(re,{asChild:!0,size:"sm",variant:w?"default":"outline",children:r.jsxs(Yt,{to:g.link,children:[jR[g.link]||"Open"," ",r.jsx(nk,{})]})})})]})]})})},g.id)})}),r.jsx(He,{children:"Steps update on their own every 15 seconds while this page is open, so you can set up the webhook on the code host and watch it turn green."})]})}const Va=[["critical","Critical","--st-fail"],["major","Major","--warning"],["minor","Minor","--sc-quality"],["nitpick","Nitpick","--st-skip"],["other","Other","--muted-foreground"]],Ug=[["30d","Last 30 days"],["90d","Last 90 days"],["365d","Last 12 months"],["all","All history"]];function Ur(t,o){const s=new URLSearchParams(o);return t.range!=="all"&&(s.set("from",t.from.slice(0,10)),s.set("to",new Date(new Date(t.to).getTime()-864e5).toISOString().slice(0,10))),"/reviews?"+s.toString()}function Br({value:t,label:o,sub:s,to:a}){const l=r.jsxs(Pt,{className:"px-4",children:[r.jsx("div",{className:"text-xl font-semibold tabular-nums",children:t}),r.jsx("div",{className:"text-xs text-muted-foreground",children:o}),s&&r.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:s})]});return r.jsx(lt,{className:"tile gap-1 py-4"+(a?" transition-colors hover:border-primary/50 hover:bg-accent/40":""),children:a?r.jsx(Yt,{to:a,className:"rounded-xl focus-visible:outline-2 focus-visible:outline-ring","aria-label":`${o}: ${t} (open in Reviews)`,children:l}):l})}function rs({title:t,description:o,children:s}){return r.jsxs(lt,{className:"py-4",children:[r.jsxs(cn,{className:"px-4",children:[r.jsx(yn,{className:"h2",children:t}),o&&r.jsx(wn,{children:o})]}),r.jsx(Pt,{className:"grid gap-3 px-4",children:s})]})}function Bg({items:t}){return r.jsx("div",{className:"flex flex-wrap gap-4 text-xs text-muted-foreground",children:t.map(([o,s,a])=>r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"size-2.5 rounded-sm",ref:l=>l==null?void 0:l.style.setProperty("background",`var(${a})`)}),s]},o))})}function Wg({rows:t,unit:o,link:s}){return t.length?r.jsx(un,{children:r.jsxs(zn,{children:[r.jsx(Fn,{children:r.jsxs(ct,{children:[r.jsx(je,{className:"pl-4",children:"Repository"}),r.jsx(je,{className:"pr-4 text-right",children:o})]})}),r.jsx($n,{children:t.map(a=>r.jsxs(ct,{children:[r.jsxs(ke,{className:"pl-4",children:[r.jsx(Yt,{to:s(a),className:"font-medium underline-offset-2 hover:underline",children:a.repo}),r.jsxs(ne,{children:[a.platform," · ",a.host]})]}),r.jsx(ke,{className:"pr-4 text-right tabular-nums",children:ze(a.count)})]},`${a.platform}|${a.host}|${a.repo}`))})]})}):r.jsx(ne,{children:"Nothing in this period."})}function Vg({rows:t}){const o=Math.max(1,...t.map(([,s])=>s));return t.some(([,s])=>s>0)?r.jsx("div",{className:"grid gap-1.5",children:t.map(([s,a,l,u])=>r.jsxs("div",{className:"grid grid-cols-[8rem_1fr_3.5rem] items-center gap-2 text-sm",children:[u&&a>0?r.jsx(Yt,{to:u,className:"truncate capitalize underline-offset-2 hover:underline",children:s}):r.jsx("span",{className:"truncate capitalize",children:s}),r.jsx("span",{className:"h-2 rounded-sm bg-muted",children:r.jsx("span",{className:"block h-2 rounded-sm",ref:d=>d&&(d.style.width=100*a/o+"%",d.style.background=`var(${l||"--primary"})`)})}),r.jsx("span",{className:"text-right text-muted-foreground tabular-nums",children:ze(a)})]},s))}):r.jsx(ne,{children:"No findings in this period."})}function CR(){var C;const t=et(),o=qt("metrics"),[s,a]=m.useState("30d"),[l,u]=m.useState(null);m.useEffect(()=>{u(null),Ke("/admin/api/impact?range="+s).then(u).catch(y=>t(Ee(y),!0))},[s]);const d=l?Cf({granularity:l.granularity,from:l.from,to:l.to,points:l.trend.map(y=>({bucket:y.bucket,reviews:y.reviews,...y.findings,scored:y.scored,quality_sum:y.quality_sum,security_sum:y.security_sum,maintainability_sum:y.maintainability_sum}))}):[],h=(l==null?void 0:l.range)==="all"?d.slice(Math.max(0,d.findIndex(y=>y.reviews))):d,g=l?Object.fromEntries(ln.map(([y])=>[y,ds({bucket:"",...l},y)])):{},v=((C=Ug.find(([y])=>y===s))==null?void 0:C[0])??"30d",w=y=>"/admin/api/impact/export?"+new URLSearchParams({range:v,format:y}).toString(),x=l?Va.filter(([y])=>l.by_severity[y]).map(([y,_])=>`${ze(l.by_severity[y])} ${_.toLowerCase()}`).join(" · "):"";return r.jsxs("section",{className:"grid gap-4",children:[r.jsxs(lr,{children:[r.jsx(Ne,{className:"w-auto","aria-label":"Period",value:s,onChange:y=>a(y.target.value),children:Ug.map(([y,_])=>r.jsxs("option",{value:y,disabled:!o&&y!=="30d",children:[_,!o&&y!=="30d"?" (licensed)":""]},y))}),l&&r.jsx("span",{className:"text-sm text-muted-foreground",children:SR(l)}),r.jsx("span",{className:"flex-1"}),o&&r.jsxs(r.Fragment,{children:[r.jsx(re,{asChild:!0,variant:"outline",size:"sm",children:r.jsx("a",{href:w("csv"),children:"Export CSV"})}),r.jsx(re,{asChild:!0,variant:"outline",size:"sm",children:r.jsx("a",{href:w("json"),children:"Export JSON"})})]})]}),l?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"tiles grid grid-cols-2 gap-3 md:grid-cols-4",children:[r.jsx(Br,{value:ze(l.prs_reviewed),label:"Merge requests reviewed",sub:ze(l.review_runs)+" review runs",to:Ur(l,{state:"done"})}),r.jsx(Br,{value:ze(l.findings),label:"Findings raised",sub:x||void 0,to:l.findings?Ur(l,{severity:"any"}):void 0}),r.jsx(Br,{value:ze(l.security_findings),label:"Security findings caught",sub:"before merge, in review",to:l.security_findings?Ur(l,{category:"security"}):void 0}),r.jsx(Br,{value:l.first_reviews?nd(l.median_first_review_ms):"–",label:"Median time to first review",sub:l.first_reviews?"from the webhook, "+ze(l.first_reviews)+" merge requests":void 0}),r.jsx(Br,{value:ze(l.active_repos),label:"Active repositories"}),r.jsx(Br,{value:ze(l.comments),label:"Comments posted"}),r.jsx(Br,{value:l.scored?ln.map(([y])=>Math.round(g[y]||0)).join(" / "):"–",label:"Avg scores (Q / S / M)",sub:l.scored?ze(l.scored)+" scored reviews":void 0}),r.jsx(Br,{value:ze(l.approvals||0),label:"Approvals by the bot",sub:"merge requests approved on the code host",to:l.approvals?Ur(l,{approval:"approved"}):void 0})]}),o?r.jsxs(r.Fragment,{children:[r.jsxs(rs,{title:"Reviews and findings",description:`Review runs and findings per ${l.granularity}.`,children:[r.jsx(Bg,{items:[["reviews","Review runs","--st-done"]]}),r.jsx(kd,{points:h,granularity:l.granularity,series:[["reviews","Review runs","--st-done"]],label:`Review runs per ${l.granularity}`}),r.jsx(Bg,{items:Va}),r.jsx(kd,{points:h,granularity:l.granularity,series:Va,label:`Findings per ${l.granularity}, by severity`})]}),l.scored>0&&r.jsxs(rs,{title:"Average scores",description:"Dashed lines at 80 and 50 are the bands of the score labels.",children:[r.jsx(_f,{values:g}),r.jsx(Sf,{points:h,granularity:l.granularity})]}),r.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[r.jsx(rs,{title:"Findings by severity",children:r.jsx(Vg,{rows:Va.map(([y,_,b])=>[_,l.by_severity[y]||0,b,y==="other"?void 0:Ur(l,{severity:y})])})}),r.jsx(rs,{title:"Findings by category",children:r.jsx(Vg,{rows:l.by_category.map(y=>[y.category||"other",y.count,void 0,y.category&&y.category!=="other"?Ur(l,{category:y.category}):void 0])})}),r.jsx(rs,{title:"Top repositories by reviews",children:r.jsx(Wg,{rows:l.top_by_reviews,unit:"Review runs",link:y=>Ur(l,{host:y.host||"",repo:y.repo||"",state:"done"})})}),r.jsx(rs,{title:"Top repositories by findings",children:r.jsx(Wg,{rows:l.top_by_findings,unit:"Findings",link:y=>Ur(l,{host:y.host||"",repo:y.repo||"",severity:"any"})})})]})]}):r.jsx(ji,{feature:"metrics",children:"Longer periods, trends, breakdowns by repository and category, and the CSV/JSON export are part of the licensed console. The numbers above cover the last 30 days."})]}):r.jsx(qe,{children:"Loading…"}),r.jsx(He,{children:"Read from this console's own database; nothing leaves the installation. Findings are what reviews reported (questions aren't counted). Time to first review runs from the webhook to the first review's comments, including the wait after a push. Findings acted on (fixed or resolved versus dismissed) needs signals from the code host and isn't tracked yet. Periods are whole UTC days or months; reviews stored before this version are counted from their saved results."})]})}function SR(t){if(t.range==="all")return"Everything recorded (UTC)";const o=t.granularity==="month"?Mk:Ok;return o(t.from)+" – "+o(t.through)+" (UTC)"}const Mf=[{path:"setup",title:"Setup",icon:yk,el:r.jsx(kR,{})},{path:"repositories",title:"Repositories",icon:uk,el:r.jsx(N2,{})},{path:"reviews",title:"Reviews",icon:sk,el:r.jsx(M2,{})},{path:"impact",title:"Impact",icon:Sk,el:r.jsx(CR,{})},{path:"learnings",title:"Learnings",icon:rk,el:r.jsx(I2,{}),paid:"learnings"},{path:"hosts",title:"Code hosts",icon:bk,el:r.jsx(V2,{})},{path:"models",title:"Models",icon:ok,el:r.jsx(gR,{})},{path:"executor",title:"Executor",icon:lk,el:r.jsx(bR,{})},{path:"rules",title:"Rules",icon:dk,el:r.jsx(q2,{}),paid:"rules"},{path:"webhooks",title:"Webhooks",icon:Vv,el:r.jsx(Q2,{})},{path:"settings",title:"Settings",icon:kk,el:r.jsx(rR,{})},{path:"change-requests",title:"Change requests",icon:ak,el:r.jsx(lR,{})},{path:"audit",title:"Audit log",icon:wk,el:r.jsx(iR,{}),paid:"audit"},{path:"license",title:"License",icon:bv,el:r.jsx(uR,{})}];function _R({me:t}){const o=t.expiry_warnings||[];if(!o.length)return null;const s=o.some(a=>a.severity==="bad");return r.jsx(Zn,{role:"status",variant:s?"destructive":"default",className:s?"banner bad":"banner border-warning/40 bg-warning-soft text-warning",children:r.jsx(er,{className:s?"":"text-warning",children:o.map(a=>r.jsxs("p",{children:[a.message," ",r.jsx(Yt,{className:"font-semibold underline underline-offset-2",to:a.kind==="license"?"/license":"/hosts",children:a.kind==="license"?"License":"Code hosts"})]},a.kind+(a.host_id||"")))})})}function NR({me:t}){const o=t.license;return t.reviews_paused?r.jsx(Zn,{role:"status",variant:"destructive",className:"banner bad",children:r.jsx(er,{children:r.jsxs("p",{children:[t.reviews_paused[0].toUpperCase()+t.reviews_paused.slice(1),"."," ",r.jsx(Yt,{className:"font-semibold underline underline-offset-2",to:"/license",children:"Add a license"})]})})}):o.state==="grace"?r.jsx(Zn,{role:"status",className:"banner border-warning/40 bg-warning-soft text-warning",children:r.jsx(er,{className:"text-warning",children:r.jsxs("p",{children:["The Divmora license expired on ",di(o.expires_at),". Paid features stop on ",di(o.grace_until),"."," ",r.jsx(Yt,{className:"font-semibold underline underline-offset-2",to:"/license",children:"Renew"})]})})}):o.state==="expired"||o.state==="invalid"?r.jsx(Zn,{role:"status",variant:"destructive",className:"banner bad",children:r.jsx(er,{children:r.jsxs("p",{children:[o.state==="expired"?"The Divmora license has expired":"The Divmora license is not valid",": paid features are off."," ",r.jsx(Yt,{className:"font-semibold underline underline-offset-2",to:"/license",children:"License"})]})})}):null}function ER(){const[t,o]=m.useState(()=>{try{return localStorage.getItem("crc-theme")||"system"}catch{return"system"}}),s=l=>{o(l);try{localStorage.setItem("crc-theme",l)}catch{}const u=window.__crcApplyTheme;u?u():document.documentElement.classList.toggle("dark",l==="dark")},a=t==="light"?Ck:t==="dark"?mk:pk;return r.jsxs(GE,{children:[r.jsx(KE,{asChild:!0,children:r.jsx(re,{variant:"ghost",size:"icon",id:"theme","aria-label":"Theme",children:r.jsx(a,{})})}),r.jsxs(qE,{align:"end",children:[r.jsx(QE,{children:"Theme"}),r.jsx(XE,{}),r.jsxs(YE,{value:t,onValueChange:s,children:[r.jsx($u,{value:"system",children:"System"}),r.jsx($u,{value:"light",children:"Light"}),r.jsx($u,{value:"dark",children:"Dark"})]})]})]})}function Tw(t){return Mf.find(o=>t.startsWith("/"+o.path))}function RR({me:t}){const o=In(),{setOpenMobile:s}=ki(),a=()=>Qt("/admin/logout").finally(()=>location.href="/admin/login");return r.jsxs(c2,{collapsible:"icon",children:[r.jsx(h2,{children:r.jsxs("div",{className:"flex items-center gap-2 px-1 py-1.5",children:[r.jsx(y2,{}),r.jsxs("div",{className:"grid leading-tight group-data-[collapsible=icon]:hidden",children:[r.jsx("span",{className:"truncate text-sm font-semibold",children:"Code review"}),r.jsx("span",{className:"truncate text-xs text-muted-foreground",children:"Divmora console"})]})]})}),r.jsx(m2,{children:r.jsx(g2,{children:r.jsx(v2,{children:r.jsx(Rg,{className:"side","aria-label":"Sections",children:Mf.filter(l=>l.path!=="change-requests"||t.role==="operator"||t.role==="admin"&&(t.license.features.includes("sso_rules")||!!t.pending_approvals)).map(l=>{var h;const u=l.paid&&!t.license.features.includes(l.paid),d=((h=Tw(o.pathname))==null?void 0:h.path)===l.path;return r.jsxs(Pg,{children:[r.jsx(Tg,{asChild:!0,isActive:d,tooltip:l.title,children:r.jsxs(Fj,{to:"/"+l.path,className:d?"on":"",onClick:()=>s(!1),children:[r.jsx(l.icon,{}),r.jsx("span",{children:l.title})]})}),l.path==="setup"&&t.setup&&!t.setup.complete&&r.jsx(Bu,{className:"text-[10px] font-normal text-muted-foreground",title:"Setup steps done",children:r.jsxs("span",{title:`${t.setup.done} of ${t.setup.total} required setup steps done`,children:[t.setup.done,"/",t.setup.total]})}),l.path==="change-requests"&&!!t.pending_approvals&&r.jsx(Bu,{className:"text-[10px]",title:t.pending_approvals+" waiting for an admin",children:t.pending_approvals}),u&&r.jsx(Bu,{className:"paid text-[10px] font-normal text-muted-foreground",title:"Needs a license",children:"licensed"})]},l.path)})})})})}),r.jsxs(p2,{children:[r.jsxs("div",{className:"grid gap-1 px-2 pb-1 text-xs text-muted-foreground group-data-[collapsible=icon]:hidden",children:[r.jsxs("span",{className:"truncate",children:["Signed in as ",t.name||t.email]}),r.jsx("a",{className:"underline-offset-2 hover:text-foreground hover:underline",href:"/admin/dashboard",children:"Status dashboard"}),t.version&&r.jsxs("span",{children:["Version ",t.version]})]}),r.jsx(Rg,{children:r.jsx(Pg,{children:r.jsxs(Tg,{id:"logout",onClick:a,tooltip:"Sign out",children:[r.jsx(fk,{}),r.jsx("span",{children:"Sign out"})]})})})]}),r.jsx(d2,{})]})}function PR(){const t=In();return r.jsxs(lt,{className:"max-w-xl",children:[r.jsxs(cn,{children:[r.jsx(yn,{className:"h2",children:"Page not found"}),r.jsxs(wn,{children:["There is no ",r.jsxs("code",{children:["/admin",t.pathname]})," page. Pick a section in the sidebar, or go to the start."]})]}),r.jsx(Pt,{children:r.jsx(re,{asChild:!0,children:r.jsx(Yt,{to:"/",children:"Go to the start"})})})]})}function TR(){const t=()=>Qt("/admin/logout").finally(()=>location.href="/admin/login");return r.jsxs(lt,{className:"max-w-xl",children:[r.jsxs(cn,{children:[r.jsx(yn,{className:"h2",children:"Sign out?"}),r.jsx(wn,{children:"You'll need to sign in again to use the admin panel."})]}),r.jsxs(Pt,{className:"flex gap-2",children:[r.jsx(re,{onClick:t,children:"Sign out"}),r.jsx(re,{asChild:!0,variant:"outline",children:r.jsx(Yt,{to:"/",children:"Stay signed in"})})]})]})}function DR({me:t}){const o=In(),s=Tw(o.pathname),a=(s==null?void 0:s.title)??(o.pathname==="/logout"?"Sign out":"Page not found");return m.useEffect(()=>{document.title=a+" · Code review admin"},[a]),r.jsxs("header",{className:"sticky top-0 z-10 flex h-14 shrink-0 items-center gap-2 border-b bg-background/80 px-4 backdrop-blur",children:[r.jsx(u2,{className:"-ml-1"}),r.jsx(cs,{orientation:"vertical",className:"mr-1 data-[orientation=vertical]:h-4"}),r.jsx("h1",{id:"pageTitle",className:"text-base font-semibold",children:a}),(s==null?void 0:s.paid)&&!t.license.features.includes(s.paid)&&r.jsx(Tt,{variant:"secondary",children:"licensed"}),r.jsx("span",{className:"flex-1"}),r.jsx(ER,{})]})}function OR(){const[t,o]=m.useState(null),[s,a]=m.useState(""),l=()=>Ke("/admin/api/me").then(u=>{_k(u.csrf),o(u)}).catch(u=>a(String(u.message||u)));return m.useEffect(()=>{l();const u=()=>l();return window.addEventListener("crc-pending",u),()=>window.removeEventListener("crc-pending",u)},[]),t?r.jsx(yw.Provider,{value:t,children:r.jsx(ww.Provider,{value:l,children:r.jsx(kw,{delayDuration:300,children:r.jsx(WE,{children:r.jsx(VE,{children:r.jsxs(l2,{children:[r.jsx(RR,{me:t}),r.jsxs(f2,{className:"min-w-0",children:[r.jsx(DR,{me:t}),r.jsxs("div",{className:"mx-auto grid w-full max-w-7xl gap-4 p-4 md:p-6",children:[r.jsx(NR,{me:t}),r.jsx(_R,{me:t}),t.role==="viewer"&&r.jsx(Zn,{role:"status",className:"banner",children:r.jsx(er,{children:"You have read-only access: you can see every page, and changes are refused. Ask an admin to change something."})}),r.jsxs(Nj,{children:[r.jsx(os,{path:"/",element:r.jsx(Bm,{to:t.setup&&!t.setup.complete?"/setup":"/repositories",replace:!0})}),Mf.map(u=>r.jsx(os,{path:"/"+u.path,element:r.jsx(jd,{name:u.title,children:u.el},u.path)},u.path)),r.jsx(os,{path:"/approvals",element:r.jsx(Bm,{to:"/change-requests",replace:!0})}),r.jsx(os,{path:"/logout",element:r.jsx(TR,{})}),r.jsx(os,{path:"*",element:r.jsx(PR,{})})]})]})]})]})})})})})}):r.jsx("div",{className:"grid min-h-svh place-items-center text-sm text-muted-foreground",children:s||"Loading…"})}var Hg;const Ku=(Hg=document.querySelector('meta[name="csp-nonce"]'))==null?void 0:Hg.content;Ku&&!Ku.startsWith("__")&&Vj(Ku);zb.createRoot(document.getElementById("root")).render(r.jsx(m.StrictMode,{children:r.jsx(Lj,{basename:"/admin",children:r.jsx(OR,{})})})); diff --git a/internal/admin/ui/index.html b/internal/admin/ui/index.html index 8b8009a..20879a9 100644 --- a/internal/admin/ui/index.html +++ b/internal/admin/ui/index.html @@ -9,7 +9,7 @@ - + diff --git a/internal/executor/executor.go b/internal/executor/executor.go index 696a5c1..405d99d 100644 --- a/internal/executor/executor.go +++ b/internal/executor/executor.go @@ -123,9 +123,9 @@ func Args(t Task) ([]string, error) { } if a := t.Approval; a != nil { args = append(args, "--approve", "--approve-block", firstNonEmpty(a.Block, "none"), "--approve-min-score", strconv.Itoa(a.MinScore)) - if a.Withdraw { - args = append(args, "--approve-withdraw") - } + // Always explicit: the CLI's default changed to on in 0.6, so + // "leave it" must say =false (older CLIs accept that too). + args = append(args, "--approve-withdraw="+strconv.FormatBool(a.Withdraw)) } return args, nil case "validate": diff --git a/internal/executor/executor_test.go b/internal/executor/executor_test.go index 8ac9803..fcf1f3d 100644 --- a/internal/executor/executor_test.go +++ b/internal/executor/executor_test.go @@ -164,12 +164,12 @@ func TestArgsPostingFlags(t *testing.T) { func TestArgsApproval(t *testing.T) { args, _ := Args(Task{Kind: "review", URL: "u", Post: true, Approval: &Approval{Block: "major", MinScore: 80, Withdraw: true}}) - if got := strings.Join(args, " "); !strings.Contains(got, "--approve --approve-block major --approve-min-score 80 --approve-withdraw") { + if got := strings.Join(args, " "); !strings.Contains(got, "--approve --approve-block major --approve-min-score 80 --approve-withdraw=true") { t.Errorf("approval flags: %s", got) } args, _ = Args(Task{Kind: "review", URL: "u", Post: true, Approval: &Approval{}}) - if got := strings.Join(args, " "); !strings.Contains(got, "--approve-block none --approve-min-score 0") || strings.Contains(got, "--approve-withdraw") { - t.Errorf("approve whatever was found, without withdrawing: %s", got) + if got := strings.Join(args, " "); !strings.Contains(got, "--approve-block none --approve-min-score 0 --approve-withdraw=false") { + t.Errorf("approve whatever was found, without withdrawing (explicit: the CLI's default is on): %s", got) } args, _ = Args(Task{Kind: "review", URL: "u", Post: true}) if strings.Contains(strings.Join(args, " "), "--approve") { diff --git a/web/src/pages/Settings.tsx b/web/src/pages/Settings.tsx index 4500ef9..4b85327 100644 --- a/web/src/pages/Settings.tsx +++ b/web/src/pages/Settings.tsx @@ -226,7 +226,7 @@ export default function Settings() { Every score (quality, security, maintainability) must be at least this. 0 ignores the scores.} /> - A partial or too-large review leaves the approval as it is. GitLab: the bot's user must be allowed to approve. GitHub: withdrawing dismisses the bot's review, which branch protection may restrict. + With withdrawing on, a review that can't judge a new commit (partial, too large) also withdraws the approval (CLI 0.6 or later). GitLab: the bot's user must be allowed to approve. GitHub: withdrawing dismisses the bot's review, which branch protection may restrict. From 2cc49a65037329be3456b01dea2011c5d77481ca Mon Sep 17 00:00:00 2001 From: Nitin Goyal Date: Mon, 23 Nov 2026 20:10:16 +0530 Subject: [PATCH 2/2] docs: resolve the merge in admin.md Co-Authored-By: Claude Opus 5.5 --- docs/admin.md | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/docs/admin.md b/docs/admin.md index 05bde0d..c2b6e96 100644 --- a/docs/admin.md +++ b/docs/admin.md @@ -99,13 +99,8 @@ once to the approving admin. 5. **Executor** shows where reviews run (from the config file, read-only) and manages the review image's version, resources and, for Kubernetes, scheduling, pod labels and annotations, the CA bundle and the job TTL. Changes apply to the next review. See [deploy.md](deploy.md#settings-in-the-admin-panel). 6. **Settings → Admin sessions → Sign out after inactivity** ends a session that has made no request for that long (60 minutes by default, 0 for never; the panel's own refreshes don't count), recorded as `session.ended` with reason `idle`. **Settings → Signed-in admins** lists every admin session. Sign one out, or **Sign out everyone else** (after offboarding someone, or if a session may be compromised). Every request is also checked against the current sign-in rules and license, so an admin removed from `allowed_emails`, `allowed_domains` or `allowed_groups` (after the restart that applies the change) is signed out at once. Group membership comes from the identity provider at sign-in: a group removed there applies when the session ends (`session_ttl`) or when you sign the session out here. 7. **Review scores.** Every review the CLI scores (quality, security, maintainability, 1 to 100) keeps its scores, whether or not score labels are on. **Reviews** shows them per review, banded like the labels (80 and up, 50 to 79, below 50), filters by them ("security below 60" searches all reviews) and sorts the loaded reviews by them. With the metrics feature, it also shows the period's average scores and a trend chart; **Repositories** shows each repository's latest scores with a 30-day sparkline, and a repository's **Settings** panel charts its scores over 30 days, 12 months or all its history. Reviews stored before the upgrade get their scores from the stored result. The filters, sort, chart period and the open review are kept in the address (for example `/admin/reviews?score_kind=security&score_below=60&sort=security`, with the same names as `/admin/api/reviews`), so a reload or Back keeps the view and a filtered view can be bookmarked or shared. A review that approved the merge request on the code host is marked **✓ approved** on Reviews and on the status dashboard (or **approval withdrawn** / **approval failed**), and Reviews filters by it (`approval=approved`); this is the bot approving merge requests, set under Settings, not operator change requests. -<<<<<<< HEAD -8. **Approve merge requests** (Settings) has the bot approve a merge request whose review passes, as its token's user (or the GitHub App). Choose which findings block approval (critical; major or critical, the default; minor or above; any finding; or none, to approve whatever it found), an optional lowest score for all three scores, and whether a later review that doesn't pass withdraws the bot's approval (on by default) or leaves it. New findings, ones beyond the comment limit and ones still open from an earlier review count; questions don't. A review that can't decide (partial, too large) of a new commit also withdraws the bot's approval when withdrawing is on (code-review-bot 0.6 or later), so an approval never carries over to code that wasn't fully reviewed; a re-review of the same commit leaves it. The console always tells the CLI which you chose. **Rules** turn approval on or off for a host, group or pattern (**Approve MRs**), and **Repositories** shows where it applies. A review's details show what happened ("approved", "withdrawn", "not approved"…), and a refusal from the code host shows on the review as "could not approve". It needs code-review-bot 0.5 or later (the CLI version on **Executor**). On GitLab the bot's user must be allowed to approve and can't approve its own merge requests; on GitHub, withdrawing dismisses the bot's review, which branch protection can restrict. -9. **Impact** shows what the console has done for this installation, from its own database only (nothing leaves it): merge requests reviewed and review runs, findings raised by severity, security findings, the median time to first review (from the webhook to the first review's comments, including the wait after a push), active repositories, comments posted and average scores. Questions aren't counted as findings. The last 30 days are free; with the metrics feature, choose 90 days, 12 months or all history, see the trends, findings by category, the top repositories by reviews and by findings, and **Export CSV** or **Export JSON** for reports (exports are audited as `impact.export`). Periods are whole UTC days or months. The numbers come from rollups kept for good, like the review charts; on upgrade they are filled in from the reviews still stored. **Approvals by the bot** counts merge requests the bot approved on the code host (a review that approved; one already approved isn't counted again), and is in the exports as `approvals_by_the_bot`. The numbers link to **Reviews** with the matching filters and period: merge requests reviewed, findings raised (`severity=any`), security findings (`category=security`), each severity and category, and each top repository. Reviews can also be filtered by finding severity and category directly; `/admin/api/reviews` takes `severity` (or `any`) and `category`, counted the way Impact counts them (questions aren't findings). How many findings were acted on (fixed, resolved or dismissed) isn't tracked yet and isn't shown. Periods are whole UTC days or months; the label ends on the last day (or month) included, and the API and exports give that day as `through` next to the exclusive end (`to`, `to_exclusive` in the CSV). -======= -8. **Approve merge requests** (Settings) has the bot approve a merge request whose review passes, as its token's user (or the GitHub App). Choose which findings block approval (critical; major or critical, the default; minor or above; any finding; or none, to approve whatever it found), an optional lowest score for all three scores, and whether a later review that doesn't pass withdraws the bot's approval (on by default) or leaves it. New findings, ones beyond the comment limit and ones still open from an earlier review count; questions don't. A partial or too-large review leaves the approval as it is. **Rules** turn approval on or off for a host, group or pattern (**Approve MRs**), and **Repositories** shows where it applies. A review's details show what happened ("approved", "withdrawn", "not approved"…), and a refusal from the code host shows on the review as "could not approve". It needs code-review-bot 0.5 or later (the CLI version on **Executor**). On GitLab the bot's user must be allowed to approve and can't approve its own merge requests; on GitHub, withdrawing dismisses the bot's review, which branch protection can restrict. -9. **Impact** shows what the console has done for this installation, from its own database only (nothing leaves it): merge requests reviewed and review runs, findings raised by severity, security findings, the median time to first review (from the webhook to the first review's comments, including the wait after a push), active repositories, comments posted and average scores. Questions aren't counted as findings. The last 30 days are free; with the metrics feature, choose 90 days, 12 months or all history, see the trends, findings by category, the top repositories by reviews and by findings, and **Export CSV** or **Export JSON** for reports (exports are audited as `impact.export`). Periods are whole UTC days or months; the label ends on the last day (or month) included, and the API and exports give that day as `through` next to the exclusive end (`to`, `to_exclusive` in the CSV). The numbers come from rollups kept for good, like the review charts; on upgrade they are filled in from the reviews still stored. How many findings were acted on (fixed, resolved or dismissed) isn't tracked yet and isn't shown. Periods are whole UTC days or months. The numbers link to **Reviews** with the matching filters and period: merge requests reviewed, findings raised (`severity=any`), security findings (`category=security`), each severity and category, and each top repository. Reviews can also be filtered by finding severity and category directly; `/admin/api/reviews` takes `severity` (or `any`) and `category`, counted the way Impact counts them (questions aren't findings). **Approvals by the bot** counts merge requests the bot approved on the code host (a review that approved; one already approved isn't counted again), and is in the exports as `approvals_by_the_bot`. ->>>>>>> origin/main +8. **Approve merge requests** (Settings) has the bot approve a merge request whose review passes, as its token's user (or the GitHub App). Choose which findings block approval (critical; major or critical, the default; minor or above; any finding; or none, to approve whatever it found), an optional lowest score for all three scores, and whether a later review that doesn't pass withdraws the bot's approval (on by default) or leaves it. New findings, ones beyond the comment limit and ones still open from an earlier review count; questions don't. A review that can't decide (partial, too large) of a new commit also withdraws the bot's approval when withdrawing is on (code-review-bot 0.6 or later), so an approval never carries over to code that wasn't fully reviewed; a re-review of the same commit leaves it. The console always tells the CLI which you chose. **Rules** turn approval on or off for a host, group or pattern (**Approve MRs**), and **Repositories** shows where it applies. A review's details show what happened ("approved", "withdrawn", "not approved"…), and a refusal from the code host shows on the review as "could not approve". It needs code-review-bot 0.5 or later (the CLI version on **Executor**). On GitLab the bot's user must be allowed to approve and can't approve its own merge requests; on GitHub, withdrawing dismisses the bot's review, which branch protection can restrict. A partial or too-large review leaves the approval as it is. +9. **Impact** shows what the console has done for this installation, from its own database only (nothing leaves it): merge requests reviewed and review runs, findings raised by severity, security findings, the median time to first review (from the webhook to the first review's comments, including the wait after a push), active repositories, comments posted and average scores. Questions aren't counted as findings. The last 30 days are free; with the metrics feature, choose 90 days, 12 months or all history, see the trends, findings by category, the top repositories by reviews and by findings, and **Export CSV** or **Export JSON** for reports (exports are audited as `impact.export`). Periods are whole UTC days or months. The numbers come from rollups kept for good, like the review charts; on upgrade they are filled in from the reviews still stored. **Approvals by the bot** counts merge requests the bot approved on the code host (a review that approved; one already approved isn't counted again), and is in the exports as `approvals_by_the_bot`. The numbers link to **Reviews** with the matching filters and period: merge requests reviewed, findings raised (`severity=any`), security findings (`category=security`), each severity and category, and each top repository. Reviews can also be filtered by finding severity and category directly; `/admin/api/reviews` takes `severity` (or `any`) and `category`, counted the way Impact counts them (questions aren't findings). How many findings were acted on (fixed, resolved or dismissed) isn't tracked yet and isn't shown. Periods are whole UTC days or months; the label ends on the last day (or month) included, and the API and exports give that day as `through` next to the exclusive end (`to`, `to_exclusive` in the CSV). 10. **Webhooks** shows every delivery. A delivery whose body was already received (a retry, an event arriving through two GitLab hooks, a replay) shows as a duplicate and is not processed again, for 7 days. Redelivering an old webhook from the code host therefore does nothing; use **Review now** on the Repositories page instead. The project and outcome filters are kept in the address. 11. **Audit log** lists sign-ins, denied sign-ins, sign-outs and every change, newest first, with who made it and from which address and browser. Each change shows only the fields that changed (old → new), with the raw entry one click away; secret changes are named without their values (`token:changed`, `signing_tokens:+1`). Filter by who, action (`host.*` matches every host action), target, a text search and dates; **Older entries** pages back through everything, and **Export CSV** or **Export JSON Lines** downloads the filtered view (up to 100,000 entries; exports are audited too). Times are shown as `23 Nov 2026, 09:33:38 IST` in your browser's time zone, with UTC on hover. The applied filter is kept in the address (`/admin/audit?action=host.*`). 12. **Unsaved changes.** On **Settings**, edited cards are marked **Unsaved**, and a bar at the bottom of the window lists what isn't saved yet (the settings, the default review settings, the queue and review settings) with **Save** and **Discard**. Leaving the page or following a link asks first. If the session ended before you save, the changes stay on the page: sign in again in the new tab it offers, come back and save.