llmist 4.0.0 → 5.1.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,
@@ -9541,13 +9545,24 @@ ${endPrefix}`
9541
9545
  observers: {
9542
9546
  ...hooks?.observers,
9543
9547
  onLLMCallStart: async (context) => {
9548
+ let inputTokens;
9549
+ try {
9550
+ if (this.client) {
9551
+ inputTokens = await this.client.countTokens(
9552
+ context.options.model,
9553
+ context.options.messages
9554
+ );
9555
+ }
9556
+ } catch {
9557
+ }
9544
9558
  onSubagentEvent({
9545
9559
  type: "llm_call_start",
9546
9560
  gadgetInvocationId: invocationId,
9547
9561
  depth,
9548
9562
  event: {
9549
9563
  iteration: context.iteration,
9550
- model: context.options.model
9564
+ model: context.options.model,
9565
+ inputTokens
9551
9566
  }
9552
9567
  });
9553
9568
  if (existingOnLLMCallStart) {
@@ -9562,8 +9577,13 @@ ${endPrefix}`
9562
9577
  event: {
9563
9578
  iteration: context.iteration,
9564
9579
  model: context.options.model,
9580
+ // Backward compat fields
9581
+ inputTokens: context.usage?.inputTokens,
9565
9582
  outputTokens: context.usage?.outputTokens,
9566
- finishReason: context.finishReason
9583
+ finishReason: context.finishReason ?? void 0,
9584
+ // Full usage object with cache details (for first-class display)
9585
+ usage: context.usage
9586
+ // Cost will be calculated by parent if it has model registry
9567
9587
  }
9568
9588
  });
9569
9589
  if (existingOnLLMCallComplete) {