@ccusage/amp 18.0.7 → 18.0.9

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.
Files changed (2) hide show
  1. package/dist/index.js +28 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import process$1 from "node:process";
4
4
  import a, { readFile } from "node:fs/promises";
5
5
  import path, { sep } from "node:path";
6
6
  import b from "node:fs";
7
- import F from "node:os";
7
+ import F, { homedir } from "node:os";
8
8
  import * as nativeFs$1 from "fs";
9
9
  import nativeFs from "fs";
10
10
  import path$1, { basename, dirname, normalize, posix, relative, resolve, sep as sep$1 } from "path";
@@ -1143,7 +1143,7 @@ async function executeCommand(cmd, ctx, name$1) {
1143
1143
  //#endregion
1144
1144
  //#region package.json
1145
1145
  var name = "@ccusage/amp";
1146
- var version = "18.0.7";
1146
+ var version = "18.0.9";
1147
1147
  var description = "Usage analysis tool for Amp CLI sessions";
1148
1148
 
1149
1149
  //#endregion
@@ -6840,7 +6840,7 @@ const DEFAULT_AMP_PATH = ".local/share/amp";
6840
6840
  /**
6841
6841
  * User home directory
6842
6842
  */
6843
- const USER_HOME_DIR = process$1.env.HOME ?? process$1.env.USERPROFILE ?? process$1.cwd();
6843
+ const USER_HOME_DIR = homedir();
6844
6844
  /**
6845
6845
  * Default Amp data directory (absolute path)
6846
6846
  */
@@ -8129,7 +8129,7 @@ if (import.meta.vitest != null) describe("loadAmpUsageEvents", () => {
8129
8129
  it("handles missing directories gracefully", async () => {
8130
8130
  const { events, missingDirectories } = await loadAmpUsageEvents({ threadDirs: ["/nonexistent/path"] });
8131
8131
  expect(events).toEqual([]);
8132
- expect(missingDirectories).toContain("/nonexistent/path");
8132
+ expect(missingDirectories).toContain(path.resolve("/nonexistent/path"));
8133
8133
  });
8134
8134
  it("handles malformed JSON gracefully", async () => {
8135
8135
  try {
@@ -8545,6 +8545,12 @@ async function prefetchAmpPricing() {
8545
8545
  //#endregion
8546
8546
  //#region src/pricing.ts
8547
8547
  const AMP_PROVIDER_PREFIXES = ["anthropic/"];
8548
+ const ZERO_MODEL_PRICING = {
8549
+ inputCostPerMToken: 0,
8550
+ cachedInputCostPerMToken: 0,
8551
+ cacheCreationCostPerMToken: 0,
8552
+ outputCostPerMToken: 0
8553
+ };
8548
8554
  function toPerMillion(value, fallback) {
8549
8555
  return (value ?? fallback ?? 0) * MILLION;
8550
8556
  }
@@ -8566,7 +8572,10 @@ var AmpPricingSource = class {
8566
8572
  const directLookup = await this.fetcher.getModelPricing(model);
8567
8573
  if (isFailure(directLookup)) throw directLookup.error;
8568
8574
  const pricing = directLookup.value;
8569
- if (pricing == null) throw new Error(`Pricing not found for model ${model}`);
8575
+ if (pricing == null) {
8576
+ logger.warn(`Pricing not found for model ${model}; defaulting to zero-cost pricing.`);
8577
+ return ZERO_MODEL_PRICING;
8578
+ }
8570
8579
  return {
8571
8580
  inputCostPerMToken: toPerMillion(pricing.input_cost_per_token),
8572
8581
  cachedInputCostPerMToken: toPerMillion(pricing.cache_read_input_token_cost, pricing.input_cost_per_token),
@@ -8635,6 +8644,20 @@ if (import.meta.vitest != null) describe("AmpPricingSource", () => {
8635
8644
  _usingCtx3.d();
8636
8645
  }
8637
8646
  });
8647
+ it("falls back to zero pricing for unknown models", async () => {
8648
+ try {
8649
+ var _usingCtx4 = _usingCtx();
8650
+ const pricing = await _usingCtx4.u(new AmpPricingSource({
8651
+ offline: true,
8652
+ offlineLoader: async () => ({})
8653
+ })).getPricing("anthropic/unknown");
8654
+ expect(pricing).toEqual(ZERO_MODEL_PRICING);
8655
+ } catch (_$1) {
8656
+ _usingCtx4.e = _$1;
8657
+ } finally {
8658
+ _usingCtx4.d();
8659
+ }
8660
+ });
8638
8661
  });
8639
8662
 
8640
8663
  //#endregion
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ccusage/amp",
3
3
  "type": "module",
4
- "version": "18.0.7",
4
+ "version": "18.0.9",
5
5
  "description": "Usage analysis tool for Amp CLI sessions",
6
6
  "author": "ryoppippi",
7
7
  "license": "MIT",