txcode-sdk 0.2.0__tar.gz → 0.4.1__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 (168) hide show
  1. txcode_sdk-0.4.1/PKG-INFO +256 -0
  2. txcode_sdk-0.4.1/README.md +231 -0
  3. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/pyproject.toml +4 -1
  4. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/setup.py +6 -1
  5. txcode_sdk-0.4.1/src/example/ws_server.py +105 -0
  6. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/__init__.py +17 -1
  7. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/client.py +32 -0
  8. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/provider/base.py +4 -0
  9. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/provider/openai_provider.py +4 -0
  10. txcode_sdk-0.4.1/src/txcode_sdk/server/__init__.py +5 -0
  11. txcode_sdk-0.4.1/src/txcode_sdk/server/__main__.py +212 -0
  12. txcode_sdk-0.4.1/src/txcode_sdk/server/handler.py +562 -0
  13. txcode_sdk-0.4.1/src/txcode_sdk/server/http.py +606 -0
  14. txcode_sdk-0.4.1/src/txcode_sdk/server/json_store.py +50 -0
  15. txcode_sdk-0.4.1/src/txcode_sdk/server/project_manager.py +120 -0
  16. txcode_sdk-0.4.1/src/txcode_sdk/server/provider_config.py +346 -0
  17. txcode_sdk-0.4.1/src/txcode_sdk/server/server.py +100 -0
  18. txcode_sdk-0.4.1/src/txcode_sdk/server/websocket.py +217 -0
  19. txcode_sdk-0.4.1/src/txcode_sdk.egg-info/PKG-INFO +256 -0
  20. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk.egg-info/SOURCES.txt +20 -1
  21. txcode_sdk-0.4.1/src/txcode_sdk.egg-info/entry_points.txt +2 -0
  22. txcode_sdk-0.4.1/tests/test_cli.py +253 -0
  23. txcode_sdk-0.4.1/tests/test_client.py +206 -0
  24. txcode_sdk-0.4.1/tests/test_http_api.py +682 -0
  25. txcode_sdk-0.4.1/tests/test_json_store.py +99 -0
  26. txcode_sdk-0.4.1/tests/test_project_manager.py +122 -0
  27. txcode_sdk-0.4.1/tests/test_provider_config.py +248 -0
  28. txcode_sdk-0.4.1/tests/test_provider_model.py +77 -0
  29. txcode_sdk-0.4.1/tests/test_websocket_protocol.py +218 -0
  30. txcode_sdk-0.4.1/tests/test_ws_server.py +1040 -0
  31. txcode_sdk-0.2.0/PKG-INFO +0 -66
  32. txcode_sdk-0.2.0/README.md +0 -41
  33. txcode_sdk-0.2.0/src/txcode_sdk.egg-info/PKG-INFO +0 -66
  34. txcode_sdk-0.2.0/tests/test_client.py +0 -37
  35. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/LICENSE +0 -0
  36. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/setup.cfg +0 -0
  37. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/example/__init__.py +0 -0
  38. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/example/code_example.py +0 -0
  39. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/example/code_session.py +0 -0
  40. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/example/code_tool.py +0 -0
  41. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/example/constants.py +0 -0
  42. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/example/query_session.py +0 -0
  43. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/_compat/__init__.py +0 -0
  44. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/_compat/dataclasses.py +0 -0
  45. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/_compat/resources.py +0 -0
  46. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/__init__.py +0 -0
  47. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/base_agent.py +0 -0
  48. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/chat/__init__.py +0 -0
  49. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/chat/agent_tool.py +0 -0
  50. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/chat/chat_agent.py +0 -0
  51. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/chat/prompts/__init__.py +0 -0
  52. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/chat/prompts/role.txt +0 -0
  53. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/code/__init__.py +0 -0
  54. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/code/agent_tool.py +0 -0
  55. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/code/code_agent.py +0 -0
  56. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/code/prompts/__init__.py +0 -0
  57. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/code/prompts/role.txt +0 -0
  58. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/common/__init__.py +0 -0
  59. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/common/common_agent.py +0 -0
  60. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/common/prompt/__init__.py +0 -0
  61. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/common/prompt/role.txt +0 -0
  62. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/design/__init__.py +0 -0
  63. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/design/agent_tool.py +0 -0
  64. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/design/design_agent.py +0 -0
  65. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/design/prompts/__init__.py +0 -0
  66. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/design/prompts/role.txt +0 -0
  67. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/discuss/__init__.py +0 -0
  68. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/discuss/agent_tool.py +0 -0
  69. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/discuss/discuss_agent.py +0 -0
  70. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/discuss/prompts/__init__.py +0 -0
  71. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/discuss/prompts/role.txt +0 -0
  72. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/dream/__init__.py +0 -0
  73. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/dream/agent_tool.py +0 -0
  74. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/dream/dream_agent.py +0 -0
  75. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/dream/prompts/__init__.py +0 -0
  76. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/dream/prompts/role.txt +0 -0
  77. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/mem/__init__.py +0 -0
  78. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/mem/agent_tool.py +0 -0
  79. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/mem/mem_agent.py +0 -0
  80. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/mem/prompts/__init__.py +0 -0
  81. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/mem/prompts/role.txt +0 -0
  82. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/name/__init__.py +0 -0
  83. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/name/name_agent.py +0 -0
  84. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/name/prompts/__init__.py +0 -0
  85. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/name/prompts/role.txt +0 -0
  86. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/plan/__init__.py +0 -0
  87. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/plan/agent_tool.py +0 -0
  88. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/plan/plan_agent.py +0 -0
  89. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/plan/prompts/__init__.py +0 -0
  90. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/plan/prompts/role.txt +0 -0
  91. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/shell/__init__.py +0 -0
  92. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/shell/agent_tool.py +0 -0
  93. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/shell/prompts/__init__.py +0 -0
  94. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/shell/prompts/role.txt +0 -0
  95. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/shell/shell_agent.py +0 -0
  96. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/skill/__init__.py +0 -0
  97. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/skill/agent_tool.py +0 -0
  98. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/skill/prompts/__init__.py +0 -0
  99. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/skill/prompts/role.txt +0 -0
  100. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/skill/skill_agent.py +0 -0
  101. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/summarizer/__init__.py +0 -0
  102. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/summarizer/prompts/__init__.py +0 -0
  103. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/summarizer/prompts/role.txt +0 -0
  104. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/summarizer/summarizer_agent.py +0 -0
  105. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/task/__init__.py +0 -0
  106. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/task/agent_tool.py +0 -0
  107. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/task/prompts/__init__.py +0 -0
  108. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/task/prompts/role.txt +0 -0
  109. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/task/task_agent.py +0 -0
  110. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/test/__init__.py +0 -0
  111. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/test/agent_tool.py +0 -0
  112. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/test/prompts/__init__.py +0 -0
  113. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/test/prompts/role.txt +0 -0
  114. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/test/test_agent.py +0 -0
  115. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/agent/tool_registry.py +0 -0
  116. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/compact/__init__.py +0 -0
  117. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/compact/compressor.py +0 -0
  118. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/hooks/__init__.py +0 -0
  119. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/hooks/handlers/__init__.py +0 -0
  120. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/hooks/handlers/base.py +0 -0
  121. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/hooks/handlers/memory.py +0 -0
  122. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/hooks/processor.py +0 -0
  123. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/hooks/queue.py +0 -0
  124. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/hooks/types.py +0 -0
  125. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/provider/__init__.py +0 -0
  126. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/provider/deepseek_provider.py +0 -0
  127. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/provider/router.py +0 -0
  128. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/provider/txcode_ai.py +0 -0
  129. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/session/__init__.py +0 -0
  130. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/session/manager.py +0 -0
  131. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/skills/__init__.py +0 -0
  132. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/specs/__init__.py +0 -0
  133. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/tools/__init__.py +0 -0
  134. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/tools/bash.txt +0 -0
  135. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/tools/bash_tool.py +0 -0
  136. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/tools/edit_file.py +0 -0
  137. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/tools/edit_file.txt +0 -0
  138. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/tools/glob.txt +0 -0
  139. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/tools/glob_tool.py +0 -0
  140. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/tools/grep.txt +0 -0
  141. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/tools/grep_tool.py +0 -0
  142. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/tools/memory_tool.py +0 -0
  143. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/tools/read_file.py +0 -0
  144. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/tools/read_file.txt +0 -0
  145. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/tools/todo_read.py +0 -0
  146. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/tools/todo_read.txt +0 -0
  147. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/tools/todo_write.py +0 -0
  148. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/tools/todo_write.txt +0 -0
  149. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/tools/web_shell_exec.py +0 -0
  150. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/tools/web_shell_exec.txt +0 -0
  151. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/tools/write_file.py +0 -0
  152. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/tools/write_file.txt +0 -0
  153. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk/types.py +0 -0
  154. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk.egg-info/dependency_links.txt +0 -0
  155. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/src/txcode_sdk.egg-info/top_level.txt +0 -0
  156. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/tests/test_compat.py +0 -0
  157. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/tests/test_design_agent.py +0 -0
  158. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/tests/test_discuss_agent.py +0 -0
  159. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/tests/test_dream_agent.py +0 -0
  160. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/tests/test_name_agent.py +0 -0
  161. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/tests/test_plan_agent.py +0 -0
  162. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/tests/test_session.py +0 -0
  163. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/tests/test_session_query.py +0 -0
  164. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/tests/test_shell_agent.py +0 -0
  165. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/tests/test_skill_agent.py +0 -0
  166. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/tests/test_test_agent.py +0 -0
  167. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/tests/test_tools.py +0 -0
  168. {txcode_sdk-0.2.0 → txcode_sdk-0.4.1}/tests/test_txcode_ai.py +0 -0
