chore: commit workspace updates
This commit is contained in:
33
backend/internal/app/cloud_agent_json.go
Normal file
33
backend/internal/app/cloud_agent_json.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
)
|
||||
|
||||
var errCloudAgentJSONSingleObject = errors.New("参数必须是单个 JSON 对象")
|
||||
|
||||
// decodeCloudAgentJSONObject is used for model tool arguments. Tool arguments
|
||||
// are an untrusted protocol boundary: reject non-objects, unknown fields and
|
||||
// trailing JSON instead of silently accepting an ambiguous payload.
|
||||
func decodeCloudAgentJSONObject(raw string, target any) error {
|
||||
data := bytes.TrimSpace([]byte(raw))
|
||||
if len(data) == 0 || data[0] != '{' {
|
||||
return errCloudAgentJSONSingleObject
|
||||
}
|
||||
decoder := json.NewDecoder(bytes.NewReader(data))
|
||||
decoder.DisallowUnknownFields()
|
||||
if err := decoder.Decode(target); err != nil {
|
||||
return err
|
||||
}
|
||||
var extra any
|
||||
if err := decoder.Decode(&extra); err != io.EOF {
|
||||
if err == nil {
|
||||
return errCloudAgentJSONSingleObject
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user