txcode-sdk 0.4.1__tar.gz → 0.5.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.
- {txcode_sdk-0.4.1/src/txcode_sdk.egg-info → txcode_sdk-0.5.0}/PKG-INFO +1 -1
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/pyproject.toml +1 -1
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/client.py +5 -0
- txcode_sdk-0.5.0/src/txcode_sdk/server/config_store.py +39 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/server/handler.py +42 -13
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/server/http.py +469 -4
- txcode_sdk-0.5.0/src/txcode_sdk/server/hub_client.py +139 -0
- txcode_sdk-0.5.0/src/txcode_sdk/server/plan_code.py +234 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/server/server.py +19 -0
- txcode_sdk-0.5.0/src/txcode_sdk/server/skill_manager.py +148 -0
- txcode_sdk-0.5.0/src/txcode_sdk/server/spec_manager.py +121 -0
- txcode_sdk-0.5.0/src/txcode_sdk/server/zip_utils.py +42 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/session/manager.py +50 -1
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0/src/txcode_sdk.egg-info}/PKG-INFO +1 -1
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk.egg-info/SOURCES.txt +7 -0
- txcode_sdk-0.5.0/tests/test_http_ext_api.py +612 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/LICENSE +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/README.md +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/setup.cfg +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/setup.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/example/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/example/code_example.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/example/code_session.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/example/code_tool.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/example/constants.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/example/query_session.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/example/ws_server.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/_compat/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/_compat/dataclasses.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/_compat/resources.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/base_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/chat/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/chat/agent_tool.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/chat/chat_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/chat/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/chat/prompts/role.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/code/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/code/agent_tool.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/code/code_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/code/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/code/prompts/role.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/common/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/common/common_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/common/prompt/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/common/prompt/role.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/design/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/design/agent_tool.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/design/design_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/design/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/design/prompts/role.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/discuss/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/discuss/agent_tool.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/discuss/discuss_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/discuss/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/discuss/prompts/role.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/dream/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/dream/agent_tool.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/dream/dream_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/dream/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/dream/prompts/role.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/mem/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/mem/agent_tool.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/mem/mem_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/mem/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/mem/prompts/role.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/name/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/name/name_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/name/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/name/prompts/role.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/plan/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/plan/agent_tool.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/plan/plan_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/plan/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/plan/prompts/role.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/shell/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/shell/agent_tool.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/shell/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/shell/prompts/role.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/shell/shell_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/skill/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/skill/agent_tool.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/skill/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/skill/prompts/role.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/skill/skill_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/summarizer/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/summarizer/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/summarizer/prompts/role.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/summarizer/summarizer_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/task/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/task/agent_tool.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/task/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/task/prompts/role.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/task/task_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/test/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/test/agent_tool.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/test/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/test/prompts/role.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/test/test_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/tool_registry.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/compact/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/compact/compressor.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/hooks/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/hooks/handlers/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/hooks/handlers/base.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/hooks/handlers/memory.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/hooks/processor.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/hooks/queue.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/hooks/types.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/provider/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/provider/base.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/provider/deepseek_provider.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/provider/openai_provider.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/provider/router.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/provider/txcode_ai.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/server/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/server/__main__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/server/json_store.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/server/project_manager.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/server/provider_config.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/server/websocket.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/session/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/skills/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/specs/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/__init__.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/bash.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/bash_tool.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/edit_file.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/edit_file.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/glob.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/glob_tool.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/grep.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/grep_tool.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/memory_tool.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/read_file.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/read_file.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/todo_read.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/todo_read.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/todo_write.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/todo_write.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/web_shell_exec.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/web_shell_exec.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/write_file.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/write_file.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk/types.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk.egg-info/dependency_links.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk.egg-info/entry_points.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/src/txcode_sdk.egg-info/top_level.txt +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_cli.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_client.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_compat.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_design_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_discuss_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_dream_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_http_api.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_json_store.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_name_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_plan_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_project_manager.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_provider_config.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_provider_model.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_session.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_session_query.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_shell_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_skill_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_test_agent.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_tools.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_txcode_ai.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_websocket_protocol.py +0 -0
- {txcode_sdk-0.4.1 → txcode_sdk-0.5.0}/tests/test_ws_server.py +0 -0
|
@@ -68,6 +68,11 @@ class TxCodeClient:
|
|
|
68
68
|
def work_dir(self) -> str:
|
|
69
69
|
return self._work_dir
|
|
70
70
|
|
|
71
|
+
@property
|
|
72
|
+
def session_manager(self) -> SessionManager:
|
|
73
|
+
"""当前 SessionManager(set_work_dir 重建后仍指向最新实例)。"""
|
|
74
|
+
return self._session_manager
|
|
75
|
+
|
|
71
76
|
def get_model(self) -> str:
|
|
72
77
|
return self._model
|
|
73
78
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""ConfigStore:通用 KV 配置存储(`~/.txcode/config.json`,用户级,跨项目共享)。
|
|
2
|
+
|
|
3
|
+
与 TS 版 configService 对齐:字符串值原样存取,非字符串 JSON 序列化。
|
|
4
|
+
复用 JsonStore(asyncio.Lock + 原子写),Python 3.6 兼容,零第三方依赖。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
import os
|
|
9
|
+
|
|
10
|
+
from .json_store import JsonStore
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ConfigStore:
|
|
14
|
+
"""通用 KV 配置:~/.txcode/config.json(用户级,跨项目共享)。"""
|
|
15
|
+
|
|
16
|
+
def __init__(self, path: str = "~/.txcode/config.json"):
|
|
17
|
+
self._store = JsonStore(os.path.expanduser(path))
|
|
18
|
+
|
|
19
|
+
def get(self, key: str):
|
|
20
|
+
"""不存在返回 None;值为字符串原样返回,否则返回 JSON 对象。"""
|
|
21
|
+
data = self._store.load({})
|
|
22
|
+
value = data.get(key)
|
|
23
|
+
if value is None:
|
|
24
|
+
return None
|
|
25
|
+
if isinstance(value, str):
|
|
26
|
+
return value
|
|
27
|
+
try:
|
|
28
|
+
return json.loads(value)
|
|
29
|
+
except (TypeError, ValueError):
|
|
30
|
+
return value
|
|
31
|
+
|
|
32
|
+
async def set(self, key: str, value):
|
|
33
|
+
"""value 为字符串原样存,否则 json.dumps;原子写。"""
|
|
34
|
+
data = self._store.load({})
|
|
35
|
+
if isinstance(value, str):
|
|
36
|
+
data[key] = value
|
|
37
|
+
else:
|
|
38
|
+
data[key] = json.dumps(value, ensure_ascii=False)
|
|
39
|
+
await self._store.save(data)
|
|
@@ -12,6 +12,7 @@ import os
|
|
|
12
12
|
from typing import Any, Dict, Optional, Set
|
|
13
13
|
|
|
14
14
|
from ..types import MediaFile, StepInfo
|
|
15
|
+
from .config_store import ConfigStore
|
|
15
16
|
from .provider_config import ProviderConfigManager
|
|
16
17
|
from .project_manager import ProjectManager
|
|
17
18
|
from .websocket import OPCODE_TEXT, build_close_frame, build_frame, read_message
|
|
@@ -66,10 +67,11 @@ def _usage_to_desktop(usage) -> Optional[dict]:
|
|
|
66
67
|
|
|
67
68
|
|
|
68
69
|
class CodeWebSocketHandler:
|
|
69
|
-
def __init__(self, client, provider_config=None, project_manager=None):
|
|
70
|
+
def __init__(self, client, provider_config=None, project_manager=None, config_store=None):
|
|
70
71
|
self._client = client
|
|
71
72
|
self._provider_config = provider_config or ProviderConfigManager()
|
|
72
73
|
self._project_manager = project_manager or ProjectManager()
|
|
74
|
+
self._config_store = config_store or ConfigStore()
|
|
73
75
|
self._writers: Set = set()
|
|
74
76
|
self._abort_signals: Dict[str, AbortSignal] = {}
|
|
75
77
|
self._running: Set[str] = set()
|
|
@@ -194,25 +196,29 @@ class CodeWebSocketHandler:
|
|
|
194
196
|
self.broadcast({"type": "error", "error": "sessionId is required"})
|
|
195
197
|
return
|
|
196
198
|
|
|
199
|
+
# ① 携带 modelName → 优先解析激活(_apply_model_name 内部 resolve + switch + client.set_provider)
|
|
200
|
+
model_name = data.get("modelName")
|
|
201
|
+
if model_name:
|
|
202
|
+
ok = await self._apply_model_name(model_name, session_id)
|
|
203
|
+
if not ok:
|
|
204
|
+
return
|
|
205
|
+
|
|
206
|
+
# ② 无 modelName → 从 KV defaultModel 兜底激活
|
|
197
207
|
active_provider, _ = self._provider_config.get_active()
|
|
198
208
|
if not active_provider:
|
|
199
|
-
self.
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
209
|
+
ok = await self._ensure_default_provider()
|
|
210
|
+
if not ok:
|
|
211
|
+
self.broadcast({
|
|
212
|
+
"type": "error",
|
|
213
|
+
"sessionId": session_id,
|
|
214
|
+
"error": "No active provider configured, please add provider first",
|
|
215
|
+
})
|
|
216
|
+
return
|
|
205
217
|
|
|
206
218
|
message = data.get("message", "")
|
|
207
219
|
agent_type = data.get("agent") or "code"
|
|
208
220
|
media_files = data.get("mediaFiles") or []
|
|
209
221
|
|
|
210
|
-
model_name = data.get("modelName")
|
|
211
|
-
if model_name:
|
|
212
|
-
ok = await self._apply_model_name(model_name, session_id)
|
|
213
|
-
if not ok:
|
|
214
|
-
return
|
|
215
|
-
|
|
216
222
|
existing = self._abort_signals.get(session_id)
|
|
217
223
|
if existing:
|
|
218
224
|
existing.abort()
|
|
@@ -302,6 +308,29 @@ class CodeWebSocketHandler:
|
|
|
302
308
|
|
|
303
309
|
# ---------- 供应商 / 模型 ----------
|
|
304
310
|
|
|
311
|
+
async def _ensure_default_provider(self) -> bool:
|
|
312
|
+
"""KV defaultModel → resolve_model → switch 激活 + 同步 client。成功返回 True。"""
|
|
313
|
+
model_name = self._config_store.get("defaultModel")
|
|
314
|
+
if not model_name:
|
|
315
|
+
return False
|
|
316
|
+
resolved = self._provider_config.resolve_model(model_name)
|
|
317
|
+
if resolved is None:
|
|
318
|
+
return False
|
|
319
|
+
provider_id, resolved_model = resolved
|
|
320
|
+
provider = self._provider_config.get_provider(provider_id)
|
|
321
|
+
if not provider:
|
|
322
|
+
return False
|
|
323
|
+
await self._provider_config.switch(provider_id, resolved_model)
|
|
324
|
+
self._client.set_provider(
|
|
325
|
+
provider.get("api_key", ""), provider.get("base_url", ""), resolved_model
|
|
326
|
+
)
|
|
327
|
+
self.broadcast({"type": "model_changed", "data": {
|
|
328
|
+
"providerName": provider.get("name", ""),
|
|
329
|
+
"modelName": model_name,
|
|
330
|
+
"model": resolved_model,
|
|
331
|
+
}})
|
|
332
|
+
return True
|
|
333
|
+
|
|
305
334
|
async def _apply_model_name(self, model_name: str, session_id: str) -> bool:
|
|
306
335
|
"""chat.modelName 解析:命中 → 切换供应商/模型 + 广播 model_changed;未命中 → error。"""
|
|
307
336
|
resolved = self._provider_config.resolve_model(model_name)
|