@koda-sl/baker-cli 0.884.0 → 0.885.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +3 -0
  2. package/dist/{account-assets-FJFPB7KD.js → account-assets-Q2O3FRUE.js} +6 -6
  3. package/dist/{account-level-CB6I4X5W.js → account-level-NBEQ6R7X.js} +3 -3
  4. package/dist/{ads-Z2YUBDUF.js → ads-4QBIYBPH.js} +2 -2
  5. package/dist/{ads-G3N76HWA.js → ads-HKPBNXWT.js} +10 -10
  6. package/dist/{adsets-2HV6TJJP.js → adsets-IBLZP6EM.js} +9 -9
  7. package/dist/{asset-writes-ZOVD5O5X.js → asset-writes-NTEJDVVM.js} +3 -3
  8. package/dist/{audience-writes-36E6ECON.js → audience-writes-DJHKIJP7.js} +2 -2
  9. package/dist/{audiences-65JSGH4L.js → audiences-7TGXZS3M.js} +6 -6
  10. package/dist/{campaigns-PP3MFPJR.js → campaigns-VD7UOTRV.js} +9 -9
  11. package/dist/{catalogs-UYYPZRFW.js → catalogs-H2T4Z6AS.js} +2 -2
  12. package/dist/{chunk-BRHYK4HQ.js → chunk-G7Q43JEZ.js} +5 -4
  13. package/dist/{chunk-BRHYK4HQ.js.map → chunk-G7Q43JEZ.js.map} +1 -1
  14. package/dist/{chunk-ZGYIG6OM.js → chunk-LUF2VYOK.js} +2 -2
  15. package/dist/{chunk-3F6AXSPB.js → chunk-ZJUUAZKY.js} +2 -2
  16. package/dist/cli.js +1 -1
  17. package/dist/{copy-writes-TEJRR2W2.js → copy-writes-FGMJ7N75.js} +3 -3
  18. package/dist/{creatives-ZYY5OF5U.js → creatives-67CDPYL7.js} +4 -4
  19. package/dist/{custom-conversions-YQPOB2IR.js → custom-conversions-RZB2622Q.js} +4 -4
  20. package/dist/{draft-OHAOBGVP.js → draft-JPWMFZNZ.js} +243 -8
  21. package/dist/draft-JPWMFZNZ.js.map +1 -0
  22. package/dist/{instant-experiences-YXH2AHFI.js → instant-experiences-MF2X374W.js} +2 -2
  23. package/dist/{leads-IGOXMIEW.js → leads-IBXGNXTX.js} +2 -2
  24. package/dist/{media-QOGVG6CU.js → media-YPVGQ535.js} +3 -3
  25. package/dist/{meta-RJH5COPE.js → meta-ZQXCUKHQ.js} +30 -30
  26. package/dist/{page-photos-P2XMKTVF.js → page-photos-BEAMTVP5.js} +2 -2
  27. package/dist/{rule-writes-MSMVQDQO.js → rule-writes-CVP6CH2R.js} +2 -2
  28. package/dist/{rules-UEKJOZTV.js → rules-LZ36YNG3.js} +7 -7
  29. package/dist/{studies-TIF7PYEB.js → studies-Y6PGWT66.js} +5 -5
  30. package/dist/{study-writes-RGKBOOJ6.js → study-writes-6F6O6N4E.js} +2 -2
  31. package/dist/{targeting-YWOOD6YL.js → targeting-FRMVSXXL.js} +2 -2
  32. package/dist/{write-commands-REUTFNJ3.js → write-commands-3BMPDY3K.js} +4 -4
  33. package/package.json +1 -1
  34. package/dist/draft-OHAOBGVP.js.map +0 -1
  35. /package/dist/{account-assets-FJFPB7KD.js.map → account-assets-Q2O3FRUE.js.map} +0 -0
  36. /package/dist/{account-level-CB6I4X5W.js.map → account-level-NBEQ6R7X.js.map} +0 -0
  37. /package/dist/{ads-Z2YUBDUF.js.map → ads-4QBIYBPH.js.map} +0 -0
  38. /package/dist/{ads-G3N76HWA.js.map → ads-HKPBNXWT.js.map} +0 -0
  39. /package/dist/{adsets-2HV6TJJP.js.map → adsets-IBLZP6EM.js.map} +0 -0
  40. /package/dist/{asset-writes-ZOVD5O5X.js.map → asset-writes-NTEJDVVM.js.map} +0 -0
  41. /package/dist/{audience-writes-36E6ECON.js.map → audience-writes-DJHKIJP7.js.map} +0 -0
  42. /package/dist/{audiences-65JSGH4L.js.map → audiences-7TGXZS3M.js.map} +0 -0
  43. /package/dist/{campaigns-PP3MFPJR.js.map → campaigns-VD7UOTRV.js.map} +0 -0
  44. /package/dist/{catalogs-UYYPZRFW.js.map → catalogs-H2T4Z6AS.js.map} +0 -0
  45. /package/dist/{chunk-ZGYIG6OM.js.map → chunk-LUF2VYOK.js.map} +0 -0
  46. /package/dist/{chunk-3F6AXSPB.js.map → chunk-ZJUUAZKY.js.map} +0 -0
  47. /package/dist/{copy-writes-TEJRR2W2.js.map → copy-writes-FGMJ7N75.js.map} +0 -0
  48. /package/dist/{creatives-ZYY5OF5U.js.map → creatives-67CDPYL7.js.map} +0 -0
  49. /package/dist/{custom-conversions-YQPOB2IR.js.map → custom-conversions-RZB2622Q.js.map} +0 -0
  50. /package/dist/{instant-experiences-YXH2AHFI.js.map → instant-experiences-MF2X374W.js.map} +0 -0
  51. /package/dist/{leads-IGOXMIEW.js.map → leads-IBXGNXTX.js.map} +0 -0
  52. /package/dist/{media-QOGVG6CU.js.map → media-YPVGQ535.js.map} +0 -0
  53. /package/dist/{meta-RJH5COPE.js.map → meta-ZQXCUKHQ.js.map} +0 -0
  54. /package/dist/{page-photos-P2XMKTVF.js.map → page-photos-BEAMTVP5.js.map} +0 -0
  55. /package/dist/{rule-writes-MSMVQDQO.js.map → rule-writes-CVP6CH2R.js.map} +0 -0
  56. /package/dist/{rules-UEKJOZTV.js.map → rules-LZ36YNG3.js.map} +0 -0
  57. /package/dist/{studies-TIF7PYEB.js.map → studies-Y6PGWT66.js.map} +0 -0
  58. /package/dist/{study-writes-RGKBOOJ6.js.map → study-writes-6F6O6N4E.js.map} +0 -0
  59. /package/dist/{targeting-YWOOD6YL.js.map → targeting-FRMVSXXL.js.map} +0 -0
  60. /package/dist/{write-commands-REUTFNJ3.js.map → write-commands-3BMPDY3K.js.map} +0 -0
@@ -1,3 +1,10 @@
1
+ import {
2
+ bareAccountId,
3
+ failWriteValidation,
4
+ preflightOp
5
+ } from "./chunk-G7Q43JEZ.js";
6
+ import "./chunk-3R62EYYX.js";
7
+ import "./chunk-GDFJOCDO.js";
1
8
  import {
2
9
  handleMetaError
3
10
  } from "./chunk-LDL5VBBD.js";
@@ -9,25 +16,51 @@ import {
9
16
  SHOW_FULL_ARG,
10
17
  showEnvelope
11
18
  } from "./chunk-3TGKBO5K.js";
19
+ import {
20
+ loadJsonPayloads
21
+ } from "./chunk-FRWCTFTP.js";
22
+ import "./chunk-LVLAFUXQ.js";
12
23
  import {
13
24
  LIST_WHERE_ARG,
14
25
  draftListWhere,
15
26
  requireDraftWhere,
16
27
  wholeDraftHints
17
28
  } from "./chunk-MTMWOUKN.js";
29
+ import {
30
+ adCopyHints
31
+ } from "./chunk-S7J2JP3U.js";
32
+ import "./chunk-UKENQSZ2.js";
18
33
  import {
19
34
  hintLines,
20
35
  withHints
21
36
  } from "./chunk-D5FY4FAK.js";
37
+ import "./chunk-4DURENF2.js";
22
38
  import "./chunk-QALAJNBG.js";
39
+ import "./chunk-IHWF5UAL.js";
40
+ import "./chunk-ERSX3MKH.js";
23
41
  import {
24
42
  CHAT_READ_ARG,
25
43
  DRAFT_FULL_ARG
26
44
  } from "./chunk-X32MFGWW.js";
45
+ import "./chunk-3JLS56VK.js";
46
+ import "./chunk-KT57LMNR.js";
47
+ import "./chunk-6U2SODK6.js";
48
+ import "./chunk-KSXGH3JX.js";
49
+ import "./chunk-YSZAKQIA.js";
50
+ import "./chunk-N4TSUEJ3.js";
51
+ import "./chunk-WZ5YRUQU.js";
52
+ import "./chunk-EHD4QVEL.js";
53
+ import "./chunk-7S7QUQIM.js";
54
+ import "./chunk-BXAPQKOP.js";
27
55
  import {
28
56
  writeJsonEnvelope
29
57
  } from "./chunk-7W5KGO5H.js";