@@ -0,0 +1,256 @@
1
+ Metadata-Version: 2.4
2
+ Name: txcode-sdk
3
+ Version: 0.4.1
4
+ Summary: AI Agent SDK with built-in tools for Python projects
5
+ Author: homecommunity
6
+ License: MIT
7
+ Project-URL: Repository, https://github.com/homecommunity/txcode-sdk
8
+ Keywords: ai,agent,openai,tools,react
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.6
14
+ Classifier: Programming Language :: Python :: 3.7
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Requires-Python: >=3.6
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Dynamic: license-file
24
+ Dynamic: requires-python
25
+
26
+ # txcode-sdk
27
+
28
+ AI Agent SDK with built-in tools for Python projects.
29
+
30
+ ## Installation
31
+
32
+ - 要求:**Python >= 3.6**(含 3.6/3.7/3.8/3.9/3.10/3.11/3.12)
33
+ - **零第三方运行时依赖**(仅标准库,适合门禁设备等离线环境)
34
+
35
+ ```bash
36
+ pip install txcode-sdk
37
+ ```
38
+
39
+ ## Quick Start
40
+
41
+ ```python
42
+ import asyncio
43
+ from txcode_sdk import TxCodeClient
44
+
45
+ async def main():
46
+ client = TxCodeClient(
47
+ api_key="sk-xxx",
48
+ base_url="https://api.openai.com/v1",
49
+ model="gpt-4",
50
+ )
51
+ result = await client.chat("Hello!")
52
+ print(result.answer)
53
+
54
+ asyncio.get_event_loop().run_until_complete(main())
55
+ ```
56
+
57
+ ## Features
58
+
59
+ - ReAct Agent loop with tool calling
60
+ - Multiple agent types: code, chat, common, task, plan, shell, skill, test, design, discuss, dream, name
61
+ - 10 built-in tools: read_file, write_file, edit_file, glob, grep, bash, memory, web_shell_exec, todo_read, todo_write
62
+ - Session management with JSON file persistence
63
+ - Context compression for long conversations
64
+ - Multimodal input support (images)
65
+ - Extensible custom tools
66
+ - Self-developed HTTP client (urllib, no openai/tiktoken dependency), supports OpenAI / DeepSeek / any OpenAI-compatible API
67
+
68
+ ## WebSocket Server
69
+
70
+ SDK 内置零第三方依赖的 WebSocket 服务端(RFC 6455 自研协议层,Python 3.6 兼容),
71
+ 支持 **txcode 桌面版远程连接**:把 SDK 安装到门禁 ARM 设备(Ubuntu 18 / Python 3.6)后,
72
+ Agent 循环与全部内置工具(read_file / write_file / edit_file / glob / grep / bash / todo 等)
73
+ 在**设备本地执行**,桌面版仅作为远程操作界面——实现"直接在门禁系统上开发门禁系统代码"。
74
+
75
+ ### 一条命令启动(主推)
76
+
77
+ ```bash
78
+ pip install txcode-sdk
79
+
80
+ export TXCODE_API_KEY=sk-xxx
81
+ export TXCODE_BASE_URL=https://api.openai.com/v1 # 可选,默认 OpenAI(仅首次启动)
82
+ export TXCODE_MODEL=gpt-4 # 可选,默认 gpt-4(仅首次启动)
83
+
84
+ txcode-sdk serve --work-dir /opt/door-access --host 0.0.0.0 --port 41000 \
85
+ --models "gpt-4o,DeepSeek V3=deepseek-chat" # 可选:默认供应商初始模型列表
86
+ ```
87
+
88
+ - `--work-dir`:门禁代码目录(**必填**,仅首次启动无当前项目时注册为当前项目),Agent 与内置工具在此目录下本地执行
89
+ - `--host` / `--port`:默认 `0.0.0.0:41000`
90
+ - `--agent-type`:默认 `code`
91
+ - `--models`:默认供应商初始模型列表 `[显示名=]模型名` 逗号分隔(仅首次注册默认供应商时使用);缺省读 `TXCODE_MODELS`,再缺省 = 不限制
92
+ - `TXCODE_API_KEY`:**可选**——仅当 `~/.txcode/providers.json` 不存在且希望首次自动注册默认供应商时使用;未设置时服务以**空配置**正常启动(stderr 打印 WARN 提示),供应商由桌面端通过 WS `add_provider` / `switch_provider` 动态添加,无需重启
93
+ - 兜底启动:`python -m txcode_sdk.server serve --work-dir ...`(无脚本路径时同样可用)
94
+
95
+ ### 启动装配(JSON 为权威源,0.4.1)
96
+
97
+ 服务启动时以用户层 JSON 为权威源恢复上次状态,**重启自动恢复上次激活供应商/模型与当前项目**:
98
+
99
+ 1. **供应商**:加载 `~/.txcode/providers.json`——存在则取激活供应商的 `(api_key, base_url, model)` 直接构造
100
+ `TxCodeClient`(不读 `TXCODE_BASE_URL` / `TXCODE_MODEL`);不存在(首次启动/全新环境)且设置了
101
+ `TXCODE_API_KEY`(可选)时以 `TXCODE_BASE_URL` / `TXCODE_MODEL` 注册默认供应商并激活(`--models` 作为初始模型列表);
102
+ **未设置 `TXCODE_API_KEY` 时以空配置正常启动**(占位 client,不发起任何 API 请求),
103
+ 供应商由桌面端经 WS `add_provider` / `switch_provider` 动态添加;未配置供应商前 `chat` / `name_session`
104
+ 会收到「No active provider configured」提示,其余能力(WS 握手、ping、配置/项目管理消息)全部可用
105
+ 2. **项目**:加载 `~/.txcode/projects.json`——有当前项目则其 `path` 作为 work_dir(不读 `TXCODE_WORK_DIR`);
106
+ 无当前项目则 `--work-dir` 注册为当前项目后使用
107
+
108
+ 配置(供应商/模型/项目列表)存**用户层 `~/.txcode/`**,跨项目共享、切换项目不影响;
109
+ 会话仍按项目分别存于各自工作目录 `{work_dir}/.txcode/session/`。
110
+
111
+ ### 桌面版连接
112
+
113
+ 1. 桌面版「主机管理」添加远程主机:IP = 门禁设备 IP,端口 = 41000
114
+ 2. 桌面版自动以 `ws://{ip}:{port}/ws/code` 连接(无需任何桌面版改动)
115
+ 3. 发起对话:AI 在门禁系统本地读写文件、执行 `bash` 编译/运行/调试代码
116
+ 4. 文件变更实时推送(`file:changed` 事件),前端自动刷新文件树与编辑器
117
+
118
+ ### 协议消息
119
+
120
+ | 方向 | type | data |
121
+ |---|---|---|
122
+ | C→S | `chat` | message, sessionId, mediaFiles, agent, modelName(可选:命中即切换供应商/模型) |
123
+ | C→S | `stop` | sessionId(中断运行中会话) |
124
+ | C→S | `ping` | - |
125
+ | C→S | `get_running_sessions` | -(桌面版 5s 轮询) |
126
+ | C→S | `name_session` | sessionId, folderName, userInput |
127
+ | C→S | `get_providers` / `get_models` | - |
128
+ | C→S | `add_provider` | name, base_url, api_key, models |
129
+ | C→S | `update_provider` | providerId, name?, base_url?, api_key?, models? |
130
+ | C→S | `delete_provider` | providerId |
131
+ | C→S | `add_model` / `delete_model` | providerId, name / modelName |
132
+ | C→S | `switch_provider` | providerId, modelName? |
133
+ | C→S | `get_projects` | - |
134
+ | C→S | `open_project` | name, path |
135
+ | C→S | `select_project` / `delete_project` | projectId |
136
+ | S→C | `connected` / `step` / `compact` / `done` / `stopped` / `error` / `running_sessions` / `pong` / `rename` | 见下 |
137
+ | S→C | `providers_list` / `model_list` | get_providers / get_models 响应(仅发送方) |
138
+ | S→C | `providers_changed` | 供应商/模型增删改广播(全局) |
139
+ | S→C | `model_changed` | 模型/供应商切换成功广播(全局),data: {providerName, modelName, model} |
140
+ | S→C | `projects_list` | get_projects 响应(仅发送方) |
141
+ | S→C | `projects_changed` / `project_changed` | 项目列表变更 / 当前项目切换广播(全局) |
142
+
143
+ ### 供应商与模型管理
144
+
145
+ 服务端支持**动态添加/编辑/删除多个供应商**(OpenAI / DeepSeek / 自建网关),配置实时持久化到用户层
146
+ `~/.txcode/providers.json`,服务重启自动恢复;聊天消息携带 `modelName` 命中即切换(自动匹配供应商),
147
+ 也可用 `switch_provider` 显式切换。
148
+
149
+ `~/.txcode/providers.json` 结构(配置在用户层,跨项目共享,**不随 work_dir 变化**):
150
+
151
+ ```json
152
+ {
153
+ "providers": [
154
+ {
155
+ "id": "3f2a...",
156
+ "name": "OpenAI",
157
+ "base_url": "https://api.openai.com/v1",
158
+ "api_key": "sk-xxx",
159
+ "models": [{"name": "gpt-4o", "display_name": "GPT-4o"}],
160
+ "created_at": "2026-08-14T...",
161
+ "updated_at": "2026-08-14T..."
162
+ }
163
+ ],
164
+ "active_provider_id": "3f2a...",
165
+ "active_model": "gpt-4o"
166
+ }
167
+ ```
168
+
169
+ - **模型限制规则**:供应商 `models` 为空列表 = 不限制(向后兼容);非空 = 白名单校验
170
+ - **显示名**:`display_name` 对齐桌面版模型选择器语义(如 `DeepSeek V3` = `deepseek-chat`),
171
+ 匹配 name 与 display_name 双通道;`add_model` 缺省 display_name = name
172
+ - **api_key 安全**:WS 协议返回打码值(`sk-***` + 后 4 位);`update_provider` 传打码值/空不改原 key;
173
+ 明文仅存于用户层本地文件(权限建议 `chmod 600`)
174
+ - **模型解析定序**:激活供应商优先 → 跨供应商按列表顺序第一个命中 → 未限制放行 → 全未命中回
175
+ `error: Model not allowed: xxx, available: [..]`
176
+
177
+ ### 项目管理
178
+
179
+ 远程模式下桌面版右上角「打开项目 / 选择项目」由 SDK 侧 WS 协议提供等价能力:项目列表 / 打开(目录校验)/
180
+ 选择(切换当前项目)/ 删除(不删实际文件),数据持久化到用户层 `~/.txcode/projects.json`(跨项目记忆);
181
+ 选择/打开项目后 SDK 实时切换 `work_dir`(Agent 与内置工具基准目录立即生效,切换前中断全部运行中会话)。
182
+
183
+ `~/.txcode/projects.json` 结构:
184
+
185
+ ```json
186
+ {
187
+ "projects": [
188
+ {"id": "a1b2...", "name": "door-access", "path": "/opt/door-access",
189
+ "created_at": "2026-08-14T...", "updated_at": "2026-08-14T..."}
190
+ ],
191
+ "current_project_id": "a1b2..."
192
+ }
193
+ ```
194
+
195
+ > 安全边界:供应商 `api_key` 明文存于用户层 `~/.txcode/providers.json`(本地文件,与 TS 版 sys_config
196
+ > 数据库同等级别),仅限内网/受信网络部署,建议 `chmod 600`;WS 协议无鉴权,建议防火墙限制端口来源。
197
+
198
+ `step` 事件数据形状(对齐桌面版):
199
+
200
+ ```json
201
+ {
202
+ "type": "step",
203
+ "data": {
204
+ "reasoning": "...",
205
+ "toolCalls": [{"id": "call-1", "type": "function", "function": {"name": "bash", "arguments": "{\"command\": \"python3 main.py\"}"}, "status": "completed"}],
206
+ "success": true,
207
+ "iteration": 1,
208
+ "sessionId": "xxx",
209
+ "usage": {"promptTokens": 10, "completionTokens": 5, "totalTokens": 15}
210
+ }
211
+ }
212
+ ```
213
+
214
+ ### 自定义工具(进阶,需写代码)
215
+
216
+ `txcode-sdk serve` CLI **只支持内置工具**(远程开发场景完全够用)。
217
+ 需要对接门禁硬件控制(`open_door` / `get_door_status` 等)时,走进阶示例
218
+ [`src/example/ws_server.py`](src/example/ws_server.py):注册自定义工具 + 启动 `TxCodeServer`。
219
+
220
+ ```python
221
+ import asyncio
222
+ from txcode_sdk import Tool, ToolResult, TxCodeClient
223
+ from txcode_sdk.server import TxCodeServer
224
+
225
+ def open_door(args, ctx):
226
+ return ToolResult(success=True, output="door opened")
227
+
228
+ client = TxCodeClient(
229
+ api_key="sk-xxx", work_dir="/opt/door-access",
230
+ tools=[Tool(name="open_door", description="打开门禁",
231
+ parameters={"type": "object", "properties": {}}, execute=open_door)],
232
+ )
233
+ server = TxCodeServer(client, host="0.0.0.0", port=41000)
234
+ asyncio.get_event_loop().run_until_complete(server.start())
235
+ asyncio.get_event_loop().run_forever()
236
+ ```
237
+
238
+ ### 门禁系统部署(Ubuntu 18 / ARM)
239
+
240
+ ```bash
241
+ # 1. 安装(离线可先下载 wheel 拷贝)
242
+ pip install txcode-sdk
243
+ python3 -c "import txcode_sdk; print(txcode_sdk.__version__)"
244
+
245
+ # 2. 验证端口监听
246
+ txcode-sdk serve --work-dir /opt/door-access &
247
+ ss -ltn | grep 41000
248
+
249
+ # 3. systemd 常驻(/etc/systemd/system/txcode-sdk.service)
250
+ # [Service] Environment=TXCODE_API_KEY=sk-xxx
251
+ # ExecStart=/usr/local/bin/txcode-sdk serve --work-dir /opt/door-access
252
+ # Restart=always
253
+ ```
254
+
255
+ > 安全边界:协议无鉴权(与桌面版/TS 版一致),仅限内网/受信网络部署,
256
+ > 建议防火墙限制 41000 端口来源;鉴权(token 校验)列为二期增强。
@@ -0,0 +1,231 @@
1
+ # txcode-sdk
2
+
3
+ AI Agent SDK with built-in tools for Python projects.
4
+
5
+ ## Installation
6
+
7
+ - 要求:**Python >= 3.6**(含 3.6/3.7/3.8/3.9/3.10/3.11/3.12)
8
+ - **零第三方运行时依赖**(仅标准库,适合门禁设备等离线环境)
9
+
10
+ ```bash
11
+ pip install txcode-sdk
12
+ ```
13
+
14
+ ## Quick Start
15
+
16
+ ```python
17
+ import asyncio
18
+ from txcode_sdk import TxCodeClient
19
+
20
+ async def main():
21
+ client = TxCodeClient(
22
+ api_key="sk-xxx",
23
+ base_url="https://api.openai.com/v1",
24
+ model="gpt-4",
25
+ )
26
+ result = await client.chat("Hello!")
27
+ print(result.answer)
28
+
29
+ asyncio.get_event_loop().run_until_complete(main())
30
+ ```
31
+
32
+ ## Features
33
+
34
+ - ReAct Agent loop with tool calling
35
+ - Multiple agent types: code, chat, common, task, plan, shell, skill, test, design, discuss, dream, name
36
+ - 10 built-in tools: read_file, write_file, edit_file, glob, grep, bash, memory, web_shell_exec, todo_read, todo_write
37
+ - Session management with JSON file persistence
38
+ - Context compression for long conversations
39
+ - Multimodal input support (images)
40
+ - Extensible custom tools
41
+ - Self-developed HTTP client (urllib, no openai/tiktoken dependency), supports OpenAI / DeepSeek / any OpenAI-compatible API
42
+
43
+ ## WebSocket Server
44
+
45
+ SDK 内置零第三方依赖的 WebSocket 服务端(RFC 6455 自研协议层,Python 3.6 兼容),
46
+ 支持 **txcode 桌面版远程连接**:把 SDK 安装到门禁 ARM 设备(Ubuntu 18 / Python 3.6)后,
47
+ Agent 循环与全部内置工具(read_file / write_file / edit_file / glob / grep / bash / todo 等)
48
+ 在**设备本地执行**,桌面版仅作为远程操作界面——实现"直接在门禁系统上开发门禁系统代码"。
49
+
50
+ ### 一条命令启动(主推)
51
+
52
+ ```bash
53
+ pip install txcode-sdk
54
+
55
+ export TXCODE_API_KEY=sk-xxx
56
+ export TXCODE_BASE_URL=https://api.openai.com/v1 # 可选,默认 OpenAI(仅首次启动)
57
+ export TXCODE_MODEL=gpt-4 # 可选,默认 gpt-4(仅首次启动)
58
+
59
+ txcode-sdk serve --work-dir /opt/door-access --host 0.0.0.0 --port 41000 \
60
+ --models "gpt-4o,DeepSeek V3=deepseek-chat" # 可选:默认供应商初始模型列表
61
+ ```
62
+
63
+ - `--work-dir`:门禁代码目录(**必填**,仅首次启动无当前项目时注册为当前项目),Agent 与内置工具在此目录下本地执行
64
+ - `--host` / `--port`:默认 `0.0.0.0:41000`
65
+ - `--agent-type`:默认 `code`
66
+ - `--models`:默认供应商初始模型列表 `[显示名=]模型名` 逗号分隔(仅首次注册默认供应商时使用);缺省读 `TXCODE_MODELS`,再缺省 = 不限制
67
+ - `TXCODE_API_KEY`:**可选**——仅当 `~/.txcode/providers.json` 不存在且希望首次自动注册默认供应商时使用;未设置时服务以**空配置**正常启动(stderr 打印 WARN 提示),供应商由桌面端通过 WS `add_provider` / `switch_provider` 动态添加,无需重启
68
+ - 兜底启动:`python -m txcode_sdk.server serve --work-dir ...`(无脚本路径时同样可用)
69
+
70
+ ### 启动装配(JSON 为权威源,0.4.1)
71
+
72
+ 服务启动时以用户层 JSON 为权威源恢复上次状态,**重启自动恢复上次激活供应商/模型与当前项目**:
73
+
74
+ 1. **供应商**:加载 `~/.txcode/providers.json`——存在则取激活供应商的 `(api_key, base_url, model)` 直接构造
75
+ `TxCodeClient`(不读 `TXCODE_BASE_URL` / `TXCODE_MODEL`);不存在(首次启动/全新环境)且设置了
76
+ `TXCODE_API_KEY`(可选)时以 `TXCODE_BASE_URL` / `TXCODE_MODEL` 注册默认供应商并激活(`--models` 作为初始模型列表);
77
+ **未设置 `TXCODE_API_KEY` 时以空配置正常启动**(占位 client,不发起任何 API 请求),
78
+ 供应商由桌面端经 WS `add_provider` / `switch_provider` 动态添加;未配置供应商前 `chat` / `name_session`
79
+ 会收到「No active provider configured」提示,其余能力(WS 握手、ping、配置/项目管理消息)全部可用
80
+ 2. **项目**:加载 `~/.txcode/projects.json`——有当前项目则其 `path` 作为 work_dir(不读 `TXCODE_WORK_DIR`);
81
+ 无当前项目则 `--work-dir` 注册为当前项目后使用
82
+
83
+ 配置(供应商/模型/项目列表)存**用户层 `~/.txcode/`**,跨项目共享、切换项目不影响;
84
+ 会话仍按项目分别存于各自工作目录 `{work_dir}/.txcode/session/`。
85
+
86
+ ### 桌面版连接
87
+
88
+ 1. 桌面版「主机管理」添加远程主机:IP = 门禁设备 IP,端口 = 41000
89
+ 2. 桌面版自动以 `ws://{ip}:{port}/ws/code` 连接(无需任何桌面版改动)
90
+ 3. 发起对话:AI 在门禁系统本地读写文件、执行 `bash` 编译/运行/调试代码
91
+ 4. 文件变更实时推送(`file:changed` 事件),前端自动刷新文件树与编辑器
92
+
93
+ ### 协议消息
94
+
95
+ | 方向 | type | data |
96
+ |---|---|---|
97
+ | C→S | `chat` | message, sessionId, mediaFiles, agent, modelName(可选:命中即切换供应商/模型) |
98
+ | C→S | `stop` | sessionId(中断运行中会话) |
99
+ | C→S | `ping` | - |
100
+ | C→S | `get_running_sessions` | -(桌面版 5s 轮询) |
101
+ | C→S | `name_session` | sessionId, folderName, userInput |
102
+ | C→S | `get_providers` / `get_models` | - |
103
+ | C→S | `add_provider` | name, base_url, api_key, models |
104
+ | C→S | `update_provider` | providerId, name?, base_url?, api_key?, models? |
105
+ | C→S | `delete_provider` | providerId |
106
+ | C→S | `add_model` / `delete_model` | providerId, name / modelName |
107
+ | C→S | `switch_provider` | providerId, modelName? |
108
+ | C→S | `get_projects` | - |
109
+ | C→S | `open_project` | name, path |
110
+ | C→S | `select_project` / `delete_project` | projectId |
111
+ | S→C | `connected` / `step` / `compact` / `done` / `stopped` / `error` / `running_sessions` / `pong` / `rename` | 见下 |
112
+ | S→C | `providers_list` / `model_list` | get_providers / get_models 响应(仅发送方) |
113
+ | S→C | `providers_changed` | 供应商/模型增删改广播(全局) |
114
+ | S→C | `model_changed` | 模型/供应商切换成功广播(全局),data: {providerName, modelName, model} |
115
+ | S→C | `projects_list` | get_projects 响应(仅发送方) |
116
+ | S→C | `projects_changed` / `project_changed` | 项目列表变更 / 当前项目切换广播(全局) |
117
+
118
+ ### 供应商与模型管理
119
+
120
+ 服务端支持**动态添加/编辑/删除多个供应商**(OpenAI / DeepSeek / 自建网关),配置实时持久化到用户层
121
+ `~/.txcode/providers.json`,服务重启自动恢复;聊天消息携带 `modelName` 命中即切换(自动匹配供应商),
122
+ 也可用 `switch_provider` 显式切换。
123
+
124
+ `~/.txcode/providers.json` 结构(配置在用户层,跨项目共享,**不随 work_dir 变化**):
125
+
126
+ ```json
127
+ {
128
+ "providers": [
129
+ {
130
+ "id": "3f2a...",
131
+ "name": "OpenAI",
132
+ "base_url": "https://api.openai.com/v1",
133
+ "api_key": "sk-xxx",
134
+ "models": [{"name": "gpt-4o", "display_name": "GPT-4o"}],
135
+ "created_at": "2026-08-14T...",
136
+ "updated_at": "2026-08-14T..."
137
+ }
138
+ ],
139
+ "active_provider_id": "3f2a...",
140
+ "active_model": "gpt-4o"
141
+ }
142
+ ```
143
+
144
+ - **模型限制规则**:供应商 `models` 为空列表 = 不限制(向后兼容);非空 = 白名单校验
145
+ - **显示名**:`display_name` 对齐桌面版模型选择器语义(如 `DeepSeek V3` = `deepseek-chat`),
146
+ 匹配 name 与 display_name 双通道;`add_model` 缺省 display_name = name
147
+ - **api_key 安全**:WS 协议返回打码值(`sk-***` + 后 4 位);`update_provider` 传打码值/空不改原 key;
148
+ 明文仅存于用户层本地文件(权限建议 `chmod 600`)
149
+ - **模型解析定序**:激活供应商优先 → 跨供应商按列表顺序第一个命中 → 未限制放行 → 全未命中回
150
+ `error: Model not allowed: xxx, available: [..]`
151
+
152
+ ### 项目管理
153
+
154
+ 远程模式下桌面版右上角「打开项目 / 选择项目」由 SDK 侧 WS 协议提供等价能力:项目列表 / 打开(目录校验)/
155
+ 选择(切换当前项目)/ 删除(不删实际文件),数据持久化到用户层 `~/.txcode/projects.json`(跨项目记忆);
156
+ 选择/打开项目后 SDK 实时切换 `work_dir`(Agent 与内置工具基准目录立即生效,切换前中断全部运行中会话)。
157
+
158
+ `~/.txcode/projects.json` 结构:
159
+
160
+ ```json
161
+ {
162
+ "projects": [
163
+ {"id": "a1b2...", "name": "door-access", "path": "/opt/door-access",
164
+ "created_at": "2026-08-14T...", "updated_at": "2026-08-14T..."}
165
+ ],
166
+ "current_project_id": "a1b2..."
167
+ }
168
+ ```
169
+
170
+ > 安全边界:供应商 `api_key` 明文存于用户层 `~/.txcode/providers.json`(本地文件,与 TS 版 sys_config
171
+ > 数据库同等级别),仅限内网/受信网络部署,建议 `chmod 600`;WS 协议无鉴权,建议防火墙限制端口来源。
172
+
173
+ `step` 事件数据形状(对齐桌面版):
174
+
175
+ ```json
176
+ {
177
+ "type": "step",
178
+ "data": {
179
+ "reasoning": "...",
180
+ "toolCalls": [{"id": "call-1", "type": "function", "function": {"name": "bash", "arguments": "{\"command\": \"python3 main.py\"}"}, "status": "completed"}],
181
+ "success": true,
182
+ "iteration": 1,
183
+ "sessionId": "xxx",
184
+ "usage": {"promptTokens": 10, "completionTokens": 5, "totalTokens": 15}
185
+ }
186
+ }
187
+ ```
188
+
189
+ ### 自定义工具(进阶,需写代码)
190
+
191
+ `txcode-sdk serve` CLI **只支持内置工具**(远程开发场景完全够用)。
192
+ 需要对接门禁硬件控制(`open_door` / `get_door_status` 等)时,走进阶示例
193
+ [`src/example/ws_server.py`](src/example/ws_server.py):注册自定义工具 + 启动 `TxCodeServer`。
194
+
195
+ ```python
196
+ import asyncio
197
+ from txcode_sdk import Tool, ToolResult, TxCodeClient
198
+ from txcode_sdk.server import TxCodeServer
199
+
200
+ def open_door(args, ctx):
201
+ return ToolResult(success=True, output="door opened")
202
+
203
+ client = TxCodeClient(
204
+ api_key="sk-xxx", work_dir="/opt/door-access",
205
+ tools=[Tool(name="open_door", description="打开门禁",
206
+ parameters={"type": "object", "properties": {}}, execute=open_door)],
207
+ )
208
+ server = TxCodeServer(client, host="0.0.0.0", port=41000)
209
+ asyncio.get_event_loop().run_until_complete(server.start())
210
+ asyncio.get_event_loop().run_forever()
211
+ ```
212
+
213
+ ### 门禁系统部署(Ubuntu 18 / ARM)
214
+
215
+ ```bash
216
+ # 1. 安装(离线可先下载 wheel 拷贝)
217
+ pip install txcode-sdk
218
+ python3 -c "import txcode_sdk; print(txcode_sdk.__version__)"
219
+
220
+ # 2. 验证端口监听
221
+ txcode-sdk serve --work-dir /opt/door-access &
222
+ ss -ltn | grep 41000
223
+
224
+ # 3. systemd 常驻(/etc/systemd/system/txcode-sdk.service)
225
+ # [Service] Environment=TXCODE_API_KEY=sk-xxx
226
+ # ExecStart=/usr/local/bin/txcode-sdk serve --work-dir /opt/door-access
227
+ # Restart=always
228
+ ```
229
+
230
+ > 安全边界:协议无鉴权(与桌面版/TS 版一致),仅限内网/受信网络部署,
231
+ > 建议防火墙限制 41000 端口来源;鉴权(token 校验)列为二期增强。
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "txcode-sdk"
7
- version = "0.2.0"
7
+ version = "0.4.1"
8
8
  description = "AI Agent SDK with built-in tools for Python projects"
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
@@ -28,6 +28,9 @@ classifiers = [
28
28
  ]
