返回 DeepSeek-Reasonix
canonicalize.go
根目录 / internal / plugin / canonicalize.go
1 package plugin
2
3 import (
4 "encoding/json"
5 "sort"
6
7 "reasonix/internal/provider"
8 "reasonix/internal/tool"
9 )
10
11 // sortToolsByName returns a new slice of tools sorted alphabetically by Name().
12 func sortToolsByName(tools []tool.Tool) []tool.Tool {
13 sorted := make([]tool.Tool, len(tools))
14 copy(sorted, tools)
15 sort.SliceStable(sorted, func(i, j int) bool {
16 return sorted[i].Name() < sorted[j].Name()
17 })
18 return sorted
19 }
20
21 // canonicalizeSchema recursively stabilizes a JSON Schema so the same logical
22 // schema always produces the same byte representation — important for cache
23 // fingerprint stability across MCP sessions.
24 func canonicalizeSchema(raw json.RawMessage) json.RawMessage {
25 return provider.CanonicalizeSchema(raw)
26 }
27
27 lines GO