txcode-sdk 1.5.0__tar.gz → 1.7.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.
Files changed (224) hide show
  1. {txcode_sdk-1.5.0/src/txcode_sdk.egg-info → txcode_sdk-1.7.0}/PKG-INFO +16 -1
  2. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/README.md +58 -43
  3. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/pyproject.toml +1 -1
  4. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/setup.py +1 -1
  5. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/__init__.py +1 -1
  6. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/base_agent.py +2 -0
  7. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/compact_mixin.py +9 -2
  8. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/message_utils.py +26 -12
  9. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/summarizer/summarizer_agent.py +131 -127
  10. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/client.py +32 -33
  11. txcode_sdk-1.7.0/src/txcode_sdk/config/runtime_settings.py +222 -0
  12. txcode_sdk-1.7.0/src/txcode_sdk/queue/__init__.py +30 -0
  13. txcode_sdk-1.7.0/src/txcode_sdk/queue/dispatcher.py +186 -0
  14. txcode_sdk-1.7.0/src/txcode_sdk/queue/handlers/__init__.py +7 -0
  15. txcode_sdk-1.7.0/src/txcode_sdk/queue/handlers/db_maintenance.py +49 -0
  16. txcode_sdk-1.7.0/src/txcode_sdk/queue/handlers/session_cleanup.py +93 -0
  17. txcode_sdk-1.7.0/src/txcode_sdk/queue/handlers/session_status_repair.py +23 -0
  18. txcode_sdk-1.7.0/src/txcode_sdk/queue/registry.py +52 -0
  19. txcode_sdk-1.7.0/src/txcode_sdk/queue/worker.py +140 -0
  20. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/config_store.py +25 -0
  21. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/handler.py +5 -1
  22. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/http/__init__.py +2 -0
  23. txcode_sdk-1.7.0/src/txcode_sdk/server/http/chat_routes.py +165 -0
  24. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/http/http_base.py +23 -6
  25. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/server.py +2 -0
  26. txcode_sdk-1.7.0/src/txcode_sdk/session/db.py +239 -0
  27. txcode_sdk-1.7.0/src/txcode_sdk/session/manager.py +420 -0
  28. txcode_sdk-1.7.0/src/txcode_sdk/session/migrations.py +148 -0
  29. txcode_sdk-1.7.0/src/txcode_sdk/session/repositories.py +326 -0
  30. txcode_sdk-1.7.0/src/txcode_sdk/session/retention.py +128 -0
  31. txcode_sdk-1.7.0/src/txcode_sdk/utils/multipart.py +104 -0
  32. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0/src/txcode_sdk.egg-info}/PKG-INFO +16 -1
  33. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk.egg-info/SOURCES.txt +22 -0
  34. txcode_sdk-1.7.0/tests/test_chat_upload.py +275 -0
  35. txcode_sdk-1.7.0/tests/test_db_migrations.py +143 -0
  36. txcode_sdk-1.7.0/tests/test_job_queue.py +112 -0
  37. txcode_sdk-1.7.0/tests/test_message_repository.py +124 -0
  38. txcode_sdk-1.7.0/tests/test_py36_compat.py +123 -0
  39. txcode_sdk-1.7.0/tests/test_retention_maintenance.py +79 -0
  40. txcode_sdk-1.7.0/tests/test_session_cleanup.py +123 -0
  41. txcode_sdk-1.7.0/tests/test_session_repository.py +113 -0
  42. txcode_sdk-1.5.0/src/txcode_sdk/server/http/chat_routes.py +0 -64
  43. txcode_sdk-1.5.0/src/txcode_sdk/session/manager.py +0 -336
  44. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/LICENSE +0 -0
  45. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/setup.cfg +0 -0
  46. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/example/__init__.py +0 -0
  47. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/example/code_example.py +0 -0
  48. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/example/code_session.py +0 -0
  49. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/example/code_tool.py +0 -0
  50. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/example/constants.py +0 -0
  51. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/example/query_session.py +0 -0
  52. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/example/ws_server.py +0 -0
  53. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/_compat/__init__.py +0 -0
  54. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/_compat/dataclasses.py +0 -0
  55. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/_compat/resources.py +0 -0
  56. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/__init__.py +0 -0
  57. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/chat/__init__.py +0 -0
  58. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/chat/agent_tool.py +0 -0
  59. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/chat/chat_agent.py +0 -0
  60. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/chat/prompts/__init__.py +0 -0
  61. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/chat/prompts/role.txt +0 -0
  62. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/code/__init__.py +0 -0
  63. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/code/agent_tool.py +0 -0
  64. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/code/code_agent.py +0 -0
  65. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/code/prompts/__init__.py +0 -0
  66. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/code/prompts/role.txt +0 -0
  67. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/common/__init__.py +0 -0
  68. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/common/common_agent.py +0 -0
  69. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/common/prompt/__init__.py +0 -0
  70. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/common/prompt/role.txt +0 -0
  71. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/design/__init__.py +0 -0
  72. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/design/agent_tool.py +0 -0
  73. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/design/design_agent.py +0 -0
  74. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/design/prompts/__init__.py +0 -0
  75. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/design/prompts/role.txt +0 -0
  76. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/discuss/__init__.py +0 -0
  77. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/discuss/agent_tool.py +0 -0
  78. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/discuss/discuss_agent.py +0 -0
  79. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/discuss/prompts/__init__.py +0 -0
  80. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/discuss/prompts/role.txt +0 -0
  81. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/dream/__init__.py +0 -0
  82. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/dream/agent_tool.py +0 -0
  83. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/dream/dream_agent.py +0 -0
  84. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/dream/prompts/__init__.py +0 -0
  85. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/dream/prompts/role.txt +0 -0
  86. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/factory.py +0 -0
  87. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/hook_mixin.py +0 -0
  88. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/mem/__init__.py +0 -0
  89. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/mem/agent_tool.py +0 -0
  90. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/mem/mem_agent.py +0 -0
  91. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/mem/prompts/__init__.py +0 -0
  92. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/mem/prompts/role.txt +0 -0
  93. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/name/__init__.py +0 -0
  94. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/name/name_agent.py +0 -0
  95. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/name/prompts/__init__.py +0 -0
  96. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/name/prompts/role.txt +0 -0
  97. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/plan/__init__.py +0 -0
  98. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/plan/agent_tool.py +0 -0
  99. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/plan/plan_agent.py +0 -0
  100. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/plan/prompts/__init__.py +0 -0
  101. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/plan/prompts/role.txt +0 -0
  102. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/prompt_builder.py +0 -0
  103. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/shell/__init__.py +0 -0
  104. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/shell/agent_tool.py +0 -0
  105. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/shell/prompts/__init__.py +0 -0
  106. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/shell/prompts/role.txt +0 -0
  107. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/shell/shell_agent.py +0 -0
  108. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/skill/__init__.py +0 -0
  109. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/skill/agent_tool.py +0 -0
  110. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/skill/prompts/__init__.py +0 -0
  111. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/skill/prompts/role.txt +0 -0
  112. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/skill/skill_agent.py +0 -0
  113. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/step_utils.py +0 -0
  114. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/summarizer/__init__.py +0 -0
  115. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/summarizer/prompts/__init__.py +0 -0
  116. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/summarizer/prompts/role.txt +0 -0
  117. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/task/__init__.py +0 -0
  118. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/task/agent_tool.py +0 -0
  119. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/task/prompts/__init__.py +0 -0
  120. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/task/prompts/role.txt +0 -0
  121. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/task/task_agent.py +0 -0
  122. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/test/__init__.py +0 -0
  123. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/test/agent_tool.py +0 -0
  124. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/test/prompts/__init__.py +0 -0
  125. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/test/prompts/role.txt +0 -0
  126. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/test/test_agent.py +0 -0
  127. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/agent/tool_registry.py +0 -0
  128. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/compact/__init__.py +0 -0
  129. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/compact/compressor.py +0 -0
  130. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/config/__init__.py +0 -0
  131. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/config/ai_settings.py +0 -0
  132. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/config/context_config.py +0 -0
  133. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/hooks/__init__.py +0 -0
  134. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/hooks/handlers/__init__.py +0 -0
  135. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/hooks/handlers/base.py +0 -0
  136. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/hooks/handlers/memory.py +0 -0
  137. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/hooks/processor.py +0 -0
  138. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/hooks/queue.py +0 -0
  139. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/hooks/types.py +0 -0
  140. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/provider/__init__.py +0 -0
  141. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/provider/base.py +0 -0
  142. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/provider/deepseek_provider.py +0 -0
  143. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/provider/openai_provider.py +0 -0
  144. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/provider/router.py +0 -0
  145. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/provider/txcode_ai.py +0 -0
  146. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/__init__.py +0 -0
  147. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/__main__.py +0 -0
  148. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/git.py +0 -0
  149. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/http/file_routes.py +0 -0
  150. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/http/git_routes.py +0 -0
  151. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/http/plan_code_routes.py +0 -0
  152. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/http/project_routes.py +0 -0
  153. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/http/session_routes.py +0 -0
  154. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/http/skill_routes.py +0 -0
  155. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/http/spec_routes.py +0 -0
  156. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/http/sys_config_routes.py +0 -0
  157. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/hub_client.py +0 -0
  158. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/json_store.py +0 -0
  159. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/plan_code.py +0 -0
  160. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/project_manager.py +0 -0
  161. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/provider_config.py +0 -0
  162. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/services/__init__.py +0 -0
  163. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/services/broadcaster.py +0 -0
  164. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/services/config_import_export.py +0 -0
  165. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/services/project_service.py +0 -0
  166. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/services/provider_service.py +0 -0
  167. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/skill_manager.py +0 -0
  168. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/spec_manager.py +0 -0
  169. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/websocket.py +0 -0
  170. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/yaml_lite.py +0 -0
  171. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/server/zip_utils.py +0 -0
  172. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/session/__init__.py +0 -0
  173. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/skills/__init__.py +0 -0
  174. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/specs/__init__.py +0 -0
  175. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/__init__.py +0 -0
  176. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/_util.py +0 -0
  177. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/bash.py +0 -0
  178. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/bash.txt +0 -0
  179. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/code_search.py +0 -0
  180. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/code_search.txt +0 -0
  181. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/edit_file.py +0 -0
  182. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/edit_file.txt +0 -0
  183. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/edit_replacers.py +0 -0
  184. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/edit_similarity.py +0 -0
  185. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/email_tool.py +0 -0
  186. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/email_tool.txt +0 -0
  187. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/glob.py +0 -0
  188. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/glob.txt +0 -0
  189. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/grep.py +0 -0
  190. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/grep.txt +0 -0
  191. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/memory.py +0 -0
  192. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/memory.txt +0 -0
  193. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/read_file.py +0 -0
  194. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/read_file.txt +0 -0
  195. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/skill_tool.py +0 -0
  196. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/skill_tool.txt +0 -0
  197. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/todo_read.py +0 -0
  198. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/todo_read.txt +0 -0
  199. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/todo_write.py +0 -0
  200. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/todo_write.txt +0 -0
  201. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/web_fetch.py +0 -0
  202. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/web_fetch.txt +0 -0
  203. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/web_search.py +0 -0
  204. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/web_search.txt +0 -0
  205. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/web_shell_exec.py +0 -0
  206. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/web_shell_exec.txt +0 -0
  207. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/write_file.py +0 -0
  208. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/tools/write_file.txt +0 -0
  209. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/types.py +0 -0
  210. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/utils/__init__.py +0 -0
  211. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/utils/format.py +0 -0
  212. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/utils/log.py +0 -0
  213. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/utils/path_util.py +0 -0
  214. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk/utils/time_util.py +0 -0
  215. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk.egg-info/dependency_links.txt +0 -0
  216. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk.egg-info/entry_points.txt +0 -0
  217. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/src/txcode_sdk.egg-info/top_level.txt +0 -0
  218. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/tests/test_ai_settings.py +0 -0
  219. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/tests/test_provider_reasoning_effort.py +0 -0
  220. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/tests/test_server_cli_logging.py +0 -0
  221. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/tests/test_sys_config_ai_settings.py +0 -0
  222. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/tests/test_sys_config_import_export.py +0 -0
  223. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/tests/test_txcode_ai.py +0 -0
  224. {txcode_sdk-1.5.0 → txcode_sdk-1.7.0}/tests/test_yaml_lite.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: txcode-sdk
