topchester-ai 0.33.0 → 0.34.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
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as runTopchesterCli } from "./cli-Dietd7cK.mjs";
2
+ import { t as runTopchesterCli } from "./cli-jv4-Z3DZ.mjs";
3
3
  //#region src/bin.ts
4
4
  await runTopchesterCli();
5
5
  //#endregion
@@ -5145,7 +5145,7 @@ async function consumeReasoningStream(stream, onReasoning) {
5145
5145
  if (!part || typeof part !== "object") continue;
5146
5146
  const typedPart = part;
5147
5147
  if (typedPart.type === "error") throw typedPart.error;
5148
- if (typedPart.type === "raw" && hasUsageCostBody(typedPart.rawValue)) {
5148
+ if (typedPart.type === "raw" && hasUsageOrCostBody(typedPart.rawValue)) {
5149
5149
  rawUsageBody = typedPart.rawValue;
5150
5150
  continue;
5151
5151
  }
@@ -5170,8 +5170,8 @@ async function emitReasoningSummary(onReasoning, sawReasoningDelta, reasoningTex
5170
5170
  text: reasoningText
5171
5171
  });
5172
5172
  }
5173
- function hasUsageCostBody(value) {
5174
- return Boolean(value && typeof value === "object" && "usage" in value && value.usage && typeof value.usage === "object");
5173
+ function hasUsageOrCostBody(value) {
5174
+ return Boolean(value && typeof value === "object" && ("usage" in value && value.usage && typeof value.usage === "object" || extractResponseCostUsd(value) !== void 0));
5175
5175
  }
5176
5176
  function withRawUsageBody(response, rawUsageBody) {
5177
5177
  return rawUsageBody === void 0 ? response : {
@@ -5221,7 +5221,7 @@ function extractWarningMessages(warnings) {
5221
5221
  return warnings.map((warning) => formatErrorMessage$2(warning));
5222
5222
  }
5223
5223
  function normalizeUsage(usage, context) {
5224
- const costUsd = context && isOpenRouterProvider$1(context.providerId, context.providerConfig) ? extractOpenRouterCost(context.responseBody) : void 0;
5224
+ const costUsd = extractResponseCostUsd(context?.responseBody);
5225
5225
  if (!usage) return costUsd === void 0 ? void 0 : { costUsd };
5226
5226
  const normalized = {
5227
5227
  ...typeof usage.inputTokens === "number" ? { inputTokens: usage.inputTokens } : {},
@@ -5231,12 +5231,24 @@ function normalizeUsage(usage, context) {
5231
5231
  };
5232
5232
  return Object.keys(normalized).length > 0 ? normalized : void 0;
5233
5233
  }
5234
- function extractOpenRouterCost(responseBody) {
5234
+ function extractResponseCostUsd(responseBody) {
5235
5235
  if (!responseBody || typeof responseBody !== "object") return;
5236
5236
  const usage = responseBody.usage;
5237
- if (!usage || typeof usage !== "object") return;
5238
- const cost = usage.cost;
5239
- return typeof cost === "number" && Number.isFinite(cost) ? cost : void 0;
5237
+ const hiddenParams = responseBody.hidden_params;
5238
+ const privateHiddenParams = responseBody._hidden_params;
5239
+ 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
+ }
5241
+ function getObjectNumber(value, key) {
5242
+ if (!value || typeof value !== "object") return;
5243
+ const field = value[key];
5244
+ if (typeof field === "number" && Number.isFinite(field)) return field;
5245
+ if (typeof field === "string" && field.trim().length > 0) {
5246
+ const parsed = Number(field);
5247
+ return Number.isFinite(parsed) ? parsed : void 0;
5248
+ }
5249
+ }
5250
+ function firstFiniteNumber(...values) {
5251
+ return values.find((value) => value !== void 0);
5240
5252
  }
5241
5253
  function formatErrorMessage$2(error) {
5242
5254
  return error instanceof Error ? error.message : String(error);
@@ -13665,4 +13677,4 @@ function formatDryRunSyncStatus(status) {
13665
13677
  //#endregion
13666
13678
  export { runTopchesterCli as t };
13667
13679
 
13668
- //# sourceMappingURL=cli-Dietd7cK.mjs.map
13680
+ //# sourceMappingURL=cli-jv4-Z3DZ.mjs.map