@rankcli/agent-runtime 0.0.15 → 0.0.17

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 (203) hide show
  1. package/README.md +5 -4
  2. package/dist/index.d.mts +44 -393
  3. package/dist/index.d.ts +44 -393
  4. package/dist/index.js +22098 -26131
  5. package/dist/index.mjs +11834 -15857
  6. package/package.json +10 -4
  7. package/scripts/build-deno.ts +0 -134
  8. package/src/analyzers/core-web-vitals-analyzer.test.ts +0 -236
  9. package/src/analyzers/core-web-vitals-analyzer.ts +0 -557
  10. package/src/analyzers/geo-analyzer.test.ts +0 -310
  11. package/src/analyzers/geo-analyzer.ts +0 -814
  12. package/src/analyzers/image-optimization-analyzer.test.ts +0 -145
  13. package/src/analyzers/image-optimization-analyzer.ts +0 -348
  14. package/src/analyzers/index.ts +0 -233
  15. package/src/analyzers/internal-linking-analyzer.test.ts +0 -141
  16. package/src/analyzers/internal-linking-analyzer.ts +0 -419
  17. package/src/analyzers/mobile-seo-analyzer.test.ts +0 -140
  18. package/src/analyzers/mobile-seo-analyzer.ts +0 -455
  19. package/src/analyzers/security-headers-analyzer.test.ts +0 -115
  20. package/src/analyzers/security-headers-analyzer.ts +0 -318
  21. package/src/analyzers/structured-data-analyzer.test.ts +0 -210
  22. package/src/analyzers/structured-data-analyzer.ts +0 -590
  23. package/src/audit/ai/analyzer.ts +0 -347
  24. package/src/audit/ai/index.ts +0 -29
  25. package/src/audit/ai/prompts/content-analysis.ts +0 -271
  26. package/src/audit/ai/types.ts +0 -179
  27. package/src/audit/checks/additional-checks.ts +0 -439
  28. package/src/audit/checks/agent-experience.ts +0 -108
  29. package/src/audit/checks/ai-citation-worthiness.ts +0 -399
  30. package/src/audit/checks/ai-content-structure.ts +0 -325
  31. package/src/audit/checks/ai-readiness.ts +0 -406
  32. package/src/audit/checks/anchor-text.ts +0 -179
  33. package/src/audit/checks/answer-conciseness.ts +0 -322
  34. package/src/audit/checks/asset-minification.ts +0 -270
  35. package/src/audit/checks/bing-optimization.ts +0 -206
  36. package/src/audit/checks/brand-mention-optimization.ts +0 -349
  37. package/src/audit/checks/caching-headers.ts +0 -305
  38. package/src/audit/checks/canonical-advanced.ts +0 -150
  39. package/src/audit/checks/canonical-domain.ts +0 -196
  40. package/src/audit/checks/citation-quality.ts +0 -358
  41. package/src/audit/checks/client-rendering.ts +0 -542
  42. package/src/audit/checks/color-contrast.ts +0 -342
  43. package/src/audit/checks/content-freshness.ts +0 -170
  44. package/src/audit/checks/content-science.ts +0 -589
  45. package/src/audit/checks/conversion-elements.ts +0 -526
  46. package/src/audit/checks/crawlability.ts +0 -220
  47. package/src/audit/checks/directory-listing.ts +0 -172
  48. package/src/audit/checks/dom-analysis.ts +0 -191
  49. package/src/audit/checks/dom-size.ts +0 -246
  50. package/src/audit/checks/duplicate-content.ts +0 -194
  51. package/src/audit/checks/eeat-signals.ts +0 -990
  52. package/src/audit/checks/entity-seo.ts +0 -396
  53. package/src/audit/checks/featured-snippet.ts +0 -473
  54. package/src/audit/checks/freshness-signals.ts +0 -443
  55. package/src/audit/checks/funnel-intent.ts +0 -463
  56. package/src/audit/checks/hreflang.ts +0 -174
  57. package/src/audit/checks/html-compliance.ts +0 -302
  58. package/src/audit/checks/image-dimensions.ts +0 -167
  59. package/src/audit/checks/images.ts +0 -160
  60. package/src/audit/checks/indexnow.ts +0 -275
  61. package/src/audit/checks/interactive-tools.ts +0 -475
  62. package/src/audit/checks/internal-link-graph.ts +0 -436
  63. package/src/audit/checks/keyword-analysis.ts +0 -239
  64. package/src/audit/checks/keyword-cannibalization.ts +0 -385
  65. package/src/audit/checks/keyword-placement.ts +0 -471
  66. package/src/audit/checks/links.ts +0 -273
  67. package/src/audit/checks/llms-txt.ts +0 -224
  68. package/src/audit/checks/local-seo.ts +0 -296
  69. package/src/audit/checks/mobile.ts +0 -167
  70. package/src/audit/checks/modern-images.ts +0 -226
  71. package/src/audit/checks/navboost-signals.ts +0 -395
  72. package/src/audit/checks/on-page.ts +0 -209
  73. package/src/audit/checks/page-resources.ts +0 -285
  74. package/src/audit/checks/pagination.ts +0 -180
  75. package/src/audit/checks/performance.ts +0 -153
  76. package/src/audit/checks/platform-presence.ts +0 -580
  77. package/src/audit/checks/rag-chunk-readiness.test.ts +0 -159
  78. package/src/audit/checks/rag-chunk-readiness.ts +0 -163
  79. package/src/audit/checks/redirect-analysis.ts +0 -153
  80. package/src/audit/checks/redirect-chain.ts +0 -389
  81. package/src/audit/checks/resource-hints.ts +0 -420
  82. package/src/audit/checks/responsive-css.ts +0 -247
  83. package/src/audit/checks/responsive-images.ts +0 -396
  84. package/src/audit/checks/review-ecosystem.ts +0 -415
  85. package/src/audit/checks/robots-validation.ts +0 -373
  86. package/src/audit/checks/security-headers.ts +0 -188
  87. package/src/audit/checks/security.ts +0 -144
  88. package/src/audit/checks/serp-preview.ts +0 -251
  89. package/src/audit/checks/site-maturity.ts +0 -453
  90. package/src/audit/checks/social-meta.test.ts +0 -275
  91. package/src/audit/checks/social-meta.ts +0 -134
  92. package/src/audit/checks/soft-404.ts +0 -151
  93. package/src/audit/checks/structured-data.ts +0 -238
  94. package/src/audit/checks/tech-detection.ts +0 -496
  95. package/src/audit/checks/topical-clusters.ts +0 -435
  96. package/src/audit/checks/tracker-bloat.ts +0 -462
  97. package/src/audit/checks/tracking-verification.test.ts +0 -371
  98. package/src/audit/checks/tracking-verification.ts +0 -636
  99. package/src/audit/checks/url-safety.ts +0 -682
  100. package/src/audit/deno-entry.ts +0 -66
  101. package/src/audit/discovery/index.ts +0 -15
  102. package/src/audit/discovery/link-crawler.ts +0 -233
  103. package/src/audit/discovery/repo-routes.ts +0 -347
  104. package/src/audit/engine.ts +0 -633
  105. package/src/audit/fixes/index.ts +0 -209
  106. package/src/audit/fixes/social-meta-fixes.test.ts +0 -329
  107. package/src/audit/fixes/social-meta-fixes.ts +0 -463
  108. package/src/audit/index.ts +0 -74
  109. package/src/audit/runner.test.ts +0 -299
  110. package/src/audit/runner.ts +0 -130
  111. package/src/audit/types.ts +0 -1987
  112. package/src/content/featured-snippet.ts +0 -367
  113. package/src/content/generator.test.ts +0 -534
  114. package/src/content/generator.ts +0 -501
  115. package/src/content/headline.ts +0 -317
  116. package/src/content/index.ts +0 -62
  117. package/src/content/intent.ts +0 -258
  118. package/src/content/keyword-density.ts +0 -349
  119. package/src/content/readability.ts +0 -262
  120. package/src/executor.ts +0 -336
  121. package/src/fixer/framework-fixes.test.ts +0 -489
  122. package/src/fixer/framework-fixes.ts +0 -5287
  123. package/src/fixer/index.ts +0 -6
  124. package/src/fixer/schemas.ts +0 -971
  125. package/src/fixer.ts +0 -642
  126. package/src/frameworks/detector.test.ts +0 -248
  127. package/src/frameworks/detector.ts +0 -899
  128. package/src/frameworks/index.ts +0 -68
  129. package/src/frameworks/recipes/angular.yaml +0 -171
  130. package/src/frameworks/recipes/astro.yaml +0 -206
  131. package/src/frameworks/recipes/django.yaml +0 -180
  132. package/src/frameworks/recipes/laravel.yaml +0 -137
  133. package/src/frameworks/recipes/nextjs.yaml +0 -268
  134. package/src/frameworks/recipes/nuxt.yaml +0 -175
  135. package/src/frameworks/recipes/rails.yaml +0 -188
  136. package/src/frameworks/recipes/react.yaml +0 -202
  137. package/src/frameworks/recipes/sveltekit.yaml +0 -154
  138. package/src/frameworks/recipes/vue.yaml +0 -137
  139. package/src/frameworks/recipes/wordpress.yaml +0 -209
  140. package/src/frameworks/suggestion-engine.ts +0 -357
  141. package/src/geo/geo-content.test.ts +0 -305
  142. package/src/geo/geo-content.ts +0 -266
  143. package/src/geo/geo-history.test.ts +0 -473
  144. package/src/geo/geo-history.ts +0 -433
  145. package/src/geo/geo-tracker.test.ts +0 -359
  146. package/src/geo/geo-tracker.ts +0 -411
  147. package/src/geo/index.ts +0 -11
  148. package/src/geo/llm-citation-checker.ts +0 -188
  149. package/src/git/commit-helper.test.ts +0 -261
  150. package/src/git/commit-helper.ts +0 -329
  151. package/src/git/index.ts +0 -12
  152. package/src/git/pr-helper.test.ts +0 -284
  153. package/src/git/pr-helper.ts +0 -307
  154. package/src/index.ts +0 -76
  155. package/src/keywords/ai-keyword-engine.ts +0 -1062
  156. package/src/keywords/ai-summarizer.ts +0 -387
  157. package/src/keywords/ci-mode.ts +0 -555
  158. package/src/keywords/engine.ts +0 -359
  159. package/src/keywords/index.ts +0 -151
  160. package/src/keywords/llm-judge.ts +0 -357
  161. package/src/keywords/nlp-analysis.ts +0 -706
  162. package/src/keywords/prioritizer.ts +0 -295
  163. package/src/keywords/site-crawler.ts +0 -342
  164. package/src/keywords/sources/autocomplete.ts +0 -139
  165. package/src/keywords/sources/competitive-search.ts +0 -450
  166. package/src/keywords/sources/competitor-analysis.ts +0 -374
  167. package/src/keywords/sources/dataforseo.ts +0 -206
  168. package/src/keywords/sources/free-sources.ts +0 -294
  169. package/src/keywords/sources/gsc.ts +0 -123
  170. package/src/keywords/topic-grouping.ts +0 -327
  171. package/src/keywords/types.ts +0 -144
  172. package/src/keywords/wizard.ts +0 -457
  173. package/src/loader.ts +0 -40
  174. package/src/ranking/index.ts +0 -5
  175. package/src/ranking/serp-client.ts +0 -348
  176. package/src/ranking/tracker.ts +0 -380
  177. package/src/ranking/types.ts +0 -123
  178. package/src/reports/index.ts +0 -7
  179. package/src/reports/report-generator.test.ts +0 -293
  180. package/src/reports/report-generator.ts +0 -713
  181. package/src/scheduler/alerts.test.ts +0 -458
  182. package/src/scheduler/alerts.ts +0 -328
  183. package/src/scheduler/index.ts +0 -8
  184. package/src/scheduler/scheduled-audit.test.ts +0 -377
  185. package/src/scheduler/scheduled-audit.ts +0 -149
  186. package/src/test/integration-test.ts +0 -325
  187. package/src/tools/analyzer.ts +0 -373
  188. package/src/tools/crawl.ts +0 -293
  189. package/src/tools/files.ts +0 -301
  190. package/src/tools/h1-fixer.ts +0 -249
  191. package/src/tools/index.ts +0 -67
  192. package/src/tracking/github-action.ts +0 -326
  193. package/src/tracking/google-analytics.ts +0 -265
  194. package/src/tracking/index.ts +0 -45
  195. package/src/tracking/report-generator.ts +0 -386
  196. package/src/tracking/search-console.ts +0 -335
  197. package/src/types.ts +0 -148
  198. package/src/utils/http.ts +0 -302
  199. package/src/wasm-adapter.ts +0 -297
  200. package/src/wasm-entry.ts +0 -14
  201. package/tsconfig.json +0 -17
  202. package/tsup.wasm.config.ts +0 -26
  203. package/vitest.config.ts +0 -15
