@agentica/core
Version:
Agentic AI Library specialized in LLM Function Calling
105 lines • 4.19 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AgenticaTokenUsage = void 0;
const typia_1 = __importDefault(require("typia"));
const AgenticaTokenUsageAggregator_1 = require("./internal/AgenticaTokenUsageAggregator");
class AgenticaTokenUsage {
constructor(props) {
if (props === undefined) {
const zero = AgenticaTokenUsage.zero();
this.aggregate = zero.aggregate;
this.initialize = zero.initialize;
this.select = zero.select;
this.cancel = zero.cancel;
this.call = zero.call;
this.describe = zero.describe;
}
else {
this.aggregate = props.aggregate;
this.initialize = props.initialize;
this.select = props.select;
this.cancel = props.cancel;
this.call = props.call;
this.describe = props.describe;
}
}
increment(y) {
const increment = (x, y) => {
x.total += y.total;
x.input.total += y.input.total;
x.input.cached += y.input.cached;
x.output.total += y.output.total;
x.output.reasoning += y.output.reasoning;
x.output.accepted_prediction += y.output.accepted_prediction;
x.output.rejected_prediction += y.output.rejected_prediction;
};
increment(this.aggregate, y.aggregate);
increment(this.initialize, y.initialize);
increment(this.select, y.select);
increment(this.cancel, y.cancel);
increment(this.call, y.call);
increment(this.describe, y.describe);
}
use(kind, completionUsage) {
AgenticaTokenUsageAggregator_1.AgenticaTokenUsageAggregator.aggregate({
kind,
completionUsage,
usage: this,
});
}
toJSON() {
return (() => { const _co0 = input => ({
aggregate: _co1(input.aggregate),
initialize: _co1(input.initialize),
select: _co1(input.select),
cancel: _co1(input.cancel),
call: _co1(input.call),
describe: _co1(input.describe)
}); const _co1 = input => ({
total: input.total,
input: _co2(input.input),
output: _co3(input.output)
}); const _co2 = input => ({
total: input.total,
cached: input.cached
}); const _co3 = input => ({
total: input.total,
reasoning: input.reasoning,
accepted_prediction: input.accepted_prediction,
rejected_prediction: input.rejected_prediction
}); const _io1 = input => "number" === typeof input.total && ("object" === typeof input.input && null !== input.input && _io2(input.input)) && ("object" === typeof input.output && null !== input.output && _io3(input.output)); const _io2 = input => "number" === typeof input.total && "number" === typeof input.cached; const _io3 = input => "number" === typeof input.total && "number" === typeof input.reasoning && "number" === typeof input.accepted_prediction && "number" === typeof input.rejected_prediction; return input => _co0(input); })()(this);
}
static zero() {
const component = () => ({
total: 0,
input: {
total: 0,
cached: 0,
},
output: {
total: 0,
reasoning: 0,
accepted_prediction: 0,
rejected_prediction: 0,
},
});
return new AgenticaTokenUsage({
aggregate: component(),
initialize: component(),
select: component(),
cancel: component(),
call: component(),
describe: component(),
});
}
static plus(x, y) {
const z = new AgenticaTokenUsage(x.toJSON());
z.increment(y.toJSON());
return z;
}
}
exports.AgenticaTokenUsage = AgenticaTokenUsage;
//# sourceMappingURL=AgenticaTokenUsage.js.map