siluzan-tso-cli 1.1.29-beta.17 → 1.1.29-beta.18

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/README.md CHANGED
@@ -51,7 +51,7 @@ siluzan-tso init -d /path/to/skills # 写入自定义目录
51
51
  siluzan-tso init --force # 强制覆盖已存在文件
52
52
  ```
53
53
 
54
- > **注意**:当前为测试版(1.1.29-beta.17),供内部测试使用。正式发布后安装命令将改为 `npm install -g siluzan-tso-cli`。
54
+ > **注意**:当前为测试版(1.1.29-beta.18),供内部测试使用。正式发布后安装命令将改为 `npm install -g siluzan-tso-cli`。
55
55
 
56
56
  | 助手 | 建议 `--ai` |
57
57
  | ----------------------- | ------------------------------------ |
package/dist/index.js CHANGED
@@ -114916,13 +114916,13 @@ var VALID_PMAX_BIDDING_STRATEGIES = [
114916
114916
  "TARGET_CPA",
114917
114917
  "TARGET_ROAS"
114918
114918
  ];
114919
- var PMAX_HEADLINE_MIN = 3;
114919
+ var PMAX_HEADLINE_MIN = 15;
114920
114920
  var PMAX_HEADLINE_MAX = 15;
114921
114921
  var PMAX_HEADLINE_CHAR_MAX = 30;
114922
- var PMAX_LONG_HEADLINE_MIN = 1;
114922
+ var PMAX_LONG_HEADLINE_MIN = 5;
114923
114923
  var PMAX_LONG_HEADLINE_MAX = 5;
114924
114924
  var PMAX_LONG_HEADLINE_CHAR_MAX = 90;
114925
- var PMAX_DESCRIPTION_MIN = 2;
114925
+ var PMAX_DESCRIPTION_MIN = 5;
114926
114926
  var PMAX_DESCRIPTION_MAX = 5;
114927
114927
  var PMAX_DESCRIPTION_CHAR_MAX = 90;
114928
114928
  var PMAX_BUSINESS_NAME_CHAR_MAX = 25;
@@ -115629,6 +115629,431 @@ function assertPmaxImageSlotsResolved(slots, requiredKinds = ["marketing", "squa
115629
115629
 
115630
115630
  // src/commands/ad/pmax-load.ts
115631
115631
  import { readFileSync as readFileSync9 } from "fs";
115632
+
115633
+ // src/commands/ad/pmax-campaign-extensions.ts
115634
+ init_auth();
115635
+ var PMAX_POLICY_CALLOUT_MIN = 20;
115636
+ var PMAX_POLICY_STRUCTURED_SNIPPET_MIN = 20;
115637
+ var PMAX_POLICY_SITELINK_MIN = 6;
115638
+ var PMAX_EXTENSIONS_POLICY_HINT = `\u987B\u542B\uFF1A\u5BA3\u4F20\u4FE1\u606F \u2265${PMAX_POLICY_CALLOUT_MIN}\u3001\u7ED3\u6784\u5316\u6458\u8981 \u2265${PMAX_POLICY_STRUCTURED_SNIPPET_MIN}\u3001\u7AD9\u5185\u94FE\u63A5 \u2265${PMAX_POLICY_SITELINK_MIN}\u3001\u6F5C\u5728\u5BA2\u6237\u8868\u5355 leadForm\u3001WhatsApp businessMessage`;
115639
+ function countNonEmptyCallouts(callouts) {
115640
+ return (callouts ?? []).filter((t) => t?.trim()).length;
115641
+ }
115642
+ function countValidSnippets(snippets) {
115643
+ return (snippets ?? []).filter(
115644
+ (s) => s?.header?.trim() && (s.values ?? []).filter((v) => v?.trim()).length >= 3
115645
+ ).length;
115646
+ }
115647
+ function countValidSitelinks(sitelinks) {
115648
+ return (sitelinks ?? []).filter((s) => s?.text?.trim() && s?.destinationUrl?.trim()).length;
115649
+ }
115650
+ function validatePmaxSitelinkSpec(link, prefix, errors, warnings) {
115651
+ if (!link) {
115652
+ errors.push(`${prefix} \u4E0D\u80FD\u4E3A\u7A7A`);
115653
+ return;
115654
+ }
115655
+ const text = link.text?.trim();
115656
+ const url = link.destinationUrl?.trim();
115657
+ if (!text) errors.push(`${prefix}.text \u4E0D\u80FD\u4E3A\u7A7A`);
115658
+ if (!url) {
115659
+ errors.push(`${prefix}.destinationUrl \u4E0D\u80FD\u4E3A\u7A7A`);
115660
+ } else if (!/^https?:\/\/.+/i.test(url)) {
115661
+ errors.push(`${prefix}.destinationUrl \u683C\u5F0F\u4E0D\u6B63\u786E\uFF1A${url}`);
115662
+ }
115663
+ if (text && url) {
115664
+ validateSitelinkProperties(
115665
+ prefix,
115666
+ {
115667
+ Text: text,
115668
+ DestinationUrl: url,
115669
+ Line2: link.line2?.trim() ?? "",
115670
+ Line3: link.line3?.trim() ?? ""
115671
+ },
115672
+ errors,
115673
+ warnings,
115674
+ []
115675
+ );
115676
+ }
115677
+ }
115678
+ function validatePmaxExtensionsPolicyCounts(ext, errors) {
115679
+ const calloutCount = countNonEmptyCallouts(ext.callouts);
115680
+ if (calloutCount < PMAX_POLICY_CALLOUT_MIN) {
115681
+ errors.push(
115682
+ `campaignExtensions.callouts \u81F3\u5C11 ${PMAX_POLICY_CALLOUT_MIN} \u6761\u975E\u7A7A\u5BA3\u4F20\u4FE1\u606F\uFF08\u5F53\u524D ${calloutCount}\uFF09`
115683
+ );
115684
+ }
115685
+ const snippetCount = countValidSnippets(ext.structuredSnippets);
115686
+ if (snippetCount < PMAX_POLICY_STRUCTURED_SNIPPET_MIN) {
115687
+ errors.push(
115688
+ `campaignExtensions.structuredSnippets \u81F3\u5C11 ${PMAX_POLICY_STRUCTURED_SNIPPET_MIN} \u6761\u6709\u6548\u7ED3\u6784\u5316\u6458\u8981\uFF08\u6BCF\u6761 header + \u22653 values\uFF0C\u5F53\u524D ${snippetCount}\uFF09`
115689
+ );
115690
+ }
115691
+ const sitelinkCount = countValidSitelinks(ext.sitelinks);
115692
+ if (sitelinkCount < PMAX_POLICY_SITELINK_MIN) {
115693
+ errors.push(
115694
+ `campaignExtensions.sitelinks \u81F3\u5C11 ${PMAX_POLICY_SITELINK_MIN} \u6761\u7AD9\u5185\u94FE\u63A5\uFF08text + destinationUrl\uFF0C\u5F53\u524D ${sitelinkCount}\uFF09`
115695
+ );
115696
+ }
115697
+ if (!ext.leadForm) {
115698
+ errors.push("campaignExtensions.leadForm \u5FC5\u586B\uFF08\u6F5C\u5728\u5BA2\u6237\u8868\u5355\uFF09");
115699
+ }
115700
+ if (!ext.businessMessage) {
115701
+ errors.push("campaignExtensions.businessMessage \u5FC5\u586B\uFF08WhatsApp \u79C1\u4FE1\uFF09");
115702
+ }
115703
+ }
115704
+ function convertExtensionsForBatchJobToCampaignExtensions(items) {
115705
+ const config = {
115706
+ callouts: [],
115707
+ structuredSnippets: [],
115708
+ sitelinks: []
115709
+ };
115710
+ const warnings = [];
115711
+ for (let i = 0; i < items.length; i++) {
115712
+ const item = items[i];
115713
+ if (!item || typeof item !== "object") continue;
115714
+ const ext = item;
115715
+ const type = String(ext.typeV2 ?? ext.TypeV2 ?? ext.AssetFieldType ?? "").toUpperCase();
115716
+ const props = ext.Properties ?? {};
115717
+ if (type === "CALLOUT") {
115718
+ const text = String(props.Text ?? props.CalloutText ?? "").trim();
115719
+ if (text) config.callouts.push(text);
115720
+ continue;
115721
+ }
115722
+ if (type === "SITELINK") {
115723
+ const text = String(props.Text ?? props.LinkText ?? "").trim();
115724
+ const destinationUrl = String(props.DestinationUrl ?? "").trim();
115725
+ if (text && destinationUrl) {
115726
+ config.sitelinks.push({
115727
+ text,
115728
+ destinationUrl,
115729
+ line2: String(props.Line2 ?? props.Description1 ?? "").trim() || void 0,
115730
+ line3: String(props.Line3 ?? props.Description2 ?? "").trim() || void 0
115731
+ });
115732
+ }
115733
+ continue;
115734
+ }
115735
+ if (type === "STRUCTURED_SNIPPET") {
115736
+ const headerValue = ext.structuredSnippetHeaderValue ?? ext.StructuredSnippetHeaderValue;
115737
+ if (headerValue && typeof headerValue === "object") {
115738
+ const hv = headerValue;
115739
+ const header = String(hv.key ?? hv.Key ?? "").trim();
115740
+ const rawValues = hv.value ?? hv.Value;
115741
+ const values = Array.isArray(rawValues) ? rawValues.map((v) => String(v).trim()).filter(Boolean) : [];
115742
+ if (header && values.length >= 3) {
115743
+ config.structuredSnippets.push({ header, values });
115744
+ }
115745
+ }
115746
+ continue;
115747
+ }
115748
+ if (type === "LEAD_FORM" && ext.leadForm && typeof ext.leadForm === "object") {
115749
+ config.leadForm = ext.leadForm;
115750
+ continue;
115751
+ }
115752
+ if (type === "CALL" || type === "BUSINESS_MESSAGE") {
115753
+ warnings.push(
115754
+ `ExtensionsForBatchJob[${i}]\uFF08${type}\uFF09\u65E0\u6CD5\u81EA\u52A8\u8F6C\u4E3A campaignExtensions\uFF1BPMax \u8BF7\u7528 campaignExtensions \u6216\u521B\u5EFA\u540E ad extension * \u8865\u6302`
115755
+ );
115756
+ }
115757
+ }
115758
+ if ((config.callouts?.length ?? 0) === 0) delete config.callouts;
115759
+ if ((config.structuredSnippets?.length ?? 0) === 0) delete config.structuredSnippets;
115760
+ if ((config.sitelinks?.length ?? 0) === 0) delete config.sitelinks;
115761
+ return { config, warnings };
115762
+ }
115763
+ function validatePmaxCampaignExtensions(ext, opts) {
115764
+ const errors = [];
115765
+ const warnings = [];
115766
+ const skip = opts?.skipCampaignExtensions === true;
115767
+ if (!ext && !skip) {
115768
+ const batchExt = opts?.rawConfig?.["ExtensionsForBatchJob"];
115769
+ if (Array.isArray(batchExt) && batchExt.length > 0) {
115770
+ errors.push(
115771
+ `\u68C0\u6D4B\u5230 ExtensionsForBatchJob\uFF08Search \u6A21\u677F\u5B57\u6BB5\uFF09\uFF1APMax \u987B\u6539\u7528 campaignExtensions\u3002${PMAX_EXTENSIONS_POLICY_HINT}`
115772
+ );
115773
+ const { config: converted, warnings: convertWarnings } = convertExtensionsForBatchJobToCampaignExtensions(batchExt);
115774
+ warnings.push(...convertWarnings);
115775
+ if (hasExtensionsToAttach(converted)) {
115776
+ errors.push(
115777
+ "\u53EF\u4ECE ExtensionsForBatchJob \u81EA\u52A8\u6620\u5C04\u90E8\u5206\u5B57\u6BB5\uFF1B\u8BF7\u5728 JSON \u6839\u7EA7\u6DFB\u52A0 campaignExtensions \u540E\u5220\u9664 ExtensionsForBatchJob"
115778
+ );
115779
+ }
115780
+ } else {
115781
+ errors.push(
115782
+ `\u672A\u914D\u7F6E campaignExtensions\uFF1A${PMAX_EXTENSIONS_POLICY_HINT}\uFF1B\u7528\u6237\u660E\u786E\u4E0D\u8981\u9644\u52A0\u8D44\u4EA7\u65F6\u8BBE skipCampaignExtensions: true`
115783
+ );
115784
+ }
115785
+ return { errors, warnings };
115786
+ }
115787
+ if (skip && !ext) return { errors, warnings };
115788
+ if (!ext) return { errors, warnings };
115789
+ if (opts?.rawConfig?.["ExtensionsForBatchJob"]) {
115790
+ warnings.push(
115791
+ "JSON \u4ECD\u542B ExtensionsForBatchJob\uFF08Search \u6A21\u677F\u5B57\u6BB5\uFF09\uFF1B\u8BF7\u5220\u8BE5\u5B57\u6BB5\u5E76\u4EC5\u4FDD\u7559 campaignExtensions"
115792
+ );
115793
+ }
115794
+ const callouts = ext.callouts ?? [];
115795
+ for (let i = 0; i < callouts.length; i++) {
115796
+ const text = callouts[i]?.trim();
115797
+ if (!text) {
115798
+ errors.push(`campaignExtensions.callouts[${i}] \u4E0D\u80FD\u4E3A\u7A7A`);
115799
+ continue;
115800
+ }
115801
+ if (text.length > CALLOUT_TEXT_MAX_LEN) {
115802
+ errors.push(
115803
+ `campaignExtensions.callouts[${i}] \u8D85\u8FC7 ${CALLOUT_TEXT_MAX_LEN} \u5B57\u7B26\uFF08\u5F53\u524D ${text.length}\uFF09\uFF1A"${text}"`
115804
+ );
115805
+ }
115806
+ }
115807
+ const snippets = ext.structuredSnippets ?? [];
115808
+ for (let i = 0; i < snippets.length; i++) {
115809
+ const s = snippets[i];
115810
+ const prefix = `campaignExtensions.structuredSnippets[${i}]`;
115811
+ if (!s?.header?.trim()) {
115812
+ errors.push(`${prefix}.header \u4E0D\u80FD\u4E3A\u7A7A`);
115813
+ }
115814
+ const values = (s?.values ?? []).map((v) => v?.trim()).filter(Boolean);
115815
+ if (values.length < 3) {
115816
+ errors.push(`${prefix}.values \u81F3\u5C11 3 \u4E2A\u975E\u7A7A\u503C\uFF08\u5F53\u524D ${values.length}\uFF09`);
115817
+ }
115818
+ }
115819
+ const sitelinks = ext.sitelinks ?? [];
115820
+ for (let i = 0; i < sitelinks.length; i++) {
115821
+ validatePmaxSitelinkSpec(sitelinks[i], `campaignExtensions.sitelinks[${i}]`, errors, warnings);
115822
+ }
115823
+ if (ext.leadForm) {
115824
+ errors.push(...validateLeadFormPayload(ext.leadForm, "campaignExtensions.leadForm"));
115825
+ }
115826
+ if (ext.businessMessage) {
115827
+ errors.push(
115828
+ ...validateBusinessMessagePayload(ext.businessMessage, "campaignExtensions.businessMessage")
115829
+ );
115830
+ warnings.push(
115831
+ "WhatsApp\uFF08BUSINESS_MESSAGE\uFF09\u9700 Google API \u767D\u540D\u5355\uFF1B\u672A\u5F00\u901A\u4F1A\u8FD4\u56DE CUSTOMER_NOT_ON_ALLOWLIST_FOR_MESSAGE_ASSETS"
115832
+ );
115833
+ }
115834
+ if (!skip) {
115835
+ validatePmaxExtensionsPolicyCounts(ext, errors);
115836
+ }
115837
+ return { errors, warnings };
115838
+ }
115839
+ function hasExtensionsToAttach(ext) {
115840
+ if (!ext) return false;
115841
+ return countNonEmptyCallouts(ext.callouts) > 0 || countValidSnippets(ext.structuredSnippets) > 0 || countValidSitelinks(ext.sitelinks) > 0 || Boolean(ext.leadForm) || Boolean(ext.businessMessage);
115842
+ }
115843
+ async function postExtension(config, googleApiUrl, accountId, body, verbose) {
115844
+ const url = `${googleApiUrl}/extensionmanagement/extension/${accountId}`;
115845
+ try {
115846
+ const data = await apiFetch2(
115847
+ url,
115848
+ config,
115849
+ { method: "POST", body: JSON.stringify(body) },
115850
+ verbose
115851
+ );
115852
+ return { ok: true, data };
115853
+ } catch (err) {
115854
+ return { ok: false, error: err instanceof Error ? err.message : String(err) };
115855
+ }
115856
+ }
115857
+ function buildCalloutBody(accountId, campaignId, text) {
115858
+ return {
115859
+ activeuseridg: accountId,
115860
+ campaignId,
115861
+ level: "Campaign",
115862
+ typeV2: "CALLOUT",
115863
+ assetFieldType: "CALLOUT",
115864
+ properties: { Text: text.trim() }
115865
+ };
115866
+ }
115867
+ function buildSnippetBody(accountId, campaignId, header, values) {
115868
+ return {
115869
+ activeuseridg: accountId,
115870
+ campaignId,
115871
+ level: "Campaign",
115872
+ typeV2: "STRUCTURED_SNIPPET",
115873
+ assetFieldType: "STRUCTURED_SNIPPET",
115874
+ structuredSnippetHeaderValue: {
115875
+ key: header.trim(),
115876
+ value: values.map((v) => v.trim()).filter(Boolean)
115877
+ }
115878
+ };
115879
+ }
115880
+ function buildSitelinkBody(accountId, campaignId, link) {
115881
+ const text = link.text.trim();
115882
+ const line2 = link.line2?.trim() || text;
115883
+ const line3 = link.line3?.trim() || line2;
115884
+ return {
115885
+ activeuseridg: accountId,
115886
+ campaignId,
115887
+ level: "Campaign",
115888
+ typeV2: "SITELINK",
115889
+ assetFieldType: "SITELINK",
115890
+ properties: {
115891
+ Text: text,
115892
+ Line2: line2,
115893
+ Line3: line3,
115894
+ DestinationUrl: link.destinationUrl.trim()
115895
+ }
115896
+ };
115897
+ }
115898
+ function buildLeadFormBodyForCampaign(accountId, campaignId, leadForm) {
115899
+ return buildLeadFormExtensionBody({ account: accountId, campaignId, leadForm });
115900
+ }
115901
+ async function attachPmaxCampaignExtensions(opts) {
115902
+ const ext = opts.extensions;
115903
+ if (!hasExtensionsToAttach(ext)) {
115904
+ return {
115905
+ callouts: [],
115906
+ structuredSnippets: [],
115907
+ sitelinks: [],
115908
+ allOk: true,
115909
+ skippedReason: "\u672A\u914D\u7F6E campaignExtensions \u6216\u5185\u5BB9\u4E3A\u7A7A"
115910
+ };
115911
+ }
115912
+ const result = {
115913
+ callouts: [],
115914
+ structuredSnippets: [],
115915
+ sitelinks: [],
115916
+ allOk: true
115917
+ };
115918
+ for (const raw of ext.callouts ?? []) {
115919
+ const text = raw?.trim();
115920
+ if (!text) continue;
115921
+ if (opts.logProgress) console.log(`
115922
+ \u6302\u8F7D\u5BA3\u4F20\u4FE1\u606F\uFF1A${text}`);
115923
+ const posted = await postExtension(
115924
+ opts.config,
115925
+ opts.googleApiUrl,
115926
+ opts.accountId,
115927
+ buildCalloutBody(opts.accountId, opts.campaignId, text),
115928
+ opts.verbose
115929
+ );
115930
+ if (posted.ok) {
115931
+ result.callouts.push({
115932
+ ok: true,
115933
+ id: String(posted.data["id"] ?? ""),
115934
+ label: text
115935
+ });
115936
+ } else {
115937
+ result.allOk = false;
115938
+ result.callouts.push({ ok: false, error: posted.error, label: text });
115939
+ }
115940
+ }
115941
+ for (const s of ext.structuredSnippets ?? []) {
115942
+ const header = s?.header?.trim();
115943
+ const values = (s?.values ?? []).map((v) => v?.trim()).filter(Boolean);
115944
+ if (!header || values.length < 3) continue;
115945
+ const label = `${header}: ${values.join(", ")}`;
115946
+ if (opts.logProgress) console.log(`
115947
+ \u6302\u8F7D\u7ED3\u6784\u5316\u6458\u8981\uFF1A${label}`);
115948
+ const posted = await postExtension(
115949
+ opts.config,
115950
+ opts.googleApiUrl,
115951
+ opts.accountId,
115952
+ buildSnippetBody(opts.accountId, opts.campaignId, header, values),
115953
+ opts.verbose
115954
+ );
115955
+ if (posted.ok) {
115956
+ result.structuredSnippets.push({
115957
+ ok: true,
115958
+ id: String(posted.data["id"] ?? ""),
115959
+ label
115960
+ });
115961
+ } else {
115962
+ result.allOk = false;
115963
+ result.structuredSnippets.push({ ok: false, error: posted.error, label });
115964
+ }
115965
+ }
115966
+ for (const link of ext.sitelinks ?? []) {
115967
+ const text = link?.text?.trim();
115968
+ const url = link?.destinationUrl?.trim();
115969
+ if (!text || !url) continue;
115970
+ if (opts.logProgress) console.log(`
115971
+ \u6302\u8F7D\u7AD9\u5185\u94FE\u63A5\uFF1A${text} \u2192 ${url}`);
115972
+ const posted = await postExtension(
115973
+ opts.config,
115974
+ opts.googleApiUrl,
115975
+ opts.accountId,
115976
+ buildSitelinkBody(opts.accountId, opts.campaignId, link),
115977
+ opts.verbose
115978
+ );
115979
+ if (posted.ok) {
115980
+ result.sitelinks.push({
115981
+ ok: true,
115982
+ id: String(posted.data["id"] ?? ""),
115983
+ label: text
115984
+ });
115985
+ } else {
115986
+ result.allOk = false;
115987
+ result.sitelinks.push({ ok: false, error: posted.error, label: text });
115988
+ }
115989
+ }
115990
+ if (ext.leadForm) {
115991
+ const headline = ext.leadForm.headline?.trim() || "Lead Form";
115992
+ if (opts.logProgress) console.log(`
115993
+ \u6302\u8F7D\u6F5C\u5728\u5BA2\u6237\u8868\u5355\uFF1A${headline}`);
115994
+ const posted = await postExtension(
115995
+ opts.config,
115996
+ opts.googleApiUrl,
115997
+ opts.accountId,
115998
+ buildLeadFormBodyForCampaign(opts.accountId, opts.campaignId, ext.leadForm),
115999
+ opts.verbose
116000
+ );
116001
+ if (posted.ok) {
116002
+ result.leadForm = {
116003
+ ok: true,
116004
+ id: String(posted.data["id"] ?? ""),
116005
+ label: headline
116006
+ };
116007
+ } else {
116008
+ result.allOk = false;
116009
+ result.leadForm = { ok: false, error: posted.error, label: headline };
116010
+ }
116011
+ }
116012
+ if (ext.businessMessage) {
116013
+ const label = ext.businessMessage.starterMessage?.trim().slice(0, 40) || "WhatsApp";
116014
+ if (opts.logProgress) console.log(`
116015
+ \u6302\u8F7D WhatsApp \u79C1\u4FE1\uFF1A${label}`);
116016
+ const posted = await postExtension(
116017
+ opts.config,
116018
+ opts.googleApiUrl,
116019
+ opts.accountId,
116020
+ buildBusinessMessageBodyForCampaign(opts.accountId, opts.campaignId, ext.businessMessage),
116021
+ opts.verbose
116022
+ );
116023
+ if (posted.ok) {
116024
+ result.whatsapp = {
116025
+ ok: true,
116026
+ id: String(posted.data["id"] ?? ""),
116027
+ label
116028
+ };
116029
+ } else {
116030
+ result.allOk = false;
116031
+ result.whatsapp = { ok: false, error: posted.error, label };
116032
+ }
116033
+ }
116034
+ return result;
116035
+ }
116036
+ function formatPmaxExtensionsAttachErrors(result) {
116037
+ const msgs = [];
116038
+ for (const c of result.callouts) {
116039
+ if (!c.ok) msgs.push(`\u5BA3\u4F20\u4FE1\u606F\u300C${c.label}\u300D\u5931\u8D25\uFF1A${c.error}`);
116040
+ }
116041
+ for (const s of result.structuredSnippets) {
116042
+ if (!s.ok) msgs.push(`\u7ED3\u6784\u5316\u6458\u8981\u300C${s.label}\u300D\u5931\u8D25\uFF1A${s.error}`);
116043
+ }
116044
+ for (const sl of result.sitelinks) {
116045
+ if (!sl.ok) msgs.push(`\u7AD9\u5185\u94FE\u63A5\u300C${sl.label}\u300D\u5931\u8D25\uFF1A${sl.error}`);
116046
+ }
116047
+ if (result.leadForm && !result.leadForm.ok) {
116048
+ msgs.push(`\u6F5C\u5728\u5BA2\u6237\u8868\u5355\u300C${result.leadForm.label}\u300D\u5931\u8D25\uFF1A${result.leadForm.error}`);
116049
+ }
116050
+ if (result.whatsapp && !result.whatsapp.ok) {
116051
+ msgs.push(`WhatsApp\u300C${result.whatsapp.label}\u300D\u5931\u8D25\uFF1A${result.whatsapp.error}`);
116052
+ }
116053
+ return msgs;
116054
+ }
116055
+
116056
+ // src/commands/ad/pmax-load.ts
115632
116057
  function loadPmaxCreateConfig(configFile) {
115633
116058
  const cfg = tryLoadPmaxCreateConfig(configFile);
115634
116059
  if (!cfg) {
@@ -115640,9 +116065,35 @@ function loadPmaxCreateConfig(configFile) {
115640
116065
  return cfg;
115641
116066
  }
115642
116067
  var PMAX_VIDEO_PATH_ALIASES = ["video", "videoFile", "localVideo"];
116068
+ function normalizeCampaignExtensions(stripped, cfg) {
116069
+ const migrationWarnings = [];
116070
+ if (!cfg.campaignExtensions) {
116071
+ const alias = stripped["extensions"];
116072
+ if (alias && typeof alias === "object" && !Array.isArray(alias)) {
116073
+ cfg.campaignExtensions = alias;
116074
+ migrationWarnings.push("\u5DF2\u5C06 extensions \u522B\u540D\u6620\u5C04\u4E3A campaignExtensions");
116075
+ }
116076
+ }
116077
+ const batchExt = stripped["ExtensionsForBatchJob"];
116078
+ if (!cfg.campaignExtensions && Array.isArray(batchExt) && batchExt.length > 0) {
116079
+ const { config: converted, warnings } = convertExtensionsForBatchJobToCampaignExtensions(batchExt);
116080
+ migrationWarnings.push(...warnings);
116081
+ if (hasExtensionsToAttach(converted)) {
116082
+ cfg.campaignExtensions = converted;
116083
+ migrationWarnings.push(
116084
+ "\u5DF2\u5C06 ExtensionsForBatchJob \u81EA\u52A8\u8F6C\u6362\u4E3A campaignExtensions\uFF08\u8BF7\u6539 JSON \u6839\u7EA7\u5B57\u6BB5\u5E76\u5220\u9664 ExtensionsForBatchJob\uFF09"
116085
+ );
116086
+ }
116087
+ }
116088
+ if (stripped["skipCampaignExtensions"] === true) {
116089
+ cfg.skipCampaignExtensions = true;
116090
+ }
116091
+ return migrationWarnings;
116092
+ }
115643
116093
  function normalizePmaxCreateConfig(raw) {
115644
116094
  const stripped = stripMetaKeys(raw);
115645
116095
  const cfg = { ...stripped };
116096
+ normalizeCampaignExtensions(stripped, cfg);
115646
116097
  if (!cfg.videoPath?.trim()) {
115647
116098
  for (const key of PMAX_VIDEO_PATH_ALIASES) {
115648
116099
  const v = stripped[key];
@@ -116155,230 +116606,6 @@ async function linkPmaxVideoAfterCreate(opts) {
116155
116606
  }
116156
116607
  }
116157
116608
 
116158
- // src/commands/ad/pmax-campaign-extensions.ts
116159
- init_auth();
116160
- function validatePmaxCampaignExtensions(ext) {
116161
- const errors = [];
116162
- const warnings = [];
116163
- if (!ext) return { errors, warnings };
116164
- const callouts = ext.callouts ?? [];
116165
- for (let i = 0; i < callouts.length; i++) {
116166
- const text = callouts[i]?.trim();
116167
- if (!text) {
116168
- errors.push(`campaignExtensions.callouts[${i}] \u4E0D\u80FD\u4E3A\u7A7A`);
116169
- continue;
116170
- }
116171
- if (text.length > CALLOUT_TEXT_MAX_LEN) {
116172
- errors.push(
116173
- `campaignExtensions.callouts[${i}] \u8D85\u8FC7 ${CALLOUT_TEXT_MAX_LEN} \u5B57\u7B26\uFF08\u5F53\u524D ${text.length}\uFF09\uFF1A"${text}"`
116174
- );
116175
- }
116176
- }
116177
- const snippets = ext.structuredSnippets ?? [];
116178
- for (let i = 0; i < snippets.length; i++) {
116179
- const s = snippets[i];
116180
- const prefix = `campaignExtensions.structuredSnippets[${i}]`;
116181
- if (!s?.header?.trim()) {
116182
- errors.push(`${prefix}.header \u4E0D\u80FD\u4E3A\u7A7A`);
116183
- }
116184
- const values = (s?.values ?? []).map((v) => v?.trim()).filter(Boolean);
116185
- if (values.length < 3) {
116186
- errors.push(`${prefix}.values \u81F3\u5C11 3 \u4E2A\u975E\u7A7A\u503C\uFF08\u5F53\u524D ${values.length}\uFF09`);
116187
- }
116188
- }
116189
- if (ext.leadForm) {
116190
- const lfErrors = validateLeadFormPayload(ext.leadForm, "campaignExtensions.leadForm");
116191
- errors.push(...lfErrors);
116192
- }
116193
- if (ext.businessMessage) {
116194
- errors.push(
116195
- ...validateBusinessMessagePayload(ext.businessMessage, "campaignExtensions.businessMessage")
116196
- );
116197
- warnings.push(
116198
- "WhatsApp\uFF08BUSINESS_MESSAGE\uFF09\u9700 Google API \u767D\u540D\u5355\uFF1B\u672A\u5F00\u901A\u4F1A\u8FD4\u56DE CUSTOMER_NOT_ON_ALLOWLIST_FOR_MESSAGE_ASSETS"
116199
- );
116200
- }
116201
- if (callouts.length === 0 && snippets.length === 0 && !ext.leadForm && !ext.businessMessage) {
116202
- warnings.push(
116203
- "campaignExtensions \u5DF2\u58F0\u660E\u4F46 callouts / structuredSnippets / leadForm / businessMessage \u5747\u4E3A\u7A7A\uFF0C\u521B\u5EFA\u65F6\u5C06\u8DF3\u8FC7\u9644\u52A0\u8D44\u4EA7"
116204
- );
116205
- }
116206
- return { errors, warnings };
116207
- }
116208
- function hasExtensionsToAttach(ext) {
116209
- if (!ext) return false;
116210
- const hasCallouts = (ext.callouts ?? []).some((t) => t?.trim());
116211
- const hasSnippets = (ext.structuredSnippets ?? []).some(
116212
- (s) => s?.header?.trim() && (s.values ?? []).some((v) => v?.trim())
116213
- );
116214
- return hasCallouts || hasSnippets || Boolean(ext.leadForm) || Boolean(ext.businessMessage);
116215
- }
116216
- async function postExtension(config, googleApiUrl, accountId, body, verbose) {
116217
- const url = `${googleApiUrl}/extensionmanagement/extension/${accountId}`;
116218
- try {
116219
- const data = await apiFetch2(
116220
- url,
116221
- config,
116222
- { method: "POST", body: JSON.stringify(body) },
116223
- verbose
116224
- );
116225
- return { ok: true, data };
116226
- } catch (err) {
116227
- return { ok: false, error: err instanceof Error ? err.message : String(err) };
116228
- }
116229
- }
116230
- function buildCalloutBody(accountId, campaignId, text) {
116231
- return {
116232
- activeuseridg: accountId,
116233
- campaignId,
116234
- level: "Campaign",
116235
- typeV2: "CALLOUT",
116236
- assetFieldType: "CALLOUT",
116237
- properties: { Text: text.trim() }
116238
- };
116239
- }
116240
- function buildSnippetBody(accountId, campaignId, header, values) {
116241
- return {
116242
- activeuseridg: accountId,
116243
- campaignId,
116244
- level: "Campaign",
116245
- typeV2: "STRUCTURED_SNIPPET",
116246
- assetFieldType: "STRUCTURED_SNIPPET",
116247
- structuredSnippetHeaderValue: {
116248
- key: header.trim(),
116249
- value: values.map((v) => v.trim()).filter(Boolean)
116250
- }
116251
- };
116252
- }
116253
- function buildLeadFormBodyForCampaign(accountId, campaignId, leadForm) {
116254
- return buildLeadFormExtensionBody({ account: accountId, campaignId, leadForm });
116255
- }
116256
- async function attachPmaxCampaignExtensions(opts) {
116257
- const ext = opts.extensions;
116258
- if (!hasExtensionsToAttach(ext)) {
116259
- return {
116260
- callouts: [],
116261
- structuredSnippets: [],
116262
- allOk: true,
116263
- skippedReason: "\u672A\u914D\u7F6E campaignExtensions \u6216\u5185\u5BB9\u4E3A\u7A7A"
116264
- };
116265
- }
116266
- const result = {
116267
- callouts: [],
116268
- structuredSnippets: [],
116269
- allOk: true
116270
- };
116271
- for (const raw of ext.callouts ?? []) {
116272
- const text = raw?.trim();
116273
- if (!text) continue;
116274
- if (opts.logProgress) console.log(`
116275
- \u6302\u8F7D\u5BA3\u4F20\u4FE1\u606F\uFF1A${text}`);
116276
- const posted = await postExtension(
116277
- opts.config,
116278
- opts.googleApiUrl,
116279
- opts.accountId,
116280
- buildCalloutBody(opts.accountId, opts.campaignId, text),
116281
- opts.verbose
116282
- );
116283
- if (posted.ok) {
116284
- result.callouts.push({
116285
- ok: true,
116286
- id: String(posted.data["id"] ?? ""),
116287
- label: text
116288
- });
116289
- } else {
116290
- result.allOk = false;
116291
- result.callouts.push({ ok: false, error: posted.error, label: text });
116292
- }
116293
- }
116294
- for (const s of ext.structuredSnippets ?? []) {
116295
- const header = s?.header?.trim();
116296
- const values = (s?.values ?? []).map((v) => v?.trim()).filter(Boolean);
116297
- if (!header || values.length < 3) continue;
116298
- const label = `${header}: ${values.join(", ")}`;
116299
- if (opts.logProgress) console.log(`
116300
- \u6302\u8F7D\u7ED3\u6784\u5316\u6458\u8981\uFF1A${label}`);
116301
- const posted = await postExtension(
116302
- opts.config,
116303
- opts.googleApiUrl,
116304
- opts.accountId,
116305
- buildSnippetBody(opts.accountId, opts.campaignId, header, values),
116306
- opts.verbose
116307
- );
116308
- if (posted.ok) {
116309
- result.structuredSnippets.push({
116310
- ok: true,
116311
- id: String(posted.data["id"] ?? ""),
116312
- label
116313
- });
116314
- } else {
116315
- result.allOk = false;
116316
- result.structuredSnippets.push({ ok: false, error: posted.error, label });
116317
- }
116318
- }
116319
- if (ext.leadForm) {
116320
- const headline = ext.leadForm.headline?.trim() || "Lead Form";
116321
- if (opts.logProgress) console.log(`
116322
- \u6302\u8F7D\u6F5C\u5728\u5BA2\u6237\u8868\u5355\uFF1A${headline}`);
116323
- const posted = await postExtension(
116324
- opts.config,
116325
- opts.googleApiUrl,
116326
- opts.accountId,
116327
- buildLeadFormBodyForCampaign(opts.accountId, opts.campaignId, ext.leadForm),
116328
- opts.verbose
116329
- );
116330
- if (posted.ok) {
116331
- result.leadForm = {
116332
- ok: true,
116333
- id: String(posted.data["id"] ?? ""),
116334
- label: headline
116335
- };
116336
- } else {
116337
- result.allOk = false;
116338
- result.leadForm = { ok: false, error: posted.error, label: headline };
116339
- }
116340
- }
116341
- if (ext.businessMessage) {
116342
- const label = ext.businessMessage.starterMessage?.trim().slice(0, 40) || "WhatsApp";
116343
- if (opts.logProgress) console.log(`
116344
- \u6302\u8F7D WhatsApp \u79C1\u4FE1\uFF1A${label}`);
116345
- const posted = await postExtension(
116346
- opts.config,
116347
- opts.googleApiUrl,
116348
- opts.accountId,
116349
- buildBusinessMessageBodyForCampaign(opts.accountId, opts.campaignId, ext.businessMessage),
116350
- opts.verbose
116351
- );
116352
- if (posted.ok) {
116353
- result.whatsapp = {
116354
- ok: true,
116355
- id: String(posted.data["id"] ?? ""),
116356
- label
116357
- };
116358
- } else {
116359
- result.allOk = false;
116360
- result.whatsapp = { ok: false, error: posted.error, label };
116361
- }
116362
- }
116363
- return result;
116364
- }
116365
- function formatPmaxExtensionsAttachErrors(result) {
116366
- const msgs = [];
116367
- for (const c of result.callouts) {
116368
- if (!c.ok) msgs.push(`\u5BA3\u4F20\u4FE1\u606F\u300C${c.label}\u300D\u5931\u8D25\uFF1A${c.error}`);
116369
- }
116370
- for (const s of result.structuredSnippets) {
116371
- if (!s.ok) msgs.push(`\u7ED3\u6784\u5316\u6458\u8981\u300C${s.label}\u300D\u5931\u8D25\uFF1A${s.error}`);
116372
- }
116373
- if (result.leadForm && !result.leadForm.ok) {
116374
- msgs.push(`\u6F5C\u5728\u5BA2\u6237\u8868\u5355\u300C${result.leadForm.label}\u300D\u5931\u8D25\uFF1A${result.leadForm.error}`);
116375
- }
116376
- if (result.whatsapp && !result.whatsapp.ok) {
116377
- msgs.push(`WhatsApp\u300C${result.whatsapp.label}\u300D\u5931\u8D25\uFF1A${result.whatsapp.error}`);
116378
- }
116379
- return msgs;
116380
- }
116381
-
116382
116609
  // src/commands/ad/pmax-create.ts
116383
116610
  function printVideoLinkRecoveryHint(accountId, assetGroupId, campaignId, youtubeTarget) {
116384
116611
  const cid = campaignId != null ? ` --campaign-id ${campaignId}` : "";
@@ -116406,7 +116633,11 @@ async function runAdPmaxCreate(opts) {
116406
116633
  cfg
116407
116634
  );
116408
116635
  const { errors: extErrors, warnings: extWarnings } = validatePmaxCampaignExtensions(
116409
- cfg.campaignExtensions
116636
+ cfg.campaignExtensions,
116637
+ {
116638
+ skipCampaignExtensions: cfg.skipCampaignExtensions,
116639
+ rawConfig: rawCfg
116640
+ }
116410
116641
  );
116411
116642
  const errors = [...deprecatedVideoKeys, ...cfgErrors, ...imgErrors, ...videoErrors, ...extErrors];
116412
116643
  const warnings = [...cfgWarnings, ...imgWarnings, ...videoWarnings, ...extWarnings];
@@ -116551,7 +116782,7 @@ async function runAdPmaxCreate(opts) {
116551
116782
  ` \u53EF\u624B\u52A8\u8865\u6302\uFF1Asiluzan-tso ad extension callout|snippet|lead-form -a ${accountId} --campaign-id ${campaignId} \u2026
