@kapishdima/ai-ledger 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 AI Ledger Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,137 @@
1
+ # ai-ledger
2
+
3
+ AI provider balance and spending tracker for OpenCode
4
+
5
+ Track your AI API usage across multiple providers (OpenAI, Anthropic, Kimi, MiniMax) directly in OpenCode with automatic cost deduction and beautiful balance visualization.
6
+
7
+ ## Features
8
+
9
+ - 🔍 **Automatic Provider Detection** - Detects configured AI providers from environment variables
10
+ - 💰 **Balance Tracking** - Track spending and remaining balances in real-time
11
+ - 📊 **Visual Progress Bars** - Unicode-based progress bars show usage at a glance
12
+ - 💾 **Local SQLite Storage** - All data stored locally in `~/.config/opencode/ai-ledger/wallet.db`
13
+ - 🎯 **Automatic Cost Deduction** - Automatically deducts costs from AI requests
14
+ - 🏦 **Easy Top-ups** - Simple commands to add funds to any provider
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install ai-ledger
20
+ # or
21
+ bun add ai-ledger
22
+ ```
23
+
24
+ Then add to your OpenCode configuration:
25
+
26
+ ```json
27
+ {
28
+ "plugins": ["ai-ledger"]
29
+ }
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ### Initialize
35
+
36
+ Detects configured AI providers and shows setup instructions:
37
+
38
+ ```bash
39
+ /ledger_init
40
+ ```
41
+
42
+ **Example output:**
43
+ ```
44
+ Found 2 AI provider(s):
45
+
46
+ /ledger_set openai <amount> - Set OpenAI balance
47
+ /ledger_set anthropic <amount> - Set Anthropic balance
48
+
49
+ Example: /ledger_set openai 50.00
50
+ ```
51
+
52
+ ### Set Initial Balance
53
+
54
+ Set the initial balance for a provider:
55
+
56
+ ```bash
57
+ /ledger_set openai 50.00
58
+ /ledger_set anthropic 25.00
59
+ /ledger_set kimi 100.00
60
+ ```
61
+
62
+ ### Add Funds
63
+
64
+ Add money to an existing provider balance:
65
+
66
+ ```bash
67
+ /ledger_add openai 20.00
68
+ ```
69
+
70
+ ### Check Balances
71
+
72
+ View all provider balances with visual progress bars:
73
+
74
+ ```bash
75
+ /ledger_balance
76
+ ```
77
+
78
+ **Example output:**
79
+ ```
80
+ ┌──────────────┬──────────────┬──────────┬────────────────────┐
81
+ │ Provider │ Balance │ Spent │ Progress │
82
+ ├──────────────┼──────────────┼──────────┼────────────────────┤
83
+ │ OpenAI │ $42.86 │ $7.14 │ ████░░░░░░░░░░░░░░ │
84
+ │ Anthropic │ $25.00 │ $0.00 │ ░░░░░░░░░░░░░░░░░░░░ │
85
+ └──────────────┴──────────────┴──────────┴────────────────────┘
86
+ ```
87
+
88
+ ### Automatic Tracking
89
+
90
+ Once configured, the plugin automatically tracks all AI requests and deducts costs from your balances. You'll see log messages like:
91
+
92
+ ```
93
+ ai-ledger: openai (gpt-4): -$0.0023 | balance: $42.86
94
+ ```
95
+
96
+ ## Supported Providers
97
+
98
+ The plugin automatically detects and supports:
99
+
100
+ - **OpenAI** - Requires `OPENAI_API_KEY`
101
+ - **Anthropic** - Requires `ANTHROPIC_API_KEY`
102
+ - **Kimi (Moonshot)** - Requires `MOONSHOT_API_KEY`
103
+ - **MiniMax** - Requires `MINIMAX_API_KEY`
104
+
105
+ ## Database
106
+
107
+ Data is stored locally in SQLite at:
108
+ ```
109
+ ~/.config/opencode/ai-ledger/wallet.db
110
+ ```
111
+
112
+ The database contains two tables:
113
+ - `wallets` - Stores provider balances and metadata
114
+ - `transactions` - Stores every AI request with cost details
115
+
116
+ ## Requirements
117
+
118
+ - OpenCode
119
+ - Bun runtime (>= 1.0.0)
120
+ - Node.js (>= 18.0.0)
121
+ - TypeScript (>= 5.0.0)
122
+
123
+ ## Configuration
124
+
125
+ No additional configuration required! The plugin automatically detects your API keys from environment variables.
126
+
127
+ ## License
128
+
129
+ MIT
130
+
131
+ ## Contributing
132
+
133
+ Contributions are welcome! Please feel free to submit a Pull Request.
134
+
135
+ ## Support
136
+
137
+ For issues and feature requests, please use the [GitHub issue tracker](https://github.com/yourusername/ai-ledger/issues).