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 consts
import "time"
const (
MySQLDsn = "MYSQL_DSN"
RedisAddr = "REDIS_ADDR"
VeImageXAK = "VE_IMAGEX_AK"
VeImageXSK = "VE_IMAGEX_SK"
VeImageXServerID = "VE_IMAGEX_SERVER_ID"
VeImageXDomain = "VE_IMAGEX_DOMAIN"
VeImageXTemplate = "VE_IMAGEX_TEMPLATE"
VeImageXUploadHost = "VE_IMAGEX_UPLOAD_HOST"
FileUploadComponentType = "FILE_UPLOAD_COMPONENT_TYPE"
FileUploadComponentTypeImagex = "imagex"
FileUploadComponentTypeStorage = "storage"
StorageType = "STORAGE_TYPE"
MinIOAK = "MINIO_AK"
MinIOSK = "MINIO_SK"
MinIOEndpoint = "MINIO_ENDPOINT"
MinIOProxyEndpoint = "MINIO_PROXY_ENDPOINT"
MinIOAPIHost = "MINIO_API_HOST"
StorageBucket = "STORAGE_BUCKET"
TOSAccessKey = "TOS_ACCESS_KEY"
TOSSecretKey = "TOS_SECRET_KEY"
TOSRegion = "TOS_REGION"
TOSEndpoint = "TOS_ENDPOINT"
HostKeyInCtx = "HOST_KEY_IN_CTX"
RequestSchemeKeyInCtx = "REQUEST_SCHEME_IN_CTX"
MQTypeKey = "COZE_MQ_TYPE"
MQServer = "MQ_NAME_SERVER"
RMQSecretKey = "RMQ_SECRET_KEY"
RMQAccessKey = "RMQ_ACCESS_KEY"
RMQTopicApp = "opencoze_search_app"
RMQTopicResource = "opencoze_search_resource"
RMQTopicKnowledge = "opencoze_knowledge"
RMQConsumeGroupResource = "cg_search_resource"
RMQConsumeGroupApp = "cg_search_app"
RMQConsumeGroupKnowledge = "cg_knowledge"
CozeConnectorID = int64(10000010)
WebSDKConnectorID = int64(999)
APIConnectorID = int64(1024)
SessionDataKeyInCtx = "session_data_key_in_ctx"
OpenapiAuthKeyInCtx = "openapi_auth_key_in_ctx"
)
const (
ShortcutCommandResourceType = "uri"
)
const (
SessionMaxAgeSecond = 30 * 24 * 60 * 60
DefaultSessionDuration = SessionMaxAgeSecond * time.Second
)
const (
DefaultUserIcon = "default_icon/user_default_icon.png"
DefaultAgentIcon = "default_icon/default_agent_icon.png"
DefaultAppIcon = "default_icon/default_app_icon.png"
DefaultPluginIcon = "default_icon/plugin_default_icon.png"
DefaultDatabaseIcon = "default_icon/default_database_icon.png"
DefaultDatasetIcon = "default_icon/default_dataset_icon.png"
DefaultPromptIcon = "default_icon/default_prompt_icon.png"
DefaultWorkflowIcon = "default_icon/default_workflow_icon.png"
DefaultTeamIcon = "default_icon/team_default_icon.png"
)
const (
TemplateSpaceID = int64(999999) // special space id for template
)
const (
ApplyUploadActionURI = "/api/playground/apply_upload_action"
UploadURI = "/api/playground/upload"
)

View File

