@ainyc/canonry 4.54.0 → 4.55.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/assets/agent-workspace/skills/canonry/references/server-side-traffic.md +9 -4
  2. package/assets/assets/{BacklinksPage-BXFT4pLI.js → BacklinksPage-buvZ4ZOd.js} +1 -1
  3. package/assets/assets/{ProjectPage-DAtd9Vay.js → ProjectPage-D0UqSqe7.js} +4 -4
  4. package/assets/assets/{RunRow-38dDceGl.js → RunRow-D-DTu1PA.js} +1 -1
  5. package/assets/assets/{RunsPage-AJnFLtaE.js → RunsPage-CrBpgwkO.js} +1 -1
  6. package/assets/assets/{SettingsPage-FT9ZAvFH.js → SettingsPage-Bgsi9tZ2.js} +1 -1
  7. package/assets/assets/TrafficPage-DAHXrzqz.js +1 -0
  8. package/assets/assets/TrafficSourceDetailPage-DCcDN3VD.js +1 -0
  9. package/assets/assets/extract-error-message-BGhWiJPr.js +1 -0
  10. package/assets/assets/{index-DLPKqyhx.js → index-CbDkoDBH.js} +62 -62
  11. package/assets/assets/{index-Bm3JQsW0.css → index-dxdJhCQO.css} +1 -1
  12. package/assets/assets/{server-traffic-GqiQYm6x.js → server-traffic-3xxyOEIX.js} +1 -1
  13. package/assets/assets/{trash-2-BwPzJ8NI.js → trash-2-dppRdHYI.js} +1 -1
  14. package/assets/index.html +2 -2
  15. package/dist/{chunk-CRO6Q25G.js → chunk-5EAGNVCJ.js} +423 -250
  16. package/dist/{chunk-J7MX3YOH.js → chunk-UOQ62KDD.js} +8 -3
  17. package/dist/{chunk-JHAHNKSN.js → chunk-XB6Y63NI.js} +260 -5
  18. package/dist/{chunk-VZPDBHBW.js → chunk-XHU35P3S.js} +367 -365
  19. package/dist/cli.js +14 -12
  20. package/dist/index.d.ts +13 -0
  21. package/dist/index.js +4 -4
  22. package/dist/{intelligence-service-OCREQUCQ.js → intelligence-service-4PT22FED.js} +2 -2
  23. package/dist/mcp.js +2 -2
  24. package/package.json +15 -14
  25. package/assets/assets/TrafficPage-B4A3oO8M.js +0 -1
  26. package/assets/assets/TrafficSourceDetailPage-8NYU1TA6.js +0 -1
  27. package/assets/assets/arrow-left-DgI0X1Q1.js +0 -1
@@ -4,316 +4,8 @@ var __export = (target, all) => {
4
4
  __defProp(target, name, { get: all[name], enumerable: true });
5
5
  };
6
6
 
