feat: add prompt opening behavior modes

This commit is contained in:
Xin Wang
2026-08-04 13:29:21 +08:00
parent 78bba090a2
commit 5bf5987fe4
11 changed files with 235 additions and 97 deletions

View File

@@ -29,6 +29,7 @@ ToolExecutionMode = Literal["immediate", "async"]
ClientToolResponseWaitMode = Literal["timeout", "session"]
DynamicVariableType = Literal["string", "number", "boolean"]
PromptEntryMode = Literal["wait_user", "generate"]
PromptOpeningMode = Literal["interruptible", "playback", "confirmation"]
# 外部应用类型:其 config.apiKey 是该助手私有密钥,读时打码 / 写时哨兵
EXTERNAL_TYPES = {"dify", "fastgpt", "opencode"}
@@ -107,11 +108,11 @@ class OpeningMessageConfig(CamelModel):
title: str = Field(default="重要提示", min_length=1, max_length=120)
message: str = Field(min_length=1, max_length=2000)
confirm_label: str = Field(default="确认", min_length=1, max_length=40)
skip_speech_on_confirm: bool = True
class StartupConfig(CamelModel):
execution_mode: Literal["sequential"] = "sequential"
opening_mode: PromptOpeningMode | None = None
entry_mode: PromptEntryMode | None = None
actions: list[StartupAction] = Field(default_factory=list, max_length=5)
opening_message: OpeningMessageConfig | None = None
@@ -121,11 +122,22 @@ 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 self.opening_message is not None else "wait_user"
"generate" if legacy_confirmation else "wait_user"
)
return self
@@ -191,6 +203,7 @@ class AssistantUpsert(CamelModel):
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 模式暂不支持启动阶段")