@duckmind/dm-darwin-x64 0.52.6 → 0.53.1
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/dm +0 -0
- package/extensions/.dm-extensions.json +14 -10
- package/extensions/dm-cua/bin/browser-cua.mjs +6 -6
- package/extensions/dm-cua/index.js +5 -5
- package/extensions/dm-cua/src/browser-cua-lib.mjs +2 -2
- package/extensions/greedysearch-dm/bin/cdp-greedy.mjs +8 -1
- package/extensions/greedysearch-dm/bin/cdp-headless.mjs +1 -1
- package/extensions/greedysearch-dm/bin/cdp-visible.mjs +1 -1
- package/extensions/greedysearch-dm/bin/cdp.mjs +29 -20
- package/extensions/greedysearch-dm/bin/gschrome.mjs +1 -8
- package/extensions/greedysearch-dm/bin/kill-visible.mjs +1 -1
- package/extensions/greedysearch-dm/bin/launch-visible.mjs +1 -2
- package/extensions/greedysearch-dm/bin/launch.mjs +9 -11
- package/extensions/greedysearch-dm/bin/mcp.mjs +375 -0
- package/extensions/greedysearch-dm/bin/search.mjs +309 -157
- package/extensions/greedysearch-dm/bin/visible.mjs +1 -1
- package/extensions/greedysearch-dm/extractors/bing-copilot.mjs +205 -68
- package/extensions/greedysearch-dm/extractors/chatgpt.mjs +229 -140
- package/extensions/greedysearch-dm/extractors/common.mjs +160 -50
- package/extensions/greedysearch-dm/extractors/consensus.mjs +226 -93
- package/extensions/greedysearch-dm/extractors/consent.mjs +44 -17
- package/extensions/greedysearch-dm/extractors/gemini.mjs +277 -138
- package/extensions/greedysearch-dm/extractors/google-ai.mjs +172 -64
- package/extensions/greedysearch-dm/extractors/logically.mjs +183 -69
- package/extensions/greedysearch-dm/extractors/perplexity.mjs +331 -65
- package/extensions/greedysearch-dm/extractors/semantic-scholar.mjs +118 -41
- package/extensions/greedysearch-dm/index.js +23 -20
- package/extensions/greedysearch-dm/package.json +8 -3
- package/extensions/greedysearch-dm/skills/greedy-search/skill.md +8 -8
- package/extensions/greedysearch-dm/src/fetcher.mjs +2 -2
- package/extensions/greedysearch-dm/src/formatters/results.js +8 -6
- package/extensions/greedysearch-dm/src/github.mjs +7 -7
- package/extensions/greedysearch-dm/src/reddit.mjs +1 -1
- package/extensions/greedysearch-dm/src/search/browser-lifecycle.mjs +10 -8
- package/extensions/greedysearch-dm/src/search/challenge-detect.mjs +48 -0
- package/extensions/greedysearch-dm/src/search/chrome.mjs +130 -54
- package/extensions/greedysearch-dm/src/search/constants.mjs +6 -6
- package/extensions/greedysearch-dm/src/search/engines.mjs +9 -9
- package/extensions/greedysearch-dm/src/search/fetch-source.mjs +160 -83
- package/extensions/greedysearch-dm/src/search/minimize.mjs +1 -0
- package/extensions/greedysearch-dm/src/search/paths.mjs +1 -1
- package/extensions/greedysearch-dm/src/search/pdf.mjs +1 -1
- package/extensions/greedysearch-dm/src/search/port-pid.mjs +1 -1
- package/extensions/greedysearch-dm/src/search/progress.mjs +2 -0
- package/extensions/greedysearch-dm/src/search/recovery.mjs +1 -1
- package/extensions/greedysearch-dm/src/search/research.mjs +262 -167
- package/extensions/greedysearch-dm/src/search/scale-aware.mjs +11 -0
- package/extensions/greedysearch-dm/src/search/simple-research.mjs +827 -0
- package/extensions/greedysearch-dm/src/search/synthesis-runner.mjs +9 -9
- package/extensions/greedysearch-dm/src/search/synthesis.mjs +10 -10
- package/extensions/greedysearch-dm/src/tools/greedy-search-handler.js +23 -20
- package/extensions/greedysearch-dm/src/tools/shared.js +10 -9
- package/extensions/greedysearch-dm/src/utils/node-runtime.mjs +1 -1
- package/package.json +1 -1
- package/extensions/greedysearch-dm/src/search/cdp-endpoint.mjs +0 -3
- package/extensions/greedysearch-dm/src/search/launcher-paths.mjs +0 -3
- package/extensions/greedysearch-dm/src/search/partial-output.mjs +0 -1
- package/extensions/greedysearch-dm/src/utils/browser-executable.mjs +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{createRequire as y}from"node:module";var C=y(import.meta.url);var L=null;async function A(){if(L)return L;let[{Readability:K},{JSDOM:Y},{default:j}]=await Promise.all([import("@mozilla/readability"),import("jsdom"),import("turndown")]),Z=new j({headingStyle:"atx",bulletListMarker:"-",codeBlockStyle:"fenced"});return Z.addRule("removeDataUrls",{filter:($)=>$.tagName==="IMG"&&$.getAttribute("src")?.startsWith("data:"),replacement:()=>""}),L={Readability:K,JSDOM:Y,turndown:Z},L}var w="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",g={"user-agent":w,accept:"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8","accept-language":"en-US,en;q=0.9","accept-encoding":"gzip, deflate, br","cache-control":"no-cache",pragma:"no-cache","sec-ch-ua":'"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',"sec-ch-ua-mobile":"?0","sec-ch-ua-platform":'"Windows"',"sec-fetch-dest":"document","sec-fetch-mode":"navigate","sec-fetch-site":"none","sec-fetch-user":"?1","upgrade-insecure-requests":"1"},k=[/^localhost$/i,/^127\.\d+\.\d+\.\d+$/,/^0\.0\.0\.0$/,/^\[::1\]$/,/^10\./,/^172\.(1[6-9]|2\d|3[01])\./,/^192\.168\./,/^169\.254\./,/^fc00:/i,/^fe80:/i,/\.local$/i,/\.internal$/i,/\.localhost$/i],P=/^::ffff:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/i,R=/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i,_=/^(?:0x[0-9a-f]+|0[0-7]*|[1-9][0-9]*)$/i;function M(K){if(!K||K.includes(":"))return null;let Y=K.split(".");if(Y.length<1||Y.length>4)return null;if(!Y.every(($)=>_.test($)))return null;let j=Y.map(($)=>{if(/^0x/i.test($))return parseInt($,16);if(/^0[0-7]+$/.test($))return parseInt($,8);return parseInt($,10)});if(j.some(($)=>!Number.isFinite($)||$<0))return null;let Z;if(j.length===1){if(j[0]>4294967295)return null;Z=[j[0]>>>24&255,j[0]>>>16&255,j[0]>>>8&255,j[0]&255]}else if(j.length===2){if(j[0]>255||j[1]>16777215)return null;Z=[j[0],j[1]>>>16&255,j[1]>>>8&255,j[1]&255]}else if(j.length===3){if(j[0]>255||j[1]>255||j[2]>65535)return null;Z=[j[0],j[1],j[2]>>>8&255,j[2]&255]}else{if(j.some(($)=>$>255))return null;Z=j}return Z.join(".")}function E(K){let Y=K.match(P);if(Y)return`${Y[1]}.${Y[2]}.${Y[3]}.${Y[4]}`;let j=K.match(R);if(j){let Z=parseInt(j[1],16),$=parseInt(j[2],16);if(Z>65535||$>65535)return null;return[Z>>>8&255,Z&255,$>>>8&255,$&255].join(".")}return null}function D(K){return k.some((Y)=>Y.test(K))}function o(K={}){return{...g,...K}}function b(K){try{if(typeof K!=="string"||!K.trim())return{blocked:!0,reason:"URL must be a non-empty string"};let Y=new URL(K);if(Y.protocol!=="http:"&&Y.protocol!=="https:")return{blocked:!0,reason:`Protocol not allowed: ${Y.protocol}`};let j=Y.hostname.toLowerCase();for(let $ of k)if($.test(j))return{blocked:!0,reason:`Private/internal address: ${j}`};if(j.startsWith("[")&&j.endsWith("]")){let $=j.slice(1,-1),W=E($);if(W&&D(W))return{blocked:!0,reason:`Private/internal address: ${j} (maps to ${W})`}}let Z=M(j);if(Z&&D(Z))return{blocked:!0,reason:`Private/internal address: ${j} (normalizes to ${Z})`};return{blocked:!1}}catch(Y){return{blocked:!0,reason:`Invalid URL: ${Y.message}`}}}function x(K){try{let Y=new URL(K);if(!(Y.hostname==="github.com"||Y.hostname.endsWith(".github.com")))return K;let j=Y.pathname.split("/").filter(Boolean);if(j.length<5)return K;let[Z,$,W,X,...z]=j;if(W!=="blob")return K;let J=z.join("/");return`https://raw.githubusercontent.com/${Z}/${$}/${X}/${J}`}catch{return K}}async function n(K,Y={}){let j=b(K);if(j.blocked)return{ok:!1,url:K,finalUrl:K,status:403,error:`Blocked: ${j.reason}`,needsBrowser:!1};let Z=K;if(K=x(K),K!==Z)console.error(`[fetcher] Rewrote GitHub URL: ${Z.slice(0,60)}... → raw.githubusercontent.com`);let{timeoutMs:$=15000,userAgent:W,signal:X}=Y,z=new AbortController,J=setTimeout(()=>z.abort(),$);if(X)X.addEventListener("abort",()=>z.abort(),{once:!0});try{let Q=await fetch(K,{method:"GET",headers:{...g,"user-agent":W||w},redirect:"follow",signal:z.signal});clearTimeout(J);let B=Q.headers.get("content-type")||"",V=Q.url,F=Q.headers.get("last-modified")||"",q=b(V);if(q.blocked)return{ok:!1,url:K,finalUrl:V,status:Q.status,error:`Blocked: ${q.reason}`,needsBrowser:!1};let H=!1;try{H=new URL(V).hostname.toLowerCase()==="raw.githubusercontent.com"}catch{}if(B.includes("text/plain")&&H){let O=await Q.text();return{ok:!0,url:Z,finalUrl:V,status:Q.status,title:V.split("/").pop()||"GitHub File",byline:"",siteName:"GitHub",lang:"",publishedTime:F,lastModified:F,markdown:O,contentLength:O.length,excerpt:O.slice(0,300).replaceAll(/\n/g," "),needsBrowser:!1}}if(!B.includes("text/html")&&!B.includes("application/xhtml"))return{ok:!1,url:K,finalUrl:V,status:Q.status,error:`Unsupported content type: ${B}`,needsBrowser:!1};let I=await Q.text(),N=T(Q.status,I,V,K);if(N.blocked)return{ok:!1,url:K,finalUrl:V,status:Q.status,error:`Blocked: ${N.reason}`,needsBrowser:!0};let G=await c(I,V),S=d(G);if(!S.ok)return{ok:!1,url:K,finalUrl:V,status:Q.status,error:`Low quality content: ${S.reason}`,needsBrowser:!0};return{ok:!0,url:K,finalUrl:V,status:Q.status,title:G.title,byline:G.byline,siteName:G.siteName,lang:G.lang,publishedTime:G.publishedTime||F,lastModified:F,markdown:G.markdown,excerpt:G.excerpt,contentLength:G.markdown.length,needsBrowser:!1}}catch(Q){clearTimeout(J);let B=m(Q);return{ok:!1,url:K,finalUrl:K,status:0,error:Q.message,needsBrowser:B}}}function T(K,Y,j,Z){let $=Y.match(/<title[^>]*>([^<]*)<\/title>/i)?.[1]?.toLowerCase()||"",W=Y.slice(0,30000).toLowerCase(),X=`${$} ${W}`;if(K===403||K===429||K===503)return{blocked:!0,reason:`HTTP ${K}`};let z=[{pattern:/class=["'][^"']*captcha["']|<div[^>]*id=["']captcha/i,reason:"captcha"},{pattern:/g-recaptcha|data-sitekey|i['"]m not a robot/i,reason:"captcha"},{pattern:/checking your browser.{0,100}please wait|cf-browser-verification/i,reason:"cloudflare challenge"},{pattern:/just a moment.{0,50}security check|ddos protection by cloudflare/i,reason:"cloudflare challenge"},{pattern:/unusual traffic.{0,50}from your computer network/i,reason:"unusual traffic"},{pattern:/bot detected|automated.{0,20}request/i,reason:"bot detection"},{pattern:/enable\s+javascript\s+to\s+view|javascript\s+is\s+required.{0,50}enabled/i,reason:"requires javascript"},{pattern:/access denied|accessdenied/i,reason:"access denied"},{pattern:/protected by anubis|anubis uses a proof-of-work/i,reason:"anubis challenge"}];for(let Q of z)if(Q.pattern.test(X))return{blocked:!0,reason:Q.reason};let J=p(Z,j,Y);if(J)return{blocked:!0,reason:J};return{blocked:!1}}var f=["accounts.google.com","login.microsoftonline.com","login.live.com","auth0.com","okta.com","auth.mozilla.auth0.com","id.atlassian.com"],U=["login.","signin.","auth.","sso.","accounts.","idp."],h=["sign in to continue","log in to continue","authentication required","create an account to continue","subscribe to continue reading","members only"];function p(K,Y,j){try{let Z=new URL(K),$=new URL(Y);if(Z.hostname.toLowerCase()===$.hostname.toLowerCase())return;let W=$.hostname.toLowerCase();if(f.some((z)=>W===z||W.endsWith(`.${z}`)))return`redirected to login (${$.hostname})`;if(U.some((z)=>W.startsWith(z)))return`redirected to login (${$.hostname})`;let X=j.slice(0,20000).toLowerCase();if(h.some((z)=>X.includes(z)))return`redirected to login page (${$.hostname})`}catch{}return}function m(K){let Y=K.message.toLowerCase();return Y.includes("fetch failed")||Y.includes("unable to verify")||Y.includes("certificate")||Y.includes("timeout")}function v(K){let Y=['meta[property="article:published_time"]','meta[name="article:published_time"]','meta[property="og:published_time"]','meta[name="publication_date"]','meta[name="date"]','meta[itemprop="datePublished"]','time[itemprop="datePublished"]','meta[name="DC.date"]'];for(let j of Y){let Z=K.querySelector(j),$=Z?.getAttribute("content")||Z?.getAttribute("datetime")||"";if($)return $}return""}async function c(K,Y){let{Readability:j,JSDOM:Z,turndown:$}=await A(),W=new Z(K,{url:Y});try{let X=W.window.document,J=new j(X).parse();if(J&&J.content){let V=$.turndown(J.content).replaceAll(/\n{3,}/g,`
|
|
2
2
|
|
|
3
|
-
`).trim(),
|
|
3
|
+
`).trim(),F=J.publishedTime||v(X)||"";return{title:J.title||X.title||Y,byline:J.byline||"",siteName:J.siteName||"",lang:J.lang||"",publishedTime:F,markdown:V,excerpt:V.slice(0,300).replaceAll(/\n/g," ")}}let Q=X.body;if(Q){let B=Q.cloneNode(!0);B.querySelectorAll("script, style, nav, footer, header, aside").forEach((q)=>q.remove());let F=(B.textContent||"").replaceAll(/\s+/g," ").trim();return{title:X.title||Y,byline:"",siteName:"",lang:"",publishedTime:v(X),markdown:F,excerpt:F.slice(0,300)}}return{title:Y,byline:"",siteName:"",lang:"",publishedTime:"",markdown:"",excerpt:""}}finally{W.window.close()}}function d(K){let Y=K.markdown.trim().toLowerCase(),j=(K.title||"").toLowerCase();if(K.markdown.trim().length<100)return{ok:!1,reason:"content too short (< 100 chars)"};let Z=Y.toLowerCase(),$=[{check:()=>Z.includes("loading")&&Z.includes("please wait"),desc:"loading page"},{check:()=>Z.includes("please ensure javascript is enabled"),desc:"requires javascript"},{check:()=>Z.includes("enable javascript to view"),desc:"requires javascript"},{check:()=>Z.includes("just a moment"),desc:"cloudflare challenge detected in content"},{check:()=>Z.includes("verify you are human"),desc:"human verification"},{check:()=>Z.includes("captcha required"),desc:"captcha in extracted content"},{check:()=>Z.includes("access denied"),desc:"access denied in content"},{check:()=>/^\s{0,10}sign\s{1,5}in\s{0,10}$|^\s{0,10}log\s{1,5}in\s{0,10}$/im.test(Y),desc:"login form only"}];for(let{check:W,desc:X}of $)if(W())return{ok:!1,reason:X};if(j.includes("just a moment")||j.includes("checking your browser"))return{ok:!1,reason:"cloudflare challenge page detected in title"};return{ok:!0}}function s(K){try{let Y=new URL(K),j=Y.hostname.toLowerCase(),Z=Y.pathname.toLowerCase();if(["react.dev","nextjs.org","vuejs.org","angular.io","svelte.dev","docs.expo.dev","tailwindcss.com","storybook.js.org"].some((W)=>j===W||j.endsWith(`.${W}`)))return!0;if(Z.includes("/playground")||Z.includes("/demo")||Z.includes("/app"))return!0;if(Y.hash&&Y.hash.length>1)return!0;return!1}catch{return!1}}export{s as shouldUseBrowser,x as rewriteGitHubUrl,b as isPrivateUrl,n as fetchSourceHttp,c as extractContent,T as detectBotBlock,o as defaultFetchHeaders,d as checkContentQuality};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
function
|
|
1
|
+
function P(q){return{bing:"Bing Copilot",google:"Google AI",gemini:"Gemini",copilot:"Copilot",perplexity:"Perplexity"}[q]??q.charAt(0).toUpperCase()+q.slice(1)}function W(q){if(!q)return"";if(q==="official-docs")return"official docs";return q.replace(/-/g," ")}function X(q){if(!q)return"Mixed";return q.charAt(0).toUpperCase()+q.slice(1)}function z(q){return String(q.displayUrl||q.canonicalUrl||q.url||"")}function M(q){return String(q.title||q.domain||z(q)||"Untitled source")}function R(q){if(typeof q.engineCount==="number")return q.engineCount;return(Array.isArray(q.engines)?q.engines:[]).length}function _(q){return new Map(q.map((G)=>[String(G.id||""),G]).filter(([G])=>G))}function D(q){let G=String(q.id||"?"),J=z(q),K=M(q),O=String(q.domain||""),Q=Array.isArray(q.engines)?q.engines:[],V=R(q),Z=W(String(q.sourceType||"")),$=q.fetch,B=$?.ok?`fetched ${$.status||200}`:$?.attempted?"fetch failed":"";return`- ${[`${G} - [${K}](${J})`,O,Z,Q.length?`cited by ${Q.map(P).join(", ")} (${V}/3)`:`${V}/3`,B].filter(Boolean).join(" - ")}`}function b(q,G=[],J=6){if(!q.length)return[];let K=_(q),O=G.map((Q)=>K.get(Q)).filter((Q)=>Boolean(Q));if(O.length>0)return O.slice(0,J);return q.slice(0,J)}function w(q,G,J,K=6){if(G.answer)q.push("## Answer"),q.push(String(G.answer)),q.push("");let O=G.agreement,Q=String(O?.summary||"").trim(),V=String(O?.level||"").trim();if(Q||V)q.push("## Consensus"),q.push(`- ${X(V)}${Q?` - ${Q}`:""}`),q.push("");let Z=Array.isArray(G.differences)?G.differences:[];if(Z.length>0){q.push("## Where Engines Differ");for(let Y of Z)q.push(`- ${Y}`);q.push("")}let $=Array.isArray(G.caveats)?G.caveats:[];if($.length>0){q.push("## Caveats");for(let Y of $)q.push(`- ${Y}`);q.push("")}let B=Array.isArray(G.claims)?G.claims:[];if(B.length>0){q.push("## Key Claims");for(let Y of B){let U=Array.isArray(Y.sourceIds)?Y.sourceIds:[],A=String(Y.support||"moderate");q.push(`- ${String(Y.claim||"")} [${A}${U.length?`; ${U.join(", ")}`:""}]`)}q.push("")}let k=Array.isArray(G.recommendedSources)?G.recommendedSources:[],F=b(J,k,K);if(F.length>0){q.push("## Top Sources");for(let Y of F)q.push(D(Y));q.push("")}}var C=800;function N(q){return q.split(`
|
|
2
|
+
`).map((G)=>G.length>C?G.slice(0,C-1)+"…":G).join(`
|
|
3
|
+
`)}function y(q,G){let J=[];if(q==="all")return N(E(G,J));return N(x(G,J))}function E(q,G){let{_synthesis:J,_sources:K,_needsHumanVerification:O,_research:Q}=q;if(O){let V=Array.isArray(O.engines)?O.engines.join(", "):"one or more engines";G.push("## Manual verification required"),G.push(String(O.message||"Visible Chrome is open. Solve the verification challenge, then rerun the same search.")),G.push(`Engines: ${V}`),G.push("")}if(J?.answer){if(Q?.mode==="iterative")I(G,Q);w(G,J,K||[],6);let V=String(J.synthesizedBy||"configured synthesizer");return G.push(Q?.mode==="iterative"?`*Research mode: iterative planning, source fetching, citation audit, and bundle output*
|
|
2
4
|
`:`*Synthesized by ${V} from multi-engine results and fetched sources*
|
|
3
5
|
`),G.join(`
|
|
4
|
-
`).trim()}for(let[V,
|
|
5
|
-
## ${
|
|
6
|
-
`).trim()}function I(q,G){let J=G.floor,K=J?.metrics,O=G.bundle,Q=G.manifest;if(q.push("## Research Run"),q.push(`- Status: ${J?.floorMet?"floor met":"partial / floor unmet"}`),Q?.terminationReason)q.push(`- Stop reason: ${String(Q.terminationReason)}`);if(K)q.push(`- Evidence: ${K.fetchedOk||0} fetched sources, ${K.primarySources||0} primary/official, ${K.claims||0} claims, ${K.cited||0} citations`),q.push(`- Questions: ${K.closedQuestions||0}/${K.totalQuestions||0} closed${K.openQuestions?`, ${K.openQuestions} open`:""}`);if(O?.dir)q.push(`- Bundle: ${String(O.dir)}`);q.push("")}function
|
|
7
|
-
`).trim()}function
|
|
8
|
-
Sources:`);for(let O of K.slice(0,J))G.push(`- [${O.title||O.url}](${O.url})`)}}export{
|
|
6
|
+
`).trim()}for(let[V,Z]of Object.entries(q)){if(V.startsWith("_"))continue;G.push(`
|
|
7
|
+
## ${P(V)}`),j(Z,G,3)}return G.join(`
|
|
8
|
+
`).trim()}function I(q,G){let J=G.floor,K=J?.metrics,O=G.bundle,Q=G.manifest;if(q.push("## Research Run"),q.push(`- Status: ${J?.floorMet?"floor met":"partial / floor unmet"}`),Q?.terminationReason)q.push(`- Stop reason: ${String(Q.terminationReason)}`);if(K)q.push(`- Evidence: ${K.fetchedOk||0} fetched sources, ${K.primarySources||0} primary/official, ${K.claims||0} claims, ${K.cited||0} citations`),q.push(`- Questions: ${K.closedQuestions||0}/${K.totalQuestions||0} closed${K.openQuestions?`, ${K.openQuestions} open`:""}`);if(O?.dir)q.push(`- Bundle: ${String(O.dir)}`);q.push("")}function x(q,G){let J=q._needsHumanVerification;if(J){let K=Array.isArray(J.engines)?J.engines.join(", "):"this engine";G.push("## Manual verification required"),G.push(String(J.message||"Visible Chrome is open. Solve the verification challenge, then rerun the same search.")),G.push(`Engines: ${K}`),G.push("")}return j(q,G,5),G.join(`
|
|
9
|
+
`).trim()}function j(q,G,J){if(q.error){G.push(`Error: ${q.error}`);return}if(q.answer)G.push(String(q.answer));let K=q.sources;if(Array.isArray(K)&&K.length>0){G.push(`
|
|
10
|
+
Sources:`);for(let O of K.slice(0,J))G.push(`- [${O.title||O.url}](${O.url})`)}}export{y as formatResults};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
var
|
|
1
|
+
var x={"user-agent":"GreedySearch/1.0",accept:"application/vnd.github+json","x-github-api-version":"2022-11-28"};function F(J){try{let z=new URL(J);if(!(z.hostname==="github.com"||z.hostname.endsWith(".github.com")))return null;let j=z.pathname.split("/").filter(Boolean);if(j.length<2)return null;let[q,K]=j;if(j.length===2)return{owner:q,repo:K,type:"root"};if(j.length>=4&&(j[2]==="blob"||j[2]==="tree")){let N=j[2],Q=j[3],C=j.slice(4).join("/");return{owner:q,repo:K,type:N,ref:Q,path:C}}return null}catch{return null}}async function Y(J,z=1e4){let j=new AbortController,q=setTimeout(()=>j.abort(),z);try{let K=await fetch(`https://api.github.com${J}`,{headers:x,signal:j.signal});if(clearTimeout(q),!K.ok)throw Error(`GitHub API ${K.status}: ${J}`);return await K.json()}catch(K){throw clearTimeout(q),K}}async function M(J,z){try{let j=await Y(`/repos/${J}/${z}/readme`);if(j.content&&j.encoding==="base64")return Buffer.from(j.content,"base64").toString("utf8");return""}catch{return""}}async function v(J,z,j="HEAD",q="",K){try{let N;if(j==="HEAD")if(K)N=await Y(`/repos/${J}/${z}/git/ref/heads/${K}`).catch(()=>null);else N=await Promise.any([Y(`/repos/${J}/${z}/git/ref/heads/main`),Y(`/repos/${J}/${z}/git/ref/heads/master`)]).catch(()=>null);else N=await Y(`/repos/${J}/${z}/git/ref/heads/${j}`).catch(()=>Y(`/repos/${J}/${z}/git/ref/heads/master`).catch(()=>null));if(!N?.object?.sha)return[];let C=(await Y(`/repos/${J}/${z}/git/commits/${N.object.sha}`)).tree.sha,X=(await Y(`/repos/${J}/${z}/git/trees/${C}`)).tree||[];if(q)X=X.filter((V)=>V.path.startsWith(q));return X.slice(0,50).map((V)=>({path:V.path,type:V.type==="tree"?"dir":"file",size:V.size}))}catch{return[]}}async function O(J,z,j,q,K=1e4,N){let Q=async(W)=>{let X=new AbortController,V=setTimeout(()=>X.abort(),K);try{let Z=await fetch(W,{headers:{"user-agent":x["user-agent"]},signal:X.signal});if(clearTimeout(V),Z.ok)return await Z.text();throw Error("not ok")}catch{throw clearTimeout(V),Error("failed")}};if(!j||j==="HEAD"){if(N)try{return await Q(`https://raw.githubusercontent.com/${J}/${z}/${N}/${q}`)}catch{return null}try{return await Promise.any([Q(`https://raw.githubusercontent.com/${J}/${z}/main/${q}`),Q(`https://raw.githubusercontent.com/${J}/${z}/master/${q}`)])}catch{return null}}let C=[`https://raw.githubusercontent.com/${J}/${z}/${j}/${q}`,`https://raw.githubusercontent.com/${J}/${z}/master/${q}`];for(let W of C)try{return await Q(W)}catch{}return null}async function U(J){let z=F(J);if(!z)return{ok:!1,error:"Not a valid GitHub URL"};let{owner:j,repo:q,type:K,ref:N,path:Q}=z;try{if(K==="root"||K==="tree"&&!Q){let C=await Y(`/repos/${j}/${q}`),[W,X]=await Promise.allSettled([M(j,q),v(j,q,N||"HEAD","",C.default_branch)]),V=W.status==="fulfilled"?W.value:"",Z=X.status==="fulfilled"?X.value:[],_=C?.description?`
|
|
2
2
|
|
|
3
|
-
> ${
|
|
3
|
+
> ${C.description}`:"",L=C?.stargazers_count==null?"":` ⭐ ${C.stargazers_count}`,S=C?.language?` · ${C.language}`:"",$=`# ${j}/${q}${L}${S}${_}
|
|
4
4
|
|
|
5
|
-
`;if(
|
|
5
|
+
`;if(V)$+=V.slice(0,6000);else $+=`[No README found]
|
|
6
6
|
|
|
7
7
|
Files:
|
|
8
|
-
${
|
|
9
|
-
`)}`;return{ok:!0,title:`${j}/${
|
|
10
|
-
`);return{ok:!0,title:`${j}/${
|
|
8
|
+
${Z.map((k)=>` ${k.type==="dir"?"\uD83D\uDCC1":"\uD83D\uDCC4"} ${k.path}`).join(`
|
|
9
|
+
`)}`;return{ok:!0,title:`${j}/${q}`,content:$,tree:Z.slice(0,30)}}if(K==="blob"&&Q){let C;if(!N||N==="HEAD")try{C=(await Y(`/repos/${j}/${q}`)).default_branch}catch{C=void 0}let W=await O(j,q,N,Q,1e4,C);if(W===null)return{ok:!1,error:`File not found: ${Q}`};return{ok:!0,title:`${j}/${q}: ${Q}`,content:W}}if(K==="tree"&&Q){let C;if(!N||N==="HEAD")try{C=(await Y(`/repos/${j}/${q}`)).default_branch}catch{C=void 0}let W=await v(j,q,N||"HEAD",Q,C),X=W.map((V)=>` ${V.type==="dir"?"\uD83D\uDCC1":"\uD83D\uDCC4"} ${V.path}`).join(`
|
|
10
|
+
`);return{ok:!0,title:`${j}/${q}/${Q}`,content:`[Directory: ${Q}]
|
|
11
11
|
|
|
12
12
|
Files:
|
|
13
|
-
${
|
|
13
|
+
${X}`,tree:W}}return{ok:!1,error:"Unsupported GitHub URL type"}}catch(C){return{ok:!1,error:C.message}}}export{F as parseGitHubUrl,U as fetchGitHubContent};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var X={"user-agent":"GreedySearch/1.0 (Research Bot)",accept:"application/json"};function Z(b){try{let v=new URL(b),B=v.hostname.toLowerCase();if(!(B==="reddit.com"||B.endsWith(".reddit.com")))return null;let q=v.pathname;if(q.match(/^\/(u|user)\/[^/]+\/?$/i))return{type:"user",cleanUrl:O(b)};if(q.match(/^\/r\/[^/]+\/comments\/[^/]+/i))return{type:"post",cleanUrl:O(b)};return null}catch{return null}}function O(b){try{let v=new URL(b);return`${v.protocol}//${v.hostname}${v.pathname}`}catch{return b}}async function $(b,v=8000){let B=Date.now();try{let q=b.
|
|
1
|
+
var X={"user-agent":"GreedySearch/1.0 (Research Bot)",accept:"application/json"};function Z(b){try{let v=new URL(b),B=v.hostname.toLowerCase();if(!(B==="reddit.com"||B.endsWith(".reddit.com")))return null;let q=v.pathname;if(q.match(/^\/(u|user)\/[^/]+\/?$/i))return{type:"user",cleanUrl:O(b)};if(q.match(/^\/r\/[^/]+\/comments\/[^/]+/i))return{type:"post",cleanUrl:O(b)};return null}catch{return null}}function O(b){try{let v=new URL(b);return`${v.protocol}//${v.hostname}${v.pathname}`}catch{return b}}async function $(b,v=8000){let B=Date.now();try{let q=b.replace(/\/+$/,"")+".json",F=new AbortController,G=setTimeout(()=>F.abort(),15000),M=await fetch(q,{headers:X,signal:F.signal});if(clearTimeout(G),!M.ok)throw Error(`Reddit API ${M.status}`);let K=await M.json();if(!Array.isArray(K)||K.length<1)throw Error("Invalid Reddit API response structure");let V=K[0],W=K[1],J=V?.data?.children?.[0]?.data;if(!J)throw Error("No post data in Reddit response");let N=Y(J,W,v);return{ok:!0,url:b,finalUrl:b,status:200,contentType:"text/markdown",lastModified:"",title:J.title||"Reddit Post",byline:`u/${J.author}`,siteName:`r/${J.subreddit}`,lang:"en",publishedTime:new Date(J.created_utc*1000).toISOString(),excerpt:J.selftext?.slice(0,300).replace(/\n/g," ")||"",markdown:N,contentLength:N.length,needsBrowser:!1,duration:Date.now()-B}}catch(q){return{ok:!1,url:b,finalUrl:b,status:0,error:`Reddit fetch failed: ${q.message}`,needsBrowser:!1,duration:Date.now()-B}}}function Y(b,v,B){let q="";if(q+=`# ${b.title}
|
|
2
2
|
|
|
3
3
|
`,q+=`**Subreddit:** r/${b.subreddit} | **Author:** u/${b.author} | **Score:** ${b.score}
|
|
4
4
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import{execFileSync as
|
|
2
|
-
[greedysearch] Available engines: ${Object.keys(
|
|
3
|
-
`);if(
|
|
4
|
-
`)}}}catch{}return
|
|
5
|
-
`,"utf8")}catch{}}
|
|
6
|
-
[greedysearch] Available synthesizers: ${
|
|
7
|
-
[greedysearch] Falling back to default: ${
|
|
8
|
-
`)}}}catch{}return
|
|
1
|
+
import{execFileSync as p,execSync as C}from"node:child_process";import{existsSync as w,mkdirSync as Xq,readFileSync as g,unlinkSync as j,writeFileSync as b}from"node:fs";import{platform as S}from"node:os";import{existsSync as x,mkdirSync as E,readFileSync as P,writeFileSync as i}from"node:fs";import{homedir as r}from"node:os";import{join as F}from"node:path";import{tmpdir as d}from"node:os";function t(q,J=9222){let Q=Number.parseInt(String(q??""),10);return Number.isInteger(Q)&&Q>1024&&Q<65535?Q:J}var a=d().replaceAll("\\","/"),Z=t(process.env.GREEDY_SEARCH_PORT),W=(process.env.GREEDY_SEARCH_PROFILE_DIR||process.env.CDP_PROFILE_DIR||`${a}/greedysearch-chrome-profile`).replaceAll("\\","/"),Hq=`${W}/DevToolsActivePort`,R=process.env.GREEDY_SEARCH_PID_FILE||`${W}/browser.pid`,kq=process.env.CDP_PAGES_CACHE||`${W}/cdp-pages.json`,L=process.env.GREEDY_SEARCH_MODE_FILE||`${W}/browser-mode`,l=process.env.GREEDY_SEARCH_METADATA_FILE||`${W}/browser-metadata.json`,c=process.env.GREEDY_SEARCH_LAUNCH_LOCK_FILE||`${W}/browser-launch.lock`,I=process.env.GREEDY_SEARCH_ACTIVITY_FILE||`${W}/browser-last-activity`,gq=(process.env.CDP_SOCKET_DIR||`${W}/cdp-sockets`).replaceAll("\\","/"),Uq=`${W}/visible-recovery.jsonl`,T=F(r(),".dm"),V=F(T,"greedyconfig"),O=["perplexity","google","chatgpt","gemini"],G="gemini";function e(){try{if(x(V)){let q=P(V,"utf8"),J=JSON.parse(q);if(Array.isArray(J.engines)&&J.engines.length>0&&J.engines.every((Q)=>typeof Q==="string")){let Q=J.engines.filter(($)=>Y[$]),X=J.engines.filter(($)=>!Y[$]);if(X.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${V}: ${X.join(", ")}
|
|
2
|
+
[greedysearch] Available engines: ${Object.keys(Y).join(", ")}
|
|
3
|
+
`);if(Q.length>0)return Q;process.stderr.write(`[greedysearch] Warning: no valid engines in ${V}, falling back to defaults: ${O.join(", ")}
|
|
4
|
+
`)}}}catch{}return O}function qq(){try{if(!x(T))E(T,{recursive:!0});if(!x(V))i(V,JSON.stringify({engines:O,synthesizer:G},null,2)+`
|
|
5
|
+
`,"utf8")}catch{}}qq();var D=["gemini","chatgpt"];function Jq(){try{if(x(V)){let q=P(V,"utf8"),J=JSON.parse(q);if(typeof J.synthesizer==="string"){let Q=J.synthesizer.toLowerCase();if(D.includes(Q))return Q;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${J.synthesizer}" in ${V}
|
|
6
|
+
[greedysearch] Available synthesizers: ${D.join(", ")}
|
|
7
|
+
[greedysearch] Falling back to default: ${G}
|
|
8
|
+
`)}}}catch{}return G}var Y={perplexity:"perplexity.mjs",p:"perplexity.mjs",bing:"bing-copilot.mjs",b:"bing-copilot.mjs",google:"google-ai.mjs",g:"google-ai.mjs",gemini:"gemini.mjs",gem:"gemini.mjs",chatgpt:"chatgpt.mjs",gpt:"chatgpt.mjs","semantic-scholar":"semantic-scholar.mjs",semanticscholar:"semantic-scholar.mjs",s2:"semantic-scholar.mjs",logically:"logically.mjs",log:"logically.mjs"},vq=e();var hq=Jq(),Mq=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=W;import{existsSync as _}from"node:fs";import{platform as Qq}from"node:os";import{join as z}from"node:path";function B(q){let J=Qq()==="win32",Q=process.env.SystemRoot||"C:\\Windows",X={win32:{powershell:z(Q,"System32","WindowsPowerShell","v1.0","powershell.exe"),powershell_ise:z(Q,"System32","WindowsPowerShell","v1.0","powershell_ise.exe"),netstat:z(Q,"System32","netstat.exe"),taskkill:z(Q,"System32","taskkill.exe"),tasklist:z(Q,"System32","tasklist.exe"),cmd:z(Q,"System32","cmd.exe")},unix:{ps:"/usr/bin/ps",lsof:"/usr/bin/lsof",ss:"/usr/sbin/ss",grep:"/usr/bin/grep",kill:"/usr/bin/kill"}},$=J?X.win32:X.unix,k=q.toLowerCase();if($[k]&&_($[k]))return $[k];if(J&&k==="netstat"){let M=z(Q,"Sysnative","netstat.exe");if(_(M))return M}return q}var f=l,K=c,$q=15000,N=R,u=L,v=I;function H(q){if(!Number.isInteger(q)||q<=0)return!1;try{return process.kill(q,0),!0}catch{return!1}}function Wq(q){if(!H(q))return null;try{if(S()==="win32")return p(B("powershell"),["-NoProfile","-NonInteractive","-Command",`(Get-CimInstance Win32_Process -Filter "ProcessId = ${q}").CommandLine`],{encoding:"utf8",windowsHide:!0,timeout:5000}).trim()||null;return p(B("ps"),["-p",String(q),"-o","command="],{encoding:"utf8",timeout:5000}).trim()||null}catch{return null}}function Zq(q,J,Q=Z){if(!q)return!1;let X=(M)=>String(M||"").replaceAll("\\","/").toLowerCase(),$=X(q),k=X(J);return $.includes(k)&&$.includes(`--remote-debugging-port=${Q}`)&&!$.includes("--type=")}function U(q,J,Q=Z){return Zq(Wq(q),J,Q)}function y(q=Z){try{if(S()==="win32"){let Q=C(`${B("netstat")} -ano -p TCP 2>nul`,{encoding:"utf8"}),X=new RegExp(String.raw`TCP\s+\S+:${q}\s+\S+:0\s+LISTENING\s+(\d+)`,"i"),$=Q.match(X);return $?Number.parseInt($[1],10):null}let J=C(`${B("lsof")} -i :${q} -t 2>/dev/null || ${B("ss")} -tlnp 2>/dev/null | ${B("grep")} :${q} | ${B("grep")} -oP 'pid=\\K\\d+'`,{encoding:"utf8"}).trim();return J?Number.parseInt(J.split(`
|
|
9
|
+
`)[0],10):null}catch{return null}}function Vq(q,J=null,Q=null){if(J&&!U(q,J,Q))return!1;try{if(S()==="win32")C(`${B("taskkill")} /F /T /PID ${q}`,{stdio:"ignore"});else{try{process.kill(-q,"SIGKILL")}catch{}try{process.kill(q,"SIGKILL")}catch{}}return!0}catch{return!1}}function o(){try{if(w(f)){let q=g(f,"utf8"),J=JSON.parse(q);if(J&&typeof J.tempDir==="string"&&typeof J.debugPort==="number")return{browserPid:Number.isInteger(J.browserPid)?J.browserPid:void 0,debugPort:J.debugPort,tempDir:J.tempDir,clientPids:Array.isArray(J.clientPids)?J.clientPids.filter((Q)=>Number.isInteger(Q)&&Q>0):[],sessionMode:J.sessionMode==="visible"?"visible":"headless",lastActivity:Number.isFinite(J.lastActivity)?J.lastActivity:0,launchedAt:Number.isFinite(J.launchedAt)?J.launchedAt:0}}}catch{}try{let q=w(N)?Number.parseInt(g(N,"utf8").trim(),10)||void 0:void 0,J=w(u)?g(u,"utf8").trim()==="visible"?"visible":"headless":"headless",Q=w(v)?Number.parseInt(g(v,"utf8").trim(),10)||0:0;return{browserPid:q,debugPort:Z,tempDir:W,clientPids:q?[q]:[],sessionMode:J,lastActivity:Q,launchedAt:0}}catch{return null}}function h(q){try{b(f,JSON.stringify({browserPid:q.browserPid,debugPort:q.debugPort,tempDir:q.tempDir,clientPids:[...new Set(q.clientPids.filter((J)=>J>0))],sessionMode:q.sessionMode,lastActivity:q.lastActivity,launchedAt:q.launchedAt},null,2),"utf8")}catch{}try{if(q.browserPid)b(N,String(q.browserPid),"utf8")}catch{}try{b(u,q.sessionMode,"utf8")}catch{}try{b(v,String(q.lastActivity),"utf8")}catch{}}function A(){try{j(f)}catch{}try{j(N)}catch{}try{j(u)}catch{}try{j(v)}catch{}}function Cq(q){if(!q)return q;let J={...q,clientPids:[...new Set([...q.clientPids,process.pid].filter((Q)=>H(Q)||Q===process.pid))]};return h(J),J}function yq(q){if(!q)return q;let J={...q,clientPids:q.clientPids.filter((Q)=>Q!==process.pid).filter((Q)=>H(Q))};return h(J),J}function Sq(q){let J=Date.now();try{if(q)h({...q,lastActivity:J});else b(v,String(J),"utf8")}catch{}}var m=Number.parseInt(process.env.GREEDY_SEARCH_IDLE_TIMEOUT_MINUTES||"5",10)||5;function Dq(q){if(m<=0)return!1;if(!q||!q.lastActivity)return!1;return(Date.now()-q.lastActivity)/60000>=m}var n=!1;function Bq(){if(process.env.GREEDY_SEARCH_RESEARCH_CHILD)return;if(n)return;n=!0;let q=o();if(!q)return;if(q.browserPid){if(!H(q.browserPid)){A();return}if(!U(q.browserPid,q.tempDir,q.debugPort))A();else h({...q,clientPids:q.clientPids.filter(($)=>H($))})}let J=y();if(J&&J!==q.browserPid)if(U(J,W,Z))h({browserPid:J,debugPort:Z,tempDir:W,clientPids:[J],sessionMode:q.sessionMode,lastActivity:Date.now(),launchedAt:Date.now()});else process.stderr.write(`[greedysearch] Refusing to kill unverified listener ${J} on port ${Z}.
|
|
10
|
+
`)}function Pq(){Xq(W,{recursive:!0});try{let q=JSON.stringify({pid:process.pid,ts:Date.now()});return b(K,q,{encoding:"utf8",flag:"wx"}),{acquired:!0,release:()=>{try{let J=g(K,"utf8");if(JSON.parse(J).pid===process.pid)j(K)}catch{}}}}catch(q){if(q?.code!=="EEXIST")return{acquired:!1,release:()=>{}}}try{let q=g(K,"utf8"),J=JSON.parse(q),Q=Date.now()-(J.ts||0);if(!H(J.pid)||Q>$q){try{j(K)}catch{}try{let $=JSON.stringify({pid:process.pid,ts:Date.now()});return b(K,$,{encoding:"utf8",flag:"wx"}),{acquired:!0,release:()=>{try{j(K)}catch{}}}}catch{return{acquired:!1,release:()=>{}}}}}catch{}return{acquired:!1,release:()=>{}}}function s(){let q=o();if(!q||!q.browserPid){let X=y();if(X&&U(X,W,Z))return{running:!0,pid:X,metadata:q};return{running:!1,pid:null,metadata:null}}if(!H(q.browserPid))return{running:!1,pid:null,metadata:q};if(!U(q.browserPid,q.tempDir,q.debugPort)){let X=y();if(X&&U(X,W,Z))return{running:!0,pid:X,metadata:q};return{running:!1,pid:null,metadata:q}}return{running:!0,pid:q.browserPid,metadata:q}}function Fq(){let{running:q,pid:J,metadata:Q}=s();if(!q||!J)return A(),!1;let X=Vq(J,Q?.tempDir||W,Q?.debugPort||Z);return A(),X}async function Rq(){return Bq(),s()}export{h as writeMetadata,U as verifyBrowserProcess,yq as unregisterClient,Sq as touchActivity,Cq as registerClient,o as readMetadata,Fq as killChrome,Dq as isIdleExpired,Rq as ensureCleanSession,Zq as commandLineMatchesGreedyChrome,A as clearMetadata,Bq as cleanupStaleSessions,s as checkRunning,Pq as acquireLaunchLock,f as METADATA_FILE};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import{spawn as m}from"node:child_process";import{basename as h}from"node:path";import{dirname as _,join as w}from"node:path";import{fileURLToPath as b}from"node:url";function y(e=process.env,r=process.execPath){let t=e.GREEDY_SEARCH_NODE||e.NODE_BINARY||e.NODE;if(t?.trim())return t.trim();let o=h(r||"").toLowerCase();if(o==="node"||o==="node.exe")return r;return"node"}var v=_(b(import.meta.url)),x=w(v,"..","bin","cdp.mjs"),P=new Set(["list","snap","eval","shot","html","nav","net","click","clickxy","type","loadall","evalraw","browse","stop","--tab"]);function D(e){if(!Array.isArray(e)||e.length===0)throw Error("cdp: args must be a non-empty array");if(e[0]==="test")return e.map((r,t)=>p(r,t));if(!P.has(e[0]))throw Error(`cdp: unknown subcommand '${e[0]}'`);return e.map((r,t)=>p(r,t))}function p(e,r){if(typeof e!=="string")throw Error(`cdp: argv[${r}] must be a string (got ${typeof e})`);if(e.includes("\x00"))throw Error(`cdp: argv[${r}] contains a null byte`);return e}function u(e,r=30000){return O(e,null,r)}function O(e,r=null,t=30000){let o=D(e);return new Promise((d,l)=>{let n=m(y(),[x,...o],{stdio:[r==null?"ignore":"pipe","pipe","pipe"]});if(r!=null)n.stdin.write(r),n.stdin.end();let s="",c="";n.stdout.on("data",(a)=>s+=a),n.stderr.on("data",(a)=>c+=a);let i=setTimeout(()=>{n.kill(),l(Error(`cdp timeout: ${e[0]}`))},t);n.on("close",(a)=>{if(clearTimeout(i),a===0)d(s.trim());else l(Error(c.trim()||`cdp exit ${a}`))})})}var k=Number.parseInt(process.env.GREEDY_SEARCH_CHALLENGE_WAIT_MS||"300000",10),T=3000,f={chatgpt:{name:"chatgpt",isCleared:async(e)=>{let r=await u(["eval",e,`(() => {
|
|
2
|
+
const title = document.title;
|
|
3
|
+
const onChatGPT = location.hostname === "chatgpt.com";
|
|
4
|
+
const hasProseMirror = !!document.querySelector("div.ProseMirror");
|
|
5
|
+
const hasTurnstileInput =
|
|
6
|
+
!!document.querySelector("input[name=\\"cf-turnstile-response\\"]") ||
|
|
7
|
+
!!document.querySelector("iframe[id^=\\"cf-chl-widget-\\"]");
|
|
8
|
+
// Body innerText is empty while on the Turnstile page.
|
|
9
|
+
const bodyText = (document.body && document.body.innerText) || "";
|
|
10
|
+
return JSON.stringify({
|
|
11
|
+
title,
|
|
12
|
+
url: location.href,
|
|
13
|
+
hasProseMirror,
|
|
14
|
+
hasTurnstileInput,
|
|
15
|
+
bodyLen: bodyText.length,
|
|
16
|
+
onChatGPT,
|
|
17
|
+
});
|
|
18
|
+
})()`]).catch(()=>null);if(!r)return!1;let t;try{t=JSON.parse(r)}catch{return!1}if(!t.onChatGPT)return!1;if(t.title&&/περιμένετε|please wait|just a moment|verifying|checking/i.test(t.title))return!1;if(t.hasTurnstileInput)return!1;return t.hasProseMirror||t.bodyLen>50}},bing:{name:"bing",isCleared:async(e)=>{let r=await u(["eval",e,`(() => {
|
|
19
|
+
const url = location.href;
|
|
20
|
+
const title = document.title;
|
|
21
|
+
const onCopilot = /copilot\\.microsoft\\.com/.test(location.hostname);
|
|
22
|
+
const onChallenge =
|
|
23
|
+
/challenge|turnstile|cdn-cgi\\/challenge/i.test(url) ||
|
|
24
|
+
/verify|human|robot/i.test(title);
|
|
25
|
+
const hasTextarea =
|
|
26
|
+
!!document.querySelector("textarea") ||
|
|
27
|
+
!!document.querySelector("div[contenteditable=\\"true\\"]");
|
|
28
|
+
const hasTurnstileInput =
|
|
29
|
+
!!document.querySelector("iframe[id^=\\"cf-chl-widget-\\"]") ||
|
|
30
|
+
!!document.querySelector("input[name=\\"cf-turnstile-response\\"]");
|
|
31
|
+
const bodyText = (document.body && document.body.innerText) || "";
|
|
32
|
+
return JSON.stringify({
|
|
33
|
+
url,
|
|
34
|
+
title,
|
|
35
|
+
onCopilot,
|
|
36
|
+
onChallenge,
|
|
37
|
+
hasTextarea,
|
|
38
|
+
hasTurnstileInput,
|
|
39
|
+
bodyLen: bodyText.length,
|
|
40
|
+
});
|
|
41
|
+
})()`]).catch(()=>null);if(!r)return!1;let t;try{t=JSON.parse(r)}catch{return!1}if(!t.onCopilot)return!1;if(t.onChallenge)return!1;if(t.hasTurnstileInput)return!1;return t.hasTextarea||t.bodyLen>50}}};async function C(e){let r=await u(["eval",e,`(() => {
|
|
42
|
+
const cookies = document.cookie || "";
|
|
43
|
+
return JSON.stringify({
|
|
44
|
+
hasCfClearance: /(?:^|;\\s*)cf_clearance=/.test(cookies),
|
|
45
|
+
hasCfBm: /(?:^|;\\s*)__cf_bm=/.test(cookies),
|
|
46
|
+
cookiesLength: cookies.length,
|
|
47
|
+
});
|
|
48
|
+
})()`]).catch(()=>null);if(!r)return!1;try{let t=JSON.parse(r);return t.hasCfClearance||t.hasCfBm}catch{return!1}}async function M({tab:e,engine:r,timeoutMs:t=k,intervalMs:o=T,signal:d,log:l=()=>{}}){let n=f[r],s=Date.now(),c=null;while(Date.now()-s<t){if(d?.aborted)return{cleared:!1,reason:"aborted"};let i=Math.floor((Date.now()-s)/1000),a=!1;if(n)a=await n.isCleared(e).catch(()=>!1);else a=await C(e).catch(()=>!1);if(a)return l(`[greedysearch] ✅ ${r} challenge cleared after ${i}s — auto-resuming extraction.`),{cleared:!0,signal:n?"dom-marker":"cookie"};if(i>0&&i%30===0&&c!==i)c=i,l(`[greedysearch] ⏳ Waiting for ${r} challenge to clear (${i}s/${Math.floor(t/1000)}s)...`);await new Promise((g)=>setTimeout(g,o))}return{cleared:!1,reason:`Challenge not cleared within ${Math.floor(t/1000)}s`}}var N=Object.keys(f);export{M as waitForChallengeCleared,N as CHALLENGE_ENGINES};
|