@inkeep/open-knowledge 0.31.0-beta.7 → 0.31.0-beta.8

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 (81) hide show
  1. package/dist/assets/skills/discovery/SKILL.md +1 -1
  2. package/dist/assets/skills/project/SKILL.md +1 -1
  3. package/dist/cli.mjs +11 -11
  4. package/dist/constants-B2EvNGWZ.mjs +2 -0
  5. package/dist/{dist-Pe1Q8dMj.mjs → dist-CynAX6cy.mjs} +4 -4
  6. package/dist/{dist-BYM_jxPa.mjs → dist-DiaxTJ69.mjs} +1 -1
  7. package/dist/{gh-detect-C6QZctcU.mjs → gh-detect-Uu4VAWnW.mjs} +2 -2
  8. package/dist/index.d.mts +9 -3
  9. package/dist/index.mjs +1 -1
  10. package/dist/init-1G9fj8cH.mjs +639 -0
  11. package/dist/init-MrbSP11w.mjs +1 -0
  12. package/dist/launch-json-removal-D3x1PYMJ.mjs +2 -0
  13. package/dist/loader-BvbWpeUk.mjs +1 -0
  14. package/dist/{loader-Biqewihc.mjs → loader-DIcwzOTi.mjs} +2 -2
  15. package/dist/{open-browser-CPSoIF8R.mjs → open-browser-Lk0l8JF5.mjs} +2 -2
  16. package/dist/{preview-DhDDUDKS.mjs → preview-C9JeIyOB.mjs} +2 -2
  17. package/dist/preview-CZN7WKk2.mjs +1 -0
  18. package/dist/public/assets/{ActivityModeContent-DCeOqkvP.js → ActivityModeContent-BbFXNuKx.js} +1 -1
  19. package/dist/public/assets/{CodeMirrorPropInput-B1vWorID.js → CodeMirrorPropInput-CHf8Iz40.js} +1 -1
  20. package/dist/public/assets/{DocumentContext-BhV2wOiZ.js → DocumentContext-DG5n9u7B.js} +1 -1
  21. package/dist/public/assets/{EnableSyncConfirmDialog-Ca-ry-Ae.js → EnableSyncConfirmDialog-CJzmvuen.js} +1 -1
  22. package/dist/public/assets/{GraphPanel-lBz9qIQN.js → GraphPanel-m-nt5HQn.js} +1 -1
  23. package/dist/public/assets/{ManagedArtifactProperties-D_Nk4cbN.js → ManagedArtifactProperties-BePO6ANU.js} +1 -1
  24. package/dist/public/assets/{McpConsentDialogBody-Bsj9E3Ff.js → McpConsentDialogBody-arNbqqes.js} +1 -1
  25. package/dist/public/assets/{MermaidDocEditor-DX5BTbSo.js → MermaidDocEditor-DoV9dGJN.js} +1 -1
  26. package/dist/public/assets/{PropertyPanel-CDFSWToc.js → PropertyPanel-DUZsqzTw.js} +1 -1
  27. package/dist/public/assets/{SettingsDialogBody-CZ8Q6HdO.js → SettingsDialogBody-BPlL1Yed.js} +1 -1
  28. package/dist/public/assets/{ShareBranchSwitchDialog-BF1nOzHu.js → ShareBranchSwitchDialog-DSKoiVrF.js} +1 -1
  29. package/dist/public/assets/{ShareReceiveDialog-Dqg_ZHxL.js → ShareReceiveDialog-Bvh3tHuH.js} +1 -1
  30. package/dist/public/assets/{ShareReceiveMissDialog-Cmk3vfV-.js → ShareReceiveMissDialog-Bdk7y3ML.js} +1 -1
  31. package/dist/public/assets/{SkillEditorActions-kSWzLf2i.js → SkillEditorActions-oiOuAa4I.js} +1 -1
  32. package/dist/public/assets/{SourceEditor-DUfgIVNL.js → SourceEditor-Df_8kdW5.js} +1 -1
  33. package/dist/public/assets/{TerminalPanel-z1aKcdQN.js → TerminalPanel-Bd8Dtt_n.js} +1 -1
  34. package/dist/public/assets/agent-presence-Dl0E_LN8.js +1 -0
  35. package/dist/public/assets/{auth-state-cache-QESJRGUP.js → auth-state-cache-BSJEl4LS.js} +1 -1
  36. package/dist/public/assets/{config-provider-DJpUWM8E.js → config-provider-CFiLGdZF.js} +1 -1
  37. package/dist/public/assets/{cursor-BkiD2ODR.js → cursor-BsJMggkz.js} +1 -1
  38. package/dist/public/assets/{dist-Bj4Ae4LE.js → dist-BVRsG3b2.js} +2 -2
  39. package/dist/public/assets/{dist-C9FdwUZB.js → dist-DSzqChbc.js} +1 -1
  40. package/dist/public/assets/{doc-hash-BvJ4F5wQ.js → doc-hash-CmkGIiUd.js} +1 -1
  41. package/dist/public/assets/{documents-events-KDHNhdfV.js → documents-events-CBqhEmHl.js} +1 -1
  42. package/dist/public/assets/{file-tree-adapter-D99FaCGJ.js → file-tree-adapter-BRoSU5bE.js} +1 -1
  43. package/dist/public/assets/{index-DZyzbLiq.js → index-FeSh48__.js} +13 -13
  44. package/dist/public/assets/{keyboard-shortcuts-9kQVtaDu.js → keyboard-shortcuts-Dw2cvMMp.js} +1 -1
  45. package/dist/public/assets/{navigation-targets-B1j0YdRn.js → navigation-targets-G6yEVp6c.js} +1 -1
  46. package/dist/public/assets/{open-managed-artifact-tab-BThYnqZz.js → open-managed-artifact-tab-acLO8au6.js} +1 -1
  47. package/dist/public/assets/{pending-receive-nav-store-D9kW0zL5.js → pending-receive-nav-store-omPUhaeY.js} +1 -1
  48. package/dist/public/assets/{prop-types-CADDENK9.js → prop-types-6gA_YVnm.js} +1 -1
  49. package/dist/public/assets/{receive-store-1Qk9uwTc.js → receive-store-CrJ3w3k0.js} +1 -1
  50. package/dist/public/assets/{selection-context-_wSKX4pT.js → selection-context-8HFgCBJz.js} +1 -1
  51. package/dist/public/assets/skill-actions-D2r7iq9h.js +1 -0
  52. package/dist/public/assets/{skills-api-C6f0gQUn.js → skills-api-DvU5qnRa.js} +1 -1
  53. package/dist/public/assets/{src-DIGGo2K4.js → src-DldiksFQ.js} +1 -1
  54. package/dist/public/assets/{target-navigation-intent-DszwtIOt.js → target-navigation-intent-DIz1qTBm.js} +1 -1
  55. package/dist/public/assets/{typing-burst-detector--_GJ5sz1.js → typing-burst-detector-DP8u_tQC.js} +1 -1
  56. package/dist/public/assets/{workspace-paths-GEb_gilm.js → workspace-paths-Dj3MgOE7.js} +1 -1
  57. package/dist/public/index.html +26 -26
  58. package/dist/{repair-launch-json-B6nfMuDG.mjs → repair-launch-json-DzczMayl.mjs} +2 -2
  59. package/dist/repair-mcp-configs-Cp5VRehu.mjs +2 -0
  60. package/dist/repair-skills-B-9mVcmb.mjs +1 -0
  61. package/dist/{repair-skills-DuNm-kMp.mjs → repair-skills-XQg-rb3q.mjs} +2 -2
  62. package/dist/server-lock-GuuouVft-C6kYMpa7.mjs +1 -0
  63. package/dist/{server-lock-iLcBw_q0-nWzkxbfg.mjs → server-lock-iLcBw_q0-DddnIrHS.mjs} +2 -2
  64. package/dist/{src-CU3zxCid.mjs → src-CZcBOOJs.mjs} +4 -4
  65. package/dist/start-DcvuVtnN.mjs +1 -0
  66. package/dist/{start-D9sidghM.mjs → start-Ig8o-wfe.mjs} +2 -2
  67. package/dist/write-project-skill-DV1PSHkd.mjs +50 -0
  68. package/package.json +1 -1
  69. package/dist/constants-B8Zie8rF.mjs +0 -2
  70. package/dist/init-D3BvztSN.mjs +0 -1
  71. package/dist/init-DT-9Ccjv.mjs +0 -653
  72. package/dist/launch-json-removal-bo3gNUN4.mjs +0 -2
  73. package/dist/loader-BiXk2JV6.mjs +0 -1
  74. package/dist/preview-BrPKQxiM.mjs +0 -1
  75. package/dist/public/assets/agent-presence-CR_Kl3f1.js +0 -1
  76. package/dist/public/assets/skill-actions-CnQtb5aQ.js +0 -1
  77. package/dist/repair-mcp-configs-CfO_BZxd.mjs +0 -2
  78. package/dist/repair-skills-BDe9l22O.mjs +0 -1
  79. package/dist/server-lock-GuuouVft-CO_sPVNi.mjs +0 -1
  80. package/dist/start-DHrKkLIh.mjs +0 -1
  81. package/dist/write-project-skill-DyoxYjJB.mjs +0 -36
