@inkeep/open-knowledge 0.36.0-beta.14 → 0.36.0-beta.16
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.
- package/dist/{acp-harness-probe-D0NqAq9o.mjs → acp-harness-probe-DzzmnVA9.mjs} +2 -2
- package/dist/assets/skills/discovery/SKILL.md +1 -1
- package/dist/assets/skills/project/SKILL.md +1 -1
- package/dist/cli.mjs +18 -18
- package/dist/constants-DMEiZNZI.mjs +2 -0
- package/dist/{git-handle-Dp8hOAlv.mjs → git-handle-YAE9YR9Q.mjs} +2 -2
- package/dist/git-handle-ip9_uwkn.mjs +1 -0
- package/dist/index.mjs +1 -1
- package/dist/init-DC_diOY8.mjs +1 -0
- package/dist/{init-kqBx-EMM.mjs → init-Du1ej_je.mjs} +36 -36
- package/dist/{launch-json-removal-bn1agUo9.mjs → launch-json-removal-Co2Hh8Vw.mjs} +2 -2
- package/dist/{loader-DL8JXbrq.mjs → loader-BahUa-3b.mjs} +2 -2
- package/dist/loader-iNgaaI6Q.mjs +1 -0
- package/dist/{open-browser-BzNwp-k4.mjs → open-browser-DCvMiuE2.mjs} +2 -2
- package/dist/{preview-UPT_ohMO.mjs → preview-BYw1WeBG.mjs} +2 -2
- package/dist/preview-Cg9TMkgu.mjs +1 -0
- package/dist/{repair-launch-json-DZyKI_AY.mjs → repair-launch-json-BTMqUbuK.mjs} +2 -2
- package/dist/{repair-mcp-configs-DcQlnVHp.mjs → repair-mcp-configs-DDFw8jyo.mjs} +2 -2
- package/dist/repair-skills-CuU6zHmH.mjs +1 -0
- package/dist/{repair-skills-CNFH4ZJ9.mjs → repair-skills-Ds2IYnpp.mjs} +2 -2
- package/dist/{server-lock-DgdIEzts.mjs → server-lock-0xVm4FnC.mjs} +2 -2
- package/dist/server-lock-CTzXqyfA.mjs +1 -0
- package/dist/src-BI0dWmz0.mjs +1 -0
- package/dist/src-CZe5oBcp.mjs +3262 -0
- package/dist/{src-CRlKbuFA.mjs → src-Cus5RnL8.mjs} +5 -5
- package/dist/{src-Blpirc4b.mjs → src-DgWjvSDo.mjs} +6 -6
- package/dist/{start-unO_gX5Q.mjs → start-DKzs2lPa.mjs} +2 -2
- package/dist/start-DsChVTte.mjs +1 -0
- package/dist/{write-project-skill-F-AuG1hx.mjs → write-project-skill-Ct6JxGJ6.mjs} +4 -4
- package/package.json +5 -5
- package/dist/constants-BVLSXFsS.mjs +0 -2
- package/dist/git-handle-CXXBHz9N.mjs +0 -1
- package/dist/init-B_PRHhsZ.mjs +0 -1
- package/dist/loader-iEX_wQeM.mjs +0 -1
- package/dist/preview-9HXAylOM.mjs +0 -1
- package/dist/repair-skills-SsJumQvo.mjs +0 -1
- package/dist/server-lock-BePZlSZd.mjs +0 -1
- package/dist/src-Bo3Yfnp8.mjs +0 -1
- package/dist/src-Cv6se_bc.mjs +0 -3262
- package/dist/start-DurKOnKX.mjs +0 -1
|
@@ -310,8 +310,8 @@ Read more at https://docs.orama.com/docs/orama-js/plugins/plugin-secure-proxy#pl
|
|
|
310
310
|
`,PLUGIN_SECURE_PROXY_MISSING_CHAT_MODEL:`Could not find a chat model defined in the secure proxy plugin configuration.
|
|
311
311
|
Please provide a chat model before proceeding with creating an answer session.
|
|
312
312
|
Read more at https://docs.orama.com/docs/orama-js/plugins/plugin-secure-proxy#plugin-secure-proxy
|
|
313
|
-
`,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 $(e,...t){let n=Error(MX(eZ[e]??`Unsupported Orama Error code: ${e}`,...t));return n.code=e,`captureStackTrace`in Error.prototype&&Error.captureStackTrace(n),n}function tZ(e){return{raw:Number(e),formatted:IX(e)}}function nZ(e){if(e.id){if(typeof e.id!=`string`)throw $(`DOCUMENT_ID_MUST_BE_STRING`,typeof e.id);return e.id}return RX()}function rZ(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(sZ(r)){let e=uZ(r);if(!Array.isArray(t)||t.length!==e)throw $(`INVALID_INPUT_VECTOR`,n,e,t.length);continue}if(cZ(r)){if(!Array.isArray(t))return n;let e=lZ(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=rZ(t,r);if(e)return n+`.`+e;continue}if(typeof t!==r)return n}}}const iZ={string:!1,number:!1,boolean:!1,enum:!1,geopoint:!1,"string[]":!0,"number[]":!0,"boolean[]":!0,"enum[]":!0},aZ={"string[]":`string`,"number[]":`number`,"boolean[]":`boolean`,"enum[]":`enum`};function oZ(e){return e===`geopoint`}function sZ(e){return typeof e==`string`&&/^vector\[\d+\]$/.test(e)}function cZ(e){return typeof e==`string`&&iZ[e]}function lZ(e){return aZ[e]}function uZ(e){let t=Number(e.slice(7,-1));switch(!0){case isNaN(t):throw $(`INVALID_VECTOR_VALUE`,e);case t<=0:throw $(`INVALID_VECTOR_SIZE`,e);default:return t}}function dZ(){return{idToInternalId:new Map,internalIdToId:[],save:fZ,load:pZ}}function fZ(e){return{internalIdToId:e.internalIdToId}}function pZ(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 mZ(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?mZ(e,t.toString()):t}function hZ(e,t){if(e.internalIdToId.length<t)throw Error(`Invalid internalId ${t}`);return e.internalIdToId[t-1]}function gZ(e,t){return{sharedInternalDocumentStore:t,docs:{},count:0}}function _Z(e,t){let n=mZ(e.sharedInternalDocumentStore,t);return e.docs[n]}function vZ(e,t){let n=t.length,r=Array.from({length:n});for(let i=0;i<n;i++){let n=mZ(e.sharedInternalDocumentStore,t[i]);r[i]=e.docs[n]}return r}function yZ(e){return e.docs}function bZ(e,t,n,r){return e.docs[n]===void 0?(e.docs[n]=r,e.count++,!0):!1}function xZ(e,t){let n=mZ(e.sharedInternalDocumentStore,t);return e.docs[n]===void 0?!1:(delete e.docs[n],e.count--,!0)}function SZ(e){return e.count}function CZ(e,t){let n=t;return{docs:n.docs,count:n.count,sharedInternalDocumentStore:e}}function wZ(e){return{docs:e.docs,count:e.count}}function TZ(){return{create:gZ,get:_Z,getMultiple:vZ,getAll:yZ,store:bZ,remove:xZ,count:SZ,load:CZ,save:wZ}}const EZ=[`beforeInsert`,`afterInsert`,`beforeRemove`,`afterRemove`,`beforeUpdate`,`afterUpdate`,`beforeUpsert`,`afterUpsert`,`beforeSearch`,`afterSearch`,`beforeInsertMultiple`,`afterInsertMultiple`,`beforeRemoveMultiple`,`afterRemoveMultiple`,`beforeUpdateMultiple`,`afterUpdateMultiple`,`beforeUpsertMultiple`,`afterUpsertMultiple`,`beforeLoad`,`afterLoad`,`afterCreate`];function DZ(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),$(`PLUGIN_CRASHED`)}return n}const OZ=[`tokenizer`,`index`,`documentsStore`,`sorter`,`pinning`],kZ=[`validateSchema`,`getDocumentIndexId`,`getDocumentProperties`,`formatElapsedTime`];function AZ(e,t,n,r){if(e.some(qX))return(async()=>{for(let i of e)await i(t,n,r)})();for(let i of e)i(t,n,r)}function jZ(e,t,n){if(e.some(qX))return(async()=>{for(let r of e)await r(t,n)})();for(let r of e)r(t,n)}function MZ(e,t,n,r,i){if(e.some(qX))return(async()=>{for(let a of e)await a(t,n,r,i)})();for(let a of e)a(t,n,r,i)}function NZ(e,t,n,r){if(e.some(qX))return(async()=>{for(let i of e)await i(t,n,r)})();for(let i of e)i(t,n,r)}function PZ(e,t){if(e.some(qX))return(async()=>{for(let n of e)await n(t)})();for(let n of e)n(t)}var FZ=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}},IZ=class e{root=null;insertCount=0;constructor(e,t){e!==void 0&&t!==void 0&&(this.root=new FZ(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?FZ.fromJSON(t.root):null,n.insertCount=t.insertCount||0,n}insertNode(e,t,n,r){if(e===null)return new FZ(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 FZ(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 FZ(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}},LZ=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 RZ(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 zZ(e,t,n){let r=RZ(e,t,n);return{distance:r,isBounded:r>=0}}var BZ=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(zX(e,i)!==null)if(r)if(Math.abs(t.length-i.length)<=r&&zZ(t,i,r).isBounded)e[i]=[];else continue;else e[i]=[];if(zX(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&&(zZ(e,n,r).isBounded&&(i[n]=[]),zX(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}},VZ=class e extends BZ{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,BZ.fromJSON(t)])||[]),n}toJSON(){return super.toJSON()}},HZ=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}},UZ=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 HZ(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=HZ.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)}},WZ=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 GZ(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 KZ=class e{size;vectors=new Map;constructor(e){this.size=e}add(e,t){t instanceof Float32Array||(t=new Float32Array(t));let n=qZ(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)),JZ(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 qZ(e,t){let n=0;for(let r=0;r<t;r++)n+=e[r]*e[r];return Math.sqrt(n)}function JZ(e,t,n,r,i){let a=qZ(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 YZ(e,t,n,r,i){let a=mZ(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 XZ(e,t,n,r,i){let a=0;for(let e of r)e===i&&a++;let o=mZ(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 ZZ(e,t,n,r){let i=mZ(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 QZ(e,t,n){e.tokenOccurrences[t][n]--}function $Z(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)){$Z(e,t,o,r,n);continue}if(sZ(o))r.searchableProperties.push(n),r.searchablePropertiesWithTypes[n]=o,r.vectorIndexes[n]={type:`Vector`,node:new KZ(uZ(o)),isArray:!1};else{let e=/\[/.test(o);switch(o){case`boolean`:case`boolean[]`:r.indexes[n]={type:`Bool`,node:new WZ,isArray:e};break;case`number`:case`number[]`:r.indexes[n]={type:`AVL`,node:new IZ(0,[]),isArray:e};break;case`string`:case`string[]`:r.indexes[n]={type:`Radix`,node:new VZ,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 LZ,isArray:e};break;case`geopoint`:r.indexes[n]={type:`BKD`,node:new UZ,isArray:e};break;default:throw $(`INVALID_SCHEMA_TYPE`,Array.isArray(o)?`array`:o,n)}r.searchableProperties.push(n),r.searchablePropertiesWithTypes[n]=o}}return r}function eQ(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 tQ(e,t,n,r,i,a,o,s,c,l,u){if(sZ(o))return nQ(t,n,a,r,i);let d=eQ(e,t,n,i,s,c,l,u);if(!cZ(o))return d(a);let f=a,p=f.length;for(let e=0;e<p;e++)d(f[e])}function nQ(e,t,n,r,i){e.vectorIndexes[t].node.add(i,n)}function rQ(e,t,n,r,i,a,o,s,c,l){if(sZ(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 iQ(e,t,n,r,i,a,o,s,c,l){if(!cZ(o))return rQ(e,t,n,r,i,a,o,s,c,l);let u=lZ(o),d=a,f=d.length;for(let a=0;a<f;a++)rQ(e,t,n,r,i,d[a],u,s,c,l);return!0}function aQ(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=GZ(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 oQ(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 $(`WRONG_SEARCH_PROPERTY_TYPE`,n);let d=s[n]??1;if(d<=0)throw $(`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];aQ(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 sQ(e,t,n,r){if(`and`in n&&n.and&&Array.isArray(n.and)){let i=n.and;return i.length===0?new Set:YX(...i.map(n=>sQ(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=>sQ(e,t,n,r)).reduce((e,t)=>ZX(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 QX(a,sQ(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 $(`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]=ZX(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=GX(t,r),d=s.searchByRadius(n,u,c,void 0,l);a[o]=pQ(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]=pQ(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]=_Q(a[o],t)}}continue}let u=Object.keys(i);if(u.length>1)throw $(`INVALID_FILTER_OPERATION`,u.length);if(c===`Flat`){let e=new Set(l?s.filterArr(i):s.filter(i));a[o]=ZX(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 $(`INVALID_FILTER_OPERATION`,e)}a[o]=ZX(a[o],n)}}return YX(...Object.values(a))}function cQ(e){return e.searchableProperties}function lQ(e){return e.searchablePropertiesWithTypes}function uQ(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:VZ.fromJSON(t),isArray:i};break;case`Flat`:u[e]={type:`Flat`,node:LZ.fromJSON(t),isArray:i};break;case`AVL`:u[e]={type:`AVL`,node:IZ.fromJSON(t),isArray:i};break;case`BKD`:u[e]={type:`BKD`,node:UZ.fromJSON(t),isArray:i};break;case`Bool`:u[e]={type:`Bool`,node:WZ.fromJSON(t),isArray:i};break;default:u[e]=n[e]}}for(let e of Object.keys(r))d[e]={type:`Vector`,isArray:!1,node:KZ.fromJSON(r[e])};return{sharedInternalDocumentStore:e,indexes:u,vectorIndexes:d,searchableProperties:i,searchablePropertiesWithTypes:a,frequencies:o,tokenOccurrences:s,avgFieldLength:c,fieldLengths:l}}function dQ(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 fQ(){return{create:$Z,insert:tQ,remove:iQ,insertDocumentScoreParameters:YZ,insertTokenScoreParameters:XZ,removeDocumentScoreParameters:ZZ,removeTokenScoreParameters:QZ,calculateResultScores:aQ,search:oQ,searchByWhereClause:sQ,getSearchableProperties:cQ,getSearchablePropertiesWithTypes:lQ,load:uQ,save:dQ}}function pQ(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 mQ(e,t,n=!1){let r=n?UZ.vincentyDistance:UZ.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 hQ(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 gQ(e,t){let n=e,r=hQ(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=GX(e,n);return s=o.searchByRadius(c,l,r,`asc`,i),mQ(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=UZ.calculatePolygonCentroid(e);return mQ(s,r,n)}return null}function _Q(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 vQ(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=vQ(e,t,s,r,n);jX(a.sortableProperties,i.sortableProperties),a.sorts={...a.sorts,...i.sorts},a.sortablePropertiesWithTypes={...a.sortablePropertiesWithTypes,...i.sortablePropertiesWithTypes};continue}if(!sZ(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 $(`INVALID_SORT_SCHEMA_TYPE`,Array.isArray(s)?`array`:s,n)}}}return a}function yQ(e,t,n,r){return r?.enabled===!1?{disabled:!0}:vQ(e,t,n,(r||{}).unsortableProperties||[],``)}function bQ(e,t,n,r){if(!e.enabled)return;e.isSorted=!1;let i=mZ(e.sharedInternalDocumentStore,n),a=e.sorts[t];a.orderedDocsToRemove.has(i)&&DQ(e,t),a.docs.set(i,a.orderedDocs.length),a.orderedDocs.push([i,r])}function xQ(e){if(e.isSorted||!e.enabled)return;let t=Object.keys(e.sorts);for(let n of t)TQ(e,n);e.isSorted=!0}function SQ(e,t,n){return t[1].localeCompare(n[1],wX(e))}function CQ(e,t){return e[1]-t[1]}function wQ(e,t){return t[1]?-1:1}function TQ(e,t){let n=e.sorts[t],r;switch(n.type){case`string`:r=SQ.bind(null,e.language);break;case`number`:r=CQ.bind(null);break;case`boolean`:r=wQ.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 EQ(e){let t=Object.keys(e.sorts);for(let n of t)DQ(e,n)}function DQ(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 OQ(e,t,n){if(!e.enabled)return;let r=e.sorts[t],i=mZ(e.sharedInternalDocumentStore,n);r.docs.get(i)&&(r.docs.delete(i),r.orderedDocsToRemove.set(i,!0))}function kQ(e,t,n){if(!e.enabled)throw $(`SORT_DISABLED`);let r=n.property,i=n.order===`DESC`,a=e.sorts[r];if(!a)throw $(`UNABLE_TO_SORT_ON_UNKNOWN_FIELD`,r,e.sortableProperties.join(`, `));return DQ(e,r),xQ(e),t.sort((t,n)=>{let r=a.docs.get(mZ(e.sharedInternalDocumentStore,t[0])),o=a.docs.get(mZ(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 AQ(e){return e.enabled?e.sortableProperties:[]}function jQ(e){return e.enabled?e.sortablePropertiesWithTypes:{}}function MQ(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 NQ(e){if(!e.enabled)return{enabled:!1};EQ(e),xQ(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 PQ(){return{create:yQ,insert:bQ,remove:OQ,save:NQ,load:MQ,sortBy:kQ,getSortableProperties:AQ,getSortablePropertiesWithTypes:jQ}}const FQ=[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 IQ(e){return e<192||e>383?e:FQ[e-192]||e}function LQ(e){let t=[];for(let n=0;n<e.length;n++)t[n]=IQ(e.charCodeAt(n));return String.fromCharCode(...t)}const RQ={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`},zQ={icate:`ic`,ative:``,alize:`al`,iciti:`ic`,ical:`ic`,ful:``,ness:``},BQ=`[aeiouy]`,VQ=`[^aeiou][^aeiouy]*`;BQ+``;const HQ=`^(`+VQ+`)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*`;``+VQ;const UQ=`^(`+VQ+`)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*[aeiouy][aeiou]*[^aeiou][^aeiouy]*`,WQ=`^(`+VQ+`)?[aeiouy]`;function GQ(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(HQ),r.test(t[1])&&(r=/.$/,e=e.replace(r,``))}else i.test(e)&&(t=i.exec(e)[1],i=new RegExp(WQ),i.test(t)&&(e=t,i=/(at|bl|iz)$/,a=RegExp(`([^aeiouylsz])\\1$`),o=RegExp(`^`+VQ+BQ+`[^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(WQ),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(HQ),t&&r.test(t)&&(e=t+RQ[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(HQ),t&&r.test(t)&&(e=t+zQ[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(UQ),t&&r.test(t)&&(e=t);else if(i.test(e)){let n=i.exec(e);t=n?.[1]??``+n?.[2]??``,i=new RegExp(UQ),i.test(t)&&(e=t)}return r=/^(.+?)e$/,r.test(e)&&(t=r.exec(e)?.[1],r=new RegExp(UQ),i=RegExp(`^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*([aeiouy][aeiou]*)?$`),a=RegExp(`^`+VQ+BQ+`[^aeiouwxy]$`),t&&(r.test(t)||i.test(t)&&!a.test(t))&&(e=t)),r=/ll$/,i=new RegExp(UQ),r.test(e)&&i.test(e)&&(r=/.$/,e=e.replace(r,``)),s==`y`&&(e=s.toLowerCase()+e.substring(1)),e}function KQ(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=LQ(t),n&&this.normalizationCache.set(r,t),t)}function qQ(e){for(;e[e.length-1]===``;)e.pop();for(;e[0]===``;)e.shift();return e}function JQ(e,t,n,r=!0){if(t&&t!==this.language)throw $(`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=SX[this.language];a=e.toLowerCase().split(t).map(e=>i(e,r)).filter(Boolean)}let o=qQ(a);return this.allowDuplicates?o:Array.from(new Set(o))}function YQ(e={}){if(!e.language)e.language=`english`;else if(!CX.includes(e.language))throw $(`LANGUAGE_NOT_SUPPORTED`,e.language);let t;if(e.stemming||e.stemmer&&!(`stemming`in e))if(e.stemmer){if(typeof e.stemmer!=`function`)throw $(`INVALID_STEMMER_FUNCTION_TYPE`);t=e.stemmer}else if(e.language===`english`)t=GQ;else throw $(`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 $(`CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY`);if(!Array.isArray(n))throw $(`CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY`);for(let e of n)if(typeof e!=`string`)throw $(`CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY`)}let r={tokenize:JQ,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:KQ,normalizationCache:new Map};return r.tokenize=JQ.bind(r),r.normalizeToken=KQ,r}function XQ(e){return{sharedInternalDocumentStore:e,rules:new Map}}function ZQ(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 QQ(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 $Q(e,t){return e.rules.delete(t)}function e$(e,t){return e.rules.get(t)}function t$(e){return Array.from(e.rules.values())}function n$(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 r$(e,t){return e?t.conditions.every(t=>n$(e,t)):!1}function i$(e,t){if(!t)return[];let n=[];for(let r of e.rules.values())r$(t,r)&&n.push(r);return n}function a$(e,t){return{sharedInternalDocumentStore:e,rules:new Map(t?.rules??[])}}function o$(e){return{rules:Array.from(e.rules.entries())}}function s$(){return{create:XQ,addRule:ZQ,updateRule:QQ,removeRule:$Q,getRule:e$,getAllRules:t$,getMatchingRules:i$,load:a$,save:o$}}function c$(e){let t={formatElapsedTime:tZ,getDocumentIndexId:nZ,getDocumentProperties:HX,validateSchema:rZ};for(let n of kZ){let r=n;if(e[r]){if(typeof e[r]!=`function`)throw $(`COMPONENT_MUST_BE_FUNCTION`,r)}else e[r]=t[r]}for(let t of Object.keys(e))if(!OZ.includes(t)&&!kZ.includes(t))throw $(`UNSUPPORTED_COMPONENT`,t)}function l$({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 $(`PLUGIN_COMPONENT_CONFLICT`,e,t.name);r={...r,...n}}i||=RX();let o=r.tokenizer,s=r.index,c=r.documentsStore,l=r.sorter,u=r.pinning;if(o=o?o.tokenize?o:YQ(o):YQ({language:n??`english`}),r.tokenizer&&n)throw $(`NO_LANGUAGE_WITH_CUSTOM_TOKENIZER`);let d=dZ();s||=fQ(),l||=PQ(),c||=TZ(),u||=s$(),c$(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:u$()};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 EZ)g[e]=(g[e]??[]).concat(DZ(g,e));let _=g.afterCreate;return _&&PZ(_,g),g}function u$(){return`{{VERSION}}`}function d$(e){return e.documentsStore.count(e.data.docs)}function f$(e,t,n,r,i){let a=e.validateSchema(t,e.schema);if(a)throw $(`SCHEMA_VALIDATION_FAILURE`,a);return qX(e.beforeInsert)||qX(e.afterInsert)||qX(e.index.beforeInsert)||qX(e.index.insert)||qX(e.index.afterInsert)?h$(e,t,n,r,i):g$(e,t,n,r,i)}const p$=new Set([`enum`,`enum[]`]),m$=new Set([`string`,`number`]);async function h$(e,t,n,r,i){let{index:a,docs:o}=e.data,s=e.getDocumentIndexId(t);if(typeof s!=`string`)throw $(`DOCUMENT_ID_MUST_BE_STRING`,typeof s);let c=mZ(e.internalDocumentIDStore,s);if(r||await AZ(e.beforeInsert,e,s,t),!e.documentsStore.store(o,s,c,t))throw $(`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];_$(n,r,e,t)}return await v$(e,s,u,f,l,n,t,i),r||await AZ(e.afterInsert,e,s,t),s}function g$(e,t,n,r,i){let{index:a,docs:o}=e.data,s=e.getDocumentIndexId(t);if(typeof s!=`string`)throw $(`DOCUMENT_ID_MUST_BE_STRING`,typeof s);let c=mZ(e.internalDocumentIDStore,s);if(r||AZ(e.beforeInsert,e,s,t),!e.documentsStore.store(o,s,c,t))throw $(`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];_$(n,r,e,t)}return y$(e,s,u,f,l,n,t,i),r||AZ(e.afterInsert,e,s,t),s}function _$(e,t,n,r){if(!(oZ(t)&&typeof r==`object`&&typeof r.lon==`number`&&typeof r.lat==`number`)&&!(sZ(t)&&Array.isArray(r))&&!(cZ(t)&&Array.isArray(r))&&!(p$.has(t)&&m$.has(e))&&e!==t)throw $(`INVALID_DOCUMENT_PROPERTY`,n,t,e)}async function v$(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 y$(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=mZ(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 b$(e,t,n,r,i,a){return qX(e.afterInsertMultiple)||qX(e.beforeInsertMultiple)||qX(e.index.beforeInsert)||qX(e.index.insert)||qX(e.index.afterInsert)?x$(e,t,n,r,i,a):S$(e,t,n,r,i,a)}async function x$(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 f$(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&&$X(e)}}})(),i||await jZ(e.afterInsertMultiple,e,t),o}function S$(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=f$(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&&$X(e)}}}return l(),i||jZ(e.afterInsertMultiple,e,t),o}function C$(e,t){return e[1]-t[1]}function w$(e,t){return t[1]-e[1]}function T$(e=`desc`){return e.toLowerCase()===`asc`?C$:w$}function E$(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(`.`)?UX(t,e):t[e],a=s[e],o=r[e].values;switch(a){case`number`:{let t=n[e].ranges;D$(t,o)(i);break}case`number[]`:{let t=new Set,r=n[e].ranges,a=D$(r,o,t);for(let e of i)a(e);break}case`boolean`:case`enum`:case`string`:O$(o,a)(i);break;case`boolean[]`:case`enum[]`:case`string[]`:{let e=O$(o,a===`boolean[]`?`boolean`:`string`,new Set);for(let t of i)e(t);break}default:throw $(`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=T$(r.sort);t.values=Object.fromEntries(Object.entries(t.values).sort(i).slice(r.offset??0,r.limit??10))}}return r}function D$(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 O$(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 k$={reducer:(e,t,n,r)=>(t[r]=n,t),getInitialValue:e=>Array.from({length:e})},A$=[`string`,`number`,`boolean`];function j$(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 $(`UNKNOWN_GROUP_BY_PROPERTY`,t);if(!A$.includes(a[t]))throw $(`INVALID_GROUP_BY_PROPERTY`,t,A$.join(`, `),a[t])}let o=t.map(([t])=>hZ(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=UX(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=M$(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=VX(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||k$,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 M$(e,t=0){if(t+1===e.length)return e[t].map(e=>[e]);let n=e[t],r=M$(e,t+1),i=[];for(let e of n)for(let t of r){let n=[e];jX(n,t),i.push(n)}return i}function N$(e,t,n,r){let i=i$(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=mZ(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 P$(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 $(`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=d$(e);if(l=e.index.search(a,r||``,e.tokenizer,n,o,t.exact||!1,t.tolerance||0,t.boost||{},z$(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=I$(r,e);if(typeof n==`string`&&t.every(e=>RegExp(`\\b${F$(e)}\\b`).test(n)))return!0}return!1})}}else l=s?gQ(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 F$(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function I$(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 L$(e,t,n){let r=LX();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=P$(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])=>[mZ(e.internalDocumentIDStore,t),n]);else d=d.sort(BX);d=N$(e,e.data.pinning,d,t.term);let f;u||(f=c?Z$(e,d,s,o,c):Q$(e,d,s,o));let p={elapsed:{formatted:``,raw:0},hits:[],count:d.length};return f!==void 0&&(p.hits=f.filter(Boolean),l||KX(p,i)),a&&(p.facets=E$(e,d,t.facets)),t.groupBy&&(p.groups=j$(e,d,t.groupBy)),p.elapsed=e.formatElapsedTime(LX()-r),p}async function a(){e.beforeSearch&&await NZ(e.beforeSearch,e,t,n);let r=i();return e.afterSearch&&await MZ(e.afterSearch,e,t,n,r),r}return e.beforeSearch?.length||e.afterSearch?.length?a():i()}const R$={k:1.2,b:.75,d:.5};function z$(e){let t=e??{};return t.k=t.k??R$.k,t.b=t.b??R$.b,t.d=t.d??R$.d,t}function B$(e,t,n){let r=t.vector;if(r&&(!(`value`in r)||!(`property`in r)))throw $(`INVALID_VECTOR_INPUT`,Object.keys(r).join(`, `));let i=e.data.index.vectorIndexes[r.property];if(!i)throw $(`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?$(`INVALID_INPUT_VECTOR`,`undefined`,a,`undefined`):$(`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 V$(e,t,n=`english`){let r=LX();function i(){let i=B$(e,t,n).sort(BX);i=N$(e,e.data.pinning,i,void 0);let a=[];t.facets&&Object.keys(t.facets).length>0&&(a=E$(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:hZ(e.internalDocumentIDStore,n[0]),score:n[1],document:r})}let d=[];t.groupBy&&(d=j$(e,i,t.groupBy));let f=LX()-r;return{count:i.length,hits:u.filter(Boolean),elapsed:{raw:Number(f),formatted:IX(f)},...a?{facets:a}:{},...d?{groups:d}:{}}}async function a(){e.beforeSearch&&await NZ(e.beforeSearch,e,t,n);let r=i();return e.afterSearch&&await MZ(e.afterSearch,e,t,n,r),r}return e.beforeSearch?.length||e.afterSearch?.length?a():i()}function H$(e,t,n){let r=G$(P$(e,t,n)),i=B$(e,t,n),a=t.hybridWeights;return J$(r,i,t.term??``,a)}function U$(e,t,n){let r=LX();function i(){let i=H$(e,t,n);i=N$(e,e.data.pinning,i,t.term);let a;t.facets&&Object.keys(t.facets).length>0&&(a=E$(e,i,t.facets));let o;t.groupBy&&(o=j$(e,i,t.groupBy));let s=t.offset??0,c=t.limit??10,l=Q$(e,i,s,c).filter(Boolean),u=LX(),d={count:i.length,elapsed:{raw:Number(u-r),formatted:IX(u-r)},hits:l,...a?{facets:a}:{},...o?{groups:o}:{}};return(t.includeVectors??!1)||KX(d,Object.keys(e.data.index.vectorIndexes)),d}async function a(){e.beforeSearch&&await NZ(e.beforeSearch,e,t,n);let r=i();return e.afterSearch&&await MZ(e.afterSearch,e,t,n,r),r}return e.beforeSearch?.length||e.afterSearch?.length?a():i()}function W$(e){return e[1]}function G$(e){let t=Math.max.apply(Math,e.map(W$));return e.map(([e,n])=>[e,n/t])}function K$(e,t){return e/t}function q$(e,t){return(n,r)=>n*e+r*t}function J$(e,t,n,r){let i=Math.max.apply(Math,e.map(W$)),a=Math.max.apply(Math,t.map(W$)),{text:o,vector:s}=r&&r.text&&r.vector?r:Y$(n),c=new Map,l=e.length,u=q$(o,s);for(let t=0;t<l;t++){let[n,r]=e[t],a=u(K$(r,i),0);c.set(n,a)}let d=t.length;for(let e=0;e<d;e++){let[n,r]=t[e],i=K$(r,a),o=c.get(n)??0;c.set(n,o+u(0,i))}return[...c].sort((e,t)=>t[1]-e[1])}function Y$(e){return{text:.5,vector:.5}}function X$(e,t,n){let r=t.mode??`fulltext`;if(r===`fulltext`)return L$(e,t,n);if(r===`vector`)return V$(e,t);if(r===`hybrid`)return U$(e,t);throw $(`INVALID_SEARCH_MODE`,r)}function Z$(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=UX(m,i);if(!(h===void 0||o.has(h))&&(o.set(h,!0),u++,!(u<=n)&&(s.push({id:hZ(e.internalDocumentIDStore,f),score:p,document:m}),c.add(f),u>=n+r)))break}return s}function Q$(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:hZ(e.internalDocumentIDStore,r),score:c,document:t},o.add(r)}}return a}const $$={id:`string`,kind:`enum`,path:`string`,title:`string`,name:`string`,pathSegments:`string`,content:`string`,modifiedTs:`number`},e1=new WeakMap;function t1(e){return e===void 0||!Number.isFinite(e)?20:Math.max(1,Math.min(100,Math.trunc(e)))}function n1(e){return e.trim().toLowerCase()}const r1=/\.(?:md|mdx)$/;function i1(e,t){if(t!==`page`)return e;let n=e.replace(r1,``);return n.length>0?n:e}function a1(e){let t=e.split(`/`).filter(Boolean);return t[t.length-1]??e}function o1(e){let t=a1(e.path),n=e.title?.trim()||t,r=e.modifiedTs??0,i=e.path.split(`/`).filter(Boolean),a=new Set(i),o=[...new Set((e.aliases??[]).flatMap(e=>e.split(`/`).filter(Boolean)).filter(e=>!a.has(e)))];return{id:`${e.kind}:${e.path}`,kind:e.kind,path:e.path,title:n,name:t,pathSegments:[...i,...o].join(` `),content:e.content??``,modifiedTs:Number.isFinite(r)?r:0}}function s1(e){let t=l$({schema:$$});return e.length>0&&b$(t,e),t}function c1(e){let t={documents:e};return e1.set(t,s1(e)),t}function l1(e){let t=e1.get(e);if(t)return t;let n=s1(e.documents);return e1.set(e,n),n}function u1(e){return e===`autocomplete`?[`page`]:e===`full_text`?[`page`,`content`,`file`]:[`page`,`folder`,`file`]}function d1(e,t){return t.has(e.kind)?!0:e.kind===`page`&&t.has(`content`)}function f1(e,t){let n=n1(t);if(!n)return 0;let r=i1(n,e.kind),i=n1(e.title),a=n1(e.name),o=n1(e.path),s=o.split(`/`);return i===r||a===r?700:o===r?650:i.startsWith(r)||a.startsWith(r)?600:s.some(e=>e.startsWith(r))?550:i.includes(r)||a.includes(r)?500:o.includes(r)?450:-1}function p1(e,t){let n=f1(e,t);return n<=0?n:$v(e.path)?n*.5:n}function m1(e){return e===`file`?-60:0}function h1(e,t,n,r,i){let a=i>0?t/i:0,o=n/50,s=r===`file`?-.001:0,c=1*a+1*o+s;return e*1e3+c}function g1(e,t,n,r){return e+t*20+n+m1(r)}function _1(e,t,n,r,i,a){return e===`relevance`?g1(t,n,r,i):h1(t,n,r,i,a)}function v1(e,t){return t||(e===`full_text`?`relevance`:`navigation`)}function y1(e,t){let n=0;for(let r of e){let e=t.get(r.id)??0;e>n&&(n=e)}return n}function b1(e){let t=e.map(e=>e.modifiedTs).filter(e=>Number.isFinite(e)&&e>0);if(t.length===0)return new Map;let n=1/0,r=-1/0;for(let e of t)e<n&&(n=e),e>r&&(r=e);let i=Math.max(1,r-n);return new Map(e.map(e=>[e.id,e.modifiedTs>0?(e.modifiedTs-n)/i*50:0]))}function x1(e){return e===`full_text`?[`title`,`name`,`path`,`pathSegments`,`content`]:[`title`,`name`,`path`,`pathSegments`]}function S1(e){return e===`full_text`?{title:8,name:7,path:5,pathSegments:4,content:1}:e===`autocomplete`?{title:10,name:9,path:5,pathSegments:4}:{title:8,name:7,path:5,pathSegments:4}}function C1(e,t){return n1(t).length<4?0:+(e===`full_text`)}function w1(e){let{lexical:t,fullText:n}=e.signals;return t>=500?`lexical`:t===450&&n<=0?`pathOnly`:`body`}function T1(e){let t=[],n=[],r=[];for(let i of e){let e=w1(i);e===`lexical`?t.length<100&&t.push(i):e===`body`?n.length<6&&n.push(i):r.length<4&&r.push(i)}return[...t,...n,...r]}function E1(e,t,n){if(t===`relevance`)return e.slice(0,n);let r=T1(e),i=[],a=0,o=0;for(let e of r){if(e.document.kind===`folder`){if(a>=3)continue;a+=1}else if(e.document.kind===`file`){if(o>=3)continue;o+=1}if(i.push(e),i.length>=n)break}return i}function D1(e,t,n={}){let r=n.intent??`omnibar`,i=v1(r,n.ranking),a=t1(n.limit),o=new Set(n.scopes??u1(r)),s=e.documents.filter(e=>d1(e,o)),c=n1(t);if(!c)return s.slice().sort((e,t)=>e.path.localeCompare(t.path)).slice(0,a).map(e=>({document:e,score:0,signals:{lexical:0,fullText:0,recency:0}}));let l=X$(l1(e),{term:c,properties:x1(r),boost:S1(r),tolerance:C1(r,c),limit:Math.max(a*4,40)}),u=new Map(l.hits.filter(e=>d1(e.document,o)).map(e=>[e.document.id,e.score])),d=b1(s),f=new Map;for(let e of s)p1(e,c)>=0&&f.set(e.id,e);for(let e of l.hits)d1(e.document,o)&&f.set(e.document.id,e.document);if(!n.semantic){let e=y1(f.values(),u);return E1([...f.values()].map(t=>{let n=Math.max(0,p1(t,c)),r=u.get(t.id)??0,a=d.get(t.id)??0;return{document:t,score:_1(i,n,r,a,t.kind,e),signals:{lexical:n,fullText:r,recency:a}}}).sort((e,t)=>e.score===t.score?e.document.path.localeCompare(t.document.path):t.score-e.score),i,a)}return E1(k1({scopedDocuments:s,candidates:f,fullTextScores:u,recency:d,normalizedQuery:c,ranking:i,semantic:n.semantic}),i,a)}function O1(e){let t=new Map;return e.forEach((e,n)=>{t.set(e,n+1)}),t}function k1(e){let{scopedDocuments:t,candidates:n,fullTextScores:r,recency:i,normalizedQuery:a,ranking:o,semantic:s}=e,c=s.rrfK??60,l=s.candidateLimit??64,u=s.similarityFloor??0,d=s.scores,f=new Map(t.map(e=>[e.id,e])),p=[...d.entries()].filter(([e,t])=>t>=u&&f.has(e)).sort((e,t)=>t[1]-e[1]||e[0].localeCompare(t[0])).slice(0,l);for(let[e]of p)if(!n.has(e)){let t=f.get(e);t&&n.set(e,t)}let m=y1(n.values(),r),h=[...n.values()].map(e=>{let t=Math.max(0,p1(e,a)),n=r.get(e.id)??0,s=i.get(e.id)??0,c=d.get(e.id),l=c!==void 0&&c>=u;return{document:e,score:t>0?_1(o,t,n,s,e.kind,m):g1(t,n,s,e.kind),signals:l?{lexical:t,fullText:n,recency:s,vector:c}:{lexical:t,fullText:n,recency:s},lexical:t,fullText:n,recency:s,cosine:c}}),g=O1(h.filter(e=>e.fullText>0).sort((e,t)=>t.fullText-e.fullText||e.document.path.localeCompare(t.document.path)).map(e=>e.document.id)),_=O1(h.filter(e=>e.cosine!==void 0&&e.cosine>=u).sort((e,t)=>t.cosine-e.cosine||e.document.path.localeCompare(t.document.path)).map(e=>e.document.id)),v=e=>{let t=0,n=g.get(e);n!==void 0&&(t+=1/(c+n));let r=_.get(e);return r!==void 0&&(t+=1/(c+r)),t};return h.sort((e,t)=>{let n=+(e.lexical>0),r=+(t.lexical>0);if(n!==r)return r-n;if(n===1)return e.score===t.score?e.document.path.localeCompare(t.document.path):t.score-e.score;let i=v(e.document.id),a=v(t.document.id);return i===a?e.recency===t.recency?e.document.path.localeCompare(t.document.path):t.recency-e.recency:a-i}).map(({document:e,score:t,signals:n})=>({document:e,score:t,signals:n}))}const A1=Symbol.for(`@inkeep/open-knowledge/skill-state-field-registry`),j1=globalThis;j1[A1]===void 0&&(j1[A1]=x());const M1=j1[A1],N1=[`.ok`,`skill-state.yml`],P1=[`claude-cowork`,`cli-hosts`],F1=[`server-build-and-open`,`electron-build-and-open`,`cli-npx-skills-add`,`desktop-direct`,`cli-start`],I1=/^\d+\.\d+\.\d+(?:[-+][\w.-]+)?$/,L1=te({version:T().regex(I1,`version must match /^\\d+\\.\\d+\\.\\d+(?:[-+][\\w.-]+)?$/`).register(M1,{description:`Recorded skill version for this target.`}),recordedAt:ee().register(M1,{description:`ISO 8601 timestamp of the most recent successful write. Updated on every write, including reinstalls of the same version.`}),surface:c(F1).register(M1,{description:`Install-source surface that recorded this entry.`}).optional()}),R1=te({enabled:p().register(M1,{description:`Whether this user-global skill bundle is opted in.`}),decidedAt:ee().register(M1,{description:`ISO 8601 timestamp of the opt-in / opt-out decision.`})}),z1=te({schema:E(1).register(M1,{description:`Schema major version. Bumped only on breaking shape changes.`}),targets:te({"claude-cowork":L1.optional(),"cli-hosts":L1.optional()}).register(M1,{description:`Per-target install-state entries. Absent target = no recorded install.`}).default({}),bundles:v(T(),R1).register(M1,{description:`Per-bundle opt-in decisions keyed by install name. Absent key = no recorded decision.`}).optional()});function B1(e,t){return e??t.installedOnDisk}function V1(){return{schema:1,targets:{}}}const H1=`template`;function U1(e){if(e.trim()===``)return{};let t;try{t=(0,Ce.parse)(e)}catch{return{}}return typeof t!=`object`||!t||Array.isArray(t)?{}:t}function W1(e,t){return e.trim()===``?t:`---\n${e}\n---\n${t}`}function G1(e){let{frontmatter:t,body:n}=kp(e);return t===``?{docFrontmatterText:``,markdown:e}:{docFrontmatterText:jp(t),markdown:n}}function K1(e){let t=e.split(`
|
|
314
|
-
`);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=
|
|
315
|
-
`))[
|
|
316
|
-
`).replace(/\n+$/,``)}}function
|
|
317
|
-
//# sourceMappingURL=src-
|
|
313
|
+
`,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 $(e,...t){let n=Error(MX(eZ[e]??`Unsupported Orama Error code: ${e}`,...t));return n.code=e,`captureStackTrace`in Error.prototype&&Error.captureStackTrace(n),n}function tZ(e){return{raw:Number(e),formatted:IX(e)}}function nZ(e){if(e.id){if(typeof e.id!=`string`)throw $(`DOCUMENT_ID_MUST_BE_STRING`,typeof e.id);return e.id}return RX()}function rZ(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(sZ(r)){let e=uZ(r);if(!Array.isArray(t)||t.length!==e)throw $(`INVALID_INPUT_VECTOR`,n,e,t.length);continue}if(cZ(r)){if(!Array.isArray(t))return n;let e=lZ(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=rZ(t,r);if(e)return n+`.`+e;continue}if(typeof t!==r)return n}}}const iZ={string:!1,number:!1,boolean:!1,enum:!1,geopoint:!1,"string[]":!0,"number[]":!0,"boolean[]":!0,"enum[]":!0},aZ={"string[]":`string`,"number[]":`number`,"boolean[]":`boolean`,"enum[]":`enum`};function oZ(e){return e===`geopoint`}function sZ(e){return typeof e==`string`&&/^vector\[\d+\]$/.test(e)}function cZ(e){return typeof e==`string`&&iZ[e]}function lZ(e){return aZ[e]}function uZ(e){let t=Number(e.slice(7,-1));switch(!0){case isNaN(t):throw $(`INVALID_VECTOR_VALUE`,e);case t<=0:throw $(`INVALID_VECTOR_SIZE`,e);default:return t}}function dZ(){return{idToInternalId:new Map,internalIdToId:[],save:fZ,load:pZ}}function fZ(e){return{internalIdToId:e.internalIdToId}}function pZ(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 mZ(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?mZ(e,t.toString()):t}function hZ(e,t){if(e.internalIdToId.length<t)throw Error(`Invalid internalId ${t}`);return e.internalIdToId[t-1]}function gZ(e,t){return{sharedInternalDocumentStore:t,docs:{},count:0}}function _Z(e,t){let n=mZ(e.sharedInternalDocumentStore,t);return e.docs[n]}function vZ(e,t){let n=t.length,r=Array.from({length:n});for(let i=0;i<n;i++){let n=mZ(e.sharedInternalDocumentStore,t[i]);r[i]=e.docs[n]}return r}function yZ(e){return e.docs}function bZ(e,t,n,r){return e.docs[n]===void 0?(e.docs[n]=r,e.count++,!0):!1}function xZ(e,t){let n=mZ(e.sharedInternalDocumentStore,t);return e.docs[n]===void 0?!1:(delete e.docs[n],e.count--,!0)}function SZ(e){return e.count}function CZ(e,t){let n=t;return{docs:n.docs,count:n.count,sharedInternalDocumentStore:e}}function wZ(e){return{docs:e.docs,count:e.count}}function TZ(){return{create:gZ,get:_Z,getMultiple:vZ,getAll:yZ,store:bZ,remove:xZ,count:SZ,load:CZ,save:wZ}}const EZ=[`beforeInsert`,`afterInsert`,`beforeRemove`,`afterRemove`,`beforeUpdate`,`afterUpdate`,`beforeUpsert`,`afterUpsert`,`beforeSearch`,`afterSearch`,`beforeInsertMultiple`,`afterInsertMultiple`,`beforeRemoveMultiple`,`afterRemoveMultiple`,`beforeUpdateMultiple`,`afterUpdateMultiple`,`beforeUpsertMultiple`,`afterUpsertMultiple`,`beforeLoad`,`afterLoad`,`afterCreate`];function DZ(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),$(`PLUGIN_CRASHED`)}return n}const OZ=[`tokenizer`,`index`,`documentsStore`,`sorter`,`pinning`],kZ=[`validateSchema`,`getDocumentIndexId`,`getDocumentProperties`,`formatElapsedTime`];function AZ(e,t,n,r){if(e.some(qX))return(async()=>{for(let i of e)await i(t,n,r)})();for(let i of e)i(t,n,r)}function jZ(e,t,n){if(e.some(qX))return(async()=>{for(let r of e)await r(t,n)})();for(let r of e)r(t,n)}function MZ(e,t,n,r,i){if(e.some(qX))return(async()=>{for(let a of e)await a(t,n,r,i)})();for(let a of e)a(t,n,r,i)}function NZ(e,t,n,r){if(e.some(qX))return(async()=>{for(let i of e)await i(t,n,r)})();for(let i of e)i(t,n,r)}function PZ(e,t){if(e.some(qX))return(async()=>{for(let n of e)await n(t)})();for(let n of e)n(t)}var FZ=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}},IZ=class e{root=null;insertCount=0;constructor(e,t){e!==void 0&&t!==void 0&&(this.root=new FZ(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?FZ.fromJSON(t.root):null,n.insertCount=t.insertCount||0,n}insertNode(e,t,n,r){if(e===null)return new FZ(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 FZ(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 FZ(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}},LZ=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 RZ(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 zZ(e,t,n){let r=RZ(e,t,n);return{distance:r,isBounded:r>=0}}var BZ=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(zX(e,i)!==null)if(r)if(Math.abs(t.length-i.length)<=r&&zZ(t,i,r).isBounded)e[i]=[];else continue;else e[i]=[];if(zX(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&&(zZ(e,n,r).isBounded&&(i[n]=[]),zX(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}},VZ=class e extends BZ{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,BZ.fromJSON(t)])||[]),n}toJSON(){return super.toJSON()}},HZ=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}},UZ=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 HZ(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=HZ.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)}},WZ=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 GZ(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 KZ=class e{size;vectors=new Map;constructor(e){this.size=e}add(e,t){t instanceof Float32Array||(t=new Float32Array(t));let n=qZ(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)),JZ(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 qZ(e,t){let n=0;for(let r=0;r<t;r++)n+=e[r]*e[r];return Math.sqrt(n)}function JZ(e,t,n,r,i){let a=qZ(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 YZ(e,t,n,r,i){let a=mZ(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 XZ(e,t,n,r,i){let a=0;for(let e of r)e===i&&a++;let o=mZ(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 ZZ(e,t,n,r){let i=mZ(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 QZ(e,t,n){e.tokenOccurrences[t][n]--}function $Z(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)){$Z(e,t,o,r,n);continue}if(sZ(o))r.searchableProperties.push(n),r.searchablePropertiesWithTypes[n]=o,r.vectorIndexes[n]={type:`Vector`,node:new KZ(uZ(o)),isArray:!1};else{let e=/\[/.test(o);switch(o){case`boolean`:case`boolean[]`:r.indexes[n]={type:`Bool`,node:new WZ,isArray:e};break;case`number`:case`number[]`:r.indexes[n]={type:`AVL`,node:new IZ(0,[]),isArray:e};break;case`string`:case`string[]`:r.indexes[n]={type:`Radix`,node:new VZ,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 LZ,isArray:e};break;case`geopoint`:r.indexes[n]={type:`BKD`,node:new UZ,isArray:e};break;default:throw $(`INVALID_SCHEMA_TYPE`,Array.isArray(o)?`array`:o,n)}r.searchableProperties.push(n),r.searchablePropertiesWithTypes[n]=o}}return r}function eQ(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 tQ(e,t,n,r,i,a,o,s,c,l,u){if(sZ(o))return nQ(t,n,a,r,i);let d=eQ(e,t,n,i,s,c,l,u);if(!cZ(o))return d(a);let f=a,p=f.length;for(let e=0;e<p;e++)d(f[e])}function nQ(e,t,n,r,i){e.vectorIndexes[t].node.add(i,n)}function rQ(e,t,n,r,i,a,o,s,c,l){if(sZ(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 iQ(e,t,n,r,i,a,o,s,c,l){if(!cZ(o))return rQ(e,t,n,r,i,a,o,s,c,l);let u=lZ(o),d=a,f=d.length;for(let a=0;a<f;a++)rQ(e,t,n,r,i,d[a],u,s,c,l);return!0}function aQ(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=GZ(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 oQ(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 $(`WRONG_SEARCH_PROPERTY_TYPE`,n);let d=s[n]??1;if(d<=0)throw $(`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];aQ(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 sQ(e,t,n,r){if(`and`in n&&n.and&&Array.isArray(n.and)){let i=n.and;return i.length===0?new Set:YX(...i.map(n=>sQ(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=>sQ(e,t,n,r)).reduce((e,t)=>ZX(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 QX(a,sQ(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 $(`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]=ZX(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=GX(t,r),d=s.searchByRadius(n,u,c,void 0,l);a[o]=pQ(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]=pQ(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]=_Q(a[o],t)}}continue}let u=Object.keys(i);if(u.length>1)throw $(`INVALID_FILTER_OPERATION`,u.length);if(c===`Flat`){let e=new Set(l?s.filterArr(i):s.filter(i));a[o]=ZX(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 $(`INVALID_FILTER_OPERATION`,e)}a[o]=ZX(a[o],n)}}return YX(...Object.values(a))}function cQ(e){return e.searchableProperties}function lQ(e){return e.searchablePropertiesWithTypes}function uQ(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:VZ.fromJSON(t),isArray:i};break;case`Flat`:u[e]={type:`Flat`,node:LZ.fromJSON(t),isArray:i};break;case`AVL`:u[e]={type:`AVL`,node:IZ.fromJSON(t),isArray:i};break;case`BKD`:u[e]={type:`BKD`,node:UZ.fromJSON(t),isArray:i};break;case`Bool`:u[e]={type:`Bool`,node:WZ.fromJSON(t),isArray:i};break;default:u[e]=n[e]}}for(let e of Object.keys(r))d[e]={type:`Vector`,isArray:!1,node:KZ.fromJSON(r[e])};return{sharedInternalDocumentStore:e,indexes:u,vectorIndexes:d,searchableProperties:i,searchablePropertiesWithTypes:a,frequencies:o,tokenOccurrences:s,avgFieldLength:c,fieldLengths:l}}function dQ(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 fQ(){return{create:$Z,insert:tQ,remove:iQ,insertDocumentScoreParameters:YZ,insertTokenScoreParameters:XZ,removeDocumentScoreParameters:ZZ,removeTokenScoreParameters:QZ,calculateResultScores:aQ,search:oQ,searchByWhereClause:sQ,getSearchableProperties:cQ,getSearchablePropertiesWithTypes:lQ,load:uQ,save:dQ}}function pQ(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 mQ(e,t,n=!1){let r=n?UZ.vincentyDistance:UZ.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 hQ(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 gQ(e,t){let n=e,r=hQ(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=GX(e,n);return s=o.searchByRadius(c,l,r,`asc`,i),mQ(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=UZ.calculatePolygonCentroid(e);return mQ(s,r,n)}return null}function _Q(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 vQ(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=vQ(e,t,s,r,n);jX(a.sortableProperties,i.sortableProperties),a.sorts={...a.sorts,...i.sorts},a.sortablePropertiesWithTypes={...a.sortablePropertiesWithTypes,...i.sortablePropertiesWithTypes};continue}if(!sZ(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 $(`INVALID_SORT_SCHEMA_TYPE`,Array.isArray(s)?`array`:s,n)}}}return a}function yQ(e,t,n,r){return r?.enabled===!1?{disabled:!0}:vQ(e,t,n,(r||{}).unsortableProperties||[],``)}function bQ(e,t,n,r){if(!e.enabled)return;e.isSorted=!1;let i=mZ(e.sharedInternalDocumentStore,n),a=e.sorts[t];a.orderedDocsToRemove.has(i)&&DQ(e,t),a.docs.set(i,a.orderedDocs.length),a.orderedDocs.push([i,r])}function xQ(e){if(e.isSorted||!e.enabled)return;let t=Object.keys(e.sorts);for(let n of t)TQ(e,n);e.isSorted=!0}function SQ(e,t,n){return t[1].localeCompare(n[1],wX(e))}function CQ(e,t){return e[1]-t[1]}function wQ(e,t){return t[1]?-1:1}function TQ(e,t){let n=e.sorts[t],r;switch(n.type){case`string`:r=SQ.bind(null,e.language);break;case`number`:r=CQ.bind(null);break;case`boolean`:r=wQ.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 EQ(e){let t=Object.keys(e.sorts);for(let n of t)DQ(e,n)}function DQ(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 OQ(e,t,n){if(!e.enabled)return;let r=e.sorts[t],i=mZ(e.sharedInternalDocumentStore,n);r.docs.get(i)&&(r.docs.delete(i),r.orderedDocsToRemove.set(i,!0))}function kQ(e,t,n){if(!e.enabled)throw $(`SORT_DISABLED`);let r=n.property,i=n.order===`DESC`,a=e.sorts[r];if(!a)throw $(`UNABLE_TO_SORT_ON_UNKNOWN_FIELD`,r,e.sortableProperties.join(`, `));return DQ(e,r),xQ(e),t.sort((t,n)=>{let r=a.docs.get(mZ(e.sharedInternalDocumentStore,t[0])),o=a.docs.get(mZ(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 AQ(e){return e.enabled?e.sortableProperties:[]}function jQ(e){return e.enabled?e.sortablePropertiesWithTypes:{}}function MQ(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 NQ(e){if(!e.enabled)return{enabled:!1};EQ(e),xQ(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 PQ(){return{create:yQ,insert:bQ,remove:OQ,save:NQ,load:MQ,sortBy:kQ,getSortableProperties:AQ,getSortablePropertiesWithTypes:jQ}}const FQ=[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 IQ(e){return e<192||e>383?e:FQ[e-192]||e}function LQ(e){let t=[];for(let n=0;n<e.length;n++)t[n]=IQ(e.charCodeAt(n));return String.fromCharCode(...t)}const RQ={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`},zQ={icate:`ic`,ative:``,alize:`al`,iciti:`ic`,ical:`ic`,ful:``,ness:``},BQ=`[aeiouy]`,VQ=`[^aeiou][^aeiouy]*`;BQ+``;const HQ=`^(`+VQ+`)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*`;``+VQ;const UQ=`^(`+VQ+`)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*[aeiouy][aeiou]*[^aeiou][^aeiouy]*`,WQ=`^(`+VQ+`)?[aeiouy]`;function GQ(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(HQ),r.test(t[1])&&(r=/.$/,e=e.replace(r,``))}else i.test(e)&&(t=i.exec(e)[1],i=new RegExp(WQ),i.test(t)&&(e=t,i=/(at|bl|iz)$/,a=RegExp(`([^aeiouylsz])\\1$`),o=RegExp(`^`+VQ+BQ+`[^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(WQ),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(HQ),t&&r.test(t)&&(e=t+RQ[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(HQ),t&&r.test(t)&&(e=t+zQ[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(UQ),t&&r.test(t)&&(e=t);else if(i.test(e)){let n=i.exec(e);t=n?.[1]??``+n?.[2]??``,i=new RegExp(UQ),i.test(t)&&(e=t)}return r=/^(.+?)e$/,r.test(e)&&(t=r.exec(e)?.[1],r=new RegExp(UQ),i=RegExp(`^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*([aeiouy][aeiou]*)?$`),a=RegExp(`^`+VQ+BQ+`[^aeiouwxy]$`),t&&(r.test(t)||i.test(t)&&!a.test(t))&&(e=t)),r=/ll$/,i=new RegExp(UQ),r.test(e)&&i.test(e)&&(r=/.$/,e=e.replace(r,``)),s==`y`&&(e=s.toLowerCase()+e.substring(1)),e}function KQ(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=LQ(t),n&&this.normalizationCache.set(r,t),t)}function qQ(e){for(;e[e.length-1]===``;)e.pop();for(;e[0]===``;)e.shift();return e}function JQ(e,t,n,r=!0){if(t&&t!==this.language)throw $(`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=SX[this.language];a=e.toLowerCase().split(t).map(e=>i(e,r)).filter(Boolean)}let o=qQ(a);return this.allowDuplicates?o:Array.from(new Set(o))}function YQ(e={}){if(!e.language)e.language=`english`;else if(!CX.includes(e.language))throw $(`LANGUAGE_NOT_SUPPORTED`,e.language);let t;if(e.stemming||e.stemmer&&!(`stemming`in e))if(e.stemmer){if(typeof e.stemmer!=`function`)throw $(`INVALID_STEMMER_FUNCTION_TYPE`);t=e.stemmer}else if(e.language===`english`)t=GQ;else throw $(`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 $(`CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY`);if(!Array.isArray(n))throw $(`CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY`);for(let e of n)if(typeof e!=`string`)throw $(`CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY`)}let r={tokenize:JQ,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:KQ,normalizationCache:new Map};return r.tokenize=JQ.bind(r),r.normalizeToken=KQ,r}function XQ(e){return{sharedInternalDocumentStore:e,rules:new Map}}function ZQ(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 QQ(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 $Q(e,t){return e.rules.delete(t)}function e$(e,t){return e.rules.get(t)}function t$(e){return Array.from(e.rules.values())}function n$(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 r$(e,t){return e?t.conditions.every(t=>n$(e,t)):!1}function i$(e,t){if(!t)return[];let n=[];for(let r of e.rules.values())r$(t,r)&&n.push(r);return n}function a$(e,t){return{sharedInternalDocumentStore:e,rules:new Map(t?.rules??[])}}function o$(e){return{rules:Array.from(e.rules.entries())}}function s$(){return{create:XQ,addRule:ZQ,updateRule:QQ,removeRule:$Q,getRule:e$,getAllRules:t$,getMatchingRules:i$,load:a$,save:o$}}function c$(e){let t={formatElapsedTime:tZ,getDocumentIndexId:nZ,getDocumentProperties:HX,validateSchema:rZ};for(let n of kZ){let r=n;if(e[r]){if(typeof e[r]!=`function`)throw $(`COMPONENT_MUST_BE_FUNCTION`,r)}else e[r]=t[r]}for(let t of Object.keys(e))if(!OZ.includes(t)&&!kZ.includes(t))throw $(`UNSUPPORTED_COMPONENT`,t)}function l$({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 $(`PLUGIN_COMPONENT_CONFLICT`,e,t.name);r={...r,...n}}i||=RX();let o=r.tokenizer,s=r.index,c=r.documentsStore,l=r.sorter,u=r.pinning;if(o=o?o.tokenize?o:YQ(o):YQ({language:n??`english`}),r.tokenizer&&n)throw $(`NO_LANGUAGE_WITH_CUSTOM_TOKENIZER`);let d=dZ();s||=fQ(),l||=PQ(),c||=TZ(),u||=s$(),c$(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:u$()};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 EZ)g[e]=(g[e]??[]).concat(DZ(g,e));let _=g.afterCreate;return _&&PZ(_,g),g}function u$(){return`{{VERSION}}`}function d$(e){return e.documentsStore.count(e.data.docs)}function f$(e,t,n,r,i){let a=e.validateSchema(t,e.schema);if(a)throw $(`SCHEMA_VALIDATION_FAILURE`,a);return qX(e.beforeInsert)||qX(e.afterInsert)||qX(e.index.beforeInsert)||qX(e.index.insert)||qX(e.index.afterInsert)?h$(e,t,n,r,i):g$(e,t,n,r,i)}const p$=new Set([`enum`,`enum[]`]),m$=new Set([`string`,`number`]);async function h$(e,t,n,r,i){let{index:a,docs:o}=e.data,s=e.getDocumentIndexId(t);if(typeof s!=`string`)throw $(`DOCUMENT_ID_MUST_BE_STRING`,typeof s);let c=mZ(e.internalDocumentIDStore,s);if(r||await AZ(e.beforeInsert,e,s,t),!e.documentsStore.store(o,s,c,t))throw $(`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];_$(n,r,e,t)}return await v$(e,s,u,f,l,n,t,i),r||await AZ(e.afterInsert,e,s,t),s}function g$(e,t,n,r,i){let{index:a,docs:o}=e.data,s=e.getDocumentIndexId(t);if(typeof s!=`string`)throw $(`DOCUMENT_ID_MUST_BE_STRING`,typeof s);let c=mZ(e.internalDocumentIDStore,s);if(r||AZ(e.beforeInsert,e,s,t),!e.documentsStore.store(o,s,c,t))throw $(`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];_$(n,r,e,t)}return y$(e,s,u,f,l,n,t,i),r||AZ(e.afterInsert,e,s,t),s}function _$(e,t,n,r){if(!(oZ(t)&&typeof r==`object`&&typeof r.lon==`number`&&typeof r.lat==`number`)&&!(sZ(t)&&Array.isArray(r))&&!(cZ(t)&&Array.isArray(r))&&!(p$.has(t)&&m$.has(e))&&e!==t)throw $(`INVALID_DOCUMENT_PROPERTY`,n,t,e)}async function v$(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 y$(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=mZ(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 b$(e,t,n,r,i,a){return qX(e.afterInsertMultiple)||qX(e.beforeInsertMultiple)||qX(e.index.beforeInsert)||qX(e.index.insert)||qX(e.index.afterInsert)?x$(e,t,n,r,i,a):S$(e,t,n,r,i,a)}async function x$(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 f$(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&&$X(e)}}})(),i||await jZ(e.afterInsertMultiple,e,t),o}function S$(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=f$(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&&$X(e)}}}return l(),i||jZ(e.afterInsertMultiple,e,t),o}function C$(e,t,n,r){return qX(e.index.beforeRemove)||qX(e.index.remove)||qX(e.index.afterRemove)?w$(e,t,n,r):T$(e,t,n,r)}async function w$(e,t,n,r){let i=!0,{index:a,docs:o}=e.data,s=e.documentsStore.get(o,t);if(!s)return!1;let c=mZ(e.internalDocumentIDStore,t),l=hZ(e.internalDocumentIDStore,c),u=e.documentsStore.count(o);r||await AZ(e.beforeRemove,e,l);let d=e.index.getSearchableProperties(a),f=e.index.getSearchablePropertiesWithTypes(a),p=e.getDocumentProperties(s,d);for(let r of d){let a=p[r];if(a===void 0)continue;let o=f[r];await e.index.beforeRemove?.(e.data.index,r,l,a,o,n,e.tokenizer,u),await e.index.remove(e.index,e.data.index,r,t,c,a,o,n,e.tokenizer,u)||(i=!1),await e.index.afterRemove?.(e.data.index,r,l,a,o,n,e.tokenizer,u)}let m=await e.sorter.getSortableProperties(e.data.sorting),h=await e.getDocumentProperties(s,m);for(let n of m)h[n]!==void 0&&e.sorter.remove(e.data.sorting,n,t);return r||await AZ(e.afterRemove,e,l),e.documentsStore.remove(e.data.docs,t,c),i}function T$(e,t,n,r){let i=!0,{index:a,docs:o}=e.data,s=e.documentsStore.get(o,t);if(!s)return!1;let c=mZ(e.internalDocumentIDStore,t),l=hZ(e.internalDocumentIDStore,c),u=e.documentsStore.count(o);r||AZ(e.beforeRemove,e,l);let d=e.index.getSearchableProperties(a),f=e.index.getSearchablePropertiesWithTypes(a),p=e.getDocumentProperties(s,d);for(let r of d){let a=p[r];if(a===void 0)continue;let o=f[r];e.index.beforeRemove?.(e.data.index,r,l,a,o,n,e.tokenizer,u),e.index.remove(e.index,e.data.index,r,t,c,a,o,n,e.tokenizer,u)||(i=!1),e.index.afterRemove?.(e.data.index,r,l,a,o,n,e.tokenizer,u)}let m=e.sorter.getSortableProperties(e.data.sorting),h=e.getDocumentProperties(s,m);for(let n of m)h[n]!==void 0&&e.sorter.remove(e.data.sorting,n,t);return r||AZ(e.afterRemove,e,l),e.documentsStore.remove(e.data.docs,t,c),i}function E$(e,t,n,r,i){return qX(e.index.beforeRemove)||qX(e.index.remove)||qX(e.index.afterRemove)||qX(e.beforeRemoveMultiple)||qX(e.afterRemoveMultiple)?D$(e,t,n,r,i):O$(e,t,n,r,i)}async function D$(e,t,n,r,i){let a=0;n||=1e3;let o=i?[]:t.map(t=>hZ(e.internalDocumentIDStore,mZ(e.internalDocumentIDStore,t)));return i||await jZ(e.beforeRemoveMultiple,e,o),await new Promise((o,s)=>{let c=0;async function l(){let u=t.slice(c*n,++c*n);if(!u.length)return o();for(let t of u)try{await C$(e,t,r,i)&&a++}catch(e){s(e)}setTimeout(l,0)}setTimeout(l,0)}),i||await jZ(e.afterRemoveMultiple,e,o),a}function O$(e,t,n,r,i){let a=0;n||=1e3;let o=i?[]:t.map(t=>hZ(e.internalDocumentIDStore,mZ(e.internalDocumentIDStore,t)));i||jZ(e.beforeRemoveMultiple,e,o);let s=0;function c(){let o=t.slice(s*n,++s*n);if(o.length){for(let t of o)C$(e,t,r,i)&&a++;setTimeout(c,0)}}return c(),i||jZ(e.afterRemoveMultiple,e,o),a}function k$(e,t){return e[1]-t[1]}function A$(e,t){return t[1]-e[1]}function j$(e=`desc`){return e.toLowerCase()===`asc`?k$:A$}function M$(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(`.`)?UX(t,e):t[e],a=s[e],o=r[e].values;switch(a){case`number`:{let t=n[e].ranges;N$(t,o)(i);break}case`number[]`:{let t=new Set,r=n[e].ranges,a=N$(r,o,t);for(let e of i)a(e);break}case`boolean`:case`enum`:case`string`:P$(o,a)(i);break;case`boolean[]`:case`enum[]`:case`string[]`:{let e=P$(o,a===`boolean[]`?`boolean`:`string`,new Set);for(let t of i)e(t);break}default:throw $(`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=j$(r.sort);t.values=Object.fromEntries(Object.entries(t.values).sort(i).slice(r.offset??0,r.limit??10))}}return r}function N$(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 P$(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 F$={reducer:(e,t,n,r)=>(t[r]=n,t),getInitialValue:e=>Array.from({length:e})},I$=[`string`,`number`,`boolean`];function L$(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 $(`UNKNOWN_GROUP_BY_PROPERTY`,t);if(!I$.includes(a[t]))throw $(`INVALID_GROUP_BY_PROPERTY`,t,I$.join(`, `),a[t])}let o=t.map(([t])=>hZ(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=UX(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=R$(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=VX(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||F$,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 R$(e,t=0){if(t+1===e.length)return e[t].map(e=>[e]);let n=e[t],r=R$(e,t+1),i=[];for(let e of n)for(let t of r){let n=[e];jX(n,t),i.push(n)}return i}function z$(e,t,n,r){let i=i$(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=mZ(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 B$(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 $(`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=d$(e);if(l=e.index.search(a,r||``,e.tokenizer,n,o,t.exact||!1,t.tolerance||0,t.boost||{},G$(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=H$(r,e);if(typeof n==`string`&&t.every(e=>RegExp(`\\b${V$(e)}\\b`).test(n)))return!0}return!1})}}else l=s?gQ(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 V$(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function H$(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 U$(e,t,n){let r=LX();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=B$(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])=>[mZ(e.internalDocumentIDStore,t),n]);else d=d.sort(BX);d=z$(e,e.data.pinning,d,t.term);let f;u||(f=c?r1(e,d,s,o,c):i1(e,d,s,o));let p={elapsed:{formatted:``,raw:0},hits:[],count:d.length};return f!==void 0&&(p.hits=f.filter(Boolean),l||KX(p,i)),a&&(p.facets=M$(e,d,t.facets)),t.groupBy&&(p.groups=L$(e,d,t.groupBy)),p.elapsed=e.formatElapsedTime(LX()-r),p}async function a(){e.beforeSearch&&await NZ(e.beforeSearch,e,t,n);let r=i();return e.afterSearch&&await MZ(e.afterSearch,e,t,n,r),r}return e.beforeSearch?.length||e.afterSearch?.length?a():i()}const W$={k:1.2,b:.75,d:.5};function G$(e){let t=e??{};return t.k=t.k??W$.k,t.b=t.b??W$.b,t.d=t.d??W$.d,t}function K$(e,t,n){let r=t.vector;if(r&&(!(`value`in r)||!(`property`in r)))throw $(`INVALID_VECTOR_INPUT`,Object.keys(r).join(`, `));let i=e.data.index.vectorIndexes[r.property];if(!i)throw $(`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?$(`INVALID_INPUT_VECTOR`,`undefined`,a,`undefined`):$(`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 q$(e,t,n=`english`){let r=LX();function i(){let i=K$(e,t,n).sort(BX);i=z$(e,e.data.pinning,i,void 0);let a=[];t.facets&&Object.keys(t.facets).length>0&&(a=M$(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:hZ(e.internalDocumentIDStore,n[0]),score:n[1],document:r})}let d=[];t.groupBy&&(d=L$(e,i,t.groupBy));let f=LX()-r;return{count:i.length,hits:u.filter(Boolean),elapsed:{raw:Number(f),formatted:IX(f)},...a?{facets:a}:{},...d?{groups:d}:{}}}async function a(){e.beforeSearch&&await NZ(e.beforeSearch,e,t,n);let r=i();return e.afterSearch&&await MZ(e.afterSearch,e,t,n,r),r}return e.beforeSearch?.length||e.afterSearch?.length?a():i()}function J$(e,t,n){let r=Z$(B$(e,t,n)),i=K$(e,t,n),a=t.hybridWeights;return e1(r,i,t.term??``,a)}function Y$(e,t,n){let r=LX();function i(){let i=J$(e,t,n);i=z$(e,e.data.pinning,i,t.term);let a;t.facets&&Object.keys(t.facets).length>0&&(a=M$(e,i,t.facets));let o;t.groupBy&&(o=L$(e,i,t.groupBy));let s=t.offset??0,c=t.limit??10,l=i1(e,i,s,c).filter(Boolean),u=LX(),d={count:i.length,elapsed:{raw:Number(u-r),formatted:IX(u-r)},hits:l,...a?{facets:a}:{},...o?{groups:o}:{}};return(t.includeVectors??!1)||KX(d,Object.keys(e.data.index.vectorIndexes)),d}async function a(){e.beforeSearch&&await NZ(e.beforeSearch,e,t,n);let r=i();return e.afterSearch&&await MZ(e.afterSearch,e,t,n,r),r}return e.beforeSearch?.length||e.afterSearch?.length?a():i()}function X$(e){return e[1]}function Z$(e){let t=Math.max.apply(Math,e.map(X$));return e.map(([e,n])=>[e,n/t])}function Q$(e,t){return e/t}function $$(e,t){return(n,r)=>n*e+r*t}function e1(e,t,n,r){let i=Math.max.apply(Math,e.map(X$)),a=Math.max.apply(Math,t.map(X$)),{text:o,vector:s}=r&&r.text&&r.vector?r:t1(n),c=new Map,l=e.length,u=$$(o,s);for(let t=0;t<l;t++){let[n,r]=e[t],a=u(Q$(r,i),0);c.set(n,a)}let d=t.length;for(let e=0;e<d;e++){let[n,r]=t[e],i=Q$(r,a),o=c.get(n)??0;c.set(n,o+u(0,i))}return[...c].sort((e,t)=>t[1]-e[1])}function t1(e){return{text:.5,vector:.5}}function n1(e,t,n){let r=t.mode??`fulltext`;if(r===`fulltext`)return U$(e,t,n);if(r===`vector`)return q$(e,t);if(r===`hybrid`)return Y$(e,t);throw $(`INVALID_SEARCH_MODE`,r)}function r1(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=UX(m,i);if(!(h===void 0||o.has(h))&&(o.set(h,!0),u++,!(u<=n)&&(s.push({id:hZ(e.internalDocumentIDStore,f),score:p,document:m}),c.add(f),u>=n+r)))break}return s}function i1(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:hZ(e.internalDocumentIDStore,r),score:c,document:t},o.add(r)}}return a}const a1={id:`string`,kind:`enum`,path:`string`,title:`string`,name:`string`,pathSegments:`string`,content:`string`,modifiedTs:`number`},o1=new WeakMap;function s1(e){return e===void 0||!Number.isFinite(e)?20:Math.max(1,Math.min(100,Math.trunc(e)))}function c1(e){return e.trim().toLowerCase()}const l1=/\.(?:md|mdx)$/;function u1(e,t){if(t!==`page`)return e;let n=e.replace(l1,``);return n.length>0?n:e}function d1(e){let t=e.split(`/`).filter(Boolean);return t[t.length-1]??e}function f1(e){let t=d1(e.path),n=e.title?.trim()||t,r=e.modifiedTs??0,i=e.path.split(`/`).filter(Boolean),a=new Set(i),o=[...new Set((e.aliases??[]).flatMap(e=>e.split(`/`).filter(Boolean)).filter(e=>!a.has(e)))];return{id:`${e.kind}:${e.path}`,kind:e.kind,path:e.path,title:n,name:t,pathSegments:[...i,...o].join(` `),content:e.content??``,modifiedTs:Number.isFinite(r)?r:0}}function p1(e){let t=l$({schema:a1});return e.length>0&&b$(t,e),t}function m1(e){let t={documents:e};return o1.set(t,p1(e)),t}function h1(e){let t=o1.get(e);if(t)return t;let n=p1(e.documents);return o1.set(e,n),n}const g1=new WeakSet;function _1(e,t){return e===t||e.kind===t.kind&&e.path===t.path&&e.title===t.title&&e.name===t.name&&e.pathSegments===t.pathSegments&&e.modifiedTs===t.modifiedTs&&e.content===t.content}function v1(e,t){let n=e=>({corpus:m1(t),inserted:0,updated:0,removed:0,rebuilt:!0,rebuildReason:e}),r=o1.get(e);if(!r)return n(`no-index`);if(g1.has(e))return n(`stale-base`);let i=new Map(t.map(e=>[e.id,e]));if(i.size!==t.length)return n(`duplicate-id`);let a=[],o=[],s=0;for(let t of e.documents){let e=i.get(t.id);e?_1(t,e)||(a.push(t.id),o.push(e),s+=1):a.push(t.id)}let c=new Set(e.documents.map(e=>e.id));for(let e of t)c.has(e.id)||o.push(e);if(a.length+o.length>t.length)return n(`bulk-change`);g1.add(e);try{if(a.length>0&&E$(r,a),o.length>0&&b$(r,o),d$(r)!==t.length)throw Error(`Search index count ${d$(r)} diverged from document count ${t.length} after incremental update`)}catch{return n(`mutation-failed`)}let l={documents:t};return o1.set(l,r),{corpus:l,inserted:o.length-s,updated:s,removed:a.length-s,rebuilt:!1}}function y1(e){return e===`autocomplete`?[`page`]:e===`full_text`?[`page`,`content`,`file`]:[`page`,`folder`,`file`]}function b1(e,t){return t.has(e.kind)?!0:e.kind===`page`&&t.has(`content`)}function x1(e,t){let n=c1(t);if(!n)return 0;let r=u1(n,e.kind),i=c1(e.title),a=c1(e.name),o=c1(e.path),s=o.split(`/`);return i===r||a===r?700:o===r?650:i.startsWith(r)||a.startsWith(r)?600:s.some(e=>e.startsWith(r))?550:i.includes(r)||a.includes(r)?500:o.includes(r)?450:-1}function S1(e,t){let n=x1(e,t);return n<=0?n:$v(e.path)?n*.5:n}function C1(e){return e===`file`?-60:0}function w1(e,t,n,r,i){let a=i>0?t/i:0,o=n/50,s=r===`file`?-.001:0,c=1*a+1*o+s;return e*1e3+c}function T1(e,t,n,r){return e+t*20+n+C1(r)}function E1(e,t,n,r,i,a){return e===`relevance`?T1(t,n,r,i):w1(t,n,r,i,a)}function D1(e,t){return t||(e===`full_text`?`relevance`:`navigation`)}function O1(e,t){let n=0;for(let r of e){let e=t.get(r.id)??0;e>n&&(n=e)}return n}function k1(e){let t=e.map(e=>e.modifiedTs).filter(e=>Number.isFinite(e)&&e>0);if(t.length===0)return new Map;let n=1/0,r=-1/0;for(let e of t)e<n&&(n=e),e>r&&(r=e);let i=Math.max(1,r-n);return new Map(e.map(e=>[e.id,e.modifiedTs>0?(e.modifiedTs-n)/i*50:0]))}function A1(e){return e===`full_text`?[`title`,`name`,`path`,`pathSegments`,`content`]:[`title`,`name`,`path`,`pathSegments`]}function j1(e){return e===`full_text`?{title:8,name:7,path:5,pathSegments:4,content:1}:e===`autocomplete`?{title:10,name:9,path:5,pathSegments:4}:{title:8,name:7,path:5,pathSegments:4}}function M1(e,t){return c1(t).length<4?0:+(e===`full_text`)}function N1(e){let{lexical:t,fullText:n}=e.signals;return t>=500?`lexical`:t===450&&n<=0?`pathOnly`:`body`}function P1(e){let t=[],n=[],r=[];for(let i of e){let e=N1(i);e===`lexical`?t.length<100&&t.push(i):e===`body`?n.length<6&&n.push(i):r.length<4&&r.push(i)}return[...t,...n,...r]}function F1(e,t,n){if(t===`relevance`)return e.slice(0,n);let r=P1(e),i=[],a=0,o=0;for(let e of r){if(e.document.kind===`folder`){if(a>=3)continue;a+=1}else if(e.document.kind===`file`){if(o>=3)continue;o+=1}if(i.push(e),i.length>=n)break}return i}function I1(e,t,n={}){let r=n.intent??`omnibar`,i=D1(r,n.ranking),a=s1(n.limit),o=new Set(n.scopes??y1(r)),s=e.documents.filter(e=>b1(e,o)),c=c1(t);if(!c)return s.slice().sort((e,t)=>e.path.localeCompare(t.path)).slice(0,a).map(e=>({document:e,score:0,signals:{lexical:0,fullText:0,recency:0}}));let l=n1(h1(e),{term:c,properties:A1(r),boost:j1(r),tolerance:M1(r,c),limit:Math.max(a*4,40)}),u=new Map(l.hits.filter(e=>b1(e.document,o)).map(e=>[e.document.id,e.score])),d=k1(s),f=new Map;for(let e of s)S1(e,c)>=0&&f.set(e.id,e);for(let e of l.hits)b1(e.document,o)&&f.set(e.document.id,e.document);if(!n.semantic){let e=O1(f.values(),u);return F1([...f.values()].map(t=>{let n=Math.max(0,S1(t,c)),r=u.get(t.id)??0,a=d.get(t.id)??0;return{document:t,score:E1(i,n,r,a,t.kind,e),signals:{lexical:n,fullText:r,recency:a}}}).sort((e,t)=>e.score===t.score?e.document.path.localeCompare(t.document.path):t.score-e.score),i,a)}return F1(R1({scopedDocuments:s,candidates:f,fullTextScores:u,recency:d,normalizedQuery:c,ranking:i,semantic:n.semantic}),i,a)}function L1(e){let t=new Map;return e.forEach((e,n)=>{t.set(e,n+1)}),t}function R1(e){let{scopedDocuments:t,candidates:n,fullTextScores:r,recency:i,normalizedQuery:a,ranking:o,semantic:s}=e,c=s.rrfK??60,l=s.candidateLimit??64,u=s.similarityFloor??0,d=s.scores,f=new Map(t.map(e=>[e.id,e])),p=[...d.entries()].filter(([e,t])=>t>=u&&f.has(e)).sort((e,t)=>t[1]-e[1]||e[0].localeCompare(t[0])).slice(0,l);for(let[e]of p)if(!n.has(e)){let t=f.get(e);t&&n.set(e,t)}let m=O1(n.values(),r),h=[...n.values()].map(e=>{let t=Math.max(0,S1(e,a)),n=r.get(e.id)??0,s=i.get(e.id)??0,c=d.get(e.id),l=c!==void 0&&c>=u;return{document:e,score:t>0?E1(o,t,n,s,e.kind,m):T1(t,n,s,e.kind),signals:l?{lexical:t,fullText:n,recency:s,vector:c}:{lexical:t,fullText:n,recency:s},lexical:t,fullText:n,recency:s,cosine:c}}),g=L1(h.filter(e=>e.fullText>0).sort((e,t)=>t.fullText-e.fullText||e.document.path.localeCompare(t.document.path)).map(e=>e.document.id)),_=L1(h.filter(e=>e.cosine!==void 0&&e.cosine>=u).sort((e,t)=>t.cosine-e.cosine||e.document.path.localeCompare(t.document.path)).map(e=>e.document.id)),v=e=>{let t=0,n=g.get(e);n!==void 0&&(t+=1/(c+n));let r=_.get(e);return r!==void 0&&(t+=1/(c+r)),t};return h.sort((e,t)=>{let n=+(e.lexical>0),r=+(t.lexical>0);if(n!==r)return r-n;if(n===1)return e.score===t.score?e.document.path.localeCompare(t.document.path):t.score-e.score;let i=v(e.document.id),a=v(t.document.id);return i===a?e.recency===t.recency?e.document.path.localeCompare(t.document.path):t.recency-e.recency:a-i}).map(({document:e,score:t,signals:n})=>({document:e,score:t,signals:n}))}const z1=Symbol.for(`@inkeep/open-knowledge/skill-state-field-registry`),B1=globalThis;B1[z1]===void 0&&(B1[z1]=x());const V1=B1[z1],H1=[`.ok`,`skill-state.yml`],U1=[`claude-cowork`,`cli-hosts`],W1=[`server-build-and-open`,`electron-build-and-open`,`cli-npx-skills-add`,`desktop-direct`,`cli-start`],G1=/^\d+\.\d+\.\d+(?:[-+][\w.-]+)?$/,K1=te({version:T().regex(G1,`version must match /^\\d+\\.\\d+\\.\\d+(?:[-+][\\w.-]+)?$/`).register(V1,{description:`Recorded skill version for this target.`}),recordedAt:ee().register(V1,{description:`ISO 8601 timestamp of the most recent successful write. Updated on every write, including reinstalls of the same version.`}),surface:c(W1).register(V1,{description:`Install-source surface that recorded this entry.`}).optional()}),q1=te({enabled:p().register(V1,{description:`Whether this user-global skill bundle is opted in.`}),decidedAt:ee().register(V1,{description:`ISO 8601 timestamp of the opt-in / opt-out decision.`})}),J1=te({schema:E(1).register(V1,{description:`Schema major version. Bumped only on breaking shape changes.`}),targets:te({"claude-cowork":K1.optional(),"cli-hosts":K1.optional()}).register(V1,{description:`Per-target install-state entries. Absent target = no recorded install.`}).default({}),bundles:v(T(),q1).register(V1,{description:`Per-bundle opt-in decisions keyed by install name. Absent key = no recorded decision.`}).optional()});function Y1(e,t){return e??t.installedOnDisk}function X1(){return{schema:1,targets:{}}}const Z1=`template`;function Q1(e){if(e.trim()===``)return{};let t;try{t=(0,Ce.parse)(e)}catch{return{}}return typeof t!=`object`||!t||Array.isArray(t)?{}:t}function $1(e,t){return e.trim()===``?t:`---\n${e}\n---\n${t}`}function e0(e){let{frontmatter:t,body:n}=kp(e);return t===``?{docFrontmatterText:``,markdown:e}:{docFrontmatterText:jp(t),markdown:n}}function t0(e){let t=e.split(`
|
|
314
|
+
`);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=Q1(n.join(`
|
|
315
|
+
`))[Z1];return{identity:typeof i==`object`&&i&&!Array.isArray(i)?i:{},docFrontmatterText:t.slice(r).join(`
|
|
316
|
+
`).replace(/\n+$/,``)}}function n0(e){let t=e.charCodeAt(0)===65279?e.slice(1):e,{frontmatter:n,body:r}=kp(t);if(n===``)return{identity:{},starterContent:t};let i=jp(n),a=t0(i);if(a)return{identity:a.identity,starterContent:$1(a.docFrontmatterText,r)};let{frontmatter:o}=kp(r);if(o!==``)return{identity:Q1(i),starterContent:r};let s=Q1(i);return typeof s.title==`string`?{identity:s,starterContent:r}:{identity:{},starterContent:$1(i,r)}}function r0(e,t){let{docFrontmatterText:n,markdown:r}=e0(t),i={};for(let[t,n]of Object.entries(e))n!==void 0&&(i[t]=n);let a=(0,Ce.stringify)({[Z1]:i});return`---\n${n.trim()===``?a:`${a}${n}\n`}---\n${r}`}function i0(e){return n0(e).starterContent}const a0=`(agent thread)`;function o0(){let e=!1,t=``,n=0;return r=>{let i=s0(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 s0(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 c0=[`#D97757`,`#1B1912`,`#F9F3E9`,`#7A9DFF`,`#8534F3`,`#9663F0`,`#727CF3`],l0={claude:`#D97757`,cursor:`#1B1912`,windsurf:`#0B100F`,openai:`#7A9DFF`,github:`#8534F3`,cline:`#9663F0`,bot:`#727CF3`};function u0(e,t=c0){let n=0;for(let t of e)n=(n<<5)-n+t.charCodeAt(0)|0;return t[Math.abs(n)%t.length]}const d0={"claude-code":`claude`,"claude-ai":`claude`,cursor:`cursor`,"cursor-vscode":`cursor`,cascade:`windsurf`,codex:`openai`,"codex-mcp-client":`openai`,copilot:`github`,cline:`cline`};function f0(e){return e?d0[e]||(e.startsWith(`local-agent-mode-`)?`claude`:`bot`):`bot`}const p0={claude:`Claude`,cursor:`Cursor`,windsurf:`Windsurf`,openai:`Codex`,github:`Copilot`,cline:`Cline`};function m0(e){let t=e?.trim();return t?p0[f0(t)]??t:`Agent`}function h0(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 g0=/^[a-zA-Z][a-zA-Z\d+\-.]*:/;function _0(e){let t=(e.split(/[?#]/)[0]??e).match(/\.([a-z0-9]+)$/i);return t?(t[1]??``).toLowerCase():null}function v0(e){let t=e.trim();return g0.test(t)||t.startsWith(`//`)}function y0(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(v0(n))return{kind:`external`,url:n};let r=h0(n,t);if(r)return{kind:`doc`,docName:r.docName,anchor:r.anchor};let i=_0(n);return i&&i!==`md`&&i!==`mdx`?{kind:`asset`,url:n,ext:i}:null}function b0(e,t){let n=e.trim();if(!n)return null;if(v0(n))return{kind:`external`,url:t?`${n}#${t}`:n};let r=_0(n);return r&&r!==`md`&&r!==`mdx`?{kind:`asset`,url:n,ext:r}:{kind:`doc`,docName:n,anchor:t?.trim()||null}}function x0(e,t){let n=e.trim();if(!n||g0.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 S0(e){let t=e;return t.startsWith(`./`)&&(t=t.slice(2)),t.startsWith(`/`)&&(t=t.slice(1)),t}function C0(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}function w0(e){let t=e.lastIndexOf(`/`);return t===-1?``:e.slice(0,t)}function T0(e){return e.split(`/`).filter(e=>e!==``)}function E0(e,t){let n=w0(t);return e===``||n===e?!0:n.startsWith(`${e}/`)}function D0(e,t){let n=w0(t);if(e===n)return 0;let r=e===``?n:n.slice(e.length+1);return r===``?0:T0(r).length}function O0(e,t){let n=T0(e),r=T0(t),i=0;for(;i<n.length&&i<r.length&&n[i]===r[i];)i++;return n.length-i+(r.length-i)}function k0(){let e=new Map;function t(t){let n=S0(t);if(n===``)return;let r=C0(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=S0(t),r=C0(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=w0(S0(n)),o=[],s=[];for(let e of i)E0(a,e)?o.push(e):s.push(e);return o.length>0?(e=>{let t=e[0],n=D0(a,t);for(let r=1;r<e.length;r++){let i=e[r],o=D0(a,i);(o<n||o===n&&i<t)&&(t=i,n=o)}return t})(o):(e=>{let t=e[0],n=O0(a,w0(t));for(let r=1;r<e.length;r++){let i=e[r],o=O0(a,w0(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 A0(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 j0(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}export{oY as $,ht as $i,EK as $n,PW as $r,Fq as $t,yX as A,Te as Aa,py as Ai,$K as An,UG as Ar,Xq as At,$Y as B,_e as Ba,$v as Bi,eq as Bn,dG as Br,Wq as Bt,Y1 as C,De as Ca,Hy as Ci,lq as Cn,QG as Cr,CJ as Ct,v1 as D,Ne as Da,My as Di,BK as Dn,FG as Dr,cJ as Dt,I1 as E,Me as Ea,Ay as Ei,UK as En,LG as Er,lJ as Et,lX as F,Ve as Fa,Py as Fi,KK as Fn,DG as Fr,iJ as Ft,wY as G,Hv as Gi,NK as Gn,sG as Gr,pJ as Gt,QY as H,ge as Ha,Yv as Hi,SK as Hn,CG as Hr,hJ as Ht,cX as I,Le as Ia,Ey as Ii,XK as In,mG as Ir,Qq as It,fY as J,jp as Ji,OK as Jn,nG as Jr,Zq as Jt,xY as K,Ap as Ki,jK as Kn,uG as Kr,eJ as Kt,sX as L,ze as La,by as Li,ZK as Ln,OG as Lr,$q as Lt,mX as M,Je as Ma,hy as Mi,GK as Mn,MG as Mr,TJ as Mt,uX as N,Ue as Na,_y as Ni,zK as Nn,xG as Nr,dJ as Nt,hX as O,Pe as Oa,ay as Oi,VK as On,PG as Or,oJ as Ot,oX as P,Ke as Pa,Ny as Pi,JK as Pn,pG as Pr,rJ as Pt,sY as Q,gt as Qi,TK as Qn,FW as Qr,Vq as Qt,aX as R,We as Ra,Dy as Ri,nq as Rn,fG as Rr,_J as Rt,X1 as S,Ae as Sa,Uy as Si,cq as Sn,JG as Sr,yJ as St,f1 as T,Oe as Ta,ky as Ti,HK as Tn,RG as Tr,nJ as Tt,GY as U,he as Ua,Jv as Ui,CK as Un,kG as Ur,gJ as Ut,KY as V,ve as Va,Zv as Vi,tq as Vn,TG as Vr,mJ as Vt,WY as W,Kv as Wi,FK as Wn,AG as Wr,fJ as Wt,uY as X,ci as Xi,IK as Xn,VW as Xr,Aq as Xt,dY as Y,bd as Yi,PK as Yn,rG as Yr,Jq as Yt,cY as Z,A as Zi,DK as Zn,zW as Zr,Oq as Zt,n0 as _,Ze as _a,Wy as _i,hq as _n,nK as _r,EJ as _t,b0 as a,st as aa,OW as ai,Rq as an,gK as ar,UJ as at,G1 as b,Ee as ba,Iy as bi,fq as bn,$G as br,Nq as bt,l0 as c,ot as ca,vW as ci,wq as cn,mK as cr,LJ as ct,f0 as d,at as da,oB as di,Dq as dn,oK as dr,FJ as dt,pt as ea,MW as ei,zq as en,wK as er,QJ as et,o0 as f,et as fa,aB as fi,xq as fn,iK as fr,MJ as ft,i0 as g,nt as ga,Ry as gi,bq as gn,tK as gr,OJ as gt,r0 as h,rt as ha,gM as hi,_q as hn,eK as hr,kJ as ht,y0 as i,dt as ia,EW as ii,Lq as in,pK as ir,ZJ as it,bX as j,Fe as ja,fy as ji,WK as jn,jG as jr,uJ as jt,vX as k,Ie as ka,cy as ki,QK as kn,BG as kr,sJ as kt,u0 as l,Qe as la,_W as li,Tq as ln,cK as lr,IJ as lt,Z1 as m,tt as ma,CN as mi,gq as mn,sK as mr,AJ as mt,j0 as n,ft as na,DW as ni,Hq as nn,dK as nr,qJ as nt,x0 as o,ct as oa,kW as oi,Iq as on,_K as or,HJ as ot,a0 as p,it as pa,$I as pi,Cq as pn,rK as pr,DJ as pt,hY as q,kp as qi,kK as qn,qW as qr,tJ as qt,k0 as r,ut as ra,bW as ri,Uq as rn,fK as rr,JJ as rt,h0 as s,lt as sa,SW as si,qq as sn,hK as sr,NJ as st,A0 as t,mt as ta,NW as ti,Bq as tn,vK as tr,tY as tt,m0 as u,$e as ua,vB as ui,Eq as un,uK as ur,PJ as ut,H1 as v,Xe as va,Ly as vi,mq as vn,XG as vr,jq as vt,m1 as w,ke as wa,By as wi,uq as wn,KG as wr,SJ as wt,J1 as x,je as xa,Gy as xi,pq as xn,qG as xr,Gq as xt,U1 as y,Ye as ya,Vy as yi,dq as yn,ZG as yr,Mq as yt,iX as z,we as za,vy as zi,rq as zn,EG as zr,vJ as zt};
|
|
317
|
+
//# sourceMappingURL=src-Cus5RnL8.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{o as e}from"./chunk-DTipWd-i.mjs";import{F as t,
|
|
1
|
+
import{o as e}from"./chunk-DTipWd-i.mjs";import{F as t,I as n,sa as r}from"./src-Cus5RnL8.mjs";import{Er as i,Nr as a,it as o,ma as s,nt as c,rn as l,rt as u,tt as d}from"./src-CZe5oBcp.mjs";import{U as f}from"./sleep-DcENuR74.mjs";import{O as p,P as m}from"./fs-traced-BISd_YTv.mjs";import{b as h,u as g,v as _,y as v}from"./server-lock-0xVm4FnC.mjs";import{t as y}from"./yazl-DZr4PyKA.mjs";import{C as b,d as x,i as S,v as ee,y as C}from"./write-project-skill-Ct6JxGJ6.mjs";import"./acp-harness-probe-DzzmnVA9.mjs";import{E as te,S as ne,T as re,_ as w,b as T,o as ie,v as ae,w as E}from"./init-Du1ej_je.mjs";import{n as oe}from"./constants-DMEiZNZI.mjs";import{t as D}from"./is-object-DKopTkoU.mjs";import"./loader-BahUa-3b.mjs";import{c as O}from"./colors-BslXS0bZ.mjs";import"./preview-BYw1WeBG.mjs";import{execSync as se,spawnSync as ce}from"node:child_process";import{basename as k,dirname as A,isAbsolute as j,join as M,relative as le,resolve as N,sep as ue}from"node:path";import{cpSync as de,createWriteStream as fe,existsSync as P,lstatSync as pe,mkdirSync as F,mkdtempSync as me,readFileSync as I,readdirSync as he,readlinkSync as ge,rmSync as _e,statSync as ve,writeFileSync as L}from"node:fs";import{arch as ye,freemem as be,homedir as xe,hostname as Se,platform as Ce,release as we,tmpdir as Te,totalmem as Ee,type as De,uptime as Oe}from"node:os";import{realpath as R}from"node:fs/promises";import{createHash as z}from"node:crypto";const ke=[{name:`macos-home-path`,regex:/\/Users\/[^/]+\//g,replacement:`~/`},{name:`linux-home-path`,regex:/\/home\/[^/]+\//g,replacement:`~/`},{name:`github-pat`,regex:/\b(ghp_|gho_|ghu_|ghs_|ghr_)[A-Za-z0-9]{36,}\b/g,replacement:`[REDACTED-GH-PAT]`},{name:`aws-access-key`,regex:/\b(AKIA|ASIA|ABIA)[A-Z2-7]{16}\b/g,replacement:`[REDACTED-AWS-KEY]`},{name:`anthropic-key`,regex:/\bsk-ant-api03-[A-Za-z0-9_-]{20,}\b/g,replacement:`[REDACTED-ANTHROPIC]`},{name:`openai-key`,regex:/\bsk-[A-Za-z0-9]{20,}\b/g,replacement:`[REDACTED-OPENAI]`},{name:`bearer-token`,regex:/([Aa]uthorization:\s*[Bb]earer\s+)\S+/g,replacement:`$1[REDACTED]`},{name:`jwt`,regex:/eyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g,replacement:`[REDACTED-JWT]`},{name:`url-credentials`,regex:/:\/\/[^/\s:@]+:[^/\s:@]+@/g,replacement:`://[REDACTED]@`}],Ae=ke.map(e=>e.name);function B(e){let t=new Set,n=0;return{redacted:e.split(`
|
|
2
2
|
`).map(e=>{let r=e;for(let{name:e,regex:i,replacement:a}of ke)i.lastIndex=0,i.test(r)&&(t.add(e),n++,i.lastIndex=0,r=r.replace(i,a));return r}).join(`
|
|
3
|
-
`),patterns:[...t],lineCount:n}}function je(){return M(xe(),`.ok`,`bug-reports`)}function Me(e=new Date){let t=e.toISOString().replace(/[:.]/g,`-`);return M(je(),`${t}-bugreport.zip`)}function Ne(e,t){let n=M(e,`.ok`,`config.yml`);if(P(n))try{let e=I(n,`utf8`).match(/^\s*name:\s*['"]?(.+?)['"]?\s*$/m);if(e?.[1])return e[1]}catch(e){t?.warn({configPath:n,err:e instanceof Error?e.message:String(e)},`bug-report: failed to read .ok/config.yml for project slug; using path-hash fallback`)}return P(M(e,`.ok`))?z(`sha256`).update(N(e)).digest(`hex`).slice(0,12):null}function Pe(){let e={timestamp:new Date().toISOString(),platform:Ce(),osType:De(),osRelease:we(),hostname:`[redacted]`,uptime:Oe(),freeMem:be(),totalMem:Ee(),nodeVersion:process.version,bunVersion:process.versions.bun??null,v8Version:process.versions.v8??null,pid:process.pid};try{e.macosVersion=se(`sw_vers -productVersion 2>/dev/null`,a({encoding:`utf8`})).trim()}catch{}try{let t=M(__dirname,`..`,`..`,`package.json`);P(t)&&(e.okVersion=JSON.parse(I(t,`utf8`)).version)}catch{}return e}function Fe(e,t){if(!P(t))return{files:[]};let n=he(t).filter(e=>e.endsWith(`.log`)||/\.log\.\d+$/.test(e)).map(e=>M(t,e));if(e&&n.length>0){let t=n.filter(t=>{try{return I(t,`utf8`).includes(`"project":"${e}"`)}catch{return!0}});t.length>0&&(n=t)}return{files:n}}function Ie(e){let
|
|
3
|
+
`),patterns:[...t],lineCount:n}}function je(){return M(xe(),`.ok`,`bug-reports`)}function Me(e=new Date){let t=e.toISOString().replace(/[:.]/g,`-`);return M(je(),`${t}-bugreport.zip`)}function Ne(e,t){let n=M(e,`.ok`,`config.yml`);if(P(n))try{let e=I(n,`utf8`).match(/^\s*name:\s*['"]?(.+?)['"]?\s*$/m);if(e?.[1])return e[1]}catch(e){t?.warn({configPath:n,err:e instanceof Error?e.message:String(e)},`bug-report: failed to read .ok/config.yml for project slug; using path-hash fallback`)}return P(M(e,`.ok`))?z(`sha256`).update(N(e)).digest(`hex`).slice(0,12):null}function Pe(){let e={timestamp:new Date().toISOString(),platform:Ce(),osType:De(),osRelease:we(),hostname:`[redacted]`,uptime:Oe(),freeMem:be(),totalMem:Ee(),nodeVersion:process.version,bunVersion:process.versions.bun??null,v8Version:process.versions.v8??null,pid:process.pid};try{e.macosVersion=se(`sw_vers -productVersion 2>/dev/null`,a({encoding:`utf8`})).trim()}catch{}try{let t=M(__dirname,`..`,`..`,`package.json`);P(t)&&(e.okVersion=JSON.parse(I(t,`utf8`)).version)}catch{}return e}function Fe(e,t){if(!P(t))return{files:[]};let n=he(t).filter(e=>e.endsWith(`.log`)||/\.log\.\d+$/.test(e)).map(e=>M(t,e));if(e&&n.length>0){let t=n.filter(t=>{try{return I(t,`utf8`).includes(`"project":"${e}"`)}catch{return!0}});t.length>0&&(n=t)}return{files:n}}function Ie(e){let n=M(e,`.ok`,`local`);return P(n)?{files:[`server.lock`,`last-spawn-error.log`,t].map(e=>M(n,e)).filter(e=>P(e))}:{files:[]}}function Le(e){let t=M(e,`.ok`,`local`,`logs`);return P(t)?{files:[`server-current.jsonl`,`server-prev.jsonl`].map(e=>M(t,e)).filter(e=>P(e))}:{files:[]}}function Re(e){if(e.redact){let{redacted:t,patterns:n,lineCount:r}=B(e.content);e.zipfile.addBuffer(Buffer.from(t,`utf8`),e.name),e.bundleFiles.push(e.name),n.length>0&&e.redactions.push({file:e.name,lineCount:r,patterns:n})}else e.zipfile.addBuffer(Buffer.from(e.content,`utf8`),e.name),e.bundleFiles.push(e.name)}function V(e){for(let t of e.files)try{Re({zipfile:e.zipfile,name:`${e.prefix}/${k(t)}`,content:I(t,`utf8`),redact:e.redact,bundleFiles:e.bundleFiles,redactions:e.redactions})}catch(n){e.logger?.warn({file:t,prefix:e.prefix,err:n instanceof Error?n.message:String(n)},`bug-report: skipped unreadable file`)}}async function ze(t){let{redact:n,outputPath:r,logger:i}=t,a=t.userLogsDir??M(xe(),`.ok`,`logs`),o=t.projectDir?Ne(t.projectDir,i):null;F(A(r),{recursive:!0}),i?.info({projectSlug:o},`gathering diagnostic data`);let s=Pe();s.desktop=t.desktop??null;let{files:c}=Fe(o,a),{files:l}=t.projectDir?Ie(t.projectDir):{files:[]},{files:u}=t.projectDir?Le(t.projectDir):{files:[]};i?.info({logFileCount:c.length,lockFileCount:l.length,localSinkFileCount:u.length},`files collected`);let d=[],f=[],{ZipFile:p}=await import(`./yazl-jVENrf5i.mjs`).then(t=>e(t.default,1)),m=new p;V({zipfile:m,files:c,prefix:`logs`,redact:n,bundleFiles:f,redactions:d,logger:i}),V({zipfile:m,files:l,prefix:`lockdir`,redact:n,bundleFiles:f,redactions:d,logger:i}),V({zipfile:m,files:u,prefix:`local-logs`,redact:n,bundleFiles:f,redactions:d,logger:i});for(let e of t.extraFiles??[])try{let t=I(e.sourcePath),n=`extra/${e.zipName??k(e.sourcePath)}`;m.addBuffer(t,n),f.push(n)}catch(t){i?.warn({sourcePath:e.sourcePath,err:t},`extra file unreadable; omitted from bundle`)}t.note&&Re({zipfile:m,name:`note.txt`,content:t.note,redact:n,bundleFiles:f,redactions:d});let h=JSON.stringify(s,null,2);m.addBuffer(Buffer.from(h,`utf8`),`sysinfo.json`),f.push(`sysinfo.json`);let g={generatedAt:new Date().toISOString(),disciplineVersion:`1.0.0`,projectSlug:o,files:f,redactions:d,sysinfo:s};m.addBuffer(Buffer.from(JSON.stringify(g,null,2),`utf8`),`MANIFEST.json`);let _=d.reduce((e,t)=>e+t.lineCount,0),v=[`# Bug Report Bundle`,``,`Generated: ${g.generatedAt}`,`Project: ${o??`(unscoped)`}`,`Discipline version: ${g.disciplineVersion}`,``,`## Contents`,``,...f.map(e=>`- ${e}`),``,`## Privacy`,``,...n?[`This bundle was auto-redacted before packaging.`,`Patterns checked: ${Ae.join(`, `)}`,_>0?`${_} line(s) were scrubbed across ${d.length} file(s).`:`No redactions were needed.`,`See MANIFEST.json for the full redaction audit report.`,``,`This bundle is safe to attach to a GitHub issue.`]:[`Redaction was disabled for this bundle; file contents are unmodified.`]].join(`
|
|
4
4
|
`);m.addBuffer(Buffer.from(v,`utf8`),`README.md`),m.end();let y=fe(r);return m.outputStream.pipe(y),await new Promise((e,t)=>{y.on(`close`,e),y.on(`error`,t)}),i?.info({bundlePath:r,fileCount:f.length,redactionCount:_},`bundle written`),{zipPath:r,summary:{projectSlug:o,files:f,redactions:d,redactedLineCount:_,generatedAt:g.generatedAt}}}var H=f(),Be=e(y(),1);const Ve=new Set([`doc.name`,`currentDoc`]);function He(e){return`doc:${z(`sha256`).update(e).digest(`hex`).slice(0,8)}`}function Ue(e,t,n){let r=e.docNameMap[n];if(r===void 0){e.docNameMap[n]=t;return}if(r===t)return;let i=e.docNameCollisions[n];i?i.includes(t)||i.push(t):e.docNameCollisions[n]=[t]}function We(e,t){let n=t.originalToHashed.get(e);if(n!==void 0)return n;let r=He(e);return t.originalToHashed.set(e,r),Ue(t,e,r),r}function U(e,t){return t.length===0||!e.includes(t)?e:e.split(t).join(`<CONTENT_DIR>`)}function W(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function G(e,t){if(typeof e==`string`)return U(e,t.contentDir);if(Array.isArray(e))return e.map(e=>G(e,t));if(!W(e))return e;let n=typeof e.key==`string`&&Ve.has(e.key)&&W(e.value)&&typeof e.value.stringValue==`string`?e.value.stringValue:null,r={};for(let[i,a]of Object.entries(e))if(n!==null&&i===`value`&&W(a)){let e=We(n,t);r[i]={...a,stringValue:e}}else Ve.has(i)&&typeof a==`string`?r[i]=We(a,t):r[i]=G(a,t);return r}function Ge(e,t){if(t.originalToHashed.size===0)return e;let n=Array.from(t.originalToHashed.entries()).sort(([e],[t])=>t.length-e.length),r=e;for(let[e,t]of n)e.length!==0&&r.includes(e)&&(r=r.split(e).join(t));return r}function Ke(e,t){let n=I(e,`utf-8`);if(n.length===0)return;let r=n.endsWith(`
|
|
5
5
|
`),i=n.split(`
|
|
6
6
|
`),a=[];for(let e=0;e<i.length;e++){let n=i[e]??``;if(!(e===i.length-1&&n===``)){if(n.length===0){a.push(``);continue}try{let e=G(JSON.parse(n),t);a.push(JSON.stringify(e))}catch{a.push(n)}}}L(e,r?`${a.join(`
|
|
@@ -8,7 +8,7 @@ import{o as e}from"./chunk-DTipWd-i.mjs";import{F as t,P as n,oa as r}from"./src
|
|
|
8
8
|
`))}function qe(e,t){let n=I(e,`utf-8`);if(n.trim().length!==0)try{let r=G(JSON.parse(n),t),i=n.endsWith(`
|
|
9
9
|
`)?`
|
|
10
10
|
`:``;L(e,`${JSON.stringify(r,null,2)}${i}`)}catch{let r=Ge(U(n,t.contentDir),t);r!==n&&L(e,r)}}function Je(e,t){let n=I(e,`utf-8`),r=U(n,t.contentDir);r!==n&&L(e,r)}function Ye(e){try{return he(e,{withFileTypes:!0}).filter(e=>e.isFile()).map(t=>M(e,t.name))}catch{return[]}}const Xe=new Set([`agent-presence.json`,`agent-effects.json`,`runtime.json`]);function Ze(e){let t={contentDir:e.contentDir,docNameMap:{},originalToHashed:new Map,docNameCollisions:{}};for(let n of[`telemetry`,`logs`,`process`])for(let r of Ye(M(e.stagingDir,n)))r.endsWith(`.jsonl`)?Ke(r,t):r.endsWith(`.json`)?qe(r,t):Je(r,t);for(let n of Ye(M(e.stagingDir,`state`))){let e=k(n);n.endsWith(`.jsonl`)?Ke(n,t):Xe.has(e)?qe(n,t):Je(n,t)}return{docNameMap:t.docNameMap,docNameCollisions:t.docNameCollisions}}const Qe=[`.ok`,`local`,`telemetry`],$e=[`.ok`,`local`,`logs`],et=`spans-current.jsonl`,tt=`spans-prev.jsonl`,nt=`server-current.jsonl`,rt=`server-prev.jsonl`;function it(e){return M(e,...Qe,et)}function at(e){return M(e,...Qe,tt)}function ot(e){return M(e,...$e,nt)}function st(e){return M(e,...$e,rt)}const ct=1e3;async function lt(e){try{let t=await fetch(`http://127.0.0.1:${e}/api/metrics/agent-presence`,{signal:AbortSignal.timeout(ct)});return t.ok?await t.text():null}catch{return null}}async function ut(e){try{let t=await fetch(`http://127.0.0.1:${e}/api/metrics/agent-effects`,{signal:AbortSignal.timeout(ct)});return t.ok?await t.text():null}catch{return null}}async function dt(e){try{let t=await fetch(`http://127.0.0.1:${e}/api/metrics/watcher-recent`,{signal:AbortSignal.timeout(ct)});return t.ok?await t.text():null}catch{return null}}function ft(e){try{let t=JSON.parse(e);if(typeof t!=`object`||!t)return null;let n=t.decisions;return Array.isArray(n)?n.length===0?``:`${n.map(e=>JSON.stringify(e)).join(`
|
|
11
|
-
`)}\n`:null}catch{return null}}function pt(e){let t=M(e,`.git`,`ok`);if(!P(t))return null;let n=ce(`git`,[`-C`,t,`log`,`--oneline`,`-50`],a({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function mt(e){let t=M(e,`.git`,`ok`);if(!P(t))return null;let n=ce(`git`,[`-C`,t,`for-each-ref`,`--sort=-creatordate`,`--count=50`,`--format=%(refname)%09%(creatordate:iso-strict)%09%(contents:subject)`,`refs/checkpoints/`],a({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function ht(){let e=process.env.OK_DESKTOP_VERSION,t=process.env.OK_DESKTOP_PACKAGED,n=process.env.OK_DESKTOP_CHANNEL;return e===void 0||t===void 0||n===void 0?null:{electronVersion:e,packaged:t===`1`||t.toLowerCase()===`true`,channel:n}}function gt(){return{nodeVersion:process.version,platform:Ce(),arch:ye()}}function _t(){return process.env.OTEL_SDK_DISABLED===`false`}function K(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function vt(e){if(!P(e))return{};let t;try{t=(0,H.parse)(I(e,`utf-8`))}catch(t){return console.warn(`[ok diagnose bundle] failed to parse ${e} for manifest config; manifest will report schema defaults. Reason: ${t instanceof Error?t.message:String(t)}`),{}}if(!K(t))return{};let n=t.telemetry;if(!K(n))return{};let r=n.localSink;return K(r)?r:{}}function yt(e){return typeof e==`boolean`?e:void 0}function bt(e){return typeof e==`number`&&Number.isFinite(e)&&e>0?e:void 0}function q(e){if(K(e))return bt(e.maxBytes)}function xt(e){let t=vt(p(`project`,e)),n=vt(p(`project-local`,e));return{enabled:yt(n.enabled)??yt(t.enabled)??!0,spansMaxBytes:q(n.spans)??q(t.spans)??52428800,logsMaxBytes:q(n.logs)??q(t.logs)??26214400}}function St(e){return z(`sha256`).update(e).digest(`hex`)}function Ct(e){let t=I(e),n=0;for(let e=0;e<t.length;e++)t[e]===10&&n++;return n}function wt(e){let t=I(e,`utf-8`),n=`"doc.name"`,r=0,i=t.indexOf(n);for(;i!==-1;)r++,i=t.indexOf(n,i+10);return r}function J(e,t){return P(e)?(F(A(t),{recursive:!0}),de(e,t),!0):!1}function Y(e){let t=[],n=e=>{let r=he(e,{withFileTypes:!0});for(let i of r){let r=M(e,i.name);i.isDirectory()?n(r):i.isFile()&&t.push(r)}};return n(e),t.sort()}const Tt=new Set([`.jsonl`]);function Et(e){let t=e.lastIndexOf(`.`);return t===-1?!1:Tt.has(e.slice(t))}const Dt=new Set([`.jsonl`,`.json`,`.txt`,`.log`,`.lock`]);function Ot(e){let t=e.lastIndexOf(`.`);return t===-1?!1:Dt.has(e.slice(t))}function kt(e){let t=[];for(let n of Y(e)){let r=At(e,n);if(!Ot(r))continue;let{redacted:i,patterns:a,lineCount:o}=B(I(n,`utf-8`));a.length!==0&&(L(n,i),t.push({file:r,lineCount:o,patterns:a}))}return{redactions:t,redactedLineCount:t.reduce((e,t)=>e+t.lineCount,0)}}function At(e,t){return le(e,t).split(ue).join(`/`)}async function jt(e){let r=N(e.contentDir),i=N(e.projectDir??e.contentDir),a=e.deps??{},o=a.fetchAgentPresence??lt,s=a.fetchAgentEffects??ut,c=a.fetchWatcherRecent??dt,l=a.readShadowHead??pt,u=a.readCheckpointRefs??mt,d=a.now??(()=>new Date),f=a.okVersion??(()=>oe),p=a.readDesktopEnv??ht,m=a.readRuntime??gt,h=a.isOtlpPushEnabled??_t,g=me(M(Te(),`ok-bundle-`));try{F(M(g,`telemetry`),{recursive:!0}),F(M(g,`logs`),{recursive:!0}),F(M(g,`state`),{recursive:!0}),J(it(i),M(g,`telemetry`,et)),J(at(i),M(g,`telemetry`,tt)),J(ot(i),M(g,`logs`,nt)),J(st(i),M(g,`logs`,rt));let _=M(i,`.ok`,`local`),v=M(_,`server.lock`),y=`not-running`,b=`no server.lock`,x=null;if(P(v)){J(v,M(g,`state`,`server.lock`));try{let e=I(v,`utf-8`),t=JSON.parse(e);typeof t.port==`number`?x=t.port:b=`lock present but no port`}catch{b=`lock present but unparseable`}}if(x!==null){let e=await o(x);e===null?b=`agent-presence endpoint at :${x} unreachable`:(L(M(g,`state`,`agent-presence.json`),e),y=`running`,b=``);let t=await s(x);t!==null&&L(M(g,`state`,`agent-effects.json`),t);let n=await c(x);if(n!==null){let e=ft(n);e!==null&&L(M(g,`state`,`watcher-recent.jsonl`),e)}}let S=l(r);S!==null&&L(M(g,`state`,`shadow-head.txt`),S);let ee=u(r);ee!==null&&L(M(g,`state`,`checkpoint-refs.txt`),ee),J(M(_,`last-spawn-error.log`),M(g,`state`,`last-spawn-error.log`)),J(M(_,
|
|
11
|
+
`)}\n`:null}catch{return null}}function pt(e){let t=M(e,`.git`,`ok`);if(!P(t))return null;let n=ce(`git`,[`-C`,t,`log`,`--oneline`,`-50`],a({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function mt(e){let t=M(e,`.git`,`ok`);if(!P(t))return null;let n=ce(`git`,[`-C`,t,`for-each-ref`,`--sort=-creatordate`,`--count=50`,`--format=%(refname)%09%(creatordate:iso-strict)%09%(contents:subject)`,`refs/checkpoints/`],a({encoding:`utf-8`,timeout:2e3}));return n.error||n.status!==0?null:n.stdout??``}function ht(){let e=process.env.OK_DESKTOP_VERSION,t=process.env.OK_DESKTOP_PACKAGED,n=process.env.OK_DESKTOP_CHANNEL;return e===void 0||t===void 0||n===void 0?null:{electronVersion:e,packaged:t===`1`||t.toLowerCase()===`true`,channel:n}}function gt(){return{nodeVersion:process.version,platform:Ce(),arch:ye()}}function _t(){return process.env.OTEL_SDK_DISABLED===`false`}function K(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function vt(e){if(!P(e))return{};let t;try{t=(0,H.parse)(I(e,`utf-8`))}catch(t){return console.warn(`[ok diagnose bundle] failed to parse ${e} for manifest config; manifest will report schema defaults. Reason: ${t instanceof Error?t.message:String(t)}`),{}}if(!K(t))return{};let n=t.telemetry;if(!K(n))return{};let r=n.localSink;return K(r)?r:{}}function yt(e){return typeof e==`boolean`?e:void 0}function bt(e){return typeof e==`number`&&Number.isFinite(e)&&e>0?e:void 0}function q(e){if(K(e))return bt(e.maxBytes)}function xt(e){let t=vt(p(`project`,e)),n=vt(p(`project-local`,e));return{enabled:yt(n.enabled)??yt(t.enabled)??!0,spansMaxBytes:q(n.spans)??q(t.spans)??52428800,logsMaxBytes:q(n.logs)??q(t.logs)??26214400}}function St(e){return z(`sha256`).update(e).digest(`hex`)}function Ct(e){let t=I(e),n=0;for(let e=0;e<t.length;e++)t[e]===10&&n++;return n}function wt(e){let t=I(e,`utf-8`),n=`"doc.name"`,r=0,i=t.indexOf(n);for(;i!==-1;)r++,i=t.indexOf(n,i+10);return r}function J(e,t){return P(e)?(F(A(t),{recursive:!0}),de(e,t),!0):!1}function Y(e){let t=[],n=e=>{let r=he(e,{withFileTypes:!0});for(let i of r){let r=M(e,i.name);i.isDirectory()?n(r):i.isFile()&&t.push(r)}};return n(e),t.sort()}const Tt=new Set([`.jsonl`]);function Et(e){let t=e.lastIndexOf(`.`);return t===-1?!1:Tt.has(e.slice(t))}const Dt=new Set([`.jsonl`,`.json`,`.txt`,`.log`,`.lock`]);function Ot(e){let t=e.lastIndexOf(`.`);return t===-1?!1:Dt.has(e.slice(t))}function kt(e){let t=[];for(let n of Y(e)){let r=At(e,n);if(!Ot(r))continue;let{redacted:i,patterns:a,lineCount:o}=B(I(n,`utf-8`));a.length!==0&&(L(n,i),t.push({file:r,lineCount:o,patterns:a}))}return{redactions:t,redactedLineCount:t.reduce((e,t)=>e+t.lineCount,0)}}function At(e,t){return le(e,t).split(ue).join(`/`)}async function jt(e){let r=N(e.contentDir),i=N(e.projectDir??e.contentDir),a=e.deps??{},o=a.fetchAgentPresence??lt,s=a.fetchAgentEffects??ut,c=a.fetchWatcherRecent??dt,l=a.readShadowHead??pt,u=a.readCheckpointRefs??mt,d=a.now??(()=>new Date),f=a.okVersion??(()=>oe),p=a.readDesktopEnv??ht,m=a.readRuntime??gt,h=a.isOtlpPushEnabled??_t,g=me(M(Te(),`ok-bundle-`));try{F(M(g,`telemetry`),{recursive:!0}),F(M(g,`logs`),{recursive:!0}),F(M(g,`state`),{recursive:!0}),J(it(i),M(g,`telemetry`,et)),J(at(i),M(g,`telemetry`,tt)),J(ot(i),M(g,`logs`,nt)),J(st(i),M(g,`logs`,rt));let _=M(i,`.ok`,`local`),v=M(_,`server.lock`),y=`not-running`,b=`no server.lock`,x=null;if(P(v)){J(v,M(g,`state`,`server.lock`));try{let e=I(v,`utf-8`),t=JSON.parse(e);typeof t.port==`number`?x=t.port:b=`lock present but no port`}catch{b=`lock present but unparseable`}}if(x!==null){let e=await o(x);e===null?b=`agent-presence endpoint at :${x} unreachable`:(L(M(g,`state`,`agent-presence.json`),e),y=`running`,b=``);let t=await s(x);t!==null&&L(M(g,`state`,`agent-effects.json`),t);let n=await c(x);if(n!==null){let e=ft(n);e!==null&&L(M(g,`state`,`watcher-recent.jsonl`),e)}}let S=l(r);S!==null&&L(M(g,`state`,`shadow-head.txt`),S);let ee=u(r);ee!==null&&L(M(g,`state`,`checkpoint-refs.txt`),ee),J(M(_,`last-spawn-error.log`),M(g,`state`,`last-spawn-error.log`)),J(M(_,n),M(g,`state`,n)),J(M(_,t),M(g,`state`,t));let C=m(),te=p(),ne={ok:{version:f(),nodeVersion:C.nodeVersion,platform:C.platform,arch:C.arch},host:{desktop:te}};L(M(g,`state`,`runtime.json`),`${JSON.stringify(ne,null,2)}\n`);let re=y===`running`?`running
|
|
12
12
|
`:`not-running (${b})\n`;if(L(M(g,`state`,`server-status.txt`),re),e.processDir&&P(e.processDir)){let t=M(g,`process`);F(t,{recursive:!0}),de(e.processDir,t,{recursive:!0})}let w=null;e.redact===!0&&(w=Ze({stagingDir:g,contentDir:r})),e.note&&L(M(g,`note.txt`),e.note);let T=null;e.scrubSecrets===!0&&(T=kt(g));for(let t of e.extraFiles??[])J(t.sourcePath,M(g,`extra`,t.zipName??k(t.sourcePath)))||a.logger?.warn({sourcePath:t.sourcePath},`extra file missing; omitted from bundle`);let ie=xt(i),ae=Y(g),E=[],oe=0,D=0;for(let e of ae){let t=At(g,e),n=ve(e).size,r=Et(t)?Ct(e):0;E.push({path:t,bytes:n,lines:r}),oe+=n,t.startsWith(`telemetry/`)&&Et(t)&&(D+=wt(e))}let O=w===null?{applied:!1,docNameMapSidecar:null}:Object.keys(w.docNameCollisions).length>0?{applied:!0,docNameMapSidecar:null,docNameCollisions:w.docNameCollisions}:{applied:!0,docNameMapSidecar:null};T!==null&&(O.secretScrub=T);let se={schemaVersion:1,createdAt:d().toISOString(),ok:{version:f(),nodeVersion:C.nodeVersion,platform:C.platform,arch:C.arch},host:{desktop:te},contentDir:{pathSha256:St(r),absolutePath:w===null?r:`<CONTENT_DIR>`},telemetry:{localSink:ie,otlpPushEnabled:h()},redaction:O,serverStatus:y,files:E};L(M(g,`manifest.json`),`${JSON.stringify(se,null,2)}\n`);let ce=ae.some(e=>{try{return I(e,`utf-8`).includes(r)}catch{return!1}}),A={totalBytes:oe,fileCount:E.length,docNameCount:D,contentDirVisible:ce,redacted:w!==null},j=!1;return{stagingDir:g,manifest:se,summary:A,redactionMapPayload:w===null?null:{docNameMap:w.docNameMap,docNameCollisions:w.docNameCollisions},cleanup:()=>{j||(j=!0,_e(g,{recursive:!0,force:!0}))}}}catch(e){throw _e(g,{recursive:!0,force:!0}),e}}async function Mt(e){let{collected:t,outputPath:n}=e,r=A(n);if(!P(r))throw Error(`ok diagnose bundle: parent directory does not exist: ${r}. Create it or pass --out with an existing parent.`);if(t.redactionMapPayload!==null){let e=`${k(n,`.zip`)}.docnames.json`,r={...t.manifest,redaction:{...t.manifest.redaction,applied:!0,docNameMapSidecar:e}};L(M(t.stagingDir,`manifest.json`),`${JSON.stringify(r,null,2)}\n`)}let i=new Be.ZipFile,a=Y(t.stagingDir);for(let e of a){let n=At(t.stagingDir,e);i.addFile(e,n)}i.end(),t.redactionMapPayload!==null&&L(M(r,`${k(n,`.zip`)}.docnames.json`),`${JSON.stringify({docNameMap:t.redactionMapPayload.docNameMap,docNameCollisions:t.redactionMapPayload.docNameCollisions},null,2)}\n`,{mode:384});let o=fe(n);return i.outputStream.pipe(o),await new Promise((e,t)=>{o.on(`close`,e),o.on(`error`,t),i.outputStream.on(`error`,t)}),n}function Nt(e,t){let n=M(e,`.ok`,`config.yml`);if(P(n))try{let t=(0,H.parse)(I(n,`utf-8`)),r=D(t)?t.content:void 0,i=D(r)?r.dir:void 0;if(typeof i==`string`&&i.length>0)return N(e,i)}catch(e){t?.warn({configPath:n,err:e instanceof Error?e.message:String(e)},`bug-report: failed to read .ok/config.yml; falling back to project root as content dir`)}return N(e)}async function Pt(e,t,n){let r=await jt({contentDir:Nt(t,e.logger),projectDir:t,redact:e.redact,scrubSecrets:e.redact,note:e.note,extraFiles:e.extraFiles,deps:{readDesktopEnv:n,logger:e.logger}});try{F(A(e.outputPath),{recursive:!0}),await Mt({collected:r,outputPath:e.outputPath});let n=r.manifest.redaction.secretScrub;return{zipPath:e.outputPath,summary:{level:`full`,systemWide:!1,projectSlug:Ne(t,e.logger),files:r.manifest.files.map(e=>e.path),redactions:n?.redactions??[],redactedLineCount:n?.redactedLineCount??0,generatedAt:r.manifest.createdAt}}}finally{r.cleanup()}}async function Ft(e){let{projectDir:t}=e,n=e.readDesktopEnv??ht;if(e.level===`full`&&t!==void 0)return Pt(e,t,n);let{zipPath:r,summary:i}=await ze({projectDir:t,redact:e.redact,outputPath:e.outputPath,userLogsDir:e.userLogsDir,logger:e.logger,note:e.note,extraFiles:e.extraFiles,desktop:n()});return{zipPath:r,summary:{level:e.level,systemWide:t===void 0,projectSlug:i.projectSlug,files:i.files,redactions:i.redactions,redactedLineCount:i.redactedLineCount,generatedAt:i.generatedAt}}}function X(e,t,n={}){let r=g(e,t);if(!P(r))return{status:`missing`,lockPath:r};let i;try{i=JSON.parse(I(r,`utf-8`))}catch{return{status:`corrupt`,lockPath:r}}if(!i||typeof i!=`object`||!h(i.pid))return{status:`corrupt`,lockPath:r};let a=i;if(!(n.isAlive??v)(a.pid))return{status:`dead-pid`,lockPath:r,lock:a};if(typeof a.machineId==`string`)return a.machineId===(n.machineId??_())?{status:`alive`,lockPath:r,lock:a}:{status:`foreign-host`,lockPath:r,lock:a};let o=n.host??Se();return a.hostname===o?{status:`alive`,lockPath:r,lock:a}:{status:`foreign-host`,lockPath:r,lock:a}}function It(e){return e.replace(/:\d+$/,``)}function Lt(e){let t=e.trim();if(!t)return null;{let e=/^https?:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`https`,hostname:It(e[1]),owner:e[2],name:e[3]}}{let e=/^ssh:\/\/(?:[\w.-]+@)?([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`ssh`,hostname:It(e[1]),owner:e[2],name:e[3]}}{let e=/^git:\/\/([^/?#]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:It(e[1]),owner:e[2],name:e[3]}}{let e=/^(?:[\w.-]+@)?([\w.-]+):([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?$/.exec(t);if(e?.[1].includes(`.`)||e&&t.startsWith(`git@`))return{protocol:`ssh`,hostname:e[1],owner:e[2],name:e[3]}}{let e=/^git:([\w.-]+)\/([\w.\-~%]+)\/([\w.\-~%]+?)(?:\.git)?\/?$/.exec(t);if(e)return{protocol:`git`,hostname:e[1],owner:e[2],name:e[3]}}if(!t.includes(`://`)&&!t.includes(`@`)&&!t.startsWith(`/`)){let e=/^([\w.-]+)\/([\w.\-~%]+?)(?:\.git)?$/.exec(t);if(e)return{protocol:`https`,hostname:`github.com`,owner:e[1],name:e[2]}}return null}function Rt(e){let t;try{t=new URL(e)}catch{return null}if(t.protocol!==`https:`)return null;let n=r(t.hostname);if(n===null)return null;let i=t.pathname.split(`/`).filter(e=>e.length>0);if(i.length<5||i[2]!==`blob`)return null;let a,o,s,c;try{a=decodeURIComponent(i[0]),o=decodeURIComponent(i[1]),s=decodeURIComponent(i[3]),c=i.slice(4).map(e=>decodeURIComponent(e))}catch{return null}return!a||!o||!s||c.length===0||c.some(e=>e.length===0)?null:{host:n,owner:a,repo:o,branch:s,path:c.join(`/`)}}function zt(e){let t;try{t=new URL(e)}catch{return null}if(t.protocol!==`https:`)return null;let n=r(t.hostname);if(n===null)return null;let i=t.pathname.split(`/`);if(i.length<5||i[0]!==``||i[3]!==`tree`)return null;let a=i.slice(5);a.length===1&&a[0]===``&&a.pop();let o,s,c,l;try{o=decodeURIComponent(i[1]),s=decodeURIComponent(i[2]),c=decodeURIComponent(i[4]),l=a.map(e=>decodeURIComponent(e))}catch{return null}return!o||!s||!c||l.some(e=>e.length===0)?null:{host:n,owner:o,repo:s,branch:c,path:l.join(`/`)}}function Bt(e){let t=Rt(e);if(t)return{kind:`doc`,...t};let n=zt(e);return n?{kind:`folder`,...n}:null}var Z=e(O(),1);const Vt=`# >>> open-knowledge cli >>>`,Ht=`# <<< open-knowledge cli <<<`,Ut=/^# >>> open-knowledge cli >>>\n[\s\S]*?^# <<< open-knowledge cli <<<\n?/m;function Wt(e){return M(e,`Library`,`Application Support`,`OpenKnowledge`,`path-install.json`)}const Gt={existsSync:e=>P(e),readFileSync:(e,t)=>I(e,t),lstatSync:e=>pe(e),readlinkSync:e=>ge(e)};function Kt(e,t=Gt){let n=Wt(e);if(!t.existsSync(n))return null;try{let e=JSON.parse(t.readFileSync(n,`utf8`));return e?.version===1?e:null}catch{return null}}function qt(e){let t=e.replace(Ut,``);return{text:t,changed:t!==e,emptyAfter:t.trim()===``}}function Jt(e,t,n=Gt){try{return n.lstatSync(e).isSymbolicLink()?n.readlinkSync(e)===t:!1}catch{return!1}}function Yt(e){return ee(e)||C(e)||ne(e)}const Xt=10*1024*1024;function Zt(e,t,n,r){let i=ie(e,t,n,r);if(i.kind===`absent`||i.kind===`no-entry`)return{kind:`not-present`};if(i.kind===`decline`)return{kind:`declined`,reason:i.reason};if(!Yt(i.entry))return{kind:`left-foreign`};let a;try{a=r??e.configPath(t,n)}catch{return{kind:`not-present`}}let o=e.serverName(t);return e.format===`file`?(_e(a,{force:!0}),{kind:`removed`}):e.format===`toml`?en(a,o):e.format===`yaml`?$t(a,e.topLevelKey,o):Qt(a,e.topLevelKey,e.serverMapSubKey,o)}function Qt(e,t,n,r){let i;try{i=I(e,`utf-8`)}catch{return{kind:`declined`,reason:`unparseable`}}if(Buffer.byteLength(i,`utf-8`)>Xt)return{kind:`declined`,reason:`oversize`};let{text:a,changed:o}=te(i,w(t,n,r));return o?(m(e,a,{mode:E(e)}),{kind:`removed`}):{kind:`not-present`}}function $t(e,t,n){let r;try{r=I(e,`utf-8`)}catch{return{kind:`declined`,reason:`unparseable`}}if(Buffer.byteLength(r,`utf-8`)>Xt)return{kind:`declined`,reason:`oversize`};let i=r.charCodeAt(0)===65279,a=i?r.slice(1):r,o=(0,H.parseDocument)(a);if(o.errors.length>0)return{kind:`declined`,reason:`unparseable`};let s=[t,n];if(!o.hasIn(s))return{kind:`not-present`};o.deleteIn(s);let c=o.toString(),l=re(a);a.trim()===``||a.endsWith(`
|
|
13
13
|
`)?c.endsWith(`
|
|
14
14
|
`)||(c=`${c}\n`):c=c.replace(/\n+$/,``),l&&(c=c.replace(/\r\n/g,`
|
|
@@ -17,6 +17,6 @@ import{o as e}from"./chunk-DTipWd-i.mjs";import{F as t,P as n,oa as r}from"./src
|
|
|
17
17
|
`),c;try{c=n.removeEntry(a,t)}catch{return{kind:`declined`,reason:`unparseable`}}if(!c.existed)return{kind:`not-present`};let l=c.text;s?l.endsWith(`
|
|
18
18
|
`)||(l=`${l}\n`):l=l.replace(/\n+$/,``),o&&(l=l.replace(/\r\n/g,`
|
|
19
19
|
`).replace(/\n/g,`\r
|
|
20
|
-
`));let u=`${i?``:``}${l}`;return u!==r&&m(e,u,{mode:E(e)}),{kind:`removed`}}const tn=new Set([`start`,`stop`,`status`,`clean`,`ui`,`mcp`,`preview`,`lint`,`deinit`,`auth`]);function nn(e,t,n=l){if(e!==void 0&&!tn.has(e))return null;let r=n(t);return r===null||r.distance===0?null:r.rootPath}let rn=null;function an(e){rn=e}function on(){return rn??process.cwd()}function sn(e){return e==null?!1:e.includes(`--type=utility`)&&e.includes(`--utility-sub-type=node.mojom.NodeService`)}function cn(e,t=Date.now()){let n=new Date(e).getTime();if(Number.isNaN(n))return`—`;let r=t-n,i=Math.floor(r/1e3);if(i<60)return`${i}s`;let a=Math.floor(i/60);if(a<60)return`${a}m ago`;let o=Math.floor(a/60);return o<24?`${o}h ago`:`${Math.floor(o/24)}d ago`}function ln(e,t,n,r,i,a){if(t.status===`missing`||t.status===`corrupt`)return null;let o=t.lock,
|
|
21
|
-
`)}async function _n(e={}){let t=e.discover??d,n=e.inspect??X,r=e.log??(e=>console.log(e)),i=e.resolveCommand??u,a=e.resolveUsage??o,s=await t(),c=[];for(let e of s){let t=n(e,`server`),r=n(e,`ui`),o=ln(e,t,r,t.status===`missing`||t.status===`corrupt`?null:i(t.lock.pid),t.status===`missing`||t.status===`corrupt`?null:a(t.lock.pid),r.status===`missing`||r.status===`corrupt`?null:a(r.lock.pid));o!=null&&c.push(o)}if(e.json){let e=c.map(e=>({...e,displayStatus:Q(e)}));r(JSON.stringify(e,null,2));return}r(gn(e.all?c:c.filter(e=>dn.has(Q(e)))))}function vn(){return new b(`ps`).description(`List all running open-knowledge servers`).argument(`[modifier]`,`"all" to include stale (dead-pid) entries`).option(`--all`,`Include stale (dead-pid) entries (foreign-host shows by default)`).option(`--json`,`Emit structured JSON (always includes all statuses)`).action(async(e,t)=>{await _n({all:t.all===!0||e===`all`,json:t.json===!0})})}function yn(e,t,n={}){let r=n.isAlive??v,i=[];for(let[n,a]of[[`server`,e],[`ui`,t]])(a.status===`alive`||a.status===`foreign-host`&&r(a.lock.pid))&&i.push({name:n,pid:a.lock.pid,port:a.lock.port});return{targets:i}}function bn(e){let t=e.inspect??(t=>X(e.lockDir,t)),n=e.kill??((e,t)=>process.kill(e,t)),r=e.log??(e=>console.log(e)),i=e.error??(e=>console.error(e)),a=yn(t(`server`),t(`ui`),{isAlive:e.isAlive});if(a.targets.length===0)return r(`No running open-knowledge processes.`),{stopped:[],failed:[],hadTargets:!1};let o=[],s=[];for(let e of a.targets)try{n(e.pid,`SIGTERM`),o.push(e)}catch(t){s.push({target:e,error:t instanceof Error?t.message:String(t)})}return o.length>0&&r(`Stopped: ${o.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `)}`),s.length>0&&i(`Failed to stop: ${s.map(({target:e,error:t})=>`${e.name} (pid=${e.pid}): ${t}`).join(`; `)}`),{stopped:o,failed:s,hadTargets:!0}}function $(e,t){return e.status===`alive`?!0:e.status===`foreign-host`?t(e.lock.pid):!1}async function xn(e,t=v){let n=await d(),r=null;for(let i of n){let n=X(i,`server`),a=X(i,`ui`);if($(n,t)&&n.lock.port===e||$(a,t)&&a.lock.port===e)return i;r===null&&($(n,t)&&n.lock.pid===e||$(a,t)&&a.lock.pid===e)&&(r=i)}return r}function Sn(e){let t=bn({lockDir:e});return t.failed.length>0&&(process.exitCode=1),t}function Cn(e){return new b(`stop`).description(`Stop open-knowledge server(s). With no argument: stops the server for the current directory. Pass a port number, a directory path, or "all" to target globally.`).argument(`[target...]`,`port number, directory path (spaces OK), or "all"`).action(async t=>{let n=t.length===0?void 0:t.join(` `);if(n===void 0){e();let t=bn({lockDir:i(process.cwd()),log:()=>{}});if(t.hadTargets){if(t.stopped.length>0){let e=t.stopped.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `);console.log(`Stopped: ${e}`)}t.failed.length>0&&(process.exitCode=1)}else await _n({});return}if(n===`all`){let e=await d();if(e.length===0){console.log(`No running open-knowledge servers found.`);return}let t=0;for(let n of e){let e=X(n,`server`),r=X(n,`ui`);!$(e,v)&&!$(r,v)||(Sn(n),t++)}t===0&&console.log(`No running open-knowledge servers found.`);return}if(/^\d+$/.test(n)){let e=Number.parseInt(n,10),t=await xn(e);if(t===null){console.log(`No running open-knowledge server found with port or PID ${e}.`);return}Sn(t);return}Sn(i(N(on(),n)))})}function wn(e){return{event:`mcp-config-decline`,scope:e.scope,surface:e.surface,editorId:e.editorId,reason:e.reason}}async function Tn(e,t){let n,i;try{n=await R(N(e)),i=await R(N(A(e)))}catch{return{kind:`not-git`}}if(!En(n,i))return{kind:`symlink-escape`};let a=M(n,`.git`),o;try{o=ve(a)}catch{return{kind:`not-git`}}if(o.isDirectory()){let e;try{e=await R(a)}catch{return{kind:`not-git`}}if(!En(e,n))return{kind:`symlink-escape`}}else if(!o.isFile())return{kind:`not-git`};let s
|
|
22
|
-
//# sourceMappingURL=src-
|
|
20
|
+
`));let u=`${i?``:``}${l}`;return u!==r&&m(e,u,{mode:E(e)}),{kind:`removed`}}const tn=new Set([`start`,`stop`,`status`,`clean`,`ui`,`mcp`,`preview`,`lint`,`deinit`,`auth`]);function nn(e,t,n=l){if(e!==void 0&&!tn.has(e))return null;let r=n(t);return r===null||r.distance===0?null:r.rootPath}let rn=null;function an(e){rn=e}function on(){return rn??process.cwd()}function sn(e){return e==null?!1:e.includes(`--type=utility`)&&e.includes(`--utility-sub-type=node.mojom.NodeService`)}function cn(e,t=Date.now()){let n=new Date(e).getTime();if(Number.isNaN(n))return`—`;let r=t-n,i=Math.floor(r/1e3);if(i<60)return`${i}s`;let a=Math.floor(i/60);if(a<60)return`${a}m ago`;let o=Math.floor(a/60);return o<24?`${o}h ago`:`${Math.floor(o/24)}d ago`}function ln(e,t,n,r,i,a){if(t.status===`missing`||t.status===`corrupt`)return null;let o=t.lock,s=null;if(n.status!==`missing`&&n.status!==`corrupt`){let e=n.lock;s={port:e.port,status:n.status,pid:e.pid,startedAt:e.startedAt,usage:a}}return{directory:o.worktreeRoot,server:{port:o.port,status:t.status,pid:o.pid,startedAt:o.startedAt,usage:i},ui:s,hostname:o.hostname,lockPath:t.lockPath,binary:r==null?null:c(r),command:r,isDesktop:sn(r)}}function un(e){return e.ui==null?!1:e.ui.status===`alive`||e.ui.status===`foreign-host`}function Q(e){let t=e.server.status;return t===`alive`||t===`foreign-host`?e.isDesktop?`desktop`:t===`alive`?`running`:`foreign`:t===`dead-pid`&&un(e)?`ui-orphan`:`stale`}const dn=new Set([`running`,`desktop`,`foreign`,`ui-orphan`]);function fn(e){switch(e){case`running`:return Z.default.green(e);case`desktop`:return Z.default.blue(e);case`foreign`:return Z.default.cyan(e);case`ui-orphan`:return Z.default.magenta(e);case`stale`:return Z.default.yellow(e)}}function pn(e){return e==null?`—`:`${e.cpuPercent.toFixed(1)}% / ${e.memPercent.toFixed(1)}%`}function mn(e){return`${pn(e.server.usage)} | ${pn(e.ui?.usage??null)}`}function hn(e){return`${e.server.port===0?`(starting)`:String(e.server.port)} / ${e.ui==null||e.ui.status===`dead-pid`?`—`:String(e.ui.port)}`}function gn(e){if(e.length===0)return`No open-knowledge servers found.`;let t=[`DIRECTORY`,`PORTS (API/UI)`,`CPU/MEM (API | UI)`,`STATUS`,`PID`,`STARTED`,`BINARY`],n=e.map(e=>{let t=Q(e),n=t===`ui-orphan`&&e.ui!=null?e.ui.pid:e.server.pid;return[e.directory,hn(e),mn(e),t,String(n),cn(e.server.startedAt),e.binary??`—`]}),r=t.length,i=t.map(e=>e.length);for(let e of n)for(let t=0;t<r;t++)i[t]=Math.max(i[t]??0,(e[t]??``).length);let a=t.map((e,t)=>e.padEnd(i[t]??0)).join(` `).trimEnd(),o=e.map((e,t)=>{let a=n[t]??[],o=[];for(let t=0;t<r;t++){let n=(a[t]??``).padEnd(i[t]??0);if(t===3){let r=a[t]??``;n=fn(Q(e))+` `.repeat(Math.max(0,(i[t]??0)-r.length))}o.push(n)}return o.join(` `).trimEnd()}),s=Z.default.dim(`To stop a server: ok stop <port|pid|directory|all>`);return[a,...o,``,s].join(`
|
|
21
|
+
`)}async function _n(e={}){let t=e.discover??d,n=e.inspect??X,r=e.log??(e=>console.log(e)),i=e.resolveCommand??u,a=e.resolveUsage??o,s=await t(),c=[];for(let e of s){let t=n(e,`server`),r=n(e,`ui`),o=ln(e,t,r,t.status===`missing`||t.status===`corrupt`?null:i(t.lock.pid),t.status===`missing`||t.status===`corrupt`?null:a(t.lock.pid),r.status===`missing`||r.status===`corrupt`?null:a(r.lock.pid));o!=null&&c.push(o)}if(e.json){let e=c.map(e=>({...e,displayStatus:Q(e)}));r(JSON.stringify(e,null,2));return}r(gn(e.all?c:c.filter(e=>dn.has(Q(e)))))}function vn(){return new b(`ps`).description(`List all running open-knowledge servers`).argument(`[modifier]`,`"all" to include stale (dead-pid) entries`).option(`--all`,`Include stale (dead-pid) entries (foreign-host shows by default)`).option(`--json`,`Emit structured JSON (always includes all statuses)`).action(async(e,t)=>{await _n({all:t.all===!0||e===`all`,json:t.json===!0})})}function yn(e,t,n={}){let r=n.isAlive??v,i=[];for(let[n,a]of[[`server`,e],[`ui`,t]])(a.status===`alive`||a.status===`foreign-host`&&r(a.lock.pid))&&i.push({name:n,pid:a.lock.pid,port:a.lock.port});return{targets:i}}function bn(e){let t=e.inspect??(t=>X(e.lockDir,t)),n=e.kill??((e,t)=>process.kill(e,t)),r=e.log??(e=>console.log(e)),i=e.error??(e=>console.error(e)),a=yn(t(`server`),t(`ui`),{isAlive:e.isAlive});if(a.targets.length===0)return r(`No running open-knowledge processes.`),{stopped:[],failed:[],hadTargets:!1};let o=[],s=[];for(let e of a.targets)try{n(e.pid,`SIGTERM`),o.push(e)}catch(t){s.push({target:e,error:t instanceof Error?t.message:String(t)})}return o.length>0&&r(`Stopped: ${o.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `)}`),s.length>0&&i(`Failed to stop: ${s.map(({target:e,error:t})=>`${e.name} (pid=${e.pid}): ${t}`).join(`; `)}`),{stopped:o,failed:s,hadTargets:!0}}function $(e,t){return e.status===`alive`?!0:e.status===`foreign-host`?t(e.lock.pid):!1}async function xn(e,t=v){let n=await d(),r=null;for(let i of n){let n=X(i,`server`),a=X(i,`ui`);if($(n,t)&&n.lock.port===e||$(a,t)&&a.lock.port===e)return i;r===null&&($(n,t)&&n.lock.pid===e||$(a,t)&&a.lock.pid===e)&&(r=i)}return r}function Sn(e){let t=bn({lockDir:e});return t.failed.length>0&&(process.exitCode=1),t}function Cn(e){return new b(`stop`).description(`Stop open-knowledge server(s). With no argument: stops the server for the current directory. Pass a port number, a directory path, or "all" to target globally.`).argument(`[target...]`,`port number, directory path (spaces OK), or "all"`).action(async t=>{let n=t.length===0?void 0:t.join(` `);if(n===void 0){e();let t=bn({lockDir:i(process.cwd()),log:()=>{}});if(t.hadTargets){if(t.stopped.length>0){let e=t.stopped.map(e=>`${e.name} (pid=${e.pid}, port=${e.port})`).join(`, `);console.log(`Stopped: ${e}`)}t.failed.length>0&&(process.exitCode=1)}else await _n({});return}if(n===`all`){let e=await d();if(e.length===0){console.log(`No running open-knowledge servers found.`);return}let t=0;for(let n of e){let e=X(n,`server`),r=X(n,`ui`);!$(e,v)&&!$(r,v)||(Sn(n),t++)}t===0&&console.log(`No running open-knowledge servers found.`);return}if(/^\d+$/.test(n)){let e=Number.parseInt(n,10),t=await xn(e);if(t===null){console.log(`No running open-knowledge server found with port or PID ${e}.`);return}Sn(t);return}Sn(i(N(on(),n)))})}function wn(e){return{event:`mcp-config-decline`,scope:e.scope,surface:e.surface,editorId:e.editorId,reason:e.reason}}async function Tn(e,t){let n,i;try{n=await R(N(e)),i=await R(N(A(e)))}catch{return{kind:`not-git`}}if(!En(n,i))return{kind:`symlink-escape`};let a=M(n,`.git`),o;try{o=ve(a)}catch{return{kind:`not-git`}}if(o.isDirectory()){let e;try{e=await R(a)}catch{return{kind:`not-git`}}if(!En(e,n))return{kind:`symlink-escape`}}else if(!o.isFile())return{kind:`not-git`};let c=s(n);if(c.kind!==`repository`)return{kind:`not-git`};let l=c.repository.readRemoteUrl(`origin`);if(l.kind===`unreadable`)return{kind:`not-git`};if(l.kind===`absent`)return l.reason===`config-missing`?{kind:`not-git`}:{kind:`no-origin`};let u=l.url,d=Lt(u);if(d===null)return{kind:`non-github`};let f=r(d.hostname);if(f===null)return{kind:`non-github`};let p=f===t.host.toLowerCase(),m=d.owner.toLowerCase()===t.owner.toLowerCase(),h=d.name.toLowerCase()===t.repo.toLowerCase();return!p&&m&&h?{kind:`wrong-host`,actualHost:f}:!p||!m||!h?{kind:`wrong-repo`,actualOwner:d.owner,actualRepo:d.name}:{kind:`ok`,gitRemoteUrl:`https://${f}/${d.owner}/${d.name}.git`}}function En(e,t){if(e===t)return!0;let n=le(t,e);return n.length>0&&!n.startsWith(`..`)&&!j(n)}const Dn=[{id:`mcp-config`,write(e,t,n){let r=e.projectConfigPath?.(t);if(!r)return{integration:`mcp-config`,editorId:e.id,action:`skipped-unsupported`};try{let i=ae(e,t,n,void 0,r);return i.action===`written`||i.action===`overwritten`?{integration:`mcp-config`,editorId:e.id,action:i.action,path:i.configPath}:i.action===`failed`?{integration:`mcp-config`,editorId:e.id,action:`failed`,path:i.configPath,error:i.error??`unknown failure`}:i.action===`declined`?{integration:`mcp-config`,editorId:e.id,action:`declined`,path:i.configPath,...i.declineReason===void 0?{}:{reason:i.declineReason}}:{integration:`mcp-config`,editorId:e.id,action:`failed`,path:i.configPath,error:`unexpected project-scope action: ${i.action}`}}catch(t){return{integration:`mcp-config`,editorId:e.id,action:`failed`,path:r,error:t instanceof Error?t.message:String(t)}}}},{id:`project-skill`,write(e,t,n){try{let r=S(e,t,{home:n.home});return{integration:`project-skill`,editorId:e.id,action:r.action,...r.path?{path:r.path}:{},...r.error?{error:r.error}:{}}}catch(t){return{integration:`project-skill`,editorId:e.id,action:`failed`,error:t instanceof Error?t.message:String(t)}}}}];function On(e,t,n={},r=Dn){let i=[];for(let a of t){let t=x[a];for(let a of r)i.push(a.write(t,e,n))}return i}function kn(e,t,n={}){return{integrations:On(e,t,n)}}export{Ft as C,B as D,Me as E,X as S,Mt as T,qt as _,Cn as a,zt as b,an as c,Vt as d,Ut as f,Kt as g,Wt as h,bn as i,nn as l,Jt as m,Tn as n,vn as o,Ht as p,wn as r,on as s,kn as t,Zt as u,Rt as v,jt as w,Lt as x,Bt as y};
|
|
22
|
+
//# sourceMappingURL=src-DgWjvSDo.mjs.map
|