- Add full Telegram bot functionality with Z.AI API integration
- Implement 4 tools: Bash, FileEdit, WebSearch, Git
- Add 3 agents: Code Reviewer, Architect, DevOps Engineer
- Add 6 skills for common coding tasks
- Add systemd service file for 24/7 operation
- Add nginx configuration for HTTPS webhook
- Add comprehensive documentation
- Implement WebSocket server for real-time updates
- Add logging system with Winston
- Add environment validation
🤖 zCode CLI X - Agentic coder with Z.AI + Telegram integration
85 lines
2.8 KiB
JavaScript
85 lines
2.8 KiB
JavaScript
/*
|
|
* Copyright The OpenTelemetry Authors
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
import { AggregatorKind } from './types';
|
|
import { DataPointType } from '../export/MetricData';
|
|
export class SumAccumulation {
|
|
startTime;
|
|
monotonic;
|
|
_current;
|
|
reset;
|
|
constructor(startTime, monotonic, current = 0, reset = false) {
|
|
this.startTime = startTime;
|
|
this.monotonic = monotonic;
|
|
this._current = current;
|
|
this.reset = reset;
|
|
}
|
|
record(value) {
|
|
if (this.monotonic && value < 0) {
|
|
return;
|
|
}
|
|
this._current += value;
|
|
}
|
|
setStartTime(startTime) {
|
|
this.startTime = startTime;
|
|
}
|
|
toPointValue() {
|
|
return this._current;
|
|
}
|
|
}
|
|
/** Basic aggregator which calculates a Sum from individual measurements. */
|
|
export class SumAggregator {
|
|
kind = AggregatorKind.SUM;
|
|
monotonic;
|
|
constructor(monotonic) {
|
|
this.monotonic = monotonic;
|
|
}
|
|
createAccumulation(startTime) {
|
|
return new SumAccumulation(startTime, this.monotonic);
|
|
}
|
|
/**
|
|
* Returns the result of the merge of the given accumulations.
|
|
*/
|
|
merge(previous, delta) {
|
|
const prevPv = previous.toPointValue();
|
|
const deltaPv = delta.toPointValue();
|
|
if (delta.reset) {
|
|
return new SumAccumulation(delta.startTime, this.monotonic, deltaPv, delta.reset);
|
|
}
|
|
return new SumAccumulation(previous.startTime, this.monotonic, prevPv + deltaPv);
|
|
}
|
|
/**
|
|
* Returns a new DELTA aggregation by comparing two cumulative measurements.
|
|
*/
|
|
diff(previous, current) {
|
|
const prevPv = previous.toPointValue();
|
|
const currPv = current.toPointValue();
|
|
/**
|
|
* If the SumAggregator is a monotonic one and the previous point value is
|
|
* greater than the current one, a reset is deemed to be happened.
|
|
* Return the current point value to prevent the value from been reset.
|
|
*/
|
|
if (this.monotonic && prevPv > currPv) {
|
|
return new SumAccumulation(current.startTime, this.monotonic, currPv, true);
|
|
}
|
|
return new SumAccumulation(current.startTime, this.monotonic, currPv - prevPv);
|
|
}
|
|
toMetricData(descriptor, aggregationTemporality, accumulationByAttributes, endTime) {
|
|
return {
|
|
descriptor,
|
|
aggregationTemporality,
|
|
dataPointType: DataPointType.SUM,
|
|
dataPoints: accumulationByAttributes.map(([attributes, accumulation]) => {
|
|
return {
|
|
attributes,
|
|
startTime: accumulation.startTime,
|
|
endTime,
|
|
value: accumulation.toPointValue(),
|
|
};
|
|
}),
|
|
isMonotonic: this.monotonic,
|
|
};
|
|
}
|
|
}
|
|
//# sourceMappingURL=Sum.js.map
|