@aiusage/cli 1.5.1 → 1.5.2

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/cli.js +23 -3
  2. package/package.json +9 -9
package/dist/cli.js CHANGED
@@ -1637,6 +1637,8 @@ function getRangeLabel(range) {
1637
1637
  return "\u6700\u8FD1 90 \u5929";
1638
1638
  case "all":
1639
1639
  return "\u5168\u90E8\u5386\u53F2";
1640
+ case "today":
1641
+ return "\u4ECA\u5929";
1640
1642
  }
1641
1643
  }
1642
1644
  function buildPresetDates(range) {
@@ -1975,6 +1977,8 @@ var FAST_MULTIPLIER = 6, CLAUDE_PRICING = {
1975
1977
  "claude-haiku-3-5": { input: 0.8, cache_write_5m: 1, cache_write_1h: 1.6, cache_read: 0.08, output: 4 },
1976
1978
  "claude-haiku-3": { input: 0.25, cache_write_5m: 0.3, cache_write_1h: 0.5, cache_read: 0.03, output: 1.25 }
1977
1979
  }, OPENAI_PRICING = {
1980
+ "gpt-5.5-pro": { input: 30, cached_input: null, output: 180, estimated: !1 },
1981
+ "gpt-5.5": { input: 5, cached_input: 0.5, output: 30, estimated: !1 },
1978
1982
  "gpt-5.4-pro": { input: 30, cached_input: null, output: 180, estimated: !1 },
1979
1983
  "gpt-5.4": { input: 2.5, cached_input: 0.25, output: 15, estimated: !1 },
1980
1984
  "gpt-5.4-mini": { input: 0.75, cached_input: 0.075, output: 4.5, estimated: !1 },
@@ -2027,7 +2031,8 @@ var FAST_MULTIPLIER = 6, CLAUDE_PRICING = {
2027
2031
  "text-embedding-3-small": { input: 0.02, cached_input: null, output: 0, estimated: !1 },
2028
2032
  "text-embedding-3-large": { input: 0.13, cached_input: null, output: 0, estimated: !1 },
2029
2033
  "text-embedding-ada-002": { input: 0.1, cached_input: null, output: 0, estimated: !1 },
2030
- "codex-mini-latest": { input: 1.5, cached_input: 0.375, output: 6, estimated: !1 }
2034
+ "codex-mini-latest": { input: 1.5, cached_input: 0.375, output: 6, estimated: !1 },
2035
+ "codex-auto-review": { input: 2.5, cached_input: 0.25, output: 15, estimated: !0, estimatedFrom: "GPT-5.4" }
2031
2036
  }, GEMINI_PRICING = {
2032
2037
  "gemini-3-flash": { input: 0.1, cache_read: 0.025, output: 0.4 },
2033
2038
  "gemini-2.0-flash": { input: 0.1, cache_read: 0.025, output: 0.4 },
@@ -2063,7 +2068,7 @@ function calculateBreakdownCost(breakdown, warnings) {
2063
2068
  if (!resolved)
2064
2069
  return warnings.add(`Codex/OpenAI \u6A21\u578B ${breakdown.model} \u672A\u914D\u7F6E\u516C\u5F00\u5355\u4EF7\uFF0C\u5DF2\u8DF3\u8FC7\u6210\u672C\u4F30\u7B97\u3002`), 0;
2065
2070
  let pricing = OPENAI_PRICING[resolved.model];
2066
- return resolved.normalized ? warnings.add(`${breakdown.model} \u5DF2\u6309 ${resolved.model} \u7684\u516C\u5F00\u5355\u4EF7\u4F30\u7B97\u3002`) : pricing.estimated && warnings.add(`${breakdown.model} \u672A\u5728\u516C\u5F00\u4EF7\u76EE\u8868\u5355\u5217\uFF0C\u5F53\u524D\u6309 GPT-5 \u516C\u5F00\u5355\u4EF7\u4F30\u7B97\u3002`), breakdown.inputTokens / 1e6 * pricing.input + breakdown.cachedInputTokens / 1e6 * (pricing.cached_input ?? 0) + breakdown.outputTokens / 1e6 * pricing.output;
2071
+ return resolved.normalized ? warnings.add(`${breakdown.model} \u5DF2\u6309 ${resolved.model} \u7684\u516C\u5F00\u5355\u4EF7\u4F30\u7B97\u3002`) : pricing.estimated && warnings.add(`${breakdown.model} \u672A\u5728\u516C\u5F00\u4EF7\u76EE\u8868\u5355\u5217\uFF0C\u5F53\u524D\u6309 ${pricing.estimatedFrom ?? "GPT-5"} \u516C\u5F00\u5355\u4EF7\u4F30\u7B97\u3002`), breakdown.inputTokens / 1e6 * pricing.input + breakdown.cachedInputTokens / 1e6 * (pricing.cached_input ?? 0) + breakdown.outputTokens / 1e6 * pricing.output;
2067
2072
  }
2068
2073
  if (breakdown.provider === "google" && breakdown.product === "gemini-cli") {
2069
2074
  let resolved = resolveModel(breakdown.model, GEMINI_PRICING);
@@ -2472,7 +2477,13 @@ function defaultLookbackDays(config) {
2472
2477
  return config.lookbackDays ?? DEFAULT_LOOKBACK_DAYS;
2473
2478
  }
2474
2479
  async function requestJson(url, init) {
2475
- let response = await fetch(url, init), text = await response.text(), data = null;
2480
+ let response;
2481
+ try {
2482
+ response = await fetch(url, init);
2483
+ } catch (err) {
2484
+ throw new Error(`\u65E0\u6CD5\u8FDE\u63A5 ${url}\uFF1A${describeFetchError(err)}`, { cause: err });
2485
+ }
2486
+ let text = await response.text(), data = null;
2476
2487
  if (text)
2477
2488
  try {
2478
2489
  data = JSON.parse(text);
@@ -2487,6 +2498,13 @@ async function requestJson(url, init) {
2487
2498
  throw new Error("\u670D\u52A1\u7AEF\u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94");
2488
2499
  return data;
2489
2500
  }
2501
+ function describeFetchError(err) {
2502
+ if (!(err instanceof Error)) return String(err);
2503
+ let cause = err.cause, parts = [];
2504
+ cause?.code && parts.push(cause.code);
2505
+ let causeMsg = cause?.message ?? cause?.errors?.[0]?.message;
2506
+ return causeMsg && causeMsg !== err.message && parts.push(causeMsg), parts.length === 0 ? err.message : `${err.message} (${parts.join(": ")})`;
2507
+ }
2490
2508
 
2491
2509
  // src/schedule.ts
2492
2510
  import { mkdir as mkdir2, readFile as readFile15, stat, unlink, writeFile as writeFile2 } from "node:fs/promises";
@@ -3250,6 +3268,8 @@ async function runSync(flags) {
3250
3268
  if (allTargets.length === 0)
3251
3269
  throw new Error("\u672A\u914D\u7F6E\u4EFB\u4F55\u4E0A\u62A5\u76EE\u6807\uFF0C\u8BF7\u5148\u6267\u884C aiusage enroll");
3252
3270
  let deviceId = resolveRequiredString(void 0, config.deviceId, "\u7F3A\u5C11 deviceId\uFF0C\u8BF7\u5148\u6267\u884C enroll"), targetName = resolveOptionalString(flags.target, void 0), targets = targetName ? [findTargetOrThrow(config, targetName)] : allTargets, { dates: targetDates } = resolveDateParams(flags, config);
3271
+ if (!targetDates)
3272
+ throw new Error("sync \u4E0D\u652F\u6301 --range\uFF0C\u8BF7\u4F7F\u7528 --lookback\u3001--date\u3001--from/--to \u6216 --today");
3253
3273
  console.log(`\u626B\u63CF ${targetDates.length} \u5929 (${targetDates[0]} ~ ${targetDates[targetDates.length - 1]}) ...`);
3254
3274
  let allDays = (await scanDates(targetDates, { projectAliases: config.projectAliases })).filter((r) => r.breakdowns.length > 0).map((r) => ({ usageDate: r.usageDate, breakdowns: r.breakdowns }));
3255
3275
  if (allDays.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiusage/cli",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "Track and sync AI tool token usage across devices.",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -36,17 +36,17 @@
36
36
  "engines": {
37
37
  "node": ">=18"
38
38
  },
39
+ "devDependencies": {
40
+ "@types/node": "^22",
41
+ "esbuild": "^0.27.4",
42
+ "typescript": "^5",
43
+ "vitest": "^4.1.2",
44
+ "@aiusage/shared": "1.0.0"
45
+ },
39
46
  "scripts": {
40
47
  "build": "rm -rf dist && node build.mjs",
41
48
  "dev": "tsc --watch",
42
49
  "lint": "tsc --noEmit",
43
50
  "test": "vitest run"
44
- },
45
- "devDependencies": {
46
- "@aiusage/shared": "workspace:*",
47
- "@types/node": "^22",
48
- "esbuild": "^0.27.4",
49
- "typescript": "^5",
50
- "vitest": "^4.1.2"
51
51
  }
52
- }
52
+ }