footprintjs - v11.2.0
    Preparing search index...

    Class KeyedStore<T>

    KeyedStore — concrete, composable 1:1 storage keyed by string id.

    Pattern: COMPOSITION primitive. Concrete class — instantiate with new KeyedStore<T>() and own it as a field on your recorder. Replaces the abstract KeyedRecorder<T> base class for the v5 "one purpose per recorder" rule. Role: 1:1 Map keyed by runtimeStageId (or any string). Insertion-ordered iteration.

    Contrast with SequenceStore<T>: KeyedStore is 1:1 — one entry per key. Use SequenceStore for 1:N (multiple entries per runtimeStageId, ordering matters).

    import { KeyedStore } from 'footprintjs/trace';

    interface TokenEntry { input: number; output: number; }

    // ONE PURPOSE: typed-event handler. Storage is composed in.
    class TokenRecorder {
    readonly id = 'tokens';
    private readonly store = new KeyedStore<TokenEntry>();

    onLLMCall(event: LLMCallEvent) {
    this.store.set(event.runtimeStageId, event.usage);
    }

    getForStep(id: string) { return this.store.get(id); }
    getTotalTokens() { return this.store.aggregate((s, e) => s + e.input + e.output, 0); }
    getTokensUpTo(keys: Set<string>) {
    return this.store.accumulate((s, e) => s + e.input + e.output, 0, keys);
    }

    clear() { this.store.clear(); }
    }

    Type Parameters

    • T
    Index
    • Reduce entries, optionally filtered by a set of keys. For time-travel progressive view: pass the keys visible at the current slider position. Without keys, reduces all entries (same as aggregate).

      Type Parameters

      • R

      Parameters

      • fn: (acc: R, entry: T, key: string) => R
      • initial: R
      • Optionalkeys: ReadonlySet<string>

      Returns R

    • Reduce ALL entries to a single value. For dashboards, totals, summaries.

      Type Parameters

      • R

      Parameters

      • fn: (acc: R, entry: T, key: string) => R
      • initial: R

      Returns R

    • Clear all stored data. Recorders typically call this from their own clear() method, which the executor invokes before each run.

      Returns void

    • Remove an entry. Returns true if the key existed, false otherwise.

      Parameters

      • key: string

      Returns boolean

    • Return entries whose keys are in the set, preserving insertion order.

      Parameters

      • keys: ReadonlySet<string>

      Returns T[]

    • All entries as a read-only Map (insertion-ordered).

      Returns ReadonlyMap<string, T>

    • Store a single entry. Replaces any existing entry for the same key.

      Parameters

      • key: string
      • entry: T

      Returns void