Fully autonomous AI Agents system capable of performing complex penetration testing tasks
Go ai-agentsai-security-toolanthropicautonomous-agentsgolanggptgraphqlmulti-agent-systemoffensive-securityopen-sourceopenaipenetration-testingpenetration-testing-toolsreactsecurity-automationsecurity-testingsecurity-toolsself-hosted
feat: implement flow file management with upload and retrieval capabilities
Dmitry Ng72b1c8489ed9
diff --git a/backend/cmd/installer/processor/docker.go b/backend/cmd/installer/processor/docker.goindex eb5a81d7..292b4660 100644--- a/backend/cmd/installer/processor/docker.go+++ b/backend/cmd/installer/processor/docker.go@@ -8,6 +8,8 @@ import ("path/filepath""strings"+ "pentagi/pkg/tools"+cerrdefs "github.com/containerd/errdefs""github.com/docker/docker/api/types/container""github.com/docker/docker/api/types/image"@@ -324,7 +326,7 @@ func (d *dockerOperationsImpl) removeWorkerVolumes(ctx context.Context, state *oreturn err}for _, v := range vols.Volumes {- if strings.HasPrefix(v.Name, "pentagi-terminal-") && strings.HasSuffix(v.Name, "-data") {+ if strings.HasPrefix(v.Name, tools.PrimaryTerminalNamePrefix) && strings.HasSuffix(v.Name, "-data") {_ = cli.VolumeRemove(ctx, v.Name, true)}}diff --git a/backend/pkg/flowfiles/files.go b/backend/pkg/flowfiles/files.gonew file mode 100644index 00000000..18276a93--- /dev/null+++ b/backend/pkg/flowfiles/files.go@@ -0,0 +1,543 @@+package flowfiles++import (+ "archive/tar"+ "archive/zip"+ "crypto/md5"+ "encoding/hex"+ "errors"+ "fmt"+ "io"+ "io/fs"+ "mime/multipart"+ "os"+ "path"+ "path/filepath"+ "sort"+ "strings"+ "time"+)++const (+ UploadsDirName = "uploads"+ ContainerDirName = "container"++ MaxUploadFileSize = 300 * 1024 * 1024 // 300 MB+ MaxUploadFiles = 1000 // files+ MaxUploadTotalSize = 2 * 1024 * 1024 * 1024 // 2 GB+ MaxUploadRequestSize = MaxUploadTotalSize + 64*1024*1024+ MaxPullFiles = 1000 // files+ MaxPullTotalSize = 2 * 1024 * 1024 * 1024 // 2 GB+ MaxFileNameLength = 255+)++type File struct {+ ID string+ Name string+ Path string+ Size int64+ IsDir bool+ ModifiedAt time.Time+}++type Files struct {+ Files []File+ Total uint64+}++func List(dataDir string, flowID uint64) (Files, error) {+ uploadsEntries, err := ListDirEntries(FlowUploadsDir(dataDir, flowID), UploadsDirName)+ if err != nil {+ return Files{}, fmt.Errorf("reading uploads cache: %w", err)+ }++ containerEntries, err := ListDirEntriesRecursive(FlowContainerDir(dataDir, flowID), ContainerDirName)+ if err != nil {+ return Files{}, fmt.Errorf("reading container cache: %w", err)+ }++ files := append(uploadsEntries, containerEntries...)+ Sort(files)+ return Files{+ Files: files,+ Total: uint64(len(files)),+ }, nil+}++func FlowDataDir(dataDir string, flowID uint64) string {+ return filepath.Join(dataDir, fmt.Sprintf("flow-%d-data", flowID))+}++func FlowUploadsDir(dataDir string, flowID uint64) string {+ return filepath.Join(FlowDataDir(dataDir, flowID), UploadsDirName)+}++func FlowContainerDir(dataDir string, flowID uint64) string {+ return filepath.Join(FlowDataDir(dataDir, flowID), ContainerDirName)+}++func ResolveCachedPath(dataDir string, flowID uint64, reqPath string) (string, error) {+ if strings.TrimSpace(reqPath) == "" {+ return "", errors.New("path query parameter is required")+ }++ cleaned := filepath.Clean(filepath.FromSlash(strings.ReplaceAll(reqPath, "\\", "/")))+ if filepath.IsAbs(cleaned) {+ return "", fmt.Errorf("path must be relative (no leading /)")+ }++ parts := strings.SplitN(cleaned, string(filepath.Separator), 2)+ if parts[0] != UploadsDirName && parts[0] != ContainerDirName {+ return "", fmt.Errorf("path must start with '%s' or '%s'", UploadsDirName, ContainerDirName)+ }++ flowDataDir := FlowDataDir(dataDir, flowID)+ absPath := filepath.Join(flowDataDir, cleaned)+ if !IsWithinDir(absPath, flowDataDir) {+ return "", fmt.Errorf("path escapes the flow data directory")+ }++ return absPath, nil+}++func SanitizeFileName(fileName string) (string, error) {+ trimmedName := strings.TrimSpace(fileName)+ if trimmedName == "" {+ return "", fmt.Errorf("file name is required")+ }++ normalizedName := strings.ReplaceAll(trimmedName, "\\", "/")+ cleanName := path.Base(path.Clean("/" + normalizedName))++ return validatePathComponent(cleanName)+}++func SanitizeContainerCachePath(containerPath string) (string, error) {+ trimmedPath := strings.TrimSpace(containerPath)+ if trimmedPath == "" {+ return "", fmt.Errorf("path is required")+ }++ normalizedPath := strings.ReplaceAll(trimmedPath, "\\", "/")+ cleanPath := strings.TrimPrefix(path.Clean("/"+normalizedPath), "/")+ if cleanPath == "." || cleanPath == "" {+ return "", fmt.Errorf("invalid path")+ }++ parts := strings.Split(cleanPath, "/")+ for i, part := range parts {+ cleanPart, err := validatePathComponent(part)+ if err != nil {+ return "", fmt.Errorf("invalid path component '%s': %w", part, err)+ }+ parts[i] = cleanPart+ }++ return path.Join(parts...), nil+}++func validatePathComponent(component string) (string, error) {+ cleanName := strings.TrimSpace(component)+ if cleanName == "." || cleanName == ".." || cleanName == "/" || cleanName == "" {+ return "", fmt.Errorf("invalid file name")+ }+ if len(cleanName) > MaxFileNameLength {+ return "", fmt.Errorf("file name is too long")+ }+ for _, r := range cleanName {+ if r < 0x20 || r == 0x7f {+ return "", fmt.Errorf("file name contains control characters")+ }+ switch r {+ case '/', '\\', ':', '*', '?', '"', '<', '>', '|':+ return "", fmt.Errorf("file name contains unsupported characters")+ }+ }++ return cleanName, nil+}++func NewFile(info os.FileInfo, sourceDir string) File {+ return NewFileWithPath(info, path.Join(sourceDir, info.Name()))+}++func NewFileWithPath(info os.FileInfo, filePath string) File {+ return File{+ ID: ID(filePath),+ Name: info.Name(),+ Path: filePath,+ Size: info.Size(),+ IsDir: info.IsDir(),+ ModifiedAt: info.ModTime(),+ }+}++func ID(filePath string) string {+ sum := md5.Sum([]byte(filePath))+ return hex.EncodeToString(sum[:])+}++func ListDirEntries(dir, sourceDir string) ([]File, error) {+ entries, err := os.ReadDir(dir)+ if err != nil {+ if errors.Is(err, os.ErrNotExist) {+ return nil, nil+ }+ return nil, err+ }++ files := make([]File, 0, len(entries))+ for _, entry := range entries {+ if strings.HasPrefix(entry.Name(), ".upload-") || strings.HasPrefix(entry.Name(), ".pull-") {+ continue+ }+ if entry.Type()&os.ModeSymlink != 0 {+ continue+ }++ info, err := entry.Info()+ if err != nil {+ return nil, err+ }++ if !info.Mode().IsRegular() && !info.IsDir() {+ continue+ }++ files = append(files, NewFile(info, sourceDir))+ }++ return files, nil+}++func ListDirEntriesRecursive(dir, sourceDir string) ([]File, error) {+ if _, err := os.Lstat(dir); err != nil {+ if errors.Is(err, os.ErrNotExist) {+ return nil, nil+ }+ return nil, err+ }++ var files []File+ err := filepath.WalkDir(dir, func(entryPath string, entry fs.DirEntry, err error) error {+ if err != nil {+ return err+ }+ if entryPath == dir {+ return nil+ }+ if strings.HasPrefix(entry.Name(), ".pull-") {+ if entry.IsDir() {+ return filepath.SkipDir+ }+ return nil+ }+ if entry.Type()&os.ModeSymlink != 0 {+ return nil+ }++ info, err := entry.Info()+ if err != nil {+ return err+ }+ if !info.Mode().IsRegular() && !info.IsDir() {+ return nil+ }++ rel, err := filepath.Rel(dir, entryPath)+ if err != nil {+ return fmt.Errorf("failed to resolve relative cache path: %w", err)+ }+ files = append(files, NewFileWithPath(info, path.Join(sourceDir, filepath.ToSlash(rel))))+ return nil+ })+ if err != nil {+ return nil, err+ }++ return files, nil+}++func Sort(files []File) {+ sort.Slice(files, func(i, j int) bool {+ if files[i].ModifiedAt.Equal(files[j].ModifiedAt) {+ return files[i].Name < files[j].Name+ }+ return files[i].ModifiedAt.After(files[j].ModifiedAt)+ })+}++func LocalEntryExists(filePath string) (bool, error) {+ if _, err := os.Lstat(filePath); err != nil {+ if errors.Is(err, os.ErrNotExist) {+ return false, nil+ }+ return false, err+ }++ return true, nil+}++func RegularFileInfo(filePath string) (os.FileInfo, error) {+ info, err := os.Lstat(filePath)+ if err != nil {+ return nil, err+ }+ if !info.Mode().IsRegular() {+ return nil, fmt.Errorf("'%s' is not a regular file", filePath)+ }++ return info, nil+}++func SaveUploadedFileToTemp(fh *multipart.FileHeader, dir string) (string, error) {+ src, err := fh.Open()+ if err != nil {+ return "", fmt.Errorf("failed to open uploaded file: %w", err)+ }+ defer src.Close()++ dst, err := os.CreateTemp(dir, ".upload-*")+ if err != nil {+ return "", fmt.Errorf("failed to create temporary upload file: %w", err)+ }+ tmpPath := dst.Name()+ defer dst.Close()++ if _, err := io.Copy(dst, src); err != nil {+ os.Remove(tmpPath)+ return "", fmt.Errorf("failed to write temporary upload file: %w", err)+ }+ if err := dst.Chmod(0644); err != nil {+ os.Remove(tmpPath)+ return "", fmt.Errorf("failed to set temporary upload file permissions: %w", err)+ }++ return tmpPath, nil+}++func IsWithinDir(absPath, dir string) bool {+ return strings.HasPrefix(+ filepath.Clean(absPath)+string(filepath.Separator),+ filepath.Clean(dir)+string(filepath.Separator),+ )+}++func ResolvePulledStagedTarget(stagingDir, cacheRelPath string) string {+ candidates := []string{+ filepath.Join(stagingDir, filepath.FromSlash(cacheRelPath)),+ filepath.Join(stagingDir, path.Base(cacheRelPath)),+ }++ for _, candidate := range candidates {+ if _, err := os.Lstat(candidate); err == nil {+ return candidate+ }+ }++ return ""+}++func WriteUploadsTar(w *io.PipeWriter, uploadDir string) error {+ tw := tar.NewWriter(w)+ defer w.Close()+ defer tw.Close()++ if err := tw.WriteHeader(&tar.Header{+ Typeflag: tar.TypeDir,+ Name: UploadsDirName,+ Mode: 0755,+ ModTime: time.Now(),+ }); err != nil {+ w.CloseWithError(err)+ return fmt.Errorf("failed to write uploads directory tar header: %w", err)+ }++ var filesCount int+ var totalSize int64+ return filepath.WalkDir(uploadDir, func(entryPath string, d os.DirEntry, err error) error {+ if err != nil {+ w.CloseWithError(err)+ return err+ }+ if entryPath == uploadDir {+ return nil+ }+ if d.Type()&os.ModeSymlink != 0 {+ return nil+ }++ info, err := d.Info()+ if err != nil {+ w.CloseWithError(err)+ return err+ }+ if !info.Mode().IsRegular() && !info.IsDir() {+ return nil+ }++ rel, err := filepath.Rel(uploadDir, entryPath)+ if err != nil {+ w.CloseWithError(err)+ return fmt.Errorf("failed to get upload relative path: %w", err)+ }+ headerName := path.Join(UploadsDirName, filepath.ToSlash(rel))++ if info.IsDir() {+ if err := tw.WriteHeader(&tar.Header{+ Typeflag: tar.TypeDir,+ Name: headerName,+ Mode: int64(info.Mode().Perm()),+ ModTime: info.ModTime(),+ }); err != nil {+ w.CloseWithError(err)+ return fmt.Errorf("failed to write upload directory tar header: %w", err)+ }+ return nil+ }++ filesCount+++ if filesCount > MaxUploadFiles {+ err := fmt.Errorf("uploads cache exceeds maximum file count of %d", MaxUploadFiles)+ w.CloseWithError(err)+ return err+ }+ totalSize += info.Size()+ if totalSize > MaxUploadTotalSize {+ err := fmt.Errorf("uploads cache exceeds maximum total size of %d bytes", MaxUploadTotalSize)+ w.CloseWithError(err)+ return err+ }++ if err := tw.WriteHeader(&tar.Header{+ Typeflag: tar.TypeReg,+ Name: headerName,+ Mode: int64(info.Mode().Perm()),+ Size: info.Size(),+ ModTime: info.ModTime(),+ }); err != nil {+ w.CloseWithError(err)+ return fmt.Errorf("failed to write upload file tar header: %w", err)+ }++ f, err := os.Open(entryPath)+ if err != nil {+ w.CloseWithError(err)+ return fmt.Errorf("failed to open upload file: %w", err)+ }+ defer f.Close()++ if _, err := io.Copy(tw, f); err != nil {+ w.CloseWithError(err)+ return fmt.Errorf("failed to write upload file tar content: %w", err)+ }++ return nil+ })+}++func ExtractTar(r io.Reader, destDir string) error {+ tr := tar.NewReader(r)+ var filesCount int+ var totalSize int64+ for {+ hdr, err := tr.Next()+ if err == io.EOF {+ break+ }+ if err != nil {+ return fmt.Errorf("failed to read tar entry: %w", err)+ }+ if hdr.Typeflag == tar.TypeSymlink || hdr.Typeflag == tar.TypeLink {+ continue+ }++ entryPath := filepath.Join(destDir, filepath.Clean(filepath.FromSlash(hdr.Name)))+ if !IsWithinDir(entryPath, destDir) {+ continue+ }++ switch hdr.Typeflag {+ case tar.TypeDir:+ if err := os.MkdirAll(entryPath, 0755); err != nil {+ return fmt.Errorf("failed to create directory '%s': %w", entryPath, err)+ }+ case tar.TypeReg, tar.TypeRegA:+ if hdr.Size < 0 {+ return fmt.Errorf("tar entry '%s' has invalid size %d", hdr.Name, hdr.Size)+ }+ filesCount+++ if filesCount > MaxPullFiles {+ return fmt.Errorf("tar archive exceeds maximum file count of %d", MaxPullFiles)+ }+ totalSize += hdr.Size+ if totalSize > MaxPullTotalSize {+ return fmt.Errorf("tar archive exceeds maximum total size of %d bytes", MaxPullTotalSize)+ }++ if err := os.MkdirAll(filepath.Dir(entryPath), 0755); err != nil {+ return fmt.Errorf("failed to create parent directory for '%s': %w", entryPath, err)+ }++ f, err := os.OpenFile(entryPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)+ if err != nil {+ return fmt.Errorf("failed to create file '%s': %w", entryPath, err)+ }+ _, copyErr := io.CopyN(f, tr, hdr.Size)+ f.Close()+ if copyErr != nil {+ return fmt.Errorf("failed to write file '%s': %w", entryPath, copyErr)+ }+ }+ }++ return nil+}++func ZipDirectory(w io.Writer, dirPath string) error {+ zw := zip.NewWriter(w)+ defer zw.Close()++ return filepath.WalkDir(dirPath, func(entryPath string, d fs.DirEntry, err error) error {+ if err != nil {+ return err+ }+ if d.IsDir() {+ return nil+ }+ if d.Type()&os.ModeSymlink != 0 || !d.Type().IsRegular() {+ return nil+ }++ rel, err := filepath.Rel(dirPath, entryPath)+ if err != nil {+ return fmt.Errorf("failed to get relative path: %w", err)+ }++ info, err := d.Info()+ if err != nil {+ return fmt.Errorf("failed to get file info: %w", err)+ }++ header, err := zip.FileInfoHeader(info)+ if err != nil {+ return fmt.Errorf("failed to create zip header: %w", err)+ }+ header.Name = filepath.ToSlash(rel)+ header.Method = zip.Deflate++ zf, err := zw.CreateHeader(header)+ if err != nil {+ return fmt.Errorf("failed to create zip entry: %w", err)+ }++ f, err := os.Open(entryPath)+ if err != nil {+ return fmt.Errorf("failed to open file for zip: %w", err)+ }+ defer f.Close()++ _, err = io.Copy(zf, f)+ return err+ })+}diff --git a/backend/pkg/flowfiles/files_test.go b/backend/pkg/flowfiles/files_test.gonew file mode 100644index 00000000..c2ad696d--- /dev/null+++ b/backend/pkg/flowfiles/files_test.go@@ -0,0 +1,457 @@+package flowfiles++import (+ "archive/tar"+ "archive/zip"+ "bytes"+ "io"+ "mime/multipart"+ "net/http/httptest"+ "os"+ "path/filepath"+ "strconv"+ "testing"+ "time"++ "github.com/stretchr/testify/assert"+ "github.com/stretchr/testify/require"+)++type tarTestEntry struct {+ name string+ typeflag byte+ content string+ linkname string+}++func buildTar(t *testing.T, entries []tarTestEntry) *bytes.Buffer {+ t.Helper()++ var buf bytes.Buffer+ tw := tar.NewWriter(&buf)+ for _, entry := range entries {+ hdr := &tar.Header{+ Name: entry.name,+ Typeflag: entry.typeflag,+ Mode: 0644,+ Size: int64(len(entry.content)),+ Linkname: entry.linkname,+ }+ if entry.typeflag == tar.TypeDir {+ hdr.Mode = 0755+ }+ require.NoError(t, tw.WriteHeader(hdr))+ if len(entry.content) > 0 {+ _, _ = tw.Write([]byte(entry.content))+ }+ }+ require.NoError(t, tw.Close())+ return &buf+}++func TestFlowDirs(t *testing.T) {+ assert.Equal(t, "/data/flow-42-data", FlowDataDir("/data", 42))+ assert.Equal(t, "/data/flow-42-data/uploads", FlowUploadsDir("/data", 42))+ assert.Equal(t, "/data/flow-42-data/container", FlowContainerDir("/data", 42))+}++func TestSanitizeFileName(t *testing.T) {+ tests := []struct {+ name string+ input string+ expected string+ wantErr bool+ }{+ {"plain name", "report.txt", "report.txt", false},+ {"strips parent traversal", "../report.txt", "report.txt", false},+ {"normalizes windows separators", `nested\brief.md`, "brief.md", false},+ {"strips absolute path", "/etc/passwd", "passwd", false},+ {"strips deep traversal", "../../etc/shadow", "shadow", false},+ {"trims whitespace", " wordlist.txt ", "wordlist.txt", false},+ {"rejects empty", " ", "", true},+ {"rejects dot-only", ".", "", true},+ {"rejects root slash", "/", "", true},+ {"rejects control characters", "bad\nname.txt", "", true},+ {"rejects unsupported header characters", `bad"name.txt`, "", true},+ {"rejects too long", string(bytes.Repeat([]byte("a"), MaxFileNameLength+1)), "", true},+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ got, err := SanitizeFileName(tt.input)+ if tt.wantErr {+ require.Error(t, err)+ return+ }+ require.NoError(t, err)+ assert.Equal(t, tt.expected, got)+ })+ }+}++func TestSanitizeContainerCachePath(t *testing.T) {+ tests := []struct {+ name string+ input string+ expected string+ wantErr bool+ }{+ {"absolute directory", "/etc/nginx/conf/", "etc/nginx/conf", false},+ {"absolute file", "/etc/nginx/nginx.conf", "etc/nginx/nginx.conf", false},+ {"relative file", "var/log/app.log", "var/log/app.log", false},+ {"normalizes traversal", "../../etc/shadow", "etc/shadow", false},+ {"normalizes windows separators", `etc\nginx\nginx.conf`, "etc/nginx/nginx.conf", false},+ {"rejects empty", " ", "", true},+ {"rejects root", "/", "", true},+ {"rejects bad component", "/etc/bad\nname", "", true},+ {"rejects unsupported component", `/etc/bad"name`, "", true},+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ got, err := SanitizeContainerCachePath(tt.input)+ if tt.wantErr {+ require.Error(t, err)+ return+ }+ require.NoError(t, err)+ assert.Equal(t, tt.expected, got)+ })+ }+}++func TestResolveCachedPath(t *testing.T) {+ tests := []struct {+ name string+ input string+ want string+ wantErr bool+ }{+ {"uploads file", "uploads/report.txt", "/data/flow-1-data/uploads/report.txt", false},+ {"container file", "container/etc/nginx/nginx.conf", "/data/flow-1-data/container/etc/nginx/nginx.conf", false},+ {"container windows separators", `container\etc\nginx.conf`, "/data/flow-1-data/container/etc/nginx.conf", false},+ {"empty path", "", "", true},+ {"wrong prefix", "tmp/evil.sh", "", true},+ {"absolute path", "/etc/passwd", "", true},+ {"path traversal", "uploads/../../etc/passwd", "", true},+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ got, err := ResolveCachedPath("/data", 1, tt.input)+ if tt.wantErr {+ require.Error(t, err)+ return+ }+ require.NoError(t, err)+ assert.Equal(t, tt.want, got)+ })+ }+}++func TestListDirEntries(t *testing.T) {+ dir := t.TempDir()+ require.NoError(t, os.WriteFile(filepath.Join(dir, "a.txt"), []byte("a"), 0644))+ require.NoError(t, os.Mkdir(filepath.Join(dir, "sub"), 0755))+ require.NoError(t, os.WriteFile(filepath.Join(dir, ".upload-temp"), []byte("tmp"), 0644))+ require.NoError(t, os.Mkdir(filepath.Join(dir, ".pull-temp"), 0755))+ if err := os.Symlink(filepath.Join(dir, "a.txt"), filepath.Join(dir, "link.txt")); err != nil {+ t.Skipf("symlink creation not available: %v", err)+ }++ entries, err := ListDirEntries(dir, UploadsDirName)+ require.NoError(t, err)+ require.Len(t, entries, 2)++ paths := make([]string, len(entries))+ for i, entry := range entries {+ paths[i] = entry.Path+ }+ assert.Contains(t, paths, "uploads/a.txt")+ assert.Contains(t, paths, "uploads/sub")+ assert.NotContains(t, paths, "uploads/.upload-temp")+ assert.NotContains(t, paths, "uploads/.pull-temp")+ assert.NotContains(t, paths, "uploads/link.txt")+}++func TestListDirEntriesMissingDir(t *testing.T) {+ entries, err := ListDirEntries(filepath.Join(t.TempDir(), "missing"), UploadsDirName)+ require.NoError(t, err)+ assert.Empty(t, entries)++ entries, err = ListDirEntriesRecursive(filepath.Join(t.TempDir(), "missing"), ContainerDirName)+ require.NoError(t, err)+ assert.Empty(t, entries)+}++func TestListDirEntriesRecursivePreservesNestedPaths(t *testing.T) {+ dir := t.TempDir()+ require.NoError(t, os.MkdirAll(filepath.Join(dir, "etc", "nginx", "conf"), 0755))+ require.NoError(t, os.WriteFile(filepath.Join(dir, "etc", "nginx", "nginx.conf"), []byte("nginx"), 0644))+ require.NoError(t, os.Mkdir(filepath.Join(dir, ".pull-temp"), 0755))+ require.NoError(t, os.WriteFile(filepath.Join(dir, ".pull-temp", "tmp.txt"), []byte("tmp"), 0644))++ entries, err := ListDirEntriesRecursive(dir, ContainerDirName)+ require.NoError(t, err)++ paths := make([]string, len(entries))+ for i, entry := range entries {+ paths[i] = entry.Path+ }+ assert.Contains(t, paths, "container/etc")+ assert.Contains(t, paths, "container/etc/nginx")+ assert.Contains(t, paths, "container/etc/nginx/conf")+ assert.Contains(t, paths, "container/etc/nginx/nginx.conf")+ assert.NotContains(t, paths, "container/.pull-temp")+ assert.NotContains(t, paths, "container/.pull-temp/tmp.txt")+}++func TestListBothSources(t *testing.T) {+ dataDir := t.TempDir()+ uploadsDir := FlowUploadsDir(dataDir, 7)+ containerDir := FlowContainerDir(dataDir, 7)+ require.NoError(t, os.MkdirAll(uploadsDir, 0755))+ require.NoError(t, os.MkdirAll(filepath.Join(containerDir, "etc", "nginx", "conf"), 0755))++ require.NoError(t, os.WriteFile(filepath.Join(uploadsDir, "wordlist.txt"), []byte("words"), 0644))+ require.NoError(t, os.WriteFile(filepath.Join(containerDir, "etc", "nginx", "nginx.conf"), []byte("nginx"), 0644))++ files, err := List(dataDir, 7)+ require.NoError(t, err)+ assert.Equal(t, uint64(len(files.Files)), files.Total)++ paths := make([]string, len(files.Files))+ for i, file := range files.Files {+ paths[i] = file.Path+ }+ assert.Contains(t, paths, "uploads/wordlist.txt")+ assert.Contains(t, paths, "container/etc/nginx/conf")+ assert.Contains(t, paths, "container/etc/nginx/nginx.conf")+}++func TestLocalEntryExistsAndRegularFileInfo(t *testing.T) {+ dir := t.TempDir()+ filePath := filepath.Join(dir, "f.txt")++ exists, err := LocalEntryExists(filePath)+ require.NoError(t, err)+ assert.False(t, exists)++ require.NoError(t, os.WriteFile(filePath, []byte("x"), 0644))++ exists, err = LocalEntryExists(filePath)+ require.NoError(t, err)+ assert.True(t, exists)++ info, err := RegularFileInfo(filePath)+ require.NoError(t, err)+ assert.Equal(t, "f.txt", info.Name())++ _, err = RegularFileInfo(dir)+ require.Error(t, err)+}++func TestSaveUploadedFileToTemp(t *testing.T) {+ var body bytes.Buffer+ writer := multipart.NewWriter(&body)+ part, err := writer.CreateFormFile("file", "report.txt")+ require.NoError(t, err)+ _, err = part.Write([]byte("payload"))+ require.NoError(t, err)+ require.NoError(t, writer.Close())++ req := httptest.NewRequest("POST", "/", &body)+ req.Header.Set("Content-Type", writer.FormDataContentType())+ require.NoError(t, req.ParseMultipartForm(1024))+ fh := req.MultipartForm.File["file"][0]++ tmpPath, err := SaveUploadedFileToTemp(fh, t.TempDir())+ require.NoError(t, err)++ data, err := os.ReadFile(tmpPath)+ require.NoError(t, err)+ assert.Equal(t, "payload", string(data))+}++func TestIsWithinDir(t *testing.T) {+ assert.True(t, IsWithinDir("/data/flow-1/uploads/file.txt", "/data/flow-1/uploads"))+ assert.True(t, IsWithinDir("/data/flow-1/uploads/sub/file.txt", "/data/flow-1/uploads"))+ assert.False(t, IsWithinDir("/data/flow-1/../evil.txt", "/data/flow-1/uploads"))+ assert.False(t, IsWithinDir("/data/flow-2/uploads/file.txt", "/data/flow-1/uploads"))+}++func TestResolvePulledStagedTarget(t *testing.T) {+ t.Run("full cache path archive", func(t *testing.T) {+ stagingDir := t.TempDir()+ target := filepath.Join(stagingDir, "etc", "nginx", "nginx.conf")+ require.NoError(t, os.MkdirAll(filepath.Dir(target), 0755))+ require.NoError(t, os.WriteFile(target, []byte("nginx"), 0644))++ assert.Equal(t, target, ResolvePulledStagedTarget(stagingDir, "etc/nginx/nginx.conf"))+ })++ t.Run("basename archive", func(t *testing.T) {+ stagingDir := t.TempDir()+ target := filepath.Join(stagingDir, "nginx.conf")+ require.NoError(t, os.WriteFile(target, []byte("nginx"), 0644))++ assert.Equal(t, target, ResolvePulledStagedTarget(stagingDir, "etc/nginx/nginx.conf"))+ })+}++func TestWriteUploadsTar(t *testing.T) {+ uploadDir := t.TempDir()+ require.NoError(t, os.WriteFile(filepath.Join(uploadDir, "a.txt"), []byte("alpha"), 0644))+ require.NoError(t, os.Mkdir(filepath.Join(uploadDir, "sub"), 0755))+ require.NoError(t, os.WriteFile(filepath.Join(uploadDir, "sub", "b.txt"), []byte("bravo"), 0644))+ if err := os.Symlink(filepath.Join(uploadDir, "a.txt"), filepath.Join(uploadDir, "link.txt")); err != nil {+ t.Skipf("symlink creation not available: %v", err)+ }++ pr, pw := io.Pipe()+ errCh := make(chan error, 1)+ go func() {+ errCh <- WriteUploadsTar(pw, uploadDir)+ }()++ var buf bytes.Buffer+ _, err := io.Copy(&buf, pr)+ require.NoError(t, err)+ require.NoError(t, <-errCh)++ tr := tar.NewReader(bytes.NewReader(buf.Bytes()))+ contents := map[string]string{}+ for {+ hdr, err := tr.Next()+ if err == io.EOF {+ break+ }+ require.NoError(t, err)+ if hdr.Typeflag != tar.TypeReg {+ continue+ }+ data, err := io.ReadAll(tr)+ require.NoError(t, err)+ contents[hdr.Name] = string(data)+ }++ assert.Equal(t, "alpha", contents["uploads/a.txt"])+ assert.Equal(t, "bravo", contents["uploads/sub/b.txt"])+ assert.NotContains(t, contents, "uploads/link.txt")+}++func TestExtractTarRegularFiles(t *testing.T) {+ destDir := t.TempDir()+ buf := buildTar(t, []tarTestEntry{+ {name: "dir/", typeflag: tar.TypeDir},+ {name: "dir/file.txt", typeflag: tar.TypeReg, content: "hello"},+ })++ require.NoError(t, ExtractTar(buf, destDir))++ data, err := os.ReadFile(filepath.Join(destDir, "dir", "file.txt"))+ require.NoError(t, err)+ assert.Equal(t, "hello", string(data))+}++func TestExtractTarSkipsSymlinks(t *testing.T) {+ destDir := t.TempDir()+ buf := buildTar(t, []tarTestEntry{+ {name: "link.txt", typeflag: tar.TypeSymlink, linkname: "/etc/passwd"},+ })++ require.NoError(t, ExtractTar(buf, destDir))++ _, err := os.Lstat(filepath.Join(destDir, "link.txt"))+ assert.True(t, os.IsNotExist(err), "symlink must not be created in cache")+}++func TestExtractTarSkipsPathTraversal(t *testing.T) {+ destDir := t.TempDir()+ buf := buildTar(t, []tarTestEntry{+ {name: "../../evil.txt", typeflag: tar.TypeReg, content: "evil"},+ })++ require.NoError(t, ExtractTar(buf, destDir))++ evilPath := filepath.Join(filepath.Dir(destDir), "evil.txt")+ _, err := os.Lstat(evilPath)+ assert.True(t, os.IsNotExist(err), "path traversal file must not be created")+}++func TestExtractTarRejectsTooManyFiles(t *testing.T) {+ destDir := t.TempDir()+ entries := make([]tarTestEntry, 0, MaxPullFiles+1)+ for i := 0; i < MaxPullFiles+1; i++ {+ entries = append(entries, tarTestEntry{+ name: filepath.Join("many", "file-"+strconv.Itoa(i)+".txt"),+ typeflag: tar.TypeReg,+ content: "x",+ })+ }++ err := ExtractTar(buildTar(t, entries), destDir)+ require.Error(t, err)+ assert.Contains(t, err.Error(), "maximum file count")+}++func TestZipDirectory(t *testing.T) {+ src := t.TempDir()+ require.NoError(t, os.WriteFile(filepath.Join(src, "a.txt"), []byte("hello"), 0644))+ require.NoError(t, os.MkdirAll(filepath.Join(src, "sub"), 0755))+ require.NoError(t, os.WriteFile(filepath.Join(src, "sub", "b.txt"), []byte("world"), 0644))++ var buf bytes.Buffer+ require.NoError(t, ZipDirectory(&buf, src))++ zr, err := zip.NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()))+ require.NoError(t, err)++ contents := make(map[string]string)+ for _, f := range zr.File {+ rc, err := f.Open()+ require.NoError(t, err)+ data, _ := io.ReadAll(rc)+ rc.Close()+ contents[f.Name] = string(data)+ }+ assert.Equal(t, "hello", contents["a.txt"])+ assert.Equal(t, "world", contents["sub/b.txt"])+}++func TestZipDirectoryExcludesSymlinks(t *testing.T) {+ src := t.TempDir()+ target := filepath.Join(src, "real.txt")+ link := filepath.Join(src, "link.txt")+ require.NoError(t, os.WriteFile(target, []byte("real"), 0644))+ if err := os.Symlink(target, link); err != nil {+ t.Skipf("symlink creation not available: %v", err)+ }++ var buf bytes.Buffer+ require.NoError(t, ZipDirectory(&buf, src))++ zr, err := zip.NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()))+ require.NoError(t, err)++ names := make([]string, len(zr.File))+ for i, f := range zr.File {+ names[i] = f.Name+ }+ assert.Contains(t, names, "real.txt")+ assert.NotContains(t, names, "link.txt")+}++func TestSort(t *testing.T) {+ now := time.Now()+ files := []File{+ {Name: "b.txt", ModifiedAt: now.Add(-2 * time.Hour)},+ {Name: "a.txt", ModifiedAt: now.Add(-1 * time.Hour)},+ {Name: "c.txt", ModifiedAt: now.Add(-1 * time.Hour)},+ }+ Sort(files)++ assert.Equal(t, "a.txt", files[0].Name)+ assert.Equal(t, "c.txt", files[1].Name)+ assert.Equal(t, "b.txt", files[2].Name)+}diff --git a/backend/pkg/graph/context.go b/backend/pkg/graph/context.goindex 4d17ed5f..90c97b18 100644--- a/backend/pkg/graph/context.go+++ b/backend/pkg/graph/context.go@@ -8,6 +8,8 @@ import ("slices""pentagi/pkg/database"+ "pentagi/pkg/flowfiles"+ "pentagi/pkg/graph/model")// This file will not be regenerated automatically.@@ -120,3 +122,23 @@ func validatePermissionWithFlowID(return uid, nil}++func convertFlowFiles(files flowfiles.Files) []*model.FlowFile {+ converted := make([]*model.FlowFile, 0, len(files.Files))+ for _, file := range files.Files {+ converted = append(converted, convertFlowFile(file))+ }++ return converted+}++func convertFlowFile(file flowfiles.File) *model.FlowFile {+ return &model.FlowFile{+ ID: file.ID,+ Name: file.Name,+ Path: file.Path,+ Size: int(file.Size),+ IsDir: file.IsDir,+ ModifiedAt: file.ModifiedAt,+ }+}diff --git a/backend/pkg/graph/generated.go b/backend/pkg/graph/generated.goindex 9e41b679..2d9d10d3 100644--- a/backend/pkg/graph/generated.go+++ b/backend/pkg/graph/generated.go@@ -241,6 +241,15 @@ type ComplexityRoot struct {TotalToolcallsCount func(childComplexity int) int}+ FlowFile struct {+ ID func(childComplexity int) int+ IsDir func(childComplexity int) int+ ModifiedAt func(childComplexity int) int+ Name func(childComplexity int) int+ Path func(childComplexity int) int+ Size func(childComplexity int) int+ }+FlowStats struct {TotalAssistantsCount func(childComplexity int) intTotalSubtasksCount func(childComplexity int) int@@ -430,6 +439,7 @@ type ComplexityRoot struct {AssistantLogs func(childComplexity int, flowID int64, assistantID int64) intAssistants func(childComplexity int, flowID int64) intFlow func(childComplexity int, flowID int64) int+ FlowFiles func(childComplexity int, flowID int64) intFlowStatsByFlow func(childComplexity int, flowID int64) intFlowTemplate func(childComplexity int, templateID int64) intFlowTemplates func(childComplexity int) int@@ -510,6 +520,9 @@ type ComplexityRoot struct {AssistantUpdated func(childComplexity int, flowID int64) intFlowCreated func(childComplexity int) intFlowDeleted func(childComplexity int) int+ FlowFileAdded func(childComplexity int, flowID int64) int+ FlowFileDeleted func(childComplexity int, flowID int64) int+ FlowFileUpdated func(childComplexity int, flowID int64) intFlowTemplateCreated func(childComplexity int) intFlowTemplateDeleted func(childComplexity int) intFlowTemplateUpdated func(childComplexity int) int@@ -688,6 +701,7 @@ type QueryResolver interface {Flows(ctx context.Context) ([]*model.Flow, error)Flow(ctx context.Context, flowID int64) (*model.Flow, error)Tasks(ctx context.Context, flowID int64) ([]*model.Task, error)+ FlowFiles(ctx context.Context, flowID int64) ([]*model.FlowFile, error)Screenshots(ctx context.Context, flowID int64) ([]*model.Screenshot, error)TerminalLogs(ctx context.Context, flowID int64) ([]*model.TerminalLog, error)MessageLogs(ctx context.Context, flowID int64) ([]*model.MessageLog, error)@@ -730,6 +744,9 @@ type SubscriptionResolver interface {AssistantCreated(ctx context.Context, flowID int64) (<-chan *model.Assistant, error)AssistantUpdated(ctx context.Context, flowID int64) (<-chan *model.Assistant, error)AssistantDeleted(ctx context.Context, flowID int64) (<-chan *model.Assistant, error)+ FlowFileAdded(ctx context.Context, flowID int64) (<-chan *model.FlowFile, error)+ FlowFileUpdated(ctx context.Context, flowID int64) (<-chan *model.FlowFile, error)+ FlowFileDeleted(ctx context.Context, flowID int64) (<-chan *model.FlowFile, error)ScreenshotAdded(ctx context.Context, flowID int64) (<-chan *model.Screenshot, error)TerminalLogAdded(ctx context.Context, flowID int64) (<-chan *model.TerminalLog, error)MessageLogAdded(ctx context.Context, flowID int64) (<-chan *model.MessageLog, error)@@ -1666,6 +1683,48 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity inreturn e.complexity.FlowExecutionStats.TotalToolcallsCount(childComplexity), true+ case "FlowFile.id":+ if e.complexity.FlowFile.ID == nil {+ break+ }++ return e.complexity.FlowFile.ID(childComplexity), true++ case "FlowFile.isDir":+ if e.complexity.FlowFile.IsDir == nil {+ break+ }++ return e.complexity.FlowFile.IsDir(childComplexity), true++ case "FlowFile.modifiedAt":+ if e.complexity.FlowFile.ModifiedAt == nil {+ break+ }++ return e.complexity.FlowFile.ModifiedAt(childComplexity), true++ case "FlowFile.name":+ if e.complexity.FlowFile.Name == nil {+ break+ }++ return e.complexity.FlowFile.Name(childComplexity), true++ case "FlowFile.path":+ if e.complexity.FlowFile.Path == nil {+ break+ }++ return e.complexity.FlowFile.Path(childComplexity), true++ case "FlowFile.size":+ if e.complexity.FlowFile.Size == nil {+ break+ }++ return e.complexity.FlowFile.Size(childComplexity), true+case "FlowStats.totalAssistantsCount":if e.complexity.FlowStats.TotalAssistantsCount == nil {break@@ -2743,6 +2802,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity inreturn e.complexity.Query.Flow(childComplexity, args["flowId"].(int64)), true+ case "Query.flowFiles":+ if e.complexity.Query.FlowFiles == nil {+ break+ }++ args, err := ec.field_Query_flowFiles_args(context.TODO(), rawArgs)+ if err != nil {+ return 0, false+ }++ return e.complexity.Query.FlowFiles(childComplexity, args["flowId"].(int64)), true+case "Query.flowStatsByFlow":if e.complexity.Query.FlowStatsByFlow == nil {break@@ -3313,6 +3384,42 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity inreturn e.complexity.Subscription.FlowDeleted(childComplexity), true+ case "Subscription.flowFileAdded":+ if e.complexity.Subscription.FlowFileAdded == nil {+ break+ }++ args, err := ec.field_Subscription_flowFileAdded_args(context.TODO(), rawArgs)+ if err != nil {+ return 0, false+ }++ return e.complexity.Subscription.FlowFileAdded(childComplexity, args["flowId"].(int64)), true++ case "Subscription.flowFileDeleted":+ if e.complexity.Subscription.FlowFileDeleted == nil {+ break+ }++ args, err := ec.field_Subscription_flowFileDeleted_args(context.TODO(), rawArgs)+ if err != nil {+ return 0, false+ }++ return e.complexity.Subscription.FlowFileDeleted(childComplexity, args["flowId"].(int64)), true++ case "Subscription.flowFileUpdated":+ if e.complexity.Subscription.FlowFileUpdated == nil {+ break+ }++ args, err := ec.field_Subscription_flowFileUpdated_args(context.TODO(), rawArgs)+ if err != nil {+ return 0, false+ }++ return e.complexity.Subscription.FlowFileUpdated(childComplexity, args["flowId"].(int64)), true+case "Subscription.flowTemplateCreated":if e.complexity.Subscription.FlowTemplateCreated == nil {break@@ -5908,6 +6015,38 @@ func (ec *executionContext) field_Query_assistants_argsFlowID(return zeroVal, nil}+func (ec *executionContext) field_Query_flowFiles_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {+ var err error+ args := map[string]interface{}{}+ arg0, err := ec.field_Query_flowFiles_argsFlowID(ctx, rawArgs)+ if err != nil {+ return nil, err+ }+ args["flowId"] = arg0+ return args, nil+}+func (ec *executionContext) field_Query_flowFiles_argsFlowID(+ ctx context.Context,+ rawArgs map[string]interface{},+) (int64, error) {+ // We won't call the directive if the argument is null.+ // Set call_argument_directives_with_null to true to call directives+ // even if the argument is null.+ _, ok := rawArgs["flowId"]+ if !ok {+ var zeroVal int64+ return zeroVal, nil+ }++ ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("flowId"))+ if tmp, ok := rawArgs["flowId"]; ok {+ return ec.unmarshalNID2int64(ctx, tmp)+ }++ var zeroVal int64+ return zeroVal, nil+}+func (ec *executionContext) field_Query_flowStatsByFlow_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {var err errorargs := map[string]interface{}{}@@ -6676,6 +6815,102 @@ func (ec *executionContext) field_Subscription_assistantUpdated_argsFlowID(return zeroVal, nil}+func (ec *executionContext) field_Subscription_flowFileAdded_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {+ var err error+ args := map[string]interface{}{}+ arg0, err := ec.field_Subscription_flowFileAdded_argsFlowID(ctx, rawArgs)+ if err != nil {+ return nil, err+ }+ args["flowId"] = arg0+ return args, nil+}+func (ec *executionContext) field_Subscription_flowFileAdded_argsFlowID(+ ctx context.Context,+ rawArgs map[string]interface{},+) (int64, error) {+ // We won't call the directive if the argument is null.+ // Set call_argument_directives_with_null to true to call directives+ // even if the argument is null.+ _, ok := rawArgs["flowId"]+ if !ok {+ var zeroVal int64+ return zeroVal, nil+ }++ ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("flowId"))+ if tmp, ok := rawArgs["flowId"]; ok {+ return ec.unmarshalNID2int64(ctx, tmp)+ }++ var zeroVal int64+ return zeroVal, nil+}++func (ec *executionContext) field_Subscription_flowFileDeleted_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {+ var err error+ args := map[string]interface{}{}+ arg0, err := ec.field_Subscription_flowFileDeleted_argsFlowID(ctx, rawArgs)+ if err != nil {+ return nil, err+ }+ args["flowId"] = arg0+ return args, nil+}+func (ec *executionContext) field_Subscription_flowFileDeleted_argsFlowID(+ ctx context.Context,+ rawArgs map[string]interface{},+) (int64, error) {+ // We won't call the directive if the argument is null.+ // Set call_argument_directives_with_null to true to call directives+ // even if the argument is null.+ _, ok := rawArgs["flowId"]+ if !ok {+ var zeroVal int64+ return zeroVal, nil+ }++ ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("flowId"))+ if tmp, ok := rawArgs["flowId"]; ok {+ return ec.unmarshalNID2int64(ctx, tmp)+ }++ var zeroVal int64+ return zeroVal, nil+}++func (ec *executionContext) field_Subscription_flowFileUpdated_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {+ var err error+ args := map[string]interface{}{}+ arg0, err := ec.field_Subscription_flowFileUpdated_argsFlowID(ctx, rawArgs)+ if err != nil {+ return nil, err+ }+ args["flowId"] = arg0+ return args, nil+}+func (ec *executionContext) field_Subscription_flowFileUpdated_argsFlowID(+ ctx context.Context,+ rawArgs map[string]interface{},+) (int64, error) {+ // We won't call the directive if the argument is null.+ // Set call_argument_directives_with_null to true to call directives+ // even if the argument is null.+ _, ok := rawArgs["flowId"]+ if !ok {+ var zeroVal int64+ return zeroVal, nil+ }++ ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("flowId"))+ if tmp, ok := rawArgs["flowId"]; ok {+ return ec.unmarshalNID2int64(ctx, tmp)+ }++ var zeroVal int64+ return zeroVal, nil+}+func (ec *executionContext) field_Subscription_messageLogAdded_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {var err errorargs := map[string]interface{}{}@@ -13353,6 +13588,270 @@ func (ec *executionContext) fieldContext_FlowExecutionStats_tasks(_ context.Contreturn fc, nil}+func (ec *executionContext) _FlowFile_id(ctx context.Context, field graphql.CollectedField, obj *model.FlowFile) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_FlowFile_id(ctx, field)+ if err != nil {+ return graphql.Null+ }+ ctx = graphql.WithFieldContext(ctx, fc)+ defer func() {+ if r := recover(); r != nil {+ ec.Error(ctx, ec.Recover(ctx, r))+ ret = graphql.Null+ }+ }()+ resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {+ ctx = rctx // use context from middleware stack in children+ return obj.ID, nil+ })+ if err != nil {+ ec.Error(ctx, err)+ return graphql.Null+ }+ if resTmp == nil {+ if !graphql.HasFieldError(ctx, fc) {+ ec.Errorf(ctx, "must not be null")+ }+ return graphql.Null+ }+ res := resTmp.(string)+ fc.Result = res+ return ec.marshalNString2string(ctx, field.Selections, res)+}++func (ec *executionContext) fieldContext_FlowFile_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+ fc = &graphql.FieldContext{+ Object: "FlowFile",+ Field: field,+ IsMethod: false,+ IsResolver: false,+ Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {+ return nil, errors.New("field of type String does not have child fields")+ },+ }+ return fc, nil+}++func (ec *executionContext) _FlowFile_name(ctx context.Context, field graphql.CollectedField, obj *model.FlowFile) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_FlowFile_name(ctx, field)+ if err != nil {+ return graphql.Null+ }+ ctx = graphql.WithFieldContext(ctx, fc)+ defer func() {+ if r := recover(); r != nil {+ ec.Error(ctx, ec.Recover(ctx, r))+ ret = graphql.Null+ }+ }()+ resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {+ ctx = rctx // use context from middleware stack in children+ return obj.Name, nil+ })+ if err != nil {+ ec.Error(ctx, err)+ return graphql.Null+ }+ if resTmp == nil {+ if !graphql.HasFieldError(ctx, fc) {+ ec.Errorf(ctx, "must not be null")+ }+ return graphql.Null+ }+ res := resTmp.(string)+ fc.Result = res+ return ec.marshalNString2string(ctx, field.Selections, res)+}++func (ec *executionContext) fieldContext_FlowFile_name(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+ fc = &graphql.FieldContext{+ Object: "FlowFile",+ Field: field,+ IsMethod: false,+ IsResolver: false,+ Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {+ return nil, errors.New("field of type String does not have child fields")+ },+ }+ return fc, nil+}++func (ec *executionContext) _FlowFile_path(ctx context.Context, field graphql.CollectedField, obj *model.FlowFile) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_FlowFile_path(ctx, field)+ if err != nil {+ return graphql.Null+ }+ ctx = graphql.WithFieldContext(ctx, fc)+ defer func() {+ if r := recover(); r != nil {+ ec.Error(ctx, ec.Recover(ctx, r))+ ret = graphql.Null+ }+ }()+ resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {+ ctx = rctx // use context from middleware stack in children+ return obj.Path, nil+ })+ if err != nil {+ ec.Error(ctx, err)+ return graphql.Null+ }+ if resTmp == nil {+ if !graphql.HasFieldError(ctx, fc) {+ ec.Errorf(ctx, "must not be null")+ }+ return graphql.Null+ }+ res := resTmp.(string)+ fc.Result = res+ return ec.marshalNString2string(ctx, field.Selections, res)+}++func (ec *executionContext) fieldContext_FlowFile_path(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+ fc = &graphql.FieldContext{+ Object: "FlowFile",+ Field: field,+ IsMethod: false,+ IsResolver: false,+ Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {+ return nil, errors.New("field of type String does not have child fields")+ },+ }+ return fc, nil+}++func (ec *executionContext) _FlowFile_size(ctx context.Context, field graphql.CollectedField, obj *model.FlowFile) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_FlowFile_size(ctx, field)+ if err != nil {+ return graphql.Null+ }+ ctx = graphql.WithFieldContext(ctx, fc)+ defer func() {+ if r := recover(); r != nil {+ ec.Error(ctx, ec.Recover(ctx, r))+ ret = graphql.Null+ }+ }()+ resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {+ ctx = rctx // use context from middleware stack in children+ return obj.Size, nil+ })+ if err != nil {+ ec.Error(ctx, err)+ return graphql.Null+ }+ if resTmp == nil {+ if !graphql.HasFieldError(ctx, fc) {+ ec.Errorf(ctx, "must not be null")+ }+ return graphql.Null+ }+ res := resTmp.(int)+ fc.Result = res+ return ec.marshalNInt2int(ctx, field.Selections, res)+}++func (ec *executionContext) fieldContext_FlowFile_size(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+ fc = &graphql.FieldContext{+ Object: "FlowFile",+ Field: field,+ IsMethod: false,+ IsResolver: false,+ Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {+ return nil, errors.New("field of type Int does not have child fields")+ },+ }+ return fc, nil+}++func (ec *executionContext) _FlowFile_isDir(ctx context.Context, field graphql.CollectedField, obj *model.FlowFile) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_FlowFile_isDir(ctx, field)+ if err != nil {+ return graphql.Null+ }+ ctx = graphql.WithFieldContext(ctx, fc)+ defer func() {+ if r := recover(); r != nil {+ ec.Error(ctx, ec.Recover(ctx, r))+ ret = graphql.Null+ }+ }()+ resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {+ ctx = rctx // use context from middleware stack in children+ return obj.IsDir, nil+ })+ if err != nil {+ ec.Error(ctx, err)+ return graphql.Null+ }+ if resTmp == nil {+ if !graphql.HasFieldError(ctx, fc) {+ ec.Errorf(ctx, "must not be null")+ }+ return graphql.Null+ }+ res := resTmp.(bool)+ fc.Result = res+ return ec.marshalNBoolean2bool(ctx, field.Selections, res)+}++func (ec *executionContext) fieldContext_FlowFile_isDir(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+ fc = &graphql.FieldContext{+ Object: "FlowFile",+ Field: field,+ IsMethod: false,+ IsResolver: false,+ Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {+ return nil, errors.New("field of type Boolean does not have child fields")+ },+ }+ return fc, nil+}++func (ec *executionContext) _FlowFile_modifiedAt(ctx context.Context, field graphql.CollectedField, obj *model.FlowFile) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_FlowFile_modifiedAt(ctx, field)+ if err != nil {+ return graphql.Null+ }+ ctx = graphql.WithFieldContext(ctx, fc)+ defer func() {+ if r := recover(); r != nil {+ ec.Error(ctx, ec.Recover(ctx, r))+ ret = graphql.Null+ }+ }()+ resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {+ ctx = rctx // use context from middleware stack in children+ return obj.ModifiedAt, nil+ })+ if err != nil {+ ec.Error(ctx, err)+ return graphql.Null+ }+ if resTmp == nil {+ if !graphql.HasFieldError(ctx, fc) {+ ec.Errorf(ctx, "must not be null")+ }+ return graphql.Null+ }+ res := resTmp.(time.Time)+ fc.Result = res+ return ec.marshalNTime2timeᚐTime(ctx, field.Selections, res)+}++func (ec *executionContext) fieldContext_FlowFile_modifiedAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+ fc = &graphql.FieldContext{+ Object: "FlowFile",+ Field: field,+ IsMethod: false,+ IsResolver: false,+ Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {+ return nil, errors.New("field of type Time does not have child fields")+ },+ }+ return fc, nil+}+func (ec *executionContext) _FlowStats_totalTasksCount(ctx context.Context, field graphql.CollectedField, obj *model.FlowStats) (ret graphql.Marshaler) {fc, err := ec.fieldContext_FlowStats_totalTasksCount(ctx, field)if err != nil {@@ -19966,6 +20465,75 @@ func (ec *executionContext) fieldContext_Query_tasks(ctx context.Context, fieldreturn fc, nil}+func (ec *executionContext) _Query_flowFiles(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_Query_flowFiles(ctx, field)+ if err != nil {+ return graphql.Null+ }+ ctx = graphql.WithFieldContext(ctx, fc)+ defer func() {+ if r := recover(); r != nil {+ ec.Error(ctx, ec.Recover(ctx, r))+ ret = graphql.Null+ }+ }()+ resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {+ ctx = rctx // use context from middleware stack in children+ return ec.resolvers.Query().FlowFiles(rctx, fc.Args["flowId"].(int64))+ })+ if err != nil {+ ec.Error(ctx, err)+ return graphql.Null+ }+ if resTmp == nil {+ if !graphql.HasFieldError(ctx, fc) {+ ec.Errorf(ctx, "must not be null")+ }+ return graphql.Null+ }+ res := resTmp.([]*model.FlowFile)+ fc.Result = res+ return ec.marshalNFlowFile2ᚕᚖpentagiᚋpkgᚋgraphᚋmodelᚐFlowFileᚄ(ctx, field.Selections, res)+}++func (ec *executionContext) fieldContext_Query_flowFiles(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+ fc = &graphql.FieldContext{+ Object: "Query",+ Field: field,+ IsMethod: true,+ IsResolver: true,+ Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {+ switch field.Name {+ case "id":+ return ec.fieldContext_FlowFile_id(ctx, field)+ case "name":+ return ec.fieldContext_FlowFile_name(ctx, field)+ case "path":+ return ec.fieldContext_FlowFile_path(ctx, field)+ case "size":+ return ec.fieldContext_FlowFile_size(ctx, field)+ case "isDir":+ return ec.fieldContext_FlowFile_isDir(ctx, field)+ case "modifiedAt":+ return ec.fieldContext_FlowFile_modifiedAt(ctx, field)+ }+ return nil, fmt.Errorf("no field named %q was found under type FlowFile", field.Name)+ },+ }+ defer func() {+ if r := recover(); r != nil {+ err = ec.Recover(ctx, r)+ ec.Error(ctx, err)+ }+ }()+ ctx = graphql.WithFieldContext(ctx, fc)+ if fc.Args, err = ec.field_Query_flowFiles_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {+ ec.Error(ctx, err)+ return fc, err+ }+ return fc, nil+}+func (ec *executionContext) _Query_screenshots(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {fc, err := ec.fieldContext_Query_screenshots(ctx, field)if err != nil {@@ -23553,15 +24121,189 @@ func (ec *executionContext) fieldContext_Subscription_assistantCreated(ctx conte}}()ctx = graphql.WithFieldContext(ctx, fc)- if fc.Args, err = ec.field_Subscription_assistantCreated_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {+ if fc.Args, err = ec.field_Subscription_assistantCreated_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {+ ec.Error(ctx, err)+ return fc, err+ }+ return fc, nil+}++func (ec *executionContext) _Subscription_assistantUpdated(ctx context.Context, field graphql.CollectedField) (ret func(ctx context.Context) graphql.Marshaler) {+ fc, err := ec.fieldContext_Subscription_assistantUpdated(ctx, field)+ if err != nil {+ return nil+ }+ ctx = graphql.WithFieldContext(ctx, fc)+ defer func() {+ if r := recover(); r != nil {+ ec.Error(ctx, ec.Recover(ctx, r))+ ret = nil+ }+ }()+ resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {+ ctx = rctx // use context from middleware stack in children+ return ec.resolvers.Subscription().AssistantUpdated(rctx, fc.Args["flowId"].(int64))+ })+ if err != nil {+ ec.Error(ctx, err)+ return nil+ }+ if resTmp == nil {+ if !graphql.HasFieldError(ctx, fc) {+ ec.Errorf(ctx, "must not be null")+ }+ return nil+ }+ return func(ctx context.Context) graphql.Marshaler {+ select {+ case res, ok := <-resTmp.(<-chan *model.Assistant):+ if !ok {+ return nil+ }+ return graphql.WriterFunc(func(w io.Writer) {+ w.Write([]byte{'{'})+ graphql.MarshalString(field.Alias).MarshalGQL(w)+ w.Write([]byte{':'})+ ec.marshalNAssistant2ᚖpentagiᚋpkgᚋgraphᚋmodelᚐAssistant(ctx, field.Selections, res).MarshalGQL(w)+ w.Write([]byte{'}'})+ })+ case <-ctx.Done():+ return nil+ }+ }+}++func (ec *executionContext) fieldContext_Subscription_assistantUpdated(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+ fc = &graphql.FieldContext{+ Object: "Subscription",+ Field: field,+ IsMethod: true,+ IsResolver: true,+ Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {+ switch field.Name {+ case "id":+ return ec.fieldContext_Assistant_id(ctx, field)+ case "title":+ return ec.fieldContext_Assistant_title(ctx, field)+ case "status":+ return ec.fieldContext_Assistant_status(ctx, field)+ case "provider":+ return ec.fieldContext_Assistant_provider(ctx, field)+ case "flowId":+ return ec.fieldContext_Assistant_flowId(ctx, field)+ case "useAgents":+ return ec.fieldContext_Assistant_useAgents(ctx, field)+ case "createdAt":+ return ec.fieldContext_Assistant_createdAt(ctx, field)+ case "updatedAt":+ return ec.fieldContext_Assistant_updatedAt(ctx, field)+ }+ return nil, fmt.Errorf("no field named %q was found under type Assistant", field.Name)+ },+ }+ defer func() {+ if r := recover(); r != nil {+ err = ec.Recover(ctx, r)+ ec.Error(ctx, err)+ }+ }()+ ctx = graphql.WithFieldContext(ctx, fc)+ if fc.Args, err = ec.field_Subscription_assistantUpdated_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {+ ec.Error(ctx, err)+ return fc, err+ }+ return fc, nil+}++func (ec *executionContext) _Subscription_assistantDeleted(ctx context.Context, field graphql.CollectedField) (ret func(ctx context.Context) graphql.Marshaler) {+ fc, err := ec.fieldContext_Subscription_assistantDeleted(ctx, field)+ if err != nil {+ return nil+ }+ ctx = graphql.WithFieldContext(ctx, fc)+ defer func() {+ if r := recover(); r != nil {+ ec.Error(ctx, ec.Recover(ctx, r))+ ret = nil+ }+ }()+ resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {+ ctx = rctx // use context from middleware stack in children+ return ec.resolvers.Subscription().AssistantDeleted(rctx, fc.Args["flowId"].(int64))+ })+ if err != nil {+ ec.Error(ctx, err)+ return nil+ }+ if resTmp == nil {+ if !graphql.HasFieldError(ctx, fc) {+ ec.Errorf(ctx, "must not be null")+ }+ return nil+ }+ return func(ctx context.Context) graphql.Marshaler {+ select {+ case res, ok := <-resTmp.(<-chan *model.Assistant):+ if !ok {+ return nil+ }+ return graphql.WriterFunc(func(w io.Writer) {+ w.Write([]byte{'{'})+ graphql.MarshalString(field.Alias).MarshalGQL(w)+ w.Write([]byte{':'})+ ec.marshalNAssistant2ᚖpentagiᚋpkgᚋgraphᚋmodelᚐAssistant(ctx, field.Selections, res).MarshalGQL(w)+ w.Write([]byte{'}'})+ })+ case <-ctx.Done():+ return nil+ }+ }+}++func (ec *executionContext) fieldContext_Subscription_assistantDeleted(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+ fc = &graphql.FieldContext{+ Object: "Subscription",+ Field: field,+ IsMethod: true,+ IsResolver: true,+ Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {+ switch field.Name {+ case "id":+ return ec.fieldContext_Assistant_id(ctx, field)+ case "title":+ return ec.fieldContext_Assistant_title(ctx, field)+ case "status":+ return ec.fieldContext_Assistant_status(ctx, field)+ case "provider":+ return ec.fieldContext_Assistant_provider(ctx, field)+ case "flowId":+ return ec.fieldContext_Assistant_flowId(ctx, field)+ case "useAgents":+ return ec.fieldContext_Assistant_useAgents(ctx, field)+ case "createdAt":+ return ec.fieldContext_Assistant_createdAt(ctx, field)+ case "updatedAt":+ return ec.fieldContext_Assistant_updatedAt(ctx, field)+ }+ return nil, fmt.Errorf("no field named %q was found under type Assistant", field.Name)+ },+ }+ defer func() {+ if r := recover(); r != nil {+ err = ec.Recover(ctx, r)+ ec.Error(ctx, err)+ }+ }()+ ctx = graphql.WithFieldContext(ctx, fc)+ if fc.Args, err = ec.field_Subscription_assistantDeleted_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {ec.Error(ctx, err)return fc, err}return fc, nil}-func (ec *executionContext) _Subscription_assistantUpdated(ctx context.Context, field graphql.CollectedField) (ret func(ctx context.Context) graphql.Marshaler) {- fc, err := ec.fieldContext_Subscription_assistantUpdated(ctx, field)+func (ec *executionContext) _Subscription_flowFileAdded(ctx context.Context, field graphql.CollectedField) (ret func(ctx context.Context) graphql.Marshaler) {+ fc, err := ec.fieldContext_Subscription_flowFileAdded(ctx, field)if err != nil {return nil}@@ -23574,7 +24316,7 @@ func (ec *executionContext) _Subscription_assistantUpdated(ctx context.Context,}()resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {ctx = rctx // use context from middleware stack in children- return ec.resolvers.Subscription().AssistantUpdated(rctx, fc.Args["flowId"].(int64))+ return ec.resolvers.Subscription().FlowFileAdded(rctx, fc.Args["flowId"].(int64))})if err != nil {ec.Error(ctx, err)@@ -23588,7 +24330,7 @@ func (ec *executionContext) _Subscription_assistantUpdated(ctx context.Context,}return func(ctx context.Context) graphql.Marshaler {select {- case res, ok := <-resTmp.(<-chan *model.Assistant):+ case res, ok := <-resTmp.(<-chan *model.FlowFile):if !ok {return nil}@@ -23596,7 +24338,7 @@ func (ec *executionContext) _Subscription_assistantUpdated(ctx context.Context,w.Write([]byte{'{'})graphql.MarshalString(field.Alias).MarshalGQL(w)w.Write([]byte{':'})- ec.marshalNAssistant2ᚖpentagiᚋpkgᚋgraphᚋmodelᚐAssistant(ctx, field.Selections, res).MarshalGQL(w)+ ec.marshalNFlowFile2ᚖpentagiᚋpkgᚋgraphᚋmodelᚐFlowFile(ctx, field.Selections, res).MarshalGQL(w)w.Write([]byte{'}'})})case <-ctx.Done():@@ -23605,7 +24347,7 @@ func (ec *executionContext) _Subscription_assistantUpdated(ctx context.Context,}}-func (ec *executionContext) fieldContext_Subscription_assistantUpdated(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+func (ec *executionContext) fieldContext_Subscription_flowFileAdded(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {fc = &graphql.FieldContext{Object: "Subscription",Field: field,@@ -23614,23 +24356,19 @@ func (ec *executionContext) fieldContext_Subscription_assistantUpdated(ctx conteChild: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {switch field.Name {case "id":- return ec.fieldContext_Assistant_id(ctx, field)- case "title":- return ec.fieldContext_Assistant_title(ctx, field)- case "status":- return ec.fieldContext_Assistant_status(ctx, field)- case "provider":- return ec.fieldContext_Assistant_provider(ctx, field)- case "flowId":- return ec.fieldContext_Assistant_flowId(ctx, field)- case "useAgents":- return ec.fieldContext_Assistant_useAgents(ctx, field)- case "createdAt":- return ec.fieldContext_Assistant_createdAt(ctx, field)- case "updatedAt":- return ec.fieldContext_Assistant_updatedAt(ctx, field)+ return ec.fieldContext_FlowFile_id(ctx, field)+ case "name":+ return ec.fieldContext_FlowFile_name(ctx, field)+ case "path":+ return ec.fieldContext_FlowFile_path(ctx, field)+ case "size":+ return ec.fieldContext_FlowFile_size(ctx, field)+ case "isDir":+ return ec.fieldContext_FlowFile_isDir(ctx, field)+ case "modifiedAt":+ return ec.fieldContext_FlowFile_modifiedAt(ctx, field)}- return nil, fmt.Errorf("no field named %q was found under type Assistant", field.Name)+ return nil, fmt.Errorf("no field named %q was found under type FlowFile", field.Name)},}defer func() {@@ -23640,15 +24378,15 @@ func (ec *executionContext) fieldContext_Subscription_assistantUpdated(ctx conte}}()ctx = graphql.WithFieldContext(ctx, fc)- if fc.Args, err = ec.field_Subscription_assistantUpdated_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {+ if fc.Args, err = ec.field_Subscription_flowFileAdded_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {ec.Error(ctx, err)return fc, err}return fc, nil}-func (ec *executionContext) _Subscription_assistantDeleted(ctx context.Context, field graphql.CollectedField) (ret func(ctx context.Context) graphql.Marshaler) {- fc, err := ec.fieldContext_Subscription_assistantDeleted(ctx, field)+func (ec *executionContext) _Subscription_flowFileUpdated(ctx context.Context, field graphql.CollectedField) (ret func(ctx context.Context) graphql.Marshaler) {+ fc, err := ec.fieldContext_Subscription_flowFileUpdated(ctx, field)if err != nil {return nil}@@ -23661,7 +24399,7 @@ func (ec *executionContext) _Subscription_assistantDeleted(ctx context.Context,}()resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {ctx = rctx // use context from middleware stack in children- return ec.resolvers.Subscription().AssistantDeleted(rctx, fc.Args["flowId"].(int64))+ return ec.resolvers.Subscription().FlowFileUpdated(rctx, fc.Args["flowId"].(int64))})if err != nil {ec.Error(ctx, err)@@ -23675,7 +24413,7 @@ func (ec *executionContext) _Subscription_assistantDeleted(ctx context.Context,}return func(ctx context.Context) graphql.Marshaler {select {- case res, ok := <-resTmp.(<-chan *model.Assistant):+ case res, ok := <-resTmp.(<-chan *model.FlowFile):if !ok {return nil}@@ -23683,7 +24421,7 @@ func (ec *executionContext) _Subscription_assistantDeleted(ctx context.Context,w.Write([]byte{'{'})graphql.MarshalString(field.Alias).MarshalGQL(w)w.Write([]byte{':'})- ec.marshalNAssistant2ᚖpentagiᚋpkgᚋgraphᚋmodelᚐAssistant(ctx, field.Selections, res).MarshalGQL(w)+ ec.marshalNFlowFile2ᚖpentagiᚋpkgᚋgraphᚋmodelᚐFlowFile(ctx, field.Selections, res).MarshalGQL(w)w.Write([]byte{'}'})})case <-ctx.Done():@@ -23692,7 +24430,7 @@ func (ec *executionContext) _Subscription_assistantDeleted(ctx context.Context,}}-func (ec *executionContext) fieldContext_Subscription_assistantDeleted(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+func (ec *executionContext) fieldContext_Subscription_flowFileUpdated(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {fc = &graphql.FieldContext{Object: "Subscription",Field: field,@@ -23701,23 +24439,19 @@ func (ec *executionContext) fieldContext_Subscription_assistantDeleted(ctx conteChild: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {switch field.Name {case "id":- return ec.fieldContext_Assistant_id(ctx, field)- case "title":- return ec.fieldContext_Assistant_title(ctx, field)- case "status":- return ec.fieldContext_Assistant_status(ctx, field)- case "provider":- return ec.fieldContext_Assistant_provider(ctx, field)- case "flowId":- return ec.fieldContext_Assistant_flowId(ctx, field)- case "useAgents":- return ec.fieldContext_Assistant_useAgents(ctx, field)- case "createdAt":- return ec.fieldContext_Assistant_createdAt(ctx, field)- case "updatedAt":- return ec.fieldContext_Assistant_updatedAt(ctx, field)+ return ec.fieldContext_FlowFile_id(ctx, field)+ case "name":+ return ec.fieldContext_FlowFile_name(ctx, field)+ case "path":+ return ec.fieldContext_FlowFile_path(ctx, field)+ case "size":+ return ec.fieldContext_FlowFile_size(ctx, field)+ case "isDir":+ return ec.fieldContext_FlowFile_isDir(ctx, field)+ case "modifiedAt":+ return ec.fieldContext_FlowFile_modifiedAt(ctx, field)}- return nil, fmt.Errorf("no field named %q was found under type Assistant", field.Name)+ return nil, fmt.Errorf("no field named %q was found under type FlowFile", field.Name)},}defer func() {@@ -23727,7 +24461,90 @@ func (ec *executionContext) fieldContext_Subscription_assistantDeleted(ctx conte}}()ctx = graphql.WithFieldContext(ctx, fc)- if fc.Args, err = ec.field_Subscription_assistantDeleted_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {+ if fc.Args, err = ec.field_Subscription_flowFileUpdated_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {+ ec.Error(ctx, err)+ return fc, err+ }+ return fc, nil+}++func (ec *executionContext) _Subscription_flowFileDeleted(ctx context.Context, field graphql.CollectedField) (ret func(ctx context.Context) graphql.Marshaler) {+ fc, err := ec.fieldContext_Subscription_flowFileDeleted(ctx, field)+ if err != nil {+ return nil+ }+ ctx = graphql.WithFieldContext(ctx, fc)+ defer func() {+ if r := recover(); r != nil {+ ec.Error(ctx, ec.Recover(ctx, r))+ ret = nil+ }+ }()+ resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {+ ctx = rctx // use context from middleware stack in children+ return ec.resolvers.Subscription().FlowFileDeleted(rctx, fc.Args["flowId"].(int64))+ })+ if err != nil {+ ec.Error(ctx, err)+ return nil+ }+ if resTmp == nil {+ if !graphql.HasFieldError(ctx, fc) {+ ec.Errorf(ctx, "must not be null")+ }+ return nil+ }+ return func(ctx context.Context) graphql.Marshaler {+ select {+ case res, ok := <-resTmp.(<-chan *model.FlowFile):+ if !ok {+ return nil+ }+ return graphql.WriterFunc(func(w io.Writer) {+ w.Write([]byte{'{'})+ graphql.MarshalString(field.Alias).MarshalGQL(w)+ w.Write([]byte{':'})+ ec.marshalNFlowFile2ᚖpentagiᚋpkgᚋgraphᚋmodelᚐFlowFile(ctx, field.Selections, res).MarshalGQL(w)+ w.Write([]byte{'}'})+ })+ case <-ctx.Done():+ return nil+ }+ }+}++func (ec *executionContext) fieldContext_Subscription_flowFileDeleted(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+ fc = &graphql.FieldContext{+ Object: "Subscription",+ Field: field,+ IsMethod: true,+ IsResolver: true,+ Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {+ switch field.Name {+ case "id":+ return ec.fieldContext_FlowFile_id(ctx, field)+ case "name":+ return ec.fieldContext_FlowFile_name(ctx, field)+ case "path":+ return ec.fieldContext_FlowFile_path(ctx, field)+ case "size":+ return ec.fieldContext_FlowFile_size(ctx, field)+ case "isDir":+ return ec.fieldContext_FlowFile_isDir(ctx, field)+ case "modifiedAt":+ return ec.fieldContext_FlowFile_modifiedAt(ctx, field)+ }+ return nil, fmt.Errorf("no field named %q was found under type FlowFile", field.Name)+ },+ }+ defer func() {+ if r := recover(); r != nil {+ err = ec.Recover(ctx, r)+ ec.Error(ctx, err)+ }+ }()+ ctx = graphql.WithFieldContext(ctx, fc)+ if fc.Args, err = ec.field_Subscription_flowFileDeleted_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {ec.Error(ctx, err)return fc, err}@@ -32282,73 +33099,199 @@ func (ec *executionContext) _DailyUsageStats(ctx context.Context, sel ast.Selectreturn out}-var defaultPromptImplementors = []string{"DefaultPrompt"}+var defaultPromptImplementors = []string{"DefaultPrompt"}++func (ec *executionContext) _DefaultPrompt(ctx context.Context, sel ast.SelectionSet, obj *model.DefaultPrompt) graphql.Marshaler {+ fields := graphql.CollectFields(ec.OperationContext, sel, defaultPromptImplementors)++ out := graphql.NewFieldSet(fields)+ deferred := make(map[string]*graphql.FieldSet)+ for i, field := range fields {+ switch field.Name {+ case "__typename":+ out.Values[i] = graphql.MarshalString("DefaultPrompt")+ case "type":+ out.Values[i] = ec._DefaultPrompt_type(ctx, field, obj)+ if out.Values[i] == graphql.Null {+ out.Invalids+++ }+ case "template":+ out.Values[i] = ec._DefaultPrompt_template(ctx, field, obj)+ if out.Values[i] == graphql.Null {+ out.Invalids+++ }+ case "variables":+ out.Values[i] = ec._DefaultPrompt_variables(ctx, field, obj)+ if out.Values[i] == graphql.Null {+ out.Invalids+++ }+ default:+ panic("unknown field " + strconv.Quote(field.Name))+ }+ }+ out.Dispatch(ctx)+ if out.Invalids > 0 {+ return graphql.Null+ }++ atomic.AddInt32(&ec.deferred, int32(len(deferred)))++ for label, dfs := range deferred {+ ec.processDeferredGroup(graphql.DeferredGroup{+ Label: label,+ Path: graphql.GetPath(ctx),+ FieldSet: dfs,+ Context: ctx,+ })+ }++ return out+}++var defaultPromptsImplementors = []string{"DefaultPrompts"}++func (ec *executionContext) _DefaultPrompts(ctx context.Context, sel ast.SelectionSet, obj *model.DefaultPrompts) graphql.Marshaler {+ fields := graphql.CollectFields(ec.OperationContext, sel, defaultPromptsImplementors)++ out := graphql.NewFieldSet(fields)+ deferred := make(map[string]*graphql.FieldSet)+ for i, field := range fields {+ switch field.Name {+ case "__typename":+ out.Values[i] = graphql.MarshalString("DefaultPrompts")+ case "agents":+ out.Values[i] = ec._DefaultPrompts_agents(ctx, field, obj)+ if out.Values[i] == graphql.Null {+ out.Invalids+++ }+ case "tools":+ out.Values[i] = ec._DefaultPrompts_tools(ctx, field, obj)+ if out.Values[i] == graphql.Null {+ out.Invalids+++ }+ default:+ panic("unknown field " + strconv.Quote(field.Name))+ }+ }+ out.Dispatch(ctx)+ if out.Invalids > 0 {+ return graphql.Null+ }++ atomic.AddInt32(&ec.deferred, int32(len(deferred)))++ for label, dfs := range deferred {+ ec.processDeferredGroup(graphql.DeferredGroup{+ Label: label,+ Path: graphql.GetPath(ctx),+ FieldSet: dfs,+ Context: ctx,+ })+ }++ return out+}++var defaultProvidersConfigImplementors = []string{"DefaultProvidersConfig"}++func (ec *executionContext) _DefaultProvidersConfig(ctx context.Context, sel ast.SelectionSet, obj *model.DefaultProvidersConfig) graphql.Marshaler {+ fields := graphql.CollectFields(ec.OperationContext, sel, defaultProvidersConfigImplementors)++ out := graphql.NewFieldSet(fields)+ deferred := make(map[string]*graphql.FieldSet)+ for i, field := range fields {+ switch field.Name {+ case "__typename":+ out.Values[i] = graphql.MarshalString("DefaultProvidersConfig")+ case "openai":+ out.Values[i] = ec._DefaultProvidersConfig_openai(ctx, field, obj)+ if out.Values[i] == graphql.Null {+ out.Invalids+++ }+ case "anthropic":+ out.Values[i] = ec._DefaultProvidersConfig_anthropic(ctx, field, obj)+ if out.Values[i] == graphql.Null {+ out.Invalids+++ }+ case "gemini":+ out.Values[i] = ec._DefaultProvidersConfig_gemini(ctx, field, obj)+ case "bedrock":+ out.Values[i] = ec._DefaultProvidersConfig_bedrock(ctx, field, obj)+ case "ollama":+ out.Values[i] = ec._DefaultProvidersConfig_ollama(ctx, field, obj)+ case "custom":+ out.Values[i] = ec._DefaultProvidersConfig_custom(ctx, field, obj)+ case "deepseek":+ out.Values[i] = ec._DefaultProvidersConfig_deepseek(ctx, field, obj)+ case "glm":+ out.Values[i] = ec._DefaultProvidersConfig_glm(ctx, field, obj)+ case "kimi":+ out.Values[i] = ec._DefaultProvidersConfig_kimi(ctx, field, obj)+ case "qwen":+ out.Values[i] = ec._DefaultProvidersConfig_qwen(ctx, field, obj)+ default:+ panic("unknown field " + strconv.Quote(field.Name))+ }+ }+ out.Dispatch(ctx)+ if out.Invalids > 0 {+ return graphql.Null+ }++ atomic.AddInt32(&ec.deferred, int32(len(deferred)))++ for label, dfs := range deferred {+ ec.processDeferredGroup(graphql.DeferredGroup{+ Label: label,+ Path: graphql.GetPath(ctx),+ FieldSet: dfs,+ Context: ctx,+ })+ }++ return out+}++var flowImplementors = []string{"Flow"}-func (ec *executionContext) _DefaultPrompt(ctx context.Context, sel ast.SelectionSet, obj *model.DefaultPrompt) graphql.Marshaler {- fields := graphql.CollectFields(ec.OperationContext, sel, defaultPromptImplementors)+func (ec *executionContext) _Flow(ctx context.Context, sel ast.SelectionSet, obj *model.Flow) graphql.Marshaler {+ fields := graphql.CollectFields(ec.OperationContext, sel, flowImplementors)out := graphql.NewFieldSet(fields)deferred := make(map[string]*graphql.FieldSet)for i, field := range fields {switch field.Name {case "__typename":- out.Values[i] = graphql.MarshalString("DefaultPrompt")- case "type":- out.Values[i] = ec._DefaultPrompt_type(ctx, field, obj)+ out.Values[i] = graphql.MarshalString("Flow")+ case "id":+ out.Values[i] = ec._Flow_id(ctx, field, obj)if out.Values[i] == graphql.Null {out.Invalids++}- case "template":- out.Values[i] = ec._DefaultPrompt_template(ctx, field, obj)+ case "title":+ out.Values[i] = ec._Flow_title(ctx, field, obj)if out.Values[i] == graphql.Null {out.Invalids++}- case "variables":- out.Values[i] = ec._DefaultPrompt_variables(ctx, field, obj)+ case "status":+ out.Values[i] = ec._Flow_status(ctx, field, obj)if out.Values[i] == graphql.Null {out.Invalids++}- default:- panic("unknown field " + strconv.Quote(field.Name))- }- }- out.Dispatch(ctx)- if out.Invalids > 0 {- return graphql.Null- }-- atomic.AddInt32(&ec.deferred, int32(len(deferred)))-- for label, dfs := range deferred {- ec.processDeferredGroup(graphql.DeferredGroup{- Label: label,- Path: graphql.GetPath(ctx),- FieldSet: dfs,- Context: ctx,- })- }-- return out-}--var defaultPromptsImplementors = []string{"DefaultPrompts"}--func (ec *executionContext) _DefaultPrompts(ctx context.Context, sel ast.SelectionSet, obj *model.DefaultPrompts) graphql.Marshaler {- fields := graphql.CollectFields(ec.OperationContext, sel, defaultPromptsImplementors)-- out := graphql.NewFieldSet(fields)- deferred := make(map[string]*graphql.FieldSet)- for i, field := range fields {- switch field.Name {- case "__typename":- out.Values[i] = graphql.MarshalString("DefaultPrompts")- case "agents":- out.Values[i] = ec._DefaultPrompts_agents(ctx, field, obj)+ case "terminals":+ out.Values[i] = ec._Flow_terminals(ctx, field, obj)+ case "provider":+ out.Values[i] = ec._Flow_provider(ctx, field, obj)if out.Values[i] == graphql.Null {out.Invalids++}- case "tools":- out.Values[i] = ec._DefaultPrompts_tools(ctx, field, obj)+ case "createdAt":+ out.Values[i] = ec._Flow_createdAt(ctx, field, obj)+ if out.Values[i] == graphql.Null {+ out.Invalids+++ }+ case "updatedAt":+ out.Values[i] = ec._Flow_updatedAt(ctx, field, obj)if out.Values[i] == graphql.Null {out.Invalids++}@@ -32375,43 +33318,27 @@ func (ec *executionContext) _DefaultPrompts(ctx context.Context, sel ast.Selectireturn out}-var defaultProvidersConfigImplementors = []string{"DefaultProvidersConfig"}+var flowAssistantImplementors = []string{"FlowAssistant"}-func (ec *executionContext) _DefaultProvidersConfig(ctx context.Context, sel ast.SelectionSet, obj *model.DefaultProvidersConfig) graphql.Marshaler {- fields := graphql.CollectFields(ec.OperationContext, sel, defaultProvidersConfigImplementors)+func (ec *executionContext) _FlowAssistant(ctx context.Context, sel ast.SelectionSet, obj *model.FlowAssistant) graphql.Marshaler {+ fields := graphql.CollectFields(ec.OperationContext, sel, flowAssistantImplementors)out := graphql.NewFieldSet(fields)deferred := make(map[string]*graphql.FieldSet)for i, field := range fields {switch field.Name {case "__typename":- out.Values[i] = graphql.MarshalString("DefaultProvidersConfig")- case "openai":- out.Values[i] = ec._DefaultProvidersConfig_openai(ctx, field, obj)+ out.Values[i] = graphql.MarshalString("FlowAssistant")+ case "flow":+ out.Values[i] = ec._FlowAssistant_flow(ctx, field, obj)if out.Values[i] == graphql.Null {out.Invalids++}- case "anthropic":- out.Values[i] = ec._DefaultProvidersConfig_anthropic(ctx, field, obj)+ case "assistant":+ out.Values[i] = ec._FlowAssistant_assistant(ctx, field, obj)if out.Values[i] == graphql.Null {out.Invalids++}- case "gemini":- out.Values[i] = ec._DefaultProvidersConfig_gemini(ctx, field, obj)- case "bedrock":- out.Values[i] = ec._DefaultProvidersConfig_bedrock(ctx, field, obj)- case "ollama":- out.Values[i] = ec._DefaultProvidersConfig_ollama(ctx, field, obj)- case "custom":- out.Values[i] = ec._DefaultProvidersConfig_custom(ctx, field, obj)- case "deepseek":- out.Values[i] = ec._DefaultProvidersConfig_deepseek(ctx, field, obj)- case "glm":- out.Values[i] = ec._DefaultProvidersConfig_glm(ctx, field, obj)- case "kimi":- out.Values[i] = ec._DefaultProvidersConfig_kimi(ctx, field, obj)- case "qwen":- out.Values[i] = ec._DefaultProvidersConfig_qwen(ctx, field, obj)default:panic("unknown field " + strconv.Quote(field.Name))}@@ -32435,90 +33362,44 @@ func (ec *executionContext) _DefaultProvidersConfig(ctx context.Context, sel astreturn out}-var flowImplementors = []string{"Flow"}+var flowExecutionStatsImplementors = []string{"FlowExecutionStats"}-func (ec *executionContext) _Flow(ctx context.Context, sel ast.SelectionSet, obj *model.Flow) graphql.Marshaler {- fields := graphql.CollectFields(ec.OperationContext, sel, flowImplementors)+func (ec *executionContext) _FlowExecutionStats(ctx context.Context, sel ast.SelectionSet, obj *model.FlowExecutionStats) graphql.Marshaler {+ fields := graphql.CollectFields(ec.OperationContext, sel, flowExecutionStatsImplementors)out := graphql.NewFieldSet(fields)deferred := make(map[string]*graphql.FieldSet)for i, field := range fields {switch field.Name {case "__typename":- out.Values[i] = graphql.MarshalString("Flow")- case "id":- out.Values[i] = ec._Flow_id(ctx, field, obj)- if out.Values[i] == graphql.Null {- out.Invalids++- }- case "title":- out.Values[i] = ec._Flow_title(ctx, field, obj)- if out.Values[i] == graphql.Null {- out.Invalids++- }- case "status":- out.Values[i] = ec._Flow_status(ctx, field, obj)+ out.Values[i] = graphql.MarshalString("FlowExecutionStats")+ case "flowId":+ out.Values[i] = ec._FlowExecutionStats_flowId(ctx, field, obj)if out.Values[i] == graphql.Null {out.Invalids++}- case "terminals":- out.Values[i] = ec._Flow_terminals(ctx, field, obj)- case "provider":- out.Values[i] = ec._Flow_provider(ctx, field, obj)+ case "flowTitle":+ out.Values[i] = ec._FlowExecutionStats_flowTitle(ctx, field, obj)if out.Values[i] == graphql.Null {out.Invalids++}- case "createdAt":- out.Values[i] = ec._Flow_createdAt(ctx, field, obj)+ case "totalDurationSeconds":+ out.Values[i] = ec._FlowExecutionStats_totalDurationSeconds(ctx, field, obj)if out.Values[i] == graphql.Null {out.Invalids++}- case "updatedAt":- out.Values[i] = ec._Flow_updatedAt(ctx, field, obj)+ case "totalToolcallsCount":+ out.Values[i] = ec._FlowExecutionStats_totalToolcallsCount(ctx, field, obj)if out.Values[i] == graphql.Null {out.Invalids++}- default:- panic("unknown field " + strconv.Quote(field.Name))- }- }- out.Dispatch(ctx)- if out.Invalids > 0 {- return graphql.Null- }-- atomic.AddInt32(&ec.deferred, int32(len(deferred)))-- for label, dfs := range deferred {- ec.processDeferredGroup(graphql.DeferredGroup{- Label: label,- Path: graphql.GetPath(ctx),- FieldSet: dfs,- Context: ctx,- })- }-- return out-}--var flowAssistantImplementors = []string{"FlowAssistant"}--func (ec *executionContext) _FlowAssistant(ctx context.Context, sel ast.SelectionSet, obj *model.FlowAssistant) graphql.Marshaler {- fields := graphql.CollectFields(ec.OperationContext, sel, flowAssistantImplementors)-- out := graphql.NewFieldSet(fields)- deferred := make(map[string]*graphql.FieldSet)- for i, field := range fields {- switch field.Name {- case "__typename":- out.Values[i] = graphql.MarshalString("FlowAssistant")- case "flow":- out.Values[i] = ec._FlowAssistant_flow(ctx, field, obj)+ case "totalAssistantsCount":+ out.Values[i] = ec._FlowExecutionStats_totalAssistantsCount(ctx, field, obj)if out.Values[i] == graphql.Null {out.Invalids++}- case "assistant":- out.Values[i] = ec._FlowAssistant_assistant(ctx, field, obj)+ case "tasks":+ out.Values[i] = ec._FlowExecutionStats_tasks(ctx, field, obj)if out.Values[i] == graphql.Null {out.Invalids++}@@ -32545,44 +33426,44 @@ func (ec *executionContext) _FlowAssistant(ctx context.Context, sel ast.Selectioreturn out}-var flowExecutionStatsImplementors = []string{"FlowExecutionStats"}+var flowFileImplementors = []string{"FlowFile"}-func (ec *executionContext) _FlowExecutionStats(ctx context.Context, sel ast.SelectionSet, obj *model.FlowExecutionStats) graphql.Marshaler {- fields := graphql.CollectFields(ec.OperationContext, sel, flowExecutionStatsImplementors)+func (ec *executionContext) _FlowFile(ctx context.Context, sel ast.SelectionSet, obj *model.FlowFile) graphql.Marshaler {+ fields := graphql.CollectFields(ec.OperationContext, sel, flowFileImplementors)out := graphql.NewFieldSet(fields)deferred := make(map[string]*graphql.FieldSet)for i, field := range fields {switch field.Name {case "__typename":- out.Values[i] = graphql.MarshalString("FlowExecutionStats")- case "flowId":- out.Values[i] = ec._FlowExecutionStats_flowId(ctx, field, obj)+ out.Values[i] = graphql.MarshalString("FlowFile")+ case "id":+ out.Values[i] = ec._FlowFile_id(ctx, field, obj)if out.Values[i] == graphql.Null {out.Invalids++}- case "flowTitle":- out.Values[i] = ec._FlowExecutionStats_flowTitle(ctx, field, obj)+ case "name":+ out.Values[i] = ec._FlowFile_name(ctx, field, obj)if out.Values[i] == graphql.Null {out.Invalids++}- case "totalDurationSeconds":- out.Values[i] = ec._FlowExecutionStats_totalDurationSeconds(ctx, field, obj)+ case "path":+ out.Values[i] = ec._FlowFile_path(ctx, field, obj)if out.Values[i] == graphql.Null {out.Invalids++}- case "totalToolcallsCount":- out.Values[i] = ec._FlowExecutionStats_totalToolcallsCount(ctx, field, obj)+ case "size":+ out.Values[i] = ec._FlowFile_size(ctx, field, obj)if out.Values[i] == graphql.Null {out.Invalids++}- case "totalAssistantsCount":- out.Values[i] = ec._FlowExecutionStats_totalAssistantsCount(ctx, field, obj)+ case "isDir":+ out.Values[i] = ec._FlowFile_isDir(ctx, field, obj)if out.Values[i] == graphql.Null {out.Invalids++}- case "tasks":- out.Values[i] = ec._FlowExecutionStats_tasks(ctx, field, obj)+ case "modifiedAt":+ out.Values[i] = ec._FlowFile_modifiedAt(ctx, field, obj)if out.Values[i] == graphql.Null {out.Invalids++}@@ -34001,6 +34882,28 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) grfunc(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })}+ out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) })+ case "flowFiles":+ field := field++ innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) {+ defer func() {+ if r := recover(); r != nil {+ ec.Error(ctx, ec.Recover(ctx, r))+ }+ }()+ res = ec._Query_flowFiles(ctx, field)+ if res == graphql.Null {+ atomic.AddUint32(&fs.Invalids, 1)+ }+ return res+ }++ rrm := func(ctx context.Context) graphql.Marshaler {+ return ec.OperationContext.RootResolverMiddleware(ctx,+ func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })+ }+out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) })case "screenshots":field := field@@ -34972,6 +35875,12 @@ func (ec *executionContext) _Subscription(ctx context.Context, sel ast.Selectionreturn ec._Subscription_assistantUpdated(ctx, fields[0])case "assistantDeleted":return ec._Subscription_assistantDeleted(ctx, fields[0])+ case "flowFileAdded":+ return ec._Subscription_flowFileAdded(ctx, fields[0])+ case "flowFileUpdated":+ return ec._Subscription_flowFileUpdated(ctx, fields[0])+ case "flowFileDeleted":+ return ec._Subscription_flowFileDeleted(ctx, fields[0])case "screenshotAdded":return ec._Subscription_screenshotAdded(ctx, fields[0])case "terminalLogAdded":@@ -36829,6 +37738,64 @@ func (ec *executionContext) marshalNFlowExecutionStats2ᚖpentagiᚋpkgᚋgraphreturn ec._FlowExecutionStats(ctx, sel, v)}+func (ec *executionContext) marshalNFlowFile2pentagiᚋpkgᚋgraphᚋmodelᚐFlowFile(ctx context.Context, sel ast.SelectionSet, v model.FlowFile) graphql.Marshaler {+ return ec._FlowFile(ctx, sel, &v)+}++func (ec *executionContext) marshalNFlowFile2ᚕᚖpentagiᚋpkgᚋgraphᚋmodelᚐFlowFileᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.FlowFile) graphql.Marshaler {+ ret := make(graphql.Array, len(v))+ var wg sync.WaitGroup+ isLen1 := len(v) == 1+ if !isLen1 {+ wg.Add(len(v))+ }+ for i := range v {+ i := i+ fc := &graphql.FieldContext{+ Index: &i,+ Result: &v[i],+ }+ ctx := graphql.WithFieldContext(ctx, fc)+ f := func(i int) {+ defer func() {+ if r := recover(); r != nil {+ ec.Error(ctx, ec.Recover(ctx, r))+ ret = nil+ }+ }()+ if !isLen1 {+ defer wg.Done()+ }+ ret[i] = ec.marshalNFlowFile2ᚖpentagiᚋpkgᚋgraphᚋmodelᚐFlowFile(ctx, sel, v[i])+ }+ if isLen1 {+ f(i)+ } else {+ go f(i)+ }++ }+ wg.Wait()++ for _, e := range ret {+ if e == graphql.Null {+ return graphql.Null+ }+ }++ return ret+}++func (ec *executionContext) marshalNFlowFile2ᚖpentagiᚋpkgᚋgraphᚋmodelᚐFlowFile(ctx context.Context, sel ast.SelectionSet, v *model.FlowFile) graphql.Marshaler {+ if v == nil {+ if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {+ ec.Errorf(ctx, "the requested element is null which the schema does not allow")+ }+ return graphql.Null+ }+ return ec._FlowFile(ctx, sel, v)+}+func (ec *executionContext) marshalNFlowStats2pentagiᚋpkgᚋgraphᚋmodelᚐFlowStats(ctx context.Context, sel ast.SelectionSet, v model.FlowStats) graphql.Marshaler {return ec._FlowStats(ctx, sel, &v)}diff --git a/backend/pkg/graph/model/models_gen.go b/backend/pkg/graph/model/models_gen.goindex d6b19542..3a62b982 100644--- a/backend/pkg/graph/model/models_gen.go+++ b/backend/pkg/graph/model/models_gen.go@@ -210,6 +210,15 @@ type FlowExecutionStats struct {Tasks []*TaskExecutionStats `json:"tasks"`}+type FlowFile struct {+ ID string `json:"id"`+ Name string `json:"name"`+ Path string `json:"path"`+ Size int `json:"size"`+ IsDir bool `json:"isDir"`+ ModifiedAt time.Time `json:"modifiedAt"`+}+type FlowStats struct {TotalTasksCount int `json:"totalTasksCount"`TotalSubtasksCount int `json:"totalSubtasksCount"`diff --git a/backend/pkg/graph/schema.graphqls b/backend/pkg/graph/schema.graphqlsindex fd819419..76a5cba1 100644--- a/backend/pkg/graph/schema.graphqls+++ b/backend/pkg/graph/schema.graphqls@@ -338,6 +338,15 @@ type Screenshot {createdAt: Time!}+type FlowFile {+ id: String!+ name: String!+ path: String!+ size: Int!+ isDir: Boolean!+ modifiedAt: Time!+}+# =================== API Tokens types ===================enum TokenStatus {@@ -814,6 +823,7 @@ type Query {# Task and execution logstasks(flowId: ID!): [Task!]+ flowFiles(flowId: ID!): [FlowFile!]!screenshots(flowId: ID!): [Screenshot!]terminalLogs(flowId: ID!): [TerminalLog!]messageLogs(flowId: ID!): [MessageLog!]@@ -918,6 +928,11 @@ type Subscription {assistantUpdated(flowId: ID!): Assistant!assistantDeleted(flowId: ID!): Assistant!+ # Flow file events+ flowFileAdded(flowId: ID!): FlowFile!+ flowFileUpdated(flowId: ID!): FlowFile!+ flowFileDeleted(flowId: ID!): FlowFile!+# Log eventsscreenshotAdded(flowId: ID!): Screenshot!terminalLogAdded(flowId: ID!): TerminalLog!diff --git a/backend/pkg/graph/schema.resolvers.go b/backend/pkg/graph/schema.resolvers.goindex 55e54e8f..fcddc491 100644--- a/backend/pkg/graph/schema.resolvers.go+++ b/backend/pkg/graph/schema.resolvers.go@@ -13,6 +13,7 @@ import ("pentagi/pkg/controller""pentagi/pkg/database""pentagi/pkg/database/converter"+ "pentagi/pkg/flowfiles""pentagi/pkg/graph/model""pentagi/pkg/providers/anthropic""pentagi/pkg/providers/bedrock"@@ -1224,6 +1225,26 @@ func (r *queryResolver) Tasks(ctx context.Context, flowID int64) ([]*model.Task,return converter.ConvertTasks(tasks, subtasks), nil}+// FlowFiles is the resolver for the flowFiles field.+func (r *queryResolver) FlowFiles(ctx context.Context, flowID int64) ([]*model.FlowFile, error) {+ uid, err := validatePermissionWithFlowID(ctx, "flows.view", flowID, r.DB)+ if err != nil {+ return nil, err+ }++ r.Logger.WithFields(logrus.Fields{+ "uid": uid,+ "flow": flowID,+ }).Debug("get flow files")++ files, err := flowfiles.List(r.Config.DataDir, uint64(flowID))+ if err != nil {+ return nil, err+ }++ return convertFlowFiles(files), nil+}+// Screenshots is the resolver for the screenshots field.func (r *queryResolver) Screenshots(ctx context.Context, flowID int64) ([]*model.Screenshot, error) {uid, err := validatePermissionWithFlowID(ctx, "screenshots.view", flowID, r.DB)@@ -2272,6 +2293,36 @@ func (r *subscriptionResolver) AssistantDeleted(ctx context.Context, flowID int6return r.Subscriptions.NewFlowSubscriber(uid, flowID).AssistantDeleted(ctx)}+// FlowFileAdded is the resolver for the flowFileAdded field.+func (r *subscriptionResolver) FlowFileAdded(ctx context.Context, flowID int64) (<-chan *model.FlowFile, error) {+ uid, err := validatePermissionWithFlowID(ctx, "flows.subscribe", flowID, r.DB)+ if err != nil {+ return nil, err+ }++ return r.Subscriptions.NewFlowSubscriber(uid, flowID).FlowFileAdded(ctx)+}++// FlowFileUpdated is the resolver for the flowFileUpdated field.+func (r *subscriptionResolver) FlowFileUpdated(ctx context.Context, flowID int64) (<-chan *model.FlowFile, error) {+ uid, err := validatePermissionWithFlowID(ctx, "flows.subscribe", flowID, r.DB)+ if err != nil {+ return nil, err+ }++ return r.Subscriptions.NewFlowSubscriber(uid, flowID).FlowFileUpdated(ctx)+}++// FlowFileDeleted is the resolver for the flowFileDeleted field.+func (r *subscriptionResolver) FlowFileDeleted(ctx context.Context, flowID int64) (<-chan *model.FlowFile, error) {+ uid, err := validatePermissionWithFlowID(ctx, "flows.subscribe", flowID, r.DB)+ if err != nil {+ return nil, err+ }++ return r.Subscriptions.NewFlowSubscriber(uid, flowID).FlowFileDeleted(ctx)+}+// ScreenshotAdded is the resolver for the screenshotAdded field.func (r *subscriptionResolver) ScreenshotAdded(ctx context.Context, flowID int64) (<-chan *model.Screenshot, error) {uid, err := validatePermissionWithFlowID(ctx, "screenshots.subscribe", flowID, r.DB)diff --git a/backend/pkg/graph/subscriptions/controller.go b/backend/pkg/graph/subscriptions/controller.goindex 0b8b438d..2aa3cc9f 100644--- a/backend/pkg/graph/subscriptions/controller.go+++ b/backend/pkg/graph/subscriptions/controller.go@@ -39,6 +39,9 @@ type FlowSubscriber interface {AssistantCreated(ctx context.Context) (<-chan *model.Assistant, error)AssistantUpdated(ctx context.Context) (<-chan *model.Assistant, error)AssistantDeleted(ctx context.Context) (<-chan *model.Assistant, error)+ FlowFileAdded(ctx context.Context) (<-chan *model.FlowFile, error)+ FlowFileUpdated(ctx context.Context) (<-chan *model.FlowFile, error)+ FlowFileDeleted(ctx context.Context) (<-chan *model.FlowFile, error)ScreenshotAdded(ctx context.Context) (<-chan *model.Screenshot, error)TerminalLogAdded(ctx context.Context) (<-chan *model.TerminalLog, error)MessageLogAdded(ctx context.Context) (<-chan *model.MessageLog, error)@@ -70,6 +73,9 @@ type FlowPublisher interface {AssistantCreated(ctx context.Context, assistant database.Assistant)AssistantUpdated(ctx context.Context, assistant database.Assistant)AssistantDeleted(ctx context.Context, assistant database.Assistant)+ FlowFileAdded(ctx context.Context, file *model.FlowFile)+ FlowFileUpdated(ctx context.Context, file *model.FlowFile)+ FlowFileDeleted(ctx context.Context, file *model.FlowFile)ScreenshotAdded(ctx context.Context, screenshot database.Screenshot)TerminalLogAdded(ctx context.Context, terminalLog database.Termlog)MessageLogAdded(ctx context.Context, messageLog database.Msglog)@@ -104,6 +110,9 @@ type controller struct {assistantCreated Channel[*model.Assistant]assistantUpdated Channel[*model.Assistant]assistantDeleted Channel[*model.Assistant]+ flowFileAdded Channel[*model.FlowFile]+ flowFileUpdated Channel[*model.FlowFile]+ flowFileDeleted Channel[*model.FlowFile]screenshotAdded Channel[*model.Screenshot]terminalLogAdded Channel[*model.TerminalLog]messageLogAdded Channel[*model.MessageLog]@@ -138,6 +147,9 @@ func NewSubscriptionsController() SubscriptionsController {assistantCreated: NewChannel[*model.Assistant](),assistantUpdated: NewChannel[*model.Assistant](),assistantDeleted: NewChannel[*model.Assistant](),+ flowFileAdded: NewChannel[*model.FlowFile](),+ flowFileUpdated: NewChannel[*model.FlowFile](),+ flowFileDeleted: NewChannel[*model.FlowFile](),screenshotAdded: NewChannel[*model.Screenshot](),terminalLogAdded: NewChannel[*model.TerminalLog](),messageLogAdded: NewChannel[*model.MessageLog](),diff --git a/backend/pkg/graph/subscriptions/publisher.go b/backend/pkg/graph/subscriptions/publisher.goindex 5cef04a7..d9da8153 100644--- a/backend/pkg/graph/subscriptions/publisher.go+++ b/backend/pkg/graph/subscriptions/publisher.go@@ -5,6 +5,7 @@ import ("pentagi/pkg/database""pentagi/pkg/database/converter"+ "pentagi/pkg/graph/model""pentagi/pkg/providers/pconfig")@@ -68,6 +69,18 @@ func (p *flowPublisher) AssistantDeleted(ctx context.Context, assistant databasep.ctrl.assistantDeleted.Publish(ctx, p.flowID, converter.ConvertAssistant(assistant))}+func (p *flowPublisher) FlowFileAdded(ctx context.Context, file *model.FlowFile) {+ p.ctrl.flowFileAdded.Publish(ctx, p.flowID, file)+}++func (p *flowPublisher) FlowFileUpdated(ctx context.Context, file *model.FlowFile) {+ p.ctrl.flowFileUpdated.Publish(ctx, p.flowID, file)+}++func (p *flowPublisher) FlowFileDeleted(ctx context.Context, file *model.FlowFile) {+ p.ctrl.flowFileDeleted.Publish(ctx, p.flowID, file)+}+func (p *flowPublisher) ScreenshotAdded(ctx context.Context, screenshot database.Screenshot) {p.ctrl.screenshotAdded.Publish(ctx, p.flowID, converter.ConvertScreenshot(screenshot))}diff --git a/backend/pkg/graph/subscriptions/subscriber.go b/backend/pkg/graph/subscriptions/subscriber.goindex 33e2033c..50d17a50 100644--- a/backend/pkg/graph/subscriptions/subscriber.go+++ b/backend/pkg/graph/subscriptions/subscriber.go@@ -72,6 +72,18 @@ func (s *flowSubscriber) AssistantDeleted(ctx context.Context) (<-chan *model.Asreturn s.ctrl.assistantDeleted.Subscribe(ctx, s.flowID), nil}+func (s *flowSubscriber) FlowFileAdded(ctx context.Context) (<-chan *model.FlowFile, error) {+ return s.ctrl.flowFileAdded.Subscribe(ctx, s.flowID), nil+}++func (s *flowSubscriber) FlowFileUpdated(ctx context.Context) (<-chan *model.FlowFile, error) {+ return s.ctrl.flowFileUpdated.Subscribe(ctx, s.flowID), nil+}++func (s *flowSubscriber) FlowFileDeleted(ctx context.Context) (<-chan *model.FlowFile, error) {+ return s.ctrl.flowFileDeleted.Subscribe(ctx, s.flowID), nil+}+func (s *flowSubscriber) ScreenshotAdded(ctx context.Context) (<-chan *model.Screenshot, error) {return s.ctrl.screenshotAdded.Subscribe(ctx, s.flowID), nil}diff --git a/backend/pkg/server/docs/docs.go b/backend/pkg/server/docs/docs.goindex 4b86a05f..84b4b286 100644--- a/backend/pkg/server/docs/docs.go+++ b/backend/pkg/server/docs/docs.go@@ -1861,6 +1861,390 @@ const docTemplate = `{}}},+ "/flows/{flowID}/files/": {+ "get": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "FlowFiles"+ ],+ "summary": "Retrieve flow files list",+ "parameters": [+ {+ "minimum": 0,+ "type": "integer",+ "description": "flow id",+ "name": "flowID",+ "in": "path",+ "required": true+ }+ ],+ "responses": {+ "200": {+ "description": "flow files list received successful",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/services.flowFiles"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "invalid flow files request data",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "getting flow files not permitted",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "flow not found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "internal error on getting flow files",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ },+ "post": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "consumes": [+ "multipart/form-data"+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "FlowFiles"+ ],+ "summary": "Upload files to flow workspace",+ "parameters": [+ {+ "minimum": 0,+ "type": "integer",+ "description": "flow id",+ "name": "flowID",+ "in": "path",+ "required": true+ },+ {+ "type": "file",+ "description": "files to upload (multipart, field name: files or file)",+ "name": "files",+ "in": "formData",+ "required": true+ }+ ],+ "responses": {+ "200": {+ "description": "flow files uploaded successful",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/services.flowFiles"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "invalid flow files request data",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "uploading flow files not permitted",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "flow not found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "409": {+ "description": "flow file already exists",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "internal error on uploading flow files",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ },+ "delete": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "FlowFiles"+ ],+ "summary": "Delete flow file or directory by cached path",+ "parameters": [+ {+ "minimum": 0,+ "type": "integer",+ "description": "flow id",+ "name": "flowID",+ "in": "path",+ "required": true+ },+ {+ "type": "string",+ "description": "relative path in cache: uploads/\u003cname\u003e or container/\u003cname\u003e",+ "name": "path",+ "in": "query",+ "required": true+ }+ ],+ "responses": {+ "200": {+ "description": "flow file deleted successful",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/services.flowFiles"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "invalid flow file request data",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "deleting flow file not permitted",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "flow file not found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "internal error on deleting flow file",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },+ "/flows/{flowID}/files/download": {+ "get": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "produces": [+ "application/octet-stream",+ "application/zip",+ "application/json"+ ],+ "tags": [+ "FlowFiles"+ ],+ "summary": "Download flow file or directory by cached path",+ "parameters": [+ {+ "minimum": 0,+ "type": "integer",+ "description": "flow id",+ "name": "flowID",+ "in": "path",+ "required": true+ },+ {+ "type": "string",+ "description": "relative path in cache: uploads/\u003cname\u003e or container/\u003cname\u003e",+ "name": "path",+ "in": "query",+ "required": true+ }+ ],+ "responses": {+ "200": {+ "description": "file content, or ZIP archive for directories",+ "schema": {+ "type": "file"+ }+ },+ "400": {+ "description": "invalid flow file request data",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "downloading flow file not permitted",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "flow file not found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "internal error on downloading flow file",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },+ "/flows/{flowID}/files/pull": {+ "post": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "consumes": [+ "application/json"+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "FlowFiles"+ ],+ "summary": "Pull a file or directory from the running container into the local cache",+ "parameters": [+ {+ "minimum": 0,+ "type": "integer",+ "description": "flow id",+ "name": "flowID",+ "in": "path",+ "required": true+ },+ {+ "description": "pull request",+ "name": "request",+ "in": "body",+ "required": true,+ "schema": {+ "$ref": "#/definitions/services.pullFlowFilesRequest"+ }+ }+ ],+ "responses": {+ "200": {+ "description": "container path synced to local cache",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/services.flowFiles"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "invalid pull request or container not running",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "pulling flow files not permitted",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "flow not found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "409": {+ "description": "cache entry already exists; set force=true to overwrite",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "internal error on pulling flow files",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },"/flows/{flowID}/graph": {"get": {"security": [@@ -7456,6 +7840,44 @@ const docTemplate = `{}}},+ "services.flowFile": {+ "type": "object",+ "properties": {+ "id": {+ "type": "string"+ },+ "isDir": {+ "type": "boolean"+ },+ "modifiedAt": {+ "type": "string"+ },+ "name": {+ "type": "string"+ },+ "path": {+ "description": "relative to flow data dir: \"uploads/\u003cx\u003e\" or \"container/\u003cx\u003e\"",+ "type": "string"+ },+ "size": {+ "type": "integer"+ }+ }+ },+ "services.flowFiles": {+ "type": "object",+ "properties": {+ "files": {+ "type": "array",+ "items": {+ "$ref": "#/definitions/services.flowFile"+ }+ },+ "total": {+ "type": "integer"+ }+ }+ },"services.flows": {"type": "object","properties": {@@ -7536,6 +7958,19 @@ const docTemplate = `{}}},+ "services.pullFlowFilesRequest": {+ "type": "object",+ "properties": {+ "force": {+ "description": "Force overwrites the local cache entry if it already exists.",+ "type": "boolean"+ },+ "path": {+ "description": "Path is an arbitrary path inside the container, e.g. \"/etc/nginx/conf\" or \"/work/uploads/report.txt\".",+ "type": "string"+ }+ }+ },"services.roles": {"type": "object","properties": {diff --git a/backend/pkg/server/docs/swagger.json b/backend/pkg/server/docs/swagger.jsonindex f0b37125..4f8cccd4 100644--- a/backend/pkg/server/docs/swagger.json+++ b/backend/pkg/server/docs/swagger.json@@ -1853,6 +1853,390 @@}}},+ "/flows/{flowID}/files/": {+ "get": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "FlowFiles"+ ],+ "summary": "Retrieve flow files list",+ "parameters": [+ {+ "minimum": 0,+ "type": "integer",+ "description": "flow id",+ "name": "flowID",+ "in": "path",+ "required": true+ }+ ],+ "responses": {+ "200": {+ "description": "flow files list received successful",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/services.flowFiles"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "invalid flow files request data",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "getting flow files not permitted",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "flow not found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "internal error on getting flow files",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ },+ "post": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "consumes": [+ "multipart/form-data"+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "FlowFiles"+ ],+ "summary": "Upload files to flow workspace",+ "parameters": [+ {+ "minimum": 0,+ "type": "integer",+ "description": "flow id",+ "name": "flowID",+ "in": "path",+ "required": true+ },+ {+ "type": "file",+ "description": "files to upload (multipart, field name: files or file)",+ "name": "files",+ "in": "formData",+ "required": true+ }+ ],+ "responses": {+ "200": {+ "description": "flow files uploaded successful",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/services.flowFiles"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "invalid flow files request data",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "uploading flow files not permitted",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "flow not found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "409": {+ "description": "flow file already exists",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "internal error on uploading flow files",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ },+ "delete": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "FlowFiles"+ ],+ "summary": "Delete flow file or directory by cached path",+ "parameters": [+ {+ "minimum": 0,+ "type": "integer",+ "description": "flow id",+ "name": "flowID",+ "in": "path",+ "required": true+ },+ {+ "type": "string",+ "description": "relative path in cache: uploads/\u003cname\u003e or container/\u003cname\u003e",+ "name": "path",+ "in": "query",+ "required": true+ }+ ],+ "responses": {+ "200": {+ "description": "flow file deleted successful",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/services.flowFiles"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "invalid flow file request data",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "deleting flow file not permitted",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "flow file not found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "internal error on deleting flow file",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },+ "/flows/{flowID}/files/download": {+ "get": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "produces": [+ "application/octet-stream",+ "application/zip",+ "application/json"+ ],+ "tags": [+ "FlowFiles"+ ],+ "summary": "Download flow file or directory by cached path",+ "parameters": [+ {+ "minimum": 0,+ "type": "integer",+ "description": "flow id",+ "name": "flowID",+ "in": "path",+ "required": true+ },+ {+ "type": "string",+ "description": "relative path in cache: uploads/\u003cname\u003e or container/\u003cname\u003e",+ "name": "path",+ "in": "query",+ "required": true+ }+ ],+ "responses": {+ "200": {+ "description": "file content, or ZIP archive for directories",+ "schema": {+ "type": "file"+ }+ },+ "400": {+ "description": "invalid flow file request data",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "downloading flow file not permitted",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "flow file not found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "internal error on downloading flow file",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },+ "/flows/{flowID}/files/pull": {+ "post": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "consumes": [+ "application/json"+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "FlowFiles"+ ],+ "summary": "Pull a file or directory from the running container into the local cache",+ "parameters": [+ {+ "minimum": 0,+ "type": "integer",+ "description": "flow id",+ "name": "flowID",+ "in": "path",+ "required": true+ },+ {+ "description": "pull request",+ "name": "request",+ "in": "body",+ "required": true,+ "schema": {+ "$ref": "#/definitions/services.pullFlowFilesRequest"+ }+ }+ ],+ "responses": {+ "200": {+ "description": "container path synced to local cache",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/services.flowFiles"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "invalid pull request or container not running",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "pulling flow files not permitted",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "flow not found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "409": {+ "description": "cache entry already exists; set force=true to overwrite",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "internal error on pulling flow files",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },"/flows/{flowID}/graph": {"get": {"security": [@@ -7448,6 +7832,44 @@}}},+ "services.flowFile": {+ "type": "object",+ "properties": {+ "id": {+ "type": "string"+ },+ "isDir": {+ "type": "boolean"+ },+ "modifiedAt": {+ "type": "string"+ },+ "name": {+ "type": "string"+ },+ "path": {+ "description": "relative to flow data dir: \"uploads/\u003cx\u003e\" or \"container/\u003cx\u003e\"",+ "type": "string"+ },+ "size": {+ "type": "integer"+ }+ }+ },+ "services.flowFiles": {+ "type": "object",+ "properties": {+ "files": {+ "type": "array",+ "items": {+ "$ref": "#/definitions/services.flowFile"+ }+ },+ "total": {+ "type": "integer"+ }+ }+ },"services.flows": {"type": "object","properties": {@@ -7528,6 +7950,19 @@}}},+ "services.pullFlowFilesRequest": {+ "type": "object",+ "properties": {+ "force": {+ "description": "Force overwrites the local cache entry if it already exists.",+ "type": "boolean"+ },+ "path": {+ "description": "Path is an arbitrary path inside the container, e.g. \"/etc/nginx/conf\" or \"/work/uploads/report.txt\".",+ "type": "string"+ }+ }+ },"services.roles": {"type": "object","properties": {diff --git a/backend/pkg/server/docs/swagger.yaml b/backend/pkg/server/docs/swagger.yamlindex 862c4917..98c1c1d3 100644--- a/backend/pkg/server/docs/swagger.yaml+++ b/backend/pkg/server/docs/swagger.yaml@@ -1360,6 +1360,31 @@ definitions:total:type: integertype: object+ services.flowFile:+ properties:+ id:+ type: string+ isDir:+ type: boolean+ modifiedAt:+ type: string+ name:+ type: string+ path:+ description: 'relative to flow data dir: "uploads/<x>" or "container/<x>"'+ type: string+ size:+ type: integer+ type: object+ services.flowFiles:+ properties:+ files:+ items:+ $ref: '#/definitions/services.flowFile'+ type: array+ total:+ type: integer+ type: objectservices.flows:properties:flows:@@ -1412,6 +1437,16 @@ definitions:total:type: integertype: object+ services.pullFlowFilesRequest:+ properties:+ force:+ description: Force overwrites the local cache entry if it already exists.+ type: boolean+ path:+ description: Path is an arbitrary path inside the container, e.g. "/etc/nginx/conf"+ or "/work/uploads/report.txt".+ type: string+ type: objectservices.roles:properties:roles:@@ -2797,6 +2832,245 @@ paths:summary: Retrieve container info by id and flow idtags:- Containers+ /flows/{flowID}/files/:+ delete:+ parameters:+ - description: flow id+ in: path+ minimum: 0+ name: flowID+ required: true+ type: integer+ - description: 'relative path in cache: uploads/<name> or container/<name>'+ in: query+ name: path+ required: true+ type: string+ produces:+ - application/json+ responses:+ "200":+ description: flow file deleted successful+ schema:+ allOf:+ - $ref: '#/definitions/SuccessResponse'+ - properties:+ data:+ $ref: '#/definitions/services.flowFiles'+ type: object+ "400":+ description: invalid flow file request data+ schema:+ $ref: '#/definitions/ErrorResponse'+ "403":+ description: deleting flow file not permitted+ schema:+ $ref: '#/definitions/ErrorResponse'+ "404":+ description: flow file not found+ schema:+ $ref: '#/definitions/ErrorResponse'+ "500":+ description: internal error on deleting flow file+ schema:+ $ref: '#/definitions/ErrorResponse'+ security:+ - BearerAuth: []+ summary: Delete flow file or directory by cached path+ tags:+ - FlowFiles+ get:+ parameters:+ - description: flow id+ in: path+ minimum: 0+ name: flowID+ required: true+ type: integer+ produces:+ - application/json+ responses:+ "200":+ description: flow files list received successful+ schema:+ allOf:+ - $ref: '#/definitions/SuccessResponse'+ - properties:+ data:+ $ref: '#/definitions/services.flowFiles'+ type: object+ "400":+ description: invalid flow files request data+ schema:+ $ref: '#/definitions/ErrorResponse'+ "403":+ description: getting flow files not permitted+ schema:+ $ref: '#/definitions/ErrorResponse'+ "404":+ description: flow not found+ schema:+ $ref: '#/definitions/ErrorResponse'+ "500":+ description: internal error on getting flow files+ schema:+ $ref: '#/definitions/ErrorResponse'+ security:+ - BearerAuth: []+ summary: Retrieve flow files list+ tags:+ - FlowFiles+ post:+ consumes:+ - multipart/form-data+ parameters:+ - description: flow id+ in: path+ minimum: 0+ name: flowID+ required: true+ type: integer+ - description: 'files to upload (multipart, field name: files or file)'+ in: formData+ name: files+ required: true+ type: file+ produces:+ - application/json+ responses:+ "200":+ description: flow files uploaded successful+ schema:+ allOf:+ - $ref: '#/definitions/SuccessResponse'+ - properties:+ data:+ $ref: '#/definitions/services.flowFiles'+ type: object+ "400":+ description: invalid flow files request data+ schema:+ $ref: '#/definitions/ErrorResponse'+ "403":+ description: uploading flow files not permitted+ schema:+ $ref: '#/definitions/ErrorResponse'+ "404":+ description: flow not found+ schema:+ $ref: '#/definitions/ErrorResponse'+ "409":+ description: flow file already exists+ schema:+ $ref: '#/definitions/ErrorResponse'+ "500":+ description: internal error on uploading flow files+ schema:+ $ref: '#/definitions/ErrorResponse'+ security:+ - BearerAuth: []+ summary: Upload files to flow workspace+ tags:+ - FlowFiles+ /flows/{flowID}/files/download:+ get:+ parameters:+ - description: flow id+ in: path+ minimum: 0+ name: flowID+ required: true+ type: integer+ - description: 'relative path in cache: uploads/<name> or container/<name>'+ in: query+ name: path+ required: true+ type: string+ produces:+ - application/octet-stream+ - application/zip+ - application/json+ responses:+ "200":+ description: file content, or ZIP archive for directories+ schema:+ type: file+ "400":+ description: invalid flow file request data+ schema:+ $ref: '#/definitions/ErrorResponse'+ "403":+ description: downloading flow file not permitted+ schema:+ $ref: '#/definitions/ErrorResponse'+ "404":+ description: flow file not found+ schema:+ $ref: '#/definitions/ErrorResponse'+ "500":+ description: internal error on downloading flow file+ schema:+ $ref: '#/definitions/ErrorResponse'+ security:+ - BearerAuth: []+ summary: Download flow file or directory by cached path+ tags:+ - FlowFiles+ /flows/{flowID}/files/pull:+ post:+ consumes:+ - application/json+ parameters:+ - description: flow id+ in: path+ minimum: 0+ name: flowID+ required: true+ type: integer+ - description: pull request+ in: body+ name: request+ required: true+ schema:+ $ref: '#/definitions/services.pullFlowFilesRequest'+ produces:+ - application/json+ responses:+ "200":+ description: container path synced to local cache+ schema:+ allOf:+ - $ref: '#/definitions/SuccessResponse'+ - properties:+ data:+ $ref: '#/definitions/services.flowFiles'+ type: object+ "400":+ description: invalid pull request or container not running+ schema:+ $ref: '#/definitions/ErrorResponse'+ "403":+ description: pulling flow files not permitted+ schema:+ $ref: '#/definitions/ErrorResponse'+ "404":+ description: flow not found+ schema:+ $ref: '#/definitions/ErrorResponse'+ "409":+ description: cache entry already exists; set force=true to overwrite+ schema:+ $ref: '#/definitions/ErrorResponse'+ "500":+ description: internal error on pulling flow files+ schema:+ $ref: '#/definitions/ErrorResponse'+ security:+ - BearerAuth: []+ summary: Pull a file or directory from the running container into the local+ cache+ tags:+ - FlowFiles/flows/{flowID}/graph:get:parameters:diff --git a/backend/pkg/server/response/errors.go b/backend/pkg/server/response/errors.goindex 89f75233..f53685f9 100644--- a/backend/pkg/server/response/errors.go+++ b/backend/pkg/server/response/errors.go@@ -115,6 +115,7 @@ var ErrFlowFilesInvalidRequest = NewHttpError(400, "FlowFiles.InvalidRequest", "var ErrFlowFilesNotFound = NewHttpError(404, "FlowFiles.NotFound", "flow file not found")var ErrFlowFilesInvalidData = NewHttpError(400, "FlowFiles.InvalidData", "invalid flow file data")var ErrFlowFilesAlreadyExists = NewHttpError(409, "FlowFiles.AlreadyExists", "flow file already exists")+var ErrFlowFilesContainerNotRunning = NewHttpError(400, "FlowFiles.ContainerNotRunning", "container is not running")// tasksdiff --git a/backend/pkg/server/router.go b/backend/pkg/server/router.goindex eb4c6f15..e175b83a 100644--- a/backend/pkg/server/router.go+++ b/backend/pkg/server/router.go@@ -16,6 +16,7 @@ import ("pentagi/pkg/config""pentagi/pkg/controller""pentagi/pkg/database"+ "pentagi/pkg/docker""pentagi/pkg/graph/subscriptions""pentagi/pkg/providers""pentagi/pkg/server/auth"@@ -79,6 +80,7 @@ func NewRouter(providers providers.ProviderController,controller controller.FlowController,subscriptions subscriptions.SubscriptionsController,+ dockerClient docker.DockerClient,) *gin.Engine {gin.SetMode(gin.ReleaseMode)if cfg.Debug {@@ -130,7 +132,7 @@ func NewRouter(roleService := services.NewRoleService(orm)providerService := services.NewProviderService(providers)flowService := services.NewFlowService(orm, providers, controller, subscriptions)- flowFileService := services.NewFlowFileService(orm, cfg.DataDir)+ flowFileService := services.NewFlowFileService(orm, cfg.DataDir, dockerClient, subscriptions)taskService := services.NewTaskService(orm)subtaskService := services.NewSubtaskService(orm)containerService := services.NewContainerService(orm)@@ -372,11 +374,11 @@ func setFlowsGroup(parent *gin.RouterGroup, svc *services.FlowService) {func setFlowFilesGroup(parent *gin.RouterGroup, svc *services.FlowFileService) {flowFilesGroup := parent.Group("/flows/:flowID/files"){- flowFilesGroup.GET("", svc.GetFlowFiles)flowFilesGroup.GET("/", svc.GetFlowFiles)- flowFilesGroup.POST("", svc.UploadFlowFiles)flowFilesGroup.POST("/", svc.UploadFlowFiles)- flowFilesGroup.GET("/:fileName", svc.DownloadFlowFile)+ flowFilesGroup.DELETE("/", svc.DeleteFlowFile)+ flowFilesGroup.GET("/download", svc.DownloadFlowFile)+ flowFilesGroup.POST("/pull", svc.PullFlowFiles)}}diff --git a/backend/pkg/server/services/flow_files.go b/backend/pkg/server/services/flow_files.goindex b3d20d33..f69ba444 100644--- a/backend/pkg/server/services/flow_files.go+++ b/backend/pkg/server/services/flow_files.go@@ -1,8 +1,12 @@package servicesimport (+ "archive/tar"+ "context""errors""fmt"+ "io"+ "mime""net/http""os""path"@@ -13,22 +17,30 @@ import ("strings""time"+ "pentagi/pkg/docker"+ "pentagi/pkg/flowfiles"+ "pentagi/pkg/graph/model"+ "pentagi/pkg/graph/subscriptions""pentagi/pkg/server/logger""pentagi/pkg/server/models""pentagi/pkg/server/response"+ "pentagi/pkg/tools"+ "github.com/docker/docker/api/types/container""github.com/gin-gonic/gin""github.com/jinzhu/gorm")-const flowUploadsDirName = "uploads"--var errFlowFileNotRegular = errors.New("flow file is not a regular file")-+// Local storage layout under {dataDir}/flow-{id}-data/:+//+// uploads/ ← user-uploaded files; also pushed to container /work/uploads/+// container/ ← files synced from the container via pull; never sent back to containertype flowFile struct {+ ID string `json:"id"`Name string `json:"name"`- Path string `json:"path"`+ Path string `json:"path"` // relative to flow data dir: "uploads/<x>" or "container/<x>"Size int64 `json:"size"`+ IsDir bool `json:"isDir"`ModifiedAt time.Time `json:"modifiedAt"`}@@ -37,18 +49,55 @@ type flowFiles struct {Total uint64 `json:"total"`}+type pullFlowFilesRequest struct {+ // Path is an arbitrary path inside the container, e.g. "/etc/nginx/conf" or "/work/uploads/report.txt".+ Path string `json:"path"`+ // Force overwrites the local cache entry if it already exists.+ Force bool `json:"force"`+}++type pendingUpload struct {+ fileName string+ dstPath string+ tmpPath string+}++// FlowFileService manages flow-scoped files with two distinct sources:+// - user uploads → {dataDir}/flow-{id}-data/uploads/ (also pushed to container /work/uploads/)+// - container sync → {dataDir}/flow-{id}-data/container/ (pulled from container, never sent back)type FlowFileService struct {- dataDir string- db *gorm.DB+ dataDir string+ db *gorm.DB+ dockerClient docker.DockerClient+ ss subscriptions.SubscriptionsController}-func NewFlowFileService(db *gorm.DB, dataDir string) *FlowFileService {+func NewFlowFileService(+ db *gorm.DB,+ dataDir string,+ dockerClient docker.DockerClient,+ ss subscriptions.SubscriptionsController,+) *FlowFileService {return &FlowFileService{- dataDir: dataDir,- db: db,+ dataDir: dataDir,+ db: db,+ dockerClient: dockerClient,+ ss: ss,}}+// GetFlowFiles is a function to return flow files list+// @Summary Retrieve flow files list+// @Tags FlowFiles+// @Produce json+// @Security BearerAuth+// @Param flowID path int true "flow id" minimum(0)+// @Success 200 {object} response.successResp{data=flowFiles} "flow files list received successful"+// @Failure 400 {object} response.errorResp "invalid flow files request data"+// @Failure 403 {object} response.errorResp "getting flow files not permitted"+// @Failure 404 {object} response.errorResp "flow not found"+// @Failure 500 {object} response.errorResp "internal error on getting flow files"+// @Router /flows/{flowID}/files/ [get]func (s *FlowFileService) GetFlowFiles(c *gin.Context) {flowID, err := parseFlowIDParam(c)if err != nil {@@ -75,6 +124,21 @@ func (s *FlowFileService) GetFlowFiles(c *gin.Context) {})}+// UploadFlowFiles is a function to upload files to the flow workspace+// @Summary Upload files to flow workspace+// @Tags FlowFiles+// @Accept mpfd+// @Produce json+// @Security BearerAuth+// @Param flowID path int true "flow id" minimum(0)+// @Param files formData file true "files to upload (multipart, field name: files or file)"+// @Success 200 {object} response.successResp{data=flowFiles} "flow files uploaded successful"+// @Failure 400 {object} response.errorResp "invalid flow files request data"+// @Failure 403 {object} response.errorResp "uploading flow files not permitted"+// @Failure 404 {object} response.errorResp "flow not found"+// @Failure 409 {object} response.errorResp "flow file already exists"+// @Failure 500 {object} response.errorResp "internal error on uploading flow files"+// @Router /flows/{flowID}/files/ [post]func (s *FlowFileService) UploadFlowFiles(c *gin.Context) {flowID, err := parseFlowIDParam(c)if err != nil {@@ -83,11 +147,13 @@ func (s *FlowFileService) UploadFlowFiles(c *gin.Context) {return}- if _, err := s.getFlow(c, flowID, true); err != nil {+ flow, err := s.getFlow(c, flowID, true)+ if err != nil {s.handleFlowLookupError(c, flowID, err)return}+ c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, flowfiles.MaxUploadRequestSize)multipartForm, err := c.MultipartForm()if err != nil {logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error reading multipart form")@@ -108,6 +174,13 @@ func (s *FlowFileService) UploadFlowFiles(c *gin.Context) {response.Error(c, response.ErrFlowFilesInvalidRequest, err)return}+ if len(fileHeaders) > flowfiles.MaxUploadFiles {+ err = fmt.Errorf("too many uploaded files: %d exceeds the maximum allowed count of %d",+ len(fileHeaders), flowfiles.MaxUploadFiles)+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("too many uploaded files")+ response.Error(c, response.ErrFlowFilesInvalidRequest, err)+ return+ }uploadDir := s.flowUploadsDir(flowID)if err := os.MkdirAll(uploadDir, 0755); err != nil {@@ -116,17 +189,50 @@ func (s *FlowFileService) UploadFlowFiles(c *gin.Context) {return}- savedFiles := make([]flowFile, 0, len(fileHeaders))- for _, fileHeader := range fileHeaders {- fileName, err := sanitizeFlowFileName(fileHeader.Filename)+ // Pre-validate all files before saving any to avoid partial writes on error.+ pending := make([]pendingUpload, 0, len(fileHeaders))+ var totalSize int64++ for _, fh := range fileHeaders {+ // SanitizeFileName strips path separators — only the basename is kept.+ // This prevents path traversal via crafted multipart filenames.+ fileName, err := flowfiles.SanitizeFileName(fh.Filename)if err != nil {logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("invalid uploaded file name")response.Error(c, response.ErrFlowFilesInvalidData, err)return}+ if fh.Size > flowfiles.MaxUploadFileSize {+ err = fmt.Errorf("file '%s' size %d bytes exceeds the maximum allowed upload size of %d bytes",+ fileName, fh.Size, flowfiles.MaxUploadFileSize)+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "file_name": fileName,+ }).Error("uploaded file too large")+ response.Error(c, response.ErrFlowFilesInvalidRequest, err)+ return+ }+ if fh.Size < 0 {+ err = fmt.Errorf("file '%s' has invalid size %d", fileName, fh.Size)+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "file_name": fileName,+ }).Error("uploaded file has invalid size")+ response.Error(c, response.ErrFlowFilesInvalidRequest, err)+ return+ }+ totalSize += fh.Size+ if totalSize > flowfiles.MaxUploadTotalSize {+ err = fmt.Errorf("uploaded files total size %d bytes exceeds the maximum allowed size of %d bytes",+ totalSize, flowfiles.MaxUploadTotalSize)+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("uploaded files total size too large")+ response.Error(c, response.ErrFlowFilesInvalidRequest, err)+ return+ }+dstPath := filepath.Join(uploadDir, fileName)- exists, err := flowFileExists(dstPath)+ exists, err := flowfiles.LocalEntryExists(dstPath)if err != nil {logger.FromContext(c).WithError(err).WithFields(map[string]any{"flow_id": flowID,@@ -145,35 +251,147 @@ func (s *FlowFileService) UploadFlowFiles(c *gin.Context) {return}- if err := c.SaveUploadedFile(fileHeader, dstPath); err != nil {+ pending = append(pending, pendingUpload{fileName: fileName, dstPath: dstPath})+ }++ // All files passed validation — write temporary files first to avoid partial commits on copy errors.+ for i := range pending {+ tmpPath, err := flowfiles.SaveUploadedFileToTemp(fileHeaders[i], uploadDir)+ if err != nil {logger.FromContext(c).WithError(err).WithFields(map[string]any{"flow_id": flowID,- "file_name": fileName,- }).Error("error saving uploaded file")+ "file_name": pending[i].fileName,+ }).Error("error saving uploaded file to temporary cache")+ cleanupPendingUploads(pending)response.Error(c, response.ErrInternal, err)return}+ pending[i].tmpPath = tmpPath+ }- info, err := regularFlowFileInfo(dstPath)+ // Temporary files are complete — move them into place, then push to container.+ savedFiles := make([]flowFile, 0, len(fileHeaders))+ for i := range pending {+ p := &pending[i]+ if err := os.Rename(p.tmpPath, p.dstPath); err != nil {+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "file_name": p.fileName,+ }).Error("error committing uploaded file")+ cleanupPendingUploads(pending)+ response.Error(c, response.ErrInternal, err)+ return+ }+ p.tmpPath = ""++ info, err := flowfiles.RegularFileInfo(p.dstPath)if err != nil {logger.FromContext(c).WithError(err).WithFields(map[string]any{"flow_id": flowID,- "file_name": fileName,+ "file_name": p.fileName,}).Error("error stating uploaded file")response.Error(c, response.ErrInternal, err)return}- savedFiles = append(savedFiles, newFlowFile(info))+ // Best-effort push to the running primary container so the file is+ // immediately visible at /work/uploads/<name> without a container restart.+ if pushErr := s.copyFileToContainer(c.Request.Context(), flowID, p.dstPath); pushErr != nil {+ logger.FromContext(c).WithError(pushErr).WithFields(map[string]any{+ "flow_id": flowID,+ "file_name": p.fileName,+ }).Warn("uploaded file saved locally but could not be pushed to container")+ }++ savedFiles = append(savedFiles, convertFlowFile(flowfiles.NewFile(info, flowfiles.UploadsDirName)))}sortFlowFiles(savedFiles)+ s.publishFlowFilesAdded(c.Request.Context(), flow, savedFiles)response.Success(c, http.StatusOK, flowFiles{Files: savedFiles,Total: uint64(len(savedFiles)),})}+// DeleteFlowFile is a function to delete a cached flow file or directory by path+// @Summary Delete flow file or directory by cached path+// @Tags FlowFiles+// @Produce json+// @Security BearerAuth+// @Param flowID path int true "flow id" minimum(0)+// @Param path query string true "relative path in cache: uploads/<name> or container/<name>"+// @Success 200 {object} response.successResp{data=flowFiles} "flow file deleted successful"+// @Failure 400 {object} response.errorResp "invalid flow file request data"+// @Failure 403 {object} response.errorResp "deleting flow file not permitted"+// @Failure 404 {object} response.errorResp "flow file not found"+// @Failure 500 {object} response.errorResp "internal error on deleting flow file"+// @Router /flows/{flowID}/files/ [delete]+func (s *FlowFileService) DeleteFlowFile(c *gin.Context) {+ flowID, err := parseFlowIDParam(c)+ if err != nil {+ logger.FromContext(c).WithError(err).Error("error parsing flow id")+ response.Error(c, response.ErrFlowFilesInvalidRequest, err)+ return+ }++ flow, err := s.getFlow(c, flowID, true)+ if err != nil {+ s.handleFlowLookupError(c, flowID, err)+ return+ }++ localPath, err := s.resolveCachedPath(flowID, c.Query("path"))+ if err != nil {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("invalid delete path")+ response.Error(c, response.ErrFlowFilesInvalidRequest, err)+ return+ }++ info, err := os.Lstat(localPath)+ if err != nil {+ if errors.Is(err, os.ErrNotExist) {+ response.Error(c, response.ErrFlowFilesNotFound, fmt.Errorf("'%s' not found in local cache", c.Query("path")))+ } else {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error reading cached flow file")+ response.Error(c, response.ErrInternal, err)+ }+ return+ }+ deletedFile := convertFlowFile(flowfiles.NewFileWithPath(info, filepath.ToSlash(c.Query("path"))))++ if err := s.deleteUploadFromContainer(c.Request.Context(), flowID, c.Query("path")); err != nil {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error deleting uploaded file from container")+ response.Error(c, response.ErrInternal, err)+ return+ }++ if err := os.RemoveAll(localPath); err != nil {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error deleting cached flow file")+ response.Error(c, response.ErrInternal, err)+ return+ }++ s.publishFlowFileDeleted(c.Request.Context(), flow, deletedFile)+ response.Success(c, http.StatusOK, flowFiles{+ Files: nil,+ Total: 0,+ })+}++// DownloadFlowFile is a function to download a flow file or directory (as ZIP) by cached path+// @Summary Download flow file or directory by cached path+// @Tags FlowFiles+// @Produce octet-stream,application/zip,json+// @Security BearerAuth+// @Param flowID path int true "flow id" minimum(0)+// @Param path query string true "relative path in cache: uploads/<name> or container/<name>"+// @Success 200 {file} file "file content, or ZIP archive for directories"+// @Failure 400 {object} response.errorResp "invalid flow file request data"+// @Failure 403 {object} response.errorResp "downloading flow file not permitted"+// @Failure 404 {object} response.errorResp "flow file not found"+// @Failure 500 {object} response.errorResp "internal error on downloading flow file"+// @Router /flows/{flowID}/files/download [get]func (s *FlowFileService) DownloadFlowFile(c *gin.Context) {flowID, err := parseFlowIDParam(c)if err != nil {@@ -187,29 +405,250 @@ func (s *FlowFileService) DownloadFlowFile(c *gin.Context) {return}- fileName, err := sanitizeFlowFileName(c.Param("fileName"))+ localPath, err := s.resolveCachedPath(flowID, c.Query("path"))if err != nil {- logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("invalid download file name")+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("invalid download path")response.Error(c, response.ErrFlowFilesInvalidRequest, err)return}- filePath := filepath.Join(s.flowUploadsDir(flowID), fileName)- _, err = regularFlowFileInfo(filePath)+ info, err := os.Lstat(localPath)if err != nil {- logger.FromContext(c).WithError(err).WithFields(map[string]any{- "flow_id": flowID,- "file_name": fileName,- }).Error("error reading flow file")- if errors.Is(err, os.ErrNotExist) || errors.Is(err, errFlowFileNotRegular) {- response.Error(c, response.ErrFlowFilesNotFound, err)+ if errors.Is(err, os.ErrNotExist) {+ response.Error(c, response.ErrFlowFilesNotFound, fmt.Errorf("'%s' not found in local cache", c.Query("path")))} else {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error reading cached flow file")response.Error(c, response.ErrInternal, err)}return}- c.FileAttachment(filePath, fileName)+ // Never serve symlinks — could point outside the flow data directory.+ if info.Mode()&os.ModeSymlink != 0 {+ response.Error(c, response.ErrFlowFilesNotFound, fmt.Errorf("'%s' not found in local cache", c.Query("path")))+ return+ }++ if info.IsDir() {+ name := filepath.Base(localPath)+ c.Header("Content-Disposition", mime.FormatMediaType("attachment", map[string]string{+ "filename": name + ".zip",+ }))+ c.Header("Content-Type", "application/zip")+ if err := flowfiles.ZipDirectory(c.Writer, localPath); err != nil {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error creating ZIP archive")+ }+ return+ }++ if !info.Mode().IsRegular() {+ response.Error(c, response.ErrFlowFilesNotFound, fmt.Errorf("'%s' not found in local cache", c.Query("path")))+ return+ }++ c.FileAttachment(localPath, filepath.Base(localPath))+}++// PullFlowFiles is a function to sync a path from the container into the local cache+// @Summary Pull a file or directory from the running container into the local cache+// @Tags FlowFiles+// @Accept json+// @Produce json+// @Security BearerAuth+// @Param flowID path int true "flow id" minimum(0)+// @Param request body pullFlowFilesRequest true "pull request"+// @Success 200 {object} response.successResp{data=flowFiles} "container path synced to local cache"+// @Failure 400 {object} response.errorResp "invalid pull request or container not running"+// @Failure 403 {object} response.errorResp "pulling flow files not permitted"+// @Failure 404 {object} response.errorResp "flow not found"+// @Failure 409 {object} response.errorResp "cache entry already exists; set force=true to overwrite"+// @Failure 500 {object} response.errorResp "internal error on pulling flow files"+// @Router /flows/{flowID}/files/pull [post]+func (s *FlowFileService) PullFlowFiles(c *gin.Context) {+ flowID, err := parseFlowIDParam(c)+ if err != nil {+ logger.FromContext(c).WithError(err).Error("error parsing flow id")+ response.Error(c, response.ErrFlowFilesInvalidRequest, err)+ return+ }++ flow, err := s.getFlow(c, flowID, true)+ if err != nil {+ s.handleFlowLookupError(c, flowID, err)+ return+ }++ var req pullFlowFilesRequest+ if err := c.ShouldBindJSON(&req); err != nil {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error parsing pull request")+ response.Error(c, response.ErrFlowFilesInvalidRequest, err)+ return+ }++ containerPath := strings.TrimSpace(req.Path)+ if containerPath == "" {+ err = errors.New("path is required")+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("missing container path in pull request")+ response.Error(c, response.ErrFlowFilesInvalidRequest, err)+ return+ }++ // Preserve the normalized container path under the local container cache:+ // /etc/nginx/conf/ → container/etc/nginx/conf/+ // /etc/nginx/nginx.conf → container/etc/nginx/nginx.conf+ cacheRelPath, err := flowfiles.SanitizeContainerCachePath(containerPath)+ if err != nil {+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "container_path": containerPath,+ }).Error("invalid container path")+ response.Error(c, response.ErrFlowFilesInvalidRequest, fmt.Errorf("invalid container path: %w", err))+ return+ }++ containerDir := s.flowContainerDir(flowID)+ localTarget := filepath.Join(containerDir, filepath.FromSlash(cacheRelPath))+ targetExists := false++ // Check for existing cache entry; honour force flag.+ if _, statErr := os.Lstat(localTarget); statErr == nil {+ targetExists = true+ if !req.Force {+ err = fmt.Errorf("'%s' already exists in the container cache; set force=true to overwrite", cacheRelPath)+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "cache_path": cacheRelPath,+ }).Error("pull target already exists")+ response.Error(c, response.ErrFlowFilesAlreadyExists, err)+ return+ }+ } else if !errors.Is(statErr, os.ErrNotExist) {+ logger.FromContext(c).WithError(statErr).WithField("flow_id", flowID).Error("error checking container cache entry")+ response.Error(c, response.ErrInternal, statErr)+ return+ }++ if err := os.MkdirAll(containerDir, 0755); err != nil {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error creating container cache directory")+ response.Error(c, response.ErrInternal, err)+ return+ }++ if s.dockerClient == nil {+ err = errors.New("docker client not configured on this server")+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("docker client unavailable for pull")+ response.Error(c, response.ErrInternal, err)+ return+ }++ containerName := primaryContainerName(flowID)+ running, err := s.dockerClient.IsContainerRunning(c.Request.Context(), containerName)+ if err != nil {+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "container_name": containerName,+ }).Error("error checking container status for pull")+ response.Error(c, response.ErrInternal, err)+ return+ }+ if !running {+ err = fmt.Errorf("container '%s' is not running; start the flow before pulling files", containerName)+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("container not running for pull")+ response.Error(c, response.ErrFlowFilesContainerNotRunning, err)+ return+ }++ reader, _, err := s.dockerClient.CopyFromContainer(c.Request.Context(), containerName, containerPath)+ if err != nil {+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "container_path": containerPath,+ }).Error("error copying from container")+ response.Error(c, response.ErrInternal, err)+ return+ }+ defer reader.Close()++ stagingDir, err := os.MkdirTemp(containerDir, ".pull-*")+ if err != nil {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error creating pull staging directory")+ response.Error(c, response.ErrInternal, err)+ return+ }+ defer os.RemoveAll(stagingDir)++ if err := flowfiles.ExtractTar(reader, stagingDir); err != nil {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error extracting container TAR archive")+ response.Error(c, response.ErrInternal, err)+ return+ }++ stagedTarget := flowfiles.ResolvePulledStagedTarget(stagingDir, cacheRelPath)+ if stagedTarget == "" {+ err = fmt.Errorf("pulled archive did not contain expected entry '%s'", cacheRelPath)+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "cache_path": cacheRelPath,+ }).Error("pulled container archive did not contain expected entry")+ response.Error(c, response.ErrInternal, err)+ return+ }+ if _, err := os.Lstat(stagedTarget); err != nil {+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "cache_path": cacheRelPath,+ }).Error("pulled container archive did not contain expected entry")+ response.Error(c, response.ErrInternal, err)+ return+ }++ if req.Force {+ if err := os.RemoveAll(localTarget); err != nil {+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "cache_path": cacheRelPath,+ }).Error("error removing existing cache entry before forced pull")+ response.Error(c, response.ErrInternal, err)+ return+ }+ }+ if err := os.MkdirAll(filepath.Dir(localTarget), 0755); err != nil {+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "cache_path": cacheRelPath,+ }).Error("error creating container cache parent directory")+ response.Error(c, response.ErrInternal, err)+ return+ }+ if err := os.Rename(stagedTarget, localTarget); err != nil {+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "cache_path": cacheRelPath,+ }).Error("error committing pulled container entry")+ response.Error(c, response.ErrInternal, err)+ return+ }++ info, err := os.Lstat(localTarget)+ if err != nil {+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "cache_path": cacheRelPath,+ }).Error("error stating synced container entry")+ response.Error(c, response.ErrInternal, err)+ return+ }++ synced := convertFlowFile(flowfiles.NewFileWithPath(info, path.Join(flowfiles.ContainerDirName, cacheRelPath)))+ if targetExists {+ s.publishFlowFileUpdated(c.Request.Context(), flow, synced)+ } else {+ s.publishFlowFilesAdded(c.Request.Context(), flow, []flowFile{synced})+ }+ response.Success(c, http.StatusOK, flowFiles{+ Files: []flowFile{synced},+ Total: 1,+ })}func (s *FlowFileService) getFlow(c *gin.Context, flowID uint64, writeAccess bool) (models.Flow, error) {@@ -232,34 +671,15 @@ func (s *FlowFileService) getFlow(c *gin.Context, flowID uint64, writeAccess booreturn flow, nil}+// listFlowFiles lists top-level uploads and recursive container cache entries.+// Container entries preserve pulled paths, e.g. container/etc/nginx/nginx.conf.func (s *FlowFileService) listFlowFiles(flowID uint64) ([]flowFile, error) {- entries, err := os.ReadDir(s.flowUploadsDir(flowID))+ files, err := flowfiles.List(s.dataDir, flowID)if err != nil {- if errors.Is(err, os.ErrNotExist) {- return []flowFile{}, nil- }return nil, err}- files := make([]flowFile, 0, len(entries))- for _, entry := range entries {- if entry.IsDir() || entry.Type()&os.ModeSymlink != 0 {- continue- }-- info, err := entry.Info()- if err != nil {- return nil, err- }- if !info.Mode().IsRegular() {- continue- }-- files = append(files, newFlowFile(info))- }-- sortFlowFiles(files)- return files, nil+ return convertFlowFiles(files.Files), nil}func (s *FlowFileService) handleFlowLookupError(c *gin.Context, flowID uint64, err error) {@@ -278,8 +698,155 @@ func (s *FlowFileService) handleFlowLookupError(c *gin.Context, flowID uint64, e}}+// flowDataDir returns the root of the flow-scoped local cache directory.+func (s *FlowFileService) flowDataDir(flowID uint64) string {+ return flowfiles.FlowDataDir(s.dataDir, flowID)+}++// flowUploadsDir returns the subdirectory for user-uploaded files.func (s *FlowFileService) flowUploadsDir(flowID uint64) string {- return filepath.Join(s.dataDir, fmt.Sprintf("flow-%d", flowID), flowUploadsDirName)+ return flowfiles.FlowUploadsDir(s.dataDir, flowID)+}++// flowContainerDir returns the subdirectory for files synced from the container.+func (s *FlowFileService) flowContainerDir(flowID uint64) string {+ return flowfiles.FlowContainerDir(s.dataDir, flowID)+}++// resolveCachedPath validates reqPath, ensures it starts with "uploads" or "container",+// and returns the absolute host path. Returns an error if the path would escape flowDataDir.+func (s *FlowFileService) resolveCachedPath(flowID uint64, reqPath string) (string, error) {+ return flowfiles.ResolveCachedPath(s.dataDir, flowID, reqPath)+}++// copyFileToContainer packages a single local file as a TAR archive and uploads it+// to the running primary container at /work/uploads/<filename>. Best-effort: errors are+// returned but callers should only log them as warnings.+func (s *FlowFileService) copyFileToContainer(ctx context.Context, flowID uint64, localFilePath string) error {+ if s.dockerClient == nil {+ return nil+ }++ containerName := primaryContainerName(flowID)+ running, err := s.dockerClient.IsContainerRunning(ctx, containerName)+ if err != nil || !running {+ return nil // container absent or not running — skip silently+ }++ info, err := flowfiles.RegularFileInfo(localFilePath)+ if err != nil {+ return fmt.Errorf("failed to stat local file: %w", err)+ }++ pr, pw := io.Pipe()+ errCh := make(chan error, 1)+ go func() {+ errCh <- writeSingleUploadTar(pw, localFilePath, info)+ }()++ copyErr := s.dockerClient.CopyToContainer(ctx, containerName, docker.WorkFolderPathInContainer, pr,+ container.CopyToContainerOptions{AllowOverwriteDirWithFile: true})+ pr.Close()+ writeErr := <-errCh+ if copyErr != nil {+ return copyErr+ }+ return writeErr+}++func writeSingleUploadTar(w *io.PipeWriter, localFilePath string, info os.FileInfo) error {+ tw := tar.NewWriter(w)+ defer w.Close()+ defer tw.Close()++ if err := tw.WriteHeader(&tar.Header{+ Typeflag: tar.TypeDir,+ Name: flowfiles.UploadsDirName,+ Mode: 0755,+ ModTime: time.Now(),+ }); err != nil {+ w.CloseWithError(err)+ return fmt.Errorf("failed to write uploads directory tar header: %w", err)+ }++ f, err := os.Open(localFilePath)+ if err != nil {+ w.CloseWithError(err)+ return fmt.Errorf("failed to open local file: %w", err)+ }+ defer f.Close()++ if err := tw.WriteHeader(&tar.Header{+ Typeflag: tar.TypeReg,+ Name: path.Join(flowfiles.UploadsDirName, filepath.Base(localFilePath)),+ Mode: 0644,+ Size: info.Size(),+ ModTime: info.ModTime(),+ }); err != nil {+ w.CloseWithError(err)+ return fmt.Errorf("failed to write tar header: %w", err)+ }+ if _, err := io.Copy(tw, f); err != nil {+ w.CloseWithError(err)+ return fmt.Errorf("failed to write tar content: %w", err)+ }++ return nil+}++func (s *FlowFileService) deleteUploadFromContainer(ctx context.Context, flowID uint64, reqPath string) error {+ if s.dockerClient == nil {+ return nil+ }++ cleaned := filepath.Clean(filepath.FromSlash(strings.ReplaceAll(reqPath, "\\", "/")))+ parts := strings.SplitN(cleaned, string(filepath.Separator), 2)+ if len(parts) == 0 || parts[0] != flowfiles.UploadsDirName {+ return nil+ }++ containerName := primaryContainerName(flowID)+ running, err := s.dockerClient.IsContainerRunning(ctx, containerName)+ if err != nil {+ return nil // container absent or unavailable — cache deletion will be synced on next start+ }+ if !running {+ return nil+ }++ containerPath := path.Join(docker.WorkFolderPathInContainer, filepath.ToSlash(cleaned))+ createResp, err := s.dockerClient.ContainerExecCreate(ctx, containerName, container.ExecOptions{+ Cmd: []string{"sh", "-c", fmt.Sprintf("rm -rf -- %s", shellQuote(containerPath))},+ AttachStdout: true,+ AttachStderr: true,+ })+ if err != nil {+ return fmt.Errorf("failed to create container delete exec: %w", err)+ }++ resp, err := s.dockerClient.ContainerExecAttach(ctx, createResp.ID, container.ExecAttachOptions{})+ if err != nil {+ return fmt.Errorf("failed to attach container delete exec: %w", err)+ }+ output, copyErr := io.ReadAll(resp.Reader)+ resp.Close()+ if copyErr != nil {+ return fmt.Errorf("failed to read container delete output: %w", copyErr)+ }++ inspect, err := s.dockerClient.ContainerExecInspect(ctx, createResp.ID)+ if err != nil {+ return fmt.Errorf("failed to inspect container delete exec: %w", err)+ }+ if inspect.ExitCode != 0 {+ return fmt.Errorf("container delete command failed with exit code %d: %s", inspect.ExitCode, string(output))+ }++ return nil+}++func shellQuote(value string) string {+ return "'" + strings.ReplaceAll(value, "'", "'\"'\"'") + "'"}func flowScopeForFiles(@@ -313,51 +880,70 @@ func parseFlowIDParam(c *gin.Context) (uint64, error) {return strconv.ParseUint(c.Param("flowID"), 10, 64)}-func sanitizeFlowFileName(fileName string) (string, error) {- trimmedName := strings.TrimSpace(fileName)- if trimmedName == "" {- return "", fmt.Errorf("file name is required")+func cleanupPendingUploads(pending []pendingUpload) {+ for _, p := range pending {+ if p.tmpPath != "" {+ os.Remove(p.tmpPath)+ }}+}- normalizedName := strings.ReplaceAll(trimmedName, "\\", "/")- cleanName := path.Base(path.Clean("/" + normalizedName))- if cleanName == "." || cleanName == "/" || cleanName == "" {- return "", fmt.Errorf("invalid file name")+func convertFlowFiles(files []flowfiles.File) []flowFile {+ converted := make([]flowFile, 0, len(files))+ for _, file := range files {+ converted = append(converted, convertFlowFile(file))}-- return cleanName, nil+ return converted}-func flowFileExists(filePath string) (bool, error) {- if _, err := os.Lstat(filePath); err != nil {- if errors.Is(err, os.ErrNotExist) {- return false, nil- }- return false, err+func convertFlowFile(file flowfiles.File) flowFile {+ return flowFile{+ ID: file.ID,+ Name: file.Name,+ Path: file.Path,+ Size: file.Size,+ IsDir: file.IsDir,+ ModifiedAt: file.ModifiedAt,}+}- return true, nil+func convertModelFlowFile(file flowFile) *model.FlowFile {+ return &model.FlowFile{+ Name: file.Name,+ Path: file.Path,+ Size: int(file.Size),+ IsDir: file.IsDir,+ ModifiedAt: file.ModifiedAt,+ }}-func regularFlowFileInfo(filePath string) (os.FileInfo, error) {- info, err := os.Lstat(filePath)- if err != nil {- return nil, err+func (s *FlowFileService) publishFlowFilesAdded(ctx context.Context, flow models.Flow, files []flowFile) {+ if s.ss == nil {+ return}- if !info.Mode().IsRegular() {- return nil, fmt.Errorf("%w: %s", errFlowFileNotRegular, filePath)++ publisher := s.ss.NewFlowPublisher(int64(flow.UserID), int64(flow.ID))+ for _, file := range files {+ publisher.FlowFileAdded(ctx, convertModelFlowFile(file))}+}- return info, nil+func (s *FlowFileService) publishFlowFileUpdated(ctx context.Context, flow models.Flow, file flowFile) {+ if s.ss == nil {+ return+ }++ publisher := s.ss.NewFlowPublisher(int64(flow.UserID), int64(flow.ID))+ publisher.FlowFileUpdated(ctx, convertModelFlowFile(file))}-func newFlowFile(info os.FileInfo) flowFile {- return flowFile{- Name: info.Name(),- Path: path.Join("/work", flowUploadsDirName, info.Name()),- Size: info.Size(),- ModifiedAt: info.ModTime(),+func (s *FlowFileService) publishFlowFileDeleted(ctx context.Context, flow models.Flow, file flowFile) {+ if s.ss == nil {+ return}++ publisher := s.ss.NewFlowPublisher(int64(flow.UserID), int64(flow.ID))+ publisher.FlowFileDeleted(ctx, convertModelFlowFile(file))}func sortFlowFiles(files []flowFile) {@@ -365,7 +951,11 @@ func sortFlowFiles(files []flowFile) {if files[i].ModifiedAt.Equal(files[j].ModifiedAt) {return files[i].Name < files[j].Name}-return files[i].ModifiedAt.After(files[j].ModifiedAt)})}++// primaryContainerName returns the Docker container name for a flow's primary terminal.+func primaryContainerName(flowID uint64) string {+ return fmt.Sprintf("%s%d", tools.PrimaryTerminalNamePrefix, flowID)+}diff --git a/backend/pkg/server/services/flow_files_test.go b/backend/pkg/server/services/flow_files_test.goindex 4e01f4e9..4254bef6 100644--- a/backend/pkg/server/services/flow_files_test.go+++ b/backend/pkg/server/services/flow_files_test.go@@ -1,130 +1,435 @@package servicesimport (+ "archive/tar"+ "archive/zip"+ "bytes"+ "io""os""path/filepath"+ "strconv""testing""time"+ "pentagi/pkg/flowfiles"+"github.com/stretchr/testify/assert""github.com/stretchr/testify/require")+// ── sanitizeFlowFileName ─────────────────────────────────────────────────────+func TestSanitizeFlowFileName(t *testing.T) {- testCases := []struct {+ tests := []struct {+ name string+ input stringexpected string- fileName string+ wantErr bool+ }{+ {"plain name", "report.txt", "report.txt", false},+ {"strips parent traversal", "../report.txt", "report.txt", false},+ {"normalizes windows separators", `nested\brief.md`, "brief.md", false},+ {"strips absolute path", "/etc/passwd", "passwd", false},+ {"strips deep traversal", "../../etc/shadow", "shadow", false},+ {"trims whitespace", " wordlist.txt ", "wordlist.txt", false},+ {"rejects empty", " ", "", true},+ {"rejects dot-only", ".", "", true},+ {"rejects root slash", "/", "", true},+ {"rejects control characters", "bad\nname.txt", "", true},+ {"rejects unsupported header characters", `bad"name.txt`, "", true},+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ got, err := flowfiles.SanitizeFileName(tt.input)+ if tt.wantErr {+ require.Error(t, err)+ return+ }+ require.NoError(t, err)+ assert.Equal(t, tt.expected, got)+ })+ }+}++func TestSanitizeContainerCachePath(t *testing.T) {+ tests := []struct {name string+ input string+ expected stringwantErr bool}{- {- name: "keeps plain file name",- fileName: "report.txt",- expected: "report.txt",- },- {- name: "collapses parent traversal",- fileName: "../report.txt",- expected: "report.txt",- },- {- name: "normalizes windows separators",- fileName: `nested\brief.md`,- expected: "brief.md",- },- {- name: "rejects empty names",- fileName: " ",- wantErr: true,- },- }-- for _, tc := range testCases {- t.Run(tc.name, func(t *testing.T) {- actual, err := sanitizeFlowFileName(tc.fileName)-- if tc.wantErr {+ {"absolute directory", "/etc/nginx/conf/", "etc/nginx/conf", false},+ {"absolute file", "/etc/nginx/nginx.conf", "etc/nginx/nginx.conf", false},+ {"relative file", "var/log/app.log", "var/log/app.log", false},+ {"normalizes traversal", "../../etc/shadow", "etc/shadow", false},+ {"rejects empty", " ", "", true},+ {"rejects root", "/", "", true},+ {"rejects bad component", "/etc/bad\nname", "", true},+ {"rejects unsupported component", `/etc/bad"name`, "", true},+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ got, err := flowfiles.SanitizeContainerCachePath(tt.input)+ if tt.wantErr {require.Error(t, err)return}+ require.NoError(t, err)+ assert.Equal(t, tt.expected, got)+ })+ }+}++// ── directory helpers ─────────────────────────────────────────────────────────++func TestFlowFileService_Dirs(t *testing.T) {+ svc := NewFlowFileService(nil, "/data", nil, nil)+ assert.Equal(t, "/data/flow-42-data", svc.flowDataDir(42))+ assert.Equal(t, "/data/flow-42-data/uploads", svc.flowUploadsDir(42))+ assert.Equal(t, "/data/flow-42-data/container", svc.flowContainerDir(42))+}++func TestMaxUploadFileSize(t *testing.T) {+ const expectedMaxMB = 300+ assert.Equal(t, int64(expectedMaxMB*1024*1024), int64(flowfiles.MaxUploadFileSize))+}++// ── resolveCachedPath ─────────────────────────────────────────────────────────+func TestResolveCachedPath(t *testing.T) {+ svc := NewFlowFileService(nil, "/data", nil, nil)++ tests := []struct {+ name string+ input string+ want string+ wantErr bool+ }{+ {"uploads file", "uploads/report.txt", "/data/flow-1-data/uploads/report.txt", false},+ {"container file", "container/conf/nginx.conf", "/data/flow-1-data/container/conf/nginx.conf", false},+ {"container top-level", "container/conf", "/data/flow-1-data/container/conf", false},+ {"empty path", "", "", true},+ {"wrong prefix", "tmp/evil.sh", "", true},+ {"absolute path", "/etc/passwd", "", true},+ {"path traversal", "uploads/../../etc/passwd", "", true},+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ got, err := svc.resolveCachedPath(1, tt.input)+ if tt.wantErr {+ require.Error(t, err)+ return+ }require.NoError(t, err)- assert.Equal(t, tc.expected, actual)+ assert.Equal(t, tt.want, got)})}}-func TestFlowFileService_ListFlowFiles(t *testing.T) {- dataDir := t.TempDir()- service := NewFlowFileService(nil, dataDir)- uploadDir := filepath.Join(dataDir, "flow-7", "uploads")+// ── listDirEntries ────────────────────────────────────────────────────────────- require.NoError(t, os.MkdirAll(uploadDir, 0755))- require.NoError(t, os.Mkdir(filepath.Join(uploadDir, "nested"), 0755))+func TestListDirEntries_Basic(t *testing.T) {+ dir := t.TempDir()+ require.NoError(t, os.WriteFile(filepath.Join(dir, "a.txt"), []byte("a"), 0644))+ require.NoError(t, os.Mkdir(filepath.Join(dir, "sub"), 0755))+ require.NoError(t, os.WriteFile(filepath.Join(dir, ".upload-temp"), []byte("tmp"), 0644))+ require.NoError(t, os.Mkdir(filepath.Join(dir, ".pull-temp"), 0755))+ _ = os.Symlink(filepath.Join(dir, "a.txt"), filepath.Join(dir, "link.txt"))- oldPath := filepath.Join(uploadDir, "old.txt")- newPath := filepath.Join(uploadDir, "new.txt")- linkPath := filepath.Join(uploadDir, "link.txt")+ entries, err := flowfiles.ListDirEntries(dir, "uploads")+ require.NoError(t, err)+ require.Len(t, entries, 2) // a.txt + sub; link.txt excluded- require.NoError(t, os.WriteFile(oldPath, []byte("old"), 0644))- require.NoError(t, os.WriteFile(newPath, []byte("newer content"), 0644))- _ = os.Symlink(newPath, linkPath)+ names := make([]string, len(entries))+ for i, e := range entries {+ names[i] = e.Name+ }+ assert.Contains(t, names, "a.txt")+ assert.Contains(t, names, "sub")+ assert.NotContains(t, names, ".upload-temp")+ assert.NotContains(t, names, ".pull-temp")+ assert.NotContains(t, names, "link.txt")- oldTime := time.Now().Add(-2 * time.Hour)- newTime := time.Now().Add(-1 * time.Hour)- require.NoError(t, os.Chtimes(oldPath, oldTime, oldTime))- require.NoError(t, os.Chtimes(newPath, newTime, newTime))+ for _, e := range entries {+ if e.Name == "sub" {+ assert.True(t, e.IsDir)+ assert.Equal(t, "uploads/sub", e.Path)+ } else {+ assert.False(t, e.IsDir)+ assert.Equal(t, "uploads/a.txt", e.Path)+ }+ }+}- files, err := service.listFlowFiles(7)+func TestListDirEntries_MissingDir(t *testing.T) {+ entries, err := flowfiles.ListDirEntries("/nonexistent/path", "uploads")require.NoError(t, err)- require.Len(t, files, 2)+ assert.Empty(t, entries)+}- assert.Equal(t, "new.txt", files[0].Name)- assert.Equal(t, "/work/uploads/new.txt", files[0].Path)- assert.Equal(t, int64(len("newer content")), files[0].Size)+func TestListDirEntriesRecursive_PreservesNestedPaths(t *testing.T) {+ dir := t.TempDir()+ require.NoError(t, os.MkdirAll(filepath.Join(dir, "etc", "nginx", "conf"), 0755))+ require.NoError(t, os.WriteFile(filepath.Join(dir, "etc", "nginx", "nginx.conf"), []byte("nginx"), 0644))+ require.NoError(t, os.Mkdir(filepath.Join(dir, ".pull-temp"), 0755))+ require.NoError(t, os.WriteFile(filepath.Join(dir, ".pull-temp", "tmp.txt"), []byte("tmp"), 0644))- assert.Equal(t, "old.txt", files[1].Name)- assert.Equal(t, "/work/uploads/old.txt", files[1].Path)- assert.Equal(t, int64(len("old")), files[1].Size)+ entries, err := flowfiles.ListDirEntriesRecursive(dir, "container")+ require.NoError(t, err)- for _, file := range files {- assert.NotEqual(t, "link.txt", file.Name)+ paths := make([]string, len(entries))+ for i, entry := range entries {+ paths[i] = entry.Path}+ assert.Contains(t, paths, "container/etc")+ assert.Contains(t, paths, "container/etc/nginx")+ assert.Contains(t, paths, "container/etc/nginx/conf")+ assert.Contains(t, paths, "container/etc/nginx/nginx.conf")+ assert.NotContains(t, paths, "container/.pull-temp")+ assert.NotContains(t, paths, "container/.pull-temp/tmp.txt")}-func TestFlowFileService_ListFlowFiles_MissingDirectory(t *testing.T) {- service := NewFlowFileService(nil, t.TempDir())+// ── listFlowFiles ─────────────────────────────────────────────────────────────++func TestFlowFileService_ListFlowFiles_BothSources(t *testing.T) {+ dataDir := t.TempDir()+ svc := NewFlowFileService(nil, dataDir, nil, nil)- files, err := service.listFlowFiles(999)+ uploadsDir := filepath.Join(dataDir, "flow-7-data", "uploads")+ containerDir := filepath.Join(dataDir, "flow-7-data", "container")+ require.NoError(t, os.MkdirAll(uploadsDir, 0755))+ require.NoError(t, os.MkdirAll(containerDir, 0755))++ require.NoError(t, os.WriteFile(filepath.Join(uploadsDir, "wordlist.txt"), []byte("words"), 0644))+ require.NoError(t, os.MkdirAll(filepath.Join(containerDir, "etc", "nginx", "conf"), 0755))+ require.NoError(t, os.WriteFile(filepath.Join(containerDir, "etc", "nginx", "nginx.conf"), []byte("nginx"), 0644))++ files, err := svc.listFlowFiles(7)+ require.NoError(t, err)++ paths := make([]string, len(files))+ for i, f := range files {+ paths[i] = f.Path+ }+ assert.Contains(t, paths, "uploads/wordlist.txt")+ assert.Contains(t, paths, "container/etc/nginx/conf")+ assert.Contains(t, paths, "container/etc/nginx/nginx.conf")+}++func TestFlowFileService_ListFlowFiles_EmptyDirs(t *testing.T) {+ svc := NewFlowFileService(nil, t.TempDir(), nil, nil)+ files, err := svc.listFlowFiles(999)require.NoError(t, err)assert.Empty(t, files)}-func TestFlowFileExists(t *testing.T) {+// ── localEntryExists ─────────────────────────────────────────────────────────++func TestLocalEntryExists(t *testing.T) {dir := t.TempDir()- filePath := filepath.Join(dir, "report.txt")+ p := filepath.Join(dir, "f.txt")- exists, err := flowFileExists(filePath)+ exists, err := flowfiles.LocalEntryExists(p)require.NoError(t, err)assert.False(t, exists)- require.NoError(t, os.WriteFile(filePath, []byte("report"), 0644))+ require.NoError(t, os.WriteFile(p, []byte("x"), 0644))- exists, err = flowFileExists(filePath)+ exists, err = flowfiles.LocalEntryExists(p)require.NoError(t, err)assert.True(t, exists)}-func TestRegularFlowFileInfoRejectsSymlink(t *testing.T) {- dir := t.TempDir()- filePath := filepath.Join(dir, "report.txt")- linkPath := filepath.Join(dir, "link.txt")+// ── isWithinDir ───────────────────────────────────────────────────────────────++func TestIsWithinDir(t *testing.T) {+ assert.True(t, flowfiles.IsWithinDir("/data/flow-1/uploads/file.txt", "/data/flow-1/uploads"))+ assert.True(t, flowfiles.IsWithinDir("/data/flow-1/uploads/sub/file.txt", "/data/flow-1/uploads"))+ assert.False(t, flowfiles.IsWithinDir("/data/flow-1/../evil.txt", "/data/flow-1/uploads"))+ assert.False(t, flowfiles.IsWithinDir("/data/flow-2/uploads/file.txt", "/data/flow-1/uploads"))+}++func TestResolvePulledStagedTarget(t *testing.T) {+ t.Run("full cache path archive", func(t *testing.T) {+ stagingDir := t.TempDir()+ target := filepath.Join(stagingDir, "etc", "nginx", "nginx.conf")+ require.NoError(t, os.MkdirAll(filepath.Dir(target), 0755))+ require.NoError(t, os.WriteFile(target, []byte("nginx"), 0644))++ assert.Equal(t, target, flowfiles.ResolvePulledStagedTarget(stagingDir, "etc/nginx/nginx.conf"))+ })++ t.Run("basename archive", func(t *testing.T) {+ stagingDir := t.TempDir()+ target := filepath.Join(stagingDir, "nginx.conf")+ require.NoError(t, os.WriteFile(target, []byte("nginx"), 0644))++ assert.Equal(t, target, flowfiles.ResolvePulledStagedTarget(stagingDir, "etc/nginx/nginx.conf"))+ })+}++// ── extractTar ────────────────────────────────────────────────────────────────++func buildTar(entries []tarTestEntry) *bytes.Buffer {+ var buf bytes.Buffer+ tw := tar.NewWriter(&buf)+ for _, e := range entries {+ hdr := &tar.Header{+ Name: e.name,+ Typeflag: e.typeflag,+ Mode: 0644,+ Size: int64(len(e.content)),+ Linkname: e.linkname,+ }+ if e.typeflag == tar.TypeDir {+ hdr.Mode = 0755+ }+ _ = tw.WriteHeader(hdr)+ if len(e.content) > 0 {+ _, _ = tw.Write([]byte(e.content))+ }+ }+ tw.Close()+ return &buf+}++type tarTestEntry struct {+ name string+ typeflag byte+ content string+ linkname string+}++func TestExtractTar_RegularFiles(t *testing.T) {+ destDir := t.TempDir()++ buf := buildTar([]tarTestEntry{+ {name: "dir/", typeflag: tar.TypeDir},+ {name: "dir/file.txt", typeflag: tar.TypeReg, content: "hello"},+ })++ require.NoError(t, flowfiles.ExtractTar(buf, destDir))++ data, err := os.ReadFile(filepath.Join(destDir, "dir", "file.txt"))+ require.NoError(t, err)+ assert.Equal(t, "hello", string(data))+}++func TestExtractTar_SkipsSymlinks(t *testing.T) {+ destDir := t.TempDir()++ buf := buildTar([]tarTestEntry{+ {name: "link.txt", typeflag: tar.TypeSymlink, linkname: "/etc/passwd"},+ })++ require.NoError(t, flowfiles.ExtractTar(buf, destDir))++ _, err := os.Lstat(filepath.Join(destDir, "link.txt"))+ assert.True(t, os.IsNotExist(err), "symlink must not be created in cache")+}++func TestExtractTar_PathTraversal(t *testing.T) {+ destDir := t.TempDir()++ buf := buildTar([]tarTestEntry{+ {name: "../../evil.txt", typeflag: tar.TypeReg, content: "evil"},+ })++ require.NoError(t, flowfiles.ExtractTar(buf, destDir))++ // evil.txt must NOT appear outside destDir+ evilPath := filepath.Join(filepath.Dir(destDir), "evil.txt")+ _, err := os.Lstat(evilPath)+ assert.True(t, os.IsNotExist(err), "path traversal file must not be created")+}++func TestExtractTar_RejectsTooManyFiles(t *testing.T) {+ destDir := t.TempDir()+ entries := make([]tarTestEntry, 0, flowfiles.MaxPullFiles+1)+ for i := 0; i < flowfiles.MaxPullFiles+1; i++ {+ entries = append(entries, tarTestEntry{+ name: filepath.Join("many", "file-"+strconv.Itoa(i)+".txt"),+ typeflag: tar.TypeReg,+ content: "x",+ })+ }++ err := flowfiles.ExtractTar(buildTar(entries), destDir)+ require.Error(t, err)+ assert.Contains(t, err.Error(), "maximum file count")+}++// ── zipDirectory ─────────────────────────────────────────────────────────────++func TestZipDirectory(t *testing.T) {+ src := t.TempDir()+ require.NoError(t, os.WriteFile(filepath.Join(src, "a.txt"), []byte("hello"), 0644))+ require.NoError(t, os.MkdirAll(filepath.Join(src, "sub"), 0755))+ require.NoError(t, os.WriteFile(filepath.Join(src, "sub", "b.txt"), []byte("world"), 0644))++ var buf bytes.Buffer+ require.NoError(t, flowfiles.ZipDirectory(&buf, src))++ zr, err := zip.NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()))+ require.NoError(t, err)++ contents := make(map[string]string)+ for _, f := range zr.File {+ rc, err := f.Open()+ require.NoError(t, err)+ data, _ := io.ReadAll(rc)+ rc.Close()+ contents[f.Name] = string(data)+ }+ assert.Equal(t, "hello", contents["a.txt"])+ assert.Equal(t, "world", contents["sub/b.txt"])+}++func TestZipDirectory_ExcludesSymlinks(t *testing.T) {+ src := t.TempDir()+ target := filepath.Join(src, "real.txt")+ link := filepath.Join(src, "link.txt")+ require.NoError(t, os.WriteFile(target, []byte("real"), 0644))+ if err := os.Symlink(target, link); err != nil {+ t.Skipf("symlink creation not available: %v", err)+ }++ var buf bytes.Buffer+ require.NoError(t, flowfiles.ZipDirectory(&buf, src))++ zr, err := zip.NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()))+ require.NoError(t, err)++ names := make([]string, len(zr.File))+ for i, f := range zr.File {+ names[i] = f.Name+ }+ assert.Contains(t, names, "real.txt")+ assert.NotContains(t, names, "link.txt")+}++// ── primaryContainerName ─────────────────────────────────────────────────────++func TestPrimaryContainerName(t *testing.T) {+ assert.Equal(t, "pentagi-terminal-42", primaryContainerName(42))+}++// ── sorting ───────────────────────────────────────────────────────────────────- require.NoError(t, os.WriteFile(filePath, []byte("report"), 0644))- if err := os.Symlink(filePath, linkPath); err != nil {- t.Skipf("symlink creation is not available: %v", err)+func TestSortFlowFiles(t *testing.T) {+ now := time.Now()+ files := []flowFile{+ {Name: "b.txt", ModifiedAt: now.Add(-2 * time.Hour)},+ {Name: "a.txt", ModifiedAt: now.Add(-1 * time.Hour)},+ {Name: "c.txt", ModifiedAt: now.Add(-1 * time.Hour)},}+ sortFlowFiles(files)- _, err := regularFlowFileInfo(linkPath)- require.ErrorIs(t, err, errFlowFileNotRegular)+ // Newer first; ties broken alphabetically.+ assert.Equal(t, "a.txt", files[0].Name)+ assert.Equal(t, "c.txt", files[1].Name)+ assert.Equal(t, "b.txt", files[2].Name)}diff --git a/backend/pkg/tools/terminal.go b/backend/pkg/tools/terminal.goindex c287c8d1..1a560c95 100644--- a/backend/pkg/tools/terminal.go+++ b/backend/pkg/tools/terminal.go@@ -21,6 +21,9 @@ import ("github.com/sirupsen/logrus")+// PrimaryTerminalNamePrefix is the prefix used for all primary terminal container names.+const PrimaryTerminalNamePrefix = "pentagi-terminal-"+const (maxExplicitExecCommandTimeout = 3 * time.HourdefaultExtraExecTimeout = 5 * time.Second@@ -443,7 +446,7 @@ func (t *terminal) WriteFile(ctx context.Context, flowID int64, content string,}func PrimaryTerminalName(flowID int64) string {- return fmt.Sprintf("pentagi-terminal-%d", flowID)+ return fmt.Sprintf("%s%d", PrimaryTerminalNamePrefix, flowID)}func (t *terminal) IsAvailable() bool {diff --git a/backend/pkg/tools/terminal_test.go b/backend/pkg/tools/terminal_test.goindex f4ed086b..0a65773b 100644--- a/backend/pkg/tools/terminal_test.go+++ b/backend/pkg/tools/terminal_test.go@@ -1,16 +1,21 @@package toolsimport (+ "archive/tar""bufio"+ "bytes""context""fmt""io""net"+ "os"+ "path/filepath""testing""time""pentagi/pkg/database""pentagi/pkg/docker"+ "pentagi/pkg/flowfiles""github.com/docker/docker/api/types""github.com/docker/docker/api/types/container"@@ -193,9 +198,9 @@ func TestPrimaryTerminalName(t *testing.T) {flowID int64want string}{- {1, "pentagi-terminal-1"},- {0, "pentagi-terminal-0"},- {12345, "pentagi-terminal-12345"},+ {1, PrimaryTerminalNamePrefix + "1"},+ {0, PrimaryTerminalNamePrefix + "0"},+ {12345, PrimaryTerminalNamePrefix + "12345"},}for _, tt := range tests {@@ -209,6 +214,52 @@ func TestPrimaryTerminalName(t *testing.T) {}}+func TestWriteUploadsTar(t *testing.T) {+ uploadDir := t.TempDir()+ requireNoError := func(err error) {+ if err != nil {+ t.Fatal(err)+ }+ }+ requireNoError(os.WriteFile(filepath.Join(uploadDir, "a.txt"), []byte("alpha"), 0644))+ requireNoError(os.Mkdir(filepath.Join(uploadDir, "sub"), 0755))+ requireNoError(os.WriteFile(filepath.Join(uploadDir, "sub", "b.txt"), []byte("bravo"), 0644))+ if err := os.Symlink(filepath.Join(uploadDir, "a.txt"), filepath.Join(uploadDir, "link.txt")); err != nil {+ t.Skipf("symlink creation not available: %v", err)+ }++ pr, pw := io.Pipe()+ errCh := make(chan error, 1)+ go func() {+ errCh <- flowfiles.WriteUploadsTar(pw, uploadDir)+ }()++ var buf bytes.Buffer+ _, err := io.Copy(&buf, pr)+ assert.NoError(t, err)+ assert.NoError(t, <-errCh)++ tr := tar.NewReader(bytes.NewReader(buf.Bytes()))+ contents := map[string]string{}+ for {+ hdr, err := tr.Next()+ if err == io.EOF {+ break+ }+ assert.NoError(t, err)+ if hdr.Typeflag != tar.TypeReg {+ continue+ }+ data, err := io.ReadAll(tr)+ assert.NoError(t, err)+ contents[hdr.Name] = string(data)+ }++ assert.Equal(t, "alpha", contents["uploads/a.txt"])+ assert.Equal(t, "bravo", contents["uploads/sub/b.txt"])+ assert.NotContains(t, contents, "uploads/link.txt")+}+func TestConfiguredExecTimeout(t *testing.T) {t.Parallel()diff --git a/backend/pkg/tools/tools.go b/backend/pkg/tools/tools.goindex 7760bbdc..cf986b14 100644--- a/backend/pkg/tools/tools.go+++ b/backend/pkg/tools/tools.go@@ -4,11 +4,15 @@ import ("context""encoding/json""fmt"+ "io"+ "os"+ "path/filepath""time""pentagi/pkg/config""pentagi/pkg/database""pentagi/pkg/docker"+ "pentagi/pkg/flowfiles""pentagi/pkg/graphiti""pentagi/pkg/providers/embeddings""pentagi/pkg/schema"@@ -410,6 +414,9 @@ func (fte *flowToolsExecutor) Prepare(ctx context.Context) error {case database.ContainerStatusRunning:fte.primaryID = cnt.IDfte.primaryLID = cnt.LocalID.String+ if err := fte.syncCachedUploads(ctx); err != nil {+ return fmt.Errorf("failed to sync cached uploads to container '%s': %w", PrimaryTerminalName(fte.flowID), err)+ }return nildefault:fte.docker.RemoveContainer(ctx, cnt.LocalID.String, cnt.ID)@@ -442,9 +449,92 @@ func (fte *flowToolsExecutor) Prepare(ctx context.Context) error {fte.primaryID = cnt.IDfte.primaryLID = cnt.LocalID.String+ if err := fte.syncCachedUploads(ctx); err != nil {+ return fmt.Errorf("failed to sync cached uploads to container '%s': %w", containerName, err)+ }++ return nil+}++func (fte *flowToolsExecutor) syncCachedUploads(ctx context.Context) error {+ uploadDir, err := fte.cachedUploadsDir()+ if err != nil {+ return err+ }++ containerName := PrimaryTerminalName(fte.flowID)+ if err := fte.resetContainerUploads(ctx, containerName); err != nil {+ return err+ }++ entries, err := os.ReadDir(uploadDir)+ if err != nil {+ if os.IsNotExist(err) {+ return nil+ }+ return fmt.Errorf("failed to read uploads cache directory: %w", err)+ }+ if len(entries) == 0 {+ return nil+ }++ pr, pw := io.Pipe()+ errCh := make(chan error, 1)+ go func() {+ errCh <- flowfiles.WriteUploadsTar(pw, uploadDir)+ }()++ copyErr := fte.docker.CopyToContainer(ctx, containerName, docker.WorkFolderPathInContainer, pr,+ container.CopyToContainerOptions{AllowOverwriteDirWithFile: true})+ pr.Close()+ writeErr := <-errCh+ if copyErr != nil {+ return copyErr+ }++ return writeErr+}++func (fte *flowToolsExecutor) resetContainerUploads(ctx context.Context, containerName string) error {+ createResp, err := fte.docker.ContainerExecCreate(ctx, containerName, container.ExecOptions{+ Cmd: []string{"sh", "-c", "rm -rf -- /work/uploads && mkdir -p -- /work/uploads"},+ AttachStdout: true,+ AttachStderr: true,+ })+ if err != nil {+ return fmt.Errorf("failed to create uploads reset exec: %w", err)+ }++ resp, err := fte.docker.ContainerExecAttach(ctx, createResp.ID, container.ExecAttachOptions{})+ if err != nil {+ return fmt.Errorf("failed to attach uploads reset exec: %w", err)+ }+ output, copyErr := io.ReadAll(resp.Reader)+ resp.Close()+ if copyErr != nil {+ return fmt.Errorf("failed to read uploads reset output: %w", copyErr)+ }++ inspect, err := fte.docker.ContainerExecInspect(ctx, createResp.ID)+ if err != nil {+ return fmt.Errorf("failed to inspect uploads reset exec: %w", err)+ }+ if inspect.ExitCode != 0 {+ return fmt.Errorf("uploads reset command failed with exit code %d: %s", inspect.ExitCode, string(output))+ }+return nil}+func (fte *flowToolsExecutor) cachedUploadsDir() (string, error) {+ dataDir, err := filepath.Abs(fte.cfg.DataDir)+ if err != nil {+ return "", fmt.Errorf("failed to resolve data directory: %w", err)+ }++ return flowfiles.FlowUploadsDir(dataDir, uint64(fte.flowID)), nil+}+func (fte *flowToolsExecutor) Release(ctx context.Context) error {if fte.store != nil {fte.store.Close()diff --git a/frontend/graphql-schema.graphql b/frontend/graphql-schema.graphqlindex 9da3fb8c..eb1cc4e6 100644--- a/frontend/graphql-schema.graphql+++ b/frontend/graphql-schema.graphql@@ -89,6 +89,15 @@ fragment screenshotFragment on Screenshot {createdAt}+fragment flowFileFragment on FlowFile {+ id+ name+ path+ size+ isDir+ modifiedAt+}+fragment agentLogFragment on AgentLog {idflowId@@ -772,6 +781,12 @@ query tasks($flowId: ID!) {}}+query flowFiles($flowId: ID!) {+ flowFiles(flowId: $flowId) {+ ...flowFileFragment+ }+}+query assistants($flowId: ID!) {assistants(flowId: $flowId) {...assistantFragment@@ -1141,6 +1156,24 @@ subscription assistantDeleted($flowId: ID!) {}}+subscription flowFileAdded($flowId: ID!) {+ flowFileAdded(flowId: $flowId) {+ ...flowFileFragment+ }+}++subscription flowFileUpdated($flowId: ID!) {+ flowFileUpdated(flowId: $flowId) {+ ...flowFileFragment+ }+}++subscription flowFileDeleted($flowId: ID!) {+ flowFileDeleted(flowId: $flowId) {+ ...flowFileFragment+ }+}+subscription assistantLogAdded($flowId: ID!) {assistantLogAdded(flowId: $flowId) {...assistantLogFragmentdiff --git a/frontend/src/features/flows/files/flow-files.tsx b/frontend/src/features/flows/files/flow-files.tsxindex fce6c5fa..f44bccfd 100644--- a/frontend/src/features/flows/files/flow-files.tsx+++ b/frontend/src/features/flows/files/flow-files.tsx@@ -1,11 +1,42 @@-import { AlertCircle, Copy, Download, FileUp, FolderUp, Loader2, RefreshCw } from 'lucide-react';+import { zodResolver } from '@hookform/resolvers/zod';+import debounce from 'lodash/debounce';+import {+ ArrowDownToLine,+ Copy,+ Download,+ File,+ Folder,+ FolderUp,+ HardDrive,+ Info,+ Loader2,+ Search,+ Trash2,+ X,+} from 'lucide-react';import { useCallback, useEffect, useMemo, useRef, useState } from 'react';+import { useForm } from 'react-hook-form';import { toast } from 'sonner';+import { z } from 'zod';+import ConfirmationDialog from '@/components/shared/confirmation-dialog';import { Button, buttonVariants } from '@/components/ui/button';+import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog';import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';+import { Form, FormControl, FormField } from '@/components/ui/form';+import { Input } from '@/components/ui/input';import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from '@/components/ui/input-group';+import { Label } from '@/components/ui/label';+import { Switch } from '@/components/ui/switch';import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';+import {+ type FlowFileFragmentFragment,+ StatusType,+ useFlowFileAddedSubscription,+ useFlowFileDeletedSubscription,+ useFlowFilesQuery,+ useFlowFileUpdatedSubscription,+} from '@/graphql/types';import { axios } from '@/lib/axios';import { copyToClipboard } from '@/lib/report';import { cn } from '@/lib/utils';@@ -13,32 +44,76 @@ import { formatDate } from '@/lib/utils/format';import { baseUrl } from '@/models/api';import { useFlow } from '@/providers/flow-provider';+// ── types ─────────────────────────────────────────────────────────────────────++interface ApiErrorData {+ code?: string;+ msg?: string;+}+interface ApiResponse<T> {data?: T;status: string;}-interface FlowFile {- modifiedAt: string;- name: string;- path: string;- size: number;+interface AxiosLikeError {+ message?: string;+ response?: { data?: ApiErrorData; status?: number };+ statusCode?: number;}+type FileSource = 'container' | 'unknown' | 'uploads';+type FlowFile = FlowFileFragmentFragment;+interface FlowFilesResponse {files: Array<FlowFile>;total: number;}+interface FlowFileTreeItem {+ depth: number;+ file: FlowFile;+}++const searchFormSchema = z.object({+ search: z.string(),+});+const unwrapFlowFilesResponse = (response: ApiResponse<FlowFilesResponse>) => {if (response.status !== 'success' || !response.data) {- throw new Error('Unexpected flow files response');+ throw new Error('Unexpected response from server');}return response.data;};-const formatFileSize = (size: number) => {+const getErrorMessage = (error: unknown, fallback: string): string => {+ const err = error as AxiosLikeError;++ if (err.statusCode === 409 || err.response?.status === 409) {+ return err.response?.data?.msg ?? 'Entry already exists — enable "Overwrite" to replace it';+ }++ if (err.statusCode === 400 || err.response?.status === 400) {+ return err.response?.data?.msg ?? err.message ?? fallback;+ }++ return err.message ?? fallback;+};++const fileSource = (filePath: string): FileSource => {+ if (filePath.startsWith('container/') || filePath === 'container') {+ return 'container';+ }++ if (filePath.startsWith('uploads/') || filePath === 'uploads') {+ return 'uploads';+ }++ return 'unknown';+};++const formatFileSize = (size: number): string => {if (size < 1024) {return `${size} B`;}@@ -55,55 +130,340 @@ const formatFileSize = (size: number) => {return `${value.toFixed(value >= 10 ? 0 : 1)} ${units[unitIndex]}`;};-const FlowFiles = () => {- const { flowId } = useFlow();- const inputRef = useRef<HTMLInputElement | null>(null);- const [files, setFiles] = useState<Array<FlowFile>>([]);- const [isLoading, setIsLoading] = useState(false);- const [isUploading, setIsUploading] = useState(false);- const [searchValue, setSearchValue] = useState('');+const buildDownloadHref = (flowId: null | string, file: FlowFile) =>+ `${baseUrl}/flows/${flowId}/files/download?path=${encodeURIComponent(file.path)}`;++const filePathParts = (filePath: string) => filePath.split('/').filter(Boolean);++const flowFileDepth = (filePath: string): number => {+ const parts = filePathParts(filePath);++ return Math.max(parts.length - 2, 0);+};++const compareFlowFileTreePath = (a: FlowFile, b: FlowFile): number => {+ const aParts = filePathParts(a.path).slice(1);+ const bParts = filePathParts(b.path).slice(1);+ const length = Math.min(aParts.length, bParts.length);++ for (let i = 0; i < length; i += 1) {+ const partCompare = (aParts[i] ?? '').localeCompare(bParts[i] ?? '');++ if (partCompare !== 0) {+ return partCompare;+ }+ }++ return aParts.length - bParts.length;+};++const buildFlowFileTree = (files: FlowFile[]): FlowFileTreeItem[] =>+ [...files].sort(compareFlowFileTreePath).map((file) => ({+ depth: flowFileDepth(file.path),+ file,+ }));- const loadFiles = useCallback(async () => {- if (!flowId) {- setFiles([]);+// ── section header ─────────────────────────────────────────────────────────────+const SectionHeader = ({ children, icon }: { children: React.ReactNode; icon: React.ReactNode }) => (+ <div className="flex items-center gap-2 py-1">+ <div className="text-muted-foreground flex items-center gap-1.5 text-xs font-medium">+ {icon}+ {children}+ </div>+ <div className="bg-border h-px flex-1" />+ </div>+);++// ── file item ──────────────────────────────────────────────────────────────────++interface FlowFileItemProps {+ depth?: number;+ file: FlowFile;+ flowId: null | string;+ onCopyPath: (path: string) => void;+ onDelete: (file: FlowFile) => void;+}++const FlowFileItem = ({ depth = 0, file, flowId, onCopyPath, onDelete }: FlowFileItemProps) => (+ <div+ className="flex flex-col items-start"+ style={{ paddingLeft: depth * 20 }}+ >+ <div className="bg-card text-card-foreground w-full rounded-xl border p-3 shadow-sm">+ <div className="flex items-center justify-between gap-2">+ <div className="flex min-w-0 flex-1 items-center gap-2">+ {file.isDir ? (+ <Folder className="text-muted-foreground size-4 shrink-0" />+ ) : (+ <File className="text-muted-foreground size-4 shrink-0" />+ )}+ <span className="truncate text-sm font-semibold">{file.name}</span>+ </div>++ <Tooltip>+ <TooltipTrigger asChild>+ <a+ className={cn(buttonVariants({ size: 'icon-xs', variant: 'ghost' }))}+ download={file.isDir ? `${file.name}.zip` : file.name}+ href={buildDownloadHref(flowId, file)}+ >+ <Download className="size-3.5" />+ </a>+ </TooltipTrigger>+ <TooltipContent>{file.isDir ? 'Download as ZIP' : 'Download'}</TooltipContent>+ </Tooltip>++ <Tooltip>+ <TooltipTrigger asChild>+ <Button+ onClick={() => onDelete(file)}+ size="icon-xs"+ type="button"+ variant="ghost"+ >+ <Trash2 className="size-3.5" />+ </Button>+ </TooltipTrigger>+ <TooltipContent>{file.isDir ? 'Delete directory' : 'Delete file'}</TooltipContent>+ </Tooltip>+ </div>+ </div>++ <div className="text-muted-foreground mt-1 flex items-center gap-1 px-1 text-xs">+ {!file.isDir && (+ <>+ <span className="text-muted-foreground/50">{formatFileSize(file.size)}</span>+ <span className="text-muted-foreground/30">·</span>+ </>+ )}+ <Tooltip>+ <TooltipTrigger asChild>+ <Copy+ className="hover:text-foreground size-3 shrink-0 cursor-pointer transition-colors"+ onClick={() => onCopyPath(file.path)}+ />+ </TooltipTrigger>+ <TooltipContent>Copy cache path</TooltipContent>+ </Tooltip>+ <span className="text-muted-foreground/30">·</span>+ <span className="text-muted-foreground/50">{formatDate(new Date(file.modifiedAt))}</span>+ </div>+ </div>+);++// ── pull dialog ────────────────────────────────────────────────────────────────++interface PullDialogProps {+ flowId: null | string;+ isPulling: boolean;+ onClose: () => void;+ onSuccess: () => void;+ open: boolean;+}++const PullDialog = ({ flowId, isPulling: externalIsPulling, onClose, onSuccess, open }: PullDialogProps) => {+ const [containerPath, setContainerPath] = useState('');+ const [force, setForce] = useState(false);+ const [isPulling, setIsPulling] = useState(false);++ useEffect(() => {+ if (!open) {+ setContainerPath('');+ setForce(false);+ }+ }, [open]);++ const handlePull = useCallback(async () => {+ if (!flowId || !containerPath.trim()) {return;}- setIsLoading(true);+ setIsPulling(true);try {- const response = await axios.get<unknown, ApiResponse<FlowFilesResponse>>(`/flows/${flowId}/files`);- const data = unwrapFlowFilesResponse(response);- setFiles(data.files ?? []);- } catch (error) {- const description = error instanceof Error ? error.message : 'An error occurred while loading flow files';- toast.error('Failed to load files', {- description,+ await axios.post<unknown, ApiResponse<FlowFilesResponse>>(`/flows/${flowId}/files/pull`, {+ force,+ path: containerPath.trim(),+ });+ toast.success('Pulled from container', {+ description: `Saved to local cache under container/`,});+ onSuccess();+ onClose();+ } catch (error) {+ const description = getErrorMessage(error, 'Failed to pull from container');+ toast.error('Pull failed', { description });} finally {- setIsLoading(false);+ setIsPulling(false);}- }, [flowId]);+ }, [flowId, containerPath, force, onSuccess, onClose]);++ const isSubmitting = isPulling || externalIsPulling;++ return (+ <Dialog+ onOpenChange={(v) => {+ if (!v && !isSubmitting) {+ onClose();+ }+ }}+ open={open}+ >+ <DialogContent>+ <DialogHeader>+ <DialogTitle className="flex items-center gap-2">+ <ArrowDownToLine className="size-4" />+ Pull from container+ </DialogTitle>+ <DialogDescription>+ Enter a path inside the running container. The file or directory will be synced to the local+ cache under <code>container/</code>.+ </DialogDescription>+ </DialogHeader>++ <div className="flex flex-col gap-4">+ <div className="flex flex-col gap-1.5">+ <Label htmlFor="container-path">Container path</Label>+ <Input+ autoComplete="off"+ autoFocus+ disabled={isSubmitting}+ id="container-path"+ onChange={(e) => setContainerPath(e.target.value)}+ onKeyDown={(e) => {+ if (e.key === 'Enter' && containerPath.trim() && !isSubmitting) {+ void handlePull();+ }+ }}+ placeholder="/etc/nginx/conf"+ value={containerPath}+ />+ </div>++ <div className="flex items-center gap-2">+ <Switch+ checked={force}+ disabled={isSubmitting}+ id="force-pull"+ onCheckedChange={setForce}+ />+ <Label+ className="cursor-pointer font-normal"+ htmlFor="force-pull"+ >+ Overwrite if already cached+ </Label>+ </div>+ </div>++ <div className="flex justify-end gap-2">+ <Button+ disabled={isSubmitting}+ onClick={onClose}+ variant="outline"+ >+ Cancel+ </Button>+ <Button+ disabled={!containerPath.trim() || isSubmitting}+ onClick={() => void handlePull()}+ >+ {isSubmitting ? <Loader2 className="animate-spin" /> : <ArrowDownToLine />}+ Pull+ </Button>+ </div>+ </DialogContent>+ </Dialog>+ );+};++// ── main component ─────────────────────────────────────────────────────────────++const FlowFiles = () => {+ const { flowId, flowStatus } = useFlow();+ const inputRef = useRef<HTMLInputElement | null>(null);+ const [isUploading, setIsUploading] = useState(false);+ const [fileToDelete, setFileToDelete] = useState<FlowFile | null>(null);+ const [showPullDialog, setShowPullDialog] = useState(false);+ const [debouncedSearch, setDebouncedSearch] = useState('');+ const flowFilesVariables = useMemo(() => ({ flowId: flowId ?? '' }), [flowId]);+ const {+ data: flowFilesData,+ error: flowFilesError,+ loading: isLoading,+ refetch: refetchFiles,+ } = useFlowFilesQuery({+ skip: !flowId,+ variables: flowFilesVariables,+ });++ const form = useForm<z.infer<typeof searchFormSchema>>({+ defaultValues: { search: '' },+ resolver: zodResolver(searchFormSchema),+ });++ const searchValue = form.watch('search');++ const debouncedUpdateSearch = useMemo(+ () =>+ debounce((value: string) => {+ setDebouncedSearch(value);+ }, 300),+ [],+ );useEffect(() => {- void loadFiles();- }, [loadFiles]);+ debouncedUpdateSearch(searchValue);- const handleUploadButtonClick = useCallback(() => {- inputRef.current?.click();- }, []);+ return () => {+ debouncedUpdateSearch.cancel();+ };+ }, [searchValue, debouncedUpdateSearch]);++ useEffect(() => {+ return () => {+ debouncedUpdateSearch.cancel();+ };+ }, [debouncedUpdateSearch]);++ useEffect(() => {+ form.reset({ search: '' });+ setDebouncedSearch('');+ debouncedUpdateSearch.cancel();+ }, [flowId, form, debouncedUpdateSearch]);++ const isContainerRunning = flowStatus === StatusType.Running || flowStatus === StatusType.Waiting;++ useFlowFileAddedSubscription({+ skip: !flowId,+ variables: flowFilesVariables,+ });+ useFlowFileUpdatedSubscription({+ skip: !flowId,+ variables: flowFilesVariables,+ });+ useFlowFileDeletedSubscription({+ skip: !flowId,+ variables: flowFilesVariables,+ });++ useEffect(() => {+ if (flowFilesError) {+ toast.error('Failed to load files', { description: flowFilesError.message });+ }+ }, [flowFilesError]);++ // ── upload ─────────────────────────────────────────────────────────────────const handleCopyPath = useCallback(async (filePath: string) => {const success = await copyToClipboard(filePath);if (success) {toast.success('Path copied to clipboard');-- return;+ } else {+ toast.error('Failed to copy path');}-- toast.error('Failed to copy path');}, []);const handleFileSelection = useCallback(@@ -128,7 +488,7 @@ const FlowFiles = () => {try {const response = await axios.post<unknown, ApiResponse<FlowFilesResponse>>(- `/flows/${flowId}/files`,+ `/flows/${flowId}/files/`,formData,{headers: {@@ -139,43 +499,84 @@ const FlowFiles = () => {const data = unwrapFlowFilesResponse(response);const uploadedCount = data.files?.length ?? selectedFiles.length;- toast.success(uploadedCount === 1 ? 'File uploaded successfully' : 'Files uploaded successfully', {+ toast.success(uploadedCount === 1 ? 'File uploaded' : `${uploadedCount} files uploaded`, {description:uploadedCount === 1- ? `${data.files?.[0]?.path ?? '/work/uploads'}`+ ? `Available at /work/uploads/${data.files?.[0]?.name ?? ''}`: `${uploadedCount} files are now available under /work/uploads`,});- await loadFiles();+ await refetchFiles();} catch (error) {- const description = error instanceof Error ? error.message : 'An error occurred while uploading files';- toast.error('Failed to upload files', {- description,- });+ const description = getErrorMessage(error, 'Failed to upload files');+ toast.error('Upload failed', { description });} finally {setIsUploading(false);event.target.value = '';}},- [flowId, loadFiles],+ [flowId, refetchFiles],);+ const handleDeleteFile = useCallback(async () => {+ if (!flowId || !fileToDelete) {+ return;+ }++ try {+ await axios.delete<unknown, ApiResponse<FlowFilesResponse>>(`/flows/${flowId}/files/`, {+ params: { path: fileToDelete.path },+ });+ toast.success(fileToDelete.isDir ? 'Directory deleted' : 'File deleted');+ await refetchFiles();+ } catch (error) {+ const description = getErrorMessage(error, 'Failed to delete file');+ toast.error('Delete failed', { description });+ } finally {+ setFileToDelete(null);+ }+ }, [flowId, fileToDelete, refetchFiles]);++ // ── filtering + grouping ───────────────────────────────────────────────────++ const files = useMemo(() => flowFilesData?.flowFiles ?? [], [flowFilesData?.flowFiles]);+const filteredFiles = useMemo(() => {- const normalizedSearch = searchValue.toLowerCase().trim();+ const search = debouncedSearch.toLowerCase().trim();- if (!normalizedSearch) {+ if (!search) {return files;}- return files.filter((file) => {- return (- file.name.toLowerCase().includes(normalizedSearch) || file.path.toLowerCase().includes(normalizedSearch)- );- });- }, [files, searchValue]);+ return files.filter((f) => f.name.toLowerCase().includes(search) || f.path.toLowerCase().includes(search));+ }, [files, debouncedSearch]);++ const groups = useMemo(() => {+ const uploads: FlowFile[] = [];+ const container: FlowFile[] = [];++ for (const f of filteredFiles) {+ const src = fileSource(f.path);++ if (src === 'uploads') {+ uploads.push(f);+ } else if (src === 'container') {+ container.push(f);+ }+ }++ return {+ container: buildFlowFileTree(container),+ uploads: buildFlowFileTree(uploads),+ };+ }, [filteredFiles]);++ const hasFiles = filteredFiles.length > 0;++ // ── render ─────────────────────────────────────────────────────────────────return (- <div className="flex h-full flex-col gap-4">+ <div className="flex h-full flex-col"><inputclassName="hidden"multiple@@ -184,112 +585,146 @@ const FlowFiles = () => {type="file"/>- <div className="bg-background sticky top-0 z-10 flex flex-col gap-3 pb-4">- <div className="rounded-lg border px-4 py-3 text-sm">- <div className="flex items-start gap-3">- <AlertCircle className="text-muted-foreground mt-0.5 size-4 shrink-0" />- <div className="space-y-1">- <p className="font-medium">Uploaded files are shared with the whole flow.</p>- <p className="text-muted-foreground">- PentAGI stores user uploads under <code>/work/uploads</code>, so automation, assistants,- and container commands can access the same files immediately.- </p>- </div>- </div>- </div>-- <div className="flex flex-col gap-3 sm:flex-row sm:items-center">- <InputGroup className="flex-1">- <InputGroupAddon>- <FileUp />- </InputGroupAddon>- <InputGroupInput- autoComplete="off"- onChange={(event) => setSearchValue(event.target.value)}- placeholder="Filter uploaded files..."- type="text"- value={searchValue}+ {/* Toolbar — same sticky pattern as screenshots / vector-stores */}+ <div className="bg-background sticky top-0 z-10 pb-4">+ <Form {...form}>+ <div className="flex gap-2 p-px">+ <FormField+ control={form.control}+ name="search"+ render={({ field }) => (+ <FormControl>+ <InputGroup className="flex-1">+ <InputGroupAddon>+ <Search />+ </InputGroupAddon>+ <InputGroupInput+ {...field}+ autoComplete="off"+ placeholder="Search files..."+ type="text"+ />+ {field.value && (+ <InputGroupAddon align="inline-end">+ <InputGroupButton+ onClick={() => {+ form.reset({ search: '' });+ setDebouncedSearch('');+ debouncedUpdateSearch.cancel();+ }}+ type="button"+ >+ <X />+ </InputGroupButton>+ </InputGroupAddon>+ )}+ </InputGroup>+ </FormControl>+ )}/>- {searchValue && (- <InputGroupAddon align="inline-end">- <InputGroupButton- onClick={() => setSearchValue('')}++ {/* Info hint */}+ <Tooltip>+ <TooltipTrigger asChild>+ <Button+ size="icon-sm"type="button"+ variant="ghost">- Clear- </InputGroupButton>- </InputGroupAddon>- )}- </InputGroup>-- <div className="flex items-center gap-2">- <Button- disabled={isLoading || isUploading}- onClick={() => void loadFiles()}- type="button"- variant="outline"- >- {isLoading ? <Loader2 className="animate-spin" /> : <RefreshCw />}- Refresh- </Button>- <Button- disabled={isUploading}- onClick={handleUploadButtonClick}- type="button"- >- {isUploading ? <Loader2 className="animate-spin" /> : <FolderUp />}- Upload- </Button>+ <Info className="text-muted-foreground size-4" />+ </Button>+ </TooltipTrigger>+ <TooltipContent className="max-w-64 text-center text-xs">+ <p>+ <strong>Uploads</strong> are pushed to <code>/work/uploads</code> and are+ immediately accessible inside the container.+ </p>+ <p className="mt-1">+ <strong>Container</strong> files are snapshots pulled via Pull and stored+ separately.+ </p>+ </TooltipContent>+ </Tooltip>++ {/* Upload button */}+ <Tooltip>+ <TooltipTrigger asChild>+ <Button+ disabled={isUploading || isLoading}+ onClick={() => inputRef.current?.click()}+ size="icon-sm"+ type="button"+ variant="outline"+ >+ {isUploading ? <Loader2 className="animate-spin" /> : <FolderUp />}+ </Button>+ </TooltipTrigger>+ <TooltipContent>Upload files</TooltipContent>+ </Tooltip>++ {/* Pull button — wraps in span so tooltip works when disabled */}+ <Tooltip>+ <TooltipTrigger asChild>+ <span>+ <Button+ disabled={!isContainerRunning || isLoading}+ onClick={() => setShowPullDialog(true)}+ size="icon-sm"+ type="button"+ variant="outline"+ >+ <ArrowDownToLine />+ </Button>+ </span>+ </TooltipTrigger>+ <TooltipContent>+ {isContainerRunning+ ? 'Pull file or directory from container'+ : 'Container is not running'}+ </TooltipContent>+ </Tooltip></div>- </div>+ </Form></div>- {filteredFiles.length > 0 ? (- <div className="flex flex-1 flex-col gap-3 overflow-y-auto">- {filteredFiles.map((file) => (- <div- className="bg-card text-card-foreground rounded-xl border p-4 shadow-sm"- key={`${file.name}-${file.modifiedAt}`}- >- <div className="flex flex-col gap-3 md:flex-row md:items-start md:justify-between">- <div className="min-w-0 space-y-2">- <div className="flex items-center gap-2">- <FileUp className="text-muted-foreground size-4 shrink-0" />- <p className="truncate font-semibold">{file.name}</p>- </div>- <div className="text-muted-foreground space-y-1 text-sm">- <p>{formatFileSize(file.size)}</p>- <div className="flex items-center gap-2">- <code className="bg-muted rounded px-2 py-1 text-xs">{file.path}</code>- <Tooltip>- <TooltipTrigger asChild>- <button- className={cn(- buttonVariants({ size: 'icon-xs', variant: 'ghost' }),- )}- onClick={() => void handleCopyPath(file.path)}- type="button"- >- <Copy />- </button>- </TooltipTrigger>- <TooltipContent>Copy container path</TooltipContent>- </Tooltip>- </div>- <p>{formatDate(new Date(file.modifiedAt))}</p>- </div>- </div>-- <a- className={cn(buttonVariants({ size: 'sm', variant: 'outline' }), 'shrink-0')}- href={`${baseUrl}/flows/${flowId}/files/${encodeURIComponent(file.name)}`}- >- <Download />- Download- </a>+ {/* File list grouped by source */}+ {hasFiles ? (+ <div className="flex flex-col gap-1 overflow-y-auto">+ {groups.uploads.length > 0 && (+ <>+ <SectionHeader icon={<FolderUp className="size-3" />}>Uploads</SectionHeader>+ <div className="flex flex-col gap-3 pb-3">+ {groups.uploads.map(({ depth, file }) => (+ <FlowFileItem+ depth={depth}+ file={file}+ flowId={flowId}+ key={`${file.path}-${file.modifiedAt}`}+ onCopyPath={(p) => void handleCopyPath(p)}+ onDelete={setFileToDelete}+ />+ ))}+ </div>+ </>+ )}++ {groups.container.length > 0 && (+ <>+ <SectionHeader icon={<HardDrive className="size-3" />}>Container</SectionHeader>+ <div className="flex flex-col gap-3 pb-3">+ {groups.container.map(({ depth, file }) => (+ <FlowFileItem+ depth={depth}+ file={file}+ flowId={flowId}+ key={`${file.path}-${file.modifiedAt}`}+ onCopyPath={(p) => void handleCopyPath(p)}+ onDelete={setFileToDelete}+ />+ ))}</div>- </div>- ))}+ </>+ )}</div>) : (<Empty>@@ -297,14 +732,36 @@ const FlowFiles = () => {<EmptyMedia variant="icon"><FolderUp /></EmptyMedia>- <EmptyTitle>No uploaded files</EmptyTitle>+ <EmptyTitle>No files in cache</EmptyTitle><EmptyDescription>- Upload files into <code>/work/uploads</code> when you want this flow, its assistants, or- container commands to use them.+ Upload files to make them available at <code>/work/uploads</code>, or use Pull to sync files+ from the running container.</EmptyDescription></EmptyHeader></Empty>)}++ <PullDialog+ flowId={flowId}+ isPulling={false}+ onClose={() => setShowPullDialog(false)}+ onSuccess={() => void refetchFiles()}+ open={showPullDialog}+ />++ <ConfirmationDialog+ confirmText="Delete"+ handleConfirm={() => void handleDeleteFile()}+ handleOpenChange={(isOpen) => {+ if (!isOpen) {+ setFileToDelete(null);+ }+ }}+ isOpen={!!fileToDelete}+ itemName={fileToDelete?.name}+ itemType={fileToDelete?.isDir ? 'directory' : 'file'}+ title={fileToDelete?.isDir ? 'Delete Directory' : 'Delete File'}+ /></div>);};diff --git a/frontend/src/graphql/types.ts b/frontend/src/graphql/types.tsindex bbb1c256..fdd25c94 100644--- a/frontend/src/graphql/types.ts+++ b/frontend/src/graphql/types.ts@@ -284,6 +284,15 @@ export type FlowExecutionStats = {totalToolcallsCount: Scalars['Int']['output'];};+export type FlowFile = {+ id: Scalars['String']['output'];+ isDir: Scalars['Boolean']['output'];+ modifiedAt: Scalars['Time']['output'];+ name: Scalars['String']['output'];+ path: Scalars['String']['output'];+ size: Scalars['Int']['output'];+};+export type FlowStats = {totalAssistantsCount: Scalars['Int']['output'];totalSubtasksCount: Scalars['Int']['output'];@@ -690,6 +699,7 @@ export type Query = {assistantLogs?: Maybe<Array<AssistantLog>>;assistants?: Maybe<Array<Assistant>>;flow: Flow;+ flowFiles: Array<FlowFile>;flowStatsByFlow: FlowStats;flowTemplate?: Maybe<FlowTemplate>;flowTemplates: Array<FlowTemplate>;@@ -744,6 +754,10 @@ export type QueryFlowArgs = {flowId: Scalars['ID']['input'];};+export type QueryFlowFilesArgs = {+ flowId: Scalars['ID']['input'];+};+export type QueryFlowStatsByFlowArgs = {flowId: Scalars['ID']['input'];};@@ -889,6 +903,9 @@ export type Subscription = {assistantUpdated: Assistant;flowCreated: Flow;flowDeleted: Flow;+ flowFileAdded: FlowFile;+ flowFileDeleted: FlowFile;+ flowFileUpdated: FlowFile;flowTemplateCreated: FlowTemplate;flowTemplateDeleted: FlowTemplate;flowTemplateUpdated: FlowTemplate;@@ -931,6 +948,18 @@ export type SubscriptionAssistantUpdatedArgs = {flowId: Scalars['ID']['input'];};+export type SubscriptionFlowFileAddedArgs = {+ flowId: Scalars['ID']['input'];+};++export type SubscriptionFlowFileDeletedArgs = {+ flowId: Scalars['ID']['input'];+};++export type SubscriptionFlowFileUpdatedArgs = {+ flowId: Scalars['ID']['input'];+};+export type SubscriptionMessageLogAddedArgs = {flowId: Scalars['ID']['input'];};@@ -1208,6 +1237,15 @@ export type ScreenshotFragmentFragment = {createdAt: any;};+export type FlowFileFragmentFragment = {+ id: string;+ name: string;+ path: string;+ size: number;+ isDir: boolean;+ modifiedAt: any;+};+export type AgentLogFragmentFragment = {id: string;flowId: string;@@ -1591,6 +1629,12 @@ export type TasksQueryVariables = Exact<{export type TasksQuery = { tasks?: Array<TaskFragmentFragment> | null };+export type FlowFilesQueryVariables = Exact<{+ flowId: Scalars['ID']['input'];+}>;++export type FlowFilesQuery = { flowFiles: Array<FlowFileFragmentFragment> };+export type AssistantsQueryVariables = Exact<{flowId: Scalars['ID']['input'];}>;@@ -1980,6 +2024,24 @@ export type AssistantDeletedSubscriptionVariables = Exact<{export type AssistantDeletedSubscription = { assistantDeleted: AssistantFragmentFragment };+export type FlowFileAddedSubscriptionVariables = Exact<{+ flowId: Scalars['ID']['input'];+}>;++export type FlowFileAddedSubscription = { flowFileAdded: FlowFileFragmentFragment };++export type FlowFileUpdatedSubscriptionVariables = Exact<{+ flowId: Scalars['ID']['input'];+}>;++export type FlowFileUpdatedSubscription = { flowFileUpdated: FlowFileFragmentFragment };++export type FlowFileDeletedSubscriptionVariables = Exact<{+ flowId: Scalars['ID']['input'];+}>;++export type FlowFileDeletedSubscription = { flowFileDeleted: FlowFileFragmentFragment };+export type AssistantLogAddedSubscriptionVariables = Exact<{flowId: Scalars['ID']['input'];}>;@@ -2170,6 +2232,16 @@ export const ScreenshotFragmentFragmentDoc = gql`createdAt}`;+export const FlowFileFragmentFragmentDoc = gql`+ fragment flowFileFragment on FlowFile {+ id+ name+ path+ size+ isDir+ modifiedAt+ }+`;export const AgentLogFragmentFragmentDoc = gql`fragment agentLogFragment on AgentLog {id@@ -3244,6 +3316,61 @@ export type TasksQueryHookResult = ReturnType<typeof useTasksQuery>;export type TasksLazyQueryHookResult = ReturnType<typeof useTasksLazyQuery>;export type TasksSuspenseQueryHookResult = ReturnType<typeof useTasksSuspenseQuery>;export type TasksQueryResult = Apollo.QueryResult<TasksQuery, TasksQueryVariables>;+export const FlowFilesDocument = gql`+ query flowFiles($flowId: ID!) {+ flowFiles(flowId: $flowId) {+ ...flowFileFragment+ }+ }+ ${FlowFileFragmentFragmentDoc}+`;++/**+ * __useFlowFilesQuery__+ *+ * To run a query within a React component, call `useFlowFilesQuery` and pass it any options that fit your needs.+ * When your component renders, `useFlowFilesQuery` returns an object from Apollo Client that contains loading, error, and data properties+ * you can use to render your UI.+ *+ * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;+ *+ * @example+ * const { data, loading, error } = useFlowFilesQuery({+ * variables: {+ * flowId: // value for 'flowId'+ * },+ * });+ */+export function useFlowFilesQuery(+ baseOptions: Apollo.QueryHookOptions<FlowFilesQuery, FlowFilesQueryVariables> &+ ({ variables: FlowFilesQueryVariables; skip?: boolean } | { skip: boolean }),+) {+ const options = { ...defaultOptions, ...baseOptions };+ return Apollo.useQuery<FlowFilesQuery, FlowFilesQueryVariables>(FlowFilesDocument, options);+}+export function useFlowFilesLazyQuery(+ baseOptions?: Apollo.LazyQueryHookOptions<FlowFilesQuery, FlowFilesQueryVariables>,+) {+ const options = { ...defaultOptions, ...baseOptions };+ return Apollo.useLazyQuery<FlowFilesQuery, FlowFilesQueryVariables>(FlowFilesDocument, options);+}+// @ts-ignore+export function useFlowFilesSuspenseQuery(+ baseOptions?: Apollo.SuspenseQueryHookOptions<FlowFilesQuery, FlowFilesQueryVariables>,+): Apollo.UseSuspenseQueryResult<FlowFilesQuery, FlowFilesQueryVariables>;+export function useFlowFilesSuspenseQuery(+ baseOptions?: Apollo.SkipToken | Apollo.SuspenseQueryHookOptions<FlowFilesQuery, FlowFilesQueryVariables>,+): Apollo.UseSuspenseQueryResult<FlowFilesQuery | undefined, FlowFilesQueryVariables>;+export function useFlowFilesSuspenseQuery(+ baseOptions?: Apollo.SkipToken | Apollo.SuspenseQueryHookOptions<FlowFilesQuery, FlowFilesQueryVariables>,+) {+ const options = baseOptions === Apollo.skipToken ? baseOptions : { ...defaultOptions, ...baseOptions };+ return Apollo.useSuspenseQuery<FlowFilesQuery, FlowFilesQueryVariables>(FlowFilesDocument, options);+}+export type FlowFilesQueryHookResult = ReturnType<typeof useFlowFilesQuery>;+export type FlowFilesLazyQueryHookResult = ReturnType<typeof useFlowFilesLazyQuery>;+export type FlowFilesSuspenseQueryHookResult = ReturnType<typeof useFlowFilesSuspenseQuery>;+export type FlowFilesQueryResult = Apollo.QueryResult<FlowFilesQuery, FlowFilesQueryVariables>;export const AssistantsDocument = gql`query assistants($flowId: ID!) {assistants(flowId: $flowId) {@@ -6356,6 +6483,117 @@ export function useAssistantDeletedSubscription(}export type AssistantDeletedSubscriptionHookResult = ReturnType<typeof useAssistantDeletedSubscription>;export type AssistantDeletedSubscriptionResult = Apollo.SubscriptionResult<AssistantDeletedSubscription>;+export const FlowFileAddedDocument = gql`+ subscription flowFileAdded($flowId: ID!) {+ flowFileAdded(flowId: $flowId) {+ ...flowFileFragment+ }+ }+ ${FlowFileFragmentFragmentDoc}+`;++/**+ * __useFlowFileAddedSubscription__+ *+ * To run a query within a React component, call `useFlowFileAddedSubscription` and pass it any options that fit your needs.+ * When your component renders, `useFlowFileAddedSubscription` returns an object from Apollo Client that contains loading, error, and data properties+ * you can use to render your UI.+ *+ * @param baseOptions options that will be passed into the subscription, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;+ *+ * @example+ * const { data, loading, error } = useFlowFileAddedSubscription({+ * variables: {+ * flowId: // value for 'flowId'+ * },+ * });+ */+export function useFlowFileAddedSubscription(+ baseOptions: Apollo.SubscriptionHookOptions<FlowFileAddedSubscription, FlowFileAddedSubscriptionVariables> &+ ({ variables: FlowFileAddedSubscriptionVariables; skip?: boolean } | { skip: boolean }),+) {+ const options = { ...defaultOptions, ...baseOptions };+ return Apollo.useSubscription<FlowFileAddedSubscription, FlowFileAddedSubscriptionVariables>(+ FlowFileAddedDocument,+ options,+ );+}+export type FlowFileAddedSubscriptionHookResult = ReturnType<typeof useFlowFileAddedSubscription>;+export type FlowFileAddedSubscriptionResult = Apollo.SubscriptionResult<FlowFileAddedSubscription>;+export const FlowFileUpdatedDocument = gql`+ subscription flowFileUpdated($flowId: ID!) {+ flowFileUpdated(flowId: $flowId) {+ ...flowFileFragment+ }+ }+ ${FlowFileFragmentFragmentDoc}+`;++/**+ * __useFlowFileUpdatedSubscription__+ *+ * To run a query within a React component, call `useFlowFileUpdatedSubscription` and pass it any options that fit your needs.+ * When your component renders, `useFlowFileUpdatedSubscription` returns an object from Apollo Client that contains loading, error, and data properties+ * you can use to render your UI.+ *+ * @param baseOptions options that will be passed into the subscription, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;+ *+ * @example+ * const { data, loading, error } = useFlowFileUpdatedSubscription({+ * variables: {+ * flowId: // value for 'flowId'+ * },+ * });+ */+export function useFlowFileUpdatedSubscription(+ baseOptions: Apollo.SubscriptionHookOptions<FlowFileUpdatedSubscription, FlowFileUpdatedSubscriptionVariables> &+ ({ variables: FlowFileUpdatedSubscriptionVariables; skip?: boolean } | { skip: boolean }),+) {+ const options = { ...defaultOptions, ...baseOptions };+ return Apollo.useSubscription<FlowFileUpdatedSubscription, FlowFileUpdatedSubscriptionVariables>(+ FlowFileUpdatedDocument,+ options,+ );+}+export type FlowFileUpdatedSubscriptionHookResult = ReturnType<typeof useFlowFileUpdatedSubscription>;+export type FlowFileUpdatedSubscriptionResult = Apollo.SubscriptionResult<FlowFileUpdatedSubscription>;+export const FlowFileDeletedDocument = gql`+ subscription flowFileDeleted($flowId: ID!) {+ flowFileDeleted(flowId: $flowId) {+ ...flowFileFragment+ }+ }+ ${FlowFileFragmentFragmentDoc}+`;++/**+ * __useFlowFileDeletedSubscription__+ *+ * To run a query within a React component, call `useFlowFileDeletedSubscription` and pass it any options that fit your needs.+ * When your component renders, `useFlowFileDeletedSubscription` returns an object from Apollo Client that contains loading, error, and data properties+ * you can use to render your UI.+ *+ * @param baseOptions options that will be passed into the subscription, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;+ *+ * @example+ * const { data, loading, error } = useFlowFileDeletedSubscription({+ * variables: {+ * flowId: // value for 'flowId'+ * },+ * });+ */+export function useFlowFileDeletedSubscription(+ baseOptions: Apollo.SubscriptionHookOptions<FlowFileDeletedSubscription, FlowFileDeletedSubscriptionVariables> &+ ({ variables: FlowFileDeletedSubscriptionVariables; skip?: boolean } | { skip: boolean }),+) {+ const options = { ...defaultOptions, ...baseOptions };+ return Apollo.useSubscription<FlowFileDeletedSubscription, FlowFileDeletedSubscriptionVariables>(+ FlowFileDeletedDocument,+ options,+ );+}+export type FlowFileDeletedSubscriptionHookResult = ReturnType<typeof useFlowFileDeletedSubscription>;+export type FlowFileDeletedSubscriptionResult = Apollo.SubscriptionResult<FlowFileDeletedSubscription>;export const AssistantLogAddedDocument = gql`subscription assistantLogAdded($flowId: ID!) {assistantLogAdded(flowId: $flowId) {diff --git a/frontend/src/lib/apollo.ts b/frontend/src/lib/apollo.tsindex 7bd4e3c4..28e3d439 100644--- a/frontend/src/lib/apollo.ts+++ b/frontend/src/lib/apollo.ts@@ -99,6 +99,9 @@ const subscriptionToCacheFieldMap: Record<string, string> = {assistantUpdated: 'assistants',flowCreated: 'flows',flowDeleted: 'flows',+ flowFileAdded: 'flowFiles',+ flowFileDeleted: 'flowFiles',+ flowFileUpdated: 'flowFiles',flowTemplateCreated: 'flowTemplates',flowTemplateDeleted: 'flowTemplates',flowTemplateUpdated: 'flowTemplates',@@ -497,6 +500,7 @@ const createApolloClient = () => {return existing ?? toReference({ __typename: 'Flow', id: args.flowId });},},+ flowFiles: { keyArgs: ['flowId'], ...replaceWithIncoming },flows: { ...replaceWithIncoming },flowTemplates: { ...replaceWithIncoming },messageLogs: { keyArgs: ['flowId'], ...replaceWithIncoming },diff --git a/frontend/src/pages/dashboard/dashboard-overview.tsx b/frontend/src/pages/dashboard/dashboard-overview.tsxindex 5901a5a6..2d9027ba 100644--- a/frontend/src/pages/dashboard/dashboard-overview.tsx+++ b/frontend/src/pages/dashboard/dashboard-overview.tsx@@ -37,13 +37,13 @@ const UsageStatsTable = ({ rows }: { rows: Array<{ label: string; stats: UsageSt<TableHeader><TableRow><TableHead className="whitespace-nowrap">Name</TableHead>- <TableHead className="whitespace-nowrap text-right">Tokens In</TableHead>- <TableHead className="whitespace-nowrap text-right">Tokens Out</TableHead>- <TableHead className="whitespace-nowrap text-right">Cache In</TableHead>- <TableHead className="whitespace-nowrap text-right">Cache Out</TableHead>- <TableHead className="whitespace-nowrap text-right">Cost In</TableHead>- <TableHead className="whitespace-nowrap text-right">Cost Out</TableHead>- <TableHead className="whitespace-nowrap text-right">Total Cost</TableHead>+ <TableHead className="text-right whitespace-nowrap">Tokens In</TableHead>+ <TableHead className="text-right whitespace-nowrap">Tokens Out</TableHead>+ <TableHead className="text-right whitespace-nowrap">Cache In</TableHead>+ <TableHead className="text-right whitespace-nowrap">Cache Out</TableHead>+ <TableHead className="text-right whitespace-nowrap">Cost In</TableHead>+ <TableHead className="text-right whitespace-nowrap">Cost Out</TableHead>+ <TableHead className="text-right whitespace-nowrap">Total Cost</TableHead></TableRow></TableHeader><TableBody>@@ -174,9 +174,9 @@ export const DashboardOverview = () => {<TableRow><TableHead className="whitespace-nowrap">Function</TableHead><TableHead className="whitespace-nowrap">Type</TableHead>- <TableHead className="whitespace-nowrap text-right">Count</TableHead>- <TableHead className="whitespace-nowrap text-right">Total Duration</TableHead>- <TableHead className="whitespace-nowrap text-right">Avg Duration</TableHead>+ <TableHead className="text-right whitespace-nowrap">Count</TableHead>+ <TableHead className="text-right whitespace-nowrap">Total Duration</TableHead>+ <TableHead className="text-right whitespace-nowrap">Avg Duration</TableHead></TableRow></TableHeader><TableBody>