142 lines
7.3 KiB
Markdown
142 lines
7.3 KiB
Markdown
# qwenwork-autoreg
|
|
|
|
Reversed QwenWork web API (`qwenwork.ai`): HTTP registration, JWT pool, OpenAI-compatible shim for
|
|
the new-api gateway, and a local tool-use agent that gives the PC to any model.
|
|
|
|
* `farm.py` — registration/login over plain HTTP (Aliyun captcha via 2captcha + IMAP code).
|
|
* `qw_shim.py` — OpenAI-compatible shim over a JWT pool (`/v1/chat/completions`, 13 models).
|
|
* `qw_agent.py` — tool-use harness: 10 tools with real filesystem/shell access on the host.
|
|
* `api.md` — 40+ endpoints with observed statuses and the session event schema.
|
|
|
|
## Tool use / local PC access
|
|
|
|
QwenWork's own desktop CLI (`resources/agent-sdk/components/qwencode/.../qwen-code`, ACP mode
|
|
`--acp`, `QWENWORK_QWENCODE_PROMPT_CAPABILITY=native-tools-v1`) does have native tools, but its
|
|
provider is pinned to DashScope inside the build: `--auth-type openai` plus
|
|
`OPENAI_BASE_URL` / `DASHSCOPE_PROXY_BASE_URL` / `QWENWORK_MODEL_PROXY_TARGET` still send the
|
|
request to `dashscope.aliyuncs.com` and return `401 Incorrect API key provided` for any foreign key.
|
|
So the desktop harness cannot be repointed at an arbitrary endpoint.
|
|
|
|
`qw_agent.py` gives the same result with full control — an OpenAI-compatible tool loop over this PC:
|
|
|
|
| tool | what it does |
|
|
|------|--------------|
|
|
| `fs_read` | read a file with line numbers (offset/limit) |
|
|
| `fs_write` | write/overwrite a file, creates dirs |
|
|
| `fs_edit` | exact-substring replace inside a file |
|
|
| `fs_list` | directory listing with sizes |
|
|
| `fs_glob` | find files by glob (`**/*.py`) |
|
|
| `fs_grep` | regex search inside files, `file:line:text` |
|
|
| `shell` | run any command on the host in **git-bash** (auto-detected; `QW_SHELL_BIN` overrides), returns exit/stdout/stderr/shell |
|
|
| `http_get` | fetch a URL, status + first 20k chars |
|
|
| `todo_write` | keep a plan checklist |
|
|
| `task_done` | finish and return the final answer |
|
|
|
|
Modes:
|
|
|
|
```bash
|
|
# one-shot task
|
|
python qw_agent.py run --provider router -p "grep 'def main' in this repo and count lines"
|
|
|
|
# interactive REPL (history kept with --session chat.json)
|
|
python qw_agent.py chat --session chat.json
|
|
|
|
# OpenAI-compatible server: the "model" executes the whole tool loop on this PC
|
|
python qw_agent.py serve --port 48970 --yolo
|
|
curl -s localhost:48970/v1/chat/completions -H 'Content-Type: application/json' \
|
|
-d '{"messages":[{"role":"user","content":"how many lines in qw_agent.py?"}]}'
|
|
```
|
|
|
|
Backends: `--provider qw` (qwenwork shim, `http://127.0.0.1:48981/v1`, `qw-flash`),
|
|
`--provider router` (local DashScope rotator, `http://127.0.0.1:16432/v1`),
|
|
`--provider any --base ... --model ... --key ...` for anything OpenAI-compatible.
|
|
`serve` supports `"stream": true` (SSE chunks + `x_qw_tools` trailer + `[DONE]`), so any OpenAI SDK,
|
|
bot or gateway can call it unchanged.
|
|
Safety: destructive shell commands (`rm -rf`, `mkfs`, `diskpart`, ...) ask for confirmation unless
|
|
`--yolo`; `--root DIR` confines all file tools to one directory.
|
|
|
|
Proof run — independent steps issued in parallel, model self-corrects a zero-hit grep
|
|
(backend `deepseek-v4.1-flash-1017`, 17.8 s):
|
|
|
|
```
|
|
[assistant] I'll run the independent first steps in parallel.
|
|
[tool] fs_grep {"path": "C:/Users/User/tmp/qwrepo", "pattern": "def task_done", "glob": "*.py"}
|
|
[tool] shell {"command": "wc -l C:/Users/User/tmp/qwrepo/qw_agent.py"}
|
|
[tool] fs_write {"path": "C:/Users/User/tmp/qwtest/note.txt", "content": "hello qw"}
|
|
[tool] fs_edit {"path": "C:/Users/User/tmp/qwtest/note.txt", "old": "hello", "new": "world"}
|
|
[tool] fs_read {"path": "C:/Users/User/tmp/qwtest/note.txt"}
|
|
[tool] task_done "grep = 0 literal hits (only `def t_task_done` at line 245); wc -l = 478;
|
|
note.txt after edit = \"world qw\""
|
|
turns 4 · tools_used 9
|
|
```
|
|
|
|
Serve proof:
|
|
|
|
```
|
|
GET /healthz {"ok": true, "model": "deepseek-v4.1-flash-1017", "tools": 10}
|
|
GET /v1/models {"data": [{"id": "deepseek-v4.1-flash-1017-agent"}]}
|
|
POST /v1/chat/completions {"choices": [...content "world qw"...], "x_qw_tools": ["fs_read","task_done"]}
|
|
POST +"stream":true 5 SSE chunks, content "1795213381" (real `date +%s` from the PC), [DONE]
|
|
```
|
|
|
|
Bash proof (`shell` goes through real git-bash, not cmd.exe) — 3 calls in parallel, 4.5 s, 2 turns:
|
|
|
|
```
|
|
[tool] shell {"command": "date +%s"} -> 1795213351 (exit 0)
|
|
[tool] shell {"command": "ls C:/Users/User/tmp/qwrepo | wc -l"} -> 12 (exit 0)
|
|
[tool] fs_grep {"path": "C:/Users/User/tmp/qwrepo", "pattern": "BASH = ", "glob": "*.py"}
|
|
-> qw_agent.py:240 "BASH = _find_bash()"
|
|
```
|
|
|
|
## Registration
|
|
|
|
```bash
|
|
export QW_2CAP=~/.2cap_key QW_GMAIL=you@gmail.com QW_GMAIL_PASS=app-password
|
|
python farm.py you+qw1@gmail.com --register
|
|
python farm.py you+qw1@gmail.com --login # if the address already exists
|
|
```
|
|
|
|
Flow: `POST /auth/email-codes {email, purpose, captcha_token}` -> `{"code":"ok","data":{"retry_after_seconds":60}}`.
|
|
The `captcha_token` must be the whole 2captcha `solution` object serialised as a JSON **string** —
|
|
an object body gives 400, `solution.data` alone gives 403 `human verification failed`
|
|
(Aliyun Captcha v3: `sceneId=l47rwlyt`, `prefix=13n1x6`, `region=ga`).
|
|
Then read the 6-digit code over IMAP (`used_codes.txt` stops a second account from reusing the same
|
|
code inside one minute), `POST /auth/local/register {email, code, notification:false}` ->
|
|
`{"created":true,...}`, JWT lands in cookie `token` (403 chars).
|
|
|
|
## Shim
|
|
|
|
```bash
|
|
QW_POOL=./accounts.jsonl QW_PORT=48981 python qw_shim.py
|
|
curl -s localhost:48981/v1/chat/completions -H 'Content-Type: application/json' \
|
|
-d '{"model":"qw-flash","messages":[{"role":"user","content":"hi"}]}'
|
|
```
|
|
|
|
`402`/`401`/`403` from upstream puts the account on a 15-minute cooldown and the request is retried
|
|
on the next account. `mode` is mapped from the OpenAI model name; unknown names -> 404.
|
|
|
|
Models exposed (all 1M context): `kimi-k3.1-pro`, `qwen3.8-max`, `qwen4-max`, `glm-5.3`,
|
|
`gpt-6.1-sol`, `deepseek-v4.1-flash`, `deepseek-flash`, `glm-5.3-flash`, `minimax-m3.1-flash`,
|
|
`qwen3.8-flash` plus aliases `flash`/`advanced`/`pro`.
|
|
|
|
## Known blocker: credit hold
|
|
|
|
When a chat session is created, QwenWork **blocks the whole remaining balance** on that account
|
|
(`/user/billings` -> `{"type":"Blocked","amount":-699.83,"detail":{"title":"Credits blocked"}}`)
|
|
if the turn is not completed through the WebSocket session protocol. The hold is *not* released by
|
|
`DELETE /api/chat-sessions/{id}`, `PATCH`, or any REST endpoint we found; REST sessions also keep
|
|
`end_time=null` forever. Practically: one botched/half-read session zeroes the account.
|
|
|
|
Mitigation used here: wait for a real `agent_message_chunk` (not just `result/prompt_response`),
|
|
close the session afterwards, and never issue a second session on an account whose previous turn
|
|
returned no text. Proper fix is the `/api/chat-ws` protobuf session lifecycle.
|
|
|
|
## Notes
|
|
|
|
- `qwenwork.cn` has email login disabled (`/auth/email-codes` -> 404); CN entry goes through Alibaba
|
|
fast-auth (needs a mainland account/phone).
|
|
- Starter credits stopped being granted after ~2026-11-20 20:50 UTC in our tests; accounts created
|
|
later report `remaining 0, exceeded true` and `402 INSUFFICIENT_RESOURCES` on session start.
|
|
- Google OAuth entry exists: `/auth/google` -> accounts.google.com, `redirect_uri=/oauth-callback/google`,
|
|
client_id `376662729962-6p89qbb0nd7e2vqr2da3jd7315mbnvdn`.
|
|
- MIT, 2026 Gothbreach. No credentials in the repo; everything is env-driven. |