billion-context 0.0.1 → 0.1.1
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/LICENSE +21 -0
- package/README.md +153 -0
- package/dist/index.js +1490 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ranxianglei
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# billion-context
|
|
2
|
+
|
|
3
|
+
Universal context-compression proxy for AI coding agents.
|
|
4
|
+
|
|
5
|
+
`billion-context` sits between **any** agent and its model API, rewriting Anthropic/OpenAI streams with [acp-kernel](https://github.com/ranxianglei/acp-kernel) compression. Any agent that can set a base URL works out of the box — **zero per-agent adapter code**.
|
|
6
|
+
|
|
7
|
+
## Why
|
|
8
|
+
|
|
9
|
+
Long coding sessions blow up context. Each provider charges per token, and once you pass the context window the session degrades or dies. `billion-context` compresses consumed conversation into layered summaries so you can run a single session for days — billions of tokens through one context window.
|
|
10
|
+
|
|
11
|
+
Unlike a host's built-in summarizer, compression here is **incremental, reversible, and prefix-cache friendly**: summaries are written in small ranges, can be decompressed on demand, and the cache prefix stays intact.
|
|
12
|
+
|
|
13
|
+
## How it works
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
Agent (Claude Code / Codex / Cursor / Aider ...)
|
|
17
|
+
│ you point the agent's base URL at the proxy
|
|
18
|
+
▼
|
|
19
|
+
┌─────────────────┐
|
|
20
|
+
│ billion-context│ 1. parse the request (Anthropic or OpenAI shape)
|
|
21
|
+
│ proxy │ 2. run acp-kernel compression on the conversation
|
|
22
|
+
│ │ 3. inject a `compress` tool + compression philosophy
|
|
23
|
+
│ │ 4. forward to the real model API
|
|
24
|
+
│ │ 5. rewrite the streaming response
|
|
25
|
+
└─────────────────┘
|
|
26
|
+
│
|
|
27
|
+
▼
|
|
28
|
+
real model API (Anthropic / OpenAI / compatible)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The proxy injects four context-management tools (`compress`, `decompress`, `search_context`, `acp_status`) into the conversation. The model calls `compress` when the conversation grows, and the proxy executes it server-side — the compressed ranges are folded into the conversation history before the next turn.
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install -g billion-context
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
### Single provider
|
|
42
|
+
|
|
43
|
+
Start the proxy pointing at one upstream (simplest):
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
UPSTREAM=https://api.anthropic.com bili-proxy
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Then point your agent at the proxy.
|
|
50
|
+
|
|
51
|
+
### Multiple providers (recommended)
|
|
52
|
+
|
|
53
|
+
See [Configuration](#configuration) below for how to route to multiple
|
|
54
|
+
providers by URL path — most users will want this.
|
|
55
|
+
|
|
56
|
+
### Claude Code
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
export ANTHROPIC_BASE_URL=http://localhost:8787
|
|
60
|
+
export ANTHROPIC_API_KEY=sk-ant-...
|
|
61
|
+
claude
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Codex / any OpenAI-compatible agent
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
export OPENAI_BASE_URL=http://localhost:8787/v1
|
|
68
|
+
export OPENAI_API_KEY=sk-...
|
|
69
|
+
codex
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Cursor / Aider / others
|
|
73
|
+
|
|
74
|
+
Set the base URL / API endpoint to `http://localhost:8787` (Anthropic) or `http://localhost:8787/v1` (OpenAI) in the agent's settings.
|
|
75
|
+
|
|
76
|
+
## Configuration
|
|
77
|
+
|
|
78
|
+
All config is via environment variables:
|
|
79
|
+
|
|
80
|
+
| Variable | Default | Description |
|
|
81
|
+
|----------|---------|-------------|
|
|
82
|
+
| `PORT` | `8787` | Proxy listen port |
|
|
83
|
+
| `HOST` | `127.0.0.1` | Proxy listen host |
|
|
84
|
+
| `UPSTREAM` | `https://api.anthropic.com` | Default upstream when no route matches |
|
|
85
|
+
| `ACP_PROVIDERS` | *(none)* | Path to a JSON file mapping provider names to root URLs (see below) |
|
|
86
|
+
| `ACP_COMPRESS_TOOL` | `1` | Set `0` to disable injecting the compress tool |
|
|
87
|
+
| `ACP_DEBUG` | `0` | Set `1` for verbose logging |
|
|
88
|
+
| `ACP_PASSTHROUGH` | `0` | Set `1` to forward without compression |
|
|
89
|
+
|
|
90
|
+
### Multiple upstreams (URL path routing)
|
|
91
|
+
|
|
92
|
+
Point any agent at the proxy using a provider name as a path segment. The
|
|
93
|
+
proxy strips the name and forwards to that provider's root URL. **API keys
|
|
94
|
+
are never stored in the proxy** — whatever key the agent sends is passed
|
|
95
|
+
through untouched to the upstream.
|
|
96
|
+
|
|
97
|
+
Create a providers file (e.g. `~/.bili/providers.json`):
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"glm": "https://bigmodel.cn",
|
|
102
|
+
"anthropic": "https://api.anthropic.com",
|
|
103
|
+
"openai": "https://api.openai.com",
|
|
104
|
+
"deepseek": "https://api.deepseek.com"
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Then:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
ACP_PROVIDERS=~/.bili/providers.json bili-proxy
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Each agent only needs to change its base URL to include the provider name.
|
|
115
|
+
The proxy figures out the rest, including the right context window for each
|
|
116
|
+
model family (claude=200k, gpt-4o=128k, glm=128k, ...) via a built-in table.
|
|
117
|
+
|
|
118
|
+
#### Claude Code (Anthropic)
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
export ANTHROPIC_BASE_URL=http://localhost:8787/anthropic
|
|
122
|
+
export ANTHROPIC_API_KEY=sk-ant-... # real key — passed through as-is
|
|
123
|
+
claude
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### Codex / any OpenAI-compatible agent (zhipu / openai / deepseek)
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
export OPENAI_BASE_URL=http://localhost:8787/v1/glm
|
|
130
|
+
export OPENAI_API_KEY=<your real glm key> # passed through as-is
|
|
131
|
+
codex
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The `/v1/glm` prefix tells the proxy to route to the `glm` provider; the
|
|
135
|
+
remaining `/v1/chat/completions` path is preserved. Set the key to the real
|
|
136
|
+
provider key — the proxy never reads or stores it.
|
|
137
|
+
|
|
138
|
+
### Notes on provider names
|
|
139
|
+
|
|
140
|
+
- Must start with a letter, contain only letters/digits/`-`/`_`.
|
|
141
|
+
- Reserved words (`v1`, `chat`, `completions`, `messages`, `models`, `api`)
|
|
142
|
+
are rejected to avoid colliding with real API path segments.
|
|
143
|
+
- The provider name can appear anywhere in the path; the longest match wins.
|
|
144
|
+
|
|
145
|
+
## Status
|
|
146
|
+
|
|
147
|
+
Early. Protocol handling and compression work against mock tests (79 passing). Real-model integration testing is the next milestone. Expect rough edges.
|
|
148
|
+
|
|
149
|
+
See [billion-context-pi](https://github.com/ranxianglei/billion-context-pi) for the pi-extension mode (in-process, tighter integration, the reference implementation).
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
MIT
|