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.
@@ -5005,15 +5005,16 @@ var init_agent = __esm({
5005
5005
  });
5006
5006
  } else if (event.type === "llm_call_end") {
5007
5007
  const info = event.event;
5008
+ const usage = info.usage ?? (info.outputTokens ? {
5009
+ inputTokens: info.inputTokens ?? 0,
5010
+ outputTokens: info.outputTokens,
5011
+ totalTokens: (info.inputTokens ?? 0) + info.outputTokens
5012
+ } : void 0);
5008
5013
  void this.hooks?.observers?.onLLMCallComplete?.({
5009
5014
  iteration: info.iteration,
5010
5015
  options: { model: info.model, messages: [] },
5011
5016
  finishReason: info.finishReason ?? null,
5012
- usage: info.outputTokens ? {
5013
- inputTokens: info.inputTokens ?? 0,
5014
- outputTokens: info.outputTokens,
5015
- totalTokens: (info.inputTokens ?? 0) + info.outputTokens
5016
- } : void 0,
5017
+ usage,
5017
5018
  rawResponse: "",
5018
5019
  finalMessage: "",
5019
5020
  logger: this.logger,
@@ -6278,8 +6279,13 @@ ${endPrefix}`
6278
6279
  event: {
6279
6280
  iteration: context.iteration,
6280
6281
  model: context.options.model,
6282
+ // Backward compat fields
6283
+ inputTokens: context.usage?.inputTokens,
6281
6284
  outputTokens: context.usage?.outputTokens,
6282
- finishReason: context.finishReason
6285
+ finishReason: context.finishReason ?? void 0,
6286
+ // Full usage object with cache details (for first-class display)
6287
+ usage: context.usage
6288
+ // Cost will be calculated by parent if it has model registry
6283
6289
  }
6284
6290
  });
6285
6291
  if (existingOnLLMCallComplete) {
@@ -8133,6 +8139,9 @@ var init_gemini = __esm({
8133
8139
  async countTokens(messages, descriptor, _spec) {
8134
8140
  const client = this.client;
8135
8141
  const contents = this.convertMessagesToContents(messages);
8142
+ if (!contents || contents.length === 0) {
8143
+ return 0;
8144
+ }
8136
8145
  try {
8137
8146
  const response = await client.models.countTokens({
8138
8147
  model: descriptor.name,
@@ -11698,4 +11707,4 @@ export {
11698
11707
  createEmptyStream,
11699
11708
  createErrorStream
11700
11709
  };
11701
- //# sourceMappingURL=chunk-RHR2M6T6.js.map
11710
+ //# sourceMappingURL=chunk-3SZIQI45.js.map