@@ -19,6 +19,8 @@ package knowledge
1919import (
2020 "context"
2121 "errors"
22+ "fmt"
23+ "strconv"
2224
2325 "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/knowledge"
2426 crossknowledge "github.com/coze-dev/coze-studio/backend/crossdomain/contract/knowledge"
@@ -27,9 +29,12 @@ import (
2729 "github.com/coze-dev/coze-studio/backend/domain/workflow/internal/canvas/convert"
2830 "github.com/coze-dev/coze-studio/backend/domain/workflow/internal/nodes"
2931 "github.com/coze-dev/coze-studio/backend/domain/workflow/internal/schema"
32+ "github.com/spf13/cast"
3033)
3134
32- type DeleterConfig struct {}
35+ type DeleterConfig struct {
36+ KnowledgeID int64
37+ }
3338
3439func (d * DeleterConfig ) Adapt (_ context.Context , n * vo.Node , _ ... nodes.AdaptOption ) (* schema.NodeSchema , error ) {
3540 ns := & schema.NodeSchema {
@@ -39,6 +44,18 @@ func (d *DeleterConfig) Adapt(_ context.Context, n *vo.Node, _ ...nodes.AdaptOpt
3944 Configs : d ,
4045 }
4146
47+ inputs := n .Data .Inputs
48+ datasetListInfoParam := inputs .DatasetParam [0 ]
49+ datasetIDs := datasetListInfoParam .Input .Value .Content .([]any )
50+ if len (datasetIDs ) == 0 {
51+ return nil , fmt .Errorf ("dataset ids is required" )
52+ }
53+ knowledgeID , err := cast .ToInt64E (datasetIDs [0 ])
54+ if err != nil {
55+ return nil , err
56+ }
57+ d .KnowledgeID = knowledgeID
58+
4259 if err := convert .SetInputsForNodeSchema (n , ns ); err != nil {
4360 return nil , err
4461 }
@@ -51,19 +68,29 @@ func (d *DeleterConfig) Adapt(_ context.Context, n *vo.Node, _ ...nodes.AdaptOpt
5168}
5269
5370func (d * DeleterConfig ) Build (_ context.Context , _ * schema.NodeSchema , _ ... schema.BuildOption ) (any , error ) {
54- return & Deleter {}, nil
71+ return & Deleter {
72+ KnowledgeID : d .KnowledgeID ,
73+ }, nil
5574}
5675
57- type Deleter struct {}
76+ type Deleter struct {
77+ KnowledgeID int64
78+ }
5879
59- func (k * Deleter ) Invoke (ctx context.Context , input map [string ]any ) (map [string ]any , error ) {
80+ func (d * Deleter ) Invoke (ctx context.Context , input map [string ]any ) (map [string ]any , error ) {
6081 documentID , ok := input ["documentID" ].(string )
6182 if ! ok {
6283 return nil , errors .New ("documentID is required and must be a string" )
6384 }
6485
86+ docID , err := strconv .ParseInt (documentID , 10 , 64 )
87+ if err != nil {
88+ return nil , fmt .Errorf ("invalid document id: %s" , documentID )
89+ }
90+
6591 req := & knowledge.DeleteDocumentRequest {
66- DocumentID : documentID ,
92+ DocumentID : docID ,
93+ KnowledgeID : d .KnowledgeID ,
6794 }
6895
6996 response , err := crossknowledge .DefaultSVC ().Delete (ctx , req )
0 commit comments