feat: manually mirror opencoze's code from bytedance

Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
fanlv
2025-07-20 17:36:12 +08:00
commit 890153324f
14811 changed files with 1923430 additions and 0 deletions

View File

@@ -0,0 +1,97 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dal
import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/redis/go-redis/v9"
"github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/developer_api"
"github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/entity"
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
"github.com/coze-dev/coze-studio/backend/types/errno"
)
func makeAgentDisplayInfoKey(userID, agentID int64) string {
return fmt.Sprintf("agent_display_info:%d:%d", userID, agentID)
}
func (sa *SingleAgentDraftDAO) UpdateDisplayInfo(ctx context.Context, userID int64, e *entity.AgentDraftDisplayInfo) error {
data, err := json.Marshal(e)
if err != nil {
return errorx.WrapByCode(err, errno.ErrAgentSetDraftBotDisplayInfo)
}
key := makeAgentDisplayInfoKey(userID, e.AgentID)
_, err = sa.cacheClient.Set(ctx, key, data, 0).Result()
if err != nil {
return errorx.WrapByCode(err, errno.ErrAgentSetDraftBotDisplayInfo)
}
return nil
}
func (sa *SingleAgentDraftDAO) GetDisplayInfo(ctx context.Context, userID, agentID int64) (*entity.AgentDraftDisplayInfo, error) {
key := makeAgentDisplayInfoKey(userID, agentID)
data, err := sa.cacheClient.Get(ctx, key).Result()
if errors.Is(err, redis.Nil) {
tabStatusDefault := developer_api.TabStatus_Default
return &entity.AgentDraftDisplayInfo{
AgentID: agentID,
DisplayInfo: &developer_api.DraftBotDisplayInfoData{
TabDisplayInfo: &developer_api.TabDisplayItems{
PluginTabStatus: &tabStatusDefault,
WorkflowTabStatus: &tabStatusDefault,
KnowledgeTabStatus: &tabStatusDefault,
DatabaseTabStatus: &tabStatusDefault,
VariableTabStatus: &tabStatusDefault,
OpeningDialogTabStatus: &tabStatusDefault,
ScheduledTaskTabStatus: &tabStatusDefault,
SuggestionTabStatus: &tabStatusDefault,
TtsTabStatus: &tabStatusDefault,
FileboxTabStatus: &tabStatusDefault,
LongTermMemoryTabStatus: &tabStatusDefault,
AnswerActionTabStatus: &tabStatusDefault,
ImageflowTabStatus: &tabStatusDefault,
BackgroundImageTabStatus: &tabStatusDefault,
ShortcutTabStatus: &tabStatusDefault,
KnowledgeTableTabStatus: &tabStatusDefault,
KnowledgeTextTabStatus: &tabStatusDefault,
KnowledgePhotoTabStatus: &tabStatusDefault,
HookInfoTabStatus: &tabStatusDefault,
DefaultUserInputTabStatus: &tabStatusDefault,
},
},
}, nil
}
if err != nil {
return nil, errorx.WrapByCode(err, errno.ErrAgentGetDraftBotDisplayInfoNotFound)
}
e := &entity.AgentDraftDisplayInfo{}
err = json.Unmarshal([]byte(data), e)
if err != nil {
return nil, errorx.WrapByCode(err, errno.ErrAgentGetDraftBotDisplayInfoNotFound)
}
return e, nil
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dal
import (
"context"
"strconv"
"github.com/redis/go-redis/v9"
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
)
func NewCountRepo(cli *redis.Client) *CounterImpl {
return &CounterImpl{
cacheClient: cli,
}
}
type CounterImpl struct {
cacheClient *redis.Client
}
func (c *CounterImpl) Get(ctx context.Context, key string) (int64, error) {
val, err := c.cacheClient.Get(ctx, key).Result()
if err == redis.Nil {
return 0, nil
}
if err != nil {
return 0, errorx.Wrapf(err, "failed to get count for %s", key)
}
return strconv.ParseInt(val, 10, 64)
}
func (c *CounterImpl) IncrBy(ctx context.Context, key string, incr int64) error {
_, err := c.cacheClient.IncrBy(ctx, key, incr).Result()
return errorx.Wrapf(err, "failed to incr_by count for %s", key)
}
func (c *CounterImpl) Set(ctx context.Context, key string, value int64) error {
_, err := c.cacheClient.Set(ctx, key, value, 0).Result()
return errorx.Wrapf(err, "failed to set count for %s", key)
}
func (c *CounterImpl) Del(ctx context.Context, key string) error {
_, err := c.cacheClient.Del(ctx, key).Result()
return errorx.Wrapf(err, "failed to del count for %s", key)
}

View File

@@ -0,0 +1,43 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
import (
"github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/bot_common"
"gorm.io/gorm"
)
const TableNameSingleAgentDraft = "single_agent_draft"
// SingleAgentDraft Single Agent Draft Copy Table
type SingleAgentDraft struct {
ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:Primary Key ID" json:"id"` // Primary Key ID
AgentID int64 `gorm:"column:agent_id;not null;comment:Agent ID" json:"agent_id"` // Agent ID
CreatorID int64 `gorm:"column:creator_id;not null;comment:Creator ID" json:"creator_id"` // Creator ID
SpaceID int64 `gorm:"column:space_id;not null;comment:Space ID" json:"space_id"` // Space ID
Name string `gorm:"column:name;not null;comment:Agent Name" json:"name"` // Agent Name
Description string `gorm:"column:description;not null;comment:Agent Description" json:"description"` // Agent Description
IconURI string `gorm:"column:icon_uri;not null;comment:Icon URI" json:"icon_uri"` // Icon URI
CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds
UpdatedAt int64 `gorm:"column:updated_at;not null;autoUpdateTime:milli;comment:Update Time in Milliseconds" json:"updated_at"` // Update Time in Milliseconds
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:delete time in millisecond" json:"deleted_at"` // delete time in millisecond
VariablesMetaID *int64 `gorm:"column:variables_meta_id;comment:variables meta 表 ID" json:"variables_meta_id"` // variables meta 表 ID
ModelInfo *bot_common.ModelInfo `gorm:"column:model_info;comment:Model Configuration Information;serializer:json" json:"model_info"` // Model Configuration Information
OnboardingInfo *bot_common.OnboardingInfo `gorm:"column:onboarding_info;comment:Onboarding Information;serializer:json" json:"onboarding_info"` // Onboarding Information
Prompt *bot_common.PromptInfo `gorm:"column:prompt;comment:Agent Prompt Configuration;serializer:json" json:"prompt"` // Agent Prompt Configuration
Plugin []*bot_common.PluginInfo `gorm:"column:plugin;comment:Agent Plugin Base Configuration;serializer:json" json:"plugin"` // Agent Plugin Base Configuration
Knowledge *bot_common.Knowledge `gorm:"column:knowledge;comment:Agent Knowledge Base Configuration;serializer:json" json:"knowledge"` // Agent Knowledge Base Configuration
Workflow []*bot_common.WorkflowInfo `gorm:"column:workflow;comment:Agent Workflow Configuration;serializer:json" json:"workflow"` // Agent Workflow Configuration
SuggestReply *bot_common.SuggestReplyInfo `gorm:"column:suggest_reply;comment:Suggested Replies;serializer:json" json:"suggest_reply"` // Suggested Replies
JumpConfig *bot_common.JumpConfig `gorm:"column:jump_config;comment:Jump Configuration;serializer:json" json:"jump_config"` // Jump Configuration
BackgroundImageInfoList []*bot_common.BackgroundImageInfo `gorm:"column:background_image_info_list;comment:Background image;serializer:json" json:"background_image_info_list"` // Background image
DatabaseConfig []*bot_common.Database `gorm:"column:database_config;comment:Agent Database Base Configuration;serializer:json" json:"database_config"` // Agent Database Base Configuration
ShortcutCommand []string `gorm:"column:shortcut_command;comment:shortcut command;serializer:json" json:"shortcut_command"` // shortcut command
}
// TableName SingleAgentDraft's table name
func (*SingleAgentDraft) TableName() string {
return TableNameSingleAgentDraft
}

View File

@@ -0,0 +1,28 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
const TableNameSingleAgentPublish = "single_agent_publish"
// SingleAgentPublish bot 渠道和发布版本流水表
type SingleAgentPublish struct {
ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键id" json:"id"` // 主键id
AgentID int64 `gorm:"column:agent_id;not null;comment:agent_id" json:"agent_id"` // agent_id
PublishID string `gorm:"column:publish_id;not null;comment:发布 id" json:"publish_id"` // 发布 id
ConnectorIds []int64 `gorm:"column:connector_ids;comment:发布的 connector_ids;serializer:json" json:"connector_ids"` // 发布的 connector_ids
Version string `gorm:"column:version;not null;comment:Agent Version" json:"version"` // Agent Version
PublishInfo *string `gorm:"column:publish_info;comment:发布信息" json:"publish_info"` // 发布信息
PublishTime int64 `gorm:"column:publish_time;not null;comment:发布时间" json:"publish_time"` // 发布时间
CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds
UpdatedAt int64 `gorm:"column:updated_at;not null;autoUpdateTime:milli;comment:Update Time in Milliseconds" json:"updated_at"` // Update Time in Milliseconds
CreatorID int64 `gorm:"column:creator_id;not null;comment:发布人 user_id" json:"creator_id"` // 发布人 user_id
Status int32 `gorm:"column:status;not null;comment:状态 0:使用中 1:删除 3:禁用" json:"status"` // 状态 0:使用中 1:删除 3:禁用
Extra *string `gorm:"column:extra;comment:扩展字段" json:"extra"` // 扩展字段
}
// TableName SingleAgentPublish's table name
func (*SingleAgentPublish) TableName() string {
return TableNameSingleAgentPublish
}

View File

@@ -0,0 +1,45 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
import (
"github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/bot_common"
"gorm.io/gorm"
)
const TableNameSingleAgentVersion = "single_agent_version"
// SingleAgentVersion Single Agent Version Copy Table
type SingleAgentVersion struct {
ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:Primary Key ID" json:"id"` // Primary Key ID
AgentID int64 `gorm:"column:agent_id;not null;comment:Agent ID" json:"agent_id"` // Agent ID
CreatorID int64 `gorm:"column:creator_id;not null;comment:Creator ID" json:"creator_id"` // Creator ID
SpaceID int64 `gorm:"column:space_id;not null;comment:Space ID" json:"space_id"` // Space ID
Name string `gorm:"column:name;not null;comment:Agent Name" json:"name"` // Agent Name
Description string `gorm:"column:description;not null;comment:Agent Description" json:"description"` // Agent Description
IconURI string `gorm:"column:icon_uri;not null;comment:Icon URI" json:"icon_uri"` // Icon URI
CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds
UpdatedAt int64 `gorm:"column:updated_at;not null;autoUpdateTime:milli;comment:Update Time in Milliseconds" json:"updated_at"` // Update Time in Milliseconds
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:delete time in millisecond" json:"deleted_at"` // delete time in millisecond
VariablesMetaID *int64 `gorm:"column:variables_meta_id;comment:variables meta 表 ID" json:"variables_meta_id"` // variables meta 表 ID
ModelInfo *bot_common.ModelInfo `gorm:"column:model_info;comment:Model Configuration Information;serializer:json" json:"model_info"` // Model Configuration Information
OnboardingInfo *bot_common.OnboardingInfo `gorm:"column:onboarding_info;comment:Onboarding Information;serializer:json" json:"onboarding_info"` // Onboarding Information
Prompt *bot_common.PromptInfo `gorm:"column:prompt;comment:Agent Prompt Configuration;serializer:json" json:"prompt"` // Agent Prompt Configuration
Plugin []*bot_common.PluginInfo `gorm:"column:plugin;comment:Agent Plugin Base Configuration;serializer:json" json:"plugin"` // Agent Plugin Base Configuration
Knowledge *bot_common.Knowledge `gorm:"column:knowledge;comment:Agent Knowledge Base Configuration;serializer:json" json:"knowledge"` // Agent Knowledge Base Configuration
Workflow []*bot_common.WorkflowInfo `gorm:"column:workflow;comment:Agent Workflow Configuration;serializer:json" json:"workflow"` // Agent Workflow Configuration
SuggestReply *bot_common.SuggestReplyInfo `gorm:"column:suggest_reply;comment:Suggested Replies;serializer:json" json:"suggest_reply"` // Suggested Replies
JumpConfig *bot_common.JumpConfig `gorm:"column:jump_config;comment:Jump Configuration;serializer:json" json:"jump_config"` // Jump Configuration
ConnectorID int64 `gorm:"column:connector_id;not null;comment:Connector ID" json:"connector_id"` // Connector ID
Version string `gorm:"column:version;not null;comment:Agent Version" json:"version"` // Agent Version
BackgroundImageInfoList []*bot_common.BackgroundImageInfo `gorm:"column:background_image_info_list;comment:Background image;serializer:json" json:"background_image_info_list"` // Background image
DatabaseConfig []*bot_common.Database `gorm:"column:database_config;comment:Agent Database Base Configuration;serializer:json" json:"database_config"` // Agent Database Base Configuration
ShortcutCommand []string `gorm:"column:shortcut_command;comment:shortcut command;serializer:json" json:"shortcut_command"` // shortcut command
}
// TableName SingleAgentVersion's table name
func (*SingleAgentVersion) TableName() string {
return TableNameSingleAgentVersion
}

View File

@@ -0,0 +1,119 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"database/sql"
"gorm.io/gorm"
"gorm.io/gen"
"gorm.io/plugin/dbresolver"
)
var (
Q = new(Query)
SingleAgentDraft *singleAgentDraft
SingleAgentPublish *singleAgentPublish
SingleAgentVersion *singleAgentVersion
)
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
*Q = *Use(db, opts...)
SingleAgentDraft = &Q.SingleAgentDraft
SingleAgentPublish = &Q.SingleAgentPublish
SingleAgentVersion = &Q.SingleAgentVersion
}
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
SingleAgentDraft: newSingleAgentDraft(db, opts...),
SingleAgentPublish: newSingleAgentPublish(db, opts...),
SingleAgentVersion: newSingleAgentVersion(db, opts...),
}
}
type Query struct {
db *gorm.DB
SingleAgentDraft singleAgentDraft
SingleAgentPublish singleAgentPublish
SingleAgentVersion singleAgentVersion
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
SingleAgentDraft: q.SingleAgentDraft.clone(db),
SingleAgentPublish: q.SingleAgentPublish.clone(db),
SingleAgentVersion: q.SingleAgentVersion.clone(db),
}
}
func (q *Query) ReadDB() *Query {
return q.ReplaceDB(q.db.Clauses(dbresolver.Read))
}
func (q *Query) WriteDB() *Query {
return q.ReplaceDB(q.db.Clauses(dbresolver.Write))
}
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
return &Query{
db: db,
SingleAgentDraft: q.SingleAgentDraft.replaceDB(db),
SingleAgentPublish: q.SingleAgentPublish.replaceDB(db),
SingleAgentVersion: q.SingleAgentVersion.replaceDB(db),
}
}
type queryCtx struct {
SingleAgentDraft ISingleAgentDraftDo
SingleAgentPublish ISingleAgentPublishDo
SingleAgentVersion ISingleAgentVersionDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
SingleAgentDraft: q.SingleAgentDraft.WithContext(ctx),
SingleAgentPublish: q.SingleAgentPublish.WithContext(ctx),
SingleAgentVersion: q.SingleAgentVersion.WithContext(ctx),
}
}
func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error {
return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...)
}
func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx {
tx := q.db.Begin(opts...)
return &QueryTx{Query: q.clone(tx), Error: tx.Error}
}
type QueryTx struct {
*Query
Error error
}
func (q *QueryTx) Commit() error {
return q.db.Commit().Error
}
func (q *QueryTx) Rollback() error {
return q.db.Rollback().Error
}
func (q *QueryTx) SavePoint(name string) error {
return q.db.SavePoint(name).Error
}
func (q *QueryTx) RollbackTo(name string) error {
return q.db.RollbackTo(name).Error
}