7
- // ../contracts/src/run.ts
8
- import { z as z2 } from "zod";
9
-
10
- // ../contracts/src/provider.ts
11
- import { z } from "zod";
12
- var providerQuotaPolicySchema = z.object({
13
- maxConcurrency: z.number().int().positive(),
14
- maxRequestsPerMinute: z.number().int().positive(),
15
- maxRequestsPerDay: z.number().int().positive()
16
- });
17
- var ProviderNames = {
18
- gemini: "gemini",
19
- openai: "openai",
20
- claude: "claude",
21
- perplexity: "perplexity",
22
- local: "local",
23
- cdpChatgpt: "cdp:chatgpt"
24
- };
25
- var providerNameSchema = z.string().min(1);
26
- var apiProviderNameSchema = z.string().min(1);
27
- function isBrowserProvider(name) {
28
- return name.startsWith("cdp:");
29
- }
30
- var CDP_TARGETS = ["cdp:chatgpt"];
31
- function resolveProviderInput(input) {
32
- const lower = input.trim().toLowerCase();
33
- if (lower === "cdp") {
34
- return [...CDP_TARGETS];
35
- }
36
- return lower ? [lower] : [];
37
- }
38
- var locationContextSchema = z.object({
39
- label: z.string().min(1),
40
- city: z.string().min(1),
41
- region: z.string().min(1),
42
- country: z.string().length(2),
43
- timezone: z.string().optional()
44
- });
45
- var PROVIDER_LOCATION_HANDLING = {
46
- gemini: {
47
- treatment: "prompt",
48
- description: "Location appended to the query text the Gemini model receives."
49
- },
50
- perplexity: {
51
- treatment: "prompt",
52
- description: "Location appended to the query text the Perplexity model receives."
53
- },
54
- local: {
55
- treatment: "prompt",
56
- description: "Location appended to the system message sent to the local model."
57
- },
58
- openai: {
59
- treatment: "request-param",
60
- description: "Location sent as a structured `user_location` field on OpenAI\u2019s web_search tool."
61
- },
62
- claude: {
63
- treatment: "request-param",
64
- description: "Location sent as a structured `user_location` field on Anthropic\u2019s web_search_20250305 tool."
65
- },
66
- "cdp:chatgpt": {
67
- treatment: "browser-geo",
68
- description: "CDP relies on the browser session\u2019s own geolocation; canonry\u2019s configured location is not forwarded."
69
- }
70
- };
71
- var UNKNOWN_PROVIDER_HANDLING = {
72
- treatment: "ignored",
73
- description: "No documented location handling for this provider \u2014 assume the configured location was not applied."
74
- };
75
- function getProviderLocationHandling(provider) {
76
- return PROVIDER_LOCATION_HANDLING[provider] ?? UNKNOWN_PROVIDER_HANDLING;
77
- }
78
-
79
- // ../contracts/src/run.ts
80
- var runStatusSchema = z2.enum(["queued", "running", "completed", "partial", "failed", "cancelled"]);
81
- var RunStatuses = runStatusSchema.enum;
82
- var runKindSchema = z2.enum([
83
- "answer-visibility",
84
- "site-audit",
85
- "gsc-sync",
86
- "inspect-sitemap",
87
- "ga-sync",
88
- "bing-inspect",
89
- "bing-inspect-sitemap",
90
- "backlink-extract",
91
- "traffic-sync",
92
- "aeo-discover-seed",
93
- "aeo-discover-probe"
94
- ]);
95
- var RunKinds = runKindSchema.enum;
96
- var runTriggerSchema = z2.enum(["manual", "scheduled", "config-apply", "backfill", "probe"]);
97
- var RunTriggers = runTriggerSchema.enum;
98
- var citationStateSchema = z2.enum(["cited", "not-cited"]);
99
- var CitationStates = citationStateSchema.enum;
100
- var visibilityStateSchema = z2.enum(["visible", "not-visible"]);
101
- var VisibilityStates = visibilityStateSchema.enum;
102
- var mentionStateSchema = z2.enum(["mentioned", "not-mentioned"]);
103
- var MentionStates = mentionStateSchema.enum;
104
- var computedTransitionSchema = z2.enum(["new", "cited", "lost", "emerging", "not-cited"]);
105
- var ComputedTransitions = computedTransitionSchema.enum;
106
- var mentionTransitionSchema = z2.enum(["new", "mentioned", "lost", "emerging", "not-mentioned"]);
107
- var MentionTransitions = mentionTransitionSchema.enum;
108
- var operatorTriggerSchema = z2.enum([RunTriggers.manual, RunTriggers.probe]);
109
- var runTriggerRequestSchema = z2.object({
110
- kind: z2.literal(RunKinds["answer-visibility"]).optional(),
111
- trigger: operatorTriggerSchema.optional(),
112
- providers: z2.array(providerNameSchema).optional(),
113
- queries: z2.array(z2.string().min(1)).min(1).optional(),
114
- location: z2.string().min(1).optional(),
115
- allLocations: z2.boolean().optional(),
116
- noLocation: z2.boolean().optional()
117
- }).refine(
118
- (data) => Number(Boolean(data.location)) + Number(Boolean(data.allLocations)) + Number(Boolean(data.noLocation)) <= 1,
119
- { message: 'Only one of "location", "allLocations", or "noLocation" may be provided' }
120
- );
121
- var runProviderErrorSchema = z2.object({
122
- /** Human-readable error message (best-effort extracted from `raw.error.message` / `raw.message`, otherwise the raw text with any `[provider-X]` prefix stripped). */
123
- message: z2.string(),
124
- /** Original provider response payload, if the underlying error body parsed as JSON. Use this for structured fields like HTTP status, error code, etc. */
125
- raw: z2.unknown().optional()
126
- });
127
- var runErrorSchema = z2.object({
128
- /** Top-level message for runs that failed without a per-provider error (e.g. user cancellation, internal scheduling failures). */
129
- message: z2.string().optional(),
130
- /** Per-provider errors for visibility-sweep runs that had at least one provider fail. */
131
- providers: z2.record(z2.string(), runProviderErrorSchema).optional()
132
- });
133
- var runDtoSchema = z2.object({
134
- id: z2.string(),
135
- projectId: z2.string(),
136
- kind: runKindSchema,
137
- status: runStatusSchema,
138
- trigger: runTriggerSchema.default("manual"),
139
- location: z2.string().nullable().optional(),
140
- queries: z2.array(z2.string()).nullable().optional(),
141
- startedAt: z2.string().nullable().optional(),
142
- finishedAt: z2.string().nullable().optional(),
143
- error: runErrorSchema.nullable().optional(),
144
- createdAt: z2.string()
145
- });
146
- var PROVIDER_PREFIX = /^\[provider-[\w-]+\]\s+/;
147
- function parseProviderErrorMessage(msg) {
148
- const stripped = msg.replace(PROVIDER_PREFIX, "");
149
- try {
150
- const raw = JSON.parse(stripped);
151
- if (raw && typeof raw === "object") {
152
- const inner = raw;
153
- const fromErrorMessage = typeof inner.error?.message === "string" ? inner.error.message : void 0;
154
- const fromMessage = typeof inner.message === "string" ? inner.message : void 0;
155
- return { message: fromErrorMessage ?? fromMessage ?? stripped, raw };
156
- }
157
- } catch {
158
- }
159
- return { message: stripped };
160
- }
161
- function parseRunError(raw) {
162
- if (!raw) return null;
163
- let parsed;
164
- try {
165
- parsed = JSON.parse(raw);
166
- } catch {
167
- return { message: raw };
168
- }
169
- if (!parsed || typeof parsed !== "object") {
170
- return { message: raw };
171
- }
172
- const obj = parsed;
173
- const hasProviders = obj.providers && typeof obj.providers === "object";
174
- const hasMessage = typeof obj.message === "string";
175
- if (hasProviders || hasMessage) {
176
- return parsed;
177
- }
178
- const providers = {};
179
- for (const [name, val] of Object.entries(obj)) {
180
- providers[name] = parseProviderErrorMessage(typeof val === "string" ? val : JSON.stringify(val));
181
- }
182
- return { providers };
183
- }
184
- function buildRunErrorFromMessages(messages) {
185
- const providers = {};
186
- for (const [name, msg] of messages) {
187
- providers[name] = parseProviderErrorMessage(msg);
188
- }
189
- return { providers };
190
- }
191
- function serializeRunError(err) {
192
- return JSON.stringify(err);
193
- }
194
- function formatRunErrorOneLine(err) {
195
- if (err.providers) {
196
- const entries = Object.entries(err.providers);
197
- if (entries.length === 1) {
198
- const [provider, detail] = entries[0];
199
- return `${provider}: ${detail.message}`;
200
- }
201
- if (entries.length > 1) {
202
- return entries.map(([p, d]) => `${p}: ${d.message}`).join(" \u2022 ");
203
- }
204
- }
205
- return err.message ?? "Run failed.";
206
- }
207
- var groundingSourceSchema = z2.object({
208
- uri: z2.string(),
209
- title: z2.string()
210
- });
211
- var querySnapshotDtoSchema = z2.object({
212
- id: z2.string(),
213
- runId: z2.string(),
214
- queryId: z2.string(),
215
- query: z2.string().optional(),
216
- provider: providerNameSchema,
217
- citationState: citationStateSchema,
218
- answerMentioned: z2.boolean().optional(),
219
- /** @deprecated legacy name for `mentionState`; same data, kept for backwards compatibility. */
220
- visibilityState: visibilityStateSchema.optional(),
221
- /** Mention state for this snapshot — see `mentionStateSchema`. Prefer this over the legacy `visibilityState`. */
222
- mentionState: mentionStateSchema.optional(),
223
- transition: computedTransitionSchema.optional(),
224
- answerText: z2.string().nullable().optional(),
225
- citedDomains: z2.array(z2.string()).default([]),
226
- competitorOverlap: z2.array(z2.string()).default([]),
227
- recommendedCompetitors: z2.array(z2.string()).default([]),
228
- matchedTerms: z2.array(z2.string()).default([]),
229
- groundingSources: z2.array(groundingSourceSchema).default([]),
230
- searchQueries: z2.array(z2.string()).default([]),
231
- model: z2.string().nullable().optional(),
232
- location: z2.string().nullable().optional(),
233
- createdAt: z2.string()
234
- });
235
- var snapshotListResponseSchema = z2.object({
236
- snapshots: z2.array(querySnapshotDtoSchema),
237
- total: z2.number().int().nonnegative()
238
- });
239
- var snapshotDiffRowSchema = z2.object({
240
- queryId: z2.string().nullable(),
241
- query: z2.string().nullable(),
242
- run1State: citationStateSchema.nullable(),
243
- run2State: citationStateSchema.nullable(),
244
- run1AnswerMentioned: z2.boolean().nullable(),
245
- run2AnswerMentioned: z2.boolean().nullable(),
246
- /** @deprecated legacy name for `run1MentionState`. */
247
- run1VisibilityState: visibilityStateSchema.nullable(),
248
- /** @deprecated legacy name for `run2MentionState`. */
249
- run2VisibilityState: visibilityStateSchema.nullable(),
250
- /** Mention state in run 1 — prefer this over the legacy `run1VisibilityState`. */
251
- run1MentionState: mentionStateSchema.nullable().optional(),
252
- /** Mention state in run 2 — prefer this over the legacy `run2VisibilityState`. */
253
- run2MentionState: mentionStateSchema.nullable().optional(),
254
- changed: z2.boolean(),
255
- visibilityChanged: z2.boolean()
256
- });
257
- var snapshotDiffResponseSchema = z2.object({
258
- run1: z2.string(),
259
- run2: z2.string(),
260
- diff: z2.array(snapshotDiffRowSchema)
261
- });
262
- var runDetailDtoSchema = runDtoSchema.extend({
263
- snapshots: z2.array(querySnapshotDtoSchema).optional()
264
- });
265
- var latestProjectRunDtoSchema = z2.object({
266
- totalRuns: z2.number().int().nonnegative(),
267
- run: runDetailDtoSchema.nullable()
268
- });
269
- var auditLogEntrySchema = z2.object({
270
- id: z2.string(),
271
- projectId: z2.string().nullable().optional(),
272
- actor: z2.string(),
273
- action: z2.string(),
274
- entityType: z2.string(),
275
- entityId: z2.string().nullable().optional(),
276
- diff: z2.unknown().optional(),
277
- createdAt: z2.string()
278
- });
279
-
280
- // ../contracts/src/config-schema.ts
281
- import { z as z5 } from "zod";
282
-
283
- // ../contracts/src/notification.ts
284
- import { z as z3 } from "zod";
285
- var notificationEventSchema = z3.enum([
286
- "citation.lost",
287
- "citation.gained",
288
- "run.completed",
289
- "run.failed",
290
- "insight.critical",
291
- "insight.high"
292
- ]);
293
- var notificationDtoSchema = z3.object({
294
- id: z3.string(),
295
- projectId: z3.string(),
296
- channel: z3.literal("webhook"),
297
- url: z3.string().url(),
298
- urlDisplay: z3.string(),
299
- urlHost: z3.string(),
300
- events: z3.array(notificationEventSchema),
301
- enabled: z3.boolean().default(true),
302
- /** Opaque tag identifying the creator (e.g. `"agent"` for Aero webhooks). */
303
- source: z3.string().optional(),
304
- webhookSecret: z3.string().optional(),
305
- createdAt: z3.string(),
306
- updatedAt: z3.string()
307
- });
308
- var notificationCreateRequestSchema = z3.object({
309
- channel: z3.literal("webhook"),
310
- url: z3.string().url(),
311
- events: z3.array(notificationEventSchema).min(1),
312
- source: z3.string().optional()
313
- });
314
-
315
7
  // ../contracts/src/project.ts
