wottys-test 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.
- wottys_test-0.1.0/LICENSE +21 -0
- wottys_test-0.1.0/PKG-INFO +539 -0
- wottys_test-0.1.0/README.md +475 -0
- wottys_test-0.1.0/pyproject.toml +157 -0
- wottys_test-0.1.0/setup.cfg +4 -0
- wottys_test-0.1.0/src/witty_agent_server/__init__.py +1 -0
- wottys_test-0.1.0/src/witty_agent_server/adapters/openclaw_adapter.py +51 -0
- wottys_test-0.1.0/src/witty_agent_server/adapters/runtime_registry.py +12 -0
- wottys_test-0.1.0/src/witty_agent_server/api/routers/agent_router.py +342 -0
- wottys_test-0.1.0/src/witty_agent_server/api/routers/session_router.py +191 -0
- wottys_test-0.1.0/src/witty_agent_server/api/routers/session_ws_router.py +197 -0
- wottys_test-0.1.0/src/witty_agent_server/app.py +91 -0
- wottys_test-0.1.0/src/witty_agent_server/application/__init__.py +1 -0
- wottys_test-0.1.0/src/witty_agent_server/application/materialization/__init__.py +1 -0
- wottys_test-0.1.0/src/witty_agent_server/application/materialization/converter.py +837 -0
- wottys_test-0.1.0/src/witty_agent_server/application/materialization/core/__init__.py +1 -0
- wottys_test-0.1.0/src/witty_agent_server/application/materialization/core/io_utils.py +75 -0
- wottys_test-0.1.0/src/witty_agent_server/application/materialization/core/shell_utils.py +30 -0
- wottys_test-0.1.0/src/witty_agent_server/application/materialization/json_to_env.py +106 -0
- wottys_test-0.1.0/src/witty_agent_server/application/materialization/openclaw/__init__.py +1 -0
- wottys_test-0.1.0/src/witty_agent_server/application/materialization/openclaw/converter.py +17 -0
- wottys_test-0.1.0/src/witty_agent_server/application/materialization/openclaw/core/__init__.py +1 -0
- wottys_test-0.1.0/src/witty_agent_server/application/materialization/openclaw/core/io_utils.py +13 -0
- wottys_test-0.1.0/src/witty_agent_server/application/materialization/openclaw/core/shell_utils.py +13 -0
- wottys_test-0.1.0/src/witty_agent_server/application/materialization/openclaw/json_to_env.py +13 -0
- wottys_test-0.1.0/src/witty_agent_server/application/materialization/openclaw/spec_json_parser.py +13 -0
- wottys_test-0.1.0/src/witty_agent_server/application/materialization/openclaw_materializer.py +96 -0
- wottys_test-0.1.0/src/witty_agent_server/application/materialization/ports.py +17 -0
- wottys_test-0.1.0/src/witty_agent_server/application/materialization/spec_json_parser.py +42 -0
- wottys_test-0.1.0/src/witty_agent_server/application/models/__init__.py +7 -0
- wottys_test-0.1.0/src/witty_agent_server/application/models/agent.py +23 -0
- wottys_test-0.1.0/src/witty_agent_server/application/models/agent_api.py +34 -0
- wottys_test-0.1.0/src/witty_agent_server/application/models/errors.py +16 -0
- wottys_test-0.1.0/src/witty_agent_server/application/models/events.py +49 -0
- wottys_test-0.1.0/src/witty_agent_server/application/models/runtime_events.py +46 -0
- wottys_test-0.1.0/src/witty_agent_server/application/models/session.py +20 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/__init__.py +1 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/agent/__init__.py +58 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/agent/base.py +167 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/agent/errors.py +105 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/agent/openclaw_agent_service.py +311 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/agent/openclaw_lifecycle_service.py +187 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/agent/opencode_agent_service.py +64 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/agent/runtime_workspace_resolver.py +39 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/event_emitter.py +90 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/session/__init__.py +40 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/session/base.py +314 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/session/errors.py +85 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/session/openclaw_session_service.py +138 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/session/opencode_session_service.py +10 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/session_identity_store.py +60 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/session_state_sync_service.py +138 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/session_ws_orchestrator.py +394 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/skill/__init__.py +26 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/skill/base.py +42 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/skill/errors.py +89 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/skill/openclaw_skill_service.py +438 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/skill/opencode_skill_service.py +37 -0
- wottys_test-0.1.0/src/witty_agent_server/application/services/task_pool.py +128 -0
- wottys_test-0.1.0/src/witty_agent_server/infra/persistence/in_memory.py +23 -0
- wottys_test-0.1.0/src/witty_agent_server/infra/ws/client_base.py +41 -0
- wottys_test-0.1.0/src/witty_agent_server/infra/ws/openclaw_gateway_client.py +1017 -0
- wottys_test-0.1.0/src/witty_agent_server/logger/logging_config.py +18 -0
- wottys_test-0.1.0/src/witty_agent_server/main.py +10 -0
- wottys_test-0.1.0/src/witty_agent_server/runtimes/openclaw_gateway_runtime.py +426 -0
- wottys_test-0.1.0/src/witty_agent_server/runtimes/opencode_runtime.py +40 -0
- wottys_test-0.1.0/src/witty_agent_server/runtimes/runtime_base.py +79 -0
- wottys_test-0.1.0/src/witty_service/__init__.py +5 -0
- wottys_test-0.1.0/src/witty_service/adapter/__init__.py +20 -0
- wottys_test-0.1.0/src/witty_service/adapter/exceptions.py +53 -0
- wottys_test-0.1.0/src/witty_service/adapter/http_client.py +55 -0
- wottys_test-0.1.0/src/witty_service/adapter/schemas.py +26 -0
- wottys_test-0.1.0/src/witty_service/adapter/websocket_client.py +152 -0
- wottys_test-0.1.0/src/witty_service/adapter/websocket_client_pool.py +40 -0
- wottys_test-0.1.0/src/witty_service/adapter/websocket_protocol.py +17 -0
- wottys_test-0.1.0/src/witty_service/api/__init__.py +4 -0
- wottys_test-0.1.0/src/witty_service/api/agents.py +632 -0
- wottys_test-0.1.0/src/witty_service/api/auth.py +34 -0
- wottys_test-0.1.0/src/witty_service/api/backport.py +135 -0
- wottys_test-0.1.0/src/witty_service/api/backport_schemas.py +65 -0
- wottys_test-0.1.0/src/witty_service/api/cve.py +132 -0
- wottys_test-0.1.0/src/witty_service/api/cve_schemas.py +71 -0
- wottys_test-0.1.0/src/witty_service/api/errors.py +32 -0
- wottys_test-0.1.0/src/witty_service/api/models.py +120 -0
- wottys_test-0.1.0/src/witty_service/api/schemas.py +230 -0
- wottys_test-0.1.0/src/witty_service/api/services.py +78 -0
- wottys_test-0.1.0/src/witty_service/api/skills.py +188 -0
- wottys_test-0.1.0/src/witty_service/application/__init__.py +27 -0
- wottys_test-0.1.0/src/witty_service/application/agent_manager.py +1711 -0
- wottys_test-0.1.0/src/witty_service/application/awesome_openclaw_sync.py +205 -0
- wottys_test-0.1.0/src/witty_service/application/backport_cvekit_client.py +1201 -0
- wottys_test-0.1.0/src/witty_service/application/backport_git_client.py +267 -0
- wottys_test-0.1.0/src/witty_service/application/backport_service.py +630 -0
- wottys_test-0.1.0/src/witty_service/application/cve_service.py +519 -0
- wottys_test-0.1.0/src/witty_service/application/session_manager.py +252 -0
- wottys_test-0.1.0/src/witty_service/application/skill_manager.py +768 -0
- wottys_test-0.1.0/src/witty_service/cli.py +85 -0
- wottys_test-0.1.0/src/witty_service/config.py +21 -0
- wottys_test-0.1.0/src/witty_service/data/agent-config.tar.gz +0 -0
- wottys_test-0.1.0/src/witty_service/domain/__init__.py +12 -0
- wottys_test-0.1.0/src/witty_service/domain/enums.py +22 -0
- wottys_test-0.1.0/src/witty_service/domain/errors.py +30 -0
- wottys_test-0.1.0/src/witty_service/domain/models.py +22 -0
- wottys_test-0.1.0/src/witty_service/main.py +115 -0
- wottys_test-0.1.0/src/witty_service/persistence/db.py +33 -0
- wottys_test-0.1.0/src/witty_service/persistence/orm.py +343 -0
- wottys_test-0.1.0/src/witty_service/persistence/repositories.py +1457 -0
- wottys_test-0.1.0/src/witty_service/sandbox/__init__.py +29 -0
- wottys_test-0.1.0/src/witty_service/sandbox/base.py +139 -0
- wottys_test-0.1.0/src/witty_service/sandbox/docker.py +267 -0
- wottys_test-0.1.0/src/witty_service/sandbox/e2b.py +41 -0
- wottys_test-0.1.0/src/witty_service/sandbox/factory.py +80 -0
- wottys_test-0.1.0/src/witty_service/sandbox/local_process.py +233 -0
- wottys_test-0.1.0/src/witty_service/storage/__init__.py +6 -0
- wottys_test-0.1.0/src/witty_service/storage/runtime_backup.py +62 -0
- wottys_test-0.1.0/src/witty_service/storage/workspace_store.py +60 -0
- wottys_test-0.1.0/src/witty_service/workspace_init.py +48 -0
- wottys_test-0.1.0/wottys_test.egg-info/PKG-INFO +539 -0
- wottys_test-0.1.0/wottys_test.egg-info/SOURCES.txt +121 -0
- wottys_test-0.1.0/wottys_test.egg-info/dependency_links.txt +1 -0
- wottys_test-0.1.0/wottys_test.egg-info/entry_points.txt +2 -0
- wottys_test-0.1.0/wottys_test.egg-info/requires.txt +18 -0
- wottys_test-0.1.0/wottys_test.egg-info/top_level.txt +2 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 openEuler DevStation
|
|
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,539 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wottys_test
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Witty Service - A service for managing agents and sessions
|
|
5
|
+
Author-email: Witty Team <team@witty.dev>
|
|
6
|
+
Maintainer-email: Witty Team <team@witty.dev>
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2026 openEuler DevStation
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
|
|
29
|
+
Project-URL: homepage, https://github.com/witty/witty-service
|
|
30
|
+
Project-URL: documentation, https://docs.witty.dev
|
|
31
|
+
Project-URL: repository, https://github.com/witty/witty-service.git
|
|
32
|
+
Project-URL: changelog, https://github.com/witty/witty-service/blob/main/CHANGELOG.md
|
|
33
|
+
Keywords: witty,agent,service,ai,llm
|
|
34
|
+
Classifier: Development Status :: 4 - Beta
|
|
35
|
+
Classifier: Intended Audience :: Developers
|
|
36
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
37
|
+
Classifier: Programming Language :: Python :: 3
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
41
|
+
Classifier: Operating System :: OS Independent
|
|
42
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
43
|
+
Requires-Python: >=3.11
|
|
44
|
+
Description-Content-Type: text/markdown
|
|
45
|
+
License-File: LICENSE
|
|
46
|
+
Requires-Dist: fastapi>=0.115
|
|
47
|
+
Requires-Dist: sqlalchemy>=2.0
|
|
48
|
+
Requires-Dist: alembic>=1.14
|
|
49
|
+
Requires-Dist: websockets>=15.0.1
|
|
50
|
+
Requires-Dist: cryptography>=42.0.0
|
|
51
|
+
Requires-Dist: requests>=2.32.5
|
|
52
|
+
Requires-Dist: uvicorn>=0.20
|
|
53
|
+
Requires-Dist: httpx>=0.27
|
|
54
|
+
Requires-Dist: pyyaml>=6.0
|
|
55
|
+
Requires-Dist: python-multipart>=0.0.29
|
|
56
|
+
Provides-Extra: dev
|
|
57
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
58
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
59
|
+
Requires-Dist: black>=24.0; extra == "dev"
|
|
60
|
+
Requires-Dist: flake8>=6.0; extra == "dev"
|
|
61
|
+
Requires-Dist: mypy>=1.8; extra == "dev"
|
|
62
|
+
Requires-Dist: python-semantic-release>=9.0; extra == "dev"
|
|
63
|
+
Dynamic: license-file
|
|
64
|
+
|
|
65
|
+
# Witty-Service
|
|
66
|
+
|
|
67
|
+
[](LICENSE) [](https://pypi.org/project/witty-service/) [](https://www.python.org/)
|
|
68
|
+
|
|
69
|
+
AI Agent 全生命周期管理服务。Witty-Service 提供智能体的创建、沙箱运行、会话管理、消息交互等核心能力,通过统一的 REST API 屏蔽底层沙箱(Docker / Local Process / E2B)与运行时适配器(OpenClaw / OpenCode)的差异,让你以一致的方式编排和管理 AI Agent。
|
|
70
|
+
|
|
71
|
+
## 目录
|
|
72
|
+
|
|
73
|
+
- [项目介绍](#项目介绍)
|
|
74
|
+
- [功能特性](#功能特性)
|
|
75
|
+
- [技术架构](#技术架构)
|
|
76
|
+
- [整体框架图](#整体框架图)
|
|
77
|
+
- [安装指南](#安装指南)
|
|
78
|
+
- [方式一:pip 安装](#方式一pip安装)
|
|
79
|
+
- [方式二:从源码安装](#方式二从源码安装)
|
|
80
|
+
- [快速开始](#快速开始)
|
|
81
|
+
- [配置说明](#配置说明)
|
|
82
|
+
- [部署流程](#部署流程)
|
|
83
|
+
- [测试环境](#测试环境)
|
|
84
|
+
- [生产环境](#生产环境)
|
|
85
|
+
- [本地开发](#本地开发)
|
|
86
|
+
- [环境搭建](#环境搭建)
|
|
87
|
+
- [项目结构](#项目结构)
|
|
88
|
+
- [常用开发命令](#常用开发命令)
|
|
89
|
+
- [代码贡献流程](#代码贡献流程)
|
|
90
|
+
- [开发规范](#开发规范)
|
|
91
|
+
- [API 文档](#api-文档)
|
|
92
|
+
- [许可证](#许可证)
|
|
93
|
+
- [支持与反馈](#支持与反馈)
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## 项目介绍
|
|
98
|
+
|
|
99
|
+
Witty-Service 是一个面向 AI Agent 场景的后端服务,核心职责是将 **Agent 生命周期管理**、**沙箱隔离运行**、**会话与消息交互** 三者统一封装,对外提供简洁的 RESTful API。它作为上层应用(如 PolyMind)与底层 Agent 运行时之间的桥梁,使得前端无需关心 Agent 是运行在 Docker 容器、本地进程还是云端沙箱中。
|
|
100
|
+
|
|
101
|
+
典型应用场景:
|
|
102
|
+
|
|
103
|
+
- **AI 编程助手平台** — 为每个用户创建独立沙箱中的 Agent,隔离执行代码生成、文件操作等任务
|
|
104
|
+
- **多模型对话服务** — 统一管理 OpenAI、Anthropic、DeepSeek 等多家 LLM 提供商的模型配置,按需切换
|
|
105
|
+
- **Agent 技能市场** — 通过技能仓库为 Agent 动态注入专业能力(如 CVE 分析等)
|
|
106
|
+
- **企业级 Agent 编排** — 支持定时任务、会话暂停/恢复、运行时备份等企业级运维能力
|
|
107
|
+
|
|
108
|
+
### 功能特性
|
|
109
|
+
|
|
110
|
+
- 🤖 **Agent 全生命周期管理** — 创建、暂停、恢复、删除 Agent,支持运行时备份与恢复
|
|
111
|
+
- 📦 **多沙箱隔离** — 支持 Docker、Local Process、E2B 三种沙箱类型,按需选择隔离级别
|
|
112
|
+
- 💬 **会话与消息** — 多会话管理,支持 REST 非流式和 SSE 流式两种消息交互模式
|
|
113
|
+
- 🔌 **多运行时适配** — 通过 Adapter 层对接 OpenClaw、OpenCode 等不同 Agent 运行时
|
|
114
|
+
- 🧠 **多模型管理** — 统一配置 OpenAI、Anthropic、Google、DeepSeek、GLM、Kimi 等 10+ 模型提供商
|
|
115
|
+
- 🛠️ **技能市场** — 内置技能仓库同步,支持从市场安装和上传自定义技能包
|
|
116
|
+
- 🔐 **安全认证** — 基于 Bearer Token 的 API 认证机制
|
|
117
|
+
- 📊 **CVE 与 Backport** — 内置 CVE 漏洞分析和Backport服务
|
|
118
|
+
|
|
119
|
+
### 技术架构
|
|
120
|
+
|
|
121
|
+
| 层级 | 技术栈 |
|
|
122
|
+
|------|--------|
|
|
123
|
+
| Web 框架 | FastAPI |
|
|
124
|
+
| ASGI 服务器 | Uvicorn |
|
|
125
|
+
| 数据库 | SQLAlchemy + Alembic(迁移) |
|
|
126
|
+
| 通信协议 | WebSocket + REST + SSE |
|
|
127
|
+
| 沙箱管理 | Docker SDK / subprocess / E2B SDK |
|
|
128
|
+
| 包管理 | uv |
|
|
129
|
+
| 语言 | Python 3.11+ |
|
|
130
|
+
|
|
131
|
+
### 整体框架图
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
┌─────────────────────────────────┐
|
|
135
|
+
│ 上层应用(如 PolyMind) │
|
|
136
|
+
└───────────────┬─────────────────┘
|
|
137
|
+
│
|
|
138
|
+
REST API / SSE
|
|
139
|
+
│
|
|
140
|
+
▼
|
|
141
|
+
┌──────────────────────────────────────────────────────────────────────┐
|
|
142
|
+
│ Witty-Service │
|
|
143
|
+
│ │
|
|
144
|
+
│ ┌─ API Layer ───────────────────────────────────────────────────┐ │
|
|
145
|
+
│ │ /agents · /models · /skills · /cve · /backport │ │
|
|
146
|
+
│ │ Auth (Bearer Token) · Error Handler · Schemas │ │
|
|
147
|
+
│ └──────────────────────────┬────────────────────────────────────┘ │
|
|
148
|
+
│ │ │
|
|
149
|
+
│ ┌─ Application Layer ──────▼────────────────────────────────────┐ │
|
|
150
|
+
│ │ AgentManager · SessionManager · SkillManager │ │
|
|
151
|
+
│ │ CVEService · BackportService │ │
|
|
152
|
+
│ └──┬────────────────────┬──────────────────────┬────────────────┘ │
|
|
153
|
+
│ │ │ │ │
|
|
154
|
+
│ ┌──▼─────────────┐ ┌──▼──────────────┐ ┌───▼──────────────┐ │
|
|
155
|
+
│ │ Adapter Layer │ │Persistence Layer│ │ Storage Layer │ │
|
|
156
|
+
│ │ WebSocket客户端│ │ SQLAlchemy ORM │ │ WorkspaceStore │ │
|
|
157
|
+
│ │ HTTP 客户端 │ │ SQLite+Alembic │ │ RuntimeBackup │ │
|
|
158
|
+
│ │ 连接池/协议 │ │ Repository │ │ │ │
|
|
159
|
+
│ └──┬─────────────┘ └─────────────────┘ └──────────────────┘ │
|
|
160
|
+
│ │ │
|
|
161
|
+
│ ┌──▼─────────────────────────────────────────────────────────────┐ │
|
|
162
|
+
│ │ Sandbox Layer │ │
|
|
163
|
+
│ │ ┌──────────┐ ┌──────────────┐ ┌──────────┐ │ │
|
|
164
|
+
│ │ │ Docker │ │Local Process │ │ E2B │ │ │
|
|
165
|
+
│ │ └────┬─────┘ └──────┬───────┘ └────┬─────┘ │ │
|
|
166
|
+
│ │ └────────┬──────┘ │ │ │
|
|
167
|
+
│ │ │ │ │ │
|
|
168
|
+
│ │ AdapterEndpoint │ │ │
|
|
169
|
+
│ └────────────────┼──────────────────────┼────────────────────────┘ │
|
|
170
|
+
│ │ │ │
|
|
171
|
+
│ ┌─────────────────────┐ ┌───────▼──────────┐ │
|
|
172
|
+
│ │ Domain (Enums/Errors)│ │ Config │ │
|
|
173
|
+
│ └─────────────────────┘ └──────────────────┘ │
|
|
174
|
+
└──────────────────┼──────────────────────┼───────────────────────────┘
|
|
175
|
+
│ │
|
|
176
|
+
┌─────────▼──────────┐ ┌────────▼─────────┐
|
|
177
|
+
│ HTTP REST │ │ HTTP REST │
|
|
178
|
+
│ (生命周期/技能管理) │ │ (E2B Cloud API) │
|
|
179
|
+
└─────────┬──────────┘ └──────────────────┘
|
|
180
|
+
│
|
|
181
|
+
┌─────────▼──────────┐
|
|
182
|
+
│ WebSocket │
|
|
183
|
+
│ (流式消息/事件推送) │
|
|
184
|
+
└─────────┬──────────┘
|
|
185
|
+
│
|
|
186
|
+
▼
|
|
187
|
+
┌──────────────────────────────────────────────────────────────────────┐
|
|
188
|
+
│ Witty-Agent-Server │
|
|
189
|
+
│ │
|
|
190
|
+
│ ┌─ API Layer ───────────────────────────────────────────────────┐ │
|
|
191
|
+
│ │ AgentRouter · SessionRouter · SessionWSRouter │ │
|
|
192
|
+
│ └──────────────────────────┬────────────────────────────────────┘ │
|
|
193
|
+
│ │ │
|
|
194
|
+
│ ┌─ Application Layer ──────▼────────────────────────────────────┐ │
|
|
195
|
+
│ │ AgentService · SessionService · SkillService │ │
|
|
196
|
+
│ │ SessionWSOrchestrator · TaskPool │ │
|
|
197
|
+
│ │ Materialization │ │
|
|
198
|
+
│ └──────────────────────────┬────────────────────────────────────┘ │
|
|
199
|
+
│ │ │
|
|
200
|
+
│ ┌─ Runtime Layer ──────────▼────────────────────────────────────┐ │
|
|
201
|
+
│ │ RuntimeBase (ABC) │ │
|
|
202
|
+
│ │ ├─ OpenClawGatewayRuntime │ │
|
|
203
|
+
│ │ └─ OpenCodeRuntime (WIP) │ │
|
|
204
|
+
│ └───────────────────────────┬────────────────────────────────────┘ │
|
|
205
|
+
│ │ │
|
|
206
|
+
│ ┌─ Adapter Layer ──────────▼──────────────┐ ┌─ Infra Layer ───┐ │
|
|
207
|
+
│ │ OpenClawAdapter · RuntimeRegistry │ │ GatewayClient │ │
|
|
208
|
+
│ └──────────────────────────────────────────┘ │ (WS RPC) │ │
|
|
209
|
+
│ └────────┬────────┘ │
|
|
210
|
+
└──────────────────────────────────────────────────────────┼───────────┘
|
|
211
|
+
│
|
|
212
|
+
WebSocket RPC
|
|
213
|
+
│
|
|
214
|
+
▼
|
|
215
|
+
┌──────────────────────────┐
|
|
216
|
+
│ OpenClaw Gateway │
|
|
217
|
+
│ (Agent Runtime Platform)│
|
|
218
|
+
└──────────────────────────┘
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## 安装指南
|
|
224
|
+
|
|
225
|
+
### 方式一:pip安装
|
|
226
|
+
|
|
227
|
+
如果你只需要运行 Witty-Service,无需参与开发,可以直接通过 pip 安装:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
pip install witty-service
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
安装完成后即可使用 CLI 启动服务:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
witty-service --host 0.0.0.0 --port 8000
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
> **前置条件:** Python 3.11 或更高版本
|
|
240
|
+
|
|
241
|
+
### 方式二:从源码安装
|
|
242
|
+
|
|
243
|
+
如果你需要参与开发或自定义构建,请从源码安装:
|
|
244
|
+
|
|
245
|
+
**前置条件:**
|
|
246
|
+
|
|
247
|
+
| 依赖 | 说明 | 安装方式 |
|
|
248
|
+
|------|------|----------|
|
|
249
|
+
| Python | 3.11+ | [python.org](https://www.python.org/downloads/) |
|
|
250
|
+
| uv | Python 包管理器 | [docs.astral.sh/uv](https://docs.astral.sh/uv/) |
|
|
251
|
+
| Docker | 沙箱运行时(可选) | [docker.com](https://www.docker.com/) |
|
|
252
|
+
|
|
253
|
+
**安装步骤:**
|
|
254
|
+
|
|
255
|
+
1. 克隆仓库:
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
git clone https://github.com/witty/witty-service.git
|
|
259
|
+
cd witty-service
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
2. 创建虚拟环境并安装依赖:
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
uv venv
|
|
266
|
+
source .venv/bin/activate
|
|
267
|
+
uv pip install -e ".[dev]"
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
3. 验证安装:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
witty-service --help
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## 快速开始
|
|
279
|
+
|
|
280
|
+
**1. 启动服务**
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
witty-service --host 0.0.0.0 --port 8000
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
**2. 验证服务是否正常运行**
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
curl http://127.0.0.1:8000/healthz
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
期望返回:
|
|
293
|
+
|
|
294
|
+
```json
|
|
295
|
+
{"status": "ok"}
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
**3. 创建 Agent**
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
curl -s -X POST http://127.0.0.1:8000/agents \
|
|
302
|
+
-H 'content-type: application/json' \
|
|
303
|
+
-H 'authorization: Bearer dev-token' \
|
|
304
|
+
-d '{
|
|
305
|
+
"name": "my-agent",
|
|
306
|
+
"description": "我的第一个智能体",
|
|
307
|
+
"sandbox_type": "local_process",
|
|
308
|
+
"adapter_type": "openclaw",
|
|
309
|
+
"idle_timeout_seconds": 3600
|
|
310
|
+
}' | jq
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
**4. 发送消息**
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
AGENT_ID="<上一步返回的 id>"
|
|
317
|
+
SESSION_ID="<上一步返回的 default_session_id>"
|
|
318
|
+
|
|
319
|
+
curl -s -X POST "http://127.0.0.1:8000/agents/${AGENT_ID}/sessions/${SESSION_ID}/messages" \
|
|
320
|
+
-H 'content-type: application/json' \
|
|
321
|
+
-H 'authorization: Bearer dev-token' \
|
|
322
|
+
-d '{"content": "你好,请介绍一下你自己"}' | jq
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
> **提示:** 默认认证 Token 为 `dev-token`,生产环境请通过环境变量 `AUTH_TOKEN` 修改。
|
|
326
|
+
|
|
327
|
+
---
|
|
328
|
+
|
|
329
|
+
## 配置说明
|
|
330
|
+
|
|
331
|
+
Witty-Service 通过环境变量进行配置,无需额外配置文件。
|
|
332
|
+
|
|
333
|
+
### 核心配置
|
|
334
|
+
|
|
335
|
+
| 环境变量 | 说明 | 默认值 |
|
|
336
|
+
|----------|------|--------|
|
|
337
|
+
| `AUTH_TOKEN` | API 认证 Token | `dev-token` |
|
|
338
|
+
| `WITTY_AGENT_SERVER_APP_DIR` | Local Process 模式下 witty-agent-server 代码目录 | 空 |
|
|
339
|
+
|
|
340
|
+
### Docker 沙箱配置
|
|
341
|
+
|
|
342
|
+
| 环境变量 | 说明 | 默认值 |
|
|
343
|
+
|----------|------|--------|
|
|
344
|
+
| `WITTY_DOCKER_HOST` | Docker 服务监听地址 | `127.0.0.1` |
|
|
345
|
+
| `WITTY_DOCKER_IMAGE` | 镜像名(不含 tag) | `witty-agent-server` |
|
|
346
|
+
| `WITTY_DOCKER_IMAGE_TAG` | 镜像 tag | `latest` |
|
|
347
|
+
| `WITTY_DOCKER_CONTAINER_PORT` | 容器内服务端口 | `8080` |
|
|
348
|
+
| `WITTY_DOCKER_CONTAINER_WORKSPACE_PATH` | 容器内工作区路径 | `/witty-workspace` |
|
|
349
|
+
| `WITTY_DOCKER_STOP_TIMEOUT` | 容器停止超时(秒) | `10` |
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
## 部署流程
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
### 测试环境
|
|
357
|
+
|
|
358
|
+
适用于集成测试和功能验证:
|
|
359
|
+
|
|
360
|
+
```bash
|
|
361
|
+
# 构建 pip 包
|
|
362
|
+
uv build
|
|
363
|
+
|
|
364
|
+
# 安装构建产物
|
|
365
|
+
uv pip install dist/witty_service-0.1.0-py3-none-any.whl
|
|
366
|
+
|
|
367
|
+
# 启动服务
|
|
368
|
+
witty-service --host 0.0.0.0 --port 8000
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
运行测试:
|
|
372
|
+
|
|
373
|
+
```bash
|
|
374
|
+
# 单元测试
|
|
375
|
+
uv run pytest tests/unit/ -q
|
|
376
|
+
|
|
377
|
+
# E2E 测试
|
|
378
|
+
uv run pytest tests/e2e/ -q
|
|
379
|
+
|
|
380
|
+
# 全量测试
|
|
381
|
+
uv run pytest tests/ -q
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### 生产环境
|
|
385
|
+
|
|
386
|
+
**方式一:pip 安装(推荐)**
|
|
387
|
+
|
|
388
|
+
```bash
|
|
389
|
+
pip install witty-service
|
|
390
|
+
|
|
391
|
+
# 多 worker 启动
|
|
392
|
+
witty-service --host 0.0.0.0 --port 8000 --workers 4
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
**方式二:从源码构建**
|
|
396
|
+
|
|
397
|
+
```bash
|
|
398
|
+
git clone https://github.com/witty/witty-service.git
|
|
399
|
+
cd witty-service
|
|
400
|
+
uv build
|
|
401
|
+
uv pip install dist/witty_service-0.1.0-py3-none-any.whl
|
|
402
|
+
|
|
403
|
+
witty-service --host 0.0.0.0 --port 8000 --workers 4
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
### 启动参数说明
|
|
407
|
+
|
|
408
|
+
| 参数 | 说明 | 默认值 |
|
|
409
|
+
|------|------|--------|
|
|
410
|
+
| `--host` | 绑定的主机地址 | `0.0.0.0` |
|
|
411
|
+
| `--port` | 绑定的端口 | `8000` |
|
|
412
|
+
| `--log-level` | 日志级别(debug/info/warning/error/critical) | `info` |
|
|
413
|
+
| `--reload` | 开发模式自动重载 | `False` |
|
|
414
|
+
| `--workers` | 工作进程数 | `1` |
|
|
415
|
+
|
|
416
|
+
### 生产环境注意事项
|
|
417
|
+
|
|
418
|
+
- **认证 Token** — 务必通过 `AUTH_TOKEN` 环境变量修改默认值,使用强随机字符串
|
|
419
|
+
- **Worker 数量** — 根据 CPU 核心数合理设置 `--workers`
|
|
420
|
+
- **反向代理** — 推荐在 Witty-Service 前部署 Nginx 等反向代理,配置 HTTPS 证书
|
|
421
|
+
- **进程管理** — 建议使用 systemd 或 Supervisor 管理服务进程,实现自动重启
|
|
422
|
+
- **数据库迁移** — 部署新版本前,执行 `alembic upgrade head` 完成数据库迁移
|
|
423
|
+
|
|
424
|
+
---
|
|
425
|
+
|
|
426
|
+
## 本地开发
|
|
427
|
+
|
|
428
|
+
### 环境搭建
|
|
429
|
+
|
|
430
|
+
```bash
|
|
431
|
+
# 1. 克隆仓库
|
|
432
|
+
git clone https://github.com/witty/witty-service.git
|
|
433
|
+
cd witty-service
|
|
434
|
+
|
|
435
|
+
# 2. 创建虚拟环境并安装依赖
|
|
436
|
+
uv venv
|
|
437
|
+
source .venv/bin/activate
|
|
438
|
+
uv pip install -e ".[dev]"
|
|
439
|
+
|
|
440
|
+
# 3. 初始化数据库
|
|
441
|
+
alembic upgrade head
|
|
442
|
+
|
|
443
|
+
# 4. 启动开发服务器
|
|
444
|
+
uv run uvicorn src.witty_service.main:create_app --factory --host 0.0.0.0 --port 8000 --reload
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
### 项目结构
|
|
448
|
+
|
|
449
|
+
```
|
|
450
|
+
witty-service/
|
|
451
|
+
├── src/
|
|
452
|
+
│ ├── witty_service/ # 主服务包
|
|
453
|
+
│ │ ├── main.py # FastAPI 应用入口
|
|
454
|
+
│ │ ├── cli.py # CLI 入口
|
|
455
|
+
│ │ ├── config.py # 配置管理
|
|
456
|
+
│ │ ├── api/ # API 路由层
|
|
457
|
+
│ │ │ ├── agents.py # Agent 相关接口
|
|
458
|
+
│ │ │ ├── models.py # 模型配置接口
|
|
459
|
+
│ │ │ ├── skills.py # 技能管理接口
|
|
460
|
+
│ │ │ ├── cve.py # CVE 漏洞接口
|
|
461
|
+
│ │ │ ├── backport.py # 代码回溯接口
|
|
462
|
+
│ │ │ ├── auth.py # 认证中间件
|
|
463
|
+
│ │ │ ├── errors.py # 统一错误处理
|
|
464
|
+
│ │ │ └── schemas.py # 请求/响应模型
|
|
465
|
+
│ │ ├── application/ # 业务逻辑层
|
|
466
|
+
│ │ │ ├── agent_manager.py # Agent 生命周期管理
|
|
467
|
+
│ │ │ ├── session_manager.py # 会话管理
|
|
468
|
+
│ │ │ └── skill_manager.py # 技能管理
|
|
469
|
+
│ │ ├── adapter/ # 适配器层(与 witty-agent-server 通信)
|
|
470
|
+
│ │ │ ├── websocket_client.py # WebSocket 客户端
|
|
471
|
+
│ │ │ ├── websocket_protocol.py # WebSocket 协议定义
|
|
472
|
+
│ │ │ └── http_client.py # HTTP 客户端
|
|
473
|
+
│ │ ├── sandbox/ # 沙箱层
|
|
474
|
+
│ │ │ ├── base.py # 沙箱基类
|
|
475
|
+
│ │ │ ├── docker.py # Docker 沙箱
|
|
476
|
+
│ │ │ ├── local_process.py # 本地进程沙箱
|
|
477
|
+
│ │ │ ├── e2b.py # E2B 云沙箱
|
|
478
|
+
│ │ │ └── factory.py # 沙箱工厂
|
|
479
|
+
│ │ ├── domain/ # 领域模型
|
|
480
|
+
│ │ ├── persistence/ # 数据持久化
|
|
481
|
+
│ │ └── storage/ # 文件存储
|
|
482
|
+
│ └── witty_agent_server/ # Agent 运行时服务
|
|
483
|
+
│ ├── app.py # FastAPI 应用
|
|
484
|
+
│ ├── api/routers/ # API 路由
|
|
485
|
+
│ ├── application/services/ # 业务服务
|
|
486
|
+
│ │ ├── agent/ # Agent 服务
|
|
487
|
+
│ │ ├── session/ # Session 服务
|
|
488
|
+
│ │ └── skill/ # 技能服务
|
|
489
|
+
│ ├── runtimes/ # 运行时实现
|
|
490
|
+
│ ├── adapters/ # 运行时适配器
|
|
491
|
+
│ └── infra/ # 基础设施
|
|
492
|
+
├── tests/
|
|
493
|
+
│ ├── unit/ # 单元测试
|
|
494
|
+
│ └── e2e/ # 端到端测试
|
|
495
|
+
├── alembic/ # 数据库迁移
|
|
496
|
+
├── docs/ # 文档
|
|
497
|
+
├── pyproject.toml # 项目配置
|
|
498
|
+
└── .github/workflows/ # CI/CD 工作流
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
### 常用开发命令
|
|
502
|
+
|
|
503
|
+
| 命令 | 说明 |
|
|
504
|
+
|------|------|
|
|
505
|
+
| `uv run uvicorn src.witty_service.main:create_app --factory --reload` | 启动开发服务器(热重载) |
|
|
506
|
+
| `uv run pytest tests/unit/ -q` | 运行单元测试 |
|
|
507
|
+
| `uv run pytest tests/e2e/ -q` | 运行 E2E 测试 |
|
|
508
|
+
| `uv run pytest tests/ -q` | 运行全量测试 |
|
|
509
|
+
| `uv build` | 构建 pip 包 |
|
|
510
|
+
| `alembic revision --autogenerate -m "description"` | 生成数据库迁移脚本 |
|
|
511
|
+
| `alembic upgrade head` | 执行数据库迁移 |
|
|
512
|
+
|
|
513
|
+
### 代码贡献流程
|
|
514
|
+
|
|
515
|
+
1. Fork 本仓库
|
|
516
|
+
2. 创建功能分支:`git checkout -b feature/your-feature`
|
|
517
|
+
3. 提交更改:`git commit -m 'feat: add your feature'`
|
|
518
|
+
4. 推送分支:`git push origin feature/your-feature`
|
|
519
|
+
5. 提交 Pull Request
|
|
520
|
+
|
|
521
|
+
### 开发规范
|
|
522
|
+
|
|
523
|
+
- **代码风格** — 遵循 Black 格式化规范(line-length=88),提交前运行 `black .` 检查
|
|
524
|
+
- **类型检查** — 使用 mypy 进行静态类型检查,配置为 strict 模式
|
|
525
|
+
- **提交规范** — 使用语义化提交信息(如 `feat:`、`fix:`、`docs:`、`refactor:`)
|
|
526
|
+
- **测试覆盖** — 新增功能需编写对应的单元测试,确保测试通过
|
|
527
|
+
- **数据库迁移** — 涉及模型变更时,需生成对应的 Alembic 迁移脚本
|
|
528
|
+
|
|
529
|
+
---
|
|
530
|
+
|
|
531
|
+
## 许可证
|
|
532
|
+
|
|
533
|
+
本项目基于 [MIT 许可证](LICENSE) 开源。
|
|
534
|
+
|
|
535
|
+
## 支持与反馈
|
|
536
|
+
|
|
537
|
+
- **问题反馈** — 请在 [GitHub Issues](https://github.com/witty/witty-service/issues) 提交
|
|
538
|
+
- **功能建议** — 欢迎通过 Issue 或 Pull Request 参与
|
|
539
|
+
- **项目主页** — [https://github.com/witty/witty-service](https://github.com/witty/witty-service)
|