58
+ import "./chunk-SOPVIIUW.js";
59
+ import "./chunk-G4FG5EQO.js";
60
+ import "./chunk-CS4VA3GQ.js";
61
+ import "./chunk-PMI2IYXS.js";
30
62
  import {
63
+ ApiError,
31
64
  apiPost
32
65
  } from "./chunk-NRJ6A3IF.js";
33
66
  import "./chunk-GJBDT4AD.js";
@@ -42,7 +75,203 @@ import {
42
75
  import "./chunk-YQSBHWOI.js";
43
76
 
44
77
  // src/commands/ads/meta/draft.ts
78
+ import { defineCommand as defineCommand2 } from "citty";
79
+
80
+ // src/commands/ads/meta/draft-stage.ts
45
81
  import { defineCommand } from "citty";
82
+ var BATCH_MAX = 100;
83
+ var NAME = /^meta_temp_[A-Za-z0-9_-]+$/;
84
+ var STAGE_DESCRIPTION = `Stage many Meta changes from ONE file, in one call \u2014 any mix of kinds, up to ${BATCH_MAX} ops.
85
+
86
+ Start here whenever a job is more than a few staged changes: N library pictures into M ad sets, a
87
+ set of ads, a campaign tree. Never loop the single commands from a script.
88
+ baker ads meta draft stage --file ops.json --account-id act_123
89
+
90
+ The file is a JSON array (or JSON Lines, one op per line). Each op is what the single commands
91
+ build \u2014 kind, accountId (or --account-id for all), target for a change to something that exists,
92
+ payload. A create can take a name in "as" (meta_temp_<anything>); later ops in the same file use
93
+ that name wherever a ref goes, and it becomes the real ref. Upload each picture once and reuse it:
94
+ {"kind":"media.upload","as":"meta_temp_img1","payload":{"kind":"image","bakerImageId":"<id>"}}
95
+ {"kind":"adCreative.create","as":"meta_temp_cr1","payload":{"creativeType":"single","page_id":"555",
96
+ "message":"\u2026","headline":"\u2026","link":"https://example.com","imageRef":"meta_temp_img1",
97
+ "call_to_action":{"type":"LEARN_MORE"}}}
98
+ {"kind":"ad.create","payload":{"name":"Ad 1","adset_id":"6123","creative":{"creative_id":"meta_temp_cr1"},"status":"PAUSED"}}
99
+ {"kind":"ad.create","payload":{"name":"Ad 1","adset_id":"6124","creative":{"creative_id":"meta_temp_cr1"},"status":"PAUSED"}}
100
+ Each kind's payload: \`baker schema ads meta <group> create\` (creatives create --variant placement for a
101
+ placement creative). Ops stage in file order, parents first.
102
+ Returns count, refs (each "as" \u2192 its real ref; later calls use the real ref) and only the ops that
103
+ carry a warning; --full lists every op.
104
+ An op refused at staging takes back the ops this file staged before it, and the error names the op:
105
+ fix it and run the whole file again. Unless the error says something stayed staged (an op that
106
+ changed one staged before this file, a removal or an answer that failed): then remove or review
107
+ what it names in \`baker ads meta draft\` first, since running the file again would stage it twice.
108
+ Then: baker ads meta draft`;
109
+ var FILE_ARG = {
110
+ type: "string",
111
+ description: "JSON array or JSON Lines of ops ({kind, accountId?, target?, payload?, as?}), path or inline"
112
+ };
113
+ var ACCOUNT_ARG = {
114
+ type: "string",
115
+ description: "Ad account (act_123) for every op that does not name its own"
116
+ };
117
+ var FULL_ARG = { type: "boolean", description: "List every staged op, not only those with a warning" };
118
+ registerSchema({
119
+ command: "ads.meta.draft.stage",
120
+ routes: ["POST /api/ads/meta/draft/stage", "POST /api/ads/meta/draft/remove"],
121
+ effect: "stage",
122
+ description: STAGE_DESCRIPTION,
123
+ args: {
124
+ file: { ...FILE_ARG, required: true },
125
+ "account-id": { ...ACCOUNT_ARG, required: false },
126
+ full: { ...FULL_ARG, required: false }
127
+ }
128
+ });
129
+ function withNames(value, names) {
130
+ if (typeof value === "string") return names.get(value) ?? value;
131
+ if (Array.isArray(value)) return value.map((item) => withNames(item, names));
132
+ if (value !== null && typeof value === "object") {
133
+ return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, withNames(child, names)]));
134
+ }
135
+ return value;
136
+ }
137
+ function namesUsed(value, names) {
138
+ if (typeof value === "string") return names.has(value) ? [value] : [];
139
+ if (Array.isArray(value)) return value.flatMap((item) => namesUsed(item, names));
140
+ if (value !== null && typeof value === "object") return Object.values(value).flatMap((v) => namesUsed(v, names));
141
+ return [];
142
+ }
143
+ function fileOps(items, accountId) {
144
+ if (items.length === 0) {
145
+ failWriteValidation(
146
+ 'pass --file with the ops to stage: a JSON array (or JSON Lines) of {"kind","accountId"?,"target"?,"payload"?,"as"?}'
147
+ );
148
+ }
149
+ if (items.length > BATCH_MAX) {
150
+ failWriteValidation(`${items.length} ops exceeds the limit of ${BATCH_MAX} \u2014 split the file and run each part`);
151
+ }
152
+ const declared = /* @__PURE__ */ new Map();
153
+ for (const [index, item] of items.entries()) {
154
+ const { as: name } = item;
155
+ if (name === void 0) continue;
156
+ if (typeof name !== "string" || !NAME.test(name)) {
157
+ failWriteValidation(`ops[${index}]: "as" must be meta_temp_<letters or digits>, e.g. meta_temp_img1`);
158
+ }
159
+ if ("target" in item) {
160
+ failWriteValidation(`ops[${index}]: "as" names a create \u2014 a change to something that exists already has a ref`);
161
+ }
162
+ const earlier = declared.get(name);
163
+ if (earlier !== void 0) {
164
+ failWriteValidation(`ops[${index}]: ${name} already names ops[${earlier}] \u2014 give each create its own name`);
165
+ }
166
+ declared.set(name, index);
167
+ }
168
+ const standIns = new Map([...declared.keys()].map((name, at) => [name, `meta_temp_file${at}`]));
169
+ return items.map(({ as: name, ...rest }, index) => {
170
+ const later = new Set([...declared].filter(([, at]) => at >= index).map(([n]) => n));
171
+ const [early] = namesUsed(rest, later);
172
+ if (early !== void 0) {
173
+ failWriteValidation(
174
+ `ops[${index}] names ${early}, which ops[${declared.get(early)}] creates \u2014 put each create before the ops that name it`
175
+ );
176
+ }
177
+ const op = rest.accountId === void 0 && accountId ? { ...rest, accountId } : rest;
178
+ preflightOp(withNames(op, standIns), `ops[${index}] (${String(op.kind)}): `);
179
+ return { name: typeof name === "string" ? name : void 0, op };
180
+ });
181
+ }
182
+ var OUTCOME_UNKNOWN = /* @__PURE__ */ new Set(["NETWORK_ERROR", "TIMEOUT", "INTERNAL_ERROR", "UNAVAILABLE"]);
183
+ async function takeBack(chatId, refs) {
184
+ const left = [];
185
+ for (const ref of [...refs].reverse()) {
186
+ try {
187
+ await apiPost("/api/ads/meta/draft/remove", { chatId, ref });
188
+ } catch {
189
+ left.unshift(ref);
190
+ }
191
+ }
192
+ return left;
193
+ }
194
+ var NOT_TWICE = "\u2014 running the whole file again would stage them twice";
195
+ async function refuseFile(chatId, staged, at, err) {
196
+ const created = new Set(staged.filter((entry) => !entry.amended).map((entry) => entry.ref));
197
+ const keeps = staged.some((entry) => entry.amended && !created.has(entry.ref));
198
+ const left = keeps ? [] : await takeBack(chatId, [...created]);
199
+ if (!(err instanceof ApiError)) handleMetaError(err);
200
+ const unknown = OUTCOME_UNKNOWN.has(err.code);
201
+ const after = [];
202
+ if (keeps) {
203
+ after.push(
204
+ `the ${staged.length} op(s) before it stay staged (${staged.map((entry) => entry.ref).join(", ")}) because one changed an op staged earlier ${NOT_TWICE}: review with \`baker ads meta draft\`, then stage that op and the ones after it in a new file that uses these refs`
205
+ );
206
+ } else if (left.length > 0) {
207
+ after.push(
208
+ `${left.join(", ")} could not be taken back and stay staged ${NOT_TWICE}: remove them with \`baker ads meta draft remove ${left.join(" ")}\` first`
209
+ );
210
+ }
211
+ if (unknown) {
212
+ after.push(
213
+ `its answer was lost, so it may be staged anyway: check \`baker ads meta draft\` and remove it with \`baker ads meta draft remove <ref>\` before running the file again`
214
+ );
215
+ }
216
+ if (after.length === 0) after.push("nothing from this file stayed staged \u2014 fix that op and run the whole file again");
217
+ handleMetaError(new ApiError(err.code, `${at}: ${err.message} \u2014 ${after.join("; ")}`, err.fix));
218
+ }
219
+ function activeAdHints(ops, staged) {
220
+ const refs = ops.flatMap(({ op }, index) => {
221
+ const { payload } = op;
222
+ const live = typeof payload === "object" && payload !== null && "status" in payload && payload.status === "ACTIVE";
223
+ const ref = staged[index]?.ref;
224
+ return op.kind === "ad.create" && live && ref !== void 0 ? [ref] : [];
225
+ });
226
+ if (refs.length === 0) return [];
227
+ const pauses = refs.map((ref) => `\`baker ads meta ads pause ${ref}\``).join(", ");
228
+ return [
229
+ `${refs.join(", ")} are staged ACTIVE and start spending at publish \u2014 the Meta playbook stages new ads PAUSED and resumes them once tracking is verified. Unless the person asked for them live, pause them in place with ${pauses}; never run the file again, which would stage them twice`
230
+ ];
231
+ }
232
+ async function stageFile(ops, full) {
233
+ const chatId = requireChatId();
234
+ const names = /* @__PURE__ */ new Map();
235
+ const staged = [];
236
+ const hints = [];
237
+ for (const [index, { name, op }] of ops.entries()) {
238
+ const resolved = withNames(op, names);
239
+ try {
240
+ const response = await apiPost("/api/ads/meta/draft/stage", { chatId, op: resolved });
241
+ staged.push(response.data);
242
+ hints.push(...response.hints ?? []);
243
+ if (name !== void 0) names.set(name, response.data.ref);
244
+ } catch (err) {
245
+ await refuseFile(chatId, staged, `ops[${index}] (${String(op.kind)})`, err);
246
+ }
247
+ }
248
+ const copy = await adCopyHints(ops.map(({ op }) => op.payload));
249
+ const shown = full ? staged : staged.filter((entry) => entry.warnings.length > 0);
250
+ const allHints = [.../* @__PURE__ */ new Set([...hints, ...activeAdHints(ops, staged), ...copy])];
251
+ writeJsonEnvelope({
252
+ ok: true,
253
+ data: {
254
+ staged: true,
255
+ count: staged.length,
256
+ refs: Object.fromEntries(names),
257
+ ops: shown.map(({ ref, kind, summary, warnings }) => ({ ref, kind, summary, warnings }))
258
+ },
259
+ ...allHints.length > 0 ? { hints: allHints } : {}
260
+ });
261
+ }
262
+ var draftStageCommand = withEffect(
263
+ { effect: "stage", routes: ["POST /api/ads/meta/draft/stage", "POST /api/ads/meta/draft/remove"] },
264
+ defineCommand({
265
+ meta: { name: "stage", description: STAGE_DESCRIPTION },
266
+ args: { file: FILE_ARG, "account-id": ACCOUNT_ARG, full: FULL_ARG },
267
+ run: async ({ args }) => {
268
+ const items = loadJsonPayloads(args.file);
269
+ const needsAccount = items.some((item) => item.accountId === void 0);
270
+ const accountId = needsAccount ? await bareAccountId(args) : void 0;
271
+ await stageFile(fileOps(items, accountId), args.full === true);
272
+ }
273
+ })
274
+ );
46
275
 
