@omnicross/core 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-EPN67EGP.cjs → chunk-5UK3KLE2.cjs} +9 -1
- package/dist/chunk-6D4W22P4.js +150 -0
- package/dist/{chunk-UAPBLNN2.js → chunk-AQDON6MB.js} +8 -0
- package/dist/{chunk-CQIJCPMF.js → chunk-FEBAQI5A.js} +78 -15
- package/dist/{chunk-7C7DET6S.js → chunk-GXEZ2R3E.js} +156 -1
- package/dist/chunk-QUSEZNYS.cjs +150 -0
- package/dist/{chunk-XELFM7KL.cjs → chunk-TIT74RIL.cjs} +235 -172
- package/dist/{chunk-XPIOJQS2.cjs → chunk-UWDW6PN3.cjs} +159 -4
- package/dist/completion/CompletionService.cjs +5 -5
- package/dist/completion/CompletionService.js +4 -4
- package/dist/completion.cjs +5 -5
- package/dist/completion.js +4 -4
- package/dist/index.cjs +5 -5
- package/dist/index.js +4 -4
- package/dist/outbound-api/auditCapture.cjs +2 -2
- package/dist/outbound-api/auditCapture.d.cts +6 -0
- package/dist/outbound-api/auditCapture.d.ts +6 -0
- package/dist/outbound-api/auditCapture.js +1 -1
- package/dist/outbound-api.cjs +5 -5
- package/dist/outbound-api.d.cts +2 -1
- package/dist/outbound-api.d.ts +2 -1
- package/dist/outbound-api.js +4 -4
- package/dist/provider-proxy/ProviderProxy.cjs +5 -5
- package/dist/provider-proxy/ProviderProxy.js +4 -4
- package/dist/provider-proxy/ingress/providerProxyShared.cjs +5 -5
- package/dist/provider-proxy/ingress/providerProxyShared.js +4 -4
- package/dist/provider-proxy.cjs +5 -5
- package/dist/provider-proxy.js +4 -4
- package/dist/usage/usage-recorder.cjs +2 -2
- package/dist/usage/usage-recorder.d.cts +12 -2
- package/dist/usage/usage-recorder.d.ts +12 -2
- package/dist/usage/usage-recorder.js +1 -1
- package/dist/usage.cjs +20 -3
- package/dist/usage.d.cts +149 -0
- package/dist/usage.d.ts +149 -0
- package/dist/usage.js +20 -3
- package/package.json +2 -2
- package/dist/chunk-7VU7V2E4.js +0 -0
- package/dist/chunk-EYZYXJTJ.cjs +0 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;// src/usage/throughputTracker.ts
|
|
2
|
+
var THROUGHPUT_RETENTION_MS = 15 * 6e4;
|
|
3
|
+
var THROUGHPUT_SAMPLE_LIMIT = 2e4;
|
|
4
|
+
var THROUGHPUT_WINDOWS_MS = [6e4, 3e5, 9e5];
|
|
5
|
+
var THROUGHPUT_BUCKET_COUNT = 30;
|
|
6
|
+
var COMPACT_THRESHOLD = 1024;
|
|
7
|
+
var UsageThroughputTracker = (_class = class {
|
|
8
|
+
__init() {this.samples = []}
|
|
9
|
+
/** Index of the oldest live sample; slots before it are consumed. */
|
|
10
|
+
__init2() {this.head = 0}
|
|
11
|
+
|
|
12
|
+
/** Newest ts dropped by the sample CAP (not by retention). Null when none. */
|
|
13
|
+
__init3() {this.evictedThroughTs = null}
|
|
14
|
+
constructor(now = Date.now()) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);
|
|
15
|
+
this.startedAt = now;
|
|
16
|
+
}
|
|
17
|
+
/** Record one served request. O(1) amortised; never touches disk. */
|
|
18
|
+
record(input, now = Date.now()) {
|
|
19
|
+
this.samples.push({
|
|
20
|
+
ts: _nullishCoalesce(input.ts, () => ( now)),
|
|
21
|
+
inputTokens: input.inputTokens,
|
|
22
|
+
outputTokens: input.outputTokens,
|
|
23
|
+
cacheReadTokens: input.cacheReadTokens,
|
|
24
|
+
cacheCreationTokens: input.cacheCreationTokens,
|
|
25
|
+
reasoningTokens: input.reasoningTokens,
|
|
26
|
+
costUsd: input.costUsd
|
|
27
|
+
});
|
|
28
|
+
this.prune(now);
|
|
29
|
+
}
|
|
30
|
+
/** Aggregate every reported window plus the shared trend series. */
|
|
31
|
+
snapshot(now = Date.now()) {
|
|
32
|
+
this.prune(now);
|
|
33
|
+
return {
|
|
34
|
+
available: true,
|
|
35
|
+
collectedAt: now,
|
|
36
|
+
startedAt: this.startedAt,
|
|
37
|
+
retentionMs: THROUGHPUT_RETENTION_MS,
|
|
38
|
+
bucketMs: THROUGHPUT_RETENTION_MS / THROUGHPUT_BUCKET_COUNT,
|
|
39
|
+
windows: THROUGHPUT_WINDOWS_MS.map((windowMs) => this.window(windowMs, now)),
|
|
40
|
+
buckets: this.buckets(now)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** Drop all samples (tests / teardown). `startedAt` is unchanged. */
|
|
44
|
+
clear() {
|
|
45
|
+
this.samples = [];
|
|
46
|
+
this.head = 0;
|
|
47
|
+
this.evictedThroughTs = null;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Drop samples past the retention horizon, then enforce the sample cap.
|
|
51
|
+
*
|
|
52
|
+
* Retention pruning uses the CALLER's `now`, which is never later than a
|
|
53
|
+
* subsequent snapshot's `now`, so it can only ever keep MORE than the widest
|
|
54
|
+
* window needs — it can never shave data off the 15-minute window.
|
|
55
|
+
*/
|
|
56
|
+
prune(now) {
|
|
57
|
+
const cutoff = now - THROUGHPUT_RETENTION_MS;
|
|
58
|
+
while (this.head < this.samples.length && this.samples[this.head].ts < cutoff) {
|
|
59
|
+
this.head += 1;
|
|
60
|
+
}
|
|
61
|
+
while (this.samples.length - this.head > THROUGHPUT_SAMPLE_LIMIT) {
|
|
62
|
+
const dropped = this.samples[this.head];
|
|
63
|
+
this.evictedThroughTs = this.evictedThroughTs === null ? dropped.ts : Math.max(this.evictedThroughTs, dropped.ts);
|
|
64
|
+
this.head += 1;
|
|
65
|
+
}
|
|
66
|
+
if (this.head >= COMPACT_THRESHOLD) {
|
|
67
|
+
this.samples = this.samples.slice(this.head);
|
|
68
|
+
this.head = 0;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
window(windowMs, now) {
|
|
72
|
+
const startTs = now - windowMs;
|
|
73
|
+
const row = {
|
|
74
|
+
windowMs,
|
|
75
|
+
requests: 0,
|
|
76
|
+
inputTokens: 0,
|
|
77
|
+
outputTokens: 0,
|
|
78
|
+
cacheReadTokens: 0,
|
|
79
|
+
cacheCreationTokens: 0,
|
|
80
|
+
reasoningTokens: 0,
|
|
81
|
+
totalTokens: 0,
|
|
82
|
+
costUsd: 0,
|
|
83
|
+
requestsPerMinute: 0,
|
|
84
|
+
tokensPerMinute: 0,
|
|
85
|
+
inputTokensPerMinute: 0,
|
|
86
|
+
outputTokensPerMinute: 0,
|
|
87
|
+
costUsdPerMinute: 0,
|
|
88
|
+
complete: this.evictedThroughTs === null || this.evictedThroughTs < startTs
|
|
89
|
+
};
|
|
90
|
+
for (let i = this.head; i < this.samples.length; i += 1) {
|
|
91
|
+
const sample = this.samples[i];
|
|
92
|
+
if (sample.ts < startTs) continue;
|
|
93
|
+
row.requests += 1;
|
|
94
|
+
row.inputTokens += sample.inputTokens;
|
|
95
|
+
row.outputTokens += sample.outputTokens;
|
|
96
|
+
row.cacheReadTokens += sample.cacheReadTokens;
|
|
97
|
+
row.cacheCreationTokens += sample.cacheCreationTokens;
|
|
98
|
+
row.reasoningTokens += sample.reasoningTokens;
|
|
99
|
+
row.costUsd += sample.costUsd;
|
|
100
|
+
}
|
|
101
|
+
row.totalTokens = row.inputTokens + row.outputTokens + row.cacheReadTokens + row.cacheCreationTokens;
|
|
102
|
+
const minutes = windowMs / 6e4;
|
|
103
|
+
row.requestsPerMinute = row.requests / minutes;
|
|
104
|
+
row.tokensPerMinute = row.totalTokens / minutes;
|
|
105
|
+
row.inputTokensPerMinute = row.inputTokens / minutes;
|
|
106
|
+
row.outputTokensPerMinute = row.outputTokens / minutes;
|
|
107
|
+
row.costUsdPerMinute = row.costUsd / minutes;
|
|
108
|
+
return row;
|
|
109
|
+
}
|
|
110
|
+
buckets(now) {
|
|
111
|
+
const bucketMs = THROUGHPUT_RETENTION_MS / THROUGHPUT_BUCKET_COUNT;
|
|
112
|
+
const endTs = Math.floor(now / bucketMs) * bucketMs + bucketMs;
|
|
113
|
+
const startTs = endTs - THROUGHPUT_RETENTION_MS;
|
|
114
|
+
const out = [];
|
|
115
|
+
for (let i = 0; i < THROUGHPUT_BUCKET_COUNT; i += 1) {
|
|
116
|
+
out.push({ startTs: startTs + i * bucketMs, requests: 0, tokens: 0 });
|
|
117
|
+
}
|
|
118
|
+
for (let i = this.head; i < this.samples.length; i += 1) {
|
|
119
|
+
const sample = this.samples[i];
|
|
120
|
+
if (sample.ts < startTs || sample.ts >= endTs) continue;
|
|
121
|
+
const bucket = out[Math.floor((sample.ts - startTs) / bucketMs)];
|
|
122
|
+
if (!bucket) continue;
|
|
123
|
+
bucket.requests += 1;
|
|
124
|
+
bucket.tokens += sample.inputTokens + sample.outputTokens + sample.cacheReadTokens + sample.cacheCreationTokens;
|
|
125
|
+
}
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
}, _class);
|
|
129
|
+
var sharedTracker = null;
|
|
130
|
+
function getSharedUsageThroughputTracker() {
|
|
131
|
+
if (!sharedTracker) sharedTracker = new UsageThroughputTracker();
|
|
132
|
+
return sharedTracker;
|
|
133
|
+
}
|
|
134
|
+
function setSharedUsageThroughputTracker(instance) {
|
|
135
|
+
sharedTracker = instance;
|
|
136
|
+
}
|
|
137
|
+
function __resetSharedUsageThroughputTrackerForTests() {
|
|
138
|
+
sharedTracker = null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
exports.THROUGHPUT_RETENTION_MS = THROUGHPUT_RETENTION_MS; exports.THROUGHPUT_SAMPLE_LIMIT = THROUGHPUT_SAMPLE_LIMIT; exports.THROUGHPUT_WINDOWS_MS = THROUGHPUT_WINDOWS_MS; exports.THROUGHPUT_BUCKET_COUNT = THROUGHPUT_BUCKET_COUNT; exports.UsageThroughputTracker = UsageThroughputTracker; exports.getSharedUsageThroughputTracker = getSharedUsageThroughputTracker; exports.setSharedUsageThroughputTracker = setSharedUsageThroughputTracker; exports.__resetSharedUsageThroughputTrackerForTests = __resetSharedUsageThroughputTrackerForTests;
|