fix: delete redundant fields in plugin output data (#469)
This commit is contained in:
@ -201,7 +201,7 @@ func (t *pluginService) GetPluginToolsInfo(ctx context.Context, req *crossplugin
|
||||
)
|
||||
if toolExample != nil {
|
||||
requestExample = toolExample.RequestExample
|
||||
responseExample = toolExample.RequestExample
|
||||
responseExample = toolExample.ResponseExample
|
||||
}
|
||||
|
||||
response.ToolInfoList[tf.ID] = crossplugin.ToolInfo{
|
||||
@ -220,6 +220,63 @@ func (t *pluginService) GetPluginToolsInfo(ctx context.Context, req *crossplugin
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (t *pluginService) UnwrapArrayItemFieldsInVariable(v *vo.Variable) error {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if v.Type == vo.VariableTypeObject {
|
||||
subVars, ok := v.Schema.([]*vo.Variable)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
newSubVars := make([]*vo.Variable, 0, len(subVars))
|
||||
for _, subVar := range subVars {
|
||||
if subVar.Name == "[Array Item]" {
|
||||
if err := t.UnwrapArrayItemFieldsInVariable(subVar); err != nil {
|
||||
return err
|
||||
}
|
||||
// If the array item is an object, append its children
|
||||
if subVar.Type == vo.VariableTypeObject {
|
||||
if innerSubVars, ok := subVar.Schema.([]*vo.Variable); ok {
|
||||
newSubVars = append(newSubVars, innerSubVars...)
|
||||
}
|
||||
} else {
|
||||
// If the array item is a primitive type, clear its name and append it
|
||||
subVar.Name = ""
|
||||
newSubVars = append(newSubVars, subVar)
|
||||
}
|
||||
} else {
|
||||
// For other sub-variables, recursively unwrap and append
|
||||
if err := t.UnwrapArrayItemFieldsInVariable(subVar); err != nil {
|
||||
return err
|
||||
}
|
||||
newSubVars = append(newSubVars, subVar)
|
||||
}
|
||||
}
|
||||
v.Schema = newSubVars
|
||||
|
||||
} else if v.Type == vo.VariableTypeList {
|
||||
if v.Schema != nil {
|
||||
subVar, ok := v.Schema.(*vo.Variable)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := t.UnwrapArrayItemFieldsInVariable(subVar); err != nil {
|
||||
return err
|
||||
}
|
||||
// If the array item definition itself has "[Array Item]" name, clear it
|
||||
if subVar.Name == "[Array Item]" {
|
||||
subVar.Name = ""
|
||||
}
|
||||
v.Schema = subVar
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *pluginService) GetPluginInvokableTools(ctx context.Context, req *crossplugin.ToolsInvokableRequest) (
|
||||
_ map[int64]crossplugin.InvokableTool, err error) {
|
||||
defer func() {
|
||||
@ -327,7 +384,7 @@ func (t *pluginService) ExecutePlugin(ctx context.Context, input map[string]any,
|
||||
}
|
||||
|
||||
var output map[string]any
|
||||
err = sonic.UnmarshalString(r.RawResp, &output)
|
||||
err = sonic.UnmarshalString(r.TrimmedResp, &output)
|
||||
if err != nil {
|
||||
return nil, vo.WrapError(errno.ErrSerializationDeserializationFail, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user