@cloro-dev/response-parser 0.5.3 → 0.6.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.
- package/README.md +7 -3
- package/dist/core/detector.d.ts.map +1 -1
- package/dist/core/parser.d.ts.map +1 -1
- package/dist/core/types.d.ts +3 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +35 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/providers/bing-ai-mode.d.ts +29 -0
- package/dist/providers/bing-ai-mode.d.ts.map +1 -0
- package/dist/providers/copilot.d.ts +4 -0
- package/dist/providers/copilot.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/core/types.ts","../src/core/detector.ts","../src/providers/base-provider.ts","../src/providers/chatgpt.ts","../src/providers/gemini.ts","../src/providers/perplexity.ts","../src/providers/copilot.ts","../src/providers/ai-overview.ts","../src/providers/ai-mode.ts","../src/providers/grok.ts","../src/core/parser.ts"],"sourcesContent":["export type AIProvider =\n | 'CHATGPT'\n | 'GEMINI'\n | 'PERPLEXITY'\n | 'COPILOT'\n | 'AIOVERVIEW'\n | 'AIMODE'\n | 'GROK';\n\nexport interface ParsedResponse {\n provider: AIProvider;\n html: string;\n text?: string;\n sources?: any[];\n metadata?: Record<string, any>;\n}\n\nexport interface ParseOptions {\n removeLinks?: boolean;\n removeHeader?: boolean;\n removeFooter?: boolean;\n removeSidebar?: boolean;\n removeSources?: boolean;\n}\n\nexport interface ProviderConfig {\n name: AIProvider;\n baseUrl: string;\n}\n\nexport interface DetectedProvider {\n provider: AIProvider;\n confidence: number;\n}\n\nexport interface StyleOptions {\n customCSS?: string;\n hideUI?: boolean;\n baseUrl?: string;\n}\n\nexport type ContentExtraction = {\n html?: string;\n text?: string;\n sources?: any[];\n};\n\n/**\n * Standardized metadata for provider responses\n */\nexport interface ProviderMetadata {\n isFullDocument?: boolean;\n headerRemoved?: boolean;\n footerRemoved?: boolean;\n sidebarRemoved?: boolean;\n linksRemoved?: boolean;\n cookieBannerRemoved?: boolean;\n sourcesRemoved?: boolean;\n detectionConfidence?: number;\n}\n\n/**\n * Common content extraction utility - shared across providers and parser\n */\nexport function extractContentCommon(response: any): ContentExtraction {\n let html = '';\n let text = '';\n\n // Handle nested structure\n let dataToCheck = response;\n if (response.result) {\n dataToCheck = response.result;\n }\n\n // Extract content\n if (typeof dataToCheck === 'string') {\n if (dataToCheck.trim().startsWith('<') && dataToCheck.includes('>')) {\n html = dataToCheck;\n } else {\n text = dataToCheck;\n }\n } else if (typeof dataToCheck === 'object' && dataToCheck !== null) {\n if (dataToCheck.html) {\n html = dataToCheck.html;\n } else if (dataToCheck.content) {\n if (dataToCheck.content.trim().startsWith('<')) {\n html = dataToCheck.content;\n } else {\n text = dataToCheck.content;\n }\n } else if (dataToCheck.text) {\n text = dataToCheck.text;\n }\n }\n\n return { html, text };\n}","import { AIProvider, DetectedProvider } from './types';\n\nexport class ProviderDetector {\n private static readonly PROVIDER_PATTERNS = {\n CHATGPT: [\n // Check for token-based CSS classes\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('bg-token-bg-primary') || html.includes('text-token-text-secondary');\n },\n // Check for OpenAI-specific patterns\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('chatgpt.com') || html.includes('openai.com');\n },\n ],\n GEMINI: [\n // Check for Material Design components\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('bard-sidenav') || html.includes('mat-sidenav');\n },\n // Check for Gemini-specific markup. The domain name alone also occurs in\n // Google result pages that link to Gemini.\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('<chat-app') || html.includes('gem-sys-color');\n },\n ],\n PERPLEXITY: [\n // Check for Perplexity domain\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('perplexity.ai');\n },\n // Check for Perplexity-specific structure\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('prose') && !html.includes('grok.com') && !html.includes('chatgpt.com');\n },\n ],\n COPILOT: [\n // Check for Copilot-specific elements\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('copilot.microsoft.com') || html.includes('data-testid=\"sidebar-container\"');\n },\n ],\n AIOVERVIEW: [\n // Check for AI Overview specific structure\n (response: any) => {\n if (response?.result?.aioverview?.text) return true;\n if (response?.aioverview?.text) return true;\n return false;\n },\n // Check for a Google result page without AI Mode markers.\n // WIZ_global_data alone also occurs in Gemini pages.\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('id=\"gsr\"') && !html.includes('aim-mars') && !html.includes('ho072b');\n },\n ],\n AIMODE: [\n // Check for the AI Mode input and turn containers. The DZ13He header\n // class also occurs in every Google result page.\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('aim-mars');\n },\n // Check for the AI Mode history panel\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('ho072b');\n },\n ],\n GROK: [\n // Check for Grok domain\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('grok.com') || html.includes('x.ai');\n },\n // Check for Grok CDN or app-specific patterns\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('cdn.grok.com') || html.includes('vaul-drawer');\n },\n ],\n };\n\n /**\n * Detect the AI provider from the response\n */\n static detect(response: any): DetectedProvider | null {\n const scores: Record<AIProvider, number> = {\n CHATGPT: 0,\n GEMINI: 0,\n PERPLEXITY: 0,\n COPILOT: 0,\n AIOVERVIEW: 0,\n AIMODE: 0,\n GROK: 0,\n };\n\n // Score each provider based on pattern matches\n for (const [provider, patterns] of Object.entries(this.PROVIDER_PATTERNS)) {\n for (const pattern of patterns) {\n try {\n if (pattern(response)) {\n scores[provider as AIProvider]++;\n }\n } catch {\n // Ignore pattern errors\n }\n }\n }\n\n // Find the provider with the highest score\n let maxScore = 0;\n let detectedProvider: AIProvider | null = null;\n\n for (const [provider, score] of Object.entries(scores)) {\n if (score > maxScore) {\n maxScore = score;\n detectedProvider = provider as AIProvider;\n }\n }\n\n // Return null if no patterns matched\n if (maxScore === 0) return null;\n\n return {\n provider: detectedProvider!,\n confidence: maxScore / Object.values(scores).reduce((a, b) => Math.max(a, b), 1),\n };\n }\n\n /**\n * Get all possible providers with their confidence scores\n */\n static getAllProviders(response: any): DetectedProvider[] {\n const providers: DetectedProvider[] = [];\n\n for (const [provider, patterns] of Object.entries(this.PROVIDER_PATTERNS)) {\n let matches = 0;\n for (const pattern of patterns) {\n try {\n if (pattern(response)) {\n matches++;\n }\n } catch {\n // Ignore pattern errors\n }\n }\n\n if (matches > 0) {\n providers.push({\n provider: provider as AIProvider,\n confidence: matches / patterns.length,\n });\n }\n }\n\n // Sort by confidence (highest first)\n return providers.sort((a, b) => b.confidence - a.confidence);\n }\n\n /**\n * Validate if a detected provider is likely correct\n */\n static validate(response: any, provider: AIProvider): boolean {\n const detected = this.detect(response);\n return detected?.provider === provider && detected.confidence > 0.5;\n }\n}","import { AIProvider, ParsedResponse, ParseOptions, StyleOptions, ContentExtraction, extractContentCommon } from '../core/types';\n\nexport abstract class BaseProvider {\n abstract readonly name: AIProvider;\n abstract readonly baseUrl: string;\n\n /**\n * Parse an AI response and return structured content\n */\n abstract parse(response: any, options?: ParseOptions): ParsedResponse;\n\n /**\n * Extract content from the response object\n */\n abstract extractContent(response: any): ContentExtraction;\n\n /**\n * Common content extraction logic - can be used by providers\n */\n protected extractContentCommon(response: any, includeSources = false): ContentExtraction {\n const result = extractContentCommon(response);\n\n if (includeSources) {\n let sources: any[] = [];\n const dataToCheck = response.result || response;\n\n if (typeof dataToCheck === 'object' && dataToCheck !== null) {\n if (dataToCheck.aioverview?.sources) {\n sources = dataToCheck.aioverview.sources;\n } else if (dataToCheck.sources) {\n sources = dataToCheck.sources;\n }\n }\n\n return { ...result, sources };\n }\n\n return result;\n }\n\n /**\n * Inject provider-specific styles into HTML\n */\n injectStyles(html: string, options?: StyleOptions): string {\n let styledHtml = html;\n\n // Inject base URL if not already present\n if (options?.baseUrl && !html.includes('<base ')) {\n if (styledHtml.includes('<head>')) {\n styledHtml = styledHtml.replace(\n '<head>',\n `<head><base href=\"${options.baseUrl}\">`,\n );\n } else {\n styledHtml = styledHtml.replace(\n /(<html[^>]*>)/i,\n `$1<head><base href=\"${options.baseUrl}\"></head>`,\n );\n }\n }\n\n // Inject styles only if customCSS is provided\n const styles = options?.customCSS || '';\n\n if (styles && styledHtml.includes('<head>')) {\n styledHtml = styledHtml.replace('<head>', `<head><style>${styles}</style>`);\n } else if (styles) {\n styledHtml = styledHtml.replace(\n /(<html[^>]*>)/i,\n `$1<head><style>${styles}</style></head>`,\n );\n }\n\n return styledHtml;\n }\n\n /**\n * Sanitize HTML content\n */\n sanitizeHtml(html: string): string {\n // Remove scripts\n let sanitized = html.replace(/<script\\b[^>]*>[\\s\\S]*?<\\/script>/gim, '');\n\n // Remove noscript tags\n sanitized = sanitized.replace(/<noscript[\\s\\S]*?<\\/noscript>/gi, '');\n\n return sanitized;\n }\n\n /**\n * Check if content is a full HTML document\n */\n isFullDocument(html: string): boolean {\n return /^\\s*(<html|<!DOCTYPE)/i.test(html);\n }\n\n /**\n * Remove all links from HTML, keeping the text content\n */\n removeLinks(html: string): string {\n // Replace anchor tags with their text content\n return html.replace(/<a\\b[^>]*>([\\s\\S]*?)<\\/a>/gim, '$1');\n }\n\n /**\n * Wrap HTML fragment in a document\n */\n wrapFragment(html: string): string {\n return `<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"utf-8\">\n <meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'none'; script-src 'none'; style-src 'unsafe-inline';\">\n <style>\n body {\n margin: 0;\n padding: 16px;\n font-family: system-ui, -apple-system, sans-serif;\n white-space: pre-wrap;\n word-wrap: break-word;\n }\n img { max-width: 100%; height: auto; }\n body {\n pointer-events: none;\n user-select: none;\n }\n </style>\n</head>\n<body>\n ${html}\n</body>\n</html>`;\n }\n}","import { BaseProvider } from \"./base-provider\";\nimport {\n AIProvider,\n ParsedResponse,\n ParseOptions,\n ContentExtraction,\n ProviderMetadata,\n} from \"../core/types\";\n\nexport class ChatGPTProvider extends BaseProvider {\n readonly name: AIProvider = \"CHATGPT\";\n readonly baseUrl = \"https://chatgpt.com\";\n\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response);\n }\n\n /**\n * Remove links from HTML, preserving badge styling\n * Converts <a> tags to <span> while keeping class attributes\n */\n removeLinks(html: string): string {\n // Replace anchor tags with span tags, keeping all attributes except href/alt/rel/target\n return html\n .replace(/<a\\b([^>]*)>/gi, (match, attributes) => {\n // Remove link-specific attributes but keep others (class, style, etc.)\n const cleanedAttrs = attributes\n .replace(/\\s+href\\s*=\\s*[\"'][^\"']*[\"']/gi, \"\")\n .replace(/\\s+alt\\s*=\\s*[\"'][^\"']*[\"']/gi, \"\")\n .replace(/\\s+rel\\s*=\\s*[\"'][^\"']*[\"']/gi, \"\")\n .replace(/\\s+target\\s*=\\s*[\"'][^\"']*[\"']/gi, \"\")\n .trim();\n return `<span${cleanedAttrs ? \" \" + cleanedAttrs : \"\"}>`;\n })\n .replace(/<\\/a>/gi, \"</span>\");\n }\n\n /**\n * Remove ChatGPT header from HTML\n */\n removeHeader(html: string): string {\n let cleaned = html;\n\n // Remove page header by id\n cleaned = cleaned.replace(\n /<header[^>]*id=\"page-header\"[^>]*>.*?<\\/header>/gis,\n \"\"\n );\n\n return cleaned;\n }\n\n /**\n * Remove ChatGPT sidebar from HTML\n */\n removeSidebar(html: string): string {\n // The sidebar wrapper is hidden with CSS in parse(). Its nested <div>s\n // cannot be balanced with a regex.\n return html.replace(/<nav[^>]*>.*?<\\/nav>/gis, \"\");\n }\n\n /**\n * Remove ChatGPT footer/composer from HTML.\n * Handled with CSS in parse(). A regex cannot balance the nested <div>s of\n * the composer, and a partial removal changes the page structure.\n */\n removeFooter(html: string): string {\n return html;\n }\n\n /**\n * Remove ChatGPT cookie banner from HTML\n */\n removeCookieBanner(html: string): string {\n // Remove the cookie dialog banner (matched by cookie-policy URL, language-agnostic)\n return html.replace(/<div[^>]*role=\"dialog\"[^>]*>[\\s\\S]*?openai\\.com\\/policies\\/cookie-policy[\\s\\S]*?<\\/div><\\/div><\\/div><\\/div><\\/div><\\/div>/gi, '');\n }\n\n /**\n * Remove ChatGPT sources/search flyout panel from HTML.\n * Handled with CSS in parse().\n */\n removeSources(html: string): string {\n return html;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, text } = this.extractContent(response);\n\n if (!html) {\n throw new Error(\"No HTML content found in ChatGPT response\");\n }\n\n let finalHtml = html;\n\n const removeFooter = options?.removeFooter ?? false;\n\n // Sanitize HTML\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Always remove cookie banner\n finalHtml = this.removeCookieBanner(finalHtml);\n\n // Remove header if requested\n if (options?.removeHeader) {\n finalHtml = this.removeHeader(finalHtml);\n }\n\n // Remove sidebar if requested\n if (options?.removeSidebar) {\n finalHtml = this.removeSidebar(finalHtml);\n }\n\n // Remove footer if requested\n if (removeFooter) {\n finalHtml = this.removeFooter(finalHtml);\n }\n\n // Remove sources panel if requested\n if (options?.removeSources) {\n finalHtml = this.removeSources(finalHtml);\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n // Build CSS overrides conditionally based on which remove* options are active\n let customCSS = '';\n\n if (options?.removeSidebar) {\n customCSS += `\n #stage-slideover-sidebar { display: none !important; }\n [data-sidebar-item] { display: none !important; }\n [data-skip-to-content] { display: none !important; }\n .h-svh { height: auto !important; }\n `;\n }\n\n if (removeFooter) {\n customCSS += `\n #thread-bottom-container { display: none !important; }\n form[data-type=\"unified-composer\"] { display: none !important; }\n #thread { min-height: auto !important; }\n `;\n }\n\n if (options?.removeSources) {\n customCSS += `\n /* Side flyout, the modal sheet that replaces it on narrow pages, and\n the sources dialog of the mobile page */\n [data-testid=\"stage-thread-flyout\"],\n [data-sheet-travel-state],\n #assistant-sources-dialog {\n display: none !important;\n }\n `;\n }\n\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n text,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n cookieBannerRemoved: true,\n headerRemoved: options?.removeHeader || false,\n sidebarRemoved: options?.removeSidebar || false,\n footerRemoved: removeFooter,\n sourcesRemoved: options?.removeSources || false,\n linksRemoved: options?.removeLinks || false,\n } as ProviderMetadata,\n };\n }\n}\n","import { BaseProvider } from './base-provider';\nimport { AIProvider, ParsedResponse, ParseOptions, ContentExtraction, ProviderMetadata } from '../core/types';\n\nexport class GeminiProvider extends BaseProvider {\n readonly name: AIProvider = 'GEMINI';\n readonly baseUrl = 'https://gemini.google.com';\n\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response, true);\n }\n\n /**\n * Remove Gemini header/navbar from HTML\n */\n removeHeader(html: string): string {\n let cleaned = html;\n\n // Remove the Google navbar with boqOnegoogleliteOgbOneGoogleBar class\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*boqOnegoogleliteOgbOneGoogleBar[^\"]*\"[^>]*>.*?<\\/div><\\/div><\\/div><\\/div>/gis, '');\n\n // Remove top-bar-actions (About Gemini, Gemini App, Subscriptions, For Business links)\n cleaned = cleaned.replace(/<top-bar-actions[^>]*>.*?<\\/top-bar-actions>/gis, '');\n\n // Remove desktop-ogb-buffer\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*desktop-ogb-buffer[^\"]*\"[^>]*><\\/div>/gis, '');\n\n return cleaned;\n }\n\n /**\n * Remove Gemini footer/follow-up input box from HTML\n */\n removeFooter(html: string): string {\n // Remove input-container (text input, upload button, send button, disclaimer)\n return html.replace(/<input-container[^>]*>.*?<\\/input-container>/gis, '');\n }\n\n /**\n * Remove Gemini sidebar from HTML\n */\n removeSidebar(html: string): string {\n // Remove bard-sidenav element\n return html.replace(/<bard-sidenav[^>]*>.*?<\\/bard-sidenav>/gis, '');\n }\n\n /**\n * Remove Gemini sources panel from HTML\n */\n removeSources(html: string): string {\n let cleaned = html;\n\n // Remove the context-sidebar element (contains source cards)\n cleaned = cleaned.replace(/<context-sidebar[^>]*>[\\s\\S]*?<\\/context-sidebar>/gi, '');\n\n // Remove the sources-sidebar-button trigger\n cleaned = cleaned.replace(/<sources-sidebar-button[^>]*>[\\s\\S]*?<\\/sources-sidebar-button>/gi, '');\n\n return cleaned;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, text, sources } = this.extractContent(response);\n\n if (!html) {\n throw new Error('No HTML content found in Gemini response');\n }\n\n let finalHtml = html;\n\n const removeHeader = options?.removeHeader ?? false;\n const removeFooter = options?.removeFooter ?? false;\n\n // Sanitize HTML (remove scripts and noscript)\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Remove header if requested\n if (removeHeader) {\n finalHtml = this.removeHeader(finalHtml);\n }\n\n // Remove footer if requested\n if (removeFooter) {\n finalHtml = this.removeFooter(finalHtml);\n }\n\n // Remove sidebar if requested\n if (options?.removeSidebar) {\n finalHtml = this.removeSidebar(finalHtml);\n }\n\n // Remove sources panel if requested\n if (options?.removeSources) {\n finalHtml = this.removeSources(finalHtml);\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n // Always-on: hide the \"Sign in\" prompt above the input box\n let customCSS = `\n sign-in-nudge { display: none !important; }\n `;\n\n // The hamburger button has nested <div>s that a regex cannot balance\n if (removeHeader) {\n customCSS += `\n .side-nav-menu-button { display: none !important; }\n `;\n }\n\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n text,\n sources,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n headerRemoved: removeHeader,\n footerRemoved: removeFooter,\n sidebarRemoved: options?.removeSidebar || false,\n sourcesRemoved: options?.removeSources || false,\n linksRemoved: options?.removeLinks || false,\n } as ProviderMetadata,\n };\n }\n}","import { BaseProvider } from \"./base-provider\";\nimport {\n AIProvider,\n ParsedResponse,\n ParseOptions,\n ContentExtraction,\n ProviderMetadata,\n} from \"../core/types\";\n\nexport class PerplexityProvider extends BaseProvider {\n readonly name: AIProvider = \"PERPLEXITY\";\n readonly baseUrl = \"https://www.perplexity.ai\";\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response);\n }\n\n /**\n * Remove Perplexity header/navbar from HTML\n */\n removeHeader(html: string): string {\n // Remove navbar by targeting the unique @container/header class\n // Matches from the navbar opening div through the border divider at the bottom\n return html.replace(\n /<div[^>]*class=\"[^\"]*@container\\/header[^\"]*\"[^>]*>.*?<div[^>]*class=\"[^\"]*absolute bottom-0 inset-x-0 border-b[^\"]*\"[^>]*><\\/div>/gis,\n \"\"\n );\n }\n\n /**\n * Remove Perplexity footer/followup input from HTML.\n * Uses CSS hiding — the footer's deeply nested DOM makes regex counting\n * of closing </div> tags fragile across Perplexity versions.\n */\n removeFooter(_html: string): string {\n // Handled via CSS injection in parse() for reliability\n return _html;\n }\n\n /**\n * Remove Perplexity left sidebar navigation from HTML\n */\n removeSidebar(html: string): string {\n let cleaned = html;\n // Remove the sidebar nav element and its width-holder parent\n cleaned = cleaned.replace(\n /<div[^>]*class=\"[^\"]*w-sideBarWidth[^\"]*\"[^>]*>[\\s\\S]*?<\\/nav>[\\s\\S]*?<\\/div>/gi,\n \"\"\n );\n return cleaned;\n }\n\n /**\n * Remove Perplexity sources panel from HTML.\n *\n * Why: Perplexity's sources panel is the deeply-nested\n * `fixed inset-y-0 right-0` container that wraps a citations tabpanel.\n * We can't reliably balance its nested </div>s with regex, and a partial\n * strip orphans the panel's children visibly. CSS-only hiding (see\n * parse()) is the load-bearing approach — `display:none` on the wrapper\n * collapses every descendant. The same rule hides the open \"Sources\"\n * popover, which Perplexity renders in a Radix popper at the body root.\n */\n removeSources(html: string): string {\n return html;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, text } = this.extractContent(response);\n\n if (!html) {\n throw new Error(\"No HTML content found in Perplexity response\");\n }\n\n let finalHtml = html;\n\n const removeHeader = options?.removeHeader ?? false;\n const removeFooter = options?.removeFooter ?? false;\n\n // Sanitize HTML\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Fix collapsed answer container: Perplexity uses JS animation to expand the\n // answer area from height:48px. Without scripts, it stays collapsed.\n finalHtml = finalHtml.replace(\n /style=\"transition: none; overflow: hidden; height: 48px;\"/gi,\n ''\n );\n\n // Strip inline padding-right used for the sources sidecar panel\n // (e.g. padding-right: 500px) which squeezes content when sources are removed\n finalHtml = finalHtml.replace(\n /padding-right:\\s*\\d+px/gi,\n 'padding-right: 0px'\n );\n\n // Remove header if requested\n if (removeHeader) {\n finalHtml = this.removeHeader(finalHtml);\n }\n\n // Remove sidebar if requested\n if (options?.removeSidebar) {\n finalHtml = this.removeSidebar(finalHtml);\n }\n\n // Remove footer if requested\n if (removeFooter) {\n finalHtml = this.removeFooter(finalHtml);\n }\n\n // Remove sources panel if requested\n if (options?.removeSources) {\n finalHtml = this.removeSources(finalHtml);\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n // Build CSS overrides conditionally based on which remove* options are active\n let customCSS = `\n #cookie-consent,\n [role=\"dialog\"]:has(#cookie-consent),\n div[role=\"dialog\"][class*=\"fixed\"][class*=\"bottom-2\"] {\n display: none !important;\n }\n /* Login prompts: the full-page modal and the corner card. The #root\n prefix keeps the rule above the removeSidebar layout overrides. */\n [data-type=\"portal\"]:has([data-testid=\"login-modal\"]),\n #root div[class*=\"fixed\"]:has([data-testid=\"login-modal\"]),\n div[class*=\"fixed\"]:has([data-testid=\"login-modal\"]) {\n display: none !important;\n }\n [data-radix-focus-guard] {\n display: none !important;\n }\n `;\n\n if (options?.removeSidebar) {\n customCSS += `\n [class*=\"w-sideBarWidth\"] { display: none !important; }\n #root, #root > div, #root > div > div {\n display: block !important;\n height: auto !important;\n max-height: none !important;\n width: 100% !important;\n padding: 0 !important;\n }\n main {\n display: block !important;\n height: auto !important;\n max-height: none !important;\n overflow: visible !important;\n }\n main > div {\n height: auto !important;\n overflow: visible !important;\n }\n [class*=\"scrollable-container\"] {\n height: auto !important;\n overflow: visible !important;\n }\n [class*=\"max-w-threadContentWidth\"] {\n max-width: 100% !important;\n }\n `;\n }\n\n if (options?.removeSources) {\n customCSS += `\n div[class*=\"fixed\"][class*=\"inset-y-0\"][class*=\"right-0\"],\n [data-radix-popper-content-wrapper] {\n display: none !important;\n }\n `;\n }\n\n if (removeFooter) {\n customCSS += `\n [class*=\"bottom-safeAreaInsetBottom\"] {\n display: none !important;\n }\n `;\n }\n\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n text,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n linksRemoved: options?.removeLinks || false,\n headerRemoved: removeHeader,\n footerRemoved: removeFooter,\n sidebarRemoved: options?.removeSidebar || false,\n cookieBannerRemoved: true,\n sourcesRemoved: options?.removeSources || false,\n } as ProviderMetadata,\n };\n }\n}\n","import { BaseProvider } from './base-provider';\nimport { AIProvider, ParsedResponse, ParseOptions, ContentExtraction, ProviderMetadata } from '../core/types';\n\nexport class CopilotProvider extends BaseProvider {\n readonly name: AIProvider = 'COPILOT';\n readonly baseUrl = 'https://copilot.microsoft.com';\n\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response);\n }\n\n /**\n * Remove Copilot header/navbar from HTML\n */\n removeHeader(html: string): string {\n let cleaned = html;\n\n // Remove settings wrapper (share/settings buttons in top-right corner)\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*absolute flex end-6 origin-top-right flex-col items-end[^\"]*\"[^>]*data-testid=\"settings-wrapper\"[^>]*>.*?<\\/div><\\/div>/gis, '');\n\n return cleaned;\n }\n\n /**\n * Remove Copilot footer/followup input box from HTML\n */\n removeFooter(html: string): string {\n let cleaned = html;\n\n // Remove the composer (input box at bottom)\n // Starts with: <div class=\"absolute bottom-0 w-full\">\n // Contains: file input, composer content with textarea, buttons (home, attach, chat mode, audio call)\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*absolute bottom-0 w-full[^\"]*\"[^>]*>.*?<\\/div><\\/div><\\/div><\\/div><\\/div><\\/div><\\/div><\\/div><\\/div><\\/div><\\/div><\\/div>/gis, '');\n\n // Remove spacer div for composer height\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*mt-\\[var\\(--composer-container-height\\)\\][^\"]*\"[^>]*><\\/div>/gis, '');\n\n // Remove \"scroll to bottom\" button (full container with button and inner content)\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*pointer-events-none absolute flex justify-center z-20 inset-x-0 bottom-\\[calc\\(var\\(--composer-container-height\\)\\+1rem\\)\\][^\"]*\"[^>]*>.*?<button[^>]*data-testid=\"scroll-to-bottom-button\"[^>]*>.*?<\\/button><\\/div>/gis, '');\n\n return cleaned;\n }\n\n /**\n * Remove Copilot cookie banner from HTML\n */\n removeCookieBanner(html: string): string {\n let cleaned = html;\n\n // Remove cookie banner by id\n cleaned = cleaned.replace(/<div[^>]*id=\"cookie-banner\"[^>]*>.*?<\\/div>.*?<\\/div>.*?<\\/div>.*?<\\/div>/gis, '');\n\n // Remove cookie banner by max-w-cookie-banner class (outer container)\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*max-w-cookie-banner[^\"]*\"[^>]*>.*?<\\/div>.*?<\\/div>.*?<\\/div>.*?<\\/div>/gis, '');\n\n return cleaned;\n }\n\n /**\n * Remove Copilot sources/references panel from HTML\n */\n removeSources(html: string): string {\n // Remove the references panel (right-side panel with variable width containing citations)\n return html.replace(/<div[^>]*class=\"[^\"]*relative h-full overflow-hidden will-change-auto[^\"]*\"[^>]*style=\"[^\"]*width:\\s*\\d+px[^\"]*\"[^>]*>[\\s\\S]*?(?=<div[^>]*class=\"[^\"]*pointer-events-none (?:fixed|absolute)[^\"]*\")/gi, '');\n }\n\n /**\n * Remove Copilot sidebar from HTML\n */\n removeSidebar(html: string): string {\n // Handled with CSS in parse(). The sidebar shares a flex wrapper with\n // <main>, and a regex removes the opening tag of that wrapper.\n return html;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, text } = this.extractContent(response);\n\n if (!html) {\n throw new Error('No HTML content found in Copilot response');\n }\n\n let finalHtml = html;\n\n const removeHeader = options?.removeHeader ?? false;\n const removeFooter = options?.removeFooter ?? false;\n\n // Sanitize HTML\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Remove cookie banner (always)\n finalHtml = this.removeCookieBanner(finalHtml);\n\n // Remove header if requested\n if (removeHeader) {\n finalHtml = this.removeHeader(finalHtml);\n }\n\n // Remove footer if requested\n if (removeFooter) {\n finalHtml = this.removeFooter(finalHtml);\n }\n\n // Remove sidebar if requested\n if (options?.removeSidebar) {\n finalHtml = this.removeSidebar(finalHtml);\n }\n\n // Remove sources/references panel if requested\n if (options?.removeSources) {\n finalHtml = this.removeSources(finalHtml);\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n let customCSS = '';\n\n if (removeHeader) {\n customCSS += `\n [data-testid=\"sticky-header\"],\n [data-testid=\"backstage-chats\"],\n div:has(> div > [data-testid=\"date-divider\"]) {\n display: none !important;\n }\n `;\n }\n\n if (options?.removeSidebar) {\n customCSS += `\n div:has(> #sidebar-container) { display: none !important; }\n `;\n }\n\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n text,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n cookieBannerRemoved: true,\n headerRemoved: removeHeader,\n footerRemoved: removeFooter,\n sidebarRemoved: options?.removeSidebar || false,\n sourcesRemoved: options?.removeSources || false,\n linksRemoved: options?.removeLinks || false,\n } as ProviderMetadata,\n };\n }\n}","import { BaseProvider } from \"./base-provider\";\nimport {\n AIProvider,\n ParsedResponse,\n ParseOptions,\n ContentExtraction,\n ProviderMetadata,\n} from \"../core/types\";\n\nexport class AIOverviewProvider extends BaseProvider {\n readonly name: AIProvider = \"AIOVERVIEW\";\n readonly baseUrl = \"https://www.google.com\";\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response, true);\n }\n\n /**\n * Remove Google Search header/navbar from HTML\n */\n removeHeader(html: string): string {\n // Remove header elements via CSS injection\n return html;\n }\n\n /**\n * Remove Google Search footer from HTML\n */\n removeFooter(html: string): string {\n // Remove footer elements via CSS injection\n return html;\n }\n\n /**\n * Remove Google Search sidebar from HTML\n */\n removeSidebar(html: string): string {\n // Remove sidebar elements via CSS injection\n return html;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, sources } = this.extractContent(response);\n\n if (!html) {\n throw new Error(\"No HTML content found in AI Overview response\");\n }\n\n let finalHtml = html;\n\n // For AI Overview, default to removing header and footer for cleaner display\n const removeHeader = options?.removeHeader ?? true;\n const removeFooter = options?.removeFooter ?? true;\n\n // Sanitize HTML\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Remove header if requested\n if (removeHeader) {\n finalHtml = this.removeHeader(finalHtml);\n }\n\n // Remove footer if requested\n if (removeFooter) {\n finalHtml = this.removeFooter(finalHtml);\n }\n\n // Remove sidebar if requested\n if (options?.removeSidebar) {\n finalHtml = this.removeSidebar(finalHtml);\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n // Build CSS based on options\n let stylesToInject = \"\";\n\n // Header removal styles\n if (removeHeader) {\n stylesToInject += `\n /* Header hiding */\n header, #header, #searchform, .sfbg, #appbar,\n div[role=\"navigation\"], #leftnav, #sidetogether,\n [role=\"banner\"], .Fgvgjc, #hdtb, .hdtb-msb,\n .DZ13He, .wYq63b, .eT9Cje, .bNg8Rb, .S6VXfe, .Lu57id {\n display: none !important;\n }\n `;\n }\n\n // Sidebar removal styles\n if (options?.removeSidebar) {\n stylesToInject += `\n /* Sidebar hiding */\n #leftnav, #sidetogether {\n display: none !important;\n }\n `;\n }\n\n // Footer removal styles\n if (removeFooter) {\n stylesToInject += `\n /* Footer hiding */\n footer, #footer, #sfooter, .fbar,\n .pdp-nav, [aria-label=\"Main menu\"], .gb_Td, .gb_L {\n display: none !important;\n }\n `;\n }\n\n // Inject base URL and styles\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS: stylesToInject,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n sources,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n headerRemoved: removeHeader,\n footerRemoved: removeFooter,\n sidebarRemoved: options?.removeSidebar || false,\n linksRemoved: options?.removeLinks || false,\n } as ProviderMetadata,\n };\n }\n}\n","import { BaseProvider } from \"./base-provider\";\nimport {\n AIProvider,\n ParsedResponse,\n ParseOptions,\n ContentExtraction,\n ProviderMetadata,\n} from \"../core/types\";\n\nexport class AIModeProvider extends BaseProvider {\n readonly name: AIProvider = \"AIMODE\";\n readonly baseUrl = \"https://www.google.com\";\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response);\n }\n\n /**\n * Remove Google Search header/navbar from HTML\n */\n removeHeader(html: string): string {\n let cleaned = html;\n\n // Remove the AI Mode filter/header bar\n // Starts with <div jsname=\"oEQ3x\" class=\"DZ13He YNk70c EjQTId\">\n // Contains the Filters and Topics navigation (AI Mode, All, Images, Videos, News, More)\n // Ends with closing divs after <hr class=\"e9c7U\">\n cleaned = cleaned.replace(\n /<div[^>]*jsname=\"oEQ3x\"[^>]*class=\"[^\"]*DZ13He[^\"]*\"[^>]*>.*?<hr class=\"e9c7U\">.*?<\\/div><\\/div><\\/div><\\/div><\\/div>/gis,\n \"\"\n );\n\n return cleaned;\n }\n\n /**\n * Remove Google Search footer from HTML\n */\n removeFooter(html: string): string {\n let cleaned = html;\n\n // Remove the AI Mode input bar/footer\n // Target the most unique identifier: data-xid=\"aim-mars-input-plate\"\n // This element is deeply nested, so we need to match many closing divs\n cleaned = cleaned.replace(\n /<div[^>]*data-xid=\"aim-mars-input-plate\"[^>]*>[\\s\\S]*?<\\/div><\\/div><\\/div><\\/div><\\/div>/gis,\n \"\"\n );\n\n // Fallback: Target by jscontroller P5gZDb which wraps the input plate\n cleaned = cleaned.replace(\n /<div[^>]*jscontroller=\"P5gZDb\"[^>]*>[\\s\\S]*?<\\/div><\\/div><\\/div>/gis,\n \"\"\n );\n\n // Fallback: Target the t0ITR container\n cleaned = cleaned.replace(\n /<div[^>]*class=\"[^\"]*t0ITR hh3ttd[^\"]*\"[^>]*>[\\s\\S]*?<\\/div><\\/div>/gis,\n \"\"\n );\n\n // Fallback: Target outer y4VEUd vve6Ce wrapper\n cleaned = cleaned.replace(\n /<div[^>]*class=\"[^\"]*y4VEUd vve6Ce[^\"]*\"[^>]*>[\\s\\S]*?<\\/div><\\/div>/gis,\n \"\"\n );\n\n return cleaned;\n }\n\n /**\n * Remove Google Search sidebar from HTML\n */\n removeSidebar(html: string): string {\n let cleaned = html;\n\n // Remove the AI Mode history panel/dialog\n // Target by aria-label (handles both attribute orderings)\n cleaned = cleaned.replace(\n /<div[^>]*aria-label=\"AI Mode history\"[^>]*class=\"[^\"]*ho072b[^\"]*\"[^>]*>[\\s\\S]*?(?=<!--TgQPHd)/gi,\n \"\"\n );\n // Fallback: class before aria-label\n cleaned = cleaned.replace(\n /<div[^>]*class=\"[^\"]*ho072b[^\"]*\"[^>]*aria-label=\"AI Mode history\"[^>]*>[\\s\\S]*?(?=<!--TgQPHd)/gi,\n \"\"\n );\n\n // Remove the floating action buttons (OEwhSe wrapper)\n cleaned = cleaned.replace(\n /<div[^>]*class=\"[^\"]*OEwhSe[^\"]*\"[^>]*>[\\s\\S]*?<\\/div><\\/div>/gis,\n \"\"\n );\n\n // Remove buttons with aria-label\n cleaned = cleaned.replace(\n /<button[^>]*aria-label=\"AI Mode history\"[^>]*>[\\s\\S]*?<\\/button>/gis,\n \"\"\n );\n\n return cleaned;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, text } = this.extractContent(response);\n\n if (!html) {\n throw new Error(\"No HTML content found in AI Mode response\");\n }\n\n let finalHtml = html;\n\n // For AI Mode, default to removing header and footer for cleaner display\n const removeHeader = options?.removeHeader ?? true;\n const removeFooter = options?.removeFooter ?? true;\n\n // Sanitize HTML\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Remove header if requested\n if (removeHeader) {\n finalHtml = this.removeHeader(finalHtml);\n }\n\n // Remove footer if requested\n if (removeFooter) {\n finalHtml = this.removeFooter(finalHtml);\n }\n\n // Remove sidebar if requested\n if (options?.removeSidebar) {\n finalHtml = this.removeSidebar(finalHtml);\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n // Build CSS based on options\n let stylesToInject = \"\";\n\n // Always inject general layout\n /* Remove cookie consent banner */\n stylesToInject += `\n .KxvlWc, #CXQnmb {\n display: none !important;\n }\n `;\n\n // Header removal styles\n if (removeHeader) {\n stylesToInject += `\n /* Header hiding */\n header, #header, #searchform, .sfbg, #appbar,\n div[role=\"navigation\"], #leftnav, #sidetogether,\n [role=\"banner\"], .Fgvgjc, #hdtb, .hdtb-msb,\n .DZ13He, .wYq63b, .eT9Cje, .bNg8Rb, .S6VXfe, .Lu57id,\n .YHsVn, .UTNPFf {\n display: none !important;\n }\n `;\n }\n\n // Footer removal styles\n if (removeFooter) {\n stylesToInject += `\n /* Footer hiding */\n footer, #footer, .fbar,\n .pdp-nav, [aria-label=\"Main menu\"], .gb_Td, .gb_L {\n display: none !important;\n }\n /* Hide the \"Ask anything\" input bar */\n [data-xid=\"aim-mars-input-plate\"],\n .UAbVe, .y4VEUd, .t0ITR.hh3ttd {\n display: none !important;\n }\n `;\n }\n\n // Sidebar removal styles\n if (options?.removeSidebar) {\n stylesToInject += `\n /* Hide AI Mode history panel */\n .ho072b, .OEwhSe, .qEn1od {\n display: none !important;\n }\n `;\n }\n\n // Inject base URL and styles\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS: stylesToInject,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n text,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n headerRemoved: removeHeader,\n footerRemoved: removeFooter,\n sidebarRemoved: options?.removeSidebar || false,\n linksRemoved: options?.removeLinks || false,\n } as ProviderMetadata,\n };\n }\n}\n","import { BaseProvider } from \"./base-provider\";\nimport {\n AIProvider,\n ParsedResponse,\n ParseOptions,\n ContentExtraction,\n ProviderMetadata,\n} from \"../core/types\";\n\nexport class GrokProvider extends BaseProvider {\n readonly name: AIProvider = \"GROK\";\n readonly baseUrl = \"https://grok.com\";\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response);\n }\n\n /**\n * Remove Grok header from HTML (using CSS-based hiding)\n */\n removeHeader(html: string): string {\n // Header removal is now done via CSS in the parse method\n return html;\n }\n\n /**\n * Remove Grok footer/input area from HTML (using CSS-based hiding)\n */\n removeFooter(html: string): string {\n // Footer removal is now done via CSS in the parse method\n return html;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, text } = this.extractContent(response);\n\n if (!html) {\n throw new Error(\"No HTML content found in Grok response\");\n }\n\n let finalHtml = html;\n\n // Sanitize HTML\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Build CSS based on options\n let stylesToInject = '';\n\n // Always-on: hide cookie/privacy policy banner (Grok uses data-cookie-banner attribute)\n stylesToInject += `\n [data-cookie-banner],\n [data-cookie-banner=\"true\"] {\n display: none !important;\n }\n `;\n\n // Always-on: hide rate-limit banners and toast notifications\n stylesToInject += `\n [data-sonner-toaster],\n [data-sonner-toast],\n [class*=\"sonner-toast\"] {\n display: none !important;\n }\n `;\n\n // Sources panel removal via regex (CSS selectors don't reliably hide this element)\n if (options?.removeSources) {\n // Remove the sources panel wrapper containing the aside\n finalHtml = finalHtml.replace(/<div[^>]*class=\"[^\"]*h-dvh[^\"]*flex-shrink-0[^\"]*max-w-[^\"]*\"[^>]*>[\\s\\S]*?<\\/aside>[\\s\\S]*?(?=<section)/gi, '');\n\n // Hide the inline \"N sources\" trigger button and vaul-drawer overlay via CSS\n stylesToInject += `\n div[data-state] > div.flex.flex-row.gap-1.items-center.rounded-full.cursor-pointer {\n display: none !important;\n }\n [vaul-drawer][vaul-drawer-direction=\"right\"],\n [vaul-overlay] {\n display: none !important;\n }\n `;\n }\n\n // Header hiding via CSS\n if (options?.removeHeader) {\n stylesToInject += `\n /* Header hiding - hide elements with Grok's header class pattern */\n div[class*=\"h-16\"][class*=\"top-0\"][class*=\"z-10\"],\n div[class*=\"absolute\"][class*=\"inset-x-0\"][class*=\"top-0\"] {\n display: none !important;\n }\n `;\n }\n\n // Footer hiding via CSS\n if (options?.removeFooter) {\n stylesToInject += `\n /* Footer hiding - hide Grok's footer/input area */\n div[class*=\"absolute\"][class*=\"inset-x-0\"][class*=\"bottom-0\"][class*=\"max-w-breakout\"],\n div[class*=\"absolute\"][class*=\"bottom-0\"][class*=\"w-full\"] {\n display: none !important;\n }\n `;\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS: stylesToInject,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n text,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n linksRemoved: options?.removeLinks || false,\n headerRemoved: options?.removeHeader || false,\n footerRemoved: options?.removeFooter || false,\n cookieBannerRemoved: true,\n sourcesRemoved: options?.removeSources || false,\n } as ProviderMetadata,\n };\n }\n}\n","import { AIProvider, ParsedResponse, ParseOptions, extractContentCommon } from './types';\nimport { ProviderDetector } from './detector';\nimport { ChatGPTProvider } from '../providers/chatgpt';\nimport { GeminiProvider } from '../providers/gemini';\nimport { PerplexityProvider } from '../providers/perplexity';\nimport { CopilotProvider } from '../providers/copilot';\nimport { AIOverviewProvider } from '../providers/ai-overview';\nimport { AIModeProvider } from '../providers/ai-mode';\nimport { GrokProvider } from '../providers/grok';\n\nexport class AIResponseParser {\n private providers: Map<AIProvider, any> = new Map();\n\n constructor() {\n this.providers.set('CHATGPT', new ChatGPTProvider());\n this.providers.set('GEMINI', new GeminiProvider());\n this.providers.set('PERPLEXITY', new PerplexityProvider());\n this.providers.set('COPILOT', new CopilotProvider());\n this.providers.set('AIOVERVIEW', new AIOverviewProvider());\n this.providers.set('AIMODE', new AIModeProvider());\n this.providers.set('GROK', new GrokProvider());\n }\n\n /**\n * Parse an AI response with auto-detected provider\n */\n parse(response: any, options?: ParseOptions): ParsedResponse | null {\n const detection = ProviderDetector.detect(response);\n\n if (!detection) {\n // Try to parse as generic HTML if no provider detected\n return this.parseGeneric(response);\n }\n\n const provider = this.providers.get(detection.provider);\n if (!provider) {\n return null;\n }\n\n try {\n const parsed = provider.parse(response, options);\n return {\n ...parsed,\n metadata: {\n ...parsed.metadata,\n detectionConfidence: detection.confidence,\n },\n };\n } catch (error) {\n console.error(`Failed to parse response with ${detection.provider}:`, error);\n return null;\n }\n }\n\n /**\n * Parse with explicit provider specification\n */\n parseWithProvider(\n response: any,\n provider: AIProvider,\n options?: ParseOptions\n ): ParsedResponse | null {\n const providerInstance = this.providers.get(provider);\n if (!providerInstance) {\n throw new Error(`Unknown provider: ${provider}`);\n }\n\n try {\n return providerInstance.parse(response, options);\n } catch (error) {\n console.error(`Failed to parse response with ${provider}:`, error);\n return null;\n }\n }\n\n /**\n * Detect the provider from a response\n */\n detectProvider(response: any): AIProvider | null {\n const detection = ProviderDetector.detect(response);\n return detection?.provider || null;\n }\n\n /**\n * Get all possible providers with confidence scores\n */\n detectAllProviders(response: any): Array<{ provider: AIProvider; confidence: number }> {\n return ProviderDetector.getAllProviders(response);\n }\n\n /**\n * Parse as generic HTML when no specific provider is detected\n */\n private parseGeneric(response: any): ParsedResponse | null {\n const { html, text } = extractContentCommon(response);\n\n if (!html && !text) {\n return null;\n }\n\n // Basic sanitization\n let sanitizedHtml = html;\n if (sanitizedHtml) {\n sanitizedHtml = sanitizedHtml.replace(/<script\\b[^>]*>[\\s\\S]*?<\\/script>/gim, '');\n sanitizedHtml = sanitizedHtml.replace(/<noscript[\\s\\S]*?<\\/noscript>/gi, '');\n }\n\n return {\n provider: 'CHATGPT' as AIProvider, // Default to ChatGPT for unknown\n html: sanitizedHtml || '',\n text: text || '',\n metadata: {\n isGeneric: true,\n },\n };\n }\n\n /**\n * Get list of supported providers\n */\n getSupportedProviders(): AIProvider[] {\n return Array.from(this.providers.keys());\n }\n\n /**\n * Register a custom provider\n */\n registerProvider(provider: AIProvider, instance: any): void {\n this.providers.set(provider, instance);\n }\n}\n\n// Export a singleton instance\nexport const parser = new AIResponseParser();\n\n// Convenience functions\nexport const parseAiResponse = (response: any, options?: ParseOptions) =>\n parser.parse(response, options);\n\nexport const detectProvider = (response: any) =>\n parser.detectProvider(response);"],"names":["extractContentCommon","response","html","text","dataToCheck","result","trim","startsWith","includes","content","ProviderDetector","detect","scores","CHATGPT","GEMINI","PERPLEXITY","COPILOT","AIOVERVIEW","AIMODE","GROK","provider","patterns","Object","entries","this","PROVIDER_PATTERNS","pattern","_a","maxScore","detectedProvider","score","confidence","values","reduce","a","b","Math","max","getAllProviders","providers","matches","push","length","sort","validate","detected","_b","aioverview","_c","BaseProvider","includeSources","sources","injectStyles","options","styledHtml","baseUrl","replace","styles","customCSS","sanitizeHtml","sanitized","isFullDocument","test","removeLinks","wrapFragment","ChatGPTProvider","constructor","name","extractContent","match","attributes","cleanedAttrs","removeHeader","cleaned","removeSidebar","removeFooter","removeCookieBanner","removeSources","parse","Error","finalHtml","metadata","cookieBannerRemoved","headerRemoved","sidebarRemoved","footerRemoved","sourcesRemoved","linksRemoved","GeminiProvider","PerplexityProvider","_html","CopilotProvider","AIOverviewProvider","stylesToInject","AIModeProvider","GrokProvider","AIResponseParser","Map","set","detection","parseGeneric","get","parsed","detectionConfidence","error","console","parseWithProvider","providerInstance","detectProvider","detectAllProviders","sanitizedHtml","isGeneric","getSupportedProviders","Array","from","keys","registerProvider","instance","parser","parseAiResponse"],"mappings":"AAgEM,SAAUA,EAAqBC,GACnC,IAAIC,EAAO,GACPC,EAAO,GAGPC,EAAcH,EA0BlB,OAzBIA,EAASI,SACXD,EAAcH,EAASI,QAIE,iBAAhBD,EACLA,EAAYE,OAAOC,WAAW,MAAQH,EAAYI,SAAS,KAC7DN,EAAOE,EAEPD,EAAOC,EAEuB,iBAAhBA,GAA4C,OAAhBA,IACxCA,EAAYF,KACdA,EAAOE,EAAYF,KACVE,EAAYK,QACjBL,EAAYK,QAAQH,OAAOC,WAAW,KACxCL,EAAOE,EAAYK,QAEnBN,EAAOC,EAAYK,QAEZL,EAAYD,OACrBA,EAAOC,EAAYD,OAIhB,CAAED,OAAMC,OACjB,OC9FaO,EA0FX,aAAOC,CAAOV,GACZ,MAAMW,EAAqC,CACzCC,QAAS,EACTC,OAAQ,EACRC,WAAY,EACZC,QAAS,EACTC,WAAY,EACZC,OAAQ,EACRC,KAAM,GAIR,IAAK,MAAOC,EAAUC,KAAaC,OAAOC,QAAQC,KAAKC,mBACrD,IAAK,MAAMC,KAAWL,EACpB,IACMK,EAAQzB,IACVW,EAAOQ,IAEX,CAAE,MAAAO,GAEF,CAKJ,IAAIC,EAAW,EACXC,EAAsC,KAE1C,IAAK,MAAOT,EAAUU,KAAUR,OAAOC,QAAQX,GACzCkB,EAAQF,IACVA,EAAWE,EACXD,EAAmBT,GAKvB,OAAiB,IAAbQ,EAAuB,KAEpB,CACLR,SAAUS,EACVE,WAAYH,EAAWN,OAAOU,OAAOpB,GAAQqB,OAAO,CAACC,EAAGC,IAAMC,KAAKC,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C,CAKA,kBAAAyF,CAAmB5G,GACjB,OAAOS,EAAiB4B,gBAAgBrC,EAC1C,CAKQ,YAAAmG,CAAanG,GACnB,MAAMC,KAAEA,EAAIC,KAAEA,GAASH,EAAqBC,GAE5C,IAAKC,IAASC,EACZ,OAAO,KAIT,IAAI2G,EAAgB5G,EAMpB,OALI4G,IACFA,EAAgBA,EAActD,QAAQ,uCAAwC,IAC9EsD,EAAgBA,EAActD,QAAQ,kCAAmC,KAGpE,CACLpC,SAAU,UACVlB,KAAM4G,GAAiB,GACvB3G,KAAMA,GAAQ,GACd8E,SAAU,CACR8B,WAAW,GAGjB,CAKA,qBAAAC,GACE,OAAOC,MAAMC,KAAK1F,KAAKe,UAAU4E,OACnC,CAKA,gBAAAC,CAAiBhG,EAAsBiG,GACrC7F,KAAKe,UAAU2D,IAAI9E,EAAUiG,EAC/B,EAIK,MAAMC,EAAS,IAAItB,EAGbuB,EAAkB,CAACtH,EAAeoD,IAC7CiE,EAAOxC,MAAM7E,EAAUoD,GAEZuD,EAAkB3G,GAC7BqH,EAAOV,eAAe3G"}
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/core/types.ts","../src/core/detector.ts","../src/providers/base-provider.ts","../src/providers/chatgpt.ts","../src/providers/gemini.ts","../src/providers/perplexity.ts","../src/providers/copilot.ts","../src/providers/ai-overview.ts","../src/providers/ai-mode.ts","../src/providers/bing-ai-mode.ts","../src/providers/grok.ts","../src/core/parser.ts"],"sourcesContent":["export type AIProvider =\n | 'CHATGPT'\n | 'GEMINI'\n | 'PERPLEXITY'\n /** @deprecated cloro discontinues its Copilot endpoint. Use `BING_AIMODE` for Bing's AI answers. */\n | 'COPILOT'\n | 'AIOVERVIEW'\n | 'AIMODE'\n | 'BING_AIMODE'\n | 'GROK';\n\nexport interface ParsedResponse {\n provider: AIProvider;\n html: string;\n text?: string;\n sources?: any[];\n metadata?: Record<string, any>;\n}\n\nexport interface ParseOptions {\n removeLinks?: boolean;\n removeHeader?: boolean;\n removeFooter?: boolean;\n removeSidebar?: boolean;\n removeSources?: boolean;\n}\n\nexport interface ProviderConfig {\n name: AIProvider;\n baseUrl: string;\n}\n\nexport interface DetectedProvider {\n provider: AIProvider;\n confidence: number;\n}\n\nexport interface StyleOptions {\n customCSS?: string;\n hideUI?: boolean;\n baseUrl?: string;\n}\n\nexport type ContentExtraction = {\n html?: string;\n text?: string;\n sources?: any[];\n};\n\n/**\n * Standardized metadata for provider responses\n */\nexport interface ProviderMetadata {\n isFullDocument?: boolean;\n headerRemoved?: boolean;\n footerRemoved?: boolean;\n sidebarRemoved?: boolean;\n linksRemoved?: boolean;\n cookieBannerRemoved?: boolean;\n sourcesRemoved?: boolean;\n detectionConfidence?: number;\n}\n\n/**\n * Common content extraction utility - shared across providers and parser\n */\nexport function extractContentCommon(response: any): ContentExtraction {\n let html = '';\n let text = '';\n\n // Handle nested structure\n let dataToCheck = response;\n if (response.result) {\n dataToCheck = response.result;\n }\n\n // Extract content\n if (typeof dataToCheck === 'string') {\n if (dataToCheck.trim().startsWith('<') && dataToCheck.includes('>')) {\n html = dataToCheck;\n } else {\n text = dataToCheck;\n }\n } else if (typeof dataToCheck === 'object' && dataToCheck !== null) {\n if (dataToCheck.html) {\n html = dataToCheck.html;\n } else if (dataToCheck.content) {\n if (dataToCheck.content.trim().startsWith('<')) {\n html = dataToCheck.content;\n } else {\n text = dataToCheck.content;\n }\n } else if (dataToCheck.text) {\n text = dataToCheck.text;\n }\n }\n\n return { html, text };\n}","import { AIProvider, DetectedProvider } from './types';\n\nexport class ProviderDetector {\n private static readonly PROVIDER_PATTERNS = {\n CHATGPT: [\n // Check for token-based CSS classes\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('bg-token-bg-primary') || html.includes('text-token-text-secondary');\n },\n // Check for OpenAI-specific patterns\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('chatgpt.com') || html.includes('openai.com');\n },\n ],\n GEMINI: [\n // Check for Material Design components\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('bard-sidenav') || html.includes('mat-sidenav');\n },\n // Check for Gemini-specific markup. The domain name alone also occurs in\n // Google result pages that link to Gemini.\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('<chat-app') || html.includes('gem-sys-color');\n },\n ],\n PERPLEXITY: [\n // Check for Perplexity domain\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('perplexity.ai');\n },\n // Check for Perplexity-specific structure\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('prose') && !html.includes('grok.com') && !html.includes('chatgpt.com');\n },\n ],\n COPILOT: [\n // Check for Copilot-specific elements\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('copilot.microsoft.com') || html.includes('data-testid=\"sidebar-container\"');\n },\n ],\n AIOVERVIEW: [\n // Check for AI Overview specific structure\n (response: any) => {\n if (response?.result?.aioverview?.text) return true;\n if (response?.aioverview?.text) return true;\n return false;\n },\n // Check for a Google result page without AI Mode markers.\n // WIZ_global_data alone also occurs in Gemini pages.\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('id=\"gsr\"') && !html.includes('aim-mars') && !html.includes('ho072b');\n },\n ],\n AIMODE: [\n // Check for the AI Mode input and turn containers. The DZ13He header\n // class also occurs in every Google result page.\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('aim-mars');\n },\n // Check for the AI Mode history panel\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('ho072b');\n },\n ],\n BING_AIMODE: [\n // Check for the Bing AI Mode chat canvas\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('b_cs_canvas');\n },\n // Check for the answer container, in the shell's srcdoc or in the\n // answer document itself\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('gs_temp_content');\n },\n ],\n GROK: [\n // Check for Grok domain\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('grok.com') || html.includes('x.ai');\n },\n // Check for Grok CDN or app-specific patterns\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('cdn.grok.com') || html.includes('vaul-drawer');\n },\n ],\n };\n\n /**\n * Detect the AI provider from the response\n */\n static detect(response: any): DetectedProvider | null {\n const scores: Record<AIProvider, number> = {\n CHATGPT: 0,\n GEMINI: 0,\n PERPLEXITY: 0,\n COPILOT: 0,\n AIOVERVIEW: 0,\n AIMODE: 0,\n BING_AIMODE: 0,\n GROK: 0,\n };\n\n // Score each provider based on pattern matches\n for (const [provider, patterns] of Object.entries(this.PROVIDER_PATTERNS)) {\n for (const pattern of patterns) {\n try {\n if (pattern(response)) {\n scores[provider as AIProvider]++;\n }\n } catch {\n // Ignore pattern errors\n }\n }\n }\n\n // Find the provider with the highest score\n let maxScore = 0;\n let detectedProvider: AIProvider | null = null;\n\n for (const [provider, score] of Object.entries(scores)) {\n if (score > maxScore) {\n maxScore = score;\n detectedProvider = provider as AIProvider;\n }\n }\n\n // Return null if no patterns matched\n if (maxScore === 0) return null;\n\n return {\n provider: detectedProvider!,\n confidence: maxScore / Object.values(scores).reduce((a, b) => Math.max(a, b), 1),\n };\n }\n\n /**\n * Get all possible providers with their confidence scores\n */\n static getAllProviders(response: any): DetectedProvider[] {\n const providers: DetectedProvider[] = [];\n\n for (const [provider, patterns] of Object.entries(this.PROVIDER_PATTERNS)) {\n let matches = 0;\n for (const pattern of patterns) {\n try {\n if (pattern(response)) {\n matches++;\n }\n } catch {\n // Ignore pattern errors\n }\n }\n\n if (matches > 0) {\n providers.push({\n provider: provider as AIProvider,\n confidence: matches / patterns.length,\n });\n }\n }\n\n // Sort by confidence (highest first)\n return providers.sort((a, b) => b.confidence - a.confidence);\n }\n\n /**\n * Validate if a detected provider is likely correct\n */\n static validate(response: any, provider: AIProvider): boolean {\n const detected = this.detect(response);\n return detected?.provider === provider && detected.confidence > 0.5;\n }\n}","import { AIProvider, ParsedResponse, ParseOptions, StyleOptions, ContentExtraction, extractContentCommon } from '../core/types';\n\nexport abstract class BaseProvider {\n abstract readonly name: AIProvider;\n abstract readonly baseUrl: string;\n\n /**\n * Parse an AI response and return structured content\n */\n abstract parse(response: any, options?: ParseOptions): ParsedResponse;\n\n /**\n * Extract content from the response object\n */\n abstract extractContent(response: any): ContentExtraction;\n\n /**\n * Common content extraction logic - can be used by providers\n */\n protected extractContentCommon(response: any, includeSources = false): ContentExtraction {\n const result = extractContentCommon(response);\n\n if (includeSources) {\n let sources: any[] = [];\n const dataToCheck = response.result || response;\n\n if (typeof dataToCheck === 'object' && dataToCheck !== null) {\n if (dataToCheck.aioverview?.sources) {\n sources = dataToCheck.aioverview.sources;\n } else if (dataToCheck.sources) {\n sources = dataToCheck.sources;\n }\n }\n\n return { ...result, sources };\n }\n\n return result;\n }\n\n /**\n * Inject provider-specific styles into HTML\n */\n injectStyles(html: string, options?: StyleOptions): string {\n let styledHtml = html;\n\n // Inject base URL if not already present\n if (options?.baseUrl && !html.includes('<base ')) {\n if (styledHtml.includes('<head>')) {\n styledHtml = styledHtml.replace(\n '<head>',\n `<head><base href=\"${options.baseUrl}\">`,\n );\n } else {\n styledHtml = styledHtml.replace(\n /(<html[^>]*>)/i,\n `$1<head><base href=\"${options.baseUrl}\"></head>`,\n );\n }\n }\n\n // Inject styles only if customCSS is provided\n const styles = options?.customCSS || '';\n\n if (styles && styledHtml.includes('<head>')) {\n styledHtml = styledHtml.replace('<head>', `<head><style>${styles}</style>`);\n } else if (styles) {\n styledHtml = styledHtml.replace(\n /(<html[^>]*>)/i,\n `$1<head><style>${styles}</style></head>`,\n );\n }\n\n return styledHtml;\n }\n\n /**\n * Sanitize HTML content\n */\n sanitizeHtml(html: string): string {\n // Remove scripts\n let sanitized = html.replace(/<script\\b[^>]*>[\\s\\S]*?<\\/script>/gim, '');\n\n // Remove noscript tags\n sanitized = sanitized.replace(/<noscript[\\s\\S]*?<\\/noscript>/gi, '');\n\n return sanitized;\n }\n\n /**\n * Check if content is a full HTML document\n */\n isFullDocument(html: string): boolean {\n return /^\\s*(<html|<!DOCTYPE)/i.test(html);\n }\n\n /**\n * Remove all links from HTML, keeping the text content\n */\n removeLinks(html: string): string {\n // Replace anchor tags with their text content\n return html.replace(/<a\\b[^>]*>([\\s\\S]*?)<\\/a>/gim, '$1');\n }\n\n /**\n * Wrap HTML fragment in a document\n */\n wrapFragment(html: string): string {\n return `<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"utf-8\">\n <meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'none'; script-src 'none'; style-src 'unsafe-inline';\">\n <style>\n body {\n margin: 0;\n padding: 16px;\n font-family: system-ui, -apple-system, sans-serif;\n white-space: pre-wrap;\n word-wrap: break-word;\n }\n img { max-width: 100%; height: auto; }\n body {\n pointer-events: none;\n user-select: none;\n }\n </style>\n</head>\n<body>\n ${html}\n</body>\n</html>`;\n }\n}","import { BaseProvider } from \"./base-provider\";\nimport {\n AIProvider,\n ParsedResponse,\n ParseOptions,\n ContentExtraction,\n ProviderMetadata,\n} from \"../core/types\";\n\nexport class ChatGPTProvider extends BaseProvider {\n readonly name: AIProvider = \"CHATGPT\";\n readonly baseUrl = \"https://chatgpt.com\";\n\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response);\n }\n\n /**\n * Remove links from HTML, preserving badge styling\n * Converts <a> tags to <span> while keeping class attributes\n */\n removeLinks(html: string): string {\n // Replace anchor tags with span tags, keeping all attributes except href/alt/rel/target\n return html\n .replace(/<a\\b([^>]*)>/gi, (match, attributes) => {\n // Remove link-specific attributes but keep others (class, style, etc.)\n const cleanedAttrs = attributes\n .replace(/\\s+href\\s*=\\s*[\"'][^\"']*[\"']/gi, \"\")\n .replace(/\\s+alt\\s*=\\s*[\"'][^\"']*[\"']/gi, \"\")\n .replace(/\\s+rel\\s*=\\s*[\"'][^\"']*[\"']/gi, \"\")\n .replace(/\\s+target\\s*=\\s*[\"'][^\"']*[\"']/gi, \"\")\n .trim();\n return `<span${cleanedAttrs ? \" \" + cleanedAttrs : \"\"}>`;\n })\n .replace(/<\\/a>/gi, \"</span>\");\n }\n\n /**\n * Remove ChatGPT header from HTML\n */\n removeHeader(html: string): string {\n let cleaned = html;\n\n // Remove page header by id\n cleaned = cleaned.replace(\n /<header[^>]*id=\"page-header\"[^>]*>.*?<\\/header>/gis,\n \"\"\n );\n\n return cleaned;\n }\n\n /**\n * Remove ChatGPT sidebar from HTML\n */\n removeSidebar(html: string): string {\n // The sidebar wrapper is hidden with CSS in parse(). Its nested <div>s\n // cannot be balanced with a regex.\n return html.replace(/<nav[^>]*>.*?<\\/nav>/gis, \"\");\n }\n\n /**\n * Remove ChatGPT footer/composer from HTML.\n * Handled with CSS in parse(). A regex cannot balance the nested <div>s of\n * the composer, and a partial removal changes the page structure.\n */\n removeFooter(html: string): string {\n return html;\n }\n\n /**\n * Remove ChatGPT cookie banner from HTML\n */\n removeCookieBanner(html: string): string {\n // Remove the cookie dialog banner (matched by cookie-policy URL, language-agnostic)\n return html.replace(/<div[^>]*role=\"dialog\"[^>]*>[\\s\\S]*?openai\\.com\\/policies\\/cookie-policy[\\s\\S]*?<\\/div><\\/div><\\/div><\\/div><\\/div><\\/div>/gi, '');\n }\n\n /**\n * Remove ChatGPT sources/search flyout panel from HTML.\n * Handled with CSS in parse().\n */\n removeSources(html: string): string {\n return html;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, text } = this.extractContent(response);\n\n if (!html) {\n throw new Error(\"No HTML content found in ChatGPT response\");\n }\n\n let finalHtml = html;\n\n const removeFooter = options?.removeFooter ?? false;\n\n // Sanitize HTML\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Always remove cookie banner\n finalHtml = this.removeCookieBanner(finalHtml);\n\n // Remove header if requested\n if (options?.removeHeader) {\n finalHtml = this.removeHeader(finalHtml);\n }\n\n // Remove sidebar if requested\n if (options?.removeSidebar) {\n finalHtml = this.removeSidebar(finalHtml);\n }\n\n // Remove footer if requested\n if (removeFooter) {\n finalHtml = this.removeFooter(finalHtml);\n }\n\n // Remove sources panel if requested\n if (options?.removeSources) {\n finalHtml = this.removeSources(finalHtml);\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n // Build CSS overrides conditionally based on which remove* options are active\n let customCSS = '';\n\n if (options?.removeSidebar) {\n customCSS += `\n #stage-slideover-sidebar { display: none !important; }\n [data-sidebar-item] { display: none !important; }\n [data-skip-to-content] { display: none !important; }\n .h-svh { height: auto !important; }\n `;\n }\n\n if (removeFooter) {\n customCSS += `\n #thread-bottom-container { display: none !important; }\n form[data-type=\"unified-composer\"] { display: none !important; }\n #thread { min-height: auto !important; }\n `;\n }\n\n if (options?.removeSources) {\n customCSS += `\n /* Side flyout, the modal sheet that replaces it on narrow pages, and\n the sources dialog of the mobile page */\n [data-testid=\"stage-thread-flyout\"],\n [data-sheet-travel-state],\n #assistant-sources-dialog {\n display: none !important;\n }\n `;\n }\n\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n text,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n cookieBannerRemoved: true,\n headerRemoved: options?.removeHeader || false,\n sidebarRemoved: options?.removeSidebar || false,\n footerRemoved: removeFooter,\n sourcesRemoved: options?.removeSources || false,\n linksRemoved: options?.removeLinks || false,\n } as ProviderMetadata,\n };\n }\n}\n","import { BaseProvider } from './base-provider';\nimport { AIProvider, ParsedResponse, ParseOptions, ContentExtraction, ProviderMetadata } from '../core/types';\n\nexport class GeminiProvider extends BaseProvider {\n readonly name: AIProvider = 'GEMINI';\n readonly baseUrl = 'https://gemini.google.com';\n\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response, true);\n }\n\n /**\n * Remove Gemini header/navbar from HTML\n */\n removeHeader(html: string): string {\n let cleaned = html;\n\n // Remove the Google navbar with boqOnegoogleliteOgbOneGoogleBar class\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*boqOnegoogleliteOgbOneGoogleBar[^\"]*\"[^>]*>.*?<\\/div><\\/div><\\/div><\\/div>/gis, '');\n\n // Remove top-bar-actions (About Gemini, Gemini App, Subscriptions, For Business links)\n cleaned = cleaned.replace(/<top-bar-actions[^>]*>.*?<\\/top-bar-actions>/gis, '');\n\n // Remove desktop-ogb-buffer\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*desktop-ogb-buffer[^\"]*\"[^>]*><\\/div>/gis, '');\n\n return cleaned;\n }\n\n /**\n * Remove Gemini footer/follow-up input box from HTML\n */\n removeFooter(html: string): string {\n // Remove input-container (text input, upload button, send button, disclaimer)\n return html.replace(/<input-container[^>]*>.*?<\\/input-container>/gis, '');\n }\n\n /**\n * Remove Gemini sidebar from HTML\n */\n removeSidebar(html: string): string {\n // Remove bard-sidenav element\n return html.replace(/<bard-sidenav[^>]*>.*?<\\/bard-sidenav>/gis, '');\n }\n\n /**\n * Remove Gemini sources panel from HTML\n */\n removeSources(html: string): string {\n let cleaned = html;\n\n // Remove the context-sidebar element (contains source cards)\n cleaned = cleaned.replace(/<context-sidebar[^>]*>[\\s\\S]*?<\\/context-sidebar>/gi, '');\n\n // Remove the sources-sidebar-button trigger\n cleaned = cleaned.replace(/<sources-sidebar-button[^>]*>[\\s\\S]*?<\\/sources-sidebar-button>/gi, '');\n\n return cleaned;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, text, sources } = this.extractContent(response);\n\n if (!html) {\n throw new Error('No HTML content found in Gemini response');\n }\n\n let finalHtml = html;\n\n const removeHeader = options?.removeHeader ?? false;\n const removeFooter = options?.removeFooter ?? false;\n\n // Sanitize HTML (remove scripts and noscript)\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Remove header if requested\n if (removeHeader) {\n finalHtml = this.removeHeader(finalHtml);\n }\n\n // Remove footer if requested\n if (removeFooter) {\n finalHtml = this.removeFooter(finalHtml);\n }\n\n // Remove sidebar if requested\n if (options?.removeSidebar) {\n finalHtml = this.removeSidebar(finalHtml);\n }\n\n // Remove sources panel if requested\n if (options?.removeSources) {\n finalHtml = this.removeSources(finalHtml);\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n // Always-on: hide the \"Sign in\" prompt above the input box\n let customCSS = `\n sign-in-nudge { display: none !important; }\n `;\n\n // The hamburger button has nested <div>s that a regex cannot balance\n if (removeHeader) {\n customCSS += `\n .side-nav-menu-button { display: none !important; }\n `;\n }\n\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n text,\n sources,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n headerRemoved: removeHeader,\n footerRemoved: removeFooter,\n sidebarRemoved: options?.removeSidebar || false,\n sourcesRemoved: options?.removeSources || false,\n linksRemoved: options?.removeLinks || false,\n } as ProviderMetadata,\n };\n }\n}","import { BaseProvider } from \"./base-provider\";\nimport {\n AIProvider,\n ParsedResponse,\n ParseOptions,\n ContentExtraction,\n ProviderMetadata,\n} from \"../core/types\";\n\nexport class PerplexityProvider extends BaseProvider {\n readonly name: AIProvider = \"PERPLEXITY\";\n readonly baseUrl = \"https://www.perplexity.ai\";\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response);\n }\n\n /**\n * Remove Perplexity header/navbar from HTML\n */\n removeHeader(html: string): string {\n // Remove navbar by targeting the unique @container/header class\n // Matches from the navbar opening div through the border divider at the bottom\n return html.replace(\n /<div[^>]*class=\"[^\"]*@container\\/header[^\"]*\"[^>]*>.*?<div[^>]*class=\"[^\"]*absolute bottom-0 inset-x-0 border-b[^\"]*\"[^>]*><\\/div>/gis,\n \"\"\n );\n }\n\n /**\n * Remove Perplexity footer/followup input from HTML.\n * Uses CSS hiding — the footer's deeply nested DOM makes regex counting\n * of closing </div> tags fragile across Perplexity versions.\n */\n removeFooter(_html: string): string {\n // Handled via CSS injection in parse() for reliability\n return _html;\n }\n\n /**\n * Remove Perplexity left sidebar navigation from HTML\n */\n removeSidebar(html: string): string {\n let cleaned = html;\n // Remove the sidebar nav element and its width-holder parent\n cleaned = cleaned.replace(\n /<div[^>]*class=\"[^\"]*w-sideBarWidth[^\"]*\"[^>]*>[\\s\\S]*?<\\/nav>[\\s\\S]*?<\\/div>/gi,\n \"\"\n );\n return cleaned;\n }\n\n /**\n * Remove Perplexity sources panel from HTML.\n *\n * Why: Perplexity's sources panel is the deeply-nested\n * `fixed inset-y-0 right-0` container that wraps a citations tabpanel.\n * We can't reliably balance its nested </div>s with regex, and a partial\n * strip orphans the panel's children visibly. CSS-only hiding (see\n * parse()) is the load-bearing approach — `display:none` on the wrapper\n * collapses every descendant. The same rule hides the open \"Sources\"\n * popover, which Perplexity renders in a Radix popper at the body root.\n */\n removeSources(html: string): string {\n return html;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, text } = this.extractContent(response);\n\n if (!html) {\n throw new Error(\"No HTML content found in Perplexity response\");\n }\n\n let finalHtml = html;\n\n const removeHeader = options?.removeHeader ?? false;\n const removeFooter = options?.removeFooter ?? false;\n\n // Sanitize HTML\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Fix collapsed answer container: Perplexity uses JS animation to expand the\n // answer area from height:48px. Without scripts, it stays collapsed.\n finalHtml = finalHtml.replace(\n /style=\"transition: none; overflow: hidden; height: 48px;\"/gi,\n ''\n );\n\n // Strip inline padding-right used for the sources sidecar panel\n // (e.g. padding-right: 500px) which squeezes content when sources are removed\n finalHtml = finalHtml.replace(\n /padding-right:\\s*\\d+px/gi,\n 'padding-right: 0px'\n );\n\n // Remove header if requested\n if (removeHeader) {\n finalHtml = this.removeHeader(finalHtml);\n }\n\n // Remove sidebar if requested\n if (options?.removeSidebar) {\n finalHtml = this.removeSidebar(finalHtml);\n }\n\n // Remove footer if requested\n if (removeFooter) {\n finalHtml = this.removeFooter(finalHtml);\n }\n\n // Remove sources panel if requested\n if (options?.removeSources) {\n finalHtml = this.removeSources(finalHtml);\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n // Build CSS overrides conditionally based on which remove* options are active\n let customCSS = `\n #cookie-consent,\n [role=\"dialog\"]:has(#cookie-consent),\n div[role=\"dialog\"][class*=\"fixed\"][class*=\"bottom-2\"] {\n display: none !important;\n }\n /* Login prompts: the full-page modal and the corner card. The #root\n prefix keeps the rule above the removeSidebar layout overrides. */\n [data-type=\"portal\"]:has([data-testid=\"login-modal\"]),\n #root div[class*=\"fixed\"]:has([data-testid=\"login-modal\"]),\n div[class*=\"fixed\"]:has([data-testid=\"login-modal\"]) {\n display: none !important;\n }\n [data-radix-focus-guard] {\n display: none !important;\n }\n `;\n\n if (options?.removeSidebar) {\n customCSS += `\n [class*=\"w-sideBarWidth\"] { display: none !important; }\n #root, #root > div, #root > div > div {\n display: block !important;\n height: auto !important;\n max-height: none !important;\n width: 100% !important;\n padding: 0 !important;\n }\n main {\n display: block !important;\n height: auto !important;\n max-height: none !important;\n overflow: visible !important;\n }\n main > div {\n height: auto !important;\n overflow: visible !important;\n }\n [class*=\"scrollable-container\"] {\n height: auto !important;\n overflow: visible !important;\n }\n [class*=\"max-w-threadContentWidth\"] {\n max-width: 100% !important;\n }\n `;\n }\n\n if (options?.removeSources) {\n customCSS += `\n div[class*=\"fixed\"][class*=\"inset-y-0\"][class*=\"right-0\"],\n [data-radix-popper-content-wrapper] {\n display: none !important;\n }\n `;\n }\n\n if (removeFooter) {\n customCSS += `\n [class*=\"bottom-safeAreaInsetBottom\"] {\n display: none !important;\n }\n `;\n }\n\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n text,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n linksRemoved: options?.removeLinks || false,\n headerRemoved: removeHeader,\n footerRemoved: removeFooter,\n sidebarRemoved: options?.removeSidebar || false,\n cookieBannerRemoved: true,\n sourcesRemoved: options?.removeSources || false,\n } as ProviderMetadata,\n };\n }\n}\n","import { BaseProvider } from './base-provider';\nimport { AIProvider, ParsedResponse, ParseOptions, ContentExtraction, ProviderMetadata } from '../core/types';\n\n/**\n * @deprecated cloro discontinues its Copilot endpoint. For Bing's AI answers,\n * use `BingAiModeProvider` (`BING_AIMODE`).\n */\nexport class CopilotProvider extends BaseProvider {\n readonly name: AIProvider = 'COPILOT';\n readonly baseUrl = 'https://copilot.microsoft.com';\n\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response);\n }\n\n /**\n * Remove Copilot header/navbar from HTML\n */\n removeHeader(html: string): string {\n let cleaned = html;\n\n // Remove settings wrapper (share/settings buttons in top-right corner)\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*absolute flex end-6 origin-top-right flex-col items-end[^\"]*\"[^>]*data-testid=\"settings-wrapper\"[^>]*>.*?<\\/div><\\/div>/gis, '');\n\n return cleaned;\n }\n\n /**\n * Remove Copilot footer/followup input box from HTML\n */\n removeFooter(html: string): string {\n let cleaned = html;\n\n // Remove the composer (input box at bottom)\n // Starts with: <div class=\"absolute bottom-0 w-full\">\n // Contains: file input, composer content with textarea, buttons (home, attach, chat mode, audio call)\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*absolute bottom-0 w-full[^\"]*\"[^>]*>.*?<\\/div><\\/div><\\/div><\\/div><\\/div><\\/div><\\/div><\\/div><\\/div><\\/div><\\/div><\\/div>/gis, '');\n\n // Remove spacer div for composer height\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*mt-\\[var\\(--composer-container-height\\)\\][^\"]*\"[^>]*><\\/div>/gis, '');\n\n // Remove \"scroll to bottom\" button (full container with button and inner content)\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*pointer-events-none absolute flex justify-center z-20 inset-x-0 bottom-\\[calc\\(var\\(--composer-container-height\\)\\+1rem\\)\\][^\"]*\"[^>]*>.*?<button[^>]*data-testid=\"scroll-to-bottom-button\"[^>]*>.*?<\\/button><\\/div>/gis, '');\n\n return cleaned;\n }\n\n /**\n * Remove Copilot cookie banner from HTML\n */\n removeCookieBanner(html: string): string {\n let cleaned = html;\n\n // Remove cookie banner by id\n cleaned = cleaned.replace(/<div[^>]*id=\"cookie-banner\"[^>]*>.*?<\\/div>.*?<\\/div>.*?<\\/div>.*?<\\/div>/gis, '');\n\n // Remove cookie banner by max-w-cookie-banner class (outer container)\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*max-w-cookie-banner[^\"]*\"[^>]*>.*?<\\/div>.*?<\\/div>.*?<\\/div>.*?<\\/div>/gis, '');\n\n return cleaned;\n }\n\n /**\n * Remove Copilot sources/references panel from HTML\n */\n removeSources(html: string): string {\n // Remove the references panel (right-side panel with variable width containing citations)\n return html.replace(/<div[^>]*class=\"[^\"]*relative h-full overflow-hidden will-change-auto[^\"]*\"[^>]*style=\"[^\"]*width:\\s*\\d+px[^\"]*\"[^>]*>[\\s\\S]*?(?=<div[^>]*class=\"[^\"]*pointer-events-none (?:fixed|absolute)[^\"]*\")/gi, '');\n }\n\n /**\n * Remove Copilot sidebar from HTML\n */\n removeSidebar(html: string): string {\n // Handled with CSS in parse(). The sidebar shares a flex wrapper with\n // <main>, and a regex removes the opening tag of that wrapper.\n return html;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, text } = this.extractContent(response);\n\n if (!html) {\n throw new Error('No HTML content found in Copilot response');\n }\n\n let finalHtml = html;\n\n const removeHeader = options?.removeHeader ?? false;\n const removeFooter = options?.removeFooter ?? false;\n\n // Sanitize HTML\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Remove cookie banner (always)\n finalHtml = this.removeCookieBanner(finalHtml);\n\n // Remove header if requested\n if (removeHeader) {\n finalHtml = this.removeHeader(finalHtml);\n }\n\n // Remove footer if requested\n if (removeFooter) {\n finalHtml = this.removeFooter(finalHtml);\n }\n\n // Remove sidebar if requested\n if (options?.removeSidebar) {\n finalHtml = this.removeSidebar(finalHtml);\n }\n\n // Remove sources/references panel if requested\n if (options?.removeSources) {\n finalHtml = this.removeSources(finalHtml);\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n let customCSS = '';\n\n if (removeHeader) {\n customCSS += `\n [data-testid=\"sticky-header\"],\n [data-testid=\"backstage-chats\"],\n div:has(> div > [data-testid=\"date-divider\"]) {\n display: none !important;\n }\n `;\n }\n\n if (options?.removeSidebar) {\n customCSS += `\n div:has(> #sidebar-container) { display: none !important; }\n `;\n }\n\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n text,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n cookieBannerRemoved: true,\n headerRemoved: removeHeader,\n footerRemoved: removeFooter,\n sidebarRemoved: options?.removeSidebar || false,\n sourcesRemoved: options?.removeSources || false,\n linksRemoved: options?.removeLinks || false,\n } as ProviderMetadata,\n };\n }\n}","import { BaseProvider } from \"./base-provider\";\nimport {\n AIProvider,\n ParsedResponse,\n ParseOptions,\n ContentExtraction,\n ProviderMetadata,\n} from \"../core/types\";\n\nexport class AIOverviewProvider extends BaseProvider {\n readonly name: AIProvider = \"AIOVERVIEW\";\n readonly baseUrl = \"https://www.google.com\";\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response, true);\n }\n\n /**\n * Remove Google Search header/navbar from HTML\n */\n removeHeader(html: string): string {\n // Remove header elements via CSS injection\n return html;\n }\n\n /**\n * Remove Google Search footer from HTML\n */\n removeFooter(html: string): string {\n // Remove footer elements via CSS injection\n return html;\n }\n\n /**\n * Remove Google Search sidebar from HTML\n */\n removeSidebar(html: string): string {\n // Remove sidebar elements via CSS injection\n return html;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, sources } = this.extractContent(response);\n\n if (!html) {\n throw new Error(\"No HTML content found in AI Overview response\");\n }\n\n let finalHtml = html;\n\n // For AI Overview, default to removing header and footer for cleaner display\n const removeHeader = options?.removeHeader ?? true;\n const removeFooter = options?.removeFooter ?? true;\n\n // Sanitize HTML\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Remove header if requested\n if (removeHeader) {\n finalHtml = this.removeHeader(finalHtml);\n }\n\n // Remove footer if requested\n if (removeFooter) {\n finalHtml = this.removeFooter(finalHtml);\n }\n\n // Remove sidebar if requested\n if (options?.removeSidebar) {\n finalHtml = this.removeSidebar(finalHtml);\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n // Build CSS based on options\n let stylesToInject = \"\";\n\n // Header removal styles\n if (removeHeader) {\n stylesToInject += `\n /* Header hiding */\n header, #header, #searchform, .sfbg, #appbar,\n div[role=\"navigation\"], #leftnav, #sidetogether,\n [role=\"banner\"], .Fgvgjc, #hdtb, .hdtb-msb,\n .DZ13He, .wYq63b, .eT9Cje, .bNg8Rb, .S6VXfe, .Lu57id {\n display: none !important;\n }\n `;\n }\n\n // Sidebar removal styles\n if (options?.removeSidebar) {\n stylesToInject += `\n /* Sidebar hiding */\n #leftnav, #sidetogether {\n display: none !important;\n }\n `;\n }\n\n // Footer removal styles\n if (removeFooter) {\n stylesToInject += `\n /* Footer hiding */\n footer, #footer, #sfooter, .fbar,\n .pdp-nav, [aria-label=\"Main menu\"], .gb_Td, .gb_L {\n display: none !important;\n }\n `;\n }\n\n // Inject base URL and styles\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS: stylesToInject,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n sources,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n headerRemoved: removeHeader,\n footerRemoved: removeFooter,\n sidebarRemoved: options?.removeSidebar || false,\n linksRemoved: options?.removeLinks || false,\n } as ProviderMetadata,\n };\n }\n}\n","import { BaseProvider } from \"./base-provider\";\nimport {\n AIProvider,\n ParsedResponse,\n ParseOptions,\n ContentExtraction,\n ProviderMetadata,\n} from \"../core/types\";\n\nexport class AIModeProvider extends BaseProvider {\n readonly name: AIProvider = \"AIMODE\";\n readonly baseUrl = \"https://www.google.com\";\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response);\n }\n\n /**\n * Remove Google Search header/navbar from HTML\n */\n removeHeader(html: string): string {\n let cleaned = html;\n\n // Remove the AI Mode filter/header bar\n // Starts with <div jsname=\"oEQ3x\" class=\"DZ13He YNk70c EjQTId\">\n // Contains the Filters and Topics navigation (AI Mode, All, Images, Videos, News, More)\n // Ends with closing divs after <hr class=\"e9c7U\">\n cleaned = cleaned.replace(\n /<div[^>]*jsname=\"oEQ3x\"[^>]*class=\"[^\"]*DZ13He[^\"]*\"[^>]*>.*?<hr class=\"e9c7U\">.*?<\\/div><\\/div><\\/div><\\/div><\\/div>/gis,\n \"\"\n );\n\n return cleaned;\n }\n\n /**\n * Remove Google Search footer from HTML\n */\n removeFooter(html: string): string {\n let cleaned = html;\n\n // Remove the AI Mode input bar/footer\n // Target the most unique identifier: data-xid=\"aim-mars-input-plate\"\n // This element is deeply nested, so we need to match many closing divs\n cleaned = cleaned.replace(\n /<div[^>]*data-xid=\"aim-mars-input-plate\"[^>]*>[\\s\\S]*?<\\/div><\\/div><\\/div><\\/div><\\/div>/gis,\n \"\"\n );\n\n // Fallback: Target by jscontroller P5gZDb which wraps the input plate\n cleaned = cleaned.replace(\n /<div[^>]*jscontroller=\"P5gZDb\"[^>]*>[\\s\\S]*?<\\/div><\\/div><\\/div>/gis,\n \"\"\n );\n\n // Fallback: Target the t0ITR container\n cleaned = cleaned.replace(\n /<div[^>]*class=\"[^\"]*t0ITR hh3ttd[^\"]*\"[^>]*>[\\s\\S]*?<\\/div><\\/div>/gis,\n \"\"\n );\n\n // Fallback: Target outer y4VEUd vve6Ce wrapper\n cleaned = cleaned.replace(\n /<div[^>]*class=\"[^\"]*y4VEUd vve6Ce[^\"]*\"[^>]*>[\\s\\S]*?<\\/div><\\/div>/gis,\n \"\"\n );\n\n return cleaned;\n }\n\n /**\n * Remove Google Search sidebar from HTML\n */\n removeSidebar(html: string): string {\n let cleaned = html;\n\n // Remove the AI Mode history panel/dialog\n // Target by aria-label (handles both attribute orderings)\n cleaned = cleaned.replace(\n /<div[^>]*aria-label=\"AI Mode history\"[^>]*class=\"[^\"]*ho072b[^\"]*\"[^>]*>[\\s\\S]*?(?=<!--TgQPHd)/gi,\n \"\"\n );\n // Fallback: class before aria-label\n cleaned = cleaned.replace(\n /<div[^>]*class=\"[^\"]*ho072b[^\"]*\"[^>]*aria-label=\"AI Mode history\"[^>]*>[\\s\\S]*?(?=<!--TgQPHd)/gi,\n \"\"\n );\n\n // Remove the floating action buttons (OEwhSe wrapper)\n cleaned = cleaned.replace(\n /<div[^>]*class=\"[^\"]*OEwhSe[^\"]*\"[^>]*>[\\s\\S]*?<\\/div><\\/div>/gis,\n \"\"\n );\n\n // Remove buttons with aria-label\n cleaned = cleaned.replace(\n /<button[^>]*aria-label=\"AI Mode history\"[^>]*>[\\s\\S]*?<\\/button>/gis,\n \"\"\n );\n\n return cleaned;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, text } = this.extractContent(response);\n\n if (!html) {\n throw new Error(\"No HTML content found in AI Mode response\");\n }\n\n let finalHtml = html;\n\n // For AI Mode, default to removing header and footer for cleaner display\n const removeHeader = options?.removeHeader ?? true;\n const removeFooter = options?.removeFooter ?? true;\n\n // Sanitize HTML\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Remove header if requested\n if (removeHeader) {\n finalHtml = this.removeHeader(finalHtml);\n }\n\n // Remove footer if requested\n if (removeFooter) {\n finalHtml = this.removeFooter(finalHtml);\n }\n\n // Remove sidebar if requested\n if (options?.removeSidebar) {\n finalHtml = this.removeSidebar(finalHtml);\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n // Build CSS based on options\n let stylesToInject = \"\";\n\n // Always inject general layout\n /* Remove cookie consent banner */\n stylesToInject += `\n .KxvlWc, #CXQnmb {\n display: none !important;\n }\n `;\n\n // Header removal styles\n if (removeHeader) {\n stylesToInject += `\n /* Header hiding */\n header, #header, #searchform, .sfbg, #appbar,\n div[role=\"navigation\"], #leftnav, #sidetogether,\n [role=\"banner\"], .Fgvgjc, #hdtb, .hdtb-msb,\n .DZ13He, .wYq63b, .eT9Cje, .bNg8Rb, .S6VXfe, .Lu57id,\n .YHsVn, .UTNPFf {\n display: none !important;\n }\n `;\n }\n\n // Footer removal styles\n if (removeFooter) {\n stylesToInject += `\n /* Footer hiding */\n footer, #footer, .fbar,\n .pdp-nav, [aria-label=\"Main menu\"], .gb_Td, .gb_L {\n display: none !important;\n }\n /* Hide the \"Ask anything\" input bar */\n [data-xid=\"aim-mars-input-plate\"],\n .UAbVe, .y4VEUd, .t0ITR.hh3ttd {\n display: none !important;\n }\n `;\n }\n\n // Sidebar removal styles\n if (options?.removeSidebar) {\n stylesToInject += `\n /* Hide AI Mode history panel */\n .ho072b, .OEwhSe, .qEn1od {\n display: none !important;\n }\n `;\n }\n\n // Inject base URL and styles\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS: stylesToInject,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n text,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n headerRemoved: removeHeader,\n footerRemoved: removeFooter,\n sidebarRemoved: options?.removeSidebar || false,\n linksRemoved: options?.removeLinks || false,\n } as ProviderMetadata,\n };\n }\n}\n","import { BaseProvider } from './base-provider';\nimport { AIProvider, ParsedResponse, ParseOptions, ContentExtraction, ProviderMetadata } from '../core/types';\n\n/**\n * Bing AI Mode (bing.com/copilotsearch).\n *\n * The page that cloro stores is Bing's chat shell. The answer is inside an\n * `<iframe srcdoc>` that an inline `onload` script sizes to its content. With\n * scripts blocked (a sandboxed preview, or this parser, which removes\n * scripts), the frame stays 150px high and shows only the first sentence. So\n * this provider renders the frame's own document, which holds the whole\n * answer: the reasoning panel, the answer, the citation chips and the source\n * cards.\n */\nexport class BingAiModeProvider extends BaseProvider {\n readonly name: AIProvider = 'BING_AIMODE';\n readonly baseUrl = 'https://www.bing.com';\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response);\n }\n\n /**\n * The document in the answer frame's `srcdoc`, or the input when the page\n * has no such frame (for example, when it is already the answer document).\n */\n answerDocument(html: string): string {\n const match = /<iframe\\b[^>]*\\ssrcdoc=\"([^\"]*)\"/i.exec(html);\n if (!match) return html;\n return match[1]\n .replace(/"/g, '\"')\n .replace(/�*39;/g, \"'\")\n .replace(/�*27;/gi, \"'\")\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/&/g, '&');\n }\n\n /** The prompt, from the question bubble in the shell. */\n userQuery(html: string): string | null {\n const match = /<div\\b[^>]*class=\"ca_userquery_text\"[^>]*>([^<]*)<\\/div>/i.exec(html);\n return match ? match[1].trim() : null;\n }\n\n /** Put the question above the answer, as the shell shows it. */\n addQuery(html: string, query: string | null): string {\n if (!query) return html;\n const bubble = `<div class=\"cloro_bing_query\">${query}</div>`;\n return /<body\\b[^>]*>/i.test(html)\n ? html.replace(/(<body\\b[^>]*>)/i, `$1${bubble}`)\n : bubble + html;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, text } = this.extractContent(response);\n\n if (!html) {\n throw new Error('No HTML content found in Bing AI Mode response');\n }\n\n const removeHeader = options?.removeHeader ?? false;\n const removeSources = options?.removeSources ?? false;\n\n const query = this.userQuery(html);\n let finalHtml = this.addQuery(this.sanitizeHtml(this.answerDocument(html)), query);\n\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n // Bing sets overflow: hidden on <html>, because in Bing the frame grows to\n // its content and the shell scrolls. In a fixed-height view the answer\n // must scroll itself. The column and the question bubble copy the shell.\n // The reasoning panel's favicons are blob: URLs from Bing's session, so\n // they are hidden. The panel's toggle needs a script, so the panel is\n // open and the toggle is hidden.\n let customCSS = `\n html { overflow: auto !important; height: auto !important; }\n body { max-width: 880px; margin: 0 auto !important; padding: 24px 24px 48px !important; box-sizing: border-box; }\n .cloro_bing_query { width: fit-content; max-width: 80%; margin: 0 0 16px; padding: 10px 16px; border-radius: 16px; background: #e8f1fd; color: #111; font: 16px/1.5 \"Segoe UI\", -apple-system, system-ui, sans-serif; }\n .b_ts_source_fav:has(img[src^=\"blob:\"]) { display: none !important; }\n #b_ts_exp_content { display: block !important; height: auto !important; max-height: none !important; overflow: visible !important; opacity: 1 !important; }\n .b_ts_exp_header { display: none !important; }\n `;\n\n // The header is the reasoning panel (\"See reasoning\") above the answer.\n if (removeHeader) {\n customCSS += `\n .b_ts_container { display: none !important; }\n `;\n }\n\n // The sources are the cards below the answer and the \"N Sources\" group\n // under each section. The citation chips in the text (.gs_sup_cit) stay.\n if (removeSources) {\n customCSS += `\n .gs_cit_cont, .gs_cit_stry_preview { display: none !important; }\n `;\n }\n\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n text,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n headerRemoved: removeHeader,\n // The answer document has no footer or sidebar. The follow-up box and\n // the side rail are in the shell that this provider drops.\n footerRemoved: true,\n sidebarRemoved: true,\n sourcesRemoved: removeSources,\n linksRemoved: options?.removeLinks || false,\n } as ProviderMetadata,\n };\n }\n}\n","import { BaseProvider } from \"./base-provider\";\nimport {\n AIProvider,\n ParsedResponse,\n ParseOptions,\n ContentExtraction,\n ProviderMetadata,\n} from \"../core/types\";\n\nexport class GrokProvider extends BaseProvider {\n readonly name: AIProvider = \"GROK\";\n readonly baseUrl = \"https://grok.com\";\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response);\n }\n\n /**\n * Remove Grok header from HTML (using CSS-based hiding)\n */\n removeHeader(html: string): string {\n // Header removal is now done via CSS in the parse method\n return html;\n }\n\n /**\n * Remove Grok footer/input area from HTML (using CSS-based hiding)\n */\n removeFooter(html: string): string {\n // Footer removal is now done via CSS in the parse method\n return html;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, text } = this.extractContent(response);\n\n if (!html) {\n throw new Error(\"No HTML content found in Grok response\");\n }\n\n let finalHtml = html;\n\n // Sanitize HTML\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Build CSS based on options\n let stylesToInject = '';\n\n // Always-on: hide cookie/privacy policy banner (Grok uses data-cookie-banner attribute)\n stylesToInject += `\n [data-cookie-banner],\n [data-cookie-banner=\"true\"] {\n display: none !important;\n }\n `;\n\n // Always-on: hide rate-limit banners and toast notifications\n stylesToInject += `\n [data-sonner-toaster],\n [data-sonner-toast],\n [class*=\"sonner-toast\"] {\n display: none !important;\n }\n `;\n\n // Sources panel removal via regex (CSS selectors don't reliably hide this element)\n if (options?.removeSources) {\n // Remove the sources panel wrapper containing the aside\n finalHtml = finalHtml.replace(/<div[^>]*class=\"[^\"]*h-dvh[^\"]*flex-shrink-0[^\"]*max-w-[^\"]*\"[^>]*>[\\s\\S]*?<\\/aside>[\\s\\S]*?(?=<section)/gi, '');\n\n // Hide the inline \"N sources\" trigger button and vaul-drawer overlay via CSS\n stylesToInject += `\n div[data-state] > div.flex.flex-row.gap-1.items-center.rounded-full.cursor-pointer {\n display: none !important;\n }\n [vaul-drawer][vaul-drawer-direction=\"right\"],\n [vaul-overlay] {\n display: none !important;\n }\n `;\n }\n\n // Header hiding via CSS\n if (options?.removeHeader) {\n stylesToInject += `\n /* Header hiding - hide elements with Grok's header class pattern */\n div[class*=\"h-16\"][class*=\"top-0\"][class*=\"z-10\"],\n div[class*=\"absolute\"][class*=\"inset-x-0\"][class*=\"top-0\"] {\n display: none !important;\n }\n `;\n }\n\n // Footer hiding via CSS\n if (options?.removeFooter) {\n stylesToInject += `\n /* Footer hiding - hide Grok's footer/input area */\n div[class*=\"absolute\"][class*=\"inset-x-0\"][class*=\"bottom-0\"][class*=\"max-w-breakout\"],\n div[class*=\"absolute\"][class*=\"bottom-0\"][class*=\"w-full\"] {\n display: none !important;\n }\n `;\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS: stylesToInject,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n text,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n linksRemoved: options?.removeLinks || false,\n headerRemoved: options?.removeHeader || false,\n footerRemoved: options?.removeFooter || false,\n cookieBannerRemoved: true,\n sourcesRemoved: options?.removeSources || false,\n } as ProviderMetadata,\n };\n }\n}\n","import { AIProvider, ParsedResponse, ParseOptions, extractContentCommon } from './types';\nimport { ProviderDetector } from './detector';\nimport { ChatGPTProvider } from '../providers/chatgpt';\nimport { GeminiProvider } from '../providers/gemini';\nimport { PerplexityProvider } from '../providers/perplexity';\nimport { CopilotProvider } from '../providers/copilot';\nimport { AIOverviewProvider } from '../providers/ai-overview';\nimport { AIModeProvider } from '../providers/ai-mode';\nimport { BingAiModeProvider } from '../providers/bing-ai-mode';\nimport { GrokProvider } from '../providers/grok';\n\nexport class AIResponseParser {\n private providers: Map<AIProvider, any> = new Map();\n\n constructor() {\n this.providers.set('CHATGPT', new ChatGPTProvider());\n this.providers.set('GEMINI', new GeminiProvider());\n this.providers.set('PERPLEXITY', new PerplexityProvider());\n this.providers.set('COPILOT', new CopilotProvider());\n this.providers.set('AIOVERVIEW', new AIOverviewProvider());\n this.providers.set('AIMODE', new AIModeProvider());\n this.providers.set('BING_AIMODE', new BingAiModeProvider());\n this.providers.set('GROK', new GrokProvider());\n }\n\n /**\n * Parse an AI response with auto-detected provider\n */\n parse(response: any, options?: ParseOptions): ParsedResponse | null {\n const detection = ProviderDetector.detect(response);\n\n if (!detection) {\n // Try to parse as generic HTML if no provider detected\n return this.parseGeneric(response);\n }\n\n const provider = this.providers.get(detection.provider);\n if (!provider) {\n return null;\n }\n\n try {\n const parsed = provider.parse(response, options);\n return {\n ...parsed,\n metadata: {\n ...parsed.metadata,\n detectionConfidence: detection.confidence,\n },\n };\n } catch (error) {\n console.error(`Failed to parse response with ${detection.provider}:`, error);\n return null;\n }\n }\n\n /**\n * Parse with explicit provider specification\n */\n parseWithProvider(\n response: any,\n provider: AIProvider,\n options?: ParseOptions\n ): ParsedResponse | null {\n const providerInstance = this.providers.get(provider);\n if (!providerInstance) {\n throw new Error(`Unknown provider: ${provider}`);\n }\n\n try {\n return providerInstance.parse(response, options);\n } catch (error) {\n console.error(`Failed to parse response with ${provider}:`, error);\n return null;\n }\n }\n\n /**\n * Detect the provider from a response\n */\n detectProvider(response: any): AIProvider | null {\n const detection = ProviderDetector.detect(response);\n return detection?.provider || null;\n }\n\n /**\n * Get all possible providers with confidence scores\n */\n detectAllProviders(response: any): Array<{ provider: AIProvider; confidence: number }> {\n return ProviderDetector.getAllProviders(response);\n }\n\n /**\n * Parse as generic HTML when no specific provider is detected\n */\n private parseGeneric(response: any): ParsedResponse | null {\n const { html, text } = extractContentCommon(response);\n\n if (!html && !text) {\n return null;\n }\n\n // Basic sanitization\n let sanitizedHtml = html;\n if (sanitizedHtml) {\n sanitizedHtml = sanitizedHtml.replace(/<script\\b[^>]*>[\\s\\S]*?<\\/script>/gim, '');\n sanitizedHtml = sanitizedHtml.replace(/<noscript[\\s\\S]*?<\\/noscript>/gi, '');\n }\n\n return {\n provider: 'CHATGPT' as AIProvider, // Default to ChatGPT for unknown\n html: sanitizedHtml || '',\n text: text || '',\n metadata: {\n isGeneric: true,\n },\n };\n }\n\n /**\n * Get list of supported providers\n */\n getSupportedProviders(): AIProvider[] {\n return Array.from(this.providers.keys());\n }\n\n /**\n * Register a custom provider\n */\n registerProvider(provider: AIProvider, instance: any): void {\n this.providers.set(provider, instance);\n }\n}\n\n// Export a singleton instance\nexport const parser = new AIResponseParser();\n\n// Convenience functions\nexport const parseAiResponse = (response: any, options?: ParseOptions) =>\n parser.parse(response, options);\n\nexport const detectProvider = (response: any) =>\n parser.detectProvider(response);"],"names":["extractContentCommon","response","html","text","dataToCheck","result","trim","startsWith","includes","content","ProviderDetector","detect","scores","CHATGPT","GEMINI","PERPLEXITY","COPILOT","AIOVERVIEW","AIMODE","BING_AIMODE","GROK","provider","patterns","Object","entries","this","PROVIDER_PATTERNS","pattern","_a","maxScore","detectedProvider","score","confidence","values","reduce","a","b","Math","max","getAllProviders","providers","matches","push","length","sort","validate","detected","_b","aioverview","_c","BaseProvider","includeSources","sources","injectStyles","options","styledHtml","baseUrl","replace","styles","customCSS","sanitizeHtml","sanitized","isFullDocument","test","removeLinks","wrapFragment","ChatGPTProvider","constructor","name","extractContent","match","attributes","cleanedAttrs","removeHeader","cleaned","removeSidebar","removeFooter","removeCookieBanner","removeSources","parse","Error","finalHtml","metadata","cookieBannerRemoved","headerRemoved","sidebarRemoved","footerRemoved","sourcesRemoved","linksRemoved","GeminiProvider","PerplexityProvider","_html","CopilotProvider","AIOverviewProvider","stylesToInject","AIModeProvider","BingAiModeProvider","answerDocument","exec","userQuery","addQuery","query","bubble","GrokProvider","AIResponseParser","Map","set","detection","parseGeneric","get","parsed","detectionConfidence","error","console","parseWithProvider","providerInstance","detectProvider","detectAllProviders","sanitizedHtml","isGeneric","getSupportedProviders","Array","from","keys","registerProvider","instance","parser","parseAiResponse"],"mappings":"AAkEM,SAAUA,EAAqBC,GACnC,IAAIC,EAAO,GACPC,EAAO,GAGPC,EAAcH,EA0BlB,OAzBIA,EAASI,SACXD,EAAcH,EAASI,QAIE,iBAAhBD,EACLA,EAAYE,OAAOC,WAAW,MAAQH,EAAYI,SAAS,KAC7DN,EAAOE,EAEPD,EAAOC,EAEuB,iBAAhBA,GAA4C,OAAhBA,IACxCA,EAAYF,KACdA,EAAOE,EAAYF,KACVE,EAAYK,QACjBL,EAAYK,QAAQH,OAAOC,WAAW,KACxCL,EAAOE,EAAYK,QAEnBN,EAAOC,EAAYK,QAEZL,EAAYD,OACrBA,EA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AiB6B,gBAAgBtC,EAC1C,CAKQ,YAAA2G,CAAa3G,GACnB,MAAMC,KAAEA,EAAIC,KAAEA,GAASH,EAAqBC,GAE5C,IAAKC,IAASC,EACZ,OAAO,KAIT,IAAImH,EAAgBpH,EAMpB,OALIoH,IACFA,EAAgBA,EAAc7D,QAAQ,uCAAwC,IAC9E6D,EAAgBA,EAAc7D,QAAQ,kCAAmC,KAGpE,CACLpC,SAAU,UACVnB,KAAMoH,GAAiB,GACvBnH,KAAMA,GAAQ,GACd+E,SAAU,CACRqC,WAAW,GAGjB,CAKA,qBAAAC,GACE,OAAOC,MAAMC,KAAKjG,KAAKe,UAAUmF,OACnC,CAKA,gBAAAC,CAAiBvG,EAAsBwG,GACrCpG,KAAKe,UAAUkE,IAAIrF,EAAUwG,EAC/B,EAIK,MAAMC,EAAS,IAAItB,EAGbuB,EAAkB,CAAC9H,EAAeqD,IAC7CwE,EAAO/C,MAAM9E,EAAUqD,GAEZ8D,EAAkBnH,GAC7B6H,EAAOV,eAAenH"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BaseProvider } from './base-provider';
|
|
2
|
+
import { AIProvider, ParsedResponse, ParseOptions, ContentExtraction } from '../core/types';
|
|
3
|
+
/**
|
|
4
|
+
* Bing AI Mode (bing.com/copilotsearch).
|
|
5
|
+
*
|
|
6
|
+
* The page that cloro stores is Bing's chat shell. The answer is inside an
|
|
7
|
+
* `<iframe srcdoc>` that an inline `onload` script sizes to its content. With
|
|
8
|
+
* scripts blocked (a sandboxed preview, or this parser, which removes
|
|
9
|
+
* scripts), the frame stays 150px high and shows only the first sentence. So
|
|
10
|
+
* this provider renders the frame's own document, which holds the whole
|
|
11
|
+
* answer: the reasoning panel, the answer, the citation chips and the source
|
|
12
|
+
* cards.
|
|
13
|
+
*/
|
|
14
|
+
export declare class BingAiModeProvider extends BaseProvider {
|
|
15
|
+
readonly name: AIProvider;
|
|
16
|
+
readonly baseUrl = "https://www.bing.com";
|
|
17
|
+
extractContent(response: any): ContentExtraction;
|
|
18
|
+
/**
|
|
19
|
+
* The document in the answer frame's `srcdoc`, or the input when the page
|
|
20
|
+
* has no such frame (for example, when it is already the answer document).
|
|
21
|
+
*/
|
|
22
|
+
answerDocument(html: string): string;
|
|
23
|
+
/** The prompt, from the question bubble in the shell. */
|
|
24
|
+
userQuery(html: string): string | null;
|
|
25
|
+
/** Put the question above the answer, as the shell shows it. */
|
|
26
|
+
addQuery(html: string, query: string | null): string;
|
|
27
|
+
parse(response: any, options?: ParseOptions): ParsedResponse;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=bing-ai-mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bing-ai-mode.d.ts","sourceRoot":"","sources":["../../src/providers/bing-ai-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,iBAAiB,EAAoB,MAAM,eAAe,CAAC;AAE9G;;;;;;;;;;GAUG;AACH,qBAAa,kBAAmB,SAAQ,YAAY;IAClD,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAiB;IAC1C,QAAQ,CAAC,OAAO,0BAA0B;IAE1C,cAAc,CAAC,QAAQ,EAAE,GAAG,GAAG,iBAAiB;IAIhD;;;OAGG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAYpC,yDAAyD;IACzD,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAKtC,gEAAgE;IAChE,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM;IAQpD,KAAK,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,cAAc;CAoE7D"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { BaseProvider } from './base-provider';
|
|
2
2
|
import { AIProvider, ParsedResponse, ParseOptions, ContentExtraction } from '../core/types';
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated cloro discontinues its Copilot endpoint. For Bing's AI answers,
|
|
5
|
+
* use `BingAiModeProvider` (`BING_AIMODE`).
|
|
6
|
+
*/
|
|
3
7
|
export declare class CopilotProvider extends BaseProvider {
|
|
4
8
|
readonly name: AIProvider;
|
|
5
9
|
readonly baseUrl = "https://copilot.microsoft.com";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copilot.d.ts","sourceRoot":"","sources":["../../src/providers/copilot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,iBAAiB,EAAoB,MAAM,eAAe,CAAC;AAE9G,qBAAa,eAAgB,SAAQ,YAAY;IAC/C,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAa;IACtC,QAAQ,CAAC,OAAO,mCAAmC;IAGnD,cAAc,CAAC,QAAQ,EAAE,GAAG,GAAG,iBAAiB;IAIhD;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IASlC;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAiBlC;;OAEG;IACH,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAYxC;;OAEG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAKnC;;OAEG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAMnC,KAAK,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,cAAc;CAiF7D"}
|
|
1
|
+
{"version":3,"file":"copilot.d.ts","sourceRoot":"","sources":["../../src/providers/copilot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,iBAAiB,EAAoB,MAAM,eAAe,CAAC;AAE9G;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,YAAY;IAC/C,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAa;IACtC,QAAQ,CAAC,OAAO,mCAAmC;IAGnD,cAAc,CAAC,QAAQ,EAAE,GAAG,GAAG,iBAAiB;IAIhD;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IASlC;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAiBlC;;OAEG;IACH,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAYxC;;OAEG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAKnC;;OAEG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAMnC,KAAK,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,cAAc;CAiF7D"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloro-dev/response-parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Parse and render AI model responses from ChatGPT, Gemini, Perplexity, and more",
|
|
5
|
+
"description": "Parse and render AI model responses from ChatGPT, Gemini, Perplexity, Google AI Mode, Bing AI Mode, and more",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.esm.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"chatgpt",
|
|
32
32
|
"gemini",
|
|
33
33
|
"perplexity",
|
|
34
|
-
"
|
|
34
|
+
"bing",
|
|
35
35
|
"html-parser",
|
|
36
36
|
"typescript",
|
|
37
37
|
"framework-agnostic"
|