View File

@@ -0,0 +1,465 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/internal/dal/model"
)
func newSingleAgentDraft(db *gorm.DB, opts ...gen.DOOption) singleAgentDraft {
_singleAgentDraft := singleAgentDraft{}
_singleAgentDraft.singleAgentDraftDo.UseDB(db, opts...)
_singleAgentDraft.singleAgentDraftDo.UseModel(&model.SingleAgentDraft{})
tableName := _singleAgentDraft.singleAgentDraftDo.TableName()
_singleAgentDraft.ALL = field.NewAsterisk(tableName)
_singleAgentDraft.ID = field.NewInt64(tableName, "id")
_singleAgentDraft.AgentID = field.NewInt64(tableName, "agent_id")
_singleAgentDraft.CreatorID = field.NewInt64(tableName, "creator_id")
_singleAgentDraft.SpaceID = field.NewInt64(tableName, "space_id")
_singleAgentDraft.Name = field.NewString(tableName, "name")
_singleAgentDraft.Description = field.NewString(tableName, "description")
_singleAgentDraft.IconURI = field.NewString(tableName, "icon_uri")
_singleAgentDraft.CreatedAt = field.NewInt64(tableName, "created_at")
_singleAgentDraft.UpdatedAt = field.NewInt64(tableName, "updated_at")
_singleAgentDraft.DeletedAt = field.NewField(tableName, "deleted_at")
_singleAgentDraft.VariablesMetaID = field.NewInt64(tableName, "variables_meta_id")
_singleAgentDraft.ModelInfo = field.NewField(tableName, "model_info")
_singleAgentDraft.OnboardingInfo = field.NewField(tableName, "onboarding_info")
_singleAgentDraft.Prompt = field.NewField(tableName, "prompt")
_singleAgentDraft.Plugin = field.NewField(tableName, "plugin")
_singleAgentDraft.Knowledge = field.NewField(tableName, "knowledge")
_singleAgentDraft.Workflow = field.NewField(tableName, "workflow")
_singleAgentDraft.SuggestReply = field.NewField(tableName, "suggest_reply")
_singleAgentDraft.JumpConfig = field.NewField(tableName, "jump_config")
_singleAgentDraft.BackgroundImageInfoList = field.NewField(tableName, "background_image_info_list")
_singleAgentDraft.DatabaseConfig = field.NewField(tableName, "database_config")
_singleAgentDraft.ShortcutCommand = field.NewField(tableName, "shortcut_command")
_singleAgentDraft.fillFieldMap()
return _singleAgentDraft
}
// singleAgentDraft Single Agent Draft Copy Table
type singleAgentDraft struct {
singleAgentDraftDo
ALL field.Asterisk
ID field.Int64 // Primary Key ID
AgentID field.Int64 // Agent ID
CreatorID field.Int64 // Creator ID
SpaceID field.Int64 // Space ID
Name field.String // Agent Name
Description field.String // Agent Description
IconURI field.String // Icon URI
CreatedAt field.Int64 // Create Time in Milliseconds
UpdatedAt field.Int64 // Update Time in Milliseconds
DeletedAt field.Field // delete time in millisecond
VariablesMetaID field.Int64 // variables meta 表 ID
ModelInfo field.Field // Model Configuration Information
OnboardingInfo field.Field // Onboarding Information
Prompt field.Field // Agent Prompt Configuration
Plugin field.Field // Agent Plugin Base Configuration
Knowledge field.Field // Agent Knowledge Base Configuration
Workflow field.Field // Agent Workflow Configuration
SuggestReply field.Field // Suggested Replies
JumpConfig field.Field // Jump Configuration
BackgroundImageInfoList field.Field // Background image
DatabaseConfig field.Field // Agent Database Base Configuration
ShortcutCommand field.Field // shortcut command
fieldMap map[string]field.Expr
}
func (s singleAgentDraft) Table(newTableName string) *singleAgentDraft {
s.singleAgentDraftDo.UseTable(newTableName)
return s.updateTableName(newTableName)
}
func (s singleAgentDraft) As(alias string) *singleAgentDraft {
s.singleAgentDraftDo.DO = *(s.singleAgentDraftDo.As(alias).(*gen.DO))
return s.updateTableName(alias)
}
func (s *singleAgentDraft) updateTableName(table string) *singleAgentDraft {
s.ALL = field.NewAsterisk(table)
s.ID = field.NewInt64(table, "id")
s.AgentID = field.NewInt64(table, "agent_id")
s.CreatorID = field.NewInt64(table, "creator_id")
s.SpaceID = field.NewInt64(table, "space_id")
s.Name = field.NewString(table, "name")
s.Description = field.NewString(table, "description")
s.IconURI = field.NewString(table, "icon_uri")
s.CreatedAt = field.NewInt64(table, "created_at")
s.UpdatedAt = field.NewInt64(table, "updated_at")
s.DeletedAt = field.NewField(table, "deleted_at")
s.VariablesMetaID = field.NewInt64(table, "variables_meta_id")
s.ModelInfo = field.NewField(table, "model_info")
s.OnboardingInfo = field.NewField(table, "onboarding_info")
s.Prompt = field.NewField(table, "prompt")
s.Plugin = field.NewField(table, "plugin")
s.Knowledge = field.NewField(table, "knowledge")
s.Workflow = field.NewField(table, "workflow")
s.SuggestReply = field.NewField(table, "suggest_reply")
s.JumpConfig = field.NewField(table, "jump_config")
s.BackgroundImageInfoList = field.NewField(table, "background_image_info_list")
s.DatabaseConfig = field.NewField(table, "database_config")
s.ShortcutCommand = field.NewField(table, "shortcut_command")
s.fillFieldMap()
return s
}
func (s *singleAgentDraft) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := s.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (s *singleAgentDraft) fillFieldMap() {
s.fieldMap = make(map[string]field.Expr, 22)
s.fieldMap["id"] = s.ID
s.fieldMap["agent_id"] = s.AgentID
s.fieldMap["creator_id"] = s.CreatorID
s.fieldMap["space_id"] = s.SpaceID
s.fieldMap["name"] = s.Name
s.fieldMap["description"] = s.Description
s.fieldMap["icon_uri"] = s.IconURI
s.fieldMap["created_at"] = s.CreatedAt
s.fieldMap["updated_at"] = s.UpdatedAt
s.fieldMap["deleted_at"] = s.DeletedAt
s.fieldMap["variables_meta_id"] = s.VariablesMetaID
s.fieldMap["model_info"] = s.ModelInfo
s.fieldMap["onboarding_info"] = s.OnboardingInfo
s.fieldMap["prompt"] = s.Prompt
s.fieldMap["plugin"] = s.Plugin
s.fieldMap["knowledge"] = s.Knowledge
s.fieldMap["workflow"] = s.Workflow
s.fieldMap["suggest_reply"] = s.SuggestReply
s.fieldMap["jump_config"] = s.JumpConfig
s.fieldMap["background_image_info_list"] = s.BackgroundImageInfoList
s.fieldMap["database_config"] = s.DatabaseConfig
s.fieldMap["shortcut_command"] = s.ShortcutCommand
}
func (s singleAgentDraft) clone(db *gorm.DB) singleAgentDraft {
s.singleAgentDraftDo.ReplaceConnPool(db.Statement.ConnPool)
return s
}
func (s singleAgentDraft) replaceDB(db *gorm.DB) singleAgentDraft {
s.singleAgentDraftDo.ReplaceDB(db)
return s
}
type singleAgentDraftDo struct{ gen.DO }
type ISingleAgentDraftDo interface {
gen.SubQuery
Debug() ISingleAgentDraftDo
WithContext(ctx context.Context) ISingleAgentDraftDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() ISingleAgentDraftDo
WriteDB() ISingleAgentDraftDo
As(alias string) gen.Dao
Session(config *gorm.Session) ISingleAgentDraftDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) ISingleAgentDraftDo
Not(conds ...gen.Condition) ISingleAgentDraftDo
Or(conds ...gen.Condition) ISingleAgentDraftDo
Select(conds ...field.Expr) ISingleAgentDraftDo
Where(conds ...gen.Condition) ISingleAgentDraftDo
Order(conds ...field.Expr) ISingleAgentDraftDo
Distinct(cols ...field.Expr) ISingleAgentDraftDo
Omit(cols ...field.Expr) ISingleAgentDraftDo
Join(table schema.Tabler, on ...field.Expr) ISingleAgentDraftDo
LeftJoin(table schema.Tabler, on ...field.Expr) ISingleAgentDraftDo
RightJoin(table schema.Tabler, on ...field.Expr) ISingleAgentDraftDo
Group(cols ...field.Expr) ISingleAgentDraftDo
Having(conds ...gen.Condition) ISingleAgentDraftDo
Limit(limit int) ISingleAgentDraftDo
Offset(offset int) ISingleAgentDraftDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) ISingleAgentDraftDo
Unscoped() ISingleAgentDraftDo
Create(values ...*model.SingleAgentDraft) error
CreateInBatches(values []*model.SingleAgentDraft, batchSize int) error
Save(values ...*model.SingleAgentDraft) error
First() (*model.SingleAgentDraft, error)
Take() (*model.SingleAgentDraft, error)
Last() (*model.SingleAgentDraft, error)
Find() ([]*model.SingleAgentDraft, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.SingleAgentDraft, err error)
FindInBatches(result *[]*model.SingleAgentDraft, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*model.SingleAgentDraft) (info gen.ResultInfo, err error)
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
Updates(value interface{}) (info gen.ResultInfo, err error)
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
UpdateFrom(q gen.SubQuery) gen.Dao
Attrs(attrs ...field.AssignExpr) ISingleAgentDraftDo
Assign(attrs ...field.AssignExpr) ISingleAgentDraftDo
Joins(fields ...field.RelationField) ISingleAgentDraftDo
Preload(fields ...field.RelationField) ISingleAgentDraftDo
FirstOrInit() (*model.SingleAgentDraft, error)
FirstOrCreate() (*model.SingleAgentDraft, error)
FindByPage(offset int, limit int) (result []*model.SingleAgentDraft, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) ISingleAgentDraftDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (s singleAgentDraftDo) Debug() ISingleAgentDraftDo {
return s.withDO(s.DO.Debug())
}
func (s singleAgentDraftDo) WithContext(ctx context.Context) ISingleAgentDraftDo {
return s.withDO(s.DO.WithContext(ctx))
}
func (s singleAgentDraftDo) ReadDB() ISingleAgentDraftDo {
return s.Clauses(dbresolver.Read)
}
func (s singleAgentDraftDo) WriteDB() ISingleAgentDraftDo {
return s.Clauses(dbresolver.Write)
}
func (s singleAgentDraftDo) Session(config *gorm.Session) ISingleAgentDraftDo {
return s.withDO(s.DO.Session(config))
}
func (s singleAgentDraftDo) Clauses(conds ...clause.Expression) ISingleAgentDraftDo {
return s.withDO(s.DO.Clauses(conds...))
}
func (s singleAgentDraftDo) Returning(value interface{}, columns ...string) ISingleAgentDraftDo {
return s.withDO(s.DO.Returning(value, columns...))
}
func (s singleAgentDraftDo) Not(conds ...gen.Condition) ISingleAgentDraftDo {
return s.withDO(s.DO.Not(conds...))
}
func (s singleAgentDraftDo) Or(conds ...gen.Condition) ISingleAgentDraftDo {
return s.withDO(s.DO.Or(conds...))
}
func (s singleAgentDraftDo) Select(conds ...field.Expr) ISingleAgentDraftDo {
return s.withDO(s.DO.Select(conds...))
}
func (s singleAgentDraftDo) Where(conds ...gen.Condition) ISingleAgentDraftDo {
return s.withDO(s.DO.Where(conds...))
}
func (s singleAgentDraftDo) Order(conds ...field.Expr) ISingleAgentDraftDo {
return s.withDO(s.DO.Order(conds...))
}
func (s singleAgentDraftDo) Distinct(cols ...field.Expr) ISingleAgentDraftDo {
return s.withDO(s.DO.Distinct(cols...))
}
func (s singleAgentDraftDo) Omit(cols ...field.Expr) ISingleAgentDraftDo {
return s.withDO(s.DO.Omit(cols...))
}
func (s singleAgentDraftDo) Join(table schema.Tabler, on ...field.Expr) ISingleAgentDraftDo {
return s.withDO(s.DO.Join(table, on...))
}
func (s singleAgentDraftDo) LeftJoin(table schema.Tabler, on ...field.Expr) ISingleAgentDraftDo {
return s.withDO(s.DO.LeftJoin(table, on...))
}
func (s singleAgentDraftDo) RightJoin(table schema.Tabler, on ...field.Expr) ISingleAgentDraftDo {
return s.withDO(s.DO.RightJoin(table, on...))
}
func (s singleAgentDraftDo) Group(cols ...field.Expr) ISingleAgentDraftDo {
return s.withDO(s.DO.Group(cols...))
}
func (s singleAgentDraftDo) Having(conds ...gen.Condition) ISingleAgentDraftDo {
return s.withDO(s.DO.Having(conds...))
}
func (s singleAgentDraftDo) Limit(limit int) ISingleAgentDraftDo {
return s.withDO(s.DO.Limit(limit))
}
func (s singleAgentDraftDo) Offset(offset int) ISingleAgentDraftDo {
return s.withDO(s.DO.Offset(offset))
}
func (s singleAgentDraftDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ISingleAgentDraftDo {
return s.withDO(s.DO.Scopes(funcs...))
}
func (s singleAgentDraftDo) Unscoped() ISingleAgentDraftDo {
return s.withDO(s.DO.Unscoped())
}
func (s singleAgentDraftDo) Create(values ...*model.SingleAgentDraft) error {
if len(values) == 0 {
return nil
}
return s.DO.Create(values)
}
func (s singleAgentDraftDo) CreateInBatches(values []*model.SingleAgentDraft, batchSize int) error {
return s.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (s singleAgentDraftDo) Save(values ...*model.SingleAgentDraft) error {
if len(values) == 0 {
return nil
}
return s.DO.Save(values)
}
func (s singleAgentDraftDo) First() (*model.SingleAgentDraft, error) {
if result, err := s.DO.First(); err != nil {
return nil, err
} else {
return result.(*model.SingleAgentDraft), nil
}
}
func (s singleAgentDraftDo) Take() (*model.SingleAgentDraft, error) {
if result, err := s.DO.Take(); err != nil {
return nil, err
} else {
return result.(*model.SingleAgentDraft), nil
}
}
func (s singleAgentDraftDo) Last() (*model.SingleAgentDraft, error) {
if result, err := s.DO.Last(); err != nil {
return nil, err
} else {
return result.(*model.SingleAgentDraft), nil
}
}
func (s singleAgentDraftDo) Find() ([]*model.SingleAgentDraft, error) {
result, err := s.DO.Find()
return result.([]*model.SingleAgentDraft), err
}
func (s singleAgentDraftDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.SingleAgentDraft, err error) {
buf := make([]*model.SingleAgentDraft, 0, batchSize)
err = s.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
})
return results, err
}
func (s singleAgentDraftDo) FindInBatches(result *[]*model.SingleAgentDraft, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return s.DO.FindInBatches(result, batchSize, fc)
}
func (s singleAgentDraftDo) Attrs(attrs ...field.AssignExpr) ISingleAgentDraftDo {
return s.withDO(s.DO.Attrs(attrs...))
}
func (s singleAgentDraftDo) Assign(attrs ...field.AssignExpr) ISingleAgentDraftDo {
return s.withDO(s.DO.Assign(attrs...))
}
func (s singleAgentDraftDo) Joins(fields ...field.RelationField) ISingleAgentDraftDo {
for _, _f := range fields {
s = *s.withDO(s.DO.Joins(_f))
}
return &s
}
func (s singleAgentDraftDo) Preload(fields ...field.RelationField) ISingleAgentDraftDo {
for _, _f := range fields {
s = *s.withDO(s.DO.Preload(_f))
}
return &s
}
func (s singleAgentDraftDo) FirstOrInit() (*model.SingleAgentDraft, error) {
if result, err := s.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*model.SingleAgentDraft), nil
}
}
func (s singleAgentDraftDo) FirstOrCreate() (*model.SingleAgentDraft, error) {
if result, err := s.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*model.SingleAgentDraft), nil
}
}
func (s singleAgentDraftDo) FindByPage(offset int, limit int) (result []*model.SingleAgentDraft, count int64, err error) {
result, err = s.Offset(offset).Limit(limit).Find()
if err != nil {
return
}
if size := len(result); 0 < limit && 0 < size && size < limit {
count = int64(size + offset)
return
}
count, err = s.Offset(-1).Limit(-1).Count()
return
}
func (s singleAgentDraftDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = s.Count()
if err != nil {
return
}
err = s.Offset(offset).Limit(limit).Scan(result)
return
}
func (s singleAgentDraftDo) Scan(result interface{}) (err error) {
return s.DO.Scan(result)
}
func (s singleAgentDraftDo) Delete(models ...*model.SingleAgentDraft) (result gen.ResultInfo, err error) {
return s.DO.Delete(models)
}
func (s *singleAgentDraftDo) withDO(do gen.Dao) *singleAgentDraftDo {
s.DO = *do.(*gen.DO)
return s
}