@@ -0,0 +1,310 @@
/*
* 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 main
import (
"fmt"
"log"
"os"
"path/filepath"
"reflect"
"runtime"
"strings"
"gorm.io/driver/mysql"
"gorm.io/gen"
"gorm.io/gorm"
"gorm.io/gorm/schema"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/agentrun"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/database"
modelEntity "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/modelmgr"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
"github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/bot_common"
"github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/playground"
appEntity "github.com/coze-dev/coze-studio/backend/domain/app/entity"
variableEntity "github.com/coze-dev/coze-studio/backend/domain/memory/variables/entity"
"github.com/coze-dev/coze-studio/backend/infra/contract/chatmodel"
)
var path2Table2Columns2Model = map[string]map[string]map[string]any{
"domain/datacopy/internal/dal/query": {
"data_copy_task": {},
},
"domain/agent/singleagent/internal/dal/query": {
"single_agent_draft": {
// "variable": []*bot_common.Variable{},
"model_info": &bot_common.ModelInfo{},
"onboarding_info": &bot_common.OnboardingInfo{},
"prompt": &bot_common.PromptInfo{},
"plugin": []*bot_common.PluginInfo{},
"knowledge": &bot_common.Knowledge{},
"workflow": []*bot_common.WorkflowInfo{},
"suggest_reply": &bot_common.SuggestReplyInfo{},
"jump_config": &bot_common.JumpConfig{},
"background_image_info_list": []*bot_common.BackgroundImageInfo{},
"database_config": []*bot_common.Database{},
"shortcut_command": []string{},
},
"single_agent_version": {
// "variable": []*bot_common.Variable{},
"model_info": &bot_common.ModelInfo{},
"onboarding_info": &bot_common.OnboardingInfo{},
"prompt": &bot_common.PromptInfo{},
"plugin": []*bot_common.PluginInfo{},
"knowledge": &bot_common.Knowledge{},
"workflow": []*bot_common.WorkflowInfo{},
"suggest_reply": &bot_common.SuggestReplyInfo{},
"jump_config": &bot_common.JumpConfig{},
"background_image_info_list": []*bot_common.BackgroundImageInfo{},
"database_config": []*bot_common.Database{},
"shortcut_command": []string{},
},
"single_agent_publish": {
"connector_ids": []int64{},
},
},
"domain/plugin/internal/dal/query": {
"plugin": {
"manifest": &plugin.PluginManifest{},
"openapi_doc": &plugin.Openapi3T{},
},
"plugin_draft": {
"manifest": &plugin.PluginManifest{},
"openapi_doc": &plugin.Openapi3T{},
},
"plugin_version": {
"manifest": &plugin.PluginManifest{},
"openapi_doc": &plugin.Openapi3T{},
},
"agent_tool_draft": {
"operation": &plugin.Openapi3Operation{},
},
"agent_tool_version": {
"operation": &plugin.Openapi3Operation{},
},
"tool": {
"operation": &plugin.Openapi3Operation{},
},
"tool_draft": {
"operation": &plugin.Openapi3Operation{},
},
"tool_version": {
"operation": &plugin.Openapi3Operation{},
},
"plugin_oauth_auth": {
"oauth_config": &plugin.OAuthAuthorizationCodeConfig{},
},
},
"domain/conversation/agentrun/internal/dal/query": {
"run_record": {
"usage": &agentrun.Usage{},
},
},
"domain/conversation/conversation/internal/dal/query": {
"conversation": {},
},
"domain/conversation/message/internal/dal/query": {
"message": {},
},
"domain/prompt/internal/dal/query": {
"prompt_resource": {},
},
// "domain/knowledge/internal/query": {
// "knowledge": {},
// "knowledge_document": {},
// "knowledge_document_slice": {},
// },
"domain/memory/variables/internal/dal/query": {
"variables_meta": {
"variable_list": []*variableEntity.VariableMeta{},
},
"variable_instance": {},
},
"domain/modelmgr/internal/dal/query": {
"model_meta": {
"capability": &modelEntity.Capability{},
"conn_config": &chatmodel.Config{},
"status": modelEntity.ModelMetaStatus(0),
},
"model_entity": {
"scenario": modelEntity.Scenario(0),
"default_params": []*modelEntity.Parameter{},
"status": modelEntity.ModelEntityStatus(0),
},
},
"domain/workflow/internal/repo/dal/query": {
"workflow_meta": {},
"workflow_draft": {},
"workflow_version": {},
"workflow_reference": {},
"workflow_execution": {},
"node_execution": {},
"workflow_snapshot": {},
"connector_workflow_version": {},
},
"domain/openauth/openapiauth/internal/dal/query": {
"api_key": {},
},
"domain/shortcutcmd/internal/dal/query": {
"shortcut_command": {
"tool_info": &playground.ToolInfo{},
"components": []*playground.Components{},
"shortcut_icon": &playground.ShortcutFileInfo{},
},
},
"domain/memory/database/internal/dal/query": {
"online_database_info": {
"table_field": []*database.FieldItem{},
},
"draft_database_info": {
"table_field": []*database.FieldItem{},
},
"agent_to_database": {},
},
"domain/user/internal/dal/query": {
"user": {},
"space": {},
"space_user": {},
},
"domain/app/internal/dal/query": {
"app_draft": {},
"app_release_record": {
"connector_ids": []int64{},
"extra_info": &appEntity.PublishRecordExtraInfo{},
},
"app_connector_release_ref": {
"publish_config": appEntity.PublishConfig{},
},
},
}
var fieldNullablePath = map[string]bool{
"domain/agent/singleagent/internal/dal/query": true,
}
func main() {
dsn := os.Getenv("MYSQL_DSN")
os.Setenv("LANG", "en_US.UTF-8")
dsn = "root:root@tcp(localhost:3306)/opencoze?charset=utf8mb4&parseTime=True"
gormDB, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
NamingStrategy: schema.NamingStrategy{
SingularTable: true,
},
})
if err != nil {
log.Fatalf("gorm.Open failed, err=%v", err)
}
rootPath, err := findProjectRoot()
if err != nil {
log.Fatalf("failed to find project root: %v", err)
}
for path, mapping := range path2Table2Columns2Model {
g := gen.NewGenerator(gen.Config{
OutPath: filepath.Join(rootPath, path),
Mode: gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface,
FieldNullable: fieldNullablePath[path],
})
parts := strings.Split(path, "/")
modelPath := strings.Join(append(parts[:len(parts)-1], g.Config.ModelPkgPath), "/")
g.UseDB(gormDB)
g.WithOpts(gen.FieldType("deleted_at", "gorm.DeletedAt"))
var resolveType func(typ reflect.Type, required bool) string
resolveType = func(typ reflect.Type, required bool) string {
switch typ.Kind() {
case reflect.Ptr:
return resolveType(typ.Elem(), false)
case reflect.Slice:
return "[]" + resolveType(typ.Elem(), required)
default:
prefix := "*"
if required {
prefix = ""
}
if strings.HasSuffix(typ.PkgPath(), modelPath) {
return prefix + typ.Name()
}
return prefix + typ.String()
}
}
genModify := func(col string, model any) func(f gen.Field) gen.Field {
return func(f gen.Field) gen.Field {
if f.ColumnName != col {
return f
}
st := reflect.TypeOf(model)
// f.Name = st.Name()
f.Type = resolveType(st, true)
f.GORMTag.Set("serializer", "json")
return f
}
}
timeModify := func(f gen.Field) gen.Field {
if f.ColumnName == "updated_at" {
// https://gorm.io/zh_CN/docs/models.html#%E5%88%9B%E5%BB%BA-x2F-%E6%9B%B4%E6%96%B0%E6%97%B6%E9%97%B4%E8%BF%BD%E8%B8%AA%EF%BC%88%E7%BA%B3%E7%A7%92%E3%80%81%E6%AF%AB%E7%A7%92%E3%80%81%E7%A7%92%E3%80%81Time%EF%BC%89
f.GORMTag.Set("autoUpdateTime", "milli")
}
if f.ColumnName == "created_at" {
f.GORMTag.Set("autoCreateTime", "milli")
}
return f
}
var models []any
for table, col2Model := range mapping {
opts := make([]gen.ModelOpt, 0, len(col2Model))
for column, m := range col2Model {
cp := m
opts = append(opts, gen.FieldModify(genModify(column, cp)))
}
opts = append(opts, gen.FieldModify(timeModify))
models = append(models, g.GenerateModel(table, opts...))
}
g.ApplyBasic(models...)
g.Execute()
}
}
func findProjectRoot() (string, error) {
_, filename, _, ok := runtime.Caller(0)
if !ok {
return "", fmt.Errorf("failed to get current file path")
}
backendDir := filepath.Dir(filepath.Dir(filepath.Dir(filename))) // notice: the relative path of the script file is assumed here
if _, err := os.Stat(filepath.Join(backendDir, "domain")); os.IsNotExist(err) {
return "", fmt.Errorf("could not find 'domain' directory in backend path: %s", backendDir)
}
return backendDir, nil
}

View File

@@ -0,0 +1,116 @@
/*
* 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 errno
import (
"github.com/coze-dev/coze-studio/backend/pkg/errorx/code"
)
// single agent: 100 000 000 ~ 100 999 999
const (
ErrAgentInvalidParamCode = 100000000
ErrAgentSupportedChatModelProtocol = 100000001
ErrAgentResourceNotFound = 100000002
ErrAgentPermissionCode = 100000003
ErrAgentIDGenFailCode = 100000004
ErrAgentCreateDraftCode = 100000005
ErrAgentGetCode = 100000006
ErrAgentUpdateCode = 100000007
ErrAgentSetDraftBotDisplayInfo = 100000008
ErrAgentGetDraftBotDisplayInfoNotFound = 100000009
ErrAgentPublishSingleAgentCode = 100000010
ErrAgentAlreadyBindDatabaseCode = 100000011
ErrAgentExecuteErrCode = 100000012
)
func init() {
code.Register(
ErrAgentPublishSingleAgentCode,
"publish single agent failed",
code.WithAffectStability(true),
)
code.Register(
ErrAgentGetDraftBotDisplayInfoNotFound,
"get draft bot display info failed",
code.WithAffectStability(true),
)
code.Register(
ErrAgentSetDraftBotDisplayInfo,
"set draft bot display info failed",
code.WithAffectStability(true),
)
code.Register(
ErrAgentUpdateCode,
"update single agent failed",
code.WithAffectStability(true),
)
code.Register(
ErrAgentGetCode,
"get single agent failed",
code.WithAffectStability(true),
)
code.Register(
ErrAgentCreateDraftCode,
"create single agent failed",
code.WithAffectStability(true),
)
code.Register(
ErrAgentIDGenFailCode,
"gen id failed : {msg}",
code.WithAffectStability(true),
)
code.Register(
ErrAgentPermissionCode,
"unauthorized access : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrAgentResourceNotFound,
"{type} not found: {id}",
code.WithAffectStability(false),
)
code.Register(
ErrAgentSupportedChatModelProtocol,
"unsupported chat model protocol : {protocol}",
code.WithAffectStability(false),
)
code.Register(
ErrAgentInvalidParamCode,
"invalid parameter : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrAgentAlreadyBindDatabaseCode,
"already bind database : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrAgentExecuteErrCode,
"systemt error",
code.WithAffectStability(true),
)
}

View File

@@ -0,0 +1,48 @@
/*
* 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 errno
import "github.com/coze-dev/coze-studio/backend/pkg/errorx/code"
// App: 101 000 000 ~ 101 999 999
const (
ErrAppInvalidParamCode = 101000000
ErrAppPermissionCode = 101000001
ErrAppRecordNotFound = 109000002
)
const APPMsgKey = "msg"
func init() {
code.Register(
ErrAppPermissionCode,
"unauthorized access : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrAppInvalidParamCode,
"invalid parameter : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrAppRecordNotFound,
"record not found",
code.WithAffectStability(false),
)
}

View File

@@ -0,0 +1,46 @@
/*
* 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 errno
import "github.com/coze-dev/coze-studio/backend/pkg/errorx/code"
// Connector: 102 000 000 ~ 102 999 999
const (
ErrConnectorInvalidParamCode = 102000000
ErrConnectorPermissionCode = 102000001
ErrConnectorNotFound = 102000002
)
func init() {
code.Register(
ErrConnectorNotFound,
"connector not found : {id}",
code.WithAffectStability(false),
)
code.Register(
ErrConnectorPermissionCode,
"unauthorized access : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrConnectorInvalidParamCode,
"invalid parameter : {msg}",
code.WithAffectStability(false),
)
}

View File

@@ -0,0 +1,96 @@
/*
* 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 errno
import "github.com/coze-dev/coze-studio/backend/pkg/errorx/code"
// Conversation: 103 000 000 ~ 103 999 999
const (
ErrConversationInvalidParamCode = 103000000
ErrConversationPermissionCode = 103000001
ErrConversationNotFound = 103000002
ErrConversationJsonMarshal = 103000003
ErrConversationAgentRunError = 103100001
ErrAgentNotExists = 103100002
ErrReplyUnknowEventType = 103100003
ErrUnknowInterruptType = 103100004
ErrInterruptDataEmpty = 103100005
ErrConversationMessageNotFound = 103200001
)
func init() {
code.Register(
ErrConversationJsonMarshal,
"json marshal failed",
code.WithAffectStability(true),
)
code.Register(
ErrConversationNotFound,
"conversation not found",
code.WithAffectStability(false),
)
code.Register(
ErrConversationPermissionCode,
"unauthorized access : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrConversationInvalidParamCode,
"invalid parameter : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrConversationAgentRunError,
"agent run error : {msg}",
code.WithAffectStability(true),
)
code.Register(
ErrAgentNotExists,
"agent not exists",
code.WithAffectStability(false),
)
code.Register(
ErrConversationMessageNotFound,
"message not found",
code.WithAffectStability(false),
)
code.Register(
ErrReplyUnknowEventType,
"unknow event type",
code.WithAffectStability(true),
)
code.Register(
ErrUnknowInterruptType,
"unknow interrupt type",
code.WithAffectStability(true),
)
code.Register(
ErrInterruptDataEmpty,
"interrupt data is empty",
code.WithAffectStability(true),
)
}

View File

@@ -0,0 +1,277 @@
/*
* 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 errno
import "github.com/coze-dev/coze-studio/backend/pkg/errorx/code"
// Knowledge: 105 000 000 ~ 105 999 999
const (
ErrKnowledgeInvalidParamCode = 105000000
ErrKnowledgePermissionCode = 105000001
ErrKnowledgeNonRetryableCode = 105000002
ErrKnowledgeDBCode = 105000003
ErrKnowledgeSearchStoreCode = 105000004
ErrKnowledgeSystemCode = 105000005
ErrKnowledgeCrossDomainCode = 105000006
ErrKnowledgeEmbeddingCode = 105000007
ErrKnowledgeIDGenCode = 105000008
ErrKnowledgeMQSendFailCode = 105000009
ErrKnowledgeDuplicateCode = 105000010
ErrKnowledgeNotExistCode = 105000011
ErrKnowledgeDocumentNotExistCode = 105000012
ErrKnowledgeSemanticColumnValueEmptyCode = 105000013
ErrKnowledgeParseJSONCode = 105000014
ErrKnowledgeResegmentNotSupportedCode = 105000015
ErrKnowledgeFieldNameDuplicatedCode = 105000016
ErrKnowledgeDocOversizeCode = 105000017
ErrKnowledgeDocNotReadyCode = 105000018
ErrKnowledgeDownloadFailedCode = 105000019
ErrKnowledgeTableInfoNotExistCode = 105000020
ErrKnowledgePutObjectFailCode = 105000021
ErrKnowledgeGetObjectURLFailCode = 105000022
ErrKnowledgeGetDocProgressFailCode = 105000023
ErrKnowledgeSliceInsertPositionIllegalCode = 105000024
ErrKnowledgeSliceNotExistCode = 105000025
ErrKnowledgeColumnParseFailCode = 105000026
ErrKnowledgeAutoAnnotationNotSupportedCode = 105000027
ErrKnowledgeGetParserFailCode = 105000028
ErrKnowledgeGetObjectFailCode = 105000029
ErrKnowledgeParserParseFailCode = 105000030
ErrKnowledgeBuildRetrieveChainFailCode = 105000031
ErrKnowledgeRetrieveExecFailCode = 105000032
ErrKnowledgeNL2SqlExecFailCode = 105000033
ErrKnowledgeCopyFailCode = 105000034
ErrKnowledgeParseResultEmptyCode = 105000035
ErrKnowledgeCacheClientSetFailCode = 105000036
ErrKnowledgeCheckTableSliceValidCode = 105000037
)
func init() {
code.Register(
ErrKnowledgeNonRetryableCode,
"non-retryable error",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgePermissionCode,
"unauthorized access : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeInvalidParamCode,
"invalid parameter : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeDBCode,
"MySQL operation failed: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeSearchStoreCode,
"SearchStore operation failed: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeSystemCode,
"system internal error: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeCrossDomainCode,
"cross-domain error: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeEmbeddingCode,
"embedding error: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeIDGenCode,
"ID generation failed: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeMQSendFailCode,
"MQ send message failed: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeDuplicateCode,
"knowledge name duplicate: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeNotExistCode,
"knowledge not exist: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeDocumentNotExistCode,
"document not exist: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeSemanticColumnValueEmptyCode,
"semantic column value empty: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeParseJSONCode,
"parse json failed: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeResegmentNotSupportedCode,
"Processing, resegment is not supported: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeFieldNameDuplicatedCode,
"field name duplicated: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeDocOversizeCode,
"document oversize: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeDocNotReadyCode,
"document not ready: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeDownloadFailedCode,
"download failed: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeGetObjectURLFailCode,
"get object url failed: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeTableInfoNotExistCode,
"table info not exist: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeGetDocProgressFailCode,
"get document progress failed: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeSliceInsertPositionIllegalCode,
"slice insert position illegal: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeSliceNotExistCode,
"slice not exist: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeColumnParseFailCode,
"column parse failed: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeAutoAnnotationNotSupportedCode,
"auto annotation not supported: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeGetParserFailCode,
"get parser failed: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeGetObjectFailCode,
"get object failed: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeParserParseFailCode,
"parser parse failed: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeBuildRetrieveChainFailCode,
"build retrieve chain failed: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeRetrieveExecFailCode,
"retrieve exec failed: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeNL2SqlExecFailCode,
"nl2sql exec failed: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeCopyFailCode,
"copy failed: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeParseResultEmptyCode,
"parse result empty: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeCacheClientSetFailCode,
"cache client set failed: {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrKnowledgeCheckTableSliceValidCode,
"slice content validation failed, please check if the input is correct:{msg}",
code.WithAffectStability(false),
)
}

View File

@@ -0,0 +1,213 @@
/*
* 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 errno
import "github.com/coze-dev/coze-studio/backend/pkg/errorx/code"
// Memory: 106 000 000 ~ 106 999 999
const (
ErrMemoryInvalidParamCode = 106000000
ErrMemoryPermissionCode = 106000001
ErrMemoryIDGenFailCode = 106000002
ErrMemorySchemeInvalidCode = 106000003
ErrMemoryGetAppVariableCode = 106000004
ErrMemoryCreateAppVariableCode = 106000005
ErrMemoryUpdateAppVariableCode = 106000006
ErrMemoryGetVariableMetaCode = 106000007
ErrMemoryVariableMetaNotFoundCode = 106000008
ErrMemoryNoVariableCanBeChangedCode = 106000009
ErrMemoryDeleteVariableInstanceCode = 106000010
ErrMemoryGetSysUUIDInstanceCode = 106000011
ErrMemoryGetVariableInstanceCode = 106000012
ErrMemorySetKvMemoryItemInstanceCode = 106000013
ErrMemoryUpdateVariableInstanceCode = 106000014
ErrMemoryInsertVariableInstanceCode = 106000015
ErrMemoryDatabaseFieldNotFoundCode = 106000016
ErrMemoryDatabaseNotFoundCode = 106000017
ErrMemoryDatabaseCannotAddData = 106000018
ErrMemoryDatabaseColumnNotMatch = 106000019
ErrMemoryDatabaseXlsSheetEmpty = 106000020
ErrMemoryDatabaseSheetSizeExceed = 106000021
ErrMemoryDatabaseUnsupportedFileType = 106000022
ErrMemoryDatabaseSheetRowCountExceed = 106000023
ErrMemoryDatabaseSheetIndexExceed = 106000024
ErrMemoryDatabaseNoSheetFound = 106000025
ErrMemoryDatabaseNameInvalid = 106000026
)
func init() {
code.Register(
ErrMemorySchemeInvalidCode,
"schema is invalid : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrMemoryGetAppVariableCode,
"get project variable failed ",
code.WithAffectStability(true),
)
code.Register(
ErrMemoryCreateAppVariableCode,
"get project variable failed ",
code.WithAffectStability(true),
)
code.Register(
ErrMemoryUpdateAppVariableCode,
"update project variable failed ",
code.WithAffectStability(true),
)
code.Register(
ErrMemoryGetVariableMetaCode,
"get variable meta failed ",
code.WithAffectStability(true),
)
code.Register(
ErrMemoryVariableMetaNotFoundCode,
"variable meta not found ",
code.WithAffectStability(false),
)
code.Register(
ErrMemoryNoVariableCanBeChangedCode,
"no variable can be changed ",
code.WithAffectStability(false),
)
code.Register(
ErrMemoryDeleteVariableInstanceCode,
"delete variable instance failed",
code.WithAffectStability(true),
)
code.Register(
ErrMemoryGetSysUUIDInstanceCode,
"get sys uuid instance failed {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrMemoryGetVariableInstanceCode,
"get sys uuid instance failed {msg}",
code.WithAffectStability(true),
)
code.Register(
ErrMemorySetKvMemoryItemInstanceCode,
"no key can be changed",
code.WithAffectStability(false),
)
code.Register(
ErrMemoryUpdateVariableInstanceCode,
"update variable instance failed",
code.WithAffectStability(true),
)
code.Register(
ErrMemoryInsertVariableInstanceCode,
"insert variable instance failed",
code.WithAffectStability(true),
)
code.Register(
ErrMemoryIDGenFailCode,
"gen id failed : {msg}",
code.WithAffectStability(true),
)
code.Register(
ErrMemoryPermissionCode,
"unauthorized access : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrMemoryInvalidParamCode,
"invalid parameter : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrMemoryDatabaseFieldNotFoundCode,
"database field not found",
code.WithAffectStability(false),
)
code.Register(
ErrMemoryDatabaseNotFoundCode,
"database not found",
code.WithAffectStability(false),
)
code.Register(
ErrMemoryDatabaseCannotAddData,
"database cannot add data",
code.WithAffectStability(false),
)
code.Register(
ErrMemoryDatabaseColumnNotMatch,
"database column not match : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrMemoryDatabaseXlsSheetEmpty,
"database xls sheet empty",
code.WithAffectStability(false),
)
code.Register(
ErrMemoryDatabaseSheetSizeExceed,
"database sheet size exceed",
code.WithAffectStability(false),
)
code.Register(
ErrMemoryDatabaseUnsupportedFileType,
"database unsupported file type",
code.WithAffectStability(false),
)
code.Register(
ErrMemoryDatabaseSheetRowCountExceed,
"database sheet row count exceed : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrMemoryDatabaseSheetIndexExceed,
"database sheet index exceed",
code.WithAffectStability(false),
)
code.Register(
ErrMemoryDatabaseNoSheetFound,
"database no sheet found",
code.WithAffectStability(false),
)
code.Register(
ErrMemoryDatabaseNameInvalid,
"database name invalid",
code.WithAffectStability(false),
)
}

View File

@@ -0,0 +1,39 @@
/*
* 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 errno
import "github.com/coze-dev/coze-studio/backend/pkg/errorx/code"
// ModelMgr: 107 000 000 ~ 107 999 999
const (
ErrModelMgrInvalidParamCode = 107000000
ErrModelMgrPermissionCode = 107000001
)
func init() {
code.Register(
ErrModelMgrPermissionCode,
"unauthorized access : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrModelMgrInvalidParamCode,
"invalid parameter : {msg}",
code.WithAffectStability(false),
)
}

View File

@@ -0,0 +1,32 @@
/*
* 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 errno
import "github.com/coze-dev/coze-studio/backend/pkg/errorx/code"
// Permission: 108 000 000 ~ 108 999 999
const (
ErrPermissionInvalidParamCode = 108000000
)
func init() {
code.Register(
ErrPermissionInvalidParamCode,
"invalid parameter : {msg}",
code.WithAffectStability(false),
)
}

View File

@@ -0,0 +1,125 @@
/*
* 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 errno
import (
"fmt"
"github.com/coze-dev/coze-studio/backend/pkg/errorx/code"
)
// Plugin: 109 000 000 ~ 109 999 999
const (
ErrPluginInvalidParamCode = 109000000
ErrPluginPermissionCode = 109000001
ErrPluginInvalidClientCredentialsCode = 109000002
ErrPluginInvalidOpenapi3Doc = 109000003
ErrPluginInvalidManifest = 109000004
ErrPluginRecordNotFound = 109000005
ErrPluginDeactivatedTool = 109000006
ErrPluginDuplicatedTool = 109000007
ErrPluginInvalidThirdPartyCode = 109000008
ErrPluginExecuteToolFailed = 109000009
ErrPluginConvertProtocolFailed = 109000010
ErrPluginToolsCheckFailed = 109000011
ErrPluginParseToolRespFailed = 109000012
ErrPluginOAuthFailed = 109000013
)
const (
PluginMsgKey = "msg"
)
func init() {
code.Register(
ErrPluginPermissionCode,
fmt.Sprintf("unauthorized access : {%s}", PluginMsgKey),
code.WithAffectStability(false),
)
code.Register(
ErrPluginInvalidParamCode,
fmt.Sprintf("invalid parameter : {%s}", PluginMsgKey),
code.WithAffectStability(false),
)
code.Register(
ErrPluginInvalidClientCredentialsCode,
"invalid client credentials",
code.WithAffectStability(false),
)
code.Register(
ErrPluginInvalidOpenapi3Doc,
fmt.Sprintf("invalid plugin openapi3 document : {%s}", PluginMsgKey),
code.WithAffectStability(false),
)
code.Register(
ErrPluginInvalidManifest,
fmt.Sprintf("invalid plugin manifest : {%s}", PluginMsgKey),
code.WithAffectStability(false),
)
code.Register(
ErrPluginRecordNotFound,
fmt.Sprintf("record not found"),
code.WithAffectStability(false),
)
code.Register(
ErrPluginDeactivatedTool,
fmt.Sprintf("tool is deactivated : {%s}", PluginMsgKey),
code.WithAffectStability(false),
)
code.Register(
ErrPluginDuplicatedTool,
fmt.Sprintf("duplicated tool : {%s}", PluginMsgKey),
code.WithAffectStability(false),
)
code.Register(
ErrPluginExecuteToolFailed,
fmt.Sprintf("execute tool failed : {%s}", PluginMsgKey),
code.WithAffectStability(false),
)
code.Register(
ErrPluginConvertProtocolFailed,
fmt.Sprintf("convert protocol failed : {%s}", PluginMsgKey),
code.WithAffectStability(false),
)
code.Register(
ErrPluginToolsCheckFailed,
fmt.Sprintf("tools check failed : {%s}", PluginMsgKey),
code.WithAffectStability(false),
)
code.Register(
ErrPluginParseToolRespFailed,
fmt.Sprintf("parse tool response failed : {%s}", PluginMsgKey),
code.WithAffectStability(false),
)
code.Register(
ErrPluginOAuthFailed,
fmt.Sprintf("oauth failed : {%s}", PluginMsgKey),
code.WithAffectStability(false),
)
}

View File

@@ -0,0 +1,80 @@
/*
* 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 errno
import "github.com/coze-dev/coze-studio/backend/pkg/errorx/code"
// Prompt: 110 000 000 ~ 110 999 999
const (
ErrPromptInvalidParamCode = 110000000
ErrPromptPermissionCode = 110000001
ErrPromptIDGenFailCode = 110000002
ErrPromptCreateCode = 110000003
ErrPromptGetCode = 110000004
ErrPromptDataNotFoundCode = 110000005
ErrPromptUpdateCode = 110000006
ErrPromptDeleteCode = 110000007
)
func init() {
code.Register(
ErrPromptDeleteCode,
"delete prompt resource failed",
code.WithAffectStability(true),
)
code.Register(
ErrPromptUpdateCode,
"update prompt resource failed",
code.WithAffectStability(true),
)
code.Register(
ErrPromptDataNotFoundCode,
"prompt resource not found",
code.WithAffectStability(false),
)
code.Register(
ErrPromptGetCode,
"get prompt resource failed",
code.WithAffectStability(true),
)
code.Register(
ErrPromptCreateCode,
"create prompt resource failed",
code.WithAffectStability(true),
)
code.Register(
ErrPromptIDGenFailCode,
"gen id failed : {msg}",
code.WithAffectStability(true),
)
code.Register(
ErrPromptPermissionCode,
"unauthorized access : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrPromptInvalidParamCode,
"invalid parameter : {msg}",
code.WithAffectStability(false),
)
}

View File

@@ -0,0 +1,39 @@
/*
* 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 errno
import "github.com/coze-dev/coze-studio/backend/pkg/errorx/code"
// Search: 111 000 000 ~ 111 999 999
const (
ErrSearchInvalidParamCode = 111000000
ErrSearchPermissionCode = 111000001
)
func init() {
code.Register(
ErrSearchPermissionCode,
"unauthorized access : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrSearchInvalidParamCode,
"invalid parameter : {msg}",
code.WithAffectStability(false),
)
}

View File

@@ -0,0 +1,39 @@
/*
* 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 errno
import "github.com/coze-dev/coze-studio/backend/pkg/errorx/code"
// ShortCmd: 112 000 000 ~ 112 999 999
const (
ErrShortCmdInvalidParamCode = 112000000
ErrShortCmdPermissionCode = 112000002
)
func init() {
code.Register(
ErrShortCmdPermissionCode,
"unauthorized access : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrShortCmdInvalidParamCode,
"invalid parameter : {msg}",
code.WithAffectStability(false),
)
}

View File

@@ -0,0 +1,102 @@
/*
* 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 errno
import "github.com/coze-dev/coze-studio/backend/pkg/errorx/code"
// Upload: 104 000 000 ~ 104 999 999
const (
ErrUploadInvalidParamCode = 104000000
ErrUploadPermissionCode = 104000001
ErrUploadInvalidType = 104000002
ErrUploadInvalidContentTypeCode = 104000003
ErrUploadInvalidFileSizeCode = 104000004
ErrUploadMultipartFormDataReadFailedCode = 104000005
ErrUploadEmptyFileCode = 104000006
ErrUploadFileUploadGreaterOneCode = 104000007
ErrUploadSystemErrorCode = 104000008
ErrUploadHostNotExistCode = 104000009
ErrUploadHostSchemaNotExistCode = 104000010
)
func init() {
code.Register(
ErrUploadInvalidType,
"invalid Upload type : {type}",
code.WithAffectStability(false),
)
code.Register(
ErrUploadPermissionCode,
"unauthorized access : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrUploadInvalidParamCode,
"invalid parameter : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrUploadInvalidContentTypeCode,
"invalid content-type : {content-type}",
code.WithAffectStability(false),
)
code.Register(
ErrUploadInvalidFileSizeCode,
"文件size过大",
code.WithAffectStability(false),
)
code.Register(
ErrUploadMultipartFormDataReadFailedCode,
"multipart form data read failed",
code.WithAffectStability(false),
)
code.Register(
ErrUploadEmptyFileCode,
"upload fileopencan't find file",
code.WithAffectStability(false),
)
code.Register(
ErrUploadFileUploadGreaterOneCode,
"upload fileopenexceed one file",
code.WithAffectStability(false),
)
code.Register(
ErrUploadSystemErrorCode,
"system error : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrUploadHostNotExistCode,
"upload host not exist",
code.WithAffectStability(false),
)
code.Register(
ErrUploadHostSchemaNotExistCode,
"upload host schema not exist",
code.WithAffectStability(false),
)
}

View File

@@ -0,0 +1,77 @@
/*
* 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 errno
import (
"github.com/coze-dev/coze-studio/backend/pkg/errorx/code"
)
// Passport: 700 000 000 ~ 700 999 999
const (
ErrUserAuthenticationFailed = 700012006 // Don't change this code. It is used in the frontend.
ErrUserEmailAlreadyExistCode = 700000001
ErrUserUniqueNameAlreadyExistCode = 700000002
ErrUserInfoInvalidateCode = 700000003
ErrUserSessionInvalidateCode = 700000004
ErrUserResourceNotFound = 700000005
ErrUserInvalidParamCode = 700000006
ErrUserPermissionCode = 700000007
)
func init() {
code.Register(
ErrUserPermissionCode,
"unauthorized access : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrUserInvalidParamCode,
"invalid parameter : {msg}",
code.WithAffectStability(false),
)
code.Register(
ErrUserResourceNotFound,
"{type} not found: {id}",
code.WithAffectStability(false),
)
code.Register(
ErrUserInfoInvalidateCode,
"invalid email or password, please try again.",
code.WithAffectStability(false),
)
code.Register(
ErrUserUniqueNameAlreadyExistCode,
"unique name already exist : {name}",
code.WithAffectStability(false),
)
code.Register(
ErrUserEmailAlreadyExistCode,
"email already exist : {email}",
code.WithAffectStability(false),
)
code.Register(
ErrUserAuthenticationFailed,
"authentication failed: {reason}",
code.WithAffectStability(false),
)
}

View File

@@ -0,0 +1,299 @@
/*
* 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 errno
import (
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
"github.com/coze-dev/coze-studio/backend/pkg/errorx/code"
)
const (
ErrWorkflowNotPublished = 720702011
ErrMissingRequiredParam = 720702002
ErrInterruptNotSupported = 720702078
ErrInvalidParameter = 720702001
ErrArrIndexOutOfRange = 720712014
ErrWorkflowExecuteFail = 720701013
ErrCodeExecuteFail = 305000002
ErrQuestionOptionsEmpty = 720712049
ErrNodeOutputParseFail = 720712023
ErrWorkflowTimeout = 720702085
ErrWorkflowNotFound = 720702004
ErrSerializationDeserializationFail = 720701011
ErrInternalBadRequest = 720701007
ErrSchemaConversionFail = 720702089
ErrWorkflowCompileFail = 720701003
ErrPluginAPIErr = 720701004
)
const (
ErrWorkflowSpecifiedVersionNotFound = 777777778
ErrWorkflowCanceledByUser = 777777777
ErrNodeTimeout = 777777776
ErrWorkflowOperationFail = 777777775
ErrIndexingNilArray = 777777774
ErrLLMStructuredOutputParseFail = 777777773
ErrCreateNodeFail = 777777772
ErrWorkflowSnapshotNotFound = 777777771
ErrNotifyWorkflowResourceChangeErr = 777777770
ErrInvalidVersionName = 777777769
ErrPluginIDNotFound = 777777768
ErrTOSError = 777777767
ErrToolIDNotFound = 777777766
ErrAuthorizationRequired = 777777765
ErrVariablesAPIFail = 777777764
ErrInputFieldMissing = 777777763
)
// stability problems
const (
ErrDatabaseError = 720700801
ErrRedisError = 720700803
ErrIDGenError = 720700808
)
const (
ErrOpenAPIWorkflowNotPublished = 6031
ErrOpenAPIBadRequest = 4000
ErrOpenAPIInterruptNotSupported = 6039
ErrOpenAPIWorkflowTimeout = 6023
)
func init() {
code.Register(
ErrWorkflowNotPublished,
"Workflow not published. The requested operation cannot be performed on an unpublished workflow. Please publish the workflow and try again.",
code.WithAffectStability(false),
)
code.Register(
ErrMissingRequiredParam,
"Missing required parameters {param}. Please review the API documentation and ensure all mandatory fields are included in your request.",
code.WithAffectStability(false),
)
code.Register(
ErrInterruptNotSupported,
"Synchronous requests do not support interruption. Please switch to asynchronous requests for interruptible operations.",
code.WithAffectStability(false),
)
code.Register(
ErrInvalidParameter,
"Invalid request parameters. Please check your input and ensure all required fields are correctly formatted and within allowed ranges.",
code.WithAffectStability(false),
)
code.Register(
ErrArrIndexOutOfRange,
"Array {arr_name} index out of bounds: The requested index {req_index} exceeds the array's length {arr_len}. Please ensure the index is within the valid range of the array. You can refer to debug_url for more details.",
code.WithAffectStability(false),
)
code.Register(
ErrIndexingNilArray,
"Array {arr_name} is nil: The requested index {req_index} cannot be extracted.",
code.WithAffectStability(false),
)
code.Register(
ErrWorkflowExecuteFail,
"Workflow execution failure: {cause}",
code.WithAffectStability(false),
)
code.Register(
ErrWorkflowOperationFail,
"Workflow operation failure: {cause}",
code.WithAffectStability(false),
)
code.Register(
ErrCodeExecuteFail,
"Function execution failed, please check the code of the function. Detail: {detail}",
code.WithAffectStability(false),
)
code.Register(
ErrQuestionOptionsEmpty,
"question option is empty",
code.WithAffectStability(false),
)
code.Register(
ErrNodeOutputParseFail,
"node output parse fail: {warnings}",
code.WithAffectStability(false),
)
code.Register(
ErrWorkflowCanceledByUser,
"workflow cancel by user",
code.WithAffectStability(false),
)
code.Register(
ErrNodeTimeout,
"node timeout",
code.WithAffectStability(false),
)
code.Register(
ErrWorkflowTimeout,
"Workflow execution timed out. Please check for long-running operations, optimize if possible, or retry later.",
code.WithAffectStability(false),
)
code.Register(
ErrLLMStructuredOutputParseFail,
"parse LLM structured output failed, please refer to LLM's raw output for detail.",
code.WithAffectStability(false),
)
code.Register(
ErrCreateNodeFail,
"create node {node_name} failed: {cause}",
code.WithAffectStability(false),
)
code.Register(
ErrDatabaseError,
"database operation failed",
code.WithAffectStability(true),
)
code.Register(
ErrRedisError,
"redis operation failed",
code.WithAffectStability(true),
)
code.Register(
ErrIDGenError,
"id generator failed",
code.WithAffectStability(true),
)
code.Register(
ErrWorkflowNotFound,
"workflow {id} not found, please check if the workflow exists and not deleted",
code.WithAffectStability(false),
)
code.Register(
ErrSerializationDeserializationFail,
"data serialization/deserialization fail, please contact support team",
code.WithAffectStability(false),
)
code.Register(
ErrWorkflowSnapshotNotFound,
"workflow {id} snapshot {commit_id} not found, please contact support team",
code.WithAffectStability(false),
)
code.Register(
ErrInternalBadRequest,
"one of the request parameters for {scene} is invalid, please contact support team",
code.WithAffectStability(false),
)
code.Register(
ErrSchemaConversionFail,
"schema conversion failed, please contact support team",
code.WithAffectStability(false),
)
code.Register(
ErrWorkflowCompileFail,
"workflow compile failed, please contact support team",
code.WithAffectStability(false),
)
code.Register(
ErrNotifyWorkflowResourceChangeErr,
"notify workflow resource change failed, please try again later",
code.WithAffectStability(false),
)
code.Register(
ErrInvalidVersionName,
"workflow version name is invalid",
code.WithAffectStability(false),
)
code.Register(
ErrPluginAPIErr,
"plugin api error",
code.WithAffectStability(false),
)
code.Register(
ErrPluginIDNotFound,
"plugin {id} not found",
code.WithAffectStability(false),
)
code.Register(
ErrTOSError,
"tos operation failed",
code.WithAffectStability(true),
)
code.Register(
ErrToolIDNotFound,
"tool {id} not found",
code.WithAffectStability(false),
)
code.Register(
ErrAuthorizationRequired,
"authorization required: {extra}",
code.WithAffectStability(false),
)
code.Register(
ErrVariablesAPIFail,
"variables API failed",
code.WithAffectStability(false),
)
code.Register(
ErrInputFieldMissing,
"input field {name} not found",
code.WithAffectStability(false),
)
}
var errnoMap = map[int]int{
ErrWorkflowNotPublished: ErrOpenAPIWorkflowNotPublished,
ErrMissingRequiredParam: ErrOpenAPIBadRequest,
ErrInterruptNotSupported: ErrOpenAPIInterruptNotSupported,
ErrInvalidParameter: ErrOpenAPIBadRequest,
ErrArrIndexOutOfRange: ErrOpenAPIBadRequest,
ErrWorkflowTimeout: ErrOpenAPIWorkflowTimeout,
}
func CodeForOpenAPI(err errorx.StatusError) int {
if err == nil {
return 0
}
if c, ok := errnoMap[int(err.Code())]; ok {
return c
}
return int(err.Code())
}