mirror of
https://gitcode.com/JianFeeeee/homeagent-sdk.git
synced 2026-09-22 01:48:03 +00:00
fix: napcat returns json.RawMessage to avoid double-quoting in C ABI bridge
go_invoke_tool does json.Marshal(r) on handler results. When r is a string,
the raw JSON gets wrapped in quotes and escapes, causing the core's
json.Unmarshal into map[string]interface{} to fail (displayed as map[]).
Changed return type to json.RawMessage (implements json.Marshaler, outputs
raw bytes inline). Added rawString() helper for callers that need the
string representation.
This commit is contained in:
@ -693,7 +693,7 @@ func (p *Plugin) handleWebhook(w http.ResponseWriter, r *http.Request) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
raw, _ := resp.(string)
|
raw, _ := rawString(resp)
|
||||||
var gi struct {
|
var gi struct {
|
||||||
Data *struct {
|
Data *struct {
|
||||||
GroupName string `json:"group_name"`
|
GroupName string `json:"group_name"`
|
||||||
@ -1063,7 +1063,7 @@ func (p *Plugin) handleGetHistory(args map[string]interface{}) (interface{}, err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
rawStr, _ := rawResp.(string)
|
rawStr, _ := rawString(rawResp)
|
||||||
if rawStr == "" {
|
if rawStr == "" {
|
||||||
return map[string]interface{}{"messages": []interface{}{}, "note": "未获取到历史消息"}, nil
|
return map[string]interface{}{"messages": []interface{}{}, "note": "未获取到历史消息"}, nil
|
||||||
}
|
}
|
||||||
@ -1159,7 +1159,7 @@ func (p *Plugin) handleResolveNickname(args map[string]interface{}) (interface{}
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
raw, _ := v.(string)
|
raw, _ := rawString(v)
|
||||||
return filterMemberList(raw, keyword)
|
return filterMemberList(raw, keyword)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1167,7 +1167,7 @@ func (p *Plugin) handleResolveNickname(args map[string]interface{}) (interface{}
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
raw, _ := v.(string)
|
raw, _ := rawString(v)
|
||||||
return filterFriendList(raw, keyword)
|
return filterFriendList(raw, keyword)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1944,11 +1944,23 @@ func (p *Plugin) napcat(action string, params map[string]interface{}) (interface
|
|||||||
if err := json.NewDecoder(resp.Body).Decode(&raw); err != nil {
|
if err := json.NewDecoder(resp.Body).Decode(&raw); err != nil {
|
||||||
return nil, fmt.Errorf("napcat decode %s: %w", action, err)
|
return nil, fmt.Errorf("napcat decode %s: %w", action, err)
|
||||||
}
|
}
|
||||||
return string(raw), nil
|
return raw, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======== Helpers ========
|
// ======== Helpers ========
|
||||||
|
|
||||||
|
// rawString extracts a string from napcat's return type (json.RawMessage or string).
|
||||||
|
func rawString(v interface{}) (string, bool) {
|
||||||
|
switch r := v.(type) {
|
||||||
|
case string:
|
||||||
|
return r, true
|
||||||
|
case json.RawMessage:
|
||||||
|
return string(r), true
|
||||||
|
case []byte:
|
||||||
|
return string(r), true
|
||||||
|
}
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
|
||||||
var reAPIKey = regexp.MustCompile(`(?i)(api[_-]?key|token|secret|password)\s*[=:]\s*\S+`)
|
var reAPIKey = regexp.MustCompile(`(?i)(api[_-]?key|token|secret|password)\s*[=:]\s*\S+`)
|
||||||
var reSKKey = regexp.MustCompile(`sk-[a-zA-Z0-9]{20,}`)
|
var reSKKey = regexp.MustCompile(`sk-[a-zA-Z0-9]{20,}`)
|
||||||
|
|||||||
Reference in New Issue
Block a user