View File

@@ -0,0 +1,425 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/internal/dal/model"
)
func newSingleAgentPublish(db *gorm.DB, opts ...gen.DOOption) singleAgentPublish {
_singleAgentPublish := singleAgentPublish{}
_singleAgentPublish.singleAgentPublishDo.UseDB(db, opts...)
_singleAgentPublish.singleAgentPublishDo.UseModel(&model.SingleAgentPublish{})
tableName := _singleAgentPublish.singleAgentPublishDo.TableName()
_singleAgentPublish.ALL = field.NewAsterisk(tableName)
_singleAgentPublish.ID = field.NewInt64(tableName, "id")
_singleAgentPublish.AgentID = field.NewInt64(tableName, "agent_id")
_singleAgentPublish.PublishID = field.NewString(tableName, "publish_id")
_singleAgentPublish.ConnectorIds = field.NewField(tableName, "connector_ids")
_singleAgentPublish.Version = field.NewString(tableName, "version")
_singleAgentPublish.PublishInfo = field.NewString(tableName, "publish_info")
_singleAgentPublish.PublishTime = field.NewInt64(tableName, "publish_time")
_singleAgentPublish.CreatedAt = field.NewInt64(tableName, "created_at")
_singleAgentPublish.UpdatedAt = field.NewInt64(tableName, "updated_at")
_singleAgentPublish.CreatorID = field.NewInt64(tableName, "creator_id")
_singleAgentPublish.Status = field.NewInt32(tableName, "status")
_singleAgentPublish.Extra = field.NewString(tableName, "extra")
_singleAgentPublish.fillFieldMap()
return _singleAgentPublish
}
// singleAgentPublish bot 渠道和发布版本流水表
type singleAgentPublish struct {
singleAgentPublishDo
ALL field.Asterisk
ID field.Int64 // 主键id
AgentID field.Int64 // agent_id
PublishID field.String // 发布 id
ConnectorIds field.Field // 发布的 connector_ids
Version field.String // Agent Version
PublishInfo field.String // 发布信息
PublishTime field.Int64 // 发布时间
CreatedAt field.Int64 // Create Time in Milliseconds
UpdatedAt field.Int64 // Update Time in Milliseconds
CreatorID field.Int64 // 发布人 user_id
Status field.Int32 // 状态 0:使用中 1:删除 3:禁用
Extra field.String // 扩展字段
fieldMap map[string]field.Expr
}
func (s singleAgentPublish) Table(newTableName string) *singleAgentPublish {
s.singleAgentPublishDo.UseTable(newTableName)
return s.updateTableName(newTableName)
}
func (s singleAgentPublish) As(alias string) *singleAgentPublish {
s.singleAgentPublishDo.DO = *(s.singleAgentPublishDo.As(alias).(*gen.DO))
return s.updateTableName(alias)
}
func (s *singleAgentPublish) updateTableName(table string) *singleAgentPublish {
s.ALL = field.NewAsterisk(table)
s.ID = field.NewInt64(table, "id")
s.AgentID = field.NewInt64(table, "agent_id")
s.PublishID = field.NewString(table, "publish_id")
s.ConnectorIds = field.NewField(table, "connector_ids")
s.Version = field.NewString(table, "version")
s.PublishInfo = field.NewString(table, "publish_info")
s.PublishTime = field.NewInt64(table, "publish_time")
s.CreatedAt = field.NewInt64(table, "created_at")
s.UpdatedAt = field.NewInt64(table, "updated_at")
s.CreatorID = field.NewInt64(table, "creator_id")
s.Status = field.NewInt32(table, "status")
s.Extra = field.NewString(table, "extra")
s.fillFieldMap()
return s
}
func (s *singleAgentPublish) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := s.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (s *singleAgentPublish) fillFieldMap() {
s.fieldMap = make(map[string]field.Expr, 12)
s.fieldMap["id"] = s.ID
s.fieldMap["agent_id"] = s.AgentID
s.fieldMap["publish_id"] = s.PublishID
s.fieldMap["connector_ids"] = s.ConnectorIds
s.fieldMap["version"] = s.Version
s.fieldMap["publish_info"] = s.PublishInfo
s.fieldMap["publish_time"] = s.PublishTime
s.fieldMap["created_at"] = s.CreatedAt
s.fieldMap["updated_at"] = s.UpdatedAt
s.fieldMap["creator_id"] = s.CreatorID
s.fieldMap["status"] = s.Status
s.fieldMap["extra"] = s.Extra
}
func (s singleAgentPublish) clone(db *gorm.DB) singleAgentPublish {
s.singleAgentPublishDo.ReplaceConnPool(db.Statement.ConnPool)
return s
}
func (s singleAgentPublish) replaceDB(db *gorm.DB) singleAgentPublish {
s.singleAgentPublishDo.ReplaceDB(db)
return s
}
type singleAgentPublishDo struct{ gen.DO }
type ISingleAgentPublishDo interface {
gen.SubQuery
Debug() ISingleAgentPublishDo
WithContext(ctx context.Context) ISingleAgentPublishDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() ISingleAgentPublishDo
WriteDB() ISingleAgentPublishDo
As(alias string) gen.Dao
Session(config *gorm.Session) ISingleAgentPublishDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) ISingleAgentPublishDo
Not(conds ...gen.Condition) ISingleAgentPublishDo
Or(conds ...gen.Condition) ISingleAgentPublishDo
Select(conds ...field.Expr) ISingleAgentPublishDo
Where(conds ...gen.Condition) ISingleAgentPublishDo
Order(conds ...field.Expr) ISingleAgentPublishDo
Distinct(cols ...field.Expr) ISingleAgentPublishDo
Omit(cols ...field.Expr) ISingleAgentPublishDo
Join(table schema.Tabler, on ...field.Expr) ISingleAgentPublishDo
LeftJoin(table schema.Tabler, on ...field.Expr) ISingleAgentPublishDo
RightJoin(table schema.Tabler, on ...field.Expr) ISingleAgentPublishDo
Group(cols ...field.Expr) ISingleAgentPublishDo
Having(conds ...gen.Condition) ISingleAgentPublishDo
Limit(limit int) ISingleAgentPublishDo
Offset(offset int) ISingleAgentPublishDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) ISingleAgentPublishDo
Unscoped() ISingleAgentPublishDo
Create(values ...*model.SingleAgentPublish) error
CreateInBatches(values []*model.SingleAgentPublish, batchSize int) error
Save(values ...*model.SingleAgentPublish) error
First() (*model.SingleAgentPublish, error)
Take() (*model.SingleAgentPublish, error)
Last() (*model.SingleAgentPublish, error)
Find() ([]*model.SingleAgentPublish, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.SingleAgentPublish, err error)
FindInBatches(result *[]*model.SingleAgentPublish, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*model.SingleAgentPublish) (info gen.ResultInfo, err error)
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
Updates(value interface{}) (info gen.ResultInfo, err error)
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
UpdateFrom(q gen.SubQuery) gen.Dao
Attrs(attrs ...field.AssignExpr) ISingleAgentPublishDo
Assign(attrs ...field.AssignExpr) ISingleAgentPublishDo
Joins(fields ...field.RelationField) ISingleAgentPublishDo
Preload(fields ...field.RelationField) ISingleAgentPublishDo
FirstOrInit() (*model.SingleAgentPublish, error)
FirstOrCreate() (*model.SingleAgentPublish, error)
FindByPage(offset int, limit int) (result []*model.SingleAgentPublish, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) ISingleAgentPublishDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (s singleAgentPublishDo) Debug() ISingleAgentPublishDo {
return s.withDO(s.DO.Debug())
}
func (s singleAgentPublishDo) WithContext(ctx context.Context) ISingleAgentPublishDo {
return s.withDO(s.DO.WithContext(ctx))
}
func (s singleAgentPublishDo) ReadDB() ISingleAgentPublishDo {
return s.Clauses(dbresolver.Read)
}
func (s singleAgentPublishDo) WriteDB() ISingleAgentPublishDo {
return s.Clauses(dbresolver.Write)
}
func (s singleAgentPublishDo) Session(config *gorm.Session) ISingleAgentPublishDo {
return s.withDO(s.DO.Session(config))
}
func (s singleAgentPublishDo) Clauses(conds ...clause.Expression) ISingleAgentPublishDo {
return s.withDO(s.DO.Clauses(conds...))
}
func (s singleAgentPublishDo) Returning(value interface{}, columns ...string) ISingleAgentPublishDo {
return s.withDO(s.DO.Returning(value, columns...))
}
func (s singleAgentPublishDo) Not(conds ...gen.Condition) ISingleAgentPublishDo {
return s.withDO(s.DO.Not(conds...))
}
func (s singleAgentPublishDo) Or(conds ...gen.Condition) ISingleAgentPublishDo {
return s.withDO(s.DO.Or(conds...))
}
func (s singleAgentPublishDo) Select(conds ...field.Expr) ISingleAgentPublishDo {
return s.withDO(s.DO.Select(conds...))
}
func (s singleAgentPublishDo) Where(conds ...gen.Condition) ISingleAgentPublishDo {
return s.withDO(s.DO.Where(conds...))
}
func (s singleAgentPublishDo) Order(conds ...field.Expr) ISingleAgentPublishDo {
return s.withDO(s.DO.Order(conds...))
}
func (s singleAgentPublishDo) Distinct(cols ...field.Expr) ISingleAgentPublishDo {
return s.withDO(s.DO.Distinct(cols...))
}
func (s singleAgentPublishDo) Omit(cols ...field.Expr) ISingleAgentPublishDo {
return s.withDO(s.DO.Omit(cols...))
}
func (s singleAgentPublishDo) Join(table schema.Tabler, on ...field.Expr) ISingleAgentPublishDo {
return s.withDO(s.DO.Join(table, on...))
}
func (s singleAgentPublishDo) LeftJoin(table schema.Tabler, on ...field.Expr) ISingleAgentPublishDo {
return s.withDO(s.DO.LeftJoin(table, on...))
}
func (s singleAgentPublishDo) RightJoin(table schema.Tabler, on ...field.Expr) ISingleAgentPublishDo {
return s.withDO(s.DO.RightJoin(table, on...))
}
func (s singleAgentPublishDo) Group(cols ...field.Expr) ISingleAgentPublishDo {
return s.withDO(s.DO.Group(cols...))
}
func (s singleAgentPublishDo) Having(conds ...gen.Condition) ISingleAgentPublishDo {
return s.withDO(s.DO.Having(conds...))
}
func (s singleAgentPublishDo) Limit(limit int) ISingleAgentPublishDo {
return s.withDO(s.DO.Limit(limit))
}
func (s singleAgentPublishDo) Offset(offset int) ISingleAgentPublishDo {
return s.withDO(s.DO.Offset(offset))
}
func (s singleAgentPublishDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ISingleAgentPublishDo {
return s.withDO(s.DO.Scopes(funcs...))
}
func (s singleAgentPublishDo) Unscoped() ISingleAgentPublishDo {
return s.withDO(s.DO.Unscoped())
}
func (s singleAgentPublishDo) Create(values ...*model.SingleAgentPublish) error {
if len(values) == 0 {
return nil
}
return s.DO.Create(values)
}
func (s singleAgentPublishDo) CreateInBatches(values []*model.SingleAgentPublish, batchSize int) error {
return s.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (s singleAgentPublishDo) Save(values ...*model.SingleAgentPublish) error {
if len(values) == 0 {
return nil
}
return s.DO.Save(values)
}
func (s singleAgentPublishDo) First() (*model.SingleAgentPublish, error) {
if result, err := s.DO.First(); err != nil {
return nil, err
} else {
return result.(*model.SingleAgentPublish), nil
}
}
func (s singleAgentPublishDo) Take() (*model.SingleAgentPublish, error) {
if result, err := s.DO.Take(); err != nil {
return nil, err
} else {
return result.(*model.SingleAgentPublish), nil
}
}
func (s singleAgentPublishDo) Last() (*model.SingleAgentPublish, error) {
if result, err := s.DO.Last(); err != nil {
return nil, err
} else {
return result.(*model.SingleAgentPublish), nil
}
}
func (s singleAgentPublishDo) Find() ([]*model.SingleAgentPublish, error) {
result, err := s.DO.Find()
return result.([]*model.SingleAgentPublish), err
}
func (s singleAgentPublishDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.SingleAgentPublish, err error) {
buf := make([]*model.SingleAgentPublish, 0, batchSize)
err = s.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
})
return results, err
}
func (s singleAgentPublishDo) FindInBatches(result *[]*model.SingleAgentPublish, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return s.DO.FindInBatches(result, batchSize, fc)
}
func (s singleAgentPublishDo) Attrs(attrs ...field.AssignExpr) ISingleAgentPublishDo {
return s.withDO(s.DO.Attrs(attrs...))
}
func (s singleAgentPublishDo) Assign(attrs ...field.AssignExpr) ISingleAgentPublishDo {
return s.withDO(s.DO.Assign(attrs...))
}
func (s singleAgentPublishDo) Joins(fields ...field.RelationField) ISingleAgentPublishDo {
for _, _f := range fields {
s = *s.withDO(s.DO.Joins(_f))
}
return &s
}
func (s singleAgentPublishDo) Preload(fields ...field.RelationField) ISingleAgentPublishDo {
for _, _f := range fields {
s = *s.withDO(s.DO.Preload(_f))
}
return &s
}
func (s singleAgentPublishDo) FirstOrInit() (*model.SingleAgentPublish, error) {
if result, err := s.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*model.SingleAgentPublish), nil
}
}
func (s singleAgentPublishDo) FirstOrCreate() (*model.SingleAgentPublish, error) {
if result, err := s.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*model.SingleAgentPublish), nil
}
}
func (s singleAgentPublishDo) FindByPage(offset int, limit int) (result []*model.SingleAgentPublish, count int64, err error) {
result, err = s.Offset(offset).Limit(limit).Find()
if err != nil {
return
}
if size := len(result); 0 < limit && 0 < size && size < limit {
count = int64(size + offset)
return
}
count, err = s.Offset(-1).Limit(-1).Count()
return
}
func (s singleAgentPublishDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = s.Count()
if err != nil {
return
}
err = s.Offset(offset).Limit(limit).Scan(result)
return
}
func (s singleAgentPublishDo) Scan(result interface{}) (err error) {
return s.DO.Scan(result)
}
func (s singleAgentPublishDo) Delete(models ...*model.SingleAgentPublish) (result gen.ResultInfo, err error) {
return s.DO.Delete(models)
}
func (s *singleAgentPublishDo) withDO(do gen.Dao) *singleAgentPublishDo {
s.DO = *do.(*gen.DO)
return s
}

