@aiusage/cli 1.5.2 → 1.6.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/README.md +21 -4
- package/README.zh-CN.md +21 -4
- package/dist/cli.js +968 -160
- package/package.json +9 -9
package/dist/cli.js
CHANGED
|
@@ -26,12 +26,12 @@ function parseTs(value) {
|
|
|
26
26
|
function dateKey(date) {
|
|
27
27
|
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
|
|
28
28
|
}
|
|
29
|
-
function projectFromPath(raw,
|
|
29
|
+
function projectFromPath(raw, aliases2) {
|
|
30
30
|
let parts = raw.split("/").filter(Boolean), name = parts[parts.length - 1] || "unknown";
|
|
31
|
-
return
|
|
31
|
+
return aliases2?.[raw] ?? aliases2?.[name] ?? name;
|
|
32
32
|
}
|
|
33
|
-
function resolveProjectFields(rawPath,
|
|
34
|
-
let parts = rawPath.split("/").filter(Boolean), display = parts[parts.length - 1] || "unknown", alias =
|
|
33
|
+
function resolveProjectFields(rawPath, aliases2) {
|
|
34
|
+
let parts = rawPath.split("/").filter(Boolean), display = parts[parts.length - 1] || "unknown", alias = aliases2?.[rawPath] ?? aliases2?.[display];
|
|
35
35
|
return {
|
|
36
36
|
project: rawPath || "unknown",
|
|
37
37
|
projectDisplay: display,
|
|
@@ -347,8 +347,8 @@ function extractProjectFromCwd(cwd) {
|
|
|
347
347
|
let parts = cwd.split("/").filter(Boolean);
|
|
348
348
|
return parts[parts.length - 1] || "unknown";
|
|
349
349
|
}
|
|
350
|
-
function resolveProject(rawPath,
|
|
351
|
-
let project = extractProjectFromCwd(rawPath), alias =
|
|
350
|
+
function resolveProject(rawPath, aliases2) {
|
|
351
|
+
let project = extractProjectFromCwd(rawPath), alias = aliases2?.[rawPath] ?? aliases2?.[project];
|
|
352
352
|
return { project: rawPath, projectDisplay: project, projectAlias: alias };
|
|
353
353
|
}
|
|
354
354
|
async function walkForJsonl(dir, result) {
|
|
@@ -1065,9 +1065,9 @@ async function scanKimiDates(targetDates, baseDir, projectAliases) {
|
|
|
1065
1065
|
}
|
|
1066
1066
|
return finalize(grouped);
|
|
1067
1067
|
}
|
|
1068
|
-
function resolveKimiProject(hash, workspaceMap,
|
|
1068
|
+
function resolveKimiProject(hash, workspaceMap, aliases2) {
|
|
1069
1069
|
let wsPath = workspaceMap.get(hash);
|
|
1070
|
-
return wsPath ? resolveProjectFields(wsPath,
|
|
1070
|
+
return wsPath ? resolveProjectFields(wsPath, aliases2) : resolveProjectFields(hash, aliases2);
|
|
1071
1071
|
}
|
|
1072
1072
|
async function loadWorkspaceMap(kimiHome) {
|
|
1073
1073
|
let map = /* @__PURE__ */ new Map();
|
|
@@ -1587,6 +1587,880 @@ function parseCsv(content) {
|
|
|
1587
1587
|
import { readdir as readdir6, readFile as readFile13 } from "node:fs/promises";
|
|
1588
1588
|
import { homedir as homedir14 } from "node:os";
|
|
1589
1589
|
import { basename as basename8, join as join14 } from "node:path";
|
|
1590
|
+
|
|
1591
|
+
// ../shared/src/pricing/data/anthropic.ts
|
|
1592
|
+
var anthropic = {
|
|
1593
|
+
"claude-code": {
|
|
1594
|
+
models: {
|
|
1595
|
+
"claude-opus-4-7": {
|
|
1596
|
+
currency: "USD",
|
|
1597
|
+
input_per_million: 5,
|
|
1598
|
+
output_per_million: 25,
|
|
1599
|
+
cache_write_5m_per_million: 6.25,
|
|
1600
|
+
cache_write_1h_per_million: 10,
|
|
1601
|
+
cached_input_per_million: 0.5
|
|
1602
|
+
},
|
|
1603
|
+
"claude-opus-4-6": {
|
|
1604
|
+
currency: "USD",
|
|
1605
|
+
input_per_million: 5,
|
|
1606
|
+
output_per_million: 25,
|
|
1607
|
+
cache_write_5m_per_million: 6.25,
|
|
1608
|
+
cache_write_1h_per_million: 10,
|
|
1609
|
+
cached_input_per_million: 0.5
|
|
1610
|
+
},
|
|
1611
|
+
"claude-opus-4-5": {
|
|
1612
|
+
currency: "USD",
|
|
1613
|
+
input_per_million: 5,
|
|
1614
|
+
output_per_million: 25,
|
|
1615
|
+
cache_write_5m_per_million: 6.25,
|
|
1616
|
+
cache_write_1h_per_million: 10,
|
|
1617
|
+
cached_input_per_million: 0.5
|
|
1618
|
+
},
|
|
1619
|
+
"claude-opus-4-1": {
|
|
1620
|
+
currency: "USD",
|
|
1621
|
+
input_per_million: 15,
|
|
1622
|
+
output_per_million: 75,
|
|
1623
|
+
cache_write_5m_per_million: 18.75,
|
|
1624
|
+
cache_write_1h_per_million: 30,
|
|
1625
|
+
cached_input_per_million: 1.5
|
|
1626
|
+
},
|
|
1627
|
+
"claude-opus-4": {
|
|
1628
|
+
currency: "USD",
|
|
1629
|
+
notes: "deprecated",
|
|
1630
|
+
input_per_million: 15,
|
|
1631
|
+
output_per_million: 75,
|
|
1632
|
+
cache_write_5m_per_million: 18.75,
|
|
1633
|
+
cache_write_1h_per_million: 30,
|
|
1634
|
+
cached_input_per_million: 1.5
|
|
1635
|
+
},
|
|
1636
|
+
"claude-sonnet-4-6": {
|
|
1637
|
+
currency: "USD",
|
|
1638
|
+
input_per_million: 3,
|
|
1639
|
+
output_per_million: 15,
|
|
1640
|
+
cache_write_5m_per_million: 3.75,
|
|
1641
|
+
cache_write_1h_per_million: 6,
|
|
1642
|
+
cached_input_per_million: 0.3
|
|
1643
|
+
},
|
|
1644
|
+
"claude-sonnet-4-5": {
|
|
1645
|
+
currency: "USD",
|
|
1646
|
+
input_per_million: 3,
|
|
1647
|
+
output_per_million: 15,
|
|
1648
|
+
cache_write_5m_per_million: 3.75,
|
|
1649
|
+
cache_write_1h_per_million: 6,
|
|
1650
|
+
cached_input_per_million: 0.3
|
|
1651
|
+
},
|
|
1652
|
+
"claude-sonnet-4": {
|
|
1653
|
+
currency: "USD",
|
|
1654
|
+
notes: "deprecated",
|
|
1655
|
+
input_per_million: 3,
|
|
1656
|
+
output_per_million: 15,
|
|
1657
|
+
cache_write_5m_per_million: 3.75,
|
|
1658
|
+
cache_write_1h_per_million: 6,
|
|
1659
|
+
cached_input_per_million: 0.3
|
|
1660
|
+
},
|
|
1661
|
+
"claude-haiku-4-5": {
|
|
1662
|
+
currency: "USD",
|
|
1663
|
+
input_per_million: 1,
|
|
1664
|
+
output_per_million: 5,
|
|
1665
|
+
cache_write_5m_per_million: 1.25,
|
|
1666
|
+
cache_write_1h_per_million: 2,
|
|
1667
|
+
cached_input_per_million: 0.1
|
|
1668
|
+
},
|
|
1669
|
+
"claude-haiku-3-5": {
|
|
1670
|
+
currency: "USD",
|
|
1671
|
+
notes: "retired except on Bedrock/Vertex",
|
|
1672
|
+
input_per_million: 0.8,
|
|
1673
|
+
output_per_million: 4,
|
|
1674
|
+
cache_write_5m_per_million: 1,
|
|
1675
|
+
cache_write_1h_per_million: 1.6,
|
|
1676
|
+
cached_input_per_million: 0.08
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
};
|
|
1681
|
+
|
|
1682
|
+
// ../shared/src/pricing/data/openai.ts
|
|
1683
|
+
var openai = {
|
|
1684
|
+
codex: {
|
|
1685
|
+
models: {
|
|
1686
|
+
// ── GPT-5.5 系列 ──
|
|
1687
|
+
"gpt-5.5": {
|
|
1688
|
+
currency: "USD",
|
|
1689
|
+
input_per_million: 5,
|
|
1690
|
+
cached_input_per_million: 0.5,
|
|
1691
|
+
output_per_million: 30
|
|
1692
|
+
},
|
|
1693
|
+
"gpt-5.5-pro": {
|
|
1694
|
+
currency: "USD",
|
|
1695
|
+
input_per_million: 30,
|
|
1696
|
+
cached_input_per_million: null,
|
|
1697
|
+
output_per_million: 180
|
|
1698
|
+
},
|
|
1699
|
+
// ── GPT-5.4 系列 ──
|
|
1700
|
+
"gpt-5.4": {
|
|
1701
|
+
currency: "USD",
|
|
1702
|
+
input_per_million: 2.5,
|
|
1703
|
+
cached_input_per_million: 0.25,
|
|
1704
|
+
output_per_million: 15
|
|
1705
|
+
},
|
|
1706
|
+
"gpt-5.4-mini": {
|
|
1707
|
+
currency: "USD",
|
|
1708
|
+
input_per_million: 0.75,
|
|
1709
|
+
cached_input_per_million: 0.075,
|
|
1710
|
+
output_per_million: 4.5
|
|
1711
|
+
},
|
|
1712
|
+
"gpt-5.4-nano": {
|
|
1713
|
+
currency: "USD",
|
|
1714
|
+
input_per_million: 0.2,
|
|
1715
|
+
cached_input_per_million: 0.02,
|
|
1716
|
+
output_per_million: 1.25
|
|
1717
|
+
},
|
|
1718
|
+
"gpt-5.4-pro": {
|
|
1719
|
+
currency: "USD",
|
|
1720
|
+
input_per_million: 30,
|
|
1721
|
+
cached_input_per_million: null,
|
|
1722
|
+
output_per_million: 180
|
|
1723
|
+
},
|
|
1724
|
+
// ── GPT-5.3 / 5.2 / Codex 变体 ──
|
|
1725
|
+
"gpt-5.3-codex": {
|
|
1726
|
+
currency: "USD",
|
|
1727
|
+
input_per_million: 1.75,
|
|
1728
|
+
cached_input_per_million: 0.175,
|
|
1729
|
+
output_per_million: 14
|
|
1730
|
+
},
|
|
1731
|
+
"gpt-5.2-codex": {
|
|
1732
|
+
currency: "USD",
|
|
1733
|
+
input_per_million: 1.75,
|
|
1734
|
+
cached_input_per_million: 0.175,
|
|
1735
|
+
output_per_million: 14
|
|
1736
|
+
},
|
|
1737
|
+
"gpt-5.2-pro": {
|
|
1738
|
+
currency: "USD",
|
|
1739
|
+
input_per_million: 21,
|
|
1740
|
+
cached_input_per_million: null,
|
|
1741
|
+
output_per_million: 168
|
|
1742
|
+
},
|
|
1743
|
+
"gpt-5.2": {
|
|
1744
|
+
currency: "USD",
|
|
1745
|
+
input_per_million: 1.75,
|
|
1746
|
+
cached_input_per_million: 0.175,
|
|
1747
|
+
output_per_million: 14
|
|
1748
|
+
},
|
|
1749
|
+
// ── GPT-5.1 / 5 系列 ──
|
|
1750
|
+
"gpt-5.1-codex-max": {
|
|
1751
|
+
currency: "USD",
|
|
1752
|
+
input_per_million: 1.25,
|
|
1753
|
+
cached_input_per_million: 0.125,
|
|
1754
|
+
output_per_million: 10
|
|
1755
|
+
},
|
|
1756
|
+
"gpt-5.1-codex-mini": {
|
|
1757
|
+
currency: "USD",
|
|
1758
|
+
input_per_million: 0.25,
|
|
1759
|
+
cached_input_per_million: 0.025,
|
|
1760
|
+
output_per_million: 2
|
|
1761
|
+
},
|
|
1762
|
+
"gpt-5.1-codex": {
|
|
1763
|
+
currency: "USD",
|
|
1764
|
+
input_per_million: 1.25,
|
|
1765
|
+
cached_input_per_million: 0.125,
|
|
1766
|
+
output_per_million: 10
|
|
1767
|
+
},
|
|
1768
|
+
"gpt-5.1": {
|
|
1769
|
+
currency: "USD",
|
|
1770
|
+
input_per_million: 1.25,
|
|
1771
|
+
cached_input_per_million: 0.125,
|
|
1772
|
+
output_per_million: 10
|
|
1773
|
+
},
|
|
1774
|
+
"gpt-5-pro": {
|
|
1775
|
+
currency: "USD",
|
|
1776
|
+
input_per_million: 15,
|
|
1777
|
+
cached_input_per_million: null,
|
|
1778
|
+
output_per_million: 120
|
|
1779
|
+
},
|
|
1780
|
+
"gpt-5-codex": {
|
|
1781
|
+
currency: "USD",
|
|
1782
|
+
input_per_million: 1.25,
|
|
1783
|
+
cached_input_per_million: 0.125,
|
|
1784
|
+
output_per_million: 10
|
|
1785
|
+
},
|
|
1786
|
+
"gpt-5-mini": {
|
|
1787
|
+
currency: "USD",
|
|
1788
|
+
input_per_million: 0.25,
|
|
1789
|
+
cached_input_per_million: 0.025,
|
|
1790
|
+
output_per_million: 2
|
|
1791
|
+
},
|
|
1792
|
+
"gpt-5-nano": {
|
|
1793
|
+
currency: "USD",
|
|
1794
|
+
input_per_million: 0.05,
|
|
1795
|
+
cached_input_per_million: 5e-3,
|
|
1796
|
+
output_per_million: 0.4
|
|
1797
|
+
},
|
|
1798
|
+
"gpt-5": {
|
|
1799
|
+
currency: "USD",
|
|
1800
|
+
input_per_million: 1.25,
|
|
1801
|
+
cached_input_per_million: 0.125,
|
|
1802
|
+
output_per_million: 10
|
|
1803
|
+
},
|
|
1804
|
+
// ── GPT-4.1 / 4o ──
|
|
1805
|
+
"gpt-4.1": { currency: "USD", input_per_million: 2, cached_input_per_million: 0.5, output_per_million: 8 },
|
|
1806
|
+
"gpt-4.1-mini": { currency: "USD", input_per_million: 0.4, cached_input_per_million: 0.1, output_per_million: 1.6 },
|
|
1807
|
+
"gpt-4.1-nano": { currency: "USD", input_per_million: 0.1, cached_input_per_million: 0.025, output_per_million: 0.4 },
|
|
1808
|
+
"gpt-4o": { currency: "USD", input_per_million: 2.5, cached_input_per_million: 1.25, output_per_million: 10 },
|
|
1809
|
+
"gpt-4o-mini": { currency: "USD", input_per_million: 0.15, cached_input_per_million: 0.075, output_per_million: 0.6 },
|
|
1810
|
+
"gpt-4o-2024-05-13": { currency: "USD", input_per_million: 5, cached_input_per_million: null, output_per_million: 15 },
|
|
1811
|
+
// ── o 系列 ──
|
|
1812
|
+
"o1-pro": { currency: "USD", input_per_million: 150, cached_input_per_million: null, output_per_million: 600 },
|
|
1813
|
+
o1: { currency: "USD", input_per_million: 15, cached_input_per_million: 7.5, output_per_million: 60 },
|
|
1814
|
+
"o1-mini": { currency: "USD", input_per_million: 1.1, cached_input_per_million: 0.55, output_per_million: 4.4 },
|
|
1815
|
+
"o3-pro": { currency: "USD", input_per_million: 20, cached_input_per_million: null, output_per_million: 80 },
|
|
1816
|
+
o3: { currency: "USD", input_per_million: 2, cached_input_per_million: 0.5, output_per_million: 8 },
|
|
1817
|
+
"o3-mini": { currency: "USD", input_per_million: 1.1, cached_input_per_million: 0.55, output_per_million: 4.4 },
|
|
1818
|
+
"o4-mini": { currency: "USD", input_per_million: 1.1, cached_input_per_million: 0.275, output_per_million: 4.4 },
|
|
1819
|
+
// ── Deep research / 工具型 ──
|
|
1820
|
+
"o3-deep-research": {
|
|
1821
|
+
currency: "USD",
|
|
1822
|
+
notes: "corrected from previous 10/40 entry on 2026-05-24",
|
|
1823
|
+
input_per_million: 5,
|
|
1824
|
+
cached_input_per_million: null,
|
|
1825
|
+
output_per_million: 20
|
|
1826
|
+
},
|
|
1827
|
+
"o4-mini-deep-research": {
|
|
1828
|
+
currency: "USD",
|
|
1829
|
+
notes: "corrected from previous 2/8 entry on 2026-05-24",
|
|
1830
|
+
input_per_million: 1,
|
|
1831
|
+
cached_input_per_million: null,
|
|
1832
|
+
output_per_million: 4
|
|
1833
|
+
},
|
|
1834
|
+
"computer-use-preview": {
|
|
1835
|
+
currency: "USD",
|
|
1836
|
+
notes: "corrected from previous 3/12 entry on 2026-05-24",
|
|
1837
|
+
input_per_million: 1.5,
|
|
1838
|
+
cached_input_per_million: null,
|
|
1839
|
+
output_per_million: 6
|
|
1840
|
+
},
|
|
1841
|
+
// ── 历史模型(GPT-4 / 3.5 / davinci 等)──
|
|
1842
|
+
"gpt-4-turbo-2024-04-09": { currency: "USD", input_per_million: 10, cached_input_per_million: null, output_per_million: 30 },
|
|
1843
|
+
"gpt-4-0125-preview": { currency: "USD", input_per_million: 10, cached_input_per_million: null, output_per_million: 30 },
|
|
1844
|
+
"gpt-4-1106-preview": { currency: "USD", input_per_million: 10, cached_input_per_million: null, output_per_million: 30 },
|
|
1845
|
+
"gpt-4-1106-vision-preview": { currency: "USD", input_per_million: 10, cached_input_per_million: null, output_per_million: 30 },
|
|
1846
|
+
"gpt-4-0613": { currency: "USD", input_per_million: 30, cached_input_per_million: null, output_per_million: 60 },
|
|
1847
|
+
"gpt-4-0314": { currency: "USD", input_per_million: 30, cached_input_per_million: null, output_per_million: 60 },
|
|
1848
|
+
"gpt-4-32k": { currency: "USD", input_per_million: 60, cached_input_per_million: null, output_per_million: 120 },
|
|
1849
|
+
"gpt-3.5-turbo": { currency: "USD", input_per_million: 0.5, cached_input_per_million: null, output_per_million: 1.5 },
|
|
1850
|
+
"gpt-3.5-turbo-0125": { currency: "USD", input_per_million: 0.5, cached_input_per_million: null, output_per_million: 1.5 },
|
|
1851
|
+
"gpt-3.5-turbo-1106": { currency: "USD", input_per_million: 1, cached_input_per_million: null, output_per_million: 2 },
|
|
1852
|
+
"gpt-3.5-turbo-0613": { currency: "USD", input_per_million: 1.5, cached_input_per_million: null, output_per_million: 2 },
|
|
1853
|
+
"gpt-3.5-0301": { currency: "USD", input_per_million: 1.5, cached_input_per_million: null, output_per_million: 2 },
|
|
1854
|
+
"gpt-3.5-turbo-instruct": { currency: "USD", input_per_million: 1.5, cached_input_per_million: null, output_per_million: 2 },
|
|
1855
|
+
"gpt-3.5-turbo-16k-0613": { currency: "USD", input_per_million: 3, cached_input_per_million: null, output_per_million: 4 },
|
|
1856
|
+
"davinci-002": { currency: "USD", input_per_million: 2, cached_input_per_million: null, output_per_million: 2 },
|
|
1857
|
+
"babbage-002": { currency: "USD", input_per_million: 0.4, cached_input_per_million: null, output_per_million: 0.4 },
|
|
1858
|
+
"codex-mini-latest": { currency: "USD", input_per_million: 1.5, cached_input_per_million: 0.375, output_per_million: 6 },
|
|
1859
|
+
// ── Embeddings ──
|
|
1860
|
+
"text-embedding-3-small": { currency: "USD", input_per_million: 0.02, cached_input_per_million: null, output_per_million: 0 },
|
|
1861
|
+
"text-embedding-3-large": { currency: "USD", input_per_million: 0.13, cached_input_per_million: null, output_per_million: 0 },
|
|
1862
|
+
"text-embedding-ada-002": { currency: "USD", input_per_million: 0.1, cached_input_per_million: null, output_per_million: 0 }
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
};
|
|
1866
|
+
|
|
1867
|
+
// ../shared/src/pricing/data/google.ts
|
|
1868
|
+
var google = {
|
|
1869
|
+
// Antigravity 本地不输出 token 信息,仅事件计数;保留空 models 不算费用
|
|
1870
|
+
antigravity: { models: {} },
|
|
1871
|
+
"gemini-cli": {
|
|
1872
|
+
models: {
|
|
1873
|
+
// ── Gemini 3.x 系列 ──
|
|
1874
|
+
"gemini-3.5-flash": {
|
|
1875
|
+
currency: "USD",
|
|
1876
|
+
input_per_million: 1.5,
|
|
1877
|
+
output_per_million: 9,
|
|
1878
|
+
cached_input_per_million: 0.15
|
|
1879
|
+
},
|
|
1880
|
+
"gemini-3.1-pro-preview": {
|
|
1881
|
+
currency: "USD",
|
|
1882
|
+
notes: "tiered by prompt length, 200K threshold",
|
|
1883
|
+
tiers: [
|
|
1884
|
+
{ threshold: 2e5, input_per_million: 2, cached_input_per_million: 0.2, output_per_million: 12 },
|
|
1885
|
+
{ input_per_million: 4, cached_input_per_million: 0.4, output_per_million: 18 }
|
|
1886
|
+
]
|
|
1887
|
+
},
|
|
1888
|
+
"gemini-3.1-flash-lite": {
|
|
1889
|
+
currency: "USD",
|
|
1890
|
+
notes: "text/image/video price; audio is $0.50/M",
|
|
1891
|
+
input_per_million: 0.25,
|
|
1892
|
+
cached_input_per_million: 0.025,
|
|
1893
|
+
output_per_million: 1.5
|
|
1894
|
+
},
|
|
1895
|
+
"gemini-3.1-flash-lite-preview": {
|
|
1896
|
+
currency: "USD",
|
|
1897
|
+
notes: "text/image/video price",
|
|
1898
|
+
input_per_million: 0.25,
|
|
1899
|
+
cached_input_per_million: 0.025,
|
|
1900
|
+
output_per_million: 1.5
|
|
1901
|
+
},
|
|
1902
|
+
"gemini-3-flash-preview": {
|
|
1903
|
+
currency: "USD",
|
|
1904
|
+
notes: "text/image/video price; audio is $1.00/M",
|
|
1905
|
+
input_per_million: 0.5,
|
|
1906
|
+
cached_input_per_million: 0.05,
|
|
1907
|
+
output_per_million: 3
|
|
1908
|
+
},
|
|
1909
|
+
// ── Gemini 2.5 系列 ──
|
|
1910
|
+
"gemini-2.5-pro": {
|
|
1911
|
+
currency: "USD",
|
|
1912
|
+
notes: "tiered by prompt length, 200K threshold",
|
|
1913
|
+
tiers: [
|
|
1914
|
+
{ threshold: 2e5, input_per_million: 1.25, cached_input_per_million: 0.125, output_per_million: 10 },
|
|
1915
|
+
{ input_per_million: 2.5, cached_input_per_million: 0.25, output_per_million: 15 }
|
|
1916
|
+
]
|
|
1917
|
+
},
|
|
1918
|
+
"gemini-2.5-flash": {
|
|
1919
|
+
currency: "USD",
|
|
1920
|
+
notes: "text/image/video price; audio is $1.00/M; corrected from 0.15/0.6 on 2026-05-24",
|
|
1921
|
+
input_per_million: 0.3,
|
|
1922
|
+
cached_input_per_million: 0.03,
|
|
1923
|
+
output_per_million: 2.5
|
|
1924
|
+
},
|
|
1925
|
+
"gemini-2.5-flash-lite": {
|
|
1926
|
+
currency: "USD",
|
|
1927
|
+
notes: "text/image/video price; audio is $0.30/M",
|
|
1928
|
+
input_per_million: 0.1,
|
|
1929
|
+
cached_input_per_million: 0.01,
|
|
1930
|
+
output_per_million: 0.4
|
|
1931
|
+
},
|
|
1932
|
+
"gemini-2.5-flash-lite-preview": {
|
|
1933
|
+
currency: "USD",
|
|
1934
|
+
input_per_million: 0.1,
|
|
1935
|
+
cached_input_per_million: 0.01,
|
|
1936
|
+
output_per_million: 0.4
|
|
1937
|
+
},
|
|
1938
|
+
"gemini-2.5-computer-use-preview": {
|
|
1939
|
+
currency: "USD",
|
|
1940
|
+
notes: "tiered by prompt length, 200K threshold",
|
|
1941
|
+
tiers: [
|
|
1942
|
+
{ threshold: 2e5, input_per_million: 1.25, output_per_million: 10 },
|
|
1943
|
+
{ input_per_million: 2.5, output_per_million: 15 }
|
|
1944
|
+
]
|
|
1945
|
+
},
|
|
1946
|
+
// ── Gemini 2.0 系列 ──
|
|
1947
|
+
"gemini-2.0-flash": {
|
|
1948
|
+
currency: "USD",
|
|
1949
|
+
notes: "text/image/video price; audio is $0.70/M",
|
|
1950
|
+
input_per_million: 0.1,
|
|
1951
|
+
cached_input_per_million: 0.025,
|
|
1952
|
+
output_per_million: 0.4
|
|
1953
|
+
},
|
|
1954
|
+
"gemini-2.0-flash-lite": {
|
|
1955
|
+
currency: "USD",
|
|
1956
|
+
input_per_million: 0.075,
|
|
1957
|
+
output_per_million: 0.3
|
|
1958
|
+
},
|
|
1959
|
+
// ── Gemini 1.5(legacy)──
|
|
1960
|
+
"gemini-1.5-pro": {
|
|
1961
|
+
currency: "USD",
|
|
1962
|
+
notes: "legacy",
|
|
1963
|
+
input_per_million: 1.25,
|
|
1964
|
+
cached_input_per_million: 0.3125,
|
|
1965
|
+
output_per_million: 5
|
|
1966
|
+
},
|
|
1967
|
+
"gemini-1.5-flash": {
|
|
1968
|
+
currency: "USD",
|
|
1969
|
+
notes: "legacy",
|
|
1970
|
+
input_per_million: 0.075,
|
|
1971
|
+
cached_input_per_million: 0.01875,
|
|
1972
|
+
output_per_million: 0.3
|
|
1973
|
+
},
|
|
1974
|
+
// ── Robotics / Embedding ──
|
|
1975
|
+
"gemini-robotics-er-1.6-preview": {
|
|
1976
|
+
currency: "USD",
|
|
1977
|
+
notes: "text/image/video price; audio is $2.00/M",
|
|
1978
|
+
input_per_million: 1,
|
|
1979
|
+
output_per_million: 5
|
|
1980
|
+
},
|
|
1981
|
+
"gemini-embedding-2": {
|
|
1982
|
+
currency: "USD",
|
|
1983
|
+
notes: "text input only price; image $0.45/M, audio $6.50/M, video $12.00/M",
|
|
1984
|
+
input_per_million: 0.2,
|
|
1985
|
+
output_per_million: 0
|
|
1986
|
+
},
|
|
1987
|
+
"gemini-embedding": {
|
|
1988
|
+
currency: "USD",
|
|
1989
|
+
input_per_million: 0.15,
|
|
1990
|
+
output_per_million: 0
|
|
1991
|
+
},
|
|
1992
|
+
// ── Live API / TTS / Image / Video 走 perfect-fit 模型,按其代表单价;
|
|
1993
|
+
// 这些模型的 input/output 不是简单的 text token,应在 scanner 侧匹配。 ──
|
|
1994
|
+
"gemini-3.1-flash-live-preview": {
|
|
1995
|
+
currency: "USD",
|
|
1996
|
+
notes: "Live API text price; audio/video/image priced separately",
|
|
1997
|
+
input_per_million: 0.75,
|
|
1998
|
+
output_per_million: 4.5
|
|
1999
|
+
},
|
|
2000
|
+
"gemini-2.5-flash-native-audio": {
|
|
2001
|
+
currency: "USD",
|
|
2002
|
+
notes: "Live API text price; audio is $3.00 input / $12.00 output",
|
|
2003
|
+
input_per_million: 0.5,
|
|
2004
|
+
output_per_million: 2
|
|
2005
|
+
},
|
|
2006
|
+
"gemini-3.1-flash-tts-preview": {
|
|
2007
|
+
currency: "USD",
|
|
2008
|
+
notes: "text in, audio out",
|
|
2009
|
+
input_per_million: 1,
|
|
2010
|
+
output_per_million: 20
|
|
2011
|
+
},
|
|
2012
|
+
"gemini-2.5-flash-preview-tts": {
|
|
2013
|
+
currency: "USD",
|
|
2014
|
+
notes: "text in, audio out",
|
|
2015
|
+
input_per_million: 0.5,
|
|
2016
|
+
output_per_million: 10
|
|
2017
|
+
},
|
|
2018
|
+
"gemini-2.5-pro-preview-tts": {
|
|
2019
|
+
currency: "USD",
|
|
2020
|
+
notes: "text in, audio out",
|
|
2021
|
+
input_per_million: 1,
|
|
2022
|
+
output_per_million: 20
|
|
2023
|
+
},
|
|
2024
|
+
"gemini-3.1-flash-image-preview": {
|
|
2025
|
+
currency: "USD",
|
|
2026
|
+
notes: "text/image in, image out priced per-image",
|
|
2027
|
+
input_per_million: 0.5,
|
|
2028
|
+
output_per_million: 3
|
|
2029
|
+
},
|
|
2030
|
+
"gemini-2.5-flash-image": {
|
|
2031
|
+
currency: "USD",
|
|
2032
|
+
notes: "image out priced per-image ($0.039)",
|
|
2033
|
+
input_per_million: 0.3,
|
|
2034
|
+
output_per_million: 0
|
|
2035
|
+
},
|
|
2036
|
+
"gemini-3-pro-image-preview": {
|
|
2037
|
+
currency: "USD",
|
|
2038
|
+
notes: "image out priced per-image; text-output $12/M",
|
|
2039
|
+
input_per_million: 2,
|
|
2040
|
+
output_per_million: 12
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
};
|
|
2045
|
+
|
|
2046
|
+
// ../shared/src/pricing/data/moonshot.ts
|
|
2047
|
+
var moonshot = {
|
|
2048
|
+
"kimi-code": {
|
|
2049
|
+
models: {
|
|
2050
|
+
"kimi-k2.6": {
|
|
2051
|
+
currency: "CNY",
|
|
2052
|
+
input_per_million: 6.5,
|
|
2053
|
+
cached_input_per_million: 1.1,
|
|
2054
|
+
output_per_million: 27
|
|
2055
|
+
},
|
|
2056
|
+
"kimi-k2.5": {
|
|
2057
|
+
currency: "CNY",
|
|
2058
|
+
input_per_million: 4,
|
|
2059
|
+
cached_input_per_million: 0.7,
|
|
2060
|
+
output_per_million: 21
|
|
2061
|
+
},
|
|
2062
|
+
"kimi-k2-0905-preview": {
|
|
2063
|
+
currency: "CNY",
|
|
2064
|
+
notes: "will be retired 2026-05-25",
|
|
2065
|
+
input_per_million: 4,
|
|
2066
|
+
cached_input_per_million: 1,
|
|
2067
|
+
output_per_million: 16
|
|
2068
|
+
},
|
|
2069
|
+
"kimi-k2-0711-preview": {
|
|
2070
|
+
currency: "CNY",
|
|
2071
|
+
notes: "will be retired 2026-05-25",
|
|
2072
|
+
input_per_million: 4,
|
|
2073
|
+
cached_input_per_million: 1,
|
|
2074
|
+
output_per_million: 16
|
|
2075
|
+
},
|
|
2076
|
+
"kimi-k2-turbo-preview": {
|
|
2077
|
+
currency: "CNY",
|
|
2078
|
+
notes: "will be retired 2026-05-25",
|
|
2079
|
+
input_per_million: 8,
|
|
2080
|
+
cached_input_per_million: 1,
|
|
2081
|
+
output_per_million: 58
|
|
2082
|
+
},
|
|
2083
|
+
"kimi-k2-thinking": {
|
|
2084
|
+
currency: "CNY",
|
|
2085
|
+
input_per_million: 4,
|
|
2086
|
+
cached_input_per_million: 1,
|
|
2087
|
+
output_per_million: 16
|
|
2088
|
+
},
|
|
2089
|
+
"kimi-k2-thinking-turbo": {
|
|
2090
|
+
currency: "CNY",
|
|
2091
|
+
input_per_million: 8,
|
|
2092
|
+
cached_input_per_million: 1,
|
|
2093
|
+
output_per_million: 58
|
|
2094
|
+
},
|
|
2095
|
+
"moonshot-v1-8k": {
|
|
2096
|
+
currency: "CNY",
|
|
2097
|
+
input_per_million: 2,
|
|
2098
|
+
output_per_million: 10
|
|
2099
|
+
},
|
|
2100
|
+
"moonshot-v1-32k": {
|
|
2101
|
+
currency: "CNY",
|
|
2102
|
+
input_per_million: 5,
|
|
2103
|
+
output_per_million: 20
|
|
2104
|
+
},
|
|
2105
|
+
"moonshot-v1-128k": {
|
|
2106
|
+
currency: "CNY",
|
|
2107
|
+
input_per_million: 10,
|
|
2108
|
+
output_per_million: 30
|
|
2109
|
+
},
|
|
2110
|
+
"moonshot-v1-8k-vision-preview": {
|
|
2111
|
+
currency: "CNY",
|
|
2112
|
+
input_per_million: 2,
|
|
2113
|
+
output_per_million: 10
|
|
2114
|
+
},
|
|
2115
|
+
"moonshot-v1-32k-vision-preview": {
|
|
2116
|
+
currency: "CNY",
|
|
2117
|
+
input_per_million: 5,
|
|
2118
|
+
output_per_million: 20
|
|
2119
|
+
},
|
|
2120
|
+
"moonshot-v1-128k-vision-preview": {
|
|
2121
|
+
currency: "CNY",
|
|
2122
|
+
input_per_million: 10,
|
|
2123
|
+
output_per_million: 30
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2127
|
+
};
|
|
2128
|
+
|
|
2129
|
+
// ../shared/src/pricing/data/alibaba.ts
|
|
2130
|
+
var alibaba = {
|
|
2131
|
+
"qwen-code": {
|
|
2132
|
+
models: {
|
|
2133
|
+
"qwen3-coder-plus": {
|
|
2134
|
+
currency: "CNY",
|
|
2135
|
+
notes: "tiered by input length",
|
|
2136
|
+
tiers: [
|
|
2137
|
+
{ threshold: 32e3, input_per_million: 4, output_per_million: 16 },
|
|
2138
|
+
{ threshold: 128e3, input_per_million: 6, output_per_million: 24 },
|
|
2139
|
+
{ threshold: 256e3, input_per_million: 10, output_per_million: 40 },
|
|
2140
|
+
{ input_per_million: 20, output_per_million: 200 }
|
|
2141
|
+
]
|
|
2142
|
+
},
|
|
2143
|
+
"qwen3-coder-flash": {
|
|
2144
|
+
currency: "CNY",
|
|
2145
|
+
tiers: [
|
|
2146
|
+
{ threshold: 32e3, input_per_million: 1, output_per_million: 4 },
|
|
2147
|
+
{ threshold: 128e3, input_per_million: 1.5, output_per_million: 6 },
|
|
2148
|
+
{ threshold: 256e3, input_per_million: 2, output_per_million: 8 },
|
|
2149
|
+
{ input_per_million: 3, output_per_million: 30 }
|
|
2150
|
+
]
|
|
2151
|
+
},
|
|
2152
|
+
"qwen-coder-plus": {
|
|
2153
|
+
currency: "CNY",
|
|
2154
|
+
input_per_million: 3.5,
|
|
2155
|
+
output_per_million: 7
|
|
2156
|
+
},
|
|
2157
|
+
"qwen3-max": {
|
|
2158
|
+
currency: "CNY",
|
|
2159
|
+
tiers: [
|
|
2160
|
+
{ threshold: 32e3, input_per_million: 2.5, output_per_million: 10 },
|
|
2161
|
+
{ threshold: 128e3, input_per_million: 5, output_per_million: 20 },
|
|
2162
|
+
{ threshold: 256e3, input_per_million: 10, output_per_million: 100 }
|
|
2163
|
+
]
|
|
2164
|
+
},
|
|
2165
|
+
"qwen-max": {
|
|
2166
|
+
currency: "CNY",
|
|
2167
|
+
input_per_million: 2.4,
|
|
2168
|
+
output_per_million: 9.6
|
|
2169
|
+
},
|
|
2170
|
+
"qwen-plus": {
|
|
2171
|
+
currency: "CNY",
|
|
2172
|
+
notes: "cache hit \xA50.8/M",
|
|
2173
|
+
cached_input_per_million: 0.8,
|
|
2174
|
+
input_per_million: 2,
|
|
2175
|
+
output_per_million: 8
|
|
2176
|
+
},
|
|
2177
|
+
"qwen-turbo": {
|
|
2178
|
+
currency: "CNY",
|
|
2179
|
+
notes: "cache hit \xA50.3/M",
|
|
2180
|
+
cached_input_per_million: 0.3,
|
|
2181
|
+
input_per_million: 0.6,
|
|
2182
|
+
output_per_million: 3
|
|
2183
|
+
},
|
|
2184
|
+
"qwen3-32b": {
|
|
2185
|
+
currency: "CNY",
|
|
2186
|
+
input_per_million: 2,
|
|
2187
|
+
output_per_million: 8
|
|
2188
|
+
},
|
|
2189
|
+
"qwen3-235b-a22b-thinking-2507": {
|
|
2190
|
+
currency: "CNY",
|
|
2191
|
+
input_per_million: 2,
|
|
2192
|
+
output_per_million: 20
|
|
2193
|
+
},
|
|
2194
|
+
"qwen3-235b-a22b-instruct-2507": {
|
|
2195
|
+
currency: "CNY",
|
|
2196
|
+
input_per_million: 2,
|
|
2197
|
+
output_per_million: 8
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
};
|
|
2202
|
+
|
|
2203
|
+
// ../shared/src/pricing/data/deepseek.ts
|
|
2204
|
+
var deepseek = {
|
|
2205
|
+
"deepseek-chat": {
|
|
2206
|
+
models: {
|
|
2207
|
+
"deepseek-v4-flash": {
|
|
2208
|
+
currency: "USD",
|
|
2209
|
+
input_per_million: 0.14,
|
|
2210
|
+
cached_input_per_million: 28e-4,
|
|
2211
|
+
output_per_million: 0.28
|
|
2212
|
+
},
|
|
2213
|
+
"deepseek-v4-pro": {
|
|
2214
|
+
currency: "USD",
|
|
2215
|
+
notes: "75% off promo until 2026-05-31",
|
|
2216
|
+
input_per_million: 0.435,
|
|
2217
|
+
cached_input_per_million: 3625e-6,
|
|
2218
|
+
output_per_million: 0.87,
|
|
2219
|
+
effective_to: "2026-05-31"
|
|
2220
|
+
},
|
|
2221
|
+
// 兼容别名(chat = v4-flash 非思考,reasoner = v4-flash 思考),按 v4-flash 同价计
|
|
2222
|
+
"deepseek-chat": {
|
|
2223
|
+
currency: "USD",
|
|
2224
|
+
notes: "alias for v4-flash non-thinking",
|
|
2225
|
+
input_per_million: 0.14,
|
|
2226
|
+
cached_input_per_million: 28e-4,
|
|
2227
|
+
output_per_million: 0.28
|
|
2228
|
+
},
|
|
2229
|
+
"deepseek-reasoner": {
|
|
2230
|
+
currency: "USD",
|
|
2231
|
+
notes: "alias for v4-flash thinking",
|
|
2232
|
+
input_per_million: 0.14,
|
|
2233
|
+
cached_input_per_million: 28e-4,
|
|
2234
|
+
output_per_million: 0.28
|
|
2235
|
+
}
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
};
|
|
2239
|
+
|
|
2240
|
+
// ../shared/src/pricing/data/zhipu.ts
|
|
2241
|
+
var zhipu = {
|
|
2242
|
+
"glm-chat": {
|
|
2243
|
+
models: {
|
|
2244
|
+
"glm-5.1": {
|
|
2245
|
+
currency: "CNY",
|
|
2246
|
+
tiers: [
|
|
2247
|
+
{ threshold: 32e3, input_per_million: 6, output_per_million: 24, cached_input_per_million: 1.3 },
|
|
2248
|
+
{ input_per_million: 8, output_per_million: 28, cached_input_per_million: 2 }
|
|
2249
|
+
]
|
|
2250
|
+
},
|
|
2251
|
+
"glm-5-turbo": {
|
|
2252
|
+
currency: "CNY",
|
|
2253
|
+
tiers: [
|
|
2254
|
+
{ threshold: 32e3, input_per_million: 5, output_per_million: 22, cached_input_per_million: 1.2 },
|
|
2255
|
+
{ input_per_million: 7, output_per_million: 26, cached_input_per_million: 1.8 }
|
|
2256
|
+
]
|
|
2257
|
+
},
|
|
2258
|
+
"glm-5": {
|
|
2259
|
+
currency: "CNY",
|
|
2260
|
+
tiers: [
|
|
2261
|
+
{ threshold: 32e3, input_per_million: 4, output_per_million: 18, cached_input_per_million: 1 },
|
|
2262
|
+
{ input_per_million: 6, output_per_million: 22, cached_input_per_million: 1.5 }
|
|
2263
|
+
]
|
|
2264
|
+
},
|
|
2265
|
+
"glm-4.7": {
|
|
2266
|
+
currency: "CNY",
|
|
2267
|
+
notes: "output<200 archetype; >200 doubles output rate",
|
|
2268
|
+
tiers: [
|
|
2269
|
+
{ threshold: 32e3, input_per_million: 2, output_per_million: 8, cached_input_per_million: 0.4 },
|
|
2270
|
+
{ threshold: 2e5, input_per_million: 4, output_per_million: 16, cached_input_per_million: 0.8 }
|
|
2271
|
+
]
|
|
2272
|
+
},
|
|
2273
|
+
"glm-4.5-air": {
|
|
2274
|
+
currency: "CNY",
|
|
2275
|
+
tiers: [
|
|
2276
|
+
{ threshold: 32e3, input_per_million: 0.8, output_per_million: 2, cached_input_per_million: 0.16 },
|
|
2277
|
+
{ threshold: 128e3, input_per_million: 1.2, output_per_million: 8, cached_input_per_million: 0.24 }
|
|
2278
|
+
]
|
|
2279
|
+
},
|
|
2280
|
+
"glm-4.7-flashx": {
|
|
2281
|
+
currency: "CNY",
|
|
2282
|
+
input_per_million: 0.5,
|
|
2283
|
+
cached_input_per_million: 0.1,
|
|
2284
|
+
output_per_million: 3
|
|
2285
|
+
},
|
|
2286
|
+
"glm-4.7-flash": {
|
|
2287
|
+
currency: "CNY",
|
|
2288
|
+
notes: "free tier",
|
|
2289
|
+
input_per_million: 0,
|
|
2290
|
+
cached_input_per_million: 0,
|
|
2291
|
+
output_per_million: 0
|
|
2292
|
+
},
|
|
2293
|
+
"glm-4-plus": {
|
|
2294
|
+
currency: "CNY",
|
|
2295
|
+
input_per_million: 5,
|
|
2296
|
+
output_per_million: 5
|
|
2297
|
+
},
|
|
2298
|
+
"glm-4-air": {
|
|
2299
|
+
currency: "CNY",
|
|
2300
|
+
input_per_million: 0.5,
|
|
2301
|
+
output_per_million: 0.5
|
|
2302
|
+
},
|
|
2303
|
+
"glm-4-airx": {
|
|
2304
|
+
currency: "CNY",
|
|
2305
|
+
input_per_million: 10,
|
|
2306
|
+
output_per_million: 10
|
|
2307
|
+
},
|
|
2308
|
+
"glm-4-flashx-250414": {
|
|
2309
|
+
currency: "CNY",
|
|
2310
|
+
input_per_million: 0.1,
|
|
2311
|
+
output_per_million: 0.1
|
|
2312
|
+
},
|
|
2313
|
+
"glm-4-long": {
|
|
2314
|
+
currency: "CNY",
|
|
2315
|
+
input_per_million: 1,
|
|
2316
|
+
output_per_million: 1
|
|
2317
|
+
},
|
|
2318
|
+
"glm-4.5": {
|
|
2319
|
+
currency: "CNY",
|
|
2320
|
+
notes: "legacy, 128K context",
|
|
2321
|
+
input_per_million: 4,
|
|
2322
|
+
output_per_million: 16
|
|
2323
|
+
},
|
|
2324
|
+
"glm-4.6": {
|
|
2325
|
+
currency: "CNY",
|
|
2326
|
+
notes: "legacy, 200K context",
|
|
2327
|
+
input_per_million: 4,
|
|
2328
|
+
output_per_million: 16
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
};
|
|
2333
|
+
|
|
2334
|
+
// ../shared/src/pricing/data/github.ts
|
|
2335
|
+
var github = {
|
|
2336
|
+
// copilot-vscode 仅事件计数(日志里无 token 数),保留空 models 不算费用
|
|
2337
|
+
"copilot-vscode": { models: {} },
|
|
2338
|
+
"copilot-cli": {
|
|
2339
|
+
models: {
|
|
2340
|
+
"gpt-4o": { currency: "USD", input_per_million: 2.5, cached_input_per_million: 1.25, output_per_million: 10 },
|
|
2341
|
+
"gpt-4o-mini": { currency: "USD", input_per_million: 0.15, cached_input_per_million: 0.075, output_per_million: 0.6 },
|
|
2342
|
+
"claude-sonnet-4": { currency: "USD", input_per_million: 3, cached_input_per_million: 0.3, output_per_million: 15 },
|
|
2343
|
+
"claude-sonnet-4-6": { currency: "USD", input_per_million: 3, cached_input_per_million: 0.3, output_per_million: 15 },
|
|
2344
|
+
"o3-mini": { currency: "USD", input_per_million: 1.1, cached_input_per_million: 0.55, output_per_million: 4.4 },
|
|
2345
|
+
"gemini-2.0-flash": { currency: "USD", input_per_million: 0.1, cached_input_per_million: 0.025, output_per_million: 0.4 }
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
};
|
|
2349
|
+
|
|
2350
|
+
// ../shared/src/pricing/data/sourcegraph.ts
|
|
2351
|
+
var sourcegraph = {
|
|
2352
|
+
amp: {
|
|
2353
|
+
models: {
|
|
2354
|
+
"claude-sonnet-4": { currency: "USD", input_per_million: 3, cached_input_per_million: 0.3, output_per_million: 15 },
|
|
2355
|
+
"claude-sonnet-3.7": { currency: "USD", input_per_million: 3, cached_input_per_million: 0.3, output_per_million: 15 },
|
|
2356
|
+
"gemini-2.5-pro": { currency: "USD", input_per_million: 1.25, cached_input_per_million: 0.125, output_per_million: 10 }
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
};
|
|
2360
|
+
|
|
2361
|
+
// ../shared/src/pricing/data/placeholders.ts
|
|
2362
|
+
var inflection = {
|
|
2363
|
+
pi: { models: {} }
|
|
2364
|
+
}, cursor = {
|
|
2365
|
+
cursor: { models: {} }
|
|
2366
|
+
}, droid = {
|
|
2367
|
+
droid: { models: {} }
|
|
2368
|
+
}, opencode = {
|
|
2369
|
+
opencode: { models: {} }
|
|
2370
|
+
};
|
|
2371
|
+
|
|
2372
|
+
// ../shared/src/pricing/catalog.ts
|
|
2373
|
+
var PRICING_VERSION = "2026-05-24-unified-v1", aliases = {
|
|
2374
|
+
"claude-opus-4-7-20260201": "claude-opus-4-7",
|
|
2375
|
+
"claude-sonnet-4-6-20250301": "claude-sonnet-4-6",
|
|
2376
|
+
"claude-opus-4-6-20250301": "claude-opus-4-6",
|
|
2377
|
+
"claude-haiku-4-5-20251001": "claude-haiku-4-5",
|
|
2378
|
+
"claude-sonnet-4.6": "claude-sonnet-4-6",
|
|
2379
|
+
"codex-auto-review": "gpt-5.4"
|
|
2380
|
+
}, catalog = {
|
|
2381
|
+
version: PRICING_VERSION,
|
|
2382
|
+
// 汇率(1 USD ≈ N CNY)。Worker 启动时可被 env 覆盖。
|
|
2383
|
+
fx: {
|
|
2384
|
+
CNY: 7.2
|
|
2385
|
+
},
|
|
2386
|
+
aliases,
|
|
2387
|
+
providers: {
|
|
2388
|
+
anthropic,
|
|
2389
|
+
openai,
|
|
2390
|
+
google,
|
|
2391
|
+
moonshot,
|
|
2392
|
+
alibaba,
|
|
2393
|
+
deepseek,
|
|
2394
|
+
zhipu,
|
|
2395
|
+
github,
|
|
2396
|
+
sourcegraph,
|
|
2397
|
+
inflection,
|
|
2398
|
+
cursor,
|
|
2399
|
+
droid,
|
|
2400
|
+
opencode
|
|
2401
|
+
}
|
|
2402
|
+
};
|
|
2403
|
+
|
|
2404
|
+
// ../shared/src/pricing/calculate.ts
|
|
2405
|
+
var FAST_MULTIPLIER = 6;
|
|
2406
|
+
function resolveModelPricing(catalog2, provider, product, model) {
|
|
2407
|
+
let models = catalog2.providers[provider]?.[product]?.models;
|
|
2408
|
+
if (!models) return null;
|
|
2409
|
+
let aliasResolved = catalog2.aliases[model];
|
|
2410
|
+
if (aliasResolved && models[aliasResolved])
|
|
2411
|
+
return { resolvedModel: aliasResolved, pricing: models[aliasResolved], normalized: !1 };
|
|
2412
|
+
if (models[model])
|
|
2413
|
+
return { resolvedModel: model, pricing: models[model], normalized: !1 };
|
|
2414
|
+
for (let knownModel of Object.keys(models).sort((a, b) => b.length - a.length))
|
|
2415
|
+
if (model.startsWith(`${knownModel}-`))
|
|
2416
|
+
return { resolvedModel: knownModel, pricing: models[knownModel], normalized: !0 };
|
|
2417
|
+
return null;
|
|
2418
|
+
}
|
|
2419
|
+
function selectTier(tiers, totalInputTokens) {
|
|
2420
|
+
for (let i = 0; i < tiers.length; i += 1) {
|
|
2421
|
+
let t2 = tiers[i];
|
|
2422
|
+
if (t2.threshold === void 0 || totalInputTokens <= t2.threshold)
|
|
2423
|
+
return { tier: t2, index: i };
|
|
2424
|
+
}
|
|
2425
|
+
return { tier: tiers[tiers.length - 1], index: tiers.length - 1 };
|
|
2426
|
+
}
|
|
2427
|
+
function toUsd(amount, currency, catalog2) {
|
|
2428
|
+
if (currency === "USD") return amount;
|
|
2429
|
+
let rate = catalog2.fx[currency];
|
|
2430
|
+
return rate ? amount / rate : amount;
|
|
2431
|
+
}
|
|
2432
|
+
function calculateCost(provider, product, model, tokens, options = {}) {
|
|
2433
|
+
let cat = options.catalog ?? catalog;
|
|
2434
|
+
if (tokens.inputTokens + tokens.cachedInputTokens + tokens.cacheWriteTokens + tokens.outputTokens === 0)
|
|
2435
|
+
return { estimatedCostUsd: 0, costStatus: "exact", pricingVersion: cat.version };
|
|
2436
|
+
let isFast = model.endsWith("-fast"), baseModel = isFast ? model.replace(/-fast$/, "") : model, resolved = resolveModelPricing(cat, provider, product, baseModel);
|
|
2437
|
+
if (!resolved)
|
|
2438
|
+
return { estimatedCostUsd: 0, costStatus: "unavailable", pricingVersion: cat.version };
|
|
2439
|
+
let { resolvedModel, pricing, normalized } = resolved, costStatus = normalized ? "estimated" : "exact", unit, matchedTierIndex;
|
|
2440
|
+
if (pricing.tiers && pricing.tiers.length > 0) {
|
|
2441
|
+
let totalIn = tokens.inputTokens + tokens.cachedInputTokens + tokens.cacheWriteTokens, { tier, index } = selectTier(pricing.tiers, totalIn);
|
|
2442
|
+
unit = tier, matchedTierIndex = index;
|
|
2443
|
+
} else
|
|
2444
|
+
unit = {
|
|
2445
|
+
input_per_million: pricing.input_per_million ?? 0,
|
|
2446
|
+
output_per_million: pricing.output_per_million ?? 0,
|
|
2447
|
+
cached_input_per_million: pricing.cached_input_per_million ?? null,
|
|
2448
|
+
cache_write_5m_per_million: pricing.cache_write_5m_per_million ?? 0,
|
|
2449
|
+
cache_write_1h_per_million: pricing.cache_write_1h_per_million ?? 0
|
|
2450
|
+
};
|
|
2451
|
+
let cw5Rate = unit.cache_write_5m_per_million ?? pricing.cache_write_5m_per_million ?? 0, cw1hRate = unit.cache_write_1h_per_million ?? pricing.cache_write_1h_per_million ?? 0, cachedRate = unit.cached_input_per_million ?? pricing.cached_input_per_million ?? 0, raw = tokens.inputTokens / 1e6 * (unit.input_per_million ?? 0) + tokens.cachedInputTokens / 1e6 * (cachedRate ?? 0) + (tokens.cacheWrite5mTokens ?? tokens.cacheWriteTokens) / 1e6 * cw5Rate + (tokens.cacheWrite1hTokens ?? 0) / 1e6 * cw1hRate + tokens.outputTokens / 1e6 * (unit.output_per_million ?? 0);
|
|
2452
|
+
raw = toUsd(raw, pricing.currency, cat);
|
|
2453
|
+
let finalCost = isFast ? raw * FAST_MULTIPLIER : raw;
|
|
2454
|
+
return {
|
|
2455
|
+
estimatedCostUsd: Math.round(finalCost * 1e4) / 1e4,
|
|
2456
|
+
costStatus,
|
|
2457
|
+
pricingVersion: cat.version,
|
|
2458
|
+
resolvedModel,
|
|
2459
|
+
matchedTierIndex
|
|
2460
|
+
};
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2463
|
+
// src/report.ts
|
|
1590
2464
|
async function buildLocalReport(range, options = {}) {
|
|
1591
2465
|
let requestedDates = options.dates ? options.dates : range === "all" ? await discoverAllDates() : range === "today" ? [toDateKey3(getTodayLocalDate())] : buildPresetDates(range), daily = [], totals = createEmptyTotals2(), bySource = /* @__PURE__ */ new Map(), byModel = /* @__PURE__ */ new Map(), pricingWarnings = /* @__PURE__ */ new Set(), daysWithData = 0, results = await scanDates(requestedDates, { projectAliases: options.projectAliases });
|
|
1592
2466
|
for (let result of results) {
|
|
@@ -1963,82 +2837,6 @@ function createEmptyTotals2() {
|
|
|
1963
2837
|
function mergeTotals(target, source) {
|
|
1964
2838
|
return target.eventCount += source.eventCount, target.inputTokens += source.inputTokens, target.cachedInputTokens += source.cachedInputTokens, target.cacheWriteTokens += source.cacheWriteTokens, target.outputTokens += source.outputTokens, target.reasoningOutputTokens += source.reasoningOutputTokens, target.totalTokens += source.totalTokens, target.estimatedCostUsd += source.estimatedCostUsd, target;
|
|
1965
2839
|
}
|
|
1966
|
-
var FAST_MULTIPLIER = 6, CLAUDE_PRICING = {
|
|
1967
|
-
"claude-opus-4-6": { input: 5, cache_write_5m: 6.25, cache_write_1h: 10, cache_read: 0.5, output: 25 },
|
|
1968
|
-
"claude-opus-4-5": { input: 5, cache_write_5m: 6.25, cache_write_1h: 10, cache_read: 0.5, output: 25 },
|
|
1969
|
-
"claude-opus-4-1": { input: 15, cache_write_5m: 18.75, cache_write_1h: 30, cache_read: 1.5, output: 75 },
|
|
1970
|
-
"claude-opus-4": { input: 15, cache_write_5m: 18.75, cache_write_1h: 30, cache_read: 1.5, output: 75 },
|
|
1971
|
-
"claude-opus-3": { input: 15, cache_write_5m: 18.75, cache_write_1h: 30, cache_read: 1.5, output: 75 },
|
|
1972
|
-
"claude-sonnet-4-6": { input: 3, cache_write_5m: 3.75, cache_write_1h: 6, cache_read: 0.3, output: 15 },
|
|
1973
|
-
"claude-sonnet-4-5": { input: 3, cache_write_5m: 3.75, cache_write_1h: 6, cache_read: 0.3, output: 15 },
|
|
1974
|
-
"claude-sonnet-4": { input: 3, cache_write_5m: 3.75, cache_write_1h: 6, cache_read: 0.3, output: 15 },
|
|
1975
|
-
"claude-sonnet-3.7": { input: 3, cache_write_5m: 3.75, cache_write_1h: 6, cache_read: 0.3, output: 15 },
|
|
1976
|
-
"claude-haiku-4-5": { input: 1, cache_write_5m: 1.25, cache_write_1h: 2, cache_read: 0.1, output: 5 },
|
|
1977
|
-
"claude-haiku-3-5": { input: 0.8, cache_write_5m: 1, cache_write_1h: 1.6, cache_read: 0.08, output: 4 },
|
|
1978
|
-
"claude-haiku-3": { input: 0.25, cache_write_5m: 0.3, cache_write_1h: 0.5, cache_read: 0.03, output: 1.25 }
|
|
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 },
|
|
1982
|
-
"gpt-5.4-pro": { input: 30, cached_input: null, output: 180, estimated: !1 },
|
|
1983
|
-
"gpt-5.4": { input: 2.5, cached_input: 0.25, output: 15, estimated: !1 },
|
|
1984
|
-
"gpt-5.4-mini": { input: 0.75, cached_input: 0.075, output: 4.5, estimated: !1 },
|
|
1985
|
-
"gpt-5.4-nano": { input: 0.2, cached_input: 0.02, output: 1.25, estimated: !1 },
|
|
1986
|
-
"gpt-5.2-pro": { input: 21, cached_input: null, output: 168, estimated: !1 },
|
|
1987
|
-
"gpt-5.2": { input: 1.75, cached_input: 0.175, output: 14, estimated: !1 },
|
|
1988
|
-
"gpt-5.1": { input: 1.25, cached_input: 0.125, output: 10, estimated: !1 },
|
|
1989
|
-
"gpt-5": { input: 1.25, cached_input: 0.125, output: 10, estimated: !1 },
|
|
1990
|
-
"gpt-5-pro": { input: 15, cached_input: null, output: 120, estimated: !1 },
|
|
1991
|
-
"gpt-5-mini": { input: 0.25, cached_input: 0.025, output: 2, estimated: !1 },
|
|
1992
|
-
"gpt-5-nano": { input: 0.05, cached_input: 5e-3, output: 0.4, estimated: !1 },
|
|
1993
|
-
"gpt-5-codex": { input: 1.25, cached_input: 0.125, output: 10, estimated: !1 },
|
|
1994
|
-
"gpt-5.1-codex": { input: 1.25, cached_input: 0.125, output: 10, estimated: !1 },
|
|
1995
|
-
"gpt-5.1-codex-mini": { input: 0.25, cached_input: 0.025, output: 2, estimated: !1 },
|
|
1996
|
-
"gpt-5.1-codex-max": { input: 1.25, cached_input: 0.125, output: 10, estimated: !1 },
|
|
1997
|
-
"gpt-5.2-codex": { input: 1.75, cached_input: 0.175, output: 14, estimated: !1 },
|
|
1998
|
-
"gpt-5.3-codex": { input: 1.75, cached_input: 0.175, output: 14, estimated: !1 },
|
|
1999
|
-
"gpt-4.1": { input: 2, cached_input: 0.5, output: 8, estimated: !1 },
|
|
2000
|
-
"gpt-4.1-mini": { input: 0.4, cached_input: 0.1, output: 1.6, estimated: !1 },
|
|
2001
|
-
"gpt-4.1-nano": { input: 0.1, cached_input: 0.025, output: 0.4, estimated: !1 },
|
|
2002
|
-
"gpt-4o": { input: 2.5, cached_input: 1.25, output: 10, estimated: !1 },
|
|
2003
|
-
"gpt-4o-2024-05-13": { input: 5, cached_input: null, output: 15, estimated: !1 },
|
|
2004
|
-
"gpt-4o-mini": { input: 0.15, cached_input: 0.075, output: 0.6, estimated: !1 },
|
|
2005
|
-
o1: { input: 15, cached_input: 7.5, output: 60, estimated: !1 },
|
|
2006
|
-
"o1-pro": { input: 150, cached_input: null, output: 600, estimated: !1 },
|
|
2007
|
-
"o3-pro": { input: 20, cached_input: null, output: 80, estimated: !1 },
|
|
2008
|
-
o3: { input: 2, cached_input: 0.5, output: 8, estimated: !1 },
|
|
2009
|
-
"o4-mini": { input: 1.1, cached_input: 0.275, output: 4.4, estimated: !1 },
|
|
2010
|
-
"o3-mini": { input: 1.1, cached_input: 0.55, output: 4.4, estimated: !1 },
|
|
2011
|
-
"o1-mini": { input: 1.1, cached_input: 0.55, output: 4.4, estimated: !1 },
|
|
2012
|
-
"gpt-4-turbo-2024-04-09": { input: 10, cached_input: null, output: 30, estimated: !1 },
|
|
2013
|
-
"gpt-4-0125-preview": { input: 10, cached_input: null, output: 30, estimated: !1 },
|
|
2014
|
-
"gpt-4-1106-preview": { input: 10, cached_input: null, output: 30, estimated: !1 },
|
|
2015
|
-
"gpt-4-1106-vision-preview": { input: 10, cached_input: null, output: 30, estimated: !1 },
|
|
2016
|
-
"gpt-4-0613": { input: 30, cached_input: null, output: 60, estimated: !1 },
|
|
2017
|
-
"gpt-4-0314": { input: 30, cached_input: null, output: 60, estimated: !1 },
|
|
2018
|
-
"gpt-4-32k": { input: 60, cached_input: null, output: 120, estimated: !1 },
|
|
2019
|
-
"gpt-3.5-turbo": { input: 0.5, cached_input: null, output: 1.5, estimated: !1 },
|
|
2020
|
-
"gpt-3.5-turbo-0125": { input: 0.5, cached_input: null, output: 1.5, estimated: !1 },
|
|
2021
|
-
"gpt-3.5-turbo-1106": { input: 1, cached_input: null, output: 2, estimated: !1 },
|
|
2022
|
-
"gpt-3.5-turbo-0613": { input: 1.5, cached_input: null, output: 2, estimated: !1 },
|
|
2023
|
-
"gpt-3.5-0301": { input: 1.5, cached_input: null, output: 2, estimated: !1 },
|
|
2024
|
-
"gpt-3.5-turbo-instruct": { input: 1.5, cached_input: null, output: 2, estimated: !1 },
|
|
2025
|
-
"gpt-3.5-turbo-16k-0613": { input: 3, cached_input: null, output: 4, estimated: !1 },
|
|
2026
|
-
"davinci-002": { input: 2, cached_input: null, output: 2, estimated: !1 },
|
|
2027
|
-
"babbage-002": { input: 0.4, cached_input: null, output: 0.4, estimated: !1 },
|
|
2028
|
-
"o3-deep-research": { input: 10, cached_input: 2.5, output: 40, estimated: !1 },
|
|
2029
|
-
"o4-mini-deep-research": { input: 2, cached_input: 0.5, output: 8, estimated: !1 },
|
|
2030
|
-
"computer-use-preview": { input: 3, cached_input: null, output: 12, estimated: !1 },
|
|
2031
|
-
"text-embedding-3-small": { input: 0.02, cached_input: null, output: 0, estimated: !1 },
|
|
2032
|
-
"text-embedding-3-large": { input: 0.13, cached_input: null, output: 0, estimated: !1 },
|
|
2033
|
-
"text-embedding-ada-002": { input: 0.1, cached_input: null, output: 0, 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" }
|
|
2036
|
-
}, GEMINI_PRICING = {
|
|
2037
|
-
"gemini-3-flash": { input: 0.1, cache_read: 0.025, output: 0.4 },
|
|
2038
|
-
"gemini-2.0-flash": { input: 0.1, cache_read: 0.025, output: 0.4 },
|
|
2039
|
-
"gemini-1.5-flash": { input: 0.075, cache_read: 0.01875, output: 0.3 },
|
|
2040
|
-
"gemini-1.5-pro": { input: 3.5, cache_read: 0.875, output: 10.5 }
|
|
2041
|
-
};
|
|
2042
2840
|
function toBreakdownTotals(breakdown, warnings) {
|
|
2043
2841
|
let estimatedCostUsd = calculateBreakdownCost(breakdown, warnings);
|
|
2044
2842
|
return {
|
|
@@ -2055,37 +2853,20 @@ function toBreakdownTotals(breakdown, warnings) {
|
|
|
2055
2853
|
function calculateBreakdownCost(breakdown, warnings) {
|
|
2056
2854
|
if (breakdown.costUSD != null && breakdown.costUSD > 0)
|
|
2057
2855
|
return breakdown.costUSD;
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
}
|
|
2073
|
-
if (breakdown.provider === "google" && breakdown.product === "gemini-cli") {
|
|
2074
|
-
let resolved = resolveModel(breakdown.model, GEMINI_PRICING);
|
|
2075
|
-
if (!resolved)
|
|
2076
|
-
return warnings.add(`Gemini \u6A21\u578B ${breakdown.model} \u672A\u914D\u7F6E\u516C\u5F00\u5355\u4EF7\uFF0C\u5DF2\u8DF3\u8FC7\u6210\u672C\u4F30\u7B97\u3002`), 0;
|
|
2077
|
-
let pricing = GEMINI_PRICING[resolved.model];
|
|
2078
|
-
return resolved.normalized && warnings.add(`${breakdown.model} \u5DF2\u6309 ${resolved.model} \u7684\u516C\u5F00\u5355\u4EF7\u4F30\u7B97\u3002`), breakdown.inputTokens / 1e6 * pricing.input + breakdown.cachedInputTokens / 1e6 * pricing.cache_read + breakdown.outputTokens / 1e6 * pricing.output;
|
|
2079
|
-
}
|
|
2080
|
-
return warnings.add(`${breakdown.provider}/${breakdown.product} \u6682\u65E0\u672C\u5730\u5B9A\u4EF7\u7B56\u7565\uFF0C\u5DF2\u8DF3\u8FC7\u6210\u672C\u4F30\u7B97\u3002`), 0;
|
|
2081
|
-
}
|
|
2082
|
-
function resolveModel(model, pricingTable) {
|
|
2083
|
-
if (model in pricingTable)
|
|
2084
|
-
return { model, normalized: !1 };
|
|
2085
|
-
for (let known of Object.keys(pricingTable).sort((a, b) => b.length - a.length))
|
|
2086
|
-
if (model.startsWith(`${known}-`))
|
|
2087
|
-
return { model: known, normalized: !0 };
|
|
2088
|
-
return null;
|
|
2856
|
+
let result = calculateCost(
|
|
2857
|
+
breakdown.provider,
|
|
2858
|
+
breakdown.product,
|
|
2859
|
+
breakdown.model,
|
|
2860
|
+
{
|
|
2861
|
+
inputTokens: breakdown.inputTokens,
|
|
2862
|
+
cachedInputTokens: breakdown.cachedInputTokens,
|
|
2863
|
+
cacheWriteTokens: breakdown.cacheWriteTokens,
|
|
2864
|
+
cacheWrite5mTokens: breakdown.cacheWrite5mTokens,
|
|
2865
|
+
cacheWrite1hTokens: breakdown.cacheWrite1hTokens,
|
|
2866
|
+
outputTokens: breakdown.outputTokens
|
|
2867
|
+
}
|
|
2868
|
+
);
|
|
2869
|
+
return result.costStatus === "unavailable" ? warnings.add(`${breakdown.provider}/${breakdown.product}/${breakdown.model} \u6682\u65E0\u5B9A\u4EF7\u914D\u7F6E\uFF0C\u5DF2\u8DF3\u8FC7\u6210\u672C\u4F30\u7B97\u3002`) : result.costStatus === "estimated" && result.resolvedModel && result.resolvedModel !== breakdown.model && warnings.add(`${breakdown.model} \u5DF2\u6309 ${result.resolvedModel} \u7684\u516C\u5F00\u5355\u4EF7\u4F30\u7B97\u3002`), result.estimatedCostUsd;
|
|
2089
2870
|
}
|
|
2090
2871
|
|
|
2091
2872
|
// src/i18n.ts
|
|
@@ -2477,13 +3258,7 @@ function defaultLookbackDays(config) {
|
|
|
2477
3258
|
return config.lookbackDays ?? DEFAULT_LOOKBACK_DAYS;
|
|
2478
3259
|
}
|
|
2479
3260
|
async function requestJson(url, init) {
|
|
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;
|
|
3261
|
+
let response = await fetch(url, init), text = await response.text(), data = null;
|
|
2487
3262
|
if (text)
|
|
2488
3263
|
try {
|
|
2489
3264
|
data = JSON.parse(text);
|
|
@@ -2498,13 +3273,6 @@ async function requestJson(url, init) {
|
|
|
2498
3273
|
throw new Error("\u670D\u52A1\u7AEF\u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94");
|
|
2499
3274
|
return data;
|
|
2500
3275
|
}
|
|
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
|
-
}
|
|
2508
3276
|
|
|
2509
3277
|
// src/schedule.ts
|
|
2510
3278
|
import { mkdir as mkdir2, readFile as readFile15, stat, unlink, writeFile as writeFile2 } from "node:fs/promises";
|
|
@@ -3119,11 +3887,11 @@ try {
|
|
|
3119
3887
|
if (command === "--version" || command === "-v")
|
|
3120
3888
|
console.log(getVersion());
|
|
3121
3889
|
else if (command === "scan") {
|
|
3122
|
-
let parsed = parseArgs(argv.slice(1))
|
|
3123
|
-
await runScan(
|
|
3890
|
+
let parsed = parseArgs(argv.slice(1));
|
|
3891
|
+
await runScan(parsed.flags, parsed.positionals);
|
|
3124
3892
|
} else if (command === "report") {
|
|
3125
3893
|
let parsed = parseArgs(argv.slice(1));
|
|
3126
|
-
await runReport(parsed.flags);
|
|
3894
|
+
await runReport(parsed.flags, parsed.positionals);
|
|
3127
3895
|
} else if (command === "health") {
|
|
3128
3896
|
let parsed = parseArgs(argv.slice(1));
|
|
3129
3897
|
await runHealth(parsed.flags);
|
|
@@ -3132,7 +3900,7 @@ try {
|
|
|
3132
3900
|
await runEnroll(parsed.flags);
|
|
3133
3901
|
} else if (command === "sync") {
|
|
3134
3902
|
let parsed = parseArgs(argv.slice(1));
|
|
3135
|
-
await runSync(parsed.flags);
|
|
3903
|
+
await runSync(parsed.flags, parsed.positionals);
|
|
3136
3904
|
} else if (command === "init") {
|
|
3137
3905
|
let parsed = parseArgs(argv.slice(1));
|
|
3138
3906
|
await runInit(parsed.flags);
|
|
@@ -3185,15 +3953,30 @@ try {
|
|
|
3185
3953
|
} catch (error) {
|
|
3186
3954
|
console.error(error instanceof Error ? error.message : String(error)), process.exitCode = 1;
|
|
3187
3955
|
}
|
|
3188
|
-
async function runScan(
|
|
3956
|
+
async function runScan(flags, positionals = []) {
|
|
3189
3957
|
let config = await readConfig(), zh2 = config.lang === "zh";
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
let result = await scanDate(date, { projectAliases: config.projectAliases });
|
|
3958
|
+
assertNoPositionals("scan", positionals, zh2);
|
|
3959
|
+
let isJson = !!flags.json, dates = resolveScanDates(flags, config), results = dates.length === 1 ? [await scanDate(dates[0], { projectAliases: config.projectAliases })] : await scanDates(dates, { projectAliases: config.projectAliases });
|
|
3193
3960
|
if (isJson) {
|
|
3194
|
-
console.log(JSON.stringify(
|
|
3961
|
+
console.log(JSON.stringify(results.length === 1 ? results[0] : results, null, 2));
|
|
3195
3962
|
return;
|
|
3196
3963
|
}
|
|
3964
|
+
if (results.length === 1) {
|
|
3965
|
+
console.log(`${zh2 ? "\u626B\u63CF\u65E5\u671F" : "Scan date"}: ${results[0].usageDate}
|
|
3966
|
+
`), printScanResult(results[0], zh2);
|
|
3967
|
+
return;
|
|
3968
|
+
}
|
|
3969
|
+
console.log(`${zh2 ? "\u626B\u63CF\u8303\u56F4" : "Scan range"}: ${dates[0]} ~ ${dates[dates.length - 1]} (${dates.length} ${zh2 ? "\u5929" : "days"})
|
|
3970
|
+
`);
|
|
3971
|
+
let daysWithData = results.filter((result) => result.breakdowns.length > 0);
|
|
3972
|
+
if (daysWithData.length === 0) {
|
|
3973
|
+
console.log(zh2 ? "\u8BE5\u8303\u56F4\u65E0\u6570\u636E\u3002" : "No data in this range.");
|
|
3974
|
+
return;
|
|
3975
|
+
}
|
|
3976
|
+
for (let result of daysWithData)
|
|
3977
|
+
console.log(`\u2550\u2550 ${result.usageDate} \u2550\u2550`), printScanResult(result, zh2);
|
|
3978
|
+
}
|
|
3979
|
+
function printScanResult(result, zh2) {
|
|
3197
3980
|
if (result.breakdowns.length === 0) {
|
|
3198
3981
|
console.log(zh2 ? "\u8BE5\u65E5\u65E0\u6570\u636E\u3002" : "No data for this date.");
|
|
3199
3982
|
return;
|
|
@@ -3209,10 +3992,12 @@ async function runScan(date, isJson) {
|
|
|
3209
3992
|
console.log(` ${b.model} | ${b.projectAlias ?? b.projectDisplay ?? b.project}`), console.log(` \u4E8B\u4EF6: ${b.eventCount} \u8F93\u5165: ${fmt(b.inputTokens)} \u7F13\u5B58\u8BFB: ${fmt(b.cachedInputTokens)} \u7F13\u5B58\u5199: ${fmt(b.cacheWriteTokens)} \u8F93\u51FA: ${fmt(b.outputTokens)} \u63A8\u7406: ${fmt(b.reasoningOutputTokens)}`);
|
|
3210
3993
|
console.log();
|
|
3211
3994
|
}
|
|
3212
|
-
console.log("\u2500\u2500 \u5408\u8BA1 \u2500\u2500"), console.log(` \u4E8B\u4EF6: ${result.totals.eventCount} \u8F93\u5165: ${fmt(result.totals.inputTokens)} \u7F13\u5B58\u8BFB: ${fmt(result.totals.cachedInputTokens)} \u7F13\u5B58\u5199: ${fmt(result.totals.cacheWriteTokens)} \u8F93\u51FA: ${fmt(result.totals.outputTokens)} \u63A8\u7406: ${fmt(result.totals.reasoningOutputTokens)}`);
|
|
3995
|
+
console.log("\u2500\u2500 \u5408\u8BA1 \u2500\u2500"), console.log(` \u4E8B\u4EF6: ${result.totals.eventCount} \u8F93\u5165: ${fmt(result.totals.inputTokens)} \u7F13\u5B58\u8BFB: ${fmt(result.totals.cachedInputTokens)} \u7F13\u5B58\u5199: ${fmt(result.totals.cacheWriteTokens)} \u8F93\u51FA: ${fmt(result.totals.outputTokens)} \u63A8\u7406: ${fmt(result.totals.reasoningOutputTokens)}`), console.log();
|
|
3213
3996
|
}
|
|
3214
|
-
async function runReport(flags) {
|
|
3215
|
-
let config = await readConfig()
|
|
3997
|
+
async function runReport(flags, positionals = []) {
|
|
3998
|
+
let config = await readConfig();
|
|
3999
|
+
assertNoPositionals("report", positionals, config.lang === "zh");
|
|
4000
|
+
let { dates, range } = resolveDateParams(flags, config), report = await buildLocalReport(range, { projectAliases: config.projectAliases, dates });
|
|
3216
4001
|
if (flags.json) {
|
|
3217
4002
|
console.log(JSON.stringify(report, null, 2));
|
|
3218
4003
|
return;
|
|
@@ -3263,13 +4048,15 @@ function prompt(question) {
|
|
|
3263
4048
|
});
|
|
3264
4049
|
});
|
|
3265
4050
|
}
|
|
3266
|
-
async function runSync(flags) {
|
|
3267
|
-
let config = await readConfig()
|
|
4051
|
+
async function runSync(flags, positionals = []) {
|
|
4052
|
+
let config = await readConfig();
|
|
4053
|
+
assertNoPositionals("sync", positionals, config.lang === "zh");
|
|
4054
|
+
let allTargets = config.targets ?? [];
|
|
3268
4055
|
if (allTargets.length === 0)
|
|
3269
4056
|
throw new Error("\u672A\u914D\u7F6E\u4EFB\u4F55\u4E0A\u62A5\u76EE\u6807\uFF0C\u8BF7\u5148\u6267\u884C aiusage enroll");
|
|
3270
4057
|
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
4058
|
if (!targetDates)
|
|
3272
|
-
throw new Error("sync \
|
|
4059
|
+
throw new Error("sync --range all \u9700\u8981\u660E\u786E\u65E5\u671F\u8303\u56F4\uFF0C\u8BF7\u6539\u7528 --from YYYY-MM-DD --to YYYY-MM-DD");
|
|
3273
4060
|
console.log(`\u626B\u63CF ${targetDates.length} \u5929 (${targetDates[0]} ~ ${targetDates[targetDates.length - 1]}) ...`);
|
|
3274
4061
|
let allDays = (await scanDates(targetDates, { projectAliases: config.projectAliases })).filter((r) => r.breakdowns.length > 0).map((r) => ({ usageDate: r.usageDate, breakdowns: r.breakdowns }));
|
|
3275
4062
|
if (allDays.length === 0) {
|
|
@@ -3432,7 +4219,7 @@ ${zh2 ? "\u5171" : "Total:"} ${projects.length} ${zh2 ? "\u4E2A\u9879\u76EE" : "
|
|
|
3432
4219
|
async function runProjectAlias(args) {
|
|
3433
4220
|
let config = await readConfig(), zh2 = config.lang === "zh";
|
|
3434
4221
|
if (args.length === 0) {
|
|
3435
|
-
let
|
|
4222
|
+
let aliases2 = config.projectAliases ?? {}, entries = Object.entries(aliases2);
|
|
3436
4223
|
if (entries.length === 0) {
|
|
3437
4224
|
console.log(zh2 ? "\u5C1A\u672A\u8BBE\u7F6E\u4EFB\u4F55\u9879\u76EE\u522B\u540D\u3002" : "No project aliases configured."), console.log(zh2 ? "\u7528\u6CD5: aiusage project alias <\u9879\u76EE\u540D> <\u522B\u540D>" : "Usage: aiusage project alias <name> <alias>");
|
|
3438
4225
|
return;
|
|
@@ -3444,10 +4231,10 @@ async function runProjectAlias(args) {
|
|
|
3444
4231
|
if (args[0] === "--remove") {
|
|
3445
4232
|
let name2 = args.slice(1).join(" ").trim();
|
|
3446
4233
|
if (!name2) throw new Error(zh2 ? "\u8BF7\u6307\u5B9A\u8981\u79FB\u9664\u522B\u540D\u7684\u9879\u76EE\u540D" : "Please specify the project name to remove");
|
|
3447
|
-
let
|
|
3448
|
-
if (!(name2 in
|
|
4234
|
+
let aliases2 = { ...config.projectAliases ?? {} };
|
|
4235
|
+
if (!(name2 in aliases2))
|
|
3449
4236
|
throw new Error(zh2 ? `\u9879\u76EE "${name2}" \u672A\u8BBE\u7F6E\u522B\u540D` : `No alias set for "${name2}"`);
|
|
3450
|
-
delete
|
|
4237
|
+
delete aliases2[name2], config.projectAliases = Object.keys(aliases2).length > 0 ? aliases2 : void 0, await writeConfig(config), console.log(zh2 ? `\u5DF2\u79FB\u9664 "${name2}" \u7684\u522B\u540D\u3002` : `Removed alias for "${name2}".`);
|
|
3451
4238
|
return;
|
|
3452
4239
|
}
|
|
3453
4240
|
if (args.length < 2)
|
|
@@ -3460,10 +4247,10 @@ function printHelp(zh2 = !1) {
|
|
|
3460
4247
|
console.log(`aiusage v${getVersion()}
|
|
3461
4248
|
`);
|
|
3462
4249
|
let cmds = zh2 ? [
|
|
3463
|
-
["scan [--date YYYY-MM-DD] [--json]", "\u626B\u63CF\
|
|
4250
|
+
["scan [--date YYYY-MM-DD|--today|--range 7d|1m|3m] [--json]", "\u626B\u63CF\u7528\u91CF\u660E\u7EC6"],
|
|
3464
4251
|
["report [--today] [--range 7d|1m|3m|all] [--detail] [--json]", "\u672C\u5730\u7528\u91CF\u62A5\u544A"],
|
|
3465
|
-
["sync [--today] [--range 7d|1m|3m
|
|
3466
|
-
["report/sync --from YYYY-MM-DD [--to YYYY-MM-DD]", "\u6307\u5B9A\u65E5\u671F\u8303\u56F4\uFF08--start/--end \u540C\u4E49\uFF09"],
|
|
4252
|
+
["sync [--today] [--range 7d|1m|3m]", "\u4E0A\u4F20\u7528\u91CF\u5230\u670D\u52A1\u7AEF"],
|
|
4253
|
+
["scan/report/sync --from YYYY-MM-DD [--to YYYY-MM-DD]", "\u6307\u5B9A\u65E5\u671F\u8303\u56F4\uFF08--start/--end \u540C\u4E49\uFF09"],
|
|
3467
4254
|
["project [list|alias]", "\u9879\u76EE\u7BA1\u7406\u4E0E\u522B\u540D\u8BBE\u7F6E"],
|
|
3468
4255
|
["schedule [on|off|status] [--every 5m]", "\u5B9A\u65F6\u540C\u6B65\u7BA1\u7406"],
|
|
3469
4256
|
["doctor", "\u8BCA\u65AD\u68C0\u67E5"],
|
|
@@ -3472,10 +4259,10 @@ function printHelp(zh2 = !1) {
|
|
|
3472
4259
|
["enroll --server URL --site-id ID --enroll-token TOKEN", "\u6CE8\u518C\u8BBE\u5907\u5230\u670D\u52A1\u7AEF"],
|
|
3473
4260
|
["health [--server URL]", "\u6D4B\u8BD5\u670D\u52A1\u7AEF\u8FDE\u901A\u6027"]
|
|
3474
4261
|
] : [
|
|
3475
|
-
["scan [--date YYYY-MM-DD] [--json]", "Scan
|
|
4262
|
+
["scan [--date YYYY-MM-DD|--today|--range 7d|1m|3m] [--json]", "Scan usage breakdown"],
|
|
3476
4263
|
["report [--today] [--range 7d|1m|3m|all] [--detail] [--json]", "Local usage report"],
|
|
3477
|
-
["sync [--today] [--range 7d|1m|3m
|
|
3478
|
-
["report/sync --from YYYY-MM-DD [--to YYYY-MM-DD]", "Date range (--start/--end aliases)"],
|
|
4264
|
+
["sync [--today] [--range 7d|1m|3m]", "Upload usage to server"],
|
|
4265
|
+
["scan/report/sync --from YYYY-MM-DD [--to YYYY-MM-DD]", "Date range (--start/--end aliases)"],
|
|
3479
4266
|
["project [list|alias]", "Project management & aliases"],
|
|
3480
4267
|
["schedule [on|off|status] [--every 5m]", "Scheduled sync management"],
|
|
3481
4268
|
["doctor", "Run diagnostics"],
|
|
@@ -3493,17 +4280,17 @@ function printUsageHint(zh2 = !1) {
|
|
|
3493
4280
|
console.log(`aiusage v${getVersion()}
|
|
3494
4281
|
`);
|
|
3495
4282
|
let cmds = zh2 ? [
|
|
3496
|
-
["scan [--date YYYY-MM-DD]", "\u626B\u63CF\
|
|
4283
|
+
["scan [--date YYYY-MM-DD|--range 1m]", "\u626B\u63CF\u7528\u91CF\u660E\u7EC6"],
|
|
3497
4284
|
["report [--today] [--range 7d|1m|3m|all]", "\u672C\u5730\u7528\u91CF\u62A5\u544A"],
|
|
3498
|
-
["sync [--today] [--range 7d|1m|3m
|
|
4285
|
+
["sync [--today] [--range 7d|1m|3m]", "\u4E0A\u4F20\u7528\u91CF\u5230\u670D\u52A1\u7AEF"],
|
|
3499
4286
|
["project [list|alias]", "\u9879\u76EE\u7BA1\u7406\u4E0E\u522B\u540D\u8BBE\u7F6E"],
|
|
3500
4287
|
["schedule [on|off|status]", "\u5B9A\u65F6\u540C\u6B65\u7BA1\u7406"],
|
|
3501
4288
|
["doctor", "\u8BCA\u65AD\u68C0\u67E5"],
|
|
3502
4289
|
["config set <key> <value>", "\u4FEE\u6539\u914D\u7F6E"]
|
|
3503
4290
|
] : [
|
|
3504
|
-
["scan [--date YYYY-MM-DD]", "Scan
|
|
4291
|
+
["scan [--date YYYY-MM-DD|--range 1m]", "Scan usage breakdown"],
|
|
3505
4292
|
["report [--today] [--range 7d|1m|3m|all]", "Local usage report"],
|
|
3506
|
-
["sync [--today] [--range 7d|1m|3m
|
|
4293
|
+
["sync [--today] [--range 7d|1m|3m]", "Upload usage to server"],
|
|
3507
4294
|
["project [list|alias]", "Project management & aliases"],
|
|
3508
4295
|
["schedule [on|off|status]", "Scheduled sync management"],
|
|
3509
4296
|
["doctor", "Run diagnostics"],
|
|
@@ -3536,6 +4323,13 @@ function parseArgs(args) {
|
|
|
3536
4323
|
}
|
|
3537
4324
|
return { flags, positionals };
|
|
3538
4325
|
}
|
|
4326
|
+
function assertNoPositionals(command2, positionals, zh2 = !1) {
|
|
4327
|
+
if (positionals.length === 0) return;
|
|
4328
|
+
let value = positionals.join(" "), rangeHint = positionals.includes("range") || positionals.some((arg) => /^-\d+[dm]$/.test(arg));
|
|
4329
|
+
throw zh2 ? new Error(rangeHint ? `${command2} \u4E0D\u652F\u6301\u4F4D\u7F6E\u53C2\u6570: ${value}
|
|
4330
|
+
\u65F6\u95F4\u8303\u56F4\u8BF7\u4F7F\u7528 --range 1m\uFF0C\u4F8B\u5982: aiusage ${command2} --range 1m` : `${command2} \u4E0D\u652F\u6301\u4F4D\u7F6E\u53C2\u6570: ${value}`) : new Error(rangeHint ? `${command2} does not accept positional arguments: ${value}
|
|
4331
|
+
Use --range 1m, for example: aiusage ${command2} --range 1m` : `${command2} does not accept positional arguments: ${value}`);
|
|
4332
|
+
}
|
|
3539
4333
|
function localDateKey(d) {
|
|
3540
4334
|
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
3541
4335
|
}
|
|
@@ -3545,6 +4339,8 @@ function getYesterdayDate() {
|
|
|
3545
4339
|
}
|
|
3546
4340
|
function resolveDateParams(flags, config) {
|
|
3547
4341
|
let requestedDate = typeof flags.date == "string" ? flags.date : void 0, fromDate = typeof flags.from == "string" ? flags.from : typeof flags.start == "string" ? flags.start : void 0, toDate = typeof flags.to == "string" ? flags.to : typeof flags.end == "string" ? flags.end : void 0;
|
|
4342
|
+
if (toDate && !fromDate)
|
|
4343
|
+
throw new Error("--to \u9700\u8981\u642D\u914D --from \u4F7F\u7528");
|
|
3548
4344
|
if (requestedDate)
|
|
3549
4345
|
return { dates: [requestedDate], range: "today" };
|
|
3550
4346
|
if (fromDate)
|
|
@@ -3552,8 +4348,10 @@ function resolveDateParams(flags, config) {
|
|
|
3552
4348
|
if (flags.today === !0)
|
|
3553
4349
|
return { dates: [getTodayDate()], range: "today" };
|
|
3554
4350
|
let rangeFlag = flags.range;
|
|
3555
|
-
if (typeof rangeFlag == "string")
|
|
3556
|
-
|
|
4351
|
+
if (typeof rangeFlag == "string") {
|
|
4352
|
+
let range = parseReportRange(rangeFlag);
|
|
4353
|
+
return range === "today" ? { dates: [getTodayDate()], range } : range === "7d" ? { dates: [...getClosedDates(6), getTodayDate()], range } : range === "1m" ? { dates: [...getClosedDates(29), getTodayDate()], range } : range === "3m" ? { dates: [...getClosedDates(89), getTodayDate()], range } : { range };
|
|
4354
|
+
}
|
|
3557
4355
|
if (typeof flags.lookback == "string") {
|
|
3558
4356
|
let lookbackDays2 = parsePositiveInt2(flags.lookback, "--lookback"), dates2 = getClosedDates(lookbackDays2);
|
|
3559
4357
|
return dates2.push(getTodayDate()), { dates: dates2, range: "7d" };
|
|
@@ -3561,6 +4359,16 @@ function resolveDateParams(flags, config) {
|
|
|
3561
4359
|
let lookbackDays = defaultLookbackDays(config), dates = getClosedDates(lookbackDays);
|
|
3562
4360
|
return dates.push(getTodayDate()), { dates, range: "7d" };
|
|
3563
4361
|
}
|
|
4362
|
+
function resolveScanDates(flags, config) {
|
|
4363
|
+
if (!hasDateSelection(flags)) return [getYesterdayDate()];
|
|
4364
|
+
let { dates } = resolveDateParams(flags, config);
|
|
4365
|
+
if (!dates)
|
|
4366
|
+
throw new Error("scan --range all \u9700\u8981\u660E\u786E\u65E5\u671F\u8303\u56F4\uFF0C\u8BF7\u6539\u7528 --from YYYY-MM-DD --to YYYY-MM-DD");
|
|
4367
|
+
return dates;
|
|
4368
|
+
}
|
|
4369
|
+
function hasDateSelection(flags) {
|
|
4370
|
+
return typeof flags.date == "string" || flags.today === !0 || typeof flags.from == "string" || typeof flags.start == "string" || typeof flags.to == "string" || typeof flags.end == "string" || typeof flags.range == "string" || typeof flags.lookback == "string";
|
|
4371
|
+
}
|
|
3564
4372
|
function resolveGlobalLang(flags, config) {
|
|
3565
4373
|
let lang = (typeof flags.lang == "string" ? flags.lang : config.lang) || "en";
|
|
3566
4374
|
if (lang !== "en" && lang !== "zh") throw new Error("--lang only supports en or zh");
|