refactor: enhance MCP tool management with risk policies and confirmation handling
This commit is contained in:
@@ -46,12 +46,24 @@ func resolveInterruptPrompt(summary *applicationruntime.RunResult) string {
|
||||
if summary == nil || len(summary.Interrupts) == 0 {
|
||||
return i18nx.Get("conversation.interrupt.defaultPrompt")
|
||||
}
|
||||
if prompt := extractInterruptMessage(summary.Interrupts[0].InfoPreview); prompt != "" {
|
||||
interrupt := summary.Interrupts[0]
|
||||
if prompt := strings.TrimSpace(interrupt.PromptText); prompt != "" {
|
||||
return prompt
|
||||
}
|
||||
if prompt := strings.TrimSpace(summary.Interrupts[0].InfoPreview); prompt != "" {
|
||||
if prompt := extractInterruptMessage(interrupt.InfoPreview); prompt != "" {
|
||||
return prompt
|
||||
}
|
||||
if prompt := strings.TrimSpace(summary.ReplyText); prompt != "" {
|
||||
return prompt
|
||||
}
|
||||
if interrupt.Type != "tool_confirmation" {
|
||||
if prompt := strings.TrimSpace(interrupt.InfoPreview); prompt != "" {
|
||||
return prompt
|
||||
}
|
||||
}
|
||||
if displayName := strings.TrimSpace(interrupt.DisplayName); displayName != "" {
|
||||
return "即将执行“" + displayName + "”,是否确认继续?"
|
||||
}
|
||||
return i18nx.Get("conversation.interrupt.defaultPrompt")
|
||||
}
|
||||
|
||||
|
||||
@@ -103,6 +103,22 @@ func TestResolveInterruptPrompt(t *testing.T) {
|
||||
if got := resolveInterruptPrompt(summary); got != "直接补充手机号" {
|
||||
t.Fatalf("unexpected raw interrupt prompt: %q", got)
|
||||
}
|
||||
|
||||
summary.ReplyText = ""
|
||||
summary.Interrupts[0] = applicationruntime.InterruptContextSummary{
|
||||
ID: "system/server_time",
|
||||
Type: "tool_confirmation",
|
||||
DisplayName: "获取当前时间",
|
||||
InfoPreview: "system/server_time",
|
||||
}
|
||||
if got := resolveInterruptPrompt(summary); got != "即将执行“获取当前时间”,是否确认继续?" {
|
||||
t.Fatalf("tool code leaked into customer prompt: %q", got)
|
||||
}
|
||||
|
||||
summary.Interrupts[0].PromptText = "请确认是否更新客户资料。"
|
||||
if got := resolveInterruptPrompt(summary); got != "请确认是否更新客户资料。" {
|
||||
t.Fatalf("explicit customer prompt was not preferred: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func newConversationFixture() models.Conversation {
|
||||
|
||||
Reference in New Issue
Block a user