47
276
  // src/commands/ads/meta/draft-status.ts
48
277
  var STATUS_HEADINGS = {
@@ -228,7 +457,7 @@ async function listDraft(json, chat, full = false, selector) {
228
457
  handleMetaError(err);
229
458
  }
230
459
  }
231
- var listCommand = defineCommand({
460
+ var listCommand = defineCommand2({
232
461
  meta: {
233
462
  name: "list",
234
463
  description: "Show every Meta write op staged in this chat, one line each (ref \xB7 kind \xB7 summary \xB7 parent ad set or campaign and its status \xB7 dependencies \xB7 post-publish result), with staged ads counted by their ad set's status; --json for the raw envelope, --full for every op's payload too. Publishing reaches the real ad account, so review this before you finish. Example: baker ads meta draft"
@@ -248,7 +477,7 @@ var listCommand = defineCommand({
248
477
  );
249
478
  }
250
479
  });
251
- var showCommand = defineCommand({
480
+ var showCommand = defineCommand2({
252
481
  meta: {
253
482
  name: "show",
254
483
  description: "Print the staged payload for one op \u2014 the receipt to verify a change looks right before publish. A list longer than 50 items (a customer list's members) prints as its count; --full prints every item. Example: baker ads meta draft show meta_temp_abc123"
@@ -273,7 +502,7 @@ var showCommand = defineCommand({
273
502
  }
274
503
  }
275
504
  });
276
- var removeCommand = defineCommand({
505
+ var removeCommand = defineCommand2({
277
506
  meta: {
278
507
  name: "remove",
279
508
  description: "Drop staged Meta ops \u2014 one, or many in one call. Removing a create cascades to everything that depends on it. Example: baker ads meta draft remove meta_temp_abc123 meta_temp_def456"
@@ -303,7 +532,7 @@ var removeCommand = defineCommand({
303
532
  }
304
533
  }
305
534
  });
306
- var clearCommand = defineCommand({
535
+ var clearCommand = defineCommand2({
307
536
  meta: {
308
537
  name: "clear",
309
538
  description: "Discard ALL staged Meta ops in this chat's draft \u2014 nothing will apply on publish. Example: baker ads meta draft clear"
@@ -324,10 +553,10 @@ withEffect({ effect: "read", routes: ["POST /api/ads/meta/draft"] }, listCommand
324
553
  withEffect({ effect: "read", routes: ["POST /api/ads/meta/draft/show"] }, showCommand);
325
554
  withEffect({ effect: "unstage", routes: ["POST /api/ads/meta/draft/remove"] }, removeCommand);
326
555
  withEffect({ effect: "unstage", routes: ["POST /api/ads/meta/draft/clear"] }, clearCommand);
327
- var metaDraftCommand = defineCommand({
556
+ var metaDraftCommand = defineCommand2({
328
557
  meta: {
329
558
  name: "draft",
330
- description: "Review and edit the Meta write ops staged in this chat BEFORE publish. Subcommands: list (default), show, remove, clear. Ops never hit Meta until the chat is published. `list` and `show` take --chat <id> to read an earlier chat's changes instead."
559
+ description: "Review and edit the Meta write ops staged in this chat BEFORE publish. Subcommands: list (default), show, remove, clear, and stage --file (many ops from one file in one call, names chaining creates). Ops never hit Meta until the chat is published. `list` and `show` take --chat <id> to read an earlier chat's changes instead."
331
560
  },
332
561
  // Declared on the parent too: `default: "list"` dispatches the bare `draft --chat <id>` form, and
333
562
  // citty prints help for a flag the parent does not know instead of forwarding it.
@@ -337,7 +566,13 @@ var metaDraftCommand = defineCommand({
337
566
  chat: CHAT_READ_ARG,
338
567
  where: LIST_WHERE_ARG
339
568
  },
340
- subCommands: { list: listCommand, show: showCommand, remove: removeCommand, clear: clearCommand },
569
+ subCommands: {
570
+ list: listCommand,
571
+ show: showCommand,
572
+ remove: removeCommand,
573
+ clear: clearCommand,
574
+ stage: draftStageCommand
575
+ },
341
576
  // `default` (not `run`) dispatches the bare invocation: citty falls through to `run`
342
577
  // after dispatching a subcommand, so a `run` here would list the draft a second time
343
578
  // on every `draft list` / `draft remove` / `draft clear`.
@@ -346,4 +581,4 @@ var metaDraftCommand = defineCommand({
346
581
  export {
347
582
  metaDraftCommand
348
583
  };
349
- //# sourceMappingURL=draft-OHAOBGVP.js.map
584
+ //# sourceMappingURL=draft-JPWMFZNZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/ads/meta/draft.ts","../src/commands/ads/meta/draft-stage.ts","../src/commands/ads/meta/draft-status.ts"],"sourcesContent":["import type {\n MetaDraftClearResponse,\n MetaDraftListResponse,\n MetaDraftRemoveResponse,\n MetaDraftShowResponse,\n} from \"@baker/api/ads-meta\";\nimport { defineCommand } from \"citty\";\nimport { apiPost } from \"../../../client.ts\";\nimport { requireChatId, resolveChatId } from \"../../../env.ts\";\nimport { registerSchema, withEffect } from \"../../../schemas.ts\";\nimport { CHAT_READ_ARG, DRAFT_FULL_ARG } from \"../../chat-arg.ts\";\nimport { draftRefs, removeDraftRefs } from \"../../draft-refs.ts\";\nimport { draftListWhere, LIST_WHERE_ARG, requireDraftWhere, wholeDraftHints } from \"../../draft-where.ts\";\nimport { SHOW_FULL_ARG, showEnvelope } from \"../draft-show.ts\";\nimport { hintLines, withHints } from \"../hints.ts\";\nimport { writeJsonEnvelope } from \"../output.ts\";\nimport { draftStageCommand } from \"./draft-stage.ts\";\nimport { renderDraftStatus } from \"./draft-status.ts\";\nimport { handleMetaError } from \"./shared.ts\";\n\nregisterSchema({\n command: \"ads.meta.draft\",\n routes: [\"POST /api/ads/meta/draft\"],\n effect: \"read\",\n description:\n \"Review every Meta op staged on this chat, one line each: ref · kind · summary · the ad set (or campaign) a staged ad (or ad set) goes into with the status it publishes under · what it waits on · ✗ blocked: <why> when publish would now refuse it, and after a publish ✓ applied → id or ✗ failed: <error>. `draft show <ref>` prints one op's payload (--full for lists over 50 items).\",\n args: {\n json: { type: \"boolean\", description: \"Raw JSON envelope instead of the readable list\", required: false },\n full: { type: \"boolean\", description: DRAFT_FULL_ARG.description, required: false },\n chat: { type: \"string\", description: \"Read another chat's draft instead of this one\", required: false },\n where: LIST_WHERE_ARG,\n },\n});\n\n/**\n * The readable one-line-per-op view is the default, like the Google, LinkedIn and X drafts;\n * `--json` (or `--output json`) returns the raw envelope for tools.\n */\nasync function listDraft(json: boolean, chat?: unknown, full = false, selector?: string): Promise<void> {\n const where = selector === undefined ? undefined : requireDraftWhere(selector);\n try {\n const chatId = resolveChatId(chat);\n const response = await apiPost<{ ok: boolean; data?: MetaDraftListResponse }>(\"/api/ads/meta/draft\", {\n chatId,\n ...(full || where ? { full: true } : {}),\n });\n if (where && selector !== undefined && response.ok && response.data) {\n const narrowed = draftListWhere(response.data, where, selector);\n writeJsonEnvelope(withHints({ ...response, data: narrowed.data }, narrowed.hints));\n return;\n }\n if (json || full || !response.ok || !response.data) {\n const whole = response.ok && response.data ? wholeDraftHints(response.data.ops, \"baker ads meta draft list\") : [];\n writeJsonEnvelope(withHints(response, whole));\n return;\n }\n process.stdout.write(`${renderDraftStatus(response.data)}${hintLines(response)}\\n`);\n } catch (err) {\n handleMetaError(err);\n }\n}\n\nconst listCommand = defineCommand({\n meta: {\n name: \"list\",\n description:\n \"Show every Meta write op staged in this chat, one line each (ref · kind · summary · parent ad set or campaign and its status · dependencies · post-publish result), with staged ads counted by their ad set's status; --json for the raw envelope, --full for every op's payload too. Publishing reaches the real ad account, so review this before you finish. Example: baker ads meta draft\",\n },\n args: {\n json: { type: \"boolean\", description: \"Print the raw JSON envelope instead of the readable list\" },\n full: DRAFT_FULL_ARG,\n chat: CHAT_READ_ARG,\n where: LIST_WHERE_ARG,\n },\n run: async ({ args }) => {\n await listDraft(\n args.json === true,\n args.chat,\n args.full === true,\n typeof args.where === \"string\" ? args.where : undefined,\n );\n },\n});\n\nconst showCommand = defineCommand({\n meta: {\n name: \"show\",\n description:\n \"Print the staged payload for one op — the receipt to verify a change looks right before publish. A list longer than 50 items (a customer list's members) prints as its count; --full prints every item. Example: baker ads meta draft show meta_temp_abc123\",\n },\n args: {\n ref: { type: \"positional\", description: \"Op ref (meta_temp_* for creates, target id for updates)\", required: true },\n // `show` always prints the envelope; `--json` is the spelling `list` taught, so it is accepted here too.\n json: { type: \"boolean\", description: \"Accepted for symmetry with list; show always prints the JSON envelope\" },\n chat: CHAT_READ_ARG,\n full: SHOW_FULL_ARG,\n },\n run: async ({ args }) => {\n try {\n const chatId = resolveChatId(args.chat);\n const response = await apiPost<{ ok: true; data: MetaDraftShowResponse }>(\"/api/ads/meta/draft/show\", {\n chatId,\n ref: args.ref,\n });\n writeJsonEnvelope(showEnvelope(response, args.full === true));\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n\nconst removeCommand = defineCommand({\n meta: {\n name: \"remove\",\n description:\n \"Drop staged Meta ops — one, or many in one call. Removing a create cascades to everything that depends on it. Example: baker ads meta draft remove meta_temp_abc123 meta_temp_def456\",\n },\n args: {\n ref: {\n type: \"positional\",\n description: \"Op ref(s) (meta_temp_* for creates, target id for updates) — several, space- or comma-separated\",\n required: true,\n },\n },\n run: async ({ args }) => {\n const refs = draftRefs(args._);\n if (refs.length > 1) {\n await removeDraftRefs(\"/api/ads/meta/draft/remove\", refs);\n return;\n }\n try {\n const chatId = requireChatId();\n const response = await apiPost<{ ok: true; data: MetaDraftRemoveResponse }>(\"/api/ads/meta/draft/remove\", {\n chatId,\n ref: args.ref,\n });\n writeJsonEnvelope(response);\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n\nconst clearCommand = defineCommand({\n meta: {\n name: \"clear\",\n description:\n \"Discard ALL staged Meta ops in this chat's draft — nothing will apply on publish. Example: baker ads meta draft clear\",\n },\n run: async () => {\n try {\n const chatId = requireChatId();\n const response = await apiPost<{ ok: true; data: MetaDraftClearResponse }>(\"/api/ads/meta/draft/clear\", {\n chatId,\n });\n writeJsonEnvelope(response);\n } catch (err) {\n handleMetaError(err);\n }\n },\n});\n\nwithEffect({ effect: \"read\", routes: [\"POST /api/ads/meta/draft\"] }, listCommand);\nwithEffect({ effect: \"read\", routes: [\"POST /api/ads/meta/draft/show\"] }, showCommand);\nwithEffect({ effect: \"unstage\", routes: [\"POST /api/ads/meta/draft/remove\"] }, removeCommand);\nwithEffect({ effect: \"unstage\", routes: [\"POST /api/ads/meta/draft/clear\"] }, clearCommand);\n\nexport const metaDraftCommand = defineCommand({\n meta: {\n name: \"draft\",\n description:\n \"Review and edit the Meta write ops staged in this chat BEFORE publish. Subcommands: list (default), show, remove, clear, and stage --file (many ops from one file in one call, names chaining creates). Ops never hit Meta until the chat is published. `list` and `show` take --chat <id> to read an earlier chat's changes instead.\",\n },\n // Declared on the parent too: `default: \"list\"` dispatches the bare `draft --chat <id>` form, and\n // citty prints help for a flag the parent does not know instead of forwarding it.\n args: {\n json: { type: \"boolean\", description: \"Print the raw JSON envelope instead of the readable list\" },\n full: DRAFT_FULL_ARG,\n chat: CHAT_READ_ARG,\n where: LIST_WHERE_ARG,\n },\n subCommands: {\n list: listCommand,\n show: showCommand,\n remove: removeCommand,\n clear: clearCommand,\n stage: draftStageCommand,\n },\n // `default` (not `run`) dispatches the bare invocation: citty falls through to `run`\n // after dispatching a subcommand, so a `run` here would list the draft a second time\n // on every `draft list` / `draft remove` / `draft clear`.\n default: \"list\",\n});\n","import type { MetaDraftOpInput, MetaDraftStageResponse } from \"@baker/api/ads-meta\";\nimport { defineCommand } from \"citty\";\nimport { ApiError, apiPost, type ErrorCode } from \"../../../client.ts\";\nimport { requireChatId } from \"../../../env.ts\";\nimport { registerSchema, withEffect } from \"../../../schemas.ts\";\nimport { adCopyHints } from \"../copy-hints.ts\";\nimport { loadJsonPayloads } from \"../google/write-shared.ts\";\nimport { writeJsonEnvelope } from \"../output.ts\";\nimport { handleMetaError } from \"./shared.ts\";\nimport { bareAccountId, failWriteValidation, preflightOp } from \"./write-shared.ts\";\n\n/**\n * `draft stage --file`: many Meta ops from one file, in one command. Pictures into ad sets is three\n * ops per ad (upload, creative, ad), each needing the ref the one before it returned, so without this\n * the agent wrote a script looping the CLI and parsing every envelope. Each op still goes through the\n * one-op stage route — Meta staging dry-runs each change, so a whole tree in one request would\n * outlast the request — but the names are resolved here, and a refusal takes back what the file\n * staged before it.\n */\n\nconst BATCH_MAX = 100;\n\n/** A name the file gives a create. Any length: it is replaced before anything is sent. */\nconst NAME = /^meta_temp_[A-Za-z0-9_-]+$/;\n\nconst STAGE_DESCRIPTION = `Stage many Meta changes from ONE file, in one call — any mix of kinds, up to ${BATCH_MAX} ops.\n\nStart here whenever a job is more than a few staged changes: N library pictures into M ad sets, a\nset of ads, a campaign tree. Never loop the single commands from a script.\n baker ads meta draft stage --file ops.json --account-id act_123\n\nThe file is a JSON array (or JSON Lines, one op per line). Each op is what the single commands\nbuild — kind, accountId (or --account-id for all), target for a change to something that exists,\npayload. A create can take a name in \"as\" (meta_temp_<anything>); later ops in the same file use\nthat name wherever a ref goes, and it becomes the real ref. Upload each picture once and reuse it:\n {\"kind\":\"media.upload\",\"as\":\"meta_temp_img1\",\"payload\":{\"kind\":\"image\",\"bakerImageId\":\"<id>\"}}\n {\"kind\":\"adCreative.create\",\"as\":\"meta_temp_cr1\",\"payload\":{\"creativeType\":\"single\",\"page_id\":\"555\",\n \"message\":\"…\",\"headline\":\"…\",\"link\":\"https://example.com\",\"imageRef\":\"meta_temp_img1\",\n \"call_to_action\":{\"type\":\"LEARN_MORE\"}}}\n {\"kind\":\"ad.create\",\"payload\":{\"name\":\"Ad 1\",\"adset_id\":\"6123\",\"creative\":{\"creative_id\":\"meta_temp_cr1\"},\"status\":\"PAUSED\"}}\n {\"kind\":\"ad.create\",\"payload\":{\"name\":\"Ad 1\",\"adset_id\":\"6124\",\"creative\":{\"creative_id\":\"meta_temp_cr1\"},\"status\":\"PAUSED\"}}\nEach kind's payload: \\`baker schema ads meta <group> create\\` (creatives create --variant placement for a\nplacement creative). Ops stage in file order, parents first.\nReturns count, refs (each \"as\" → its real ref; later calls use the real ref) and only the ops that\ncarry a warning; --full lists every op.\nAn op refused at staging takes back the ops this file staged before it, and the error names the op:\nfix it and run the whole file again. Unless the error says something stayed staged (an op that\nchanged one staged before this file, a removal or an answer that failed): then remove or review\nwhat it names in \\`baker ads meta draft\\` first, since running the file again would stage it twice.\nThen: baker ads meta draft`;\n\nconst FILE_ARG = {\n type: \"string\",\n description: \"JSON array or JSON Lines of ops ({kind, accountId?, target?, payload?, as?}), path or inline\",\n} as const;\nconst ACCOUNT_ARG = {\n type: \"string\",\n description: \"Ad account (act_123) for every op that does not name its own\",\n} as const;\nconst FULL_ARG = { type: \"boolean\", description: \"List every staged op, not only those with a warning\" } as const;\n\nregisterSchema({\n command: \"ads.meta.draft.stage\",\n routes: [\"POST /api/ads/meta/draft/stage\", \"POST /api/ads/meta/draft/remove\"],\n effect: \"stage\",\n description: STAGE_DESCRIPTION,\n args: {\n file: { ...FILE_ARG, required: true },\n \"account-id\": { ...ACCOUNT_ARG, required: false },\n full: { ...FULL_ARG, required: false },\n },\n});\n\ninterface FileOp {\n name?: string;\n op: Record<string, unknown>;\n}\n\n/** Every string in `value` equal to a key of `names`, swapped for its value: same shape otherwise. */\nfunction withNames(value: unknown, names: ReadonlyMap<string, string>): unknown {\n if (typeof value === \"string\") return names.get(value) ?? value;\n if (Array.isArray(value)) return value.map((item) => withNames(item, names));\n if (value !== null && typeof value === \"object\") {\n return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, withNames(child, names)]));\n }\n return value;\n}\n\n/** The strings in `value` that a later op in the file names: refused, since that op is not staged yet. */\nfunction namesUsed(value: unknown, names: ReadonlySet<string>): string[] {\n if (typeof value === \"string\") return names.has(value) ? [value] : [];\n if (Array.isArray(value)) return value.flatMap((item) => namesUsed(item, names));\n if (value !== null && typeof value === \"object\") return Object.values(value).flatMap((v) => namesUsed(v, names));\n return [];\n}\n\n/** The file's ops, each with its name split off and the account filled in; the names checked before anything stages. */\nfunction fileOps(items: ReadonlyArray<Record<string, unknown>>, accountId: string | undefined): FileOp[] {\n if (items.length === 0) {\n failWriteValidation(\n 'pass --file with the ops to stage: a JSON array (or JSON Lines) of {\"kind\",\"accountId\"?,\"target\"?,\"payload\"?,\"as\"?}',\n );\n }\n if (items.length > BATCH_MAX) {\n failWriteValidation(`${items.length} ops exceeds the limit of ${BATCH_MAX} — split the file and run each part`);\n }\n const declared = new Map<string, number>();\n for (const [index, item] of items.entries()) {\n const { as: name } = item;\n if (name === undefined) continue;\n if (typeof name !== \"string\" || !NAME.test(name)) {\n failWriteValidation(`ops[${index}]: \"as\" must be meta_temp_<letters or digits>, e.g. meta_temp_img1`);\n }\n if (\"target\" in item) {\n failWriteValidation(`ops[${index}]: \"as\" names a create — a change to something that exists already has a ref`);\n }\n const earlier = declared.get(name);\n if (earlier !== undefined) {\n failWriteValidation(`ops[${index}]: ${name} already names ops[${earlier}] — give each create its own name`);\n }\n declared.set(name, index);\n }\n const standIns = new Map([...declared.keys()].map((name, at) => [name, `meta_temp_file${at}`]));\n return items.map(({ as: name, ...rest }, index) => {\n const later = new Set([...declared].filter(([, at]) => at >= index).map(([n]) => n));\n const [early] = namesUsed(rest, later);\n if (early !== undefined) {\n failWriteValidation(\n `ops[${index}] names ${early}, which ops[${declared.get(early)}] creates — put each create before the ops that name it`,\n );\n }\n const op = rest.accountId === undefined && accountId ? { ...rest, accountId } : rest;\n // Checked with each name standing in as a ref the contract takes; the real ref replaces it at staging.\n preflightOp(withNames(op, standIns) as Record<string, unknown>, `ops[${index}] (${String(op.kind)}): `);\n return { name: typeof name === \"string\" ? name : undefined, op };\n });\n}\n\ninterface StageEnvelope {\n ok: true;\n data: MetaDraftStageResponse;\n hints?: string[];\n}\n\n/** A failure that may come after the backend staged the op: its answer, and so its ref, never arrived. */\nconst OUTCOME_UNKNOWN: ReadonlySet<ErrorCode> = new Set([\"NETWORK_ERROR\", \"TIMEOUT\", \"INTERNAL_ERROR\", \"UNAVAILABLE\"]);\n\n/** Drops what this file staged, newest first, and returns the refs it could not drop. A ref a cascade already took answers as removed. */\nasync function takeBack(chatId: string, refs: readonly string[]): Promise<string[]> {\n const left: string[] = [];\n for (const ref of [...refs].reverse()) {\n try {\n await apiPost(\"/api/ads/meta/draft/remove\", { chatId, ref });\n } catch {\n left.unshift(ref);\n }\n }\n return left;\n}\n\nconst NOT_TWICE = \"— running the whole file again would stage them twice\";\n\n/**\n * A refused op ends the file: what it staged before is taken back, unless one of those ops amended an\n * op staged before this file ran, which removing cannot undo. The refusal names the op, and says what\n * stays staged or may have: an op whose answer was lost, and any op whose removal failed.\n */\nasync function refuseFile(\n chatId: string,\n staged: readonly MetaDraftStageResponse[],\n at: string,\n err: unknown,\n): Promise<never> {\n const created = new Set(staged.filter((entry) => !entry.amended).map((entry) => entry.ref));\n const keeps = staged.some((entry) => entry.amended && !created.has(entry.ref));\n const left = keeps ? [] : await takeBack(chatId, [...created]);\n if (!(err instanceof ApiError)) handleMetaError(err);\n const unknown = OUTCOME_UNKNOWN.has(err.code);\n const after: string[] = [];\n if (keeps) {\n after.push(\n `the ${staged.length} op(s) before it stay staged (${staged.map((entry) => entry.ref).join(\", \")}) because one changed an op staged earlier ${NOT_TWICE}: review with \\`baker ads meta draft\\`, then stage that op and the ones after it in a new file that uses these refs`,\n );\n } else if (left.length > 0) {\n after.push(\n `${left.join(\", \")} could not be taken back and stay staged ${NOT_TWICE}: remove them with \\`baker ads meta draft remove ${left.join(\" \")}\\` first`,\n );\n }\n if (unknown) {\n after.push(\n `its answer was lost, so it may be staged anyway: check \\`baker ads meta draft\\` and remove it with \\`baker ads meta draft remove <ref>\\` before running the file again`,\n );\n }\n if (after.length === 0) after.push(\"nothing from this file stayed staged — fix that op and run the whole file again\");\n handleMetaError(new ApiError(err.code, `${at}: ${err.message} — ${after.join(\"; \")}`, err.fix));\n}\n\n/**\n * The skill stages new ads PAUSED; an ACTIVE one spends from publish, so the agent is reminded, never refused.\n * The ads are staged by now, so the reminder names their refs and amends them in place: staging them again\n * would add a PAUSED copy beside each ACTIVE one.\n */\nfunction activeAdHints(ops: readonly FileOp[], staged: readonly MetaDraftStageResponse[]): string[] {\n const refs = ops.flatMap(({ op }, index) => {\n const { payload } = op;\n const live = typeof payload === \"object\" && payload !== null && \"status\" in payload && payload.status === \"ACTIVE\";\n const ref = staged[index]?.ref;\n return op.kind === \"ad.create\" && live && ref !== undefined ? [ref] : [];\n });\n if (refs.length === 0) return [];\n const pauses = refs.map((ref) => `\\`baker ads meta ads pause ${ref}\\``).join(\", \");\n return [\n `${refs.join(\", \")} are staged ACTIVE and start spending at publish — the Meta playbook stages new ads PAUSED and resumes them once tracking is verified. Unless the person asked for them live, pause them in place with ${pauses}; never run the file again, which would stage them twice`,\n ];\n}\n\nasync function stageFile(ops: readonly FileOp[], full: boolean): Promise<void> {\n const chatId = requireChatId();\n const names = new Map<string, string>();\n const staged: MetaDraftStageResponse[] = [];\n const hints: string[] = [];\n for (const [index, { name, op }] of ops.entries()) {\n const resolved = withNames(op, names) as MetaDraftOpInput;\n try {\n const response = await apiPost<StageEnvelope>(\"/api/ads/meta/draft/stage\", { chatId, op: resolved });\n staged.push(response.data);\n hints.push(...(response.hints ?? []));\n if (name !== undefined) names.set(name, response.data.ref);\n } catch (err) {\n await refuseFile(chatId, staged, `ops[${index}] (${String(op.kind)})`, err);\n }\n }\n const copy = await adCopyHints(ops.map(({ op }) => op.payload));\n const shown = full ? staged : staged.filter((entry) => entry.warnings.length > 0);\n const allHints = [...new Set([...hints, ...activeAdHints(ops, staged), ...copy])];\n writeJsonEnvelope({\n ok: true,\n data: {\n staged: true,\n count: staged.length,\n refs: Object.fromEntries(names),\n ops: shown.map(({ ref, kind, summary, warnings }) => ({ ref, kind, summary, warnings })),\n },\n ...(allHints.length > 0 ? { hints: allHints } : {}),\n });\n}\n\nexport const draftStageCommand = withEffect(\n { effect: \"stage\", routes: [\"POST /api/ads/meta/draft/stage\", \"POST /api/ads/meta/draft/remove\"] },\n defineCommand({\n meta: { name: \"stage\", description: STAGE_DESCRIPTION },\n args: { file: FILE_ARG, \"account-id\": ACCOUNT_ARG, full: FULL_ARG },\n run: async ({ args }) => {\n const items = loadJsonPayloads(args.file);\n const needsAccount = items.some((item) => item.accountId === undefined);\n const accountId = needsAccount ? await bareAccountId(args as Record<string, unknown>) : undefined;\n await stageFile(fileOps(items, accountId), args.full === true);\n },\n }),\n);\n","import type { MetaDraftListResponse, MetaDraftOpView } from \"@baker/api/ads-meta\";\n\n/**\n * Render the staged Meta draft as one line per op — ref, kind, summary, what it\n * waits on and, after a publish, what happened to it. The Google, LinkedIn and\n * X drafts already print a readable view by default; Meta printed the pretty\n * JSON envelope, and agents piped every read through python to get these same\n * columns back. Pure: takes the draft-list response, returns text.\n */\n\nconst STATUS_HEADINGS: Record<MetaDraftListResponse[\"status\"], string> = {\n active: \"staged\",\n publishing: \"publishing\",\n applied: \"published\",\n partial: \"published with failures\",\n discarded: \"discarded\",\n none: \"none\",\n};\n\nfunction plural(count: number, word: string): string {\n return `${count} ${word}${count === 1 ? \"\" : \"s\"}`;\n}\n\nfunction headingLine(draft: MetaDraftListResponse): string {\n const heading = STATUS_HEADINGS[draft.status];\n if (draft.status === \"active\" || draft.status === \"discarded\") {\n return `Meta Ads — ${plural(draft.count, \"change\")} ${heading} · ${draft.mode}`;\n }\n const counts = new Map<string, number>();\n for (const op of draft.ops) {\n const status = op.result?.status ?? \"pending\";\n counts.set(status, (counts.get(status) ?? 0) + 1);\n }\n const summary = [...counts].map(([status, count]) => `${count} ${status}`).join(\", \");\n return `Meta Ads — ${heading} · ${summary} · ${draft.mode}`;\n}\n\n/** A failed op: why, and what of it already reached Meta. */\nfunction failedPart(result: NonNullable<MetaDraftOpView[\"result\"]>): string {\n const landed = result.landed ? ` (${result.landed})` : \"\";\n return `✗ failed: ${result.error ?? \"no reason recorded\"}${landed}`;\n}\n\nfunction resultPart(op: MetaDraftOpView): string | undefined {\n const result = op.result;\n if (!result) {\n return undefined;\n }\n if (result.status === \"failed\") {\n return failedPart(result);\n }\n if (result.status === \"skipped\") {\n // Publish records either the dependency ref that did not apply or a plain reason; either way the op is finished.\n const because = result.skippedBecause;\n if (because && op.dependsOn.includes(because)) {\n return `✗ skipped: ${because} did not apply`;\n }\n return `✗ skipped: ${because ?? \"a change it needs did not apply\"}`;\n }\n const id = result.id ?? result.hash;\n const applied = `✓ ${result.status}${id ? ` → ${id}` : \"\"}`;\n const verification = result.verification;\n if (verification && verification.status !== \"confirmed\") {\n return `${applied} (read-back ${verification.status}${verification.note ? `: ${verification.note}` : \"\"})`;\n }\n return applied;\n}\n\nconst PARENT_WORD: Record<string, string> = {\n \"ad.create\": \"ad set\",\n \"ad.copy\": \"ad set\",\n \"adSet.create\": \"campaign\",\n \"adSet.copy\": \"campaign\",\n};\n\nconst STAGED_AD_KINDS: ReadonlySet<string> = new Set([\"ad.create\", \"ad.copy\"]);\n\n/** Where a staged ad (or ad set) goes, and the status that parent publishes with. */\nfunction parentPart(op: MetaDraftOpView): string | undefined {\n const parent = op.parent;\n if (!parent) {\n return undefined;\n }\n const word = PARENT_WORD[op.kind] ?? \"parent\";\n const named = parent.name ? `\"${parent.name}\" (${parent.ref})` : parent.ref;\n const staged = parent.staged ? \", staged here\" : \"\";\n const status = parent.status\n ? `${parent.statusBefore ? `${parent.statusBefore} → ` : \"\"}${parent.status}`\n : \"status not recorded\";\n return `in ${word} ${named}${staged} ${status}`;\n}\n\n/** \"Which staged ads will run\" in one line: ads counted by the status of the ad set they go into. */\nfunction adParentStatusLine(ops: readonly MetaDraftOpView[]): string | undefined {\n const counts = new Map<string, number>();\n for (const op of ops) {\n if (STAGED_AD_KINDS.has(op.kind) && op.parent) {\n const status = op.parent.status ?? \"not recorded\";\n counts.set(status, (counts.get(status) ?? 0) + 1);\n }\n }\n if (counts.size === 0) {\n return undefined;\n }\n return `Staged ads by ad set status: ${[...counts].map(([status, count]) => `${count} ${status}`).join(\", \")}`;\n}\n\nfunction readinessLine(ops: readonly MetaDraftOpView[]): string {\n const blocked = ops.filter((op) => op.blocked);\n if (blocked.length === 0) {\n return \"Every change passed its checks when staged — no need to re-check them.\";\n }\n // A first publish holds every change beside a refused one; only the refused ones need fixing.\n const heldBack = blocked.filter((op) => op.heldBack).length;\n const refused = blocked.length - heldBack;\n const held =\n heldBack === 0\n ? \"\"\n : `; the other ${plural(heldBack, \"change\")} ${heldBack === 1 ? \"is\" : \"are\"} held back with ${refused === 1 ? \"it\" : \"them\"} and need${heldBack === 1 ? \"s\" : \"\"} nothing`;\n return `${plural(refused, \"change\")} passed its checks when staged but would be refused now (✗ blocked below) — fix or remove ${refused === 1 ? \"it\" : \"them\"} before publishing${held}.`;\n}\n\nfunction opLine(op: MetaDraftOpView, showAccount: boolean): string {\n const parts = [op.ref, op.kind, op.summary];\n if (op.target && op.target !== op.ref) {\n parts.push(`target ${op.target}`);\n }\n if (showAccount) {\n parts.push(`account ${op.accountId}`);\n }\n const parent = parentPart(op);\n if (parent) {\n parts.push(parent);\n }\n if (op.dependsOn.length > 0) {\n parts.push(`after ${op.dependsOn.join(\", \")}`);\n }\n if (op.blocked) {\n parts.push(`✗ blocked: ${op.blocked}`);\n }\n const result = resultPart(op);\n if (result) {\n parts.push(result);\n }\n // Creative copy and provider errors can carry line breaks; one op stays one line.\n return ` ${parts.join(\" · \").replace(/[\\r\\n]+/g, \" \")}`;\n}\n\nexport function renderDraftStatus(draft: MetaDraftListResponse): string {\n if (draft.status === \"none\" || draft.count === 0) {\n return \"No staged Meta changes on this chat.\";\n }\n const lines = [headingLine(draft)];\n if (draft.status === \"active\") {\n lines.push(\"Publishing makes every change real on the ad account.\", readinessLine(draft.ops));\n }\n const adParents = adParentStatusLine(draft.ops);\n if (adParents) {\n lines.push(adParents);\n }\n lines.push(\"\");\n // A draft may span several ad accounts; the account is only noise when there is one.\n const showAccount = new Set(draft.ops.map((op) => op.accountId)).size > 1;\n for (const op of draft.ops) {\n lines.push(opLine(op, showAccount));\n }\n if (draft.advisories.length > 0) {\n lines.push(\"\", \"Advisories\");\n for (const advisory of draft.advisories) {\n lines.push(` ! ${advisory.ref}: ${advisory.message}`);\n }\n }\n lines.push(\n \"\",\n \"Staged payload for one op: baker ads meta draft show <ref> (--full for lists over 50 items) · raw envelope: --json\",\n );\n return lines.join(\"\\n\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,SAAS,iBAAAA,sBAAqB;;;ACL9B,SAAS,qBAAqB;AAmB9B,IAAM,YAAY;AAGlB,IAAM,OAAO;AAEb,IAAM,oBAAoB,qFAAgF,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0BnH,IAAM,WAAW;AAAA,EACf,MAAM;AAAA,EACN,aAAa;AACf;AACA,IAAM,cAAc;AAAA,EAClB,MAAM;AAAA,EACN,aAAa;AACf;AACA,IAAM,WAAW,EAAE,MAAM,WAAW,aAAa,sDAAsD;AAEvG,eAAe;AAAA,EACb,SAAS;AAAA,EACT,QAAQ,CAAC,kCAAkC,iCAAiC;AAAA,EAC5E,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,MAAM;AAAA,IACJ,MAAM,EAAE,GAAG,UAAU,UAAU,KAAK;AAAA,IACpC,cAAc,EAAE,GAAG,aAAa,UAAU,MAAM;A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;AAAA,IACrB;AAAA,EACF;AACF,CAAC;AAED,WAAW,EAAE,QAAQ,QAAQ,QAAQ,CAAC,0BAA0B,EAAE,GAAG,WAAW;AAChF,WAAW,EAAE,QAAQ,QAAQ,QAAQ,CAAC,+BAA+B,EAAE,GAAG,WAAW;AACrF,WAAW,EAAE,QAAQ,WAAW,QAAQ,CAAC,iCAAiC,EAAE,GAAG,aAAa;AAC5F,WAAW,EAAE,QAAQ,WAAW,QAAQ,CAAC,gCAAgC,EAAE,GAAG,YAAY;AAEnF,IAAM,mBAAmBA,eAAc;AAAA,EAC5C,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,aACE;AAAA,EACJ;AAAA;AAAA;AAAA,EAGA,MAAM;AAAA,IACJ,MAAM,EAAE,MAAM,WAAW,aAAa,2DAA2D;AAAA,IACjG,MAAM;AAAA,IACN,MAAM;AAAA,IACN,OAAO;AAAA,EACT;AAAA,EACA,aAAa;AAAA,IACX,MAAM;AAAA,IACN,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,OAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAIA,SAAS;AACX,CAAC;","names":["defineCommand","defineCommand"]}
@@ -6,7 +6,7 @@ import {
6
6
  mergePayload,
7
7
  requireTarget,
8
8
  stageOp
9
- } from "./chunk-BRHYK4HQ.js";
9
+ } from "./chunk-G7Q43JEZ.js";
10
10
  import "./chunk-3R62EYYX.js";
11
11
  import "./chunk-GDFJOCDO.js";
12
12
  import {
@@ -265,4 +265,4 @@ export {
265
265
  instantExperiencesCreateCommand,
266
266
  instantExperiencesUpdateCommand
267
267
  };
268
- //# sourceMappingURL=instant-experiences-YXH2AHFI.js.map
268
+ //# sourceMappingURL=instant-experiences-MF2X374W.js.map
@@ -8,7 +8,7 @@ import {
8
8
  requireTarget,
9
9
  stageOp,
10
10
  upper
11
- } from "./chunk-BRHYK4HQ.js";
11
+ } from "./chunk-G7Q43JEZ.js";
12
12
  import {
13
13
  isMetaLeadAdsRefusal
14
14
  } from "./chunk-3R62EYYX.js";
@@ -572,4 +572,4 @@ export {
572
572
  leadPageHints,
573
573
  leadsCommand
574
574
  };
575
- //# sourceMappingURL=leads-IGOXMIEW.js.map
575
+ //# sourceMappingURL=leads-IBXGNXTX.js.map
@@ -8,11 +8,11 @@ var metaMediaCommand = defineCommand({
8
8
  description: "Stage Baker library media uploads to Meta so creatives can reference them (upload), or take an image out of the account's image library (delete --image-hash). Upload publishes an ad-image hash or video id a creative binds via --image-ref/--video-ref."
9
9
  },
10
10
  subCommands: {
11
- upload: () => import("./write-commands-REUTFNJ3.js").then((m) => m.mediaUploadCommand),
12
- delete: () => import("./asset-writes-ZOVD5O5X.js").then((m) => m.mediaDeleteCommand)
11
+ upload: () => import("./write-commands-3BMPDY3K.js").then((m) => m.mediaUploadCommand),
12
+ delete: () => import("./asset-writes-NTEJDVVM.js").then((m) => m.mediaDeleteCommand)
13
13
  }
14
14
  });
15
15
  export {
16
16
  metaMediaCommand
17
17
  };
18
- //# sourceMappingURL=media-QOGVG6CU.js.map
18
+ //# sourceMappingURL=media-YPVGQ535.js.map
@@ -110,43 +110,43 @@ Full guide: __tooling__/docs/tools/baker/ads-meta.md`
110
110
  account: () => import("./account-AIW3XGWG.js").then((m) => m.accountCommand),
111
111
  businesses: () => import("./businesses-5AEHP23G.js").then((m) => m.businessesCommand),
112
112
  pages: () => import("./pages-O7NXGSBG.js").then((m) => m.pagesCommand),
113
- "lead-forms": () => import("./leads-IGOXMIEW.js").then((m) => m.leadFormsCommand),
114
- "instant-experiences": () => import("./instant-experiences-YXH2AHFI.js").then((m) => m.instantExperiencesCommand),
115
- leads: () => import("./leads-IGOXMIEW.js").then((m) => m.leadsCommand),
116
- campaigns: () => import("./campaigns-PP3MFPJR.js").then((m) => m.campaignsCommand),
117
- adsets: () => import("./adsets-2HV6TJJP.js").then((m) => m.adsetsCommand),
118
- ads: () => import("./ads-G3N76HWA.js").then((m) => m.adsListCommand),
119
- creatives: () => import("./creatives-ZYY5OF5U.js").then((m) => m.creativesCommand),
120
- audiences: () => import("./audiences-65JSGH4L.js").then((m) => m.audiencesCommand),
121
- "custom-conversions": () => import("./custom-conversions-YQPOB2IR.js").then((m) => m.customConversionsCommand),
113
+ "lead-forms": () => import("./leads-IBXGNXTX.js").then((m) => m.leadFormsCommand),
114
+ "instant-experiences": () => import("./instant-experiences-MF2X374W.js").then((m) => m.instantExperiencesCommand),
115
+ leads: () => import("./leads-IBXGNXTX.js").then((m) => m.leadsCommand),
116
+ campaigns: () => import("./campaigns-VD7UOTRV.js").then((m) => m.campaignsCommand),
117
+ adsets: () => import("./adsets-IBLZP6EM.js").then((m) => m.adsetsCommand),
118
+ ads: () => import("./ads-HKPBNXWT.js").then((m) => m.adsListCommand),
119
+ creatives: () => import("./creatives-67CDPYL7.js").then((m) => m.creativesCommand),
120
+ audiences: () => import("./audiences-7TGXZS3M.js").then((m) => m.audiencesCommand),
121
+ "custom-conversions": () => import("./custom-conversions-RZB2622Q.js").then((m) => m.customConversionsCommand),
122
122
  pixels: () => import("./pixels-I7S5N76B.js").then((m) => m.pixelsCommand),
123
123
  activities: () => import("./activities-DYI25TF4.js").then((m) => m.activitiesCommand),
124
124
  insights: () => import("./insights-PBJODKMY.js").then((m) => m.insightsCommand),
125
125
  preview: () => import("./preview-5CK5INGO.js").then((m) => m.previewCommand),
126
126
  videos: () => import("./videos-OF6PAPP2.js").then((m) => m.videosCommand),
127
- targeting: () => import("./targeting-YWOOD6YL.js").then((m) => m.targetingCommand),
128
- "instagram-accounts": () => import("./account-assets-FJFPB7KD.js").then((m) => m.instagramAccountsCommand),
129
- apps: () => import("./account-assets-FJFPB7KD.js").then((m) => m.appsCommand),
130
- "dsa-recommendations": () => import("./account-assets-FJFPB7KD.js").then((m) => m.dsaRecommendationsCommand),
131
- images: () => import("./account-assets-FJFPB7KD.js").then((m) => m.imagesCommand),
132
- labels: () => import("./account-assets-FJFPB7KD.js").then((m) => m.labelsCommand),
133
- studies: () => import("./studies-TIF7PYEB.js").then((m) => m.studiesCommand),
134
- catalogs: () => import("./catalogs-UYYPZRFW.js").then((m) => m.catalogsCommand),
135
- "page-photos": () => import("./page-photos-P2XMKTVF.js").then((m) => m.pagePhotosCommand),
136
- "page-posts": () => import("./account-level-CB6I4X5W.js").then((m) => m.pagePostsCommand),
137
- "instagram-media": () => import("./account-level-CB6I4X5W.js").then((m) => m.instagramMediaCommand),
138
- comments: () => import("./account-level-CB6I4X5W.js").then((m) => m.commentsCommand),
139
- "account-settings": () => import("./account-level-CB6I4X5W.js").then((m) => m.accountSettingsCommand),
140
- "account-details": () => import("./account-level-CB6I4X5W.js").then((m) => m.accountDetailsCommand),
141
- "block-lists": () => import("./account-level-CB6I4X5W.js").then((m) => m.blockListsCommand),
142
- "reach-frequency": () => import("./account-level-CB6I4X5W.js").then((m) => m.reachFrequencyCommand),
143
- "high-demand-periods": () => import("./account-assets-FJFPB7KD.js").then((m) => m.highDemandPeriodsCommand),
144
- rules: () => import("./rules-UEKJOZTV.js").then((m) => m.rulesCommand),
145
- media: () => import("./media-QOGVG6CU.js").then((m) => m.metaMediaCommand),
146
- draft: () => import("./draft-OHAOBGVP.js").then((m) => m.metaDraftCommand)
127
+ targeting: () => import("./targeting-FRMVSXXL.js").then((m) => m.targetingCommand),
128
+ "instagram-accounts": () => import("./account-assets-Q2O3FRUE.js").then((m) => m.instagramAccountsCommand),
129
+ apps: () => import("./account-assets-Q2O3FRUE.js").then((m) => m.appsCommand),
130
+ "dsa-recommendations": () => import("./account-assets-Q2O3FRUE.js").then((m) => m.dsaRecommendationsCommand),
131
+ images: () => import("./account-assets-Q2O3FRUE.js").then((m) => m.imagesCommand),
132
+ labels: () => import("./account-assets-Q2O3FRUE.js").then((m) => m.labelsCommand),
133
+ studies: () => import("./studies-Y6PGWT66.js").then((m) => m.studiesCommand),
134
+ catalogs: () => import("./catalogs-H2T4Z6AS.js").then((m) => m.catalogsCommand),
135
+ "page-photos": () => import("./page-photos-BEAMTVP5.js").then((m) => m.pagePhotosCommand),
136
+ "page-posts": () => import("./account-level-NBEQ6R7X.js").then((m) => m.pagePostsCommand),
137
+ "instagram-media": () => import("./account-level-NBEQ6R7X.js").then((m) => m.instagramMediaCommand),
138
+ comments: () => import("./account-level-NBEQ6R7X.js").then((m) => m.commentsCommand),
139
+ "account-settings": () => import("./account-level-NBEQ6R7X.js").then((m) => m.accountSettingsCommand),
140
+ "account-details": () => import("./account-level-NBEQ6R7X.js").then((m) => m.accountDetailsCommand),
141
+ "block-lists": () => import("./account-level-NBEQ6R7X.js").then((m) => m.blockListsCommand),
142
+ "reach-frequency": () => import("./account-level-NBEQ6R7X.js").then((m) => m.reachFrequencyCommand),
143
+ "high-demand-periods": () => import("./account-assets-Q2O3FRUE.js").then((m) => m.highDemandPeriodsCommand),
144
+ rules: () => import("./rules-LZ36YNG3.js").then((m) => m.rulesCommand),
145
+ media: () => import("./media-YPVGQ535.js").then((m) => m.metaMediaCommand),
146
+ draft: () => import("./draft-JPWMFZNZ.js").then((m) => m.metaDraftCommand)
147
147
  }
148
148
  });
149
149
  export {
150
150
  metaCommand
151
151
  };
152
- //# sourceMappingURL=meta-RJH5COPE.js.map
152
+ //# sourceMappingURL=meta-ZQXCUKHQ.js.map
@@ -3,7 +3,7 @@ import {
3
3
  failWriteValidation,
4
4
  requireTarget,
5
5
  stageOp
6
- } from "./chunk-BRHYK4HQ.js";
6
+ } from "./chunk-G7Q43JEZ.js";
7
7
  import "./chunk-3R62EYYX.js";
8
8
  import "./chunk-GDFJOCDO.js";
9
9
  import "./chunk-LDL5VBBD.js";
@@ -119,4 +119,4 @@ var pagePhotosCommand = defineCommand({
119
119
  export {
120
120
  pagePhotosCommand
121
121
  };
122
- //# sourceMappingURL=page-photos-P2XMKTVF.js.map
122
+ //# sourceMappingURL=page-photos-BEAMTVP5.js.map
@@ -7,7 +7,7 @@ import {
7
7
  fileArg,
8
8
  requireTarget,
9
9
  stageOp
10
- } from "./chunk-BRHYK4HQ.js";
10
+ } from "./chunk-G7Q43JEZ.js";
11
11
  import "./chunk-3R62EYYX.js";
12
12
  import "./chunk-GDFJOCDO.js";
13
13
  import "./chunk-LDL5VBBD.js";
@@ -531,4 +531,4 @@ export {
531
531
  rulesRunCommand,
532
532
  rulesUpdateCommand
533
533
  };
534
- //# sourceMappingURL=rule-writes-MSMVQDQO.js.map
534
+ //# sourceMappingURL=rule-writes-CVP6CH2R.js.map
@@ -211,12 +211,12 @@ Examples:
211
211
  list: listCommand,
212
212
  history: historyCommand,
213
213
  preview: previewCommand,
214
- create: () => import("./rule-writes-MSMVQDQO.js").then((m) => m.rulesCreateCommand),
215
- update: () => import("./rule-writes-MSMVQDQO.js").then((m) => m.rulesUpdateCommand),
216
- enable: () => import("./rule-writes-MSMVQDQO.js").then((m) => m.rulesEnableCommand),
217
- disable: () => import("./rule-writes-MSMVQDQO.js").then((m) => m.rulesDisableCommand),
218
- delete: () => import("./rule-writes-MSMVQDQO.js").then((m) => m.rulesDeleteCommand),
219
- run: () => import("./rule-writes-MSMVQDQO.js").then((m) => m.rulesRunCommand)
214
+ create: () => import("./rule-writes-CVP6CH2R.js").then((m) => m.rulesCreateCommand),
215
+ update: () => import("./rule-writes-CVP6CH2R.js").then((m) => m.rulesUpdateCommand),
216
+ enable: () => import("./rule-writes-CVP6CH2R.js").then((m) => m.rulesEnableCommand),
217
+ disable: () => import("./rule-writes-CVP6CH2R.js").then((m) => m.rulesDisableCommand),
218
+ delete: () => import("./rule-writes-CVP6CH2R.js").then((m) => m.rulesDeleteCommand),
219
+ run: () => import("./rule-writes-CVP6CH2R.js").then((m) => m.rulesRunCommand)
220
220
  },
221
221
  args: {
222
222
  "account-id": LISTING_ACCOUNT_ARG,
@@ -231,4 +231,4 @@ export {
231
231
  ruleListHints,
232
232
  rulesCommand
233
233
  };
234
- //# sourceMappingURL=rules-UEKJOZTV.js.map
234
+ //# sourceMappingURL=rules-LZ36YNG3.js.map