@zhafron/opencode-kiro-auth 1.4.1 → 1.4.3

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.
@@ -72,7 +72,7 @@ export class AccountManager {
72
72
  const now = Date.now();
73
73
  const available = this.accounts.filter((a) => {
74
74
  if (!a.isHealthy) {
75
- if (a.failCount < 3 && a.recoveryTime && now >= a.recoveryTime) {
75
+ if (a.failCount < 10 && a.recoveryTime && now >= a.recoveryTime) {
76
76
  a.isHealthy = true;
77
77
  delete a.unhealthyReason;
78
78
  delete a.recoveryTime;
@@ -97,7 +97,7 @@ export class AccountManager {
97
97
  }
98
98
  if (!selected) {
99
99
  const fallback = this.accounts
100
- .filter((a) => !a.isHealthy && a.failCount < 3)
100
+ .filter((a) => !a.isHealthy && a.failCount < 10)
101
101
  .sort((a, b) => (a.usedCount || 0) - (b.usedCount || 0) || (a.lastUsed || 0) - (b.lastUsed || 0))[0];
102
102
  if (fallback) {
103
103
  fallback.isHealthy = true;
@@ -178,7 +178,7 @@ export class AccountManager {
178
178
  acc.failCount = (acc.failCount || 0) + 1;
179
179
  acc.unhealthyReason = reason;
180
180
  acc.lastUsed = Date.now();
181
- if (acc.failCount >= 3) {
181
+ if (acc.failCount >= 10) {
182
182
  acc.isHealthy = false;
183
183
  acc.recoveryTime = recovery || Date.now() + 3600000;
184
184
  }
package/dist/plugin.js CHANGED
@@ -11,6 +11,7 @@ import { transformToCodeWhisperer } from './plugin/request';
11
11
  import { parseEventStream } from './plugin/response';
12
12
  import { startIDCAuthServer } from './plugin/server';
13
13
  import { migrateJsonToSqlite } from './plugin/storage/migration';
14
+ import { kiroDb } from './plugin/storage/sqlite';
14
15
  import { transformKiroStream } from './plugin/streaming';
15
16
  import { syncFromKiroCli } from './plugin/sync/kiro-cli';
16
17
  import { refreshAccessToken } from './plugin/token';
@@ -176,6 +177,10 @@ export const createKiroPlugin = (id) => async ({ client, directory }) => {
176
177
  }, apiTimestamp);
177
178
  }
178
179
  if (res.ok) {
180
+ if (acc.failCount && acc.failCount > 0) {
181
+ acc.failCount = 0;
182
+ kiroDb.upsertAccount(acc);
183
+ }
179
184
  if (config.usage_tracking_enabled) {
180
185
  const sync = async (att = 0) => {
181
186
  try {
@@ -261,8 +266,31 @@ export const createKiroPlugin = (id) => async ({ client, directory }) => {
261
266
  continue;
262
267
  }
263
268
  if ((res.status === 402 || res.status === 403) && count > 1) {
264
- am.markUnhealthy(acc, res.status === 402 ? 'Quota' : 'Forbidden');
269
+ let errorReason = res.status === 402 ? 'Quota' : 'Forbidden';
270
+ let isPermanent = false;
271
+ try {
272
+ const errorBody = await res.text();
273
+ const errorData = JSON.parse(errorBody);
274
+ if (errorData.reason === 'INVALID_MODEL_ID') {
275
+ logger.warn(`Invalid model ID for ${acc.email}: ${errorData.message}`);
276
+ throw new Error(`Invalid model: ${errorData.message}`);
277
+ }
278
+ if (errorData.reason === 'TEMPORARILY_SUSPENDED') {
279
+ errorReason = 'Account Suspended';
280
+ isPermanent = true;
281
+ }
282
+ }
283
+ catch (e) {
284
+ if (e instanceof Error && e.message.includes('Invalid model')) {
285
+ throw e;
286
+ }
287
+ }
288
+ if (isPermanent) {
289
+ acc.failCount = 10;
290
+ }
291
+ am.markUnhealthy(acc, errorReason);
265
292
  await am.saveToDisk();
293
+ showToast(`${errorReason}. Switching account...`, 'warning');
266
294
  continue;
267
295
  }
268
296
  const h = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhafron/opencode-kiro-auth",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "description": "OpenCode plugin for AWS Kiro (CodeWhisperer) providing access to Claude models",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",