llmist 4.0.0 → 5.0.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.cjs CHANGED
@@ -5018,15 +5018,16 @@ var init_agent = __esm({
5018
5018
  });
5019
5019
  } else if (event.type === "llm_call_end") {
5020
5020
  const info = event.event;
5021
+ const usage = info.usage ?? (info.outputTokens ? {
5022
+ inputTokens: info.inputTokens ?? 0,
5023
+ outputTokens: info.outputTokens,
5024
+ totalTokens: (info.inputTokens ?? 0) + info.outputTokens
5025
+ } : void 0);
5021
5026
  void this.hooks?.observers?.onLLMCallComplete?.({
5022
5027
  iteration: info.iteration,
5023
5028
  options: { model: info.model, messages: [] },
5024
5029
  finishReason: info.finishReason ?? null,
5025
- usage: info.outputTokens ? {
5026
- inputTokens: info.inputTokens ?? 0,
5027
- outputTokens: info.outputTokens,
5028
- totalTokens: (info.inputTokens ?? 0) + info.outputTokens
5029
- } : void 0,
5030
+ usage,
5030
5031
  rawResponse: "",
5031
5032
  finalMessage: "",
5032
5033
  logger: this.logger,
@@ -7069,6 +7070,9 @@ var init_gemini = __esm({
7069
7070
  async countTokens(messages, descriptor, _spec) {
7070
7071
  const client = this.client;
7071
7072
  const contents = this.convertMessagesToContents(messages);
7073
+ if (!contents || contents.length === 0) {
7074
+ return 0;
7075
+ }
7072
7076
  try {
7073
7077
  const response = await client.models.countTokens({
7074
7078
  model: descriptor.name,
@@ -9562,8 +9566,13 @@ ${endPrefix}`
9562
9566
  event: {
9563
9567
  iteration: context.iteration,
9564
9568
  model: context.options.model,
9569
+ // Backward compat fields
9570
+ inputTokens: context.usage?.inputTokens,
9565
9571
  outputTokens: context.usage?.outputTokens,
9566
- finishReason: context.finishReason
9572
+ finishReason: context.finishReason ?? void 0,
9573
+ // Full usage object with cache details (for first-class display)
9574
+ usage: context.usage
9575
+ // Cost will be calculated by parent if it has model registry
9567
9576
  }
9568
9577
  });
9569
9578
  if (existingOnLLMCallComplete) {