3
- Version: 1.5.0
3
+ Version: 1.7.0
4
4
  Summary: AI Agent SDK with built-in tools for Python projects
5
5
  Author: homecommunity
6
6
  License: MIT
@@ -157,6 +157,21 @@ txcode-sdk serve --work-dir /opt/door-access \
157
157
  | S→C | `projects_list` | get_projects 响应(仅发送方) |
158
158
  | S→C | `projects_changed` / `project_changed` | 项目列表变更 / 当前项目切换广播(全局) |
159
159
 
160
+ ### 图片上传 / 下载
161
+
162
+ 桌面端粘贴/选择图片后先调上传接口,再把 `mediaFiles`(`[{filePath, type, dataUrl?}]`)随 `chat` 一并发送:
163
+
164
+ - `POST /api/chat/upload_image_chat`:`multipart/form-data` 字段名 `file`,落盘当前项目
165
+ `.txcode/uploads/<YYYY-MM-DD>/<uuid>.<ext>`,返回 `{filePath, url, type, size}`;
166
+ 单文件上限 10MB,仅支持 `.png/.jpg/.jpeg/.gif/.webp/.bmp/.svg`
167
+ - `GET /api/chat/file_download?filePath=<绝对/相对路径>`:返回图片二进制(按扩展名定 `Content-Type`),
168
+ 供 `<img src>` / Electron 直取;文件不存在 404,缺 `filePath` 400
169
+ - `GET /api/chat/history_chat?sessionId=<id>`:用户消息的 `mediaFiles[]` 含 `filePath/url/type`,
170
+ 历史会话重开后图片仍可渲染(`url` 为绝对地址,`Host` 缺失回退 `localhost:<端口>`)
171
+
172
+ 发送链路对图片按 `work_dir` 解析相对路径并转 `data:` URI(`dataUrl` 存在时优先),
173
+ 单张图片读取失败仅告警跳过,不中断整轮对话。
174
+
160
175
  ### 供应商与模型管理
