UNPKG

@nanocollective/nanocoder

Version:

A local-first CLI coding agent that brings the power of agentic coding tools like Claude Code and Gemini CLI to local models or controlled APIs like OpenRouter

121 lines 4.46 kB
/** * Correlation ID management for tracking requests across components */ import { AsyncLocalStorage } from 'async_hooks'; import type { CorrelationContext, CorrelationHttpRequest, CorrelationHttpResponse } from './types.js'; /** * Async local storage for correlation context * Provides thread-safe context storage across async operations */ export declare const correlationStorage: AsyncLocalStorage<CorrelationContext>; /** * Correlation Context Monitoring Metrics * Tracks usage, performance, and potential issues for production monitoring */ declare const correlationMonitoring: { contextsCreated: number; activeContexts: number; errors: number; lastError: string | null; lastErrorTime: number; startTime: number; }; /** * Legacy context has been removed in favor of AsyncLocalStorage-only approach * This eliminates race conditions in concurrent operations * All code should now use withCorrelationContext() or withNewCorrelationContext() */ /** * Get correlation context monitoring metrics * Provides insights into context usage, performance, and health */ export declare function getCorrelationMonitoring(): typeof correlationMonitoring; /** * Log correlation context monitoring metrics * Useful for periodic logging of system health * @internal */ export declare function logCorrelationMonitoring(level?: 'debug' | 'info' | 'warn' | 'error'): void; /** * Reset correlation context monitoring metrics * Useful for testing or periodic reporting */ export declare function resetCorrelationMonitoring(): void; /** * Perform health check on correlation context system * Verifies that the AsyncLocalStorage context system is functioning properly */ export declare function checkCorrelationHealth(): { healthy: boolean; message: string; metrics: typeof correlationMonitoring; }; /** * Generate a new correlation ID */ export declare function generateCorrelationId(): string; /** * Generate a short correlation ID (8 characters) for display */ export declare function generateShortCorrelationId(): string; /** * Create a new correlation context with specific ID */ export declare function createCorrelationContextWithId(id: string, metadata?: Record<string, unknown>): CorrelationContext; /** * Create a new correlation context with optional parent ID */ export declare function createCorrelationContext(parentId?: string, metadata?: Record<string, unknown>): CorrelationContext; /** * Get the current correlation context * Now uses AsyncLocalStorage exclusively - no legacy fallback */ export declare function getCurrentCorrelationContext(): CorrelationContext | null; /** * Run a function with a specific correlation context */ export declare function withCorrelationContext<T>(context: CorrelationContext, fn: () => T): T; /** * Run a function with a new correlation context */ export declare function withNewCorrelationContext<T>(fn: (context: CorrelationContext) => T, correlationId?: string, metadata?: Record<string, unknown>): T; /** * Get the correlation ID for the current context */ export declare function getCorrelationId(): string | null; /** * Check if correlation is enabled */ export declare function isCorrelationEnabled(): boolean; /** * Get correlation header for HTTP requests */ export declare function getCorrelationHeader(): { 'X-Correlation-ID': string; } | Record<string, never>; /** * Extract correlation ID from HTTP headers */ export declare function extractCorrelationId(headers: Record<string, string>): string | null; /** * Create a correlation context from HTTP headers */ export declare function createCorrelationFromHeaders(headers: Record<string, string>, metadata?: Record<string, unknown>): CorrelationContext | null; /** * Get correlation metadata */ export declare function getCorrelationMetadata(key?: string): unknown; /** * Format correlation context for logging */ export declare function formatCorrelationForLog(): Record<string, string>; /** * Correlation middleware for Express-like frameworks */ export declare function correlationMiddleware(): (req: CorrelationHttpRequest, res: CorrelationHttpResponse, next: () => void) => void; /** * Wrap an async function with correlation tracking */ export declare function withCorrelation<T extends (...args: unknown[]) => Promise<unknown>>(fn: T, getCorrelationIdFromArgs?: (...args: Parameters<T>) => string): T; export {}; //# sourceMappingURL=correlation.d.ts.map