opencode-puter-auth 1.0.0-beta.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mihai Alexandru Chindris
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,253 @@
1
+ # opencode-puter-auth
2
+
3
+ [![npm version](https://img.shields.io/npm/v/opencode-puter-auth.svg)](https://www.npmjs.com/package/opencode-puter-auth)
4
+ [![npm beta](https://img.shields.io/npm/v/opencode-puter-auth/beta.svg)](https://www.npmjs.com/package/opencode-puter-auth)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/chindrismihai)
7
+
8
+ > **FREE, UNLIMITED access to Claude Opus 4.5, Sonnet 4.5, GPT-5, Gemini, and 500+ AI models** through Puter.com's revolutionary "User-Pays" model.
9
+
10
+ Enable OpenCode to authenticate with [Puter.com](https://puter.com) via OAuth, giving you unlimited access to the world's best AI coding models - **completely free**.
11
+
12
+ ## What You Get
13
+
14
+ - **FREE, UNLIMITED Claude Opus 4.5** - The best coding AI model available
15
+ - **FREE, UNLIMITED Claude Sonnet 4.5** - Fast, powerful reasoning
16
+ - **FREE, UNLIMITED GPT-5.2, o3-mini** - OpenAI's latest models
17
+ - **FREE, UNLIMITED Gemini 2.5 Pro** - 1M context window
18
+ - **500+ More Models** - DeepSeek, Mistral, Llama, and more
19
+ - **No Rate Limits** - Puter's "User-Pays" model means truly unlimited usage
20
+ - **Real-time SSE Streaming** - Full streaming support
21
+ - **Tool Calling** - Native function calling support
22
+ - **Vision Support** - Image analysis capabilities
23
+
24
+ ## How It Works
25
+
26
+ Puter.com uses the innovative **"User-Pays" model**:
27
+
28
+ 1. **You (the developer)** pay nothing for infrastructure
29
+ 2. **Users** cover their own AI usage costs through their Puter account
30
+ 3. **For personal use**, you ARE the user - so it's FREE for you!
31
+
32
+ This means whether you have 1 or 1 million users, you pay $0 for AI infrastructure.
33
+
34
+ ## Installation
35
+
36
+ ### Option A: Let an LLM do it (Easiest)
37
+
38
+ Paste this into any LLM agent (Claude Code, OpenCode, Cursor, etc.):
39
+
40
+ ```
41
+ Install the opencode-puter-auth plugin and configure Puter.com models
42
+ in ~/.config/opencode/opencode.json by following:
43
+ https://raw.githubusercontent.com/chindris-mihai-alexandru/opencode-puter-auth/main/README.md
44
+ ```
45
+
46
+ ### Option B: Manual Setup
47
+
48
+ 1. **Add the plugin to your config** (`~/.config/opencode/opencode.json`):
49
+
50
+ ```json
51
+ {
52
+ "plugin": ["opencode-puter-auth@beta"]
53
+ }
54
+ ```
55
+
56
+ 2. **Authenticate with Puter:**
57
+
58
+ ```bash
59
+ opencode auth login
60
+ # Select "Puter.com (FREE Unlimited)"
61
+ ```
62
+
63
+ 3. **Add model definitions:**
64
+
65
+ ```json
66
+ {
67
+ "$schema": "https://opencode.ai/config.json",
68
+ "plugin": ["opencode-puter-auth@beta"],
69
+ "provider": {
70
+ "puter": {
71
+ "models": {
72
+ "claude-opus-4-5": {
73
+ "name": "Claude Opus 4.5 (FREE via Puter)",
74
+ "limit": { "context": 200000, "output": 64000 },
75
+ "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] }
76
+ },
77
+ "claude-sonnet-4-5": {
78
+ "name": "Claude Sonnet 4.5 (FREE via Puter)",
79
+ "limit": { "context": 200000, "output": 64000 },
80
+ "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] }
81
+ },
82
+ "claude-sonnet-4": {
83
+ "name": "Claude Sonnet 4 (FREE via Puter)",
84
+ "limit": { "context": 200000, "output": 64000 },
85
+ "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] }
86
+ },
87
+ "claude-haiku-4-5": {
88
+ "name": "Claude Haiku 4.5 (FREE via Puter - Fast)",
89
+ "limit": { "context": 200000, "output": 64000 },
90
+ "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] }
91
+ },
92
+ "gpt-5.2": {
93
+ "name": "GPT-5.2 (FREE via Puter)",
94
+ "limit": { "context": 128000, "output": 32768 },
95
+ "modalities": { "input": ["text", "image"], "output": ["text"] }
96
+ },
97
+ "gpt-5-nano": {
98
+ "name": "GPT-5 Nano (FREE via Puter - Fast)",
99
+ "limit": { "context": 128000, "output": 16384 },
100
+ "modalities": { "input": ["text", "image"], "output": ["text"] }
101
+ },
102
+ "o3-mini": {
103
+ "name": "o3-mini (FREE via Puter)",
104
+ "limit": { "context": 128000, "output": 32768 },
105
+ "modalities": { "input": ["text"], "output": ["text"] }
106
+ },
107
+ "gemini-2.5-pro": {
108
+ "name": "Gemini 2.5 Pro (FREE via Puter - 1M Context)",
109
+ "limit": { "context": 1000000, "output": 65536 },
110
+ "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] }
111
+ },
112
+ "gemini-2.5-flash": {
113
+ "name": "Gemini 2.5 Flash (FREE via Puter)",
114
+ "limit": { "context": 1000000, "output": 65536 },
115
+ "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] }
116
+ }
117
+ }
118
+ }
119
+ }
120
+ }
121
+ ```
122
+
123
+ 4. **Use it:**
124
+
125
+ ```bash
126
+ opencode run "Hello" --model=puter/claude-opus-4-5
127
+ ```
128
+
129
+ ## Available Models
130
+
131
+ ### Anthropic (Claude)
132
+
133
+ | Model | Description | Context | Best For |
134
+ |-------|-------------|---------|----------|
135
+ | `puter/claude-opus-4-5` | Most capable Claude model | 200K | Complex reasoning, coding |
136
+ | `puter/claude-sonnet-4-5` | Balanced performance | 200K | General coding tasks |
137
+ | `puter/claude-sonnet-4` | Previous gen Sonnet | 200K | Fast coding |
138
+ | `puter/claude-haiku-4-5` | Fastest Claude | 200K | Simple tasks |
139
+
140
+ ### OpenAI (GPT)
141
+
142
+ | Model | Description | Context | Best For |
143
+ |-------|-------------|---------|----------|
144
+ | `puter/gpt-5.2` | Latest GPT model | 128K | Advanced tasks |
145
+ | `puter/gpt-5-nano` | Ultra-fast GPT | 128K | Quick responses |
146
+ | `puter/o3-mini` | Reasoning model | 128K | Complex logic |
147
+ | `puter/gpt-4o` | Multimodal GPT | 128K | Vision tasks |
148
+
149
+ ### Google (Gemini)
150
+
151
+ | Model | Description | Context | Best For |
152
+ |-------|-------------|---------|----------|
153
+ | `puter/gemini-2.5-pro` | Best Gemini | 1M | Huge context |
154
+ | `puter/gemini-2.5-flash` | Fast Gemini | 1M | Quick analysis |
155
+
156
+ ## Configuration
157
+
158
+ Create `~/.config/opencode/puter.json` for advanced settings:
159
+
160
+ ```json
161
+ {
162
+ "quiet_mode": false,
163
+ "debug": false,
164
+ "api_timeout_ms": 120000,
165
+ "auto_create_temp_user": true,
166
+ "max_retries": 3
167
+ }
168
+ ```
169
+
170
+ | Option | Default | Description |
171
+ |--------|---------|-------------|
172
+ | `quiet_mode` | `false` | Suppress status messages |
173
+ | `debug` | `false` | Enable debug logging |
174
+ | `api_timeout_ms` | `120000` | Request timeout (2 min) |
175
+ | `auto_create_temp_user` | `true` | Auto-create temp account |
176
+ | `max_retries` | `3` | Retry failed requests |
177
+
178
+ ## Custom Tools
179
+
180
+ The plugin adds these tools to OpenCode:
181
+
182
+ - **`puter-models`** - List all available Puter models
183
+ - **`puter-account`** - Show current account info
184
+
185
+ ## Comparison: Puter vs Antigravity
186
+
187
+ | Feature | Puter | Antigravity |
188
+ |---------|-------|-------------|
189
+ | **Cost** | FREE | FREE |
190
+ | **Rate Limits** | **NONE** | Weekly quotas |
191
+ | **Claude Opus 4.5** | ✅ Unlimited | ✅ Limited |
192
+ | **Claude Sonnet 4.5** | ✅ Unlimited | ✅ Limited |
193
+ | **GPT-5** | ✅ Unlimited | ❌ No |
194
+ | **Gemini 3** | ❌ No | ✅ Limited |
195
+ | **Multi-Account** | N/A (unlimited) | Required for quota |
196
+ | **Auth Method** | Puter OAuth | Google OAuth |
197
+
198
+ **Bottom line**: Use Puter for unlimited Claude/GPT access, Antigravity for Gemini 3.
199
+
200
+ ## Troubleshooting
201
+
202
+ ### Browser doesn't open for auth
203
+
204
+ ```bash
205
+ # Manually visit:
206
+ http://localhost:19847
207
+ ```
208
+
209
+ ### "Not authenticated" error
210
+
211
+ ```bash
212
+ opencode auth login
213
+ # Select "Puter.com (FREE Unlimited)"
214
+ ```
215
+
216
+ ### API timeout errors
217
+
218
+ Increase timeout in `puter.json`:
219
+
220
+ ```json
221
+ {
222
+ "api_timeout_ms": 300000
223
+ }
224
+ ```
225
+
226
+ ## Support the Project
227
+
228
+ If this plugin helps you, consider supporting its development:
229
+
230
+ [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/chindrismihai)
231
+
232
+ ## Publishing to npm
233
+
234
+ To publish this package, you'll need an npm account:
235
+
236
+ 1. Create an account at [npmjs.com](https://www.npmjs.com/signup)
237
+ 2. Login via CLI: `npm login`
238
+ 3. Create a token at npmjs.com → Access Tokens → Generate New Token (Automation)
239
+ 4. Add the token to GitHub Secrets as `NPM_TOKEN` for CI/CD
240
+
241
+ ## Credits
242
+
243
+ - [Puter.com](https://puter.com) - The amazing "Internet Computer" platform
244
+ - [OpenCode](https://opencode.ai) - The best AI coding agent
245
+ - [opencode-antigravity-auth](https://github.com/NoeFabris/opencode-antigravity-auth) - Inspiration for plugin architecture
246
+
247
+ ## License
248
+
249
+ MIT - See [LICENSE](LICENSE)
250
+
251
+ ---
252
+
253
+ **Made with ❤️ by [@chindris-mihai-alexandru](https://github.com/chindris-mihai-alexandru)**
package/dist/auth.d.ts ADDED
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Puter Authentication Manager
3
+ *
4
+ * Handles OAuth authentication with Puter.com via browser popup
5
+ *
6
+ * IMPORTANT: Puter uses popup-based auth (puter.auth.signIn()) which returns a token.
7
+ * For CLI tools, we serve an HTML page that handles the popup auth flow,
8
+ * then redirects to our local callback with the token.
9
+ */
10
+ import type { PuterAccount, PuterAuthResult, PuterConfig } from './types.js';
11
+ export declare class PuterAuthManager {
12
+ private configDir;
13
+ private accountsFile;
14
+ private storage;
15
+ constructor(configDir: string, _config?: Partial<PuterConfig>);
16
+ /**
17
+ * Initialize the auth manager and load existing accounts
18
+ */
19
+ init(): Promise<void>;
20
+ /**
21
+ * Ensure the config directory exists
22
+ */
23
+ private ensureConfigDir;
24
+ /**
25
+ * Load accounts from disk
26
+ */
27
+ private loadAccounts;
28
+ /**
29
+ * Save accounts to disk
30
+ */
31
+ private saveAccounts;
32
+ /**
33
+ * Get the active account
34
+ */
35
+ getActiveAccount(): PuterAccount | null;
36
+ /**
37
+ * Get all accounts
38
+ */
39
+ getAllAccounts(): PuterAccount[];
40
+ /**
41
+ * Check if we have any authenticated accounts
42
+ */
43
+ isAuthenticated(): boolean;
44
+ /**
45
+ * Start the OAuth flow in browser
46
+ *
47
+ * This serves an HTML page that handles the Puter popup auth flow,
48
+ * then redirects to our local callback with the token.
49
+ */
50
+ login(): Promise<PuterAuthResult>;
51
+ /**
52
+ * Add a new account (or update existing)
53
+ */
54
+ addAccount(account: PuterAccount): Promise<void>;
55
+ /**
56
+ * Switch to a different account
57
+ */
58
+ switchAccount(index: number): Promise<boolean>;
59
+ /**
60
+ * Remove an account
61
+ */
62
+ removeAccount(index: number): Promise<boolean>;
63
+ /**
64
+ * Update the last used timestamp for the active account
65
+ */
66
+ touchActiveAccount(): Promise<void>;
67
+ /**
68
+ * Logout - remove all accounts
69
+ */
70
+ logout(): Promise<void>;
71
+ }
72
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,KAAK,EACV,YAAY,EAEZ,eAAe,EACf,WAAW,EACZ,MAAM,YAAY,CAAC;AAgLpB,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,OAAO,CAAqC;gBAExC,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,OAAO,CAAC,WAAW,CAAM;IAKjE;;OAEG;IACU,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAKlC;;OAEG;YACW,eAAe;IAQ7B;;OAEG;YACW,YAAY;IAe1B;;OAEG;YACW,YAAY;IAO1B;;OAEG;IACI,gBAAgB,IAAI,YAAY,GAAG,IAAI;IAO9C;;OAEG;IACI,cAAc,IAAI,YAAY,EAAE;IAIvC;;OAEG;IACI,eAAe,IAAI,OAAO;IAIjC;;;;;OAKG;IACU,KAAK,IAAI,OAAO,CAAC,eAAe,CAAC;IA+G9C;;OAEG;IACU,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAuB7D;;OAEG;IACU,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAU3D;;OAEG;IACU,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAe3D;;OAEG;IACU,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAQhD;;OAEG;IACU,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAQrC"}