billion-context 0.1.26 → 0.1.27
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 +66 -0
- package/README.zh-CN.md +53 -0
- package/dist/index.js +26105 -408
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -167,6 +167,12 @@ non-model traffic.
|
|
|
167
167
|
> so no other app is affected. Deleting the CA files and restarting the proxy
|
|
168
168
|
> regenerates them.
|
|
169
169
|
|
|
170
|
+
**Routing a login client through its own proxy (firewall/GFW).** A login
|
|
171
|
+
client (ZCode) and an API-key client can both hit the same host
|
|
172
|
+
(`open.bigmodel.cn`). To give the login client its OWN upstream proxy without
|
|
173
|
+
affecting API-key clients, use the `mitm://` scheme key — see
|
|
174
|
+
[Upstream proxy (MITM vs `/bili/`)](#upstream-proxy-firewall--gfw).
|
|
175
|
+
|
|
170
176
|
### Option B — Manual config file & context windows
|
|
171
177
|
|
|
172
178
|
Open `~/.config/billion-context/billion-context.json` and edit the `providers`
|
|
@@ -344,6 +350,7 @@ The config file is a single JSON object. Example:
|
|
|
344
350
|
| `passthrough` | `false` | Forward without compression (same as `ACP_PASSTHROUGH=1`) |
|
|
345
351
|
| `providers` | *(none)* | Per-URL context overrides — see below |
|
|
346
352
|
| `compress` | *(see defaults)* | `{ injectTool, injectNudge }` |
|
|
353
|
+
| `proxy` | *(none)* | Upstream HTTP proxy for the proxy's OWN outbound connections to model providers (`http://host:port`). Per-URL `proxy` overrides this. See [Upstream proxy](#upstream-proxy-firewall--gfw). |
|
|
347
354
|
|
|
348
355
|
> **Choosing a `host`** (IPv6 / containers): the default `127.0.0.1` is
|
|
349
356
|
> IPv4-only and loopback-only. Use `--host ::` (or `"host": "::"`) to listen
|
|
@@ -401,6 +408,65 @@ registry, then the built-in prefix table.
|
|
|
401
408
|
**API keys are never stored in the proxy** — whatever key the agent sends is
|
|
402
409
|
passed through untouched to the upstream.
|
|
403
410
|
|
|
411
|
+
### Upstream proxy (firewall / GFW)
|
|
412
|
+
|
|
413
|
+
If the proxy's own outbound connections to a model provider are blocked
|
|
414
|
+
(e.g. `api.openai.com` from inside the GFW), configure an **upstream proxy**
|
|
415
|
+
(the local v2rayA / clash HTTP port) so the proxy reaches the provider:
|
|
416
|
+
|
|
417
|
+
```jsonc
|
|
418
|
+
{
|
|
419
|
+
// Global default: ALL providers route through this proxy
|
|
420
|
+
"proxy": "http://127.0.0.1:20172",
|
|
421
|
+
"providers": {
|
|
422
|
+
"https://api.openai.com/v1": {
|
|
423
|
+
// Per-URL overrides global (use a different proxy for this host)
|
|
424
|
+
"proxy": "http://127.0.0.1:20173",
|
|
425
|
+
"models": { "gpt-5": { "context": 400000 } }
|
|
426
|
+
},
|
|
427
|
+
"https://open.bigmodel.cn/api/anthropic": {
|
|
428
|
+
// Empty string = explicitly DIRECT, overriding the global proxy
|
|
429
|
+
"proxy": "",
|
|
430
|
+
"models": { "glm-5.2": { "context": 1000000 } }
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
Rules:
|
|
437
|
+
- **Global `proxy`** (top level) applies to every provider's outbound.
|
|
438
|
+
- **Per-URL `proxy`** overrides the global for that host.
|
|
439
|
+
- Empty string `""` means **explicitly direct** (override-and-disable).
|
|
440
|
+
- Neither set = direct connect.
|
|
441
|
+
- Only HTTP proxies (`http://host:port`). SOCKS5 is not supported yet.
|
|
442
|
+
- Both outbound paths are covered: `/bili/` path-mode (fetch) AND MITM CONNECT
|
|
443
|
+
tunnels (the proxy's connection to the real upstream goes through the HTTP
|
|
444
|
+
CONNECT proxy).
|
|
445
|
+
|
|
446
|
+
Env override: `BILI_UPSTREAM_PROXY=http://127.0.0.1:20172` (same as global
|
|
447
|
+
`proxy`; config file wins over env if both set).
|
|
448
|
+
|
|
449
|
+
**MITM vs `/bili/` — distinguishing the key scheme.** A login client
|
|
450
|
+
(ZCode via MITM) and an API-key client can both hit the same host
|
|
451
|
+
(`open.bigmodel.cn`). To let their config differ, MITM traffic uses a
|
|
452
|
+
`mitm://` scheme in the lookup key while `/bili/` traffic uses the real
|
|
453
|
+
`https://`:
|
|
454
|
+
|
|
455
|
+
| Client | Lookup key example |
|
|
456
|
+
|---|---|
|
|
457
|
+
| ZCode (MITM, login) | `mitm://open.bigmodel.cn` |
|
|
458
|
+
| API-key client (`/bili/`) | `https://open.bigmodel.cn/api/anthropic` |
|
|
459
|
+
|
|
460
|
+
So you can give ZCode its own proxy without affecting API-key clients:
|
|
461
|
+
```jsonc
|
|
462
|
+
{
|
|
463
|
+
"providers": {
|
|
464
|
+
"mitm://open.bigmodel.cn": { "proxy": "http://127.0.0.1:20173" },
|
|
465
|
+
"https://open.bigmodel.cn/api/anthropic": { "proxy": "http://127.0.0.1:20172" }
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
```
|
|
469
|
+
|
|
404
470
|
## How sessions work
|
|
405
471
|
|
|
406
472
|
The proxy needs a stable per-conversation identifier to isolate compression
|
package/README.zh-CN.md
CHANGED
|
@@ -140,6 +140,8 @@ MITM 默认开启,且只对一份 **白名单**中的模型域名(`open.bigmodel
|
|
|
140
140
|
> 客户端(通过 CA 路径设置,它会把该路径作为 `NODE_EXTRA_CA_CERTS` 喂给
|
|
141
141
|
> Node)信任它,其他应用不受影响。删除 CA 文件并重启 proxy 会重新生成。
|
|
142
142
|
|
|
143
|
+
**给登录客户端单独配代理(防火墙/GFW)。** 登录客户端(ZCode)和 API-key 客户端可能连同一个域名(`open.bigmodel.cn`)。要给登录客户端配**专属上游代理**而不影响 API-key 客户端,用 `mitm://` scheme 键 —— 见[上游代理(MITM 与 `/bili/`)](#上游代理防火墙gfw)。
|
|
144
|
+
|
|
143
145
|
### 方式 B 手动配置文件&设置上下文大小
|
|
144
146
|
|
|
145
147
|
打开 `~/.config/billion-context/billion-context.json`,编辑 `providers` 块。
|
|
@@ -298,6 +300,7 @@ bili --no-auto-update # 本次启动禁用自动更新
|
|
|
298
300
|
| `passthrough` | `false` | 不压缩直接转发(等同 `ACP_PASSTHROUGH=1`) |
|
|
299
301
|
| `providers` | *(无)* | 按 URL 的 context 覆盖 —— 见下文 |
|
|
300
302
|
| `compress` | *(见默认值)* | `{ injectTool, injectNudge }` |
|
|
303
|
+
| `proxy` | *(无)* | 代理自身访问模型提供商时走的上游 HTTP 代理(`http://host:port`)。按 URL 的 `proxy` 会覆盖它。见[上游代理](#上游代理防火墙gfw)。 |
|
|
301
304
|
|
|
302
305
|
> **选择 `host`**(IPv6 / 容器):默认 `127.0.0.1` 只听 IPv4 且仅
|
|
303
306
|
> loopback。用 `--host ::`(或 `"host": "::"`)可同时听 IPv4 和 IPv6
|
|
@@ -340,6 +343,56 @@ key 就是客户端写在 `/bili/` 后面的那个字符串:
|
|
|
340
343
|
|
|
341
344
|
**API key 永远不存进代理** —— 助手发什么 key,原样透传给上游。
|
|
342
345
|
|
|
346
|
+
### 上游代理(防火墙 / GFW)
|
|
347
|
+
|
|
348
|
+
如果代理自身访问模型提供商的连接被墙(比如 GFW 内访问 `api.openai.com`),配置一个**上游代理**(本地 v2rayA / clash 的 HTTP 端口),让代理能连到提供商:
|
|
349
|
+
|
|
350
|
+
```jsonc
|
|
351
|
+
{
|
|
352
|
+
// 全局默认:所有提供商的出站都走这个代理
|
|
353
|
+
"proxy": "http://127.0.0.1:20172",
|
|
354
|
+
"providers": {
|
|
355
|
+
"https://api.openai.com/v1": {
|
|
356
|
+
// 按 URL 覆盖全局(给这个域名用另一个代理)
|
|
357
|
+
"proxy": "http://127.0.0.1:20173",
|
|
358
|
+
"models": { "gpt-5": { "context": 400000 } }
|
|
359
|
+
},
|
|
360
|
+
"https://open.bigmodel.cn/api/anthropic": {
|
|
361
|
+
// 空字符串 = 明确直连,覆盖全局代理
|
|
362
|
+
"proxy": "",
|
|
363
|
+
"models": { "glm-5.2": { "context": 1000000 } }
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
规则:
|
|
370
|
+
- **全局 `proxy`**(顶层)对所有提供商的出站生效。
|
|
371
|
+
- **按 URL 的 `proxy`** 覆盖该域名的全局设置。
|
|
372
|
+
- 空字符串 `""` 表示**明确直连**(覆盖并禁用)。
|
|
373
|
+
- 都不配 = 直连。
|
|
374
|
+
- 只支持 HTTP 代理(`http://host:port`)。SOCKS5 暂不支持。
|
|
375
|
+
- 两条出站路径都覆盖:`/bili/` 路径模式(fetch)和 MITM CONNECT 隧道(代理连接真实上游的链路走 HTTP CONNECT 代理)。
|
|
376
|
+
|
|
377
|
+
环境变量覆盖:`BILI_UPSTREAM_PROXY=http://127.0.0.1:20172`(等同全局 `proxy`;两者都设时配置文件优先)。
|
|
378
|
+
|
|
379
|
+
**MITM 与 `/bili/` —— 用 scheme 区分。** 登录客户端(ZCode 走 MITM)和 API-key 客户端可能连同一个域名(`open.bigmodel.cn`)。为了让它们的配置能区分,MITM 流量在查找键里用 `mitm://` scheme,`/bili/` 流量用真实的 `https://`:
|
|
380
|
+
|
|
381
|
+
| 客户端 | 查找键示例 |
|
|
382
|
+
|---|---|
|
|
383
|
+
| ZCode(MITM,登录态)| `mitm://open.bigmodel.cn` |
|
|
384
|
+
| API-key 客户端(`/bili/`)| `https://open.bigmodel.cn/api/anthropic` |
|
|
385
|
+
|
|
386
|
+
所以你可以给 ZCode 单独配代理,不影响 API-key 客户端:
|
|
387
|
+
```jsonc
|
|
388
|
+
{
|
|
389
|
+
"providers": {
|
|
390
|
+
"mitm://open.bigmodel.cn": { "proxy": "http://127.0.0.1:20173" },
|
|
391
|
+
"https://open.bigmodel.cn/api/anthropic": { "proxy": "http://127.0.0.1:20172" }
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
```
|
|
395
|
+
|
|
343
396
|
## 会话机制
|
|
344
397
|
|
|
345
398
|
代理需要一个稳定的、按会话标识的 ID,以便在多个用户/账号并发时隔离压缩状态。它从四个维度推导一个(见 `src/session-id.ts`):**协议 × 上游 origin × API key × 会话**。前三个防止跨账号 / 跨 provider 串数据;会话维度来自客户端发送的内容。
|