@ainyc/canonry 4.11.0 → 4.11.1

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.
@@ -8,7 +8,7 @@ import {
8
8
  categoryLabel,
9
9
  determineAnswerMentioned,
10
10
  normalizeProjectDomain
11
- } from "./chunk-WWU65YPN.js";
11
+ } from "./chunk-565T7PMC.js";
12
12
 
13
13
  // src/intelligence-service.ts
14
14
  import { eq, desc, asc, and, or, inArray } from "drizzle-orm";
@@ -1209,11 +1209,22 @@ var ga4AiReferralDtoSchema = z12.object({
1209
1209
  medium: z12.string(),
1210
1210
  sessions: z12.number(),
1211
1211
  users: z12.number(),
1212
+ /**
1213
+ * The winning attribution dimension for this (source, medium) tuple — the
1214
+ * one with the highest session count. GA4 emits one row per dimension
1215
+ * (session, first_user, manual_utm), but they're overlapping lenses on the
1216
+ * same visit; only the dominant dimension is surfaced here so the table is
1217
+ * not inflated.
1218
+ */
1212
1219
  sourceDimension: ga4SourceDimensionSchema
1213
1220
  });
1214
1221
  var ga4AiReferralLandingPageDtoSchema = z12.object({
1215
1222
  source: z12.string(),
1216
1223
  medium: z12.string(),
1224
+ /**
1225
+ * The winning attribution dimension for this (source, medium, landingPage)
1226
+ * tuple — the one with the highest session count.
1227
+ */
1217
1228
  sourceDimension: ga4SourceDimensionSchema,
1218
1229
  landingPage: z12.string(),
1219
1230
  sessions: z12.number(),
@@ -12,7 +12,7 @@ import {
12
12
  queryGenerateRequestSchema,
13
13
  runTriggerRequestSchema,
14
14
  scheduleUpsertRequestSchema
15
- } from "./chunk-WWU65YPN.js";
15
+ } from "./chunk-565T7PMC.js";
16
16
 
17
17
  // src/config.ts
18
18
  import fs from "fs";
@@ -4,7 +4,7 @@ import {
4
4
  configExists,
5
5
  loadConfig,
6
6
  saveConfigPatch
7
- } from "./chunk-ZR4AVT4T.js";
7
+ } from "./chunk-5J5BVJF7.js";
8
8
  import {
9
9
  DEFAULT_RUN_HISTORY_LIMIT,
10
10
  IntelligenceService,
@@ -61,7 +61,7 @@ import {
61
61
  runs,
62
62
  schedules,
63
63
  usageCounters
64
- } from "./chunk-5G6WYP2S.js";
64
+ } from "./chunk-3SFDZPKU.js";
65
65
  import {
66
66
  AGENT_MEMORY_VALUE_MAX_BYTES,
67
67
  AGENT_PROVIDER_IDS,
@@ -137,7 +137,7 @@ import {
137
137
  visibilityStateFromAnswerMentioned,
138
138
  windowCutoff,
139
139
  wordpressEnvSchema
140
- } from "./chunk-WWU65YPN.js";
140
+ } from "./chunk-565T7PMC.js";
141
141
 
142
142
  // src/telemetry.ts
143
143
  import crypto from "crypto";
@@ -12235,6 +12235,17 @@ function formatSharePct(numerator, total) {
12235
12235
  if (rounded === 0) return "<1%";
12236
12236
  return `${rounded}%`;
12237
12237
  }
12238
+ function pickWinningDimension(rows, tupleKey) {
12239
+ const winners = /* @__PURE__ */ new Map();
12240
+ for (const row of rows) {
12241
+ const key = tupleKey(row);
12242
+ const existing = winners.get(key);
12243
+ if (!existing || (row.sessions ?? 0) > (existing.sessions ?? 0)) {
12244
+ winners.set(key, row);
12245
+ }
12246
+ }
12247
+ return [...winners.values()].sort((a, b) => (b.sessions ?? 0) - (a.sessions ?? 0));
12248
+ }
12238
12249
  async function refreshOAuthTokenIfNeeded(googleStore, authConfig, canonicalDomain, oauthConn) {
12239
12250
  const expiresAt = oauthConn.tokenExpiresAt ? new Date(oauthConn.tokenExpiresAt).getTime() : 0;
12240
12251
  const fiveMinutes = 5 * 60 * 1e3;
@@ -12656,14 +12667,14 @@ async function ga4Routes(app, opts) {
12656
12667
  directSessions: sql5`COALESCE(SUM(${gaTrafficSnapshots.directSessions}), 0)`,
12657
12668
  users: sql5`SUM(${gaTrafficSnapshots.users})`
12658
12669
  }).from(gaTrafficSnapshots).where(and9(...snapshotConditions)).groupBy(sql5`COALESCE(${gaTrafficSnapshots.landingPageNormalized}, ${gaTrafficSnapshots.landingPage})`).orderBy(sql5`SUM(${gaTrafficSnapshots.sessions}) DESC`).limit(limit).all();
