- 集成MCP连接管理器,支持MCP服务器连接 - 添加多种内置工具:ClarifyTool、CronTool、DelegateTool、ExecuteCodeTool、 PatchFileTool、ProcessTool、SendMessageTool、SpawnTool、TerminalTool、 TodoTool、WebFetchTool、WebSearchTool、WriteFileTool等 - 实现工具注册和装配功能 - 添加技能选择上下文参数 - 支持思考模式控制参数thinking_enabled feat(coordinator): 重构任务执行计划器参数命名 - 将learning_candidate_enabled重命名为allow_candidate_generation - 更新TeamGraphScheduler中的参数传递 - 修改LocalAgentRunner中的相关参数处理 - 更新README文档中的相应描述 refactor(context): 标准化工具调用参数格式 - 添加_json导入用于参数序列化 - 实现_provider_tool_calls方法标准化OpenAI兼容的工具调用载荷 - 修复工具调用中参数非字符串类型的序列化问题 refactor(session): 优化消息历史记录过滤逻辑 - 修改get_messages_as_conversation为基于运行状态过滤消息 - 排除未完成、失败或错误结束的运行记录 - 改进对话历史的可见性控制机制 fix(store): 修复FTS索引重建逻辑 - 添加异常处理防止FTS索引创建失败 - 实现_rebuild_fts_index方法重新构建全文搜索索引 - 优化索引触发器和表的维护流程
138 lines
3.8 KiB
Python
138 lines
3.8 KiB
Python
"""Chat-related web schemas."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
try:
|
|
from pydantic import BaseModel, Field
|
|
except ModuleNotFoundError: # pragma: no cover - fallback for skeleton-only environments
|
|
class BaseModel:
|
|
"""Very small fallback shim used only so imports work without pydantic."""
|
|
|
|
def __init__(self, **kwargs: Any) -> None:
|
|
annotations = getattr(self.__class__, "__annotations__", {})
|
|
for name in annotations:
|
|
default = getattr(self.__class__, name, None)
|
|
if name in kwargs:
|
|
value = kwargs[name]
|
|
else:
|
|
value = default
|
|
setattr(self, name, value)
|
|
|
|
def model_dump(self, *, exclude_none: bool = False) -> dict[str, Any]:
|
|
data = dict(self.__dict__)
|
|
if exclude_none:
|
|
data = {key: value for key, value in data.items() if value is not None}
|
|
return data
|
|
|
|
def Field(default: Any = None, **kwargs: Any) -> Any:
|
|
default_factory = kwargs.get("default_factory")
|
|
if default_factory is not None:
|
|
return default_factory()
|
|
return default
|
|
|
|
|
|
class WebProviderTarget(BaseModel):
|
|
"""Web-facing provider target shape.
|
|
|
|
先保持和 runtime 里的 `ProviderTarget` 接近,但只暴露 Web 当前需要的字段。
|
|
后面如果 provider 层扩字段,再由这里显式补齐。
|
|
"""
|
|
|
|
provider: str | None = None
|
|
model: str | None = None
|
|
api_key: str | None = None
|
|
api_base: str | None = None
|
|
extra_headers: dict[str, str] | None = None
|
|
|
|
|
|
class WebChatRequest(BaseModel):
|
|
"""最小正式 chat 请求结构。"""
|
|
|
|
message: str = Field(min_length=1)
|
|
session_id: str | None = None
|
|
user_id: str | None = None
|
|
title: str | None = None
|
|
execution_context: str | None = None
|
|
model: str | None = None
|
|
provider_name: str | None = None
|
|
embedding_model: str | None = None
|
|
temperature: float | None = None
|
|
max_tokens: int | None = None
|
|
thinking_enabled: bool | None = None
|
|
max_tool_iterations: int | None = None
|
|
fallback_target: WebProviderTarget | None = None
|
|
auxiliary_target: WebProviderTarget | None = None
|
|
embedding_target: WebProviderTarget | None = None
|
|
reply_to_scheduled_run_id: str | None = None
|
|
scheduled_reply_intent: str | None = None
|
|
|
|
|
|
class WebChatResponse(BaseModel):
|
|
"""最小正式 chat 响应结构。"""
|
|
|
|
session_id: str
|
|
run_id: str
|
|
output_text: str
|
|
finish_reason: str
|
|
tool_iterations: int
|
|
provider_name: str | None = None
|
|
model: str | None = None
|
|
usage: dict[str, Any] = Field(default_factory=dict)
|
|
task_id: str | None = None
|
|
task_status: str | None = None
|
|
validation_result: dict[str, Any] | None = None
|
|
|
|
|
|
class WebChatFeedbackRequest(BaseModel):
|
|
"""Feedback on the latest assistant result in chat."""
|
|
|
|
session_id: str
|
|
run_id: str
|
|
feedback_type: str
|
|
comment: str | None = None
|
|
|
|
|
|
class WebChatFeedbackResponse(BaseModel):
|
|
"""Feedback recording result."""
|
|
|
|
session_id: str
|
|
run_id: str
|
|
task_id: str
|
|
task_status: str
|
|
feedback_type: str
|
|
learning_candidates: list[dict[str, Any]] = Field(default_factory=list)
|
|
|
|
|
|
class WebProviderConfigRequest(BaseModel):
|
|
"""Provider config update from the status page."""
|
|
|
|
enabled: bool = True
|
|
model: str | None = None
|
|
api_key: str | None = None
|
|
api_base: str | None = None
|
|
request_timeout_seconds: float | None = None
|
|
|
|
|
|
class WebProviderConfigResponse(BaseModel):
|
|
"""Provider config update result."""
|
|
|
|
ok: bool
|
|
provider: str
|
|
enabled: bool
|
|
|
|
|
|
class WebStatusResponse(BaseModel):
|
|
"""Web 宿主层状态响应。"""
|
|
|
|
status: str
|
|
running: bool
|
|
mode: str
|
|
|
|
|
|
class WebErrorResponse(BaseModel):
|
|
"""统一错误响应结构。"""
|
|
|
|
detail: str
|