(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,66027,54616,e=>{"use strict";let t;var s=e.i(75555),r=e.i(40143),i=e.i(86491),n=e.i(15823),a=e.i(93803),o=e.i(19273),u=e.i(80166),l=class extends n.Subscribable{constructor(e,t){super(),this.options=t,this.#e=e,this.#t=null,this.#s=(0,a.pendingThenable)(),this.bindMethods(),this.setOptions(t)}#e;#r=void 0;#i=void 0;#n=void 0;#a;#o;#s;#t;#u;#l;#c;#h;#d;#p;#f=new Set;bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){1===this.listeners.size&&(this.#r.addObserver(this),c(this.#r,this.options)?this.#m():this.updateResult(),this.#y())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return h(this.#r,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return h(this.#r,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#b(),this.#x(),this.#r.removeObserver(this)}setOptions(e){let t=this.options,s=this.#r;if(this.options=this.#e.defaultQueryOptions(e),void 0!==this.options.enabled&&"boolean"!=typeof this.options.enabled&&"function"!=typeof this.options.enabled&&"boolean"!=typeof(0,o.resolveEnabled)(this.options.enabled,this.#r))throw Error("Expected enabled to be a boolean or a callback that returns a boolean");this.#v(),this.#r.setOptions(this.options),t._defaulted&&!(0,o.shallowEqualObjects)(this.options,t)&&this.#e.getQueryCache().notify({type:"observerOptionsUpdated",query:this.#r,observer:this});let r=this.hasListeners();r&&d(this.#r,s,this.options,t)&&this.#m(),this.updateResult(),r&&(this.#r!==s||(0,o.resolveEnabled)(this.options.enabled,this.#r)!==(0,o.resolveEnabled)(t.enabled,this.#r)||(0,o.resolveStaleTime)(this.options.staleTime,this.#r)!==(0,o.resolveStaleTime)(t.staleTime,this.#r))&&this.#R();let i=this.#g();r&&(this.#r!==s||(0,o.resolveEnabled)(this.options.enabled,this.#r)!==(0,o.resolveEnabled)(t.enabled,this.#r)||i!==this.#p)&&this.#O(i)}getOptimisticResult(e){var t,s;let r=this.#e.getQueryCache().build(this.#e,e),i=this.createResult(r,e);return t=this,s=i,(0,o.shallowEqualObjects)(t.getCurrentResult(),s)||(this.#n=i,this.#o=this.options,this.#a=this.#r.state),i}getCurrentResult(){return this.#n}trackResult(e,t){return new Proxy(e,{get:(e,s)=>(this.trackProp(s),t?.(s),"promise"===s&&(this.trackProp("data"),this.options.experimental_prefetchInRender||"pending"!==this.#s.status||this.#s.reject(Error("experimental_prefetchInRender feature flag is not enabled"))),Reflect.get(e,s))})}trackProp(e){this.#f.add(e)}getCurrentQuery(){return this.#r}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){let t=this.#e.defaultQueryOptions(e),s=this.#e.getQueryCache().build(this.#e,t);return s.fetch().then(()=>this.createResult(s,t))}fetch(e){return this.#m({...e,cancelRefetch:e.cancelRefetch??!0}).then(()=>(this.updateResult(),this.#n))}#m(e){this.#v();let t=this.#r.fetch(this.options,e);return e?.throwOnError||(t=t.catch(o.noop)),t}#R(){this.#b();let e=(0,o.resolveStaleTime)(this.options.staleTime,this.#r);if(o.isServer||this.#n.isStale||!(0,o.isValidTimeout)(e))return;let t=(0,o.timeUntilStale)(this.#n.dataUpdatedAt,e);this.#h=u.timeoutManager.setTimeout(()=>{this.#n.isStale||this.updateResult()},t+1)}#g(){return("function"==typeof this.options.refetchInterval?this.options.refetchInterval(this.#r):this.options.refetchInterval)??!1}#O(e){this.#x(),this.#p=e,!o.isServer&&!1!==(0,o.resolveEnabled)(this.options.enabled,this.#r)&&(0,o.isValidTimeout)(this.#p)&&0!==this.#p&&(this.#d=u.timeoutManager.setInterval(()=>{(this.options.refetchIntervalInBackground||s.focusManager.isFocused())&&this.#m()},this.#p))}#y(){this.#R(),this.#O(this.#g())}#b(){this.#h&&(u.timeoutManager.clearTimeout(this.#h),this.#h=void 0)}#x(){this.#d&&(u.timeoutManager.clearInterval(this.#d),this.#d=void 0)}createResult(e,t){let s,r=this.#r,n=this.options,u=this.#n,l=this.#a,h=this.#o,f=e!==r?e.state:this.#i,{state:m}=e,y={...m},b=!1;if(t._optimisticResults){let s=this.hasListeners(),a=!s&&c(e,t),o=s&&d(e,r,t,n);(a||o)&&(y={...y,...(0,i.fetchState)(m.data,e.options)}),"isRestoring"===t._optimisticResults&&(y.fetchStatus="idle")}let{error:x,errorUpdatedAt:v,status:R}=y;s=y.data;let g=!1;if(void 0!==t.placeholderData&&void 0===s&&"pending"===R){let e;u?.isPlaceholderData&&t.placeholderData===h?.placeholderData?(e=u.data,g=!0):e="function"==typeof t.placeholderData?t.placeholderData(this.#c?.state.data,this.#c):t.placeholderData,void 0!==e&&(R="success",s=(0,o.replaceData)(u?.data,e,t),b=!0)}if(t.select&&void 0!==s&&!g)if(u&&s===l?.data&&t.select===this.#u)s=this.#l;else try{this.#u=t.select,s=t.select(s),s=(0,o.replaceData)(u?.data,s,t),this.#l=s,this.#t=null}catch(e){this.#t=e}this.#t&&(x=this.#t,s=this.#l,v=Date.now(),R="error");let O="fetching"===y.fetchStatus,Q="pending"===R,S="error"===R,T=Q&&O,E=void 0!==s,C={status:R,fetchStatus:y.fetchStatus,isPending:Q,isSuccess:"success"===R,isError:S,isInitialLoading:T,isLoading:T,data:s,dataUpdatedAt:y.dataUpdatedAt,error:x,errorUpdatedAt:v,failureCount:y.fetchFailureCount,failureReason:y.fetchFailureReason,errorUpdateCount:y.errorUpdateCount,isFetched:y.dataUpdateCount>0||y.errorUpdateCount>0,isFetchedAfterMount:y.dataUpdateCount>f.dataUpdateCount||y.errorUpdateCount>f.errorUpdateCount,isFetching:O,isRefetching:O&&!Q,isLoadingError:S&&!E,isPaused:"paused"===y.fetchStatus,isPlaceholderData:b,isRefetchError:S&&E,isStale:p(e,t),refetch:this.refetch,promise:this.#s,isEnabled:!1!==(0,o.resolveEnabled)(t.enabled,e)};if(this.options.experimental_prefetchInRender){let t=void 0!==C.data,s="error"===C.status&&!t,i=e=>{s?e.reject(C.error):t&&e.resolve(C.data)},n=()=>{i(this.#s=C.promise=(0,a.pendingThenable)())},o=this.#s;switch(o.status){case"pending":e.queryHash===r.queryHash&&i(o);break;case"fulfilled":(s||C.data!==o.value)&&n();break;case"rejected":s&&C.error===o.reason||n()}}return C}updateResult(){let e=this.#n,t=this.createResult(this.#r,this.options);if(this.#a=this.#r.state,this.#o=this.options,void 0!==this.#a.data&&(this.#c=this.#r),(0,o.shallowEqualObjects)(t,e))return;this.#n=t;let s=()=>{if(!e)return!0;let{notifyOnChangeProps:t}=this.options,s="function"==typeof t?t():t;if("all"===s||!s&&!this.#f.size)return!0;let r=new Set(s??this.#f);return this.options.throwOnError&&r.add("error"),Object.keys(this.#n).some(t=>this.#n[t]!==e[t]&&r.has(t))};this.#Q({listeners:s()})}#v(){let e=this.#e.getQueryCache().build(this.#e,this.options);if(e===this.#r)return;let t=this.#r;this.#r=e,this.#i=e.state,this.hasListeners()&&(t?.removeObserver(this),e.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#y()}#Q(e){r.notifyManager.batch(()=>{e.listeners&&this.listeners.forEach(e=>{e(this.#n)}),this.#e.getQueryCache().notify({query:this.#r,type:"observerResultsUpdated"})})}};function c(e,t){return!1!==(0,o.resolveEnabled)(t.enabled,e)&&void 0===e.state.data&&("error"!==e.state.status||!1!==t.retryOnMount)||void 0!==e.state.data&&h(e,t,t.refetchOnMount)}function h(e,t,s){if(!1!==(0,o.resolveEnabled)(t.enabled,e)&&"static"!==(0,o.resolveStaleTime)(t.staleTime,e)){let r="function"==typeof s?s(e):s;return"always"===r||!1!==r&&p(e,t)}return!1}function d(e,t,s,r){return(e!==t||!1===(0,o.resolveEnabled)(r.enabled,e))&&(!s.suspense||"error"!==e.state.status)&&p(e,s)}function p(e,t){return!1!==(0,o.resolveEnabled)(t.enabled,e)&&e.isStaleByTime((0,o.resolveStaleTime)(t.staleTime,e))}e.i(47167);var f=e.i(71645),m=e.i(12598);e.i(43476);var y=f.createContext((t=!1,{clearReset:()=>{t=!1},reset:()=>{t=!0},isReset:()=>t})),b=f.createContext(!1);b.Provider;var x=(e,t,s)=>t.fetchOptimistic(e).catch(()=>{s.clearReset()});function v(e,t){return function(e,t,s){let i,n=f.useContext(b),a=f.useContext(y),u=(0,m.useQueryClient)(s),l=u.defaultQueryOptions(e);u.getDefaultOptions().queries?._experimental_beforeQuery?.(l);let c=u.getQueryCache().get(l.queryHash);if(l._optimisticResults=n?"isRestoring":"optimistic",l.suspense){let e=e=>"static"===e?e:Math.max(e??1e3,1e3),t=l.staleTime;l.staleTime="function"==typeof t?(...s)=>e(t(...s)):e(t),"number"==typeof l.gcTime&&(l.gcTime=Math.max(l.gcTime,1e3))}i=c?.state.error&&"function"==typeof l.throwOnError?(0,o.shouldThrowError)(l.throwOnError,[c.state.error,c]):l.throwOnError,(l.suspense||l.experimental_prefetchInRender||i)&&!a.isReset()&&(l.retryOnMount=!1),f.useEffect(()=>{a.clearReset()},[a]);let h=!u.getQueryCache().get(l.queryHash),[d]=f.useState(()=>new t(u,l)),p=d.getOptimisticResult(l),v=!n&&!1!==e.subscribed;if(f.useSyncExternalStore(f.useCallback(e=>{let t=v?d.subscribe(r.notifyManager.batchCalls(e)):o.noop;return d.updateResult(),t},[d,v]),()=>d.getCurrentResult(),()=>d.getCurrentResult()),f.useEffect(()=>{d.setOptions(l)},[l,d]),l?.suspense&&p.isPending)throw x(l,d,a);if((({result:e,errorResetBoundary:t,throwOnError:s,query:r,suspense:i})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(i&&void 0===e.data||(0,o.shouldThrowError)(s,[e.error,r])))({result:p,errorResetBoundary:a,throwOnError:l.throwOnError,query:c,suspense:l.suspense}))throw p.error;if(u.getDefaultOptions().queries?._experimental_afterQuery?.(l,p),l.experimental_prefetchInRender&&!o.isServer&&p.isLoading&&p.isFetching&&!n){let e=h?x(l,d,a):c?.promise;e?.catch(o.noop).finally(()=>{d.updateResult()})}return l.notifyOnChangeProps?p:d.trackResult(p)}(e,l,t)}e.s(["useQuery",()=>v],66027);var R=e.i(14272),g=n,O=class extends g.Subscribable{#e;#n=void 0;#S;#T;constructor(e,t){super(),this.#e=e,this.setOptions(t),this.bindMethods(),this.#E()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(e){let t=this.options;this.options=this.#e.defaultMutationOptions(e),(0,o.shallowEqualObjects)(this.options,t)||this.#e.getMutationCache().notify({type:"observerOptionsUpdated",mutation:this.#S,observer:this}),t?.mutationKey&&this.options.mutationKey&&(0,o.hashKey)(t.mutationKey)!==(0,o.hashKey)(this.options.mutationKey)?this.reset():this.#S?.state.status==="pending"&&this.#S.setOptions(this.options)}onUnsubscribe(){this.hasListeners()||this.#S?.removeObserver(this)}onMutationUpdate(e){this.#E(),this.#Q(e)}getCurrentResult(){return this.#n}reset(){this.#S?.removeObserver(this),this.#S=void 0,this.#E(),this.#Q()}mutate(e,t){return this.#T=t,this.#S?.removeObserver(this),this.#S=this.#e.getMutationCache().build(this.#e,this.options),this.#S.addObserver(this),this.#S.execute(e)}#E(){let e=this.#S?.state??(0,R.getDefaultState)();this.#n={...e,isPending:"pending"===e.status,isSuccess:"success"===e.status,isError:"error"===e.status,isIdle:"idle"===e.status,mutate:this.mutate,reset:this.reset}}#Q(e){r.notifyManager.batch(()=>{if(this.#T&&this.hasListeners()){let t=this.#n.variables,s=this.#n.context,r={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey};if(e?.type==="success"){try{this.#T.onSuccess?.(e.data,t,s,r)}catch(e){Promise.reject(e)}try{this.#T.onSettled?.(e.data,null,t,s,r)}catch(e){Promise.reject(e)}}else if(e?.type==="error"){try{this.#T.onError?.(e.error,t,s,r)}catch(e){Promise.reject(e)}try{this.#T.onSettled?.(void 0,e.error,t,s,r)}catch(e){Promise.reject(e)}}}this.listeners.forEach(e=>{e(this.#n)})})}};function Q(e,t){let s=(0,m.useQueryClient)(t),[i]=f.useState(()=>new O(s,e));f.useEffect(()=>{i.setOptions(e)},[i,e]);let n=f.useSyncExternalStore(f.useCallback(e=>i.subscribe(r.notifyManager.batchCalls(e)),[i]),()=>i.getCurrentResult(),()=>i.getCurrentResult()),a=f.useCallback((e,t)=>{i.mutate(e,t).catch(o.noop)},[i]);if(n.error&&(0,o.shouldThrowError)(i.options.throwOnError,[n.error]))throw n.error;return{...n,mutate:a,mutateAsync:n.mutate}}e.s(["useMutation",()=>Q],54616)},84944,e=>{"use strict";var t=e.i(43476),s=e.i(77183),r=e.i(76590),i=e.i(71645),n=e.i(7311),a=e.i(66027),o=e.i(54616),u=e.i(12598);let l="http://localhost:8000",c=async()=>{let e=await fetch(`${l}/api/sites`);if(!e.ok)throw Error("Failed to fetch sites");return e.json()},h=async(e,t)=>{if(!(await fetch(`${l}/api/sites/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).ok)throw Error("Failed to update site")},d=async e=>{if(!(await fetch(`${l}/api/sites/${e}`,{method:"DELETE"})).ok)throw Error("Failed to delete site")},p=async e=>{if(!(await fetch(`${l}/api/sites/reorder`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:e})})).ok)throw Error("Failed to reorder sites")},f=async e=>{if(!(await fetch(`${l}/api/sites/${e}/adapt`,{method:"POST"})).ok)throw Error("Adapt failed")},m=async e=>{let t=await fetch(`${l}/api/sites/${e}/selectors`);if(404===t.status)return null;if(!t.ok)throw Error("Failed to fetch selectors");return t.json()},y=["sites"];var b=e.i(47163);function x({site:e}){return e.cooldown_until&&new Date(e.cooldown_until)>new Date?(0,t.jsx)("span",{className:"text-ghost-gold text-xs font-mono",children:"⏳ COOLDOWN"}):e.consecutive_failures>2?(0,t.jsxs)("span",{className:"text-ghost-danger text-xs font-mono",children:["✗ ",e.error_count," errors"]}):(0,t.jsx)("span",{className:"text-ghost-accent text-xs font-mono",children:"✓ OK"})}function v({siteId:e}){let{data:s}=(0,a.useQuery)({queryKey:["selectors",e],queryFn:()=>m(e),staleTime:3e4});if(!s)return(0,t.jsx)("span",{className:"text-ghost-dim text-xs font-mono",children:"—"});let r=s.confidence>=70?"text-ghost-accent":s.confidence>=40?"text-ghost-gold":"text-ghost-danger";return(0,t.jsxs)("span",{className:(0,b.cn)("text-xs font-mono",r),children:[s.confidence,"%",s.stale?" ⚠":""]})}function R({site:e}){let s,a,l,{attributes:c,listeners:p,setNodeRef:m,transform:R,transition:g}=(0,r.useSortable)({id:e.id}),O=(s=(0,u.useQueryClient)(),(0,o.useMutation)({mutationFn:({id:e,data:t})=>h(e,t),onSuccess:()=>s.invalidateQueries({queryKey:y})})),Q=(a=(0,u.useQueryClient)(),(0,o.useMutation)({mutationFn:d,onSuccess:()=>a.invalidateQueries({queryKey:y})})),S=(l=(0,u.useQueryClient)(),(0,o.useMutation)({mutationFn:f,onSuccess:(e,t)=>l.invalidateQueries({queryKey:["selectors",t]})})),T=(0,u.useQueryClient)(),[E,C]=(0,i.useState)(!1),j=(0,i.useRef)(null),w={transform:n.CSS.Transform.toString(R),transition:g},I=S.isPending||E;return(0,t.jsxs)("tr",{ref:m,style:w,className:"border-b border-ghost-border hover:bg-ghost-panel",children:[(0,t.jsx)("td",{className:"p-2 w-6 cursor-grab text-ghost-dim",...c,...p,children:"⋮⋮"}),(0,t.jsx)("td",{className:"p-2 font-mono text-xs text-ghost-text",children:e.name}),(0,t.jsx)("td",{className:"p-2 font-mono text-xs text-ghost-dim truncate max-w-xs",children:e.url_template}),(0,t.jsx)("td",{className:"p-2",children:(0,t.jsx)(x,{site:e})}),(0,t.jsx)("td",{className:"p-2",children:(0,t.jsx)(v,{siteId:e.id})}),(0,t.jsx)("td",{className:"p-2",children:(0,t.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,t.jsx)("input",{type:"checkbox",checked:1===e.enabled,onChange:t=>O.mutate({id:e.id,data:{enabled:+!!t.target.checked}}),className:"accent-ghost-accent"}),(0,t.jsx)("span",{className:"font-mono text-xs text-ghost-dim",children:e.enabled?"ON":"OFF"})]})}),(0,t.jsxs)("td",{className:"p-2",children:[(0,t.jsx)("button",{onClick:()=>{S.mutate(e.id,{onSuccess:()=>{C(!0),j.current&&clearTimeout(j.current),j.current=setTimeout(()=>{C(!1),T.invalidateQueries({queryKey:["selectors",e.id]})},45e3)}})},disabled:I,className:(0,b.cn)("font-mono text-xs mr-2 transition-colors",I?"text-ghost-gold cursor-not-allowed":"text-ghost-dim hover:text-ghost-accent"),children:I?"⏳ ADAPTING…":"🤖 ADAPT"}),(0,t.jsx)("button",{onClick:()=>{confirm(`Delete "${e.name}"?`)&&Q.mutate(e.id)},className:"text-ghost-danger font-mono text-xs",children:"✕"})]})]})}function g(){let e,{data:i,isLoading:n}=(0,a.useQuery)({queryKey:y,queryFn:c}),l=(e=(0,u.useQueryClient)(),(0,o.useMutation)({mutationFn:p,onSuccess:()=>e.invalidateQueries({queryKey:y})}));return n?(0,t.jsx)("div",{className:"text-ghost-dim font-mono text-xs animate-pulse",children:"Loading sites…"}):(0,t.jsx)(s.DndContext,{collisionDetection:s.closestCenter,onDragEnd:({active:e,over:t})=>{if(!t||e.id===t.id||!i)return;let s=i.map(e=>e.id),r=s.indexOf(Number(e.id)),n=s.indexOf(Number(t.id)),a=[...s];a.splice(n,0,a.splice(r,1)[0]),l.mutate(a)},children:(0,t.jsx)(r.SortableContext,{items:(i??[]).map(e=>e.id),strategy:r.verticalListSortingStrategy,children:(0,t.jsxs)("table",{className:"w-full text-xs font-mono",children:[(0,t.jsx)("thead",{children:(0,t.jsxs)("tr",{className:"border-b border-ghost-border text-ghost-dim text-left",children:[(0,t.jsx)("th",{className:"p-2 w-6"}),(0,t.jsx)("th",{className:"p-2",children:"NAME"}),(0,t.jsx)("th",{className:"p-2",children:"URL TEMPLATE"}),(0,t.jsx)("th",{className:"p-2",children:"HEALTH"}),(0,t.jsx)("th",{className:"p-2",children:"AI CONF."}),(0,t.jsx)("th",{className:"p-2",children:"ENABLED"}),(0,t.jsx)("th",{className:"p-2",children:"ACTIONS"})]})}),(0,t.jsx)("tbody",{children:(i??[]).map(e=>(0,t.jsx)(R,{site:e},e.id))})]})})})}e.s(["default",()=>g],84944)}]);