feat(infra): use tos tagging instead meta (#1868)

main
Ryo 2 months ago committed by GitHub
parent a1da673962
commit 56ce8a0131
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      backend/api/handler/coze/workflow_service_test.go
  2. 3
      backend/application/workflow/init.go
  3. 1
      backend/crossdomain/contract/message/message.go
  4. 1
      backend/crossdomain/impl/message/message.go
  5. 5
      backend/crossdomain/impl/message/message_test.go
  6. 1
      backend/crossdomain/impl/workflow/workflow.go
  7. 3
      backend/domain/workflow/internal/canvas/adaptor/canvas_test.go
  8. 5
      backend/domain/workflow/internal/compose/test/llm_test.go
  9. 1
      backend/domain/workflow/internal/nodes/conversation/createconversation.go
  10. 2
      backend/domain/workflow/internal/nodes/conversation/createmessage.go
  11. 3
      backend/domain/workflow/internal/nodes/conversation/editmessage.go
  12. 1
      backend/domain/workflow/internal/nodes/intentdetector/prompt.go
  13. 1
      backend/domain/workflow/internal/nodes/utils.go
  14. 1
      backend/domain/workflow/internal/repo/suggest.go
  15. 1
      backend/domain/workflow/service/conversation_impl.go
  16. 1
      backend/domain/workflow/service/service_impl.go
  17. 16
      backend/infra/impl/storage/s3/s3.go
  18. 53
      backend/infra/impl/storage/tos/tos.go
  19. 31
      backend/pkg/goutil/url.go

@ -43,13 +43,14 @@ import (
"github.com/cloudwego/hertz/pkg/common/ut"
"github.com/cloudwego/hertz/pkg/protocol"
"github.com/cloudwego/hertz/pkg/protocol/sse"
"github.com/coze-dev/coze-studio/backend/domain/workflow/config"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"github.com/coze-dev/coze-studio/backend/domain/workflow/config"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/knowledge"
modelknowledge "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/knowledge"
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/modelmgr"

@ -20,9 +20,10 @@ import (
"context"
"path/filepath"
"gopkg.in/yaml.v3"
"os"
"gopkg.in/yaml.v3"
"github.com/cloudwego/eino/callbacks"
"github.com/cloudwego/eino/compose"
"gorm.io/gorm"

@ -20,6 +20,7 @@ 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/domain/conversation/message/entity"
)

@ -22,6 +22,7 @@ import (
"strconv"
"github.com/cloudwego/eino/schema"
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
crossagentrun "github.com/coze-dev/coze-studio/backend/crossdomain/contract/agentrun"
crossmessage "github.com/coze-dev/coze-studio/backend/crossdomain/contract/message"

@ -21,6 +21,9 @@ import (
"testing"
"github.com/cloudwego/eino/schema"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
crossmessage "github.com/coze-dev/coze-studio/backend/crossdomain/contract/message"
"github.com/coze-dev/coze-studio/backend/domain/conversation/message/entity"
@ -28,8 +31,6 @@ import (
"github.com/coze-dev/coze-studio/backend/infra/contract/storage"
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
"github.com/coze-dev/coze-studio/backend/pkg/sonic"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type mockWorkflowRepo struct {

@ -18,6 +18,7 @@ package workflow
import (
"context"
"github.com/cloudwego/eino/compose"
einoCompose "github.com/cloudwego/eino/compose"
"github.com/cloudwego/eino/schema"

@ -18,7 +18,6 @@ package adaptor
import (
"context"
"github.com/coze-dev/coze-studio/backend/domain/workflow/config"
"io"
"net"
"net/http"
@ -28,6 +27,8 @@ import (
"testing"
"time"
"github.com/coze-dev/coze-studio/backend/domain/workflow/config"
"github.com/bytedance/mockey"
"github.com/cloudwego/eino/schema"
"github.com/stretchr/testify/assert"

@ -31,11 +31,12 @@ import (
model2 "github.com/cloudwego/eino/components/model"
"github.com/cloudwego/eino/compose"
"github.com/cloudwego/eino/schema"
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/execute"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/execute"
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/modelmgr"
crossmodelmgr "github.com/coze-dev/coze-studio/backend/crossdomain/contract/modelmgr"
mockmodel "github.com/coze-dev/coze-studio/backend/crossdomain/contract/modelmgr/modelmock"

@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
"github.com/coze-dev/coze-studio/backend/api/model/conversation/common"
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"

@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
"github.com/coze-dev/coze-studio/backend/api/model/conversation/common"
conventity "github.com/coze-dev/coze-studio/backend/domain/conversation/conversation/entity"
@ -27,6 +28,7 @@ import (
"sync/atomic"
einoSchema "github.com/cloudwego/eino/schema"
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
crossagentrun "github.com/coze-dev/coze-studio/backend/crossdomain/contract/agentrun"

@ -20,9 +20,10 @@ import (
"context"
"errors"
"fmt"
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
"strconv"
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message"
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
"github.com/coze-dev/coze-studio/backend/crossdomain/contract/message"
crossmessage "github.com/coze-dev/coze-studio/backend/crossdomain/contract/message"

@ -19,6 +19,7 @@ package intentdetector
import (
"context"
"fmt"
"github.com/cloudwego/eino/components/prompt"
"github.com/cloudwego/eino/schema"

@ -25,6 +25,7 @@ import (
"strings"
"github.com/cloudwego/eino/compose"
crossmessage "github.com/coze-dev/coze-studio/backend/crossdomain/contract/message"
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"

@ -25,6 +25,7 @@ import (
"github.com/cloudwego/eino/compose"
einoCompose "github.com/cloudwego/eino/compose"
"github.com/cloudwego/eino/schema"
"github.com/coze-dev/coze-studio/backend/domain/workflow"
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
"github.com/coze-dev/coze-studio/backend/pkg/logs"

@ -19,6 +19,7 @@ package service
import (
"context"
"fmt"
"github.com/coze-dev/coze-studio/backend/api/model/conversation/common"
conventity "github.com/coze-dev/coze-studio/backend/domain/conversation/conversation/entity"

@ -29,6 +29,7 @@ import (
"strconv"
einoCompose "github.com/cloudwego/eino/compose"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
cloudworkflow "github.com/coze-dev/coze-studio/backend/api/model/workflow"

@ -21,7 +21,6 @@ import (
"context"
"fmt"
"io"
"net/url"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
@ -32,6 +31,7 @@ import (
"github.com/coze-dev/coze-studio/backend/infra/contract/storage"
"github.com/coze-dev/coze-studio/backend/infra/impl/storage/proxy"
"github.com/coze-dev/coze-studio/backend/pkg/goutil"
"github.com/coze-dev/coze-studio/backend/pkg/logs"
"github.com/coze-dev/coze-studio/backend/pkg/taskgroup"
)
@ -182,8 +182,7 @@ func (t *s3Client) PutObjectWithReader(ctx context.Context, objectKey string, co
}
if option.Tagging != nil {
tagging := mapToQueryParams(option.Tagging)
input.Tagging = aws.String(tagging)
input.Tagging = aws.String(goutil.MapToQuery(option.Tagging))
}
// upload object
@ -361,17 +360,6 @@ func (t *s3Client) ListObjectsPaginated(ctx context.Context, input *storage.List
return output, nil
}
func mapToQueryParams(tagging map[string]string) string {
if len(tagging) == 0 {
return ""
}
params := url.Values{}
for k, v := range tagging {
params.Set(k, v)
}
return params.Encode()
}
func tagsToMap(tags []types.Tag) map[string]string {
if len(tags) == 0 {
return nil

@ -30,8 +30,10 @@ import (
"github.com/coze-dev/coze-studio/backend/infra/contract/storage"
"github.com/coze-dev/coze-studio/backend/infra/impl/storage/proxy"
"github.com/coze-dev/coze-studio/backend/pkg/goutil"
"github.com/coze-dev/coze-studio/backend/pkg/lang/conv"
"github.com/coze-dev/coze-studio/backend/pkg/logs"
"github.com/coze-dev/coze-studio/backend/pkg/taskgroup"
)
type tosClient struct {
@ -181,7 +183,7 @@ func (t *tosClient) PutObjectWithReader(ctx context.Context, objectKey string, c
}
if len(option.Tagging) > 0 {
input.Meta = option.Tagging
input.Tagging = goutil.MapToQuery(option.Tagging)
}
_, err := client.PutObjectV2(ctx, input)
@ -277,26 +279,38 @@ func (t *tosClient) ListObjectsPaginated(ctx context.Context, input *storage.Lis
continue
}
var tagging map[string]string
if obj.Meta != nil {
obj.Meta.Range(func(key, value string) bool {
if tagging == nil {
tagging = make(map[string]string)
}
tagging[key] = value
return true
})
}
files = append(files, &storage.FileInfo{
Key: obj.Key,
LastModified: obj.LastModified,
ETag: obj.ETag,
Size: obj.Size,
Tagging: tagging,
})
}
if input.WithTagging {
client := t.client
taskGroup := taskgroup.NewTaskGroup(ctx, 5)
for idx := range files {
f := files[idx]
taskGroup.Go(func() error {
tagging, err := client.GetObjectTagging(ctx, &tos.GetObjectTaggingInput{
Bucket: t.bucketName,
Key: f.Key,
})
if err != nil {
return err
}
f.Tagging = tagsToMap(tagging.TagSet.Tags)
return nil
})
}
if err := taskGroup.Wait(); err != nil {
return nil, err
}
}
return &storage.ListObjectsPaginatedOutput{
Files: files,
Cursor: output.NextMarker,
@ -345,3 +359,16 @@ func (t *tosClient) ListAllObjects(ctx context.Context, prefix string, withTaggi
return files, nil
}
func tagsToMap(tags []tos.Tag) map[string]string {
if len(tags) == 0 {
return nil
}
m := make(map[string]string, len(tags))
for _, tag := range tags {
m[tag.Key] = tag.Value
}
return m
}

@ -0,0 +1,31 @@
/*
* 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 goutil
import "net/url"
// MapToQuery converts a map[string]string to a URL-encoded query string.
func MapToQuery(data map[string]string) string {
if len(data) == 0 {
return ""
}
params := url.Values{}
for k, v := range data {
params.Set(k, v)
}
return params.Encode()
}
Loading…
Cancel
Save