@leo000001/opencode-quota-sidebar 1.13.6 → 1.13.7
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/cost.js +9 -2
- package/dist/usage_service.js +22 -0
- package/package.json +1 -1
package/dist/cost.js
CHANGED
|
@@ -79,17 +79,24 @@ export function guessModelCostDivisor(rates) {
|
|
|
79
79
|
: MODEL_COST_DIVISOR_PER_TOKEN;
|
|
80
80
|
}
|
|
81
81
|
export function calcEquivalentApiCostForMessage(message, rates) {
|
|
82
|
+
const info = message;
|
|
82
83
|
const effectiveRates = message.tokens.input > 200_000 && rates.contextOver200k
|
|
83
84
|
? rates.contextOver200k
|
|
84
85
|
: rates;
|
|
86
|
+
const serviceTier = info.providerMetadata?.openai?.serviceTier ??
|
|
87
|
+
info.providerMetadata?.openai?.service_tier;
|
|
88
|
+
const priorityMultiplier = message.providerID === 'openai' && serviceTier === 'priority'
|
|
89
|
+
? 2
|
|
90
|
+
: 1;
|
|
85
91
|
// For providers that expose reasoning tokens separately, they are still
|
|
86
92
|
// billed as output/completion tokens (same unit price). Our UI also merges
|
|
87
93
|
// reasoning into the single Output statistic, so API cost should match that.
|
|
88
94
|
const billedOutput = message.tokens.output + message.tokens.reasoning;
|
|
89
|
-
const rawCost = message.tokens.input * effectiveRates.input +
|
|
95
|
+
const rawCost = (message.tokens.input * effectiveRates.input +
|
|
90
96
|
billedOutput * effectiveRates.output +
|
|
91
97
|
message.tokens.cache.read * effectiveRates.cacheRead +
|
|
92
|
-
message.tokens.cache.write * effectiveRates.cacheWrite
|
|
98
|
+
message.tokens.cache.write * effectiveRates.cacheWrite) *
|
|
99
|
+
priorityMultiplier;
|
|
93
100
|
const divisor = guessModelCostDivisor(effectiveRates);
|
|
94
101
|
const normalized = rawCost / divisor;
|
|
95
102
|
return Number.isFinite(normalized) && normalized > 0 ? normalized : 0;
|
package/dist/usage_service.js
CHANGED
|
@@ -143,12 +143,34 @@ export function createUsageService(deps) {
|
|
|
143
143
|
tokens,
|
|
144
144
|
};
|
|
145
145
|
};
|
|
146
|
+
const extractProviderMetadata = (parts) => {
|
|
147
|
+
if (!Array.isArray(parts))
|
|
148
|
+
return undefined;
|
|
149
|
+
for (const part of parts) {
|
|
150
|
+
if (!isRecord(part))
|
|
151
|
+
continue;
|
|
152
|
+
const meta = part.metadata;
|
|
153
|
+
if (isRecord(meta))
|
|
154
|
+
return meta;
|
|
155
|
+
const stateMeta = isRecord(part.state)
|
|
156
|
+
? part.state?.metadata
|
|
157
|
+
: undefined;
|
|
158
|
+
if (isRecord(stateMeta))
|
|
159
|
+
return stateMeta;
|
|
160
|
+
}
|
|
161
|
+
return undefined;
|
|
162
|
+
};
|
|
146
163
|
const decodeMessageEntry = (value) => {
|
|
147
164
|
if (!isRecord(value))
|
|
148
165
|
return undefined;
|
|
149
166
|
const decoded = decodeMessageInfo(value.info);
|
|
150
167
|
if (!decoded)
|
|
151
168
|
return undefined;
|
|
169
|
+
const metadata = extractProviderMetadata(value.parts);
|
|
170
|
+
if (metadata && decoded.role === 'assistant') {
|
|
171
|
+
const msg = decoded;
|
|
172
|
+
msg.providerMetadata = metadata;
|
|
173
|
+
}
|
|
152
174
|
return { info: decoded };
|
|
153
175
|
};
|
|
154
176
|
const decodeMessageEntries = (value) => {
|