atris 3.82.17 → 3.82.18

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.
Files changed (2) hide show
  1. package/commands/usage.js +27 -1
  2. package/package.json +1 -1
package/commands/usage.js CHANGED
@@ -15,12 +15,38 @@ const {
15
15
 
16
16
  function showUsageHelp() {
17
17
  console.log('usage: atris usage [--json]');
18
- console.log('show developer api usage for the logged-in account.');
18
+ console.log('show developer api usage: every key you own when signed in, or one key with ATRIS_API_KEY.');
19
+ }
20
+
21
+ function plural(n, word) {
22
+ return `${n} ${word}${n === 1 ? '' : 's'}`;
23
+ }
24
+
25
+ // Signed in as a person, the server answers with every developer key you own
26
+ // plus a total. One line per key, then the total.
27
+ function renderKeyBreakdown(usage) {
28
+ const total = usage.total && typeof usage.total === 'object' ? usage.total : {};
29
+ const days = Number(total.period_days) || 30;
30
+ const lines = [`last ${days} days, ${plural(usage.keys.length, 'developer key')}:`];
31
+ for (const entry of usage.keys) {
32
+ const u = (entry && entry.usage) || {};
33
+ const label = `${entry.agent_name || 'key'} (${u.api_key || 'key'})`;
34
+ const errors = Number(u.error_count) || 0;
35
+ lines.push(` ${label}: ${plural(Number(u.total_requests) || 0, 'request')}${errors ? `, ${plural(errors, 'error')}` : ''}`);
36
+ }
37
+ const totalErrors = Number(total.error_count) || 0;
38
+ lines.push(`total: ${plural(Number(total.total_requests) || 0, 'request')}${totalErrors ? `, ${plural(totalErrors, 'error')} (${total.error_rate}%)` : ''}`);
39
+ const endpoints = Object.entries(total.endpoints || {}).sort((a, b) => b[1] - a[1]).slice(0, 5);
40
+ if (endpoints.length) lines.push(`busiest: ${endpoints.map(([name, count]) => `${name} ${count}`).join(', ')}`);
41
+ return lines.join('\n');
19
42
  }
20
43
 
21
44
  function renderUsage(data = {}) {
22
45
  const raw = data && typeof data === 'object' ? data : {};
23
46
  const usage = raw.usage && typeof raw.usage === 'object' ? raw.usage : raw;
47
+ if (Array.isArray(usage.keys)) {
48
+ return usage.keys.length ? renderKeyBreakdown(usage) : 'no developer keys yet. make one with atris api-key create';
49
+ }
24
50
  const lines = [];
25
51
  if (raw.agent_name || raw.agent_id) {
26
52
  lines.push(`${raw.agent_name || 'agent'} ${raw.agent_id || ''}`.trim());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atris",
3
- "version": "3.82.17",
3
+ "version": "3.82.18",
4
4
  "description": "you say what you want in plain words. atris builds it, checks it, and shows you proof. project memory your coding agents share across sessions.",
5
5
  "mcpName": "io.github.atrislabs/atris",
6
6
  "main": "bin/atris.js",