@common_ch/common 1.0.293 → 1.0.298

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.
@@ -1,4 +1,5 @@
1
1
  import mongoose from 'mongoose';
2
+ import { ToolName } from '../../services/pricing/pricingTable';
2
3
  export declare enum RequestType {
3
4
  chat = "chat",
4
5
  image = "create_image",
@@ -19,6 +20,7 @@ export interface UsageAiAttrs {
19
20
  totalTokens?: number;
20
21
  cost: number;
21
22
  description: string;
23
+ tools: ToolName[];
22
24
  createdAt?: number;
23
25
  updatedAt?: number;
24
26
  }
@@ -38,6 +40,7 @@ export interface UsageAiDoc extends mongoose.Document {
38
40
  totalTokens?: number;
39
41
  cost: number;
40
42
  description: string;
43
+ tools: ToolName[];
41
44
  createdAt?: number;
42
45
  updatedAt?: number;
43
46
  }
@@ -62,6 +62,10 @@ const usageAiSchema = new mongoose_1.default.Schema({
62
62
  type: Number,
63
63
  require: true,
64
64
  },
65
+ tools: [{
66
+ type: String,
67
+ required: false
68
+ }],
65
69
  createdAt: {
66
70
  type: mongoose_1.default.Schema.Types.Date,
67
71
  },
@@ -1,2 +1,3 @@
1
1
  import { AiOptionNamesEnum } from "../../enums/ai";
2
- export declare function calculateCostChat(model: AiOptionNamesEnum, promptTokens: number, cacheToken: number, completionTokens: number): number;
2
+ import { ToolName } from "./pricingTable";
3
+ export declare function calculateCostChat(model: AiOptionNamesEnum, promptTokens: number, cacheToken: number, completionTokens: number, toolsUsed?: ToolName[]): number;
@@ -2,12 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateCostChat = calculateCostChat;
4
4
  const pricingTable_1 = require("./pricingTable");
5
- function calculateCostChat(model, promptTokens, cacheToken, completionTokens) {
5
+ function calculateCostChat(model, promptTokens, cacheToken, completionTokens, toolsUsed = []) {
6
6
  const pricing = pricingTable_1.pricingTableChat[model];
7
7
  if (!pricing)
8
8
  throw new Error(`No pricing found for model: ${model}`);
9
- const cost = (promptTokens / 1000000) * pricing.prompt +
9
+ let cost = (promptTokens / 1000000) * pricing.prompt +
10
10
  (cacheToken / 1000000) * pricing.cache +
11
11
  (completionTokens / 1000000) * pricing.completion;
12
- return parseFloat(cost.toFixed(6));
12
+ let multiplier = 1;
13
+ for (const tool of toolsUsed) {
14
+ if (pricingTable_1.toolOverhead[tool]) {
15
+ multiplier *= pricingTable_1.toolOverhead[tool];
16
+ }
17
+ }
18
+ const finalCost = cost * multiplier;
19
+ return parseFloat(finalCost.toFixed(6));
13
20
  }
@@ -16,4 +16,6 @@ export declare const pricingTableChat: Record<string, ModelPricingChat>;
16
16
  export declare const pricingTableImage: Record<string, ModelPricingImage>;
17
17
  export declare const pricingTableAudio: Record<string, ModelPricingAudio>;
18
18
  export declare const pricingTableTTS: Record<string, ModelPricingTTS>;
19
+ export type ToolName = "web_search" | "code_interpreter" | "file_search" | "image_generation" | "speech_to_text" | "text_to_speech" | string;
20
+ export declare const toolOverhead: Record<ToolName, number>;
19
21
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pricingTableTTS = exports.pricingTableAudio = exports.pricingTableImage = exports.pricingTableChat = void 0;
3
+ exports.toolOverhead = exports.pricingTableTTS = exports.pricingTableAudio = exports.pricingTableImage = exports.pricingTableChat = void 0;
4
4
  exports.pricingTableChat = {
5
5
  // --- GPT-5 family ---
6
6
  'gpt-5-mini': { prompt: 0.25, cache: 0.025, completion: 2.0 },
@@ -29,3 +29,11 @@ exports.pricingTableTTS = {
29
29
  // --- Text-to-Speech ---
30
30
  'tts-1': { audioOut: 0.015 }, // $0.015 / minute
31
31
  };
32
+ exports.toolOverhead = {
33
+ web_search: 1.1,
34
+ code_interpreter: 1.25,
35
+ file_search: 1.15,
36
+ image_generation: 1.0,
37
+ speech_to_text: 1.0,
38
+ text_to_speech: 1.0,
39
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@common_ch/common",
3
- "version": "1.0.293",
3
+ "version": "1.0.298",
4
4
  "main": "./build/index.js",
5
5
  "types": "./build/index.d.ts",
6
6
  "files": [