29
29
  dependencies = []
30
30
 
31
+ [project.scripts]
32
+ txcode-sdk = "txcode_sdk.server.__main__:main"
33
+
31
34
  [project.urls]
32
35
  Repository = "https://github.com/homecommunity/txcode-sdk"
33
36
 
@@ -8,7 +8,7 @@ from setuptools import find_packages, setup
8
8
 
9
9
  setup(
10
10
  name="txcode-sdk",
11
- version="0.2.0",
11
+ version="0.4.1",
12
12
  description="AI Agent SDK with built-in tools for Python projects",
13
13
  long_description=open("README.md", encoding="utf-8").read(),
14
14
  long_description_content_type="text/markdown",
@@ -18,6 +18,11 @@ setup(
18
18
  package_dir={"": "src"},
19
19
  package_data={"txcode_sdk": ["**/*.txt"]},
20
20
  install_requires=[],
21
+ entry_points={
22
+ "console_scripts": [
23
+ "txcode-sdk=txcode_sdk.server.__main__:main",
24
+ ],
25
+ },
21
26
  classifiers=[
22
27
  "Development Status :: 3 - Alpha",
23
28
  "Intended Audience :: Developers",
@@ -0,0 +1,105 @@
1
+ """进阶示例:自定义门禁硬件工具(open_door 等)+ 启动 WebSocket 服务。
2
+
3
+ 场景:`txcode-sdk serve` CLI 只支持内置工具(本地远程开发足够);
4
+ 需要对接门禁硬件控制(open_door / get_door_status 等)时,用本示例代码注册自定义工具。
5
+
6
+ 0.4.0 起支持供应商/模型/项目管理:ProviderConfigManager / ProjectManager 可注入
7
+ `TxCodeServer`(缺省内部构造读用户层 `~/.txcode/providers.json` / `projects.json`);
8
+ 本示例展示注入形态与运行期 set_provider / set_work_dir 用法。
9
+
10
+ 环境变量:TXCODE_API_KEY(必填)/ TXCODE_BASE_URL / TXCODE_MODEL / TXCODE_WORK_DIR
11
+ (CLI `txcode-sdk serve` 走 JSON 权威源装配,见 README;本示例直接读环境变量构造 client)"""
12
+
13
+ import asyncio
14
+ import os
15
+ import sys
16
+
17
+ from txcode_sdk import Tool, ToolResult, TxCodeClient
18
+ from txcode_sdk.server import TxCodeServer
19
+ from txcode_sdk.server.provider_config import ProviderConfigManager
20
+ from txcode_sdk.server.project_manager import ProjectManager
21
+
22
+
23
+ def open_door(args, ctx):
24
+ """门禁硬件控制逻辑(示例:实际对接 GPIO/串口/继电器等)。"""
25
+ door_id = args.get("door_id", "main")
26
+ print("[open_door] opening door:", door_id)
27
+ return ToolResult(success=True, output="door %s opened" % door_id)
28
+
29
+
30
+ def get_door_status(args, ctx):
31
+ """查询门禁状态。"""
32
+ return ToolResult(success=True, output="closed")
33
+
34
+
35
+ def _get_event_loop():
36
+ """3.6/3.12 双版本兼容:已在运行 loop 则复用;否则新建(避免 3.12 弃用警告)。"""
37
+ if hasattr(asyncio, "get_running_loop"):
38
+ try:
39
+ return asyncio.get_running_loop()
40
+ except RuntimeError:
41
+ pass
42
+ loop = asyncio.new_event_loop()
43
+ asyncio.set_event_loop(loop)
44
+ return loop
45
+
46
+
47
+ def main() -> int:
48
+ api_key = os.environ.get("TXCODE_API_KEY", "").strip()
49
+ if not api_key:
50
+ sys.stderr.write(
51
+ "[txcode-sdk] ERROR: TXCODE_API_KEY is not set, run: export TXCODE_API_KEY=sk-xxx\n"
52
+ )
53
+ return 1
54
+
55
+ client = TxCodeClient(
56
+ api_key=api_key,
57
+ base_url=os.environ.get("TXCODE_BASE_URL", "https://api.openai.com/v1").strip() or "https://api.openai.com/v1",
58
+ model=os.environ.get("TXCODE_MODEL", "gpt-4").strip() or "gpt-4",
59
+ work_dir=os.environ.get("TXCODE_WORK_DIR", "/opt/door-access").strip() or "/opt/door-access",
60
+ agent_type="code",
61
+ tools=[
62
+ Tool(
63
+ name="open_door",
64
+ description="打开门禁(硬件控制)",
65
+ parameters={
66
+ "type": "object",
67
+ "properties": {"door_id": {"type": "string", "description": "门编号"}},
68
+ },
69
+ execute=open_door,
70
+ ),
71
+ Tool(
72
+ name="get_door_status",
73
+ description="获取门禁状态",
74
+ parameters={"type": "object", "properties": {}},
75
+ execute=get_door_status,
76
+ ),
77
+ ],
78
+ )
79
+
80
+ # 0.4.0:供应商/项目管理器注入 TxCodeServer(缺省读 ~/.txcode/providers.json / projects.json)
81
+ provider_config = ProviderConfigManager()
82
+ project_manager = ProjectManager()
83
+
84
+ server = TxCodeServer(
85
+ client,
86
+ host="0.0.0.0",
87
+ port=41000,
88
+ provider_config=provider_config,
89
+ project_manager=project_manager,
90
+ )
91
+ loop = _get_event_loop()
92
+ loop.run_until_complete(server.start())
93
+ print("[txcode-sdk] WebSocket server listening on ws://0.0.0.0:%d/ws/code" % server.port)
94
+ print("[txcode-sdk] work_dir:", client.work_dir)
95
+ try:
96
+ loop.run_forever()
97
+ except KeyboardInterrupt:
98
+ pass
99
+ finally:
100
+ loop.run_until_complete(server.stop())
101
+ return 0
102
+
103
+
104
+ if __name__ == "__main__":
105
+ sys.exit(main())
@@ -62,4 +62,20 @@ __all__ = [
62
62
  "TestAgent",
63
63
  ]
64
64
 
65
- __version__ = "0.2.0"
65
+ try:
66
+ from .server import TxCodeServer
67
+ __all__.append("TxCodeServer")
68
+ except Exception:
69
+ TxCodeServer = None
70
+
71
+ try:
72
+ from .server.provider_config import ProviderConfigManager
73
+ from .server.project_manager import ProjectManager
74
+ from .server.json_store import JsonStore
75
+ __all__ += ["ProviderConfigManager", "ProjectManager", "JsonStore"]
76
+ except Exception:
77
+ ProviderConfigManager = None
78
+ ProjectManager = None
79
+ JsonStore = None
80
+
81
+ __version__ = "0.4.1"