View File

@@ -0,0 +1,473 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/internal/dal/model"
)
func newSingleAgentVersion(db *gorm.DB, opts ...gen.DOOption) singleAgentVersion {
_singleAgentVersion := singleAgentVersion{}
_singleAgentVersion.singleAgentVersionDo.UseDB(db, opts...)
_singleAgentVersion.singleAgentVersionDo.UseModel(&model.SingleAgentVersion{})
tableName := _singleAgentVersion.singleAgentVersionDo.TableName()
_singleAgentVersion.ALL = field.NewAsterisk(tableName)
_singleAgentVersion.ID = field.NewInt64(tableName, "id")
_singleAgentVersion.AgentID = field.NewInt64(tableName, "agent_id")
_singleAgentVersion.CreatorID = field.NewInt64(tableName, "creator_id")
_singleAgentVersion.SpaceID = field.NewInt64(tableName, "space_id")
_singleAgentVersion.Name = field.NewString(tableName, "name")
_singleAgentVersion.Description = field.NewString(tableName, "description")
_singleAgentVersion.IconURI = field.NewString(tableName, "icon_uri")
_singleAgentVersion.CreatedAt = field.NewInt64(tableName, "created_at")
_singleAgentVersion.UpdatedAt = field.NewInt64(tableName, "updated_at")
_singleAgentVersion.DeletedAt = field.NewField(tableName, "deleted_at")
_singleAgentVersion.VariablesMetaID = field.NewInt64(tableName, "variables_meta_id")
_singleAgentVersion.ModelInfo = field.NewField(tableName, "model_info")
_singleAgentVersion.OnboardingInfo = field.NewField(tableName, "onboarding_info")
_singleAgentVersion.Prompt = field.NewField(tableName, "prompt")
_singleAgentVersion.Plugin = field.NewField(tableName, "plugin")
_singleAgentVersion.Knowledge = field.NewField(tableName, "knowledge")
_singleAgentVersion.Workflow = field.NewField(tableName, "workflow")
_singleAgentVersion.SuggestReply = field.NewField(tableName, "suggest_reply")
_singleAgentVersion.JumpConfig = field.NewField(tableName, "jump_config")
_singleAgentVersion.ConnectorID = field.NewInt64(tableName, "connector_id")
_singleAgentVersion.Version = field.NewString(tableName, "version")
_singleAgentVersion.BackgroundImageInfoList = field.NewField(tableName, "background_image_info_list")
_singleAgentVersion.DatabaseConfig = field.NewField(tableName, "database_config")
_singleAgentVersion.ShortcutCommand = field.NewField(tableName, "shortcut_command")
_singleAgentVersion.fillFieldMap()
return _singleAgentVersion
}
// singleAgentVersion Single Agent Version Copy Table
type singleAgentVersion struct {
singleAgentVersionDo
ALL field.Asterisk
ID field.Int64 // Primary Key ID
AgentID field.Int64 // Agent ID
CreatorID field.Int64 // Creator ID
SpaceID field.Int64 // Space ID
Name field.String // Agent Name
Description field.String // Agent Description
IconURI field.String // Icon URI
CreatedAt field.Int64 // Create Time in Milliseconds
UpdatedAt field.Int64 // Update Time in Milliseconds
DeletedAt field.Field // delete time in millisecond
VariablesMetaID field.Int64 // variables meta 表 ID
ModelInfo field.Field // Model Configuration Information
OnboardingInfo field.Field // Onboarding Information
Prompt field.Field // Agent Prompt Configuration
Plugin field.Field // Agent Plugin Base Configuration
Knowledge field.Field // Agent Knowledge Base Configuration
Workflow field.Field // Agent Workflow Configuration
SuggestReply field.Field // Suggested Replies
JumpConfig field.Field // Jump Configuration
ConnectorID field.Int64 // Connector ID
Version field.String // Agent Version
BackgroundImageInfoList field.Field // Background image
DatabaseConfig field.Field // Agent Database Base Configuration
ShortcutCommand field.Field // shortcut command
fieldMap map[string]field.Expr
}
func (s singleAgentVersion) Table(newTableName string) *singleAgentVersion {
s.singleAgentVersionDo.UseTable(newTableName)
return s.updateTableName(newTableName)
}
func (s singleAgentVersion) As(alias string) *singleAgentVersion {
s.singleAgentVersionDo.DO = *(s.singleAgentVersionDo.As(alias).(*gen.DO))
return s.updateTableName(alias)
}
func (s *singleAgentVersion) updateTableName(table string) *singleAgentVersion {
s.ALL = field.NewAsterisk(table)
s.ID = field.NewInt64(table, "id")
s.AgentID = field.NewInt64(table, "agent_id")
s.CreatorID = field.NewInt64(table, "creator_id")
s.SpaceID = field.NewInt64(table, "space_id")
s.Name = field.NewString(table, "name")
s.Description = field.NewString(table, "description")
s.IconURI = field.NewString(table, "icon_uri")
s.CreatedAt = field.NewInt64(table, "created_at")
s.UpdatedAt = field.NewInt64(table, "updated_at")
s.DeletedAt = field.NewField(table, "deleted_at")
s.VariablesMetaID = field.NewInt64(table, "variables_meta_id")
s.ModelInfo = field.NewField(table, "model_info")
s.OnboardingInfo = field.NewField(table, "onboarding_info")
s.Prompt = field.NewField(table, "prompt")
s.Plugin = field.NewField(table, "plugin")
s.Knowledge = field.NewField(table, "knowledge")
s.Workflow = field.NewField(table, "workflow")
s.SuggestReply = field.NewField(table, "suggest_reply")
s.JumpConfig = field.NewField(table, "jump_config")
s.ConnectorID = field.NewInt64(table, "connector_id")
s.Version = field.NewString(table, "version")
s.BackgroundImageInfoList = field.NewField(table, "background_image_info_list")
s.DatabaseConfig = field.NewField(table, "database_config")
s.ShortcutCommand = field.NewField(table, "shortcut_command")
s.fillFieldMap()
return s
}
func (s *singleAgentVersion) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := s.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (s *singleAgentVersion) fillFieldMap() {
s.fieldMap = make(map[string]field.Expr, 24)
s.fieldMap["id"] = s.ID
s.fieldMap["agent_id"] = s.AgentID
s.fieldMap["creator_id"] = s.CreatorID
s.fieldMap["space_id"] = s.SpaceID
s.fieldMap["name"] = s.Name
s.fieldMap["description"] = s.Description
s.fieldMap["icon_uri"] = s.IconURI
s.fieldMap["created_at"] = s.CreatedAt
s.fieldMap["updated_at"] = s.UpdatedAt
s.fieldMap["deleted_at"] = s.DeletedAt
s.fieldMap["variables_meta_id"] = s.VariablesMetaID
s.fieldMap["model_info"] = s.ModelInfo
s.fieldMap["onboarding_info"] = s.OnboardingInfo
s.fieldMap["prompt"] = s.Prompt
s.fieldMap["plugin"] = s.Plugin
s.fieldMap["knowledge"] = s.Knowledge
s.fieldMap["workflow"] = s.Workflow
s.fieldMap["suggest_reply"] = s.SuggestReply
s.fieldMap["jump_config"] = s.JumpConfig
s.fieldMap["connector_id"] = s.ConnectorID
s.fieldMap["version"] = s.Version
s.fieldMap["background_image_info_list"] = s.BackgroundImageInfoList
s.fieldMap["database_config"] = s.DatabaseConfig
s.fieldMap["shortcut_command"] = s.ShortcutCommand
}
func (s singleAgentVersion) clone(db *gorm.DB) singleAgentVersion {
s.singleAgentVersionDo.ReplaceConnPool(db.Statement.ConnPool)
return s
}
func (s singleAgentVersion) replaceDB(db *gorm.DB) singleAgentVersion {
s.singleAgentVersionDo.ReplaceDB(db)
return s
}
type singleAgentVersionDo struct{ gen.DO }
type ISingleAgentVersionDo interface {
gen.SubQuery
Debug() ISingleAgentVersionDo
WithContext(ctx context.Context) ISingleAgentVersionDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() ISingleAgentVersionDo
WriteDB() ISingleAgentVersionDo
As(alias string) gen.Dao
Session(config *gorm.Session) ISingleAgentVersionDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) ISingleAgentVersionDo
Not(conds ...gen.Condition) ISingleAgentVersionDo
Or(conds ...gen.Condition) ISingleAgentVersionDo
Select(conds ...field.Expr) ISingleAgentVersionDo
Where(conds ...gen.Condition) ISingleAgentVersionDo
Order(conds ...field.Expr) ISingleAgentVersionDo
Distinct(cols ...field.Expr) ISingleAgentVersionDo
Omit(cols ...field.Expr) ISingleAgentVersionDo
Join(table schema.Tabler, on ...field.Expr) ISingleAgentVersionDo
LeftJoin(table schema.Tabler, on ...field.Expr) ISingleAgentVersionDo
RightJoin(table schema.Tabler, on ...field.Expr) ISingleAgentVersionDo
Group(cols ...field.Expr) ISingleAgentVersionDo
Having(conds ...gen.Condition) ISingleAgentVersionDo
Limit(limit int) ISingleAgentVersionDo
Offset(offset int) ISingleAgentVersionDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) ISingleAgentVersionDo
Unscoped() ISingleAgentVersionDo
Create(values ...*model.SingleAgentVersion) error
CreateInBatches(values []*model.SingleAgentVersion, batchSize int) error
Save(values ...*model.SingleAgentVersion) error
First() (*model.SingleAgentVersion, error)
Take() (*model.SingleAgentVersion, error)
Last() (*model.SingleAgentVersion, error)
Find() ([]*model.SingleAgentVersion, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.SingleAgentVersion, err error)
FindInBatches(result *[]*model.SingleAgentVersion, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*model.SingleAgentVersion) (info gen.ResultInfo, err error)
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
Updates(value interface{}) (info gen.ResultInfo, err error)
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
UpdateFrom(q gen.SubQuery) gen.Dao
Attrs(attrs ...field.AssignExpr) ISingleAgentVersionDo
Assign(attrs ...field.AssignExpr) ISingleAgentVersionDo
Joins(fields ...field.RelationField) ISingleAgentVersionDo
Preload(fields ...field.RelationField) ISingleAgentVersionDo
FirstOrInit() (*model.SingleAgentVersion, error)
FirstOrCreate() (*model.SingleAgentVersion, error)
FindByPage(offset int, limit int) (result []*model.SingleAgentVersion, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) ISingleAgentVersionDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (s singleAgentVersionDo) Debug() ISingleAgentVersionDo {
return s.withDO(s.DO.Debug())
}
func (s singleAgentVersionDo) WithContext(ctx context.Context) ISingleAgentVersionDo {
return s.withDO(s.DO.WithContext(ctx))
}
func (s singleAgentVersionDo) ReadDB() ISingleAgentVersionDo {
return s.Clauses(dbresolver.Read)
}
func (s singleAgentVersionDo) WriteDB() ISingleAgentVersionDo {
return s.Clauses(dbresolver.Write)
}
func (s singleAgentVersionDo) Session(config *gorm.Session) ISingleAgentVersionDo {
return s.withDO(s.DO.Session(config))
}
func (s singleAgentVersionDo) Clauses(conds ...clause.Expression) ISingleAgentVersionDo {
return s.withDO(s.DO.Clauses(conds...))
}
func (s singleAgentVersionDo) Returning(value interface{}, columns ...string) ISingleAgentVersionDo {
return s.withDO(s.DO.Returning(value, columns...))
}
func (s singleAgentVersionDo) Not(conds ...gen.Condition) ISingleAgentVersionDo {
return s.withDO(s.DO.Not(conds...))
}
func (s singleAgentVersionDo) Or(conds ...gen.Condition) ISingleAgentVersionDo {
return s.withDO(s.DO.Or(conds...))
}
func (s singleAgentVersionDo) Select(conds ...field.Expr) ISingleAgentVersionDo {
return s.withDO(s.DO.Select(conds...))
}
func (s singleAgentVersionDo) Where(conds ...gen.Condition) ISingleAgentVersionDo {
return s.withDO(s.DO.Where(conds...))
}
func (s singleAgentVersionDo) Order(conds ...field.Expr) ISingleAgentVersionDo {
return s.withDO(s.DO.Order(conds...))
}
func (s singleAgentVersionDo) Distinct(cols ...field.Expr) ISingleAgentVersionDo {
return s.withDO(s.DO.Distinct(cols...))
}
func (s singleAgentVersionDo) Omit(cols ...field.Expr) ISingleAgentVersionDo {
return s.withDO(s.DO.Omit(cols...))
}
func (s singleAgentVersionDo) Join(table schema.Tabler, on ...field.Expr) ISingleAgentVersionDo {
return s.withDO(s.DO.Join(table, on...))
}
func (s singleAgentVersionDo) LeftJoin(table schema.Tabler, on ...field.Expr) ISingleAgentVersionDo {
return s.withDO(s.DO.LeftJoin(table, on...))
}
func (s singleAgentVersionDo) RightJoin(table schema.Tabler, on ...field.Expr) ISingleAgentVersionDo {
return s.withDO(s.DO.RightJoin(table, on...))
}
func (s singleAgentVersionDo) Group(cols ...field.Expr) ISingleAgentVersionDo {
return s.withDO(s.DO.Group(cols...))
}
func (s singleAgentVersionDo) Having(conds ...gen.Condition) ISingleAgentVersionDo {
return s.withDO(s.DO.Having(conds...))
}
func (s singleAgentVersionDo) Limit(limit int) ISingleAgentVersionDo {
return s.withDO(s.DO.Limit(limit))
}
func (s singleAgentVersionDo) Offset(offset int) ISingleAgentVersionDo {
return s.withDO(s.DO.Offset(offset))
}
func (s singleAgentVersionDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ISingleAgentVersionDo {
return s.withDO(s.DO.Scopes(funcs...))
}
func (s singleAgentVersionDo) Unscoped() ISingleAgentVersionDo {
return s.withDO(s.DO.Unscoped())
}
func (s singleAgentVersionDo) Create(values ...*model.SingleAgentVersion) error {
if len(values) == 0 {
return nil
}
return s.DO.Create(values)
}
func (s singleAgentVersionDo) CreateInBatches(values []*model.SingleAgentVersion, batchSize int) error {
return s.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (s singleAgentVersionDo) Save(values ...*model.SingleAgentVersion) error {
if len(values) == 0 {
return nil
}
return s.DO.Save(values)
}
func (s singleAgentVersionDo) First() (*model.SingleAgentVersion, error) {
if result, err := s.DO.First(); err != nil {
return nil, err
} else {
return result.(*model.SingleAgentVersion), nil
}
}
func (s singleAgentVersionDo) Take() (*model.SingleAgentVersion, error) {
if result, err := s.DO.Take(); err != nil {
return nil, err
} else {
return result.(*model.SingleAgentVersion), nil
}
}
func (s singleAgentVersionDo) Last() (*model.SingleAgentVersion, error) {
if result, err := s.DO.Last(); err != nil {
return nil, err
} else {
return result.(*model.SingleAgentVersion), nil
}
}
func (s singleAgentVersionDo) Find() ([]*model.SingleAgentVersion, error) {
result, err := s.DO.Find()
return result.([]*model.SingleAgentVersion), err
}
func (s singleAgentVersionDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.SingleAgentVersion, err error) {
buf := make([]*model.SingleAgentVersion, 0, batchSize)
err = s.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
})
return results, err
}
func (s singleAgentVersionDo) FindInBatches(result *[]*model.SingleAgentVersion, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return s.DO.FindInBatches(result, batchSize, fc)
}
func (s singleAgentVersionDo) Attrs(attrs ...field.AssignExpr) ISingleAgentVersionDo {
return s.withDO(s.DO.Attrs(attrs...))
}
func (s singleAgentVersionDo) Assign(attrs ...field.AssignExpr) ISingleAgentVersionDo {
return s.withDO(s.DO.Assign(attrs...))
}
func (s singleAgentVersionDo) Joins(fields ...field.RelationField) ISingleAgentVersionDo {
for _, _f := range fields {
s = *s.withDO(s.DO.Joins(_f))
}
return &s
}
func (s singleAgentVersionDo) Preload(fields ...field.RelationField) ISingleAgentVersionDo {
for _, _f := range fields {
s = *s.withDO(s.DO.Preload(_f))
}
return &s
}
func (s singleAgentVersionDo) FirstOrInit() (*model.SingleAgentVersion, error) {
if result, err := s.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*model.SingleAgentVersion), nil
}
}
func (s singleAgentVersionDo) FirstOrCreate() (*model.SingleAgentVersion, error) {
if result, err := s.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*model.SingleAgentVersion), nil
}
}
func (s singleAgentVersionDo) FindByPage(offset int, limit int) (result []*model.SingleAgentVersion, count int64, err error) {
result, err = s.Offset(offset).Limit(limit).Find()
if err != nil {
return
}
if size := len(result); 0 < limit && 0 < size && size < limit {
count = int64(size + offset)
return
}
count, err = s.Offset(-1).Limit(-1).Count()
return
}
func (s singleAgentVersionDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = s.Count()
if err != nil {
return
}
err = s.Offset(offset).Limit(limit).Scan(result)
return
}
func (s singleAgentVersionDo) Scan(result interface{}) (err error) {
return s.DO.Scan(result)
}
func (s singleAgentVersionDo) Delete(models ...*model.SingleAgentVersion) (result gen.ResultInfo, err error) {
return s.DO.Delete(models)
}
func (s *singleAgentVersionDo) withDO(do gen.Dao) *singleAgentVersionDo {
s.DO = *do.(*gen.DO)
return s
}

