seo 0.17.9 → 0.18.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/dist/mcp.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __seoCreateRequire } from 'node:module'; const require = __seoCreateRequire(import.meta.url);
2
- import { i as __toESM, n as version, r as __commonJSMin, t as load } from "./esm-BByR3SEY.js";
2
+ import { i as __toESM, n as version, r as __commonJSMin, t as load } from "./esm-BVLLXPWR.js";
3
3
  import { createHash, randomUUID, sign } from "node:crypto";
4
4
  import { ZodOptional, z } from "zod";
5
5
  import { arch, homedir, platform, tmpdir, totalmem } from "node:os";
@@ -14996,7 +14996,7 @@ async function runSites(input) {
14996
14996
  };
14997
14997
  }
14998
14998
  // packages/core/dist/commands/linked.js
14999
- const MAX_ROWS$2 = 1e5;
14999
+ const MAX_ROWS$3 = 1e5;
15000
15000
  const PERMISSION_RANK = {
15001
15001
  siteOwner: 0,
15002
15002
  siteFullUser: 1,
@@ -15088,7 +15088,7 @@ var LinkedAccounts = class {
15088
15088
  searchAnalytics() {
15089
15089
  return async (site, body) => searchAnalyticsRows((await this.owner(site)).google, site, {
15090
15090
  ...body,
15091
- maxRows: body.maxRows ?? body.rowLimit ?? MAX_ROWS$2
15091
+ maxRows: body.maxRows ?? body.rowLimit ?? MAX_ROWS$3
15092
15092
  }, { signIn: this.hint.signIn });
15093
15093
  }
15094
15094
  async inspect(site, url) {
@@ -17366,7 +17366,7 @@ function sessionSourceInListFilter(values) {
17366
17366
  }
17367
17367
  // packages/core/dist/analyze/ai-referrals.js
17368
17368
  const DEFAULT_MAX_ROWS$1 = 1e5;
17369
- const MAX_ROWS$1 = 1e5;
17369
+ const MAX_ROWS$2 = 1e5;
17370
17370
  const DEFAULT_RESULT_LIMIT = 25;
17371
17371
  const MAX_RESULT_LIMIT = 1e3;
17372
17372
  function validIsoDate$1(value) {
@@ -17392,7 +17392,7 @@ function reportRange(input) {
17392
17392
  function maxRows(input) {
17393
17393
  if (input.maxRows !== void 0 && input.limit !== void 0 && input.maxRows !== input.limit) throw new SeoError("INVALID_INPUT", "Use maxRows or the legacy limit option, not both.");
17394
17394
  const value = input.maxRows ?? input.limit ?? DEFAULT_MAX_ROWS$1;
17395
- if (!Number.isInteger(value) || value < 1 || value > MAX_ROWS$1) throw new SeoError("INVALID_INPUT", `maxRows must be a whole number between 1 and ${MAX_ROWS$1}.`);
17395
+ if (!Number.isInteger(value) || value < 1 || value > MAX_ROWS$2) throw new SeoError("INVALID_INPUT", `maxRows must be a whole number between 1 and ${MAX_ROWS$2}.`);
17396
17396
  return value;
17397
17397
  }
17398
17398
  function resultLimit(input) {
@@ -22716,6 +22716,172 @@ async function pageOpportunitiesReport(input, dependencies = defaultDependencies
22716
22716
  recommendations: pageOpportunityRecommendations(analysis)
22717
22717
  };
22718
22718
  }
22719
+ // packages/core/dist/brand-evidence.js
22720
+ const NAVIGATIONAL_STEM_THRESHOLDS = {
22721
+ maximumPosition: 2,
22722
+ minimumCtr: .2,
22723
+ minimumImpressions: 20
22724
+ };
22725
+ function compact(value) {
22726
+ return normalizeBrandText(value).replace(/\s+/g, "");
22727
+ }
22728
+ function round$2(value, digits) {
22729
+ return Number(value.toFixed(digits));
22730
+ }
22731
+ function stemQueryEvidence(rows, stem) {
22732
+ const target = compact(stem);
22733
+ if (!target) return void 0;
22734
+ let clicks = 0;
22735
+ let impressions = 0;
22736
+ let weightedPosition = 0;
22737
+ let sourceRows = 0;
22738
+ let query;
22739
+ for (const row of rows) {
22740
+ const value = row.keys?.[0];
22741
+ if (typeof value !== "string" || compact(value) !== target) continue;
22742
+ if (!Number.isFinite(row.clicks) || !Number.isFinite(row.impressions) || !Number.isFinite(row.position) || row.impressions <= 0 || row.clicks < 0) continue;
22743
+ const trimmed = value.trim();
22744
+ if (query === void 0 || trimmed < query) query = trimmed;
22745
+ clicks += row.clicks;
22746
+ impressions += row.impressions;
22747
+ weightedPosition += row.position * row.impressions;
22748
+ sourceRows++;
22749
+ }
22750
+ if (!sourceRows || query === void 0) return void 0;
22751
+ return {
22752
+ query,
22753
+ clicks,
22754
+ impressions,
22755
+ ctr: round$2(clicks / impressions, 4),
22756
+ position: round$2(weightedPosition / impressions, 2),
22757
+ sourceRows
22758
+ };
22759
+ }
22760
+ /**
22761
+ * Brand terms for a property, decided from its own Search Console query rows.
22762
+ * `rows` are query rows (`keys[0]` is the query); query/page rows also work
22763
+ * because rows for the same query are summed. Pure and Worker-safe.
22764
+ */
22765
+ function brandTermsFromQueryRows(input) {
22766
+ const evidence = [];
22767
+ const excluded = [];
22768
+ const host = registrableDomain(input.siteUrl);
22769
+ const method = {
22770
+ id: "gsc_navigational_brand_terms_v1",
22771
+ heuristic: true,
22772
+ stemRule: NAVIGATIONAL_STEM_THRESHOLDS,
22773
+ stemMatch: "exact_query_ignoring_spaces_and_punctuation"
22774
+ };
22775
+ if (!host) return {
22776
+ terms: [],
22777
+ evidence,
22778
+ excluded,
22779
+ method
22780
+ };
22781
+ const suffixWords = host.suffix.split(".");
22782
+ const compounds = [
22783
+ host.domain,
22784
+ [host.stem, ...suffixWords].join(" "),
22785
+ [host.stem, ...suffixWords].join(""),
22786
+ [host.stem, ...suffixWords].join("-")
22787
+ ];
22788
+ for (const term of [...new Set(compounds)]) evidence.push({
22789
+ term,
22790
+ source: "host-compound",
22791
+ reason: `Contains the property host ${host.domain}.`
22792
+ });
22793
+ const stemEvidence = stemQueryEvidence(input.rows, host.stem);
22794
+ const thresholds = NAVIGATIONAL_STEM_THRESHOLDS;
22795
+ if (!stemEvidence) excluded.push({
22796
+ term: host.stem,
22797
+ source: "domain-stem",
22798
+ reason: `No retained Search Console row for the exact query "${host.stem}", so the bare stem is not treated as brand.`
22799
+ });
22800
+ else if (stemEvidence.impressions >= thresholds.minimumImpressions && stemEvidence.position <= thresholds.maximumPosition && stemEvidence.ctr >= thresholds.minimumCtr) evidence.push({
22801
+ term: host.stem,
22802
+ source: "navigational-stem",
22803
+ reason: `The exact query "${stemEvidence.query}" averages position ${stemEvidence.position} with CTR ${stemEvidence.ctr} over ${stemEvidence.impressions} impressions, so the property looks like its navigational answer (heuristic).`,
22804
+ query: stemEvidence
22805
+ });
22806
+ else excluded.push({
22807
+ term: host.stem,
22808
+ source: "domain-stem",
22809
+ reason: `The exact query "${stemEvidence.query}" averages position ${stemEvidence.position} with CTR ${stemEvidence.ctr} over ${stemEvidence.impressions} impressions. That does not meet position <= ${thresholds.maximumPosition}, CTR >= ${thresholds.minimumCtr} and impressions >= ${thresholds.minimumImpressions}, so the bare stem is treated as a generic word.`,
22810
+ query: stemEvidence
22811
+ });
22812
+ for (const spelling of navigationalSpellings(input.rows, host.stem)) evidence.push({
22813
+ term: spelling.query,
22814
+ source: "navigational-spelling",
22815
+ reason: `"${spelling.query}" is a spelling of ${host.stem} that averages position ${spelling.position} with CTR ${spelling.ctr} over ${spelling.impressions} impressions, so the property looks like its navigational answer (heuristic).`,
22816
+ query: spelling
22817
+ });
22818
+ return {
22819
+ terms: evidence.map((item) => item.term),
22820
+ evidence,
22821
+ excluded,
22822
+ method
22823
+ };
22824
+ }
22825
+ function editsWithin(a, b, most) {
22826
+ if (Math.abs(a.length - b.length) > most) return false;
22827
+ let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
22828
+ for (let i = 1; i <= a.length; i++) {
22829
+ const current = [i];
22830
+ for (let j = 1; j <= b.length; j++) current[j] = Math.min((previous[j] ?? 0) + 1, (current[j - 1] ?? 0) + 1, (previous[j - 1] ?? 0) + (a[i - 1] === b[j - 1] ? 0 : 1));
22831
+ if (Math.min(...current) > most) return false;
22832
+ previous = current;
22833
+ }
22834
+ return (previous[b.length] ?? most + 1) <= most;
22835
+ }
22836
+ const SPELLING_WORDS = 3;
22837
+ function navigationalSpellings(rows, stem) {
22838
+ const target = compact(stem);
22839
+ if (target.length < 6) return [];
22840
+ const most = target.length >= 9 ? 2 : 1;
22841
+ const totals = /* @__PURE__ */ new Map();
22842
+ for (const row of rows) {
22843
+ const value = row.keys?.[0];
22844
+ if (typeof value !== "string") continue;
22845
+ if (normalizeBrandText(value).split(" ").length > SPELLING_WORDS) continue;
22846
+ const key = compact(value);
22847
+ if (key === target || !editsWithin(key, target, most)) continue;
22848
+ totals.set(key, [...totals.get(key) ?? [], row]);
22849
+ }
22850
+ const thresholds = NAVIGATIONAL_STEM_THRESHOLDS;
22851
+ return [...totals].map(([key, matched]) => stemQueryEvidence(matched, key)).filter((found) => !!found && found.impressions >= thresholds.minimumImpressions && found.position <= thresholds.maximumPosition && found.ctr >= thresholds.minimumCtr).sort((a, b) => b.impressions - a.impressions || a.query.localeCompare(b.query));
22852
+ }
22853
+ /**
22854
+ * Brand terms a report uses: the caller's terms when given, otherwise terms
22855
+ * derived from the same Search Console rows the report analyses.
22856
+ */
22857
+ function resolveReportBrandTerms(input) {
22858
+ const filtering = input.includeBrand ? "included" : "excluded";
22859
+ const provided = (input.brandTerms ?? []).filter((term) => normalizeBrandText(term));
22860
+ if (provided.length) return {
22861
+ source: "provided",
22862
+ filtering,
22863
+ terms: provided,
22864
+ evidence: provided.map((term) => ({
22865
+ term,
22866
+ source: "provided",
22867
+ reason: "Supplied by the caller."
22868
+ })),
22869
+ excluded: [],
22870
+ heuristic: false
22871
+ };
22872
+ const derived = brandTermsFromQueryRows({
22873
+ siteUrl: input.siteUrl,
22874
+ rows: input.rows
22875
+ });
22876
+ return {
22877
+ source: "search-console-navigational",
22878
+ filtering,
22879
+ terms: derived.terms,
22880
+ evidence: derived.evidence,
22881
+ excluded: derived.excluded,
22882
+ heuristic: true
22883
+ };
22884
+ }
22719
22885
  // packages/core/dist/analyze/ai-queries.js
22720
22886
  const RULES = [
22721
22887
  ["agent_prompt", "^(search the web for|browse the web|find sources)|do not invent|return the [0-9]+ most relevant|include source urls|context: location|do not include location|question: |reply only with|the model you are using"],
@@ -22723,6 +22889,7 @@ const RULES = [
22723
22889
  ["reply", "^(yes|yeah|yep|ok|okay|sure|yes please|go on|continue|keep going|tell me more|why not|how so|really|exactly|show me|and then|thanks|thank you|got it|what else|anything else)[?!.,]*$"],
22724
22890
  ["follow_up", "^(what|how) about .{1,40}$|^(and|so|ok so|okay so|but) (what|which|how|why) "],
22725
22891
  ["operator", "(^|\\s)-?(site|before|after|intitle|inurl|intext|filetype):|\"[^\"]*\" or \""],
22892
+ ["pronoun", "\\b(it|its|they|them|their|this|these|those)\\b"],
22726
22893
  ["chat", "\\b(please|can you|could you|give me|show me|tell me|i want|i need|i have|i am|should i|do i need|is it worth|help me|walk me through)\\b|^(what|how|why|is|does|can|will|would) (it|that|this|they)\\b"],
22727
22894
  ["long", "^(\\S+\\s+){9,}\\S+$"]
22728
22895
  ];
@@ -22732,6 +22899,7 @@ const AI_QUERY_KINDS = {
22732
22899
  reply: "a bare reply, such as \"yes\" or \"tell me more\"",
22733
22900
  follow_up: "a follow-up, such as \"what about …\"",
22734
22901
  operator: "search operators, such as site:, before: or \"a\" or \"b\"",
22902
+ pronoun: "a pronoun with nothing named, such as \"how much is it\" or \"do they ship to canada\", so likely a follow-up in a conversation",
22735
22903
  chat: "chat phrasing, such as \"can you\" or \"should i\"",
22736
22904
  long: "ten or more words with no other sign"
22737
22905
  };
@@ -22753,16 +22921,44 @@ function askable(query, kind) {
22753
22921
  const text = query.trim().toLowerCase().replace(/^["'“]+/u, "");
22754
22922
  return Boolean(kind && ASKABLE_KINDS.has(kind)) && text.length <= PROMPT_CHARACTERS && QUESTION.test(text);
22755
22923
  }
22756
- function aiQueryKind(query) {
22924
+ const PRONOUNS = /\b(it|its|they|them|their|this|these|those)\b/gu;
22925
+ const TIME_WORD = /\b(this|these|those) (morning|evening|afternoon|night|day|date|week|weekend|month|year|time)\b/gu;
22926
+ const DUMMY_IT = /\b(now|rn|atm|tn|tdy|tmr|tmrw|tonite|yday|currently|to ?n?ight|to day|lastn\S*|(last|past|next|this) \S+|(mon|tues|wednes|thurs|fri|satur|sun)day|outside|dark|sunny|raining|snowing|o'?clock)\b|\bit (take|takes|took)\b.*\b(to|for)\b|\b(far|miles|km) (is|was) it (to|from|around|between)\b|\bis it (\S+ )?(safe|legal|illegal|possible|ok|okay|bad|good|better|best|hard|easy|normal|necessary|true|cheaper|rude|wise) (to|for|if)\b/u;
22927
+ const IDENTIFY_IT = /^(what|which)( (kind|type|sort) of)?( \S+){1,2} (is|was) it\b|^(is|was) it (a|an|the) /u;
22928
+ const CLASS_WORD = /\b(name|surname|names|word|thing|one|company|brand|product|place|site|website|app|scam|service)\b/u;
22929
+ const PRONOUN_WORDS = 10;
22930
+ const DAYS$1 = [
22931
+ "today",
22932
+ "tonight",
22933
+ "tomorrow",
22934
+ "yesterday"
22935
+ ];
22936
+ function pointsBack(text) {
22937
+ const tokens = text.split(/\s+/u);
22938
+ if (tokens.length >= PRONOUN_WORDS) return false;
22939
+ const found = text.replace(TIME_WORD, " ").replace(/(?<!^)\bits\b/gu, " ").match(PRONOUNS) ?? [];
22940
+ if (!found.length) return false;
22941
+ if (!found.every((word) => word === "it" || word === "its")) return true;
22942
+ return !(DUMMY_IT.test(text) || IDENTIFY_IT.test(text) && !CLASS_WORD.test(text) || tokens.some((token) => token.length >= 4 && DAYS$1.some((day) => editsWithin(token, day, day.length >= 8 ? 2 : 1))));
22943
+ }
22944
+ function aiQueryKind(query, brandTerms = []) {
22757
22945
  const text = query.trim().toLowerCase();
22758
- return MATCHERS.find(([, pattern]) => pattern.test(text))?.[0] ?? null;
22946
+ return MATCHERS.find(([kind, pattern]) => pattern.test(text) && (kind !== "pronoun" || pointsBack(text) && !isBrandQuery(text, brandTerms)))?.[0] ?? null;
22759
22947
  }
22760
22948
  const STOP = new Set("the and for with that this what which who how why when where are is was can does do did you your our from about into than then them they their there have has had will would should could not but its it’s me my i am of to in on at by or an as be if so".split(" "));
22761
22949
  function words$3(query) {
22762
22950
  return new Set(query.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter((word) => word.length >= 3 && !STOP.has(word)).map((word) => word.length > 4 && word.endsWith("s") ? word.slice(0, -1) : word));
22763
22951
  }
22764
22952
  const SAME_QUESTION = .6;
22765
- const MAX_ROWS = 25e3;
22953
+ const BRAND_ROWS = 5e3;
22954
+ const TRAILS_KEPT = 50;
22955
+ const TURNS = /* @__PURE__ */ new Set([
22956
+ "reply",
22957
+ "follow_up",
22958
+ "pronoun"
22959
+ ]);
22960
+ const TURN_PATTERN = RULES.filter(([kind]) => TURNS.has(kind)).map(([, pattern]) => `(?:${pattern})`).join("|");
22961
+ const MAX_ROWS$1 = 25e3;
22766
22962
  const EXAMPLES = 3;
22767
22963
  const CANDIDATES = 200;
22768
22964
  const overlap = (a, b, weight) => {
@@ -22775,29 +22971,119 @@ const overlap = (a, b, weight) => {
22775
22971
  for (const word of b) if (!a.has(word)) union += weight(word);
22776
22972
  return union ? shared / union : 0;
22777
22973
  };
22778
- const round$2 = (value, places) => Math.round(value * 10 ** places) / 10 ** places;
22974
+ function trailsOf(rows, brandTerms, questionOf) {
22975
+ const days = /* @__PURE__ */ new Map();
22976
+ for (const row of rows) {
22977
+ const [date = "", query = "", page = ""] = row.keys.map(String);
22978
+ const text = query.trim().toLowerCase();
22979
+ const kind = aiQueryKind(text, brandTerms);
22980
+ if (!kind || !TURNS.has(kind) || aiQueryNoise(text)) continue;
22981
+ const key = `${date} ${page}`;
22982
+ const day = days.get(key) ?? {
22983
+ date,
22984
+ page,
22985
+ impressions: 0,
22986
+ questions: /* @__PURE__ */ new Map()
22987
+ };
22988
+ days.set(key, day);
22989
+ const question = questionOf(text) ?? text;
22990
+ const seen = day.questions.get(question);
22991
+ if (!seen || row.impressions > seen.impressions) day.questions.set(question, {
22992
+ query: text,
22993
+ impressions: row.impressions + (seen?.impressions ?? 0)
22994
+ });
22995
+ else seen.impressions += row.impressions;
22996
+ day.impressions += row.impressions;
22997
+ }
22998
+ const trails = [...days.values()].filter((day) => day.questions.size >= 2).map((day) => ({
22999
+ date: day.date,
23000
+ page: day.page,
23001
+ turns: day.questions.size,
23002
+ impressions: day.impressions,
23003
+ queries: [...day.questions.values()].sort((a, b) => b.impressions - a.impressions || a.query.localeCompare(b.query)).map((turn) => turn.query)
23004
+ })).sort((a, b) => b.turns - a.turns || b.impressions - a.impressions || b.date.localeCompare(a.date) || a.page.localeCompare(b.page));
23005
+ const pages = /* @__PURE__ */ new Map();
23006
+ for (const trail of trails) {
23007
+ const entry = pages.get(trail.page) ?? {
23008
+ trails: 0,
23009
+ days: /* @__PURE__ */ new Set(),
23010
+ asked: /* @__PURE__ */ new Map()
23011
+ };
23012
+ pages.set(trail.page, entry);
23013
+ entry.trails += 1;
23014
+ entry.days.add(trail.date);
23015
+ for (const query of trail.queries) entry.asked.set(query, (entry.asked.get(query) ?? 0) + 1);
23016
+ }
23017
+ const byPage = [...pages].map(([page, entry]) => ({
23018
+ page,
23019
+ trails: entry.trails,
23020
+ days: entry.days.size,
23021
+ followUps: [...entry.asked].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).slice(0, EXAMPLES).map(([query]) => query)
23022
+ })).sort((a, b) => b.trails - a.trails || a.page.localeCompare(b.page));
23023
+ return {
23024
+ trailCount: trails.length,
23025
+ pageCount: byPage.length,
23026
+ byPage: byPage.slice(0, 10),
23027
+ trails: trails.slice(0, TRAILS_KEPT)
23028
+ };
23029
+ }
23030
+ const round$1 = (value, places) => Math.round(value * 10 ** places) / 10 ** places;
22779
23031
  async function aiQueriesReport(input, searchAnalytics) {
22780
23032
  const range = {
22781
23033
  startDate: input.startDate,
22782
23034
  endDate: input.endDate
22783
23035
  };
22784
- const [matched, site] = await Promise.all([searchAnalytics(input.site, {
22785
- ...range,
22786
- dimensions: ["query", "page"],
22787
- type: "web",
22788
- dataState: "final",
22789
- maxRows: MAX_ROWS,
22790
- dimensionFilterGroups: [{ filters: [{
22791
- dimension: "query",
22792
- operator: "includingRegex",
22793
- expression: AI_QUERY_PATTERN
22794
- }] }]
22795
- }), searchAnalytics(input.site, {
22796
- ...range,
22797
- dimensions: [],
22798
- type: "web",
22799
- dataState: "final"
22800
- })]);
23036
+ const trailRange = {
23037
+ startDate: [input.startDate, shiftIsoDate(input.endDate, -27)].sort().at(-1),
23038
+ endDate: input.endDate
23039
+ };
23040
+ const [matched, site, named, daily] = await Promise.all([
23041
+ searchAnalytics(input.site, {
23042
+ ...range,
23043
+ dimensions: ["query", "page"],
23044
+ type: "web",
23045
+ dataState: "final",
23046
+ maxRows: MAX_ROWS$1,
23047
+ dimensionFilterGroups: [{ filters: [{
23048
+ dimension: "query",
23049
+ operator: "includingRegex",
23050
+ expression: AI_QUERY_PATTERN
23051
+ }] }]
23052
+ }),
23053
+ searchAnalytics(input.site, {
23054
+ ...range,
23055
+ dimensions: [],
23056
+ type: "web",
23057
+ dataState: "final"
23058
+ }),
23059
+ searchAnalytics(input.site, {
23060
+ ...range,
23061
+ dimensions: ["query"],
23062
+ type: "web",
23063
+ dataState: "final",
23064
+ maxRows: BRAND_ROWS
23065
+ }),
23066
+ searchAnalytics(input.site, {
23067
+ ...trailRange,
23068
+ dimensions: [
23069
+ "date",
23070
+ "query",
23071
+ "page"
23072
+ ],
23073
+ type: "web",
23074
+ dataState: "final",
23075
+ maxRows: MAX_ROWS$1,
23076
+ dimensionFilterGroups: [{ filters: [{
23077
+ dimension: "query",
23078
+ operator: "includingRegex",
23079
+ expression: TURN_PATTERN
23080
+ }] }]
23081
+ })
23082
+ ]);
23083
+ const brand = resolveReportBrandTerms({
23084
+ siteUrl: input.site,
23085
+ rows: named.rows
23086
+ });
22801
23087
  const rows = [...matched.rows].sort((a, b) => b.impressions - a.impressions || String(a.keys[0]).localeCompare(String(b.keys[0])) || String(a.keys[1]).localeCompare(String(b.keys[1])));
22802
23088
  const usage = /* @__PURE__ */ new Map();
22803
23089
  const unique = new Set(rows.map((row) => String(row.keys[0] ?? "")));
@@ -22808,10 +23094,12 @@ async function aiQueriesReport(input, searchAnalytics) {
22808
23094
  const byText = /* @__PURE__ */ new Map();
22809
23095
  const kindOf = /* @__PURE__ */ new Map();
22810
23096
  const noise = /* @__PURE__ */ new Map();
23097
+ const namesBrand = /* @__PURE__ */ new Set();
22811
23098
  for (const row of rows) {
22812
23099
  const query = String(row.keys[0] ?? "");
22813
23100
  const page = String(row.keys[1] ?? "");
22814
- const kind = aiQueryKind(query);
23101
+ const kind = aiQueryKind(query, brand.terms);
23102
+ if (kind !== "pronoun" && aiQueryKind(query) === "pronoun") namesBrand.add(query.trim().toLowerCase());
22815
23103
  if (!kind) continue;
22816
23104
  const junk = aiQueryNoise(query);
22817
23105
  if (junk) {
@@ -22898,16 +23186,19 @@ async function aiQueriesReport(input, searchAnalytics) {
22898
23186
  wordings: group.queries.size,
22899
23187
  impressions: group.impressions,
22900
23188
  clicks: group.clicks,
22901
- ctr: group.impressions ? round$2(group.clicks / group.impressions, 4) : 0,
22902
- position: group.impressions ? round$2(group.positionWeight / group.impressions, 1) : 0,
23189
+ ctr: group.impressions ? round$1(group.clicks / group.impressions, 4) : 0,
23190
+ position: group.impressions ? round$1(group.positionWeight / group.impressions, 1) : 0,
22903
23191
  otherWordings: rest.slice(0, EXAMPLES)
22904
23192
  };
22905
23193
  }).sort((a, b) => b.impressions - a.impressions || b.wordings - a.wordings || a.query.localeCompare(b.query) || a.page.localeCompare(b.page));
22906
- const pct = (part, whole) => whole ? round$2(part / whole * 100, 1) : null;
23194
+ const pct = (part, whole) => whole ? round$1(part / whole * 100, 1) : null;
22907
23195
  const kinds = [...byKind].sort((a, b) => b[1].impressions - a[1].impressions || a[0].localeCompare(b[0])).map(([kind, entry]) => `${kind} ${entry.queries}`).join(", ");
22908
23196
  const leftOut = [...noise].sort((a, b) => a[0].localeCompare(b[0])).map(([reason, seen]) => `${reason.replace("_", " ")} ${seen.size}`).join(", ");
23197
+ const followUps = trailsOf(daily.rows, brand.terms, (text) => byText.get(text));
23198
+ const path = (page) => page.replace(/^https?:\/\/[^/]+/u, "") || "/";
23199
+ const finding = followUps.trailCount ? `Follow-up trails, a heuristic, ${trailRange.startDate} to ${trailRange.endDate}: ${followUps.trailCount} on ${followUps.pageCount} ${followUps.pageCount === 1 ? "page" : "pages"}, where two or more follow-ups (a pronoun with nothing named, a bare reply, "what about …") reached one page on one day. ${followUps.byPage.slice(0, 3).map((entry) => `${path(entry.page)}: ${entry.trails}, such as ${entry.followUps.map((query) => `"${query}"`).join(", ")}`).join("; ")}. Search Console has no sessions, so a trail may join different people; it hides rare queries, so these counts are floors.` : `No follow-up trails from ${trailRange.startDate} to ${trailRange.endDate}: no page got two or more follow-ups on one day.`;
22909
23200
  const asked = items.filter((item) => item.askable).length;
22910
- const capped = matched.rowsFetched >= MAX_ROWS;
23201
+ const capped = matched.rowsFetched >= MAX_ROWS$1;
22911
23202
  return {
22912
23203
  range,
22913
23204
  verdict: queries ? `${queries} queries in ${groups.length} questions have the shape of AI conversations or agent searches.` : "No queries with the shape of AI conversations or agent searches.",
@@ -22920,19 +23211,28 @@ async function aiQueriesReport(input, searchAnalytics) {
22920
23211
  clicks,
22921
23212
  shareOfImpressionsPct: pct(impressions, total.impressions),
22922
23213
  byKind: kinds || "none",
22923
- ctr: impressions ? round$2(clicks / impressions, 4) : 0,
22924
- siteCtr: total.impressions ? round$2(total.clicks / total.impressions, 4) : 0
23214
+ ctr: impressions ? round$1(clicks / impressions, 4) : 0,
23215
+ siteCtr: total.impressions ? round$1(total.clicks / total.impressions, 4) : 0
22925
23216
  },
23217
+ finding,
22926
23218
  kinds: AI_QUERY_KINDS,
22927
23219
  items,
23220
+ followUps: {
23221
+ range: trailRange,
23222
+ ...followUps,
23223
+ namesBrand: namesBrand.size,
23224
+ brandTerms: brand.terms,
23225
+ capped: daily.rowsFetched >= MAX_ROWS$1
23226
+ },
22928
23227
  caveats: [
22929
23228
  "A heuristic: these queries match the patterns of AI conversations and agent searches. Search Console does not mark AI Mode or AI Overviews, and people type some of these too.",
22930
23229
  "A minimum: Search Console leaves out rare queries, and these are rare by nature.",
23230
+ "pronoun: it, they, this and the like with nothing named, under ten words. Queries that name the site (its brand terms, from its own top queries) and the \"it\" of time, weather and distance are not counted.",
22931
23231
  "Rewordings of one question are grouped by their shared words; page is the page with the most impressions for it.",
22932
23232
  "Left out and counted, not shown: letters split by spaces, text broken by a wrong encoding, and text pasted from a tool or an agent’s output.",
22933
23233
  "askable: a chat or long question that opens with a question word or a request such as \"i need\", or ends with a question mark, so an AI engine can be asked it as it is. ai_answers checks the top askable questions only.",
22934
23234
  "Search Console’s Generative AI report is not in its API, so it is not here.",
22935
- ...capped ? [`Capped at the first ${MAX_ROWS} matching query and page rows.`] : []
23235
+ ...capped ? [`Capped at the first ${MAX_ROWS$1} matching query and page rows.`] : []
22936
23236
  ]
22937
23237
  };
22938
23238
  }
@@ -29545,138 +29845,6 @@ async function crawlSite(input, dependencies) {
29545
29845
  await renderer?.close();
29546
29846
  }
29547
29847
  }
29548
- // packages/core/dist/brand-evidence.js
29549
- const NAVIGATIONAL_STEM_THRESHOLDS = {
29550
- maximumPosition: 2,
29551
- minimumCtr: .2,
29552
- minimumImpressions: 20
29553
- };
29554
- function compact(value) {
29555
- return normalizeBrandText(value).replace(/\s+/g, "");
29556
- }
29557
- function round$1(value, digits) {
29558
- return Number(value.toFixed(digits));
29559
- }
29560
- function stemQueryEvidence(rows, stem) {
29561
- const target = compact(stem);
29562
- if (!target) return void 0;
29563
- let clicks = 0;
29564
- let impressions = 0;
29565
- let weightedPosition = 0;
29566
- let sourceRows = 0;
29567
- let query;
29568
- for (const row of rows) {
29569
- const value = row.keys?.[0];
29570
- if (typeof value !== "string" || compact(value) !== target) continue;
29571
- if (!Number.isFinite(row.clicks) || !Number.isFinite(row.impressions) || !Number.isFinite(row.position) || row.impressions <= 0 || row.clicks < 0) continue;
29572
- const trimmed = value.trim();
29573
- if (query === void 0 || trimmed < query) query = trimmed;
29574
- clicks += row.clicks;
29575
- impressions += row.impressions;
29576
- weightedPosition += row.position * row.impressions;
29577
- sourceRows++;
29578
- }
29579
- if (!sourceRows || query === void 0) return void 0;
29580
- return {
29581
- query,
29582
- clicks,
29583
- impressions,
29584
- ctr: round$1(clicks / impressions, 4),
29585
- position: round$1(weightedPosition / impressions, 2),
29586
- sourceRows
29587
- };
29588
- }
29589
- /**
29590
- * Brand terms for a property, decided from its own Search Console query rows.
29591
- * `rows` are query rows (`keys[0]` is the query); query/page rows also work
29592
- * because rows for the same query are summed. Pure and Worker-safe.
29593
- */
29594
- function brandTermsFromQueryRows(input) {
29595
- const evidence = [];
29596
- const excluded = [];
29597
- const host = registrableDomain(input.siteUrl);
29598
- const method = {
29599
- id: "gsc_navigational_brand_terms_v1",
29600
- heuristic: true,
29601
- stemRule: NAVIGATIONAL_STEM_THRESHOLDS,
29602
- stemMatch: "exact_query_ignoring_spaces_and_punctuation"
29603
- };
29604
- if (!host) return {
29605
- terms: [],
29606
- evidence,
29607
- excluded,
29608
- method
29609
- };
29610
- const suffixWords = host.suffix.split(".");
29611
- const compounds = [
29612
- host.domain,
29613
- [host.stem, ...suffixWords].join(" "),
29614
- [host.stem, ...suffixWords].join(""),
29615
- [host.stem, ...suffixWords].join("-")
29616
- ];
29617
- for (const term of [...new Set(compounds)]) evidence.push({
29618
- term,
29619
- source: "host-compound",
29620
- reason: `Contains the property host ${host.domain}.`
29621
- });
29622
- const stemEvidence = stemQueryEvidence(input.rows, host.stem);
29623
- const thresholds = NAVIGATIONAL_STEM_THRESHOLDS;
29624
- if (!stemEvidence) excluded.push({
29625
- term: host.stem,
29626
- source: "domain-stem",
29627
- reason: `No retained Search Console row for the exact query "${host.stem}", so the bare stem is not treated as brand.`
29628
- });
29629
- else if (stemEvidence.impressions >= thresholds.minimumImpressions && stemEvidence.position <= thresholds.maximumPosition && stemEvidence.ctr >= thresholds.minimumCtr) evidence.push({
29630
- term: host.stem,
29631
- source: "navigational-stem",
29632
- reason: `The exact query "${stemEvidence.query}" averages position ${stemEvidence.position} with CTR ${stemEvidence.ctr} over ${stemEvidence.impressions} impressions, so the property looks like its navigational answer (heuristic).`,
29633
- query: stemEvidence
29634
- });
29635
- else excluded.push({
29636
- term: host.stem,
29637
- source: "domain-stem",
29638
- reason: `The exact query "${stemEvidence.query}" averages position ${stemEvidence.position} with CTR ${stemEvidence.ctr} over ${stemEvidence.impressions} impressions. That does not meet position <= ${thresholds.maximumPosition}, CTR >= ${thresholds.minimumCtr} and impressions >= ${thresholds.minimumImpressions}, so the bare stem is treated as a generic word.`,
29639
- query: stemEvidence
29640
- });
29641
- return {
29642
- terms: evidence.map((item) => item.term),
29643
- evidence,
29644
- excluded,
29645
- method
29646
- };
29647
- }
29648
- /**
29649
- * Brand terms a report uses: the caller's terms when given, otherwise terms
29650
- * derived from the same Search Console rows the report analyses.
29651
- */
29652
- function resolveReportBrandTerms(input) {
29653
- const filtering = input.includeBrand ? "included" : "excluded";
29654
- const provided = (input.brandTerms ?? []).filter((term) => normalizeBrandText(term));
29655
- if (provided.length) return {
29656
- source: "provided",
29657
- filtering,
29658
- terms: provided,
29659
- evidence: provided.map((term) => ({
29660
- term,
29661
- source: "provided",
29662
- reason: "Supplied by the caller."
29663
- })),
29664
- excluded: [],
29665
- heuristic: false
29666
- };
29667
- const derived = brandTermsFromQueryRows({
29668
- siteUrl: input.siteUrl,
29669
- rows: input.rows
29670
- });
29671
- return {
29672
- source: "search-console-navigational",
29673
- filtering,
29674
- terms: derived.terms,
29675
- evidence: derived.evidence,
29676
- excluded: derived.excluded,
29677
- heuristic: true
29678
- };
29679
- }
29680
29848
  // packages/core/dist/analyze/min-impressions-policy.js
29681
29849
  const POSITION_MIN_IMPRESSIONS_SCALE = {
29682
29850
  share: 2e-4,
@@ -43489,6 +43657,29 @@ const hostOf$3 = (url) => {
43489
43657
  };
43490
43658
  const text$1 = (value) => typeof value === "string" && value ? value : null;
43491
43659
  function dataForSeoSerp(keyword, items) {
43660
+ const asked = /* @__PURE__ */ new Map();
43661
+ for (const block of items) {
43662
+ if (block.type !== "people_also_ask") continue;
43663
+ for (const element of block.items ?? []) {
43664
+ const question = text$1(element.title);
43665
+ if (!question || asked.has(question.toLowerCase())) continue;
43666
+ const answer = element.expanded_element?.[0];
43667
+ const page = answer?.type === "people_also_ask_expanded_element";
43668
+ const url = page ? String(answer?.url ?? "") : "";
43669
+ const goto = GOTO.test(url);
43670
+ asked.set(question.toLowerCase(), {
43671
+ question,
43672
+ aiAnswer: answer?.type === "people_also_ask_ai_overview_expanded_element",
43673
+ url: page && url && !goto ? url : null,
43674
+ domain: page ? goto ? null : text$1(answer?.domain) ?? (hostOf$3(url) || null) : null,
43675
+ title: page ? text$1(answer?.title) : null
43676
+ });
43677
+ }
43678
+ }
43679
+ const questions = asked.size ? {
43680
+ keyword,
43681
+ questions: [...asked.values()].slice(0, 20)
43682
+ } : null;
43492
43683
  const found = items.find((item) => item.type === "ai_overview");
43493
43684
  const overview = found ? {
43494
43685
  keyword,
@@ -43522,7 +43713,8 @@ function dataForSeoSerp(keyword, items) {
43522
43713
  }
43523
43714
  return row;
43524
43715
  }),
43525
- overview
43716
+ overview,
43717
+ questions
43526
43718
  };
43527
43719
  }
43528
43720
  // packages/core/dist/commands/research-providers.js
@@ -43738,6 +43930,7 @@ async function dataForSeo(keys, input) {
43738
43930
  ...spent.available !== void 0 ? { available: spent.available } : {},
43739
43931
  ...spent.siteTotal ? { siteTotal: spent.siteTotal } : {},
43740
43932
  ...spent.aiOverviews ? { aiOverviews: spent.aiOverviews } : {},
43933
+ ...spent.peopleAlsoAsk ? { peopleAlsoAsk: spent.peopleAlsoAsk } : {},
43741
43934
  ...spent.rankFailed ? { rankFailed: true } : {}
43742
43935
  };
43743
43936
  }
@@ -43838,12 +44031,14 @@ async function dataForSeoRows(keys, input, spent) {
43838
44031
  }
43839
44032
  if (input.action === "serp") {
43840
44033
  const rows = await eachKeyword(input.keywords.slice(0, serpKeywords(input)), spent.missed, async (keyword) => {
43841
- const { rows, overview } = dataForSeoSerp(keyword, await post("v3/serp/google/organic/live/advanced", {
44034
+ const { rows, overview, questions } = dataForSeoSerp(keyword, await post("v3/serp/google/organic/live/advanced", {
43842
44035
  keyword,
43843
44036
  depth: serpDepth(input),
43844
- device: input.device ?? "desktop"
44037
+ device: input.device ?? "desktop",
44038
+ ...input.peopleAlsoAskDepth ? { people_also_ask_click_depth: Math.min(4, Math.max(1, Math.round(input.peopleAlsoAskDepth))) } : {}
43845
44039
  }, 2));
43846
44040
  if (overview) spent.aiOverviews = [...spent.aiOverviews ?? [], overview];
44041
+ if (questions) spent.peopleAlsoAsk = [...spent.peopleAlsoAsk ?? [], questions];
43847
44042
  return rows;
43848
44043
  });
43849
44044
  return input.noRank ? rows : withDomainRank(keys, rows, spent);
@@ -44313,7 +44508,8 @@ const overview = (result) => {
44313
44508
  return {
44314
44509
  markdown: typeof block.markdown === "string" ? block.markdown : parts.map((part) => String(part.markdown ?? "")).join("\n"),
44315
44510
  sources: urls([...list$1(block.references), ...parts.flatMap((part) => list$1(part.references))]),
44316
- model: null
44511
+ model: null,
44512
+ searches: null
44317
44513
  };
44318
44514
  };
44319
44515
  const ENGINES = [
@@ -44334,9 +44530,11 @@ const ENGINES = [
44334
44530
  return {
44335
44531
  markdown,
44336
44532
  sources,
44337
- model: typeof result.model === "string" ? result.model : null
44533
+ model: typeof result.model === "string" ? result.model : null,
44534
+ searches: [...new Set((Array.isArray(result.fan_out_queries) ? result.fan_out_queries : []).filter((query) => typeof query === "string").map((query) => query.trim()).filter(Boolean))]
44338
44535
  };
44339
- }
44536
+ },
44537
+ searches: true
44340
44538
  },
44341
44539
  {
44342
44540
  name: "google_ai_mode",
@@ -44348,7 +44546,8 @@ const ENGINES = [
44348
44546
  keyword: question,
44349
44547
  ...market
44350
44548
  }),
44351
- shown: overview
44549
+ shown: overview,
44550
+ searches: false
44352
44551
  },
44353
44552
  {
44354
44553
  name: "google_ai_overview",
@@ -44362,7 +44561,8 @@ const ENGINES = [
44362
44561
  load_async_ai_overview: true,
44363
44562
  ...market
44364
44563
  }),
44365
- shown: overview
44564
+ shown: overview,
44565
+ searches: false
44366
44566
  }
44367
44567
  ];
44368
44568
  function prose(markdown) {
@@ -44409,6 +44609,7 @@ const empty = {
44409
44609
  mentioned_as: null,
44410
44610
  sources: [],
44411
44611
  model: null,
44612
+ searches: null,
44412
44613
  answered_at: null
44413
44614
  };
44414
44615
  function judge(engine, task, site) {
@@ -44437,6 +44638,7 @@ function judge(engine, task, site) {
44437
44638
  mentioned_as: null,
44438
44639
  sources: [...new Set(all.filter((url) => !onTarget(url)).map(hostOf$2).filter((host) => Boolean(host)))].slice(0, MAX_SOURCES),
44439
44640
  model: shown.model,
44641
+ searches: shown.searches,
44440
44642
  answered_at
44441
44643
  };
44442
44644
  if (cited) return {
@@ -44473,6 +44675,13 @@ const ROUND_WAIT_MS = 5e3;
44473
44675
  const sleep = (ms) => new Promise((done) => setTimeout(done, ms));
44474
44676
  const TASK_PATTERN = /^([a-z_]+):([0-9a-f-]{20,64})$/;
44475
44677
  const AI_ANSWER_TASK_PATTERN = TASK_PATTERN;
44678
+ const TOP_SEARCHES = 15;
44679
+ function searchesText(row) {
44680
+ const engine = ENGINES.find((item) => item.name === row.engine);
44681
+ if (engine && !engine.searches) return "not available";
44682
+ if (row.searches === null) return null;
44683
+ return row.searches.length ? row.searches.join("; ") : "none returned";
44684
+ }
44476
44685
  async function runAiAnswers(input, headers, deps, more) {
44477
44686
  const keys = dataForSeoKeys(headers);
44478
44687
  const domain = registrableDomain(input.site)?.domain;
@@ -44615,10 +44824,21 @@ async function runAiAnswers(input, headers, deps, more) {
44615
44824
  const cites = /* @__PURE__ */ new Map();
44616
44825
  for (const row of rows) for (const host of row.sources) cites.set(host, (cites.get(host) ?? 0) + 1);
44617
44826
  const topCited = [...cites].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).slice(0, 10);
44827
+ const searched = /* @__PURE__ */ new Map();
44828
+ for (const row of rows) for (const query of row.searches ?? []) {
44829
+ const key = query.toLowerCase();
44830
+ searched.set(key, (searched.get(key) ?? 0) + 1);
44831
+ }
44832
+ const topSearches = [...searched].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).slice(0, TOP_SEARCHES);
44833
+ const reporting = rows.filter((row) => row.searches !== null);
44834
+ const noSearches = reporting.filter((row) => !row.searches?.length).length;
44835
+ const silent = ENGINES.filter((engine) => !engine.searches);
44836
+ const searchesNote = reporting.length ? `Searches ChatGPT ran, across ${reporting.length} ${reporting.length === 1 ? "answer" : "answers"}${noSearches ? ` (${noSearches} returned none: ChatGPT answered without searching)` : ""}: ${topSearches.length ? `${topSearches.map(([query, n]) => `"${query}" (${n})`).join(", ")}${searched.size > TOP_SEARCHES ? `, and ${searched.size - TOP_SEARCHES} more in the rows` : ""}.` : "none returned."} ${silent.map((engine) => engine.name).join(" and ")} do not report their searches, so their searches column says not available.` : null;
44618
44837
  const questionCount = new Set(rows.map((row) => row.question)).size;
44619
44838
  const notes = [tasks.length ? `${tasks.length === 1 ? "One answer" : `${tasks.length} answers`} queued by an earlier run, read back at no cost.` : given.length ? `The ${given.length} questions you gave, asked as written. Impressions are blank because they don't come from Search Console.` : questionCount ? `The top ${questionCount} askable questions in Search Console’s AI-shaped queries for ${range.startDate} to ${range.endDate}, by impressions. No calls were made for other questions.` : `No askable questions in Search Console’s AI-shaped queries for ${range.startDate} to ${range.endDate}, so no answers were checked and nothing was spent.`, ...rows.length ? [
44620
44839
  `Cited ${count("cited")}, mentioned ${count("mentioned")}, neither ${count("neither")}, no answer shown ${count("no_answer")}, unavailable ${count("unavailable")}, not ready ${count("pending")}. DataForSEO cost: $${cost}.`,
44621
44840
  ...left.length ? [`${left.length === 1 ? "One answer wasn't" : `${left.length} answers weren't`} ready yet. They're paid for: ask ai_answers again with the same target and tasks ${JSON.stringify(left)} in a minute to read them at no cost (DataForSEO keeps them for 30 days).`] : [],
44841
+ ...searchesNote ? [searchesNote] : [],
44622
44842
  ...topCited.length ? [`Other sites these answers cite: ${topCited.map(([host, n]) => `${host} (${n})`).join(", ")}.`] : [],
44623
44843
  ...domains.filter((name) => !names.includes(name)).map((name) => `${name} is a placeholder domain that answers write into examples, so no answer counts as citing or mentioning it.`),
44624
44844
  "Each row is one sample of an answer that changes from run to run, not a ranking.",
@@ -44634,6 +44854,7 @@ async function runAiAnswers(input, headers, deps, more) {
44634
44854
  cited_url: row.cited_url,
44635
44855
  mentioned_as: row.mentioned_as,
44636
44856
  sources: row.sources.join(", "),
44857
+ searches: searchesText(row),
44637
44858
  model: row.model,
44638
44859
  answered_at: row.answered_at,
44639
44860
  cost_usd: row.cost_usd,
@@ -44670,6 +44891,10 @@ async function runAiAnswers(input, headers, deps, more) {
44670
44891
  host,
44671
44892
  answers
44672
44893
  })),
44894
+ searches: topSearches.map(([query, answers]) => ({
44895
+ query,
44896
+ answers
44897
+ })),
44673
44898
  total: rows.length,
44674
44899
  offset: input.offset,
44675
44900
  rows: rows.slice(input.offset, input.offset + 50).map(({ error, ...row }) => error ? {
@@ -45612,18 +45837,22 @@ async function bingSection(source, read, property, range) {
45612
45837
  if (!source.call) throw new CommandError("NOT_CONNECTED", source.missing);
45613
45838
  const google = (dimension) => read(property, {
45614
45839
  ...range,
45615
- dimensions: [dimension],
45840
+ dimensions: dimension ? [dimension] : [],
45616
45841
  type: "web",
45617
45842
  dataState: "final",
45618
- maxRows: 25e3
45843
+ maxRows: GOOGLE_ROWS
45619
45844
  });
45620
45845
  const [queries, pages, googleRead] = await Promise.all([
45621
45846
  bingQueries(source.call, source.site),
45622
45847
  bingPages(source.call, source.site),
45623
- Promise.all([google("query"), google("page")]).catch((error) => error instanceof Error ? error : new Error(String(error)))
45848
+ Promise.all([
45849
+ google("query"),
45850
+ google("page"),
45851
+ google()
45852
+ ]).catch((error) => error instanceof Error ? error : new Error(String(error)))
45624
45853
  ]);
45625
45854
  const googleError = googleRead instanceof Error ? googleRead : null;
45626
- const [googleQueries, googlePages] = googleRead instanceof Error ? [] : googleRead;
45855
+ const [googleQueries, googlePages, googleTotal] = googleRead instanceof Error ? [] : googleRead;
45627
45856
  const beside = (bing, googleRows, name) => {
45628
45857
  const norm = (value) => name === "query" ? value.toLowerCase().trim() : value.replace(/#.*$/, "");
45629
45858
  const byKey = new Map(googleRows?.map((row) => [norm(row.keys[0] ?? ""), row]));
@@ -45645,6 +45874,11 @@ async function bingSection(source, read, property, range) {
45645
45874
  const p = sumWeeks(pages.rows, range);
45646
45875
  const invalid = queries.invalidRows + pages.invalidRows;
45647
45876
  const empty = !queries.rows.length && !pages.rows.length && !invalid;
45877
+ const gap = googleQueries && googlePages && googleTotal && !empty ? engineGap(q.rows, p.rows, {
45878
+ queries: googleQueries,
45879
+ pages: googlePages,
45880
+ impressions: googleTotal.rows[0]?.impressions ?? 0
45881
+ }) : null;
45648
45882
  return {
45649
45883
  range,
45650
45884
  bingSite: source.site,
@@ -45653,6 +45887,10 @@ async function bingSection(source, read, property, range) {
45653
45887
  bingPages: p.rows.length,
45654
45888
  weeks: q.weeks.length
45655
45889
  },
45890
+ ...gap ? {
45891
+ finding: gap.finding,
45892
+ gap: gap.data
45893
+ } : {},
45656
45894
  items: beside(q.rows, googleQueries?.rows, "query"),
45657
45895
  topPages: beside(p.rows, googlePages?.rows, "page"),
45658
45896
  caveats: [
@@ -45665,6 +45903,57 @@ async function bingSection(source, read, property, range) {
45665
45903
  ]
45666
45904
  };
45667
45905
  }
45906
+ const GOOGLE_ROWS = 25e3;
45907
+ const GAP_PAGES = 20;
45908
+ function engineGap(bingQueries, bingPages, google) {
45909
+ const query = (value) => value.toLowerCase().trim();
45910
+ const page = (value) => value.replace(/#.*$/, "");
45911
+ const googleQueries = new Set(google.queries.rows.map((row) => query(row.keys[0] ?? "")));
45912
+ const bingQuerySet = new Set(bingQueries.map((row) => query(row.key)));
45913
+ const shared = [...bingQuerySet].filter((key) => googleQueries.has(key));
45914
+ const queriesCapped = google.queries.rowsFetched >= GOOGLE_ROWS;
45915
+ const pagesCapped = google.pages.rowsFetched >= GOOGLE_ROWS;
45916
+ const shown = google.queries.rows.reduce((sum, row) => sum + row.impressions, 0);
45917
+ const hiddenPct = google.impressions > 0 ? Math.round(Math.max(0, google.impressions - shown) / google.impressions * 1e3) / 10 : null;
45918
+ const googleByPage = new Map(google.pages.rows.map((row) => [page(row.keys[0] ?? ""), row]));
45919
+ const bingByPage = new Set(bingPages.map((row) => page(row.key)));
45920
+ const bingOnlyPages = bingPages.filter((row) => row.impressions > 0 && !googleByPage.has(page(row.key))).slice(0, GAP_PAGES).map((row) => ({
45921
+ page: row.key,
45922
+ bingClicks: row.clicks,
45923
+ bingImpressions: row.impressions,
45924
+ bingPosition: row.position
45925
+ }));
45926
+ const googleOnlyPages = [...google.pages.rows].filter((row) => row.clicks > 0 && !bingByPage.has(page(row.keys[0] ?? ""))).sort((a, b) => b.clicks - a.clicks || b.impressions - a.impressions || String(a.keys[0]).localeCompare(String(b.keys[0]))).slice(0, GAP_PAGES).map((row) => ({
45927
+ page: row.keys[0] ?? "",
45928
+ googleClicks: row.clicks,
45929
+ googleImpressions: row.impressions,
45930
+ googlePosition: Math.round(row.position * 10) / 10
45931
+ }));
45932
+ const googleCount = googleQueries.size;
45933
+ const bingCount = bingQuerySet.size;
45934
+ const ratio = bingCount > 0 && !queriesCapped ? Math.round(googleCount / bingCount * 10) / 10 : null;
45935
+ return {
45936
+ finding: [
45937
+ `Distinct queries, same dates: Search Console lists ${queriesCapped ? `at least ${googleCount} (capped)` : googleCount}, Bing ${bingCount}; ${shared.length} appear in both and ${bingCount - shared.length} ${queriesCapped ? "are not among the Search Console rows read" : "only in Bing's list"}.`,
45938
+ ratio !== null ? `Search Console lists ${ratio} times as many queries as Bing for this site, a heuristic: each engine lists its own subset, so this is not a ratio of searches.` : null,
45939
+ hiddenPct !== null ? `Queries Search Console hides for privacy carry ${queriesCapped ? "at most " : ""}${hiddenPct}% of its impressions.` : null,
45940
+ `Pages: ${bingOnlyPages.length}${bingOnlyPages.length === GAP_PAGES ? "+" : ""} get Bing impressions with no Search Console row${pagesCapped ? " among the pages read (capped)" : ""}; ${googleOnlyPages.length}${googleOnlyPages.length === GAP_PAGES ? "+" : ""} get Google clicks and are not in Bing's list, which holds only Bing's top pages, so that is not proof Bing does not show them.`
45941
+ ].filter(Boolean).join(" "),
45942
+ data: {
45943
+ googleQueries: googleCount,
45944
+ googleQueriesCapped: queriesCapped,
45945
+ bingQueries: bingCount,
45946
+ sharedQueries: shared.length,
45947
+ bingOnlyQueries: bingCount - shared.length,
45948
+ googleToBingQueryRatio: ratio,
45949
+ ratioHeuristic: true,
45950
+ googleHiddenImpressionsPct: hiddenPct,
45951
+ googlePagesCapped: pagesCapped,
45952
+ bingOnlyPages,
45953
+ googleOnlyPages
45954
+ }
45955
+ };
45956
+ }
45668
45957
  async function runBingRows(input, deps) {
45669
45958
  const source = await bingFor(deps, input.site);
45670
45959
  if (!source.call) throw new CommandError("NOT_CONNECTED", source.missing);
@@ -47757,8 +48046,8 @@ const SECTIONS = {
47757
48046
  "content-decay": "Query and page pairs that lost clicks against the previous period.",
47758
48047
  cannibalization: "Queries where more than one page of the site gets impressions, with each page’s share.",
47759
48048
  "traffic-drop": "Daily clicks and impressions checked for a sudden change that lasted, with the date it started (else the last 7 days against the days before), and Google updates within 3 days of that date. Overlap is timing only, not cause.",
47760
- "ai-queries": "Queries with the shape of AI conversations and agent searches (replies such as \"yes go on\", follow-ups, agent prompts, search operators, chat phrasing, ten or more words), with rewordings grouped into one question and its top page, impressions, clicks and position. A heuristic: Search Console does not mark AI Mode.",
47761
- bing: "Bing’s top queries from Bing Webmaster Tools with Google’s clicks, impressions and position for the same query beside them, and the same for pages."
48049
+ "ai-queries": "Queries with the shape of AI conversations and agent searches (replies such as \"yes go on\", follow-ups, agent prompts, search operators, a pronoun with nothing named, chat phrasing, ten or more words), with rewordings grouped into one question and its top page, impressions, clicks and position, and follow-up trails: follow-ups that reached one page on one day. A heuristic: Search Console does not mark AI Mode.",
48050
+ bing: "Bing’s top queries from Bing Webmaster Tools with Google’s clicks, impressions and position for the same query beside them, and the same for pages; how many distinct queries each engine shows, and pages one engine shows that the other does not."
47762
48051
  };
47763
48052
  const SECTION_IDS = Object.keys(SECTIONS);
47764
48053
  const PAGE_CHECKS = /* @__PURE__ */ new Set([
@@ -48156,6 +48445,7 @@ async function allSections(input, deps) {
48156
48445
  `## ${id}: ${shown.total} ${shown.total === 1 ? "row" : "rows"}`,
48157
48446
  SECTIONS[id],
48158
48447
  typeof run.queryShapes === "string" ? run.queryShapes : null,
48448
+ typeof run.finding === "string" ? run.finding : null,
48159
48449
  shown.text,
48160
48450
  id === "traffic-drop" ? listOfUpdates(run.googleUpdates, run.updateWindow) : null
48161
48451
  ].filter(Boolean).join("\n"));
@@ -48249,6 +48539,7 @@ async function oneSection(input, deps) {
48249
48539
  }
48250
48540
  const notes = money ? [money] : [];
48251
48541
  if (typeof report.queryShapes === "string") notes.push(report.queryShapes);
48542
+ if (typeof report.finding === "string") notes.push(report.finding);
48252
48543
  const brand = brandNote(report);
48253
48544
  if (brand) notes.push(brand);
48254
48545
  const updates = listOfUpdates(report.googleUpdates, report.updateWindow);
@@ -48520,6 +48811,124 @@ async function installedSerpResearch(provider, input, serp) {
48520
48811
  warnings
48521
48812
  };
48522
48813
  }
48814
+ // packages/core/dist/commands/research-zero-volume.js
48815
+ const ZERO_VOLUME_KEYWORDS = {
48816
+ dataforseo: 700,
48817
+ ahrefs: 100
48818
+ };
48819
+ const DAYS = 28;
48820
+ const MAX_ROWS = 25e3;
48821
+ const ASKABLE = /^[\p{L}\p{N}][\p{L}\p{N}\p{M} '’.&-]*$/u;
48822
+ const MAX_CHARACTERS = 80;
48823
+ const MAX_WORDS = 10;
48824
+ async function zeroVolumeCandidates(site, searchAnalytics, most) {
48825
+ const range = finalGscDateRange(DAYS);
48826
+ const { rows, rowsFetched } = await searchAnalytics(site, {
48827
+ ...range,
48828
+ dimensions: ["query", "page"],
48829
+ type: "web",
48830
+ dataState: "final",
48831
+ maxRows: MAX_ROWS
48832
+ });
48833
+ const byQuery = /* @__PURE__ */ new Map();
48834
+ for (const row of rows) {
48835
+ const keyword = String(row.keys[0] ?? "").trim().toLowerCase();
48836
+ const page = String(row.keys[1] ?? "");
48837
+ if (!keyword || row.impressions <= 0) continue;
48838
+ const entry = byQuery.get(keyword) ?? {
48839
+ keyword,
48840
+ impressions: 0,
48841
+ clicks: 0,
48842
+ position: 0,
48843
+ page,
48844
+ positionWeight: 0,
48845
+ pageImpressions: 0
48846
+ };
48847
+ byQuery.set(keyword, entry);
48848
+ entry.impressions += row.impressions;
48849
+ entry.clicks += row.clicks;
48850
+ entry.positionWeight += row.position * row.impressions;
48851
+ if (row.impressions > entry.pageImpressions || row.impressions === entry.pageImpressions && page < entry.page) {
48852
+ entry.page = page;
48853
+ entry.pageImpressions = row.impressions;
48854
+ }
48855
+ }
48856
+ const brand = resolveReportBrandTerms({
48857
+ siteUrl: site,
48858
+ rows
48859
+ });
48860
+ const skipped = {
48861
+ brand: 0,
48862
+ notAKeyword: 0,
48863
+ overLimit: 0
48864
+ };
48865
+ const kept = [];
48866
+ const ordered = [...byQuery.values()].sort((a, b) => b.impressions - a.impressions || a.keyword.localeCompare(b.keyword));
48867
+ for (const entry of ordered) {
48868
+ const { keyword } = entry;
48869
+ if (isBrandQuery(keyword, brand.terms)) {
48870
+ skipped.brand += 1;
48871
+ continue;
48872
+ }
48873
+ if (keyword.length > MAX_CHARACTERS || keyword.split(/\s+/u).length > MAX_WORDS || !ASKABLE.test(keyword) || isSearchArtifactQuery(keyword) || spamHint(keyword) || aiQueryNoise(keyword) || aiQueryKind(keyword) === "operator") {
48874
+ skipped.notAKeyword += 1;
48875
+ continue;
48876
+ }
48877
+ if (kept.length >= most) {
48878
+ skipped.overLimit += 1;
48879
+ continue;
48880
+ }
48881
+ kept.push({
48882
+ keyword,
48883
+ impressions: entry.impressions,
48884
+ clicks: entry.clicks,
48885
+ position: Math.round(entry.positionWeight / entry.impressions * 10) / 10,
48886
+ page: entry.page
48887
+ });
48888
+ }
48889
+ return {
48890
+ range,
48891
+ queries: kept,
48892
+ skipped,
48893
+ brandTerms: brand.terms,
48894
+ capped: rowsFetched >= MAX_ROWS
48895
+ };
48896
+ }
48897
+ function zeroVolumeRows(candidates, providerRows, provider) {
48898
+ const metric = provider === "dataforseo" ? "search_volume" : "volume";
48899
+ const volumes = /* @__PURE__ */ new Map();
48900
+ for (const row of providerRows) {
48901
+ const keyword = String(row.keyword ?? "").toLowerCase();
48902
+ const value = row[metric];
48903
+ const volume = typeof value === "number" ? value : null;
48904
+ if (!volumes.has(keyword) || volume !== null) volumes.set(keyword, volume);
48905
+ }
48906
+ let zero = 0;
48907
+ let unknown = 0;
48908
+ const rows = [];
48909
+ for (const query of candidates.queries) {
48910
+ const volume = volumes.get(query.keyword);
48911
+ if (typeof volume === "number" && volume > 0) continue;
48912
+ const known = typeof volume === "number";
48913
+ if (known) zero += 1;
48914
+ else unknown += 1;
48915
+ rows.push({
48916
+ keyword: query.keyword,
48917
+ [metric]: known ? volume : null,
48918
+ status: known ? "zero" : "unknown",
48919
+ impressions: query.impressions,
48920
+ clicks: query.clicks,
48921
+ position: query.position,
48922
+ page: query.page
48923
+ });
48924
+ }
48925
+ return {
48926
+ rows,
48927
+ zero,
48928
+ unknown,
48929
+ rated: candidates.queries.length - zero - unknown
48930
+ };
48931
+ }
48523
48932
  // packages/core/dist/commands/research.js
48524
48933
  const RESEARCH_ACTIONS = [
48525
48934
  "keyword_metrics",
@@ -48536,7 +48945,7 @@ const RESEARCH_ACTIONS = [
48536
48945
  "index_check"
48537
48946
  ];
48538
48947
  const RESEARCH_PROVIDERS = ["dataforseo", "ahrefs"];
48539
- const RESEARCH_HELP = `provider is optional: without it the call uses the saved key, DataForSEO when both are saved. In the CLI and the local MCP server, serp can also use a provider package installed on this machine that supplies live search results: pass its id as provider. The target is a domain (the whole site), a path ending in / such as example.com/blog/ (every URL under it), or one page; scope overrides that. keyword_metrics (keywords: volume, difficulty, CPC), keyword_ideas (up to 5 seed keywords: searches that contain each seed, by volume), ranked_keywords (target: keywords a site, subfolder or page ranks for, with the provider's traffic total for the whole target), top_pages (target: the pages with the most estimated organic traffic), serp (keywords, up to 5: the ranking pages with their organic position beside DataForSEO's rank_absolute, which also counts AI Overviews and other blocks, plus the AI Overview's sources; device desktop or mobile, DataForSEO only; each with its domain's authority: DataForSEO domain_rank 0 to 100, Ahrefs domain_rating; depth sets results per keyword, default 20; rows run position by position across the keywords), index_check (DataForSEO only; target: one page URL; keywords: up to 2 exact phrases from the page, default its H1 or title. Searches Google for site:<url> and each "<phrase>" on desktop and mobile, retries failed searches, treats Google's fallback to unrelated sites as no match, and says indexed, not found or unknown with each search's evidence; about $0.01 a page), serp_overlap (2 to 10 keywords: for each pair, how many of their top 10 pages and sites are the same, to decide one page or several; results without a real page are counted, not compared), competitors (target: domains that share keywords), backlinks (target: referring domains), pages_by_backlinks (target: the pages with the most referring domains), link_gap (target and 2 to 5 competitors: referring domains that link to two or more competitors and not the target, highest authority first, from each site's top 1,000 referring domains; costs one backlinks call per site), ai_answers (DataForSEO only; target: the site. Without keywords it takes the site’s top 10 chat-style and long questions from Search Console’s AI-shaped queries itself. With up to 10 questions in keywords it asks those instead, and the target can be any domain, such as a competitor's. Each answer row also lists the other sites it cites, and the notes rank them. Answers come from DataForSEO's queue: answers not ready after about 40 seconds are returned as tasks, already paid for; call again with the same target and those tasks to read them at no cost. It asks ChatGPT search, Google AI Mode and Google AI Overviews each one and says whether the answer cites or mentions the site. DataForSEO’s queue prices are about $0.0072 a question across the three engines, so about $0.07 a run: tell the person before running it). Rows with a domain, and the target, get a free Ahrefs domain_rating column. Numbers are provider estimates, not Search Console data.`;
48948
+ const RESEARCH_HELP = `provider is optional: without it the call uses the saved key, DataForSEO when both are saved. In the CLI and the local MCP server, serp can also use a provider package installed on this machine that supplies live search results: pass its id as provider. The target is a domain (the whole site), a path ending in / such as example.com/blog/ (every URL under it), or one page; scope overrides that. keyword_metrics (keywords: volume, difficulty, CPC; or target a Search Console site with no keywords: its top queries by impressions that the provider rates at zero or does not know, zero-volume keywords, in one call of up to 700 queries, about $0.10 on DataForSEO or 100 on Ahrefs), keyword_ideas (up to 5 seed keywords: searches that contain each seed, by volume), ranked_keywords (target: keywords a site, subfolder or page ranks for, with the provider's traffic total for the whole target), top_pages (target: the pages with the most estimated organic traffic), serp (keywords, up to 5: the ranking pages with their organic position beside DataForSEO's rank_absolute, which also counts AI Overviews and other blocks, plus the AI Overview's sources and the People Also Ask questions; device desktop or mobile, DataForSEO only; each with its domain's authority: DataForSEO domain_rank 0 to 100, Ahrefs domain_rating; depth sets results per keyword, default 20; rows run position by position across the keywords), index_check (DataForSEO only; target: one page URL; keywords: up to 2 exact phrases from the page, default its H1 or title. Searches Google for site:<url> and each "<phrase>" on desktop and mobile, retries failed searches, treats Google's fallback to unrelated sites as no match, and says indexed, not found or unknown with each search's evidence; about $0.01 a page), serp_overlap (2 to 10 keywords: for each pair, how many of their top 10 pages and sites are the same, to decide one page or several; results without a real page are counted, not compared), competitors (target: domains that share keywords), backlinks (target: referring domains), pages_by_backlinks (target: the pages with the most referring domains), link_gap (target and 2 to 5 competitors: referring domains that link to two or more competitors and not the target, highest authority first, from each site's top 1,000 referring domains; costs one backlinks call per site), ai_answers (DataForSEO only; target: the site. Without keywords it takes the site’s top 10 chat-style and long questions from Search Console’s AI-shaped queries itself. With up to 10 questions in keywords it asks those instead, and the target can be any domain, such as a competitor's. Each answer row also lists the other sites it cites, and the notes rank them. Answers come from DataForSEO's queue: answers not ready after about 40 seconds are returned as tasks, already paid for; call again with the same target and those tasks to read them at no cost. It asks ChatGPT search, Google AI Mode and Google AI Overviews each one and says whether the answer cites or mentions the site. Each ChatGPT row lists the web searches ChatGPT ran (fan-out), and the notes rank the most common; to see them for any questions, pass the questions in keywords with any target. Web search is not forced: forcing costs the same but makes ChatGPT search questions it answers from memory, so "none returned" means it answered without searching. AI Mode and AI Overviews do not report their searches. DataForSEO’s queue prices are about $0.0072 a question across the three engines, so about $0.07 a run: tell the person before running it). Rows with a domain, and the target, get a free Ahrefs domain_rating column. Numbers are provider estimates, not Search Console data.`;
48540
48949
  const GENERIC_PLATFORMS = [
48541
48950
  "youtube.com",
48542
48951
  "facebook.com",
@@ -48598,6 +49007,7 @@ async function runResearch(input, keys, options) {
48598
49007
  const offset = input.offset ?? 0;
48599
49008
  if (input.action === "ai_answers") throw new CommandError("INVALID_INPUT", "ai_answers runs on its own.");
48600
49009
  const provider = chooseProvider(input.provider, keys);
49010
+ if (input.action === "keyword_metrics" && !input.keywords?.length && target && options.searchAnalytics) return zeroVolume(input, keys, provider, options.searchAnalytics, options);
48601
49011
  const builtIn = RESEARCH_PROVIDERS.includes(provider) ? provider : null;
48602
49012
  if (!builtIn && input.action !== "serp") throw new CommandError("INVALID_INPUT", `An installed provider answers serp only; ${input.action} needs a built-in provider.`);
48603
49013
  if (input.action === "index_check") {
@@ -48627,7 +49037,8 @@ async function runResearch(input, keys, options) {
48627
49037
  competitors: input.competitors ?? [],
48628
49038
  country,
48629
49039
  ...input.action === "serp" ? { depth: input.depth ?? 20 } : {},
48630
- ...device === "mobile" ? { device } : {}
49040
+ ...device === "mobile" ? { device } : {},
49041
+ ...input.action === "serp" && input.peopleAlsoAskDepth ? { peopleAlsoAskDepth: input.peopleAlsoAskDepth } : {}
48631
49042
  };
48632
49043
  const store = options.store ?? workersResearchStore();
48633
49044
  const key = await researchKey([
@@ -48648,7 +49059,7 @@ async function runResearch(input, keys, options) {
48648
49059
  savedAt: (/* @__PURE__ */ new Date()).toISOString(),
48649
49060
  result
48650
49061
  });
48651
- const { rows: fetched, costUsd: paid, partial, missed, noData, floor, leftOut, available, siteTotal, rankFailed, compared, aiOverviews, warnings } = result;
49062
+ const { rows: fetched, costUsd: paid, partial, missed, noData, floor, leftOut, available, siteTotal, rankFailed, compared, aiOverviews, peopleAlsoAsk, warnings } = result;
48652
49063
  const costUsd = saved ? 0 : paid;
48653
49064
  const order = new Map(request.keywords.map((word, index) => [word, index]));
48654
49065
  const found = input.action === "serp" && request.keywords.length > 1 ? [...fetched].sort((a, b) => Number(a.position ?? 0) - Number(b.position ?? 0) || (order.get(String(a.keyword)) ?? 0) - (order.get(String(b.keyword)) ?? 0)) : fetched;
@@ -48680,6 +49091,7 @@ async function runResearch(input, keys, options) {
48680
49091
  ...VOLUME_ACTIONS.includes(input.action) && builtIn ? [`Volume model: ${VOLUME_MODEL[builtIn]} ${VOLUMES_DIFFER}`] : [],
48681
49092
  ...input.action === "serp" || input.action === "ranked_keywords" ? [positionNote(provider)] : [],
48682
49093
  ...aiOverviews?.length ? [aiOverviewNote(aiOverviews, request.keywords.length)] : input.action === "serp" && provider === "dataforseo" && rows.length ? ["No AI Overview on these results pages."] : [],
49094
+ ...peopleAlsoAsk?.length ? [peopleAlsoAskNote(peopleAlsoAsk, request.keywords.length)] : [],
48683
49095
  ...perKeyword ? [`Results per keyword: ${Object.entries(perKeyword).map(([word, count]) => `${word} ${count}`).join(", ")}. Rows run position by position across the keywords.`] : [],
48684
49096
  ...siteTotal && builtIn ? [siteTotalNote(builtIn, siteTotal, rows.length)] : [],
48685
49097
  ...available !== void 0 && available > found.length ? [`Capped: ${provider} has ${available.toLocaleString("en-US")} rows for this; this read the first ${found.length.toLocaleString("en-US")} in its order.`] : [],
@@ -48715,7 +49127,10 @@ async function runResearch(input, keys, options) {
48715
49127
  country,
48716
49128
  language,
48717
49129
  ...device ? { device: provider === "dataforseo" ? device : null } : {},
48718
- ...input.action === "serp" && provider === "dataforseo" ? { aiOverviews: aiOverviews ?? [] } : {},
49130
+ ...input.action === "serp" && provider === "dataforseo" ? {
49131
+ aiOverviews: aiOverviews ?? [],
49132
+ peopleAlsoAsk: peopleAlsoAsk ?? []
49133
+ } : {},
48719
49134
  targetDomainRating: hasTargetDr ? targetDr : null,
48720
49135
  attribution: rated.added || hasTargetDr ? DR_ATTRIBUTION : null,
48721
49136
  leftOut: note,
@@ -48744,6 +49159,10 @@ function positionNote(provider) {
48744
49159
  if (provider !== "dataforseo" && provider !== "ahrefs") return `position is the organic position the ${provider} package reports (its rankGroup); rank_absolute is its rank among every block on the page, and type is featured_snippet for a featured snippet, which has no organic position.`;
48745
49160
  return provider === "dataforseo" ? "position is the organic position: the nth organic link (DataForSEO rank_group). rank_absolute counts every block on the page from the top, AI Overviews, People Also Ask, videos and images included, so it is higher. A featured snippet has type featured_snippet and no organic position." : "position is the organic position: the nth row Ahrefs marks organic. ahrefs_position is Ahrefs' own position field, and type lists what each row is.";
48746
49161
  }
49162
+ function peopleAlsoAskNote(asked, keywords) {
49163
+ const each = asked.map((block) => `${block.keyword}: ${block.questions.map((item) => item.question).join(" | ")}`);
49164
+ return `People Also Ask shown for ${asked.length} of ${keywords} keyword${keywords === 1 ? "" : "s"}. ${each.join("; ")}. Google answers most of these with its own AI text, not a page; the answering page, when there is one, is in the JSON as peopleAlsoAsk.`;
49165
+ }
48747
49166
  function aiOverviewNote(overviews, keywords) {
48748
49167
  const each = overviews.map((overview) => {
48749
49168
  const sites = [...new Set(overview.references.map((ref) => ref.domain).filter((domain) => Boolean(domain)))];
@@ -48795,6 +49214,83 @@ async function sortedByDomainRating(rows, key) {
48795
49214
  added: true
48796
49215
  };
48797
49216
  }
49217
+ async function zeroVolume(input, keys, asked, searchAnalytics, options) {
49218
+ if (!RESEARCH_PROVIDERS.includes(asked)) throw new CommandError("INVALID_INPUT", "keyword_metrics for a site needs dataforseo or ahrefs.");
49219
+ const provider = asked;
49220
+ const country = input.country ?? "us";
49221
+ const site = input.target ?? "";
49222
+ const offset = input.offset ?? 0;
49223
+ const candidates = await zeroVolumeCandidates(site, searchAnalytics, ZERO_VOLUME_KEYWORDS[provider]);
49224
+ const keywords = candidates.queries.map((query) => query.keyword);
49225
+ const request = {
49226
+ action: "keyword_metrics",
49227
+ keywords,
49228
+ target: "",
49229
+ competitors: [],
49230
+ country
49231
+ };
49232
+ const limit = keywords.length;
49233
+ const store = options.store ?? workersResearchStore();
49234
+ const key = await researchKey([
49235
+ provider,
49236
+ keys.get(KEY_HEADER[provider]),
49237
+ request
49238
+ ]);
49239
+ const saved = keywords.length ? await readResearch(store, key, limit) : null;
49240
+ const result = keywords.length ? saved?.result ?? await research(provider, keys, {
49241
+ ...request,
49242
+ limit
49243
+ }) : null;
49244
+ if (result && !saved) await saveResearch(store, key, {
49245
+ limit,
49246
+ savedAt: (/* @__PURE__ */ new Date()).toISOString(),
49247
+ result
49248
+ });
49249
+ const found = result ? zeroVolumeRows(candidates, result.rows, provider) : {
49250
+ rows: [],
49251
+ zero: 0,
49252
+ unknown: 0,
49253
+ rated: 0
49254
+ };
49255
+ const costUsd = saved ? 0 : result?.costUsd ?? null;
49256
+ const detail = input.detail ?? "summary";
49257
+ const size = detail === "full" ? Math.max(found.rows.length, 1) : 50;
49258
+ const { skipped, range } = candidates;
49259
+ const metric = provider === "dataforseo" ? "search_volume" : "volume";
49260
+ return {
49261
+ text: rowsText({
49262
+ title: `${provider} zero-volume keywords for ${site}, ${country}: ${found.rows.length} of ${keywords.length} of the site's top queries by Search Console impressions (${range.startDate} to ${range.endDate}) have ${metric} 0 (${found.zero}) or none (${found.unknown}); ${found.rated} have a volume.`,
49263
+ rows: found.rows,
49264
+ offset,
49265
+ limit: size,
49266
+ detail,
49267
+ notes: [
49268
+ `Impressions, clicks and position are Search Console's; ${metric} is ${provider}'s estimate. ${VOLUME_MODEL[provider]} A zero or missing volume means the provider's data is below its floor or does not have the keyword, not that nobody searches it: the impressions show people do.`,
49269
+ `Asked about ${keywords.length} queries in one call (at most ${ZERO_VOLUME_KEYWORDS[provider]} for ${provider}). Not asked: ${skipped.brand} brand queries (${candidates.brandTerms.join(", ") || "no brand terms"}), ${skipped.notAKeyword} that are not keywords (operators, pasted text, over 10 words or 80 characters), ${skipped.overLimit} with fewer impressions.`,
49270
+ ...candidates.capped ? ["Search Console rows were capped at 25,000 query and page rows, so some queries were not read."] : [],
49271
+ saved ? `Read from the result saved at ${saved.savedAt}, at no new cost. Results are kept for a day.` : costUsd !== null ? `DataForSEO cost: $${costUsd}.` : provider === "ahrefs" ? "Ahrefs charges API units for each keyword returned; its response doesn't say how many." : "No keywords to ask about, so nothing was spent."
49272
+ ],
49273
+ more: options.call
49274
+ }),
49275
+ data: {
49276
+ provider,
49277
+ action: "keyword_metrics",
49278
+ target: site,
49279
+ country,
49280
+ range,
49281
+ asked: keywords.length,
49282
+ zero: found.zero,
49283
+ unknown: found.unknown,
49284
+ rated: found.rated,
49285
+ skipped,
49286
+ brandTerms: candidates.brandTerms,
49287
+ capped: candidates.capped,
49288
+ costUsd,
49289
+ savedAt: saved?.savedAt ?? null,
49290
+ rows: detail === "full" ? found.rows : found.rows.slice(offset, offset + size)
49291
+ }
49292
+ };
49293
+ }
48798
49294
  // packages/core/dist/commands/simple-analytics.js
48799
49295
  const SIMPLE_ANALYTICS_KEY = "x-simpleanalytics-key";
48800
49296
  const simpleAnalyticsKey = (keys) => keys.get("x-simpleanalytics-key")?.trim() || null;
@@ -49654,6 +50150,7 @@ function telemetryReportFor(command, args = {}) {
49654
50150
  "internal-links": "internal-links"
49655
50151
  }[command] ?? null;
49656
50152
  }
50153
+ [...STOPWORDS];
49657
50154
  // packages/core/dist/commands/week.js
49658
50155
  const DAY_MS = 864e5;
49659
50156
  function weekLabel(start, end) {
@@ -50109,7 +50606,12 @@ const SHARED_TOOLS = [
50109
50606
  brand: input.brand
50110
50607
  }, await surface.keys(), surface.deps, (offset, tasks) => `seo_research with the same provider, action, target, also and brand, tasks ${JSON.stringify(tasks)}, detail "rows", offset ${offset}. Passing the tasks reads these answers back at no cost; without them every question is asked and paid for again`);
50111
50608
  }
50112
- return runResearch(input, await surface.keys(), {
50609
+ const zeroVolume = input.action === "keyword_metrics" && !input.keywords.length && input.target;
50610
+ return runResearch(zeroVolume ? {
50611
+ ...input,
50612
+ target: await surface.resolveSite(input.target)
50613
+ } : input, await surface.keys(), {
50614
+ searchAnalytics: zeroVolume ? surface.deps.searchAnalytics : void 0,
50113
50615
  drKey: surface.drKey,
50114
50616
  store: surface.researchStore,
50115
50617
  installedSerp: surface.installedSerp,