seo 0.18.0 → 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/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __seoCreateRequire } from 'node:module'; const require = __seoCreateRequire(import.meta.url);
2
- import { n as version, t as load } from "./esm-X4uq3k2w.js";
2
+ import { n as version, t as load } from "./esm-vb8HxBFD.js";
3
3
  import { SEO_PROVIDER_API_VERSION } from "./provider-sdk.js";
4
4
  import crypto$1, { createHash, randomUUID, sign } from "node:crypto";
5
5
  import { z } from "zod";
@@ -1104,17 +1104,17 @@ function isAgentFindings(value) {
1104
1104
  const counts = record(candidate?.counts);
1105
1105
  return candidate?.schemaVersion === 1 && candidate.scope === "returned-report" && typeof counts?.total === "number" && typeof counts.returned === "number" && Array.isArray(candidate.items) && candidate.items.every((value) => {
1106
1106
  const item = record(value);
1107
- if (!text$1(item?.id) || item?.status !== "open" || !text$1(item.title) || !text$1(item.sourcePath) || !Array.isArray(item.allowedOutcomes)) return false;
1108
- if (item.type === "fix") return Boolean(text$1(record(item.fix)?.instruction));
1107
+ if (!text$2(item?.id) || item?.status !== "open" || !text$2(item.title) || !text$2(item.sourcePath) || !Array.isArray(item.allowedOutcomes)) return false;
1108
+ if (item.type === "fix") return Boolean(text$2(record(item.fix)?.instruction));
1109
1109
  if (item.type === "review") {
1110
1110
  const review = record(item.review);
1111
1111
  if (!review) return false;
1112
- return Boolean(text$1(review.question) && text$1(review.changeOnlyIf) && text$1(review.ifConfirmed) && text$1(review.ifNotNeeded) && Array.isArray(review.doNot));
1112
+ return Boolean(text$2(review.question) && text$2(review.changeOnlyIf) && text$2(review.ifConfirmed) && text$2(review.ifNotNeeded) && Array.isArray(review.doNot));
1113
1113
  }
1114
1114
  return false;
1115
1115
  });
1116
1116
  }