116552
116783
  `
116553
116784
  );
116554
- } else if (extensionsResult?.allOk && extensionsResult.callouts.length + extensionsResult.structuredSnippets.length + (extensionsResult.leadForm ? 1 : 0) + (extensionsResult.whatsapp ? 1 : 0) > 0) {
116785
+ } else if (extensionsResult?.allOk && extensionsResult.callouts.length + extensionsResult.structuredSnippets.length + extensionsResult.sitelinks.length + (extensionsResult.leadForm ? 1 : 0) + (extensionsResult.whatsapp ? 1 : 0) > 0) {
116555
116786
  if (!opts.jsonOut) {
116556
116787
  console.log("\n\u2705 Campaign \u9644\u52A0\u8D44\u4EA7\u5DF2\u6302\u8F7D");
116557
116788
  }
@@ -116609,7 +116840,11 @@ async function runAdPmaxValidate(opts) {
116609
116840
  cfg
116610
116841
  );
116611
116842
  const { errors: extErrors, warnings: extWarnings } = validatePmaxCampaignExtensions(
116612
- cfg.campaignExtensions
116843
+ cfg.campaignExtensions,
116844
+ {
116845
+ skipCampaignExtensions: cfg.skipCampaignExtensions,
116846
+ rawConfig: rawCfg
116847
+ }
116613
116848
  );
116614
116849
  const errors = [...deprecatedVideoKeys, ...cfgErrors, ...imgErrors, ...videoErrors, ...extErrors];
116615
116850
  const warnings = [...cfgWarnings, ...imgWarnings, ...videoWarnings, ...extWarnings];
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "slug": "siluzan-tso",
3
- "version": "1.1.29-beta.17",
4
- "publishedAt": 1781748956615
3
+ "version": "1.1.29-beta.18",
4
+ "publishedAt": 1781751946624
5
5
  }
@@ -11,10 +11,12 @@
11
11
  "改已上线品牌:先 pmax-get 看 _brandGuidelinesActive;true 用 pmax-brand-assets-edit,false 用 pmax-assets-update 或 pmax-brand-guidelines-enable",
12
12
  "本地视频:填 videoPath(或别名 video);创建后 CLI 自动 PyAPI 上传并链接,与 --json-out 无关",
13
13
  "提交前:ad pmax-validate → 用户确认 → ad pmax-create",
14
- "campaignExtensions 可选:创建成功后 CLI 自动挂 callout/snippet/leadForm(非 pmax POST body)",
14
+ "campaignExtensions 默认必填:宣传信息≥20、结构化摘要≥20、站内链接≥6、leadForm、businessMessage",
15
+ "文案门禁:headlines 15、longHeadlines 5(Google 上限须填满)、descriptions 5",
16
+ "勿用 Search 的 ExtensionsForBatchJob;PMax 用 campaignExtensions(CLI 会尝试自动转换 CALLOUT/SNIPPET)",
15
17
  "Lead Gen/B2B 询盘方案:默认保留 campaignExtensions.leadForm(勿只写 callouts/snippets);用户明确不要表单才删 leadForm",
16
18
  "方案 Markdown 须单列「潜在客户表单」节(标题/描述/字段/privacyPolicyUrl);与 JSON 一致",
17
- "不需要任何附加资产时删除整个 campaignExtensions "
19
+ "不需要任何附加资产时设 skipCampaignExtensions: true(勿仅删除 campaignExtensions 块)"
18
20
  ]
19
21
  },
20
22
 
@@ -17,7 +17,8 @@
17
17
  | 金额 | JSON 填**主币种「元」**;CLI 提交前 `budget`、`targetCpa_BidingAmount` ×100 |
18
18
  | 图片 | **只填 `imagePaths`** 指向本地 PNG/JPEG;`pmax-create` 会自动 multipart 上传并用 assetId 创建(勿把 Base64 提交进 Git) |
19
19
  | 视频 | JSON 填 **`videoPath`**(别名 `video` 亦可);`pmax-create` 成功后 **必定**经 PyAPI 上传并链接(含 `--json-out`)。已有 YouTube 用 `youtubeUrlOrId` |
20
- | 附加资产 | 可选填 **`campaignExtensions`** |
20
+ | 附加资产 | **必填** `campaignExtensions`:宣传信息 ≥20、结构化摘要 ≥20、站内链接 ≥6、leadForm、WhatsApp |
21
+ | 文案数量 | 短标题 15、长 nga 5(Google API 上限,须填满)、描述 5 |
21
22
  | Lead Gen 方案 | **默认**在 `campaignExtensions` 含 **`leadForm`**(B2B/询盘/留资);仅 callouts/snippets 不算完整方案;用户明确不要才省略 |
22
23
  | 存量补表单 | 活动已创建时用 `ad extension lead-form`(见 `pmax-lead-form-template.md` 方式 B) |
23
24
  | 改已上线 PMax | 先 `ad pmax-get` 看 `_brandGuidelinesActive`;改品牌见 `pmax-api.md` § Brand Guidelines |
@@ -65,7 +65,7 @@
65
65
  - **步骤(PMax 方案 → 创建)**:
66
66
  1. 账户:`list-accounts -m Google -k <id>`;落地页与品牌从官网/RAG 归纳。
67
67
  2. 地域/语言:`ad geo search` 取 location id;语言 id 写入 JSON。
68
- 3. 复制 `pmax-create-template.json` 填文案/预算/图片;**Lead Gen/B2B 默认** `campaignExtensions.leadForm`(方案 Markdown 须单列表单节)。
68
+ 3. 复制 `pmax-create-template.json` 填文案/预算/图片;**必须**含 `campaignExtensions`(至少 callouts + structuredSnippets);**Lead Gen/B2B 默认** `campaignExtensions.leadForm`(方案 Markdown 须单列表单节)。
69
69
  4. 门禁:`ad pmax-validate --config-file ./pmax.json --json-out ./snap-pmax`。
70
70
  5. 输出 JSON + Markdown 方案 → 用户确认 → `ad pmax-create --commit "…"`。
71
71
  6. 复核:`ad campaigns` / `ad pmax-get`;缺表单时 `ad extension lead-form` 补挂。
@@ -9,7 +9,7 @@ $ErrorActionPreference = 'Stop'
9
9
  # -- Package info (injected at build time) ------------------------------------
10
10
  $PKG_NAME = 'siluzan-tso-cli'
11
11
  # PKG_VERSION 锁定到与本脚本同批构建产物一致的版本,避免与 dist/skill 错位
12
- $PKG_VERSION = '1.1.29-beta.17'
12
+ $PKG_VERSION = '1.1.29-beta.18'
13
13
  $CLI_BIN = 'siluzan-tso'
14
14
  $SKILL_LABEL = 'Siluzan TSO'
15
15
  $INSTALL_CMD = 'npm install -g siluzan-tso-cli@beta'
@@ -9,7 +9,7 @@ set -euo pipefail
9
9
  # -- Package info (injected at build time) ------------------------------------
10
10
  readonly PKG_NAME="siluzan-tso-cli"
11
11
  # PKG_VERSION 锁定到与本脚本同批构建产物一致的版本,避免与 dist/skill 错位
12
- readonly PKG_VERSION="1.1.29-beta.17"
12
+ readonly PKG_VERSION="1.1.29-beta.18"
13
13
  readonly CLI_BIN="siluzan-tso"
14
14
  readonly SKILL_LABEL="Siluzan TSO"
15
15
  readonly INSTALL_CMD="npm install -g siluzan-tso-cli@beta"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "siluzan-tso-cli",
3
- "version": "1.1.29-beta.17",
3
+ "version": "1.1.29-beta.18",
4
4
  "description": "Siluzan 广告账户管理 CLI — 查询账户、余额、消耗数据,管理绑定关系与充值。",
5
5
  "keywords": [
6
6
  "ad-account",