View File

@@ -0,0 +1,175 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dal
import (
"context"
"errors"
"github.com/redis/go-redis/v9"
"gorm.io/gorm"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/singleagent"
"github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/entity"
"github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/internal/dal/model"
"github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/internal/dal/query"
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
"github.com/coze-dev/coze-studio/backend/types/errno"
)
type SingleAgentDraftDAO struct {
idGen idgen.IDGenerator
dbQuery *query.Query
cacheClient *redis.Client
}
func NewSingleAgentDraftDAO(db *gorm.DB, idGen idgen.IDGenerator, cli *redis.Client) *SingleAgentDraftDAO {
query.SetDefault(db)
return &SingleAgentDraftDAO{
idGen: idGen,
dbQuery: query.Use(db),
cacheClient: cli,
}
}
func (sa *SingleAgentDraftDAO) Create(ctx context.Context, creatorID int64, draft *entity.SingleAgent) (draftID int64, err error) {
id, err := sa.idGen.GenID(ctx)
if err != nil {
return 0, errorx.WrapByCode(err, errno.ErrAgentIDGenFailCode, errorx.KV("msg", "CreatePromptResource"))
}
return sa.CreateWithID(ctx, creatorID, id, draft)
}
func (sa *SingleAgentDraftDAO) CreateWithID(ctx context.Context, creatorID, agentID int64, draft *entity.SingleAgent) (draftID int64, err error) {
po := sa.singleAgentDraftDo2Po(draft)
po.AgentID = agentID
po.CreatorID = creatorID
err = sa.dbQuery.SingleAgentDraft.WithContext(ctx).Create(po)
if err != nil {
return 0, errorx.WrapByCode(err, errno.ErrAgentCreateDraftCode)
}
return agentID, nil
}
func (sa *SingleAgentDraftDAO) Get(ctx context.Context, agentID int64) (*entity.SingleAgent, error) {
singleAgentDAOModel := sa.dbQuery.SingleAgentDraft
singleAgent, err := sa.dbQuery.SingleAgentDraft.Where(singleAgentDAOModel.AgentID.Eq(agentID)).First()
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
if err != nil {
return nil, errorx.WrapByCode(err, errno.ErrAgentGetCode)
}
do := sa.singleAgentDraftPo2Do(singleAgent)
return do, nil
}
func (sa *SingleAgentDraftDAO) MGet(ctx context.Context, agentIDs []int64) ([]*entity.SingleAgent, error) {
sam := sa.dbQuery.SingleAgentDraft
singleAgents, err := sam.WithContext(ctx).Where(sam.AgentID.In(agentIDs...)).Find()
if err != nil {
return nil, errorx.WrapByCode(err, errno.ErrAgentGetCode)
}
dos := make([]*entity.SingleAgent, 0, len(singleAgents))
for _, singleAgent := range singleAgents {
dos = append(dos, sa.singleAgentDraftPo2Do(singleAgent))
}
return dos, nil
}
func (sa *SingleAgentDraftDAO) Update(ctx context.Context, agentInfo *entity.SingleAgent) (err error) {
po := sa.singleAgentDraftDo2Po(agentInfo)
singleAgentDAOModel := sa.dbQuery.SingleAgentDraft
_, err = singleAgentDAOModel.Where(singleAgentDAOModel.AgentID.Eq(agentInfo.AgentID)).Updates(po)
if err != nil {
return errorx.WrapByCode(err, errno.ErrAgentUpdateCode)
}
return nil
}
func (sa *SingleAgentDraftDAO) Delete(ctx context.Context, spaceID, agentID int64) (err error) {
po := sa.dbQuery.SingleAgentDraft
_, err = po.WithContext(ctx).Where(po.AgentID.Eq(agentID), po.SpaceID.Eq(spaceID)).Delete()
return err
}
func (sa *SingleAgentDraftDAO) singleAgentDraftPo2Do(po *model.SingleAgentDraft) *entity.SingleAgent {
return &entity.SingleAgent{
SingleAgent: &singleagent.SingleAgent{
AgentID: po.AgentID,
CreatorID: po.CreatorID,
SpaceID: po.SpaceID,
Name: po.Name,
Desc: po.Description,
IconURI: po.IconURI,
CreatedAt: po.CreatedAt,
UpdatedAt: po.UpdatedAt,
DeletedAt: po.DeletedAt,
ModelInfo: po.ModelInfo,
OnboardingInfo: po.OnboardingInfo,
Prompt: po.Prompt,
Plugin: po.Plugin,
Knowledge: po.Knowledge,
Workflow: po.Workflow,
SuggestReply: po.SuggestReply,
JumpConfig: po.JumpConfig,
VariablesMetaID: po.VariablesMetaID,
BackgroundImageInfoList: po.BackgroundImageInfoList,
Database: po.DatabaseConfig,
ShortcutCommand: po.ShortcutCommand,
},
}
}
func (sa *SingleAgentDraftDAO) singleAgentDraftDo2Po(do *entity.SingleAgent) *model.SingleAgentDraft {
return &model.SingleAgentDraft{
AgentID: do.AgentID,
CreatorID: do.CreatorID,
SpaceID: do.SpaceID,
Name: do.Name,
Description: do.Desc,
IconURI: do.IconURI,
CreatedAt: do.CreatedAt,
UpdatedAt: do.UpdatedAt,
DeletedAt: do.DeletedAt,
ModelInfo: do.ModelInfo,
OnboardingInfo: do.OnboardingInfo,
Prompt: do.Prompt,
Plugin: do.Plugin,
Knowledge: do.Knowledge,
Workflow: do.Workflow,
SuggestReply: do.SuggestReply,
JumpConfig: do.JumpConfig,
VariablesMetaID: do.VariablesMetaID,
BackgroundImageInfoList: do.BackgroundImageInfoList,
DatabaseConfig: do.Database,
ShortcutCommand: do.ShortcutCommand,
}
}

