fix: Correct role config versioning, sync on publish, and resolve chat flow copy bug
This commit is contained in:
@ -3915,7 +3915,13 @@ func (w *ApplicationService) GetChatFlowRole(ctx context.Context, req *workflow.
|
||||
|
||||
var version string
|
||||
if wf.Meta.AppID != nil {
|
||||
version = "" // TODO : search version from DB using AppID
|
||||
vl, err := GetWorkflowDomainSVC().GetWorkflowVersionsByConnector(ctx, mustParseInt64(req.GetConnectorID()), wf.ID, 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(vl) > 0 {
|
||||
version = vl[0]
|
||||
}
|
||||
}
|
||||
|
||||
role, err := GetWorkflowDomainSVC().GetChatFlowRole(ctx, mustParseInt64(req.WorkflowID), version)
|
||||
|
||||
@ -50,6 +50,7 @@ type Service interface {
|
||||
DeleteChatFlowRole(ctx context.Context, id int64, workflowID int64) error
|
||||
PublishChatFlowRole(ctx context.Context, policy *vo.PublishRolePolicy) error
|
||||
CopyChatFlowRole(ctx context.Context, policy *vo.CopyRolePolicy) error
|
||||
GetWorkflowVersionsByConnector(ctx context.Context, connectorID, workflowID int64, limit int) ([]string, error)
|
||||
|
||||
Executable
|
||||
AsTool
|
||||
@ -76,6 +77,7 @@ type Repository interface {
|
||||
GetMeta(ctx context.Context, id int64) (*vo.Meta, error)
|
||||
UpdateMeta(ctx context.Context, id int64, metaUpdate *vo.MetaUpdate) error
|
||||
GetVersion(ctx context.Context, id int64, version string) (*vo.VersionInfo, error)
|
||||
GetVersionListByConnectorAndWorkflowID(ctx context.Context, connectorID, workflowID int64, limit int) ([]string, error)
|
||||
|
||||
GetEntity(ctx context.Context, policy *vo.GetPolicy) (*entity.Workflow, error)
|
||||
|
||||
|
||||
@ -618,6 +618,7 @@ func (r *RepositoryImpl) CreateChatFlowRoleConfig(ctx context.Context, chatFlowR
|
||||
SuggestReplyInfo: chatFlowRole.SuggestReplyInfo,
|
||||
UserInputConfig: chatFlowRole.UserInputConfig,
|
||||
CreatorID: chatFlowRole.CreatorID,
|
||||
Version: chatFlowRole.Version,
|
||||
}
|
||||
|
||||
if err := r.query.ChatFlowRoleConfig.WithContext(ctx).Create(chatFlowRoleConfig); err != nil {
|
||||
@ -743,6 +744,30 @@ func (r *RepositoryImpl) GetVersion(ctx context.Context, id int64, version strin
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *RepositoryImpl) GetVersionListByConnectorAndWorkflowID(ctx context.Context, connectorID, workflowID int64, limit int) (_ []string, err error) {
|
||||
defer func() {
|
||||
if err != nil {
|
||||
err = vo.WrapIfNeeded(errno.ErrDatabaseError, err)
|
||||
}
|
||||
}()
|
||||
|
||||
connectorWorkflowVersion := r.query.ConnectorWorkflowVersion
|
||||
vl, err := connectorWorkflowVersion.WithContext(ctx).
|
||||
Where(connectorWorkflowVersion.ConnectorID.Eq(connectorID),
|
||||
connectorWorkflowVersion.WorkflowID.Eq(workflowID)).
|
||||
Order(connectorWorkflowVersion.CreatedAt.Desc()).
|
||||
Limit(limit).
|
||||
Find()
|
||||
if err != nil {
|
||||
return nil, vo.WrapError(errno.ErrDatabaseError, err)
|
||||
}
|
||||
var versionList []string
|
||||
for _, v := range vl {
|
||||
versionList = append(versionList, v.Version)
|
||||
}
|
||||
return versionList, nil
|
||||
}
|
||||
|
||||
func (r *RepositoryImpl) IsApplicationConnectorWorkflowVersion(ctx context.Context, connectorID, workflowID int64, version string) (b bool, err error) {
|
||||
connectorWorkflowVersion := r.query.ConnectorWorkflowVersion
|
||||
_, err = connectorWorkflowVersion.WithContext(ctx).
|
||||
@ -1629,6 +1654,7 @@ func (r *RepositoryImpl) CopyWorkflow(ctx context.Context, workflowID int64, pol
|
||||
IconURI: wfMeta.IconURI,
|
||||
Desc: wfMeta.Description,
|
||||
AppID: ternary.IFElse(wfMeta.AppID == 0, (*int64)(nil), ptr.Of(wfMeta.AppID)),
|
||||
Mode: vo.WorkflowMode(wfMeta.Mode),
|
||||
},
|
||||
CanvasInfo: &vo.CanvasInfo{
|
||||
Canvas: wfDraft.Canvas,
|
||||
|
||||
@ -545,6 +545,10 @@ func (i *impl) GetChatFlowRole(ctx context.Context, workflowID int64, version st
|
||||
return role, nil
|
||||
}
|
||||
|
||||
func (i *impl) GetWorkflowVersionsByConnector(ctx context.Context, connectorID, workflowID int64, limit int) ([]string, error) {
|
||||
return i.repo.GetVersionListByConnectorAndWorkflowID(ctx, connectorID, workflowID, limit)
|
||||
}
|
||||
|
||||
func (i *impl) DeleteChatFlowRole(ctx context.Context, id int64, workflowID int64) error {
|
||||
return i.repo.DeleteChatFlowRoleConfig(ctx, id, workflowID)
|
||||
}
|
||||
@ -922,6 +926,19 @@ func (i *impl) ReleaseApplicationWorkflows(ctx context.Context, appID int64, con
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, wf := range wfs {
|
||||
if wf.Mode == cloudworkflow.WorkflowMode_ChatFlow {
|
||||
err = i.PublishChatFlowRole(ctx, &vo.PublishRolePolicy{
|
||||
WorkflowID: wf.ID,
|
||||
CreatorID: wf.CreatorID,
|
||||
Version: config.Version,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, connectorID := range config.ConnectorIDs {
|
||||
err = i.repo.BatchCreateConnectorWorkflowVersion(ctx, appID, connectorID, workflowIDs, config.Version)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user