cursor-opencode-provider 0.6.1 → 0.6.2
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/language-model.js +4 -1
- package/dist/usage.d.ts +2 -0
- package/dist/usage.js +13 -1
- package/package.json +1 -1
package/dist/language-model.js
CHANGED
|
@@ -1707,7 +1707,10 @@ export async function pump(session, controller, ids, abortSignal) {
|
|
|
1707
1707
|
const counters = te ? cursorUsageCountersFromTurnEnded(te) : undefined;
|
|
1708
1708
|
const usage = settledUsage ?? (te
|
|
1709
1709
|
? tokenDetails
|
|
1710
|
-
? buildLanguageModelV3UsageFromCounters(counters, {
|
|
1710
|
+
? buildLanguageModelV3UsageFromCounters(counters, {
|
|
1711
|
+
contextTotalTokens: tokenDetails.usedTokens,
|
|
1712
|
+
priorContextTokens: session.cacheDiagnostics?.priorTokenDetails?.usedTokens,
|
|
1713
|
+
})
|
|
1711
1714
|
: emptyLanguageModelV3Usage()
|
|
1712
1715
|
: emptyLanguageModelV3Usage());
|
|
1713
1716
|
const providerMetadata = te
|
package/dist/usage.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export type CursorUsageCounters = {
|
|
|
10
10
|
export type CursorUsageOptions = {
|
|
11
11
|
/** Cursor checkpoint occupancy, including the current turn's output. */
|
|
12
12
|
contextTotalTokens?: number;
|
|
13
|
+
/** Previous turn's occupancy. When Cursor's cache read covers this window, do not dilute the hit by multi-step TurnEnded aggregates. */
|
|
14
|
+
priorContextTokens?: number;
|
|
13
15
|
};
|
|
14
16
|
export type CursorCacheDiagnosticStats = {
|
|
15
17
|
sessionKey?: string;
|
package/dist/usage.js
CHANGED
|
@@ -32,9 +32,17 @@ export function buildLanguageModelV3UsageFromCounters(counters, options = {}) {
|
|
|
32
32
|
// TurnEnded can aggregate several internal model calls, so its absolute input
|
|
33
33
|
// and cache counts can exceed the final checkpoint occupancy. Preserve the
|
|
34
34
|
// cache proportions while normalizing the partition to Cursor's context total.
|
|
35
|
-
const
|
|
35
|
+
const proportionalRead = rawInput > 0
|
|
36
36
|
? Math.min(input, Math.round(input * rawCacheRead / rawInput))
|
|
37
37
|
: 0;
|
|
38
|
+
const priorContext = options.priorContextTokens;
|
|
39
|
+
const prefixRead = typeof priorContext === "number"
|
|
40
|
+
&& Number.isFinite(priorContext)
|
|
41
|
+
&& priorContext > 0
|
|
42
|
+
&& rawCacheRead >= priorContext
|
|
43
|
+
? Math.min(input, Math.trunc(priorContext))
|
|
44
|
+
: 0;
|
|
45
|
+
const cacheRead = Math.min(input, Math.max(proportionalRead, prefixRead));
|
|
38
46
|
const cacheWrite = rawInput > 0
|
|
39
47
|
? Math.min(input - cacheRead, Math.round(input * rawCacheWrite / rawInput))
|
|
40
48
|
: 0;
|
|
@@ -170,9 +178,13 @@ export function formatTurnUsageValidation(counters, usage, tokenDetails, context
|
|
|
170
178
|
: undefined;
|
|
171
179
|
const rawCached = counters.cacheRead + counters.cacheWrite;
|
|
172
180
|
const sentCached = cacheRead + cacheWrite;
|
|
181
|
+
const proportionalCached = counters.inputTokens > 0 && input > 0
|
|
182
|
+
? Math.round(input * rawCached / counters.inputTokens)
|
|
183
|
+
: 0;
|
|
173
184
|
const cacheRatioMatch = tokenDetails
|
|
174
185
|
? counters.inputTokens > 0 && input > 0
|
|
175
186
|
? Math.abs(rawCached / counters.inputTokens - sentCached / input) <= 1 / input
|
|
187
|
+
|| (sentCached >= proportionalCached && sentCached <= input)
|
|
176
188
|
: rawCached === 0 && sentCached === 0
|
|
177
189
|
: undefined;
|
|
178
190
|
const status = input === inputParts &&
|