opencode-puter-auth 1.0.39 → 1.0.41
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 +114 -0
- package/dist/account-rotation.d.ts +243 -0
- package/dist/account-rotation.d.ts.map +1 -0
- package/dist/account-rotation.js +431 -0
- package/dist/account-rotation.js.map +1 -0
- package/dist/auth.d.ts +166 -18
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +167 -20
- package/dist/auth.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/dist/auth.d.ts
CHANGED
|
@@ -1,21 +1,73 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Puter Authentication Manager
|
|
3
3
|
*
|
|
4
|
-
* Handles OAuth authentication with Puter.com via browser popup
|
|
4
|
+
* Handles OAuth authentication with Puter.com via browser popup.
|
|
5
|
+
* Supports multiple accounts with automatic persistence and seamless switching.
|
|
6
|
+
*
|
|
7
|
+
* Authentication Flow:
|
|
8
|
+
* 1. Start local HTTP server to serve auth HTML and receive callback
|
|
9
|
+
* 2. Open browser to the local server serving Puter SDK auth page
|
|
10
|
+
* 3. User signs in via Puter popup (puter.auth.signIn())
|
|
11
|
+
* 4. Page redirects to /callback with token and username
|
|
12
|
+
* 5. Token is stored locally and server shuts down
|
|
5
13
|
*
|
|
6
14
|
* IMPORTANT: Puter uses popup-based auth (puter.auth.signIn()) which returns a token.
|
|
7
15
|
* For CLI tools, we serve an HTML page that handles the popup auth flow,
|
|
8
16
|
* then redirects to our local callback with the token.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { createPuterAuthManager } from 'opencode-puter-auth';
|
|
21
|
+
*
|
|
22
|
+
* const authManager = createPuterAuthManager('~/.config/opencode');
|
|
23
|
+
* await authManager.init();
|
|
24
|
+
*
|
|
25
|
+
* if (!authManager.isAuthenticated()) {
|
|
26
|
+
* const result = await authManager.login();
|
|
27
|
+
* if (result.success) {
|
|
28
|
+
* console.log('Logged in as:', result.account?.username);
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* const account = authManager.getActiveAccount();
|
|
33
|
+
* console.log('Token:', account?.authToken);
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @module auth
|
|
9
37
|
*/
|
|
10
38
|
import type { PuterAccount, PuterAuthResult, PuterConfig } from './types.js';
|
|
39
|
+
/**
|
|
40
|
+
* Internal implementation of PuterAuthManager.
|
|
41
|
+
*
|
|
42
|
+
* Not exported directly to avoid OpenCode plugin loader issues.
|
|
43
|
+
* OpenCode iterates through all exports and calls them as functions,
|
|
44
|
+
* which causes "cannot call class without new" errors.
|
|
45
|
+
*
|
|
46
|
+
* Use {@link createPuterAuthManager} factory function instead.
|
|
47
|
+
*/
|
|
11
48
|
declare class PuterAuthManagerInternal {
|
|
49
|
+
/** Directory where config files are stored */
|
|
12
50
|
private configDir;
|
|
51
|
+
/** Path to the accounts JSON file */
|
|
13
52
|
private accountsFile;
|
|
53
|
+
/** In-memory account storage (synced with disk) */
|
|
14
54
|
private storage;
|
|
55
|
+
/** Logger instance for debugging */
|
|
15
56
|
private logger;
|
|
57
|
+
/**
|
|
58
|
+
* Create a new PuterAuthManager instance.
|
|
59
|
+
*
|
|
60
|
+
* @param configDir - Directory to store account data (e.g., ~/.config/opencode)
|
|
61
|
+
* @param config - Optional configuration overrides
|
|
62
|
+
*/
|
|
16
63
|
constructor(configDir: string, config?: Partial<PuterConfig>);
|
|
17
64
|
/**
|
|
18
|
-
* Initialize the auth manager and load existing accounts
|
|
65
|
+
* Initialize the auth manager and load existing accounts from disk.
|
|
66
|
+
*
|
|
67
|
+
* Must be called before using other methods. Creates the config
|
|
68
|
+
* directory if it doesn't exist and loads any saved accounts.
|
|
69
|
+
*
|
|
70
|
+
* @throws Error if unable to create config directory
|
|
19
71
|
*/
|
|
20
72
|
init(): Promise<void>;
|
|
21
73
|
/**
|
|
@@ -23,60 +75,156 @@ declare class PuterAuthManagerInternal {
|
|
|
23
75
|
*/
|
|
24
76
|
private ensureConfigDir;
|
|
25
77
|
/**
|
|
26
|
-
* Load accounts from
|
|
78
|
+
* Load accounts from the persisted JSON file.
|
|
79
|
+
* If file doesn't exist or is invalid, initializes with empty storage.
|
|
27
80
|
*/
|
|
28
81
|
private loadAccounts;
|
|
29
82
|
/**
|
|
30
|
-
*
|
|
83
|
+
* Persist current account storage to disk.
|
|
84
|
+
* Called automatically after any account modification.
|
|
31
85
|
*/
|
|
32
86
|
private saveAccounts;
|
|
33
87
|
/**
|
|
34
|
-
* Get the active account
|
|
88
|
+
* Get the currently active Puter account.
|
|
89
|
+
*
|
|
90
|
+
* The active account is used for all API calls. Use {@link switchAccount}
|
|
91
|
+
* to change which account is active.
|
|
92
|
+
*
|
|
93
|
+
* @returns The active account, or null if not authenticated
|
|
35
94
|
*/
|
|
36
95
|
getActiveAccount(): PuterAccount | null;
|
|
37
96
|
/**
|
|
38
|
-
* Get all accounts
|
|
97
|
+
* Get all stored Puter accounts.
|
|
98
|
+
*
|
|
99
|
+
* Useful for displaying account selection UI or implementing
|
|
100
|
+
* account rotation when rate limits are hit.
|
|
101
|
+
*
|
|
102
|
+
* @returns Array of all accounts (may be empty)
|
|
39
103
|
*/
|
|
40
104
|
getAllAccounts(): PuterAccount[];
|
|
41
105
|
/**
|
|
42
|
-
* Check if
|
|
106
|
+
* Check if there is at least one authenticated account.
|
|
107
|
+
*
|
|
108
|
+
* @returns true if at least one account is available
|
|
43
109
|
*/
|
|
44
110
|
isAuthenticated(): boolean;
|
|
45
111
|
/**
|
|
46
|
-
* Start the OAuth flow
|
|
112
|
+
* Start the OAuth flow by opening a browser for Puter authentication.
|
|
47
113
|
*
|
|
48
|
-
* This
|
|
49
|
-
*
|
|
114
|
+
* This method:
|
|
115
|
+
* 1. Starts a local HTTP server on port 19847
|
|
116
|
+
* 2. Opens the browser to serve the Puter SDK auth page
|
|
117
|
+
* 3. Waits for the user to complete sign-in via Puter popup
|
|
118
|
+
* 4. Receives the token via redirect to /callback
|
|
119
|
+
* 5. Stores the account and shuts down the server
|
|
120
|
+
*
|
|
121
|
+
* The browser window can be closed after successful authentication.
|
|
122
|
+
*
|
|
123
|
+
* @returns Authentication result with success status and account details
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* const result = await authManager.login();
|
|
128
|
+
* if (result.success) {
|
|
129
|
+
* console.log('Authenticated as:', result.account?.username);
|
|
130
|
+
* } else {
|
|
131
|
+
* console.error('Auth failed:', result.error);
|
|
132
|
+
* }
|
|
133
|
+
* ```
|
|
50
134
|
*/
|
|
51
135
|
login(): Promise<PuterAuthResult>;
|
|
52
136
|
/**
|
|
53
|
-
* Add a new account
|
|
137
|
+
* Add a new account or update an existing one.
|
|
138
|
+
*
|
|
139
|
+
* If an account with the same username exists, it will be updated
|
|
140
|
+
* with the new token. The added/updated account becomes the active account.
|
|
141
|
+
*
|
|
142
|
+
* @param account - The account to add or update
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* await authManager.addAccount({
|
|
147
|
+
* username: 'john_doe',
|
|
148
|
+
* authToken: 'puter-token-xyz',
|
|
149
|
+
* addedAt: Date.now(),
|
|
150
|
+
* isTemporary: false,
|
|
151
|
+
* });
|
|
152
|
+
* ```
|
|
54
153
|
*/
|
|
55
154
|
addAccount(account: PuterAccount): Promise<void>;
|
|
56
155
|
/**
|
|
57
|
-
* Switch to a different account
|
|
156
|
+
* Switch to a different account by index.
|
|
157
|
+
*
|
|
158
|
+
* The index corresponds to the account's position in {@link getAllAccounts}.
|
|
159
|
+
* The switched account becomes the active account for all API calls.
|
|
160
|
+
*
|
|
161
|
+
* @param index - Zero-based index of the account to switch to
|
|
162
|
+
* @returns true if switch was successful, false if index is invalid
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* const accounts = authManager.getAllAccounts();
|
|
167
|
+
* if (accounts.length > 1) {
|
|
168
|
+
* await authManager.switchAccount(1); // Switch to second account
|
|
169
|
+
* }
|
|
170
|
+
* ```
|
|
58
171
|
*/
|
|
59
172
|
switchAccount(index: number): Promise<boolean>;
|
|
60
173
|
/**
|
|
61
|
-
* Remove an account
|
|
174
|
+
* Remove an account by index.
|
|
175
|
+
*
|
|
176
|
+
* If the removed account was active, the active index is adjusted
|
|
177
|
+
* to point to the previous account (or first if none remain).
|
|
178
|
+
*
|
|
179
|
+
* @param index - Zero-based index of the account to remove
|
|
180
|
+
* @returns true if removal was successful, false if index is invalid
|
|
62
181
|
*/
|
|
63
182
|
removeAccount(index: number): Promise<boolean>;
|
|
64
183
|
/**
|
|
65
|
-
* Update the
|
|
184
|
+
* Update the lastUsed timestamp for the active account.
|
|
185
|
+
*
|
|
186
|
+
* Called automatically by PuterClient after successful API calls.
|
|
187
|
+
* Useful for implementing least-recently-used account rotation.
|
|
66
188
|
*/
|
|
67
189
|
touchActiveAccount(): Promise<void>;
|
|
68
190
|
/**
|
|
69
|
-
* Logout
|
|
191
|
+
* Logout and remove all stored accounts.
|
|
192
|
+
*
|
|
193
|
+
* This clears all account data from memory and disk.
|
|
194
|
+
* A new login will be required to use the plugin.
|
|
70
195
|
*/
|
|
71
196
|
logout(): Promise<void>;
|
|
72
197
|
}
|
|
73
198
|
/**
|
|
74
|
-
* Type alias for the auth manager
|
|
199
|
+
* Type alias for the auth manager.
|
|
200
|
+
*
|
|
201
|
+
* Used for external typing without exposing the internal class.
|
|
202
|
+
* Compatible with the {@link IAuthManager} interface for account rotation.
|
|
75
203
|
*/
|
|
76
204
|
export type PuterAuthManager = PuterAuthManagerInternal;
|
|
77
205
|
/**
|
|
78
|
-
* Factory function to create a PuterAuthManager instance
|
|
79
|
-
*
|
|
206
|
+
* Factory function to create a PuterAuthManager instance.
|
|
207
|
+
*
|
|
208
|
+
* This is the recommended way to create an auth manager.
|
|
209
|
+
* Direct class instantiation is not exposed to avoid plugin loader issues.
|
|
210
|
+
*
|
|
211
|
+
* @param configDir - Directory to store account data (e.g., ~/.config/opencode)
|
|
212
|
+
* @param config - Optional configuration overrides
|
|
213
|
+
* @returns A new PuterAuthManager instance (call .init() before use)
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```ts
|
|
217
|
+
* import { createPuterAuthManager } from 'opencode-puter-auth';
|
|
218
|
+
*
|
|
219
|
+
* const authManager = createPuterAuthManager('~/.config/my-app');
|
|
220
|
+
* await authManager.init();
|
|
221
|
+
*
|
|
222
|
+
* if (!authManager.isAuthenticated()) {
|
|
223
|
+
* await authManager.login();
|
|
224
|
+
* }
|
|
225
|
+
*
|
|
226
|
+
* const token = authManager.getActiveAccount()?.authToken;
|
|
227
|
+
* ```
|
|
80
228
|
*/
|
|
81
229
|
export declare function createPuterAuthManager(configDir: string, config?: Partial<PuterConfig>): PuterAuthManager;
|
|
82
230
|
export {};
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAMH,OAAO,KAAK,EACV,YAAY,EAEZ,eAAe,EACf,WAAW,EACZ,MAAM,YAAY,CAAC;AAoLpB;;;;;;;;GAQG;AAGH,cAAM,wBAAwB;IAC5B,8CAA8C;IAC9C,OAAO,CAAC,SAAS,CAAS;IAE1B,qCAAqC;IACrC,OAAO,CAAC,YAAY,CAAS;IAE7B,mDAAmD;IACnD,OAAO,CAAC,OAAO,C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
|
|
4
|
-
* Handles OAuth authentication with Puter.com via browser popup
|
|
4
|
+
* Handles OAuth authentication with Puter.com via browser popup.
|
|
5
|
+
* Supports multiple accounts with automatic persistence and seamless switching.
|
|
6
|
+
*
|
|
7
|
+
* Authentication Flow:
|
|
8
|
+
* 1. Start local HTTP server to serve auth HTML and receive callback
|
|
9
|
+
* 2. Open browser to the local server serving Puter SDK auth page
|
|
10
|
+
* 3. User signs in via Puter popup (puter.auth.signIn())
|
|
11
|
+
* 4. Page redirects to /callback with token and username
|
|
12
|
+
* 5. Token is stored locally and server shuts down
|
|
5
13
|
*
|
|
6
14
|
* IMPORTANT: Puter uses popup-based auth (puter.auth.signIn()) which returns a token.
|
|
7
15
|
* For CLI tools, we serve an HTML page that handles the popup auth flow,
|
|
8
16
|
* then redirects to our local callback with the token.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { createPuterAuthManager } from 'opencode-puter-auth';
|
|
21
|
+
*
|
|
22
|
+
* const authManager = createPuterAuthManager('~/.config/opencode');
|
|
23
|
+
* await authManager.init();
|
|
24
|
+
*
|
|
25
|
+
* if (!authManager.isAuthenticated()) {
|
|
26
|
+
* const result = await authManager.login();
|
|
27
|
+
* if (result.success) {
|
|
28
|
+
* console.log('Logged in as:', result.account?.username);
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* const account = authManager.getActiveAccount();
|
|
33
|
+
* console.log('Token:', account?.authToken);
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @module auth
|
|
9
37
|
*/
|
|
10
38
|
import { promises as fs } from 'node:fs';
|
|
11
39
|
import path from 'node:path';
|
|
@@ -13,8 +41,10 @@ import http from 'node:http';
|
|
|
13
41
|
import { URL } from 'node:url';
|
|
14
42
|
import { PuterAccountsStorageSchema } from './types.js';
|
|
15
43
|
import { createLoggerFromConfig } from './logger.js';
|
|
44
|
+
/** Default port for the local OAuth callback server */
|
|
16
45
|
const DEFAULT_CALLBACK_PORT = 19847;
|
|
17
|
-
|
|
46
|
+
/** Authentication timeout duration (5 minutes) */
|
|
47
|
+
const AUTH_TIMEOUT_MS = 300000;
|
|
18
48
|
/**
|
|
19
49
|
* HTML page that handles Puter popup auth flow
|
|
20
50
|
* This page loads the Puter SDK, triggers signIn(), and redirects to our callback
|
|
@@ -94,7 +124,7 @@ const getAuthHtml = (callbackUrl) => `
|
|
|
94
124
|
<div class="card">
|
|
95
125
|
<div class="logo">🟣</div>
|
|
96
126
|
<h1>Connect to Puter</h1>
|
|
97
|
-
<p class="subtitle">
|
|
127
|
+
<p class="subtitle">Access Claude, GPT-5, Gemini and 500+ AI models through Puter.com</p>
|
|
98
128
|
|
|
99
129
|
<div id="status" class="status loading">Initializing Puter SDK...</div>
|
|
100
130
|
|
|
@@ -106,7 +136,7 @@ const getAuthHtml = (callbackUrl) => `
|
|
|
106
136
|
<div class="feature"><span class="feature-icon">✓</span> Claude Opus 4.5 & Sonnet 4.5</div>
|
|
107
137
|
<div class="feature"><span class="feature-icon">✓</span> GPT-5.2 & o3-mini</div>
|
|
108
138
|
<div class="feature"><span class="feature-icon">✓</span> Gemini 2.5 Pro (1M context)</div>
|
|
109
|
-
<div class="feature"><span class="feature-icon">✓</span> No
|
|
139
|
+
<div class="feature"><span class="feature-icon">✓</span> No API keys required</div>
|
|
110
140
|
</div>
|
|
111
141
|
</div>
|
|
112
142
|
|
|
@@ -184,20 +214,44 @@ const getAuthHtml = (callbackUrl) => `
|
|
|
184
214
|
</body>
|
|
185
215
|
</html>
|
|
186
216
|
`;
|
|
217
|
+
/**
|
|
218
|
+
* Internal implementation of PuterAuthManager.
|
|
219
|
+
*
|
|
220
|
+
* Not exported directly to avoid OpenCode plugin loader issues.
|
|
221
|
+
* OpenCode iterates through all exports and calls them as functions,
|
|
222
|
+
* which causes "cannot call class without new" errors.
|
|
223
|
+
*
|
|
224
|
+
* Use {@link createPuterAuthManager} factory function instead.
|
|
225
|
+
*/
|
|
187
226
|
// Internal class - not exported to avoid OpenCode plugin loader issues
|
|
188
227
|
// OpenCode iterates through all exports and calls them as functions
|
|
189
228
|
class PuterAuthManagerInternal {
|
|
229
|
+
/** Directory where config files are stored */
|
|
190
230
|
configDir;
|
|
231
|
+
/** Path to the accounts JSON file */
|
|
191
232
|
accountsFile;
|
|
233
|
+
/** In-memory account storage (synced with disk) */
|
|
192
234
|
storage = null;
|
|
235
|
+
/** Logger instance for debugging */
|
|
193
236
|
logger;
|
|
237
|
+
/**
|
|
238
|
+
* Create a new PuterAuthManager instance.
|
|
239
|
+
*
|
|
240
|
+
* @param configDir - Directory to store account data (e.g., ~/.config/opencode)
|
|
241
|
+
* @param config - Optional configuration overrides
|
|
242
|
+
*/
|
|
194
243
|
constructor(configDir, config = {}) {
|
|
195
244
|
this.configDir = configDir;
|
|
196
245
|
this.accountsFile = path.join(configDir, 'puter-accounts.json');
|
|
197
246
|
this.logger = createLoggerFromConfig(config);
|
|
198
247
|
}
|
|
199
248
|
/**
|
|
200
|
-
* Initialize the auth manager and load existing accounts
|
|
249
|
+
* Initialize the auth manager and load existing accounts from disk.
|
|
250
|
+
*
|
|
251
|
+
* Must be called before using other methods. Creates the config
|
|
252
|
+
* directory if it doesn't exist and loads any saved accounts.
|
|
253
|
+
*
|
|
254
|
+
* @throws Error if unable to create config directory
|
|
201
255
|
*/
|
|
202
256
|
async init() {
|
|
203
257
|
this.logger.debug('Initializing auth manager');
|
|
@@ -218,7 +272,8 @@ class PuterAuthManagerInternal {
|
|
|
218
272
|
}
|
|
219
273
|
}
|
|
220
274
|
/**
|
|
221
|
-
* Load accounts from
|
|
275
|
+
* Load accounts from the persisted JSON file.
|
|
276
|
+
* If file doesn't exist or is invalid, initializes with empty storage.
|
|
222
277
|
*/
|
|
223
278
|
async loadAccounts() {
|
|
224
279
|
try {
|
|
@@ -236,7 +291,8 @@ class PuterAuthManagerInternal {
|
|
|
236
291
|
}
|
|
237
292
|
}
|
|
238
293
|
/**
|
|
239
|
-
*
|
|
294
|
+
* Persist current account storage to disk.
|
|
295
|
+
* Called automatically after any account modification.
|
|
240
296
|
*/
|
|
241
297
|
async saveAccounts() {
|
|
242
298
|
if (!this.storage)
|
|
@@ -245,7 +301,12 @@ class PuterAuthManagerInternal {
|
|
|
245
301
|
await fs.writeFile(this.accountsFile, data, 'utf-8');
|
|
246
302
|
}
|
|
247
303
|
/**
|
|
248
|
-
* Get the active account
|
|
304
|
+
* Get the currently active Puter account.
|
|
305
|
+
*
|
|
306
|
+
* The active account is used for all API calls. Use {@link switchAccount}
|
|
307
|
+
* to change which account is active.
|
|
308
|
+
*
|
|
309
|
+
* @returns The active account, or null if not authenticated
|
|
249
310
|
*/
|
|
250
311
|
getActiveAccount() {
|
|
251
312
|
if (!this.storage || this.storage.accounts.length === 0) {
|
|
@@ -254,22 +315,47 @@ class PuterAuthManagerInternal {
|
|
|
254
315
|
return this.storage.accounts[this.storage.activeIndex] || null;
|
|
255
316
|
}
|
|
256
317
|
/**
|
|
257
|
-
* Get all accounts
|
|
318
|
+
* Get all stored Puter accounts.
|
|
319
|
+
*
|
|
320
|
+
* Useful for displaying account selection UI or implementing
|
|
321
|
+
* account rotation when rate limits are hit.
|
|
322
|
+
*
|
|
323
|
+
* @returns Array of all accounts (may be empty)
|
|
258
324
|
*/
|
|
259
325
|
getAllAccounts() {
|
|
260
326
|
return this.storage?.accounts || [];
|
|
261
327
|
}
|
|
262
328
|
/**
|
|
263
|
-
* Check if
|
|
329
|
+
* Check if there is at least one authenticated account.
|
|
330
|
+
*
|
|
331
|
+
* @returns true if at least one account is available
|
|
264
332
|
*/
|
|
265
333
|
isAuthenticated() {
|
|
266
334
|
return this.getActiveAccount() !== null;
|
|
267
335
|
}
|
|
268
336
|
/**
|
|
269
|
-
* Start the OAuth flow
|
|
337
|
+
* Start the OAuth flow by opening a browser for Puter authentication.
|
|
270
338
|
*
|
|
271
|
-
* This
|
|
272
|
-
*
|
|
339
|
+
* This method:
|
|
340
|
+
* 1. Starts a local HTTP server on port 19847
|
|
341
|
+
* 2. Opens the browser to serve the Puter SDK auth page
|
|
342
|
+
* 3. Waits for the user to complete sign-in via Puter popup
|
|
343
|
+
* 4. Receives the token via redirect to /callback
|
|
344
|
+
* 5. Stores the account and shuts down the server
|
|
345
|
+
*
|
|
346
|
+
* The browser window can be closed after successful authentication.
|
|
347
|
+
*
|
|
348
|
+
* @returns Authentication result with success status and account details
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```ts
|
|
352
|
+
* const result = await authManager.login();
|
|
353
|
+
* if (result.success) {
|
|
354
|
+
* console.log('Authenticated as:', result.account?.username);
|
|
355
|
+
* } else {
|
|
356
|
+
* console.error('Auth failed:', result.error);
|
|
357
|
+
* }
|
|
358
|
+
* ```
|
|
273
359
|
*/
|
|
274
360
|
async login() {
|
|
275
361
|
return new Promise((resolve) => {
|
|
@@ -374,7 +460,22 @@ class PuterAuthManagerInternal {
|
|
|
374
460
|
});
|
|
375
461
|
}
|
|
376
462
|
/**
|
|
377
|
-
* Add a new account
|
|
463
|
+
* Add a new account or update an existing one.
|
|
464
|
+
*
|
|
465
|
+
* If an account with the same username exists, it will be updated
|
|
466
|
+
* with the new token. The added/updated account becomes the active account.
|
|
467
|
+
*
|
|
468
|
+
* @param account - The account to add or update
|
|
469
|
+
*
|
|
470
|
+
* @example
|
|
471
|
+
* ```ts
|
|
472
|
+
* await authManager.addAccount({
|
|
473
|
+
* username: 'john_doe',
|
|
474
|
+
* authToken: 'puter-token-xyz',
|
|
475
|
+
* addedAt: Date.now(),
|
|
476
|
+
* isTemporary: false,
|
|
477
|
+
* });
|
|
478
|
+
* ```
|
|
378
479
|
*/
|
|
379
480
|
async addAccount(account) {
|
|
380
481
|
if (!this.storage) {
|
|
@@ -397,7 +498,21 @@ class PuterAuthManagerInternal {
|
|
|
397
498
|
await this.saveAccounts();
|
|
398
499
|
}
|
|
399
500
|
/**
|
|
400
|
-
* Switch to a different account
|
|
501
|
+
* Switch to a different account by index.
|
|
502
|
+
*
|
|
503
|
+
* The index corresponds to the account's position in {@link getAllAccounts}.
|
|
504
|
+
* The switched account becomes the active account for all API calls.
|
|
505
|
+
*
|
|
506
|
+
* @param index - Zero-based index of the account to switch to
|
|
507
|
+
* @returns true if switch was successful, false if index is invalid
|
|
508
|
+
*
|
|
509
|
+
* @example
|
|
510
|
+
* ```ts
|
|
511
|
+
* const accounts = authManager.getAllAccounts();
|
|
512
|
+
* if (accounts.length > 1) {
|
|
513
|
+
* await authManager.switchAccount(1); // Switch to second account
|
|
514
|
+
* }
|
|
515
|
+
* ```
|
|
401
516
|
*/
|
|
402
517
|
async switchAccount(index) {
|
|
403
518
|
if (!this.storage || index < 0 || index >= this.storage.accounts.length) {
|
|
@@ -411,7 +526,13 @@ class PuterAuthManagerInternal {
|
|
|
411
526
|
return true;
|
|
412
527
|
}
|
|
413
528
|
/**
|
|
414
|
-
* Remove an account
|
|
529
|
+
* Remove an account by index.
|
|
530
|
+
*
|
|
531
|
+
* If the removed account was active, the active index is adjusted
|
|
532
|
+
* to point to the previous account (or first if none remain).
|
|
533
|
+
*
|
|
534
|
+
* @param index - Zero-based index of the account to remove
|
|
535
|
+
* @returns true if removal was successful, false if index is invalid
|
|
415
536
|
*/
|
|
416
537
|
async removeAccount(index) {
|
|
417
538
|
if (!this.storage || index < 0 || index >= this.storage.accounts.length) {
|
|
@@ -428,7 +549,10 @@ class PuterAuthManagerInternal {
|
|
|
428
549
|
return true;
|
|
429
550
|
}
|
|
430
551
|
/**
|
|
431
|
-
* Update the
|
|
552
|
+
* Update the lastUsed timestamp for the active account.
|
|
553
|
+
*
|
|
554
|
+
* Called automatically by PuterClient after successful API calls.
|
|
555
|
+
* Useful for implementing least-recently-used account rotation.
|
|
432
556
|
*/
|
|
433
557
|
async touchActiveAccount() {
|
|
434
558
|
const account = this.getActiveAccount();
|
|
@@ -438,7 +562,10 @@ class PuterAuthManagerInternal {
|
|
|
438
562
|
}
|
|
439
563
|
}
|
|
440
564
|
/**
|
|
441
|
-
* Logout
|
|
565
|
+
* Logout and remove all stored accounts.
|
|
566
|
+
*
|
|
567
|
+
* This clears all account data from memory and disk.
|
|
568
|
+
* A new login will be required to use the plugin.
|
|
442
569
|
*/
|
|
443
570
|
async logout() {
|
|
444
571
|
this.logger.auth('Logging out', 'all accounts');
|
|
@@ -451,8 +578,28 @@ class PuterAuthManagerInternal {
|
|
|
451
578
|
}
|
|
452
579
|
}
|
|
453
580
|
/**
|
|
454
|
-
* Factory function to create a PuterAuthManager instance
|
|
455
|
-
*
|
|
581
|
+
* Factory function to create a PuterAuthManager instance.
|
|
582
|
+
*
|
|
583
|
+
* This is the recommended way to create an auth manager.
|
|
584
|
+
* Direct class instantiation is not exposed to avoid plugin loader issues.
|
|
585
|
+
*
|
|
586
|
+
* @param configDir - Directory to store account data (e.g., ~/.config/opencode)
|
|
587
|
+
* @param config - Optional configuration overrides
|
|
588
|
+
* @returns A new PuterAuthManager instance (call .init() before use)
|
|
589
|
+
*
|
|
590
|
+
* @example
|
|
591
|
+
* ```ts
|
|
592
|
+
* import { createPuterAuthManager } from 'opencode-puter-auth';
|
|
593
|
+
*
|
|
594
|
+
* const authManager = createPuterAuthManager('~/.config/my-app');
|
|
595
|
+
* await authManager.init();
|
|
596
|
+
*
|
|
597
|
+
* if (!authManager.isAuthenticated()) {
|
|
598
|
+
* await authManager.login();
|
|
599
|
+
* }
|
|
600
|
+
*
|
|
601
|
+
* const token = authManager.getActiveAccount()?.authToken;
|
|
602
|
+
* ```
|
|
456
603
|
*/
|
|
457
604
|
export function createPuterAuthManager(configDir, config = {}) {
|
|
458
605
|
return new PuterAuthManagerInternal(configDir, config);
|
package/dist/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;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AC,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC3E,CAAC;QAED,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,kBAAkB;QAC7B,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxC,IAAI,OAAO,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAC5B,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAC5B,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,MAAM;QACjB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;QAChD,IAAI,CAAC,OAAO,GAAG;YACb,OAAO,EAAE,CAAC;YACV,QAAQ,EAAE,EAAE;YACZ,WAAW,EAAE,CAAC;SACf,CAAC;QACF,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;IAC5B,CAAC;CACF;AAUD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,sBAAsB,CAAC,SAAiB,EAAE,SAA+B,EAAE;IACzF,OAAO,IAAI,wBAAwB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;AACzD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -18,5 +18,7 @@ export { createLogger, createLoggerFromConfig, nullLogger, LogLevel } from './lo
|
|
|
18
18
|
export type { Logger, LoggerOptions } from './logger.js';
|
|
19
19
|
export { FallbackManager, getGlobalFallbackManager, resetGlobalFallbackManager, isRateLimitError, FallbackExhaustedError, DEFAULT_FALLBACK_MODELS, DEFAULT_COOLDOWN_MS, } from './fallback.js';
|
|
20
20
|
export type { FallbackOptions, FallbackResult, FallbackAttempt, } from './fallback.js';
|
|
21
|
+
export { AccountRotationManager, getGlobalAccountRotationManager, resetGlobalAccountRotationManager, AllAccountsOnCooldownError, DEFAULT_ACCOUNT_COOLDOWN_MS, } from './account-rotation.js';
|
|
22
|
+
export type { AccountRotationOptions, AccountRotationResult, AccountStatus, IAuthManager, } from './account-rotation.js';
|
|
21
23
|
export type { PuterConfig, PuterAccount, PuterChatOptions, PuterChatResponse, PuterChatMessage, PuterChatStreamChunk, PuterModelInfo } from './types.js';
|
|
22
24
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAOH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAI9C,OAAO,EAAE,WAAW,IAAI,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAGhE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAGrH,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACzF,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGzD,OAAO,EACL,eAAe,EACf,wBAAwB,EACxB,0BAA0B,EAC1B,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,eAAe,EACf,cAAc,EACd,eAAe,GAChB,MAAM,eAAe,CAAC;AAGvB,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAOH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAI9C,OAAO,EAAE,WAAW,IAAI,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAGhE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAGrH,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACzF,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGzD,OAAO,EACL,eAAe,EACf,wBAAwB,EACxB,0BAA0B,EAC1B,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,eAAe,EACf,cAAc,EACd,eAAe,GAChB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,sBAAsB,EACtB,+BAA+B,EAC/B,iCAAiC,EACjC,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,sBAAsB,EACtB,qBAAqB,EACrB,aAAa,EACb,YAAY,GACb,MAAM,uBAAuB,CAAC;AAG/B,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -25,4 +25,6 @@ export { createPuter } from './ai-provider/index.js';
|
|
|
25
25
|
export { createLogger, createLoggerFromConfig, nullLogger, LogLevel } from './logger.js';
|
|
26
26
|
// Fallback Manager exports for automatic model fallback
|
|
27
27
|
export { FallbackManager, getGlobalFallbackManager, resetGlobalFallbackManager, isRateLimitError, FallbackExhaustedError, DEFAULT_FALLBACK_MODELS, DEFAULT_COOLDOWN_MS, } from './fallback.js';
|
|
28
|
+
// Account Rotation Manager exports for multi-account support
|
|
29
|
+
export { AccountRotationManager, getGlobalAccountRotationManager, resetGlobalAccountRotationManager, AllAccountsOnCooldownError, DEFAULT_ACCOUNT_COOLDOWN_MS, } from './account-rotation.js';
|
|
28
30
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,kDAAkD;AAClD,2DAA2D;AAC3D,wEAAwE;AACxE,yFAAyF;AACzF,gFAAgF;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,gEAAgE;AAChE,uEAAuE;AACvE,OAAO,EAAE,WAAW,IAAI,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEhE,0BAA0B;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,gCAAgC;AAChC,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGzF,wDAAwD;AACxD,OAAO,EACL,eAAe,EACf,wBAAwB,EACxB,0BAA0B,EAC1B,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,kDAAkD;AAClD,2DAA2D;AAC3D,wEAAwE;AACxE,yFAAyF;AACzF,gFAAgF;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,gEAAgE;AAChE,uEAAuE;AACvE,OAAO,EAAE,WAAW,IAAI,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEhE,0BAA0B;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,gCAAgC;AAChC,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGzF,wDAAwD;AACxD,OAAO,EACL,eAAe,EACf,wBAAwB,EACxB,0BAA0B,EAC1B,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,eAAe,CAAC;AAOvB,6DAA6D;AAC7D,OAAO,EACL,sBAAsB,EACtB,+BAA+B,EAC/B,iCAAiC,EACjC,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,uBAAuB,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -39,6 +39,12 @@ export declare const PuterConfigSchema: z.ZodObject<{
|
|
|
39
39
|
fallback_enabled: z.ZodDefault<z.ZodBoolean>;
|
|
40
40
|
fallback_models: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
41
41
|
fallback_cooldown_ms: z.ZodDefault<z.ZodNumber>;
|
|
42
|
+
account_rotation_enabled: z.ZodDefault<z.ZodBoolean>;
|
|
43
|
+
account_rotation_strategy: z.ZodDefault<z.ZodEnum<{
|
|
44
|
+
"round-robin": "round-robin";
|
|
45
|
+
"least-recently-used": "least-recently-used";
|
|
46
|
+
}>>;
|
|
47
|
+
account_rotation_cooldown_ms: z.ZodDefault<z.ZodNumber>;
|
|
42
48
|
}, z.core.$strip>;
|
|
43
49
|
export type PuterConfig = z.infer<typeof PuterConfigSchema>;
|
|
44
50
|
export interface PuterChatMessage {
|