agent-usage-all-in-one 0.7.0 → 0.7.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.
package/README.md CHANGED
@@ -64,9 +64,10 @@ pnpm install
64
64
  pnpm dev
65
65
  ```
66
66
 
67
- This starts the source daemon, authenticated Vite proxy, hot reload, and dashboard.
67
+ This starts the source daemon, authenticated Vite proxy, hot reload, and dashboard on a random available port.
68
68
  Development state is isolated in the ignored `.agent-usage-dev/` directory. Use
69
- `AGENT_USAGE_DEMO=1 pnpm dev` for demo data or `pnpm dev -- --no-open` to keep the
69
+ `pnpm dev -- --port 3000` (or `AGENT_USAGE_DEV_PORT=3000`) to customize the port,
70
+ `AGENT_USAGE_DEMO=1 pnpm dev` for demo data, or `pnpm dev -- --no-open` to keep the
70
71
  browser closed.
71
72
 
72
73
  ## Install and run
package/README.zh-CN.md CHANGED
@@ -48,8 +48,8 @@ pnpm install
48
48
  pnpm dev
49
49
  ```
50
50
 
51
- 该命令会启动源码守护进程、带认证的 Vite 代理、热更新和页面。开发数据隔离在已忽略的
52
- `.agent-usage-dev/` 目录。使用 `AGENT_USAGE_DEMO=1 pnpm dev` 加载演示数据;使用
51
+ 该命令会启动源码守护进程、带认证的 Vite 代理、热更新和页面(默认分配随机可用端口)。开发数据隔离在已忽略的
52
+ `.agent-usage-dev/` 目录。使用 `pnpm dev -- --port 3000`(或环境变量 `AGENT_USAGE_DEV_PORT=3000`)自定义端口;使用 `AGENT_USAGE_DEMO=1 pnpm dev` 加载演示数据;使用
53
53
  `pnpm dev -- --no-open` 禁止自动打开浏览器。
54
54
 
55
55
  ## 安装与启动
package/dist/cli.js CHANGED
@@ -2439,7 +2439,7 @@ var init_usage_application = __esm({
2439
2439
  });
2440
2440
  }
2441
2441
  this.#repository.saveNotificationState(usedKey, String(bucket.usedPercent));
2442
- const remaining = 100 - bucket.usedPercent;
2442
+ const remaining = Math.max(0, 100 - bucket.usedPercent);
2443
2443
  const level = remaining <= 5 ? "5" : remaining <= 20 ? "20" : "normal";
2444
2444
  const levelKey = `quota-level:${prefix}`;
2445
2445
  const priorLevel = this.#repository.getNotificationState(levelKey) ?? "normal";
@@ -2856,6 +2856,19 @@ var init_catalog = __esm({
2856
2856
  }
2857
2857
  });
2858
2858
 
2859
+ // src/core/quota-normalization.ts
2860
+ function clampPercent(value) {
2861
+ if (value === null || value === void 0 || !Number.isFinite(value)) {
2862
+ return null;
2863
+ }
2864
+ return Math.min(100, Math.max(0, value));
2865
+ }
2866
+ var init_quota_normalization = __esm({
2867
+ "src/core/quota-normalization.ts"() {
2868
+ "use strict";
2869
+ }
2870
+ });
2871
+
2859
2872
  // src/connectors/claude-code/claude-code-connector.ts
