@canonry/canonry 4.165.0 → 4.165.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/README.md +11 -1
  2. package/assets/agent-workspace/skills/canonry/references/server-side-traffic.md +75 -3
  3. package/assets/assets/{AuditHistoryPanel-IYMElyK5.js → AuditHistoryPanel-DYBAiNCu.js} +1 -1
  4. package/assets/assets/{BacklinksPage-BMqIPRvZ.js → BacklinksPage-p19FCIyh.js} +1 -1
  5. package/assets/assets/{HistoryPage-iuETLmwO.js → HistoryPage-CRSuA-J0.js} +1 -1
  6. package/assets/assets/{MeasurementPropertyPage-BzNAaB8X.js → MeasurementPropertyPage-Bgr9VeUk.js} +1 -1
  7. package/assets/assets/{ProjectPage-DIzi4Ggo.js → ProjectPage-D6-9qYKU.js} +8 -8
  8. package/assets/assets/{RunRow-BkkYxEjl.js → RunRow-_RMMaLPt.js} +1 -1
  9. package/assets/assets/{RunsPage-DGTrqrTA.js → RunsPage-CaDPSEfE.js} +1 -1
  10. package/assets/assets/{SettingsPage-Cwb_Ft9u.js → SettingsPage-Dcp71zcu.js} +1 -1
  11. package/assets/assets/{SiteHealthSection-k4I71wfJ.js → SiteHealthSection-Byp_Fu5K.js} +3 -3
  12. package/assets/assets/{TrafficPage-C8nyb8l1.js → TrafficPage-BXkXNKYB.js} +1 -1
  13. package/assets/assets/{TrafficSourceDetailPage-ry7Da0pV.js → TrafficSourceDetailPage-CReS8q0H.js} +1 -1
  14. package/assets/assets/{extract-error-message-BYyBW07F.js → extract-error-message-CHW-A3AQ.js} +1 -1
  15. package/assets/assets/{index-rqOXhYwp.js → index-CcS2bDjR.js} +2 -2
  16. package/assets/assets/{react-sigma_core.esm.min-BtG8TWTe.js → react-sigma_core.esm.min-Cm0RA3Iv.js} +1 -1
  17. package/assets/index.html +1 -1
  18. package/dist/{chunk-QKLNTSQ2.js → chunk-BJLIMWL2.js} +12 -11
  19. package/dist/{chunk-QDOZEMDK.js → chunk-J56XZGG6.js} +1 -1
  20. package/dist/{chunk-BU6C2DKF.js → chunk-P2CQ57UV.js} +8 -2
  21. package/dist/{chunk-L5SMSDZB.js → chunk-UVDX2Y4N.js} +4 -4
  22. package/dist/cli.js +4 -4
  23. package/dist/index.js +4 -4
  24. package/dist/{intelligence-service-RDGUEEZQ.js → intelligence-service-QGBYYNWV.js} +2 -2
  25. package/dist/mcp.js +2 -2
  26. package/package.json +7 -7