12659
- const aiReferrals = app.db.select({
12670
+ const aiReferralRows = app.db.select({
12660
12671
  source: gaAiReferrals.source,
12661
12672
  medium: gaAiReferrals.medium,
12662
12673
  sourceDimension: gaAiReferrals.sourceDimension,
12663
12674
  sessions: sql5`SUM(${gaAiReferrals.sessions})`,
12664
12675
  users: sql5`SUM(${gaAiReferrals.users})`
12665
- }).from(gaAiReferrals).where(and9(...aiConditions)).groupBy(gaAiReferrals.source, gaAiReferrals.medium, gaAiReferrals.sourceDimension).orderBy(sql5`SUM(${gaAiReferrals.sessions}) DESC`).all();
12666
- const aiReferralLandingPages = app.db.select({
12676
+ }).from(gaAiReferrals).where(and9(...aiConditions)).groupBy(gaAiReferrals.source, gaAiReferrals.medium, gaAiReferrals.sourceDimension).all();
12677
+ const aiReferralLandingPageRows = app.db.select({
12667
12678
  source: gaAiReferrals.source,
12668
12679
  medium: gaAiReferrals.medium,
12669
12680
  sourceDimension: gaAiReferrals.sourceDimension,
@@ -12675,7 +12686,15 @@ async function ga4Routes(app, opts) {
12675
12686
  gaAiReferrals.medium,
12676
12687
  gaAiReferrals.sourceDimension,
12677
12688
  sql5`COALESCE(${gaAiReferrals.landingPageNormalized}, ${gaAiReferrals.landingPage})`
12678
- ).orderBy(sql5`SUM(${gaAiReferrals.sessions}) DESC`).all();
12689
+ ).all();
12690
+ const aiReferrals = pickWinningDimension(
12691
+ aiReferralRows,
12692
+ (r) => `${r.source}\0${r.medium}`
12693
+ );
12694
+ const aiReferralLandingPages = pickWinningDimension(
12695
+ aiReferralLandingPageRows,
12696
+ (r) => `${r.source}\0${r.medium}\0${r.landingPage}`
12697
+ );
12679
12698
  const aiDeduped = app.db.select({
12680
12699
  sessions: sql5`COALESCE(SUM(max_sessions), 0)`,
12681
12700
  users: sql5`COALESCE(SUM(max_users), 0)`
package/dist/cli.js CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  setGoogleAuthConfig,
19
19
  showFirstRunNotice,
20
20
  trackEvent
21
- } from "./chunk-NG2PJHVL.js";
21
+ } from "./chunk-PBQ4Z4P4.js";
22
22
  import {
23
23
  CliError,
24
24
  EXIT_SYSTEM_ERROR,
@@ -33,7 +33,7 @@ import {
33
33
  saveConfig,
34
34
  saveConfigPatch,
35
35
  usageError
36
- } from "./chunk-ZR4AVT4T.js";
36
+ } from "./chunk-5J5BVJF7.js";
37
37
  import {
38
38
  apiKeys,
39
39
  competitors,
@@ -45,7 +45,7 @@ import {
45
45
  projects,
46
46
  querySnapshots,
47
47
  runs
48
- } from "./chunk-5G6WYP2S.js";
48
+ } from "./chunk-3SFDZPKU.js";
49
49
  import {
50
50
  CcReleaseSyncStatuses,
51
51
  CheckScopes,
@@ -64,7 +64,7 @@ import {
64
64
  providerQuotaPolicySchema,
65
65
  resolveProviderInput,
66
66
  skillsClientSchema
67
- } from "./chunk-WWU65YPN.js";
67
+ } from "./chunk-565T7PMC.js";
68
68
 
69
69
  // src/cli.ts
70
70
  import { pathToFileURL } from "url";
@@ -580,7 +580,7 @@ function readStoredGroundingSources(rawResponse) {
580
580
  return result;
581
581
  }
582
582
  async function backfillInsightsCommand(project, opts) {
583
- const { IntelligenceService } = await import("./intelligence-service-ZFIYBHLQ.js");
583
+ const { IntelligenceService } = await import("./intelligence-service-XWOFLEHJ.js");
584
584
  const config = loadConfig();
585
585
  const db = createClient(config.database);
586
586
  migrate(db);
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  createServer
3
- } from "./chunk-NG2PJHVL.js";
3
+ } from "./chunk-PBQ4Z4P4.js";
4
4
  import {
5
5
  loadConfig
6
- } from "./chunk-ZR4AVT4T.js";
7
- import "./chunk-5G6WYP2S.js";
8
- import "./chunk-WWU65YPN.js";
6
+ } from "./chunk-5J5BVJF7.js";
7
+ import "./chunk-3SFDZPKU.js";
8
+ import "./chunk-565T7PMC.js";
9
9
  export {
10
10
  createServer,
11
11
  loadConfig
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  IntelligenceService
3
- } from "./chunk-5G6WYP2S.js";
4
- import "./chunk-WWU65YPN.js";
3
+ } from "./chunk-3SFDZPKU.js";
4
+ import "./chunk-565T7PMC.js";
5
5
  export {
6
6
  IntelligenceService
7
7
  };
