feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
50
backend/domain/workflow/crossdomain/code/code.go
Normal file
50
backend/domain/workflow/crossdomain/code/code.go
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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 code
|
||||
|
||||
import "context"
|
||||
|
||||
type Language string
|
||||
|
||||
const (
|
||||
Python Language = "Python"
|
||||
JavaScript Language = "JavaScript"
|
||||
)
|
||||
|
||||
type RunRequest struct {
|
||||
Code string
|
||||
Params map[string]any
|
||||
Language Language
|
||||
}
|
||||
type RunResponse struct {
|
||||
Result map[string]any
|
||||
}
|
||||
|
||||
func GetCodeRunner() Runner {
|
||||
return runnerImpl
|
||||
}
|
||||
|
||||
func SetCodeRunner(runner Runner) {
|
||||
runnerImpl = runner
|
||||
}
|
||||
|
||||
var runnerImpl Runner
|
||||
|
||||
//go:generate mockgen -destination ../../../../internal/mock/domain/workflow/crossdomain/code/code_mock.go --package code -source code.go
|
||||
type Runner interface {
|
||||
Run(ctx context.Context, request *RunRequest) (*RunResponse, error)
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 conversation
|
||||
|
||||
import "context"
|
||||
|
||||
type ClearMessageRequest struct {
|
||||
Name string
|
||||
}
|
||||
type ClearMessageResponse struct {
|
||||
IsSuccess bool
|
||||
}
|
||||
type CreateConversationRequest struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
type CreateConversationResponse struct {
|
||||
Result map[string]any
|
||||
}
|
||||
|
||||
type ListMessageRequest struct {
|
||||
ConversationName string
|
||||
Limit *int
|
||||
BeforeID *string
|
||||
AfterID *string
|
||||
}
|
||||
type Message struct {
|
||||
ID string `json:"id"`
|
||||
Role string `json:"role"`
|
||||
ContentType string `json:"contentType"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
type ListMessageResponse struct {
|
||||
Messages []*Message
|
||||
FirstID string
|
||||
LastID string
|
||||
HasMore bool
|
||||
}
|
||||
|
||||
var ConversationManagerImpl ConversationManager
|
||||
|
||||
type ConversationManager interface {
|
||||
ClearMessage(context.Context, *ClearMessageRequest) (*ClearMessageResponse, error)
|
||||
CreateConversation(ctx context.Context, c *CreateConversationRequest) (*CreateConversationResponse, error)
|
||||
MessageList(ctx context.Context, req *ListMessageRequest) (*ListMessageResponse, error)
|
||||
}
|
||||
143
backend/domain/workflow/crossdomain/database/database.go
Normal file
143
backend/domain/workflow/crossdomain/database/database.go
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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 database
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type SQLParam struct {
|
||||
Value string
|
||||
IsNull bool
|
||||
}
|
||||
type CustomSQLRequest struct {
|
||||
DatabaseInfoID int64
|
||||
SQL string
|
||||
Params []SQLParam
|
||||
IsDebugRun bool
|
||||
UserID int64
|
||||
}
|
||||
|
||||
type Object = map[string]any
|
||||
|
||||
type Response struct {
|
||||
RowNumber *int64
|
||||
Objects []Object
|
||||
}
|
||||
|
||||
type Operator string
|
||||
type ClauseRelation string
|
||||
|
||||
const (
|
||||
ClauseRelationAND ClauseRelation = "and"
|
||||
ClauseRelationOR ClauseRelation = "or"
|
||||
)
|
||||
|
||||
const (
|
||||
OperatorEqual Operator = "="
|
||||
OperatorNotEqual Operator = "!="
|
||||
OperatorGreater Operator = ">"
|
||||
OperatorLesser Operator = "<"
|
||||
OperatorGreaterOrEqual Operator = ">="
|
||||
OperatorLesserOrEqual Operator = "<="
|
||||
OperatorIn Operator = "in"
|
||||
OperatorNotIn Operator = "not_in"
|
||||
OperatorIsNull Operator = "is_null"
|
||||
OperatorIsNotNull Operator = "is_not_null"
|
||||
OperatorLike Operator = "like"
|
||||
OperatorNotLike Operator = "not_like"
|
||||
)
|
||||
|
||||
type ClauseGroup struct {
|
||||
Single *Clause
|
||||
Multi *MultiClause
|
||||
}
|
||||
type Clause struct {
|
||||
Left string
|
||||
Operator Operator
|
||||
}
|
||||
type MultiClause struct {
|
||||
Clauses []*Clause
|
||||
Relation ClauseRelation
|
||||
}
|
||||
|
||||
type Condition struct {
|
||||
Left string
|
||||
Operator Operator
|
||||
Right any
|
||||
}
|
||||
|
||||
type ConditionGroup struct {
|
||||
Conditions []*Condition
|
||||
Relation ClauseRelation
|
||||
}
|
||||
|
||||
type DeleteRequest struct {
|
||||
DatabaseInfoID int64
|
||||
ConditionGroup *ConditionGroup
|
||||
IsDebugRun bool
|
||||
UserID int64
|
||||
}
|
||||
|
||||
type QueryRequest struct {
|
||||
DatabaseInfoID int64
|
||||
SelectFields []string
|
||||
Limit int64
|
||||
ConditionGroup *ConditionGroup
|
||||
OrderClauses []*OrderClause
|
||||
IsDebugRun bool
|
||||
UserID int64
|
||||
}
|
||||
|
||||
type OrderClause struct {
|
||||
FieldID string
|
||||
IsAsc bool
|
||||
}
|
||||
type UpdateRequest struct {
|
||||
DatabaseInfoID int64
|
||||
ConditionGroup *ConditionGroup
|
||||
Fields map[string]any
|
||||
IsDebugRun bool
|
||||
UserID int64
|
||||
}
|
||||
|
||||
type InsertRequest struct {
|
||||
DatabaseInfoID int64
|
||||
Fields map[string]any
|
||||
IsDebugRun bool
|
||||
UserID int64
|
||||
}
|
||||
|
||||
func GetDatabaseOperator() DatabaseOperator {
|
||||
return databaseOperatorImpl
|
||||
}
|
||||
func SetDatabaseOperator(d DatabaseOperator) {
|
||||
databaseOperatorImpl = d
|
||||
}
|
||||
|
||||
var (
|
||||
databaseOperatorImpl DatabaseOperator
|
||||
)
|
||||
|
||||
//go:generate mockgen -destination databasemock/database_mock.go --package databasemock -source database.go
|
||||
type DatabaseOperator interface {
|
||||
Execute(ctx context.Context, request *CustomSQLRequest) (*Response, error)
|
||||
Query(ctx context.Context, request *QueryRequest) (*Response, error)
|
||||
Update(context.Context, *UpdateRequest) (*Response, error)
|
||||
Insert(ctx context.Context, request *InsertRequest) (*Response, error)
|
||||
Delete(context.Context, *DeleteRequest) (*Response, error)
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: database.go
|
||||
//
|
||||
// Generated by this command:
|
||||
//
|
||||
// mockgen -destination databasemock/database_mock.go --package databasemock -source database.go
|
||||
//
|
||||
|
||||
// Package databasemock is a generated GoMock package.
|
||||
package databasemock
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
database "github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/database"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
// MockDatabaseOperator is a mock of DatabaseOperator interface.
|
||||
type MockDatabaseOperator struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockDatabaseOperatorMockRecorder
|
||||
isgomock struct{}
|
||||
}
|
||||
|
||||
// MockDatabaseOperatorMockRecorder is the mock recorder for MockDatabaseOperator.
|
||||
type MockDatabaseOperatorMockRecorder struct {
|
||||
mock *MockDatabaseOperator
|
||||
}
|
||||
|
||||
// NewMockDatabaseOperator creates a new mock instance.
|
||||
func NewMockDatabaseOperator(ctrl *gomock.Controller) *MockDatabaseOperator {
|
||||
mock := &MockDatabaseOperator{ctrl: ctrl}
|
||||
mock.recorder = &MockDatabaseOperatorMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockDatabaseOperator) EXPECT() *MockDatabaseOperatorMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// Delete mocks base method.
|
||||
func (m *MockDatabaseOperator) Delete(arg0 context.Context, arg1 *database.DeleteRequest) (*database.Response, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Delete", arg0, arg1)
|
||||
ret0, _ := ret[0].(*database.Response)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// Delete indicates an expected call of Delete.
|
||||
func (mr *MockDatabaseOperatorMockRecorder) Delete(arg0, arg1 any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockDatabaseOperator)(nil).Delete), arg0, arg1)
|
||||
}
|
||||
|
||||
// Execute mocks base method.
|
||||
func (m *MockDatabaseOperator) Execute(ctx context.Context, request *database.CustomSQLRequest) (*database.Response, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Execute", ctx, request)
|
||||
ret0, _ := ret[0].(*database.Response)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// Execute indicates an expected call of Execute.
|
||||
func (mr *MockDatabaseOperatorMockRecorder) Execute(ctx, request any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Execute", reflect.TypeOf((*MockDatabaseOperator)(nil).Execute), ctx, request)
|
||||
}
|
||||
|
||||
// Insert mocks base method.
|
||||
func (m *MockDatabaseOperator) Insert(ctx context.Context, request *database.InsertRequest) (*database.Response, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Insert", ctx, request)
|
||||
ret0, _ := ret[0].(*database.Response)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// Insert indicates an expected call of Insert.
|
||||
func (mr *MockDatabaseOperatorMockRecorder) Insert(ctx, request any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Insert", reflect.TypeOf((*MockDatabaseOperator)(nil).Insert), ctx, request)
|
||||
}
|
||||
|
||||
// Query mocks base method.
|
||||
func (m *MockDatabaseOperator) Query(ctx context.Context, request *database.QueryRequest) (*database.Response, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Query", ctx, request)
|
||||
ret0, _ := ret[0].(*database.Response)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// Query indicates an expected call of Query.
|
||||
func (mr *MockDatabaseOperatorMockRecorder) Query(ctx, request any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Query", reflect.TypeOf((*MockDatabaseOperator)(nil).Query), ctx, request)
|
||||
}
|
||||
|
||||
// Update mocks base method.
|
||||
func (m *MockDatabaseOperator) Update(arg0 context.Context, arg1 *database.UpdateRequest) (*database.Response, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Update", arg0, arg1)
|
||||
ret0, _ := ret[0].(*database.Response)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// Update indicates an expected call of Update.
|
||||
func (mr *MockDatabaseOperatorMockRecorder) Update(arg0, arg1 any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockDatabaseOperator)(nil).Update), arg0, arg1)
|
||||
}
|
||||
143
backend/domain/workflow/crossdomain/knowledge/knowledge.go
Normal file
143
backend/domain/workflow/crossdomain/knowledge/knowledge.go
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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 knowledge
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/document/parser"
|
||||
)
|
||||
|
||||
type ParseMode string
|
||||
|
||||
const (
|
||||
FastParseMode = "fast_mode"
|
||||
AccurateParseMode = "accurate_mode"
|
||||
)
|
||||
|
||||
type ChunkType string
|
||||
|
||||
const (
|
||||
ChunkTypeDefault ChunkType = "default"
|
||||
ChunkTypeCustom ChunkType = "custom"
|
||||
ChunkTypeLeveled ChunkType = "leveled"
|
||||
)
|
||||
|
||||
type ParsingStrategy struct {
|
||||
ParseMode ParseMode
|
||||
ExtractImage bool
|
||||
ExtractTable bool
|
||||
ImageOCR bool
|
||||
}
|
||||
type ChunkingStrategy struct {
|
||||
ChunkType ChunkType
|
||||
ChunkSize int64
|
||||
Separator string
|
||||
Overlap int64
|
||||
}
|
||||
|
||||
type CreateDocumentRequest struct {
|
||||
KnowledgeID int64
|
||||
ParsingStrategy *ParsingStrategy
|
||||
ChunkingStrategy *ChunkingStrategy
|
||||
FileURL string
|
||||
FileName string
|
||||
FileExtension parser.FileExtension
|
||||
}
|
||||
type CreateDocumentResponse struct {
|
||||
DocumentID int64
|
||||
FileName string
|
||||
FileURL string
|
||||
}
|
||||
|
||||
type SearchType string
|
||||
|
||||
const (
|
||||
SearchTypeSemantic SearchType = "semantic" // 语义
|
||||
SearchTypeFullText SearchType = "full_text" // 全文
|
||||
SearchTypeHybrid SearchType = "hybrid" // 混合
|
||||
)
|
||||
|
||||
type RetrievalStrategy struct {
|
||||
TopK *int64
|
||||
MinScore *float64
|
||||
SearchType SearchType
|
||||
|
||||
EnableNL2SQL bool
|
||||
EnableQueryRewrite bool
|
||||
EnableRerank bool
|
||||
IsPersonalOnly bool
|
||||
}
|
||||
|
||||
type RetrieveRequest struct {
|
||||
Query string
|
||||
KnowledgeIDs []int64
|
||||
RetrievalStrategy *RetrievalStrategy
|
||||
}
|
||||
|
||||
type Slice struct {
|
||||
DocumentID string `json:"documentId"`
|
||||
Output string `json:"output"`
|
||||
}
|
||||
|
||||
type RetrieveResponse struct {
|
||||
Slices []*Slice
|
||||
}
|
||||
|
||||
var (
|
||||
knowledgeOperatorImpl KnowledgeOperator
|
||||
)
|
||||
|
||||
func GetKnowledgeOperator() KnowledgeOperator {
|
||||
return knowledgeOperatorImpl
|
||||
}
|
||||
|
||||
func SetKnowledgeOperator(k KnowledgeOperator) {
|
||||
knowledgeOperatorImpl = k
|
||||
}
|
||||
|
||||
type KnowledgeDetail struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
IconURL string `json:"-"`
|
||||
FormatType int64 `json:"-"`
|
||||
}
|
||||
|
||||
type ListKnowledgeDetailRequest struct {
|
||||
KnowledgeIDs []int64
|
||||
}
|
||||
|
||||
type ListKnowledgeDetailResponse struct {
|
||||
KnowledgeDetails []*KnowledgeDetail
|
||||
}
|
||||
|
||||
type DeleteDocumentRequest struct {
|
||||
DocumentID string
|
||||
}
|
||||
|
||||
type DeleteDocumentResponse struct {
|
||||
IsSuccess bool
|
||||
}
|
||||
|
||||
//go:generate mockgen -destination knowledgemock/knowledge_mock.go --package knowledgemock -source knowledge.go
|
||||
type KnowledgeOperator interface {
|
||||
Store(ctx context.Context, document *CreateDocumentRequest) (*CreateDocumentResponse, error)
|
||||
Retrieve(context.Context, *RetrieveRequest) (*RetrieveResponse, error)
|
||||
Delete(context.Context, *DeleteDocumentRequest) (*DeleteDocumentResponse, error)
|
||||
ListKnowledgeDetail(context.Context, *ListKnowledgeDetailRequest) (*ListKnowledgeDetailResponse, error)
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: knowledge.go
|
||||
//
|
||||
// Generated by this command:
|
||||
//
|
||||
// mockgen -destination knowledgemock/knowledge_mock.go --package knowledgemock -source knowledge.go
|
||||
//
|
||||
|
||||
// Package knowledgemock is a generated GoMock package.
|
||||
package knowledgemock
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
knowledge "github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/knowledge"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
// MockKnowledgeOperator is a mock of KnowledgeOperator interface.
|
||||
type MockKnowledgeOperator struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockKnowledgeOperatorMockRecorder
|
||||
isgomock struct{}
|
||||
}
|
||||
|
||||
// MockKnowledgeOperatorMockRecorder is the mock recorder for MockKnowledgeOperator.
|
||||
type MockKnowledgeOperatorMockRecorder struct {
|
||||
mock *MockKnowledgeOperator
|
||||
}
|
||||
|
||||
// NewMockKnowledgeOperator creates a new mock instance.
|
||||
func NewMockKnowledgeOperator(ctrl *gomock.Controller) *MockKnowledgeOperator {
|
||||
mock := &MockKnowledgeOperator{ctrl: ctrl}
|
||||
mock.recorder = &MockKnowledgeOperatorMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockKnowledgeOperator) EXPECT() *MockKnowledgeOperatorMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// Delete mocks base method.
|
||||
func (m *MockKnowledgeOperator) Delete(arg0 context.Context, arg1 *knowledge.DeleteDocumentRequest) (*knowledge.DeleteDocumentResponse, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Delete", arg0, arg1)
|
||||
ret0, _ := ret[0].(*knowledge.DeleteDocumentResponse)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// Delete indicates an expected call of Delete.
|
||||
func (mr *MockKnowledgeOperatorMockRecorder) Delete(arg0, arg1 any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockKnowledgeOperator)(nil).Delete), arg0, arg1)
|
||||
}
|
||||
|
||||
// ListKnowledgeDetail mocks base method.
|
||||
func (m *MockKnowledgeOperator) ListKnowledgeDetail(arg0 context.Context, arg1 *knowledge.ListKnowledgeDetailRequest) (*knowledge.ListKnowledgeDetailResponse, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ListKnowledgeDetail", arg0, arg1)
|
||||
ret0, _ := ret[0].(*knowledge.ListKnowledgeDetailResponse)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// ListKnowledgeDetail indicates an expected call of ListKnowledgeDetail.
|
||||
func (mr *MockKnowledgeOperatorMockRecorder) ListKnowledgeDetail(arg0, arg1 any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListKnowledgeDetail", reflect.TypeOf((*MockKnowledgeOperator)(nil).ListKnowledgeDetail), arg0, arg1)
|
||||
}
|
||||
|
||||
// Retrieve mocks base method.
|
||||
func (m *MockKnowledgeOperator) Retrieve(arg0 context.Context, arg1 *knowledge.RetrieveRequest) (*knowledge.RetrieveResponse, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Retrieve", arg0, arg1)
|
||||
ret0, _ := ret[0].(*knowledge.RetrieveResponse)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// Retrieve indicates an expected call of Retrieve.
|
||||
func (mr *MockKnowledgeOperatorMockRecorder) Retrieve(arg0, arg1 any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Retrieve", reflect.TypeOf((*MockKnowledgeOperator)(nil).Retrieve), arg0, arg1)
|
||||
}
|
||||
|
||||
// Store mocks base method.
|
||||
func (m *MockKnowledgeOperator) Store(ctx context.Context, document *knowledge.CreateDocumentRequest) (*knowledge.CreateDocumentResponse, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Store", ctx, document)
|
||||
ret0, _ := ret[0].(*knowledge.CreateDocumentResponse)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// Store indicates an expected call of Store.
|
||||
func (mr *MockKnowledgeOperatorMockRecorder) Store(ctx, document any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Store", reflect.TypeOf((*MockKnowledgeOperator)(nil).Store), ctx, document)
|
||||
}
|
||||
63
backend/domain/workflow/crossdomain/model/model.go
Normal file
63
backend/domain/workflow/crossdomain/model/model.go
Normal 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 model
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/eino/components/model"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/crossdomain/contract/crossmodelmgr"
|
||||
)
|
||||
|
||||
type LLMParams struct {
|
||||
ModelName string `json:"modelName"`
|
||||
ModelType int64 `json:"modelType"`
|
||||
Prompt string `json:"prompt"` // user prompt
|
||||
Temperature *float64 `json:"temperature"`
|
||||
FrequencyPenalty float64 `json:"frequencyPenalty"`
|
||||
PresencePenalty float64 `json:"presencePenalty"`
|
||||
MaxTokens int `json:"maxTokens"`
|
||||
TopP *float64 `json:"topP"`
|
||||
TopK *int `json:"topK"`
|
||||
EnableChatHistory bool `json:"enableChatHistory"`
|
||||
SystemPrompt string `json:"systemPrompt"`
|
||||
ResponseFormat ResponseFormat `json:"responseFormat"`
|
||||
}
|
||||
|
||||
type ResponseFormat int64
|
||||
|
||||
const (
|
||||
ResponseFormatText ResponseFormat = 0
|
||||
ResponseFormatMarkdown ResponseFormat = 1
|
||||
ResponseFormatJSON ResponseFormat = 2
|
||||
)
|
||||
|
||||
var ManagerImpl Manager
|
||||
|
||||
func GetManager() Manager {
|
||||
return ManagerImpl
|
||||
}
|
||||
|
||||
func SetManager(m Manager) {
|
||||
ManagerImpl = m
|
||||
}
|
||||
|
||||
//go:generate mockgen -destination modelmock/model_mock.go --package mockmodel -source model.go
|
||||
type Manager interface {
|
||||
GetModel(ctx context.Context, params *LLMParams) (model.BaseChatModel, *crossmodelmgr.Model, error)
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: model.go
|
||||
//
|
||||
// Generated by this command:
|
||||
//
|
||||
// mockgen -destination modelmock/model_mock.go --package mockmodel -source model.go
|
||||
//
|
||||
|
||||
// Package mockmodel is a generated GoMock package.
|
||||
package mockmodel
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
crossmodelmgr "github.com/coze-dev/coze-studio/backend/crossdomain/contract/crossmodelmgr"
|
||||
model "github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/model"
|
||||
model0 "github.com/cloudwego/eino/components/model"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
// MockManager is a mock of Manager interface.
|
||||
type MockManager struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockManagerMockRecorder
|
||||
isgomock struct{}
|
||||
}
|
||||
|
||||
// MockManagerMockRecorder is the mock recorder for MockManager.
|
||||
type MockManagerMockRecorder struct {
|
||||
mock *MockManager
|
||||
}
|
||||
|
||||
// NewMockManager creates a new mock instance.
|
||||
func NewMockManager(ctrl *gomock.Controller) *MockManager {
|
||||
mock := &MockManager{ctrl: ctrl}
|
||||
mock.recorder = &MockManagerMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockManager) EXPECT() *MockManagerMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// GetModel mocks base method.
|
||||
func (m *MockManager) GetModel(ctx context.Context, params *model.LLMParams) (model0.BaseChatModel, *crossmodelmgr.Model, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetModel", ctx, params)
|
||||
ret0, _ := ret[0].(model0.BaseChatModel)
|
||||
ret1, _ := ret[1].(*crossmodelmgr.Model)
|
||||
ret2, _ := ret[2].(error)
|
||||
return ret0, ret1, ret2
|
||||
}
|
||||
|
||||
// GetModel indicates an expected call of GetModel.
|
||||
func (mr *MockManagerMockRecorder) GetModel(ctx, params any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetModel", reflect.TypeOf((*MockManager)(nil).GetModel), ctx, params)
|
||||
}
|
||||
121
backend/domain/workflow/crossdomain/plugin/plugin.go
Normal file
121
backend/domain/workflow/crossdomain/plugin/plugin.go
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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 plugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/eino/components/tool"
|
||||
"github.com/cloudwego/eino/schema"
|
||||
|
||||
workflow3 "github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/execute"
|
||||
)
|
||||
|
||||
//go:generate mockgen -destination pluginmock/plugin_mock.go --package pluginmock -source plugin.go
|
||||
type Service interface {
|
||||
GetPluginToolsInfo(ctx context.Context, req *ToolsInfoRequest) (*ToolsInfoResponse, error)
|
||||
GetPluginInvokableTools(ctx context.Context, req *ToolsInvokableRequest) (map[int64]InvokableTool, error)
|
||||
ExecutePlugin(ctx context.Context, input map[string]any, pe *Entity,
|
||||
toolID int64, cfg ExecConfig) (map[string]any, error)
|
||||
}
|
||||
|
||||
func GetPluginService() Service {
|
||||
return pluginSrvImpl
|
||||
}
|
||||
|
||||
func SetPluginService(ts Service) {
|
||||
pluginSrvImpl = ts
|
||||
}
|
||||
|
||||
var pluginSrvImpl Service
|
||||
|
||||
type Entity = vo.PluginEntity
|
||||
|
||||
type WorkflowAPIParameters = []*workflow3.APIParameter
|
||||
type ToolsInfoRequest struct {
|
||||
PluginEntity Entity
|
||||
ToolIDs []int64
|
||||
IsDraft bool
|
||||
}
|
||||
type ToolsInvokableInfo struct {
|
||||
ToolID int64
|
||||
RequestAPIParametersConfig WorkflowAPIParameters
|
||||
ResponseAPIParametersConfig WorkflowAPIParameters
|
||||
}
|
||||
|
||||
type ToolsInvokableRequest struct {
|
||||
PluginEntity Entity
|
||||
ToolsInvokableInfo map[int64]*ToolsInvokableInfo
|
||||
IsDraft bool
|
||||
}
|
||||
|
||||
type DebugExample struct {
|
||||
ReqExample string
|
||||
RespExample string
|
||||
}
|
||||
|
||||
type ToolInfo struct {
|
||||
ToolName string
|
||||
ToolID int64
|
||||
Description string
|
||||
DebugExample *DebugExample
|
||||
|
||||
Inputs []*workflow3.APIParameter
|
||||
Outputs []*workflow3.APIParameter
|
||||
}
|
||||
|
||||
type ToolsInfoResponse struct {
|
||||
PluginID int64
|
||||
SpaceID int64
|
||||
Version string
|
||||
PluginName string
|
||||
Description string
|
||||
IconURL string
|
||||
PluginType int64
|
||||
ToolInfoList map[int64]ToolInfo
|
||||
LatestVersion *string
|
||||
IsOfficial bool
|
||||
AppID int64
|
||||
}
|
||||
|
||||
type ExecConfig = vo.ExecuteConfig
|
||||
|
||||
type InvokableTool interface {
|
||||
Info(ctx context.Context) (*schema.ToolInfo, error)
|
||||
PluginInvoke(ctx context.Context, argumentsInJSON string, cfg ExecConfig) (string, error)
|
||||
}
|
||||
|
||||
type pluginInvokableTool struct {
|
||||
pluginInvokableTool InvokableTool
|
||||
}
|
||||
|
||||
func NewInvokableTool(pl InvokableTool) tool.InvokableTool {
|
||||
return &pluginInvokableTool{
|
||||
pluginInvokableTool: pl,
|
||||
}
|
||||
}
|
||||
|
||||
func (p pluginInvokableTool) Info(ctx context.Context) (*schema.ToolInfo, error) {
|
||||
return p.pluginInvokableTool.Info(ctx)
|
||||
}
|
||||
|
||||
func (p pluginInvokableTool) InvokableRun(ctx context.Context, argumentsInJSON string, opts ...tool.Option) (string, error) {
|
||||
execCfg := execute.GetExecuteConfig(opts...)
|
||||
return p.pluginInvokableTool.PluginInvoke(ctx, argumentsInJSON, execCfg)
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: plugin.go
|
||||
//
|
||||
// Generated by this command:
|
||||
//
|
||||
// mockgen -destination pluginmock/plugin_mock.go --package pluginmock -source plugin.go
|
||||
//
|
||||
|
||||
// Package pluginmock is a generated GoMock package.
|
||||
package pluginmock
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
plugin "github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/plugin"
|
||||
schema "github.com/cloudwego/eino/schema"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
// MockService is a mock of Service interface.
|
||||
type MockService struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockServiceMockRecorder
|
||||
isgomock struct{}
|
||||
}
|
||||
|
||||
// MockServiceMockRecorder is the mock recorder for MockService.
|
||||
type MockServiceMockRecorder struct {
|
||||
mock *MockService
|
||||
}
|
||||
|
||||
// NewMockService creates a new mock instance.
|
||||
func NewMockService(ctrl *gomock.Controller) *MockService {
|
||||
mock := &MockService{ctrl: ctrl}
|
||||
mock.recorder = &MockServiceMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockService) EXPECT() *MockServiceMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// ExecutePlugin mocks base method.
|
||||
func (m *MockService) ExecutePlugin(ctx context.Context, input map[string]any, pe *plugin.Entity, toolID int64, cfg plugin.ExecConfig) (map[string]any, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ExecutePlugin", ctx, input, pe, toolID, cfg)
|
||||
ret0, _ := ret[0].(map[string]any)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// ExecutePlugin indicates an expected call of ExecutePlugin.
|
||||
func (mr *MockServiceMockRecorder) ExecutePlugin(ctx, input, pe, toolID, cfg any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExecutePlugin", reflect.TypeOf((*MockService)(nil).ExecutePlugin), ctx, input, pe, toolID, cfg)
|
||||
}
|
||||
|
||||
// GetPluginInvokableTools mocks base method.
|
||||
func (m *MockService) GetPluginInvokableTools(ctx context.Context, req *plugin.ToolsInvokableRequest) (map[int64]plugin.InvokableTool, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetPluginInvokableTools", ctx, req)
|
||||
ret0, _ := ret[0].(map[int64]plugin.InvokableTool)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetPluginInvokableTools indicates an expected call of GetPluginInvokableTools.
|
||||
func (mr *MockServiceMockRecorder) GetPluginInvokableTools(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPluginInvokableTools", reflect.TypeOf((*MockService)(nil).GetPluginInvokableTools), ctx, req)
|
||||
}
|
||||
|
||||
// GetPluginToolsInfo mocks base method.
|
||||
func (m *MockService) GetPluginToolsInfo(ctx context.Context, req *plugin.ToolsInfoRequest) (*plugin.ToolsInfoResponse, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetPluginToolsInfo", ctx, req)
|
||||
ret0, _ := ret[0].(*plugin.ToolsInfoResponse)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetPluginToolsInfo indicates an expected call of GetPluginToolsInfo.
|
||||
func (mr *MockServiceMockRecorder) GetPluginToolsInfo(ctx, req any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPluginToolsInfo", reflect.TypeOf((*MockService)(nil).GetPluginToolsInfo), ctx, req)
|
||||
}
|
||||
|
||||
// MockInvokableTool is a mock of InvokableTool interface.
|
||||
type MockInvokableTool struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockInvokableToolMockRecorder
|
||||
isgomock struct{}
|
||||
}
|
||||
|
||||
// MockInvokableToolMockRecorder is the mock recorder for MockInvokableTool.
|
||||
type MockInvokableToolMockRecorder struct {
|
||||
mock *MockInvokableTool
|
||||
}
|
||||
|
||||
// NewMockInvokableTool creates a new mock instance.
|
||||
func NewMockInvokableTool(ctrl *gomock.Controller) *MockInvokableTool {
|
||||
mock := &MockInvokableTool{ctrl: ctrl}
|
||||
mock.recorder = &MockInvokableToolMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockInvokableTool) EXPECT() *MockInvokableToolMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// Info mocks base method.
|
||||
func (m *MockInvokableTool) Info(ctx context.Context) (*schema.ToolInfo, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Info", ctx)
|
||||
ret0, _ := ret[0].(*schema.ToolInfo)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// Info indicates an expected call of Info.
|
||||
func (mr *MockInvokableToolMockRecorder) Info(ctx any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Info", reflect.TypeOf((*MockInvokableTool)(nil).Info), ctx)
|
||||
}
|
||||
|
||||
// PluginInvoke mocks base method.
|
||||
func (m *MockInvokableTool) PluginInvoke(ctx context.Context, argumentsInJSON string, cfg plugin.ExecConfig) (string, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "PluginInvoke", ctx, argumentsInJSON, cfg)
|
||||
ret0, _ := ret[0].(string)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// PluginInvoke indicates an expected call of PluginInvoke.
|
||||
func (mr *MockInvokableToolMockRecorder) PluginInvoke(ctx, argumentsInJSON, cfg any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PluginInvoke", reflect.TypeOf((*MockInvokableTool)(nil).PluginInvoke), ctx, argumentsInJSON, cfg)
|
||||
}
|
||||
66
backend/domain/workflow/crossdomain/search/search.go
Normal file
66
backend/domain/workflow/crossdomain/search/search.go
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 search
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type OpType string
|
||||
|
||||
const (
|
||||
Created OpType = "created"
|
||||
Updated OpType = "updated"
|
||||
Deleted OpType = "deleted"
|
||||
)
|
||||
|
||||
type PublishStatus int64
|
||||
|
||||
const (
|
||||
UnPublished PublishStatus = 1
|
||||
Published PublishStatus = 2
|
||||
)
|
||||
|
||||
type Resource struct {
|
||||
WorkflowID int64
|
||||
Name *string
|
||||
URI *string
|
||||
Desc *string
|
||||
APPID *int64
|
||||
SpaceID *int64
|
||||
OwnerID *int64
|
||||
PublishStatus *PublishStatus
|
||||
Mode *int32 // 0 workflow 3 chat_workflow
|
||||
CreatedAt *int64
|
||||
UpdatedAt *int64
|
||||
PublishedAt *int64
|
||||
}
|
||||
|
||||
func SetNotifier(n Notifier) {
|
||||
notifierImpl = n
|
||||
}
|
||||
|
||||
func GetNotifier() Notifier {
|
||||
return notifierImpl
|
||||
}
|
||||
|
||||
var notifierImpl Notifier
|
||||
|
||||
//go:generate mockgen -destination searchmock/search_mock.go --package searchmock -source search.go
|
||||
type Notifier interface {
|
||||
PublishWorkflowResource(ctx context.Context, OpType OpType, event *Resource) error
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: search.go
|
||||
//
|
||||
// Generated by this command:
|
||||
//
|
||||
// mockgen -destination searchmock/search_mock.go --package searchmock -source search.go
|
||||
//
|
||||
|
||||
// Package searchmock is a generated GoMock package.
|
||||
package searchmock
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
search "github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/search"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
// MockNotifier is a mock of Notifier interface.
|
||||
type MockNotifier struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockNotifierMockRecorder
|
||||
isgomock struct{}
|
||||
}
|
||||
|
||||
// MockNotifierMockRecorder is the mock recorder for MockNotifier.
|
||||
type MockNotifierMockRecorder struct {
|
||||
mock *MockNotifier
|
||||
}
|
||||
|
||||
// NewMockNotifier creates a new mock instance.
|
||||
func NewMockNotifier(ctrl *gomock.Controller) *MockNotifier {
|
||||
mock := &MockNotifier{ctrl: ctrl}
|
||||
mock.recorder = &MockNotifierMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockNotifier) EXPECT() *MockNotifierMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// PublishWorkflowResource mocks base method.
|
||||
func (m *MockNotifier) PublishWorkflowResource(ctx context.Context, OpType search.OpType, event *search.Resource) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "PublishWorkflowResource", ctx, OpType, event)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// PublishWorkflowResource indicates an expected call of PublishWorkflowResource.
|
||||
func (mr *MockNotifierMockRecorder) PublishWorkflowResource(ctx, OpType, event any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PublishWorkflowResource", reflect.TypeOf((*MockNotifier)(nil).PublishWorkflowResource), ctx, OpType, event)
|
||||
}
|
||||
124
backend/domain/workflow/crossdomain/variable/variable.go
Normal file
124
backend/domain/workflow/crossdomain/variable/variable.go
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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 variable
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/cloudwego/eino/compose"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
|
||||
)
|
||||
|
||||
var variableHandlerSingleton *Handler
|
||||
|
||||
func GetVariableHandler() *Handler {
|
||||
return variableHandlerSingleton
|
||||
}
|
||||
func SetVariableHandler(handler *Handler) {
|
||||
variableHandlerSingleton = handler
|
||||
}
|
||||
|
||||
type Handler struct {
|
||||
UserVarStore Store
|
||||
SystemVarStore Store
|
||||
AppVarStore Store
|
||||
}
|
||||
|
||||
func (v *Handler) Get(ctx context.Context, t vo.GlobalVarType, path compose.FieldPath, opts ...OptionFn) (any, error) {
|
||||
switch t {
|
||||
case vo.GlobalUser:
|
||||
return v.UserVarStore.Get(ctx, path, opts...)
|
||||
case vo.GlobalSystem:
|
||||
return v.SystemVarStore.Get(ctx, path, opts...)
|
||||
case vo.GlobalAPP:
|
||||
return v.AppVarStore.Get(ctx, path, opts...)
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown variable type: %v", t)
|
||||
}
|
||||
}
|
||||
|
||||
func (v *Handler) Set(ctx context.Context, t vo.GlobalVarType, path compose.FieldPath, value any, opts ...OptionFn) error {
|
||||
switch t {
|
||||
case vo.GlobalUser:
|
||||
return v.UserVarStore.Set(ctx, path, value, opts...)
|
||||
case vo.GlobalSystem:
|
||||
return v.SystemVarStore.Set(ctx, path, value, opts...)
|
||||
case vo.GlobalAPP:
|
||||
return v.AppVarStore.Set(ctx, path, value, opts...)
|
||||
default:
|
||||
return fmt.Errorf("unknown variable type: %v", t)
|
||||
}
|
||||
}
|
||||
|
||||
func (v *Handler) Init(ctx context.Context) context.Context {
|
||||
if v.UserVarStore != nil {
|
||||
v.UserVarStore.Init(ctx)
|
||||
}
|
||||
|
||||
if v.SystemVarStore != nil {
|
||||
v.SystemVarStore.Init(ctx)
|
||||
}
|
||||
|
||||
if v.AppVarStore != nil {
|
||||
v.AppVarStore.Init(ctx)
|
||||
}
|
||||
|
||||
return ctx
|
||||
}
|
||||
|
||||
type StoreInfo struct {
|
||||
AppID *int64
|
||||
AgentID *int64
|
||||
ConnectorID int64
|
||||
ConnectorUID string
|
||||
}
|
||||
|
||||
type StoreConfig struct {
|
||||
StoreInfo StoreInfo
|
||||
}
|
||||
|
||||
type OptionFn func(*StoreConfig)
|
||||
|
||||
func WithStoreInfo(info StoreInfo) OptionFn {
|
||||
return func(option *StoreConfig) {
|
||||
option.StoreInfo = info
|
||||
}
|
||||
}
|
||||
|
||||
//go:generate mockgen -destination varmock/var_mock.go --package mockvar -source variable.go
|
||||
type Store interface {
|
||||
Init(ctx context.Context)
|
||||
Get(ctx context.Context, path compose.FieldPath, opts ...OptionFn) (any, error)
|
||||
Set(ctx context.Context, path compose.FieldPath, value any, opts ...OptionFn) error
|
||||
}
|
||||
|
||||
var variablesMetaGetterImpl VariablesMetaGetter
|
||||
|
||||
func GetVariablesMetaGetter() VariablesMetaGetter {
|
||||
return variablesMetaGetterImpl
|
||||
}
|
||||
|
||||
func SetVariablesMetaGetter(v VariablesMetaGetter) {
|
||||
variablesMetaGetterImpl = v
|
||||
}
|
||||
|
||||
type VariablesMetaGetter interface {
|
||||
GetAppVariablesMeta(ctx context.Context, id, version string) (m map[string]*vo.TypeInfo, err error)
|
||||
GetAgentVariablesMeta(ctx context.Context, id int64, version string) (m map[string]*vo.TypeInfo, err error)
|
||||
}
|
||||
165
backend/domain/workflow/crossdomain/variable/varmock/var_mock.go
Normal file
165
backend/domain/workflow/crossdomain/variable/varmock/var_mock.go
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: variable.go
|
||||
//
|
||||
// Generated by this command:
|
||||
//
|
||||
// mockgen -destination varmock/var_mock.go --package mockvar -source variable.go
|
||||
//
|
||||
|
||||
// Package mockvar is a generated GoMock package.
|
||||
package mockvar
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
variable "github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/variable"
|
||||
vo "github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
|
||||
compose "github.com/cloudwego/eino/compose"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
// MockStore is a mock of Store interface.
|
||||
type MockStore struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockStoreMockRecorder
|
||||
isgomock struct{}
|
||||
}
|
||||
|
||||
// MockStoreMockRecorder is the mock recorder for MockStore.
|
||||
type MockStoreMockRecorder struct {
|
||||
mock *MockStore
|
||||
}
|
||||
|
||||
// NewMockStore creates a new mock instance.
|
||||
func NewMockStore(ctrl *gomock.Controller) *MockStore {
|
||||
mock := &MockStore{ctrl: ctrl}
|
||||
mock.recorder = &MockStoreMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockStore) EXPECT() *MockStoreMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// Get mocks base method.
|
||||
func (m *MockStore) Get(ctx context.Context, path compose.FieldPath, opts ...variable.OptionFn) (any, error) {
|
||||
m.ctrl.T.Helper()
|
||||
varargs := []any{ctx, path}
|
||||
for _, a := range opts {
|
||||
varargs = append(varargs, a)
|
||||
}
|
||||
ret := m.ctrl.Call(m, "Get", varargs...)
|
||||
ret0, _ := ret[0].(any)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// Get indicates an expected call of Get.
|
||||
func (mr *MockStoreMockRecorder) Get(ctx, path any, opts ...any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
varargs := append([]any{ctx, path}, opts...)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockStore)(nil).Get), varargs...)
|
||||
}
|
||||
|
||||
// Init mocks base method.
|
||||
func (m *MockStore) Init(ctx context.Context) {
|
||||
m.ctrl.T.Helper()
|
||||
m.ctrl.Call(m, "Init", ctx)
|
||||
}
|
||||
|
||||
// Init indicates an expected call of Init.
|
||||
func (mr *MockStoreMockRecorder) Init(ctx any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Init", reflect.TypeOf((*MockStore)(nil).Init), ctx)
|
||||
}
|
||||
|
||||
// Set mocks base method.
|
||||
func (m *MockStore) Set(ctx context.Context, path compose.FieldPath, value any, opts ...variable.OptionFn) error {
|
||||
m.ctrl.T.Helper()
|
||||
varargs := []any{ctx, path, value}
|
||||
for _, a := range opts {
|
||||
varargs = append(varargs, a)
|
||||
}
|
||||
ret := m.ctrl.Call(m, "Set", varargs...)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Set indicates an expected call of Set.
|
||||
func (mr *MockStoreMockRecorder) Set(ctx, path, value any, opts ...any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
varargs := append([]any{ctx, path, value}, opts...)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Set", reflect.TypeOf((*MockStore)(nil).Set), varargs...)
|
||||
}
|
||||
|
||||
// MockVariablesMetaGetter is a mock of VariablesMetaGetter interface.
|
||||
type MockVariablesMetaGetter struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockVariablesMetaGetterMockRecorder
|
||||
isgomock struct{}
|
||||
}
|
||||
|
||||
// MockVariablesMetaGetterMockRecorder is the mock recorder for MockVariablesMetaGetter.
|
||||
type MockVariablesMetaGetterMockRecorder struct {
|
||||
mock *MockVariablesMetaGetter
|
||||
}
|
||||
|
||||
// NewMockVariablesMetaGetter creates a new mock instance.
|
||||
func NewMockVariablesMetaGetter(ctrl *gomock.Controller) *MockVariablesMetaGetter {
|
||||
mock := &MockVariablesMetaGetter{ctrl: ctrl}
|
||||
mock.recorder = &MockVariablesMetaGetterMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockVariablesMetaGetter) EXPECT() *MockVariablesMetaGetterMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// GetAgentVariablesMeta mocks base method.
|
||||
func (m *MockVariablesMetaGetter) GetAgentVariablesMeta(ctx context.Context, id int64, version string) (map[string]*vo.TypeInfo, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetAgentVariablesMeta", ctx, id, version)
|
||||
ret0, _ := ret[0].(map[string]*vo.TypeInfo)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetAgentVariablesMeta indicates an expected call of GetAgentVariablesMeta.
|
||||
func (mr *MockVariablesMetaGetterMockRecorder) GetAgentVariablesMeta(ctx, id, version any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAgentVariablesMeta", reflect.TypeOf((*MockVariablesMetaGetter)(nil).GetAgentVariablesMeta), ctx, id, version)
|
||||
}
|
||||
|
||||
// GetAppVariablesMeta mocks base method.
|
||||
func (m *MockVariablesMetaGetter) GetAppVariablesMeta(ctx context.Context, id, version string) (map[string]*vo.TypeInfo, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetAppVariablesMeta", ctx, id, version)
|
||||
ret0, _ := ret[0].(map[string]*vo.TypeInfo)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetAppVariablesMeta indicates an expected call of GetAppVariablesMeta.
|
||||
func (mr *MockVariablesMetaGetterMockRecorder) GetAppVariablesMeta(ctx, id, version any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAppVariablesMeta", reflect.TypeOf((*MockVariablesMetaGetter)(nil).GetAppVariablesMeta), ctx, id, version)
|
||||
}
|
||||
Reference in New Issue
Block a user