@@ -1 +1 @@
1
- import{r as c,j as e,h as V,u as E,f as L,L as U}from"./vendor-tanstack-Dock0eH1.js";import{cx as z,cy as B,cz as I,cA as A,cB as D,B as C,f as O,cC as $,bx as H,k as F,i as w,d as S,cD as W,T as G}from"./index-rqOXhYwp.js";import{b as J,c as M,d as Q,a as T,f as _,t as K}from"./extract-error-message-BYyBW07F.js";import{G as Y,w as X,x as Z,y as ee,p as q,A as te}from"./vendor-lucide-nYKv-BB7.js";import"./vendor-radix-4UOaVWza.js";import"./vendor-recharts-D8rt5lKn.js";import"./vendor-markdown-Bn7fRwrx.js";import"./vendor-yaml-GWJz5H2G.js";function re({open:t,onOpenChange:a,projectName:n}){const[r,s]=c.useState("pick");c.useEffect(()=>{t&&s("pick")},[t]);const o=()=>{a(!1),s("pick")};return e.jsx(z,{open:t,onOpenChange:i=>{i?a(!0):o()},children:e.jsx(B,{children:r==="pick"?e.jsx(ne,{onPick:s}):r==="wordpress"?e.jsx(ie,{projectName:n,onBack:()=>s("pick"),onClose:o}):r==="vercel"?e.jsx(ce,{projectName:n,onBack:()=>s("pick"),onClose:o}):e.jsx(le,{projectName:n,onBack:()=>s("pick"),onClose:o})})})}const se=[{type:"wordpress",name:"WordPress",action:"Install the traffic plugin",icon:Y},{type:"cloud-run",name:"Google Cloud Run",action:"Read request logs",icon:X},{type:"vercel",name:"Vercel",action:"Read request logs",icon:Z}];function ne({onPick:t}){return e.jsxs(e.Fragment,{children:[e.jsxs(I,{children:[e.jsx(A,{children:"Connect a traffic source"}),e.jsx(D,{children:"Choose where Canonry should read traffic logs."})]}),e.jsx("div",{className:"mt-6 flex flex-col gap-3",children:se.map(({type:a,name:n,action:r,icon:s})=>e.jsxs("button",{type:"button",onClick:()=>t(a),className:"group flex items-center gap-3 rounded-md border border-base bg-bg-elevated/30 px-3 py-3 text-left transition-colors hover:border-mono-600 hover:bg-bg-elevated/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400",children:[e.jsx("span",{className:"mt-0.5 inline-flex size-9 shrink-0 items-center justify-center rounded-md border border-base bg-bg text-neutral group-hover:text-heading",children:e.jsx(s,{className:"size-4"})}),e.jsxs("span",{className:"flex min-w-0 flex-1 items-baseline justify-between gap-3",children:[e.jsx("span",{className:"text-sm font-medium text-heading",children:n}),e.jsx("span",{className:"text-sm text-secondary",children:r})]})]},a))})]})}function oe({title:t,description:a,onBack:n}){return e.jsxs(I,{children:[e.jsxs("button",{type:"button",onClick:n,className:"mb-1 inline-flex w-fit items-center gap-1 rounded text-sm text-secondary transition-colors hover:text-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400",children:[e.jsx(ee,{className:"size-3"}),"Choose a different source"]}),e.jsx(A,{children:t}),e.jsx(D,{children:a})]})}function ae(t,a){const n=V();return async(r,s)=>{await $(t,r),s?.(),a(),n({to:"/traffic/$projectName/$sourceId",params:{projectName:t,sourceId:r}})}}function k(t,a){const[n,r]=c.useState(null),s=ae(t,a);return{error:n,runConnect:async i=>{r(null);const d=i.validate();if(d){r(d);return}let u;try{u=await i.mutate()}catch(l){r(T(l));return}try{await s(u.id,i.onConnected)}catch(l){r(`Source connected, but starting the initial backfill failed: ${T(l)}`)}}}}function P({title:t,description:a,projectName:n,onBack:r,onClose:s,onSubmit:o,isPending:i,error:d,children:u}){return e.jsxs(e.Fragment,{children:[e.jsx(oe,{title:t,description:a,onBack:r}),e.jsxs("form",{onSubmit:O(async l=>{l.preventDefault(),await o()}),className:"mt-6 flex flex-col gap-5 overflow-y-auto pr-1",children:[e.jsx(p,{label:"Project",description:"Canonry project this source attaches to.",children:e.jsx("input",{type:"text",value:n,disabled:!0,className:"w-full rounded border border-strong bg-bg-elevated/50 px-2 py-1.5 text-sm text-neutral"})}),u,d?e.jsx("p",{className:"rounded-md border border-negative-800/50 bg-negative-950/30 px-3 py-2 text-xs text-negative-200",children:d}):null,e.jsxs("div",{className:"mt-2 flex items-center justify-end gap-2 border-t border-default pt-4",children:[e.jsx(C,{type:"button",variant:"ghost",size:"sm",onClick:s,children:"Close"}),e.jsx(C,{type:"submit",disabled:i,size:"sm",children:i?"Connecting…":"Connect"})]})]})]})}function ie({projectName:t,onBack:a,onClose:n}){const[r,s]=c.useState(""),[o,i]=c.useState(""),[d,u]=c.useState(""),[l,j]=c.useState(""),f=J(t||null),{error:g,runConnect:b}=k(t,n),y=()=>b({validate:()=>r.trim()?o.trim()?d.trim()?null:"Application Password is required.":"Username is required.":"WordPress site URL is required.",mutate:()=>f.mutateAsync({baseUrl:r.trim(),username:o.trim(),applicationPassword:d.trim(),displayName:l.trim()||void 0}),onConnected:()=>u("")});return e.jsxs(P,{title:"Connect a WordPress site",description:e.jsxs(e.Fragment,{children:["Pulls request events from the Canonry Traffic Logger plugin. The Application Password is stored in ",e.jsx("code",{children:"~/.canonry/config.yaml"})," on the server and never echoed back to the dashboard."]}),projectName:t,onBack:a,onClose:n,onSubmit:y,isPending:f.isPending,error:g,children:[e.jsx(p,{label:"WordPress site URL",description:"Base URL of the site running the Canonry Traffic Logger plugin.",required:!0,children:e.jsx("input",{type:"url",value:r,onChange:x=>s(x.target.value),required:!0,autoComplete:"url",placeholder:"https://example.com",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})}),e.jsx(p,{label:"Username",description:"WordPress user that owns the Application Password.",required:!0,children:e.jsx("input",{type:"text",value:o,onChange:x=>i(x.target.value),required:!0,autoComplete:"username",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})}),e.jsx(p,{label:"Application Password",description:"Create one in wp-admin under Users -> Profile -> Application Passwords.",required:!0,children:e.jsx("input",{type:"password",value:d,onChange:x=>u(x.target.value),required:!0,autoComplete:"new-password",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})}),e.jsx(p,{label:"Display name (optional)",description:"Friendly label shown in the dashboard. Defaults to the WordPress host.",children:e.jsx("input",{type:"text",value:l,onChange:x=>j(x.target.value),autoComplete:"off",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})})]})}function le({projectName:t,onBack:a,onClose:n}){const[r,s]=c.useState(""),[o,i]=c.useState(""),[d,u]=c.useState(""),[l,j]=c.useState(""),[f,g]=c.useState(""),b=Q(t||null),{error:y,runConnect:x}=k(t,n),N=()=>x({validate:()=>r.trim()?f.trim()?null:"Service-account JSON content is required.":"GCP project ID is required.",mutate:()=>b.mutateAsync({gcpProjectId:r.trim(),serviceName:o.trim()||void 0,location:d.trim()||void 0,displayName:l.trim()||void 0,keyJson:f.trim()}),onConnected:()=>g("")}),h=async m=>{if(!m)return;const R=await m.text();g(R)};return e.jsxs(P,{title:"Connect a Cloud Run service",description:e.jsxs(e.Fragment,{children:["v1 supports service-account JSON only. The private key is stored in"," ",e.jsx("code",{children:"~/.canonry/config.yaml"})," on the server and never echoed back to the dashboard."]}),projectName:t,onBack:a,onClose:n,onSubmit:N,isPending:b.isPending,error:y,children:[e.jsx(p,{label:"GCP project ID",description:"The Google Cloud project hosting the Cloud Run service (e.g. my-prod-foo).",required:!0,children:e.jsx("input",{type:"text",value:r,onChange:m=>s(m.target.value),required:!0,autoComplete:"off",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})}),e.jsx(p,{label:"Service name (optional)",description:"Restrict log pulls to a specific Cloud Run service. Omit to pull all services in the project.",children:e.jsx("input",{type:"text",value:o,onChange:m=>i(m.target.value),autoComplete:"off",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})}),e.jsx(p,{label:"Location (optional)",description:"Region of the Cloud Run service (e.g. us-central1). Helpful when multiple regions emit logs.",children:e.jsx("input",{type:"text",value:d,onChange:m=>u(m.target.value),autoComplete:"off",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})}),e.jsx(p,{label:"Display name (optional)",description:"Friendly label shown in the dashboard. Defaults to the project + service combo.",children:e.jsx("input",{type:"text",value:l,onChange:m=>j(m.target.value),autoComplete:"off",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})}),e.jsxs(p,{label:"Service-account JSON",description:"Paste the contents of the SA key (JSON). The SA needs roles/logging.viewer (or any role granting logging.logEntries.list).",required:!0,children:[e.jsx("textarea",{value:f,onChange:m=>g(m.target.value),rows:6,spellCheck:!1,autoComplete:"off",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 font-mono text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none",placeholder:'{"type":"service_account","project_id":"…","private_key":"…"}',required:!0}),e.jsxs("label",{className:"mt-2 inline-flex cursor-pointer items-center gap-2 text-sm text-secondary hover:text-strong",children:[e.jsx("input",{type:"file",accept:"application/json,.json",className:"hidden",onChange:m=>{h(m.target.files?.[0]??null)}}),e.jsx("span",{className:"rounded-md border border-base px-2 py-1",children:"Or upload a key file"})]})]})]})}function ce({projectName:t,onBack:a,onClose:n}){const[r,s]=c.useState(""),[o,i]=c.useState(""),[d,u]=c.useState(""),[l,j]=c.useState("production"),[f,g]=c.useState(""),b=M(t||null),{error:y,runConnect:x}=k(t,n),N=()=>x({validate:()=>r.trim()?o.trim()?d.trim()?null:"Vercel personal access token is required.":"Vercel team / account ID is required.":"Vercel project ID is required.",mutate:()=>b.mutateAsync({projectId:r.trim(),teamId:o.trim(),token:d.trim(),environment:l,displayName:f.trim()||void 0}),onConnected:()=>u("")});return e.jsxs(P,{title:"Connect a Vercel project",description:e.jsxs(e.Fragment,{children:["Pulls request logs straight from Vercel, no in-app instrumentation needed. The personal access token is stored in ",e.jsx("code",{children:"~/.canonry/config.yaml"})," on the server and never echoed back to the dashboard."]}),projectName:t,onBack:a,onClose:n,onSubmit:N,isPending:b.isPending,error:y,children:[e.jsx(p,{label:"Vercel project ID",description:"The prj_… id from the Vercel dashboard or .vercel/project.json.",required:!0,children:e.jsx("input",{type:"text",value:r,onChange:h=>s(h.target.value),required:!0,autoComplete:"off",placeholder:"prj_…",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})}),e.jsx(p,{label:"Vercel team / account ID",description:"The Vercel team or personal account that owns the project. Find it as orgId in your .vercel/project.json.",required:!0,children:e.jsx("input",{type:"text",value:o,onChange:h=>i(h.target.value),required:!0,autoComplete:"off",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})}),e.jsx(p,{label:"Personal access token",description:"Create a Vercel personal access token under Account Settings → Tokens. Tokens can expire, so use a long-lived one.",required:!0,children:e.jsx("input",{type:"password",value:d,onChange:h=>u(h.target.value),required:!0,autoComplete:"new-password",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})}),e.jsx(p,{label:"Environment",description:"Which deployment environment's request logs to pull.",children:e.jsxs("select",{value:l,onChange:h=>j(h.target.value),className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong focus:border-mono-500 focus:outline-none",children:[e.jsx("option",{value:"production",children:"production"}),e.jsx("option",{value:"preview",children:"preview"})]})}),e.jsx(p,{label:"Display name (optional)",description:"Friendly label shown in the dashboard. Defaults to the Vercel project ID.",children:e.jsx("input",{type:"text",value:f,onChange:h=>g(h.target.value),autoComplete:"off",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})})]})}function p({label:t,description:a,required:n,children:r}){return e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsxs("span",{className:"text-sm font-medium text-strong",children:[t,n?e.jsx("span",{className:"ml-1 text-negative-400",children:"*"}):null]}),r,e.jsx("span",{className:"text-[13px] leading-5 text-secondary",children:a})]})}function de(t){if(!t)return"never";const a=Date.now()-new Date(t).getTime(),n=Math.floor(a/6e4);if(n<1)return"just now";if(n<60)return`${n}m ago`;const r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function v(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toLocaleString()}function ye(){const[t,a]=c.useState(""),[n,r]=c.useState(!1),o=E(H({client:F})).data??[],i=c.useMemo(()=>t||(o[0]?.name??""),[t,o]),d=_(i||null),u=d.data?.sources??[];return e.jsxs("div",{className:"page-container",children:[e.jsxs("div",{className:"page-header",children:[e.jsxs("div",{className:"page-header-left",children:[e.jsx("h1",{className:"page-title",children:"Traffic sources"}),e.jsx("p",{className:"page-subtitle",children:"AI crawler hits and referral sessions from your server logs."})]}),!w()&&e.jsx("div",{className:"flex flex-wrap items-center justify-end gap-2",children:e.jsxs(C,{type:"button",variant:"outline",size:"sm",onClick:()=>r(!0),disabled:!i,children:[e.jsx(q,{className:"size-3.5"}),"Connect a source"]})})]}),e.jsxs("section",{children:[o.length>1&&e.jsxs("label",{className:"mb-4 flex w-fit items-center gap-2 text-sm font-medium text-secondary",htmlFor:"traffic-project",children:["Project",e.jsx("select",{id:"traffic-project",className:"h-8 min-w-44 rounded-md border border-base bg-bg px-2 text-sm text-heading outline-none transition focus:border-mono-500 focus:ring-1 focus:ring-mono-500",value:i,onChange:l=>a(l.target.value),children:o.map(l=>e.jsx("option",{value:l.name,children:l.displayName??l.name},l.id))})]}),i?d.isLoading?e.jsx(S,{className:"p-6 text-center text-sm text-muted",children:"Loading sources…"}):u.length===0?e.jsxs(S,{className:"p-8 text-center",children:[e.jsxs("p",{className:"text-sm text-neutral",children:["No traffic sources connected for ",i,"."]}),!w()&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mt-1 text-sm text-secondary",children:"Connect a source to start collecting traffic."}),e.jsx("div",{className:"mt-4 flex flex-wrap items-center justify-center gap-2",children:e.jsxs(C,{type:"button",variant:"outline",size:"sm",onClick:()=>r(!0),children:[e.jsx(q,{className:"size-3.5"}),"Connect a source"]})})]})]}):e.jsx(ue,{projectName:i,sources:u}):e.jsx(S,{className:"p-6 text-center text-sm text-muted",children:"No projects yet."})]}),!w()&&e.jsx(re,{open:n,onOpenChange:r,projectName:i})]})}function ue({projectName:t,sources:a}){const n=L({queries:a.map(s=>({...W({client:F,path:{name:t,id:s.id}}),staleTime:3e4}))}),r=a.map((s,o)=>({source:s,detail:n[o]?.data,isLoading:n[o]?.isLoading??!1}));return e.jsx("div",{className:"rounded-xl border border-default bg-surface overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-bg-elevated/50 text-[10px] font-semibold uppercase tracking-wider text-muted",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-2 text-left",children:"Source"}),e.jsx("th",{className:"px-4 py-2 text-left",children:"Status"}),e.jsx("th",{className:"px-4 py-2 text-left",children:"Last sync"}),e.jsx("th",{className:"px-4 py-2 text-right",children:"Content crawls"}),e.jsx("th",{className:"px-4 py-2 text-right",children:"Infra crawls"}),e.jsx("th",{className:"px-4 py-2 text-right",children:"AI fetches"}),e.jsx("th",{className:"px-4 py-2 text-right",children:"AI referrals"}),e.jsx("th",{className:"px-4 py-2 text-right"})]})}),e.jsx("tbody",{className:"divide-y divide-mono-800/60",children:r.map(({source:s,detail:o,isLoading:i})=>e.jsxs("tr",{className:"hover:bg-bg-elevated/40 transition-colors",children:[e.jsx("td",{className:"px-4 py-3",children:e.jsx("div",{className:"font-medium text-heading",children:s.displayName})}),e.jsxs("td",{className:"px-4 py-3",children:[e.jsx(G,{tone:K(s.status),children:s.status}),s.lastError?e.jsx("p",{className:"mt-1 max-w-[18rem] truncate text-sm text-negative-400",title:s.lastError,children:s.lastError}):null]}),e.jsx("td",{className:"px-4 py-3 text-neutral",children:de(s.lastSyncedAt)}),e.jsx("td",{className:"px-4 py-3 text-right tabular-nums text-heading",title:o?`${o.totals24h.crawlerHits.toLocaleString("en-US")} total crawler hits`:void 0,children:i?"—":v(o?.totals24h.crawlerContentHits??0)}),e.jsx("td",{className:"px-4 py-3 text-right tabular-nums text-muted",children:i?"—":v(o?.totals24h.crawlerInfraHits??0)}),e.jsx("td",{className:"px-4 py-3 text-right tabular-nums text-heading",children:i?"—":v(o?.totals24h.aiUserFetchHits??0)}),e.jsx("td",{className:"px-4 py-3 text-right tabular-nums text-heading",children:i?"—":v(o?.totals24h.aiReferralHits??0)}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsxs(U,{to:"/traffic/$projectName/$sourceId",params:{projectName:t,sourceId:s.id},className:"inline-flex items-center gap-1 text-sm text-secondary hover:text-heading",children:["View",e.jsx(te,{className:"size-3.5"})]})})]},s.id))})]})})}export{ye as TrafficPage};
1
+ import{r as c,j as e,h as V,u as E,f as L,L as U}from"./vendor-tanstack-Dock0eH1.js";import{cx as z,cy as B,cz as I,cA as A,cB as D,B as C,f as O,cC as $,bx as H,k as F,i as w,d as S,cD as W,T as G}from"./index-CcS2bDjR.js";import{b as J,c as M,d as Q,a as T,f as _,t as K}from"./extract-error-message-CHW-A3AQ.js";import{G as Y,w as X,x as Z,y as ee,p as q,A as te}from"./vendor-lucide-nYKv-BB7.js";import"./vendor-radix-4UOaVWza.js";import"./vendor-recharts-D8rt5lKn.js";import"./vendor-markdown-Bn7fRwrx.js";import"./vendor-yaml-GWJz5H2G.js";function re({open:t,onOpenChange:a,projectName:n}){const[r,s]=c.useState("pick");c.useEffect(()=>{t&&s("pick")},[t]);const o=()=>{a(!1),s("pick")};return e.jsx(z,{open:t,onOpenChange:i=>{i?a(!0):o()},children:e.jsx(B,{children:r==="pick"?e.jsx(ne,{onPick:s}):r==="wordpress"?e.jsx(ie,{projectName:n,onBack:()=>s("pick"),onClose:o}):r==="vercel"?e.jsx(ce,{projectName:n,onBack:()=>s("pick"),onClose:o}):e.jsx(le,{projectName:n,onBack:()=>s("pick"),onClose:o})})})}const se=[{type:"wordpress",name:"WordPress",action:"Install the traffic plugin",icon:Y},{type:"cloud-run",name:"Google Cloud Run",action:"Read request logs",icon:X},{type:"vercel",name:"Vercel",action:"Read request logs",icon:Z}];function ne({onPick:t}){return e.jsxs(e.Fragment,{children:[e.jsxs(I,{children:[e.jsx(A,{children:"Connect a traffic source"}),e.jsx(D,{children:"Choose where Canonry should read traffic logs."})]}),e.jsx("div",{className:"mt-6 flex flex-col gap-3",children:se.map(({type:a,name:n,action:r,icon:s})=>e.jsxs("button",{type:"button",onClick:()=>t(a),className:"group flex items-center gap-3 rounded-md border border-base bg-bg-elevated/30 px-3 py-3 text-left transition-colors hover:border-mono-600 hover:bg-bg-elevated/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400",children:[e.jsx("span",{className:"mt-0.5 inline-flex size-9 shrink-0 items-center justify-center rounded-md border border-base bg-bg text-neutral group-hover:text-heading",children:e.jsx(s,{className:"size-4"})}),e.jsxs("span",{className:"flex min-w-0 flex-1 items-baseline justify-between gap-3",children:[e.jsx("span",{className:"text-sm font-medium text-heading",children:n}),e.jsx("span",{className:"text-sm text-secondary",children:r})]})]},a))})]})}function oe({title:t,description:a,onBack:n}){return e.jsxs(I,{children:[e.jsxs("button",{type:"button",onClick:n,className:"mb-1 inline-flex w-fit items-center gap-1 rounded text-sm text-secondary transition-colors hover:text-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400",children:[e.jsx(ee,{className:"size-3"}),"Choose a different source"]}),e.jsx(A,{children:t}),e.jsx(D,{children:a})]})}function ae(t,a){const n=V();return async(r,s)=>{await $(t,r),s?.(),a(),n({to:"/traffic/$projectName/$sourceId",params:{projectName:t,sourceId:r}})}}function k(t,a){const[n,r]=c.useState(null),s=ae(t,a);return{error:n,runConnect:async i=>{r(null);const d=i.validate();if(d){r(d);return}let u;try{u=await i.mutate()}catch(l){r(T(l));return}try{await s(u.id,i.onConnected)}catch(l){r(`Source connected, but starting the initial backfill failed: ${T(l)}`)}}}}function P({title:t,description:a,projectName:n,onBack:r,onClose:s,onSubmit:o,isPending:i,error:d,children:u}){return e.jsxs(e.Fragment,{children:[e.jsx(oe,{title:t,description:a,onBack:r}),e.jsxs("form",{onSubmit:O(async l=>{l.preventDefault(),await o()}),className:"mt-6 flex flex-col gap-5 overflow-y-auto pr-1",children:[e.jsx(p,{label:"Project",description:"Canonry project this source attaches to.",children:e.jsx("input",{type:"text",value:n,disabled:!0,className:"w-full rounded border border-strong bg-bg-elevated/50 px-2 py-1.5 text-sm text-neutral"})}),u,d?e.jsx("p",{className:"rounded-md border border-negative-800/50 bg-negative-950/30 px-3 py-2 text-xs text-negative-200",children:d}):null,e.jsxs("div",{className:"mt-2 flex items-center justify-end gap-2 border-t border-default pt-4",children:[e.jsx(C,{type:"button",variant:"ghost",size:"sm",onClick:s,children:"Close"}),e.jsx(C,{type:"submit",disabled:i,size:"sm",children:i?"Connecting…":"Connect"})]})]})]})}function ie({projectName:t,onBack:a,onClose:n}){const[r,s]=c.useState(""),[o,i]=c.useState(""),[d,u]=c.useState(""),[l,j]=c.useState(""),f=J(t||null),{error:g,runConnect:b}=k(t,n),y=()=>b({validate:()=>r.trim()?o.trim()?d.trim()?null:"Application Password is required.":"Username is required.":"WordPress site URL is required.",mutate:()=>f.mutateAsync({baseUrl:r.trim(),username:o.trim(),applicationPassword:d.trim(),displayName:l.trim()||void 0}),onConnected:()=>u("")});return e.jsxs(P,{title:"Connect a WordPress site",description:e.jsxs(e.Fragment,{children:["Pulls request events from the Canonry Traffic Logger plugin. The Application Password is stored in ",e.jsx("code",{children:"~/.canonry/config.yaml"})," on the server and never echoed back to the dashboard."]}),projectName:t,onBack:a,onClose:n,onSubmit:y,isPending:f.isPending,error:g,children:[e.jsx(p,{label:"WordPress site URL",description:"Base URL of the site running the Canonry Traffic Logger plugin.",required:!0,children:e.jsx("input",{type:"url",value:r,onChange:x=>s(x.target.value),required:!0,autoComplete:"url",placeholder:"https://example.com",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})}),e.jsx(p,{label:"Username",description:"WordPress user that owns the Application Password.",required:!0,children:e.jsx("input",{type:"text",value:o,onChange:x=>i(x.target.value),required:!0,autoComplete:"username",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})}),e.jsx(p,{label:"Application Password",description:"Create one in wp-admin under Users -> Profile -> Application Passwords.",required:!0,children:e.jsx("input",{type:"password",value:d,onChange:x=>u(x.target.value),required:!0,autoComplete:"new-password",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})}),e.jsx(p,{label:"Display name (optional)",description:"Friendly label shown in the dashboard. Defaults to the WordPress host.",children:e.jsx("input",{type:"text",value:l,onChange:x=>j(x.target.value),autoComplete:"off",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})})]})}function le({projectName:t,onBack:a,onClose:n}){const[r,s]=c.useState(""),[o,i]=c.useState(""),[d,u]=c.useState(""),[l,j]=c.useState(""),[f,g]=c.useState(""),b=Q(t||null),{error:y,runConnect:x}=k(t,n),N=()=>x({validate:()=>r.trim()?f.trim()?null:"Service-account JSON content is required.":"GCP project ID is required.",mutate:()=>b.mutateAsync({gcpProjectId:r.trim(),serviceName:o.trim()||void 0,location:d.trim()||void 0,displayName:l.trim()||void 0,keyJson:f.trim()}),onConnected:()=>g("")}),h=async m=>{if(!m)return;const R=await m.text();g(R)};return e.jsxs(P,{title:"Connect a Cloud Run service",description:e.jsxs(e.Fragment,{children:["v1 supports service-account JSON only. The private key is stored in"," ",e.jsx("code",{children:"~/.canonry/config.yaml"})," on the server and never echoed back to the dashboard."]}),projectName:t,onBack:a,onClose:n,onSubmit:N,isPending:b.isPending,error:y,children:[e.jsx(p,{label:"GCP project ID",description:"The Google Cloud project hosting the Cloud Run service (e.g. my-prod-foo).",required:!0,children:e.jsx("input",{type:"text",value:r,onChange:m=>s(m.target.value),required:!0,autoComplete:"off",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})}),e.jsx(p,{label:"Service name (optional)",description:"Restrict log pulls to a specific Cloud Run service. Omit to pull all services in the project.",children:e.jsx("input",{type:"text",value:o,onChange:m=>i(m.target.value),autoComplete:"off",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})}),e.jsx(p,{label:"Location (optional)",description:"Region of the Cloud Run service (e.g. us-central1). Helpful when multiple regions emit logs.",children:e.jsx("input",{type:"text",value:d,onChange:m=>u(m.target.value),autoComplete:"off",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})}),e.jsx(p,{label:"Display name (optional)",description:"Friendly label shown in the dashboard. Defaults to the project + service combo.",children:e.jsx("input",{type:"text",value:l,onChange:m=>j(m.target.value),autoComplete:"off",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})}),e.jsxs(p,{label:"Service-account JSON",description:"Paste the contents of the SA key (JSON). The SA needs roles/logging.viewer (or any role granting logging.logEntries.list).",required:!0,children:[e.jsx("textarea",{value:f,onChange:m=>g(m.target.value),rows:6,spellCheck:!1,autoComplete:"off",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 font-mono text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none",placeholder:'{"type":"service_account","project_id":"…","private_key":"…"}',required:!0}),e.jsxs("label",{className:"mt-2 inline-flex cursor-pointer items-center gap-2 text-sm text-secondary hover:text-strong",children:[e.jsx("input",{type:"file",accept:"application/json,.json",className:"hidden",onChange:m=>{h(m.target.files?.[0]??null)}}),e.jsx("span",{className:"rounded-md border border-base px-2 py-1",children:"Or upload a key file"})]})]})]})}function ce({projectName:t,onBack:a,onClose:n}){const[r,s]=c.useState(""),[o,i]=c.useState(""),[d,u]=c.useState(""),[l,j]=c.useState("production"),[f,g]=c.useState(""),b=M(t||null),{error:y,runConnect:x}=k(t,n),N=()=>x({validate:()=>r.trim()?o.trim()?d.trim()?null:"Vercel personal access token is required.":"Vercel team / account ID is required.":"Vercel project ID is required.",mutate:()=>b.mutateAsync({projectId:r.trim(),teamId:o.trim(),token:d.trim(),environment:l,displayName:f.trim()||void 0}),onConnected:()=>u("")});return e.jsxs(P,{title:"Connect a Vercel project",description:e.jsxs(e.Fragment,{children:["Pulls request logs straight from Vercel, no in-app instrumentation needed. The personal access token is stored in ",e.jsx("code",{children:"~/.canonry/config.yaml"})," on the server and never echoed back to the dashboard."]}),projectName:t,onBack:a,onClose:n,onSubmit:N,isPending:b.isPending,error:y,children:[e.jsx(p,{label:"Vercel project ID",description:"The prj_… id from the Vercel dashboard or .vercel/project.json.",required:!0,children:e.jsx("input",{type:"text",value:r,onChange:h=>s(h.target.value),required:!0,autoComplete:"off",placeholder:"prj_…",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})}),e.jsx(p,{label:"Vercel team / account ID",description:"The Vercel team or personal account that owns the project. Find it as orgId in your .vercel/project.json.",required:!0,children:e.jsx("input",{type:"text",value:o,onChange:h=>i(h.target.value),required:!0,autoComplete:"off",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})}),e.jsx(p,{label:"Personal access token",description:"Create a Vercel personal access token under Account Settings → Tokens. Tokens can expire, so use a long-lived one.",required:!0,children:e.jsx("input",{type:"password",value:d,onChange:h=>u(h.target.value),required:!0,autoComplete:"new-password",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})}),e.jsx(p,{label:"Environment",description:"Which deployment environment's request logs to pull.",children:e.jsxs("select",{value:l,onChange:h=>j(h.target.value),className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong focus:border-mono-500 focus:outline-none",children:[e.jsx("option",{value:"production",children:"production"}),e.jsx("option",{value:"preview",children:"preview"})]})}),e.jsx(p,{label:"Display name (optional)",description:"Friendly label shown in the dashboard. Defaults to the Vercel project ID.",children:e.jsx("input",{type:"text",value:f,onChange:h=>g(h.target.value),autoComplete:"off",className:"w-full rounded border border-strong bg-transparent px-2 py-1.5 text-sm text-strong placeholder-mono-600 focus:border-mono-500 focus:outline-none"})})]})}function p({label:t,description:a,required:n,children:r}){return e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsxs("span",{className:"text-sm font-medium text-strong",children:[t,n?e.jsx("span",{className:"ml-1 text-negative-400",children:"*"}):null]}),r,e.jsx("span",{className:"text-[13px] leading-5 text-secondary",children:a})]})}function de(t){if(!t)return"never";const a=Date.now()-new Date(t).getTime(),n=Math.floor(a/6e4);if(n<1)return"just now";if(n<60)return`${n}m ago`;const r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function v(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toLocaleString()}function ye(){const[t,a]=c.useState(""),[n,r]=c.useState(!1),o=E(H({client:F})).data??[],i=c.useMemo(()=>t||(o[0]?.name??""),[t,o]),d=_(i||null),u=d.data?.sources??[];return e.jsxs("div",{className:"page-container",children:[e.jsxs("div",{className:"page-header",children:[e.jsxs("div",{className:"page-header-left",children:[e.jsx("h1",{className:"page-title",children:"Traffic sources"}),e.jsx("p",{className:"page-subtitle",children:"AI crawler hits and referral sessions from your server logs."})]}),!w()&&e.jsx("div",{className:"flex flex-wrap items-center justify-end gap-2",children:e.jsxs(C,{type:"button",variant:"outline",size:"sm",onClick:()=>r(!0),disabled:!i,children:[e.jsx(q,{className:"size-3.5"}),"Connect a source"]})})]}),e.jsxs("section",{children:[o.length>1&&e.jsxs("label",{className:"mb-4 flex w-fit items-center gap-2 text-sm font-medium text-secondary",htmlFor:"traffic-project",children:["Project",e.jsx("select",{id:"traffic-project",className:"h-8 min-w-44 rounded-md border border-base bg-bg px-2 text-sm text-heading outline-none transition focus:border-mono-500 focus:ring-1 focus:ring-mono-500",value:i,onChange:l=>a(l.target.value),children:o.map(l=>e.jsx("option",{value:l.name,children:l.displayName??l.name},l.id))})]}),i?d.isLoading?e.jsx(S,{className:"p-6 text-center text-sm text-muted",children:"Loading sources…"}):u.length===0?e.jsxs(S,{className:"p-8 text-center",children:[e.jsxs("p",{className:"text-sm text-neutral",children:["No traffic sources connected for ",i,"."]}),!w()&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mt-1 text-sm text-secondary",children:"Connect a source to start collecting traffic."}),e.jsx("div",{className:"mt-4 flex flex-wrap items-center justify-center gap-2",children:e.jsxs(C,{type:"button",variant:"outline",size:"sm",onClick:()=>r(!0),children:[e.jsx(q,{className:"size-3.5"}),"Connect a source"]})})]})]}):e.jsx(ue,{projectName:i,sources:u}):e.jsx(S,{className:"p-6 text-center text-sm text-muted",children:"No projects yet."})]}),!w()&&e.jsx(re,{open:n,onOpenChange:r,projectName:i})]})}function ue({projectName:t,sources:a}){const n=L({queries:a.map(s=>({...W({client:F,path:{name:t,id:s.id}}),staleTime:3e4}))}),r=a.map((s,o)=>({source:s,detail:n[o]?.data,isLoading:n[o]?.isLoading??!1}));return e.jsx("div",{className:"rounded-xl border border-default bg-surface overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-bg-elevated/50 text-[10px] font-semibold uppercase tracking-wider text-muted",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-2 text-left",children:"Source"}),e.jsx("th",{className:"px-4 py-2 text-left",children:"Status"}),e.jsx("th",{className:"px-4 py-2 text-left",children:"Last sync"}),e.jsx("th",{className:"px-4 py-2 text-right",children:"Content crawls"}),e.jsx("th",{className:"px-4 py-2 text-right",children:"Infra crawls"}),e.jsx("th",{className:"px-4 py-2 text-right",children:"AI fetches"}),e.jsx("th",{className:"px-4 py-2 text-right",children:"AI referrals"}),e.jsx("th",{className:"px-4 py-2 text-right"})]})}),e.jsx("tbody",{className:"divide-y divide-mono-800/60",children:r.map(({source:s,detail:o,isLoading:i})=>e.jsxs("tr",{className:"hover:bg-bg-elevated/40 transition-colors",children:[e.jsx("td",{className:"px-4 py-3",children:e.jsx("div",{className:"font-medium text-heading",children:s.displayName})}),e.jsxs("td",{className:"px-4 py-3",children:[e.jsx(G,{tone:K(s.status),children:s.status}),s.lastError?e.jsx("p",{className:"mt-1 max-w-[18rem] truncate text-sm text-negative-400",title:s.lastError,children:s.lastError}):null]}),e.jsx("td",{className:"px-4 py-3 text-neutral",children:de(s.lastSyncedAt)}),e.jsx("td",{className:"px-4 py-3 text-right tabular-nums text-heading",title:o?`${o.totals24h.crawlerHits.toLocaleString("en-US")} total crawler hits`:void 0,children:i?"—":v(o?.totals24h.crawlerContentHits??0)}),e.jsx("td",{className:"px-4 py-3 text-right tabular-nums text-muted",children:i?"—":v(o?.totals24h.crawlerInfraHits??0)}),e.jsx("td",{className:"px-4 py-3 text-right tabular-nums text-heading",children:i?"—":v(o?.totals24h.aiUserFetchHits??0)}),e.jsx("td",{className:"px-4 py-3 text-right tabular-nums text-heading",children:i?"—":v(o?.totals24h.aiReferralHits??0)}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsxs(U,{to:"/traffic/$projectName/$sourceId",params:{projectName:t,sourceId:s.id},className:"inline-flex items-center gap-1 text-sm text-secondary hover:text-heading",children:["View",e.jsx(te,{className:"size-3.5"})]})})]},s.id))})]})})}export{ye as TrafficPage};
@@ -1 +1 @@
1
- import{j as e,C as Re,E as Ee,r as o,L as $e}from"./vendor-tanstack-Dock0eH1.js";import{cE as W,cF as i,I as P,T as Fe,i as ae,B as He,d as H,cG as Pe}from"./index-rqOXhYwp.js";import{g as Ue,h as Oe,i as Me,t as _e,a as De}from"./extract-error-message-BYyBW07F.js";import{e as Y,h as Be,C as re,a as ne,c as ze}from"./ChartPrimitives-BoYe2M-i.js";import{q as Ke,z as Ge,e as We,y as le,X as Ve}from"./vendor-lucide-nYKv-BB7.js";import{R as qe,B as Xe,a as Qe,X as Ye,Y as Ze,T as Je,f as V,g as q}from"./vendor-recharts-D8rt5lKn.js";import"./vendor-radix-4UOaVWza.js";import"./vendor-markdown-Bn7fRwrx.js";import"./vendor-yaml-GWJz5H2G.js";const et=[{value:"all",label:"All status"},{value:"2xx",label:"2xx success"},{value:"3xx",label:"3xx redirect"},{value:"4xx",label:"4xx client error"},{value:"5xx",label:"5xx server error"}],he=[{value:"all",label:"All claims"},{value:W.verified,label:"Verified"},{value:W.claimed_unverified,label:"Claimed unverified"},{value:W.unknown_ai_like,label:"Unknown AI-like"}];function tt(s){return s==="all"?null:Number.parseInt(s[0],10)}function fe(s){switch(s.kind){case i.crawler:case i["ai-user-fetch"]:return s.botId;case i["ai-referral"]:return s.product}}function pe(s){switch(s.kind){case i.crawler:case i["ai-user-fetch"]:return s.pathNormalized;case i["ai-referral"]:return s.landingPathNormalized}}function st(s){switch(s.kind){case i.crawler:case i["ai-user-fetch"]:return s.verificationStatus;case i["ai-referral"]:return null}}function at(s,a){if(a==="hour")return s;const r=new Date(s),n=r.getFullYear(),u=String(r.getMonth()+1).padStart(2,"0"),h=String(r.getDate()).padStart(2,"0");return`${n}-${u}-${h}`}function rt(s,a,r){const n=a.pathQuery.trim().toLowerCase(),u=tt(a.statusClass);return s.filter(h=>!(a.selectedBucket&&at(h.tsHour,r)!==a.selectedBucket||a.identity&&fe(h)!==a.identity||a.operator&&h.operator!==a.operator||n&&!pe(h).toLowerCase().includes(n)||u!==null&&Math.floor(h.status/100)!==u||a.verification!=="all"&&st(h)!==a.verification))}function nt(s,a){if(!s||typeof s!="object")return null;const r=s.activeTooltipIndex;let n;if(typeof r=="number")n=r;else if(typeof r=="string"&&r!=="")n=Number(r);else return null;return!Number.isInteger(n)||n<0||n>=a.length?null:a[n]?.bucket??null}const U=[{value:60,label:"1h",granularity:"hour",fetchLimit:500},{value:360,label:"6h",granularity:"hour",fetchLimit:500},{value:1440,label:"24h",granularity:"hour",fetchLimit:500},{value:10080,label:"7d",granularity:"hour",fetchLimit:1e3},{value:720*60,label:"30d",granularity:"day",fetchLimit:2e3},{value:2160*60,label:"90d",granularity:"day",fetchLimit:5e3}],ie=U.find(s=>s.label==="24h")??U[2],L=50,oe=Y[0],ce=Y[2],de=Y[1],ue=Pe();function be(s){const a=new Date(s);return`${a.getMonth()+1}/${a.getDate()} ${String(a.getHours()).padStart(2,"0")}:00`}function lt(s){const a=new Date(`${s}T00:00:00`);return`${a.getMonth()+1}/${a.getDate()}`}function xe(s){if(!s)return"never";const a=Date.now()-new Date(s).getTime(),r=Math.floor(a/6e4);if(r<1)return"just now";if(r<60)return`${r}m ago`;const n=Math.floor(r/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}function me({canGoBack:s,className:a}){const r="inline-flex items-center gap-1";if(s){const n=()=>{window.history.back()};return e.jsxs("button",{type:"button",onClick:n,className:`${r} ${a??""}`,children:[e.jsx(le,{className:"size-3"})," Back"]})}return e.jsxs($e,{to:"/traffic",className:`${r} ${a??""}`,children:[e.jsx(le,{className:"size-3"})," All sources"]})}function Nt(){const s=Re({strict:!1}),a=s.projectName??"",r=Ee(),n=s.sourceId??"",[u,h]=o.useState(ie.value),[f,ye]=o.useState(()=>new Set(["crawler","ai-user-fetch","ai-referral"])),[c,I]=o.useState(null),[p,O]=o.useState(""),[b,M]=o.useState(""),[v,_]=o.useState(""),[N,D]=o.useState("all"),[S,B]=o.useState("all"),[je,z]=o.useState(1),[Z,J]=o.useState(null),[ee,te]=o.useState(null),x=o.useMemo(()=>U.find(t=>t.value===u)??ie,[u]),K=Ue(a||null,n||null),g=Oe(a||null,{kind:"all",sourceId:n||void 0,sinceMinutes:u,limit:x.fetchLimit,granularity:x.granularity}),A=Me(a||null,n||null),l=K.data,w=g.data?.events??[],y=g.data?.totals,R=g.data?.eventRows,E=o.useMemo(()=>w.filter(t=>{switch(t.kind){case i.crawler:return f.has("crawler");case i["ai-user-fetch"]:return f.has("ai-user-fetch");case i["ai-referral"]:return f.has("ai-referral")}}),[w,f]),ve=o.useMemo(()=>{const t=new Set;for(const d of w)t.add(fe(d));return p&&t.add(p),[...t].sort((d,m)=>d.localeCompare(m))},[w,p]),Ne=o.useMemo(()=>{const t=new Set;for(const d of w)t.add(d.operator);return b&&t.add(b),[...t].sort((d,m)=>d.localeCompare(m))},[w,b]),j=o.useMemo(()=>rt(E,{selectedBucket:c,identity:p,operator:b,pathQuery:v,statusClass:N,verification:S},x.granularity),[E,c,p,b,v,N,S,x.granularity]);o.useEffect(()=>{z(1)},[E,c,p,b,v,N,S]);const $=Math.max(1,Math.ceil(j.length/L)),F=Math.min(Math.max(1,je),$),T=(F-1)*L,Se=o.useMemo(()=>j.slice(T,T+L),[j,T]),we=j.length>L,Ce=j.length===0?0:T+1,ke=Math.min(T+L,j.length),se=o.useMemo(()=>c?ge(c,x.granularity):null,[c,x.granularity]),C=o.useMemo(()=>it(g.data?.series.points??[],x.granularity),[g.data?.series.points,x.granularity]),G=t=>{ye(d=>{const m=new Set(d);return m.has(t)?m.size>1&&m.delete(t):m.add(t),m})},Te=t=>{const d=nt(t,C);d&&I(m=>m===d?null:d)},Le=()=>{I(null),O(""),M(""),_(""),D("all"),B("all")},Ie=!!(c||p||b||v.trim()||N!=="all"||S!=="all"),Ae=async()=>{J(null),te(null);try{const t=await A.mutateAsync({sinceMinutes:60});te(`Pulled ${t.pulledEvents} entries · ${t.crawlerHits} crawler · ${t.aiUserFetchHits} AI user fetch · ${t.aiReferralHits} AI referral · ${t.unknownHits} unknown`)}catch(t){J(De(t))}};return!a||!n?e.jsx("div",{className:"page-container",children:e.jsx("p",{className:"text-sm text-muted",children:"Missing project name or source id in URL."})}):K.isLoading?e.jsx("div",{className:"page-container",children:e.jsx("p",{className:"text-sm text-muted",children:"Loading source…"})}):K.isError||!l?e.jsxs("div",{className:"page-container",children:[e.jsx("p",{className:"text-sm text-negative",children:"Could not load this source."}),e.jsx(me,{canGoBack:r,className:"mt-2 text-xs text-secondary hover:text-strong"})]}):e.jsxs("div",{className:"page-container space-y-8",children:[e.jsxs("div",{className:"page-header",children:[e.jsxs("div",{className:"page-header-left",children:[e.jsx(me,{canGoBack:r,className:"text-xs text-muted hover:text-strong"}),e.jsx("h1",{className:"page-title mt-2",children:l.displayName}),e.jsxs("p",{className:"page-subtitle",children:[l.sourceType," source for ",a]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Fe,{tone:_e(l.status),children:l.status}),!ae()&&e.jsxs(He,{type:"button",variant:"outline",size:"sm",disabled:A.isPending,onClick:()=>{Ae()},children:[e.jsx(Ke,{className:`size-3.5 ${A.isPending?"animate-spin":""}`}),A.isPending?"Syncing…":"Sync now"]})]})]}),Z?e.jsx("div",{className:"rounded-md border border-negative-800/50 bg-negative-950/30 px-3 py-2 text-sm text-negative-200",children:Z}):null,ee?e.jsx("div",{className:"rounded-md border border-positive-800/50 bg-positive-950/30 px-3 py-2 text-sm text-positive-200",children:ee}):null,e.jsxs("section",{"aria-labelledby":"traffic-24h-heading",children:[e.jsx("h2",{id:"traffic-24h-heading",className:"mb-3 text-sm font-medium text-heading",children:"Last 24 hours"}),e.jsxs("div",{className:"grid grid-cols-1 divide-y divide-default border-y border-default sm:grid-cols-3 sm:divide-x sm:divide-y-0",children:[e.jsx(Q,{label:"Content crawls",value:l.totals24h.crawlerContentHits,tooltip:`Content and document paths only. Excludes sitemap ${l.totals24h.crawlerSegments.sitemap.toLocaleString("en-US")}, robots ${l.totals24h.crawlerSegments.robots.toLocaleString("en-US")}, assets ${l.totals24h.crawlerSegments.asset.toLocaleString("en-US")}, and ${l.totals24h.crawlerSegments.other.toLocaleString("en-US")} other requests such as feeds, API paths, or downloads. Total crawler hits: ${l.totals24h.crawlerHits.toLocaleString("en-US")}.`}),e.jsx(Q,{label:"AI user fetches",value:l.totals24h.aiUserFetchHits,tooltip:"ChatGPT-User/Perplexity-User fetches initiated by a real user in an AI surface."}),e.jsx(Q,{label:"AI referral sessions",value:l.totals24h.aiReferralHits,tooltip:"Browser click-throughs from AI surfaces, identified by Referer or UTM evidence."})]})]}),e.jsxs("section",{children:[e.jsx("p",{className:"eyebrow mb-4",children:"Latest sync run"}),l.latestRun?e.jsxs(H,{className:"p-4 text-sm",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-6 gap-y-1.5",children:[e.jsxs("span",{className:"text-heading",children:["Status: ",e.jsx("span",{className:"font-medium",children:l.latestRun.status})]}),e.jsxs("span",{className:"text-muted",children:["Started: ",xe(l.latestRun.startedAt)]}),l.latestRun.finishedAt?e.jsxs("span",{className:"text-muted",children:["Finished: ",xe(l.latestRun.finishedAt)]}):null]}),e.jsxs("details",{className:"mt-3",children:[e.jsx("summary",{className:"cursor-pointer text-sm text-secondary hover:text-strong",children:"Run details"}),e.jsx("code",{className:"mt-2 block text-xs text-muted",children:l.latestRun.runId})]}),l.latestRun.error?e.jsx("p",{className:"mt-2 rounded border border-negative-900/40 bg-negative-950/30 px-3 py-2 text-xs text-negative",children:l.latestRun.error}):null]}):e.jsx(H,{className:"px-4 py-3 text-sm text-muted",children:ae()?"No traffic-sync runs recorded yet.":'No traffic-sync runs recorded yet. Hit "Sync now" above to create one.'})]}),e.jsxs("section",{children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-end justify-between gap-x-4 gap-y-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted",children:"Events"}),e.jsx("h2",{className:"mt-1 text-base font-semibold text-primary",children:x.granularity==="day"?"Daily rollups":"Hourly rollups"}),y?e.jsxs("p",{className:"mt-1.5 text-xs text-muted",children:[y.crawlerContentHits.toLocaleString("en-US")," content crawls ·"," ",y.crawlerInfraHits.toLocaleString("en-US")," infra (sitemap/robots/assets) ·"," ",y.aiUserFetchHits.toLocaleString("en-US")," AI user fetches ·"," ",y.aiReferralHits.toLocaleString("en-US")," AI referral sessions · last ",x.label," · ",ue]}):null]}),e.jsx("div",{className:"inline-flex rounded-md border border-base p-0.5",role:"toolbar","aria-label":"Window",children:U.map(t=>e.jsx("button",{type:"button",className:`rounded px-2.5 py-1 text-xs ${u===t.value?"bg-bg-elevated text-heading":"text-secondary hover:text-strong"}`,"aria-pressed":u===t.value,onClick:()=>{h(t.value),I(null)},children:t.label},t.value))})]}),e.jsxs(H,{className:"p-4",children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2",role:"toolbar","aria-label":"Series",children:[e.jsx(X,{label:"Crawler",color:oe,count:y?.crawlerHits??0,active:f.has("crawler"),onToggle:()=>G("crawler")}),e.jsx(X,{label:"AI user fetches",color:ce,count:y?.aiUserFetchHits??0,active:f.has("ai-user-fetch"),onToggle:()=>G("ai-user-fetch")}),e.jsx(X,{label:"AI referral sessions",color:de,count:y?.aiReferralHits??0,active:f.has("ai-referral"),onToggle:()=>G("ai-referral")})]}),g.isError?e.jsxs("p",{className:"py-12 text-center text-xs text-negative-400",children:["Failed to load events: ",g.error instanceof Error?g.error.message:"Unknown error"]}):g.isLoading?e.jsx("p",{className:"py-12 text-center text-xs text-muted",children:"Loading events…"}):C.length===0?e.jsx("p",{className:"py-12 text-center text-xs text-muted",children:"No events in this window."}):e.jsx("div",{className:"h-72",children:e.jsx(qe,{children:e.jsxs(Xe,{data:C,margin:{top:4,right:4,bottom:0,left:0},onClick:Te,style:{cursor:"pointer"},children:[e.jsx(Qe,{stroke:Be,strokeDasharray:"3 3"}),e.jsx(Ye,{dataKey:"label",tick:ne,stroke:re,interval:"preserveStartEnd",minTickGap:x.granularity==="day"?24:32}),e.jsx(Ze,{tick:ne,stroke:re,allowDecimals:!1}),e.jsx(Je,{...ze}),f.has("crawler")?e.jsx(V,{dataKey:"crawler",name:"Crawler",fill:oe,stackId:"a",children:C.map(t=>e.jsx(q,{fillOpacity:c&&c!==t.bucket?.25:1},t.bucket))}):null,f.has("ai-user-fetch")?e.jsx(V,{dataKey:"aiUserFetch",name:"AI user fetch",fill:ce,stackId:"a",children:C.map(t=>e.jsx(q,{fillOpacity:c&&c!==t.bucket?.25:1},t.bucket))}):null,f.has("ai-referral")?e.jsx(V,{dataKey:"aiReferral",name:"AI referral",fill:de,stackId:"a",children:C.map(t=>e.jsx(q,{fillOpacity:c&&c!==t.bucket?.25:1},t.bucket))}):null]})})})]})]}),e.jsxs("section",{children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-end justify-between gap-x-4 gap-y-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted",children:"Event rows"}),e.jsxs("p",{className:"mt-1 text-xs text-muted",children:["Showing ",e.jsx("span",{className:"tabular-nums text-neutral",children:j.length.toLocaleString("en-US")})," of"," ",e.jsx("span",{className:"tabular-nums text-muted",children:E.length.toLocaleString("en-US")})," ",R?.truncated?"loaded events":"events",R?.truncated?e.jsxs(e.Fragment,{children:[" ","· loaded ",e.jsx("span",{className:"tabular-nums text-neutral",children:R.returned.toLocaleString("en-US")})," of"," ",e.jsx("span",{className:"tabular-nums text-muted",children:R.total.toLocaleString("en-US")})," rows"]}):null," ","· ",ue]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"inline-flex items-center text-secondary",children:[e.jsxs("select",{"aria-label":"Filter by identity",value:p,onChange:t=>O(t.target.value),className:"rounded-md border border-base bg-bg px-2.5 py-1.5 text-xs text-strong focus:outline-none focus-visible:ring-1 focus-visible:ring-mono-600",children:[e.jsx("option",{value:"",children:"All identities"}),ve.map(t=>e.jsx("option",{value:t,children:t},t))]}),e.jsx(P,{text:"The specific bot or AI product making the request (e.g., GPTBot, ChatGPT-User, Perplexity). One operator usually runs several identities."})]}),e.jsxs("span",{className:"inline-flex items-center text-secondary",children:[e.jsxs("select",{"aria-label":"Filter by operator",value:b,onChange:t=>M(t.target.value),className:"rounded-md border border-base bg-bg px-2.5 py-1.5 text-xs text-strong focus:outline-none focus-visible:ring-1 focus-visible:ring-mono-600",children:[e.jsx("option",{value:"",children:"All operators"}),Ne.map(t=>e.jsx("option",{value:t,children:t},t))]}),e.jsx(P,{text:"The company that runs the bot or product (e.g., OpenAI, Anthropic, Perplexity). Filtering by operator includes every identity under that company."})]}),e.jsx("select",{"aria-label":"Filter by HTTP status class",value:N,onChange:t=>D(t.target.value),className:"rounded-md border border-base bg-bg px-2.5 py-1.5 text-xs text-strong focus:outline-none focus-visible:ring-1 focus-visible:ring-mono-600",children:et.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}),e.jsx("select",{"aria-label":"Filter by verification claim",value:S,onChange:t=>B(t.target.value),className:"rounded-md border border-base bg-bg px-2.5 py-1.5 text-xs text-strong focus:outline-none focus-visible:ring-1 focus-visible:ring-mono-600",children:he.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}),e.jsx("input",{type:"search","aria-label":"Filter by path",placeholder:"path contains…",value:v,onChange:t=>_(t.target.value),className:"w-44 rounded-md border border-base bg-bg px-2.5 py-1.5 text-xs text-strong placeholder:text-faint focus:outline-none focus-visible:ring-1 focus-visible:ring-mono-600"})]})]}),Ie?e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[se?e.jsx(k,{label:`Bucket: ${se}`,onClear:()=>I(null)}):null,p?e.jsx(k,{label:`Identity: ${p}`,onClear:()=>O("")}):null,b?e.jsx(k,{label:`Operator: ${b}`,onClear:()=>M("")}):null,v.trim()?e.jsx(k,{label:`Path: ${v.trim()}`,onClear:()=>_("")}):null,N!=="all"?e.jsx(k,{label:`Status: ${N}`,onClear:()=>D("all")}):null,S!=="all"?e.jsx(k,{label:`Claim: ${ot(S)}`,onClear:()=>B("all")}):null,e.jsx("button",{type:"button",onClick:Le,className:"text-xs text-muted underline-offset-4 hover:text-strong hover:underline",children:"Clear all"})]}):null,e.jsx(xt,{events:Se}),we?e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-x-4 gap-y-2 text-xs text-secondary",children:[e.jsxs("p",{className:"tabular-nums",children:["Showing ",e.jsx("span",{className:"text-neutral",children:Ce.toLocaleString("en-US")}),"–",e.jsx("span",{className:"text-neutral",children:ke.toLocaleString("en-US")})," of"," ",e.jsx("span",{className:"text-neutral",children:j.length.toLocaleString("en-US")})," events"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>z(t=>Math.max(1,t-1)),disabled:F<=1,"aria-label":"Previous page",className:"inline-flex items-center gap-1 rounded-md border border-base bg-bg px-2.5 py-1.5 text-strong transition hover:border-strong hover:text-primary disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:border-base disabled:hover:text-strong",children:[e.jsx(Ge,{className:"size-3.5"}),"Prev"]}),e.jsxs("span",{className:"tabular-nums",children:["Page ",e.jsx("span",{className:"text-strong",children:F})," of"," ",e.jsx("span",{className:"text-strong",children:$})]}),e.jsxs("button",{type:"button",onClick:()=>z(t=>Math.min($,t+1)),disabled:F>=$,"aria-label":"Next page",className:"inline-flex items-center gap-1 rounded-md border border-base bg-bg px-2.5 py-1.5 text-strong transition hover:border-strong hover:text-primary disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:border-base disabled:hover:text-strong",children:["Next",e.jsx(We,{className:"size-3.5"})]})]})]}):null]}),e.jsxs("details",{className:"border-t border-default pt-4",children:[e.jsx("summary",{className:"cursor-pointer text-sm text-secondary hover:text-strong",children:"How traffic is classified"}),e.jsx("p",{className:"mt-2 max-w-3xl text-sm text-secondary",children:"Crawler requests, AI user fetches, and referrals are recorded separately. Filters expose the underlying evidence."})]})]})}function ge(s,a){return a==="day"?lt(s):be(s)}function it(s,a){return s.map(r=>({bucket:r.bucket,label:ge(r.bucket,a),crawler:r.crawlerHits,aiUserFetch:r.aiUserFetchHits,aiReferral:r.aiReferralHits}))}function ot(s){return he.find(a=>a.value===s)?.label??s}function k({label:s,onClear:a}){return e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded border border-strong bg-surface-inset px-2.5 py-1 text-sm text-strong",children:[s,e.jsx("button",{type:"button",onClick:a,"aria-label":`Clear ${s}`,className:"rounded p-0.5 text-secondary hover:bg-mono-700/60 hover:text-heading",children:e.jsx(Ve,{className:"size-3"})})]})}function X({label:s,color:a,count:r,active:n,onToggle:u}){return e.jsxs("button",{type:"button",onClick:u,"aria-pressed":n,className:`inline-flex items-center gap-2 rounded border px-3 py-1.5 text-xs font-medium transition ${n?"border-strong bg-surface-inset text-heading":"border-base bg-transparent text-muted hover:text-neutral"}`,children:[e.jsx("span",{"aria-hidden":"true",className:`flex size-3 items-center justify-center rounded-sm border transition-opacity ${n?"border-transparent opacity-100":"border-strong opacity-60"}`,style:n?{backgroundColor:a}:void 0,children:n?"✓":""}),e.jsx("span",{children:s}),e.jsx("span",{className:`tabular-nums ${n?"text-secondary":"text-faint"}`,children:r.toLocaleString("en-US")})]})}function Q({label:s,value:a,tooltip:r}){return e.jsxs("div",{className:"px-4 py-3",children:[e.jsxs("p",{className:"flex items-center gap-1 text-sm text-secondary",children:[s,r?e.jsx(P,{text:r}):null]}),e.jsx("p",{className:"mt-1 text-2xl font-semibold tabular-nums text-heading",children:a.toLocaleString("en-US")})]})}function ct(s){switch(s){case i.crawler:return"Crawler";case i["ai-user-fetch"]:return"AI hit";case i["ai-referral"]:return"AI referral"}}function dt(s){switch(s.kind){case i.crawler:case i["ai-user-fetch"]:return s.botId;case i["ai-referral"]:return s.product}}function ut(s){switch(s.kind){case i.crawler:case i["ai-user-fetch"]:return`${s.verificationStatus} · HTTP ${s.status}`;case i["ai-referral"]:return`${s.evidenceType} · ${s.sourceDomain}`}}function xt({events:s}){return s.length===0?e.jsx(H,{className:"p-6 text-center text-sm text-muted",children:"No event rows match the current filters."}):e.jsx("div",{className:"rounded-xl border border-default bg-surface overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-bg-elevated/50 text-[10px] font-semibold uppercase tracking-wider text-muted",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-2 text-left",children:"Hour"}),e.jsx("th",{className:"px-4 py-2 text-left",children:"Kind"}),e.jsx("th",{className:"px-4 py-2 text-left",children:"Identity"}),e.jsx("th",{className:"px-4 py-2 text-left",children:"Evidence / status"}),e.jsx("th",{className:"px-4 py-2 text-left",children:"Path"}),e.jsx("th",{className:"px-4 py-2 text-right",children:e.jsxs("span",{className:"inline-flex items-center",children:["Hits",e.jsx(P,{text:"Each row is one hour-bucket, not one request. Hits is the number of requests in that hour that shared the same identity, path, HTTP status, and verification claim."})]})})]})}),e.jsx("tbody",{className:"divide-y divide-mono-800/60",children:s.map((a,r)=>e.jsxs("tr",{className:"hover:bg-bg-elevated/40 transition-colors",children:[e.jsx("td",{className:"px-4 py-2 font-mono text-xs text-neutral",children:be(a.tsHour)}),e.jsx("td",{className:"px-4 py-2 text-neutral",children:ct(a.kind)}),e.jsxs("td",{className:"px-4 py-2 text-heading",children:[dt(a),e.jsx("span",{className:"ml-2 text-[11px] text-muted",children:a.operator})]}),e.jsx("td",{className:"px-4 py-2 text-neutral",children:ut(a)}),e.jsx("td",{className:"px-4 py-2 truncate font-mono text-xs text-neutral",children:pe(a)}),e.jsx("td",{className:"px-4 py-2 text-right tabular-nums text-heading",children:a.hits})]},`${a.kind}:${a.tsHour}:${r}`))})]})})}export{Q as TrafficKpi,Nt as TrafficSourceDetailPage};
1
+ import{j as e,C as Re,E as Ee,r as o,L as $e}from"./vendor-tanstack-Dock0eH1.js";import{cE as W,cF as i,I as P,T as Fe,i as ae,B as He,d as H,cG as Pe}from"./index-CcS2bDjR.js";import{g as Ue,h as Oe,i as Me,t as _e,a as De}from"./extract-error-message-CHW-A3AQ.js";import{e as Y,h as Be,C as re,a as ne,c as ze}from"./ChartPrimitives-BoYe2M-i.js";import{q as Ke,z as Ge,e as We,y as le,X as Ve}from"./vendor-lucide-nYKv-BB7.js";import{R as qe,B as Xe,a as Qe,X as Ye,Y as Ze,T as Je,f as V,g as q}from"./vendor-recharts-D8rt5lKn.js";import"./vendor-radix-4UOaVWza.js";import"./vendor-markdown-Bn7fRwrx.js";import"./vendor-yaml-GWJz5H2G.js";const et=[{value:"all",label:"All status"},{value:"2xx",label:"2xx success"},{value:"3xx",label:"3xx redirect"},{value:"4xx",label:"4xx client error"},{value:"5xx",label:"5xx server error"}],he=[{value:"all",label:"All claims"},{value:W.verified,label:"Verified"},{value:W.claimed_unverified,label:"Claimed unverified"},{value:W.unknown_ai_like,label:"Unknown AI-like"}];function tt(s){return s==="all"?null:Number.parseInt(s[0],10)}function fe(s){switch(s.kind){case i.crawler:case i["ai-user-fetch"]:return s.botId;case i["ai-referral"]:return s.product}}function pe(s){switch(s.kind){case i.crawler:case i["ai-user-fetch"]:return s.pathNormalized;case i["ai-referral"]:return s.landingPathNormalized}}function st(s){switch(s.kind){case i.crawler:case i["ai-user-fetch"]:return s.verificationStatus;case i["ai-referral"]:return null}}function at(s,a){if(a==="hour")return s;const r=new Date(s),n=r.getFullYear(),u=String(r.getMonth()+1).padStart(2,"0"),h=String(r.getDate()).padStart(2,"0");return`${n}-${u}-${h}`}function rt(s,a,r){const n=a.pathQuery.trim().toLowerCase(),u=tt(a.statusClass);return s.filter(h=>!(a.selectedBucket&&at(h.tsHour,r)!==a.selectedBucket||a.identity&&fe(h)!==a.identity||a.operator&&h.operator!==a.operator||n&&!pe(h).toLowerCase().includes(n)||u!==null&&Math.floor(h.status/100)!==u||a.verification!=="all"&&st(h)!==a.verification))}function nt(s,a){if(!s||typeof s!="object")return null;const r=s.activeTooltipIndex;let n;if(typeof r=="number")n=r;else if(typeof r=="string"&&r!=="")n=Number(r);else return null;return!Number.isInteger(n)||n<0||n>=a.length?null:a[n]?.bucket??null}const U=[{value:60,label:"1h",granularity:"hour",fetchLimit:500},{value:360,label:"6h",granularity:"hour",fetchLimit:500},{value:1440,label:"24h",granularity:"hour",fetchLimit:500},{value:10080,label:"7d",granularity:"hour",fetchLimit:1e3},{value:720*60,label:"30d",granularity:"day",fetchLimit:2e3},{value:2160*60,label:"90d",granularity:"day",fetchLimit:5e3}],ie=U.find(s=>s.label==="24h")??U[2],L=50,oe=Y[0],ce=Y[2],de=Y[1],ue=Pe();function be(s){const a=new Date(s);return`${a.getMonth()+1}/${a.getDate()} ${String(a.getHours()).padStart(2,"0")}:00`}function lt(s){const a=new Date(`${s}T00:00:00`);return`${a.getMonth()+1}/${a.getDate()}`}function xe(s){if(!s)return"never";const a=Date.now()-new Date(s).getTime(),r=Math.floor(a/6e4);if(r<1)return"just now";if(r<60)return`${r}m ago`;const n=Math.floor(r/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}function me({canGoBack:s,className:a}){const r="inline-flex items-center gap-1";if(s){const n=()=>{window.history.back()};return e.jsxs("button",{type:"button",onClick:n,className:`${r} ${a??""}`,children:[e.jsx(le,{className:"size-3"})," Back"]})}return e.jsxs($e,{to:"/traffic",className:`${r} ${a??""}`,children:[e.jsx(le,{className:"size-3"})," All sources"]})}function Nt(){const s=Re({strict:!1}),a=s.projectName??"",r=Ee(),n=s.sourceId??"",[u,h]=o.useState(ie.value),[f,ye]=o.useState(()=>new Set(["crawler","ai-user-fetch","ai-referral"])),[c,I]=o.useState(null),[p,O]=o.useState(""),[b,M]=o.useState(""),[v,_]=o.useState(""),[N,D]=o.useState("all"),[S,B]=o.useState("all"),[je,z]=o.useState(1),[Z,J]=o.useState(null),[ee,te]=o.useState(null),x=o.useMemo(()=>U.find(t=>t.value===u)??ie,[u]),K=Ue(a||null,n||null),g=Oe(a||null,{kind:"all",sourceId:n||void 0,sinceMinutes:u,limit:x.fetchLimit,granularity:x.granularity}),A=Me(a||null,n||null),l=K.data,w=g.data?.events??[],y=g.data?.totals,R=g.data?.eventRows,E=o.useMemo(()=>w.filter(t=>{switch(t.kind){case i.crawler:return f.has("crawler");case i["ai-user-fetch"]:return f.has("ai-user-fetch");case i["ai-referral"]:return f.has("ai-referral")}}),[w,f]),ve=o.useMemo(()=>{const t=new Set;for(const d of w)t.add(fe(d));return p&&t.add(p),[...t].sort((d,m)=>d.localeCompare(m))},[w,p]),Ne=o.useMemo(()=>{const t=new Set;for(const d of w)t.add(d.operator);return b&&t.add(b),[...t].sort((d,m)=>d.localeCompare(m))},[w,b]),j=o.useMemo(()=>rt(E,{selectedBucket:c,identity:p,operator:b,pathQuery:v,statusClass:N,verification:S},x.granularity),[E,c,p,b,v,N,S,x.granularity]);o.useEffect(()=>{z(1)},[E,c,p,b,v,N,S]);const $=Math.max(1,Math.ceil(j.length/L)),F=Math.min(Math.max(1,je),$),T=(F-1)*L,Se=o.useMemo(()=>j.slice(T,T+L),[j,T]),we=j.length>L,Ce=j.length===0?0:T+1,ke=Math.min(T+L,j.length),se=o.useMemo(()=>c?ge(c,x.granularity):null,[c,x.granularity]),C=o.useMemo(()=>it(g.data?.series.points??[],x.granularity),[g.data?.series.points,x.granularity]),G=t=>{ye(d=>{const m=new Set(d);return m.has(t)?m.size>1&&m.delete(t):m.add(t),m})},Te=t=>{const d=nt(t,C);d&&I(m=>m===d?null:d)},Le=()=>{I(null),O(""),M(""),_(""),D("all"),B("all")},Ie=!!(c||p||b||v.trim()||N!=="all"||S!=="all"),Ae=async()=>{J(null),te(null);try{const t=await A.mutateAsync({sinceMinutes:60});te(`Pulled ${t.pulledEvents} entries · ${t.crawlerHits} crawler · ${t.aiUserFetchHits} AI user fetch · ${t.aiReferralHits} AI referral · ${t.unknownHits} unknown`)}catch(t){J(De(t))}};return!a||!n?e.jsx("div",{className:"page-container",children:e.jsx("p",{className:"text-sm text-muted",children:"Missing project name or source id in URL."})}):K.isLoading?e.jsx("div",{className:"page-container",children:e.jsx("p",{className:"text-sm text-muted",children:"Loading source…"})}):K.isError||!l?e.jsxs("div",{className:"page-container",children:[e.jsx("p",{className:"text-sm text-negative",children:"Could not load this source."}),e.jsx(me,{canGoBack:r,className:"mt-2 text-xs text-secondary hover:text-strong"})]}):e.jsxs("div",{className:"page-container space-y-8",children:[e.jsxs("div",{className:"page-header",children:[e.jsxs("div",{className:"page-header-left",children:[e.jsx(me,{canGoBack:r,className:"text-xs text-muted hover:text-strong"}),e.jsx("h1",{className:"page-title mt-2",children:l.displayName}),e.jsxs("p",{className:"page-subtitle",children:[l.sourceType," source for ",a]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Fe,{tone:_e(l.status),children:l.status}),!ae()&&e.jsxs(He,{type:"button",variant:"outline",size:"sm",disabled:A.isPending,onClick:()=>{Ae()},children:[e.jsx(Ke,{className:`size-3.5 ${A.isPending?"animate-spin":""}`}),A.isPending?"Syncing…":"Sync now"]})]})]}),Z?e.jsx("div",{className:"rounded-md border border-negative-800/50 bg-negative-950/30 px-3 py-2 text-sm text-negative-200",children:Z}):null,ee?e.jsx("div",{className:"rounded-md border border-positive-800/50 bg-positive-950/30 px-3 py-2 text-sm text-positive-200",children:ee}):null,e.jsxs("section",{"aria-labelledby":"traffic-24h-heading",children:[e.jsx("h2",{id:"traffic-24h-heading",className:"mb-3 text-sm font-medium text-heading",children:"Last 24 hours"}),e.jsxs("div",{className:"grid grid-cols-1 divide-y divide-default border-y border-default sm:grid-cols-3 sm:divide-x sm:divide-y-0",children:[e.jsx(Q,{label:"Content crawls",value:l.totals24h.crawlerContentHits,tooltip:`Content and document paths only. Excludes sitemap ${l.totals24h.crawlerSegments.sitemap.toLocaleString("en-US")}, robots ${l.totals24h.crawlerSegments.robots.toLocaleString("en-US")}, assets ${l.totals24h.crawlerSegments.asset.toLocaleString("en-US")}, and ${l.totals24h.crawlerSegments.other.toLocaleString("en-US")} other requests such as feeds, API paths, or downloads. Total crawler hits: ${l.totals24h.crawlerHits.toLocaleString("en-US")}.`}),e.jsx(Q,{label:"AI user fetches",value:l.totals24h.aiUserFetchHits,tooltip:"ChatGPT-User/Perplexity-User fetches initiated by a real user in an AI surface."}),e.jsx(Q,{label:"AI referral sessions",value:l.totals24h.aiReferralHits,tooltip:"Browser click-throughs from AI surfaces, identified by Referer or UTM evidence."})]})]}),e.jsxs("section",{children:[e.jsx("p",{className:"eyebrow mb-4",children:"Latest sync run"}),l.latestRun?e.jsxs(H,{className:"p-4 text-sm",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-6 gap-y-1.5",children:[e.jsxs("span",{className:"text-heading",children:["Status: ",e.jsx("span",{className:"font-medium",children:l.latestRun.status})]}),e.jsxs("span",{className:"text-muted",children:["Started: ",xe(l.latestRun.startedAt)]}),l.latestRun.finishedAt?e.jsxs("span",{className:"text-muted",children:["Finished: ",xe(l.latestRun.finishedAt)]}):null]}),e.jsxs("details",{className:"mt-3",children:[e.jsx("summary",{className:"cursor-pointer text-sm text-secondary hover:text-strong",children:"Run details"}),e.jsx("code",{className:"mt-2 block text-xs text-muted",children:l.latestRun.runId})]}),l.latestRun.error?e.jsx("p",{className:"mt-2 rounded border border-negative-900/40 bg-negative-950/30 px-3 py-2 text-xs text-negative",children:l.latestRun.error}):null]}):e.jsx(H,{className:"px-4 py-3 text-sm text-muted",children:ae()?"No traffic-sync runs recorded yet.":'No traffic-sync runs recorded yet. Hit "Sync now" above to create one.'})]}),e.jsxs("section",{children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-end justify-between gap-x-4 gap-y-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted",children:"Events"}),e.jsx("h2",{className:"mt-1 text-base font-semibold text-primary",children:x.granularity==="day"?"Daily rollups":"Hourly rollups"}),y?e.jsxs("p",{className:"mt-1.5 text-xs text-muted",children:[y.crawlerContentHits.toLocaleString("en-US")," content crawls ·"," ",y.crawlerInfraHits.toLocaleString("en-US")," infra (sitemap/robots/assets) ·"," ",y.aiUserFetchHits.toLocaleString("en-US")," AI user fetches ·"," ",y.aiReferralHits.toLocaleString("en-US")," AI referral sessions · last ",x.label," · ",ue]}):null]}),e.jsx("div",{className:"inline-flex rounded-md border border-base p-0.5",role:"toolbar","aria-label":"Window",children:U.map(t=>e.jsx("button",{type:"button",className:`rounded px-2.5 py-1 text-xs ${u===t.value?"bg-bg-elevated text-heading":"text-secondary hover:text-strong"}`,"aria-pressed":u===t.value,onClick:()=>{h(t.value),I(null)},children:t.label},t.value))})]}),e.jsxs(H,{className:"p-4",children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2",role:"toolbar","aria-label":"Series",children:[e.jsx(X,{label:"Crawler",color:oe,count:y?.crawlerHits??0,active:f.has("crawler"),onToggle:()=>G("crawler")}),e.jsx(X,{label:"AI user fetches",color:ce,count:y?.aiUserFetchHits??0,active:f.has("ai-user-fetch"),onToggle:()=>G("ai-user-fetch")}),e.jsx(X,{label:"AI referral sessions",color:de,count:y?.aiReferralHits??0,active:f.has("ai-referral"),onToggle:()=>G("ai-referral")})]}),g.isError?e.jsxs("p",{className:"py-12 text-center text-xs text-negative-400",children:["Failed to load events: ",g.error instanceof Error?g.error.message:"Unknown error"]}):g.isLoading?e.jsx("p",{className:"py-12 text-center text-xs text-muted",children:"Loading events…"}):C.length===0?e.jsx("p",{className:"py-12 text-center text-xs text-muted",children:"No events in this window."}):e.jsx("div",{className:"h-72",children:e.jsx(qe,{children:e.jsxs(Xe,{data:C,margin:{top:4,right:4,bottom:0,left:0},onClick:Te,style:{cursor:"pointer"},children:[e.jsx(Qe,{stroke:Be,strokeDasharray:"3 3"}),e.jsx(Ye,{dataKey:"label",tick:ne,stroke:re,interval:"preserveStartEnd",minTickGap:x.granularity==="day"?24:32}),e.jsx(Ze,{tick:ne,stroke:re,allowDecimals:!1}),e.jsx(Je,{...ze}),f.has("crawler")?e.jsx(V,{dataKey:"crawler",name:"Crawler",fill:oe,stackId:"a",children:C.map(t=>e.jsx(q,{fillOpacity:c&&c!==t.bucket?.25:1},t.bucket))}):null,f.has("ai-user-fetch")?e.jsx(V,{dataKey:"aiUserFetch",name:"AI user fetch",fill:ce,stackId:"a",children:C.map(t=>e.jsx(q,{fillOpacity:c&&c!==t.bucket?.25:1},t.bucket))}):null,f.has("ai-referral")?e.jsx(V,{dataKey:"aiReferral",name:"AI referral",fill:de,stackId:"a",children:C.map(t=>e.jsx(q,{fillOpacity:c&&c!==t.bucket?.25:1},t.bucket))}):null]})})})]})]}),e.jsxs("section",{children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-end justify-between gap-x-4 gap-y-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted",children:"Event rows"}),e.jsxs("p",{className:"mt-1 text-xs text-muted",children:["Showing ",e.jsx("span",{className:"tabular-nums text-neutral",children:j.length.toLocaleString("en-US")})," of"," ",e.jsx("span",{className:"tabular-nums text-muted",children:E.length.toLocaleString("en-US")})," ",R?.truncated?"loaded events":"events",R?.truncated?e.jsxs(e.Fragment,{children:[" ","· loaded ",e.jsx("span",{className:"tabular-nums text-neutral",children:R.returned.toLocaleString("en-US")})," of"," ",e.jsx("span",{className:"tabular-nums text-muted",children:R.total.toLocaleString("en-US")})," rows"]}):null," ","· ",ue]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"inline-flex items-center text-secondary",children:[e.jsxs("select",{"aria-label":"Filter by identity",value:p,onChange:t=>O(t.target.value),className:"rounded-md border border-base bg-bg px-2.5 py-1.5 text-xs text-strong focus:outline-none focus-visible:ring-1 focus-visible:ring-mono-600",children:[e.jsx("option",{value:"",children:"All identities"}),ve.map(t=>e.jsx("option",{value:t,children:t},t))]}),e.jsx(P,{text:"The specific bot or AI product making the request (e.g., GPTBot, ChatGPT-User, Perplexity). One operator usually runs several identities."})]}),e.jsxs("span",{className:"inline-flex items-center text-secondary",children:[e.jsxs("select",{"aria-label":"Filter by operator",value:b,onChange:t=>M(t.target.value),className:"rounded-md border border-base bg-bg px-2.5 py-1.5 text-xs text-strong focus:outline-none focus-visible:ring-1 focus-visible:ring-mono-600",children:[e.jsx("option",{value:"",children:"All operators"}),Ne.map(t=>e.jsx("option",{value:t,children:t},t))]}),e.jsx(P,{text:"The company that runs the bot or product (e.g., OpenAI, Anthropic, Perplexity). Filtering by operator includes every identity under that company."})]}),e.jsx("select",{"aria-label":"Filter by HTTP status class",value:N,onChange:t=>D(t.target.value),className:"rounded-md border border-base bg-bg px-2.5 py-1.5 text-xs text-strong focus:outline-none focus-visible:ring-1 focus-visible:ring-mono-600",children:et.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}),e.jsx("select",{"aria-label":"Filter by verification claim",value:S,onChange:t=>B(t.target.value),className:"rounded-md border border-base bg-bg px-2.5 py-1.5 text-xs text-strong focus:outline-none focus-visible:ring-1 focus-visible:ring-mono-600",children:he.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}),e.jsx("input",{type:"search","aria-label":"Filter by path",placeholder:"path contains…",value:v,onChange:t=>_(t.target.value),className:"w-44 rounded-md border border-base bg-bg px-2.5 py-1.5 text-xs text-strong placeholder:text-faint focus:outline-none focus-visible:ring-1 focus-visible:ring-mono-600"})]})]}),Ie?e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[se?e.jsx(k,{label:`Bucket: ${se}`,onClear:()=>I(null)}):null,p?e.jsx(k,{label:`Identity: ${p}`,onClear:()=>O("")}):null,b?e.jsx(k,{label:`Operator: ${b}`,onClear:()=>M("")}):null,v.trim()?e.jsx(k,{label:`Path: ${v.trim()}`,onClear:()=>_("")}):null,N!=="all"?e.jsx(k,{label:`Status: ${N}`,onClear:()=>D("all")}):null,S!=="all"?e.jsx(k,{label:`Claim: ${ot(S)}`,onClear:()=>B("all")}):null,e.jsx("button",{type:"button",onClick:Le,className:"text-xs text-muted underline-offset-4 hover:text-strong hover:underline",children:"Clear all"})]}):null,e.jsx(xt,{events:Se}),we?e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-x-4 gap-y-2 text-xs text-secondary",children:[e.jsxs("p",{className:"tabular-nums",children:["Showing ",e.jsx("span",{className:"text-neutral",children:Ce.toLocaleString("en-US")}),"–",e.jsx("span",{className:"text-neutral",children:ke.toLocaleString("en-US")})," of"," ",e.jsx("span",{className:"text-neutral",children:j.length.toLocaleString("en-US")})," events"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>z(t=>Math.max(1,t-1)),disabled:F<=1,"aria-label":"Previous page",className:"inline-flex items-center gap-1 rounded-md border border-base bg-bg px-2.5 py-1.5 text-strong transition hover:border-strong hover:text-primary disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:border-base disabled:hover:text-strong",children:[e.jsx(Ge,{className:"size-3.5"}),"Prev"]}),e.jsxs("span",{className:"tabular-nums",children:["Page ",e.jsx("span",{className:"text-strong",children:F})," of"," ",e.jsx("span",{className:"text-strong",children:$})]}),e.jsxs("button",{type:"button",onClick:()=>z(t=>Math.min($,t+1)),disabled:F>=$,"aria-label":"Next page",className:"inline-flex items-center gap-1 rounded-md border border-base bg-bg px-2.5 py-1.5 text-strong transition hover:border-strong hover:text-primary disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:border-base disabled:hover:text-strong",children:["Next",e.jsx(We,{className:"size-3.5"})]})]})]}):null]}),e.jsxs("details",{className:"border-t border-default pt-4",children:[e.jsx("summary",{className:"cursor-pointer text-sm text-secondary hover:text-strong",children:"How traffic is classified"}),e.jsx("p",{className:"mt-2 max-w-3xl text-sm text-secondary",children:"Crawler requests, AI user fetches, and referrals are recorded separately. Filters expose the underlying evidence."})]})]})}function ge(s,a){return a==="day"?lt(s):be(s)}function it(s,a){return s.map(r=>({bucket:r.bucket,label:ge(r.bucket,a),crawler:r.crawlerHits,aiUserFetch:r.aiUserFetchHits,aiReferral:r.aiReferralHits}))}function ot(s){return he.find(a=>a.value===s)?.label??s}function k({label:s,onClear:a}){return e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded border border-strong bg-surface-inset px-2.5 py-1 text-sm text-strong",children:[s,e.jsx("button",{type:"button",onClick:a,"aria-label":`Clear ${s}`,className:"rounded p-0.5 text-secondary hover:bg-mono-700/60 hover:text-heading",children:e.jsx(Ve,{className:"size-3"})})]})}function X({label:s,color:a,count:r,active:n,onToggle:u}){return e.jsxs("button",{type:"button",onClick:u,"aria-pressed":n,className:`inline-flex items-center gap-2 rounded border px-3 py-1.5 text-xs font-medium transition ${n?"border-strong bg-surface-inset text-heading":"border-base bg-transparent text-muted hover:text-neutral"}`,children:[e.jsx("span",{"aria-hidden":"true",className:`flex size-3 items-center justify-center rounded-sm border transition-opacity ${n?"border-transparent opacity-100":"border-strong opacity-60"}`,style:n?{backgroundColor:a}:void 0,children:n?"✓":""}),e.jsx("span",{children:s}),e.jsx("span",{className:`tabular-nums ${n?"text-secondary":"text-faint"}`,children:r.toLocaleString("en-US")})]})}function Q({label:s,value:a,tooltip:r}){return e.jsxs("div",{className:"px-4 py-3",children:[e.jsxs("p",{className:"flex items-center gap-1 text-sm text-secondary",children:[s,r?e.jsx(P,{text:r}):null]}),e.jsx("p",{className:"mt-1 text-2xl font-semibold tabular-nums text-heading",children:a.toLocaleString("en-US")})]})}function ct(s){switch(s){case i.crawler:return"Crawler";case i["ai-user-fetch"]:return"AI hit";case i["ai-referral"]:return"AI referral"}}function dt(s){switch(s.kind){case i.crawler:case i["ai-user-fetch"]:return s.botId;case i["ai-referral"]:return s.product}}function ut(s){switch(s.kind){case i.crawler:case i["ai-user-fetch"]:return`${s.verificationStatus} · HTTP ${s.status}`;case i["ai-referral"]:return`${s.evidenceType} · ${s.sourceDomain}`}}function xt({events:s}){return s.length===0?e.jsx(H,{className:"p-6 text-center text-sm text-muted",children:"No event rows match the current filters."}):e.jsx("div",{className:"rounded-xl border border-default bg-surface overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-bg-elevated/50 text-[10px] font-semibold uppercase tracking-wider text-muted",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-2 text-left",children:"Hour"}),e.jsx("th",{className:"px-4 py-2 text-left",children:"Kind"}),e.jsx("th",{className:"px-4 py-2 text-left",children:"Identity"}),e.jsx("th",{className:"px-4 py-2 text-left",children:"Evidence / status"}),e.jsx("th",{className:"px-4 py-2 text-left",children:"Path"}),e.jsx("th",{className:"px-4 py-2 text-right",children:e.jsxs("span",{className:"inline-flex items-center",children:["Hits",e.jsx(P,{text:"Each row is one hour-bucket, not one request. Hits is the number of requests in that hour that shared the same identity, path, HTTP status, and verification claim."})]})})]})}),e.jsx("tbody",{className:"divide-y divide-mono-800/60",children:s.map((a,r)=>e.jsxs("tr",{className:"hover:bg-bg-elevated/40 transition-colors",children:[e.jsx("td",{className:"px-4 py-2 font-mono text-xs text-neutral",children:be(a.tsHour)}),e.jsx("td",{className:"px-4 py-2 text-neutral",children:ct(a.kind)}),e.jsxs("td",{className:"px-4 py-2 text-heading",children:[dt(a),e.jsx("span",{className:"ml-2 text-[11px] text-muted",children:a.operator})]}),e.jsx("td",{className:"px-4 py-2 text-neutral",children:ut(a)}),e.jsx("td",{className:"px-4 py-2 truncate font-mono text-xs text-neutral",children:pe(a)}),e.jsx("td",{className:"px-4 py-2 text-right tabular-nums text-heading",children:a.hits})]},`${a.kind}:${a.tsHour}:${r}`))})]})})}export{Q as TrafficKpi,Nt as TrafficSourceDetailPage};
@@ -1 +1 @@
1
- import{u as s,r as m,n as c,o}from"./vendor-tanstack-Dock0eH1.js";import{g as u,cH as l,cD as g,cI as S,aH as y,k as t,cJ as v,cK as i,e as T,cL as p,cM as C,cN as h,cO as q}from"./index-rqOXhYwp.js";function F(e){switch(e){case i.connected:return"positive";case i.paused:return"caution";case i.error:return"negative";case i.archived:return"neutral"}}function w(e){const n={};return e.kind&&e.kind!=="all"&&(n.kind=e.kind),e.sourceId&&(n.sourceId=e.sourceId),e.sinceMinutes!==void 0&&(n.since=new Date(Date.now()-e.sinceMinutes*6e4).toISOString()),e.limit!==void 0&&(n.limit=String(e.limit)),e.granularity!==void 0&&(n.granularity=e.granularity),n}function f(e){T(e,"traffic")}function M(e){return s({...l({client:t,path:{name:e??""}}),enabled:!!e,staleTime:u})}function A(e){return s({...q({client:t,path:{name:e??""}}),enabled:!!e,staleTime:u})}function I(e,n){return s({...g({client:t,path:{name:e??"",id:n??""}}),enabled:!!(e&&n),staleTime:u})}function V(e,n){const r=m.useMemo(()=>w(n),[n.kind,n.sourceId,n.sinceMinutes,n.limit,n.granularity]);return s({...S({client:t,path:{name:e??""},query:r}),enabled:!!e,staleTime:u})}function b(e){const n=c();return o({mutationFn:r=>{if(!e)throw new Error("Project is required to connect a Cloud Run source");return h(e,r)},onSuccess:()=>{e&&f(n)}})}function Q(e){const n=c();return o({mutationFn:r=>{if(!e)throw new Error("Project is required to connect a WordPress source");return p(e,r)},onSuccess:()=>{e&&f(n)}})}function R(e){const n=c();return o({mutationFn:r=>{if(!e)throw new Error("Project is required to connect a Vercel source");return C(e,r)},onSuccess:()=>{e&&f(n)}})}function k(e,n){const r=c();return o({mutationFn:d=>{if(!e||!n)throw new Error("Project and sourceId are required to sync");return v(e,n,d??void 0)},onSuccess:()=>{e&&(f(r),r.invalidateQueries({queryKey:y({client:t})}))}})}function a(e){return typeof e=="object"&&e!==null}function E(e){if(e instanceof Error){const n=e;return{message:e.message,code:typeof n.code=="string"?n.code:void 0,details:a(n.details)?n.details:void 0}}if(a(e)){const n=e.error;if(a(n))return{message:typeof n.message=="string"?n.message:"Request failed",code:typeof n.code=="string"?n.code:void 0,details:a(n.details)?n.details:void 0};if(typeof n=="string")return{message:n};const r=e.message;if(typeof r=="string")return{message:r}}return typeof e=="string"?{message:e}:{message:String(e)}}function O(e){return E(e).message}export{O as a,Q as b,R as c,b as d,E as e,M as f,I as g,V as h,k as i,F as t,A as u};
1
+ import{u as s,r as m,n as c,o}from"./vendor-tanstack-Dock0eH1.js";import{g as u,cH as l,cD as g,cI as S,aH as y,k as t,cJ as v,cK as i,e as T,cL as p,cM as C,cN as h,cO as q}from"./index-CcS2bDjR.js";function F(e){switch(e){case i.connected:return"positive";case i.paused:return"caution";case i.error:return"negative";case i.archived:return"neutral"}}function w(e){const n={};return e.kind&&e.kind!=="all"&&(n.kind=e.kind),e.sourceId&&(n.sourceId=e.sourceId),e.sinceMinutes!==void 0&&(n.since=new Date(Date.now()-e.sinceMinutes*6e4).toISOString()),e.limit!==void 0&&(n.limit=String(e.limit)),e.granularity!==void 0&&(n.granularity=e.granularity),n}function f(e){T(e,"traffic")}function M(e){return s({...l({client:t,path:{name:e??""}}),enabled:!!e,staleTime:u})}function A(e){return s({...q({client:t,path:{name:e??""}}),enabled:!!e,staleTime:u})}function I(e,n){return s({...g({client:t,path:{name:e??"",id:n??""}}),enabled:!!(e&&n),staleTime:u})}function V(e,n){const r=m.useMemo(()=>w(n),[n.kind,n.sourceId,n.sinceMinutes,n.limit,n.granularity]);return s({...S({client:t,path:{name:e??""},query:r}),enabled:!!e,staleTime:u})}function b(e){const n=c();return o({mutationFn:r=>{if(!e)throw new Error("Project is required to connect a Cloud Run source");return h(e,r)},onSuccess:()=>{e&&f(n)}})}function Q(e){const n=c();return o({mutationFn:r=>{if(!e)throw new Error("Project is required to connect a WordPress source");return p(e,r)},onSuccess:()=>{e&&f(n)}})}function R(e){const n=c();return o({mutationFn:r=>{if(!e)throw new Error("Project is required to connect a Vercel source");return C(e,r)},onSuccess:()=>{e&&f(n)}})}function k(e,n){const r=c();return o({mutationFn:d=>{if(!e||!n)throw new Error("Project and sourceId are required to sync");return v(e,n,d??void 0)},onSuccess:()=>{e&&(f(r),r.invalidateQueries({queryKey:y({client:t})}))}})}function a(e){return typeof e=="object"&&e!==null}function E(e){if(e instanceof Error){const n=e;return{message:e.message,code:typeof n.code=="string"?n.code:void 0,details:a(n.details)?n.details:void 0}}if(a(e)){const n=e.error;if(a(n))return{message:typeof n.message=="string"?n.message:"Request failed",code:typeof n.code=="string"?n.code:void 0,details:a(n.details)?n.details:void 0};if(typeof n=="string")return{message:n};const r=e.message;if(typeof r=="string")return{message:r}}return typeof e=="string"?{message:e}:{message:String(e)}}function O(e){return E(e).message}export{O as a,Q as b,R as c,b as d,E as e,M as f,I as g,V as h,k as i,F as t,A as u};
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./SiteHealthSection-k4I71wfJ.js","./vendor-tanstack-Dock0eH1.js","./vendor-lucide-nYKv-BB7.js","./ChartPrimitives-BoYe2M-i.js","./vendor-recharts-D8rt5lKn.js","./ProjectPage-DIzi4Ggo.js","./RunRow-BkkYxEjl.js","./extract-error-message-BYyBW07F.js","./AuditHistoryPanel-IYMElyK5.js","./v2-overview-adapter-COMP5UGt.js","./vendor-radix-4UOaVWza.js","./vendor-markdown-Bn7fRwrx.js","./vendor-yaml-GWJz5H2G.js","./RunsPage-DGTrqrTA.js","./HistoryPage-iuETLmwO.js","./SettingsPage-Cwb_Ft9u.js","./BacklinksPage-BMqIPRvZ.js","./TrafficPage-C8nyb8l1.js","./TrafficSourceDetailPage-ry7Da0pV.js","./MeasurementPropertyPage-BzNAaB8X.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./SiteHealthSection-Byp_Fu5K.js","./vendor-tanstack-Dock0eH1.js","./vendor-lucide-nYKv-BB7.js","./ChartPrimitives-BoYe2M-i.js","./vendor-recharts-D8rt5lKn.js","./ProjectPage-D6-9qYKU.js","./RunRow-_RMMaLPt.js","./extract-error-message-CHW-A3AQ.js","./AuditHistoryPanel-DYBAiNCu.js","./v2-overview-adapter-COMP5UGt.js","./vendor-radix-4UOaVWza.js","./vendor-markdown-Bn7fRwrx.js","./vendor-yaml-GWJz5H2G.js","./RunsPage-CaDPSEfE.js","./HistoryPage-CRSuA-J0.js","./SettingsPage-Dcp71zcu.js","./BacklinksPage-p19FCIyh.js","./TrafficPage-BXkXNKYB.js","./TrafficSourceDetailPage-CReS8q0H.js","./MeasurementPropertyPage-Bgr9VeUk.js"])))=>i.map(i=>d[i]);
2
2
  import{c as Ww,d as eS,r as z,j as c,Q as tS,M as aS,q as ye,e as Jc,L as Je,a as nS,t as io,u as Kt,f as iS,h as cs,k as Yb,l as sS,m as Xb,O as cp,n as Mn,o as us,p as oS,s as kt,v as Jb,x as Si,y as rS,z as lS,A as cS}from"./vendor-tanstack-Dock0eH1.js";import{S as uS,O as Pp,P as Wb,C as Ip,a as ev,T as Up,D as tv,R as av}from"./vendor-radix-4UOaVWza.js";import{c as nv}from"./vendor-recharts-D8rt5lKn.js";import{A as dS,X as No,S as mS,L as fo,C as Lp,R as $g,a as iv,M as pS,b as hS,c as fS,d as Vp,T as sv,W as gS,e as $p,f as ov,g as yS,G as bS,P as vS,H as xS,h as kS,i as wS,j as SS,k as jS,l as AS,B as NS,F as CS,m as _S,n as zS,o as ES,p as Hg,E as DS}from"./vendor-lucide-nYKv-BB7.js";import{M as TS}from"./vendor-markdown-Bn7fRwrx.js";import{p as RS}from"./vendor-yaml-GWJz5H2G.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const u of document.querySelectorAll('link[rel="modulepreload"]'))r(u);new MutationObserver(u=>{for(const f of u)if(f.type==="childList")for(const g of f.addedNodes)g.tagName==="LINK"&&g.rel==="modulepreload"&&r(g)}).observe(document,{childList:!0,subtree:!0});function s(u){const f={};return u.integrity&&(f.integrity=u.integrity),u.referrerPolicy&&(f.referrerPolicy=u.referrerPolicy),u.crossOrigin==="use-credentials"?f.credentials="include":u.crossOrigin==="anonymous"?f.credentials="omit":f.credentials="same-origin",f}function r(u){if(u.ep)return;u.ep=!0;const f=s(u);fetch(u.href,f)}})();var Mm={exports:{}},_r={},Pm={exports:{}},Im={};var Gg;function OS(){return Gg||(Gg=1,(function(e){function n(I,ne){var he=I.length;I.push(ne);e:for(;0<he;){var Ee=he-1>>>1,le=I[Ee];if(0<u(le,ne))I[Ee]=ne,I[he]=le,he=Ee;else break e}}function s(I){return I.length===0?null:I[0]}function r(I){if(I.length===0)return null;var ne=I[0],he=I.pop();if(he!==ne){I[0]=he;e:for(var Ee=0,le=I.length,et=le>>>1;Ee<et;){var G=2*(Ee+1)-1,ce=I[G],ie=G+1,re=I[ie];if(0>u(ce,he))ie<le&&0>u(re,ce)?(I[Ee]=re,I[ie]=he,Ee=ie):(I[Ee]=ce,I[G]=he,Ee=G);else if(ie<le&&0>u(re,he))I[Ee]=re,I[ie]=he,Ee=ie;else break e}}return ne}function u(I,ne){var he=I.sortIndex-ne.sortIndex;return he!==0?he:I.id-ne.id}if(e.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var f=performance;e.unstable_now=function(){return f.now()}}else{var g=Date,b=g.now();e.unstable_now=function(){return g.now()-b}}var x=[],k=[],S=1,A=null,j=3,D=!1,R=!1,q=!1,U=!1,V=typeof setTimeout=="function"?setTimeout:null,te=typeof clearTimeout=="function"?clearTimeout:null,X=typeof setImmediate<"u"?setImmediate:null;function ae(I){for(var ne=s(k);ne!==null;){if(ne.callback===null)r(k);else if(ne.startTime<=I)r(k),ne.sortIndex=ne.expirationTime,n(x,ne);else break;ne=s(k)}}function oe(I){if(q=!1,ae(I),!R)if(s(x)!==null)R=!0,fe||(fe=!0,Re());else{var ne=s(k);ne!==null&&ge(oe,ne.startTime-I)}}var fe=!1,M=-1,J=5,_e=-1;function me(){return U?!0:!(e.unstable_now()-_e<J)}function we(){if(U=!1,fe){var I=e.unstable_now();_e=I;var ne=!0;try{e:{R=!1,q&&(q=!1,te(M),M=-1),D=!0;var he=j;try{t:{for(ae(I),A=s(x);A!==null&&!(A.expirationTime>I&&me());){var Ee=A.callback;if(typeof Ee=="function"){A.callback=null,j=A.priorityLevel;var le=Ee(A.expirationTime<=I);if(I=e.unstable_now(),typeof le=="function"){A.callback=le,ae(I),ne=!0;break t}A===s(x)&&r(x),ae(I)}else r(x);A=s(x)}if(A!==null)ne=!0;else{var et=s(k);et!==null&&ge(oe,et.startTime-I),ne=!1}}break e}finally{A=null,j=he,D=!1}ne=void 0}}finally{ne?Re():fe=!1}}}var Re;if(typeof X=="function")Re=function(){X(we)};else if(typeof MessageChannel<"u"){var je=new MessageChannel,Qe=je.port2;je.port1.onmessage=we,Re=function(){Qe.postMessage(null)}}else Re=function(){V(we,0)};function ge(I,ne){M=V(function(){I(e.unstable_now())},ne)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(I){I.callback=null},e.unstable_forceFrameRate=function(I){0>I||125<I?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):J=0<I?Math.floor(1e3/I):5},e.unstable_getCurrentPriorityLevel=function(){return j},e.unstable_next=function(I){switch(j){case 1:case 2:case 3:var ne=3;break;default:ne=j}var he=j;j=ne;try{return I()}finally{j=he}},e.unstable_requestPaint=function(){U=!0},e.unstable_runWithPriority=function(I,ne){switch(I){case 1:case 2:case 3:case 4:case 5:break;default:I=3}var he=j;j=I;try{return ne()}finally{j=he}},e.unstable_scheduleCallback=function(I,ne,he){var Ee=e.unstable_now();switch(typeof he=="object"&&he!==null?(he=he.delay,he=typeof he=="number"&&0<he?Ee+he:Ee):he=Ee,I){case 1:var le=-1;break;case 2:le=250;break;case 5:le=1073741823;break;case 4:le=1e4;break;default:le=5e3}return le=he+le,I={id:S++,callback:ne,priorityLevel:I,startTime:he,expirationTime:le,sortIndex:-1},he>Ee?(I.sortIndex=he,n(k,I),s(x)===null&&I===s(k)&&(q?(te(M),M=-1):q=!0,ge(oe,he-Ee))):(I.sortIndex=le,n(x,I),R||D||(R=!0,fe||(fe=!0,Re()))),I},e.unstable_shouldYield=me,e.unstable_wrapCallback=function(I){var ne=j;return function(){var he=j;j=ne;try{return I.apply(this,arguments)}finally{j=he}}}})(Im)),Im}var Kg;function qS(){return Kg||(Kg=1,Pm.exports=OS()),Pm.exports}var Qg;function BS(){if(Qg)return _r;Qg=1;var e=qS(),n=Ww(),s=eS();function r(t){var a="https://react.dev/errors/"+t;if(1<arguments.length){a+="?args[]="+encodeURIComponent(arguments[1]);for(var i=2;i<arguments.length;i++)a+="&args[]="+encodeURIComponent(arguments[i])}return"Minified React error #"+t+"; visit "+a+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}function u(t){return!(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)}function f(t){var a=t,i=t;if(t.alternate)for(;a.return;)a=a.return;else{t=a;do a=t,(a.flags&4098)!==0&&(i=a.return),t=a.return;while(t)}return a.tag===3?i:null}function g(t){if(t.tag===13){var a=t.memoizedState;if(a===null&&(t=t.alternate,t!==null&&(a=t.memoizedState)),a!==null)return a.dehydrated}return null}function b(t){if(t.tag===31){var a=t.memoizedState;if(a===null&&(t=t.alternate,t!==null&&(a=t.memoizedState)),a!==null)return a.dehydrated}return null}function x(t){if(f(t)!==t)throw Error(r(188))}function k(t){var a=t.alternate;if(!a){if(a=f(t),a===null)throw Error(r(188));return a!==t?null:t}for(var i=t,l=a;;){var d=i.return;if(d===null)break;var p=d.alternate;if(p===null){if(l=d.return,l!==null){i=l;continue}break}if(d.child===p.child){for(p=d.child;p;){if(p===i)return x(d),t;if(p===l)return x(d),a;p=p.sibling}throw Error(r(188))}if(i.return!==l.return)i=d,l=p;else{for(var v=!1,w=d.child;w;){if(w===i){v=!0,i=d,l=p;break}if(w===l){v=!0,l=d,i=p;break}w=w.sibling}if(!v){for(w=p.child;w;){if(w===i){v=!0,i=p,l=d;break}if(w===l){v=!0,l=p,i=d;break}w=w.sibling}if(!v)throw Error(r(189))}}if(i.alternate!==l)throw Error(r(190))}if(i.tag!==3)throw Error(r(188));return i.stateNode.current===i?t:a}function S(t){var a=t.tag;if(a===5||a===26||a===27||a===6)return t;for(t=t.child;t!==null;){if(a=S(t),a!==null)return a;t=t.sibling}return null}var A=Object.assign,j=Symbol.for("react.element"),D=Symbol.for("react.transitional.element"),R=Symbol.for("react.portal"),q=Symbol.for("react.fragment"),U=Symbol.for("react.strict_mode"),V=Symbol.for("react.profiler"),te=Symbol.for("react.consumer"),X=Symbol.for("react.context"),ae=Symbol.for("react.forward_ref"),oe=Symbol.for("react.suspense"),fe=Symbol.for("react.suspense_list"),M=Symbol.for("react.memo"),J=Symbol.for("react.lazy"),_e=Symbol.for("react.activity"),me=Symbol.for("react.memo_cache_sentinel"),we=Symbol.iterator;function Re(t){return t===null||typeof t!="object"?null:(t=we&&t[we]||t["@@iterator"],typeof t=="function"?t:null)}var je=Symbol.for("react.client.reference");function Qe(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===je?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case q:return"Fragment";case V:return"Profiler";case U:return"StrictMode";case oe:return"Suspense";case fe:return"SuspenseList";case _e:return"Activity"}if(typeof t=="object")switch(t.$$typeof){case R:return"Portal";case X:return t.displayName||"Context";case te:return(t._context.displayName||"Context")+".Consumer";case ae:var a=t.render;return t=t.displayName,t||(t=a.displayName||a.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case M:return a=t.displayName||null,a!==null?a:Qe(t.type)||"Memo";case J:a=t._payload,t=t._init;try{return Qe(t(a))}catch{}}return null}var ge=Array.isArray,I=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,ne=s.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,he={pending:!1,data:null,method:null,action:null},Ee=[],le=-1;function et(t){return{current:t}}function G(t){0>le||(t.current=Ee[le],Ee[le]=null,le--)}function ce(t,a){le++,Ee[le]=t.current,t.current=a}var ie=et(null),re=et(null),W=et(null),Z=et(null);function Ce(t,a){switch(ce(W,a),ce(re,t),ce(ie,null),a.nodeType){case 9:case 11:t=(t=a.documentElement)&&(t=t.namespaceURI)?mg(t):0;break;default:if(t=a.tagName,a=a.namespaceURI)a=mg(a),t=pg(a,t);else switch(t){case"svg":t=1;break;case"math":t=2;break;default:t=0}}G(ie),ce(ie,t)}function Ae(){G(ie),G(re),G(W)}function Le(t){t.memoizedState!==null&&ce(Z,t);var a=ie.current,i=pg(a,t.type);a!==i&&(ce(re,t),ce(ie,i))}function Ze(t){re.current===t&&(G(ie),G(re)),Z.current===t&&(G(Z),jr._currentValue=he)}var Lt,Ia;function zt(t){if(Lt===void 0)try{throw Error()}catch(i){var a=i.stack.trim().match(/\n( *(at )?)/);Lt=a&&a[1]||"",Ia=-1<i.stack.indexOf(`
3
3
  at`)?" (<anonymous>)":-1<i.stack.indexOf("@")?"@unknown:0:0":""}return`
4
4
  `+Lt+t+Ia}var Un=!1;function Ei(t,a){if(!t||Un)return"";Un=!0;var i=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var l={DetermineComponentFrameRoot:function(){try{if(a){var ee=function(){throw Error()};if(Object.defineProperty(ee.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(ee,[])}catch(H){var L=H}Reflect.construct(t,[],ee)}else{try{ee.call()}catch(H){L=H}t.call(ee.prototype)}}else{try{throw Error()}catch(H){L=H}(ee=t())&&typeof ee.catch=="function"&&ee.catch(function(){})}}catch(H){if(H&&L&&typeof H.stack=="string")return[H.stack,L.stack]}return[null,null]}};l.DetermineComponentFrameRoot.displayName="DetermineComponentFrameRoot";var d=Object.getOwnPropertyDescriptor(l.DetermineComponentFrameRoot,"name");d&&d.configurable&&Object.defineProperty(l.DetermineComponentFrameRoot,"name",{value:"DetermineComponentFrameRoot"});var p=l.DetermineComponentFrameRoot(),v=p[0],w=p[1];if(v&&w){var C=v.split(`
@@ -80,4 +80,4 @@ spec:
80
80
  `);Ei(qe),Jt(!0)}}catch(F){Ln(F instanceof Error?F.message:"Failed to generate queries"),R({flowVersion:At,onboardingSessionId:j,event:"onboarding.blocked",step:"queries",action:"generate_queries",reasonCode:Gb(F,"unknown")},"onboarding.blocked:queries:generate")}finally{rl(!1)}}},Gn=async()=>{if(!Ce)return;const F=Nt;if(F.length!==0){Oi(!0),ul(null);try{await Y5(Ce,F),_u(!0),await r(),R({flowVersion:At,onboardingSessionId:j,event:"onboarding.step_completed",step:"competitors",method:"manual",countBucket:sn(F.length)},"onboarding.step_completed:competitors"),je(4)}catch(qe){ul(qe instanceof Error?qe.message:"Failed to save competitors"),R({flowVersion:At,onboardingSessionId:j,event:"onboarding.blocked",step:"competitors",action:"save",reasonCode:"unknown"},"onboarding.blocked:competitors:save")}finally{Oi(!1)}}},Li=async()=>{const F=xs.trim();if(F){ks(!0),Po(null);try{await t6("gemini",{apiKey:F}),Qt({title:"Gemini configured",detail:"Provider is ready — continuing setup.",tone:"positive",dedupeKey:"setup:gemini:configured",dedupeMode:"drop"}),Bo(""),await r(),Di(b.providerStatuses.find(qe=>qe.name.toLowerCase()==="gemini")?.name??"gemini"),R({flowVersion:At,onboardingSessionId:j,event:"onboarding.step_completed",step:"system",method:"inline"},"onboarding.step_completed:system")}catch(qe){Po(qe instanceof Error?qe.message:"Failed to save Gemini key"),R({flowVersion:At,onboardingSessionId:j,event:"onboarding.blocked",step:"system",action:"configure_provider",reasonCode:"provider_save_failed"},"onboarding.blocked:system:provider_save_failed")}finally{ks(!1)}}},dn=async()=>{if(!Ce||La){vs(La??"Complete setup before launching the first sweep.");const F=$n??(Ce?Na===0?"no_queries":"run_rejected":"unknown");R({flowVersion:At,onboardingSessionId:j,event:"run.requested",origin:"dashboard_setup",result:"rejected",providerCountBucket:sn(fa.length),queryCountBucket:sn(Na),reasonCode:F});return}Vn(!0),vs(null);try{const F=await zu.mutateAsync({projectName:Ce,projectLabel:he||I||Ce,sourceAction:"setup-launch"});Mi(F.id),ln(!0),R({flowVersion:At,onboardingSessionId:j,event:"run.requested",origin:"dashboard_setup",result:"queued",providerCountBucket:sn(fa.length),queryCountBucket:sn(Na)}),await r()}catch(F){vs(F instanceof Error?F.message:"Failed to queue the visibility sweep. Retry when the instance is ready."),R({flowVersion:At,onboardingSessionId:j,event:"run.requested",origin:"dashboard_setup",result:"rejected",providerCountBucket:sn(fa.length),queryCountBucket:sn(Na),reasonCode:Gb(F,"run_rejected")})}finally{Vn(!1)}},ct=()=>je(F=>Math.max(0,F-1)),ws=(F,qe,pn)=>{R({flowVersion:At,onboardingSessionId:j,event:"onboarding.step_completed",step:F,method:"existing",...pn===void 0?{}:{countBucket:sn(pn)}},`onboarding.step_completed:${F}`),je(qe)},dl=()=>{R({flowVersion:At,onboardingSessionId:j,event:"onboarding.step_completed",step:"queries",method:"skipped",countBucket:"0"},"onboarding.step_completed:queries"),je(3)},mn=()=>{R({flowVersion:At,onboardingSessionId:j,event:"onboarding.step_completed",step:"competitors",method:"skipped",countBucket:"0"},"onboarding.step_completed:competitors"),je(4)},Kn=(()=>{switch(Re){case 0:return c.jsxs(Sa,{className:"surface-card step-card",children:[c.jsx("div",{className:"section-head",children:c.jsxs("div",{children:[c.jsx("p",{className:"eyebrow eyebrow-soft",children:"Step 1 of 5"}),c.jsx("h2",{children:"System check"})]})}),c.jsx("p",{className:"supporting-copy",children:"Checking that your Canonry instance is configured and reachable."}),c.jsx("div",{className:"compact-stack",children:S.healthChecks.map(F=>c.jsxs("div",{className:"health-check-row",children:[c.jsxs("div",{children:[c.jsx("p",{className:"run-row-title",children:F.label}),c.jsx("p",{className:"supporting-copy",children:F.detail}),F.id==="provider"&&F.state!=="ready"&&c.jsxs("div",{className:"mt-3 rounded-md border border-default bg-bg-elevated/40 p-3 space-y-2",children:[c.jsxs("p",{className:"text-xs text-secondary",children:["Paste a Gemini key to enable visibility checks (free at"," ",c.jsx("a",{href:"https://aistudio.google.com/apikey",target:"_blank",rel:"noreferrer",className:"text-positive-400 hover:text-positive underline underline-offset-2",children:"aistudio.google.com"}),")."]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{type:"password",value:xs,onChange:qe=>Bo(qe.target.value),placeholder:"AI... (paste here)",className:"flex-1 rounded-md border border-base bg-bg px-2.5 py-1.5 text-sm text-heading placeholder:text-faint focus:border-mono-600 focus:outline-none font-mono",disabled:Pi}),c.jsx(xe,{type:"button",size:"sm",disabled:Pi||!xs.trim(),onClick:Ut(Li),children:Pi?"Saving...":"Save"})]}),Mo&&c.jsxs("div",{role:"alert",className:"space-y-1 text-xs text-negative",children:[c.jsx("p",{children:Mo}),c.jsx("p",{children:"Check that the key is complete, then retry Save."})]}),c.jsxs("p",{className:"text-sm text-secondary",children:["Connect more answer engines later in"," ",c.jsx(Je,{to:"/settings",className:"text-link hover:underline",children:"Settings"}),"."]})]})]}),c.jsx(ma,{tone:F.state==="ready"?"positive":"caution",title:F.id==="api"?jo(k.apiStatus):F.id==="worker"?jo(k.workerStatus):F.detail,children:F.state==="ready"?"Ready":"Attention"})]},F.id))}),c.jsxs("div",{className:"setup-nav",children:[S.launchState.blockedReason?c.jsx("p",{role:"status",className:"supporting-copy text-negative",children:S.launchState.blockedReason}):c.jsx("span",{}),c.jsx(xe,{type:"button",disabled:!S.launchState.enabled,title:S.launchState.blockedReason,onClick:()=>{R({flowVersion:At,onboardingSessionId:j,event:"onboarding.step_completed",step:"system",method:"automatic"},"onboarding.step_completed:system"),je(we)},children:"Continue"})]})]});case 1:return c.jsxs(Sa,{className:"surface-card step-card",children:[c.jsxs("div",{className:"section-head",children:[c.jsxs("div",{children:[c.jsx("p",{className:"eyebrow eyebrow-soft",children:"Step 2 of 5"}),c.jsx("h2",{children:"Create project"})]}),Ce?c.jsx(ma,{tone:"positive",children:"Created"}):null]}),Ce?c.jsxs("div",{className:"compact-stack",children:[c.jsxs("p",{className:"text-neutral",children:["Project ",c.jsx("span",{className:"text-heading font-medium",children:Ce})," created successfully."]}),c.jsxs("div",{className:"setup-nav",children:[c.jsx(xe,{type:"button",variant:"outline",onClick:ct,children:"Back"}),c.jsx(xe,{type:"button",onClick:()=>ws("project",2),children:"Continue"})]})]}):c.jsxs("div",{className:"compact-stack",children:[c.jsxs("div",{className:"setup-field",children:[c.jsx("label",{className:"setup-label",htmlFor:"project-name",children:"Project name"}),c.jsx("input",{id:"project-name",className:"setup-input",type:"text",placeholder:"my-website",value:I,onChange:F=>ne(F.target.value)}),Yt&&Yt!==I?c.jsxs("p",{className:"supporting-copy",children:["Slug: ",Yt]}):null]}),c.jsxs("div",{className:"setup-field",children:[c.jsx("label",{className:"setup-label",htmlFor:"display-name",children:"Display name (optional)"}),c.jsx("input",{id:"display-name",className:"setup-input",type:"text",placeholder:"My Website",value:he,onChange:F=>Ee(F.target.value)})]}),c.jsxs("div",{className:"setup-field",children:[c.jsx("label",{className:"setup-label",htmlFor:"domain",children:"Canonical domain"}),c.jsx("input",{id:"domain",className:"setup-input",type:"text",placeholder:"example.com",value:le,onChange:F=>et(F.target.value)})]}),c.jsxs("div",{className:"setup-field-row",children:[c.jsxs("div",{className:"setup-field",children:[c.jsx("label",{className:"setup-label",htmlFor:"country",children:"Country"}),c.jsx("input",{id:"country",className:"setup-input",type:"text",placeholder:"US",maxLength:2,value:G,onChange:F=>ce(F.target.value.toUpperCase())})]}),c.jsxs("div",{className:"setup-field",children:[c.jsx("label",{className:"setup-label",htmlFor:"language",children:"Language"}),c.jsx("input",{id:"language",className:"setup-input",type:"text",placeholder:"en",maxLength:5,value:ie,onChange:F=>re(F.target.value.toLowerCase())})]})]}),c.jsxs("label",{className:"flex items-start gap-3 rounded-md border border-default bg-surface p-3 cursor-pointer hover:border-strong",children:[c.jsx("input",{type:"checkbox",className:"mt-0.5 h-4 w-4 rounded border-strong bg-bg",checked:W,onChange:F=>Z(F.target.checked)}),c.jsxs("span",{className:"flex-1",children:[c.jsx("span",{className:"block text-sm text-heading",children:"Auto-extract backlinks"}),c.jsxs("span",{className:"block text-xs text-muted mt-0.5",children:["When a new Common Crawl release syncs, automatically extract backlinks for this project."," ",c.jsx(Je,{to:"/backlinks",className:"text-positive-400 hover:text-positive underline underline-offset-2",children:"Manage backlinks"})]})]})]}),Le?c.jsx("p",{className:"text-negative-400 text-sm",children:Le}):null,c.jsxs("div",{className:"setup-nav",children:[c.jsx(xe,{type:"button",variant:"outline",onClick:ct,children:"Back"}),c.jsx(xe,{type:"button",disabled:!Yt||!le||Lt,onClick:Ut(Ui),children:Lt?"Creating...":"Create project"})]})]})]});case 2:return c.jsxs(Sa,{className:"surface-card step-card",children:[c.jsxs("div",{className:"section-head",children:[c.jsxs("div",{children:[c.jsx("p",{className:"eyebrow eyebrow-soft",children:"Step 3 of 5"}),c.jsx("h2",{children:"Add queries"})]}),X.isError?c.jsx(ma,{tone:"negative",children:"Load failed"}):Ro?c.jsxs(ma,{tone:"positive",children:[st.length," saved"]}):c.jsxs(ma,{tone:"neutral",children:[st.length," quer",st.length!==1?"ies":"y"]})]}),c.jsx("p",{className:"supporting-copy",children:"Enter the queries you want to track, one per line. A rough first list is fine: you can edit them, research more, and add to them at any time from the project."}),X.isError?c.jsxs("div",{className:"compact-stack",children:[c.jsx("div",{role:"alert",className:"rounded-md border border-negative bg-negative-soft p-3 text-sm text-negative",children:"Saved queries could not be loaded. Retry before changing the query basket."}),c.jsxs("div",{className:"setup-nav",children:[c.jsx(xe,{type:"button",variant:"outline",onClick:ct,children:"Back"}),c.jsx(xe,{type:"button",onClick:()=>{X.refetch()},children:"Retry loading queries"})]})]}):Ro?c.jsxs("div",{className:"compact-stack",children:[c.jsx("ul",{className:"detail-list",children:st.map(F=>c.jsx("li",{children:F},F))}),c.jsxs("div",{className:"setup-nav",children:[c.jsx(xe,{type:"button",variant:"outline",onClick:ct,children:"Back"}),c.jsx(xe,{type:"button",onClick:()=>ws("queries",3,st.length),children:"Continue"})]})]}):c.jsxs("div",{className:"compact-stack",children:[fa.length>0?c.jsxs("div",{className:"compact-stack",children:[c.jsxs("div",{className:"flex items-center gap-2 text-muted text-xs uppercase tracking-wide",children:[c.jsx("span",{className:"flex-1 border-t border-base"}),"auto-generate",c.jsx("span",{className:"flex-1 border-t border-base"})]}),c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsxs("div",{className:"setup-field flex-1",children:[c.jsx("label",{className:"setup-label",htmlFor:"gen-provider",children:"Provider"}),c.jsx("select",{id:"gen-provider",className:"setup-input",value:rn,onChange:F=>Di(F.target.value),children:fa.map(F=>c.jsxs("option",{value:F.name,children:[F.displayName??F.name,F.model?` (${F.model})`:""]},F.name))})]}),c.jsxs("div",{className:"setup-field",children:[c.jsx("label",{className:"setup-label",htmlFor:"gen-count",children:"Count"}),c.jsx("select",{id:"gen-count",className:"setup-input",value:Ti,onChange:F=>Cu(Number(F.target.value)),children:[3,5,10,15,20].map(F=>c.jsx("option",{value:F,children:F},F))})]}),c.jsx(xe,{type:"button",variant:"outline",disabled:qo||!rn,onClick:Ut(Hn),children:qo?"Analyzing site...":"Generate"})]}),ll?c.jsx("p",{className:"text-negative-400 text-sm",children:ll}):null]}):null,c.jsxs("div",{className:"flex items-center gap-2 text-muted text-xs uppercase tracking-wide",children:[c.jsx("span",{className:"flex-1 border-t border-base"}),"or type manually",c.jsx("span",{className:"flex-1 border-t border-base"})]}),c.jsxs("div",{className:"setup-field",children:[c.jsx("label",{className:"setup-label",htmlFor:"queries",children:"Queries (one per line)"}),c.jsx("textarea",{id:"queries",className:"setup-textarea",rows:6,placeholder:`emergency dentist brooklyn
81
81
  best invisalign downtown brooklyn
82
82
  pediatric dentist brooklyn heights`,value:Un,onChange:F=>Ei(F.target.value)})]}),gs?c.jsx("p",{className:"text-negative-400 text-sm",children:gs}):null,c.jsxs("div",{className:"setup-nav",children:[c.jsx(xe,{type:"button",variant:"outline",onClick:ct,children:"Back"}),c.jsx(xe,{type:"button",variant:"ghost",onClick:dl,children:"Skip for now"}),c.jsx(xe,{type:"button",disabled:st.length===0||bs,onClick:Ut(Io),children:bs?"Saving...":`Save ${st.length} quer${st.length!==1?"ies":"y"}`})]})]})]});case 3:return c.jsxs(Sa,{className:"surface-card step-card",children:[c.jsxs("div",{className:"section-head",children:[c.jsxs("div",{children:[c.jsx("p",{className:"eyebrow eyebrow-soft",children:"Step 4 of 5"}),c.jsx("h2",{children:"Add competitors"})]}),Ft?c.jsx(ma,{tone:"positive",children:"Saved"}):null]}),c.jsx("p",{className:"supporting-copy",children:"Domains that compete for the same queries. One per line."}),Ft?c.jsxs("div",{className:"compact-stack",children:[c.jsx("ul",{className:"detail-list",children:Nt.map(F=>c.jsx("li",{children:F},F))}),c.jsxs("div",{className:"setup-nav",children:[c.jsx(xe,{type:"button",variant:"outline",onClick:ct,children:"Back"}),c.jsx(xe,{type:"button",onClick:()=>ws("competitors",4,Nt.length),children:"Continue"})]})]}):c.jsxs("div",{className:"compact-stack",children:[c.jsxs("div",{className:"setup-field",children:[c.jsx("label",{className:"setup-label",htmlFor:"competitors",children:"Competitor domains (one per line)"}),c.jsx("textarea",{id:"competitors",className:"setup-textarea",rows:4,placeholder:`competitor1.com
83
- competitor2.com`,value:Zt,onChange:F=>Xa(F.target.value)})]}),cl?c.jsx("p",{className:"text-negative-400 text-sm",children:cl}):null,c.jsxs("div",{className:"setup-nav",children:[c.jsx(xe,{type:"button",variant:"outline",onClick:ct,children:"Back"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(xe,{type:"button",variant:"outline",onClick:mn,children:"Skip"}),c.jsx(xe,{type:"button",disabled:Nt.length===0||Ri,onClick:Ut(Gn),children:Ri?"Saving...":`Save ${Nt.length} competitor${Nt.length!==1?"s":""}`})]})]})]})]});case 4:{const F=Ja.data,qe=F?.status??(Bi===M?.id?M.status:void 0),pn=qe==="completed"||qe==="partial"||qe==="failed"||qe==="cancelled",Qn=F?.snapshots??[],Ss=Qn.filter(Wa=>Wa.citationState==="cited").length,js=Qn.filter(Wa=>Wa.answerMentioned===!0).length,Ca=new Set(Qn.map(Wa=>Wa.query).filter(Wa=>!!Wa)).size,Wt=qe?Kb(qe,Qn.length):!1,Uo=J&&!Ua,Eu=qi??(F?.error?AO(F.error):qe==="cancelled"?"The sweep was cancelled before it produced a baseline.":(qe==="completed"||qe==="partial")&&Qn.length===0?"The sweep finished without producing any snapshots. Confirm the query set and provider configuration, then retry.":M?.statusDetail||"The sweep did not produce a baseline. Review provider configuration, then retry.");let hn=null;return Uo||Wt?hn=c.jsx(ma,{tone:"positive",children:"Complete"}):qi&&!Ua?hn=c.jsx(ma,{tone:"negative",children:"Failed"}):pn?hn=c.jsx(ma,{tone:"negative",children:qe==="cancelled"?"Cancelled":"Failed"}):Ua&&(hn=c.jsx(ma,{tone:"caution",children:"Running"})),c.jsxs(Sa,{className:"surface-card step-card",children:[c.jsxs("div",{className:"section-head",children:[c.jsxs("div",{children:[c.jsx("p",{className:"eyebrow eyebrow-soft",children:"Step 5 of 5"}),c.jsx("h2",{children:"Launch first run"})]}),hn]}),Uo?c.jsxs("div",{className:"compact-stack",children:[c.jsxs("p",{className:"text-secondary",children:["Setup is complete. ",c.jsx("span",{className:"text-strong font-medium",children:Ce})," already has a successful answer-visibility baseline."]}),c.jsxs("div",{className:"setup-nav",children:[c.jsx("span",{}),c.jsx(xe,{type:"button",onClick:zt,children:g?"Finish and open project":"Open project dashboard →"})]})]}):Ua?pn?Wt?c.jsxs("div",{className:"compact-stack",children:[c.jsxs("p",{className:"text-neutral",children:["Sweep complete. Your first answer-visibility snapshot for"," ",c.jsx("span",{className:"text-heading font-medium",children:Ce}),":"]}),c.jsxs("div",{className:"grid grid-cols-3 gap-2 mt-1",children:[c.jsxs("div",{className:"rounded-md border border-default bg-surface p-3",children:[c.jsx("p",{className:"text-xs font-medium text-secondary",children:"Mentioned"}),c.jsxs("p",{className:"text-2xl font-bold tabular-nums text-primary mt-1",children:[js,c.jsxs("span",{className:"text-faint text-lg",children:[" / ",Ca]})]}),c.jsx("p",{className:"mt-0.5 text-sm text-secondary",children:"queries naming your brand"})]}),c.jsxs("div",{className:"rounded-md border border-default bg-surface p-3",children:[c.jsx("p",{className:"text-xs font-medium text-secondary",children:"Cited"}),c.jsxs("p",{className:"text-2xl font-bold tabular-nums text-primary mt-1",children:[Ss,c.jsxs("span",{className:"text-faint text-lg",children:[" / ",Ca]})]}),c.jsx("p",{className:"mt-0.5 text-sm text-secondary",children:"queries citing your site"})]}),c.jsxs("div",{className:"rounded-md border border-default bg-surface p-3",children:[c.jsx("p",{className:"text-xs font-medium text-secondary",children:"Results"}),c.jsx("p",{className:"text-2xl font-bold tabular-nums text-primary mt-1",children:Qn.length}),c.jsx("p",{className:"mt-0.5 text-sm text-secondary",children:"completed engine checks"})]})]}),c.jsx("p",{className:"mt-1 text-sm text-secondary",children:g?"Your project is ready. Review the evidence in the project.":"Open the project to review the evidence."}),c.jsxs("div",{className:"setup-nav",children:[c.jsx("span",{}),c.jsx(xe,{type:"button",onClick:zt,children:g?"Finish and open project":"Open project dashboard →"})]})]}):c.jsxs("div",{className:"compact-stack",children:[c.jsxs("div",{role:"alert",className:"rounded-md border border-negative bg-negative-soft p-3 text-sm text-negative",children:[c.jsx("p",{children:Eu}),c.jsx("p",{className:"mt-1 text-xs text-secondary",children:"Fix provider or query configuration if needed, then retry without leaving setup."})]}),c.jsxs("div",{className:"setup-nav",children:[c.jsx(xe,{type:"button",variant:"outline",asChild:!0,children:c.jsx(Je,{to:"/settings",children:"Configure providers"})}),c.jsx(xe,{type:"button",disabled:cn||!!La,onClick:Ut(dn),children:cn?"Retrying...":"Retry visibility sweep"})]})]}):c.jsxs("div",{className:"compact-stack",children:[c.jsx("p",{className:"text-neutral",children:"Sweep running. This usually takes 30 to 60 seconds."}),c.jsx("div",{className:"rounded-md border border-default bg-surface p-3 text-xs text-muted",children:c.jsxs("p",{children:["Status: ",c.jsx("span",{className:"text-neutral",children:qe??"queued"})]})}),Ja.isError&&c.jsxs("div",{role:"alert",className:"rounded-md border border-negative bg-negative-soft p-3 text-sm text-negative",children:[c.jsx("p",{children:Ja.error instanceof Error?Ja.error.message:"Could not refresh the sweep status."}),c.jsx(xe,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>{Ja.refetch()},children:"Retry status check"})]}),c.jsxs("div",{className:"setup-nav",children:[c.jsx("span",{}),c.jsx(xe,{type:"button",variant:"outline",onClick:zt,children:g?"Finish and open project":"Watch on project page"})]})]}):c.jsxs("div",{className:"compact-stack",children:[c.jsxs("p",{className:"supporting-copy",children:["Setup is done. You can run a first sweep now to get a baseline for"," ",c.jsx("span",{className:"text-heading font-medium",children:Ce}),", or finish and run it later from the project. A sweep calls the answer engines, so it costs provider usage."]}),(La||qi)&&c.jsxs("div",{role:"alert",className:"rounded-md border border-negative bg-negative-soft p-3 text-sm text-negative",children:[c.jsx("p",{children:qi??La}),c.jsx("p",{className:"mt-1 text-xs text-secondary",children:"Resolve the blocker above, then retry the sweep here."})]}),c.jsxs("div",{className:"setup-nav",children:[c.jsx(xe,{type:"button",variant:"outline",onClick:ct,children:"Back"}),c.jsx(xe,{type:"button",variant:"ghost",onClick:zt,children:"Finish without running"}),c.jsx(xe,{type:"button",disabled:cn||!!La,title:La,onClick:Ut(dn),children:cn?"Launching...":qi?"Retry visibility sweep":"Launch visibility sweep"})]})]})]})}default:return null}})();return c.jsxs("div",{className:"page-container",children:[g?c.jsx(Ao,{current:"visibility"}):null,c.jsxs("div",{className:"page-header",children:[c.jsxs("div",{className:"page-header-left",children:[c.jsx("h1",{ref:u?f:void 0,tabIndex:u?-1:void 0,className:"page-title",children:u?"Set up AI Visibility":"Setup"}),c.jsx("p",{className:"page-subtitle",children:u?"Choose what to track, then run your first visibility sweep.":"Create a project and run its first visibility check."})]}),g?c.jsx("div",{className:"page-header-right",children:c.jsx(xe,{type:"button",variant:"outline",onClick:zt,children:"Skip AI Visibility"})}):null]}),c.jsx(eI,{current:Re,labels:JP}),c.jsx("section",{className:"setup-wizard",children:Kn})]})}const iI=z.lazy(async()=>({default:(await Pn(()=>import("./SiteHealthSection-k4I71wfJ.js").then(n=>n.d),__vite__mapDeps([0,1,2,3,4]),import.meta.url)).SiteHealthSection})),sI=1800,oI="https://github.com/Canonry/canonry#or-use-any-shell-capable-coding-agent",rI="Help me set up Canonry for my public site.\n\nUse Canonry's official docs:\n- Agent quickstart: https://github.com/Canonry/canonry#or-use-any-shell-capable-coding-agent\n- CLI reference: https://github.com/Canonry/canonry/blob/main/skills/canonry/references/canonry-cli.md\n- Plugin setup: https://github.com/Canonry/canonry/blob/main/docs/plugins.md\n- MCP setup: https://github.com/Canonry/canonry/blob/main/docs/mcp.md\n\nUse an existing Canonry installation or connected plugin/MCP if one is already available. Do not create a duplicate. The `cnry` and `canonry` commands are interchangeable.\n\n1. Ask for my public domain, country, and language. Do not create or scan anything yet.\n2. Check the local setup with `command -v cnry`, `cnry --version`, `cnry doctor --format json`, and `cnry project list --format json`. If Canonry is missing, propose `npm install -g @canonry/canonry` and wait for approval. If initialization is required, tell me to run `cnry init` in my private terminal and wait. Never ask me to paste passwords, API keys, OAuth credentials, or `cnry init` output.\n3. Show the normalized domain, proposed project name, exact `cnry project create ...` command, and wait for explicit approval before creating it.\n4. Propose a bounded Site Health scan, including `--max-pages` and whether dead-link checking is enabled. Show the exact `cnry technical-aeo run ... --wait --format json` command and wait for separate approval before scanning.\n5. After the crawl, summarize the findings and propose AI Visibility setup. Ask before adding queries, connecting providers, starting any provider-backed or quota-consuming run, editing files, or publishing.";function lI(e,n){return e==="legacy"?"legacy":e==="platform"?"platform":n.state==="success"?n.projectCount===0?"platform":"legacy":n.state==="error"?"retry":"loading"}function cI(e,n){try{const s=new Intl.DisplayNames(["en"],{type:"region"}),r=new Intl.DisplayNames(["en"],{type:"language"}),u=e.length===2?s.of(e.toUpperCase()):void 0,f=n?r.of(n.toLowerCase()):void 0;return`${u??(e||"Country")} · ${f??(n||"Language")}`}catch{return`${e||"Country"} · ${n||"Language"}`}}function uI(e){const n=e.replace(/^\[|\]$/g,"");return/^(?:\d{1,3}\.){3}\d{1,3}$/.test(n)||n.includes(":")}function dI(e){const n=e.trim();if(!n)return null;const s=/^[a-z][a-z\d+.-]*:\/\//i.test(n)?n:`https://${n}`;let r;try{r=new URL(s)}catch{return null}if(r.protocol!=="http:"&&r.protocol!=="https:")return null;const u=r.hostname.toLowerCase().replace(/^www\./,"");if(!u||u==="localhost"||uI(u)||!u.includes("."))return null;const f=u.replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");return f?{canonicalDomain:u,projectName:f,displayName:u}:null}async function mI(e,n=sI){let s;const r=new Promise(f=>{s=setTimeout(()=>f({state:"timed-out"}),n)}),u=await Promise.race([e.then(f=>({state:"queued",run:f})),r]);return s&&clearTimeout(s),u}function pI(e,n){e.catch(()=>{Qt({title:"Site Health scan did not start",detail:"The project is safe. Choose Run scan in Site Health to retry.",tone:"negative",dedupeKey:`site-health-dispatch:${n}`})})}function Zb(e,n){return e instanceof na&&e.statusCode===409?"A project with this name already exists. Change the project name, or open the existing project.":e instanceof Error&&e.message?e.message:n}function hI(){return c.jsxs("div",{className:"page-container max-w-3xl","aria-busy":"true","aria-live":"polite",children:[c.jsx("div",{className:"page-header",children:c.jsxs("div",{className:"page-header-left",children:[c.jsx("h1",{className:"page-title",children:"Preparing setup"}),c.jsx("p",{className:"page-subtitle",children:"Checking the projects already on this install."})]})}),c.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-default bg-surface p-4 text-sm text-secondary",role:"status",children:[c.jsx(fo,{className:"size-4 motion-safe:animate-spin","aria-hidden":"true"}),"Loading projects…"]})]})}function fI({onRetry:e}){return c.jsxs("div",{className:"page-container max-w-3xl",children:[c.jsx("div",{className:"page-header",children:c.jsxs("div",{className:"page-header-left",children:[c.jsx("h1",{className:"page-title",children:"Can’t load projects"}),c.jsx("p",{className:"page-subtitle",children:"Canonry could not confirm whether this install already has a project."})]})}),c.jsxs("div",{className:"rounded-lg border border-negative bg-negative-soft p-4",role:"alert",tabIndex:-1,children:[c.jsx("p",{className:"text-sm font-medium text-heading",children:"Setup is paused to protect existing projects."}),c.jsx("p",{className:"mt-1 text-sm text-secondary",children:"Check the connection or sign in again, then retry."}),c.jsx(xe,{type:"button",className:"mt-4",variant:"secondary",onClick:e,children:"Retry project check"})]})]})}function gI({projectName:e,initialRunId:n}){return c.jsx(ih,{title:"Site Health setup",children:c.jsx(yI,{projectName:e,initialRunId:n})})}function yI({projectName:e,initialRunId:n}){const s=cs(),r=Kt({...ps({client:se}),enabled:!!e,retry:!1,refetchOnMount:"always"});if(!e)return c.jsxs("div",{className:"page-container max-w-3xl",children:[c.jsx("div",{className:"page-header",children:c.jsxs("div",{className:"page-header-left",children:[c.jsx("h1",{className:"page-title",children:"Project not found"}),c.jsx("p",{className:"page-subtitle",children:"This setup link does not identify a project."})]})}),c.jsx(xe,{type:"button",variant:"secondary",onClick:()=>{s({to:"/projects"})},children:"View projects"})]});if(r.isPending)return c.jsxs("div",{className:"page-container max-w-3xl","aria-busy":"true","aria-live":"polite",children:[c.jsx(Ao,{current:"site"}),c.jsxs("div",{className:"mt-8 flex items-center gap-3 text-sm text-secondary",role:"status",children:[c.jsx(fo,{className:"size-4 motion-safe:animate-spin","aria-hidden":"true"}),"Loading Site Health setup…"]})]});if(r.isError)return c.jsxs("div",{className:"page-container max-w-3xl",children:[c.jsx("div",{className:"page-header",children:c.jsxs("div",{className:"page-header-left",children:[c.jsx("h1",{className:"page-title",children:"Can’t resume setup"}),c.jsx("p",{className:"page-subtitle",children:"Canonry could not load the project for this Site Health scan."})]})}),c.jsxs("div",{className:"rounded-lg border border-negative bg-negative-soft p-4",role:"alert",children:[c.jsx("p",{className:"text-sm text-secondary",children:"Check the connection or sign in again, then retry."}),c.jsx(xe,{type:"button",className:"mt-4",variant:"secondary",onClick:()=>{r.refetch()},children:"Retry project check"})]})]});const u=r.data.find(x=>x.name===e);if(!u)return c.jsxs("div",{className:"page-container max-w-3xl",children:[c.jsx("div",{className:"page-header",children:c.jsxs("div",{className:"page-header-left",children:[c.jsx("h1",{className:"page-title",children:"Project not found"}),c.jsxs("p",{className:"page-subtitle",children:["Canonry could not find ",e,". It will not open a different project."]})]})}),c.jsx(xe,{type:"button",variant:"secondary",onClick:()=>{s({to:"/projects"})},children:"View projects"})]});const f=()=>{s({to:"/setup",search:{onboarding:"site-health",setupProject:u.name},replace:!0})},g=()=>{s({to:"/setup",search:{experience:"legacy",onboarding:"site-health",setupProject:u.name},replace:!0})},b=()=>{s({to:"/projects/$projectName",params:{projectName:u.name},replace:!0})};return c.jsxs("div",{className:"page-container max-w-7xl py-8 md:py-10",children:[c.jsx("h1",{className:"sr-only",children:"Set up Canonry"}),c.jsx(z.Suspense,{fallback:c.jsxs("div",{className:"space-y-5",children:[c.jsx(Ao,{current:"site"}),c.jsxs("div",{className:"flex min-h-72 items-center justify-center gap-3 text-sm text-secondary",role:"status",children:[c.jsx(fo,{className:"size-4 motion-safe:animate-spin","aria-hidden":"true"}),"Loading Site Health…"]})]}),children:c.jsx(iI,{projectName:u.name,projectId:u.id,initialRunId:n,onReleaseInitialRun:f,showOnboardingActions:!0,onContinueOnboarding:g,onSkipOnboarding:b})})]})}function bI(){const e=Yb({from:"/setup"}),n=e.onboarding==="site-health"&&!e.setupProject,s=e.onboarding==="site-health"&&e.experience!=="legacy",r=z5(),u=e.experience==="legacy"?"legacy":r,[f,g]=z.useState(!1),b=Kt({...ps({client:se}),enabled:u==="auto",retry:!1,refetchOnMount:"always"}),x=u==="auto"&&b.isSuccess&&b.isFetchedAfterMount&&b.data.length===0;z.useEffect(()=>{x&&g(!0)},[x]);const k=u!=="auto"?{state:"idle"}:b.isSuccess&&b.isFetchedAfterMount?{state:"success",projectCount:b.data.length}:b.isError?{state:"error"}:{state:"loading"},S=u==="legacy"?"legacy":f||x?"platform":lI(u,k);return n||s?c.jsx(gI,{projectName:e.setupProject,initialRunId:e.siteHealthRunId}):S==="legacy"?c.jsx(tI,{visibilityProjectName:e.setupProject,siteHealthOnboarding:e.onboarding==="site-health"}):S==="loading"?c.jsx(hI,{}):S==="retry"?c.jsx(fI,{onRetry:()=>{b.refetch()}}):c.jsx(vI,{onActivationStarted:()=>g(!0)})}function vI({onActivationStarted:e}){return c.jsx(ih,{title:"Site Health setup",children:c.jsx(xI,{onActivationStarted:e})})}function xI({onActivationStarted:e}){const n=cs(),s=Mn(),r=HP(),[u,f]=z.useState(""),[g,b]=z.useState(""),[x,k]=z.useState(""),[S,A]=z.useState("US"),[j,D]=z.useState("en"),[R,q]=z.useState(!1),[U,V]=z.useState("idle"),[te,X]=z.useState(null),[ae,oe]=z.useState(null),[fe,M]=z.useState(!1),[J,_e]=z.useState(null),[me,we]=z.useState(!1),Re=z.useRef(null),je=dI(u),Qe=g||je?.projectName||"",ge=x||je?.displayName||"",I=U==="creating"||U==="dispatching",ne=ae??J,he=cI(S,j);z.useEffect(()=>{ne&&Re.current?.focus()},[ne]);const Ee=(re,W)=>n({to:"/setup",search:{...W?{siteHealthRunId:W}:{},onboarding:"site-health",setupProject:re.name},replace:!0}),le=async re=>{V("dispatching"),_e(null);try{const W=r.mutateAsync({projectName:re.name,projectId:re.id,projectLabel:re.displayName||re.name,suppressErrorToast:!0,body:{checkDeadLinks:!0}}),Z=await mI(W);if(Z.state==="queued"){await Ee(re,Z.run.runId);return}pI(W,re.id),await Ee(re)}catch(W){V("recovery"),_e(Zb(W,"The project was created, but the Site Health scan could not be started."))}},et=async re=>{if(re.preventDefault(),!(!je||!R||I)){V("creating"),oe(null),M(!1),_e(null);try{const W=await _v({name:Qe,displayName:ge,canonicalDomain:je.canonicalDomain,country:S,language:j});e(),X(W),await s.invalidateQueries({queryKey:wi({client:se})}),await le(W)}catch(W){V("idle");const Z=W instanceof na&&W.statusCode===409;M(Z),oe(Zb(W,"Could not create the project. Try again.")),Z&&(e(),s.invalidateQueries({queryKey:wi({client:se})}))}}},G=()=>{te&&!I&&le(te)},ce=()=>{I||n({to:"/projects"})},ie=async()=>{try{await navigator.clipboard.writeText(rI),we(!0)}catch{Qt({tone:"negative",title:"Could not copy setup request",detail:"Open the agent quickstart to continue with the CLI instead."})}};return te&&U==="recovery"?c.jsxs("div",{className:"page-container max-w-3xl",children:[c.jsx(Ao,{current:"site"}),c.jsx("div",{className:"page-header mt-8",children:c.jsxs("div",{className:"page-header-left",children:[c.jsx("h1",{className:"page-title",children:"Project created"}),c.jsxs("p",{className:"page-subtitle",children:[te.displayName||te.name," is ready. The Site Health scan needs another try."]})]})}),c.jsxs("div",{ref:Re,className:"rounded-lg border border-negative bg-negative-soft p-4",role:"alert",tabIndex:-1,children:[c.jsx("p",{className:"text-sm font-medium text-heading",children:J}),c.jsx("p",{className:"mt-1 text-sm text-secondary",children:"You can retry the scan or continue setup and retry from Site Health."}),c.jsxs("div",{className:"mt-4 flex flex-wrap gap-3",children:[c.jsx(xe,{type:"button",onClick:G,children:"Retry Site Health scan"}),c.jsx(xe,{type:"button",variant:"secondary",onClick:()=>{Ee(te)},children:"Continue setup"})]})]})]}):c.jsxs("div",{className:"page-container max-w-xl py-8 md:py-12",children:[c.jsx(Ao,{current:"site"}),c.jsxs("header",{className:"mb-8 mt-8",children:[c.jsx("h1",{id:"site-map-setup-title",className:"text-2xl font-semibold tracking-[-0.025em] text-heading",children:"Map your site"}),c.jsx("p",{className:"mt-2 max-w-lg text-sm leading-6 text-secondary",children:"Enter your public website to see its pages, structure, and internal links."})]}),c.jsxs("form",{"aria-labelledby":"site-map-setup-title",className:"space-y-6",onSubmit:Ut(et),noValidate:!0,children:[c.jsxs("div",{className:"grid gap-2",children:[c.jsx("label",{className:"text-sm font-medium text-heading",htmlFor:"launchpad-domain",children:"Website URL"}),c.jsx("input",{id:"launchpad-domain",className:"h-11 w-full rounded-md border border-strong bg-bg-elevated/50 px-3 text-base text-heading outline-none transition placeholder:text-muted focus:border-mono-500 focus:ring-1 focus:ring-mono-500",type:"text",inputMode:"url",autoComplete:"url",autoCapitalize:"none",spellCheck:!1,required:!0,"aria-invalid":!!(u&&!je),"aria-describedby":u&&!je?"launchpad-domain-hint launchpad-domain-error":"launchpad-domain-hint",placeholder:"https://example.com",value:u,onChange:re=>{f(re.target.value),oe(null),M(!1)}}),c.jsxs("p",{id:"launchpad-domain-hint",className:"text-sm text-secondary",children:["Only public pages are scanned."," ",c.jsx(Je,{to:"/setup",search:{experience:"legacy"},className:"font-medium text-link underline-offset-4 hover:underline",children:"Set up without a site scan"})]}),u&&!je?c.jsx("p",{id:"launchpad-domain-error",className:"text-sm text-negative",role:"alert",children:"Enter a public domain, such as example.com."}):null]}),c.jsxs("details",{className:"group border-y border-default",children:[c.jsxs("summary",{className:"flex min-h-11 cursor-pointer list-none items-center justify-between gap-4 py-3 text-sm [&::-webkit-details-marker]:hidden",children:[c.jsx("span",{className:"font-medium text-heading",children:"Advanced settings"}),c.jsxs("span",{className:"flex items-center gap-2 text-secondary",children:[he,c.jsx(Lp,{className:"size-4 transition-transform group-open:rotate-180 motion-reduce:transition-none","aria-hidden":"true"})]})]}),c.jsxs("div",{className:"space-y-5 border-t border-default py-4",children:[je?c.jsxs("div",{children:[c.jsx("p",{className:"mb-3 text-sm font-medium text-heading",children:"Project"}),c.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[c.jsxs("div",{className:"grid gap-2",children:[c.jsx("label",{className:"text-sm text-secondary",htmlFor:"launchpad-project-name",children:"Project name"}),c.jsx("input",{id:"launchpad-project-name",className:"setup-input h-10",type:"text",value:Qe,onChange:re=>b(re.target.value)})]}),c.jsxs("div",{className:"grid gap-2",children:[c.jsx("label",{className:"text-sm text-secondary",htmlFor:"launchpad-display-name",children:"Display name"}),c.jsx("input",{id:"launchpad-display-name",className:"setup-input h-10",type:"text",value:ge,onChange:re=>k(re.target.value)})]})]})]}):null,c.jsxs("div",{children:[c.jsx("p",{className:"mb-3 text-sm font-medium text-heading",children:"Locale"}),c.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[c.jsxs("div",{className:"grid gap-2",children:[c.jsx("label",{className:"text-sm text-secondary",htmlFor:"launchpad-country",children:"Country"}),c.jsx("input",{id:"launchpad-country",className:"setup-input h-10",type:"text",maxLength:2,value:S,onChange:re=>A(re.target.value.toUpperCase())})]}),c.jsxs("div",{className:"grid gap-2",children:[c.jsx("label",{className:"text-sm text-secondary",htmlFor:"launchpad-language",children:"Language"}),c.jsx("input",{id:"launchpad-language",className:"setup-input h-10",type:"text",maxLength:5,value:j,onChange:re=>D(re.target.value.toLowerCase())})]})]})]})]})]}),c.jsxs("label",{className:"flex min-h-11 cursor-pointer items-start gap-3 py-2",children:[c.jsx("input",{className:"mt-0.5 size-4 shrink-0 rounded border-strong bg-bg",type:"checkbox",checked:R,onChange:re=>q(re.target.checked),"aria-label":"Allow Canonry to scan this public site.","aria-describedby":"local-crawl-note"}),c.jsxs("span",{className:"grid gap-0.5",children:[c.jsx("span",{className:"text-sm leading-5 text-heading",children:"Allow Canonry to scan this public site."}),c.jsx("span",{id:"local-crawl-note",className:"text-sm leading-5 text-secondary",children:"The crawl runs on this Canonry instance, follows internal links, and stores its results locally."})]})]}),ne?c.jsxs("div",{ref:Re,className:"rounded-md border border-negative bg-negative-soft p-3",role:"alert",tabIndex:-1,children:[c.jsx("p",{className:"text-sm font-medium text-heading",children:ne}),fe?c.jsx(xe,{type:"button",variant:"secondary",size:"sm",className:"mt-3",onClick:ce,children:"View projects"}):null]}):null,c.jsxs("div",{className:"grid gap-2",children:[c.jsx(xe,{className:"h-11 w-full",type:"submit",disabled:!je||!R||I,children:U==="creating"||U==="dispatching"?c.jsxs(c.Fragment,{children:[c.jsx(fo,{className:"size-4 motion-safe:animate-spin","aria-hidden":"true"})," Mapping site…"]}):"Map site"}),c.jsx(xe,{className:"w-full",type:"button",variant:"ghost",disabled:I,onClick:ce,children:"Cancel"}),U==="dispatching"?c.jsx("span",{className:"text-center text-sm text-secondary",role:"status",children:"Opening Site Health when the scan is ready."}):null]})]}),c.jsxs("section",{className:"mt-8 border-t border-default pt-6","aria-labelledby":"agent-setup-title",children:[c.jsx("p",{id:"agent-setup-title",className:"text-sm font-medium text-heading",children:"Use your agent instead"}),c.jsx("p",{className:"mt-1 text-sm leading-5 text-secondary",children:"Copy a complete CLI setup request into any coding agent."}),c.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-1",children:[c.jsxs(xe,{type:"button",variant:"ghost",size:"sm",className:"-ml-3",onClick:Ut(ie),children:[me?c.jsx(Vp,{className:"size-3.5","aria-hidden":"true"}):c.jsx(ov,{className:"size-3.5","aria-hidden":"true"}),c.jsx("span",{"aria-live":"polite",children:me?"Copied setup request":"Copy setup request"})]}),c.jsx(xe,{asChild:!0,variant:"ghost",size:"sm",children:c.jsxs("a",{href:oI,target:"_blank",rel:"noopener noreferrer",children:["Agent quickstart",c.jsx(DS,{className:"size-3.5","aria-hidden":"true"}),c.jsx("span",{className:"sr-only",children:" (opens in a new tab)"})]})})]})]})]})}function kI(){return c.jsx("div",{className:"page-container",children:c.jsx("section",{className:"page-section",children:c.jsxs(Sa,{className:"surface-card empty-card",children:[c.jsx("h1",{children:"Route not found"}),c.jsx("p",{children:"The current path does not map to a dashboard view."}),c.jsx(xe,{asChild:!0,children:c.jsx(Je,{to:"/",children:"Return to overview"})})]})})})}const Ya=Si(()=>Pn(()=>import("./ProjectPage-DIzi4Ggo.js"),__vite__mapDeps([5,1,6,0,2,3,4,7,8,9,10,11,12]),import.meta.url),"ProjectPage"),wI=Si(()=>Pn(()=>import("./RunsPage-DGTrqrTA.js"),__vite__mapDeps([13,1,6,10,4,2,11,12]),import.meta.url),"RunsPage"),SI=Si(()=>Pn(()=>import("./HistoryPage-iuETLmwO.js"),__vite__mapDeps([14,1,8,10,4,2,11,12]),import.meta.url),"HistoryPage"),jI=Si(()=>Pn(()=>import("./SettingsPage-Cwb_Ft9u.js"),__vite__mapDeps([15,1,10,4,2,11,12]),import.meta.url),"SettingsPage"),AI=Si(()=>Pn(()=>import("./BacklinksPage-BMqIPRvZ.js"),__vite__mapDeps([16,1,2,10,4,11,12]),import.meta.url),"BacklinksPage"),NI=Si(()=>Pn(()=>import("./TrafficPage-C8nyb8l1.js"),__vite__mapDeps([17,1,7,2,10,4,11,12]),import.meta.url),"TrafficPage"),CI=Si(()=>Pn(()=>import("./TrafficSourceDetailPage-ry7Da0pV.js"),__vite__mapDeps([18,1,7,3,4,2,10,11,12]),import.meta.url),"TrafficSourceDetailPage"),_I=Si(()=>Pn(()=>import("./MeasurementPropertyPage-BzNAaB8X.js"),__vite__mapDeps([19,1,3,4,9,2,10,11,12]),import.meta.url),"MeasurementPropertyPage");function zI(){return c.jsx(EP,{children:c.jsx(zP,{})})}const ia=oS()({component:zI,validateSearch:e=>({manageQueries:e.manageQueries===!0||e.manageQueries==="true"?!0:void 0,runId:typeof e.runId=="string"?e.runId:void 0,siteHealthRunId:typeof e.siteHealthRunId=="string"?e.siteHealthRunId:void 0,evidenceId:typeof e.evidenceId=="string"?e.evidenceId:void 0,runStatus:typeof e.runStatus=="string"?e.runStatus:void 0,runKind:typeof e.runKind=="string"?e.runKind:void 0,runProject:typeof e.runProject=="string"?e.runProject:void 0,runWindow:typeof e.runWindow=="string"?e.runWindow:void 0,runQuery:typeof e.runQuery=="string"?e.runQuery:void 0,onboarding:e.onboarding==="site-health"?"site-health":void 0,experience:e.experience==="legacy"?"legacy":void 0,setupProject:typeof e.setupProject=="string"?e.setupProject:void 0,scope:typeof e.scope=="string"?e.scope:void 0,class:typeof e.class=="string"?e.class:void 0})}),EI=kt({getParentRoute:()=>ia,path:"/",component:qP,beforeLoad:async({context:e})=>{let n=e.queryClient.getQueryData(wi({client:se}));if(n===void 0)try{n=await e.queryClient.ensureQueryData(ps({client:se}))}catch{return}if(n.length===0)throw Jb({to:"/setup"})}}),DI=kt({getParentRoute:()=>ia,path:"/projects",component:MP}),TI=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,Aa=kt({getParentRoute:()=>ia,path:"/projects/$projectName",component:()=>c.jsx(cp,{}),beforeLoad:async({context:e,params:n,location:s})=>{const r=n.projectName;if(!TI.test(r))return;let u=e.queryClient.getQueryData(wi({client:se}));if(!u)try{u=await e.queryClient.ensureQueryData(ps({client:se}))}catch{return}const f=u.find(g=>g.id===r);if(f)throw Jb({to:s.pathname.replace(`/projects/${r}`,`/projects/${encodeURIComponent(f.name)}`),replace:!0})}}),RI=kt({getParentRoute:()=>Aa,path:"/",component:()=>c.jsx(Ya,{tab:"overview"})}),OI=kt({getParentRoute:()=>Aa,path:"/portfolio",component:()=>c.jsx(Ya,{tab:"portfolio"})}),qI=kt({getParentRoute:()=>Aa,path:"/search-console",component:()=>c.jsx(Ya,{tab:"search-console"})}),BI=kt({getParentRoute:()=>Aa,path:"/local",component:()=>c.jsx(Ya,{tab:"local"})}),MI=kt({getParentRoute:()=>Aa,path:"/discovery",component:()=>c.jsx(Ya,{tab:"discovery"})}),PI=kt({getParentRoute:()=>Aa,path:"/properties/$targetKey",component:()=>c.jsx(_I,{})}),II=kt({getParentRoute:()=>Aa,path:"/report",component:()=>c.jsx(Ya,{tab:"report"})}),UI=kt({getParentRoute:()=>Aa,path:"/activity",component:()=>c.jsx(Ya,{tab:"activity"})}),LI=kt({getParentRoute:()=>Aa,path:"/backlinks",component:()=>c.jsx(Ya,{tab:"backlinks"})}),VI=kt({getParentRoute:()=>Aa,path:"/technical-aeo",component:()=>c.jsx(Ya,{tab:"technical-aeo"})}),$I=kt({getParentRoute:()=>Aa,path:"/history",component:()=>c.jsx(Ya,{tab:"history"})}),HI=kt({getParentRoute:()=>Aa,path:"/settings",component:()=>c.jsx(Ya,{tab:"settings"})}),GI=kt({getParentRoute:()=>ia,path:"/runs",component:wI}),KI=kt({getParentRoute:()=>ia,path:"/history",component:SI}),QI=kt({getParentRoute:()=>ia,path:"/settings",component:jI,beforeLoad:({context:e})=>{}}),ZI=kt({getParentRoute:()=>ia,path:"/setup",component:bI}),FI=kt({getParentRoute:()=>ia,path:"/backlinks",component:AI}),YI=kt({getParentRoute:()=>ia,path:"/traffic",component:NI}),XI=kt({getParentRoute:()=>ia,path:"/traffic/$projectName/$sourceId",component:CI}),JI=kt({getParentRoute:()=>ia,path:"*",component:kI}),WI=ia.addChildren([EI,DI,Aa.addChildren([RI,OI,qI,BI,MI,PI,II,UI,LI,VI,$I,HI]),GI,KI,QI,ZI,FI,YI,XI,JI]);function eU(){return typeof window<"u"&&window.__CANONRY_CONFIG__?.basePath?window.__CANONRY_CONFIG__.basePath:"/"}const Fb=eU(),tU=Fb==="/"?"":Fb.replace(/\/$/,"");function aU(e,n){return rS({routeTree:WI,basepath:tU||"/",context:{queryClient:e},...n?.initialEntries})}const nU=6e4;function iU(){const[e,n]=z.useState(Lm()?"ready":"checking"),[s,r]=z.useState(null),[u,f]=z.useState(!1),[g,b]=z.useState(""),[x,k]=z.useState(""),[S,A]=z.useState(""),[j,D]=z.useState(null),[R,q]=z.useState(!1),[U,V]=z.useState(!1),te=z.useRef(null),X=z.useRef(null),ae=z.useRef(null),oe=()=>{const me=s?`${s.name}:${s.role}`:"no-accounts";if(!te.current||ae.current!==me){X.current?.clear();const we=j6();X.current=we,te.current=aU(we),ae.current=me}return{queryClient:X.current,router:te.current}},fe=me=>me.authRequired?(f(!0),r(me.user),n(me.user?"ready":"account-login"),!0):!1;z.useEffect(()=>{if(Lm())return;let me=!1;return Promise.allSettled([Wg(),Jg()]).then(([we,Re])=>{if(me||we.status==="fulfilled"&&fe(we.value))return;if(Re.status==="rejected"){const Qe=Re.reason;D(Qe instanceof Error?Qe.message:"Failed to reach the Canonry API"),n("login");return}const je=Re.value;je.authenticated?n("ready"):n(je.setupRequired?"setup":"login")}),()=>{me=!0}},[]),z.useEffect(()=>{if(e!=="ready"||Lm())return;const me=setInterval(()=>{if(u){Wg().then(we=>{we.authRequired&&!we.user&&(V(!0),r(null),n("account-login"))}).catch(()=>{});return}Jg().then(we=>{we.authenticated||(V(!0),n(we.setupRequired?"setup":"login"))}).catch(()=>{})},nU);return Xg(()=>{V(!0),r(null),n(u?"account-login":"login")}),()=>{clearInterval(me),Xg(null)}},[e,u]);const M=async me=>{if(me.preventDefault(),!x.trim()||x.trim().length<8){D("Password must be at least 8 characters");return}if(x!==S){D("Passwords do not match");return}q(!0),D(null);try{if(!(await J5(x.trim())).authenticated){D("Setup failed");return}k(""),A(""),V(!1),n("ready")}catch(we){D(we instanceof na||we instanceof Error?we.message:"Setup failed")}finally{q(!1)}},J=async me=>{if(me.preventDefault(),!!x.trim()){q(!0),D(null);try{if(!(await W5(x.trim())).authenticated){D("Incorrect password");return}k(""),V(!1),n("ready")}catch(we){D(we instanceof na||we instanceof Error?we.message:"Authentication failed")}finally{q(!1)}}},_e=async me=>{if(me.preventDefault(),!(!g.trim()||!x)){q(!0),D(null);try{const we=await e6(g.trim(),x);if(!we.user){D("Incorrect name or password.");return}k(""),V(!1),r(we.user),n("ready")}catch(we){D(we instanceof na?we.message:"Incorrect name or password.")}finally{q(!1)}}};if(e==="ready"){const{queryClient:me,router:we}=oe();return c.jsx(h6,{account:s,children:c.jsx(lS,{client:me,children:c.jsx(cS,{router:we})})})}return c.jsx("div",{className:"min-h-screen bg-bg px-4 py-8",children:c.jsxs("div",{className:"mx-auto flex min-h-[calc(100vh-4rem)] max-w-md flex-col items-center justify-center gap-5",children:[c.jsxs("div",{"data-testid":"auth-brand",className:"flex items-center gap-2.5",children:[c.jsx("img",{className:"size-7",src:"./favicon.svg",alt:"","aria-hidden":"true"}),c.jsx("span",{className:"text-lg font-semibold tracking-tight text-heading",children:"Canonry"})]}),c.jsx(Sa,{className:"surface-card w-full",children:e==="checking"?c.jsx(uo,{className:"py-8",children:c.jsx("p",{className:"supporting-copy text-center",children:"Connecting to Canonry…"})}):e==="account-login"?c.jsxs(c.Fragment,{children:[c.jsxs(Ur,{children:[c.jsx("p",{className:"eyebrow eyebrow-soft",children:"Dashboard access"}),c.jsx(Lr,{children:"Sign in to Canonry"})]}),c.jsxs(uo,{children:[U?c.jsx("p",{className:"mb-4 rounded-md border border-caution bg-caution-soft px-3 py-2 text-sm text-caution",children:"You were signed out — please sign in again."}):null,c.jsxs("form",{className:"space-y-4",onSubmit:Ut(_e),children:[c.jsxs("label",{className:"block space-y-1.5",htmlFor:"account-name",children:[c.jsx("span",{className:"text-xs font-medium text-secondary",children:"Name"}),c.jsx("input",{autoFocus:!0,id:"account-name",className:"w-full rounded-md border border-base bg-bg px-3 py-2 text-sm text-heading outline-none transition focus:border-mono-600",type:"text",autoComplete:"username",value:g,onChange:me=>b(me.target.value)})]}),c.jsxs("label",{className:"block space-y-1.5",htmlFor:"account-password",children:[c.jsx("span",{className:"text-xs font-medium text-secondary",children:"Password"}),c.jsx("input",{id:"account-password",className:"w-full rounded-md border border-base bg-bg px-3 py-2 text-sm text-heading outline-none transition focus:border-mono-600",type:"password",autoComplete:"current-password",value:x,onChange:me=>k(me.target.value)})]}),j?c.jsx("p",{className:"text-sm text-negative-400",children:j}):null,c.jsx(xe,{type:"submit",disabled:R||!g.trim()||!x,children:R?"Signing in…":"Sign in"})]})]})]}):e==="setup"?c.jsxs(c.Fragment,{children:[c.jsxs(Ur,{children:[c.jsx("p",{className:"eyebrow eyebrow-soft",children:"First-time setup"}),c.jsx(Lr,{children:"Create a dashboard password"}),c.jsx(Xc,{children:"Choose a password to protect the Canonry dashboard."})]}),c.jsx(uo,{children:c.jsxs("form",{className:"space-y-4",onSubmit:Ut(M),children:[c.jsxs("label",{className:"block space-y-1.5",children:[c.jsx("span",{className:"text-xs font-medium text-secondary",children:"Password"}),c.jsx("input",{autoFocus:!0,className:"w-full rounded-md border border-base bg-bg px-3 py-2 text-sm text-heading outline-none transition focus:border-mono-600",type:"password",value:x,onChange:me=>k(me.target.value),placeholder:"At least 8 characters"})]}),c.jsxs("label",{className:"block space-y-1.5",children:[c.jsx("span",{className:"text-xs font-medium text-secondary",children:"Confirm password"}),c.jsx("input",{className:"w-full rounded-md border border-base bg-bg px-3 py-2 text-sm text-heading outline-none transition focus:border-mono-600",type:"password",value:S,onChange:me=>A(me.target.value),placeholder:"Re-enter password"})]}),j?c.jsx("p",{className:"text-sm text-negative-400",children:j}):null,c.jsx(xe,{type:"submit",disabled:R||!x.trim()||!S.trim(),children:R?"Setting up…":"Create password & open dashboard"})]})})]}):c.jsxs(c.Fragment,{children:[c.jsxs(Ur,{children:[c.jsx("p",{className:"eyebrow eyebrow-soft",children:"Dashboard access"}),c.jsx(Lr,{children:"Sign in to Canonry"}),c.jsx(Xc,{children:"Enter your dashboard password to continue."})]}),c.jsxs(uo,{children:[U?c.jsx("p",{className:"mb-4 rounded-md border border-caution bg-caution-soft px-3 py-2 text-sm text-caution",children:"Your session expired — please sign in again."}):null,c.jsxs("form",{className:"space-y-4",onSubmit:Ut(J),children:[c.jsxs("label",{className:"block space-y-1.5",children:[c.jsx("span",{className:"text-xs font-medium text-secondary",children:"Password"}),c.jsx("input",{autoFocus:!0,className:"w-full rounded-md border border-base bg-bg px-3 py-2 text-sm text-heading outline-none transition focus:border-mono-600",type:"password",value:x,onChange:me=>k(me.target.value),placeholder:"Dashboard password"})]}),j?c.jsx("p",{className:"text-sm text-negative-400",children:j}):null,c.jsx(xe,{type:"submit",disabled:R||!x.trim(),children:R?"Signing in…":"Open dashboard"})]})]})]})})]})})}const Kk=document.getElementById("root");if(!Kk)throw new Error("Expected #root element for web app bootstrap.");PS.createRoot(Kk).render(c.jsx(z.StrictMode,{children:c.jsx(iU,{})}));export{XV as $,VU as A,xe as B,Qc as C,qV as D,PV as E,MV as F,UL as G,JU as H,Or as I,XU as J,cL as K,Qt as L,LV as M,VV as N,nL as O,sM as P,$V as Q,iL as R,jO as S,ma as T,eL as U,aL as V,IV as W,UV as X,BV as Y,WU as Z,HV as _,T$ as a,yU as a$,QV as a0,FV as a1,ZV as a2,YV as a3,d6 as a4,Z0 as a5,Oe as a6,KV as a7,hk as a8,Bn as a9,lV as aA,f$ as aB,g$ as aC,y$ as aD,sL as aE,wi as aF,oL as aG,K0 as aH,c$ as aI,FO as aJ,RV as aK,ue as aL,DU as aM,EU as aN,zU as aO,_U as aP,AU as aQ,jU as aR,CU as aS,NU as aT,SU as aU,wU as aV,fU as aW,gU as aX,kU as aY,xU as aZ,vU as a_,GV as aa,U$ as ab,V9 as ac,$9 as ad,$L as ae,VL as af,zL as ag,qL as ah,BL as ai,na as aj,ML as ak,RU as al,AO as am,cB as an,Bc as ao,PL as ap,hp as aq,u$ as ar,tL as as,LL as at,BO as au,tq as av,CV as aw,zV as ax,_V as ay,rV as az,W7 as b,a$ as b$,bU as b0,hU as b1,pU as b2,mU as b3,dU as b4,cj as b5,WL as b6,l$ as b7,JL as b8,yL as b9,Sv as bA,yV as bB,bV as bC,P$ as bD,$P as bE,EV as bF,OV as bG,vV as bH,kV as bI,SV as bJ,xV as bK,aa as bL,K5 as bM,EO as bN,O$ as bO,qU as bP,BU as bQ,OU as bR,Z5 as bS,MU as bT,qO as bU,LU as bV,JV as bW,e$ as bX,o6 as bY,hL as bZ,t$ as b_,I$ as ba,aV as bb,eV as bc,nV as bd,iV as be,XL as bf,tV as bg,UU as bh,IU as bi,PU as bj,bL as bk,HU as bl,fV as bm,yb as bn,hV as bo,GU as bp,KU as bq,pV as br,QU as bs,ZU as bt,YU as bu,FU as bv,sl as bw,ps as bx,FM as by,Fr as bz,R$ as c,HP as c$,WV as c0,uV as c1,uL as c2,dL as c3,mL as c4,fL as c5,pL as c6,go as c7,Q0 as c8,q$ as c9,Rk as cA,Ok as cB,NL as cC,p$ as cD,oV as cE,L0 as cF,gV as cG,d$ as cH,h$ as cI,AL as cJ,sV as cK,SL as cL,jL as cM,wL as cN,m$ as cO,M_ as cP,jV as cQ,wV as cR,NV as cS,AV as cT,KL as cU,Pn as cV,Pa as cW,GL as cX,b$ as cY,x$ as cZ,v$ as c_,Su as ca,X0 as cb,DV as cc,TV as cd,t6 as ce,I5 as cf,TU as cg,$U as ch,rL as ci,lL as cj,ih as ck,ju as cl,J0 as cm,gL as cn,jo as co,vb as cp,CL as cq,EL as cr,TL as cs,RL as ct,_L as cu,DL as cv,OL as cw,oM as cx,Tk as cy,dM as cz,Sa as d,QL as d0,z$ as d1,E$ as d2,D$ as d3,k$ as d4,w$ as d5,HL as d6,A$ as d7,_$ as d8,j$ as d9,C$ as da,S$ as db,Ao as dc,ZL as dd,N$ as de,NE as df,YL as dg,FL as dh,on as e,Ut as f,IL as g,Eb as h,q5 as i,n$ as j,se as k,i$ as l,s$ as m,r$ as n,o$ as o,vL as p,kL as q,xL as r,B$ as s,CO as t,W0 as u,M$ as v,Bp as w,dV as x,cV as y,mV as z};
83
+ competitor2.com`,value:Zt,onChange:F=>Xa(F.target.value)})]}),cl?c.jsx("p",{className:"text-negative-400 text-sm",children:cl}):null,c.jsxs("div",{className:"setup-nav",children:[c.jsx(xe,{type:"button",variant:"outline",onClick:ct,children:"Back"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(xe,{type:"button",variant:"outline",onClick:mn,children:"Skip"}),c.jsx(xe,{type:"button",disabled:Nt.length===0||Ri,onClick:Ut(Gn),children:Ri?"Saving...":`Save ${Nt.length} competitor${Nt.length!==1?"s":""}`})]})]})]})]});case 4:{const F=Ja.data,qe=F?.status??(Bi===M?.id?M.status:void 0),pn=qe==="completed"||qe==="partial"||qe==="failed"||qe==="cancelled",Qn=F?.snapshots??[],Ss=Qn.filter(Wa=>Wa.citationState==="cited").length,js=Qn.filter(Wa=>Wa.answerMentioned===!0).length,Ca=new Set(Qn.map(Wa=>Wa.query).filter(Wa=>!!Wa)).size,Wt=qe?Kb(qe,Qn.length):!1,Uo=J&&!Ua,Eu=qi??(F?.error?AO(F.error):qe==="cancelled"?"The sweep was cancelled before it produced a baseline.":(qe==="completed"||qe==="partial")&&Qn.length===0?"The sweep finished without producing any snapshots. Confirm the query set and provider configuration, then retry.":M?.statusDetail||"The sweep did not produce a baseline. Review provider configuration, then retry.");let hn=null;return Uo||Wt?hn=c.jsx(ma,{tone:"positive",children:"Complete"}):qi&&!Ua?hn=c.jsx(ma,{tone:"negative",children:"Failed"}):pn?hn=c.jsx(ma,{tone:"negative",children:qe==="cancelled"?"Cancelled":"Failed"}):Ua&&(hn=c.jsx(ma,{tone:"caution",children:"Running"})),c.jsxs(Sa,{className:"surface-card step-card",children:[c.jsxs("div",{className:"section-head",children:[c.jsxs("div",{children:[c.jsx("p",{className:"eyebrow eyebrow-soft",children:"Step 5 of 5"}),c.jsx("h2",{children:"Launch first run"})]}),hn]}),Uo?c.jsxs("div",{className:"compact-stack",children:[c.jsxs("p",{className:"text-secondary",children:["Setup is complete. ",c.jsx("span",{className:"text-strong font-medium",children:Ce})," already has a successful answer-visibility baseline."]}),c.jsxs("div",{className:"setup-nav",children:[c.jsx("span",{}),c.jsx(xe,{type:"button",onClick:zt,children:g?"Finish and open project":"Open project dashboard →"})]})]}):Ua?pn?Wt?c.jsxs("div",{className:"compact-stack",children:[c.jsxs("p",{className:"text-neutral",children:["Sweep complete. Your first answer-visibility snapshot for"," ",c.jsx("span",{className:"text-heading font-medium",children:Ce}),":"]}),c.jsxs("div",{className:"grid grid-cols-3 gap-2 mt-1",children:[c.jsxs("div",{className:"rounded-md border border-default bg-surface p-3",children:[c.jsx("p",{className:"text-xs font-medium text-secondary",children:"Mentioned"}),c.jsxs("p",{className:"text-2xl font-bold tabular-nums text-primary mt-1",children:[js,c.jsxs("span",{className:"text-faint text-lg",children:[" / ",Ca]})]}),c.jsx("p",{className:"mt-0.5 text-sm text-secondary",children:"queries naming your brand"})]}),c.jsxs("div",{className:"rounded-md border border-default bg-surface p-3",children:[c.jsx("p",{className:"text-xs font-medium text-secondary",children:"Cited"}),c.jsxs("p",{className:"text-2xl font-bold tabular-nums text-primary mt-1",children:[Ss,c.jsxs("span",{className:"text-faint text-lg",children:[" / ",Ca]})]}),c.jsx("p",{className:"mt-0.5 text-sm text-secondary",children:"queries citing your site"})]}),c.jsxs("div",{className:"rounded-md border border-default bg-surface p-3",children:[c.jsx("p",{className:"text-xs font-medium text-secondary",children:"Results"}),c.jsx("p",{className:"text-2xl font-bold tabular-nums text-primary mt-1",children:Qn.length}),c.jsx("p",{className:"mt-0.5 text-sm text-secondary",children:"completed engine checks"})]})]}),c.jsx("p",{className:"mt-1 text-sm text-secondary",children:g?"Your project is ready. Review the evidence in the project.":"Open the project to review the evidence."}),c.jsxs("div",{className:"setup-nav",children:[c.jsx("span",{}),c.jsx(xe,{type:"button",onClick:zt,children:g?"Finish and open project":"Open project dashboard →"})]})]}):c.jsxs("div",{className:"compact-stack",children:[c.jsxs("div",{role:"alert",className:"rounded-md border border-negative bg-negative-soft p-3 text-sm text-negative",children:[c.jsx("p",{children:Eu}),c.jsx("p",{className:"mt-1 text-xs text-secondary",children:"Fix provider or query configuration if needed, then retry without leaving setup."})]}),c.jsxs("div",{className:"setup-nav",children:[c.jsx(xe,{type:"button",variant:"outline",asChild:!0,children:c.jsx(Je,{to:"/settings",children:"Configure providers"})}),c.jsx(xe,{type:"button",disabled:cn||!!La,onClick:Ut(dn),children:cn?"Retrying...":"Retry visibility sweep"})]})]}):c.jsxs("div",{className:"compact-stack",children:[c.jsx("p",{className:"text-neutral",children:"Sweep running. This usually takes 30 to 60 seconds."}),c.jsx("div",{className:"rounded-md border border-default bg-surface p-3 text-xs text-muted",children:c.jsxs("p",{children:["Status: ",c.jsx("span",{className:"text-neutral",children:qe??"queued"})]})}),Ja.isError&&c.jsxs("div",{role:"alert",className:"rounded-md border border-negative bg-negative-soft p-3 text-sm text-negative",children:[c.jsx("p",{children:Ja.error instanceof Error?Ja.error.message:"Could not refresh the sweep status."}),c.jsx(xe,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>{Ja.refetch()},children:"Retry status check"})]}),c.jsxs("div",{className:"setup-nav",children:[c.jsx("span",{}),c.jsx(xe,{type:"button",variant:"outline",onClick:zt,children:g?"Finish and open project":"Watch on project page"})]})]}):c.jsxs("div",{className:"compact-stack",children:[c.jsxs("p",{className:"supporting-copy",children:["Setup is done. You can run a first sweep now to get a baseline for"," ",c.jsx("span",{className:"text-heading font-medium",children:Ce}),", or finish and run it later from the project. A sweep calls the answer engines, so it costs provider usage."]}),(La||qi)&&c.jsxs("div",{role:"alert",className:"rounded-md border border-negative bg-negative-soft p-3 text-sm text-negative",children:[c.jsx("p",{children:qi??La}),c.jsx("p",{className:"mt-1 text-xs text-secondary",children:"Resolve the blocker above, then retry the sweep here."})]}),c.jsxs("div",{className:"setup-nav",children:[c.jsx(xe,{type:"button",variant:"outline",onClick:ct,children:"Back"}),c.jsx(xe,{type:"button",variant:"ghost",onClick:zt,children:"Finish without running"}),c.jsx(xe,{type:"button",disabled:cn||!!La,title:La,onClick:Ut(dn),children:cn?"Launching...":qi?"Retry visibility sweep":"Launch visibility sweep"})]})]})]})}default:return null}})();return c.jsxs("div",{className:"page-container",children:[g?c.jsx(Ao,{current:"visibility"}):null,c.jsxs("div",{className:"page-header",children:[c.jsxs("div",{className:"page-header-left",children:[c.jsx("h1",{ref:u?f:void 0,tabIndex:u?-1:void 0,className:"page-title",children:u?"Set up AI Visibility":"Setup"}),c.jsx("p",{className:"page-subtitle",children:u?"Choose what to track, then run your first visibility sweep.":"Create a project and run its first visibility check."})]}),g?c.jsx("div",{className:"page-header-right",children:c.jsx(xe,{type:"button",variant:"outline",onClick:zt,children:"Skip AI Visibility"})}):null]}),c.jsx(eI,{current:Re,labels:JP}),c.jsx("section",{className:"setup-wizard",children:Kn})]})}const iI=z.lazy(async()=>({default:(await Pn(()=>import("./SiteHealthSection-Byp_Fu5K.js").then(n=>n.d),__vite__mapDeps([0,1,2,3,4]),import.meta.url)).SiteHealthSection})),sI=1800,oI="https://github.com/Canonry/canonry#or-use-any-shell-capable-coding-agent",rI="Help me set up Canonry for my public site.\n\nUse Canonry's official docs:\n- Agent quickstart: https://github.com/Canonry/canonry#or-use-any-shell-capable-coding-agent\n- CLI reference: https://github.com/Canonry/canonry/blob/main/skills/canonry/references/canonry-cli.md\n- Plugin setup: https://github.com/Canonry/canonry/blob/main/docs/plugins.md\n- MCP setup: https://github.com/Canonry/canonry/blob/main/docs/mcp.md\n\nUse an existing Canonry installation or connected plugin/MCP if one is already available. Do not create a duplicate. The `cnry` and `canonry` commands are interchangeable.\n\n1. Ask for my public domain, country, and language. Do not create or scan anything yet.\n2. Check the local setup with `command -v cnry`, `cnry --version`, `cnry doctor --format json`, and `cnry project list --format json`. If Canonry is missing, propose `npm install -g @canonry/canonry` and wait for approval. If initialization is required, tell me to run `cnry init` in my private terminal and wait. Never ask me to paste passwords, API keys, OAuth credentials, or `cnry init` output.\n3. Show the normalized domain, proposed project name, exact `cnry project create ...` command, and wait for explicit approval before creating it.\n4. Propose a bounded Site Health scan, including `--max-pages` and whether dead-link checking is enabled. Show the exact `cnry technical-aeo run ... --wait --format json` command and wait for separate approval before scanning.\n5. After the crawl, summarize the findings and propose AI Visibility setup. Ask before adding queries, connecting providers, starting any provider-backed or quota-consuming run, editing files, or publishing.";function lI(e,n){return e==="legacy"?"legacy":e==="platform"?"platform":n.state==="success"?n.projectCount===0?"platform":"legacy":n.state==="error"?"retry":"loading"}function cI(e,n){try{const s=new Intl.DisplayNames(["en"],{type:"region"}),r=new Intl.DisplayNames(["en"],{type:"language"}),u=e.length===2?s.of(e.toUpperCase()):void 0,f=n?r.of(n.toLowerCase()):void 0;return`${u??(e||"Country")} · ${f??(n||"Language")}`}catch{return`${e||"Country"} · ${n||"Language"}`}}function uI(e){const n=e.replace(/^\[|\]$/g,"");return/^(?:\d{1,3}\.){3}\d{1,3}$/.test(n)||n.includes(":")}function dI(e){const n=e.trim();if(!n)return null;const s=/^[a-z][a-z\d+.-]*:\/\//i.test(n)?n:`https://${n}`;let r;try{r=new URL(s)}catch{return null}if(r.protocol!=="http:"&&r.protocol!=="https:")return null;const u=r.hostname.toLowerCase().replace(/^www\./,"");if(!u||u==="localhost"||uI(u)||!u.includes("."))return null;const f=u.replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");return f?{canonicalDomain:u,projectName:f,displayName:u}:null}async function mI(e,n=sI){let s;const r=new Promise(f=>{s=setTimeout(()=>f({state:"timed-out"}),n)}),u=await Promise.race([e.then(f=>({state:"queued",run:f})),r]);return s&&clearTimeout(s),u}function pI(e,n){e.catch(()=>{Qt({title:"Site Health scan did not start",detail:"The project is safe. Choose Run scan in Site Health to retry.",tone:"negative",dedupeKey:`site-health-dispatch:${n}`})})}function Zb(e,n){return e instanceof na&&e.statusCode===409?"A project with this name already exists. Change the project name, or open the existing project.":e instanceof Error&&e.message?e.message:n}function hI(){return c.jsxs("div",{className:"page-container max-w-3xl","aria-busy":"true","aria-live":"polite",children:[c.jsx("div",{className:"page-header",children:c.jsxs("div",{className:"page-header-left",children:[c.jsx("h1",{className:"page-title",children:"Preparing setup"}),c.jsx("p",{className:"page-subtitle",children:"Checking the projects already on this install."})]})}),c.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-default bg-surface p-4 text-sm text-secondary",role:"status",children:[c.jsx(fo,{className:"size-4 motion-safe:animate-spin","aria-hidden":"true"}),"Loading projects…"]})]})}function fI({onRetry:e}){return c.jsxs("div",{className:"page-container max-w-3xl",children:[c.jsx("div",{className:"page-header",children:c.jsxs("div",{className:"page-header-left",children:[c.jsx("h1",{className:"page-title",children:"Can’t load projects"}),c.jsx("p",{className:"page-subtitle",children:"Canonry could not confirm whether this install already has a project."})]})}),c.jsxs("div",{className:"rounded-lg border border-negative bg-negative-soft p-4",role:"alert",tabIndex:-1,children:[c.jsx("p",{className:"text-sm font-medium text-heading",children:"Setup is paused to protect existing projects."}),c.jsx("p",{className:"mt-1 text-sm text-secondary",children:"Check the connection or sign in again, then retry."}),c.jsx(xe,{type:"button",className:"mt-4",variant:"secondary",onClick:e,children:"Retry project check"})]})]})}function gI({projectName:e,initialRunId:n}){return c.jsx(ih,{title:"Site Health setup",children:c.jsx(yI,{projectName:e,initialRunId:n})})}function yI({projectName:e,initialRunId:n}){const s=cs(),r=Kt({...ps({client:se}),enabled:!!e,retry:!1,refetchOnMount:"always"});if(!e)return c.jsxs("div",{className:"page-container max-w-3xl",children:[c.jsx("div",{className:"page-header",children:c.jsxs("div",{className:"page-header-left",children:[c.jsx("h1",{className:"page-title",children:"Project not found"}),c.jsx("p",{className:"page-subtitle",children:"This setup link does not identify a project."})]})}),c.jsx(xe,{type:"button",variant:"secondary",onClick:()=>{s({to:"/projects"})},children:"View projects"})]});if(r.isPending)return c.jsxs("div",{className:"page-container max-w-3xl","aria-busy":"true","aria-live":"polite",children:[c.jsx(Ao,{current:"site"}),c.jsxs("div",{className:"mt-8 flex items-center gap-3 text-sm text-secondary",role:"status",children:[c.jsx(fo,{className:"size-4 motion-safe:animate-spin","aria-hidden":"true"}),"Loading Site Health setup…"]})]});if(r.isError)return c.jsxs("div",{className:"page-container max-w-3xl",children:[c.jsx("div",{className:"page-header",children:c.jsxs("div",{className:"page-header-left",children:[c.jsx("h1",{className:"page-title",children:"Can’t resume setup"}),c.jsx("p",{className:"page-subtitle",children:"Canonry could not load the project for this Site Health scan."})]})}),c.jsxs("div",{className:"rounded-lg border border-negative bg-negative-soft p-4",role:"alert",children:[c.jsx("p",{className:"text-sm text-secondary",children:"Check the connection or sign in again, then retry."}),c.jsx(xe,{type:"button",className:"mt-4",variant:"secondary",onClick:()=>{r.refetch()},children:"Retry project check"})]})]});const u=r.data.find(x=>x.name===e);if(!u)return c.jsxs("div",{className:"page-container max-w-3xl",children:[c.jsx("div",{className:"page-header",children:c.jsxs("div",{className:"page-header-left",children:[c.jsx("h1",{className:"page-title",children:"Project not found"}),c.jsxs("p",{className:"page-subtitle",children:["Canonry could not find ",e,". It will not open a different project."]})]})}),c.jsx(xe,{type:"button",variant:"secondary",onClick:()=>{s({to:"/projects"})},children:"View projects"})]});const f=()=>{s({to:"/setup",search:{onboarding:"site-health",setupProject:u.name},replace:!0})},g=()=>{s({to:"/setup",search:{experience:"legacy",onboarding:"site-health",setupProject:u.name},replace:!0})},b=()=>{s({to:"/projects/$projectName",params:{projectName:u.name},replace:!0})};return c.jsxs("div",{className:"page-container max-w-7xl py-8 md:py-10",children:[c.jsx("h1",{className:"sr-only",children:"Set up Canonry"}),c.jsx(z.Suspense,{fallback:c.jsxs("div",{className:"space-y-5",children:[c.jsx(Ao,{current:"site"}),c.jsxs("div",{className:"flex min-h-72 items-center justify-center gap-3 text-sm text-secondary",role:"status",children:[c.jsx(fo,{className:"size-4 motion-safe:animate-spin","aria-hidden":"true"}),"Loading Site Health…"]})]}),children:c.jsx(iI,{projectName:u.name,projectId:u.id,initialRunId:n,onReleaseInitialRun:f,showOnboardingActions:!0,onContinueOnboarding:g,onSkipOnboarding:b})})]})}function bI(){const e=Yb({from:"/setup"}),n=e.onboarding==="site-health"&&!e.setupProject,s=e.onboarding==="site-health"&&e.experience!=="legacy",r=z5(),u=e.experience==="legacy"?"legacy":r,[f,g]=z.useState(!1),b=Kt({...ps({client:se}),enabled:u==="auto",retry:!1,refetchOnMount:"always"}),x=u==="auto"&&b.isSuccess&&b.isFetchedAfterMount&&b.data.length===0;z.useEffect(()=>{x&&g(!0)},[x]);const k=u!=="auto"?{state:"idle"}:b.isSuccess&&b.isFetchedAfterMount?{state:"success",projectCount:b.data.length}:b.isError?{state:"error"}:{state:"loading"},S=u==="legacy"?"legacy":f||x?"platform":lI(u,k);return n||s?c.jsx(gI,{projectName:e.setupProject,initialRunId:e.siteHealthRunId}):S==="legacy"?c.jsx(tI,{visibilityProjectName:e.setupProject,siteHealthOnboarding:e.onboarding==="site-health"}):S==="loading"?c.jsx(hI,{}):S==="retry"?c.jsx(fI,{onRetry:()=>{b.refetch()}}):c.jsx(vI,{onActivationStarted:()=>g(!0)})}function vI({onActivationStarted:e}){return c.jsx(ih,{title:"Site Health setup",children:c.jsx(xI,{onActivationStarted:e})})}function xI({onActivationStarted:e}){const n=cs(),s=Mn(),r=HP(),[u,f]=z.useState(""),[g,b]=z.useState(""),[x,k]=z.useState(""),[S,A]=z.useState("US"),[j,D]=z.useState("en"),[R,q]=z.useState(!1),[U,V]=z.useState("idle"),[te,X]=z.useState(null),[ae,oe]=z.useState(null),[fe,M]=z.useState(!1),[J,_e]=z.useState(null),[me,we]=z.useState(!1),Re=z.useRef(null),je=dI(u),Qe=g||je?.projectName||"",ge=x||je?.displayName||"",I=U==="creating"||U==="dispatching",ne=ae??J,he=cI(S,j);z.useEffect(()=>{ne&&Re.current?.focus()},[ne]);const Ee=(re,W)=>n({to:"/setup",search:{...W?{siteHealthRunId:W}:{},onboarding:"site-health",setupProject:re.name},replace:!0}),le=async re=>{V("dispatching"),_e(null);try{const W=r.mutateAsync({projectName:re.name,projectId:re.id,projectLabel:re.displayName||re.name,suppressErrorToast:!0,body:{checkDeadLinks:!0}}),Z=await mI(W);if(Z.state==="queued"){await Ee(re,Z.run.runId);return}pI(W,re.id),await Ee(re)}catch(W){V("recovery"),_e(Zb(W,"The project was created, but the Site Health scan could not be started."))}},et=async re=>{if(re.preventDefault(),!(!je||!R||I)){V("creating"),oe(null),M(!1),_e(null);try{const W=await _v({name:Qe,displayName:ge,canonicalDomain:je.canonicalDomain,country:S,language:j});e(),X(W),await s.invalidateQueries({queryKey:wi({client:se})}),await le(W)}catch(W){V("idle");const Z=W instanceof na&&W.statusCode===409;M(Z),oe(Zb(W,"Could not create the project. Try again.")),Z&&(e(),s.invalidateQueries({queryKey:wi({client:se})}))}}},G=()=>{te&&!I&&le(te)},ce=()=>{I||n({to:"/projects"})},ie=async()=>{try{await navigator.clipboard.writeText(rI),we(!0)}catch{Qt({tone:"negative",title:"Could not copy setup request",detail:"Open the agent quickstart to continue with the CLI instead."})}};return te&&U==="recovery"?c.jsxs("div",{className:"page-container max-w-3xl",children:[c.jsx(Ao,{current:"site"}),c.jsx("div",{className:"page-header mt-8",children:c.jsxs("div",{className:"page-header-left",children:[c.jsx("h1",{className:"page-title",children:"Project created"}),c.jsxs("p",{className:"page-subtitle",children:[te.displayName||te.name," is ready. The Site Health scan needs another try."]})]})}),c.jsxs("div",{ref:Re,className:"rounded-lg border border-negative bg-negative-soft p-4",role:"alert",tabIndex:-1,children:[c.jsx("p",{className:"text-sm font-medium text-heading",children:J}),c.jsx("p",{className:"mt-1 text-sm text-secondary",children:"You can retry the scan or continue setup and retry from Site Health."}),c.jsxs("div",{className:"mt-4 flex flex-wrap gap-3",children:[c.jsx(xe,{type:"button",onClick:G,children:"Retry Site Health scan"}),c.jsx(xe,{type:"button",variant:"secondary",onClick:()=>{Ee(te)},children:"Continue setup"})]})]})]}):c.jsxs("div",{className:"page-container max-w-xl py-8 md:py-12",children:[c.jsx(Ao,{current:"site"}),c.jsxs("header",{className:"mb-8 mt-8",children:[c.jsx("h1",{id:"site-map-setup-title",className:"text-2xl font-semibold tracking-[-0.025em] text-heading",children:"Map your site"}),c.jsx("p",{className:"mt-2 max-w-lg text-sm leading-6 text-secondary",children:"Enter your public website to see its pages, structure, and internal links."})]}),c.jsxs("form",{"aria-labelledby":"site-map-setup-title",className:"space-y-6",onSubmit:Ut(et),noValidate:!0,children:[c.jsxs("div",{className:"grid gap-2",children:[c.jsx("label",{className:"text-sm font-medium text-heading",htmlFor:"launchpad-domain",children:"Website URL"}),c.jsx("input",{id:"launchpad-domain",className:"h-11 w-full rounded-md border border-strong bg-bg-elevated/50 px-3 text-base text-heading outline-none transition placeholder:text-muted focus:border-mono-500 focus:ring-1 focus:ring-mono-500",type:"text",inputMode:"url",autoComplete:"url",autoCapitalize:"none",spellCheck:!1,required:!0,"aria-invalid":!!(u&&!je),"aria-describedby":u&&!je?"launchpad-domain-hint launchpad-domain-error":"launchpad-domain-hint",placeholder:"https://example.com",value:u,onChange:re=>{f(re.target.value),oe(null),M(!1)}}),c.jsxs("p",{id:"launchpad-domain-hint",className:"text-sm text-secondary",children:["Only public pages are scanned."," ",c.jsx(Je,{to:"/setup",search:{experience:"legacy"},className:"font-medium text-link underline-offset-4 hover:underline",children:"Set up without a site scan"})]}),u&&!je?c.jsx("p",{id:"launchpad-domain-error",className:"text-sm text-negative",role:"alert",children:"Enter a public domain, such as example.com."}):null]}),c.jsxs("details",{className:"group border-y border-default",children:[c.jsxs("summary",{className:"flex min-h-11 cursor-pointer list-none items-center justify-between gap-4 py-3 text-sm [&::-webkit-details-marker]:hidden",children:[c.jsx("span",{className:"font-medium text-heading",children:"Advanced settings"}),c.jsxs("span",{className:"flex items-center gap-2 text-secondary",children:[he,c.jsx(Lp,{className:"size-4 transition-transform group-open:rotate-180 motion-reduce:transition-none","aria-hidden":"true"})]})]}),c.jsxs("div",{className:"space-y-5 border-t border-default py-4",children:[je?c.jsxs("div",{children:[c.jsx("p",{className:"mb-3 text-sm font-medium text-heading",children:"Project"}),c.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[c.jsxs("div",{className:"grid gap-2",children:[c.jsx("label",{className:"text-sm text-secondary",htmlFor:"launchpad-project-name",children:"Project name"}),c.jsx("input",{id:"launchpad-project-name",className:"setup-input h-10",type:"text",value:Qe,onChange:re=>b(re.target.value)})]}),c.jsxs("div",{className:"grid gap-2",children:[c.jsx("label",{className:"text-sm text-secondary",htmlFor:"launchpad-display-name",children:"Display name"}),c.jsx("input",{id:"launchpad-display-name",className:"setup-input h-10",type:"text",value:ge,onChange:re=>k(re.target.value)})]})]})]}):null,c.jsxs("div",{children:[c.jsx("p",{className:"mb-3 text-sm font-medium text-heading",children:"Locale"}),c.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[c.jsxs("div",{className:"grid gap-2",children:[c.jsx("label",{className:"text-sm text-secondary",htmlFor:"launchpad-country",children:"Country"}),c.jsx("input",{id:"launchpad-country",className:"setup-input h-10",type:"text",maxLength:2,value:S,onChange:re=>A(re.target.value.toUpperCase())})]}),c.jsxs("div",{className:"grid gap-2",children:[c.jsx("label",{className:"text-sm text-secondary",htmlFor:"launchpad-language",children:"Language"}),c.jsx("input",{id:"launchpad-language",className:"setup-input h-10",type:"text",maxLength:5,value:j,onChange:re=>D(re.target.value.toLowerCase())})]})]})]})]})]}),c.jsxs("label",{className:"flex min-h-11 cursor-pointer items-start gap-3 py-2",children:[c.jsx("input",{className:"mt-0.5 size-4 shrink-0 rounded border-strong bg-bg",type:"checkbox",checked:R,onChange:re=>q(re.target.checked),"aria-label":"Allow Canonry to scan this public site.","aria-describedby":"local-crawl-note"}),c.jsxs("span",{className:"grid gap-0.5",children:[c.jsx("span",{className:"text-sm leading-5 text-heading",children:"Allow Canonry to scan this public site."}),c.jsx("span",{id:"local-crawl-note",className:"text-sm leading-5 text-secondary",children:"The crawl runs on this Canonry instance, follows internal links, and stores its results locally."})]})]}),ne?c.jsxs("div",{ref:Re,className:"rounded-md border border-negative bg-negative-soft p-3",role:"alert",tabIndex:-1,children:[c.jsx("p",{className:"text-sm font-medium text-heading",children:ne}),fe?c.jsx(xe,{type:"button",variant:"secondary",size:"sm",className:"mt-3",onClick:ce,children:"View projects"}):null]}):null,c.jsxs("div",{className:"grid gap-2",children:[c.jsx(xe,{className:"h-11 w-full",type:"submit",disabled:!je||!R||I,children:U==="creating"||U==="dispatching"?c.jsxs(c.Fragment,{children:[c.jsx(fo,{className:"size-4 motion-safe:animate-spin","aria-hidden":"true"})," Mapping site…"]}):"Map site"}),c.jsx(xe,{className:"w-full",type:"button",variant:"ghost",disabled:I,onClick:ce,children:"Cancel"}),U==="dispatching"?c.jsx("span",{className:"text-center text-sm text-secondary",role:"status",children:"Opening Site Health when the scan is ready."}):null]})]}),c.jsxs("section",{className:"mt-8 border-t border-default pt-6","aria-labelledby":"agent-setup-title",children:[c.jsx("p",{id:"agent-setup-title",className:"text-sm font-medium text-heading",children:"Use your agent instead"}),c.jsx("p",{className:"mt-1 text-sm leading-5 text-secondary",children:"Copy a complete CLI setup request into any coding agent."}),c.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-1",children:[c.jsxs(xe,{type:"button",variant:"ghost",size:"sm",className:"-ml-3",onClick:Ut(ie),children:[me?c.jsx(Vp,{className:"size-3.5","aria-hidden":"true"}):c.jsx(ov,{className:"size-3.5","aria-hidden":"true"}),c.jsx("span",{"aria-live":"polite",children:me?"Copied setup request":"Copy setup request"})]}),c.jsx(xe,{asChild:!0,variant:"ghost",size:"sm",children:c.jsxs("a",{href:oI,target:"_blank",rel:"noopener noreferrer",children:["Agent quickstart",c.jsx(DS,{className:"size-3.5","aria-hidden":"true"}),c.jsx("span",{className:"sr-only",children:" (opens in a new tab)"})]})})]})]})]})}function kI(){return c.jsx("div",{className:"page-container",children:c.jsx("section",{className:"page-section",children:c.jsxs(Sa,{className:"surface-card empty-card",children:[c.jsx("h1",{children:"Route not found"}),c.jsx("p",{children:"The current path does not map to a dashboard view."}),c.jsx(xe,{asChild:!0,children:c.jsx(Je,{to:"/",children:"Return to overview"})})]})})})}const Ya=Si(()=>Pn(()=>import("./ProjectPage-D6-9qYKU.js"),__vite__mapDeps([5,1,6,0,2,3,4,7,8,9,10,11,12]),import.meta.url),"ProjectPage"),wI=Si(()=>Pn(()=>import("./RunsPage-CaDPSEfE.js"),__vite__mapDeps([13,1,6,10,4,2,11,12]),import.meta.url),"RunsPage"),SI=Si(()=>Pn(()=>import("./HistoryPage-CRSuA-J0.js"),__vite__mapDeps([14,1,8,10,4,2,11,12]),import.meta.url),"HistoryPage"),jI=Si(()=>Pn(()=>import("./SettingsPage-Dcp71zcu.js"),__vite__mapDeps([15,1,10,4,2,11,12]),import.meta.url),"SettingsPage"),AI=Si(()=>Pn(()=>import("./BacklinksPage-p19FCIyh.js"),__vite__mapDeps([16,1,2,10,4,11,12]),import.meta.url),"BacklinksPage"),NI=Si(()=>Pn(()=>import("./TrafficPage-BXkXNKYB.js"),__vite__mapDeps([17,1,7,2,10,4,11,12]),import.meta.url),"TrafficPage"),CI=Si(()=>Pn(()=>import("./TrafficSourceDetailPage-CReS8q0H.js"),__vite__mapDeps([18,1,7,3,4,2,10,11,12]),import.meta.url),"TrafficSourceDetailPage"),_I=Si(()=>Pn(()=>import("./MeasurementPropertyPage-Bgr9VeUk.js"),__vite__mapDeps([19,1,3,4,9,2,10,11,12]),import.meta.url),"MeasurementPropertyPage");function zI(){return c.jsx(EP,{children:c.jsx(zP,{})})}const ia=oS()({component:zI,validateSearch:e=>({manageQueries:e.manageQueries===!0||e.manageQueries==="true"?!0:void 0,runId:typeof e.runId=="string"?e.runId:void 0,siteHealthRunId:typeof e.siteHealthRunId=="string"?e.siteHealthRunId:void 0,evidenceId:typeof e.evidenceId=="string"?e.evidenceId:void 0,runStatus:typeof e.runStatus=="string"?e.runStatus:void 0,runKind:typeof e.runKind=="string"?e.runKind:void 0,runProject:typeof e.runProject=="string"?e.runProject:void 0,runWindow:typeof e.runWindow=="string"?e.runWindow:void 0,runQuery:typeof e.runQuery=="string"?e.runQuery:void 0,onboarding:e.onboarding==="site-health"?"site-health":void 0,experience:e.experience==="legacy"?"legacy":void 0,setupProject:typeof e.setupProject=="string"?e.setupProject:void 0,scope:typeof e.scope=="string"?e.scope:void 0,class:typeof e.class=="string"?e.class:void 0})}),EI=kt({getParentRoute:()=>ia,path:"/",component:qP,beforeLoad:async({context:e})=>{let n=e.queryClient.getQueryData(wi({client:se}));if(n===void 0)try{n=await e.queryClient.ensureQueryData(ps({client:se}))}catch{return}if(n.length===0)throw Jb({to:"/setup"})}}),DI=kt({getParentRoute:()=>ia,path:"/projects",component:MP}),TI=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,Aa=kt({getParentRoute:()=>ia,path:"/projects/$projectName",component:()=>c.jsx(cp,{}),beforeLoad:async({context:e,params:n,location:s})=>{const r=n.projectName;if(!TI.test(r))return;let u=e.queryClient.getQueryData(wi({client:se}));if(!u)try{u=await e.queryClient.ensureQueryData(ps({client:se}))}catch{return}const f=u.find(g=>g.id===r);if(f)throw Jb({to:s.pathname.replace(`/projects/${r}`,`/projects/${encodeURIComponent(f.name)}`),replace:!0})}}),RI=kt({getParentRoute:()=>Aa,path:"/",component:()=>c.jsx(Ya,{tab:"overview"})}),OI=kt({getParentRoute:()=>Aa,path:"/portfolio",component:()=>c.jsx(Ya,{tab:"portfolio"})}),qI=kt({getParentRoute:()=>Aa,path:"/search-console",component:()=>c.jsx(Ya,{tab:"search-console"})}),BI=kt({getParentRoute:()=>Aa,path:"/local",component:()=>c.jsx(Ya,{tab:"local"})}),MI=kt({getParentRoute:()=>Aa,path:"/discovery",component:()=>c.jsx(Ya,{tab:"discovery"})}),PI=kt({getParentRoute:()=>Aa,path:"/properties/$targetKey",component:()=>c.jsx(_I,{})}),II=kt({getParentRoute:()=>Aa,path:"/report",component:()=>c.jsx(Ya,{tab:"report"})}),UI=kt({getParentRoute:()=>Aa,path:"/activity",component:()=>c.jsx(Ya,{tab:"activity"})}),LI=kt({getParentRoute:()=>Aa,path:"/backlinks",component:()=>c.jsx(Ya,{tab:"backlinks"})}),VI=kt({getParentRoute:()=>Aa,path:"/technical-aeo",component:()=>c.jsx(Ya,{tab:"technical-aeo"})}),$I=kt({getParentRoute:()=>Aa,path:"/history",component:()=>c.jsx(Ya,{tab:"history"})}),HI=kt({getParentRoute:()=>Aa,path:"/settings",component:()=>c.jsx(Ya,{tab:"settings"})}),GI=kt({getParentRoute:()=>ia,path:"/runs",component:wI}),KI=kt({getParentRoute:()=>ia,path:"/history",component:SI}),QI=kt({getParentRoute:()=>ia,path:"/settings",component:jI,beforeLoad:({context:e})=>{}}),ZI=kt({getParentRoute:()=>ia,path:"/setup",component:bI}),FI=kt({getParentRoute:()=>ia,path:"/backlinks",component:AI}),YI=kt({getParentRoute:()=>ia,path:"/traffic",component:NI}),XI=kt({getParentRoute:()=>ia,path:"/traffic/$projectName/$sourceId",component:CI}),JI=kt({getParentRoute:()=>ia,path:"*",component:kI}),WI=ia.addChildren([EI,DI,Aa.addChildren([RI,OI,qI,BI,MI,PI,II,UI,LI,VI,$I,HI]),GI,KI,QI,ZI,FI,YI,XI,JI]);function eU(){return typeof window<"u"&&window.__CANONRY_CONFIG__?.basePath?window.__CANONRY_CONFIG__.basePath:"/"}const Fb=eU(),tU=Fb==="/"?"":Fb.replace(/\/$/,"");function aU(e,n){return rS({routeTree:WI,basepath:tU||"/",context:{queryClient:e},...n?.initialEntries})}const nU=6e4;function iU(){const[e,n]=z.useState(Lm()?"ready":"checking"),[s,r]=z.useState(null),[u,f]=z.useState(!1),[g,b]=z.useState(""),[x,k]=z.useState(""),[S,A]=z.useState(""),[j,D]=z.useState(null),[R,q]=z.useState(!1),[U,V]=z.useState(!1),te=z.useRef(null),X=z.useRef(null),ae=z.useRef(null),oe=()=>{const me=s?`${s.name}:${s.role}`:"no-accounts";if(!te.current||ae.current!==me){X.current?.clear();const we=j6();X.current=we,te.current=aU(we),ae.current=me}return{queryClient:X.current,router:te.current}},fe=me=>me.authRequired?(f(!0),r(me.user),n(me.user?"ready":"account-login"),!0):!1;z.useEffect(()=>{if(Lm())return;let me=!1;return Promise.allSettled([Wg(),Jg()]).then(([we,Re])=>{if(me||we.status==="fulfilled"&&fe(we.value))return;if(Re.status==="rejected"){const Qe=Re.reason;D(Qe instanceof Error?Qe.message:"Failed to reach the Canonry API"),n("login");return}const je=Re.value;je.authenticated?n("ready"):n(je.setupRequired?"setup":"login")}),()=>{me=!0}},[]),z.useEffect(()=>{if(e!=="ready"||Lm())return;const me=setInterval(()=>{if(u){Wg().then(we=>{we.authRequired&&!we.user&&(V(!0),r(null),n("account-login"))}).catch(()=>{});return}Jg().then(we=>{we.authenticated||(V(!0),n(we.setupRequired?"setup":"login"))}).catch(()=>{})},nU);return Xg(()=>{V(!0),r(null),n(u?"account-login":"login")}),()=>{clearInterval(me),Xg(null)}},[e,u]);const M=async me=>{if(me.preventDefault(),!x.trim()||x.trim().length<8){D("Password must be at least 8 characters");return}if(x!==S){D("Passwords do not match");return}q(!0),D(null);try{if(!(await J5(x.trim())).authenticated){D("Setup failed");return}k(""),A(""),V(!1),n("ready")}catch(we){D(we instanceof na||we instanceof Error?we.message:"Setup failed")}finally{q(!1)}},J=async me=>{if(me.preventDefault(),!!x.trim()){q(!0),D(null);try{if(!(await W5(x.trim())).authenticated){D("Incorrect password");return}k(""),V(!1),n("ready")}catch(we){D(we instanceof na||we instanceof Error?we.message:"Authentication failed")}finally{q(!1)}}},_e=async me=>{if(me.preventDefault(),!(!g.trim()||!x)){q(!0),D(null);try{const we=await e6(g.trim(),x);if(!we.user){D("Incorrect name or password.");return}k(""),V(!1),r(we.user),n("ready")}catch(we){D(we instanceof na?we.message:"Incorrect name or password.")}finally{q(!1)}}};if(e==="ready"){const{queryClient:me,router:we}=oe();return c.jsx(h6,{account:s,children:c.jsx(lS,{client:me,children:c.jsx(cS,{router:we})})})}return c.jsx("div",{className:"min-h-screen bg-bg px-4 py-8",children:c.jsxs("div",{className:"mx-auto flex min-h-[calc(100vh-4rem)] max-w-md flex-col items-center justify-center gap-5",children:[c.jsxs("div",{"data-testid":"auth-brand",className:"flex items-center gap-2.5",children:[c.jsx("img",{className:"size-7",src:"./favicon.svg",alt:"","aria-hidden":"true"}),c.jsx("span",{className:"text-lg font-semibold tracking-tight text-heading",children:"Canonry"})]}),c.jsx(Sa,{className:"surface-card w-full",children:e==="checking"?c.jsx(uo,{className:"py-8",children:c.jsx("p",{className:"supporting-copy text-center",children:"Connecting to Canonry…"})}):e==="account-login"?c.jsxs(c.Fragment,{children:[c.jsxs(Ur,{children:[c.jsx("p",{className:"eyebrow eyebrow-soft",children:"Dashboard access"}),c.jsx(Lr,{children:"Sign in to Canonry"})]}),c.jsxs(uo,{children:[U?c.jsx("p",{className:"mb-4 rounded-md border border-caution bg-caution-soft px-3 py-2 text-sm text-caution",children:"You were signed out — please sign in again."}):null,c.jsxs("form",{className:"space-y-4",onSubmit:Ut(_e),children:[c.jsxs("label",{className:"block space-y-1.5",htmlFor:"account-name",children:[c.jsx("span",{className:"text-xs font-medium text-secondary",children:"Name"}),c.jsx("input",{autoFocus:!0,id:"account-name",className:"w-full rounded-md border border-base bg-bg px-3 py-2 text-sm text-heading outline-none transition focus:border-mono-600",type:"text",autoComplete:"username",value:g,onChange:me=>b(me.target.value)})]}),c.jsxs("label",{className:"block space-y-1.5",htmlFor:"account-password",children:[c.jsx("span",{className:"text-xs font-medium text-secondary",children:"Password"}),c.jsx("input",{id:"account-password",className:"w-full rounded-md border border-base bg-bg px-3 py-2 text-sm text-heading outline-none transition focus:border-mono-600",type:"password",autoComplete:"current-password",value:x,onChange:me=>k(me.target.value)})]}),j?c.jsx("p",{className:"text-sm text-negative-400",children:j}):null,c.jsx(xe,{type:"submit",disabled:R||!g.trim()||!x,children:R?"Signing in…":"Sign in"})]})]})]}):e==="setup"?c.jsxs(c.Fragment,{children:[c.jsxs(Ur,{children:[c.jsx("p",{className:"eyebrow eyebrow-soft",children:"First-time setup"}),c.jsx(Lr,{children:"Create a dashboard password"}),c.jsx(Xc,{children:"Choose a password to protect the Canonry dashboard."})]}),c.jsx(uo,{children:c.jsxs("form",{className:"space-y-4",onSubmit:Ut(M),children:[c.jsxs("label",{className:"block space-y-1.5",children:[c.jsx("span",{className:"text-xs font-medium text-secondary",children:"Password"}),c.jsx("input",{autoFocus:!0,className:"w-full rounded-md border border-base bg-bg px-3 py-2 text-sm text-heading outline-none transition focus:border-mono-600",type:"password",value:x,onChange:me=>k(me.target.value),placeholder:"At least 8 characters"})]}),c.jsxs("label",{className:"block space-y-1.5",children:[c.jsx("span",{className:"text-xs font-medium text-secondary",children:"Confirm password"}),c.jsx("input",{className:"w-full rounded-md border border-base bg-bg px-3 py-2 text-sm text-heading outline-none transition focus:border-mono-600",type:"password",value:S,onChange:me=>A(me.target.value),placeholder:"Re-enter password"})]}),j?c.jsx("p",{className:"text-sm text-negative-400",children:j}):null,c.jsx(xe,{type:"submit",disabled:R||!x.trim()||!S.trim(),children:R?"Setting up…":"Create password & open dashboard"})]})})]}):c.jsxs(c.Fragment,{children:[c.jsxs(Ur,{children:[c.jsx("p",{className:"eyebrow eyebrow-soft",children:"Dashboard access"}),c.jsx(Lr,{children:"Sign in to Canonry"}),c.jsx(Xc,{children:"Enter your dashboard password to continue."})]}),c.jsxs(uo,{children:[U?c.jsx("p",{className:"mb-4 rounded-md border border-caution bg-caution-soft px-3 py-2 text-sm text-caution",children:"Your session expired — please sign in again."}):null,c.jsxs("form",{className:"space-y-4",onSubmit:Ut(J),children:[c.jsxs("label",{className:"block space-y-1.5",children:[c.jsx("span",{className:"text-xs font-medium text-secondary",children:"Password"}),c.jsx("input",{autoFocus:!0,className:"w-full rounded-md border border-base bg-bg px-3 py-2 text-sm text-heading outline-none transition focus:border-mono-600",type:"password",value:x,onChange:me=>k(me.target.value),placeholder:"Dashboard password"})]}),j?c.jsx("p",{className:"text-sm text-negative-400",children:j}):null,c.jsx(xe,{type:"submit",disabled:R||!x.trim(),children:R?"Signing in…":"Open dashboard"})]})]})]})})]})})}const Kk=document.getElementById("root");if(!Kk)throw new Error("Expected #root element for web app bootstrap.");PS.createRoot(Kk).render(c.jsx(z.StrictMode,{children:c.jsx(iU,{})}));export{XV as $,VU as A,xe as B,Qc as C,qV as D,PV as E,MV as F,UL as G,JU as H,Or as I,XU as J,cL as K,Qt as L,LV as M,VV as N,nL as O,sM as P,$V as Q,iL as R,jO as S,ma as T,eL as U,aL as V,IV as W,UV as X,BV as Y,WU as Z,HV as _,T$ as a,yU as a$,QV as a0,FV as a1,ZV as a2,YV as a3,d6 as a4,Z0 as a5,Oe as a6,KV as a7,hk as a8,Bn as a9,lV as aA,f$ as aB,g$ as aC,y$ as aD,sL as aE,wi as aF,oL as aG,K0 as aH,c$ as aI,FO as aJ,RV as aK,ue as aL,DU as aM,EU as aN,zU as aO,_U as aP,AU as aQ,jU as aR,CU as aS,NU as aT,SU as aU,wU as aV,fU as aW,gU as aX,kU as aY,xU as aZ,vU as a_,GV as aa,U$ as ab,V9 as ac,$9 as ad,$L as ae,VL as af,zL as ag,qL as ah,BL as ai,na as aj,ML as ak,RU as al,AO as am,cB as an,Bc as ao,PL as ap,hp as aq,u$ as ar,tL as as,LL as at,BO as au,tq as av,CV as aw,zV as ax,_V as ay,rV as az,W7 as b,a$ as b$,bU as b0,hU as b1,pU as b2,mU as b3,dU as b4,cj as b5,WL as b6,l$ as b7,JL as b8,yL as b9,Sv as bA,yV as bB,bV as bC,P$ as bD,$P as bE,EV as bF,OV as bG,vV as bH,kV as bI,SV as bJ,xV as bK,aa as bL,K5 as bM,EO as bN,O$ as bO,qU as bP,BU as bQ,OU as bR,Z5 as bS,MU as bT,qO as bU,LU as bV,JV as bW,e$ as bX,o6 as bY,hL as bZ,t$ as b_,I$ as ba,aV as bb,eV as bc,nV as bd,iV as be,XL as bf,tV as bg,UU as bh,IU as bi,PU as bj,bL as bk,HU as bl,fV as bm,yb as bn,hV as bo,GU as bp,KU as bq,pV as br,QU as bs,ZU as bt,YU as bu,FU as bv,sl as bw,ps as bx,FM as by,Fr as bz,R$ as c,HP as c$,WV as c0,uV as c1,uL as c2,dL as c3,mL as c4,fL as c5,pL as c6,go as c7,Q0 as c8,q$ as c9,Rk as cA,Ok as cB,NL as cC,p$ as cD,oV as cE,L0 as cF,gV as cG,d$ as cH,h$ as cI,AL as cJ,sV as cK,SL as cL,jL as cM,wL as cN,m$ as cO,M_ as cP,jV as cQ,wV as cR,NV as cS,AV as cT,KL as cU,Pn as cV,Pa as cW,GL as cX,b$ as cY,x$ as cZ,v$ as c_,Su as ca,X0 as cb,DV as cc,TV as cd,t6 as ce,I5 as cf,TU as cg,$U as ch,rL as ci,lL as cj,ih as ck,ju as cl,J0 as cm,gL as cn,jo as co,vb as cp,CL as cq,EL as cr,TL as cs,RL as ct,_L as cu,DL as cv,OL as cw,oM as cx,Tk as cy,dM as cz,Sa as d,QL as d0,z$ as d1,E$ as d2,D$ as d3,k$ as d4,w$ as d5,HL as d6,A$ as d7,_$ as d8,j$ as d9,C$ as da,S$ as db,Ao as dc,ZL as dd,N$ as de,NE as df,YL as dg,FL as dh,on as e,Ut as f,IL as g,Eb as h,q5 as i,n$ as j,se as k,i$ as l,s$ as m,r$ as n,o$ as o,vL as p,kL as q,xL as r,B$ as s,CO as t,W0 as u,M$ as v,Bp as w,dV as x,cV as y,mV as z};