txcode-sdk 0.4.0__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.0/src/txcode_sdk.egg-info → txcode_sdk-0.5.0}/PKG-INFO +8 -6
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/README.md +7 -5
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/pyproject.toml +44 -44
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/setup.py +39 -39
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/__init__.py +1 -1
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/client.py +5 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/server/__main__.py +41 -27
- txcode_sdk-0.5.0/src/txcode_sdk/server/config_store.py +39 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/server/handler.py +54 -5
- txcode_sdk-0.5.0/src/txcode_sdk/server/http.py +1071 -0
- 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.0 → txcode_sdk-0.5.0}/src/txcode_sdk/server/server.py +44 -8
- 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.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/server/websocket.py +16 -33
- txcode_sdk-0.5.0/src/txcode_sdk/server/zip_utils.py +42 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/session/manager.py +50 -1
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0/src/txcode_sdk.egg-info}/PKG-INFO +8 -6
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk.egg-info/SOURCES.txt +9 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_cli.py +40 -9
- txcode_sdk-0.5.0/tests/test_http_api.py +682 -0
- txcode_sdk-0.5.0/tests/test_http_ext_api.py +612 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_ws_server.py +127 -23
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/LICENSE +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/setup.cfg +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/example/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/example/code_example.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/example/code_session.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/example/code_tool.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/example/constants.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/example/query_session.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/example/ws_server.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/_compat/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/_compat/dataclasses.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/_compat/resources.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/base_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/chat/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/chat/agent_tool.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/chat/chat_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/chat/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/chat/prompts/role.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/code/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/code/agent_tool.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/code/code_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/code/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/code/prompts/role.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/common/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/common/common_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/common/prompt/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/common/prompt/role.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/design/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/design/agent_tool.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/design/design_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/design/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/design/prompts/role.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/discuss/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/discuss/agent_tool.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/discuss/discuss_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/discuss/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/discuss/prompts/role.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/dream/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/dream/agent_tool.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/dream/dream_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/dream/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/dream/prompts/role.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/mem/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/mem/agent_tool.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/mem/mem_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/mem/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/mem/prompts/role.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/name/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/name/name_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/name/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/name/prompts/role.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/plan/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/plan/agent_tool.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/plan/plan_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/plan/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/plan/prompts/role.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/shell/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/shell/agent_tool.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/shell/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/shell/prompts/role.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/shell/shell_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/skill/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/skill/agent_tool.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/skill/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/skill/prompts/role.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/skill/skill_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/summarizer/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/summarizer/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/summarizer/prompts/role.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/summarizer/summarizer_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/task/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/task/agent_tool.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/task/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/task/prompts/role.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/task/task_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/test/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/test/agent_tool.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/test/prompts/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/test/prompts/role.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/test/test_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/agent/tool_registry.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/compact/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/compact/compressor.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/hooks/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/hooks/handlers/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/hooks/handlers/base.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/hooks/handlers/memory.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/hooks/processor.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/hooks/queue.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/hooks/types.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/provider/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/provider/base.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/provider/deepseek_provider.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/provider/openai_provider.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/provider/router.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/provider/txcode_ai.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/server/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/server/json_store.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/server/project_manager.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/server/provider_config.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/session/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/skills/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/specs/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/__init__.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/bash.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/bash_tool.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/edit_file.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/edit_file.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/glob.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/glob_tool.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/grep.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/grep_tool.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/memory_tool.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/read_file.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/read_file.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/todo_read.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/todo_read.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/todo_write.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/todo_write.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/web_shell_exec.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/web_shell_exec.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/write_file.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/tools/write_file.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk/types.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk.egg-info/dependency_links.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk.egg-info/entry_points.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/src/txcode_sdk.egg-info/top_level.txt +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_client.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_compat.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_design_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_discuss_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_dream_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_json_store.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_name_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_plan_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_project_manager.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_provider_config.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_provider_model.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_session.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_session_query.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_shell_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_skill_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_test_agent.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_tools.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_txcode_ai.py +0 -0
- {txcode_sdk-0.4.0 → txcode_sdk-0.5.0}/tests/test_websocket_protocol.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: txcode-sdk
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: AI Agent SDK with built-in tools for Python projects
|
|
5
5
|
Author: homecommunity
|
|
6
6
|
License: MIT
|
|
@@ -89,17 +89,19 @@ txcode-sdk serve --work-dir /opt/door-access --host 0.0.0.0 --port 41000 \
|
|
|
89
89
|
- `--host` / `--port`:默认 `0.0.0.0:41000`
|
|
90
90
|
- `--agent-type`:默认 `code`
|
|
91
91
|
- `--models`:默认供应商初始模型列表 `[显示名=]模型名` 逗号分隔(仅首次注册默认供应商时使用);缺省读 `TXCODE_MODELS`,再缺省 = 不限制
|
|
92
|
-
-
|
|
92
|
+
- `TXCODE_API_KEY`:**可选**——仅当 `~/.txcode/providers.json` 不存在且希望首次自动注册默认供应商时使用;未设置时服务以**空配置**正常启动(stderr 打印 WARN 提示),供应商由桌面端通过 WS `add_provider` / `switch_provider` 动态添加,无需重启
|
|
93
93
|
- 兜底启动:`python -m txcode_sdk.server serve --work-dir ...`(无脚本路径时同样可用)
|
|
94
94
|
|
|
95
|
-
### 启动装配(JSON 为权威源,0.4.
|
|
95
|
+
### 启动装配(JSON 为权威源,0.4.1)
|
|
96
96
|
|
|
97
97
|
服务启动时以用户层 JSON 为权威源恢复上次状态,**重启自动恢复上次激活供应商/模型与当前项目**:
|
|
98
98
|
|
|
99
99
|
1. **供应商**:加载 `~/.txcode/providers.json`——存在则取激活供应商的 `(api_key, base_url, model)` 直接构造
|
|
100
|
-
`TxCodeClient`(不读 `TXCODE_BASE_URL` / `TXCODE_MODEL
|
|
101
|
-
`TXCODE_API_KEY
|
|
102
|
-
|
|
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、配置/项目管理消息)全部可用
|
|
103
105
|
2. **项目**:加载 `~/.txcode/projects.json`——有当前项目则其 `path` 作为 work_dir(不读 `TXCODE_WORK_DIR`);
|
|
104
106
|
无当前项目则 `--work-dir` 注册为当前项目后使用
|
|
105
107
|
|
|
@@ -64,17 +64,19 @@ txcode-sdk serve --work-dir /opt/door-access --host 0.0.0.0 --port 41000 \
|
|
|
64
64
|
- `--host` / `--port`:默认 `0.0.0.0:41000`
|
|
65
65
|
- `--agent-type`:默认 `code`
|
|
66
66
|
- `--models`:默认供应商初始模型列表 `[显示名=]模型名` 逗号分隔(仅首次注册默认供应商时使用);缺省读 `TXCODE_MODELS`,再缺省 = 不限制
|
|
67
|
-
-
|
|
67
|
+
- `TXCODE_API_KEY`:**可选**——仅当 `~/.txcode/providers.json` 不存在且希望首次自动注册默认供应商时使用;未设置时服务以**空配置**正常启动(stderr 打印 WARN 提示),供应商由桌面端通过 WS `add_provider` / `switch_provider` 动态添加,无需重启
|
|
68
68
|
- 兜底启动:`python -m txcode_sdk.server serve --work-dir ...`(无脚本路径时同样可用)
|
|
69
69
|
|
|
70
|
-
### 启动装配(JSON 为权威源,0.4.
|
|
70
|
+
### 启动装配(JSON 为权威源,0.4.1)
|
|
71
71
|
|
|
72
72
|
服务启动时以用户层 JSON 为权威源恢复上次状态,**重启自动恢复上次激活供应商/模型与当前项目**:
|
|
73
73
|
|
|
74
74
|
1. **供应商**:加载 `~/.txcode/providers.json`——存在则取激活供应商的 `(api_key, base_url, model)` 直接构造
|
|
75
|
-
`TxCodeClient`(不读 `TXCODE_BASE_URL` / `TXCODE_MODEL
|
|
76
|
-
`TXCODE_API_KEY
|
|
77
|
-
|
|
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、配置/项目管理消息)全部可用
|
|
78
80
|
2. **项目**:加载 `~/.txcode/projects.json`——有当前项目则其 `path` 作为 work_dir(不读 `TXCODE_WORK_DIR`);
|
|
79
81
|
无当前项目则 `--work-dir` 注册为当前项目后使用
|
|
80
82
|
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
[build-system]
|
|
2
|
-
requires = ["setuptools>=40.8.0", "wheel"]
|
|
3
|
-
build-backend = "setuptools.build_meta"
|
|
4
|
-
|
|
5
|
-
[project]
|
|
6
|
-
name = "txcode-sdk"
|
|
7
|
-
version = "0.
|
|
8
|
-
description = "AI Agent SDK with built-in tools for Python projects"
|
|
9
|
-
readme = "README.md"
|
|
10
|
-
license = { text = "MIT" }
|
|
11
|
-
requires-python = ">=3.6"
|
|
12
|
-
authors = [
|
|
13
|
-
{ name = "homecommunity" }
|
|
14
|
-
]
|
|
15
|
-
keywords = ["ai", "agent", "openai", "tools", "react"]
|
|
16
|
-
classifiers = [
|
|
17
|
-
"Development Status :: 3 - Alpha",
|
|
18
|
-
"Intended Audience :: Developers",
|
|
19
|
-
"License :: OSI Approved :: MIT License",
|
|
20
|
-
"Programming Language :: Python :: 3",
|
|
21
|
-
"Programming Language :: Python :: 3.6",
|
|
22
|
-
"Programming Language :: Python :: 3.7",
|
|
23
|
-
"Programming Language :: Python :: 3.8",
|
|
24
|
-
"Programming Language :: Python :: 3.9",
|
|
25
|
-
"Programming Language :: Python :: 3.10",
|
|
26
|
-
"Programming Language :: Python :: 3.11",
|
|
27
|
-
"Programming Language :: Python :: 3.12",
|
|
28
|
-
]
|
|
29
|
-
dependencies = []
|
|
30
|
-
|
|
31
|
-
[project.scripts]
|
|
32
|
-
txcode-sdk = "txcode_sdk.server.__main__:main"
|
|
33
|
-
|
|
34
|
-
[project.urls]
|
|
35
|
-
Repository = "https://github.com/homecommunity/txcode-sdk"
|
|
36
|
-
|
|
37
|
-
[tool.pytest.ini_options]
|
|
38
|
-
testpaths = ["tests"]
|
|
39
|
-
|
|
40
|
-
[tool.setuptools.packages.find]
|
|
41
|
-
where = ["src"]
|
|
42
|
-
|
|
43
|
-
[tool.setuptools.package-data]
|
|
44
|
-
txcode_sdk = ["**/*.txt"]
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=40.8.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "txcode-sdk"
|
|
7
|
+
version = "0.5.0"
|
|
8
|
+
description = "AI Agent SDK with built-in tools for Python projects"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
requires-python = ">=3.6"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "homecommunity" }
|
|
14
|
+
]
|
|
15
|
+
keywords = ["ai", "agent", "openai", "tools", "react"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.6",
|
|
22
|
+
"Programming Language :: Python :: 3.7",
|
|
23
|
+
"Programming Language :: Python :: 3.8",
|
|
24
|
+
"Programming Language :: Python :: 3.9",
|
|
25
|
+
"Programming Language :: Python :: 3.10",
|
|
26
|
+
"Programming Language :: Python :: 3.11",
|
|
27
|
+
"Programming Language :: Python :: 3.12",
|
|
28
|
+
]
|
|
29
|
+
dependencies = []
|
|
30
|
+
|
|
31
|
+
[project.scripts]
|
|
32
|
+
txcode-sdk = "txcode_sdk.server.__main__:main"
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Repository = "https://github.com/homecommunity/txcode-sdk"
|
|
36
|
+
|
|
37
|
+
[tool.pytest.ini_options]
|
|
38
|
+
testpaths = ["tests"]
|
|
39
|
+
|
|
40
|
+
[tool.setuptools.packages.find]
|
|
41
|
+
where = ["src"]
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.package-data]
|
|
44
|
+
txcode_sdk = ["**/*.txt"]
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
"""setuptools 传统入口(兼容老版本 pip 离线安装,Python 3.6)。
|
|
2
|
-
|
|
3
|
-
pyproject.toml 中的 [tool.setuptools] 配置与 setup.cfg 等价;
|
|
4
|
-
此文件仅为老版本 pip(不支持 PEP 517)提供回退入口。
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from setuptools import find_packages, setup
|
|
8
|
-
|
|
9
|
-
setup(
|
|
10
|
-
name="txcode-sdk",
|
|
11
|
-
version="0.4.
|
|
12
|
-
description="AI Agent SDK with built-in tools for Python projects",
|
|
13
|
-
long_description=open("README.md", encoding="utf-8").read(),
|
|
14
|
-
long_description_content_type="text/markdown",
|
|
15
|
-
license="MIT",
|
|
16
|
-
python_requires=">=3.6",
|
|
17
|
-
packages=find_packages("src"),
|
|
18
|
-
package_dir={"": "src"},
|
|
19
|
-
package_data={"txcode_sdk": ["**/*.txt"]},
|
|
20
|
-
install_requires=[],
|
|
21
|
-
entry_points={
|
|
22
|
-
"console_scripts": [
|
|
23
|
-
"txcode-sdk=txcode_sdk.server.__main__:main",
|
|
24
|
-
],
|
|
25
|
-
},
|
|
26
|
-
classifiers=[
|
|
27
|
-
"Development Status :: 3 - Alpha",
|
|
28
|
-
"Intended Audience :: Developers",
|
|
29
|
-
"License :: OSI Approved :: MIT License",
|
|
30
|
-
"Programming Language :: Python :: 3",
|
|
31
|
-
"Programming Language :: Python :: 3.6",
|
|
32
|
-
"Programming Language :: Python :: 3.7",
|
|
33
|
-
"Programming Language :: Python :: 3.8",
|
|
34
|
-
"Programming Language :: Python :: 3.9",
|
|
35
|
-
"Programming Language :: Python :: 3.10",
|
|
36
|
-
"Programming Language :: Python :: 3.11",
|
|
37
|
-
"Programming Language :: Python :: 3.12",
|
|
38
|
-
],
|
|
39
|
-
)
|
|
1
|
+
"""setuptools 传统入口(兼容老版本 pip 离线安装,Python 3.6)。
|
|
2
|
+
|
|
3
|
+
pyproject.toml 中的 [tool.setuptools] 配置与 setup.cfg 等价;
|
|
4
|
+
此文件仅为老版本 pip(不支持 PEP 517)提供回退入口。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from setuptools import find_packages, setup
|
|
8
|
+
|
|
9
|
+
setup(
|
|
10
|
+
name="txcode-sdk",
|
|
11
|
+
version="0.4.1",
|
|
12
|
+
description="AI Agent SDK with built-in tools for Python projects",
|
|
13
|
+
long_description=open("README.md", encoding="utf-8").read(),
|
|
14
|
+
long_description_content_type="text/markdown",
|
|
15
|
+
license="MIT",
|
|
16
|
+
python_requires=">=3.6",
|
|
17
|
+
packages=find_packages("src"),
|
|
18
|
+
package_dir={"": "src"},
|
|
19
|
+
package_data={"txcode_sdk": ["**/*.txt"]},
|
|
20
|
+
install_requires=[],
|
|
21
|
+
entry_points={
|
|
22
|
+
"console_scripts": [
|
|
23
|
+
"txcode-sdk=txcode_sdk.server.__main__:main",
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
classifiers=[
|
|
27
|
+
"Development Status :: 3 - Alpha",
|
|
28
|
+
"Intended Audience :: Developers",
|
|
29
|
+
"License :: OSI Approved :: MIT License",
|
|
30
|
+
"Programming Language :: Python :: 3",
|
|
31
|
+
"Programming Language :: Python :: 3.6",
|
|
32
|
+
"Programming Language :: Python :: 3.7",
|
|
33
|
+
"Programming Language :: Python :: 3.8",
|
|
34
|
+
"Programming Language :: Python :: 3.9",
|
|
35
|
+
"Programming Language :: Python :: 3.10",
|
|
36
|
+
"Programming Language :: Python :: 3.11",
|
|
37
|
+
"Programming Language :: Python :: 3.12",
|
|
38
|
+
],
|
|
39
|
+
)
|
|
@@ -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
|
|
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
txcode-sdk serve --work-dir <目录> [--host 0.0.0.0] [--port 41000] [--agent-type code] [--models "gpt-4o,DeepSeek V3=deepseek-chat"]
|
|
5
5
|
python -m txcode_sdk.server serve --work-dir <目录>
|
|
6
6
|
|
|
7
|
-
启动装配(JSON 为权威源,0.4.
|
|
7
|
+
启动装配(JSON 为权威源,0.4.1 起):
|
|
8
8
|
- 供应商:`~/.txcode/providers.json` 存在 → 激活供应商 (api_key, base_url, model) 权威;
|
|
9
|
-
|
|
10
|
-
注册默认供应商并激活(--models
|
|
9
|
+
不存在(首次启动/全新环境)→ 设置了 TXCODE_API_KEY(可选)时以其 / TXCODE_BASE_URL /
|
|
10
|
+
TXCODE_MODEL 注册默认供应商并激活(--models 作为初始模型列表),再读回构造;
|
|
11
|
+
未设置 TXCODE_API_KEY → 以空配置正常启动(占位 client + WARN 提示),
|
|
12
|
+
供应商由桌面端经 WS add_provider / switch_provider 动态添加,无需重启。
|
|
11
13
|
- 项目:`~/.txcode/projects.json` 有当前项目 → 其 path 作为 work_dir;
|
|
12
14
|
无当前项目 → --work-dir 注册为当前项目后使用。
|
|
13
15
|
- TXCODE_BASE_URL / TXCODE_MODEL / TXCODE_MODELS 仅首次注册默认供应商时使用;
|
|
@@ -75,7 +77,11 @@ class MissingApiKeyError(Exception):
|
|
|
75
77
|
|
|
76
78
|
|
|
77
79
|
async def build_components(args, user_dir: str = None):
|
|
78
|
-
"""启动装配(JSON 为权威源):返回 (client, provider_config, project_manager, work_dir)。
|
|
80
|
+
"""启动装配(JSON 为权威源):返回 (client, provider_config, project_manager, work_dir)。
|
|
81
|
+
|
|
82
|
+
0.4.1 起无 TXCODE_API_KEY 且无 providers.json / 无激活供应商时不再抛
|
|
83
|
+
MissingApiKeyError,以占位 client(api_key 为空)空配置启动,等待桌面端 WS 添加供应商。
|
|
84
|
+
"""
|
|
79
85
|
from txcode_sdk import TxCodeClient
|
|
80
86
|
from .provider_config import ProviderConfigManager
|
|
81
87
|
from .project_manager import ProjectManager
|
|
@@ -87,31 +93,23 @@ async def build_components(args, user_dir: str = None):
|
|
|
87
93
|
providers_path = os.path.join(user_dir, "providers.json")
|
|
88
94
|
if not os.path.exists(providers_path):
|
|
89
95
|
api_key = os.environ.get("TXCODE_API_KEY", "").strip()
|
|
90
|
-
if
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
if api_key: # 有 env:注册默认供应商(行为不变);无 env:空配置启动,不抛错
|
|
97
|
+
base_url = os.environ.get("TXCODE_BASE_URL", "").strip() or DEFAULT_BASE_URL
|
|
98
|
+
model = os.environ.get("TXCODE_MODEL", "").strip() or DEFAULT_MODEL
|
|
99
|
+
models = parse_models(args.models or os.environ.get("TXCODE_MODELS", ""))
|
|
100
|
+
provider = await provider_config.add_provider(
|
|
101
|
+
name="default",
|
|
102
|
+
base_url=base_url,
|
|
103
|
+
api_key=api_key,
|
|
104
|
+
models=models or None,
|
|
93
105
|
)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
base_url=base_url,
|
|
100
|
-
api_key=api_key,
|
|
101
|
-
models=models or None,
|
|
102
|
-
)
|
|
103
|
-
try:
|
|
104
|
-
await provider_config.switch(provider["id"], model)
|
|
105
|
-
except ValueError:
|
|
106
|
-
# 模型名不在 --models 白名单:回退激活该供应商第一个模型
|
|
107
|
-
await provider_config.switch(provider["id"], None)
|
|
108
|
-
|
|
109
|
-
active_provider, active_model = provider_config.get_active()
|
|
110
|
-
if not active_provider:
|
|
111
|
-
raise MissingApiKeyError(
|
|
112
|
-
"No active provider configured in %s" % providers_path
|
|
113
|
-
)
|
|
106
|
+
try:
|
|
107
|
+
await provider_config.switch(provider["id"], model)
|
|
108
|
+
except ValueError:
|
|
109
|
+
# 模型名不在 --models 白名单:回退激活该供应商第一个模型
|
|
110
|
+
await provider_config.switch(provider["id"], None)
|
|
114
111
|
|
|
112
|
+
# work_dir 装配(先于 client 构造:占位 client 也需要 work_dir)
|
|
115
113
|
current = project_manager.get_current()
|
|
116
114
|
if current and os.path.isdir(current.get("path", "")):
|
|
117
115
|
work_dir = current["path"]
|
|
@@ -121,6 +119,22 @@ async def build_components(args, user_dir: str = None):
|
|
|
121
119
|
os.path.basename(os.path.normpath(work_dir)) or "default", work_dir
|
|
122
120
|
)
|
|
123
121
|
|
|
122
|
+
active_provider, active_model = provider_config.get_active()
|
|
123
|
+
if not active_provider:
|
|
124
|
+
# 空配置启动:占位 client(不发起真实请求)+ WARN 提示(不再抛 MissingApiKeyError)
|
|
125
|
+
client = TxCodeClient(
|
|
126
|
+
api_key="",
|
|
127
|
+
base_url=DEFAULT_BASE_URL,
|
|
128
|
+
model=DEFAULT_MODEL,
|
|
129
|
+
work_dir=work_dir,
|
|
130
|
+
agent_type=args.agent_type,
|
|
131
|
+
)
|
|
132
|
+
sys.stderr.write(
|
|
133
|
+
"[txcode-sdk] WARN: No active provider configured, "
|
|
134
|
+
"add via WS add_provider (desktop)\n"
|
|
135
|
+
)
|
|
136
|
+
return client, provider_config, project_manager, work_dir
|
|
137
|
+
|
|
124
138
|
model = active_model or (
|
|
125
139
|
(active_provider.get("models") or [{}])[0].get("name", "")
|
|
126
140
|
)
|
|
@@ -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,16 +196,29 @@ class CodeWebSocketHandler:
|
|
|
194
196
|
self.broadcast({"type": "error", "error": "sessionId is required"})
|
|
195
197
|
return
|
|
196
198
|
|
|
197
|
-
|
|
198
|
-
agent_type = data.get("agent") or "code"
|
|
199
|
-
media_files = data.get("mediaFiles") or []
|
|
200
|
-
|
|
199
|
+
# ① 携带 modelName → 优先解析激活(_apply_model_name 内部 resolve + switch + client.set_provider)
|
|
201
200
|
model_name = data.get("modelName")
|
|
202
201
|
if model_name:
|
|
203
202
|
ok = await self._apply_model_name(model_name, session_id)
|
|
204
203
|
if not ok:
|
|
205
204
|
return
|
|
206
205
|
|
|
206
|
+
# ② 无 modelName → 从 KV defaultModel 兜底激活
|
|
207
|
+
active_provider, _ = self._provider_config.get_active()
|
|
208
|
+
if not active_provider:
|
|
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
|
|
217
|
+
|
|
218
|
+
message = data.get("message", "")
|
|
219
|
+
agent_type = data.get("agent") or "code"
|
|
220
|
+
media_files = data.get("mediaFiles") or []
|
|
221
|
+
|
|
207
222
|
existing = self._abort_signals.get(session_id)
|
|
208
223
|
if existing:
|
|
209
224
|
existing.abort()
|
|
@@ -273,6 +288,9 @@ class CodeWebSocketHandler:
|
|
|
273
288
|
folder_name = data.get("folderName")
|
|
274
289
|
if not session_id or not folder_name:
|
|
275
290
|
return
|
|
291
|
+
active_provider, _ = self._provider_config.get_active()
|
|
292
|
+
if not active_provider:
|
|
293
|
+
return # 无供应商:跳过命名(不调 chat,避免空 key 请求)
|
|
276
294
|
user_input = data.get("userInput") or ""
|
|
277
295
|
try:
|
|
278
296
|
result = await self._client.chat(
|
|
@@ -290,6 +308,29 @@ class CodeWebSocketHandler:
|
|
|
290
308
|
|
|
291
309
|
# ---------- 供应商 / 模型 ----------
|
|
292
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
|
+
|
|
293
334
|
async def _apply_model_name(self, model_name: str, session_id: str) -> bool:
|
|
294
335
|
"""chat.modelName 解析:命中 → 切换供应商/模型 + 广播 model_changed;未命中 → error。"""
|
|
295
336
|
resolved = self._provider_config.resolve_model(model_name)
|
|
@@ -476,6 +517,14 @@ class CodeWebSocketHandler:
|
|
|
476
517
|
self._abort_signals.clear()
|
|
477
518
|
self._client.set_work_dir(path)
|
|
478
519
|
|
|
520
|
+
async def switch_project(self, path: str):
|
|
521
|
+
"""公开入口:HTTP 层切换 work_dir 时复用(语义与 _switch_project 一致)。"""
|
|
522
|
+
await self._switch_project(path)
|
|
523
|
+
|
|
524
|
+
def sync_client_active(self, active):
|
|
525
|
+
"""公开入口:HTTP 层删除激活供应商/模型后同步 client(语义与 _sync_client_active 一致)。"""
|
|
526
|
+
self._sync_client_active(active)
|
|
527
|
+
|
|
479
528
|
async def _handle_open_project(self, writer, data: dict):
|
|
480
529
|
name = data.get("name")
|
|
481
530
|
path = data.get("path")
|