Metadata-Version: 2.4
Name: brewer-nash-dispatcher
Version: 0.1.4
Summary: Brewer-Nash session dispatcher + OpenAI compatible streaming API
Author-email: Rexllnia <328626536@qq.com>
License: MIT
Project-URL: Homepage, https://github.com/Rexllnia/brewer-nash-dispatcher
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: fastapi>=0.100
Requires-Dist: uvicorn>=0.20
Requires-Dist: httpx>=0.24
Requires-Dist: websockets>=12.0

# brewer-nash-dispatcher

A session-affinity dispatcher for AI workers, inspired by the dynamic access-history mechanism of the **Brewer-Nash (Chinese Wall)** security model.

一个面向 AI Worker 的会话亲和调度器，灵感来自 **Brewer-Nash（中国墙）** 安全模型的动态访问历史机制。

The core idea: **isolation is triggered only by information asymmetry.** Workers with identical history are interchangeable; a worker holding non-empty history is walled off from unrelated new tasks. Fresh tasks target the zero-information state, so only workers with empty history qualify.

核心思想：**只有信息不对称才触发隔离。** history 完全相同的 worker 可以互换；持有非空 history 的 worker 不能接不相关的新任务。新任务的目标状态是“零信息”，因此只有 `history=[]` 的全新 worker 才有资格。

---

## Install / 安装

### pip

```bash
pip install brewer-nash-dispatcher

Quick start / 快速开始
Three processes, three terminals. 三个进程，三个终端。

bash
# 1. Start the dispatcher
brewer-nash-dispatcher --host 127.0.0.1 --port 9000

# 2. Attach one (or more) workers — any client that opens a WS to /ws
#    A reference worker is bundled for testing:
python -m fake_agent --url ws://127.0.0.1:9000/ws

# 3. Start the OpenAI-compatible gateway
brewer-nash-dispatcher-openai-apikey-server --host 127.0.0.1 --port 8001
Now point any OpenAI SDK at http://127.0.0.1:8001/v1:

现在可以用任意 OpenAI SDK 指向 http://127.0.0.1:8001/v1：

python
from openai import OpenAI

client = OpenAI(base_url="http://127.0.0.1:8001/v1", api_key="sk-darkdola-demo-123456")

stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello"}],
    stream=True,          # required — only streaming is supported
)

