import { SearchResult } from "../../core/dist/index.js"; //#region packages/enterprise-bridge/src/types.d.ts /** ER bridge configuration (subset of AikitConfig.er) */ interface ERBridgeConfig { enabled: boolean; baseUrl: string; apiKey: string; timeoutMs: number; cacheTtlMs: number; cacheMaxEntries: number; fallbackThreshold: number; } /** Result from ER search API */ interface ERSearchResult { content: string; sourcePath: string; score: number; metadata?: Record; } /** Response from ER search API (POST /api/v1/search) */ interface ERSearchResponse { sources: Array<{ content: string; metadata: Record; score?: number; confidence?: number; }>; query?: string; searchMode?: string; } /** Push request to ER */ interface ERPushRequest { title: string; content: string; category?: string; tags?: string[]; } /** Push response from ER */ interface ERPushResponse { pushed: boolean; status: 'stored' | 'failed'; remotePath?: string; timestamp: string; error?: string; } /** Transient ER error (429, 5xx, network) — retries exhausted but not a permanent failure */ declare class ERTransientError extends Error { readonly statusCode?: number | undefined; constructor(message: string, statusCode?: number | undefined); } /** Sync status entry for tracking push history */ interface ERSyncEntry { entryId: string; title: string; pushedAt: string; status: 'stored' | 'failed'; remotePath?: string; } /** Cache entry wrapping ER search results */ interface ERCacheEntry { results: ERSearchResult[]; query: string; cachedAt: number; ttl: number; } /** Merged search result with source provenance */ interface MergedSearchResult { content: string; sourcePath: string; score: number; source: 'local' | 'er'; startLine?: number; endLine?: number; contentType?: string; headingPath?: string; origin?: string; category?: string; tags?: string[]; metadata?: Record; } //#endregion //#region packages/enterprise-bridge/src/cache.d.ts declare class ERCache { private readonly cache; private readonly maxEntries; private readonly defaultTtl; constructor(options?: { maxEntries?: number; defaultTtl?: number; }); /** Normalize query for cache key: lowercase, trim, collapse whitespace */ static normalizeKey(query: string): string; get(query: string): ERSearchResult[] | undefined; set(query: string, results: ERSearchResult[], ttl?: number): void; /** Invalidate entries matching a topic (exact normalized key match) */ invalidate(query: string): boolean; clear(): void; get size(): number; /** Get cache stats */ stats(): { size: number; maxEntries: number; defaultTtlMs: number; }; } //#endregion //#region packages/enterprise-bridge/src/er-client.d.ts declare class ERClient { private readonly baseUrl; private readonly apiKey; private readonly timeoutMs; private readonly cb; private readonly healthBus; constructor(config: ERBridgeConfig); /** Search ER AI Kit */ search(query: string, maxResults?: number): Promise; /** Push curated knowledge to ER via MCP tools endpoint */ push(request: ERPushRequest): Promise; /** Explicit pull from ER (bypasses local search, for cross-repo context) */ pull(query: string, maxResults?: number): Promise; /** Check ER health */ health(): Promise<{ healthy: boolean; status?: number; }>; /** Check available MCP tools (verify curated_remember exists) */ listTools(): Promise; private fetch; private doFetch; private parseRetryAfter; } //#endregion //#region packages/enterprise-bridge/src/evolution-collector.d.ts /** Evolution data collector — tracks usage metrics for LLM review */ interface EvolutionMetrics { /** Search metrics */ search: { totalSearches: number; erFallbackCount: number; erFallbackRate: number; erCacheHitCount: number; erCacheHitRate: number; topMissedQueries: Array<{ query: string; count: number; }>; }; /** Push metrics */ push: { totalPushes: number; successCount: number; failCount: number; pushRate: number; /** Classification match rate — how often rules fired vs knowledge stored */ classificationMatchRate: number; /** Push acceptance rate — how often LLM decided to push after recommendation */ pushAcceptanceRate: number; }; /** Rule effectiveness */ rules: { matchCounts: Record; pushCounts: Record; /** Rules that fire often but rarely lead to pushes (potential false positives) */ lowConversionRules: Array<{ ruleId: string; matchCount: number; pushCount: number; conversionRate: number; }>; }; /** Summary period */ period: { startedAt: string; queriedAt: string; totalEvents: number; }; } declare class EvolutionCollector { private searchEvents; private classificationEvents; private pushEvents; private readonly startedAt; constructor(); /** Record a search event */ recordSearch(query: string, erFallbackTriggered: boolean, erCacheHit: boolean): void; /** Record a classification event (when remember returns classification signals) */ recordClassification(entryTitle: string, matchingRuleIds: string[], pushRecommended: boolean): void; /** Record a push event */ recordPush(entryId: string, success: boolean, ruleId?: string): void; /** Get aggregated metrics for LLM review */ getMetrics(): EvolutionMetrics; /** Reset all collected data */ reset(): void; private trimEvents; } //#endregion //#region packages/enterprise-bridge/src/policy-store.d.ts /** A single classification rule */ interface ClassificationRule { id: string; patterns: string[]; category: string; pushWeight: number; description: string; examples: string[]; autoPush: false; enabled: boolean; createdAt: string; updatedAt: string; } /** Classification result for a knowledge entry */ interface ClassificationResult { matchingRules: Array<{ ruleId: string; category: string; pushWeight: number; matchedPatterns: string[]; }>; pushRecommended: boolean; maxPushWeight: number; } declare class PolicyStore { private rules; private readonly rulesPath; constructor(curatedPath: string); /** Classify a knowledge entry against all enabled rules */ classify(title: string, content: string, tags: string[]): ClassificationResult; /** Get all rules */ getRules(): ClassificationRule[]; /** Get a single rule by ID */ getRule(ruleId: string): ClassificationRule | undefined; /** Update an existing rule */ updateRule(ruleId: string, changes: Partial>): ClassificationRule | undefined; /** Add a new rule */ addRule(rule: Omit): ClassificationRule; /** Delete a rule */ deleteRule(ruleId: string): boolean; private save; } //#endregion //#region packages/enterprise-bridge/src/push-adapter.d.ts declare class PushAdapter { private readonly client; private readonly syncHistory; private static readonly MAX_HISTORY; constructor(client: ERClient); /** Push a knowledge entry to ER */ push(entryId: string, request: ERPushRequest): Promise; /** Get sync history */ getHistory(): ERSyncEntry[]; /** Get sync status summary */ getStatus(): { totalPushed: number; successCount: number; failCount: number; lastPush?: ERSyncEntry; }; } //#endregion //#region packages/enterprise-bridge/src/result-merger.d.ts /** * Merge local and ER results using local-first interleaving. * * Local RRF scores (~0.01-0.05) and ER raw similarity scores (~0.3-0.9) are on * incomparable scales. Instead of sorting both together (which would always rank * ER above local), we preserve local ordering, deduplicate, then append ER results. */ declare function mergeResults(localResults: SearchResult[], erResults: ERSearchResult[], limit: number): MergedSearchResult[]; //#endregion export { type ClassificationResult, type ClassificationRule, type ERBridgeConfig, ERCache, type ERCacheEntry, ERClient, type ERPushRequest, type ERPushResponse, type ERSearchResponse, type ERSearchResult, type ERSyncEntry, ERTransientError, EvolutionCollector, type EvolutionMetrics, type MergedSearchResult, PolicyStore, PushAdapter, mergeResults };