feat: 修复审计落差 #1/#2/#3/#6 + 管理面板移动端适配
#1 工具布尔标记生效(agent-106, 安全红线): loop toolSchemas/runToolCalls 加 allow-set 安全门 restrictSchemas/applyToolSecurityGate——群聊/陌生人只暴露允许工具(默认关), 被拒not_allowed软提示+AuditEvent, owner全工具不变; 身份靠 ActorEnv(非提示词) #2 checkpoint 恢复(agent-109): run.go LoadLatest + resumableStopReason门控(只恢复in-flight工具循环,不出答案不续跑), 幂等不重放副作用, 新会话不误恢复; resume_test 4用例 #3 tool_result(agent-108, 协议层): Anthropic 原生tool_result块(tool_use_id/is_error)非user纯文本 + OpenAI tool消息补tool_call_id; Content加ToolCallID/IsError等; (loop接线层2处留待,见备注) #6 capacity_awaken推送(agent-107): onCapacity从只Debug改推WS hub(BroadcastCapacityAwaken, sessionId定向+payload对齐前端AwakenPayload) 管理面板移动端(agent-110): AdminApp 汉堡菜单+抽屉侧栏+标题truncate防换行, RBAC守卫不受影响 全仓 build/vet/test绿 + 前端build绿; 前端无涉差异已对齐 备注: #3 loop接线层2处(assistant工具轮append历史 + Message.ToolCallID/IsError)留给后续; #4代审/#5子代理触发/#7拆文件后置(主人说后三不急)
This commit is contained in:
1 parent
aedae2190b
commit
7e39153a69
24 files changed
+1286
-56
No files matched your search
@@ -509,3 +509,103 @@ func TestAnthropicChat_ToolResult(t *testing.T) {
|
||||
t.Errorf("is_error = %v, want true", blk["is_error"])
|
||||
}
|
||||
}
|
||||
|
||||
// anthropicBlockContent asserts a message renders a single Anthropic content block
|
||||
// and returns it as a map for inspection.
|
||||
func anthropicBlockContent(t *testing.T, msg anthropicMessage) (map[string]any, bool) {
|
||||
t.Helper()
|
||||
blocks, ok := msg.Content.([]any)
|
||||
if !ok || len(blocks) != 1 {
|
||||
t.Fatalf("content = %#v, want exactly 1 content block", msg.Content)
|
||||
}
|
||||
block, ok := blocks[0].(map[string]any)
|
||||
return block, ok
|
||||
}
|
||||
|
||||
func TestAnthropicChat_Build_ToolResultBlock(t *testing.T) {
|
||||
t.Parallel()
|
||||
msgs := []Message{
|
||||
TextMessage(RoleUser, "what's the weather in Paris?"),
|
||||
AssistantToolCallMessage([]ToolCall{{ID: "toolu_1", Name: "weather", Args: map[string]any{"city": "Paris"}}}),
|
||||
ToolResultMessage("toolu_1", `{"temp":22}`, true),
|
||||
}
|
||||
sys, out, err := buildAnthropicMessages(msgs)
|
||||
if err != nil {
|
||||
t.Fatalf("buildAnthropicMessages error: %v", err)
|
||||
}
|
||||
if sys != "" {
|
||||
t.Errorf("system = %q, want empty", sys)
|
||||
}
|
||||
if len(out) != 3 {
|
||||
t.Fatalf("messages = %d, want 3", len(out))
|
||||
}
|
||||
|
||||
// The assistant turn must carry the native tool_use block, not plain text.
|
||||
if out[1].Role != "assistant" {
|
||||
t.Errorf("assistant role = %q, want assistant", out[1].Role)
|
||||
}
|
||||
use, ok := anthropicBlockContent(t, out[1])
|
||||
if !ok {
|
||||
t.Fatal("assistant content is not a single block")
|
||||
}
|
||||
if use["type"] != "tool_use" || use["id"] != "toolu_1" || use["name"] != "weather" {
|
||||
t.Errorf("tool_use block = %#v, want type=tool_use id=toolu_1 name=weather", use)
|
||||
}
|
||||
if inp, _ := use["input"].(map[string]any); inp["city"] != "Paris" {
|
||||
t.Errorf("tool_use input = %#v, want {city:Paris}", use["input"])
|
||||
}
|
||||
|
||||
// The tool-result turn must be a user turn with a native tool_result block
|
||||
// (the audit's core fix: never a user plain-text turn).
|
||||
if out[2].Role != "user" {
|
||||
t.Errorf("tool-result role = %q, want user", out[2].Role)
|
||||
}
|
||||
tr, ok := anthropicBlockContent(t, out[2])
|
||||
if !ok {
|
||||
t.Fatal("tool-result content is not a single block")
|
||||
}
|
||||
if tr["type"] != "tool_result" {
|
||||
t.Errorf("type = %v, want tool_result (not plain user text)", tr["type"])
|
||||
}
|
||||
if tr["tool_use_id"] != "toolu_1" {
|
||||
t.Errorf("tool_use_id = %v, want toolu_1", tr["tool_use_id"])
|
||||
}
|
||||
if tr["content"] != `{"temp":22}` {
|
||||
t.Errorf("content = %v, want the raw result", tr["content"])
|
||||
}
|
||||
if tr["is_error"] != true {
|
||||
t.Errorf("is_error = %v, want true", tr["is_error"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnthropicChat_Build_ToolResultLegacyText(t *testing.T) {
|
||||
t.Parallel()
|
||||
// The loop's current form: a RoleTool message carrying a plain text part and
|
||||
// Message.ToolCallID. The protocol layer must still render a native tool_result
|
||||
// block (not a user plain-text turn).
|
||||
m := Message{Role: RoleTool, ToolCallID: "toolu_9",
|
||||
Content: []Content{{Type: ContentTypeText, Text: "tool weather result: 22"}}}
|
||||
_, out, err := buildAnthropicMessages([]Message{m})
|
||||
if err != nil {
|
||||
t.Fatalf("buildAnthropicMessages error: %v", err)
|
||||
}
|
||||
if len(out) != 1 {
|
||||
t.Fatalf("messages = %d, want 1", len(out))
|
||||
}
|
||||
if out[0].Role != "user" {
|
||||
t.Errorf("role = %q, want user", out[0].Role)
|
||||
}
|
||||
tr, ok := anthropicBlockContent(t, out[0])
|
||||
if !ok {
|
||||
t.Fatal("content is not a single block")
|
||||
}
|
||||
if tr["type"] != "tool_result" {
|
||||
t.Errorf("type = %v, want tool_result (not user text)", tr["type"])
|
||||
}
|
||||
if tr["tool_use_id"] != "toolu_9" {
|
||||
t.Errorf("tool_use_id = %v, want toolu_9", tr["tool_use_id"])
|
||||
}
|
||||
if tr["content"] != "tool weather result: 22" {
|
||||
t.Errorf("content = %v, want the text", tr["content"])
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user