161
176
 
162
177
  服务端支持**动态添加/编辑/删除多个供应商**(OpenAI / DeepSeek / 自建网关),配置实时持久化到用户层
@@ -132,6 +132,21 @@ txcode-sdk serve --work-dir /opt/door-access \
132
132
  | S→C | `projects_list` | get_projects 响应(仅发送方) |
133
133
  | S→C | `projects_changed` / `project_changed` | 项目列表变更 / 当前项目切换广播(全局) |
134
134
 
135
+ ### 图片上传 / 下载
136
+
137
+ 桌面端粘贴/选择图片后先调上传接口,再把 `mediaFiles`(`[{filePath, type, dataUrl?}]`)随 `chat` 一并发送:
138
+
139
+ - `POST /api/chat/upload_image_chat`:`multipart/form-data` 字段名 `file`,落盘当前项目
140
+ `.txcode/uploads/<YYYY-MM-DD>/<uuid>.<ext>`,返回 `{filePath, url, type, size}`;
141
+ 单文件上限 10MB,仅支持 `.png/.jpg/.jpeg/.gif/.webp/.bmp/.svg`
142
+ - `GET /api/chat/file_download?filePath=<绝对/相对路径>`:返回图片二进制(按扩展名定 `Content-Type`),
143
+ 供 `<img src>` / Electron 直取;文件不存在 404,缺 `filePath` 400
144
+ - `GET /api/chat/history_chat?sessionId=<id>`:用户消息的 `mediaFiles[]` 含 `filePath/url/type`,
145
+ 历史会话重开后图片仍可渲染(`url` 为绝对地址,`Host` 缺失回退 `localhost:<端口>`)
146
+
147
+ 发送链路对图片按 `work_dir` 解析相对路径并转 `data:` URI(`dataUrl` 存在时优先),
148
+ 单张图片读取失败仅告警跳过,不中断整轮对话。
149
+
135
150
  ### 供应商与模型管理
