siluzan-tso-cli 1.1.54-beta.2 → 1.1.54-beta.3

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
@@ -4612,6 +4612,13 @@ function resolveDailyMetricsQueryTimes(startDate, endDate, now = /* @__PURE__ */
4612
4612
  const endInstant = endOfDay.getTime() > now.getTime() ? formatChinaOffsetDateTime(now) : formatChinaOffsetDateTime(endOfDay);
4613
4613
  return { startInstant, endInstant };
4614
4614
  }
4615
+ function clampRowsToCalendarRange(rows, startDate, endDate) {
4616
+ return rows.filter((r) => {
4617
+ if (typeof r.date !== "string" || r.date.length < 10) return true;
4618
+ const day = r.date.slice(0, 10);
4619
+ return day >= startDate && day <= endDate;
4620
+ });
4621
+ }
4615
4622
  function resolveChinaQueryTimes(startDate, endDate, _now = /* @__PURE__ */ new Date()) {
4616
4623
  return { startInstant: startDate, endInstant: endDate };
4617
4624
  }
@@ -102868,7 +102875,7 @@ async function fetchSectionPayload(def, opts, config, id, http2) {
102868
102875
  }
102869
102876
  if (def.name === "daily-metrics") {
102870
102877
  const { startDate, endDate } = resolveDateRange(opts.start, opts.end);
102871
- const { startInstant, endInstant } = resolveChinaQueryTimes(startDate, endDate);
102878
+ const { startInstant, endInstant } = resolveDailyMetricsQueryTimes(startDate, endDate);
102872
102879
  const params = new URLSearchParams({
102873
102880
  mediaCustomerIds: id,
102874
102881
  startDate: startInstant,
@@ -102882,7 +102889,11 @@ async function fetchSectionPayload(def, opts, config, id, http2) {
102882
102889
  `daily-metrics/${id}`,
102883
102890
  http2
102884
102891
  );
102885
- const rows = rowsFromAccountDailyReportsEnvelope(raw, id);
102892
+ const rows = clampRowsToCalendarRange(
102893
+ rowsFromAccountDailyReportsEnvelope(raw, id),
102894
+ startDate,
102895
+ endDate
102896
+ );
102886
102897
  return annotateZhFields(
102887
102898
  normalizeMoneyScales(
102888
102899
  normalizeRateScales(stripLegacyGoogleFieldsIfV2Present(rows), "daily-metrics"),
@@ -103057,7 +103068,7 @@ function narrativeClaimsMobileSpendLeads(text2) {
103057
103068
  if (!t.includes("\u79FB\u52A8")) return false;
103058
103069
  return /移动(?:端|设备)?(?:为|是)主要消耗/.test(t) || /移动(?:端|设备)?为主要(?:消耗)?设备/.test(t) || /移动(?:端|设备)?(?:消耗|花费|费用|流量)?占比高/.test(t);
103059
103070
  }
103060
- function asRecord15(value) {
103071
+ function asRecord16(value) {
103061
103072
  if (value && typeof value === "object" && !Array.isArray(value)) return value;
103062
103073
  return null;
103063
103074
  }
@@ -103065,16 +103076,16 @@ function stringList(value) {
103065
103076
  return (Array.isArray(value) ? value : []).map((item) => typeof item === "string" ? item.trim() : "").filter(Boolean);
103066
103077
  }
103067
103078
  function collectOkkiNarrativeText(data) {
103068
- const narrative = asRecord15(data.narrative) ?? {};
103079
+ const narrative = asRecord16(data.narrative) ?? {};
103069
103080
  const parts = [];
103070
- const sheetAnalysis = asRecord15(narrative.sheetAnalysis) ?? {};
103081
+ const sheetAnalysis = asRecord16(narrative.sheetAnalysis) ?? {};
103071
103082
  for (const block of Object.values(sheetAnalysis)) {
103072
- const rec = asRecord15(block);
103083
+ const rec = asRecord16(block);
103073
103084
  parts.push(...stringList(rec?.summary), ...stringList(rec?.suggestions));
103074
103085
  }
103075
- const review = asRecord15(narrative.review) ?? {};
103086
+ const review = asRecord16(narrative.review) ?? {};
103076
103087
  for (const block of Object.values(review)) {
103077
- const rec = asRecord15(block);
103088
+ const rec = asRecord16(block);
103078
103089
  for (const key of ["overview", "summary", "suggestion"]) {
103079
103090
  const value = rec?.[key];
103080
103091
  if (typeof value === "string" && value.trim()) parts.push(value.trim());
@@ -103091,7 +103102,7 @@ var init_okki_display = __esm({
103091
103102
  // src/commands/google-analysis/merge-snapshot.ts
103092
103103
  import * as fs27 from "fs/promises";
103093
103104
  import * as path32 from "path";
103094
- function asRecord16(value) {
103105
+ function asRecord17(value) {
103095
103106
  if (value && typeof value === "object" && !Array.isArray(value)) {
103096
103107
  return value;
103097
103108
  }
@@ -103187,7 +103198,7 @@ function periodMetricsFromRow(row) {
103187
103198
  }
103188
103199
  function items(envelope) {
103189
103200
  if (!envelope || !Array.isArray(envelope.items)) return [];
103190
- return envelope.items.filter((row) => asRecord16(row) !== null);
103201
+ return envelope.items.filter((row) => asRecord17(row) !== null);
103191
103202
  }
103192
103203
  function record(envelope) {
103193
103204
  return envelope?.record ?? null;
@@ -103234,14 +103245,14 @@ function sumCampaignRowsToPeriodKpis(rows) {
103234
103245
  }
103235
103246
  async function mergeGoogleAnalysisSnapshotIntoReport(payload, snapshotDir) {
103236
103247
  const absDir = path32.resolve(snapshotDir);
103237
- const metaAccountId = typeof asRecord16(payload.meta)?.accountId === "string" ? asRecord16(payload.meta)?.accountId : void 0;
103248
+ const metaAccountId = typeof asRecord17(payload.meta)?.accountId === "string" ? asRecord17(payload.meta)?.accountId : void 0;
103238
103249
  const manifest = await readManifest(snapshotDir, metaAccountId);
103239
103250
  if (!manifest) {
103240
103251
  throw new Error(`\u672A\u5728 ${absDir} \u627E\u5230 manifest*.json\uFF0C\u8BF7\u5148\u6267\u884C google-analysis --json-out`);
103241
103252
  }
103242
103253
  const accountId = manifest.googleAnalysis?.accountId ?? metaAccountId;
103243
103254
  const dateRange = manifest.googleAnalysis?.dateRange;
103244
- const preferredDateTag = dateTagFromRange(dateRange) ?? dateTagFromMeta(asRecord16(payload.meta) ?? void 0);
103255
+ const preferredDateTag = dateTagFromRange(dateRange) ?? dateTagFromMeta(asRecord17(payload.meta) ?? void 0);
103245
103256
  const sectionMap = /* @__PURE__ */ new Map();
103246
103257
  for (const art of manifest.artifacts ?? []) {
103247
103258
  const data = await loadSectionFile(absDir, art.file);
@@ -103249,8 +103260,8 @@ async function mergeGoogleAnalysisSnapshotIntoReport(payload, snapshotDir) {
103249
103260
  }
103250
103261
  await recoverMissingReportSections(sectionMap, absDir, accountId, preferredDateTag);
103251
103262
  const overviewRecord = record(sectionMap.get("overview"));
103252
- const currentPeriod = asRecord16(overviewRecord?.currentPeriod);
103253
- const previousPeriod = asRecord16(overviewRecord?.previousPeriod);
103263
+ const currentPeriod = asRecord17(overviewRecord?.currentPeriod);
103264
+ const previousPeriod = asRecord17(overviewRecord?.previousPeriod);
103254
103265
  const meta = { ...payload.meta ?? {} };
103255
103266
  if (!meta.accountId && accountId) meta.accountId = accountId;
103256
103267
  if (!meta.currency) {
@@ -103396,7 +103407,7 @@ function textLen(value) {
103396
103407
  function asArray(value) {
103397
103408
  return Array.isArray(value) ? value : [];
103398
103409
  }
103399
- function asRecord17(value) {
103410
+ function asRecord18(value) {
103400
103411
  if (value && typeof value === "object" && !Array.isArray(value)) {
103401
103412
  return value;
103402
103413
  }
@@ -103410,7 +103421,7 @@ function pushMissing(missing, id, chapter, dimension, hint) {
103410
103421
  }
103411
103422
  function validateOkkiWeeklyReportContent(data) {
103412
103423
  const missing = [];
103413
- const meta = asRecord17(data.meta) ?? {};
103424
+ const meta = asRecord18(data.meta) ?? {};
103414
103425
  if (!textLen(meta.accountId)) {
103415
103426
  pushMissing(
103416
103427
  missing,
@@ -103420,7 +103431,7 @@ function validateOkkiWeeklyReportContent(data) {
103420
103431
  "meta.accountId \u5FC5\u586B\uFF1B\u53EF\u7531 --snapshot-dir \u5408\u5E76 overview/manifest"
103421
103432
  );
103422
103433
  }
103423
- const snapshotSections = asRecord17(data.snapshot?.sections) ?? {};
103434
+ const snapshotSections = asRecord18(data.snapshot?.sections) ?? {};
103424
103435
  const snapshotPresent = {};
103425
103436
  for (const section of OKKI_SNAPSHOT_SECTIONS) {
103426
103437
  const present = snapshotSections[section] === true;
@@ -103435,12 +103446,12 @@ function validateOkkiWeeklyReportContent(data) {
103435
103446
  );
103436
103447
  }
103437
103448
  }
103438
- const narrative = asRecord17(data.narrative) ?? {};
103439
- const sheetAnalysis = asRecord17(narrative.sheetAnalysis) ?? {};
103440
- const review = asRecord17(narrative.review) ?? {};
103449
+ const narrative = asRecord18(data.narrative) ?? {};
103450
+ const sheetAnalysis = asRecord18(narrative.sheetAnalysis) ?? {};
103451
+ const review = asRecord18(narrative.review) ?? {};
103441
103452
  const sheetAnalysisCounts = {};
103442
103453
  for (const key of OKKI_SHEET_KEYS) {
103443
- const block = asRecord17(sheetAnalysis[key]);
103454
+ const block = asRecord18(sheetAnalysis[key]);
103444
103455
  const summary = stringList2(block?.summary);
103445
103456
  const suggestions = stringList2(block?.suggestions);
103446
103457
  sheetAnalysisCounts[key] = { summary: summary.length, suggestions: suggestions.length };
@@ -103466,7 +103477,7 @@ function validateOkkiWeeklyReportContent(data) {
103466
103477
  }
103467
103478
  const reviewFilled = {};
103468
103479
  for (const key of OKKI_REVIEW_KEYS) {
103469
- const block = asRecord17(review[key]);
103480
+ const block = asRecord18(review[key]);
103470
103481
  const overview = textLen(block?.overview);
103471
103482
  const summary = textLen(block?.summary);
103472
103483
  const suggestion = textLen(block?.suggestion);
@@ -103501,7 +103512,7 @@ function validateOkkiWeeklyReportContent(data) {
103501
103512
  }
103502
103513
  }
103503
103514
  const deviceRows2 = Array.isArray(data.tables?.devices) ? data.tables.devices : [];
103504
- const deviceSpend = summarizeOkkiDeviceSpend(deviceRows2.filter((row) => asRecord17(row) !== null));
103515
+ const deviceSpend = summarizeOkkiDeviceSpend(deviceRows2.filter((row) => asRecord18(row) !== null));
103505
103516
  if (deviceSpend.total > 0 && deviceSpend.desktop >= deviceSpend.mobile && narrativeClaimsMobileSpendLeads(collectOkkiNarrativeText(data))) {
103506
103517
  pushMissing(
103507
103518
  missing,
@@ -103590,7 +103601,7 @@ function round25(value) {
103590
103601
  }
103591
103602
  function items2(envelope) {
103592
103603
  if (!envelope || !Array.isArray(envelope.items)) return [];
103593
- return envelope.items.filter((row) => asRecord17(row) !== null);
103604
+ return envelope.items.filter((row) => asRecord18(row) !== null);
103594
103605
  }
103595
103606
  function dateTagFromRange2(dateRange) {
103596
103607
  if (!dateRange || dateRange.mode !== "range") return void 0;
@@ -103634,14 +103645,14 @@ async function loadSectionFile2(snapshotDir, file) {
103634
103645
  }
103635
103646
  async function mergeOkkiSnapshotIntoReport(payload, snapshotDir) {
103636
103647
  const absDir = path33.resolve(snapshotDir);
103637
- const metaAccountId = typeof asRecord17(payload.meta)?.accountId === "string" ? asRecord17(payload.meta)?.accountId : void 0;
103648
+ const metaAccountId = typeof asRecord18(payload.meta)?.accountId === "string" ? asRecord18(payload.meta)?.accountId : void 0;
103638
103649
  const manifest = await readManifest2(absDir, metaAccountId);
103639
103650
  if (!manifest) {
103640
103651
  throw new Error(`\u672A\u5728 ${absDir} \u627E\u5230 manifest*.json\uFF0C\u8BF7\u5148\u6267\u884C google-analysis --json-out`);
103641
103652
  }
103642
103653
  const accountId = manifest.googleAnalysis?.accountId ?? metaAccountId;
103643
103654
  const dateRange = manifest.googleAnalysis?.dateRange;
103644
- const preferredDateTag = dateTagFromRange2(dateRange) ?? dateTagFromMeta2(asRecord17(payload.meta) ?? void 0);
103655
+ const preferredDateTag = dateTagFromRange2(dateRange) ?? dateTagFromMeta2(asRecord18(payload.meta) ?? void 0);
103645
103656
  const sectionMap = /* @__PURE__ */ new Map();
103646
103657
  for (const art of manifest.artifacts ?? []) {
103647
103658
  const data = await loadSectionFile2(absDir, art.file);
@@ -103667,7 +103678,7 @@ async function mergeOkkiSnapshotIntoReport(payload, snapshotDir) {
103667
103678
  snapshotPresent[section] = sectionMap.has(section);
103668
103679
  }
103669
103680
  const overviewRecord = sectionMap.get("overview")?.record ?? null;
103670
- const currentPeriod = asRecord17(overviewRecord?.currentPeriod);
103681
+ const currentPeriod = asRecord18(overviewRecord?.currentPeriod);
103671
103682
  const meta = { ...payload.meta ?? {} };
103672
103683
  if (!meta.accountId && accountId) meta.accountId = accountId;
103673
103684
  if (!meta.currency) {
@@ -103810,18 +103821,18 @@ function prefixLines(items3, firstPrefix) {
103810
103821
  });
103811
103822
  }
103812
103823
  function analysisLines(data, key) {
103813
- const block = asRecord17(asRecord17(data.narrative)?.sheetAnalysis)?.[key];
103814
- const rec = asRecord17(block);
103824
+ const block = asRecord18(asRecord18(data.narrative)?.sheetAnalysis)?.[key];
103825
+ const rec = asRecord18(block);
103815
103826
  return [
103816
103827
  ...prefixLines(stringList2(rec?.summary), "\u603B\u7ED3\uFF1A"),
103817
103828
  ...prefixLines(stringList2(rec?.suggestions), "\u5EFA\u8BAE\uFF1A")
103818
103829
  ];
103819
103830
  }
103820
103831
  function reviewLines(data) {
103821
- const review = asRecord17(asRecord17(data.narrative)?.review) ?? {};
103832
+ const review = asRecord18(asRecord18(data.narrative)?.review) ?? {};
103822
103833
  const lines = [];
103823
103834
  OKKI_REVIEW_KEYS.forEach((key, idx) => {
103824
- const block = asRecord17(review[key]) ?? {};
103835
+ const block = asRecord18(review[key]) ?? {};
103825
103836
  lines.push(`${idx + 1}\u3001${REVIEW_LABELS2[key]}\uFF1A${str(block.overview, "")}`);
103826
103837
  lines.push(` \u603B\u7ED3\uFF1A${str(block.summary, "")}`);
103827
103838
  lines.push(` \u5EFA\u8BAE\uFF1A${str(block.suggestion, "")}`);
@@ -103953,7 +103964,7 @@ function geoRows(data) {
103953
103964
  });
103954
103965
  }
103955
103966
  function buildOkkiWeeklySheetDrafts(data) {
103956
- const meta = asRecord17(data.meta) ?? {};
103967
+ const meta = asRecord18(data.meta) ?? {};
103957
103968
  const period = formatOkkiZhDateRange(str(meta.startDate, ""), str(meta.endDate, ""));
103958
103969
  const campaigns = campaignRows(data);
103959
103970
  const drafts = {
@@ -104214,7 +104225,7 @@ function textLen2(value) {
104214
104225
  function asArray2(value) {
104215
104226
  return Array.isArray(value) ? value : [];
104216
104227
  }
104217
- function asRecord18(value) {
104228
+ function asRecord19(value) {
104218
104229
  if (value && typeof value === "object" && !Array.isArray(value)) {
104219
104230
  return value;
104220
104231
  }
@@ -104225,9 +104236,9 @@ function pushMissing2(missing, id, chapter, dimension, hint) {
104225
104236
  }
104226
104237
  function validateGooglePeriodReportContent(data) {
104227
104238
  const missing = [];
104228
- const meta = asRecord18(data.meta) ?? {};
104229
- const narrative = asRecord18(data.narrative) ?? {};
104230
- const sections = asRecord18(narrative.sections) ?? {};
104239
+ const meta = asRecord19(data.meta) ?? {};
104240
+ const narrative = asRecord19(data.narrative) ?? {};
104241
+ const sections = asRecord19(narrative.sections) ?? {};
104231
104242
  if (!textLen2(meta.accountId)) {
104232
104243
  pushMissing2(
104233
104244
  missing,
@@ -104247,7 +104258,7 @@ function validateGooglePeriodReportContent(data) {
104247
104258
  "\u22651 \u6BB5\u6267\u884C\u6458\u8981\uFF0C\u6982\u8FF0\u672C\u671F\u6D88\u8017/\u8F6C\u5316/CTR/CPA \u8D70\u52BF"
104248
104259
  );
104249
104260
  }
104250
- const kpis = asRecord18(data.kpis);
104261
+ const kpis = asRecord19(data.kpis);
104251
104262
  const hasCoreKpi = ["cost", "impressions", "clicks"].some(
104252
104263
  (key) => Number.isFinite(Number(kpis?.[key]))
104253
104264
  );
@@ -104263,7 +104274,7 @@ function validateGooglePeriodReportContent(data) {
104263
104274
  const sectionAnalysisCounts = {};
104264
104275
  const sectionSuggestionCounts = {};
104265
104276
  for (const key of SECTION_KEYS) {
104266
- const section = asRecord18(sections[key]);
104277
+ const section = asRecord19(sections[key]);
104267
104278
  const analysis = asArray2(section?.analysis).filter((s) => textLen2(s) > 0);
104268
104279
  const suggestions = asArray2(section?.suggestions).filter((s) => textLen2(s) > 0);
104269
104280
  sectionAnalysisCounts[key] = analysis.length;
@@ -104289,7 +104300,7 @@ function validateGooglePeriodReportContent(data) {
104289
104300
  }
104290
104301
  const recommendations = asArray2(narrative.recommendations).filter((r) => {
104291
104302
  if (typeof r === "string") return textLen2(r) > 0;
104292
- const rec = asRecord18(r);
104303
+ const rec = asRecord19(r);
104293
104304
  return textLen2(rec?.content) > 0;
104294
104305
  });
104295
104306
  if (recommendations.length < 3) {
@@ -104378,7 +104389,7 @@ async function readJsonFile3(filePath) {
104378
104389
  throw new Error(`\u65E0\u6CD5\u89E3\u6790 JSON\uFF1A${filePath}`);
104379
104390
  }
104380
104391
  }
104381
- function asRecord19(value) {
104392
+ function asRecord20(value) {
104382
104393
  if (value && typeof value === "object" && !Array.isArray(value)) {
104383
104394
  return value;
104384
104395
  }
@@ -104393,7 +104404,7 @@ function injectReportData2(html, payload) {
104393
104404
  }
104394
104405
  async function runGoogleAnalysisRender(opts) {
104395
104406
  const dataPath = path35.resolve(opts.dataFile);
104396
- let data = asRecord19(await readJsonFile3(dataPath));
104407
+ let data = asRecord20(await readJsonFile3(dataPath));
104397
104408
  if (opts.snapshotDir?.trim()) {
104398
104409
  data = await mergeGoogleAnalysisSnapshotIntoReport(data, path35.resolve(opts.snapshotDir));
104399
104410
  }
@@ -113044,6 +113055,19 @@ init_cli_json_snapshot();
113044
113055
  init_strip_legacy_google_fields();
113045
113056
  init_cli_table();
113046
113057
 
113058
+ // src/utils/destructive-confirm.ts
113059
+ function ensureIConfirm(opts) {
113060
+ if (opts.iConfirm) return;
113061
+ console.error(
113062
+ `
113063
+ \u274C \u62D2\u7EDD\u6267\u884C\uFF1A${opts.actionLabel} \u4E3A\u7834\u574F\u6027\u64CD\u4F5C\uFF0C\u987B\u5148\u5411\u7528\u6237\u8BF4\u660E\u98CE\u9669\u5E76\u83B7\u5F97\u660E\u786E\u786E\u8BA4\u3002
113064
+ \u7528\u6237\u540C\u610F\u540E\uFF0C\u8BF7\u9644\u52A0 --i-confirm\uFF0C\u5E76\u4F7F\u7528 --commit "\u2026" \u8BF4\u660E\u539F\u56E0\u540E\u518D\u6267\u884C\u3002
113065
+ \u793A\u4F8B\uFF1Asiluzan-tso \u2026 --i-confirm --commit "\u7528\u6237\u786E\u8BA4\u89E3\u7ED1 entityId=\u2026"
113066
+ `
113067
+ );
113068
+ process.exit(1);
113069
+ }
113070
+
113047
113071
  // src/commands/ad/campaign-create-validate.ts
113048
113072
  init_media_customer_id();
113049
113073
 
@@ -114191,23 +114215,28 @@ function pushKeywordAutoFixWarning(warnings, path55, fieldLabel, trimmedRaw, for
114191
114215
  warnings.push(
114192
114216
  `${path55}.${fieldLabel} \u672A\u6307\u5B9A MatchTypeV2\uFF0C\u5DF2\u6309\u8BCD\u9762\u63A8\u65AD\u4E3A ${matchTypeUiToV2(matchType)}`
114193
114217
  );
114194
- return;
114218
+ return false;
114219
+ }
114220
+ if (declaredUi && declaredUi !== "Broad" && beforeUi === "Broad" && unwrapKeywordDisplayTextForEdit(formatted) === trimmedRaw) {
114221
+ return true;
114195
114222
  }
114196
114223
  if (declaredUi && beforeUi !== declaredUi) {
114197
114224
  warnings.push(
114198
114225
  `${path55}.${fieldLabel} MatchTypeV2=${matchTypeUiToV2(declaredUi)} \u4E0E\u8BCD\u9762\u4E0D\u4E00\u81F4\uFF0C\u5DF2\u81EA\u52A8\u4FEE\u590D\u4E3A\uFF1A${formatted}`
114199
114226
  );
114200
- return;
114227
+ return false;
114201
114228
  }
114202
114229
  if (formatted !== trimmedRaw) {
114203
114230
  warnings.push(`${path55}.${fieldLabel} \u5DF2\u81EA\u52A8\u4FEE\u590D\u8BCD\u9762\uFF1A${trimmedRaw} \u2192 ${formatted}`);
114204
114231
  }
114232
+ return false;
114205
114233
  }
114206
114234
  function normalizeKeywordTextList(texts, matchTypeRaw, path55, fieldLabel, errors, warnings, lengthViolations) {
114207
114235
  const declaredUi = matchTypeV2ToUi(matchTypeRaw);
114208
114236
  const normalized = [];
114209
114237
  const seen = /* @__PURE__ */ new Set();
114210
114238
  let resolvedUi = declaredUi;
114239
+ let bareWrapped = 0;
114211
114240
  for (let k = 0; k < texts.length; k++) {
114212
114241
  const raw = texts[k];
114213
114242
  if (typeof raw !== "string" || !raw.trim()) {
@@ -114220,7 +114249,7 @@ function normalizeKeywordTextList(texts, matchTypeRaw, path55, fieldLabel, error
114220
114249
  trimmedRaw,
114221
114250
  matchTypeRaw
114222
114251
  );
114223
- pushKeywordAutoFixWarning(
114252
+ if (pushKeywordAutoFixWarning(
114224
114253
  warnings,
114225
114254
  path55,
114226
114255
  fieldLabel,
@@ -114230,7 +114259,9 @@ function normalizeKeywordTextList(texts, matchTypeRaw, path55, fieldLabel, error
114230
114259
  beforeUi,
114231
114260
  matchType,
114232
114261
  inferredMatchType
114233
- );
114262
+ )) {
114263
+ bareWrapped++;
114264
+ }
114234
114265
  const core = unwrapKeywordDisplayTextForEdit(formatted);
114235
114266
  if (!validateKeywordCore(core, `${path55}.${fieldLabel}[${k}]`, errors, lengthViolations))
114236
114267
  continue;
@@ -114243,6 +114274,11 @@ function normalizeKeywordTextList(texts, matchTypeRaw, path55, fieldLabel, error
114243
114274
  normalized.push(formatted);
114244
114275
  if (!resolvedUi) resolvedUi = matchType;
114245
114276
  }
114277
+ if (bareWrapped > 0 && declaredUi) {
114278
+ warnings.push(
114279
+ `${path55}.${fieldLabel}\uFF1A${bareWrapped} \u4E2A\u88F8\u8BCD\u5DF2\u6309 MatchTypeV2=${matchTypeUiToV2(declaredUi)} \u81EA\u52A8\u4FEE\u590D\uFF08\u8865\u5168${declaredUi === "Exact" ? " [ ]" : "\u5F15\u53F7"}\uFF0C\u9884\u671F\u884C\u4E3A\uFF09`
114280
+ );
114281
+ }
114246
114282
  return { normalized, resolvedUi };
114247
114283
  }
114248
114284
  function normalizeKeywordsForBatchJobBlock(block, path55, errors, warnings, lengthViolations) {
@@ -114296,7 +114332,7 @@ function normalizeKeywordsForBatchJobBlock(block, path55, errors, warnings, leng
114296
114332
  trimmedRaw,
114297
114333
  matchTypeRaw
114298
114334
  );
114299
- pushKeywordAutoFixWarning(
114335
+ if (pushKeywordAutoFixWarning(
114300
114336
  warnings,
114301
114337
  path55,
114302
114338
  `Items[${k}].Text`,
@@ -114306,7 +114342,9 @@ function normalizeKeywordsForBatchJobBlock(block, path55, errors, warnings, leng
114306
114342
  beforeUi,
114307
114343
  matchType,
114308
114344
  inferredMatchType
114309
- );
114345
+ )) {
114346
+ warnings.push(`${path55}.Items[${k}].Text \u5DF2\u6309\u5757\u7EA7\u5339\u914D\u7C7B\u578B\u81EA\u52A8\u4FEE\u590D\u4E3A\uFF1A${formatted}`);
114347
+ }
114310
114348
  const core = unwrapKeywordDisplayTextForEdit(formatted);
114311
114349
  if (!validateKeywordCore(core, `${path55}.Items[${k}].Text`, errors, lengthViolations))
114312
114350
  continue;
@@ -114375,6 +114413,7 @@ function normalizeCampaignKeywordTrees(campaign, errors, warnings, lengthViolati
114375
114413
  }
114376
114414
  }
114377
114415
  warnIfNegativeKeywordsInPositiveKeywords(campaign, warnings);
114416
+ warnIfNegativeKeywordsBlockPositive(campaign, warnings);
114378
114417
  }
114379
114418
  var COMMON_NEGATIVE_KEYWORD_STEMS = /* @__PURE__ */ new Set([
114380
114419
  "free",
@@ -114473,6 +114512,142 @@ function warnIfNegativeKeywordsInPositiveKeywords(campaign, warnings) {
114473
114512
  }
114474
114513
  }
114475
114514
  }
114515
+ function keywordTokens(core) {
114516
+ return core.toLowerCase().split(/\s+/).map((t) => t.trim()).filter(Boolean);
114517
+ }
114518
+ function negativeBlocksKeyword(negativeCore, negativeMatch, positiveCore) {
114519
+ const neg = keywordTokens(negativeCore);
114520
+ const pos = keywordTokens(positiveCore);
114521
+ if (neg.length === 0 || pos.length === 0) return false;
114522
+ if (negativeMatch === "EXACT") return neg.join(" ") === pos.join(" ");
114523
+ if (negativeMatch === "PHRASE") {
114524
+ for (let i = 0; i + neg.length <= pos.length; i++) {
114525
+ if (neg.every((t, j) => pos[i + j] === t)) return true;
114526
+ }
114527
+ return false;
114528
+ }
114529
+ const posSet = new Set(pos);
114530
+ return neg.every((t) => posSet.has(t));
114531
+ }
114532
+ function warnIfNegativeKeywordsBlockPositive(campaign, warnings) {
114533
+ const negBlocks = campaign["NegativeKeywordsForBatchJob"];
114534
+ const groups = campaign["AdGroupsForBatchJob"];
114535
+ if (!Array.isArray(negBlocks) || !Array.isArray(groups)) return;
114536
+ const positives = [];
114537
+ for (const g of groups) {
114538
+ const gr = g;
114539
+ const groupName = String(gr?.["Name"] ?? "");
114540
+ const kws = gr?.["KeywordsForBatchJob"];
114541
+ if (!Array.isArray(kws)) continue;
114542
+ for (const b of kws) {
114543
+ const texts = b?.["KeywordText"];
114544
+ if (!Array.isArray(texts)) continue;
114545
+ for (const t of texts) {
114546
+ if (typeof t === "string" && t.trim()) {
114547
+ positives.push({ core: normalizeKeywordCoreForNegativeCheck(t), group: groupName });
114548
+ }
114549
+ }
114550
+ }
114551
+ }
114552
+ if (positives.length === 0) return;
114553
+ for (let bi = 0; bi < negBlocks.length; bi++) {
114554
+ const block = negBlocks[bi];
114555
+ const texts = block?.["KeywordText"];
114556
+ if (!Array.isArray(texts)) continue;
114557
+ const matchUi = matchTypeV2ToUi(block["MatchTypeV2"] ?? block["matchTypeV2"]);
114558
+ for (let ki = 0; ki < texts.length; ki++) {
114559
+ const raw = texts[ki];
114560
+ if (typeof raw !== "string" || !raw.trim()) continue;
114561
+ const match = matchTypeUiToV2(matchUi ?? inferMatchTypeFromDisplayText(raw.trim()));
114562
+ const negCore = normalizeKeywordCoreForNegativeCheck(raw);
114563
+ const hits = positives.filter((p) => negativeBlocksKeyword(negCore, match, p.core));
114564
+ if (hits.length === 0) continue;
114565
+ const sample = hits.slice(0, 5).map((h) => `\u300C${h.core}\u300D(${h.group})`).join("\u3001");
114566
+ warnings.push(
114567
+ `campaign.NegativeKeywordsForBatchJob[${bi}].KeywordText[${ki}] \u5426\u8BCD\u300C${negCore}\u300D(${match}) \u4F1A\u5C4F\u853D ${hits.length} \u4E2A\u6B63\u5411\u5173\u952E\u8BCD\uFF1A${sample}${hits.length > 5 ? " \u2026" : ""}\uFF1B\u65B9\u6848\u81EA\u76F8\u77DB\u76FE\uFF0C\u987B\u95EE\u7528\u6237\u5220\u5426\u8BCD\u8FD8\u662F\u5220\u5173\u952E\u8BCD`
114568
+ );
114569
+ }
114570
+ }
114571
+ }
114572
+
114573
+ // src/commands/ad/campaign-policy-risk.ts
114574
+ var POLICY_RISK_RULES = [
114575
+ { re: /\bguarantee(d|s)?\b/i, label: "\u4FDD\u8BC1\u7ED3\u679C\uFF08Misrepresentation\uFF09" },
114576
+ { re: /\b(cure|cures|cured|heal|heals)\b/i, label: "\u533B\u7597\u529F\u6548\u58F0\u660E\uFF08Healthcare\uFF09" },
114577
+ { re: /\b(replica|counterfeit|fake|knockoff|knock-off)\b/i, label: "\u4EFF\u5192\u54C1\uFF08Counterfeit goods\uFF09" },
114578
+ { re: /\b(casino|betting|gambling|poker)\b/i, label: "\u8D4C\u535A\uFF08\u987B Google \u8BA4\u8BC1\uFF09" },
114579
+ { re: /\b(cbd|thc|cannabis|marijuana|kratom)\b/i, label: "\u53D7\u7BA1\u5236\u836F\u7269/\u5927\u9EBB" },
114580
+ { re: /\b(viagra|steroids?|anabolic|prescription drugs?)\b/i, label: "\u5904\u65B9\u836F/\u7C7B\u56FA\u9187" },
114581
+ { re: /\b(firearms?|ammo|ammunition|rifles?|pistols?|handguns?)\b/i, label: "\u6B66\u5668\uFF08Dangerous products\uFF09" },
114582
+ { re: /\b(crypto|bitcoin|nft|ico)\b/i, label: "\u52A0\u5BC6\u8D27\u5E01\uFF08\u987B Google \u8BA4\u8BC1\uFF09" },
114583
+ { re: /\b(loan|loans|payday|forex)\b/i, label: "\u91D1\u878D\u670D\u52A1\uFF08\u90E8\u5206\u5730\u533A\u987B\u8BA4\u8BC1\uFF09" },
114584
+ { re: /\b(escort|hookup|porn|xxx|sexy)\b/i, label: "\u6210\u4EBA\u5185\u5BB9" },
114585
+ { re: /\b(e-?cig(arette)?s?|vape|vaping|tobacco|cigars?)\b/i, label: "\u70DF\u8349/\u7535\u5B50\u70DF" },
114586
+ { re: /\b(alcohol|whisk(e)?y|vodka|liquor)\b/i, label: "\u9152\u7CBE\uFF08\u5730\u57DF\u9650\u5236\uFF09" },
114587
+ { re: /(最好|第一|国家级|绝对|100%)/, label: "\u5E7F\u544A\u6CD5\u7EDD\u5BF9\u5316\u7528\u8BED" }
114588
+ ];
114589
+ function matchRisk(text2) {
114590
+ for (const r of POLICY_RISK_RULES) {
114591
+ if (r.re.test(text2)) return r.label;
114592
+ }
114593
+ return void 0;
114594
+ }
114595
+ function collectRsaTexts(ad) {
114596
+ const keys = ["headlinePart1", "headlinePart2", "headlinePart3", "adDescription", "adDescription2"];
114597
+ const out = [];
114598
+ for (const k of keys) {
114599
+ const v = ad[k];
114600
+ if (typeof v === "string" && v.trim()) out.push(v);
114601
+ }
114602
+ for (const k of ["AddtionalHeadlines", "AddtionalAdDescriptions"]) {
114603
+ const arr = ad[k];
114604
+ if (Array.isArray(arr)) {
114605
+ for (const v of arr) if (typeof v === "string" && v.trim()) out.push(v);
114606
+ }
114607
+ }
114608
+ return out;
114609
+ }
114610
+ function warnPolicyRiskTerms(campaign, warnings) {
114611
+ const groups = campaign["AdGroupsForBatchJob"];
114612
+ if (!Array.isArray(groups)) return;
114613
+ const hitsByLabel = /* @__PURE__ */ new Map();
114614
+ const add = (label, text2) => {
114615
+ let set = hitsByLabel.get(label);
114616
+ if (!set) hitsByLabel.set(label, set = /* @__PURE__ */ new Set());
114617
+ set.add(text2.trim());
114618
+ };
114619
+ for (const g of groups) {
114620
+ const gr = g;
114621
+ const kws = gr?.["KeywordsForBatchJob"];
114622
+ if (Array.isArray(kws)) {
114623
+ for (const b of kws) {
114624
+ const texts = b?.["KeywordText"];
114625
+ if (!Array.isArray(texts)) continue;
114626
+ for (const t of texts) {
114627
+ if (typeof t !== "string") continue;
114628
+ const label = matchRisk(t);
114629
+ if (label) add(label, t);
114630
+ }
114631
+ }
114632
+ }
114633
+ const ads = gr?.["AdsForBatchJob"];
114634
+ if (Array.isArray(ads)) {
114635
+ for (const ad of ads) {
114636
+ if (!ad || typeof ad !== "object") continue;
114637
+ for (const t of collectRsaTexts(ad)) {
114638
+ const label = matchRisk(t);
114639
+ if (label) add(label, t);
114640
+ }
114641
+ }
114642
+ }
114643
+ }
114644
+ for (const [label, set] of hitsByLabel) {
114645
+ const sample = [...set].slice(0, 5).map((s) => `\u300C${s}\u300D`).join("\u3001");
114646
+ warnings.push(
114647
+ `\u653F\u7B56\u98CE\u9669\u8BCD\u9762\uFF08${label}\uFF09\uFF1A${sample}${set.size > 5 ? ` \u7B49 ${set.size} \u6761` : ""}\uFF1B\u7F51\u5173\u65E0\u653F\u7B56\u9884\u68C0\uFF0C\u521B\u5EFA\u540E\u53EF\u80FD\u88AB PolicyViolation \u62D2\u7EDD\u2014\u2014\u521B\u5EFA\u524D\u5411\u7528\u6237\u8BF4\u660E\u98CE\u9669\uFF0C\u5FC5\u8981\u65F6\u6539\u5199\u6216\u5220\u9664`
114648
+ );
114649
+ }
114650
+ }
114476
114651
 
114477
114652
  // src/commands/ad/campaign-rsa.ts
114478
114653
  function normalizeRsaAssetKey(text2) {
@@ -114608,6 +114783,27 @@ function validateLocationsFidelity(cfg, campaign, errors) {
114608
114783
  );
114609
114784
  }
114610
114785
  }
114786
+ const excludedLocations = campaign["excludedLocations"];
114787
+ if (Array.isArray(excludedLocations) && excludedLocations.length > 0) {
114788
+ const targetedIdx = /* @__PURE__ */ new Map();
114789
+ targetedLocations.forEach((loc, i) => {
114790
+ const id = loc && typeof loc === "object" ? readLocationId(loc) : void 0;
114791
+ if (id !== void 0 && id !== null) targetedIdx.set(String(id).trim(), i);
114792
+ });
114793
+ const names = Array.isArray(cfg.locations) ? cfg.locations : [];
114794
+ for (let i = 0; i < excludedLocations.length; i++) {
114795
+ const loc = excludedLocations[i];
114796
+ const id = loc && typeof loc === "object" ? readLocationId(loc) : void 0;
114797
+ if (id === void 0 || id === null) continue;
114798
+ const ti = targetedIdx.get(String(id).trim());
114799
+ if (ti === void 0) continue;
114800
+ const label = typeof names[ti] === "string" ? `\u300C${names[ti]}\u300D` : "";
114801
+ pushErr2(
114802
+ errors,
114803
+ `campaign.excludedLocations[${i}].id=${String(id)} \u540C\u65F6\u51FA\u73B0\u5728 targetedLocations[${ti}]${label}\uFF1B\u540C\u4E00\u5730\u57DF\u65E2\u6295\u653E\u53C8\u6392\u9664\u4F1A\u4F7F BatchJob \u62A5 campaign_criterion \u2026negative immutable\u3002\u591A\u4E3A geo resolve \u628A\u6B67\u4E49\u5730\u540D\uFF08\u5982\u300C\u521A\u679C\u300Dvs\u300C\u521A\u679C\u6C11\u4E3B\u5171\u548C\u56FD\u300D\uFF09\u89E3\u6790\u6210\u540C\u4E00 ID\uFF1A\u7528 ad geo search \u6838\u5BF9\u540E\u4FEE\u6B63\u8BE5\u6761\uFF0C\u52FF\u6574\u6279\u5220\u9664\u6392\u9664\u5730\u57DF`
114804
+ );
114805
+ }
114806
+ }
114611
114807
  const locations = cfg.locations;
114612
114808
  if (Array.isArray(locations) && locations.length > 0) {
114613
114809
  if (locations.length !== targetedLocations.length) {
@@ -114787,6 +114983,56 @@ function validateRsaAd(prefix, ad, errors, warnings, lengthViolations) {
114787
114983
  }
114788
114984
  validateRsaHeadlinesWithinAd(prefix, ad, errors);
114789
114985
  }
114986
+ var DEVICE_PLATFORM_IDS = {
114987
+ "30000": "Desktop",
114988
+ "30001": "Mobile",
114989
+ "30002": "Tablet",
114990
+ "30004": "ConnectedTv"
114991
+ };
114992
+ function validateTargetedPlatforms(campaign, errors, warnings) {
114993
+ const platforms = campaign["targetedPlatforms"];
114994
+ if (platforms === void 0 || platforms === null) return;
114995
+ if (!Array.isArray(platforms)) {
114996
+ pushErr2(errors, "campaign.targetedPlatforms \u5FC5\u987B\u662F\u6570\u7EC4");
114997
+ return;
114998
+ }
114999
+ const seen = /* @__PURE__ */ new Set();
115000
+ for (let i = 0; i < platforms.length; i++) {
115001
+ const p = platforms[i];
115002
+ const prefix = `campaign.targetedPlatforms[${i}]`;
115003
+ const id = String(p?.["id"] ?? p?.["Id"] ?? "");
115004
+ if (!DEVICE_PLATFORM_IDS[id]) {
115005
+ pushErr2(
115006
+ errors,
115007
+ `${prefix}.id \u65E0\u6548\uFF08${id || "\u7A7A"}\uFF09\uFF0C\u5408\u6CD5\u503C\uFF1A30000 Desktop / 30001 Mobile / 30002 Tablet / 30004 ConnectedTv`
115008
+ );
115009
+ continue;
115010
+ }
115011
+ if (seen.has(id)) pushErr2(errors, `${prefix}.id=${id} \u91CD\u590D`);
115012
+ seen.add(id);
115013
+ const bm = p["bidModifier"] ?? p["BidModifier"];
115014
+ if (bm === void 0 || bm === null) continue;
115015
+ if (typeof bm !== "number" || !Number.isFinite(bm)) {
115016
+ pushErr2(errors, `${prefix}.bidModifier \u5FC5\u987B\u662F\u6570\u5B57\uFF08\u767E\u5206\u6BD4\uFF1A0 \u4E0D\u8C03\u6574\uFF0C-100 \u6392\u9664\uFF0C20 = +20%\uFF09`);
115017
+ } else if (bm < -100 || bm > 900) {
115018
+ pushErr2(errors, `${prefix}.bidModifier=${bm} \u8D85\u51FA\u8303\u56F4 [-100, 900]\uFF08\u767E\u5206\u6BD4\u53E3\u5F84\uFF09`);
115019
+ } else if (bm !== 0 && Math.abs(bm) < 2 && !Number.isInteger(bm)) {
115020
+ pushWarn2(
115021
+ warnings,
115022
+ `${prefix}.bidModifier=${bm} \u7591\u4F3C\u500D\u7387\u53E3\u5F84\uFF1Bcampaign-create \u7528\u767E\u5206\u6BD4\uFF08-20 = \u964D 20%\uFF0C-100 = \u6392\u9664\uFF09\uFF0C\u4E0E ad device-bid set \u7684\u500D\u7387\u4E0D\u540C`
115023
+ );
115024
+ }
115025
+ }
115026
+ if (platforms.length > 0) {
115027
+ const missing = ["30000", "30001", "30002"].filter((id) => !seen.has(id));
115028
+ if (missing.length > 0) {
115029
+ pushWarn2(
115030
+ warnings,
115031
+ `campaign.targetedPlatforms \u672A\u5217\u51FA ${missing.map((id) => `${id} ${DEVICE_PLATFORM_IDS[id]}`).join("\u3001")}\uFF1A\u7701\u7565\u4E0D\u7B49\u4E8E\u6392\u9664\uFF0CGoogle \u4ECD\u4F1A\u6295\u653E\uFF1B\u8981\u6392\u9664\u8BF7\u5199 { "id": ${missing[0]}, "bidModifier": -100 }`
115032
+ );
115033
+ }
115034
+ }
115035
+ }
114790
115036
  function validateCampaignCreateConfigCore(cfg) {
114791
115037
  const errors = [];
114792
115038
  const warnings = [];
@@ -114900,6 +115146,11 @@ function validateCampaignCreateConfigCore(cfg) {
114900
115146
  errors,
114901
115147
  "TARGET_SPEND \u51FA\u4EF7\u7B56\u7565\u4E0B campaign.TargetSpend_BidCeilingAmount\uFF08CPC \u4E0A\u9650\uFF0C\u5143\uFF09\u5FC5\u987B\u4E3A\u6B63\u6570"
114902
115148
  );
115149
+ } else if (typeof budget === "number" && budget > 0 && ceiling >= budget) {
115150
+ pushWarn2(
115151
+ warnings,
115152
+ `campaign.TargetSpend_BidCeilingAmount\uFF08${ceiling} \u5143\uFF09\u2265 \u65E5\u9884\u7B97\uFF08${budget} \u5143\uFF09\uFF0C\u7B49\u4E8E\u4E0D\u8BBE CPC \u4E0A\u9650\uFF1B\u5E38\u89C1\u4E8E\u65B9\u6848\u628A\u300C\u7CFB\u5217\u51FA\u4EF7\u300D\u8BEF\u586B\u6210\u9884\u7B97\uFF0C\u521B\u5EFA\u524D\u987B\u5411\u7528\u6237\u786E\u8BA4`
115153
+ );
114903
115154
  }
114904
115155
  }
114905
115156
  if (biddingStr === "TARGET_CPA") {
@@ -114918,6 +115169,7 @@ function validateCampaignCreateConfigCore(cfg) {
114918
115169
  }
114919
115170
  }
114920
115171
  validateLocationsFidelity(cfg, campaign, errors);
115172
+ validateTargetedPlatforms(campaign, errors, warnings);
114921
115173
  const targetedLanguages = campaign["targetedLanguages"];
114922
115174
  if (!Array.isArray(targetedLanguages) || targetedLanguages.length === 0) {
114923
115175
  pushErr2(errors, "campaign.targetedLanguages \u4E0D\u80FD\u4E3A\u7A7A\uFF08\u82F1\u8BED id=1000\uFF0C\u4E2D\u6587 id=1017\uFF09");
@@ -115023,13 +115275,16 @@ function validateCampaignCreateConfigCore(cfg) {
115023
115275
  pushErr2(errors, `${gPrefix}.TypeV2 \u4E0D\u80FD\u4E3A "${gTypeV2}"\uFF08\u4F1A\u5BFC\u81F4 Google \u62D2\u7EDD\u5E7F\u544A\u7EC4\uFF09`);
115024
115276
  }
115025
115277
  const mc = g["MaxCPCAmount"];
115026
- if (mc !== void 0 && (typeof mc !== "number" || !Number.isFinite(mc) || mc < 0)) {
115027
- pushErr2(errors, `${gPrefix}.MaxCPCAmount \u5FC5\u987B\u4E3A\u975E\u8D1F\u6570\u5B57\uFF08\u5355\u4F4D\u300C\u5143\u300D\uFF09`);
115028
- }
115029
- if (biddingStr === "MANUAL_CPC") {
115030
- if (typeof mc !== "number" || mc <= 0) {
115031
- pushErr2(errors, `MANUAL_CPC \u4E0B ${gPrefix}.MaxCPCAmount \u5FC5\u987B\u4E3A\u6B63\u6570`);
115032
- }
115278
+ if (typeof mc !== "number" || !Number.isFinite(mc) || Math.round(mc * 100) <= 0) {
115279
+ pushErr2(
115280
+ errors,
115281
+ `${gPrefix}.MaxCPCAmount \u5FC5\u987B\u4E3A\u6B63\u6570\uFF08\u5355\u4F4D\u300C\u5143\u300D\uFF0C\u5F53\u524D ${JSON.stringify(mc ?? null)}\uFF09\uFF1B\u4EFB\u4F55\u51FA\u4EF7\u7B56\u7565\uFF08\u542B ${biddingStr || "TARGET_SPEND"}\uFF09\u4E0B\u7F3A\u7701\u6216 0 \u90FD\u4F1A\u88AB Google \u62D2\uFF08cpc_bid_micros Too low\uFF09\uFF0C\u5E7F\u544A\u7EC4\u5EFA\u4E0D\u51FA\u6765\u3001\u5176\u4E0B\u5173\u952E\u8BCD/\u5E7F\u544A\u5168\u90E8 Resource not found\u3002\u6309\u65B9\u6848\u586B\u9ED8\u8BA4 CPC\uFF0C\u65B9\u6848\u65E0\u503C\u5219\u5148\u95EE\u7528\u6237`
115282
+ );
115283
+ } else if (typeof budget === "number" && budget > 0 && mc >= budget) {
115284
+ pushWarn2(
115285
+ warnings,
115286
+ `${gPrefix}.MaxCPCAmount\uFF08${mc} \u5143\uFF09\u2265 \u65E5\u9884\u7B97\uFF08${budget} \u5143\uFF09\uFF0C\u4E00\u6B21\u70B9\u51FB\u53EF\u80FD\u82B1\u5149\u5F53\u5929\u9884\u7B97\uFF1B\u521B\u5EFA\u524D\u987B\u5411\u7528\u6237\u786E\u8BA4`
115287
+ );
115033
115288
  }
115034
115289
  const ads = g["AdsForBatchJob"];
115035
115290
  if (Array.isArray(ads)) {
@@ -115074,6 +115329,7 @@ function validateCampaignCreateConfigCore(cfg) {
115074
115329
  }
115075
115330
  }
115076
115331
  validateCampaignRsaCrossGroupHeadlines(campaign, errors);
115332
+ warnPolicyRiskTerms(campaign, warnings);
115077
115333
  }
115078
115334
  validateCampaignExtensionsForBatchJob(campaign, errors, warnings, lengthViolations);
115079
115335
  return { errors, warnings, lengthViolations };
@@ -115321,6 +115577,16 @@ async function runAdCampaignDelete(opts) {
115321
115577
  );
115322
115578
  process.exit(1);
115323
115579
  }
115580
+ if (!opts.iConfirm) {
115581
+ const name2 = campaign["name"] ?? campaign["Name"] ?? "\u2014";
115582
+ const status = campaign["statusV2"] ?? campaign["status"] ?? "\u2014";
115583
+ console.error(`
115584
+ \u5F85\u5220\u9664\u7CFB\u5217\uFF1A${opts.id}\u300C${String(name2)}\u300D\uFF08\u72B6\u6001 ${String(status)}\uFF09`);
115585
+ }
115586
+ ensureIConfirm({
115587
+ iConfirm: opts.iConfirm,
115588
+ actionLabel: `ad campaign-delete\uFF08\u5220\u9664\u5E7F\u544A\u7CFB\u5217 ${opts.id}\uFF0C\u4E0D\u53EF\u6062\u590D\uFF09`
115589
+ });
115324
115590
  try {
115325
115591
  await apiDeleteRaw(detailUrl, config, {
115326
115592
  body: JSON.stringify(campaign),
@@ -117016,6 +117282,7 @@ init_auth();
117016
117282
  init_cli_json_snapshot();
117017
117283
  init_bid_modifier_display();
117018
117284
  init_bid_modifier_display();
117285
+ var CAMPAIGN_ZERO_AMBIGUOUS_DISPLAY = "\u2014 \u6216 -100%\uFF08\u7F51\u5173\u4E0D\u533A\u5206\uFF0C\u9700\u5728 Google Ads \u540E\u53F0\u786E\u8BA4\uFF09";
117019
117286
  function multiplierToAdGroupBidPercent(multiplier) {
117020
117287
  return Math.round((multiplier - 1) * 100 * 100) / 100;
117021
117288
  }
@@ -117107,16 +117374,20 @@ async function runAdDeviceBidList(opts) {
117107
117374
  if (opts.campaignId) {
117108
117375
  rows = rows.filter((r) => String(r.campaignId ?? "") === opts.campaignId);
117109
117376
  }
117110
- items3 = rows.map((row) => ({
117111
- level: "campaign",
117112
- id: row.id,
117113
- campaignId: row.campaignId,
117114
- campaignName: row.campaignName,
117115
- deviceType: row.deviceType,
117116
- bidModifier: row.bidModifier,
117117
- bidModifierDisplay: row.bidModifier != null ? formatBidModifierPercent(row.bidModifier, row.bidModifierSpecified) : GOOGLE_ADS_UNSET_BID_DISPLAY,
117118
- bidModifierSpecified: row.bidModifierSpecified
117119
- }));
117377
+ items3 = rows.map((row) => {
117378
+ const ambiguousZero = row.bidModifier === 0 && row.bidModifierSpecified == null;
117379
+ return {
117380
+ level: "campaign",
117381
+ id: row.id,
117382
+ campaignId: row.campaignId,
117383
+ campaignName: row.campaignName,
117384
+ deviceType: row.deviceType,
117385
+ bidModifier: row.bidModifier,
117386
+ bidModifierDisplay: ambiguousZero ? CAMPAIGN_ZERO_AMBIGUOUS_DISPLAY : row.bidModifier != null ? formatBidModifierPercent(row.bidModifier, row.bidModifierSpecified) : GOOGLE_ADS_UNSET_BID_DISPLAY,
117387
+ bidModifierSpecified: row.bidModifierSpecified,
117388
+ ...ambiguousZero ? { unsetOrExcluded: true } : {}
117389
+ };
117390
+ });
117120
117391
  levelLabel = opts.campaignId ? `\u7CFB\u5217 ${opts.campaignId}` : "\u8D26\u6237\u4E0B\u5168\u90E8\u7CFB\u5217";
117121
117392
  }
117122
117393
  const n = items3.length;
@@ -117270,18 +117541,89 @@ function geoItemDisplayName(item) {
117270
117541
  function geoItemType(item) {
117271
117542
  return String(item["targetType"] ?? item["typeV2"] ?? "");
117272
117543
  }
117273
- function pickGeoResolveCandidate(query, items3) {
117274
- if (items3.length === 0) return null;
117275
- const q = query.trim().toLowerCase();
117276
- const isCountry = (it) => /country/i.test(geoItemType(it)) || geoItemType(it).toUpperCase() === "COUNTRY";
117277
- const nameEq = (it) => geoItemDisplayName(it).trim().toLowerCase() === q;
117278
- const exactCountry = items3.find((it) => isCountry(it) && nameEq(it));
117279
- if (exactCountry) return exactCountry;
117280
- const anyCountry = items3.find((it) => isCountry(it));
117281
- if (anyCountry) return anyCountry;
117282
- const exactAny = items3.find((it) => nameEq(it));
117283
- if (exactAny) return exactAny;
117284
- return items3[0] ?? null;
117544
+ function splitGeoName(display) {
117545
+ const m = /^(.*\S)\s*\(([^()]+)\)\s*$/.exec(display.trim());
117546
+ if (!m) return { base: display.trim(), level: "" };
117547
+ const level = m[2].trim();
117548
+ if (!/^(Country|Region|Territory|State|Province|City|Municipality|County|District|Postal Code|Neighborhood|Sub District|Department|Prefecture|Governorate|Autonomous Community|Union Territory|Canton|Okrug|Borough|Airport|University|TV Region|Congressional District|National Park)$/i.test(level)) {
117549
+ return { base: display.trim(), level: "" };
117550
+ }
117551
+ return { base: m[1].trim(), level };
117552
+ }
117553
+ var GEO_NAME_ALIASES = {
117554
+ turkey: "turkiye",
117555
+ "czech republic": "czechia",
117556
+ burma: "myanmar (burma)",
117557
+ myanmar: "myanmar (burma)",
117558
+ "ivory coast": "cote d'ivoire",
117559
+ "c\xF4te d'ivoire": "cote d'ivoire",
117560
+ macau: "macao",
117561
+ swaziland: "eswatini",
117562
+ "east timor": "timor-leste",
117563
+ bahamas: "the bahamas",
117564
+ gambia: "the gambia",
117565
+ "republic of congo": "republic of the congo",
117566
+ "congo-brazzaville": "republic of the congo",
117567
+ "dr congo": "democratic republic of the congo",
117568
+ drc: "democratic republic of the congo",
117569
+ "congo-kinshasa": "democratic republic of the congo",
117570
+ "republic of korea": "south korea",
117571
+ uk: "united kingdom",
117572
+ "great britain": "united kingdom",
117573
+ usa: "united states",
117574
+ us: "united states",
117575
+ uae: "united arab emirates",
117576
+ "north macedonia": "north macedonia",
117577
+ macedonia: "north macedonia",
117578
+ "cape verde": "cabo verde",
117579
+ "vatican": "vatican city",
117580
+ "holy see": "vatican city"
117581
+ };
117582
+ var GEO_UNSERVED = {
117583
+ iran: "Iran",
117584
+ cuba: "Cuba",
117585
+ "north korea": "North Korea",
117586
+ "democratic people's republic of korea": "North Korea",
117587
+ dprk: "North Korea",
117588
+ crimea: "Crimea"
117589
+ };
117590
+ function normGeoName(s) {
117591
+ return s.normalize("NFD").replace(/[\u0300-\u036f]/g, "").trim().toLowerCase().replace(/\s+/g, " ");
117592
+ }
117593
+ function geoQueryKey(query) {
117594
+ const q = normGeoName(query);
117595
+ return GEO_NAME_ALIASES[q] ?? q;
117596
+ }
117597
+ function pickGeoCandidate(query, items3) {
117598
+ const key = geoQueryKey(query);
117599
+ const unserved = GEO_UNSERVED[normGeoName(query)];
117600
+ const parsed = items3.map((it) => {
117601
+ const { base, level } = splitGeoName(geoItemDisplayName(it));
117602
+ return { it, base, level: level || geoItemType(it) };
117603
+ });
117604
+ const same = parsed.filter((p) => normGeoName(p.base) === key || normGeoName(geoItemDisplayName(p.it)) === key);
117605
+ const rank = (lvl) => {
117606
+ const l = lvl.toLowerCase();
117607
+ if (l === "country") return 0;
117608
+ if (l === "region" || l === "territory") return 1;
117609
+ return 2;
117610
+ };
117611
+ same.sort((a, b) => rank(a.level) - rank(b.level));
117612
+ const usable = unserved ? same.filter((p) => rank(p.level) < 2) : same;
117613
+ if (usable.length > 0) return { picked: usable[0].it, status: "ok" };
117614
+ if (unserved) {
117615
+ return {
117616
+ picked: null,
117617
+ status: "unserved",
117618
+ note: `${unserved} \u5728 Google \u5730\u57DF\u5E93\u4E2D\u65E0\u56FD\u5BB6\u7EA7\u6761\u76EE\uFF08Google Ads \u4E0D\u5728\u8BE5\u5730\u533A\u6295\u653E\uFF09\uFF0C\u6392\u9664\u5217\u8868\u53EF\u5FFD\u7565`
117619
+ };
117620
+ }
117621
+ if (items3.length === 0) return { picked: null, status: "not_found" };
117622
+ return {
117623
+ picked: null,
117624
+ status: "needs_review",
117625
+ note: "\u65E0\u540C\u540D\u5019\u9009\uFF0C\u672A\u81EA\u52A8\u9009\u62E9\uFF1B\u8BF7\u4ECE candidates \u4E2D\u4EBA\u5DE5\u786E\u8BA4\uFF0C\u6216\u7528 ad geo search \u6362\u82F1\u6587\u6807\u51C6\u540D"
117626
+ };
117285
117627
  }
117286
117628
  async function runAdGeoSearch(opts) {
117287
117629
  opts = withResolvedAdAccount(opts);
@@ -117307,14 +117649,17 @@ async function runAdGeoSearch(opts) {
117307
117649
  name: geoItemDisplayName(item) || null,
117308
117650
  targetType: geoItemType(item) || null
117309
117651
  }));
117310
- const picked = pickGeoResolveCandidate(opts.query, items3);
117652
+ const pick2 = pickGeoCandidate(opts.query, items3);
117653
+ const picked = pick2.picked;
117311
117654
  const pickedId = picked ? String(picked["id"] ?? "") || null : null;
117312
117655
  const payload = {
117313
117656
  account: opts.account,
117314
117657
  query: opts.query,
117315
117658
  itemCount: rows.length,
117316
117659
  items: rows,
117317
- /** 单国写入 campaign-create 时优先用此选中项(Country 精确匹配优先) */
117660
+ /** ok=同名候选(Country 优先);needs_review=无同名候选未自动选;unserved=Google 不投放地区 */
117661
+ pickStatus: pick2.status,
117662
+ pickNote: pick2.note ?? null,
117318
117663
  picked: picked ? {
117319
117664
  id: pickedId,
117320
117665
  name: geoItemDisplayName(picked) || null,
@@ -117356,7 +117701,9 @@ async function runAdGeoSearch(opts) {
117356
117701
  `
117357
117702
  );
117358
117703
  } else {
117359
- console.log();
117704
+ console.log(`
117705
+ \u26A0\uFE0F \u672A\u81EA\u52A8\u9009\u62E9\uFF1A${pick2.note ?? "\u65E0\u540C\u540D\u5019\u9009"}
117706
+ `);
117360
117707
  }
117361
117708
  }
117362
117709
  function parseGeoResolveQueries(opts) {
@@ -117398,6 +117745,26 @@ function parseGeoResolveQueries(opts) {
117398
117745
  }
117399
117746
  return unique;
117400
117747
  }
117748
+ var GEO_RESOLVE_CONCURRENCY = 6;
117749
+ function buildGeoResolveRow(query, items3) {
117750
+ const pick2 = pickGeoCandidate(query, items3);
117751
+ const row = {
117752
+ query,
117753
+ id: pick2.picked ? String(pick2.picked["id"] ?? "") || null : null,
117754
+ name: pick2.picked ? geoItemDisplayName(pick2.picked) || null : null,
117755
+ targetType: pick2.picked ? geoItemType(pick2.picked) || null : null,
117756
+ status: pick2.status,
117757
+ candidates: items3.length
117758
+ };
117759
+ if (pick2.note) row.note = pick2.note;
117760
+ if (pick2.status === "needs_review") {
117761
+ row.topCandidates = items3.slice(0, 5).map((it) => ({
117762
+ id: String(it["id"] ?? ""),
117763
+ name: geoItemDisplayName(it)
117764
+ }));
117765
+ }
117766
+ return row;
117767
+ }
117401
117768
  async function runAdGeoResolve(opts) {
117402
117769
  opts = withResolvedAdAccount(opts);
117403
117770
  let queries;
@@ -117415,53 +117782,46 @@ async function runAdGeoResolve(opts) {
117415
117782
  }
117416
117783
  const config = loadConfig(opts.token);
117417
117784
  const googleApiUrl = requireGoogleApi(config);
117418
- const rows = [];
117419
- for (const query of queries) {
117420
- let items3 = [];
117421
- try {
117422
- items3 = await fetchGeoLocationCandidates(
117423
- googleApiUrl,
117424
- opts.account,
117425
- query,
117426
- config,
117427
- opts.verbose
117428
- );
117429
- } catch (err) {
117430
- console.error(
117431
- `
117785
+ const rows = new Array(queries.length);
117786
+ let cursor = 0;
117787
+ const worker = async () => {
117788
+ while (cursor < queries.length) {
117789
+ const idx = cursor++;
117790
+ const query = queries[idx];
117791
+ let items3 = [];
117792
+ try {
117793
+ items3 = await fetchGeoLocationCandidates(
117794
+ googleApiUrl,
117795
+ opts.account,
117796
+ query,
117797
+ config,
117798
+ opts.verbose
117799
+ );
117800
+ } catch (err) {
117801
+ console.error(
117802
+ `
117432
117803
  \u274C \u89E3\u6790\u300C${query}\u300D\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
117433
117804
  `
117434
- );
117435
- process.exit(1);
117436
- }
117437
- const picked = pickGeoResolveCandidate(query, items3);
117438
- if (!picked) {
117439
- rows.push({
117440
- query,
117441
- id: null,
117442
- name: null,
117443
- targetType: null,
117444
- status: "not_found",
117445
- candidates: 0
117446
- });
117447
- continue;
117805
+ );
117806
+ process.exit(1);
117807
+ }
117808
+ rows[idx] = buildGeoResolveRow(query, items3);
117448
117809
  }
117449
- rows.push({
117450
- query,
117451
- id: String(picked["id"] ?? "") || null,
117452
- name: geoItemDisplayName(picked) || null,
117453
- targetType: geoItemType(picked) || null,
117454
- status: items3.length > 1 ? "ambiguous_ok" : "ok",
117455
- candidates: items3.length
117456
- });
117457
- }
117458
- const failed = rows.filter((r) => !r.id);
117810
+ };
117811
+ await Promise.all(
117812
+ Array.from({ length: Math.min(GEO_RESOLVE_CONCURRENCY, queries.length) }, () => worker())
117813
+ );
117814
+ const failed = rows.filter((r) => !r.id && r.status !== "unserved");
117815
+ const unserved = rows.filter((r) => r.status === "unserved");
117459
117816
  const locations = rows.filter((r) => r.id).map((r) => r.query);
117460
117817
  const targetedLocations = rows.filter((r) => r.id).map((r) => ({ id: r.id }));
117461
117818
  const payload = {
117462
117819
  account: opts.account,
117463
117820
  resolved: rows.filter((r) => r.id).length,
117464
117821
  failed: failed.length,
117822
+ /** Google 不投放地区(Iran/Cuba/North Korea/Crimea):不计失败,不写入 locations */
117823
+ unserved: unserved.map((r) => r.query),
117824
+ needsReview: rows.filter((r) => r.status === "needs_review").map((r) => r.query),
117465
117825
  rows,
117466
117826
  /** 可直接写入 campaign-create JSON */
117467
117827
  locations,
@@ -117488,15 +117848,22 @@ async function runAdGeoResolve(opts) {
117488
117848
  );
117489
117849
  for (const r of rows) {
117490
117850
  if (r.id) {
117491
- console.log(` \u2705 ${r.query} \u2192 id:${r.id} ${r.name ?? ""} [${r.targetType ?? ""}]`);
117851
+ console.log(` \u2705 ${r.query} \u2192 id:${r.id} ${r.name ?? ""}`);
117852
+ } else if (r.status === "unserved") {
117853
+ console.log(` \u23ED ${r.query} \u2192 ${r.note}`);
117854
+ } else if (r.status === "needs_review") {
117855
+ const cands = (r.topCandidates ?? []).map((c) => `${c.id} ${c.name}`).join(" \uFF5C ");
117856
+ console.log(` \u26A0\uFE0F ${r.query} \u2192 \u65E0\u540C\u540D\u5019\u9009\uFF0C\u672A\u81EA\u52A8\u9009\u62E9\u3002\u5019\u9009\uFF1A${cands}`);
117492
117857
  } else {
117493
117858
  console.log(` \u274C ${r.query} \u2192 \u672A\u627E\u5230`);
117494
117859
  }
117495
117860
  }
117496
117861
  if (failed.length > 0) {
117497
- console.error(`
117498
- \u274C ${failed.length} \u4E2A\u5730\u540D\u672A\u89E3\u6790\uFF1B\u8BF7\u6539\u540D\u540E\u91CD\u8BD5\uFF0C\u6216\u68C0\u67E5\u62FC\u5199\uFF08\u52FF\u7F16\u9020 id\uFF09\u3002
117499
- `);
117862
+ console.error(
117863
+ `
117864
+ \u274C ${failed.length} \u4E2A\u5730\u540D\u672A\u89E3\u6790\uFF08\u542B\u65E0\u540C\u540D\u5019\u9009\uFF09\uFF1B\u8BF7\u6362\u82F1\u6587\u6807\u51C6\u540D\u6216\u7528 ad geo search \u4EBA\u5DE5\u786E\u8BA4\uFF08\u52FF\u7F16\u9020 id\u3001\u52FF\u53D6\u7B2C\u4E00\u6761\u5019\u9009\uFF09\u3002
117865
+ `
117866
+ );
117500
117867
  if (!opts.allowPartial) process.exit(1);
117501
117868
  } else {
117502
117869
  console.log(
@@ -117809,10 +118176,221 @@ function buildExtensionRemediateCommandLine(opts) {
117809
118176
  return null;
117810
118177
  }
117811
118178
 
117812
- // src/commands/ad/campaign-batch-diff.ts
118179
+ // src/commands/ad/campaign-batch-op-index.ts
117813
118180
  function asRecord3(v) {
117814
118181
  return v && typeof v === "object" && !Array.isArray(v) ? v : null;
117815
118182
  }
118183
+ function pickArray(obj, ...keys) {
118184
+ for (const k of keys) {
118185
+ const v = obj[k];
118186
+ if (Array.isArray(v)) return v;
118187
+ }
118188
+ return [];
118189
+ }
118190
+ function pickText(obj, ...keys) {
118191
+ if (!obj) return "";
118192
+ for (const k of keys) {
118193
+ const v = obj[k];
118194
+ if (typeof v === "string" && v.trim()) return v.trim();
118195
+ if (typeof v === "number") return String(v);
118196
+ }
118197
+ return "";
118198
+ }
118199
+ function idOf(v) {
118200
+ const r = asRecord3(v);
118201
+ return r ? pickText(r, "id", "Id") : typeof v === "string" || typeof v === "number" ? String(v) : "";
118202
+ }
118203
+ var AD_GROUP_CRITERIA_KEYS = [
118204
+ "AgeRanges",
118205
+ "ExcludedAgeRanges",
118206
+ "Genders",
118207
+ "ExcludedGenders",
118208
+ "IncomeRanges",
118209
+ "ExcludedIncomeRanges",
118210
+ "Parents",
118211
+ "ExcludedParents",
118212
+ "UserInterests",
118213
+ "CriterionVerticals"
118214
+ ];
118215
+ function lowerFirst(s) {
118216
+ return s.charAt(0).toLowerCase() + s.slice(1);
118217
+ }
118218
+ function buildBatchOperationSlots(cfg) {
118219
+ const campaign = asRecord3(cfg.campaign) ?? {};
118220
+ const names = Array.isArray(cfg.locations) ? cfg.locations : [];
118221
+ const slots = [];
118222
+ const push = (kind, path55, label) => slots.push({ index: slots.length, kind, path: path55, label });
118223
+ push("campaign_budget", "campaign.Budget", "\u7CFB\u5217\u9884\u7B97");
118224
+ push("campaign", "campaign.Name", `\u7CFB\u5217\u300C${pickText(campaign, "Name", "name") || "\u2014"}\u300D`);
118225
+ pickArray(campaign, "targetedLocations", "TargetedLocations").forEach((loc, i) => {
118226
+ const name2 = typeof names[i] === "string" ? `\uFF08${names[i]}\uFF09` : "";
118227
+ push(
118228
+ "campaign_criterion",
118229
+ `campaign.targetedLocations[${i}]`,
118230
+ `\u6295\u653E\u5730\u57DF id=${idOf(loc)}${name2}`
118231
+ );
118232
+ });
118233
+ pickArray(campaign, "excludedLocations", "ExcludedLocations").forEach((loc, i) => {
118234
+ push("campaign_criterion", `campaign.excludedLocations[${i}]`, `\u6392\u9664\u5730\u57DF id=${idOf(loc)}`);
118235
+ });
118236
+ pickArray(campaign, "excludedIpAddresses", "ExcludedIpAddresses").forEach((ip, i) => {
118237
+ push("campaign_criterion", `campaign.excludedIpAddresses[${i}]`, `\u6392\u9664 IP ${String(ip)}`);
118238
+ });
118239
+ pickArray(campaign, "adSchedules", "AdSchedules").forEach((_, i) => {
118240
+ push("campaign_criterion", `campaign.adSchedules[${i}]`, `\u6295\u653E\u65F6\u6BB5 #${i}`);
118241
+ });
118242
+ pickArray(campaign, "targetedPlatforms", "TargetedPlatforms").forEach((p, i) => {
118243
+ push("campaign_criterion", `campaign.targetedPlatforms[${i}]`, `\u6295\u653E\u8BBE\u5907 id=${idOf(p)}`);
118244
+ });
118245
+ pickArray(campaign, "targetedLanguages", "TargetedLanguages").forEach((l, i) => {
118246
+ push("campaign_criterion", `campaign.targetedLanguages[${i}]`, `\u6295\u653E\u8BED\u8A00 id=${idOf(l)}`);
118247
+ });
118248
+ pickArray(campaign, "excludedContentLabels", "ExcludedContentLabels").forEach((_, i) => {
118249
+ push("campaign_criterion", `campaign.excludedContentLabels[${i}]`, `\u6392\u9664\u5185\u5BB9\u6807\u7B7E #${i}`);
118250
+ });
118251
+ pickArray(campaign, "NegativeKeywordsForBatchJob", "negativeKeywordsForBatchJob").forEach(
118252
+ (block, bi) => {
118253
+ const texts = pickArray(asRecord3(block) ?? {}, "KeywordText", "keywordText");
118254
+ texts.forEach((t, ki) => {
118255
+ if (typeof t !== "string" || !t.trim()) return;
118256
+ push(
118257
+ "campaign_criterion",
118258
+ `campaign.NegativeKeywordsForBatchJob[${bi}].KeywordText[${ki}]`,
118259
+ `\u5426\u5B9A\u5173\u952E\u8BCD\u300C${t}\u300D`
118260
+ );
118261
+ });
118262
+ }
118263
+ );
118264
+ pickArray(campaign, "AdGroupsForBatchJob", "adGroupsForBatchJob").forEach((g, gi) => {
118265
+ const group = asRecord3(g) ?? {};
118266
+ const groupPath = `campaign.AdGroupsForBatchJob[${gi}]`;
118267
+ const groupName = pickText(group, "Name", "name") || `#${gi}`;
118268
+ push("ad_group", groupPath, `\u5E7F\u544A\u7EC4\u300C${groupName}\u300D`);
118269
+ for (const key of AD_GROUP_CRITERIA_KEYS) {
118270
+ pickArray(group, key, lowerFirst(key)).forEach((_, i) => {
118271
+ push(
118272
+ "ad_group_criterion",
118273
+ `${groupPath}.${key}[${i}]`,
118274
+ `\u5E7F\u544A\u7EC4\u300C${groupName}\u300D${key}[${i}]`
118275
+ );
118276
+ });
118277
+ }
118278
+ pickArray(group, "KeywordsForBatchJob", "keywordsForBatchJob").forEach((b, bi) => {
118279
+ const block = asRecord3(b) ?? {};
118280
+ const texts = pickArray(block, "KeywordText", "keywordText");
118281
+ if (texts.length > 0) {
118282
+ texts.forEach((t, ki) => {
118283
+ if (typeof t !== "string" || !t.trim()) return;
118284
+ push(
118285
+ "ad_group_criterion",
118286
+ `${groupPath}.KeywordsForBatchJob[${bi}].KeywordText[${ki}]`,
118287
+ `\u5173\u952E\u8BCD\u300C${t}\u300D\uFF08\u7EC4\u300C${groupName}\u300D\uFF09`
118288
+ );
118289
+ });
118290
+ return;
118291
+ }
118292
+ pickArray(block, "Items", "items").forEach((it, ii) => {
118293
+ const text2 = pickText(asRecord3(it), "Text", "text");
118294
+ push(
118295
+ "ad_group_criterion",
118296
+ `${groupPath}.KeywordsForBatchJob[${bi}].Items[${ii}]`,
118297
+ `\u5173\u952E\u8BCD\u300C${text2}\u300D\uFF08\u7EC4\u300C${groupName}\u300D\uFF09`
118298
+ );
118299
+ });
118300
+ });
118301
+ pickArray(group, "AdsForBatchJob", "adsForBatchJob").forEach((ad, ai) => {
118302
+ const h1 = pickText(asRecord3(ad), "headlinePart1", "HeadlinePart1");
118303
+ push(
118304
+ "ad_group_ad",
118305
+ `${groupPath}.AdsForBatchJob[${ai}]`,
118306
+ `\u5E7F\u544A #${ai}${h1 ? `\u300C${h1}\u300D` : ""}\uFF08\u7EC4\u300C${groupName}\u300D\uFF09`
118307
+ );
118308
+ });
118309
+ });
118310
+ const exts = pickArray(campaign, "ExtensionsForBatchJob", "extensionsForBatchJob");
118311
+ exts.forEach((e, ei) => {
118312
+ const type = pickText(asRecord3(e), "TypeV2", "typeV2", "AssetFieldType", "type");
118313
+ push(
118314
+ "asset",
118315
+ `campaign.ExtensionsForBatchJob[${ei}]`,
118316
+ `\u9644\u52A0\u4FE1\u606F #${ei}${type ? ` ${type}` : ""}`
118317
+ );
118318
+ });
118319
+ exts.forEach((_, ei) => {
118320
+ push("campaign_asset", `campaign.ExtensionsForBatchJob[${ei}]`, `\u9644\u52A0\u4FE1\u606F\u5173\u8054 #${ei}`);
118321
+ });
118322
+ return slots;
118323
+ }
118324
+ function buildSubmittedOperationSlots(cfg) {
118325
+ const clone = structuredClone(cfg);
118326
+ runCampaignCreateValidation(clone);
118327
+ return buildBatchOperationSlots(clone);
118328
+ }
118329
+ var OP_RE = /mutate_operations\[(\d+)\]\.([a-z_]+?)_operation\.([a-z_.]+)/;
118330
+ function parseBatchOperationErrors(text2) {
118331
+ const out = [];
118332
+ for (const seg of text2.split(/Processing error:\s*/).slice(1)) {
118333
+ const m = OP_RE.exec(seg);
118334
+ if (!m) continue;
118335
+ const head = seg.slice(0, m.index);
118336
+ const errorType = head.split(",")[0]?.trim() ?? "";
118337
+ const triggerMatch = /^[^,]*,\s*(\{[^}]*\}|)\s*,/.exec(head);
118338
+ const trigger = triggerMatch?.[1]?.trim() ?? "";
118339
+ const message = head.slice(triggerMatch?.[0].length ?? errorType.length + 1).replace(/,\s*$/, "").trim();
118340
+ const policyName = /"PolicyName"\s*:\s*"([^"]+)"/.exec(seg)?.[1];
118341
+ const exempt = /"IsExemptible"\s*:\s*(true|false)/i.exec(seg)?.[1];
118342
+ out.push({
118343
+ index: Number(m[1]),
118344
+ errorType,
118345
+ message,
118346
+ trigger,
118347
+ field: `${m[2]}_operation.${m[3]}`,
118348
+ cascade: /resource was not found/i.test(message) && /"int64Value"\s*:\s*"-\d+"/.test(trigger),
118349
+ ...policyName ? { policyName } : {},
118350
+ ...exempt ? { isExemptible: exempt.toLowerCase() === "true" } : {}
118351
+ });
118352
+ }
118353
+ return out;
118354
+ }
118355
+ function batchRecordErrorText(record2) {
118356
+ const reason = typeof record2["reason"] === "string" ? record2["reason"] : "";
118357
+ const errors = record2["errors"];
118358
+ const errText = typeof errors === "string" ? errors : errors ? JSON.stringify(errors) : "";
118359
+ return [reason, errText].filter(Boolean).join("\n");
118360
+ }
118361
+ function mapBatchOperationErrors(record2, cfg) {
118362
+ const parsed = parseBatchOperationErrors(batchRecordErrorText(record2));
118363
+ if (!cfg || parsed.length === 0) return parsed;
118364
+ const slots = buildSubmittedOperationSlots(cfg);
118365
+ return parsed.map((e) => {
118366
+ const slot = slots[e.index];
118367
+ if (!slot) return { ...e, slotMismatch: true };
118368
+ const kind = e.field.replace(/_operation\..*$/, "");
118369
+ return kind === slot.kind ? { ...e, slot } : { ...e, slot, slotMismatch: true };
118370
+ });
118371
+ }
118372
+ function formatMappedBatchErrors(errors, limit = 12) {
118373
+ if (errors.length === 0) return "";
118374
+ const roots = errors.filter((e) => !e.cascade);
118375
+ const cascades = errors.length - roots.length;
118376
+ const lines = roots.slice(0, limit).map((e) => {
118377
+ const where = e.slot && !e.slotMismatch ? `${e.slot.label} \u2192 ${e.slot.path}` : `\u64CD\u4F5C ${e.field}\uFF08\u6620\u5C04\u4E0D\u53EF\u4FE1\uFF0C\u6309 reason \u539F\u6587\uFF09`;
118378
+ const policy = e.policyName ? ` [\u653F\u7B56 ${e.policyName}${e.isExemptible === void 0 ? "" : e.isExemptible ? "\uFF0C\u53EF\u7533\u8BF7\u8C41\u514D" : "\uFF0C\u4E0D\u53EF\u8C41\u514D"}]` : "";
118379
+ return `[${e.index}] ${e.errorType}: ${e.message}${policy} \u2190 ${where}`;
118380
+ });
118381
+ if (roots.length > limit) lines.push(`\u2026\u53E6\u6709 ${roots.length - limit} \u6761\u6839\u56E0\u89C1 failedOperations[]`);
118382
+ if (cascades > 0) {
118383
+ lines.push(
118384
+ `\u53E6\u6709 ${cascades} \u6761\u4E3A\u7236\u8D44\u6E90\u672A\u5EFA\u6210\u5BFC\u81F4\u7684\u7EA7\u8054\u5931\u8D25\uFF08Resource was not found\uFF09\uFF0C\u4FEE\u597D\u4E0A\u9762\u7684\u6839\u56E0\u5373\u6D88\u5931\uFF0C\u52FF\u9010\u6761\u5904\u7406`
118385
+ );
118386
+ }
118387
+ return ` \u5931\u8D25\u9879\u5B9A\u4F4D\uFF08\u53EA\u6539\u8FD9\u4E9B\u9879\uFF0C\u7981\u6B62\u6574\u7C7B\u5220\u9664\u65B9\u6848\u5185\u5BB9\uFF09\uFF1A${lines.join("\uFF1B")}\u3002`;
118388
+ }
118389
+
118390
+ // src/commands/ad/campaign-batch-diff.ts
118391
+ function asRecord4(v) {
118392
+ return v && typeof v === "object" && !Array.isArray(v) ? v : null;
118393
+ }
117816
118394
  function pickString2(...vals) {
117817
118395
  for (const v of vals) {
117818
118396
  if (typeof v === "string" && v.trim()) return v.trim();
@@ -117963,18 +118541,19 @@ function buildGeoRemediateCommandLine(opts) {
117963
118541
  `-a ${opts.accountId}`,
117964
118542
  `--campaign-id ${opts.campaignId}`,
117965
118543
  `--location-id ${opts.locationId}`,
117966
- `--commit "batch-diff remediate geo"`
118544
+ ...opts.exclude ? ["--exclude"] : [],
118545
+ `--commit "batch-diff remediate ${opts.exclude ? "geo exclude" : "geo"}"`
117967
118546
  ].join(" ");
117968
118547
  }
117969
118548
  function formatExtensionPlanned(ext) {
117970
118549
  if (!ext) return "\u2014";
117971
118550
  const type = pickString2(ext["typeV2"], ext["AssetFieldType"], ext["type"]);
117972
- const props = asRecord3(ext["Properties"]);
118551
+ const props = asRecord4(ext["Properties"]);
117973
118552
  const phone = props ? pickString2(props["PhoneNumber"], props["phoneNumber"]) : "";
117974
118553
  const code = props ? pickString2(props["ContryCode"], props["CountryCode"]) : "";
117975
118554
  const linkText = props ? pickString2(props["Text"], props["LinkText"]) : "";
117976
118555
  const callout = props ? pickString2(props["Text"], props["CalloutText"]) : "";
117977
- const snippet = asRecord3(ext["StructuredSnippetHeaderValue"]);
118556
+ const snippet = asRecord4(ext["StructuredSnippetHeaderValue"]);
117978
118557
  const snippetKey = pickString2(snippet?.["Key"], props?.["StructuredSnippetHeaderValue"]);
117979
118558
  const parts = [
117980
118559
  type ? `\u7C7B\u578B: ${type}` : "",
@@ -117993,13 +118572,13 @@ function listPlannedKeywords(campaign) {
117993
118572
  if (!Array.isArray(groups)) return [];
117994
118573
  const out = [];
117995
118574
  for (let gi = 0; gi < groups.length; gi++) {
117996
- const g = asRecord3(groups[gi]);
118575
+ const g = asRecord4(groups[gi]);
117997
118576
  if (!g) continue;
117998
118577
  const groupName = pickString2(g["Name"], g["name"]) || `AdGroupsForBatchJob[${gi}]`;
117999
118578
  const blocks = g["KeywordsForBatchJob"];
118000
118579
  if (!Array.isArray(blocks)) continue;
118001
118580
  for (let bi = 0; bi < blocks.length; bi++) {
118002
- const block = asRecord3(blocks[bi]);
118581
+ const block = asRecord4(blocks[bi]);
118003
118582
  if (!block) continue;
118004
118583
  const matchTypeV2 = pickString2(block["MatchTypeV2"], block["matchTypeV2"]) || "BROAD";
118005
118584
  const texts = block["KeywordText"];
@@ -118023,7 +118602,7 @@ function listPlannedNegativeKeywords(campaign) {
118023
118602
  if (!Array.isArray(blocks)) return [];
118024
118603
  const out = [];
118025
118604
  for (let bi = 0; bi < blocks.length; bi++) {
118026
- const block = asRecord3(blocks[bi]);
118605
+ const block = asRecord4(blocks[bi]);
118027
118606
  if (!block) continue;
118028
118607
  const matchTypeV2 = pickString2(block["MatchTypeV2"], block["matchTypeV2"]) || "BROAD";
118029
118608
  const texts = block["KeywordText"];
@@ -118063,7 +118642,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
118063
118642
  const plannedGroupCount = Array.isArray(groups) ? groups.length : 0;
118064
118643
  if (Array.isArray(groups)) {
118065
118644
  for (let gi = 0; gi < groups.length; gi++) {
118066
- const g = asRecord3(groups[gi]);
118645
+ const g = asRecord4(groups[gi]);
118067
118646
  if (!g) continue;
118068
118647
  const groupName = pickString2(g["Name"], g["name"]) || `AdGroupsForBatchJob[${gi}]`;
118069
118648
  const groupPath = `campaign.AdGroupsForBatchJob[${gi}]`;
@@ -118115,7 +118694,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
118115
118694
  const blocks = g["KeywordsForBatchJob"];
118116
118695
  if (Array.isArray(blocks)) {
118117
118696
  for (let bi = 0; bi < blocks.length; bi++) {
118118
- const block = asRecord3(blocks[bi]);
118697
+ const block = asRecord4(blocks[bi]);
118119
118698
  if (!block) continue;
118120
118699
  const matchTypeV2 = pickString2(block["MatchTypeV2"], block["matchTypeV2"]) || "BROAD";
118121
118700
  const texts = block["KeywordText"];
@@ -118169,7 +118748,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
118169
118748
  const ads = g["AdsForBatchJob"];
118170
118749
  if (Array.isArray(ads)) {
118171
118750
  for (let ai = 0; ai < ads.length; ai++) {
118172
- const ad = asRecord3(ads[ai]);
118751
+ const ad = asRecord4(ads[ai]);
118173
118752
  if (!ad) continue;
118174
118753
  const path55 = `${groupPath}.AdsForBatchJob[${ai}]`;
118175
118754
  const primary = pickString2(ad["headlinePart1"], ad["AdTitle"]);
@@ -118303,7 +118882,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
118303
118882
  ).length;
118304
118883
  if (Array.isArray(extBlocks)) {
118305
118884
  for (let ei = 0; ei < extBlocks.length; ei++) {
118306
- const ext = asRecord3(extBlocks[ei]);
118885
+ const ext = asRecord4(extBlocks[ei]);
118307
118886
  const plannedContent = formatExtensionPlanned(ext);
118308
118887
  const path55 = `campaign.ExtensionsForBatchJob[${ei}]`;
118309
118888
  if (campaignMissing) {
@@ -118342,7 +118921,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
118342
118921
  if (Array.isArray(plannedLocs)) {
118343
118922
  plannedLocCount = plannedLocs.length;
118344
118923
  for (let li = 0; li < plannedLocs.length; li++) {
118345
- const loc = asRecord3(plannedLocs[li]);
118924
+ const loc = asRecord4(plannedLocs[li]);
118346
118925
  if (!loc) continue;
118347
118926
  const id = pickString2(loc["id"], loc["Id"]);
118348
118927
  if (!id) continue;
@@ -118373,6 +118952,42 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
118373
118952
  });
118374
118953
  }
118375
118954
  }
118955
+ const plannedExcl = campaign["excludedLocations"] ?? campaign["ExcludedLocations"];
118956
+ const liveExclIds = new Set(
118957
+ (live.excludedLocations ?? []).filter((loc) => belongsToCampaign(loc, campaignId, campaignName)).map((loc) => liveLocationId(loc)).filter((id) => id.length > 0)
118958
+ );
118959
+ let plannedExclCount = 0;
118960
+ if (Array.isArray(plannedExcl)) {
118961
+ plannedExclCount = plannedExcl.length;
118962
+ for (let li = 0; li < plannedExcl.length; li++) {
118963
+ const loc = asRecord4(plannedExcl[li]);
118964
+ const id = loc ? pickString2(loc["id"], loc["Id"]) : "";
118965
+ if (!id) continue;
118966
+ const path55 = `campaign.excludedLocations[${li}]`;
118967
+ const plannedContent = `\u6392\u9664 locationId: ${id}`;
118968
+ if (campaignMissing) {
118969
+ pushItem(items3, {
118970
+ layer: "excluded_location",
118971
+ path: path55,
118972
+ plannedContent,
118973
+ status: "skipped",
118974
+ liveNote: "\u7CFB\u5217\u672A\u627E\u5230\uFF0C\u8DF3\u8FC7\u6392\u9664\u5730\u57DF\u6BD4\u5BF9",
118975
+ summary: `\u6392\u9664\u5730\u57DF\u672A\u6BD4\u5BF9\uFF08\u7CFB\u5217\u7F3A\u5931\uFF09\uFF1A${id}`
118976
+ });
118977
+ continue;
118978
+ }
118979
+ const found = liveExclIds.has(id);
118980
+ pushItem(items3, {
118981
+ layer: "excluded_location",
118982
+ path: path55,
118983
+ plannedContent,
118984
+ status: found ? "ok" : "missing",
118985
+ liveNote: `\u7CFB\u5217\u5DF2\u6392\u9664 ${liveExclIds.size}/${plannedExclCount} \u4E2A\u5730\u57DF`,
118986
+ summary: found ? `\u6392\u9664\u5730\u57DF\u5DF2\u751F\u6548\uFF1Aid=${id}` : `\u6392\u9664\u5730\u57DF\u672A\u751F\u6548\uFF1Aid=${id}`,
118987
+ remediateCommand: !found && accountId && campaignId ? buildGeoRemediateCommandLine({ accountId, campaignId, locationId: id, exclude: true }) : void 0
118988
+ });
118989
+ }
118990
+ }
118376
118991
  const plannedKeywords = listPlannedKeywords(campaign);
118377
118992
  const liveKwCount = live.keywords.filter(
118378
118993
  (k) => belongsToCampaign(k, campaignId, campaignName)
@@ -118392,6 +119007,13 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
118392
119007
  } else {
118393
119008
  agentHint = `\u4E0E JSON \u8BA1\u5212\u4E00\u81F4\uFF08\u542B\u6295\u653E\u5730\u57DF\uFF1Bitems[] \u5171 ${statusCounts.ok} \u6761\u5747\u4E3A ok\uFF09\u3002**\u7ACB\u523B**\u628A\u672C\u547D\u4EE4 stdout \u4E2D BEGIN_USER_DELIVERY_MARKDOWN\u2026END \u5168\u6587\u539F\u6837\u53D1\u7ED9\u7528\u6237\uFF1B\u7981\u6B62\u53EA\u8BF4\u300C\u672A\u53D1\u73B0\u7F3A\u5931\u300D\u6216\u53EA\u8D34 counts \u6458\u8981\u3002`;
118394
119009
  }
119010
+ const emptyInPlan = [
119011
+ plannedExclCount === 0 ? "excludedLocations" : "",
119012
+ listPlannedNegativeKeywords(campaign).length === 0 ? "NegativeKeywordsForBatchJob" : ""
119013
+ ].filter(Boolean);
119014
+ if (emptyInPlan.length > 0) {
119015
+ agentHint += ` \u6CE8\u610F\uFF1A\u672C\u6B21\u6BD4\u5BF9\u7684\u8BA1\u5212 JSON \u4E2D ${emptyInPlan.join(" / ")} \u4E3A\u7A7A\u2014\u2014diff \u53EA\u80FD\u5BF9\u7167\u8FD9\u4EFD JSON\u3002\u82E5\u7528\u6237\u539F\u59CB\u65B9\u6848\u6709\u6392\u9664\u5730\u57DF/\u5426\u8BCD\u800C\u521B\u5EFA\u8FC7\u7A0B\u4E2D\u88AB\u5220\uFF0C\u5FC5\u987B\u5728\u4EA4\u4ED8\u65F6\u5982\u5B9E\u8BF4\u660E\u5E76\u8BE2\u95EE\u662F\u5426\u8865\u5EFA\uFF0C\u7981\u6B62\u58F0\u79F0\u300C\u5DF2\u6309\u65B9\u6848\u6392\u9664\u300D\u3002`;
119016
+ }
118395
119017
  return {
118396
119018
  accountId,
118397
119019
  campaignId,
@@ -118411,7 +119033,7 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
118411
119033
  plannedKeywords: plannedKeywords.length,
118412
119034
  liveKeywords: liveKwCount,
118413
119035
  plannedAds: Array.isArray(groups) ? groups.reduce((n, g) => {
118414
- const gr = asRecord3(g);
119036
+ const gr = asRecord4(g);
118415
119037
  const ads = gr?.["AdsForBatchJob"];
118416
119038
  return n + (Array.isArray(ads) ? ads.length : 0);
118417
119039
  }, 0) : 0,
@@ -118421,7 +119043,9 @@ function compareCampaignCreateToLive(cfg, campaignId, live, meta) {
118421
119043
  plannedExtensions: plannedExt,
118422
119044
  liveExtensions: liveExt,
118423
119045
  plannedLocations: plannedLocCount,
118424
- liveLocations: liveLocIds.size
119046
+ liveLocations: liveLocIds.size,
119047
+ plannedExcludedLocations: plannedExclCount,
119048
+ liveExcludedLocations: liveExclIds.size
118425
119049
  }
118426
119050
  };
118427
119051
  }
@@ -118440,7 +119064,16 @@ async function fetchLiveSnapshotForCampaign(config, accountId, campaignId, campa
118440
119064
  params.set("endDate", toGoogleDate(void 0, 0));
118441
119065
  params.set("newest", "true");
118442
119066
  const qs = params.toString();
118443
- const [campaigns, adGroups, keywords, negativeKeywords, ads, extensions, targetedLocations] = await Promise.all([
119067
+ const [
119068
+ campaigns,
119069
+ adGroups,
119070
+ keywords,
119071
+ negativeKeywords,
119072
+ ads,
119073
+ extensions,
119074
+ targetedLocations,
119075
+ excludedLocations
119076
+ ] = await Promise.all([
118444
119077
  fetchList(
118445
119078
  config,
118446
119079
  `${googleApiUrl}/campaignmanagement/v2/list/${accountId}?${qs}`,
@@ -118475,6 +119108,11 @@ async function fetchLiveSnapshotForCampaign(config, accountId, campaignId, campa
118475
119108
  config,
118476
119109
  `${googleApiUrl}/campaignmanagement/v2/targetedlocations/${accountId}?${qs}`,
118477
119110
  verbose
119111
+ ),
119112
+ fetchList(
119113
+ config,
119114
+ `${googleApiUrl}/campaignmanagement/v2/excludedlocations/${accountId}?${qs}`,
119115
+ verbose
118478
119116
  )
118479
119117
  ]);
118480
119118
  const campaignFound = campaigns.some(
@@ -118492,11 +119130,14 @@ async function fetchLiveSnapshotForCampaign(config, accountId, campaignId, campa
118492
119130
  extensions: extensions.filter((e) => belongsToCampaign(e, campaignId, campaignName)),
118493
119131
  targetedLocations: targetedLocations.filter(
118494
119132
  (loc) => belongsToCampaign(loc, campaignId, campaignName)
119133
+ ),
119134
+ excludedLocations: excludedLocations.filter(
119135
+ (loc) => belongsToCampaign(loc, campaignId, campaignName)
118495
119136
  )
118496
119137
  };
118497
119138
  }
118498
119139
  function resolveCampaignIdFromBatch(record2) {
118499
- const campaign = asRecord3(record2["campaign"]);
119140
+ const campaign = asRecord4(record2["campaign"]);
118500
119141
  const direct = pickString2(
118501
119142
  campaign?.["Id"],
118502
119143
  campaign?.["id"],
@@ -118507,7 +119148,7 @@ function resolveCampaignIdFromBatch(record2) {
118507
119148
  const groups = campaign?.["AdGroupsForBatchJob"];
118508
119149
  if (Array.isArray(groups)) {
118509
119150
  for (const g of groups) {
118510
- const gr = asRecord3(g);
119151
+ const gr = asRecord4(g);
118511
119152
  const cid = pickString2(gr?.["CampaignId"], gr?.["campaignId"]);
118512
119153
  if (cid) return cid;
118513
119154
  }
@@ -118515,7 +119156,7 @@ function resolveCampaignIdFromBatch(record2) {
118515
119156
  return "";
118516
119157
  }
118517
119158
  function resolveCampaignNameFromBatch(record2) {
118518
- const campaign = asRecord3(record2["campaign"]);
119159
+ const campaign = asRecord4(record2["campaign"]);
118519
119160
  return pickString2(
118520
119161
  record2["campaignName"],
118521
119162
  record2["CampaignName"],
@@ -118538,7 +119179,23 @@ function hintBatchFailureRemediation(record2) {
118538
119179
  );
118539
119180
  }
118540
119181
  if (/name is already assigned|already assigned to another/.test(blob)) {
118541
- tips.push("\u6539 campaign.Name\uFF08\u53CA\u5916\u5C42 name\uFF09\u4E3A\u8D26\u6237\u5185\u672A\u5360\u7528\u540D\u79F0\u540E\u91CD\u63D0");
119182
+ tips.push(
119183
+ "\u6539 campaign.Name\uFF08\u53CA\u5916\u5C42 name\uFF09\u4E3A\u8D26\u6237\u5185\u672A\u5360\u7528\u540D\u79F0\u540E\u91CD\u63D0\uFF1B\u7981\u6B62\u5220\u9664\u5360\u7528\u8BE5\u540D\u79F0\u7684\u5DF2\u6709\u7CFB\u5217"
119184
+ );
119185
+ }
119186
+ const destination = /destination_not_working|destination_not_found|destination_mismatch/.test(
119187
+ blob
119188
+ );
119189
+ if (destination) {
119190
+ tips.push(
119191
+ "\u843D\u5730\u9875\u4E0D\u53EF\u8BBF\u95EE\uFF08DESTINATION_*\uFF09\uFF1A\u5411\u7528\u6237\u8BF4\u660E\u5E76\u7D22\u53D6\u53EF\u6B63\u5E38\u6253\u5F00\u7684\u843D\u5730\u9875 URL\uFF0C\u6539\u5BF9\u5E94\u5E7F\u544A\u7684 Finalurl/DestinationUrl\uFF1B\u7CFB\u5217\u5DF2\u5EFA\u6210\u65F6\u7528 ad ad-create \u53EA\u8865\u8BE5\u5E7F\u544A\uFF0C\u52FF\u91CD\u63D0\u6574\u4E2A\u7CFB\u5217"
119192
+ );
119193
+ }
119194
+ if (/policyviolation/.test(blob) || /policy/.test(blob) && !destination) {
119195
+ const exemptible = /"isexemptible"\s*:\s*true/.test(blob);
119196
+ tips.push(
119197
+ "\u89E6\u53D1 Google \u653F\u7B56\uFF1A\u505C\u4E0B\u5411\u7528\u6237\u62A5\u544A\u89E6\u53D1\u7684\u5173\u952E\u8BCD/\u6587\u6848\uFF08\u89C1\u5931\u8D25\u9879\u5B9A\u4F4D\uFF09" + (exemptible ? "\uFF0C\u4E14\u8BE5\u653F\u7B56 IsExemptible=true\uFF08\u53EF\u7533\u8BF7\u8C41\u514D\uFF09" : "") + "\uFF1B\u7ED9\u51FA\u53EF\u9009\u65B9\u6848\uFF08\u53BB\u6389\u8FD9\u4E9B\u8BCD / \u6539\u5199\u8BCD\u9762\u6216\u6587\u6848 / \u7533\u8BF7\u653F\u7B56\u8C41\u514D / \u7531\u7528\u6237\u6307\u5B9A\u7F29\u51CF\u5730\u57DF\uFF09\u7B49\u7528\u6237\u9009\u62E9\u3002LEGAL_REQUIREMENTS \u7B49\u5730\u57DF\u76F8\u5173\u653F\u7B56\u62A5\u9519\u4E0D\u6307\u660E\u5177\u4F53\u56FD\u5BB6\uFF1A\u7981\u6B62\u81EA\u884C\u521B\u5EFA\u6D4B\u8BD5\u7CFB\u5217\u9010\u5730\u57DF\u4E8C\u5206\u6392\u67E5"
119198
+ );
118542
119199
  }
118543
119200
  return tips.length > 0 ? ` \u4FEE\u590D\u63D0\u793A\uFF1A${tips.join("\uFF1B")}\u3002` : "";
118544
119201
  }
@@ -118546,16 +119203,25 @@ function buildBatchGetAgentWorkflow(opts) {
118546
119203
  const status = pickString2(opts.record["status"]);
118547
119204
  const campaignId = resolveCampaignIdFromBatch(opts.record) || null;
118548
119205
  const campaignName = resolveCampaignNameFromBatch(opts.record) || null;
119206
+ const cfg = opts.config !== void 0 ? opts.config : opts.configFile ? tryLoadCampaignCreateConfig(opts.configFile) : null;
119207
+ const failedOperations = status === "Failed" || status === "HasFailed" ? mapBatchOperationErrors(opts.record, cfg) : [];
119208
+ const located = formatMappedBatchErrors(failedOperations) + (failedOperations.length > 0 && !cfg ? " \u672A\u63D0\u4F9B --config-file\uFF0C\u65E0\u6CD5\u628A mutate_operations[N] \u6620\u5C04\u5230 JSON \u9879\uFF1B\u8BF7\u5E26\u63D0\u4EA4\u65F6\u7684 JSON \u91CD\u8DD1 batch get\u3002" : "");
118549
119209
  const terminalNoCampaign = (status === "Failed" || status === "HasFailed") && !campaignId;
119210
+ const shellCreated = status === "HasFailed" && failedOperations.length > 0 && !failedOperations.some((e) => e.index <= 1);
118550
119211
  const runDiff = !terminalNoCampaign && shouldRunBatchDiff(status);
118551
119212
  let nextCommand = null;
118552
119213
  let agentHint;
118553
119214
  if (status === "Creating") {
118554
119215
  agentHint = "\u4EFB\u52A1\u4ECD\u5728 Creating\uFF1A\u6BCF 5s \u8F6E\u8BE2 ad batch get\uFF08\u987B\u5E26\u540C\u4E00 --config-file\uFF09\uFF0C\u52FF\u6267\u884C batch diff\u3002";
118555
119216
  nextCommand = opts.configFile ? `siluzan-tso ad batch get --id ${opts.batchId} --config-file ${shellArgPath(opts.configFile)} --json-out ./snap-campaign` : `siluzan-tso ad batch get --id ${opts.batchId} --config-file <campaign.json> --json-out ./snap-campaign`;
119217
+ } else if (terminalNoCampaign && shellCreated) {
119218
+ const account = pickString2(cfg?.account, opts.record["customerId"]) || "<accountId>";
119219
+ const name2 = campaignName ?? "<\u7CFB\u5217\u540D>";
119220
+ agentHint = `HasFailed \u4E14\u8BB0\u5F55\u91CC\u65E0 campaignId\uFF0C\u4F46\u9884\u7B97/\u7CFB\u5217\u64CD\u4F5C\u6CA1\u6709\u62A5\u9519\uFF1A\u7CFB\u5217\u300C${name2}\u300D**\u5DF2\u5728\u8D26\u6237\u4E2D\u521B\u5EFA**\uFF0C\u53EA\u6709\u90E8\u5206\u5B50\u9879\u5931\u8D25\u3002\u5148\u6267\u884C nextCommand \u6309\u540D\u79F0\u627E\u5230 campaignId\uFF0C\u518D ad batch diff --campaign-id <id> \u5E76\u628A\u62A5\u544A\u4EA4\u4ED8\u7528\u6237\uFF1B\u4E4B\u540E\u53EA\u8865\u5EFA\u5931\u8D25\u9879\uFF0C**\u7981\u6B62**\u91CD\u63D0\u6574\u4E2A\u7CFB\u5217\uFF08\u4F1A\u540D\u79F0\u51B2\u7A81\uFF09\u6216\u5220\u9664\u8BE5\u7CFB\u5217\u3002` + located + hintBatchFailureRemediation(opts.record);
119221
+ nextCommand = `siluzan-tso ad campaigns -a ${account} --fresh --json-out ./snap-campaign`;
118556
119222
  } else if (terminalNoCampaign) {
118557
119223
  const fix = hintBatchFailureRemediation(opts.record);
118558
- agentHint = `${status} \u4E14\u65E0 campaignId\uFF1A\u7CFB\u5217\u672A\u521B\u5EFA\u6210\u529F\u3002\u8BFB reason/errors\uFF0C\u6539 JSON \u540E\u91CD\u63D0 campaign-create\uFF1B\u4E0D\u8981\u8DD1 batch diff\u3002` + fix;
119224
+ agentHint = `${status} \u4E14\u65E0 campaignId\uFF1A\u7CFB\u5217\u672A\u521B\u5EFA\u6210\u529F\u3002\u8BFB reason/errors\uFF0C\u6539 JSON \u540E\u91CD\u63D0 campaign-create\uFF1B\u4E0D\u8981\u8DD1 batch diff\u3002` + (status === "HasFailed" ? "\u8D26\u6237\u91CC\u4ECD\u53EF\u80FD\u7559\u4E0B\u534A\u6210\u54C1\u7CFB\u5217\uFF1A\u5148 ad campaigns --fresh \u6838\u5BF9\u5E76\u544A\u77E5\u7528\u6237\uFF0C\u5220\u9664\u4E0E\u5426\u7531\u7528\u6237\u51B3\u5B9A\uFF08campaign-delete \u987B\u7528\u6237\u540C\u610F\u540E --i-confirm\uFF09\u3002" : "") + located + fix;
118559
119225
  nextCommand = null;
118560
119226
  } else if (runDiff) {
118561
119227
  if (!opts.configFile) {
@@ -118569,6 +119235,8 @@ function buildBatchGetAgentWorkflow(opts) {
118569
119235
  });
118570
119236
  agentHint = `\u5FC5\u505A\u4E0B\u4E00\u6B65\uFF1A\u6267\u884C nextCommand\uFF08ad batch diff\uFF09\u3002diff \u7684 stdout \u542B BEGIN_USER_DELIVERY_MARKDOWN\u2026END\u2014\u2014**\u7ACB\u523B\u539F\u6837\u53D1\u7ED9\u7528\u6237**\uFF08\u52FF\u6458\u8981\u3001\u52FF\u7B49\u8865\u5EFA\u7ED3\u675F\uFF09\uFF1B\u6709 remediateCommand \u5219\u4EA4\u4ED8\u540E\u518D\u8865\u5EFA\u5E76\u518D\u8DD1 diff\u3002`;
118571
119237
  }
119238
+ agentHint += located;
119239
+ if (status === "HasFailed") agentHint += hintBatchFailureRemediation(opts.record);
118572
119240
  } else {
118573
119241
  agentHint = `\u5F53\u524D status=${status || "\u2014"}\uFF0C\u6309 google-ads.md \xA7 batch \u5904\u7406\u3002`;
118574
119242
  }
@@ -118580,7 +119248,8 @@ function buildBatchGetAgentWorkflow(opts) {
118580
119248
  campaignName,
118581
119249
  configFile: opts.configFile ?? null,
118582
119250
  nextCommand,
118583
- agentHint
119251
+ agentHint,
119252
+ failedOperations
118584
119253
  };
118585
119254
  }
118586
119255
  function shellArgPath(p) {
@@ -118650,6 +119319,7 @@ function printBatchDiffFollowUpHint(opts) {
118650
119319
  var LAYER_ORDER = [
118651
119320
  "campaign",
118652
119321
  "location",
119322
+ "excluded_location",
118653
119323
  "adgroup",
118654
119324
  "keyword",
118655
119325
  "ad",
@@ -118659,6 +119329,7 @@ var LAYER_ORDER = [
118659
119329
  var LAYER_TITLE = {
118660
119330
  campaign: "\u7CFB\u5217",
118661
119331
  location: "\u6295\u653E\u56FD\u5BB6/\u5730\u57DF",
119332
+ excluded_location: "\u6392\u9664\u5730\u57DF",
118662
119333
  adgroup: "\u5E7F\u544A\u7EC4",
118663
119334
  keyword: "\u5173\u952E\u8BCD",
118664
119335
  ad: "RSA\u6587\u6848",
@@ -118740,10 +119411,21 @@ function buildCampaignCreateStatusMarkdown(result) {
118740
119411
  `| \u5426\u5B9A\u8BCD | ${c.liveNegativeKeywords} | ${c.plannedNegativeKeywords} |`,
118741
119412
  `| \u9644\u52A0\u4FE1\u606F | ${c.liveExtensions} | ${c.plannedExtensions} |`,
118742
119413
  `| \u6295\u653E\u5730\u57DF | ${c.liveLocations} | ${c.plannedLocations} |`,
119414
+ `| \u6392\u9664\u5730\u57DF | ${c.liveExcludedLocations} | ${c.plannedExcludedLocations} |`,
118743
119415
  ``,
118744
119416
  `**\u9010\u9879\u72B6\u6001\u8BA1\u6570**\uFF1A\u2705 ${sc.ok}\u3000\u274C ${sc.missing}\u3000\u23ED ${sc.skipped}\u3000\u5408\u8BA1 ${result.items.length}`,
118745
119417
  ``
118746
119418
  ];
119419
+ const emptyInPlan = [
119420
+ c.plannedExcludedLocations === 0 ? "\u6392\u9664\u5730\u57DF" : "",
119421
+ c.plannedNegativeKeywords === 0 ? "\u5426\u5B9A\u8BCD" : ""
119422
+ ].filter(Boolean);
119423
+ if (emptyInPlan.length > 0) {
119424
+ lines.push(
119425
+ `> \u26A0\uFE0F \u672C\u6B21\u63D0\u4EA4\u7684\u8BA1\u5212 JSON \u4E2D **${emptyInPlan.join("\u3001")}\u4E3A 0 \u6761**\uFF0C\u8D26\u6237\u5185\u4E5F\u5C31\u6CA1\u6709\u8BBE\u7F6E\u3002\u82E5\u6295\u653E\u65B9\u6848\u539F\u672C\u6709\u8FD9\u4E9B\u5185\u5BB9\uFF0C\u8BF4\u660E\u521B\u5EFA\u8FC7\u7A0B\u4E2D\u88AB\u79FB\u9664\uFF0C\u8BF7\u4E0E\u52A9\u624B\u6838\u5BF9\u662F\u5426\u9700\u8981\u8865\u4E0A\u3002`,
119426
+ ``
119427
+ );
119428
+ }
118747
119429
  const planItems = result.items.length > 0 ? result.items : result.missing.map((m) => ({ ...m, status: "missing" }));
118748
119430
  for (const layer of LAYER_ORDER) {
118749
119431
  const layerItems = planItems.filter((i) => i.layer === layer);
@@ -119136,6 +119818,22 @@ async function runAiCreationList(opts) {
119136
119818
  }
119137
119819
  console.log();
119138
119820
  }
119821
+ async function lookupCampaignIdByName(config, account, name2, verbose) {
119822
+ if (!account || !name2 || !config.googleApiUrl) return "";
119823
+ try {
119824
+ const url = campaignListUrl(config.googleApiUrl, account, void 0, void 0, true);
119825
+ const res = await apiFetch2(
119826
+ url,
119827
+ config,
119828
+ {},
119829
+ verbose
119830
+ );
119831
+ const hits = (res.data ?? []).filter((c) => String(c.name ?? "").trim() === name2.trim());
119832
+ return hits.length === 1 ? String(hits[0].id ?? "") : "";
119833
+ } catch {
119834
+ return "";
119835
+ }
119836
+ }
119139
119837
  async function runAiCreationGet(opts) {
119140
119838
  const config = loadConfig(opts.token);
119141
119839
  const url = `${config.apiBaseUrl}/query/campaign-creation-record/campaign-batch-asyncs/${opts.id}`;
@@ -119148,11 +119846,28 @@ async function runAiCreationGet(opts) {
119148
119846
  `);
119149
119847
  process.exit(1);
119150
119848
  }
119151
- const agentWorkflow = buildBatchGetAgentWorkflow({
119849
+ let agentWorkflow = buildBatchGetAgentWorkflow({
119152
119850
  batchId: opts.id,
119153
119851
  record: data,
119154
119852
  configFile: opts.configFile
119155
119853
  });
119854
+ const shellCreatedNoId = agentWorkflow["status"] === "HasFailed" && !agentWorkflow["campaignId"] && String(agentWorkflow["nextCommand"] ?? "").includes("ad campaigns");
119855
+ if (shellCreatedNoId) {
119856
+ const found = await lookupCampaignIdByName(
119857
+ config,
119858
+ String(data["customerId"] ?? ""),
119859
+ resolveCampaignNameFromBatch(data),
119860
+ opts.verbose
119861
+ );
119862
+ if (found) {
119863
+ data = { ...data, campaignId: found, campaignIdSource: "lookup-by-name" };
119864
+ agentWorkflow = buildBatchGetAgentWorkflow({
119865
+ batchId: opts.id,
119866
+ record: data,
119867
+ configFile: opts.configFile
119868
+ });
119869
+ }
119870
+ }
119156
119871
  const payload = { ...data, agentWorkflow };
119157
119872
  if (await emitCliJsonOrSnapshot(opts, {
119158
119873
  section: `ad-batch-get-${opts.id}`,
@@ -119238,6 +119953,23 @@ ${reason}
119238
119953
  console.log(JSON.stringify(errors, null, 2));
119239
119954
  console.log();
119240
119955
  }
119956
+ const failedOps = agentWorkflow["failedOperations"];
119957
+ if (failedOps.length > 0) {
119958
+ const roots = failedOps.filter((e) => !e.cascade);
119959
+ console.log(
119960
+ `
119961
+ \u2500\u2500 \u5931\u8D25\u9879\u5B9A\u4F4D\uFF08\u6839\u56E0 ${roots.length} \u6761\uFF0C\u7EA7\u8054 ${failedOps.length - roots.length} \u6761\uFF09\u2500\u2500
119962
+ `
119963
+ );
119964
+ for (const e of roots) {
119965
+ const where = e.slot && !e.slotMismatch ? `${e.slot.label} ${e.slot.path}` : `${e.field}\uFF08\u672A\u80FD\u6620\u5C04\u5230 JSON \u9879\uFF09`;
119966
+ console.log(` [${e.index}] ${e.errorType}: ${e.message}
119967
+ \u2192 ${where}`);
119968
+ }
119969
+ console.log(
119970
+ "\n \u53EA\u4FEE\u6539\u4E0A\u9762\u5217\u51FA\u7684\u9879\uFF1B\u7981\u6B62\u4E3A\u901A\u8FC7\u521B\u5EFA\u6574\u7C7B\u5220\u9664\u65B9\u6848\u5185\u5BB9\uFF08\u5426\u8BCD/\u6392\u9664\u5730\u57DF/\u6295\u653E\u56FD\u5BB6\uFF09\u3002\n"
119971
+ );
119972
+ }
119241
119973
  const st = String(item.status ?? "");
119242
119974
  if (st === "Failed") {
119243
119975
  printBatchFailedFollowUpHint({ batchId: opts.id, configFile: opts.configFile });
@@ -121798,6 +122530,13 @@ async function runAdPmaxEdit(opts) {
121798
122530
  console.error("\n\u274C PATCH body \u4E3A\u7A7A\n");
121799
122531
  process.exit(1);
121800
122532
  }
122533
+ const statusV2 = body["statusV2"] ?? body["StatusV2"];
122534
+ if (statusV2 !== void 0 && parseStatusV2(String(statusV2)) === 4) {
122535
+ ensureIConfirm({
122536
+ iConfirm: opts.iConfirm,
122537
+ actionLabel: `ad pmax-edit --status Removed\uFF08\u79FB\u9664 PMax \u6D3B\u52A8 ${campaignId}\uFF0C\u4E0D\u53EF\u6062\u590D\uFF09`
122538
+ });
122539
+ }
121801
122540
  await withGoogleApi(opts, async (config, googleApiUrl) => {
121802
122541
  const url = pmaxCampaignUrl(googleApiUrl, accountId, campaignId);
121803
122542
  try {
@@ -122794,6 +123533,10 @@ function parseOptionalMatchType(raw) {
122794
123533
  `);
122795
123534
  process.exit(1);
122796
123535
  }
123536
+ function resolveWriteNormalizedPath(raw, configFile) {
123537
+ if (raw === true) return configFile;
123538
+ return typeof raw === "string" && raw.trim() ? raw : void 0;
123539
+ }
122797
123540
  function register21(program2) {
122798
123541
  const adCmd = program2.command("ad").description(
122799
123542
  "Google \u5E7F\u544A\u7BA1\u7406\uFF08Google API \u5730\u5740\u4ECE TSO API \u81EA\u52A8\u63A8\u5BFC\uFF0C\u53EF\u901A\u8FC7 SILUZAN_GOOGLE_API \u73AF\u5883\u53D8\u91CF\u8986\u76D6\uFF09\n \u542B\uFF1A\u7CFB\u5217/\u7EC4/\u521B\u610F/\u5173\u952E\u8BCD\u7B49\u5E38\u89C4\u5E7F\u544A\u6295\u653E\u4E0E\u7BA1\u7406\u80FD\u529B"
@@ -122985,14 +123728,19 @@ function register21(program2) {
122985
123728
  });
122986
123729
  }
122987
123730
  );
122988
- adCmd.command("campaign-delete").description("\u5220\u9664\u5E7F\u544A\u7CFB\u5217\uFF08\u64CD\u4F5C\u4E0D\u53EF\u6062\u590D\uFF09").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--id <campaignId>", "\u5E7F\u544A\u7CFB\u5217 ID").option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(async (opts) => {
122989
- await runAdCampaignDelete({
122990
- token: opts.token,
122991
- account: opts.account,
122992
- id: opts.id,
122993
- verbose: opts.verbose
122994
- });
122995
- });
123731
+ adCmd.command("campaign-delete").description(
123732
+ "\u5220\u9664\u5E7F\u544A\u7CFB\u5217\uFF08\u4E0D\u53EF\u6062\u590D\uFF1B\u7834\u574F\u6027\uFF1A\u987B\u7528\u6237\u660E\u786E\u540C\u610F\u540E\u52A0 --i-confirm + --commit\uFF0C\u542B Agent \u81EA\u5EFA\u7684\u6D4B\u8BD5\u7CFB\u5217\uFF09"
123733
+ ).requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--id <campaignId>", "\u5E7F\u544A\u7CFB\u5217 ID").option("--i-confirm", "\u786E\u8BA4\u5DF2\u5411\u7528\u6237\u5217\u51FA\u5F85\u5220\u7CFB\u5217\uFF08ID+\u540D\u79F0\uFF09\u5E76\u83B7\u5F97\u660E\u786E\u540C\u610F", false).option("-t, --token <token>", "Auth Token").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(
123734
+ async (opts) => {
123735
+ await runAdCampaignDelete({
123736
+ token: opts.token,
123737
+ account: opts.account,
123738
+ id: opts.id,
123739
+ iConfirm: opts.iConfirm,
123740
+ verbose: opts.verbose
123741
+ });
123742
+ }
123743
+ );
122996
123744
  adCmd.command("adgroup-create").description("\u5728\u5E7F\u544A\u7CFB\u5217\u4E0B\u521B\u5EFA\u641C\u7D22\u5E7F\u544A\u7EC4").requiredOption("-a, --account <id>", "Google \u8D26\u6237 mediaCustomerId").requiredOption("--campaign-id <id>", "\u6240\u5C5E\u5E7F\u544A\u7CFB\u5217 ID").requiredOption("--campaign-name <name>", "\u6240\u5C5E\u5E7F\u544A\u7CFB\u5217\u540D\u79F0").requiredOption("--name <name>", "\u5E7F\u544A\u7EC4\u540D\u79F0").requiredOption(
122997
123745
  "--max-cpc <amount>",
122998
123746
  "\u6700\u9AD8\u5355\u6B21\u70B9\u51FB\u8D39\u7528\uFF0C\u4E3B\u5E01\u79CD\u91D1\u989D\uFF08\u5982 1.5 \u8868\u793A \xA51.50\uFF1BCLI \u5185\u90E8 \xD7100 \u5199\u5165\u300C\u5206\u300D\uFF09",
@@ -123197,12 +123945,15 @@ function register21(program2) {
123197
123945
  }
123198
123946
  );
123199
123947
  adCmd.command("campaign-validate").description(
123200
- "\u6821\u9A8C campaign-create JSON\uFF08\u8BCD\u9762\u89C4\u8303\u5316 + \u540E\u7AEF\u786C\u7EA6\u675F\uFF1B\u4E0D\u8C03\u7528 API\uFF09\n\n \u7528\u6CD5\uFF1A\n siluzan-tso ad campaign-validate --config-file ./campaign.json --json-out ./snap-campaign\n siluzan-tso ad campaign-validate --config-file ./campaign.json --write-normalized ./campaign.normalized.json"
123201
- ).requiredOption("--config-file <path>", "campaign-create JSON \u8DEF\u5F84").option("--write-normalized <path>", "\u5C06\u89C4\u8303\u5316\u540E\u7684 JSON \u5199\u5165\u8BE5\u8DEF\u5F84\uFF08\u5173\u952E\u8BCD\u8BCD\u9762\u5DF2\u4FEE\u6B63\uFF09").option("--json-out <path>", "\u843D\u76D8\u6821\u9A8C\u7ED3\u679C\uFF08\u542B lengthViolations\uFF09\u5E76\u66F4\u65B0 cli-manifest").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(
123948
+ "\u6821\u9A8C campaign-create JSON\uFF08\u8BCD\u9762\u89C4\u8303\u5316 + \u540E\u7AEF\u786C\u7EA6\u675F\uFF1B\u4E0D\u8C03\u7528 API\uFF09\n\n \u7528\u6CD5\uFF1A\n siluzan-tso ad campaign-validate --config-file ./campaign.json --json-out ./snap-campaign\n siluzan-tso ad campaign-validate --config-file ./campaign.json --write-normalized # \u539F\u5730\u8986\u76D6\n siluzan-tso ad campaign-validate --config-file ./campaign.json --write-normalized ./campaign.normalized.json"
123949
+ ).requiredOption("--config-file <path>", "campaign-create JSON \u8DEF\u5F84").option(
123950
+ "--write-normalized [path]",
123951
+ "\u5C06\u89C4\u8303\u5316\u540E\u7684 JSON \u5199\u5165\u8BE5\u8DEF\u5F84\uFF08\u5173\u952E\u8BCD\u8BCD\u9762\u5DF2\u4FEE\u6B63\uFF09\uFF1B\u4E0D\u5E26\u8DEF\u5F84\u65F6\u539F\u5730\u8986\u76D6 --config-file"
123952
+ ).option("--json-out <path>", "\u843D\u76D8\u6821\u9A8C\u7ED3\u679C\uFF08\u542B lengthViolations\uFF09\u5E76\u66F4\u65B0 cli-manifest").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(
123202
123953
  async (opts) => {
123203
123954
  await runAdCampaignValidate({
123204
123955
  configFile: opts.configFile,
123205
- writeNormalized: opts.writeNormalized,
123956
+ writeNormalized: resolveWriteNormalizedPath(opts.writeNormalized, opts.configFile),
123206
123957
  jsonOut: opts.jsonOut,
123207
123958
  verbose: opts.verbose
123208
123959
  });
@@ -123228,12 +123979,15 @@ function register21(program2) {
123228
123979
  }
123229
123980
  );
123230
123981
  adCmd.command("pmax-validate").description(
123231
- "\u6821\u9A8C pmax-create JSON\uFF08PMax \u4E13\u7528\uFF1B\u4E0D\u8C03\u7528 API\uFF09\n\n \u7528\u6CD5\uFF1A\n siluzan-tso ad pmax-validate --config-file ./pmax.json --json-out ./snap-pmax\n siluzan-tso ad pmax-validate --config-file ./pmax.json --write-normalized ./pmax.normalized.json"
123232
- ).requiredOption("--config-file <path>", "pmax-create JSON \u8DEF\u5F84").option("--write-normalized <path>", "\u5C06 JSON \u5199\u5165\u8BE5\u8DEF\u5F84\uFF08\u4FDD\u7559 _ \u6CE8\u89E3\u952E\uFF09").option("--json-out <path>", "\u843D\u76D8\u6821\u9A8C\u7ED3\u679C\u5E76\u66F4\u65B0 cli-manifest").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(
123982
+ "\u6821\u9A8C pmax-create JSON\uFF08PMax \u4E13\u7528\uFF1B\u4E0D\u8C03\u7528 API\uFF09\n\n \u7528\u6CD5\uFF1A\n siluzan-tso ad pmax-validate --config-file ./pmax.json --json-out ./snap-pmax\n siluzan-tso ad pmax-validate --config-file ./pmax.json --write-normalized # \u539F\u5730\u8986\u76D6\n siluzan-tso ad pmax-validate --config-file ./pmax.json --write-normalized ./pmax.normalized.json"
123983
+ ).requiredOption("--config-file <path>", "pmax-create JSON \u8DEF\u5F84").option(
123984
+ "--write-normalized [path]",
123985
+ "\u5C06 JSON \u5199\u5165\u8BE5\u8DEF\u5F84\uFF08\u4FDD\u7559 _ \u6CE8\u89E3\u952E\uFF09\uFF1B\u4E0D\u5E26\u8DEF\u5F84\u65F6\u539F\u5730\u8986\u76D6 --config-file"
123986
+ ).option("--json-out <path>", "\u843D\u76D8\u6821\u9A8C\u7ED3\u679C\u5E76\u66F4\u65B0 cli-manifest").option("--verbose", "\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F", false).action(
123233
123987
  async (opts) => {
123234
123988
  await runAdPmaxValidate({
123235
123989
  configFile: opts.configFile,
123236
- writeNormalized: opts.writeNormalized,
123990
+ writeNormalized: resolveWriteNormalizedPath(opts.writeNormalized, opts.configFile),
123237
123991
  jsonOut: opts.jsonOut,
123238
123992
  verbose: opts.verbose
123239
123993
  });
@@ -123290,7 +124044,10 @@ function register21(program2) {
123290
124044
  addPmaxJsonOptions(
123291
124045
  adCmd.command("pmax-edit").description(
123292
124046
  "\u66F4\u65B0 PMax \u6D3B\u52A8\uFF08PATCH\uFF1B\u52FF\u7528 ad campaign-edit\uFF09\n --patch-file \u89C1 assets/pmax-patch-campaign-template.json"
123293
- ).requiredOption("-a, --account <id>", "Google \u5A92\u4F53\u5BA2\u6237 ID").requiredOption("--campaign-id <id>", "\u6D3B\u52A8 ID").option("--patch-file <path>", "PATCH JSON\uFF08budget/targetCpa \u586B\u5143\uFF09").option("--status <status>", "2|3|4 \u6216 Enabled|Paused|Removed").option("--budget <yuan>", "\u65E5\u9884\u7B97\uFF08\u5143\uFF09\uFF1B\u987B\u914D\u5408 --budget-id").option("--budget-id <id>", "budgetId\uFF08\u6765\u81EA pmax-get\uFF09").option("--bidding <strategy>", "\u51FA\u4EF7\u7B56\u7565\uFF0C\u5982 MAXIMIZE_CONVERSIONS").option("--target-cpa <yuan>", "\u76EE\u6807 CPA\uFF08\u5143\uFF09").option("--target-roas <n>", "\u76EE\u6807 ROAS").option("--url-expansion-opt-out", "\u5173\u95ED\u6700\u7EC8\u5230\u8FBE\u7F51\u5740\u6269\u5C55").option("-t, --token <token>", "Auth Token")
124047
+ ).requiredOption("-a, --account <id>", "Google \u5A92\u4F53\u5BA2\u6237 ID").requiredOption("--campaign-id <id>", "\u6D3B\u52A8 ID").option("--patch-file <path>", "PATCH JSON\uFF08budget/targetCpa \u586B\u5143\uFF09").option(
124048
+ "--status <status>",
124049
+ "2|3|4 \u6216 Enabled|Paused|Removed\uFF08Removed \u4E0D\u53EF\u6062\u590D\uFF0C\u987B\u7528\u6237\u540C\u610F\u540E\u52A0 --i-confirm\uFF09"
124050
+ ).option("--i-confirm", "\u72B6\u6001\u6539 Removed \u65F6\u5FC5\u586B\uFF1A\u5DF2\u83B7\u7528\u6237\u660E\u786E\u540C\u610F", false).option("--budget <yuan>", "\u65E5\u9884\u7B97\uFF08\u5143\uFF09\uFF1B\u987B\u914D\u5408 --budget-id").option("--budget-id <id>", "budgetId\uFF08\u6765\u81EA pmax-get\uFF09").option("--bidding <strategy>", "\u51FA\u4EF7\u7B56\u7565\uFF0C\u5982 MAXIMIZE_CONVERSIONS").option("--target-cpa <yuan>", "\u76EE\u6807 CPA\uFF08\u5143\uFF09").option("--target-roas <n>", "\u76EE\u6807 ROAS").option("--url-expansion-opt-out", "\u5173\u95ED\u6700\u7EC8\u5230\u8FBE\u7F51\u5740\u6269\u5C55").option("-t, --token <token>", "Auth Token")
123294
124051
  ).action(
123295
124052
  async (opts) => {
123296
124053
  await runAdPmaxEdit(opts);
@@ -127583,21 +128340,6 @@ init_media_customer_id();
127583
128340
 
127584
128341
  // src/commands/account-manage/google-mcc.ts
127585
128342
  init_auth();
127586
-
127587
- // src/utils/destructive-confirm.ts
127588
- function ensureIConfirm(opts) {
127589
- if (opts.iConfirm) return;
127590
- console.error(
127591
- `
127592
- \u274C \u62D2\u7EDD\u6267\u884C\uFF1A${opts.actionLabel} \u4E3A\u7834\u574F\u6027\u64CD\u4F5C\uFF0C\u987B\u5148\u5411\u7528\u6237\u8BF4\u660E\u98CE\u9669\u5E76\u83B7\u5F97\u660E\u786E\u786E\u8BA4\u3002
127593
- \u7528\u6237\u540C\u610F\u540E\uFF0C\u8BF7\u9644\u52A0 --i-confirm\uFF0C\u5E76\u4F7F\u7528 --commit "\u2026" \u8BF4\u660E\u539F\u56E0\u540E\u518D\u6267\u884C\u3002
127594
- \u793A\u4F8B\uFF1Asiluzan-tso \u2026 --i-confirm --commit "\u7528\u6237\u786E\u8BA4\u89E3\u7ED1 entityId=\u2026"
127595
- `
127596
- );
127597
- process.exit(1);
127598
- }
127599
-
127600
- // src/commands/account-manage/google-mcc.ts
127601
128343
  init_cli_json_snapshot();
127602
128344
  function parseMccManagerIds(input) {
127603
128345
  const normalized = input.replace(/[,,;、]/g, ";");
@@ -131590,7 +132332,7 @@ function readJsonFile(filePath) {
131590
132332
  }
131591
132333
  });
131592
132334
  }
131593
- function asRecord4(value) {
132335
+ function asRecord5(value) {
131594
132336
  if (value && typeof value === "object" && !Array.isArray(value)) {
131595
132337
  return value;
131596
132338
  }
@@ -131616,10 +132358,10 @@ function injectReportData(html, payload) {
131616
132358
  async function runWebsiteDiagnosisRender(opts) {
131617
132359
  const dataPath = path20.resolve(opts.dataFile);
131618
132360
  const dataRaw = await readJsonFile(dataPath);
131619
- let data = asRecord4(dataRaw);
132361
+ let data = asRecord5(dataRaw);
131620
132362
  if (opts.collectFile) {
131621
132363
  const collectRaw = await readJsonFile(path20.resolve(opts.collectFile));
131622
- data = mergeCollectLighthouse(data, asRecord4(collectRaw));
132364
+ data = mergeCollectLighthouse(data, asRecord5(collectRaw));
131623
132365
  }
131624
132366
  const templatePath = websiteDiagnosisReportTemplatePath();
131625
132367
  let html;
@@ -132277,7 +133019,7 @@ function formatMarketReportContentErrors(result) {
132277
133019
  }
132278
133020
 
132279
133021
  // src/commands/market-analysis/render-report.ts
132280
- function asRecord5(value) {
133022
+ function asRecord6(value) {
132281
133023
  if (value && typeof value === "object" && !Array.isArray(value)) {
132282
133024
  return value;
132283
133025
  }
@@ -132307,7 +133049,7 @@ async function runMarketAnalysisRender(opts) {
132307
133049
  }
132308
133050
  let html;
132309
133051
  try {
132310
- html = resolveMarketAnalysisHtml(asRecord5(dataRaw));
133052
+ html = resolveMarketAnalysisHtml(asRecord6(dataRaw));
132311
133053
  } catch (err) {
132312
133054
  const message = err instanceof Error ? err.message : String(err);
132313
133055
  console.error(`
@@ -132319,7 +133061,7 @@ async function runMarketAnalysisRender(opts) {
132319
133061
  console.error("\n\u274C \u62A5\u544A HTML \u5185\u5BB9\u4E3A\u7A7A\n");
132320
133062
  process.exit(1);
132321
133063
  }
132322
- const reportData = asRecord5(dataRaw);
133064
+ const reportData = asRecord6(dataRaw);
132323
133065
  const contentCheck = validateMarketReportContent(html, validationContextFromReport(reportData));
132324
133066
  if (!contentCheck.ok) {
132325
133067
  console.error(`
@@ -133327,14 +134069,14 @@ function buildGoogleAdsDiagnosisCollectPayload(opts) {
133327
134069
  }
133328
134070
 
133329
134071
  // src/commands/google-ads-diagnosis/collect-digest.ts
133330
- function asRecord6(value) {
134072
+ function asRecord7(value) {
133331
134073
  if (value && typeof value === "object" && !Array.isArray(value)) {
133332
134074
  return value;
133333
134075
  }
133334
134076
  return null;
133335
134077
  }
133336
134078
  function fieldsOfFirstRow(rows) {
133337
- const first = asRecord6(rows[0]);
134079
+ const first = asRecord7(rows[0]);
133338
134080
  return first ? Object.keys(first) : [];
133339
134081
  }
133340
134082
  function describeSectionShapes(reportData) {
@@ -133344,7 +134086,7 @@ function describeSectionShapes(reportData) {
133344
134086
  if (Array.isArray(value)) {
133345
134087
  return { section, itemCount: value.length, fields: fieldsOfFirstRow(value), needsNarrative };
133346
134088
  }
133347
- const record2 = asRecord6(value);
134089
+ const record2 = asRecord7(value);
133348
134090
  if (!record2) {
133349
134091
  return { section, itemCount: null, fields: [], needsNarrative };
133350
134092
  }
@@ -133413,21 +134155,21 @@ function buildCollectDigest(reportData, meta) {
133413
134155
  }
133414
134156
 
133415
134157
  // src/commands/google-ads-diagnosis/collect-integrity.ts
133416
- function asRecord7(value) {
134158
+ function asRecord8(value) {
133417
134159
  if (value && typeof value === "object" && !Array.isArray(value)) {
133418
134160
  return value;
133419
134161
  }
133420
134162
  return null;
133421
134163
  }
133422
134164
  function itemCount(block) {
133423
- const items3 = asRecord7(block)?.items;
134165
+ const items3 = asRecord8(block)?.items;
133424
134166
  return Array.isArray(items3) ? items3.length : 0;
133425
134167
  }
133426
134168
  function getCollectIntegrityWarnings(reportData) {
133427
134169
  const warnings = [];
133428
134170
  const kwItems = itemCount(reportData.keywords);
133429
134171
  const fullKwItems = itemCount(reportData.fullKeywords);
133430
- const keywordCount = Number(asRecord7(reportData.structure)?.keywordCount ?? 0);
134172
+ const keywordCount = Number(asRecord8(reportData.structure)?.keywordCount ?? 0);
133431
134173
  if (kwItems === 0 && fullKwItems > 0) {
133432
134174
  warnings.push(
133433
134175
  `keywords.items \u5BF9\u6BD4\u8868\u4E3A\u7A7A\uFF0C\u4F46 fullKeywords.items \u6709 ${fullKwItems} \u884C\uFF1B\u8BF7\u786E\u8BA4 collect \u662F\u5426\u6210\u529F\u62C9\u53D6\u4E0A\u4E00\u5468\u671F keywords \u5FEB\u7167\uFF08\u73AF\u6BD4\u5217\u4F9D\u8D56 prev \u5468\u671F JSON\uFF09\u3002`
@@ -133438,7 +134180,7 @@ function getCollectIntegrityWarnings(reportData) {
133438
134180
  );
133439
134181
  }
133440
134182
  const campaignItems = itemCount(reportData.campaigns);
133441
- const campaignCount = Number(asRecord7(reportData.structure)?.campaignCount ?? 0);
134183
+ const campaignCount = Number(asRecord8(reportData.structure)?.campaignCount ?? 0);
133442
134184
  if (campaignItems === 0 && campaignCount > 0) {
133443
134185
  warnings.push(
133444
134186
  `campaigns.items \u5BF9\u6BD4\u8868\u4E3A\u7A7A\uFF0C\u4F46 structure.campaignCount=${campaignCount}\uFF1B\u8BF7\u786E\u8BA4\u4E0A\u4E00\u5468\u671F campaigns \u5FEB\u7167\u662F\u5426\u62C9\u53D6\u6210\u529F\u3002`
@@ -133496,7 +134238,7 @@ function invokeGoogleAnalysisCli(opts) {
133496
134238
 
133497
134239
  // src/commands/google-ads-diagnosis/write-draft.ts
133498
134240
  import fs20 from "fs/promises";
133499
- function asRecord8(value) {
134241
+ function asRecord9(value) {
133500
134242
  if (value && typeof value === "object" && !Array.isArray(value)) {
133501
134243
  return value;
133502
134244
  }
@@ -133505,7 +134247,7 @@ function asRecord8(value) {
133505
134247
  function valueAtPath(data, keys) {
133506
134248
  let cursor = data;
133507
134249
  for (const key of keys) {
133508
- const record2 = asRecord8(cursor);
134250
+ const record2 = asRecord9(cursor);
133509
134251
  if (!record2) return void 0;
133510
134252
  cursor = record2[key];
133511
134253
  }
@@ -133524,7 +134266,7 @@ function hasAgentNarrative(data) {
133524
134266
  async function writeDiagnosisDraft(opts) {
133525
134267
  try {
133526
134268
  const existing = JSON.parse(await fs20.readFile(opts.draftPath, "utf8"));
133527
- const record2 = asRecord8(existing);
134269
+ const record2 = asRecord9(existing);
133528
134270
  if (record2 && hasAgentNarrative(record2)) return "skipped-existing-narrative";
133529
134271
  } catch {
133530
134272
  }
@@ -133714,7 +134456,7 @@ import fs22 from "fs/promises";
133714
134456
  import path26 from "path";
133715
134457
 
133716
134458
  // src/commands/google-ads-diagnosis/report-content.ts
133717
- function asRecord9(value) {
134459
+ function asRecord10(value) {
133718
134460
  if (value && typeof value === "object" && !Array.isArray(value)) {
133719
134461
  return value;
133720
134462
  }
@@ -133723,7 +134465,7 @@ function asRecord9(value) {
133723
134465
  function getNestedValue(root, path55) {
133724
134466
  let cur = root;
133725
134467
  for (const key of path55) {
133726
- const rec = asRecord9(cur);
134468
+ const rec = asRecord10(cur);
133727
134469
  if (!rec) return void 0;
133728
134470
  cur = rec[key];
133729
134471
  }
@@ -133740,7 +134482,7 @@ function validateBudgetCompetitivenessStrategies(data) {
133740
134482
  }
133741
134483
  const warnings = [];
133742
134484
  for (let i = 0; i < items3.length; i++) {
133743
- const row = asRecord9(items3[i]);
134485
+ const row = asRecord10(items3[i]);
133744
134486
  const name2 = String(row?.name ?? row?.metric ?? i);
133745
134487
  if (!hasNarrativeContent(row?.strategy)) {
133746
134488
  warnings.push(`budgetCompetitiveness[${name2}].strategy \u4E3A\u7A7A\uFF08\u987B\u7531 Agent \u586B\u5199\uFF09`);
@@ -133749,13 +134491,13 @@ function validateBudgetCompetitivenessStrategies(data) {
133749
134491
  return warnings;
133750
134492
  }
133751
134493
  function validateNewFeatureRecommendations(data) {
133752
- const nf = asRecord9(data.newFeatures);
134494
+ const nf = asRecord10(data.newFeatures);
133753
134495
  if (!nf) return [];
133754
134496
  const items3 = nf.items;
133755
134497
  if (!Array.isArray(items3)) return [];
133756
134498
  const warnings = [];
133757
134499
  for (let i = 0; i < items3.length; i++) {
133758
- const row = asRecord9(items3[i]);
134500
+ const row = asRecord10(items3[i]);
133759
134501
  const name2 = String(row?.strategyName ?? row?.feature ?? row?.strategy ?? i);
133760
134502
  if (!hasNarrativeContent(row?.optimizerRecommendation)) {
133761
134503
  warnings.push(`newFeatures.items[${name2}].optimizerRecommendation \u4E3A\u7A7A\uFF08\u987B\u7531 Agent \u586B\u5199\uFF09`);
@@ -133764,13 +134506,13 @@ function validateNewFeatureRecommendations(data) {
133764
134506
  return warnings;
133765
134507
  }
133766
134508
  function validateAdCreativeItemSuggestions(data) {
133767
- const creative = asRecord9(data.adCreativeOptimization);
134509
+ const creative = asRecord10(data.adCreativeOptimization);
133768
134510
  if (!creative) return [];
133769
134511
  const items3 = creative.items;
133770
134512
  if (!Array.isArray(items3) || items3.length === 0) return [];
133771
134513
  const warnings = [];
133772
134514
  for (let i = 0; i < items3.length; i++) {
133773
- const row = asRecord9(items3[i]);
134515
+ const row = asRecord10(items3[i]);
133774
134516
  const title = String(row?.adTitle ?? i);
133775
134517
  if (!hasNarrativeContent(row?.suggestion ?? row?.suggestions)) {
133776
134518
  warnings.push(`adCreativeOptimization.items[${title}].suggestion \u4E3A\u7A7A\uFF08\u987B\u7531 Agent \u586B\u5199\uFF09`);
@@ -133781,7 +134523,7 @@ function validateAdCreativeItemSuggestions(data) {
133781
134523
  function validateGoogleAdsDiagnosisContent(data) {
133782
134524
  const missingKeys = GOOGLE_ADS_DIAGNOSIS_TOP_LEVEL_KEYS.filter((key) => data[key] === void 0);
133783
134525
  const warnings = [];
133784
- const accountInfo = asRecord9(data.accountInfo);
134526
+ const accountInfo = asRecord10(data.accountInfo);
133785
134527
  if (accountInfo && !accountInfo.companyName && !accountInfo.period) {
133786
134528
  warnings.push("accountInfo \u7F3A\u5C11 companyName \u4E0E period\uFF0C\u9875\u7709\u53EF\u80FD\u4E3A\u7A7A");
133787
134529
  }
@@ -133829,7 +134571,7 @@ var GOOGLE_ADS_DIAGNOSIS_RESTORE_ITEM_MODULES = [
133829
134571
  GOOGLE_ADS_DIAGNOSIS_BIDDING_STRATEGY_MODULE,
133830
134572
  GOOGLE_ADS_DIAGNOSIS_NEW_FEATURES_MODULE
133831
134573
  ];
133832
- function asRecord10(value) {
134574
+ function asRecord11(value) {
133833
134575
  if (value && typeof value === "object" && !Array.isArray(value)) {
133834
134576
  return value;
133835
134577
  }
@@ -133840,7 +134582,7 @@ function isValidRateChange(value) {
133840
134582
  return typeof value === "number" && Number.isFinite(value);
133841
134583
  }
133842
134584
  function isComparisonTableRowValid(row) {
133843
- const rec = asRecord10(row);
134585
+ const rec = asRecord11(row);
133844
134586
  if (!rec) return false;
133845
134587
  if (!String(rec.title ?? "").trim()) return false;
133846
134588
  if (!Number.isFinite(Number(rec.currentCost))) return false;
@@ -133852,12 +134594,12 @@ function isComparisonTableRowValid(row) {
133852
134594
  return true;
133853
134595
  }
133854
134596
  function isNewFeatureRowValid(row) {
133855
- const rec = asRecord10(row);
134597
+ const rec = asRecord11(row);
133856
134598
  if (!rec) return false;
133857
134599
  return Boolean(String(rec.strategyName ?? rec.feature ?? rec.strategy ?? "").trim());
133858
134600
  }
133859
134601
  function isBiddingStrategyRowValid(row) {
133860
- const rec = asRecord10(row);
134602
+ const rec = asRecord11(row);
133861
134603
  if (!rec) return false;
133862
134604
  if (!String(rec.campaignName ?? "").trim()) return false;
133863
134605
  if (!Number.isFinite(Number(rec.duration)) || Number(rec.duration) <= 0) return false;
@@ -133895,11 +134637,11 @@ function getFactItemsErrors(data) {
133895
134637
  for (const mod of GOOGLE_ADS_DIAGNOSIS_RESTORE_ITEM_MODULES) {
133896
134638
  const validator = MODULE_ITEM_VALIDATORS[mod];
133897
134639
  const hint = MODULE_ITEM_ERROR_HINT[mod];
133898
- const block = asRecord10(data[mod]);
134640
+ const block = asRecord11(data[mod]);
133899
134641
  const items3 = block?.items;
133900
134642
  if (!Array.isArray(items3) || items3.length === 0) {
133901
134643
  if (mod === "keywords") {
133902
- const fullKw = asRecord10(data.fullKeywords)?.items;
134644
+ const fullKw = asRecord11(data.fullKeywords)?.items;
133903
134645
  if (Array.isArray(fullKw) && fullKw.length > 0) {
133904
134646
  errors.push(
133905
134647
  "keywords.items \u4E3A\u7A7A\u4F46 fullKeywords.items \u6709\u6570\u636E\uFF1B\u8BF7\u4FDD\u7559\u540C\u76EE\u5F55 google-ads-diagnosis-collect.json \u540E\u91CD\u65B0 render\uFF08\u4F1A\u81EA\u52A8\u6062\u590D\u5BF9\u6BD4\u8868\uFF09"
@@ -133924,15 +134666,15 @@ var LANDING_PAGE_SPEED_KEYS = [
133924
134666
  "speedIndex"
133925
134667
  ];
133926
134668
  function isLandingPageSpeedValid(value) {
133927
- const rec = asRecord10(value);
134669
+ const rec = asRecord11(value);
133928
134670
  if (!rec) return false;
133929
134671
  return LANDING_PAGE_SPEED_KEYS.every(
133930
134672
  (key) => typeof rec[key] === "number" && Number.isFinite(rec[key])
133931
134673
  );
133932
134674
  }
133933
134675
  function restoreLandingPageSpeedFromCollect(finalData, collectReportData) {
133934
- const finalBlock = asRecord10(finalData[GOOGLE_ADS_DIAGNOSIS_LANDING_PAGE_MODULE]);
133935
- const collectBlock = asRecord10(collectReportData[GOOGLE_ADS_DIAGNOSIS_LANDING_PAGE_MODULE]);
134676
+ const finalBlock = asRecord11(finalData[GOOGLE_ADS_DIAGNOSIS_LANDING_PAGE_MODULE]);
134677
+ const collectBlock = asRecord11(collectReportData[GOOGLE_ADS_DIAGNOSIS_LANDING_PAGE_MODULE]);
133936
134678
  if (!collectBlock) return { data: finalData, restored: false };
133937
134679
  const needsDesktop = !isLandingPageSpeedValid(finalBlock?.desktop) && isLandingPageSpeedValid(collectBlock.desktop);
133938
134680
  const needsMobile = !isLandingPageSpeedValid(finalBlock?.mobile) && isLandingPageSpeedValid(collectBlock.mobile);
@@ -133955,8 +134697,8 @@ function mergeComparisonItemsFromCollect(finalData, collectReportData) {
133955
134697
  const restoredModules = [];
133956
134698
  for (const mod of GOOGLE_ADS_DIAGNOSIS_RESTORE_ITEM_MODULES) {
133957
134699
  const validator = MODULE_ITEM_VALIDATORS[mod];
133958
- const finalBlock = asRecord10(data[mod]);
133959
- const collectBlock = asRecord10(collectReportData[mod]);
134700
+ const finalBlock = asRecord11(data[mod]);
134701
+ const collectBlock = asRecord11(collectReportData[mod]);
133960
134702
  const finalItems = finalBlock?.items;
133961
134703
  const collectItems = collectBlock?.items;
133962
134704
  if (!Array.isArray(collectItems) || collectItems.length === 0) continue;
@@ -133972,7 +134714,7 @@ function mergeComparisonItemsFromCollect(finalData, collectReportData) {
133972
134714
  }
133973
134715
 
133974
134716
  // src/commands/google-ads-diagnosis/narrative-consistency-check.ts
133975
- function asRecord11(value) {
134717
+ function asRecord12(value) {
133976
134718
  if (value && typeof value === "object" && !Array.isArray(value)) {
133977
134719
  return value;
133978
134720
  }
@@ -133983,14 +134725,14 @@ function normalizeSuggestionText(value) {
133983
134725
  }
133984
134726
  function collectNarrativeTexts(data) {
133985
134727
  const texts = [];
133986
- const summary = asRecord11(data.summary);
134728
+ const summary = asRecord12(data.summary);
133987
134729
  if (Array.isArray(summary?.keyIssues)) {
133988
134730
  for (const item of summary.keyIssues) texts.push(String(item ?? ""));
133989
134731
  }
133990
- const overview = asRecord11(data.diagnosisOverview);
134732
+ const overview = asRecord12(data.diagnosisOverview);
133991
134733
  if (Array.isArray(overview?.disadvantages)) {
133992
134734
  for (const item of overview.disadvantages) {
133993
- const rec = asRecord11(item);
134735
+ const rec = asRecord12(item);
133994
134736
  if (rec) {
133995
134737
  texts.push(String(rec.title ?? ""), String(rec.description ?? ""));
133996
134738
  } else {
@@ -134001,16 +134743,16 @@ function collectNarrativeTexts(data) {
134001
134743
  return texts.filter((t) => t.trim().length > 0);
134002
134744
  }
134003
134745
  function newFeatureAccountStatus(data, strategy) {
134004
- const nf = asRecord11(data.newFeatures);
134746
+ const nf = asRecord12(data.newFeatures);
134005
134747
  const items3 = nf?.items;
134006
134748
  if (!Array.isArray(items3)) return null;
134007
- const row = items3.find((it) => asRecord11(it)?.strategy === strategy);
134008
- const rec = asRecord11(row);
134749
+ const row = items3.find((it) => asRecord12(it)?.strategy === strategy);
134750
+ const rec = asRecord12(row);
134009
134751
  if (!rec || typeof rec.accountStatus !== "boolean") return null;
134010
134752
  return rec.accountStatus;
134011
134753
  }
134012
134754
  function goldAccountFlag(data, key) {
134013
- const gold = asRecord11(data.goldAccount);
134755
+ const gold = asRecord12(data.goldAccount);
134014
134756
  const value = gold?.[key];
134015
134757
  return typeof value === "boolean" ? value : null;
134016
134758
  }
@@ -134055,7 +134797,7 @@ function getRepetitiveNarrativeErrors(data) {
134055
134797
  const errors = [];
134056
134798
  const budget = data.budgetCompetitiveness;
134057
134799
  if (Array.isArray(budget) && budget.length >= 3) {
134058
- const strategies = budget.map((row) => normalizeSuggestionText(asRecord11(row)?.strategy)).filter((s) => s.length > 0);
134800
+ const strategies = budget.map((row) => normalizeSuggestionText(asRecord12(row)?.strategy)).filter((s) => s.length > 0);
134059
134801
  const dup = findIdenticalTexts(strategies, 3);
134060
134802
  if (dup) {
134061
134803
  errors.push(
@@ -134063,10 +134805,10 @@ function getRepetitiveNarrativeErrors(data) {
134063
134805
  );
134064
134806
  }
134065
134807
  }
134066
- const creative = asRecord11(data.adCreativeOptimization);
134808
+ const creative = asRecord12(data.adCreativeOptimization);
134067
134809
  const creativeItems = creative?.items;
134068
134810
  if (Array.isArray(creativeItems) && creativeItems.length >= 3) {
134069
- const suggestions = creativeItems.map((row) => normalizeSuggestionText(asRecord11(row)?.suggestion)).filter((s) => s.length > 0);
134811
+ const suggestions = creativeItems.map((row) => normalizeSuggestionText(asRecord12(row)?.suggestion)).filter((s) => s.length > 0);
134070
134812
  const dup = findIdenticalTexts(suggestions, 3);
134071
134813
  if (dup) {
134072
134814
  errors.push(
@@ -134077,7 +134819,7 @@ function getRepetitiveNarrativeErrors(data) {
134077
134819
  return errors;
134078
134820
  }
134079
134821
  function getLandingPageTopicErrors(data) {
134080
- const lp = asRecord11(data.landingPageAnalysis);
134822
+ const lp = asRecord12(data.landingPageAnalysis);
134081
134823
  if (!lp) return [];
134082
134824
  const analysis = String(lp.analysis ?? "");
134083
134825
  if (!analysis.trim()) return [];
@@ -134107,7 +134849,7 @@ function getNarrativeConsistencyErrors(data) {
134107
134849
  }
134108
134850
 
134109
134851
  // src/commands/google-ads-diagnosis/render-report.ts
134110
- function asRecord12(value) {
134852
+ function asRecord13(value) {
134111
134853
  if (value && typeof value === "object" && !Array.isArray(value)) {
134112
134854
  return value;
134113
134855
  }
@@ -134116,8 +134858,8 @@ function asRecord12(value) {
134116
134858
  async function tryLoadCollectReportData(collectPath) {
134117
134859
  try {
134118
134860
  const raw = JSON.parse(await fs22.readFile(collectPath, "utf8"));
134119
- const root = asRecord12(raw);
134120
- const reportData = asRecord12(root?.reportData);
134861
+ const root = asRecord13(raw);
134862
+ const reportData = asRecord13(root?.reportData);
134121
134863
  return reportData ?? root;
134122
134864
  } catch {
134123
134865
  return null;
@@ -134134,7 +134876,7 @@ async function runGoogleAdsDiagnosisRender(opts) {
134134
134876
  `);
134135
134877
  process.exit(1);
134136
134878
  }
134137
- let data = asRecord12(dataRaw);
134879
+ let data = asRecord13(dataRaw);
134138
134880
  if (!opts.noMergeCollect) {
134139
134881
  const collectPath = path26.resolve(
134140
134882
  opts.collectFile ?? path26.join(path26.dirname(dataPath), GOOGLE_ADS_DIAGNOSIS_COLLECT_BASENAME)
@@ -135464,26 +136206,26 @@ import fs26 from "fs/promises";
135464
136206
  import path31 from "path";
135465
136207
 
135466
136208
  // src/commands/google-quarterly/report-content.ts
135467
- function asRecord13(value) {
136209
+ function asRecord14(value) {
135468
136210
  return value && typeof value === "object" && !Array.isArray(value) ? value : null;
135469
136211
  }
135470
136212
  function asStringArray(value) {
135471
136213
  return Array.isArray(value) ? value.map((x) => String(x).trim()).filter(Boolean) : [];
135472
136214
  }
135473
136215
  function validateQuarterlyNarrative(data) {
135474
- const root = asRecord13(data);
135475
- const narrative = asRecord13(root?.narrative);
136216
+ const root = asRecord14(data);
136217
+ const narrative = asRecord14(root?.narrative);
135476
136218
  const missing = [];
135477
136219
  if (!narrative) {
135478
136220
  return { ok: false, missing: ["narrative"] };
135479
136221
  }
135480
136222
  if (asStringArray(narrative.executiveSummary).length < 1) missing.push("narrative.executiveSummary");
135481
- const sections = asRecord13(narrative.sections);
136223
+ const sections = asRecord14(narrative.sections);
135482
136224
  for (const key of ["efficiency", "adType", "region", "summary"]) {
135483
- const block = asRecord13(sections?.[key]);
136225
+ const block = asRecord14(sections?.[key]);
135484
136226
  if (asStringArray(block?.analysis).length < 1) missing.push(`narrative.sections.${key}.analysis`);
135485
136227
  }
135486
- const plan = asRecord13(narrative.plan);
136228
+ const plan = asRecord14(narrative.plan);
135487
136229
  if (asStringArray(plan?.analysis ?? plan?.goals).length < 1 && !String(plan?.text ?? "").trim()) {
135488
136230
  missing.push("narrative.plan");
135489
136231
  }
@@ -135496,8 +136238,8 @@ function mergeCollectFacts(agentData, collect) {
135496
136238
  ...facts,
135497
136239
  narrative: agentData.narrative ?? collect.narrative,
135498
136240
  meta: {
135499
- ...asRecord13(collect.meta) ?? {},
135500
- ...asRecord13(agentData.meta) ?? {}
136241
+ ...asRecord14(collect.meta) ?? {},
136242
+ ...asRecord14(agentData.meta) ?? {}
135501
136243
  }
135502
136244
  };
135503
136245
  }
@@ -135509,7 +136251,7 @@ import { fileURLToPath as fileURLToPath8 } from "url";
135509
136251
  var TSO_CLI_ROOT = path30.join(path30.dirname(fileURLToPath8(import.meta.url)), "../..");
135510
136252
 
135511
136253
  // src/commands/google-quarterly/render-report.ts
135512
- function asRecord14(value) {
136254
+ function asRecord15(value) {
135513
136255
  if (value && typeof value === "object" && !Array.isArray(value)) {
135514
136256
  return value;
135515
136257
  }
@@ -135538,7 +136280,7 @@ async function runGoogleQuarterlyRender(opts) {
135538
136280
  `);
135539
136281
  process.exit(1);
135540
136282
  }
135541
- const merged = mergeCollectFacts(asRecord14(agentRaw), asRecord14(collectRaw));
136283
+ const merged = mergeCollectFacts(asRecord15(agentRaw), asRecord15(collectRaw));
135542
136284
  const check = validateQuarterlyNarrative(merged);
135543
136285
  if (!check.ok && !opts.lenient) {
135544
136286
  console.error("\n\u274C narrative \u4E0D\u5B8C\u6574\uFF0C\u62D2\u7EDD\u51FA HTML\uFF1A\n");
@@ -135702,7 +136444,7 @@ import * as fs33 from "fs/promises";
135702
136444
  import * as path40 from "path";
135703
136445
 
135704
136446
  // src/commands/facebook-analysis/report-metrics.ts
135705
- function asRecord20(value) {
136447
+ function asRecord21(value) {
135706
136448
  if (value && typeof value === "object" && !Array.isArray(value)) {
135707
136449
  return value;
135708
136450
  }
@@ -135839,7 +136581,7 @@ function localizeFacebookReportLabels(payload) {
135839
136581
  for (const rows of Object.values(tables)) {
135840
136582
  if (!Array.isArray(rows)) continue;
135841
136583
  for (const row of rows) {
135842
- localizeMetricLabels(asRecord20(row));
136584
+ localizeMetricLabels(asRecord21(row));
135843
136585
  }
135844
136586
  }
135845
136587
  return payload;
@@ -135872,7 +136614,7 @@ async function readManifest3(snapshotDir) {
135872
136614
  async function loadSectionFile3(snapshotDir, file) {
135873
136615
  try {
135874
136616
  const raw = await fs33.readFile(path40.join(snapshotDir, file), "utf8");
135875
- return asRecord20(JSON.parse(raw));
136617
+ return asRecord21(JSON.parse(raw));
135876
136618
  } catch {
135877
136619
  return null;
135878
136620
  }
@@ -135928,7 +136670,7 @@ async function mergeFacebookSnapshotIntoReport(payload, snapshotDir) {
135928
136670
  if (data) sectionMap.set(art.section, data);
135929
136671
  }
135930
136672
  const overview = sectionMap.get("overview");
135931
- const current = asRecord20(overview?.currentPeriod);
136673
+ const current = asRecord21(overview?.currentPeriod);
135932
136674
  const accountName = typeof overview?.accountName === "string" ? overview.accountName : void 0;
135933
136675
  const accountId = manifest.accountId ?? (typeof overview?.accountId === "string" ? overview.accountId : void 0);
135934
136676
  const kpis = { ...payload.kpis ?? {} };
@@ -136065,7 +136807,7 @@ function writeSimpleXlsx(filePath, sheets, opts = {}) {
136065
136807
  }
136066
136808
 
136067
136809
  // src/commands/facebook-analysis/render-excel.ts
136068
- function asRecord21(value) {
136810
+ function asRecord22(value) {
136069
136811
  if (value && typeof value === "object" && !Array.isArray(value)) {
136070
136812
  return value;
136071
136813
  }
@@ -136113,8 +136855,8 @@ function bullets(value) {
136113
136855
  return asArray3(value).map((item) => typeof item === "string" ? item.trim() : "").filter(Boolean);
136114
136856
  }
136115
136857
  function insightLines(section) {
136116
- const rec = asRecord21(section);
136117
- const insight = asRecord21(rec?.insight) ?? rec;
136858
+ const rec = asRecord22(section);
136859
+ const insight = asRecord22(rec?.insight) ?? rec;
136118
136860
  return [...bullets(insight?.analysis), ...bullets(insight?.advice)];
136119
136861
  }
136120
136862
  function numberedSection(index, title, lines) {
@@ -136123,15 +136865,15 @@ function numberedSection(index, title, lines) {
136123
136865
  ${body}`;
136124
136866
  }
136125
136867
  function buildSummaryNarrative(data) {
136126
- const kpis = asRecord21(data.kpis) ?? {};
136127
- const meta = asRecord21(data.meta) ?? {};
136128
- const sections = asRecord21(data.sections) ?? {};
136868
+ const kpis = asRecord22(data.kpis) ?? {};
136869
+ const meta = asRecord22(data.meta) ?? {};
136870
+ const sections = asRecord22(data.sections) ?? {};
136129
136871
  const period = str2(meta.periodLabel) || `${str2(meta.startDate)} ~ ${str2(meta.endDate)}`.trim();
136130
136872
  const account = str2(meta.accountName) || "Facebook \u5E7F\u544A\u8D26\u6237";
136131
136873
  const campaign = str2(meta.campaignName);
136132
136874
  const resultLabel = displayResultType(kpis.resultType ?? meta.resultType) || "\u6210\u6548";
136133
136875
  const resultNoun = /潜在客户|lead/i.test(resultLabel) ? "\u4E2A\u6F5C\u5728\u5BA2\u6237\u8868\u5355" : `\u4E2A${resultLabel}`;
136134
- const firstQuestion = asRecord21(asArray3(data.fourQuestions)[0]);
136876
+ const firstQuestion = asRecord22(asArray3(data.fourQuestions)[0]);
136135
136877
  const extra = str2(firstQuestion?.verdict);
136136
136878
  const spendLine = [
136137
136879
  campaign ? `\uFF08\u5E7F\u544A\u7CFB\u5217\uFF1A${campaign}\uFF09` : "",
@@ -136151,7 +136893,7 @@ function buildSummaryNarrative(data) {
136151
136893
  numberedSection(3, "\u5E7F\u544A\u9891\u6B21\u4E0E\u65E5\u8D8B\u52BF", insightLines(sections.daily))
136152
136894
  ].join("\n");
136153
136895
  const recBlocks = asArray3(data.recommendations).map((raw, i) => {
136154
- const rec = asRecord21(raw);
136896
+ const rec = asRecord22(raw);
136155
136897
  if (!rec) return "";
136156
136898
  const title = [str2(rec.title), str2(rec.tag)].filter(Boolean).join(" \xB7 ");
136157
136899
  return numberedSection(i + 1, title || "\u4F18\u5316\u5EFA\u8BAE", bullets(rec.items));
@@ -136162,9 +136904,9 @@ function buildSummaryNarrative(data) {
136162
136904
  return [partOne, partTwo, partThree];
136163
136905
  }
136164
136906
  function buildMetaPeriodExcelSheets(data) {
136165
- const meta = asRecord21(data.meta) ?? {};
136166
- const kpis = asRecord21(data.kpis) ?? {};
136167
- const tables = asRecord21(data.tables) ?? {};
136907
+ const meta = asRecord22(data.meta) ?? {};
136908
+ const kpis = asRecord22(data.kpis) ?? {};
136909
+ const tables = asRecord22(data.tables) ?? {};
136168
136910
  const currency = str2(meta.currency) || "USD";
136169
136911
  const resultType = displayResultType(kpis.resultType ?? meta.resultType);
136170
136912
  const attribution = displayAttribution(kpis.attributionSetting ?? meta.attributionSetting);
@@ -136183,19 +136925,19 @@ function buildMetaPeriodExcelSheets(data) {
136183
136925
  ];
136184
136926
  const dailyRows = [metricHeaders(currency, "\u5355\u65E5")];
136185
136927
  for (const raw of asArray3(tables.daily)) {
136186
- const row = asRecord21(raw);
136928
+ const row = asRecord22(raw);
136187
136929
  if (!row) continue;
136188
136930
  dailyRows.push([normalizeInsightDate(row.date), ...metricCells(row)]);
136189
136931
  }
136190
136932
  const countryRows = [metricHeaders(currency, "\u56FD\u5BB6/\u5730\u533A")];
136191
136933
  for (const raw of asArray3(tables.countries)) {
136192
- const row = asRecord21(raw);
136934
+ const row = asRecord22(raw);
136193
136935
  if (!row) continue;
136194
136936
  countryRows.push([str2(row.countryOrRegion), ...metricCells(row)]);
136195
136937
  }
136196
136938
  const campaignRows3 = [metricHeaders(currency, "\u5E7F\u544A\u7CFB\u5217\u540D\u79F0")];
136197
136939
  for (const raw of asArray3(tables.campaigns)) {
136198
- const row = asRecord21(raw);
136940
+ const row = asRecord22(raw);
136199
136941
  if (!row) continue;
136200
136942
  campaignRows3.push([str2(row.campaignName), ...metricCells(row)]);
136201
136943
  }
@@ -136214,7 +136956,7 @@ function buildMetaPeriodExcelSheets(data) {
136214
136956
  ]
136215
136957
  ];
136216
136958
  for (const raw of asArray3(tables.audiences)) {
136217
- const row = asRecord21(raw);
136959
+ const row = asRecord22(raw);
136218
136960
  if (!row) continue;
136219
136961
  audienceRows.push([str2(row.age), str2(row.gender), ...metricCells(row)]);
136220
136962
  }
@@ -136246,7 +136988,7 @@ function isFiniteNumber(value) {
136246
136988
  function asArray4(value) {
136247
136989
  return Array.isArray(value) ? value : [];
136248
136990
  }
136249
- function asRecord22(value) {
136991
+ function asRecord23(value) {
136250
136992
  if (value && typeof value === "object" && !Array.isArray(value)) {
136251
136993
  return value;
136252
136994
  }
@@ -136259,8 +137001,8 @@ function stringList3(value) {
136259
137001
  return asArray4(value).map((item) => typeof item === "string" ? item.trim() : "").filter(Boolean);
136260
137002
  }
136261
137003
  function insightLists(section) {
136262
- const rec = asRecord22(section);
136263
- const insight = asRecord22(rec?.insight) ?? rec;
137004
+ const rec = asRecord23(section);
137005
+ const insight = asRecord23(rec?.insight) ?? rec;
136264
137006
  return {
136265
137007
  analysis: stringList3(insight?.analysis),
136266
137008
  advice: stringList3(insight?.advice)
@@ -136290,11 +137032,11 @@ function requireInsight(missing, key, chapter, section, required) {
136290
137032
  }
136291
137033
  function validateMetaPeriodReportContent(data) {
136292
137034
  const missing = [];
136293
- const meta = asRecord22(data.meta) ?? {};
136294
- const kpis = asRecord22(data.kpis) ?? {};
136295
- const tables = asRecord22(data.tables) ?? {};
136296
- const charts = asRecord22(data.charts) ?? {};
136297
- const sections = asRecord22(data.sections) ?? {};
137035
+ const meta = asRecord23(data.meta) ?? {};
137036
+ const kpis = asRecord23(data.kpis) ?? {};
137037
+ const tables = asRecord23(data.tables) ?? {};
137038
+ const charts = asRecord23(data.charts) ?? {};
137039
+ const sections = asRecord23(data.sections) ?? {};
136298
137040
  const fourQuestions = asArray4(data.fourQuestions);
136299
137041
  const recommendations = asArray4(data.recommendations);
136300
137042
  if (!textLen3(meta.accountName) && !textLen3(meta.accountId)) {
@@ -136373,7 +137115,7 @@ function validateMetaPeriodReportContent(data) {
136373
137115
  "\u987B\u6709 tables.audiences \u6570\u7EC4\uFF1B\u62C9\u6570\u52A0 --sections audience\uFF0Crender \u65F6\u4F20 --snapshot-dir\u3002\u672C\u671F\u65E0\u6D88\u8017\u53EF\u4E3A []"
136374
137116
  );
136375
137117
  }
136376
- const dailyChart = asRecord22(charts.daily);
137118
+ const dailyChart = asRecord23(charts.daily);
136377
137119
  if (!Array.isArray(dailyChart?.labels)) {
136378
137120
  pushMissing3(
136379
137121
  missing,
@@ -136383,7 +137125,7 @@ function validateMetaPeriodReportContent(data) {
136383
137125
  "\u987B\u6709 charts.daily.labels \u6570\u7EC4\uFF1B\u53EF\u7531 --snapshot-dir \u5408\u5E76 daily\u3002\u672C\u671F\u65E0\u6D88\u8017\u53EF\u4E3A []"
136384
137126
  );
136385
137127
  }
136386
- const countryChart = asRecord22(charts.country);
137128
+ const countryChart = asRecord23(charts.country);
136387
137129
  if (!Array.isArray(countryChart?.labels)) {
136388
137130
  pushMissing3(
136389
137131
  missing,
@@ -136393,7 +137135,7 @@ function validateMetaPeriodReportContent(data) {
136393
137135
  "\u987B\u6709 charts.country.labels \u6570\u7EC4\uFF1B\u53EF\u7531 --snapshot-dir \u5408\u5E76 country\u3002\u672C\u671F\u65E0\u6D88\u8017\u53EF\u4E3A []"
136394
137136
  );
136395
137137
  }
136396
- const audienceChart = asRecord22(charts.audience);
137138
+ const audienceChart = asRecord23(charts.audience);
136397
137139
  if (!Array.isArray(audienceChart?.labels)) {
136398
137140
  pushMissing3(
136399
137141
  missing,
@@ -136412,7 +137154,7 @@ function validateMetaPeriodReportContent(data) {
136412
137154
  "\u5FC5\u987B\u6070\u597D 4 \u95EE\uFF1A\u94B1\u82B1\u5F97\u503C\u4E0D\u503C / \u8C01\u771F\u7684\u60F3\u4E70 / \u5E7F\u544A\u8FD8\u65B0\u9C9C\u5417 / \u7528\u6237\u4E3A\u4EC0\u4E48\u4E0D\u7559\u8D44"
136413
137155
  );
136414
137156
  } else {
136415
- const titles = fourQuestions.map((q) => asRecord22(q)?.title);
137157
+ const titles = fourQuestions.map((q) => asRecord23(q)?.title);
136416
137158
  for (const title of FOUR_QUESTION_TITLES) {
136417
137159
  if (!titles.includes(title)) {
136418
137160
  pushMissing3(
@@ -136425,7 +137167,7 @@ function validateMetaPeriodReportContent(data) {
136425
137167
  }
136426
137168
  }
136427
137169
  for (let i = 0; i < fourQuestions.length; i++) {
136428
- const q = asRecord22(fourQuestions[i]);
137170
+ const q = asRecord23(fourQuestions[i]);
136429
137171
  if (textLen3(q?.verdict) < 8) {
136430
137172
  pushMissing3(
136431
137173
  missing,
@@ -136465,7 +137207,7 @@ function validateMetaPeriodReportContent(data) {
136465
137207
  );
136466
137208
  } else {
136467
137209
  for (let i = 0; i < recommendations.length; i++) {
136468
- const rec = asRecord22(recommendations[i]);
137210
+ const rec = asRecord23(recommendations[i]);
136469
137211
  if (textLen3(rec?.title) < 2) {
136470
137212
  pushMissing3(
136471
137213
  missing,
@@ -136558,7 +137300,7 @@ async function readJsonFile4(filePath) {
136558
137300
  throw new Error(`\u65E0\u6CD5\u89E3\u6790 JSON\uFF1A${filePath}`);
136559
137301
  }
136560
137302
  }
136561
- function asRecord23(value) {
137303
+ function asRecord24(value) {
136562
137304
  if (value && typeof value === "object" && !Array.isArray(value)) {
136563
137305
  return value;
136564
137306
  }
@@ -136587,7 +137329,7 @@ function defaultOutPath(dataPath, format, out) {
136587
137329
  }
136588
137330
  async function runFacebookAnalysisRender(opts) {
136589
137331
  const dataPath = path41.resolve(opts.dataFile);
136590
- let data = asRecord23(await readJsonFile4(dataPath));
137332
+ let data = asRecord24(await readJsonFile4(dataPath));
136591
137333
  if (opts.snapshotDir?.trim()) {
136592
137334
  data = await mergeFacebookSnapshotIntoReport(data, path41.resolve(opts.snapshotDir));
136593
137335
  }
@@ -136651,7 +137393,7 @@ import { fileURLToPath as fileURLToPath11 } from "url";
136651
137393
  // src/commands/facebook-analysis/diagnosis-merge-snapshot.ts
136652
137394
  import * as fs35 from "fs/promises";
136653
137395
  import * as path42 from "path";
136654
- function asRecord24(value) {
137396
+ function asRecord25(value) {
136655
137397
  if (value && typeof value === "object" && !Array.isArray(value)) {
136656
137398
  return value;
136657
137399
  }
@@ -136662,7 +137404,7 @@ function num8(value) {
136662
137404
  return Number.isFinite(n) ? n : void 0;
136663
137405
  }
136664
137406
  function asRows(value) {
136665
- return Array.isArray(value) ? value.filter((r) => asRecord24(r) !== null) : [];
137407
+ return Array.isArray(value) ? value.filter((r) => asRecord25(r) !== null) : [];
136666
137408
  }
136667
137409
  function pickMetricExtras(row, extras) {
136668
137410
  const out = {
@@ -136711,14 +137453,14 @@ async function readManifest4(snapshotDir, accountId) {
136711
137453
  async function loadSectionFile4(snapshotDir, file) {
136712
137454
  try {
136713
137455
  const raw = await fs35.readFile(path42.join(snapshotDir, file), "utf8");
136714
- return asRecord24(JSON.parse(raw));
137456
+ return asRecord25(JSON.parse(raw));
136715
137457
  } catch {
136716
137458
  return null;
136717
137459
  }
136718
137460
  }
136719
137461
  async function mergeMetaDiagnosisSnapshotIntoReport(payload, snapshotDir) {
136720
137462
  const absDir = path42.resolve(snapshotDir);
136721
- const metaAccountId = typeof asRecord24(payload.meta)?.accountId === "string" ? asRecord24(payload.meta)?.accountId : void 0;
137463
+ const metaAccountId = typeof asRecord25(payload.meta)?.accountId === "string" ? asRecord25(payload.meta)?.accountId : void 0;
136722
137464
  const manifest = await readManifest4(snapshotDir, metaAccountId);
136723
137465
  if (!manifest) {
136724
137466
  throw new Error(
@@ -136731,8 +137473,8 @@ async function mergeMetaDiagnosisSnapshotIntoReport(payload, snapshotDir) {
136731
137473
  if (data) sectionMap.set(art.section, data);
136732
137474
  }
136733
137475
  const overview = sectionMap.get("overview");
136734
- const currentPeriod = asRecord24(overview?.currentPeriod);
136735
- const previousPeriod = asRecord24(overview?.previousPeriod);
137476
+ const currentPeriod = asRecord25(overview?.currentPeriod);
137477
+ const previousPeriod = asRecord25(overview?.previousPeriod);
136736
137478
  const accountId = manifest.accountId ?? metaAccountId;
136737
137479
  const meta = { ...payload.meta ?? {} };
136738
137480
  if (!meta.accountId && accountId) meta.accountId = accountId;
@@ -136866,7 +137608,7 @@ function textLen4(value) {
136866
137608
  function asArray5(value) {
136867
137609
  return Array.isArray(value) ? value : [];
136868
137610
  }
136869
- function asRecord25(value) {
137611
+ function asRecord26(value) {
136870
137612
  if (value && typeof value === "object" && !Array.isArray(value)) {
136871
137613
  return value;
136872
137614
  }
@@ -136877,9 +137619,9 @@ function pushMissing4(missing, id, chapter, dimension, hint) {
136877
137619
  }
136878
137620
  function validateMetaDiagnosisReportContent(data) {
136879
137621
  const missing = [];
136880
- const meta = asRecord25(data.meta) ?? {};
136881
- const narrative = asRecord25(data.narrative) ?? {};
136882
- const sections = asRecord25(narrative.sections) ?? {};
137622
+ const meta = asRecord26(data.meta) ?? {};
137623
+ const narrative = asRecord26(data.narrative) ?? {};
137624
+ const sections = asRecord26(narrative.sections) ?? {};
136883
137625
  if (!textLen4(meta.accountId)) {
136884
137626
  pushMissing4(missing, "meta-account", "\u5143\u4FE1\u606F", "\u8D26\u6237 ID", "meta.accountId \u5FC5\u586B");
136885
137627
  }
@@ -136897,7 +137639,7 @@ function validateMetaDiagnosisReportContent(data) {
136897
137639
  const sectionSuggestionCounts = {};
136898
137640
  const sectionNotAvailable = {};
136899
137641
  for (const key of NORMAL_SECTION_KEYS) {
136900
- const section = asRecord25(sections[key]);
137642
+ const section = asRecord26(sections[key]);
136901
137643
  const analysis = asArray5(section?.analysis).filter((s) => textLen4(s) > 0);
136902
137644
  const suggestions = asArray5(section?.suggestions).filter((s) => textLen4(s) > 0);
136903
137645
  sectionAnalysisCounts[key] = analysis.length;
@@ -136923,7 +137665,7 @@ function validateMetaDiagnosisReportContent(data) {
136923
137665
  }
136924
137666
  }
136925
137667
  for (const key of NA_SECTION_KEYS) {
136926
- const section = asRecord25(sections[key]);
137668
+ const section = asRecord26(sections[key]);
136927
137669
  const analysis = asArray5(section?.analysis).filter((s) => textLen4(s) > 0);
136928
137670
  const suggestions = asArray5(section?.suggestions).filter((s) => textLen4(s) > 0);
136929
137671
  const notAvailable = section?.notAvailable === true;
@@ -136945,7 +137687,7 @@ function validateMetaDiagnosisReportContent(data) {
136945
137687
  }
136946
137688
  const recommendations = asArray5(narrative.recommendations).filter((r) => {
136947
137689
  if (typeof r === "string") return textLen4(r) > 0;
136948
- const rec = asRecord25(r);
137690
+ const rec = asRecord26(r);
136949
137691
  return textLen4(rec?.content) > 0;
136950
137692
  });
136951
137693
  if (recommendations.length < 3) {
@@ -137018,7 +137760,7 @@ async function readJsonFile5(filePath) {
137018
137760
  throw new Error(`\u65E0\u6CD5\u89E3\u6790 JSON\uFF1A${filePath}`);
137019
137761
  }
137020
137762
  }
137021
- function asRecord26(value) {
137763
+ function asRecord27(value) {
137022
137764
  if (value && typeof value === "object" && !Array.isArray(value)) {
137023
137765
  return value;
137024
137766
  }
@@ -137033,7 +137775,7 @@ function injectReportData4(html, payload) {
137033
137775
  }
137034
137776
  async function runFacebookAnalysisDiagnosisRender(opts) {
137035
137777
  const dataPath = path43.resolve(opts.dataFile);
137036
- let data = asRecord26(await readJsonFile5(dataPath));
137778
+ let data = asRecord27(await readJsonFile5(dataPath));
137037
137779
  if (opts.snapshotDir?.trim()) {
137038
137780
  data = await mergeMetaDiagnosisSnapshotIntoReport(data, path43.resolve(opts.snapshotDir));
137039
137781
  }
@@ -137232,7 +137974,7 @@ function resolveFacebookPageSize(raw, fallback = FB_ENTITY_PAGE_SIZE_DEFAULT) {
137232
137974
  if (!Number.isFinite(n) || n <= 0) return fallback;
137233
137975
  return Math.min(Math.max(Math.floor(n), 1), FB_ENTITY_PAGE_SIZE_MAX);
137234
137976
  }
137235
- function asRecord27(value) {
137977
+ function asRecord28(value) {
137236
137978
  return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
137237
137979
  }
137238
137980
  function pickProp(obj, ...keys) {
@@ -137242,12 +137984,12 @@ function pickProp(obj, ...keys) {
137242
137984
  return void 0;
137243
137985
  }
137244
137986
  function unwrapFacebookPaged(raw) {
137245
- const rec = asRecord27(raw);
137987
+ const rec = asRecord28(raw);
137246
137988
  if (!rec) return { items: [] };
137247
137989
  const data = pickProp(rec, "data", "Data");
137248
137990
  const items3 = Array.isArray(data) ? data : [];
137249
- const paging = asRecord27(pickProp(rec, "paging", "Paging"));
137250
- const cursors = paging ? asRecord27(pickProp(paging, "cursors", "Cursors")) : void 0;
137991
+ const paging = asRecord28(pickProp(rec, "paging", "Paging"));
137992
+ const cursors = paging ? asRecord28(pickProp(paging, "cursors", "Cursors")) : void 0;
137251
137993
  const afterRaw = cursors ? pickProp(cursors, "after", "After") : void 0;
137252
137994
  const after = typeof afterRaw === "string" && afterRaw.trim() ? afterRaw.trim() : void 0;
137253
137995
  return { items: items3, after };
@@ -137395,7 +138137,7 @@ async function fetchFacebookInsights(config, digits, level, opts) {
137395
138137
  opts.verbose
137396
138138
  );
137397
138139
  if (Array.isArray(raw)) return raw;
137398
- const rec = asRecord27(raw);
138140
+ const rec = asRecord28(raw);
137399
138141
  const data = rec ? pickProp(rec, "data", "Data") : void 0;
137400
138142
  return Array.isArray(data) ? data : [];
137401
138143
  }
@@ -137404,7 +138146,7 @@ function sumActionArray(raw) {
137404
138146
  let sum = 0;
137405
138147
  let hit = false;
137406
138148
  for (const item of raw) {
137407
- const rec = asRecord27(item);
138149
+ const rec = asRecord28(item);
137408
138150
  if (!rec) continue;
137409
138151
  const n = Number(rec.value);
137410
138152
  if (!Number.isFinite(n)) continue;
@@ -138683,7 +139425,7 @@ import { fileURLToPath as fileURLToPath12 } from "url";
138683
139425
  // src/commands/bing-analysis/merge-snapshot.ts
138684
139426
  import * as fs37 from "fs/promises";
138685
139427
  import * as path46 from "path";
138686
- function asRecord28(value) {
139428
+ function asRecord29(value) {
138687
139429
  if (value && typeof value === "object" && !Array.isArray(value)) {
138688
139430
  return value;
138689
139431
  }
@@ -138698,7 +139440,7 @@ function round27(value) {
138698
139440
  }
138699
139441
  function asRows2(value) {
138700
139442
  if (Array.isArray(value)) {
138701
- return value.filter((r) => asRecord28(r) !== null);
139443
+ return value.filter((r) => asRecord29(r) !== null);
138702
139444
  }
138703
139445
  return [];
138704
139446
  }
@@ -138780,17 +139522,17 @@ function campaignStatusDisplay(status) {
138780
139522
  return status == null || status === "" ? "\u2014" : String(status);
138781
139523
  }
138782
139524
  function mapDeviceRows(payload) {
138783
- const obj = asRecord28(payload);
139525
+ const obj = asRecord29(payload);
138784
139526
  return asRows2(obj?.devices).map((r) => pickMetrics(r, ["deviceType"]));
138785
139527
  }
138786
139528
  function mapGeographicRows(payload) {
138787
- const obj = asRecord28(payload);
139529
+ const obj = asRecord29(payload);
138788
139530
  return asRows2(obj?.countries).map(
138789
139531
  (r) => pickMetrics(r, ["countryOrRegion", "countryCriteriaId", "regionName", "cityName"])
138790
139532
  );
138791
139533
  }
138792
139534
  function mapAudienceLabelRows(payload, labelKey) {
138793
- const obj = asRecord28(payload);
139535
+ const obj = asRecord29(payload);
138794
139536
  return asRows2(obj?.audience).map((r) => {
138795
139537
  const m = pickMetrics(r, ["audience", "bidModifier"]);
138796
139538
  m[labelKey] = r.audience;
@@ -138798,7 +139540,7 @@ function mapAudienceLabelRows(payload, labelKey) {
138798
139540
  });
138799
139541
  }
138800
139542
  function mapAudienceFromMerged(payload) {
138801
- const data = asRecord28(asRecord28(payload)?.data);
139543
+ const data = asRecord29(asRecord29(payload)?.data);
138802
139544
  return {
138803
139545
  audienceAge: mapAudienceLabelRows(data?.ageAudience, "ageRange"),
138804
139546
  audienceGender: mapAudienceLabelRows(data?.genderAudience, "gender")
@@ -138893,7 +139635,7 @@ function mapSearchTermRows(payload) {
138893
139635
  }
138894
139636
  async function mergeBingAnalysisSnapshotIntoReport(payload, snapshotDir) {
138895
139637
  const absDir = path46.resolve(snapshotDir);
138896
- const metaAccountId = typeof asRecord28(payload.meta)?.accountId === "string" ? asRecord28(payload.meta)?.accountId : void 0;
139638
+ const metaAccountId = typeof asRecord29(payload.meta)?.accountId === "string" ? asRecord29(payload.meta)?.accountId : void 0;
138897
139639
  const manifest = await readManifest5(snapshotDir, metaAccountId);
138898
139640
  if (!manifest) {
138899
139641
  throw new Error(`\u672A\u5728 ${absDir} \u627E\u5230 report-manifest*.json\uFF0C\u8BF7\u5148\u6267\u884C bing-analysis --json-out`);
@@ -138903,9 +139645,9 @@ async function mergeBingAnalysisSnapshotIntoReport(payload, snapshotDir) {
138903
139645
  const data = await loadSectionPayload(absDir, art.file);
138904
139646
  if (data != null) sectionMap.set(art.section, data);
138905
139647
  }
138906
- const overview = asRecord28(sectionMap.get("overview"));
138907
- const currentPeriod = asRecord28(overview?.currentPeriod);
138908
- const previousPeriod = asRecord28(overview?.previousPeriod);
139648
+ const overview = asRecord29(sectionMap.get("overview"));
139649
+ const currentPeriod = asRecord29(overview?.currentPeriod);
139650
+ const previousPeriod = asRecord29(overview?.previousPeriod);
138909
139651
  const accountId = manifest.accountId ?? metaAccountId;
138910
139652
  const campaignRows3 = mapCampaignRows2(sectionMap.get("campaigns"));
138911
139653
  const campaignKpis = sumBingCampaignRowsToPeriodKpis(campaignRows3);
@@ -139032,7 +139774,7 @@ function textLen5(value) {
139032
139774
  function asArray6(value) {
139033
139775
  return Array.isArray(value) ? value : [];
139034
139776
  }
139035
- function asRecord29(value) {
139777
+ function asRecord30(value) {
139036
139778
  if (value && typeof value === "object" && !Array.isArray(value)) {
139037
139779
  return value;
139038
139780
  }
@@ -139043,9 +139785,9 @@ function pushMissing5(missing, id, chapter, dimension, hint) {
139043
139785
  }
139044
139786
  function validateBingPeriodReportContent(data) {
139045
139787
  const missing = [];
139046
- const meta = asRecord29(data.meta) ?? {};
139047
- const narrative = asRecord29(data.narrative) ?? {};
139048
- const sections = asRecord29(narrative.sections) ?? {};
139788
+ const meta = asRecord30(data.meta) ?? {};
139789
+ const narrative = asRecord30(data.narrative) ?? {};
139790
+ const sections = asRecord30(narrative.sections) ?? {};
139049
139791
  if (!textLen5(meta.accountId)) {
139050
139792
  pushMissing5(missing, "meta-account", "\u5143\u4FE1\u606F", "\u8D26\u6237 ID", "meta.accountId \u5FC5\u586B");
139051
139793
  }
@@ -139062,7 +139804,7 @@ function validateBingPeriodReportContent(data) {
139062
139804
  const sectionAnalysisCounts = {};
139063
139805
  const sectionSuggestionCounts = {};
139064
139806
  for (const key of SECTION_KEYS2) {
139065
- const section = asRecord29(sections[key]);
139807
+ const section = asRecord30(sections[key]);
139066
139808
  const analysis = asArray6(section?.analysis).filter((s) => textLen5(s) > 0);
139067
139809
  const suggestions = asArray6(section?.suggestions).filter((s) => textLen5(s) > 0);
139068
139810
  sectionAnalysisCounts[key] = analysis.length;
@@ -139088,7 +139830,7 @@ function validateBingPeriodReportContent(data) {
139088
139830
  }
139089
139831
  const recommendations = asArray6(narrative.recommendations).filter((r) => {
139090
139832
  if (typeof r === "string") return textLen5(r) > 0;
139091
- const rec = asRecord29(r);
139833
+ const rec = asRecord30(r);
139092
139834
  return textLen5(rec?.content) > 0;
139093
139835
  });
139094
139836
  if (recommendations.length < 3) {
@@ -139149,7 +139891,7 @@ async function readJsonFile6(filePath) {
139149
139891
  throw new Error(`\u65E0\u6CD5\u89E3\u6790 JSON\uFF1A${filePath}`);
139150
139892
  }
139151
139893
  }
139152
- function asRecord30(value) {
139894
+ function asRecord31(value) {
139153
139895
  if (value && typeof value === "object" && !Array.isArray(value)) {
139154
139896
  return value;
139155
139897
  }
@@ -139164,7 +139906,7 @@ function injectReportData5(html, payload) {
139164
139906
  }
139165
139907
  async function runBingAnalysisRender(opts) {
139166
139908
  const dataPath = path47.resolve(opts.dataFile);
139167
- let data = asRecord30(await readJsonFile6(dataPath));
139909
+ let data = asRecord31(await readJsonFile6(dataPath));
139168
139910
  if (opts.snapshotDir?.trim()) {
139169
139911
  data = await mergeBingAnalysisSnapshotIntoReport(data, path47.resolve(opts.snapshotDir));
139170
139912
  }
@@ -139637,7 +140379,7 @@ import { fileURLToPath as fileURLToPath13 } from "url";
139637
140379
  // src/commands/tiktok-analysis/merge-snapshot.ts
139638
140380
  import * as fs39 from "fs/promises";
139639
140381
  import * as path49 from "path";
139640
- function asRecord31(value) {
140382
+ function asRecord32(value) {
139641
140383
  if (value && typeof value === "object" && !Array.isArray(value)) {
139642
140384
  return value;
139643
140385
  }
@@ -139815,7 +140557,7 @@ function mapAudienceMerged(payload) {
139815
140557
  }
139816
140558
  async function mergeTikTokAnalysisSnapshotIntoReport(payload, snapshotDir) {
139817
140559
  const absDir = path49.resolve(snapshotDir);
139818
- const metaAccountId = typeof asRecord31(payload.meta)?.accountId === "string" ? asRecord31(payload.meta)?.accountId : void 0;
140560
+ const metaAccountId = typeof asRecord32(payload.meta)?.accountId === "string" ? asRecord32(payload.meta)?.accountId : void 0;
139819
140561
  const manifest = await readManifest6(snapshotDir, metaAccountId);
139820
140562
  if (!manifest) {
139821
140563
  throw new Error(
@@ -139929,7 +140671,7 @@ function textLen6(value) {
139929
140671
  function asArray7(value) {
139930
140672
  return Array.isArray(value) ? value : [];
139931
140673
  }
139932
- function asRecord32(value) {
140674
+ function asRecord33(value) {
139933
140675
  if (value && typeof value === "object" && !Array.isArray(value)) {
139934
140676
  return value;
139935
140677
  }
@@ -139940,9 +140682,9 @@ function pushMissing6(missing, id, chapter, dimension, hint) {
139940
140682
  }
139941
140683
  function validateTikTokPeriodReportContent(data) {
139942
140684
  const missing = [];
139943
- const meta = asRecord32(data.meta) ?? {};
139944
- const narrative = asRecord32(data.narrative) ?? {};
139945
- const sections = asRecord32(narrative.sections) ?? {};
140685
+ const meta = asRecord33(data.meta) ?? {};
140686
+ const narrative = asRecord33(data.narrative) ?? {};
140687
+ const sections = asRecord33(narrative.sections) ?? {};
139946
140688
  if (!textLen6(meta.accountId)) {
139947
140689
  pushMissing6(missing, "meta-account", "\u5143\u4FE1\u606F", "\u8D26\u6237 ID", "meta.accountId \u5FC5\u586B");
139948
140690
  }
@@ -139959,7 +140701,7 @@ function validateTikTokPeriodReportContent(data) {
139959
140701
  const sectionAnalysisCounts = {};
139960
140702
  const sectionSuggestionCounts = {};
139961
140703
  for (const key of SECTION_KEYS3) {
139962
- const section = asRecord32(sections[key]);
140704
+ const section = asRecord33(sections[key]);
139963
140705
  const analysis = asArray7(section?.analysis).filter((s) => textLen6(s) > 0);
139964
140706
  const suggestions = asArray7(section?.suggestions).filter((s) => textLen6(s) > 0);
139965
140707
  sectionAnalysisCounts[key] = analysis.length;
@@ -139985,7 +140727,7 @@ function validateTikTokPeriodReportContent(data) {
139985
140727
  }
139986
140728
  const recommendations = asArray7(narrative.recommendations).filter((r) => {
139987
140729
  if (typeof r === "string") return textLen6(r) > 0;
139988
- const rec = asRecord32(r);
140730
+ const rec = asRecord33(r);
139989
140731
  return textLen6(rec?.content) > 0;
139990
140732
  });
139991
140733
  if (recommendations.length < 3) {
@@ -140046,7 +140788,7 @@ async function readJsonFile7(filePath) {
140046
140788
  throw new Error(`\u65E0\u6CD5\u89E3\u6790 JSON\uFF1A${filePath}`);
140047
140789
  }
140048
140790
  }
140049
- function asRecord33(value) {
140791
+ function asRecord34(value) {
140050
140792
  if (value && typeof value === "object" && !Array.isArray(value)) {
140051
140793
  return value;
140052
140794
  }
@@ -140061,7 +140803,7 @@ function injectReportData6(html, payload) {
140061
140803
  }
140062
140804
  async function runTikTokAnalysisRender(opts) {
140063
140805
  const dataPath = path50.resolve(opts.dataFile);
140064
- let data = asRecord33(await readJsonFile7(dataPath));
140806
+ let data = asRecord34(await readJsonFile7(dataPath));
140065
140807
  if (opts.snapshotDir?.trim()) {
140066
140808
  data = await mergeTikTokAnalysisSnapshotIntoReport(data, path50.resolve(opts.snapshotDir));
140067
140809
  }
@@ -141160,7 +141902,7 @@ function endpointHintForYandexSection(def) {
141160
141902
  // src/commands/yandex-analysis/merge-snapshot.ts
141161
141903
  import * as fs41 from "fs/promises";
141162
141904
  import * as path51 from "path";
141163
- function asRecord34(value) {
141905
+ function asRecord35(value) {
141164
141906
  if (value && typeof value === "object" && !Array.isArray(value)) {
141165
141907
  return value;
141166
141908
  }
@@ -141180,11 +141922,11 @@ function normalizeYandexRoi(value) {
141180
141922
  return r === -1 ? void 0 : r;
141181
141923
  }
141182
141924
  function asItems(payload) {
141183
- const obj = asRecord34(payload);
141925
+ const obj = asRecord35(payload);
141184
141926
  if (!obj) return [];
141185
141927
  const items3 = obj.items;
141186
141928
  if (!Array.isArray(items3)) return [];
141187
- return items3.filter((r) => asRecord34(r) !== null);
141929
+ return items3.filter((r) => asRecord35(r) !== null);
141188
141930
  }
141189
141931
  function pickMetrics2(row, extras = []) {
141190
141932
  const spend = num12(row.spend) ?? 0;
@@ -141320,7 +142062,7 @@ function aggregateDailyToWeekly(dailyRows) {
141320
142062
  });
141321
142063
  }
141322
142064
  function prepareYandexDailyPayload(payload) {
141323
- const obj = asRecord34(payload) ?? {};
142065
+ const obj = asRecord35(payload) ?? {};
141324
142066
  const items3 = asItems(obj).map((r) => {
141325
142067
  const date = normalizeYandexDailyDate(r.date);
141326
142068
  return date ? { ...r, date } : r;
@@ -141389,7 +142131,7 @@ function mapDeviceRows2(payload) {
141389
142131
  }
141390
142132
  async function mergeYandexAnalysisSnapshotIntoReport(payload, snapshotDir) {
141391
142133
  const absDir = path51.resolve(snapshotDir);
141392
- const metaAccountId = typeof asRecord34(payload.meta)?.accountId === "string" ? asRecord34(payload.meta)?.accountId : void 0;
142134
+ const metaAccountId = typeof asRecord35(payload.meta)?.accountId === "string" ? asRecord35(payload.meta)?.accountId : void 0;
141393
142135
  const manifest = await readManifest7(snapshotDir, metaAccountId);
141394
142136
  if (!manifest) {
141395
142137
  throw new Error(
@@ -141401,8 +142143,8 @@ async function mergeYandexAnalysisSnapshotIntoReport(payload, snapshotDir) {
141401
142143
  const data = await loadSectionPayload3(absDir, art.file);
141402
142144
  if (data != null) sectionMap.set(art.section, data);
141403
142145
  }
141404
- const overview = asRecord34(sectionMap.get("overview"));
141405
- const totals = asRecord34(overview?.totals);
142146
+ const overview = asRecord35(sectionMap.get("overview"));
142147
+ const totals = asRecord35(overview?.totals);
141406
142148
  const accountId = manifest.accountId ?? metaAccountId;
141407
142149
  const meta = { ...payload.meta ?? {} };
141408
142150
  if (!meta.accountId && accountId) meta.accountId = accountId;
@@ -141624,7 +142366,7 @@ function textLen7(value) {
141624
142366
  function asArray8(value) {
141625
142367
  return Array.isArray(value) ? value : [];
141626
142368
  }
141627
- function asRecord35(value) {
142369
+ function asRecord36(value) {
141628
142370
  if (value && typeof value === "object" && !Array.isArray(value)) {
141629
142371
  return value;
141630
142372
  }
@@ -141637,23 +142379,23 @@ function normKey(value) {
141637
142379
  return String(value ?? "").trim().toLowerCase();
141638
142380
  }
141639
142381
  function insightMatchRecord(item) {
141640
- const rec = asRecord35(item);
142382
+ const rec = asRecord36(item);
141641
142383
  if (!rec) return {};
141642
- return asRecord35(rec.match) ?? rec;
142384
+ return asRecord36(rec.match) ?? rec;
141643
142385
  }
141644
142386
  function findRowInsight(list, primaryField, primaryValue, row) {
141645
142387
  const target = normKey(primaryValue);
141646
142388
  if (!target) return null;
141647
142389
  const candidates = list.filter((it) => normKey(insightMatchRecord(it)[primaryField]) === target);
141648
- if (candidates.length <= 1) return asRecord35(candidates[0]);
142390
+ if (candidates.length <= 1) return asRecord36(candidates[0]);
141649
142391
  const campaign = normKey(row.campaignName);
141650
142392
  const narrowed = candidates.find(
141651
142393
  (it) => normKey(insightMatchRecord(it).campaignName) === campaign
141652
142394
  );
141653
- return asRecord35(narrowed ?? candidates[0]);
142395
+ return asRecord36(narrowed ?? candidates[0]);
141654
142396
  }
141655
142397
  function topRowsBySpend(rows, limit) {
141656
- return rows.map((r) => asRecord35(r)).filter((r) => r != null).sort((a, b) => (Number(b.spend) || 0) - (Number(a.spend) || 0)).slice(0, limit);
142398
+ return rows.map((r) => asRecord36(r)).filter((r) => r != null).sort((a, b) => (Number(b.spend) || 0) - (Number(a.spend) || 0)).slice(0, limit);
141657
142399
  }
141658
142400
  var ROW_INSIGHT_SPECS = [
141659
142401
  {
@@ -141668,17 +142410,17 @@ var ROW_INSIGHT_SPECS = [
141668
142410
  ];
141669
142411
  function validateYandexPeriodReportContent(data) {
141670
142412
  const missing = [];
141671
- const meta = asRecord35(data.meta) ?? {};
141672
- const narrative = asRecord35(data.narrative) ?? {};
141673
- const sections = asRecord35(narrative.sections) ?? {};
141674
- const kpis = asRecord35(data.kpis) ?? {};
142413
+ const meta = asRecord36(data.meta) ?? {};
142414
+ const narrative = asRecord36(data.narrative) ?? {};
142415
+ const sections = asRecord36(narrative.sections) ?? {};
142416
+ const kpis = asRecord36(data.kpis) ?? {};
141675
142417
  if (!textLen7(meta.accountId)) {
141676
142418
  pushMissing7(missing, "meta-account", "\u5143\u4FE1\u606F", "\u8D26\u6237 ID", "meta.accountId \u5FC5\u586B");
141677
142419
  }
141678
142420
  const sectionAnalysisCounts = {};
141679
142421
  const sectionSuggestionCounts = {};
141680
142422
  for (const key of SECTION_KEYS4) {
141681
- const section = asRecord35(sections[key]);
142423
+ const section = asRecord36(sections[key]);
141682
142424
  const analysis = asArray8(section?.analysis).filter((s) => textLen7(s) > 0);
141683
142425
  const suggestions = asArray8(section?.suggestions).filter((s) => textLen7(s) > 0);
141684
142426
  sectionAnalysisCounts[key] = analysis.length;
@@ -141704,7 +142446,7 @@ function validateYandexPeriodReportContent(data) {
141704
142446
  }
141705
142447
  const recommendations = asArray8(narrative.recommendations).filter((r) => {
141706
142448
  if (typeof r === "string") return textLen7(r) > 0;
141707
- const rec = asRecord35(r);
142449
+ const rec = asRecord36(r);
141708
142450
  return textLen7(rec?.content) > 0 || textLen7(rec?.text) > 0;
141709
142451
  });
141710
142452
  if (recommendations.length < 3) {
@@ -141726,8 +142468,8 @@ function validateYandexPeriodReportContent(data) {
141726
142468
  "\u81F3\u5C11\u4E00\u9879\u6709\u6548\u6570\u5B57\uFF08\u8BF7\u4F20 --snapshot-dir \u7531 CLI \u4ECE overview \u5408\u5E76\uFF09"
141727
142469
  );
141728
142470
  }
141729
- const tables = asRecord35(data.tables) ?? {};
141730
- const weeklyRows = asArray8(tables.weekly).map((r) => asRecord35(r)).filter((r) => r != null);
142471
+ const tables = asRecord36(data.tables) ?? {};
142472
+ const weeklyRows = asArray8(tables.weekly).map((r) => asRecord36(r)).filter((r) => r != null);
141731
142473
  for (const [i, row] of weeklyRows.entries()) {
141732
142474
  const label = `${row.weekLabel ?? ""} ${row.startDate ?? ""} ${row.endDate ?? ""}`;
141733
142475
  if (/nan/i.test(label) || !normalizeYandexDailyDate(row.startDate) || !normalizeYandexDailyDate(row.endDate)) {
@@ -141740,7 +142482,7 @@ function validateYandexPeriodReportContent(data) {
141740
142482
  );
141741
142483
  }
141742
142484
  }
141743
- const rowInsights = asRecord35(narrative.rowInsights) ?? {};
142485
+ const rowInsights = asRecord36(narrative.rowInsights) ?? {};
141744
142486
  const rowInsightCoverage = {};
141745
142487
  for (const spec of ROW_INSIGHT_SPECS) {
141746
142488
  const shown = topRowsBySpend(asArray8(tables[spec.tableKey]), spec.limit).filter(
@@ -141820,7 +142562,7 @@ async function readJsonFile8(filePath) {
141820
142562
  throw new Error(`\u65E0\u6CD5\u89E3\u6790 JSON\uFF1A${filePath}`);
141821
142563
  }
141822
142564
  }
141823
- function asRecord36(value) {
142565
+ function asRecord37(value) {
141824
142566
  if (value && typeof value === "object" && !Array.isArray(value)) {
141825
142567
  return value;
141826
142568
  }
@@ -141848,7 +142590,7 @@ function injectReportData7(html, payload) {
141848
142590
  }
141849
142591
  async function runYandexAnalysisRender(opts) {
141850
142592
  const dataPath = path53.resolve(opts.dataFile);
141851
- let data = asRecord36(await readJsonFile8(dataPath));
142593
+ let data = asRecord37(await readJsonFile8(dataPath));
141852
142594
  if (opts.snapshotDir?.trim()) {
141853
142595
  data = await mergeYandexAnalysisSnapshotIntoReport(data, path53.resolve(opts.snapshotDir));
141854
142596
  }
@@ -142044,7 +142786,7 @@ function unwrapYandexItems(raw) {
142044
142786
  }
142045
142787
  return [];
142046
142788
  }
142047
- function asRecord37(raw) {
142789
+ function asRecord38(raw) {
142048
142790
  return raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
142049
142791
  }
142050
142792
 
@@ -142123,7 +142865,7 @@ async function runYandexAccountStatus(opts) {
142123
142865
  } catch (err) {
142124
142866
  fail3("\u67E5\u8BE2 Yandex \u8D26\u6237\u603B\u89C8\u5931\u8D25", err);
142125
142867
  }
142126
- const row = asRecord37(result.raw);
142868
+ const row = asRecord38(result.raw);
142127
142869
  await emitOrTable(opts, {
142128
142870
  section: "yandex-account-status",
142129
142871
  commandLabel: "yandex-analysis account-status",