turbo-agent-store 0.1.0.dev1__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.
Files changed (57) hide show
  1. turbo_agent_store-0.1.0.dev1/PKG-INFO +16 -0
  2. turbo_agent_store-0.1.0.dev1/README.md +320 -0
  3. turbo_agent_store-0.1.0.dev1/pyproject.toml +30 -0
  4. turbo_agent_store-0.1.0.dev1/setup.cfg +4 -0
  5. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/__init__.py +127 -0
  6. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/cli.py +183 -0
  7. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/data/cache/__init__.py +19 -0
  8. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/data/cache/cache.py +53 -0
  9. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/data/cache/event_broker.py +49 -0
  10. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/data/cache/execution.py +273 -0
  11. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/data/config/__init__.py +15 -0
  12. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/data/config/config.py +285 -0
  13. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/event_archiver.py +46 -0
  14. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/event_constants.py +14 -0
  15. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/event_consumer.py +722 -0
  16. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/files/git/__init__.py +15 -0
  17. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/files/git/file.py +177 -0
  18. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/files/resource/__init__.py +45 -0
  19. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/files/resource/local.py +318 -0
  20. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/files/resource/manager.py +304 -0
  21. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/files/resource/models.py +202 -0
  22. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/files/resource/worker.py +312 -0
  23. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/files/workspace/__init__.py +5 -0
  24. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/files/workspace/local_git.py +589 -0
  25. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/rag/init_index.py +708 -0
  26. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/rag/init_index_manticore.py +770 -0
  27. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/rag/schema.py +75 -0
  28. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/runtime/git_server.py +461 -0
  29. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/runtime/worker/__init__.py +17 -0
  30. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/runtime/worker/env_builder.py +437 -0
  31. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/services/export_service.py +302 -0
  32. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/services/package_loader.py +312 -0
  33. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/settings.py +80 -0
  34. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/utils/analyze_json.py +69 -0
  35. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/utils/cos_access.py +268 -0
  36. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/utils/docling_client.py +352 -0
  37. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/utils/docx_converter.py +258 -0
  38. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/utils/grid_layout_calculator.py +708 -0
  39. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/utils/json_repair.py +24 -0
  40. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/utils/manticore_search.py +644 -0
  41. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/utils/parse_url.py +68 -0
  42. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/utils/rag_chunk.py +449 -0
  43. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/utils/schema_tool.py +110 -0
  44. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/utils/search_migration.py +88 -0
  45. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store/utils/timer.py +10 -0
  46. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store.egg-info/PKG-INFO +16 -0
  47. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store.egg-info/SOURCES.txt +55 -0
  48. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store.egg-info/dependency_links.txt +1 -0
  49. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store.egg-info/entry_points.txt +2 -0
  50. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store.egg-info/requires.txt +12 -0
  51. turbo_agent_store-0.1.0.dev1/src/turbo_agent_store.egg-info/top_level.txt +1 -0
  52. turbo_agent_store-0.1.0.dev1/tests/test_character_versions.py +24 -0
  53. turbo_agent_store-0.1.0.dev1/tests/test_data_stream_consumer_dispatch.py +110 -0
  54. turbo_agent_store-0.1.0.dev1/tests/test_event_broker_memory.py +23 -0
  55. turbo_agent_store-0.1.0.dev1/tests/test_event_stream_monitor.py +62 -0
  56. turbo_agent_store-0.1.0.dev1/tests/test_new_crud_interfaces.py +177 -0
  57. turbo_agent_store-0.1.0.dev1/tests/test_provider_manual.py +62 -0
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.4
2
+ Name: turbo-agent-store
3
+ Version: 0.1.0.dev1
4
+ Summary: 存储模块的技术实现层,提供 Memory/YAML/Git 三种技术路线的实现
5
+ Author: Turbo-Agent
6
+ Requires-Python: >=3.10
7
+ Requires-Dist: typer>=0.9.0
8
+ Requires-Dist: rich>=13.0.0
9
+ Requires-Dist: python-dotenv>=1.0.0
10
+ Requires-Dist: loguru<0.8.0,>=0.7.3
11
+ Requires-Dist: pyyaml>=6.0.1
12
+ Requires-Dist: turbo-agent-core>=1.0.0
13
+ Provides-Extra: gitpython
14
+ Requires-Dist: GitPython>=3.1.0; extra == "gitpython"
15
+ Provides-Extra: all
16
+ Requires-Dist: GitPython>=3.1.0; extra == "all"
@@ -0,0 +1,320 @@
1
+ # Turbo Agent Store
2
+
3
+ 存储模块的技术实现层,面向四个不同层次的需求提供实现。
4
+
5
+ ## 设计哲学
6
+
7
+ > **重要说明**:四个技术路线面向不同层次的需求,**不是并行的存储后端选择**。
8
+
9
+ ### 1. Memory - 内存缓存
10
+
11
+ **用途**:运行时缓存、临时数据存储
12
+
13
+ **实现**:
14
+ - `InMemoryCacheStore` - BaseCacheStore 的内存实现
15
+ - `InMemoryExecutionStore` - BaseExecutionStore 的内存降级实现
16
+ - `MemoryQueueEventBroker` - BaseEventBroker 的内存队列实现
17
+
18
+ **特点**:
19
+ - 不持久化,进程重启后数据丢失
20
+ - 用于单元测试、本地调试、临时缓存降级
21
+ - 保证接口可用与最小幂等(以 id 做覆盖/更新)
22
+
23
+ **不是**:持久化存储方案
24
+
25
+ ### 2. YAML - 结构化数据导出
26
+
27
+ **用途**:基于 core schema 的结构化导出/导入
28
+
29
+ **实现**:
30
+ - `YAMLConfigStore` - BaseConfigStore 的 YAML 文件实现
31
+
32
+ **特点**:
33
+ - 保持与 core schema 的一致性
34
+ - 用于配置备份、跨环境数据迁移
35
+ - 版本控制友好(文本格式、可读性强)
36
+ - 实现数据在不同业务线产品间的流转
37
+
38
+ **不是**:持久化存储后端,而是**数据流转格式**
39
+
40
+ ### 3. Resource - 文件资源管理
41
+
42
+ **用途**:KnowledgeResource 文件存储(上传资源、解析结果)
43
+
44
+ **实现**:
45
+ - `LocalResourceStore` - 本地文件系统实现
46
+ - `MinIOResourceStore` (cloud 模块) - MinIO 对象存储实现
47
+
48
+ **存储路径**:
49
+ ```
50
+ {user_id}/{context_id}/{resource_id}/
51
+ ├── original/{filename} # 原始上传文件
52
+ ├── parsed/ # 解析结果(预留)
53
+ └── chunks/ # 分块数据(预留)
54
+ ```
55
+
56
+ **Context 类型**:
57
+ - `session_{id}` - 对话临时文件
58
+ - `project_{id}` - 项目文件
59
+ - `temp_{id}` - 临时目录
60
+
61
+ **特点**:
62
+ - Worker 只读访问
63
+ - Server 可写
64
+ - 用于上传文档、图片、数据文件等
65
+
66
+ ### 4. Workspace - 工作区版本管理
67
+
68
+ **用途**:代码/文件的 Git 版本管理
69
+
70
+ **实现**:
71
+ - `LocalGitWorkspaceStore` - 本地 Git 实现
72
+ - `RemoteGitWorkspaceStore` (cloud 模块,规划中) - 远程 Git 服务器
73
+
74
+ **场景**:
75
+ - 用户上传工作区(zip 包)
76
+ - 在线编辑代码文件
77
+ - Agent 生成代码/配置文件
78
+ - 开发 Tool/Character 的代码逻辑
79
+
80
+ **目录结构**:
81
+ ```
82
+ {base_path}/{user_id}/{workspace_id}/
83
+ ├── .git/ # Git 版本控制
84
+ ├── files/ # 工作文件(Git 跟踪)
85
+ │ ├── main.py
86
+ │ └── config.yaml
87
+ └── .meta/ # 元数据索引
88
+ └── manifest.json
89
+ ```
90
+
91
+ **特点**:
92
+ - 完整 Git 版本控制
93
+ - Worker 可读写
94
+ - 支持历史追溯、版本回退、分支标签
95
+
96
+ ---
97
+
98
+ ## 架构关系
99
+
100
+ ```
101
+ turbo-agent-core (纯抽象)
102
+
103
+ ├── BaseConfigStore ──┬──> [cloud] PrismaConfigStore (持久化)
104
+ │ └──> [store] YAMLConfigStore (导出)
105
+
106
+ ├── BaseFileStore ────┬──> [cloud] 对象存储实现
107
+ │ └──> [store] GitFileStore (旧版工作空间)
108
+
109
+ ├── BaseCacheStore ───┬──> [cloud] RedisCacheStore
110
+ │ └──> [store] InMemoryCacheStore (降级)
111
+
112
+ ├── BaseExecutionStore ──> [store] InMemoryExecutionStore (降级)
113
+
114
+ ├── ResourceStore ────┬──> [cloud] MinIOResourceStore (生产)
115
+ │ └──> [store] LocalResourceStore (开发)
116
+
117
+ └── WorkspaceStore ───┬──> [cloud] RemoteGitWorkspaceStore (规划)
118
+ └──> [store] LocalGitWorkspaceStore (本地)
119
+ ```
120
+
121
+ **依赖规则**:
122
+ - `turbo-agent-store` 只依赖 `turbo-agent-core`
123
+ - 具体业务 DTOs 由各产品线自行定义
124
+ - 持久化存储由各场景模块自行实现(如 cloud 模块的 Prisma/MinIO 实现)
125
+
126
+ ---
127
+
128
+ ## Worker 环境管理
129
+
130
+ ### 使用场景
131
+
132
+ Worker 执行任务前需要准备执行环境:
133
+ 1. 下载 KnowledgeResource 文件(只读)
134
+ 2. 检出 Workspace 文件(可读写)
135
+ 3. 生成环境配置
136
+
137
+ ### 环境目录结构
138
+
139
+ ```
140
+ /tmp/worker_{task_id}/
141
+ ├── resources/ # KnowledgeResource 文件(只读)
142
+ │ └── {resource_id}/
143
+ │ └── {filename}
144
+ ├── workspace/ # Workspace 文件(可读写)
145
+ │ ├── .git/
146
+ │ └── files/
147
+ │ ├── main.py
148
+ │ └── config.yaml
149
+ ├── output/ # 输出目录
150
+ ├── manifest.json # 环境清单
151
+ └── .env # 环境变量
152
+ ```
153
+
154
+ ### 使用示例
155
+
156
+ ```python
157
+ from turbo_agent_store import (
158
+ LocalResourceStore,
159
+ LocalGitWorkspaceStore,
160
+ WorkerEnvironmentBuilder,
161
+ ResourceRef,
162
+ WorkspaceRef,
163
+ )
164
+
165
+ # 创建 Builder
166
+ builder = WorkerEnvironmentBuilder(
167
+ resource_store=LocalResourceStore("/data/resources"),
168
+ workspace_store_factory=lambda wid, uid: LocalGitWorkspaceStore(wid, uid, "/data/workspaces")
169
+ )
170
+
171
+ # 准备环境
172
+ env = await builder.prepare(
173
+ task_id="task_001",
174
+ resource_refs=[
175
+ ResourceRef(
176
+ resource_id="res_123",
177
+ user_id="user_001",
178
+ context_id="session_abc",
179
+ filename="document.pdf",
180
+ path="user_001/session_abc/res_123/original/document.pdf"
181
+ )
182
+ ],
183
+ workspace_ref=WorkspaceRef(
184
+ workspace_id="ws_001",
185
+ user_id="user_001",
186
+ ref="HEAD",
187
+ files=["main.py", "config.yaml"] # 或 None 表示全部
188
+ )
189
+ )
190
+
191
+ # 使用环境
192
+ print(f"Resources: {env.resources_path}")
193
+ print(f"Workspace: {env.workspace_path}")
194
+
195
+ # CharacterRuntime 使用
196
+ runtime = CharacterRuntime(
197
+ resources_path=env.resources_path,
198
+ workspace_path=env.workspace_path
199
+ )
200
+ result = await runtime.execute(task)
201
+
202
+ # 归档输出
203
+ await builder.archive_output(env, workspace_store)
204
+
205
+ # 清理环境
206
+ await builder.cleanup(env)
207
+ ```
208
+
209
+ ### 上下文管理器
210
+
211
+ ```python
212
+ # 使用 async with 自动管理生命周期
213
+ async with WorkerEnvironmentContext(
214
+ builder=builder,
215
+ task_id="task_001",
216
+ resource_refs=[...],
217
+ workspace_ref=WorkspaceRef(...)
218
+ ) as env:
219
+ # 环境已准备好
220
+ result = await runtime.execute(env)
221
+ # 自动清理
222
+ ```
223
+
224
+ ---
225
+
226
+ ## Git 服务器
227
+
228
+ 本地运行时可启动 Git 服务器供远程访问。
229
+
230
+ ### 使用示例
231
+
232
+ ```python
233
+ from turbo_agent_store import GitServer, GitServerConfig, GitWorkspaceSync
234
+
235
+ # 配置 Git 服务器
236
+ config = GitServerConfig(
237
+ base_path="/data/git_server",
238
+ enable_daemon=True,
239
+ daemon_port=9418
240
+ )
241
+
242
+ # 创建服务器
243
+ server = GitServer(config)
244
+
245
+ # 创建裸仓库
246
+ repo_path = server.create_bare_repository("user_123", "workspace_001")
247
+
248
+ # 启动 daemon
249
+ server.start_daemon()
250
+
251
+ # 获取 Git URL
252
+ url = server.get_git_url("user_123", "workspace_001", protocol="git")
253
+ # 返回: git://0.0.0.0:9418/user_123/workspace_001.git
254
+
255
+ # 同步本地工作区到服务器
256
+ sync = GitWorkspaceSync(server)
257
+ sync.push_to_server("user_123", "workspace_001")
258
+
259
+ # 停止 daemon
260
+ server.stop_daemon()
261
+ ```
262
+
263
+ ---
264
+
265
+ ## 安装
266
+
267
+ ```bash
268
+ # 基础安装
269
+ pip install turbo-agent-store
270
+
271
+ # 包含 Git 支持
272
+ pip install turbo-agent-store[git]
273
+
274
+ # 包含所有依赖
275
+ pip install turbo-agent-store[all]
276
+ ```
277
+
278
+ ---
279
+
280
+ ## CLI 使用
281
+
282
+ ```bash
283
+ # 验证 Zip 包
284
+ ta-store verify package.zip
285
+
286
+ # 格式转换
287
+ ta-store convert input.yaml output.json --format json
288
+
289
+ # 打包配置
290
+ ta-store pack create ./configs --output export.zip
291
+
292
+ # 解压配置
293
+ ta-store pack extract export.zip --output-dir ./extracted
294
+ ```
295
+
296
+ **注意**:数据库相关的命令(如 `init-db`, `export agent`)已移动到 `turbo-agent-cloud` 模块。
297
+
298
+ ---
299
+
300
+ ## 与其他模块的关系
301
+
302
+ | 模块 | 职责 | 依赖 |
303
+ |------|------|------|
304
+ | `turbo-agent-core` | 纯抽象定义、Schema | 无 |
305
+ | `turbo-agent-store` | 技术实现层(Memory/YAML/Git/Resource/Workspace) | core |
306
+ | `turbo-agent-cloud` | 云场景持久化实现(Prisma/MinIO/RemoteGit) | core + store |
307
+ | `turbo-agent-server` | HTTP API 服务 | cloud + store |
308
+ | `turbo-agent-job` | 任务调度与执行 | core + store + runtime |
309
+
310
+ ---
311
+
312
+ ## 迁移指南
313
+
314
+ 从旧版本迁移:
315
+
316
+ 1. **Prisma 相关功能** → 使用 `turbo-agent-cloud`
317
+ 2. **YAML 导出/导入** → 继续使用 `turbo-agent-store`
318
+ 3. **文件上传下载** → 使用新的 `ResourceStore` 接口
319
+ 4. **工作区版本管理** → 使用新的 `WorkspaceStore` 接口
320
+ 5. **GitFileStore** → 继续使用(旧版),或迁移到 `LocalGitWorkspaceStore`(新版)
@@ -0,0 +1,30 @@
1
+ [project]
2
+ name = "turbo-agent-store"
3
+ version = "0.1.0.dev1"
4
+ description = "存储模块的技术实现层,提供 Memory/YAML/Git 三种技术路线的实现"
5
+ authors = [ { name = "Turbo-Agent" } ]
6
+ requires-python = ">=3.10"
7
+ dependencies = [
8
+ "typer>=0.9.0",
9
+ "rich>=13.0.0",
10
+ "python-dotenv>=1.0.0",
11
+ "loguru>=0.7.3,<0.8.0",
12
+ "pyyaml>=6.0.1",
13
+ "turbo-agent-core>=1.0.0"
14
+ ]
15
+
16
+ [project.optional-dependencies]
17
+ # Git 文件存储支持
18
+ GitPython = ["GitPython>=3.1.0"]
19
+ # 完整功能
20
+ all = ["GitPython>=3.1.0"]
21
+
22
+ [project.scripts]
23
+ ta-store = "turbo_agent_store.cli:app"
24
+
25
+ [tool.uv]
26
+ package = true
27
+
28
+ [build-system]
29
+ requires = ["setuptools", "wheel"]
30
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,127 @@
1
+ """turbo-agent-store
2
+
3
+ 存储模块的技术实现层,面向不同需求提供实现:
4
+
5
+ 1. **Cache** - 内存缓存实现
6
+ - 用途:运行时缓存、临时数据存储
7
+ - 实现:InMemoryCacheStore, InMemoryExecutionStore
8
+
9
+ 2. **Config** - 结构化数据导出
10
+ - 用途:基于 core schema 的结构化导出
11
+ - 实现:YAMLConfigStore
12
+
13
+ 3. **Git** - 工作空间文件版本管理
14
+ - 用途:Agent 工作空间文件的版本管理
15
+ - 实现:GitFileStore, LocalGitWorkspaceStore
16
+
17
+ 4. **Resource** - 知识资源文件管理
18
+ - 用途:KnowledgeResource 文件存储、解析
19
+ - 实现:KnowledgeResourceManager, AnalysisWorker
20
+
21
+ 5. **Workspace** - 工作区文件管理
22
+ - 用途:Workset/Workspace Git 操作
23
+ - 实现:LocalGitWorkspaceStore
24
+
25
+ 6. **Worker** - 执行环境管理
26
+ - 用途:Worker 环境准备与清理
27
+ - 实现:WorkerEnvironmentBuilder, WorkerEnvironment
28
+
29
+ 7. **GitServer** - Git 服务器管理
30
+ - 用途:本地 Git 服务器初始化与管理
31
+ - 实现:GitServer, GitWorkspaceSync
32
+
33
+ 注意:
34
+ - 纯抽象定义在 turbo_agent_core.store 中
35
+ - 持久化存储由 cloud 模块实现(MinIO, Prisma)
36
+ """
37
+
38
+ from turbo_agent_core.store import (
39
+ BaseFileStore,
40
+ BaseExecutionStore,
41
+ BaseCacheStore,
42
+ BaseEventBroker,
43
+ BaseAssembler,
44
+ # 新增文件存储抽象
45
+ ResourceStore,
46
+ ResourceInfo,
47
+ WorkspaceStore,
48
+ FileInfo,
49
+ CommitInfo,
50
+ TagInfo,
51
+ )
52
+
53
+ # Data 存储能力
54
+ from .data.cache.cache import InMemoryCacheStore
55
+ from .data.cache.execution import InMemoryExecutionStore
56
+ from .data.cache.event_broker import MemoryQueueEventBroker
57
+
58
+ # Files 存储能力
59
+ from .files.git.file import GitFileStore
60
+ from .files.resource import (
61
+ KnowledgeType,
62
+ FileType,
63
+ ResourceStatus,
64
+ AnalysisStatus,
65
+ AnalysisJob,
66
+ ResourceMetadata,
67
+ KnowledgeResourceUploadRequest,
68
+ KnowledgeResourceManager,
69
+ AnalysisWorker,
70
+ process_knowledge_resource_analysis,
71
+ )
72
+ from .files.workspace import LocalGitWorkspaceStore
73
+
74
+ # Runtime 执行环境能力
75
+ from .runtime.worker import (
76
+ WorkerEnvironment,
77
+ WorkerEnvironmentBuilder,
78
+ WorkerEnvironmentContext,
79
+ ResourceRef,
80
+ WorkspaceRef,
81
+ )
82
+ from .runtime.git_server import GitServer, GitServerConfig, GitWorkspaceSync
83
+
84
+ __all__ = [
85
+ # 纯抽象 (from core)
86
+ "BaseFileStore",
87
+ "BaseExecutionStore",
88
+ "BaseCacheStore",
89
+ "BaseEventBroker",
90
+ "BaseAssembler",
91
+ # 新增抽象
92
+ "ResourceStore",
93
+ "ResourceInfo",
94
+ "WorkspaceStore",
95
+ "FileInfo",
96
+ "CommitInfo",
97
+ "TagInfo",
98
+ # Cache 实现
99
+ "InMemoryCacheStore",
100
+ "InMemoryExecutionStore",
101
+ "MemoryQueueEventBroker",
102
+ # Git 实现(旧版)
103
+ "GitFileStore",
104
+ # Resource 知识资源管理
105
+ "KnowledgeType",
106
+ "FileType",
107
+ "ResourceStatus",
108
+ "AnalysisStatus",
109
+ "AnalysisJob",
110
+ "ResourceMetadata",
111
+ "KnowledgeResourceUploadRequest",
112
+ "KnowledgeResourceManager",
113
+ "AnalysisWorker",
114
+ "process_knowledge_resource_analysis",
115
+ # Workspace
116
+ "LocalGitWorkspaceStore",
117
+ # Worker 环境管理
118
+ "WorkerEnvironment",
119
+ "WorkerEnvironmentBuilder",
120
+ "WorkerEnvironmentContext",
121
+ "ResourceRef",
122
+ "WorkspaceRef",
123
+ # Git 服务器管理
124
+ "GitServer",
125
+ "GitServerConfig",
126
+ "GitWorkspaceSync",
127
+ ]
@@ -0,0 +1,183 @@
1
+ """
2
+ Store 模块 CLI
3
+
4
+ 提供 YAML 格式的配置导出/导入功能。
5
+ 注意:数据库相关的命令已移动到 turbo-agent-cloud 模块。
6
+ """
7
+
8
+ import os
9
+ import typer
10
+ import yaml
11
+ import json
12
+ import zipfile
13
+ from datetime import datetime
14
+ from pathlib import Path
15
+ from typing import Optional
16
+ from rich.console import Console
17
+ from rich.table import Table
18
+ from loguru import logger
19
+
20
+ from turbo_agent_store.services.package_loader import PackageLoader
21
+
22
+ app = typer.Typer()
23
+ console = Console()
24
+
25
+
26
+ # ===== Verify Command =====
27
+
28
+ @app.command()
29
+ def verify(
30
+ package_path: str = typer.Argument(..., help="Zip 包路径"),
31
+ ):
32
+ """
33
+ 验证 Zip 包并尝试加载到内存。
34
+ 检查包内 YAML 文件的格式和依赖关系。
35
+ """
36
+ if not os.path.exists(package_path):
37
+ console.print(f"[red]文件不存在: {package_path}[/red]")
38
+ raise typer.Exit(code=1)
39
+
40
+ try:
41
+ loader = PackageLoader()
42
+ entities = loader.load(package_path)
43
+
44
+ table = Table(title=f"包内容: {os.path.basename(package_path)}")
45
+ table.add_column("Type", style="cyan")
46
+ table.add_column("ID", style="magenta")
47
+ table.add_column("Name")
48
+ table.add_column("Dependencies")
49
+
50
+ for entity in entities:
51
+ deps = []
52
+ if hasattr(entity, 'model') and entity.model:
53
+ deps.append(f"Model:{entity.model.name}")
54
+ if hasattr(entity, 'tools') and entity.tools:
55
+ deps.append(f"Tools:{len(entity.tools)}")
56
+
57
+ table.add_row(
58
+ entity.__class__.__name__,
59
+ entity.id,
60
+ entity.name,
61
+ ", ".join(deps)
62
+ )
63
+
64
+ console.print(table)
65
+ console.print(f"[green]成功加载 {len(entities)} 个实体[/green]")
66
+
67
+ except Exception as e:
68
+ console.print(f"[red]加载失败: {e}[/red]")
69
+ import traceback
70
+ traceback.print_exc()
71
+ raise typer.Exit(code=1)
72
+
73
+
74
+ # ===== Convert Command =====
75
+
76
+ @app.command()
77
+ def convert(
78
+ input_path: str = typer.Argument(..., help="输入 YAML/JSON 文件路径"),
79
+ output_path: str = typer.Argument(..., help="输出文件路径"),
80
+ format: str = typer.Option("yaml", help="输出格式: yaml 或 json"),
81
+ ):
82
+ """
83
+ 在不同格式间转换配置文件。
84
+ 用于格式标准化和数据迁移。
85
+ """
86
+ input_file = Path(input_path)
87
+ if not input_file.exists():
88
+ console.print(f"[red]输入文件不存在: {input_path}[/red]")
89
+ raise typer.Exit(code=1)
90
+
91
+ try:
92
+ # 读取输入
93
+ with open(input_file, 'r', encoding='utf-8') as f:
94
+ if input_path.endswith('.json'):
95
+ data = json.load(f)
96
+ else:
97
+ data = yaml.safe_load(f)
98
+
99
+ # 写入输出
100
+ output_file = Path(output_path)
101
+ output_file.parent.mkdir(parents=True, exist_ok=True)
102
+
103
+ with open(output_file, 'w', encoding='utf-8') as f:
104
+ if format.lower() == 'json':
105
+ json.dump(data, f, indent=2, ensure_ascii=False)
106
+ else:
107
+ yaml.dump(data, f, allow_unicode=True, sort_keys=False)
108
+
109
+ console.print(f"[green]已转换: {input_path} -> {output_path}[/green]")
110
+
111
+ except Exception as e:
112
+ console.print(f"[red]转换失败: {e}[/red]")
113
+ raise typer.Exit(code=1)
114
+
115
+
116
+ # ===== Package Command =====
117
+
118
+ pack_app = typer.Typer()
119
+ app.add_typer(pack_app, name="pack", help="打包/解包配置")
120
+
121
+
122
+ @pack_app.command("create")
123
+ def pack_create(
124
+ source_dir: str = typer.Argument(..., help="源目录路径(包含 YAML 文件)"),
125
+ output: str = typer.Option("export.zip", help="输出 Zip 文件路径"),
126
+ ):
127
+ """
128
+ 将 YAML 配置目录打包为 Zip 包。
129
+ """
130
+ source_path = Path(source_dir)
131
+ if not source_path.exists():
132
+ console.print(f"[red]源目录不存在: {source_dir}[/red]")
133
+ raise typer.Exit(code=1)
134
+
135
+ try:
136
+ output_file = Path(output)
137
+ output_file.parent.mkdir(parents=True, exist_ok=True)
138
+
139
+ with zipfile.ZipFile(output_file, 'w', zipfile.ZIP_DEFLATED) as zf:
140
+ yaml_files = list(source_path.rglob("*.yaml")) + list(source_path.rglob("*.yml"))
141
+
142
+ for file_path in yaml_files:
143
+ rel_path = file_path.relative_to(source_path)
144
+ zf.write(file_path, arcname=str(rel_path))
145
+ console.print(f" 添加: {rel_path}")
146
+
147
+ console.print(f"[green]已创建包: {output}[/green]")
148
+ console.print(f" 共 {len(yaml_files)} 个 YAML 文件")
149
+
150
+ except Exception as e:
151
+ console.print(f"[red]打包失败: {e}[/red]")
152
+ raise typer.Exit(code=1)
153
+
154
+
155
+ @pack_app.command("extract")
156
+ def pack_extract(
157
+ package_path: str = typer.Argument(..., help="Zip 包路径"),
158
+ output_dir: str = typer.Option("./extracted", help="输出目录"),
159
+ ):
160
+ """
161
+ 解压 Zip 包到目录。
162
+ """
163
+ package_file = Path(package_path)
164
+ if not package_file.exists():
165
+ console.print(f"[red]包文件不存在: {package_path}[/red]")
166
+ raise typer.Exit(code=1)
167
+
168
+ try:
169
+ output_path = Path(output_dir)
170
+ output_path.mkdir(parents=True, exist_ok=True)
171
+
172
+ with zipfile.ZipFile(package_file, 'r') as zf:
173
+ zf.extractall(output_path)
174
+
175
+ console.print(f"[green]已解压到: {output_dir}[/green]")
176
+
177
+ except Exception as e:
178
+ console.print(f"[red]解压失败: {e}[/red]")
179
+ raise typer.Exit(code=1)
180
+
181
+
182
+ if __name__ == "__main__":
183
+ app()
@@ -0,0 +1,19 @@
1
+ """
2
+ Memory 实现层
3
+
4
+ 用于内存缓存和临时存储,不持久化。
5
+ 适用于:
6
+ - 单元测试
7
+ - 本地调试
8
+ - 临时缓存降级
9
+ """
10
+
11
+ from .cache import InMemoryCacheStore
12
+ from .execution import InMemoryExecutionStore
13
+ from .event_broker import MemoryQueueEventBroker
14
+
15
+ __all__ = [
16
+ "InMemoryCacheStore",
17
+ "InMemoryExecutionStore",
18
+ "MemoryQueueEventBroker",
19
+ ]