@lightharu/krouter 1.8.0 → 1.8.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.
@@ -9,7 +9,7 @@
9
9
  http-equiv="Content-Security-Policy"
10
10
  content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:"
11
11
  />
12
- <script type="module" crossorigin src="/assets/index-DCslvfUR.js"></script>
12
+ <script type="module" crossorigin src="/assets/index-CdizCUPa.js"></script>
13
13
  <link rel="stylesheet" crossorigin href="/assets/index-CM4-0adf.css">
14
14
  </head>
15
15
 
@@ -347,6 +347,18 @@ function accountNeedsBackendRefresh(account, now) {
347
347
  const expiresAt = Number(credentials.expiresAt || 0);
348
348
  return !credentials.accessToken || !expiresAt || expiresAt - now <= TOKEN_REFRESH_BEFORE_EXPIRY_MS;
349
349
  }
350
+ function normalizeStoredUsagePercent(usage) {
351
+ const current = Number(usage.current);
352
+ const limit = Number(usage.limit);
353
+ if (Number.isFinite(current) && Number.isFinite(limit) && limit > 0) {
354
+ return { ...usage, percentUsed: current / limit };
355
+ }
356
+ const persisted = Number(usage.percentUsed);
357
+ if (Number.isFinite(persisted) && persisted > 1 && persisted <= 100) {
358
+ return { ...usage, percentUsed: persisted / 100 };
359
+ }
360
+ return usage;
361
+ }
350
362
  function getStoredAccounts(accountData) {
351
363
  return isPlainRecord(accountData.accounts) ? accountData.accounts : {};
352
364
  }
@@ -366,7 +378,7 @@ function applyRefreshDataToStoredAccount(id, account, data, now) {
366
378
  let usage = account.usage;
367
379
  if (isPlainRecord(data?.usage)) {
368
380
  const currentUsage = isPlainRecord(account.usage) ? account.usage : {};
369
- usage = { ...currentUsage, ...data.usage, lastUpdated: now };
381
+ usage = normalizeStoredUsagePercent({ ...currentUsage, ...data.usage, lastUpdated: now });
370
382
  }
371
383
  let subscription = account.subscription;
372
384
  if (isPlainRecord(data?.subscription)) {
@@ -418,7 +418,7 @@ async function checkAccountStatus(account) {
418
418
  profileArn: resolvedProfileArn,
419
419
  usage: {
420
420
  ...normalized.usage,
421
- percentUsed: normalized.usage.limit ? (normalized.usage.current / normalized.usage.limit) * 100 : 0,
421
+ percentUsed: normalized.usage.limit ? normalized.usage.current / normalized.usage.limit : 0,
422
422
  lastUpdated: Date.now()
423
423
  },
424
424
  newCredentials: refreshResult?.data ? {
package/package.json CHANGED
@@ -1,41 +1,42 @@
1
1
  {
2
- "name": "@lightharu/krouter",
3
- "version": "1.8.0",
4
- "description": "Krouter - Web dashboard and CLI router for Kiro accounts, quota balancing, and API proxy",
5
- "main": "./out-server/server/index.js",
6
- "bin": {
7
- "krouter": "scripts/krouter-cli.cjs"
8
- },
9
- "author": "LightHaru",
10
- "license": "AGPL-3.0",
11
- "homepage": "https://github.com/LightHaru/Krouter",
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/LightHaru/Krouter.git"
15
- },
16
- "bugs": {
17
- "url": "https://github.com/LightHaru/Krouter/issues"
18
- },
19
- "keywords": [
20
- "krouter",
21
- "kiro",
22
- "openclaw",
23
- "api-proxy",
24
- "openai-compatible",
25
- "cli"
26
- ],
27
- "files": [
28
- "dist-web/",
29
- "out-server/",
30
- "scripts/krouter-cli.cjs",
31
- "scripts/kiro-manager-cli.cjs",
32
- "resources/tls-client-xgo-1.14.0-windows-amd64.dll",
2
+ "name": "@lightharu/krouter",
3
+ "version": "1.8.1",
4
+ "description": "Krouter - Web dashboard and CLI router for Kiro accounts, quota balancing, and API proxy",
5
+ "main": "./out-server/server/index.js",
6
+ "bin": {
7
+ "krouter": "scripts/krouter-cli.cjs"
8
+ },
9
+ "author": "LightHaru",
10
+ "license": "AGPL-3.0",
11
+ "homepage": "https://github.com/LightHaru/Krouter",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/LightHaru/Krouter.git"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/LightHaru/Krouter/issues"
18
+ },
19
+ "keywords": [
20
+ "krouter",
21
+ "kiro",
22
+ "openclaw",
23
+ "api-proxy",
24
+ "openai-compatible",
25
+ "cli"
26
+ ],
27
+ "files": [
28
+ "dist-web/",
29
+ "out-server/",
30
+ "scripts/krouter-cli.cjs",
31
+ "scripts/kiro-manager-cli.cjs",
32
+ "resources/tls-client-xgo-1.14.0-windows-amd64.dll",
33
33
  "src/renderer/src/assets/krouter-logo.svg",
34
34
  "src/renderer/src/assets/krouter-mark.svg",
35
+ "CHANGELOG.md",
35
36
  "README.md",
36
37
  "LICENSE"
37
38
  ],
38
- "scripts": {
39
+ "scripts": {
39
40
  "format": "prettier --write .",
40
41
  "lint": "eslint --cache .",
41
42
  "typecheck:node": "tsc --noEmit -p tsconfig.node.json --composite false",
@@ -47,15 +48,15 @@
47
48
  "build": "npm run typecheck && electron-vite build",
48
49
  "dev:web": "vite --config vite.web.config.ts",
49
50
  "dev:api": "tsc -w -p tsconfig.server.json",
50
- "build:web": "vite build --config vite.web.config.ts",
51
- "build:api": "tsc -p tsconfig.server.json",
52
- "clean:fullstack": "node -e \"const fs=require('fs'); for (const p of ['dist-web','out-server']) fs.rmSync(p,{recursive:true,force:true})\"",
53
- "build:fullstack": "npm run clean:fullstack && npm run typecheck:web && npm run typecheck:server && npm run build:web && npm run build:api",
54
- "start:api": "node out-server/server/index.js --api-only",
55
- "start:backend": "node out-server/server/index.js --api-only",
56
- "start:fullstack": "node out-server/server/index.js",
57
- "cli": "node scripts/krouter-cli.cjs",
58
- "prepack": "npm run build:fullstack",
51
+ "build:web": "vite build --config vite.web.config.ts",
52
+ "build:api": "tsc -p tsconfig.server.json",
53
+ "clean:fullstack": "node -e \"const fs=require('fs'); for (const p of ['dist-web','out-server']) fs.rmSync(p,{recursive:true,force:true})\"",
54
+ "build:fullstack": "npm run clean:fullstack && npm run typecheck:web && npm run typecheck:server && npm run build:web && npm run build:api",
55
+ "start:api": "node out-server/server/index.js --api-only",
56
+ "start:backend": "node out-server/server/index.js --api-only",
57
+ "start:fullstack": "node out-server/server/index.js",
58
+ "cli": "node scripts/krouter-cli.cjs",
59
+ "prepack": "npm run build:fullstack",
59
60
  "build:unpack": "npm run build && electron-builder --dir",
60
61
  "build:win": "npm run build && electron-builder --win",
61
62
  "build:mac": "electron-vite build && electron-builder --mac",