@canonry/canonry 7.51.5 → 7.51.6

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 (116) hide show
  1. package/dist/ads-ABAT3K4K.js +544 -0
  2. package/dist/agent-5G4DRLYX.js +70 -0
  3. package/dist/agent-ask-UDVCZRO7.js +139 -0
  4. package/dist/agent-conversations-5E4JP2QZ.js +52 -0
  5. package/dist/agent-memory-7IIJ4HGZ.js +92 -0
  6. package/dist/agent-providers-BOXPUXZ4.js +55 -0
  7. package/dist/agent-transcript-4O56G6PQ.js +77 -0
  8. package/dist/analytics-PKMWX5XL.js +240 -0
  9. package/dist/apply-OK4XEBDA.js +175 -0
  10. package/dist/backfill-2OT56CX2.js +41 -0
  11. package/dist/backlinks-547WCHND.js +303 -0
  12. package/dist/bing-ZVBV4ZD5.js +418 -0
  13. package/dist/bootstrap-HUB7XQ73.js +326 -0
  14. package/dist/cdp-KQKQ4PWJ.js +162 -0
  15. package/dist/chunk-2G6IP3MO.js +517 -0
  16. package/dist/chunk-42D2LE2B.js +1273 -0
  17. package/dist/chunk-4MJYGB56.js +124 -0
  18. package/dist/chunk-63ISSSGX.js +9150 -0
  19. package/dist/{chunk-PLYJX67A.js → chunk-6G6FTDWC.js} +8080 -13939
  20. package/dist/chunk-6GO5VVAC.js +15 -0
  21. package/dist/{chunk-4YCGZGA3.js → chunk-73P65KPW.js} +2 -2
  22. package/dist/chunk-7B2Q4NJE.js +133 -0
  23. package/dist/{chunk-JBZZEIM2.js → chunk-7WZ2FPB4.js} +2 -13
  24. package/dist/chunk-AOJU5LKX.js +8 -0
  25. package/dist/chunk-B2FR2ZQ4.js +420 -0
  26. package/dist/{chunk-HAHXPJQ5.js → chunk-B5J675KK.js} +16 -1684
  27. package/dist/{chunk-SFMWHPMX.js → chunk-D6COIM3U.js} +17128 -17143
  28. package/dist/{chunk-A3WSAAQS.js → chunk-DGVUTH7W.js} +9086 -34522
  29. package/dist/chunk-ELCLGWUT.js +83 -0
  30. package/dist/chunk-GO2J7SYT.js +1034 -0
  31. package/dist/chunk-HACZUMGM.js +145 -0
  32. package/dist/chunk-HM4NNKLG.js +94 -0
  33. package/dist/chunk-I3A56PFP.js +58 -0
  34. package/dist/chunk-I77PLCWG.js +961 -0
  35. package/dist/chunk-ISOQPVPY.js +232 -0
  36. package/dist/chunk-KFT5LOP2.js +610 -0
  37. package/dist/chunk-MLKGABMK.js +9 -0
  38. package/dist/chunk-MMEO22MF.js +38 -0
  39. package/dist/chunk-NHQ2U5I4.js +78 -0
  40. package/dist/chunk-PCXRFT3N.js +530 -0
  41. package/dist/chunk-PITHTCAX.js +15376 -0
  42. package/dist/chunk-QWKPSFGL.js +30 -0
  43. package/dist/chunk-RKIXES2B.js +609 -0
  44. package/dist/chunk-TSENU4GG.js +18 -0
  45. package/dist/{chunk-HLVEB5TB.js → chunk-TUTKNUMV.js} +7 -5
  46. package/dist/chunk-U3AHE2RT.js +1160 -0
  47. package/dist/chunk-UQ3MOZGC.js +644 -0
  48. package/dist/{chunk-AZFPA7JV.js → chunk-VBCE4CLX.js} +6 -4
  49. package/dist/chunk-VJWDBFSL.js +69 -0
  50. package/dist/chunk-VYMZ3QXG.js +8264 -0
  51. package/dist/chunk-WAULJDKO.js +2686 -0
  52. package/dist/chunk-WDFI5YMD.js +204 -0
  53. package/dist/chunk-XEBKF4N5.js +8 -0
  54. package/dist/chunk-Z7IUAJOF.js +13 -0
  55. package/dist/{chunk-KEATAHXH.js → chunk-ZWJRY5UI.js} +358 -581
  56. package/dist/chunk-ZXUAWVWM.js +15 -0
  57. package/dist/citations-UYB2RU5U.js +106 -0
  58. package/dist/{cli-catalog-MO6Z2CIZ.js → cli-catalog-F6FI7NB2.js} +5 -3
  59. package/dist/cli-commands-ZG5ILKDA.js +19 -0
  60. package/dist/cli.js +35 -29
  61. package/dist/competitor-EKP4R7YY.js +561 -0
  62. package/dist/content-DREE6JF3.js +257 -0
  63. package/dist/dashboard-ZALEOLLU.js +71 -0
  64. package/dist/demo-JG4Y22O4.js +75 -0
  65. package/dist/{demo-server-GIWDJGJX.js → demo-server-3A4J2C65.js} +22 -9
  66. package/dist/discover-W6GMD2HS.js +372 -0
  67. package/dist/discover-eval-CKFZHRBW.js +282 -0
  68. package/dist/doctor-TNGBSUMA.js +152 -0
  69. package/dist/evidence-3H2GFQBZ.js +57 -0
  70. package/dist/export-cmd-WUIKU5GK.js +49 -0
  71. package/dist/ga-JI6REFO4.js +911 -0
  72. package/dist/gbp-4ENDM5NS.js +370 -0
  73. package/dist/google-HKQSCLOC.js +946 -0
  74. package/dist/google-marketing-KQR5J2S4.js +403 -0
  75. package/dist/health-cmd-TS7EMMCS.js +64 -0
  76. package/dist/history-MSD5DK6K.js +90 -0
  77. package/dist/index.d.ts +47 -47
  78. package/dist/index.js +29 -6
  79. package/dist/init-L6WAEOWX.js +432 -0
  80. package/dist/insights-RTZ3IZTD.js +63 -0
  81. package/dist/intelligence-service-TH52PCNJ.js +15 -0
  82. package/dist/keys-625DZBRM.js +116 -0
  83. package/dist/keyword-CW46RNRR.js +164 -0
  84. package/dist/logs-V33SHBIW.js +30 -0
  85. package/dist/mcp-DFEDPSEG.js +14 -0
  86. package/dist/mcp.js +14 -5
  87. package/dist/measurement-plan-6W37RUOP.js +42 -0
  88. package/dist/notify-DSUOT7WO.js +125 -0
  89. package/dist/organic-evidence-BMN6L4OB.js +53 -0
  90. package/dist/overview-WRRMBZ6S.js +213 -0
  91. package/dist/project-2GJIU3FE.js +460 -0
  92. package/dist/query-3XPMGJUA.js +211 -0
  93. package/dist/research-V433CKJ4.js +200 -0
  94. package/dist/results-export-RGBU7QQQ.js +27 -0
  95. package/dist/run-NIAC6OJN.js +31 -0
  96. package/dist/schedule-KDWXRIE7.js +177 -0
  97. package/dist/search-626MPUJN.js +42 -0
  98. package/dist/serve-73SMMASI.js +557 -0
  99. package/dist/session-7WWOETZB.js +47 -0
  100. package/dist/settings-VKFQO6F2.js +107 -0
  101. package/dist/skills-5HC5H7TE.js +33 -0
  102. package/dist/snapshot-BSJUHFBC.js +538 -0
  103. package/dist/src-F6HM73TN.js +316 -0
  104. package/dist/status-V4OWP7LZ.js +126 -0
  105. package/dist/support-ARF4HER7.js +24 -0
  106. package/dist/technical-aeo-TG7CGU3F.js +625 -0
  107. package/dist/telemetry-O2IUNUBW.js +118 -0
  108. package/dist/tools-2GJIDKND.js +41 -0
  109. package/dist/traffic-XV4I3UPH.js +1295 -0
  110. package/dist/users-VGBLDL5K.js +170 -0
  111. package/dist/visibility-stats-UKJYJ6PP.js +241 -0
  112. package/dist/wordpress-JZA7CGC6.js +600 -0
  113. package/package.json +1 -1
  114. package/dist/chunk-4QQYYRHV.js +0 -23082
  115. package/dist/cli-commands-FOJR3HHU.js +0 -15
  116. package/dist/intelligence-service-XQCNWAPL.js +0 -9
