refactor: remove legacy assistant compatibility

This commit is contained in:
Xin Wang
2026-08-18 10:07:18 +08:00
parent abfcd4cd19
commit d003ee77a5
40 changed files with 505 additions and 729 deletions
+11 -32
View File
@@ -9,7 +9,7 @@ from __future__ import annotations
from datetime import UTC, datetime
import re
from typing import Annotated, Any, ClassVar, Literal, Union
from typing import Annotated, Any, Literal, Union
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
from pydantic.alias_generators import to_camel
@@ -197,8 +197,8 @@ class OpeningMessageConfig(CamelModel):
class StartupConfig(CamelModel):
execution_mode: Literal["sequential"] = "sequential"
opening_mode: PromptOpeningMode | None = None
entry_mode: PromptEntryMode | None = None
opening_mode: PromptOpeningMode = "interruptible"
entry_mode: PromptEntryMode = "wait_user"
actions: list[StartupAction] = Field(default_factory=list, max_length=5)
opening_message: OpeningMessageConfig | None = None
@@ -207,33 +207,15 @@ class StartupConfig(CamelModel):
ids = [action.id for action in self.actions]
if len(ids) != len(set(ids)):
raise ValueError("启动 Action 的 id 不能重复")
legacy_confirmation = (
self.opening_mode is None and self.opening_message is not None
)
if self.opening_mode is None:
self.opening_mode = (
"confirmation" if legacy_confirmation else "interruptible"
)
if self.opening_mode == "confirmation" and self.opening_message is None:
raise ValueError("确认后继续必须配置开场确认弹窗")
if self.opening_mode != "confirmation":
self.opening_message = None
if self.entry_mode is None:
# Preserve the behavior introduced before entryMode became an
# explicit setting. Newly saved clients always send the field.
self.entry_mode = (
"generate" if legacy_confirmation else "wait_user"
)
return self
# ---------- 助手(单表 STI:瘦类型真列 + workflow 图 JSON 列) ----------
class AssistantUpsert(CamelModel):
# AssistantOut inherits this DTO for a stable public shape, but persisted
# historical rows must remain readable. Only request models enforce
# runtime combinations that the current editor/runtime can create.
enforce_request_constraints: ClassVar[bool] = True
name: str
type: AssistantType = "prompt"
runtime_mode: RuntimeMode = "pipeline"
@@ -299,23 +281,20 @@ class AssistantUpsert(CamelModel):
# bindings remain a Prompt-only public API.
self.tool_bindings = []
self.built_in_tools = BuiltInTools()
if self.enforce_request_constraints:
if self.runtime_mode == "realtime" and (
self.startup.actions
or self.startup.opening_message is not None
or self.startup.opening_mode != "interruptible"
or self.startup.entry_mode != "wait_user"
):
raise ValueError("Prompt Realtime 模式暂不支持启动阶段")
# 外部托管大脑只能 cascade,拦住不兼容的 realtime
if self.runtime_mode == "realtime" and (
self.startup.actions
or self.startup.opening_message is not None
or self.startup.opening_mode != "interruptible"
or self.startup.entry_mode != "wait_user"
):
raise ValueError("Prompt Realtime 模式暂不支持启动阶段")
# 外部托管大脑只能使用 Pipeline,拦住不支持的 Realtime。
if self.runtime_mode == "realtime" and self.type not in REALTIME_CAPABLE_TYPES:
raise ValueError(f"类型 {self.type} 不支持 realtime 运行模式")
return self
class AssistantOut(AssistantUpsert):
enforce_request_constraints: ClassVar[bool] = False
id: str
updated_at: str | None = None