@chatpanel/events 0.371.1 → 0.371.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/web-search.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatpanel/events",
3
- "version": "0.371.1",
3
+ "version": "0.371.2",
4
4
  "description": "The canonical ChatPanel event-log and capability contracts — typed durable facts, clock-free deterministic linearization, schema upcasting, and the invariants the replay harness asserts. Pure, dependency-free ESM shared by the ChatPanel extension, gateway and bridge.",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/web-search.js CHANGED
@@ -1 +1 @@
1
- import{GATEWAY_ENGINE as d}from"./search-engines.js";const w=Object.freeze([d,Object.freeze({id:"startpage",name:"Startpage",url:"https://www.startpage.com/sp/search?query=%s",enabled:!0}),Object.freeze({id:"duckduckgo",name:"DuckDuckGo",url:"https://html.duckduckgo.com/html/?q=%s",enabled:!0}),Object.freeze({id:"google",name:"Google",url:"https://www.google.com/search?q=%s",enabled:!1}),Object.freeze({id:"bing",name:"Bing",url:"https://www.bing.com/search?q=%s",enabled:!0})]),S=5;function C(o,t,{assertFetchable:e}={}){const n=String(o||"").trim();if(!/^https:\/\//i.test(n))throw new Error("Search engine URL must start with https://");if(!n.includes("%s")&&!n.includes("{q}"))throw new Error("Search engine URL must contain a %s (or {q}) query placeholder");const s=n.replace(/%s|\{q\}/g,encodeURIComponent(String(t||"").trim()));return typeof e=="function"&&e(s),s}const b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";function y(o){let t=0,e=0,n="";for(const s of o){const r=b.indexOf(s);if(r<0)return"";e=e<<6|r,t+=6,t>=8&&(t-=8,n+="%"+(e>>t&255).toString(16).padStart(2,"0"))}try{return decodeURIComponent(n)}catch{return""}}function k(o){try{const t=new URL(o,"https://duckduckgo.com"),e=t.searchParams.get("uddg");if(e)return decodeURIComponent(e);const n=t.searchParams.get("url")||t.searchParams.get("u");if(n&&/^https?:/i.test(n))return n;const s=n&&/^a1[A-Za-z0-9_-]+$/.test(n)?y(n.slice(2)):"";return/^https?:\/\//i.test(s)?s:t.href}catch{return String(o||"")}}const R=/(^|\.)(startpage\.com|startmail\.com|startpage\.dev|mojeek\.com|buttondown\.(com|email)|ecosia\.org|duckduckgo\.com|search\.brave\.com|qwant\.com|admarketplace\.(net|com)|googleadservices\.com|doubleclick\.net)$/i,L=/^\/(aclick|pagead\/aclk|aclk)\b/i;function x(o,t=""){const e=String(o||"").toLowerCase();if(!e||R.test(e))return!1;const n=String(t||"").split(".").slice(-2).join(".").toLowerCase();return!(n&&(e===n||e.endsWith(`.${n}`)))}function O(o,{engineHost:t="",limit:e=S,fallback:n=!1}={}){const s=[],r=new Map;for(const c of o||[]){const a=k(c?.href||"");let i;try{i=new URL(a)}catch{continue}if(i.protocol!=="https:"&&i.protocol!=="http:"||!x(i.hostname,t)||L.test(i.pathname)||n&&c.chrome)continue;const u=String(c?.text||"").replace(/\s+/g," ").trim();if(u.length<6||/^\S+\s+https?:\/\/\S+/.test(u))continue;const h=i.origin+i.pathname;if(r.has(h)){const l=r.get(h);l&&!l.snippet&&u.length>l.title.length+10&&(l.snippet=u);continue}const p={url:a,title:u,snippet:String(c?.snippet||"").replace(/\s+/g," ").trim()};if(r.set(h,p),s.push(p),s.length>=e)break}return s}const f=new Set("does have what when where which whom whose with from that this these those about many much there their they them would could should will your into were been being some such than then just also only very more most".split(" ")),E=o=>[...new Set(String(o||"").toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(t=>t.length>=4&&!f.has(t)))],U=new Set("a an the of in on at to for by is are was were be do did does can how who why and or as it its me my i you he she we us our per due according please tell give list".split(" "));function $(o){const t=String(o||"").trim().split(/\s+/).map(n=>n.replace(/^[^\p{L}\p{N}]+|[^\p{L}\p{N}]+$/gu,"")).filter(Boolean),e=t.filter(n=>/^\d/.test(n)||/^[A-Z]{2,4}$/.test(n)||!U.has(n.toLowerCase())&&!f.has(n.toLowerCase()));return e.length&&e.length<t.length?e.join(" "):""}const g=o=>o.replace(/(ies|ing|ed|es|s|y)$/u,""),m=(o,t)=>o.includes(t)||g(t).length>=3&&o.includes(g(t));function j(o,t){const e=E(t);if(e.length<2||!o?.length)return!1;const n=o.map(r=>`${r.title||""} ${r.snippet||""} ${r.url||""}`.toLowerCase());if(e.some(r=>r.length>=6&&!n.some(c=>m(c,r))))return!0;const s=Math.ceil(e.length/2);return!n.some(r=>e.filter(c=>m(r,c)).length>=s)}const N=/^(www\.)?(bing|google(\.[a-z]{2,3}){1,2}|duckduckgo|search\.yahoo|yandex|baidu|startpage|search\.brave)\.[a-z.]*$|^(www\.)?google\.[a-z.]+$/i;function q(o){try{const t=new URL(o);return N.test(t.hostname)&&/^\/(search|news\/search|web|html|sp\/search|s)\b/i.test(t.pathname)}catch{return!1}}function z(o,t=8){const e=[],n=new Set;for(const s of o||[])for(const r of s||[]){let c;try{const a=new URL(r.url);c=a.origin+a.pathname}catch{c=r.url}if(!n.has(c)&&(n.add(c),e.push(r),e.length>=t))return e}return e}function _(o=w){const t=(Array.isArray(o)?o:[]).filter(e=>e&&(e.url||e.kind==="gateway")&&!e.retired);return[...t.filter(e=>e.enabled!==!1),...t.filter(e=>e.enabled===!1)]}export{S as RESULTS_PER_ENGINE,w as SEARCH_ENGINES,C as buildSearchUrl,$ as contentQuery,_ as engineOrder,x as isResultHost,q as isSearchPage,z as mergeEngineResults,j as offTopic,O as pickResults,k as unwrapRedirect};
1
+ import{GATEWAY_ENGINE as d}from"./search-engines.js";const w=Object.freeze([d,Object.freeze({id:"startpage",name:"Startpage",url:"https://www.startpage.com/sp/search?query=%s",enabled:!0}),Object.freeze({id:"duckduckgo",name:"DuckDuckGo",url:"https://html.duckduckgo.com/html/?q=%s",enabled:!0}),Object.freeze({id:"google",name:"Google",url:"https://www.google.com/search?q=%s",enabled:!1}),Object.freeze({id:"bing",name:"Bing",url:"https://www.bing.com/search?q=%s",enabled:!0})]),S=5;function C(o,t,{assertFetchable:e}={}){const n=String(o||"").trim();if(!/^https:\/\//i.test(n))throw new Error("Search engine URL must start with https://");if(!n.includes("%s")&&!n.includes("{q}"))throw new Error("Search engine URL must contain a %s (or {q}) query placeholder");const s=n.replace(/%s|\{q\}/g,encodeURIComponent(String(t||"").trim()));return typeof e=="function"&&e(s),s}const b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";function y(o){let t=0,e=0,n="";for(const s of o){const r=b.indexOf(s);if(r<0)return"";e=e<<6|r,t+=6,t>=8&&(t-=8,n+="%"+(e>>t&255).toString(16).padStart(2,"0"))}try{return decodeURIComponent(n)}catch{return""}}function k(o){try{const t=new URL(o,"https://duckduckgo.com"),e=t.searchParams.get("uddg");if(e)return decodeURIComponent(e);const n=t.searchParams.get("url")||t.searchParams.get("u");if(n&&/^https?:/i.test(n))return n;const s=n&&/^a1[A-Za-z0-9_-]+$/.test(n)?y(n.slice(2)):"";return/^https?:\/\//i.test(s)?s:t.href}catch{return String(o||"")}}const R=/(^|\.)(startpage\.com|startmail\.com|startpage\.dev|mojeek\.com|buttondown\.(com|email)|ecosia\.org|duckduckgo\.com|search\.brave\.com|qwant\.com|admarketplace\.(net|com)|googleadservices\.com|doubleclick\.net)$/i,x=/^\/(aclick|pagead\/aclk|aclk)\b/i;function L(o,t=""){const e=String(o||"").toLowerCase();if(!e||R.test(e))return!1;const n=String(t||"").split(".").slice(-2).join(".").toLowerCase();return!(n&&(e===n||e.endsWith(`.${n}`)))}function O(o,{engineHost:t="",limit:e=S,fallback:n=!1}={}){const s=[],r=new Map;for(const c of o||[]){const a=k(c?.href||"");let i;try{i=new URL(a)}catch{continue}if(i.protocol!=="https:"&&i.protocol!=="http:"||!L(i.hostname,t)||x.test(i.pathname)||n&&c.chrome)continue;const u=String(c?.text||"").replace(/\s+/g," ").trim();if(u.length<6||/^\S+\s+https?:\/\/\S+/.test(u))continue;const h=i.origin+i.pathname;if(r.has(h)){const l=r.get(h);l&&!l.snippet&&u.length>l.title.length+10&&(l.snippet=u);continue}const p={url:a,title:u,snippet:String(c?.snippet||"").replace(/\s+/g," ").trim()};if(r.set(h,p),s.push(p),s.length>=e)break}return s}const f=new Set("does have what when where which whom whose with from that this these those about many much there their they them would could should will your into were been being some such than then just also only very more most".split(" ")),E=o=>[...new Set(String(o||"").toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(t=>t.length>=4&&!f.has(t)))],U=new Set("a an the of in on at to for by is are was were be do did does can how who why and or as it its me my i you he she we us our per due according please tell give list".split(" "));function $(o){const t=String(o||"").trim().split(/\s+/).map(n=>n.replace(/^[^\p{L}\p{N}]+|[^\p{L}\p{N}]+$/gu,"")).filter(Boolean),e=t.filter(n=>/^\d/.test(n)||/^[A-Z]{2,4}$/.test(n)||!U.has(n.toLowerCase())&&!f.has(n.toLowerCase()));return e.length&&e.length<t.length?e.join(" "):""}const g=o=>o.replace(/(ies|ing|ed|es|s|y)$/u,""),m=(o,t)=>o.includes(t)||g(t).length>=3&&o.includes(g(t));function j(o,t){const e=E(t);if(e.length<2||!o?.length)return!1;const n=o.map(r=>`${r.title||""} ${r.snippet||r.text||""} ${r.url||""}`.toLowerCase());if(e.some(r=>r.length>=6&&!n.some(c=>m(c,r))))return!0;const s=Math.ceil(e.length/2);return!n.some(r=>e.filter(c=>m(r,c)).length>=s)}const N=/^(www\.)?(bing|google(\.[a-z]{2,3}){1,2}|duckduckgo|search\.yahoo|yandex|baidu|startpage|search\.brave)\.[a-z.]*$|^(www\.)?google\.[a-z.]+$/i;function q(o){try{const t=new URL(o);return N.test(t.hostname)&&/^\/(search|news\/search|web|html|sp\/search|s)\b/i.test(t.pathname)}catch{return!1}}function z(o,t=8){const e=[],n=new Set;for(const s of o||[])for(const r of s||[]){let c;try{const a=new URL(r.url);c=a.origin+a.pathname}catch{c=r.url}if(!n.has(c)&&(n.add(c),e.push(r),e.length>=t))return e}return e}function _(o=w){const t=(Array.isArray(o)?o:[]).filter(e=>e&&(e.url||e.kind==="gateway")&&!e.retired);return[...t.filter(e=>e.enabled!==!1),...t.filter(e=>e.enabled===!1)]}export{S as RESULTS_PER_ENGINE,w as SEARCH_ENGINES,C as buildSearchUrl,$ as contentQuery,_ as engineOrder,L as isResultHost,q as isSearchPage,z as mergeEngineResults,j as offTopic,O as pickResults,k as unwrapRedirect};