@sunerpy/opencode-kiro-auth 0.2.1 → 0.2.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.
@@ -17,8 +17,19 @@ export declare class AuthHandler {
17
17
  /** Ends the auth flow cleanly with no key prompt and no credential written. */
18
18
  private endWithoutCredential;
19
19
  /**
20
- * Self-drawn account-removal flow returning method:'auto' + failed-callback in
21
- * all cases, so the auth flow ends with no key prompt and NO credential written.
20
+ * Ends the flow after a successful deletion. If a healthy account (or any
21
+ * account with a usable access token) remains, returns a SUCCESS callback
22
+ * keyed on that account's token so OpenCode shows success and persists a
23
+ * still-valid credential. If nothing usable remains, falls back to a failed
24
+ * callback (nothing left to authorize with).
25
+ */
26
+ private endWithRemainingCredentialOrFailed;
27
+ /**
28
+ * Self-drawn account-removal flow. No-op paths (cancel / no accounts /
29
+ * not-confirmed / non-TTY) end with method:'auto' + a failed callback so no
30
+ * key prompt appears and no bogus success is shown. The actual-deletion path
31
+ * ends with a remaining-account success (or failed if none remain), so a
32
+ * successful removal is not misreported as "Failed to authorize".
22
33
  */
23
34
  private authorizeRemoveAccounts;
24
35
  }
@@ -215,8 +215,34 @@ export class AuthHandler {
215
215
  };
216
216
  }
217
217
  /**
218
- * Self-drawn account-removal flow returning method:'auto' + failed-callback in
219
- * all cases, so the auth flow ends with no key prompt and NO credential written.
218
+ * Ends the flow after a successful deletion. If a healthy account (or any
219
+ * account with a usable access token) remains, returns a SUCCESS callback
220
+ * keyed on that account's token so OpenCode shows success and persists a
221
+ * still-valid credential. If nothing usable remains, falls back to a failed
222
+ * callback (nothing left to authorize with).
223
+ */
224
+ endWithRemainingCredentialOrFailed(instructions) {
225
+ const remaining = this.accountManager?.getAccounts?.() ?? [];
226
+ const hasToken = (acc) => typeof acc?.accessToken === 'string' && acc.accessToken.length > 0;
227
+ const fallback = remaining.find((acc) => acc?.isHealthy && hasToken(acc)) ??
228
+ remaining.find((acc) => hasToken(acc));
229
+ if (fallback) {
230
+ const key = fallback.accessToken;
231
+ return {
232
+ url: '',
233
+ instructions: `${instructions} Using ${fallback.email || 'a remaining account'} for future requests.`,
234
+ method: 'auto',
235
+ callback: async () => ({ type: 'success', key })
236
+ };
237
+ }
238
+ return this.endWithoutCredential(`${instructions} No accounts remain — run \`opencode auth login\` to reauthenticate.`);
239
+ }
240
+ /**
241
+ * Self-drawn account-removal flow. No-op paths (cancel / no accounts /
242
+ * not-confirmed / non-TTY) end with method:'auto' + a failed callback so no
243
+ * key prompt appears and no bogus success is shown. The actual-deletion path
244
+ * ends with a remaining-account success (or failed if none remain), so a
245
+ * successful removal is not misreported as "Failed to authorize".
220
246
  */
221
247
  async authorizeRemoveAccounts() {
222
248
  const accounts = this.accountManager?.getAccounts?.() ?? [];
@@ -248,6 +274,6 @@ export class AuthHandler {
248
274
  this.accountManager.removeAccount(target);
249
275
  logger.log('Removed Kiro account', { email: target.email, accountId: String(target.id) });
250
276
  process.stdout.write('Account deleted.\n');
251
- return this.endWithoutCredential(`Account deleted: ${target.email || 'unknown'}.`);
277
+ return this.endWithRemainingCredentialOrFailed(`Account deleted: ${target.email || 'unknown'}.`);
252
278
  }
253
279
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sunerpy/opencode-kiro-auth",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "OpenCode plugin for AWS Kiro (CodeWhisperer) providing access to Claude models",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",