billion-context-web
v0.1.0
Published
Browser-side context-compression client for billion-context / acp-kernel. Brings incremental, reversible, prefix-cache-friendly context compression to web apps without running a Node proxy.
Maintainers
Readme
billion-context-web
billion-context / acp-kernel 的浏览器端上下文压缩客户端。
billion-context 是一个 Node.js 代理,架在任意 AI 助手与其模型 API 之间,用 acp-kernel 压缩重写 Anthropic/OpenAI 流。billion-context-web 把同样的增量、可逆、对前缀缓存友好的压缩带到浏览器里运行的应用 —— 无需代理进程,无需 Node。
⚠️ 这是一个骨架包,压缩接口目前是占位实现。 请按需对接
acp-kernel,或转发到运行中的billion-context代理端点。
为什么
长 AI 会话会把上下文撑爆。一旦超过上下文窗口,会话质量下降甚至崩掉,而各家 provider 按 token 计费。压缩能让一个会话连跑数天 —— 海量 token 穿过同一个窗口。
浏览器里通常没法跑 Node 代理。billion-context-web 给 Web 应用提供一个客户端,对接 billion-context 端点(或打包后直接调用 acp-kernel),让聊天界面、浏览器内 IDE 实验、agent 前端都能享有与 CLI 助手相同的压缩能力。
安装
npm install billion-context-web快速开始
import { BillionContextWeb } from 'billion-context-web';
const bc = new BillionContextWeb({
endpoint: 'http://localhost:8787', // 运行中的 billion-context 代理
contextWindow: 200_000, // 可选:自动检测失败时的兜底窗口
});
const result = await bc.compress({ messages });
console.log(result.tokensBefore, '->', result.tokensAfter);API
new BillionContextWeb(options?)
| 选项 | 类型 | 说明 |
| -------------- | ----------------------------- | ----------------------------------------------- |
| endpoint | string | 运行中的 billion-context 代理地址。 |
| contextWindow| number | 自动检测失败时的兜底窗口大小(tokens)。 |
| headers | Record<string, string> | 附加到上游请求的额外 headers。 |
| fetch | typeof fetch | 自定义 fetch(默认为全局 fetch)。 |
bc.compress(request): Promise<CompressResult>
把已消耗的对话范围折叠成摘要。(骨架:no-op。)
License
MIT © ranxianglei
