@ai2070/l0
Version:
L0: The Missing Reliability Substrate for AI
83 lines (82 loc) • 1.74 kB
JavaScript
class Metrics {
/** Total stream requests */
requests = 0;
/** Total tokens processed */
tokens = 0;
/** Total retry attempts */
retries = 0;
/** Network retries (subset of retries) */
networkRetryCount = 0;
/** Total errors encountered */
errors = 0;
/** Guardrail violations */
violations = 0;
/** Drift detections */
driftDetections = 0;
/** Fallback activations */
fallbacks = 0;
/** Successful completions */
completions = 0;
/** Timeouts (initial + inter-token) */
timeouts = 0;
/**
* Reset all counters
*/
reset() {
this.requests = 0;
this.tokens = 0;
this.retries = 0;
this.networkRetryCount = 0;
this.errors = 0;
this.violations = 0;
this.driftDetections = 0;
this.fallbacks = 0;
this.completions = 0;
this.timeouts = 0;
}
/**
* Get snapshot of all metrics
*/
snapshot() {
return {
requests: this.requests,
tokens: this.tokens,
retries: this.retries,
networkRetryCount: this.networkRetryCount,
errors: this.errors,
violations: this.violations,
driftDetections: this.driftDetections,
fallbacks: this.fallbacks,
completions: this.completions,
timeouts: this.timeouts
};
}
/**
* Serialize for logging
*/
toJSON() {
return this.snapshot();
}
}
function createMetrics() {
return new Metrics();
}
let globalMetrics = null;
function getGlobalMetrics() {
if (!globalMetrics) {
globalMetrics = new Metrics();
}
return globalMetrics;
}
function resetGlobalMetrics() {
if (globalMetrics) {
globalMetrics.reset();
}
}
export {
Metrics,
createMetrics,
getGlobalMetrics,
resetGlobalMetrics
};
//# sourceMappingURL=metrics.js.map