UNPKG

@juspay/neurolink

Version:

The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002

33 lines (32 loc) • 1.14 kB
/** * Analytics storage — in-memory implementation with bounded FIFO capacity. * Designed modularly so Redis or a database can later replace the backend. */ /** Default max records retained in memory (FIFO eviction beyond this). */ export const DEFAULT_ANALYTICS_STORAGE_MAX_RECORDS = 10_000; /** * Lightweight bounded in-memory storage implementation. * Public surface of AnalyticsStorage is unchanged; maxRecords is optional. */ export class InMemoryAnalyticsStorage { records = []; maxRecords; constructor(options) { const max = options?.maxRecords ?? DEFAULT_ANALYTICS_STORAGE_MAX_RECORDS; this.maxRecords = max > 0 ? Math.floor(max) : DEFAULT_ANALYTICS_STORAGE_MAX_RECORDS; } async saveRecord(record) { this.records.push(record); // Slice once when over capacity — avoids O(n²) repeated shift() on burst. if (this.records.length > this.maxRecords) { this.records = this.records.slice(-this.maxRecords); } } async getRecords() { return [...this.records]; } async clear() { this.records = []; } }