@canonry/canonry 7.51.4 → 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 (172) hide show
  1. package/assets/assets/AccessControls-B5TqDgeq.js +1 -0
  2. package/assets/assets/AuditHistoryPanel-DgxiizOW.js +1 -0
  3. package/assets/assets/BacklinksPage-Ay6pdphx.js +1 -0
  4. package/assets/assets/ChartPrimitives-DIEeZdrs.js +1 -0
  5. package/assets/assets/Hint-Cn4lh0Do.js +1 -0
  6. package/assets/assets/HistoryPage-B11eFH21.js +1 -0
  7. package/assets/assets/InfoTooltip-TIx9qM5h.js +1 -0
  8. package/assets/assets/MeasurementPropertyPage-1UYI7mzP.js +4 -0
  9. package/assets/assets/ProjectPage-DoY0hftd.js +8 -0
  10. package/assets/assets/RunsPage-BPBmuQAS.js +1 -0
  11. package/assets/assets/SettingsPage-ClKnP8xy.js +1 -0
  12. package/assets/assets/SiteHealthSection-PWjKMmEn.js +2 -0
  13. package/assets/assets/TrafficPage-DkfGiJXR.js +40 -0
  14. package/assets/assets/TrafficSourceDetailPage-DQu0YNt2.js +1 -0
  15. package/assets/assets/async-handler-Bj3TnIRw.js +1 -0
  16. package/assets/assets/card-DYMyvhB9.js +60 -0
  17. package/assets/assets/extract-error-message-BRM1I_3L.js +1 -0
  18. package/assets/assets/format-helpers-DrkFERj3.js +3 -0
  19. package/assets/assets/index-CG1Jox52.js +39 -0
  20. package/assets/assets/index-CsPsaUr7.css +1 -0
  21. package/assets/assets/query-client-gRFnU4VF.js +1 -0
  22. package/assets/assets/react-query-lH82FULK.js +1 -0
  23. package/assets/assets/react-sigma_core.esm.min-D09H4byP.js +3225 -0
  24. package/assets/assets/rolldown-runtime-XKyaHtl9.js +1 -0
  25. package/assets/assets/service-Cx0HSnE9.js +1 -0
  26. package/assets/assets/vendor-lucide-BjvO55Hk.js +1 -0
  27. package/assets/assets/vendor-markdown-DWjffpgb.js +29 -0
  28. package/assets/assets/vendor-radix-BU76HM0G.js +41 -0
  29. package/assets/assets/vendor-recharts-CsHBXoK8.js +59 -0
  30. package/assets/assets/vendor-tanstack-QhOrDhIL.js +2 -0
  31. package/assets/assets/vendor-yaml-Y43rmNgW.js +105 -0
  32. package/assets/index.html +16 -8
  33. package/dist/ads-ABAT3K4K.js +544 -0
  34. package/dist/agent-5G4DRLYX.js +70 -0
  35. package/dist/agent-ask-UDVCZRO7.js +139 -0
  36. package/dist/agent-conversations-5E4JP2QZ.js +52 -0
  37. package/dist/agent-memory-7IIJ4HGZ.js +92 -0
  38. package/dist/agent-providers-BOXPUXZ4.js +55 -0
  39. package/dist/agent-transcript-4O56G6PQ.js +77 -0
  40. package/dist/analytics-PKMWX5XL.js +240 -0
  41. package/dist/apply-OK4XEBDA.js +175 -0
  42. package/dist/backfill-2OT56CX2.js +41 -0
  43. package/dist/backlinks-547WCHND.js +303 -0
  44. package/dist/bing-ZVBV4ZD5.js +418 -0
  45. package/dist/bootstrap-HUB7XQ73.js +326 -0
  46. package/dist/cdp-KQKQ4PWJ.js +162 -0
  47. package/dist/chunk-2G6IP3MO.js +517 -0
  48. package/dist/chunk-42D2LE2B.js +1273 -0
  49. package/dist/chunk-4MJYGB56.js +124 -0
  50. package/dist/chunk-63ISSSGX.js +9150 -0
  51. package/dist/{chunk-HHRM3H3L.js → chunk-6G6FTDWC.js} +8082 -13941
  52. package/dist/chunk-6GO5VVAC.js +15 -0
  53. package/dist/{chunk-6GNV6VF4.js → chunk-73P65KPW.js} +2 -2
  54. package/dist/chunk-7B2Q4NJE.js +133 -0
  55. package/dist/{chunk-KU4TPVZV.js → chunk-7WZ2FPB4.js} +2 -13
  56. package/dist/chunk-AOJU5LKX.js +8 -0
  57. package/dist/chunk-B2FR2ZQ4.js +420 -0
  58. package/dist/chunk-B5J675KK.js +6557 -0
  59. package/dist/{chunk-YOGHHIGE.js → chunk-D6COIM3U.js} +17155 -17164
  60. package/dist/{chunk-KUS7M65J.js → chunk-DGVUTH7W.js} +6809 -32243
  61. package/dist/chunk-ELCLGWUT.js +83 -0
  62. package/dist/chunk-GO2J7SYT.js +1034 -0
  63. package/dist/chunk-HACZUMGM.js +145 -0
  64. package/dist/chunk-HM4NNKLG.js +94 -0
  65. package/dist/chunk-I3A56PFP.js +58 -0
  66. package/dist/chunk-I77PLCWG.js +961 -0
  67. package/dist/chunk-ISOQPVPY.js +232 -0
  68. package/dist/chunk-KFT5LOP2.js +610 -0
  69. package/dist/chunk-MLKGABMK.js +9 -0
  70. package/dist/chunk-MMEO22MF.js +38 -0
  71. package/dist/chunk-NHQ2U5I4.js +78 -0
  72. package/dist/chunk-PCXRFT3N.js +530 -0
  73. package/dist/chunk-PITHTCAX.js +15376 -0
  74. package/dist/chunk-QWKPSFGL.js +30 -0
  75. package/dist/chunk-RKIXES2B.js +609 -0
  76. package/dist/chunk-TSENU4GG.js +18 -0
  77. package/dist/{chunk-P6D6P337.js → chunk-TUTKNUMV.js} +7 -5
  78. package/dist/chunk-U3AHE2RT.js +1160 -0
  79. package/dist/chunk-UQ3MOZGC.js +644 -0
  80. package/dist/{chunk-35QQMVO6.js → chunk-VBCE4CLX.js} +6 -4
  81. package/dist/chunk-VJWDBFSL.js +69 -0
  82. package/dist/chunk-VYMZ3QXG.js +8264 -0
  83. package/dist/chunk-WAULJDKO.js +2686 -0
  84. package/dist/chunk-WDFI5YMD.js +204 -0
  85. package/dist/chunk-XEBKF4N5.js +8 -0
  86. package/dist/chunk-Z7IUAJOF.js +13 -0
  87. package/dist/{chunk-RUWELF3K.js → chunk-ZWJRY5UI.js} +358 -581
  88. package/dist/chunk-ZXUAWVWM.js +15 -0
  89. package/dist/citations-UYB2RU5U.js +106 -0
  90. package/dist/{cli-catalog-KTQ6BHEU.js → cli-catalog-F6FI7NB2.js} +5 -3
  91. package/dist/cli-commands-ZG5ILKDA.js +19 -0
  92. package/dist/cli.js +35 -29
  93. package/dist/competitor-EKP4R7YY.js +561 -0
  94. package/dist/content-DREE6JF3.js +257 -0
  95. package/dist/dashboard-ZALEOLLU.js +71 -0
  96. package/dist/demo-JG4Y22O4.js +75 -0
  97. package/dist/{demo-server-26UUDUM7.js → demo-server-3A4J2C65.js} +22 -9
  98. package/dist/discover-W6GMD2HS.js +372 -0
  99. package/dist/discover-eval-CKFZHRBW.js +282 -0
  100. package/dist/doctor-TNGBSUMA.js +152 -0
  101. package/dist/evidence-3H2GFQBZ.js +57 -0
  102. package/dist/export-cmd-WUIKU5GK.js +49 -0
  103. package/dist/ga-JI6REFO4.js +911 -0
  104. package/dist/gbp-4ENDM5NS.js +370 -0
  105. package/dist/google-HKQSCLOC.js +946 -0
  106. package/dist/google-marketing-KQR5J2S4.js +403 -0
  107. package/dist/health-cmd-TS7EMMCS.js +64 -0
  108. package/dist/history-MSD5DK6K.js +90 -0
  109. package/dist/index.d.ts +194 -60
  110. package/dist/index.js +29 -6
  111. package/dist/init-L6WAEOWX.js +432 -0
  112. package/dist/insights-RTZ3IZTD.js +63 -0
  113. package/dist/intelligence-service-TH52PCNJ.js +15 -0
  114. package/dist/keys-625DZBRM.js +116 -0
  115. package/dist/keyword-CW46RNRR.js +164 -0
  116. package/dist/logs-V33SHBIW.js +30 -0
  117. package/dist/mcp-DFEDPSEG.js +14 -0
  118. package/dist/mcp.js +14 -5
  119. package/dist/measurement-plan-6W37RUOP.js +42 -0
  120. package/dist/notify-DSUOT7WO.js +125 -0
  121. package/dist/organic-evidence-BMN6L4OB.js +53 -0
  122. package/dist/overview-WRRMBZ6S.js +213 -0
  123. package/dist/project-2GJIU3FE.js +460 -0
  124. package/dist/query-3XPMGJUA.js +211 -0
  125. package/dist/research-V433CKJ4.js +200 -0
  126. package/dist/results-export-RGBU7QQQ.js +27 -0
  127. package/dist/run-NIAC6OJN.js +31 -0
  128. package/dist/schedule-KDWXRIE7.js +177 -0
  129. package/dist/search-626MPUJN.js +42 -0
  130. package/dist/serve-73SMMASI.js +557 -0
  131. package/dist/session-7WWOETZB.js +47 -0
  132. package/dist/settings-VKFQO6F2.js +107 -0
  133. package/dist/skills-5HC5H7TE.js +33 -0
  134. package/dist/snapshot-BSJUHFBC.js +538 -0
  135. package/dist/src-F6HM73TN.js +316 -0
  136. package/dist/status-V4OWP7LZ.js +126 -0
  137. package/dist/support-ARF4HER7.js +24 -0
  138. package/dist/technical-aeo-TG7CGU3F.js +625 -0
  139. package/dist/telemetry-O2IUNUBW.js +118 -0
  140. package/dist/tools-2GJIDKND.js +41 -0
  141. package/dist/traffic-XV4I3UPH.js +1295 -0
  142. package/dist/users-VGBLDL5K.js +170 -0
  143. package/dist/visibility-stats-UKJYJ6PP.js +241 -0
  144. package/dist/wordpress-JZA7CGC6.js +600 -0
  145. package/package.json +30 -30
  146. package/assets/assets/AuditHistoryPanel-CtWNkC6F.js +0 -1
  147. package/assets/assets/BacklinksPage-Cs3_j55C.js +0 -1
  148. package/assets/assets/ChartPrimitives-B6ryduMN.js +0 -1
  149. package/assets/assets/Hint-DICI5Jq9.js +0 -1
  150. package/assets/assets/HistoryPage-_5Vwj01m.js +0 -1
  151. package/assets/assets/MeasurementPropertyPage-B2yBTUZd.js +0 -4
  152. package/assets/assets/ProjectPage-hs-9PcoS.js +0 -8
  153. package/assets/assets/RunsPage-B_mhz9vj.js +0 -1
  154. package/assets/assets/SettingsPage-D1Lzcw03.js +0 -1
  155. package/assets/assets/SiteHealthSection-CGlrPdrk.js +0 -4
  156. package/assets/assets/TrafficPage-C27a0rQp.js +0 -40
  157. package/assets/assets/TrafficSourceDetailPage-DOSoQySv.js +0 -1
  158. package/assets/assets/extract-error-message-itBoiivg.js +0 -1
  159. package/assets/assets/index-Br2WtEIO.css +0 -1
  160. package/assets/assets/index-CdAuyP-X.js +0 -86
  161. package/assets/assets/react-sigma_core.esm.min-CPYhSQFc.js +0 -312
  162. package/assets/assets/v2-overview-adapter-DQXWmK0B.js +0 -1
  163. package/assets/assets/vendor-lucide-Y6jANGfG.js +0 -1
  164. package/assets/assets/vendor-markdown-B4giJcws.js +0 -29
  165. package/assets/assets/vendor-radix-twS1M3FF.js +0 -45
  166. package/assets/assets/vendor-recharts-D_R6YxjS.js +0 -36
  167. package/assets/assets/vendor-tanstack-ZXXkndVj.js +0 -1
  168. package/assets/assets/vendor-yaml-GWJz5H2G.js +0 -131
  169. package/dist/chunk-EQTVQIM2.js +0 -23082
  170. package/dist/chunk-GZPJ7TSE.js +0 -10872
  171. package/dist/cli-commands-5ZODWR4I.js +0 -15
  172. package/dist/intelligence-service-ZGDBVFDE.js +0 -9
