feat: extract models from command-code dist, load via models.json

- Add scripts/extract-models.ts to parse command-code npm dist file
- Generate models.json (21 models, 15 pricing entries) with contextWindow
  and maxOutputTokens pre-filled; no nulls or hardcoded fallbacks in index.ts
- Rewrite index.ts to load model list and costs from models.json
- Cap gateway model maxOutputTokens at 65536 (API limit for Baseten/Vercel)
- Add 'Update models' section to README documenting the generation flow
- Add npm run extract-models script
This commit is contained in:
Tao Yang
2026-05-25 16:37:08 +08:00
parent b5b109c63c
commit 960d0d1f23
5 changed files with 907 additions and 143 deletions
+23
View File
@@ -100,6 +100,29 @@ Or within pi:
/models
```
## Update models
The model list (`models.json`) is extracted from the [command-code](https://www.npmjs.com/package/command-code) npm package's dist file. When Command Code releases a new version with updated models, regenerate it:
```sh
npm run extract-models
```
This runs `scripts/extract-models.ts`, which:
1. Downloads the latest `command-code` tarball from npm (`npm pack command-code`)
2. Parses the minified `dist/index.mjs` to extract provider definitions, model metadata, and pricing
3. Fills in `contextWindow` and `maxOutputTokens` with sensible defaults where the CLI omits them
4. Writes the result to `models.json`
To use a specific version or local dist file:
```sh
npx tsx scripts/extract-models.ts /path/to/command-code/dist/index.mjs
```
`models.json` is committed to the repo and included in the npm package.
## Publish
```sh