@@ -0,0 +1,544 @@
1
+ import {
2
+ createApiClient
3
+ } from "./chunk-B5J675KK.js";
4
+ import "./chunk-UQ3MOZGC.js";
5
+ import {
6
+ emitJsonl
7
+ } from "./chunk-Z7IUAJOF.js";
8
+ import "./chunk-AOJU5LKX.js";
9
+ import {
10
+ CliError,
11
+ isMachineFormat
12
+ } from "./chunk-HGMYEDAQ.js";
13
+ import {
14
+ AdsDeliverySnapshotStatuses,
15
+ AdsHistoricalCampaignRollupStatuses,
16
+ AdsLiveEntityTypes,
17
+ AdsOperationKinds,
18
+ AdsOperationStates,
19
+ AdsOperationStepStates,
20
+ adsActivateTreeRequestSchema,
21
+ adsActivationGrantCreateRequestSchema,
22
+ adsAdCreateRequestSchema,
23
+ adsAdGroupCreateRequestSchema,
24
+ adsAdGroupUpdateRequestSchema,
25
+ adsAdUpdateRequestSchema,
26
+ adsCampaignCreateRequestSchema,
27
+ adsCampaignUpdateRequestSchema,
28
+ adsGeoSearchQuerySchema,
29
+ adsImageUploadRequestSchema,
30
+ adsPauseRequestSchema,
31
+ describeError,
32
+ formatMicros,
33
+ formatPercent
34
+ } from "./chunk-D6COIM3U.js";
35
+ import "./chunk-MLKGABMK.js";
36
+
37
+ // src/commands/ads.ts
38
+ import fs from "fs";
39
+ function getClient() {
40
+ return createApiClient();
41
+ }
42
+ function readRequest(inputPath, schema) {
43
+ if (!inputPath) {
44
+ throw new CliError({
45
+ code: "ADS_INPUT_REQUIRED",
46
+ message: "A JSON input file is required",
47
+ displayMessage: "Error: --input <json-file> is required (use --input - for stdin)"
48
+ });
49
+ }
50
+ try {
51
+ const raw = fs.readFileSync(inputPath === "-" ? 0 : inputPath, "utf8");
52
+ return schema.parse(JSON.parse(raw));
53
+ } catch (err) {
54
+ if (err instanceof CliError) throw err;
55
+ throw new CliError({
56
+ code: "ADS_INPUT_INVALID",
57
+ message: describeError(err),
58
+ displayMessage: `Error: invalid ads JSON input (${describeError(err)})`,
59
+ details: { inputPath }
60
+ });
61
+ }
62
+ }
63
+ function partialDayNote(inProgressDate) {
64
+ return inProgressDate === null ? "" : ` (${inProgressDate} still filling)`;
65
+ }
66
+ function printOperationDetails(operation) {
67
+ console.log(`Operation: ${operation.operationKey}`);
68
+ if (operation.entityId) console.log(`Entity: ${operation.entityType ?? "unknown"} ${operation.entityId}`);
69
+ if (operation.upstreamUpdatedAt != null) console.log(`Updated: ${operation.upstreamUpdatedAt}`);
70
+ if (operation.errorCode) console.log(`Error: ${operation.errorCode}: ${operation.errorMessage ?? ""}`);
71
+ if (operation.state === AdsOperationStates.pending || operation.state === AdsOperationStates.unknown || operation.state === AdsOperationStates.reconciling) {
72
+ if (operation.kind === AdsOperationKinds.campaign_tree_activate) {
73
+ console.log("Do not retry with a new operation key. Resume activation recovery for the original receipt instead.");
74
+ } else {
75
+ console.log("Do not retry with a new operation key. Reconcile the original receipt instead.");
76
+ }
77
+ }
78
+ }
79
+ function printOperation(result, format) {
80
+ if (isMachineFormat(format)) {
81
+ console.log(JSON.stringify(result, null, 2));
82
+ return;
83
+ }
84
+ console.log(`${result.replayed ? "Replayed" : "Recorded"} ${result.operation.kind}: ${result.operation.state}`);
85
+ printOperationDetails(result.operation);
86
+ }
87
+ function printReconciliation(result, format) {
88
+ if (isMachineFormat(format)) {
89
+ console.log(JSON.stringify(result, null, 2));
90
+ return;
91
+ }
92
+ console.log(`${result.resolved ? "Resolved" : "Still unresolved"} ${result.operation.kind}: ${result.operation.state}`);
93
+ printOperationDetails(result.operation);
94
+ }
95
+ function printActivationGrant(result, verb, format) {
96
+ if (isMachineFormat(format)) {
97
+ console.log(JSON.stringify(result, null, 2));
98
+ return;
99
+ }
100
+ const cancellationRequested = verb === "Revoked" && result.grant.revocationRequestedAt !== null;
101
+ console.log(cancellationRequested ? `Cancellation requested for activation grant ${result.grant.id}: ${result.grant.state}` : `${verb} activation grant ${result.grant.id}: ${result.grant.state}`);
102
+ if (cancellationRequested) console.log(`Requested: ${result.grant.revocationRequestedAt}`);
103
+ console.log(`Manifest: ${result.grant.manifestHash}`);
104
+ console.log(`Expires: ${result.grant.expiresAt}`);
105
+ }
106
+ function printActivation(result, format) {
107
+ if (isMachineFormat(format)) {
108
+ console.log(JSON.stringify(result, null, 2));
109
+ return;
110
+ }
111
+ const activeSteps = result.steps.filter((step) => step.state === AdsOperationStepStates.active).length;
112
+ console.log(`Activation ${result.operation.operationKey}: ${result.operation.state}`);
113
+ console.log(`Steps: ${activeSteps}/${result.steps.length} active`);
114
+ }
115
+ function describeConnection(status) {
116
+ const lines = [];
117
+ lines.push(`Connected: ${status.connected ? "yes" : "no"}`);
118
+ if (status.connected) {
119
+ if (status.displayName) lines.push(`Account: ${status.displayName} (${status.adAccountId ?? "unknown id"})`);
120
+ if (status.currencyCode) lines.push(`Currency: ${status.currencyCode}`);
121
+ if (status.timezone) lines.push(`Timezone: ${status.timezone}`);
122
+ if (status.status) lines.push(`Status: ${status.status}`);
123
+ lines.push(`Last synced: ${status.lastSyncedAt ?? "never"}`);
124
+ }
125
+ return lines;
126
+ }
127
+ async function adsConnect(project, opts) {
128
+ if (!opts.apiKey) {
129
+ throw new CliError({
130
+ code: "ADS_API_KEY_REQUIRED",
131
+ message: "API key is required (pass --api-key)",
132
+ displayMessage: "Error: --api-key is required (mint an SDK key in OpenAI Ads Manager)",
133
+ details: { project }
134
+ });
135
+ }
136
+ const client = getClient();
137
+ const result = await client.adsConnect(project, { apiKey: opts.apiKey });
138
+ if (isMachineFormat(opts.format)) {
139
+ console.log(JSON.stringify(result, null, 2));
140
+ return;
141
+ }
142
+ console.log(`Connected OpenAI ad account for ${project}.`);
143
+ for (const line of describeConnection(result)) console.log(line);
144
+ console.log("Schedule daily syncs with: canonry schedule set " + project + " --kind ads-sync --preset daily");
145
+ }
146
+ async function adsDisconnect(project, opts) {
147
+ const client = getClient();
148
+ const result = await client.adsDisconnect(project);
149
+ if (isMachineFormat(opts?.format)) {
150
+ console.log(JSON.stringify(result, null, 2));
151
+ return;
152
+ }
153
+ console.log(result.disconnected ? `Disconnected the ads connection for ${project}.` : "No ads connection to remove.");
154
+ }
155
+ async function adsStatus(project, opts) {
156
+ const client = getClient();
157
+ const result = await client.getAdsStatus(project);
158
+ if (isMachineFormat(opts?.format)) {
159
+ console.log(JSON.stringify(result, null, 2));
160
+ return;
161
+ }
162
+ for (const line of describeConnection(result)) console.log(line);
163
+ if (!result.connected) {
164
+ console.log("Connect with: canonry ads connect " + project + " --api-key <sdk-key>");
165
+ }
166
+ }
167
+ async function adsAccount(project, opts) {
168
+ const result = await getClient().getAdsAccount(project);
169
+ if (isMachineFormat(opts?.format)) {
170
+ console.log(JSON.stringify(result, null, 2));
171
+ return;
172
+ }
173
+ console.log(`Account: ${result.name}`);
174
+ console.log(`ID: ${result.id}`);
175
+ console.log(`Status: ${result.status}`);
176
+ console.log(`Currency: ${result.currencyCode ?? "unknown"}`);
177
+ console.log(`Timezone: ${result.timezone ?? "unknown"}`);
178
+ console.log(`Review: ${result.reviewStatus ?? "unknown"}`);
179
+ console.log(`Integrity: ${result.integrityReviewStatus ?? "unknown"}`);
180
+ if (result.integrityDecision) console.log(`Decision: ${result.integrityDecision}`);
181
+ if (result.url) console.log(`Ads Manager: ${result.url}`);
182
+ }
183
+ async function adsGeoSearch(project, opts) {
184
+ const parsed = adsGeoSearchQuerySchema.safeParse({ q: opts.q, limit: opts.limit });
185
+ if (!parsed.success) {
186
+ throw new CliError({
187
+ code: "ADS_GEO_QUERY_INVALID",
188
+ message: "A valid geo search query is required",
189
+ displayMessage: "Error: --query is required and --limit must be an integer from 1 to 100",
190
+ details: {
191
+ project,
192
+ issues: parsed.error.issues.map((issue) => ({ path: issue.path.join("."), message: issue.message }))
193
+ }
194
+ });
195
+ }
196
+ const query = parsed.data;
197
+ const result = await getClient().searchAdsGeo(project, query);
198
+ if (opts.format === "jsonl") {
199
+ emitJsonl(result.results.map((location) => ({ project, query: result.query, ...location })));
200
+ return;
201
+ }
202
+ if (isMachineFormat(opts.format)) {
203
+ console.log(JSON.stringify(result, null, 2));
204
+ return;
205
+ }
206
+ if (result.results.length === 0) {
207
+ console.log(`No OpenAI Ads locations matched "${result.query}".`);
208
+ return;
209
+ }
210
+ for (const location of result.results) {
211
+ const region = location.regionCode ? `, ${location.regionCode}` : "";
212
+ console.log(`${location.canonicalName} (${location.type}, ${location.countryCode}${region}) [${location.id}]`);
213
+ }
214
+ }
215
+ async function adsConversionPixels(project, opts) {
216
+ const result = await getClient().getAdsConversionPixels(project);
217
+ if (opts?.format === "jsonl") {
218
+ emitJsonl(result.pixels.map((pixel) => ({ project, ...pixel })));
219
+ return;
220
+ }
221
+ if (isMachineFormat(opts?.format)) {
222
+ console.log(JSON.stringify(result, null, 2));
223
+ return;
224
+ }
225
+ if (result.pixels.length === 0) {
226
+ console.log("No OpenAI Ads conversion pixels are configured.");
227
+ return;
228
+ }
229
+ for (const pixel of result.pixels) {
230
+ const name = pixel.name ?? "Unnamed conversion pixel";
231
+ const clientType = pixel.clientType ?? "unknown client";
232
+ const pixelId = pixel.pixelId ? ` pixel ${pixel.pixelId}` : "";
233
+ console.log(`${name} (${clientType}) [${pixel.id}]${pixelId}`);
234
+ }
235
+ }
236
+ async function adsConversionEventSettings(project, opts) {
237
+ const result = await getClient().getAdsConversionEventSettings(project);
238
+ if (opts?.format === "jsonl") {
239
+ emitJsonl(result.eventSettings.map((eventSetting) => ({ project, ...eventSetting })));
240
+ return;
241
+ }
242
+ if (isMachineFormat(opts?.format)) {
243
+ console.log(JSON.stringify(result, null, 2));
244
+ return;
245
+ }
246
+ if (result.eventSettings.length === 0) {
247
+ console.log("No OpenAI Ads conversion event settings are configured.");
248
+ return;
249
+ }
250
+ for (const eventSetting of result.eventSettings) {
251
+ const name = eventSetting.name ?? "Unnamed conversion event";
252
+ const eventType = eventSetting.eventType ?? "unknown event";
253
+ const attribution = eventSetting.attributionWindowDays === void 0 ? "unknown attribution window" : `${eventSetting.attributionWindowDays}d attribution`;
254
+ const sources = eventSetting.sources?.map((source) => source.name ?? source.id).join(", ") || "no source details";
255
+ const archived = eventSetting.archived === true ? " [archived]" : "";
256
+ console.log(
257
+ `${name}${archived}: ${eventType}, ${attribution}, ${sources} [${eventSetting.id}]`
258
+ );
259
+ }
260
+ }
261
+ async function adsOperationGet(project, opts) {
262
+ printOperation(await getClient().getAdsOperation(project, opts.operationKey), opts.format);
263
+ }
264
+ async function adsOperationsUnresolved(project, opts) {
265
+ const query = {
266
+ state: opts?.state,
267
+ limit: opts?.limit,
268
+ cursor: opts?.cursor
269
+ };
270
+ const client = getClient();
271
+ const result = Object.values(query).some((value) => value !== void 0) ? await client.getUnresolvedAdsOperations(project, query) : await client.getUnresolvedAdsOperations(project);
272
+ if (opts?.format === "jsonl") {
273
+ emitJsonl(result.operations.map((operation) => ({ project, ...operation })));
274
+ return;
275
+ }
276
+ if (isMachineFormat(opts?.format)) {
277
+ console.log(JSON.stringify(result, null, 2));
278
+ return;
279
+ }
280
+ if (result.operations.length === 0) {
281
+ console.log("No unresolved OpenAI Ads mutation receipts.");
282
+ return;
283
+ }
284
+ console.log("STATE KIND OPERATION KEY");
285
+ for (const operation of result.operations) {
286
+ console.log(`${operation.state.padEnd(13)} ${operation.kind.padEnd(21)} ${operation.operationKey}`);
287
+ }
288
+ if (result.nextCursor) console.log(`Next cursor: ${result.nextCursor}`);
289
+ }
290
+ async function adsOperationReconcile(project, opts) {
291
+ printReconciliation(
292
+ await getClient().reconcileAdsOperation(project, opts.operationKey),
293
+ opts.format
294
+ );
295
+ }
296
+ async function adsOperationResumeActivation(project, opts) {
297
+ printActivation(
298
+ await getClient().resumeAdsActivation(project, opts.operationKey),
299
+ opts.format
300
+ );
301
+ }
302
+ async function adsActivationGrantCreate(project, opts) {
303
+ const request = readRequest(
304
+ opts.input,
305
+ adsActivationGrantCreateRequestSchema
306
+ );
307
+ printActivationGrant(await getClient().createAdsActivationGrant(project, request), "Approved", opts.format);
308
+ }
309
+ async function adsActivationGrantRevoke(project, grantId, opts) {
310
+ printActivationGrant(
311
+ await getClient().revokeAdsActivationGrant(project, grantId),
312
+ "Revoked",
313
+ opts?.format
314
+ );
315
+ }
316
+ async function adsImageUpload(project, opts) {
317
+ const request = readRequest(opts.input, adsImageUploadRequestSchema);
318
+ printOperation(await getClient().uploadAdsImage(project, request), opts.format);
319
+ }
320
+ async function adsCampaignCreate(project, opts) {
321
+ const request = readRequest(opts.input, adsCampaignCreateRequestSchema);
322
+ printOperation(await getClient().createAdsCampaign(project, request), opts.format);
323
+ }
324
+ async function adsCampaignUpdate(project, campaignId, opts) {
325
+ const request = readRequest(opts.input, adsCampaignUpdateRequestSchema);
326
+ printOperation(await getClient().updateAdsCampaign(project, campaignId, request), opts.format);
327
+ }
328
+ async function adsCampaignPause(project, campaignId, opts) {
329
+ const request = readRequest(opts.input, adsPauseRequestSchema);
330
+ printOperation(await getClient().pauseAdsCampaign(project, campaignId, request), opts.format);
331
+ }
332
+ async function adsCampaignActivateTree(project, campaignId, opts) {
333
+ const request = readRequest(opts.input, adsActivateTreeRequestSchema);
334
+ printActivation(await getClient().activateAdsCampaignTree(project, campaignId, request), opts.format);
335
+ }
336
+ async function adsAdGroupCreate(project, opts) {
337
+ const request = readRequest(opts.input, adsAdGroupCreateRequestSchema);
338
+ printOperation(await getClient().createAdsAdGroup(project, request), opts.format);
339
+ }
340
+ async function adsAdGroupUpdate(project, adGroupId, opts) {
341
+ const request = readRequest(opts.input, adsAdGroupUpdateRequestSchema);
342
+ printOperation(await getClient().updateAdsAdGroup(project, adGroupId, request), opts.format);
343
+ }
344
+ async function adsAdGroupPause(project, adGroupId, opts) {
345
+ const request = readRequest(opts.input, adsPauseRequestSchema);
346
+ printOperation(await getClient().pauseAdsAdGroup(project, adGroupId, request), opts.format);
347
+ }
348
+ async function adsAdCreate(project, opts) {
349
+ const request = readRequest(opts.input, adsAdCreateRequestSchema);
350
+ printOperation(await getClient().createAdsAd(project, request), opts.format);
351
+ }
352
+ async function adsAdUpdate(project, adId, opts) {
353
+ const request = readRequest(opts.input, adsAdUpdateRequestSchema);
354
+ printOperation(await getClient().updateAdsAd(project, adId, request), opts.format);
355
+ }
356
+ async function adsAdPause(project, adId, opts) {
357
+ const request = readRequest(opts.input, adsPauseRequestSchema);
358
+ printOperation(await getClient().pauseAdsAd(project, adId, request), opts.format);
359
+ }
360
+ async function adsSync(project, opts) {
361
+ const client = getClient();
362
+ const result = await client.triggerAdsSync(project);
363
+ if (isMachineFormat(opts?.format)) {
364
+ console.log(JSON.stringify(result, null, 2));
365
+ return;
366
+ }
367
+ console.log(`Ads sync queued (run ${result.runId}). Check progress with: canonry runs get ${result.runId}`);
368
+ }
369
+ async function adsCampaigns(project, opts) {
370
+ const client = getClient();
371
+ const result = await client.getAdsCampaigns(project);
372
+ if (opts?.format === "jsonl") {
373
+ emitJsonl(result.campaigns.map((campaign) => ({ project, ...campaign })));
374
+ return;
375
+ }
376
+ if (isMachineFormat(opts?.format)) {
377
+ console.log(JSON.stringify(result, null, 2));
378
+ return;
379
+ }
380
+ if (result.campaigns.length === 0) {
381
+ console.log('No campaign snapshots. Run "canonry ads sync ' + project + '" first.');
382
+ return;
383
+ }
384
+ for (const campaign of result.campaigns) {
385
+ const budget = campaign.dailySpendLimitMicros != null ? `${formatMicros(campaign.dailySpendLimitMicros)}/day` : "no daily limit";
386
+ console.log(`${campaign.name} [${campaign.status}] \u2014 ${campaign.adGroups.length} ad groups, ${budget}`);
387
+ for (const group of campaign.adGroups) {
388
+ const bid = group.maxBidMicros != null ? `max bid ${formatMicros(group.maxBidMicros)}` : "auto bid";
389
+ console.log(` - ${group.name} [${group.status}] \u2014 ${group.ads.length} ads, ${bid}`);
390
+ const hintLines = group.contextHints.flatMap((hint) => hint.split("\n")).filter(Boolean);
391
+ for (const hint of hintLines.slice(0, 3)) console.log(` ${hint}`);
392
+ if (hintLines.length > 3) console.log(` \u2026 and ${hintLines.length - 3} more hint lines`);
393
+ }
394
+ }
395
+ }
396
+ async function adsInsights(project, opts) {
397
+ const client = getClient();
398
+ const result = await client.getAdsInsights(project, {
399
+ level: opts?.level,
400
+ entityId: opts?.entity,
401
+ from: opts?.from,
402
+ to: opts?.to
403
+ });
404
+ if (opts?.format === "jsonl") {
405
+ emitJsonl(result.rows.map((row) => ({ project, ...row })));
406
+ return;
407
+ }
408
+ if (isMachineFormat(opts?.format)) {
409
+ console.log(JSON.stringify(result, null, 2));
410
+ return;
411
+ }
412
+ if (result.rows.length === 0) {
413
+ console.log('No paid-performance rollups in range. Run "canonry ads sync ' + project + '" first.');
414
+ return;
415
+ }
416
+ const currency = result.currencyCode ?? "USD";
417
+ console.log("DATE LEVEL ENTITY IMPR CLICKS SPEND CPC");
418
+ for (const row of result.rows) {
419
+ const cpc = row.cpcMicros != null ? formatMicros(row.cpcMicros, currency) : "\u2014";
420
+ const partial = row.inProgress ? " (still filling)" : "";
421
+ console.log(
422
+ `${row.date} ${row.level.padEnd(9)} ${row.entityId.padEnd(36).slice(0, 36)} ${String(row.impressions).padStart(6)} ${String(row.clicks).padStart(6)} ${formatMicros(row.spendMicros, currency).padStart(9)} ${cpc}${partial}`
423
+ );
424
+ }
425
+ }
426
+ async function adsSummary(project, opts) {
427
+ const client = getClient();
428
+ const result = await client.getAdsSummary(project);
429
+ if (isMachineFormat(opts?.format)) {
430
+ console.log(JSON.stringify(result, null, 2));
431
+ return;
432
+ }
433
+ if (!result.connected) {
434
+ console.log("Not connected. Connect with: canonry ads connect " + project + " --api-key <sdk-key>");
435
+ return;
436
+ }
437
+ console.log(`Account: ${result.displayName ?? "unknown"} (${result.currencyCode ?? "?"})`);
438
+ console.log(`Structure: ${result.campaignCount} campaigns / ${result.adGroupCount} ad groups / ${result.adCount} ads`);
439
+ console.log(`Window: ${result.window.from ?? "\u2014"} \u2192 ${result.window.to ?? "\u2014"}${partialDayNote(result.window.inProgressDate)}`);
440
+ console.log(`Impressions: ${result.totals.impressions}`);
441
+ console.log(`Clicks: ${result.totals.clicks}${result.totals.ctr != null ? ` (CTR ${formatPercent(result.totals.ctr)})` : ""}`);
442
+ console.log(`Spend: ${formatMicros(result.totals.spendMicros, result.currencyCode ?? "USD")}${result.totals.cpcMicros != null ? ` (CPC ${formatMicros(result.totals.cpcMicros, result.currencyCode ?? "USD")})` : ""}`);
443
+ console.log(`Last synced: ${result.lastSyncedAt ?? "never"}`);
444
+ }
445
+ async function adsDeliveryDiagnostics(project, opts) {
446
+ const result = await getClient().getAdsDeliveryDiagnostics(project);
447
+ if (isMachineFormat(opts?.format)) {
448
+ console.log(JSON.stringify(result, null, 2));
449
+ return;
450
+ }
451
+ console.log(`Snapshot: ${result.snapshot.status}${result.snapshot.issue ? ` (${result.snapshot.issue})` : ""}`);
452
+ console.log(`Source sync: ${result.snapshot.sourceSync ? `${result.snapshot.sourceSync.runId} [${result.snapshot.sourceSync.status}]` : "none"}`);
453
+ console.log(`Structure: ${result.snapshot.campaignCount} campaigns / ${result.snapshot.adGroupCount} ad groups / ${result.snapshot.adCount} ads`);
454
+ console.log(`Last synced: ${result.snapshot.lastSyncedAt ?? "never"}`);
455
+ console.log(`Activity: ${result.assessment.state}`);
456
+ if (result.historicalCampaignRollups.status === AdsHistoricalCampaignRollupStatuses.reported && result.historicalCampaignRollups.totals !== null) {
457
+ const rollupWindow = result.historicalCampaignRollups.window;
458
+ console.log(`Historical: ${result.historicalCampaignRollups.totals.impressions} impressions / ${result.historicalCampaignRollups.totals.clicks} clicks (${rollupWindow.from} \u2192 ${rollupWindow.to})${partialDayNote(rollupWindow.inProgressDate)}`);
459
+ } else {
460
+ console.log("Historical: no stored campaign rollups");
461
+ }
462
+ console.log("Evidence: stored snapshot and historical rollups only; not an OpenAI eligibility or serving verdict.");
463
+ if (result.snapshot.status !== AdsDeliverySnapshotStatuses.complete) {
464
+ console.log("Structure details suppressed until a complete trusted snapshot exists.");
465
+ return;
466
+ }
467
+ for (const campaign of result.storedConfiguration.campaigns) {
468
+ const budget = campaign.dailySpendLimitMicros !== null ? `${formatMicros(campaign.dailySpendLimitMicros)}/day` : campaign.lifetimeSpendLimitMicros !== null ? `${formatMicros(campaign.lifetimeSpendLimitMicros)} lifetime` : "no stored budget";
469
+ console.log(`${campaign.name} [${campaign.status}] \u2014 ${campaign.biddingType ?? "unknown bidding"}, ${budget}, ${campaign.conversionEventSettingIds.length} conversion settings`);
470
+ for (const group of campaign.adGroups) {
471
+ const bid = group.maxBidMicros === null ? "no stored max bid" : `max bid ${formatMicros(group.maxBidMicros)}`;
472
+ console.log(` - ${group.name} [${group.status}] \u2014 ${group.billingEventType ?? "unknown billing"}, ${bid}, ${group.contextHints.length} context hints`);
473
+ for (const ad of group.ads) console.log(` ${ad.name} [${ad.status}] review=${ad.reviewStatus ?? "unknown"}`);
474
+ }
475
+ }
476
+ }
477
+ async function adsLiveDelivery(project, opts) {
478
+ const result = await getClient().getAdsLiveDelivery(project, {
479
+ campaignId: opts?.campaignId,
480
+ lookbackDays: opts?.lookbackDays
481
+ });
482
+ if (isMachineFormat(opts?.format)) {
483
+ console.log(JSON.stringify(result, null, 2));
484
+ return;
485
+ }
486
+ console.log(`Read at: ${result.fetchedAt} (live provider read)`);
487
+ console.log(`Ad account: ${result.adAccountId}`);
488
+ console.log(`Snapshot: last synced ${result.storedSnapshotSyncedAt ?? "never"}`);
489
+ console.log(`Metrics: last ${result.metricsWindow.lookbackDays}d, as the provider reported them`);
490
+ console.log(`Provider: ${result.bounds.readerCalls}/${result.bounds.maxReaderCalls} reader calls, up to ${result.bounds.maxUpstreamHttpRequests} upstream HTTP requests${result.bounds.truncated ? " (TRUNCATED, walk hit a cap)" : ""}`);
491
+ console.log(`Drift: ${result.drift.driftedEntities}/${result.drift.entitiesCompared} entities (${result.drift.statusDrifted} status, ${result.drift.metricsDrifted} metrics)`);
492
+ for (const failure of result.errors) {
493
+ console.log(`Read failed: ${failure.surface}${failure.entityId ? ` ${failure.entityId}` : ""}${failure.upstreamStatus === null ? "" : ` [HTTP ${failure.upstreamStatus}]`}`);
494
+ }
495
+ for (const entity of result.entities) {
496
+ const indent = entity.entityType === AdsLiveEntityTypes.campaign ? "" : entity.entityType === AdsLiveEntityTypes.ad_group ? " " : " ";
497
+ const label = entity.live?.name ?? entity.stored?.name ?? entity.id;
498
+ const liveStatus = entity.live === null ? "absent upstream" : entity.live.status;
499
+ const storedStatus = entity.stored === null ? "absent locally" : entity.stored.status;
500
+ const marker = entity.drifted ? "DRIFT" : "match";
501
+ console.log(`${indent}${label} [${entity.entityType}]: live ${liveStatus} / stored ${storedStatus} (${marker})`);
502
+ for (const delta of entity.fieldDeltas) {
503
+ console.log(`${indent} ${delta.field}: live ${delta.live ?? "none"} / stored ${delta.stored ?? "none"}`);
504
+ }
505
+ for (const delta of entity.metricDeltas ?? []) {
506
+ if (!delta.drifted) continue;
507
+ const live = delta.live === null ? "no provider row" : `${delta.live.impressions} impr / ${delta.live.clicks} clicks / ${formatMicros(delta.live.spendMicros)}`;
508
+ const stored = delta.stored === null ? "no stored row" : `${delta.stored.impressions} impr / ${delta.stored.clicks} clicks / ${formatMicros(delta.stored.spendMicros)}`;
509
+ console.log(`${indent} ${delta.date}: live ${live} / stored ${stored}`);
510
+ }
511
+ }
512
+ }
513
+ export {
514
+ adsAccount,
515
+ adsActivationGrantCreate,
516
+ adsActivationGrantRevoke,
517
+ adsAdCreate,
518
+ adsAdGroupCreate,
519
+ adsAdGroupPause,
520
+ adsAdGroupUpdate,
521
+ adsAdPause,
522
+ adsAdUpdate,
523
+ adsCampaignActivateTree,
524
+ adsCampaignCreate,
525
+ adsCampaignPause,
526
+ adsCampaignUpdate,
527
+ adsCampaigns,
528
+ adsConnect,
529
+ adsConversionEventSettings,
530
+ adsConversionPixels,
531
+ adsDeliveryDiagnostics,
532
+ adsDisconnect,
533
+ adsGeoSearch,
534
+ adsImageUpload,
535
+ adsInsights,
536
+ adsLiveDelivery,
537
+ adsOperationGet,
538
+ adsOperationReconcile,
539
+ adsOperationResumeActivation,
540
+ adsOperationsUnresolved,
541
+ adsStatus,
542
+ adsSummary,
543
+ adsSync
544
+ };
@@ -0,0 +1,70 @@
1
+ import {
2
+ trackCliConnection
3
+ } from "./chunk-ZXUAWVWM.js";
4
+ import "./chunk-ISOQPVPY.js";
5
+ import "./chunk-RKIXES2B.js";
6
+ import {
7
+ createApiClient
8
+ } from "./chunk-B5J675KK.js";
9
+ import "./chunk-UQ3MOZGC.js";
10
+ import "./chunk-AOJU5LKX.js";
11
+ import {
12
+ isMachineFormat
13
+ } from "./chunk-HGMYEDAQ.js";
14
+ import "./chunk-7B2Q4NJE.js";
15
+ import "./chunk-D6COIM3U.js";
16
+ import "./chunk-MLKGABMK.js";
17
+
18
+ // src/agent-webhook.ts
19
+ var AGENT_WEBHOOK_EVENTS = ["run.completed", "insight.critical", "insight.high", "citation.gained"];
20
+
21
+ // src/commands/agent.ts
22
+ async function agentAttach(opts) {
23
+ const client = createApiClient();
24
+ const existing = await client.listNotifications(opts.project);
25
+ const hasAgent = existing.some((n) => n.source === "agent");
26
+ if (hasAgent) {
27
+ trackCliConnection({ integration: "agent_webhook", action: "connect", status: "cancelled", reasonCode: "ALREADY_CONNECTED" });
28
+ if (isMachineFormat(opts.format)) {
29
+ console.log(JSON.stringify({ status: "already-attached", project: opts.project }));
30
+ } else {
31
+ console.log(`Agent webhook already attached to "${opts.project}"`);
32
+ }
33
+ return;
34
+ }
35
+ const result = await client.createNotification(opts.project, {
36
+ channel: "webhook",
37
+ url: opts.url,
38
+ events: [...AGENT_WEBHOOK_EVENTS],
39
+ source: "agent"
40
+ });
41
+ if (isMachineFormat(opts.format)) {
42
+ console.log(JSON.stringify({ status: "attached", project: opts.project, notificationId: result.id }));
43
+ } else {
44
+ console.log(`Agent webhook attached to "${opts.project}" (${opts.url})`);
45
+ }
46
+ }
47
+ async function agentDetach(opts) {
48
+ const client = createApiClient();
49
+ const existing = await client.listNotifications(opts.project);
50
+ const agentNotif = existing.find((n) => n.source === "agent");
51
+ if (!agentNotif) {
52
+ trackCliConnection({ integration: "agent_webhook", action: "disconnect", status: "cancelled", reasonCode: "NOT_CONNECTED" });
53
+ if (isMachineFormat(opts.format)) {
54
+ console.log(JSON.stringify({ status: "not-attached", project: opts.project }));
55
+ } else {
56
+ console.log(`No agent webhook found on "${opts.project}"`);
57
+ }
58
+ return;
59
+ }
60
+ await client.deleteNotification(opts.project, agentNotif.id);
61
+ if (isMachineFormat(opts.format)) {
62
+ console.log(JSON.stringify({ status: "detached", project: opts.project }));
63
+ } else {
64
+ console.log(`Agent webhook detached from "${opts.project}"`);
65
+ }
66
+ }
67
+ export {
68
+ agentAttach,
69
+ agentDetach
70
+ };