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,47 @@
/*
* 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 crossagent
import (
"context"
"github.com/cloudwego/eino/schema"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/singleagent"
)
// Requests and responses must not reference domain entities and can only use models under api/model/crossdomain.
type SingleAgent interface {
StreamExecute(ctx context.Context, historyMsg []*message.Message, query *message.Message,
agentRuntime *singleagent.AgentRuntime) (*schema.StreamReader[*singleagent.AgentEvent], error)
ObtainAgentByIdentity(ctx context.Context, identity *singleagent.AgentIdentity) (*singleagent.SingleAgent, error)
}
type ResumeInfo = singleagent.InterruptInfo
type AgentEvent = singleagent.AgentEvent
var defaultSVC SingleAgent
func DefaultSVC() SingleAgent {
return defaultSVC
}
func SetDefaultSVC(svc SingleAgent) {
defaultSVC = svc
}

View File

@@ -0,0 +1,35 @@
/*
* 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 crossagentrun
import (
"context"
)
type AgentRun interface {
Delete(ctx context.Context, runID []int64) error
}
var defaultSVC AgentRun
func DefaultSVC() AgentRun {
return defaultSVC
}
func SetDefaultSVC(svc AgentRun) {
defaultSVC = svc
}

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 crossconnector
import (
"context"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/connector"
)
type Connector interface {
List(ctx context.Context) ([]*connector.Connector, error)
GetByIDs(ctx context.Context, ids []int64) (map[int64]*connector.Connector, error)
GetByID(ctx context.Context, id int64) (*connector.Connector, error)
}
var defaultSVC Connector
func DefaultSVC() Connector {
return defaultSVC
}
func SetDefaultSVC(c Connector) {
defaultSVC = c
}

View File

@@ -0,0 +1,37 @@
/*
* 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 crossconversation
import (
"context"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/conversation"
)
type Conversation interface {
GetCurrentConversation(ctx context.Context, req *conversation.GetCurrent) (*conversation.Conversation, error)
}
var defaultSVC Conversation
func DefaultSVC() Conversation {
return defaultSVC
}
func SetDefaultSVC(c Conversation) {
defaultSVC = c
}

View File

@@ -0,0 +1,43 @@
/*
* 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 crossdatabase
import (
"context"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/database"
)
type Database interface {
ExecuteSQL(ctx context.Context, req *database.ExecuteSQLRequest) (*database.ExecuteSQLResponse, error)
PublishDatabase(ctx context.Context, req *database.PublishDatabaseRequest) (resp *database.PublishDatabaseResponse, err error)
DeleteDatabase(ctx context.Context, req *database.DeleteDatabaseRequest) error
BindDatabase(ctx context.Context, req *database.BindDatabaseToAgentRequest) error
UnBindDatabase(ctx context.Context, req *database.UnBindDatabaseToAgentRequest) error
MGetDatabase(ctx context.Context, req *database.MGetDatabaseRequest) (*database.MGetDatabaseResponse, error)
GetAllDatabaseByAppID(ctx context.Context, req *database.GetAllDatabaseByAppIDRequest) (*database.GetAllDatabaseByAppIDResponse, error)
}
var defaultSVC Database
func DefaultSVC() Database {
return defaultSVC
}
func SetDefaultSVC(c Database) {
defaultSVC = c
}

View File

@@ -0,0 +1,41 @@
/*
* 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 crossdatacopy
import (
"context"
"gorm.io/gorm"
"github.com/coze-dev/coze-studio/backend/domain/datacopy"
)
type DataCopy interface {
CheckAndGenCopyTask(ctx context.Context, req *datacopy.CheckAndGenCopyTaskReq) (*datacopy.CheckAndGenCopyTaskResp, error)
UpdateCopyTask(ctx context.Context, req *datacopy.UpdateCopyTaskReq) error
UpdateCopyTaskWithTX(ctx context.Context, req *datacopy.UpdateCopyTaskReq, tx *gorm.DB) error
}
var defaultSVC DataCopy
func DefaultSVC() DataCopy {
return defaultSVC
}
func SetDefaultSVC(c DataCopy) {
defaultSVC = c
}

View File

@@ -0,0 +1,40 @@
/*
* 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 crossknowledge
import (
"context"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/knowledge"
)
type Knowledge interface {
ListKnowledge(ctx context.Context, request *knowledge.ListKnowledgeRequest) (response *knowledge.ListKnowledgeResponse, err error)
GetKnowledgeByID(ctx context.Context, request *knowledge.GetKnowledgeByIDRequest) (response *knowledge.GetKnowledgeByIDResponse, err error)
Retrieve(ctx context.Context, req *knowledge.RetrieveRequest) (*knowledge.RetrieveResponse, error)
DeleteKnowledge(ctx context.Context, request *knowledge.DeleteKnowledgeRequest) error
}
var defaultSVC Knowledge
func DefaultSVC() Knowledge {
return defaultSVC
}
func SetDefaultSVC(c Knowledge) {
defaultSVC = c
}

View File

@@ -0,0 +1,41 @@
/*
* 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 crossmessage
import (
"context"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
)
type Message interface {
GetByRunIDs(ctx context.Context, conversationID int64, runIDs []int64) ([]*message.Message, error)
Create(ctx context.Context, msg *message.Message) (*message.Message, error)
Edit(ctx context.Context, msg *message.Message) (*message.Message, error)
}
var defaultSVC Message
type MessageMeta = message.Message
func DefaultSVC() Message {
return defaultSVC
}
func SetDefaultSVC(c Message) {
defaultSVC = c
}

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 crossmodelmgr
import (
"context"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/modelmgr"
)
type ModelMgr interface {
MGetModelByID(ctx context.Context, req *modelmgr.MGetModelRequest) ([]*modelmgr.Model, error)
}
type Model = modelmgr.Model
var defaultSVC ModelMgr
func DefaultSVC() ModelMgr {
return defaultSVC
}
func SetDefaultSVC(c ModelMgr) {
defaultSVC = c
}

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 crossplugin
import (
"context"
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
)
type PluginService interface {
MGetVersionPlugins(ctx context.Context, versionPlugins []model.VersionPlugin) (plugins []*model.PluginInfo, err error)
MGetPluginLatestVersion(ctx context.Context, pluginIDs []int64) (resp *model.MGetPluginLatestVersionResponse, err error)
BindAgentTools(ctx context.Context, agentID int64, toolIDs []int64) (err error)
DuplicateDraftAgentTools(ctx context.Context, fromAgentID, toAgentID int64) (err error)
MGetAgentTools(ctx context.Context, req *model.MGetAgentToolsRequest) (tools []*model.ToolInfo, err error)
ExecuteTool(ctx context.Context, req *model.ExecuteToolRequest, opts ...model.ExecuteToolOpt) (resp *model.ExecuteToolResponse, err error)
PublishAgentTools(ctx context.Context, agentID int64, agentVersion string) (err error)
DeleteDraftPlugin(ctx context.Context, PluginID int64) (err error)
PublishPlugin(ctx context.Context, req *model.PublishPluginRequest) (err error)
PublishAPPPlugins(ctx context.Context, req *model.PublishAPPPluginsRequest) (resp *model.PublishAPPPluginsResponse, err error)
GetAPPAllPlugins(ctx context.Context, appID int64) (plugins []*model.PluginInfo, err error)
MGetVersionTools(ctx context.Context, versionTools []model.VersionTool) (tools []*model.ToolInfo, err error)
}
var defaultSVC PluginService
func DefaultSVC() PluginService {
return defaultSVC
}
func SetDefaultSVC(svc PluginService) {
defaultSVC = svc
}

View File

@@ -0,0 +1,37 @@
/*
* 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 crosssearch
import (
"context"
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/search"
)
type Search interface {
SearchResources(ctx context.Context, req *model.SearchResourcesRequest) (resp *model.SearchResourcesResponse, err error)
}
var defaultSVC Search
func DefaultSVC() Search {
return defaultSVC
}
func SetDefaultSVC(svc Search) {
defaultSVC = svc
}

View File

@@ -0,0 +1,40 @@
/*
* 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 crossuser
import (
"context"
"github.com/coze-dev/coze-studio/backend/domain/user/entity"
)
type EntitySpace = entity.Space
//go:generate mockgen -destination ../../../internal/mock/crossdomain/crossuser/crossuser.go --package mockCrossUser -source crossuser.go
type User interface {
GetUserSpaceList(ctx context.Context, userID int64) (spaces []*EntitySpace, err error)
}
var defaultSVC User
func DefaultSVC() User {
return defaultSVC
}
func SetDefaultSVC(u User) {
defaultSVC = u
}

View File

@@ -0,0 +1,40 @@
/*
* 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 crossvariables
import (
"context"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/variables"
"github.com/coze-dev/coze-studio/backend/api/model/kvmemory"
)
type Variables interface {
GetVariableInstance(ctx context.Context, e *variables.UserVariableMeta, keywords []string) ([]*kvmemory.KVItem, error)
SetVariableInstance(ctx context.Context, e *variables.UserVariableMeta, items []*kvmemory.KVItem) ([]string, error)
DecryptSysUUIDKey(ctx context.Context, encryptSysUUIDKey string) *variables.UserVariableMeta
}
var defaultSVC Variables
func DefaultSVC() Variables {
return defaultSVC
}
func SetDefaultSVC(svc Variables) {
defaultSVC = svc
}

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 crossworkflow
import (
"context"
einoCompose "github.com/cloudwego/eino/compose"
"github.com/coze-dev/coze-studio/backend/domain/workflow"
workflowEntity "github.com/coze-dev/coze-studio/backend/domain/workflow/entity"
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
)
// TODO(@fanlv): 参数引用需要修改。
type Workflow interface {
WorkflowAsModelTool(ctx context.Context, policies []*vo.GetPolicy) ([]workflow.ToolFromWorkflow, error)
DeleteWorkflow(ctx context.Context, id int64) error
PublishWorkflow(ctx context.Context, info *vo.PublishPolicy) (err error)
WithResumeToolWorkflow(resumingEvent *workflowEntity.ToolInterruptEvent, resumeData string,
allInterruptEvents map[string]*workflowEntity.ToolInterruptEvent) einoCompose.Option
ReleaseApplicationWorkflows(ctx context.Context, appID int64, config *ReleaseWorkflowConfig) ([]*vo.ValidateIssue, error)
GetWorkflowIDsByAppID(ctx context.Context, appID int64) ([]int64, error)
SyncExecuteWorkflow(ctx context.Context, config vo.ExecuteConfig, input map[string]any) (*workflowEntity.WorkflowExecution, vo.TerminatePlan, error)
WithExecuteConfig(cfg vo.ExecuteConfig) einoCompose.Option
}
type ExecuteConfig = vo.ExecuteConfig
type ExecuteMode = vo.ExecuteMode
const (
ExecuteModeDebug ExecuteMode = "debug"
ExecuteModeRelease ExecuteMode = "release"
ExecuteModeNodeDebug ExecuteMode = "node_debug"
)
type TaskType = vo.TaskType
const (
TaskTypeForeground TaskType = "foreground"
TaskTypeBackground TaskType = "background"
)
type BizType = vo.BizType
const (
BizTypeAgent BizType = "agent"
BizTypeWorkflow BizType = "workflow"
)
type ReleaseWorkflowConfig = vo.ReleaseWorkflowConfig
type ToolInterruptEvent = workflowEntity.ToolInterruptEvent
var defaultSVC Workflow
func DefaultSVC() Workflow {
return defaultSVC
}
func SetDefaultSVC(svc Workflow) {
defaultSVC = svc
}