@getrouter/getrouter-cli 0.1.0
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/.github/workflows/ci.yml +19 -0
- package/AGENTS.md +78 -0
- package/README.ja.md +116 -0
- package/README.md +116 -0
- package/README.zh-cn.md +116 -0
- package/biome.json +10 -0
- package/bun.lock +397 -0
- package/dist/bin.mjs +1422 -0
- package/docs/plans/2026-01-01-getrouter-cli-config-command-plan.md +231 -0
- package/docs/plans/2026-01-01-getrouter-cli-config-core-plan.md +307 -0
- package/docs/plans/2026-01-01-getrouter-cli-design.md +106 -0
- package/docs/plans/2026-01-01-getrouter-cli-scaffold-plan.md +327 -0
- package/docs/plans/2026-01-02-getrouter-cli-auth-design.md +68 -0
- package/docs/plans/2026-01-02-getrouter-cli-auth-device-design.md +73 -0
- package/docs/plans/2026-01-02-getrouter-cli-auth-device-plan.md +411 -0
- package/docs/plans/2026-01-02-getrouter-cli-auth-plan.md +435 -0
- package/docs/plans/2026-01-02-getrouter-cli-http-client-plan.md +235 -0
- package/docs/plans/2026-01-02-getrouter-cli-keys-create-update-output-design.md +24 -0
- package/docs/plans/2026-01-02-getrouter-cli-keys-create-update-output-plan.md +141 -0
- package/docs/plans/2026-01-02-getrouter-cli-keys-delete-output-design.md +22 -0
- package/docs/plans/2026-01-02-getrouter-cli-keys-delete-output-plan.md +122 -0
- package/docs/plans/2026-01-02-getrouter-cli-keys-get-output-design.md +23 -0
- package/docs/plans/2026-01-02-getrouter-cli-keys-get-output-plan.md +141 -0
- package/docs/plans/2026-01-02-getrouter-cli-keys-interactive-design.md +28 -0
- package/docs/plans/2026-01-02-getrouter-cli-keys-interactive-plan.md +247 -0
- package/docs/plans/2026-01-02-getrouter-cli-keys-output-design.md +31 -0
- package/docs/plans/2026-01-02-getrouter-cli-keys-output-plan.md +187 -0
- package/docs/plans/2026-01-02-getrouter-cli-keys-subscription-design.md +52 -0
- package/docs/plans/2026-01-02-getrouter-cli-keys-subscription-plan.md +306 -0
- package/docs/plans/2026-01-02-getrouter-cli-setup-env-design.md +67 -0
- package/docs/plans/2026-01-02-getrouter-cli-setup-env-plan.md +441 -0
- package/docs/plans/2026-01-02-getrouter-cli-subscription-output-design.md +34 -0
- package/docs/plans/2026-01-02-getrouter-cli-subscription-output-plan.md +157 -0
- package/docs/plans/2026-01-03-bun-migration-plan.md +103 -0
- package/docs/plans/2026-01-03-cli-emoji-output.md +45 -0
- package/docs/plans/2026-01-03-cli-english-output.md +123 -0
- package/docs/plans/2026-01-03-cli-simplify-design.md +62 -0
- package/docs/plans/2026-01-03-cli-simplify-implementation.md +468 -0
- package/docs/plans/2026-01-03-readme-command-descriptions.md +116 -0
- package/docs/plans/2026-01-03-tsdown-migration-plan.md +75 -0
- package/docs/plans/2026-01-04-cli-docs-cleanup-design.md +49 -0
- package/docs/plans/2026-01-04-cli-docs-cleanup-plan.md +126 -0
- package/docs/plans/2026-01-04-codex-multistep-design.md +76 -0
- package/docs/plans/2026-01-04-codex-multistep-plan.md +240 -0
- package/docs/plans/2026-01-04-env-hook-design.md +48 -0
- package/docs/plans/2026-01-04-env-hook-plan.md +173 -0
- package/docs/plans/2026-01-04-models-keys-fuzzy-design.md +75 -0
- package/docs/plans/2026-01-04-models-keys-fuzzy-implementation.md +704 -0
- package/package.json +37 -0
- package/src/.gitkeep +0 -0
- package/src/bin.ts +4 -0
- package/src/cli.ts +12 -0
- package/src/cmd/auth.ts +44 -0
- package/src/cmd/claude.ts +10 -0
- package/src/cmd/codex.ts +119 -0
- package/src/cmd/config-helpers.ts +16 -0
- package/src/cmd/config.ts +31 -0
- package/src/cmd/env.ts +103 -0
- package/src/cmd/index.ts +20 -0
- package/src/cmd/keys.ts +207 -0
- package/src/cmd/models.ts +48 -0
- package/src/cmd/status.ts +106 -0
- package/src/cmd/usages.ts +29 -0
- package/src/core/api/client.ts +79 -0
- package/src/core/auth/device.ts +105 -0
- package/src/core/auth/index.ts +37 -0
- package/src/core/config/fs.ts +13 -0
- package/src/core/config/index.ts +37 -0
- package/src/core/config/paths.ts +5 -0
- package/src/core/config/redact.ts +18 -0
- package/src/core/config/types.ts +23 -0
- package/src/core/http/errors.ts +32 -0
- package/src/core/http/request.ts +41 -0
- package/src/core/http/url.ts +12 -0
- package/src/core/interactive/clipboard.ts +61 -0
- package/src/core/interactive/codex.ts +75 -0
- package/src/core/interactive/fuzzy.ts +64 -0
- package/src/core/interactive/keys.ts +164 -0
- package/src/core/output/table.ts +34 -0
- package/src/core/output/usages.ts +75 -0
- package/src/core/paths.ts +4 -0
- package/src/core/setup/codex.ts +129 -0
- package/src/core/setup/env.ts +220 -0
- package/src/core/usages/aggregate.ts +69 -0
- package/src/generated/router/dashboard/v1/index.ts +1104 -0
- package/src/index.ts +1 -0
- package/tests/.gitkeep +0 -0
- package/tests/auth/device.test.ts +75 -0
- package/tests/auth/status.test.ts +64 -0
- package/tests/cli.test.ts +31 -0
- package/tests/cmd/auth.test.ts +90 -0
- package/tests/cmd/claude.test.ts +132 -0
- package/tests/cmd/codex.test.ts +147 -0
- package/tests/cmd/config-helpers.test.ts +18 -0
- package/tests/cmd/config.test.ts +56 -0
- package/tests/cmd/keys.test.ts +163 -0
- package/tests/cmd/models.test.ts +63 -0
- package/tests/cmd/status.test.ts +82 -0
- package/tests/cmd/usages.test.ts +42 -0
- package/tests/config/fs.test.ts +14 -0
- package/tests/config/index.test.ts +63 -0
- package/tests/config/paths.test.ts +10 -0
- package/tests/config/redact.test.ts +17 -0
- package/tests/config/types.test.ts +10 -0
- package/tests/core/api/client.test.ts +92 -0
- package/tests/core/interactive/clipboard.test.ts +44 -0
- package/tests/core/interactive/codex.test.ts +17 -0
- package/tests/core/interactive/fuzzy.test.ts +30 -0
- package/tests/core/setup/codex.test.ts +38 -0
- package/tests/core/setup/env.test.ts +84 -0
- package/tests/core/usages/aggregate.test.ts +55 -0
- package/tests/http/errors.test.ts +15 -0
- package/tests/http/request.test.ts +82 -0
- package/tests/http/url.test.ts +17 -0
- package/tests/output/table.test.ts +29 -0
- package/tests/output/usages.test.ts +71 -0
- package/tests/paths.test.ts +9 -0
- package/tsconfig.json +13 -0
- package/tsdown.config.ts +5 -0
- package/vitest.config.ts +7 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Models & Keys Fuzzy Selection Design
|
|
2
|
+
|
|
3
|
+
## Goals
|
|
4
|
+
- Provide an interactive, fzf-like fuzzy search for `models` and `keys` when run without `list`.
|
|
5
|
+
- Keep `models list` and `keys list` as non-interactive, script-friendly outputs.
|
|
6
|
+
- Preserve existing CLI style: concise tables, small emoji accents, and predictable error handling.
|
|
7
|
+
- Copy selected model ID to the clipboard when possible (best-effort, cross-platform fallback).
|
|
8
|
+
|
|
9
|
+
## Non-Goals
|
|
10
|
+
- No new dependencies (keep using `prompts`).
|
|
11
|
+
- No multi-column preview panes or advanced fzf features.
|
|
12
|
+
- No server-side filtering for now (no `--filter` on models in this iteration).
|
|
13
|
+
|
|
14
|
+
## Command Behavior
|
|
15
|
+
### models
|
|
16
|
+
- `getrouter models` (TTY): interactive fuzzy search.
|
|
17
|
+
- Prompt: `🔎 Search models`.
|
|
18
|
+
- User selects a model; CLI prints a single-row detail table
|
|
19
|
+
(`ID / NAME / AUTHOR / ENABLED / UPDATED_AT`).
|
|
20
|
+
- CLI attempts to copy `id` to clipboard and prints `📋 Copied model id` on success.
|
|
21
|
+
- `getrouter models` (non-TTY): same as `models list`.
|
|
22
|
+
- `getrouter models list`: non-interactive list table, with header `🧠Models`.
|
|
23
|
+
- Empty results: `😕 No models found`.
|
|
24
|
+
|
|
25
|
+
### keys
|
|
26
|
+
- `getrouter keys` (TTY): interactive fuzzy search.
|
|
27
|
+
- Prompt: `🔎 Search keys`.
|
|
28
|
+
- User selects a key; CLI prints a single-row detail table
|
|
29
|
+
(same columns as current output, with API key redaction).
|
|
30
|
+
- CLI attempts to copy the full API key to clipboard and prints
|
|
31
|
+
`📋 Copied API key` on success.
|
|
32
|
+
- `getrouter keys` (non-TTY): same as `keys list`.
|
|
33
|
+
- `getrouter keys list`: non-interactive list table (existing behavior).
|
|
34
|
+
- Empty results: `😕 No keys found` (reuse existing error path if appropriate).
|
|
35
|
+
|
|
36
|
+
## Data Flow
|
|
37
|
+
- `models list` and `models` read from `ModelService.ListModels`.
|
|
38
|
+
- `keys list` and `keys` read from `ConsumerService.ListConsumers`.
|
|
39
|
+
- Interactive flow always starts from list data, then filters client-side.
|
|
40
|
+
|
|
41
|
+
## Fuzzy Matching
|
|
42
|
+
- Use `prompts` `autocomplete` with a `suggest` callback.
|
|
43
|
+
- Implement a small fuzzy scorer (in `src/core/interactive/fuzzy.ts`) to:
|
|
44
|
+
- Normalize to lowercase.
|
|
45
|
+
- Score by ordered subsequence match (simple, fast).
|
|
46
|
+
- Sort by best score, then by name.
|
|
47
|
+
- The `suggest` callback returns top N items (e.g., 50) for responsiveness.
|
|
48
|
+
|
|
49
|
+
## Clipboard Handling
|
|
50
|
+
- Best-effort copy using platform tools:
|
|
51
|
+
- macOS: `pbcopy`.
|
|
52
|
+
- Linux: `wl-copy`, fallback to `xclip -selection clipboard`.
|
|
53
|
+
- If none available, skip copying and print the model id/API key for manual copy.
|
|
54
|
+
- Implement as `copyToClipboard(text): Promise<boolean>` in `src/core/interactive/clipboard.ts`.
|
|
55
|
+
|
|
56
|
+
## Error Handling
|
|
57
|
+
- If not TTY for interactive commands, fall back to list output.
|
|
58
|
+
- If selection is cancelled, exit quietly with no error.
|
|
59
|
+
- If list API returns empty, show friendly message and exit with code 0.
|
|
60
|
+
|
|
61
|
+
## Testing Plan
|
|
62
|
+
- Add new tests for:
|
|
63
|
+
- `models` (non-TTY) behaves like `models list`.
|
|
64
|
+
- `models` (TTY) uses interactive flow and prints selection output.
|
|
65
|
+
- `keys` (TTY) interactive selection prints detail output.
|
|
66
|
+
- Clipboard copy is attempted and failures do not crash (models + keys).
|
|
67
|
+
- Mock `prompts` to simulate selection and `child_process` for clipboard.
|
|
68
|
+
|
|
69
|
+
## Files To Touch
|
|
70
|
+
- `src/cmd/models.ts` (new list + interactive behavior).
|
|
71
|
+
- `src/cmd/index.ts` (register models commands).
|
|
72
|
+
- `src/core/interactive` (new fuzzy + clipboard helpers).
|
|
73
|
+
- `src/cmd/keys.ts` and `src/core/interactive/keys.ts` (wire fuzzy when no subcommand).
|
|
74
|
+
- `tests/cmd/models.test.ts` (new).
|
|
75
|
+
- Update existing tests for keys if behavior changes.
|