wechat-openclaw-sdk 0.1.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 wangzhiyi
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.
@@ -0,0 +1,199 @@
1
+ Metadata-Version: 2.4
2
+ Name: wechat-openclaw-sdk
3
+ Version: 0.1.0
4
+ Summary: Python SDK for WeChat iLink OpenClaw bot channel (HTTP long-polling)
5
+ Author-email: wangzhiyi <eliseowzy@hotmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Eliseowzy/wechat-openclaw-sdk
8
+ Project-URL: Repository, https://github.com/Eliseowzy/wechat-openclaw-sdk
9
+ Project-URL: Issues, https://github.com/Eliseowzy/wechat-openclaw-sdk/issues
10
+ Keywords: wechat,ilink,openclaw,bot,sdk,long-polling
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Communications :: Chat
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: httpx>=0.27
25
+ Requires-Dist: pydantic>=2.5
26
+ Requires-Dist: cryptography>=42.0
27
+ Provides-Extra: redis
28
+ Requires-Dist: redis>=5.0; extra == "redis"
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=8.0; extra == "dev"
31
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
32
+ Requires-Dist: respx>=0.21; extra == "dev"
33
+ Requires-Dist: fakeredis>=2.21; extra == "dev"
34
+ Dynamic: license-file
35
+
36
+ # WeChat OpenClaw SDK(Python)
37
+
38
+ 微信 iLink OpenClaw 机器人渠道的 Python 接入 SDK。消息 API 协议为 **HTTP 长轮询**(非 WebSocket),
39
+ 5 个消息端点均为 POST JSON 到 `https://ilinkai.weixin.qq.com`;扫码登录网关为 GET 接口,
40
+ CDN 媒体上传为 POST octet-stream 密文。
41
+
42
+ > 面向 AI coding agents 的精简参考文档见 [llms.md](llms.md)。
43
+
44
+ ## 核心能力
45
+
46
+ 1. **任意 Agent 对接**:`BaseAgent` 异步事件流抽象,自研服务 / OpenAI 兼容接口 / 本地模型均可插拔;
47
+ 2. **单机 / 分布式部署**:单机零外部依赖;分布式借助 Redis Leader 选举,保证同一 botToken 全局只有一个实例拉消息;
48
+ 3. **主动发消息**:可在入站消息之外的时机推送文本 / 图片 / 文件 / 视频 / 语音,
49
+ 但需复用该用户最近一条入站消息的 `context_token`(见「主动推送」一节);
50
+ 4. **二维码登录**:内置扫码登录流程,产出 `WeChatCredentials` 直接构造客户端。
51
+
52
+ ## 安装
53
+
54
+ ```bash
55
+ # Python >= 3.10
56
+ pip install httpx "pydantic>=2" cryptography
57
+
58
+ # 分布式模式(可选)
59
+ pip install redis
60
+
61
+ # 或从源码安装
62
+ pip install . # 单机
63
+ pip install ".[redis]" # 含分布式依赖
64
+ ```
65
+
66
+ ## 快速上手
67
+
68
+ ```python
69
+ import asyncio
70
+ from wechat_openclaw import (EchoAgent, NoopCoordinator, OpenClawClient,
71
+ QrLoginModule, SDKConfig)
72
+
73
+ async def main():
74
+ # 基础地址(登录网关与消息 API 同源)唯一配置项:环境变量 WECHAT_OPENCLAW_BASE_URL,
75
+ # 未配置时默认 https://ilinkai.weixin.qq.com;也可在此显式传入 base_url="..."
76
+ config = SDKConfig()
77
+
78
+ # 1. 扫码登录(二维码内容会打印到控制台)
79
+ qr = QrLoginModule(config.base_url)
80
+ credentials = await qr.login_with_qr(timeout=480)
81
+
82
+ # 2. 构造客户端并注册 Agent
83
+ client = OpenClawClient(credentials, NoopCoordinator(), config)
84
+ client.register_agent(EchoAgent())
85
+
86
+ # 3. 启动长轮询(阻塞直到 stop / 会话过期)
87
+ await client.start()
88
+
89
+ asyncio.run(main())
90
+ ```
91
+
92
+ ### 地址配置
93
+
94
+ SDK 只有一个地址配置项,消息 API 与扫码登录网关共用:
95
+
96
+ ```bash
97
+ export WECHAT_OPENCLAW_BASE_URL=https://ilinkai.weixin.qq.com
98
+ ```
99
+
100
+ 未设置时取默认值 `https://ilinkai.weixin.qq.com`;也可通过 `SDKConfig(base_url=...)`
101
+ 在代码中覆盖。优先级:显式配置的非默认值 > 扫码登录返回的 `baseurl` > 默认值。
102
+
103
+ ### 主动推送
104
+
105
+ `sendmessage` 的服务端 prepare 阶段要靠 `context_token` 定位会话,该 token 由服务端
106
+ 随每条入站消息经 `getupdates` 下发,出站必须原样回带。**不带 / 带伪造值都会被拒**:
107
+ `{"ret":-2,"errmsg":"prepare failed"}`。因此机器人无法冷启动主动发消息,必须先收到
108
+ 该用户的一条入站消息,记下它的 `from_user_id` 与 `context_token` 再推送:
109
+
110
+ ```python
111
+ # 完整可运行版本见 examples/push_message.py
112
+ token = None
113
+ to_user_id = None
114
+
115
+ async def remember(msg): # 每条新入站消息都会签发新 token,需刷新
116
+ global token, to_user_id
117
+ to_user_id, token = msg.from_user_id, msg.context_token
118
+
119
+ client.connection.on_message(remember)
120
+ asyncio.create_task(client.start())
121
+ # ...等 remember 被触发后...
122
+ await client.send_text(to_user_id, "您关注的任务已完成 ✅", token)
123
+ ```
124
+
125
+ 宿主应用需自行持久化 `user_id -> context_token` 映射(官方 JS SDK 也是落盘保存),
126
+ 才能在进程重启后继续推送。注意微信频控,建议合并推送。
127
+
128
+ ### 自定义 Agent
129
+
130
+ ```python
131
+ from wechat_openclaw import AgentEvent, AgentEventType, BaseAgent
132
+
133
+ class MyAgent(BaseAgent):
134
+ async def run(self, request):
135
+ yield AgentEvent(AgentEventType.TEXT_DELTA, {"text": f"收到:{request.user_input}"})
136
+ yield AgentEvent(AgentEventType.MESSAGE_COMPLETED)
137
+ ```
138
+
139
+ 对接 OpenAI 兼容接口可直接使用内置 `OpenAICompatAgent(base_url, api_key, model)`。
140
+
141
+ ### 分布式部署
142
+
143
+ ```python
144
+ import redis.asyncio as aioredis
145
+ from wechat_openclaw import OpenClawClient, RedisCoordinator
146
+
147
+ r = aioredis.from_url("redis://localhost:6379/0")
148
+ coordinator = RedisCoordinator(r, credentials.account_id)
149
+ client = OpenClawClient(credentials, coordinator, config, redis_client=r)
150
+ ```
151
+
152
+ Leader 选举语义:锁 key `distributed:connection:wechat:{account_id}`,
153
+ 租约 1500ms、Leader 每 500ms 续期、Follower 每 300ms 抢占;
154
+ 故障切换时游标不迁移,新 Leader 从服务端最新位置开始拉取。
155
+
156
+ ## 模块结构
157
+
158
+ ```
159
+ wechat_openclaw/
160
+ ├── models.py # pydantic 协议模型 + 枚举(字段名对齐协议线上格式)
161
+ ├── config.py # 统一基础地址配置(WECHAT_OPENCLAW_BASE_URL)
162
+ ├── api.py # OpenClawAPI:5 个 HTTP 端点 + CDN 上传
163
+ ├── client.py # OpenClawClient:编排入口(收发/typing/媒体)+ SDKConfig
164
+ ├── connection.py # 长轮询 ConnectionManager(游标/过滤/去重/会话过期)
165
+ ├── coordinator.py # NoopCoordinator / RedisCoordinator(SET NX PX + Lua)
166
+ ├── qrlogin.py # 二维码登录模块
167
+ ├── agent.py # BaseAgent + AgentEvent + Dispatcher + 参考实现
168
+ └── utils/
169
+ ├── markdown.py # 流式 Markdown -> 纯文本过滤器(微信不渲染 Markdown)
170
+ ├── crypto.py # AES-128-ECB 加解密(CDN 媒体协议强制)
171
+ ├── ids.py # client_id / X-WECHAT-UIN 生成与日志脱敏
172
+ └── retry.py # 指数退避异步重试(3 次 / 0.5s 起 / x2.0)
173
+ ```
174
+
175
+ ## 关键协议要点
176
+
177
+ - 长轮询 `getupdates` 超时 35s(客户端超时视为正常空响应);`sendmessage`/`getuploadurl` 15s;`getconfig`/`sendtyping` 10s;
178
+ - `errcode == -14` 表示会话过期(`SessionExpiredError`),不重试,需重新扫码登录;
179
+ - 出站文本必须经 Markdown 过滤器转纯文本(微信仅原生渲染 `**加粗**`/`__加粗__`);
180
+ - 长耗时 Agent 处理需 typing 保活(每 8–15s 随机刷新、上限 5 分钟),`status=1/2` 必须配对;
181
+ - 本 SDK 仅支持单聊,群聊行为未验证。
182
+
183
+ ## 示例
184
+
185
+ - `examples/echo_bot.py` —— 扫码登录 + 回声机器人(单机)
186
+ - `examples/llm_bot.py` —— 扫码登录 + DashScope(OpenAI 兼容接口)LLM 机器人
187
+ - `examples/push_message.py` —— 主动推送
188
+ - `examples/distributed_bot.py` —— Redis Leader 选举的分布式部署
189
+
190
+ 本地调试可将凭据写入仓库根目录 `.env.local`(已在 `.gitignore` 中忽略),`llm_bot.py` 与
191
+ `push_message.py` 启动时自动加载;`echo_bot.py` / `distributed_bot.py` 不加载该文件,需显式
192
+ `export` 环境变量。已 `export` 的环境变量优先级更高,不会被文件覆盖。
193
+
194
+ ## 安全说明
195
+
196
+ - `WECHAT_OPENCLAW_BASE_URL` 应使用 HTTPS;若自建部署只提供明文 HTTP,需置于可信内网或加 HTTPS 反向代理;
197
+ - 日志中 bot_token / 用户 ID 一律脱敏(前 4 后 4,中间 `*`),URL 去 query;
198
+ - API Key 等凭据不得硬编码进源码,仅通过环境变量或 `.env.local` 提供;
199
+ - AES-128-ECB 为 OpenClaw CDN 协议强制规定,密钥为每文件一次性随机密钥。
@@ -0,0 +1,164 @@
1
+ # WeChat OpenClaw SDK(Python)
2
+
3
+ 微信 iLink OpenClaw 机器人渠道的 Python 接入 SDK。消息 API 协议为 **HTTP 长轮询**(非 WebSocket),
4
+ 5 个消息端点均为 POST JSON 到 `https://ilinkai.weixin.qq.com`;扫码登录网关为 GET 接口,
5
+ CDN 媒体上传为 POST octet-stream 密文。
6
+
7
+ > 面向 AI coding agents 的精简参考文档见 [llms.md](llms.md)。
8
+
9
+ ## 核心能力
10
+
11
+ 1. **任意 Agent 对接**:`BaseAgent` 异步事件流抽象,自研服务 / OpenAI 兼容接口 / 本地模型均可插拔;
12
+ 2. **单机 / 分布式部署**:单机零外部依赖;分布式借助 Redis Leader 选举,保证同一 botToken 全局只有一个实例拉消息;
13
+ 3. **主动发消息**:可在入站消息之外的时机推送文本 / 图片 / 文件 / 视频 / 语音,
14
+ 但需复用该用户最近一条入站消息的 `context_token`(见「主动推送」一节);
15
+ 4. **二维码登录**:内置扫码登录流程,产出 `WeChatCredentials` 直接构造客户端。
16
+
17
+ ## 安装
18
+
19
+ ```bash
20
+ # Python >= 3.10
21
+ pip install httpx "pydantic>=2" cryptography
22
+
23
+ # 分布式模式(可选)
24
+ pip install redis
25
+
26
+ # 或从源码安装
27
+ pip install . # 单机
28
+ pip install ".[redis]" # 含分布式依赖
29
+ ```
30
+
31
+ ## 快速上手
32
+
33
+ ```python
34
+ import asyncio
35
+ from wechat_openclaw import (EchoAgent, NoopCoordinator, OpenClawClient,
36
+ QrLoginModule, SDKConfig)
37
+
38
+ async def main():
39
+ # 基础地址(登录网关与消息 API 同源)唯一配置项:环境变量 WECHAT_OPENCLAW_BASE_URL,
40
+ # 未配置时默认 https://ilinkai.weixin.qq.com;也可在此显式传入 base_url="..."
41
+ config = SDKConfig()
42
+
43
+ # 1. 扫码登录(二维码内容会打印到控制台)
44
+ qr = QrLoginModule(config.base_url)
45
+ credentials = await qr.login_with_qr(timeout=480)
46
+
47
+ # 2. 构造客户端并注册 Agent
48
+ client = OpenClawClient(credentials, NoopCoordinator(), config)
49
+ client.register_agent(EchoAgent())
50
+
51
+ # 3. 启动长轮询(阻塞直到 stop / 会话过期)
52
+ await client.start()
53
+
54
+ asyncio.run(main())
55
+ ```
56
+
57
+ ### 地址配置
58
+
59
+ SDK 只有一个地址配置项,消息 API 与扫码登录网关共用:
60
+
61
+ ```bash
62
+ export WECHAT_OPENCLAW_BASE_URL=https://ilinkai.weixin.qq.com
63
+ ```
64
+
65
+ 未设置时取默认值 `https://ilinkai.weixin.qq.com`;也可通过 `SDKConfig(base_url=...)`
66
+ 在代码中覆盖。优先级:显式配置的非默认值 > 扫码登录返回的 `baseurl` > 默认值。
67
+
68
+ ### 主动推送
69
+
70
+ `sendmessage` 的服务端 prepare 阶段要靠 `context_token` 定位会话,该 token 由服务端
71
+ 随每条入站消息经 `getupdates` 下发,出站必须原样回带。**不带 / 带伪造值都会被拒**:
72
+ `{"ret":-2,"errmsg":"prepare failed"}`。因此机器人无法冷启动主动发消息,必须先收到
73
+ 该用户的一条入站消息,记下它的 `from_user_id` 与 `context_token` 再推送:
74
+
75
+ ```python
76
+ # 完整可运行版本见 examples/push_message.py
77
+ token = None
78
+ to_user_id = None
79
+
80
+ async def remember(msg): # 每条新入站消息都会签发新 token,需刷新
81
+ global token, to_user_id
82
+ to_user_id, token = msg.from_user_id, msg.context_token
83
+
84
+ client.connection.on_message(remember)
85
+ asyncio.create_task(client.start())
86
+ # ...等 remember 被触发后...
87
+ await client.send_text(to_user_id, "您关注的任务已完成 ✅", token)
88
+ ```
89
+
90
+ 宿主应用需自行持久化 `user_id -> context_token` 映射(官方 JS SDK 也是落盘保存),
91
+ 才能在进程重启后继续推送。注意微信频控,建议合并推送。
92
+
93
+ ### 自定义 Agent
94
+
95
+ ```python
96
+ from wechat_openclaw import AgentEvent, AgentEventType, BaseAgent
97
+
98
+ class MyAgent(BaseAgent):
99
+ async def run(self, request):
100
+ yield AgentEvent(AgentEventType.TEXT_DELTA, {"text": f"收到:{request.user_input}"})
101
+ yield AgentEvent(AgentEventType.MESSAGE_COMPLETED)
102
+ ```
103
+
104
+ 对接 OpenAI 兼容接口可直接使用内置 `OpenAICompatAgent(base_url, api_key, model)`。
105
+
106
+ ### 分布式部署
107
+
108
+ ```python
109
+ import redis.asyncio as aioredis
110
+ from wechat_openclaw import OpenClawClient, RedisCoordinator
111
+
112
+ r = aioredis.from_url("redis://localhost:6379/0")
113
+ coordinator = RedisCoordinator(r, credentials.account_id)
114
+ client = OpenClawClient(credentials, coordinator, config, redis_client=r)
115
+ ```
116
+
117
+ Leader 选举语义:锁 key `distributed:connection:wechat:{account_id}`,
118
+ 租约 1500ms、Leader 每 500ms 续期、Follower 每 300ms 抢占;
119
+ 故障切换时游标不迁移,新 Leader 从服务端最新位置开始拉取。
120
+
121
+ ## 模块结构
122
+
123
+ ```
124
+ wechat_openclaw/
125
+ ├── models.py # pydantic 协议模型 + 枚举(字段名对齐协议线上格式)
126
+ ├── config.py # 统一基础地址配置(WECHAT_OPENCLAW_BASE_URL)
127
+ ├── api.py # OpenClawAPI:5 个 HTTP 端点 + CDN 上传
128
+ ├── client.py # OpenClawClient:编排入口(收发/typing/媒体)+ SDKConfig
129
+ ├── connection.py # 长轮询 ConnectionManager(游标/过滤/去重/会话过期)
130
+ ├── coordinator.py # NoopCoordinator / RedisCoordinator(SET NX PX + Lua)
131
+ ├── qrlogin.py # 二维码登录模块
132
+ ├── agent.py # BaseAgent + AgentEvent + Dispatcher + 参考实现
133
+ └── utils/
134
+ ├── markdown.py # 流式 Markdown -> 纯文本过滤器(微信不渲染 Markdown)
135
+ ├── crypto.py # AES-128-ECB 加解密(CDN 媒体协议强制)
136
+ ├── ids.py # client_id / X-WECHAT-UIN 生成与日志脱敏
137
+ └── retry.py # 指数退避异步重试(3 次 / 0.5s 起 / x2.0)
138
+ ```
139
+
140
+ ## 关键协议要点
141
+
142
+ - 长轮询 `getupdates` 超时 35s(客户端超时视为正常空响应);`sendmessage`/`getuploadurl` 15s;`getconfig`/`sendtyping` 10s;
143
+ - `errcode == -14` 表示会话过期(`SessionExpiredError`),不重试,需重新扫码登录;
144
+ - 出站文本必须经 Markdown 过滤器转纯文本(微信仅原生渲染 `**加粗**`/`__加粗__`);
145
+ - 长耗时 Agent 处理需 typing 保活(每 8–15s 随机刷新、上限 5 分钟),`status=1/2` 必须配对;
146
+ - 本 SDK 仅支持单聊,群聊行为未验证。
147
+
148
+ ## 示例
149
+
150
+ - `examples/echo_bot.py` —— 扫码登录 + 回声机器人(单机)
151
+ - `examples/llm_bot.py` —— 扫码登录 + DashScope(OpenAI 兼容接口)LLM 机器人
152
+ - `examples/push_message.py` —— 主动推送
153
+ - `examples/distributed_bot.py` —— Redis Leader 选举的分布式部署
154
+
155
+ 本地调试可将凭据写入仓库根目录 `.env.local`(已在 `.gitignore` 中忽略),`llm_bot.py` 与
156
+ `push_message.py` 启动时自动加载;`echo_bot.py` / `distributed_bot.py` 不加载该文件,需显式
157
+ `export` 环境变量。已 `export` 的环境变量优先级更高,不会被文件覆盖。
158
+
159
+ ## 安全说明
160
+
161
+ - `WECHAT_OPENCLAW_BASE_URL` 应使用 HTTPS;若自建部署只提供明文 HTTP,需置于可信内网或加 HTTPS 反向代理;
162
+ - 日志中 bot_token / 用户 ID 一律脱敏(前 4 后 4,中间 `*`),URL 去 query;
163
+ - API Key 等凭据不得硬编码进源码,仅通过环境变量或 `.env.local` 提供;
164
+ - AES-128-ECB 为 OpenClaw CDN 协议强制规定,密钥为每文件一次性随机密钥。
@@ -0,0 +1,45 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "wechat-openclaw-sdk"
7
+ version = "0.1.0"
8
+ description = "Python SDK for WeChat iLink OpenClaw bot channel (HTTP long-polling)"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ authors = [
13
+ { name = "wangzhiyi", email = "eliseowzy@hotmail.com" },
14
+ ]
15
+ keywords = ["wechat", "ilink", "openclaw", "bot", "sdk", "long-polling"]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Intended Audience :: Developers",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: 3.13",
25
+ "Topic :: Communications :: Chat",
26
+ "Topic :: Software Development :: Libraries :: Python Modules",
27
+ ]
28
+ dependencies = [
29
+ "httpx>=0.27",
30
+ "pydantic>=2.5",
31
+ "cryptography>=42.0",
32
+ ]
33
+
34
+ [project.urls]
35
+ Homepage = "https://github.com/Eliseowzy/wechat-openclaw-sdk"
36
+ Repository = "https://github.com/Eliseowzy/wechat-openclaw-sdk"
37
+ Issues = "https://github.com/Eliseowzy/wechat-openclaw-sdk/issues"
38
+
39
+ [project.optional-dependencies]
40
+ # 分布式模式(Leader 选举 / Redis 去重)可选依赖
41
+ redis = ["redis>=5.0"]
42
+ dev = ["pytest>=8.0", "pytest-asyncio>=0.23", "respx>=0.21", "fakeredis>=2.21"]
43
+
44
+ [tool.setuptools.packages.find]
45
+ include = ["wechat_openclaw*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,50 @@
1
+ """WeChat OpenClaw SDK —— Python 版微信 iLink OpenClaw 接入 SDK。
2
+
3
+ 核心能力:任意 Agent 对接、单机/分布式部署、主动发消息、二维码登录。
4
+ """
5
+ from .agent import (
6
+ AgentEvent,
7
+ AgentEventType,
8
+ AgentRunRequest,
9
+ Attachment,
10
+ BaseAgent,
11
+ Dispatcher,
12
+ EchoAgent,
13
+ OpenAICompatAgent,
14
+ )
15
+ from .api import OpenClawAPI, OpenClawApiError, SessionExpiredError
16
+ from .client import OpenClawClient, SDKConfig
17
+ from .config import DEFAULT_BASE_URL, DEFAULT_CDN_BASE_URL, ENV_BASE_URL, get_base_url
18
+ from .connection import ConnectionManager, LocalDeduplicator, RedisDeduplicator
19
+ from .coordinator import BaseCoordinator, NoopCoordinator, RedisCoordinator
20
+ from .models import (
21
+ BaseInfo,
22
+ CdnMedia,
23
+ MessageItem,
24
+ TextItem,
25
+ TypingStatus,
26
+ UploadMediaType,
27
+ WeChatMessage,
28
+ WeChatMessageItemType,
29
+ WeChatMessageState,
30
+ WeChatMessageType,
31
+ )
32
+ from .qrlogin import QrLoginError, QrLoginModule, QrSession, WeChatCredentials
33
+ from .utils.markdown import StreamingMarkdownFilter, markdown_to_plain
34
+
35
+ __version__ = "0.1.0"
36
+
37
+ __all__ = [
38
+ "AgentEvent", "AgentEventType", "AgentRunRequest", "Attachment",
39
+ "BaseAgent", "Dispatcher", "EchoAgent", "OpenAICompatAgent",
40
+ "OpenClawAPI", "OpenClawApiError", "SessionExpiredError",
41
+ "OpenClawClient", "SDKConfig",
42
+ "DEFAULT_BASE_URL", "DEFAULT_CDN_BASE_URL", "ENV_BASE_URL", "get_base_url",
43
+ "ConnectionManager", "LocalDeduplicator", "RedisDeduplicator",
44
+ "BaseCoordinator", "NoopCoordinator", "RedisCoordinator",
45
+ "BaseInfo", "CdnMedia", "MessageItem", "TextItem", "TypingStatus",
46
+ "UploadMediaType", "WeChatMessage", "WeChatMessageItemType",
47
+ "WeChatMessageState", "WeChatMessageType",
48
+ "QrLoginError", "QrLoginModule", "QrSession", "WeChatCredentials",
49
+ "StreamingMarkdownFilter", "markdown_to_plain",
50
+ ]