topchester-ai 0.36.0 → 0.37.0
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/bin.mjs
CHANGED
|
@@ -4872,7 +4872,8 @@ var ModelGateway = class ModelGateway {
|
|
|
4872
4872
|
const usage = normalizeUsage(result.usage, {
|
|
4873
4873
|
providerId: resolved.providerId,
|
|
4874
4874
|
providerConfig: resolved.providerConfig,
|
|
4875
|
-
responseBody: result.response.body
|
|
4875
|
+
responseBody: result.response.body,
|
|
4876
|
+
responseHeaders: result.response.headers
|
|
4876
4877
|
});
|
|
4877
4878
|
return {
|
|
4878
4879
|
text: result.text,
|
|
@@ -4962,7 +4963,8 @@ var ModelGateway = class ModelGateway {
|
|
|
4962
4963
|
const usage = normalizeUsage(result.usage, {
|
|
4963
4964
|
providerId: resolved.providerId,
|
|
4964
4965
|
providerConfig: resolved.providerConfig,
|
|
4965
|
-
responseBody: result.response.body
|
|
4966
|
+
responseBody: result.response.body,
|
|
4967
|
+
responseHeaders: result.response.headers
|
|
4966
4968
|
});
|
|
4967
4969
|
const toolCalls = result.toolCalls.map((call, index) => {
|
|
4968
4970
|
const parsed = parseNativeToolCall(call.toolName, call.input);
|
|
@@ -5003,7 +5005,8 @@ var ModelGateway = class ModelGateway {
|
|
|
5003
5005
|
const usage = normalizeUsage(result.usage, {
|
|
5004
5006
|
providerId: resolved.providerId,
|
|
5005
5007
|
providerConfig: resolved.providerConfig,
|
|
5006
|
-
responseBody: result.response.body
|
|
5008
|
+
responseBody: result.response.body,
|
|
5009
|
+
responseHeaders: result.response.headers
|
|
5007
5010
|
});
|
|
5008
5011
|
const parsed = parseToolCallWithSource(result.text, allowedSources);
|
|
5009
5012
|
const defaultProtocol = allowedSources.length === 1 && allowedSources[0] === "text-xml" ? "text-xml" : "text-json";
|
|
@@ -5221,7 +5224,7 @@ function extractWarningMessages(warnings) {
|
|
|
5221
5224
|
return warnings.map((warning) => formatErrorMessage$2(warning));
|
|
5222
5225
|
}
|
|
5223
5226
|
function normalizeUsage(usage, context) {
|
|
5224
|
-
const costUsd = extractResponseCostUsd(context?.responseBody);
|
|
5227
|
+
const costUsd = extractResponseCostUsd(context?.responseBody, context?.responseHeaders);
|
|
5225
5228
|
if (!usage) return costUsd === void 0 ? void 0 : { costUsd };
|
|
5226
5229
|
const normalized = {
|
|
5227
5230
|
...typeof usage.inputTokens === "number" ? { inputTokens: usage.inputTokens } : {},
|
|
@@ -5231,21 +5234,29 @@ function normalizeUsage(usage, context) {
|
|
|
5231
5234
|
};
|
|
5232
5235
|
return Object.keys(normalized).length > 0 ? normalized : void 0;
|
|
5233
5236
|
}
|
|
5234
|
-
function extractResponseCostUsd(responseBody) {
|
|
5237
|
+
function extractResponseCostUsd(responseBody, responseHeaders) {
|
|
5238
|
+
return extractResponseBodyCostUsd(responseBody) ?? extractResponseHeaderCostUsd(responseHeaders);
|
|
5239
|
+
}
|
|
5240
|
+
function extractResponseBodyCostUsd(responseBody) {
|
|
5235
5241
|
if (!responseBody || typeof responseBody !== "object") return;
|
|
5236
5242
|
const usage = responseBody.usage;
|
|
5237
5243
|
const hiddenParams = responseBody.hidden_params;
|
|
5238
5244
|
const privateHiddenParams = responseBody._hidden_params;
|
|
5239
5245
|
return firstFiniteNumber(getObjectNumber(responseBody, "response_cost"), getObjectNumber(responseBody, "responseCost"), getObjectNumber(responseBody, "cost"), getObjectNumber(responseBody, "cost_usd"), getObjectNumber(responseBody, "costUsd"), getObjectNumber(usage, "cost"), getObjectNumber(usage, "response_cost"), getObjectNumber(usage, "responseCost"), getObjectNumber(usage, "cost_usd"), getObjectNumber(usage, "costUsd"), getObjectNumber(hiddenParams, "response_cost"), getObjectNumber(privateHiddenParams, "response_cost"));
|
|
5240
5246
|
}
|
|
5247
|
+
function extractResponseHeaderCostUsd(responseHeaders) {
|
|
5248
|
+
if (!responseHeaders) return;
|
|
5249
|
+
for (const [key, value] of Object.entries(responseHeaders)) if (key.toLowerCase() === "x-litellm-response-cost") return parseFiniteNumber(value);
|
|
5250
|
+
}
|
|
5241
5251
|
function getObjectNumber(value, key) {
|
|
5242
5252
|
if (!value || typeof value !== "object") return;
|
|
5243
5253
|
const field = value[key];
|
|
5244
5254
|
if (typeof field === "number" && Number.isFinite(field)) return field;
|
|
5245
|
-
if (typeof field === "string" && field.trim().length > 0)
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5255
|
+
if (typeof field === "string" && field.trim().length > 0) return parseFiniteNumber(field);
|
|
5256
|
+
}
|
|
5257
|
+
function parseFiniteNumber(value) {
|
|
5258
|
+
const parsed = Number(value.trim());
|
|
5259
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
5249
5260
|
}
|
|
5250
5261
|
function firstFiniteNumber(...values) {
|
|
5251
5262
|
return values.find((value) => value !== void 0);
|
|
@@ -13704,4 +13715,4 @@ function formatDryRunSyncStatus(status) {
|
|
|
13704
13715
|
//#endregion
|
|
13705
13716
|
export { runTopchesterCli as t };
|
|
13706
13717
|
|
|
13707
|
-
//# sourceMappingURL=cli-
|
|
13718
|
+
//# sourceMappingURL=cli-CKfn9zSQ.mjs.map
|