136
151
 
137
152
  服务端支持**动态添加/编辑/删除多个供应商**(OpenAI / DeepSeek / 自建网关),配置实时持久化到用户层
@@ -163,49 +178,49 @@ txcode-sdk serve --work-dir /opt/door-access \
163
178
  匹配 name 与 display_name 双通道;`add_model` 缺省 display_name = name
164
179
  - **api_key 安全**:WS 协议返回打码值(`sk-***` + 后 4 位);`update_provider` 传打码值/空不改原 key;
165
180
  明文仅存于用户层本地文件(权限建议 `chmod 600`)
166
- - **模型解析定序**:激活供应商优先 → 跨供应商按列表顺序第一个命中 → 未限制放行 → 全未命中回
167
- `error: Model not allowed: xxx, available: [..]`
168
-
169
- #### 配置导入 / 导出(与桌面版本地后端同一 YAML 契约)
170
-
171
- `GET /api/sys_config/export_config` 与 `POST /api/sys_config/import_config`(请求体 `{"content": "<配置文件文本>"}`)
172
- 使用**与桌面版本地后端 `tx_server` 完全相同的格式**:YAML、camelCase、模型在顶层 `models` 数组、**无 `success/data` 信封**。
173
- 因此桌面端「导出配置」得到的 `config.yml` 可直接导入 SDK 主机,SDK 导出的 `config.yml` 也可直接导入桌面端/其他 SDK 主机。
174
- 文本解析/生成由纯标准库模块 `yaml_lite` 完成(零第三方依赖,JSON 文本是 YAML 子集,同一入口天然兼容)。
175
-
176
- 导出响应为文件附件:`Content-Type: application/x-yaml` + `Content-Disposition: attachment; filename=config.yml`:
177
-
178
- ```yaml
179
- providers:
180
- - id: 3f2a1b... # 命中本地已有 id → 更新;未命中但 name 同名 → 更新该条;否则新增并保留文件中的 id
181
- name: OpenAI
182
- apiKey: sk-xxx # 明文(导入必需,注意保管);空串或打码值 sk-***xxxx 时不覆盖本地已有 key
183
- baseUrl: https://api.openai.com/v1
184
- enabled: true
185
- isDefault: true
186
- models:
187
- - id: m-1 # SDK 无 model id 语义,导出时按 providerId + name 派生
188
- providerId: 3f2a1b... # 关联同一文件内 providers[].id(导入期建立「文件 id → 本地 id」映射)
189
- name: gpt-4o
190
- contextWindow: 128000 # SDK 无此存储,导入时忽略不报错,导出时省略
191
- maxOutputTokens: 8192
192
- supportsVision: true
193
- supportsTools: true
194
- enabled: true
195
- projects: # SDK 扩展段:目录存在则打开项目;桌面端后端解析时忽略该段,不报错
196
- - id: a1b2c3
197
- name: door-access
198
- path: /opt/door-access
199
- ```
200
-
201
- - **兼容旧格式**:`providers[].models` 内联的模型数组(旧版 SDK 导出)仍可导入;
202
- - **忽略未知段**:`providerAuth / gateway / wafGateway / email / proxy` 等桌面端专属段只解析不落库,不报错;
203
- - **幂等**:同一文件重复导入不产生重复供应商/模型(id 命中走更新,未命中同名走更新);
204
- - **可读报错**:语法不合法(含锚点/别名/多文档等 YAML 子集外特性)返回 400
205
- `{"success": false, "error": "配置文件格式无效(第 N 行): ..."}`,不再透出 Python 异常串;
206
- - **统计反馈**:成功返回 `{"success": true, "message": "配置导入成功", "data": {"providers": 6, "models": 12, "projects": 2, "skipped": []}}`,
207
- `skipped` 列出被跳过的条目及原因(缺 apiKey 的新供应商、`providerId` 不存在或目录不存在的项目等)。
208
-
181
+ - **模型解析定序**:激活供应商优先 → 跨供应商按列表顺序第一个命中 → 未限制放行 → 全未命中回
182
+ `error: Model not allowed: xxx, available: [..]`
183
+
184
+ #### 配置导入 / 导出(与桌面版本地后端同一 YAML 契约)
185
+
186
+ `GET /api/sys_config/export_config` 与 `POST /api/sys_config/import_config`(请求体 `{"content": "<配置文件文本>"}`)
187
+ 使用**与桌面版本地后端 `tx_server` 完全相同的格式**:YAML、camelCase、模型在顶层 `models` 数组、**无 `success/data` 信封**。
188
+ 因此桌面端「导出配置」得到的 `config.yml` 可直接导入 SDK 主机,SDK 导出的 `config.yml` 也可直接导入桌面端/其他 SDK 主机。
189
+ 文本解析/生成由纯标准库模块 `yaml_lite` 完成(零第三方依赖,JSON 文本是 YAML 子集,同一入口天然兼容)。
190
+
191
+ 导出响应为文件附件:`Content-Type: application/x-yaml` + `Content-Disposition: attachment; filename=config.yml`:
192
+
193
+ ```yaml
194
+ providers:
195
+ - id: 3f2a1b... # 命中本地已有 id → 更新;未命中但 name 同名 → 更新该条;否则新增并保留文件中的 id
196
+ name: OpenAI
197
+ apiKey: sk-xxx # 明文(导入必需,注意保管);空串或打码值 sk-***xxxx 时不覆盖本地已有 key
198
+ baseUrl: https://api.openai.com/v1
199
+ enabled: true
200
+ isDefault: true
201
+ models:
202
+ - id: m-1 # SDK 无 model id 语义,导出时按 providerId + name 派生
203
+ providerId: 3f2a1b... # 关联同一文件内 providers[].id(导入期建立「文件 id → 本地 id」映射)
204
+ name: gpt-4o
205
+ contextWindow: 128000 # SDK 无此存储,导入时忽略不报错,导出时省略
206
+ maxOutputTokens: 8192
207
+ supportsVision: true
208
+ supportsTools: true
209
+ enabled: true
210
+ projects: # SDK 扩展段:目录存在则打开项目;桌面端后端解析时忽略该段,不报错
211
+ - id: a1b2c3
212
+ name: door-access
213
+ path: /opt/door-access
214
+ ```
215
+
216
+ - **兼容旧格式**:`providers[].models` 内联的模型数组(旧版 SDK 导出)仍可导入;
217
+ - **忽略未知段**:`providerAuth / gateway / wafGateway / email / proxy` 等桌面端专属段只解析不落库,不报错;
218
+ - **幂等**:同一文件重复导入不产生重复供应商/模型(id 命中走更新,未命中同名走更新);
219
+ - **可读报错**:语法不合法(含锚点/别名/多文档等 YAML 子集外特性)返回 400
220
+ `{"success": false, "error": "配置文件格式无效(第 N 行): ..."}`,不再透出 Python 异常串;
221
+ - **统计反馈**:成功返回 `{"success": true, "message": "配置导入成功", "data": {"providers": 6, "models": 12, "projects": 2, "skipped": []}}`,
222
+ `skipped` 列出被跳过的条目及原因(缺 apiKey 的新供应商、`providerId` 不存在或目录不存在的项目等)。
223
+
209
224
  ### 项目管理
