fix(plugin): setting the default value of the agent tool does not take effect (#341)
This commit is contained in:
@@ -216,6 +216,7 @@ func (t *toolRepoImpl) GetOnlineTool(ctx context.Context, toolID int64) (tool *e
|
||||
|
||||
func (t *toolRepoImpl) MGetOnlineTools(ctx context.Context, toolIDs []int64, opts ...ToolSelectedOptions) (tools []*entity.ToolInfo, err error) {
|
||||
toolProducts := pluginConf.MGetToolProducts(toolIDs)
|
||||
|
||||
tools = slices.Transform(toolProducts, func(tool *pluginConf.ToolInfo) *entity.ToolInfo {
|
||||
return tool.Info
|
||||
})
|
||||
@@ -269,13 +270,38 @@ func (t *toolRepoImpl) MGetVersionTools(ctx context.Context, versionTools []enti
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) BindDraftAgentTools(ctx context.Context, agentID int64, toolIDs []int64) (err error) {
|
||||
onlineTools, err := t.MGetOnlineTools(ctx, toolIDs)
|
||||
opt := &dal.ToolSelectedOption{
|
||||
ToolID: true,
|
||||
}
|
||||
draftAgentTools, err := t.agentToolDraftDAO.GetAll(ctx, agentID, opt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(onlineTools) == 0 {
|
||||
return t.agentToolDraftDAO.DeleteAll(ctx, agentID)
|
||||
draftAgentToolIDMap := slices.ToMap(draftAgentTools, func(tool *entity.ToolInfo) (int64, bool) {
|
||||
return tool.ID, true
|
||||
})
|
||||
|
||||
bindToolIDMap := slices.ToMap(toolIDs, func(toolID int64) (int64, bool) {
|
||||
return toolID, true
|
||||
})
|
||||
|
||||
newBindToolIDs := make([]int64, 0, len(toolIDs))
|
||||
for _, toolID := range toolIDs {
|
||||
_, ok := draftAgentToolIDMap[toolID]
|
||||
if ok {
|
||||
continue
|
||||
}
|
||||
newBindToolIDs = append(newBindToolIDs, toolID)
|
||||
}
|
||||
|
||||
removeToolIDs := make([]int64, 0, len(draftAgentTools))
|
||||
for toolID := range draftAgentToolIDMap {
|
||||
_, ok := bindToolIDMap[toolID]
|
||||
if ok {
|
||||
continue
|
||||
}
|
||||
removeToolIDs = append(removeToolIDs, toolID)
|
||||
}
|
||||
|
||||
tx := t.query.Begin()
|
||||
@@ -298,17 +324,29 @@ func (t *toolRepoImpl) BindDraftAgentTools(ctx context.Context, agentID int64, t
|
||||
}
|
||||
}()
|
||||
|
||||
err = t.agentToolDraftDAO.DeleteAllWithTX(ctx, tx, agentID)
|
||||
onlineTools, err := t.MGetOnlineTools(ctx, newBindToolIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = t.agentToolDraftDAO.BatchCreateWithTX(ctx, tx, agentID, onlineTools)
|
||||
if len(onlineTools) > 0 {
|
||||
err = t.agentToolDraftDAO.BatchCreateIgnoreConflictWithTX(ctx, tx, agentID, onlineTools)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err = t.agentToolDraftDAO.DeleteWithTX(ctx, tx, agentID, removeToolIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) GetAgentPluginIDs(ctx context.Context, agentID int64) (pluginIDs []int64, err error) {
|
||||
@@ -316,7 +354,7 @@ func (t *toolRepoImpl) GetAgentPluginIDs(ctx context.Context, agentID int64) (pl
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) DuplicateDraftAgentTools(ctx context.Context, fromAgentID, toAgentID int64) (err error) {
|
||||
tools, err := t.agentToolDraftDAO.GetAll(ctx, fromAgentID)
|
||||
tools, err := t.agentToolDraftDAO.GetAll(ctx, fromAgentID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -370,7 +408,7 @@ func (t *toolRepoImpl) UpdateDraftAgentTool(ctx context.Context, req *UpdateDraf
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) GetSpaceAllDraftAgentTools(ctx context.Context, agentID int64) (tools []*entity.ToolInfo, err error) {
|
||||
return t.agentToolDraftDAO.GetAll(ctx, agentID)
|
||||
return t.agentToolDraftDAO.GetAll(ctx, agentID, nil)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) GetVersionAgentTool(ctx context.Context, agentID int64, vAgentTool entity.VersionAgentTool) (tool *entity.ToolInfo, exist bool, err error) {
|
||||
|
||||
Reference in New Issue
Block a user