@@ -1,4 +1,4 @@
1
- import{o as e}from"./chunk-CFjPhJqf.js";import{n as t,r as n,t as r}from"./compiler-runtime-CVnuRdak.js";import{n as i}from"./DocumentContext-BhV2wOiZ.js";import{n as a,r as o}from"./dist-CQw2y-s3.js";import{a as s,c,i as ee,n as te,o as l,r as ne,s as u,t as re,u as ie}from"./panel-HcGnbQ9h.js";import{u as ae}from"./createLucideIcon-BPhNPfG7.js";import{B as d,I as f}from"./CodeMirrorPropInput-B1vWorID.js";import{Dr as p,Xn as oe,it as m,st as h}from"./dist-Bj4Ae4LE.js";import{i as se}from"./prop-types-CADDENK9.js";import{t as g}from"./dist-BRGTi0a4.js";import{i as _}from"./startup-marks-DkfPsa68.js";var v=e(t(),1),y=r(),b=new Map;function x(e,t){b.set(e,t)}function S(e){let t=b.get(e)??null;return b.delete(e),t}function C(e){b.delete(e)}function w(e,t){let n=(0,y.c)(4),r=t===void 0?!1:t,[i,a]=(0,v.useState)(void 0),o=(0,v.useRef)(null),s,c;return n[0]!==r||n[1]!==e?(s=()=>{if(r||e.length===0){a(void 0);return}let t=function(){let t=window.innerHeight/2,n,r;for(let i of e){let e=document.getElementById(i);if(!e)continue;let a=e.getBoundingClientRect().top;a<0?n=i:r===void 0&&a<t&&(r=i)}a(r??n??e[0])},n=function(){o.current===null&&(o.current=requestAnimationFrame(()=>{o.current=null,t()}))};return document.addEventListener(`scroll`,n,{capture:!0,passive:!0}),t(),()=>{document.removeEventListener(`scroll`,n,{capture:!0}),o.current!==null&&(cancelAnimationFrame(o.current),o.current=null)}},c=[e,r],n[0]=r,n[1]=e,n[2]=s,n[3]=c):(s=n[2],c=n[3]),(0,v.useEffect)(s,c),i}var T=n(),ce=300;async function le(e){let t=await fetch(`/api/page-headings?docName=${encodeURIComponent(e)}`),n;try{n=await t.json()}catch(e){throw new d(g._({id:`qAQVSD`}),{cause:e,status:t.status})}if(!t.ok){let e=h.safeParse(n);throw e.success?Error(e.data.title):new d(g._({id:`zlErBl`}),{status:t.status})}let r=m.safeParse(n);if(!r.success)throw new d(g._({id:`XW18jo`}),{status:t.status});return r.data.headings??[]}var E=32,D=12,O=6,k=`open-knowledge:outline-nav`;function A(e){let t=(0,y.c)(2),n;return t[0]===e?n=t[1]:(n=(0,T.jsx)(_,{name:`outline-panel`,children:(0,T.jsx)(j,{...e})}),t[0]=e,t[1]=n),n}function j(e){let t=(0,y.c)(50),{docName:n,isSourceMode:r,className:d}=e,f=d===void 0?``:d,{_:p}=o(),{pages:m,loading:h}=se(),g=ie(),{activeProvider:_,activeDocName:b}=i(),S,C;t[0]===n?(S=t[1],C=t[2]):(S=[`page-headings`,n],C=()=>le(n),t[0]=n,t[1]=S,t[2]=C);let A;t[3]!==n||t[4]!==h||t[5]!==m?(A=!h&&(m.has(n)||oe(n)),t[3]=n,t[4]=h,t[5]=m,t[6]=A):A=t[6];let j;t[7]!==S||t[8]!==C||t[9]!==A?(j={queryKey:S,queryFn:C,enabled:A,staleTime:1/0},t[7]=S,t[8]=C,t[9]=A,t[10]=j):j=t[10];let{data:N,isLoading:P,error:F}=c(j),I;t[11]===N?I=t[12]:(I=N===void 0?[]:N,t[11]=N,t[12]=I);let L=I,R,z;t[13]!==b||t[14]!==_||t[15]!==n||t[16]!==g?(R=()=>{if(!_||b!==n)return;let e=_.document,t=null,r=()=>{t!==null&&clearTimeout(t),t=setTimeout(()=>{t=null,g.invalidateQueries({queryKey:[`page-headings`,n]})},ce)};return e.on(`update`,r),()=>{e.off(`update`,r),t!==null&&clearTimeout(t)}},z=[_,b,n,g],t[13]=b,t[14]=_,t[15]=n,t[16]=g,t[17]=R,t[18]=z):(R=t[17],z=t[18]),(0,v.useEffect)(R,z);let B;t[19]===L?B=t[20]:(B=L.map(M),t[19]=L,t[20]=B);let V=w(B,r),H;t[21]!==V||t[22]!==L?(H=V?L.findIndex(e=>e.slug===V):-1,t[21]=V,t[22]=L,t[23]=H):H=t[23];let U=H,W;t[24]!==n||t[25]!==r?(W=function(e,t){let i={index:e,slug:t,mode:r?`source`:`wysiwyg`};i.mode===`source`&&x(n,{kind:`outline`,detail:i}),window.dispatchEvent(new CustomEvent(k,{detail:i}))},t[24]=n,t[25]=r,t[26]=W):W=t[26];let G=W,K=((U>=0?L[U].level:1)-1)*D+(D-O)/2,q=U*E+(E-O)/2,J;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(J=(0,T.jsx)(u,{children:(0,T.jsx)(a,{id:`dD7NPy`})}),t[27]=J):J=t[27];let Y;t[28]!==L.length||t[29]!==P?(Y=!P&&(0,T.jsx)(ne,{children:L.length}),t[28]=L.length,t[29]=P,t[30]=Y):Y=t[30];let X;t[31]===Y?X=t[32]:(X=(0,T.jsxs)(l,{children:[J,Y]}),t[31]=Y,t[32]=X);let Z;t[33]!==p||t[34]!==U||t[35]!==V||t[36]!==F||t[37]!==G||t[38]!==L||t[39]!==P||t[40]!==K||t[41]!==q?(Z=F?(0,T.jsx)(s,{className:`px-2`,children:F instanceof Error?F.message:p({id:`GuqOb1`})}):L.length===0&&!P?(0,T.jsx)(ee,{className:`px-2`,children:(0,T.jsx)(a,{id:`0BB9ID`})}):(0,T.jsxs)(`nav`,{"aria-label":p({id:`BymzO4`}),className:`relative`,children:[U>=0&&(0,T.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-0 rounded-full bg-primary motion-safe:[transition:transform_0.25s_var(--ease-out-strong)]`,style:{width:O,height:O,transform:`translate(${K}px, ${q}px)`}}),L.map((e,t)=>{let n=e.slug===V;return(0,T.jsx)(`button`,{type:`button`,"aria-current":n?`location`:void 0,onClick:()=>G(t,e.slug),className:ae(`w-full cursor-pointer truncate py-1.5 pe-2 text-left text-sm transition-colors`,n?`font-medium text-primary`:`text-muted-foreground hover:text-foreground`),style:{paddingLeft:`${(e.level-1)*D+20}px`},title:e.text,children:e.text},t)})]}),t[33]=p,t[34]=U,t[35]=V,t[36]=F,t[37]=G,t[38]=L,t[39]=P,t[40]=K,t[41]=q,t[42]=Z):Z=t[42];let Q;t[43]!==P||t[44]!==Z?(Q=(0,T.jsx)(te,{className:`px-3 py-2`,"aria-busy":P,children:Z}),t[43]=P,t[44]=Z,t[45]=Q):Q=t[45];let $;return t[46]!==f||t[47]!==X||t[48]!==Q?($=(0,T.jsxs)(re,{className:f,children:[X,Q]}),t[46]=f,t[47]=X,t[48]=Q,t[49]=$):$=t[49],$}function M(e){return e.slug}var N={words:0,chars:0,tokens:0},P=/[ -〿぀-ゟ゠-ヿ㐀-䶿一-鿿豈-﫿＀-￯฀-๿ក-៿]/,F=/[\p{L}\p{N}]/u,I=new Set([`text`,`inlineCode`,`code`,`tag`]),L=new Set([`html`,`definition`,`footnoteDefinition`,`yaml`,`toml`,`image`,`imageReference`,`mdxFlowExpression`,`mdxTextExpression`,`mdxjsEsm`,`rawMdxFallback`,`rawMdxFallbackMdast`]),R=new Set([`paragraph`,`heading`,`blockquote`,`list`,`listItem`,`thematicBreak`,`table`,`tableRow`,`tableCell`,`mdxJsxFlowElement`,`commentBlock`]);function z(e,t){if(!e)return;let n=e.type;if(!L.has(n)){if(I.has(n)){e.value&&(t.push(e.value),n===`code`&&t.push(`
1
+ import{o as e}from"./chunk-CFjPhJqf.js";import{n as t,r as n,t as r}from"./compiler-runtime-CVnuRdak.js";import{n as i}from"./DocumentContext-DG5n9u7B.js";import{n as a,r as o}from"./dist-CQw2y-s3.js";import{a as s,c,i as ee,n as te,o as l,r as ne,s as u,t as re,u as ie}from"./panel-HcGnbQ9h.js";import{u as ae}from"./createLucideIcon-BPhNPfG7.js";import{B as d,I as f}from"./CodeMirrorPropInput-CHf8Iz40.js";import{Dr as p,Xn as oe,it as m,st as h}from"./dist-BVRsG3b2.js";import{i as se}from"./prop-types-6gA_YVnm.js";import{t as g}from"./dist-BRGTi0a4.js";import{i as _}from"./startup-marks-DkfPsa68.js";var v=e(t(),1),y=r(),b=new Map;function x(e,t){b.set(e,t)}function S(e){let t=b.get(e)??null;return b.delete(e),t}function C(e){b.delete(e)}function w(e,t){let n=(0,y.c)(4),r=t===void 0?!1:t,[i,a]=(0,v.useState)(void 0),o=(0,v.useRef)(null),s,c;return n[0]!==r||n[1]!==e?(s=()=>{if(r||e.length===0){a(void 0);return}let t=function(){let t=window.innerHeight/2,n,r;for(let i of e){let e=document.getElementById(i);if(!e)continue;let a=e.getBoundingClientRect().top;a<0?n=i:r===void 0&&a<t&&(r=i)}a(r??n??e[0])},n=function(){o.current===null&&(o.current=requestAnimationFrame(()=>{o.current=null,t()}))};return document.addEventListener(`scroll`,n,{capture:!0,passive:!0}),t(),()=>{document.removeEventListener(`scroll`,n,{capture:!0}),o.current!==null&&(cancelAnimationFrame(o.current),o.current=null)}},c=[e,r],n[0]=r,n[1]=e,n[2]=s,n[3]=c):(s=n[2],c=n[3]),(0,v.useEffect)(s,c),i}var T=n(),ce=300;async function le(e){let t=await fetch(`/api/page-headings?docName=${encodeURIComponent(e)}`),n;try{n=await t.json()}catch(e){throw new d(g._({id:`qAQVSD`}),{cause:e,status:t.status})}if(!t.ok){let e=h.safeParse(n);throw e.success?Error(e.data.title):new d(g._({id:`zlErBl`}),{status:t.status})}let r=m.safeParse(n);if(!r.success)throw new d(g._({id:`XW18jo`}),{status:t.status});return r.data.headings??[]}var E=32,D=12,O=6,k=`open-knowledge:outline-nav`;function A(e){let t=(0,y.c)(2),n;return t[0]===e?n=t[1]:(n=(0,T.jsx)(_,{name:`outline-panel`,children:(0,T.jsx)(j,{...e})}),t[0]=e,t[1]=n),n}function j(e){let t=(0,y.c)(50),{docName:n,isSourceMode:r,className:d}=e,f=d===void 0?``:d,{_:p}=o(),{pages:m,loading:h}=se(),g=ie(),{activeProvider:_,activeDocName:b}=i(),S,C;t[0]===n?(S=t[1],C=t[2]):(S=[`page-headings`,n],C=()=>le(n),t[0]=n,t[1]=S,t[2]=C);let A;t[3]!==n||t[4]!==h||t[5]!==m?(A=!h&&(m.has(n)||oe(n)),t[3]=n,t[4]=h,t[5]=m,t[6]=A):A=t[6];let j;t[7]!==S||t[8]!==C||t[9]!==A?(j={queryKey:S,queryFn:C,enabled:A,staleTime:1/0},t[7]=S,t[8]=C,t[9]=A,t[10]=j):j=t[10];let{data:N,isLoading:P,error:F}=c(j),I;t[11]===N?I=t[12]:(I=N===void 0?[]:N,t[11]=N,t[12]=I);let L=I,R,z;t[13]!==b||t[14]!==_||t[15]!==n||t[16]!==g?(R=()=>{if(!_||b!==n)return;let e=_.document,t=null,r=()=>{t!==null&&clearTimeout(t),t=setTimeout(()=>{t=null,g.invalidateQueries({queryKey:[`page-headings`,n]})},ce)};return e.on(`update`,r),()=>{e.off(`update`,r),t!==null&&clearTimeout(t)}},z=[_,b,n,g],t[13]=b,t[14]=_,t[15]=n,t[16]=g,t[17]=R,t[18]=z):(R=t[17],z=t[18]),(0,v.useEffect)(R,z);let B;t[19]===L?B=t[20]:(B=L.map(M),t[19]=L,t[20]=B);let V=w(B,r),H;t[21]!==V||t[22]!==L?(H=V?L.findIndex(e=>e.slug===V):-1,t[21]=V,t[22]=L,t[23]=H):H=t[23];let U=H,W;t[24]!==n||t[25]!==r?(W=function(e,t){let i={index:e,slug:t,mode:r?`source`:`wysiwyg`};i.mode===`source`&&x(n,{kind:`outline`,detail:i}),window.dispatchEvent(new CustomEvent(k,{detail:i}))},t[24]=n,t[25]=r,t[26]=W):W=t[26];let G=W,K=((U>=0?L[U].level:1)-1)*D+(D-O)/2,q=U*E+(E-O)/2,J;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(J=(0,T.jsx)(u,{children:(0,T.jsx)(a,{id:`dD7NPy`})}),t[27]=J):J=t[27];let Y;t[28]!==L.length||t[29]!==P?(Y=!P&&(0,T.jsx)(ne,{children:L.length}),t[28]=L.length,t[29]=P,t[30]=Y):Y=t[30];let X;t[31]===Y?X=t[32]:(X=(0,T.jsxs)(l,{children:[J,Y]}),t[31]=Y,t[32]=X);let Z;t[33]!==p||t[34]!==U||t[35]!==V||t[36]!==F||t[37]!==G||t[38]!==L||t[39]!==P||t[40]!==K||t[41]!==q?(Z=F?(0,T.jsx)(s,{className:`px-2`,children:F instanceof Error?F.message:p({id:`GuqOb1`})}):L.length===0&&!P?(0,T.jsx)(ee,{className:`px-2`,children:(0,T.jsx)(a,{id:`0BB9ID`})}):(0,T.jsxs)(`nav`,{"aria-label":p({id:`BymzO4`}),className:`relative`,children:[U>=0&&(0,T.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute left-0 top-0 rounded-full bg-primary motion-safe:[transition:transform_0.25s_var(--ease-out-strong)]`,style:{width:O,height:O,transform:`translate(${K}px, ${q}px)`}}),L.map((e,t)=>{let n=e.slug===V;return(0,T.jsx)(`button`,{type:`button`,"aria-current":n?`location`:void 0,onClick:()=>G(t,e.slug),className:ae(`w-full cursor-pointer truncate py-1.5 pe-2 text-left text-sm transition-colors`,n?`font-medium text-primary`:`text-muted-foreground hover:text-foreground`),style:{paddingLeft:`${(e.level-1)*D+20}px`},title:e.text,children:e.text},t)})]}),t[33]=p,t[34]=U,t[35]=V,t[36]=F,t[37]=G,t[38]=L,t[39]=P,t[40]=K,t[41]=q,t[42]=Z):Z=t[42];let Q;t[43]!==P||t[44]!==Z?(Q=(0,T.jsx)(te,{className:`px-3 py-2`,"aria-busy":P,children:Z}),t[43]=P,t[44]=Z,t[45]=Q):Q=t[45];let $;return t[46]!==f||t[47]!==X||t[48]!==Q?($=(0,T.jsxs)(re,{className:f,children:[X,Q]}),t[46]=f,t[47]=X,t[48]=Q,t[49]=$):$=t[49],$}function M(e){return e.slug}var N={words:0,chars:0,tokens:0},P=/[ -〿぀-ゟ゠-ヿ㐀-䶿一-鿿豈-﫿＀-￯฀-๿ក-៿]/,F=/[\p{L}\p{N}]/u,I=new Set([`text`,`inlineCode`,`code`,`tag`]),L=new Set([`html`,`definition`,`footnoteDefinition`,`yaml`,`toml`,`image`,`imageReference`,`mdxFlowExpression`,`mdxTextExpression`,`mdxjsEsm`,`rawMdxFallback`,`rawMdxFallbackMdast`]),R=new Set([`paragraph`,`heading`,`blockquote`,`list`,`listItem`,`thematicBreak`,`table`,`tableRow`,`tableCell`,`mdxJsxFlowElement`,`commentBlock`]);function z(e,t){if(!e)return;let n=e.type;if(!L.has(n)){if(I.has(n)){e.value&&(t.push(e.value),n===`code`&&t.push(`
2
2
  `));return}if(n===`wikiLink`||n===`wikiLinkEmbed`){let n=e.data?.alias??e.value??``;n&&t.push(n);return}if(Array.isArray(e.children)){for(let n of e.children)z(n,t);if(R.has(n)&&t.length>0){let e=t[t.length-1];e&&!e.endsWith(`
3
3
  `)&&t.push(`
4
4
  `)}}}}function B(e){try{let t=f().parseToMdast(e),n=[];return z(t,n),n.join(``).trim()}catch(t){return console.warn(`[document-stats] mdast parse failed, falling back to raw text`,t),e.trim()}}function V(e){if(!e)return 0;let t=0;for(let n of e.split(/\s+/))F.test(n)&&t++;return t}function H(e){let t=globalThis.Intl.Segmenter;if(!t)return V(e);let n=new t(void 0,{granularity:`word`}),r=0;for(let t of n.segment(e))t.isWordLike&&r++;return r}function U(e){let t=P.test(e)?1.5:4;return Math.ceil(e.length/t)}function W(e){return e?{words:P.test(e)?H(e):V(e),chars:e.length,tokens:U(e)}:{words:0,chars:0,tokens:0}}function G(e){if(!e)return{words:0,chars:0,tokens:0};let{body:t}=p(e);return t.trim()?W(B(t)):{words:0,chars:0,tokens:0}}function K(e,{isMarkdown:t}){let n=e.trim();return n?W(t?B(e):n):N}var q=new Map,J=new Set,Y=(e,t)=>`${t}:${e}`;function X(){for(let e of J)e()}function Z(e,t,n){let r=Y(e,t);if(n===null){q.delete(r)&&X();return}let i=q.get(r);i&&i.words===n.words&&i.chars===n.chars&&i.tokens===n.tokens||(q.set(r,n),X())}function Q(e,t){return e===null?null:q.get(Y(e,t))??null}function $(e){return J.add(e),()=>{J.delete(e)}}function ue(e){let{from:t,to:n,empty:r}=e.state.selection;if(r)return null;let i=e.state.doc.textBetween(t,n,`
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CFjPhJqf.js";import{n as t}from"./compiler-runtime-CVnuRdak.js";import{r as n}from"./dist-CQw2y-s3.js";import{t as r}from"./createLucideIcon-BPhNPfG7.js";import{hn as i}from"./dist-Bj4Ae4LE.js";var a=r(`copy-plus`,[[`line`,{x1:`15`,x2:`15`,y1:`12`,y2:`18`,key:`1p7wdc`}],[`line`,{x1:`12`,x2:`18`,y1:`15`,y2:`15`,key:`1nscbv`}],[`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`}]]),o=r(`pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),s=r(`sparkles`,[[`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`}]]),c=[`global`,`project`];function l(e){return{project:new Set(e.filter(e=>e.scope===`project`).map(e=>e.name)),global:new Set(e.filter(e=>e.scope===`global`).map(e=>e.name))}}var u=`open-knowledge-pack-`;function d(e){return e.startsWith(u)?e.slice(20):e}function f(){let{_:e}=n();return{project:e({id:`e0NrBM`}),global:e({id:`2GT3Hf`})}}function p(){let{_:e}=n();return{project:e({id:`HyvSqq`}),global:e({id:`C7XjNB`})}}var m=e(t(),1);function h(){let[e]=(0,m.useState)(g);return e}function g(){return i()!=null}function _(e,t,n){let r=n===`\\`?t.replaceAll(`/`,`\\`):t;return`${e.endsWith(n)?e.slice(0,-1):e}${n}${r}`}var v=/\.(md|mdx)$/i;function y(e){return v.test(e)?e:`${e}.md`}export{d as a,p as c,a as d,c as i,s as l,_ as n,l as o,h as r,f as s,y as t,o as u};
1
+ import{o as e}from"./chunk-CFjPhJqf.js";import{n as t}from"./compiler-runtime-CVnuRdak.js";import{r as n}from"./dist-CQw2y-s3.js";import{t as r}from"./createLucideIcon-BPhNPfG7.js";import{hn as i}from"./dist-BVRsG3b2.js";var a=r(`copy-plus`,[[`line`,{x1:`15`,x2:`15`,y1:`12`,y2:`18`,key:`1p7wdc`}],[`line`,{x1:`12`,x2:`18`,y1:`15`,y2:`15`,key:`1nscbv`}],[`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`}]]),o=r(`pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),s=r(`sparkles`,[[`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`}]]),c=[`global`,`project`];function l(e){return{project:new Set(e.filter(e=>e.scope===`project`).map(e=>e.name)),global:new Set(e.filter(e=>e.scope===`global`).map(e=>e.name))}}var u=`open-knowledge-pack-`;function d(e){return e.startsWith(u)?e.slice(20):e}function f(){let{_:e}=n();return{project:e({id:`e0NrBM`}),global:e({id:`2GT3Hf`})}}function p(){let{_:e}=n();return{project:e({id:`HyvSqq`}),global:e({id:`C7XjNB`})}}var m=e(t(),1);function h(){let[e]=(0,m.useState)(g);return e}function g(){return i()!=null}function _(e,t,n){let r=n===`\\`?t.replaceAll(`/`,`\\`):t;return`${e.endsWith(n)?e.slice(0,-1):e}${n}${r}`}var v=/\.(md|mdx)$/i;function y(e){return v.test(e)?e:`${e}.md`}export{d as a,p as c,a as d,c as i,s as l,_ as n,l as o,h as r,f as s,y as t,o as u};
@@ -48,7 +48,7 @@
48
48
  -->
49
49
  <script>(() => { let t = 'system'; try { const r = localStorage.getItem('ok-theme-v1'); if (r === 'light' || r === 'dark' || r === 'system') t = r; } catch {} let dark = t === 'dark'; if (t === 'system') { try { dark = window.matchMedia('(prefers-color-scheme: dark)').matches; } catch {} } if (dark) document.documentElement.classList.add('dark'); if (window.okDesktop) document.documentElement.classList.add('electron-mode'); })();</script>
50
50
  <style>html { background-color: #fafafa } html.dark { background-color: #171717 }</style>
51
- <script type="module" crossorigin src="./assets/index-DZyzbLiq.js"></script>
51
+ <script type="module" crossorigin src="./assets/index-FeSh48__.js"></script>
52
52
  <link rel="modulepreload" crossorigin href="./assets/chunk-CFjPhJqf.js">
53
53
  <link rel="modulepreload" crossorigin href="./assets/preload-helper-2ej06EnG.js">
54
54
  <link rel="modulepreload" crossorigin href="./assets/w3c-keyname-CRPBoZED.js">
@@ -64,11 +64,11 @@
64
64
  <link rel="modulepreload" crossorigin href="./assets/stex-Bt71ugp5.js">
65
65
  <link rel="modulepreload" crossorigin href="./assets/floating-ui.dom-B3TJy2Tg.js">
66
66
  <link rel="modulepreload" crossorigin href="./assets/trace-api-BIWqyPc9.js">
67
- <link rel="modulepreload" crossorigin href="./assets/dist-Bj4Ae4LE.js">
67
+ <link rel="modulepreload" crossorigin href="./assets/dist-BVRsG3b2.js">
68
68
  <link rel="modulepreload" crossorigin href="./assets/compiler-runtime-CVnuRdak.js">
69
69
  <link rel="modulepreload" crossorigin href="./assets/dist-BVOt51sU.js">
70
70
  <link rel="modulepreload" crossorigin href="./assets/config-context-B9tR3DuQ.js">
71
- <link rel="modulepreload" crossorigin href="./assets/config-provider-DJpUWM8E.js">
71
+ <link rel="modulepreload" crossorigin href="./assets/config-provider-CFiLGdZF.js">
72
72
  <link rel="modulepreload" crossorigin href="./assets/dist-BRGTi0a4.js">
73
73
  <link rel="modulepreload" crossorigin href="./assets/dist-CQw2y-s3.js">
74
74
  <link rel="modulepreload" crossorigin href="./assets/createLucideIcon-BPhNPfG7.js">
@@ -76,15 +76,15 @@
76
76
  <link rel="modulepreload" crossorigin href="./assets/trash-2-DuQrfywu.js">
77
77
  <link rel="modulepreload" crossorigin href="./assets/triangle-alert-CX4BgEzP.js">
78
78
  <link rel="modulepreload" crossorigin href="./assets/react-dom-C-oc-P2K.js">
79
- <link rel="modulepreload" crossorigin href="./assets/doc-hash-BvJ4F5wQ.js">
80
- <link rel="modulepreload" crossorigin href="./assets/navigation-targets-B1j0YdRn.js">
79
+ <link rel="modulepreload" crossorigin href="./assets/doc-hash-CmkGIiUd.js">
80
+ <link rel="modulepreload" crossorigin href="./assets/navigation-targets-G6yEVp6c.js">
81
81
  <link rel="modulepreload" crossorigin href="./assets/external-link-Ds9yTh4D.js">
82
82
  <link rel="modulepreload" crossorigin href="./assets/documents-fetch-B7M_d64D.js">
83
- <link rel="modulepreload" crossorigin href="./assets/CodeMirrorPropInput-B1vWorID.js">
84
- <link rel="modulepreload" crossorigin href="./assets/dist-C9FdwUZB.js">
85
- <link rel="modulepreload" crossorigin href="./assets/documents-events-KDHNhdfV.js">
83
+ <link rel="modulepreload" crossorigin href="./assets/CodeMirrorPropInput-CHf8Iz40.js">
84
+ <link rel="modulepreload" crossorigin href="./assets/dist-DSzqChbc.js">
85
+ <link rel="modulepreload" crossorigin href="./assets/documents-events-CBqhEmHl.js">
86
86
  <link rel="modulepreload" crossorigin href="./assets/parse-api-error-CKwNHPHP.js">
87
- <link rel="modulepreload" crossorigin href="./assets/open-managed-artifact-tab-BThYnqZz.js">
87
+ <link rel="modulepreload" crossorigin href="./assets/open-managed-artifact-tab-acLO8au6.js">
88
88
  <link rel="modulepreload" crossorigin href="./assets/dist-BhVkC6Rc.js">
89
89
  <link rel="modulepreload" crossorigin href="./assets/dist-jyqE5kfZ.js">
90
90
  <link rel="modulepreload" crossorigin href="./assets/propagation-api-M_AcuP6N.js">
@@ -101,44 +101,44 @@
101
101
  <link rel="modulepreload" crossorigin href="./assets/copy-D8YVE0Jc.js">
102
102
  <link rel="modulepreload" crossorigin href="./assets/CopyButton-DoEsGDa4.js">
103
103
  <link rel="modulepreload" crossorigin href="./assets/startup-marks-DkfPsa68.js">
104
- <link rel="modulepreload" crossorigin href="./assets/prop-types-CADDENK9.js">
105
- <link rel="modulepreload" crossorigin href="./assets/workspace-paths-GEb_gilm.js">
104
+ <link rel="modulepreload" crossorigin href="./assets/prop-types-6gA_YVnm.js">
105
+ <link rel="modulepreload" crossorigin href="./assets/workspace-paths-Dj3MgOE7.js">
106
106
  <link rel="modulepreload" crossorigin href="./assets/eye-W_Da58Av.js">
107
107
  <link rel="modulepreload" crossorigin href="./assets/info-DsmJgZ0m.js">
108
108
  <link rel="modulepreload" crossorigin href="./assets/loader-circle-IFoG3v_v.js">
109
109
  <link rel="modulepreload" crossorigin href="./assets/dist-B0Ibo2lT.js">
110
110
  <link rel="modulepreload" crossorigin href="./assets/file-tree-rename-validation-DcXYaYEd.js">
111
111
  <link rel="modulepreload" crossorigin href="./assets/input-tBscWWrn.js">
112
- <link rel="modulepreload" crossorigin href="./assets/DocumentContext-BhV2wOiZ.js">
112
+ <link rel="modulepreload" crossorigin href="./assets/DocumentContext-DG5n9u7B.js">
113
113
  <link rel="modulepreload" crossorigin href="./assets/checkbox-CgcvT5md.js">
114
114
  <link rel="modulepreload" crossorigin href="./assets/dist-BR1KZiCX.js">
115
- <link rel="modulepreload" crossorigin href="./assets/skills-api-C6f0gQUn.js">
115
+ <link rel="modulepreload" crossorigin href="./assets/skills-api-DvU5qnRa.js">
116
116
  <link rel="modulepreload" crossorigin href="./assets/label-DmfuSB7r.js">
117
117
  <link rel="modulepreload" crossorigin href="./assets/radio-group-DyHNJs2C.js">
118
- <link rel="modulepreload" crossorigin href="./assets/EnableSyncConfirmDialog-Ca-ry-Ae.js">
118
+ <link rel="modulepreload" crossorigin href="./assets/EnableSyncConfirmDialog-CJzmvuen.js">
119
119
  <link rel="modulepreload" crossorigin href="./assets/arrow-up-right-Bj9cWgcz.js">
120
120
  <link rel="modulepreload" crossorigin href="./assets/refresh-cw-C6wj273J.js">
121
- <link rel="modulepreload" crossorigin href="./assets/cursor-BkiD2ODR.js">
121
+ <link rel="modulepreload" crossorigin href="./assets/cursor-BsJMggkz.js">
122
122
  <link rel="modulepreload" crossorigin href="./assets/clipboard-adapter-BYqGVFAr.js">
123
- <link rel="modulepreload" crossorigin href="./assets/skill-actions-CnQtb5aQ.js">
123
+ <link rel="modulepreload" crossorigin href="./assets/skill-actions-D2r7iq9h.js">
124
124
  <link rel="modulepreload" crossorigin href="./assets/textarea-IugbKaIV.js">
125
- <link rel="modulepreload" crossorigin href="./assets/keyboard-shortcuts-9kQVtaDu.js">
126
- <link rel="modulepreload" crossorigin href="./assets/auth-state-cache-QESJRGUP.js">
125
+ <link rel="modulepreload" crossorigin href="./assets/keyboard-shortcuts-Dw2cvMMp.js">
126
+ <link rel="modulepreload" crossorigin href="./assets/auth-state-cache-BSJEl4LS.js">
127
127
  <link rel="modulepreload" crossorigin href="./assets/toggle-group-Hn7Etr9N.js">
128
128
  <link rel="modulepreload" crossorigin href="./assets/panel-HcGnbQ9h.js">
129
129
  <link rel="modulepreload" crossorigin href="./assets/format-Dfi8-r7-.js">
130
- <link rel="modulepreload" crossorigin href="./assets/selection-context-_wSKX4pT.js">
131
- <link rel="modulepreload" crossorigin href="./assets/PropertyPanel-CDFSWToc.js">
130
+ <link rel="modulepreload" crossorigin href="./assets/selection-context-8HFgCBJz.js">
131
+ <link rel="modulepreload" crossorigin href="./assets/PropertyPanel-DUZsqzTw.js">
132
132
  <link rel="modulepreload" crossorigin href="./assets/miss-dialog-store-E61ZbtU3.js">
133
- <link rel="modulepreload" crossorigin href="./assets/pending-receive-nav-store-D9kW0zL5.js">
133
+ <link rel="modulepreload" crossorigin href="./assets/pending-receive-nav-store-omPUhaeY.js">
134
134
  <link rel="modulepreload" crossorigin href="./assets/chevron-left-aRnXScdx.js">
135
- <link rel="modulepreload" crossorigin href="./assets/agent-presence-CR_Kl3f1.js">
136
- <link rel="modulepreload" crossorigin href="./assets/typing-burst-detector--_GJ5sz1.js">
135
+ <link rel="modulepreload" crossorigin href="./assets/agent-presence-Dl0E_LN8.js">
136
+ <link rel="modulepreload" crossorigin href="./assets/typing-burst-detector-DP8u_tQC.js">
137
137
  <link rel="modulepreload" crossorigin href="./assets/project-paths-CqH22Xq0.js">
138
- <link rel="modulepreload" crossorigin href="./assets/file-tree-adapter-D99FaCGJ.js">
139
- <link rel="modulepreload" crossorigin href="./assets/target-navigation-intent-DszwtIOt.js">
138
+ <link rel="modulepreload" crossorigin href="./assets/file-tree-adapter-BRoSU5bE.js">
139
+ <link rel="modulepreload" crossorigin href="./assets/target-navigation-intent-DIz1qTBm.js">
140
140
  <link rel="modulepreload" crossorigin href="./assets/mcp-consent-store-Q4I4TJ6C.js">
141
- <link rel="modulepreload" crossorigin href="./assets/receive-store-1Qk9uwTc.js">
141
+ <link rel="modulepreload" crossorigin href="./assets/receive-store-CrJ3w3k0.js">
142
142
  <link rel="modulepreload" crossorigin href="./assets/worktree-store-DfQ15jw3.js">
143
143
  <link rel="stylesheet" crossorigin href="./assets/DocumentContext-B0sQn39F.css">
144
144
  <link rel="stylesheet" crossorigin href="./assets/index-C3IDVWhb.css">
@@ -1,2 +1,2 @@
1
- import{t as e}from"./launch-json-removal-bo3gNUN4.mjs";import{join as t}from"node:path";function n(n){let i=n.logger??r,a=t(n.projectDir,`.claude`,`launch.json`);if(n.reclaimDisableEnv===`1`)return i({event:`launch-json-repair-skipped`,reason:`reclaim-disabled`}),{outcome:{configPath:a,outcome:`skipped-reclaim-disabled`},repairedCount:0};let o;try{o=e(n.projectDir)}catch(e){let t=e instanceof Error?e.message:String(e);return i({event:`launch-json-repair-write-failed`,configPath:a}),{outcome:{configPath:a,outcome:`write-failed`,error:t},repairedCount:0}}let s=o.kind===`removed`||o.kind===`removed-file`;return s&&i({event:`launch-json-repair-removed`,configPath:a}),{outcome:{configPath:a,outcome:o.kind},repairedCount:s?1:0}}function r(e){process.stderr.write(`${JSON.stringify(e)}\n`)}export{n as repairLaunchJson};
2
- //# sourceMappingURL=repair-launch-json-B6nfMuDG.mjs.map
1
+ import{t as e}from"./launch-json-removal-D3x1PYMJ.mjs";import{join as t}from"node:path";function n(n){let i=n.logger??r,a=t(n.projectDir,`.claude`,`launch.json`);if(n.reclaimDisableEnv===`1`)return i({event:`launch-json-repair-skipped`,reason:`reclaim-disabled`}),{outcome:{configPath:a,outcome:`skipped-reclaim-disabled`},repairedCount:0};let o;try{o=e(n.projectDir)}catch(e){let t=e instanceof Error?e.message:String(e);return i({event:`launch-json-repair-write-failed`,configPath:a}),{outcome:{configPath:a,outcome:`write-failed`,error:t},repairedCount:0}}let s=o.kind===`removed`||o.kind===`removed-file`;return s&&i({event:`launch-json-repair-removed`,configPath:a}),{outcome:{configPath:a,outcome:o.kind},repairedCount:s?1:0}}function r(e){process.stderr.write(`${JSON.stringify(e)}\n`)}export{n as repairLaunchJson};
2
+ //# sourceMappingURL=repair-launch-json-DzczMayl.mjs.map
@@ -0,0 +1,2 @@
1
+ import{d as e,v as t}from"./init-1G9fj8cH.mjs";import{d as n,h as r,x as i}from"./write-project-skill-DV1PSHkd.mjs";import{t as a}from"./mcp-migrate-event-CyH1VVyy.mjs";import{homedir as o}from"node:os";function s(e){let t=e.logger??u,i=e.home??o(),a=[];if(e.reclaimDisableEnv===`1`)return t({event:`mcp-config-repair-skipped`,reason:`reclaim-disabled`}),{outcomes:a,repairedCount:0};for(let o of n){let n=r[o],s=c(()=>n.configPath(``,i));if(s!==null&&a.push(l({scope:`user`,editorId:o,target:n,home:i,cwd:``,configPath:s,configPathOverride:void 0,logger:t})),n.projectConfigPath){let r=n.projectConfigPath,i=c(()=>r(e.projectDir));i!==null&&a.push(l({scope:`project`,editorId:o,target:n,home:void 0,cwd:e.projectDir,configPath:i,configPathOverride:i,logger:t}))}}return{outcomes:a,repairedCount:a.filter(e=>e.outcome===`repaired`).length}}function c(e){try{return e()}catch{return null}}function l(n){let r={scope:n.scope,editorId:n.editorId,configPath:n.configPath},o=e(n.target,n.cwd,n.home,n.configPathOverride);if(o===null)return{...r,outcome:`no-entry`};if(i(o))return{...r,outcome:`canonical`};n.logger(a({scope:n.scope,surface:`cli-repair`,editorId:n.editorId,configPath:n.configPath,priorEntry:o}));let s=t(n.target,n.cwd,{mode:`published`,skipAvailabilityCheck:!0},n.home,n.configPathOverride);if(s.action===`failed`){let e=s.error??`unknown write failure`;return n.logger({event:`mcp-config-repair-write-failed`,scope:n.scope,editorId:n.editorId,configPath:n.configPath,error:e}),{...r,outcome:`write-failed`,error:e}}return s.action===`declined`?(n.logger({event:`mcp-config-repair-declined`,scope:n.scope,editorId:n.editorId,configPath:n.configPath,reason:s.declineReason}),{...r,outcome:`declined`}):{...r,outcome:`repaired`}}function u(e){process.stderr.write(`${JSON.stringify(e)}\n`)}export{s as repairMcpConfigs};
2
+ //# sourceMappingURL=repair-mcp-configs-Cp5VRehu.mjs.map
@@ -0,0 +1 @@
1
+ import{t as e}from"./repair-skills-XQg-rb3q.mjs";export{e as repairSkills};
@@ -1,3 +1,3 @@
1
- import{ha as e}from"./server-lock-iLcBw_q0-nWzkxbfg.mjs";import{Gr as t,Ir as n,Pr as r,Vr as i,Zr as a,aa as o,d as s,lt as c,ta as l}from"./dist-Pe1Q8dMj.mjs";import{t as u}from"./esm-CsQUg9js.mjs";import{a as d,d as f,f as p,t as m}from"./write-project-skill-DyoxYjJB.mjs";import{dirname as h,join as g,resolve as _}from"node:path";import{homedir as v}from"node:os";import{existsSync as y,mkdirSync as b,readFileSync as x,readdirSync as S,rmSync as C,statSync as w,writeFileSync as T}from"node:fs";const E={existsSync:e=>y(e),isDirectory:e=>{try{return w(e).isDirectory()}catch(e){if(e.code===`ENOENT`)return!1;throw e}},readdirSync:e=>S(e),readFileSync:e=>x(e),writeFileSync:(e,t)=>{T(e,t)},mkdirSync:(e,t)=>{b(e,t)},rmSync:(e,t)=>{C(e,t)}},D={resolveProjectBundledSkillDir:()=>a(`project`,{checkDesktop:!1}),resolveUserBundledSkillDir:e=>a(e,{checkDesktop:!1}),readBundledVersion:()=>n(),readRecordedVersion:e=>i(e,`cli-hosts`),writeRecordedVersion:(e,t)=>o(e,`cli-hosts`,t,`cli-start`),recordEvent:e=>t(e),readBundleDecision:(e,t)=>r(e,t),writeBundleDecision:(e,t,n)=>l(e,t,n),removeBundleFromDisk:(e,t)=>d(e,t)};function O(e){process.stderr.write(`${JSON.stringify(e)}\n`)}function k(e,t,n){n.rmSync(t,{recursive:!0,force:!0}),n.mkdirSync(h(t),{recursive:!0}),A(e,t,n)}function A(e,t,n){n.mkdirSync(t,{recursive:!0});for(let r of n.readdirSync(e)){let i=g(e,r),a=g(t,r);n.isDirectory(i)?A(i,a,n):n.writeFileSync(a,n.readFileSync(i))}}function j(e,t,n,r,i,a){let o=[],s=g(e,`.agents`,`skills`,t),c=r.existsSync(s),l=!1;try{k(n,s,r),l=!0,o.push({kind:`central`,path:s,outcome:c?`overwritten`:`written`}),i({event:`user-skill-reclaim-central-written`,scope:`user`,path:s,preexisting:c,version:a})}catch(e){let t=e instanceof Error?e.message:String(e);o.push({kind:`central`,path:s,outcome:`failed`,error:t}),i({event:`user-skill-reclaim-central-failed`,scope:`user`,path:s,error:t})}for(let c of p){let l=g(e,c.hostDir),u=g(l,`skills`,t);if(u===s){o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:`skipped-collapsed-with-central`});continue}if(!r.existsSync(l)){o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:`skipped-host-absent`});continue}let d=r.existsSync(u);try{k(n,u,r),o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:d?`overwritten`:`written`}),i({event:`user-skill-reclaim-host-written`,scope:`user`,editorId:c.editorId,hostDir:c.hostDir,path:u,preexisting:d,version:a})}catch(e){let t=e instanceof Error?e.message:String(e);o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:`failed`,error:t}),i({event:`user-skill-reclaim-host-failed`,scope:`user`,editorId:c.editorId,hostDir:c.hostDir,path:u,error:t})}}return{entries:o,centralWritten:l}}function M(e,t){if(!e)return!1;try{if(!t.existsSync(e))return!1;let n=t.readFileSync(e).toString(`utf8`);return n.includes(`# ok-mcp-v1`)||n.includes(`# ok-mcp-win-v1`)}catch{return!1}}function N(e,t,n,r){let i;try{i=t.resolveProjectBundledSkillDir()}catch(e){return r({event:`project-skill-reclaim-bundle-missing`,scope:`project`,error:e instanceof Error?e.message:String(e)}),{outcome:`skipped`,reason:`bundle-missing`}}let a=[];for(let t of p){let o=g(e,t.hostDir,`skills`,`open-knowledge`),s=g(o,`SKILL.md`),c=n.existsSync(s),l=f[t.editorId]?.projectConfigPath?.(e),u=!c&&M(l,n);if(!c&&!u){a.push({editorId:t.editorId,hostDir:t.hostDir,path:o,outcome:`no-token`}),r({event:`project-skill-reclaim-no-token`,scope:`project`,editorId:t.editorId,path:o});continue}try{m(o,e),k(i,o,n);let s=c?`reclaimed`:`created`;a.push({editorId:t.editorId,hostDir:t.hostDir,path:o,outcome:s}),r({event:c?`project-skill-reclaim-reclaimed`:`project-skill-reclaim-created`,scope:`project`,editorId:t.editorId,path:o})}catch(e){let n=e instanceof Error?e.message:String(e);a.push({editorId:t.editorId,hostDir:t.hostDir,path:o,outcome:`failed`,error:n}),r({event:`project-skill-reclaim-failed`,scope:`project`,editorId:t.editorId,path:o,error:n})}}return{outcome:`done`,entries:a}}async function P(t,n,r,i){let a=e=>{n.recordEvent(e).catch(()=>{})},o=()=>new Date().toISOString(),l;try{l=await n.readBundledVersion()}catch(e){let t=e instanceof Error?e.message:String(e);return i({event:`user-skill-reclaim-version-read-failed`,scope:`user`,error:t}),a({ts:o(),surface:`cli-start`,target:`cli-hosts`,bundle:`discovery`,outcome:`failed`,reason:`version-read-failed:${t}`}),{outcome:`skipped`,reason:`version-read-failed`}}let u;try{u=await n.readRecordedVersion(t)}catch(e){i({event:`user-skill-reclaim-version-read-error`,scope:`user`,error:e instanceof Error?e.message:String(e)}),u=null}let d=[],f=null;for(let e of c)try{d.push({id:e,sourceDir:n.resolveUserBundledSkillDir(e)})}catch(e){f=e instanceof Error?e.message:String(e)}if(d.length===0)return i({event:`user-skill-reclaim-bundle-missing`,scope:`user`,error:f??`no user-global bundles`}),a({ts:o(),surface:`cli-start`,target:`cli-hosts`,outcome:`failed`,reason:`bundle-missing:${f}`}),{outcome:`skipped`,reason:`bundle-missing`};let p=[];for(let a of d){let o=s[a.id],c=r.existsSync(g(t,`.agents`,`skills`,o)),l=await n.readBundleDecision(t,o).catch(()=>null);if(!e(l,{installedOnDisk:c})){if(c)try{n.removeBundleFromDisk(t,a.id),i({event:`user-skill-reclaim-bundle-declined-removed`,scope:`user`,bundle:a.id})}catch(e){i({event:`user-skill-reclaim-bundle-remove-failed`,scope:`user`,bundle:a.id,error:e instanceof Error?e.message:String(e)})}continue}if(l===null&&c)try{await n.writeBundleDecision(t,o,!0)}catch(e){i({event:`user-skill-reclaim-grandfather-write-failed`,scope:`user`,bundle:a.id,error:e instanceof Error?e.message:String(e)})}p.push(a)}if(p.length===0)return{outcome:`skipped`,reason:`all-bundles-declined`};let m=p.every(e=>r.existsSync(g(t,`.agents`,`skills`,s[e.id])));if(u!==null&&u===l&&m)return i({event:`user-skill-reclaim-skipped-version-current`,scope:`user`,version:l}),{outcome:`skipped`,reason:`version-current`};let h=[],_=d.length===c.length,v=!0;for(let{id:e,sourceDir:n}of p){let a=j(t,s[e],n,r,i,l);h.push(...a.entries),a.centralWritten||(v=!1)}let y=h.some(e=>e.kind===`central`&&(e.outcome===`written`||e.outcome===`overwritten`));if(_&&v&&y){let e=null;try{await n.writeRecordedVersion(t,l),i({event:`user-skill-reclaim-version-recorded`,scope:`user`,version:l})}catch(t){e=t instanceof Error?t.message:String(t),i({event:`user-skill-reclaim-version-record-failed`,scope:`user`,version:l,error:e})}for(let{id:t}of p)a({ts:o(),surface:`cli-start`,target:`cli-hosts`,bundle:t,outcome:e===null?`installed`:`failed`,version:l,...e===null?{}:{reason:`state-write-failed:${e}`}})}else{let e=h.some(e=>e.kind===`host`&&e.outcome===`failed`);a({ts:o(),surface:`cli-start`,target:`cli-hosts`,outcome:`failed`,version:l,reason:e?`all-writes-failed`:`no-hosts-installed`})}return{outcome:`done`,version:l,entries:h}}async function F(e){let t=e.logger??O,n=e.fs??E,r=e.home??v(),i={...D,...e.deps};return e.reclaimDisableEnv===`1`?(t({event:`skill-repair-skipped`,reason:`reclaim-disabled`}),{status:`skipped`,reason:`reclaim-disabled`}):{status:`done`,project:N(e.projectDir,i,n,t),user:await P(r,i,n,t)}}function I(e){return e.status===`skipped`?e.reason===`reclaim-disabled`?0:1:e.project.outcome===`skipped`||e.user.outcome===`skipped`&&e.user.reason!==`version-current`&&e.user.reason!==`all-bundles-declined`||e.project.entries.some(e=>e.outcome===`failed`)||e.user.outcome===`done`&&e.user.entries.some(e=>e.outcome===`failed`)?1:0}function L(e){if(e.status===`skipped`)return`Skipped: ${e.reason}`;let t=[`Skill reclaim complete.`];if(e.project.outcome===`done`){let n=e.project.entries.filter(e=>e.outcome===`reclaimed`).length,r=e.project.entries.filter(e=>e.outcome===`created`).length,i=e.project.entries.filter(e=>e.outcome===`no-token`).length,a=e.project.entries.filter(e=>e.outcome===`failed`).length;t.push(` Project: ${n} reclaimed, ${r} created, ${i} no-token, ${a} failed.`)}else t.push(` Project: skipped (${e.project.reason}).`);if(e.user.outcome===`done`){let n=e.user.entries.filter(e=>e.outcome===`written`||e.outcome===`overwritten`).length,r=e.user.entries.filter(e=>e.outcome===`skipped-host-absent`||e.outcome===`skipped-collapsed-with-central`).length,i=e.user.entries.filter(e=>e.outcome===`failed`).length;t.push(` User (${e.user.version}): ${n} written, ${r} skipped, ${i} failed.`)}else t.push(` User: skipped (${e.user.reason}).`);return t.join(`
1
+ import{ha as e}from"./server-lock-iLcBw_q0-DddnIrHS.mjs";import{Gr as t,Ir as n,Pr as r,Vr as i,Zr as a,aa as o,d as s,lt as c,ta as l}from"./dist-CynAX6cy.mjs";import{t as u}from"./esm-CsQUg9js.mjs";import{g as d,h as f,l as p,t as m}from"./write-project-skill-DV1PSHkd.mjs";import{dirname as h,join as g,resolve as _}from"node:path";import{homedir as v}from"node:os";import{existsSync as y,mkdirSync as b,readFileSync as x,readdirSync as S,rmSync as C,statSync as w,writeFileSync as T}from"node:fs";const E={existsSync:e=>y(e),isDirectory:e=>{try{return w(e).isDirectory()}catch(e){if(e.code===`ENOENT`)return!1;throw e}},readdirSync:e=>S(e),readFileSync:e=>x(e),writeFileSync:(e,t)=>{T(e,t)},mkdirSync:(e,t)=>{b(e,t)},rmSync:(e,t)=>{C(e,t)}},D={resolveProjectBundledSkillDir:()=>a(`project`,{checkDesktop:!1}),resolveUserBundledSkillDir:e=>a(e,{checkDesktop:!1}),readBundledVersion:()=>n(),readRecordedVersion:e=>i(e,`cli-hosts`),writeRecordedVersion:(e,t)=>o(e,`cli-hosts`,t,`cli-start`),recordEvent:e=>t(e),readBundleDecision:(e,t)=>r(e,t),writeBundleDecision:(e,t,n)=>l(e,t,n),removeBundleFromDisk:(e,t)=>p(e,t)};function O(e){process.stderr.write(`${JSON.stringify(e)}\n`)}function k(e,t,n){n.rmSync(t,{recursive:!0,force:!0}),n.mkdirSync(h(t),{recursive:!0}),A(e,t,n)}function A(e,t,n){n.mkdirSync(t,{recursive:!0});for(let r of n.readdirSync(e)){let i=g(e,r),a=g(t,r);n.isDirectory(i)?A(i,a,n):n.writeFileSync(a,n.readFileSync(i))}}function j(e,t,n,r,i,a){let o=[],s=g(e,`.agents`,`skills`,t),c=r.existsSync(s),l=!1;try{k(n,s,r),l=!0,o.push({kind:`central`,path:s,outcome:c?`overwritten`:`written`}),i({event:`user-skill-reclaim-central-written`,scope:`user`,path:s,preexisting:c,version:a})}catch(e){let t=e instanceof Error?e.message:String(e);o.push({kind:`central`,path:s,outcome:`failed`,error:t}),i({event:`user-skill-reclaim-central-failed`,scope:`user`,path:s,error:t})}for(let c of d){let l=g(e,c.hostDir),u=g(l,`skills`,t);if(u===s){o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:`skipped-collapsed-with-central`});continue}if(!r.existsSync(l)){o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:`skipped-host-absent`});continue}let d=r.existsSync(u);try{k(n,u,r),o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:d?`overwritten`:`written`}),i({event:`user-skill-reclaim-host-written`,scope:`user`,editorId:c.editorId,hostDir:c.hostDir,path:u,preexisting:d,version:a})}catch(e){let t=e instanceof Error?e.message:String(e);o.push({kind:`host`,editorId:c.editorId,hostDir:c.hostDir,path:u,outcome:`failed`,error:t}),i({event:`user-skill-reclaim-host-failed`,scope:`user`,editorId:c.editorId,hostDir:c.hostDir,path:u,error:t})}}return{entries:o,centralWritten:l}}function M(e,t){if(!e)return!1;try{if(!t.existsSync(e))return!1;let n=t.readFileSync(e).toString(`utf8`);return n.includes(`# ok-mcp-v1`)||n.includes(`# ok-mcp-win-v1`)}catch{return!1}}function N(e,t,n,r){let i;try{i=t.resolveProjectBundledSkillDir()}catch(e){return r({event:`project-skill-reclaim-bundle-missing`,scope:`project`,error:e instanceof Error?e.message:String(e)}),{outcome:`skipped`,reason:`bundle-missing`}}let a=[];for(let t of d){let o=g(e,t.hostDir,`skills`,`open-knowledge`),s=g(o,`SKILL.md`),c=n.existsSync(s),l=f[t.editorId]?.projectConfigPath?.(e),u=!c&&M(l,n);if(!c&&!u){a.push({editorId:t.editorId,hostDir:t.hostDir,path:o,outcome:`no-token`}),r({event:`project-skill-reclaim-no-token`,scope:`project`,editorId:t.editorId,path:o});continue}try{m(o,e),k(i,o,n);let s=c?`reclaimed`:`created`;a.push({editorId:t.editorId,hostDir:t.hostDir,path:o,outcome:s}),r({event:c?`project-skill-reclaim-reclaimed`:`project-skill-reclaim-created`,scope:`project`,editorId:t.editorId,path:o})}catch(e){let n=e instanceof Error?e.message:String(e);a.push({editorId:t.editorId,hostDir:t.hostDir,path:o,outcome:`failed`,error:n}),r({event:`project-skill-reclaim-failed`,scope:`project`,editorId:t.editorId,path:o,error:n})}}return{outcome:`done`,entries:a}}async function P(t,n,r,i){let a=e=>{n.recordEvent(e).catch(()=>{})},o=()=>new Date().toISOString(),l;try{l=await n.readBundledVersion()}catch(e){let t=e instanceof Error?e.message:String(e);return i({event:`user-skill-reclaim-version-read-failed`,scope:`user`,error:t}),a({ts:o(),surface:`cli-start`,target:`cli-hosts`,bundle:`discovery`,outcome:`failed`,reason:`version-read-failed:${t}`}),{outcome:`skipped`,reason:`version-read-failed`}}let u;try{u=await n.readRecordedVersion(t)}catch(e){i({event:`user-skill-reclaim-version-read-error`,scope:`user`,error:e instanceof Error?e.message:String(e)}),u=null}let d=[],f=null;for(let e of c)try{d.push({id:e,sourceDir:n.resolveUserBundledSkillDir(e)})}catch(e){f=e instanceof Error?e.message:String(e)}if(d.length===0)return i({event:`user-skill-reclaim-bundle-missing`,scope:`user`,error:f??`no user-global bundles`}),a({ts:o(),surface:`cli-start`,target:`cli-hosts`,outcome:`failed`,reason:`bundle-missing:${f}`}),{outcome:`skipped`,reason:`bundle-missing`};let p=[];for(let a of d){let o=s[a.id],c=r.existsSync(g(t,`.agents`,`skills`,o)),l=await n.readBundleDecision(t,o).catch(()=>null);if(!e(l,{installedOnDisk:c})){if(c)try{n.removeBundleFromDisk(t,a.id),i({event:`user-skill-reclaim-bundle-declined-removed`,scope:`user`,bundle:a.id})}catch(e){i({event:`user-skill-reclaim-bundle-remove-failed`,scope:`user`,bundle:a.id,error:e instanceof Error?e.message:String(e)})}continue}if(l===null&&c)try{await n.writeBundleDecision(t,o,!0)}catch(e){i({event:`user-skill-reclaim-grandfather-write-failed`,scope:`user`,bundle:a.id,error:e instanceof Error?e.message:String(e)})}p.push(a)}if(p.length===0)return{outcome:`skipped`,reason:`all-bundles-declined`};let m=p.every(e=>r.existsSync(g(t,`.agents`,`skills`,s[e.id])));if(u!==null&&u===l&&m)return i({event:`user-skill-reclaim-skipped-version-current`,scope:`user`,version:l}),{outcome:`skipped`,reason:`version-current`};let h=[],_=d.length===c.length,v=!0;for(let{id:e,sourceDir:n}of p){let a=j(t,s[e],n,r,i,l);h.push(...a.entries),a.centralWritten||(v=!1)}let y=h.some(e=>e.kind===`central`&&(e.outcome===`written`||e.outcome===`overwritten`));if(_&&v&&y){let e=null;try{await n.writeRecordedVersion(t,l),i({event:`user-skill-reclaim-version-recorded`,scope:`user`,version:l})}catch(t){e=t instanceof Error?t.message:String(t),i({event:`user-skill-reclaim-version-record-failed`,scope:`user`,version:l,error:e})}for(let{id:t}of p)a({ts:o(),surface:`cli-start`,target:`cli-hosts`,bundle:t,outcome:e===null?`installed`:`failed`,version:l,...e===null?{}:{reason:`state-write-failed:${e}`}})}else{let e=h.some(e=>e.kind===`host`&&e.outcome===`failed`);a({ts:o(),surface:`cli-start`,target:`cli-hosts`,outcome:`failed`,version:l,reason:e?`all-writes-failed`:`no-hosts-installed`})}return{outcome:`done`,version:l,entries:h}}async function F(e){let t=e.logger??O,n=e.fs??E,r=e.home??v(),i={...D,...e.deps};return e.reclaimDisableEnv===`1`?(t({event:`skill-repair-skipped`,reason:`reclaim-disabled`}),{status:`skipped`,reason:`reclaim-disabled`}):{status:`done`,project:N(e.projectDir,i,n,t),user:await P(r,i,n,t)}}function I(e){return e.status===`skipped`?e.reason===`reclaim-disabled`?0:1:e.project.outcome===`skipped`||e.user.outcome===`skipped`&&e.user.reason!==`version-current`&&e.user.reason!==`all-bundles-declined`||e.project.entries.some(e=>e.outcome===`failed`)||e.user.outcome===`done`&&e.user.entries.some(e=>e.outcome===`failed`)?1:0}function L(e){if(e.status===`skipped`)return`Skipped: ${e.reason}`;let t=[`Skill reclaim complete.`];if(e.project.outcome===`done`){let n=e.project.entries.filter(e=>e.outcome===`reclaimed`).length,r=e.project.entries.filter(e=>e.outcome===`created`).length,i=e.project.entries.filter(e=>e.outcome===`no-token`).length,a=e.project.entries.filter(e=>e.outcome===`failed`).length;t.push(` Project: ${n} reclaimed, ${r} created, ${i} no-token, ${a} failed.`)}else t.push(` Project: skipped (${e.project.reason}).`);if(e.user.outcome===`done`){let n=e.user.entries.filter(e=>e.outcome===`written`||e.outcome===`overwritten`).length,r=e.user.entries.filter(e=>e.outcome===`skipped-host-absent`||e.outcome===`skipped-collapsed-with-central`).length,i=e.user.entries.filter(e=>e.outcome===`failed`).length;t.push(` User (${e.user.version}): ${n} written, ${r} skipped, ${i} failed.`)}else t.push(` User: skipped (${e.user.reason}).`);return t.join(`
2
2
  `)}function R(){return new u(`repair-skills`).description("Refresh bundled SKILL.md files for installed AI editors (project-local + user-global). Runs automatically during `ok start`; this command forces an explicit sweep.").action(async()=>{let e=await F({projectDir:_(process.cwd()),reclaimDisableEnv:process.env.OK_RECLAIM_DISABLE??null});process.stdout.write(`${L(e)}\n`),process.exitCode=I(e)})}export{R as n,F as t};
3
- //# sourceMappingURL=repair-skills-DuNm-kMp.mjs.map
3
+ //# sourceMappingURL=repair-skills-XQg-rb3q.mjs.map
@@ -0,0 +1 @@
1
+ import{_ as e,f as t,y as n}from"./server-lock-iLcBw_q0-DddnIrHS.mjs";export{t as markServerLockDraining,e as releaseServerLock,n as updateServerLockPort};
@@ -301,7 +301,7 @@ Read more at https://docs.orama.com/docs/orama-js/plugins/plugin-secure-proxy#pl
301
301
  `,PLUGIN_SECURE_PROXY_MISSING_CHAT_MODEL:`Could not find a chat model defined in the secure proxy plugin configuration.
302
302
  Please provide a chat model before proceeding with creating an answer session.
303
303
  Read more at https://docs.orama.com/docs/orama-js/plugins/plugin-secure-proxy#plugin-secure-proxy
304
- `,ANSWER_SESSION_LAST_MESSAGE_IS_NOT_ASSISTANT:`The last message in the session is not an assistant message. Cannot regenerate non-assistant messages.`,PLUGIN_COMPONENT_CONFLICT:`The component "%s" is already defined. The plugin "%s" is trying to redefine it.`};function mH(e,...t){let n=Error(GV(pH[e]??`Unsupported Orama Error code: ${e}`,...t));return n.code=e,`captureStackTrace`in Error.prototype&&Error.captureStackTrace(n),n}function hH(e){return{raw:Number(e),formatted:YV(e)}}function gH(e){if(e.id){if(typeof e.id!=`string`)throw mH(`DOCUMENT_ID_MUST_BE_STRING`,typeof e.id);return e.id}return ZV()}function _H(e,t){for(let[n,r]of Object.entries(t)){let t=e[n];if(t!==void 0&&!(r===`geopoint`&&typeof t==`object`&&typeof t.lon==`number`&&typeof t.lat==`number`)&&!(r===`enum`&&(typeof t==`string`||typeof t==`number`))){if(r===`enum[]`&&Array.isArray(t)){let e=t.length;for(let r=0;r<e;r++)if(typeof t[r]!=`string`&&typeof t[r]!=`number`)return n+`.`+r;continue}if(xH(r)){let e=wH(r);if(!Array.isArray(t)||t.length!==e)throw mH(`INVALID_INPUT_VECTOR`,n,e,t.length);continue}if(SH(r)){if(!Array.isArray(t))return n;let e=CH(r),i=t.length;for(let r=0;r<i;r++)if(typeof t[r]!==e)return n+`.`+r;continue}if(typeof r==`object`){if(!t||typeof t!=`object`)return n;let e=_H(t,r);if(e)return n+`.`+e;continue}if(typeof t!==r)return n}}}const vH={string:!1,number:!1,boolean:!1,enum:!1,geopoint:!1,"string[]":!0,"number[]":!0,"boolean[]":!0,"enum[]":!0},yH={"string[]":`string`,"number[]":`number`,"boolean[]":`boolean`,"enum[]":`enum`};function bH(e){return e===`geopoint`}function xH(e){return typeof e==`string`&&/^vector\[\d+\]$/.test(e)}function SH(e){return typeof e==`string`&&vH[e]}function CH(e){return yH[e]}function wH(e){let t=Number(e.slice(7,-1));switch(!0){case isNaN(t):throw mH(`INVALID_VECTOR_VALUE`,e);case t<=0:throw mH(`INVALID_VECTOR_SIZE`,e);default:return t}}function TH(){return{idToInternalId:new Map,internalIdToId:[],save:EH,load:DH}}function EH(e){return{internalIdToId:e.internalIdToId}}function DH(e,t){let{internalIdToId:n}=t;e.internalDocumentIDStore.idToInternalId.clear(),e.internalDocumentIDStore.internalIdToId=[];let r=n.length;for(let t=0;t<r;t++){let r=n[t];e.internalDocumentIDStore.idToInternalId.set(r,t+1),e.internalDocumentIDStore.internalIdToId.push(r)}}function OH(e,t){if(typeof t==`string`){let n=e.idToInternalId.get(t);if(n)return n;let r=e.idToInternalId.size+1;return e.idToInternalId.set(t,r),e.internalIdToId.push(t),r}return t>e.internalIdToId.length?OH(e,t.toString()):t}function kH(e,t){if(e.internalIdToId.length<t)throw Error(`Invalid internalId ${t}`);return e.internalIdToId[t-1]}function AH(e,t){return{sharedInternalDocumentStore:t,docs:{},count:0}}function jH(e,t){let n=OH(e.sharedInternalDocumentStore,t);return e.docs[n]}function MH(e,t){let n=t.length,r=Array.from({length:n});for(let i=0;i<n;i++){let n=OH(e.sharedInternalDocumentStore,t[i]);r[i]=e.docs[n]}return r}function NH(e){return e.docs}function PH(e,t,n,r){return e.docs[n]===void 0?(e.docs[n]=r,e.count++,!0):!1}function FH(e,t){let n=OH(e.sharedInternalDocumentStore,t);return e.docs[n]===void 0?!1:(delete e.docs[n],e.count--,!0)}function IH(e){return e.count}function LH(e,t){let n=t;return{docs:n.docs,count:n.count,sharedInternalDocumentStore:e}}function RH(e){return{docs:e.docs,count:e.count}}function zH(){return{create:AH,get:jH,getMultiple:MH,getAll:NH,store:PH,remove:FH,count:IH,load:LH,save:RH}}const BH=[`beforeInsert`,`afterInsert`,`beforeRemove`,`afterRemove`,`beforeUpdate`,`afterUpdate`,`beforeUpsert`,`afterUpsert`,`beforeSearch`,`afterSearch`,`beforeInsertMultiple`,`afterInsertMultiple`,`beforeRemoveMultiple`,`afterRemoveMultiple`,`beforeUpdateMultiple`,`afterUpdateMultiple`,`beforeUpsertMultiple`,`afterUpsertMultiple`,`beforeLoad`,`afterLoad`,`afterCreate`];function VH(e,t){let n=[],r=e.plugins?.length;if(!r)return n;for(let i=0;i<r;i++)try{let r=e.plugins[i];typeof r[t]==`function`&&n.push(r[t])}catch(e){throw console.error(`Caught error in getAllPluginsByHook:`,e),mH(`PLUGIN_CRASHED`)}return n}const HH=[`tokenizer`,`index`,`documentsStore`,`sorter`,`pinning`],UH=[`validateSchema`,`getDocumentIndexId`,`getDocumentProperties`,`formatElapsedTime`];function WH(e,t,n,r){if(e.some(oH))return(async()=>{for(let i of e)await i(t,n,r)})();for(let i of e)i(t,n,r)}function GH(e,t,n){if(e.some(oH))return(async()=>{for(let r of e)await r(t,n)})();for(let r of e)r(t,n)}function KH(e,t,n,r,i){if(e.some(oH))return(async()=>{for(let a of e)await a(t,n,r,i)})();for(let a of e)a(t,n,r,i)}function qH(e,t,n,r){if(e.some(oH))return(async()=>{for(let i of e)await i(t,n,r)})();for(let i of e)i(t,n,r)}function JH(e,t){if(e.some(oH))return(async()=>{for(let n of e)await n(t)})();for(let n of e)n(t)}var YH=class e{k;v;l=null;r=null;h=1;constructor(e,t){this.k=e,this.v=new Set(t)}updateHeight(){this.h=Math.max(e.getHeight(this.l),e.getHeight(this.r))+1}static getHeight(e){return e?e.h:0}getBalanceFactor(){return e.getHeight(this.l)-e.getHeight(this.r)}rotateLeft(){let e=this.r;return this.r=e.l,e.l=this,this.updateHeight(),e.updateHeight(),e}rotateRight(){let e=this.l;return this.l=e.r,e.r=this,this.updateHeight(),e.updateHeight(),e}toJSON(){return{k:this.k,v:Array.from(this.v),l:this.l?this.l.toJSON():null,r:this.r?this.r.toJSON():null,h:this.h}}static fromJSON(t){let n=new e(t.k,t.v);return n.l=t.l?e.fromJSON(t.l):null,n.r=t.r?e.fromJSON(t.r):null,n.h=t.h,n}},XH=class e{root=null;insertCount=0;constructor(e,t){e!==void 0&&t!==void 0&&(this.root=new YH(e,t))}insert(e,t,n=1e3){this.root=this.insertNode(this.root,e,t,n)}insertMultiple(e,t,n=1e3){for(let r of t)this.insert(e,r,n)}rebalance(){this.root&&=this.rebalanceNode(this.root)}toJSON(){return{root:this.root?this.root.toJSON():null,insertCount:this.insertCount}}static fromJSON(t){let n=new e;return n.root=t.root?YH.fromJSON(t.root):null,n.insertCount=t.insertCount||0,n}insertNode(e,t,n,r){if(e===null)return new YH(t,[n]);let i=[],a=e,o=null;for(;a!==null;)if(i.push({parent:o,node:a}),t<a.k)if(a.l===null){a.l=new YH(t,[n]),i.push({parent:a,node:a.l});break}else o=a,a=a.l;else if(t>a.k)if(a.r===null){a.r=new YH(t,[n]),i.push({parent:a,node:a.r});break}else o=a,a=a.r;else return a.v.add(n),e;let s=!1;this.insertCount++%r===0&&(s=!0);for(let t=i.length-1;t>=0;t--){let{parent:n,node:r}=i[t];if(r.updateHeight(),s){let t=this.rebalanceNode(r);n?n.l===r?n.l=t:n.r===r&&(n.r=t):e=t}}return e}rebalanceNode(e){let t=e.getBalanceFactor();if(t>1){if(e.l&&e.l.getBalanceFactor()>=0)return e.rotateRight();if(e.l)return e.l=e.l.rotateLeft(),e.rotateRight()}if(t<-1){if(e.r&&e.r.getBalanceFactor()<=0)return e.rotateLeft();if(e.r)return e.r=e.r.rotateRight(),e.rotateLeft()}return e}find(e){let t=this.findNodeByKey(e);return t?t.v:null}contains(e){return this.find(e)!==null}getSize(){let e=0,t=[],n=this.root;for(;n||t.length>0;){for(;n;)t.push(n),n=n.l;n=t.pop(),e++,n=n.r}return e}isBalanced(){if(!this.root)return!0;let e=[this.root];for(;e.length>0;){let t=e.pop(),n=t.getBalanceFactor();if(Math.abs(n)>1)return!1;t.l&&e.push(t.l),t.r&&e.push(t.r)}return!0}remove(e){this.root=this.removeNode(this.root,e)}removeDocument(e,t){let n=this.findNodeByKey(e);n&&(n.v.size===1?this.root=this.removeNode(this.root,e):n.v=new Set([...n.v.values()].filter(e=>e!==t)))}findNodeByKey(e){let t=this.root;for(;t;)if(e<t.k)t=t.l;else if(e>t.k)t=t.r;else return t;return null}removeNode(e,t){if(e===null)return null;let n=[],r=e;for(;r!==null&&r.k!==t;)n.push(r),r=t<r.k?r.l:r.r;if(r===null)return e;if(r.l===null||r.r===null){let t=r.l?r.l:r.r;if(n.length===0)e=t;else{let e=n[n.length-1];e.l===r?e.l=t:e.r=t}}else{let e=r,t=r.r;for(;t.l!==null;)e=t,t=t.l;r.k=t.k,r.v=t.v,e.l===t?e.l=t.r:e.r=t.r,r=e}n.push(r);for(let t=n.length-1;t>=0;t--){let r=n[t];r.updateHeight();let i=this.rebalanceNode(r);if(t>0){let e=n[t-1];e.l===r?e.l=i:e.r===r&&(e.r=i)}else e=i}return e}rangeSearch(e,t){let n=new Set,r=[],i=this.root;for(;i||r.length>0;){for(;i;)r.push(i),i=i.l;if(i=r.pop(),i.k>=e&&i.k<=t)for(let e of i.v)n.add(e);if(i.k>t)break;i=i.r}return n}greaterThan(e,t=!1){let n=new Set,r=[],i=this.root;for(;i||r.length>0;){for(;i;)r.push(i),i=i.r;if(i=r.pop(),t&&i.k>=e||!t&&i.k>e)for(let e of i.v)n.add(e);else if(i.k<=e)break;i=i.l}return n}lessThan(e,t=!1){let n=new Set,r=[],i=this.root;for(;i||r.length>0;){for(;i;)r.push(i),i=i.l;if(i=r.pop(),t&&i.k<=e||!t&&i.k<e)for(let e of i.v)n.add(e);else if(i.k>e)break;i=i.r}return n}},ZH=class e{numberToDocumentId;constructor(){this.numberToDocumentId=new Map}insert(e,t){this.numberToDocumentId.has(e)?this.numberToDocumentId.get(e).add(t):this.numberToDocumentId.set(e,new Set([t]))}find(e){let t=this.numberToDocumentId.get(e);return t?Array.from(t):null}remove(e){this.numberToDocumentId.delete(e)}removeDocument(e,t){let n=this.numberToDocumentId.get(t);n&&(n.delete(e),n.size===0&&this.numberToDocumentId.delete(t))}contains(e){return this.numberToDocumentId.has(e)}getSize(){let e=0;for(let t of this.numberToDocumentId.values())e+=t.size;return e}filter(e){let t=Object.keys(e);if(t.length!==1)throw Error(`Invalid operation`);let n=t[0];switch(n){case`eq`:{let t=e[n],r=this.numberToDocumentId.get(t);return r?Array.from(r):[]}case`in`:{let t=e[n],r=new Set;for(let e of t){let t=this.numberToDocumentId.get(e);if(t)for(let e of t)r.add(e)}return Array.from(r)}case`nin`:{let t=new Set(e[n]),r=new Set;for(let[e,n]of this.numberToDocumentId.entries())if(!t.has(e))for(let e of n)r.add(e);return Array.from(r)}default:throw Error(`Invalid operation`)}}filterArr(e){let t=Object.keys(e);if(t.length!==1)throw Error(`Invalid operation`);let n=t[0];switch(n){case`containsAll`:{let t=e[n].map(e=>this.numberToDocumentId.get(e)??new Set);if(t.length===0)return[];let r=t.reduce((e,t)=>new Set([...e].filter(e=>t.has(e))));return Array.from(r)}case`containsAny`:{let t=e[n].map(e=>this.numberToDocumentId.get(e)??new Set);if(t.length===0)return[];let r=t.reduce((e,t)=>new Set([...e,...t]));return Array.from(r)}default:throw Error(`Invalid operation`)}}static fromJSON(t){if(!t.numberToDocumentId)throw Error(`Invalid Flat Tree JSON`);let n=new e;for(let[e,r]of t.numberToDocumentId)n.numberToDocumentId.set(e,new Set(r));return n}toJSON(){return{numberToDocumentId:Array.from(this.numberToDocumentId.entries()).map(([e,t])=>[e,Array.from(t)])}}};function QH(e,t,n){if(n<0)return-1;if(e===t)return 0;let r=e.length,i=t.length;if(r===0)return i<=n?i:-1;if(i===0)return r<=n?r:-1;let a=Math.abs(r-i);if(e.startsWith(t))return a<=n?a:-1;if(t.startsWith(e))return 0;if(a>n)return-1;let o=[];for(let e=0;e<=r;e++){o[e]=[e];for(let t=1;t<=i;t++)o[e][t]=e===0?t:0}for(let a=1;a<=r;a++){let r=1/0;for(let n=1;n<=i;n++)e[a-1]===t[n-1]?o[a][n]=o[a-1][n-1]:o[a][n]=Math.min(o[a-1][n]+1,o[a][n-1]+1,o[a-1][n-1]+1),r=Math.min(r,o[a][n]);if(r>n)return-1}return o[r][i]<=n?o[r][i]:-1}function $H(e,t,n){let r=QH(e,t,n);return{distance:r,isBounded:r>=0}}var eU=class e{k;s;c=new Map;d=new Set;e;w=``;constructor(e,t,n){this.k=e,this.s=t,this.e=n}updateParent(e){this.w=e.w+this.s}addDocument(e){this.d.add(e)}removeDocument(e){return this.d.delete(e)}findAllWords(e,t,n,r){let i=[this];for(;i.length>0;){let a=i.pop();if(a.e){let{w:i,d:o}=a;if(n&&i!==t)continue;if(QV(e,i)!==null)if(r)if(Math.abs(t.length-i.length)<=r&&$H(t,i,r).isBounded)e[i]=[];else continue;else e[i]=[];if(QV(e,i)!=null&&o.size>0){let t=e[i];for(let e of o)t.includes(e)||t.push(e)}}a.c.size>0&&i.push(...a.c.values())}return e}insert(t,n){let r=this,i=0,a=t.length;for(;i<a;){let o=t[i],s=r.c.get(o);if(s){let o=s.s,c=o.length,l=0;for(;l<c&&i+l<a&&o[l]===t[i+l];)l++;if(l===c){if(r=s,i+=l,i===a){s.e||=!0,s.addDocument(n);return}continue}let u=o.slice(0,l),d=o.slice(l),f=t.slice(i+l),p=new e(u[0],u,!1);if(r.c.set(u[0],p),p.updateParent(r),s.s=d,s.k=d[0],p.c.set(d[0],s),s.updateParent(p),f){let t=new e(f[0],f,!0);t.addDocument(n),p.c.set(f[0],t),t.updateParent(p)}else p.e=!0,p.addDocument(n);return}else{let a=new e(o,t.slice(i),!0);a.addDocument(n),r.c.set(o,a),a.updateParent(r);return}}r.e||=!0,r.addDocument(n)}_findLevenshtein(e,t,n,r,i){let a=[{node:this,index:t,tolerance:n}];for(;a.length>0;){let{node:t,index:n,tolerance:o}=a.pop();if(t.w.startsWith(e)){t.findAllWords(i,e,!1,0);continue}if(o<0)continue;if(t.e){let{w:n,d:a}=t;if(n&&($H(e,n,r).isBounded&&(i[n]=[]),QV(i,n)!==void 0&&a.size>0)){let e=new Set(i[n]);for(let t of a)e.add(t);i[n]=Array.from(e)}}if(n>=e.length)continue;let s=e[n];if(t.c.has(s)){let e=t.c.get(s);a.push({node:e,index:n+1,tolerance:o})}a.push({node:t,index:n+1,tolerance:o-1});for(let[e,r]of t.c)a.push({node:r,index:n,tolerance:o-1}),e!==s&&a.push({node:r,index:n+1,tolerance:o-1})}}find(e){let{term:t,exact:n,tolerance:r}=e;if(r&&!n){let e={};return this._findLevenshtein(t,0,r,r,e),e}else{let e=this,i=0,a=t.length;for(;i<a;){let o=t[i],s=e.c.get(o);if(s){let o=s.s,c=o.length,l=0;for(;l<c&&i+l<a&&o[l]===t[i+l];)l++;if(l===c)e=s,i+=l;else if(i+l===a)if(l===a-i){if(n)return{};{let e={};return s.findAllWords(e,t,n,r),e}}else return{};else return{}}else return{}}let o={};return e.findAllWords(o,t,n,r),o}}contains(e){let t=this,n=0,r=e.length;for(;n<r;){let i=e[n],a=t.c.get(i);if(a){let i=a.s,o=i.length,s=0;for(;s<o&&n+s<r&&i[s]===e[n+s];)s++;if(s<o)return!1;n+=o,t=a}else return!1}return!0}removeWord(e){if(!e)return!1;let t=this,n=e.length,r=[];for(let i=0;i<n;i++){let n=e[i];if(t.c.has(n)){let e=t.c.get(n);r.push({parent:t,character:n}),i+=e.s.length-1,t=e}else return!1}for(t.d.clear(),t.e=!1;r.length>0&&t.c.size===0&&!t.e&&t.d.size===0;){let{parent:e,character:n}=r.pop();e.c.delete(n),t=e}return!0}removeDocumentByWord(e,t,n=!0){if(!e)return!0;let r=this,i=e.length;for(let a=0;a<i;a++){let i=e[a];if(r.c.has(i)){let o=r.c.get(i);a+=o.s.length-1,r=o,n&&r.w!==e||r.removeDocument(t)}else return!1}return!0}static getCommonPrefix(e,t){let n=Math.min(e.length,t.length),r=0;for(;r<n&&e.charCodeAt(r)===t.charCodeAt(r);)r++;return e.slice(0,r)}toJSON(){return{w:this.w,s:this.s,e:this.e,k:this.k,d:Array.from(this.d),c:Array.from(this.c?.entries())?.map(([e,t])=>[e,t.toJSON()])}}static fromJSON(t){let n=new e(t.k,t.s,t.e);return n.w=t.w,n.d=new Set(t.d),n.c=new Map(t?.c?.map(([t,n])=>[t,e.fromJSON(n)])||[]),n}},tU=class e extends eU{constructor(){super(``,``,!1)}static fromJSON(t){let n=new e;return n.w=t.w,n.s=t.s,n.e=t.e,n.k=t.k,n.d=new Set(t.d),n.c=new Map(t?.c?.map(([e,t])=>[e,eU.fromJSON(t)])||[]),n}toJSON(){return super.toJSON()}},nU=class e{point;docIDs;left;right;parent;constructor(e,t){this.point=e,this.docIDs=new Set(t),this.left=null,this.right=null,this.parent=null}toJSON(){return{point:this.point,docIDs:Array.from(this.docIDs),left:this.left?this.left.toJSON():null,right:this.right?this.right.toJSON():null}}static fromJSON(t,n=null){let r=new e(t.point,t.docIDs);return r.parent=n,t.left&&(r.left=e.fromJSON(t.left,r)),t.right&&(r.right=e.fromJSON(t.right,r)),r}},rU=class e{root;nodeMap;constructor(){this.root=null,this.nodeMap=new Map}getPointKey(e){return`${e.lon},${e.lat}`}insert(e,t){let n=this.getPointKey(e),r=this.nodeMap.get(n);if(r){t.forEach(e=>r.docIDs.add(e));return}let i=new nU(e,t);if(this.nodeMap.set(n,i),this.root==null){this.root=i;return}let a=this.root,o=0;for(;;){if(o%2==0)if(e.lon<a.point.lon){if(a.left==null){a.left=i,i.parent=a;return}a=a.left}else{if(a.right==null){a.right=i,i.parent=a;return}a=a.right}else if(e.lat<a.point.lat){if(a.left==null){a.left=i,i.parent=a;return}a=a.left}else{if(a.right==null){a.right=i,i.parent=a;return}a=a.right}o++}}contains(e){let t=this.getPointKey(e);return this.nodeMap.has(t)}getDocIDsByCoordinates(e){let t=this.getPointKey(e),n=this.nodeMap.get(t);return n?Array.from(n.docIDs):null}removeDocByID(e,t){let n=this.getPointKey(e),r=this.nodeMap.get(n);r&&(r.docIDs.delete(t),r.docIDs.size===0&&(this.nodeMap.delete(n),this.deleteNode(r)))}deleteNode(e){let t=e.parent,n=e.left?e.left:e.right;n&&(n.parent=t),t?t.left===e?t.left=n:t.right===e&&(t.right=n):(this.root=n,this.root&&(this.root.parent=null))}searchByRadius(t,n,r=!0,i=`asc`,a=!1){let o=a?e.vincentyDistance:e.haversineDistance,s=[{node:this.root,depth:0}],c=[];for(;s.length>0;){let{node:e,depth:i}=s.pop();if(e==null)continue;let a=o(t,e.point);(r?a<=n:a>n)&&c.push({point:e.point,docIDs:Array.from(e.docIDs)}),e.left!=null&&s.push({node:e.left,depth:i+1}),e.right!=null&&s.push({node:e.right,depth:i+1})}return i&&c.sort((e,n)=>{let r=o(t,e.point),a=o(t,n.point);return i.toLowerCase()===`asc`?r-a:a-r}),c}searchByPolygon(t,n=!0,r=null,i=!1){let a=[{node:this.root,depth:0}],o=[];for(;a.length>0;){let{node:r,depth:i}=a.pop();if(r==null)continue;r.left!=null&&a.push({node:r.left,depth:i+1}),r.right!=null&&a.push({node:r.right,depth:i+1});let s=e.isPointInPolygon(t,r.point);(s&&n||!s&&!n)&&o.push({point:r.point,docIDs:Array.from(r.docIDs)})}let s=e.calculatePolygonCentroid(t);if(r){let t=i?e.vincentyDistance:e.haversineDistance;o.sort((e,n)=>{let i=t(s,e.point),a=t(s,n.point);return r.toLowerCase()===`asc`?i-a:a-i})}return o}toJSON(){return{root:this.root?this.root.toJSON():null}}static fromJSON(t){let n=new e;return t.root&&(n.root=nU.fromJSON(t.root),n.buildNodeMap(n.root)),n}buildNodeMap(e){if(e==null)return;let t=this.getPointKey(e.point);this.nodeMap.set(t,e),e.left&&this.buildNodeMap(e.left),e.right&&this.buildNodeMap(e.right)}static calculatePolygonCentroid(e){let t=0,n=0,r=0,i=e.length;for(let a=0,o=i-1;a<i;o=a++){let i=e[a].lon,s=e[a].lat,c=e[o].lon,l=e[o].lat,u=i*l-c*s;t+=u,n+=(i+c)*u,r+=(s+l)*u}t/=2;let a=6*t;return n/=a,r/=a,{lon:n,lat:r}}static isPointInPolygon(e,t){let n=!1,r=t.lon,i=t.lat,a=e.length;for(let t=0,o=a-1;t<a;o=t++){let a=e[t].lon,s=e[t].lat,c=e[o].lon,l=e[o].lat;s>i!=l>i&&r<(c-a)*(i-s)/(l-s)+a&&(n=!n)}return n}static haversineDistance(e,t){let n=Math.PI/180,r=e.lat*n,i=t.lat*n,a=(t.lat-e.lat)*n,o=(t.lon-e.lon)*n,s=Math.sin(a/2)*Math.sin(a/2)+Math.cos(r)*Math.cos(i)*Math.sin(o/2)*Math.sin(o/2);return 6371e3*(2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s)))}static vincentyDistance(e,t){let n=6378137,r=1/298.257223563,i=(1-r)*n,a=Math.PI/180,o=e.lat*a,s=t.lat*a,c=(t.lon-e.lon)*a,l=Math.atan((1-r)*Math.tan(o)),u=Math.atan((1-r)*Math.tan(s)),d=Math.sin(l),f=Math.cos(l),p=Math.sin(u),m=Math.cos(u),h=c,g,_=1e3,v,y,b,x,S,C;do{let e=Math.sin(h),t=Math.cos(h);if(v=Math.sqrt(m*e*(m*e)+(f*p-d*m*t)*(f*p-d*m*t)),v===0)return 0;y=d*p+f*m*t,b=Math.atan2(v,y),x=f*m*e/v,S=1-x*x,C=y-2*d*p/S,isNaN(C)&&(C=0);let n=r/16*S*(4+r*(4-3*S));g=h,h=c+(1-n)*r*x*(b+n*v*(C+n*y*(-1+2*C*C)))}while(Math.abs(h-g)>1e-12&&--_>0);if(_===0)return NaN;let w=S*(n*n-i*i)/(i*i),T=1+w/16384*(4096+w*(-768+w*(320-175*w))),E=w/1024*(256+w*(-128+w*(74-47*w))),ee=E*v*(C+E/4*(y*(-1+2*C*C)-E/6*C*(-3+4*v*v)*(-3+4*C*C)));return i*T*(b-ee)}},iU=class e{true;false;constructor(){this.true=new Set,this.false=new Set}insert(e,t){t?this.true.add(e):this.false.add(e)}delete(e,t){t?this.true.delete(e):this.false.delete(e)}getSize(){return this.true.size+this.false.size}toJSON(){return{true:Array.from(this.true),false:Array.from(this.false)}}static fromJSON(t){let n=new e;return n.true=new Set(t.true),n.false=new Set(t.false),n}};function aU(e,t,n,r,i,{k:a,b:o,d:s}){return Math.log(1+(n-t+.5)/(t+.5))*(s+e*(a+1))/(e+a*(1-o+o*r/i))}var oU=class e{size;vectors=new Map;constructor(e){this.size=e}add(e,t){t instanceof Float32Array||(t=new Float32Array(t));let n=sU(t,this.size);this.vectors.set(e,[n,t])}remove(e){this.vectors.delete(e)}find(e,t,n){return e instanceof Float32Array||(e=new Float32Array(e)),cU(e,n,this.vectors,this.size,t)}toJSON(){let e=[];for(let[t,[n,r]]of this.vectors)e.push([t,[n,Array.from(r)]]);return{size:this.size,vectors:e}}static fromJSON(t){let n=t,r=new e(n.size);for(let[e,[t,i]]of n.vectors)r.vectors.set(e,[t,new Float32Array(i)]);return r}};function sU(e,t){let n=0;for(let r=0;r<t;r++)n+=e[r]*e[r];return Math.sqrt(n)}function cU(e,t,n,r,i){let a=sU(e,r),o=[],s=t||n.keys();for(let t of s){let s=n.get(t);if(!s)continue;let c=s[0],l=s[1],u=0;for(let t=0;t<r;t++)u+=e[t]*l[t];let d=u/(a*c);d>=i&&o.push([t,d])}return o}function lU(e,t,n,r,i){let a=OH(e.sharedInternalDocumentStore,n);e.avgFieldLength[t]=((e.avgFieldLength[t]??0)*(i-1)+r.length)/i,e.fieldLengths[t][a]=r.length,e.frequencies[t][a]={}}function uU(e,t,n,r,i){let a=0;for(let e of r)e===i&&a++;let o=OH(e.sharedInternalDocumentStore,n),s=a/r.length;e.frequencies[t][o][i]=s,i in e.tokenOccurrences[t]||(e.tokenOccurrences[t][i]=0),e.tokenOccurrences[t][i]=(e.tokenOccurrences[t][i]??0)+1}function dU(e,t,n,r){let i=OH(e.sharedInternalDocumentStore,n);r>1?e.avgFieldLength[t]=(e.avgFieldLength[t]*r-e.fieldLengths[t][i])/(r-1):e.avgFieldLength[t]=void 0,e.fieldLengths[t][i]=void 0,e.frequencies[t][i]=void 0}function fU(e,t,n){e.tokenOccurrences[t][n]--}function pU(e,t,n,r,i=``){r||={sharedInternalDocumentStore:t,indexes:{},vectorIndexes:{},searchableProperties:[],searchablePropertiesWithTypes:{},frequencies:{},tokenOccurrences:{},avgFieldLength:{},fieldLengths:{}};for(let[a,o]of Object.entries(n)){let n=`${i}${i?`.`:``}${a}`;if(typeof o==`object`&&!Array.isArray(o)){pU(e,t,o,r,n);continue}if(xH(o))r.searchableProperties.push(n),r.searchablePropertiesWithTypes[n]=o,r.vectorIndexes[n]={type:`Vector`,node:new oU(wH(o)),isArray:!1};else{let e=/\[/.test(o);switch(o){case`boolean`:case`boolean[]`:r.indexes[n]={type:`Bool`,node:new iU,isArray:e};break;case`number`:case`number[]`:r.indexes[n]={type:`AVL`,node:new XH(0,[]),isArray:e};break;case`string`:case`string[]`:r.indexes[n]={type:`Radix`,node:new tU,isArray:e},r.avgFieldLength[n]=0,r.frequencies[n]={},r.tokenOccurrences[n]={},r.fieldLengths[n]={};break;case`enum`:case`enum[]`:r.indexes[n]={type:`Flat`,node:new ZH,isArray:e};break;case`geopoint`:r.indexes[n]={type:`BKD`,node:new rU,isArray:e};break;default:throw mH(`INVALID_SCHEMA_TYPE`,Array.isArray(o)?`array`:o,n)}r.searchableProperties.push(n),r.searchablePropertiesWithTypes[n]=o}}return r}function mU(e,t,n,r,i,a,o,s){return c=>{let{type:l,node:u}=t.indexes[n];switch(l){case`Bool`:u[c?`true`:`false`].add(r);break;case`AVL`:{let e=s?.avlRebalanceThreshold??1;u.insert(c,r,e);break}case`Radix`:{let s=a.tokenize(c,i,n,!1);e.insertDocumentScoreParameters(t,n,r,s,o);for(let i of s)e.insertTokenScoreParameters(t,n,r,s,i),u.insert(i,r);break}case`Flat`:u.insert(c,r);break;case`BKD`:u.insert(c,[r]);break}}}function hU(e,t,n,r,i,a,o,s,c,l,u){if(xH(o))return gU(t,n,a,r,i);let d=mU(e,t,n,i,s,c,l,u);if(!SH(o))return d(a);let f=a,p=f.length;for(let e=0;e<p;e++)d(f[e])}function gU(e,t,n,r,i){e.vectorIndexes[t].node.add(i,n)}function _U(e,t,n,r,i,a,o,s,c,l){if(xH(o))return t.vectorIndexes[n].node.remove(i),!0;let{type:u,node:d}=t.indexes[n];switch(u){case`AVL`:return d.removeDocument(a,i),!0;case`Bool`:return d[a?`true`:`false`].delete(i),!0;case`Radix`:{let o=c.tokenize(a,s,n);e.removeDocumentScoreParameters(t,n,r,l);for(let r of o)e.removeTokenScoreParameters(t,n,r),d.removeDocumentByWord(r,i);return!0}case`Flat`:return d.removeDocument(i,a),!0;case`BKD`:return d.removeDocByID(a,i),!1}}function vU(e,t,n,r,i,a,o,s,c,l){if(!SH(o))return _U(e,t,n,r,i,a,o,s,c,l);let u=CH(o),d=a,f=d.length;for(let a=0;a<f;a++)_U(e,t,n,r,i,d[a],u,s,c,l);return!0}function yU(e,t,n,r,i,a,o,s,c,l){let u=Array.from(r),d=e.avgFieldLength[t],f=e.fieldLengths[t],p=e.tokenOccurrences[t],m=e.frequencies[t],h=typeof p[n]==`number`?p[n]??0:0,g=u.length;for(let e=0;e<g;e++){let r=u[e];if(c&&!c.has(r))continue;l.has(r)||l.set(r,new Map);let p=l.get(r);p.set(t,(p.get(t)||0)+1);let g=aU(m?.[r]?.[n]??0,h,i,f[r],d,a);o.has(r)?o.set(r,o.get(r)+g*s):o.set(r,g*s)}}function bU(e,t,n,r,i,a,o,s,c,l,u,d=0){let f=n.tokenize(t,r),p=f.length||1,m=new Map,h=new Map,g=new Map;for(let n of i){if(!(n in e.indexes))continue;let r=e.indexes[n],{type:i}=r;if(i!==`Radix`)throw mH(`WRONG_SEARCH_PROPERTY_TYPE`,n);let d=s[n]??1;if(d<=0)throw mH(`INVALID_BOOST_VALUE`,d);f.length===0&&!t&&f.push(``);let p=f.length;for(let t=0;t<p;t++){let i=f[t],s=r.node.find({term:i,exact:a,tolerance:o}),p=Object.keys(s);p.length>0&&h.set(i,!0);let _=p.length;for(let t=0;t<_;t++){let r=p[t],i=s[r];yU(e,n,r,i,l,c,g,d,u,m)}}}let _=Array.from(g.entries()).map(([e,t])=>[e,t]).sort((e,t)=>t[1]-e[1]);if(_.length===0)return[];if(d===1)return _;if(d===0){if(p===1)return _;for(let e of f)if(!h.get(e))return[];return _.filter(([e])=>{let t=m.get(e);return t?Array.from(t.values()).some(e=>e===p):!1})}let v=_.filter(([e])=>{let t=m.get(e);return t?Array.from(t.values()).some(e=>e===p):!1});if(v.length>0){let e=_.filter(([e])=>!v.some(([t])=>t===e)),t=Math.ceil(e.length*d);return[...v,...e.slice(0,t)]}return _}function xU(e,t,n,r){if(`and`in n&&n.and&&Array.isArray(n.and)){let i=n.and;return i.length===0?new Set:cH(...i.map(n=>xU(e,t,n,r)))}if(`or`in n&&n.or&&Array.isArray(n.or)){let i=n.or;return i.length===0?new Set:i.map(n=>xU(e,t,n,r)).reduce((e,t)=>uH(e,t),new Set)}if(`not`in n&&n.not){let i=n.not,a=new Set,o=e.sharedInternalDocumentStore;for(let e=1;e<=o.internalIdToId.length;e++)a.add(e);return dH(a,xU(e,t,i,r))}let i=Object.keys(n),a=i.reduce((e,t)=>({[t]:new Set,...e}),{});for(let o of i){let i=n[o];if(e.indexes[o]===void 0)throw mH(`UNKNOWN_FILTER_PROPERTY`,o);let{node:s,type:c,isArray:l}=e.indexes[o];if(c===`Bool`){let e=s,t=i?e.true:e.false;a[o]=uH(a[o],t);continue}if(c===`BKD`){let e;if(`radius`in i)e=`radius`;else if(`polygon`in i)e=`polygon`;else throw Error(`Invalid operation ${i}`);if(e===`radius`){let{value:t,coordinates:n,unit:r=`m`,inside:c=!0,highPrecision:l=!1}=i[e],u=iH(t,r),d=s.searchByRadius(n,u,c,void 0,l);a[o]=DU(a[o],d)}else{let{coordinates:t,inside:n=!0,highPrecision:r=!1}=i[e],c=s.searchByPolygon(t,n,void 0,r);a[o]=DU(a[o],c)}continue}if(c===`Radix`&&(typeof i==`string`||Array.isArray(i))){for(let e of[i].flat()){let n=t.tokenize(e,r,o);for(let e of n){let t=s.find({term:e,exact:!0});a[o]=jU(a[o],t)}}continue}let u=Object.keys(i);if(u.length>1)throw mH(`INVALID_FILTER_OPERATION`,u.length);if(c===`Flat`){let e=new Set(l?s.filterArr(i):s.filter(i));a[o]=uH(a[o],e);continue}if(c===`AVL`){let e=u[0],t=i[e],n;switch(e){case`gt`:n=s.greaterThan(t,!1);break;case`gte`:n=s.greaterThan(t,!0);break;case`lt`:n=s.lessThan(t,!1);break;case`lte`:n=s.lessThan(t,!0);break;case`eq`:n=s.find(t)??new Set;break;case`between`:{let[e,r]=t;n=s.rangeSearch(e,r);break}default:throw mH(`INVALID_FILTER_OPERATION`,e)}a[o]=uH(a[o],n)}}return cH(...Object.values(a))}function SU(e){return e.searchableProperties}function CU(e){return e.searchablePropertiesWithTypes}function wU(e,t){let{indexes:n,vectorIndexes:r,searchableProperties:i,searchablePropertiesWithTypes:a,frequencies:o,tokenOccurrences:s,avgFieldLength:c,fieldLengths:l}=t,u={},d={};for(let e of Object.keys(n)){let{node:t,type:r,isArray:i}=n[e];switch(r){case`Radix`:u[e]={type:`Radix`,node:tU.fromJSON(t),isArray:i};break;case`Flat`:u[e]={type:`Flat`,node:ZH.fromJSON(t),isArray:i};break;case`AVL`:u[e]={type:`AVL`,node:XH.fromJSON(t),isArray:i};break;case`BKD`:u[e]={type:`BKD`,node:rU.fromJSON(t),isArray:i};break;case`Bool`:u[e]={type:`Bool`,node:iU.fromJSON(t),isArray:i};break;default:u[e]=n[e]}}for(let e of Object.keys(r))d[e]={type:`Vector`,isArray:!1,node:oU.fromJSON(r[e])};return{sharedInternalDocumentStore:e,indexes:u,vectorIndexes:d,searchableProperties:i,searchablePropertiesWithTypes:a,frequencies:o,tokenOccurrences:s,avgFieldLength:c,fieldLengths:l}}function TU(e){let{indexes:t,vectorIndexes:n,searchableProperties:r,searchablePropertiesWithTypes:i,frequencies:a,tokenOccurrences:o,avgFieldLength:s,fieldLengths:c}=e,l={};for(let e of Object.keys(n))l[e]=n[e].node.toJSON();let u={};for(let e of Object.keys(t)){let{type:n,node:r,isArray:i}=t[e];n===`Flat`||n===`Radix`||n===`AVL`||n===`BKD`||n===`Bool`?u[e]={type:n,node:r.toJSON(),isArray:i}:(u[e]=t[e],u[e].node=u[e].node.toJSON())}return{indexes:u,vectorIndexes:l,searchableProperties:r,searchablePropertiesWithTypes:i,frequencies:a,tokenOccurrences:o,avgFieldLength:s,fieldLengths:c}}function EU(){return{create:pU,insert:hU,remove:vU,insertDocumentScoreParameters:lU,insertTokenScoreParameters:uU,removeDocumentScoreParameters:dU,removeTokenScoreParameters:fU,calculateResultScores:yU,search:bU,searchByWhereClause:xU,getSearchableProperties:SU,getSearchablePropertiesWithTypes:CU,load:wU,save:TU}}function DU(e,t){e||=new Set;let n=t.length;for(let r=0;r<n;r++){let n=t[r].docIDs,i=n.length;for(let t=0;t<i;t++)e.add(n[t])}return e}function OU(e,t,n=!1){let r=n?rU.vincentyDistance:rU.haversineDistance,i=[],a=[];for(let{point:n}of e)a.push(r(t,n));let o=Math.max(...a),s=0;for(let{docIDs:t}of e){let e=o-a[s]+1;for(let n of t)i.push([n,e]);s++}return i.sort((e,t)=>t[1]-e[1]),i}function kU(e,t){let n=Object.keys(e);if(n.length!==1)return{isGeoOnly:!1};let r=n[0],i=e[r];if(t.indexes[r]===void 0)return{isGeoOnly:!1};let{type:a}=t.indexes[r];return a===`BKD`&&i&&(`radius`in i||`polygon`in i)?{isGeoOnly:!0,geoProperty:r,geoOperation:i}:{isGeoOnly:!1}}function AU(e,t){let n=e,r=kU(t,n);if(!r.isGeoOnly||!r.geoProperty||!r.geoOperation)return null;let{node:i}=n.indexes[r.geoProperty],a=r.geoOperation,o=i,s;if(`radius`in a){let{value:e,coordinates:t,unit:n=`m`,inside:r=!0,highPrecision:i=!1}=a.radius,c=t,l=iH(e,n);return s=o.searchByRadius(c,l,r,`asc`,i),OU(s,c,i)}else if(`polygon`in a){let{coordinates:e,inside:t=!0,highPrecision:n=!1}=a.polygon;s=o.searchByPolygon(e,t,`asc`,n);let r=rU.calculatePolygonCentroid(e);return OU(s,r,n)}return null}function jU(e,t){e||=new Set;let n=Object.keys(t),r=n.length;for(let i=0;i<r;i++){let r=t[n[i]],a=r.length;for(let t=0;t<a;t++)e.add(r[t])}return e}function MU(e,t,n,r,i){let a={language:e.tokenizer.language,sharedInternalDocumentStore:t,enabled:!0,isSorted:!0,sortableProperties:[],sortablePropertiesWithTypes:{},sorts:{}};for(let[o,s]of Object.entries(n)){let n=`${i}${i?`.`:``}${o}`;if(!r.includes(n)){if(typeof s==`object`&&!Array.isArray(s)){let i=MU(e,t,s,r,n);WV(a.sortableProperties,i.sortableProperties),a.sorts={...a.sorts,...i.sorts},a.sortablePropertiesWithTypes={...a.sortablePropertiesWithTypes,...i.sortablePropertiesWithTypes};continue}if(!xH(s))switch(s){case`boolean`:case`number`:case`string`:a.sortableProperties.push(n),a.sortablePropertiesWithTypes[n]=s,a.sorts[n]={docs:new Map,orderedDocsToRemove:new Map,orderedDocs:[],type:s};break;case`geopoint`:case`enum`:continue;case`enum[]`:case`boolean[]`:case`number[]`:case`string[]`:continue;default:throw mH(`INVALID_SORT_SCHEMA_TYPE`,Array.isArray(s)?`array`:s,n)}}}return a}function NU(e,t,n,r){return r?.enabled===!1?{disabled:!0}:MU(e,t,n,(r||{}).unsortableProperties||[],``)}function PU(e,t,n,r){if(!e.enabled)return;e.isSorted=!1;let i=OH(e.sharedInternalDocumentStore,n),a=e.sorts[t];a.orderedDocsToRemove.has(i)&&VU(e,t),a.docs.set(i,a.orderedDocs.length),a.orderedDocs.push([i,r])}function FU(e){if(e.isSorted||!e.enabled)return;let t=Object.keys(e.sorts);for(let n of t)zU(e,n);e.isSorted=!0}function IU(e,t,n){return t[1].localeCompare(n[1],LV(e))}function LU(e,t){return e[1]-t[1]}function RU(e,t){return t[1]?-1:1}function zU(e,t){let n=e.sorts[t],r;switch(n.type){case`string`:r=IU.bind(null,e.language);break;case`number`:r=LU.bind(null);break;case`boolean`:r=RU.bind(null);break}n.orderedDocs.sort(r);let i=n.orderedDocs.length;for(let e=0;e<i;e++){let t=n.orderedDocs[e][0];n.docs.set(t,e)}}function BU(e){let t=Object.keys(e.sorts);for(let n of t)VU(e,n)}function VU(e,t){let n=e.sorts[t];n.orderedDocsToRemove.size&&(n.orderedDocs=n.orderedDocs.filter(e=>!n.orderedDocsToRemove.has(e[0])),n.orderedDocsToRemove.clear())}function HU(e,t,n){if(!e.enabled)return;let r=e.sorts[t],i=OH(e.sharedInternalDocumentStore,n);r.docs.get(i)&&(r.docs.delete(i),r.orderedDocsToRemove.set(i,!0))}function UU(e,t,n){if(!e.enabled)throw mH(`SORT_DISABLED`);let r=n.property,i=n.order===`DESC`,a=e.sorts[r];if(!a)throw mH(`UNABLE_TO_SORT_ON_UNKNOWN_FIELD`,r,e.sortableProperties.join(`, `));return VU(e,r),FU(e),t.sort((t,n)=>{let r=a.docs.get(OH(e.sharedInternalDocumentStore,t[0])),o=a.docs.get(OH(e.sharedInternalDocumentStore,n[0])),s=r!==void 0,c=o!==void 0;return!s&&!c?0:s?c?i?o-r:r-o:-1:1}),t}function WU(e){return e.enabled?e.sortableProperties:[]}function GU(e){return e.enabled?e.sortablePropertiesWithTypes:{}}function KU(e,t){let n=t;if(!n.enabled)return{enabled:!1};let r=Object.keys(n.sorts).reduce((e,t)=>{let{docs:r,orderedDocs:i,type:a}=n.sorts[t];return e[t]={docs:new Map(Object.entries(r).map(([e,t])=>[+e,t])),orderedDocsToRemove:new Map,orderedDocs:i,type:a},e},{});return{sharedInternalDocumentStore:e,language:n.language,sortableProperties:n.sortableProperties,sortablePropertiesWithTypes:n.sortablePropertiesWithTypes,sorts:r,enabled:!0,isSorted:n.isSorted}}function qU(e){if(!e.enabled)return{enabled:!1};BU(e),FU(e);let t=Object.keys(e.sorts).reduce((t,n)=>{let{docs:r,orderedDocs:i,type:a}=e.sorts[n];return t[n]={docs:Object.fromEntries(r.entries()),orderedDocs:i,type:a},t},{});return{language:e.language,sortableProperties:e.sortableProperties,sortablePropertiesWithTypes:e.sortablePropertiesWithTypes,sorts:t,enabled:e.enabled,isSorted:e.isSorted}}function JU(){return{create:NU,insert:PU,remove:HU,save:qU,load:KU,sortBy:UU,getSortableProperties:WU,getSortablePropertiesWithTypes:GU}}const YU=[65,65,65,65,65,65,65,67,69,69,69,69,73,73,73,73,69,78,79,79,79,79,79,null,79,85,85,85,85,89,80,115,97,97,97,97,97,97,97,99,101,101,101,101,105,105,105,105,101,110,111,111,111,111,111,null,111,117,117,117,117,121,112,121,65,97,65,97,65,97,67,99,67,99,67,99,67,99,68,100,68,100,69,101,69,101,69,101,69,101,69,101,71,103,71,103,71,103,71,103,72,104,72,104,73,105,73,105,73,105,73,105,73,105,73,105,74,106,75,107,107,76,108,76,108,76,108,76,108,76,108,78,110,78,110,78,110,110,78,110,79,111,79,111,79,111,79,111,82,114,82,114,82,114,83,115,83,115,83,115,83,115,84,116,84,116,84,116,85,117,85,117,85,117,85,117,85,117,85,117,87,119,89,121,89,90,122,90,122,90,122,115];function XU(e){return e<192||e>383?e:YU[e-192]||e}function ZU(e){let t=[];for(let n=0;n<e.length;n++)t[n]=XU(e.charCodeAt(n));return String.fromCharCode(...t)}const QU={ational:`ate`,tional:`tion`,enci:`ence`,anci:`ance`,izer:`ize`,bli:`ble`,alli:`al`,entli:`ent`,eli:`e`,ousli:`ous`,ization:`ize`,ation:`ate`,ator:`ate`,alism:`al`,iveness:`ive`,fulness:`ful`,ousness:`ous`,aliti:`al`,iviti:`ive`,biliti:`ble`,logi:`log`},$U={icate:`ic`,ative:``,alize:`al`,iciti:`ic`,ical:`ic`,ful:``,ness:``},eW=`[aeiouy]`,tW=`[^aeiou][^aeiouy]*`;eW+``;const nW=`^(`+tW+`)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*`;``+tW;const rW=`^(`+tW+`)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*[aeiouy][aeiou]*[^aeiou][^aeiouy]*`,iW=`^(`+tW+`)?[aeiouy]`;function aW(e){let t,n,r,i,a,o;if(e.length<3)return e;let s=e.substring(0,1);if(s==`y`&&(e=s.toUpperCase()+e.substring(1)),r=/^(.+?)(ss|i)es$/,i=/^(.+?)([^s])s$/,r.test(e)?e=e.replace(r,`$1$2`):i.test(e)&&(e=e.replace(i,`$1$2`)),r=/^(.+?)eed$/,i=/^(.+?)(ed|ing)$/,r.test(e)){let t=r.exec(e);r=new RegExp(nW),r.test(t[1])&&(r=/.$/,e=e.replace(r,``))}else i.test(e)&&(t=i.exec(e)[1],i=new RegExp(iW),i.test(t)&&(e=t,i=/(at|bl|iz)$/,a=RegExp(`([^aeiouylsz])\\1$`),o=RegExp(`^`+tW+eW+`[^aeiouwxy]$`),i.test(e)?e+=`e`:a.test(e)?(r=/.$/,e=e.replace(r,``)):o.test(e)&&(e+=`e`)));if(r=/^(.+?)y$/,r.test(e)&&(t=r.exec(e)?.[1],r=new RegExp(iW),t&&r.test(t)&&(e=t+`i`)),r=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,r.test(e)){let i=r.exec(e);t=i?.[1],n=i?.[2],r=new RegExp(nW),t&&r.test(t)&&(e=t+QU[n])}if(r=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,r.test(e)){let i=r.exec(e);t=i?.[1],n=i?.[2],r=new RegExp(nW),t&&r.test(t)&&(e=t+$U[n])}if(r=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,i=/^(.+?)(s|t)(ion)$/,r.test(e))t=r.exec(e)?.[1],r=new RegExp(rW),t&&r.test(t)&&(e=t);else if(i.test(e)){let n=i.exec(e);t=n?.[1]??``+n?.[2]??``,i=new RegExp(rW),i.test(t)&&(e=t)}return r=/^(.+?)e$/,r.test(e)&&(t=r.exec(e)?.[1],r=new RegExp(rW),i=RegExp(`^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*([aeiouy][aeiou]*)?$`),a=RegExp(`^`+tW+eW+`[^aeiouwxy]$`),t&&(r.test(t)||i.test(t)&&!a.test(t))&&(e=t)),r=/ll$/,i=new RegExp(rW),r.test(e)&&i.test(e)&&(r=/.$/,e=e.replace(r,``)),s==`y`&&(e=s.toLowerCase()+e.substring(1)),e}function oW(e,t,n=!0){let r=`${this.language}:${e}:${t}`;return n&&this.normalizationCache.has(r)?this.normalizationCache.get(r):this.stopWords?.includes(t)?(n&&this.normalizationCache.set(r,``),``):(this.stemmer&&!this.stemmerSkipProperties.has(e)&&(t=this.stemmer(t)),t=ZU(t),n&&this.normalizationCache.set(r,t),t)}function sW(e){for(;e[e.length-1]===``;)e.pop();for(;e[0]===``;)e.shift();return e}function cW(e,t,n,r=!0){if(t&&t!==this.language)throw mH(`LANGUAGE_NOT_SUPPORTED`,t);if(typeof e!=`string`)return[e];let i=this.normalizeToken.bind(this,n??``),a;if(n&&this.tokenizeSkipProperties.has(n))a=[i(e,r)];else{let t=FV[this.language];a=e.toLowerCase().split(t).map(e=>i(e,r)).filter(Boolean)}let o=sW(a);return this.allowDuplicates?o:Array.from(new Set(o))}function lW(e={}){if(!e.language)e.language=`english`;else if(!IV.includes(e.language))throw mH(`LANGUAGE_NOT_SUPPORTED`,e.language);let t;if(e.stemming||e.stemmer&&!(`stemming`in e))if(e.stemmer){if(typeof e.stemmer!=`function`)throw mH(`INVALID_STEMMER_FUNCTION_TYPE`);t=e.stemmer}else if(e.language===`english`)t=aW;else throw mH(`MISSING_STEMMER`,e.language);let n;if(e.stopWords!==!1){if(n=[],Array.isArray(e.stopWords))n=e.stopWords;else if(typeof e.stopWords==`function`)n=e.stopWords(n);else if(e.stopWords)throw mH(`CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY`);if(!Array.isArray(n))throw mH(`CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY`);for(let e of n)if(typeof e!=`string`)throw mH(`CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY`)}let r={tokenize:cW,language:e.language,stemmer:t,stemmerSkipProperties:new Set(e.stemmerSkipProperties?[e.stemmerSkipProperties].flat():[]),tokenizeSkipProperties:new Set(e.tokenizeSkipProperties?[e.tokenizeSkipProperties].flat():[]),stopWords:n,allowDuplicates:!!e.allowDuplicates,normalizeToken:oW,normalizationCache:new Map};return r.tokenize=cW.bind(r),r.normalizeToken=oW,r}function uW(e){return{sharedInternalDocumentStore:e,rules:new Map}}function dW(e,t){if(e.rules.has(t.id))throw Error(`PINNING_RULE_ALREADY_EXISTS: A pinning rule with id "${t.id}" already exists. Use updateRule to modify it.`);e.rules.set(t.id,t)}function fW(e,t){if(!e.rules.has(t.id))throw Error(`PINNING_RULE_NOT_FOUND: Cannot update pinning rule with id "${t.id}" because it does not exist. Use addRule to create it.`);e.rules.set(t.id,t)}function pW(e,t){return e.rules.delete(t)}function mW(e,t){return e.rules.get(t)}function hW(e){return Array.from(e.rules.values())}function gW(e,t){let n=e.toLowerCase().trim(),r=t.pattern.toLowerCase().trim();switch(t.anchoring){case`is`:return n===r;case`starts_with`:return n.startsWith(r);case`contains`:return n.includes(r);default:return!1}}function _W(e,t){return e?t.conditions.every(t=>gW(e,t)):!1}function vW(e,t){if(!t)return[];let n=[];for(let r of e.rules.values())_W(t,r)&&n.push(r);return n}function yW(e,t){return{sharedInternalDocumentStore:e,rules:new Map(t?.rules??[])}}function bW(e){return{rules:Array.from(e.rules.entries())}}function xW(){return{create:uW,addRule:dW,updateRule:fW,removeRule:pW,getRule:mW,getAllRules:hW,getMatchingRules:vW,load:yW,save:bW}}function SW(e){let t={formatElapsedTime:hH,getDocumentIndexId:gH,getDocumentProperties:tH,validateSchema:_H};for(let n of UH){let r=n;if(e[r]){if(typeof e[r]!=`function`)throw mH(`COMPONENT_MUST_BE_FUNCTION`,r)}else e[r]=t[r]}for(let t of Object.keys(e))if(!HH.includes(t)&&!UH.includes(t))throw mH(`UNSUPPORTED_COMPONENT`,t)}function CW({schema:e,sort:t,language:n,components:r,id:i,plugins:a}){r||={};for(let t of a??[]){if(!(`getComponents`in t)||typeof t.getComponents!=`function`)continue;let n=t.getComponents(e),i=Object.keys(n);for(let e of i)if(r[e])throw mH(`PLUGIN_COMPONENT_CONFLICT`,e,t.name);r={...r,...n}}i||=ZV();let o=r.tokenizer,s=r.index,c=r.documentsStore,l=r.sorter,u=r.pinning;if(o=o?o.tokenize?o:lW(o):lW({language:n??`english`}),r.tokenizer&&n)throw mH(`NO_LANGUAGE_WITH_CUSTOM_TOKENIZER`);let d=TH();s||=EU(),l||=JU(),c||=zH(),u||=xW(),SW(r);let{getDocumentProperties:f,getDocumentIndexId:p,validateSchema:m,formatElapsedTime:h}=r,g={data:{},caches:{},schema:e,tokenizer:o,index:s,sorter:l,documentsStore:c,pinning:u,internalDocumentIDStore:d,getDocumentProperties:f,getDocumentIndexId:p,validateSchema:m,beforeInsert:[],afterInsert:[],beforeRemove:[],afterRemove:[],beforeUpdate:[],afterUpdate:[],beforeUpsert:[],afterUpsert:[],beforeSearch:[],afterSearch:[],beforeInsertMultiple:[],afterInsertMultiple:[],beforeRemoveMultiple:[],afterRemoveMultiple:[],beforeUpdateMultiple:[],afterUpdateMultiple:[],beforeUpsertMultiple:[],afterUpsertMultiple:[],afterCreate:[],formatElapsedTime:h,id:i,plugins:a,version:wW()};g.data={index:g.index.create(g,d,e),docs:g.documentsStore.create(g,d),sorting:g.sorter.create(g,d,e,t),pinning:g.pinning.create(d)};for(let e of BH)g[e]=(g[e]??[]).concat(VH(g,e));let _=g.afterCreate;return _&&JH(_,g),g}function wW(){return`{{VERSION}}`}function TW(e){return e.documentsStore.count(e.data.docs)}function EW(e,t,n,r,i){let a=e.validateSchema(t,e.schema);if(a)throw mH(`SCHEMA_VALIDATION_FAILURE`,a);return oH(e.beforeInsert)||oH(e.afterInsert)||oH(e.index.beforeInsert)||oH(e.index.insert)||oH(e.index.afterInsert)?kW(e,t,n,r,i):AW(e,t,n,r,i)}const DW=new Set([`enum`,`enum[]`]),OW=new Set([`string`,`number`]);async function kW(e,t,n,r,i){let{index:a,docs:o}=e.data,s=e.getDocumentIndexId(t);if(typeof s!=`string`)throw mH(`DOCUMENT_ID_MUST_BE_STRING`,typeof s);let c=OH(e.internalDocumentIDStore,s);if(r||await WH(e.beforeInsert,e,s,t),!e.documentsStore.store(o,s,c,t))throw mH(`DOCUMENT_ALREADY_EXISTS`,s);let l=e.documentsStore.count(o),u=e.index.getSearchableProperties(a),d=e.index.getSearchablePropertiesWithTypes(a),f=e.getDocumentProperties(t,u);for(let[e,t]of Object.entries(f)){if(t===void 0)continue;let n=typeof t,r=d[e];jW(n,r,e,t)}return await MW(e,s,u,f,l,n,t,i),r||await WH(e.afterInsert,e,s,t),s}function AW(e,t,n,r,i){let{index:a,docs:o}=e.data,s=e.getDocumentIndexId(t);if(typeof s!=`string`)throw mH(`DOCUMENT_ID_MUST_BE_STRING`,typeof s);let c=OH(e.internalDocumentIDStore,s);if(r||WH(e.beforeInsert,e,s,t),!e.documentsStore.store(o,s,c,t))throw mH(`DOCUMENT_ALREADY_EXISTS`,s);let l=e.documentsStore.count(o),u=e.index.getSearchableProperties(a),d=e.index.getSearchablePropertiesWithTypes(a),f=e.getDocumentProperties(t,u);for(let[e,t]of Object.entries(f)){if(t===void 0)continue;let n=typeof t,r=d[e];jW(n,r,e,t)}return NW(e,s,u,f,l,n,t,i),r||WH(e.afterInsert,e,s,t),s}function jW(e,t,n,r){if(!(bH(t)&&typeof r==`object`&&typeof r.lon==`number`&&typeof r.lat==`number`)&&!(xH(t)&&Array.isArray(r))&&!(SH(t)&&Array.isArray(r))&&!(DW.has(t)&&OW.has(e))&&e!==t)throw mH(`INVALID_DOCUMENT_PROPERTY`,n,t,e)}async function MW(e,t,n,r,i,a,o,s){for(let o of n){let n=r[o];if(n===void 0)continue;let c=e.index.getSearchablePropertiesWithTypes(e.data.index)[o];await e.index.beforeInsert?.(e.data.index,o,t,n,c,a,e.tokenizer,i);let l=e.internalDocumentIDStore.idToInternalId.get(t);await e.index.insert(e.index,e.data.index,o,t,l,n,c,a,e.tokenizer,i,s),await e.index.afterInsert?.(e.data.index,o,t,n,c,a,e.tokenizer,i)}let c=e.sorter.getSortableProperties(e.data.sorting),l=e.getDocumentProperties(o,c);for(let n of c){let r=l[n];if(r===void 0)continue;let i=e.sorter.getSortablePropertiesWithTypes(e.data.sorting)[n];e.sorter.insert(e.data.sorting,n,t,r,i,a)}}function NW(e,t,n,r,i,a,o,s){for(let o of n){let n=r[o];if(n===void 0)continue;let c=e.index.getSearchablePropertiesWithTypes(e.data.index)[o],l=OH(e.internalDocumentIDStore,t);e.index.beforeInsert?.(e.data.index,o,t,n,c,a,e.tokenizer,i),e.index.insert(e.index,e.data.index,o,t,l,n,c,a,e.tokenizer,i,s),e.index.afterInsert?.(e.data.index,o,t,n,c,a,e.tokenizer,i)}let c=e.sorter.getSortableProperties(e.data.sorting),l=e.getDocumentProperties(o,c);for(let n of c){let r=l[n];if(r===void 0)continue;let i=e.sorter.getSortablePropertiesWithTypes(e.data.sorting)[n];e.sorter.insert(e.data.sorting,n,t,r,i,a)}}function PW(e,t,n,r,i,a){return oH(e.afterInsertMultiple)||oH(e.beforeInsertMultiple)||oH(e.index.beforeInsert)||oH(e.index.insert)||oH(e.index.afterInsert)?FW(e,t,n,r,i,a):IW(e,t,n,r,i,a)}async function FW(e,t,n=1e3,r,i,a=0){let o=[],s=async a=>{let s=Math.min(a+n,t.length),c=t.slice(a,s);for(let t of c){let n=await EW(e,t,r,i,{avlRebalanceThreshold:c.length});o.push(n)}return s};return await(async()=>{let e=0;for(;e<t.length;){let t=Date.now();if(e=await s(e),a>0){let e=a-(Date.now()-t);e>0&&fH(e)}}})(),i||await GH(e.afterInsertMultiple,e,t),o}function IW(e,t,n=1e3,r,i,a=0){let o=[],s=0;function c(){let a=t.slice(s*n,(s+1)*n);if(a.length===0)return!1;for(let t of a){let n=EW(e,t,r,i,{avlRebalanceThreshold:a.length});o.push(n)}return s++,!0}function l(){let e=Date.now();for(;c();)if(a>0){let t=Date.now()-e;if(t>=a){let e=a-t%a;e>0&&fH(e)}}}return l(),i||GH(e.afterInsertMultiple,e,t),o}function LW(e,t){return e[1]-t[1]}function RW(e,t){return t[1]-e[1]}function zW(e=`desc`){return e.toLowerCase()===`asc`?LW:RW}function BW(e,t,n){let r={},i=t.map(([e])=>e),a=e.documentsStore.getMultiple(e.data.docs,i),o=Object.keys(n),s=e.index.getSearchablePropertiesWithTypes(e.data.index);for(let e of o){let t;if(s[e]===`number`){let{ranges:r}=n[e],i=r.length,a=Array.from({length:i});for(let e=0;e<i;e++){let t=r[e];a[e]=[`${t.from}-${t.to}`,0]}t=Object.fromEntries(a)}r[e]={count:0,values:t??{}}}let c=a.length;for(let e=0;e<c;e++){let t=a[e];for(let e of o){let i=e.includes(`.`)?nH(t,e):t[e],a=s[e],o=r[e].values;switch(a){case`number`:{let t=n[e].ranges;VW(t,o)(i);break}case`number[]`:{let t=new Set,r=n[e].ranges,a=VW(r,o,t);for(let e of i)a(e);break}case`boolean`:case`enum`:case`string`:HW(o,a)(i);break;case`boolean[]`:case`enum[]`:case`string[]`:{let e=HW(o,a===`boolean[]`?`boolean`:`string`,new Set);for(let t of i)e(t);break}default:throw mH(`FACET_NOT_SUPPORTED`,a)}}}for(let e of o){let t=r[e];if(t.count=Object.keys(t.values).length,s[e]===`string`){let r=n[e],i=zW(r.sort);t.values=Object.fromEntries(Object.entries(t.values).sort(i).slice(r.offset??0,r.limit??10))}}return r}function VW(e,t,n){return r=>{for(let i of e){let e=`${i.from}-${i.to}`;n?.has(e)||r>=i.from&&r<=i.to&&(t[e]===void 0?t[e]=1:(t[e]++,n?.add(e)))}}}function HW(e,t,n){let r=t===`boolean`?`false`:``;return t=>{let i=t?.toString()??r;n?.has(i)||(e[i]=(e[i]??0)+1,n?.add(i))}}const UW={reducer:(e,t,n,r)=>(t[r]=n,t),getInitialValue:e=>Array.from({length:e})},WW=[`string`,`number`,`boolean`];function GW(e,t,n){let r=n.properties,i=r.length,a=e.index.getSearchablePropertiesWithTypes(e.data.index);for(let e=0;e<i;e++){let t=r[e];if(a[t]===void 0)throw mH(`UNKNOWN_GROUP_BY_PROPERTY`,t);if(!WW.includes(a[t]))throw mH(`INVALID_GROUP_BY_PROPERTY`,t,WW.join(`, `),a[t])}let o=t.map(([t])=>kH(e.internalDocumentIDStore,t)),s=e.documentsStore.getMultiple(e.data.docs,o),c=s.length,l=n.maxResult||2**53-1,u=[],d={};for(let e=0;e<i;e++){let t=r[e],n={property:t,perValue:{}},i=new Set;for(let e=0;e<c;e++){let r=s[e],a=nH(r,t);if(a===void 0)continue;let o=typeof a==`boolean`?``+a:a,c=n.perValue[o]??{indexes:[],count:0};c.count>=l||(c.indexes.push(e),c.count++,n.perValue[o]=c,i.add(a))}u.push(Array.from(i)),d[t]=n}let f=KW(u),p=f.length,m=[];for(let e=0;e<p;e++){let t=f[e],n=t.length,i={values:[],indexes:[]},a=[];for(let e=0;e<n;e++){let n=t[e],o=r[e];a.push(d[o].perValue[typeof n==`boolean`?``+n:n].indexes),i.values.push(n)}i.indexes=eH(a).sort((e,t)=>e-t),i.indexes.length!==0&&m.push(i)}let h=m.length,g=Array.from({length:h});for(let e=0;e<h;e++){let r=m[e],i=n.reduce||UW,a=r.indexes.map(e=>({id:o[e],score:t[e][1],document:s[e]})),c=i.reducer.bind(null,r.values),l=i.getInitialValue(r.indexes.length),u=a.reduce(c,l);g[e]={values:r.values,result:u}}return g}function KW(e,t=0){if(t+1===e.length)return e[t].map(e=>[e]);let n=e[t],r=KW(e,t+1),i=[];for(let e of n)for(let t of r){let n=[e];WV(n,t),i.push(n)}return i}function qW(e,t,n,r){let i=vW(t,r);if(i.length===0)return n;let a=i.flatMap(e=>e.consequence.promote);a.sort((e,t)=>e.position-t.position);let o=new Set,s=new Map,c=new Set;for(let t of a){let n=OH(e.internalDocumentIDStore,t.doc_id);if(n!==void 0){if(s.has(n)){let e=s.get(n);t.position<e&&s.set(n,t.position);continue}c.has(t.position)||(o.add(n),s.set(n,t.position),c.add(t.position))}}if(s.size===0)return n;let l=n.filter(([e])=>!o.has(e)),u=[];for(let[t,r]of s.entries())n.find(([e])=>e===t)?u.push([t,1e6-r]):e.documentsStore.get(e.data.docs,t)&&u.push([t,0]);u.sort((e,t)=>(s.get(e[0])??1/0)-(s.get(t[0])??1/0));let d=[],f=new Map;for(let e of u){let t=s.get(e[0]);f.set(t,e)}let p=0,m=0;for(;m<l.length+u.length;)if(f.has(m))d.push(f.get(m)),m++;else if(p<l.length)d.push(l[p]),p++,m++;else break;for(let[e,t]of f.entries())e>=d.length&&d.push(t);return d}function JW(e,t,n){let{term:r,properties:i}=t,a=e.data.index,o=e.caches.propertiesToSearch;if(!o){let t=e.index.getSearchablePropertiesWithTypes(a);o=e.index.getSearchableProperties(a),o=o.filter(e=>t[e].startsWith(`string`)),e.caches.propertiesToSearch=o}if(i&&i!==`*`){for(let e of i)if(!o.includes(e))throw mH(`UNKNOWN_INDEX`,e,o.join(`, `));o=o.filter(e=>i.includes(e))}let s=Object.keys(t.where??{}).length>0,c;s&&(c=e.index.searchByWhereClause(a,e.tokenizer,t.where,n));let l,u=t.threshold!==void 0&&t.threshold!==null?t.threshold:1;if(r||i){let i=TW(e);if(l=e.index.search(a,r||``,e.tokenizer,n,o,t.exact||!1,t.tolerance||0,t.boost||{},$W(t.relevance),i,c,u),t.exact&&r){let t=r.trim().split(/\s+/);l=l.filter(([n])=>{let r=e.documentsStore.get(e.data.docs,n);if(!r)return!1;for(let e of o){let n=XW(r,e);if(typeof n==`string`&&t.every(e=>RegExp(`\\b${YW(e)}\\b`).test(n)))return!0}return!1})}}else l=s?AU(a,t.where)||(c?Array.from(c):[]).map(e=>[+e,0]):Object.keys(e.documentsStore.getAll(e.data.docs)).map(e=>[+e,0]);return l}function YW(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function XW(e,t){let n=t.split(`.`),r=e;for(let e of n)if(r&&typeof r==`object`&&e in r)r=r[e];else return;return r}function ZW(e,t,n){let r=XV();function i(){let i=Object.keys(e.data.index.vectorIndexes),a=t.facets&&Object.keys(t.facets).length>0,{limit:o=10,offset:s=0,distinctOn:c,includeVectors:l=!1}=t,u=t.preflight===!0,d=JW(e,t,n);if(t.sortBy)if(typeof t.sortBy==`function`){let n=d.map(([e])=>e),r=e.documentsStore.getMultiple(e.data.docs,n).map((e,t)=>[d[t][0],d[t][1],e]);r.sort(t.sortBy),d=r.map(([e,t])=>[e,t])}else d=e.sorter.sortBy(e.data.sorting,d,t.sortBy).map(([t,n])=>[OH(e.internalDocumentIDStore,t),n]);else d=d.sort($V);d=qW(e,e.data.pinning,d,t.term);let f;u||(f=c?dG(e,d,s,o,c):fG(e,d,s,o));let p={elapsed:{formatted:``,raw:0},hits:[],count:d.length};return f!==void 0&&(p.hits=f.filter(Boolean),l||aH(p,i)),a&&(p.facets=BW(e,d,t.facets)),t.groupBy&&(p.groups=GW(e,d,t.groupBy)),p.elapsed=e.formatElapsedTime(XV()-r),p}async function a(){e.beforeSearch&&await qH(e.beforeSearch,e,t,n);let r=i();return e.afterSearch&&await KH(e.afterSearch,e,t,n,r),r}return e.beforeSearch?.length||e.afterSearch?.length?a():i()}const QW={k:1.2,b:.75,d:.5};function $W(e){let t=e??{};return t.k=t.k??QW.k,t.b=t.b??QW.b,t.d=t.d??QW.d,t}function eG(e,t,n){let r=t.vector;if(r&&(!(`value`in r)||!(`property`in r)))throw mH(`INVALID_VECTOR_INPUT`,Object.keys(r).join(`, `));let i=e.data.index.vectorIndexes[r.property];if(!i)throw mH(`UNKNOWN_VECTOR_PROPERTY`,r.property);let a=i.node.size;if(r?.value.length!==a)throw r?.property===void 0||r?.value.length===void 0?mH(`INVALID_INPUT_VECTOR`,`undefined`,a,`undefined`):mH(`INVALID_INPUT_VECTOR`,r.property,a,r.value.length);let o=e.data.index,s;return Object.keys(t.where??{}).length>0&&(s=e.index.searchByWhereClause(o,e.tokenizer,t.where,n)),i.node.find(r.value,t.similarity??.8,s)}function tG(e,t,n=`english`){let r=XV();function i(){let i=eG(e,t,n).sort($V);i=qW(e,e.data.pinning,i,void 0);let a=[];t.facets&&Object.keys(t.facets).length>0&&(a=BW(e,i,t.facets));let o=t.vector.property,s=t.includeVectors??!1,c=t.limit??10,l=t.offset??0,u=Array.from({length:c});for(let t=0;t<c;t++){let n=i[t+l];if(!n)break;let r=e.data.docs.docs[n[0]];r&&(s||(r[o]=null),u[t]={id:kH(e.internalDocumentIDStore,n[0]),score:n[1],document:r})}let d=[];t.groupBy&&(d=GW(e,i,t.groupBy));let f=XV()-r;return{count:i.length,hits:u.filter(Boolean),elapsed:{raw:Number(f),formatted:YV(f)},...a?{facets:a}:{},...d?{groups:d}:{}}}async function a(){e.beforeSearch&&await qH(e.beforeSearch,e,t,n);let r=i();return e.afterSearch&&await KH(e.afterSearch,e,t,n,r),r}return e.beforeSearch?.length||e.afterSearch?.length?a():i()}function nG(e,t,n){let r=aG(JW(e,t,n)),i=eG(e,t,n),a=t.hybridWeights;return cG(r,i,t.term??``,a)}function rG(e,t,n){let r=XV();function i(){let i=nG(e,t,n);i=qW(e,e.data.pinning,i,t.term);let a;t.facets&&Object.keys(t.facets).length>0&&(a=BW(e,i,t.facets));let o;t.groupBy&&(o=GW(e,i,t.groupBy));let s=t.offset??0,c=t.limit??10,l=fG(e,i,s,c).filter(Boolean),u=XV(),d={count:i.length,elapsed:{raw:Number(u-r),formatted:YV(u-r)},hits:l,...a?{facets:a}:{},...o?{groups:o}:{}};return(t.includeVectors??!1)||aH(d,Object.keys(e.data.index.vectorIndexes)),d}async function a(){e.beforeSearch&&await qH(e.beforeSearch,e,t,n);let r=i();return e.afterSearch&&await KH(e.afterSearch,e,t,n,r),r}return e.beforeSearch?.length||e.afterSearch?.length?a():i()}function iG(e){return e[1]}function aG(e){let t=Math.max.apply(Math,e.map(iG));return e.map(([e,n])=>[e,n/t])}function oG(e,t){return e/t}function sG(e,t){return(n,r)=>n*e+r*t}function cG(e,t,n,r){let i=Math.max.apply(Math,e.map(iG)),a=Math.max.apply(Math,t.map(iG)),{text:o,vector:s}=r&&r.text&&r.vector?r:lG(n),c=new Map,l=e.length,u=sG(o,s);for(let t=0;t<l;t++){let[n,r]=e[t],a=u(oG(r,i),0);c.set(n,a)}let d=t.length;for(let e=0;e<d;e++){let[n,r]=t[e],i=oG(r,a),o=c.get(n)??0;c.set(n,o+u(0,i))}return[...c].sort((e,t)=>t[1]-e[1])}function lG(e){return{text:.5,vector:.5}}function uG(e,t,n){let r=t.mode??`fulltext`;if(r===`fulltext`)return ZW(e,t,n);if(r===`vector`)return tG(e,t);if(r===`hybrid`)return rG(e,t);throw mH(`INVALID_SEARCH_MODE`,r)}function dG(e,t,n,r,i){let a=e.data.docs,o=new Map,s=[],c=new Set,l=t.length,u=0;for(let d=0;d<l;d++){let l=t[d];if(l===void 0)continue;let[f,p]=l;if(c.has(f))continue;let m=e.documentsStore.get(a,f),h=nH(m,i);if(!(h===void 0||o.has(h))&&(o.set(h,!0),u++,!(u<=n)&&(s.push({id:kH(e.internalDocumentIDStore,f),score:p,document:m}),c.add(f),u>=n+r)))break}return s}function fG(e,t,n,r){let i=e.data.docs,a=Array.from({length:r}),o=new Set;for(let s=n;s<r+n;s++){let n=t[s];if(n===void 0)break;let[r,c]=n;if(!o.has(r)){let t=e.documentsStore.get(i,r);a[s]={id:kH(e.internalDocumentIDStore,r),score:c,document:t},o.add(r)}}return a}var pG=n(kV(),1);const mG=1,hG={protocol:`x-ok-client-protocol`,runtime:`x-ok-client-runtime`,kind:`x-ok-client-kind`};function gG({kind:e,runtimeVersion:t}){return{[hG.protocol]:`1`,[hG.runtime]:t,[hG.kind]:e}}const _G=`__system__`,vG=1,yG=`__config__/project`,bG=`__user__/config.yml`,xG=`__local__/project`,SG=`__config__/okignore`,CG=Object.freeze([yG,xG,bG,SG]),wG=`__skill__/`,TG=`__template__/`,EG=[`project`,`global`];function DG(e){return e.startsWith(`__skill__/`)||e.startsWith(`__template__/`)}const OG=`.ok/skills`;function kG(e){return`${OG}/${e}/SKILL`}const AG=[`references`,`scripts`];function jG(e,t){let n=/^(\.ok\/skills\/[^/]+)\/SKILL$/.exec(t);if(!n)return null;let r=n[1],i=e.trim().replace(/\.mdx?$/i,``).split(`/`).filter(e=>e!==``&&e!==`.`),[a]=i;return!a||!AG.includes(a)||i.includes(`..`)||i.length<2?null:`${r}/${i.join(`/`)}`}const MG=/^\.ok\/skills\/([^/]+)\/(SKILL|references\/.+)$/;function NG(e){let t=MG.exec(e);if(!t)return null;let n=t[1],r=t[2];return r===`SKILL`?{name:n,kind:`skill`,rel:null}:{name:n,kind:`reference`,rel:r.slice(11)}}const PG=/^__skill__\/global\/([^/]+)(?:\/(references\/.+))?$/;function FG(e){let t=PG.exec(e);if(!t)return null;let n=t[1],r=t[2];return r===void 0?{name:n,kind:`skill`,rel:null}:{name:n,kind:`reference`,rel:r.slice(11)}}function IG(e,t){return e===`project`?kG(t):`${wG}${e}/${t}`}function LG(e){if(e===``)return``;try{return e.split(`/`).map(e=>decodeURIComponent(e)).join(`/`)}catch{return e}}function RG(e){if(e.startsWith(`__skill__/`)){let t=e.slice(10),n=t.indexOf(`/`);if(n<0)return null;let r=t.slice(0,n);if(r!==`global`&&r!==`project`)return null;let i=t.slice(n+1);return i?{kind:`skill`,scope:r,name:LG(i)}:null}if(e.startsWith(`__template__/`)){let t=e.slice(13);if(!t)return null;let n=t.lastIndexOf(`/`),r=n<0?t:t.slice(n+1);return r?{kind:`template`,folder:LG(n<0?``:t.slice(0,n)),name:LG(r)}:null}return null}const zG=/^(?:(.+)\/)?\.ok\/templates\/([^/]+?)(?:\.mdx?)?$/;function BG(e){let t=zG.exec(e);if(t){let e=(t[1]??``).replace(/^\/+|\/+$/g,``);return`${TG}${e?`${e}/`:``}${t[2]}`}return null}const VG=[`.mdx`,`.md`],HG=`epoch`,UG=512*1024,WG=[`claude`,`claude-desktop`,`cursor`,`codex`,`opencode`,`openclaw`,`pi`,`antigravity`,`lm-studio`,`hermes`],GG={claude:`Claude`,"claude-desktop":`Claude Desktop`,cursor:`Cursor`,codex:`Codex`,opencode:`OpenCode`,openclaw:`OpenClaw`,pi:`Pi`,antigravity:`Antigravity`,"lm-studio":`LM Studio`,hermes:`Hermes`},KG={claude:`.claude/skills`,"claude-desktop":null,cursor:`.cursor/skills`,codex:`.codex/skills`,opencode:`.opencode/skills`,openclaw:null,pi:`.pi/skills`,antigravity:null,"lm-studio":null,hermes:null},qG=WG.filter(e=>KG[e]!==null),JG=qG.filter(e=>e!==`pi`).map(e=>({hostDir:(KG[e]??``).split(`/`)[0],editorId:e})),YG={claude:`.mcp.json`,"claude-desktop":null,cursor:`.cursor/mcp.json`,codex:`.codex/config.toml`,opencode:`opencode.json`,openclaw:null,pi:`.pi/extensions/open-knowledge.ts`,antigravity:null,"lm-studio":null,hermes:null},XG={cursor:/\bCursor(?:\([^)]+\))?\/\d/,codex:/\bCodex(?:\([^)]+\))?\/\d/,"claude-desktop":/\bClaude(?:\([^)]+\))?\/\d/},ZG=`Ov23liqlSd0V1MwR6rhI`,QG=new Set([`gitlab.com`,`bitbucket.org`,`codeberg.org`,`gitea.com`,`sr.ht`,`sourcehut.org`]),$G=[`incoming`,`outgoing`,`both`];function eK(e){return $G.includes(e)}const tK=`open-knowledge`,nK=[{id:`chart`,title:`Chart`,description:`A bar chart whose series colors track the OK chart palette.`,html:`<div style="font-family:system-ui,sans-serif;padding:20px;color:var(--foreground)">
304
+ `,ANSWER_SESSION_LAST_MESSAGE_IS_NOT_ASSISTANT:`The last message in the session is not an assistant message. Cannot regenerate non-assistant messages.`,PLUGIN_COMPONENT_CONFLICT:`The component "%s" is already defined. The plugin "%s" is trying to redefine it.`};function mH(e,...t){let n=Error(GV(pH[e]??`Unsupported Orama Error code: ${e}`,...t));return n.code=e,`captureStackTrace`in Error.prototype&&Error.captureStackTrace(n),n}function hH(e){return{raw:Number(e),formatted:YV(e)}}function gH(e){if(e.id){if(typeof e.id!=`string`)throw mH(`DOCUMENT_ID_MUST_BE_STRING`,typeof e.id);return e.id}return ZV()}function _H(e,t){for(let[n,r]of Object.entries(t)){let t=e[n];if(t!==void 0&&!(r===`geopoint`&&typeof t==`object`&&typeof t.lon==`number`&&typeof t.lat==`number`)&&!(r===`enum`&&(typeof t==`string`||typeof t==`number`))){if(r===`enum[]`&&Array.isArray(t)){let e=t.length;for(let r=0;r<e;r++)if(typeof t[r]!=`string`&&typeof t[r]!=`number`)return n+`.`+r;continue}if(xH(r)){let e=wH(r);if(!Array.isArray(t)||t.length!==e)throw mH(`INVALID_INPUT_VECTOR`,n,e,t.length);continue}if(SH(r)){if(!Array.isArray(t))return n;let e=CH(r),i=t.length;for(let r=0;r<i;r++)if(typeof t[r]!==e)return n+`.`+r;continue}if(typeof r==`object`){if(!t||typeof t!=`object`)return n;let e=_H(t,r);if(e)return n+`.`+e;continue}if(typeof t!==r)return n}}}const vH={string:!1,number:!1,boolean:!1,enum:!1,geopoint:!1,"string[]":!0,"number[]":!0,"boolean[]":!0,"enum[]":!0},yH={"string[]":`string`,"number[]":`number`,"boolean[]":`boolean`,"enum[]":`enum`};function bH(e){return e===`geopoint`}function xH(e){return typeof e==`string`&&/^vector\[\d+\]$/.test(e)}function SH(e){return typeof e==`string`&&vH[e]}function CH(e){return yH[e]}function wH(e){let t=Number(e.slice(7,-1));switch(!0){case isNaN(t):throw mH(`INVALID_VECTOR_VALUE`,e);case t<=0:throw mH(`INVALID_VECTOR_SIZE`,e);default:return t}}function TH(){return{idToInternalId:new Map,internalIdToId:[],save:EH,load:DH}}function EH(e){return{internalIdToId:e.internalIdToId}}function DH(e,t){let{internalIdToId:n}=t;e.internalDocumentIDStore.idToInternalId.clear(),e.internalDocumentIDStore.internalIdToId=[];let r=n.length;for(let t=0;t<r;t++){let r=n[t];e.internalDocumentIDStore.idToInternalId.set(r,t+1),e.internalDocumentIDStore.internalIdToId.push(r)}}function OH(e,t){if(typeof t==`string`){let n=e.idToInternalId.get(t);if(n)return n;let r=e.idToInternalId.size+1;return e.idToInternalId.set(t,r),e.internalIdToId.push(t),r}return t>e.internalIdToId.length?OH(e,t.toString()):t}function kH(e,t){if(e.internalIdToId.length<t)throw Error(`Invalid internalId ${t}`);return e.internalIdToId[t-1]}function AH(e,t){return{sharedInternalDocumentStore:t,docs:{},count:0}}function jH(e,t){let n=OH(e.sharedInternalDocumentStore,t);return e.docs[n]}function MH(e,t){let n=t.length,r=Array.from({length:n});for(let i=0;i<n;i++){let n=OH(e.sharedInternalDocumentStore,t[i]);r[i]=e.docs[n]}return r}function NH(e){return e.docs}function PH(e,t,n,r){return e.docs[n]===void 0?(e.docs[n]=r,e.count++,!0):!1}function FH(e,t){let n=OH(e.sharedInternalDocumentStore,t);return e.docs[n]===void 0?!1:(delete e.docs[n],e.count--,!0)}function IH(e){return e.count}function LH(e,t){let n=t;return{docs:n.docs,count:n.count,sharedInternalDocumentStore:e}}function RH(e){return{docs:e.docs,count:e.count}}function zH(){return{create:AH,get:jH,getMultiple:MH,getAll:NH,store:PH,remove:FH,count:IH,load:LH,save:RH}}const BH=[`beforeInsert`,`afterInsert`,`beforeRemove`,`afterRemove`,`beforeUpdate`,`afterUpdate`,`beforeUpsert`,`afterUpsert`,`beforeSearch`,`afterSearch`,`beforeInsertMultiple`,`afterInsertMultiple`,`beforeRemoveMultiple`,`afterRemoveMultiple`,`beforeUpdateMultiple`,`afterUpdateMultiple`,`beforeUpsertMultiple`,`afterUpsertMultiple`,`beforeLoad`,`afterLoad`,`afterCreate`];function VH(e,t){let n=[],r=e.plugins?.length;if(!r)return n;for(let i=0;i<r;i++)try{let r=e.plugins[i];typeof r[t]==`function`&&n.push(r[t])}catch(e){throw console.error(`Caught error in getAllPluginsByHook:`,e),mH(`PLUGIN_CRASHED`)}return n}const HH=[`tokenizer`,`index`,`documentsStore`,`sorter`,`pinning`],UH=[`validateSchema`,`getDocumentIndexId`,`getDocumentProperties`,`formatElapsedTime`];function WH(e,t,n,r){if(e.some(oH))return(async()=>{for(let i of e)await i(t,n,r)})();for(let i of e)i(t,n,r)}function GH(e,t,n){if(e.some(oH))return(async()=>{for(let r of e)await r(t,n)})();for(let r of e)r(t,n)}function KH(e,t,n,r,i){if(e.some(oH))return(async()=>{for(let a of e)await a(t,n,r,i)})();for(let a of e)a(t,n,r,i)}function qH(e,t,n,r){if(e.some(oH))return(async()=>{for(let i of e)await i(t,n,r)})();for(let i of e)i(t,n,r)}function JH(e,t){if(e.some(oH))return(async()=>{for(let n of e)await n(t)})();for(let n of e)n(t)}var YH=class e{k;v;l=null;r=null;h=1;constructor(e,t){this.k=e,this.v=new Set(t)}updateHeight(){this.h=Math.max(e.getHeight(this.l),e.getHeight(this.r))+1}static getHeight(e){return e?e.h:0}getBalanceFactor(){return e.getHeight(this.l)-e.getHeight(this.r)}rotateLeft(){let e=this.r;return this.r=e.l,e.l=this,this.updateHeight(),e.updateHeight(),e}rotateRight(){let e=this.l;return this.l=e.r,e.r=this,this.updateHeight(),e.updateHeight(),e}toJSON(){return{k:this.k,v:Array.from(this.v),l:this.l?this.l.toJSON():null,r:this.r?this.r.toJSON():null,h:this.h}}static fromJSON(t){let n=new e(t.k,t.v);return n.l=t.l?e.fromJSON(t.l):null,n.r=t.r?e.fromJSON(t.r):null,n.h=t.h,n}},XH=class e{root=null;insertCount=0;constructor(e,t){e!==void 0&&t!==void 0&&(this.root=new YH(e,t))}insert(e,t,n=1e3){this.root=this.insertNode(this.root,e,t,n)}insertMultiple(e,t,n=1e3){for(let r of t)this.insert(e,r,n)}rebalance(){this.root&&=this.rebalanceNode(this.root)}toJSON(){return{root:this.root?this.root.toJSON():null,insertCount:this.insertCount}}static fromJSON(t){let n=new e;return n.root=t.root?YH.fromJSON(t.root):null,n.insertCount=t.insertCount||0,n}insertNode(e,t,n,r){if(e===null)return new YH(t,[n]);let i=[],a=e,o=null;for(;a!==null;)if(i.push({parent:o,node:a}),t<a.k)if(a.l===null){a.l=new YH(t,[n]),i.push({parent:a,node:a.l});break}else o=a,a=a.l;else if(t>a.k)if(a.r===null){a.r=new YH(t,[n]),i.push({parent:a,node:a.r});break}else o=a,a=a.r;else return a.v.add(n),e;let s=!1;this.insertCount++%r===0&&(s=!0);for(let t=i.length-1;t>=0;t--){let{parent:n,node:r}=i[t];if(r.updateHeight(),s){let t=this.rebalanceNode(r);n?n.l===r?n.l=t:n.r===r&&(n.r=t):e=t}}return e}rebalanceNode(e){let t=e.getBalanceFactor();if(t>1){if(e.l&&e.l.getBalanceFactor()>=0)return e.rotateRight();if(e.l)return e.l=e.l.rotateLeft(),e.rotateRight()}if(t<-1){if(e.r&&e.r.getBalanceFactor()<=0)return e.rotateLeft();if(e.r)return e.r=e.r.rotateRight(),e.rotateLeft()}return e}find(e){let t=this.findNodeByKey(e);return t?t.v:null}contains(e){return this.find(e)!==null}getSize(){let e=0,t=[],n=this.root;for(;n||t.length>0;){for(;n;)t.push(n),n=n.l;n=t.pop(),e++,n=n.r}return e}isBalanced(){if(!this.root)return!0;let e=[this.root];for(;e.length>0;){let t=e.pop(),n=t.getBalanceFactor();if(Math.abs(n)>1)return!1;t.l&&e.push(t.l),t.r&&e.push(t.r)}return!0}remove(e){this.root=this.removeNode(this.root,e)}removeDocument(e,t){let n=this.findNodeByKey(e);n&&(n.v.size===1?this.root=this.removeNode(this.root,e):n.v=new Set([...n.v.values()].filter(e=>e!==t)))}findNodeByKey(e){let t=this.root;for(;t;)if(e<t.k)t=t.l;else if(e>t.k)t=t.r;else return t;return null}removeNode(e,t){if(e===null)return null;let n=[],r=e;for(;r!==null&&r.k!==t;)n.push(r),r=t<r.k?r.l:r.r;if(r===null)return e;if(r.l===null||r.r===null){let t=r.l?r.l:r.r;if(n.length===0)e=t;else{let e=n[n.length-1];e.l===r?e.l=t:e.r=t}}else{let e=r,t=r.r;for(;t.l!==null;)e=t,t=t.l;r.k=t.k,r.v=t.v,e.l===t?e.l=t.r:e.r=t.r,r=e}n.push(r);for(let t=n.length-1;t>=0;t--){let r=n[t];r.updateHeight();let i=this.rebalanceNode(r);if(t>0){let e=n[t-1];e.l===r?e.l=i:e.r===r&&(e.r=i)}else e=i}return e}rangeSearch(e,t){let n=new Set,r=[],i=this.root;for(;i||r.length>0;){for(;i;)r.push(i),i=i.l;if(i=r.pop(),i.k>=e&&i.k<=t)for(let e of i.v)n.add(e);if(i.k>t)break;i=i.r}return n}greaterThan(e,t=!1){let n=new Set,r=[],i=this.root;for(;i||r.length>0;){for(;i;)r.push(i),i=i.r;if(i=r.pop(),t&&i.k>=e||!t&&i.k>e)for(let e of i.v)n.add(e);else if(i.k<=e)break;i=i.l}return n}lessThan(e,t=!1){let n=new Set,r=[],i=this.root;for(;i||r.length>0;){for(;i;)r.push(i),i=i.l;if(i=r.pop(),t&&i.k<=e||!t&&i.k<e)for(let e of i.v)n.add(e);else if(i.k>e)break;i=i.r}return n}},ZH=class e{numberToDocumentId;constructor(){this.numberToDocumentId=new Map}insert(e,t){this.numberToDocumentId.has(e)?this.numberToDocumentId.get(e).add(t):this.numberToDocumentId.set(e,new Set([t]))}find(e){let t=this.numberToDocumentId.get(e);return t?Array.from(t):null}remove(e){this.numberToDocumentId.delete(e)}removeDocument(e,t){let n=this.numberToDocumentId.get(t);n&&(n.delete(e),n.size===0&&this.numberToDocumentId.delete(t))}contains(e){return this.numberToDocumentId.has(e)}getSize(){let e=0;for(let t of this.numberToDocumentId.values())e+=t.size;return e}filter(e){let t=Object.keys(e);if(t.length!==1)throw Error(`Invalid operation`);let n=t[0];switch(n){case`eq`:{let t=e[n],r=this.numberToDocumentId.get(t);return r?Array.from(r):[]}case`in`:{let t=e[n],r=new Set;for(let e of t){let t=this.numberToDocumentId.get(e);if(t)for(let e of t)r.add(e)}return Array.from(r)}case`nin`:{let t=new Set(e[n]),r=new Set;for(let[e,n]of this.numberToDocumentId.entries())if(!t.has(e))for(let e of n)r.add(e);return Array.from(r)}default:throw Error(`Invalid operation`)}}filterArr(e){let t=Object.keys(e);if(t.length!==1)throw Error(`Invalid operation`);let n=t[0];switch(n){case`containsAll`:{let t=e[n].map(e=>this.numberToDocumentId.get(e)??new Set);if(t.length===0)return[];let r=t.reduce((e,t)=>new Set([...e].filter(e=>t.has(e))));return Array.from(r)}case`containsAny`:{let t=e[n].map(e=>this.numberToDocumentId.get(e)??new Set);if(t.length===0)return[];let r=t.reduce((e,t)=>new Set([...e,...t]));return Array.from(r)}default:throw Error(`Invalid operation`)}}static fromJSON(t){if(!t.numberToDocumentId)throw Error(`Invalid Flat Tree JSON`);let n=new e;for(let[e,r]of t.numberToDocumentId)n.numberToDocumentId.set(e,new Set(r));return n}toJSON(){return{numberToDocumentId:Array.from(this.numberToDocumentId.entries()).map(([e,t])=>[e,Array.from(t)])}}};function QH(e,t,n){if(n<0)return-1;if(e===t)return 0;let r=e.length,i=t.length;if(r===0)return i<=n?i:-1;if(i===0)return r<=n?r:-1;let a=Math.abs(r-i);if(e.startsWith(t))return a<=n?a:-1;if(t.startsWith(e))return 0;if(a>n)return-1;let o=[];for(let e=0;e<=r;e++){o[e]=[e];for(let t=1;t<=i;t++)o[e][t]=e===0?t:0}for(let a=1;a<=r;a++){let r=1/0;for(let n=1;n<=i;n++)e[a-1]===t[n-1]?o[a][n]=o[a-1][n-1]:o[a][n]=Math.min(o[a-1][n]+1,o[a][n-1]+1,o[a-1][n-1]+1),r=Math.min(r,o[a][n]);if(r>n)return-1}return o[r][i]<=n?o[r][i]:-1}function $H(e,t,n){let r=QH(e,t,n);return{distance:r,isBounded:r>=0}}var eU=class e{k;s;c=new Map;d=new Set;e;w=``;constructor(e,t,n){this.k=e,this.s=t,this.e=n}updateParent(e){this.w=e.w+this.s}addDocument(e){this.d.add(e)}removeDocument(e){return this.d.delete(e)}findAllWords(e,t,n,r){let i=[this];for(;i.length>0;){let a=i.pop();if(a.e){let{w:i,d:o}=a;if(n&&i!==t)continue;if(QV(e,i)!==null)if(r)if(Math.abs(t.length-i.length)<=r&&$H(t,i,r).isBounded)e[i]=[];else continue;else e[i]=[];if(QV(e,i)!=null&&o.size>0){let t=e[i];for(let e of o)t.includes(e)||t.push(e)}}a.c.size>0&&i.push(...a.c.values())}return e}insert(t,n){let r=this,i=0,a=t.length;for(;i<a;){let o=t[i],s=r.c.get(o);if(s){let o=s.s,c=o.length,l=0;for(;l<c&&i+l<a&&o[l]===t[i+l];)l++;if(l===c){if(r=s,i+=l,i===a){s.e||=!0,s.addDocument(n);return}continue}let u=o.slice(0,l),d=o.slice(l),f=t.slice(i+l),p=new e(u[0],u,!1);if(r.c.set(u[0],p),p.updateParent(r),s.s=d,s.k=d[0],p.c.set(d[0],s),s.updateParent(p),f){let t=new e(f[0],f,!0);t.addDocument(n),p.c.set(f[0],t),t.updateParent(p)}else p.e=!0,p.addDocument(n);return}else{let a=new e(o,t.slice(i),!0);a.addDocument(n),r.c.set(o,a),a.updateParent(r);return}}r.e||=!0,r.addDocument(n)}_findLevenshtein(e,t,n,r,i){let a=[{node:this,index:t,tolerance:n}];for(;a.length>0;){let{node:t,index:n,tolerance:o}=a.pop();if(t.w.startsWith(e)){t.findAllWords(i,e,!1,0);continue}if(o<0)continue;if(t.e){let{w:n,d:a}=t;if(n&&($H(e,n,r).isBounded&&(i[n]=[]),QV(i,n)!==void 0&&a.size>0)){let e=new Set(i[n]);for(let t of a)e.add(t);i[n]=Array.from(e)}}if(n>=e.length)continue;let s=e[n];if(t.c.has(s)){let e=t.c.get(s);a.push({node:e,index:n+1,tolerance:o})}a.push({node:t,index:n+1,tolerance:o-1});for(let[e,r]of t.c)a.push({node:r,index:n,tolerance:o-1}),e!==s&&a.push({node:r,index:n+1,tolerance:o-1})}}find(e){let{term:t,exact:n,tolerance:r}=e;if(r&&!n){let e={};return this._findLevenshtein(t,0,r,r,e),e}else{let e=this,i=0,a=t.length;for(;i<a;){let o=t[i],s=e.c.get(o);if(s){let o=s.s,c=o.length,l=0;for(;l<c&&i+l<a&&o[l]===t[i+l];)l++;if(l===c)e=s,i+=l;else if(i+l===a)if(l===a-i){if(n)return{};{let e={};return s.findAllWords(e,t,n,r),e}}else return{};else return{}}else return{}}let o={};return e.findAllWords(o,t,n,r),o}}contains(e){let t=this,n=0,r=e.length;for(;n<r;){let i=e[n],a=t.c.get(i);if(a){let i=a.s,o=i.length,s=0;for(;s<o&&n+s<r&&i[s]===e[n+s];)s++;if(s<o)return!1;n+=o,t=a}else return!1}return!0}removeWord(e){if(!e)return!1;let t=this,n=e.length,r=[];for(let i=0;i<n;i++){let n=e[i];if(t.c.has(n)){let e=t.c.get(n);r.push({parent:t,character:n}),i+=e.s.length-1,t=e}else return!1}for(t.d.clear(),t.e=!1;r.length>0&&t.c.size===0&&!t.e&&t.d.size===0;){let{parent:e,character:n}=r.pop();e.c.delete(n),t=e}return!0}removeDocumentByWord(e,t,n=!0){if(!e)return!0;let r=this,i=e.length;for(let a=0;a<i;a++){let i=e[a];if(r.c.has(i)){let o=r.c.get(i);a+=o.s.length-1,r=o,n&&r.w!==e||r.removeDocument(t)}else return!1}return!0}static getCommonPrefix(e,t){let n=Math.min(e.length,t.length),r=0;for(;r<n&&e.charCodeAt(r)===t.charCodeAt(r);)r++;return e.slice(0,r)}toJSON(){return{w:this.w,s:this.s,e:this.e,k:this.k,d:Array.from(this.d),c:Array.from(this.c?.entries())?.map(([e,t])=>[e,t.toJSON()])}}static fromJSON(t){let n=new e(t.k,t.s,t.e);return n.w=t.w,n.d=new Set(t.d),n.c=new Map(t?.c?.map(([t,n])=>[t,e.fromJSON(n)])||[]),n}},tU=class e extends eU{constructor(){super(``,``,!1)}static fromJSON(t){let n=new e;return n.w=t.w,n.s=t.s,n.e=t.e,n.k=t.k,n.d=new Set(t.d),n.c=new Map(t?.c?.map(([e,t])=>[e,eU.fromJSON(t)])||[]),n}toJSON(){return super.toJSON()}},nU=class e{point;docIDs;left;right;parent;constructor(e,t){this.point=e,this.docIDs=new Set(t),this.left=null,this.right=null,this.parent=null}toJSON(){return{point:this.point,docIDs:Array.from(this.docIDs),left:this.left?this.left.toJSON():null,right:this.right?this.right.toJSON():null}}static fromJSON(t,n=null){let r=new e(t.point,t.docIDs);return r.parent=n,t.left&&(r.left=e.fromJSON(t.left,r)),t.right&&(r.right=e.fromJSON(t.right,r)),r}},rU=class e{root;nodeMap;constructor(){this.root=null,this.nodeMap=new Map}getPointKey(e){return`${e.lon},${e.lat}`}insert(e,t){let n=this.getPointKey(e),r=this.nodeMap.get(n);if(r){t.forEach(e=>r.docIDs.add(e));return}let i=new nU(e,t);if(this.nodeMap.set(n,i),this.root==null){this.root=i;return}let a=this.root,o=0;for(;;){if(o%2==0)if(e.lon<a.point.lon){if(a.left==null){a.left=i,i.parent=a;return}a=a.left}else{if(a.right==null){a.right=i,i.parent=a;return}a=a.right}else if(e.lat<a.point.lat){if(a.left==null){a.left=i,i.parent=a;return}a=a.left}else{if(a.right==null){a.right=i,i.parent=a;return}a=a.right}o++}}contains(e){let t=this.getPointKey(e);return this.nodeMap.has(t)}getDocIDsByCoordinates(e){let t=this.getPointKey(e),n=this.nodeMap.get(t);return n?Array.from(n.docIDs):null}removeDocByID(e,t){let n=this.getPointKey(e),r=this.nodeMap.get(n);r&&(r.docIDs.delete(t),r.docIDs.size===0&&(this.nodeMap.delete(n),this.deleteNode(r)))}deleteNode(e){let t=e.parent,n=e.left?e.left:e.right;n&&(n.parent=t),t?t.left===e?t.left=n:t.right===e&&(t.right=n):(this.root=n,this.root&&(this.root.parent=null))}searchByRadius(t,n,r=!0,i=`asc`,a=!1){let o=a?e.vincentyDistance:e.haversineDistance,s=[{node:this.root,depth:0}],c=[];for(;s.length>0;){let{node:e,depth:i}=s.pop();if(e==null)continue;let a=o(t,e.point);(r?a<=n:a>n)&&c.push({point:e.point,docIDs:Array.from(e.docIDs)}),e.left!=null&&s.push({node:e.left,depth:i+1}),e.right!=null&&s.push({node:e.right,depth:i+1})}return i&&c.sort((e,n)=>{let r=o(t,e.point),a=o(t,n.point);return i.toLowerCase()===`asc`?r-a:a-r}),c}searchByPolygon(t,n=!0,r=null,i=!1){let a=[{node:this.root,depth:0}],o=[];for(;a.length>0;){let{node:r,depth:i}=a.pop();if(r==null)continue;r.left!=null&&a.push({node:r.left,depth:i+1}),r.right!=null&&a.push({node:r.right,depth:i+1});let s=e.isPointInPolygon(t,r.point);(s&&n||!s&&!n)&&o.push({point:r.point,docIDs:Array.from(r.docIDs)})}let s=e.calculatePolygonCentroid(t);if(r){let t=i?e.vincentyDistance:e.haversineDistance;o.sort((e,n)=>{let i=t(s,e.point),a=t(s,n.point);return r.toLowerCase()===`asc`?i-a:a-i})}return o}toJSON(){return{root:this.root?this.root.toJSON():null}}static fromJSON(t){let n=new e;return t.root&&(n.root=nU.fromJSON(t.root),n.buildNodeMap(n.root)),n}buildNodeMap(e){if(e==null)return;let t=this.getPointKey(e.point);this.nodeMap.set(t,e),e.left&&this.buildNodeMap(e.left),e.right&&this.buildNodeMap(e.right)}static calculatePolygonCentroid(e){let t=0,n=0,r=0,i=e.length;for(let a=0,o=i-1;a<i;o=a++){let i=e[a].lon,s=e[a].lat,c=e[o].lon,l=e[o].lat,u=i*l-c*s;t+=u,n+=(i+c)*u,r+=(s+l)*u}t/=2;let a=6*t;return n/=a,r/=a,{lon:n,lat:r}}static isPointInPolygon(e,t){let n=!1,r=t.lon,i=t.lat,a=e.length;for(let t=0,o=a-1;t<a;o=t++){let a=e[t].lon,s=e[t].lat,c=e[o].lon,l=e[o].lat;s>i!=l>i&&r<(c-a)*(i-s)/(l-s)+a&&(n=!n)}return n}static haversineDistance(e,t){let n=Math.PI/180,r=e.lat*n,i=t.lat*n,a=(t.lat-e.lat)*n,o=(t.lon-e.lon)*n,s=Math.sin(a/2)*Math.sin(a/2)+Math.cos(r)*Math.cos(i)*Math.sin(o/2)*Math.sin(o/2);return 6371e3*(2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s)))}static vincentyDistance(e,t){let n=6378137,r=1/298.257223563,i=(1-r)*n,a=Math.PI/180,o=e.lat*a,s=t.lat*a,c=(t.lon-e.lon)*a,l=Math.atan((1-r)*Math.tan(o)),u=Math.atan((1-r)*Math.tan(s)),d=Math.sin(l),f=Math.cos(l),p=Math.sin(u),m=Math.cos(u),h=c,g,_=1e3,v,y,b,x,S,C;do{let e=Math.sin(h),t=Math.cos(h);if(v=Math.sqrt(m*e*(m*e)+(f*p-d*m*t)*(f*p-d*m*t)),v===0)return 0;y=d*p+f*m*t,b=Math.atan2(v,y),x=f*m*e/v,S=1-x*x,C=y-2*d*p/S,isNaN(C)&&(C=0);let n=r/16*S*(4+r*(4-3*S));g=h,h=c+(1-n)*r*x*(b+n*v*(C+n*y*(-1+2*C*C)))}while(Math.abs(h-g)>1e-12&&--_>0);if(_===0)return NaN;let w=S*(n*n-i*i)/(i*i),T=1+w/16384*(4096+w*(-768+w*(320-175*w))),E=w/1024*(256+w*(-128+w*(74-47*w))),ee=E*v*(C+E/4*(y*(-1+2*C*C)-E/6*C*(-3+4*v*v)*(-3+4*C*C)));return i*T*(b-ee)}},iU=class e{true;false;constructor(){this.true=new Set,this.false=new Set}insert(e,t){t?this.true.add(e):this.false.add(e)}delete(e,t){t?this.true.delete(e):this.false.delete(e)}getSize(){return this.true.size+this.false.size}toJSON(){return{true:Array.from(this.true),false:Array.from(this.false)}}static fromJSON(t){let n=new e;return n.true=new Set(t.true),n.false=new Set(t.false),n}};function aU(e,t,n,r,i,{k:a,b:o,d:s}){return Math.log(1+(n-t+.5)/(t+.5))*(s+e*(a+1))/(e+a*(1-o+o*r/i))}var oU=class e{size;vectors=new Map;constructor(e){this.size=e}add(e,t){t instanceof Float32Array||(t=new Float32Array(t));let n=sU(t,this.size);this.vectors.set(e,[n,t])}remove(e){this.vectors.delete(e)}find(e,t,n){return e instanceof Float32Array||(e=new Float32Array(e)),cU(e,n,this.vectors,this.size,t)}toJSON(){let e=[];for(let[t,[n,r]]of this.vectors)e.push([t,[n,Array.from(r)]]);return{size:this.size,vectors:e}}static fromJSON(t){let n=t,r=new e(n.size);for(let[e,[t,i]]of n.vectors)r.vectors.set(e,[t,new Float32Array(i)]);return r}};function sU(e,t){let n=0;for(let r=0;r<t;r++)n+=e[r]*e[r];return Math.sqrt(n)}function cU(e,t,n,r,i){let a=sU(e,r),o=[],s=t||n.keys();for(let t of s){let s=n.get(t);if(!s)continue;let c=s[0],l=s[1],u=0;for(let t=0;t<r;t++)u+=e[t]*l[t];let d=u/(a*c);d>=i&&o.push([t,d])}return o}function lU(e,t,n,r,i){let a=OH(e.sharedInternalDocumentStore,n);e.avgFieldLength[t]=((e.avgFieldLength[t]??0)*(i-1)+r.length)/i,e.fieldLengths[t][a]=r.length,e.frequencies[t][a]={}}function uU(e,t,n,r,i){let a=0;for(let e of r)e===i&&a++;let o=OH(e.sharedInternalDocumentStore,n),s=a/r.length;e.frequencies[t][o][i]=s,i in e.tokenOccurrences[t]||(e.tokenOccurrences[t][i]=0),e.tokenOccurrences[t][i]=(e.tokenOccurrences[t][i]??0)+1}function dU(e,t,n,r){let i=OH(e.sharedInternalDocumentStore,n);r>1?e.avgFieldLength[t]=(e.avgFieldLength[t]*r-e.fieldLengths[t][i])/(r-1):e.avgFieldLength[t]=void 0,e.fieldLengths[t][i]=void 0,e.frequencies[t][i]=void 0}function fU(e,t,n){e.tokenOccurrences[t][n]--}function pU(e,t,n,r,i=``){r||={sharedInternalDocumentStore:t,indexes:{},vectorIndexes:{},searchableProperties:[],searchablePropertiesWithTypes:{},frequencies:{},tokenOccurrences:{},avgFieldLength:{},fieldLengths:{}};for(let[a,o]of Object.entries(n)){let n=`${i}${i?`.`:``}${a}`;if(typeof o==`object`&&!Array.isArray(o)){pU(e,t,o,r,n);continue}if(xH(o))r.searchableProperties.push(n),r.searchablePropertiesWithTypes[n]=o,r.vectorIndexes[n]={type:`Vector`,node:new oU(wH(o)),isArray:!1};else{let e=/\[/.test(o);switch(o){case`boolean`:case`boolean[]`:r.indexes[n]={type:`Bool`,node:new iU,isArray:e};break;case`number`:case`number[]`:r.indexes[n]={type:`AVL`,node:new XH(0,[]),isArray:e};break;case`string`:case`string[]`:r.indexes[n]={type:`Radix`,node:new tU,isArray:e},r.avgFieldLength[n]=0,r.frequencies[n]={},r.tokenOccurrences[n]={},r.fieldLengths[n]={};break;case`enum`:case`enum[]`:r.indexes[n]={type:`Flat`,node:new ZH,isArray:e};break;case`geopoint`:r.indexes[n]={type:`BKD`,node:new rU,isArray:e};break;default:throw mH(`INVALID_SCHEMA_TYPE`,Array.isArray(o)?`array`:o,n)}r.searchableProperties.push(n),r.searchablePropertiesWithTypes[n]=o}}return r}function mU(e,t,n,r,i,a,o,s){return c=>{let{type:l,node:u}=t.indexes[n];switch(l){case`Bool`:u[c?`true`:`false`].add(r);break;case`AVL`:{let e=s?.avlRebalanceThreshold??1;u.insert(c,r,e);break}case`Radix`:{let s=a.tokenize(c,i,n,!1);e.insertDocumentScoreParameters(t,n,r,s,o);for(let i of s)e.insertTokenScoreParameters(t,n,r,s,i),u.insert(i,r);break}case`Flat`:u.insert(c,r);break;case`BKD`:u.insert(c,[r]);break}}}function hU(e,t,n,r,i,a,o,s,c,l,u){if(xH(o))return gU(t,n,a,r,i);let d=mU(e,t,n,i,s,c,l,u);if(!SH(o))return d(a);let f=a,p=f.length;for(let e=0;e<p;e++)d(f[e])}function gU(e,t,n,r,i){e.vectorIndexes[t].node.add(i,n)}function _U(e,t,n,r,i,a,o,s,c,l){if(xH(o))return t.vectorIndexes[n].node.remove(i),!0;let{type:u,node:d}=t.indexes[n];switch(u){case`AVL`:return d.removeDocument(a,i),!0;case`Bool`:return d[a?`true`:`false`].delete(i),!0;case`Radix`:{let o=c.tokenize(a,s,n);e.removeDocumentScoreParameters(t,n,r,l);for(let r of o)e.removeTokenScoreParameters(t,n,r),d.removeDocumentByWord(r,i);return!0}case`Flat`:return d.removeDocument(i,a),!0;case`BKD`:return d.removeDocByID(a,i),!1}}function vU(e,t,n,r,i,a,o,s,c,l){if(!SH(o))return _U(e,t,n,r,i,a,o,s,c,l);let u=CH(o),d=a,f=d.length;for(let a=0;a<f;a++)_U(e,t,n,r,i,d[a],u,s,c,l);return!0}function yU(e,t,n,r,i,a,o,s,c,l){let u=Array.from(r),d=e.avgFieldLength[t],f=e.fieldLengths[t],p=e.tokenOccurrences[t],m=e.frequencies[t],h=typeof p[n]==`number`?p[n]??0:0,g=u.length;for(let e=0;e<g;e++){let r=u[e];if(c&&!c.has(r))continue;l.has(r)||l.set(r,new Map);let p=l.get(r);p.set(t,(p.get(t)||0)+1);let g=aU(m?.[r]?.[n]??0,h,i,f[r],d,a);o.has(r)?o.set(r,o.get(r)+g*s):o.set(r,g*s)}}function bU(e,t,n,r,i,a,o,s,c,l,u,d=0){let f=n.tokenize(t,r),p=f.length||1,m=new Map,h=new Map,g=new Map;for(let n of i){if(!(n in e.indexes))continue;let r=e.indexes[n],{type:i}=r;if(i!==`Radix`)throw mH(`WRONG_SEARCH_PROPERTY_TYPE`,n);let d=s[n]??1;if(d<=0)throw mH(`INVALID_BOOST_VALUE`,d);f.length===0&&!t&&f.push(``);let p=f.length;for(let t=0;t<p;t++){let i=f[t],s=r.node.find({term:i,exact:a,tolerance:o}),p=Object.keys(s);p.length>0&&h.set(i,!0);let _=p.length;for(let t=0;t<_;t++){let r=p[t],i=s[r];yU(e,n,r,i,l,c,g,d,u,m)}}}let _=Array.from(g.entries()).map(([e,t])=>[e,t]).sort((e,t)=>t[1]-e[1]);if(_.length===0)return[];if(d===1)return _;if(d===0){if(p===1)return _;for(let e of f)if(!h.get(e))return[];return _.filter(([e])=>{let t=m.get(e);return t?Array.from(t.values()).some(e=>e===p):!1})}let v=_.filter(([e])=>{let t=m.get(e);return t?Array.from(t.values()).some(e=>e===p):!1});if(v.length>0){let e=_.filter(([e])=>!v.some(([t])=>t===e)),t=Math.ceil(e.length*d);return[...v,...e.slice(0,t)]}return _}function xU(e,t,n,r){if(`and`in n&&n.and&&Array.isArray(n.and)){let i=n.and;return i.length===0?new Set:cH(...i.map(n=>xU(e,t,n,r)))}if(`or`in n&&n.or&&Array.isArray(n.or)){let i=n.or;return i.length===0?new Set:i.map(n=>xU(e,t,n,r)).reduce((e,t)=>uH(e,t),new Set)}if(`not`in n&&n.not){let i=n.not,a=new Set,o=e.sharedInternalDocumentStore;for(let e=1;e<=o.internalIdToId.length;e++)a.add(e);return dH(a,xU(e,t,i,r))}let i=Object.keys(n),a=i.reduce((e,t)=>({[t]:new Set,...e}),{});for(let o of i){let i=n[o];if(e.indexes[o]===void 0)throw mH(`UNKNOWN_FILTER_PROPERTY`,o);let{node:s,type:c,isArray:l}=e.indexes[o];if(c===`Bool`){let e=s,t=i?e.true:e.false;a[o]=uH(a[o],t);continue}if(c===`BKD`){let e;if(`radius`in i)e=`radius`;else if(`polygon`in i)e=`polygon`;else throw Error(`Invalid operation ${i}`);if(e===`radius`){let{value:t,coordinates:n,unit:r=`m`,inside:c=!0,highPrecision:l=!1}=i[e],u=iH(t,r),d=s.searchByRadius(n,u,c,void 0,l);a[o]=DU(a[o],d)}else{let{coordinates:t,inside:n=!0,highPrecision:r=!1}=i[e],c=s.searchByPolygon(t,n,void 0,r);a[o]=DU(a[o],c)}continue}if(c===`Radix`&&(typeof i==`string`||Array.isArray(i))){for(let e of[i].flat()){let n=t.tokenize(e,r,o);for(let e of n){let t=s.find({term:e,exact:!0});a[o]=jU(a[o],t)}}continue}let u=Object.keys(i);if(u.length>1)throw mH(`INVALID_FILTER_OPERATION`,u.length);if(c===`Flat`){let e=new Set(l?s.filterArr(i):s.filter(i));a[o]=uH(a[o],e);continue}if(c===`AVL`){let e=u[0],t=i[e],n;switch(e){case`gt`:n=s.greaterThan(t,!1);break;case`gte`:n=s.greaterThan(t,!0);break;case`lt`:n=s.lessThan(t,!1);break;case`lte`:n=s.lessThan(t,!0);break;case`eq`:n=s.find(t)??new Set;break;case`between`:{let[e,r]=t;n=s.rangeSearch(e,r);break}default:throw mH(`INVALID_FILTER_OPERATION`,e)}a[o]=uH(a[o],n)}}return cH(...Object.values(a))}function SU(e){return e.searchableProperties}function CU(e){return e.searchablePropertiesWithTypes}function wU(e,t){let{indexes:n,vectorIndexes:r,searchableProperties:i,searchablePropertiesWithTypes:a,frequencies:o,tokenOccurrences:s,avgFieldLength:c,fieldLengths:l}=t,u={},d={};for(let e of Object.keys(n)){let{node:t,type:r,isArray:i}=n[e];switch(r){case`Radix`:u[e]={type:`Radix`,node:tU.fromJSON(t),isArray:i};break;case`Flat`:u[e]={type:`Flat`,node:ZH.fromJSON(t),isArray:i};break;case`AVL`:u[e]={type:`AVL`,node:XH.fromJSON(t),isArray:i};break;case`BKD`:u[e]={type:`BKD`,node:rU.fromJSON(t),isArray:i};break;case`Bool`:u[e]={type:`Bool`,node:iU.fromJSON(t),isArray:i};break;default:u[e]=n[e]}}for(let e of Object.keys(r))d[e]={type:`Vector`,isArray:!1,node:oU.fromJSON(r[e])};return{sharedInternalDocumentStore:e,indexes:u,vectorIndexes:d,searchableProperties:i,searchablePropertiesWithTypes:a,frequencies:o,tokenOccurrences:s,avgFieldLength:c,fieldLengths:l}}function TU(e){let{indexes:t,vectorIndexes:n,searchableProperties:r,searchablePropertiesWithTypes:i,frequencies:a,tokenOccurrences:o,avgFieldLength:s,fieldLengths:c}=e,l={};for(let e of Object.keys(n))l[e]=n[e].node.toJSON();let u={};for(let e of Object.keys(t)){let{type:n,node:r,isArray:i}=t[e];n===`Flat`||n===`Radix`||n===`AVL`||n===`BKD`||n===`Bool`?u[e]={type:n,node:r.toJSON(),isArray:i}:(u[e]=t[e],u[e].node=u[e].node.toJSON())}return{indexes:u,vectorIndexes:l,searchableProperties:r,searchablePropertiesWithTypes:i,frequencies:a,tokenOccurrences:o,avgFieldLength:s,fieldLengths:c}}function EU(){return{create:pU,insert:hU,remove:vU,insertDocumentScoreParameters:lU,insertTokenScoreParameters:uU,removeDocumentScoreParameters:dU,removeTokenScoreParameters:fU,calculateResultScores:yU,search:bU,searchByWhereClause:xU,getSearchableProperties:SU,getSearchablePropertiesWithTypes:CU,load:wU,save:TU}}function DU(e,t){e||=new Set;let n=t.length;for(let r=0;r<n;r++){let n=t[r].docIDs,i=n.length;for(let t=0;t<i;t++)e.add(n[t])}return e}function OU(e,t,n=!1){let r=n?rU.vincentyDistance:rU.haversineDistance,i=[],a=[];for(let{point:n}of e)a.push(r(t,n));let o=Math.max(...a),s=0;for(let{docIDs:t}of e){let e=o-a[s]+1;for(let n of t)i.push([n,e]);s++}return i.sort((e,t)=>t[1]-e[1]),i}function kU(e,t){let n=Object.keys(e);if(n.length!==1)return{isGeoOnly:!1};let r=n[0],i=e[r];if(t.indexes[r]===void 0)return{isGeoOnly:!1};let{type:a}=t.indexes[r];return a===`BKD`&&i&&(`radius`in i||`polygon`in i)?{isGeoOnly:!0,geoProperty:r,geoOperation:i}:{isGeoOnly:!1}}function AU(e,t){let n=e,r=kU(t,n);if(!r.isGeoOnly||!r.geoProperty||!r.geoOperation)return null;let{node:i}=n.indexes[r.geoProperty],a=r.geoOperation,o=i,s;if(`radius`in a){let{value:e,coordinates:t,unit:n=`m`,inside:r=!0,highPrecision:i=!1}=a.radius,c=t,l=iH(e,n);return s=o.searchByRadius(c,l,r,`asc`,i),OU(s,c,i)}else if(`polygon`in a){let{coordinates:e,inside:t=!0,highPrecision:n=!1}=a.polygon;s=o.searchByPolygon(e,t,`asc`,n);let r=rU.calculatePolygonCentroid(e);return OU(s,r,n)}return null}function jU(e,t){e||=new Set;let n=Object.keys(t),r=n.length;for(let i=0;i<r;i++){let r=t[n[i]],a=r.length;for(let t=0;t<a;t++)e.add(r[t])}return e}function MU(e,t,n,r,i){let a={language:e.tokenizer.language,sharedInternalDocumentStore:t,enabled:!0,isSorted:!0,sortableProperties:[],sortablePropertiesWithTypes:{},sorts:{}};for(let[o,s]of Object.entries(n)){let n=`${i}${i?`.`:``}${o}`;if(!r.includes(n)){if(typeof s==`object`&&!Array.isArray(s)){let i=MU(e,t,s,r,n);WV(a.sortableProperties,i.sortableProperties),a.sorts={...a.sorts,...i.sorts},a.sortablePropertiesWithTypes={...a.sortablePropertiesWithTypes,...i.sortablePropertiesWithTypes};continue}if(!xH(s))switch(s){case`boolean`:case`number`:case`string`:a.sortableProperties.push(n),a.sortablePropertiesWithTypes[n]=s,a.sorts[n]={docs:new Map,orderedDocsToRemove:new Map,orderedDocs:[],type:s};break;case`geopoint`:case`enum`:continue;case`enum[]`:case`boolean[]`:case`number[]`:case`string[]`:continue;default:throw mH(`INVALID_SORT_SCHEMA_TYPE`,Array.isArray(s)?`array`:s,n)}}}return a}function NU(e,t,n,r){return r?.enabled===!1?{disabled:!0}:MU(e,t,n,(r||{}).unsortableProperties||[],``)}function PU(e,t,n,r){if(!e.enabled)return;e.isSorted=!1;let i=OH(e.sharedInternalDocumentStore,n),a=e.sorts[t];a.orderedDocsToRemove.has(i)&&VU(e,t),a.docs.set(i,a.orderedDocs.length),a.orderedDocs.push([i,r])}function FU(e){if(e.isSorted||!e.enabled)return;let t=Object.keys(e.sorts);for(let n of t)zU(e,n);e.isSorted=!0}function IU(e,t,n){return t[1].localeCompare(n[1],LV(e))}function LU(e,t){return e[1]-t[1]}function RU(e,t){return t[1]?-1:1}function zU(e,t){let n=e.sorts[t],r;switch(n.type){case`string`:r=IU.bind(null,e.language);break;case`number`:r=LU.bind(null);break;case`boolean`:r=RU.bind(null);break}n.orderedDocs.sort(r);let i=n.orderedDocs.length;for(let e=0;e<i;e++){let t=n.orderedDocs[e][0];n.docs.set(t,e)}}function BU(e){let t=Object.keys(e.sorts);for(let n of t)VU(e,n)}function VU(e,t){let n=e.sorts[t];n.orderedDocsToRemove.size&&(n.orderedDocs=n.orderedDocs.filter(e=>!n.orderedDocsToRemove.has(e[0])),n.orderedDocsToRemove.clear())}function HU(e,t,n){if(!e.enabled)return;let r=e.sorts[t],i=OH(e.sharedInternalDocumentStore,n);r.docs.get(i)&&(r.docs.delete(i),r.orderedDocsToRemove.set(i,!0))}function UU(e,t,n){if(!e.enabled)throw mH(`SORT_DISABLED`);let r=n.property,i=n.order===`DESC`,a=e.sorts[r];if(!a)throw mH(`UNABLE_TO_SORT_ON_UNKNOWN_FIELD`,r,e.sortableProperties.join(`, `));return VU(e,r),FU(e),t.sort((t,n)=>{let r=a.docs.get(OH(e.sharedInternalDocumentStore,t[0])),o=a.docs.get(OH(e.sharedInternalDocumentStore,n[0])),s=r!==void 0,c=o!==void 0;return!s&&!c?0:s?c?i?o-r:r-o:-1:1}),t}function WU(e){return e.enabled?e.sortableProperties:[]}function GU(e){return e.enabled?e.sortablePropertiesWithTypes:{}}function KU(e,t){let n=t;if(!n.enabled)return{enabled:!1};let r=Object.keys(n.sorts).reduce((e,t)=>{let{docs:r,orderedDocs:i,type:a}=n.sorts[t];return e[t]={docs:new Map(Object.entries(r).map(([e,t])=>[+e,t])),orderedDocsToRemove:new Map,orderedDocs:i,type:a},e},{});return{sharedInternalDocumentStore:e,language:n.language,sortableProperties:n.sortableProperties,sortablePropertiesWithTypes:n.sortablePropertiesWithTypes,sorts:r,enabled:!0,isSorted:n.isSorted}}function qU(e){if(!e.enabled)return{enabled:!1};BU(e),FU(e);let t=Object.keys(e.sorts).reduce((t,n)=>{let{docs:r,orderedDocs:i,type:a}=e.sorts[n];return t[n]={docs:Object.fromEntries(r.entries()),orderedDocs:i,type:a},t},{});return{language:e.language,sortableProperties:e.sortableProperties,sortablePropertiesWithTypes:e.sortablePropertiesWithTypes,sorts:t,enabled:e.enabled,isSorted:e.isSorted}}function JU(){return{create:NU,insert:PU,remove:HU,save:qU,load:KU,sortBy:UU,getSortableProperties:WU,getSortablePropertiesWithTypes:GU}}const YU=[65,65,65,65,65,65,65,67,69,69,69,69,73,73,73,73,69,78,79,79,79,79,79,null,79,85,85,85,85,89,80,115,97,97,97,97,97,97,97,99,101,101,101,101,105,105,105,105,101,110,111,111,111,111,111,null,111,117,117,117,117,121,112,121,65,97,65,97,65,97,67,99,67,99,67,99,67,99,68,100,68,100,69,101,69,101,69,101,69,101,69,101,71,103,71,103,71,103,71,103,72,104,72,104,73,105,73,105,73,105,73,105,73,105,73,105,74,106,75,107,107,76,108,76,108,76,108,76,108,76,108,78,110,78,110,78,110,110,78,110,79,111,79,111,79,111,79,111,82,114,82,114,82,114,83,115,83,115,83,115,83,115,84,116,84,116,84,116,85,117,85,117,85,117,85,117,85,117,85,117,87,119,89,121,89,90,122,90,122,90,122,115];function XU(e){return e<192||e>383?e:YU[e-192]||e}function ZU(e){let t=[];for(let n=0;n<e.length;n++)t[n]=XU(e.charCodeAt(n));return String.fromCharCode(...t)}const QU={ational:`ate`,tional:`tion`,enci:`ence`,anci:`ance`,izer:`ize`,bli:`ble`,alli:`al`,entli:`ent`,eli:`e`,ousli:`ous`,ization:`ize`,ation:`ate`,ator:`ate`,alism:`al`,iveness:`ive`,fulness:`ful`,ousness:`ous`,aliti:`al`,iviti:`ive`,biliti:`ble`,logi:`log`},$U={icate:`ic`,ative:``,alize:`al`,iciti:`ic`,ical:`ic`,ful:``,ness:``},eW=`[aeiouy]`,tW=`[^aeiou][^aeiouy]*`;eW+``;const nW=`^(`+tW+`)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*`;``+tW;const rW=`^(`+tW+`)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*[aeiouy][aeiou]*[^aeiou][^aeiouy]*`,iW=`^(`+tW+`)?[aeiouy]`;function aW(e){let t,n,r,i,a,o;if(e.length<3)return e;let s=e.substring(0,1);if(s==`y`&&(e=s.toUpperCase()+e.substring(1)),r=/^(.+?)(ss|i)es$/,i=/^(.+?)([^s])s$/,r.test(e)?e=e.replace(r,`$1$2`):i.test(e)&&(e=e.replace(i,`$1$2`)),r=/^(.+?)eed$/,i=/^(.+?)(ed|ing)$/,r.test(e)){let t=r.exec(e);r=new RegExp(nW),r.test(t[1])&&(r=/.$/,e=e.replace(r,``))}else i.test(e)&&(t=i.exec(e)[1],i=new RegExp(iW),i.test(t)&&(e=t,i=/(at|bl|iz)$/,a=RegExp(`([^aeiouylsz])\\1$`),o=RegExp(`^`+tW+eW+`[^aeiouwxy]$`),i.test(e)?e+=`e`:a.test(e)?(r=/.$/,e=e.replace(r,``)):o.test(e)&&(e+=`e`)));if(r=/^(.+?)y$/,r.test(e)&&(t=r.exec(e)?.[1],r=new RegExp(iW),t&&r.test(t)&&(e=t+`i`)),r=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,r.test(e)){let i=r.exec(e);t=i?.[1],n=i?.[2],r=new RegExp(nW),t&&r.test(t)&&(e=t+QU[n])}if(r=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,r.test(e)){let i=r.exec(e);t=i?.[1],n=i?.[2],r=new RegExp(nW),t&&r.test(t)&&(e=t+$U[n])}if(r=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,i=/^(.+?)(s|t)(ion)$/,r.test(e))t=r.exec(e)?.[1],r=new RegExp(rW),t&&r.test(t)&&(e=t);else if(i.test(e)){let n=i.exec(e);t=n?.[1]??``+n?.[2]??``,i=new RegExp(rW),i.test(t)&&(e=t)}return r=/^(.+?)e$/,r.test(e)&&(t=r.exec(e)?.[1],r=new RegExp(rW),i=RegExp(`^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*([aeiouy][aeiou]*)?$`),a=RegExp(`^`+tW+eW+`[^aeiouwxy]$`),t&&(r.test(t)||i.test(t)&&!a.test(t))&&(e=t)),r=/ll$/,i=new RegExp(rW),r.test(e)&&i.test(e)&&(r=/.$/,e=e.replace(r,``)),s==`y`&&(e=s.toLowerCase()+e.substring(1)),e}function oW(e,t,n=!0){let r=`${this.language}:${e}:${t}`;return n&&this.normalizationCache.has(r)?this.normalizationCache.get(r):this.stopWords?.includes(t)?(n&&this.normalizationCache.set(r,``),``):(this.stemmer&&!this.stemmerSkipProperties.has(e)&&(t=this.stemmer(t)),t=ZU(t),n&&this.normalizationCache.set(r,t),t)}function sW(e){for(;e[e.length-1]===``;)e.pop();for(;e[0]===``;)e.shift();return e}function cW(e,t,n,r=!0){if(t&&t!==this.language)throw mH(`LANGUAGE_NOT_SUPPORTED`,t);if(typeof e!=`string`)return[e];let i=this.normalizeToken.bind(this,n??``),a;if(n&&this.tokenizeSkipProperties.has(n))a=[i(e,r)];else{let t=FV[this.language];a=e.toLowerCase().split(t).map(e=>i(e,r)).filter(Boolean)}let o=sW(a);return this.allowDuplicates?o:Array.from(new Set(o))}function lW(e={}){if(!e.language)e.language=`english`;else if(!IV.includes(e.language))throw mH(`LANGUAGE_NOT_SUPPORTED`,e.language);let t;if(e.stemming||e.stemmer&&!(`stemming`in e))if(e.stemmer){if(typeof e.stemmer!=`function`)throw mH(`INVALID_STEMMER_FUNCTION_TYPE`);t=e.stemmer}else if(e.language===`english`)t=aW;else throw mH(`MISSING_STEMMER`,e.language);let n;if(e.stopWords!==!1){if(n=[],Array.isArray(e.stopWords))n=e.stopWords;else if(typeof e.stopWords==`function`)n=e.stopWords(n);else if(e.stopWords)throw mH(`CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY`);if(!Array.isArray(n))throw mH(`CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY`);for(let e of n)if(typeof e!=`string`)throw mH(`CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY`)}let r={tokenize:cW,language:e.language,stemmer:t,stemmerSkipProperties:new Set(e.stemmerSkipProperties?[e.stemmerSkipProperties].flat():[]),tokenizeSkipProperties:new Set(e.tokenizeSkipProperties?[e.tokenizeSkipProperties].flat():[]),stopWords:n,allowDuplicates:!!e.allowDuplicates,normalizeToken:oW,normalizationCache:new Map};return r.tokenize=cW.bind(r),r.normalizeToken=oW,r}function uW(e){return{sharedInternalDocumentStore:e,rules:new Map}}function dW(e,t){if(e.rules.has(t.id))throw Error(`PINNING_RULE_ALREADY_EXISTS: A pinning rule with id "${t.id}" already exists. Use updateRule to modify it.`);e.rules.set(t.id,t)}function fW(e,t){if(!e.rules.has(t.id))throw Error(`PINNING_RULE_NOT_FOUND: Cannot update pinning rule with id "${t.id}" because it does not exist. Use addRule to create it.`);e.rules.set(t.id,t)}function pW(e,t){return e.rules.delete(t)}function mW(e,t){return e.rules.get(t)}function hW(e){return Array.from(e.rules.values())}function gW(e,t){let n=e.toLowerCase().trim(),r=t.pattern.toLowerCase().trim();switch(t.anchoring){case`is`:return n===r;case`starts_with`:return n.startsWith(r);case`contains`:return n.includes(r);default:return!1}}function _W(e,t){return e?t.conditions.every(t=>gW(e,t)):!1}function vW(e,t){if(!t)return[];let n=[];for(let r of e.rules.values())_W(t,r)&&n.push(r);return n}function yW(e,t){return{sharedInternalDocumentStore:e,rules:new Map(t?.rules??[])}}function bW(e){return{rules:Array.from(e.rules.entries())}}function xW(){return{create:uW,addRule:dW,updateRule:fW,removeRule:pW,getRule:mW,getAllRules:hW,getMatchingRules:vW,load:yW,save:bW}}function SW(e){let t={formatElapsedTime:hH,getDocumentIndexId:gH,getDocumentProperties:tH,validateSchema:_H};for(let n of UH){let r=n;if(e[r]){if(typeof e[r]!=`function`)throw mH(`COMPONENT_MUST_BE_FUNCTION`,r)}else e[r]=t[r]}for(let t of Object.keys(e))if(!HH.includes(t)&&!UH.includes(t))throw mH(`UNSUPPORTED_COMPONENT`,t)}function CW({schema:e,sort:t,language:n,components:r,id:i,plugins:a}){r||={};for(let t of a??[]){if(!(`getComponents`in t)||typeof t.getComponents!=`function`)continue;let n=t.getComponents(e),i=Object.keys(n);for(let e of i)if(r[e])throw mH(`PLUGIN_COMPONENT_CONFLICT`,e,t.name);r={...r,...n}}i||=ZV();let o=r.tokenizer,s=r.index,c=r.documentsStore,l=r.sorter,u=r.pinning;if(o=o?o.tokenize?o:lW(o):lW({language:n??`english`}),r.tokenizer&&n)throw mH(`NO_LANGUAGE_WITH_CUSTOM_TOKENIZER`);let d=TH();s||=EU(),l||=JU(),c||=zH(),u||=xW(),SW(r);let{getDocumentProperties:f,getDocumentIndexId:p,validateSchema:m,formatElapsedTime:h}=r,g={data:{},caches:{},schema:e,tokenizer:o,index:s,sorter:l,documentsStore:c,pinning:u,internalDocumentIDStore:d,getDocumentProperties:f,getDocumentIndexId:p,validateSchema:m,beforeInsert:[],afterInsert:[],beforeRemove:[],afterRemove:[],beforeUpdate:[],afterUpdate:[],beforeUpsert:[],afterUpsert:[],beforeSearch:[],afterSearch:[],beforeInsertMultiple:[],afterInsertMultiple:[],beforeRemoveMultiple:[],afterRemoveMultiple:[],beforeUpdateMultiple:[],afterUpdateMultiple:[],beforeUpsertMultiple:[],afterUpsertMultiple:[],afterCreate:[],formatElapsedTime:h,id:i,plugins:a,version:wW()};g.data={index:g.index.create(g,d,e),docs:g.documentsStore.create(g,d),sorting:g.sorter.create(g,d,e,t),pinning:g.pinning.create(d)};for(let e of BH)g[e]=(g[e]??[]).concat(VH(g,e));let _=g.afterCreate;return _&&JH(_,g),g}function wW(){return`{{VERSION}}`}function TW(e){return e.documentsStore.count(e.data.docs)}function EW(e,t,n,r,i){let a=e.validateSchema(t,e.schema);if(a)throw mH(`SCHEMA_VALIDATION_FAILURE`,a);return oH(e.beforeInsert)||oH(e.afterInsert)||oH(e.index.beforeInsert)||oH(e.index.insert)||oH(e.index.afterInsert)?kW(e,t,n,r,i):AW(e,t,n,r,i)}const DW=new Set([`enum`,`enum[]`]),OW=new Set([`string`,`number`]);async function kW(e,t,n,r,i){let{index:a,docs:o}=e.data,s=e.getDocumentIndexId(t);if(typeof s!=`string`)throw mH(`DOCUMENT_ID_MUST_BE_STRING`,typeof s);let c=OH(e.internalDocumentIDStore,s);if(r||await WH(e.beforeInsert,e,s,t),!e.documentsStore.store(o,s,c,t))throw mH(`DOCUMENT_ALREADY_EXISTS`,s);let l=e.documentsStore.count(o),u=e.index.getSearchableProperties(a),d=e.index.getSearchablePropertiesWithTypes(a),f=e.getDocumentProperties(t,u);for(let[e,t]of Object.entries(f)){if(t===void 0)continue;let n=typeof t,r=d[e];jW(n,r,e,t)}return await MW(e,s,u,f,l,n,t,i),r||await WH(e.afterInsert,e,s,t),s}function AW(e,t,n,r,i){let{index:a,docs:o}=e.data,s=e.getDocumentIndexId(t);if(typeof s!=`string`)throw mH(`DOCUMENT_ID_MUST_BE_STRING`,typeof s);let c=OH(e.internalDocumentIDStore,s);if(r||WH(e.beforeInsert,e,s,t),!e.documentsStore.store(o,s,c,t))throw mH(`DOCUMENT_ALREADY_EXISTS`,s);let l=e.documentsStore.count(o),u=e.index.getSearchableProperties(a),d=e.index.getSearchablePropertiesWithTypes(a),f=e.getDocumentProperties(t,u);for(let[e,t]of Object.entries(f)){if(t===void 0)continue;let n=typeof t,r=d[e];jW(n,r,e,t)}return NW(e,s,u,f,l,n,t,i),r||WH(e.afterInsert,e,s,t),s}function jW(e,t,n,r){if(!(bH(t)&&typeof r==`object`&&typeof r.lon==`number`&&typeof r.lat==`number`)&&!(xH(t)&&Array.isArray(r))&&!(SH(t)&&Array.isArray(r))&&!(DW.has(t)&&OW.has(e))&&e!==t)throw mH(`INVALID_DOCUMENT_PROPERTY`,n,t,e)}async function MW(e,t,n,r,i,a,o,s){for(let o of n){let n=r[o];if(n===void 0)continue;let c=e.index.getSearchablePropertiesWithTypes(e.data.index)[o];await e.index.beforeInsert?.(e.data.index,o,t,n,c,a,e.tokenizer,i);let l=e.internalDocumentIDStore.idToInternalId.get(t);await e.index.insert(e.index,e.data.index,o,t,l,n,c,a,e.tokenizer,i,s),await e.index.afterInsert?.(e.data.index,o,t,n,c,a,e.tokenizer,i)}let c=e.sorter.getSortableProperties(e.data.sorting),l=e.getDocumentProperties(o,c);for(let n of c){let r=l[n];if(r===void 0)continue;let i=e.sorter.getSortablePropertiesWithTypes(e.data.sorting)[n];e.sorter.insert(e.data.sorting,n,t,r,i,a)}}function NW(e,t,n,r,i,a,o,s){for(let o of n){let n=r[o];if(n===void 0)continue;let c=e.index.getSearchablePropertiesWithTypes(e.data.index)[o],l=OH(e.internalDocumentIDStore,t);e.index.beforeInsert?.(e.data.index,o,t,n,c,a,e.tokenizer,i),e.index.insert(e.index,e.data.index,o,t,l,n,c,a,e.tokenizer,i,s),e.index.afterInsert?.(e.data.index,o,t,n,c,a,e.tokenizer,i)}let c=e.sorter.getSortableProperties(e.data.sorting),l=e.getDocumentProperties(o,c);for(let n of c){let r=l[n];if(r===void 0)continue;let i=e.sorter.getSortablePropertiesWithTypes(e.data.sorting)[n];e.sorter.insert(e.data.sorting,n,t,r,i,a)}}function PW(e,t,n,r,i,a){return oH(e.afterInsertMultiple)||oH(e.beforeInsertMultiple)||oH(e.index.beforeInsert)||oH(e.index.insert)||oH(e.index.afterInsert)?FW(e,t,n,r,i,a):IW(e,t,n,r,i,a)}async function FW(e,t,n=1e3,r,i,a=0){let o=[],s=async a=>{let s=Math.min(a+n,t.length),c=t.slice(a,s);for(let t of c){let n=await EW(e,t,r,i,{avlRebalanceThreshold:c.length});o.push(n)}return s};return await(async()=>{let e=0;for(;e<t.length;){let t=Date.now();if(e=await s(e),a>0){let e=a-(Date.now()-t);e>0&&fH(e)}}})(),i||await GH(e.afterInsertMultiple,e,t),o}function IW(e,t,n=1e3,r,i,a=0){let o=[],s=0;function c(){let a=t.slice(s*n,(s+1)*n);if(a.length===0)return!1;for(let t of a){let n=EW(e,t,r,i,{avlRebalanceThreshold:a.length});o.push(n)}return s++,!0}function l(){let e=Date.now();for(;c();)if(a>0){let t=Date.now()-e;if(t>=a){let e=a-t%a;e>0&&fH(e)}}}return l(),i||GH(e.afterInsertMultiple,e,t),o}function LW(e,t){return e[1]-t[1]}function RW(e,t){return t[1]-e[1]}function zW(e=`desc`){return e.toLowerCase()===`asc`?LW:RW}function BW(e,t,n){let r={},i=t.map(([e])=>e),a=e.documentsStore.getMultiple(e.data.docs,i),o=Object.keys(n),s=e.index.getSearchablePropertiesWithTypes(e.data.index);for(let e of o){let t;if(s[e]===`number`){let{ranges:r}=n[e],i=r.length,a=Array.from({length:i});for(let e=0;e<i;e++){let t=r[e];a[e]=[`${t.from}-${t.to}`,0]}t=Object.fromEntries(a)}r[e]={count:0,values:t??{}}}let c=a.length;for(let e=0;e<c;e++){let t=a[e];for(let e of o){let i=e.includes(`.`)?nH(t,e):t[e],a=s[e],o=r[e].values;switch(a){case`number`:{let t=n[e].ranges;VW(t,o)(i);break}case`number[]`:{let t=new Set,r=n[e].ranges,a=VW(r,o,t);for(let e of i)a(e);break}case`boolean`:case`enum`:case`string`:HW(o,a)(i);break;case`boolean[]`:case`enum[]`:case`string[]`:{let e=HW(o,a===`boolean[]`?`boolean`:`string`,new Set);for(let t of i)e(t);break}default:throw mH(`FACET_NOT_SUPPORTED`,a)}}}for(let e of o){let t=r[e];if(t.count=Object.keys(t.values).length,s[e]===`string`){let r=n[e],i=zW(r.sort);t.values=Object.fromEntries(Object.entries(t.values).sort(i).slice(r.offset??0,r.limit??10))}}return r}function VW(e,t,n){return r=>{for(let i of e){let e=`${i.from}-${i.to}`;n?.has(e)||r>=i.from&&r<=i.to&&(t[e]===void 0?t[e]=1:(t[e]++,n?.add(e)))}}}function HW(e,t,n){let r=t===`boolean`?`false`:``;return t=>{let i=t?.toString()??r;n?.has(i)||(e[i]=(e[i]??0)+1,n?.add(i))}}const UW={reducer:(e,t,n,r)=>(t[r]=n,t),getInitialValue:e=>Array.from({length:e})},WW=[`string`,`number`,`boolean`];function GW(e,t,n){let r=n.properties,i=r.length,a=e.index.getSearchablePropertiesWithTypes(e.data.index);for(let e=0;e<i;e++){let t=r[e];if(a[t]===void 0)throw mH(`UNKNOWN_GROUP_BY_PROPERTY`,t);if(!WW.includes(a[t]))throw mH(`INVALID_GROUP_BY_PROPERTY`,t,WW.join(`, `),a[t])}let o=t.map(([t])=>kH(e.internalDocumentIDStore,t)),s=e.documentsStore.getMultiple(e.data.docs,o),c=s.length,l=n.maxResult||2**53-1,u=[],d={};for(let e=0;e<i;e++){let t=r[e],n={property:t,perValue:{}},i=new Set;for(let e=0;e<c;e++){let r=s[e],a=nH(r,t);if(a===void 0)continue;let o=typeof a==`boolean`?``+a:a,c=n.perValue[o]??{indexes:[],count:0};c.count>=l||(c.indexes.push(e),c.count++,n.perValue[o]=c,i.add(a))}u.push(Array.from(i)),d[t]=n}let f=KW(u),p=f.length,m=[];for(let e=0;e<p;e++){let t=f[e],n=t.length,i={values:[],indexes:[]},a=[];for(let e=0;e<n;e++){let n=t[e],o=r[e];a.push(d[o].perValue[typeof n==`boolean`?``+n:n].indexes),i.values.push(n)}i.indexes=eH(a).sort((e,t)=>e-t),i.indexes.length!==0&&m.push(i)}let h=m.length,g=Array.from({length:h});for(let e=0;e<h;e++){let r=m[e],i=n.reduce||UW,a=r.indexes.map(e=>({id:o[e],score:t[e][1],document:s[e]})),c=i.reducer.bind(null,r.values),l=i.getInitialValue(r.indexes.length),u=a.reduce(c,l);g[e]={values:r.values,result:u}}return g}function KW(e,t=0){if(t+1===e.length)return e[t].map(e=>[e]);let n=e[t],r=KW(e,t+1),i=[];for(let e of n)for(let t of r){let n=[e];WV(n,t),i.push(n)}return i}function qW(e,t,n,r){let i=vW(t,r);if(i.length===0)return n;let a=i.flatMap(e=>e.consequence.promote);a.sort((e,t)=>e.position-t.position);let o=new Set,s=new Map,c=new Set;for(let t of a){let n=OH(e.internalDocumentIDStore,t.doc_id);if(n!==void 0){if(s.has(n)){let e=s.get(n);t.position<e&&s.set(n,t.position);continue}c.has(t.position)||(o.add(n),s.set(n,t.position),c.add(t.position))}}if(s.size===0)return n;let l=n.filter(([e])=>!o.has(e)),u=[];for(let[t,r]of s.entries())n.find(([e])=>e===t)?u.push([t,1e6-r]):e.documentsStore.get(e.data.docs,t)&&u.push([t,0]);u.sort((e,t)=>(s.get(e[0])??1/0)-(s.get(t[0])??1/0));let d=[],f=new Map;for(let e of u){let t=s.get(e[0]);f.set(t,e)}let p=0,m=0;for(;m<l.length+u.length;)if(f.has(m))d.push(f.get(m)),m++;else if(p<l.length)d.push(l[p]),p++,m++;else break;for(let[e,t]of f.entries())e>=d.length&&d.push(t);return d}function JW(e,t,n){let{term:r,properties:i}=t,a=e.data.index,o=e.caches.propertiesToSearch;if(!o){let t=e.index.getSearchablePropertiesWithTypes(a);o=e.index.getSearchableProperties(a),o=o.filter(e=>t[e].startsWith(`string`)),e.caches.propertiesToSearch=o}if(i&&i!==`*`){for(let e of i)if(!o.includes(e))throw mH(`UNKNOWN_INDEX`,e,o.join(`, `));o=o.filter(e=>i.includes(e))}let s=Object.keys(t.where??{}).length>0,c;s&&(c=e.index.searchByWhereClause(a,e.tokenizer,t.where,n));let l,u=t.threshold!==void 0&&t.threshold!==null?t.threshold:1;if(r||i){let i=TW(e);if(l=e.index.search(a,r||``,e.tokenizer,n,o,t.exact||!1,t.tolerance||0,t.boost||{},$W(t.relevance),i,c,u),t.exact&&r){let t=r.trim().split(/\s+/);l=l.filter(([n])=>{let r=e.documentsStore.get(e.data.docs,n);if(!r)return!1;for(let e of o){let n=XW(r,e);if(typeof n==`string`&&t.every(e=>RegExp(`\\b${YW(e)}\\b`).test(n)))return!0}return!1})}}else l=s?AU(a,t.where)||(c?Array.from(c):[]).map(e=>[+e,0]):Object.keys(e.documentsStore.getAll(e.data.docs)).map(e=>[+e,0]);return l}function YW(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function XW(e,t){let n=t.split(`.`),r=e;for(let e of n)if(r&&typeof r==`object`&&e in r)r=r[e];else return;return r}function ZW(e,t,n){let r=XV();function i(){let i=Object.keys(e.data.index.vectorIndexes),a=t.facets&&Object.keys(t.facets).length>0,{limit:o=10,offset:s=0,distinctOn:c,includeVectors:l=!1}=t,u=t.preflight===!0,d=JW(e,t,n);if(t.sortBy)if(typeof t.sortBy==`function`){let n=d.map(([e])=>e),r=e.documentsStore.getMultiple(e.data.docs,n).map((e,t)=>[d[t][0],d[t][1],e]);r.sort(t.sortBy),d=r.map(([e,t])=>[e,t])}else d=e.sorter.sortBy(e.data.sorting,d,t.sortBy).map(([t,n])=>[OH(e.internalDocumentIDStore,t),n]);else d=d.sort($V);d=qW(e,e.data.pinning,d,t.term);let f;u||(f=c?dG(e,d,s,o,c):fG(e,d,s,o));let p={elapsed:{formatted:``,raw:0},hits:[],count:d.length};return f!==void 0&&(p.hits=f.filter(Boolean),l||aH(p,i)),a&&(p.facets=BW(e,d,t.facets)),t.groupBy&&(p.groups=GW(e,d,t.groupBy)),p.elapsed=e.formatElapsedTime(XV()-r),p}async function a(){e.beforeSearch&&await qH(e.beforeSearch,e,t,n);let r=i();return e.afterSearch&&await KH(e.afterSearch,e,t,n,r),r}return e.beforeSearch?.length||e.afterSearch?.length?a():i()}const QW={k:1.2,b:.75,d:.5};function $W(e){let t=e??{};return t.k=t.k??QW.k,t.b=t.b??QW.b,t.d=t.d??QW.d,t}function eG(e,t,n){let r=t.vector;if(r&&(!(`value`in r)||!(`property`in r)))throw mH(`INVALID_VECTOR_INPUT`,Object.keys(r).join(`, `));let i=e.data.index.vectorIndexes[r.property];if(!i)throw mH(`UNKNOWN_VECTOR_PROPERTY`,r.property);let a=i.node.size;if(r?.value.length!==a)throw r?.property===void 0||r?.value.length===void 0?mH(`INVALID_INPUT_VECTOR`,`undefined`,a,`undefined`):mH(`INVALID_INPUT_VECTOR`,r.property,a,r.value.length);let o=e.data.index,s;return Object.keys(t.where??{}).length>0&&(s=e.index.searchByWhereClause(o,e.tokenizer,t.where,n)),i.node.find(r.value,t.similarity??.8,s)}function tG(e,t,n=`english`){let r=XV();function i(){let i=eG(e,t,n).sort($V);i=qW(e,e.data.pinning,i,void 0);let a=[];t.facets&&Object.keys(t.facets).length>0&&(a=BW(e,i,t.facets));let o=t.vector.property,s=t.includeVectors??!1,c=t.limit??10,l=t.offset??0,u=Array.from({length:c});for(let t=0;t<c;t++){let n=i[t+l];if(!n)break;let r=e.data.docs.docs[n[0]];r&&(s||(r[o]=null),u[t]={id:kH(e.internalDocumentIDStore,n[0]),score:n[1],document:r})}let d=[];t.groupBy&&(d=GW(e,i,t.groupBy));let f=XV()-r;return{count:i.length,hits:u.filter(Boolean),elapsed:{raw:Number(f),formatted:YV(f)},...a?{facets:a}:{},...d?{groups:d}:{}}}async function a(){e.beforeSearch&&await qH(e.beforeSearch,e,t,n);let r=i();return e.afterSearch&&await KH(e.afterSearch,e,t,n,r),r}return e.beforeSearch?.length||e.afterSearch?.length?a():i()}function nG(e,t,n){let r=aG(JW(e,t,n)),i=eG(e,t,n),a=t.hybridWeights;return cG(r,i,t.term??``,a)}function rG(e,t,n){let r=XV();function i(){let i=nG(e,t,n);i=qW(e,e.data.pinning,i,t.term);let a;t.facets&&Object.keys(t.facets).length>0&&(a=BW(e,i,t.facets));let o;t.groupBy&&(o=GW(e,i,t.groupBy));let s=t.offset??0,c=t.limit??10,l=fG(e,i,s,c).filter(Boolean),u=XV(),d={count:i.length,elapsed:{raw:Number(u-r),formatted:YV(u-r)},hits:l,...a?{facets:a}:{},...o?{groups:o}:{}};return(t.includeVectors??!1)||aH(d,Object.keys(e.data.index.vectorIndexes)),d}async function a(){e.beforeSearch&&await qH(e.beforeSearch,e,t,n);let r=i();return e.afterSearch&&await KH(e.afterSearch,e,t,n,r),r}return e.beforeSearch?.length||e.afterSearch?.length?a():i()}function iG(e){return e[1]}function aG(e){let t=Math.max.apply(Math,e.map(iG));return e.map(([e,n])=>[e,n/t])}function oG(e,t){return e/t}function sG(e,t){return(n,r)=>n*e+r*t}function cG(e,t,n,r){let i=Math.max.apply(Math,e.map(iG)),a=Math.max.apply(Math,t.map(iG)),{text:o,vector:s}=r&&r.text&&r.vector?r:lG(n),c=new Map,l=e.length,u=sG(o,s);for(let t=0;t<l;t++){let[n,r]=e[t],a=u(oG(r,i),0);c.set(n,a)}let d=t.length;for(let e=0;e<d;e++){let[n,r]=t[e],i=oG(r,a),o=c.get(n)??0;c.set(n,o+u(0,i))}return[...c].sort((e,t)=>t[1]-e[1])}function lG(e){return{text:.5,vector:.5}}function uG(e,t,n){let r=t.mode??`fulltext`;if(r===`fulltext`)return ZW(e,t,n);if(r===`vector`)return tG(e,t);if(r===`hybrid`)return rG(e,t);throw mH(`INVALID_SEARCH_MODE`,r)}function dG(e,t,n,r,i){let a=e.data.docs,o=new Map,s=[],c=new Set,l=t.length,u=0;for(let d=0;d<l;d++){let l=t[d];if(l===void 0)continue;let[f,p]=l;if(c.has(f))continue;let m=e.documentsStore.get(a,f),h=nH(m,i);if(!(h===void 0||o.has(h))&&(o.set(h,!0),u++,!(u<=n)&&(s.push({id:kH(e.internalDocumentIDStore,f),score:p,document:m}),c.add(f),u>=n+r)))break}return s}function fG(e,t,n,r){let i=e.data.docs,a=Array.from({length:r}),o=new Set;for(let s=n;s<r+n;s++){let n=t[s];if(n===void 0)break;let[r,c]=n;if(!o.has(r)){let t=e.documentsStore.get(i,r);a[s]={id:kH(e.internalDocumentIDStore,r),score:c,document:t},o.add(r)}}return a}var pG=n(kV(),1);const mG=1,hG={protocol:`x-ok-client-protocol`,runtime:`x-ok-client-runtime`,kind:`x-ok-client-kind`};function gG({kind:e,runtimeVersion:t}){return{[hG.protocol]:`1`,[hG.runtime]:t,[hG.kind]:e}}const _G=`__system__`,vG=1,yG=`__config__/project`,bG=`__user__/config.yml`,xG=`__local__/project`,SG=`__config__/okignore`,CG=Object.freeze([yG,xG,bG,SG]),wG=`__skill__/`,TG=`__template__/`,EG=[`project`,`global`];function DG(e){return e.startsWith(`__skill__/`)||e.startsWith(`__template__/`)}const OG=`.ok/skills`;function kG(e){return`${OG}/${e}/SKILL`}const AG=[`references`,`scripts`];function jG(e,t){let n=/^(\.ok\/skills\/[^/]+)\/SKILL$/.exec(t);if(!n)return null;let r=n[1],i=e.trim().replace(/\.mdx?$/i,``).split(`/`).filter(e=>e!==``&&e!==`.`),[a]=i;return!a||!AG.includes(a)||i.includes(`..`)||i.length<2?null:`${r}/${i.join(`/`)}`}const MG=/^\.ok\/skills\/([^/]+)\/(SKILL|references\/.+)$/;function NG(e){let t=MG.exec(e);if(!t)return null;let n=t[1],r=t[2];return r===`SKILL`?{name:n,kind:`skill`,rel:null}:{name:n,kind:`reference`,rel:r.slice(11)}}const PG=/^__skill__\/global\/([^/]+)(?:\/(references\/.+))?$/;function FG(e){let t=PG.exec(e);if(!t)return null;let n=t[1],r=t[2];return r===void 0?{name:n,kind:`skill`,rel:null}:{name:n,kind:`reference`,rel:r.slice(11)}}function IG(e,t){return e===`project`?kG(t):`${wG}${e}/${t}`}function LG(e){if(e===``)return``;try{return e.split(`/`).map(e=>decodeURIComponent(e)).join(`/`)}catch{return e}}function RG(e){if(e.startsWith(`__skill__/`)){let t=e.slice(10),n=t.indexOf(`/`);if(n<0)return null;let r=t.slice(0,n);if(r!==`global`&&r!==`project`)return null;let i=t.slice(n+1);return i?{kind:`skill`,scope:r,name:LG(i)}:null}if(e.startsWith(`__template__/`)){let t=e.slice(13);if(!t)return null;let n=t.lastIndexOf(`/`),r=n<0?t:t.slice(n+1);return r?{kind:`template`,folder:LG(n<0?``:t.slice(0,n)),name:LG(r)}:null}return null}const zG=/^(?:(.+)\/)?\.ok\/templates\/([^/]+?)(?:\.mdx?)?$/;function BG(e){let t=zG.exec(e);if(t){let e=(t[1]??``).replace(/^\/+|\/+$/g,``);return`${TG}${e?`${e}/`:``}${t[2]}`}return null}const VG=[`.mdx`,`.md`],HG=`epoch`,UG=512*1024,WG=[`claude`,`claude-desktop`,`cursor`,`codex`,`copilot`,`opencode`,`openclaw`,`pi`,`antigravity`,`lm-studio`,`hermes`],GG={claude:`Claude`,"claude-desktop":`Claude Desktop`,cursor:`Cursor`,codex:`Codex`,copilot:`GitHub Copilot`,opencode:`OpenCode`,openclaw:`OpenClaw`,pi:`Pi`,antigravity:`Antigravity`,"lm-studio":`LM Studio`,hermes:`Hermes`},KG={claude:`.claude/skills`,"claude-desktop":null,cursor:`.cursor/skills`,codex:`.codex/skills`,copilot:`.github/skills`,opencode:`.opencode/skills`,openclaw:null,pi:`.pi/skills`,antigravity:null,"lm-studio":null,hermes:null},qG=WG.filter(e=>KG[e]!==null),JG=qG.filter(e=>e!==`pi`&&e!==`copilot`).map(e=>({hostDir:(KG[e]??``).split(`/`)[0],editorId:e})),YG={claude:`.mcp.json`,"claude-desktop":null,cursor:`.cursor/mcp.json`,codex:`.codex/config.toml`,copilot:null,opencode:`opencode.json`,openclaw:null,pi:`.pi/extensions/open-knowledge.ts`,antigravity:null,"lm-studio":null,hermes:null},XG={cursor:/\bCursor(?:\([^)]+\))?\/\d/,codex:/\bCodex(?:\([^)]+\))?\/\d/,"claude-desktop":/\bClaude(?:\([^)]+\))?\/\d/},ZG=`Ov23liqlSd0V1MwR6rhI`,QG=new Set([`gitlab.com`,`bitbucket.org`,`codeberg.org`,`gitea.com`,`sr.ht`,`sourcehut.org`]),$G=[`incoming`,`outgoing`,`both`];function eK(e){return $G.includes(e)}const tK=`open-knowledge`,nK=[{id:`chart`,title:`Chart`,description:`A bar chart whose series colors track the OK chart palette.`,html:`<div style="font-family:system-ui,sans-serif;padding:20px;color:var(--foreground)">
305
305
  <h3 style="margin:0 0 14px;font-size:15px;font-weight:600">Revenue by region</h3>
306
306
  <div id="bars" style="display:flex;align-items:flex-end;gap:14px;height:170px"></div>
307
307
  <script>
@@ -457,4 +457,4 @@ $2`).split(`
457
457
  `);if(!(t[0]??``).startsWith(`template:`))return null;let n=[t[0]??``],r=1;for(;r<t.length;){let e=t[r]??``;if(/^[ \t]/.test(e)){n.push(e),r++;continue}if(e.trim()===``){let i=r+1;for(;i<t.length&&(t[i]??``).trim()===``;)i++;if(i<t.length&&/^[ \t]/.test(t[i]??``)){n.push(e),r++;continue}}break}let i=n8(n.join(`
458
458
  `))[t8];return{identity:typeof i==`object`&&i&&!Array.isArray(i)?i:{},docFrontmatterText:t.slice(r).join(`
459
459
  `).replace(/\n+$/,``)}}function o8(e){let t=e.charCodeAt(0)===65279?e.slice(1):e,{frontmatter:n,body:r}=pK(t);if(n===``)return{identity:{},starterContent:t};let i=hK(n),a=a8(i);if(a)return{identity:a.identity,starterContent:r8(a.docFrontmatterText,r)};let{frontmatter:o}=pK(r);if(o!==``)return{identity:n8(i),starterContent:r};let s=n8(i);return typeof s.title==`string`?{identity:s,starterContent:r}:{identity:{},starterContent:r8(i,r)}}function s8(e,t){let{docFrontmatterText:n,markdown:r}=i8(t),i={};for(let[t,n]of Object.entries(e))n!==void 0&&(i[t]=n);let a=(0,Fc.stringify)({[t8]:i});return`---\n${n.trim()===``?a:`${a}${n}\n`}---\n${r}`}function c8(e){return o8(e).starterContent}function l8(){let e=!1,t=``,n=0;return r=>{let i=u8(r);return e?(i&&i.char===t&&i.len>=n&&!i.hasInfo&&(e=!1,t=``,n=0),!0):i?(e=!0,t=i.char,n=i.len,!0):!1}}function u8(e){let t=(e.endsWith(`\r`)?e.slice(0,-1):e).match(/^ {0,3}([`~])(\1{2,})(.*)$/);return t?{char:t[1],len:1+t[2].length,hasInfo:t[3].trim()!==``}:null}const d8=[`#D97757`,`#1B1912`,`#F9F3E9`,`#7A9DFF`,`#8534F3`,`#9663F0`,`#727CF3`],f8={claude:`#D97757`,cursor:`#1B1912`,windsurf:`#0B100F`,openai:`#7A9DFF`,github:`#8534F3`,cline:`#9663F0`,bot:`#727CF3`};function p8(e,t=d8){let n=0;for(let t of e)n=(n<<5)-n+t.charCodeAt(0)|0;return t[Math.abs(n)%t.length]}const m8={"claude-code":`claude`,"claude-ai":`claude`,cursor:`cursor`,"cursor-vscode":`cursor`,cascade:`windsurf`,codex:`openai`,"codex-mcp-client":`openai`,copilot:`github`,cline:`cline`};function h8(e){return e?m8[e]||(e.startsWith(`local-agent-mode-`)?`claude`:`bot`):`bot`}const g8={claude:`Claude`,cursor:`Cursor`,windsurf:`Windsurf`,openai:`Codex`,github:`Copilot`,cline:`Cline`};function _8(e){let t=e?.trim();return t?g8[h8(t)]??t:`Agent`}function v8(e,t){let n=e.trim();if(!n||/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(n)||n.startsWith(`//`)||n.startsWith(`#`))return null;let r=n.indexOf(`#`),i=r>=0?n.slice(0,r):n,a=r>=0?n.slice(r+1):null,o=(i.split(`?`)[0]??``).trim();if(!o)return null;let s=(o.split(`/`).pop()??``).match(/\.([a-z0-9]+)$/i);if(s){let e=(s[1]??``).toLowerCase();if(e!==`md`&&e!==`mdx`)return null}let c=o.toLowerCase(),l=c.endsWith(`.mdx`)?o.slice(0,-4):c.endsWith(`.md`)?o.slice(0,-3):o,u=l.startsWith(`/`),d=u?l.slice(1):l,f=u?[]:t.includes(`/`)?t.split(`/`).slice(0,-1):[];for(let e of d.split(`/`))if(e===`..`){if(f.length===0)return null;f.pop()}else e!==`.`&&e!==``&&f.push(e);return f.length===0?null:{docName:f.join(`/`),anchor:a||null}}const y8=/^[a-zA-Z][a-zA-Z\d+\-.]*:/;function b8(e){let t=(e.split(/[?#]/)[0]??e).match(/\.([a-z0-9]+)$/i);return t?(t[1]??``).toLowerCase():null}function x8(e){let t=e.trim();return y8.test(t)||t.startsWith(`//`)}function S8(e,t){let n=e.trim();if(!n)return null;if(n.startsWith(`#`)){let e=n.slice(1).trim();return e?{kind:`anchor`,anchor:e}:null}if(x8(n))return{kind:`external`,url:n};let r=v8(n,t);if(r)return{kind:`doc`,docName:r.docName,anchor:r.anchor};let i=b8(n);return i&&i!==`md`&&i!==`mdx`?{kind:`asset`,url:n,ext:i}:null}function C8(e,t){let n=e.trim();if(!n)return null;if(x8(n))return{kind:`external`,url:t?`${n}#${t}`:n};let r=b8(n);return r&&r!==`md`&&r!==`mdx`?{kind:`asset`,url:n,ext:r}:{kind:`doc`,docName:n,anchor:t?.trim()||null}}function w8(e,t){let n=e.trim();if(!n||y8.test(n)||n.startsWith(`//`)||n.startsWith(`#`))return null;let r=n.indexOf(`#`),i=((r>=0?n.slice(0,r):n).split(`?`)[0]??``).trim();if(!i)return null;let a=i.startsWith(`/`),o=a?i.slice(1):i,s=a?[]:t.includes(`/`)?t.split(`/`).slice(0,-1):[];for(let e of o.split(`/`))if(e===`..`){if(s.length===0)return null;s.pop()}else e!==`.`&&e!==``&&s.push(e);return s.length===0?null:s.join(`/`)}function T8(e){let t=e;return t.startsWith(`./`)&&(t=t.slice(2)),t.startsWith(`/`)&&(t=t.slice(1)),t}function E8(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}function D8(e){let t=e.lastIndexOf(`/`);return t===-1?``:e.slice(0,t)}function O8(e){return e.split(`/`).filter(e=>e!==``)}function k8(e,t){let n=D8(t);return e===``||n===e?!0:n.startsWith(`${e}/`)}function A8(e,t){let n=D8(t);if(e===n)return 0;let r=e===``?n:n.slice(e.length+1);return r===``?0:O8(r).length}function j8(e,t){let n=O8(e),r=O8(t),i=0;for(;i<n.length&&i<r.length&&n[i]===r[i];)i++;return n.length-i+(r.length-i)}function M8(){let e=new Map;function t(t){let n=T8(t);if(n===``)return;let r=E8(n);if(r===``)return;let i=r.toLowerCase(),a=e.get(i);if(!a){e.set(i,[n]);return}a.includes(n)||a.push(n)}function n(t){let n=T8(t),r=E8(n).toLowerCase(),i=e.get(r);if(!i)return;let a=i.indexOf(n);a!==-1&&(i.splice(a,1),i.length===0&&e.delete(r))}function r(e,r){n(e),t(r)}function i(t,n){let r=t.toLowerCase(),i=e.get(r);if(!i||i.length===0)return null;if(i.length===1)return i[0];let a=D8(T8(n)),o=[],s=[];for(let e of i)k8(a,e)?o.push(e):s.push(e);return o.length>0?(e=>{let t=e[0],n=A8(a,t);for(let r=1;r<e.length;r++){let i=e[r],o=A8(a,i);(o<n||o===n&&i<t)&&(t=i,n=o)}return t})(o):(e=>{let t=e[0],n=j8(a,D8(t));for(let r=1;r<e.length;r++){let i=e[r],o=j8(a,D8(i));(o<n||o===n&&i<t)&&(t=i,n=o)}return t})(s)}function a(){let t=new Map;for(let[n,r]of e)t.set(n,[...r]);return t}function o(){e.clear()}return{add:t,remove:n,rename:r,resolveEmbed:i,clear:o,snapshot:a,size:()=>e.size}}function N8(e){if(!e)return[];let t=e.split(`/`),n=[],r=``;for(let e of t)r=r?`${r}/${e}`:e,n.push(r);return n}function P8(e,t){if(e.size===0)return new Set;if(t===``)return new Set(e);let n=new Set,r=`${t}/`;for(let i of e)(i===t||i.startsWith(r))&&n.add(i);return n}function F8(e){try{return process.kill(e,0),!0}catch(e){return!!(e&&typeof e==`object`&&`code`in e&&e.code===`EPERM`)}}function I8(e){return!(typeof e!=`number`||!Number.isInteger(e)||e<2||e>2147483647)}const L8=/^[A-Za-z0-9-]{8,64}$/;let R8=null;function z8(e){return l(e??m(),`.ok`,`machine-id`)}function B8(e){if(e===void 0&&R8!==null)return R8;let t=z8(e),n=null;try{let e=b(t,`utf-8`).trim();L8.test(e)&&(n=e)}catch{}if(n===null){n=w();try{v(c(t),{recursive:!0}),S(t,`${n}\n`,{encoding:`utf-8`,mode:384})}catch(e){console.warn(`[machine-id] Failed to persist ${t} — using an ephemeral per-process id; lock ownership checks will fail closed (collision) instead of recognizing this machine: ${e instanceof Error?e.message:String(e)}`)}}return e===void 0&&(R8=n),n}function V8(){try{let e=u(c(f(import.meta.url)),`..`,`package.json`),t=JSON.parse(b(e,`utf-8`));if(typeof t.version==`string`&&t.version.length>0)return t.version}catch{}return`0.0.0-unknown`}const H8=V8(),U8=1;var W8=class extends Error{existing;lockPath;lockName;constructor(e,t,n){super(`OpenKnowledge ${n} already running on port ${e.port} (pid ${e.pid}, started ${e.startedAt}). Stop it first or use a different directory. Lock: ${t}`),this.name=`ProcessLockCollisionError`,this.existing=e,this.lockPath=t,this.lockName=n}};function G8(e,t){return u(e,`${t}.lock`)}const K8=new Map;function q8(e){K8.set(e,(K8.get(e)??0)+1)}function J8(e){let t=K8.get(e);return t===void 0||t<=1?(K8.delete(e),!0):(K8.set(e,t-1),!1)}function Y8(e){return typeof e.machineId==`string`?e.machineId===B8():e.hostname===h()}const X8=new Set;let Z8=!1;function Q8(e){X8.add(e),!Z8&&(Z8=!0,process.on(`exit`,()=>{for(let e of X8)try{let t=JSON.parse(b(e,`utf-8`));if(t?.pid!==process.pid||typeof t.machineId==`string`&&t.machineId!==B8()||t.machineId===void 0&&typeof t.hostname==`string`&&t.hostname!==h())continue;x(e)}catch{}}))}function $8(e,t){try{let n=JSON.parse(b(e,`utf-8`));return n&&typeof n==`object`&&I8(n.pid)?n:(console.warn(`${t} Corrupt lock file at ${e} — replacing`),null)}catch{return console.warn(`${t} Corrupt lock file at ${e} — replacing`),null}}function e5(e){let{lockName:t,lockDir:n,metadata:r}=e,i=`[${t}-lock]`;v(n,{recursive:!0});let a=G8(n,t),o={pid:process.pid,hostname:h(),port:r.port,startedAt:new Date().toISOString(),worktreeRoot:r.worktreeRoot,machineId:B8(),...r.kind!==void 0&&{kind:r.kind},...r.parentPid!==void 0&&{parentPid:r.parentPid},...r.capabilities!==void 0&&{capabilities:r.capabilities},protocolVersion:r.protocolVersion??1,runtimeVersion:r.runtimeVersion??H8},s=JSON.stringify(o,null,2);for(let e=0;e<3;e++){if(!_(a))try{let e=y(a,`wx`,384);try{C(e,s)}finally{g(e)}return q8(a),Q8(a),t5({lockName:t,lockDir:n,lockPath:a})}catch(e){if(e.code!==`EEXIST`)throw e}let e=$8(a,i);if(e){if(Y8(e)&&e.pid===process.pid)return S(a,s,{encoding:`utf-8`,mode:384}),q8(a),Q8(a),t5({lockName:t,lockDir:n,lockPath:a});if(F8(e.pid))throw new W8(e,a,t);console.warn(`${i} Stale lock detected (pid=${e.pid}, host=${e.hostname}) — replacing`)}try{x(a)}catch{}}throw Error(`${i} Failed to acquire ${a} after 3 attempts (concurrent acquire contention).`)}function t5(e){let{lockName:t,lockDir:n,lockPath:r}=e;return{lockPath:r,release:()=>s5({lockName:t,lockDir:n}),updatePort:e=>n5({lockName:t,lockDir:n,port:e})}}function n5(e){let{lockName:t,lockDir:n,port:r}=e,i=`[${t}-lock]`,a=G8(n,t);if(!_(a)){console.warn(`${i} Lock file missing at ${a} during port update — skipping`);return}let o;try{let e=JSON.parse(b(a,`utf-8`));if(!e||typeof e!=`object`||!I8(e.pid)){console.warn(`${i} Corrupt lock at ${a} during port update — skipping`);return}o=e}catch{console.warn(`${i} Unreadable lock at ${a} during port update — skipping`);return}if(o.pid===process.pid&&Y8(o)){o.port=r;try{S(a,JSON.stringify(o,null,2),{encoding:`utf-8`,mode:384})}catch(e){console.warn(`${i} Failed to update port in ${a}: ${e instanceof Error?e.message:String(e)}`)}}}function r5(e){let{lockName:t,lockDir:n}=e,r=`[${t}-lock]`,i=G8(n,t);if((K8.get(i)??0)>1)return;let a;try{let e=JSON.parse(b(i,`utf-8`));if(!e||typeof e!=`object`||!I8(e.pid)){console.warn(`${r} Corrupt lock at ${i} during draining mark — skipping`);return}a=e}catch(e){e.code!==`ENOENT`&&console.warn(`${r} Unreadable lock at ${i} during draining mark — skipping: ${e instanceof Error?e.message:String(e)}`);return}if(a.pid===process.pid&&Y8(a)&&a.draining!==!0){a.draining=!0;try{S(i,JSON.stringify(a,null,2),{encoding:`utf-8`,mode:384})}catch(e){console.warn(`${r} Failed to mark ${i} draining: ${e instanceof Error?e.message:String(e)}`)}}}function i5(e){let{lockName:t,lockDir:n}=e,r=G8(n,t);if(!_(r))return null;let i;try{let e=JSON.parse(b(r,`utf-8`));if(!e||typeof e!=`object`||!I8(e.pid))return null;i=e}catch{return null}if(!Y8(i))return null;if(!F8(i.pid)){try{x(r)}catch{}return null}return i}function a5(e){let{lockName:t,lockDir:n}=e,r=G8(n,t);if(!_(r))return{status:`absent`};let i;try{i=JSON.parse(b(r,`utf-8`))}catch{return{status:`incompatible`,reason:`corrupt`,raw:void 0}}if(!i||typeof i!=`object`)return{status:`incompatible`,reason:`corrupt`,raw:i};let a=i;if(!I8(a.pid)||typeof a.hostname!=`string`||typeof a.port!=`number`||typeof a.startedAt!=`string`||typeof a.worktreeRoot!=`string`)return{status:`incompatible`,reason:`corrupt`,raw:i};let o={pid:a.pid,hostname:a.hostname,port:a.port,startedAt:a.startedAt,worktreeRoot:a.worktreeRoot,machineId:typeof a.machineId==`string`?a.machineId:void 0,draining:a.draining===!0?!0:void 0,protocolVersion:typeof a.protocolVersion==`number`?a.protocolVersion:void 0,runtimeVersion:typeof a.runtimeVersion==`string`?a.runtimeVersion:void 0};if(!Y8(o))return{status:`stale`,lock:o};if(!F8(o.pid)){try{x(r)}catch{}return{status:`stale`,lock:o}}return o.protocolVersion===void 0||o.runtimeVersion===void 0?{status:`incompatible`,reason:`missing-fields`,raw:i}:{status:`live`,lock:o}}async function o5(e){let{lockName:t,lockDir:n}=e,r=e.timeoutMs??1e4,i=e.pollIntervalMs??100,a=e.readLock??(()=>i5({lockName:t,lockDir:n})),o=e.sleep??(e=>new Promise(t=>setTimeout(t,e))),s=a();if(s===null||s.draining!==!0)return`no-drain`;let c=Date.now()+r;for(;Date.now()<c;){await o(i);let e=a();if(e===null)return`released`;if(e.draining!==!0)return`no-drain`}return`timeout`}function s5(e){let{lockName:t,lockDir:n,deferUnlinkToExit:r=!1}=e,i=`[${t}-lock]`,a=G8(n,t);if(J8(a)){if(r){r5({lockName:t,lockDir:n});return}if(_(a))try{let e=JSON.parse(b(a,`utf-8`));if(!e||typeof e!=`object`||typeof e.pid!=`number`||e.pid!==process.pid||!Y8(e))return;x(a),X8.delete(a)}catch(e){console.warn(`${i} Failed to release ${a}: ${e instanceof Error?e.message:String(e)}`)}}}var c5=class extends W8{constructor(e,t){super(e,t,`server`),this.name=`ServerLockCollisionError`}};function l5(e,t){try{return e5({lockName:`server`,lockDir:e,metadata:t}).lockPath}catch(e){throw e instanceof W8&&e.lockName===`server`?new c5(e.existing,e.lockPath):e}}function u5(e,t){n5({lockName:`server`,lockDir:e,port:t})}function d5(e){return i5({lockName:`server`,lockDir:e})}function f5(e,t){s5({lockName:`server`,lockDir:e,...t})}function p5(e){r5({lockName:`server`,lockDir:e})}function m5(e,t){return o5({lockName:`server`,lockDir:e,...t})}export{hG as $,Ml as $a,U4 as $i,Hq as $n,D0 as $r,_0 as $t,h1 as A,wq as Aa,e8 as Ai,OG as An,ac as Ao,P0 as Ar,A2 as At,E1 as B,Cl as Ba,c8 as Bi,Z1 as Bn,si as Bo,t8 as Br,i6 as Bt,w1 as C,IG as Ca,_6 as Ci,uJ as Cn,rc as Co,f4 as Cr,U0 as Ct,A1 as D,r3 as Da,_8 as Di,n0 as Dn,P as Do,X2 as Dr,Y1 as Dt,g1 as E,P8 as Ea,J4 as Ei,Y0 as En,j as Eo,l4 as Er,KG as Et,V1 as F,uu as Fa,X$ as Fi,S2 as Fn,Go as Fo,u2 as Fr,u1 as Ft,j4 as G,Kc as Ga,DG as Gi,v2 as Gn,gn as Go,N2 as Gr,QG as Gt,N4 as H,Sl as Ha,p1 as Hi,y4 as Hn,un as Ho,O2 as Hr,x2 as Ht,B1 as I,qc as Ia,W$ as Ii,$3 as In,Uo as Io,d2 as Ir,JG as It,E4 as J,lu as Ja,Gq as Ji,lJ as Jn,Dt as Jo,F2 as Jr,r0 as Jt,O4 as K,Xc as Ka,eK as Ki,p2 as Kn,cn as Ko,R2 as Kr,HG as Kt,nJ as L,su as La,GY as Li,VG as Ln,ma as Lo,o2 as Lr,$1 as Lt,m1 as M,_b as Ma,N8 as Mi,K6 as Mn,$s as Mo,u0 as Mr,U1 as Mt,O1 as N,sp as Na,r6 as Ni,q6 as Nn,Ks as No,f2 as Nr,M1 as Nt,_1 as O,H$ as Oa,Z3 as Oi,e2 as On,dc as Oo,Z2 as Or,L0 as Ot,dJ as P,L as Pa,E$ as Pi,Y6 as Pn,xs as Po,l2 as Pr,N1 as Pt,vG as Q,Jc as Qa,d3 as Qi,zq as Qn,mt as Qo,E0 as Qr,m0 as Qt,i3 as R,Ol as Ra,_q as Ri,_G as Rn,Ka as Ro,s2 as Rr,e0 as Rt,WG as S,Cq as Sa,y6 as Si,W0 as Sn,tc as So,d4 as Sr,H0 as St,w0 as T,pK as Ta,L3 as Ti,J0 as Tn,Zs as To,c4 as Tr,YG as Tt,M4 as U,xl as Ua,Eq as Ui,m2 as Un,fn as Uo,E2 as Ur,N0 as Ut,k4 as V,wl as Va,qq as Vi,h4 as Vn,br as Vo,W2 as Vr,y2 as Vt,A4 as W,bl as Wa,eJ as Wi,h2 as Wn,mn as Wo,L2 as Wr,s6 as Wt,w4 as X,ru as Xa,p3 as Xi,Fq as Xn,O as Xo,P2 as Xr,a0 as Xt,T4 as Y,cu as Ya,BG as Yi,Mq as Yn,k as Yo,I2 as Yr,i0 as Yt,S4 as Z,Yc as Za,I3 as Zi,Bq as Zn,ht as Zo,O0 as Zr,y0 as Zt,f5 as _,jG as _a,s8 as _i,nK as _n,Hs as _o,m4 as _r,l0 as _t,e5 as a,o8 as aa,hJ as ai,p0 as an,fl as ao,i4 as ar,rJ as at,m5 as b,X3 as ba,l8 as bi,mG as bn,M as bo,C2 as br,R1 as bt,F8 as c,a1 as ca,R4 as ci,EG as cn,ml as co,K2 as cr,F1 as ct,r5 as d,Z4 as da,$q as di,M0 as dn,Ll as do,s4 as dr,R0 as dt,FG as ea,T0 as ei,v0 as en,zl as eo,Wq as er,CG as et,p5 as f,s3 as fa,S8 as fi,A0 as fn,Al as fo,$2 as fr,z0 as ft,s5 as g,v8 as ga,RJ as gi,R3 as gn,F as go,p4 as gr,UG as gt,d5 as h,$6 as ha,p8 as hi,o0 as hn,uc as ho,Y2 as hr,Q3 as ht,c5 as i,T2 as ia,gJ as ii,d0 as in,Jl as io,a4 as ir,bG as it,k1 as j,q4 as ja,V6 as ji,V2 as jn,A as jo,vJ as jr,j2 as jt,j1 as k,hK as ka,c6 as ki,t2 as kn,Pc as ko,q2 as kr,k2 as kt,I8 as l,c3 as la,n3 as li,tK as ln,El as lo,o4 as lr,B0 as lt,a5 as m,w8 as ma,gG as mi,$G as mn,Ls as mo,J2 as mr,aK as mt,H8 as n,RG as na,$0 as ni,g0 as nn,ou as no,sJ as nr,yG as nt,l5 as o,mK as oa,t0 as oi,wG as on,Dl as oo,n4 as or,aJ as ot,i5 as p,o1 as pa,C8 as pi,k0 as pn,jl as po,e4 as pr,ZG as pt,C4 as q,pl as qa,W3 as qi,v4 as qn,zt as qo,z2 as qr,K1 as qt,U8 as r,NG as ra,XG as ri,h0 as rn,Zl as ro,Q2 as rr,xG as rt,B8 as s,rK as sa,z4 as si,TG as sn,tu as so,r4 as sr,P1 as st,W8 as t,l6 as ta,Q0 as ti,_J as tn,Tl as to,oJ as tr,SG as tt,G8 as u,kG as ua,pJ as ui,D$ as un,Bl as uo,x4 as ur,V0 as ut,n5 as v,R6 as va,U2 as vi,iK as vn,Ws as vo,B2 as vr,X0 as vt,C0 as w,o3 as wa,G3 as wi,mJ as wn,I as wo,w2 as wr,GG as wt,f8 as x,xq as xa,$Z as xi,K0 as xn,jc as xo,u4 as xr,L1 as xt,u5 as y,W4 as ya,M8 as yi,qG as yn,N as yo,Q6 as yr,Z0 as yt,g3 as z,Zc as za,h8 as zi,X1 as zn,qa as zo,c2 as zr,s0 as zt};
460
- //# sourceMappingURL=server-lock-iLcBw_q0-nWzkxbfg.mjs.map
460
+ //# sourceMappingURL=server-lock-iLcBw_q0-DddnIrHS.mjs.map