210
225
 
211
226
  远程模式下桌面版右上角「打开项目 / 选择项目」由 SDK 侧 WS 协议提供等价能力:项目列表 / 打开(目录校验)/
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "txcode-sdk"
7
- version = "1.5.0"
7
+ version = "1.7.0"
8
8
  description = "AI Agent SDK with built-in tools for Python projects"
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
@@ -8,7 +8,7 @@ from setuptools import find_packages, setup
8
8
 
9
9
  setup(
10
10
  name="txcode-sdk",
11
- version="0.4.1",
11
+ version="1.7.0",
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",
@@ -78,4 +78,4 @@ except Exception:
78
78
  ProjectManager = None
79
79
  JsonStore = None
80
80
 
81
- __version__ = "1.5.0"
81
+ __version__ = "1.7.0"
@@ -131,6 +131,7 @@ class BaseAgent(
131
131
  "agent run aborted | session=%s iteration=%d",
132
132
  session_id, iteration,
133
133
  )
134
+ self.release_session_refs()
134
135
  return ChatResult(
135
136
  answer="", steps=steps, session_id=session_id or "",
136
137
  iterations=iteration, success=False, error="Aborted",
@@ -380,6 +381,7 @@ class BaseAgent(
380
381
  logger.warning("last response: %s", _format_last_response(last_response))
381
382
 
382
383
  success = final_answer != ""
384
+ self.release_session_refs()
383
385
  return ChatResult(
384
386
  answer=answer,
385
387
  steps=steps,
@@ -19,6 +19,13 @@ class CompactMixin:
19
19
  """注入客户端的 ContextCompressor,确保 _check_and_compact 使用同一实例。"""
20
20
  self._compressor = compressor
21
21
 
22
+ def release_session_refs(self):
23
+ """释放本轮会话相关内存引用(DB 为唯一真源,长连接不驻留消息正文)。"""
24
+ self._base_messages = []
25
+ self._injected_user_message = ""
26
+ self._original_user_index = None
27
+ self._session_id = None
28
+
22
29
  async def _check_and_compact(
23
30
  self,
24
31
  session_id: Optional[str],
@@ -67,9 +74,9 @@ class CompactMixin:
67
74
  self._original_user_index = 0 if new_base else None
68
75
 
69
76
  session = self._session_manager.get(session_id)
70
- summary_index = (session or {}).get("summary_message_index")
77
+ summary_id = (session or {}).get("summary_message_id")
71
78
  summary_msgs = self._session_manager.get_messages_for_ai(
72
- session_id, summary_index=summary_index
79
+ session_id, summary_message_id=summary_id
73
80
  )
74
81
  for m in summary_msgs:
75
82
  if m.get("role") == "system":
@@ -5,10 +5,16 @@
5
5
  _history_to_chat_message(历史 dict → ChatMessage)、_build_tool_context。
6
6
  """
7
7
 
8
+ import base64
8
9
  import json
10
+ import logging
11
+ import mimetypes
9
12
  from typing import List, Optional
10
13
 
11
14
  from ..types import ChatMessage, ImageContent, MediaFile, TextContent
15
+ from ..utils.path_util import _resolve_path
16
+
17
+ logger = logging.getLogger(__name__)
12
18
 
13
19
 
14
20
  class MessageUtilsMixin:
@@ -18,21 +24,28 @@ class MessageUtilsMixin:
18
24
  if media_files:
19
25
  content: list = [TextContent(text=text)]
20
26
  for mf in media_files:
21
- if mf.data_url:
22
- url = mf.data_url
23
- else:
24
- import base64
25
- import mimetypes
26
- from pathlib import Path
27
- path = Path(mf.file_path)
28
- mime = mf.type or mimetypes.guess_type(str(path))[0] or "image/png"
29
- with open(path, "rb") as f:
30
- b64 = base64.b64encode(f.read()).decode("utf-8")
31
- url = "data:%s;base64,%s" % (mime, b64)
32
- content.append(ImageContent(url=url))
27
+ url = self._media_file_to_url(mf)
28
+ if url:
29
+ content.append(ImageContent(url=url))
33
30
  return ChatMessage(role="user", content=content)
34
31
  return ChatMessage(role="user", content=text)
35
32
 
33
+ def _media_file_to_url(self, mf: MediaFile) -> Optional[str]:
34
+ """图片 → `data:` URI;读取失败返回 None(跳过该图,不中断整轮对话)。"""
35
+ if mf.data_url:
36
+ return mf.data_url
37
+ if not mf.file_path:
38
+ return None
39
+ path = _resolve_path(mf.file_path, self._work_dir)
40
+ try:
41
+ mime = mf.type or mimetypes.guess_type(str(path))[0] or "image/png"
42
+ with open(str(path), "rb") as f:
43
+ b64 = base64.b64encode(f.read()).decode("utf-8")
44
+ except Exception as exc:
45
+ logger.warning("image load failed | path=%s error=%s", path, exc)
46
+ return None
47
+ return "data:%s;base64,%s" % (mime, b64)
48
+
36
49
  def _build_tool_context(self, session_id: str):
37
50
  from ..types import ToolContext
38
51
  return ToolContext(session_id=session_id, work_dir=self._work_dir)
@@ -74,6 +87,7 @@ class MessageUtilsMixin:
74
87
  session_id, role, saved_content,
75
88
  keep_context=keep_context, is_original=is_original,
76
89
  tool_call_id=tool_call_id, media_files=mf_list,
90
+ reasoning=reasoning,
77
91
  )
78
92
 
79
93
  def _history_to_chat_message(self, msg: dict) -> ChatMessage:
@@ -1,130 +1,134 @@
1
- """SummarizerAgent:会话压缩总结(Python 3.6 兼容)。
2
-
3
- 行为对齐 txcode `summarizer.agent.ts:compact`:
4
- - /compact user 占位消息(keep_context=True)
5
- - 过滤 role=='tool' 且 JSON 解析后 type=='tool_result' 的消息
6
- - assistant_with_tools 反向解包 text/content,tool_result 反向解包 output
7
- - provider.chat(messages)(max_tokens 由 Provider 内部硬编码,不在此处传参)
8
- - 摘要写入 assistant(keep_context=True)后 update_summary + reset_tokens
9
- - tokens_after = round(tokens_before * 0.3)
10
- """
11
-
12
- import json
13
- from typing import Any, Optional
14
-
15
- from ..._compat.dataclasses import dataclass
16
- from ..._compat.resources import get_resource
17
- from ...provider.base import BaseProvider
18
- from ...types import ChatMessage
19
-
20
-
21
- @dataclass
22
- class CompactCheck:
23
- needed: bool
24
- current_tokens: int
25
- threshold: int
26
- reason: str = ""
27
-
28
-
29
- @dataclass
30
- class CompactResult:
31
- success: bool
32
- summary: str = ""
33
- tokens_before: int = 0
34
- tokens_after: int = 0
35
- error: Optional[str] = None
36
-
37
-
38
- class SummarizerAgent:
39
- def __init__(self, provider: BaseProvider, max_tokens: int = 150_000):
40
- self._provider = provider
41
- self._max_tokens = max_tokens
42
-
43
- def check_needs_compact(self, session_data: Optional[dict], additional_tokens: int = 0) -> CompactCheck:
44
- if not session_data:
45
- return CompactCheck(needed=False, current_tokens=0, threshold=self._max_tokens, reason="No session")
46
-
47
- prompt = session_data.get("prompt_tokens", 0)
48
- completion = session_data.get("completion_tokens", 0)
49
- total = prompt + completion + additional_tokens
50
- threshold = self._max_tokens
51
- needed = total >= threshold
52
- return CompactCheck(
53
- needed=needed,
54
- current_tokens=total,
55
- threshold=threshold,
56
- reason="Above threshold" if needed else "Below threshold",
57
- )
58
-
59
- async def compact(self, session_manager: Any, session_id: str) -> CompactResult:
60
- try:
61
- session = session_manager.get(session_id)
62
- if not session:
63
- return CompactResult(success=False, error="Session not found")
64
-
65
- summary_index = session.get("summary_message_index")
66
- msgs = session_manager.get_messages_for_ai(session_id, summary_index=summary_index)
67
- if not msgs:
68
- return CompactResult(success=False, error="No messages to compact")
69
-
70
- tokens_before = (
71
- session.get("prompt_tokens", 0) + session.get("completion_tokens", 0)
72
- )
73
-
74
- session_manager.add_message(
75
- session_id, "user", "/compact", keep_context=True,
76
- )
77
-
78
- chat_messages: list = []
79
- for m in msgs:
80
- role = m.get("role")
81
- content = m.get("content", "")
82
- if role == "tool":
83
- continue
84
- try:
85
- parsed = json.loads(content)
86
- if isinstance(parsed, dict):
87
- ptype = parsed.get("type")
88
- if ptype == "tool_result":
89
- continue
90
- if ptype == "assistant_with_tools":
91
- content = parsed.get("text") or parsed.get("content") or content
92
- elif ptype == "tool_result":
93
- content = parsed.get("output") or content
94
- except (json.JSONDecodeError, TypeError, ValueError):
95
- pass
96
- chat_messages.append(ChatMessage(role=role, content=content))
97
-
98
- if not chat_messages:
99
- return CompactResult(
100
- success=False, error="No messages to compact after filter",
101
- tokens_before=tokens_before, tokens_after=tokens_before,
102
- )
103
-
104
- role_template = get_resource(
105
- "txcode_sdk.agent.summarizer.prompts", "role.txt"
106
- )
107
- chat_messages.append(ChatMessage(role="user", content=role_template))
108
-
109
- response = await self._provider.chat(chat_messages)
110
- summary = (getattr(response, "content", "") or "").strip()
111
- if not summary:
112
- return CompactResult(
113
- success=False, error="Empty summary",
114
- tokens_before=tokens_before, tokens_after=tokens_before,
115
- )
116
-
117
- summary_index = session_manager.add_message(
1
+ """SummarizerAgent:会话压缩总结(Python 3.6 兼容)。
2
+
3
+ 行为对齐 txcode `summarizer.agent.ts:compact`:
4
+ - /compact user 占位消息(keep_context=True)
5
+ - 过滤 role=='tool' 且 JSON 解析后 type=='tool_result' 的消息
6
+ - assistant_with_tools 反向解包 text/content,tool_result 反向解包 output
7
+ - provider.chat(messages)(max_tokens 由 Provider 内部硬编码,不在此处传参)
8
+ - 摘要写入 assistant(keep_context=True)后 update_summary + reset_tokens
9
+ - tokens_after = round(tokens_before * 0.3)
10
+ """
11
+
12
+ import json
13
+ from typing import Any, Optional
14
+
15
+ from ..._compat.dataclasses import dataclass
16
+ from ..._compat.resources import get_resource
17
+ from ...provider.base import BaseProvider
18
+ from ...types import ChatMessage
19
+
20
+
21
+ @dataclass
22
+ class CompactCheck:
23
+ needed: bool
24
+ current_tokens: int
25
+ threshold: int
26
+ reason: str = ""
27
+
28
+
29
+ @dataclass
30
+ class CompactResult:
31
+ success: bool
32
+ summary: str = ""
33
+ tokens_before: int = 0
34
+ tokens_after: int = 0
35
+ error: Optional[str] = None
36
+
37
+
38
+ class SummarizerAgent:
39
+ def __init__(self, provider: BaseProvider, max_tokens: int = 150_000):
40
+ self._provider = provider
41
+ self._max_tokens = max_tokens
42
+
43
+ def check_needs_compact(self, session_data: Optional[dict], additional_tokens: int = 0) -> CompactCheck:
44
+ if not session_data:
45
+ return CompactCheck(needed=False, current_tokens=0, threshold=self._max_tokens, reason="No session")
46
+
47
+ prompt = session_data.get("prompt_tokens", 0)
48
+ completion = session_data.get("completion_tokens", 0)
49
+ total = prompt + completion + additional_tokens
50
+ threshold = self._max_tokens
51
+ needed = total >= threshold
52
+ return CompactCheck(
53
+ needed=needed,
54
+ current_tokens=total,
55
+ threshold=threshold,
56
+ reason="Above threshold" if needed else "Below threshold",
57
+ )
58
+
59
+ async def compact(self, session_manager: Any, session_id: str) -> CompactResult:
60
+ try:
61
+ session = session_manager.get(session_id)
62
+ if not session:
63
+ return CompactResult(success=False, error="Session not found")
64
+
65
+ summary_message_id = session.get("summary_message_id")
66
+ msgs = session_manager.get_messages_for_ai(
67
+ session_id, summary_message_id=summary_message_id
68
+ )
69
+
70
+ if not msgs:
71
+ return CompactResult(success=False, error="No messages to compact")
72
+
73
+ tokens_before = (
74
+ session.get("prompt_tokens", 0) + session.get("completion_tokens", 0)
75
+ )
76
+
77
+ session_manager.add_message(
78
+ session_id, "user", "/compact", keep_context=True,
79
+ )
80
+
81
+ chat_messages: list = []
82
+ for m in msgs:
83
+ role = m.get("role")
84
+ content = m.get("content", "")
85
+ if role == "tool":
86
+ continue
87
+ try:
88
+ parsed = json.loads(content)
89
+ if isinstance(parsed, dict):
90
+ ptype = parsed.get("type")
91
+ if ptype == "tool_result":
92
+ continue
93
+ if ptype == "assistant_with_tools":
94
+ content = parsed.get("text") or parsed.get("content") or content
95
+ elif ptype == "tool_result":
96
+ content = parsed.get("output") or content
97
+ except (json.JSONDecodeError, TypeError, ValueError):
98
+ pass
99
+ chat_messages.append(ChatMessage(role=role, content=content))
100
+
101
+ if not chat_messages:
102
+ return CompactResult(
103
+ success=False, error="No messages to compact after filter",
104
+ tokens_before=tokens_before, tokens_after=tokens_before,
105
+ )
106
+
107
+ role_template = get_resource(
108
+ "txcode_sdk.agent.summarizer.prompts", "role.txt"
109
+ )
110
+ chat_messages.append(ChatMessage(role="user", content=role_template))
111
+
112
+ response = await self._provider.chat(chat_messages)
113
+ summary = (getattr(response, "content", "") or "").strip()
114
+ if not summary:
115
+ return CompactResult(
116
+ success=False, error="Empty summary",
117
+ tokens_before=tokens_before, tokens_after=tokens_before,
118
+ )
119
+
120
+ summary_message_id = session_manager.add_message(
118
121
  session_id, "assistant", summary, keep_context=True,
119
122
  )
120
- session_manager.update_summary(session_id, summary_index)
123
+ session_manager.update_summary(session_id, summary_message_id)
121
124
  session_manager.reset_tokens(session_id)
122
-
123
- return CompactResult(
124
- success=True,
125
- summary=summary,
126
- tokens_before=tokens_before,
127
- tokens_after=int(round(tokens_before * 0.3)),
128
- )
129
- except Exception as e:
130
- return CompactResult(success=False, error=str(e))
125
+
126
+
127
+ return CompactResult(
128
+ success=True,
129
+ summary=summary,
130
+ tokens_before=tokens_before,
131
+ tokens_after=int(round(tokens_before * 0.3)),
132
+ )
133
+ except Exception as e:
134
+ return CompactResult(success=False, error=str(e))