feat: enhance storage engine configuration and UI updates

- Updated `.air.toml` to include additional CGO flags for improved build settings.
- Expanded `StorageEngineConfig` interface to support "tos" (火山引擎 TOS) as a new storage provider.
- Modified related components and views to accommodate the new storage engine, including updates to `ListSpaceSidebar`, `AgentList`, `KnowledgeBaseList`, and `OrganizationList`.
- Improved UI elements for batch management in the menu and sidebar components.
- Added internationalization support for new memory features and storage engine descriptions across multiple languages.

This update enhances the flexibility of storage options and improves user experience with better UI interactions.
This commit is contained in:
wizardchen
2026-02-28 15:57:09 +08:00
committed by lyingbug
parent 397689d2f3
commit 469f320d10
19 changed files with 901 additions and 292 deletions
+44 -2
View File
@@ -12,6 +12,7 @@ import (
"time"
"github.com/Tencent/WeKnora/internal/types/interfaces"
"github.com/Tencent/WeKnora/internal/utils"
"github.com/google/uuid"
"github.com/volcengine/ve-tos-golang-sdk/v2/tos"
"github.com/volcengine/ve-tos-golang-sdk/v2/tos/enum"
@@ -71,6 +72,34 @@ func NewTosFileServiceWithTempBucket(endpoint, region, accessKey, secretKey, buc
}, nil
}
// CheckConnectivity verifies TOS is reachable by performing a HeadBucket request.
func (s *tosFileService) CheckConnectivity(ctx context.Context) error {
checkCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
_, err := s.client.HeadBucket(checkCtx, &tos.HeadBucketInput{
Bucket: s.bucketName,
})
return err
}
// CheckTosConnectivity tests TOS connectivity using the provided credentials.
func CheckTosConnectivity(ctx context.Context, endpoint, region, accessKey, secretKey, bucketName string) error {
client, err := tos.NewClientV2(
endpoint,
tos.WithRegion(region),
tos.WithCredentials(tos.NewStaticCredentials(accessKey, secretKey)),
)
if err != nil {
return fmt.Errorf("failed to initialize TOS client: %w", err)
}
checkCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
_, err = client.HeadBucket(checkCtx, &tos.HeadBucketInput{
Bucket: bucketName,
})
return err
}
func ensureTOSBucket(client *tos.ClientV2, bucketName string) error {
_, err := client.HeadBucket(context.Background(), &tos.HeadBucketInput{
Bucket: bucketName,
@@ -152,7 +181,11 @@ func (s *tosFileService) SaveFile(ctx context.Context, file *multipart.FileHeade
}
func (s *tosFileService) SaveBytes(ctx context.Context, data []byte, tenantID uint64, fileName string, temp bool) (string, error) {
ext := filepath.Ext(fileName)
safeName, err := utils.SafeFileName(fileName)
if err != nil {
return "", fmt.Errorf("invalid file name: %w", err)
}
ext := filepath.Ext(safeName)
reader := bytes.NewReader(data)
targetBucket := s.bucketName
@@ -172,7 +205,7 @@ func (s *tosFileService) SaveBytes(ctx context.Context, data []byte, tenantID ui
)
}
_, err := s.client.PutObjectV2(ctx, &tos.PutObjectV2Input{
_, err = s.client.PutObjectV2(ctx, &tos.PutObjectV2Input{
PutObjectBasicInput: tos.PutObjectBasicInput{
Bucket: targetBucket,
Key: objectName,
@@ -192,6 +225,9 @@ func (s *tosFileService) GetFile(ctx context.Context, filePath string) (io.ReadC
if err != nil {
return nil, err
}
if err := utils.SafeObjectKey(objectName); err != nil {
return nil, fmt.Errorf("invalid file path: %w", err)
}
output, err := s.client.GetObjectV2(ctx, &tos.GetObjectV2Input{
Bucket: bucketName,
@@ -208,6 +244,9 @@ func (s *tosFileService) DeleteFile(ctx context.Context, filePath string) error
if err != nil {
return err
}
if err := utils.SafeObjectKey(objectName); err != nil {
return fmt.Errorf("invalid file path: %w", err)
}
_, err = s.client.DeleteObjectV2(ctx, &tos.DeleteObjectV2Input{
Bucket: bucketName,
@@ -224,6 +263,9 @@ func (s *tosFileService) GetFileURL(ctx context.Context, filePath string) (strin
if err != nil {
return "", err
}
if err := utils.SafeObjectKey(objectName); err != nil {
return "", fmt.Errorf("invalid file path: %w", err)
}
output, err := s.client.PreSignedURL(&tos.PreSignedURLInput{
HTTPMethod: enum.HttpMethodGet,