package/dist/mcp.js CHANGED
@@ -2,8 +2,8 @@ import {
2
2
  CliError,
3
3
  canonryMcpTools,
4
4
  createApiClient
5
- } from "./chunk-ZR4AVT4T.js";
6
- import "./chunk-WWU65YPN.js";
5
+ } from "./chunk-5J5BVJF7.js";
6
+ import "./chunk-565T7PMC.js";
7
7
 
8
8
  // src/mcp/cli.ts
9
9
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ainyc/canonry",
3
- "version": "4.11.0",
3
+ "version": "4.11.1",
4
4
  "type": "module",
5
5
  "description": "Agent-first open-source AEO operating platform - track how answer engines cite your domain",
6
6
  "license": "FSL-1.1-ALv2",
@@ -59,21 +59,21 @@
59
59
  "@types/node-cron": "^3.0.11",
60
60
  "tsup": "^8.5.1",
61
61
  "tsx": "^4.19.0",
62
- "@ainyc/canonry-config": "0.0.0",
62
+ "@ainyc/canonry-contracts": "0.0.0",
63
63
  "@ainyc/canonry-api-routes": "0.0.0",
64
64
  "@ainyc/canonry-db": "0.0.0",
65
- "@ainyc/canonry-contracts": "0.0.0",
66
65
  "@ainyc/canonry-intelligence": "0.0.0",
67
66
  "@ainyc/canonry-integration-bing": "0.0.0",
68
67
  "@ainyc/canonry-integration-commoncrawl": "0.0.0",
69
68
  "@ainyc/canonry-integration-google": "0.0.0",
70
69
  "@ainyc/canonry-integration-wordpress": "0.0.0",
70
+ "@ainyc/canonry-config": "0.0.0",
71
71
  "@ainyc/canonry-provider-cdp": "0.0.0",
72
- "@ainyc/canonry-provider-claude": "0.0.0",
72
+ "@ainyc/canonry-provider-local": "0.0.0",
73
73
  "@ainyc/canonry-provider-openai": "0.0.0",
74
- "@ainyc/canonry-provider-gemini": "0.0.0",
75
74
  "@ainyc/canonry-provider-perplexity": "0.0.0",
76
- "@ainyc/canonry-provider-local": "0.0.0"
75
+ "@ainyc/canonry-provider-claude": "0.0.0",
76
+ "@ainyc/canonry-provider-gemini": "0.0.0"
77
77
  },
78
78
  "scripts": {
79
79
  "build": "tsx scripts/copy-agent-assets.ts && tsup && tsx build-web.ts",