@@ -1,347 +0,0 @@
1
- // AI-Powered SEO Analyzer
2
- // Uses LLMs to provide contextual, intelligent SEO analysis
3
-
4
- import type {
5
- AIConfig,
6
- AIContentAnalysis,
7
- AIMetaAnalysis,
8
- AISchemaAnalysis,
9
- AIVisibilityAnalysis,
10
- AIFixPrioritization,
11
- AIAnalysisResult,
12
- PageContext,
13
- } from './types.js';
14
-
15
- import {
16
- CONTENT_ANALYSIS_SYSTEM,
17
- CONTENT_ANALYSIS_USER,
18
- META_ANALYSIS_SYSTEM,
19
- META_ANALYSIS_USER,
20
- SCHEMA_ANALYSIS_SYSTEM,
21
- SCHEMA_ANALYSIS_USER,
22
- AI_VISIBILITY_SYSTEM,
23
- AI_VISIBILITY_USER,
24
- FIX_PRIORITIZATION_SYSTEM,
25
- FIX_PRIORITIZATION_USER,
26
- } from './prompts/content-analysis.js';
27
-
28
- export class AIAnalyzer {
29
- private config: AIConfig;
30
- private cache: Map<string, { result: unknown; timestamp: number }> = new Map();
31
- private cacheTimeout = 3600000; // 1 hour
32
-
33
- constructor(config: AIConfig) {
34
- this.config = {
35
- model: 'gpt-4o',
36
- maxTokens: 4096,
37
- temperature: 0.3,
38
- ...config,
39
- };
40
- }
41
-
42
- /**
43
- * Call OpenAI API with structured JSON response
44
- */
45
- private async callOpenAI<T>(
46
- systemPrompt: string,
47
- userPrompt: string,
48
- cacheKey?: string
49
- ): Promise<{ result: T; tokensUsed: number; cached: boolean }> {
50
- // Check cache
51
- if (cacheKey) {
52
- const cached = this.cache.get(cacheKey);
53
- if (cached && Date.now() - cached.timestamp < this.cacheTimeout) {
54
- return { result: cached.result as T, tokensUsed: 0, cached: true };
55
- }
56
- }
57
-
58
- const response = await fetch('https://api.openai.com/v1/chat/completions', {
59
- method: 'POST',
60
- headers: {
61
- 'Content-Type': 'application/json',
62
- Authorization: `Bearer ${this.config.openaiApiKey}`,
63
- },
64
- body: JSON.stringify({
65
- model: this.config.model,
66
- messages: [
67
- { role: 'system', content: systemPrompt },
68
- { role: 'user', content: userPrompt },
69
- ],
70
- max_tokens: this.config.maxTokens,
71
- temperature: this.config.temperature,
72
- response_format: { type: 'json_object' },
73
- }),
74
- });
75
-
76
- if (!response.ok) {
77
- const error = await response.text();
78
- throw new Error(`OpenAI API error: ${response.status} - ${error}`);
79
- }
80
-
81
- const data = await response.json();
82
- const content = data.choices?.[0]?.message?.content;
83
- const tokensUsed = data.usage?.total_tokens || 0;
84
-
85
- if (!content) {
86
- throw new Error('No content in OpenAI response');
87
- }
88
-
89
- let result: T;
90
- try {
91
- result = JSON.parse(content) as T;
92
- } catch {
93
- throw new Error(`Failed to parse OpenAI JSON response: ${content}`);
94
- }
95
-
96
- // Cache result
97
- if (cacheKey) {
98
- this.cache.set(cacheKey, { result, timestamp: Date.now() });
99
- }
100
-
101
- return { result, tokensUsed, cached: false };
102
- }
103
-
104
- /**
105
- * Analyze content quality using AI
106
- */
107
- async analyzeContent(context: PageContext): Promise<{
108
- analysis: AIContentAnalysis;
109
- tokensUsed: number;
110
- cached: boolean;
111
- }> {
112
- const cacheKey = `content:${context.url}:${context.textContent.length}`;
113
-
114
- const { result, tokensUsed, cached } = await this.callOpenAI<AIContentAnalysis>(
115
- CONTENT_ANALYSIS_SYSTEM,
116
- CONTENT_ANALYSIS_USER({
117
- url: context.url,
118
- title: context.title,
119
- h1: context.h1,
120
- metaDescription: context.metaDescription,
121
- textContent: context.textContent,
122
- wordCount: context.wordCount,
123
- headings: context.headings,
124
- }),
125
- cacheKey
126
- );
127
-
128
- return { analysis: result, tokensUsed, cached };
129
- }
130
-
131
- /**
132
- * Analyze and optimize meta tags using AI
133
- */
134
- async analyzeMeta(context: PageContext): Promise<{
135
- analysis: AIMetaAnalysis;
136
- tokensUsed: number;
137
- cached: boolean;
138
- }> {
139
- const cacheKey = `meta:${context.url}:${context.title}:${context.metaDescription}`;
140
-
141
- const { result, tokensUsed, cached } = await this.callOpenAI<AIMetaAnalysis>(
142
- META_ANALYSIS_SYSTEM,
143
- META_ANALYSIS_USER({
144
- url: context.url,
145
- title: context.title,
146
- metaDescription: context.metaDescription,
147
- h1: context.h1,
148
- pageType: context.industry,
149
- industry: context.industry,
150
- }),
151
- cacheKey
152
- );
153
-
154
- return { analysis: result, tokensUsed, cached };
155
- }
156
-
157
- /**
158
- * Analyze and generate structured data using AI
159
- */
160
- async analyzeSchema(context: PageContext): Promise<{
161
- analysis: AISchemaAnalysis;
162
- tokensUsed: number;
163
- cached: boolean;
164
- }> {
165
- const cacheKey = `schema:${context.url}`;
166
-
167
- // Detect page type from URL and content
168
- let pageType = 'other';
169
- const urlLower = context.url.toLowerCase();
170
- const contentLower = context.textContent.toLowerCase();
171
-
172
- if (urlLower.includes('/blog/') || urlLower.includes('/article/') || urlLower.includes('/post/')) {
173
- pageType = 'article';
174
- } else if (urlLower.includes('/product/') || contentLower.includes('add to cart') || contentLower.includes('buy now')) {
175
- pageType = 'product';
176
- } else if (urlLower.includes('/faq') || contentLower.includes('frequently asked')) {
177
- pageType = 'faq';
178
- } else if (urlLower.includes('/about') || urlLower.includes('/team')) {
179
- pageType = 'organization';
180
- } else if (urlLower.includes('/contact')) {
181
- pageType = 'local-business';
182
- }
183
-
184
- const { result, tokensUsed, cached } = await this.callOpenAI<AISchemaAnalysis>(
185
- SCHEMA_ANALYSIS_SYSTEM,
186
- SCHEMA_ANALYSIS_USER({
187
- url: context.url,
188
- title: context.title,
189
- textContent: context.textContent,
190
- existingSchema: context.schema,
191
- pageType,
192
- }),
193
- cacheKey
194
- );
195
-
196
- return { analysis: result, tokensUsed, cached };
197
- }
198
-
199
- /**
200
- * Analyze AI/LLM visibility and optimization
201
- */
202
- async analyzeAIVisibility(
203
- context: PageContext,
204
- botAccess: { hasLlmsTxt: boolean; llmsTxtContent?: string; blockedBots: string[] }
205
- ): Promise<{
206
- analysis: AIVisibilityAnalysis;
207
- tokensUsed: number;
208
- cached: boolean;
209
- }> {
210
- const cacheKey = `aivis:${context.url}`;
211
-
212
- const { result, tokensUsed, cached } = await this.callOpenAI<AIVisibilityAnalysis>(
213
- AI_VISIBILITY_SYSTEM,
214
- AI_VISIBILITY_USER({
215
- url: context.url,
216
- title: context.title,
217
- textContent: context.textContent,
218
- headings: context.headings,
219
- hasLlmsTxt: botAccess.hasLlmsTxt,
220
- llmsTxtContent: botAccess.llmsTxtContent,
221
- blockedBots: botAccess.blockedBots,
222
- }),
223
- cacheKey
224
- );
225
-
226
- return { analysis: result, tokensUsed, cached };
227
- }
228
-
229
- /**
230
- * Prioritize fixes using AI
231
- */
232
- async prioritizeFixes(
233
- issues: { code: string; severity: string; title: string; category: string }[],
234
- context: { url: string; framework?: string }
235
- ): Promise<{
236
- analysis: AIFixPrioritization;
237
- tokensUsed: number;
238
- cached: boolean;
239
- }> {
240
- // Don't cache fix prioritization - issues change each audit
241
- const { result, tokensUsed, cached } = await this.callOpenAI<AIFixPrioritization>(
242
- FIX_PRIORITIZATION_SYSTEM,
243
- FIX_PRIORITIZATION_USER({
244
- issues,
245
- url: context.url,
246
- framework: context.framework,
247
- })
248
- );
249
-
250
- return { analysis: result, tokensUsed, cached };
251
- }
252
-
253
- /**
254
- * Run full AI analysis on a page
255
- */
256
- async runFullAnalysis(
257
- context: PageContext,
258
- options: {
259
- analyzeContent?: boolean;
260
- analyzeMeta?: boolean;
261
- analyzeSchema?: boolean;
262
- analyzeAIVisibility?: boolean;
263
- prioritizeFixes?: boolean;
264
- issues?: { code: string; severity: string; title: string; category: string }[];
265
- botAccess?: { hasLlmsTxt: boolean; llmsTxtContent?: string; blockedBots: string[] };
266
- } = {}
267
- ): Promise<AIAnalysisResult> {
268
- const startTime = Date.now();
269
- let totalTokens = 0;
270
- let anyCached = false;
271
-
272
- const result: AIAnalysisResult = {
273
- analysisTime: 0,
274
- tokensUsed: 0,
275
- modelUsed: this.config.model || 'gpt-4o',
276
- cached: false,
277
- };
278
-
279
- // Run analyses in parallel where possible
280
- const analyses = await Promise.allSettled([
281
- options.analyzeContent !== false
282
- ? this.analyzeContent(context)
283
- : Promise.resolve(null),
284
- options.analyzeMeta !== false
285
- ? this.analyzeMeta(context)
286
- : Promise.resolve(null),
287
- options.analyzeSchema !== false
288
- ? this.analyzeSchema(context)
289
- : Promise.resolve(null),
290
- options.analyzeAIVisibility !== false && options.botAccess
291
- ? this.analyzeAIVisibility(context, options.botAccess)
292
- : Promise.resolve(null),
293
- options.prioritizeFixes && options.issues
294
- ? this.prioritizeFixes(options.issues, { url: context.url, framework: context.framework })
295
- : Promise.resolve(null),
296
- ]);
297
-
298
- // Process results
299
- if (analyses[0].status === 'fulfilled' && analyses[0].value) {
300
- result.content = analyses[0].value.analysis;
301
- totalTokens += analyses[0].value.tokensUsed;
302
- if (analyses[0].value.cached) anyCached = true;
303
- }
304
-
305
- if (analyses[1].status === 'fulfilled' && analyses[1].value) {
306
- result.meta = analyses[1].value.analysis;
307
- totalTokens += analyses[1].value.tokensUsed;
308
- if (analyses[1].value.cached) anyCached = true;
309
- }
310
-
311
- if (analyses[2].status === 'fulfilled' && analyses[2].value) {
312
- result.schema = analyses[2].value.analysis;
313
- totalTokens += analyses[2].value.tokensUsed;
314
- if (analyses[2].value.cached) anyCached = true;
315
- }
316
-
317
- if (analyses[3].status === 'fulfilled' && analyses[3].value) {
318
- result.aiVisibility = analyses[3].value.analysis;
319
- totalTokens += analyses[3].value.tokensUsed;
320
- if (analyses[3].value.cached) anyCached = true;
321
- }
322
-
323
- if (analyses[4].status === 'fulfilled' && analyses[4].value) {
324
- result.fixPrioritization = analyses[4].value.analysis;
325
- totalTokens += analyses[4].value.tokensUsed;
326
- if (analyses[4].value.cached) anyCached = true;
327
- }
328
-
329
- result.analysisTime = Date.now() - startTime;
330
- result.tokensUsed = totalTokens;
331
- result.cached = anyCached;
332
-
333
- return result;
334
- }
335
-
336
- /**
337
- * Clear the cache
338
- */
339
- clearCache(): void {
340
- this.cache.clear();
341
- }
342
- }
343
-
344
- // Export a factory function for creating analyzers
345
- export function createAIAnalyzer(config: AIConfig): AIAnalyzer {
346
- return new AIAnalyzer(config);
347
- }
@@ -1,29 +0,0 @@
1
- // AI-Powered SEO Analysis Module
2
- // Exports for use in audits and Edge Functions
3
-
4
- export { AIAnalyzer, createAIAnalyzer } from './analyzer.js';
5
-
6
- export type {
7
- AIConfig,
8
- AIContentAnalysis,
9
- AIMetaAnalysis,
10
- AISchemaAnalysis,
11
- AILinkAnalysis,
12
- AIVisibilityAnalysis,
13
- AIFixPrioritization,
14
- AIAnalysisResult,
15
- PageContext,
16
- } from './types.js';
17
-
18
- export {
19
- CONTENT_ANALYSIS_SYSTEM,
20
- CONTENT_ANALYSIS_USER,
21
- META_ANALYSIS_SYSTEM,
22
- META_ANALYSIS_USER,
23
- SCHEMA_ANALYSIS_SYSTEM,
24
- SCHEMA_ANALYSIS_USER,
25
- AI_VISIBILITY_SYSTEM,
26
- AI_VISIBILITY_USER,
27
- FIX_PRIORITIZATION_SYSTEM,
28
- FIX_PRIORITIZATION_USER,
29
- } from './prompts/content-analysis.js';
@@ -1,271 +0,0 @@
1
- // AI Content Analysis Prompts
2
-
3
- export const CONTENT_ANALYSIS_SYSTEM = `You are an expert SEO analyst with deep knowledge of search engine algorithms, content quality signals, and Google's E-E-A-T (Experience, Expertise, Authoritativeness, Trustworthiness) guidelines.
4
-
5
- Your task is to analyze webpage content and provide actionable SEO insights. Be specific, practical, and data-driven in your analysis.
6
-
7
- Always respond with valid JSON matching the specified schema.`;
8
-
9
- export const CONTENT_ANALYSIS_USER = (context: {
10
- url: string;
11
- title?: string;
12
- h1?: string;
13
- metaDescription?: string;
14
- textContent: string;
15
- wordCount: number;
16
- headings?: { level: number; text: string }[];
17
- }) => `Analyze this webpage content for SEO quality:
18
-
19
- <webpage>
20
- URL: ${context.url}
21
- Title: ${context.title || 'Not found'}
22
- H1: ${context.h1 || 'Not found'}
23
- Meta Description: ${context.metaDescription || 'Not found'}
24
- Word Count: ${context.wordCount}
25
- Headings: ${JSON.stringify(context.headings || [])}
26
-
27
- Content (first 5000 chars):
28
- ${context.textContent.substring(0, 5000)}
29
- </webpage>
30
-
31
- Analyze this content and return JSON with this exact structure:
32
- {
33
- "overallScore": <0-100 integer>,
34
- "searchIntentMatch": <0-100 integer - how well content satisfies likely search intent>,
35
- "contentDepth": "<shallow|moderate|comprehensive>",
36
- "keywordNaturalness": <0-100 integer - 100 = perfectly natural, 0 = keyword stuffed>,
37
- "eeatSignals": {
38
- "experience": [<strings describing first-hand experience indicators found>],
39
- "expertise": [<strings describing expertise signals like credentials, depth of knowledge>],
40
- "authority": [<strings describing authority signals like citations, references>],
41
- "trust": [<strings describing trust signals like contact info, transparency>]
42
- },
43
- "improvements": [
44
- {
45
- "priority": <1-5 integer, 1 = highest>,
46
- "suggestion": "<specific actionable improvement>",
47
- "impact": "<expected SEO impact of this change>"
48
- }
49
- ],
50
- "uniqueValue": "<one sentence describing what unique value this page provides>",
51
- "missingTopics": [<topics that comprehensive coverage should include>],
52
- "targetKeyword": "<the primary keyword this page appears to target>",
53
- "keywordDensity": <percentage as decimal, e.g., 2.5>
54
- }
55
-
56
- Be critical but constructive. Focus on high-impact improvements.`;
57
-
58
- export const META_ANALYSIS_SYSTEM = `You are an expert SEO copywriter specializing in meta tags that drive clicks from search results.
59
-
60
- You understand:
61
- - Google's SERP display rules (title ~60 chars, description ~155 chars)
62
- - Click psychology and emotional triggers
63
- - Keyword optimization without stuffing
64
- - Brand positioning in titles
65
-
66
- Always respond with valid JSON matching the specified schema.`;
67
-
68
- export const META_ANALYSIS_USER = (context: {
69
- url: string;
70
- title?: string;
71
- metaDescription?: string;
72
- h1?: string;
73
- pageType?: string;
74
- industry?: string;
75
- }) => `Analyze these meta tags and suggest improvements:
76
-
77
- <page>
78
- URL: ${context.url}
79
- Current Title: ${context.title || 'Missing'}
80
- Current Description: ${context.metaDescription || 'Missing'}
81
- H1: ${context.h1 || 'Not found'}
82
- Page Type: ${context.pageType || 'Unknown'}
83
- Industry: ${context.industry || 'General'}
84
- </page>
85
-
86
- Return JSON with this exact structure:
87
- {
88
- "titleAnalysis": {
89
- "effectiveness": <0-100 integer>,
90
- "clickPotential": <0-100 integer>,
91
- "keywordPlacement": "<optimal|suboptimal|missing>",
92
- "emotionalTriggers": [<power words or emotional triggers found>],
93
- "suggestions": [<3-5 alternative title suggestions that would perform better>]
94
- },
95
- "descriptionAnalysis": {
96
- "effectiveness": <0-100 integer>,
97
- "hasCallToAction": <boolean>,
98
- "hasUniqueSellingProposition": <boolean>,
99
- "keywordNaturalness": <0-100 integer>,
100
- "suggestions": [<3-5 alternative description suggestions>]
101
- },
102
- "serpPrediction": {
103
- "predictedCTR": <predicted click-through rate as percentage, e.g., 3.5>,
104
- "competitiveStrength": "<weak|average|strong>",
105
- "improvements": [<specific changes that would improve CTR>]
106
- }
107
- }
108
-
109
- Make suggestions compelling, keyword-optimized, and within character limits.`;
110
-
111
- export const SCHEMA_ANALYSIS_SYSTEM = `You are an expert in structured data and Schema.org markup for SEO.
112
-
113
- You understand:
114
- - All Schema.org types and their properties
115
- - Google's rich result requirements
116
- - JSON-LD best practices
117
- - How to maximize rich snippet eligibility
118
-
119
- Always respond with valid JSON matching the specified schema.`;
120
-
121
- export const SCHEMA_ANALYSIS_USER = (context: {
122
- url: string;
123
- title?: string;
124
- textContent: string;
125
- existingSchema?: object[];
126
- pageType?: string;
127
- }) => `Analyze this page and recommend structured data:
128
-
129
- <page>
130
- URL: ${context.url}
131
- Title: ${context.title || 'Unknown'}
132
- Detected Page Type: ${context.pageType || 'Unknown'}
133
- Existing Schema: ${JSON.stringify(context.existingSchema || [], null, 2)}
134
-
135
- Content Summary (first 2000 chars):
136
- ${context.textContent.substring(0, 2000)}
137
- </page>
138
-
139
- Return JSON with this exact structure:
140
- {
141
- "detectedPageType": "<article|product|service|faq|how-to|local-business|organization|person|event|recipe|other>",
142
- "recommendedSchemas": [
143
- {
144
- "type": "<Schema.org type name>",
145
- "priority": "<critical|high|medium|low>",
146
- "reason": "<why this schema is recommended>"
147
- }
148
- ],
149
- "generatedSchemas": [
150
- {
151
- "type": "<Schema.org type>",
152
- "jsonLd": <complete valid JSON-LD object>,
153
- "explanation": "<what this schema does and why>"
154
- }
155
- ],
156
- "richSnippetPotential": [
157
- {
158
- "type": "<rich result type: FAQ, How-to, Review, Product, etc.>",
159
- "eligible": <boolean>,
160
- "requirements": [<what's needed to qualify>]
161
- }
162
- ]
163
- }
164
-
165
- Generate complete, valid JSON-LD that can be directly used.`;
166
-
167
- export const AI_VISIBILITY_SYSTEM = `You are an expert in how AI systems (LLMs like ChatGPT, Claude, Perplexity) crawl, understand, and cite web content.
168
-
169
- You understand:
170
- - How LLMs parse and understand content structure
171
- - The llms.txt standard for AI guidance
172
- - When to allow/block AI crawlers
173
- - How to optimize for AI citation
174
-
175
- Always respond with valid JSON matching the specified schema.`;
176
-
177
- export const AI_VISIBILITY_USER = (context: {
178
- url: string;
179
- title?: string;
180
- textContent: string;
181
- headings?: { level: number; text: string }[];
182
- hasLlmsTxt: boolean;
183
- llmsTxtContent?: string;
184
- blockedBots: string[];
185
- }) => `Analyze this page's AI/LLM visibility:
186
-
187
- <page>
188
- URL: ${context.url}
189
- Title: ${context.title || 'Unknown'}
190
- Has llms.txt: ${context.hasLlmsTxt}
191
- llms.txt content: ${context.llmsTxtContent || 'N/A'}
192
- Blocked AI Bots: ${context.blockedBots.join(', ') || 'None'}
193
-
194
- Heading Structure:
195
- ${(context.headings || []).map(h => ' '.repeat(h.level - 1) + h.text).join('\n')}
196
-
197
- Content (first 3000 chars):
198
- ${context.textContent.substring(0, 3000)}
199
- </page>
200
-
201
- Return JSON with this exact structure:
202
- {
203
- "llmReadability": {
204
- "score": <0-100 integer>,
205
- "structureClarity": <0-100 integer - how clear is the content structure>,
206
- "contextClarity": <0-100 integer - how clear is the page's purpose/topic>,
207
- "citationPotential": <0-100 integer - likelihood of being cited by AI>,
208
- "improvements": [<specific improvements for AI readability>]
209
- },
210
- "botAccessRecommendation": {
211
- "shouldAllowGPTBot": <boolean>,
212
- "shouldAllowClaudeBot": <boolean>,
213
- "shouldAllowPerplexityBot": <boolean>,
214
- "shouldAllowGoogleExtended": <boolean>,
215
- "rationale": "<explanation of bot access recommendation>"
216
- },
217
- "llmsTxtSuggestion": {
218
- "content": "<suggested llms.txt content>",
219
- "explanation": "<why this llms.txt is recommended>"
220
- }
221
- }
222
-
223
- Consider the site's likely goals when recommending bot access.`;
224
-
225
- export const FIX_PRIORITIZATION_SYSTEM = `You are an SEO strategist who excels at prioritizing fixes for maximum impact with minimum effort.
226
-
227
- You understand:
228
- - Which SEO issues have the biggest ranking impact
229
- - Implementation effort for different types of fixes
230
- - How to batch related fixes together
231
- - Quick wins vs long-term improvements
232
-
233
- Always respond with valid JSON matching the specified schema.`;
234
-
235
- export const FIX_PRIORITIZATION_USER = (context: {
236
- issues: { code: string; severity: string; title: string; category: string }[];
237
- url: string;
238
- framework?: string;
239
- }) => `Prioritize these SEO issues by impact and effort:
240
-
241
- <context>
242
- URL: ${context.url}
243
- Framework: ${context.framework || 'Unknown'}
244
- </context>
245
-
246
- <issues>
247
- ${context.issues.map(i => `- [${i.severity.toUpperCase()}] ${i.code}: ${i.title} (${i.category})`).join('\n')}
248
- </issues>
249
-
250
- Return JSON with this exact structure:
251
- {
252
- "prioritizedIssues": [
253
- {
254
- "issueCode": "<issue code>",
255
- "impactScore": <0-100 integer - SEO impact if fixed>,
256
- "effortScore": <0-100 integer - effort to fix, 100 = very hard>,
257
- "roiScore": <calculated as impact / effort, higher is better>,
258
- "rationale": "<why this priority>"
259
- }
260
- ],
261
- "fixBatches": [
262
- {
263
- "batch": <1, 2, 3, etc.>,
264
- "theme": "<batch theme like 'Meta Tags' or 'Technical SEO'>",
265
- "estimatedImpact": "<description of combined impact>",
266
- "issueCodes": [<issue codes in this batch>]
267
- }
268
- ]
269
- }
270
-
271
- Sort prioritizedIssues by roiScore descending. Group related fixes into batches.`;