39246-vm/frontend/out/_next/static/chunks/723edc877341e15e.js
2026-03-14 17:32:05 +03:00

1 line
17 KiB
JavaScript

(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.#g(),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.#x();let i=this.#R();r&&(this.#r!==s||(0,o.resolveEnabled)(this.options.enabled,this.#r)!==(0,o.resolveEnabled)(t.enabled,this.#r)||i!==this.#p)&&this.#Q(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}#x(){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)}#R(){return("function"==typeof this.options.refetchInterval?this.options.refetchInterval(this.#r):this.options.refetchInterval)??!1}#Q(e){this.#g(),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.#x(),this.#Q(this.#R())}#b(){this.#h&&(u.timeoutManager.clearTimeout(this.#h),this.#h=void 0)}#g(){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:g,errorUpdatedAt:v,status:x}=y;s=y.data;let R=!1;if(void 0!==t.placeholderData&&void 0===s&&"pending"===x){let e;u?.isPlaceholderData&&t.placeholderData===h?.placeholderData?(e=u.data,R=!0):e="function"==typeof t.placeholderData?t.placeholderData(this.#c?.state.data,this.#c):t.placeholderData,void 0!==e&&(x="success",s=(0,o.replaceData)(u?.data,e,t),b=!0)}if(t.select&&void 0!==s&&!R)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&&(g=this.#t,s=this.#l,v=Date.now(),x="error");let Q="fetching"===y.fetchStatus,O="pending"===x,S="error"===x,j=O&&Q,E=void 0!==s,T={status:x,fetchStatus:y.fetchStatus,isPending:O,isSuccess:"success"===x,isError:S,isInitialLoading:j,isLoading:j,data:s,dataUpdatedAt:y.dataUpdatedAt,error:g,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:Q,isRefetching:Q&&!O,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!==T.data,s="error"===T.status&&!t,i=e=>{s?e.reject(T.error):t&&e.resolve(T.data)},n=()=>{i(this.#s=T.promise=(0,a.pendingThenable)())},o=this.#s;switch(o.status){case"pending":e.queryHash===r.queryHash&&i(o);break;case"fulfilled":(s||T.data!==o.value)&&n();break;case"rejected":s&&T.error===o.reason||n()}}return T}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.#O({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()}#O(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 g=(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 g(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?g(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 x=e.i(14272),R=n,Q=class extends R.Subscribable{#e;#n=void 0;#S;#j;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.#O(e)}getCurrentResult(){return this.#n}reset(){this.#S?.removeObserver(this),this.#S=void 0,this.#E(),this.#O()}mutate(e,t){return this.#j=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,x.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}}#O(e){r.notifyManager.batch(()=>{if(this.#j&&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.#j.onSuccess?.(e.data,t,s,r)}catch(e){Promise.reject(e)}try{this.#j.onSettled?.(e.data,null,t,s,r)}catch(e){Promise.reject(e)}}else if(e?.type==="error"){try{this.#j.onError?.(e.error,t,s,r)}catch(e){Promise.reject(e)}try{this.#j.onSettled?.(void 0,e.error,t,s,r)}catch(e){Promise.reject(e)}}}this.listeners.forEach(e=>{e(this.#n)})})}};function O(e,t){let s=(0,m.useQueryClient)(t),[i]=f.useState(()=>new Q(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",()=>O],54616)},88139,e=>{"use strict";var t=e.i(43476),s=e.i(46932),r=e.i(77183),i=e.i(76590),n=e.i(71645),a=e.i(7311),o=e.i(66027),u=e.i(54616),l=e.i(12598);let c="http://localhost:8000",h=async()=>{let e=await fetch(`${c}/api/sites`);if(!e.ok)throw Error("Failed to fetch sites");return e.json()},d=async(e,t)=>{if(!(await fetch(`${c}/api/sites/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).ok)throw Error("Failed to update site")},p=async e=>{if(!(await fetch(`${c}/api/sites/${e}`,{method:"DELETE"})).ok)throw Error("Failed to delete site")},f=async e=>{if(!(await fetch(`${c}/api/sites/reorder`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:e})})).ok)throw Error("Failed to reorder sites")},m=async e=>{if(!(await fetch(`${c}/api/sites/${e}/adapt`,{method:"POST"})).ok)throw Error("Adapt failed")},y=async e=>{let t=await fetch(`${c}/api/sites/${e}/selectors`);if(404===t.status)return null;if(!t.ok)throw Error("Failed to fetch selectors");return t.json()},b=["sites"];var g=e.i(47163);function v({site:e}){return e.cooldown_until&&new Date(e.cooldown_until)>new Date?(0,t.jsx)("span",{className:"g-badge g-badge-amber",children:"Cooldown"}):e.consecutive_failures>2?(0,t.jsxs)("span",{className:"g-badge g-badge-red",children:[e.error_count," errors"]}):(0,t.jsx)("span",{className:"g-badge g-badge-green",children:"OK"})}function x({siteId:e}){let{data:s}=(0,o.useQuery)({queryKey:["selectors",e],queryFn:()=>y(e),staleTime:3e4});if(!s)return(0,t.jsx)("span",{className:"text-g-faint text-xs",children:"—"});let r=s.confidence>=70?"g-badge-green":s.confidence>=40?"g-badge-amber":"g-badge-red";return(0,t.jsxs)("span",{className:`g-badge ${r}`,children:[s.confidence,"%",s.stale?" ⚠":""]})}function R({site:e}){let s,r,o,{attributes:c,listeners:h,setNodeRef:f,transform:y,transition:R}=(0,i.useSortable)({id:e.id}),Q=(s=(0,l.useQueryClient)(),(0,u.useMutation)({mutationFn:({id:e,data:t})=>d(e,t),onSuccess:()=>s.invalidateQueries({queryKey:b})})),O=(r=(0,l.useQueryClient)(),(0,u.useMutation)({mutationFn:p,onSuccess:()=>r.invalidateQueries({queryKey:b})})),S=(o=(0,l.useQueryClient)(),(0,u.useMutation)({mutationFn:m,onSuccess:(e,t)=>o.invalidateQueries({queryKey:["selectors",t]})})),j=(0,l.useQueryClient)(),[E,T]=(0,n.useState)(!1),w=(0,n.useRef)(null),C={transform:a.CSS.Transform.toString(y),transition:R},I=S.isPending||E;return(0,t.jsxs)("tr",{ref:f,style:C,className:"group",children:[(0,t.jsx)("td",{className:"w-8",children:(0,t.jsx)("span",{...c,...h,className:"cursor-grab text-g-faint/30 hover:text-g-faint transition-colors select-none",children:"⋮⋮"})}),(0,t.jsx)("td",{children:(0,t.jsx)("span",{className:"text-sm font-medium text-g-text",children:e.name})}),(0,t.jsx)("td",{children:(0,t.jsx)("span",{className:"text-xs font-mono text-g-faint truncate max-w-xs block",children:e.url_template})}),(0,t.jsx)("td",{children:(0,t.jsx)(v,{site:e})}),(0,t.jsx)("td",{children:(0,t.jsx)(x,{siteId:e.id})}),(0,t.jsx)("td",{children:(0,t.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer w-fit",children:[(0,t.jsx)("div",{onClick:()=>Q.mutate({id:e.id,data:{enabled:+!e.enabled}}),className:(0,g.cn)("relative w-8 h-4 rounded-full transition-colors duration-200 cursor-pointer flex-shrink-0",e.enabled?"bg-g-green/30 border border-g-green/40":"bg-g-raised border border-g-border"),children:(0,t.jsx)("span",{className:(0,g.cn)("absolute top-0.5 w-3 h-3 rounded-full transition-transform duration-200 shadow-sm",e.enabled?"left-[18px] bg-g-green":"left-0.5 bg-g-faint")})}),(0,t.jsx)("span",{className:"text-xs text-g-faint",children:e.enabled?"On":"Off"})]})}),(0,t.jsx)("td",{children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("button",{onClick:()=>{S.mutate(e.id,{onSuccess:()=>{T(!0),w.current&&clearTimeout(w.current),w.current=setTimeout(()=>{T(!1),j.invalidateQueries({queryKey:["selectors",e.id]})},45e3)}})},disabled:I,className:(0,g.cn)("g-btn text-xs h-7",I&&"opacity-60 cursor-not-allowed"),children:I?"Adapting…":"Adapt AI"}),(0,t.jsx)("button",{onClick:()=>{confirm(`Delete "${e.name}"?`)&&O.mutate(e.id)},className:"text-g-faint hover:text-g-red transition-colors text-xs opacity-0 group-hover:opacity-100",children:"✕"})]})})]})}function Q(){let e,{data:s}=(0,o.useQuery)({queryKey:b,queryFn:h}),n=(e=(0,l.useQueryClient)(),(0,u.useMutation)({mutationFn:f,onSuccess:()=>e.invalidateQueries({queryKey:b})}));return(0,t.jsx)("div",{className:"g-card overflow-hidden",children:(0,t.jsx)(r.DndContext,{collisionDetection:r.closestCenter,onDragEnd:({active:e,over:t})=>{if(!t||e.id===t.id||!s)return;let r=s.map(e=>e.id),i=r.indexOf(Number(e.id)),a=r.indexOf(Number(t.id)),o=[...r];o.splice(a,0,o.splice(i,1)[0]),n.mutate(o)},children:(0,t.jsx)(i.SortableContext,{items:(s??[]).map(e=>e.id),strategy:i.verticalListSortingStrategy,children:(0,t.jsxs)("div",{className:"overflow-x-auto",children:[(0,t.jsxs)("table",{className:"g-table",children:[(0,t.jsx)("thead",{children:(0,t.jsxs)("tr",{children:[(0,t.jsx)("th",{className:"w-8"}),(0,t.jsx)("th",{children:"Name"}),(0,t.jsx)("th",{children:"URL template"}),(0,t.jsx)("th",{children:"Health"}),(0,t.jsx)("th",{children:"AI confidence"}),(0,t.jsx)("th",{children:"Enabled"}),(0,t.jsx)("th",{children:"Actions"})]})}),(0,t.jsx)("tbody",{children:(s??[]).map(e=>(0,t.jsx)(R,{site:e},e.id))})]}),!(s??[]).length&&(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center py-14 text-g-faint gap-2",children:[(0,t.jsx)("span",{className:"text-3xl opacity-20",children:"⬡"}),(0,t.jsx)("p",{className:"text-sm",children:"No sites added yet"}),(0,t.jsx)("p",{className:"text-xs opacity-60",children:"Add a site below to start scraping"})]})]})})})})}function O(){return(0,t.jsxs)("div",{className:"space-y-5",children:[(0,t.jsxs)(s.motion.div,{initial:{opacity:1,y:-8},animate:{opacity:1,y:0},transition:{duration:.4},children:[(0,t.jsx)("h1",{className:"g-page-title",children:"Sites"}),(0,t.jsx)("p",{className:"g-page-sub",children:"Auction sources and health status"})]}),(0,t.jsx)(Q,{})]})}e.s(["default",()=>O],88139)}]);