@aiusage/cli 1.5.3 → 1.6.1
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/cli.js +1028 -185
- package/package.json +1 -1
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,886 @@ 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, FAST_SUPPORTED = /* @__PURE__ */ new Set([
|
|
2406
|
+
"claude-opus-4-7",
|
|
2407
|
+
"claude-opus-4-6"
|
|
2408
|
+
]);
|
|
2409
|
+
function resolveModelPricing(catalog2, provider, product, model) {
|
|
2410
|
+
let models = catalog2.providers[provider]?.[product]?.models;
|
|
2411
|
+
if (!models) return null;
|
|
2412
|
+
let aliasResolved = catalog2.aliases[model];
|
|
2413
|
+
if (aliasResolved && models[aliasResolved])
|
|
2414
|
+
return { resolvedModel: aliasResolved, pricing: models[aliasResolved], normalized: !1 };
|
|
2415
|
+
if (models[model])
|
|
2416
|
+
return { resolvedModel: model, pricing: models[model], normalized: !1 };
|
|
2417
|
+
for (let knownModel of Object.keys(models).sort((a, b) => b.length - a.length)) {
|
|
2418
|
+
if (!model.startsWith(`${knownModel}-`)) continue;
|
|
2419
|
+
let suffix = model.slice(knownModel.length + 1);
|
|
2420
|
+
if (!/^\d+(?:[-.]\d+)*(?:-\d{6,8})?$/.test(suffix))
|
|
2421
|
+
return { resolvedModel: knownModel, pricing: models[knownModel], normalized: !0 };
|
|
2422
|
+
}
|
|
2423
|
+
return null;
|
|
2424
|
+
}
|
|
2425
|
+
function selectTier(tiers, totalInputTokens) {
|
|
2426
|
+
for (let i = 0; i < tiers.length; i += 1) {
|
|
2427
|
+
let t2 = tiers[i];
|
|
2428
|
+
if (t2.threshold === void 0 || totalInputTokens <= t2.threshold)
|
|
2429
|
+
return { tier: t2, index: i };
|
|
2430
|
+
}
|
|
2431
|
+
return { tier: tiers[tiers.length - 1], index: tiers.length - 1 };
|
|
2432
|
+
}
|
|
2433
|
+
function toUsd(amount, currency, catalog2) {
|
|
2434
|
+
if (currency === "USD") return amount;
|
|
2435
|
+
let rate = catalog2.fx[currency];
|
|
2436
|
+
return rate ? amount / rate : amount;
|
|
2437
|
+
}
|
|
2438
|
+
function calculateCost(provider, product, model, tokens, options = {}) {
|
|
2439
|
+
let cat = options.catalog ?? catalog;
|
|
2440
|
+
if (tokens.inputTokens + tokens.cachedInputTokens + tokens.cacheWriteTokens + tokens.outputTokens === 0)
|
|
2441
|
+
return { estimatedCostUsd: 0, costStatus: "exact", pricingVersion: cat.version };
|
|
2442
|
+
let isFast = model.endsWith("-fast"), baseModel = isFast ? model.replace(/-fast$/, "") : model, resolved = resolveModelPricing(cat, provider, product, baseModel);
|
|
2443
|
+
if (!resolved)
|
|
2444
|
+
return { estimatedCostUsd: 0, costStatus: "unavailable", pricingVersion: cat.version };
|
|
2445
|
+
let { resolvedModel, pricing, normalized } = resolved, costStatus = normalized ? "estimated" : "exact", unit, matchedTierIndex;
|
|
2446
|
+
if (pricing.tiers && pricing.tiers.length > 0) {
|
|
2447
|
+
let totalIn = tokens.inputTokens + tokens.cachedInputTokens + tokens.cacheWriteTokens, { tier, index } = selectTier(pricing.tiers, totalIn);
|
|
2448
|
+
unit = tier, matchedTierIndex = index;
|
|
2449
|
+
} else
|
|
2450
|
+
unit = {
|
|
2451
|
+
input_per_million: pricing.input_per_million ?? 0,
|
|
2452
|
+
output_per_million: pricing.output_per_million ?? 0,
|
|
2453
|
+
cached_input_per_million: pricing.cached_input_per_million ?? null,
|
|
2454
|
+
cache_write_5m_per_million: pricing.cache_write_5m_per_million ?? 0,
|
|
2455
|
+
cache_write_1h_per_million: pricing.cache_write_1h_per_million ?? 0
|
|
2456
|
+
};
|
|
2457
|
+
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);
|
|
2458
|
+
raw = toUsd(raw, pricing.currency, cat);
|
|
2459
|
+
let finalCost = isFast && FAST_SUPPORTED.has(resolvedModel) ? raw * FAST_MULTIPLIER : raw;
|
|
2460
|
+
return {
|
|
2461
|
+
estimatedCostUsd: Math.round(finalCost * 1e4) / 1e4,
|
|
2462
|
+
costStatus,
|
|
2463
|
+
pricingVersion: cat.version,
|
|
2464
|
+
resolvedModel,
|
|
2465
|
+
matchedTierIndex
|
|
2466
|
+
};
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2469
|
+
// src/report.ts
|
|
1590
2470
|
async function buildLocalReport(range, options = {}) {
|
|
1591
2471
|
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
2472
|
for (let result of results) {
|
|
@@ -1963,82 +2843,6 @@ function createEmptyTotals2() {
|
|
|
1963
2843
|
function mergeTotals(target, source) {
|
|
1964
2844
|
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
2845
|
}
|
|
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
2846
|
function toBreakdownTotals(breakdown, warnings) {
|
|
2043
2847
|
let estimatedCostUsd = calculateBreakdownCost(breakdown, warnings);
|
|
2044
2848
|
return {
|
|
@@ -2055,37 +2859,20 @@ function toBreakdownTotals(breakdown, warnings) {
|
|
|
2055
2859
|
function calculateBreakdownCost(breakdown, warnings) {
|
|
2056
2860
|
if (breakdown.costUSD != null && breakdown.costUSD > 0)
|
|
2057
2861
|
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;
|
|
2862
|
+
let result = calculateCost(
|
|
2863
|
+
breakdown.provider,
|
|
2864
|
+
breakdown.product,
|
|
2865
|
+
breakdown.model,
|
|
2866
|
+
{
|
|
2867
|
+
inputTokens: breakdown.inputTokens,
|
|
2868
|
+
cachedInputTokens: breakdown.cachedInputTokens,
|
|
2869
|
+
cacheWriteTokens: breakdown.cacheWriteTokens,
|
|
2870
|
+
cacheWrite5mTokens: breakdown.cacheWrite5mTokens,
|
|
2871
|
+
cacheWrite1hTokens: breakdown.cacheWrite1hTokens,
|
|
2872
|
+
outputTokens: breakdown.outputTokens
|
|
2873
|
+
}
|
|
2874
|
+
);
|
|
2875
|
+
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
2876
|
}
|
|
2090
2877
|
|
|
2091
2878
|
// src/i18n.ts
|
|
@@ -3100,78 +3887,128 @@ function getClaudeDirs() {
|
|
|
3100
3887
|
];
|
|
3101
3888
|
}
|
|
3102
3889
|
|
|
3890
|
+
// src/privacy.ts
|
|
3891
|
+
import { createHash } from "node:crypto";
|
|
3892
|
+
var DEFAULT_VISIBILITY = "masked";
|
|
3893
|
+
function applyPrivacy(breakdowns, visibility) {
|
|
3894
|
+
let mode = visibility ?? DEFAULT_VISIBILITY;
|
|
3895
|
+
return breakdowns.map((b) => transformOne(b, mode));
|
|
3896
|
+
}
|
|
3897
|
+
function transformOne(b, mode) {
|
|
3898
|
+
let original = b.project ?? "", display = b.projectDisplay ?? deriveBasename(original);
|
|
3899
|
+
if (mode === "hidden")
|
|
3900
|
+
return { ...b, project: "_redacted_", projectDisplay: "_redacted_", projectAlias: void 0 };
|
|
3901
|
+
if (mode === "masked") {
|
|
3902
|
+
let base2 = deriveBasename(original), hash = shortHash(original);
|
|
3903
|
+
return {
|
|
3904
|
+
...b,
|
|
3905
|
+
project: `${base2}-${hash}`,
|
|
3906
|
+
projectDisplay: base2,
|
|
3907
|
+
projectAlias: void 0
|
|
3908
|
+
};
|
|
3909
|
+
}
|
|
3910
|
+
let base = deriveBasename(original);
|
|
3911
|
+
return {
|
|
3912
|
+
...b,
|
|
3913
|
+
project: base,
|
|
3914
|
+
projectDisplay: display,
|
|
3915
|
+
projectAlias: b.projectAlias
|
|
3916
|
+
};
|
|
3917
|
+
}
|
|
3918
|
+
function deriveBasename(p) {
|
|
3919
|
+
if (!p) return "unknown";
|
|
3920
|
+
let parts = p.split(/[\\/]+/).filter(Boolean);
|
|
3921
|
+
return parts[parts.length - 1] || "unknown";
|
|
3922
|
+
}
|
|
3923
|
+
function shortHash(p) {
|
|
3924
|
+
return p ? createHash("sha1").update(p).digest("hex").slice(0, 8) : "00000000";
|
|
3925
|
+
}
|
|
3926
|
+
|
|
3103
3927
|
// src/cli.ts
|
|
3104
3928
|
var argv = process.argv.slice(2), command = argv[0];
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
await runScan(parsed.flags, parsed.positionals);
|
|
3111
|
-
} else if (command === "report") {
|
|
3112
|
-
let parsed = parseArgs(argv.slice(1));
|
|
3113
|
-
await runReport(parsed.flags, parsed.positionals);
|
|
3114
|
-
} else if (command === "health") {
|
|
3115
|
-
let parsed = parseArgs(argv.slice(1));
|
|
3116
|
-
await runHealth(parsed.flags);
|
|
3117
|
-
} else if (command === "enroll") {
|
|
3118
|
-
let parsed = parseArgs(argv.slice(1));
|
|
3119
|
-
await runEnroll(parsed.flags);
|
|
3120
|
-
} else if (command === "sync") {
|
|
3121
|
-
let parsed = parseArgs(argv.slice(1));
|
|
3122
|
-
await runSync(parsed.flags, parsed.positionals);
|
|
3123
|
-
} else if (command === "init") {
|
|
3124
|
-
let parsed = parseArgs(argv.slice(1));
|
|
3125
|
-
await runInit(parsed.flags);
|
|
3126
|
-
} else if (command === "schedule") {
|
|
3127
|
-
let sub = argv[1];
|
|
3128
|
-
if (sub === "off")
|
|
3129
|
-
await runSchedule("off", {});
|
|
3130
|
-
else if (sub === "status")
|
|
3131
|
-
await runSchedule("status", {});
|
|
3132
|
-
else if (sub === "on") {
|
|
3133
|
-
let parsed = parseArgs(argv.slice(2));
|
|
3134
|
-
await runSchedule("on", parsed.flags);
|
|
3135
|
-
} else {
|
|
3929
|
+
await (async () => {
|
|
3930
|
+
try {
|
|
3931
|
+
if (command === "--version" || command === "-v")
|
|
3932
|
+
console.log(getVersion());
|
|
3933
|
+
else if (command === "scan") {
|
|
3136
3934
|
let parsed = parseArgs(argv.slice(1));
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
await
|
|
3151
|
-
else if (
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3935
|
+
if (parsed.flags.help) return helpForSubcommand("scan");
|
|
3936
|
+
await runScan(parsed.flags, parsed.positionals);
|
|
3937
|
+
} else if (command === "report") {
|
|
3938
|
+
let parsed = parseArgs(argv.slice(1));
|
|
3939
|
+
if (parsed.flags.help) return helpForSubcommand("report");
|
|
3940
|
+
await runReport(parsed.flags, parsed.positionals);
|
|
3941
|
+
} else if (command === "health") {
|
|
3942
|
+
let parsed = parseArgs(argv.slice(1));
|
|
3943
|
+
if (parsed.flags.help) return helpForSubcommand("health");
|
|
3944
|
+
await runHealth(parsed.flags);
|
|
3945
|
+
} else if (command === "enroll") {
|
|
3946
|
+
let parsed = parseArgs(argv.slice(1));
|
|
3947
|
+
if (parsed.flags.help) return helpForSubcommand("enroll");
|
|
3948
|
+
await runEnroll(parsed.flags);
|
|
3949
|
+
} else if (command === "sync") {
|
|
3950
|
+
let parsed = parseArgs(argv.slice(1));
|
|
3951
|
+
if (parsed.flags.help) return helpForSubcommand("sync");
|
|
3952
|
+
await runSync(parsed.flags, parsed.positionals);
|
|
3953
|
+
} else if (command === "init") {
|
|
3954
|
+
let parsed = parseArgs(argv.slice(1));
|
|
3955
|
+
if (parsed.flags.help) return helpForSubcommand("init");
|
|
3956
|
+
await runInit(parsed.flags);
|
|
3957
|
+
} else if (command === "schedule") {
|
|
3958
|
+
let sub = argv[1];
|
|
3959
|
+
if (sub === "--help" || sub === "-h") return helpForSubcommand("schedule");
|
|
3960
|
+
if (sub === "off")
|
|
3961
|
+
await runSchedule("off", {});
|
|
3962
|
+
else if (sub === "status")
|
|
3963
|
+
await runSchedule("status", {});
|
|
3964
|
+
else if (sub === "on") {
|
|
3965
|
+
let parsed = parseArgs(argv.slice(2));
|
|
3966
|
+
if (parsed.flags.help) return helpForSubcommand("schedule");
|
|
3967
|
+
await runSchedule("on", parsed.flags);
|
|
3968
|
+
} else {
|
|
3969
|
+
let parsed = parseArgs(argv.slice(1));
|
|
3970
|
+
if (parsed.flags.help) return helpForSubcommand("schedule");
|
|
3971
|
+
await runSchedule("on", parsed.flags);
|
|
3972
|
+
}
|
|
3973
|
+
} else if (command === "doctor") {
|
|
3974
|
+
let parsed = parseArgs(argv.slice(1));
|
|
3975
|
+
if (parsed.flags.help) return helpForSubcommand("doctor");
|
|
3976
|
+
await runDoctorCommand(parsed.flags);
|
|
3977
|
+
} else if (command === "config" && argv[1] === "set")
|
|
3978
|
+
await runConfigSet(argv.slice(2));
|
|
3979
|
+
else if (command === "project") {
|
|
3980
|
+
let sub = argv[1];
|
|
3981
|
+
if (sub === "list") {
|
|
3982
|
+
let parsed = parseArgs(argv.slice(2));
|
|
3983
|
+
await runProjectList(parsed.flags);
|
|
3984
|
+
} else if (sub === void 0)
|
|
3985
|
+
await runProjectList();
|
|
3986
|
+
else if (sub === "alias")
|
|
3987
|
+
await runProjectAlias(argv.slice(2));
|
|
3988
|
+
else {
|
|
3989
|
+
let zh2 = (await readConfig()).lang === "zh";
|
|
3990
|
+
console.error(`${zh2 ? "\u672A\u77E5\u5B50\u547D\u4EE4" : "Unknown subcommand"}: project ${sub}`), console.log(zh2 ? "\u53EF\u7528: aiusage project list, aiusage project alias <\u9879\u76EE\u540D> <\u522B\u540D>" : "Available: aiusage project list, aiusage project alias <name> <alias>"), process.exitCode = 1;
|
|
3991
|
+
}
|
|
3992
|
+
} else if (command === "import") {
|
|
3993
|
+
let parsed = parseArgs(argv.slice(1));
|
|
3994
|
+
if (parsed.flags.help) return helpForSubcommand("import");
|
|
3995
|
+
await runImport(parsed.flags, parsed.positionals);
|
|
3996
|
+
} else if (command === "setup")
|
|
3997
|
+
console.log(`To deploy the server, clone the repo and run the setup wizard:
|
|
3162
3998
|
`), console.log(" git clone https://github.com/ennann/aiusage.git"), console.log(" cd aiusage && pnpm install"), console.log(` pnpm setup
|
|
3163
3999
|
`), console.log("See: https://github.com/ennann/aiusage#deploy-your-own-server");
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
4000
|
+
else if (command === "--help" || command === "-h" || command === "help") {
|
|
4001
|
+
let zh2 = (await readConfig()).lang === "zh";
|
|
4002
|
+
printHelp(zh2);
|
|
4003
|
+
} else {
|
|
4004
|
+
let zh2 = ((await readConfig()).lang || "en") === "zh";
|
|
4005
|
+
command && console.error(`${zh2 ? "\u672A\u77E5\u547D\u4EE4" : "Unknown command"}: "${command}"
|
|
3170
4006
|
`), printUsageHint(zh2);
|
|
4007
|
+
}
|
|
4008
|
+
} catch (error) {
|
|
4009
|
+
console.error(error instanceof Error ? error.message : String(error)), process.exitCode = 1;
|
|
3171
4010
|
}
|
|
3172
|
-
}
|
|
3173
|
-
console.error(error instanceof Error ? error.message : String(error)), process.exitCode = 1;
|
|
3174
|
-
}
|
|
4011
|
+
})();
|
|
3175
4012
|
async function runScan(flags, positionals = []) {
|
|
3176
4013
|
let config = await readConfig(), zh2 = config.lang === "zh";
|
|
3177
4014
|
assertNoPositionals("scan", positionals, zh2);
|
|
@@ -3277,7 +4114,7 @@ async function runSync(flags, positionals = []) {
|
|
|
3277
4114
|
if (!targetDates)
|
|
3278
4115
|
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");
|
|
3279
4116
|
console.log(`\u626B\u63CF ${targetDates.length} \u5929 (${targetDates[0]} ~ ${targetDates[targetDates.length - 1]}) ...`);
|
|
3280
|
-
let
|
|
4117
|
+
let results = await scanDates(targetDates, { projectAliases: config.projectAliases }), visibility = config.privacy?.projectVisibility, allDays = results.filter((r) => r.breakdowns.length > 0).map((r) => ({ usageDate: r.usageDate, breakdowns: applyPrivacy(r.breakdowns, visibility) }));
|
|
3281
4118
|
if (allDays.length === 0) {
|
|
3282
4119
|
console.log("\u6CA1\u6709\u53EF\u4E0A\u4F20\u7684\u6570\u636E\u3002");
|
|
3283
4120
|
return;
|
|
@@ -3357,6 +4194,8 @@ async function runImport(flags, positionals = []) {
|
|
|
3357
4194
|
}
|
|
3358
4195
|
console.log(`Found data for ${allDays.length} days. Uploading...`);
|
|
3359
4196
|
}
|
|
4197
|
+
let visibility = config.privacy?.projectVisibility;
|
|
4198
|
+
allDays = allDays.map((d) => ({ usageDate: d.usageDate, breakdowns: applyPrivacy(d.breakdowns, visibility) }));
|
|
3360
4199
|
for (let target of targets) {
|
|
3361
4200
|
if (!target.deviceToken) {
|
|
3362
4201
|
console.log(`Skipping "${target.name}": not enrolled (missing deviceToken)`);
|
|
@@ -3438,7 +4277,7 @@ ${zh2 ? "\u5171" : "Total:"} ${projects.length} ${zh2 ? "\u4E2A\u9879\u76EE" : "
|
|
|
3438
4277
|
async function runProjectAlias(args) {
|
|
3439
4278
|
let config = await readConfig(), zh2 = config.lang === "zh";
|
|
3440
4279
|
if (args.length === 0) {
|
|
3441
|
-
let
|
|
4280
|
+
let aliases2 = config.projectAliases ?? {}, entries = Object.entries(aliases2);
|
|
3442
4281
|
if (entries.length === 0) {
|
|
3443
4282
|
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>");
|
|
3444
4283
|
return;
|
|
@@ -3450,10 +4289,10 @@ async function runProjectAlias(args) {
|
|
|
3450
4289
|
if (args[0] === "--remove") {
|
|
3451
4290
|
let name2 = args.slice(1).join(" ").trim();
|
|
3452
4291
|
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");
|
|
3453
|
-
let
|
|
3454
|
-
if (!(name2 in
|
|
4292
|
+
let aliases2 = { ...config.projectAliases ?? {} };
|
|
4293
|
+
if (!(name2 in aliases2))
|
|
3455
4294
|
throw new Error(zh2 ? `\u9879\u76EE "${name2}" \u672A\u8BBE\u7F6E\u522B\u540D` : `No alias set for "${name2}"`);
|
|
3456
|
-
delete
|
|
4295
|
+
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}".`);
|
|
3457
4296
|
return;
|
|
3458
4297
|
}
|
|
3459
4298
|
if (args.length < 2)
|
|
@@ -3462,6 +4301,10 @@ async function runProjectAlias(args) {
|
|
|
3462
4301
|
if (!alias) throw new Error(zh2 ? "\u522B\u540D\u4E0D\u80FD\u4E3A\u7A7A" : "Alias cannot be empty");
|
|
3463
4302
|
config.projectAliases = { ...config.projectAliases ?? {}, [name]: alias }, await writeConfig(config), console.log(zh2 ? `\u5DF2\u8BBE\u7F6E: ${name} \u2192 ${alias}` : `Set: ${name} \u2192 ${alias}`);
|
|
3464
4303
|
}
|
|
4304
|
+
async function helpForSubcommand(_command) {
|
|
4305
|
+
let zh2 = (await readConfig().catch(() => ({ lang: "en" }))).lang === "zh";
|
|
4306
|
+
printHelp(zh2);
|
|
4307
|
+
}
|
|
3465
4308
|
function printHelp(zh2 = !1) {
|
|
3466
4309
|
console.log(`aiusage v${getVersion()}
|
|
3467
4310
|
`);
|