/** * Badgr Integration - Manages AI Badgr signup and configuration * * Handles: * - Detecting when gateway-layer solutions are needed * - Opening signup page * - Collecting API key * - Patching code for Badgr integration * - Running before/after verification */ import { ScanIssue } from './scanner'; export interface BadgrRecommendation { recommended: boolean; reasons: string[]; gatewayIssues: ScanIssue[]; } export interface BadgrIntegrationMode { mode: 'fallback' | 'full-switch' | 'test-only' | 'none'; description: string; } export interface VerificationResult { before: { ttfb_ms: number; total_time_ms: number; errors_429: number; estimated_cost: number; }; after: { ttfb_ms: number; total_time_ms: number; errors_429: number; estimated_cost: number; receipt_ids: string[]; }; improvement: { ttfb_improvement: string; time_improvement: string; errors_prevented: number; cost_savings: string; }; } /** * Determine if AI Badgr should be recommended */ export declare function shouldRecommendBadgr(localIssues: ScanIssue[], gatewayIssues: ScanIssue[]): BadgrRecommendation; /** * Print Badgr recommendation */ export declare function printBadgrRecommendation(recommendation: BadgrRecommendation): void; /** * Prompt user for Badgr integration mode */ export declare function promptBadgrIntegration(): Promise; /** * Prompt for Badgr integration after successful test */ export declare function promptBadgrIntegrationAfterTest(): Promise; /** * Open signup page in browser */ export declare function openSignupPage(): Promise; /** * Prompt for API key (hidden input) */ export declare function promptApiKey(): Promise; /** * Apply Badgr configuration to codebase */ export declare function applyBadgrConfig(mode: 'fallback' | 'full-switch' | 'test-only', apiKey: string, provider: string): Promise<{ success: boolean; message: string; filesModified: string[]; }>; /** * Run a non-destructive Badgr test without modifying any files * This is completely in-memory and safe */ export declare function runBadgrTestOnly(apiKey: string): Promise<{ success: boolean; message: string; receiptId?: string; }>; /** * Run before/after verification */ export declare function runVerification(provider: string, originalApiKey: string, badgrApiKey: string): Promise; /** * Print verification results */ export declare function printVerificationResults(result: VerificationResult): void; /** * Information about the detected project stack and environment */ export interface StackInfo { language: 'node' | 'python' | 'both' | 'unknown'; sdks: string[]; envFiles: string[]; baseUrls: { file: string; url: string; }[]; currentProvider: string; } /** * User's choice on the Switch-Now main screen */ export type SwitchNowChoice = 'd1-byok' | 'd2-primary' | 'skip' | 'none'; /** * Result of a single smoke-test call */ export interface SwitchNowSmokeResult { success: boolean; ttfb_ms: number; total_ms: number; tokens: number; estimated_cost: number; receipt_id: string; receipt_url: string; } /** * Encrypt a plaintext key with AES-256-GCM using a machine-specific key. * SECURITY: Output is safe to store in config files; never log the input. * * @returns IV:authTag:ciphertext (hex-encoded, colon-separated) */ export declare function encryptKey(plaintext: string): string; /** * Decrypt a key that was encrypted with {@link encryptKey}. * Throws if the ciphertext has been tampered with (GCM auth tag failure). */ export declare function decryptKey(encrypted: string): string; /** * Store a BYOK provider key encrypted in `.ai-patch/byok.enc` inside the * project directory. The plaintext key is never written to disk. */ export declare function storeByokKeyEncrypted(providerKey: string, providerName: string, dir: string): string; /** * Preflight: check that .env (or the project directory, if .env doesn't exist * yet) is writable so we can surface a clear error before collecting keys. */ export declare function checkEnvWritable(dir: string): { ok: boolean; error?: string; }; /** * Scan the project directory and return detected stack information * (language, SDKs, .env files, existing base URLs, provider). */ export declare function detectStackInfo(dir: string): StackInfo; /** * Show the Switch-Now MVP main screen. * * Presents D1 (BYOK) and D2 (Primary) as the only visible choices. * Advanced mode ('a') is a hidden escape hatch — not shown on screen. */ export declare function promptSwitchNow(stackInfo: StackInfo): Promise; /** * Apply D1 (Always-On BYOK) configuration: * * - Sets base URL → AIBadgr /v1 in .env (passthrough=true by default) * - Stores AIBadgr API key as BADGR_API_KEY in .env * - Enables Retry-After respect, rate-limit intelligence, circuit-breaker * failover (handled server-side by AIBadgr; BADGR_PASSTHROUGH=true signals * the gateway to forward provider credentials transparently) * - Provider key (OpenAI/Anthropic/Gemini) must be set in the AIBadgr dashboard * at https://aibadgr.com/dashboard — it is never collected or stored locally */ export declare function applySwitchNowByok(badgrApiKey: string, stackInfo: StackInfo, dir: string): Promise<{ success: boolean; message: string; filesModified: string[]; previousBaseUrls: string[]; }>; /** * Apply D2 (Primary) configuration: * * - Sets base URL → AIBadgr /v1 in .env * - Stores AIBadgr API key as BADGR_API_KEY in .env * - No provider key needed */ export declare function applySwitchNowPrimary(badgrApiKey: string, stackInfo: StackInfo, dir: string): Promise<{ success: boolean; message: string; filesModified: string[]; previousBaseUrls: string[]; }>; /** * Run two smoke calls through AIBadgr /v1 and surface signed receipt data. * * Returns receipt IDs, TTFB, latency, token counts, estimated cost, and a * one-line diff showing the env-var change (before → after). * * TODO: Replace mock implementation with real HTTPS calls to BADGR_BASE_URL * using the provided badgrApiKey before shipping to production. */ export declare function runSwitchNowSmokeTests(badgrApiKey: string, provider: string, previousBaseUrl: string): Promise<{ success: boolean; calls: SwitchNowSmokeResult[]; diff: string; }>; /** * Display undo / rollback instructions so the user can trivially revert. * * Shows the exact env-var change to undo. */ export declare function showUndoInstructions(previousBaseUrls: string[], mode: 'd1-byok' | 'd2-primary', provider: string): void; //# sourceMappingURL=badgr-integration.d.ts.map