316
- import { z as z4 } from "zod";
8
+ import { z as z2 } from "zod";
317
9
 
318
10
  // ../contracts/src/errors.ts
319
11
  var AppError = class extends Error {
@@ -349,6 +41,9 @@ function authRequired() {
349
41
  function authInvalid() {
350
42
  return new AppError("AUTH_INVALID", "Invalid API key", 401);
351
43
  }
44
+ function forbidden(message = "Forbidden") {
45
+ return new AppError("FORBIDDEN", message, 403);
46
+ }
352
47
  function providerError(message, details) {
353
48
  return new AppError("PROVIDER_ERROR", message, 502, details);
354
49
  }
@@ -384,8 +79,77 @@ function runtimeStateMissing(message, details) {
384
79
  return new AppError("RUNTIME_STATE_MISSING", message, 503, details);
385
80
  }
386
81
 
82
+ // ../contracts/src/provider.ts
83
+ import { z } from "zod";
84
+ var providerQuotaPolicySchema = z.object({
85
+ maxConcurrency: z.number().int().positive(),
86
+ maxRequestsPerMinute: z.number().int().positive(),
87
+ maxRequestsPerDay: z.number().int().positive()
88
+ });
89
+ var ProviderNames = {
90
+ gemini: "gemini",
91
+ openai: "openai",
92
+ claude: "claude",
93
+ perplexity: "perplexity",
94
+ local: "local",
95
+ cdpChatgpt: "cdp:chatgpt"
96
+ };
97
+ var providerNameSchema = z.string().min(1);
98
+ var apiProviderNameSchema = z.string().min(1);
99
+ function isBrowserProvider(name) {
100
+ return name.startsWith("cdp:");
101
+ }
102
+ var CDP_TARGETS = ["cdp:chatgpt"];
103
+ function resolveProviderInput(input) {
104
+ const lower = input.trim().toLowerCase();
105
+ if (lower === "cdp") {
106
+ return [...CDP_TARGETS];
107
+ }
108
+ return lower ? [lower] : [];
109
+ }
110
+ var locationContextSchema = z.object({
111
+ label: z.string().min(1),
112
+ city: z.string().min(1),
113
+ region: z.string().min(1),
114
+ country: z.string().length(2),
115
+ timezone: z.string().optional()
116
+ });
117
+ var PROVIDER_LOCATION_HANDLING = {
118
+ gemini: {
119
+ treatment: "prompt",
120
+ description: "Location appended to the query text the Gemini model receives."
121
+ },
122
+ perplexity: {
123
+ treatment: "prompt",
124
+ description: "Location appended to the query text the Perplexity model receives."
125
+ },
126
+ local: {
127
+ treatment: "prompt",
128
+ description: "Location appended to the system message sent to the local model."
129
+ },
130
+ openai: {
131
+ treatment: "request-param",
132
+ description: "Location sent as a structured `user_location` field on OpenAI\u2019s web_search tool."
133
+ },
134
+ claude: {
135
+ treatment: "request-param",
136
+ description: "Location sent as a structured `user_location` field on Anthropic\u2019s web_search_20250305 tool."
137
+ },
138
+ "cdp:chatgpt": {
139
+ treatment: "browser-geo",
140
+ description: "CDP relies on the browser session\u2019s own geolocation; canonry\u2019s configured location is not forwarded."
141
+ }
142
+ };
143
+ var UNKNOWN_PROVIDER_HANDLING = {
144
+ treatment: "ignored",
145
+ description: "No documented location handling for this provider \u2014 assume the configured location was not applied."
146
+ };
147
+ function getProviderLocationHandling(provider) {
148
+ return PROVIDER_LOCATION_HANDLING[provider] ?? UNKNOWN_PROVIDER_HANDLING;
149
+ }
150
+
387
151
  // ../contracts/src/project.ts
388
- var configSourceSchema = z4.enum(["cli", "api", "config-file"]);
152
+ var configSourceSchema = z2.enum(["cli", "api", "config-file"]);
389
153
  function findDuplicateLocationLabels(locations) {
390
154
  const seen = /* @__PURE__ */ new Set();
391
155
  const duplicates = /* @__PURE__ */ new Set();
@@ -422,75 +186,75 @@ function resolveLocations(projectLocations, requestedLabels) {
422
186
  }
423
187
  return resolved;
424
188
  }
425
- var projectUpsertRequestSchema = z4.object({
426
- displayName: z4.string().min(1),
427
- canonicalDomain: z4.string().min(1),
428
- ownedDomains: z4.array(z4.string().min(1)).optional(),
429
- aliases: z4.array(z4.string()).optional(),
430
- country: z4.string().length(2),
431
- language: z4.string().min(2),
432
- tags: z4.array(z4.string()).optional(),
433
- labels: z4.record(z4.string(), z4.string()).optional(),
434
- providers: z4.array(providerNameSchema).optional(),
435
- locations: z4.array(locationContextSchema).optional(),
436
- defaultLocation: z4.string().nullable().optional(),
437
- autoExtractBacklinks: z4.boolean().optional(),
189
+ var projectUpsertRequestSchema = z2.object({
190
+ displayName: z2.string().min(1),
191
+ canonicalDomain: z2.string().min(1),
192
+ ownedDomains: z2.array(z2.string().min(1)).optional(),
193
+ aliases: z2.array(z2.string()).optional(),
194
+ country: z2.string().length(2),
195
+ language: z2.string().min(2),
196
+ tags: z2.array(z2.string()).optional(),
197
+ labels: z2.record(z2.string(), z2.string()).optional(),
198
+ providers: z2.array(providerNameSchema).optional(),
199
+ locations: z2.array(locationContextSchema).optional(),
200
+ defaultLocation: z2.string().nullable().optional(),
201
+ autoExtractBacklinks: z2.boolean().optional(),
438
202
  configSource: configSourceSchema.optional()
439
203
  });
440
- var projectDtoSchema = z4.object({
441
- id: z4.string(),
442
- name: z4.string(),
443
- displayName: z4.string().optional(),
444
- canonicalDomain: z4.string(),
445
- ownedDomains: z4.array(z4.string()).default([]),
446
- aliases: z4.array(z4.string()).default([]),
447
- country: z4.string().length(2),
448
- language: z4.string().min(2),
449
- tags: z4.array(z4.string()).default([]),
450
- labels: z4.record(z4.string(), z4.string()).default({}),
204
+ var projectDtoSchema = z2.object({
205
+ id: z2.string(),
206
+ name: z2.string(),
207
+ displayName: z2.string().optional(),
208
+ canonicalDomain: z2.string(),
209
+ ownedDomains: z2.array(z2.string()).default([]),
210
+ aliases: z2.array(z2.string()).default([]),
211
+ country: z2.string().length(2),
212
+ language: z2.string().min(2),
213
+ tags: z2.array(z2.string()).default([]),
214
+ labels: z2.record(z2.string(), z2.string()).default({}),
451
215
  // Provider names this project sweeps against (subset of available providers).
452
216
  // The server emits this on every project response (see GET /projects/:name in
453
217
  // packages/api-routes/src/projects.ts) — the schema was historically missing
454
218
  // the field even though the wire shape always included it. Add it here so
455
219
  // ProjectDto consumers (web + CLI ApiClient) typecheck against the real
456
220
  // response surface.
457
- providers: z4.array(z4.string()).default([]),
458
- locations: z4.array(locationContextSchema).default([]),
459
- defaultLocation: z4.string().nullable().optional(),
460
- autoExtractBacklinks: z4.boolean().default(false),
221
+ providers: z2.array(z2.string()).default([]),
222
+ locations: z2.array(locationContextSchema).default([]),
223
+ defaultLocation: z2.string().nullable().optional(),
224
+ autoExtractBacklinks: z2.boolean().default(false),
461
225
  configSource: configSourceSchema.default("cli"),
462
- configRevision: z4.number().int().positive().default(1),
463
- createdAt: z4.string().optional(),
464
- updatedAt: z4.string().optional()
226
+ configRevision: z2.number().int().positive().default(1),
227
+ createdAt: z2.string().optional(),
228
+ updatedAt: z2.string().optional()
465
229
  });
466
- var queryDtoSchema = z4.object({
467
- id: z4.string(),
468
- query: z4.string(),
469
- createdAt: z4.string()
230
+ var queryDtoSchema = z2.object({
231
+ id: z2.string(),
232
+ query: z2.string(),
233
+ createdAt: z2.string()
470
234
  });
471
- var keywordDtoSchema = z4.object({
472
- id: z4.string(),
473
- keyword: z4.string(),
474
- createdAt: z4.string()
235
+ var keywordDtoSchema = z2.object({
236
+ id: z2.string(),
237
+ keyword: z2.string(),
238
+ createdAt: z2.string()
475
239
  });
476
- var queryBatchRequestSchema = z4.object({
477
- queries: z4.array(z4.string().trim().min(1)).min(1)
240
+ var queryBatchRequestSchema = z2.object({
241
+ queries: z2.array(z2.string().trim().min(1)).min(1)
478
242
  });
479
- var keywordBatchRequestSchema = z4.object({
480
- keywords: z4.array(z4.string().trim().min(1)).min(1)
243
+ var keywordBatchRequestSchema = z2.object({
244
+ keywords: z2.array(z2.string().trim().min(1)).min(1)
481
245
  });
482
- var queryGenerateRequestSchema = z4.object({
246
+ var queryGenerateRequestSchema = z2.object({
483
247
  provider: providerNameSchema,
484
- count: z4.number().int().min(1).max(20).optional()
248
+ count: z2.number().int().min(1).max(20).optional()
485
249
  });
486
250
  var keywordGenerateRequestSchema = queryGenerateRequestSchema;
487
- var competitorDtoSchema = z4.object({
488
- id: z4.string(),
489
- domain: z4.string(),
490
- createdAt: z4.string()
251
+ var competitorDtoSchema = z2.object({
252
+ id: z2.string(),
253
+ domain: z2.string(),
254
+ createdAt: z2.string()
491
255
  });
492
- var competitorBatchRequestSchema = z4.object({
493
- competitors: z4.array(z4.string().trim().min(1)).min(1)
256
+ var competitorBatchRequestSchema = z2.object({
257
+ competitors: z2.array(z2.string().trim().min(1)).min(1)
494
258
  });
495
259
  function normalizeProjectDomain(input) {
496
260
  let domain = input.trim().toLowerCase();
@@ -600,6 +364,243 @@ function effectiveBrandNames(project) {
600
364
  return names;
601
365
  }
602
366
 
367
+ // ../contracts/src/run.ts
368
+ import { z as z3 } from "zod";
369
+ var runStatusSchema = z3.enum(["queued", "running", "completed", "partial", "failed", "cancelled"]);
370
+ var RunStatuses = runStatusSchema.enum;
371
+ var runKindSchema = z3.enum([
372
+ "answer-visibility",
373
+ "site-audit",
374
+ "gsc-sync",
375
+ "inspect-sitemap",
376
+ "ga-sync",
377
+ "bing-inspect",
378
+ "bing-inspect-sitemap",
379
+ "backlink-extract",
380
+ "traffic-sync",
381
+ "aeo-discover-seed",
382
+ "aeo-discover-probe"
383
+ ]);
384
+ var RunKinds = runKindSchema.enum;
385
+ var runTriggerSchema = z3.enum(["manual", "scheduled", "config-apply", "backfill", "probe"]);
386
+ var RunTriggers = runTriggerSchema.enum;
387
+ var citationStateSchema = z3.enum(["cited", "not-cited"]);
388
+ var CitationStates = citationStateSchema.enum;
389
+ var visibilityStateSchema = z3.enum(["visible", "not-visible"]);
390
+ var VisibilityStates = visibilityStateSchema.enum;
391
+ var mentionStateSchema = z3.enum(["mentioned", "not-mentioned"]);
392
+ var MentionStates = mentionStateSchema.enum;
393
+ var computedTransitionSchema = z3.enum(["new", "cited", "lost", "emerging", "not-cited"]);
394
+ var ComputedTransitions = computedTransitionSchema.enum;
395
+ var mentionTransitionSchema = z3.enum(["new", "mentioned", "lost", "emerging", "not-mentioned"]);
396
+ var MentionTransitions = mentionTransitionSchema.enum;
397
+ var operatorTriggerSchema = z3.enum([RunTriggers.manual, RunTriggers.probe]);
398
+ var runTriggerRequestSchema = z3.object({
399
+ kind: z3.literal(RunKinds["answer-visibility"]).optional(),
400
+ trigger: operatorTriggerSchema.optional(),
401
+ providers: z3.array(providerNameSchema).optional(),
402
+ queries: z3.array(z3.string().min(1)).min(1).optional(),
403
+ location: z3.string().min(1).optional(),
404
+ allLocations: z3.boolean().optional(),
405
+ noLocation: z3.boolean().optional()
406
+ }).refine(
407
+ (data) => Number(Boolean(data.location)) + Number(Boolean(data.allLocations)) + Number(Boolean(data.noLocation)) <= 1,
408
+ { message: 'Only one of "location", "allLocations", or "noLocation" may be provided' }
409
+ );
410
+ var runProviderErrorSchema = z3.object({
411
+ /** Human-readable error message (best-effort extracted from `raw.error.message` / `raw.message`, otherwise the raw text with any `[provider-X]` prefix stripped). */
412
+ message: z3.string(),
413
+ /** Original provider response payload, if the underlying error body parsed as JSON. Use this for structured fields like HTTP status, error code, etc. */
414
+ raw: z3.unknown().optional()
415
+ });
416
+ var runErrorSchema = z3.object({
417
+ /** Top-level message for runs that failed without a per-provider error (e.g. user cancellation, internal scheduling failures). */
418
+ message: z3.string().optional(),
419
+ /** Per-provider errors for visibility-sweep runs that had at least one provider fail. */
420
+ providers: z3.record(z3.string(), runProviderErrorSchema).optional()
421
+ });
422
+ var runDtoSchema = z3.object({
423
+ id: z3.string(),
424
+ projectId: z3.string(),
425
+ kind: runKindSchema,
426
+ status: runStatusSchema,
427
+ trigger: runTriggerSchema.default("manual"),
428
+ location: z3.string().nullable().optional(),
429
+ queries: z3.array(z3.string()).nullable().optional(),
430
+ startedAt: z3.string().nullable().optional(),
431
+ finishedAt: z3.string().nullable().optional(),
432
+ error: runErrorSchema.nullable().optional(),
433
+ createdAt: z3.string()
434
+ });
435
+ var PROVIDER_PREFIX = /^\[provider-[\w-]+\]\s+/;
436
+ function parseProviderErrorMessage(msg) {
437
+ const stripped = msg.replace(PROVIDER_PREFIX, "");
438
+ try {
439
+ const raw = JSON.parse(stripped);
440
+ if (raw && typeof raw === "object") {
441
+ const inner = raw;
442
+ const fromErrorMessage = typeof inner.error?.message === "string" ? inner.error.message : void 0;
443
+ const fromMessage = typeof inner.message === "string" ? inner.message : void 0;
444
+ return { message: fromErrorMessage ?? fromMessage ?? stripped, raw };
445
+ }
446
+ } catch {
447
+ }
448
+ return { message: stripped };
449
+ }
450
+ function parseRunError(raw) {
451
+ if (!raw) return null;
452
+ let parsed;
453
+ try {
454
+ parsed = JSON.parse(raw);
455
+ } catch {
456
+ return { message: raw };
457
+ }
458
+ if (!parsed || typeof parsed !== "object") {
459
+ return { message: raw };
460
+ }
461
+ const obj = parsed;
462
+ const hasProviders = obj.providers && typeof obj.providers === "object";
463
+ const hasMessage = typeof obj.message === "string";
464
+ if (hasProviders || hasMessage) {
465
+ return parsed;
466
+ }
467
+ const providers = {};
468
+ for (const [name, val] of Object.entries(obj)) {
469
+ providers[name] = parseProviderErrorMessage(typeof val === "string" ? val : JSON.stringify(val));
470
+ }
471
+ return { providers };
472
+ }
473
+ function buildRunErrorFromMessages(messages) {
474
+ const providers = {};
475
+ for (const [name, msg] of messages) {
476
+ providers[name] = parseProviderErrorMessage(msg);
477
+ }
478
+ return { providers };
479
+ }
480
+ function serializeRunError(err) {
481
+ return JSON.stringify(err);
482
+ }
483
+ function formatRunErrorOneLine(err) {
484
+ if (err.providers) {
485
+ const entries = Object.entries(err.providers);
486
+ if (entries.length === 1) {
487
+ const [provider, detail] = entries[0];
488
+ return `${provider}: ${detail.message}`;
489
+ }
490
+ if (entries.length > 1) {
491
+ return entries.map(([p, d]) => `${p}: ${d.message}`).join(" \u2022 ");
492
+ }
493
+ }
494
+ return err.message ?? "Run failed.";
495
+ }
496
+ var groundingSourceSchema = z3.object({
497
+ uri: z3.string(),
498
+ title: z3.string()
499
+ });
500
+ var querySnapshotDtoSchema = z3.object({
501
+ id: z3.string(),
502
+ runId: z3.string(),
503
+ queryId: z3.string(),
504
+ query: z3.string().optional(),
505
+ provider: providerNameSchema,
506
+ citationState: citationStateSchema,
507
+ answerMentioned: z3.boolean().optional(),
508
+ /** @deprecated legacy name for `mentionState`; same data, kept for backwards compatibility. */
509
+ visibilityState: visibilityStateSchema.optional(),
510
+ /** Mention state for this snapshot — see `mentionStateSchema`. Prefer this over the legacy `visibilityState`. */
511
+ mentionState: mentionStateSchema.optional(),
512
+ transition: computedTransitionSchema.optional(),
513
+ answerText: z3.string().nullable().optional(),
514
+ citedDomains: z3.array(z3.string()).default([]),
515
+ competitorOverlap: z3.array(z3.string()).default([]),
516
+ recommendedCompetitors: z3.array(z3.string()).default([]),
517
+ matchedTerms: z3.array(z3.string()).default([]),
518
+ groundingSources: z3.array(groundingSourceSchema).default([]),
519
+ searchQueries: z3.array(z3.string()).default([]),
520
+ model: z3.string().nullable().optional(),
521
+ location: z3.string().nullable().optional(),
522
+ createdAt: z3.string()
523
+ });
524
+ var snapshotListResponseSchema = z3.object({
525
+ snapshots: z3.array(querySnapshotDtoSchema),
526
+ total: z3.number().int().nonnegative()
527
+ });
528
+ var snapshotDiffRowSchema = z3.object({
529
+ queryId: z3.string().nullable(),
530
+ query: z3.string().nullable(),
531
+ run1State: citationStateSchema.nullable(),
532
+ run2State: citationStateSchema.nullable(),
533
+ run1AnswerMentioned: z3.boolean().nullable(),
534
+ run2AnswerMentioned: z3.boolean().nullable(),
535
+ /** @deprecated legacy name for `run1MentionState`. */
536
+ run1VisibilityState: visibilityStateSchema.nullable(),
537
+ /** @deprecated legacy name for `run2MentionState`. */
538
+ run2VisibilityState: visibilityStateSchema.nullable(),
539
+ /** Mention state in run 1 — prefer this over the legacy `run1VisibilityState`. */
540
+ run1MentionState: mentionStateSchema.nullable().optional(),
541
+ /** Mention state in run 2 — prefer this over the legacy `run2VisibilityState`. */
542
+ run2MentionState: mentionStateSchema.nullable().optional(),
543
+ changed: z3.boolean(),
544
+ visibilityChanged: z3.boolean()
545
+ });
546
+ var snapshotDiffResponseSchema = z3.object({
547
+ run1: z3.string(),
548
+ run2: z3.string(),
549
+ diff: z3.array(snapshotDiffRowSchema)
550
+ });
551
+ var runDetailDtoSchema = runDtoSchema.extend({
552
+ snapshots: z3.array(querySnapshotDtoSchema).optional()
553
+ });
554
+ var latestProjectRunDtoSchema = z3.object({
555
+ totalRuns: z3.number().int().nonnegative(),
556
+ run: runDetailDtoSchema.nullable()
557
+ });
558
+ var auditLogEntrySchema = z3.object({
559
+ id: z3.string(),
560
+ projectId: z3.string().nullable().optional(),
561
+ actor: z3.string(),
562
+ action: z3.string(),
563
+ entityType: z3.string(),
564
+ entityId: z3.string().nullable().optional(),
565
+ diff: z3.unknown().optional(),
566
+ createdAt: z3.string()
567
+ });
568
+
569
+ // ../contracts/src/config-schema.ts
570
+ import { z as z5 } from "zod";
571
+
572
+ // ../contracts/src/notification.ts
573
+ import { z as z4 } from "zod";
574
+ var notificationEventSchema = z4.enum([
575
+ "citation.lost",
576
+ "citation.gained",
577
+ "run.completed",
578
+ "run.failed",
579
+ "insight.critical",
580
+ "insight.high"
581
+ ]);
582
+ var notificationDtoSchema = z4.object({
583
+ id: z4.string(),
584
+ projectId: z4.string(),
585
+ channel: z4.literal("webhook"),
586
+ url: z4.string().url(),
587
+ urlDisplay: z4.string(),
588
+ urlHost: z4.string(),
589
+ events: z4.array(notificationEventSchema),
590
+ enabled: z4.boolean().default(true),
591
+ /** Opaque tag identifying the creator (e.g. `"agent"` for Aero webhooks). */
592
+ source: z4.string().optional(),
593
+ webhookSecret: z4.string().optional(),
594
+ createdAt: z4.string(),
595
+ updatedAt: z4.string()
596
+ });
597
+ var notificationCreateRequestSchema = z4.object({
598
+ channel: z4.literal("webhook"),
599
+ url: z4.string().url(),
600
+ events: z4.array(notificationEventSchema).min(1),
601
+ source: z4.string().optional()
602
+ });
603
+
603
604
  // ../contracts/src/config-schema.ts
604
605
  var configMetadataSchema = z5.object({
605
606
  name: z5.string().min(1).max(63).regex(/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/, {
@@ -2661,7 +2662,7 @@ var serverActivitySectionSchema = z21.object({
2661
2662
  byOperator: z21.array(z21.object({
2662
2663
  operator: z21.string(),
2663
2664
  verifiedHits: z21.number(),
2664
- /** Shown to agency audience only claimed-bot UA, rDNS not confirmed. */
2665
+ /** Shown to agency audience only: claimed-bot UA, source IP not in a published range. */
2665
2666
  unverifiedHits: z21.number(),
2666
2667
  /** Per-user fetches from this operator's AI surface (ChatGPT-User, …). */
2667
2668
  userFetchHits: z21.number(),
@@ -3160,7 +3161,7 @@ var VercelTrafficEnvironments = vercelTrafficEnvironmentSchema.enum;
3160
3161
  var vercelTrafficSourceConfigSchema = z23.object({
3161
3162
  /** Vercel project id (e.g. `prj_...`). */
3162
3163
  projectId: z23.string().min(1),
3163
- /** Vercel team / owner id (e.g. `team_...`). */
3164
+ /** Vercel team or account id: the org that owns the project. */
3164
3165
  teamId: z23.string().min(1),
3165
3166
  environment: vercelTrafficEnvironmentSchema
3166
3167
  });
@@ -3196,9 +3197,9 @@ var trafficConnectWordpressRequestSchema = z23.object({
3196
3197
  var trafficConnectVercelRequestSchema = z23.object({
3197
3198
  /** Vercel project id (e.g. `prj_...`) — from the Vercel dashboard or `.vercel/project.json`. */
3198
3199
  projectId: z23.string().min(1),
3199
- /** Vercel team / owner id (e.g. `team_...`). */
3200
+ /** Vercel team or account id: the org that owns the project ("orgId" in .vercel/project.json). */
3200
3201
  teamId: z23.string().min(1),
3201
- /** Vercel API token (personal access token). Stored in `~/.canonry/config.yaml`, never the DB. */
3202
+ /** Vercel personal access token. Stored in `~/.canonry/config.yaml`, never the DB. */
3202
3203
  token: z23.string().min(1),
3203
3204
  /** Which deployment environment's request logs to pull. Default: `production`. */
3204
3205
  environment: vercelTrafficEnvironmentSchema.optional(),
@@ -3606,6 +3607,7 @@ export {
3606
3607
  validationError,
3607
3608
  authRequired,
3608
3609
  authInvalid,
3610
+ forbidden,
3609
3611
  providerError,
3610
3612
  runInProgress,
3611
3613
  runNotCancellable,