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
@@ -352,3 +352,80 @@ func TestOpenAIChat_ChatStream_ToolCall(t *testing.T) {
|
||||
t.Errorf("events = %+v, want %+v", events, wantEvents)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenAIChat_Chat_ToolRoundTrip(t *testing.T) {
|
||||
t.Parallel()
|
||||
ch := make(chan capturedRequest, 1)
|
||||
srv := newCompletionServer(t, http.StatusOK, "application/json", okCompletion, ch)
|
||||
ad := NewOpenAIChat(config.LLMConfig{BaseURL: srv.URL, Model: "gpt-test"})
|
||||
|
||||
req := Request{Messages: []Message{
|
||||
TextMessage(RoleUser, "what's the weather in Paris?"),
|
||||
AssistantToolCallMessage([]ToolCall{{ID: "call_1", Name: "weather", Args: map[string]any{"city": "Paris"}}}),
|
||||
ToolResultMessage("call_1", `{"temp":22}`, true),
|
||||
}, Model: "gpt-test"}
|
||||
if _, err := ad.Chat(context.Background(), req, Options{}); err != nil {
|
||||
t.Fatalf("Chat error: %v", err)
|
||||
}
|
||||
|
||||
got := <-ch
|
||||
msgs, _ := got.body["messages"].([]any)
|
||||
if len(msgs) != 3 {
|
||||
t.Fatalf("body.messages = %v, want 3 messages", got.body["messages"])
|
||||
}
|
||||
|
||||
// The assistant turn must carry tool_calls (so the tool message can be
|
||||
// correlated by the provider) — this was previously dropped entirely.
|
||||
assistant, _ := msgs[1].(map[string]any)
|
||||
if assistant["role"] != "assistant" {
|
||||
t.Errorf("assistant role = %v, want assistant", assistant["role"])
|
||||
}
|
||||
tcs, _ := assistant["tool_calls"].([]any)
|
||||
if len(tcs) != 1 {
|
||||
t.Fatalf("assistant tool_calls = %v, want 1 entry", assistant["tool_calls"])
|
||||
}
|
||||
tc := tcs[0].(map[string]any)
|
||||
if tc["id"] != "call_1" || tc["type"] != "function" {
|
||||
t.Errorf("tool_call = %v, want id=call_1 type=function", tc)
|
||||
}
|
||||
fn, _ := tc["function"].(map[string]any)
|
||||
if fn["name"] != "weather" || fn["arguments"] != `{"city":"Paris"}` {
|
||||
t.Errorf("function = %#v, want name=weather arguments={\"city\":\"Paris\"}", fn)
|
||||
}
|
||||
|
||||
// The tool message must carry tool_call_id (the audit's gap) and the result.
|
||||
tool, _ := msgs[2].(map[string]any)
|
||||
if tool["role"] != "tool" {
|
||||
t.Errorf("tool role = %v, want tool", tool["role"])
|
||||
}
|
||||
if tool["tool_call_id"] != "call_1" {
|
||||
t.Errorf("tool_call_id = %v, want call_1", tool["tool_call_id"])
|
||||
}
|
||||
if tool["content"] != `{"temp":22}` {
|
||||
t.Errorf("tool content = %v, want the raw result", tool["content"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenAIChat_Build_ToolMessageLegacy(t *testing.T) {
|
||||
t.Parallel()
|
||||
// The loop's current form: a RoleTool message carrying a plain text part and
|
||||
// Message.ToolCallID. buildMessages must emit a tool message with tool_call_id.
|
||||
m := Message{Role: RoleTool, ToolCallID: "call_9",
|
||||
Content: []Content{{Type: ContentTypeText, Text: "tool weather result: 22"}}}
|
||||
msgs, err := buildMessages([]Message{m})
|
||||
if err != nil {
|
||||
t.Fatalf("buildMessages error: %v", err)
|
||||
}
|
||||
if len(msgs) != 1 {
|
||||
t.Fatalf("messages = %d, want 1", len(msgs))
|
||||
}
|
||||
if msgs[0].Role != "tool" {
|
||||
t.Errorf("role = %q, want tool", msgs[0].Role)
|
||||
}
|
||||
if msgs[0].ToolCallID != "call_9" {
|
||||
t.Errorf("tool_call_id = %q, want call_9", msgs[0].ToolCallID)
|
||||
}
|
||||
if msgs[0].Content != "tool weather result: 22" {
|
||||
t.Errorf("content = %v, want the text", msgs[0].Content)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user