|
|
|
|
@ -44,7 +44,7 @@ func (p *pluginServiceImpl) DuplicateDraftAgentTools(ctx context.Context, fromAg
|
|
|
|
|
return p.toolRepo.DuplicateDraftAgentTools(ctx, fromAgentID, toAgentID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *pluginServiceImpl) GetDraftAgentToolByName(ctx context.Context, agentID int64, toolName string) (tool *entity.ToolInfo, err error) {
|
|
|
|
|
func (p *pluginServiceImpl) GetDraftAgentToolByName(ctx context.Context, agentID int64, pluginID int64, toolName string) (tool *entity.ToolInfo, err error) {
|
|
|
|
|
draftAgentTool, exist, err := p.toolRepo.GetDraftAgentToolWithToolName(ctx, agentID, toolName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errorx.Wrapf(err, "GetDraftAgentToolWithToolName failed, agentID=%d, toolName=%s", agentID, toolName)
|
|
|
|
|
@ -53,9 +53,36 @@ func (p *pluginServiceImpl) GetDraftAgentToolByName(ctx context.Context, agentID
|
|
|
|
|
return nil, errorx.New(errno.ErrPluginRecordNotFound)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tool, exist, err = p.toolRepo.GetOnlineTool(ctx, draftAgentTool.ID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errorx.Wrapf(err, "GetOnlineTool failed, id=%d", draftAgentTool.ID)
|
|
|
|
|
if draftAgentTool.GetPluginFrom() == bot_common.PluginFrom_FromSaas {
|
|
|
|
|
tools, _, err := p.toolRepo.BatchGetSaasPluginToolsInfo(ctx, []int64{draftAgentTool.PluginID})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errorx.Wrapf(err, "BatchGetSaasPluginToolsInfo failed, pluginIDs=%v", []int64{draftAgentTool.PluginID})
|
|
|
|
|
}
|
|
|
|
|
if len(tools) == 0 || len(tools[draftAgentTool.PluginID]) == 0 {
|
|
|
|
|
return nil, errorx.New(errno.ErrPluginRecordNotFound)
|
|
|
|
|
}
|
|
|
|
|
exist = false
|
|
|
|
|
for _, saasTool := range tools[draftAgentTool.PluginID] {
|
|
|
|
|
if saasTool.ID == draftAgentTool.ID {
|
|
|
|
|
tool = saasTool
|
|
|
|
|
exist = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
_, exist, err := p.pluginRepo.GetOnlinePlugin(ctx, pluginID, repository.WithPluginID())
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errorx.Wrapf(err, "GetOnlinePlugin failed, pluginID=%d", pluginID)
|
|
|
|
|
}
|
|
|
|
|
if !exist {
|
|
|
|
|
return nil, errorx.New(errno.ErrPluginRecordNotFound)
|
|
|
|
|
}
|
|
|
|
|
tool, exist, err = p.toolRepo.GetOnlineTool(ctx, draftAgentTool.ID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errorx.Wrapf(err, "GetOnlineTool failed, id=%d", draftAgentTool.ID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if !exist {
|
|
|
|
|
return nil, errorx.New(errno.ErrPluginRecordNotFound)
|
|
|
|
|
@ -157,13 +184,6 @@ func (p *pluginServiceImpl) PublishAgentTools(ctx context.Context, agentID int64
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *pluginServiceImpl) UpdateBotDefaultParams(ctx context.Context, req *dto.UpdateBotDefaultParamsRequest) (err error) {
|
|
|
|
|
_, exist, err := p.pluginRepo.GetOnlinePlugin(ctx, req.PluginID, repository.WithPluginID())
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errorx.Wrapf(err, "GetOnlinePlugin failed, pluginID=%d", req.PluginID)
|
|
|
|
|
}
|
|
|
|
|
if !exist {
|
|
|
|
|
return errorx.New(errno.ErrPluginRecordNotFound)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
draftAgentTool, exist, err := p.toolRepo.GetDraftAgentToolWithToolName(ctx, req.AgentID, req.ToolName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
@ -173,9 +193,35 @@ func (p *pluginServiceImpl) UpdateBotDefaultParams(ctx context.Context, req *dto
|
|
|
|
|
return errorx.New(errno.ErrPluginRecordNotFound)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onlineTool, exist, err := p.toolRepo.GetOnlineTool(ctx, draftAgentTool.ID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errorx.Wrapf(err, "GetOnlineTool failed, id=%d", draftAgentTool.ID)
|
|
|
|
|
var onlineTool *entity.ToolInfo
|
|
|
|
|
if draftAgentTool.GetPluginFrom() == bot_common.PluginFrom_FromSaas {
|
|
|
|
|
tools, _, err := p.toolRepo.BatchGetSaasPluginToolsInfo(ctx, []int64{draftAgentTool.PluginID})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errorx.Wrapf(err, "BatchGetSaasPluginToolsInfo failed, pluginIDs=%v", []int64{draftAgentTool.PluginID})
|
|
|
|
|
}
|
|
|
|
|
if len(tools) == 0 || len(tools[draftAgentTool.PluginID]) == 0 {
|
|
|
|
|
return errorx.New(errno.ErrPluginRecordNotFound)
|
|
|
|
|
}
|
|
|
|
|
for _, saasTool := range tools[draftAgentTool.PluginID] {
|
|
|
|
|
if saasTool.ID == draftAgentTool.ID {
|
|
|
|
|
onlineTool = saasTool
|
|
|
|
|
exist = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
_, exist, err := p.pluginRepo.GetOnlinePlugin(ctx, req.PluginID, repository.WithPluginID())
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errorx.Wrapf(err, "GetOnlinePlugin failed, pluginID=%d", req.PluginID)
|
|
|
|
|
}
|
|
|
|
|
if !exist {
|
|
|
|
|
return errorx.New(errno.ErrPluginRecordNotFound)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onlineTool, exist, err = p.toolRepo.GetOnlineTool(ctx, draftAgentTool.ID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errorx.Wrapf(err, "GetOnlineTool failed, id=%d", draftAgentTool.ID)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !exist {
|
|
|
|
|
return errorx.New(errno.ErrPluginRecordNotFound)
|
|
|
|
|
|