@duckmind/dm-darwin-x64 0.43.8 → 0.48.5
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.
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import{spawn as
|
|
2
|
-
[greedysearch] Available engines: ${Object.keys(
|
|
3
|
-
`);if(i.length>0)return i;process.stderr.write(`[greedysearch] Warning: no valid engines in ${
|
|
4
|
-
`)}}}catch{}return U}function
|
|
5
|
-
`,"utf8")}catch{}}
|
|
1
|
+
import{spawn as ve}from"node:child_process";import{basename as B}from"node:path";function H(t=process.env,e=process.execPath){let i=t.GREEDY_SEARCH_NODE||t.NODE_BINARY||t.NODE;if(i?.trim())return i.trim();let o=B(e||"").toLowerCase();if(o==="node"||o==="node.exe")return e;return"node"}import{existsSync as O,mkdirSync as V,readFileSync as k,writeFileSync as F}from"node:fs";import{homedir as z}from"node:os";import{join as M}from"node:path";import{tmpdir as T}from"node:os";var N=`${T().replaceAll("\\","/")}/greedysearch-chrome-profile`,we=`${N}/DevToolsActivePort`,Ue=`${T().replaceAll("\\","/")}/cdp-pages.json`,We=`${T().replaceAll("\\","/")}/greedysearch-chrome-mode`,De=`${T().replaceAll("\\","/")}/greedysearch-visible-recovery.jsonl`,w=M(z(),".dm"),E=M(w,"greedyconfig"),U=["perplexity","google","chatgpt"],W="gemini";function ee(){try{if(O(E)){let t=k(E,"utf8"),e=JSON.parse(t);if(Array.isArray(e.engines)&&e.engines.length>0&&e.engines.every((i)=>typeof i==="string")){let i=e.engines.filter((s)=>y[s]),o=e.engines.filter((s)=>!y[s]);if(o.length>0)process.stderr.write(`[greedysearch] Warning: ignoring unknown engine(s) in ${E}: ${o.join(", ")}
|
|
2
|
+
[greedysearch] Available engines: ${Object.keys(y).join(", ")}
|
|
3
|
+
`);if(i.length>0)return i;process.stderr.write(`[greedysearch] Warning: no valid engines in ${E}, falling back to defaults: ${U.join(", ")}
|
|
4
|
+
`)}}}catch{}return U}function ie(){try{if(!O(w))V(w,{recursive:!0});if(!O(E))F(E,JSON.stringify({engines:U,synthesizer:W},null,2)+`
|
|
5
|
+
`,"utf8")}catch{}}ie();var C=["gemini","chatgpt"];function te(){try{if(O(E)){let t=k(E,"utf8"),e=JSON.parse(t);if(typeof e.synthesizer==="string"){let i=e.synthesizer.toLowerCase();if(C.includes(i))return i;process.stderr.write(`[greedysearch] Warning: unknown synthesizer "${e.synthesizer}" in ${E}
|
|
6
6
|
[greedysearch] Available synthesizers: ${C.join(", ")}
|
|
7
|
-
[greedysearch] Falling back to default: ${
|
|
8
|
-
`)}}}catch{}return
|
|
9
|
-
`)e+="\\n";else if(i&&
|
|
10
|
-
${JSON.stringify(
|
|
7
|
+
[greedysearch] Falling back to default: ${W}
|
|
8
|
+
`)}}}catch{}return W}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"},ne=ee();var Le=te(),He=Math.max(1,Number.parseInt(process.env.GREEDY_FETCH_CONCURRENCY||"5",10)||5);process.env.CDP_PROFILE_DIR=N;var oe=["fbclid","gclid","ref","ref_src","ref_url","source","utm_campaign","utm_content","utm_medium","utm_source","utm_term"],se=["dev.to","hashnode.com","medium.com","reddit.com","stackoverflow.com","stackexchange.com","substack.com"],le=["arstechnica.com","techcrunch.com","theverge.com","venturebeat.com","wired.com","zdnet.com"],J=["facebook.com","instagram.com","linkedin.com","pinterest.com","tiktok.com","twitter.com","x.com"];function v(t="",e=240){let i=String(t).replaceAll(/\s+/g," ").trim();if(i.length<=e)return i;let o=i.slice(0,e),s=o.lastIndexOf(" ");return s>0?`${o.slice(0,s)}...`:`${o}...`}function D(t=""){let e=v(t,180);if(!e)return"";if(/^https?:\/\//i.test(e))return"";let i=e.split(/\s+/).filter(Boolean).length,o=/[A-Z]/.test(e),s=/\d/.test(e);return e===e.toLowerCase()&&i<=4&&!o&&!s?"":e}function G(t="",e=""){let i=D(t),o=D(e);if(!o)return i;if(!i)return o;let s=/^https?:\/\//i.test(i),r=/^https?:\/\//i.test(o);if(s&&!r)return o;if(!s&&r)return i;return o.length>i.length?o:i}function ce(t){if(!t)return null;try{let e=new URL(t);if(!["http:","https:"].includes(e.protocol))return null;if(e.hash="",e.hostname=e.hostname.toLowerCase(),e.protocol==="https:"&&e.port==="443"||e.protocol==="http:"&&e.port==="80")e.port="";for(let s of[...e.searchParams.keys()]){let r=s.toLowerCase();if(oe.includes(r)||r.startsWith("utm_"))e.searchParams.delete(s)}e.searchParams.sort();let i=e.pathname.replace(/\/{1,10}$/,"")||"/";e.pathname=i;let o=e.toString();return i==="/"?o.replace(/\/$/,""):o}catch{return null}}function re(t){try{return new URL(t).hostname.toLowerCase().replace(/^www\./,"")}catch{return""}}function _(t,e){return e.some((i)=>t===i||t.endsWith(`.${i}`))}function ae(t,e="",i=""){let o=e.toLowerCase(),s=i.toLowerCase();if(t==="github.com"||t==="gitlab.com")return"repo";if(t==="arxiv.org"||t==="doi.org"||t==="semanticscholar.org"||t.endsWith(".semanticscholar.org")||s.includes("/paper/")||s.includes("/pdf/"))return"academic";if(_(t,J))return"social";if(_(t,se))return"community";if(_(t,le))return"news";if(t.startsWith("docs.")||t.startsWith("developer.")||t.startsWith("developers.")||t.startsWith("api.")||o.includes("documentation")||o.includes("docs")||o.includes("reference")||s.includes("/docs/")||s.includes("/reference/")||s.includes("/api/"))return"official-docs";if(t.startsWith("blog.")||s.includes("/blog/"))return"maintainer-blog";return"website"}function fe(t){switch(t){case"official-docs":return 5;case"repo":return 4;case"academic":return 4;case"maintainer-blog":return 3;case"website":return 2;case"community":return 1;case"news":return 0;case"social":return-6;default:return 0}}function ge(t){let e=Object.values(t.perEngine||{}).map((i)=>i?.rank||99);return e.length?Math.min(...e):99}var pe=["reddit.com","news.ycombinator.com","lobste.rs"];function R(t){return t.smartScore*3+t.engineCount*5+fe(t.sourceType)*2+Math.max(0,7-ge(t))}function ue(t){let e=t.toLowerCase(),i=[];if(e.includes("openai")||e.includes("gpt")||e.includes("chatgpt"))i.push("openai.com","platform.openai.com","help.openai.com");if(e.includes("anthropic")||e.includes("claude"))i.push("anthropic.com","docs.anthropic.com");if(e.includes("bun"))i.push("bun.sh","bun.com");if(e.includes("next.js")||e.includes("nextjs"))i.push("nextjs.org","vercel.com");if(e.includes("playwright"))i.push("playwright.dev");if(e.includes("supabase"))i.push("supabase.com","supabase.io");if(e.includes("prisma"))i.push("prisma.io");if(e.includes("tailwind"))i.push("tailwindcss.com");if(e.includes("vite"))i.push("vitejs.dev","vite.dev");if(e.includes("astro"))i.push("astro.build");if(e.includes("svelte"))i.push("svelte.dev");if(e.includes("solid"))i.push("solidjs.com");if(e.includes("vue")||e.includes("nuxt"))i.push("vuejs.org","nuxt.com");if(e.includes("react")||e.includes("react native"))i.push("react.dev","reactnative.dev");if(e.includes("angular"))i.push("angular.io","angular.dev");if(e.includes("node.js")||e.includes("nodejs"))i.push("nodejs.org","nodejs.dev","npmjs.com");if(/\bgo\b/.test(e)||e.includes("golang"))i.push("go.dev","golang.org","pkg.go.dev");if(e.includes("deno"))i.push("deno.land","deno.com");if(e.includes("fresh"))i.push("fresh.deno.dev");if(e.includes("typescript")||e.includes("ts"))i.push("typescriptlang.org");if(e.includes("python"))i.push("python.org","docs.python.org");if(e.includes("rust"))i.push("rust-lang.org","docs.rs","crates.io");if(e.includes("zig"))i.push("ziglang.org");if(e.includes("docker"))i.push("docker.com","docs.docker.com","hub.docker.com");if(e.includes("kubernetes")||e.includes("k8s"))i.push("kubernetes.io","k8s.io");if(e.includes("postgres")||e.includes("postgresql"))i.push("postgresql.org","neon.tech","supabase.com");if(e.includes("redis"))i.push("redis.io");if(e.includes("sqlite"))i.push("sqlite.org");if(e.includes("cloudflare"))i.push("developers.cloudflare.com","cloudflare.com");if(e.includes("vercel"))i.push("vercel.com","nextjs.org");if(e.includes("netlify"))i.push("netlify.com","docs.netlify.com");if(e.includes("stripe"))i.push("stripe.com","docs.stripe.com");if(e.includes("github"))i.push("github.com","docs.github.com");if(e.includes("gitlab"))i.push("gitlab.com","docs.gitlab.com");if(e.includes("aws"))i.push("aws.amazon.com","docs.aws.amazon.com");if(e.includes("azure"))i.push("azure.microsoft.com","learn.microsoft.com");if(e.includes("gcp")||e.includes("google cloud"))i.push("cloud.google.com","developers.google.com");if(e.includes("gemini")||e.includes("google ai"))i.push("ai.google.dev","developers.google.com");for(let o of J){let s=o.replace(/\.com$/,"");if(e.includes(s))i.push(o)}return[...new Set(i)]}function I(t,e){return t===e||t.endsWith(`.${e}`)}function Y(t,e=""){let i=new Map,o=Object.keys(t||{}).filter((n)=>!n.startsWith("_")),s=ue(e);for(let n of o){let c=t[n];if(!c?.sources)continue;for(let a=0;a<c.sources.length;a++){let h=c.sources[a],g=ce(h.url);if(!g||g.length<10)continue;let j=D(h.title||""),u=re(g),d=ae(u,j,g),m=0;if(s.some(($)=>I(u,$)))m+=10;if(d==="official-docs")m+=3;let Q=g.toLowerCase();if(/\/docs\/|\/documentation\/|\.dev\/|\/api\/|\/reference\//.test(Q))m+=2;let q=s.some(($)=>I(u,$));if(d==="social"&&!q)m-=20;if(s.length>0){if(_(u,pe))m-=3;else if(d==="community"&&!_(u,["stackoverflow.com","stackexchange.com"]))m-=1}let p=i.get(g)||{id:"",canonicalUrl:g,displayUrl:h.url||g,domain:u,title:"",engines:[],engineCount:0,perEngine:{},sourceType:d,isOfficial:d==="official-docs",smartScore:0};if(p.title=G(p.title,j),p.displayUrl=p.displayUrl||h.url||g,p.sourceType=p.sourceType||d,p.isOfficial=p.isOfficial||d==="official-docs",p.smartScore=Math.max(p.smartScore,m),!p.engines.includes(n))p.engines.push(n);p.perEngine[n]={rank:a+1,title:G(p.perEngine[n]?.title||"",j)},i.set(g,p)}}let r=Array.from(i.values()).map((n)=>({...n,engineCount:n.engines.length})),f=r.filter((n)=>n.sourceType!=="social"),l=r.filter((n)=>n.sourceType==="social");return f.sort((n,c)=>{let a=R(c)-R(n);if(a!==0)return a;return n.domain.localeCompare(c.domain)}),l.sort((n,c)=>{let a=R(c)-R(n);if(a!==0)return a;return n.domain.localeCompare(c.domain)}),[...f,...l].slice(0,12).map((n,c)=>({...n,id:`S${c+1}`,title:n.title||n.domain||n.canonicalUrl}))}function me(t){let e="",i=!1,o=!1;for(let s of String(t)){if(o){e+=s,o=!1;continue}if(s==="\\"){e+=s,o=!0;continue}if(s==='"'){i=!i,e+=s;continue}if(i&&s===`
|
|
9
|
+
`)e+="\\n";else if(i&&s==="\r")e+="\\r";else if(i&&s==="\t")e+="\\t";else e+=s}return e}function Z(t){if(!t)return null;let e=String(t).trim(),i=e.indexOf("BEGIN_JSON"),o=e.indexOf("END_JSON");if(i!==-1&&o!==-1&&i<o)e=e.slice(i+10,o).trim();else{let l=e.indexOf("{");if(l>0)e=e.slice(l)}let s=[e,e.replace(/^```json\s*/i,"").replace(/^```\s*/i,"").replace(/```$/i,"").trim()],r=e.indexOf("{"),f=e.lastIndexOf("}");if(r!==-1&&f!==-1&&r<f)s.push(e.slice(r,f+1));for(let l of[...s]){let n=me(l);if(n!==l)s.push(n)}for(let l of s)try{return JSON.parse(l)}catch{}return null}function x(t,e,i=""){let o=new Set(e.map((n)=>n.id)),s=["high","medium","low","mixed","conflicting"].includes(t?.agreement?.level)?t.agreement.level:"mixed",r=Array.isArray(t?.claims)?t.claims.map((n)=>({claim:v(n?.claim||"",260),support:["strong","moderate","weak","conflicting"].includes(n?.support)?n.support:"moderate",sourceIds:Array.isArray(n?.sourceIds)?n.sourceIds.filter((c)=>o.has(c)):[]})).filter((n)=>n.claim):[],f=Array.isArray(t?.recommendedSources)?t.recommendedSources.filter((n)=>o.has(n)).slice(0,6):[],l="";if(i){let n=i.indexOf("{"),c=i.lastIndexOf("}");if(n!==-1&&c!==-1&&n<c)l=i.slice(n,c+1);else l=i}return{answer:v(t?.answer||l||i,4000),agreement:{level:s,summary:v(t?.agreement?.summary||"",280)},differences:Array.isArray(t?.differences)?t.differences.map((n)=>v(n,220)).filter(Boolean).slice(0,5):[],caveats:Array.isArray(t?.caveats)?t.caveats.map((n)=>v(n,220)).filter(Boolean).slice(0,5):[],claims:r,recommendedSources:f}}function A(t,e,i,{grounded:o=!1}={}){let s={};for(let l of["perplexity","bing","google"]){let n=e[l];if(!n)continue;if(n.error){s[l]={status:"error",error:String(n.error)};continue}s[l]={status:"ok",answer:v(n.answer||"",o?4500:2200),sourceIds:i.filter((c)=>c.engines.includes(l)).sort((c,a)=>(c.perEngine[l]?.rank||99)-(a.perEngine[l]?.rank||99)).map((c)=>c.id).slice(0,6)}}let r=o?700:300,f=i.slice(0,o?10:8).map((l)=>({id:l.id,title:l.title,domain:l.domain,canonicalUrl:l.canonicalUrl,sourceType:l.sourceType,isOfficial:l.isOfficial,engines:l.engines,engineCount:l.engineCount,fetch:l.fetch?.attempted?{ok:l.fetch.ok,publishedTime:l.fetch.publishedTime||"",byline:l.fetch.byline||"",snippet:v(l.fetch.snippet||"",r)}:void 0}));return["You are a research synthesizer. Combine these search engine results into a single authoritative answer.","",`Query: ${t}`,"",`Engine summaries:
|
|
10
|
+
${JSON.stringify(s,null,2)}`,"",`Source registry:
|
|
11
11
|
${JSON.stringify(f,null,2)}`,"","Instructions:","- Write a clear, direct answer in markdown (use headers/bullets where they help readability)","- Cite sources inline as [S1], [S2] etc. when making specific claims","- Prefer sources with content (fetch.ok=true and non-empty snippet) for citations","- Note where the engines agree or meaningfully disagree","- List any important caveats or limitations","- recommendedSources: the 2-4 source IDs most worth reading for this query","","Respond ONLY with a JSON object wrapped in BEGIN_JSON / END_JSON markers:","","BEGIN_JSON",JSON.stringify({answer:"<your markdown answer here>",agreement:{level:"high|medium|mixed|conflicting",summary:"<one sentence>"},differences:["<notable difference between engines, if any>"],caveats:["<important caveat or limitation>"],recommendedSources:["S1","S2"]},null,2),"END_JSON"].join(`
|
|
12
|
-
`)}import{existsSync as
|
|
12
|
+
`)}import{existsSync as S}from"node:fs";import{dirname as he,join as b}from"node:path";import{fileURLToPath as de}from"node:url";function P(t){return de(new URL(".",t)).replace(/^\/([A-Z]:)/,"$1")}function Ee(t,e=S){let i=new Set;for(let o of t.filter(Boolean)){if(i.has(o))continue;if(i.add(o),e(o))return o}return t.filter(Boolean).at(-1)}function K(t,{moduleDir:e,entrypoint:i=process.argv[1],env:o=process.env,exists:s=S}={}){let r=i?he(i):null,f=o.GREEDY_SEARCH_EXTENSION_DIR?.trim()||null,l=[e?b(e,"..","..","extractors",t):null,e?b(e,"..","extractors",t):null,f?b(f,"extractors",t):null,r?b(r,"..","extractors",t):null];return Ee(l,s)}var je=P(import.meta.url),Ce={gemini:"gemini.mjs",chatgpt:"chatgpt.mjs"},_e={gemini:"https://gemini.google.com/app",chatgpt:"https://chatgpt.com/"};function L(t="gemini"){let e=String(t||"gemini").toLowerCase();if(e==="gem")return"gemini";if(e==="gpt")return"chatgpt";return e}function Be(t="gemini"){return _e[L(t)]||"about:blank"}async function X(t,e,{tabPrefix:i=null,timeoutMs:o=180000,visible:s=null}={}){let r=L(t),f=Ce[r];if(!f||!C.includes(r))throw Error(`Unsupported synthesizer "${t}". Supported: ${C.join(", ")}`);return new Promise((l,n)=>{let c=i?["--tab",String(i)]:[],a=K(f,{moduleDir:je}),h={...process.env,CDP_PROFILE_DIR:N};if(s!==!0)delete h.GREEDY_SEARCH_VISIBLE,delete h.GREEDY_SEARCH_ALWAYS_VISIBLE;else h.GREEDY_SEARCH_VISIBLE="1",h.GREEDY_SEARCH_ALWAYS_VISIBLE="1";let g=ve(H(),[a,"--stdin",...c],{stdio:["pipe","pipe","pipe"],env:h});g.stdin.write(e),g.stdin.end();let j="",u="";g.stdout.on("data",(m)=>j+=m),g.stderr.on("data",(m)=>u+=m);let d=setTimeout(()=>{g.kill(),n(Error(`${r} prompt timed out after ${o/1000}s`))},o);g.on("close",(m)=>{if(clearTimeout(d),m!==0){n(Error(u.trim()||`${r} extractor failed`));return}try{l(JSON.parse(j.trim()))}catch{n(Error(`bad JSON from ${r}: ${j.slice(0,100)}`))}})})}async function Ve(t,e={}){return X("gemini",t,e)}async function Oe(t,e,{grounded:i=!1,tabPrefix:o=null,visible:s=null,synthesizer:r="gemini"}={}){let f=L(r),l=Array.isArray(e._sources)?e._sources:Y(e),n=A(t,e,l,{grounded:i}),c=await X(f,n,{tabPrefix:o,timeoutMs:180000,visible:s}),a=Z(c.answer||""),g=a&&["answer","agreement","claims","differences","caveats"].some((u)=>(u in a));if(a&&["perplexity","bing","google","chatgpt","gemini"].some((u)=>(u in a))&&!g)a=null;return{...x(a,l,c.answer||""),rawAnswer:c.answer||"",synthesizedBy:f,synthesizerSources:c.sources||[],geminiSources:f==="gemini"?c.sources||[]:[]}}async function Fe(t,e,i={}){return Oe(t,e,{...i,synthesizer:"gemini"})}export{Fe as synthesizeWithGemini,Oe as synthesizeResults,X as runSynthesisPrompt,Ve as runGeminiPrompt,L as normalizeSynthesizer,Be as getSynthesisStartUrl};
|