@codehz/ai 0.1.7 → 0.2.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/index.d.mts CHANGED
@@ -99,9 +99,7 @@ type Usage = {
99
99
  reasoningTokens?: number;
100
100
  totalTokens?: number; /** Tokens read from prompt cache (OpenAI cached_tokens, Anthropic cache_read_input_tokens) */
101
101
  cachedInputTokens?: number; /** Tokens written to prompt cache (Anthropic cache_creation_input_tokens) */
102
- cacheWriteInputTokens?: number; /** Best-effort billable input (full-rate input; excludes discounted cache reads where known) */
103
- billableInputTokens?: number; /** Best-effort billable output (non-reasoning slice when provider gives reasoning breakdown) */
104
- billableOutputTokens?: number;
102
+ cacheWriteInputTokens?: number;
105
103
  };
106
104
  type BillingInfo = {
107
105
  amount?: number;
@@ -1084,7 +1082,7 @@ declare function usageFromAnthropicMessages(raw: {
1084
1082
  cache_read_input_tokens?: number;
1085
1083
  [key: string]: unknown;
1086
1084
  }): Partial<Usage>;
1087
- /** Ollama 流式 chunk(无 cache / reasoning 细分时仅填基础与 billable 镜像) */
1085
+ /** Ollama 流式 chunk */
1088
1086
  declare function usageFromOllama(raw: {
1089
1087
  prompt_eval_count?: number;
1090
1088
  eval_count?: number;
package/dist/index.mjs CHANGED
@@ -1020,16 +1020,6 @@ function record(obj) {
1020
1020
  for (const [key, value] of Object.entries(obj)) if (value !== void 0) out[key] = value;
1021
1021
  return out;
1022
1022
  }
1023
- function billableFromOpenAIStyle(inputTokens, outputTokens, cachedInputTokens, reasoningTokens) {
1024
- let billableInputTokens;
1025
- if (inputTokens !== void 0) billableInputTokens = cachedInputTokens !== void 0 ? Math.max(0, inputTokens - cachedInputTokens) : inputTokens;
1026
- let billableOutputTokens;
1027
- if (outputTokens !== void 0) billableOutputTokens = reasoningTokens !== void 0 ? Math.max(0, outputTokens - reasoningTokens) : outputTokens;
1028
- return record({
1029
- billableInputTokens,
1030
- billableOutputTokens
1031
- });
1032
- }
1033
1023
  /** OpenAI Chat Completions `usage` */
1034
1024
  function usageFromChatCompletions(raw) {
1035
1025
  const inputTokens = num(raw.prompt_tokens);
@@ -1041,8 +1031,7 @@ function usageFromChatCompletions(raw) {
1041
1031
  outputTokens,
1042
1032
  totalTokens: num(raw.total_tokens) ?? (inputTokens !== void 0 && outputTokens !== void 0 ? inputTokens + outputTokens : void 0),
1043
1033
  cachedInputTokens,
1044
- reasoningTokens,
1045
- ...billableFromOpenAIStyle(inputTokens, outputTokens, cachedInputTokens, reasoningTokens)
1034
+ reasoningTokens
1046
1035
  });
1047
1036
  }
1048
1037
  /** OpenAI Responses API `usage` */
@@ -1056,45 +1045,37 @@ function usageFromOpenAIResponses(raw) {
1056
1045
  outputTokens,
1057
1046
  totalTokens: num(raw.total_tokens) ?? (inputTokens !== void 0 && outputTokens !== void 0 ? inputTokens + outputTokens : void 0),
1058
1047
  cachedInputTokens,
1059
- reasoningTokens,
1060
- ...billableFromOpenAIStyle(inputTokens, outputTokens, cachedInputTokens, reasoningTokens)
1048
+ reasoningTokens
1061
1049
  });
1062
1050
  }
1063
1051
  /** Anthropic Messages `usage`(message_start / message_delta) */
1064
1052
  function usageFromAnthropicMessages(raw) {
1065
- const inputTokens = num(raw.input_tokens);
1053
+ const uncachedInputTokens = num(raw.input_tokens);
1066
1054
  const outputTokens = num(raw.output_tokens);
1067
1055
  const cacheWriteInputTokens = num(raw.cache_creation_input_tokens);
1068
1056
  const cachedInputTokens = num(raw.cache_read_input_tokens);
1069
1057
  const inputParts = [
1070
- inputTokens,
1058
+ uncachedInputTokens,
1071
1059
  cacheWriteInputTokens,
1072
1060
  cachedInputTokens
1073
1061
  ].filter((n) => n !== void 0);
1074
- const summedInput = inputParts.length > 0 ? inputParts.reduce((sum, n) => sum + n, 0) : void 0;
1075
- const totalTokens = summedInput !== void 0 && outputTokens !== void 0 ? summedInput + outputTokens : void 0;
1076
- let billableInputTokens;
1077
- if (inputTokens !== void 0 || cacheWriteInputTokens !== void 0) billableInputTokens = (inputTokens ?? 0) + (cacheWriteInputTokens ?? 0);
1062
+ const inputTokens = inputParts.length > 0 ? inputParts.reduce((sum, n) => sum + n, 0) : void 0;
1078
1063
  return record({
1079
1064
  inputTokens,
1080
1065
  outputTokens,
1081
- totalTokens,
1066
+ totalTokens: inputTokens !== void 0 && outputTokens !== void 0 ? inputTokens + outputTokens : void 0,
1082
1067
  cachedInputTokens,
1083
- cacheWriteInputTokens,
1084
- billableInputTokens,
1085
- billableOutputTokens: outputTokens
1068
+ cacheWriteInputTokens
1086
1069
  });
1087
1070
  }
1088
- /** Ollama 流式 chunk(无 cache / reasoning 细分时仅填基础与 billable 镜像) */
1071
+ /** Ollama 流式 chunk */
1089
1072
  function usageFromOllama(raw) {
1090
1073
  const inputTokens = num(raw.prompt_eval_count);
1091
1074
  const outputTokens = num(raw.eval_count);
1092
1075
  return record({
1093
1076
  inputTokens,
1094
1077
  outputTokens,
1095
- totalTokens: inputTokens !== void 0 && outputTokens !== void 0 ? inputTokens + outputTokens : void 0,
1096
- billableInputTokens: inputTokens,
1097
- billableOutputTokens: outputTokens
1078
+ totalTokens: inputTokens !== void 0 && outputTokens !== void 0 ? inputTokens + outputTokens : void 0
1098
1079
  });
1099
1080
  }
1100
1081
  //#endregion