Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions adk/backend/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (

"github.com/bmatcuk/doublestar/v4"
"github.com/cloudwego/eino/adk/filesystem"
"github.com/cloudwego/eino/adk/middlewares/plantask"
"github.com/cloudwego/eino/schema"
"github.com/klippa-app/go-pdfium"
"github.com/klippa-app/go-pdfium/references"
Expand Down Expand Up @@ -910,6 +911,14 @@ func (s *Local) Write(ctx context.Context, req *filesystem.WriteRequest) error {
return nil
}

func (s *Local) Delete(ctx context.Context, req *plantask.DeleteRequest) error {
path := filepath.Clean(req.FilePath)
if err := os.Remove(path); err != nil {
return fmt.Errorf("failed to delete file %s: %w", path, err)
}
return nil
}

func (s *Local) Edit(ctx context.Context, req *filesystem.EditRequest) error {
path := filepath.Clean(req.FilePath)
if req.OldString == "" {
Expand Down
35 changes: 35 additions & 0 deletions adk/backend/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@ import (
"time"

"github.com/cloudwego/eino/adk/filesystem"
"github.com/cloudwego/eino/adk/middlewares/plantask"
"github.com/klippa-app/go-pdfium"
"github.com/klippa-app/go-pdfium/references"
"github.com/klippa-app/go-pdfium/requests"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var (
_ filesystem.Backend = (*Local)(nil)
_ plantask.Backend = (*Local)(nil)
)

func setupTestDir(t *testing.T) string {
dir, err := os.MkdirTemp("", "sandbox-test")
assert.NoError(t, err)
Expand Down Expand Up @@ -187,6 +193,35 @@ func TestWrite(t *testing.T) {
})
}

func TestDelete(t *testing.T) {
ctx := context.Background()
s, err := NewBackend(ctx, &Config{})
assert.NoError(t, err)

t.Run("delete file successfully", func(t *testing.T) {
dir := setupTestDir(t)
defer os.RemoveAll(dir)
filePath := filepath.Join(dir, "delete.txt")
assert.NoError(t, os.WriteFile(filePath, []byte("content"), 0644))

err := s.Delete(ctx, &plantask.DeleteRequest{FilePath: filePath})
assert.NoError(t, err)

_, err = os.Stat(filePath)
assert.True(t, os.IsNotExist(err))
})

t.Run("delete non-existent file", func(t *testing.T) {
dir := setupTestDir(t)
defer os.RemoveAll(dir)
filePath := filepath.Join(dir, "missing.txt")

err := s.Delete(ctx, &plantask.DeleteRequest{FilePath: filePath})
assert.Error(t, err)
assert.Contains(t, err.Error(), "failed to delete file")
})
}

func TestEdit(t *testing.T) {
ctx := context.Background()
s, err := NewBackend(ctx, &Config{})
Expand Down
Loading