seo 0.18.1 → 0.19.0

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-BVLLXPWR.js";
2
+ import { i as __toESM, n as version, r as __commonJSMin, t as load } from "./esm-vb8HxBFD.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";
@@ -13222,17 +13222,17 @@ function isAgentFindings(value) {
13222
13222
  const counts = record(candidate?.counts);
13223
13223
  return candidate?.schemaVersion === 1 && candidate.scope === "returned-report" && typeof counts?.total === "number" && typeof counts.returned === "number" && Array.isArray(candidate.items) && candidate.items.every((value) => {
13224
13224
  const item = record(value);
13225
- if (!text$2(item?.id) || item?.status !== "open" || !text$2(item.title) || !text$2(item.sourcePath) || !Array.isArray(item.allowedOutcomes)) return false;
13226
- if (item.type === "fix") return Boolean(text$2(record(item.fix)?.instruction));
13225
+ if (!text$3(item?.id) || item?.status !== "open" || !text$3(item.title) || !text$3(item.sourcePath) || !Array.isArray(item.allowedOutcomes)) return false;
13226
+ if (item.type === "fix") return Boolean(text$3(record(item.fix)?.instruction));
13227
13227
  if (item.type === "review") {
13228
13228
  const review = record(item.review);
13229
13229
  if (!review) return false;
13230
- return Boolean(text$2(review.question) && text$2(review.changeOnlyIf) && text$2(review.ifConfirmed) && text$2(review.ifNotNeeded) && Array.isArray(review.doNot));
13230
+ return Boolean(text$3(review.question) && text$3(review.changeOnlyIf) && text$3(review.ifConfirmed) && text$3(review.ifNotNeeded) && Array.isArray(review.doNot));
13231
13231
  }
13232
13232
  return false;
13233
13233
  });
13234
13234
  }