View File

@@ -0,0 +1,130 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dal
import (
"context"
"time"
// 添加这个导入以解决 gen.Expr 未定义的问题
"github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/entity"
"github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/internal/dal/model"
"github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/internal/dal/query"
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
"github.com/coze-dev/coze-studio/backend/types/errno"
)
// List 方法:分页查询发布记录 pageIndex 从1开始
func (dao *SingleAgentVersionDAO) List(ctx context.Context, agentID int64, pageIndex, pageSize int32) ([]*entity.SingleAgentPublish, error) {
sap := dao.dbQuery.SingleAgentPublish
offset := (pageIndex - 1) * pageSize
query := sap.WithContext(ctx).
Where(sap.AgentID.Eq(agentID)).
Order(sap.PublishTime.Desc())
result, _, err := query.FindByPage(int(offset), int(pageSize))
if err != nil {
return nil, errorx.WrapByCode(err, errno.ErrAgentGetCode)
}
dos := make([]*entity.SingleAgentPublish, 0, len(result))
for _, po := range result {
dos = append(dos, dao.singleAgentPublishPo2Do(po))
}
return dos, nil
}
func (dao *SingleAgentVersionDAO) singleAgentPublishPo2Do(po *model.SingleAgentPublish) *entity.SingleAgentPublish {
if po == nil {
return nil
}
return &entity.SingleAgentPublish{
ID: po.ID,
AgentID: po.AgentID,
PublishID: po.PublishID,
ConnectorIds: po.ConnectorIds,
Version: po.Version,
PublishInfo: po.PublishInfo,
CreatorID: po.CreatorID,
PublishTime: po.PublishTime,
CreatedAt: po.CreatedAt,
UpdatedAt: po.UpdatedAt,
Status: po.Status,
Extra: po.Extra,
}
}
func (sa *SingleAgentVersionDAO) SavePublishRecord(ctx context.Context, p *entity.SingleAgentPublish, e *entity.SingleAgent) (err error) {
connectorIDs := p.ConnectorIds
publishID := p.PublishID
version := p.Version
id, err := sa.IDGen.GenID(ctx)
if err != nil {
return errorx.WrapByCode(err, errno.ErrAgentIDGenFailCode, errorx.KV("msg", "PublishDraftAgent"))
}
now := time.Now()
po := &model.SingleAgentPublish{
ID: id,
AgentID: e.AgentID,
PublishID: publishID,
ConnectorIds: connectorIDs,
Version: version,
PublishInfo: nil,
CreatorID: e.CreatorID,
PublishTime: now.UnixMilli(),
Status: 0,
Extra: nil,
}
if p.PublishInfo != nil {
po.PublishInfo = p.PublishInfo
}
sapTable := query.SingleAgentPublish
err = sapTable.WithContext(ctx).Create(po)
if err != nil {
return errorx.WrapByCode(err, errno.ErrAgentPublishSingleAgentCode)
}
return nil
}
func (sa *SingleAgentVersionDAO) Create(ctx context.Context, connectorID int64, version string, e *entity.SingleAgent) (int64, error) {
id, err := sa.IDGen.GenID(ctx)
if err != nil {
return 0, errorx.WrapByCode(err, errno.ErrAgentIDGenFailCode, errorx.KV("msg", "CreatePromptResource"))
}
po := sa.singleAgentVersionDo2Po(e)
po.ID = id
po.ConnectorID = connectorID
po.Version = version
table := query.SingleAgentVersion
err = table.Create(po)
if err != nil {
return 0, errorx.WrapByCode(err, errno.ErrAgentPublishSingleAgentCode)
}
return id, nil
}

