billion-context 0.1.24 → 0.1.26
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/README.md +62 -5
- package/README.zh-CN.md +48 -3
- package/dist/index.js +21148 -375
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -80,7 +80,11 @@ passes it through untouched). Context windows (gpt-5.1-codex=400K,
|
|
|
80
80
|
glm-5.2=1M, claude-opus-4=200K, …) are looked up from models.dev
|
|
81
81
|
automatically.
|
|
82
82
|
|
|
83
|
-
####
|
|
83
|
+
#### A. API-key clients (`/bili/` prefix)
|
|
84
|
+
|
|
85
|
+
Clients you configure with an **API key** (not a login) let you change the
|
|
86
|
+
upstream URL. Just prepend `http://localhost:8787/bili/` to it — that's the
|
|
87
|
+
only change.
|
|
84
88
|
|
|
85
89
|
**OpenCode** — edit `~/.config/opencode/opencode.json`, change the provider's `baseURL`:
|
|
86
90
|
```jsonc
|
|
@@ -90,7 +94,7 @@ automatically.
|
|
|
90
94
|
"baseURL": "http://localhost:8787/bili/https://open.bigmodel.cn/api/coding/paas/v4"
|
|
91
95
|
```
|
|
92
96
|
|
|
93
|
-
**Codex** — edit `~/.codex/config.toml`, change the provider's `base_url`:
|
|
97
|
+
**Codex (API key)** — edit `~/.codex/config.toml`, change the provider's `base_url`:
|
|
94
98
|
```toml
|
|
95
99
|
# before:
|
|
96
100
|
base_url = "https://api.openai.com/v1"
|
|
@@ -106,9 +110,62 @@ base_url = "http://localhost:8787/bili/https://api.openai.com/v1"
|
|
|
106
110
|
"baseUrl": "http://localhost:8787/bili/https://api.anthropic.com"
|
|
107
111
|
```
|
|
108
112
|
|
|
109
|
-
**Other clients (Cursor / Aider / Continue …)** — wherever the
|
|
110
|
-
is configured, prepend `http://localhost:8787/bili/` to it.
|
|
111
|
-
changes.
|
|
113
|
+
**Other API-key clients (Cursor / Aider / Continue …)** — wherever the
|
|
114
|
+
upstream URL is configured, prepend `http://localhost:8787/bili/` to it.
|
|
115
|
+
Nothing else changes.
|
|
116
|
+
|
|
117
|
+
#### B. Login/subscription clients (MITM transparent proxy)
|
|
118
|
+
|
|
119
|
+
Clients you sign **into an account** (ChatGPT Plus/Pro, Claude, ZCode coding
|
|
120
|
+
plan, …) authenticate via **OAuth and hardcode the endpoint** — you can't
|
|
121
|
+
change the baseURL, so the `/bili/` prefix trick doesn't work. These need
|
|
122
|
+
**MITM transparent-proxy mode** instead.
|
|
123
|
+
|
|
124
|
+
Supported login clients:
|
|
125
|
+
|
|
126
|
+
| Client | Login | Endpoint hardcoded | Status |
|
|
127
|
+
|---|---|---|---|
|
|
128
|
+
| **ZCode** | bigmodel coding plan (OAuth) | `open.bigmodel.cn` (builtin provider) | ✅ tested |
|
|
129
|
+
| **Codex** | ChatGPT account (OAuth) | `chatgpt.com/backend-api` | ❓ untested (may not work — needs verification) |
|
|
130
|
+
| **Claude Code** | Claude subscription (OAuth) | `api.anthropic.com` | ❓ untested (may not work — needs verification) |
|
|
131
|
+
|
|
132
|
+
How MITM mode works: the client only offers an **HTTP proxy** setting, so it
|
|
133
|
+
sends `CONNECT <host>:443`; billion-context terminates the TLS locally (with a
|
|
134
|
+
locally-generated root CA), injects compression into the cleartext, then
|
|
135
|
+
re-encrypts and forwards. The OAuth token travels in the client's
|
|
136
|
+
`Authorization` header, which is forwarded untouched — so the subscription
|
|
137
|
+
discount is preserved.
|
|
138
|
+
|
|
139
|
+
MITM is on by default and is scoped to a **whitelist** of model hosts
|
|
140
|
+
(`open.bigmodel.cn`, `api.anthropic.com`, `api.openai.com`, `chatgpt.com`).
|
|
141
|
+
All other HTTPS hosts are blind-tunnelled — billion-context never decrypts
|
|
142
|
+
non-model traffic.
|
|
143
|
+
|
|
144
|
+
**One-time setup (trust the root CA in the client):**
|
|
145
|
+
|
|
146
|
+
1. Start the proxy once to generate the root CA:
|
|
147
|
+
```bash
|
|
148
|
+
bili start
|
|
149
|
+
ls ~/.local/share/billion-context/ca/root-ca.pem # exists now
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
2. In the client's **Settings → Network / Proxy** set:
|
|
153
|
+
- **HTTP Proxy**: `http://127.0.0.1:8787`
|
|
154
|
+
- **Proxy CA certificate path**: `~/.local/share/billion-context/ca/root-ca.pem`
|
|
155
|
+
- (optional) **No-proxy list**: `localhost,127.0.0.1`
|
|
156
|
+
- (For ZCode specifically: **Settings → Network**. For Codex/Claude Code:
|
|
157
|
+
set the `HTTPS_PROXY` env var and `NODE_EXTRA_CA_CERTS` to the CA path.)
|
|
158
|
+
|
|
159
|
+
3. Restart the client. Its model traffic now flows through billion-context
|
|
160
|
+
with compression injected. Send a message and check the proxy log
|
|
161
|
+
(`~/.local/state/billion-context/bili.log`) for
|
|
162
|
+
`mitm <host>:443 tunnel established`.
|
|
163
|
+
|
|
164
|
+
> The root CA is generated locally and lives only on this machine; it is
|
|
165
|
+
> **not** a system-wide install. Only the client you configure (via the
|
|
166
|
+
> CA-path setting, which it feeds to Node as `NODE_EXTRA_CA_CERTS`) trusts it,
|
|
167
|
+
> so no other app is affected. Deleting the CA files and restarting the proxy
|
|
168
|
+
> regenerates them.
|
|
112
169
|
|
|
113
170
|
### Option B — Manual config file & context windows
|
|
114
171
|
|
package/README.zh-CN.md
CHANGED
|
@@ -66,7 +66,9 @@ bili
|
|
|
66
66
|
|
|
67
67
|
就这样 —— 真实 API key 照常填在客户端配置里(proxy 原样透传)。context 窗口(gpt-5.1-codex=400K、glm-5.2=1M、claude-opus-4=200K ……)自动从 models.dev 查询。
|
|
68
68
|
|
|
69
|
-
####
|
|
69
|
+
#### A. API-key 客户端(`/bili/` 前缀)
|
|
70
|
+
|
|
71
|
+
用 **API key** 配置(不是登录账号)的客户端允许你改上游 URL。只需在前面加 `http://localhost:8787/bili/`,其他都不用改。
|
|
70
72
|
|
|
71
73
|
**OpenCode** —— 编辑 `~/.config/opencode/opencode.json`,改 provider 的 `baseURL`:
|
|
72
74
|
```jsonc
|
|
@@ -76,7 +78,7 @@ bili
|
|
|
76
78
|
"baseURL": "http://localhost:8787/bili/https://open.bigmodel.cn/api/coding/paas/v4"
|
|
77
79
|
```
|
|
78
80
|
|
|
79
|
-
**Codex** —— 编辑 `~/.codex/config.toml`,改 provider 的 `base_url`:
|
|
81
|
+
**Codex(API key 模式)** —— 编辑 `~/.codex/config.toml`,改 provider 的 `base_url`:
|
|
80
82
|
```toml
|
|
81
83
|
# 之前:
|
|
82
84
|
base_url = "https://api.openai.com/v1"
|
|
@@ -92,8 +94,51 @@ base_url = "http://localhost:8787/bili/https://api.openai.com/v1"
|
|
|
92
94
|
"baseUrl": "http://localhost:8787/bili/https://api.anthropic.com"
|
|
93
95
|
```
|
|
94
96
|
|
|
95
|
-
|
|
97
|
+
**其他 API-key 客户端(Cursor / Aider / Continue ……)** —— 只要配置了上游 URL,前面加 `http://localhost:8787/bili/` 就行,其他都不用改。
|
|
98
|
+
|
|
99
|
+
#### B. 登录/订阅客户端(MITM 透明代理)
|
|
100
|
+
|
|
101
|
+
需要 **登录账号**的客户端(ChatGPT Plus/Pro、Claude、ZCode coding plan
|
|
102
|
+
……)通过 **OAuth 认证,且硬编码了端点**——你改不了 baseURL,所以 `/bili/`
|
|
103
|
+
前缀方式对它们无效。这类客户端要用 **MITM 透明代理模式**。
|
|
96
104
|
|
|
105
|
+
支持的登录客户端:
|
|
106
|
+
|
|
107
|
+
| 客户端 | 登录方式 | 硬编码端点 | 状态 |
|
|
108
|
+
|---|---|---|---|
|
|
109
|
+
| **ZCode** | 智谱 coding plan(OAuth) | `open.bigmodel.cn`(内置 provider) | ✅ 已测试 |
|
|
110
|
+
| **Codex** | ChatGPT 账号(OAuth) | `chatgpt.com/backend-api` | ❓ 未测试(可能不支持,需验证) |
|
|
111
|
+
| **Claude Code** | Claude 订阅(OAuth) | `api.anthropic.com` | ❓ 未测试(可能不支持,需验证) |
|
|
112
|
+
|
|
113
|
+
MITM 模式原理:这类客户端只提供 **HTTP 代理**设置,所以它发送
|
|
114
|
+
`CONNECT <域名>:443`;billion-context 在本地用自生成的根 CA 终止 TLS,在明文里注入压缩,再重新加密转发。OAuth token 随客户端的
|
|
115
|
+
`Authorization` 头原样转发(我们不动它)——订阅折扣保留。
|
|
116
|
+
|
|
117
|
+
MITM 默认开启,且只对一份 **白名单**中的模型域名(`open.bigmodel.cn`、
|
|
118
|
+
`api.anthropic.com`、`api.openai.com`、`chatgpt.com`)生效。所有其他 HTTPS
|
|
119
|
+
域名都是盲隧道(billion-context 从不解密非模型流量)。
|
|
120
|
+
|
|
121
|
+
**一次性设置(在客户端里信任根 CA):**
|
|
122
|
+
|
|
123
|
+
1. 启动一次 proxy 以生成根 CA:
|
|
124
|
+
```bash
|
|
125
|
+
bili start
|
|
126
|
+
ls ~/.local/share/billion-context/ca/root-ca.pem # 现在存在了
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
2. 在客户端的 **设置 → 网络/代理** 里填:
|
|
130
|
+
- **HTTP 代理**:`http://127.0.0.1:8787`
|
|
131
|
+
- **代理 CA 证书路径**:`~/.local/share/billion-context/ca/root-ca.pem`
|
|
132
|
+
- (可选)**不走代理列表**:`localhost,127.0.0.1`
|
|
133
|
+
- (ZCode 具体位置:**设置 → 网络**。Codex/Claude Code:设 `HTTPS_PROXY`
|
|
134
|
+
环境变量 + `NODE_EXTRA_CA_CERTS` 指向 CA 路径。)
|
|
135
|
+
|
|
136
|
+
3. 重启客户端。它的模型流量现在会经过 billion-context 并注入压缩。发一条消息,看 proxy 日志(`~/.local/state/billion-context/bili.log`)应出现
|
|
137
|
+
`mitm <域名>:443 tunnel established`。
|
|
138
|
+
|
|
139
|
+
> 根 CA 是本地生成的、只存在本机,**不是**系统级安装。只有你配置的那个
|
|
140
|
+
> 客户端(通过 CA 路径设置,它会把该路径作为 `NODE_EXTRA_CA_CERTS` 喂给
|
|
141
|
+
> Node)信任它,其他应用不受影响。删除 CA 文件并重启 proxy 会重新生成。
|
|
97
142
|
|
|
98
143
|
### 方式 B 手动配置文件&设置上下文大小
|
|
99
144
|
|