同步完整源码至远程:扁平化重构现状 + 未入库源文件
- 补入库:server/internal/db/dump.go、redis 分页/扫描预算测试、opsxdb-mcp main_test、 packages/opsxdb-mcp package-lock、docs 审计与对比文档等 37 个新文件 - 含结构扁平化进行中的 80 处修改与 155 处旧结构删除(server/ src/ src-tauri/ 为当前有效源) - 构建产物(bin/target/dist)与签名私钥仍按规则排除
This commit is contained in:
1 parent
5c0be49217
commit
2c0bfafd8d
269 files changed
+10372
-16435
No files matched your search
+28
-20
@@ -34,17 +34,17 @@ type AgentReq struct {
|
||||
|
||||
// AgentStep 挂在回复下的步骤时间线一项。
|
||||
type AgentStep struct {
|
||||
Tool string `json:"tool"`
|
||||
Args string `json:"args,omitempty"`
|
||||
OK bool `json:"ok"`
|
||||
Summary string `json:"summary"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Ms int64 `json:"ms"`
|
||||
NeedConfirm bool `json:"needConfirm,omitempty"`
|
||||
ConfirmSQL string `json:"confirmSql,omitempty"`
|
||||
ConfirmBind string `json:"confirmBind,omitempty"`
|
||||
Pending bool `json:"pending,omitempty"`
|
||||
Result *AgentQueryResult `json:"result,omitempty"`
|
||||
Tool string `json:"tool"`
|
||||
Args string `json:"args,omitempty"`
|
||||
OK bool `json:"ok"`
|
||||
Summary string `json:"summary"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Ms int64 `json:"ms"`
|
||||
NeedConfirm bool `json:"needConfirm,omitempty"`
|
||||
ConfirmSQL string `json:"confirmSql,omitempty"`
|
||||
ConfirmBind string `json:"confirmBind,omitempty"`
|
||||
Pending bool `json:"pending,omitempty"`
|
||||
Result *AgentQueryResult `json:"result,omitempty"`
|
||||
}
|
||||
|
||||
// AgentRes Agent 最终回答 + 步骤 + 运行结果契约。
|
||||
@@ -60,7 +60,7 @@ type AgentRes struct {
|
||||
Resumable bool `json:"resumable,omitempty"`
|
||||
StepsBudget int `json:"stepsBudget,omitempty"`
|
||||
// Trajectory 含 system/user/assistant.tool_calls/tool 的完整对话(供落盘续跑;JSON 默认省略大字段可选)
|
||||
Trajectory []Message `json:"trajectory,omitempty"`
|
||||
Trajectory []Message `json:"trajectory,omitempty"`
|
||||
}
|
||||
|
||||
// RunAgent 多轮:LLM tool_call → aitools.Runtime.Call → 回灌。
|
||||
@@ -98,6 +98,10 @@ func runAgent(ctx context.Context, llm ToolChat, rt *aitools.Runtime, req AgentR
|
||||
req.SessionID = sessionID
|
||||
}
|
||||
rt.RunID = runID
|
||||
if req.ConnectionID != "" {
|
||||
rt.BoundConnectionID = req.ConnectionID
|
||||
rt.BoundDatabase = req.Database
|
||||
}
|
||||
// Agent 路径禁止模型自行带确认令牌
|
||||
rt.RejectCallerConfirm = true
|
||||
|
||||
@@ -106,14 +110,14 @@ func runAgent(ctx context.Context, llm ToolChat, rt *aitools.Runtime, req AgentR
|
||||
if req.Continue && len(req.Prior) > 0 {
|
||||
msgs = append([]Message{}, req.Prior...)
|
||||
hasSystem := false
|
||||
for _, m := range msgs {
|
||||
for i, m := range msgs {
|
||||
if m.Role == "system" {
|
||||
msgs[i].Content = buildAgentSystem(req, rt.Policy)
|
||||
hasSystem = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasSystem {
|
||||
msgs = append([]Message{{Role: "system", Content: buildAgentSystem(req)}}, msgs...)
|
||||
msgs = append([]Message{{Role: "system", Content: buildAgentSystem(req, rt.Policy)}}, msgs...)
|
||||
}
|
||||
if prompt != "" {
|
||||
msgs = append(msgs, Message{Role: "user", Content: prompt})
|
||||
@@ -121,7 +125,7 @@ func runAgent(ctx context.Context, llm ToolChat, rt *aitools.Runtime, req AgentR
|
||||
msgs = TrimMessages(msgs, h)
|
||||
} else {
|
||||
msgs = []Message{
|
||||
{Role: "system", Content: buildAgentSystem(req)},
|
||||
{Role: "system", Content: buildAgentSystem(req, rt.Policy)},
|
||||
{Role: "user", Content: prompt},
|
||||
}
|
||||
}
|
||||
@@ -258,18 +262,22 @@ func runAgent(ctx context.Context, llm ToolChat, rt *aitools.Runtime, req AgentR
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func buildAgentSystem(req AgentReq) string {
|
||||
func buildAgentSystem(req AgentReq, policy aitools.Policy) string {
|
||||
var b strings.Builder
|
||||
b.WriteString("你是 OpsxDB 数据库 Agent。你可以通过工具查询用户已白名单的连接。\n")
|
||||
b.WriteString("规则:\n")
|
||||
b.WriteString("1. 需要查库时必须调用工具;不要假装已执行 SQL。\n")
|
||||
b.WriteString("2. 默认只读:execute_query 以 SELECT/SHOW/EXPLAIN/DESCRIBE/WITH…SELECT 为主;Redis 以读命令为主。\n")
|
||||
if policy.WritesEnabled() {
|
||||
b.WriteString("2. 当前允许申请写操作:有写入意图时调用对应工具生成待确认命令;工具要求确认后必须停下,等待用户在界面确认,不能自行确认。\n")
|
||||
} else {
|
||||
b.WriteString("2. 当前策略为只读:仅能查询,写操作会被拒绝,也不会出现写操作确认。用户需要写入时,说明需先在设置 → MCP 选择使用默认权限,再提交任务并逐次确认。\n")
|
||||
}
|
||||
b.WriteString("3. 写操作若被拒绝并提示需要确认,向用户说明须在界面确认后执行;不要声称已写入。\n")
|
||||
b.WriteString("4. 先确认 connection_id(可用 opsxdb_list_connections);用户给出偏好连接时优先用它。\n")
|
||||
b.WriteString("4. 只使用当前会话绑定的 connection_id 和数据库;调用工具时传入它们,不要切换到其他连接或库。\n")
|
||||
b.WriteString("5. 用中文简明回答;可执行 SQL 放在 ```sql 代码块中。\n")
|
||||
b.WriteString("6. 工具结果可能截断,注意说明。\n")
|
||||
if req.ConnectionID != "" {
|
||||
b.WriteString(fmt.Sprintf("\n用户当前偏好连接 id: %s", req.ConnectionID))
|
||||
b.WriteString(fmt.Sprintf("\n当前会话绑定连接 id: %s", req.ConnectionID))
|
||||
if req.Driver != "" {
|
||||
b.WriteString(fmt.Sprintf("(%s)", req.Driver))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user