@1930dev/opencode-usage 0.1.0 → 0.1.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.
Files changed (3) hide show
  1. package/README.md +10 -4
  2. package/dist/cli.js +7 -15
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -108,7 +108,13 @@ glm-5.3-flash GLM 5.3-Flash 58 72 $0.11 534.9
108
108
  ...
109
109
  ```
110
110
 
111
- Data from [Artificial Analysis](https://artificialanalysis.ai) (Intelligence Index v4.1) + [models.dev](https://models.dev) pricing.
111
+ Intelligence indices from [Artificial Analysis](https://artificialanalysis.ai), pricing
112
+ from [models.dev](https://models.dev).
113
+
114
+ `top` needs an `AA_API_KEY` for the indices. This package ships neither a key nor a copy
115
+ of the data: the free Data API tier is "internal use only; no redistribution", and
116
+ attribution is required on every tier — which is why the credit is printed under the
117
+ table and carried in `--json`.
112
118
 
113
119
  ## Requirements
114
120
 
@@ -122,9 +128,9 @@ Data from [Artificial Analysis](https://artificialanalysis.ai) (Intelligence Ind
122
128
  - `OPENCODE_AUTH_PATH` — override auth.json path
123
129
  - `OPENCODE_IMP_CACHE` — cache directory (default `~/.cache/opencode-usage`)
124
130
  - `OPENCODE_IMP_BUDGETS` — budgets.json path
125
- - `AA_API_KEY` — Artificial Analysis API key, used by `top`. Without it, ranking is skipped
126
- - `INFISICAL_PROJECT_ID` optional: read `AA_API_KEY` from Infisical through the
127
- `infisical-secret` wrapper instead of from the environment
131
+ - `AA_API_KEY` — Artificial Analysis key, used by `top` for the intelligence indices.
132
+ Optional: without it `top` still prints prices, only without `IQ` and `IQ/$`.
133
+ A free key is at [artificialanalysis.ai/data-api](https://artificialanalysis.ai/data-api)
128
134
 
129
135
  ## Development
130
136
 
package/dist/cli.js CHANGED
@@ -448,7 +448,6 @@ function providersTable(statuses, local) {
448
448
  // packages/core/src/ranking/fetch.ts
449
449
  import { mkdir as mkdir2, readFile as readFile3, writeFile as writeFile2 } from "fs/promises";
450
450
  import path3 from "path";
451
- var {$ } = globalThis.Bun;
452
451
  var TTL_MS2 = 24 * 60 * 60 * 1000;
453
452
  async function readCache2(file) {
454
453
  try {
@@ -481,24 +480,14 @@ async function fetchModelsDev() {
481
480
  await writeCache2("models-dev.json", flat);
482
481
  return flat;
483
482
  }
484
- async function aaApiKey() {
485
- if (process.env.AA_API_KEY)
486
- return process.env.AA_API_KEY;
487
- const projectId = process.env.INFISICAL_PROJECT_ID;
488
- if (!projectId)
489
- return;
490
- try {
491
- const out = await $`infisical-secret get AA_API_KEY --projectId ${projectId} --env prod --plain --silent`.text();
492
- return out.trim() || undefined;
493
- } catch {
494
- return;
495
- }
483
+ function aaApiKey() {
484
+ return process.env.AA_API_KEY || undefined;
496
485
  }
497
486
  async function fetchAA() {
498
487
  const cached = await readCache2("aa.json");
499
488
  if (cached)
500
489
  return cached;
501
- const key = await aaApiKey();
490
+ const key = aaApiKey();
502
491
  if (!key)
503
492
  return [];
504
493
  const res = await fetch("https://artificialanalysis.ai/api/v2/data/llms/models", {
@@ -585,6 +574,7 @@ function valueScore(intelligenceIndex, cost) {
585
574
  }
586
575
 
587
576
  // packages/core/src/top.ts
577
+ var RANKING_ATTRIBUTION = "Intelligence: Artificial Analysis (artificialanalysis.ai) \xB7 Pricing: models.dev";
588
578
  async function buildTop(limit) {
589
579
  const [modelsDev, aaModels] = await Promise.all([fetchModelsDev(), fetchAA()]);
590
580
  const match = buildMatcher(aaModels, modelsDev);
@@ -883,7 +873,7 @@ async function cmdTop(flags, json) {
883
873
  const limit = typeof flags.get("--limit") === "string" ? Number(flags.get("--limit")) : 20;
884
874
  const rows = await buildTop(limit);
885
875
  if (json) {
886
- console.log(JSON.stringify(rows, null, 2));
876
+ console.log(JSON.stringify({ attribution: RANKING_ATTRIBUTION, models: rows }, null, 2));
887
877
  return;
888
878
  }
889
879
  const head = ["MODEL", "NAME", "IQ", "CODING", "$/M", "IQ/$"];
@@ -901,6 +891,8 @@ async function cmdTop(flags, json) {
901
891
  r.value !== undefined ? r.value.toFixed(1) : "\u2014"
902
892
  ]));
903
893
  }
894
+ console.log(`
895
+ ${RANKING_ATTRIBUTION}`);
904
896
  }
905
897
  if (import.meta.main) {
906
898
  const { cmd, flags } = parseArgs(process.argv.slice(2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1930dev/opencode-usage",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Usage tracking, budget percentages and model ranking for opencode \u2014 CLI plus a /usage TUI plugin",
5
5
  "type": "module",
6
6
  "bin": {