llm-api-gateway-cli 1.0.4 → 1.0.5

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.en.md +232 -0
  2. package/README.md +3 -0
  3. package/package.json +2 -1
package/README.en.md ADDED
@@ -0,0 +1,232 @@
1
+ # LLM API Gateway CLI — English entry
2
+
3
+ > **Language:** English (this page) · [中文(权威全文)](README.md)
4
+ >
5
+ > [`README.md`](README.md) is the authoritative, always-current document (Chinese, far more detail:
6
+ > every flag, every API route, Docker publishing, troubleshooting).
7
+ > This page is the English entry point: what the tool is, how to install it, and how to run it.
8
+
9
+ A local toolbox for an **OpenAI-compatible LLM gateway** (default `http://127.0.0.1:9000`).
10
+ It gives you five ways to talk to the gateway from your own machine, plus a task mode where the
11
+ model actually reads and writes files in a directory you pick:
12
+
13
+ | Mode | Entry point | What it does | Extra deps |
14
+ | --- | --- | --- | --- |
15
+ | 1 | `gateway-openai` (`cli-openai.js`) | OpenAI-compatible chat against `/v1/chat/completions` | `openai` SDK |
16
+ | 2 | `gateway-anthropic` (`cli-anthropic.js`) | Anthropic-compatible calls against `/v1/messages` | `@anthropic-ai/sdk` |
17
+ | 3 | `gateway-claude-code` (`cli-claude-code.js`) | Pipes through a locally installed `claude` CLI | local `claude` |
18
+ | 4 + 5 | `gateway-web` (`server.js`) · `gateway-task` (`task-server.js`) | Local Web UI: chat, task mode and manual in one page | none |
19
+ | 6 | `gateway-agent` (`cli-agent.js`) | Native agent CLI with tool calls (recommended) | none |
20
+
21
+ Modes 4, 5 and 6 are plain Node.js with no additional dependencies — the two SDKs above are only
22
+ needed by modes 1 and 2. Modes 4 and 5 run on **one port** (`3100`) as one service.
23
+
24
+ ## Requirements
25
+
26
+ - **Node.js >= 18** (`node -v`). The installers check this and stop with a clear message; they never
27
+ install a runtime for you.
28
+ - A gateway you can reach, plus an API key for it. There is no bundled model — this is a client.
29
+
30
+ ## Install
31
+
32
+ Three routes, all producing the same artifact and the same commands.
33
+
34
+ ### A. One-liner script (macOS / Linux / WSL)
35
+
36
+ ```bash
37
+ # Pin a release tag (recommended: the tag never moves)
38
+ curl -fsSL https://raw.githubusercontent.com/boonya-hrgk/llm-api-gateway-cli/<version>/scripts/install.sh | bash
39
+
40
+ # Or track the newest script from main (script and release contract may drift)
41
+ curl -fsSL https://raw.githubusercontent.com/boonya-hrgk/llm-api-gateway-cli/main/scripts/install.sh | bash
42
+
43
+ # Passing arguments through a pipe needs -s --
44
+ curl -fsSL https://raw.githubusercontent.com/boonya-hrgk/llm-api-gateway-cli/<version>/scripts/install.sh \
45
+ | bash -s -- --version v1.0.0 --prefix "$HOME/.llm-api-gateway"
46
+ ```
47
+
48
+ ### B. One-liner script (Windows PowerShell 5.1 / 7)
49
+
50
+ ```powershell
51
+ irm https://raw.githubusercontent.com/boonya-hrgk/llm-api-gateway-cli/<version>/scripts/install.ps1 | iex
52
+
53
+ # Passing arguments needs the scriptblock form
54
+ & ([scriptblock]::Create((irm https://raw.githubusercontent.com/boonya-hrgk/llm-api-gateway-cli/<version>/scripts/install.ps1))) -Version v1.0.0 -DryRun
55
+ ```
56
+
57
+ ### C. npm
58
+
59
+ ```bash
60
+ npm install -g llm-api-gateway-cli
61
+ ```
62
+
63
+ The installers put everything under `~/.llm-api-gateway` (Windows: `$HOME\.llm-api-gateway`), add the
64
+ bin directory to your `PATH`, are idempotent, and need no admin rights. Useful flags:
65
+ `--prefix`, `--no-modify-path`, `--dry-run`, `--force`, `--base` (mirror).
66
+
67
+ ### Already have the sources
68
+
69
+ ```bash
70
+ git clone https://github.com/boonya-hrgk/llm-api-gateway-cli
71
+ cd llm-api-gateway-cli
72
+ npm install
73
+ npm link # symlink, so edits take effect without reinstalling
74
+ ```
75
+
76
+ You can also skip installing entirely inside the repo: `node cli-agent.js`, `node server.js`.
77
+
78
+ ## First-time setup
79
+
80
+ You do **not** need to hand-write `.env` any more. Either run the guided setup:
81
+
82
+ ```bash
83
+ gateway-agent setup # asks for gateway URL, then the key (hidden input)
84
+ gateway-agent setup --base-url http://127.0.0.1:9000 --key sk-xxx # non-interactive
85
+ ```
86
+
87
+ or set the key from the Web UI (`Settings -> gateway key`) after starting the service — the server
88
+ **starts without a key on purpose**, so the page is reachable and you have somewhere to paste it.
89
+
90
+ The key is written to `~/.llm-api-gateway-cli/credentials.json` (owner-readable only) and is
91
+ **never stored in `config.json`**. Sources are resolved in this order, first hit wins:
92
+
93
+ 1. `--key sk-xxx` on the command line
94
+ 2. environment variables: `GATEWAY_KEY`, `SK`, `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `ANTHROPIC_AUTH_TOKEN`
95
+ 3. `credentials.json` (what the UI / `config set key` writes)
96
+ 4. `.env` in the install directory, then in the current working directory
97
+
98
+ When the key comes from the environment, `credentials.json` is ignored — the startup banner always
99
+ prints which source is in effect, so you never have to guess.
100
+
101
+ ```bash
102
+ gateway-agent config set baseUrl http://127.0.0.1:9000
103
+ gateway-agent config set model qwen3:8b
104
+ gateway-agent config list # every value and where it comes from
105
+ ```
106
+
107
+ ## Quick start
108
+
109
+ ### Command line
110
+
111
+ ```bash
112
+ gateway-agent -p "explain this stack trace" # one-shot
113
+ gateway-agent -i # interactive REPL
114
+ gateway-agent # bare command: asks chat/task, CLI/web
115
+ ```
116
+
117
+ Bare `llm-api-gateway-cli` (or `gateway-agent`) with no arguments asks two questions — what to do
118
+ (chat / task) and where to run it (terminal / Web UI) — instead of silently picking one. Passing
119
+ `-p`, `-i`, or piping stdin skips the menu.
120
+
121
+ Slash commands are available inside the REPL (`/help` lists them; the CLI REPL has 10 of them).
122
+
123
+ ### Web UI — one page, three tabs
124
+
125
+ ```bash
126
+ gateway-web # or: node server.js
127
+ ```
128
+
129
+ | Page | URL | Notes |
130
+ | --- | --- | --- |
131
+ | Tab shell (recommended entry) | `http://127.0.0.1:3100/` | Chat / Task / Manual switch in one browser tab |
132
+ | Chat panel | `http://127.0.0.1:3100/chat` | Pure conversation, no file system access |
133
+ | Task panel | `http://127.0.0.1:3100/task` | Pick a directory, the model really reads/writes it |
134
+ | Manual | `http://127.0.0.1:3100/manual` | Operation manual (Chinese) generated from the live command tables |
135
+
136
+ The shell owns the single top bar (tabs, per-panel actions, theme, reload); panels are loaded
137
+ lazily on first activation and keep their state when you switch away. `Alt+1/2/3` switches tabs.
138
+ Each panel also opens standalone, which is what external systems embed.
139
+
140
+ Useful flags: `--port`, `--host`, `--store <dir>`, `--mode manual|auto|plan`, `--max-steps`,
141
+ `--allow-bash`, `--allow-remote-fs`, `--verbose` (`node server.js --help`).
142
+
143
+ ### Task mode in one minute
144
+
145
+ 1. Open the Task tab and pick a **working directory** — the model's file tools are confined to it.
146
+ 2. Describe the job, press `Enter`. The model lists directories, reads files and searches content.
147
+ 3. In **manual** mode every write shows an approval card first; click approve/reject (or `/approve`,
148
+ `/reject`). **auto** executes writes directly. **plan** gives the model read-only tools, writes a
149
+ plan document into `docs/` inside your working directory, and waits for you to confirm.
150
+ 4. `/stop` or the Stop button cancels the current run; other tasks keep going in the background.
151
+
152
+ Tools the model can use: `list_dir`, `read_file`, `search_files`, `glob`, `grep`, `write_file`,
153
+ `apply_patch`. `bash` exists but is **off by default** — enable it with `--allow-bash` (dangerous:
154
+ in auto mode commands are not confirmed one by one). The task page has 14 slash commands; the manual
155
+ page lists all of them side by side with the CLI.
156
+
157
+ Task data is stored on disk by the server (not in the browser): `<data dir>/tasks/<id>.json` plus a
158
+ model-side session per task. Default retention is a sliding **15 days / at most 20 tasks**.
159
+
160
+ ## Configuration and storage
161
+
162
+ | Env var | Purpose |
163
+ | --- | --- |
164
+ | `GATEWAY_BASE_URL` | Gateway base URL (default `http://127.0.0.1:9000`) |
165
+ | `GATEWAY_MODEL` | Default model (built-in default `qwen3:8b`) |
166
+ | `GATEWAY_KEY` / `SK` | Gateway API key |
167
+ | `WEB_PORT` / `TASK_WEB_PORT` | Web UI port (default `3100`) |
168
+ | `TASK_MODE` | Default approval mode for new tasks: `manual` / `auto` / `plan` |
169
+ | `TASK_MAX_STEPS` | Max model turns per task |
170
+ | `TASK_STORE_DIR` | Where task records live |
171
+ | `TASK_HISTORY_MAX_CHARS` | History budget sent to the model |
172
+ | `TASK_SESSION_MAX_BYTES` | Cap for one task's model-side session file |
173
+ | `LLM_GATEWAY_DATA_DIR` | Move the whole data root (config + credentials + tasks) |
174
+
175
+ | File | Contents |
176
+ | --- | --- |
177
+ | `~/.llm-api-gateway-cli/config.json` | Settings (never the key) |
178
+ | `~/.llm-api-gateway-cli/credentials.json` | The key, owner-readable only |
179
+ | `~/.llm-api-gateway-cli/tasks/` | Task records + per-task sessions |
180
+
181
+ Precedence everywhere is **command-line flag > environment variable > `.env` > `config.json` >
182
+ built-in default**, and every surface (CLI, REPL, Web UI) reads and writes the same files.
183
+
184
+ ## Embedding and theming
185
+
186
+ Any page can be embedded in another system, and you can hand it the host's background colour so it
187
+ does not look pasted on:
188
+
189
+ ```
190
+ http://127.0.0.1:3100/task?bg=%23f0f4ff light host background
191
+ http://127.0.0.1:3100/task?bg=%23111a2b dark host background
192
+ http://127.0.0.1:3100/task?bg=none back to the page's own palette
193
+ ```
194
+
195
+ The theme is derived from that one colour (panels, borders, text and accent all follow), and the
196
+ theme switcher hides itself because the host now decides.
197
+
198
+ ## Docker
199
+
200
+ A `Dockerfile`, `docker-compose.yml` and `docker.ps1` helper are included: one image containing the
201
+ Web UI, with your project mounted as the agent's working directory and task history on a named
202
+ volume. See the [Chinese README](README.md#docker-容器化部署) for the full walkthrough
203
+ (`.\docker.ps1 up`, publishing to ACR / Docker Hub, troubleshooting).
204
+
205
+ ## Security notes
206
+
207
+ - The API key stays on the server: the browser never receives it (the config endpoint returns a mask
208
+ and its source only).
209
+ - Directory browsing, task records and the settings API are **only served when the service is bound
210
+ to loopback**. Binding `0.0.0.0` requires the explicit `--allow-remote-fs` flag.
211
+ - The agent's sandbox is the working directory you picked: path traversal, absolute paths and
212
+ symlink escapes are rejected, and `bash` is off unless you pass `--allow-bash`.
213
+
214
+ ## Tests
215
+
216
+ ```bash
217
+ npm test # offline suite (no gateway needed)
218
+ npm run test:all # offline + tests that call a real gateway on 127.0.0.1:9000
219
+ ```
220
+
221
+ ## Where to read more
222
+
223
+ - **`/manual`** in the running Web UI — install, first-time setup, task workflow, every slash command
224
+ on all three surfaces (its command tables are generated from `lib/commands.js` and
225
+ `public/task-slash.js`, so they cannot go stale).
226
+ - [`README.md`](README.md) — the authoritative Chinese document: all flags, every API route, storage
227
+ internals, Docker publishing, FAQ.
228
+ - [`docs/`](docs/) — iteration plans and release steps (Chinese).
229
+
230
+ ## License
231
+
232
+ MIT
package/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # LLM API Gateway CLI 编程工具
2
2
 
3
+ > 🌐 **English entry:** [`README.en.md`](README.en.md) —— 英文入口(是什么 / 怎么装 / 怎么跑)。
4
+ > 本页是**权威全文**(中文,最全):所有参数、全部接口、存储内部细节、Docker 发布与排错。
5
+
3
6
  验证 `llm-api-gateway`(`http://127.0.0.1:9000`)除了 Web 对话页 / SDK 之外,**CLI 方式同样可用**。多个脚本覆盖多种接入方言,其中**原生 Agent(`cli-agent.js`)是终端里干活的推荐方式** —— 自带工具循环,无需安装 Claude Code。
4
7
 
5
8
  | 脚本 | 模式 | 走网关的端点 | 依赖 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "llm-api-gateway-cli",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "CLI 测试工具:验证 LLM API Gateway(http://127.0.0.1:9000)的 OpenAI / Anthropic / 原生 Agent / Claude Code 多种接入方式",
5
5
  "type": "module",
6
6
  "bin": {
@@ -43,6 +43,7 @@
43
43
  "cli-claude-code.js",
44
44
  "server.js",
45
45
  "task-server.js",
46
+ "README.en.md",
46
47
  "lib/",
47
48
  "!lib/.tasks/",
48
49
  "public/",