@@ -0,0 +1,326 @@
1
+ import {
2
+ trackCliConnection
3
+ } from "./chunk-ZXUAWVWM.js";
4
+ import {
5
+ outcomeFailure
6
+ } from "./chunk-ISOQPVPY.js";
7
+ import {
8
+ isLoopbackBindHost
9
+ } from "./chunk-TSENU4GG.js";
10
+ import {
11
+ registeredProviderNames
12
+ } from "./chunk-QWKPSFGL.js";
13
+ import {
14
+ isTelemetryEnabled,
15
+ recordInstallRef
16
+ } from "./chunk-RKIXES2B.js";
17
+ import {
18
+ createApiClient
19
+ } from "./chunk-B5J675KK.js";
20
+ import {
21
+ configExists,
22
+ getBootstrapEnv,
23
+ getConfigDir,
24
+ getConfigPath,
25
+ loadConfig,
26
+ loadConfigRaw,
27
+ saveConfig,
28
+ withBootstrapProviderDefaults
29
+ } from "./chunk-UQ3MOZGC.js";
30
+ import "./chunk-AOJU5LKX.js";
31
+ import {
32
+ CliError,
33
+ isEndpointMissing,
34
+ isMachineFormat,
35
+ systemError
36
+ } from "./chunk-HGMYEDAQ.js";
37
+ import "./chunk-7B2Q4NJE.js";
38
+ import {
39
+ apiKeys,
40
+ createClient,
41
+ dashboardSessions,
42
+ migrate
43
+ } from "./chunk-63ISSSGX.js";
44
+ import {
45
+ ProviderNames,
46
+ ProviderReloadErrorReasons
47
+ } from "./chunk-D6COIM3U.js";
48
+ import "./chunk-MLKGABMK.js";
49
+
50
+ // src/commands/bootstrap.ts
51
+ import crypto from "crypto";
52
+ import path from "path";
53
+ import { isDeepStrictEqual } from "util";
54
+ import { eq } from "drizzle-orm";
55
+ function persistedValue(value) {
56
+ if (Array.isArray(value)) return value.map(persistedValue);
57
+ if (value && typeof value === "object") {
58
+ return Object.fromEntries(
59
+ Object.entries(value).filter(([, entry]) => entry !== void 0).map(([key, entry]) => [key, persistedValue(entry)])
60
+ );
61
+ }
62
+ return value;
63
+ }
64
+ var PROVIDER_FREE_NEXT_STEPS = [
65
+ "AI Visibility needs an answer-engine provider. Page Health does not.",
66
+ "With the server running, the operator runs `canonry settings provider gemini --api-key <key>` (free key at https://aistudio.google.com/apikey). It takes effect immediately.",
67
+ "Or the operator sets GEMINI_API_KEY and reruns `canonry bootstrap`. It reloads the matching running local server and confirms active providers; an offline server uses the saved settings at startup.",
68
+ "A provider key is the operator's credential: never ask for it in chat."
69
+ ];
70
+ var PROVIDER_CREDENTIAL_FIELDS = {
71
+ [ProviderNames.gemini]: ["apiKey", "vertexProject", "vertexRegion", "vertexCredentials"],
72
+ // A local key belongs to the server at its base URL.
73
+ [ProviderNames.local]: ["baseUrl", "apiKey"]
74
+ };
75
+ var API_KEY_CREDENTIAL_FIELDS = ["apiKey"];
76
+ function mergeEnvProvider(name, saved, fromEnv) {
77
+ const credentialFields = PROVIDER_CREDENTIAL_FIELDS[name] ?? API_KEY_CREDENTIAL_FIELDS;
78
+ const envFields = Object.entries(fromEnv);
79
+ const envValues = new Map(envFields);
80
+ const merged = {};
81
+ for (const [field, value] of Object.entries(saved ?? {})) {
82
+ if (envValues.get(field) !== void 0) merged[field] = envValues.get(field);
83
+ else if (!credentialFields.includes(field)) merged[field] = value;
84
+ }
85
+ for (const [field, value] of envFields) {
86
+ if (!(field in merged)) merged[field] = value;
87
+ }
88
+ return withBootstrapProviderDefaults(name, merged);
89
+ }
90
+ var ServerReloadStatuses = {
91
+ reloaded: "reloaded",
92
+ unchanged: "unchanged",
93
+ unavailable: "unavailable",
94
+ "not-local": "not-local",
95
+ "not-matching": "not-matching",
96
+ failed: "failed"
97
+ };
98
+ var NotMatchingReasons = {
99
+ "other-install": "other-install",
100
+ "reload-unsupported": "reload-unsupported"
101
+ };
102
+ function notMatchingReason(err) {
103
+ const status = err.details?.httpStatus;
104
+ if (status === 401 || status === 403) return NotMatchingReasons["other-install"];
105
+ if (err.details?.reason === ProviderReloadErrorReasons["install-identity-mismatch"]) return NotMatchingReasons["other-install"];
106
+ if (isEndpointMissing(err) || status === 501) return NotMatchingReasons["reload-unsupported"];
107
+ return void 0;
108
+ }
109
+ function notMatchingLines(reason, serverUrl) {
110
+ switch (reason) {
111
+ case NotMatchingReasons["other-install"]:
112
+ return [
113
+ `The server at ${serverUrl} is not this install's server, so it was not reloaded.`,
114
+ "To apply the saved providers, run `canonry settings reload-providers` against this install's server, or restart that server."
115
+ ];
116
+ case NotMatchingReasons["reload-unsupported"]:
117
+ return [
118
+ `The server at ${serverUrl} cannot reload providers: it is too old or does not support reload.`,
119
+ "Restart this install's server to apply the saved providers."
120
+ ];
121
+ }
122
+ }
123
+ async function bootstrapCommand(opts) {
124
+ const format = opts?.format ?? "text";
125
+ const configDir = getConfigDir();
126
+ const existing = configExists();
127
+ const existingConfig = existing ? loadConfig() : void 0;
128
+ const existingRaw = existing ? loadConfigRaw() : null;
129
+ const env = getBootstrapEnv(process.env);
130
+ const databasePath = env.databasePath || existingRaw?.database || path.join(configDir, "data.db");
131
+ let rawApiKey;
132
+ let generatedApiKey;
133
+ if (env.apiKey) {
134
+ rawApiKey = env.apiKey;
135
+ } else if (existingRaw) {
136
+ rawApiKey = existingRaw.apiKey;
137
+ } else {
138
+ generatedApiKey = `cnry_${crypto.randomBytes(16).toString("hex")}`;
139
+ rawApiKey = generatedApiKey;
140
+ }
141
+ const mergedProviders = { ...existingConfig?.providers };
142
+ for (const [name, fromEnv] of Object.entries(env.providers)) {
143
+ if (fromEnv) mergedProviders[name] = mergeEnvProvider(name, mergedProviders[name], fromEnv);
144
+ }
145
+ if (env.googleClientId && !env.googleClientSecret || !env.googleClientId && env.googleClientSecret) {
146
+ console.warn("Warning: GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET must both be set to configure Google OAuth. Skipping Google auth config.");
147
+ }
148
+ const mergedGoogle = env.googleClientId && env.googleClientSecret ? {
149
+ clientId: env.googleClientId,
150
+ clientSecret: env.googleClientSecret,
151
+ connections: existingConfig?.google?.connections ?? []
152
+ } : existingConfig?.google;
153
+ const keyHash = crypto.createHash("sha256").update(rawApiKey).digest("hex");
154
+ const keyPrefix = rawApiKey.slice(0, 9);
155
+ const existingConfigKeyHash = existingRaw ? crypto.createHash("sha256").update(existingRaw.apiKey).digest("hex") : void 0;
156
+ const db = createClient(databasePath);
157
+ migrate(db);
158
+ const keyChanged = db.transaction((tx) => {
159
+ let changed = false;
160
+ const rotatedAt = (/* @__PURE__ */ new Date()).toISOString();
161
+ const existingDefaults = tx.select({
162
+ id: apiKeys.id,
163
+ keyHash: apiKeys.keyHash,
164
+ keyPrefix: apiKeys.keyPrefix,
165
+ scopes: apiKeys.scopes,
166
+ projectId: apiKeys.projectId,
167
+ lastUsedAt: apiKeys.lastUsedAt,
168
+ revokedAt: apiKeys.revokedAt
169
+ }).from(apiKeys).where(eq(apiKeys.name, "default")).all();
170
+ const existingDefault = existingDefaults.find((key) => key.keyHash === existingConfigKeyHash) ?? existingDefaults.at(0);
171
+ if (existingDefault) {
172
+ const rotating = existingDefault.keyHash !== keyHash;
173
+ const needsUpdate = rotating || existingDefault.keyPrefix !== keyPrefix || !isDeepStrictEqual(existingDefault.scopes, ["*"]) || existingDefault.projectId !== null || existingDefault.revokedAt !== null;
174
+ if (needsUpdate) {
175
+ if (rotating || existingDefault.revokedAt !== null) {
176
+ tx.delete(dashboardSessions).where(eq(dashboardSessions.apiKeyId, existingDefault.id)).run();
177
+ }
178
+ tx.update(apiKeys).set({
179
+ keyHash,
180
+ keyPrefix,
181
+ scopes: ["*"],
182
+ projectId: null,
183
+ ...rotating ? { lastUsedAt: null } : {},
184
+ revokedAt: null
185
+ }).where(eq(apiKeys.id, existingDefault.id)).run();
186
+ changed = true;
187
+ }
188
+ for (const duplicate of existingDefaults) {
189
+ if (duplicate.id === existingDefault.id) continue;
190
+ tx.delete(dashboardSessions).where(eq(dashboardSessions.apiKeyId, duplicate.id)).run();
191
+ if (duplicate.revokedAt === null) {
192
+ tx.update(apiKeys).set({ revokedAt: rotatedAt }).where(eq(apiKeys.id, duplicate.id)).run();
193
+ changed = true;
194
+ }
195
+ }
196
+ } else {
197
+ tx.insert(apiKeys).values({
198
+ id: crypto.randomUUID(),
199
+ name: "default",
200
+ keyHash,
201
+ keyPrefix,
202
+ scopes: ["*"],
203
+ createdAt: rotatedAt
204
+ }).run();
205
+ changed = true;
206
+ }
207
+ return changed;
208
+ });
209
+ const apiUrl = env.apiUrl || existingRaw?.apiUrl || `http://127.0.0.1:${process.env.CANONRY_PORT || "4100"}`;
210
+ const nextConfig = {
211
+ ...existingRaw,
212
+ apiUrl,
213
+ database: databasePath,
214
+ apiKey: rawApiKey,
215
+ providers: mergedProviders,
216
+ google: mergedGoogle
217
+ };
218
+ const providersChanged = !isDeepStrictEqual(persistedValue(existingRaw?.providers ?? {}), persistedValue(mergedProviders));
219
+ const configChanged = !existingRaw || existingRaw.apiUrl !== apiUrl || existingRaw.database !== databasePath || existingRaw.apiKey !== rawApiKey || providersChanged || !isDeepStrictEqual(persistedValue(existingRaw.google), persistedValue(mergedGoogle));
220
+ const providerConnections = Object.keys(env.providers).filter((name) => env.providers[name] && !isDeepStrictEqual(persistedValue(existingRaw?.providers?.[name]), persistedValue(mergedProviders[name]))).map((name) => ({ integration: "provider", provider: name, action: existingRaw?.providers?.[name] ? "reauth" : "connect" }));
221
+ if (configChanged) {
222
+ try {
223
+ saveConfig(nextConfig);
224
+ } catch (err) {
225
+ for (const connection of providerConnections) trackCliConnection({ ...connection, status: "failed", ...outcomeFailure(err) });
226
+ throw err;
227
+ }
228
+ }
229
+ if (isTelemetryEnabled()) recordInstallRef(opts?.ref);
230
+ for (const connection of providerConnections) trackCliConnection({ ...connection, status: "succeeded" });
231
+ const status = !existing ? "created" : configChanged || keyChanged ? "updated" : "unchanged";
232
+ const providerFree = registeredProviderNames(nextConfig).length === 0;
233
+ const serverUrl = loadConfig().apiUrl;
234
+ let serverReload;
235
+ let reloadFailure;
236
+ if (!isLoopbackBindHost(new URL(serverUrl).hostname)) {
237
+ serverReload = { status: ServerReloadStatuses["not-local"] };
238
+ } else if (!providersChanged) {
239
+ serverReload = { status: ServerReloadStatuses.unchanged };
240
+ } else {
241
+ const signal = AbortSignal.timeout(4e3);
242
+ try {
243
+ const receipt = await createApiClient().reloadProviders({ configPath: getConfigPath(), databasePath }, signal);
244
+ serverReload = {
245
+ status: ServerReloadStatuses.reloaded,
246
+ providers: receipt.providers.filter((provider) => provider.configured).map((provider) => provider.name)
247
+ };
248
+ } catch (err) {
249
+ const reason = err instanceof CliError ? notMatchingReason(err) : void 0;
250
+ if (err instanceof CliError && err.code === "CONNECTION_ERROR" && err.details?.connectionUnavailable === true && !signal.aborted) {
251
+ serverReload = { status: ServerReloadStatuses.unavailable };
252
+ } else if (err instanceof CliError && reason) {
253
+ serverReload = { status: ServerReloadStatuses["not-matching"], reason, code: err.code };
254
+ } else {
255
+ reloadFailure = err instanceof CliError ? err : systemError("Provider configuration was saved, but server reload failed.");
256
+ serverReload = { status: ServerReloadStatuses.failed, code: reloadFailure.code };
257
+ }
258
+ }
259
+ }
260
+ const reloadSteps = (() => {
261
+ switch (serverReload.status) {
262
+ case ServerReloadStatuses.unavailable:
263
+ return ["Start `canonry serve` to use the saved configuration."];
264
+ case ServerReloadStatuses.failed:
265
+ return ["Resolve the server reload error, then run `canonry settings reload-providers`."];
266
+ case ServerReloadStatuses["not-matching"]:
267
+ return [notMatchingLines(serverReload.reason, serverUrl).join(" ")];
268
+ case ServerReloadStatuses.reloaded:
269
+ case ServerReloadStatuses.unchanged:
270
+ case ServerReloadStatuses["not-local"]:
271
+ return [];
272
+ }
273
+ })();
274
+ const nextSteps = [...providerFree ? PROVIDER_FREE_NEXT_STEPS : [], ...reloadSteps];
275
+ if (isMachineFormat(format)) {
276
+ console.log(JSON.stringify({
277
+ bootstrapped: true,
278
+ status,
279
+ changed: status !== "unchanged",
280
+ configPath: getConfigPath(),
281
+ databasePath,
282
+ apiUrl,
283
+ providers: Object.keys(mergedProviders),
284
+ googleConfigured: !!mergedGoogle,
285
+ generatedApiKey,
286
+ serverReload,
287
+ nextSteps
288
+ }, null, 2));
289
+ if (reloadFailure) throw reloadFailure;
290
+ return;
291
+ }
292
+ console.log(`Bootstrap ${status}. Config: ${getConfigPath()}`);
293
+ console.log(`SQLite database path: ${databasePath}`);
294
+ switch (serverReload.status) {
295
+ case ServerReloadStatuses.reloaded:
296
+ console.log(`Providers active on the running server: ${serverReload.providers.join(", ") || "none"}.`);
297
+ break;
298
+ case ServerReloadStatuses.unavailable:
299
+ console.log("Start `canonry serve` to use the saved configuration.");
300
+ break;
301
+ case ServerReloadStatuses["not-local"]:
302
+ console.log("Configuration saved locally. The configured remote server was not reloaded.");
303
+ break;
304
+ case ServerReloadStatuses["not-matching"]:
305
+ for (const line of notMatchingLines(serverReload.reason, serverUrl)) console.log(line);
306
+ break;
307
+ case ServerReloadStatuses.unchanged:
308
+ if (existing) console.log("Provider settings unchanged, so the server was not reloaded.");
309
+ break;
310
+ case ServerReloadStatuses.failed:
311
+ break;
312
+ }
313
+ if (providerFree) {
314
+ console.log("Providers: none (Page Health works now; add one later to enable AI Visibility).");
315
+ console.log(" To add one with the server running: canonry settings provider gemini --api-key <key>");
316
+ console.log(" (free key at aistudio.google.com). Or set GEMINI_API_KEY and rerun `canonry bootstrap`;");
317
+ console.log(" bootstrap reloads the matching running local server and confirms active providers.");
318
+ }
319
+ if (generatedApiKey) {
320
+ console.log(`API key (for the CLI, MCP, and agents): ${generatedApiKey}`);
321
+ }
322
+ if (reloadFailure) throw reloadFailure;
323
+ }
324
+ export {
325
+ bootstrapCommand
326
+ };
@@ -0,0 +1,162 @@
1
+ import {
2
+ trackCliConnection
3
+ } from "./chunk-ZXUAWVWM.js";
4
+ import {
5
+ outcomeFailure
6
+ } from "./chunk-ISOQPVPY.js";
7
+ import "./chunk-RKIXES2B.js";
8
+ import {
9
+ createApiClient
10
+ } from "./chunk-B5J675KK.js";
11
+ import {
12
+ loadConfig,
13
+ saveConfigPatch
14
+ } from "./chunk-UQ3MOZGC.js";
15
+ import "./chunk-AOJU5LKX.js";
16
+ import {
17
+ CliError,
18
+ isMachineFormat
19
+ } from "./chunk-HGMYEDAQ.js";
20
+ import "./chunk-7B2Q4NJE.js";
21
+ import {
22
+ describeError
23
+ } from "./chunk-D6COIM3U.js";
24
+ import "./chunk-MLKGABMK.js";
25
+
26
+ // src/commands/cdp.ts
27
+ function getClient() {
28
+ return createApiClient();
29
+ }
30
+ async function cdpConnect(opts) {
31
+ const config = loadConfig();
32
+ const host = opts.host ?? "localhost";
33
+ const port = parseInt(opts.port ?? "9222", 10);
34
+ config.cdp = {
35
+ ...config.cdp,
36
+ host,
37
+ port
38
+ };
39
+ try {
40
+ saveConfigPatch(config);
41
+ } catch (err) {
42
+ trackCliConnection({ integration: "cdp", action: "connect", status: "failed", ...outcomeFailure(err) });
43
+ throw err;
44
+ }
45
+ trackCliConnection({ integration: "cdp", action: "connect", status: "succeeded" });
46
+ if (isMachineFormat(opts.format)) {
47
+ console.log(JSON.stringify({
48
+ host,
49
+ port,
50
+ endpoint: `ws://${host}:${port}`,
51
+ restartRequired: true
52
+ }, null, 2));
53
+ return;
54
+ }
55
+ console.log(`CDP endpoint configured: ws://${host}:${port}`);
56
+ console.log("Restart canonry server for changes to take effect.");
57
+ }
58
+ async function cdpStatus(format) {
59
+ const client = getClient();
60
+ try {
61
+ const status = await client.getCdpStatus();
62
+ if (isMachineFormat(format)) {
63
+ console.log(JSON.stringify(status, null, 2));
64
+ return;
65
+ }
66
+ if (status.connected) {
67
+ console.log(`CDP connected: ${status.endpoint}`);
68
+ if (status.browserVersion) console.log(`Browser: ${status.browserVersion}`);
69
+ if (status.targets?.length) {
70
+ console.log("\nTargets:");
71
+ for (const t of status.targets) {
72
+ const status_label = t.alive ? "\u25CF alive" : "\u25CB idle";
73
+ const lastUsed = t.lastUsed ? ` (last used: ${t.lastUsed})` : "";
74
+ console.log(` ${t.name}: ${status_label}${lastUsed}`);
75
+ }
76
+ }
77
+ } else {
78
+ console.log(`CDP not connected at ${status.endpoint}`);
79
+ console.log("Launch Chrome with: chrome --remote-debugging-port=9222");
80
+ }
81
+ } catch (err) {
82
+ const msg = describeError(err);
83
+ if (msg.includes("501") || msg.includes("not configured")) {
84
+ if (isMachineFormat(format)) {
85
+ console.log(JSON.stringify({
86
+ connected: false,
87
+ endpoint: "",
88
+ targets: []
89
+ }, null, 2));
90
+ return;
91
+ }
92
+ console.log("CDP not configured. Run: canonry cdp connect --host <host> --port <port>");
93
+ } else {
94
+ throw new CliError({
95
+ code: "CDP_STATUS_FAILED",
96
+ message: `Error checking CDP status: ${msg}`,
97
+ displayMessage: `Error checking CDP status: ${msg}`
98
+ });
99
+ }
100
+ }
101
+ }
102
+ async function cdpTargets(format) {
103
+ await cdpStatus(format);
104
+ }
105
+ async function cdpScreenshot(query, opts) {
106
+ if (!query) {
107
+ throw new CliError({
108
+ code: "CLI_USAGE_ERROR",
109
+ message: "query is required",
110
+ displayMessage: 'Error: query is required\nUsage: canonry cdp screenshot "best coffee in NYC"',
111
+ details: {
112
+ command: "cdp.screenshot",
113
+ usage: 'canonry cdp screenshot "best coffee in NYC"'
114
+ }
115
+ });
116
+ }
117
+ const client = getClient();
118
+ const body = { query };
119
+ if (opts?.targets) {
120
+ body.targets = opts.targets.split(",").map((s) => s.trim());
121
+ }
122
+ try {
123
+ const response = await client.cdpScreenshot(query, body.targets);
124
+ if (isMachineFormat(opts?.format)) {
125
+ console.log(JSON.stringify(response, null, 2));
126
+ return;
127
+ }
128
+ for (const r of response.results) {
129
+ console.log(`
130
+ --- ${r.target} ---`);
131
+ console.log(`Screenshot: ${r.screenshotPath}`);
132
+ if (r.citations.length > 0) {
133
+ console.log("Citations:");
134
+ for (const c of r.citations) {
135
+ console.log(` ${c.title}: ${c.uri}`);
136
+ }
137
+ } else {
138
+ console.log("No citations found.");
139
+ }
140
+ if (r.answerText) {
141
+ const preview = r.answerText.length > 200 ? r.answerText.slice(0, 200) + "..." : r.answerText;
142
+ console.log(`Answer preview: ${preview}`);
143
+ }
144
+ }
145
+ } catch (err) {
146
+ const msg = describeError(err);
147
+ throw new CliError({
148
+ code: "CDP_SCREENSHOT_FAILED",
149
+ message: `CDP screenshot failed: ${msg}`,
150
+ displayMessage: `CDP screenshot failed: ${msg}`,
151
+ details: {
152
+ query
153
+ }
154
+ });
155
+ }
156
+ }
157
+ export {
158
+ cdpConnect,
159
+ cdpScreenshot,
160
+ cdpStatus,
161
+ cdpTargets
162
+ };