Skip to content

Commit b0dda09

Browse files
committed
chore: 移除旧的Python实现代码,更新文档和Rust代码
- 删除所有Python相关的源码、测试文件和打包配置 - 更新中文使用文档,补充Rust构建运行说明 - 修复Rust服务端的类型转换和日志事件格式问题
1 parent 2f391d9 commit b0dda09

35 files changed

Lines changed: 101 additions & 2723 deletions

.gitignore

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
__pycache__/
2-
.pytest_cache/
3-
.venv/
4-
*.pyc
5-
*.db
6-
*.sqlite3
7-
*.log
81
.env
92
target/
10-
Cargo.lock
3+
Cargo.lock
4+
*.db
5+
*.sqlite3
6+
*.log

README.md

Lines changed: 76 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,81 @@ sessions, and OpenCode tools are intentionally absent.
1414

1515
```text
1616
Codex subagent
17-
-> POST /v1/responses
17+
-> POST /v1/responses (Responses API)
1818
-> this adapter
19-
-> POST https://opencode.ai/zen/go/v1/chat/completions
20-
-> Responses JSON or SSE
19+
-> POST /chat/completions (Chat Completions API)
20+
-> OpenCode Go (https://opencode.ai/zen/go/v1)
21+
-> Chat Completions response / SSE stream
22+
-> this adapter
23+
-> Responses API response / SSE stream
24+
-> Codex subagent
2125
```
2226

2327
Codex remains responsible for task roles, sandbox permissions, tool execution,
2428
review, and deciding whether work is complete.
2529

26-
## Run
30+
## Quick start (Rust)
31+
32+
```bash
33+
# Build
34+
cargo build --release
2735

28-
```powershell
29-
$env:OPENCODE_GO_API_KEY = "..."
30-
$env:CODEX_OPENCODE_LOCAL_TOKEN = "use-a-different-local-token"
31-
$env:CODEX_OPENCODE_PORT = "4010"
32-
python -m codex_opencode_adapter
36+
# Run
37+
OPENCODE_GO_API_KEY="your-key" \
38+
CODEX_OPENCODE_LOCAL_TOKEN="your-local-token" \
39+
cargo run
3340
```
3441

42+
The adapter listens on `127.0.0.1:4010` by default.
43+
44+
## Environment variables
45+
46+
| Variable | Default | Description |
47+
|---|---|---|
48+
| `OPENCODE_GO_API_KEY` | (required) | API key for OpenCode Go |
49+
| `CODEX_OPENCODE_LOCAL_TOKEN` | (none) | Bearer token the adapter requires from callers; if empty, auth is skipped |
50+
| `CODEX_OPENCODE_HOST` | `127.0.0.1` | Listen host |
51+
| `CODEX_OPENCODE_PORT` | `4010` | Listen port |
52+
| `OPENCODE_GO_BASE_URL` | `https://opencode.ai/zen/go/v1` | Upstream base URL |
53+
| `CODEX_OPENCODE_STATE_DB` | `.codex-opencode/state.sqlite` | SQLite state database path |
54+
| `CODEX_OPENCODE_STATE_TTL_SECONDS` | `21600` | State TTL (6 hours) |
55+
| `CODEX_OPENCODE_TIMEOUT_SECONDS` | `300` | Upstream request timeout |
56+
| `CODEX_OPENCODE_MAX_REQUEST_BYTES` | `8388608` | Max request body size (8 MB) |
57+
3558
The upstream API key and local client token must be different. The adapter
36-
never logs either token. Copy the provider and agent examples from
37-
`config.toml.example` and `.codex/agents/` into the desired Codex configuration.
59+
never logs either token.
60+
61+
## Run tests
3862

39-
The provider block must be installed in the user-level Codex config. Codex
40-
ignores `model_providers` declared in a project's `.codex/config.toml`.
63+
### Rust tests (unit + integration)
64+
65+
```bash
66+
# All tests
67+
cargo test
68+
69+
# Unit tests only
70+
cargo test --lib
71+
72+
# L2 integration tests (mock upstream, no external dependency)
73+
cargo test --test test_e2e
74+
75+
# L2 real smoke test (requires OPENCODE_GO_API_KEY)
76+
OPENCODE_GO_API_KEY="your-key" cargo test --test test_e2e test_e2e_real_smoke -- --ignored
77+
```
78+
79+
### Test structure
80+
81+
```text
82+
tests/
83+
├── conversion_rs.rs # Rust unit tests for conversion modules
84+
└── test_e2e.rs # L2 integration tests (mock upstream + real smoke)
85+
```
86+
87+
## Endpoints
88+
89+
- `POST /v1/responses` — Responses API (streaming and non-streaming)
90+
- `GET /v1/models` — List available models (prefixed with `opencode-go/`)
91+
- `GET /health` — Health check
4192

4293
## Reasoning compatibility
4394

@@ -57,11 +108,19 @@ metadata and logs rather than silently pretending to work.
57108
Reasoning content is retained only in stored chat history so tool continuations
58109
remain valid. It is not exposed as user-visible chain of thought.
59110

60-
## Endpoints
111+
## Supported models
112+
113+
All models available on OpenCode Go, prefixed with `opencode-go/` when calling
114+
the adapter:
115+
116+
- deepseek-v4-flash, deepseek-v4-pro
117+
- glm-5.1, glm-5.2
118+
- kimi-k2.6, kimi-k2.7-code
119+
- mimo-v2.5, mimo-v2.5-pro
120+
- minimax-m2.7, minimax-m3
121+
- qwen3.6-plus, qwen3.7-max, qwen3.7-plus
61122

62-
- `POST /v1/responses`
63-
- `GET /v1/models`
64-
- `GET /health`
123+
## State management
65124

66125
State needed for `previous_response_id` and tool results is stored in a local
67126
SQLite database and expires according to `CODEX_OPENCODE_STATE_TTL_SECONDS`.

codex_opencode_adapter.egg-info/PKG-INFO

Lines changed: 0 additions & 9 deletions
This file was deleted.

codex_opencode_adapter.egg-info/SOURCES.txt

Lines changed: 0 additions & 30 deletions
This file was deleted.

codex_opencode_adapter.egg-info/dependency_links.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

codex_opencode_adapter.egg-info/entry_points.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

codex_opencode_adapter.egg-info/requires.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

codex_opencode_adapter.egg-info/top_level.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

codex_opencode_adapter/__init__.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

codex_opencode_adapter/__main__.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)