@ccusage/amp 18.0.8 → 18.0.10
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.js +83 -7
- 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.
|
|
1146
|
+
var version = "18.0.10";
|
|
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 =
|
|
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 {
|
|
@@ -8183,7 +8183,8 @@ const liteLLMModelPricingSchema = object({
|
|
|
8183
8183
|
cache_creation_input_token_cost_above_200k_tokens: optional(number()),
|
|
8184
8184
|
cache_read_input_token_cost_above_200k_tokens: optional(number()),
|
|
8185
8185
|
input_cost_per_token_above_128k_tokens: optional(number()),
|
|
8186
|
-
output_cost_per_token_above_128k_tokens: optional(number())
|
|
8186
|
+
output_cost_per_token_above_128k_tokens: optional(number()),
|
|
8187
|
+
provider_specific_entry: optional(object({ fast: optional(number()) }))
|
|
8187
8188
|
});
|
|
8188
8189
|
const DEFAULT_PROVIDER_PREFIXES = [
|
|
8189
8190
|
"anthropic/",
|
|
@@ -8343,11 +8344,13 @@ var LiteLLMPricingFetcher = class {
|
|
|
8343
8344
|
const cacheReadCost = calculateTieredCost(tokens.cache_read_input_tokens, pricing.cache_read_input_token_cost, pricing.cache_read_input_token_cost_above_200k_tokens);
|
|
8344
8345
|
return inputCost + outputCost + cacheCreationCost + cacheReadCost;
|
|
8345
8346
|
}
|
|
8346
|
-
async calculateCostFromTokens(tokens, modelName) {
|
|
8347
|
+
async calculateCostFromTokens(tokens, modelName, options) {
|
|
8347
8348
|
if (modelName == null || modelName === "") return succeed(0);
|
|
8348
8349
|
return pipe(this.getModelPricing(modelName), andThen((pricing) => {
|
|
8349
8350
|
if (pricing == null) return fail(/* @__PURE__ */ new Error(`Model pricing not found for ${modelName}`));
|
|
8350
|
-
|
|
8351
|
+
const baseCost = this.calculateCostFromPricing(tokens, pricing);
|
|
8352
|
+
const multiplier = options?.speed === "fast" ? pricing.provider_specific_entry?.fast ?? 1 : 1;
|
|
8353
|
+
return succeed(baseCost * multiplier);
|
|
8351
8354
|
}));
|
|
8352
8355
|
}
|
|
8353
8356
|
};
|
|
@@ -8501,6 +8504,79 @@ if (import.meta.vitest != null) describe("LiteLLMPricingFetcher", () => {
|
|
|
8501
8504
|
_usingCtx7.d();
|
|
8502
8505
|
}
|
|
8503
8506
|
});
|
|
8507
|
+
it("applies fast speed multiplier from provider_specific_entry", async () => {
|
|
8508
|
+
try {
|
|
8509
|
+
var _usingCtx8 = _usingCtx();
|
|
8510
|
+
const fetcher = _usingCtx8.u(new LiteLLMPricingFetcher({
|
|
8511
|
+
offline: true,
|
|
8512
|
+
offlineLoader: async () => ({ "claude-opus-4-6": {
|
|
8513
|
+
input_cost_per_token: 5e-6,
|
|
8514
|
+
output_cost_per_token: 25e-6,
|
|
8515
|
+
provider_specific_entry: { fast: 6 }
|
|
8516
|
+
} })
|
|
8517
|
+
}));
|
|
8518
|
+
const tokens = {
|
|
8519
|
+
input_tokens: 1e3,
|
|
8520
|
+
output_tokens: 500
|
|
8521
|
+
};
|
|
8522
|
+
const standardCost = await unwrap(fetcher.calculateCostFromTokens(tokens, "claude-opus-4-6"));
|
|
8523
|
+
const fastCost = await unwrap(fetcher.calculateCostFromTokens(tokens, "claude-opus-4-6", { speed: "fast" }));
|
|
8524
|
+
const expectedStandard = .0175;
|
|
8525
|
+
expect(standardCost).toBeCloseTo(expectedStandard);
|
|
8526
|
+
expect(fastCost).toBeCloseTo(expectedStandard * 6);
|
|
8527
|
+
} catch (_$1) {
|
|
8528
|
+
_usingCtx8.e = _$1;
|
|
8529
|
+
} finally {
|
|
8530
|
+
_usingCtx8.d();
|
|
8531
|
+
}
|
|
8532
|
+
});
|
|
8533
|
+
it("defaults to 1x multiplier when provider_specific_entry has no fast field", async () => {
|
|
8534
|
+
try {
|
|
8535
|
+
var _usingCtx9 = _usingCtx();
|
|
8536
|
+
const fetcher = _usingCtx9.u(new LiteLLMPricingFetcher({
|
|
8537
|
+
offline: true,
|
|
8538
|
+
offlineLoader: async () => ({ "claude-sonnet-4-6": {
|
|
8539
|
+
input_cost_per_token: 3e-6,
|
|
8540
|
+
output_cost_per_token: 15e-6
|
|
8541
|
+
} })
|
|
8542
|
+
}));
|
|
8543
|
+
const tokens = {
|
|
8544
|
+
input_tokens: 1e3,
|
|
8545
|
+
output_tokens: 500
|
|
8546
|
+
};
|
|
8547
|
+
const standardCost = await unwrap(fetcher.calculateCostFromTokens(tokens, "claude-sonnet-4-6"));
|
|
8548
|
+
const fastCost = await unwrap(fetcher.calculateCostFromTokens(tokens, "claude-sonnet-4-6", { speed: "fast" }));
|
|
8549
|
+
expect(fastCost).toBeCloseTo(standardCost);
|
|
8550
|
+
} catch (_$1) {
|
|
8551
|
+
_usingCtx9.e = _$1;
|
|
8552
|
+
} finally {
|
|
8553
|
+
_usingCtx9.d();
|
|
8554
|
+
}
|
|
8555
|
+
});
|
|
8556
|
+
it("does not apply multiplier when speed is standard", async () => {
|
|
8557
|
+
try {
|
|
8558
|
+
var _usingCtx10 = _usingCtx();
|
|
8559
|
+
const fetcher = _usingCtx10.u(new LiteLLMPricingFetcher({
|
|
8560
|
+
offline: true,
|
|
8561
|
+
offlineLoader: async () => ({ "claude-opus-4-6": {
|
|
8562
|
+
input_cost_per_token: 5e-6,
|
|
8563
|
+
output_cost_per_token: 25e-6,
|
|
8564
|
+
provider_specific_entry: { fast: 6 }
|
|
8565
|
+
} })
|
|
8566
|
+
}));
|
|
8567
|
+
const tokens = {
|
|
8568
|
+
input_tokens: 1e3,
|
|
8569
|
+
output_tokens: 500
|
|
8570
|
+
};
|
|
8571
|
+
const noSpeedCost = await unwrap(fetcher.calculateCostFromTokens(tokens, "claude-opus-4-6"));
|
|
8572
|
+
const standardCost = await unwrap(fetcher.calculateCostFromTokens(tokens, "claude-opus-4-6", { speed: "standard" }));
|
|
8573
|
+
expect(standardCost).toBeCloseTo(noSpeedCost);
|
|
8574
|
+
} catch (_$1) {
|
|
8575
|
+
_usingCtx10.e = _$1;
|
|
8576
|
+
} finally {
|
|
8577
|
+
_usingCtx10.d();
|
|
8578
|
+
}
|
|
8579
|
+
});
|
|
8504
8580
|
});
|
|
8505
8581
|
|
|
8506
8582
|
//#endregion
|