@ainyc/canonry 4.55.1 → 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 (24) hide show
  1. package/assets/agent-workspace/skills/canonry/references/server-side-traffic.md +9 -4
  2. package/assets/assets/{BacklinksPage-DVmaM864.js → BacklinksPage-buvZ4ZOd.js} +1 -1
  3. package/assets/assets/{ProjectPage-DtL3LFne.js → ProjectPage-D0UqSqe7.js} +1 -1
  4. package/assets/assets/{RunRow-BRqiLxj2.js → RunRow-D-DTu1PA.js} +1 -1
  5. package/assets/assets/{RunsPage-UxZ93-cg.js → RunsPage-CrBpgwkO.js} +1 -1
  6. package/assets/assets/{SettingsPage-Cr5_EGbk.js → SettingsPage-Bgsi9tZ2.js} +1 -1
  7. package/assets/assets/{TrafficPage-CUC_lfTe.js → TrafficPage-DAHXrzqz.js} +1 -1
  8. package/assets/assets/TrafficSourceDetailPage-DCcDN3VD.js +1 -0
  9. package/assets/assets/{extract-error-message-DD5MibWI.js → extract-error-message-BGhWiJPr.js} +1 -1
  10. package/assets/assets/{index-nnF1LnyK.js → index-CbDkoDBH.js} +2 -2
  11. package/assets/assets/{index-Bm3JQsW0.css → index-dxdJhCQO.css} +1 -1
  12. package/assets/assets/{server-traffic-DjRISEZ-.js → server-traffic-3xxyOEIX.js} +1 -1
  13. package/assets/assets/{trash-2-CJ5M--Le.js → trash-2-dppRdHYI.js} +1 -1
  14. package/assets/index.html +2 -2
  15. package/dist/{chunk-2OI7HFAB.js → chunk-5EAGNVCJ.js} +131 -188
  16. package/dist/{chunk-ZY3EDW3S.js → chunk-UOQ62KDD.js} +8 -3
  17. package/dist/{chunk-UTM3FPAJ.js → chunk-XB6Y63NI.js} +181 -3
  18. package/dist/{chunk-OFY3Z2F7.js → chunk-XHU35P3S.js} +359 -361
  19. package/dist/cli.js +12 -10
  20. package/dist/index.js +4 -4
  21. package/dist/{intelligence-service-NKAEHHJ5.js → intelligence-service-4PT22FED.js} +2 -2
  22. package/dist/mcp.js +2 -2
  23. package/package.json +6 -6
  24. package/assets/assets/TrafficSourceDetailPage-DARPL2TU.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 {
@@ -387,8 +79,77 @@ function runtimeStateMissing(message, details) {
387
79
  return new AppError("RUNTIME_STATE_MISSING", message, 503, details);
388
80
  }
389
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
+
390
151
  // ../contracts/src/project.ts
391
- var configSourceSchema = z4.enum(["cli", "api", "config-file"]);
152
+ var configSourceSchema = z2.enum(["cli", "api", "config-file"]);
392
153
  function findDuplicateLocationLabels(locations) {
393
154
  const seen = /* @__PURE__ */ new Set();
394
155
  const duplicates = /* @__PURE__ */ new Set();
@@ -425,75 +186,75 @@ function resolveLocations(projectLocations, requestedLabels) {
425
186
  }
426
187
  return resolved;
427
188
  }
428
- var projectUpsertRequestSchema = z4.object({
429
- displayName: z4.string().min(1),
430
- canonicalDomain: z4.string().min(1),
431
- ownedDomains: z4.array(z4.string().min(1)).optional(),
432
- aliases: z4.array(z4.string()).optional(),
433
- country: z4.string().length(2),
434
- language: z4.string().min(2),
435
- tags: z4.array(z4.string()).optional(),
436
- labels: z4.record(z4.string(), z4.string()).optional(),
437
- providers: z4.array(providerNameSchema).optional(),
438
- locations: z4.array(locationContextSchema).optional(),
439
- defaultLocation: z4.string().nullable().optional(),
440
- 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(),
441
202
  configSource: configSourceSchema.optional()
442
203
  });
443
- var projectDtoSchema = z4.object({
444
- id: z4.string(),
445
- name: z4.string(),
446
- displayName: z4.string().optional(),
447
- canonicalDomain: z4.string(),
448
- ownedDomains: z4.array(z4.string()).default([]),
449
- aliases: z4.array(z4.string()).default([]),
450
- country: z4.string().length(2),
451
- language: z4.string().min(2),
452
- tags: z4.array(z4.string()).default([]),
453
- 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({}),
454
215
  // Provider names this project sweeps against (subset of available providers).
455
216
  // The server emits this on every project response (see GET /projects/:name in
456
217
  // packages/api-routes/src/projects.ts) — the schema was historically missing
457
218
  // the field even though the wire shape always included it. Add it here so
458
219
  // ProjectDto consumers (web + CLI ApiClient) typecheck against the real
459
220
  // response surface.
460
- providers: z4.array(z4.string()).default([]),
461
- locations: z4.array(locationContextSchema).default([]),
462
- defaultLocation: z4.string().nullable().optional(),
463
- 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),
464
225
  configSource: configSourceSchema.default("cli"),
465
- configRevision: z4.number().int().positive().default(1),
466
- createdAt: z4.string().optional(),
467
- updatedAt: z4.string().optional()
226
+ configRevision: z2.number().int().positive().default(1),
227
+ createdAt: z2.string().optional(),
228
+ updatedAt: z2.string().optional()
468
229
  });
469
- var queryDtoSchema = z4.object({
470
- id: z4.string(),
471
- query: z4.string(),
472
- createdAt: z4.string()
230
+ var queryDtoSchema = z2.object({
231
+ id: z2.string(),
232
+ query: z2.string(),
233
+ createdAt: z2.string()
473
234
  });
474
- var keywordDtoSchema = z4.object({
475
- id: z4.string(),
476
- keyword: z4.string(),
477
- createdAt: z4.string()
235
+ var keywordDtoSchema = z2.object({
236
+ id: z2.string(),
237
+ keyword: z2.string(),
238
+ createdAt: z2.string()
478
239
  });
479
- var queryBatchRequestSchema = z4.object({
480
- 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)
481
242
  });
482
- var keywordBatchRequestSchema = z4.object({
483
- 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)
484
245
  });
485
- var queryGenerateRequestSchema = z4.object({
246
+ var queryGenerateRequestSchema = z2.object({
486
247
  provider: providerNameSchema,
487
- count: z4.number().int().min(1).max(20).optional()
248
+ count: z2.number().int().min(1).max(20).optional()
488
249
  });
489
250
  var keywordGenerateRequestSchema = queryGenerateRequestSchema;
490
- var competitorDtoSchema = z4.object({
491
- id: z4.string(),
492
- domain: z4.string(),
493
- createdAt: z4.string()
251
+ var competitorDtoSchema = z2.object({
252
+ id: z2.string(),
253
+ domain: z2.string(),
254
+ createdAt: z2.string()
494
255
  });
495
- var competitorBatchRequestSchema = z4.object({
496
- 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)
497
258
  });
498
259
  function normalizeProjectDomain(input) {
499
260
  let domain = input.trim().toLowerCase();
@@ -603,6 +364,243 @@ function effectiveBrandNames(project) {
603
364
  return names;
604
365
  }
605
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
+
606
604
  // ../contracts/src/config-schema.ts
607
605
  var configMetadataSchema = z5.object({
608
606
  name: z5.string().min(1).max(63).regex(/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/, {