2860
2873
  function incompleteTranscriptFailure(provider) {
2861
2874
  return {
@@ -2869,7 +2882,7 @@ function mapQuota(quota) {
2869
2882
  id: quota.id,
2870
2883
  billingDomainId: "subscription",
2871
2884
  label: quota.label,
2872
- usedPercent: quota.usedPercent,
2885
+ usedPercent: clampPercent(quota.usedPercent),
2873
2886
  windowDurationMinutes: quota.windowDurationMinutes,
2874
2887
  resetsAt: quota.resetsAt,
2875
2888
  authority: "official-client",
@@ -2890,6 +2903,7 @@ var ClaudeCodeConnector;
2890
2903
  var init_claude_code_connector = __esm({
2891
2904
  "src/connectors/claude-code/claude-code-connector.ts"() {
2892
2905
  "use strict";
2906
+ init_quota_normalization();
2893
2907
  ClaudeCodeConnector = class {
2894
2908
  id = "claude-code";
2895
2909
  displayName = "Claude Code";
@@ -3174,7 +3188,7 @@ function parseClaudeUsageScreen(text, now) {
3174
3188
  quotas.set(id, {
3175
3189
  id,
3176
3190
  label: displayLabel(heading),
3177
- usedPercent: Number(match[1]),
3191
+ usedPercent: clampPercent(Number(match[1])),
3178
3192
  windowDurationMinutes: windowDurationMinutes(heading),
3179
3193
  resetsAt: resetLine ? parseReset(resetLine, now) : null
3180
3194
  });
@@ -3363,6 +3377,7 @@ var ClaudeUsageAdapterError, ScreenReaderClaudeQuotaClient;
3363
3377
  var init_claude_usage_screen_client = __esm({
3364
3378
  "src/connectors/claude-code/claude-usage-screen-client.ts"() {
3365
3379
  "use strict";
3380
+ init_quota_normalization();
3366
3381
  ClaudeUsageAdapterError = class extends Error {
3367
3382
  code;
3368
3383
  recovery;
@@ -3566,7 +3581,7 @@ function mapQuotaBuckets(response) {
3566
3581
  id: `${key}:${windowName}`,
3567
3582
  billingDomainId: "subscription",
3568
3583
  label: multipleLimits ? `${baseLabel} \xB7 ${windowLabel}` : windowLabel,
3569
- usedPercent: window.usedPercent,
3584
+ usedPercent: clampPercent(window.usedPercent),
3570
3585
  windowDurationMinutes: window.windowDurationMins,
3571
3586
  resetsAt: window.resetsAt === null ? null : new Date(window.resetsAt * 1e3).toISOString(),
3572
3587
  authority: "official-account"
@@ -3587,6 +3602,7 @@ var nullableNumeric, numeric, rateLimitWindowSchema, rateLimitSnapshotSchema, co
3587
3602
  var init_codex_connector = __esm({
3588
3603
  "src/connectors/codex/codex-connector.ts"() {
3589
3604
  "use strict";
3605
+ init_quota_normalization();
3590
3606
  init_token_normalization();
3591
3607
  nullableNumeric = z2.union([z2.number(), z2.string()]).transform(Number).nullable();
3592
3608
  numeric = z2.union([z2.number(), z2.string()]).transform(Number);
@@ -4346,7 +4362,7 @@ function mapQuota2(response) {
4346
4362
  id,
4347
4363
  billingDomainId: "go-subscription",
4348
4364
  label: LIMITS[id].label,
4349
- usedPercent: response.usage[id].percent,
4365
+ usedPercent: clampPercent(response.usage[id].percent),
4350
4366
  windowDurationMinutes: LIMITS[id].windowDurationMinutes,
4351
4367
  resetsAt: response.usage[id].resetsAt,
4352
4368
  authority: "official-account",
@@ -4371,6 +4387,7 @@ var LIMITS, OpenCodeGoConnector;
4371
4387
  var init_opencode_go_connector = __esm({
4372
4388
  "src/connectors/opencode-go/opencode-go-connector.ts"() {
4373
4389
  "use strict";
4390
+ init_quota_normalization();
4374
4391
  LIMITS = {
4375
4392
  rolling: { label: "5 hour", amount: 12, windowDurationMinutes: 300 },
4376
4393
  weekly: { label: "Week", amount: 30, windowDurationMinutes: 10080 },
@@ -4467,7 +4484,9 @@ function grokBuildBillingDomains(usage = []) {
4467
4484
  function mapBillingQuota(billing) {
4468
4485
  const config = billing.config;
4469
4486
  if (!config) return [];
4470
- const usedPercent = config.creditUsagePercent ?? derivePercent(config.used?.val, config.monthlyLimit?.val);
4487
+ const usedPercent = clampPercent(
4488
+ config.creditUsagePercent ?? derivePercent(config.used?.val, config.monthlyLimit?.val)
4489
+ );
4471
4490
  if (usedPercent === null) return [];
4472
4491
  const periodType = config.currentPeriod?.type;
4473
4492
  const period = nativePeriod(periodType, config.currentPeriod ? void 0 : "monthly");
@@ -4525,6 +4544,7 @@ var centSchema, usagePeriodSchema, billingConfigSchema, grokBillingResponseSchem
4525
4544
  var init_grok_build_connector = __esm({
4526
4545
  "src/connectors/grok-build/grok-build-connector.ts"() {
4527
4546
  "use strict";
4547
+ init_quota_normalization();
4528
4548
  centSchema = z6.object({ val: z6.number().default(0) }).passthrough();
4529
4549
  usagePeriodSchema = z6.object({
4530
4550
  type: z6.string().optional(),
@@ -8060,7 +8080,7 @@ function mapQuotaRow(row) {
8060
8080
  id: row.id,
8061
8081
  billingDomainId: row.billing_domain_id,
8062
8082
  label: row.label,
8063
- usedPercent: row.used_percent,
8083
+ usedPercent: clampPercent(row.used_percent),
8064
8084
  windowDurationMinutes: row.window_duration_minutes,
8065
8085
  resetsAt: row.resets_at,
8066
8086
  authority: row.authority,
@@ -9156,7 +9176,10 @@ function buildRiskSummary(providers) {
9156
9176
  const limitingBucket = [...buckets].sort(
9157
9177
  (left, right) => right.usedPercent - left.usedPercent || left.id.localeCompare(right.id)
9158
9178
  )[0];
9159
- const remaining = Math.min(...buckets.map((bucket) => 100 - bucket.usedPercent));
9179
+ const remaining = Math.max(
9180
+ 0,
9181
+ Math.min(...buckets.map((bucket) => 100 - bucket.usedPercent))
9182
+ );
9160
9183
  const predictsFailure = domain.forecasts.some((forecast) => !forecast.willLastUntilReset);
9161
9184
  const predictsSuccess = domain.forecasts.length > 0 && domain.forecasts.every((forecast) => forecast.willLastUntilReset);
9162
9185
  const coveragePenalty = domain.forecastCoverage === "discontinuous" ? 40 : 0;
@@ -9239,6 +9262,7 @@ var init_sqlite_usage_repository = __esm({
9239
9262
  "src/server/sqlite-usage-repository.ts"() {
9240
9263
  "use strict";
9241
9264
  init_token_normalization();
9265
+ init_quota_normalization();
9242
9266
  init_plan_pricing();
9243
9267
  FRESHNESS_WINDOW_MS = 15 * 60 * 1e3;
9244
9268
  QUERY_INDEXES_SQL = `
@@ -9388,12 +9412,13 @@ var init_sqlite_usage_repository = __esm({
9388
9412
  }
9389
9413
  }
9390
9414
  for (const bucket of snapshot2.quotaBuckets) {
9415
+ const clampedUsedPercent = clampPercent(bucket.usedPercent);
9391
9416
  quotaStatement.run(
9392
9417
  snapshot2.provider.id,
9393
9418
  bucket.id,
9394
9419
  bucket.billingDomainId,
9395
9420
  bucket.label,
9396
- bucket.usedPercent,
9421
+ clampedUsedPercent,
9397
9422
  bucket.windowDurationMinutes ?? null,
9398
9423
  bucket.resetsAt,
9399
9424
  bucket.authority,
@@ -9418,13 +9443,14 @@ var init_sqlite_usage_repository = __esm({
9418
9443
  authority = excluded.authority`
9419
9444
  );
9420
9445
  for (const bucket of snapshot2.quotaBuckets) {
9421
- if (bucket.usedPercent === null) continue;
9446
+ const clampedUsedPercent = clampPercent(bucket.usedPercent);
9447
+ if (clampedUsedPercent === null) continue;
9422
9448
  quotaObservationStatement.run(
9423
9449
  snapshot2.provider.id,
9424
9450
  bucket.id,
9425
9451
  bucket.billingDomainId,
9426
9452
  bucket.label,
9427
- bucket.usedPercent,
9453
+ clampedUsedPercent,
9428
9454
  bucket.resetsAt,
9429
9455
  bucket.authority,
9430
9456
  snapshot2.observedAt