@undefineds.co/xpod 0.4.33 → 0.4.35

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 (103) hide show
  1. package/dist/http/SubgraphSparqlHttpHandler.d.ts +32 -0
  2. package/dist/http/SubgraphSparqlHttpHandler.js +448 -1
  3. package/dist/http/SubgraphSparqlHttpHandler.jsonld +36 -0
  4. package/dist/storage/rdf/QleverSparqlEngine.d.ts +15 -0
  5. package/dist/storage/rdf/QleverSparqlEngine.js +40 -0
  6. package/dist/storage/rdf/QleverSparqlEngine.jsonld +8 -0
  7. package/dist/storage/rdf/RdfAccessScope.d.ts +12 -0
  8. package/dist/storage/rdf/RdfAccessScope.js +63 -3
  9. package/dist/storage/rdf/RdfQuerySparqlEngine.d.ts +7 -0
  10. package/dist/storage/rdf/RdfQuerySparqlEngine.js +30 -0
  11. package/dist/storage/rdf/RdfQuerySparqlEngine.jsonld +8 -0
  12. package/dist/storage/rdf/index.d.ts +1 -1
  13. package/dist/storage/rdf/index.js +6 -2
  14. package/dist/storage/sparql/SubgraphQueryEngine.d.ts +5 -0
  15. package/dist/storage/sparql/SubgraphQueryEngine.js +9 -0
  16. package/dist/storage/sparql/SubgraphQueryEngine.jsonld +16 -0
  17. package/node_modules/@undefineds.co/ai-connections/dist/AiBuiltinProvidersSection.d.ts +32 -0
  18. package/node_modules/@undefineds.co/ai-connections/dist/AiBuiltinProvidersSection.js +8 -0
  19. package/node_modules/@undefineds.co/ai-connections/dist/AiConnectionsPanel.js +35 -1
  20. package/node_modules/@undefineds.co/ai-connections/dist/AiGatewayKeysSection.d.ts +9 -1
  21. package/node_modules/@undefineds.co/ai-connections/dist/AiGatewayKeysSection.js +32 -6
  22. package/node_modules/@undefineds.co/ai-connections/dist/index.d.ts +1 -0
  23. package/node_modules/@undefineds.co/ai-connections/dist/index.js +1 -0
  24. package/node_modules/@undefineds.co/ai-connections/package.json +2 -2
  25. package/node_modules/@undefineds.co/ai-connections-runtime/dist/contract/ai-connections-client.d.ts +1 -1
  26. package/node_modules/@undefineds.co/ai-connections-runtime/dist/contract/client/normalize.d.ts +16 -1
  27. package/node_modules/@undefineds.co/ai-connections-runtime/dist/contract/client/normalize.js +80 -2
  28. package/node_modules/@undefineds.co/ai-connections-runtime/dist/contract/client/request.js +19 -1
  29. package/node_modules/@undefineds.co/ai-connections-runtime/dist/contract/client/types.d.ts +31 -0
  30. package/node_modules/@undefineds.co/ai-connections-runtime/dist/materials/build-provenance.json +4 -4
  31. package/node_modules/@undefineds.co/ai-connections-runtime/dist/materials/index.json +15 -15
  32. package/node_modules/@undefineds.co/ai-connections-runtime/dist/materials/javascript/provider-catalog/index.json +2 -2
  33. package/node_modules/@undefineds.co/ai-connections-runtime/dist/materials/javascript/service-access-resources/index.json +2 -2
  34. package/node_modules/@undefineds.co/ai-connections-runtime/dist/materials/source/package.json +1 -1
  35. package/node_modules/@undefineds.co/ai-connections-runtime/dist/materials/source-inventory.json +11 -11
  36. package/node_modules/@undefineds.co/ai-connections-runtime/dist/provider-catalog-inputs.json +1 -1
  37. package/node_modules/@undefineds.co/ai-connections-runtime/dist/service-access-resources-inputs.json +1 -1
  38. package/node_modules/@undefineds.co/ai-connections-runtime/package.json +1 -1
  39. package/node_modules/@undefineds.co/extension-host-contracts/dist/materials/build-provenance.json +1 -1
  40. package/node_modules/@undefineds.co/extension-host-contracts/dist/materials/index.json +3 -3
  41. package/node_modules/@undefineds.co/extension-host-contracts/dist/materials/source-inventory.json +1 -1
  42. package/node_modules/@undefineds.co/xpod-afs/dist/licenses/cli-producer-original-binding.json +1 -1
  43. package/node_modules/@undefineds.co/xpod-cli/dist/producer-materials/index.json +1 -1
  44. package/package.json +4 -4
  45. package/static/dashboard/assets/{AccountAuthBoundary-D2peXpst.js → AccountAuthBoundary-DXBGmvsI.js} +1 -1
  46. package/static/dashboard/assets/{DesktopOidcCallback-DXWArav6.js → DesktopOidcCallback-p24MYq1P.js} +1 -1
  47. package/static/dashboard/assets/{DevicePages-BULFk95K.js → DevicePages-DbvhTnse.js} +1 -1
  48. package/static/dashboard/assets/ModelsPage-UMDnRyLA.js +12 -0
  49. package/static/dashboard/assets/{PaneListHeader-BSfEbecP.js → PaneListHeader-DkEH0TT_.js} +1 -1
  50. package/static/dashboard/assets/{PodDeletionAuthorizationPanel-CH-Sx18g.js → PodDeletionAuthorizationPanel-CzrI8Pgw.js} +3 -3
  51. package/static/dashboard/assets/{PodPage-BMpejIra.js → PodPage-TaiWqMBx.js} +1 -1
  52. package/static/dashboard/assets/{SystemSettingsPage-H_Jj6WfF.js → SystemSettingsPage-D4gQjDt1.js} +1 -1
  53. package/static/dashboard/assets/{TasksPage-CTDxlQra.js → TasksPage-CmkiMYil.js} +1 -1
  54. package/static/dashboard/assets/{WebDesktopEntry-Ch7-0C9a.js → WebDesktopEntry-D9kEfhbz.js} +1 -1
  55. package/static/dashboard/assets/{XpodAiConnectionsPodStore-ggRE9fmE.js → XpodAiConnectionsPodStore-orY8vQFl.js} +2 -2
  56. package/static/dashboard/assets/{XpodShellApp-Bwf9UmeJ.js → XpodShellApp-DR65DMOb.js} +4 -4
  57. package/static/dashboard/assets/{account-session-CVzooxS2.js → account-session-BZ2ttIdq.js} +1 -1
  58. package/static/dashboard/assets/{button-DGh2QVt2.js → button-_rwfCMMH.js} +1 -1
  59. package/static/dashboard/assets/{collection-runtime-DwV_9rt2.js → collection-runtime-C74icLtf.js} +1 -1
  60. package/static/dashboard/assets/{createLucideIcon-yLhAxnfL.js → createLucideIcon-DrgScGhc.js} +1 -1
  61. package/static/dashboard/assets/{dashboard-xbXlitKr.js → dashboard--DWjqkYt.js} +2 -2
  62. package/static/dashboard/assets/{index-CMigfjqD.js → index-D6dB-UNq.js} +1 -1
  63. package/static/dashboard/assets/{index-BSiKqEdo.js → index-dx5sc4rE.js} +1 -1
  64. package/static/dashboard/assets/{label-CrDv_y1q.js → label-D02Jpvm9.js} +1 -1
  65. package/static/dashboard/assets/{list-BJM0nqti.js → list-DpFAisnq.js} +1 -1
  66. package/static/dashboard/assets/{nav-item-style-CQbGyYLb.js → nav-item-style-B1-0JkON.js} +1 -1
  67. package/static/dashboard/assets/{safe-continuation-ZTBQTFWB.js → safe-continuation-DUTIOFe5.js} +1 -1
  68. package/static/dashboard/assets/{section-header-CWHRWGXl.js → section-header-CtBnllbG.js} +1 -1
  69. package/static/dashboard/assets/{setting-row-qWtxYGK1.js → setting-row-D_JPuHAJ.js} +1 -1
  70. package/static/dashboard/assets/{xpod-remembered-login-DPMxurVN.js → xpod-remembered-login-CtmMI8xG.js} +3 -3
  71. package/static/dashboard/dashboard.html +1 -1
  72. package/static/settings/assets/{AccountAuthBoundary-4Ywjpb8o.js → AccountAuthBoundary-njIhHpLf.js} +1 -1
  73. package/static/settings/assets/{DesktopOidcCallback-CAmwMT_J.js → DesktopOidcCallback-BjjNwTxc.js} +1 -1
  74. package/static/settings/assets/{DevicePages-DvuHyfHo.js → DevicePages-FFJMu_zL.js} +1 -1
  75. package/static/settings/assets/ModelsPage-6567dZKQ.js +12 -0
  76. package/static/settings/assets/{PaneListHeader-CuFgIbhe.js → PaneListHeader-CuPah5aC.js} +1 -1
  77. package/static/settings/assets/{PodDeletionAuthorizationPanel-DdNgDHH5.js → PodDeletionAuthorizationPanel-aJCKasGz.js} +3 -3
  78. package/static/settings/assets/{PodPage-DnWCNGTO.js → PodPage-BA0DQ3AB.js} +1 -1
  79. package/static/settings/assets/{SystemSettingsPage-k9P_wQcl.js → SystemSettingsPage-BNPH4VWf.js} +1 -1
  80. package/static/settings/assets/{TasksPage-Dk7gUH3J.js → TasksPage-B5m82wjD.js} +1 -1
  81. package/static/settings/assets/{WebDesktopEntry-DJwPVVnU.js → WebDesktopEntry-DgwwIUhg.js} +1 -1
  82. package/static/settings/assets/{XpodAiConnectionsPodStore-BtJQiJsx.js → XpodAiConnectionsPodStore-BJm-rFPs.js} +2 -2
  83. package/static/settings/assets/{XpodShellApp-B47vEQJp.js → XpodShellApp-BwvekJJR.js} +4 -4
  84. package/static/settings/assets/{XpodThemeProvider-Ciuwo_yl.js → XpodThemeProvider-DyX0rUID.js} +2 -2
  85. package/static/settings/assets/{account-session-CMc10iEj.js → account-session-D6vibAra.js} +1 -1
  86. package/static/settings/assets/auth-callback-DXxmF0-p.js +1 -0
  87. package/static/settings/assets/{button-D1dGKY1f.js → button-CV4KJ59A.js} +1 -1
  88. package/static/settings/assets/{collection-runtime-hK37-47o.js → collection-runtime-CARp4Cii.js} +1 -1
  89. package/static/settings/assets/{createLucideIcon-nEiQH43b.js → createLucideIcon-BIwq0vQx.js} +1 -1
  90. package/static/settings/assets/{index-DNdvma6J.js → index-D-LgcKAb.js} +1 -1
  91. package/static/settings/assets/{label-C3EGk_2E.js → label-CFTl2bC_.js} +1 -1
  92. package/static/settings/assets/{list-BensBGZp.js → list-D2aO7Nu-.js} +1 -1
  93. package/static/settings/assets/{nav-item-style-BOKCPNz8.js → nav-item-style-BKpK5_1m.js} +1 -1
  94. package/static/settings/assets/{safe-continuation-BPwW6jdq.js → safe-continuation-DRRY_t4F.js} +1 -1
  95. package/static/settings/assets/{section-header-DOSj5RvJ.js → section-header-COECjyL5.js} +1 -1
  96. package/static/settings/assets/{setting-row-C9k4cGNM.js → setting-row-cGgL78vR.js} +1 -1
  97. package/static/settings/assets/{settings-DtP5C8hi.js → settings-Bvrm5N-k.js} +1 -1
  98. package/static/settings/assets/{xpod-remembered-login-DKFG-zi3.js → xpod-remembered-login-YAmn8ZiP.js} +3 -3
  99. package/static/settings/auth-callback.html +2 -2
  100. package/static/settings/settings.html +2 -2
  101. package/static/dashboard/assets/ModelsPage-xvsVzhGZ.js +0 -12
  102. package/static/settings/assets/ModelsPage-BDXqetwk.js +0 -12
  103. package/static/settings/assets/auth-callback-fcOBaX2w.js +0 -1
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-DNdvma6J.js","assets/xpod-remembered-login-DKFG-zi3.js","assets/createLucideIcon-nEiQH43b.js","assets/XpodThemeProvider-Ciuwo_yl.js","assets/XpodThemeProvider-Cb8CjRQr.css","assets/button-D1dGKY1f.js","assets/PodDeletionAuthorizationPanel-DdNgDHH5.js","assets/account-session-CMc10iEj.js","assets/safe-continuation-BPwW6jdq.js","assets/nav-item-style-BOKCPNz8.js","assets/PodPage-DnWCNGTO.js","assets/XpodAiConnectionsPodStore-BtJQiJsx.js","assets/section-header-DOSj5RvJ.js","assets/setting-row-C9k4cGNM.js","assets/ModelsPage-BDXqetwk.js","assets/list-BensBGZp.js","assets/label-C3EGk_2E.js","assets/DevicePages-DvuHyfHo.js","assets/PaneListHeader-CuFgIbhe.js","assets/TasksPage-Dk7gUH3J.js","assets/TasksPage-DPpAgn4C.css"])))=>i.map(i=>d[i]);
2
- import{aS as Nt,aT as cr,aU as lr,aV as hs,aW as fs,aX as Me,aY as St,aZ as ps,a_ as ms,a$ as je,b0 as kt,b1 as gs,b2 as Rt,b3 as dr,b4 as bs,C as xs,a as vs,H as _s,B as ws,bp as ys,bq as js,V as Q,G as ur,l as Is,br as $e,r as Ns,i as hr,bs as Ss,bt as ks,bu as Rs,bv as ht,bw as Ps,b as Cs,n as Ze,h as Ls,bx as et,by as Pt,bz as Es,p as Ct,bA as Ts,bB as As,bC as Us,bD as Ds,bE as Os,bF as Fs,bG as fr,bH as Lt,bI as Et,q as Tt,bJ as At,aK as Ut,aL as Dt,aM as Ot,L as tt,bK as pr,bL as $s,bM as Bs,X as zs,b5 as Ms,b6 as Xs,b7 as qs,b8 as Gs,b9 as Ws,ba as Hs,bb as Vs,bc as Qs,bd as Ks,be as Js,bf as Ys,bg as Zs,O as en,bh as tn,bi as rn,bj as sn,bk as nn,J as an,S as on,bl as cn,T as ln,bm as dn,Q as un,$ as hn,bn as fn,a9 as pn,M as mn,K as gn,P as bn,bo as xn}from"./xpod-remembered-login-DKFG-zi3.js";import{r as d,j as n,_ as ae,u as mr,n as vn,X as _n,L as rt,b as wn,d as Be,O as ft,o as yn,N as jn,f as be,B as In,p as Nn}from"./XpodThemeProvider-Ciuwo_yl.js";import{c as M,f as Ft,i as gr,a as Sn,B as pe,g as kn}from"./button-D1dGKY1f.js";import{r as ze,k as Rn,I as br,P as Pn,X as Cn,R as xr,w as Ln,E as En}from"./PodDeletionAuthorizationPanel-DdNgDHH5.js";import{X as pt,u as vr,a as _r,r as mt,s as gt,A as bt}from"./account-session-CMc10iEj.js";import{f as Tn,g as An,r as Un,A as Dn}from"./safe-continuation-BPwW6jdq.js";import{k as On,T as wr,u as Fn,D as yr,W as $n,h as Bn,l as zn}from"./nav-item-style-BOKCPNz8.js";import{c as W}from"./createLucideIcon-nEiQH43b.js";const Mn=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],Xn=ze("circle-check",Mn);const qn=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]],Gn=ze("circle-x",qn);const Wn=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],Hn=ze("search",Wn);const Vn=[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],xt=ze("triangle-alert",Vn),jr=d.forwardRef(({className:t,multiple:e,size:r,...s},a)=>n.jsx("select",{ref:a,multiple:e,size:r,className:M(Rn,!e&&(!r||r<=1)&&"min-h-10",t),...s}));jr.displayName="NativeSelect";const Ir=d.forwardRef(({className:t,placeholder:e="搜索",...r},s)=>n.jsxs("div",{className:"relative min-w-0 w-full",children:[n.jsx(Hn,{"aria-hidden":"true",className:"pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),n.jsx(br,{...r,ref:s,type:"search",placeholder:e,className:M("h-auto min-h-8 rounded-lg border-border bg-card py-1 pl-8 pr-2.5 text-[13px] leading-normal",t)})]}));Ir.displayName="SearchInput";const Qn={success:"bg-success",warning:"bg-warning",destructive:"bg-destructive",info:"bg-primary",neutral:"border border-muted-foreground bg-transparent"},Kn={sm:"h-1.5 w-1.5",md:"h-2 w-2"};function vt({tone:t,label:e,size:r="md",className:s,"aria-label":a,...i}){const o=e??a,c=o?{role:"img","aria-label":o,title:o}:{"aria-hidden":!0};return n.jsx("span",{className:M("inline-block shrink-0 rounded-full",Kn[r],Qn[t],s),...i,...c})}function Jn({tone:t,children:e,dotSize:r="sm",className:s,...a}){return n.jsxs("span",{className:M("inline-flex items-center gap-1.5",s),...a,children:[n.jsx(vt,{tone:t,size:r}),n.jsx("span",{children:e})]})}const Yn={info:"border-primary/30 bg-primary/10 text-foreground",success:"border-success/30 bg-success/10 text-foreground",warning:"border-warning/30 bg-warning/10 text-foreground",destructive:"border-destructive/30 bg-destructive/10 text-foreground",neutral:"border-border bg-muted/30 text-foreground"},Zn={info:"text-primary",success:"text-success",warning:"text-warning",destructive:"text-destructive",neutral:"text-muted-foreground"},ea={info:Nt,success:Xn,warning:xt,destructive:Gn,neutral:Nt};function Nr({tone:t="info",title:e,icon:r,action:s,role:a="status",className:i,children:o,...c}){const l=ea[t];return n.jsxs("div",{role:a,className:M("flex items-start gap-2.5 rounded-md border px-3 py-2.5 text-sm leading-normal",Yn[t],i),...c,children:[n.jsx("span",{"aria-hidden":"true",className:M("mt-0.5 shrink-0",Zn[t]),children:r??n.jsx(l,{className:"h-4 w-4"})}),n.jsxs("div",{className:"min-w-0 flex-1",children:[e?n.jsx("p",{className:"font-medium",children:e}):null,o]}),s?n.jsx("div",{className:"shrink-0",children:s}):null]})}const ta={label:"Restoring session…"},Xe={title:"Connecting…",detail:"Waiting for the provider",cancelLabel:"Cancel"},qe={title:"Sign-in failed",primaryLabel:"Retry",secondaryLabel:"Back"};function fe(t,e){return t?.trim()?t:e}function ra({name:t,avatarUrl:e,size:r="lg",marker:s}){const a=r==="lg"?"h-16 w-16 text-xl":"h-10 w-10 text-sm";return n.jsxs("div",{className:"relative shrink-0",children:[e?n.jsx("img",{src:e,alt:t,className:M(a,"rounded-[18%] border border-border/50 object-cover shadow-sm")}):n.jsx("div",{"aria-hidden":"true",className:M(a,"flex items-center justify-center rounded-[18%] bg-primary/10 font-semibold text-primary shadow-sm"),children:t.slice(0,1).toUpperCase()}),s?n.jsx("div",{className:"absolute -bottom-1 -right-1",children:s}):null]})}function sa({accountName:t,avatarUrl:e,label:r}){const s=fe(r,ta.label);return n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-4 p-6",role:"status",children:[t?n.jsxs(n.Fragment,{children:[n.jsx(ra,{name:t,avatarUrl:e,size:"lg"}),n.jsx("p",{className:"text-sm font-medium text-foreground",children:t})]}):null,n.jsx(cr,{className:"h-6 w-6 animate-spin text-muted-foreground","aria-hidden":"true"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:s})]})}function vc({title:t,detail:e,providerLabel:r,providerHost:s,onCancel:a,cancelLabel:i}){const o=fe(t,Xe.title),c=fe(e,Xe.detail),l=fe(i,Xe.cancelLabel);return n.jsxs("div",{className:"flex h-full flex-1 flex-col",children:[n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center px-6 py-8 text-center",role:"status",children:[n.jsx(cr,{className:"mb-4 h-8 w-8 animate-spin text-primary","aria-hidden":"true"}),n.jsx("p",{className:"text-sm font-medium text-foreground",children:o}),n.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:c}),r||s?n.jsxs("div",{className:"mt-4 w-full max-w-[18rem] rounded-lg border border-border/60 bg-muted/30 px-3 py-2",children:[r?n.jsx("p",{className:"truncate text-xs font-medium text-foreground",children:r}):null,s?n.jsx("p",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:s}):null]}):null]}),a?n.jsx("div",{className:"shrink-0 px-5 pb-5",children:n.jsx("button",{type:"button",onClick:a,className:M("h-9 w-full cursor-pointer rounded-md text-xs text-muted-foreground transition-colors hover:bg-muted/40 hover:text-foreground",gr),children:l})}):null]})}function _c({title:t,description:e,primaryLabel:r,onPrimary:s,secondaryLabel:a,onSecondary:i}){const o=fe(t,qe.title),c=fe(r,qe.primaryLabel),l=fe(a,qe.secondaryLabel);return n.jsxs("div",{className:"flex h-full flex-1 flex-col",children:[n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 pb-5 pt-7 text-center",children:[n.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-full bg-destructive/10",children:n.jsx(xt,{className:"h-6 w-6 text-destructive","aria-hidden":"true"})}),n.jsx("p",{className:"text-base font-semibold text-foreground",children:o}),e?n.jsx("p",{className:"max-w-[19rem] text-sm leading-6 text-muted-foreground",role:"alert",children:e}):null]}),n.jsxs("div",{className:"shrink-0 space-y-2 px-4 pb-5",children:[n.jsx("button",{type:"button",onClick:s,className:M("h-9 w-full cursor-pointer rounded-md bg-primary text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 focus-visible:bg-primary/80 disabled:cursor-not-allowed disabled:opacity-50",Ft),children:c}),i?n.jsx("button",{type:"button",onClick:i,className:M("h-9 w-full cursor-pointer rounded-md border border-border/60 bg-muted/30 text-sm font-medium text-foreground transition-colors hover:bg-muted/50 focus-visible:border-ring focus-visible:bg-muted/50",Ft),children:l}):null]})]})}var na=Object.defineProperty,Sr=(t,e)=>na(t,"name",{value:e,configurable:!0}),$t="horizontal",aa=["horizontal","vertical"],ia=d.forwardRef(Sr(function(e,r){const{decorative:s,orientation:a=$t,...i}=e,o=kr(a)?a:$t,l=s?{role:"none"}:{"aria-orientation":o==="vertical"?o:void 0,role:"separator"};return n.jsx(Pn.div,{"data-orientation":o,...l,...i,ref:r})},"Separator"));function kr(t){return aa.includes(t)}Sr(kr,"isValidOrientation");var Rr=ia;const Pr=d.forwardRef(({className:t,orientation:e="horizontal",decorative:r=!0,...s},a)=>n.jsx(Rr,{ref:a,decorative:r,orientation:e,className:M("shrink-0 bg-border",e==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",t),...s}));Pr.displayName=Rr.displayName;const oa=3e3,ca=Sn("pointer-events-auto relative flex w-full items-start justify-between gap-3 overflow-hidden rounded-md border px-4 py-3 text-sm shadow-lg transition-opacity",{variants:{variant:{default:"border-border bg-background text-foreground",destructive:"border-destructive/30 bg-destructive/10 text-destructive",success:"border-green-500/20 bg-green-500/15 text-green-600"}},defaultVariants:{variant:"default"}});let Ge=0,he=[];const st=new Set;function Cr(){for(const t of st)t()}function Lr(t){const e=he.findIndex(r=>r.id===t);e<0||(clearTimeout(he[e].timer),he=he.filter(r=>r.id!==t),Cr())}function la(t){Lr(t)}function wc(t){Ge=(Ge+1)%Number.MAX_SAFE_INTEGER;const e=Ge.toString(),r=t.duration??oa,s={id:e,title:t.title,description:t.description,variant:t.variant??"default",className:t.className,timer:setTimeout(()=>Lr(e),r)};return he=[...he.slice(-2),s],Cr(),e}function da(t){return st.add(t),()=>{st.delete(t)}}function Bt(){return he}function ua({className:t}){const e=d.useSyncExternalStore(da,Bt,Bt);return n.jsx("div",{"aria-live":"polite",role:"status",className:M("pointer-events-none fixed bottom-4 right-4 z-[var(--layer-toast)] flex w-full max-w-sm flex-col gap-2",t),children:e.map(r=>n.jsxs("div",{className:M(ca({variant:r.variant}),r.className),children:[n.jsxs("div",{className:"min-w-0 flex-1",children:[r.title?n.jsx("p",{className:"font-medium",children:r.title}):null,r.description?n.jsx("p",{className:M(r.title?"mt-0.5":void 0),children:r.description}):null]}),n.jsx("button",{type:"button","aria-label":"关闭通知",className:M("shrink-0 rounded-sm opacity-60 transition-opacity hover:opacity-100",gr),onClick:()=>la(r.id),children:n.jsx(Cn,{"aria-hidden":"true",className:"h-3.5 w-3.5"})})]},r.id))})}const ha=300;function fa({notice:t,developerMode:e,copy:r}){const[s,a]=d.useState(!1),i=n.jsxs("span",{className:"inline-flex items-start gap-1.5",children:[t.tone==="warning"?n.jsx(xt,{"aria-hidden":"true",className:"mt-0.5 h-3.5 w-3.5 shrink-0"}):null,n.jsx("span",{children:t.text})]}),o=t.tone==="warning"?"text-warning":"text-muted-foreground",c=t.tone==="warning"?"alert":"status",l=e?t.developerDetail:void 0;return n.jsx("div",{role:c,"data-pod-sign-in":"notice","data-tone":t.tone,className:M("text-[13px] leading-5",o),children:l?n.jsxs("details",{children:[n.jsx("summary",{title:r.noticeDetailsToggle,className:"cursor-pointer rounded focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring",children:i}),n.jsxs("div",{className:"mt-1 rounded-lg bg-muted p-2 text-foreground",children:[n.jsx("pre",{className:"whitespace-pre-wrap break-all font-mono text-xs",children:l}),n.jsx("button",{type:"button",className:"mt-1 h-9 rounded-lg px-2 text-[13px] font-medium text-primary hover:bg-accent focus-visible:outline focus-visible:outline-2 focus-visible:outline-ring",onClick:()=>{navigator.clipboard?.writeText(l).then(()=>a(!0),()=>{})},children:s?r.noticeCopied:r.noticeCopy})]})]}):i})}function pa({copy:t,error:e,busy:r,onSubmit:s}){const[a,i]=d.useState(""),o=c=>{c.preventDefault();const l=a.trim();l&&s&&s(l)};return n.jsxs("form",{onSubmit:o,className:"flex flex-col gap-3","data-pod-sign-in":"custom-service",children:[n.jsx(bs,{label:t.customLabel,error:e,children:c=>n.jsx(br,{...c,name:"service",type:"text",inputMode:"url",autoComplete:"url",autoCapitalize:"none",spellCheck:!1,placeholder:t.customPlaceholder,value:a,disabled:r,className:"h-11 rounded-lg bg-card text-sm",onChange:l=>i(l.target.value)})}),n.jsx(je,{type:"submit",variant:"outline",className:dr,busy:r,disabled:!a.trim(),children:t.customSubmit})]})}function ma({app:t,brand:e,state:r,notice:s,locale:a="zh-CN",copy:i,developerMode:o=!1,primaryIcon:c,capabilities:l,onPrimary:h,onUseAnother:u,onCustomService:g,onRegister:f,onToggleCustom:v}){const p=lr(a,i),m=hs(ha),[b,S]=d.useState(!1),N=e?n.jsx("div",{"data-pod-sign-in":"source",children:e}):n.jsx(fs,{icon:t.icon,name:t.name});if(r.kind==="restoring"){const _=m?r.identity:void 0;return n.jsxs(Me,{"data-pod-sign-in-state":"restoring",children:[N,n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 text-center",children:[_?n.jsxs(n.Fragment,{children:[n.jsx(St,{name:_.displayName,avatarUrl:_.avatarUrl,storage:_.storage}),n.jsx("h1",{className:"text-[17px] font-semibold text-foreground",children:_.displayName})]}):n.jsx("h1",{className:"sr-only",children:t.name}),n.jsx("div",{role:"status","aria-live":"polite",children:m?n.jsxs("p",{className:"flex items-center gap-2 text-[13px] text-muted-foreground",children:[n.jsx(ps,{}),p.restoring]}):null})]})]})}const x=r.busy===!0,I=s?.primaryLabel??(r.kind==="remembered"?ms(p.enterApp,{app:t.name}):r.kind==="expired"?p.reauthenticate:p.useXpod),k=s?n.jsx(fa,{notice:s,developerMode:o,copy:p}):null;if(r.kind==="remembered"||r.kind==="expired")return n.jsxs(Me,{"data-pod-sign-in-state":r.kind,actions:n.jsxs(n.Fragment,{children:[k,n.jsx(je,{className:kt,busy:x,"data-pod-sign-in-primary":"true",onClick:h,children:I}),u?n.jsx(je,{variant:"ghost",className:M(gs,"w-full"),disabled:x,onClick:u,children:p.useAnother}):null]}),children:[N,n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 text-center",children:[n.jsx(St,{name:r.identity.displayName,avatarUrl:r.identity.avatarUrl,storage:r.identity.storage}),n.jsx("h1",{className:"text-[17px] font-semibold text-foreground",children:r.identity.displayName}),r.kind==="expired"?n.jsx("p",{className:"text-sm text-muted-foreground",children:p.expiredLine}):null]})]});const R=l?.customService!==!1,y=l?.register!==!1&&!!f,T=R&&(r.customOpen??b),j=()=>{const _=!T;S(_),v?.(_)};return n.jsxs(Me,{"data-pod-sign-in-state":"choose-service",actions:n.jsxs(n.Fragment,{children:[k,n.jsxs(je,{className:kt,busy:x,"data-pod-sign-in-primary":"true",onClick:h,children:[!s?.primaryLabel&&c!==null?n.jsx("span",{"aria-hidden":"true",className:"mr-2 flex",children:c??n.jsx(pt,{size:20})}):null,I]}),R?n.jsxs(n.Fragment,{children:[n.jsx(je,{variant:"outline",className:dr,disabled:x,"aria-expanded":T,onClick:j,children:p.useOtherSolid}),T?n.jsx(pa,{copy:p,error:r.customError,busy:x,onSubmit:g}):null]}):null,y?n.jsxs("p",{className:"text-center text-[13px] text-muted-foreground",children:[p.noAccount,n.jsx("button",{type:"button",className:"ml-1 h-9 rounded px-1 font-medium text-primary hover:underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-ring",disabled:x,onClick:f,children:p.register})]}):null]}),children:[N,n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsx("h1",{className:"text-[17px] font-semibold text-foreground",children:p.chooseTitle}),n.jsx("p",{className:"text-sm leading-[22px] text-muted-foreground",children:p.chooseLead}),n.jsxs("div",{className:"flex flex-col",children:[n.jsx(Rt,{summary:p.whatIsWebId,children:p.whatIsWebIdBody}),n.jsx(Rt,{summary:p.whatIsPod,children:p.whatIsPodBody})]})]})]})}function ga(t){try{const e=new URL(t),r=e.pathname.split("/").filter(s=>s&&!["profile","card"].includes(s));return r[r.length-1]??e.hostname}catch{return t}}const ba=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]],xa=W("bell",ba);const va=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],_a=W("chevron-right",va);const wa=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],ya=W("circle-check",wa);const ja=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],Ia=W("copy",ja);const Na=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]],Sa=W("external-link",Na);const ka=[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]],Ra=W("inbox",ka);const Pa=[["path",{d:"m10 17 5-5-5-5",key:"1bsop3"}],["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4",key:"u53s6r"}]],Ca=W("log-in",Pa);const La=[["path",{d:"m16 17 5-5-5-5",key:"1bji2h"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}]],Ea=W("log-out",La);const Ta=[["path",{d:"M4 5h16",key:"1tepv9"}],["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 19h16",key:"1djgab"}]],Aa=W("menu",Ta);const Ua=[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]],Da=W("monitor",Ua);const Oa=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],Er=W("refresh-cw",Oa);const Fa=[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],$a=W("settings",Fa);const Ba=[["path",{d:"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z",key:"1s2grr"}],["path",{d:"M20 2v4",key:"1rf3ol"}],["path",{d:"M22 4h-4",key:"gwowj6"}],["circle",{cx:"4",cy:"20",r:"2",key:"6kqj1y"}]],za=W("sparkles",Ba);const Ma=[["path",{d:"M21 10.656V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h12.344",key:"2acyp4"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]],Xa=W("square-check-big",Ma);const qa=[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]],Ga=W("user-round",qa);const Wa=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],Tr=W("x",Wa);function Ha({title:t="操作未完成",description:e,primaryLabel:r="重试",onPrimary:s,primaryDisabled:a=!1,secondaryLabel:i="返回",onSecondary:o,tertiaryLabel:c,onTertiary:l,pending:h=!1,children:u}){return n.jsxs("div",{className:"flex min-h-44 flex-col items-center justify-center gap-4 px-5 py-8 text-center",children:[n.jsx("div",{className:"flex h-11 w-11 items-center justify-center rounded-full bg-destructive/10",children:n.jsx(xs,{"aria-hidden":"true",className:"h-5 w-5 text-destructive"})}),n.jsxs("div",{className:"space-y-2",children:[n.jsx("p",{className:"text-base font-semibold text-foreground",children:t}),e?n.jsx("p",{role:"alert",className:"text-sm leading-6 text-muted-foreground",children:e}):null]}),u?n.jsx("div",{className:"w-full space-y-2 text-left sm:max-w-xs",children:u}):null,n.jsxs("div",{className:"flex w-full flex-col gap-2 sm:max-w-xs",children:[n.jsx("button",{type:"button",disabled:h||a,onClick:s,className:"h-10 rounded-xl bg-primary px-4 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 focus:outline-none focus-visible:bg-primary/80 disabled:cursor-not-allowed disabled:opacity-50",children:r}),o?n.jsx("button",{type:"button",disabled:h,onClick:o,className:"h-9 rounded-lg border border-border bg-background px-4 text-sm font-medium text-foreground transition-colors hover:bg-muted/50 focus:outline-none focus-visible:border-ring disabled:cursor-not-allowed disabled:opacity-50",children:i}):null,l&&c?n.jsx("button",{type:"button",disabled:h,onClick:l,className:"h-9 rounded-lg px-4 text-sm text-muted-foreground transition-colors hover:bg-muted/40 hover:text-foreground focus:outline-none focus-visible:bg-muted/40 disabled:cursor-not-allowed disabled:opacity-50",children:c}):null]})]})}let Ar=!1,Ur={status:"idle"},Fe,ue;const nt=new Set,Va=()=>Ar,zt=()=>Ur;function Dr(t){return nt.add(t),()=>{nt.delete(t)}}function Ee(t){Ur=t,nt.forEach(e=>e())}function at(t,e,r={}){return ue||(Ar=!0,Fe={account:t,runtime:e,solidCleared:!1,onComplete:r.onComplete},Or())}function Or(){if(ue)return ue;if(!Fe)return Promise.resolve();const t=Fe;return ue=(async()=>{let r=t.solidCleared?"account":"solid";Ee({status:"running",step:r});try{if(t.solidCleared||(await t.runtime?.logout(),t.solidCleared=!0),r="account",Ee({status:"running",step:r}),await t.account.logout(),t.account.isAnonymous&&!t.account.isAnonymous())throw new Error("Account sign-out did not complete")}catch(s){throw Ee({status:"error",step:r}),s}Fe=void 0,Ee({status:"idle"}),t.onComplete?.()})().finally(()=>{ue=void 0}),ue}const Mt=d.createContext(!1);function Fr({children:t}){const e=d.useContext(Mt),r=d.useSyncExternalStore(Dr,zt,zt);if(e)return n.jsx(n.Fragment,{children:t});const s=r.status!=="idle";return n.jsxs(Mt.Provider,{value:!0,children:[s&&n.jsx(vs,{mode:"page",title:"退出 Xpod",children:r.status==="running"?n.jsx(sa,{label:"正在退出…"}):n.jsx(Ha,{title:"退出未完成",description:r.step==="account"?"账号会话尚未退出,请重试完成退出。":"WebID 会话尚未退出,请重试完成退出。",primaryLabel:"重试退出",onPrimary:()=>{Or().catch(()=>{})}})}),n.jsx("div",{className:s?"hidden":"contents","aria-hidden":s||void 0,inert:s||void 0,children:t})]})}function Qa(t){try{const r=new URL(t).pathname.split("/").filter(Boolean).map(i=>decodeURIComponent(i)),s=r.indexOf("profile");if(s>0)return r[s-1];const a=r.find(i=>i!=="profile"&&i!=="card");if(a)return a}catch{}return"there"}const yc=Object.freeze(Object.defineProperty({__proto__:null,ColumnBuilder:Ms,PodArrayColumn:Xs,PodBooleanColumn:qs,PodColumnBase:Gs,PodDateTimeColumn:Ws,PodIntegerColumn:Hs,PodJsonColumn:Vs,PodObjectColumn:Qs,PodStringColumn:Ks,PodTable:Js,PodUriColumn:Ys,SolidSchema:Zs,boolean:en,date:tn,generateNanoId:rn,hasStringValue:sn,hasTermValue:nn,id:an,integer:on,isSolidSchema:cn,json:ln,mergeSchemaColumns:dn,object:un,podTable:ws,real:hn,resolveTermIri:fn,solidSchema:pn,string:_s,text:mn,timestamp:gn,uri:bn,validateColumnOverride:xn},Symbol.toStringTag,{value:"Module"})),_e="http://www.w3.org/1999/02/22-rdf-syntax-ns#",we="http://www.w3.org/2001/XMLSchema#",Te="http://www.w3.org/2000/10/swap/",Z={xsd:{decimal:`${we}decimal`,boolean:`${we}boolean`,double:`${we}double`,integer:`${we}integer`,string:`${we}string`},rdf:{type:`${_e}type`,nil:`${_e}nil`,first:`${_e}first`,rest:`${_e}rest`,langString:`${_e}langString`},owl:{sameAs:"http://www.w3.org/2002/07/owl#sameAs"},r:{forSome:`${Te}reify#forSome`,forAll:`${Te}reify#forAll`},log:{implies:`${Te}log#implies`,isImpliedBy:`${Te}log#isImpliedBy`}},{xsd:Ae}=Z,Ka=/\\u([a-fA-F0-9]{4})|\\U([a-fA-F0-9]{8})|\\([^])/g,Xt={"\\":"\\","'":"'",'"':'"',n:`
3
- `,r:"\r",t:" ",f:"\f",b:"\b",_:"_","~":"~",".":".","-":"-","!":"!",$:"$","&":"&","(":"(",")":")","*":"*","+":"+",",":",",";":";","=":"=","/":"/","?":"?","#":"#","@":"@","%":"%"},Ja=/[\x00-\x20<>\\"\{\}\|\^\`]/,Ya={_iri:!0,_unescapedIri:!0,_simpleQuotedString:!0,_langcode:!0,_blank:!0,_newline:!0,_comment:!0,_whitespace:!0,_endOfFile:!0},Za=/$0^/;class ei{constructor(e){if(this._iri=/^<((?:[^ <>{}\\]|\\[uU])+)>[ \t]*/,this._unescapedIri=/^<([^\x00-\x20<>\\"\{\}\|\^\`]*)>[ \t]*/,this._simpleQuotedString=/^"([^"\\\r\n]*)"(?=[^"])/,this._simpleApostropheString=/^'([^'\\\r\n]*)'(?=[^'])/,this._langcode=/^@([a-z]+(?:-[a-z0-9]+)*)(?=[^a-z0-9\-])/i,this._prefix=/^((?:[A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:\.?[\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)?:(?=[#\s<])/,this._prefixed=/^((?:[A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:\.?[\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)?:((?:(?:[0-:A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~])(?:(?:[\.\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~])*(?:[\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~]))?)?)(?:[ \t]+|(?=\.?[,;!\^\s#()\[\]\{\}"'<>]))/,this._variable=/^\?(?:(?:[A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:[\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)(?=[.,;!\^\s#()\[\]\{\}"'<>])/,this._blank=/^_:((?:[0-9A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:\.?[\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)(?:[ \t]+|(?=\.?[,;:\s#()\[\]\{\}"'<>]))/,this._number=/^[\-+]?(?:(\d+\.\d*|\.?\d+)[eE][\-+]?|\d*(\.)?)\d+(?=\.?[,;:\s#()\[\]\{\}"'<>])/,this._boolean=/^(?:true|false)(?=[.,;\s#()\[\]\{\}"'<>])/,this._keyword=/^@[a-z]+(?=[\s#<:])/i,this._sparqlKeyword=/^(?:PREFIX|BASE|GRAPH)(?=[\s#<])/i,this._shortPredicates=/^a(?=[\s#()\[\]\{\}"'<>])/,this._newline=/^[ \t]*(?:#[^\n\r]*)?(?:\r\n|\n|\r)[ \t]*/,this._comment=/#([^\n\r]*)/,this._whitespace=/^[ \t]+/,this._endOfFile=/^(?:#[^\n\r]*)?$/,e=e||{},this._isImpliedBy=e.isImpliedBy,this._lineMode=!!e.lineMode){this._n3Mode=!1;for(const r in this)!(r in Ya)&&this[r]instanceof RegExp&&(this[r]=Za)}else this._n3Mode=e.n3!==!1;this.comments=!!e.comments,this._literalClosingPos=0}_tokenizeToEnd(e,r){let s=this._input,a=s.length;for(;;){let c,l;for(;c=this._newline.exec(s);)this.comments&&(l=this._comment.exec(c[0]))&&i("comment",l[1],"",this._line,c[0].length),s=s.substr(c[0].length,s.length),a=s.length,this._line++;if(!c&&(c=this._whitespace.exec(s))&&(s=s.substr(c[0].length,s.length)),this._endOfFile.test(s))return r&&(this.comments&&(l=this._comment.exec(s))&&i("comment",l[1],"",this._line,s.length),s=null,i("eof","","",this._line,0)),this._input=s;const h=this._line,u=s[0];let g="",f="",v="",p=null,m=0,b=!1;switch(u){case"^":if(s.length<3)break;if(s[1]==="^"){if(this._previousMarker="^^",s=s.substr(2),s[0]!=="<"){b=!0;break}}else{this._n3Mode&&(m=1,g="^");break}case"<":if(p=this._unescapedIri.exec(s))g="IRI",f=p[1];else if(p=this._iri.exec(s)){if(f=this._unescape(p[1]),f===null||Ja.test(f))return o(this);g="IRI"}else s.length>1&&s[1]==="<"?(g="<<",m=2):this._n3Mode&&s.length>1&&s[1]==="="&&(m=2,this._isImpliedBy?(g="abbreviation",f="<"):(g="inverse",f=">"));break;case">":s.length>1&&s[1]===">"&&(g=">>",m=2);break;case"_":((p=this._blank.exec(s))||r&&(p=this._blank.exec(`${s} `)))&&(g="blank",v="_",f=p[1]);break;case'"':if(p=this._simpleQuotedString.exec(s))f=p[1];else if({value:f,matchLength:m}=this._parseLiteral(s),f===null)return o(this);(p!==null||m!==0)&&(g="literal",this._literalClosingPos=0);break;case"'":if(!this._lineMode){if(p=this._simpleApostropheString.exec(s))f=p[1];else if({value:f,matchLength:m}=this._parseLiteral(s),f===null)return o(this);(p!==null||m!==0)&&(g="literal",this._literalClosingPos=0)}break;case"?":this._n3Mode&&(p=this._variable.exec(s))&&(g="var",f=p[0]);break;case"@":this._previousMarker==="literal"&&(p=this._langcode.exec(s))?(g="langcode",f=p[1]):(p=this._keyword.exec(s))&&(g=p[0]);break;case".":if(s.length===1?r:s[1]<"0"||s[1]>"9"){g=".",m=1;break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":case"+":case"-":(p=this._number.exec(s)||r&&(p=this._number.exec(`${s} `)))&&(g="literal",f=p[0],v=typeof p[1]=="string"?Ae.double:typeof p[2]=="string"?Ae.decimal:Ae.integer);break;case"B":case"b":case"p":case"P":case"G":case"g":(p=this._sparqlKeyword.exec(s))?g=p[0].toUpperCase():b=!0;break;case"f":case"t":(p=this._boolean.exec(s))?(g="literal",f=p[0],v=Ae.boolean):b=!0;break;case"a":(p=this._shortPredicates.exec(s))?(g="abbreviation",f="a"):b=!0;break;case"=":this._n3Mode&&s.length>1&&(g="abbreviation",s[1]!==">"?(m=1,f="="):(m=2,f=">"));break;case"!":if(!this._n3Mode)break;case",":case";":case"[":case"]":case"(":case")":case"}":this._lineMode||(m=1,g=u);break;case"{":!this._lineMode&&s.length>=2&&(s[1]==="|"?(g="{|",m=2):(g=u,m=1));break;case"|":s.length>=2&&s[1]==="}"&&(g="|}",m=2);break;default:b=!0}if(b&&((this._previousMarker==="@prefix"||this._previousMarker==="PREFIX")&&(p=this._prefix.exec(s))?(g="prefix",f=p[1]||""):((p=this._prefixed.exec(s))||r&&(p=this._prefixed.exec(`${s} `)))&&(g="prefixed",v=p[1]||"",f=this._unescape(p[2]))),this._previousMarker==="^^")switch(g){case"prefixed":g="type";break;case"IRI":g="typeIRI";break;default:g=""}if(!g)return r||!/^'''|^"""/.test(s)&&/\n|\r/.test(s)?o(this):this._input=s;const S=m||p[0].length,N=i(g,f,v,h,S);this.previousToken=N,this._previousMarker=g,s=s.substr(S,s.length)}function i(c,l,h,u,g){const f=s?a-s.length:a,v=f+g,p={type:c,value:l,prefix:h,line:u,start:f,end:v};return e(null,p),p}function o(c){e(c._syntaxError(/^\S*/.exec(s)[0]))}}_unescape(e){let r=!1;const s=e.replace(Ka,(a,i,o,c)=>{if(typeof i=="string")return String.fromCharCode(Number.parseInt(i,16));if(typeof o=="string"){let l=Number.parseInt(o,16);return l<=65535?String.fromCharCode(Number.parseInt(o,16)):String.fromCharCode(55296+((l-=65536)>>10),56320+(l&1023))}return c in Xt?Xt[c]:(r=!0,"")});return r?null:s}_parseLiteral(e){if(e.length>=3){const r=e.match(/^(?:"""|"|'''|'|)/)[0],s=r.length;let a=Math.max(this._literalClosingPos,s);for(;(a=e.indexOf(r,a))>0;){let i=0;for(;e[a-i-1]==="\\";)i++;if(i%2===0){const o=e.substring(s,a),c=o.split(/\r\n|\r|\n/).length-1,l=a+s;if(s===1&&c!==0||s===3&&this._lineMode)break;return this._line+=c,{value:this._unescape(o),matchLength:l}}a++}this._literalClosingPos=e.length-s+1}return{value:"",matchLength:0}}_syntaxError(e){this._input=null;const r=new Error(`Unexpected "${e}" on line ${this._line}.`);return r.context={token:void 0,line:this._line,previousToken:this.previousToken},r}_readStartingBom(e){return e.startsWith("\uFEFF")?e.substr(1):e}tokenize(e,r){if(this._line=1,typeof e=="string")if(this._input=this._readStartingBom(e),typeof r=="function")queueMicrotask(()=>this._tokenizeToEnd(r,!0));else{const s=[];let a;if(this._tokenizeToEnd((i,o)=>i?a=i:s.push(o),!0),a)throw a;return s}else this._pendingBuffer=null,typeof e.setEncoding=="function"&&e.setEncoding("utf8"),e.on("data",s=>{this._input!==null&&s.length!==0&&(this._pendingBuffer&&(s=ys.Buffer.concat([this._pendingBuffer,s]),this._pendingBuffer=null),s[s.length-1]&128?this._pendingBuffer=s:(typeof this._input>"u"?this._input=this._readStartingBom(typeof s=="string"?s:s.toString()):this._input+=s,this._tokenizeToEnd(r,!1)))}),e.on("end",()=>{typeof this._input=="string"&&this._tokenizeToEnd(r,!0)}),e.on("error",r)}}const{rdf:ti,xsd:me}=Z;let Pe,ri=0;const si={namedNode:zr,blankNode:Mr,variable:qr,literal:Xr,defaultGraph:oi,quad:it,triple:it,fromTerm:Ie,fromQuad:Gr};class ie{constructor(e){this.id=e}get value(){return this.id}equals(e){return e instanceof ie?this.id===e.id:!!e&&this.termType===e.termType&&this.value===e.value}hashCode(){return 0}toJSON(){return{termType:this.termType,value:this.value}}}class $r extends ie{get termType(){return"NamedNode"}}class ke extends ie{get termType(){return"Literal"}get value(){return this.id.substring(1,this.id.lastIndexOf('"'))}get language(){const e=this.id;let r=e.lastIndexOf('"')+1;return r<e.length&&e[r++]==="@"?e.substr(r).toLowerCase():""}get datatype(){return new $r(this.datatypeString)}get datatypeString(){const e=this.id,r=e.lastIndexOf('"')+1,s=r<e.length?e[r]:"";return s==="^"?e.substr(r+2):s!=="@"?me.string:ti.langString}equals(e){return e instanceof ke?this.id===e.id:!!e&&!!e.datatype&&this.termType===e.termType&&this.value===e.value&&this.language===e.language&&this.datatype.value===e.datatype.value}toJSON(){return{termType:this.termType,value:this.value,language:this.language,datatype:{termType:"NamedNode",value:this.datatypeString}}}}class ni extends ie{constructor(e){super(`_:${e}`)}get termType(){return"BlankNode"}get value(){return this.id.substr(2)}}class ai extends ie{constructor(e){super(`?${e}`)}get termType(){return"Variable"}get value(){return this.id.substr(1)}}class ii extends ie{constructor(){return super(""),Pe||this}get termType(){return"DefaultGraph"}equals(e){return this===e||!!e&&this.termType===e.termType}}Pe=new ii;class Br extends ie{constructor(e,r,s,a){super(""),this._subject=e,this._predicate=r,this._object=s,this._graph=a||Pe}get termType(){return"Quad"}get subject(){return this._subject}get predicate(){return this._predicate}get object(){return this._object}get graph(){return this._graph}toJSON(){return{termType:this.termType,subject:this._subject.toJSON(),predicate:this._predicate.toJSON(),object:this._object.toJSON(),graph:this._graph.toJSON()}}equals(e){return!!e&&this._subject.equals(e.subject)&&this._predicate.equals(e.predicate)&&this._object.equals(e.object)&&this._graph.equals(e.graph)}}function zr(t){return new $r(t)}function Mr(t){return new ni(t||`n3-${ri++}`)}function Xr(t,e){if(typeof e=="string")return new ke(`"${t}"@${e.toLowerCase()}`);let r=e?e.value:"";return r===""&&(typeof t=="boolean"?r=me.boolean:typeof t=="number"&&(Number.isFinite(t)?r=Number.isInteger(t)?me.integer:me.double:(r=me.double,Number.isNaN(t)||(t=t>0?"INF":"-INF")))),r===""||r===me.string?new ke(`"${t}"`):new ke(`"${t}"^^${r}`)}function qr(t){return new ai(t)}function oi(){return Pe}function it(t,e,r,s){return new Br(t,e,r,s)}function Ie(t){if(t instanceof ie)return t;switch(t.termType){case"NamedNode":return zr(t.value);case"BlankNode":return Mr(t.value);case"Variable":return qr(t.value);case"DefaultGraph":return Pe;case"Literal":return Xr(t.value,t.language||t.datatype);case"Quad":return Gr(t);default:throw new Error(`Unexpected termType: ${t.termType}`)}}function Gr(t){if(t instanceof Br)return t;if(t.termType!=="Quad")throw new Error(`Unexpected termType: ${t.termType}`);return it(Ie(t.subject),Ie(t.predicate),Ie(t.object),Ie(t.graph))}let qt=0;class Wr{constructor(e){this._contextStack=[],this._graph=null,e=e||{},this._setBase(e.baseIRI),e.factory&&Hr(this,e.factory);const r=typeof e.format=="string"?e.format.match(/\w*$/)[0].toLowerCase():"",s=/turtle/.test(r),a=/trig/.test(r),i=/triple/.test(r),o=/quad/.test(r),c=this._n3Mode=/n3/.test(r),l=i||o;(this._supportsNamedGraphs=!(s||c))||(this._readPredicateOrNamedGraph=this._readPredicate),this._supportsQuads=!(s||a||i||c),this._isImpliedBy=e.isImpliedBy,this._supportsRDFStar=r===""||/star|\*$/.test(r),l&&(this._resolveRelativeIRI=h=>null),this._blankNodePrefix=typeof e.blankNodePrefix!="string"?"":e.blankNodePrefix.replace(/^(?!_:)/,"_:"),this._lexer=e.lexer||new ei({lineMode:l,n3:c,isImpliedBy:this._isImpliedBy}),this._explicitQuantifiers=!!e.explicitQuantifiers}static _resetBlankNodePrefix(){qt=0}_setBase(e){if(!e)this._base="",this._basePath="";else{const r=e.indexOf("#");r>=0&&(e=e.substr(0,r)),this._base=e,this._basePath=e.indexOf("/")<0?e:e.replace(/[^\/?]*(?:\?.*)?$/,""),e=e.match(/^(?:([a-z][a-z0-9+.-]*:))?(?:\/\/[^\/]*)?/i),this._baseRoot=e[0],this._baseScheme=e[1]}}_saveContext(e,r,s,a,i){const o=this._n3Mode;this._contextStack.push({type:e,subject:s,predicate:a,object:i,graph:r,inverse:o?this._inversePredicate:!1,blankPrefix:o?this._prefixes._:"",quantified:o?this._quantified:null}),o&&(this._inversePredicate=!1,this._prefixes._=this._graph?`${this._graph.value}.`:".",this._quantified=Object.create(this._quantified))}_restoreContext(e,r){const s=this._contextStack.pop();if(!s||s.type!==e)return this._error(`Unexpected ${r.type}`,r);this._subject=s.subject,this._predicate=s.predicate,this._object=s.object,this._graph=s.graph,this._n3Mode&&(this._inversePredicate=s.inverse,this._prefixes._=s.blankPrefix,this._quantified=s.quantified)}_readInTopContext(e){switch(e.type){case"eof":return this._graph!==null?this._error("Unclosed graph",e):(delete this._prefixes._,this._callback(null,null,this._prefixes));case"PREFIX":this._sparqlStyle=!0;case"@prefix":return this._readPrefix;case"BASE":this._sparqlStyle=!0;case"@base":return this._readBaseIRI;case"{":if(this._supportsNamedGraphs)return this._graph="",this._subject=null,this._readSubject;case"GRAPH":if(this._supportsNamedGraphs)return this._readNamedGraphLabel;default:return this._readSubject(e)}}_readEntity(e,r){let s;switch(e.type){case"IRI":case"typeIRI":const a=this._resolveIRI(e.value);if(a===null)return this._error("Invalid IRI",e);s=this._factory.namedNode(a);break;case"type":case"prefixed":const i=this._prefixes[e.prefix];if(i===void 0)return this._error(`Undefined prefix "${e.prefix}:"`,e);s=this._factory.namedNode(i+e.value);break;case"blank":s=this._factory.blankNode(this._prefixes[e.prefix]+e.value);break;case"var":s=this._factory.variable(e.value.substr(1));break;default:return this._error(`Expected entity but got ${e.type}`,e)}return!r&&this._n3Mode&&s.id in this._quantified&&(s=this._quantified[s.id]),s}_readSubject(e){switch(this._predicate=null,e.type){case"[":return this._saveContext("blank",this._graph,this._subject=this._factory.blankNode(),null,null),this._readBlankNodeHead;case"(":return this._saveContext("list",this._graph,this.RDF_NIL,null,null),this._subject=null,this._readListItem;case"{":return this._n3Mode?(this._saveContext("formula",this._graph,this._graph=this._factory.blankNode(),null,null),this._readSubject):this._error("Unexpected graph",e);case"}":return this._readPunctuation(e);case"@forSome":return this._n3Mode?(this._subject=null,this._predicate=this.N3_FORSOME,this._quantifier="blankNode",this._readQuantifierList):this._error('Unexpected "@forSome"',e);case"@forAll":return this._n3Mode?(this._subject=null,this._predicate=this.N3_FORALL,this._quantifier="variable",this._readQuantifierList):this._error('Unexpected "@forAll"',e);case"literal":if(!this._n3Mode)return this._error("Unexpected literal",e);if(e.prefix.length===0)return this._literalValue=e.value,this._completeSubjectLiteral;this._subject=this._factory.literal(e.value,this._factory.namedNode(e.prefix));break;case"<<":return this._supportsRDFStar?(this._saveContext("<<",this._graph,null,null,null),this._graph=null,this._readSubject):this._error("Unexpected RDF-star syntax",e);default:if((this._subject=this._readEntity(e))===void 0)return;if(this._n3Mode)return this._getPathReader(this._readPredicateOrNamedGraph)}return this._readPredicateOrNamedGraph}_readPredicate(e){const r=e.type;switch(r){case"inverse":this._inversePredicate=!0;case"abbreviation":this._predicate=this.ABBREVIATIONS[e.value];break;case".":case"]":case"}":return this._predicate===null?this._error(`Unexpected ${r}`,e):(this._subject=null,r==="]"?this._readBlankNodeTail(e):this._readPunctuation(e));case";":return this._predicate!==null?this._readPredicate:this._error("Expected predicate but got ;",e);case"[":if(this._n3Mode)return this._saveContext("blank",this._graph,this._subject,this._subject=this._factory.blankNode(),null),this._readBlankNodeHead;case"blank":if(!this._n3Mode)return this._error("Disallowed blank node as predicate",e);default:if((this._predicate=this._readEntity(e))===void 0)return}return this._readObject}_readObject(e){switch(e.type){case"literal":if(e.prefix.length===0)return this._literalValue=e.value,this._readDataTypeOrLang;this._object=this._factory.literal(e.value,this._factory.namedNode(e.prefix));break;case"[":return this._saveContext("blank",this._graph,this._subject,this._predicate,this._subject=this._factory.blankNode()),this._readBlankNodeHead;case"(":return this._saveContext("list",this._graph,this._subject,this._predicate,this.RDF_NIL),this._subject=null,this._readListItem;case"{":return this._n3Mode?(this._saveContext("formula",this._graph,this._subject,this._predicate,this._graph=this._factory.blankNode()),this._readSubject):this._error("Unexpected graph",e);case"<<":return this._supportsRDFStar?(this._saveContext("<<",this._graph,this._subject,this._predicate,null),this._graph=null,this._readSubject):this._error("Unexpected RDF-star syntax",e);default:if((this._object=this._readEntity(e))===void 0)return;if(this._n3Mode)return this._getPathReader(this._getContextEndReader())}return this._getContextEndReader()}_readPredicateOrNamedGraph(e){return e.type==="{"?this._readGraph(e):this._readPredicate(e)}_readGraph(e){return e.type!=="{"?this._error(`Expected graph but got ${e.type}`,e):(this._graph=this._subject,this._subject=null,this._readSubject)}_readBlankNodeHead(e){return e.type==="]"?(this._subject=null,this._readBlankNodeTail(e)):(this._predicate=null,this._readPredicate(e))}_readBlankNodeTail(e){if(e.type!=="]")return this._readBlankNodePunctuation(e);this._subject!==null&&this._emit(this._subject,this._predicate,this._object,this._graph);const r=this._predicate===null;return this._restoreContext("blank",e),this._object!==null?this._getContextEndReader():this._predicate!==null?this._readObject:r?this._readPredicateOrNamedGraph:this._readPredicateAfterBlank}_readPredicateAfterBlank(e){switch(e.type){case".":case"}":return this._subject=null,this._readPunctuation(e);default:return this._readPredicate(e)}}_readListItem(e){let r=null,s=null,a=this._readListItem;const i=this._subject,o=this._contextStack,c=o[o.length-1];switch(e.type){case"[":this._saveContext("blank",this._graph,s=this._factory.blankNode(),this.RDF_FIRST,this._subject=r=this._factory.blankNode()),a=this._readBlankNodeHead;break;case"(":this._saveContext("list",this._graph,s=this._factory.blankNode(),this.RDF_FIRST,this.RDF_NIL),this._subject=null;break;case")":if(this._restoreContext("list",e),o.length!==0&&o[o.length-1].type==="list"&&this._emit(this._subject,this._predicate,this._object,this._graph),this._predicate===null){if(a=this._readPredicate,this._subject===this.RDF_NIL)return a}else if(a=this._getContextEndReader(),this._object===this.RDF_NIL)return a;s=this.RDF_NIL;break;case"literal":e.prefix.length===0?(this._literalValue=e.value,a=this._readListItemDataTypeOrLang):(r=this._factory.literal(e.value,this._factory.namedNode(e.prefix)),a=this._getContextEndReader());break;case"{":return this._n3Mode?(this._saveContext("formula",this._graph,this._subject,this._predicate,this._graph=this._factory.blankNode()),this._readSubject):this._error("Unexpected graph",e);default:if((r=this._readEntity(e))===void 0)return}if(s===null&&(this._subject=s=this._factory.blankNode()),i===null?c.predicate===null?c.subject=s:c.object=s:this._emit(i,this.RDF_REST,s,this._graph),r!==null){if(this._n3Mode&&(e.type==="IRI"||e.type==="prefixed"))return this._saveContext("item",this._graph,s,this.RDF_FIRST,r),this._subject=r,this._predicate=null,this._getPathReader(this._readListItem);this._emit(s,this.RDF_FIRST,r,this._graph)}return a}_readDataTypeOrLang(e){return this._completeObjectLiteral(e,!1)}_readListItemDataTypeOrLang(e){return this._completeObjectLiteral(e,!0)}_completeLiteral(e){let r=this._factory.literal(this._literalValue);switch(e.type){case"type":case"typeIRI":const s=this._readEntity(e);if(s===void 0)return;r=this._factory.literal(this._literalValue,s),e=null;break;case"langcode":r=this._factory.literal(this._literalValue,e.value),e=null;break}return{token:e,literal:r}}_completeSubjectLiteral(e){return this._subject=this._completeLiteral(e).literal,this._readPredicateOrNamedGraph}_completeObjectLiteral(e,r){const s=this._completeLiteral(e);if(s)return this._object=s.literal,r&&this._emit(this._subject,this.RDF_FIRST,this._object,this._graph),s.token===null?this._getContextEndReader():(this._readCallback=this._getContextEndReader(),this._readCallback(s.token))}_readFormulaTail(e){return e.type!=="}"?this._readPunctuation(e):(this._subject!==null&&this._emit(this._subject,this._predicate,this._object,this._graph),this._restoreContext("formula",e),this._object===null?this._readPredicate:this._getContextEndReader())}_readPunctuation(e){let r,s=this._graph;const a=this._subject,i=this._inversePredicate;switch(e.type){case"}":if(this._graph===null)return this._error("Unexpected graph closing",e);if(this._n3Mode)return this._readFormulaTail(e);this._graph=null;case".":this._subject=null,r=this._contextStack.length?this._readSubject:this._readInTopContext,i&&(this._inversePredicate=!1);break;case";":r=this._readPredicate;break;case",":r=this._readObject;break;case"{|":if(!this._supportsRDFStar)return this._error("Unexpected RDF-star syntax",e);const o=this._predicate,c=this._object;this._subject=this._factory.quad(a,o,c,this.DEFAULTGRAPH),r=this._readPredicate;break;case"|}":if(this._subject.termType!=="Quad")return this._error("Unexpected asserted triple closing",e);this._subject=null,r=this._readPunctuation;break;default:if(this._supportsQuads&&this._graph===null&&(s=this._readEntity(e))!==void 0){r=this._readQuadPunctuation;break}return this._error(`Expected punctuation to follow "${this._object.id}"`,e)}if(a!==null){const o=this._predicate,c=this._object;i?this._emit(c,o,a,s):this._emit(a,o,c,s)}return r}_readBlankNodePunctuation(e){let r;switch(e.type){case";":r=this._readPredicate;break;case",":r=this._readObject;break;default:return this._error(`Expected punctuation to follow "${this._object.id}"`,e)}return this._emit(this._subject,this._predicate,this._object,this._graph),r}_readQuadPunctuation(e){return e.type!=="."?this._error("Expected dot to follow quad",e):this._readInTopContext}_readPrefix(e){return e.type!=="prefix"?this._error("Expected prefix to follow @prefix",e):(this._prefix=e.value,this._readPrefixIRI)}_readPrefixIRI(e){if(e.type!=="IRI")return this._error(`Expected IRI to follow prefix "${this._prefix}:"`,e);const r=this._readEntity(e);return this._prefixes[this._prefix]=r.value,this._prefixCallback(this._prefix,r),this._readDeclarationPunctuation}_readBaseIRI(e){const r=e.type==="IRI"&&this._resolveIRI(e.value);return r?(this._setBase(r),this._readDeclarationPunctuation):this._error("Expected valid IRI to follow base declaration",e)}_readNamedGraphLabel(e){switch(e.type){case"IRI":case"blank":case"prefixed":return this._readSubject(e),this._readGraph;case"[":return this._readNamedGraphBlankLabel;default:return this._error("Invalid graph label",e)}}_readNamedGraphBlankLabel(e){return e.type!=="]"?this._error("Invalid graph label",e):(this._subject=this._factory.blankNode(),this._readGraph)}_readDeclarationPunctuation(e){return this._sparqlStyle?(this._sparqlStyle=!1,this._readInTopContext(e)):e.type!=="."?this._error("Expected declaration to end with a dot",e):this._readInTopContext}_readQuantifierList(e){let r;switch(e.type){case"IRI":case"prefixed":if((r=this._readEntity(e,!0))!==void 0)break;default:return this._error(`Unexpected ${e.type}`,e)}return this._explicitQuantifiers?(this._subject===null?this._emit(this._graph||this.DEFAULTGRAPH,this._predicate,this._subject=this._factory.blankNode(),this.QUANTIFIERS_GRAPH):this._emit(this._subject,this.RDF_REST,this._subject=this._factory.blankNode(),this.QUANTIFIERS_GRAPH),this._emit(this._subject,this.RDF_FIRST,r,this.QUANTIFIERS_GRAPH)):this._quantified[r.id]=this._factory[this._quantifier](this._factory.blankNode().value),this._readQuantifierPunctuation}_readQuantifierPunctuation(e){return e.type===","?this._readQuantifierList:(this._explicitQuantifiers&&(this._emit(this._subject,this.RDF_REST,this.RDF_NIL,this.QUANTIFIERS_GRAPH),this._subject=null),this._readCallback=this._getContextEndReader(),this._readCallback(e))}_getPathReader(e){return this._afterPath=e,this._readPath}_readPath(e){switch(e.type){case"!":return this._readForwardPath;case"^":return this._readBackwardPath;default:const r=this._contextStack,s=r.length&&r[r.length-1];if(s&&s.type==="item"){const a=this._subject;this._restoreContext("item",e),this._emit(this._subject,this.RDF_FIRST,a,this._graph)}return this._afterPath(e)}}_readForwardPath(e){let r,s;const a=this._factory.blankNode();if((s=this._readEntity(e))!==void 0)return this._predicate===null?(r=this._subject,this._subject=a):(r=this._object,this._object=a),this._emit(r,s,a,this._graph),this._readPath}_readBackwardPath(e){const r=this._factory.blankNode();let s,a;if((s=this._readEntity(e))!==void 0)return this._predicate===null?(a=this._subject,this._subject=r):(a=this._object,this._object=r),this._emit(r,s,a,this._graph),this._readPath}_readRDFStarTailOrGraph(e){return e.type!==">>"?this._supportsQuads&&this._graph===null&&(this._graph=this._readEntity(e))!==void 0?this._readRDFStarTail:this._error(`Expected >> to follow "${this._object.id}"`,e):this._readRDFStarTail(e)}_readRDFStarTail(e){if(e.type!==">>")return this._error(`Expected >> but got ${e.type}`,e);const r=this._factory.quad(this._subject,this._predicate,this._object,this._graph||this.DEFAULTGRAPH);return this._restoreContext("<<",e),this._subject===null?(this._subject=r,this._readPredicate):(this._object=r,this._getContextEndReader())}_getContextEndReader(){const e=this._contextStack;if(!e.length)return this._readPunctuation;switch(e[e.length-1].type){case"blank":return this._readBlankNodeTail;case"list":return this._readListItem;case"formula":return this._readFormulaTail;case"<<":return this._readRDFStarTailOrGraph}}_emit(e,r,s,a){this._callback(null,this._factory.quad(e,r,s,a||this.DEFAULTGRAPH))}_error(e,r){const s=new Error(`${e} on line ${r.line}.`);s.context={token:r,line:r.line,previousToken:this._lexer.previousToken},this._callback(s),this._callback=Ue}_resolveIRI(e){return/^[a-z][a-z0-9+.-]*:/i.test(e)?e:this._resolveRelativeIRI(e)}_resolveRelativeIRI(e){if(!e.length)return this._base;switch(e[0]){case"#":return this._base+e;case"?":return this._base.replace(/(?:\?.*)?$/,e);case"/":return(e[1]==="/"?this._baseScheme:this._baseRoot)+this._removeDotSegments(e);default:return/^[^/:]*:/.test(e)?null:this._removeDotSegments(this._basePath+e)}}_removeDotSegments(e){if(!/(^|\/)\.\.?($|[/#?])/.test(e))return e;const r=e.length;let s="",a=-1,i=-1,o=0,c="/";for(;a<r;){switch(c){case":":if(i<0&&e[++a]==="/"&&e[++a]==="/")for(;(i=a+1)<r&&e[i]!=="/";)a=i;break;case"?":case"#":a=r;break;case"/":if(e[a+1]===".")switch(c=e[++a+1],c){case"/":s+=e.substring(o,a-1),o=a+1;break;case void 0:case"?":case"#":return s+e.substring(o,a)+e.substr(a+1);case".":if(c=e[++a+1],c===void 0||c==="/"||c==="?"||c==="#"){if(s+=e.substring(o,a-2),(o=s.lastIndexOf("/"))>=i&&(s=s.substr(0,o)),c!=="/")return`${s}/${e.substr(a+1)}`;o=a+1}}}c=e[++a]}return s+e.substring(o)}parse(e,r,s){let a,i,o;if(r&&(r.onQuad||r.onPrefix||r.onComment)?(a=r.onQuad,i=r.onPrefix,o=r.onComment):(a=r,i=s),this._readCallback=this._readInTopContext,this._sparqlStyle=!1,this._prefixes=Object.create(null),this._prefixes._=this._blankNodePrefix?this._blankNodePrefix.substr(2):`b${qt++}_`,this._prefixCallback=i||Ue,this._inversePredicate=!1,this._quantified=Object.create(null),!a){const l=[];let h;if(this._callback=(u,g)=>{u?h=u:g&&l.push(g)},this._lexer.tokenize(e).every(u=>this._readCallback=this._readCallback(u)),h)throw h;return l}let c=(l,h)=>{l!==null?(this._callback(l),this._callback=Ue):this._readCallback&&(this._readCallback=this._readCallback(h))};o&&(this._lexer.comments=!0,c=(l,h)=>{l!==null?(this._callback(l),this._callback=Ue):this._readCallback&&(h.type==="comment"?o(h.value):this._readCallback=this._readCallback(h))}),this._callback=a,this._lexer.tokenize(e,c)}}function Ue(){}function Hr(t,e){t._factory=e,t.DEFAULTGRAPH=e.defaultGraph(),t.RDF_FIRST=e.namedNode(Z.rdf.first),t.RDF_REST=e.namedNode(Z.rdf.rest),t.RDF_NIL=e.namedNode(Z.rdf.nil),t.N3_FORALL=e.namedNode(Z.r.forAll),t.N3_FORSOME=e.namedNode(Z.r.forSome),t.ABBREVIATIONS={a:e.namedNode(Z.rdf.type),"=":e.namedNode(Z.owl.sameAs),">":e.namedNode(Z.log.implies),"<":e.namedNode(Z.log.isImpliedBy)},t.QUANTIFIERS_GRAPH=e.namedNode("urn:n3:quantifiers")}Hr(Wr.prototype,si);async function ci(t,e={}){const r=e.webId??t.info?.webId;if(!r?.trim()||typeof t.fetch!="function")return null;const s=fi(r),a=await t.fetch(s,{headers:{Accept:"text/turtle, application/ld+json;q=0.9, text/n3;q=0.8, */*;q=0.1"}});if(!a.ok)throw new Error(`Failed to fetch WebID profile: ${a.status} ${a.statusText}`.trim());const i=a.headers.get("content-type")??"",o=await a.text();if(!o.trim())return Gt(r,null);const c=await li(o,{contentType:i,profileDocumentUrl:s,webId:r});return Gt(r,c)}async function li(t,e){return(e.contentType?.toLowerCase()??"").includes("application/ld+json")||t.trimStart().startsWith("{")?ui(t,e.webId):await di(t,e)}async function di(t,e){const r=Wr,a=new r({baseIRI:e.profileDocumentUrl}).parse(t);return hi(a,e.webId)}function ui(t,e){try{const r=JSON.parse(t),s=Array.isArray(r)?r:Ne(r)&&Array.isArray(r["@graph"])?r["@graph"]:[r],a=s.find(o=>Ne(o)&&o["@id"]===e),i=Ne(a)?a:s.find(Ne);return i?Vr({id:e,name:le(i,Q.fn),nick:le(i,ur.nick),avatar:le(i,Q.hasPhoto),note:le(i,Q.note),email:le(i,Q.hasEmail),phone:le(i,Q.hasTelephone),region:le(i,Q.region),gender:le(i,Q.hasGender)}):null}catch{return null}}function hi(t,e){const r={id:e};for(const s of t){if(s.subject.value!==e)continue;const a=s.predicate.value,i=s.object.value;!a||!i||(a===Q.fn?r.name=i:a===ur.nick?r.nick=i:a===Q.hasPhoto?r.avatar=i:a===Q.note?r.note=i:a===Q.hasEmail?r.email=i:a===Q.hasTelephone?r.phone=i:a===Q.region?r.region=i:a===Q.hasGender&&(r.gender=i))}return Vr(r)}function Gt(t,e){return{webId:t,profile:e,displayName:js(e),username:Qa(t)}}function Vr(t){const e=Object.fromEntries(Object.entries(t).filter(([,r])=>typeof r=="string"&&r.trim()));return Object.keys(e).length>1?e:null}function le(t,e){return ot(t[e])}function ot(t){if(typeof t=="string")return t;if(Array.isArray(t))return t.map(ot).find(Boolean);if(Ne(t))return ot(t["@value"]??t["@id"])}function fi(t){const e=t.indexOf("#");return e>=0?t.slice(0,e):t}function Ne(t){return typeof t=="object"&&t!==null}function _t({accountIdentity:t,runtime:e}){const r=e?.state.status,s=r==="authenticated"&&e?e.webId??e.state.webId:t?.webId,a=r==="authenticated"&&s?void 0:t,i=a?.displayName,o=a?.username,c=a?.id,l=a?.webId,h=e?.fetch,u=d.useMemo(()=>pi({displayName:i,username:o,id:c},s),[i,c,o,l,s]),g=`${s??""}\0${u.displayName}\0${u.username??""}`,[f,v]=d.useState(),[p,m]=d.useState(!1);d.useEffect(()=>{const S=h;if(r!=="authenticated"||!S||!s)return;let N=!1,x;async function I(k,R){m(!0);try{const y=await ci({info:{webId:R},fetch:k});if(N||!y)return;const T=gi(y.profile?.avatar);let j=T;if(T&&(j=await mi(k,T),x=j?.startsWith("blob:")?j:void 0),N){x&&URL.revokeObjectURL(x);return}v({key:g,value:{displayName:y.displayName??y.username??u.displayName,username:y.username||u.username,avatarUrl:j??u.avatarUrl,avatarSourceUrl:T,note:y.profile?.note||u.note,region:y.profile?.region||u.region,webId:y.webId||u.webId,loading:!1,source:"webid-profile"}})}catch{N||v(void 0)}finally{N||m(!1)}}return I(S,s),()=>{N=!0,x&&URL.revokeObjectURL(x)}},[h,u,g,r,s]);const b=r==="authenticated"?p:!1;return r==="authenticated"&&f?.key===g?{...f.value,loading:b}:{...u,loading:b}}function pi(t,e){const r=t?.username||bi(e)||t?.id;return{displayName:t?.displayName||r||t?.id||"Xpod account",username:r,webId:e,loading:!1,source:"account"}}async function mi(t,e){try{const r=await t(e);if(!r.ok)return e;const s=await r.blob();return URL.createObjectURL(s)}catch{return e}}function gi(t){if(t)try{const e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"?e.href:void 0}catch{return}}function bi(t){if(t)try{const e=new URL(t);return e.pathname.split("/").filter(Boolean).at(0)||e.hostname}catch{return}}const xi=d.createContext(null);function vi({value:t,children:e}){return d.createElement(xi.Provider,{value:t},e)}async function _i(t){const{Parser:e,Writer:r,DataFactory:s}=await ae(async()=>{const{Parser:_,Writer:L,DataFactory:$}=await import("./index-DNdvma6J.js");return{Parser:_,Writer:L,DataFactory:$}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),{UDFS:a,RDF:i}=await ae(async()=>{const{UDFS:_,RDF:L}=await import("./xpod-remembered-login-DKFG-zi3.js").then($=>$.bN);return{UDFS:_,RDF:L}},__vite__mapDeps([1,2,3,4,5,6,7])),o=new URL(t.approval),c=new URL(t.decisionBy);if(![o,c].every(_=>["https:","http:"].includes(_.protocol)&&!_.username&&!_.password))throw new Error("Approval and decision identity must be HTTP(S) IRIs without credentials.");if(!["approved","rejected"].includes(t.decision))throw new Error("Invalid approval decision.");const l=o.href;o.hash="";const h=o.href,u=await t.authenticatedFetch(h,{headers:{accept:"text/turtle"},cache:"no-store",redirect:"error"});if(u.status===404)return{status:"not_found"};if(!u.ok)throw new Error(`Approval read failed: HTTP ${u.status}`);const g=u.headers.get("etag"),f=await u.text();if(!g||!/^"[^"\r\n]+"$/.test(g))return{status:"unavailable",reason:"A strong ETag is required for approval decisions."};if(!u.headers.get("content-type")?.toLowerCase().includes("text/turtle"))return{status:"unavailable",reason:"The approval document must be served as Turtle."};const v=new e({baseIRI:h}).parse(f),p=_=>v.filter(L=>L.subject.termType==="NamedNode"&&L.subject.value===l&&L.predicate.value===_).map(L=>L.object);if(!p(i.type).some(_=>_.termType==="NamedNode"&&_.value===a.ApprovalRequest))return{status:"not_found"};const m=p(a.status);if(m.length!==1||m[0].termType!=="Literal"||!["pending","handling"].includes(m[0].value)||p(a.resolvedAt).length)return{status:"not_actionable",reason:"Approval is already decided or has ambiguous state."};if(p(a.assignedTo).some(_=>_.termType!=="NamedNode"||_.value!==c.href))return{status:"not_actionable",reason:"Approval belongs to another decision maker."};const S=t.now??(()=>new Date),N=()=>p(a.expiresAt).some(_=>{const L=Date.parse(_.value);return!Number.isFinite(L)||L<=S().getTime()});if(N())return{status:"not_actionable",reason:"Approval has expired."};const x=p(a.leaseOwner),I=p(a.leaseExpiresAt);if((x.length||I.length)&&(x.length!==1||x[0].termType!=="Literal"||I.length!==1||I[0].termType!=="Literal"||!Number.isFinite(Date.parse(I[0].value))||Date.parse(I[0].value)>S().getTime()))return{status:"conflict",reason:"Approval is being handled by another client."};const k=new Set([a.status,a.decisionBy,a.resolvedAt]),R=v.filter(_=>_.subject.value!==l||!k.has(_.predicate.value)),y=s.namedNode(l);R.push(s.quad(y,s.namedNode(a.status),s.literal(t.decision)),s.quad(y,s.namedNode(a.decisionBy),s.namedNode(c.href)),s.quad(y,s.namedNode(a.resolvedAt),s.literal(S().toISOString(),s.namedNode("http://www.w3.org/2001/XMLSchema#dateTime"))));const T=await new Promise((_,L)=>{const $=new r({format:"Turtle"});$.addQuads(R),$.end((A,V)=>A?L(A):_(V))});if(t.isCurrent&&!t.isCurrent())return{status:"not_actionable",reason:"The current session changed."};if(N())return{status:"not_actionable",reason:"Approval has expired."};const j=await t.authenticatedFetch(h,{method:"PUT",headers:{"content-type":"text/turtle","if-match":g},body:T,redirect:"error"});if(await j.arrayBuffer(),j.status===412)return{status:"conflict",reason:"Another client changed the approval. Refresh before deciding again."};if(!j.ok)throw new Error(`Approval decision failed: HTTP ${j.status}`);return{status:"decided"}}const Ce=Is;function wi(){const t=vr(),e=Ce(),r=e.selectedStorage,s=_t({accountIdentity:t.identity,runtime:e}),a=e.state.status==="authenticated"?e.webId??e.state.webId:void 0,i=$e(),o=Ns(t.idpIndex),c=t.isInitializing?void 0:_r(t.idpIndex),l=c?new URL(c).origin:void 0,h=l?hr(void 0,t.idpIndex):void 0,u=o===!0?h??(i&&i.issuer===l?i.account.email:void 0):void 0;return d.useEffect(()=>{!l||o===!1||!a||!r||!e.currentPod||r.webId===a&&(e.currentPod.webId!==a||e.currentPod.podUrl!==r.storageUrl||i&&!Ss(i,{accountIdentity:t.identity,accountEmail:h,webId:a,selectedStorage:r})||ks({issuer:l,account:{...u?{email:u}:{},...t.identity??{},displayName:s.displayName,...s.username?{username:s.username}:{},...s.avatarSourceUrl??i?.account.avatarUrl?{avatarUrl:s.avatarSourceUrl??i?.account.avatarUrl}:{}},webId:a,storageBinding:r,routeId:Rs}))},[t.identity,l,o,u,h,s.displayName,s.avatarSourceUrl,s.username,i,e.currentPod,r,a]),null}const yi=80,ji=2048;function Ii(){const t=Ce(),e=_t({runtime:t}),r=t.state.status==="authenticated"?t.webId??t.state.webId:void 0,s=t.state.status==="authenticated"?t.currentPod?.podUrl??t.podUrl??t.state.podUrl:void 0,a=d.useMemo(()=>Ni({isLoggedIn:t.state.status==="authenticated",displayName:e.displayName,username:e.username,webId:r,podUrl:s}),[e.displayName,e.username,t.state.status,s,r]);return d.useEffect(()=>{globalThis.xpodDesktop?.setIdentity(a)},[a]),d.useEffect(()=>()=>{globalThis.xpodDesktop?.setIdentity(null)},[]),null}function Ni({isLoggedIn:t,displayName:e,username:r,webId:s,podUrl:a}){if(!t)return null;const i=Wt(e)??Wt(r)??"WebID",o=Ht(s),c=Ht(a);return{label:i,...o?{webId:o}:{},...c?{podUrl:c}:{}}}function Wt(t){if(!t)return;const r=Array.from(t,s=>{const a=s.codePointAt(0);return Si(a)?" ":s}).join("").replace(/\s+/g," ").trim();if(r)return Array.from(r).slice(0,yi).join("").trim()}function Si(t){return t<32||t>=127&&t<=159||t>=8234&&t<=8238||t>=8294&&t<=8297}function Ht(t){if(!(!t||t.length>ji))try{const e=new URL(t);return e.protocol!=="http:"&&e.protocol!=="https:"||e.username||e.password?void 0:e.toString()}catch{return}}function ki({children:t}){const[e,r]=d.useState(!1),s=d.useRef(()=>{});return d.useEffect(()=>{let a=!1,i,o,c=0;async function l(){if(a||i)return;clearTimeout(o);const u=new AbortController;i=u;const g=setTimeout(()=>u.abort(),5e3);let f=!0;try{const v=await fetch("/service/status",{cache:"no-store",signal:u.signal});if(f=v.status<500,v.ok){const p=await v.json().catch(()=>null);Array.isArray(p)&&(f=!p.some(m=>m&&["css","api"].includes(m.name)&&typeof m.status=="string"&&m.status!=="running")),u.signal.aborted&&(f=!1)}else await v.body?.cancel()}catch{f=!1}finally{clearTimeout(g),i=void 0}a||(c=f?0:c+1,r(!f),o=setTimeout(()=>{document.visibilityState!=="hidden"&&l()},f?1e4:Math.min(2e3*2**Math.min(c-1,4),3e4)))}const h=()=>{document.visibilityState!=="hidden"&&l()};return s.current=()=>{l()},window.addEventListener("online",h),window.addEventListener("focus",h),document.addEventListener("visibilitychange",h),l(),()=>{a=!0,clearTimeout(o),i?.abort(),s.current=()=>{},window.removeEventListener("online",h),window.removeEventListener("focus",h),document.removeEventListener("visibilitychange",h)}},[]),n.jsxs("div",{className:"flex h-dvh min-h-0 flex-col",style:{"--xpod-shell-height":"100%"},children:[e&&n.jsxs("section",{role:"alert","aria-label":"Xpod 连接中断",className:"flex shrink-0 flex-wrap items-center gap-x-4 gap-y-2 border-b border-border bg-background px-4 py-2 text-sm",children:[n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"font-medium",children:"Xpod 连接中断"}),n.jsx("span",{className:"ml-2 text-muted-foreground",children:"正在自动重连;你仍可打开这台设备和设置。"}),n.jsxs("details",{className:"text-xs text-muted-foreground",children:[n.jsx("summary",{children:"页面与未完成操作"}),"登录状态和当前页面已保留。未完成的操作不会自动重试,请在连接恢复后确认结果。"]})]}),n.jsx("button",{type:"button",onClick:()=>s.current(),className:"shrink-0 rounded-lg bg-primary px-3 py-2 text-primary-foreground",children:"立即重试"})]}),n.jsx("div",{className:"min-h-0 flex-1",children:t})]})}function Ri(){const t=mr();return d.useEffect(()=>globalThis.xpodDesktop?.onNavigate?.(e=>{const r=new URL(e,window.location.origin);r.origin===window.location.origin&&t(`${r.pathname}${r.search}${r.hash}`)}),[t]),null}const Re="/ai-connections",F={pod:"/pod/models",status:"/device/services",network:"/device/network",aiConnections:"/ai-connections"},Qr={"/dashboard":F.status,"/dashboard/overview":F.status,"/dashboard/status":F.status,"/dashboard/runtime":"/device/runtime","/dashboard/logs":"/device/logs","/dashboard/network":F.network,"/dashboard/usage":"/pod/data","/dashboard/models":F.aiConnections,"/dashboard/pod":F.pod,"/dashboard/services":F.status,"/dashboard/settings":"/device/runtime","/status":F.status,"/status/overview":F.status,"/status/services/gateway":F.status,"/status/services/solid-server":F.status,"/status/services/api-server":F.status,"/status/logs":"/device/logs","/network":F.network,"/network/overview":F.network,"/settings/models":F.aiConnections,"/settings/ai-connections":F.aiConnections,"/settings/ai-config":F.pod,"/settings/pod":F.pod,"/settings/identity-access":"/pod/apps","/settings/storage":"/pod/data","/settings/network":F.network,"/settings/services":F.status,"/settings/system":"/device/runtime","/settings/runtime":"/device/runtime","/ai-config":F.pod,"/ai-config/model-assignments":F.pod,"/ai-config/document-processing":F.pod,"/ai-config/search-indexing":"/pod/search","/ai-config/index-lifecycle":"/pod/search"},jc=[...["/dashboard","/status","/network"].map(t=>({app:"dashboard",basename:t})),...["/settings","/ai-connections","/ai-config","/tasks","/pod","/device","/inbox","/notifications"].map(t=>({app:"settings",basename:t}))];function Pi(t){return Qr[t.replace(/\/$/,"")]??t}const Ci="https://id.undefineds.co/app/xpod-desktop-client.json",Li={client_id:Ci},Kr=1,Ei="xpod.auth.transaction.v1",Ti=600*1e3,Jr=1,xe="xpod.auth.selected-storage.v1",Ai=1440*60*1e3;class E extends Error{code;constructor(e,r){super(r),this.name="XpodLoginTransactionError",this.code=e}}function Ic(t,e={}){const r=e.storage??yt()??wt();if(!r)throw new E("storage_unavailable","Session storage is unavailable");const s=new URL(e.origin??jt()).origin,a=e.storageRoot??s,i=es(t,a,e.storageRoot===void 0),c=(e.now??(()=>Date.now()))(),l={version:Jr,createdAt:c,expiresAt:c+(e.ttlMs??Ai),binding:i,...e.storageRoot===void 0?{}:{storageRoot:ts(e.storageRoot)}};r.setItem(xe,JSON.stringify(l))}function Ui(t={}){return t.storage?We(t.storage,t):We(yt(),t)??We(wt(),t)}function We(t,e){if(!t)return;const r=t.getItem(xe);if(!r)return;const s=()=>t.removeItem(xe);let a;try{a=JSON.parse(r)}catch{s();return}if(!$i(a)){s();return}const i=e.now??(()=>Date.now());if(a.expiresAt<=i()){s();return}let o;try{o=es(a.binding,a.storageRoot??new URL(e.origin??jt()).origin,a.storageRoot===void 0)}catch{s();return}if(e.webId!==void 0&&o.webId!==e.webId){s();return}return o}function He(t={}){t.storage?.removeItem(xe);try{yt()?.removeItem(xe),wt()?.removeItem(xe)}catch{}}function Yr(){const t=globalThis.crypto;if(typeof t?.randomUUID=="function")return t.randomUUID();if(typeof t?.getRandomValues=="function"){const e=new Uint8Array(24);return t.getRandomValues(e),`xpod-${Array.from(e,r=>r.toString(16).padStart(2,"0")).join("")}`}throw new E("storage_unavailable","Secure transaction id generation is unavailable")}function Di(t={}){const e=t.storage??Bi(),r=new URL(t.origin??jt()).origin,s=t.now??(()=>Date.now()),a=t.ttlMs??Ti,i=t.prefix??Ei,o=`${i}.active`,c=f=>`${i}.record.${f}`,l=f=>`${i}.consumed.${f}`,h=f=>{e.getItem(o)===f&&e.removeItem(o),e.removeItem(c(f))},u=(f,v=!0)=>{if(!Qt(f))throw new E("malformed","Transaction id is malformed");if(e.getItem(l(f))==="1")throw new E("consumed","Transaction has already been consumed");if(v&&e.getItem(o)!==f)throw new E("unknown","Transaction is not the active Xpod login transaction");const p=e.getItem(c(f));if(!p)throw v&&e.getItem(o)===f&&e.removeItem(o),new E("unknown","Xpod login transaction was not found");let m;try{m=JSON.parse(p)}catch{throw h(f),new E("malformed","Xpod login transaction is malformed")}if(!Fi(m)||m.transaction.id!==f)throw h(f),new E("malformed","Xpod login transaction is malformed");if(m.expiresAt<=s())throw h(f),new E("expired","Xpod login transaction has expired");try{const b=Vt({...m.transaction,authorizationSurface:"redirect",discovery:"strict"},r);return m.transaction={id:b.id,route:b.route,...b.returnTo===void 0?{}:{returnTo:b.returnTo},...b.prompt===void 0?{}:{prompt:b.prompt},...b.selectedStorage===void 0?{}:{selectedStorage:b.selectedStorage}},m}catch(b){throw h(f),b instanceof E?b:new E("malformed","Xpod login transaction is malformed")}};return{begin:f=>{const v=e.getItem(o);if(v){try{u(v)}catch(x){if(!(x instanceof E&&(x.code==="expired"||x.code==="malformed"||x.code==="unknown")))throw x}if(e.getItem(o)===v)throw new E("already_active","An Xpod login transaction is already pending in this tab")}const p=Qt(f.id)?f.id:Yr(),m=Vt({...f,id:p},r),b=s(),S=b+a,N={version:Kr,createdAt:b,expiresAt:S,transaction:{id:m.id,route:m.route,...m.returnTo===void 0?{}:{returnTo:m.returnTo},...m.prompt===void 0?{}:{prompt:m.prompt},...m.selectedStorage===void 0?{}:{selectedStorage:m.selectedStorage}}};return e.setItem(c(m.id),JSON.stringify(N)),e.setItem(o,m.id),m},readSinglePending(){const f=e.getItem(o);if(f)return Ve(u(f).transaction)},updateSelectedStorage(f,v){const p=u(f),m=Ve(p.transaction),b=Zr(v,r,m.route.storageProvider?.url),S={...p,transaction:{...p.transaction,selectedStorage:b}};e.setItem(c(f),JSON.stringify(S))},consume(f){const v=u(f),p=Ve(v.transaction);return e.removeItem(o),e.removeItem(c(f)),e.setItem(l(f),"1"),p},cancel(f){u(f),e.removeItem(o),e.removeItem(c(f)),e.setItem(l(f),"1")}}}function Vt(t,e){let r;try{r=Ps(t)}catch(i){throw new E("malformed",i instanceof Error?i.message:"Transaction is malformed")}let s;try{s=Cs(r.route,e)}catch(i){throw new E("cross_origin",i instanceof Error?i.message:"Transaction route is not local")}let a;try{a=Ze(r.returnTo)}catch(i){throw new E("mismatch",i instanceof Error?i.message:"Transaction return path is unsafe")}if(r.selectedStorage!==void 0)try{const i=Zr(r.selectedStorage,e,s.storageProvider?.url);return{id:r.id,route:s,selectedStorage:i,authorizationSurface:"redirect",discovery:"strict",...a===void 0?{}:{returnTo:a},...r.prompt===void 0?{}:{prompt:r.prompt}}}catch(i){throw i instanceof E?i:new E("mismatch","Selected storage binding is invalid")}return{id:r.id,route:s,authorizationSurface:"redirect",discovery:"strict",...a===void 0?{}:{returnTo:a},...r.prompt===void 0?{}:{prompt:r.prompt}}}function Zr(t,e,r){if(!t||typeof t.storageUrl!="string"||typeof t.webId!="string"||ht(t.webId))throw new E("malformed","Selected storage binding is malformed");let s,a;try{s=new URL(t.storageUrl),a=new URL(t.webId)}catch{throw new E("malformed","Selected storage binding is malformed")}if(!["http:","https:"].includes(s.protocol)||!["http:","https:"].includes(a.protocol))throw new E("cross_origin","Selected storage binding must use web URLs");if(s.origin!==e||a.origin!==e||r&&s.origin!==new URL(r).origin)throw new E("cross_origin","Selected storage binding is not local to this Xpod");if(s.username||s.password||s.hash||a.username||a.password)throw new E("malformed","Selected storage binding contains unsafe URL data");return{storageUrl:s.href,webId:t.webId,...t.label===void 0?{}:{label:t.label}}}function Ve(t){return{id:t.id,route:t.route,authorizationSurface:"redirect",discovery:"strict",...t.returnTo===void 0?{}:{returnTo:t.returnTo},...t.prompt===void 0?{}:{prompt:t.prompt},...t.selectedStorage===void 0?{}:{selectedStorage:t.selectedStorage}}}function es(t,e,r){if(!t||typeof t.storageUrl!="string"||typeof t.webId!="string"||ht(t.webId))throw new E("malformed","Selected storage binding is malformed");let s,a;try{s=new URL(t.storageUrl),a=new URL(t.webId)}catch{throw new E("malformed","Selected storage binding is malformed")}if(!["http:","https:"].includes(s.protocol)||!["http:","https:"].includes(a.protocol))throw new E("cross_origin","Selected storage binding must use web URLs");if(!Oi(s,e)||r&&a.origin!==new URL(e).origin||s.username||s.password||s.hash||a.username||a.password)throw new E("cross_origin","Selected storage binding is not local to this Xpod");return{storageUrl:s.href,webId:t.webId}}function ts(t){const e=new URL(t);return e.hash="",e.search="",e.pathname.endsWith("/")||(e.pathname+="/"),e.href}function Oi(t,e){const r=new URL(ts(e));if(t.origin!==r.origin)return!1;const s=r.pathname;return t.pathname===s.slice(0,-1)||t.pathname.startsWith(s)}function Qt(t){return typeof t=="string"&&/^[A-Za-z0-9_-]{16,128}$/.test(t)}function Fi(t){if(!t||typeof t!="object")return!1;const e=t;return e.version===Kr&&typeof e.createdAt=="number"&&typeof e.expiresAt=="number"&&!!(e.transaction&&typeof e.transaction=="object")}function $i(t){if(!t||typeof t!="object")return!1;const e=t;return e.version===Jr&&typeof e.createdAt=="number"&&typeof e.expiresAt=="number"&&!!(e.binding&&typeof e.binding=="object")}function Bi(){try{if(typeof window<"u"&&window.sessionStorage)return window.sessionStorage}catch{}throw new E("storage_unavailable","Session storage is unavailable")}function wt(){try{if(typeof window<"u"&&window.sessionStorage)return window.sessionStorage}catch{}}function yt(){try{if(typeof window<"u"&&window.localStorage)return window.localStorage}catch{}}function jt(){return typeof window<"u"&&window.location.origin!=="null"?window.location.origin:"http://localhost"}function zi({collection:t,assertCurrent:e,accountIndex:r,fetch:s=window.fetch.bind(window)}){const a=async(...l)=>{e();const h=await s(...l);try{e()}catch(u){throw h.body?.cancel().catch(()=>{}),u}return h},i=new Set,o=async l=>{e();const h=await mt(l,a,r);if(e(),!h||!new URL(h).pathname.startsWith("/.account/"))throw new Error("客户端凭据地址不属于可信账号服务。");return h},c=(l,h,u)=>(e(),a(l,{method:h,credentials:"include",redirect:"error",headers:gt({Accept:"application/json",...u?{"Content-Type":"application/json"}:{}},r),...u?{body:JSON.stringify(u)}:{}}));return{async create({name:l,webId:h}){if(!l.trim()||!h)throw new Error("创建客户端凭据需要名称和当前 WebID。");const u=await c(await o(t),"POST",{name:l.trim(),webId:h});if(!u.ok)throw new Error(`创建客户端凭据失败(HTTP ${u.status})。`);const g=await u.json();if(e(),typeof g.id!="string"||!g.id||g.id.includes(":")||typeof g.secret!="string"||!g.secret||typeof g.resource!="string"||!g.resource)throw new Error("账号服务未返回有效的客户端凭据。");const f=await o(g.resource),v=new TextEncoder().encode(`${g.id}:${g.secret}`),p=btoa(Array.from(v,m=>String.fromCharCode(m)).join(""));return e(),{apiKey:`sk-${p}`,clientId:g.id,resource:f}},async list(){const l=await c(await o(t),"GET");if(!l.ok)throw new Error(`读取客户端凭据失败(HTTP ${l.status})。`);const h=await l.json();e();const u=Object.entries(h.clientCredentials??{}),g=await Promise.all(u.map(async([f,v])=>{const p=await o(String(v)),m=await c(p,"GET");if(m.status===404||m.status===410)return;if(!m.ok)throw new Error(`读取客户端凭据失败(HTTP ${m.status})。`);const b=await m.json();if(e(),!(b.id!==f||typeof b.webId!="string"||!b.webId))return{clientId:f,label:f,resource:p,webId:b.webId}}));return e(),g.filter(f=>f!==void 0)},async revoke({clientId:l,resource:h,webId:u}){const g=await o(h),f=JSON.stringify([g,l,u]),v=await c(g,"GET");if(v.status===404||v.status===410){if(i.has(f))return;throw new Error("无法确认客户端凭据已撤销,请检查当前 Account 登录;Key 记录已保留。")}if(!v.ok)throw new Error(`读取客户端凭据失败(HTTP ${v.status})。`);const p=await v.json();if(e(),p.id!==l||p.webId!==u)throw new Error("客户端凭据与当前 Key 或 WebID 不匹配,未执行删除。");const m=await c(g,"DELETE");if(!m.ok)throw new Error(`撤销客户端凭据失败(HTTP ${m.status})。`);i.add(f)}}}class ee extends Error{code;constructor(e,r){super(r),this.name="AccountStorageBindingsError",this.code=e}}async function Mi(t){const e=qi(t.origin),r=t.controls?.account?.bindings;if(typeof r!="string"||r.trim()==="")throw new ee("missing-control","Account storage bindings control is unavailable");const s=t.fetchImpl??fetch,a=Gi(r,e),i=a.origin===e?a.href:await mt(a.href,s,t.trustedAccountIndex);if(!i)throw new ee("cross-origin","Account storage bindings control is not hosted by this Xpod");const o=gt({Accept:"application/json",...t.headers});let c;try{c=await s(i,{headers:o,credentials:"include"})}catch(h){throw new ee("request-failed",h instanceof Error?h.message:"Failed to load Account storage bindings")}if(c.status===401||c.status===403)throw new ee("forbidden","Account storage bindings require an authenticated Account");if(!c.ok)throw new ee("request-failed",`Account storage bindings request failed (${c.status})`);let l;try{l=await c.json()}catch{throw new ee("invalid-response","Account storage bindings response is not valid JSON")}return Xi(l,a.origin,Vi(a,t.trustedAccountIndex,e))}function Xi(t,e,r=!1){if(!Kt(t)||!Array.isArray(t.bindings))throw new ee("invalid-response","Account storage bindings response is malformed");const s=[],a=new Set;for(const i of t.bindings){if(!Kt(i)||typeof i.webId!="string"||typeof i.storageUrl!="string")throw new ee("invalid-response","Account storage binding row is malformed");const o=Wi(i.webId),c=Hi(i.storageUrl,r?void 0:e);if(!o||!c)throw new ee("cross-origin","Account storage binding is outside the trusted storage scope");const l={webId:o,storageUrl:c,...typeof i.label=="string"?{label:i.label}:{}},h=`${l.webId}
4
- ${l.storageUrl}`;a.has(h)||(a.add(h),s.push(l))}return s}function qi(t){try{return new URL(t??(typeof window>"u"?"http://localhost":window.location.origin)).origin}catch{throw new ee("cross-origin","Current Xpod origin is invalid")}}function Gi(t,e){try{const r=new URL(t,e);if(!["http:","https:"].includes(r.protocol)||r.username||r.password||r.hash)throw new Error("unsafe control URL");return r}catch{throw new ee("cross-origin","Account storage bindings control is not a valid URL")}}function Wi(t){if(!ht(t))try{const e=new URL(t);return!["http:","https:"].includes(e.protocol)||e.username||e.password?void 0:t}catch{return}}function Hi(t,e){try{const r=new URL(t.trim());return e!==void 0&&r.origin!==e||!["http:","https:"].includes(r.protocol)||r.username||r.password||r.search||r.hash?void 0:(r.pathname=r.pathname.endsWith("/")?r.pathname:`${r.pathname}/`,r.href)}catch{return}}function Vi(t,e,r){if(!e)return!1;try{const s=new URL(e,r);return s.pathname.startsWith("/.account/")&&t.origin===s.origin&&t.pathname.startsWith("/.account/")}catch{return!1}}function Kt(t){return!!(t&&typeof t=="object"&&!Array.isArray(t))}function Qi(t){let e;const r=t.webId,s=t.name?.trim()||"Xpod 会话凭据";let a,i,o=!1;const c=async()=>{if(!r||o)return;const h=t.capability??await t.resolveCapability?.();if(!h||o)return;e=h;const u=await h.create({name:s,webId:r});if(o){await h.revoke({clientId:Jt(u.apiKey),resource:u.resource,webId:r}).catch(()=>{});return}return a={apiKey:u.apiKey,clientId:Jt(u.apiKey),resource:u.resource},a},l=async()=>a||(i??=c().finally(()=>{i=void 0}),await i);return{async authorization(){if(o)return;const h=await l();return!o&&h?`Bearer ${h.apiKey}`:void 0},async apiKey(){if(o)return;const h=await l();return o?void 0:h?.apiKey},clientId(){return a?.clientId},async release(){o=!0;const h=a;a=void 0;const u=e;!h||!u||!r||await u.revoke({clientId:h.clientId,resource:h.resource,webId:r})}}}function Jt(t){const e=t.startsWith("sk-")?t.slice(3):t;try{const r=atob(e),s=r.indexOf(":");return s>0?r.slice(0,s):""}catch{return""}}function Yt(t,e,r=t,s,a){return e?async(i,o)=>{const c=(o?.method??(i instanceof Request?i.method:"GET")).toUpperCase(),l=await t(i,o);if(!["GET","HEAD"].includes(c)||!Ji(i,s,a)||l.status!==403||!await Ki(l))return l;const h=await e().catch(()=>{});if(!h)return l;const u=new Headers(o?.headers??(i instanceof Request?i.headers:void 0));return u.set("authorization",h),u.delete("dpop"),r(i,{...o,headers:u})}:t}async function Ki(t){try{const e=await t.clone().json();return e?.error==="service_access_missing"||!!(e?.error&&typeof e.error=="object"&&"code"in e.error&&e.error.code==="service_access_missing")}catch{return!1}}function Ji(t,e,r){if(!e)return!1;try{const s=new URL(t instanceof Request?t.url:String(t),e);if(s.username||s.password||s.hash||!["http:","https:"].includes(s.protocol)||!(s.pathname.startsWith("/api/")||s.pathname.startsWith("/v1/")))return!1;const a=new URL(e).origin;if(s.origin===a)return!0;if(!r)return!1;const i=new URL(r(s.href));return i.origin===a&&!i.username&&!i.password&&i.pathname===s.pathname&&i.search===s.search&&i.hash===s.hash}catch{return!1}}async function Yi(t){if(!t.accountIndex||!t.webId)return;t.assertCurrent(t.webId);const e=t.binding??await Zi(t)??await eo(t);if(t.assertCurrent(t.webId),!(!e||e.webId!==t.webId))return e.assertCurrent(),zi({collection:e.collection,assertCurrent:()=>{t.assertCurrent(t.webId),e.assertCurrent()},accountIndex:t.accountIndex,...e.fetch?{fetch:e.fetch}:{}})}async function Zi(t){const e=t.accountIndex,r=t.webId;try{const l=new URL(e);if(!["http:","https:"].includes(l.protocol)||l.username||l.password||l.pathname!=="/.account/"||l.search||l.hash)return}catch{return}let s;try{s=await t.accountFetch(e,{headers:gt({accept:"application/json"},e),credentials:"include",redirect:"error"})}catch{return}if(!s.ok)return;const a=await s.json().catch(()=>{}),i=a?.controls?.account?.clientCredentials;if(typeof i!="string"||!i)return;try{for(const l of[i,a?.controls?.account?.bindings]){if(typeof l!="string"||!l)return;const h=new URL(l,e);if(h.origin!==new URL(e).origin||!h.pathname.startsWith("/.account/")||h.username||h.password||h.hash)return}}catch{return}const o=await Mi({controls:a?.controls,fetchImpl:t.accountFetch,trustedAccountIndex:e}).catch(()=>{});if(t.assertCurrent(r),!o?.some(l=>l.webId===r))return;const c=await mt(i,t.accountFetch,e);return c?{collection:c,webId:r,assertCurrent:()=>t.assertCurrent(r),fetch:t.accountFetch}:void 0}async function eo(t){if(!t.sessionFetch)return;const e=t.webId,r=Tn({accountIndex:t.accountIndex,fetch:t.sessionFetch,assertCurrent:()=>t.assertCurrent(e)}),s=await An({accountIndex:t.accountIndex,webId:e,fetch:r}).catch(()=>{});if(s)return{collection:s.collection,webId:s.webId,assertCurrent:()=>t.assertCurrent(s.webId),fetch:r}}function to({children:t,value:e}){const r=e??Ls(),s=d.useMemo(()=>r.storage??{},[r]),a=d.useMemo(()=>so(r),[r]),[i,o]=d.useState(a.snapshot),[c,l]=d.useState(a.issuer),[h,u]=d.useState(),[g,f]=d.useState(),[v,p]=d.useState(),[m,b]=d.useState(0),[S,N]=d.useState(),x=d.useRef(i),I=d.useRef(a.rejected),k=d.useRef(void 0),R=d.useCallback(async(w,P)=>I.current?Promise.reject(Zt):P===void 0?r.session.fetch(w):r.session.fetch(w,P),[r.session]),y=d.useMemo(()=>i.status==="authenticated"?r.session.createAuthenticatedFetch(i.webId):void 0,[r.session,i]),T=d.useCallback(async(w,P)=>{if(!y||I.current)throw Zt;return P===void 0?y(w):y(w,P)},[y]),j=d.useCallback(()=>{if(k.current)return k.current;const w=(async()=>{try{await r.session.logout();const P=r.session.getSnapshot();(P.status!=="authenticated"||et(P,r.getIssuer(),r.getExpectedIssuer?.()??window.location.origin))&&(I.current=!1)}catch{}finally{const P={status:"anonymous"};r.pod.clear(),He({storage:s.selectedStorage}),Pt(s.issuer),r.setIssuer(void 0),x.current=P,o(P),l(void 0),u(void 0),f(void 0),p(void 0),N(void 0)}})().finally(()=>{k.current===w&&(k.current=void 0)});return k.current=w,w},[r,s.issuer,s.selectedStorage]),_=d.useContext(bt),L=_?.idpIndex,$=_?.registerAccountSession;d.useLayoutEffect(()=>{if(!(!$||i.status!=="authenticated"||!c||I.current))return $({issuer:c,fetch:T,assertCurrent:()=>{if(I.current||r.session.getSnapshot()!==i||r.getIssuer()!==c)throw new Error("Solid 会话已改变,请重新打开账号操作。")}})},[T,c,$,r,i]);const A=i.status==="authenticated"?i.webId:void 0,V=_?.controls?.account?.clientCredentials,K=_?.identity?.webId,te=_?.bindAccountCapability,J=d.useMemo(()=>V&&K&&K===A&&te?{collection:V,webId:K,assertCurrent:te(),fetch:ye}:void 0,[V,K,te,A]),z=d.useMemo(()=>{const w=()=>{if(r.session.getSnapshot()!==i)throw new Error("Solid 会话已改变,请重新打开客户端凭据操作。")};return Qi({webId:A,resolveCapability:()=>Yi({accountIndex:L,webId:A,binding:J,accountFetch:ye,sessionFetch:y,assertCurrent:w})})},[J,L,y,A,r.session,i]),B=d.useRef(void 0);d.useEffect(()=>(B.current?.credential===z&&(B.current.cancelled=!0),()=>{const w={credential:z,cancelled:!1};B.current=w,queueMicrotask(()=>{w.cancelled||z.release().catch(()=>{})})}),[z]);const H=d.useCallback((w,P)=>Yt(T,()=>z.authorization(),r.transportFetch??ye,window.location.origin,r.resolveLocalUrl)(w,P),[T,z,r]),re=d.useCallback((w,P)=>Yt(R,()=>z.authorization(),r.transportFetch??ye,window.location.origin,r.resolveLocalUrl)(w,P),[R,z,r]),se=d.useMemo(()=>({...r.session,fetch:re,getSnapshot:()=>x.current}),[re,r.session]);d.useEffect(()=>{const w=C=>{const X=r.getIssuer();if(!et(C,X,r.getExpectedIssuer?.()??window.location.origin)){I.current=!0,j();return}C.status==="authenticated"&&(I.current=!1);const U=x.current;x.current=C,o(C),l(X),C.status!=="authenticated"?(r.setLocalPodRoutes?.(void 0),r.setLocalPodRoutesRefresh?.(void 0),u(void 0),C.status!=="expired"&&f(void 0),p(void 0),N(void 0),r.pod.clear()):U!==C&&(u(void 0),f(void 0),p(void 0),N(void 0),r.pod.clear(U.status==="authenticated"?{webId:U.webId}:void 0))},P=r.session.subscribe(w);return w(r.session.getSnapshot()),P},[j,r,s]),d.useEffect(()=>{I.current&&j()},[j]),d.useEffect(()=>{if(i.status!=="authenticated")return;let w=!1;const P=new AbortController,C=Ui({storage:s.selectedStorage,origin:typeof window>"u"?void 0:window.location.origin,webId:i.webId}),X={webId:i.webId,...C?{podUrl:C.storageUrl}:{},fetch:H};return(async()=>{try{const U=r.getProvisionRouteStatus?.()??await Es(fetch,{signal:P.signal});if(w)return;r.setLocalPodRoutes?.(Ct(C?.storageUrl??U.storageRoot,U));const q=await r.pod.open(X),Y=Ct(q.podUrl,U);if(w)return;if(r.setLocalPodRoutes?.(Y),r.setLocalPodRoutesRefresh?.(async()=>{const O=await Ts(q.podUrl,fetch,{signal:P.signal});w||r.setLocalPodRoutes?.(O)}),!w){if(C&&(q.webId!==C.webId||!no(q.podUrl,C.storageUrl))){He({storage:s.selectedStorage}),u(void 0),f(void 0),p({webId:i.webId,error:new Error("Selected Pod binding mismatch")});return}u(q),f(C??{webId:q.webId,storageUrl:q.podUrl}),p(void 0)}}catch(U){w||p({webId:i.webId,error:U instanceof Error?U:new Error(String(U))})}})(),()=>{w=!0,P.abort(),r.setLocalPodRoutesRefresh?.(void 0)}},[H,m,r,s.selectedStorage,i]);const de=d.useCallback(()=>{p(void 0),b(w=>w+1)},[]),D=i.status==="authenticated"?i.webId:void 0;d.useEffect(()=>{if(!D)return;let w=!1;return ao(T).then(P=>{!w&&r.session.getSnapshot().status==="authenticated"&&r.session.getSnapshot().webId===D&&N(P)}),()=>{w=!0}},[T,D,r]);const ne=d.useMemo(()=>{const w=c??r.getIssuer(),P=i.status==="authenticated"&&v?.webId===i.webId?v:void 0,C=As(i,h,w);return{session:se,pod:r.pod,fetch:H,transportFetch:r.transportFetch??ye,state:C.status==="error"?{...C,error:Fs(C.error)}:C,webId:C.webId,podUrl:C.podUrl,issuer:C.issuer,currentPod:h,selectedStorage:g,...P?{podError:P}:{},retryPodOpen:de,aiClientConfiguration:S,resolveLocalUrl:X=>r.resolveLocalUrl(X),requestPodAuthorization:()=>z.authorization(),requestPodApiKey:()=>z.apiKey(),login:async X=>{const U=Us(X),q=await Ds(U.route.identityProvider.url,fetch),Y=q.oidcIssuer;if(!Y)throw new TypeError("Xpod login route has no valid issuer");const O=new URL("/auth/callback",window.location.origin),oe=globalThis.xpodDesktop?Li.client_id:void 0;try{await r.session.login({...oe?{clientId:oe}:{},oidcIssuer:Y,redirectUrl:O.toString(),handleRedirect:ce=>{r.setIssuer(Y),l(Y);const ve=new URL(ce);U.prompt?ve.searchParams.set("prompt",U.prompt):oe&&ve.searchParams.get("prompt")==="consent"&&ve.searchParams.delete("prompt"),window.location.assign(q.provisionCode?Os(ve.href,q.provisionCode):ve.href)}}),r.setIssuer(Y),l(Y)}catch(ce){throw console.error("[XpodSolidRuntimeProvider] WebID login failed",ce,ce instanceof Error?ce.cause:void 0),ce}},logout:async()=>{await z.release().catch(()=>{}),await r.session.logout(),r.pod.clear(),He({storage:s.selectedStorage}),Pt(s.issuer),u(void 0),f(void 0),N(void 0)}}},[S,H,h,se,c,v,z,de,r,s,g,i]);return n.jsx(vi,{value:{session:se,pod:r.pod,currentPod:h},children:n.jsx(fr.Provider,{value:ne,children:t})})}const ro={status:"anonymous"},Zt=new Error("Xpod session is unavailable"),ye=(t,e)=>globalThis.fetch(t,e);function so(t){const e=t.session.getSnapshot(),r=t.getIssuer();return et(e,r,t.getExpectedIssuer?.()??window.location.origin)?{snapshot:e,issuer:r,rejected:!1}:{snapshot:ro,issuer:void 0,rejected:!0}}function no(t,e){try{return new URL(t).href===new URL(e).href}catch{return t===e}}async function ao(t){try{const e=new URL("/api/ai/client-configuration/capability",window.location.href).toString(),r=await t(e,{method:"GET",credentials:"include",headers:{accept:"application/json"}});if(!r.ok||!r.headers.get("content-type")?.includes("application/json"))return await r.arrayBuffer().catch(()=>{}),Qe();const s=await r.json();if(io(s)&&s.available===!0&&s.authority==="local-filesystem")return{available:!0,authority:"local-filesystem",manualInstructions:typeof s.manualInstructions=="string"?s.manualInstructions:Qe().manualInstructions}}catch{}return Qe()}function Qe(){return{available:!1,manualInstructions:"manual client setup is available"}}function io(t){return!!(t&&typeof t=="object"&&!Array.isArray(t))}function oo({children:t}){return d.useContext(vn)?n.jsx(n.Fragment,{children:t}):n.jsx(_n,{children:t})}function co(t){const e=async(r,s="GET",a,i)=>{const o=await t.fetch(`${(t.baseUrl??"").replace(/\/$/,"")}/api/tasks${r}${i?`?id=${encodeURIComponent(i)}`:""}`,{method:s,headers:a===void 0?void 0:{"Content-Type":"application/json"},body:a===void 0?void 0:JSON.stringify(a)});if(!o.ok){const c=await o.json().catch(()=>{});throw new Error(o.status===401?"登录已失效,请重新登录":o.status===403?"暂时无法访问任务,请检查连接与授权":o.status>=500?"任务服务暂时不可用,请稍后重试":c?.error&&/[\u4e00-\u9fff]/.test(c.error)?c.error:"任务操作未完成,请检查输入后重试")}return o.json()};return{resumeRun:(r,s)=>e("/resume","POST",{approval:s},r),selection:r=>e("/selection","GET",void 0,r),list:()=>e(""),create:r=>e("","POST",r),update:(r,s)=>e("","PATCH",s,r),pause:(r,s)=>e("/pause","POST",{paused:s},r),run:r=>e("/run","POST",{},r),runs:r=>e("/runs","GET",void 0,r),steps:r=>e("/steps","GET",void 0,r),stop:r=>e("/stop","POST",{},r)}}const rs=d.createContext(null);function ss(){return d.useContext(rs)}function Le(){const t=ss();if(!t)throw new Error("ShellStateProvider is required");return t}async function lo({webId:t,podUrl:e,authenticatedFetch:r}){const s=new URL("/",e).origin,a=await r(`${s}/api/pod/settings/status`,{method:"GET",credentials:"include",headers:{accept:"application/json"}});if(!a.ok)throw await a.arrayBuffer(),new Error("Pod settings request failed. Please try again.");if(!a.headers.get("content-type")?.includes("application/json"))throw await a.arrayBuffer(),new Error("Pod settings request failed. Please try again.");const i=await a.json();if(i.identity?.webId!==t)throw new Error("Pod settings response does not match the current Solid session.");return i}const De=()=>({attention:[],activity:[],inProgress:[],inbox:[]});function uo(t,e=Date.now()){return["pending","handling"].includes(t.status)&&(!t.expiresAt||new Date(t.expiresAt).getTime()>e)}const Ke=t=>t?new Date(t).toISOString():"",ct=t=>`/tasks?run=${encodeURIComponent(t.id)}`;function ho(t){if(!t.metadata||typeof t.metadata!="object")return;const e=t.metadata.waitingTool;if(!e||typeof e!="object")return;const r=e.requestId;return typeof r=="string"?r:void 0}function ns(t,e){return!!(t.thread&&t.toolCallId&&t.thread===e.thread&&t.toolCallId===ho(e))}function lt(t,e){return e.status==="waiting_input"&&ns(t,e)}function fo(t,e,r){const s=`approval=${encodeURIComponent(t.id)}`;if(e.some(i=>i.object===t.id))return`/inbox?${s}`;const a=r.find(i=>lt(t,i));return a?`${ct(a)}&${s}`:`/inbox?${s}`}function po({approvals:t,inbox:e,runs:r,tasks:s}){const a=new Set(["completed","failed","cancelled"]),i=t.filter(o=>{if(!uo(o))return!1;const c=r.filter(l=>ns(o,l));return c.length===0||c.some(l=>!a.has(l.status))});return{attention:[...i.map(o=>({id:o.id,approvalId:o.id,thread:o.thread||void 0,run:r.find(c=>lt(o,c))?.id,title:o.toolName||"访问申请",kind:"approval",href:fo(o,e,r),risk:o.risk,toolName:o.toolName,expiresAt:Ke(o.expiresAt)||void 0})),...r.filter(o=>["failed","waiting_input"].includes(o.status)).map(o=>{const c=t.find(l=>["approved","rejected"].includes(l.status)&&lt(l,o));return{id:o.id,run:o.id,thread:o.thread||void 0,resumeApproval:c?.id,title:o.status==="failed"?"运行失败":c?"审批已保存,运行待处理":"运行在等你确认",kind:"run",href:ct(o)}})],activity:s.map(o=>({id:`task:${o.id}`,title:`新建任务:${o.title||"未命名任务"}`,href:`/tasks?task=${encodeURIComponent(o.id)}`,createdAt:Ke(o.createdAt)})).sort((o,c)=>c.createdAt.localeCompare(o.createdAt)),inProgress:r.filter(o=>o.status==="running").map(o=>({id:o.id,title:o.prompt||"任务运行中",href:ct(o)})),inbox:e.map(o=>({id:o.id,actor:o.actor||void 0,object:o.object,createdAt:Ke(o.createdAt),approvalId:i.find(c=>c.id===o.object)?.id})).sort((o,c)=>c.createdAt.localeCompare(o.createdAt))}}function mo(t){return{...t,activity:t.activity.map(e=>({...e,read:!0}))}}async function go(t){const[e,r,s,a]=await Promise.all([t.select().from(Lt),t.select().from(Et),t.select().from(Tt),t.select().from(At)]);return po({approvals:e.map(i=>({...i,id:t.resolveRowIri(Lt,{...i})})),inbox:r.map(i=>({...i,id:t.resolveRowIri(Et,{...i})})),runs:s.map(i=>({...i,id:t.resolveRowIri(Tt,{...i})})),tasks:a.map(i=>({...i,id:t.resolveRowIri(At,{...i})}))})}async function bo(t,e,r,s,a=()=>!0){const i=await _i({approval:e,decisionBy:r,decision:s,authenticatedFetch:t,isCurrent:a});if(i.status==="decided")return;const o={conflict:"申请已被其他入口处理,请刷新后查看。",not_found:"申请不存在,请刷新。",not_actionable:"申请已处理、过期或当前身份无权处理,请刷新。",unavailable:"此 Pod 尚不支持安全审批,请稍后重试。"};throw new Error(o[i.status])}function xo({children:t}){const e=Ce();return n.jsx(vo,{runtime:e,children:t},`${e.state.status}|${e.webId||""}|${e.currentPod?.podUrl||""}`)}function vo({children:t,runtime:e}){const r=d.useMemo(()=>co({fetch:e.fetch,baseUrl:window.location.origin}),[e.fetch]),[s,a]=d.useState(De),[i,o]=d.useState(!1),[c,l]=d.useState(),[h,u]=d.useState([]),g=d.useRef(new Set),[f,v]=d.useState(0),p=d.useRef(new Set),m=d.useRef(!0),b=d.useCallback(()=>v(x=>x+1),[]);d.useEffect(()=>(m.current=!0,()=>{m.current=!1}),[]),d.useEffect(()=>{let x=!0,I=!1;async function k(){if(!I){I=!0,o(!0);try{const[y,T,j]=await Promise.allSettled([e.state.status==="authenticated"&&e.currentPod?go(e.currentPod.database):Promise.resolve(De()),On(),e.state.status==="authenticated"&&e.webId&&e.currentPod?lo({webId:e.webId,podUrl:e.currentPod.podUrl,authenticatedFetch:e.fetch}):Promise.resolve(null)]),_=y.status==="fulfilled"?y.value:De();if(T.status==="fulfilled"&&T.value?.status==="fail"&&_.attention.push({id:"device:network",kind:"network",title:"设备网络需要检查",href:"/device/network"}),j.status==="fulfilled"&&j.value?.storage.status==="available"){const L=j.value.storage;L.limits.storageLimitBytes&&L.usage.storageBytes/L.limits.storageLimitBytes>=.8&&_.attention.push({id:"pod:storage",kind:"quota",title:"Pod 空间快到上限",href:"/pod/data"})}x&&(a(L=>{const $=y.status==="fulfilled"?_:{...L,attention:[...L.attention.filter(A=>A.kind!=="network"&&A.kind!=="quota"),..._.attention]};return{...$,activity:$.activity.map(A=>({...A,read:p.current.has(A.id)}))}}),l(y.status==="rejected"?"Pod 通知读取失败,请重试":void 0))}catch{x&&l("通知读取失败,请重试")}finally{I=!1,x&&o(!1)}}}k();const R=window.setInterval(()=>{k()},3e4);return window.addEventListener("focus",b),window.addEventListener("xpod:pod-changed",b),()=>{x=!1,window.clearInterval(R),window.removeEventListener("focus",b),window.removeEventListener("xpod:pod-changed",b)}},[e.currentPod,e.webId,e.fetch,e.state.status,f,b]),d.useEffect(()=>{globalThis.xpodDesktop?.publishAttention?.(s)},[s]),d.useEffect(()=>()=>{globalThis.xpodDesktop?.publishAttention?.(De())},[]);const S=d.useCallback(async(x,I)=>{if(!(!m.current||g.current.has(x))){g.current.add(x),u(k=>k.map(R=>R.approvalId===x?{...R,busy:!0}:R));try{await r.resumeRun(I,x),m.current&&(u(k=>k.filter(R=>R.approvalId!==x)),b())}catch{m.current&&u(k=>[...k.filter(R=>R.approvalId!==x),{approvalId:x,run:I,message:"决定已保存,运行处理失败,请重试。"}])}finally{g.current.delete(x)}}},[r,b]),N=d.useCallback(async(x,I)=>{if(e.state.status!=="authenticated"||!e.currentPod||!e.webId)throw new Error("请先登录并打开 Pod。");const k=s.attention.find(R=>R.approvalId===x)?.run;await bo(e.fetch,x,e.webId,I,()=>m.current),m.current&&(a(R=>({...R,attention:R.attention.filter(y=>y.approvalId!==x),inbox:R.inbox.map(y=>y.approvalId===x?{...y,approvalId:void 0}:y)})),k&&await S(x,k),b())},[e.currentPod,e.webId,e.fetch,e.state.status,s.attention,S,b]);return d.useEffect(()=>globalThis.xpodDesktop?.onApprovalDecision?.(({approvalId:x,decision:I})=>{N(x,I).catch(k=>{m.current&&l(k instanceof Error?k.message:"决定保存失败,请重试")})}),[N]),n.jsx(rs.Provider,{value:{snapshot:s,loading:i,error:c,refresh:b,decide:N,resumeFailures:h,retryResume:S,markAllRead(){s.activity.forEach(x=>p.current.add(x.id)),a(mo)}},children:t})}function er({item:t}){const{decide:e}=Le(),[r,s]=d.useState(!1),[a,i]=d.useState("");async function o(c){if(t.approvalId){s(!0);try{await e(t.approvalId,c),i("决定已保存。")}catch(l){i(l instanceof Error?l.message:"保存失败,请重试。")}finally{s(!1)}}}return n.jsxs("div",{className:"space-y-2 rounded-md border border-border p-3 text-sm leading-normal",children:[n.jsx("p",{className:"font-medium",children:t.title}),n.jsxs("p",{className:"text-xs leading-normal text-muted-foreground",children:["风险:",{low:"低",medium:"中",high:"高"}[t.risk||""]||t.risk||"未说明",t.expiresAt?` · 有效至 ${new Date(t.expiresAt).toLocaleString("zh-CN")}`:""]}),n.jsxs("div",{className:"flex flex-wrap gap-2",children:[n.jsx("button",{disabled:r,onClick:()=>{o("approved")},className:"rounded bg-primary px-2 py-1 text-primary-foreground",children:"只这一次"}),n.jsx("button",{disabled:!0,title:"长期授权待接入",className:"rounded border px-2 py-1 opacity-50",children:"以后都允许 · 待接入"}),n.jsx("button",{disabled:r,onClick:()=>{o("rejected")},className:"rounded border px-2 py-1",children:"拒绝"})]}),n.jsx("p",{className:"text-xs leading-normal text-muted-foreground",children:"这次决定只对当前申请有效。"}),a&&n.jsx("p",{role:"status",children:a})]})}function as({run:t,recoveryApproval:e}){const{snapshot:r,resumeFailures:s,retryResume:a}=Le(),i=s.filter(c=>!t||c.run===t),o=r.attention.filter(c=>c.resumeApproval&&c.run&&(!t||c.run===t));for(const c of o)i.some(l=>l.approvalId===c.resumeApproval)||i.push({approvalId:c.resumeApproval,run:c.run,message:"审批决定已保存,可以继续处理这次运行。"});return t&&e&&!i.some(c=>c.approvalId===e)&&i.push({approvalId:e,run:t,message:"审批决定已保存,可以继续处理这次运行。"}),n.jsx(n.Fragment,{children:i.map(c=>n.jsx(Nr,{tone:"neutral",role:"alert",className:"my-2",action:n.jsx("button",{disabled:c.busy,className:"underline",onClick:()=>{a(c.approvalId,c.run)},children:c.busy?"正在重试…":"重试处理运行"}),children:c.message},c.approvalId))})}function is(){const{snapshot:t}=Le(),[e]=wn(),r=t.attention.find(a=>a.approvalId===e.get("approval")),s=r&&!t.inbox.some(a=>a.approvalId===r.approvalId);return n.jsxs(n.Fragment,{children:[n.jsx(as,{}),s&&n.jsx("div",{className:"mb-4",children:n.jsx(er,{item:r})}),t.inbox.length?n.jsx("ul",{className:"space-y-3",children:t.inbox.map(a=>{const i=t.attention.find(o=>o.approvalId===a.approvalId&&a.approvalId);return n.jsxs("li",{className:"space-y-2 border-b border-border pb-3",children:[n.jsxs("p",{className:"break-all text-xs leading-normal text-muted-foreground",children:[a.actor||"未知发送者"," · ",new Date(a.createdAt).toLocaleString("zh-CN")]}),i?n.jsx(er,{item:i}):n.jsx("a",{className:"break-all text-sm leading-normal underline",href:/^https?:\/\//.test(a.object)?a.object:void 0,target:"_blank",rel:"noreferrer",children:a.object})]},a.id)})}):n.jsx("p",{className:"py-6 text-sm leading-normal text-muted-foreground",children:"收件箱是空的"})]})}function os({close:t=()=>{}}){const{snapshot:e,markAllRead:r}=Le();return n.jsxs("div",{className:"space-y-5",children:[n.jsx(as,{}),n.jsxs("section",{children:[n.jsx("h3",{className:"mb-2 text-sm leading-normal font-medium",children:"需要你处理"}),e.attention.length?n.jsx("ul",{className:"space-y-2",children:e.attention.map(s=>n.jsx("li",{children:n.jsxs(rt,{onClick:t,to:s.href,className:"block rounded-md border border-border p-3 text-sm leading-normal hover:bg-accent",children:[s.title," ›"]})},s.id))}):n.jsx("p",{className:"text-sm leading-normal text-muted-foreground",children:"没有待处理事项"})]}),n.jsxs("section",{children:[n.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[n.jsx("h3",{className:"text-sm leading-normal font-medium",children:"动态"}),n.jsx("button",{className:"text-xs leading-normal text-muted-foreground",onClick:r,children:"全部已读"})]}),e.activity.length?n.jsx("ul",{className:"space-y-2",children:e.activity.map(s=>n.jsx("li",{children:n.jsx(rt,{to:s.href,onClick:t,className:`block text-sm leading-normal ${s.read?"text-muted-foreground":"font-medium"}`,children:s.title})},s.id))}):n.jsx("p",{className:"text-sm leading-normal text-muted-foreground",children:"暂无动态"})]})]})}function _o(){const{snapshot:t,loading:e,error:r,refresh:s}=Le(),[a,i]=d.useState(null),o=d.useRef(null),c=d.useRef(null),l=d.useRef(null);return d.useEffect(()=>{if(!a)return;c.current?.focus();function h(g){g.key==="Escape"&&(i(null),l.current?.focus())}function u(g){o.current?.contains(g.target)||i(null)}return document.addEventListener("keydown",h),document.addEventListener("pointerdown",u),()=>{document.removeEventListener("keydown",h),document.removeEventListener("pointerdown",u)}},[a]),n.jsxs("div",{ref:o,className:"relative flex items-center gap-1",children:[n.jsx("button",{"aria-label":e?"正在同步":r||"刷新同步状态",title:r||(e?"正在同步":"刷新同步状态"),onClick:s,className:"rounded p-2 hover:bg-accent",children:n.jsx(Er,{size:16,className:e?"animate-spin":""})}),["notifications","inbox"].map(h=>n.jsxs("button",{"aria-label":h==="notifications"?"通知":"收件箱","aria-expanded":a===h,"aria-controls":"shell-popover",onClick:u=>{l.current=u.currentTarget,i(a===h?null:h)},className:"relative rounded p-2 hover:bg-accent",children:[h==="notifications"?n.jsx(xa,{size:16}):n.jsx(Ra,{size:16}),(h==="notifications"?t.attention.length+t.activity.filter(u=>!u.read).length:t.inbox.length)>0&&n.jsx(vt,{tone:"info",size:"sm",className:"absolute right-1 top-1"})]},h)),a&&n.jsxs("div",{id:"shell-popover",ref:c,tabIndex:-1,role:"region","aria-label":a==="notifications"?"通知中心":"收件箱",className:"absolute right-0 top-full z-50 mt-2 max-h-[70vh] w-[360px] max-w-[calc(100vw-24px)] overflow-y-auto rounded-lg border border-border bg-popover p-4 text-popover-foreground shadow-lg",children:[n.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[n.jsx("h2",{className:"font-medium",children:a==="notifications"?"通知中心":"收件箱"}),n.jsx("button",{"aria-label":"关闭",onClick:()=>{i(null),l.current?.focus()},children:n.jsx(Tr,{size:16})})]}),r&&n.jsx(Nr,{tone:"destructive",role:"alert",className:"mb-3",action:n.jsx("button",{onClick:s,className:"underline",children:"重试"}),children:r}),a==="notifications"?n.jsx(os,{close:()=>i(null)}):n.jsx(is,{})]})]})}const wo=d.lazy(()=>ae(()=>import("./PodPage-DnWCNGTO.js"),__vite__mapDeps([10,3,4,1,2,5,6,7,11,12,13,8,9]))),yo=[{path:"/device/network",label:"网络访问"},{path:"/device/services",label:"服务状态"},{path:"/device/runtime",label:"运行设置"},{path:"/device/logs",label:"查看日志"}],jo=[{path:"/pod/models",label:"模型设置"},{path:"/pod/search",label:"检索与索引"},{path:"/pod/apps",label:"授权应用"},{path:"/pod/data",label:"数据管理"}],Io=[{path:"/settings/appearance",label:"外观"}];function No({items:t,query:e,label:r}){const{openMain:s}=Fn();return n.jsx("nav",{"aria-label":r,className:"p-2",children:t.filter(a=>a.label.includes(e.trim())).map(a=>n.jsx(jn,{to:a.path,onClick:s,className:({isActive:i})=>`flex min-h-11 items-center rounded-lg px-3 text-sm leading-normal ${i?"bg-accent font-medium text-primary":"hover:bg-muted"}`,children:a.label},a.path))})}function dt({subject:t}){const e=Be(),r=t==="device"?yo:t==="pod"?jo:Io,[s,a]=d.useState(""),i=r.find(c=>c.path===e.pathname)??r[0],o=t==="device"?"这台设备":t==="pod"?"Pod":"设置";return n.jsx(wr,{mode:"auto",listHeader:n.jsx("div",{className:"flex h-full min-w-0 items-center px-3",children:n.jsx(Ir,{"aria-label":"搜索页面",value:s,onChange:c=>a(c.target.value)})}),list:n.jsx(No,{items:r,query:s,label:o}),mainHeader:n.jsx(cs,{title:i.label}),main:n.jsx(ft,{})})}function cs({title:t,children:e}){return n.jsxs("div",{className:"flex h-full min-w-0 items-center justify-between gap-2 px-4",children:[n.jsx("h1",{className:"min-w-0 truncate text-sm leading-normal font-semibold",children:t}),n.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e,n.jsx(_o,{})]})]})}function tr({title:t,children:e}){return n.jsx(wr,{className:"workspace-page",pageType:"collection",hasObjectCollection:!1,listHeader:null,list:null,mainHeader:n.jsx(cs,{title:t}),main:n.jsx("div",{className:"p-6",children:e})})}function So({section:t}){const e=mr(),r=Ce(),s=r.issuer?new URL("/.account/account/",r.issuer).toString():void 0;return n.jsx(xr,{children:n.jsx(wo,{section:t,onSection:a=>e(`/pod/${a}`),accountUrl:s})})}function ko(){const t=yn();return n.jsx("section",{className:"p-6 text-sm leading-normal",children:n.jsxs("label",{className:"flex flex-wrap items-center justify-between gap-3 border-b pb-4",children:["主题",n.jsxs(jr,{"aria-label":"主题",className:"w-auto",value:t.preference,onChange:e=>t.setPreference(e.target.value),children:[n.jsx("option",{value:"system",children:"跟随系统"}),n.jsx("option",{value:"light",children:"浅色"}),n.jsx("option",{value:"dark",children:"深色"})]})]})})}const Je=[{id:"tasks",label:"任务",labelEn:"Tasks",href:"/tasks",activePaths:["/tasks"],icon:Xa},{id:"ai",label:"AI 连接",labelEn:"AI connections",href:"/ai-connections",activePaths:["/ai-connections"],icon:za},{id:"pod",label:"Pod",labelEn:"Pod",href:"/pod/models",activePaths:["/pod"],icon:yr},{id:"device",label:"这台设备",labelEn:"This device",href:"/device/network",activePaths:["/device"],icon:Da},{id:"settings",label:"设置",labelEn:"Settings",href:"/settings/appearance",activePaths:["/settings"],icon:$a}];function ls(t,e){const r=e.replace(/\/+$/,"")||"/";return t.activePaths.some(s=>r===s||r.startsWith(`${s}/`))}function Ro(t,e,r){const i=Math.min(360,e-16),o=Math.max(8,Math.min(t.top,r-240-8));return{left:Math.max(8,Math.min(t.right+12,e-i-8)),top:o,width:i,maxHeight:Math.max(0,r-o-8)}}function Po(){const t=vr(),e=d.useContext(fr),r=t.isLoggedIn&&t.accountState.status==="authenticated",s=e?.state.status==="authenticated"&&!!(e.webId??e.state.webId),a=r||s,[i,o]=d.useState(Do(a)),[c,l]=d.useState(),[h,u]=d.useState(),[g,f]=d.useState(),v=d.useRef(null),p=d.useRef(null),m=d.useRef(void 0),b=d.useId(),S=t.identity,N=_r(t.idpIndex),x=!t.isInitializing&&N?new URL(N).origin:void 0,I=x?hr(void 0,t.idpIndex):void 0,k=$e(),R=Un(t.controls,S),y=x&&k?.issuer===x&&R&&k.account.id===R?k.account:void 0,T=r?Co(S,I,y):void 0,j=_t({accountIdentity:T,runtime:s?e:void 0}),_=j.displayName,L=Eo(j.displayName),$=e?.webId??(e?.state.status==="authenticated"?e.state.webId:void 0),A=e?.selectedStorage?.storageUrl??e?.podUrl,V=e?.selectedStorage,K=e?.currentPod,te=d.useMemo(()=>A?To(A):void 0,[A]),J=e?.state.status==="authenticated"&&!!($&&A&&V&&K)&&V?.webId===$&&rr(V?.storageUrl??"",A??"")&&K?.webId===$&&rr(K?.podUrl??"",A??""),z=a,B=i&&z,H=d.useCallback(D=>{o(D),D||(f(void 0),sr())},[]);d.useLayoutEffect(()=>{if(!B)return;const D=()=>{const ne=p.current;ne&&f(Ro(ne.getBoundingClientRect(),window.innerWidth,window.innerHeight))};return D(),window.addEventListener("resize",D),window.addEventListener("scroll",D,!0),window.visualViewport?.addEventListener("resize",D),()=>{window.removeEventListener("resize",D),window.removeEventListener("scroll",D,!0),window.visualViewport?.removeEventListener("resize",D)}},[B]),d.useEffect(()=>{if(!z){sr();return}if(!B)return;const D=w=>{const P=w.target;P instanceof Node&&(v.current?.contains(P)||p.current?.contains(P)||H(!1))},ne=w=>{w.key==="Escape"&&(H(!1),p.current?.focus())};return document.addEventListener("pointerdown",D),document.addEventListener("keydown",ne),()=>{document.removeEventListener("pointerdown",D),document.removeEventListener("keydown",ne)}},[z,B,H]),d.useEffect(()=>{!B||!g||v.current?.focus({preventScroll:!0})},[B,g]),d.useEffect(()=>()=>{m.current!==void 0&&window.clearTimeout(m.current)},[]);const re=async()=>{l("logout"),H(!1);try{await at(t,e),(t.isAnonymous?.()??!0)&&H(!1)}catch{}finally{l(void 0)}},se=async()=>{l("switch"),H(!1);try{await at(t,e,{onComplete:()=>{pr();const D=new URL(Re,window.location.origin);D.searchParams.set("xpod-login","switch"),window.location.assign(D)}}),H(!1)}catch{}finally{l(void 0)}},de=async()=>{const D=j.webId??$;if(D){try{await navigator.clipboard.writeText(D),u("已复制")}catch{u("复制失败")}m.current!==void 0&&window.clearTimeout(m.current),m.current=window.setTimeout(()=>u(void 0),1800)}};return z?n.jsxs("div",{className:"relative",children:[n.jsxs("button",{ref:p,type:"button","aria-label":a?`打开 ${_} 的个人卡片`:"个人卡片","aria-expanded":B,"aria-controls":B?b:void 0,"data-testid":"xpod-user-card-trigger","data-pod-ready":J?"true":"false",className:"flex h-9 w-9 items-center justify-center rounded-md text-foreground transition-colors hover:bg-accent focus:outline-none focus:ring-0 focus-visible:bg-accent",onClick:()=>H(!B),children:[n.jsxs(Ut,{className:"h-8 w-8 rounded-md border border-border bg-muted",children:[j.avatarUrl?n.jsx(Dt,{src:j.avatarUrl,alt:_}):null,n.jsx(Ot,{className:"rounded-md bg-muted text-xs text-muted-foreground",children:L})]}),n.jsx("span",{className:"sr-only",children:a?_:"Not signed in"})]}),B&&typeof document<"u"?Ln.createPortal(n.jsx("section",{ref:v,id:b,role:"region",tabIndex:-1,"aria-label":a?_:"Xpod account","data-avatar-card":"true","data-selected-pod-url":A,style:g,className:`fixed z-50 overflow-y-auto rounded-xl border border-border/40 bg-card text-card-foreground shadow-xl shadow-black/10 ${g?"":"invisible"}`,children:n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-start gap-5 px-6 pb-5 pt-6",children:[n.jsxs(Ut,{"data-testid":"xpod-profile-avatar",className:"h-20 w-20 shrink-0 rounded-2xl border border-border/50 bg-primary/10 shadow-sm",children:[j.avatarUrl?n.jsx(Dt,{src:j.avatarUrl,alt:_}):null,n.jsx(Ot,{className:"rounded-2xl bg-primary/10 text-2xl font-bold text-primary",children:L})]}),n.jsxs("div",{className:"min-w-0 flex-1 py-0.5",children:[n.jsx("h2",{className:"truncate text-xl font-bold text-foreground",children:_}),n.jsxs("div",{className:"mt-1 flex min-w-0 items-center gap-1 text-sm text-muted-foreground",children:[n.jsx("span",{className:"shrink-0 opacity-70",children:"WebID"}),n.jsx("span",{className:"truncate font-mono font-medium",children:j.webId??$}),n.jsx(pe,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 text-muted-foreground","aria-label":"复制 WebID",onClick:()=>{de()},children:n.jsx(Ia,{className:"h-3 w-3","aria-hidden":"true"})}),h?n.jsx("span",{role:"status",className:"shrink-0 text-xs text-primary",children:h}):null]}),n.jsx(Jn,{tone:J?"success":"neutral",dotSize:"sm",className:M("mt-2.5 gap-1.5 rounded-full px-2 py-1 text-xs font-medium",J?"bg-success/10 text-success":"bg-muted text-muted-foreground"),children:J?"Pod 已就绪":"WebID 已登录"})]})]}),j.note||j.region?n.jsxs("div",{className:"px-6 pb-5 text-sm text-muted-foreground",children:[j.note?n.jsx("p",{className:"line-clamp-2 text-foreground/85",children:j.note}):null,j.region?n.jsx("p",{className:"mt-1 text-xs",children:j.region}):null]}):null,n.jsx("div",{className:"border-t border-border/40 p-2",children:n.jsx(pe,{asChild:!0,variant:"ghost",className:"h-auto min-h-14 w-full justify-start gap-3 px-3 py-2.5 font-normal",children:n.jsxs("a",{href:"/pod/models","aria-label":"Pod",children:[n.jsx("span",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground",children:n.jsx(yr,{className:"h-4 w-4","aria-hidden":"true"})}),n.jsxs("span",{className:"min-w-0 flex-1 text-left",children:[n.jsx("span",{className:"block truncate text-sm font-medium text-foreground",children:Ao(te)}),n.jsxs("span",{className:"mt-0.5 block truncate text-xs text-muted-foreground",children:[Uo(A)," · ",J?"已就绪":"尚未就绪"]})]}),J?n.jsx(ya,{className:"h-4 w-4 shrink-0 text-success","aria-label":"Pod 已就绪"}):n.jsx(_a,{className:"h-4 w-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})})}),n.jsx(Pr,{}),n.jsxs("div",{className:"p-2",children:[N?n.jsx(pe,{asChild:!0,variant:"ghost",className:"h-10 w-full justify-start px-3 font-normal",children:n.jsxs("a",{href:N,target:"_blank",rel:"noopener noreferrer",children:[n.jsx(Ga,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),"管理账号",n.jsx(Sa,{className:"ml-1 h-3.5 w-3.5","aria-hidden":"true"})]})}):null,n.jsxs(pe,{type:"button",variant:"ghost",className:"h-10 w-full justify-start px-3 font-normal",onClick:()=>{se()},disabled:c!==void 0,children:[c==="switch"?n.jsx(tt,{className:"mr-2 h-4 w-4 animate-spin","aria-hidden":"true"}):n.jsx(Er,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),"切换 WebID"]}),n.jsxs(pe,{type:"button",variant:"ghost",className:"h-10 w-full justify-start px-3 font-normal text-destructive hover:text-destructive",onClick:()=>{re()},disabled:c!==void 0,children:[c==="logout"?n.jsx(tt,{className:"mr-2 h-4 w-4 animate-spin","aria-hidden":"true"}):n.jsx(Ea,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),"退出"]})]})]})}),document.body):null]}):n.jsx("a",{href:Re,"aria-label":"登录",title:"登录",className:"flex h-9 w-9 items-center justify-center rounded-lg text-muted-foreground hover:bg-accent",children:n.jsx(Ca,{size:20,"aria-hidden":"true"})})}function Co(t,e,r){if(t?.displayName||t?.username)return t;const s=e||(r&&"email"in r&&typeof r.email=="string"?r.email:void 0);if(!s&&!r)return t;const a=r?.username||Lo(s);return{...r??{},...t??{},...a?{username:a}:{},...r?.displayName?{displayName:r.displayName}:{displayName:a||s||"Xpod account"}}}function Lo(t){if(t)return t.split("@")[0]?.trim()||void 0}function Eo(t){const e=t.trim().split(/\s+/).filter(Boolean);return e.length>=2?`${e[0][0]}${e.at(-1)[0]}`.toUpperCase():t.slice(0,2).toUpperCase()||"XP"}function To(t){try{return new URL(t).pathname.split("/").filter(Boolean).at(-1)}catch{return}}function Ao(t){return t?`${t} Pod`:"我的 Pod"}function Uo(t){if(!t)return"未连接 Pod";try{return new URL(t).host}catch{return"Pod"}}function rr(t,e){try{return new URL(t).href===new URL(e).href}catch{return t===e}}function Do(t){return t?typeof window<"u"&&new URLSearchParams(window.location.search).get("account")==="open":!1}function sr(){if(typeof window>"u")return;const t=new URL(window.location.href);t.searchParams.get("account")==="open"&&(t.searchParams.delete("account"),window.history.replaceState(window.history.state,"",`${t.pathname}${t.search}${t.hash}`))}function nr({items:t,label:e,attentionIds:r=[]}){const a=Be().pathname;return n.jsx("nav",{"aria-label":e,className:"flex w-full flex-col items-center gap-2",children:t.map(i=>{const o=i.icon,c=i.href??i.path??"/",l=i.activePaths?ls(i,a):a===i.path||a.startsWith(`${i.path}/`);return n.jsxs(rt,{to:c,"aria-label":i.label,"aria-current":l?"page":void 0,"data-list-item":"true",title:i.label,onKeyDown:Bn,className:kn(zn(l),"text-sm"),children:[n.jsx(o,{className:"h-5 w-5 shrink-0","aria-hidden":"true"}),n.jsx("span",{className:"sr-only",children:i.label}),r.includes(i.id)?n.jsx(vt,{tone:"destructive",label:"需要处理",className:"absolute right-1 top-1"}):null]},i.id)})})}function Oo({product:t}){const e=Be(),s=ss()?.snapshot.attention.some(m=>m.kind==="network")??!1,[a,i]=d.useState({path:e.pathname,open:!1}),o=a.path===e.pathname&&a.open;a.path!==e.pathname&&i({path:e.pathname,open:!1});const c=d.useRef(null),l=d.useRef(!1),h=d.useRef(null),u=Je.find(m=>ls(m,e.pathname)),f={models:"模型设置",search:"检索与索引",indexing:"检索与索引",applications:"授权应用",data:"数据管理",network:"网络访问",services:"服务状态",runtime:"运行设置",logs:"查看日志",appearance:"外观"}[e.pathname.split("/").filter(Boolean).at(-1)??""];d.useEffect(()=>{l.current&&!o&&c.current?.focus(),l.current=o},[o]),d.useEffect(()=>{const m=()=>{window.innerWidth>=768&&i(b=>({...b,open:!1}))};return window.addEventListener("resize",m),()=>window.removeEventListener("resize",m)},[]),d.useEffect(()=>{if(!o)return;const m=b=>{if(b.key==="Escape"&&(i(I=>({...I,open:!1})),c.current?.focus()),b.key!=="Tab")return;const S=Array.from(h.current?.querySelectorAll('[data-app-layout-navigation] a, [data-app-layout-navigation] button, [data-workspace-pane="list"] a, [data-workspace-pane="list"] button, [data-workspace-pane="list"] input, [data-drawer-close]')??[]).filter(I=>I.getClientRects().length&&!I.hasAttribute("disabled")),N=S[0],x=S.at(-1);b.shiftKey&&document.activeElement===N?(b.preventDefault(),x?.focus()):!b.shiftKey&&document.activeElement===x&&(b.preventDefault(),N?.focus())};return document.addEventListener("keydown",m),h.current?.querySelector("[data-drawer-close]")?.focus(),()=>document.removeEventListener("keydown",m)},[o]);const v=n.jsx("button",{ref:c,type:"button",className:"xpod-navigation-toggle","aria-label":"打开导航","aria-expanded":o,onClick:()=>i({path:e.pathname,open:!0}),children:n.jsx(Aa,{"aria-hidden":"true",size:20})}),p=n.jsxs(n.Fragment,{children:[v,n.jsxs("span",{className:"xpod-header-parent",children:[u?.label??"Xpod"," ›"]})]});return n.jsx($n.Provider,{value:{open:o,onClose:()=>i(m=>({...m,open:!1})),headerLeading:p},children:n.jsxs("section",{ref:h,role:o?"dialog":void 0,"aria-modal":o||void 0,"aria-label":o?"Xpod 导航":void 0,className:`xpod-desktop-shell xpod-${t}-shell`,"data-app-layout":"workspace","data-drawer-open":o,children:[n.jsxs("header",{className:"xpod-narrow-header","data-app-layout-header":!0,children:[v,n.jsxs("span",{children:[u?.label??"Xpod",f?` › ${f}`:""]})]}),o?n.jsx("button",{className:"xpod-drawer-backdrop","aria-label":"关闭导航",onClick:()=>{i(m=>({...m,open:!1})),c.current?.focus()}}):null,n.jsxs("aside",{className:"xpod-rail","data-app-layout-navigation":!0,"aria-label":"Xpod 工作区导航",onClick:m=>{m.target.closest("a")&&i(b=>({...b,open:!1}))},children:[n.jsx("div",{className:"xpod-rail-profile",children:n.jsx(Po,{})}),n.jsx(nr,{items:Je.slice(0,3),label:"应用"}),n.jsx("div",{className:"xpod-rail-host",children:n.jsx(nr,{items:Je.slice(3),label:"本机",attentionIds:s?["device"]:[]})})]}),o?n.jsx("button",{"data-drawer-close":!0,className:"xpod-drawer-close","aria-label":"收起导航",onClick:()=>{i(m=>({...m,open:!1})),c.current?.focus()},children:n.jsx(Tr,{size:18})}):null,n.jsx("div",{className:"xpod-shell-content","data-app-layout-content":!0,children:n.jsx(ft,{})})]})})}function Fo({onReady:t}){const e=d.useContext(bt),r=d.useRef(!1),s=e?.isInitializing===!0;return d.useEffect(()=>{!s&&!r.current&&(r.current=!0,t())},[s,t]),null}const ar="xpod:returnTo";function $o(){try{const t=sessionStorage.getItem(ar);return t&&sessionStorage.removeItem(ar),t}catch{return null}}const ut="xpod.auth.login-cancelled";function Se(t){try{t?window.localStorage.setItem(ut,"1"):window.localStorage.removeItem(ut)}catch{}}function ds(t){const e=new URL(window.location.href);return e.searchParams.get("xpod-login")!==t?!1:(Se(!0),$o(),e.searchParams.delete("xpod-login"),window.history.replaceState(window.history.state,"",`${e.pathname}${e.search}${e.hash}`),!0)}function Bo(){return new URL(window.location.href).searchParams.get("xpod-login")==="switch"}function ir(){return ds("switch")}function zo(){if(ds("cancelled"))return!0;try{return window.localStorage.getItem(ut)==="1"}catch{return!1}}function Mo(t){const e=t.location??(typeof window>"u"?"http://localhost/":window.location),s=[$s(e)],a=Xo(e),i=t.transactionStore??Di({origin:a}),o=u=>{if(u!==void 0)return Ze(u);const g=new URL(us(e)),f=`${g.pathname}${g.search}`;try{return Ze(f)}catch{return}};let c=!1;const l=u=>{try{return i.begin(u)}catch(g){if(c||!(g instanceof E)||g.code!=="already_active")throw g;try{const f=i.readSinglePending();f&&i.cancel(f.id)}catch{}return i.begin(u)}},h=async(u,g,f)=>{const v=o(u),p={id:Yr(),route:s[0],authorizationSurface:"redirect",discovery:"strict",...f?{prompt:f}:{},...v===void 0?{}:{returnTo:v},...g===void 0?{}:{selectedStorage:g}},m=l(p);c=!0;try{await t.runtime.login(m)}catch(b){try{i.cancel(m.id)}catch{}throw b}finally{c=!1}return m};return{routes:s,startLogin:h,retryLogin:h,cancelLogin(){const u=i.readSinglePending();u&&i.cancel(u.id)},readPending:()=>i.readSinglePending(),callbackUrl(){return`${a}/auth/callback`}}}function Xo(t){return new URL(us(t)).origin}function us(t){return typeof t=="string"?t:t.href}function qo(t){if(!t)return"cloud";let e;try{e=new URL(t).hostname.toLowerCase()}catch{return"cloud"}return e==="localhost"||e.endsWith(".localhost")||e.endsWith(".local")||e==="::1"||e==="[::1]"||/^127\./u.test(e)||/^10\./u.test(e)||/^192\.168\./u.test(e)||/^172\.(1[6-9]|2\d|3[01])\./u.test(e)?"edge":"cloud"}const G=lr("zh-CN"),Go={name:"Xpod",icon:n.jsx(pt,{size:24})},Wo="无法打开选中的 Pod,请重试。",Ho="操作未完成,请重试。";function Vo(t){return n.jsx(Fr,{children:n.jsx(Qo,{...t})})}function Qo({children:t,autoStart:e=!1,developerMode:r=!1}){const s=Ce(),a=d.useContext(bt),i=d.useSyncExternalStore(Dr,Va,()=>!1),o=d.useMemo(()=>Mo({runtime:s}),[s]),[c]=d.useState(Bo),[l,h]=d.useState(()=>c||zo());d.useEffect(()=>{if(l)try{o.cancelLogin()}catch{}},[l,o]);const u=Yo(s.state),g=Jo(s,u),f="remembered"in u?u.remembered:void 0,v=f?Ko(f):void 0,[p,m]=d.useState(f&&v?{signature:v,identity:f}:void 0);v!==void 0&&v!==p?.signature&&m({signature:v,identity:f});const b=u.status==="authenticated"&&g?.status==="ready",[S,N]=d.useState(),[x,I]=d.useState(!1),[k,R]=d.useState(!1),[y,T]=d.useState(c?{prompt:"login"}:void 0),j=d.useRef(0),[_,L]=d.useState(!1),$=d.useRef(!1),A=d.useRef(!1),V=d.useCallback(O=>{console.error("[WebIdAuthBoundary] authentication action failed",O),N(Ho)},[]),K=d.useCallback(O=>{const oe=++j.current;N(void 0),I(!0),O().catch(ce=>{oe===j.current&&V(ce)}).finally(()=>{oe===j.current&&I(!1)})},[V]),te=d.useCallback(()=>{Se(!1),h(!1),N(void 0),T({})},[]),J=d.useCallback(()=>{R(!0),te()},[te]),z=d.useCallback(()=>{if(!y)return;const O=y.prompt;h(!1),T(void 0),K(async()=>{const oe=j.current;c&&await s.session.initialize({restorePreviousSession:!1}),oe===j.current&&(c&&ir(),Se(!1),await o.startLogin(void 0,void 0,O))})},[o,y,K,s.session,c]),B=()=>{if(_){re();return}u.status==="authenticated"?s.retryPodOpen?.():J()},H=()=>{if(!_){try{o.cancelLogin()}catch{}c&&ir(),Se(!0),h(!0),T(void 0),j.current+=1,I(!1),N(void 0)}},re=()=>K(async()=>{R(!0),L(!0);const O=()=>{Se(!1),h(!1),pr(),N(void 0),T({prompt:"login"}),L(!1)};a?await at(a,s,{onComplete:O}):(await s.logout(),O())});if(d.useEffect(()=>{s.state.status!=="loading"||$.current||($.current=!0,s.session.initialize({restorePreviousSession:!l}).catch(V))},[l,V,s.session,s.state.status]),d.useEffect(()=>{l||y||i||x||_||!e||A.current||u.status!=="anonymous"||(A.current=!0,te())},[l,i,e,x,y,te,u.status,_]),b&&!x&&!S)return n.jsx(n.Fragment,{children:t});const se=f,de=u.status==="restoring",D=!!globalThis.xpodDesktop&&e&&!k&&!l&&!c&&!_&&!i&&!S&&(de||u.status==="anonymous"),ne=x||!!y||e&&!l&&!i&&u.status==="anonymous"&&!S,w=se&&!l?Oe(se):void 0;let C=((O=!1)=>w?{kind:"remembered",identity:w,busy:O}:{kind:"choose-service",busy:O})(),X,U=J,q,Y=!1;if(!l&&s.state.status==="error"&&s.state.error.name==="SolidSessionPendingError")X={tone:"warning",text:G.noticePending,primaryLabel:G.refreshPage,developerDetail:s.state.error.message},U=()=>window.location.reload();else if(S)X={tone:"warning",text:G.noticeIncomplete,primaryLabel:G.retry,developerDetail:S},U=B,q=w&&!_?re:void 0;else if(de)C={kind:"restoring",...se?{identity:Oe(se)}:{}};else if(ne){const O=w??(!l&&p?Oe(p.identity):void 0);C=O?{kind:"remembered",identity:O,busy:!0}:{kind:"choose-service",busy:!0},U=()=>{},Y=!_}else if(u.status==="authenticated"){const O=Oe(It(u.webId)??{displayName:ga(u.webId),webId:u.webId});g?.status==="conflict"?(C={kind:"remembered",identity:O},X={tone:"warning",text:G.noticeIncomplete,primaryLabel:G.useAnother,developerDetail:g.message},U=re):g?.status==="error"?(C={kind:"remembered",identity:O},X={tone:"warning",text:G.noticeUnreachable,primaryLabel:G.retry,developerDetail:g.message},U=B,q=re):(C={kind:"remembered",identity:O,busy:!0},U=()=>{})}else w?(q=re,u.status==="expired"?(C={kind:"expired",identity:w},U=B):u.status==="error"&&(X={tone:"warning",text:G.noticeIncomplete,primaryLabel:G.reauthenticate,developerDetail:u.message},U=B)):!l&&(u.status==="error"||u.status==="expired")&&(X={tone:"warning",text:u.status==="expired"?G.expiredLine:G.noticeIncomplete,primaryLabel:G.reauthenticate,developerDetail:u.status==="error"?u.message:void 0},U=B);return n.jsxs(Bs,{ariaLabel:"登录 Xpod",children:[y?n.jsx(Fo,{onReady:z}):null,D?n.jsxs("div",{role:"status","aria-live":"polite",className:"flex flex-1 items-center justify-center p-5 text-sm text-muted-foreground",children:[n.jsx(tt,{"aria-hidden":"true",className:"mr-2 h-5 w-5 animate-spin"}),"正在登录…"]}):n.jsx(ma,{app:Go,brand:n.jsx(zs,{renderLogo:O=>n.jsxs("span",{className:"flex items-center gap-2",children:[n.jsx(pt,{size:24}),n.jsxs("span",{className:"flex flex-col text-left",children:[n.jsx("span",{className:"text-[13px] font-medium",children:"Xpod"}),n.jsx("span",{className:"text-[9px] leading-none text-primary",children:O})]})]})}),state:C,notice:X,locale:"zh-CN",developerMode:r,capabilities:{customService:!1,register:!1},onPrimary:U,onUseAnother:q}),Y?n.jsx(pe,{type:"button",variant:"ghost",className:"mt-2 h-9 w-full rounded-lg px-2",onClick:H,children:G.cancel}):null]})}function Oe(t){const e=$e(),r=e&&(!t.webId||e.webId===t.webId)?e.storageBinding.storageUrl:void 0,s=qo(r);return{displayName:t.displayName,...t.avatarUrl?{avatarUrl:t.avatarUrl}:{},...r?{storage:{kind:s,label:s==="cloud"?G.storageCloud:G.storageEdge}}:{}}}function Ko(t){return[t.routeId,t.webId??"",t.displayName,t.avatarUrl??""].join("\0")}function Jo(t,e){if(e.status!=="authenticated")return;if(t.podError?.webId===e.webId)return{status:"error",message:Wo};if(t.currentPod===void 0)return{status:"waiting_for_binding"};const r=t.selectedStorage??{webId:t.currentPod.webId,storageUrl:t.currentPod.podUrl},s=t.state.status==="authenticated"?t.state.podUrl:void 0;return t.currentPod.webId===e.webId&&r.webId===t.currentPod.webId&&or(r.storageUrl,t.currentPod.podUrl)&&(s===void 0||or(t.currentPod.podUrl,s))?{status:"ready",selected:r}:{status:"conflict",message:"当前 WebID 已登录,但选中的 Pod 与该身份不一致。"}}function or(t,e){try{return new URL(t).href===new URL(e).href}catch{return t===e}}function It(t){const e=$e();if(e&&!(t&&t!==e.webId))return{displayName:e.account.displayName??e.account.username??e.account.email??"Xpod",...e.account.avatarUrl?{avatarUrl:e.account.avatarUrl}:{},webId:e.webId,routeId:e.routeId}}function Ye(t,e){const r=It(e);return r?{...t,remembered:r}:t}function Yo(t){switch(t.status){case"loading":return Ye({status:"restoring"});case"anonymous":return Ye({status:"anonymous"});case"expired":return Ye({status:"expired"},t.webId);case"authenticated":return{status:"authenticated",webId:t.webId};case"error":{const e=It(t.webId);return{status:"error",message:t.error.message,retryRouteId:"xpod-current-origin",...e?{remembered:e}:{}}}}}const Zo=d.lazy(()=>ae(()=>import("./ModelsPage-BDXqetwk.js").then(t=>t.M),__vite__mapDeps([14,3,4,9,2,5,11,1,6,7,15,12,16]))),ec=d.lazy(()=>ae(()=>import("./DevicePages-DvuHyfHo.js"),__vite__mapDeps([17,3,4,9,2,5,18,6,12,15,13,1,7,8])).then(t=>({default:t.DeviceNetworkPage}))),tc=d.lazy(()=>ae(()=>import("./DevicePages-DvuHyfHo.js"),__vite__mapDeps([17,3,4,9,2,5,18,6,12,15,13,1,7,8])).then(t=>({default:t.DeviceServicesPage}))),rc=d.lazy(()=>ae(()=>import("./DevicePages-DvuHyfHo.js"),__vite__mapDeps([17,3,4,9,2,5,18,6,12,15,13,1,7,8])).then(t=>({default:t.DeviceRuntimePage}))),sc=d.lazy(()=>ae(()=>import("./DevicePages-DvuHyfHo.js"),__vite__mapDeps([17,3,4,9,2,5,18,6,12,15,13,1,7,8])).then(t=>({default:t.DeviceLogsPage}))),nc=d.lazy(()=>ae(()=>import("./TasksPage-Dk7gUH3J.js"),__vite__mapDeps([19,3,4,1,2,5,6,7,9,8,20]))),ge=t=>n.jsx(xr,{children:t}),ac=[{path:"device",element:n.jsx(dt,{subject:"device"}),children:[{index:!0,element:n.jsx(be,{to:"network",replace:!0})},{path:"network",element:ge(n.jsx(ec,{}))},{path:"services",element:ge(n.jsx(tc,{}))},{path:"runtime",element:ge(n.jsx(rc,{}))},{path:"logs",element:ge(n.jsx(sc,{}))}]},{path:"settings",element:n.jsx(dt,{subject:"settings"}),children:[{index:!0,element:n.jsx(be,{to:"appearance",replace:!0})},{path:"appearance",element:n.jsx(ko,{})}]}],ic=[{element:n.jsx(Vo,{autoStart:!0,children:n.jsx(ft,{})}),children:[{path:"ai-connections",element:ge(n.jsx(Zo,{}))},{path:"pod",element:n.jsx(dt,{subject:"pod"}),children:[{index:!0,element:n.jsx(be,{to:"models",replace:!0})},...["models","search","apps","data"].map(t=>({path:t,element:n.jsx(So,{section:t})}))]},{path:"tasks",element:ge(n.jsx(nc,{}))},{path:"inbox",element:n.jsx(tr,{title:"收件箱",children:n.jsx(is,{})})},{path:"notifications",element:n.jsx(tr,{title:"通知",children:n.jsx(os,{})})}]}],oc=[{element:n.jsx(Oo,{product:"settings"}),children:[...ac,...ic,...Object.entries(Qr).map(([t,e])=>({path:t.slice(1),element:t==="/settings/pod"?n.jsx(En,{to:e}):n.jsx(be,{to:e,replace:!0})})),{index:!0,element:n.jsx(be,{to:Re,replace:!0})},{path:"*",element:n.jsx(be,{to:Re,replace:!0})}]}];function cc(){const t=Be(),e=Nn(oc);return d.useEffect(()=>{document.title="Xpod"},[t.pathname]),e}function lc({runtime:t,initialPathname:e}={}){const[r]=d.useState(()=>dc(e));return n.jsx(oo,{children:n.jsx(Dn,{children:n.jsxs(to,{value:t,children:[n.jsx(Ii,{}),n.jsx(wi,{}),n.jsxs(In,{children:[n.jsx(Ri,{}),n.jsx(ki,{children:n.jsx(xo,{children:n.jsx(Fr,{children:n.jsx(cc,{})})})}),n.jsx(ua,{})]},r)]})})})}function dc(t){const r=`${Pi(t??globalThis.location?.pathname??Re)}${globalThis.location?.search??""}${globalThis.location?.hash??""}`;return`${globalThis.location?.pathname??""}${globalThis.location?.search??""}${globalThis.location?.hash??""}`!==r&&globalThis.history?.replaceState(null,"",r),r}const Nc=Object.freeze(Object.defineProperty({__proto__:null,XpodShellApp:lc},Symbol.toStringTag,{value:"Module"}));export{er as A,ni as B,_a as C,si as D,Sa as E,yc as F,Nc as G,Nr as I,ke as L,Wr as N,Br as Q,Er as R,Ir as S,ie as T,ai as V,Re as X,He as a,lc as b,Di as c,ii as d,ei as e,$r as f,jr as g,Le as h,co as i,as as j,_o as k,lo as l,Ia as m,Z as n,vt as o,jc as p,_c as q,Ic as r,Se as s,wc as t,Ce as u,vc as v,la as w,ua as x,Mo as y,zi as z};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-D-LgcKAb.js","assets/xpod-remembered-login-YAmn8ZiP.js","assets/createLucideIcon-BIwq0vQx.js","assets/XpodThemeProvider-DyX0rUID.js","assets/XpodThemeProvider-Cb8CjRQr.css","assets/button-CV4KJ59A.js","assets/PodDeletionAuthorizationPanel-aJCKasGz.js","assets/account-session-D6vibAra.js","assets/safe-continuation-DRRY_t4F.js","assets/nav-item-style-BKpK5_1m.js","assets/PodPage-BA0DQ3AB.js","assets/XpodAiConnectionsPodStore-BJm-rFPs.js","assets/section-header-COECjyL5.js","assets/setting-row-cGgL78vR.js","assets/ModelsPage-6567dZKQ.js","assets/list-D2aO7Nu-.js","assets/label-CFTl2bC_.js","assets/DevicePages-FFJMu_zL.js","assets/PaneListHeader-CuPah5aC.js","assets/TasksPage-B5m82wjD.js","assets/TasksPage-DPpAgn4C.css"])))=>i.map(i=>d[i]);
2
+ import{aS as Nt,aT as cr,aU as lr,aV as hs,aW as fs,aX as Me,aY as St,aZ as ps,a_ as ms,a$ as je,b0 as kt,b1 as gs,b2 as Rt,b3 as dr,b4 as bs,C as xs,a as vs,H as _s,B as ws,bp as ys,bq as js,V as Q,G as ur,l as Is,br as $e,r as Ns,i as hr,bs as Ss,bt as ks,bu as Rs,bv as ht,bw as Ps,b as Cs,n as Ze,h as Ls,bx as et,by as Pt,bz as Es,p as Ct,bA as Ts,bB as As,bC as Us,bD as Ds,bE as Os,bF as Fs,bG as fr,bH as Lt,bI as Et,q as Tt,bJ as At,aK as Ut,aL as Dt,aM as Ot,L as tt,bK as pr,bL as $s,bM as Bs,X as zs,b5 as Ms,b6 as Xs,b7 as qs,b8 as Gs,b9 as Ws,ba as Hs,bb as Vs,bc as Qs,bd as Ks,be as Js,bf as Ys,bg as Zs,O as en,bh as tn,bi as rn,bj as sn,bk as nn,J as an,S as on,bl as cn,T as ln,bm as dn,Q as un,$ as hn,bn as fn,a9 as pn,M as mn,K as gn,P as bn,bo as xn}from"./xpod-remembered-login-YAmn8ZiP.js";import{r as d,j as n,_ as ae,u as mr,n as vn,X as _n,L as rt,b as wn,d as Be,O as ft,o as yn,N as jn,f as be,B as In,p as Nn}from"./XpodThemeProvider-DyX0rUID.js";import{c as M,f as Ft,i as gr,a as Sn,B as pe,g as kn}from"./button-CV4KJ59A.js";import{r as ze,k as Rn,I as br,P as Pn,X as Cn,R as xr,w as Ln,E as En}from"./PodDeletionAuthorizationPanel-aJCKasGz.js";import{X as pt,u as vr,a as _r,r as mt,s as gt,A as bt}from"./account-session-D6vibAra.js";import{f as Tn,g as An,r as Un,A as Dn}from"./safe-continuation-DRRY_t4F.js";import{k as On,T as wr,u as Fn,D as yr,W as $n,h as Bn,l as zn}from"./nav-item-style-BKpK5_1m.js";import{c as W}from"./createLucideIcon-BIwq0vQx.js";const Mn=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],Xn=ze("circle-check",Mn);const qn=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]],Gn=ze("circle-x",qn);const Wn=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],Hn=ze("search",Wn);const Vn=[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],xt=ze("triangle-alert",Vn),jr=d.forwardRef(({className:t,multiple:e,size:r,...s},a)=>n.jsx("select",{ref:a,multiple:e,size:r,className:M(Rn,!e&&(!r||r<=1)&&"min-h-10",t),...s}));jr.displayName="NativeSelect";const Ir=d.forwardRef(({className:t,placeholder:e="搜索",...r},s)=>n.jsxs("div",{className:"relative min-w-0 w-full",children:[n.jsx(Hn,{"aria-hidden":"true",className:"pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),n.jsx(br,{...r,ref:s,type:"search",placeholder:e,className:M("h-auto min-h-8 rounded-lg border-border bg-card py-1 pl-8 pr-2.5 text-[13px] leading-normal",t)})]}));Ir.displayName="SearchInput";const Qn={success:"bg-success",warning:"bg-warning",destructive:"bg-destructive",info:"bg-primary",neutral:"border border-muted-foreground bg-transparent"},Kn={sm:"h-1.5 w-1.5",md:"h-2 w-2"};function vt({tone:t,label:e,size:r="md",className:s,"aria-label":a,...i}){const o=e??a,c=o?{role:"img","aria-label":o,title:o}:{"aria-hidden":!0};return n.jsx("span",{className:M("inline-block shrink-0 rounded-full",Kn[r],Qn[t],s),...i,...c})}function Jn({tone:t,children:e,dotSize:r="sm",className:s,...a}){return n.jsxs("span",{className:M("inline-flex items-center gap-1.5",s),...a,children:[n.jsx(vt,{tone:t,size:r}),n.jsx("span",{children:e})]})}const Yn={info:"border-primary/30 bg-primary/10 text-foreground",success:"border-success/30 bg-success/10 text-foreground",warning:"border-warning/30 bg-warning/10 text-foreground",destructive:"border-destructive/30 bg-destructive/10 text-foreground",neutral:"border-border bg-muted/30 text-foreground"},Zn={info:"text-primary",success:"text-success",warning:"text-warning",destructive:"text-destructive",neutral:"text-muted-foreground"},ea={info:Nt,success:Xn,warning:xt,destructive:Gn,neutral:Nt};function Nr({tone:t="info",title:e,icon:r,action:s,role:a="status",className:i,children:o,...c}){const l=ea[t];return n.jsxs("div",{role:a,className:M("flex items-start gap-2.5 rounded-md border px-3 py-2.5 text-sm leading-normal",Yn[t],i),...c,children:[n.jsx("span",{"aria-hidden":"true",className:M("mt-0.5 shrink-0",Zn[t]),children:r??n.jsx(l,{className:"h-4 w-4"})}),n.jsxs("div",{className:"min-w-0 flex-1",children:[e?n.jsx("p",{className:"font-medium",children:e}):null,o]}),s?n.jsx("div",{className:"shrink-0",children:s}):null]})}const ta={label:"Restoring session…"},Xe={title:"Connecting…",detail:"Waiting for the provider",cancelLabel:"Cancel"},qe={title:"Sign-in failed",primaryLabel:"Retry",secondaryLabel:"Back"};function fe(t,e){return t?.trim()?t:e}function ra({name:t,avatarUrl:e,size:r="lg",marker:s}){const a=r==="lg"?"h-16 w-16 text-xl":"h-10 w-10 text-sm";return n.jsxs("div",{className:"relative shrink-0",children:[e?n.jsx("img",{src:e,alt:t,className:M(a,"rounded-[18%] border border-border/50 object-cover shadow-sm")}):n.jsx("div",{"aria-hidden":"true",className:M(a,"flex items-center justify-center rounded-[18%] bg-primary/10 font-semibold text-primary shadow-sm"),children:t.slice(0,1).toUpperCase()}),s?n.jsx("div",{className:"absolute -bottom-1 -right-1",children:s}):null]})}function sa({accountName:t,avatarUrl:e,label:r}){const s=fe(r,ta.label);return n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-4 p-6",role:"status",children:[t?n.jsxs(n.Fragment,{children:[n.jsx(ra,{name:t,avatarUrl:e,size:"lg"}),n.jsx("p",{className:"text-sm font-medium text-foreground",children:t})]}):null,n.jsx(cr,{className:"h-6 w-6 animate-spin text-muted-foreground","aria-hidden":"true"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:s})]})}function vc({title:t,detail:e,providerLabel:r,providerHost:s,onCancel:a,cancelLabel:i}){const o=fe(t,Xe.title),c=fe(e,Xe.detail),l=fe(i,Xe.cancelLabel);return n.jsxs("div",{className:"flex h-full flex-1 flex-col",children:[n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center px-6 py-8 text-center",role:"status",children:[n.jsx(cr,{className:"mb-4 h-8 w-8 animate-spin text-primary","aria-hidden":"true"}),n.jsx("p",{className:"text-sm font-medium text-foreground",children:o}),n.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:c}),r||s?n.jsxs("div",{className:"mt-4 w-full max-w-[18rem] rounded-lg border border-border/60 bg-muted/30 px-3 py-2",children:[r?n.jsx("p",{className:"truncate text-xs font-medium text-foreground",children:r}):null,s?n.jsx("p",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:s}):null]}):null]}),a?n.jsx("div",{className:"shrink-0 px-5 pb-5",children:n.jsx("button",{type:"button",onClick:a,className:M("h-9 w-full cursor-pointer rounded-md text-xs text-muted-foreground transition-colors hover:bg-muted/40 hover:text-foreground",gr),children:l})}):null]})}function _c({title:t,description:e,primaryLabel:r,onPrimary:s,secondaryLabel:a,onSecondary:i}){const o=fe(t,qe.title),c=fe(r,qe.primaryLabel),l=fe(a,qe.secondaryLabel);return n.jsxs("div",{className:"flex h-full flex-1 flex-col",children:[n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 pb-5 pt-7 text-center",children:[n.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-full bg-destructive/10",children:n.jsx(xt,{className:"h-6 w-6 text-destructive","aria-hidden":"true"})}),n.jsx("p",{className:"text-base font-semibold text-foreground",children:o}),e?n.jsx("p",{className:"max-w-[19rem] text-sm leading-6 text-muted-foreground",role:"alert",children:e}):null]}),n.jsxs("div",{className:"shrink-0 space-y-2 px-4 pb-5",children:[n.jsx("button",{type:"button",onClick:s,className:M("h-9 w-full cursor-pointer rounded-md bg-primary text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 focus-visible:bg-primary/80 disabled:cursor-not-allowed disabled:opacity-50",Ft),children:c}),i?n.jsx("button",{type:"button",onClick:i,className:M("h-9 w-full cursor-pointer rounded-md border border-border/60 bg-muted/30 text-sm font-medium text-foreground transition-colors hover:bg-muted/50 focus-visible:border-ring focus-visible:bg-muted/50",Ft),children:l}):null]})]})}var na=Object.defineProperty,Sr=(t,e)=>na(t,"name",{value:e,configurable:!0}),$t="horizontal",aa=["horizontal","vertical"],ia=d.forwardRef(Sr(function(e,r){const{decorative:s,orientation:a=$t,...i}=e,o=kr(a)?a:$t,l=s?{role:"none"}:{"aria-orientation":o==="vertical"?o:void 0,role:"separator"};return n.jsx(Pn.div,{"data-orientation":o,...l,...i,ref:r})},"Separator"));function kr(t){return aa.includes(t)}Sr(kr,"isValidOrientation");var Rr=ia;const Pr=d.forwardRef(({className:t,orientation:e="horizontal",decorative:r=!0,...s},a)=>n.jsx(Rr,{ref:a,decorative:r,orientation:e,className:M("shrink-0 bg-border",e==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",t),...s}));Pr.displayName=Rr.displayName;const oa=3e3,ca=Sn("pointer-events-auto relative flex w-full items-start justify-between gap-3 overflow-hidden rounded-md border px-4 py-3 text-sm shadow-lg transition-opacity",{variants:{variant:{default:"border-border bg-background text-foreground",destructive:"border-destructive/30 bg-destructive/10 text-destructive",success:"border-green-500/20 bg-green-500/15 text-green-600"}},defaultVariants:{variant:"default"}});let Ge=0,he=[];const st=new Set;function Cr(){for(const t of st)t()}function Lr(t){const e=he.findIndex(r=>r.id===t);e<0||(clearTimeout(he[e].timer),he=he.filter(r=>r.id!==t),Cr())}function la(t){Lr(t)}function wc(t){Ge=(Ge+1)%Number.MAX_SAFE_INTEGER;const e=Ge.toString(),r=t.duration??oa,s={id:e,title:t.title,description:t.description,variant:t.variant??"default",className:t.className,timer:setTimeout(()=>Lr(e),r)};return he=[...he.slice(-2),s],Cr(),e}function da(t){return st.add(t),()=>{st.delete(t)}}function Bt(){return he}function ua({className:t}){const e=d.useSyncExternalStore(da,Bt,Bt);return n.jsx("div",{"aria-live":"polite",role:"status",className:M("pointer-events-none fixed bottom-4 right-4 z-[var(--layer-toast)] flex w-full max-w-sm flex-col gap-2",t),children:e.map(r=>n.jsxs("div",{className:M(ca({variant:r.variant}),r.className),children:[n.jsxs("div",{className:"min-w-0 flex-1",children:[r.title?n.jsx("p",{className:"font-medium",children:r.title}):null,r.description?n.jsx("p",{className:M(r.title?"mt-0.5":void 0),children:r.description}):null]}),n.jsx("button",{type:"button","aria-label":"关闭通知",className:M("shrink-0 rounded-sm opacity-60 transition-opacity hover:opacity-100",gr),onClick:()=>la(r.id),children:n.jsx(Cn,{"aria-hidden":"true",className:"h-3.5 w-3.5"})})]},r.id))})}const ha=300;function fa({notice:t,developerMode:e,copy:r}){const[s,a]=d.useState(!1),i=n.jsxs("span",{className:"inline-flex items-start gap-1.5",children:[t.tone==="warning"?n.jsx(xt,{"aria-hidden":"true",className:"mt-0.5 h-3.5 w-3.5 shrink-0"}):null,n.jsx("span",{children:t.text})]}),o=t.tone==="warning"?"text-warning":"text-muted-foreground",c=t.tone==="warning"?"alert":"status",l=e?t.developerDetail:void 0;return n.jsx("div",{role:c,"data-pod-sign-in":"notice","data-tone":t.tone,className:M("text-[13px] leading-5",o),children:l?n.jsxs("details",{children:[n.jsx("summary",{title:r.noticeDetailsToggle,className:"cursor-pointer rounded focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring",children:i}),n.jsxs("div",{className:"mt-1 rounded-lg bg-muted p-2 text-foreground",children:[n.jsx("pre",{className:"whitespace-pre-wrap break-all font-mono text-xs",children:l}),n.jsx("button",{type:"button",className:"mt-1 h-9 rounded-lg px-2 text-[13px] font-medium text-primary hover:bg-accent focus-visible:outline focus-visible:outline-2 focus-visible:outline-ring",onClick:()=>{navigator.clipboard?.writeText(l).then(()=>a(!0),()=>{})},children:s?r.noticeCopied:r.noticeCopy})]})]}):i})}function pa({copy:t,error:e,busy:r,onSubmit:s}){const[a,i]=d.useState(""),o=c=>{c.preventDefault();const l=a.trim();l&&s&&s(l)};return n.jsxs("form",{onSubmit:o,className:"flex flex-col gap-3","data-pod-sign-in":"custom-service",children:[n.jsx(bs,{label:t.customLabel,error:e,children:c=>n.jsx(br,{...c,name:"service",type:"text",inputMode:"url",autoComplete:"url",autoCapitalize:"none",spellCheck:!1,placeholder:t.customPlaceholder,value:a,disabled:r,className:"h-11 rounded-lg bg-card text-sm",onChange:l=>i(l.target.value)})}),n.jsx(je,{type:"submit",variant:"outline",className:dr,busy:r,disabled:!a.trim(),children:t.customSubmit})]})}function ma({app:t,brand:e,state:r,notice:s,locale:a="zh-CN",copy:i,developerMode:o=!1,primaryIcon:c,capabilities:l,onPrimary:h,onUseAnother:u,onCustomService:g,onRegister:f,onToggleCustom:v}){const p=lr(a,i),m=hs(ha),[b,S]=d.useState(!1),N=e?n.jsx("div",{"data-pod-sign-in":"source",children:e}):n.jsx(fs,{icon:t.icon,name:t.name});if(r.kind==="restoring"){const _=m?r.identity:void 0;return n.jsxs(Me,{"data-pod-sign-in-state":"restoring",children:[N,n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 text-center",children:[_?n.jsxs(n.Fragment,{children:[n.jsx(St,{name:_.displayName,avatarUrl:_.avatarUrl,storage:_.storage}),n.jsx("h1",{className:"text-[17px] font-semibold text-foreground",children:_.displayName})]}):n.jsx("h1",{className:"sr-only",children:t.name}),n.jsx("div",{role:"status","aria-live":"polite",children:m?n.jsxs("p",{className:"flex items-center gap-2 text-[13px] text-muted-foreground",children:[n.jsx(ps,{}),p.restoring]}):null})]})]})}const x=r.busy===!0,I=s?.primaryLabel??(r.kind==="remembered"?ms(p.enterApp,{app:t.name}):r.kind==="expired"?p.reauthenticate:p.useXpod),k=s?n.jsx(fa,{notice:s,developerMode:o,copy:p}):null;if(r.kind==="remembered"||r.kind==="expired")return n.jsxs(Me,{"data-pod-sign-in-state":r.kind,actions:n.jsxs(n.Fragment,{children:[k,n.jsx(je,{className:kt,busy:x,"data-pod-sign-in-primary":"true",onClick:h,children:I}),u?n.jsx(je,{variant:"ghost",className:M(gs,"w-full"),disabled:x,onClick:u,children:p.useAnother}):null]}),children:[N,n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 text-center",children:[n.jsx(St,{name:r.identity.displayName,avatarUrl:r.identity.avatarUrl,storage:r.identity.storage}),n.jsx("h1",{className:"text-[17px] font-semibold text-foreground",children:r.identity.displayName}),r.kind==="expired"?n.jsx("p",{className:"text-sm text-muted-foreground",children:p.expiredLine}):null]})]});const R=l?.customService!==!1,y=l?.register!==!1&&!!f,T=R&&(r.customOpen??b),j=()=>{const _=!T;S(_),v?.(_)};return n.jsxs(Me,{"data-pod-sign-in-state":"choose-service",actions:n.jsxs(n.Fragment,{children:[k,n.jsxs(je,{className:kt,busy:x,"data-pod-sign-in-primary":"true",onClick:h,children:[!s?.primaryLabel&&c!==null?n.jsx("span",{"aria-hidden":"true",className:"mr-2 flex",children:c??n.jsx(pt,{size:20})}):null,I]}),R?n.jsxs(n.Fragment,{children:[n.jsx(je,{variant:"outline",className:dr,disabled:x,"aria-expanded":T,onClick:j,children:p.useOtherSolid}),T?n.jsx(pa,{copy:p,error:r.customError,busy:x,onSubmit:g}):null]}):null,y?n.jsxs("p",{className:"text-center text-[13px] text-muted-foreground",children:[p.noAccount,n.jsx("button",{type:"button",className:"ml-1 h-9 rounded px-1 font-medium text-primary hover:underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-ring",disabled:x,onClick:f,children:p.register})]}):null]}),children:[N,n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsx("h1",{className:"text-[17px] font-semibold text-foreground",children:p.chooseTitle}),n.jsx("p",{className:"text-sm leading-[22px] text-muted-foreground",children:p.chooseLead}),n.jsxs("div",{className:"flex flex-col",children:[n.jsx(Rt,{summary:p.whatIsWebId,children:p.whatIsWebIdBody}),n.jsx(Rt,{summary:p.whatIsPod,children:p.whatIsPodBody})]})]})]})}function ga(t){try{const e=new URL(t),r=e.pathname.split("/").filter(s=>s&&!["profile","card"].includes(s));return r[r.length-1]??e.hostname}catch{return t}}const ba=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]],xa=W("bell",ba);const va=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],_a=W("chevron-right",va);const wa=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],ya=W("circle-check",wa);const ja=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],Ia=W("copy",ja);const Na=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]],Sa=W("external-link",Na);const ka=[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]],Ra=W("inbox",ka);const Pa=[["path",{d:"m10 17 5-5-5-5",key:"1bsop3"}],["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4",key:"u53s6r"}]],Ca=W("log-in",Pa);const La=[["path",{d:"m16 17 5-5-5-5",key:"1bji2h"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}]],Ea=W("log-out",La);const Ta=[["path",{d:"M4 5h16",key:"1tepv9"}],["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 19h16",key:"1djgab"}]],Aa=W("menu",Ta);const Ua=[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]],Da=W("monitor",Ua);const Oa=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],Er=W("refresh-cw",Oa);const Fa=[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],$a=W("settings",Fa);const Ba=[["path",{d:"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z",key:"1s2grr"}],["path",{d:"M20 2v4",key:"1rf3ol"}],["path",{d:"M22 4h-4",key:"gwowj6"}],["circle",{cx:"4",cy:"20",r:"2",key:"6kqj1y"}]],za=W("sparkles",Ba);const Ma=[["path",{d:"M21 10.656V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h12.344",key:"2acyp4"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]],Xa=W("square-check-big",Ma);const qa=[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]],Ga=W("user-round",qa);const Wa=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],Tr=W("x",Wa);function Ha({title:t="操作未完成",description:e,primaryLabel:r="重试",onPrimary:s,primaryDisabled:a=!1,secondaryLabel:i="返回",onSecondary:o,tertiaryLabel:c,onTertiary:l,pending:h=!1,children:u}){return n.jsxs("div",{className:"flex min-h-44 flex-col items-center justify-center gap-4 px-5 py-8 text-center",children:[n.jsx("div",{className:"flex h-11 w-11 items-center justify-center rounded-full bg-destructive/10",children:n.jsx(xs,{"aria-hidden":"true",className:"h-5 w-5 text-destructive"})}),n.jsxs("div",{className:"space-y-2",children:[n.jsx("p",{className:"text-base font-semibold text-foreground",children:t}),e?n.jsx("p",{role:"alert",className:"text-sm leading-6 text-muted-foreground",children:e}):null]}),u?n.jsx("div",{className:"w-full space-y-2 text-left sm:max-w-xs",children:u}):null,n.jsxs("div",{className:"flex w-full flex-col gap-2 sm:max-w-xs",children:[n.jsx("button",{type:"button",disabled:h||a,onClick:s,className:"h-10 rounded-xl bg-primary px-4 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 focus:outline-none focus-visible:bg-primary/80 disabled:cursor-not-allowed disabled:opacity-50",children:r}),o?n.jsx("button",{type:"button",disabled:h,onClick:o,className:"h-9 rounded-lg border border-border bg-background px-4 text-sm font-medium text-foreground transition-colors hover:bg-muted/50 focus:outline-none focus-visible:border-ring disabled:cursor-not-allowed disabled:opacity-50",children:i}):null,l&&c?n.jsx("button",{type:"button",disabled:h,onClick:l,className:"h-9 rounded-lg px-4 text-sm text-muted-foreground transition-colors hover:bg-muted/40 hover:text-foreground focus:outline-none focus-visible:bg-muted/40 disabled:cursor-not-allowed disabled:opacity-50",children:c}):null]})]})}let Ar=!1,Ur={status:"idle"},Fe,ue;const nt=new Set,Va=()=>Ar,zt=()=>Ur;function Dr(t){return nt.add(t),()=>{nt.delete(t)}}function Ee(t){Ur=t,nt.forEach(e=>e())}function at(t,e,r={}){return ue||(Ar=!0,Fe={account:t,runtime:e,solidCleared:!1,onComplete:r.onComplete},Or())}function Or(){if(ue)return ue;if(!Fe)return Promise.resolve();const t=Fe;return ue=(async()=>{let r=t.solidCleared?"account":"solid";Ee({status:"running",step:r});try{if(t.solidCleared||(await t.runtime?.logout(),t.solidCleared=!0),r="account",Ee({status:"running",step:r}),await t.account.logout(),t.account.isAnonymous&&!t.account.isAnonymous())throw new Error("Account sign-out did not complete")}catch(s){throw Ee({status:"error",step:r}),s}Fe=void 0,Ee({status:"idle"}),t.onComplete?.()})().finally(()=>{ue=void 0}),ue}const Mt=d.createContext(!1);function Fr({children:t}){const e=d.useContext(Mt),r=d.useSyncExternalStore(Dr,zt,zt);if(e)return n.jsx(n.Fragment,{children:t});const s=r.status!=="idle";return n.jsxs(Mt.Provider,{value:!0,children:[s&&n.jsx(vs,{mode:"page",title:"退出 Xpod",children:r.status==="running"?n.jsx(sa,{label:"正在退出…"}):n.jsx(Ha,{title:"退出未完成",description:r.step==="account"?"账号会话尚未退出,请重试完成退出。":"WebID 会话尚未退出,请重试完成退出。",primaryLabel:"重试退出",onPrimary:()=>{Or().catch(()=>{})}})}),n.jsx("div",{className:s?"hidden":"contents","aria-hidden":s||void 0,inert:s||void 0,children:t})]})}function Qa(t){try{const r=new URL(t).pathname.split("/").filter(Boolean).map(i=>decodeURIComponent(i)),s=r.indexOf("profile");if(s>0)return r[s-1];const a=r.find(i=>i!=="profile"&&i!=="card");if(a)return a}catch{}return"there"}const yc=Object.freeze(Object.defineProperty({__proto__:null,ColumnBuilder:Ms,PodArrayColumn:Xs,PodBooleanColumn:qs,PodColumnBase:Gs,PodDateTimeColumn:Ws,PodIntegerColumn:Hs,PodJsonColumn:Vs,PodObjectColumn:Qs,PodStringColumn:Ks,PodTable:Js,PodUriColumn:Ys,SolidSchema:Zs,boolean:en,date:tn,generateNanoId:rn,hasStringValue:sn,hasTermValue:nn,id:an,integer:on,isSolidSchema:cn,json:ln,mergeSchemaColumns:dn,object:un,podTable:ws,real:hn,resolveTermIri:fn,solidSchema:pn,string:_s,text:mn,timestamp:gn,uri:bn,validateColumnOverride:xn},Symbol.toStringTag,{value:"Module"})),_e="http://www.w3.org/1999/02/22-rdf-syntax-ns#",we="http://www.w3.org/2001/XMLSchema#",Te="http://www.w3.org/2000/10/swap/",Z={xsd:{decimal:`${we}decimal`,boolean:`${we}boolean`,double:`${we}double`,integer:`${we}integer`,string:`${we}string`},rdf:{type:`${_e}type`,nil:`${_e}nil`,first:`${_e}first`,rest:`${_e}rest`,langString:`${_e}langString`},owl:{sameAs:"http://www.w3.org/2002/07/owl#sameAs"},r:{forSome:`${Te}reify#forSome`,forAll:`${Te}reify#forAll`},log:{implies:`${Te}log#implies`,isImpliedBy:`${Te}log#isImpliedBy`}},{xsd:Ae}=Z,Ka=/\\u([a-fA-F0-9]{4})|\\U([a-fA-F0-9]{8})|\\([^])/g,Xt={"\\":"\\","'":"'",'"':'"',n:`
3
+ `,r:"\r",t:" ",f:"\f",b:"\b",_:"_","~":"~",".":".","-":"-","!":"!",$:"$","&":"&","(":"(",")":")","*":"*","+":"+",",":",",";":";","=":"=","/":"/","?":"?","#":"#","@":"@","%":"%"},Ja=/[\x00-\x20<>\\"\{\}\|\^\`]/,Ya={_iri:!0,_unescapedIri:!0,_simpleQuotedString:!0,_langcode:!0,_blank:!0,_newline:!0,_comment:!0,_whitespace:!0,_endOfFile:!0},Za=/$0^/;class ei{constructor(e){if(this._iri=/^<((?:[^ <>{}\\]|\\[uU])+)>[ \t]*/,this._unescapedIri=/^<([^\x00-\x20<>\\"\{\}\|\^\`]*)>[ \t]*/,this._simpleQuotedString=/^"([^"\\\r\n]*)"(?=[^"])/,this._simpleApostropheString=/^'([^'\\\r\n]*)'(?=[^'])/,this._langcode=/^@([a-z]+(?:-[a-z0-9]+)*)(?=[^a-z0-9\-])/i,this._prefix=/^((?:[A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:\.?[\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)?:(?=[#\s<])/,this._prefixed=/^((?:[A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:\.?[\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)?:((?:(?:[0-:A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~])(?:(?:[\.\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~])*(?:[\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~]))?)?)(?:[ \t]+|(?=\.?[,;!\^\s#()\[\]\{\}"'<>]))/,this._variable=/^\?(?:(?:[A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:[\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)(?=[.,;!\^\s#()\[\]\{\}"'<>])/,this._blank=/^_:((?:[0-9A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:\.?[\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)(?:[ \t]+|(?=\.?[,;:\s#()\[\]\{\}"'<>]))/,this._number=/^[\-+]?(?:(\d+\.\d*|\.?\d+)[eE][\-+]?|\d*(\.)?)\d+(?=\.?[,;:\s#()\[\]\{\}"'<>])/,this._boolean=/^(?:true|false)(?=[.,;\s#()\[\]\{\}"'<>])/,this._keyword=/^@[a-z]+(?=[\s#<:])/i,this._sparqlKeyword=/^(?:PREFIX|BASE|GRAPH)(?=[\s#<])/i,this._shortPredicates=/^a(?=[\s#()\[\]\{\}"'<>])/,this._newline=/^[ \t]*(?:#[^\n\r]*)?(?:\r\n|\n|\r)[ \t]*/,this._comment=/#([^\n\r]*)/,this._whitespace=/^[ \t]+/,this._endOfFile=/^(?:#[^\n\r]*)?$/,e=e||{},this._isImpliedBy=e.isImpliedBy,this._lineMode=!!e.lineMode){this._n3Mode=!1;for(const r in this)!(r in Ya)&&this[r]instanceof RegExp&&(this[r]=Za)}else this._n3Mode=e.n3!==!1;this.comments=!!e.comments,this._literalClosingPos=0}_tokenizeToEnd(e,r){let s=this._input,a=s.length;for(;;){let c,l;for(;c=this._newline.exec(s);)this.comments&&(l=this._comment.exec(c[0]))&&i("comment",l[1],"",this._line,c[0].length),s=s.substr(c[0].length,s.length),a=s.length,this._line++;if(!c&&(c=this._whitespace.exec(s))&&(s=s.substr(c[0].length,s.length)),this._endOfFile.test(s))return r&&(this.comments&&(l=this._comment.exec(s))&&i("comment",l[1],"",this._line,s.length),s=null,i("eof","","",this._line,0)),this._input=s;const h=this._line,u=s[0];let g="",f="",v="",p=null,m=0,b=!1;switch(u){case"^":if(s.length<3)break;if(s[1]==="^"){if(this._previousMarker="^^",s=s.substr(2),s[0]!=="<"){b=!0;break}}else{this._n3Mode&&(m=1,g="^");break}case"<":if(p=this._unescapedIri.exec(s))g="IRI",f=p[1];else if(p=this._iri.exec(s)){if(f=this._unescape(p[1]),f===null||Ja.test(f))return o(this);g="IRI"}else s.length>1&&s[1]==="<"?(g="<<",m=2):this._n3Mode&&s.length>1&&s[1]==="="&&(m=2,this._isImpliedBy?(g="abbreviation",f="<"):(g="inverse",f=">"));break;case">":s.length>1&&s[1]===">"&&(g=">>",m=2);break;case"_":((p=this._blank.exec(s))||r&&(p=this._blank.exec(`${s} `)))&&(g="blank",v="_",f=p[1]);break;case'"':if(p=this._simpleQuotedString.exec(s))f=p[1];else if({value:f,matchLength:m}=this._parseLiteral(s),f===null)return o(this);(p!==null||m!==0)&&(g="literal",this._literalClosingPos=0);break;case"'":if(!this._lineMode){if(p=this._simpleApostropheString.exec(s))f=p[1];else if({value:f,matchLength:m}=this._parseLiteral(s),f===null)return o(this);(p!==null||m!==0)&&(g="literal",this._literalClosingPos=0)}break;case"?":this._n3Mode&&(p=this._variable.exec(s))&&(g="var",f=p[0]);break;case"@":this._previousMarker==="literal"&&(p=this._langcode.exec(s))?(g="langcode",f=p[1]):(p=this._keyword.exec(s))&&(g=p[0]);break;case".":if(s.length===1?r:s[1]<"0"||s[1]>"9"){g=".",m=1;break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":case"+":case"-":(p=this._number.exec(s)||r&&(p=this._number.exec(`${s} `)))&&(g="literal",f=p[0],v=typeof p[1]=="string"?Ae.double:typeof p[2]=="string"?Ae.decimal:Ae.integer);break;case"B":case"b":case"p":case"P":case"G":case"g":(p=this._sparqlKeyword.exec(s))?g=p[0].toUpperCase():b=!0;break;case"f":case"t":(p=this._boolean.exec(s))?(g="literal",f=p[0],v=Ae.boolean):b=!0;break;case"a":(p=this._shortPredicates.exec(s))?(g="abbreviation",f="a"):b=!0;break;case"=":this._n3Mode&&s.length>1&&(g="abbreviation",s[1]!==">"?(m=1,f="="):(m=2,f=">"));break;case"!":if(!this._n3Mode)break;case",":case";":case"[":case"]":case"(":case")":case"}":this._lineMode||(m=1,g=u);break;case"{":!this._lineMode&&s.length>=2&&(s[1]==="|"?(g="{|",m=2):(g=u,m=1));break;case"|":s.length>=2&&s[1]==="}"&&(g="|}",m=2);break;default:b=!0}if(b&&((this._previousMarker==="@prefix"||this._previousMarker==="PREFIX")&&(p=this._prefix.exec(s))?(g="prefix",f=p[1]||""):((p=this._prefixed.exec(s))||r&&(p=this._prefixed.exec(`${s} `)))&&(g="prefixed",v=p[1]||"",f=this._unescape(p[2]))),this._previousMarker==="^^")switch(g){case"prefixed":g="type";break;case"IRI":g="typeIRI";break;default:g=""}if(!g)return r||!/^'''|^"""/.test(s)&&/\n|\r/.test(s)?o(this):this._input=s;const S=m||p[0].length,N=i(g,f,v,h,S);this.previousToken=N,this._previousMarker=g,s=s.substr(S,s.length)}function i(c,l,h,u,g){const f=s?a-s.length:a,v=f+g,p={type:c,value:l,prefix:h,line:u,start:f,end:v};return e(null,p),p}function o(c){e(c._syntaxError(/^\S*/.exec(s)[0]))}}_unescape(e){let r=!1;const s=e.replace(Ka,(a,i,o,c)=>{if(typeof i=="string")return String.fromCharCode(Number.parseInt(i,16));if(typeof o=="string"){let l=Number.parseInt(o,16);return l<=65535?String.fromCharCode(Number.parseInt(o,16)):String.fromCharCode(55296+((l-=65536)>>10),56320+(l&1023))}return c in Xt?Xt[c]:(r=!0,"")});return r?null:s}_parseLiteral(e){if(e.length>=3){const r=e.match(/^(?:"""|"|'''|'|)/)[0],s=r.length;let a=Math.max(this._literalClosingPos,s);for(;(a=e.indexOf(r,a))>0;){let i=0;for(;e[a-i-1]==="\\";)i++;if(i%2===0){const o=e.substring(s,a),c=o.split(/\r\n|\r|\n/).length-1,l=a+s;if(s===1&&c!==0||s===3&&this._lineMode)break;return this._line+=c,{value:this._unescape(o),matchLength:l}}a++}this._literalClosingPos=e.length-s+1}return{value:"",matchLength:0}}_syntaxError(e){this._input=null;const r=new Error(`Unexpected "${e}" on line ${this._line}.`);return r.context={token:void 0,line:this._line,previousToken:this.previousToken},r}_readStartingBom(e){return e.startsWith("\uFEFF")?e.substr(1):e}tokenize(e,r){if(this._line=1,typeof e=="string")if(this._input=this._readStartingBom(e),typeof r=="function")queueMicrotask(()=>this._tokenizeToEnd(r,!0));else{const s=[];let a;if(this._tokenizeToEnd((i,o)=>i?a=i:s.push(o),!0),a)throw a;return s}else this._pendingBuffer=null,typeof e.setEncoding=="function"&&e.setEncoding("utf8"),e.on("data",s=>{this._input!==null&&s.length!==0&&(this._pendingBuffer&&(s=ys.Buffer.concat([this._pendingBuffer,s]),this._pendingBuffer=null),s[s.length-1]&128?this._pendingBuffer=s:(typeof this._input>"u"?this._input=this._readStartingBom(typeof s=="string"?s:s.toString()):this._input+=s,this._tokenizeToEnd(r,!1)))}),e.on("end",()=>{typeof this._input=="string"&&this._tokenizeToEnd(r,!0)}),e.on("error",r)}}const{rdf:ti,xsd:me}=Z;let Pe,ri=0;const si={namedNode:zr,blankNode:Mr,variable:qr,literal:Xr,defaultGraph:oi,quad:it,triple:it,fromTerm:Ie,fromQuad:Gr};class ie{constructor(e){this.id=e}get value(){return this.id}equals(e){return e instanceof ie?this.id===e.id:!!e&&this.termType===e.termType&&this.value===e.value}hashCode(){return 0}toJSON(){return{termType:this.termType,value:this.value}}}class $r extends ie{get termType(){return"NamedNode"}}class ke extends ie{get termType(){return"Literal"}get value(){return this.id.substring(1,this.id.lastIndexOf('"'))}get language(){const e=this.id;let r=e.lastIndexOf('"')+1;return r<e.length&&e[r++]==="@"?e.substr(r).toLowerCase():""}get datatype(){return new $r(this.datatypeString)}get datatypeString(){const e=this.id,r=e.lastIndexOf('"')+1,s=r<e.length?e[r]:"";return s==="^"?e.substr(r+2):s!=="@"?me.string:ti.langString}equals(e){return e instanceof ke?this.id===e.id:!!e&&!!e.datatype&&this.termType===e.termType&&this.value===e.value&&this.language===e.language&&this.datatype.value===e.datatype.value}toJSON(){return{termType:this.termType,value:this.value,language:this.language,datatype:{termType:"NamedNode",value:this.datatypeString}}}}class ni extends ie{constructor(e){super(`_:${e}`)}get termType(){return"BlankNode"}get value(){return this.id.substr(2)}}class ai extends ie{constructor(e){super(`?${e}`)}get termType(){return"Variable"}get value(){return this.id.substr(1)}}class ii extends ie{constructor(){return super(""),Pe||this}get termType(){return"DefaultGraph"}equals(e){return this===e||!!e&&this.termType===e.termType}}Pe=new ii;class Br extends ie{constructor(e,r,s,a){super(""),this._subject=e,this._predicate=r,this._object=s,this._graph=a||Pe}get termType(){return"Quad"}get subject(){return this._subject}get predicate(){return this._predicate}get object(){return this._object}get graph(){return this._graph}toJSON(){return{termType:this.termType,subject:this._subject.toJSON(),predicate:this._predicate.toJSON(),object:this._object.toJSON(),graph:this._graph.toJSON()}}equals(e){return!!e&&this._subject.equals(e.subject)&&this._predicate.equals(e.predicate)&&this._object.equals(e.object)&&this._graph.equals(e.graph)}}function zr(t){return new $r(t)}function Mr(t){return new ni(t||`n3-${ri++}`)}function Xr(t,e){if(typeof e=="string")return new ke(`"${t}"@${e.toLowerCase()}`);let r=e?e.value:"";return r===""&&(typeof t=="boolean"?r=me.boolean:typeof t=="number"&&(Number.isFinite(t)?r=Number.isInteger(t)?me.integer:me.double:(r=me.double,Number.isNaN(t)||(t=t>0?"INF":"-INF")))),r===""||r===me.string?new ke(`"${t}"`):new ke(`"${t}"^^${r}`)}function qr(t){return new ai(t)}function oi(){return Pe}function it(t,e,r,s){return new Br(t,e,r,s)}function Ie(t){if(t instanceof ie)return t;switch(t.termType){case"NamedNode":return zr(t.value);case"BlankNode":return Mr(t.value);case"Variable":return qr(t.value);case"DefaultGraph":return Pe;case"Literal":return Xr(t.value,t.language||t.datatype);case"Quad":return Gr(t);default:throw new Error(`Unexpected termType: ${t.termType}`)}}function Gr(t){if(t instanceof Br)return t;if(t.termType!=="Quad")throw new Error(`Unexpected termType: ${t.termType}`);return it(Ie(t.subject),Ie(t.predicate),Ie(t.object),Ie(t.graph))}let qt=0;class Wr{constructor(e){this._contextStack=[],this._graph=null,e=e||{},this._setBase(e.baseIRI),e.factory&&Hr(this,e.factory);const r=typeof e.format=="string"?e.format.match(/\w*$/)[0].toLowerCase():"",s=/turtle/.test(r),a=/trig/.test(r),i=/triple/.test(r),o=/quad/.test(r),c=this._n3Mode=/n3/.test(r),l=i||o;(this._supportsNamedGraphs=!(s||c))||(this._readPredicateOrNamedGraph=this._readPredicate),this._supportsQuads=!(s||a||i||c),this._isImpliedBy=e.isImpliedBy,this._supportsRDFStar=r===""||/star|\*$/.test(r),l&&(this._resolveRelativeIRI=h=>null),this._blankNodePrefix=typeof e.blankNodePrefix!="string"?"":e.blankNodePrefix.replace(/^(?!_:)/,"_:"),this._lexer=e.lexer||new ei({lineMode:l,n3:c,isImpliedBy:this._isImpliedBy}),this._explicitQuantifiers=!!e.explicitQuantifiers}static _resetBlankNodePrefix(){qt=0}_setBase(e){if(!e)this._base="",this._basePath="";else{const r=e.indexOf("#");r>=0&&(e=e.substr(0,r)),this._base=e,this._basePath=e.indexOf("/")<0?e:e.replace(/[^\/?]*(?:\?.*)?$/,""),e=e.match(/^(?:([a-z][a-z0-9+.-]*:))?(?:\/\/[^\/]*)?/i),this._baseRoot=e[0],this._baseScheme=e[1]}}_saveContext(e,r,s,a,i){const o=this._n3Mode;this._contextStack.push({type:e,subject:s,predicate:a,object:i,graph:r,inverse:o?this._inversePredicate:!1,blankPrefix:o?this._prefixes._:"",quantified:o?this._quantified:null}),o&&(this._inversePredicate=!1,this._prefixes._=this._graph?`${this._graph.value}.`:".",this._quantified=Object.create(this._quantified))}_restoreContext(e,r){const s=this._contextStack.pop();if(!s||s.type!==e)return this._error(`Unexpected ${r.type}`,r);this._subject=s.subject,this._predicate=s.predicate,this._object=s.object,this._graph=s.graph,this._n3Mode&&(this._inversePredicate=s.inverse,this._prefixes._=s.blankPrefix,this._quantified=s.quantified)}_readInTopContext(e){switch(e.type){case"eof":return this._graph!==null?this._error("Unclosed graph",e):(delete this._prefixes._,this._callback(null,null,this._prefixes));case"PREFIX":this._sparqlStyle=!0;case"@prefix":return this._readPrefix;case"BASE":this._sparqlStyle=!0;case"@base":return this._readBaseIRI;case"{":if(this._supportsNamedGraphs)return this._graph="",this._subject=null,this._readSubject;case"GRAPH":if(this._supportsNamedGraphs)return this._readNamedGraphLabel;default:return this._readSubject(e)}}_readEntity(e,r){let s;switch(e.type){case"IRI":case"typeIRI":const a=this._resolveIRI(e.value);if(a===null)return this._error("Invalid IRI",e);s=this._factory.namedNode(a);break;case"type":case"prefixed":const i=this._prefixes[e.prefix];if(i===void 0)return this._error(`Undefined prefix "${e.prefix}:"`,e);s=this._factory.namedNode(i+e.value);break;case"blank":s=this._factory.blankNode(this._prefixes[e.prefix]+e.value);break;case"var":s=this._factory.variable(e.value.substr(1));break;default:return this._error(`Expected entity but got ${e.type}`,e)}return!r&&this._n3Mode&&s.id in this._quantified&&(s=this._quantified[s.id]),s}_readSubject(e){switch(this._predicate=null,e.type){case"[":return this._saveContext("blank",this._graph,this._subject=this._factory.blankNode(),null,null),this._readBlankNodeHead;case"(":return this._saveContext("list",this._graph,this.RDF_NIL,null,null),this._subject=null,this._readListItem;case"{":return this._n3Mode?(this._saveContext("formula",this._graph,this._graph=this._factory.blankNode(),null,null),this._readSubject):this._error("Unexpected graph",e);case"}":return this._readPunctuation(e);case"@forSome":return this._n3Mode?(this._subject=null,this._predicate=this.N3_FORSOME,this._quantifier="blankNode",this._readQuantifierList):this._error('Unexpected "@forSome"',e);case"@forAll":return this._n3Mode?(this._subject=null,this._predicate=this.N3_FORALL,this._quantifier="variable",this._readQuantifierList):this._error('Unexpected "@forAll"',e);case"literal":if(!this._n3Mode)return this._error("Unexpected literal",e);if(e.prefix.length===0)return this._literalValue=e.value,this._completeSubjectLiteral;this._subject=this._factory.literal(e.value,this._factory.namedNode(e.prefix));break;case"<<":return this._supportsRDFStar?(this._saveContext("<<",this._graph,null,null,null),this._graph=null,this._readSubject):this._error("Unexpected RDF-star syntax",e);default:if((this._subject=this._readEntity(e))===void 0)return;if(this._n3Mode)return this._getPathReader(this._readPredicateOrNamedGraph)}return this._readPredicateOrNamedGraph}_readPredicate(e){const r=e.type;switch(r){case"inverse":this._inversePredicate=!0;case"abbreviation":this._predicate=this.ABBREVIATIONS[e.value];break;case".":case"]":case"}":return this._predicate===null?this._error(`Unexpected ${r}`,e):(this._subject=null,r==="]"?this._readBlankNodeTail(e):this._readPunctuation(e));case";":return this._predicate!==null?this._readPredicate:this._error("Expected predicate but got ;",e);case"[":if(this._n3Mode)return this._saveContext("blank",this._graph,this._subject,this._subject=this._factory.blankNode(),null),this._readBlankNodeHead;case"blank":if(!this._n3Mode)return this._error("Disallowed blank node as predicate",e);default:if((this._predicate=this._readEntity(e))===void 0)return}return this._readObject}_readObject(e){switch(e.type){case"literal":if(e.prefix.length===0)return this._literalValue=e.value,this._readDataTypeOrLang;this._object=this._factory.literal(e.value,this._factory.namedNode(e.prefix));break;case"[":return this._saveContext("blank",this._graph,this._subject,this._predicate,this._subject=this._factory.blankNode()),this._readBlankNodeHead;case"(":return this._saveContext("list",this._graph,this._subject,this._predicate,this.RDF_NIL),this._subject=null,this._readListItem;case"{":return this._n3Mode?(this._saveContext("formula",this._graph,this._subject,this._predicate,this._graph=this._factory.blankNode()),this._readSubject):this._error("Unexpected graph",e);case"<<":return this._supportsRDFStar?(this._saveContext("<<",this._graph,this._subject,this._predicate,null),this._graph=null,this._readSubject):this._error("Unexpected RDF-star syntax",e);default:if((this._object=this._readEntity(e))===void 0)return;if(this._n3Mode)return this._getPathReader(this._getContextEndReader())}return this._getContextEndReader()}_readPredicateOrNamedGraph(e){return e.type==="{"?this._readGraph(e):this._readPredicate(e)}_readGraph(e){return e.type!=="{"?this._error(`Expected graph but got ${e.type}`,e):(this._graph=this._subject,this._subject=null,this._readSubject)}_readBlankNodeHead(e){return e.type==="]"?(this._subject=null,this._readBlankNodeTail(e)):(this._predicate=null,this._readPredicate(e))}_readBlankNodeTail(e){if(e.type!=="]")return this._readBlankNodePunctuation(e);this._subject!==null&&this._emit(this._subject,this._predicate,this._object,this._graph);const r=this._predicate===null;return this._restoreContext("blank",e),this._object!==null?this._getContextEndReader():this._predicate!==null?this._readObject:r?this._readPredicateOrNamedGraph:this._readPredicateAfterBlank}_readPredicateAfterBlank(e){switch(e.type){case".":case"}":return this._subject=null,this._readPunctuation(e);default:return this._readPredicate(e)}}_readListItem(e){let r=null,s=null,a=this._readListItem;const i=this._subject,o=this._contextStack,c=o[o.length-1];switch(e.type){case"[":this._saveContext("blank",this._graph,s=this._factory.blankNode(),this.RDF_FIRST,this._subject=r=this._factory.blankNode()),a=this._readBlankNodeHead;break;case"(":this._saveContext("list",this._graph,s=this._factory.blankNode(),this.RDF_FIRST,this.RDF_NIL),this._subject=null;break;case")":if(this._restoreContext("list",e),o.length!==0&&o[o.length-1].type==="list"&&this._emit(this._subject,this._predicate,this._object,this._graph),this._predicate===null){if(a=this._readPredicate,this._subject===this.RDF_NIL)return a}else if(a=this._getContextEndReader(),this._object===this.RDF_NIL)return a;s=this.RDF_NIL;break;case"literal":e.prefix.length===0?(this._literalValue=e.value,a=this._readListItemDataTypeOrLang):(r=this._factory.literal(e.value,this._factory.namedNode(e.prefix)),a=this._getContextEndReader());break;case"{":return this._n3Mode?(this._saveContext("formula",this._graph,this._subject,this._predicate,this._graph=this._factory.blankNode()),this._readSubject):this._error("Unexpected graph",e);default:if((r=this._readEntity(e))===void 0)return}if(s===null&&(this._subject=s=this._factory.blankNode()),i===null?c.predicate===null?c.subject=s:c.object=s:this._emit(i,this.RDF_REST,s,this._graph),r!==null){if(this._n3Mode&&(e.type==="IRI"||e.type==="prefixed"))return this._saveContext("item",this._graph,s,this.RDF_FIRST,r),this._subject=r,this._predicate=null,this._getPathReader(this._readListItem);this._emit(s,this.RDF_FIRST,r,this._graph)}return a}_readDataTypeOrLang(e){return this._completeObjectLiteral(e,!1)}_readListItemDataTypeOrLang(e){return this._completeObjectLiteral(e,!0)}_completeLiteral(e){let r=this._factory.literal(this._literalValue);switch(e.type){case"type":case"typeIRI":const s=this._readEntity(e);if(s===void 0)return;r=this._factory.literal(this._literalValue,s),e=null;break;case"langcode":r=this._factory.literal(this._literalValue,e.value),e=null;break}return{token:e,literal:r}}_completeSubjectLiteral(e){return this._subject=this._completeLiteral(e).literal,this._readPredicateOrNamedGraph}_completeObjectLiteral(e,r){const s=this._completeLiteral(e);if(s)return this._object=s.literal,r&&this._emit(this._subject,this.RDF_FIRST,this._object,this._graph),s.token===null?this._getContextEndReader():(this._readCallback=this._getContextEndReader(),this._readCallback(s.token))}_readFormulaTail(e){return e.type!=="}"?this._readPunctuation(e):(this._subject!==null&&this._emit(this._subject,this._predicate,this._object,this._graph),this._restoreContext("formula",e),this._object===null?this._readPredicate:this._getContextEndReader())}_readPunctuation(e){let r,s=this._graph;const a=this._subject,i=this._inversePredicate;switch(e.type){case"}":if(this._graph===null)return this._error("Unexpected graph closing",e);if(this._n3Mode)return this._readFormulaTail(e);this._graph=null;case".":this._subject=null,r=this._contextStack.length?this._readSubject:this._readInTopContext,i&&(this._inversePredicate=!1);break;case";":r=this._readPredicate;break;case",":r=this._readObject;break;case"{|":if(!this._supportsRDFStar)return this._error("Unexpected RDF-star syntax",e);const o=this._predicate,c=this._object;this._subject=this._factory.quad(a,o,c,this.DEFAULTGRAPH),r=this._readPredicate;break;case"|}":if(this._subject.termType!=="Quad")return this._error("Unexpected asserted triple closing",e);this._subject=null,r=this._readPunctuation;break;default:if(this._supportsQuads&&this._graph===null&&(s=this._readEntity(e))!==void 0){r=this._readQuadPunctuation;break}return this._error(`Expected punctuation to follow "${this._object.id}"`,e)}if(a!==null){const o=this._predicate,c=this._object;i?this._emit(c,o,a,s):this._emit(a,o,c,s)}return r}_readBlankNodePunctuation(e){let r;switch(e.type){case";":r=this._readPredicate;break;case",":r=this._readObject;break;default:return this._error(`Expected punctuation to follow "${this._object.id}"`,e)}return this._emit(this._subject,this._predicate,this._object,this._graph),r}_readQuadPunctuation(e){return e.type!=="."?this._error("Expected dot to follow quad",e):this._readInTopContext}_readPrefix(e){return e.type!=="prefix"?this._error("Expected prefix to follow @prefix",e):(this._prefix=e.value,this._readPrefixIRI)}_readPrefixIRI(e){if(e.type!=="IRI")return this._error(`Expected IRI to follow prefix "${this._prefix}:"`,e);const r=this._readEntity(e);return this._prefixes[this._prefix]=r.value,this._prefixCallback(this._prefix,r),this._readDeclarationPunctuation}_readBaseIRI(e){const r=e.type==="IRI"&&this._resolveIRI(e.value);return r?(this._setBase(r),this._readDeclarationPunctuation):this._error("Expected valid IRI to follow base declaration",e)}_readNamedGraphLabel(e){switch(e.type){case"IRI":case"blank":case"prefixed":return this._readSubject(e),this._readGraph;case"[":return this._readNamedGraphBlankLabel;default:return this._error("Invalid graph label",e)}}_readNamedGraphBlankLabel(e){return e.type!=="]"?this._error("Invalid graph label",e):(this._subject=this._factory.blankNode(),this._readGraph)}_readDeclarationPunctuation(e){return this._sparqlStyle?(this._sparqlStyle=!1,this._readInTopContext(e)):e.type!=="."?this._error("Expected declaration to end with a dot",e):this._readInTopContext}_readQuantifierList(e){let r;switch(e.type){case"IRI":case"prefixed":if((r=this._readEntity(e,!0))!==void 0)break;default:return this._error(`Unexpected ${e.type}`,e)}return this._explicitQuantifiers?(this._subject===null?this._emit(this._graph||this.DEFAULTGRAPH,this._predicate,this._subject=this._factory.blankNode(),this.QUANTIFIERS_GRAPH):this._emit(this._subject,this.RDF_REST,this._subject=this._factory.blankNode(),this.QUANTIFIERS_GRAPH),this._emit(this._subject,this.RDF_FIRST,r,this.QUANTIFIERS_GRAPH)):this._quantified[r.id]=this._factory[this._quantifier](this._factory.blankNode().value),this._readQuantifierPunctuation}_readQuantifierPunctuation(e){return e.type===","?this._readQuantifierList:(this._explicitQuantifiers&&(this._emit(this._subject,this.RDF_REST,this.RDF_NIL,this.QUANTIFIERS_GRAPH),this._subject=null),this._readCallback=this._getContextEndReader(),this._readCallback(e))}_getPathReader(e){return this._afterPath=e,this._readPath}_readPath(e){switch(e.type){case"!":return this._readForwardPath;case"^":return this._readBackwardPath;default:const r=this._contextStack,s=r.length&&r[r.length-1];if(s&&s.type==="item"){const a=this._subject;this._restoreContext("item",e),this._emit(this._subject,this.RDF_FIRST,a,this._graph)}return this._afterPath(e)}}_readForwardPath(e){let r,s;const a=this._factory.blankNode();if((s=this._readEntity(e))!==void 0)return this._predicate===null?(r=this._subject,this._subject=a):(r=this._object,this._object=a),this._emit(r,s,a,this._graph),this._readPath}_readBackwardPath(e){const r=this._factory.blankNode();let s,a;if((s=this._readEntity(e))!==void 0)return this._predicate===null?(a=this._subject,this._subject=r):(a=this._object,this._object=r),this._emit(r,s,a,this._graph),this._readPath}_readRDFStarTailOrGraph(e){return e.type!==">>"?this._supportsQuads&&this._graph===null&&(this._graph=this._readEntity(e))!==void 0?this._readRDFStarTail:this._error(`Expected >> to follow "${this._object.id}"`,e):this._readRDFStarTail(e)}_readRDFStarTail(e){if(e.type!==">>")return this._error(`Expected >> but got ${e.type}`,e);const r=this._factory.quad(this._subject,this._predicate,this._object,this._graph||this.DEFAULTGRAPH);return this._restoreContext("<<",e),this._subject===null?(this._subject=r,this._readPredicate):(this._object=r,this._getContextEndReader())}_getContextEndReader(){const e=this._contextStack;if(!e.length)return this._readPunctuation;switch(e[e.length-1].type){case"blank":return this._readBlankNodeTail;case"list":return this._readListItem;case"formula":return this._readFormulaTail;case"<<":return this._readRDFStarTailOrGraph}}_emit(e,r,s,a){this._callback(null,this._factory.quad(e,r,s,a||this.DEFAULTGRAPH))}_error(e,r){const s=new Error(`${e} on line ${r.line}.`);s.context={token:r,line:r.line,previousToken:this._lexer.previousToken},this._callback(s),this._callback=Ue}_resolveIRI(e){return/^[a-z][a-z0-9+.-]*:/i.test(e)?e:this._resolveRelativeIRI(e)}_resolveRelativeIRI(e){if(!e.length)return this._base;switch(e[0]){case"#":return this._base+e;case"?":return this._base.replace(/(?:\?.*)?$/,e);case"/":return(e[1]==="/"?this._baseScheme:this._baseRoot)+this._removeDotSegments(e);default:return/^[^/:]*:/.test(e)?null:this._removeDotSegments(this._basePath+e)}}_removeDotSegments(e){if(!/(^|\/)\.\.?($|[/#?])/.test(e))return e;const r=e.length;let s="",a=-1,i=-1,o=0,c="/";for(;a<r;){switch(c){case":":if(i<0&&e[++a]==="/"&&e[++a]==="/")for(;(i=a+1)<r&&e[i]!=="/";)a=i;break;case"?":case"#":a=r;break;case"/":if(e[a+1]===".")switch(c=e[++a+1],c){case"/":s+=e.substring(o,a-1),o=a+1;break;case void 0:case"?":case"#":return s+e.substring(o,a)+e.substr(a+1);case".":if(c=e[++a+1],c===void 0||c==="/"||c==="?"||c==="#"){if(s+=e.substring(o,a-2),(o=s.lastIndexOf("/"))>=i&&(s=s.substr(0,o)),c!=="/")return`${s}/${e.substr(a+1)}`;o=a+1}}}c=e[++a]}return s+e.substring(o)}parse(e,r,s){let a,i,o;if(r&&(r.onQuad||r.onPrefix||r.onComment)?(a=r.onQuad,i=r.onPrefix,o=r.onComment):(a=r,i=s),this._readCallback=this._readInTopContext,this._sparqlStyle=!1,this._prefixes=Object.create(null),this._prefixes._=this._blankNodePrefix?this._blankNodePrefix.substr(2):`b${qt++}_`,this._prefixCallback=i||Ue,this._inversePredicate=!1,this._quantified=Object.create(null),!a){const l=[];let h;if(this._callback=(u,g)=>{u?h=u:g&&l.push(g)},this._lexer.tokenize(e).every(u=>this._readCallback=this._readCallback(u)),h)throw h;return l}let c=(l,h)=>{l!==null?(this._callback(l),this._callback=Ue):this._readCallback&&(this._readCallback=this._readCallback(h))};o&&(this._lexer.comments=!0,c=(l,h)=>{l!==null?(this._callback(l),this._callback=Ue):this._readCallback&&(h.type==="comment"?o(h.value):this._readCallback=this._readCallback(h))}),this._callback=a,this._lexer.tokenize(e,c)}}function Ue(){}function Hr(t,e){t._factory=e,t.DEFAULTGRAPH=e.defaultGraph(),t.RDF_FIRST=e.namedNode(Z.rdf.first),t.RDF_REST=e.namedNode(Z.rdf.rest),t.RDF_NIL=e.namedNode(Z.rdf.nil),t.N3_FORALL=e.namedNode(Z.r.forAll),t.N3_FORSOME=e.namedNode(Z.r.forSome),t.ABBREVIATIONS={a:e.namedNode(Z.rdf.type),"=":e.namedNode(Z.owl.sameAs),">":e.namedNode(Z.log.implies),"<":e.namedNode(Z.log.isImpliedBy)},t.QUANTIFIERS_GRAPH=e.namedNode("urn:n3:quantifiers")}Hr(Wr.prototype,si);async function ci(t,e={}){const r=e.webId??t.info?.webId;if(!r?.trim()||typeof t.fetch!="function")return null;const s=fi(r),a=await t.fetch(s,{headers:{Accept:"text/turtle, application/ld+json;q=0.9, text/n3;q=0.8, */*;q=0.1"}});if(!a.ok)throw new Error(`Failed to fetch WebID profile: ${a.status} ${a.statusText}`.trim());const i=a.headers.get("content-type")??"",o=await a.text();if(!o.trim())return Gt(r,null);const c=await li(o,{contentType:i,profileDocumentUrl:s,webId:r});return Gt(r,c)}async function li(t,e){return(e.contentType?.toLowerCase()??"").includes("application/ld+json")||t.trimStart().startsWith("{")?ui(t,e.webId):await di(t,e)}async function di(t,e){const r=Wr,a=new r({baseIRI:e.profileDocumentUrl}).parse(t);return hi(a,e.webId)}function ui(t,e){try{const r=JSON.parse(t),s=Array.isArray(r)?r:Ne(r)&&Array.isArray(r["@graph"])?r["@graph"]:[r],a=s.find(o=>Ne(o)&&o["@id"]===e),i=Ne(a)?a:s.find(Ne);return i?Vr({id:e,name:le(i,Q.fn),nick:le(i,ur.nick),avatar:le(i,Q.hasPhoto),note:le(i,Q.note),email:le(i,Q.hasEmail),phone:le(i,Q.hasTelephone),region:le(i,Q.region),gender:le(i,Q.hasGender)}):null}catch{return null}}function hi(t,e){const r={id:e};for(const s of t){if(s.subject.value!==e)continue;const a=s.predicate.value,i=s.object.value;!a||!i||(a===Q.fn?r.name=i:a===ur.nick?r.nick=i:a===Q.hasPhoto?r.avatar=i:a===Q.note?r.note=i:a===Q.hasEmail?r.email=i:a===Q.hasTelephone?r.phone=i:a===Q.region?r.region=i:a===Q.hasGender&&(r.gender=i))}return Vr(r)}function Gt(t,e){return{webId:t,profile:e,displayName:js(e),username:Qa(t)}}function Vr(t){const e=Object.fromEntries(Object.entries(t).filter(([,r])=>typeof r=="string"&&r.trim()));return Object.keys(e).length>1?e:null}function le(t,e){return ot(t[e])}function ot(t){if(typeof t=="string")return t;if(Array.isArray(t))return t.map(ot).find(Boolean);if(Ne(t))return ot(t["@value"]??t["@id"])}function fi(t){const e=t.indexOf("#");return e>=0?t.slice(0,e):t}function Ne(t){return typeof t=="object"&&t!==null}function _t({accountIdentity:t,runtime:e}){const r=e?.state.status,s=r==="authenticated"&&e?e.webId??e.state.webId:t?.webId,a=r==="authenticated"&&s?void 0:t,i=a?.displayName,o=a?.username,c=a?.id,l=a?.webId,h=e?.fetch,u=d.useMemo(()=>pi({displayName:i,username:o,id:c},s),[i,c,o,l,s]),g=`${s??""}\0${u.displayName}\0${u.username??""}`,[f,v]=d.useState(),[p,m]=d.useState(!1);d.useEffect(()=>{const S=h;if(r!=="authenticated"||!S||!s)return;let N=!1,x;async function I(k,R){m(!0);try{const y=await ci({info:{webId:R},fetch:k});if(N||!y)return;const T=gi(y.profile?.avatar);let j=T;if(T&&(j=await mi(k,T),x=j?.startsWith("blob:")?j:void 0),N){x&&URL.revokeObjectURL(x);return}v({key:g,value:{displayName:y.displayName??y.username??u.displayName,username:y.username||u.username,avatarUrl:j??u.avatarUrl,avatarSourceUrl:T,note:y.profile?.note||u.note,region:y.profile?.region||u.region,webId:y.webId||u.webId,loading:!1,source:"webid-profile"}})}catch{N||v(void 0)}finally{N||m(!1)}}return I(S,s),()=>{N=!0,x&&URL.revokeObjectURL(x)}},[h,u,g,r,s]);const b=r==="authenticated"?p:!1;return r==="authenticated"&&f?.key===g?{...f.value,loading:b}:{...u,loading:b}}function pi(t,e){const r=t?.username||bi(e)||t?.id;return{displayName:t?.displayName||r||t?.id||"Xpod account",username:r,webId:e,loading:!1,source:"account"}}async function mi(t,e){try{const r=await t(e);if(!r.ok)return e;const s=await r.blob();return URL.createObjectURL(s)}catch{return e}}function gi(t){if(t)try{const e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"?e.href:void 0}catch{return}}function bi(t){if(t)try{const e=new URL(t);return e.pathname.split("/").filter(Boolean).at(0)||e.hostname}catch{return}}const xi=d.createContext(null);function vi({value:t,children:e}){return d.createElement(xi.Provider,{value:t},e)}async function _i(t){const{Parser:e,Writer:r,DataFactory:s}=await ae(async()=>{const{Parser:_,Writer:L,DataFactory:$}=await import("./index-D-LgcKAb.js");return{Parser:_,Writer:L,DataFactory:$}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),{UDFS:a,RDF:i}=await ae(async()=>{const{UDFS:_,RDF:L}=await import("./xpod-remembered-login-YAmn8ZiP.js").then($=>$.bN);return{UDFS:_,RDF:L}},__vite__mapDeps([1,2,3,4,5,6,7])),o=new URL(t.approval),c=new URL(t.decisionBy);if(![o,c].every(_=>["https:","http:"].includes(_.protocol)&&!_.username&&!_.password))throw new Error("Approval and decision identity must be HTTP(S) IRIs without credentials.");if(!["approved","rejected"].includes(t.decision))throw new Error("Invalid approval decision.");const l=o.href;o.hash="";const h=o.href,u=await t.authenticatedFetch(h,{headers:{accept:"text/turtle"},cache:"no-store",redirect:"error"});if(u.status===404)return{status:"not_found"};if(!u.ok)throw new Error(`Approval read failed: HTTP ${u.status}`);const g=u.headers.get("etag"),f=await u.text();if(!g||!/^"[^"\r\n]+"$/.test(g))return{status:"unavailable",reason:"A strong ETag is required for approval decisions."};if(!u.headers.get("content-type")?.toLowerCase().includes("text/turtle"))return{status:"unavailable",reason:"The approval document must be served as Turtle."};const v=new e({baseIRI:h}).parse(f),p=_=>v.filter(L=>L.subject.termType==="NamedNode"&&L.subject.value===l&&L.predicate.value===_).map(L=>L.object);if(!p(i.type).some(_=>_.termType==="NamedNode"&&_.value===a.ApprovalRequest))return{status:"not_found"};const m=p(a.status);if(m.length!==1||m[0].termType!=="Literal"||!["pending","handling"].includes(m[0].value)||p(a.resolvedAt).length)return{status:"not_actionable",reason:"Approval is already decided or has ambiguous state."};if(p(a.assignedTo).some(_=>_.termType!=="NamedNode"||_.value!==c.href))return{status:"not_actionable",reason:"Approval belongs to another decision maker."};const S=t.now??(()=>new Date),N=()=>p(a.expiresAt).some(_=>{const L=Date.parse(_.value);return!Number.isFinite(L)||L<=S().getTime()});if(N())return{status:"not_actionable",reason:"Approval has expired."};const x=p(a.leaseOwner),I=p(a.leaseExpiresAt);if((x.length||I.length)&&(x.length!==1||x[0].termType!=="Literal"||I.length!==1||I[0].termType!=="Literal"||!Number.isFinite(Date.parse(I[0].value))||Date.parse(I[0].value)>S().getTime()))return{status:"conflict",reason:"Approval is being handled by another client."};const k=new Set([a.status,a.decisionBy,a.resolvedAt]),R=v.filter(_=>_.subject.value!==l||!k.has(_.predicate.value)),y=s.namedNode(l);R.push(s.quad(y,s.namedNode(a.status),s.literal(t.decision)),s.quad(y,s.namedNode(a.decisionBy),s.namedNode(c.href)),s.quad(y,s.namedNode(a.resolvedAt),s.literal(S().toISOString(),s.namedNode("http://www.w3.org/2001/XMLSchema#dateTime"))));const T=await new Promise((_,L)=>{const $=new r({format:"Turtle"});$.addQuads(R),$.end((A,V)=>A?L(A):_(V))});if(t.isCurrent&&!t.isCurrent())return{status:"not_actionable",reason:"The current session changed."};if(N())return{status:"not_actionable",reason:"Approval has expired."};const j=await t.authenticatedFetch(h,{method:"PUT",headers:{"content-type":"text/turtle","if-match":g},body:T,redirect:"error"});if(await j.arrayBuffer(),j.status===412)return{status:"conflict",reason:"Another client changed the approval. Refresh before deciding again."};if(!j.ok)throw new Error(`Approval decision failed: HTTP ${j.status}`);return{status:"decided"}}const Ce=Is;function wi(){const t=vr(),e=Ce(),r=e.selectedStorage,s=_t({accountIdentity:t.identity,runtime:e}),a=e.state.status==="authenticated"?e.webId??e.state.webId:void 0,i=$e(),o=Ns(t.idpIndex),c=t.isInitializing?void 0:_r(t.idpIndex),l=c?new URL(c).origin:void 0,h=l?hr(void 0,t.idpIndex):void 0,u=o===!0?h??(i&&i.issuer===l?i.account.email:void 0):void 0;return d.useEffect(()=>{!l||o===!1||!a||!r||!e.currentPod||r.webId===a&&(e.currentPod.webId!==a||e.currentPod.podUrl!==r.storageUrl||i&&!Ss(i,{accountIdentity:t.identity,accountEmail:h,webId:a,selectedStorage:r})||ks({issuer:l,account:{...u?{email:u}:{},...t.identity??{},displayName:s.displayName,...s.username?{username:s.username}:{},...s.avatarSourceUrl??i?.account.avatarUrl?{avatarUrl:s.avatarSourceUrl??i?.account.avatarUrl}:{}},webId:a,storageBinding:r,routeId:Rs}))},[t.identity,l,o,u,h,s.displayName,s.avatarSourceUrl,s.username,i,e.currentPod,r,a]),null}const yi=80,ji=2048;function Ii(){const t=Ce(),e=_t({runtime:t}),r=t.state.status==="authenticated"?t.webId??t.state.webId:void 0,s=t.state.status==="authenticated"?t.currentPod?.podUrl??t.podUrl??t.state.podUrl:void 0,a=d.useMemo(()=>Ni({isLoggedIn:t.state.status==="authenticated",displayName:e.displayName,username:e.username,webId:r,podUrl:s}),[e.displayName,e.username,t.state.status,s,r]);return d.useEffect(()=>{globalThis.xpodDesktop?.setIdentity(a)},[a]),d.useEffect(()=>()=>{globalThis.xpodDesktop?.setIdentity(null)},[]),null}function Ni({isLoggedIn:t,displayName:e,username:r,webId:s,podUrl:a}){if(!t)return null;const i=Wt(e)??Wt(r)??"WebID",o=Ht(s),c=Ht(a);return{label:i,...o?{webId:o}:{},...c?{podUrl:c}:{}}}function Wt(t){if(!t)return;const r=Array.from(t,s=>{const a=s.codePointAt(0);return Si(a)?" ":s}).join("").replace(/\s+/g," ").trim();if(r)return Array.from(r).slice(0,yi).join("").trim()}function Si(t){return t<32||t>=127&&t<=159||t>=8234&&t<=8238||t>=8294&&t<=8297}function Ht(t){if(!(!t||t.length>ji))try{const e=new URL(t);return e.protocol!=="http:"&&e.protocol!=="https:"||e.username||e.password?void 0:e.toString()}catch{return}}function ki({children:t}){const[e,r]=d.useState(!1),s=d.useRef(()=>{});return d.useEffect(()=>{let a=!1,i,o,c=0;async function l(){if(a||i)return;clearTimeout(o);const u=new AbortController;i=u;const g=setTimeout(()=>u.abort(),5e3);let f=!0;try{const v=await fetch("/service/status",{cache:"no-store",signal:u.signal});if(f=v.status<500,v.ok){const p=await v.json().catch(()=>null);Array.isArray(p)&&(f=!p.some(m=>m&&["css","api"].includes(m.name)&&typeof m.status=="string"&&m.status!=="running")),u.signal.aborted&&(f=!1)}else await v.body?.cancel()}catch{f=!1}finally{clearTimeout(g),i=void 0}a||(c=f?0:c+1,r(!f),o=setTimeout(()=>{document.visibilityState!=="hidden"&&l()},f?1e4:Math.min(2e3*2**Math.min(c-1,4),3e4)))}const h=()=>{document.visibilityState!=="hidden"&&l()};return s.current=()=>{l()},window.addEventListener("online",h),window.addEventListener("focus",h),document.addEventListener("visibilitychange",h),l(),()=>{a=!0,clearTimeout(o),i?.abort(),s.current=()=>{},window.removeEventListener("online",h),window.removeEventListener("focus",h),document.removeEventListener("visibilitychange",h)}},[]),n.jsxs("div",{className:"flex h-dvh min-h-0 flex-col",style:{"--xpod-shell-height":"100%"},children:[e&&n.jsxs("section",{role:"alert","aria-label":"Xpod 连接中断",className:"flex shrink-0 flex-wrap items-center gap-x-4 gap-y-2 border-b border-border bg-background px-4 py-2 text-sm",children:[n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"font-medium",children:"Xpod 连接中断"}),n.jsx("span",{className:"ml-2 text-muted-foreground",children:"正在自动重连;你仍可打开这台设备和设置。"}),n.jsxs("details",{className:"text-xs text-muted-foreground",children:[n.jsx("summary",{children:"页面与未完成操作"}),"登录状态和当前页面已保留。未完成的操作不会自动重试,请在连接恢复后确认结果。"]})]}),n.jsx("button",{type:"button",onClick:()=>s.current(),className:"shrink-0 rounded-lg bg-primary px-3 py-2 text-primary-foreground",children:"立即重试"})]}),n.jsx("div",{className:"min-h-0 flex-1",children:t})]})}function Ri(){const t=mr();return d.useEffect(()=>globalThis.xpodDesktop?.onNavigate?.(e=>{const r=new URL(e,window.location.origin);r.origin===window.location.origin&&t(`${r.pathname}${r.search}${r.hash}`)}),[t]),null}const Re="/ai-connections",F={pod:"/pod/models",status:"/device/services",network:"/device/network",aiConnections:"/ai-connections"},Qr={"/dashboard":F.status,"/dashboard/overview":F.status,"/dashboard/status":F.status,"/dashboard/runtime":"/device/runtime","/dashboard/logs":"/device/logs","/dashboard/network":F.network,"/dashboard/usage":"/pod/data","/dashboard/models":F.aiConnections,"/dashboard/pod":F.pod,"/dashboard/services":F.status,"/dashboard/settings":"/device/runtime","/status":F.status,"/status/overview":F.status,"/status/services/gateway":F.status,"/status/services/solid-server":F.status,"/status/services/api-server":F.status,"/status/logs":"/device/logs","/network":F.network,"/network/overview":F.network,"/settings/models":F.aiConnections,"/settings/ai-connections":F.aiConnections,"/settings/ai-config":F.pod,"/settings/pod":F.pod,"/settings/identity-access":"/pod/apps","/settings/storage":"/pod/data","/settings/network":F.network,"/settings/services":F.status,"/settings/system":"/device/runtime","/settings/runtime":"/device/runtime","/ai-config":F.pod,"/ai-config/model-assignments":F.pod,"/ai-config/document-processing":F.pod,"/ai-config/search-indexing":"/pod/search","/ai-config/index-lifecycle":"/pod/search"},jc=[...["/dashboard","/status","/network"].map(t=>({app:"dashboard",basename:t})),...["/settings","/ai-connections","/ai-config","/tasks","/pod","/device","/inbox","/notifications"].map(t=>({app:"settings",basename:t}))];function Pi(t){return Qr[t.replace(/\/$/,"")]??t}const Ci="https://id.undefineds.co/app/xpod-desktop-client.json",Li={client_id:Ci},Kr=1,Ei="xpod.auth.transaction.v1",Ti=600*1e3,Jr=1,xe="xpod.auth.selected-storage.v1",Ai=1440*60*1e3;class E extends Error{code;constructor(e,r){super(r),this.name="XpodLoginTransactionError",this.code=e}}function Ic(t,e={}){const r=e.storage??yt()??wt();if(!r)throw new E("storage_unavailable","Session storage is unavailable");const s=new URL(e.origin??jt()).origin,a=e.storageRoot??s,i=es(t,a,e.storageRoot===void 0),c=(e.now??(()=>Date.now()))(),l={version:Jr,createdAt:c,expiresAt:c+(e.ttlMs??Ai),binding:i,...e.storageRoot===void 0?{}:{storageRoot:ts(e.storageRoot)}};r.setItem(xe,JSON.stringify(l))}function Ui(t={}){return t.storage?We(t.storage,t):We(yt(),t)??We(wt(),t)}function We(t,e){if(!t)return;const r=t.getItem(xe);if(!r)return;const s=()=>t.removeItem(xe);let a;try{a=JSON.parse(r)}catch{s();return}if(!$i(a)){s();return}const i=e.now??(()=>Date.now());if(a.expiresAt<=i()){s();return}let o;try{o=es(a.binding,a.storageRoot??new URL(e.origin??jt()).origin,a.storageRoot===void 0)}catch{s();return}if(e.webId!==void 0&&o.webId!==e.webId){s();return}return o}function He(t={}){t.storage?.removeItem(xe);try{yt()?.removeItem(xe),wt()?.removeItem(xe)}catch{}}function Yr(){const t=globalThis.crypto;if(typeof t?.randomUUID=="function")return t.randomUUID();if(typeof t?.getRandomValues=="function"){const e=new Uint8Array(24);return t.getRandomValues(e),`xpod-${Array.from(e,r=>r.toString(16).padStart(2,"0")).join("")}`}throw new E("storage_unavailable","Secure transaction id generation is unavailable")}function Di(t={}){const e=t.storage??Bi(),r=new URL(t.origin??jt()).origin,s=t.now??(()=>Date.now()),a=t.ttlMs??Ti,i=t.prefix??Ei,o=`${i}.active`,c=f=>`${i}.record.${f}`,l=f=>`${i}.consumed.${f}`,h=f=>{e.getItem(o)===f&&e.removeItem(o),e.removeItem(c(f))},u=(f,v=!0)=>{if(!Qt(f))throw new E("malformed","Transaction id is malformed");if(e.getItem(l(f))==="1")throw new E("consumed","Transaction has already been consumed");if(v&&e.getItem(o)!==f)throw new E("unknown","Transaction is not the active Xpod login transaction");const p=e.getItem(c(f));if(!p)throw v&&e.getItem(o)===f&&e.removeItem(o),new E("unknown","Xpod login transaction was not found");let m;try{m=JSON.parse(p)}catch{throw h(f),new E("malformed","Xpod login transaction is malformed")}if(!Fi(m)||m.transaction.id!==f)throw h(f),new E("malformed","Xpod login transaction is malformed");if(m.expiresAt<=s())throw h(f),new E("expired","Xpod login transaction has expired");try{const b=Vt({...m.transaction,authorizationSurface:"redirect",discovery:"strict"},r);return m.transaction={id:b.id,route:b.route,...b.returnTo===void 0?{}:{returnTo:b.returnTo},...b.prompt===void 0?{}:{prompt:b.prompt},...b.selectedStorage===void 0?{}:{selectedStorage:b.selectedStorage}},m}catch(b){throw h(f),b instanceof E?b:new E("malformed","Xpod login transaction is malformed")}};return{begin:f=>{const v=e.getItem(o);if(v){try{u(v)}catch(x){if(!(x instanceof E&&(x.code==="expired"||x.code==="malformed"||x.code==="unknown")))throw x}if(e.getItem(o)===v)throw new E("already_active","An Xpod login transaction is already pending in this tab")}const p=Qt(f.id)?f.id:Yr(),m=Vt({...f,id:p},r),b=s(),S=b+a,N={version:Kr,createdAt:b,expiresAt:S,transaction:{id:m.id,route:m.route,...m.returnTo===void 0?{}:{returnTo:m.returnTo},...m.prompt===void 0?{}:{prompt:m.prompt},...m.selectedStorage===void 0?{}:{selectedStorage:m.selectedStorage}}};return e.setItem(c(m.id),JSON.stringify(N)),e.setItem(o,m.id),m},readSinglePending(){const f=e.getItem(o);if(f)return Ve(u(f).transaction)},updateSelectedStorage(f,v){const p=u(f),m=Ve(p.transaction),b=Zr(v,r,m.route.storageProvider?.url),S={...p,transaction:{...p.transaction,selectedStorage:b}};e.setItem(c(f),JSON.stringify(S))},consume(f){const v=u(f),p=Ve(v.transaction);return e.removeItem(o),e.removeItem(c(f)),e.setItem(l(f),"1"),p},cancel(f){u(f),e.removeItem(o),e.removeItem(c(f)),e.setItem(l(f),"1")}}}function Vt(t,e){let r;try{r=Ps(t)}catch(i){throw new E("malformed",i instanceof Error?i.message:"Transaction is malformed")}let s;try{s=Cs(r.route,e)}catch(i){throw new E("cross_origin",i instanceof Error?i.message:"Transaction route is not local")}let a;try{a=Ze(r.returnTo)}catch(i){throw new E("mismatch",i instanceof Error?i.message:"Transaction return path is unsafe")}if(r.selectedStorage!==void 0)try{const i=Zr(r.selectedStorage,e,s.storageProvider?.url);return{id:r.id,route:s,selectedStorage:i,authorizationSurface:"redirect",discovery:"strict",...a===void 0?{}:{returnTo:a},...r.prompt===void 0?{}:{prompt:r.prompt}}}catch(i){throw i instanceof E?i:new E("mismatch","Selected storage binding is invalid")}return{id:r.id,route:s,authorizationSurface:"redirect",discovery:"strict",...a===void 0?{}:{returnTo:a},...r.prompt===void 0?{}:{prompt:r.prompt}}}function Zr(t,e,r){if(!t||typeof t.storageUrl!="string"||typeof t.webId!="string"||ht(t.webId))throw new E("malformed","Selected storage binding is malformed");let s,a;try{s=new URL(t.storageUrl),a=new URL(t.webId)}catch{throw new E("malformed","Selected storage binding is malformed")}if(!["http:","https:"].includes(s.protocol)||!["http:","https:"].includes(a.protocol))throw new E("cross_origin","Selected storage binding must use web URLs");if(s.origin!==e||a.origin!==e||r&&s.origin!==new URL(r).origin)throw new E("cross_origin","Selected storage binding is not local to this Xpod");if(s.username||s.password||s.hash||a.username||a.password)throw new E("malformed","Selected storage binding contains unsafe URL data");return{storageUrl:s.href,webId:t.webId,...t.label===void 0?{}:{label:t.label}}}function Ve(t){return{id:t.id,route:t.route,authorizationSurface:"redirect",discovery:"strict",...t.returnTo===void 0?{}:{returnTo:t.returnTo},...t.prompt===void 0?{}:{prompt:t.prompt},...t.selectedStorage===void 0?{}:{selectedStorage:t.selectedStorage}}}function es(t,e,r){if(!t||typeof t.storageUrl!="string"||typeof t.webId!="string"||ht(t.webId))throw new E("malformed","Selected storage binding is malformed");let s,a;try{s=new URL(t.storageUrl),a=new URL(t.webId)}catch{throw new E("malformed","Selected storage binding is malformed")}if(!["http:","https:"].includes(s.protocol)||!["http:","https:"].includes(a.protocol))throw new E("cross_origin","Selected storage binding must use web URLs");if(!Oi(s,e)||r&&a.origin!==new URL(e).origin||s.username||s.password||s.hash||a.username||a.password)throw new E("cross_origin","Selected storage binding is not local to this Xpod");return{storageUrl:s.href,webId:t.webId}}function ts(t){const e=new URL(t);return e.hash="",e.search="",e.pathname.endsWith("/")||(e.pathname+="/"),e.href}function Oi(t,e){const r=new URL(ts(e));if(t.origin!==r.origin)return!1;const s=r.pathname;return t.pathname===s.slice(0,-1)||t.pathname.startsWith(s)}function Qt(t){return typeof t=="string"&&/^[A-Za-z0-9_-]{16,128}$/.test(t)}function Fi(t){if(!t||typeof t!="object")return!1;const e=t;return e.version===Kr&&typeof e.createdAt=="number"&&typeof e.expiresAt=="number"&&!!(e.transaction&&typeof e.transaction=="object")}function $i(t){if(!t||typeof t!="object")return!1;const e=t;return e.version===Jr&&typeof e.createdAt=="number"&&typeof e.expiresAt=="number"&&!!(e.binding&&typeof e.binding=="object")}function Bi(){try{if(typeof window<"u"&&window.sessionStorage)return window.sessionStorage}catch{}throw new E("storage_unavailable","Session storage is unavailable")}function wt(){try{if(typeof window<"u"&&window.sessionStorage)return window.sessionStorage}catch{}}function yt(){try{if(typeof window<"u"&&window.localStorage)return window.localStorage}catch{}}function jt(){return typeof window<"u"&&window.location.origin!=="null"?window.location.origin:"http://localhost"}function zi({collection:t,assertCurrent:e,accountIndex:r,fetch:s=window.fetch.bind(window)}){const a=async(...l)=>{e();const h=await s(...l);try{e()}catch(u){throw h.body?.cancel().catch(()=>{}),u}return h},i=new Set,o=async l=>{e();const h=await mt(l,a,r);if(e(),!h||!new URL(h).pathname.startsWith("/.account/"))throw new Error("客户端凭据地址不属于可信账号服务。");return h},c=(l,h,u)=>(e(),a(l,{method:h,credentials:"include",redirect:"error",headers:gt({Accept:"application/json",...u?{"Content-Type":"application/json"}:{}},r),...u?{body:JSON.stringify(u)}:{}}));return{async create({name:l,webId:h}){if(!l.trim()||!h)throw new Error("创建客户端凭据需要名称和当前 WebID。");const u=await c(await o(t),"POST",{name:l.trim(),webId:h});if(!u.ok)throw new Error(`创建客户端凭据失败(HTTP ${u.status})。`);const g=await u.json();if(e(),typeof g.id!="string"||!g.id||g.id.includes(":")||typeof g.secret!="string"||!g.secret||typeof g.resource!="string"||!g.resource)throw new Error("账号服务未返回有效的客户端凭据。");const f=await o(g.resource),v=new TextEncoder().encode(`${g.id}:${g.secret}`),p=btoa(Array.from(v,m=>String.fromCharCode(m)).join(""));return e(),{apiKey:`sk-${p}`,clientId:g.id,resource:f}},async list(){const l=await c(await o(t),"GET");if(!l.ok)throw new Error(`读取客户端凭据失败(HTTP ${l.status})。`);const h=await l.json();e();const u=Object.entries(h.clientCredentials??{}),g=await Promise.all(u.map(async([f,v])=>{const p=await o(String(v)),m=await c(p,"GET");if(m.status===404||m.status===410)return;if(!m.ok)throw new Error(`读取客户端凭据失败(HTTP ${m.status})。`);const b=await m.json();if(e(),!(b.id!==f||typeof b.webId!="string"||!b.webId))return{clientId:f,label:f,resource:p,webId:b.webId}}));return e(),g.filter(f=>f!==void 0)},async revoke({clientId:l,resource:h,webId:u}){const g=await o(h),f=JSON.stringify([g,l,u]),v=await c(g,"GET");if(v.status===404||v.status===410){if(i.has(f))return;throw new Error("无法确认客户端凭据已撤销,请检查当前 Account 登录;Key 记录已保留。")}if(!v.ok)throw new Error(`读取客户端凭据失败(HTTP ${v.status})。`);const p=await v.json();if(e(),p.id!==l||p.webId!==u)throw new Error("客户端凭据与当前 Key 或 WebID 不匹配,未执行删除。");const m=await c(g,"DELETE");if(!m.ok)throw new Error(`撤销客户端凭据失败(HTTP ${m.status})。`);i.add(f)}}}class ee extends Error{code;constructor(e,r){super(r),this.name="AccountStorageBindingsError",this.code=e}}async function Mi(t){const e=qi(t.origin),r=t.controls?.account?.bindings;if(typeof r!="string"||r.trim()==="")throw new ee("missing-control","Account storage bindings control is unavailable");const s=t.fetchImpl??fetch,a=Gi(r,e),i=a.origin===e?a.href:await mt(a.href,s,t.trustedAccountIndex);if(!i)throw new ee("cross-origin","Account storage bindings control is not hosted by this Xpod");const o=gt({Accept:"application/json",...t.headers});let c;try{c=await s(i,{headers:o,credentials:"include"})}catch(h){throw new ee("request-failed",h instanceof Error?h.message:"Failed to load Account storage bindings")}if(c.status===401||c.status===403)throw new ee("forbidden","Account storage bindings require an authenticated Account");if(!c.ok)throw new ee("request-failed",`Account storage bindings request failed (${c.status})`);let l;try{l=await c.json()}catch{throw new ee("invalid-response","Account storage bindings response is not valid JSON")}return Xi(l,a.origin,Vi(a,t.trustedAccountIndex,e))}function Xi(t,e,r=!1){if(!Kt(t)||!Array.isArray(t.bindings))throw new ee("invalid-response","Account storage bindings response is malformed");const s=[],a=new Set;for(const i of t.bindings){if(!Kt(i)||typeof i.webId!="string"||typeof i.storageUrl!="string")throw new ee("invalid-response","Account storage binding row is malformed");const o=Wi(i.webId),c=Hi(i.storageUrl,r?void 0:e);if(!o||!c)throw new ee("cross-origin","Account storage binding is outside the trusted storage scope");const l={webId:o,storageUrl:c,...typeof i.label=="string"?{label:i.label}:{}},h=`${l.webId}
4
+ ${l.storageUrl}`;a.has(h)||(a.add(h),s.push(l))}return s}function qi(t){try{return new URL(t??(typeof window>"u"?"http://localhost":window.location.origin)).origin}catch{throw new ee("cross-origin","Current Xpod origin is invalid")}}function Gi(t,e){try{const r=new URL(t,e);if(!["http:","https:"].includes(r.protocol)||r.username||r.password||r.hash)throw new Error("unsafe control URL");return r}catch{throw new ee("cross-origin","Account storage bindings control is not a valid URL")}}function Wi(t){if(!ht(t))try{const e=new URL(t);return!["http:","https:"].includes(e.protocol)||e.username||e.password?void 0:t}catch{return}}function Hi(t,e){try{const r=new URL(t.trim());return e!==void 0&&r.origin!==e||!["http:","https:"].includes(r.protocol)||r.username||r.password||r.search||r.hash?void 0:(r.pathname=r.pathname.endsWith("/")?r.pathname:`${r.pathname}/`,r.href)}catch{return}}function Vi(t,e,r){if(!e)return!1;try{const s=new URL(e,r);return s.pathname.startsWith("/.account/")&&t.origin===s.origin&&t.pathname.startsWith("/.account/")}catch{return!1}}function Kt(t){return!!(t&&typeof t=="object"&&!Array.isArray(t))}function Qi(t){let e;const r=t.webId,s=t.name?.trim()||"Xpod 会话凭据";let a,i,o=!1;const c=async()=>{if(!r||o)return;const h=t.capability??await t.resolveCapability?.();if(!h||o)return;e=h;const u=await h.create({name:s,webId:r});if(o){await h.revoke({clientId:Jt(u.apiKey),resource:u.resource,webId:r}).catch(()=>{});return}return a={apiKey:u.apiKey,clientId:Jt(u.apiKey),resource:u.resource},a},l=async()=>a||(i??=c().finally(()=>{i=void 0}),await i);return{async authorization(){if(o)return;const h=await l();return!o&&h?`Bearer ${h.apiKey}`:void 0},async apiKey(){if(o)return;const h=await l();return o?void 0:h?.apiKey},clientId(){return a?.clientId},async release(){o=!0;const h=a;a=void 0;const u=e;!h||!u||!r||await u.revoke({clientId:h.clientId,resource:h.resource,webId:r})}}}function Jt(t){const e=t.startsWith("sk-")?t.slice(3):t;try{const r=atob(e),s=r.indexOf(":");return s>0?r.slice(0,s):""}catch{return""}}function Yt(t,e,r=t,s,a){return e?async(i,o)=>{const c=(o?.method??(i instanceof Request?i.method:"GET")).toUpperCase(),l=await t(i,o);if(!["GET","HEAD"].includes(c)||!Ji(i,s,a)||l.status!==403||!await Ki(l))return l;const h=await e().catch(()=>{});if(!h)return l;const u=new Headers(o?.headers??(i instanceof Request?i.headers:void 0));return u.set("authorization",h),u.delete("dpop"),r(i,{...o,headers:u})}:t}async function Ki(t){try{const e=await t.clone().json();return e?.error==="service_access_missing"||!!(e?.error&&typeof e.error=="object"&&"code"in e.error&&e.error.code==="service_access_missing")}catch{return!1}}function Ji(t,e,r){if(!e)return!1;try{const s=new URL(t instanceof Request?t.url:String(t),e);if(s.username||s.password||s.hash||!["http:","https:"].includes(s.protocol)||!(s.pathname.startsWith("/api/")||s.pathname.startsWith("/v1/")))return!1;const a=new URL(e).origin;if(s.origin===a)return!0;if(!r)return!1;const i=new URL(r(s.href));return i.origin===a&&!i.username&&!i.password&&i.pathname===s.pathname&&i.search===s.search&&i.hash===s.hash}catch{return!1}}async function Yi(t){if(!t.accountIndex||!t.webId)return;t.assertCurrent(t.webId);const e=t.binding??await Zi(t)??await eo(t);if(t.assertCurrent(t.webId),!(!e||e.webId!==t.webId))return e.assertCurrent(),zi({collection:e.collection,assertCurrent:()=>{t.assertCurrent(t.webId),e.assertCurrent()},accountIndex:t.accountIndex,...e.fetch?{fetch:e.fetch}:{}})}async function Zi(t){const e=t.accountIndex,r=t.webId;try{const l=new URL(e);if(!["http:","https:"].includes(l.protocol)||l.username||l.password||l.pathname!=="/.account/"||l.search||l.hash)return}catch{return}let s;try{s=await t.accountFetch(e,{headers:gt({accept:"application/json"},e),credentials:"include",redirect:"error"})}catch{return}if(!s.ok)return;const a=await s.json().catch(()=>{}),i=a?.controls?.account?.clientCredentials;if(typeof i!="string"||!i)return;try{for(const l of[i,a?.controls?.account?.bindings]){if(typeof l!="string"||!l)return;const h=new URL(l,e);if(h.origin!==new URL(e).origin||!h.pathname.startsWith("/.account/")||h.username||h.password||h.hash)return}}catch{return}const o=await Mi({controls:a?.controls,fetchImpl:t.accountFetch,trustedAccountIndex:e}).catch(()=>{});if(t.assertCurrent(r),!o?.some(l=>l.webId===r))return;const c=await mt(i,t.accountFetch,e);return c?{collection:c,webId:r,assertCurrent:()=>t.assertCurrent(r),fetch:t.accountFetch}:void 0}async function eo(t){if(!t.sessionFetch)return;const e=t.webId,r=Tn({accountIndex:t.accountIndex,fetch:t.sessionFetch,assertCurrent:()=>t.assertCurrent(e)}),s=await An({accountIndex:t.accountIndex,webId:e,fetch:r}).catch(()=>{});if(s)return{collection:s.collection,webId:s.webId,assertCurrent:()=>t.assertCurrent(s.webId),fetch:r}}function to({children:t,value:e}){const r=e??Ls(),s=d.useMemo(()=>r.storage??{},[r]),a=d.useMemo(()=>so(r),[r]),[i,o]=d.useState(a.snapshot),[c,l]=d.useState(a.issuer),[h,u]=d.useState(),[g,f]=d.useState(),[v,p]=d.useState(),[m,b]=d.useState(0),[S,N]=d.useState(),x=d.useRef(i),I=d.useRef(a.rejected),k=d.useRef(void 0),R=d.useCallback(async(w,P)=>I.current?Promise.reject(Zt):P===void 0?r.session.fetch(w):r.session.fetch(w,P),[r.session]),y=d.useMemo(()=>i.status==="authenticated"?r.session.createAuthenticatedFetch(i.webId):void 0,[r.session,i]),T=d.useCallback(async(w,P)=>{if(!y||I.current)throw Zt;return P===void 0?y(w):y(w,P)},[y]),j=d.useCallback(()=>{if(k.current)return k.current;const w=(async()=>{try{await r.session.logout();const P=r.session.getSnapshot();(P.status!=="authenticated"||et(P,r.getIssuer(),r.getExpectedIssuer?.()??window.location.origin))&&(I.current=!1)}catch{}finally{const P={status:"anonymous"};r.pod.clear(),He({storage:s.selectedStorage}),Pt(s.issuer),r.setIssuer(void 0),x.current=P,o(P),l(void 0),u(void 0),f(void 0),p(void 0),N(void 0)}})().finally(()=>{k.current===w&&(k.current=void 0)});return k.current=w,w},[r,s.issuer,s.selectedStorage]),_=d.useContext(bt),L=_?.idpIndex,$=_?.registerAccountSession;d.useLayoutEffect(()=>{if(!(!$||i.status!=="authenticated"||!c||I.current))return $({issuer:c,fetch:T,assertCurrent:()=>{if(I.current||r.session.getSnapshot()!==i||r.getIssuer()!==c)throw new Error("Solid 会话已改变,请重新打开账号操作。")}})},[T,c,$,r,i]);const A=i.status==="authenticated"?i.webId:void 0,V=_?.controls?.account?.clientCredentials,K=_?.identity?.webId,te=_?.bindAccountCapability,J=d.useMemo(()=>V&&K&&K===A&&te?{collection:V,webId:K,assertCurrent:te(),fetch:ye}:void 0,[V,K,te,A]),z=d.useMemo(()=>{const w=()=>{if(r.session.getSnapshot()!==i)throw new Error("Solid 会话已改变,请重新打开客户端凭据操作。")};return Qi({webId:A,resolveCapability:()=>Yi({accountIndex:L,webId:A,binding:J,accountFetch:ye,sessionFetch:y,assertCurrent:w})})},[J,L,y,A,r.session,i]),B=d.useRef(void 0);d.useEffect(()=>(B.current?.credential===z&&(B.current.cancelled=!0),()=>{const w={credential:z,cancelled:!1};B.current=w,queueMicrotask(()=>{w.cancelled||z.release().catch(()=>{})})}),[z]);const H=d.useCallback((w,P)=>Yt(T,()=>z.authorization(),r.transportFetch??ye,window.location.origin,r.resolveLocalUrl)(w,P),[T,z,r]),re=d.useCallback((w,P)=>Yt(R,()=>z.authorization(),r.transportFetch??ye,window.location.origin,r.resolveLocalUrl)(w,P),[R,z,r]),se=d.useMemo(()=>({...r.session,fetch:re,getSnapshot:()=>x.current}),[re,r.session]);d.useEffect(()=>{const w=C=>{const X=r.getIssuer();if(!et(C,X,r.getExpectedIssuer?.()??window.location.origin)){I.current=!0,j();return}C.status==="authenticated"&&(I.current=!1);const U=x.current;x.current=C,o(C),l(X),C.status!=="authenticated"?(r.setLocalPodRoutes?.(void 0),r.setLocalPodRoutesRefresh?.(void 0),u(void 0),C.status!=="expired"&&f(void 0),p(void 0),N(void 0),r.pod.clear()):U!==C&&(u(void 0),f(void 0),p(void 0),N(void 0),r.pod.clear(U.status==="authenticated"?{webId:U.webId}:void 0))},P=r.session.subscribe(w);return w(r.session.getSnapshot()),P},[j,r,s]),d.useEffect(()=>{I.current&&j()},[j]),d.useEffect(()=>{if(i.status!=="authenticated")return;let w=!1;const P=new AbortController,C=Ui({storage:s.selectedStorage,origin:typeof window>"u"?void 0:window.location.origin,webId:i.webId}),X={webId:i.webId,...C?{podUrl:C.storageUrl}:{},fetch:H};return(async()=>{try{const U=r.getProvisionRouteStatus?.()??await Es(fetch,{signal:P.signal});if(w)return;r.setLocalPodRoutes?.(Ct(C?.storageUrl??U.storageRoot,U));const q=await r.pod.open(X),Y=Ct(q.podUrl,U);if(w)return;if(r.setLocalPodRoutes?.(Y),r.setLocalPodRoutesRefresh?.(async()=>{const O=await Ts(q.podUrl,fetch,{signal:P.signal});w||r.setLocalPodRoutes?.(O)}),!w){if(C&&(q.webId!==C.webId||!no(q.podUrl,C.storageUrl))){He({storage:s.selectedStorage}),u(void 0),f(void 0),p({webId:i.webId,error:new Error("Selected Pod binding mismatch")});return}u(q),f(C??{webId:q.webId,storageUrl:q.podUrl}),p(void 0)}}catch(U){w||p({webId:i.webId,error:U instanceof Error?U:new Error(String(U))})}})(),()=>{w=!0,P.abort(),r.setLocalPodRoutesRefresh?.(void 0)}},[H,m,r,s.selectedStorage,i]);const de=d.useCallback(()=>{p(void 0),b(w=>w+1)},[]),D=i.status==="authenticated"?i.webId:void 0;d.useEffect(()=>{if(!D)return;let w=!1;return ao(T).then(P=>{!w&&r.session.getSnapshot().status==="authenticated"&&r.session.getSnapshot().webId===D&&N(P)}),()=>{w=!0}},[T,D,r]);const ne=d.useMemo(()=>{const w=c??r.getIssuer(),P=i.status==="authenticated"&&v?.webId===i.webId?v:void 0,C=As(i,h,w);return{session:se,pod:r.pod,fetch:H,transportFetch:r.transportFetch??ye,state:C.status==="error"?{...C,error:Fs(C.error)}:C,webId:C.webId,podUrl:C.podUrl,issuer:C.issuer,currentPod:h,selectedStorage:g,...P?{podError:P}:{},retryPodOpen:de,aiClientConfiguration:S,resolveLocalUrl:X=>r.resolveLocalUrl(X),requestPodAuthorization:()=>z.authorization(),requestPodApiKey:()=>z.apiKey(),login:async X=>{const U=Us(X),q=await Ds(U.route.identityProvider.url,fetch),Y=q.oidcIssuer;if(!Y)throw new TypeError("Xpod login route has no valid issuer");const O=new URL("/auth/callback",window.location.origin),oe=globalThis.xpodDesktop?Li.client_id:void 0;try{await r.session.login({...oe?{clientId:oe}:{},oidcIssuer:Y,redirectUrl:O.toString(),handleRedirect:ce=>{r.setIssuer(Y),l(Y);const ve=new URL(ce);U.prompt?ve.searchParams.set("prompt",U.prompt):oe&&ve.searchParams.get("prompt")==="consent"&&ve.searchParams.delete("prompt"),window.location.assign(q.provisionCode?Os(ve.href,q.provisionCode):ve.href)}}),r.setIssuer(Y),l(Y)}catch(ce){throw console.error("[XpodSolidRuntimeProvider] WebID login failed",ce,ce instanceof Error?ce.cause:void 0),ce}},logout:async()=>{await z.release().catch(()=>{}),await r.session.logout(),r.pod.clear(),He({storage:s.selectedStorage}),Pt(s.issuer),u(void 0),f(void 0),N(void 0)}}},[S,H,h,se,c,v,z,de,r,s,g,i]);return n.jsx(vi,{value:{session:se,pod:r.pod,currentPod:h},children:n.jsx(fr.Provider,{value:ne,children:t})})}const ro={status:"anonymous"},Zt=new Error("Xpod session is unavailable"),ye=(t,e)=>globalThis.fetch(t,e);function so(t){const e=t.session.getSnapshot(),r=t.getIssuer();return et(e,r,t.getExpectedIssuer?.()??window.location.origin)?{snapshot:e,issuer:r,rejected:!1}:{snapshot:ro,issuer:void 0,rejected:!0}}function no(t,e){try{return new URL(t).href===new URL(e).href}catch{return t===e}}async function ao(t){try{const e=new URL("/api/ai/client-configuration/capability",window.location.href).toString(),r=await t(e,{method:"GET",credentials:"include",headers:{accept:"application/json"}});if(!r.ok||!r.headers.get("content-type")?.includes("application/json"))return await r.arrayBuffer().catch(()=>{}),Qe();const s=await r.json();if(io(s)&&s.available===!0&&s.authority==="local-filesystem")return{available:!0,authority:"local-filesystem",manualInstructions:typeof s.manualInstructions=="string"?s.manualInstructions:Qe().manualInstructions}}catch{}return Qe()}function Qe(){return{available:!1,manualInstructions:"manual client setup is available"}}function io(t){return!!(t&&typeof t=="object"&&!Array.isArray(t))}function oo({children:t}){return d.useContext(vn)?n.jsx(n.Fragment,{children:t}):n.jsx(_n,{children:t})}function co(t){const e=async(r,s="GET",a,i)=>{const o=await t.fetch(`${(t.baseUrl??"").replace(/\/$/,"")}/api/tasks${r}${i?`?id=${encodeURIComponent(i)}`:""}`,{method:s,headers:a===void 0?void 0:{"Content-Type":"application/json"},body:a===void 0?void 0:JSON.stringify(a)});if(!o.ok){const c=await o.json().catch(()=>{});throw new Error(o.status===401?"登录已失效,请重新登录":o.status===403?"暂时无法访问任务,请检查连接与授权":o.status>=500?"任务服务暂时不可用,请稍后重试":c?.error&&/[\u4e00-\u9fff]/.test(c.error)?c.error:"任务操作未完成,请检查输入后重试")}return o.json()};return{resumeRun:(r,s)=>e("/resume","POST",{approval:s},r),selection:r=>e("/selection","GET",void 0,r),list:()=>e(""),create:r=>e("","POST",r),update:(r,s)=>e("","PATCH",s,r),pause:(r,s)=>e("/pause","POST",{paused:s},r),run:r=>e("/run","POST",{},r),runs:r=>e("/runs","GET",void 0,r),steps:r=>e("/steps","GET",void 0,r),stop:r=>e("/stop","POST",{},r)}}const rs=d.createContext(null);function ss(){return d.useContext(rs)}function Le(){const t=ss();if(!t)throw new Error("ShellStateProvider is required");return t}async function lo({webId:t,podUrl:e,authenticatedFetch:r}){const s=new URL("/",e).origin,a=await r(`${s}/api/pod/settings/status`,{method:"GET",credentials:"include",headers:{accept:"application/json"}});if(!a.ok)throw await a.arrayBuffer(),new Error("Pod settings request failed. Please try again.");if(!a.headers.get("content-type")?.includes("application/json"))throw await a.arrayBuffer(),new Error("Pod settings request failed. Please try again.");const i=await a.json();if(i.identity?.webId!==t)throw new Error("Pod settings response does not match the current Solid session.");return i}const De=()=>({attention:[],activity:[],inProgress:[],inbox:[]});function uo(t,e=Date.now()){return["pending","handling"].includes(t.status)&&(!t.expiresAt||new Date(t.expiresAt).getTime()>e)}const Ke=t=>t?new Date(t).toISOString():"",ct=t=>`/tasks?run=${encodeURIComponent(t.id)}`;function ho(t){if(!t.metadata||typeof t.metadata!="object")return;const e=t.metadata.waitingTool;if(!e||typeof e!="object")return;const r=e.requestId;return typeof r=="string"?r:void 0}function ns(t,e){return!!(t.thread&&t.toolCallId&&t.thread===e.thread&&t.toolCallId===ho(e))}function lt(t,e){return e.status==="waiting_input"&&ns(t,e)}function fo(t,e,r){const s=`approval=${encodeURIComponent(t.id)}`;if(e.some(i=>i.object===t.id))return`/inbox?${s}`;const a=r.find(i=>lt(t,i));return a?`${ct(a)}&${s}`:`/inbox?${s}`}function po({approvals:t,inbox:e,runs:r,tasks:s}){const a=new Set(["completed","failed","cancelled"]),i=t.filter(o=>{if(!uo(o))return!1;const c=r.filter(l=>ns(o,l));return c.length===0||c.some(l=>!a.has(l.status))});return{attention:[...i.map(o=>({id:o.id,approvalId:o.id,thread:o.thread||void 0,run:r.find(c=>lt(o,c))?.id,title:o.toolName||"访问申请",kind:"approval",href:fo(o,e,r),risk:o.risk,toolName:o.toolName,expiresAt:Ke(o.expiresAt)||void 0})),...r.filter(o=>["failed","waiting_input"].includes(o.status)).map(o=>{const c=t.find(l=>["approved","rejected"].includes(l.status)&&lt(l,o));return{id:o.id,run:o.id,thread:o.thread||void 0,resumeApproval:c?.id,title:o.status==="failed"?"运行失败":c?"审批已保存,运行待处理":"运行在等你确认",kind:"run",href:ct(o)}})],activity:s.map(o=>({id:`task:${o.id}`,title:`新建任务:${o.title||"未命名任务"}`,href:`/tasks?task=${encodeURIComponent(o.id)}`,createdAt:Ke(o.createdAt)})).sort((o,c)=>c.createdAt.localeCompare(o.createdAt)),inProgress:r.filter(o=>o.status==="running").map(o=>({id:o.id,title:o.prompt||"任务运行中",href:ct(o)})),inbox:e.map(o=>({id:o.id,actor:o.actor||void 0,object:o.object,createdAt:Ke(o.createdAt),approvalId:i.find(c=>c.id===o.object)?.id})).sort((o,c)=>c.createdAt.localeCompare(o.createdAt))}}function mo(t){return{...t,activity:t.activity.map(e=>({...e,read:!0}))}}async function go(t){const[e,r,s,a]=await Promise.all([t.select().from(Lt),t.select().from(Et),t.select().from(Tt),t.select().from(At)]);return po({approvals:e.map(i=>({...i,id:t.resolveRowIri(Lt,{...i})})),inbox:r.map(i=>({...i,id:t.resolveRowIri(Et,{...i})})),runs:s.map(i=>({...i,id:t.resolveRowIri(Tt,{...i})})),tasks:a.map(i=>({...i,id:t.resolveRowIri(At,{...i})}))})}async function bo(t,e,r,s,a=()=>!0){const i=await _i({approval:e,decisionBy:r,decision:s,authenticatedFetch:t,isCurrent:a});if(i.status==="decided")return;const o={conflict:"申请已被其他入口处理,请刷新后查看。",not_found:"申请不存在,请刷新。",not_actionable:"申请已处理、过期或当前身份无权处理,请刷新。",unavailable:"此 Pod 尚不支持安全审批,请稍后重试。"};throw new Error(o[i.status])}function xo({children:t}){const e=Ce();return n.jsx(vo,{runtime:e,children:t},`${e.state.status}|${e.webId||""}|${e.currentPod?.podUrl||""}`)}function vo({children:t,runtime:e}){const r=d.useMemo(()=>co({fetch:e.fetch,baseUrl:window.location.origin}),[e.fetch]),[s,a]=d.useState(De),[i,o]=d.useState(!1),[c,l]=d.useState(),[h,u]=d.useState([]),g=d.useRef(new Set),[f,v]=d.useState(0),p=d.useRef(new Set),m=d.useRef(!0),b=d.useCallback(()=>v(x=>x+1),[]);d.useEffect(()=>(m.current=!0,()=>{m.current=!1}),[]),d.useEffect(()=>{let x=!0,I=!1;async function k(){if(!I){I=!0,o(!0);try{const[y,T,j]=await Promise.allSettled([e.state.status==="authenticated"&&e.currentPod?go(e.currentPod.database):Promise.resolve(De()),On(),e.state.status==="authenticated"&&e.webId&&e.currentPod?lo({webId:e.webId,podUrl:e.currentPod.podUrl,authenticatedFetch:e.fetch}):Promise.resolve(null)]),_=y.status==="fulfilled"?y.value:De();if(T.status==="fulfilled"&&T.value?.status==="fail"&&_.attention.push({id:"device:network",kind:"network",title:"设备网络需要检查",href:"/device/network"}),j.status==="fulfilled"&&j.value?.storage.status==="available"){const L=j.value.storage;L.limits.storageLimitBytes&&L.usage.storageBytes/L.limits.storageLimitBytes>=.8&&_.attention.push({id:"pod:storage",kind:"quota",title:"Pod 空间快到上限",href:"/pod/data"})}x&&(a(L=>{const $=y.status==="fulfilled"?_:{...L,attention:[...L.attention.filter(A=>A.kind!=="network"&&A.kind!=="quota"),..._.attention]};return{...$,activity:$.activity.map(A=>({...A,read:p.current.has(A.id)}))}}),l(y.status==="rejected"?"Pod 通知读取失败,请重试":void 0))}catch{x&&l("通知读取失败,请重试")}finally{I=!1,x&&o(!1)}}}k();const R=window.setInterval(()=>{k()},3e4);return window.addEventListener("focus",b),window.addEventListener("xpod:pod-changed",b),()=>{x=!1,window.clearInterval(R),window.removeEventListener("focus",b),window.removeEventListener("xpod:pod-changed",b)}},[e.currentPod,e.webId,e.fetch,e.state.status,f,b]),d.useEffect(()=>{globalThis.xpodDesktop?.publishAttention?.(s)},[s]),d.useEffect(()=>()=>{globalThis.xpodDesktop?.publishAttention?.(De())},[]);const S=d.useCallback(async(x,I)=>{if(!(!m.current||g.current.has(x))){g.current.add(x),u(k=>k.map(R=>R.approvalId===x?{...R,busy:!0}:R));try{await r.resumeRun(I,x),m.current&&(u(k=>k.filter(R=>R.approvalId!==x)),b())}catch{m.current&&u(k=>[...k.filter(R=>R.approvalId!==x),{approvalId:x,run:I,message:"决定已保存,运行处理失败,请重试。"}])}finally{g.current.delete(x)}}},[r,b]),N=d.useCallback(async(x,I)=>{if(e.state.status!=="authenticated"||!e.currentPod||!e.webId)throw new Error("请先登录并打开 Pod。");const k=s.attention.find(R=>R.approvalId===x)?.run;await bo(e.fetch,x,e.webId,I,()=>m.current),m.current&&(a(R=>({...R,attention:R.attention.filter(y=>y.approvalId!==x),inbox:R.inbox.map(y=>y.approvalId===x?{...y,approvalId:void 0}:y)})),k&&await S(x,k),b())},[e.currentPod,e.webId,e.fetch,e.state.status,s.attention,S,b]);return d.useEffect(()=>globalThis.xpodDesktop?.onApprovalDecision?.(({approvalId:x,decision:I})=>{N(x,I).catch(k=>{m.current&&l(k instanceof Error?k.message:"决定保存失败,请重试")})}),[N]),n.jsx(rs.Provider,{value:{snapshot:s,loading:i,error:c,refresh:b,decide:N,resumeFailures:h,retryResume:S,markAllRead(){s.activity.forEach(x=>p.current.add(x.id)),a(mo)}},children:t})}function er({item:t}){const{decide:e}=Le(),[r,s]=d.useState(!1),[a,i]=d.useState("");async function o(c){if(t.approvalId){s(!0);try{await e(t.approvalId,c),i("决定已保存。")}catch(l){i(l instanceof Error?l.message:"保存失败,请重试。")}finally{s(!1)}}}return n.jsxs("div",{className:"space-y-2 rounded-md border border-border p-3 text-sm leading-normal",children:[n.jsx("p",{className:"font-medium",children:t.title}),n.jsxs("p",{className:"text-xs leading-normal text-muted-foreground",children:["风险:",{low:"低",medium:"中",high:"高"}[t.risk||""]||t.risk||"未说明",t.expiresAt?` · 有效至 ${new Date(t.expiresAt).toLocaleString("zh-CN")}`:""]}),n.jsxs("div",{className:"flex flex-wrap gap-2",children:[n.jsx("button",{disabled:r,onClick:()=>{o("approved")},className:"rounded bg-primary px-2 py-1 text-primary-foreground",children:"只这一次"}),n.jsx("button",{disabled:!0,title:"长期授权待接入",className:"rounded border px-2 py-1 opacity-50",children:"以后都允许 · 待接入"}),n.jsx("button",{disabled:r,onClick:()=>{o("rejected")},className:"rounded border px-2 py-1",children:"拒绝"})]}),n.jsx("p",{className:"text-xs leading-normal text-muted-foreground",children:"这次决定只对当前申请有效。"}),a&&n.jsx("p",{role:"status",children:a})]})}function as({run:t,recoveryApproval:e}){const{snapshot:r,resumeFailures:s,retryResume:a}=Le(),i=s.filter(c=>!t||c.run===t),o=r.attention.filter(c=>c.resumeApproval&&c.run&&(!t||c.run===t));for(const c of o)i.some(l=>l.approvalId===c.resumeApproval)||i.push({approvalId:c.resumeApproval,run:c.run,message:"审批决定已保存,可以继续处理这次运行。"});return t&&e&&!i.some(c=>c.approvalId===e)&&i.push({approvalId:e,run:t,message:"审批决定已保存,可以继续处理这次运行。"}),n.jsx(n.Fragment,{children:i.map(c=>n.jsx(Nr,{tone:"neutral",role:"alert",className:"my-2",action:n.jsx("button",{disabled:c.busy,className:"underline",onClick:()=>{a(c.approvalId,c.run)},children:c.busy?"正在重试…":"重试处理运行"}),children:c.message},c.approvalId))})}function is(){const{snapshot:t}=Le(),[e]=wn(),r=t.attention.find(a=>a.approvalId===e.get("approval")),s=r&&!t.inbox.some(a=>a.approvalId===r.approvalId);return n.jsxs(n.Fragment,{children:[n.jsx(as,{}),s&&n.jsx("div",{className:"mb-4",children:n.jsx(er,{item:r})}),t.inbox.length?n.jsx("ul",{className:"space-y-3",children:t.inbox.map(a=>{const i=t.attention.find(o=>o.approvalId===a.approvalId&&a.approvalId);return n.jsxs("li",{className:"space-y-2 border-b border-border pb-3",children:[n.jsxs("p",{className:"break-all text-xs leading-normal text-muted-foreground",children:[a.actor||"未知发送者"," · ",new Date(a.createdAt).toLocaleString("zh-CN")]}),i?n.jsx(er,{item:i}):n.jsx("a",{className:"break-all text-sm leading-normal underline",href:/^https?:\/\//.test(a.object)?a.object:void 0,target:"_blank",rel:"noreferrer",children:a.object})]},a.id)})}):n.jsx("p",{className:"py-6 text-sm leading-normal text-muted-foreground",children:"收件箱是空的"})]})}function os({close:t=()=>{}}){const{snapshot:e,markAllRead:r}=Le();return n.jsxs("div",{className:"space-y-5",children:[n.jsx(as,{}),n.jsxs("section",{children:[n.jsx("h3",{className:"mb-2 text-sm leading-normal font-medium",children:"需要你处理"}),e.attention.length?n.jsx("ul",{className:"space-y-2",children:e.attention.map(s=>n.jsx("li",{children:n.jsxs(rt,{onClick:t,to:s.href,className:"block rounded-md border border-border p-3 text-sm leading-normal hover:bg-accent",children:[s.title," ›"]})},s.id))}):n.jsx("p",{className:"text-sm leading-normal text-muted-foreground",children:"没有待处理事项"})]}),n.jsxs("section",{children:[n.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[n.jsx("h3",{className:"text-sm leading-normal font-medium",children:"动态"}),n.jsx("button",{className:"text-xs leading-normal text-muted-foreground",onClick:r,children:"全部已读"})]}),e.activity.length?n.jsx("ul",{className:"space-y-2",children:e.activity.map(s=>n.jsx("li",{children:n.jsx(rt,{to:s.href,onClick:t,className:`block text-sm leading-normal ${s.read?"text-muted-foreground":"font-medium"}`,children:s.title})},s.id))}):n.jsx("p",{className:"text-sm leading-normal text-muted-foreground",children:"暂无动态"})]})]})}function _o(){const{snapshot:t,loading:e,error:r,refresh:s}=Le(),[a,i]=d.useState(null),o=d.useRef(null),c=d.useRef(null),l=d.useRef(null);return d.useEffect(()=>{if(!a)return;c.current?.focus();function h(g){g.key==="Escape"&&(i(null),l.current?.focus())}function u(g){o.current?.contains(g.target)||i(null)}return document.addEventListener("keydown",h),document.addEventListener("pointerdown",u),()=>{document.removeEventListener("keydown",h),document.removeEventListener("pointerdown",u)}},[a]),n.jsxs("div",{ref:o,className:"relative flex items-center gap-1",children:[n.jsx("button",{"aria-label":e?"正在同步":r||"刷新同步状态",title:r||(e?"正在同步":"刷新同步状态"),onClick:s,className:"rounded p-2 hover:bg-accent",children:n.jsx(Er,{size:16,className:e?"animate-spin":""})}),["notifications","inbox"].map(h=>n.jsxs("button",{"aria-label":h==="notifications"?"通知":"收件箱","aria-expanded":a===h,"aria-controls":"shell-popover",onClick:u=>{l.current=u.currentTarget,i(a===h?null:h)},className:"relative rounded p-2 hover:bg-accent",children:[h==="notifications"?n.jsx(xa,{size:16}):n.jsx(Ra,{size:16}),(h==="notifications"?t.attention.length+t.activity.filter(u=>!u.read).length:t.inbox.length)>0&&n.jsx(vt,{tone:"info",size:"sm",className:"absolute right-1 top-1"})]},h)),a&&n.jsxs("div",{id:"shell-popover",ref:c,tabIndex:-1,role:"region","aria-label":a==="notifications"?"通知中心":"收件箱",className:"absolute right-0 top-full z-50 mt-2 max-h-[70vh] w-[360px] max-w-[calc(100vw-24px)] overflow-y-auto rounded-lg border border-border bg-popover p-4 text-popover-foreground shadow-lg",children:[n.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[n.jsx("h2",{className:"font-medium",children:a==="notifications"?"通知中心":"收件箱"}),n.jsx("button",{"aria-label":"关闭",onClick:()=>{i(null),l.current?.focus()},children:n.jsx(Tr,{size:16})})]}),r&&n.jsx(Nr,{tone:"destructive",role:"alert",className:"mb-3",action:n.jsx("button",{onClick:s,className:"underline",children:"重试"}),children:r}),a==="notifications"?n.jsx(os,{close:()=>i(null)}):n.jsx(is,{})]})]})}const wo=d.lazy(()=>ae(()=>import("./PodPage-BA0DQ3AB.js"),__vite__mapDeps([10,3,4,1,2,5,6,7,11,12,13,8,9]))),yo=[{path:"/device/network",label:"网络访问"},{path:"/device/services",label:"服务状态"},{path:"/device/runtime",label:"运行设置"},{path:"/device/logs",label:"查看日志"}],jo=[{path:"/pod/models",label:"模型设置"},{path:"/pod/search",label:"检索与索引"},{path:"/pod/apps",label:"授权应用"},{path:"/pod/data",label:"数据管理"}],Io=[{path:"/settings/appearance",label:"外观"}];function No({items:t,query:e,label:r}){const{openMain:s}=Fn();return n.jsx("nav",{"aria-label":r,className:"p-2",children:t.filter(a=>a.label.includes(e.trim())).map(a=>n.jsx(jn,{to:a.path,onClick:s,className:({isActive:i})=>`flex min-h-11 items-center rounded-lg px-3 text-sm leading-normal ${i?"bg-accent font-medium text-primary":"hover:bg-muted"}`,children:a.label},a.path))})}function dt({subject:t}){const e=Be(),r=t==="device"?yo:t==="pod"?jo:Io,[s,a]=d.useState(""),i=r.find(c=>c.path===e.pathname)??r[0],o=t==="device"?"这台设备":t==="pod"?"Pod":"设置";return n.jsx(wr,{mode:"auto",listHeader:n.jsx("div",{className:"flex h-full min-w-0 items-center px-3",children:n.jsx(Ir,{"aria-label":"搜索页面",value:s,onChange:c=>a(c.target.value)})}),list:n.jsx(No,{items:r,query:s,label:o}),mainHeader:n.jsx(cs,{title:i.label}),main:n.jsx(ft,{})})}function cs({title:t,children:e}){return n.jsxs("div",{className:"flex h-full min-w-0 items-center justify-between gap-2 px-4",children:[n.jsx("h1",{className:"min-w-0 truncate text-sm leading-normal font-semibold",children:t}),n.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e,n.jsx(_o,{})]})]})}function tr({title:t,children:e}){return n.jsx(wr,{className:"workspace-page",pageType:"collection",hasObjectCollection:!1,listHeader:null,list:null,mainHeader:n.jsx(cs,{title:t}),main:n.jsx("div",{className:"p-6",children:e})})}function So({section:t}){const e=mr(),r=Ce(),s=r.issuer?new URL("/.account/account/",r.issuer).toString():void 0;return n.jsx(xr,{children:n.jsx(wo,{section:t,onSection:a=>e(`/pod/${a}`),accountUrl:s})})}function ko(){const t=yn();return n.jsx("section",{className:"p-6 text-sm leading-normal",children:n.jsxs("label",{className:"flex flex-wrap items-center justify-between gap-3 border-b pb-4",children:["主题",n.jsxs(jr,{"aria-label":"主题",className:"w-auto",value:t.preference,onChange:e=>t.setPreference(e.target.value),children:[n.jsx("option",{value:"system",children:"跟随系统"}),n.jsx("option",{value:"light",children:"浅色"}),n.jsx("option",{value:"dark",children:"深色"})]})]})})}const Je=[{id:"tasks",label:"任务",labelEn:"Tasks",href:"/tasks",activePaths:["/tasks"],icon:Xa},{id:"ai",label:"AI 连接",labelEn:"AI connections",href:"/ai-connections",activePaths:["/ai-connections"],icon:za},{id:"pod",label:"Pod",labelEn:"Pod",href:"/pod/models",activePaths:["/pod"],icon:yr},{id:"device",label:"这台设备",labelEn:"This device",href:"/device/network",activePaths:["/device"],icon:Da},{id:"settings",label:"设置",labelEn:"Settings",href:"/settings/appearance",activePaths:["/settings"],icon:$a}];function ls(t,e){const r=e.replace(/\/+$/,"")||"/";return t.activePaths.some(s=>r===s||r.startsWith(`${s}/`))}function Ro(t,e,r){const i=Math.min(360,e-16),o=Math.max(8,Math.min(t.top,r-240-8));return{left:Math.max(8,Math.min(t.right+12,e-i-8)),top:o,width:i,maxHeight:Math.max(0,r-o-8)}}function Po(){const t=vr(),e=d.useContext(fr),r=t.isLoggedIn&&t.accountState.status==="authenticated",s=e?.state.status==="authenticated"&&!!(e.webId??e.state.webId),a=r||s,[i,o]=d.useState(Do(a)),[c,l]=d.useState(),[h,u]=d.useState(),[g,f]=d.useState(),v=d.useRef(null),p=d.useRef(null),m=d.useRef(void 0),b=d.useId(),S=t.identity,N=_r(t.idpIndex),x=!t.isInitializing&&N?new URL(N).origin:void 0,I=x?hr(void 0,t.idpIndex):void 0,k=$e(),R=Un(t.controls,S),y=x&&k?.issuer===x&&R&&k.account.id===R?k.account:void 0,T=r?Co(S,I,y):void 0,j=_t({accountIdentity:T,runtime:s?e:void 0}),_=j.displayName,L=Eo(j.displayName),$=e?.webId??(e?.state.status==="authenticated"?e.state.webId:void 0),A=e?.selectedStorage?.storageUrl??e?.podUrl,V=e?.selectedStorage,K=e?.currentPod,te=d.useMemo(()=>A?To(A):void 0,[A]),J=e?.state.status==="authenticated"&&!!($&&A&&V&&K)&&V?.webId===$&&rr(V?.storageUrl??"",A??"")&&K?.webId===$&&rr(K?.podUrl??"",A??""),z=a,B=i&&z,H=d.useCallback(D=>{o(D),D||(f(void 0),sr())},[]);d.useLayoutEffect(()=>{if(!B)return;const D=()=>{const ne=p.current;ne&&f(Ro(ne.getBoundingClientRect(),window.innerWidth,window.innerHeight))};return D(),window.addEventListener("resize",D),window.addEventListener("scroll",D,!0),window.visualViewport?.addEventListener("resize",D),()=>{window.removeEventListener("resize",D),window.removeEventListener("scroll",D,!0),window.visualViewport?.removeEventListener("resize",D)}},[B]),d.useEffect(()=>{if(!z){sr();return}if(!B)return;const D=w=>{const P=w.target;P instanceof Node&&(v.current?.contains(P)||p.current?.contains(P)||H(!1))},ne=w=>{w.key==="Escape"&&(H(!1),p.current?.focus())};return document.addEventListener("pointerdown",D),document.addEventListener("keydown",ne),()=>{document.removeEventListener("pointerdown",D),document.removeEventListener("keydown",ne)}},[z,B,H]),d.useEffect(()=>{!B||!g||v.current?.focus({preventScroll:!0})},[B,g]),d.useEffect(()=>()=>{m.current!==void 0&&window.clearTimeout(m.current)},[]);const re=async()=>{l("logout"),H(!1);try{await at(t,e),(t.isAnonymous?.()??!0)&&H(!1)}catch{}finally{l(void 0)}},se=async()=>{l("switch"),H(!1);try{await at(t,e,{onComplete:()=>{pr();const D=new URL(Re,window.location.origin);D.searchParams.set("xpod-login","switch"),window.location.assign(D)}}),H(!1)}catch{}finally{l(void 0)}},de=async()=>{const D=j.webId??$;if(D){try{await navigator.clipboard.writeText(D),u("已复制")}catch{u("复制失败")}m.current!==void 0&&window.clearTimeout(m.current),m.current=window.setTimeout(()=>u(void 0),1800)}};return z?n.jsxs("div",{className:"relative",children:[n.jsxs("button",{ref:p,type:"button","aria-label":a?`打开 ${_} 的个人卡片`:"个人卡片","aria-expanded":B,"aria-controls":B?b:void 0,"data-testid":"xpod-user-card-trigger","data-pod-ready":J?"true":"false",className:"flex h-9 w-9 items-center justify-center rounded-md text-foreground transition-colors hover:bg-accent focus:outline-none focus:ring-0 focus-visible:bg-accent",onClick:()=>H(!B),children:[n.jsxs(Ut,{className:"h-8 w-8 rounded-md border border-border bg-muted",children:[j.avatarUrl?n.jsx(Dt,{src:j.avatarUrl,alt:_}):null,n.jsx(Ot,{className:"rounded-md bg-muted text-xs text-muted-foreground",children:L})]}),n.jsx("span",{className:"sr-only",children:a?_:"Not signed in"})]}),B&&typeof document<"u"?Ln.createPortal(n.jsx("section",{ref:v,id:b,role:"region",tabIndex:-1,"aria-label":a?_:"Xpod account","data-avatar-card":"true","data-selected-pod-url":A,style:g,className:`fixed z-50 overflow-y-auto rounded-xl border border-border/40 bg-card text-card-foreground shadow-xl shadow-black/10 ${g?"":"invisible"}`,children:n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-start gap-5 px-6 pb-5 pt-6",children:[n.jsxs(Ut,{"data-testid":"xpod-profile-avatar",className:"h-20 w-20 shrink-0 rounded-2xl border border-border/50 bg-primary/10 shadow-sm",children:[j.avatarUrl?n.jsx(Dt,{src:j.avatarUrl,alt:_}):null,n.jsx(Ot,{className:"rounded-2xl bg-primary/10 text-2xl font-bold text-primary",children:L})]}),n.jsxs("div",{className:"min-w-0 flex-1 py-0.5",children:[n.jsx("h2",{className:"truncate text-xl font-bold text-foreground",children:_}),n.jsxs("div",{className:"mt-1 flex min-w-0 items-center gap-1 text-sm text-muted-foreground",children:[n.jsx("span",{className:"shrink-0 opacity-70",children:"WebID"}),n.jsx("span",{className:"truncate font-mono font-medium",children:j.webId??$}),n.jsx(pe,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 text-muted-foreground","aria-label":"复制 WebID",onClick:()=>{de()},children:n.jsx(Ia,{className:"h-3 w-3","aria-hidden":"true"})}),h?n.jsx("span",{role:"status",className:"shrink-0 text-xs text-primary",children:h}):null]}),n.jsx(Jn,{tone:J?"success":"neutral",dotSize:"sm",className:M("mt-2.5 gap-1.5 rounded-full px-2 py-1 text-xs font-medium",J?"bg-success/10 text-success":"bg-muted text-muted-foreground"),children:J?"Pod 已就绪":"WebID 已登录"})]})]}),j.note||j.region?n.jsxs("div",{className:"px-6 pb-5 text-sm text-muted-foreground",children:[j.note?n.jsx("p",{className:"line-clamp-2 text-foreground/85",children:j.note}):null,j.region?n.jsx("p",{className:"mt-1 text-xs",children:j.region}):null]}):null,n.jsx("div",{className:"border-t border-border/40 p-2",children:n.jsx(pe,{asChild:!0,variant:"ghost",className:"h-auto min-h-14 w-full justify-start gap-3 px-3 py-2.5 font-normal",children:n.jsxs("a",{href:"/pod/models","aria-label":"Pod",children:[n.jsx("span",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground",children:n.jsx(yr,{className:"h-4 w-4","aria-hidden":"true"})}),n.jsxs("span",{className:"min-w-0 flex-1 text-left",children:[n.jsx("span",{className:"block truncate text-sm font-medium text-foreground",children:Ao(te)}),n.jsxs("span",{className:"mt-0.5 block truncate text-xs text-muted-foreground",children:[Uo(A)," · ",J?"已就绪":"尚未就绪"]})]}),J?n.jsx(ya,{className:"h-4 w-4 shrink-0 text-success","aria-label":"Pod 已就绪"}):n.jsx(_a,{className:"h-4 w-4 shrink-0 text-muted-foreground","aria-hidden":"true"})]})})}),n.jsx(Pr,{}),n.jsxs("div",{className:"p-2",children:[N?n.jsx(pe,{asChild:!0,variant:"ghost",className:"h-10 w-full justify-start px-3 font-normal",children:n.jsxs("a",{href:N,target:"_blank",rel:"noopener noreferrer",children:[n.jsx(Ga,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),"管理账号",n.jsx(Sa,{className:"ml-1 h-3.5 w-3.5","aria-hidden":"true"})]})}):null,n.jsxs(pe,{type:"button",variant:"ghost",className:"h-10 w-full justify-start px-3 font-normal",onClick:()=>{se()},disabled:c!==void 0,children:[c==="switch"?n.jsx(tt,{className:"mr-2 h-4 w-4 animate-spin","aria-hidden":"true"}):n.jsx(Er,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),"切换 WebID"]}),n.jsxs(pe,{type:"button",variant:"ghost",className:"h-10 w-full justify-start px-3 font-normal text-destructive hover:text-destructive",onClick:()=>{re()},disabled:c!==void 0,children:[c==="logout"?n.jsx(tt,{className:"mr-2 h-4 w-4 animate-spin","aria-hidden":"true"}):n.jsx(Ea,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),"退出"]})]})]})}),document.body):null]}):n.jsx("a",{href:Re,"aria-label":"登录",title:"登录",className:"flex h-9 w-9 items-center justify-center rounded-lg text-muted-foreground hover:bg-accent",children:n.jsx(Ca,{size:20,"aria-hidden":"true"})})}function Co(t,e,r){if(t?.displayName||t?.username)return t;const s=e||(r&&"email"in r&&typeof r.email=="string"?r.email:void 0);if(!s&&!r)return t;const a=r?.username||Lo(s);return{...r??{},...t??{},...a?{username:a}:{},...r?.displayName?{displayName:r.displayName}:{displayName:a||s||"Xpod account"}}}function Lo(t){if(t)return t.split("@")[0]?.trim()||void 0}function Eo(t){const e=t.trim().split(/\s+/).filter(Boolean);return e.length>=2?`${e[0][0]}${e.at(-1)[0]}`.toUpperCase():t.slice(0,2).toUpperCase()||"XP"}function To(t){try{return new URL(t).pathname.split("/").filter(Boolean).at(-1)}catch{return}}function Ao(t){return t?`${t} Pod`:"我的 Pod"}function Uo(t){if(!t)return"未连接 Pod";try{return new URL(t).host}catch{return"Pod"}}function rr(t,e){try{return new URL(t).href===new URL(e).href}catch{return t===e}}function Do(t){return t?typeof window<"u"&&new URLSearchParams(window.location.search).get("account")==="open":!1}function sr(){if(typeof window>"u")return;const t=new URL(window.location.href);t.searchParams.get("account")==="open"&&(t.searchParams.delete("account"),window.history.replaceState(window.history.state,"",`${t.pathname}${t.search}${t.hash}`))}function nr({items:t,label:e,attentionIds:r=[]}){const a=Be().pathname;return n.jsx("nav",{"aria-label":e,className:"flex w-full flex-col items-center gap-2",children:t.map(i=>{const o=i.icon,c=i.href??i.path??"/",l=i.activePaths?ls(i,a):a===i.path||a.startsWith(`${i.path}/`);return n.jsxs(rt,{to:c,"aria-label":i.label,"aria-current":l?"page":void 0,"data-list-item":"true",title:i.label,onKeyDown:Bn,className:kn(zn(l),"text-sm"),children:[n.jsx(o,{className:"h-5 w-5 shrink-0","aria-hidden":"true"}),n.jsx("span",{className:"sr-only",children:i.label}),r.includes(i.id)?n.jsx(vt,{tone:"destructive",label:"需要处理",className:"absolute right-1 top-1"}):null]},i.id)})})}function Oo({product:t}){const e=Be(),s=ss()?.snapshot.attention.some(m=>m.kind==="network")??!1,[a,i]=d.useState({path:e.pathname,open:!1}),o=a.path===e.pathname&&a.open;a.path!==e.pathname&&i({path:e.pathname,open:!1});const c=d.useRef(null),l=d.useRef(!1),h=d.useRef(null),u=Je.find(m=>ls(m,e.pathname)),f={models:"模型设置",search:"检索与索引",indexing:"检索与索引",applications:"授权应用",data:"数据管理",network:"网络访问",services:"服务状态",runtime:"运行设置",logs:"查看日志",appearance:"外观"}[e.pathname.split("/").filter(Boolean).at(-1)??""];d.useEffect(()=>{l.current&&!o&&c.current?.focus(),l.current=o},[o]),d.useEffect(()=>{const m=()=>{window.innerWidth>=768&&i(b=>({...b,open:!1}))};return window.addEventListener("resize",m),()=>window.removeEventListener("resize",m)},[]),d.useEffect(()=>{if(!o)return;const m=b=>{if(b.key==="Escape"&&(i(I=>({...I,open:!1})),c.current?.focus()),b.key!=="Tab")return;const S=Array.from(h.current?.querySelectorAll('[data-app-layout-navigation] a, [data-app-layout-navigation] button, [data-workspace-pane="list"] a, [data-workspace-pane="list"] button, [data-workspace-pane="list"] input, [data-drawer-close]')??[]).filter(I=>I.getClientRects().length&&!I.hasAttribute("disabled")),N=S[0],x=S.at(-1);b.shiftKey&&document.activeElement===N?(b.preventDefault(),x?.focus()):!b.shiftKey&&document.activeElement===x&&(b.preventDefault(),N?.focus())};return document.addEventListener("keydown",m),h.current?.querySelector("[data-drawer-close]")?.focus(),()=>document.removeEventListener("keydown",m)},[o]);const v=n.jsx("button",{ref:c,type:"button",className:"xpod-navigation-toggle","aria-label":"打开导航","aria-expanded":o,onClick:()=>i({path:e.pathname,open:!0}),children:n.jsx(Aa,{"aria-hidden":"true",size:20})}),p=n.jsxs(n.Fragment,{children:[v,n.jsxs("span",{className:"xpod-header-parent",children:[u?.label??"Xpod"," ›"]})]});return n.jsx($n.Provider,{value:{open:o,onClose:()=>i(m=>({...m,open:!1})),headerLeading:p},children:n.jsxs("section",{ref:h,role:o?"dialog":void 0,"aria-modal":o||void 0,"aria-label":o?"Xpod 导航":void 0,className:`xpod-desktop-shell xpod-${t}-shell`,"data-app-layout":"workspace","data-drawer-open":o,children:[n.jsxs("header",{className:"xpod-narrow-header","data-app-layout-header":!0,children:[v,n.jsxs("span",{children:[u?.label??"Xpod",f?` › ${f}`:""]})]}),o?n.jsx("button",{className:"xpod-drawer-backdrop","aria-label":"关闭导航",onClick:()=>{i(m=>({...m,open:!1})),c.current?.focus()}}):null,n.jsxs("aside",{className:"xpod-rail","data-app-layout-navigation":!0,"aria-label":"Xpod 工作区导航",onClick:m=>{m.target.closest("a")&&i(b=>({...b,open:!1}))},children:[n.jsx("div",{className:"xpod-rail-profile",children:n.jsx(Po,{})}),n.jsx(nr,{items:Je.slice(0,3),label:"应用"}),n.jsx("div",{className:"xpod-rail-host",children:n.jsx(nr,{items:Je.slice(3),label:"本机",attentionIds:s?["device"]:[]})})]}),o?n.jsx("button",{"data-drawer-close":!0,className:"xpod-drawer-close","aria-label":"收起导航",onClick:()=>{i(m=>({...m,open:!1})),c.current?.focus()},children:n.jsx(Tr,{size:18})}):null,n.jsx("div",{className:"xpod-shell-content","data-app-layout-content":!0,children:n.jsx(ft,{})})]})})}function Fo({onReady:t}){const e=d.useContext(bt),r=d.useRef(!1),s=e?.isInitializing===!0;return d.useEffect(()=>{!s&&!r.current&&(r.current=!0,t())},[s,t]),null}const ar="xpod:returnTo";function $o(){try{const t=sessionStorage.getItem(ar);return t&&sessionStorage.removeItem(ar),t}catch{return null}}const ut="xpod.auth.login-cancelled";function Se(t){try{t?window.localStorage.setItem(ut,"1"):window.localStorage.removeItem(ut)}catch{}}function ds(t){const e=new URL(window.location.href);return e.searchParams.get("xpod-login")!==t?!1:(Se(!0),$o(),e.searchParams.delete("xpod-login"),window.history.replaceState(window.history.state,"",`${e.pathname}${e.search}${e.hash}`),!0)}function Bo(){return new URL(window.location.href).searchParams.get("xpod-login")==="switch"}function ir(){return ds("switch")}function zo(){if(ds("cancelled"))return!0;try{return window.localStorage.getItem(ut)==="1"}catch{return!1}}function Mo(t){const e=t.location??(typeof window>"u"?"http://localhost/":window.location),s=[$s(e)],a=Xo(e),i=t.transactionStore??Di({origin:a}),o=u=>{if(u!==void 0)return Ze(u);const g=new URL(us(e)),f=`${g.pathname}${g.search}`;try{return Ze(f)}catch{return}};let c=!1;const l=u=>{try{return i.begin(u)}catch(g){if(c||!(g instanceof E)||g.code!=="already_active")throw g;try{const f=i.readSinglePending();f&&i.cancel(f.id)}catch{}return i.begin(u)}},h=async(u,g,f)=>{const v=o(u),p={id:Yr(),route:s[0],authorizationSurface:"redirect",discovery:"strict",...f?{prompt:f}:{},...v===void 0?{}:{returnTo:v},...g===void 0?{}:{selectedStorage:g}},m=l(p);c=!0;try{await t.runtime.login(m)}catch(b){try{i.cancel(m.id)}catch{}throw b}finally{c=!1}return m};return{routes:s,startLogin:h,retryLogin:h,cancelLogin(){const u=i.readSinglePending();u&&i.cancel(u.id)},readPending:()=>i.readSinglePending(),callbackUrl(){return`${a}/auth/callback`}}}function Xo(t){return new URL(us(t)).origin}function us(t){return typeof t=="string"?t:t.href}function qo(t){if(!t)return"cloud";let e;try{e=new URL(t).hostname.toLowerCase()}catch{return"cloud"}return e==="localhost"||e.endsWith(".localhost")||e.endsWith(".local")||e==="::1"||e==="[::1]"||/^127\./u.test(e)||/^10\./u.test(e)||/^192\.168\./u.test(e)||/^172\.(1[6-9]|2\d|3[01])\./u.test(e)?"edge":"cloud"}const G=lr("zh-CN"),Go={name:"Xpod",icon:n.jsx(pt,{size:24})},Wo="无法打开选中的 Pod,请重试。",Ho="操作未完成,请重试。";function Vo(t){return n.jsx(Fr,{children:n.jsx(Qo,{...t})})}function Qo({children:t,autoStart:e=!1,developerMode:r=!1}){const s=Ce(),a=d.useContext(bt),i=d.useSyncExternalStore(Dr,Va,()=>!1),o=d.useMemo(()=>Mo({runtime:s}),[s]),[c]=d.useState(Bo),[l,h]=d.useState(()=>c||zo());d.useEffect(()=>{if(l)try{o.cancelLogin()}catch{}},[l,o]);const u=Yo(s.state),g=Jo(s,u),f="remembered"in u?u.remembered:void 0,v=f?Ko(f):void 0,[p,m]=d.useState(f&&v?{signature:v,identity:f}:void 0);v!==void 0&&v!==p?.signature&&m({signature:v,identity:f});const b=u.status==="authenticated"&&g?.status==="ready",[S,N]=d.useState(),[x,I]=d.useState(!1),[k,R]=d.useState(!1),[y,T]=d.useState(c?{prompt:"login"}:void 0),j=d.useRef(0),[_,L]=d.useState(!1),$=d.useRef(!1),A=d.useRef(!1),V=d.useCallback(O=>{console.error("[WebIdAuthBoundary] authentication action failed",O),N(Ho)},[]),K=d.useCallback(O=>{const oe=++j.current;N(void 0),I(!0),O().catch(ce=>{oe===j.current&&V(ce)}).finally(()=>{oe===j.current&&I(!1)})},[V]),te=d.useCallback(()=>{Se(!1),h(!1),N(void 0),T({})},[]),J=d.useCallback(()=>{R(!0),te()},[te]),z=d.useCallback(()=>{if(!y)return;const O=y.prompt;h(!1),T(void 0),K(async()=>{const oe=j.current;c&&await s.session.initialize({restorePreviousSession:!1}),oe===j.current&&(c&&ir(),Se(!1),await o.startLogin(void 0,void 0,O))})},[o,y,K,s.session,c]),B=()=>{if(_){re();return}u.status==="authenticated"?s.retryPodOpen?.():J()},H=()=>{if(!_){try{o.cancelLogin()}catch{}c&&ir(),Se(!0),h(!0),T(void 0),j.current+=1,I(!1),N(void 0)}},re=()=>K(async()=>{R(!0),L(!0);const O=()=>{Se(!1),h(!1),pr(),N(void 0),T({prompt:"login"}),L(!1)};a?await at(a,s,{onComplete:O}):(await s.logout(),O())});if(d.useEffect(()=>{s.state.status!=="loading"||$.current||($.current=!0,s.session.initialize({restorePreviousSession:!l}).catch(V))},[l,V,s.session,s.state.status]),d.useEffect(()=>{l||y||i||x||_||!e||A.current||u.status!=="anonymous"||(A.current=!0,te())},[l,i,e,x,y,te,u.status,_]),b&&!x&&!S)return n.jsx(n.Fragment,{children:t});const se=f,de=u.status==="restoring",D=!!globalThis.xpodDesktop&&e&&!k&&!l&&!c&&!_&&!i&&!S&&(de||u.status==="anonymous"),ne=x||!!y||e&&!l&&!i&&u.status==="anonymous"&&!S,w=se&&!l?Oe(se):void 0;let C=((O=!1)=>w?{kind:"remembered",identity:w,busy:O}:{kind:"choose-service",busy:O})(),X,U=J,q,Y=!1;if(!l&&s.state.status==="error"&&s.state.error.name==="SolidSessionPendingError")X={tone:"warning",text:G.noticePending,primaryLabel:G.refreshPage,developerDetail:s.state.error.message},U=()=>window.location.reload();else if(S)X={tone:"warning",text:G.noticeIncomplete,primaryLabel:G.retry,developerDetail:S},U=B,q=w&&!_?re:void 0;else if(de)C={kind:"restoring",...se?{identity:Oe(se)}:{}};else if(ne){const O=w??(!l&&p?Oe(p.identity):void 0);C=O?{kind:"remembered",identity:O,busy:!0}:{kind:"choose-service",busy:!0},U=()=>{},Y=!_}else if(u.status==="authenticated"){const O=Oe(It(u.webId)??{displayName:ga(u.webId),webId:u.webId});g?.status==="conflict"?(C={kind:"remembered",identity:O},X={tone:"warning",text:G.noticeIncomplete,primaryLabel:G.useAnother,developerDetail:g.message},U=re):g?.status==="error"?(C={kind:"remembered",identity:O},X={tone:"warning",text:G.noticeUnreachable,primaryLabel:G.retry,developerDetail:g.message},U=B,q=re):(C={kind:"remembered",identity:O,busy:!0},U=()=>{})}else w?(q=re,u.status==="expired"?(C={kind:"expired",identity:w},U=B):u.status==="error"&&(X={tone:"warning",text:G.noticeIncomplete,primaryLabel:G.reauthenticate,developerDetail:u.message},U=B)):!l&&(u.status==="error"||u.status==="expired")&&(X={tone:"warning",text:u.status==="expired"?G.expiredLine:G.noticeIncomplete,primaryLabel:G.reauthenticate,developerDetail:u.status==="error"?u.message:void 0},U=B);return n.jsxs(Bs,{ariaLabel:"登录 Xpod",children:[y?n.jsx(Fo,{onReady:z}):null,D?n.jsxs("div",{role:"status","aria-live":"polite",className:"flex flex-1 items-center justify-center p-5 text-sm text-muted-foreground",children:[n.jsx(tt,{"aria-hidden":"true",className:"mr-2 h-5 w-5 animate-spin"}),"正在登录…"]}):n.jsx(ma,{app:Go,brand:n.jsx(zs,{renderLogo:O=>n.jsxs("span",{className:"flex items-center gap-2",children:[n.jsx(pt,{size:24}),n.jsxs("span",{className:"flex flex-col text-left",children:[n.jsx("span",{className:"text-[13px] font-medium",children:"Xpod"}),n.jsx("span",{className:"text-[9px] leading-none text-primary",children:O})]})]})}),state:C,notice:X,locale:"zh-CN",developerMode:r,capabilities:{customService:!1,register:!1},onPrimary:U,onUseAnother:q}),Y?n.jsx(pe,{type:"button",variant:"ghost",className:"mt-2 h-9 w-full rounded-lg px-2",onClick:H,children:G.cancel}):null]})}function Oe(t){const e=$e(),r=e&&(!t.webId||e.webId===t.webId)?e.storageBinding.storageUrl:void 0,s=qo(r);return{displayName:t.displayName,...t.avatarUrl?{avatarUrl:t.avatarUrl}:{},...r?{storage:{kind:s,label:s==="cloud"?G.storageCloud:G.storageEdge}}:{}}}function Ko(t){return[t.routeId,t.webId??"",t.displayName,t.avatarUrl??""].join("\0")}function Jo(t,e){if(e.status!=="authenticated")return;if(t.podError?.webId===e.webId)return{status:"error",message:Wo};if(t.currentPod===void 0)return{status:"waiting_for_binding"};const r=t.selectedStorage??{webId:t.currentPod.webId,storageUrl:t.currentPod.podUrl},s=t.state.status==="authenticated"?t.state.podUrl:void 0;return t.currentPod.webId===e.webId&&r.webId===t.currentPod.webId&&or(r.storageUrl,t.currentPod.podUrl)&&(s===void 0||or(t.currentPod.podUrl,s))?{status:"ready",selected:r}:{status:"conflict",message:"当前 WebID 已登录,但选中的 Pod 与该身份不一致。"}}function or(t,e){try{return new URL(t).href===new URL(e).href}catch{return t===e}}function It(t){const e=$e();if(e&&!(t&&t!==e.webId))return{displayName:e.account.displayName??e.account.username??e.account.email??"Xpod",...e.account.avatarUrl?{avatarUrl:e.account.avatarUrl}:{},webId:e.webId,routeId:e.routeId}}function Ye(t,e){const r=It(e);return r?{...t,remembered:r}:t}function Yo(t){switch(t.status){case"loading":return Ye({status:"restoring"});case"anonymous":return Ye({status:"anonymous"});case"expired":return Ye({status:"expired"},t.webId);case"authenticated":return{status:"authenticated",webId:t.webId};case"error":{const e=It(t.webId);return{status:"error",message:t.error.message,retryRouteId:"xpod-current-origin",...e?{remembered:e}:{}}}}}const Zo=d.lazy(()=>ae(()=>import("./ModelsPage-6567dZKQ.js").then(t=>t.M),__vite__mapDeps([14,3,4,9,2,5,11,1,6,7,15,12,16]))),ec=d.lazy(()=>ae(()=>import("./DevicePages-FFJMu_zL.js"),__vite__mapDeps([17,3,4,9,2,5,18,6,12,15,13,1,7,8])).then(t=>({default:t.DeviceNetworkPage}))),tc=d.lazy(()=>ae(()=>import("./DevicePages-FFJMu_zL.js"),__vite__mapDeps([17,3,4,9,2,5,18,6,12,15,13,1,7,8])).then(t=>({default:t.DeviceServicesPage}))),rc=d.lazy(()=>ae(()=>import("./DevicePages-FFJMu_zL.js"),__vite__mapDeps([17,3,4,9,2,5,18,6,12,15,13,1,7,8])).then(t=>({default:t.DeviceRuntimePage}))),sc=d.lazy(()=>ae(()=>import("./DevicePages-FFJMu_zL.js"),__vite__mapDeps([17,3,4,9,2,5,18,6,12,15,13,1,7,8])).then(t=>({default:t.DeviceLogsPage}))),nc=d.lazy(()=>ae(()=>import("./TasksPage-B5m82wjD.js"),__vite__mapDeps([19,3,4,1,2,5,6,7,9,8,20]))),ge=t=>n.jsx(xr,{children:t}),ac=[{path:"device",element:n.jsx(dt,{subject:"device"}),children:[{index:!0,element:n.jsx(be,{to:"network",replace:!0})},{path:"network",element:ge(n.jsx(ec,{}))},{path:"services",element:ge(n.jsx(tc,{}))},{path:"runtime",element:ge(n.jsx(rc,{}))},{path:"logs",element:ge(n.jsx(sc,{}))}]},{path:"settings",element:n.jsx(dt,{subject:"settings"}),children:[{index:!0,element:n.jsx(be,{to:"appearance",replace:!0})},{path:"appearance",element:n.jsx(ko,{})}]}],ic=[{element:n.jsx(Vo,{autoStart:!0,children:n.jsx(ft,{})}),children:[{path:"ai-connections",element:ge(n.jsx(Zo,{}))},{path:"pod",element:n.jsx(dt,{subject:"pod"}),children:[{index:!0,element:n.jsx(be,{to:"models",replace:!0})},...["models","search","apps","data"].map(t=>({path:t,element:n.jsx(So,{section:t})}))]},{path:"tasks",element:ge(n.jsx(nc,{}))},{path:"inbox",element:n.jsx(tr,{title:"收件箱",children:n.jsx(is,{})})},{path:"notifications",element:n.jsx(tr,{title:"通知",children:n.jsx(os,{})})}]}],oc=[{element:n.jsx(Oo,{product:"settings"}),children:[...ac,...ic,...Object.entries(Qr).map(([t,e])=>({path:t.slice(1),element:t==="/settings/pod"?n.jsx(En,{to:e}):n.jsx(be,{to:e,replace:!0})})),{index:!0,element:n.jsx(be,{to:Re,replace:!0})},{path:"*",element:n.jsx(be,{to:Re,replace:!0})}]}];function cc(){const t=Be(),e=Nn(oc);return d.useEffect(()=>{document.title="Xpod"},[t.pathname]),e}function lc({runtime:t,initialPathname:e}={}){const[r]=d.useState(()=>dc(e));return n.jsx(oo,{children:n.jsx(Dn,{children:n.jsxs(to,{value:t,children:[n.jsx(Ii,{}),n.jsx(wi,{}),n.jsxs(In,{children:[n.jsx(Ri,{}),n.jsx(ki,{children:n.jsx(xo,{children:n.jsx(Fr,{children:n.jsx(cc,{})})})}),n.jsx(ua,{})]},r)]})})})}function dc(t){const r=`${Pi(t??globalThis.location?.pathname??Re)}${globalThis.location?.search??""}${globalThis.location?.hash??""}`;return`${globalThis.location?.pathname??""}${globalThis.location?.search??""}${globalThis.location?.hash??""}`!==r&&globalThis.history?.replaceState(null,"",r),r}const Nc=Object.freeze(Object.defineProperty({__proto__:null,XpodShellApp:lc},Symbol.toStringTag,{value:"Module"}));export{er as A,ni as B,_a as C,si as D,Sa as E,yc as F,Nc as G,Nr as I,ke as L,Wr as N,Br as Q,Er as R,Ir as S,ie as T,ai as V,Re as X,He as a,lc as b,Di as c,ii as d,ei as e,$r as f,jr as g,Le as h,co as i,as as j,_o as k,lo as l,Ia as m,Z as n,vt as o,jc as p,_c as q,Ic as r,Se as s,wc as t,Ce as u,vc as v,la as w,ua as x,Mo as y,zi as z};