View File

@@ -0,0 +1,135 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dal
import (
"context"
"errors"
"gorm.io/gorm"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/singleagent"
"github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/entity"
"github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/internal/dal/model"
"github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/internal/dal/query"
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
"github.com/coze-dev/coze-studio/backend/types/errno"
)
type SingleAgentVersionDAO struct {
IDGen idgen.IDGenerator
dbQuery *query.Query
}
func NewSingleAgentVersion(db *gorm.DB, idGen idgen.IDGenerator) *SingleAgentVersionDAO {
query.SetDefault(db)
return &SingleAgentVersionDAO{
IDGen: idGen,
dbQuery: query.Use(db),
}
}
func (sa *SingleAgentVersionDAO) GetLatest(ctx context.Context, agentID int64) (*entity.SingleAgent, error) {
singleAgentDAOModel := sa.dbQuery.SingleAgentVersion
singleAgent, err := singleAgentDAOModel.
Where(singleAgentDAOModel.AgentID.Eq(agentID)).
Order(singleAgentDAOModel.CreatedAt.Desc()).
First()
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
if err != nil {
return nil, errorx.WrapByCode(err, errno.ErrAgentGetCode)
}
do := sa.singleAgentVersionPo2Do(singleAgent)
return do, nil
}
func (sa *SingleAgentVersionDAO) Get(ctx context.Context, agentID int64, version string) (*entity.SingleAgent, error) {
singleAgentDAOModel := sa.dbQuery.SingleAgentVersion
singleAgent, err := singleAgentDAOModel.
Where(singleAgentDAOModel.AgentID.Eq(agentID), singleAgentDAOModel.Version.Eq(version)).
First()
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
if err != nil {
return nil, errorx.WrapByCode(err, errno.ErrAgentGetCode)
}
do := sa.singleAgentVersionPo2Do(singleAgent)
return do, nil
}
func (sa *SingleAgentVersionDAO) singleAgentVersionPo2Do(po *model.SingleAgentVersion) *entity.SingleAgent {
return &entity.SingleAgent{
SingleAgent: &singleagent.SingleAgent{
AgentID: po.AgentID,
CreatorID: po.CreatorID,
SpaceID: po.SpaceID,
Name: po.Name,
Desc: po.Description,
IconURI: po.IconURI,
CreatedAt: po.CreatedAt,
UpdatedAt: po.UpdatedAt,
DeletedAt: po.DeletedAt,
ModelInfo: po.ModelInfo,
OnboardingInfo: po.OnboardingInfo,
Prompt: po.Prompt,
Plugin: po.Plugin,
Knowledge: po.Knowledge,
Workflow: po.Workflow,
SuggestReply: po.SuggestReply,
JumpConfig: po.JumpConfig,
VariablesMetaID: po.VariablesMetaID,
Database: po.DatabaseConfig,
ShortcutCommand: po.ShortcutCommand,
Version: po.Version,
},
}
}
func (sa *SingleAgentVersionDAO) singleAgentVersionDo2Po(do *entity.SingleAgent) *model.SingleAgentVersion {
return &model.SingleAgentVersion{
AgentID: do.AgentID,
CreatorID: do.CreatorID,
SpaceID: do.SpaceID,
Name: do.Name,
Description: do.Desc,
IconURI: do.IconURI,
CreatedAt: do.CreatedAt,
UpdatedAt: do.UpdatedAt,
DeletedAt: do.DeletedAt,
ModelInfo: do.ModelInfo,
OnboardingInfo: do.OnboardingInfo,
Prompt: do.Prompt,
Plugin: do.Plugin,
Knowledge: do.Knowledge,
Workflow: do.Workflow,
SuggestReply: do.SuggestReply,
JumpConfig: do.JumpConfig,
VariablesMetaID: do.VariablesMetaID,
DatabaseConfig: do.Database,
ShortcutCommand: do.ShortcutCommand,
}
}