/** * Auth Flow Detector (GAP-003) * * Detects authentication challenges and triggers automatic authentication flows: * 1. HTTP 401/403 responses * 2. Redirects to login pages * 3. Session expiration detection * 4. Explicit auth requirement messages * * When a challenge is detected: * - First, try to replay a stored login workflow * - If no workflow exists, fall back to user prompt * - After successful auth, retry the original request */ import type { ProceduralMemory } from './procedural-memory.js'; import type { SessionManager } from './session-manager.js'; import type { AuthWorkflow } from './auth-workflow.js'; import type { Workflow, WorkflowVariables } from '../types/workflow.js'; /** * Types of authentication challenges that can be detected */ export type AuthChallengeType = 'http_401' | 'http_403' | 'login_redirect' | 'session_expired' | 'auth_message' | 'captcha_required'; /** * Detected authentication challenge */ export interface AuthChallenge { type: AuthChallengeType; statusCode?: number; redirectUrl?: string; originalUrl: string; domain: string; timestamp: number; message?: string; requiresUserAction?: boolean; } /** * Result of attempting to resolve an auth challenge */ export interface AuthResolutionResult { success: boolean; method: 'workflow_replay' | 'stored_credentials' | 'user_prompt' | 'skipped'; workflowId?: string; error?: string; retryRecommended: boolean; } /** * Callback for when user action is required */ export type UserAuthCallback = (challenge: AuthChallenge, domain: string, suggestedCredentialTypes: string[]) => Promise; /** * Options for auth flow detection */ export interface AuthFlowDetectorOptions { /** Enable automatic workflow replay */ autoReplayWorkflow?: boolean; /** Enable automatic credential application */ autoApplyCredentials?: boolean; /** Callback for user prompts when automation fails */ userCallback?: UserAuthCallback; /** Session profile to use */ sessionProfile?: string; } export declare class AuthFlowDetector { private proceduralMemory; private sessionManager; private authWorkflow; private options; constructor(options?: AuthFlowDetectorOptions); /** * Wire up dependencies (optional - enables full functionality) */ configure(deps: { proceduralMemory?: ProceduralMemory; sessionManager?: SessionManager; authWorkflow?: AuthWorkflow; }): void; /** * Detect if a response indicates an auth challenge */ detectFromResponse(url: string, statusCode: number, headers: Record, body?: string): AuthChallenge | null; /** * Detect auth challenge from a redirect URL */ detectFromRedirect(originalUrl: string, redirectUrl: string): AuthChallenge | null; /** * Check if session is expired for a domain */ detectExpiredSession(domain: string, profile?: string): Promise; /** * Attempt to resolve an auth challenge automatically */ resolveChallenge(challenge: AuthChallenge, variables?: WorkflowVariables): Promise; /** * Try to find a login workflow for replay * Note: Actual workflow execution should be done by the caller with proper context */ private tryLoginWorkflow; /** * Try to apply stored credentials */ private tryStoredCredentials; /** * Find a login workflow for a domain */ private findLoginWorkflow; /** * Check if a URL is a login page */ private isLoginUrl; /** * Check if response body contains auth requirement messages */ private containsAuthRequiredMessage; /** * Resolve a redirect URL relative to the original URL */ private resolveRedirectUrl; /** * Get suggested credential types based on challenge */ private getSuggestedCredentialTypes; /** * Check if a workflow is a login workflow */ isLoginWorkflow(workflow: Workflow): boolean; /** * Mark a workflow as a login workflow by adding appropriate tags */ markAsLoginWorkflow(workflow: Workflow): void; } /** Default auth flow detector instance */ export declare const authFlowDetector: AuthFlowDetector; //# sourceMappingURL=auth-flow-detector.d.ts.map