@llmops/app 0.6.2 → 0.6.3

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/index.cjs CHANGED
@@ -18384,7 +18384,7 @@ function getGlobalTraceBatchWriter(deps, config$1) {
18384
18384
 
18385
18385
  //#endregion
18386
18386
  //#region src/server/middlewares/costTracking.ts
18387
- const pricingProvider = (0, __llmops_core.getDefaultPricingProvider)();
18387
+ const pricingProvider$1 = (0, __llmops_core.getDefaultPricingProvider)();
18388
18388
  /**
18389
18389
  * Transform gateway hook results to our schema format for telemetry
18390
18390
  */
@@ -18654,7 +18654,7 @@ async function processUsageAndLog(params) {
18654
18654
  let outputCost = 0;
18655
18655
  let cacheSavings = 0;
18656
18656
  if (usage && usage.promptTokens + usage.completionTokens > 0) try {
18657
- const pricing = await pricingProvider.getModelPricing(provider, model);
18657
+ const pricing = await pricingProvider$1.getModelPricing(provider, model);
18658
18658
  if (pricing) {
18659
18659
  const costResult = (0, __llmops_core.calculateCacheAwareCost)({
18660
18660
  promptTokens: usage.promptTokens,
@@ -18873,6 +18873,7 @@ function extractTypedFields(attrs) {
18873
18873
  output
18874
18874
  };
18875
18875
  }
18876
+ const pricingProvider = (0, __llmops_core.getDefaultPricingProvider)();
18876
18877
  /**
18877
18878
  * OTLP ingestion endpoint
18878
18879
  * Accepts OTLP JSON (ExportTraceServiceRequest) format
@@ -18913,6 +18914,16 @@ const app$3 = new hono.Hono().post("/v1/traces", async (c) => {
18913
18914
  const durationMs = endTime ? endTime.getTime() - startTime.getTime() : null;
18914
18915
  const spanStatus = otlpSpan.status?.code ?? 0;
18915
18916
  const traceStatus = spanStatus === 2 ? "error" : spanStatus === 1 ? "ok" : "unset";
18917
+ let cost = 0;
18918
+ if (typed.provider && typed.model && (typed.promptTokens > 0 || typed.completionTokens > 0)) try {
18919
+ const pricing = await pricingProvider.getModelPricing(typed.provider, typed.model);
18920
+ if (pricing) cost = (0, __llmops_core.calculateCacheAwareCost)({
18921
+ promptTokens: typed.promptTokens,
18922
+ completionTokens: typed.completionTokens
18923
+ }, pricing, typed.provider).totalCost;
18924
+ } catch (e) {
18925
+ __llmops_core.logger.debug(`[OTLP] Failed to calculate cost for ${typed.provider}/${typed.model}: ${e instanceof Error ? e.message : String(e)}`);
18926
+ }
18916
18927
  const spanData = {
18917
18928
  traceId: otlpSpan.traceId,
18918
18929
  spanId: otlpSpan.spanId,
@@ -18929,7 +18940,7 @@ const app$3 = new hono.Hono().post("/v1/traces", async (c) => {
18929
18940
  promptTokens: typed.promptTokens,
18930
18941
  completionTokens: typed.completionTokens,
18931
18942
  totalTokens: typed.totalTokens,
18932
- cost: 0,
18943
+ cost,
18933
18944
  source: "otlp",
18934
18945
  input: typed.input,
18935
18946
  output: typed.output,
@@ -18955,7 +18966,7 @@ const app$3 = new hono.Hono().post("/v1/traces", async (c) => {
18955
18966
  totalInputTokens: typed.promptTokens,
18956
18967
  totalOutputTokens: typed.completionTokens,
18957
18968
  totalTokens: typed.totalTokens,
18958
- totalCost: 0,
18969
+ totalCost: cost,
18959
18970
  tags: {},
18960
18971
  metadata: {}
18961
18972
  };
package/dist/index.mjs CHANGED
@@ -18356,7 +18356,7 @@ function getGlobalTraceBatchWriter(deps, config$1) {
18356
18356
 
18357
18357
  //#endregion
18358
18358
  //#region src/server/middlewares/costTracking.ts
18359
- const pricingProvider = getDefaultPricingProvider();
18359
+ const pricingProvider$1 = getDefaultPricingProvider();
18360
18360
  /**
18361
18361
  * Transform gateway hook results to our schema format for telemetry
18362
18362
  */
@@ -18626,7 +18626,7 @@ async function processUsageAndLog(params) {
18626
18626
  let outputCost = 0;
18627
18627
  let cacheSavings = 0;
18628
18628
  if (usage && usage.promptTokens + usage.completionTokens > 0) try {
18629
- const pricing = await pricingProvider.getModelPricing(provider, model);
18629
+ const pricing = await pricingProvider$1.getModelPricing(provider, model);
18630
18630
  if (pricing) {
18631
18631
  const costResult = calculateCacheAwareCost({
18632
18632
  promptTokens: usage.promptTokens,
@@ -18845,6 +18845,7 @@ function extractTypedFields(attrs) {
18845
18845
  output
18846
18846
  };
18847
18847
  }
18848
+ const pricingProvider = getDefaultPricingProvider();
18848
18849
  /**
18849
18850
  * OTLP ingestion endpoint
18850
18851
  * Accepts OTLP JSON (ExportTraceServiceRequest) format
@@ -18885,6 +18886,16 @@ const app$3 = new Hono().post("/v1/traces", async (c) => {
18885
18886
  const durationMs = endTime ? endTime.getTime() - startTime.getTime() : null;
18886
18887
  const spanStatus = otlpSpan.status?.code ?? 0;
18887
18888
  const traceStatus = spanStatus === 2 ? "error" : spanStatus === 1 ? "ok" : "unset";
18889
+ let cost = 0;
18890
+ if (typed.provider && typed.model && (typed.promptTokens > 0 || typed.completionTokens > 0)) try {
18891
+ const pricing = await pricingProvider.getModelPricing(typed.provider, typed.model);
18892
+ if (pricing) cost = calculateCacheAwareCost({
18893
+ promptTokens: typed.promptTokens,
18894
+ completionTokens: typed.completionTokens
18895
+ }, pricing, typed.provider).totalCost;
18896
+ } catch (e) {
18897
+ logger.debug(`[OTLP] Failed to calculate cost for ${typed.provider}/${typed.model}: ${e instanceof Error ? e.message : String(e)}`);
18898
+ }
18888
18899
  const spanData = {
18889
18900
  traceId: otlpSpan.traceId,
18890
18901
  spanId: otlpSpan.spanId,
@@ -18901,7 +18912,7 @@ const app$3 = new Hono().post("/v1/traces", async (c) => {
18901
18912
  promptTokens: typed.promptTokens,
18902
18913
  completionTokens: typed.completionTokens,
18903
18914
  totalTokens: typed.totalTokens,
18904
- cost: 0,
18915
+ cost,
18905
18916
  source: "otlp",
18906
18917
  input: typed.input,
18907
18918
  output: typed.output,
@@ -18927,7 +18938,7 @@ const app$3 = new Hono().post("/v1/traces", async (c) => {
18927
18938
  totalInputTokens: typed.promptTokens,
18928
18939
  totalOutputTokens: typed.completionTokens,
18929
18940
  totalTokens: typed.totalTokens,
18930
- totalCost: 0,
18941
+ totalCost: cost,
18931
18942
  tags: {},
18932
18943
  metadata: {}
18933
18944
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@llmops/app",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "LLMOps application with server and client",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -76,8 +76,8 @@
76
76
  "react-hook-form": "^7.68.0",
77
77
  "recharts": "^3.6.0",
78
78
  "uuid": "^13.0.0",
79
- "@llmops/core": "^0.6.2",
80
- "@llmops/gateway": "^0.6.2"
79
+ "@llmops/core": "^0.6.3",
80
+ "@llmops/gateway": "^0.6.3"
81
81
  },
82
82
  "peerDependencies": {
83
83
  "react": "^19.2.1",