1117
- function text$1(value) {
1117
+ function text$2(value) {
1118
1118
  return typeof value === "string" && value.trim() ? value.trim() : void 0;
1119
1119
  }
1120
1120
  function stableId(value) {
@@ -1137,7 +1137,7 @@ function findingId(item, path, action) {
1137
1137
  "actionId",
1138
1138
  "id"
1139
1139
  ]) {
1140
- const id = text$1(item[key]);
1140
+ const id = text$2(item[key]);
1141
1141
  if (id) return id;
1142
1142
  }
1143
1143
  return `action-${stableId(`${path}|${action}`)}`;
@@ -1147,9 +1147,9 @@ function findingType(path, item) {
1147
1147
  }
1148
1148
  function findingVerification(item, fallback) {
1149
1149
  const supplied = record(item.verification);
1150
- const expected = text$1(supplied?.expected ?? item.howToVerify ?? fallback);
1150
+ const expected = text$2(supplied?.expected ?? item.howToVerify ?? fallback);
1151
1151
  if (!expected) return void 0;
1152
- const command = text$1(supplied?.command);
1152
+ const command = text$2(supplied?.command);
1153
1153
  return {
1154
1154
  ...command ? { command } : {},
1155
1155
  expected
@@ -1157,14 +1157,14 @@ function findingVerification(item, fallback) {
1157
1157
  }
1158
1158
  function stringArray(value) {
1159
1159
  if (!Array.isArray(value)) return [];
1160
- return value.flatMap((item) => text$1(item) ? [text$1(item)] : []);
1160
+ return value.flatMap((item) => text$2(item) ? [text$2(item)] : []);
1161
1161
  }
1162
1162
  function affectedUrls(item, affectedCount) {
1163
1163
  const items = stringArray(item.sampleUrls);
1164
1164
  const details = record(item.affectedUrlsReport);
1165
1165
  const params = record(details?.params);
1166
- const reportId = details?.id === "affected-urls" ? text$1(params?.reportId) : void 0;
1167
- const ruleId = details?.id === "affected-urls" ? text$1(params?.ruleId) : void 0;
1166
+ const reportId = details?.id === "affected-urls" ? text$2(params?.reportId) : void 0;
1167
+ const ruleId = details?.id === "affected-urls" ? text$2(params?.ruleId) : void 0;
1168
1168
  if (!items.length && !reportId) return void 0;
1169
1169
  const total = affectedCount ?? items.length;
1170
1170
  return {
@@ -1184,13 +1184,13 @@ function affectedUrls(item, affectedCount) {
1184
1184
  function reviewGuidance(item, title, action) {
1185
1185
  const supplied = record(item.review);
1186
1186
  const evidence = record(item.evidence);
1187
- const ruleId = text$1(item.ruleId ?? evidence?.ruleId);
1187
+ const ruleId = text$2(item.ruleId ?? evidence?.ruleId);
1188
1188
  const defined = (ruleId ? explainRule(ruleId) : void 0)?.review;
1189
1189
  return {
1190
- question: text$1(supplied?.question) ?? defined?.question ?? `Does the retained evidence and confirmed intent show that "${title}" needs a change?`,
1191
- changeOnlyIf: text$1(supplied?.changeOnlyIf) ?? defined?.changeOnlyIf ?? "Make a change only when the retained evidence and required intent support it.",
1192
- ifConfirmed: text$1(supplied?.ifConfirmed) ?? action,
1193
- ifNotNeeded: text$1(supplied?.ifNotNeeded) ?? defined?.ifNotNeeded ?? "Record no change and cite the evidence or confirmed intent that makes a change unnecessary.",
1190
+ question: text$2(supplied?.question) ?? defined?.question ?? `Does the retained evidence and confirmed intent show that "${title}" needs a change?`,
1191
+ changeOnlyIf: text$2(supplied?.changeOnlyIf) ?? defined?.changeOnlyIf ?? "Make a change only when the retained evidence and required intent support it.",
1192
+ ifConfirmed: text$2(supplied?.ifConfirmed) ?? action,
1193
+ ifNotNeeded: text$2(supplied?.ifNotNeeded) ?? defined?.ifNotNeeded ?? "Record no change and cite the evidence or confirmed intent that makes a change unnecessary.",
1194
1194
  doNot: stringArray(supplied?.doNot).length ? stringArray(supplied?.doNot) : [...defined?.doNot ?? []]
1195
1195
  };
1196
1196
  }
@@ -1209,7 +1209,7 @@ function findingEvidence(item) {
1209
1209
  }
1210
1210
  function normalizeFinding(value, path, index, options) {
1211
1211
  if (typeof value === "string") {
1212
- const action = text$1(value);
1212
+ const action = text$2(value);
1213
1213
  if (!action) return void 0;
1214
1214
  const common = {
1215
1215
  id: `action-${stableId(`${options.reportId ?? ""}|${path}|${action}`)}`,
@@ -1241,8 +1241,8 @@ function normalizeFinding(value, path, index, options) {
1241
1241
  }
1242
1242
  const item = record(value);
1243
1243
  if (!item) return void 0;
1244
- const action = text$1(item.action) ?? text$1(item.howToFix) ?? (item.recommendation === "fix" || item.recommendation === "review" ? void 0 : text$1(item.recommendation)) ?? text$1(item.nextStep);
1245
- const title = text$1(item.title) ?? text$1(item.headline) ?? text$1(item.name) ?? action;
1244
+ 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);
1245
+ const title = text$2(item.title) ?? text$2(item.headline) ?? text$2(item.name) ?? action;
1246
1246
  if (!action || !title) return void 0;
1247
1247
  const confidence = [
1248
1248
  "high",
@@ -1260,7 +1260,7 @@ function normalizeFinding(value, path, index, options) {
1260
1260
  status: "open",
1261
1261
  title,
1262
1262
  ...confidence ? { confidence } : {},
1263
- ...text$1(item.severity) ? { severity: text$1(item.severity) } : {},
1263
+ ...text$2(item.severity) ? { severity: text$2(item.severity) } : {},
1264
1264
  ...typeof affectedCount === "number" && Number.isFinite(affectedCount) ? { affectedCount } : {},
1265
1265
  ...urls ? { affectedUrls: urls } : {},
1266
1266
  sourcePath: `${path}[${index}]`,
@@ -1322,7 +1322,7 @@ function inventory(value, path, reportId) {
1322
1322
  const totalItems = typeof (source.totalPages ?? source.totalItems) === "number" ? Number(source.totalPages ?? source.totalItems) : source.rows.length;
1323
1323
  const items = source.rows.map((value, index) => {
1324
1324
  const row = record(value) ?? { value };
1325
- const identity = text$1(row.id) ?? text$1(row.url) ?? text$1(row.path) ?? `${path}[${index}]`;
1325
+ const identity = text$2(row.id) ?? text$2(row.url) ?? text$2(row.path) ?? `${path}[${index}]`;
1326
1326
  return {
1327
1327
  ...row,
1328
1328
  id: `inventory-item-${stableId(`${reportId ?? ""}|${path}|${identity}`)}`,
@@ -1341,7 +1341,7 @@ function inventory(value, path, reportId) {
1341
1341
  returnedItems: items.length,
1342
1342
  complete: source.capped === false && items.length >= totalItems,
1343
1343
  ...source.criteria !== void 0 ? { criteria: source.criteria } : {},
1344
- ...text$1(source.note) ? { note: text$1(source.note) } : {},
1344
+ ...text$2(source.note) ? { note: text$2(source.note) } : {},
1345
1345
  ...pageCount !== void 0 ? { pagination: {
1346
1346
  page,
1347
1347
  pageCount,
@@ -33859,6 +33859,31 @@ function flattenIntents(row) {
33859
33859
  }
33860
33860
  // packages/core/src/commands/research-serp.ts
33861
33861
  const GOTO = /^https?:\/\/(www\.)?google\.[a-z.]+\/goto\b/;
33862
+ const bare$2 = (host) => host.toLowerCase().replace(/^www\./, "");
33863
+ function pageKey(url) {
33864
+ try {
33865
+ const parsed = new URL(url);
33866
+ return `${bare$2(parsed.hostname)}${parsed.pathname.replace(/\/+$/, "")}`.toLowerCase();
33867
+ } catch {
33868
+ return "";
33869
+ }
33870
+ }
33871
+ function hintKey(hint) {
33872
+ const parts = hint.split("›").map((part) => part.trim());
33873
+ if (!parts[0] || parts.some((part) => /^\.\.\.$|…/.test(part))) return null;
33874
+ return `${bare$2(parts[0])}${parts.length > 1 ? `/${parts.slice(1).join("/")}` : ""}`.toLowerCase();
33875
+ }
33876
+ function overlapKey(row) {
33877
+ if (typeof row.url === "string" && row.url) return {
33878
+ key: pageKey(row.url),
33879
+ breadcrumb: false
33880
+ };
33881
+ const hint = typeof row.url_hint === "string" ? hintKey(row.url_hint) : null;
33882
+ return {
33883
+ key: hint?.includes("/") ? hint : "",
33884
+ breadcrumb: true
33885
+ };
33886
+ }
33862
33887
  const hostOf$3 = (url) => {
33863
33888
  try {
33864
33889
  return new URL(url).hostname;
@@ -33866,13 +33891,13 @@ const hostOf$3 = (url) => {
33866
33891
  return "";
33867
33892
  }
33868
33893
  };
33869
- const text = (value) => typeof value === "string" && value ? value : null;
33894
+ const text$1 = (value) => typeof value === "string" && value ? value : null;
33870
33895
  function dataForSeoSerp(keyword, items) {
33871
33896
  const asked = /* @__PURE__ */ new Map();
33872
33897
  for (const block of items) {
33873
33898
  if (block.type !== "people_also_ask") continue;
33874
33899
  for (const element of block.items ?? []) {
33875
- const question = text(element.title);
33900
+ const question = text$1(element.title);
33876
33901
  if (!question || asked.has(question.toLowerCase())) continue;
33877
33902
  const answer = element.expanded_element?.[0];
33878
33903
  const page = answer?.type === "people_also_ask_expanded_element";
@@ -33882,8 +33907,8 @@ function dataForSeoSerp(keyword, items) {
33882
33907
  question,
33883
33908
  aiAnswer: answer?.type === "people_also_ask_ai_overview_expanded_element",
33884
33909
  url: page && url && !goto ? url : null,
33885
- domain: page ? goto ? null : text(answer?.domain) ?? (hostOf$3(url) || null) : null,
33886
- title: page ? text(answer?.title) : null
33910
+ domain: page ? goto ? null : text$1(answer?.domain) ?? (hostOf$3(url) || null) : null,
33911
+ title: page ? text$1(answer?.title) : null
33887
33912
  });
33888
33913
  }
33889
33914
  }
@@ -33898,9 +33923,9 @@ function dataForSeoSerp(keyword, items) {
33898
33923
  const url = String(ref.url ?? "");
33899
33924
  const goto = GOTO.test(url);
33900
33925
  return {
33901
- domain: goto ? null : text(ref.domain) ?? (hostOf$3(url) || null),
33926
+ domain: goto ? null : text$1(ref.domain) ?? (hostOf$3(url) || null),
33902
33927
  url: goto || !url ? null : url,
33903
- title: text(ref.title)
33928
+ title: text$1(ref.title)
33904
33929
  };
33905
33930
  })
33906
33931
  } : null;
@@ -33911,9 +33936,9 @@ function dataForSeoSerp(keyword, items) {
33911
33936
  position: item.type === "organic" ? Number(item.rank_group) : null,
33912
33937
  rank_absolute: Number(item.rank_absolute),
33913
33938
  type: String(item.type),
33914
- url: text(item.url),
33915
- domain: text(item.domain),
33916
- title: text(item.title)
33939
+ url: text$1(item.url),
33940
+ domain: text$1(item.domain),
33941
+ title: text$1(item.title)
33917
33942
  };
33918
33943
  if (GOTO.test(String(row.url))) {
33919
33944
  const crumb = String(item.breadcrumb ?? "");
@@ -34369,12 +34394,15 @@ async function serpOverlap(provider, headers, input) {
34369
34394
  const host = (value) => String(value ?? "").toLowerCase().replace(/^www\./, "");
34370
34395
  const top = new Map(keywords.map((keyword) => {
34371
34396
  const rows = serps.rows.filter((row) => row.keyword === keyword && row.type !== "featured_snippet").slice(0, OVERLAP_DEPTH);
34372
- const pages = new Set(rows.map((row) => row.url).filter((url) => typeof url === "string" && url !== "").map((url) => url.replace(/\/$/, "").toLowerCase()));
34397
+ const keys = rows.map(overlapKey);
34398
+ const pages = new Set(keys.map((k) => k.key).filter(Boolean));
34399
+ const fromBreadcrumb = new Set(keys.filter((k) => k.key && k.breadcrumb).map((k) => k.key)).size;
34373
34400
  const sites = new Set(rows.map((row) => host(row.domain ?? siteOf(row.url))).filter(Boolean));
34374
34401
  return [keyword, {
34375
34402
  results: rows.length,
34376
34403
  pages,
34377
- sites
34404
+ sites,
34405
+ fromBreadcrumb
34378
34406
  }];
34379
34407
  }));
34380
34408
  const rows = [];
@@ -34401,7 +34429,8 @@ async function serpOverlap(provider, headers, input) {
34401
34429
  compared: {
34402
34430
  results: results.reduce((sum, item) => sum + item.results, 0),
34403
34431
  withPage: results.reduce((sum, item) => sum + item.pages.size, 0),
34404
- withSite: results.reduce((sum, item) => sum + item.sites.size, 0)
34432
+ withSite: results.reduce((sum, item) => sum + item.sites.size, 0),
34433
+ fromBreadcrumb: results.reduce((sum, item) => sum + item.fromBreadcrumb, 0)
34405
34434
  }
34406
34435
  };
34407
34436
  }
@@ -38784,20 +38813,7 @@ async function runBingReport(input, deps) {
38784
38813
  }
38785
38814
  const DEVICES = ["desktop", "mobile"];
38786
38815
  const DEPTH = 10;
38787
- const bare = (host) => host.toLowerCase().replace(/^www\./, "");
38788
- function key(url) {
38789
- try {
38790
- const parsed = new URL(url);
38791
- return `${bare(parsed.hostname)}${parsed.pathname.replace(/\/+$/, "")}`.toLowerCase();
38792
- } catch {
38793
- return "";
38794
- }
38795
- }
38796
- function hintKey(hint) {
38797
- const parts = hint.split("›").map((part) => part.trim());
38798
- if (!parts[0] || parts.some((part) => /^\.\.\.$|…/.test(part))) return null;
38799
- return `${bare(parts[0])}${parts.length > 1 ? `/${parts.slice(1).join("/")}` : ""}`.toLowerCase();
38800
- }
38816
+ const bare$1 = (host) => host.toLowerCase().replace(/^www\./, "");
38801
38817
  function phraseFrom(text, words = 2) {
38802
38818
  const cleaned = (text ?? "").split(/\s+[|\u2013\u2014-]\s+/)[0]?.replace(/["“”]/g, "").trim();
38803
38819
  if (!cleaned || cleaned.split(/\s+/).length < words) return null;
@@ -38813,8 +38829,8 @@ async function runIndexCheck(input, headers) {
38813
38829
  const keys = dataForSeoKeys(headers);
38814
38830
  const country = input.country ?? "us";
38815
38831
  const market = dataForSeoMarket(country, dataForSeoLanguage(country));
38816
- const page = key(target.href);
38817
- const host = bare(target.hostname);
38832
+ const page = pageKey(target.href);
38833
+ const host = bare$1(target.hostname);
38818
38834
  let phrases = (input.phrases ?? []).slice(0, 2);
38819
38835
  let phraseSource = phrases.length ? "given" : null;
38820
38836
  if (!phrases.length) {
@@ -38850,10 +38866,10 @@ async function runIndexCheck(input, headers) {
38850
38866
  row.results = results.length;
38851
38867
  row.top_domains = [...new Set(results.map((r) => String(r.domain ?? "?")))].slice(0, 3).join(", ");
38852
38868
  const onSite = results.filter((r) => {
38853
- const domain = bare(String(r.domain ?? ""));
38869
+ const domain = bare$1(String(r.domain ?? ""));
38854
38870
  return domain === host || domain.endsWith(`.${host}`);
38855
38871
  });
38856
- const match = onSite.find((r) => typeof r.url === "string" && key(r.url) === page || typeof r.url_hint === "string" && hintKey(r.url_hint) === page);
38872
+ const match = onSite.find((r) => typeof r.url === "string" && pageKey(r.url) === page || typeof r.url_hint === "string" && hintKey(r.url_hint) === page);
38857
38873
  if (match) {
38858
38874
  row.result = "page";
38859
38875
  row.position = typeof match.position === "number" ? match.position : null;
@@ -38969,6 +38985,108 @@ async function installedSerpResearch(provider, input, serp) {
38969
38985
  warnings
38970
38986
  };
38971
38987
  }
38988
+ const PER_TERM = 100;
38989
+ const SNIPPET = 200;
38990
+ const bare = (host) => host.toLowerCase().replace(/^www\./, "");
38991
+ const text = (value) => typeof value === "string" && value.trim() ? value.trim() : null;
38992
+ async function runMentions(input, headers) {
38993
+ const target = bare(input.target.replace(/^https?:\/\//i, "").split("/")[0]?.trim() ?? "");
38994
+ if (!target.includes(".")) throw new CommandError("INVALID_INPUT", "mentions needs a domain as target, such as example.com.");
38995
+ const keys = dataForSeoKeys(headers);
38996
+ const terms = [...new Set([target, ...input.brand ?? []].map((term) => term.replace(/"/g, "").trim().toLowerCase()).filter(Boolean))].slice(0, 4);
38997
+ const onTarget = (host) => host === target || host.endsWith(`.${target}`);
38998
+ let cost = 0;
38999
+ const found = /* @__PURE__ */ new Map();
39000
+ const capped = [];
39001
+ for (const term of terms) {
39002
+ const done = await dataForSeoTask(keys, "v3/content_analysis/search/live", {
39003
+ keyword: `"${term}"`,
39004
+ search_mode: "one_per_domain",
39005
+ limit: PER_TERM
39006
+ });
39007
+ cost += done.cost;
39008
+ const items = done.result?.items ?? [];
39009
+ if (Number(done.result?.total_count ?? 0) > items.length) capped.push(term);
39010
+ for (const item of items) {
39011
+ const site = bare(String(item.main_domain ?? item.domain ?? ""));
39012
+ const url = text(item.url);
39013
+ if (!site || !url || onTarget(bare(String(item.domain ?? site)))) continue;
39014
+ if (found.has(site)) continue;
39015
+ const info = item.content_info ?? {};
39016
+ const snippet = text(info.snippet);
39017
+ found.set(site, {
39018
+ site,
39019
+ url,
39020
+ title: text(info.main_title) ?? text(info.title),
39021
+ snippet: snippet ? snippet.length > SNIPPET ? `${snippet.slice(0, SNIPPET)}…` : snippet : null,
39022
+ matched: term,
39023
+ domain_rank: typeof item.domain_rank === "number" ? item.domain_rank : null,
39024
+ fetched: text(item.fetch_time),
39025
+ links: "not_found"
39026
+ });
39027
+ }
39028
+ }
39029
+ const sites = [...found.keys()];
39030
+ let linkCheck = "none";
39031
+ if (sites.length) try {
39032
+ const done = await dataForSeoTask(keys, "v3/backlinks/backlinks/live", {
39033
+ target,
39034
+ mode: "one_per_domain",
39035
+ filters: [
39036
+ "domain_from",
39037
+ "in",
39038
+ sites.flatMap((s) => [s, `www.${s}`])
39039
+ ],
39040
+ limit: 1e3
39041
+ });
39042
+ cost += done.cost;
39043
+ const items = done.result?.items ?? [];
39044
+ for (const item of items) {
39045
+ const from = bare(String(item.domain_from ?? ""));
39046
+ const mention = found.get(from) ?? [...found.values()].find((m) => from.endsWith(`.${m.site}`));
39047
+ if (mention) mention.links = "yes";
39048
+ }
39049
+ linkCheck = "done";
39050
+ } catch (error) {
39051
+ cost += error.cost ?? 0;
39052
+ linkCheck = "failed";
39053
+ }
39054
+ 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));
39055
+ const unlinked = rows.filter((row) => row.links !== "yes").length;
39056
+ const named = rows.filter((row) => row.matched === target);
39057
+ const spent = Math.round(cost * 1e4) / 1e4;
39058
+ const notes = [
39059
+ `Searched DataForSEO's content index for ${terms.map((t) => `"${t}"`).join(", ")}, one page per site, leaving out ${target} and its subdomains. DataForSEO cost: $${spent}.`,
39060
+ 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.`,
39061
+ ...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.`] : [],
39062
+ ...capped.length ? [`More pages mention ${capped.join(", ")} than the ${PER_TERM} sites read per term, so the list is partial.`] : [],
39063
+ ...linkCheck === "failed" ? ["The backlink check failed, so links is not_found for every site: whether they link is unknown."] : [],
39064
+ "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.",
39065
+ "domain_rank is DataForSEO's own authority score, not Ahrefs' Domain Rating."
39066
+ ];
39067
+ return {
39068
+ text: rowsText({
39069
+ title: `Mentions of ${target}.`,
39070
+ rows,
39071
+ offset: input.offset ?? 0,
39072
+ limit: 50,
39073
+ detail: input.detail ?? "summary",
39074
+ notes
39075
+ }),
39076
+ data: {
39077
+ provider: "dataforseo",
39078
+ action: "mentions",
39079
+ target,
39080
+ terms,
39081
+ costUsd: spent,
39082
+ partial: capped.length > 0,
39083
+ linkCheck,
39084
+ total: rows.length,
39085
+ unlinked,
39086
+ rows: rows.slice(input.offset ?? 0, (input.offset ?? 0) + 50)
39087
+ }
39088
+ };
39089
+ }
38972
39090
  // packages/core/src/commands/research-zero-volume.ts
38973
39091
  const ZERO_VOLUME_KEYWORDS = {
38974
39092
  dataforseo: 700,
@@ -39100,10 +39218,11 @@ const RESEARCH_ACTIONS = [
39100
39218
  "pages_by_backlinks",
39101
39219
  "keyword_ideas",
39102
39220
  "serp_overlap",
39103
- "index_check"
39221
+ "index_check",
39222
+ "mentions"
39104
39223
  ];
39105
39224
  const RESEARCH_PROVIDERS = ["dataforseo", "ahrefs"];
39106
- 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.`;
39225
+ 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.`;
39107
39226
  const GENERIC_PLATFORMS = [
39108
39227
  "youtube.com",
39109
39228
  "facebook.com",
@@ -39164,6 +39283,15 @@ async function runResearch(input, keys, options) {
39164
39283
  const target = input.target ?? "";
39165
39284
  const offset = input.offset ?? 0;
39166
39285
  if (input.action === "ai_answers") throw new CommandError("INVALID_INPUT", "ai_answers runs on its own.");
39286
+ if (input.action === "mentions") {
39287
+ if (input.provider && input.provider !== "dataforseo") throw new CommandError("INVALID_INPUT", "mentions uses dataforseo.");
39288
+ return runMentions({
39289
+ target,
39290
+ brand: input.brand,
39291
+ offset,
39292
+ detail: input.detail
39293
+ }, keys);
39294
+ }
39167
39295
  const provider = chooseProvider(input.provider, keys);
39168
39296
  if (input.action === "keyword_metrics" && !input.keywords?.length && target && options.searchAnalytics) return zeroVolume(input, keys, provider, options.searchAnalytics, options);
39169
39297
  const builtIn = RESEARCH_PROVIDERS.includes(provider) ? provider : null;
@@ -39245,7 +39373,7 @@ async function runResearch(input, keys, options) {
39245
39373
  detail,
39246
39374
  notes: [
39247
39375
  `${provider} estimates, in the provider’s own units.`,
39248
- ...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." : ""}`] : [],
39376
+ ...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." : ""}`] : [],
39249
39377
  ...VOLUME_ACTIONS.includes(input.action) && builtIn ? [`Volume model: ${VOLUME_MODEL[builtIn]} ${VOLUMES_DIFFER}`] : [],
39250
39378
  ...input.action === "serp" || input.action === "ranked_keywords" ? [positionNote(provider)] : [],
39251
39379
  ...aiOverviews?.length ? [aiOverviewNote(aiOverviews, request.keywords.length)] : input.action === "serp" && provider === "dataforseo" && rows.length ? ["No AI Overview on these results pages."] : [],
@@ -40714,7 +40842,7 @@ const SHARED_TOOLS = [
40714
40842
  competitors: z.array(z.string().min(1)).max(5).default([]).describe("link_gap only: 2 to 5 competitor domains."),
40715
40843
  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."),
40716
40844
  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."),
40717
- 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."),
40845
+ 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."),
40718
40846
  country: z.string().regex(/^[a-z]{2}$/).default("us").describe("Two-letter country code."),
40719
40847
  depth: z.number().int().min(1).max(100).optional().describe(`serp only: results per keyword, default 20. Deeper costs more.`),
40720
40848
  device: z.enum(RESEARCH_DEVICES).optional().describe("serp only: desktop (default) or mobile. Google ranks pages differently on each. DataForSEO only."),