Files
Losita d7184b776b Version: 0.9.75.dev.260505
后端:
1.收口阶段 6 agent 结构迁移,将 newAgent 内核与 agentsvc 编排层迁入 services/agent
- 切换 Agent 启动装配与 HTTP handler 直连 agent sv,移除旧 service agent bridge
- 补齐 Agent 对 memory、task、task-class、schedule 的 RPC 适配与契约字段
- 扩展 schedule、task、task-class RPC/contract 支撑 Agent 查询、写入与 provider 切流
- 更新迁移文档、README 与相关注释,明确 agent 当前切流点和剩余 memory 迁移面
2026-05-05 16:00:57 +08:00

62 lines
1.7 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package schedule
import (
"fmt"
"sort"
"strings"
)
// validateToolArgsStrict 校验工具参数是否全部命中 schema 白名单。
//
// 职责边界:
// 1. 只做“字段名是否允许”的校验,不校验字段值合法性;
// 2. 发现未知字段时直接报错,避免静默忽略导致范围漂移;
// 3. 该函数不做别名兼容,调用方应自行传入 schema 中允许的字段。
func validateToolArgsStrict(args map[string]any, allowedKeys []string) error {
if len(args) == 0 {
return nil
}
allowed := make(map[string]struct{}, len(allowedKeys))
for _, key := range allowedKeys {
allowed[strings.TrimSpace(key)] = struct{}{}
}
unknown := make([]string, 0, len(args))
for key := range args {
trimmed := strings.TrimSpace(key)
if trimmed == "" {
continue
}
if _, ok := allowed[trimmed]; ok {
continue
}
unknown = append(unknown, trimmed)
}
if len(unknown) == 0 {
return nil
}
sort.Strings(unknown)
hint := "请仅使用当前工具 schema 中声明的参数字段。"
if containsAnyUnknownArg(unknown, "day_from", "day_to") {
hint = "请仅使用当前工具 schema 中声明的参数字段day_from/day_to 不受支持,请改用 day_start/day_end。"
}
return fmt.Errorf("参数非法:%s。%s", strings.Join(unknown, "、"), hint)
}
func containsAnyUnknownArg(keys []string, targets ...string) bool {
if len(keys) == 0 || len(targets) == 0 {
return false
}
targetSet := make(map[string]struct{}, len(targets))
for _, target := range targets {
targetSet[strings.TrimSpace(target)] = struct{}{}
}
for _, key := range keys {
if _, ok := targetSet[strings.TrimSpace(key)]; ok {
return true
}
}
return false
}