13235
- function text$2(value) {
13235
+ function text$3(value) {
13236
13236
  return typeof value === "string" && value.trim() ? value.trim() : void 0;
13237
13237
  }
13238
13238
  function stableId(value) {
@@ -13255,7 +13255,7 @@ function findingId(item, path, action) {
13255
13255
  "actionId",
13256
13256
  "id"
13257
13257
  ]) {
13258
- const id = text$2(item[key]);
13258
+ const id = text$3(item[key]);
13259
13259
  if (id) return id;
13260
13260
  }
13261
13261
  return `action-${stableId(`${path}|${action}`)}`;
@@ -13265,9 +13265,9 @@ function findingType(path, item) {
13265
13265
  }
13266
13266
  function findingVerification(item, fallback) {
13267
13267
  const supplied = record(item.verification);
13268
- const expected = text$2(supplied?.expected ?? item.howToVerify ?? fallback);
13268
+ const expected = text$3(supplied?.expected ?? item.howToVerify ?? fallback);
13269
13269
  if (!expected) return void 0;
13270
- const command = text$2(supplied?.command);
13270
+ const command = text$3(supplied?.command);
13271
13271
  return {
13272
13272
  ...command ? { command } : {},
13273
13273
  expected
@@ -13275,14 +13275,14 @@ function findingVerification(item, fallback) {
13275
13275
  }
13276
13276
  function stringArray(value) {
13277
13277
  if (!Array.isArray(value)) return [];
13278
- return value.flatMap((item) => text$2(item) ? [text$2(item)] : []);
13278
+ return value.flatMap((item) => text$3(item) ? [text$3(item)] : []);
13279
13279
  }
13280
13280
  function affectedUrls(item, affectedCount) {
13281
13281
  const items = stringArray(item.sampleUrls);
13282
13282
  const details = record(item.affectedUrlsReport);
13283
13283
  const params = record(details?.params);
13284
- const reportId = details?.id === "affected-urls" ? text$2(params?.reportId) : void 0;
13285
- const ruleId = details?.id === "affected-urls" ? text$2(params?.ruleId) : void 0;
13284
+ const reportId = details?.id === "affected-urls" ? text$3(params?.reportId) : void 0;
13285
+ const ruleId = details?.id === "affected-urls" ? text$3(params?.ruleId) : void 0;
13286
13286
  if (!items.length && !reportId) return void 0;
13287
13287
  const total = affectedCount ?? items.length;
13288
13288
  return {
@@ -13302,13 +13302,13 @@ function affectedUrls(item, affectedCount) {
13302
13302
  function reviewGuidance(item, title, action) {
13303
13303
  const supplied = record(item.review);
13304
13304
  const evidence = record(item.evidence);
13305
- const ruleId = text$2(item.ruleId ?? evidence?.ruleId);
13305
+ const ruleId = text$3(item.ruleId ?? evidence?.ruleId);
13306
13306
  const defined = (ruleId ? explainRule(ruleId) : void 0)?.review;
13307
13307
  return {
13308
- question: text$2(supplied?.question) ?? defined?.question ?? `Does the retained evidence and confirmed intent show that "${title}" needs a change?`,
13309
- changeOnlyIf: text$2(supplied?.changeOnlyIf) ?? defined?.changeOnlyIf ?? "Make a change only when the retained evidence and required intent support it.",
13310
- ifConfirmed: text$2(supplied?.ifConfirmed) ?? action,
13311
- ifNotNeeded: text$2(supplied?.ifNotNeeded) ?? defined?.ifNotNeeded ?? "Record no change and cite the evidence or confirmed intent that makes a change unnecessary.",
13308
+ question: text$3(supplied?.question) ?? defined?.question ?? `Does the retained evidence and confirmed intent show that "${title}" needs a change?`,
13309
+ changeOnlyIf: text$3(supplied?.changeOnlyIf) ?? defined?.changeOnlyIf ?? "Make a change only when the retained evidence and required intent support it.",
13310
+ ifConfirmed: text$3(supplied?.ifConfirmed) ?? action,
13311
+ ifNotNeeded: text$3(supplied?.ifNotNeeded) ?? defined?.ifNotNeeded ?? "Record no change and cite the evidence or confirmed intent that makes a change unnecessary.",
13312
13312
  doNot: stringArray(supplied?.doNot).length ? stringArray(supplied?.doNot) : [...defined?.doNot ?? []]
13313
13313
  };
13314
13314
  }
@@ -13327,7 +13327,7 @@ function findingEvidence(item) {
13327
13327
  }
13328
13328
  function normalizeFinding(value, path, index, options) {
13329
13329
  if (typeof value === "string") {
13330
- const action = text$2(value);
13330
+ const action = text$3(value);
13331
13331
  if (!action) return void 0;
13332
13332
  const common = {
13333
13333
  id: `action-${stableId(`${options.reportId ?? ""}|${path}|${action}`)}`,
@@ -13359,8 +13359,8 @@ function normalizeFinding(value, path, index, options) {
13359
13359
  }
13360
13360
  const item = record(value);
13361
13361
  if (!item) return void 0;
13362
- const action = text$2(item.action) ?? text$2(item.howToFix) ?? (item.recommendation === "fix" || item.recommendation === "review" ? void 0 : text$2(item.recommendation)) ?? text$2(item.nextStep);
13363
- const title = text$2(item.title) ?? text$2(item.headline) ?? text$2(item.name) ?? action;
13362
+ const action = text$3(item.action) ?? text$3(item.howToFix) ?? (item.recommendation === "fix" || item.recommendation === "review" ? void 0 : text$3(item.recommendation)) ?? text$3(item.nextStep);
13363
+ const title = text$3(item.title) ?? text$3(item.headline) ?? text$3(item.name) ?? action;
13364
13364
  if (!action || !title) return void 0;
13365
13365
  const confidence = [
13366
13366
  "high",
@@ -13378,7 +13378,7 @@ function normalizeFinding(value, path, index, options) {
13378
13378
  status: "open",
13379
13379
  title,
13380
13380
  ...confidence ? { confidence } : {},
13381
- ...text$2(item.severity) ? { severity: text$2(item.severity) } : {},
13381
+ ...text$3(item.severity) ? { severity: text$3(item.severity) } : {},
13382
13382
  ...typeof affectedCount === "number" && Number.isFinite(affectedCount) ? { affectedCount } : {},
13383
13383
  ...urls ? { affectedUrls: urls } : {},
13384
13384
  sourcePath: `${path}[${index}]`,
@@ -13440,7 +13440,7 @@ function inventory(value, path, reportId) {
13440
13440
  const totalItems = typeof (source.totalPages ?? source.totalItems) === "number" ? Number(source.totalPages ?? source.totalItems) : source.rows.length;
13441
13441
  const items = source.rows.map((value, index) => {
13442
13442
  const row = record(value) ?? { value };
13443
- const identity = text$2(row.id) ?? text$2(row.url) ?? text$2(row.path) ?? `${path}[${index}]`;
13443
+ const identity = text$3(row.id) ?? text$3(row.url) ?? text$3(row.path) ?? `${path}[${index}]`;
13444
13444
  return {
13445
13445
  ...row,
13446
13446
  id: `inventory-item-${stableId(`${reportId ?? ""}|${path}|${identity}`)}`,
@@ -13459,7 +13459,7 @@ function inventory(value, path, reportId) {
13459
13459
  returnedItems: items.length,
13460
13460
  complete: source.capped === false && items.length >= totalItems,
13461
13461
  ...source.criteria !== void 0 ? { criteria: source.criteria } : {},
13462
- ...text$2(source.note) ? { note: text$2(source.note) } : {},
13462
+ ...text$3(source.note) ? { note: text$3(source.note) } : {},
13463
13463
  ...pageCount !== void 0 ? { pagination: {
13464
13464
  page,
13465
13465
  pageCount,
@@ -43648,6 +43648,31 @@ function flattenIntents(row) {
43648
43648
  }
43649
43649
  // packages/core/dist/commands/research-serp.js
43650
43650
  const GOTO = /^https?:\/\/(www\.)?google\.[a-z.]+\/goto\b/;
43651
+ const bare$2 = (host) => host.toLowerCase().replace(/^www\./, "");
43652
+ function pageKey(url) {
43653
+ try {
43654
+ const parsed = new URL(url);
43655
+ return `${bare$2(parsed.hostname)}${parsed.pathname.replace(/\/+$/, "")}`.toLowerCase();
43656
+ } catch {
43657
+ return "";
43658
+ }
43659
+ }
43660
+ function hintKey(hint) {
43661
+ const parts = hint.split("›").map((part) => part.trim());
43662
+ if (!parts[0] || parts.some((part) => /^\.\.\.$|…/.test(part))) return null;
43663
+ return `${bare$2(parts[0])}${parts.length > 1 ? `/${parts.slice(1).join("/")}` : ""}`.toLowerCase();
43664
+ }
43665
+ function overlapKey(row) {
43666
+ if (typeof row.url === "string" && row.url) return {
43667
+ key: pageKey(row.url),
43668
+ breadcrumb: false
43669
+ };
43670
+ const hint = typeof row.url_hint === "string" ? hintKey(row.url_hint) : null;
43671
+ return {
43672
+ key: hint?.includes("/") ? hint : "",
43673
+ breadcrumb: true
43674
+ };
43675
+ }
43651
43676
  const hostOf$3 = (url) => {
43652
43677
  try {
43653
43678
  return new URL(url).hostname;
@@ -43655,13 +43680,13 @@ const hostOf$3 = (url) => {
43655
43680
  return "";
43656
43681
  }
43657
43682
  };
43658
- const text$1 = (value) => typeof value === "string" && value ? value : null;
43683
+ const text$2 = (value) => typeof value === "string" && value ? value : null;
43659
43684
  function dataForSeoSerp(keyword, items) {
43660
43685
  const asked = /* @__PURE__ */ new Map();
43661
43686
  for (const block of items) {
43662
43687
  if (block.type !== "people_also_ask") continue;
43663
43688
  for (const element of block.items ?? []) {
43664
- const question = text$1(element.title);
43689
+ const question = text$2(element.title);
43665
43690
  if (!question || asked.has(question.toLowerCase())) continue;
43666
43691
  const answer = element.expanded_element?.[0];
43667
43692
  const page = answer?.type === "people_also_ask_expanded_element";
@@ -43671,8 +43696,8 @@ function dataForSeoSerp(keyword, items) {
43671
43696
  question,
43672
43697
  aiAnswer: answer?.type === "people_also_ask_ai_overview_expanded_element",
43673
43698
  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
43699
+ domain: page ? goto ? null : text$2(answer?.domain) ?? (hostOf$3(url) || null) : null,
43700
+ title: page ? text$2(answer?.title) : null
43676
43701
  });
43677
43702
  }
43678
43703
  }
@@ -43687,9 +43712,9 @@ function dataForSeoSerp(keyword, items) {
43687
43712
  const url = String(ref.url ?? "");
43688
43713
  const goto = GOTO.test(url);
43689
43714
  return {
43690
- domain: goto ? null : text$1(ref.domain) ?? (hostOf$3(url) || null),
43715
+ domain: goto ? null : text$2(ref.domain) ?? (hostOf$3(url) || null),
43691
43716
  url: goto || !url ? null : url,
43692
- title: text$1(ref.title)
43717
+ title: text$2(ref.title)
43693
43718
  };
43694
43719
  })
43695
43720
  } : null;
@@ -43700,9 +43725,9 @@ function dataForSeoSerp(keyword, items) {
43700
43725
  position: item.type === "organic" ? Number(item.rank_group) : null,
43701
43726
  rank_absolute: Number(item.rank_absolute),
43702
43727
  type: String(item.type),
43703
- url: text$1(item.url),
43704
- domain: text$1(item.domain),
43705
- title: text$1(item.title)
43728
+ url: text$2(item.url),
43729
+ domain: text$2(item.domain),
43730
+ title: text$2(item.title)
43706
43731
  };
43707
43732
  if (GOTO.test(String(row.url))) {
43708
43733
  const crumb = String(item.breadcrumb ?? "");
@@ -44158,12 +44183,15 @@ async function serpOverlap(provider, headers, input) {
44158
44183
  const host = (value) => String(value ?? "").toLowerCase().replace(/^www\./, "");
44159
44184
  const top = new Map(keywords.map((keyword) => {
44160
44185
  const rows = serps.rows.filter((row) => row.keyword === keyword && row.type !== "featured_snippet").slice(0, OVERLAP_DEPTH);
44161
- const pages = new Set(rows.map((row) => row.url).filter((url) => typeof url === "string" && url !== "").map((url) => url.replace(/\/$/, "").toLowerCase()));
44186
+ const keys = rows.map(overlapKey);
44187
+ const pages = new Set(keys.map((k) => k.key).filter(Boolean));
44188
+ const fromBreadcrumb = new Set(keys.filter((k) => k.key && k.breadcrumb).map((k) => k.key)).size;
44162
44189
  const sites = new Set(rows.map((row) => host(row.domain ?? siteOf(row.url))).filter(Boolean));
44163
44190
  return [keyword, {
44164
44191
  results: rows.length,
44165
44192
  pages,
44166
- sites
44193
+ sites,
44194
+ fromBreadcrumb
44167
44195
  }];
44168
44196
  }));
44169
44197
  const rows = [];
@@ -44190,7 +44218,8 @@ async function serpOverlap(provider, headers, input) {
44190
44218
  compared: {
44191
44219
  results: results.reduce((sum, item) => sum + item.results, 0),
44192
44220
  withPage: results.reduce((sum, item) => sum + item.pages.size, 0),
44193
- withSite: results.reduce((sum, item) => sum + item.sites.size, 0)
44221
+ withSite: results.reduce((sum, item) => sum + item.sites.size, 0),
44222
+ fromBreadcrumb: results.reduce((sum, item) => sum + item.fromBreadcrumb, 0)
44194
44223
  }
44195
44224
  };
44196
44225
  }
@@ -48626,20 +48655,7 @@ async function runBingReport(input, deps) {
48626
48655
  }
48627
48656
  const DEVICES = ["desktop", "mobile"];
48628
48657
  const DEPTH = 10;
48629
- const bare = (host) => host.toLowerCase().replace(/^www\./, "");
48630
- function key(url) {
48631
- try {
48632
- const parsed = new URL(url);
48633
- return `${bare(parsed.hostname)}${parsed.pathname.replace(/\/+$/, "")}`.toLowerCase();
48634
- } catch {
48635
- return "";
48636
- }
48637
- }
48638
- function hintKey(hint) {
48639
- const parts = hint.split("›").map((part) => part.trim());
48640
- if (!parts[0] || parts.some((part) => /^\.\.\.$|…/.test(part))) return null;
48641
- return `${bare(parts[0])}${parts.length > 1 ? `/${parts.slice(1).join("/")}` : ""}`.toLowerCase();
48642
- }
48658
+ const bare$1 = (host) => host.toLowerCase().replace(/^www\./, "");
48643
48659
  function phraseFrom(text, words = 2) {
48644
48660
  const cleaned = (text ?? "").split(/\s+[|\u2013\u2014-]\s+/)[0]?.replace(/["“”]/g, "").trim();
48645
48661
  if (!cleaned || cleaned.split(/\s+/).length < words) return null;
@@ -48655,8 +48671,8 @@ async function runIndexCheck(input, headers) {
48655
48671
  const keys = dataForSeoKeys(headers);
48656
48672
  const country = input.country ?? "us";
48657
48673
  const market = dataForSeoMarket(country, dataForSeoLanguage(country));
48658
- const page = key(target.href);
48659
- const host = bare(target.hostname);
48674
+ const page = pageKey(target.href);
48675
+ const host = bare$1(target.hostname);
48660
48676
  let phrases = (input.phrases ?? []).slice(0, 2);
48661
48677
  let phraseSource = phrases.length ? "given" : null;
48662
48678
  if (!phrases.length) {
@@ -48692,10 +48708,10 @@ async function runIndexCheck(input, headers) {
48692
48708
  row.results = results.length;
48693
48709
  row.top_domains = [...new Set(results.map((r) => String(r.domain ?? "?")))].slice(0, 3).join(", ");
48694
48710
  const onSite = results.filter((r) => {
48695
- const domain = bare(String(r.domain ?? ""));
48711
+ const domain = bare$1(String(r.domain ?? ""));
48696
48712
  return domain === host || domain.endsWith(`.${host}`);
48697
48713
  });
48698
- const match = onSite.find((r) => typeof r.url === "string" && key(r.url) === page || typeof r.url_hint === "string" && hintKey(r.url_hint) === page);
48714
+ const match = onSite.find((r) => typeof r.url === "string" && pageKey(r.url) === page || typeof r.url_hint === "string" && hintKey(r.url_hint) === page);
48699
48715
  if (match) {
48700
48716
  row.result = "page";
48701
48717
  row.position = typeof match.position === "number" ? match.position : null;
@@ -48811,6 +48827,108 @@ async function installedSerpResearch(provider, input, serp) {
48811
48827
  warnings
48812
48828
  };
48813
48829
  }
48830
+ const PER_TERM = 100;
48831
+ const SNIPPET = 200;
48832
+ const bare = (host) => host.toLowerCase().replace(/^www\./, "");
48833
+ const text$1 = (value) => typeof value === "string" && value.trim() ? value.trim() : null;
48834
+ async function runMentions(input, headers) {
48835
+ const target = bare(input.target.replace(/^https?:\/\//i, "").split("/")[0]?.trim() ?? "");
48836
+ if (!target.includes(".")) throw new CommandError("INVALID_INPUT", "mentions needs a domain as target, such as example.com.");
48837
+ const keys = dataForSeoKeys(headers);
48838
+ const terms = [...new Set([target, ...input.brand ?? []].map((term) => term.replace(/"/g, "").trim().toLowerCase()).filter(Boolean))].slice(0, 4);
48839
+ const onTarget = (host) => host === target || host.endsWith(`.${target}`);
48840
+ let cost = 0;
48841
+ const found = /* @__PURE__ */ new Map();
48842
+ const capped = [];
48843
+ for (const term of terms) {
48844
+ const done = await dataForSeoTask(keys, "v3/content_analysis/search/live", {
48845
+ keyword: `"${term}"`,
48846
+ search_mode: "one_per_domain",
48847
+ limit: PER_TERM
48848
+ });
48849
+ cost += done.cost;
48850
+ const items = done.result?.items ?? [];
48851
+ if (Number(done.result?.total_count ?? 0) > items.length) capped.push(term);
48852
+ for (const item of items) {
48853
+ const site = bare(String(item.main_domain ?? item.domain ?? ""));
48854
+ const url = text$1(item.url);
48855
+ if (!site || !url || onTarget(bare(String(item.domain ?? site)))) continue;
48856
+ if (found.has(site)) continue;
48857
+ const info = item.content_info ?? {};
48858
+ const snippet = text$1(info.snippet);
48859
+ found.set(site, {
48860
+ site,
48861
+ url,
48862
+ title: text$1(info.main_title) ?? text$1(info.title),
48863
+ snippet: snippet ? snippet.length > SNIPPET ? `${snippet.slice(0, SNIPPET)}…` : snippet : null,
48864
+ matched: term,
48865
+ domain_rank: typeof item.domain_rank === "number" ? item.domain_rank : null,
48866
+ fetched: text$1(item.fetch_time),
48867
+ links: "not_found"
48868
+ });
48869
+ }
48870
+ }
48871
+ const sites = [...found.keys()];
48872
+ let linkCheck = "none";
48873
+ if (sites.length) try {
48874
+ const done = await dataForSeoTask(keys, "v3/backlinks/backlinks/live", {
48875
+ target,
48876
+ mode: "one_per_domain",
48877
+ filters: [
48878
+ "domain_from",
48879
+ "in",
48880
+ sites.flatMap((s) => [s, `www.${s}`])
48881
+ ],
48882
+ limit: 1e3
48883
+ });
48884
+ cost += done.cost;
48885
+ const items = done.result?.items ?? [];
48886
+ for (const item of items) {
48887
+ const from = bare(String(item.domain_from ?? ""));
48888
+ const mention = found.get(from) ?? [...found.values()].find((m) => from.endsWith(`.${m.site}`));
48889
+ if (mention) mention.links = "yes";
48890
+ }
48891
+ linkCheck = "done";
48892
+ } catch (error) {
48893
+ cost += error.cost ?? 0;
48894
+ linkCheck = "failed";
48895
+ }
48896
+ const rows = [...found.values()].sort((a, b) => Number(a.matched !== target) - Number(b.matched !== target) || Number(a.links === "yes") - Number(b.links === "yes") || (b.domain_rank ?? -1) - (a.domain_rank ?? -1) || a.site.localeCompare(b.site));
48897
+ const unlinked = rows.filter((row) => row.links !== "yes").length;
48898
+ const named = rows.filter((row) => row.matched === target);
48899
+ const spent = Math.round(cost * 1e4) / 1e4;
48900
+ const notes = [
48901
+ `Searched DataForSEO's content index for ${terms.map((t) => `"${t}"`).join(", ")}, one page per site, leaving out ${target} and its subdomains. DataForSEO cost: $${spent}.`,
48902
+ rows.length ? `${named.length} sites name ${target}, and ${named.filter((row) => row.links !== "yes").length} of them have no link to it in DataForSEO's backlink index.${rows.length > named.length ? ` ${rows.length - named.length} more match only a brand name, ${unlinked - named.filter((row) => row.links !== "yes").length} of them with no link found.` : ""}` : `No pages in DataForSEO's content index mention ${terms.join(" or ")}. That index is a sample of the web, so a mention it hasn't crawled won't show.`,
48903
+ ...terms.length > 1 ? [`Pages that name ${target} come first. A brand name that is also an ordinary phrase matches pages using the words, not the brand, so check those rows before you count them.`] : [],
48904
+ ...capped.length ? [`More pages mention ${capped.join(", ")} than the ${PER_TERM} sites read per term, so the list is partial.`] : [],
48905
+ ...linkCheck === "failed" ? ["The backlink check failed, so links is not_found for every site: whether they link is unknown."] : [],
48906
+ "links: yes means DataForSEO has a link from that site to the target; not_found means it has none, which can also be a link it hasn't crawled, so check the page before you ask. A mention with no link is a site that already knows you: ask for the link, or for a correct one.",
48907
+ "domain_rank is DataForSEO's own authority score, not Ahrefs' Domain Rating."
48908
+ ];
48909
+ return {
48910
+ text: rowsText({
48911
+ title: `Mentions of ${target}.`,
48912
+ rows,
48913
+ offset: input.offset ?? 0,
48914
+ limit: 50,
48915
+ detail: input.detail ?? "summary",
48916
+ notes
48917
+ }),
48918
+ data: {
48919
+ provider: "dataforseo",
48920
+ action: "mentions",
48921
+ target,
48922
+ terms,
48923
+ costUsd: spent,
48924
+ partial: capped.length > 0,
48925
+ linkCheck,
48926
+ total: rows.length,
48927
+ unlinked,
48928
+ rows: rows.slice(input.offset ?? 0, (input.offset ?? 0) + 50)
48929
+ }
48930
+ };
48931
+ }
48814
48932
  // packages/core/dist/commands/research-zero-volume.js
48815
48933
  const ZERO_VOLUME_KEYWORDS = {
48816
48934
  dataforseo: 700,
@@ -48942,10 +49060,11 @@ const RESEARCH_ACTIONS = [
48942
49060
  "pages_by_backlinks",
48943
49061
  "keyword_ideas",
48944
49062
  "serp_overlap",
48945
- "index_check"
49063
+ "index_check",
49064
+ "mentions"
48946
49065
  ];
48947
49066
  const RESEARCH_PROVIDERS = ["dataforseo", "ahrefs"];
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.`;
49067
+ 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 behind a Google redirect link are compared by their breadcrumb's site and path, and counted, not compared, when it is shortened), mentions (DataForSEO only; target: a domain; brand: up to 3 brand names. Pages on other sites that name the domain or brand, one per site, from DataForSEO's content index, and whether each site already links to the target in DataForSEO's backlink index; sites with no link come first, to ask for the link. About $0.03 a term plus one backlinks call, under $0.10 a run), 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.`;
48949
49068
  const GENERIC_PLATFORMS = [
48950
49069
  "youtube.com",
48951
49070
  "facebook.com",
@@ -49006,6 +49125,15 @@ async function runResearch(input, keys, options) {
49006
49125
  const target = input.target ?? "";
49007
49126
  const offset = input.offset ?? 0;
49008
49127
  if (input.action === "ai_answers") throw new CommandError("INVALID_INPUT", "ai_answers runs on its own.");
49128
+ if (input.action === "mentions") {
49129
+ if (input.provider && input.provider !== "dataforseo") throw new CommandError("INVALID_INPUT", "mentions uses dataforseo.");
49130
+ return runMentions({
49131
+ target,
49132
+ brand: input.brand,
49133
+ offset,
49134
+ detail: input.detail
49135
+ }, keys);
49136
+ }
49009
49137
  const provider = chooseProvider(input.provider, keys);
49010
49138
  if (input.action === "keyword_metrics" && !input.keywords?.length && target && options.searchAnalytics) return zeroVolume(input, keys, provider, options.searchAnalytics, options);
49011
49139
  const builtIn = RESEARCH_PROVIDERS.includes(provider) ? provider : null;
@@ -49087,7 +49215,7 @@ async function runResearch(input, keys, options) {
49087
49215
  detail,
49088
49216
  notes: [
49089
49217
  `${provider} estimates, in the provider’s own units.`,
49090
- ...compared ? [`Compared: ${compared.withPage} of ${compared.results} top results had a real page, so shared_pages counts only those; ${compared.results - compared.withPage} came back as Google redirect links and could not be compared by page. ${compared.withSite} had a known site for shared_sites. Unique pages and sites are counted per keyword.${compared.withPage < compared.results / 2 && provider === "dataforseo" ? " With this few pages, shared_pages cannot settle one page or several; provider ahrefs returns real pages." : ""}`] : [],
49218
+ ...compared ? [`Compared: ${compared.withPage} of ${compared.results} top results by page, so shared_pages counts only those${compared.fromBreadcrumb ? `; ${compared.fromBreadcrumb} of them came back as Google redirect links and were matched by Google's breadcrumb (site and path), which names the page but can't tell apart two pages with the same breadcrumb` : ""}. ${compared.results - compared.withPage} had no page to compare (a shortened or site-only breadcrumb). ${compared.withSite} had a known site for shared_sites. Unique pages and sites are counted per keyword. Each keyword is one live snapshot, and live results can change a lot from one pull to the next, so a low overlap is weak evidence on its own; where the site already ranks, Search Console queries that land on the same page are a steadier sign of one topic.${compared.withPage < compared.results / 2 && provider === "dataforseo" ? " With this few pages, shared_pages cannot settle one page or several; provider ahrefs returns real pages." : ""}`] : [],
49091
49219
  ...VOLUME_ACTIONS.includes(input.action) && builtIn ? [`Volume model: ${VOLUME_MODEL[builtIn]} ${VOLUMES_DIFFER}`] : [],
49092
49220
  ...input.action === "serp" || input.action === "ranked_keywords" ? [positionNote(provider)] : [],
49093
49221
  ...aiOverviews?.length ? [aiOverviewNote(aiOverviews, request.keywords.length)] : input.action === "serp" && provider === "dataforseo" && rows.length ? ["No AI Overview on these results pages."] : [],
@@ -50585,7 +50713,7 @@ const SHARED_TOOLS = [
50585
50713
  competitors: z.array(z.string().min(1)).max(5).default([]).describe("link_gap only: 2 to 5 competitor domains."),
50586
50714
  tasks: z.array(z.string().regex(AI_ANSWER_TASK_PATTERN)).max(30).default([]).describe("ai_answers only: the tasks an earlier run returned as not ready, to read back at no cost."),
50587
50715
  also: z.array(z.string().min(1)).max(4).default([]).describe("ai_answers only: the brand's other domains, such as claude.ai beside claude.com. A citation to any of them counts as citing the target."),
50588
- brand: z.array(z.string().min(1).max(60)).max(10).default([]).describe("ai_answers only: the brand names that count as a mention, such as Datadog for datadoghq.com. Default: each domain's name."),
50716
+ brand: z.array(z.string().min(1).max(60)).max(10).default([]).describe("ai_answers and mentions: the brand names that count as a mention, such as Datadog for datadoghq.com. Default: each domain's name for ai_answers; mentions searches the domain itself plus up to 3 names."),
50589
50717
  country: z.string().regex(/^[a-z]{2}$/).default("us").describe("Two-letter country code."),
50590
50718
  depth: z.number().int().min(1).max(100).optional().describe(`serp only: results per keyword, default 20. Deeper costs more.`),
50591
50719
  device: z.enum(RESEARCH_DEVICES).optional().describe("serp only: desktop (default) or mobile. Google ranks pages differently on each. DataForSEO only."),