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: add user resources system and flow integration
Dmitry Ngaa4b70eaba95
diff --git a/backend/docs/flow_execution.md b/backend/docs/flow_execution.mdindex 0c0a56e0..9e9e0c63 100644--- a/backend/docs/flow_execution.md+++ b/backend/docs/flow_execution.md@@ -40,6 +40,7 @@ This document describes the internal architecture and execution workflow of Flow- **Environment Tools** - Terminal commands, file operations within Docker containers- `terminal` - Command execution (configurable via `TERMINAL_TOOL_TIMEOUT`, default: 1200s; hard limit: 3h/10800s; 0 or negative values are clamped to the hard limit)- `file` - Read/write operations with absolute path requirements+ - User-provided flow files are available under `/work/uploads` and `/work/resources`- **Search Network Tools** - External information sources- `browser` - Web scraping with screenshot capture@@ -79,6 +80,7 @@ This document describes the internal architecture and execution workflow of Flow- **Execution Context** - Comprehensive state including completed/planned Subtasks- **Docker Environment** - Isolated container for secure tool execution- **Vector Store** - Long-term semantic memory for knowledge retention+- **Task Materials** - Optional user uploads and resources exposed to prompts via `{{.UserFiles}}`### Performance Results- **PerformResultDone** - Subtask completed successfully via `done` tool@@ -572,6 +574,8 @@ graph TBsubgraph "Tool Execution Environment"WorkDir[Work Directory<br/>/work in container]+ Uploads[User Uploads<br/>/work/uploads]+ Resources[User Resources<br/>/work/resources]Terminal[Terminal Tool<br/>default 1200s, hard limit 3h]FileOps[File Operations<br/>Absolute paths required]WebAccess[Web Access<br/>Separate scraper container]@@ -583,6 +587,8 @@ graph TBPrimary --> VolumesPrimary --> NetworkPrimary --> WorkDir+ WorkDir --> Uploads+ WorkDir --> ResourcesWorkDir --> TerminalWorkDir --> FileOpsPrimary --> WebAccess@@ -852,6 +858,7 @@ The system uses 25+ dedicated prompt types for specific functions:- **XML Semantic Delimiters** - Structured sections like `<memory_protocol>`, `<terminal_protocol>`- **Summarization Awareness** - Universal protocol for handling historical summaries- **Tool Placeholder System** - `{{.ToolPlaceholder}}` injection at prompt end+- **Task Materials Section** - `{{.UserFiles}}` lists user uploads/resources when present- **Template Variable System** - 50+ variables for dynamic content injection### Performance Optimizations and Limits@@ -877,6 +884,7 @@ Several mechanisms ensure efficient execution:**Container Resource Management**:- **Port Allocation** - 2 ports per Flow starting from base 28000- **Volume Management** - Per-flow data directories with cleanup+- **File Sync** - Incremental sync of `uploads/` and `resources/` into `/work/uploads` and `/work/resources`- **Network Isolation** - Optional custom Docker networks- **Image Fallback** - Automatic fallback to default Debian image@@ -1178,7 +1186,7 @@ The Flow execution system represents a sophisticated orchestration platform that- **Flow continuity** - System can resume operations after interruptions- **Real-time feedback** - Streaming responses provide immediate user visibility- **Vector knowledge system** - 4 storage types with semantic search and metadata filtering-- **Comprehensive tool ecosystem** - 44+ tools across 6 categories with automatic memory storage+- **Comprehensive tool ecosystem** - 44+ tools across 7 categories with automatic memory storage- **GraphQL subscriptions** - Real-time Flow/Task/Log updates via WebSocket connections- **Logging architecture** - 7-layer logging system with Controller/Worker pattern@@ -1196,6 +1204,7 @@ The Flow execution system represents a sophisticated orchestration platform that- **Two-layer validation**: tool handlers (`tools/flow_manager.go`) perform primary checks; provider callbacks are safety nets- **Subtask patching**: delta operations applied via `applySubtaskOperations()`; all planned subtask IDs are recreated; new IDs returned in tool result- **State verification**: `stop_flow` re-queries `GetFlowTasks` after handler returns and reports actual state+- **Resource handoff**: assistant inputs with resource IDs delegate file copying to `FlowWorker.PutResources()`**Message Chain Consistency**:- **AST Processing**: Uses Chain Abstract Syntax Tree for structured message analysis@@ -1211,10 +1220,16 @@ The Flow execution system represents a sophisticated orchestration platform that### Implementation Architecture Summary+**User Files and Resources**:+- **User Resources** - Per-user blob storage with metadata in `user_resources`+- **Flow Files** - Per-flow filesystem cache under `flow-{id}-data/{uploads,container,resources}`+- **Container Availability** - `FlowToolsExecutor.Prepare()` incrementally syncs missing `uploads/` and `resources/` files into `/work`+- **Prompt Visibility** - Agents receive a compact `<task_files>` listing only when user files are present+**Core Flow Processing**:- **3-layer hierarchy**: FlowWorker → TaskWorker → SubtaskWorker with proper lifecycle management- **Agent orchestration**: 13 specialized agent types with role-specific tool access-- **Tool ecosystem**: 44+ tools across 6 categories (Environment, SearchNetwork, SearchVectorDb, Agent, StoreAgentResult, Barrier)+- **Tool ecosystem**: 44+ tools across 7 categories (Environment, SearchNetwork, SearchVectorDb, Agent, StoreAgentResult, Barrier, FlowManagement)- **Message chain types**: 14 distinct chain types for agent communication tracking**Error Resilience & Recovery**:diff --git a/backend/migrations/sql/20260426_120000_user_resources.sql b/backend/migrations/sql/20260426_120000_user_resources.sqlnew file mode 100644index 00000000..6282b610--- /dev/null+++ b/backend/migrations/sql/20260426_120000_user_resources.sql@@ -0,0 +1,85 @@+-- +goose Up+-- +goose StatementBegin+INSERT INTO privileges (role_id, name) VALUES+ (1, 'flow_files.admin'),+ (1, 'flow_files.view'),+ (1, 'flow_files.upload'),+ (1, 'flow_files.edit'),+ (1, 'flow_files.delete'),+ (1, 'flow_files.download'),+ (1, 'flow_files.subscribe'),+ (2, 'flow_files.view'),+ (2, 'flow_files.upload'),+ (2, 'flow_files.edit'),+ (2, 'flow_files.delete'),+ (2, 'flow_files.download'),+ (2, 'flow_files.subscribe')+ ON CONFLICT DO NOTHING;++INSERT INTO privileges (role_id, name) VALUES+ (1, 'resources.admin'),+ (1, 'resources.view'),+ (1, 'resources.upload'),+ (1, 'resources.edit'),+ (1, 'resources.delete'),+ (1, 'resources.download'),+ (1, 'resources.subscribe'),+ (2, 'resources.view'),+ (2, 'resources.upload'),+ (2, 'resources.edit'),+ (2, 'resources.delete'),+ (2, 'resources.download'),+ (2, 'resources.subscribe')+ ON CONFLICT DO NOTHING;++CREATE TABLE user_resources (+ id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,+ user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,+ hash TEXT NOT NULL DEFAULT '',+ name TEXT NOT NULL,+ path TEXT NOT NULL,+ size BIGINT NOT NULL DEFAULT 0,+ is_dir BOOLEAN NOT NULL DEFAULT FALSE,+ created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,+ updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,++ CONSTRAINT user_resources_user_path_unique UNIQUE (user_id, path),+ CONSTRAINT user_resources_name_not_empty CHECK (length(trim(name)) > 0),+ CONSTRAINT user_resources_path_not_empty CHECK (length(trim(path)) > 0)+);++CREATE INDEX user_resources_user_id_idx ON user_resources(user_id);+CREATE INDEX user_resources_hash_idx ON user_resources(hash) WHERE hash != '';+CREATE INDEX user_resources_path_idx ON user_resources USING btree (path text_pattern_ops);+CREATE INDEX user_resources_user_path_idx ON user_resources(user_id, path text_pattern_ops);+CREATE INDEX user_resources_updated_at_idx ON user_resources(updated_at DESC);++CREATE OR REPLACE TRIGGER update_user_resources_modified+ BEFORE UPDATE ON user_resources+ FOR EACH ROW EXECUTE PROCEDURE update_modified_column();+-- +goose StatementEnd++-- +goose Down+-- +goose StatementBegin+DROP TABLE IF EXISTS user_resources;++DELETE FROM privileges WHERE name IN (+ 'flow_files.admin',+ 'flow_files.view',+ 'flow_files.upload',+ 'flow_files.edit',+ 'flow_files.delete',+ 'flow_files.download',+ 'flow_files.subscribe'+);++DELETE FROM privileges WHERE name IN (+ 'resources.admin',+ 'resources.view',+ 'resources.upload',+ 'resources.edit',+ 'resources.delete',+ 'resources.download',+ 'resources.subscribe'+);+-- +goose StatementEnddiff --git a/backend/pkg/controller/assistant.go b/backend/pkg/controller/assistant.goindex f49539f6..44e257cb 100644--- a/backend/pkg/controller/assistant.go+++ b/backend/pkg/controller/assistant.go@@ -31,7 +31,7 @@ type AssistantWorker interface {GetTitle() stringGetStatus(ctx context.Context) (database.AssistantStatus, error)SetStatus(ctx context.Context, status database.AssistantStatus) error- PutInput(ctx context.Context, input string, useAgents bool) error+ PutInput(ctx context.Context, input string, useAgents bool, resources []database.UserResource) errorFinish(ctx context.Context) errorStop(ctx context.Context) error}@@ -46,6 +46,7 @@ type assistantWorker struct {db database.Querierwg *sync.WaitGrouppub subscriptions.FlowPublisher+ fw FlowWorkerctx context.Contextcancel context.CancelFuncrunMX *sync.Mutex@@ -63,6 +64,7 @@ type newAssistantWorkerCtx struct {prvname provider.ProviderNameprvtype provider.ProviderTypefunctions *tools.Functions+ resources []database.UserResourcefw FlowWorkerflowWorkerCtx@@ -226,6 +228,7 @@ func NewAssistantWorker(ctx context.Context, awc newAssistantWorkerCtx) (Assistadb: awc.db,wg: &sync.WaitGroup{},pub: pub,+ fw: awc.fw,ctx: ctx,cancel: cancel,runMX: &sync.Mutex{},@@ -247,7 +250,7 @@ func NewAssistantWorker(ctx context.Context, awc newAssistantWorkerCtx) (Assistaaw.wg.Add(1)go aw.worker()- if err := aw.PutInput(ctx, awc.input, awc.useAgents); err != nil {+ if err := aw.PutInput(ctx, awc.input, awc.useAgents, awc.resources); err != nil {return nil, wrapErrorEndSpan(ctx, assistantSpan, "failed to run assistant worker", err)}@@ -373,6 +376,7 @@ func LoadAssistantWorker(db: awc.db,wg: &sync.WaitGroup{},pub: pub,+ fw: awc.fw,ctx: ctx,cancel: cancel,runMX: &sync.Mutex{},@@ -512,10 +516,16 @@ func (aw *assistantWorker) SetStatus(ctx context.Context, status database.Assistreturn nil}-func (aw *assistantWorker) PutInput(ctx context.Context, input string, useAgents bool) error {+func (aw *assistantWorker) PutInput(ctx context.Context, input string, useAgents bool, resources []database.UserResource) error {ctx, span := obs.Observer.NewSpan(ctx, obs.SpanKindInternal, "controller.assistantWorker.PutInput")defer span.End()+ if aw.fw != nil {+ if err := aw.fw.PutResources(ctx, resources); err != nil {+ aw.logger.WithError(err).Warn("failed to copy resources before assistant input")+ }+ }+ain := assistantInput{input: input, useAgents: useAgents, done: make(chan error, 1)}select {case <-aw.ctx.Done():diff --git a/backend/pkg/controller/flow.go b/backend/pkg/controller/flow.goindex 821721d4..ea8f3e0f 100644--- a/backend/pkg/controller/flow.go+++ b/backend/pkg/controller/flow.go@@ -5,6 +5,8 @@ import ("encoding/json""errors""fmt"+ "io"+ "os""slices""sync""time"@@ -13,15 +15,19 @@ import ("pentagi/pkg/config""pentagi/pkg/database""pentagi/pkg/docker"+ "pentagi/pkg/flowfiles"+ "pentagi/pkg/graph/model""pentagi/pkg/graph/subscriptions"obs "pentagi/pkg/observability""pentagi/pkg/observability/langfuse""pentagi/pkg/providers""pentagi/pkg/providers/pconfig""pentagi/pkg/providers/provider"+ "pentagi/pkg/resources""pentagi/pkg/templates""pentagi/pkg/tools"+ dockercontainer "github.com/docker/docker/api/types/container""github.com/sirupsen/logrus")@@ -39,7 +45,8 @@ type FlowWorker interface {DeleteAssistant(ctx context.Context, assistantID int64) errorListAssistants(ctx context.Context) []AssistantWorkerListTasks(ctx context.Context) []TaskWorker- PutInput(ctx context.Context, input string, prv provider.Provider) error+ PutInput(ctx context.Context, input string, prv provider.Provider, resources []database.UserResource) error+ PutResources(ctx context.Context, resources []database.UserResource) errorFinish(ctx context.Context) errorStop(ctx context.Context) errorRename(ctx context.Context, title string) error@@ -57,6 +64,8 @@ type flowWorker struct {taskWG *sync.WaitGroupinput chan flowInputflowCtx *FlowContext+ dataDir string+ docker docker.DockerClientlogger *logrus.Entry}@@ -67,6 +76,7 @@ type newFlowWorkerCtx struct {prvname provider.ProviderNameprvtype provider.ProviderTypefunctions *tools.Functions+ resources []database.UserResourceflowWorkerCtx}@@ -241,6 +251,8 @@ func NewFlowWorker(taskWG: &sync.WaitGroup{},input: make(chan flowInput),flowCtx: flowCtx,+ dataDir: fwc.cfg.DataDir,+ docker: fwc.docker,logger: logrus.WithFields(logrus.Fields{"flow_id": flow.ID,"user_id": fwc.userID,@@ -264,7 +276,7 @@ func NewFlowWorker(go fw.worker()if !fwc.dryRun {- if err := fw.PutInput(ctx, fwc.input, nil); err != nil {+ if err := fw.PutInput(ctx, fwc.input, nil, fwc.resources); err != nil {return nil, wrapErrorEndSpan(ctx, flowSpan, "failed to run flow worker", err)}}@@ -391,6 +403,8 @@ func LoadFlowWorker(ctx context.Context, flow database.Flow, fwc flowWorkerCtx)taskWG: &sync.WaitGroup{},input: make(chan flowInput),flowCtx: flowCtx,+ dataDir: fwc.cfg.DataDir,+ docker: fwc.docker,logger: logrus.WithFields(logrus.Fields{"flow_id": flow.ID,"user_id": flow.UserID,@@ -572,6 +586,7 @@ func (fw *flowWorker) PutInput(ctx context.Context,input string,prv provider.Provider,+ resources []database.UserResource,) error {ctx, span := obs.Observer.NewSpan(ctx, obs.SpanKindInternal, "controller.flowWorker.PutInput")defer span.End()@@ -580,6 +595,10 @@ func (fw *flowWorker) PutInput(return fmt.Errorf("failed to switch provider: %w", err)}+ if err := fw.PutResources(ctx, resources); err != nil {+ fw.logger.WithError(err).Warn("failed to copy resources before user input")+ }+flin := flowInput{input: input, done: make(chan error, 1)}select {case <-fw.ctx.Done():@@ -605,6 +624,110 @@ func (fw *flowWorker) PutInput(}}+func (fw *flowWorker) PutResources(ctx context.Context, dbResources []database.UserResource) error {+ ctx, span := obs.Observer.NewSpan(ctx, obs.SpanKindInternal, "controller.flowWorker.PutResources")+ defer span.End()++ addedPaths, err := fw.copyResourcesToFS(dbResources)+ if err != nil {+ return err+ }+ if len(addedPaths) == 0 {+ return nil+ }++ fw.pushResourcesToContainer(ctx, addedPaths)+ fw.publishResourceFileEvents(ctx, addedPaths)+ return nil+}++// copyResourcesToFS copies user resource blobs into the flow resources directory on disk.+// Returns relative paths of newly written files (skips files already present).+func (fw *flowWorker) copyResourcesToFS(dbResources []database.UserResource) ([]string, error) {+ if len(dbResources) == 0 {+ return nil, nil+ }++ refs := make([]flowfiles.ResourceRef, 0, len(dbResources))+ for _, r := range dbResources {+ refs = append(refs, flowfiles.ResourceRef{+ Hash: r.Hash,+ VirtualPath: r.Path,+ Name: r.Name,+ IsDir: r.IsDir,+ })+ }++ storeDir := resources.ResourcesDir(fw.dataDir)+ return flowfiles.CopyResourcesToFlow(fw.dataDir, storeDir, uint64(fw.flowCtx.FlowID), refs, false)+}++// pushResourcesToContainer pushes newly added resource files into the running primary container.+// Each file is sent individually so partial failures are non-fatal.+func (fw *flowWorker) pushResourcesToContainer(ctx context.Context, addedPaths []string) {+ if fw.docker == nil {+ return+ }+ containerName := tools.PrimaryTerminalName(fw.flowCtx.FlowID)+ running, _ := fw.docker.IsContainerRunning(ctx, containerName)+ if !running {+ return+ }++ resourcesDir := flowfiles.FlowResourcesDir(fw.dataDir, uint64(fw.flowCtx.FlowID))+ for _, relPath := range addedPaths {+ fsRelPath := relPath[len(flowfiles.ResourcesDirName)+1:]+ absPath := resourcesDir + "/" + fsRelPath++ pr, pw := io.Pipe()+ errCh := make(chan error, 1)+ go func() {+ errCh <- flowfiles.WriteSingleFileTar(pw, absPath, flowfiles.ResourcesDirName+"/"+fsRelPath)+ }()++ copyErr := fw.docker.CopyToContainer(ctx, containerName, docker.WorkFolderPathInContainer, pr,+ dockercontainer.CopyToContainerOptions{AllowOverwriteDirWithFile: true})+ pr.Close()+ writeErr := <-errCh++ if copyErr != nil || writeErr != nil {+ fw.logger.WithFields(logrus.Fields{+ "path": relPath,+ "copy_err": copyErr,+ "write_err": writeErr,+ }).Warn("failed to push resource file to container; will be synced on restart")+ }+ }+}++// publishResourceFileEvents emits flowFileAdded subscription events for newly written resource files.+func (fw *flowWorker) publishResourceFileEvents(ctx context.Context, addedPaths []string) {+ if len(addedPaths) == 0 {+ return+ }++ resourcesDir := flowfiles.FlowResourcesDir(fw.dataDir, uint64(fw.flowCtx.FlowID))+ pub := fw.flowCtx.Publisher+ for _, relPath := range addedPaths {+ fsRelPath := relPath[len(flowfiles.ResourcesDirName)+1:]+ absPath := resourcesDir + "/" + fsRelPath++ file := &model.FlowFile{+ ID: flowfiles.ID(relPath),+ Name: flowfiles.BaseName(relPath),+ Path: relPath,+ IsDir: false,+ ModifiedAt: time.Now(),+ }+ if info, err := os.Lstat(absPath); err == nil {+ file.Size = int(info.Size())+ file.ModifiedAt = info.ModTime()+ }++ pub.FlowFileAdded(ctx, file)+ }+}+func (fw *flowWorker) Finish(ctx context.Context) error {ctx, span := obs.Observer.NewSpan(ctx, obs.SpanKindInternal, "controller.flowWorker.Finish")defer span.End()diff --git a/backend/pkg/controller/flows.go b/backend/pkg/controller/flows.goindex e73aac47..11c52a06 100644--- a/backend/pkg/controller/flows.go+++ b/backend/pkg/controller/flows.go@@ -31,6 +31,7 @@ type FlowController interface {prvname provider.ProviderName,prvtype provider.ProviderType,functions *tools.Functions,+ resources []database.UserResource,) (FlowWorker, error)CreateAssistant(ctx context.Context,@@ -41,6 +42,7 @@ type FlowController interface {prvname provider.ProviderName,prvtype provider.ProviderType,functions *tools.Functions,+ resources []database.UserResource,) (AssistantWorker, error)LoadFlows(ctx context.Context) errorListFlows(ctx context.Context) []FlowWorker@@ -137,6 +139,7 @@ func (fc *flowController) CreateFlow(prvname provider.ProviderName,prvtype provider.ProviderType,functions *tools.Functions,+ resources []database.UserResource,) (FlowWorker, error) {fc.mx.Lock()defer fc.mx.Unlock()@@ -147,6 +150,7 @@ func (fc *flowController) CreateFlow(prvname: prvname,prvtype: prvtype,functions: functions,+ resources: resources,flowWorkerCtx: flowWorkerCtx{db: fc.db,cfg: fc.cfg,@@ -182,6 +186,7 @@ func (fc *flowController) CreateAssistant(prvname provider.ProviderName,prvtype provider.ProviderType,functions *tools.Functions,+ resources []database.UserResource,) (AssistantWorker, error) {fc.mx.Lock()defer fc.mx.Unlock()@@ -289,6 +294,7 @@ func (fc *flowController) CreateAssistant(prvtype: prvtype,useAgents: useAgents,functions: functions,+ resources: resources,fw: fw,flowWorkerCtx: flowWorkerCtx,})diff --git a/backend/pkg/database/converter/converter.go b/backend/pkg/database/converter/converter.goindex a1900d2f..b235edb2 100644--- a/backend/pkg/database/converter/converter.go+++ b/backend/pkg/database/converter/converter.go@@ -1201,4 +1201,25 @@ func ConvertDailyFlowsStatsQuarter(stats []database.GetFlowsStatsByDayLast3Monthreturn result}-// ==================== Flows/Tasks/Subtasks Execution Time Converters ====================+// ConvertUserResources converts database user resources to GraphQL model+func ConvertUserResources(resources []database.UserResource) []*model.UserResource {+ result := make([]*model.UserResource, 0, len(resources))+ for _, r := range resources {+ result = append(result, ConvertUserResource(r))+ }+ return result+}++// ConvertUserResource converts database single user resource to GraphQL model+func ConvertUserResource(r database.UserResource) *model.UserResource {+ return &model.UserResource{+ ID: r.ID,+ UserID: r.UserID,+ Name: r.Name,+ Path: r.Path,+ Size: int(r.Size),+ IsDir: r.IsDir,+ CreatedAt: r.CreatedAt.Time,+ UpdatedAt: r.UpdatedAt.Time,+ }+}diff --git a/backend/pkg/database/models.go b/backend/pkg/database/models.goindex e53678d6..1672901d 100644--- a/backend/pkg/database/models.go+++ b/backend/pkg/database/models.go@@ -1113,6 +1113,18 @@ type UserPreference struct {UpdatedAt sql.NullTime `json:"updated_at"`}+type UserResource struct {+ ID int64 `json:"id"`+ UserID int64 `json:"user_id"`+ Hash string `json:"hash"`+ Name string `json:"name"`+ Path string `json:"path"`+ Size int64 `json:"size"`+ IsDir bool `json:"is_dir"`+ CreatedAt sql.NullTime `json:"created_at"`+ UpdatedAt sql.NullTime `json:"updated_at"`+}+type Vecstorelog struct {ID int64 `json:"id"`Initiator MsgchainType `json:"initiator"`diff --git a/backend/pkg/database/querier.go b/backend/pkg/database/querier.goindex 8e7c0b2a..8317ff7a 100644--- a/backend/pkg/database/querier.go+++ b/backend/pkg/database/querier.go@@ -55,6 +55,9 @@ type Querier interface {// Get toolcalls stats for all flowsGetAllFlowsToolcallsStats(ctx context.Context) ([]GetAllFlowsToolcallsStatsRow, error)GetAllFlowsUsageStats(ctx context.Context) ([]GetAllFlowsUsageStatsRow, error)+ GetAllResourcesInDir(ctx context.Context, arg GetAllResourcesInDirParams) ([]UserResource, error)+ GetAllResourcesRecursive(ctx context.Context, arg GetAllResourcesRecursiveParams) ([]UserResource, error)+ GetAllResourcesRoot(ctx context.Context) ([]UserResource, error)GetAssistant(ctx context.Context, id int64) (Assistant, error)GetAssistantUseAgents(ctx context.Context, id int64) (bool, error)// Get total count of assistants for a specific flow@@ -206,6 +209,11 @@ type Querier interface {GetUserProviderByName(ctx context.Context, arg GetUserProviderByNameParams) (Provider, error)GetUserProviders(ctx context.Context, userID int64) ([]Provider, error)GetUserProvidersByType(ctx context.Context, arg GetUserProvidersByTypeParams) ([]Provider, error)+ GetUserResourceByID(ctx context.Context, id int64) (UserResource, error)+ GetUserResourcesByIDs(ctx context.Context, ids []int64) ([]UserResource, error)+ GetUserResourcesInDir(ctx context.Context, arg GetUserResourcesInDirParams) ([]UserResource, error)+ GetUserResourcesRecursive(ctx context.Context, arg GetUserResourcesRecursiveParams) ([]UserResource, error)+ GetUserResourcesRoot(ctx context.Context, userID int64) ([]UserResource, error)// Get total count of flows, tasks, subtasks, and assistants for a userGetUserTotalFlowsStats(ctx context.Context, userID int64) (GetUserTotalFlowsStatsRow, error)// Get total toolcalls stats for a userdiff --git a/backend/pkg/database/resources.sql.go b/backend/pkg/database/resources.sql.gonew file mode 100644index 00000000..c3f1c623--- /dev/null+++ b/backend/pkg/database/resources.sql.go@@ -0,0 +1,348 @@+// Code generated by sqlc. DO NOT EDIT.+// versions:+// sqlc v1.27.0+// source: resources.sql++package database++import (+ "context"++ "github.com/lib/pq"+)++const getAllResourcesInDir = `-- name: GetAllResourcesInDir :many+SELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_at+FROM user_resources+WHERE (path = $1 AND is_dir = true)+ OR (path LIKE $2 AND path NOT LIKE $3)+ORDER BY updated_at DESC, name ASC+`++type GetAllResourcesInDirParams struct {+ DirPath string `json:"dir_path"`+ ChildPrefix string `json:"child_prefix"`+ DeepPrefix string `json:"deep_prefix"`+}++func (q *Queries) GetAllResourcesInDir(ctx context.Context, arg GetAllResourcesInDirParams) ([]UserResource, error) {+ rows, err := q.db.QueryContext(ctx, getAllResourcesInDir, arg.DirPath, arg.ChildPrefix, arg.DeepPrefix)+ if err != nil {+ return nil, err+ }+ defer rows.Close()+ var items []UserResource+ for rows.Next() {+ var i UserResource+ if err := rows.Scan(+ &i.ID,+ &i.UserID,+ &i.Hash,+ &i.Name,+ &i.Path,+ &i.Size,+ &i.IsDir,+ &i.CreatedAt,+ &i.UpdatedAt,+ ); err != nil {+ return nil, err+ }+ items = append(items, i)+ }+ if err := rows.Close(); err != nil {+ return nil, err+ }+ if err := rows.Err(); err != nil {+ return nil, err+ }+ return items, nil+}++const getAllResourcesRecursive = `-- name: GetAllResourcesRecursive :many+SELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_at+FROM user_resources+WHERE path = $1 OR path LIKE $2+ORDER BY updated_at DESC, name ASC+`++type GetAllResourcesRecursiveParams struct {+ DirPath string `json:"dir_path"`+ ChildPrefix string `json:"child_prefix"`+}++func (q *Queries) GetAllResourcesRecursive(ctx context.Context, arg GetAllResourcesRecursiveParams) ([]UserResource, error) {+ rows, err := q.db.QueryContext(ctx, getAllResourcesRecursive, arg.DirPath, arg.ChildPrefix)+ if err != nil {+ return nil, err+ }+ defer rows.Close()+ var items []UserResource+ for rows.Next() {+ var i UserResource+ if err := rows.Scan(+ &i.ID,+ &i.UserID,+ &i.Hash,+ &i.Name,+ &i.Path,+ &i.Size,+ &i.IsDir,+ &i.CreatedAt,+ &i.UpdatedAt,+ ); err != nil {+ return nil, err+ }+ items = append(items, i)+ }+ if err := rows.Close(); err != nil {+ return nil, err+ }+ if err := rows.Err(); err != nil {+ return nil, err+ }+ return items, nil+}++const getAllResourcesRoot = `-- name: GetAllResourcesRoot :many+SELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_at+FROM user_resources+WHERE path NOT LIKE '%/%'+ORDER BY updated_at DESC, name ASC+`++func (q *Queries) GetAllResourcesRoot(ctx context.Context) ([]UserResource, error) {+ rows, err := q.db.QueryContext(ctx, getAllResourcesRoot)+ if err != nil {+ return nil, err+ }+ defer rows.Close()+ var items []UserResource+ for rows.Next() {+ var i UserResource+ if err := rows.Scan(+ &i.ID,+ &i.UserID,+ &i.Hash,+ &i.Name,+ &i.Path,+ &i.Size,+ &i.IsDir,+ &i.CreatedAt,+ &i.UpdatedAt,+ ); err != nil {+ return nil, err+ }+ items = append(items, i)+ }+ if err := rows.Close(); err != nil {+ return nil, err+ }+ if err := rows.Err(); err != nil {+ return nil, err+ }+ return items, nil+}++const getUserResourceByID = `-- name: GetUserResourceByID :one+SELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_at+FROM user_resources+WHERE id = $1+`++func (q *Queries) GetUserResourceByID(ctx context.Context, id int64) (UserResource, error) {+ row := q.db.QueryRowContext(ctx, getUserResourceByID, id)+ var i UserResource+ err := row.Scan(+ &i.ID,+ &i.UserID,+ &i.Hash,+ &i.Name,+ &i.Path,+ &i.Size,+ &i.IsDir,+ &i.CreatedAt,+ &i.UpdatedAt,+ )+ return i, err+}++const getUserResourcesByIDs = `-- name: GetUserResourcesByIDs :many+SELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_at+FROM user_resources+WHERE id = ANY($1::bigint[])+ORDER BY id ASC+`++func (q *Queries) GetUserResourcesByIDs(ctx context.Context, ids []int64) ([]UserResource, error) {+ rows, err := q.db.QueryContext(ctx, getUserResourcesByIDs, pq.Array(ids))+ if err != nil {+ return nil, err+ }+ defer rows.Close()+ var items []UserResource+ for rows.Next() {+ var i UserResource+ if err := rows.Scan(+ &i.ID,+ &i.UserID,+ &i.Hash,+ &i.Name,+ &i.Path,+ &i.Size,+ &i.IsDir,+ &i.CreatedAt,+ &i.UpdatedAt,+ ); err != nil {+ return nil, err+ }+ items = append(items, i)+ }+ if err := rows.Close(); err != nil {+ return nil, err+ }+ if err := rows.Err(); err != nil {+ return nil, err+ }+ return items, nil+}++const getUserResourcesInDir = `-- name: GetUserResourcesInDir :many+SELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_at+FROM user_resources+WHERE user_id = $1+ AND ((path = $2 AND is_dir = true)+ OR (path LIKE $3 AND path NOT LIKE $4))+ORDER BY updated_at DESC, name ASC+`++type GetUserResourcesInDirParams struct {+ UserID int64 `json:"user_id"`+ DirPath string `json:"dir_path"`+ ChildPrefix string `json:"child_prefix"`+ DeepPrefix string `json:"deep_prefix"`+}++func (q *Queries) GetUserResourcesInDir(ctx context.Context, arg GetUserResourcesInDirParams) ([]UserResource, error) {+ rows, err := q.db.QueryContext(ctx, getUserResourcesInDir,+ arg.UserID,+ arg.DirPath,+ arg.ChildPrefix,+ arg.DeepPrefix,+ )+ if err != nil {+ return nil, err+ }+ defer rows.Close()+ var items []UserResource+ for rows.Next() {+ var i UserResource+ if err := rows.Scan(+ &i.ID,+ &i.UserID,+ &i.Hash,+ &i.Name,+ &i.Path,+ &i.Size,+ &i.IsDir,+ &i.CreatedAt,+ &i.UpdatedAt,+ ); err != nil {+ return nil, err+ }+ items = append(items, i)+ }+ if err := rows.Close(); err != nil {+ return nil, err+ }+ if err := rows.Err(); err != nil {+ return nil, err+ }+ return items, nil+}++const getUserResourcesRecursive = `-- name: GetUserResourcesRecursive :many+SELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_at+FROM user_resources+WHERE user_id = $1+ AND (path = $2 OR path LIKE $3)+ORDER BY updated_at DESC, name ASC+`++type GetUserResourcesRecursiveParams struct {+ UserID int64 `json:"user_id"`+ DirPath string `json:"dir_path"`+ ChildPrefix string `json:"child_prefix"`+}++func (q *Queries) GetUserResourcesRecursive(ctx context.Context, arg GetUserResourcesRecursiveParams) ([]UserResource, error) {+ rows, err := q.db.QueryContext(ctx, getUserResourcesRecursive, arg.UserID, arg.DirPath, arg.ChildPrefix)+ if err != nil {+ return nil, err+ }+ defer rows.Close()+ var items []UserResource+ for rows.Next() {+ var i UserResource+ if err := rows.Scan(+ &i.ID,+ &i.UserID,+ &i.Hash,+ &i.Name,+ &i.Path,+ &i.Size,+ &i.IsDir,+ &i.CreatedAt,+ &i.UpdatedAt,+ ); err != nil {+ return nil, err+ }+ items = append(items, i)+ }+ if err := rows.Close(); err != nil {+ return nil, err+ }+ if err := rows.Err(); err != nil {+ return nil, err+ }+ return items, nil+}++const getUserResourcesRoot = `-- name: GetUserResourcesRoot :many+SELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_at+FROM user_resources+WHERE user_id = $1 AND path NOT LIKE '%/%'+ORDER BY updated_at DESC, name ASC+`++func (q *Queries) GetUserResourcesRoot(ctx context.Context, userID int64) ([]UserResource, error) {+ rows, err := q.db.QueryContext(ctx, getUserResourcesRoot, userID)+ if err != nil {+ return nil, err+ }+ defer rows.Close()+ var items []UserResource+ for rows.Next() {+ var i UserResource+ if err := rows.Scan(+ &i.ID,+ &i.UserID,+ &i.Hash,+ &i.Name,+ &i.Path,+ &i.Size,+ &i.IsDir,+ &i.CreatedAt,+ &i.UpdatedAt,+ ); err != nil {+ return nil, err+ }+ items = append(items, i)+ }+ if err := rows.Close(); err != nil {+ return nil, err+ }+ if err := rows.Err(); err != nil {+ return nil, err+ }+ return items, nil+}diff --git a/backend/pkg/flowfiles/files.go b/backend/pkg/flowfiles/files.goindex 18276a93..418ef755 100644--- a/backend/pkg/flowfiles/files.go+++ b/backend/pkg/flowfiles/files.go@@ -13,6 +13,7 @@ import ("os""path""path/filepath"+ "pentagi/pkg/docker""sort""strings""time"@@ -21,6 +22,7 @@ import (const (UploadsDirName = "uploads"ContainerDirName = "container"+ ResourcesDirName = "resources"MaxUploadFileSize = 300 * 1024 * 1024 // 300 MBMaxUploadFiles = 1000 // files@@ -45,6 +47,12 @@ type Files struct {Total uint64}+// TarEntry describes a local regular file to include in a TAR archive.+type TarEntry struct {+ LocalPath string+ TarPath string+}+func List(dataDir string, flowID uint64) (Files, error) {uploadsEntries, err := ListDirEntries(FlowUploadsDir(dataDir, flowID), UploadsDirName)if err != nil {@@ -56,7 +64,13 @@ func List(dataDir string, flowID uint64) (Files, error) {return Files{}, fmt.Errorf("reading container cache: %w", err)}+ resourcesEntries, err := ListDirEntriesRecursive(FlowResourcesDir(dataDir, flowID), ResourcesDirName)+ if err != nil {+ return Files{}, fmt.Errorf("reading resources cache: %w", err)+ }+files := append(uploadsEntries, containerEntries...)+ files = append(files, resourcesEntries...)Sort(files)return Files{Files: files,@@ -76,6 +90,10 @@ func FlowContainerDir(dataDir string, flowID uint64) string {return filepath.Join(FlowDataDir(dataDir, flowID), ContainerDirName)}+func FlowResourcesDir(dataDir string, flowID uint64) string {+ return filepath.Join(FlowDataDir(dataDir, flowID), ResourcesDirName)+}+func ResolveCachedPath(dataDir string, flowID uint64, reqPath string) (string, error) {if strings.TrimSpace(reqPath) == "" {return "", errors.New("path query parameter is required")@@ -87,8 +105,8 @@ func ResolveCachedPath(dataDir string, flowID uint64, reqPath string) (string, e}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)+ if parts[0] != UploadsDirName && parts[0] != ContainerDirName && parts[0] != ResourcesDirName {+ return "", fmt.Errorf("path must start with '%s', '%s', or '%s'", UploadsDirName, ContainerDirName, ResourcesDirName)}flowDataDir := FlowDataDir(dataDir, flowID)@@ -339,28 +357,220 @@ func ResolvePulledStagedTarget(stagingDir, cacheRelPath string) string {}func WriteUploadsTar(w *io.PipeWriter, uploadDir string) error {+ return writeDirectoryTar(w, uploadDir, UploadsDirName, "upload", "uploads")+}++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+ })+}++// ResourceRef is a lightweight reference to a user resource for copying into a flow.+type ResourceRef struct {+ Hash string // MD5 hex — name of the .blob file in the resources store+ VirtualPath string // virtual path (relative) used to restore directory hierarchy+ Name string // display name+ IsDir bool+}++// CopyResourcesToFlow copies user resource blobs into flow-{id}-data/resources/,+// restoring the virtual directory hierarchy from VirtualPath.+// Already-present files are skipped (idempotent); when force is true, existing files are replaced.+// Returns relative paths ("resources/<virtualPath>") of newly added or replaced files.+func CopyResourcesToFlow(dataDir, resourcesStoreDir string, flowID uint64, refs []ResourceRef, force bool) ([]string, error) {+ resourcesDir := FlowResourcesDir(dataDir, flowID)+ var added []string++ for _, ref := range refs {+ if ref.IsDir {+ dst := filepath.Join(resourcesDir, filepath.FromSlash(ref.VirtualPath))+ if !IsWithinDir(dst, resourcesDir) {+ return added, fmt.Errorf("resource path '%s' escapes resources directory", ref.VirtualPath)+ }+ if err := os.MkdirAll(dst, 0755); err != nil {+ return added, fmt.Errorf("failed to create resource directory '%s': %w", ref.VirtualPath, err)+ }+ continue+ }++ dst := filepath.Join(resourcesDir, filepath.FromSlash(ref.VirtualPath))+ if !IsWithinDir(dst, resourcesDir) {+ return added, fmt.Errorf("resource path '%s' escapes resources directory", ref.VirtualPath)+ }++ if _, err := os.Lstat(dst); err == nil {+ if !force {+ continue // already present, skip+ }+ if err := os.Remove(dst); err != nil {+ return added, fmt.Errorf("failed to remove existing resource '%s': %w", ref.VirtualPath, err)+ }+ }++ if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {+ return added, fmt.Errorf("failed to create parent directory for resource '%s': %w", ref.VirtualPath, err)+ }++ src := filepath.Join(resourcesStoreDir, ref.Hash+".blob")+ if err := copyFile(src, dst); err != nil {+ return added, fmt.Errorf("failed to copy resource '%s': %w", ref.VirtualPath, err)+ }++ added = append(added, path.Join(ResourcesDirName, filepath.ToSlash(ref.VirtualPath)))+ }++ return added, nil+}++func copyFile(src, dst string) error {+ in, err := os.Open(src)+ if err != nil {+ return fmt.Errorf("failed to open source file: %w", err)+ }+ defer in.Close()++ out, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)+ if err != nil {+ return fmt.Errorf("failed to create destination file: %w", err)+ }+ defer out.Close()++ if _, err := io.Copy(out, in); err != nil {+ return fmt.Errorf("failed to copy file content: %w", err)+ }+ return nil+}++// WriteResourcesTar writes flow-{id}-data/resources/ as a tar stream+// with entries prefixed as "resources/<path>", mirroring WriteUploadsTar.+func WriteResourcesTar(w *io.PipeWriter, resourcesDir string) error {+ return writeDirectoryTar(w, resourcesDir, ResourcesDirName, "resource", "resources")+}++func writeDirectoryTar(w *io.PipeWriter, rootDir, tarRootName, entryLabel, cacheLabel string) error {tw := tar.NewWriter(w)defer w.Close()defer tw.Close()if err := tw.WriteHeader(&tar.Header{Typeflag: tar.TypeDir,- Name: UploadsDirName,+ Name: tarRootName,Mode: 0755,ModTime: time.Now(),}); err != nil {w.CloseWithError(err)- return fmt.Errorf("failed to write uploads directory tar header: %w", err)+ return fmt.Errorf("failed to write %s directory tar header: %w", cacheLabel, err)}var filesCount intvar totalSize int64- return filepath.WalkDir(uploadDir, func(entryPath string, d os.DirEntry, err error) error {+ return filepath.WalkDir(rootDir, func(entryPath string, d os.DirEntry, err error) error {if err != nil {w.CloseWithError(err)return err}- if entryPath == uploadDir {+ if entryPath == rootDir {return nil}if d.Type()&os.ModeSymlink != 0 {@@ -376,12 +586,12 @@ func WriteUploadsTar(w *io.PipeWriter, uploadDir string) error {return nil}- rel, err := filepath.Rel(uploadDir, entryPath)+ rel, err := filepath.Rel(rootDir, entryPath)if err != nil {w.CloseWithError(err)- return fmt.Errorf("failed to get upload relative path: %w", err)+ return fmt.Errorf("failed to get %s relative path: %w", entryLabel, err)}- headerName := path.Join(UploadsDirName, filepath.ToSlash(rel))+ headerName := path.Join(tarRootName, filepath.ToSlash(rel))if info.IsDir() {if err := tw.WriteHeader(&tar.Header{@@ -391,20 +601,20 @@ func WriteUploadsTar(w *io.PipeWriter, uploadDir string) error {ModTime: info.ModTime(),}); err != nil {w.CloseWithError(err)- return fmt.Errorf("failed to write upload directory tar header: %w", err)+ return fmt.Errorf("failed to write %s directory tar header: %w", entryLabel, err)}return nil}filesCount++if filesCount > MaxUploadFiles {- err := fmt.Errorf("uploads cache exceeds maximum file count of %d", MaxUploadFiles)+ err := fmt.Errorf("%s cache exceeds maximum file count of %d", cacheLabel, 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)+ err := fmt.Errorf("%s cache exceeds maximum total size of %d bytes", cacheLabel, MaxUploadTotalSize)w.CloseWithError(err)return err}@@ -417,127 +627,198 @@ func WriteUploadsTar(w *io.PipeWriter, uploadDir string) error {ModTime: info.ModTime(),}); err != nil {w.CloseWithError(err)- return fmt.Errorf("failed to write upload file tar header: %w", err)+ return fmt.Errorf("failed to write %s file tar header: %w", entryLabel, err)}f, err := os.Open(entryPath)if err != nil {w.CloseWithError(err)- return fmt.Errorf("failed to open upload file: %w", err)+ return fmt.Errorf("failed to open %s file: %w", entryLabel, 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 fmt.Errorf("failed to write %s file tar content: %w", entryLabel, 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- }+// FileListingForPrompt returns a compact XML block listing user-accessible files in+// uploads/ and resources/ for injection into agent system prompts.+// Each tag carries a base attribute with the container-side root path; individual+// entries are slash-separated relative paths (no repeated prefix per file).+// Returns empty string when both directories are empty or absent.+func FileListingForPrompt(dataDir string, flowID uint64) string {+ uploadsBase := filepath.Join(docker.WorkFolderPathInContainer, UploadsDirName)+ uploadFiles := collectRelativeFilePaths(FlowUploadsDir(dataDir, flowID))+ resourcesBase := filepath.Join(docker.WorkFolderPathInContainer, ResourcesDirName)+ resourceFiles := collectRelativeFilePaths(FlowResourcesDir(dataDir, flowID))++ if len(uploadFiles) == 0 && len(resourceFiles) == 0 {+ return ""+ }- entryPath := filepath.Join(destDir, filepath.Clean(filepath.FromSlash(hdr.Name)))- if !IsWithinDir(entryPath, destDir) {- continue- }+ var b strings.Builder+ b.WriteString("<task_files>\n")- 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)- }+ if len(uploadFiles) > 0 {+ b.WriteString("<uploads base=\"")+ b.WriteString(uploadsBase)+ b.WriteString("\">\n")+ for _, p := range uploadFiles {+ b.WriteString(p)+ b.WriteByte('\n')+ }+ b.WriteString("</uploads>\n")+ }- 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)- }+ if len(resourceFiles) > 0 {+ b.WriteString("<resources base=\"")+ b.WriteString(resourcesBase)+ b.WriteString("\">\n")+ for _, p := range resourceFiles {+ b.WriteString(p)+ b.WriteByte('\n')}+ b.WriteString("</resources>\n")}- return nil+ b.WriteString("</task_files>")+ return b.String()}-func ZipDirectory(w io.Writer, dirPath string) error {- zw := zip.NewWriter(w)- defer zw.Close()+// collectRelativeFilePaths walks dir and returns slash-separated paths relative to dir.+// Symlinks and directories are skipped; only regular files are included.+func collectRelativeFilePaths(dir string) []string {+ if _, err := os.Lstat(dir); err != nil {+ return nil+ }- return filepath.WalkDir(dirPath, func(entryPath string, d fs.DirEntry, err error) error {- if err != nil {- return err+ var paths []string+ _ = filepath.WalkDir(dir, func(entryPath string, d fs.DirEntry, err error) error {+ if err != nil || entryPath == dir {+ return nil}- if d.IsDir() {+ if d.Type()&os.ModeSymlink != 0 || d.IsDir() {return nil}- if d.Type()&os.ModeSymlink != 0 || !d.Type().IsRegular() {+ if !d.Type().IsRegular() {return nil}-- rel, err := filepath.Rel(dirPath, entryPath)+ rel, err := filepath.Rel(dir, entryPath)if err != nil {- return fmt.Errorf("failed to get relative path: %w", err)+ return nil}+ paths = append(paths, filepath.ToSlash(rel))+ return nil+ })+ return paths+}- info, err := d.Info()- if err != nil {- return fmt.Errorf("failed to get file info: %w", err)+// BaseName returns the last path component of a slash-separated path.+func BaseName(p string) string {+ for i := len(p) - 1; i >= 0; i-- {+ if p[i] == '/' || p[i] == '\\' {+ return p[i+1:]}+ }+ return p+}- header, err := zip.FileInfoHeader(info)- if err != nil {- return fmt.Errorf("failed to create zip header: %w", err)+// WriteSingleFileTar writes a single regular file as a tar stream.+// tarName is the path inside the tar archive (e.g. "resources/creds/pass.txt").+func WriteSingleFileTar(w *io.PipeWriter, absPath, tarName string) error {+ return WriteFilesTar(w, []TarEntry{{LocalPath: absPath, TarPath: tarName}})+}++// WriteFilesTar writes regular files into a tar stream and emits parent+// directory headers once per archive. Missing files are skipped to tolerate+// concurrent cache changes between listing and copying.+func WriteFilesTar(w *io.PipeWriter, entries []TarEntry) error {+ tw := tar.NewWriter(w)+ defer w.Close()+ defer tw.Close()++ createdDirs := make(map[string]bool)+ for _, entry := range entries {+ tarName := path.Clean(strings.ReplaceAll(entry.TarPath, "\\", "/"))+ if tarName == "." || strings.HasPrefix(tarName, "../") || strings.HasPrefix(tarName, "/") {+ err := fmt.Errorf("invalid tar entry path '%s'", entry.TarPath)+ w.CloseWithError(err)+ return err}- header.Name = filepath.ToSlash(rel)- header.Method = zip.Deflate- zf, err := zw.CreateHeader(header)+ info, err := os.Lstat(entry.LocalPath)if err != nil {- return fmt.Errorf("failed to create zip entry: %w", err)+ if errors.Is(err, os.ErrNotExist) {+ continue+ }+ w.CloseWithError(err)+ return fmt.Errorf("failed to stat file '%s': %w", entry.LocalPath, err)+ }+ if !info.Mode().IsRegular() {+ continue}- f, err := os.Open(entryPath)+ if err := writeTarParentDirs(tw, path.Dir(tarName), createdDirs); err != nil {+ w.CloseWithError(err)+ return fmt.Errorf("failed to write directory tar headers for '%s': %w", tarName, err)+ }++ if err := tw.WriteHeader(&tar.Header{+ Typeflag: tar.TypeReg,+ Name: tarName,+ Mode: int64(info.Mode().Perm()),+ Size: info.Size(),+ ModTime: info.ModTime(),+ }); err != nil {+ w.CloseWithError(err)+ return fmt.Errorf("failed to write file tar header for '%s': %w", tarName, err)+ }++ f, err := os.Open(entry.LocalPath)if err != nil {- return fmt.Errorf("failed to open file for zip: %w", err)+ w.CloseWithError(err)+ return fmt.Errorf("failed to open file '%s': %w", entry.LocalPath, err)}- defer f.Close()+ if _, err := io.Copy(tw, f); err != nil {+ f.Close()+ w.CloseWithError(err)+ return fmt.Errorf("failed to write file '%s' into tar: %w", entry.LocalPath, err)+ }+ f.Close()+ }- _, err = io.Copy(zf, f)- return err- })+ return nil+}++func writeTarParentDirs(tw *tar.Writer, dirPath string, created map[string]bool) error {+ parts := strings.Split(dirPath, "/")+ built := ""+ for _, part := range parts {+ if part == "" || part == "." {+ continue+ }+ if built == "" {+ built = part+ } else {+ built = built + "/" + part+ }+ if created[built] {+ continue+ }+ if err := tw.WriteHeader(&tar.Header{+ Typeflag: tar.TypeDir,+ Name: built,+ Mode: 0755,+ ModTime: time.Now(),+ }); err != nil {+ return err+ }+ created[built] = true+ }+ return nil}diff --git a/backend/pkg/flowfiles/files_test.go b/backend/pkg/flowfiles/files_test.goindex c2ad696d..83891cdb 100644--- a/backend/pkg/flowfiles/files_test.go+++ b/backend/pkg/flowfiles/files_test.go@@ -53,6 +53,7 @@ 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))+ assert.Equal(t, "/data/flow-42-data/resources", FlowResourcesDir("/data", 42))}func TestSanitizeFileName(t *testing.T) {@@ -129,6 +130,7 @@ func TestResolveCachedPath(t *testing.T) {}{{"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},+ {"resources file", "resources/creds/passwords.txt", "/data/flow-1-data/resources/creds/passwords.txt", 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},@@ -210,11 +212,14 @@ func TestListBothSources(t *testing.T) {dataDir := t.TempDir()uploadsDir := FlowUploadsDir(dataDir, 7)containerDir := FlowContainerDir(dataDir, 7)+ resourcesDir := FlowResourcesDir(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.MkdirAll(filepath.Join(resourcesDir, "creds"), 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))+ require.NoError(t, os.WriteFile(filepath.Join(resourcesDir, "creds", "passwords.txt"), []byte("secret"), 0644))files, err := List(dataDir, 7)require.NoError(t, err)@@ -227,6 +232,8 @@ func TestListBothSources(t *testing.T) {assert.Contains(t, paths, "uploads/wordlist.txt")assert.Contains(t, paths, "container/etc/nginx/conf")assert.Contains(t, paths, "container/etc/nginx/nginx.conf")+ assert.Contains(t, paths, "resources/creds")+ assert.Contains(t, paths, "resources/creds/passwords.txt")}func TestLocalEntryExistsAndRegularFileInfo(t *testing.T) {@@ -340,6 +347,242 @@ func TestWriteUploadsTar(t *testing.T) {assert.NotContains(t, contents, "uploads/link.txt")}+func TestCopyResourcesToFlow(t *testing.T) {+ dataDir := t.TempDir()+ storeDir := filepath.Join(dataDir, "resources")+ require.NoError(t, os.MkdirAll(storeDir, 0755))+ require.NoError(t, os.WriteFile(filepath.Join(storeDir, "hash-a.blob"), []byte("alpha"), 0644))+ require.NoError(t, os.WriteFile(filepath.Join(storeDir, "hash-b.blob"), []byte("bravo"), 0644))++ added, err := CopyResourcesToFlow(dataDir, storeDir, 3, []ResourceRef{+ {VirtualPath: "creds", IsDir: true},+ {Hash: "hash-a", VirtualPath: "creds/passwords.txt", Name: "passwords.txt"},+ {Hash: "hash-b", VirtualPath: "notes.txt", Name: "notes.txt"},+ }, false)+ require.NoError(t, err)+ assert.ElementsMatch(t, []string{+ "resources/creds/passwords.txt",+ "resources/notes.txt",+ }, added)++ data, err := os.ReadFile(filepath.Join(FlowResourcesDir(dataDir, 3), "creds", "passwords.txt"))+ require.NoError(t, err)+ assert.Equal(t, "alpha", string(data))++ added, err = CopyResourcesToFlow(dataDir, storeDir, 3, []ResourceRef{+ {Hash: "hash-a", VirtualPath: "creds/passwords.txt", Name: "passwords.txt"},+ }, false)+ require.NoError(t, err)+ assert.Empty(t, added)++ require.NoError(t, os.WriteFile(filepath.Join(storeDir, "hash-a.blob"), []byte("updated"), 0644))+ added, err = CopyResourcesToFlow(dataDir, storeDir, 3, []ResourceRef{+ {Hash: "hash-a", VirtualPath: "creds/passwords.txt", Name: "passwords.txt"},+ }, true)+ require.NoError(t, err)+ assert.Equal(t, []string{"resources/creds/passwords.txt"}, added)++ data, err = os.ReadFile(filepath.Join(FlowResourcesDir(dataDir, 3), "creds", "passwords.txt"))+ require.NoError(t, err)+ assert.Equal(t, "updated", string(data))+}++func TestCopyResourcesToFlowRejectsEscapingPath(t *testing.T) {+ dataDir := t.TempDir()+ storeDir := filepath.Join(dataDir, "resources")+ require.NoError(t, os.MkdirAll(storeDir, 0755))+ require.NoError(t, os.WriteFile(filepath.Join(storeDir, "hash.blob"), []byte("x"), 0644))++ _, err := CopyResourcesToFlow(dataDir, storeDir, 3, []ResourceRef{+ {Hash: "hash", VirtualPath: "../evil.txt", Name: "evil.txt"},+ }, false)+ require.Error(t, err)+ assert.Contains(t, err.Error(), "escapes resources directory")+}++func TestWriteResourcesTar(t *testing.T) {+ resourcesDir := t.TempDir()+ require.NoError(t, os.MkdirAll(filepath.Join(resourcesDir, "creds"), 0755))+ require.NoError(t, os.WriteFile(filepath.Join(resourcesDir, "creds", "passwords.txt"), []byte("secret"), 0644))+ if err := os.Symlink(filepath.Join(resourcesDir, "creds", "passwords.txt"), filepath.Join(resourcesDir, "link.txt")); err != nil {+ t.Skipf("symlink creation not available: %v", err)+ }++ pr, pw := io.Pipe()+ errCh := make(chan error, 1)+ go func() {+ errCh <- WriteResourcesTar(pw, resourcesDir)+ }()++ 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, "secret", contents["resources/creds/passwords.txt"])+ assert.NotContains(t, contents, "resources/link.txt")+}++func TestFileListingForPrompt(t *testing.T) {+ dataDir := t.TempDir()+ uploadsDir := FlowUploadsDir(dataDir, 11)+ resourcesDir := FlowResourcesDir(dataDir, 11)+ require.NoError(t, os.MkdirAll(filepath.Join(uploadsDir, "targets"), 0755))+ require.NoError(t, os.MkdirAll(filepath.Join(resourcesDir, "creds"), 0755))+ require.NoError(t, os.WriteFile(filepath.Join(uploadsDir, "targets", "ips.txt"), []byte("127.0.0.1"), 0644))+ require.NoError(t, os.WriteFile(filepath.Join(resourcesDir, "creds", "passwords.txt"), []byte("secret"), 0644))+ if err := os.Symlink(filepath.Join(uploadsDir, "targets", "ips.txt"), filepath.Join(uploadsDir, "link.txt")); err != nil {+ t.Skipf("symlink creation not available: %v", err)+ }++ listing := FileListingForPrompt(dataDir, 11)++ assert.Contains(t, listing, "<task_files>")+ assert.Contains(t, listing, `<uploads base="/work/uploads">`)+ assert.Contains(t, listing, "targets/ips.txt\n")+ assert.Contains(t, listing, `<resources base="/work/resources">`)+ assert.Contains(t, listing, "creds/passwords.txt\n")+ assert.NotContains(t, listing, "link.txt")+}++func TestFileListingForPromptEmpty(t *testing.T) {+ assert.Empty(t, FileListingForPrompt(t.TempDir(), 11))+}++func TestBaseName(t *testing.T) {+ assert.Equal(t, "passwords.txt", BaseName("resources/creds/passwords.txt"))+ assert.Equal(t, "passwords.txt", BaseName(`resources\creds\passwords.txt`))+ assert.Equal(t, "plain.txt", BaseName("plain.txt"))+}++func TestWriteSingleFileTar(t *testing.T) {+ dir := t.TempDir()+ filePath := filepath.Join(dir, "passwords.txt")+ require.NoError(t, os.WriteFile(filePath, []byte("secret"), 0644))++ pr, pw := io.Pipe()+ errCh := make(chan error, 1)+ go func() {+ errCh <- WriteSingleFileTar(pw, filePath, "resources/creds/passwords.txt")+ }()++ var buf bytes.Buffer+ _, err := io.Copy(&buf, pr)+ require.NoError(t, err)+ require.NoError(t, <-errCh)++ tr := tar.NewReader(bytes.NewReader(buf.Bytes()))+ seenDirs := map[string]bool{}+ contents := map[string]string{}+ for {+ hdr, err := tr.Next()+ if err == io.EOF {+ break+ }+ require.NoError(t, err)+ switch hdr.Typeflag {+ case tar.TypeDir:+ seenDirs[hdr.Name] = true+ case tar.TypeReg:+ data, err := io.ReadAll(tr)+ require.NoError(t, err)+ contents[hdr.Name] = string(data)+ }+ }++ assert.True(t, seenDirs["resources"])+ assert.True(t, seenDirs["resources/creds"])+ assert.Equal(t, "secret", contents["resources/creds/passwords.txt"])+}++func TestWriteFilesTar(t *testing.T) {+ dir := t.TempDir()+ firstPath := filepath.Join(dir, "passwords.txt")+ secondPath := filepath.Join(dir, "ips.txt")+ missingPath := filepath.Join(dir, "missing.txt")+ require.NoError(t, os.WriteFile(firstPath, []byte("secret"), 0644))+ require.NoError(t, os.WriteFile(secondPath, []byte("127.0.0.1"), 0644))+ if err := os.Symlink(firstPath, filepath.Join(dir, "link.txt")); err != nil {+ t.Skipf("symlink creation not available: %v", err)+ }++ pr, pw := io.Pipe()+ errCh := make(chan error, 1)+ go func() {+ errCh <- WriteFilesTar(pw, []TarEntry{+ {LocalPath: firstPath, TarPath: "resources/creds/passwords.txt"},+ {LocalPath: secondPath, TarPath: "uploads/targets/ips.txt"},+ {LocalPath: filepath.Join(dir, "link.txt"), TarPath: "uploads/link.txt"},+ {LocalPath: missingPath, TarPath: "uploads/missing.txt"},+ })+ }()++ var buf bytes.Buffer+ _, err := io.Copy(&buf, pr)+ require.NoError(t, err)+ require.NoError(t, <-errCh)++ tr := tar.NewReader(bytes.NewReader(buf.Bytes()))+ seenDirs := map[string]bool{}+ contents := map[string]string{}+ for {+ hdr, err := tr.Next()+ if err == io.EOF {+ break+ }+ require.NoError(t, err)+ switch hdr.Typeflag {+ case tar.TypeDir:+ seenDirs[hdr.Name] = true+ case tar.TypeReg:+ data, err := io.ReadAll(tr)+ require.NoError(t, err)+ contents[hdr.Name] = string(data)+ }+ }++ assert.True(t, seenDirs["resources"])+ assert.True(t, seenDirs["resources/creds"])+ assert.True(t, seenDirs["uploads"])+ assert.True(t, seenDirs["uploads/targets"])+ assert.Equal(t, "secret", contents["resources/creds/passwords.txt"])+ assert.Equal(t, "127.0.0.1", contents["uploads/targets/ips.txt"])+ assert.NotContains(t, contents, "uploads/link.txt")+ assert.NotContains(t, contents, "uploads/missing.txt")+}++func TestWriteFilesTarRejectsInvalidTarPath(t *testing.T) {+ dir := t.TempDir()+ filePath := filepath.Join(dir, "passwords.txt")+ require.NoError(t, os.WriteFile(filePath, []byte("secret"), 0644))++ pr, pw := io.Pipe()+ errCh := make(chan error, 1)+ go func() {+ errCh <- WriteFilesTar(pw, []TarEntry{{LocalPath: filePath, TarPath: "../evil.txt"}})+ }()++ _, err := io.Copy(io.Discard, pr)+ require.Error(t, err)+ require.Error(t, <-errCh)+}+func TestExtractTarRegularFiles(t *testing.T) {destDir := t.TempDir()buf := buildTar(t, []tarTestEntry{diff --git a/backend/pkg/graph/context.go b/backend/pkg/graph/context.goindex 90c97b18..e415d453 100644--- a/backend/pkg/graph/context.go+++ b/backend/pkg/graph/context.go@@ -123,6 +123,45 @@ func validatePermissionWithFlowID(return uid, nil}+// validateUserResources checks that all given IDs exist and belong to uid (or uid is admin).+// Returns the fetched UserResource records for use in copy operations.+// An empty ids slice is valid and returns nil, nil.+func validateUserResources(+ ctx context.Context,+ db database.Querier,+ uid int64,+ isAdmin bool,+ ids []int64,+) ([]database.UserResource, error) {+ if len(ids) == 0 {+ return nil, nil+ }++ dbResources, err := db.GetUserResourcesByIDs(ctx, ids)+ if err != nil {+ return nil, fmt.Errorf("failed to fetch resources: %w", err)+ }++ found := make(map[int64]database.UserResource, len(dbResources))+ for _, r := range dbResources {+ found[r.ID] = r+ }++ result := make([]database.UserResource, 0, len(ids))+ for _, id := range ids {+ r, ok := found[id]+ if !ok {+ return nil, fmt.Errorf("resource %d not found", id)+ }+ if !isAdmin && r.UserID != uid {+ return nil, fmt.Errorf("resource %d not accessible", id)+ }+ result = append(result, r)+ }++ return result, nil+}+func convertFlowFiles(files flowfiles.Files) []*model.FlowFile {converted := make([]*model.FlowFile, 0, len(files.Files))for _, file := range files.Files {diff --git a/backend/pkg/graph/generated.go b/backend/pkg/graph/generated.goindex 2d9d10d3..5b5bb569 100644--- a/backend/pkg/graph/generated.go+++ b/backend/pkg/graph/generated.go@@ -323,10 +323,10 @@ type ComplexityRoot struct {Mutation struct {AddFavoriteFlow func(childComplexity int, flowID int64) int- CallAssistant func(childComplexity int, flowID int64, assistantID int64, input string, useAgents bool) int+ CallAssistant func(childComplexity int, flowID int64, assistantID int64, input string, useAgents bool, resourceIds []int64) intCreateAPIToken func(childComplexity int, input model.CreateAPITokenInput) int- CreateAssistant func(childComplexity int, flowID int64, modelProvider string, input string, useAgents bool) int- CreateFlow func(childComplexity int, modelProvider string, input string) int+ CreateAssistant func(childComplexity int, flowID int64, modelProvider string, input string, useAgents bool, resourceIds []int64) int+ CreateFlow func(childComplexity int, modelProvider string, input string, resourceIds []int64) intCreateFlowTemplate func(childComplexity int, input model.CreateFlowTemplateInput) intCreatePrompt func(childComplexity int, typeArg model.PromptType, template string) intCreateProvider func(childComplexity int, name string, typeArg model.ProviderType, agents model.AgentsConfig) int@@ -338,7 +338,7 @@ type ComplexityRoot struct {DeletePrompt func(childComplexity int, promptID int64) intDeleteProvider func(childComplexity int, providerID int64) intFinishFlow func(childComplexity int, flowID int64) int- PutUserInput func(childComplexity int, flowID int64, input string, modelProvider *string) int+ PutUserInput func(childComplexity int, flowID int64, input string, modelProvider *string, resourceIds []int64) intRenameFlow func(childComplexity int, flowID int64, title string) intStopAssistant func(childComplexity int, flowID int64, assistantID int64) intStopFlow func(childComplexity int, flowID int64) int@@ -449,6 +449,7 @@ type ComplexityRoot struct {FlowsStatsTotal func(childComplexity int) intMessageLogs func(childComplexity int, flowID int64) intProviders func(childComplexity int) int+ Resources func(childComplexity int, path *string, recursive *bool) intScreenshots func(childComplexity int, flowID int64) intSearchLogs func(childComplexity int, flowID int64) intSettings func(childComplexity int) int@@ -532,6 +533,9 @@ type ComplexityRoot struct {ProviderCreated func(childComplexity int) intProviderDeleted func(childComplexity int) intProviderUpdated func(childComplexity int) int+ ResourceAdded func(childComplexity int) int+ ResourceDeleted func(childComplexity int) int+ ResourceUpdated func(childComplexity int) intScreenshotAdded func(childComplexity int, flowID int64) intSearchLogAdded func(childComplexity int, flowID int64) intSettingsUserUpdated func(childComplexity int) int@@ -651,6 +655,17 @@ type ComplexityRoot struct {UpdatedAt func(childComplexity int) int}+ UserResource struct {+ CreatedAt func(childComplexity int) int+ ID func(childComplexity int) int+ IsDir func(childComplexity int) int+ Name func(childComplexity int) int+ Path func(childComplexity int) int+ Size func(childComplexity int) int+ UpdatedAt func(childComplexity int) int+ UserID func(childComplexity int) int+ }+VectorStoreLog struct {Action func(childComplexity int) intCreatedAt func(childComplexity int) int@@ -667,14 +682,14 @@ type ComplexityRoot struct {}type MutationResolver interface {- CreateFlow(ctx context.Context, modelProvider string, input string) (*model.Flow, error)- PutUserInput(ctx context.Context, flowID int64, input string, modelProvider *string) (model.ResultType, error)+ CreateFlow(ctx context.Context, modelProvider string, input string, resourceIds []int64) (*model.Flow, error)+ PutUserInput(ctx context.Context, flowID int64, input string, modelProvider *string, resourceIds []int64) (model.ResultType, error)StopFlow(ctx context.Context, flowID int64) (model.ResultType, error)FinishFlow(ctx context.Context, flowID int64) (model.ResultType, error)DeleteFlow(ctx context.Context, flowID int64) (model.ResultType, error)RenameFlow(ctx context.Context, flowID int64, title string) (model.ResultType, error)- CreateAssistant(ctx context.Context, flowID int64, modelProvider string, input string, useAgents bool) (*model.FlowAssistant, error)- CallAssistant(ctx context.Context, flowID int64, assistantID int64, input string, useAgents bool) (model.ResultType, error)+ CreateAssistant(ctx context.Context, flowID int64, modelProvider string, input string, useAgents bool, resourceIds []int64) (*model.FlowAssistant, error)+ CallAssistant(ctx context.Context, flowID int64, assistantID int64, input string, useAgents bool, resourceIds []int64) (model.ResultType, error)StopAssistant(ctx context.Context, flowID int64, assistantID int64) (*model.Assistant, error)DeleteAssistant(ctx context.Context, flowID int64, assistantID int64) (model.ResultType, error)TestAgent(ctx context.Context, typeArg model.ProviderType, agentType model.AgentConfigType, agent model.AgentConfig) (*model.AgentTestResult, error)@@ -734,6 +749,7 @@ type QueryResolver interface {APITokens(ctx context.Context) ([]*model.APIToken, error)FlowTemplate(ctx context.Context, templateID int64) (*model.FlowTemplate, error)FlowTemplates(ctx context.Context) ([]*model.FlowTemplate, error)+ Resources(ctx context.Context, path *string, recursive *bool) ([]*model.UserResource, error)}type SubscriptionResolver interface {FlowCreated(ctx context.Context) (<-chan *model.Flow, error)@@ -766,6 +782,9 @@ type SubscriptionResolver interface {FlowTemplateCreated(ctx context.Context) (<-chan *model.FlowTemplate, error)FlowTemplateUpdated(ctx context.Context) (<-chan *model.FlowTemplate, error)FlowTemplateDeleted(ctx context.Context) (<-chan *model.FlowTemplate, error)+ ResourceAdded(ctx context.Context) (<-chan *model.UserResource, error)+ ResourceUpdated(ctx context.Context) (<-chan *model.UserResource, error)+ ResourceDeleted(ctx context.Context) (<-chan *model.UserResource, error)}type executableSchema struct {@@ -2055,7 +2074,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity inreturn 0, false}- return e.complexity.Mutation.CallAssistant(childComplexity, args["flowId"].(int64), args["assistantId"].(int64), args["input"].(string), args["useAgents"].(bool)), true+ return e.complexity.Mutation.CallAssistant(childComplexity, args["flowId"].(int64), args["assistantId"].(int64), args["input"].(string), args["useAgents"].(bool), args["resourceIds"].([]int64)), truecase "Mutation.createAPIToken":if e.complexity.Mutation.CreateAPIToken == nil {@@ -2079,7 +2098,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity inreturn 0, false}- return e.complexity.Mutation.CreateAssistant(childComplexity, args["flowId"].(int64), args["modelProvider"].(string), args["input"].(string), args["useAgents"].(bool)), true+ return e.complexity.Mutation.CreateAssistant(childComplexity, args["flowId"].(int64), args["modelProvider"].(string), args["input"].(string), args["useAgents"].(bool), args["resourceIds"].([]int64)), truecase "Mutation.createFlow":if e.complexity.Mutation.CreateFlow == nil {@@ -2091,7 +2110,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity inreturn 0, false}- return e.complexity.Mutation.CreateFlow(childComplexity, args["modelProvider"].(string), args["input"].(string)), true+ return e.complexity.Mutation.CreateFlow(childComplexity, args["modelProvider"].(string), args["input"].(string), args["resourceIds"].([]int64)), truecase "Mutation.createFlowTemplate":if e.complexity.Mutation.CreateFlowTemplate == nil {@@ -2235,7 +2254,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity inreturn 0, false}- return e.complexity.Mutation.PutUserInput(childComplexity, args["flowId"].(int64), args["input"].(string), args["modelProvider"].(*string)), true+ return e.complexity.Mutation.PutUserInput(childComplexity, args["flowId"].(int64), args["input"].(string), args["modelProvider"].(*string), args["resourceIds"].([]int64)), truecase "Mutation.renameFlow":if e.complexity.Mutation.RenameFlow == nil {@@ -2902,6 +2921,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity inreturn e.complexity.Query.Providers(childComplexity), true+ case "Query.resources":+ if e.complexity.Query.Resources == nil {+ break+ }++ args, err := ec.field_Query_resources_args(context.TODO(), rawArgs)+ if err != nil {+ return 0, false+ }++ return e.complexity.Query.Resources(childComplexity, args["path"].(*string), args["recursive"].(*bool)), true+case "Query.screenshots":if e.complexity.Query.Screenshots == nil {break@@ -3493,6 +3524,27 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity inreturn e.complexity.Subscription.ProviderUpdated(childComplexity), true+ case "Subscription.resourceAdded":+ if e.complexity.Subscription.ResourceAdded == nil {+ break+ }++ return e.complexity.Subscription.ResourceAdded(childComplexity), true++ case "Subscription.resourceDeleted":+ if e.complexity.Subscription.ResourceDeleted == nil {+ break+ }++ return e.complexity.Subscription.ResourceDeleted(childComplexity), true++ case "Subscription.resourceUpdated":+ if e.complexity.Subscription.ResourceUpdated == nil {+ break+ }++ return e.complexity.Subscription.ResourceUpdated(childComplexity), true+case "Subscription.screenshotAdded":if e.complexity.Subscription.ScreenshotAdded == nil {break@@ -4090,6 +4142,62 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity inreturn e.complexity.UserPrompt.UpdatedAt(childComplexity), true+ case "UserResource.createdAt":+ if e.complexity.UserResource.CreatedAt == nil {+ break+ }++ return e.complexity.UserResource.CreatedAt(childComplexity), true++ case "UserResource.id":+ if e.complexity.UserResource.ID == nil {+ break+ }++ return e.complexity.UserResource.ID(childComplexity), true++ case "UserResource.isDir":+ if e.complexity.UserResource.IsDir == nil {+ break+ }++ return e.complexity.UserResource.IsDir(childComplexity), true++ case "UserResource.name":+ if e.complexity.UserResource.Name == nil {+ break+ }++ return e.complexity.UserResource.Name(childComplexity), true++ case "UserResource.path":+ if e.complexity.UserResource.Path == nil {+ break+ }++ return e.complexity.UserResource.Path(childComplexity), true++ case "UserResource.size":+ if e.complexity.UserResource.Size == nil {+ break+ }++ return e.complexity.UserResource.Size(childComplexity), true++ case "UserResource.updatedAt":+ if e.complexity.UserResource.UpdatedAt == nil {+ break+ }++ return e.complexity.UserResource.UpdatedAt(childComplexity), true++ case "UserResource.userId":+ if e.complexity.UserResource.UserID == nil {+ break+ }++ return e.complexity.UserResource.UserID(childComplexity), true+case "VectorStoreLog.action":if e.complexity.VectorStoreLog.Action == nil {break@@ -4371,6 +4479,11 @@ func (ec *executionContext) field_Mutation_callAssistant_args(ctx context.Contexreturn nil, err}args["useAgents"] = arg3+ arg4, err := ec.field_Mutation_callAssistant_argsResourceIds(ctx, rawArgs)+ if err != nil {+ return nil, err+ }+ args["resourceIds"] = arg4return args, nil}func (ec *executionContext) field_Mutation_callAssistant_argsFlowID(@@ -4461,6 +4574,28 @@ func (ec *executionContext) field_Mutation_callAssistant_argsUseAgents(return zeroVal, nil}+func (ec *executionContext) field_Mutation_callAssistant_argsResourceIds(+ 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["resourceIds"]+ if !ok {+ var zeroVal []int64+ return zeroVal, nil+ }++ ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("resourceIds"))+ if tmp, ok := rawArgs["resourceIds"]; ok {+ return ec.unmarshalOID2ᚕint64ᚄ(ctx, tmp)+ }++ var zeroVal []int64+ return zeroVal, nil+}+func (ec *executionContext) field_Mutation_createAPIToken_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {var err errorargs := map[string]interface{}{}@@ -4516,6 +4651,11 @@ func (ec *executionContext) field_Mutation_createAssistant_args(ctx context.Contreturn nil, err}args["useAgents"] = arg3+ arg4, err := ec.field_Mutation_createAssistant_argsResourceIds(ctx, rawArgs)+ if err != nil {+ return nil, err+ }+ args["resourceIds"] = arg4return args, nil}func (ec *executionContext) field_Mutation_createAssistant_argsFlowID(@@ -4606,6 +4746,28 @@ func (ec *executionContext) field_Mutation_createAssistant_argsUseAgents(return zeroVal, nil}+func (ec *executionContext) field_Mutation_createAssistant_argsResourceIds(+ 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["resourceIds"]+ if !ok {+ var zeroVal []int64+ return zeroVal, nil+ }++ ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("resourceIds"))+ if tmp, ok := rawArgs["resourceIds"]; ok {+ return ec.unmarshalOID2ᚕint64ᚄ(ctx, tmp)+ }++ var zeroVal []int64+ return zeroVal, nil+}+func (ec *executionContext) field_Mutation_createFlowTemplate_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {var err errorargs := map[string]interface{}{}@@ -4651,6 +4813,11 @@ func (ec *executionContext) field_Mutation_createFlow_args(ctx context.Context,return nil, err}args["input"] = arg1+ arg2, err := ec.field_Mutation_createFlow_argsResourceIds(ctx, rawArgs)+ if err != nil {+ return nil, err+ }+ args["resourceIds"] = arg2return args, nil}func (ec *executionContext) field_Mutation_createFlow_argsModelProvider(@@ -4697,6 +4864,28 @@ func (ec *executionContext) field_Mutation_createFlow_argsInput(return zeroVal, nil}+func (ec *executionContext) field_Mutation_createFlow_argsResourceIds(+ 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["resourceIds"]+ if !ok {+ var zeroVal []int64+ return zeroVal, nil+ }++ ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("resourceIds"))+ if tmp, ok := rawArgs["resourceIds"]; ok {+ return ec.unmarshalOID2ᚕint64ᚄ(ctx, tmp)+ }++ var zeroVal []int64+ return zeroVal, nil+}+func (ec *executionContext) field_Mutation_createPrompt_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {var err errorargs := map[string]interface{}{}@@ -5143,6 +5332,11 @@ func (ec *executionContext) field_Mutation_putUserInput_args(ctx context.Contextreturn nil, err}args["modelProvider"] = arg2+ arg3, err := ec.field_Mutation_putUserInput_argsResourceIds(ctx, rawArgs)+ if err != nil {+ return nil, err+ }+ args["resourceIds"] = arg3return args, nil}func (ec *executionContext) field_Mutation_putUserInput_argsFlowID(@@ -5211,6 +5405,28 @@ func (ec *executionContext) field_Mutation_putUserInput_argsModelProvider(return zeroVal, nil}+func (ec *executionContext) field_Mutation_putUserInput_argsResourceIds(+ 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["resourceIds"]+ if !ok {+ var zeroVal []int64+ return zeroVal, nil+ }++ ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("resourceIds"))+ if tmp, ok := rawArgs["resourceIds"]; ok {+ return ec.unmarshalOID2ᚕint64ᚄ(ctx, tmp)+ }++ var zeroVal []int64+ return zeroVal, nil+}+func (ec *executionContext) field_Mutation_renameFlow_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {var err errorargs := map[string]interface{}{}@@ -6239,113 +6455,76 @@ func (ec *executionContext) field_Query_messageLogs_argsFlowID(return zeroVal, nil}-func (ec *executionContext) field_Query_screenshots_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {+func (ec *executionContext) field_Query_resources_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {var err errorargs := map[string]interface{}{}- arg0, err := ec.field_Query_screenshots_argsFlowID(ctx, rawArgs)+ arg0, err := ec.field_Query_resources_argsPath(ctx, rawArgs)if err != nil {return nil, err}- args["flowId"] = arg0- return args, nil-}-func (ec *executionContext) field_Query_screenshots_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_searchLogs_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {- var err error- args := map[string]interface{}{}- arg0, err := ec.field_Query_searchLogs_argsFlowID(ctx, rawArgs)+ args["path"] = arg0+ arg1, err := ec.field_Query_resources_argsRecursive(ctx, rawArgs)if err != nil {return nil, err}- args["flowId"] = arg0+ args["recursive"] = arg1return args, nil}-func (ec *executionContext) field_Query_searchLogs_argsFlowID(+func (ec *executionContext) field_Query_resources_argsPath(ctx context.Context,rawArgs map[string]interface{},-) (int64, error) {+) (*string, 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"]+ _, ok := rawArgs["path"]if !ok {- var zeroVal int64+ var zeroVal *stringreturn zeroVal, nil}- ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("flowId"))- if tmp, ok := rawArgs["flowId"]; ok {- return ec.unmarshalNID2int64(ctx, tmp)+ ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("path"))+ if tmp, ok := rawArgs["path"]; ok {+ return ec.unmarshalOString2ᚖstring(ctx, tmp)}- var zeroVal int64+ var zeroVal *stringreturn zeroVal, nil}-func (ec *executionContext) field_Query_tasks_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {- var err error- args := map[string]interface{}{}- arg0, err := ec.field_Query_tasks_argsFlowID(ctx, rawArgs)- if err != nil {- return nil, err- }- args["flowId"] = arg0- return args, nil-}-func (ec *executionContext) field_Query_tasks_argsFlowID(+func (ec *executionContext) field_Query_resources_argsRecursive(ctx context.Context,rawArgs map[string]interface{},-) (int64, error) {+) (*bool, 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"]+ _, ok := rawArgs["recursive"]if !ok {- var zeroVal int64+ var zeroVal *boolreturn zeroVal, nil}- ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("flowId"))- if tmp, ok := rawArgs["flowId"]; ok {- return ec.unmarshalNID2int64(ctx, tmp)+ ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("recursive"))+ if tmp, ok := rawArgs["recursive"]; ok {+ return ec.unmarshalOBoolean2ᚖbool(ctx, tmp)}- var zeroVal int64+ var zeroVal *boolreturn zeroVal, nil}-func (ec *executionContext) field_Query_terminalLogs_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {+func (ec *executionContext) field_Query_screenshots_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {var err errorargs := map[string]interface{}{}- arg0, err := ec.field_Query_terminalLogs_argsFlowID(ctx, rawArgs)+ arg0, err := ec.field_Query_screenshots_argsFlowID(ctx, rawArgs)if err != nil {return nil, err}args["flowId"] = arg0return args, nil}-func (ec *executionContext) field_Query_terminalLogs_argsFlowID(+func (ec *executionContext) field_Query_screenshots_argsFlowID(ctx context.Context,rawArgs map[string]interface{},) (int64, error) {@@ -6367,17 +6546,17 @@ func (ec *executionContext) field_Query_terminalLogs_argsFlowID(return zeroVal, nil}-func (ec *executionContext) field_Query_toolcallsStatsByFlow_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {+func (ec *executionContext) field_Query_searchLogs_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {var err errorargs := map[string]interface{}{}- arg0, err := ec.field_Query_toolcallsStatsByFlow_argsFlowID(ctx, rawArgs)+ arg0, err := ec.field_Query_searchLogs_argsFlowID(ctx, rawArgs)if err != nil {return nil, err}args["flowId"] = arg0return args, nil}-func (ec *executionContext) field_Query_toolcallsStatsByFlow_argsFlowID(+func (ec *executionContext) field_Query_searchLogs_argsFlowID(ctx context.Context,rawArgs map[string]interface{},) (int64, error) {@@ -6399,17 +6578,17 @@ func (ec *executionContext) field_Query_toolcallsStatsByFlow_argsFlowID(return zeroVal, nil}-func (ec *executionContext) field_Query_toolcallsStatsByFunctionForFlow_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {+func (ec *executionContext) field_Query_tasks_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {var err errorargs := map[string]interface{}{}- arg0, err := ec.field_Query_toolcallsStatsByFunctionForFlow_argsFlowID(ctx, rawArgs)+ arg0, err := ec.field_Query_tasks_argsFlowID(ctx, rawArgs)if err != nil {return nil, err}args["flowId"] = arg0return args, nil}-func (ec *executionContext) field_Query_toolcallsStatsByFunctionForFlow_argsFlowID(+func (ec *executionContext) field_Query_tasks_argsFlowID(ctx context.Context,rawArgs map[string]interface{},) (int64, error) {@@ -6431,49 +6610,17 @@ func (ec *executionContext) field_Query_toolcallsStatsByFunctionForFlow_argsFlowreturn zeroVal, nil}-func (ec *executionContext) field_Query_toolcallsStatsByPeriod_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {- var err error- args := map[string]interface{}{}- arg0, err := ec.field_Query_toolcallsStatsByPeriod_argsPeriod(ctx, rawArgs)- if err != nil {- return nil, err- }- args["period"] = arg0- return args, nil-}-func (ec *executionContext) field_Query_toolcallsStatsByPeriod_argsPeriod(- ctx context.Context,- rawArgs map[string]interface{},-) (model.UsageStatsPeriod, 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["period"]- if !ok {- var zeroVal model.UsageStatsPeriod- return zeroVal, nil- }-- ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("period"))- if tmp, ok := rawArgs["period"]; ok {- return ec.unmarshalNUsageStatsPeriod2pentagiᚋpkgᚋgraphᚋmodelᚐUsageStatsPeriod(ctx, tmp)- }-- var zeroVal model.UsageStatsPeriod- return zeroVal, nil-}--func (ec *executionContext) field_Query_usageStatsByAgentTypeForFlow_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {+func (ec *executionContext) field_Query_terminalLogs_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {var err errorargs := map[string]interface{}{}- arg0, err := ec.field_Query_usageStatsByAgentTypeForFlow_argsFlowID(ctx, rawArgs)+ arg0, err := ec.field_Query_terminalLogs_argsFlowID(ctx, rawArgs)if err != nil {return nil, err}args["flowId"] = arg0return args, nil}-func (ec *executionContext) field_Query_usageStatsByAgentTypeForFlow_argsFlowID(+func (ec *executionContext) field_Query_terminalLogs_argsFlowID(ctx context.Context,rawArgs map[string]interface{},) (int64, error) {@@ -6495,17 +6642,17 @@ func (ec *executionContext) field_Query_usageStatsByAgentTypeForFlow_argsFlowID(return zeroVal, nil}-func (ec *executionContext) field_Query_usageStatsByFlow_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {+func (ec *executionContext) field_Query_toolcallsStatsByFlow_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {var err errorargs := map[string]interface{}{}- arg0, err := ec.field_Query_usageStatsByFlow_argsFlowID(ctx, rawArgs)+ arg0, err := ec.field_Query_toolcallsStatsByFlow_argsFlowID(ctx, rawArgs)if err != nil {return nil, err}args["flowId"] = arg0return args, nil}-func (ec *executionContext) field_Query_usageStatsByFlow_argsFlowID(+func (ec *executionContext) field_Query_toolcallsStatsByFlow_argsFlowID(ctx context.Context,rawArgs map[string]interface{},) (int64, error) {@@ -6527,17 +6674,145 @@ func (ec *executionContext) field_Query_usageStatsByFlow_argsFlowID(return zeroVal, nil}-func (ec *executionContext) field_Query_usageStatsByModelAgentsForFlow_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {+func (ec *executionContext) field_Query_toolcallsStatsByFunctionForFlow_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {var err errorargs := map[string]interface{}{}- arg0, err := ec.field_Query_usageStatsByModelAgentsForFlow_argsFlowID(ctx, rawArgs)+ arg0, err := ec.field_Query_toolcallsStatsByFunctionForFlow_argsFlowID(ctx, rawArgs)if err != nil {return nil, err}args["flowId"] = arg0return args, nil}-func (ec *executionContext) field_Query_usageStatsByModelAgentsForFlow_argsFlowID(+func (ec *executionContext) field_Query_toolcallsStatsByFunctionForFlow_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_toolcallsStatsByPeriod_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {+ var err error+ args := map[string]interface{}{}+ arg0, err := ec.field_Query_toolcallsStatsByPeriod_argsPeriod(ctx, rawArgs)+ if err != nil {+ return nil, err+ }+ args["period"] = arg0+ return args, nil+}+func (ec *executionContext) field_Query_toolcallsStatsByPeriod_argsPeriod(+ ctx context.Context,+ rawArgs map[string]interface{},+) (model.UsageStatsPeriod, 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["period"]+ if !ok {+ var zeroVal model.UsageStatsPeriod+ return zeroVal, nil+ }++ ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("period"))+ if tmp, ok := rawArgs["period"]; ok {+ return ec.unmarshalNUsageStatsPeriod2pentagiᚋpkgᚋgraphᚋmodelᚐUsageStatsPeriod(ctx, tmp)+ }++ var zeroVal model.UsageStatsPeriod+ return zeroVal, nil+}++func (ec *executionContext) field_Query_usageStatsByAgentTypeForFlow_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {+ var err error+ args := map[string]interface{}{}+ arg0, err := ec.field_Query_usageStatsByAgentTypeForFlow_argsFlowID(ctx, rawArgs)+ if err != nil {+ return nil, err+ }+ args["flowId"] = arg0+ return args, nil+}+func (ec *executionContext) field_Query_usageStatsByAgentTypeForFlow_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_usageStatsByFlow_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {+ var err error+ args := map[string]interface{}{}+ arg0, err := ec.field_Query_usageStatsByFlow_argsFlowID(ctx, rawArgs)+ if err != nil {+ return nil, err+ }+ args["flowId"] = arg0+ return args, nil+}+func (ec *executionContext) field_Query_usageStatsByFlow_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_usageStatsByModelAgentsForFlow_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {+ var err error+ args := map[string]interface{}{}+ arg0, err := ec.field_Query_usageStatsByModelAgentsForFlow_argsFlowID(ctx, rawArgs)+ if err != nil {+ return nil, err+ }+ args["flowId"] = arg0+ return args, nil+}+func (ec *executionContext) field_Query_usageStatsByModelAgentsForFlow_argsFlowID(ctx context.Context,rawArgs map[string]interface{},) (int64, error) {@@ -15819,7 +16094,7 @@ func (ec *executionContext) _Mutation_createFlow(ctx context.Context, field grap}()resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {ctx = rctx // use context from middleware stack in children- return ec.resolvers.Mutation().CreateFlow(rctx, fc.Args["modelProvider"].(string), fc.Args["input"].(string))+ return ec.resolvers.Mutation().CreateFlow(rctx, fc.Args["modelProvider"].(string), fc.Args["input"].(string), fc.Args["resourceIds"].([]int64))})if err != nil {ec.Error(ctx, err)@@ -15890,7 +16165,7 @@ func (ec *executionContext) _Mutation_putUserInput(ctx context.Context, field gr}()resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {ctx = rctx // use context from middleware stack in children- return ec.resolvers.Mutation().PutUserInput(rctx, fc.Args["flowId"].(int64), fc.Args["input"].(string), fc.Args["modelProvider"].(*string))+ return ec.resolvers.Mutation().PutUserInput(rctx, fc.Args["flowId"].(int64), fc.Args["input"].(string), fc.Args["modelProvider"].(*string), fc.Args["resourceIds"].([]int64))})if err != nil {ec.Error(ctx, err)@@ -16165,7 +16440,7 @@ func (ec *executionContext) _Mutation_createAssistant(ctx context.Context, field}()resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {ctx = rctx // use context from middleware stack in children- return ec.resolvers.Mutation().CreateAssistant(rctx, fc.Args["flowId"].(int64), fc.Args["modelProvider"].(string), fc.Args["input"].(string), fc.Args["useAgents"].(bool))+ return ec.resolvers.Mutation().CreateAssistant(rctx, fc.Args["flowId"].(int64), fc.Args["modelProvider"].(string), fc.Args["input"].(string), fc.Args["useAgents"].(bool), fc.Args["resourceIds"].([]int64))})if err != nil {ec.Error(ctx, err)@@ -16226,7 +16501,7 @@ func (ec *executionContext) _Mutation_callAssistant(ctx context.Context, field g}()resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {ctx = rctx // use context from middleware stack in children- return ec.resolvers.Mutation().CallAssistant(rctx, fc.Args["flowId"].(int64), fc.Args["assistantId"].(int64), fc.Args["input"].(string), fc.Args["useAgents"].(bool))+ return ec.resolvers.Mutation().CallAssistant(rctx, fc.Args["flowId"].(int64), fc.Args["assistantId"].(int64), fc.Args["input"].(string), fc.Args["useAgents"].(bool), fc.Args["resourceIds"].([]int64))})if err != nil {ec.Error(ctx, err)@@ -22518,6 +22793,79 @@ func (ec *executionContext) fieldContext_Query_flowTemplates(_ context.Context,return fc, nil}+func (ec *executionContext) _Query_resources(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_Query_resources(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().Resources(rctx, fc.Args["path"].(*string), fc.Args["recursive"].(*bool))+ })+ 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.UserResource)+ fc.Result = res+ return ec.marshalNUserResource2ᚕᚖpentagiᚋpkgᚋgraphᚋmodelᚐUserResourceᚄ(ctx, field.Selections, res)+}++func (ec *executionContext) fieldContext_Query_resources(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_UserResource_id(ctx, field)+ case "userId":+ return ec.fieldContext_UserResource_userId(ctx, field)+ case "name":+ return ec.fieldContext_UserResource_name(ctx, field)+ case "path":+ return ec.fieldContext_UserResource_path(ctx, field)+ case "size":+ return ec.fieldContext_UserResource_size(ctx, field)+ case "isDir":+ return ec.fieldContext_UserResource_isDir(ctx, field)+ case "createdAt":+ return ec.fieldContext_UserResource_createdAt(ctx, field)+ case "updatedAt":+ return ec.fieldContext_UserResource_updatedAt(ctx, field)+ }+ return nil, fmt.Errorf("no field named %q was found under type UserResource", 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_resources_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {+ ec.Error(ctx, err)+ return fc, err+ }+ return fc, nil+}+func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {fc, err := ec.fieldContext_Query___type(ctx, field)if err != nil {@@ -26090,6 +26438,234 @@ func (ec *executionContext) fieldContext_Subscription_flowTemplateDeleted(_ contreturn fc, nil}+func (ec *executionContext) _Subscription_resourceAdded(ctx context.Context, field graphql.CollectedField) (ret func(ctx context.Context) graphql.Marshaler) {+ fc, err := ec.fieldContext_Subscription_resourceAdded(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().ResourceAdded(rctx)+ })+ 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.UserResource):+ if !ok {+ return nil+ }+ return graphql.WriterFunc(func(w io.Writer) {+ w.Write([]byte{'{'})+ graphql.MarshalString(field.Alias).MarshalGQL(w)+ w.Write([]byte{':'})+ ec.marshalNUserResource2ᚖpentagiᚋpkgᚋgraphᚋmodelᚐUserResource(ctx, field.Selections, res).MarshalGQL(w)+ w.Write([]byte{'}'})+ })+ case <-ctx.Done():+ return nil+ }+ }+}++func (ec *executionContext) fieldContext_Subscription_resourceAdded(_ 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_UserResource_id(ctx, field)+ case "userId":+ return ec.fieldContext_UserResource_userId(ctx, field)+ case "name":+ return ec.fieldContext_UserResource_name(ctx, field)+ case "path":+ return ec.fieldContext_UserResource_path(ctx, field)+ case "size":+ return ec.fieldContext_UserResource_size(ctx, field)+ case "isDir":+ return ec.fieldContext_UserResource_isDir(ctx, field)+ case "createdAt":+ return ec.fieldContext_UserResource_createdAt(ctx, field)+ case "updatedAt":+ return ec.fieldContext_UserResource_updatedAt(ctx, field)+ }+ return nil, fmt.Errorf("no field named %q was found under type UserResource", field.Name)+ },+ }+ return fc, nil+}++func (ec *executionContext) _Subscription_resourceUpdated(ctx context.Context, field graphql.CollectedField) (ret func(ctx context.Context) graphql.Marshaler) {+ fc, err := ec.fieldContext_Subscription_resourceUpdated(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().ResourceUpdated(rctx)+ })+ 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.UserResource):+ if !ok {+ return nil+ }+ return graphql.WriterFunc(func(w io.Writer) {+ w.Write([]byte{'{'})+ graphql.MarshalString(field.Alias).MarshalGQL(w)+ w.Write([]byte{':'})+ ec.marshalNUserResource2ᚖpentagiᚋpkgᚋgraphᚋmodelᚐUserResource(ctx, field.Selections, res).MarshalGQL(w)+ w.Write([]byte{'}'})+ })+ case <-ctx.Done():+ return nil+ }+ }+}++func (ec *executionContext) fieldContext_Subscription_resourceUpdated(_ 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_UserResource_id(ctx, field)+ case "userId":+ return ec.fieldContext_UserResource_userId(ctx, field)+ case "name":+ return ec.fieldContext_UserResource_name(ctx, field)+ case "path":+ return ec.fieldContext_UserResource_path(ctx, field)+ case "size":+ return ec.fieldContext_UserResource_size(ctx, field)+ case "isDir":+ return ec.fieldContext_UserResource_isDir(ctx, field)+ case "createdAt":+ return ec.fieldContext_UserResource_createdAt(ctx, field)+ case "updatedAt":+ return ec.fieldContext_UserResource_updatedAt(ctx, field)+ }+ return nil, fmt.Errorf("no field named %q was found under type UserResource", field.Name)+ },+ }+ return fc, nil+}++func (ec *executionContext) _Subscription_resourceDeleted(ctx context.Context, field graphql.CollectedField) (ret func(ctx context.Context) graphql.Marshaler) {+ fc, err := ec.fieldContext_Subscription_resourceDeleted(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().ResourceDeleted(rctx)+ })+ 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.UserResource):+ if !ok {+ return nil+ }+ return graphql.WriterFunc(func(w io.Writer) {+ w.Write([]byte{'{'})+ graphql.MarshalString(field.Alias).MarshalGQL(w)+ w.Write([]byte{':'})+ ec.marshalNUserResource2ᚖpentagiᚋpkgᚋgraphᚋmodelᚐUserResource(ctx, field.Selections, res).MarshalGQL(w)+ w.Write([]byte{'}'})+ })+ case <-ctx.Done():+ return nil+ }+ }+}++func (ec *executionContext) fieldContext_Subscription_resourceDeleted(_ 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_UserResource_id(ctx, field)+ case "userId":+ return ec.fieldContext_UserResource_userId(ctx, field)+ case "name":+ return ec.fieldContext_UserResource_name(ctx, field)+ case "path":+ return ec.fieldContext_UserResource_path(ctx, field)+ case "size":+ return ec.fieldContext_UserResource_size(ctx, field)+ case "isDir":+ return ec.fieldContext_UserResource_isDir(ctx, field)+ case "createdAt":+ return ec.fieldContext_UserResource_createdAt(ctx, field)+ case "updatedAt":+ return ec.fieldContext_UserResource_updatedAt(ctx, field)+ }+ return nil, fmt.Errorf("no field named %q was found under type UserResource", field.Name)+ },+ }+ return fc, nil+}+func (ec *executionContext) _Subtask_id(ctx context.Context, field graphql.CollectedField, obj *model.Subtask) (ret graphql.Marshaler) {fc, err := ec.fieldContext_Subtask_id(ctx, field)if err != nil {@@ -29178,9 +29754,317 @@ func (ec *executionContext) _UserPreferences_id(ctx context.Context, field graphreturn ec.marshalNID2int64(ctx, field.Selections, res)}-func (ec *executionContext) fieldContext_UserPreferences_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+func (ec *executionContext) fieldContext_UserPreferences_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+ fc = &graphql.FieldContext{+ Object: "UserPreferences",+ Field: field,+ IsMethod: false,+ IsResolver: false,+ Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {+ return nil, errors.New("field of type ID does not have child fields")+ },+ }+ return fc, nil+}++func (ec *executionContext) _UserPreferences_favoriteFlows(ctx context.Context, field graphql.CollectedField, obj *model.UserPreferences) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_UserPreferences_favoriteFlows(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.FavoriteFlows, 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.([]int64)+ fc.Result = res+ return ec.marshalNID2ᚕint64ᚄ(ctx, field.Selections, res)+}++func (ec *executionContext) fieldContext_UserPreferences_favoriteFlows(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+ fc = &graphql.FieldContext{+ Object: "UserPreferences",+ Field: field,+ IsMethod: false,+ IsResolver: false,+ Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {+ return nil, errors.New("field of type ID does not have child fields")+ },+ }+ return fc, nil+}++func (ec *executionContext) _UserPrompt_id(ctx context.Context, field graphql.CollectedField, obj *model.UserPrompt) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_UserPrompt_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.(int64)+ fc.Result = res+ return ec.marshalNID2int64(ctx, field.Selections, res)+}++func (ec *executionContext) fieldContext_UserPrompt_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+ fc = &graphql.FieldContext{+ Object: "UserPrompt",+ Field: field,+ IsMethod: false,+ IsResolver: false,+ Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {+ return nil, errors.New("field of type ID does not have child fields")+ },+ }+ return fc, nil+}++func (ec *executionContext) _UserPrompt_type(ctx context.Context, field graphql.CollectedField, obj *model.UserPrompt) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_UserPrompt_type(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.Type, 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.(model.PromptType)+ fc.Result = res+ return ec.marshalNPromptType2pentagiᚋpkgᚋgraphᚋmodelᚐPromptType(ctx, field.Selections, res)+}++func (ec *executionContext) fieldContext_UserPrompt_type(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+ fc = &graphql.FieldContext{+ Object: "UserPrompt",+ Field: field,+ IsMethod: false,+ IsResolver: false,+ Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {+ return nil, errors.New("field of type PromptType does not have child fields")+ },+ }+ return fc, nil+}++func (ec *executionContext) _UserPrompt_template(ctx context.Context, field graphql.CollectedField, obj *model.UserPrompt) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_UserPrompt_template(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.Template, 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_UserPrompt_template(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+ fc = &graphql.FieldContext{+ Object: "UserPrompt",+ 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) _UserPrompt_createdAt(ctx context.Context, field graphql.CollectedField, obj *model.UserPrompt) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_UserPrompt_createdAt(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.CreatedAt, 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_UserPrompt_createdAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+ fc = &graphql.FieldContext{+ Object: "UserPrompt",+ 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) _UserPrompt_updatedAt(ctx context.Context, field graphql.CollectedField, obj *model.UserPrompt) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_UserPrompt_updatedAt(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.UpdatedAt, 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_UserPrompt_updatedAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+ fc = &graphql.FieldContext{+ Object: "UserPrompt",+ 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) _UserResource_id(ctx context.Context, field graphql.CollectedField, obj *model.UserResource) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_UserResource_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.(int64)+ fc.Result = res+ return ec.marshalNID2int64(ctx, field.Selections, res)+}++func (ec *executionContext) fieldContext_UserResource_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {fc = &graphql.FieldContext{- Object: "UserPreferences",+ Object: "UserResource",Field: field,IsMethod: false,IsResolver: false,@@ -29191,8 +30075,8 @@ func (ec *executionContext) fieldContext_UserPreferences_id(_ context.Context, freturn fc, nil}-func (ec *executionContext) _UserPreferences_favoriteFlows(ctx context.Context, field graphql.CollectedField, obj *model.UserPreferences) (ret graphql.Marshaler) {- fc, err := ec.fieldContext_UserPreferences_favoriteFlows(ctx, field)+func (ec *executionContext) _UserResource_userId(ctx context.Context, field graphql.CollectedField, obj *model.UserResource) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_UserResource_userId(ctx, field)if err != nil {return graphql.Null}@@ -29205,7 +30089,7 @@ func (ec *executionContext) _UserPreferences_favoriteFlows(ctx context.Context,}()resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {ctx = rctx // use context from middleware stack in children- return obj.FavoriteFlows, nil+ return obj.UserID, nil})if err != nil {ec.Error(ctx, err)@@ -29217,14 +30101,14 @@ func (ec *executionContext) _UserPreferences_favoriteFlows(ctx context.Context,}return graphql.Null}- res := resTmp.([]int64)+ res := resTmp.(int64)fc.Result = res- return ec.marshalNID2ᚕint64ᚄ(ctx, field.Selections, res)+ return ec.marshalNID2int64(ctx, field.Selections, res)}-func (ec *executionContext) fieldContext_UserPreferences_favoriteFlows(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+func (ec *executionContext) fieldContext_UserResource_userId(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {fc = &graphql.FieldContext{- Object: "UserPreferences",+ Object: "UserResource",Field: field,IsMethod: false,IsResolver: false,@@ -29235,8 +30119,8 @@ func (ec *executionContext) fieldContext_UserPreferences_favoriteFlows(_ contextreturn fc, nil}-func (ec *executionContext) _UserPrompt_id(ctx context.Context, field graphql.CollectedField, obj *model.UserPrompt) (ret graphql.Marshaler) {- fc, err := ec.fieldContext_UserPrompt_id(ctx, field)+func (ec *executionContext) _UserResource_name(ctx context.Context, field graphql.CollectedField, obj *model.UserResource) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_UserResource_name(ctx, field)if err != nil {return graphql.Null}@@ -29249,7 +30133,7 @@ func (ec *executionContext) _UserPrompt_id(ctx context.Context, field graphql.Co}()resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {ctx = rctx // use context from middleware stack in children- return obj.ID, nil+ return obj.Name, nil})if err != nil {ec.Error(ctx, err)@@ -29261,26 +30145,26 @@ func (ec *executionContext) _UserPrompt_id(ctx context.Context, field graphql.Co}return graphql.Null}- res := resTmp.(int64)+ res := resTmp.(string)fc.Result = res- return ec.marshalNID2int64(ctx, field.Selections, res)+ return ec.marshalNString2string(ctx, field.Selections, res)}-func (ec *executionContext) fieldContext_UserPrompt_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+func (ec *executionContext) fieldContext_UserResource_name(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {fc = &graphql.FieldContext{- Object: "UserPrompt",+ Object: "UserResource",Field: field,IsMethod: false,IsResolver: false,Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {- return nil, errors.New("field of type ID does not have child fields")+ return nil, errors.New("field of type String does not have child fields")},}return fc, nil}-func (ec *executionContext) _UserPrompt_type(ctx context.Context, field graphql.CollectedField, obj *model.UserPrompt) (ret graphql.Marshaler) {- fc, err := ec.fieldContext_UserPrompt_type(ctx, field)+func (ec *executionContext) _UserResource_path(ctx context.Context, field graphql.CollectedField, obj *model.UserResource) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_UserResource_path(ctx, field)if err != nil {return graphql.Null}@@ -29293,7 +30177,7 @@ func (ec *executionContext) _UserPrompt_type(ctx context.Context, field graphql.}()resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {ctx = rctx // use context from middleware stack in children- return obj.Type, nil+ return obj.Path, nil})if err != nil {ec.Error(ctx, err)@@ -29305,26 +30189,26 @@ func (ec *executionContext) _UserPrompt_type(ctx context.Context, field graphql.}return graphql.Null}- res := resTmp.(model.PromptType)+ res := resTmp.(string)fc.Result = res- return ec.marshalNPromptType2pentagiᚋpkgᚋgraphᚋmodelᚐPromptType(ctx, field.Selections, res)+ return ec.marshalNString2string(ctx, field.Selections, res)}-func (ec *executionContext) fieldContext_UserPrompt_type(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+func (ec *executionContext) fieldContext_UserResource_path(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {fc = &graphql.FieldContext{- Object: "UserPrompt",+ Object: "UserResource",Field: field,IsMethod: false,IsResolver: false,Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {- return nil, errors.New("field of type PromptType does not have child fields")+ return nil, errors.New("field of type String does not have child fields")},}return fc, nil}-func (ec *executionContext) _UserPrompt_template(ctx context.Context, field graphql.CollectedField, obj *model.UserPrompt) (ret graphql.Marshaler) {- fc, err := ec.fieldContext_UserPrompt_template(ctx, field)+func (ec *executionContext) _UserResource_size(ctx context.Context, field graphql.CollectedField, obj *model.UserResource) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_UserResource_size(ctx, field)if err != nil {return graphql.Null}@@ -29337,7 +30221,7 @@ func (ec *executionContext) _UserPrompt_template(ctx context.Context, field grap}()resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {ctx = rctx // use context from middleware stack in children- return obj.Template, nil+ return obj.Size, nil})if err != nil {ec.Error(ctx, err)@@ -29349,26 +30233,70 @@ func (ec *executionContext) _UserPrompt_template(ctx context.Context, field grap}return graphql.Null}- res := resTmp.(string)+ res := resTmp.(int)fc.Result = res- return ec.marshalNString2string(ctx, field.Selections, res)+ return ec.marshalNInt2int(ctx, field.Selections, res)}-func (ec *executionContext) fieldContext_UserPrompt_template(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+func (ec *executionContext) fieldContext_UserResource_size(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {fc = &graphql.FieldContext{- Object: "UserPrompt",+ Object: "UserResource",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 nil, errors.New("field of type Int does not have child fields")},}return fc, nil}-func (ec *executionContext) _UserPrompt_createdAt(ctx context.Context, field graphql.CollectedField, obj *model.UserPrompt) (ret graphql.Marshaler) {- fc, err := ec.fieldContext_UserPrompt_createdAt(ctx, field)+func (ec *executionContext) _UserResource_isDir(ctx context.Context, field graphql.CollectedField, obj *model.UserResource) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_UserResource_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_UserResource_isDir(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+ fc = &graphql.FieldContext{+ Object: "UserResource",+ 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) _UserResource_createdAt(ctx context.Context, field graphql.CollectedField, obj *model.UserResource) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_UserResource_createdAt(ctx, field)if err != nil {return graphql.Null}@@ -29398,9 +30326,9 @@ func (ec *executionContext) _UserPrompt_createdAt(ctx context.Context, field grareturn ec.marshalNTime2timeᚐTime(ctx, field.Selections, res)}-func (ec *executionContext) fieldContext_UserPrompt_createdAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+func (ec *executionContext) fieldContext_UserResource_createdAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {fc = &graphql.FieldContext{- Object: "UserPrompt",+ Object: "UserResource",Field: field,IsMethod: false,IsResolver: false,@@ -29411,8 +30339,8 @@ func (ec *executionContext) fieldContext_UserPrompt_createdAt(_ context.Context,return fc, nil}-func (ec *executionContext) _UserPrompt_updatedAt(ctx context.Context, field graphql.CollectedField, obj *model.UserPrompt) (ret graphql.Marshaler) {- fc, err := ec.fieldContext_UserPrompt_updatedAt(ctx, field)+func (ec *executionContext) _UserResource_updatedAt(ctx context.Context, field graphql.CollectedField, obj *model.UserResource) (ret graphql.Marshaler) {+ fc, err := ec.fieldContext_UserResource_updatedAt(ctx, field)if err != nil {return graphql.Null}@@ -29442,9 +30370,9 @@ func (ec *executionContext) _UserPrompt_updatedAt(ctx context.Context, field grareturn ec.marshalNTime2timeᚐTime(ctx, field.Selections, res)}-func (ec *executionContext) fieldContext_UserPrompt_updatedAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {+func (ec *executionContext) fieldContext_UserResource_updatedAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {fc = &graphql.FieldContext{- Object: "UserPrompt",+ Object: "UserResource",Field: field,IsMethod: false,IsResolver: false,@@ -35581,6 +36509,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 "resources":+ 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_resources(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 "__type":out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) {@@ -35919,6 +36869,12 @@ func (ec *executionContext) _Subscription(ctx context.Context, sel ast.Selectionreturn ec._Subscription_flowTemplateUpdated(ctx, fields[0])case "flowTemplateDeleted":return ec._Subscription_flowTemplateDeleted(ctx, fields[0])+ case "resourceAdded":+ return ec._Subscription_resourceAdded(ctx, fields[0])+ case "resourceUpdated":+ return ec._Subscription_resourceUpdated(ctx, fields[0])+ case "resourceDeleted":+ return ec._Subscription_resourceDeleted(ctx, fields[0])default:panic("unknown field " + strconv.Quote(fields[0].Name))}@@ -36687,6 +37643,80 @@ func (ec *executionContext) _UserPrompt(ctx context.Context, sel ast.SelectionSereturn out}+var userResourceImplementors = []string{"UserResource"}++func (ec *executionContext) _UserResource(ctx context.Context, sel ast.SelectionSet, obj *model.UserResource) graphql.Marshaler {+ fields := graphql.CollectFields(ec.OperationContext, sel, userResourceImplementors)++ 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("UserResource")+ case "id":+ out.Values[i] = ec._UserResource_id(ctx, field, obj)+ if out.Values[i] == graphql.Null {+ out.Invalids+++ }+ case "userId":+ out.Values[i] = ec._UserResource_userId(ctx, field, obj)+ if out.Values[i] == graphql.Null {+ out.Invalids+++ }+ case "name":+ out.Values[i] = ec._UserResource_name(ctx, field, obj)+ if out.Values[i] == graphql.Null {+ out.Invalids+++ }+ case "path":+ out.Values[i] = ec._UserResource_path(ctx, field, obj)+ if out.Values[i] == graphql.Null {+ out.Invalids+++ }+ case "size":+ out.Values[i] = ec._UserResource_size(ctx, field, obj)+ if out.Values[i] == graphql.Null {+ out.Invalids+++ }+ case "isDir":+ out.Values[i] = ec._UserResource_isDir(ctx, field, obj)+ if out.Values[i] == graphql.Null {+ out.Invalids+++ }+ case "createdAt":+ out.Values[i] = ec._UserResource_createdAt(ctx, field, obj)+ if out.Values[i] == graphql.Null {+ out.Invalids+++ }+ case "updatedAt":+ out.Values[i] = ec._UserResource_updatedAt(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 vectorStoreLogImplementors = []string{"VectorStoreLog"}func (ec *executionContext) _VectorStoreLog(ctx context.Context, sel ast.SelectionSet, obj *model.VectorStoreLog) graphql.Marshaler {@@ -38862,6 +39892,64 @@ func (ec *executionContext) marshalNUserPrompt2ᚖpentagiᚋpkgᚋgraphᚋmodelreturn ec._UserPrompt(ctx, sel, v)}+func (ec *executionContext) marshalNUserResource2pentagiᚋpkgᚋgraphᚋmodelᚐUserResource(ctx context.Context, sel ast.SelectionSet, v model.UserResource) graphql.Marshaler {+ return ec._UserResource(ctx, sel, &v)+}++func (ec *executionContext) marshalNUserResource2ᚕᚖpentagiᚋpkgᚋgraphᚋmodelᚐUserResourceᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.UserResource) 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.marshalNUserResource2ᚖpentagiᚋpkgᚋgraphᚋmodelᚐUserResource(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) marshalNUserResource2ᚖpentagiᚋpkgᚋgraphᚋmodelᚐUserResource(ctx context.Context, sel ast.SelectionSet, v *model.UserResource) 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._UserResource(ctx, sel, v)+}+func (ec *executionContext) unmarshalNVectorStoreAction2pentagiᚋpkgᚋgraphᚋmodelᚐVectorStoreAction(ctx context.Context, v interface{}) (model.VectorStoreAction, error) {var res model.VectorStoreActionerr := res.UnmarshalGQL(v)@@ -39383,6 +40471,44 @@ func (ec *executionContext) marshalOFlowTemplate2ᚖpentagiᚋpkgᚋgraphᚋmodereturn ec._FlowTemplate(ctx, sel, v)}+func (ec *executionContext) unmarshalOID2ᚕint64ᚄ(ctx context.Context, v interface{}) ([]int64, error) {+ if v == nil {+ return nil, nil+ }+ var vSlice []interface{}+ if v != nil {+ vSlice = graphql.CoerceList(v)+ }+ var err error+ res := make([]int64, len(vSlice))+ for i := range vSlice {+ ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i))+ res[i], err = ec.unmarshalNID2int64(ctx, vSlice[i])+ if err != nil {+ return nil, err+ }+ }+ return res, nil+}++func (ec *executionContext) marshalOID2ᚕint64ᚄ(ctx context.Context, sel ast.SelectionSet, v []int64) graphql.Marshaler {+ if v == nil {+ return graphql.Null+ }+ ret := make(graphql.Array, len(v))+ for i := range v {+ ret[i] = ec.marshalNID2int64(ctx, sel, v[i])+ }++ for _, e := range ret {+ if e == graphql.Null {+ return graphql.Null+ }+ }++ return ret+}+func (ec *executionContext) unmarshalOID2ᚖint64(ctx context.Context, v interface{}) (*int64, error) {if v == nil {return nil, nildiff --git a/backend/pkg/graph/model/models_gen.go b/backend/pkg/graph/model/models_gen.goindex 3a62b982..05025de4 100644--- a/backend/pkg/graph/model/models_gen.go+++ b/backend/pkg/graph/model/models_gen.go@@ -535,6 +535,17 @@ type UserPrompt struct {UpdatedAt time.Time `json:"updatedAt"`}+type UserResource struct {+ ID int64 `json:"id"`+ UserID int64 `json:"userId"`+ Name string `json:"name"`+ Path string `json:"path"`+ Size int `json:"size"`+ IsDir bool `json:"isDir"`+ CreatedAt time.Time `json:"createdAt"`+ UpdatedAt time.Time `json:"updatedAt"`+}+type VectorStoreLog struct {ID int64 `json:"id"`Initiator AgentType `json:"initiator"`diff --git a/backend/pkg/graph/schema.graphqls b/backend/pkg/graph/schema.graphqlsindex 76a5cba1..803c77f1 100644--- a/backend/pkg/graph/schema.graphqls+++ b/backend/pkg/graph/schema.graphqls@@ -347,6 +347,17 @@ type FlowFile {modifiedAt: Time!}+type UserResource {+ id: ID!+ userId: ID!+ name: String!+ path: String!+ size: Int!+ isDir: Boolean!+ createdAt: Time!+ updatedAt: Time!+}+# =================== API Tokens types ===================enum TokenStatus {@@ -870,20 +881,23 @@ type Query {# Flow Templates managementflowTemplate(templateId: ID!): FlowTemplateflowTemplates: [FlowTemplate!]!++ # User Resources management+ resources(path: String, recursive: Boolean): [UserResource!]!}type Mutation {# Flow management- createFlow(modelProvider: String!, input: String!): Flow!- putUserInput(flowId: ID!, input: String!, modelProvider: String): ResultType!+ createFlow(modelProvider: String!, input: String!, resourceIds: [ID!]): Flow!+ putUserInput(flowId: ID!, input: String!, modelProvider: String, resourceIds: [ID!]): ResultType!stopFlow(flowId: ID!): ResultType!finishFlow(flowId: ID!): ResultType!deleteFlow(flowId: ID!): ResultType!renameFlow(flowId: ID!, title: String!): ResultType!# Assistant management- createAssistant(flowId: ID!, modelProvider: String!, input: String!, useAgents: Boolean!): FlowAssistant!- callAssistant(flowId: ID!, assistantId: ID!, input: String!, useAgents: Boolean!): ResultType!+ createAssistant(flowId: ID!, modelProvider: String!, input: String!, useAgents: Boolean!, resourceIds: [ID!]): FlowAssistant!+ callAssistant(flowId: ID!, assistantId: ID!, input: String!, useAgents: Boolean!, resourceIds: [ID!]): ResultType!stopAssistant(flowId: ID!, assistantId: ID!): Assistant!deleteAssistant(flowId: ID!, assistantId: ID!): ResultType!@@ -961,4 +975,9 @@ type Subscription {flowTemplateCreated: FlowTemplate!flowTemplateUpdated: FlowTemplate!flowTemplateDeleted: FlowTemplate!++ # User resource events+ resourceAdded: UserResource!+ resourceUpdated: UserResource!+ resourceDeleted: UserResource!}diff --git a/backend/pkg/graph/schema.resolvers.go b/backend/pkg/graph/schema.resolvers.goindex fcddc491..a4321ba5 100644--- a/backend/pkg/graph/schema.resolvers.go+++ b/backend/pkg/graph/schema.resolvers.go@@ -25,16 +25,18 @@ import ("pentagi/pkg/providers/pconfig""pentagi/pkg/providers/provider""pentagi/pkg/providers/qwen"+ "pentagi/pkg/resources""pentagi/pkg/server/auth""pentagi/pkg/templates""pentagi/pkg/templates/validator"+ "strings""time""github.com/sirupsen/logrus")// CreateFlow is the resolver for the createFlow field.-func (r *mutationResolver) CreateFlow(ctx context.Context, modelProvider string, input string) (*model.Flow, error) {+func (r *mutationResolver) CreateFlow(ctx context.Context, modelProvider string, input string, resourceIds []int64) (*model.Flow, error) {uid, _, err := validatePermission(ctx, "flows.create")if err != nil {return nil, err@@ -54,6 +56,14 @@ func (r *mutationResolver) CreateFlow(ctx context.Context, modelProvider string,return nil, fmt.Errorf("user input is required")}+ var dbResources []database.UserResource+ if _, isAdmin, err := validatePermission(ctx, "resources.view"); err == nil {+ dbResources, err = validateUserResources(ctx, r.DB, uid, isAdmin, resourceIds)+ if err != nil {+ return nil, err+ }+ }+prvname := provider.ProviderName(modelProvider)prv, err := r.ProvidersCtrl.GetProvider(ctx, prvname, uid)if err != nil {@@ -61,7 +71,7 @@ func (r *mutationResolver) CreateFlow(ctx context.Context, modelProvider string,}prvtype := prv.Type()- fw, err := r.Controller.CreateFlow(ctx, uid, input, prvname, prvtype, nil)+ fw, err := r.Controller.CreateFlow(ctx, uid, input, prvname, prvtype, nil, dbResources)if err != nil {return nil, err}@@ -83,7 +93,7 @@ func (r *mutationResolver) CreateFlow(ctx context.Context, modelProvider string,}// PutUserInput is the resolver for the putUserInput field.-func (r *mutationResolver) PutUserInput(ctx context.Context, flowID int64, input string, modelProvider *string) (model.ResultType, error) {+func (r *mutationResolver) PutUserInput(ctx context.Context, flowID int64, input string, modelProvider *string, resourceIds []int64) (model.ResultType, error) {uid, err := validatePermissionWithFlowID(ctx, "flows.edit", flowID, r.DB)if err != nil {return model.ResultTypeError, err@@ -105,6 +115,14 @@ func (r *mutationResolver) PutUserInput(ctx context.Context, flowID int64, inputr.Logger.WithFields(fields).Debug("put user input")+ var dbResources []database.UserResource+ if _, isAdmin, err := validatePermission(ctx, "resources.view"); err == nil {+ dbResources, err = validateUserResources(ctx, r.DB, uid, isAdmin, resourceIds)+ if err != nil {+ return model.ResultTypeError, err+ }+ }+fw, err := r.Controller.GetFlow(ctx, flowID)if err != nil {return model.ResultTypeError, err@@ -119,7 +137,7 @@ func (r *mutationResolver) PutUserInput(ctx context.Context, flowID int64, input}}- if err := fw.PutInput(ctx, input, prv); err != nil {+ if err := fw.PutInput(ctx, input, prv, dbResources); err != nil {return model.ResultTypeError, err}@@ -245,7 +263,7 @@ func (r *mutationResolver) RenameFlow(ctx context.Context, flowID int64, title s}// CreateAssistant is the resolver for the createAssistant field.-func (r *mutationResolver) CreateAssistant(ctx context.Context, flowID int64, modelProvider string, input string, useAgents bool) (*model.FlowAssistant, error) {+func (r *mutationResolver) CreateAssistant(ctx context.Context, flowID int64, modelProvider string, input string, useAgents bool, resourceIds []int64) (*model.FlowAssistant, error) {var (err erroruid int64@@ -282,6 +300,14 @@ func (r *mutationResolver) CreateAssistant(ctx context.Context, flowID int64, moreturn nil, fmt.Errorf("user input is required")}+ var dbResources []database.UserResource+ if _, isAdmin, err := validatePermission(ctx, "resources.view"); err == nil {+ dbResources, err = validateUserResources(ctx, r.DB, uid, isAdmin, resourceIds)+ if err != nil {+ return nil, err+ }+ }+prvname := provider.ProviderName(modelProvider)prv, err := r.ProvidersCtrl.GetProvider(ctx, prvname, uid)if err != nil {@@ -289,7 +315,7 @@ func (r *mutationResolver) CreateAssistant(ctx context.Context, flowID int64, mo}prvtype := prv.Type()- aw, err := r.Controller.CreateAssistant(ctx, uid, flowID, input, useAgents, prvname, prvtype, nil)+ aw, err := r.Controller.CreateAssistant(ctx, uid, flowID, input, useAgents, prvname, prvtype, nil, dbResources)if err != nil {return nil, err}@@ -313,7 +339,7 @@ func (r *mutationResolver) CreateAssistant(ctx context.Context, flowID int64, mo}// CallAssistant is the resolver for the callAssistant field.-func (r *mutationResolver) CallAssistant(ctx context.Context, flowID int64, assistantID int64, input string, useAgents bool) (model.ResultType, error) {+func (r *mutationResolver) CallAssistant(ctx context.Context, flowID int64, assistantID int64, input string, useAgents bool, resourceIds []int64) (model.ResultType, error) {uid, err := validatePermissionWithFlowID(ctx, "assistants.edit", flowID, r.DB)if err != nil {return model.ResultTypeError, err@@ -325,6 +351,14 @@ func (r *mutationResolver) CallAssistant(ctx context.Context, flowID int64, assi"assistant": assistantID,}).Debug("call assistant")+ var dbResources []database.UserResource+ if _, isAdmin, err := validatePermission(ctx, "resources.view"); err == nil {+ dbResources, err = validateUserResources(ctx, r.DB, uid, isAdmin, resourceIds)+ if err != nil {+ return model.ResultTypeError, err+ }+ }+fw, err := r.Controller.GetFlow(ctx, flowID)if err != nil {return model.ResultTypeError, err@@ -335,7 +369,7 @@ func (r *mutationResolver) CallAssistant(ctx context.Context, flowID int64, assireturn model.ResultTypeError, err}- if err := aw.PutInput(ctx, input, useAgents); err != nil {+ if err := aw.PutInput(ctx, input, useAgents, dbResources); err != nil {return model.ResultTypeError, err}@@ -482,7 +516,7 @@ func (r *mutationResolver) CreateProvider(ctx context.Context, name string, typereturn nil, err}- r.Subscriptions.NewFlowPublisher(uid, 0).ProviderCreated(ctx, prv, cfg)+ r.Subscriptions.NewProviderPublisher(uid).ProviderCreated(ctx, prv, cfg)return converter.ConvertProvider(prv, cfg), nil}@@ -507,7 +541,7 @@ func (r *mutationResolver) UpdateProvider(ctx context.Context, providerID int64,return nil, err}- r.Subscriptions.NewFlowPublisher(uid, 0).ProviderUpdated(ctx, prv, cfg)+ r.Subscriptions.NewProviderPublisher(uid).ProviderUpdated(ctx, prv, cfg)return converter.ConvertProvider(prv, cfg), nil}@@ -534,7 +568,7 @@ func (r *mutationResolver) DeleteProvider(ctx context.Context, providerID int64)return model.ResultTypeError, err}- r.Subscriptions.NewFlowPublisher(uid, 0).ProviderDeleted(ctx, prv, &cfg)+ r.Subscriptions.NewProviderPublisher(uid).ProviderDeleted(ctx, prv, &cfg)return model.ResultTypeSuccess, nil}@@ -759,7 +793,7 @@ func (r *mutationResolver) CreateAPIToken(ctx context.Context, input model.Creatr.TokenCache.Invalidate(tokenID)r.TokenCache.InvalidateUser(uint64(uid))- r.Subscriptions.NewFlowPublisher(uid, 0).APITokenCreated(ctx, tokenWithSecret)+ r.Subscriptions.NewAPITokenPublisher(uid).APITokenCreated(ctx, tokenWithSecret)return converter.ConvertAPITokenWithSecret(tokenWithSecret), nil}@@ -829,7 +863,7 @@ func (r *mutationResolver) UpdateAPIToken(ctx context.Context, tokenID string, ir.TokenCache.InvalidateUser(uint64(uid))}- r.Subscriptions.NewFlowPublisher(uid, 0).APITokenUpdated(ctx, updatedToken)+ r.Subscriptions.NewAPITokenPublisher(uid).APITokenUpdated(ctx, updatedToken)return converter.ConvertAPIToken(updatedToken), nil}@@ -866,7 +900,7 @@ func (r *mutationResolver) DeleteAPIToken(ctx context.Context, tokenID string) (r.TokenCache.Invalidate(tokenID)r.TokenCache.InvalidateUser(uint64(uid))- r.Subscriptions.NewFlowPublisher(uid, 0).APITokenDeleted(ctx, token)+ r.Subscriptions.NewAPITokenPublisher(uid).APITokenDeleted(ctx, token)return true, nil}@@ -914,7 +948,7 @@ func (r *mutationResolver) AddFavoriteFlow(ctx context.Context, flowID int64) (mreturn model.ResultTypeError, fmt.Errorf("failed to add favorite flow: %w", err)}- r.Subscriptions.NewFlowPublisher(uid, 0).SettingsUserUpdated(ctx, prefs)+ r.Subscriptions.NewSettingsPublisher(uid).SettingsUserUpdated(ctx, prefs)return model.ResultTypeSuccess, nil}@@ -953,7 +987,7 @@ func (r *mutationResolver) DeleteFavoriteFlow(ctx context.Context, flowID int64)return model.ResultTypeError, fmt.Errorf("failed to delete favorite flow: %w", err)}- r.Subscriptions.NewFlowPublisher(uid, 0).SettingsUserUpdated(ctx, prefs)+ r.Subscriptions.NewSettingsPublisher(uid).SettingsUserUpdated(ctx, prefs)return model.ResultTypeSuccess, nil}@@ -988,7 +1022,7 @@ func (r *mutationResolver) CreateFlowTemplate(ctx context.Context, input model.Creturn nil, fmt.Errorf("failed to create template: %w", err)}- r.Subscriptions.NewFlowPublisher(uid, 0).FlowTemplateCreated(ctx, template)+ r.Subscriptions.NewFlowTemplatePublisher(uid).FlowTemplateCreated(ctx, template)return converter.ConvertFlowTemplate(template), nil}@@ -1032,7 +1066,7 @@ func (r *mutationResolver) UpdateFlowTemplate(ctx context.Context, templateID inreturn nil, fmt.Errorf("failed to update template: %w", err)}- r.Subscriptions.NewFlowPublisher(uid, 0).FlowTemplateUpdated(ctx, template)+ r.Subscriptions.NewFlowTemplatePublisher(uid).FlowTemplateUpdated(ctx, template)return converter.ConvertFlowTemplate(template), nil}@@ -1074,7 +1108,7 @@ func (r *mutationResolver) DeleteFlowTemplate(ctx context.Context, templateID inreturn model.ResultTypeError, fmt.Errorf("failed to delete template: %w", err)}- r.Subscriptions.NewFlowPublisher(uid, 0).FlowTemplateDeleted(ctx, template)+ r.Subscriptions.NewFlowTemplatePublisher(uid).FlowTemplateDeleted(ctx, template)return model.ResultTypeSuccess, nil}@@ -1227,7 +1261,7 @@ func (r *queryResolver) Tasks(ctx context.Context, flowID int64) ([]*model.Task,// 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)+ uid, err := validatePermissionWithFlowID(ctx, "flow_files.view", flowID, r.DB)if err != nil {return nil, err}@@ -2198,6 +2232,78 @@ func (r *queryResolver) FlowTemplates(ctx context.Context) ([]*model.FlowTemplatreturn converter.ConvertFlowTemplates(templates), nil}+// Resources is the resolver for the resources field.+func (r *queryResolver) Resources(ctx context.Context, path *string, recursive *bool) ([]*model.UserResource, error) {+ uid, admin, err := validatePermission(ctx, "resources.view")+ if err != nil {+ return nil, err+ }++ r.Logger.WithFields(logrus.Fields{+ "uid": uid,+ "admin": admin,+ "path": path,+ "recursive": recursive,+ }).Debug("list user resources")++ reqPath := ""+ if path != nil {+ reqPath = strings.TrimSpace(*path)+ if reqPath != "" {+ reqPath, err = resources.SanitizeResourcePath(reqPath)+ if err != nil {+ return nil, err+ }+ }+ }+ isRecursive := recursive != nil && *recursive++ var recs []database.UserResource++ if !admin {+ if reqPath == "" {+ recs, err = r.DB.GetUserResourcesRoot(ctx, uid)+ } else if isRecursive {+ escaped := resources.EscapeLike(reqPath)+ recs, err = r.DB.GetUserResourcesRecursive(ctx, database.GetUserResourcesRecursiveParams{+ UserID: uid,+ DirPath: reqPath,+ ChildPrefix: escaped + "/%",+ })+ } else {+ escaped := resources.EscapeLike(reqPath)+ recs, err = r.DB.GetUserResourcesInDir(ctx, database.GetUserResourcesInDirParams{+ UserID: uid,+ DirPath: reqPath,+ ChildPrefix: escaped + "/%",+ DeepPrefix: escaped + "/%/%",+ })+ }+ } else {+ if reqPath == "" {+ recs, err = r.DB.GetAllResourcesRoot(ctx)+ } else if isRecursive {+ escaped := resources.EscapeLike(reqPath)+ recs, err = r.DB.GetAllResourcesRecursive(ctx, database.GetAllResourcesRecursiveParams{+ DirPath: reqPath,+ ChildPrefix: escaped + "/%",+ })+ } else {+ escaped := resources.EscapeLike(reqPath)+ recs, err = r.DB.GetAllResourcesInDir(ctx, database.GetAllResourcesInDirParams{+ DirPath: reqPath,+ ChildPrefix: escaped + "/%",+ DeepPrefix: escaped + "/%/%",+ })+ }+ }+ if err != nil {+ return nil, fmt.Errorf("failed to list resources: %w", err)+ }++ return converter.ConvertUserResources(recs), nil+}+// FlowCreated is the resolver for the flowCreated field.func (r *subscriptionResolver) FlowCreated(ctx context.Context) (<-chan *model.Flow, error) {uid, admin, err := validatePermission(ctx, "flows.subscribe")@@ -2295,7 +2401,7 @@ func (r *subscriptionResolver) AssistantDeleted(ctx context.Context, flowID int6// 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)+ uid, err := validatePermissionWithFlowID(ctx, "flow_files.subscribe", flowID, r.DB)if err != nil {return nil, err}@@ -2305,7 +2411,7 @@ func (r *subscriptionResolver) FlowFileAdded(ctx context.Context, flowID int64)// 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)+ uid, err := validatePermissionWithFlowID(ctx, "flow_files.subscribe", flowID, r.DB)if err != nil {return nil, err}@@ -2315,7 +2421,7 @@ func (r *subscriptionResolver) FlowFileUpdated(ctx context.Context, flowID int64// 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)+ uid, err := validatePermissionWithFlowID(ctx, "flow_files.subscribe", flowID, r.DB)if err != nil {return nil, err}@@ -2420,7 +2526,7 @@ func (r *subscriptionResolver) ProviderCreated(ctx context.Context) (<-chan *modreturn nil, err}- return r.Subscriptions.NewFlowSubscriber(uid, 0).ProviderCreated(ctx)+ return r.Subscriptions.NewProviderSubscriber(uid).ProviderCreated(ctx)}// ProviderUpdated is the resolver for the providerUpdated field.@@ -2430,7 +2536,7 @@ func (r *subscriptionResolver) ProviderUpdated(ctx context.Context) (<-chan *modreturn nil, err}- return r.Subscriptions.NewFlowSubscriber(uid, 0).ProviderUpdated(ctx)+ return r.Subscriptions.NewProviderSubscriber(uid).ProviderUpdated(ctx)}// ProviderDeleted is the resolver for the providerDeleted field.@@ -2440,7 +2546,7 @@ func (r *subscriptionResolver) ProviderDeleted(ctx context.Context) (<-chan *modreturn nil, err}- return r.Subscriptions.NewFlowSubscriber(uid, 0).ProviderDeleted(ctx)+ return r.Subscriptions.NewProviderSubscriber(uid).ProviderDeleted(ctx)}// APITokenCreated is the resolver for the apiTokenCreated field.@@ -2459,7 +2565,7 @@ func (r *subscriptionResolver) APITokenCreated(ctx context.Context) (<-chan *modreturn nil, fmt.Errorf("unauthorized: non-user session is not allowed to subscribe to API tokens")}- return r.Subscriptions.NewFlowSubscriber(uid, 0).APITokenCreated(ctx)+ return r.Subscriptions.NewAPITokenSubscriber(uid).APITokenCreated(ctx)}// APITokenUpdated is the resolver for the apiTokenUpdated field.@@ -2478,7 +2584,7 @@ func (r *subscriptionResolver) APITokenUpdated(ctx context.Context) (<-chan *modreturn nil, fmt.Errorf("unauthorized: non-user session is not allowed to subscribe to API tokens")}- return r.Subscriptions.NewFlowSubscriber(uid, 0).APITokenUpdated(ctx)+ return r.Subscriptions.NewAPITokenSubscriber(uid).APITokenUpdated(ctx)}// APITokenDeleted is the resolver for the apiTokenDeleted field.@@ -2497,7 +2603,7 @@ func (r *subscriptionResolver) APITokenDeleted(ctx context.Context) (<-chan *modreturn nil, fmt.Errorf("unauthorized: non-user session is not allowed to subscribe to API tokens")}- return r.Subscriptions.NewFlowSubscriber(uid, 0).APITokenDeleted(ctx)+ return r.Subscriptions.NewAPITokenSubscriber(uid).APITokenDeleted(ctx)}// SettingsUserUpdated is the resolver for the settingsUserUpdated field.@@ -2516,7 +2622,7 @@ func (r *subscriptionResolver) SettingsUserUpdated(ctx context.Context) (<-chanreturn nil, fmt.Errorf("unauthorized: non-user session is not allowed to subscribe to user preferences")}- return r.Subscriptions.NewFlowSubscriber(uid, 0).SettingsUserUpdated(ctx)+ return r.Subscriptions.NewSettingsSubscriber(uid).SettingsUserUpdated(ctx)}// FlowTemplateCreated is the resolver for the flowTemplateCreated field.@@ -2535,7 +2641,7 @@ func (r *subscriptionResolver) FlowTemplateCreated(ctx context.Context) (<-chanreturn nil, fmt.Errorf("unauthorized: non-user session is not allowed to subscribe to templates")}- return r.Subscriptions.NewFlowSubscriber(uid, 0).FlowTemplateCreated(ctx)+ return r.Subscriptions.NewFlowTemplateSubscriber(uid).FlowTemplateCreated(ctx)}// FlowTemplateUpdated is the resolver for the flowTemplateUpdated field.@@ -2554,7 +2660,7 @@ func (r *subscriptionResolver) FlowTemplateUpdated(ctx context.Context) (<-chanreturn nil, fmt.Errorf("unauthorized: non-user session is not allowed to subscribe to templates")}- return r.Subscriptions.NewFlowSubscriber(uid, 0).FlowTemplateUpdated(ctx)+ return r.Subscriptions.NewFlowTemplateSubscriber(uid).FlowTemplateUpdated(ctx)}// FlowTemplateDeleted is the resolver for the flowTemplateDeleted field.@@ -2573,7 +2679,49 @@ func (r *subscriptionResolver) FlowTemplateDeleted(ctx context.Context) (<-chanreturn nil, fmt.Errorf("unauthorized: non-user session is not allowed to subscribe to templates")}- return r.Subscriptions.NewFlowSubscriber(uid, 0).FlowTemplateDeleted(ctx)+ return r.Subscriptions.NewFlowTemplateSubscriber(uid).FlowTemplateDeleted(ctx)+}++// ResourceAdded is the resolver for the resourceAdded field.+func (r *subscriptionResolver) ResourceAdded(ctx context.Context) (<-chan *model.UserResource, error) {+ uid, admin, err := validatePermission(ctx, "resources.subscribe")+ if err != nil {+ return nil, err+ }++ sub := r.Subscriptions.NewResourceSubscriber(uid)+ if admin {+ return sub.ResourceAddedAdmin(ctx)+ }+ return sub.ResourceAdded(ctx)+}++// ResourceUpdated is the resolver for the resourceUpdated field.+func (r *subscriptionResolver) ResourceUpdated(ctx context.Context) (<-chan *model.UserResource, error) {+ uid, admin, err := validatePermission(ctx, "resources.subscribe")+ if err != nil {+ return nil, err+ }++ sub := r.Subscriptions.NewResourceSubscriber(uid)+ if admin {+ return sub.ResourceUpdatedAdmin(ctx)+ }+ return sub.ResourceUpdated(ctx)+}++// ResourceDeleted is the resolver for the resourceDeleted field.+func (r *subscriptionResolver) ResourceDeleted(ctx context.Context) (<-chan *model.UserResource, error) {+ uid, admin, err := validatePermission(ctx, "resources.subscribe")+ if err != nil {+ return nil, err+ }++ sub := r.Subscriptions.NewResourceSubscriber(uid)+ if admin {+ return sub.ResourceDeletedAdmin(ctx)+ }+ return sub.ResourceDeleted(ctx)}// Mutation returns MutationResolver implementation.diff --git a/backend/pkg/graph/subscriptions/controller.go b/backend/pkg/graph/subscriptions/controller.goindex 2aa3cc9f..fb542867 100644--- a/backend/pkg/graph/subscriptions/controller.go+++ b/backend/pkg/graph/subscriptions/controller.go@@ -18,13 +18,26 @@ const (type SubscriptionsController interface {NewFlowSubscriber(userID, flowID int64) FlowSubscriberNewFlowPublisher(userID, flowID int64) FlowPublisher+ NewResourceSubscriber(userID int64) ResourceSubscriber+ NewResourcePublisher(userID int64) ResourcePublisher+ NewProviderSubscriber(userID int64) ProviderSubscriber+ NewProviderPublisher(userID int64) ProviderPublisher+ NewAPITokenSubscriber(userID int64) APITokenSubscriber+ NewAPITokenPublisher(userID int64) APITokenPublisher+ NewSettingsSubscriber(userID int64) SettingsSubscriber+ NewSettingsPublisher(userID int64) SettingsPublisher+ NewFlowTemplateSubscriber(userID int64) FlowTemplateSubscriber+ NewFlowTemplatePublisher(userID int64) FlowTemplatePublisher+}++type UserContext interface {+ GetUserID() int64+ SetUserID(userID int64)}type FlowContext interface {GetFlowID() int64SetFlowID(flowID int64)- GetUserID() int64- SetUserID(userID int64)}type FlowSubscriber interface {@@ -51,17 +64,44 @@ type FlowSubscriber interface {VectorStoreLogAdded(ctx context.Context) (<-chan *model.VectorStoreLog, error)AssistantLogAdded(ctx context.Context) (<-chan *model.AssistantLog, error)AssistantLogUpdated(ctx context.Context) (<-chan *model.AssistantLog, error)+ FlowContext+ UserContext+}++type ProviderSubscriber interface {ProviderCreated(ctx context.Context) (<-chan *model.ProviderConfig, error)ProviderUpdated(ctx context.Context) (<-chan *model.ProviderConfig, error)ProviderDeleted(ctx context.Context) (<-chan *model.ProviderConfig, error)+ UserContext+}++type APITokenSubscriber interface {APITokenCreated(ctx context.Context) (<-chan *model.APIToken, error)APITokenUpdated(ctx context.Context) (<-chan *model.APIToken, error)APITokenDeleted(ctx context.Context) (<-chan *model.APIToken, error)+ UserContext+}++type SettingsSubscriber interface {SettingsUserUpdated(ctx context.Context) (<-chan *model.UserPreferences, error)+ UserContext+}++type FlowTemplateSubscriber interface {FlowTemplateCreated(ctx context.Context) (<-chan *model.FlowTemplate, error)FlowTemplateUpdated(ctx context.Context) (<-chan *model.FlowTemplate, error)FlowTemplateDeleted(ctx context.Context) (<-chan *model.FlowTemplate, error)- FlowContext+ UserContext+}++type ResourceSubscriber interface {+ ResourceAdded(ctx context.Context) (<-chan *model.UserResource, error)+ ResourceUpdated(ctx context.Context) (<-chan *model.UserResource, error)+ ResourceDeleted(ctx context.Context) (<-chan *model.UserResource, error)+ ResourceAddedAdmin(ctx context.Context) (<-chan *model.UserResource, error)+ ResourceUpdatedAdmin(ctx context.Context) (<-chan *model.UserResource, error)+ ResourceDeletedAdmin(ctx context.Context) (<-chan *model.UserResource, error)+ UserContext}type FlowPublisher interface {@@ -85,90 +125,126 @@ type FlowPublisher interface {VectorStoreLogAdded(ctx context.Context, vectorStoreLog database.Vecstorelog)AssistantLogAdded(ctx context.Context, assistantLog database.Assistantlog)AssistantLogUpdated(ctx context.Context, assistantLog database.Assistantlog, appendPart bool)+ FlowContext+ UserContext+}++type ProviderPublisher interface {ProviderCreated(ctx context.Context, provider database.Provider, cfg *pconfig.ProviderConfig)ProviderUpdated(ctx context.Context, provider database.Provider, cfg *pconfig.ProviderConfig)ProviderDeleted(ctx context.Context, provider database.Provider, cfg *pconfig.ProviderConfig)+ UserContext+}++type APITokenPublisher interface {APITokenCreated(ctx context.Context, apiToken database.APITokenWithSecret)APITokenUpdated(ctx context.Context, apiToken database.ApiToken)APITokenDeleted(ctx context.Context, apiToken database.ApiToken)+ UserContext+}++type SettingsPublisher interface {SettingsUserUpdated(ctx context.Context, userPreferences database.UserPreference)+ UserContext+}++type FlowTemplatePublisher interface {FlowTemplateCreated(ctx context.Context, template database.FlowTemplate)FlowTemplateUpdated(ctx context.Context, template database.FlowTemplate)FlowTemplateDeleted(ctx context.Context, template database.FlowTemplate)- FlowContext+ UserContext+}++type ResourcePublisher interface {+ ResourceAdded(ctx context.Context, resource *model.UserResource)+ ResourceUpdated(ctx context.Context, resource *model.UserResource)+ ResourceDeleted(ctx context.Context, resource *model.UserResource)+ UserContext}type controller struct {- flowCreatedAdmin Channel[*model.Flow]- flowCreated Channel[*model.Flow]- flowDeletedAdmin Channel[*model.Flow]- flowDeleted Channel[*model.Flow]- flowUpdatedAdmin Channel[*model.Flow]- flowUpdated Channel[*model.Flow]- taskCreated Channel[*model.Task]- taskUpdated Channel[*model.Task]- 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]- messageLogUpdated Channel[*model.MessageLog]- agentLogAdded Channel[*model.AgentLog]- searchLogAdded Channel[*model.SearchLog]- vecStoreLogAdded Channel[*model.VectorStoreLog]- assistantLogAdded Channel[*model.AssistantLog]- assistantLogUpdated Channel[*model.AssistantLog]- providerCreated Channel[*model.ProviderConfig]- providerUpdated Channel[*model.ProviderConfig]- providerDeleted Channel[*model.ProviderConfig]- apiTokenCreated Channel[*model.APIToken]- apiTokenUpdated Channel[*model.APIToken]- apiTokenDeleted Channel[*model.APIToken]- settingsUserUpdated Channel[*model.UserPreferences]- flowTemplateCreated Channel[*model.FlowTemplate]- flowTemplateUpdated Channel[*model.FlowTemplate]- flowTemplateDeleted Channel[*model.FlowTemplate]+ flowCreatedAdmin Channel[*model.Flow]+ flowCreated Channel[*model.Flow]+ flowDeletedAdmin Channel[*model.Flow]+ flowDeleted Channel[*model.Flow]+ flowUpdatedAdmin Channel[*model.Flow]+ flowUpdated Channel[*model.Flow]+ taskCreated Channel[*model.Task]+ taskUpdated Channel[*model.Task]+ 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]+ messageLogUpdated Channel[*model.MessageLog]+ agentLogAdded Channel[*model.AgentLog]+ searchLogAdded Channel[*model.SearchLog]+ vecStoreLogAdded Channel[*model.VectorStoreLog]+ assistantLogAdded Channel[*model.AssistantLog]+ assistantLogUpdated Channel[*model.AssistantLog]+ providerCreated Channel[*model.ProviderConfig]+ providerUpdated Channel[*model.ProviderConfig]+ providerDeleted Channel[*model.ProviderConfig]+ apiTokenCreated Channel[*model.APIToken]+ apiTokenUpdated Channel[*model.APIToken]+ apiTokenDeleted Channel[*model.APIToken]+ settingsUserUpdated Channel[*model.UserPreferences]+ flowTemplateCreated Channel[*model.FlowTemplate]+ flowTemplateUpdated Channel[*model.FlowTemplate]+ flowTemplateDeleted Channel[*model.FlowTemplate]+ resourceAdded Channel[*model.UserResource]+ resourceUpdated Channel[*model.UserResource]+ resourceDeleted Channel[*model.UserResource]+ resourceAddedAdmin Channel[*model.UserResource]+ resourceUpdatedAdmin Channel[*model.UserResource]+ resourceDeletedAdmin Channel[*model.UserResource]}func NewSubscriptionsController() SubscriptionsController {return &controller{- flowCreatedAdmin: NewChannel[*model.Flow](),- flowCreated: NewChannel[*model.Flow](),- flowDeletedAdmin: NewChannel[*model.Flow](),- flowDeleted: NewChannel[*model.Flow](),- flowUpdatedAdmin: NewChannel[*model.Flow](),- flowUpdated: NewChannel[*model.Flow](),- taskCreated: NewChannel[*model.Task](),- taskUpdated: NewChannel[*model.Task](),- 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](),- messageLogUpdated: NewChannel[*model.MessageLog](),- agentLogAdded: NewChannel[*model.AgentLog](),- searchLogAdded: NewChannel[*model.SearchLog](),- vecStoreLogAdded: NewChannel[*model.VectorStoreLog](),- assistantLogAdded: NewChannel[*model.AssistantLog](),- assistantLogUpdated: NewChannel[*model.AssistantLog](),- providerCreated: NewChannel[*model.ProviderConfig](),- providerUpdated: NewChannel[*model.ProviderConfig](),- providerDeleted: NewChannel[*model.ProviderConfig](),- apiTokenCreated: NewChannel[*model.APIToken](),- apiTokenUpdated: NewChannel[*model.APIToken](),- apiTokenDeleted: NewChannel[*model.APIToken](),- settingsUserUpdated: NewChannel[*model.UserPreferences](),- flowTemplateCreated: NewChannel[*model.FlowTemplate](),- flowTemplateUpdated: NewChannel[*model.FlowTemplate](),- flowTemplateDeleted: NewChannel[*model.FlowTemplate](),+ flowCreatedAdmin: NewChannel[*model.Flow](),+ flowCreated: NewChannel[*model.Flow](),+ flowDeletedAdmin: NewChannel[*model.Flow](),+ flowDeleted: NewChannel[*model.Flow](),+ flowUpdatedAdmin: NewChannel[*model.Flow](),+ flowUpdated: NewChannel[*model.Flow](),+ taskCreated: NewChannel[*model.Task](),+ taskUpdated: NewChannel[*model.Task](),+ 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](),+ messageLogUpdated: NewChannel[*model.MessageLog](),+ agentLogAdded: NewChannel[*model.AgentLog](),+ searchLogAdded: NewChannel[*model.SearchLog](),+ vecStoreLogAdded: NewChannel[*model.VectorStoreLog](),+ assistantLogAdded: NewChannel[*model.AssistantLog](),+ assistantLogUpdated: NewChannel[*model.AssistantLog](),+ providerCreated: NewChannel[*model.ProviderConfig](),+ providerUpdated: NewChannel[*model.ProviderConfig](),+ providerDeleted: NewChannel[*model.ProviderConfig](),+ apiTokenCreated: NewChannel[*model.APIToken](),+ apiTokenUpdated: NewChannel[*model.APIToken](),+ apiTokenDeleted: NewChannel[*model.APIToken](),+ settingsUserUpdated: NewChannel[*model.UserPreferences](),+ flowTemplateCreated: NewChannel[*model.FlowTemplate](),+ flowTemplateUpdated: NewChannel[*model.FlowTemplate](),+ flowTemplateDeleted: NewChannel[*model.FlowTemplate](),+ resourceAdded: NewChannel[*model.UserResource](),+ resourceUpdated: NewChannel[*model.UserResource](),+ resourceDeleted: NewChannel[*model.UserResource](),+ resourceAddedAdmin: NewChannel[*model.UserResource](),+ resourceUpdatedAdmin: NewChannel[*model.UserResource](),+ resourceDeletedAdmin: NewChannel[*model.UserResource](),}}@@ -188,6 +264,52 @@ func (s *controller) NewFlowSubscriber(userID, flowID int64) FlowSubscriber {}}+func (s *controller) NewResourcePublisher(userID int64) ResourcePublisher {+ return &resourcePublisher{+ userID: userID,+ ctrl: s,+ }+}++func (s *controller) NewResourceSubscriber(userID int64) ResourceSubscriber {+ return &resourceSubscriber{+ userID: userID,+ ctrl: s,+ }+}++func (s *controller) NewProviderPublisher(userID int64) ProviderPublisher {+ return &providerPublisher{userID: userID, ctrl: s}+}++func (s *controller) NewProviderSubscriber(userID int64) ProviderSubscriber {+ return &providerSubscriber{userID: userID, ctrl: s}+}++func (s *controller) NewAPITokenPublisher(userID int64) APITokenPublisher {+ return &apiTokenPublisher{userID: userID, ctrl: s}+}++func (s *controller) NewAPITokenSubscriber(userID int64) APITokenSubscriber {+ return &apiTokenSubscriber{userID: userID, ctrl: s}+}++func (s *controller) NewSettingsPublisher(userID int64) SettingsPublisher {+ return &settingsPublisher{userID: userID, ctrl: s}+}++func (s *controller) NewSettingsSubscriber(userID int64) SettingsSubscriber {+ return &settingsSubscriber{userID: userID, ctrl: s}+}++func (s *controller) NewFlowTemplatePublisher(userID int64) FlowTemplatePublisher {+ return &flowTemplatePublisher{userID: userID, ctrl: s}+}++func (s *controller) NewFlowTemplateSubscriber(userID int64) FlowTemplateSubscriber {+ return &flowTemplateSubscriber{userID: userID, ctrl: s}+}+type Channel[T any] interface {Subscribe(ctx context.Context, id int64) <-chan TPublish(ctx context.Context, id int64, data T)diff --git a/backend/pkg/graph/subscriptions/publisher.go b/backend/pkg/graph/subscriptions/publisher.goindex d9da8153..1fcfcce0 100644--- a/backend/pkg/graph/subscriptions/publisher.go+++ b/backend/pkg/graph/subscriptions/publisher.go@@ -117,42 +117,127 @@ func (p *flowPublisher) AssistantLogUpdated(ctx context.Context, assistantLog dap.ctrl.assistantLogUpdated.Publish(ctx, p.flowID, converter.ConvertAssistantLog(assistantLog, appendPart))}-func (p *flowPublisher) ProviderCreated(ctx context.Context, provider database.Provider, cfg *pconfig.ProviderConfig) {+// providerPublisher publishes user-scoped provider events.+type providerPublisher struct {+ userID int64+ ctrl *controller+}++func (p *providerPublisher) GetUserID() int64 {+ return p.userID+}++func (p *providerPublisher) SetUserID(userID int64) {+ p.userID = userID+}++func (p *providerPublisher) ProviderCreated(ctx context.Context, provider database.Provider, cfg *pconfig.ProviderConfig) {p.ctrl.providerCreated.Publish(ctx, p.userID, converter.ConvertProvider(provider, cfg))}-func (p *flowPublisher) ProviderUpdated(ctx context.Context, provider database.Provider, cfg *pconfig.ProviderConfig) {+func (p *providerPublisher) ProviderUpdated(ctx context.Context, provider database.Provider, cfg *pconfig.ProviderConfig) {p.ctrl.providerUpdated.Publish(ctx, p.userID, converter.ConvertProvider(provider, cfg))}-func (p *flowPublisher) ProviderDeleted(ctx context.Context, provider database.Provider, cfg *pconfig.ProviderConfig) {+func (p *providerPublisher) ProviderDeleted(ctx context.Context, provider database.Provider, cfg *pconfig.ProviderConfig) {p.ctrl.providerDeleted.Publish(ctx, p.userID, converter.ConvertProvider(provider, cfg))}-func (p *flowPublisher) APITokenCreated(ctx context.Context, apiToken database.APITokenWithSecret) {+// apiTokenPublisher publishes user-scoped API token events.+type apiTokenPublisher struct {+ userID int64+ ctrl *controller+}++func (p *apiTokenPublisher) GetUserID() int64 {+ return p.userID+}++func (p *apiTokenPublisher) SetUserID(userID int64) {+ p.userID = userID+}++func (p *apiTokenPublisher) APITokenCreated(ctx context.Context, apiToken database.APITokenWithSecret) {p.ctrl.apiTokenCreated.Publish(ctx, p.userID, converter.ConvertAPITokenRemoveSecret(apiToken))}-func (p *flowPublisher) APITokenUpdated(ctx context.Context, apiToken database.ApiToken) {+func (p *apiTokenPublisher) APITokenUpdated(ctx context.Context, apiToken database.ApiToken) {p.ctrl.apiTokenUpdated.Publish(ctx, p.userID, converter.ConvertAPIToken(apiToken))}-func (p *flowPublisher) APITokenDeleted(ctx context.Context, apiToken database.ApiToken) {+func (p *apiTokenPublisher) APITokenDeleted(ctx context.Context, apiToken database.ApiToken) {p.ctrl.apiTokenDeleted.Publish(ctx, p.userID, converter.ConvertAPIToken(apiToken))}-func (p *flowPublisher) SettingsUserUpdated(ctx context.Context, userPreferences database.UserPreference) {+// settingsPublisher publishes user-scoped settings events.+type settingsPublisher struct {+ userID int64+ ctrl *controller+}++func (p *settingsPublisher) GetUserID() int64 {+ return p.userID+}++func (p *settingsPublisher) SetUserID(userID int64) {+ p.userID = userID+}++func (p *settingsPublisher) SettingsUserUpdated(ctx context.Context, userPreferences database.UserPreference) {p.ctrl.settingsUserUpdated.Publish(ctx, p.userID, converter.ConvertUserPreferences(userPreferences))}-func (p *flowPublisher) FlowTemplateCreated(ctx context.Context, template database.FlowTemplate) {+// flowTemplatePublisher publishes user-scoped flow template events.+type flowTemplatePublisher struct {+ userID int64+ ctrl *controller+}++func (p *flowTemplatePublisher) GetUserID() int64 {+ return p.userID+}++func (p *flowTemplatePublisher) SetUserID(userID int64) {+ p.userID = userID+}++func (p *flowTemplatePublisher) FlowTemplateCreated(ctx context.Context, template database.FlowTemplate) {p.ctrl.flowTemplateCreated.Publish(ctx, p.userID, converter.ConvertFlowTemplate(template))}-func (p *flowPublisher) FlowTemplateUpdated(ctx context.Context, template database.FlowTemplate) {+func (p *flowTemplatePublisher) FlowTemplateUpdated(ctx context.Context, template database.FlowTemplate) {p.ctrl.flowTemplateUpdated.Publish(ctx, p.userID, converter.ConvertFlowTemplate(template))}-func (p *flowPublisher) FlowTemplateDeleted(ctx context.Context, template database.FlowTemplate) {+func (p *flowTemplatePublisher) FlowTemplateDeleted(ctx context.Context, template database.FlowTemplate) {p.ctrl.flowTemplateDeleted.Publish(ctx, p.userID, converter.ConvertFlowTemplate(template))}++// resourcePublisher publishes user-scoped resource events.+type resourcePublisher struct {+ userID int64+ ctrl *controller+}++func (p *resourcePublisher) GetUserID() int64 {+ return p.userID+}++func (p *resourcePublisher) SetUserID(userID int64) {+ p.userID = userID+}++func (p *resourcePublisher) ResourceAdded(ctx context.Context, resource *model.UserResource) {+ p.ctrl.resourceAdded.Publish(ctx, p.userID, resource)+ p.ctrl.resourceAddedAdmin.Broadcast(ctx, resource)+}++func (p *resourcePublisher) ResourceUpdated(ctx context.Context, resource *model.UserResource) {+ p.ctrl.resourceUpdated.Publish(ctx, p.userID, resource)+ p.ctrl.resourceUpdatedAdmin.Broadcast(ctx, resource)+}++func (p *resourcePublisher) ResourceDeleted(ctx context.Context, resource *model.UserResource) {+ p.ctrl.resourceDeleted.Publish(ctx, p.userID, resource)+ p.ctrl.resourceDeletedAdmin.Broadcast(ctx, resource)+}diff --git a/backend/pkg/graph/subscriptions/subscriber.go b/backend/pkg/graph/subscriptions/subscriber.goindex 50d17a50..aa4a4827 100644--- a/backend/pkg/graph/subscriptions/subscriber.go+++ b/backend/pkg/graph/subscriptions/subscriber.go@@ -120,42 +120,136 @@ func (s *flowSubscriber) AssistantLogUpdated(ctx context.Context) (<-chan *modelreturn s.ctrl.assistantLogUpdated.Subscribe(ctx, s.flowID), nil}-func (s *flowSubscriber) ProviderCreated(ctx context.Context) (<-chan *model.ProviderConfig, error) {+// providerSubscriber subscribes to user-scoped provider events.+type providerSubscriber struct {+ userID int64+ ctrl *controller+}++func (s *providerSubscriber) GetUserID() int64 {+ return s.userID+}++func (s *providerSubscriber) SetUserID(userID int64) {+ s.userID = userID+}++func (s *providerSubscriber) ProviderCreated(ctx context.Context) (<-chan *model.ProviderConfig, error) {return s.ctrl.providerCreated.Subscribe(ctx, s.userID), nil}-func (s *flowSubscriber) ProviderUpdated(ctx context.Context) (<-chan *model.ProviderConfig, error) {+func (s *providerSubscriber) ProviderUpdated(ctx context.Context) (<-chan *model.ProviderConfig, error) {return s.ctrl.providerUpdated.Subscribe(ctx, s.userID), nil}-func (s *flowSubscriber) ProviderDeleted(ctx context.Context) (<-chan *model.ProviderConfig, error) {+func (s *providerSubscriber) ProviderDeleted(ctx context.Context) (<-chan *model.ProviderConfig, error) {return s.ctrl.providerDeleted.Subscribe(ctx, s.userID), nil}-func (s *flowSubscriber) APITokenCreated(ctx context.Context) (<-chan *model.APIToken, error) {+// apiTokenSubscriber subscribes to user-scoped API token events.+type apiTokenSubscriber struct {+ userID int64+ ctrl *controller+}++func (s *apiTokenSubscriber) GetUserID() int64 {+ return s.userID+}++func (s *apiTokenSubscriber) SetUserID(userID int64) {+ s.userID = userID+}++func (s *apiTokenSubscriber) APITokenCreated(ctx context.Context) (<-chan *model.APIToken, error) {return s.ctrl.apiTokenCreated.Subscribe(ctx, s.userID), nil}-func (s *flowSubscriber) APITokenUpdated(ctx context.Context) (<-chan *model.APIToken, error) {+func (s *apiTokenSubscriber) APITokenUpdated(ctx context.Context) (<-chan *model.APIToken, error) {return s.ctrl.apiTokenUpdated.Subscribe(ctx, s.userID), nil}-func (s *flowSubscriber) APITokenDeleted(ctx context.Context) (<-chan *model.APIToken, error) {+func (s *apiTokenSubscriber) APITokenDeleted(ctx context.Context) (<-chan *model.APIToken, error) {return s.ctrl.apiTokenDeleted.Subscribe(ctx, s.userID), nil}-func (s *flowSubscriber) SettingsUserUpdated(ctx context.Context) (<-chan *model.UserPreferences, error) {+// settingsSubscriber subscribes to user-scoped settings events.+type settingsSubscriber struct {+ userID int64+ ctrl *controller+}++func (s *settingsSubscriber) GetUserID() int64 {+ return s.userID+}++func (s *settingsSubscriber) SetUserID(userID int64) {+ s.userID = userID+}++func (s *settingsSubscriber) SettingsUserUpdated(ctx context.Context) (<-chan *model.UserPreferences, error) {return s.ctrl.settingsUserUpdated.Subscribe(ctx, s.userID), nil}-func (s *flowSubscriber) FlowTemplateCreated(ctx context.Context) (<-chan *model.FlowTemplate, error) {+// flowTemplateSubscriber subscribes to user-scoped flow template events.+type flowTemplateSubscriber struct {+ userID int64+ ctrl *controller+}++func (s *flowTemplateSubscriber) GetUserID() int64 {+ return s.userID+}++func (s *flowTemplateSubscriber) SetUserID(userID int64) {+ s.userID = userID+}++func (s *flowTemplateSubscriber) FlowTemplateCreated(ctx context.Context) (<-chan *model.FlowTemplate, error) {return s.ctrl.flowTemplateCreated.Subscribe(ctx, s.userID), nil}-func (s *flowSubscriber) FlowTemplateUpdated(ctx context.Context) (<-chan *model.FlowTemplate, error) {+func (s *flowTemplateSubscriber) FlowTemplateUpdated(ctx context.Context) (<-chan *model.FlowTemplate, error) {return s.ctrl.flowTemplateUpdated.Subscribe(ctx, s.userID), nil}-func (s *flowSubscriber) FlowTemplateDeleted(ctx context.Context) (<-chan *model.FlowTemplate, error) {+func (s *flowTemplateSubscriber) FlowTemplateDeleted(ctx context.Context) (<-chan *model.FlowTemplate, error) {return s.ctrl.flowTemplateDeleted.Subscribe(ctx, s.userID), nil}++// resourceSubscriber subscribes to user-scoped resource events.+type resourceSubscriber struct {+ userID int64+ ctrl *controller+}++func (s *resourceSubscriber) GetUserID() int64 {+ return s.userID+}++func (s *resourceSubscriber) SetUserID(userID int64) {+ s.userID = userID+}++func (s *resourceSubscriber) ResourceAdded(ctx context.Context) (<-chan *model.UserResource, error) {+ return s.ctrl.resourceAdded.Subscribe(ctx, s.userID), nil+}++func (s *resourceSubscriber) ResourceUpdated(ctx context.Context) (<-chan *model.UserResource, error) {+ return s.ctrl.resourceUpdated.Subscribe(ctx, s.userID), nil+}++func (s *resourceSubscriber) ResourceDeleted(ctx context.Context) (<-chan *model.UserResource, error) {+ return s.ctrl.resourceDeleted.Subscribe(ctx, s.userID), nil+}++func (s *resourceSubscriber) ResourceAddedAdmin(ctx context.Context) (<-chan *model.UserResource, error) {+ return s.ctrl.resourceAddedAdmin.Subscribe(ctx, s.userID), nil+}++func (s *resourceSubscriber) ResourceUpdatedAdmin(ctx context.Context) (<-chan *model.UserResource, error) {+ return s.ctrl.resourceUpdatedAdmin.Subscribe(ctx, s.userID), nil+}++func (s *resourceSubscriber) ResourceDeletedAdmin(ctx context.Context) (<-chan *model.UserResource, error) {+ return s.ctrl.resourceDeletedAdmin.Subscribe(ctx, s.userID), nil+}diff --git a/backend/pkg/providers/assistant.go b/backend/pkg/providers/assistant.goindex 551a6ff3..3b64013c 100644--- a/backend/pkg/providers/assistant.go+++ b/backend/pkg/providers/assistant.go@@ -45,7 +45,8 @@ type AssistantProvider interface {type FlowWorker interface {GetTitle() stringGetStatus(ctx context.Context) (database.FlowStatus, error)- PutInput(ctx context.Context, input string, prv provider.Provider) error+ PutInput(ctx context.Context, input string, prv provider.Provider, resources []database.UserResource) error+ PutResources(ctx context.Context, resources []database.UserResource) errorStop(ctx context.Context) errorRename(ctx context.Context, title string) error}@@ -358,6 +359,7 @@ func (ap *assistantProvider) getAssistantSystemPrompt(ctx context.Context) (stri"StopFlowToolName": tools.StopFlowToolName,"SubmitFlowInputToolName": tools.SubmitFlowInputToolName,"PatchFlowSubtasksToolName": tools.PatchFlowSubtasksToolName,+ "UserFiles": ap.fp.userFilesListing(),})if err != nil {logger.WithError(err).Error("failed to get system prompt for assistant template")@@ -516,7 +518,7 @@ func (ap *assistantProvider) sendAssistantFlowInput(ctx context.Context, input sreturn fmt.Errorf("flow is not in 'waiting' state (current: %s); cannot submit input", status)}- err = ap.flowWorker.PutInput(ctx, input, nil)+ err = ap.flowWorker.PutInput(ctx, input, nil, nil)level := langfuse.ObservationLevelDefaultstatusMsg := "success"diff --git a/backend/pkg/providers/handlers.go b/backend/pkg/providers/handlers.goindex 4883e77f..bb6d2533 100644--- a/backend/pkg/providers/handlers.go+++ b/backend/pkg/providers/handlers.go@@ -93,6 +93,7 @@ func (fp *flowProvider) GetAskAdviceHandler(ctx context.Context, taskID, subtask"SummarizationToolName": cast.SummarizationToolName,"SummarizedContentPrefix": strings.ReplaceAll(csum.SummarizedContentPrefix, "\n", "\\n"),"ExecutionContext": executionContext,+ "Cwd": docker.WorkFolderPathInContainer,"Lang": fp.language,"CurrentTime": getCurrentTime(),"ToolPlaceholder": ToolPlaceholder,@@ -102,6 +103,7 @@ func (fp *flowProvider) GetAskAdviceHandler(ctx context.Context, taskID, subtask"FileToolName": tools.FileToolName,"TerminalToolName": tools.TerminalToolName,"BrowserToolName": tools.BrowserToolName,+ "UserFiles": fp.userFilesListing(),},}@@ -176,6 +178,7 @@ func (fp *flowProvider) GetAskAdviceHandler(ctx context.Context, taskID, subtask"DockerImage": fp.image,"Cwd": docker.WorkFolderPathInContainer,"ContainerPorts": fp.getContainerPortsDescription(),+ "UserFiles": fp.userFilesListing(),},}@@ -280,6 +283,7 @@ func (fp *flowProvider) GetCoderHandler(ctx context.Context, taskID, subtaskID *"Lang": fp.language,"CurrentTime": getCurrentTime(),"ToolPlaceholder": ToolPlaceholder,+ "UserFiles": fp.userFilesListing(),},}@@ -374,6 +378,7 @@ func (fp *flowProvider) GetInstallerHandler(ctx context.Context, taskID, subtask"Lang": fp.language,"CurrentTime": getCurrentTime(),"ToolPlaceholder": ToolPlaceholder,+ "UserFiles": fp.userFilesListing(),},}@@ -508,6 +513,7 @@ func (fp *flowProvider) GetMemoristHandler(ctx context.Context, taskID, subtaskI"Lang": fp.language,"CurrentTime": getCurrentTime(),"ToolPlaceholder": ToolPlaceholder,+ "UserFiles": fp.userFilesListing(),},}@@ -610,6 +616,7 @@ func (fp *flowProvider) GetPentesterHandler(ctx context.Context, taskID, subtask"Lang": fp.language,"CurrentTime": getCurrentTime(),"ToolPlaceholder": ToolPlaceholder,+ "UserFiles": fp.userFilesListing(),},}@@ -697,9 +704,11 @@ func (fp *flowProvider) GetSubtaskSearcherHandler(ctx context.Context, taskID, s"SummarizationToolName": cast.SummarizationToolName,"SummarizedContentPrefix": strings.ReplaceAll(csum.SummarizedContentPrefix, "\n", "\\n"),"ExecutionContext": executionContext,+ "Cwd": docker.WorkFolderPathInContainer,"Lang": fp.language,"CurrentTime": getCurrentTime(),"ToolPlaceholder": ToolPlaceholder,+ "UserFiles": fp.userFilesListing(),},}@@ -786,9 +795,11 @@ func (fp *flowProvider) GetTaskSearcherHandler(ctx context.Context, taskID int64"SummarizationToolName": cast.SummarizationToolName,"SummarizedContentPrefix": strings.ReplaceAll(csum.SummarizedContentPrefix, "\n", "\\n"),"ExecutionContext": executionContext,+ "Cwd": docker.WorkFolderPathInContainer,"Lang": fp.language,"CurrentTime": getCurrentTime(),"ToolPlaceholder": ToolPlaceholder,+ "UserFiles": fp.userFilesListing(),},}diff --git a/backend/pkg/providers/helpers_test.go b/backend/pkg/providers/helpers_test.goindex eb9bd40c..1b5e201a 100644--- a/backend/pkg/providers/helpers_test.go+++ b/backend/pkg/providers/helpers_test.go@@ -199,6 +199,7 @@ func cloneChain(chain []llms.MessageContent) []llms.MessageContent {func newFlowProvider() *flowProvider {return &flowProvider{mx: &sync.RWMutex{},+ dataDir: "testdata",summarizerCache: lru.NewLRU[[32]byte, string](summarizerCacheMaxSize, nil, summarizerCacheTTL),callCounter: &atomic.Int64{},maxGACallsLimit: maxGeneralAgentChainIterations,diff --git a/backend/pkg/providers/provider.go b/backend/pkg/providers/provider.goindex c18680ae..e3c7425b 100644--- a/backend/pkg/providers/provider.go+++ b/backend/pkg/providers/provider.go@@ -11,6 +11,8 @@ import ("pentagi/pkg/cast""pentagi/pkg/csum""pentagi/pkg/database"+ "pentagi/pkg/docker"+ "pentagi/pkg/flowfiles""pentagi/pkg/graphiti"obs "pentagi/pkg/observability""pentagi/pkg/observability/langfuse"@@ -133,6 +135,7 @@ type flowProvider struct {graphitiClient *graphiti.ClientflowID int64+ dataDir stringpublicIP stringdockerNetwork string@@ -224,6 +227,15 @@ func (fp *flowProvider) Title() string {return fp.title}+// userFilesListing returns the compact XML listing of user files in uploads/ and resources/+// for injection into agent system prompts. Returns empty string if no files are present.+func (fp *flowProvider) userFilesListing() string {+ if fp.dataDir == "" {+ return ""+ }+ return flowfiles.FileListingForPrompt(fp.dataDir, uint64(fp.flowID))+}+func (fp *flowProvider) SetTitle(title string) {fp.mx.Lock()defer fp.mx.Unlock()@@ -330,10 +342,12 @@ func (fp *flowProvider) GenerateSubtasks(ctx context.Context, taskID int64) ([]t"SummarizationToolName": cast.SummarizationToolName,"SummarizedContentPrefix": strings.ReplaceAll(csum.SummarizedContentPrefix, "\n", "\\n"),"DockerImage": fp.image,+ "Cwd": docker.WorkFolderPathInContainer,"Lang": fp.language,"CurrentTime": getCurrentTime(),"N": TasksNumberLimit,"ToolPlaceholder": ToolPlaceholder,+ "UserFiles": fp.userFilesListing(),},}@@ -420,10 +434,12 @@ func (fp *flowProvider) RefineSubtasks(ctx context.Context, taskID int64) ([]too"SummarizationToolName": cast.SummarizationToolName,"SummarizedContentPrefix": strings.ReplaceAll(csum.SummarizedContentPrefix, "\n", "\\n"),"DockerImage": fp.image,+ "Cwd": docker.WorkFolderPathInContainer,"Lang": fp.language,"CurrentTime": getCurrentTime(),"N": max(TasksNumberLimit-len(subtasksInfo.Completed), 0),"ToolPlaceholder": ToolPlaceholder,+ "UserFiles": fp.userFilesListing(),},}@@ -513,9 +529,11 @@ func (fp *flowProvider) GetTaskResult(ctx context.Context, taskID int64) (*tools"ReportResultToolName": tools.ReportResultToolName,"SummarizationToolName": cast.SummarizationToolName,"SummarizedContentPrefix": strings.ReplaceAll(csum.SummarizedContentPrefix, "\n", "\\n"),+ "Cwd": docker.WorkFolderPathInContainer,"Lang": fp.language,"N": 4000,"ToolPlaceholder": ToolPlaceholder,+ "UserFiles": fp.userFilesListing(),},}@@ -629,10 +647,12 @@ func (fp *flowProvider) PrepareAgentChain(ctx context.Context, taskID, subtaskID"AskUserToolName": tools.AskUserToolName,"AskUserEnabled": fp.askUser,"ExecutionContext": executionContext,+ "Cwd": docker.WorkFolderPathInContainer,"Lang": fp.language,"DockerImage": fp.image,"CurrentTime": getCurrentTime(),"ToolPlaceholder": ToolPlaceholder,+ "UserFiles": fp.userFilesListing(),})if err != nil {logger.WithError(err).Error("failed to get system prompt for primary agent template")diff --git a/backend/pkg/providers/providers.go b/backend/pkg/providers/providers.goindex 47b9cdc6..4e6e49cc 100644--- a/backend/pkg/providers/providers.go+++ b/backend/pkg/providers/providers.go@@ -454,6 +454,7 @@ func (pc *providerController) NewFlowProvider(embedder: pc.embedder,graphitiClient: pc.graphitiClient,flowID: flowID,+ dataDir: pc.cfg.DataDir,publicIP: pc.publicIP,dockerNetwork: pc.dockerNetwork,callCounter: newAtomicInt64(pc.startCallNumber.Add(deltaCallCounter)),@@ -505,6 +506,7 @@ func (pc *providerController) LoadFlowProvider(embedder: pc.embedder,graphitiClient: pc.graphitiClient,flowID: flowID,+ dataDir: pc.cfg.DataDir,publicIP: pc.publicIP,dockerNetwork: pc.dockerNetwork,callCounter: newAtomicInt64(pc.startCallNumber.Add(deltaCallCounter)),@@ -601,6 +603,7 @@ func (pc *providerController) NewAssistantProvider(embedder: pc.embedder,graphitiClient: pc.graphitiClient,flowID: flowID,+ dataDir: pc.cfg.DataDir,publicIP: pc.publicIP,dockerNetwork: pc.dockerNetwork,callCounter: newAtomicInt64(pc.startCallNumber.Add(deltaCallCounter)),@@ -655,6 +658,7 @@ func (pc *providerController) LoadAssistantProvider(embedder: pc.embedder,graphitiClient: pc.graphitiClient,flowID: flowID,+ dataDir: pc.cfg.DataDir,publicIP: pc.publicIP,dockerNetwork: pc.dockerNetwork,callCounter: newAtomicInt64(pc.startCallNumber.Add(deltaCallCounter)),diff --git a/backend/pkg/resources/resources.go b/backend/pkg/resources/resources.gonew file mode 100644index 00000000..dfa452b9--- /dev/null+++ b/backend/pkg/resources/resources.go@@ -0,0 +1,435 @@+package resources++import (+ "archive/zip"+ "crypto/md5"+ "encoding/hex"+ "fmt"+ "io"+ "io/fs"+ "os"+ "path"+ "path/filepath"+ "strings"+ "time"+)++const (+ ResourcesDirName = "resources"++ invalidBlobHashFileName = ".invalid-blob-hash.blob"++ MaxUploadFileSize = 300 * 1024 * 1024 // 300 MB+ MaxUploadFiles = 1000 // files per request+ MaxUploadTotalSize = 2 * 1024 * 1024 * 1024 // 2 GB+ MaxUploadRequestSize = MaxUploadTotalSize + 64*1024*1024+ MaxPathLength = 4096+ MaxFileNameLength = 255+)++// ResourceEntry is a file or directory record as returned by the package layer.+type ResourceEntry struct {+ Hash string+ Name string+ Path string+ Size int64+ IsDir bool+ CreatedAt time.Time+ UpdatedAt time.Time+}++// ZipEntry describes a single file to include in a ZIP archive.+type ZipEntry struct {+ // BlobPath is the absolute path to the .blob file on disk.+ BlobPath string+ // ZipPath is the relative path inside the archive (uses original name / subdirectory structure).+ ZipPath string+}++// ResourcesDir returns the absolute path to the flat blob storage directory.+func ResourcesDir(dataDir string) string {+ return filepath.Join(dataDir, ResourcesDirName)+}++// BlobPath returns the absolute path to the .blob file for a given MD5 hash.+func BlobPath(dataDir, hash string) string {+ cleanHash := strings.ToLower(strings.TrimSpace(hash))+ if !IsValidBlobHash(cleanHash) {+ return filepath.Join(ResourcesDir(dataDir), invalidBlobHashFileName)+ }+ return filepath.Join(ResourcesDir(dataDir), cleanHash+".blob")+}++// EnsureResourcesDir creates the resources storage directory if it does not exist.+func EnsureResourcesDir(dataDir string) error {+ if err := os.MkdirAll(ResourcesDir(dataDir), 0755); err != nil {+ return fmt.Errorf("failed to create resources directory: %w", err)+ }+ return nil+}++// ComputeFileMD5 reads r to EOF and returns the lowercase hex MD5 digest.+func ComputeFileMD5(r io.Reader) (string, error) {+ h := md5.New()+ if _, err := io.Copy(h, r); err != nil {+ return "", fmt.Errorf("failed to compute MD5: %w", err)+ }+ return hex.EncodeToString(h.Sum(nil)), nil+}++// IsValidBlobHash reports whether hash is a hex-encoded MD5 digest.+func IsValidBlobHash(hash string) bool {+ if len(hash) != md5.Size*2 {+ return false+ }+ for _, r := range hash {+ if (r >= '0' && r <= '9') || (r >= 'a' && r <= 'f') || (r >= 'A' && r <= 'F') {+ continue+ }+ return false+ }+ return true+}++func validateBlobHash(hash string) error {+ if !IsValidBlobHash(hash) {+ return fmt.Errorf("invalid blob hash %q", hash)+ }+ return nil+}++// BlobExists returns true if the .blob file for hash already exists on disk.+func BlobExists(dataDir, hash string) (bool, error) {+ if err := validateBlobHash(hash); err != nil {+ return false, err+ }+ _, err := os.Lstat(BlobPath(dataDir, hash))+ if err == nil {+ return true, nil+ }+ if os.IsNotExist(err) {+ return false, nil+ }+ return false, err+}++// DeleteBlob removes the .blob file for hash. It is safe to call if the file+// does not exist (returns nil in that case).+func DeleteBlob(dataDir, hash string) error {+ if err := validateBlobHash(hash); err != nil {+ return err+ }+ err := os.Remove(BlobPath(dataDir, hash))+ if err != nil && !os.IsNotExist(err) {+ return fmt.Errorf("failed to delete blob %s: %w", hash, err)+ }+ return nil+}++// SanitizeResourcePath normalises a client-supplied virtual path and ensures it+// is safe to use:+// - trims whitespace+// - converts backslashes to forward slashes+// - cleans the path (removes .., double slashes, etc.)+// - rejects absolute paths, dot-only components, and paths that exceed MaxPathLength+// - returns an error for the empty path+func SanitizeResourcePath(p string) (string, error) {+ trimmed := strings.TrimSpace(p)+ if trimmed == "" {+ return "", fmt.Errorf("path must not be empty")+ }+ if len(trimmed) > MaxPathLength {+ return "", fmt.Errorf("path exceeds maximum allowed length of %d characters", MaxPathLength)+ }++ normalized := strings.ReplaceAll(trimmed, "\\", "/")+ if strings.HasPrefix(normalized, "/") {+ return "", fmt.Errorf("path must be relative")+ }+ for _, part := range strings.Split(normalized, "/") {+ if part == ".." {+ return "", fmt.Errorf("path must not contain parent directory traversal")+ }+ }+ cleaned := path.Clean("/" + normalized)+ // Remove the leading "/" we added for Clean, making the path relative.+ rel := strings.TrimPrefix(cleaned, "/")+ if rel == "" || rel == "." {+ return "", fmt.Errorf("invalid path")+ }++ // Validate every path component.+ parts := strings.Split(rel, "/")+ for _, part := range parts {+ if err := validatePathComponent(part); err != nil {+ return "", err+ }+ }++ return rel, nil+}++// SanitizeResourceDir is like SanitizeResourcePath but also accepts an empty+// string to mean "root". It returns "" for root, or a clean relative path.+func SanitizeResourceDir(p string) (string, error) {+ if strings.TrimSpace(p) == "" {+ return "", nil+ }+ return SanitizeResourcePath(p)+}++// SanitizeResourceFileName strips path separators and validates the basename.+func SanitizeResourceFileName(fileName string) (string, error) {+ trimmed := strings.TrimSpace(fileName)+ if trimmed == "" {+ return "", fmt.Errorf("file name is required")+ }++ normalized := strings.ReplaceAll(trimmed, "\\", "/")+ cleanName := path.Base(path.Clean("/" + normalized))++ if err := validatePathComponent(cleanName); err != nil {+ return "", err+ }+ return cleanName, nil+}++// FilePath builds the virtual file path for a file named name inside dir.+// dir may be "" (root).+func FilePath(dir, name string) string {+ if dir == "" {+ return name+ }+ return dir + "/" + name+}++// ParentDir returns the parent directory of a virtual path, or "" for root.+func ParentDir(p string) string {+ parent := path.Dir(p)+ if parent == "." || parent == "/" || parent == "" {+ return ""+ }+ return parent+}++// FileName returns the final component of a virtual path.+func FileName(p string) string {+ return path.Base(p)+}++// IsChildOf returns true when candidate is a direct child of dir (not a deeper+// descendant). dir == "" means root.+func IsChildOf(candidate, dir string) bool {+ if dir == "" {+ return !strings.Contains(candidate, "/")+ }+ prefix := dir + "/"+ if !strings.HasPrefix(candidate, prefix) {+ return false+ }+ rest := candidate[len(prefix):]+ return !strings.Contains(rest, "/")+}++// PathHasPrefix returns true when p equals dir or starts with dir+"/".+// dir == "" matches everything.+func PathHasPrefix(p, dir string) bool {+ if dir == "" {+ return true+ }+ return p == dir || strings.HasPrefix(p, dir+"/")+}++// ReplacePrefixPath replaces the leading oldPrefix in p with newPrefix.+// The prefix must match exactly; the function panics if it does not.+func ReplacePrefixPath(p, oldPrefix, newPrefix string) string {+ if oldPrefix == "" {+ if newPrefix == "" {+ return p+ }+ return newPrefix + "/" + p+ }+ if p == oldPrefix {+ return newPrefix+ }+ rest := strings.TrimPrefix(p, oldPrefix+"/")+ if newPrefix == "" {+ return rest+ }+ return newPrefix + "/" + rest+}++// EscapeLike escapes special LIKE pattern characters (%, _) in s so the string+// can be safely embedded in a SQL LIKE clause.+func EscapeLike(s string) string {+ s = strings.ReplaceAll(s, `\`, `\\`)+ s = strings.ReplaceAll(s, `%`, `\%`)+ s = strings.ReplaceAll(s, `_`, `\_`)+ return s+}++// SaveToTemp writes r into a new temporary file in dir and returns the path to+// the temp file. The caller is responsible for removing the temp file on error.+func SaveToTemp(r io.Reader, dir string) (tmpPath string, hash string, size int64, err error) {+ if err := os.MkdirAll(dir, 0755); err != nil {+ return "", "", 0, fmt.Errorf("failed to create temp directory: %w", err)+ }++ tmp, err := os.CreateTemp(dir, ".resource-upload-*")+ if err != nil {+ return "", "", 0, fmt.Errorf("failed to create temp file: %w", err)+ }+ tmpPath = tmp.Name()+ defer tmp.Close()++ h := md5.New()+ mw := io.MultiWriter(tmp, h)+ written, copyErr := io.Copy(mw, r)+ if copyErr != nil {+ os.Remove(tmpPath)+ return "", "", 0, fmt.Errorf("failed to write temp file: %w", copyErr)+ }+ if err := tmp.Chmod(0644); err != nil {+ os.Remove(tmpPath)+ return "", "", 0, fmt.Errorf("failed to set temp file permissions: %w", err)+ }++ return tmpPath, hex.EncodeToString(h.Sum(nil)), written, nil+}++// CommitBlob atomically moves tmpPath to the .blob destination for hash. If+// the blob already exists (race with concurrent upload of identical file) the+// tmp file is removed and no error is returned.+func CommitBlob(dataDir, hash, tmpPath string) error {+ if err := validateBlobHash(hash); err != nil {+ return err+ }+ if err := EnsureResourcesDir(dataDir); err != nil {+ return err+ }++ dest := BlobPath(dataDir, hash)+ if _, err := os.Lstat(dest); err == nil {+ // Already exists — remove tmp and consider success.+ os.Remove(tmpPath)+ return nil+ }+ if err := os.Rename(tmpPath, dest); err != nil {+ return fmt.Errorf("failed to commit blob %s: %w", hash, err)+ }+ return nil+}++// ZipResources writes a ZIP archive to w containing all entries in files.+// Each ZipEntry maps a .blob file on disk to a path inside the archive.+func ZipResources(w io.Writer, entries []ZipEntry) error {+ zw := zip.NewWriter(w)+ defer zw.Close()++ for _, e := range entries {+ info, err := os.Lstat(e.BlobPath)+ if err != nil {+ return fmt.Errorf("failed to stat blob %s: %w", e.BlobPath, err)+ }+ if !info.Mode().IsRegular() {+ continue+ }++ header, err := zip.FileInfoHeader(info)+ if err != nil {+ return fmt.Errorf("failed to create zip header for %s: %w", e.ZipPath, err)+ }+ zipPath, err := SanitizeResourcePath(e.ZipPath)+ if err != nil {+ return fmt.Errorf("invalid zip entry path %q: %w", e.ZipPath, err)+ }+ header.Name = filepath.ToSlash(zipPath)+ header.Method = zip.Deflate++ zf, err := zw.CreateHeader(header)+ if err != nil {+ return fmt.Errorf("failed to create zip entry %s: %w", e.ZipPath, err)+ }++ f, err := os.Open(e.BlobPath)+ if err != nil {+ return fmt.Errorf("failed to open blob %s: %w", e.BlobPath, err)+ }+ _, copyErr := io.Copy(zf, f)+ f.Close()+ if copyErr != nil {+ return fmt.Errorf("failed to write zip entry %s: %w", e.ZipPath, copyErr)+ }+ }+ return nil+}++// ZipDirectory is kept for symmetry with flowfiles and wraps ZipResources by+// walking a real FS directory. In the resources service, use ZipResources+// instead since files are stored as blobs, not in a directory structure.+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() || 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)+ }+ zipPath, err := SanitizeResourcePath(filepath.ToSlash(rel))+ if err != nil {+ return fmt.Errorf("invalid zip entry path %q: %w", rel, err)+ }+ header.Name = filepath.ToSlash(zipPath)+ 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: %w", err)+ }+ _, copyErr := io.Copy(zf, f)+ f.Close()+ return copyErr+ })+}++// validatePathComponent rejects empty, dot/dotdot, overly long, or+// character-unsafe path segments. Mirrors flowfiles.validatePathComponent.+func validatePathComponent(component string) error {+ clean := strings.TrimSpace(component)+ if clean == "" || clean == "." || clean == ".." {+ return fmt.Errorf("invalid path component %q", component)+ }+ if len(clean) > MaxFileNameLength {+ return fmt.Errorf("path component %q exceeds maximum length of %d", component, MaxFileNameLength)+ }+ for _, r := range clean {+ if r < 0x20 || r == 0x7f {+ return fmt.Errorf("path component contains control characters")+ }+ switch r {+ case '/', '\\', ':', '*', '?', '"', '<', '>', '|':+ return fmt.Errorf("path component contains unsupported character %q", r)+ }+ }+ return nil+}diff --git a/backend/pkg/resources/resources_test.go b/backend/pkg/resources/resources_test.gonew file mode 100644index 00000000..1291c245--- /dev/null+++ b/backend/pkg/resources/resources_test.go@@ -0,0 +1,263 @@+package resources++import (+ "archive/zip"+ "bytes"+ "crypto/md5"+ "encoding/hex"+ "io"+ "os"+ "path/filepath"+ "strings"+ "testing"++ "github.com/stretchr/testify/assert"+ "github.com/stretchr/testify/require"+)++func TestResourceDirsAndBlobPath(t *testing.T) {+ assert.Equal(t, "/data/resources", ResourcesDir("/data"))+ assert.Equal(t, "/data/resources/900150983cd24fb0d6963f7d28e17f72.blob",+ BlobPath("/data", "900150983cd24fb0d6963f7d28e17f72"))++ invalidPath := BlobPath("/data", "../evil")+ assert.Equal(t, "/data/resources/.invalid-blob-hash.blob", invalidPath)+ assert.NotContains(t, invalidPath, "..")+}++func TestComputeFileMD5(t *testing.T) {+ got, err := ComputeFileMD5(strings.NewReader("abc"))+ require.NoError(t, err)+ assert.Equal(t, "900150983cd24fb0d6963f7d28e17f72", got)+}++func TestIsValidBlobHash(t *testing.T) {+ tests := []struct {+ name string+ hash string+ want bool+ }{+ {"lowercase md5", "900150983cd24fb0d6963f7d28e17f72", true},+ {"uppercase md5", "900150983CD24FB0D6963F7D28E17F72", true},+ {"too short", "abc", false},+ {"non hex", "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", false},+ {"path traversal", "../900150983cd24fb0d6963f7d28e17f72", false},+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ assert.Equal(t, tt.want, IsValidBlobHash(tt.hash))+ })+ }+}++func TestBlobLifecycle(t *testing.T) {+ dataDir := t.TempDir()+ hash := "900150983cd24fb0d6963f7d28e17f72"++ exists, err := BlobExists(dataDir, hash)+ require.NoError(t, err)+ assert.False(t, exists)++ tmpPath, gotHash, size, err := SaveToTemp(strings.NewReader("abc"), ResourcesDir(dataDir))+ require.NoError(t, err)+ assert.Equal(t, hash, gotHash)+ assert.Equal(t, int64(3), size)++ require.NoError(t, CommitBlob(dataDir, gotHash, tmpPath))+ exists, err = BlobExists(dataDir, hash)+ require.NoError(t, err)+ assert.True(t, exists)++ tmpPath, _, _, err = SaveToTemp(strings.NewReader("abc"), ResourcesDir(dataDir))+ require.NoError(t, err)+ require.NoError(t, CommitBlob(dataDir, hash, tmpPath))+ _, err = os.Lstat(tmpPath)+ assert.True(t, os.IsNotExist(err), "duplicate commit should remove temp file")++ require.NoError(t, DeleteBlob(dataDir, hash))+ exists, err = BlobExists(dataDir, hash)+ require.NoError(t, err)+ assert.False(t, exists)++ require.Error(t, DeleteBlob(dataDir, "../evil"))+ _, err = BlobExists(dataDir, "../evil")+ require.Error(t, err)+ require.Error(t, CommitBlob(dataDir, "../evil", filepath.Join(dataDir, "tmp")))+}++func TestSanitizeResourcePath(t *testing.T) {+ tests := []struct {+ name string+ input string+ expected string+ wantErr bool+ }{+ {"plain", "report.txt", "report.txt", false},+ {"nested", "targets/ips.txt", "targets/ips.txt", false},+ {"windows separators", `targets\ips.txt`, "targets/ips.txt", false},+ {"cleans duplicate slashes", "targets//ips.txt", "targets/ips.txt", false},+ {"trims whitespace", " targets/ips.txt ", "targets/ips.txt", false},+ {"rejects empty", " ", "", true},+ {"rejects absolute", "/etc/passwd", "", true},+ {"rejects traversal", "../etc/passwd", "", true},+ {"rejects nested traversal", "targets/../passwd", "", true},+ {"rejects control characters", "bad\nname.txt", "", true},+ {"rejects unsupported characters", `bad"name.txt`, "", true},+ {"rejects too long path", strings.Repeat("a", MaxPathLength+1), "", true},+ {"rejects too long component", strings.Repeat("a", MaxFileNameLength+1), "", true},+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ got, err := SanitizeResourcePath(tt.input)+ if tt.wantErr {+ require.Error(t, err)+ return+ }+ require.NoError(t, err)+ assert.Equal(t, tt.expected, got)+ })+ }+}++func TestSanitizeResourceDir(t *testing.T) {+ got, err := SanitizeResourceDir(" ")+ require.NoError(t, err)+ assert.Empty(t, got)++ got, err = SanitizeResourceDir(`targets\internal`)+ require.NoError(t, err)+ assert.Equal(t, "targets/internal", got)+}++func TestSanitizeResourceFileName(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},+ {"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 characters", `bad"name.txt`, "", true},+ {"rejects too long", strings.Repeat("a", MaxFileNameLength+1), "", true},+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ got, err := SanitizeResourceFileName(tt.input)+ if tt.wantErr {+ require.Error(t, err)+ return+ }+ require.NoError(t, err)+ assert.Equal(t, tt.expected, got)+ })+ }+}++func TestPathHelpers(t *testing.T) {+ assert.Equal(t, "report.txt", FilePath("", "report.txt"))+ assert.Equal(t, "docs/report.txt", FilePath("docs", "report.txt"))+ assert.Equal(t, "", ParentDir("report.txt"))+ assert.Equal(t, "docs", ParentDir("docs/report.txt"))+ assert.Equal(t, "report.txt", FileName("docs/report.txt"))++ assert.True(t, IsChildOf("report.txt", ""))+ assert.False(t, IsChildOf("docs/report.txt", ""))+ assert.True(t, IsChildOf("docs/report.txt", "docs"))+ assert.False(t, IsChildOf("docs/sub/report.txt", "docs"))++ assert.True(t, PathHasPrefix("docs", "docs"))+ assert.True(t, PathHasPrefix("docs/report.txt", "docs"))+ assert.False(t, PathHasPrefix("docs2/report.txt", "docs"))++ assert.Equal(t, "archive/docs/report.txt", ReplacePrefixPath("docs/report.txt", "docs", "archive/docs"))+ assert.Equal(t, "report.txt", ReplacePrefixPath("docs/report.txt", "docs", ""))+ assert.Equal(t, "archive/report.txt", ReplacePrefixPath("report.txt", "", "archive"))+}++func TestEscapeLike(t *testing.T) {+ assert.Equal(t, `a\%b\_c\\d`, EscapeLike(`a%b_c\d`))+}++func TestZipResources(t *testing.T) {+ dataDir := t.TempDir()+ hash := md5Hex("alpha")+ blobPath := BlobPath(dataDir, hash)+ require.NoError(t, os.MkdirAll(filepath.Dir(blobPath), 0755))+ require.NoError(t, os.WriteFile(blobPath, []byte("alpha"), 0644))++ var buf bytes.Buffer+ require.NoError(t, ZipResources(&buf, []ZipEntry{+ {BlobPath: blobPath, ZipPath: "docs/a.txt"},+ }))++ zr, err := zip.NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()))+ require.NoError(t, err)+ require.Len(t, zr.File, 1)+ assert.Equal(t, "docs/a.txt", zr.File[0].Name)+ rc, err := zr.File[0].Open()+ require.NoError(t, err)+ data, err := io.ReadAll(rc)+ rc.Close()+ require.NoError(t, err)+ assert.Equal(t, "alpha", string(data))++ var bad bytes.Buffer+ err = ZipResources(&bad, []ZipEntry{{BlobPath: blobPath, ZipPath: "../evil.txt"}})+ require.Error(t, err)+}++func TestZipResourcesSkipsNonRegularBlobs(t *testing.T) {+ dataDir := t.TempDir()+ target := BlobPath(dataDir, md5Hex("alpha"))+ require.NoError(t, os.MkdirAll(filepath.Dir(target), 0755))+ require.NoError(t, os.WriteFile(target, []byte("alpha"), 0644))+ link := filepath.Join(dataDir, "resources", "link.blob")+ if err := os.Symlink(target, link); err != nil {+ t.Skipf("symlink creation not available: %v", err)+ }++ var buf bytes.Buffer+ require.NoError(t, ZipResources(&buf, []ZipEntry{{BlobPath: link, ZipPath: "link.txt"}}))++ zr, err := zip.NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()))+ require.NoError(t, err)+ assert.Empty(t, zr.File)+}++func TestZipDirectory(t *testing.T) {+ src := t.TempDir()+ require.NoError(t, os.MkdirAll(filepath.Join(src, "sub"), 0755))+ require.NoError(t, os.WriteFile(filepath.Join(src, "sub", "a.txt"), []byte("alpha"), 0644))+ if err := os.Symlink(filepath.Join(src, "sub", "a.txt"), filepath.Join(src, "link.txt")); 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, "sub/a.txt")+ assert.NotContains(t, names, "link.txt")+}++func md5Hex(content string) string {+ sum := md5.Sum([]byte(content))+ return hex.EncodeToString(sum[:])+}diff --git a/backend/pkg/server/docs/docs.go b/backend/pkg/server/docs/docs.goindex f5dd6899..19c8beae 100644--- a/backend/pkg/server/docs/docs.go+++ b/backend/pkg/server/docs/docs.go@@ -1897,7 +1897,7 @@ const docTemplate = `{"type": "object","properties": {"data": {- "$ref": "#/definitions/services.flowFiles"+ "$ref": "#/definitions/models.FlowFiles"}}}@@ -1975,7 +1975,7 @@ const docTemplate = `{"type": "object","properties": {"data": {- "$ref": "#/definitions/services.flowFiles"+ "$ref": "#/definitions/models.FlowFiles"}}}@@ -2056,7 +2056,7 @@ const docTemplate = `{"type": "object","properties": {"data": {- "$ref": "#/definitions/services.flowFiles"+ "$ref": "#/definitions/models.FlowFiles"}}}@@ -2132,7 +2132,7 @@ const docTemplate = `{"type": "object","properties": {"data": {- "$ref": "#/definitions/services.containerFiles"+ "$ref": "#/definitions/models.ContainerFiles"}}}@@ -2265,7 +2265,7 @@ const docTemplate = `{"in": "body","required": true,"schema": {- "$ref": "#/definitions/services.pullFlowFilesRequest"+ "$ref": "#/definitions/models.PullFlowFilesRequest"}}],@@ -2281,7 +2281,7 @@ const docTemplate = `{"type": "object","properties": {"data": {- "$ref": "#/definitions/services.flowFiles"+ "$ref": "#/definitions/models.FlowFiles"}}}@@ -2321,6 +2321,184 @@ const docTemplate = `{}}},+ "/flows/{flowID}/files/resources": {+ "post": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "description": "Copies one or more user resources (identified by ID) into flow-{id}-data/resources/.\nFiles already present in the flow are skipped unless force=true, in which case they are replaced.",+ "consumes": [+ "application/json"+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "FlowFiles"+ ],+ "summary": "Copy user resources into a flow",+ "parameters": [+ {+ "minimum": 0,+ "type": "integer",+ "description": "flow id",+ "name": "flowID",+ "in": "path",+ "required": true+ },+ {+ "description": "resource IDs and force flag",+ "name": "body",+ "in": "body",+ "required": true,+ "schema": {+ "$ref": "#/definitions/models.AddResourcesRequest"+ }+ }+ ],+ "responses": {+ "200": {+ "description": "resources copied successfully",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/models.FlowFiles"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "invalid request",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "not permitted",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "flow not found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "409": {+ "description": "file already exists and force=false",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "internal error",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },+ "/flows/{flowID}/files/to-resources": {+ "post": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "description": "Reads a file from flow-{id}-data/{sourcePath}, computes MD5, stores the blob, inserts a user_resources row.",+ "consumes": [+ "application/json"+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "FlowFiles"+ ],+ "summary": "Promote a flow file to user resources",+ "parameters": [+ {+ "minimum": 0,+ "type": "integer",+ "description": "flow id",+ "name": "flowID",+ "in": "path",+ "required": true+ },+ {+ "description": "source path, destination and force flag",+ "name": "body",+ "in": "body",+ "required": true,+ "schema": {+ "$ref": "#/definitions/models.AddResourceFromFlowRequest"+ }+ }+ ],+ "responses": {+ "200": {+ "description": "resource created or updated",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/models.ResourceEntry"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "invalid request",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "not permitted",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "source file or flow not found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "409": {+ "description": "destination already exists and force=false",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "internal error",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },"/flows/{flowID}/graph": {"get": {"security": [@@ -4501,79 +4679,37 @@ const docTemplate = `{}}},- "/roles/": {+ "/resources/": {"get": {+ "security": [+ {+ "BearerAuth": []+ }+ ],"produces": ["application/json"],"tags": [- "Roles"+ "Resources"],- "summary": "Retrieve roles list",+ "summary": "List user resources","parameters": [- {- "type": "array",- "items": {- "type": "string"- },- "collectionFormat": "multi",- "description": "Filtering result on server e.g. {\"value\":[...],\"field\":\"...\",\"operator\":\"...\"}\n field is the unique identifier of the table column, different for each endpoint\n value should be integer or string or array type, \"value\":123 or \"value\":\"string\" or \"value\":[123,456]\n operator value should be one of \u003c,\u003c=,\u003e=,\u003e,=,!=,like,not like,in\n default operator value is 'like' or '=' if field is 'id' or '*_id' or '*_at'",- "name": "filters[]",- "in": "query"- },{"type": "string",- "description": "Field to group results by",- "name": "group",- "in": "query"- },- {- "minimum": 1,- "type": "integer",- "default": 1,- "description": "Number of page (since 1)",- "name": "page",- "in": "query",- "required": true- },- {- "maximum": 1000,- "minimum": -1,- "type": "integer",- "default": 5,- "description": "Amount items per page (min -1, max 1000, -1 means unlimited)",- "name": "pageSize",+ "description": "virtual directory path; empty for root",+ "name": "path","in": "query"},{- "type": "array",- "items": {- "type": "string"- },- "collectionFormat": "multi",- "description": "Sorting result on server e.g. {\"prop\":\"...\",\"order\":\"...\"}\n field order is \"ascending\" or \"descending\" value\n order is required if prop is not empty",- "name": "sort[]",+ "type": "boolean",+ "description": "list recursively (default false)",+ "name": "recursive","in": "query"- },- {- "enum": [- "sort",- "filter",- "init",- "page",- "size"- ],- "type": "string",- "default": "init",- "description": "Type of request",- "name": "type",- "in": "query",- "required": true}],"responses": {"200": {- "description": "roles list received successful",+ "description": "OK","schema": {"allOf": [{@@ -4583,7 +4719,7 @@ const docTemplate = `{"type": "object","properties": {"data": {- "$ref": "#/definitions/services.roles"+ "$ref": "#/definitions/models.ResourceList"}}}@@ -4591,47 +4727,59 @@ const docTemplate = `{}},"400": {- "description": "invalid query request data",+ "description": "Bad Request","schema": {"$ref": "#/definitions/ErrorResponse"}},"403": {- "description": "getting roles not permitted",+ "description": "Forbidden","schema": {"$ref": "#/definitions/ErrorResponse"}},"500": {- "description": "internal error on getting roles",+ "description": "Internal Server Error","schema": {"$ref": "#/definitions/ErrorResponse"}}}- }- },- "/roles/{roleID}": {- "get": {+ },+ "post": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "consumes": [+ "multipart/form-data"+ ],"produces": ["application/json"],"tags": [- "Roles"+ "Resources"],- "summary": "Retrieve role by id",+ "summary": "Upload files to resource storage","parameters": [{- "type": "integer",- "description": "role id",- "name": "id",- "in": "path",+ "type": "string",+ "description": "target virtual directory path; empty or omitted means root",+ "name": "dir",+ "in": "query"+ },+ {+ "type": "file",+ "description": "files to upload (field name: files or file)",+ "name": "files",+ "in": "formData","required": true}],"responses": {"200": {- "description": "role received successful",+ "description": "OK","schema": {"allOf": [{@@ -4641,7 +4789,7 @@ const docTemplate = `{"type": "object","properties": {"data": {- "$ref": "#/definitions/models.RolePrivileges"+ "$ref": "#/definitions/models.ResourceList"}}}@@ -4649,24 +4797,550 @@ const docTemplate = `{}},"400": {- "description": "invalid query request data",+ "description": "Bad Request","schema": {"$ref": "#/definitions/ErrorResponse"}},"403": {- "description": "getting role not permitted",+ "description": "Forbidden","schema": {"$ref": "#/definitions/ErrorResponse"}},- "500": {- "description": "internal error on getting role",+ "409": {+ "description": "Conflict","schema": {"$ref": "#/definitions/ErrorResponse"}- }- }+ },+ "500": {+ "description": "Internal Server Error",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ },+ "delete": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "Resources"+ ],+ "summary": "Delete a resource (file or directory)",+ "parameters": [+ {+ "type": "string",+ "description": "virtual path to delete",+ "name": "path",+ "in": "query",+ "required": true+ }+ ],+ "responses": {+ "200": {+ "description": "OK",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/models.ResourceList"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "Bad Request",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "Forbidden",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "Not Found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "Internal Server Error",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },+ "/resources/copy": {+ "post": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "consumes": [+ "application/json"+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "Resources"+ ],+ "summary": "Copy a resource (file or directory)",+ "parameters": [+ {+ "description": "copy request",+ "name": "request",+ "in": "body",+ "required": true,+ "schema": {+ "$ref": "#/definitions/models.CopyResourceRequest"+ }+ }+ ],+ "responses": {+ "200": {+ "description": "OK",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/models.ResourceList"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "Bad Request",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "Forbidden",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "Not Found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "409": {+ "description": "Conflict",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "Internal Server Error",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },+ "/resources/download": {+ "get": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "produces": [+ "application/octet-stream"+ ],+ "tags": [+ "Resources"+ ],+ "summary": "Download a resource",+ "parameters": [+ {+ "type": "string",+ "description": "virtual path to download",+ "name": "path",+ "in": "query",+ "required": true+ }+ ],+ "responses": {+ "200": {+ "description": "file content, or ZIP archive for directories",+ "schema": {+ "type": "file"+ }+ },+ "400": {+ "description": "invalid resource request data",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "downloading resource not permitted",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "resource not found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "internal error on downloading resource",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },+ "/resources/mkdir": {+ "post": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "consumes": [+ "application/json"+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "Resources"+ ],+ "summary": "Create a virtual directory",+ "parameters": [+ {+ "description": "mkdir request",+ "name": "request",+ "in": "body",+ "required": true,+ "schema": {+ "$ref": "#/definitions/models.MkdirResourceRequest"+ }+ }+ ],+ "responses": {+ "200": {+ "description": "OK",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/models.ResourceEntry"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "Bad Request",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "Forbidden",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "Internal Server Error",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },+ "/resources/move": {+ "put": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "consumes": [+ "application/json"+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "Resources"+ ],+ "summary": "Move or rename a resource (file or directory)",+ "parameters": [+ {+ "description": "move request",+ "name": "request",+ "in": "body",+ "required": true,+ "schema": {+ "$ref": "#/definitions/models.MoveResourceRequest"+ }+ }+ ],+ "responses": {+ "200": {+ "description": "OK",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/models.ResourceList"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "Bad Request",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "Forbidden",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "Not Found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "409": {+ "description": "Conflict",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "Internal Server Error",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },+ "/roles/": {+ "get": {+ "produces": [+ "application/json"+ ],+ "tags": [+ "Roles"+ ],+ "summary": "Retrieve roles list",+ "parameters": [+ {+ "type": "array",+ "items": {+ "type": "string"+ },+ "collectionFormat": "multi",+ "description": "Filtering result on server e.g. {\"value\":[...],\"field\":\"...\",\"operator\":\"...\"}\n field is the unique identifier of the table column, different for each endpoint\n value should be integer or string or array type, \"value\":123 or \"value\":\"string\" or \"value\":[123,456]\n operator value should be one of \u003c,\u003c=,\u003e=,\u003e,=,!=,like,not like,in\n default operator value is 'like' or '=' if field is 'id' or '*_id' or '*_at'",+ "name": "filters[]",+ "in": "query"+ },+ {+ "type": "string",+ "description": "Field to group results by",+ "name": "group",+ "in": "query"+ },+ {+ "minimum": 1,+ "type": "integer",+ "default": 1,+ "description": "Number of page (since 1)",+ "name": "page",+ "in": "query",+ "required": true+ },+ {+ "maximum": 1000,+ "minimum": -1,+ "type": "integer",+ "default": 5,+ "description": "Amount items per page (min -1, max 1000, -1 means unlimited)",+ "name": "pageSize",+ "in": "query"+ },+ {+ "type": "array",+ "items": {+ "type": "string"+ },+ "collectionFormat": "multi",+ "description": "Sorting result on server e.g. {\"prop\":\"...\",\"order\":\"...\"}\n field order is \"ascending\" or \"descending\" value\n order is required if prop is not empty",+ "name": "sort[]",+ "in": "query"+ },+ {+ "enum": [+ "sort",+ "filter",+ "init",+ "page",+ "size"+ ],+ "type": "string",+ "default": "init",+ "description": "Type of request",+ "name": "type",+ "in": "query",+ "required": true+ }+ ],+ "responses": {+ "200": {+ "description": "roles list received successful",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/services.roles"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "invalid query request data",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "getting roles not permitted",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "internal error on getting roles",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },+ "/roles/{roleID}": {+ "get": {+ "produces": [+ "application/json"+ ],+ "tags": [+ "Roles"+ ],+ "summary": "Retrieve role by id",+ "parameters": [+ {+ "type": "integer",+ "description": "role id",+ "name": "id",+ "in": "path",+ "required": true+ }+ ],+ "responses": {+ "200": {+ "description": "role received successful",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/models.RolePrivileges"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "invalid query request data",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "getting role not permitted",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "internal error on getting role",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }}},"/screenshots/": {@@ -6216,6 +6890,47 @@ const docTemplate = `{}}},+ "models.AddResourceFromFlowRequest": {+ "type": "object",+ "required": [+ "destination",+ "sourcePath"+ ],+ "properties": {+ "destination": {+ "description": "Destination is the virtual path the resource will have in the user's resource tree.",+ "type": "string"+ },+ "force": {+ "description": "Force overwrites an existing resource at Destination if one already exists.",+ "type": "boolean"+ },+ "sourcePath": {+ "description": "SourcePath is a relative path within the flow cache, e.g. \"container/work/result.md\" or \"uploads/task.md\".",+ "type": "string"+ }+ }+ },+ "models.AddResourcesRequest": {+ "type": "object",+ "required": [+ "ids"+ ],+ "properties": {+ "force": {+ "description": "Force overwrites files that already exist in the flow resources directory.",+ "type": "boolean"+ },+ "ids": {+ "description": "IDs is the list of user resource IDs to copy into the flow resources directory.",+ "type": "array",+ "minItems": 1,+ "items": {+ "type": "string"+ }+ }+ }+ },"models.AgentTypeUsageStats": {"type": "object","required": [@@ -6496,36 +7211,94 @@ const docTemplate = `{"type"],"properties": {- "created_at": {+ "created_at": {+ "type": "string"+ },+ "flow_id": {+ "type": "integer",+ "minimum": 0+ },+ "id": {+ "type": "integer",+ "minimum": 0+ },+ "image": {+ "type": "string"+ },+ "local_dir": {+ "type": "string"+ },+ "local_id": {+ "type": "string"+ },+ "name": {+ "type": "string"+ },+ "status": {+ "type": "string"+ },+ "type": {+ "type": "string"+ },+ "updated_at": {+ "type": "string"+ }+ }+ },+ "models.ContainerFile": {+ "type": "object",+ "properties": {+ "id": {"type": "string"},- "flow_id": {- "type": "integer",- "minimum": 0- },- "id": {- "type": "integer",- "minimum": 0+ "isDir": {+ "type": "boolean"},- "image": {+ "modifiedAt": {"type": "string"},- "local_dir": {+ "name": {"type": "string"},- "local_id": {+ "path": {"type": "string"},- "name": {- "type": "string"+ "size": {+ "type": "integer"+ }+ }+ },+ "models.ContainerFiles": {+ "type": "object",+ "properties": {+ "files": {+ "type": "array",+ "items": {+ "$ref": "#/definitions/models.ContainerFile"+ }},- "status": {+ "path": {"type": "string"},- "type": {+ "total": {+ "type": "integer"+ }+ }+ },+ "models.CopyResourceRequest": {+ "type": "object",+ "required": [+ "destination",+ "source"+ ],+ "properties": {+ "destination": {"type": "string"},- "updated_at": {+ "force": {+ "type": "boolean"+ },+ "source": {"type": "string"}}@@ -6566,6 +7339,12 @@ const docTemplate = `{"type": "string","example": "openai"},+ "resource_ids": {+ "type": "array",+ "items": {+ "type": "integer"+ }+ },"use_agents": {"type": "boolean","example": true@@ -6589,6 +7368,12 @@ const docTemplate = `{"provider": {"type": "string","example": "openai"+ },+ "resource_ids": {+ "type": "array",+ "items": {+ "type": "integer"+ }}}},@@ -6735,6 +7520,44 @@ const docTemplate = `{}}},+ "models.FlowFile": {+ "type": "object",+ "properties": {+ "id": {+ "type": "string"+ },+ "isDir": {+ "type": "boolean"+ },+ "modifiedAt": {+ "type": "string"+ },+ "name": {+ "type": "string"+ },+ "path": {+ "description": "relative: \"uploads/\u003cx\u003e\" or resources/\u003cx\u003e or container/\u003cx\u003e\"",+ "type": "string"+ },+ "size": {+ "type": "integer"+ }+ }+ },+ "models.FlowFiles": {+ "type": "object",+ "properties": {+ "files": {+ "type": "array",+ "items": {+ "$ref": "#/definitions/models.FlowFile"+ }+ },+ "total": {+ "type": "integer"+ }+ }+ },"models.FlowStats": {"type": "object","properties": {@@ -6924,6 +7747,17 @@ const docTemplate = `{}}},+ "models.MkdirResourceRequest": {+ "type": "object",+ "required": [+ "path"+ ],+ "properties": {+ "path": {+ "type": "string"+ }+ }+ },"models.ModelUsageStats": {"type": "object","required": [@@ -6943,6 +7777,24 @@ const docTemplate = `{}}},+ "models.MoveResourceRequest": {+ "type": "object",+ "required": [+ "destination",+ "source"+ ],+ "properties": {+ "destination": {+ "type": "string"+ },+ "force": {+ "type": "boolean"+ },+ "source": {+ "type": "string"+ }+ }+ },"models.Msglog": {"type": "object","required": [@@ -7027,6 +7879,12 @@ const docTemplate = `{"type": "string","example": "user input for waiting assistant"},+ "resource_ids": {+ "type": "array",+ "items": {+ "type": "integer"+ }+ },"use_agents": {"type": "boolean","example": true@@ -7059,6 +7917,12 @@ const docTemplate = `{},"provider": {"type": "string"+ },+ "resource_ids": {+ "type": "array",+ "items": {+ "type": "integer"+ }}}},@@ -7189,6 +8053,62 @@ const docTemplate = `{}}},+ "models.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"+ }+ }+ },+ "models.ResourceEntry": {+ "type": "object",+ "properties": {+ "createdAt": {+ "type": "string"+ },+ "id": {+ "type": "integer"+ },+ "isDir": {+ "type": "boolean"+ },+ "name": {+ "type": "string"+ },+ "path": {+ "type": "string"+ },+ "size": {+ "type": "integer"+ },+ "updatedAt": {+ "type": "string"+ },+ "userId": {+ "type": "integer"+ }+ }+ },+ "models.ResourceList": {+ "type": "object",+ "properties": {+ "items": {+ "type": "array",+ "items": {+ "$ref": "#/definitions/models.ResourceEntry"+ }+ },+ "total": {+ "type": "integer"+ }+ }+ },"models.Role": {"type": "object","required": [@@ -7902,46 +8822,6 @@ const docTemplate = `{}}},- "services.containerFile": {- "type": "object",- "properties": {- "id": {- "type": "string"- },- "isDir": {- "type": "boolean"- },- "modifiedAt": {- "type": "string"- },- "name": {- "type": "string"- },- "path": {- "type": "string"- },- "size": {- "type": "integer"- }- }- },- "services.containerFiles": {- "type": "object",- "properties": {- "files": {- "type": "array",- "items": {- "$ref": "#/definitions/services.containerFile"- }- },- "path": {- "type": "string"- },- "total": {- "type": "integer"- }- }- },"services.containers": {"type": "object","properties": {@@ -7956,44 +8836,6 @@ 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": {@@ -8074,19 +8916,6 @@ 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 85027226..166e75df 100644--- a/backend/pkg/server/docs/swagger.json+++ b/backend/pkg/server/docs/swagger.json@@ -1889,7 +1889,7 @@"type": "object","properties": {"data": {- "$ref": "#/definitions/services.flowFiles"+ "$ref": "#/definitions/models.FlowFiles"}}}@@ -1967,7 +1967,7 @@"type": "object","properties": {"data": {- "$ref": "#/definitions/services.flowFiles"+ "$ref": "#/definitions/models.FlowFiles"}}}@@ -2048,7 +2048,7 @@"type": "object","properties": {"data": {- "$ref": "#/definitions/services.flowFiles"+ "$ref": "#/definitions/models.FlowFiles"}}}@@ -2124,7 +2124,7 @@"type": "object","properties": {"data": {- "$ref": "#/definitions/services.containerFiles"+ "$ref": "#/definitions/models.ContainerFiles"}}}@@ -2257,7 +2257,7 @@"in": "body","required": true,"schema": {- "$ref": "#/definitions/services.pullFlowFilesRequest"+ "$ref": "#/definitions/models.PullFlowFilesRequest"}}],@@ -2273,7 +2273,7 @@"type": "object","properties": {"data": {- "$ref": "#/definitions/services.flowFiles"+ "$ref": "#/definitions/models.FlowFiles"}}}@@ -2313,6 +2313,184 @@}}},+ "/flows/{flowID}/files/resources": {+ "post": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "description": "Copies one or more user resources (identified by ID) into flow-{id}-data/resources/.\nFiles already present in the flow are skipped unless force=true, in which case they are replaced.",+ "consumes": [+ "application/json"+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "FlowFiles"+ ],+ "summary": "Copy user resources into a flow",+ "parameters": [+ {+ "minimum": 0,+ "type": "integer",+ "description": "flow id",+ "name": "flowID",+ "in": "path",+ "required": true+ },+ {+ "description": "resource IDs and force flag",+ "name": "body",+ "in": "body",+ "required": true,+ "schema": {+ "$ref": "#/definitions/models.AddResourcesRequest"+ }+ }+ ],+ "responses": {+ "200": {+ "description": "resources copied successfully",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/models.FlowFiles"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "invalid request",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "not permitted",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "flow not found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "409": {+ "description": "file already exists and force=false",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "internal error",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },+ "/flows/{flowID}/files/to-resources": {+ "post": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "description": "Reads a file from flow-{id}-data/{sourcePath}, computes MD5, stores the blob, inserts a user_resources row.",+ "consumes": [+ "application/json"+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "FlowFiles"+ ],+ "summary": "Promote a flow file to user resources",+ "parameters": [+ {+ "minimum": 0,+ "type": "integer",+ "description": "flow id",+ "name": "flowID",+ "in": "path",+ "required": true+ },+ {+ "description": "source path, destination and force flag",+ "name": "body",+ "in": "body",+ "required": true,+ "schema": {+ "$ref": "#/definitions/models.AddResourceFromFlowRequest"+ }+ }+ ],+ "responses": {+ "200": {+ "description": "resource created or updated",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/models.ResourceEntry"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "invalid request",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "not permitted",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "source file or flow not found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "409": {+ "description": "destination already exists and force=false",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "internal error",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },"/flows/{flowID}/graph": {"get": {"security": [@@ -4493,79 +4671,37 @@}}},- "/roles/": {+ "/resources/": {"get": {+ "security": [+ {+ "BearerAuth": []+ }+ ],"produces": ["application/json"],"tags": [- "Roles"+ "Resources"],- "summary": "Retrieve roles list",+ "summary": "List user resources","parameters": [- {- "type": "array",- "items": {- "type": "string"- },- "collectionFormat": "multi",- "description": "Filtering result on server e.g. {\"value\":[...],\"field\":\"...\",\"operator\":\"...\"}\n field is the unique identifier of the table column, different for each endpoint\n value should be integer or string or array type, \"value\":123 or \"value\":\"string\" or \"value\":[123,456]\n operator value should be one of \u003c,\u003c=,\u003e=,\u003e,=,!=,like,not like,in\n default operator value is 'like' or '=' if field is 'id' or '*_id' or '*_at'",- "name": "filters[]",- "in": "query"- },{"type": "string",- "description": "Field to group results by",- "name": "group",- "in": "query"- },- {- "minimum": 1,- "type": "integer",- "default": 1,- "description": "Number of page (since 1)",- "name": "page",- "in": "query",- "required": true- },- {- "maximum": 1000,- "minimum": -1,- "type": "integer",- "default": 5,- "description": "Amount items per page (min -1, max 1000, -1 means unlimited)",- "name": "pageSize",+ "description": "virtual directory path; empty for root",+ "name": "path","in": "query"},{- "type": "array",- "items": {- "type": "string"- },- "collectionFormat": "multi",- "description": "Sorting result on server e.g. {\"prop\":\"...\",\"order\":\"...\"}\n field order is \"ascending\" or \"descending\" value\n order is required if prop is not empty",- "name": "sort[]",+ "type": "boolean",+ "description": "list recursively (default false)",+ "name": "recursive","in": "query"- },- {- "enum": [- "sort",- "filter",- "init",- "page",- "size"- ],- "type": "string",- "default": "init",- "description": "Type of request",- "name": "type",- "in": "query",- "required": true}],"responses": {"200": {- "description": "roles list received successful",+ "description": "OK","schema": {"allOf": [{@@ -4575,7 +4711,7 @@"type": "object","properties": {"data": {- "$ref": "#/definitions/services.roles"+ "$ref": "#/definitions/models.ResourceList"}}}@@ -4583,47 +4719,59 @@}},"400": {- "description": "invalid query request data",+ "description": "Bad Request","schema": {"$ref": "#/definitions/ErrorResponse"}},"403": {- "description": "getting roles not permitted",+ "description": "Forbidden","schema": {"$ref": "#/definitions/ErrorResponse"}},"500": {- "description": "internal error on getting roles",+ "description": "Internal Server Error","schema": {"$ref": "#/definitions/ErrorResponse"}}}- }- },- "/roles/{roleID}": {- "get": {+ },+ "post": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "consumes": [+ "multipart/form-data"+ ],"produces": ["application/json"],"tags": [- "Roles"+ "Resources"],- "summary": "Retrieve role by id",+ "summary": "Upload files to resource storage","parameters": [{- "type": "integer",- "description": "role id",- "name": "id",- "in": "path",+ "type": "string",+ "description": "target virtual directory path; empty or omitted means root",+ "name": "dir",+ "in": "query"+ },+ {+ "type": "file",+ "description": "files to upload (field name: files or file)",+ "name": "files",+ "in": "formData","required": true}],"responses": {"200": {- "description": "role received successful",+ "description": "OK","schema": {"allOf": [{@@ -4633,7 +4781,7 @@"type": "object","properties": {"data": {- "$ref": "#/definitions/models.RolePrivileges"+ "$ref": "#/definitions/models.ResourceList"}}}@@ -4641,24 +4789,550 @@}},"400": {- "description": "invalid query request data",+ "description": "Bad Request","schema": {"$ref": "#/definitions/ErrorResponse"}},"403": {- "description": "getting role not permitted",+ "description": "Forbidden","schema": {"$ref": "#/definitions/ErrorResponse"}},- "500": {- "description": "internal error on getting role",+ "409": {+ "description": "Conflict","schema": {"$ref": "#/definitions/ErrorResponse"}- }- }+ },+ "500": {+ "description": "Internal Server Error",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ },+ "delete": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "Resources"+ ],+ "summary": "Delete a resource (file or directory)",+ "parameters": [+ {+ "type": "string",+ "description": "virtual path to delete",+ "name": "path",+ "in": "query",+ "required": true+ }+ ],+ "responses": {+ "200": {+ "description": "OK",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/models.ResourceList"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "Bad Request",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "Forbidden",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "Not Found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "Internal Server Error",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },+ "/resources/copy": {+ "post": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "consumes": [+ "application/json"+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "Resources"+ ],+ "summary": "Copy a resource (file or directory)",+ "parameters": [+ {+ "description": "copy request",+ "name": "request",+ "in": "body",+ "required": true,+ "schema": {+ "$ref": "#/definitions/models.CopyResourceRequest"+ }+ }+ ],+ "responses": {+ "200": {+ "description": "OK",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/models.ResourceList"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "Bad Request",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "Forbidden",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "Not Found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "409": {+ "description": "Conflict",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "Internal Server Error",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },+ "/resources/download": {+ "get": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "produces": [+ "application/octet-stream"+ ],+ "tags": [+ "Resources"+ ],+ "summary": "Download a resource",+ "parameters": [+ {+ "type": "string",+ "description": "virtual path to download",+ "name": "path",+ "in": "query",+ "required": true+ }+ ],+ "responses": {+ "200": {+ "description": "file content, or ZIP archive for directories",+ "schema": {+ "type": "file"+ }+ },+ "400": {+ "description": "invalid resource request data",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "downloading resource not permitted",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "resource not found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "internal error on downloading resource",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },+ "/resources/mkdir": {+ "post": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "consumes": [+ "application/json"+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "Resources"+ ],+ "summary": "Create a virtual directory",+ "parameters": [+ {+ "description": "mkdir request",+ "name": "request",+ "in": "body",+ "required": true,+ "schema": {+ "$ref": "#/definitions/models.MkdirResourceRequest"+ }+ }+ ],+ "responses": {+ "200": {+ "description": "OK",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/models.ResourceEntry"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "Bad Request",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "Forbidden",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "Internal Server Error",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },+ "/resources/move": {+ "put": {+ "security": [+ {+ "BearerAuth": []+ }+ ],+ "consumes": [+ "application/json"+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "Resources"+ ],+ "summary": "Move or rename a resource (file or directory)",+ "parameters": [+ {+ "description": "move request",+ "name": "request",+ "in": "body",+ "required": true,+ "schema": {+ "$ref": "#/definitions/models.MoveResourceRequest"+ }+ }+ ],+ "responses": {+ "200": {+ "description": "OK",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/models.ResourceList"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "Bad Request",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "Forbidden",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "404": {+ "description": "Not Found",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "409": {+ "description": "Conflict",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "Internal Server Error",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },+ "/roles/": {+ "get": {+ "produces": [+ "application/json"+ ],+ "tags": [+ "Roles"+ ],+ "summary": "Retrieve roles list",+ "parameters": [+ {+ "type": "array",+ "items": {+ "type": "string"+ },+ "collectionFormat": "multi",+ "description": "Filtering result on server e.g. {\"value\":[...],\"field\":\"...\",\"operator\":\"...\"}\n field is the unique identifier of the table column, different for each endpoint\n value should be integer or string or array type, \"value\":123 or \"value\":\"string\" or \"value\":[123,456]\n operator value should be one of \u003c,\u003c=,\u003e=,\u003e,=,!=,like,not like,in\n default operator value is 'like' or '=' if field is 'id' or '*_id' or '*_at'",+ "name": "filters[]",+ "in": "query"+ },+ {+ "type": "string",+ "description": "Field to group results by",+ "name": "group",+ "in": "query"+ },+ {+ "minimum": 1,+ "type": "integer",+ "default": 1,+ "description": "Number of page (since 1)",+ "name": "page",+ "in": "query",+ "required": true+ },+ {+ "maximum": 1000,+ "minimum": -1,+ "type": "integer",+ "default": 5,+ "description": "Amount items per page (min -1, max 1000, -1 means unlimited)",+ "name": "pageSize",+ "in": "query"+ },+ {+ "type": "array",+ "items": {+ "type": "string"+ },+ "collectionFormat": "multi",+ "description": "Sorting result on server e.g. {\"prop\":\"...\",\"order\":\"...\"}\n field order is \"ascending\" or \"descending\" value\n order is required if prop is not empty",+ "name": "sort[]",+ "in": "query"+ },+ {+ "enum": [+ "sort",+ "filter",+ "init",+ "page",+ "size"+ ],+ "type": "string",+ "default": "init",+ "description": "Type of request",+ "name": "type",+ "in": "query",+ "required": true+ }+ ],+ "responses": {+ "200": {+ "description": "roles list received successful",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/services.roles"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "invalid query request data",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "getting roles not permitted",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "internal error on getting roles",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }+ }+ },+ "/roles/{roleID}": {+ "get": {+ "produces": [+ "application/json"+ ],+ "tags": [+ "Roles"+ ],+ "summary": "Retrieve role by id",+ "parameters": [+ {+ "type": "integer",+ "description": "role id",+ "name": "id",+ "in": "path",+ "required": true+ }+ ],+ "responses": {+ "200": {+ "description": "role received successful",+ "schema": {+ "allOf": [+ {+ "$ref": "#/definitions/SuccessResponse"+ },+ {+ "type": "object",+ "properties": {+ "data": {+ "$ref": "#/definitions/models.RolePrivileges"+ }+ }+ }+ ]+ }+ },+ "400": {+ "description": "invalid query request data",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "403": {+ "description": "getting role not permitted",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ },+ "500": {+ "description": "internal error on getting role",+ "schema": {+ "$ref": "#/definitions/ErrorResponse"+ }+ }+ }}},"/screenshots/": {@@ -6208,6 +6882,47 @@}}},+ "models.AddResourceFromFlowRequest": {+ "type": "object",+ "required": [+ "destination",+ "sourcePath"+ ],+ "properties": {+ "destination": {+ "description": "Destination is the virtual path the resource will have in the user's resource tree.",+ "type": "string"+ },+ "force": {+ "description": "Force overwrites an existing resource at Destination if one already exists.",+ "type": "boolean"+ },+ "sourcePath": {+ "description": "SourcePath is a relative path within the flow cache, e.g. \"container/work/result.md\" or \"uploads/task.md\".",+ "type": "string"+ }+ }+ },+ "models.AddResourcesRequest": {+ "type": "object",+ "required": [+ "ids"+ ],+ "properties": {+ "force": {+ "description": "Force overwrites files that already exist in the flow resources directory.",+ "type": "boolean"+ },+ "ids": {+ "description": "IDs is the list of user resource IDs to copy into the flow resources directory.",+ "type": "array",+ "minItems": 1,+ "items": {+ "type": "string"+ }+ }+ }+ },"models.AgentTypeUsageStats": {"type": "object","required": [@@ -6488,36 +7203,94 @@"type"],"properties": {- "created_at": {+ "created_at": {+ "type": "string"+ },+ "flow_id": {+ "type": "integer",+ "minimum": 0+ },+ "id": {+ "type": "integer",+ "minimum": 0+ },+ "image": {+ "type": "string"+ },+ "local_dir": {+ "type": "string"+ },+ "local_id": {+ "type": "string"+ },+ "name": {+ "type": "string"+ },+ "status": {+ "type": "string"+ },+ "type": {+ "type": "string"+ },+ "updated_at": {+ "type": "string"+ }+ }+ },+ "models.ContainerFile": {+ "type": "object",+ "properties": {+ "id": {"type": "string"},- "flow_id": {- "type": "integer",- "minimum": 0- },- "id": {- "type": "integer",- "minimum": 0+ "isDir": {+ "type": "boolean"},- "image": {+ "modifiedAt": {"type": "string"},- "local_dir": {+ "name": {"type": "string"},- "local_id": {+ "path": {"type": "string"},- "name": {- "type": "string"+ "size": {+ "type": "integer"+ }+ }+ },+ "models.ContainerFiles": {+ "type": "object",+ "properties": {+ "files": {+ "type": "array",+ "items": {+ "$ref": "#/definitions/models.ContainerFile"+ }},- "status": {+ "path": {"type": "string"},- "type": {+ "total": {+ "type": "integer"+ }+ }+ },+ "models.CopyResourceRequest": {+ "type": "object",+ "required": [+ "destination",+ "source"+ ],+ "properties": {+ "destination": {"type": "string"},- "updated_at": {+ "force": {+ "type": "boolean"+ },+ "source": {"type": "string"}}@@ -6558,6 +7331,12 @@"type": "string","example": "openai"},+ "resource_ids": {+ "type": "array",+ "items": {+ "type": "integer"+ }+ },"use_agents": {"type": "boolean","example": true@@ -6581,6 +7360,12 @@"provider": {"type": "string","example": "openai"+ },+ "resource_ids": {+ "type": "array",+ "items": {+ "type": "integer"+ }}}},@@ -6727,6 +7512,44 @@}}},+ "models.FlowFile": {+ "type": "object",+ "properties": {+ "id": {+ "type": "string"+ },+ "isDir": {+ "type": "boolean"+ },+ "modifiedAt": {+ "type": "string"+ },+ "name": {+ "type": "string"+ },+ "path": {+ "description": "relative: \"uploads/\u003cx\u003e\" or resources/\u003cx\u003e or container/\u003cx\u003e\"",+ "type": "string"+ },+ "size": {+ "type": "integer"+ }+ }+ },+ "models.FlowFiles": {+ "type": "object",+ "properties": {+ "files": {+ "type": "array",+ "items": {+ "$ref": "#/definitions/models.FlowFile"+ }+ },+ "total": {+ "type": "integer"+ }+ }+ },"models.FlowStats": {"type": "object","properties": {@@ -6916,6 +7739,17 @@}}},+ "models.MkdirResourceRequest": {+ "type": "object",+ "required": [+ "path"+ ],+ "properties": {+ "path": {+ "type": "string"+ }+ }+ },"models.ModelUsageStats": {"type": "object","required": [@@ -6935,6 +7769,24 @@}}},+ "models.MoveResourceRequest": {+ "type": "object",+ "required": [+ "destination",+ "source"+ ],+ "properties": {+ "destination": {+ "type": "string"+ },+ "force": {+ "type": "boolean"+ },+ "source": {+ "type": "string"+ }+ }+ },"models.Msglog": {"type": "object","required": [@@ -7019,6 +7871,12 @@"type": "string","example": "user input for waiting assistant"},+ "resource_ids": {+ "type": "array",+ "items": {+ "type": "integer"+ }+ },"use_agents": {"type": "boolean","example": true@@ -7051,6 +7909,12 @@},"provider": {"type": "string"+ },+ "resource_ids": {+ "type": "array",+ "items": {+ "type": "integer"+ }}}},@@ -7181,6 +8045,62 @@}}},+ "models.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"+ }+ }+ },+ "models.ResourceEntry": {+ "type": "object",+ "properties": {+ "createdAt": {+ "type": "string"+ },+ "id": {+ "type": "integer"+ },+ "isDir": {+ "type": "boolean"+ },+ "name": {+ "type": "string"+ },+ "path": {+ "type": "string"+ },+ "size": {+ "type": "integer"+ },+ "updatedAt": {+ "type": "string"+ },+ "userId": {+ "type": "integer"+ }+ }+ },+ "models.ResourceList": {+ "type": "object",+ "properties": {+ "items": {+ "type": "array",+ "items": {+ "$ref": "#/definitions/models.ResourceEntry"+ }+ },+ "total": {+ "type": "integer"+ }+ }+ },"models.Role": {"type": "object","required": [@@ -7894,46 +8814,6 @@}}},- "services.containerFile": {- "type": "object",- "properties": {- "id": {- "type": "string"- },- "isDir": {- "type": "boolean"- },- "modifiedAt": {- "type": "string"- },- "name": {- "type": "string"- },- "path": {- "type": "string"- },- "size": {- "type": "integer"- }- }- },- "services.containerFiles": {- "type": "object",- "properties": {- "files": {- "type": "array",- "items": {- "$ref": "#/definitions/services.containerFile"- }- },- "path": {- "type": "string"- },- "total": {- "type": "integer"- }- }- },"services.containers": {"type": "object","properties": {@@ -7948,44 +8828,6 @@}}},- "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": {@@ -8066,19 +8908,6 @@}}},- "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 a4c69431..7f396dba 100644--- a/backend/pkg/server/docs/swagger.yaml+++ b/backend/pkg/server/docs/swagger.yaml@@ -160,6 +160,40 @@ definitions:- ttl- updated_attype: object+ models.AddResourceFromFlowRequest:+ properties:+ destination:+ description: Destination is the virtual path the resource will have in the+ user's resource tree.+ type: string+ force:+ description: Force overwrites an existing resource at Destination if one already+ exists.+ type: boolean+ sourcePath:+ description: SourcePath is a relative path within the flow cache, e.g. "container/work/result.md"+ or "uploads/task.md".+ type: string+ required:+ - destination+ - sourcePath+ type: object+ models.AddResourcesRequest:+ properties:+ force:+ description: Force overwrites files that already exist in the flow resources+ directory.+ type: boolean+ ids:+ description: IDs is the list of user resource IDs to copy into the flow resources+ directory.+ items:+ type: string+ minItems: 1+ type: array+ required:+ - ids+ type: objectmodels.AgentTypeUsageStats:properties:agent_type:@@ -386,6 +420,44 @@ definitions:- status- typetype: object+ models.ContainerFile:+ properties:+ id:+ type: string+ isDir:+ type: boolean+ modifiedAt:+ type: string+ name:+ type: string+ path:+ type: string+ size:+ type: integer+ type: object+ models.ContainerFiles:+ properties:+ files:+ items:+ $ref: '#/definitions/models.ContainerFile'+ type: array+ path:+ type: string+ total:+ type: integer+ type: object+ models.CopyResourceRequest:+ properties:+ destination:+ type: string+ force:+ type: boolean+ source:+ type: string+ required:+ - destination+ - source+ type: objectmodels.CreateAPITokenRequest:properties:name:@@ -409,6 +481,10 @@ definitions:provider:example: openaitype: string+ resource_ids:+ items:+ type: integer+ type: arrayuse_agents:example: truetype: boolean@@ -426,6 +502,10 @@ definitions:provider:example: openaitype: string+ resource_ids:+ items:+ type: integer+ type: arrayrequired:- input- provider@@ -531,6 +611,31 @@ definitions:required:- flow_titletype: object+ models.FlowFile:+ properties:+ id:+ type: string+ isDir:+ type: boolean+ modifiedAt:+ type: string+ name:+ type: string+ path:+ description: 'relative: "uploads/<x>" or resources/<x> or container/<x>"'+ type: string+ size:+ type: integer+ type: object+ models.FlowFiles:+ properties:+ files:+ items:+ $ref: '#/definitions/models.FlowFile'+ type: array+ total:+ type: integer+ type: objectmodels.FlowStats:properties:total_assistants_count:@@ -666,6 +771,13 @@ definitions:- passwordtype: object+ models.MkdirResourceRequest:+ properties:+ path:+ type: string+ required:+ - path+ type: objectmodels.ModelUsageStats:properties:model:@@ -679,6 +791,18 @@ definitions:- provider- statstype: object+ models.MoveResourceRequest:+ properties:+ destination:+ type: string+ force:+ type: boolean+ source:+ type: string+ required:+ - destination+ - source+ type: objectmodels.Msglog:properties:created_at:@@ -737,6 +861,10 @@ definitions:input:example: user input for waiting assistanttype: string+ resource_ids:+ items:+ type: integer+ type: arrayuse_agents:example: truetype: boolean@@ -761,6 +889,10 @@ definitions:type: stringprovider:type: string+ resource_ids:+ items:+ type: integer+ type: arrayrequired:- actiontype: object@@ -850,6 +982,44 @@ definitions:- provider- statstype: object+ models.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: object+ models.ResourceEntry:+ properties:+ createdAt:+ type: string+ id:+ type: integer+ isDir:+ type: boolean+ name:+ type: string+ path:+ type: string+ size:+ type: integer+ updatedAt:+ type: string+ userId:+ type: integer+ type: object+ models.ResourceList:+ properties:+ items:+ items:+ $ref: '#/definitions/models.ResourceEntry'+ type: array+ total:+ type: integer+ type: objectmodels.Role:properties:id:@@ -1351,32 +1521,6 @@ definitions:total:type: integertype: object- services.containerFile:- properties:- id:- type: string- isDir:- type: boolean- modifiedAt:- type: string- name:- type: string- path:- type: string- size:- type: integer- type: object- services.containerFiles:- properties:- files:- items:- $ref: '#/definitions/services.containerFile'- type: array- path:- type: string- total:- type: integer- type: objectservices.containers:properties:containers:@@ -1386,31 +1530,6 @@ 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:@@ -1463,16 +1582,6 @@ 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:@@ -2882,7 +2991,7 @@ paths:- $ref: '#/definitions/SuccessResponse'- properties:data:- $ref: '#/definitions/services.flowFiles'+ $ref: '#/definitions/models.FlowFiles'type: object"400":description: invalid flow file request data@@ -2923,7 +3032,7 @@ paths:- $ref: '#/definitions/SuccessResponse'- properties:data:- $ref: '#/definitions/services.flowFiles'+ $ref: '#/definitions/models.FlowFiles'type: object"400":description: invalid flow files request data@@ -2971,7 +3080,7 @@ paths:- $ref: '#/definitions/SuccessResponse'- properties:data:- $ref: '#/definitions/services.flowFiles'+ $ref: '#/definitions/models.FlowFiles'type: object"400":description: invalid flow files request data@@ -3021,7 +3130,7 @@ paths:- $ref: '#/definitions/SuccessResponse'- properties:data:- $ref: '#/definitions/services.containerFiles'+ $ref: '#/definitions/models.ContainerFiles'type: object"400":description: invalid flow files request data or container not running@@ -3104,7 +3213,7 @@ paths:name: requestrequired: trueschema:- $ref: '#/definitions/services.pullFlowFilesRequest'+ $ref: '#/definitions/models.PullFlowFilesRequest'produces:- application/jsonresponses:@@ -3115,7 +3224,7 @@ paths:- $ref: '#/definitions/SuccessResponse'- properties:data:- $ref: '#/definitions/services.flowFiles'+ $ref: '#/definitions/models.FlowFiles'type: object"400":description: invalid pull request or container not running@@ -3143,6 +3252,119 @@ paths:cachetags:- FlowFiles+ /flows/{flowID}/files/resources:+ post:+ consumes:+ - application/json+ description: |-+ Copies one or more user resources (identified by ID) into flow-{id}-data/resources/.+ Files already present in the flow are skipped unless force=true, in which case they are replaced.+ parameters:+ - description: flow id+ in: path+ minimum: 0+ name: flowID+ required: true+ type: integer+ - description: resource IDs and force flag+ in: body+ name: body+ required: true+ schema:+ $ref: '#/definitions/models.AddResourcesRequest'+ produces:+ - application/json+ responses:+ "200":+ description: resources copied successfully+ schema:+ allOf:+ - $ref: '#/definitions/SuccessResponse'+ - properties:+ data:+ $ref: '#/definitions/models.FlowFiles'+ type: object+ "400":+ description: invalid request+ schema:+ $ref: '#/definitions/ErrorResponse'+ "403":+ description: not permitted+ schema:+ $ref: '#/definitions/ErrorResponse'+ "404":+ description: flow not found+ schema:+ $ref: '#/definitions/ErrorResponse'+ "409":+ description: file already exists and force=false+ schema:+ $ref: '#/definitions/ErrorResponse'+ "500":+ description: internal error+ schema:+ $ref: '#/definitions/ErrorResponse'+ security:+ - BearerAuth: []+ summary: Copy user resources into a flow+ tags:+ - FlowFiles+ /flows/{flowID}/files/to-resources:+ post:+ consumes:+ - application/json+ description: Reads a file from flow-{id}-data/{sourcePath}, computes MD5, stores+ the blob, inserts a user_resources row.+ parameters:+ - description: flow id+ in: path+ minimum: 0+ name: flowID+ required: true+ type: integer+ - description: source path, destination and force flag+ in: body+ name: body+ required: true+ schema:+ $ref: '#/definitions/models.AddResourceFromFlowRequest'+ produces:+ - application/json+ responses:+ "200":+ description: resource created or updated+ schema:+ allOf:+ - $ref: '#/definitions/SuccessResponse'+ - properties:+ data:+ $ref: '#/definitions/models.ResourceEntry'+ type: object+ "400":+ description: invalid request+ schema:+ $ref: '#/definitions/ErrorResponse'+ "403":+ description: not permitted+ schema:+ $ref: '#/definitions/ErrorResponse'+ "404":+ description: source file or flow not found+ schema:+ $ref: '#/definitions/ErrorResponse'+ "409":+ description: destination already exists and force=false+ schema:+ $ref: '#/definitions/ErrorResponse'+ "500":+ description: internal error+ schema:+ $ref: '#/definitions/ErrorResponse'+ security:+ - BearerAuth: []+ summary: Promote a flow file to user resources+ tags:+ - FlowFiles/flows/{flowID}/graph:get:parameters:@@ -4616,6 +4838,304 @@ paths:summary: Retrieve providers listtags:- Providers+ /resources/:+ delete:+ parameters:+ - description: virtual path to delete+ in: query+ name: path+ required: true+ type: string+ produces:+ - application/json+ responses:+ "200":+ description: OK+ schema:+ allOf:+ - $ref: '#/definitions/SuccessResponse'+ - properties:+ data:+ $ref: '#/definitions/models.ResourceList'+ type: object+ "400":+ description: Bad Request+ schema:+ $ref: '#/definitions/ErrorResponse'+ "403":+ description: Forbidden+ schema:+ $ref: '#/definitions/ErrorResponse'+ "404":+ description: Not Found+ schema:+ $ref: '#/definitions/ErrorResponse'+ "500":+ description: Internal Server Error+ schema:+ $ref: '#/definitions/ErrorResponse'+ security:+ - BearerAuth: []+ summary: Delete a resource (file or directory)+ tags:+ - Resources+ get:+ parameters:+ - description: virtual directory path; empty for root+ in: query+ name: path+ type: string+ - description: list recursively (default false)+ in: query+ name: recursive+ type: boolean+ produces:+ - application/json+ responses:+ "200":+ description: OK+ schema:+ allOf:+ - $ref: '#/definitions/SuccessResponse'+ - properties:+ data:+ $ref: '#/definitions/models.ResourceList'+ type: object+ "400":+ description: Bad Request+ schema:+ $ref: '#/definitions/ErrorResponse'+ "403":+ description: Forbidden+ schema:+ $ref: '#/definitions/ErrorResponse'+ "500":+ description: Internal Server Error+ schema:+ $ref: '#/definitions/ErrorResponse'+ security:+ - BearerAuth: []+ summary: List user resources+ tags:+ - Resources+ post:+ consumes:+ - multipart/form-data+ parameters:+ - description: target virtual directory path; empty or omitted means root+ in: query+ name: dir+ type: string+ - description: 'files to upload (field name: files or file)'+ in: formData+ name: files+ required: true+ type: file+ produces:+ - application/json+ responses:+ "200":+ description: OK+ schema:+ allOf:+ - $ref: '#/definitions/SuccessResponse'+ - properties:+ data:+ $ref: '#/definitions/models.ResourceList'+ type: object+ "400":+ description: Bad Request+ schema:+ $ref: '#/definitions/ErrorResponse'+ "403":+ description: Forbidden+ schema:+ $ref: '#/definitions/ErrorResponse'+ "409":+ description: Conflict+ schema:+ $ref: '#/definitions/ErrorResponse'+ "500":+ description: Internal Server Error+ schema:+ $ref: '#/definitions/ErrorResponse'+ security:+ - BearerAuth: []+ summary: Upload files to resource storage+ tags:+ - Resources+ /resources/copy:+ post:+ consumes:+ - application/json+ parameters:+ - description: copy request+ in: body+ name: request+ required: true+ schema:+ $ref: '#/definitions/models.CopyResourceRequest'+ produces:+ - application/json+ responses:+ "200":+ description: OK+ schema:+ allOf:+ - $ref: '#/definitions/SuccessResponse'+ - properties:+ data:+ $ref: '#/definitions/models.ResourceList'+ type: object+ "400":+ description: Bad Request+ schema:+ $ref: '#/definitions/ErrorResponse'+ "403":+ description: Forbidden+ schema:+ $ref: '#/definitions/ErrorResponse'+ "404":+ description: Not Found+ schema:+ $ref: '#/definitions/ErrorResponse'+ "409":+ description: Conflict+ schema:+ $ref: '#/definitions/ErrorResponse'+ "500":+ description: Internal Server Error+ schema:+ $ref: '#/definitions/ErrorResponse'+ security:+ - BearerAuth: []+ summary: Copy a resource (file or directory)+ tags:+ - Resources+ /resources/download:+ get:+ parameters:+ - description: virtual path to download+ in: query+ name: path+ required: true+ type: string+ produces:+ - application/octet-stream+ responses:+ "200":+ description: file content, or ZIP archive for directories+ schema:+ type: file+ "400":+ description: invalid resource request data+ schema:+ $ref: '#/definitions/ErrorResponse'+ "403":+ description: downloading resource not permitted+ schema:+ $ref: '#/definitions/ErrorResponse'+ "404":+ description: resource not found+ schema:+ $ref: '#/definitions/ErrorResponse'+ "500":+ description: internal error on downloading resource+ schema:+ $ref: '#/definitions/ErrorResponse'+ security:+ - BearerAuth: []+ summary: Download a resource+ tags:+ - Resources+ /resources/mkdir:+ post:+ consumes:+ - application/json+ parameters:+ - description: mkdir request+ in: body+ name: request+ required: true+ schema:+ $ref: '#/definitions/models.MkdirResourceRequest'+ produces:+ - application/json+ responses:+ "200":+ description: OK+ schema:+ allOf:+ - $ref: '#/definitions/SuccessResponse'+ - properties:+ data:+ $ref: '#/definitions/models.ResourceEntry'+ type: object+ "400":+ description: Bad Request+ schema:+ $ref: '#/definitions/ErrorResponse'+ "403":+ description: Forbidden+ schema:+ $ref: '#/definitions/ErrorResponse'+ "500":+ description: Internal Server Error+ schema:+ $ref: '#/definitions/ErrorResponse'+ security:+ - BearerAuth: []+ summary: Create a virtual directory+ tags:+ - Resources+ /resources/move:+ put:+ consumes:+ - application/json+ parameters:+ - description: move request+ in: body+ name: request+ required: true+ schema:+ $ref: '#/definitions/models.MoveResourceRequest'+ produces:+ - application/json+ responses:+ "200":+ description: OK+ schema:+ allOf:+ - $ref: '#/definitions/SuccessResponse'+ - properties:+ data:+ $ref: '#/definitions/models.ResourceList'+ type: object+ "400":+ description: Bad Request+ schema:+ $ref: '#/definitions/ErrorResponse'+ "403":+ description: Forbidden+ schema:+ $ref: '#/definitions/ErrorResponse'+ "404":+ description: Not Found+ schema:+ $ref: '#/definitions/ErrorResponse'+ "409":+ description: Conflict+ schema:+ $ref: '#/definitions/ErrorResponse'+ "500":+ description: Internal Server Error+ schema:+ $ref: '#/definitions/ErrorResponse'+ security:+ - BearerAuth: []+ summary: Move or rename a resource (file or directory)+ tags:+ - Resources/roles/:get:parameters:diff --git a/backend/pkg/server/models/assistants.go b/backend/pkg/server/models/assistants.goindex 42e88515..a018ae59 100644--- a/backend/pkg/server/models/assistants.go+++ b/backend/pkg/server/models/assistants.go@@ -84,10 +84,11 @@ func (a Assistant) Validate(db *gorm.DB) {// CreateAssistant is model to contain assistant creation paylaod// nolint:llltype CreateAssistant struct {- Input string `form:"input" json:"input" validate:"required" example:"user input for running assistant"`- Provider string `form:"provider" json:"provider" validate:"required" example:"openai"`- UseAgents bool `form:"use_agents" json:"use_agents" validate:"omitempty" example:"true"`- Functions *tools.Functions `form:"functions,omitempty" json:"functions,omitempty" validate:"omitempty,valid"`+ Input string `form:"input" json:"input" validate:"required" example:"user input for running assistant"`+ Provider string `form:"provider" json:"provider" validate:"required" example:"openai"`+ UseAgents bool `form:"use_agents" json:"use_agents" validate:"omitempty" example:"true"`+ Functions *tools.Functions `form:"functions,omitempty" json:"functions,omitempty" validate:"omitempty,valid"`+ ResourceIDs []uint64 `form:"resource_ids,omitempty" json:"resource_ids,omitempty" validate:"omitempty" swaggertype:"array,integer"`}// Valid is function to control input/output data@@ -98,9 +99,10 @@ func (ca CreateAssistant) Valid() error {// PatchAssistant is model to contain assistant patching paylaod// nolint:llltype PatchAssistant struct {- Action string `form:"action" json:"action" validate:"required,oneof=stop input" enums:"stop,input" default:"stop"`- Input *string `form:"input,omitempty" json:"input,omitempty" validate:"required_if=Action input" example:"user input for waiting assistant"`- UseAgents bool `form:"use_agents" json:"use_agents" validate:"omitempty" example:"true"`+ Action string `form:"action" json:"action" validate:"required,oneof=stop input" enums:"stop,input" default:"stop"`+ Input *string `form:"input,omitempty" json:"input,omitempty" validate:"required_if=Action input" example:"user input for waiting assistant"`+ UseAgents bool `form:"use_agents" json:"use_agents" validate:"omitempty" example:"true"`+ ResourceIDs []uint64 `form:"resource_ids,omitempty" json:"resource_ids,omitempty" validate:"omitempty" swaggertype:"array,integer"`}// Valid is function to control input/output datadiff --git a/backend/pkg/server/models/flow_files.go b/backend/pkg/server/models/flow_files.gonew file mode 100644index 00000000..e6082f82--- /dev/null+++ b/backend/pkg/server/models/flow_files.go@@ -0,0 +1,62 @@+package models++import "time"++// FlowFile represents a single entry in the flow's local file cache.+type FlowFile struct {+ ID string `json:"id"`+ Name string `json:"name"`+ Path string `json:"path"` // relative: "uploads/<x>" or resources/<x> or container/<x>"+ Size int64 `json:"size"`+ IsDir bool `json:"isDir"`+ ModifiedAt time.Time `json:"modifiedAt"`+}++// FlowFiles is the list response for flow file operations.+type FlowFiles struct {+ Files []FlowFile `json:"files"`+ Total uint64 `json:"total"`+}++// ContainerFile represents a single entry in the running container's filesystem.+type ContainerFile struct {+ ID string `json:"id"`+ Name string `json:"name"`+ Path string `json:"path"`+ Size int64 `json:"size"`+ IsDir bool `json:"isDir"`+ ModifiedAt time.Time `json:"modifiedAt"`+}++// ContainerFiles is the list response for container directory listing.+type ContainerFiles struct {+ Path string `json:"path"`+ Files []ContainerFile `json:"files"`+ Total uint64 `json:"total"`+}++// PullFlowFilesRequest is the request body for pulling files from a container.+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"`+}++// AddResourcesRequest is the request body for copying user resources into a flow.+type AddResourcesRequest struct {+ // IDs is the list of user resource IDs to copy into the flow resources directory.+ IDs []string `json:"ids" binding:"required,min=1"`+ // Force overwrites files that already exist in the flow resources directory.+ Force bool `json:"force"`+}++// AddResourceFromFlowRequest is the request body for promoting a flow file to user resources.+type AddResourceFromFlowRequest struct {+ // SourcePath is a relative path within the flow cache, e.g. "container/work/result.md" or "uploads/task.md".+ SourcePath string `json:"sourcePath" binding:"required"`+ // Destination is the virtual path the resource will have in the user's resource tree.+ Destination string `json:"destination" binding:"required"`+ // Force overwrites an existing resource at Destination if one already exists.+ Force bool `json:"force"`+}diff --git a/backend/pkg/server/models/flows.go b/backend/pkg/server/models/flows.goindex 6e8cd5d4..b28052a4 100644--- a/backend/pkg/server/models/flows.go+++ b/backend/pkg/server/models/flows.go@@ -83,9 +83,10 @@ func (f Flow) Validate(db *gorm.DB) {// CreateFlow is model to contain flow creation paylaod// nolint:llltype CreateFlow struct {- Input string `form:"input" json:"input" validate:"required" example:"user input for first task in the flow"`- Provider string `form:"provider" json:"provider" validate:"required" example:"openai"`- Functions *tools.Functions `form:"functions,omitempty" json:"functions,omitempty" validate:"omitempty,valid"`+ Input string `form:"input" json:"input" validate:"required" example:"user input for first task in the flow"`+ Provider string `form:"provider" json:"provider" validate:"required" example:"openai"`+ Functions *tools.Functions `form:"functions,omitempty" json:"functions,omitempty" validate:"omitempty,valid"`+ ResourceIDs []uint64 `form:"resource_ids,omitempty" json:"resource_ids,omitempty" validate:"omitempty" swaggertype:"array,integer"`}// Valid is function to control input/output data@@ -96,10 +97,11 @@ func (cf CreateFlow) Valid() error {// PatchFlow is model to contain flow patching paylaod// nolint:llltype PatchFlow struct {- Action string `form:"action" json:"action" validate:"required,oneof=stop finish input rename" enums:"stop,finish,input,rename" default:"stop"`- Input *string `form:"input,omitempty" json:"input,omitempty" validate:"required_if=Action input" example:"user input for waiting flow"`- Provider *string `form:"provider,omitempty" json:"provider,omitempty" validate:"omitempty"`- Name *string `form:"name,omitempty" json:"name,omitempty" validate:"required_if=Action rename" example:"new flow name"`+ Action string `form:"action" json:"action" validate:"required,oneof=stop finish input rename" enums:"stop,finish,input,rename" default:"stop"`+ Input *string `form:"input,omitempty" json:"input,omitempty" validate:"required_if=Action input" example:"user input for waiting flow"`+ Provider *string `form:"provider,omitempty" json:"provider,omitempty" validate:"omitempty"`+ Name *string `form:"name,omitempty" json:"name,omitempty" validate:"required_if=Action rename" example:"new flow name"`+ ResourceIDs []uint64 `form:"resource_ids,omitempty" json:"resource_ids,omitempty" validate:"omitempty" swaggertype:"array,integer"`}// Valid is function to control input/output datadiff --git a/backend/pkg/server/models/resources.go b/backend/pkg/server/models/resources.gonew file mode 100644index 00000000..6861af63--- /dev/null+++ b/backend/pkg/server/models/resources.go@@ -0,0 +1,57 @@+package models++import "time"++// UserResource is the GORM model for a user-owned resource (file or directory)+// whose metadata lives in PostgreSQL and whose content (for files) is stored as+// a .blob file on disk keyed by MD5 hash.+//+// nolint:lll+type UserResource struct {+ ID uint64 `form:"id" json:"id" gorm:"type:BIGINT;NOT NULL;PRIMARY_KEY;AUTO_INCREMENT"`+ UserID uint64 `form:"user_id" json:"user_id" gorm:"type:BIGINT;NOT NULL;index"`+ Hash string `form:"hash" json:"hash" gorm:"type:TEXT;NOT NULL;default:''"`+ Name string `form:"name" json:"name" gorm:"type:TEXT;NOT NULL"`+ Path string `form:"path" json:"path" gorm:"type:TEXT;NOT NULL"`+ Size int64 `form:"size" json:"size" gorm:"type:BIGINT;NOT NULL;default:0"`+ IsDir bool `form:"is_dir" json:"is_dir" gorm:"type:BOOLEAN;NOT NULL;default:false"`+ CreatedAt time.Time `form:"created_at" json:"created_at"`+ UpdatedAt time.Time `form:"updated_at" json:"updated_at"`+}++// ResourceEntry is the REST response representation of a single resource.+type ResourceEntry struct {+ ID int64 `json:"id"`+ UserID uint64 `json:"userId"`+ Name string `json:"name"`+ Path string `json:"path"`+ Size int64 `json:"size"`+ IsDir bool `json:"isDir"`+ CreatedAt time.Time `json:"createdAt"`+ UpdatedAt time.Time `json:"updatedAt"`+}++// ResourceList is the REST list response for resource operations.+type ResourceList struct {+ Items []ResourceEntry `json:"items"`+ Total uint64 `json:"total"`+}++// MkdirResourceRequest is the request body for creating a virtual directory.+type MkdirResourceRequest struct {+ Path string `json:"path" binding:"required"`+}++// MoveResourceRequest is the request body for moving or renaming a resource.+type MoveResourceRequest struct {+ Source string `json:"source" binding:"required"`+ Destination string `json:"destination" binding:"required"`+ Force bool `json:"force"`+}++// CopyResourceRequest is the request body for copying a resource.+type CopyResourceRequest struct {+ Source string `json:"source" binding:"required"`+ Destination string `json:"destination" binding:"required"`+ Force bool `json:"force"`+}diff --git a/backend/pkg/server/response/errors.go b/backend/pkg/server/response/errors.goindex f53685f9..e5aeff71 100644--- a/backend/pkg/server/response/errors.go+++ b/backend/pkg/server/response/errors.go@@ -135,6 +135,14 @@ var ErrAssistantsInvalidRequest = NewHttpError(400, "Assistants.InvalidRequest",var ErrAssistantsNotFound = NewHttpError(404, "Assistants.NotFound", "assistant not found")var ErrAssistantsInvalidData = NewHttpError(500, "Assistants.InvalidData", "invalid assistant data")+// resources++var ErrResourcesInvalidRequest = NewHttpError(400, "Resources.InvalidRequest", "invalid resource request data")+var ErrResourcesNotFound = NewHttpError(404, "Resources.NotFound", "resource not found")+var ErrResourcesAlreadyExists = NewHttpError(409, "Resources.AlreadyExists", "resource already exists")+var ErrResourcesInvalidData = NewHttpError(400, "Resources.InvalidData", "invalid resource data")+var ErrResourcesConflict = NewHttpError(409, "Resources.Conflict", "resource conflict: use force=true to merge")+// tokensvar ErrTokenCreationDisabled = NewHttpError(400, "Token.CreationDisabled", "token creation is disabled with default configuration")diff --git a/backend/pkg/server/router.go b/backend/pkg/server/router.goindex 920a37c6..082d9d79 100644--- a/backend/pkg/server/router.go+++ b/backend/pkg/server/router.go@@ -133,6 +133,7 @@ func NewRouter(providerService := services.NewProviderService(providers)flowService := services.NewFlowService(orm, providers, controller, subscriptions)flowFileService := services.NewFlowFileService(orm, cfg.DataDir, dockerClient, subscriptions)+ resourceService := services.NewResourceService(orm, cfg.DataDir, subscriptions)taskService := services.NewTaskService(orm)subtaskService := services.NewSubtaskService(orm)containerService := services.NewContainerService(orm)@@ -227,6 +228,7 @@ func NewRouter(setProvidersGroup(privateGroup, providerService)setFlowsGroup(privateGroup, flowService)setFlowFilesGroup(privateGroup, flowFileService)+ setResourcesGroup(privateGroup, resourceService)setTasksGroup(privateGroup, taskService)setSubtasksGroup(privateGroup, subtaskService)setContainersGroup(privateGroup, containerService)@@ -380,6 +382,21 @@ func setFlowFilesGroup(parent *gin.RouterGroup, svc *services.FlowFileService) {flowFilesGroup.DELETE("/", svc.DeleteFlowFile)flowFilesGroup.GET("/download", svc.DownloadFlowFile)flowFilesGroup.POST("/pull", svc.PullFlowFiles)+ flowFilesGroup.POST("/resources", svc.AddResourcesToFlow)+ flowFilesGroup.POST("/to-resources", svc.AddResourceFromFlow)+ }+}++func setResourcesGroup(parent *gin.RouterGroup, svc *services.ResourceService) {+ rg := parent.Group("/resources")+ {+ rg.GET("/", svc.ListResources)+ rg.POST("/", svc.UploadResources)+ rg.POST("/mkdir", svc.MkdirResource)+ rg.PUT("/move", svc.MoveResource)+ rg.POST("/copy", svc.CopyResource)+ rg.DELETE("/", svc.DeleteResource)+ rg.GET("/download", svc.DownloadResource)}}diff --git a/backend/pkg/server/services/api_tokens.go b/backend/pkg/server/services/api_tokens.goindex 4577fbe6..653a1c42 100644--- a/backend/pkg/server/services/api_tokens.go+++ b/backend/pkg/server/services/api_tokens.go@@ -138,7 +138,7 @@ func (s *TokenService) CreateToken(c *gin.Context) {s.tokenCache.InvalidateUser(apiToken.UserID)if s.ss != nil {- publisher := s.ss.NewFlowPublisher(int64(apiToken.UserID), 0)+ publisher := s.ss.NewAPITokenPublisher(int64(apiToken.UserID))publisher.APITokenCreated(c, database.APITokenWithSecret{ApiToken: convertAPITokenToDatabase(apiToken),Token: token,@@ -348,7 +348,7 @@ func (s *TokenService) UpdateToken(c *gin.Context) {}if s.ss != nil {- publisher := s.ss.NewFlowPublisher(int64(token.UserID), 0)+ publisher := s.ss.NewAPITokenPublisher(int64(token.UserID))publisher.APITokenUpdated(c, convertAPITokenToDatabase(token))}@@ -401,7 +401,7 @@ func (s *TokenService) DeleteToken(c *gin.Context) {s.tokenCache.InvalidateUser(token.UserID)if s.ss != nil {- publisher := s.ss.NewFlowPublisher(int64(token.UserID), 0)+ publisher := s.ss.NewAPITokenPublisher(int64(token.UserID))publisher.APITokenDeleted(c, convertAPITokenToDatabase(token))}diff --git a/backend/pkg/server/services/assistants.go b/backend/pkg/server/services/assistants.goindex 1386d986..16eb0661 100644--- a/backend/pkg/server/services/assistants.go+++ b/backend/pkg/server/services/assistants.go@@ -3,6 +3,7 @@ package servicesimport ("encoding/json""errors"+ "fmt""net/http""slices""strconv"@@ -284,6 +285,13 @@ func (s *AssistantService) CreateFlowAssistant(c *gin.Context) {}prvtype := prv.Type()+ dbResources, err := validateServiceResources(s.db, uid, privs, createAssistant.ResourceIDs)+ if err != nil {+ logger.FromContext(c).WithError(err).Errorf("error validating resource ids")+ response.Error(c, response.ErrAssistantsInvalidRequest, err)+ return+ }+aw, err := s.fc.CreateAssistant(c,int64(uid),@@ -293,6 +301,7 @@ func (s *AssistantService) CreateFlowAssistant(c *gin.Context) {prvname,prvtype,createAssistant.Functions,+ dbResources,)if err != nil {logger.FromContext(c).WithError(err).Errorf("error creating assistant")@@ -416,7 +425,14 @@ func (s *AssistantService) PatchAssistant(c *gin.Context) {return}- if err := aw.PutInput(c, *patchAssistant.Input, patchAssistant.UseAgents); err != nil {+ dbResources, err := validateServiceResources(s.db, uid, privs, patchAssistant.ResourceIDs)+ if err != nil {+ logger.FromContext(c).WithError(err).Errorf("error validating resource ids")+ response.Error(c, response.ErrAssistantsInvalidRequest, err)+ return+ }++ if err := aw.PutInput(c, *patchAssistant.Input, patchAssistant.UseAgents, dbResources); err != nil {logger.FromContext(c).WithError(err).Errorf("error sending input to assistant")response.Error(c, response.ErrInternal, err)return@@ -584,3 +600,52 @@ func convertAssistantToDatabase(assistant models.Assistant) (database.Assistant,ToolCallIDTemplate: assistant.ToolCallIDTemplate,}, nil}++// validateServiceResources fetches and validates user resource ownership for REST handlers.+// It mirrors the logic in validateUserResources from the graph package but works with *gorm.DB.+// privs must contain at least "resources.view" or "resources.admin"; otherwise permission is denied.+// "resources.admin" bypasses the user_id ownership check.+func validateServiceResources(db *gorm.DB, uid uint64, privs []string, ids []uint64) ([]database.UserResource, error) {+ if len(ids) == 0 {+ return nil, nil+ }++ isAdmin := slices.Contains(privs, "resources.admin")+ if !isAdmin && !slices.Contains(privs, "resources.view") && len(ids) > 0 {+ return nil, fmt.Errorf("permission 'resources.view' required to use resource IDs")+ }++ var recs []models.UserResource+ if err := db.Model(&models.UserResource{}).Where("id IN (?)", ids).Find(&recs).Error; err != nil {+ return nil, fmt.Errorf("failed to fetch resources: %w", err)+ }++ found := make(map[uint64]models.UserResource, len(recs))+ for _, r := range recs {+ found[r.ID] = r+ }++ result := make([]database.UserResource, 0, len(ids))+ for _, id := range ids {+ r, ok := found[id]+ if !ok {+ return nil, fmt.Errorf("resource %d not found", id)+ }+ if !isAdmin && r.UserID != uid {+ return nil, fmt.Errorf("resource %d not accessible", id)+ }+ result = append(result, database.UserResource{+ ID: int64(r.ID),+ UserID: int64(r.UserID),+ Hash: r.Hash,+ Name: r.Name,+ Path: r.Path,+ Size: r.Size,+ IsDir: r.IsDir,+ CreatedAt: database.TimeToNullTime(r.CreatedAt),+ UpdatedAt: database.TimeToNullTime(r.UpdatedAt),+ })+ }++ return result, nil+}diff --git a/backend/pkg/server/services/flow_files.go b/backend/pkg/server/services/flow_files.goindex 792a1ac2..934c3ad6 100644--- a/backend/pkg/server/services/flow_files.go+++ b/backend/pkg/server/services/flow_files.go@@ -1,7 +1,6 @@package servicesimport (- "archive/tar""context""errors""fmt"@@ -21,6 +20,7 @@ import ("pentagi/pkg/flowfiles""pentagi/pkg/graph/model""pentagi/pkg/graph/subscriptions"+ "pentagi/pkg/resources""pentagi/pkg/server/logger""pentagi/pkg/server/models""pentagi/pkg/server/response"@@ -34,42 +34,8 @@ import (// Local storage layout under {dataDir}/flow-{id}-data/://// uploads/ ← user-uploaded files; also pushed to container /work/uploads/+// resources/ ← user resources copied from user_resources table; also pushed to container /work/resources/// container/ ← files synced from the container via pull; never sent back to container-type flowFile struct {- ID string `json:"id"`- Name string `json:"name"`- 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"`-}--type flowFiles struct {- Files []flowFile `json:"files"`- Total uint64 `json:"total"`-}--type containerFile struct {- ID string `json:"id"`- Name string `json:"name"`- Path string `json:"path"`- Size int64 `json:"size"`- IsDir bool `json:"isDir"`- ModifiedAt time.Time `json:"modifiedAt"`-}--type containerFiles struct {- Path string `json:"path"`- Files []containerFile `json:"files"`- 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@@ -79,6 +45,7 @@ type pendingUpload struct {// FlowFileService manages flow-scoped files with two distinct sources:// - user uploads → {dataDir}/flow-{id}-data/uploads/ (also pushed to container /work/uploads/)+// - user resources → {dataDir}/flow-{id}-data/resources/ (copied from user_resources table)// - container sync → {dataDir}/flow-{id}-data/container/ (pulled from container, never sent back)type FlowFileService struct {dataDir string@@ -107,7 +74,7 @@ func NewFlowFileService(// @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"+// @Success 200 {object} response.successResp{data=models.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"@@ -133,7 +100,7 @@ func (s *FlowFileService) GetFlowFiles(c *gin.Context) {return}- response.Success(c, http.StatusOK, flowFiles{+ response.Success(c, http.StatusOK, models.FlowFiles{Files: files,Total: uint64(len(files)),})@@ -147,7 +114,7 @@ func (s *FlowFileService) GetFlowFiles(c *gin.Context) {// @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"+// @Success 200 {object} response.successResp{data=models.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"@@ -285,7 +252,7 @@ func (s *FlowFileService) UploadFlowFiles(c *gin.Context) {}// Temporary files are complete — move them into place, then push to container.- savedFiles := make([]flowFile, 0, len(fileHeaders))+ savedFiles := make([]models.FlowFile, 0, len(fileHeaders))for i := range pending {p := &pending[i]if err := os.Rename(p.tmpPath, p.dstPath); err != nil {@@ -323,7 +290,7 @@ func (s *FlowFileService) UploadFlowFiles(c *gin.Context) {sortFlowFiles(savedFiles)s.publishFlowFilesAdded(c.Request.Context(), flow, savedFiles)- response.Success(c, http.StatusOK, flowFiles{+ response.Success(c, http.StatusOK, models.FlowFiles{Files: savedFiles,Total: uint64(len(savedFiles)),})@@ -336,7 +303,7 @@ func (s *FlowFileService) UploadFlowFiles(c *gin.Context) {// @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"+// @Success 200 {object} response.successResp{data=models.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"@@ -388,7 +355,7 @@ func (s *FlowFileService) DeleteFlowFile(c *gin.Context) {}s.publishFlowFileDeleted(c.Request.Context(), flow, deletedFile)- response.Success(c, http.StatusOK, flowFiles{+ response.Success(c, http.StatusOK, models.FlowFiles{Files: nil,Total: 0,})@@ -401,7 +368,7 @@ func (s *FlowFileService) DeleteFlowFile(c *gin.Context) {// @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"+// @Success 200 {file} binary "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"@@ -471,8 +438,8 @@ func (s *FlowFileService) DownloadFlowFile(c *gin.Context) {// @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"+// @Param request body models.PullFlowFilesRequest true "pull request"+// @Success 200 {object} response.successResp{data=models.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"@@ -493,7 +460,14 @@ func (s *FlowFileService) PullFlowFiles(c *gin.Context) {return}- var req pullFlowFilesRequest+ // Container interaction additionally requires containers.view (or containers.admin).+ privs := c.GetStringSlice("prm")+ if !slices.Contains(privs, "containers.admin") && !slices.Contains(privs, "containers.view") {+ response.Error(c, response.ErrNotPermitted, fmt.Errorf("containers.view privilege is required to pull from container"))+ return+ }++ var req models.PullFlowFilesRequestif 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)@@ -658,10 +632,10 @@ func (s *FlowFileService) PullFlowFiles(c *gin.Context) {if targetExists {s.publishFlowFileUpdated(c.Request.Context(), flow, synced)} else {- s.publishFlowFilesAdded(c.Request.Context(), flow, []flowFile{synced})+ s.publishFlowFilesAdded(c.Request.Context(), flow, []models.FlowFile{synced})}- response.Success(c, http.StatusOK, flowFiles{- Files: []flowFile{synced},+ response.Success(c, http.StatusOK, models.FlowFiles{+ Files: []models.FlowFile{synced},Total: 1,})}@@ -673,7 +647,7 @@ func (s *FlowFileService) PullFlowFiles(c *gin.Context) {// @Security BearerAuth// @Param flowID path int true "flow id" minimum(0)// @Param path query string false "absolute path inside the running container; defaults to /work"-// @Success 200 {object} response.successResp{data=containerFiles} "container files list received successful"+// @Success 200 {object} response.successResp{data=models.ContainerFiles} "container files list received successful"// @Failure 400 {object} response.errorResp "invalid flow files request data or container not running"// @Failure 403 {object} response.errorResp "getting flow container files not permitted"// @Failure 404 {object} response.errorResp "flow not found"@@ -692,6 +666,13 @@ func (s *FlowFileService) GetFlowContainerFiles(c *gin.Context) {return}+ // Container interaction additionally requires containers.view (or containers.admin).+ privs := c.GetStringSlice("prm")+ if !slices.Contains(privs, "containers.admin") && !slices.Contains(privs, "containers.view") {+ response.Error(c, response.ErrNotPermitted, fmt.Errorf("containers.view privilege is required to list container files"))+ 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 container files list")@@ -732,9 +713,9 @@ func (s *FlowFileService) GetFlowContainerFiles(c *gin.Context) {}if !pathStat.Mode.IsDir() {file := convertContainerFile(path.Dir(containerPath), pathStat)- response.Success(c, http.StatusOK, containerFiles{+ response.Success(c, http.StatusOK, models.ContainerFiles{Path: containerPath,- Files: []containerFile{file},+ Files: []models.ContainerFile{file},Total: 1,})return@@ -751,7 +732,7 @@ func (s *FlowFileService) GetFlowContainerFiles(c *gin.Context) {}files := convertContainerFiles(containerPath, stats)- response.Success(c, http.StatusOK, containerFiles{+ response.Success(c, http.StatusOK, models.ContainerFiles{Path: containerPath,Files: files,Total: uint64(len(files)),@@ -780,7 +761,7 @@ func (s *FlowFileService) getFlow(c *gin.Context, flowID uint64, writeAccess boo// 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) {+func (s *FlowFileService) listFlowFiles(flowID uint64) ([]models.FlowFile, error) {files, err := flowfiles.List(s.dataDir, flowID)if err != nil {return nil, err@@ -840,15 +821,11 @@ func (s *FlowFileService) copyFileToContainer(ctx context.Context, flowID uint64return 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)+ tarName := path.Join(flowfiles.UploadsDirName, filepath.Base(localFilePath))+ errCh <- flowfiles.WriteSingleFileTar(pw, localFilePath, tarName)}()copyErr := s.dockerClient.CopyToContainer(ctx, containerName, docker.WorkFolderPathInContainer, pr,@@ -861,46 +838,6 @@ func (s *FlowFileService) copyFileToContainer(ctx context.Context, flowID uint64return 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@@ -962,19 +899,19 @@ func flowScopeForFiles(flowID uint64,writeAccess bool,) func(db *gorm.DB) *gorm.DB {- if slices.Contains(privs, "flows.admin") {+ if slices.Contains(privs, "flow_files.admin") {return func(db *gorm.DB) *gorm.DB {return db.Where("id = ?", flowID)}}- if writeAccess && slices.Contains(privs, "flows.edit") {+ if writeAccess && slices.Contains(privs, "flow_files.upload") {return func(db *gorm.DB) *gorm.DB {return db.Where("id = ? AND user_id = ?", flowID, uid)}}- if !writeAccess && slices.Contains(privs, "flows.view") {+ if !writeAccess && slices.Contains(privs, "flow_files.view") {return func(db *gorm.DB) *gorm.DB {return db.Where("id = ? AND user_id = ?", flowID, uid)}@@ -995,16 +932,16 @@ func cleanupPendingUploads(pending []pendingUpload) {}}-func convertFlowFiles(files []flowfiles.File) []flowFile {- converted := make([]flowFile, 0, len(files))+func convertFlowFiles(files []flowfiles.File) []models.FlowFile {+ converted := make([]models.FlowFile, 0, len(files))for _, file := range files {converted = append(converted, convertFlowFile(file))}return converted}-func convertFlowFile(file flowfiles.File) flowFile {- return flowFile{+func convertFlowFile(file flowfiles.File) models.FlowFile {+ return models.FlowFile{ID: file.ID,Name: file.Name,Path: file.Path,@@ -1014,7 +951,7 @@ func convertFlowFile(file flowfiles.File) flowFile {}}-func convertModelFlowFile(file flowFile) *model.FlowFile {+func convertModelFlowFile(file models.FlowFile) *model.FlowFile {return &model.FlowFile{ID: file.ID,Name: file.Name,@@ -1025,8 +962,8 @@ func convertModelFlowFile(file flowFile) *model.FlowFile {}}-func convertContainerFiles(basePath string, stats []container.PathStat) []containerFile {- files := make([]containerFile, 0, len(stats))+func convertContainerFiles(basePath string, stats []container.PathStat) []models.ContainerFile {+ files := make([]models.ContainerFile, 0, len(stats))for _, stat := range stats {files = append(files, convertContainerFile(basePath, stat))}@@ -1038,10 +975,10 @@ func convertContainerFiles(basePath string, stats []container.PathStat) []contaireturn files}-func convertContainerFile(basePath string, stat container.PathStat) containerFile {+func convertContainerFile(basePath string, stat container.PathStat) models.ContainerFile {filePath := path.Join(basePath, stat.Name)- return containerFile{+ return models.ContainerFile{ID: flowfiles.ID(filePath),Name: stat.Name,Path: filePath,@@ -1051,7 +988,7 @@ func convertContainerFile(basePath string, stat container.PathStat) containerFil}}-func (s *FlowFileService) publishFlowFilesAdded(ctx context.Context, flow models.Flow, files []flowFile) {+func (s *FlowFileService) publishFlowFilesAdded(ctx context.Context, flow models.Flow, files []models.FlowFile) {if s.ss == nil {return}@@ -1062,7 +999,7 @@ func (s *FlowFileService) publishFlowFilesAdded(ctx context.Context, flow models}}-func (s *FlowFileService) publishFlowFileUpdated(ctx context.Context, flow models.Flow, file flowFile) {+func (s *FlowFileService) publishFlowFileUpdated(ctx context.Context, flow models.Flow, file models.FlowFile) {if s.ss == nil {return}@@ -1071,7 +1008,7 @@ func (s *FlowFileService) publishFlowFileUpdated(ctx context.Context, flow modelpublisher.FlowFileUpdated(ctx, convertModelFlowFile(file))}-func (s *FlowFileService) publishFlowFileDeleted(ctx context.Context, flow models.Flow, file flowFile) {+func (s *FlowFileService) publishFlowFileDeleted(ctx context.Context, flow models.Flow, file models.FlowFile) {if s.ss == nil {return}@@ -1080,7 +1017,7 @@ func (s *FlowFileService) publishFlowFileDeleted(ctx context.Context, flow modelpublisher.FlowFileDeleted(ctx, convertModelFlowFile(file))}-func sortFlowFiles(files []flowFile) {+func sortFlowFiles(files []models.FlowFile) {sort.Slice(files, func(i, j int) bool {if files[i].ModifiedAt.Equal(files[j].ModifiedAt) {return files[i].Name < files[j].Name@@ -1093,3 +1030,317 @@ func sortFlowFiles(files []flowFile) {func primaryContainerName(flowID uint64) string {return fmt.Sprintf("%s%d", tools.PrimaryTerminalNamePrefix, flowID)}++// AddResourcesToFlow copies user-owned resources into the flow resources directory.+// @Summary Copy user resources into a flow+// @Description Copies one or more user resources (identified by ID) into flow-{id}-data/resources/.+// @Description Files already present in the flow are skipped unless force=true, in which case they are replaced.+// @Tags FlowFiles+// @Accept json+// @Produce json+// @Security BearerAuth+// @Param flowID path int true "flow id" minimum(0)+// @Param body body models.AddResourcesRequest true "resource IDs and force flag"+// @Success 200 {object} response.successResp{data=models.FlowFiles} "resources copied successfully"+// @Failure 400 {object} response.errorResp "invalid request"+// @Failure 403 {object} response.errorResp "not permitted"+// @Failure 404 {object} response.errorResp "flow not found"+// @Failure 409 {object} response.errorResp "file already exists and force=false"+// @Failure 500 {object} response.errorResp "internal error"+// @Router /flows/{flowID}/files/resources [post]+func (s *FlowFileService) AddResourcesToFlow(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 models.AddResourcesRequest+ if err := c.ShouldBindJSON(&req); err != nil {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("invalid add resources request")+ response.Error(c, response.ErrFlowFilesInvalidRequest, err)+ return+ }++ uid := c.GetUint64("uid")+ privs := c.GetStringSlice("prm")+ isAdmin := slices.Contains(privs, "resources.admin") || slices.Contains(privs, "flow_files.admin")++ // Check privilege: need both flow_files.upload and resources.view.+ if !isAdmin {+ if !slices.Contains(privs, "flow_files.upload") {+ response.Error(c, response.ErrNotPermitted, nil)+ return+ }+ if !slices.Contains(privs, "resources.view") && !slices.Contains(privs, "resources.admin") {+ response.Error(c, response.ErrNotPermitted, nil)+ return+ }+ }++ // Fetch resources and validate ownership.+ var recs []models.UserResource+ if err := s.db.Model(&models.UserResource{}).Where("id IN (?)", req.IDs).Find(&recs).Error; err != nil {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error fetching resources by IDs")+ response.Error(c, response.ErrInternal, err)+ return+ }++ found := make(map[string]models.UserResource, len(recs))+ for _, r := range recs {+ found[fmt.Sprintf("%d", r.ID)] = r+ }++ refs := make([]flowfiles.ResourceRef, 0, len(req.IDs))+ for _, idStr := range req.IDs {+ r, ok := found[idStr]+ if !ok {+ err := fmt.Errorf("resource %s not found", idStr)+ response.Error(c, response.ErrFlowFilesInvalidRequest, err)+ return+ }+ if !isAdmin && r.UserID != uid {+ response.Error(c, response.ErrNotPermitted, nil)+ return+ }+ refs = append(refs, flowfiles.ResourceRef{+ Hash: r.Hash,+ VirtualPath: r.Path,+ Name: r.Name,+ IsDir: r.IsDir,+ })+ }++ storeDir := filepath.Join(s.dataDir, "resources")+ addedPaths, err := flowfiles.CopyResourcesToFlow(s.dataDir, storeDir, flowID, refs, req.Force)+ if err != nil {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error copying resources to flow")+ response.Error(c, response.ErrInternal, err)+ return+ }++ // Publish subscription events for newly added/updated files.+ if len(addedPaths) > 0 {+ addedFiles := make([]models.FlowFile, 0, len(addedPaths))+ resourcesDir := flowfiles.FlowResourcesDir(s.dataDir, flowID)+ for _, relPath := range addedPaths {+ fsRelPath := relPath[len(flowfiles.ResourcesDirName)+1:]+ absPath := filepath.Join(resourcesDir, filepath.FromSlash(fsRelPath))+ var size int64+ var modTime time.Time+ if info, err := os.Lstat(absPath); err == nil {+ size = info.Size()+ modTime = info.ModTime()+ } else {+ modTime = time.Now()+ }+ addedFiles = append(addedFiles, models.FlowFile{+ ID: flowfiles.ID(relPath),+ Name: path.Base(relPath),+ Path: relPath,+ Size: size,+ IsDir: false,+ ModifiedAt: modTime,+ })+ }++ if req.Force {+ for _, f := range addedFiles {+ s.publishFlowFileUpdated(c.Request.Context(), flow, f)+ }+ } else {+ s.publishFlowFilesAdded(c.Request.Context(), flow, addedFiles)+ }+ }++ files, err := s.listFlowFiles(flowID)+ if err != nil {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error listing flow files after resource add")+ response.Error(c, response.ErrInternal, err)+ return+ }++ response.Success(c, http.StatusOK, models.FlowFiles{+ Files: files,+ Total: uint64(len(files)),+ })+}++// AddResourceFromFlow promotes a file from the flow cache into the user's global resource store.+// @Summary Promote a flow file to user resources+// @Description Reads a file from flow-{id}-data/{sourcePath}, computes MD5, stores the blob, inserts a user_resources row.+// @Tags FlowFiles+// @Accept json+// @Produce json+// @Security BearerAuth+// @Param flowID path int true "flow id" minimum(0)+// @Param body body models.AddResourceFromFlowRequest true "source path, destination and force flag"+// @Success 200 {object} response.successResp{data=models.ResourceEntry} "resource created or updated"+// @Failure 400 {object} response.errorResp "invalid request"+// @Failure 403 {object} response.errorResp "not permitted"+// @Failure 404 {object} response.errorResp "source file or flow not found"+// @Failure 409 {object} response.errorResp "destination already exists and force=false"+// @Failure 500 {object} response.errorResp "internal error"+// @Router /flows/{flowID}/files/to-resources [post]+func (s *FlowFileService) AddResourceFromFlow(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+ }++ uid := c.GetUint64("uid")+ privs := c.GetStringSlice("prm")+ isAdmin := slices.Contains(privs, "resources.admin")++ if !isAdmin {+ if !slices.Contains(privs, "resources.upload") {+ response.Error(c, response.ErrNotPermitted, nil)+ return+ }+ if !slices.Contains(privs, "flow_files.view") && !slices.Contains(privs, "flow_files.admin") {+ response.Error(c, response.ErrNotPermitted, nil)+ return+ }+ }++ if _, err := s.getFlow(c, flowID, false); err != nil {+ s.handleFlowLookupError(c, flowID, err)+ return+ }++ var req models.AddResourceFromFlowRequest+ if err := c.ShouldBindJSON(&req); err != nil {+ logger.FromContext(c).WithError(err).Error("invalid add resource from flow request")+ response.Error(c, response.ErrFlowFilesInvalidRequest, err)+ return+ }++ absPath, err := flowfiles.ResolveCachedPath(s.dataDir, flowID, req.SourcePath)+ if err != nil {+ logger.FromContext(c).WithError(err).Error("invalid source path for add resource from flow")+ response.Error(c, response.ErrFlowFilesInvalidData, err)+ return+ }++ if _, statErr := os.Lstat(absPath); statErr != nil {+ if os.IsNotExist(statErr) {+ response.Error(c, response.ErrFlowFilesNotFound, statErr)+ return+ }+ logger.FromContext(c).WithError(statErr).Error("error stating flow file")+ response.Error(c, response.ErrInternal, statErr)+ return+ }++ destPath, err := resources.SanitizeResourcePath(req.Destination)+ if err != nil {+ logger.FromContext(c).WithError(err).Error("invalid destination path for add resource from flow")+ response.Error(c, response.ErrFlowFilesInvalidData, err)+ return+ }++ var existingRec models.UserResource+ existErr := s.db.Where("user_id = ? AND path = ?", uid, destPath).First(&existingRec).Error+ exists := existErr == nil+ if existErr != nil && !gorm.IsRecordNotFoundError(existErr) {+ logger.FromContext(c).WithError(existErr).Error("error checking resource existence")+ response.Error(c, response.ErrInternal, existErr)+ return+ }+ if exists && !req.Force {+ response.Error(c, response.ErrFlowFilesAlreadyExists, fmt.Errorf("resource already exists at %q; use force=true to overwrite", destPath))+ return+ }++ f, err := os.Open(absPath)+ if err != nil {+ logger.FromContext(c).WithError(err).Error("error opening flow file")+ response.Error(c, response.ErrInternal, err)+ return+ }+ tmpPath, hash, size, err := resources.SaveToTemp(f, resources.ResourcesDir(s.dataDir))+ f.Close()+ if err != nil {+ logger.FromContext(c).WithError(err).Error("error saving flow file to temp")+ response.Error(c, response.ErrInternal, err)+ return+ }++ if err := resources.CommitBlob(s.dataDir, hash, tmpPath); err != nil {+ logger.FromContext(c).WithError(err).Error("error committing blob for flow file")+ response.Error(c, response.ErrInternal, err)+ return+ }++ name := filepath.Base(destPath)++ if exists {+ oldHash := existingRec.Hash+ if err := s.db.Model(&existingRec).Updates(models.UserResource{+ Hash: hash,+ Name: name,+ Size: size,+ UpdatedAt: time.Now(),+ }).Error; err != nil {+ logger.FromContext(c).WithError(err).Error("error updating resource record")+ response.Error(c, response.ErrInternal, err)+ return+ }+ if s.db.Model(&models.UserResource{}).Where("hash = ?", oldHash).RecordNotFound() {+ os.Remove(resources.BlobPath(s.dataDir, oldHash))+ }+ entry := models.ResourceEntry{+ ID: int64(existingRec.ID),+ UserID: existingRec.UserID,+ Name: existingRec.Name,+ Path: existingRec.Path,+ Size: size,+ IsDir: false,+ CreatedAt: existingRec.CreatedAt,+ UpdatedAt: existingRec.UpdatedAt,+ }+ if s.ss != nil {+ s.ss.NewResourcePublisher(int64(uid)).ResourceUpdated(c.Request.Context(), convertResourceToModel(entry))+ }+ response.Success(c, http.StatusOK, entry)+ return+ }++ rec := models.UserResource{+ UserID: uid,+ Hash: hash,+ Name: name,+ Path: destPath,+ Size: size,+ IsDir: false,+ }+ if err := s.db.Create(&rec).Error; err != nil {+ logger.FromContext(c).WithError(err).Error("error inserting resource from flow")+ response.Error(c, response.ErrInternal, err)+ return+ }++ entry := models.ResourceEntry{+ ID: int64(rec.ID),+ UserID: rec.UserID,+ Name: rec.Name,+ Path: rec.Path,+ Size: rec.Size,+ IsDir: false,+ CreatedAt: rec.CreatedAt,+ UpdatedAt: rec.UpdatedAt,+ }+ if s.ss != nil {+ s.ss.NewResourcePublisher(int64(uid)).ResourceAdded(c.Request.Context(), convertResourceToModel(entry))+ }+ response.Success(c, http.StatusOK, entry)+}diff --git a/backend/pkg/server/services/flow_files_test.go b/backend/pkg/server/services/flow_files_test.goindex 429607e3..b624a0cc 100644--- a/backend/pkg/server/services/flow_files_test.go+++ b/backend/pkg/server/services/flow_files_test.go@@ -12,6 +12,7 @@ import ("time""pentagi/pkg/flowfiles"+ "pentagi/pkg/server/models""github.com/docker/docker/api/types/container""github.com/stretchr/testify/assert"@@ -90,6 +91,7 @@ func TestFlowFileService_Dirs(t *testing.T) {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))+ assert.Equal(t, "/data/flow-42-data/resources", flowfiles.FlowResourcesDir("/data", 42))}func TestMaxUploadFileSize(t *testing.T) {@@ -111,6 +113,7 @@ func TestResolveCachedPath(t *testing.T) {{"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},+ {"resources file", "resources/creds/passwords.txt", "/data/flow-1-data/resources/creds/passwords.txt", false},{"empty path", "", "", true},{"wrong prefix", "tmp/evil.sh", "", true},{"absolute path", "/etc/passwd", "", true},@@ -201,12 +204,15 @@ func TestFlowFileService_ListFlowFiles_BothSources(t *testing.T) {uploadsDir := filepath.Join(dataDir, "flow-7-data", "uploads")containerDir := filepath.Join(dataDir, "flow-7-data", "container")+ resourcesDir := filepath.Join(dataDir, "flow-7-data", "resources")require.NoError(t, os.MkdirAll(uploadsDir, 0755))require.NoError(t, os.MkdirAll(containerDir, 0755))+ require.NoError(t, os.MkdirAll(filepath.Join(resourcesDir, "creds"), 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))+ require.NoError(t, os.WriteFile(filepath.Join(resourcesDir, "creds", "passwords.txt"), []byte("secret"), 0644))files, err := svc.listFlowFiles(7)require.NoError(t, err)@@ -218,6 +224,8 @@ func TestFlowFileService_ListFlowFiles_BothSources(t *testing.T) {assert.Contains(t, paths, "uploads/wordlist.txt")assert.Contains(t, paths, "container/etc/nginx/conf")assert.Contains(t, paths, "container/etc/nginx/nginx.conf")+ assert.Contains(t, paths, "resources/creds")+ assert.Contains(t, paths, "resources/creds/passwords.txt")}func TestFlowFileService_ListFlowFiles_EmptyDirs(t *testing.T) {@@ -228,7 +236,7 @@ func TestFlowFileService_ListFlowFiles_EmptyDirs(t *testing.T) {}func TestConvertModelFlowFile_PreservesID(t *testing.T) {- file := flowFile{+ file := models.FlowFile{ID: "flow-file-id",Name: "report.md",Path: "uploads/report.md",@@ -473,7 +481,7 @@ func TestPrimaryContainerName(t *testing.T) {func TestSortFlowFiles(t *testing.T) {now := time.Now()- files := []flowFile{+ files := []models.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)},diff --git a/backend/pkg/server/services/flows.go b/backend/pkg/server/services/flows.goindex 3bfa12fe..6675cedc 100644--- a/backend/pkg/server/services/flows.go+++ b/backend/pkg/server/services/flows.go@@ -357,7 +357,14 @@ func (s *FlowService) CreateFlow(c *gin.Context) {}prvtype := prv.Type()- fw, err := s.fc.CreateFlow(c, int64(uid), createFlow.Input, prvname, prvtype, createFlow.Functions)+ dbResources, err := validateServiceResources(s.db, uid, privs, createFlow.ResourceIDs)+ if err != nil {+ logger.FromContext(c).WithError(err).Errorf("error validating resource ids")+ response.Error(c, response.ErrFlowsInvalidRequest, err)+ return+ }++ fw, err := s.fc.CreateFlow(c, int64(uid), createFlow.Input, prvname, prvtype, createFlow.Functions, dbResources)if err != nil {logger.FromContext(c).WithError(err).Errorf("error creating flow")response.Error(c, response.ErrInternal, err)@@ -478,7 +485,14 @@ func (s *FlowService) PatchFlow(c *gin.Context) {}}- if err := fw.PutInput(c, *patchFlow.Input, prv); err != nil {+ dbResources, err := validateServiceResources(s.db, uid, privs, patchFlow.ResourceIDs)+ if err != nil {+ logger.FromContext(c).WithError(err).Errorf("error validating resource ids")+ response.Error(c, response.ErrFlowsInvalidRequest, err)+ return+ }++ if err := fw.PutInput(c, *patchFlow.Input, prv, dbResources); err != nil {logger.FromContext(c).WithError(err).Errorf("error sending input to flow")response.Error(c, response.ErrInternal, err)returndiff --git a/backend/pkg/server/services/resources.go b/backend/pkg/server/services/resources.gonew file mode 100644index 00000000..040dfe63--- /dev/null+++ b/backend/pkg/server/services/resources.go@@ -0,0 +1,1516 @@+package services++import (+ "context"+ "errors"+ "fmt"+ "mime"+ "net/http"+ "os"+ "path"+ "slices"+ "strings"+ "time"++ "pentagi/pkg/graph/model"+ "pentagi/pkg/graph/subscriptions"+ "pentagi/pkg/resources"+ "pentagi/pkg/server/logger"+ "pentagi/pkg/server/models"+ "pentagi/pkg/server/response"++ "github.com/gin-gonic/gin"+ "github.com/jinzhu/gorm"+)++// ---- request/response types ------------------------------------------------++// pendingResourceUpload holds state for a single file in the upload pipeline.+type pendingResourceUpload struct {+ name string+ vPath string+ tmpPath string+ hash string+ size int64+ newBlob bool+}++// ---- service ---------------------------------------------------------------++// ResourceService manages user-owned resource files.+// Physical file content is stored as {DATA_DIR}/resources/{md5hash}.blob;+// all metadata (virtual path, name, size, …) lives in user_resources (PostgreSQL).+type ResourceService struct {+ dataDir string+ db *gorm.DB+ ss subscriptions.SubscriptionsController+}++func NewResourceService(+ db *gorm.DB,+ dataDir string,+ ss subscriptions.SubscriptionsController,+) *ResourceService {+ return &ResourceService{+ dataDir: dataDir,+ db: db,+ ss: ss,+ }+}++// ---- GET /resources/ -------------------------------------------------------++// ListResources returns a list of user-owned resources.+// @Summary List user resources+// @Tags Resources+// @Produce json+// @Security BearerAuth+// @Param path query string false "virtual directory path; empty for root"+// @Param recursive query bool false "list recursively (default false)"+// @Success 200 {object} response.successResp{data=models.ResourceList}+// @Failure 400 {object} response.errorResp+// @Failure 403 {object} response.errorResp+// @Failure 500 {object} response.errorResp+// @Router /resources/ [get]+func (s *ResourceService) ListResources(c *gin.Context) {+ uid := c.GetUint64("uid")+ privs := c.GetStringSlice("prm")+ isAdmin := slices.Contains(privs, "resources.admin")++ if !isAdmin && !slices.Contains(privs, "resources.view") {+ response.Error(c, response.ErrNotPermitted, nil)+ return+ }++ reqPath := strings.TrimSpace(c.Query("path"))+ recursive := c.Query("recursive") == "true" || c.Query("recursive") == "1"++ var dirPath string+ if reqPath != "" {+ var err error+ dirPath, err = resources.SanitizeResourcePath(reqPath)+ if err != nil {+ logger.FromContext(c).WithError(err).Error("invalid path for list resources")+ response.Error(c, response.ErrResourcesInvalidRequest, err)+ return+ }+ }++ items, err := s.queryResources(uid, isAdmin, dirPath, recursive)+ if err != nil {+ logger.FromContext(c).WithError(err).Error("error listing resources")+ response.Error(c, response.ErrInternal, err)+ return+ }++ response.Success(c, http.StatusOK, models.ResourceList{Items: items, Total: uint64(len(items))})+}++// ---- POST /resources/ ------------------------------------------------------++// UploadResources uploads one or more files into the user's resource storage.+// @Summary Upload files to resource storage+// @Tags Resources+// @Accept mpfd+// @Produce json+// @Security BearerAuth+// @Param dir query string false "target virtual directory path; empty or omitted means root"+// @Param files formData file true "files to upload (field name: files or file)"+// @Success 200 {object} response.successResp{data=models.ResourceList}+// @Failure 400 {object} response.errorResp+// @Failure 403 {object} response.errorResp+// @Failure 409 {object} response.errorResp+// @Failure 500 {object} response.errorResp+// @Router /resources/ [post]+func (s *ResourceService) UploadResources(c *gin.Context) {+ uid := c.GetUint64("uid")+ privs := c.GetStringSlice("prm")++ if !slices.Contains(privs, "resources.upload") && !slices.Contains(privs, "resources.admin") {+ response.Error(c, response.ErrNotPermitted, nil)+ return+ }++ dirRaw := strings.TrimSpace(c.Query("dir"))+ dirPath, err := resources.SanitizeResourceDir(dirRaw)+ if err != nil {+ logger.FromContext(c).WithError(err).Error("invalid upload target directory")+ response.Error(c, response.ErrResourcesInvalidRequest, err)+ return+ }++ c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, resources.MaxUploadRequestSize)+ multipartForm, err := c.MultipartForm()+ if err != nil {+ logger.FromContext(c).WithError(err).Error("error reading multipart form for resources upload")+ response.Error(c, response.ErrResourcesInvalidRequest, err)+ return+ }++ fileHeaders := multipartForm.File["files"]+ if len(fileHeaders) == 0 {+ if fh, ferr := c.FormFile("file"); ferr == nil && fh != nil {+ fileHeaders = append(fileHeaders, fh)+ }+ }+ if len(fileHeaders) == 0 {+ response.Error(c, response.ErrResourcesInvalidRequest, errors.New("at least one file is required"))+ return+ }+ if len(fileHeaders) > resources.MaxUploadFiles {+ response.Error(c, response.ErrResourcesInvalidRequest,+ fmt.Errorf("too many files: %d exceeds the limit of %d", len(fileHeaders), resources.MaxUploadFiles))+ return+ }++ if err := resources.EnsureResourcesDir(s.dataDir); err != nil {+ logger.FromContext(c).WithError(err).Error("failed to ensure resources directory")+ response.Error(c, response.ErrInternal, err)+ return+ }+ blobsDir := resources.ResourcesDir(s.dataDir)++ var totalSize int64+ pendingList := make([]pendingResourceUpload, 0, len(fileHeaders))+ seenPaths := make(map[string]struct{}, len(fileHeaders))++ // Phase 1: validate, stream to tmp, compute MD5.+ for _, fh := range fileHeaders {+ name, err := resources.SanitizeResourceFileName(fh.Filename)+ if err != nil {+ cleanupResourceUploads(pendingList)+ response.Error(c, response.ErrResourcesInvalidData, err)+ return+ }++ if fh.Size > resources.MaxUploadFileSize {+ cleanupResourceUploads(pendingList)+ response.Error(c, response.ErrResourcesInvalidRequest,+ fmt.Errorf("file %q size %d bytes exceeds the limit of %d bytes", name, fh.Size, resources.MaxUploadFileSize))+ return+ }+ if fh.Size < 0 {+ cleanupResourceUploads(pendingList)+ response.Error(c, response.ErrResourcesInvalidRequest,+ fmt.Errorf("file %q has invalid size %d", name, fh.Size))+ return+ }+ totalSize += fh.Size+ if totalSize > resources.MaxUploadTotalSize {+ cleanupResourceUploads(pendingList)+ response.Error(c, response.ErrResourcesInvalidRequest,+ fmt.Errorf("total upload size exceeds the limit of %d bytes", resources.MaxUploadTotalSize))+ return+ }++ vPath := resources.FilePath(dirPath, name)+ if _, ok := seenPaths[vPath]; ok {+ cleanupResourceUploads(pendingList)+ response.Error(c, response.ErrResourcesAlreadyExists,+ fmt.Errorf("resource %q is duplicated in upload request", vPath))+ return+ }+ seenPaths[vPath] = struct{}{}++ exists, err := s.resourceExists(uid, vPath)+ if err != nil {+ cleanupResourceUploads(pendingList)+ logger.FromContext(c).WithError(err).Error("error checking resource existence")+ response.Error(c, response.ErrInternal, err)+ return+ }+ if exists {+ cleanupResourceUploads(pendingList)+ response.Error(c, response.ErrResourcesAlreadyExists,+ fmt.Errorf("resource %q already exists", vPath))+ return+ }++ src, openErr := fh.Open()+ if openErr != nil {+ cleanupResourceUploads(pendingList)+ response.Error(c, response.ErrInternal, fmt.Errorf("failed to open uploaded file: %w", openErr))+ return+ }+ tmpPath, hash, size, saveErr := resources.SaveToTemp(src, blobsDir)+ src.Close()+ if saveErr != nil {+ cleanupResourceUploads(pendingList)+ response.Error(c, response.ErrInternal, saveErr)+ return+ }++ pendingList = append(pendingList, pendingResourceUpload{+ name: name,+ vPath: vPath,+ tmpPath: tmpPath,+ hash: hash,+ size: size,+ })+ }++ // Phase 2: commit blobs (atomic rename; safe against duplicate hashes).+ for i := range pendingList {+ p := &pendingList[i]+ blobAlreadyExisted, err := resources.BlobExists(s.dataDir, p.hash)+ if err != nil {+ cleanupResourceUploads(pendingList)+ response.Error(c, response.ErrInternal, err)+ return+ }+ if err := resources.CommitBlob(s.dataDir, p.hash, p.tmpPath); err != nil {+ cleanupResourceUploads(pendingList)+ response.Error(c, response.ErrInternal, err)+ return+ }+ p.tmpPath = ""+ p.newBlob = !blobAlreadyExisted+ }++ // Phase 3: insert DB records in a transaction.+ tx := s.db.Begin()+ if tx.Error != nil {+ for _, p := range pendingList {+ if p.newBlob {+ s.deleteOrphanBlob(context.Background(), p.hash)+ }+ }+ logger.FromContext(c).WithError(tx.Error).Error("failed to begin transaction for upload")+ response.Error(c, response.ErrInternal, tx.Error)+ return+ }++ var saved []models.UserResource+ var createdDirs []models.UserResource+ var txErr error+ if dirPath != "" {+ createdDirs, txErr = ensureResourceDirs(tx, uid, dirPath)+ }+ for _, p := range pendingList {+ if txErr != nil {+ break+ }+ rec := models.UserResource{+ UserID: uid,+ Hash: p.hash,+ Name: p.name,+ Path: p.vPath,+ Size: p.size,+ IsDir: false,+ }+ if err := tx.Create(&rec).Error; err != nil {+ txErr = fmt.Errorf("failed to insert resource %q: %w", p.vPath, err)+ break+ }+ saved = append(saved, rec)+ }++ if txErr != nil {+ tx.Rollback()+ for _, p := range pendingList {+ if p.newBlob {+ s.deleteOrphanBlob(context.Background(), p.hash)+ }+ }+ if isUniqueViolation(txErr) {+ response.Error(c, response.ErrResourcesAlreadyExists, txErr)+ } else if errors.Is(txErr, errResourceConflict) {+ response.Error(c, response.ErrResourcesAlreadyExists, txErr)+ } else {+ logger.FromContext(c).WithError(txErr).Error("failed to persist uploaded resources")+ response.Error(c, response.ErrInternal, txErr)+ }+ return+ }+ if err := tx.Commit().Error; err != nil {+ tx.Rollback()+ for _, p := range pendingList {+ if p.newBlob {+ s.deleteOrphanBlob(context.Background(), p.hash)+ }+ }+ logger.FromContext(c).WithError(err).Error("failed to commit upload transaction")+ response.Error(c, response.ErrInternal, err)+ return+ }++ entries := convertResources(saved)+ s.publishResourcesAdded(c.Request.Context(), uid, convertResources(createdDirs))+ s.publishResourcesAdded(c.Request.Context(), uid, entries)+ response.Success(c, http.StatusOK, models.ResourceList{Items: entries, Total: uint64(len(entries))})+}++// ---- POST /resources/mkdir -------------------------------------------------++// MkdirResource creates a virtual directory entry (idempotent).+// @Summary Create a virtual directory+// @Tags Resources+// @Accept json+// @Produce json+// @Security BearerAuth+// @Param request body models.MkdirResourceRequest true "mkdir request"+// @Success 200 {object} response.successResp{data=models.ResourceEntry}+// @Failure 400 {object} response.errorResp+// @Failure 403 {object} response.errorResp+// @Failure 500 {object} response.errorResp+// @Router /resources/mkdir [post]+func (s *ResourceService) MkdirResource(c *gin.Context) {+ uid := c.GetUint64("uid")+ privs := c.GetStringSlice("prm")++ if !slices.Contains(privs, "resources.edit") && !slices.Contains(privs, "resources.admin") {+ response.Error(c, response.ErrNotPermitted, nil)+ return+ }++ var req models.MkdirResourceRequest+ if err := c.ShouldBindJSON(&req); err != nil {+ response.Error(c, response.ErrResourcesInvalidRequest, err)+ return+ }++ dirPath, err := resources.SanitizeResourcePath(req.Path)+ if err != nil {+ response.Error(c, response.ErrResourcesInvalidRequest, err)+ return+ }++ // Idempotent — if already exists as a directory, return it.+ var existing models.UserResource+ err = s.db.Where("user_id = ? AND path = ?", uid, dirPath).First(&existing).Error+ if err == nil {+ if !existing.IsDir {+ response.Error(c, response.ErrResourcesAlreadyExists,+ fmt.Errorf("a file already exists at path %q", dirPath))+ return+ }+ response.Success(c, http.StatusOK, convertResource(existing))+ return+ }+ if !gorm.IsRecordNotFoundError(err) {+ logger.FromContext(c).WithError(err).Error("error checking resource for mkdir")+ response.Error(c, response.ErrInternal, err)+ return+ }++ rec := models.UserResource{+ UserID: uid,+ Hash: "",+ Name: path.Base(dirPath),+ Path: dirPath,+ Size: 0,+ IsDir: true,+ }+ if err := s.db.Create(&rec).Error; err != nil {+ if isUniqueViolation(err) {+ // Race: another request created it — re-fetch and return.+ if refetchErr := s.db.Where("user_id = ? AND path = ?", uid, dirPath).First(&rec).Error; refetchErr == nil {+ response.Success(c, http.StatusOK, convertResource(rec))+ return+ }+ }+ logger.FromContext(c).WithError(err).Error("error creating resource directory")+ response.Error(c, response.ErrInternal, err)+ return+ }++ entry := convertResource(rec)+ s.publishResourceAdded(c.Request.Context(), uid, entry)+ response.Success(c, http.StatusOK, entry)+}++// ---- PUT /resources/move ---------------------------------------------------++// MoveResource renames or moves a file or directory.+// @Summary Move or rename a resource (file or directory)+// @Tags Resources+// @Accept json+// @Produce json+// @Security BearerAuth+// @Param request body models.MoveResourceRequest true "move request"+// @Success 200 {object} response.successResp{data=models.ResourceList}+// @Failure 400 {object} response.errorResp+// @Failure 403 {object} response.errorResp+// @Failure 404 {object} response.errorResp+// @Failure 409 {object} response.errorResp+// @Failure 500 {object} response.errorResp+// @Router /resources/move [put]+func (s *ResourceService) MoveResource(c *gin.Context) {+ uid := c.GetUint64("uid")+ privs := c.GetStringSlice("prm")++ if !slices.Contains(privs, "resources.edit") && !slices.Contains(privs, "resources.admin") {+ response.Error(c, response.ErrNotPermitted, nil)+ return+ }++ var req models.MoveResourceRequest+ if err := c.ShouldBindJSON(&req); err != nil {+ response.Error(c, response.ErrResourcesInvalidRequest, err)+ return+ }++ srcPath, err := resources.SanitizeResourcePath(req.Source)+ if err != nil {+ response.Error(c, response.ErrResourcesInvalidRequest, fmt.Errorf("invalid source: %w", err))+ return+ }+ dstPath, err := resources.SanitizeResourcePath(req.Destination)+ if err != nil {+ response.Error(c, response.ErrResourcesInvalidRequest, fmt.Errorf("invalid destination: %w", err))+ return+ }+ if srcPath == dstPath {+ response.Error(c, response.ErrResourcesInvalidRequest, errors.New("source and destination are the same"))+ return+ }++ var src models.UserResource+ if err := s.db.Where("user_id = ? AND path = ?", uid, srcPath).First(&src).Error; err != nil {+ if gorm.IsRecordNotFoundError(err) {+ response.Error(c, response.ErrResourcesNotFound, fmt.Errorf("resource %q not found", srcPath))+ return+ }+ logger.FromContext(c).WithError(err).Error("error finding source resource for move")+ response.Error(c, response.ErrInternal, err)+ return+ }++ result, moveErr := s.moveResource(uid, src, srcPath, dstPath, req.Force)+ if moveErr != nil {+ switch {+ case errors.Is(moveErr, errResourceInvalid):+ response.Error(c, response.ErrResourcesInvalidRequest, moveErr)+ case errors.Is(moveErr, errResourceConflict):+ response.Error(c, response.ErrResourcesConflict,+ fmt.Errorf("destination %q already exists; move items individually", dstPath))+ case errors.Is(moveErr, errResourceNotFound):+ response.Error(c, response.ErrResourcesNotFound, fmt.Errorf("resource %q not found", srcPath))+ default:+ logger.FromContext(c).WithError(moveErr).Error("error moving resource")+ response.Error(c, response.ErrInternal, moveErr)+ }+ return+ }++ s.cleanupOrphanBlobs(c.Request.Context(), result.OrphanHashes)+ s.publishResourcesDeleted(c.Request.Context(), uid, result.DeletedBefore)+ s.publishResourcesUpdated(c.Request.Context(), uid, result.Updated)+ s.publishResourcesDeleted(c.Request.Context(), uid, result.DeletedAfter)+ response.Success(c, http.StatusOK, models.ResourceList{Items: result.Updated, Total: uint64(len(result.Updated))})+}++var errResourceConflict = errors.New("resource conflict")+var errResourceNotFound = errors.New("resource not found")+var errResourceInvalid = errors.New("invalid resource operation")++type moveResourceResult struct {+ Updated []models.ResourceEntry+ DeletedBefore []models.ResourceEntry+ DeletedAfter []models.ResourceEntry+ OrphanHashes []string+}++func (s *ResourceService) moveResource(+ uid uint64,+ src models.UserResource,+ srcPath, dstPath string,+ force bool,+) (moveResourceResult, error) {+ tx := s.db.Begin()+ if tx.Error != nil {+ return moveResourceResult{}, tx.Error+ }++ if !src.IsDir {+ result, err := s.moveFileResource(tx, uid, src, dstPath, force)+ if err != nil {+ tx.Rollback()+ return moveResourceResult{}, err+ }+ if err := tx.Commit().Error; err != nil {+ tx.Rollback()+ return moveResourceResult{}, err+ }+ return result, nil+ }++ result, err := s.moveDirResource(tx, uid, srcPath, dstPath, force)+ if err != nil {+ tx.Rollback()+ return moveResourceResult{}, err+ }+ if err := tx.Commit().Error; err != nil {+ tx.Rollback()+ return moveResourceResult{}, err+ }+ return result, nil+}++func (s *ResourceService) moveFileResource(+ tx *gorm.DB,+ uid uint64,+ src models.UserResource,+ dstPath string,+ force bool,+) (moveResourceResult, error) {+ result := moveResourceResult{}+ targetPath := dstPath++ dest, exists, err := findResourceByPath(tx, uid, dstPath)+ if err != nil {+ return result, err+ }+ if exists && dest.IsDir {+ targetPath = resources.FilePath(dstPath, src.Name)+ dest, exists, err = findResourceByPath(tx, uid, targetPath)+ if err != nil {+ return result, err+ }+ }++ if exists {+ if dest.IsDir {+ return result, errResourceConflict+ }+ if !force {+ return result, errResourceConflict+ }+ if err := tx.Delete(&dest).Error; err != nil {+ return result, fmt.Errorf("failed to delete destination for overwrite: %w", err)+ }+ result.DeletedBefore = append(result.DeletedBefore, convertResource(dest))+ if dest.Hash != "" {+ result.OrphanHashes = append(result.OrphanHashes, dest.Hash)+ }+ }++ updated, err := updateMovedResource(tx, src, targetPath, time.Now())+ if err != nil {+ return result, err+ }+ result.Updated = append(result.Updated, convertResource(updated))+ return result, nil+}++func (s *ResourceService) moveDirResource(+ tx *gorm.DB,+ uid uint64,+ srcPath, dstPath string,+ force bool,+) (moveResourceResult, error) {+ result := moveResourceResult{}+ if resources.PathHasPrefix(dstPath, srcPath) {+ return result, fmt.Errorf("%w: cannot move directory into itself", errResourceInvalid)+ }++ dest, destExists, err := findResourceByPath(tx, uid, dstPath)+ if err != nil {+ return result, err+ }+ if destExists && !dest.IsDir {+ return result, errResourceConflict+ }+ if destExists && !force {+ return result, errResourceConflict+ }++ entries, err := listResourceTree(tx, uid, srcPath)+ if err != nil {+ return result, err+ }++ now := time.Now()+ if !destExists {+ return moveDirResourceToAbsentDestination(tx, uid, entries, srcPath, dstPath, force, now)+ }+ return moveDirResourceMerge(tx, uid, entries, srcPath, dstPath, now)+}++func moveDirResourceToAbsentDestination(+ tx *gorm.DB,+ uid uint64,+ entries []models.UserResource,+ srcPath, dstPath string,+ force bool,+ now time.Time,+) (moveResourceResult, error) {+ result := moveResourceResult{}+ newPaths := make([]string, 0, len(entries))+ for _, entry := range entries {+ newPaths = append(newPaths, resources.ReplacePrefixPath(entry.Path, srcPath, dstPath))+ }++ existing, err := findResourcesByPaths(tx, uid, newPaths)+ if err != nil {+ return result, err+ }+ existingByPath := resourcesByPath(existing)+ if len(existingByPath) > 0 && !force {+ return result, errResourceConflict+ }++ for i, entry := range entries {+ newPath := newPaths[i]+ if dest, ok := existingByPath[newPath]; ok {+ if dest.IsDir != entry.IsDir {+ return result, errResourceConflict+ }+ if err := tx.Delete(&dest).Error; err != nil {+ return result, fmt.Errorf("failed to delete destination for overwrite: %w", err)+ }+ result.DeletedBefore = append(result.DeletedBefore, convertResource(dest))+ if dest.Hash != "" {+ result.OrphanHashes = append(result.OrphanHashes, dest.Hash)+ }+ }+ updated, err := updateMovedResource(tx, entry, newPath, now)+ if err != nil {+ return result, err+ }+ result.Updated = append(result.Updated, convertResource(updated))+ }++ return result, nil+}++func moveDirResourceMerge(+ tx *gorm.DB,+ uid uint64,+ entries []models.UserResource,+ srcPath, dstPath string,+ now time.Time,+) (moveResourceResult, error) {+ result := moveResourceResult{}+ mappedPaths := make([]string, 0, len(entries))++ for _, entry := range entries {+ if entry.Path == srcPath {+ continue+ }+ rel := strings.TrimPrefix(entry.Path, srcPath+"/")+ newPath := resources.FilePath(dstPath, rel)+ mappedPaths = append(mappedPaths, newPath)+ }++ existing, err := findResourcesByPaths(tx, uid, mappedPaths)+ if err != nil {+ return result, err+ }+ existingByPath := resourcesByPath(existing)++ var sourceRoot *models.UserResource+ var sourceDirsToDelete []models.UserResource+ for _, entry := range entries {+ if entry.Path == srcPath {+ entryCopy := entry+ sourceRoot = &entryCopy+ continue+ }++ rel := strings.TrimPrefix(entry.Path, srcPath+"/")+ newPath := resources.FilePath(dstPath, rel)+ if dest, ok := existingByPath[newPath]; ok {+ if dest.IsDir != entry.IsDir {+ return result, errResourceConflict+ }+ if entry.IsDir {+ sourceDirsToDelete = append(sourceDirsToDelete, entry)+ continue+ }+ if err := tx.Delete(&dest).Error; err != nil {+ return result, fmt.Errorf("failed to delete destination for overwrite: %w", err)+ }+ result.DeletedBefore = append(result.DeletedBefore, convertResource(dest))+ if dest.Hash != "" {+ result.OrphanHashes = append(result.OrphanHashes, dest.Hash)+ }+ }++ updated, err := updateMovedResource(tx, entry, newPath, now)+ if err != nil {+ return result, err+ }+ result.Updated = append(result.Updated, convertResource(updated))+ }++ for _, dir := range sourceDirsToDelete {+ if err := tx.Delete(&dir).Error; err != nil {+ return result, fmt.Errorf("failed to delete merged source directory %q: %w", dir.Path, err)+ }+ result.DeletedAfter = append(result.DeletedAfter, convertResource(dir))+ }+ if sourceRoot != nil {+ if err := tx.Delete(sourceRoot).Error; err != nil {+ return result, fmt.Errorf("failed to delete source directory %q: %w", sourceRoot.Path, err)+ }+ result.DeletedAfter = append(result.DeletedAfter, convertResource(*sourceRoot))+ }++ return result, nil+}++func listResourceTree(tx *gorm.DB, uid uint64, rootPath string) ([]models.UserResource, error) {+ escapedRoot := resources.EscapeLike(rootPath)+ var entries []models.UserResource+ if err := tx.Where(+ "user_id = ? AND (path = ? OR path LIKE ?)",+ uid, rootPath, escapedRoot+"/%",+ ).Order("path ASC").Find(&entries).Error; err != nil {+ return nil, fmt.Errorf("failed to list source directory: %w", err)+ }+ return entries, nil+}++func findResourceByPath(tx *gorm.DB, uid uint64, resourcePath string) (models.UserResource, bool, error) {+ var rec models.UserResource+ err := tx.Where("user_id = ? AND path = ?", uid, resourcePath).First(&rec).Error+ if err == nil {+ return rec, true, nil+ }+ if gorm.IsRecordNotFoundError(err) {+ return models.UserResource{}, false, nil+ }+ return models.UserResource{}, false, err+}++func findResourcesByPaths(tx *gorm.DB, uid uint64, paths []string) ([]models.UserResource, error) {+ if len(paths) == 0 {+ return nil, nil+ }++ var recs []models.UserResource+ if err := tx.Where("user_id = ? AND path IN (?)", uid, paths).Find(&recs).Error; err != nil {+ return nil, err+ }+ return recs, nil+}++func resourcesByPath(recs []models.UserResource) map[string]models.UserResource {+ byPath := make(map[string]models.UserResource, len(recs))+ for _, rec := range recs {+ byPath[rec.Path] = rec+ }+ return byPath+}++func updateMovedResource(tx *gorm.DB, rec models.UserResource, newPath string, now time.Time) (models.UserResource, error) {+ if err := tx.Model(&models.UserResource{}).+ Where("id = ?", rec.ID).+ Updates(map[string]interface{}{+ "path": newPath,+ "name": path.Base(newPath),+ "updated_at": now,+ }).Error; err != nil {+ return models.UserResource{}, fmt.Errorf("failed to move resource %q: %w", rec.Path, err)+ }+ rec.Path = newPath+ rec.Name = path.Base(newPath)+ rec.UpdatedAt = now+ return rec, nil+}++// ---- POST /resources/copy --------------------------------------------------++// CopyResource copies a file or directory to a new path.+// @Summary Copy a resource (file or directory)+// @Tags Resources+// @Accept json+// @Produce json+// @Security BearerAuth+// @Param request body models.CopyResourceRequest true "copy request"+// @Success 200 {object} response.successResp{data=models.ResourceList}+// @Failure 400 {object} response.errorResp+// @Failure 403 {object} response.errorResp+// @Failure 404 {object} response.errorResp+// @Failure 409 {object} response.errorResp+// @Failure 500 {object} response.errorResp+// @Router /resources/copy [post]+func (s *ResourceService) CopyResource(c *gin.Context) {+ uid := c.GetUint64("uid")+ privs := c.GetStringSlice("prm")++ if !slices.Contains(privs, "resources.edit") && !slices.Contains(privs, "resources.admin") {+ response.Error(c, response.ErrNotPermitted, nil)+ return+ }++ var req models.CopyResourceRequest+ if err := c.ShouldBindJSON(&req); err != nil {+ response.Error(c, response.ErrResourcesInvalidRequest, err)+ return+ }++ srcPath, err := resources.SanitizeResourcePath(req.Source)+ if err != nil {+ response.Error(c, response.ErrResourcesInvalidRequest, fmt.Errorf("invalid source: %w", err))+ return+ }+ dstPath, err := resources.SanitizeResourcePath(req.Destination)+ if err != nil {+ response.Error(c, response.ErrResourcesInvalidRequest, fmt.Errorf("invalid destination: %w", err))+ return+ }+ if srcPath == dstPath {+ response.Error(c, response.ErrResourcesInvalidRequest, errors.New("source and destination are the same"))+ return+ }++ var src models.UserResource+ if err := s.db.Where("user_id = ? AND path = ?", uid, srcPath).First(&src).Error; err != nil {+ if gorm.IsRecordNotFoundError(err) {+ response.Error(c, response.ErrResourcesNotFound, fmt.Errorf("resource %q not found", srcPath))+ return+ }+ logger.FromContext(c).WithError(err).Error("error finding source resource for copy")+ response.Error(c, response.ErrInternal, err)+ return+ }++ result, copyErr := s.copyResource(uid, src, srcPath, dstPath, req.Force)+ if copyErr != nil {+ switch {+ case errors.Is(copyErr, errResourceInvalid):+ response.Error(c, response.ErrResourcesInvalidRequest, copyErr)+ case errors.Is(copyErr, errResourceConflict):+ response.Error(c, response.ErrResourcesConflict,+ fmt.Errorf("destination already exists; use force=true to merge/overwrite"))+ default:+ logger.FromContext(c).WithError(copyErr).Error("error copying resource")+ response.Error(c, response.ErrInternal, copyErr)+ }+ return+ }++ // Orphan-check for overwritten blobs (after TX committed).+ s.cleanupOrphanBlobs(c.Request.Context(), result.OrphanHashes)++ s.publishResourcesDeleted(c.Request.Context(), uid, result.Deleted)+ s.publishResourcesAdded(c.Request.Context(), uid, result.Added)+ s.publishResourcesUpdated(c.Request.Context(), uid, result.Updated)++ all := append(result.Added, result.Updated...)+ response.Success(c, http.StatusOK, models.ResourceList{Items: all, Total: uint64(len(all))})+}++type copyResourceResult struct {+ Added []models.ResourceEntry+ Updated []models.ResourceEntry+ Deleted []models.ResourceEntry+ OrphanHashes []string+}++func (s *ResourceService) copyResource(+ uid uint64,+ src models.UserResource,+ srcPath, dstPath string,+ force bool,+) (copyResourceResult, error) {+ tx := s.db.Begin()+ if tx.Error != nil {+ return copyResourceResult{}, tx.Error+ }++ if !src.IsDir {+ result, err := s.copyFileResource(tx, uid, src, dstPath, force)+ if err != nil {+ tx.Rollback()+ return copyResourceResult{}, err+ }+ if err := tx.Commit().Error; err != nil {+ tx.Rollback()+ return copyResourceResult{}, err+ }+ return result, nil+ }++ result, err := s.copyDirResource(tx, uid, srcPath, dstPath, force)+ if err != nil {+ tx.Rollback()+ return copyResourceResult{}, err+ }+ if err := tx.Commit().Error; err != nil {+ tx.Rollback()+ return copyResourceResult{}, err+ }+ return result, nil+}++func (s *ResourceService) copyFileResource(+ tx *gorm.DB,+ uid uint64,+ src models.UserResource,+ dstPath string,+ force bool,+) (copyResourceResult, error) {+ result := copyResourceResult{}+ targetPath := dstPath++ dest, exists, err := findResourceByPath(tx, uid, dstPath)+ if err != nil {+ return result, err+ }+ if exists && dest.IsDir {+ targetPath = resources.FilePath(dstPath, src.Name)+ dest, exists, err = findResourceByPath(tx, uid, targetPath)+ if err != nil {+ return result, err+ }+ }++ if exists {+ if dest.IsDir {+ return result, errResourceConflict+ }+ if !force {+ return result, errResourceConflict+ }+ if err := tx.Delete(&dest).Error; err != nil {+ return result, fmt.Errorf("failed to delete destination for overwrite: %w", err)+ }+ result.Deleted = append(result.Deleted, convertResource(dest))+ if dest.Hash != "" {+ result.OrphanHashes = append(result.OrphanHashes, dest.Hash)+ }+ }++ newRec := models.UserResource{+ UserID: uid,+ Hash: src.Hash,+ Name: path.Base(targetPath),+ Path: targetPath,+ Size: src.Size,+ IsDir: false,+ }+ if err := tx.Create(&newRec).Error; err != nil {+ return result, fmt.Errorf("failed to copy resource: %w", err)+ }++ entry := convertResource(newRec)+ if exists {+ result.Updated = append(result.Updated, entry)+ } else {+ result.Added = append(result.Added, entry)+ }+ return result, nil+}++func (s *ResourceService) copyDirResource(+ tx *gorm.DB,+ uid uint64,+ srcPath, dstPath string,+ force bool,+) (copyResourceResult, error) {+ result := copyResourceResult{}+ if resources.PathHasPrefix(dstPath, srcPath) {+ return result, fmt.Errorf("%w: cannot copy directory into itself", errResourceInvalid)+ }++ dest, destExists, err := findResourceByPath(tx, uid, dstPath)+ if err != nil {+ return result, err+ }+ if destExists && !dest.IsDir {+ return result, errResourceConflict+ }+ if destExists && !force {+ return result, errResourceConflict+ }++ srcEntries, err := listResourceTree(tx, uid, srcPath)+ if err != nil {+ return result, err+ }++ newPaths := make([]string, 0, len(srcEntries))+ sourceByNewPath := make(map[string]models.UserResource, len(srcEntries))+ newPathBySourcePath := make(map[string]string, len(srcEntries))+ for _, e := range srcEntries {+ newPath := resources.ReplacePrefixPath(e.Path, srcPath, dstPath)+ if destExists {+ if e.Path == srcPath {+ continue+ }+ rel := strings.TrimPrefix(e.Path, srcPath+"/")+ newPath = resources.FilePath(dstPath, rel)+ }+ newPaths = append(newPaths, newPath)+ sourceByNewPath[newPath] = e+ newPathBySourcePath[e.Path] = newPath+ }++ existing, err := findResourcesByPaths(tx, uid, newPaths)+ if err != nil {+ return result, fmt.Errorf("failed to check destination conflicts: %w", err)+ }+ if len(existing) > 0 && !force {+ return result, errResourceConflict+ }++ existingSet := make(map[string]models.UserResource, len(existing))+ for _, e := range existing {+ srcEntry := sourceByNewPath[e.Path]+ if e.IsDir != srcEntry.IsDir {+ return result, errResourceConflict+ }+ existingSet[e.Path] = e+ }++ for _, e := range srcEntries {+ if destExists && e.Path == srcPath {+ continue+ }+ newPath := newPathBySourcePath[e.Path]+ if dest, wasExisting := existingSet[newPath]; wasExisting {+ if dest.IsDir {+ result.Updated = append(result.Updated, convertResource(dest))+ continue+ }+ if err := tx.Delete(&dest).Error; err != nil {+ return result, fmt.Errorf("failed to delete destination for overwrite: %w", err)+ }+ result.Deleted = append(result.Deleted, convertResource(dest))+ if dest.Hash != "" {+ result.OrphanHashes = append(result.OrphanHashes, dest.Hash)+ }+ }++ newRec := models.UserResource{+ UserID: uid,+ Hash: e.Hash,+ Name: path.Base(newPath),+ Path: newPath,+ Size: e.Size,+ IsDir: e.IsDir,+ }+ if err := tx.Create(&newRec).Error; err != nil {+ return result, fmt.Errorf("failed to copy resource %q: %w", e.Path, err)+ }+ entry := convertResource(newRec)+ if _, wasExisting := existingSet[newPath]; wasExisting {+ result.Updated = append(result.Updated, entry)+ } else {+ result.Added = append(result.Added, entry)+ }+ }++ return result, nil+}++// ---- DELETE /resources/ ----------------------------------------------------++// DeleteResource deletes a file or directory (recursively) by virtual path.+// @Summary Delete a resource (file or directory)+// @Tags Resources+// @Produce json+// @Security BearerAuth+// @Param path query string true "virtual path to delete"+// @Success 200 {object} response.successResp{data=models.ResourceList}+// @Failure 400 {object} response.errorResp+// @Failure 403 {object} response.errorResp+// @Failure 404 {object} response.errorResp+// @Failure 500 {object} response.errorResp+// @Router /resources/ [delete]+func (s *ResourceService) DeleteResource(c *gin.Context) {+ uid := c.GetUint64("uid")+ privs := c.GetStringSlice("prm")++ if !slices.Contains(privs, "resources.delete") && !slices.Contains(privs, "resources.admin") {+ response.Error(c, response.ErrNotPermitted, nil)+ return+ }++ reqPath := strings.TrimSpace(c.Query("path"))+ if reqPath == "" {+ response.Error(c, response.ErrResourcesInvalidRequest, errors.New("path query parameter is required"))+ return+ }+ targetPath, err := resources.SanitizeResourcePath(reqPath)+ if err != nil {+ response.Error(c, response.ErrResourcesInvalidRequest, err)+ return+ }++ // Verify target exists and belongs to user.+ var root models.UserResource+ if err := s.db.Where("user_id = ? AND path = ?", uid, targetPath).First(&root).Error; err != nil {+ if gorm.IsRecordNotFoundError(err) {+ response.Error(c, response.ErrResourcesNotFound, fmt.Errorf("resource %q not found", targetPath))+ return+ }+ logger.FromContext(c).WithError(err).Error("error finding resource for delete")+ response.Error(c, response.ErrInternal, err)+ return+ }++ escapedTarget := resources.EscapeLike(targetPath)++ var toDelete []models.UserResource+ if err := s.db.Where(+ "user_id = ? AND (path = ? OR path LIKE ?)",+ uid, targetPath, escapedTarget+"/%",+ ).Find(&toDelete).Error; err != nil {+ logger.FromContext(c).WithError(err).Error("error listing resources for delete")+ response.Error(c, response.ErrInternal, err)+ return+ }++ hashSet := make(map[string]struct{})+ ids := make([]uint64, 0, len(toDelete))+ deleted := make([]models.ResourceEntry, 0, len(toDelete))+ for _, rec := range toDelete {+ ids = append(ids, rec.ID)+ deleted = append(deleted, convertResource(rec))+ if !rec.IsDir && rec.Hash != "" {+ hashSet[rec.Hash] = struct{}{}+ }+ }++ if len(ids) == 0 {+ response.Success(c, http.StatusOK, models.ResourceList{})+ return+ }++ if err := s.db.Where("id IN (?)", ids).Delete(&models.UserResource{}).Error; err != nil {+ logger.FromContext(c).WithError(err).Error("error deleting resources")+ response.Error(c, response.ErrInternal, err)+ return+ }++ if len(hashSet) > 0 {+ hashes := make([]string, 0, len(hashSet))+ for h := range hashSet {+ hashes = append(hashes, h)+ }+ s.cleanupOrphanBlobs(c.Request.Context(), hashes)+ }++ s.publishResourcesDeleted(c.Request.Context(), uid, deleted)+ response.Success(c, http.StatusOK, models.ResourceList{Items: deleted, Total: uint64(len(deleted))})+}++// ---- GET /resources/download -----------------------------------------------++// DownloadResource downloads a single file or a directory as a ZIP archive.+// @Summary Download a resource+// @Tags Resources+// @Produce application/octet-stream+// @Security BearerAuth+// @Param path query string true "virtual path to download"+// @Success 200 {file} binary "file content, or ZIP archive for directories"+// @Failure 400 {object} response.errorResp "invalid resource request data"+// @Failure 403 {object} response.errorResp "downloading resource not permitted"+// @Failure 404 {object} response.errorResp "resource not found"+// @Failure 500 {object} response.errorResp "internal error on downloading resource"+// @Router /resources/download [get]+func (s *ResourceService) DownloadResource(c *gin.Context) {+ uid := c.GetUint64("uid")+ privs := c.GetStringSlice("prm")+ isAdmin := slices.Contains(privs, "resources.admin")++ if !isAdmin && !slices.Contains(privs, "resources.download") {+ response.Error(c, response.ErrNotPermitted, nil)+ return+ }++ reqPath := strings.TrimSpace(c.Query("path"))+ if reqPath == "" {+ response.Error(c, response.ErrResourcesInvalidRequest, errors.New("path query parameter is required"))+ return+ }+ targetPath, err := resources.SanitizeResourcePath(reqPath)+ if err != nil {+ response.Error(c, response.ErrResourcesInvalidRequest, err)+ return+ }++ q := s.db.Where("path = ?", targetPath)+ if !isAdmin {+ q = q.Where("user_id = ?", uid)+ }+ var rec models.UserResource+ if err := q.First(&rec).Error; err != nil {+ if gorm.IsRecordNotFoundError(err) {+ response.Error(c, response.ErrResourcesNotFound, fmt.Errorf("resource %q not found", targetPath))+ return+ }+ logger.FromContext(c).WithError(err).Error("error finding resource for download")+ response.Error(c, response.ErrInternal, err)+ return+ }++ if !rec.IsDir {+ blobPath := resources.BlobPath(s.dataDir, rec.Hash)+ if _, statErr := os.Lstat(blobPath); statErr != nil {+ if os.IsNotExist(statErr) {+ response.Error(c, response.ErrResourcesNotFound,+ fmt.Errorf("blob for resource %q not found on disk", targetPath))+ return+ }+ logger.FromContext(c).WithError(statErr).Error("error checking blob for download")+ response.Error(c, response.ErrInternal, statErr)+ return+ }+ c.FileAttachment(blobPath, rec.Name)+ return+ }++ // Directory: collect all non-directory entries recursively.+ escapedTarget := resources.EscapeLike(targetPath)+ var fileRecs []models.UserResource+ if err := s.db.Where(+ "user_id = ? AND path LIKE ? AND is_dir = false",+ rec.UserID, escapedTarget+"/%",+ ).Find(&fileRecs).Error; err != nil {+ logger.FromContext(c).WithError(err).Error("error listing resources for zip download")+ response.Error(c, response.ErrInternal, err)+ return+ }++ entries := make([]resources.ZipEntry, 0, len(fileRecs))+ for _, fr := range fileRecs {+ relPath := strings.TrimPrefix(fr.Path, targetPath+"/")+ if relPath == "" {+ relPath = fr.Name+ }+ entries = append(entries, resources.ZipEntry{+ BlobPath: resources.BlobPath(s.dataDir, fr.Hash),+ ZipPath: relPath,+ })+ }++ dirName := path.Base(targetPath)+ c.Header("Content-Disposition", mime.FormatMediaType("attachment", map[string]string{+ "filename": dirName + ".zip",+ }))+ c.Header("Content-Type", "application/zip")+ if err := resources.ZipResources(c.Writer, entries); err != nil {+ logger.FromContext(c).WithError(err).Error("error creating zip archive for download")+ }+}++// ---- helper methods --------------------------------------------------------++func (s *ResourceService) queryResources(+ uid uint64,+ isAdmin bool,+ dirPath string,+ recursive bool,+) ([]models.ResourceEntry, error) {+ q := s.db.Model(&models.UserResource{}).Order("updated_at DESC, name ASC")+ if !isAdmin {+ q = q.Where("user_id = ?", uid)+ }++ if dirPath != "" {+ escaped := resources.EscapeLike(dirPath)+ if recursive {+ q = q.Where("path = ? OR path LIKE ?", dirPath, escaped+"/%")+ } else {+ q = q.Where(+ "(path = ? AND is_dir = true) OR (path LIKE ? AND path NOT LIKE ?)",+ dirPath,+ escaped+"/%",+ escaped+"/%/%",+ )+ }+ } else if !recursive {+ q = q.Where("path NOT LIKE ?", "%/%")+ }++ var recs []models.UserResource+ if err := q.Find(&recs).Error; err != nil {+ return nil, fmt.Errorf("failed to list resources: %w", err)+ }+ return convertResources(recs), nil+}++func (s *ResourceService) resourceExists(uid uint64, vPath string) (bool, error) {+ var count int64+ err := s.db.Model(&models.UserResource{}).+ Where("user_id = ? AND path = ?", uid, vPath).+ Count(&count).Error+ return count > 0, err+}++func ensureResourceDirs(tx *gorm.DB, uid uint64, dirPath string) ([]models.UserResource, error) {+ if dirPath == "" {+ return nil, nil+ }++ parts := strings.Split(dirPath, "/")+ created := make([]models.UserResource, 0, len(parts))+ current := ""+ for _, part := range parts {+ current = resources.FilePath(current, part)++ existing, exists, err := findResourceByPath(tx, uid, current)+ if err != nil {+ return nil, err+ }+ if exists {+ if !existing.IsDir {+ return nil, fmt.Errorf("%w: resource %q already exists and is not a directory", errResourceConflict, current)+ }+ continue+ }++ rec := models.UserResource{+ UserID: uid,+ Hash: "",+ Name: path.Base(current),+ Path: current,+ Size: 0,+ IsDir: true,+ }+ if err := tx.Create(&rec).Error; err != nil {+ if isUniqueViolation(err) {+ refetched, ok, refetchErr := findResourceByPath(tx, uid, current)+ if refetchErr != nil {+ return nil, refetchErr+ }+ if ok && refetched.IsDir {+ continue+ }+ }+ return nil, fmt.Errorf("failed to create resource directory %q: %w", current, err)+ }+ created = append(created, rec)+ }++ return created, nil+}++// deleteOrphanBlob removes the .blob for hash if no DB row references it.+func (s *ResourceService) deleteOrphanBlob(_ context.Context, hash string) {+ if hash == "" {+ return+ }+ var count int64+ if err := s.db.Model(&models.UserResource{}).+ Where("hash = ?", hash).+ Count(&count).Error; err != nil || count > 0 {+ return+ }+ _ = resources.DeleteBlob(s.dataDir, hash)+}++// cleanupOrphanBlobs removes .blob files whose hashes are no longer referenced.+func (s *ResourceService) cleanupOrphanBlobs(_ context.Context, hashes []string) {+ if len(hashes) == 0 {+ return+ }+ var stillReferenced []string+ if err := s.db.Model(&models.UserResource{}).+ Where("hash IN (?)", hashes).+ Pluck("DISTINCT hash", &stillReferenced).Error; err != nil {+ return+ }+ refSet := make(map[string]bool, len(stillReferenced))+ for _, h := range stillReferenced {+ refSet[h] = true+ }+ for _, h := range hashes {+ if !refSet[h] {+ _ = resources.DeleteBlob(s.dataDir, h)+ }+ }+}++// cleanupResourceUploads removes tmp files left after a failed upload.+func cleanupResourceUploads(pending []pendingResourceUpload) {+ for _, p := range pending {+ if p.tmpPath != "" {+ os.Remove(p.tmpPath)+ }+ }+}++// ---- conversion helpers ----------------------------------------------------++func convertResource(r models.UserResource) models.ResourceEntry {+ return models.ResourceEntry{+ ID: int64(r.ID),+ UserID: r.UserID,+ Name: r.Name,+ Path: r.Path,+ Size: r.Size,+ IsDir: r.IsDir,+ CreatedAt: r.CreatedAt,+ UpdatedAt: r.UpdatedAt,+ }+}++func convertResources(recs []models.UserResource) []models.ResourceEntry {+ entries := make([]models.ResourceEntry, 0, len(recs))+ for _, r := range recs {+ entries = append(entries, convertResource(r))+ }+ return entries+}++func convertResourceToModel(e models.ResourceEntry) *model.UserResource {+ return &model.UserResource{+ ID: e.ID,+ UserID: int64(e.UserID),+ Name: e.Name,+ Path: e.Path,+ Size: int(e.Size),+ IsDir: e.IsDir,+ CreatedAt: e.CreatedAt,+ UpdatedAt: e.UpdatedAt,+ }+}++// ---- subscription publishing -----------------------------------------------++func (s *ResourceService) publishResourceAdded(ctx context.Context, uid uint64, e models.ResourceEntry) {+ if s.ss == nil {+ return+ }+ s.ss.NewResourcePublisher(int64(uid)).ResourceAdded(ctx, convertResourceToModel(e))+}++func (s *ResourceService) publishResourcesAdded(ctx context.Context, uid uint64, entries []models.ResourceEntry) {+ if s.ss == nil || len(entries) == 0 {+ return+ }+ pub := s.ss.NewResourcePublisher(int64(uid))+ for _, e := range entries {+ pub.ResourceAdded(ctx, convertResourceToModel(e))+ }+}++func (s *ResourceService) publishResourcesUpdated(ctx context.Context, uid uint64, entries []models.ResourceEntry) {+ if s.ss == nil || len(entries) == 0 {+ return+ }+ pub := s.ss.NewResourcePublisher(int64(uid))+ for _, e := range entries {+ pub.ResourceUpdated(ctx, convertResourceToModel(e))+ }+}++func (s *ResourceService) publishResourcesDeleted(ctx context.Context, uid uint64, entries []models.ResourceEntry) {+ if s.ss == nil || len(entries) == 0 {+ return+ }+ pub := s.ss.NewResourcePublisher(int64(uid))+ for _, e := range entries {+ pub.ResourceDeleted(ctx, convertResourceToModel(e))+ }+}++// ---- utility ---------------------------------------------------------------++// isUniqueViolation returns true if err is a PostgreSQL unique constraint+// violation (error code 23505).+func isUniqueViolation(err error) bool {+ if err == nil {+ return false+ }+ msg := err.Error()+ return strings.Contains(msg, "unique") ||+ strings.Contains(msg, "duplicate") ||+ strings.Contains(msg, "23505")+}diff --git a/backend/pkg/server/services/resources_test.go b/backend/pkg/server/services/resources_test.gonew file mode 100644index 00000000..7645eb52--- /dev/null+++ b/backend/pkg/server/services/resources_test.go@@ -0,0 +1,1131 @@+package services++import (+ "bytes"+ "context"+ "crypto/md5"+ "encoding/hex"+ "encoding/json"+ "mime/multipart"+ "net/http"+ "net/http/httptest"+ "os"+ "path/filepath"+ "testing"++ graphmodel "pentagi/pkg/graph/model"+ "pentagi/pkg/graph/subscriptions"+ "pentagi/pkg/resources"+ "pentagi/pkg/server/models"++ "github.com/gin-gonic/gin"+ "github.com/jinzhu/gorm"+ _ "github.com/jinzhu/gorm/dialects/sqlite"+ "github.com/stretchr/testify/assert"+ "github.com/stretchr/testify/require"+)++func setupResourceServiceTestDB(t *testing.T) *gorm.DB {+ t.Helper()++ db, err := gorm.Open("sqlite3", ":memory:")+ require.NoError(t, err)+ db.LogMode(false)++ require.NoError(t, db.Exec(`+ CREATE TABLE user_resources (+ id INTEGER PRIMARY KEY AUTOINCREMENT,+ user_id INTEGER NOT NULL,+ hash TEXT NOT NULL DEFAULT '',+ name TEXT NOT NULL,+ path TEXT NOT NULL,+ size INTEGER NOT NULL DEFAULT 0,+ is_dir BOOLEAN NOT NULL DEFAULT FALSE,+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,+ updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,+ UNIQUE(user_id, path)+ )+ `).Error)++ t.Cleanup(func() {+ require.NoError(t, db.Close())+ })++ return db+}++func seedResource(t *testing.T, db *gorm.DB, rec models.UserResource) models.UserResource {+ t.Helper()++ require.NoError(t, db.Create(&rec).Error)+ return rec+}++func resourcePaths(entries []models.ResourceEntry) []string {+ paths := make([]string, len(entries))+ for i, entry := range entries {+ paths[i] = entry.Path+ }+ return paths+}++func allResourcePaths(t *testing.T, db *gorm.DB) []string {+ t.Helper()++ var recs []models.UserResource+ require.NoError(t, db.Order("path ASC").Find(&recs).Error)+ paths := make([]string, len(recs))+ for i, rec := range recs {+ paths[i] = rec.Path+ }+ return paths+}++func newResourceTestContext(method, target string, body *bytes.Buffer, privs []string) (*gin.Context, *httptest.ResponseRecorder) {+ gin.SetMode(gin.TestMode)+ w := httptest.NewRecorder()+ c, _ := gin.CreateTestContext(w)+ c.Set("uid", uint64(1))+ c.Set("prm", privs)+ if body == nil {+ body = bytes.NewBuffer(nil)+ }+ c.Request = httptest.NewRequest(method, target, body)+ return c, w+}++func decodeResourceListResponse(t *testing.T, w *httptest.ResponseRecorder) models.ResourceList {+ t.Helper()++ var resp struct {+ Status string `json:"status"`+ Data models.ResourceList `json:"data"`+ }+ require.NoError(t, json.Unmarshal(w.Body.Bytes(), &resp))+ require.Equal(t, "success", resp.Status)+ return resp.Data+}++type resourceEvent struct {+ action string+ path string+}++type uploadTestFile struct {+ name string+ content string+}++func multipartUploadBody(t *testing.T, files []uploadTestFile) (*bytes.Buffer, string) {+ t.Helper()++ var body bytes.Buffer+ writer := multipart.NewWriter(&body)+ for _, file := range files {+ part, err := writer.CreateFormFile("files", file.name)+ require.NoError(t, err)+ _, err = part.Write([]byte(file.content))+ require.NoError(t, err)+ }+ require.NoError(t, writer.Close())+ return &body, writer.FormDataContentType()+}++type captureSubscriptions struct {+ events []resourceEvent+}++func (s *captureSubscriptions) NewFlowSubscriber(int64, int64) subscriptions.FlowSubscriber {+ return nil+}+func (s *captureSubscriptions) NewFlowPublisher(int64, int64) subscriptions.FlowPublisher { return nil }+func (s *captureSubscriptions) NewResourceSubscriber(int64) subscriptions.ResourceSubscriber {+ return nil+}+func (s *captureSubscriptions) NewProviderSubscriber(int64) subscriptions.ProviderSubscriber {+ return nil+}+func (s *captureSubscriptions) NewProviderPublisher(int64) subscriptions.ProviderPublisher {+ return nil+}+func (s *captureSubscriptions) NewAPITokenSubscriber(int64) subscriptions.APITokenSubscriber {+ return nil+}+func (s *captureSubscriptions) NewAPITokenPublisher(int64) subscriptions.APITokenPublisher {+ return nil+}+func (s *captureSubscriptions) NewSettingsSubscriber(int64) subscriptions.SettingsSubscriber {+ return nil+}+func (s *captureSubscriptions) NewSettingsPublisher(int64) subscriptions.SettingsPublisher {+ return nil+}+func (s *captureSubscriptions) NewFlowTemplateSubscriber(int64) subscriptions.FlowTemplateSubscriber {+ return nil+}+func (s *captureSubscriptions) NewFlowTemplatePublisher(int64) subscriptions.FlowTemplatePublisher {+ return nil+}+func (s *captureSubscriptions) NewResourcePublisher(int64) subscriptions.ResourcePublisher {+ return &captureResourcePublisher{events: &s.events}+}++type captureResourcePublisher struct {+ userID int64+ events *[]resourceEvent+}++func (p *captureResourcePublisher) GetUserID() int64 { return p.userID }+func (p *captureResourcePublisher) SetUserID(userID int64) {+ p.userID = userID+}+func (p *captureResourcePublisher) ResourceAdded(_ context.Context, resource *graphmodel.UserResource) {+ *p.events = append(*p.events, resourceEvent{action: "added", path: resource.Path})+}+func (p *captureResourcePublisher) ResourceUpdated(_ context.Context, resource *graphmodel.UserResource) {+ *p.events = append(*p.events, resourceEvent{action: "updated", path: resource.Path})+}+func (p *captureResourcePublisher) ResourceDeleted(_ context.Context, resource *graphmodel.UserResource) {+ *p.events = append(*p.events, resourceEvent{action: "deleted", path: resource.Path})+}++func TestResourceService_ListResourcesAPI(t *testing.T) {+ db := setupResourceServiceTestDB(t)+ svc := NewResourceService(db, t.TempDir(), nil)+ seedResource(t, db, models.UserResource{UserID: 1, Name: "docs", Path: "docs", IsDir: true})+ seedResource(t, db, models.UserResource{UserID: 1, Hash: md5HexForService("a"), Name: "a.txt", Path: "docs/a.txt", Size: 1})+ seedResource(t, db, models.UserResource{UserID: 1, Hash: md5HexForService("b"), Name: "b.txt", Path: "docs/sub/b.txt", Size: 1})++ c, w := newResourceTestContext(http.MethodGet, "/resources/?path=docs&recursive=true", nil, []string{"resources.view"})++ svc.ListResources(c)++ require.Equal(t, http.StatusOK, w.Code)+ list := decodeResourceListResponse(t, w)+ assert.ElementsMatch(t, []string{"docs", "docs/a.txt", "docs/sub/b.txt"}, resourcePaths(list.Items))+ assert.Equal(t, uint64(3), list.Total)+}++func TestResourceService_MkdirResourceAPI(t *testing.T) {+ db := setupResourceServiceTestDB(t)+ svc := NewResourceService(db, t.TempDir(), nil)+ body := bytes.NewBufferString(`{"path":"docs"}`)+ c, w := newResourceTestContext(http.MethodPost, "/resources/mkdir", body, []string{"resources.edit"})+ c.Request.Header.Set("Content-Type", "application/json")++ svc.MkdirResource(c)++ require.Equal(t, http.StatusOK, w.Code)+ var rec models.UserResource+ require.NoError(t, db.Where("user_id = ? AND path = ?", 1, "docs").First(&rec).Error)+ assert.True(t, rec.IsDir)+ assert.Equal(t, "docs", rec.Name)+}++func TestResourceService_UploadResourcesScenarios(t *testing.T) {+ type seed struct {+ path string+ isDir bool+ content string+ }++ tests := []struct {+ name string+ dir string+ files []uploadTestFile+ privs []string+ seeds []seed+ wantStatus int+ wantPaths []string+ wantResponsePaths []string+ wantEvents []resourceEvent+ wantMissingBlobs []string+ wantPresentBlobs []string+ }{+ {+ name: "upload without dir creates file in root",+ files: []uploadTestFile{{name: "report.txt", content: "payload"}},+ privs: []string{"resources.upload"},+ wantStatus: http.StatusOK,+ wantPaths: []string{"report.txt"},+ wantResponsePaths: []string{"report.txt"},+ wantEvents: []resourceEvent{{action: "added", path: "report.txt"}},+ wantPresentBlobs: []string{"payload"},+ },+ {+ name: "upload into existing dir creates file only",+ dir: "docs",+ files: []uploadTestFile{{name: "report.txt", content: "payload"}},+ privs: []string{"resources.upload"},+ seeds: []seed{{path: "docs", isDir: true}},+ wantStatus: http.StatusOK,+ wantPaths: []string{"docs", "docs/report.txt"},+ wantResponsePaths: []string{"docs/report.txt"},+ wantEvents: []resourceEvent{{action: "added", path: "docs/report.txt"}},+ wantPresentBlobs: []string{"payload"},+ },+ {+ name: "upload into missing dir creates dir and file",+ dir: "docs",+ files: []uploadTestFile{{name: "report.txt", content: "payload"}},+ privs: []string{"resources.upload"},+ wantStatus: http.StatusOK,+ wantPaths: []string{"docs", "docs/report.txt"},+ wantResponsePaths: []string{"docs/report.txt"},+ wantEvents: []resourceEvent{{action: "added", path: "docs"}, {action: "added", path: "docs/report.txt"}},+ wantPresentBlobs: []string{"payload"},+ },+ {+ name: "upload into missing nested dir creates parents and files",+ dir: "docs/sub",+ files: []uploadTestFile{{name: "a.txt", content: "a"}, {name: "b.txt", content: "b"}},+ privs: []string{"resources.upload"},+ wantStatus: http.StatusOK,+ wantPaths: []string{"docs", "docs/sub", "docs/sub/a.txt", "docs/sub/b.txt"},+ wantResponsePaths: []string{"docs/sub/a.txt", "docs/sub/b.txt"},+ wantEvents: []resourceEvent{+ {action: "added", path: "docs"},+ {action: "added", path: "docs/sub"},+ {action: "added", path: "docs/sub/a.txt"},+ {action: "added", path: "docs/sub/b.txt"},+ },+ wantPresentBlobs: []string{"a", "b"},+ },+ {+ name: "upload target dir path occupied by file conflicts",+ dir: "docs",+ files: []uploadTestFile{{name: "report.txt", content: "payload"}},+ privs: []string{"resources.upload"},+ seeds: []seed{{path: "docs", content: "file"}},+ wantStatus: http.StatusConflict,+ wantPaths: []string{"docs"},+ wantMissingBlobs: []string{"payload"},+ wantPresentBlobs: []string{"file"},+ },+ {+ name: "upload existing file path conflicts before writing",+ files: []uploadTestFile{{name: "report.txt", content: "new"}},+ privs: []string{"resources.upload"},+ seeds: []seed{{path: "report.txt", content: "old"}},+ wantStatus: http.StatusConflict,+ wantPaths: []string{"report.txt"},+ wantMissingBlobs: []string{"new"},+ wantPresentBlobs: []string{"old"},+ },+ {+ name: "upload duplicate filenames in same request conflicts",+ files: []uploadTestFile{{name: "report.txt", content: "first"}, {name: "./report.txt", content: "second"}},+ privs: []string{"resources.upload"},+ wantStatus: http.StatusConflict,+ wantMissingBlobs: []string{"first", "second"},+ },+ {+ name: "upload invalid dir rejected",+ dir: "../docs",+ files: []uploadTestFile{{name: "report.txt", content: "payload"}},+ privs: []string{"resources.upload"},+ wantStatus: http.StatusBadRequest,+ wantMissingBlobs: []string{"payload"},+ },+ {+ name: "upload invalid filename rejected",+ files: []uploadTestFile{{name: "bad\nname.txt", content: "payload"}},+ privs: []string{"resources.upload"},+ wantStatus: http.StatusBadRequest,+ wantMissingBlobs: []string{"payload"},+ },+ {+ name: "upload without privilege forbidden",+ files: []uploadTestFile{{name: "report.txt", content: "payload"}},+ privs: []string{"resources.view"},+ wantStatus: http.StatusForbidden,+ wantMissingBlobs: []string{"payload"},+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ db := setupResourceServiceTestDB(t)+ dataDir := t.TempDir()+ ss := &captureSubscriptions{}+ svc := NewResourceService(db, dataDir, ss)+ hashes := map[string]string{}+ for _, rec := range tt.seeds {+ seeded := models.UserResource{+ UserID: 1,+ Name: filepath.Base(rec.path),+ Path: rec.path,+ IsDir: rec.isDir,+ }+ if !rec.isDir {+ seeded.Hash = md5HexForService(rec.content)+ seeded.Size = int64(len(rec.content))+ writeResourceBlob(t, dataDir, seeded.Hash, rec.content)+ hashes[rec.content] = seeded.Hash+ }+ seedResource(t, db, seeded)+ }+ for _, file := range tt.files {+ hashes[file.content] = md5HexForService(file.content)+ }++ body, contentType := multipartUploadBody(t, tt.files)+ target := "/resources/"+ if tt.dir != "" {+ target += "?dir=" + tt.dir+ }+ c, w := newResourceTestContext(http.MethodPost, target, body, tt.privs)+ c.Request.Header.Set("Content-Type", contentType)++ svc.UploadResources(c)++ require.Equal(t, tt.wantStatus, w.Code)+ if tt.wantPaths != nil {+ assert.ElementsMatch(t, tt.wantPaths, allResourcePaths(t, db))+ }+ assert.Equal(t, tt.wantEvents, ss.events)+ if tt.wantStatus == http.StatusOK {+ list := decodeResourceListResponse(t, w)+ assert.ElementsMatch(t, tt.wantResponsePaths, resourcePaths(list.Items))+ }+ for _, key := range tt.wantMissingBlobs {+ _, err := os.Lstat(resources.BlobPath(dataDir, hashes[key]))+ assert.True(t, os.IsNotExist(err), "blob for %q should not exist", key)+ }+ for _, key := range tt.wantPresentBlobs {+ _, err := os.Lstat(resources.BlobPath(dataDir, hashes[key]))+ assert.NoError(t, err, "blob for %q should exist", key)+ }+ })+ }+}++func TestResourceService_DownloadResourceAPI(t *testing.T) {+ db := setupResourceServiceTestDB(t)+ dataDir := t.TempDir()+ svc := NewResourceService(db, dataDir, nil)+ hash := md5HexForService("payload")+ writeResourceBlob(t, dataDir, hash, "payload")+ seedResource(t, db, models.UserResource{UserID: 1, Hash: hash, Name: "report.txt", Path: "report.txt", Size: 7})+ c, w := newResourceTestContext(http.MethodGet, "/resources/download?path=report.txt", nil, []string{"resources.download"})++ svc.DownloadResource(c)++ require.Equal(t, http.StatusOK, w.Code)+ assert.Equal(t, "payload", w.Body.String())+ assert.Contains(t, w.Header().Get("Content-Disposition"), "report.txt")+}++func TestResourceService_DeleteResourceScenarios(t *testing.T) {+ type seed struct {+ userID uint64+ path string+ isDir bool+ content string+ hash string+ }++ tests := []struct {+ name string+ seeds []seed+ targetPath string+ privs []string+ wantStatus int+ wantPaths []string+ wantResponsePaths []string+ wantEvents []resourceEvent+ wantMissingBlobs []string+ wantPresentBlobs []string+ }{+ {+ name: "delete file removes row and orphan blob",+ seeds: []seed{{path: "report.txt", content: "payload"}},+ targetPath: "report.txt",+ privs: []string{"resources.delete"},+ wantStatus: http.StatusOK,+ wantResponsePaths: []string{"report.txt"},+ wantEvents: []resourceEvent{{action: "deleted", path: "report.txt"}},+ wantMissingBlobs: []string{"payload"},+ },+ {+ name: "delete directory removes recursive tree and orphan blobs",+ seeds: []seed{+ {path: "docs", isDir: true},+ {path: "docs/a.txt", content: "a"},+ {path: "docs/sub", isDir: true},+ {path: "docs/sub/b.txt", content: "b"},+ {path: "other.txt", content: "other"},+ },+ targetPath: "docs",+ privs: []string{"resources.delete"},+ wantStatus: http.StatusOK,+ wantPaths: []string{"other.txt"},+ wantResponsePaths: []string{"docs", "docs/a.txt", "docs/sub", "docs/sub/b.txt"},+ wantEvents: []resourceEvent{+ {action: "deleted", path: "docs"},+ {action: "deleted", path: "docs/a.txt"},+ {action: "deleted", path: "docs/sub"},+ {action: "deleted", path: "docs/sub/b.txt"},+ },+ wantMissingBlobs: []string{"a", "b"},+ wantPresentBlobs: []string{"other"},+ },+ {+ name: "delete file keeps shared blob",+ seeds: []seed{+ {path: "a.txt", content: "same", hash: "shared"},+ {path: "b.txt", content: "same", hash: "shared"},+ },+ targetPath: "a.txt",+ privs: []string{"resources.delete"},+ wantStatus: http.StatusOK,+ wantPaths: []string{"b.txt"},+ wantResponsePaths: []string{"a.txt"},+ wantEvents: []resourceEvent{{action: "deleted", path: "a.txt"}},+ wantPresentBlobs: []string{"shared"},+ },+ {+ name: "admin delete is still scoped to current user writes",+ seeds: []seed{+ {userID: 1, path: "own.txt", content: "own"},+ {userID: 2, path: "own.txt", content: "other"},+ },+ targetPath: "own.txt",+ privs: []string{"resources.admin"},+ wantStatus: http.StatusOK,+ wantPaths: []string{"own.txt"},+ wantResponsePaths: []string{"own.txt"},+ wantEvents: []resourceEvent{{action: "deleted", path: "own.txt"}},+ wantMissingBlobs: []string{"own"},+ wantPresentBlobs: []string{"other"},+ },+ {+ name: "missing path returns not found",+ targetPath: "missing.txt",+ privs: []string{"resources.delete"},+ wantStatus: http.StatusNotFound,+ },+ {+ name: "unsafe path returns bad request",+ targetPath: "../evil.txt",+ privs: []string{"resources.delete"},+ wantStatus: http.StatusBadRequest,+ },+ {+ name: "missing privilege returns forbidden",+ seeds: []seed{{path: "report.txt", content: "payload"}},+ targetPath: "report.txt",+ privs: []string{"resources.view"},+ wantStatus: http.StatusForbidden,+ wantPaths: []string{"report.txt"},+ wantPresentBlobs: []string{"payload"},+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ db := setupResourceServiceTestDB(t)+ dataDir := t.TempDir()+ ss := &captureSubscriptions{}+ svc := NewResourceService(db, dataDir, ss)+ hashes := map[string]string{}+ for _, rec := range tt.seeds {+ userID := rec.userID+ if userID == 0 {+ userID = 1+ }+ seeded := models.UserResource{+ UserID: userID,+ Name: filepath.Base(rec.path),+ Path: rec.path,+ IsDir: rec.isDir,+ }+ if !rec.isDir {+ hashKey := rec.content+ if rec.hash != "" {+ hashKey = rec.hash+ }+ seeded.Hash = md5HexForService(hashKey)+ seeded.Size = int64(len(rec.content))+ writeResourceBlob(t, dataDir, seeded.Hash, rec.content)+ hashes[hashKey] = seeded.Hash+ }+ seedResource(t, db, seeded)+ }++ c, w := newResourceTestContext(http.MethodDelete, "/resources/?path="+tt.targetPath, nil, tt.privs)+ svc.DeleteResource(c)++ require.Equal(t, tt.wantStatus, w.Code)+ if tt.wantPaths != nil {+ assert.ElementsMatch(t, tt.wantPaths, allResourcePaths(t, db))+ }+ assert.Equal(t, tt.wantEvents, ss.events)+ if tt.wantStatus == http.StatusOK {+ list := decodeResourceListResponse(t, w)+ assert.ElementsMatch(t, tt.wantResponsePaths, resourcePaths(list.Items))+ }+ for _, key := range tt.wantMissingBlobs {+ _, err := os.Lstat(resources.BlobPath(dataDir, hashes[key]))+ assert.True(t, os.IsNotExist(err), "blob for %q should be removed", key)+ }+ for _, key := range tt.wantPresentBlobs {+ _, err := os.Lstat(resources.BlobPath(dataDir, hashes[key]))+ assert.NoError(t, err, "blob for %q should still exist", key)+ }+ })+ }+}++func TestResourceService_CopyResourceScenarios(t *testing.T) {+ type seed struct {+ path string+ isDir bool+ content string+ }+ type copyRequest struct {+ Source string `json:"source"`+ Destination string `json:"destination"`+ Force bool `json:"force,omitempty"`+ }++ tests := []struct {+ name string+ seeds []seed+ req copyRequest+ wantStatus int+ wantPaths []string+ wantResponsePaths []string+ wantEvents []resourceEvent+ wantDeletedBlobTexts []string+ }{+ {+ name: "file to absent path adds copy",+ seeds: []seed{{path: "a.txt", content: "src"}},+ req: copyRequest{Source: "a.txt", Destination: "copies/a.txt"},+ wantStatus: http.StatusOK,+ wantPaths: []string{"a.txt", "copies/a.txt"},+ wantResponsePaths: []string{"copies/a.txt"},+ wantEvents: []resourceEvent{{action: "added", path: "copies/a.txt"}},+ },+ {+ name: "file to existing file without force conflicts",+ seeds: []seed{{path: "a.txt", content: "src"}, {path: "b.txt", content: "dst"}},+ req: copyRequest{Source: "a.txt", Destination: "b.txt"},+ wantStatus: http.StatusConflict,+ wantPaths: []string{"a.txt", "b.txt"},+ },+ {+ name: "file to existing file with force overwrites destination",+ seeds: []seed{{path: "a.txt", content: "src"}, {path: "b.txt", content: "dst"}},+ req: copyRequest{Source: "a.txt", Destination: "b.txt", Force: true},+ wantStatus: http.StatusOK,+ wantPaths: []string{"a.txt", "b.txt"},+ wantResponsePaths: []string{"b.txt"},+ wantEvents: []resourceEvent{{action: "deleted", path: "b.txt"}, {action: "updated", path: "b.txt"}},+ wantDeletedBlobTexts: []string{"dst"},+ },+ {+ name: "file to existing directory copies inside directory",+ seeds: []seed{{path: "a.txt", content: "src"}, {path: "docs", isDir: true}},+ req: copyRequest{Source: "a.txt", Destination: "docs"},+ wantStatus: http.StatusOK,+ wantPaths: []string{"a.txt", "docs", "docs/a.txt"},+ wantResponsePaths: []string{"docs/a.txt"},+ wantEvents: []resourceEvent{{action: "added", path: "docs/a.txt"}},+ },+ {+ name: "file to existing directory child without force conflicts",+ seeds: []seed{{path: "a.txt", content: "src"}, {path: "docs", isDir: true}, {path: "docs/a.txt", content: "dst"}},+ req: copyRequest{Source: "a.txt", Destination: "docs"},+ wantStatus: http.StatusConflict,+ wantPaths: []string{"a.txt", "docs", "docs/a.txt"},+ },+ {+ name: "file to existing directory child with force overwrites child",+ seeds: []seed{{path: "a.txt", content: "src"}, {path: "docs", isDir: true}, {path: "docs/a.txt", content: "dst"}},+ req: copyRequest{Source: "a.txt", Destination: "docs", Force: true},+ wantStatus: http.StatusOK,+ wantPaths: []string{"a.txt", "docs", "docs/a.txt"},+ wantResponsePaths: []string{"docs/a.txt"},+ wantEvents: []resourceEvent{{action: "deleted", path: "docs/a.txt"}, {action: "updated", path: "docs/a.txt"}},+ wantDeletedBlobTexts: []string{"dst"},+ },+ {+ name: "file to existing directory child directory conflicts",+ seeds: []seed{{path: "a.txt", content: "src"}, {path: "docs", isDir: true}, {path: "docs/a.txt", isDir: true}},+ req: copyRequest{Source: "a.txt", Destination: "docs", Force: true},+ wantStatus: http.StatusConflict,+ wantPaths: []string{"a.txt", "docs", "docs/a.txt"},+ },+ {+ name: "directory to absent path adds whole tree",+ seeds: []seed{+ {path: "docs", isDir: true},+ {path: "docs/a.txt", content: "a"},+ {path: "docs/sub", isDir: true},+ {path: "docs/sub/b.txt", content: "b"},+ },+ req: copyRequest{Source: "docs", Destination: "copies/docs"},+ wantStatus: http.StatusOK,+ wantPaths: []string{"docs", "docs/a.txt", "docs/sub", "docs/sub/b.txt", "copies/docs", "copies/docs/a.txt", "copies/docs/sub", "copies/docs/sub/b.txt"},+ wantResponsePaths: []string{"copies/docs", "copies/docs/a.txt", "copies/docs/sub", "copies/docs/sub/b.txt"},+ wantEvents: []resourceEvent{+ {action: "added", path: "copies/docs"},+ {action: "added", path: "copies/docs/a.txt"},+ {action: "added", path: "copies/docs/sub"},+ {action: "added", path: "copies/docs/sub/b.txt"},+ },+ },+ {+ name: "directory to existing file conflicts",+ seeds: []seed{{path: "docs", isDir: true}, {path: "target", content: "file"}},+ req: copyRequest{Source: "docs", Destination: "target", Force: true},+ wantStatus: http.StatusConflict,+ wantPaths: []string{"docs", "target"},+ },+ {+ name: "directory to existing directory without force conflicts",+ seeds: []seed{{path: "docs", isDir: true}, {path: "archive", isDir: true}},+ req: copyRequest{Source: "docs", Destination: "archive"},+ wantStatus: http.StatusConflict,+ wantPaths: []string{"archive", "docs"},+ },+ {+ name: "directory to existing directory with force merges",+ seeds: []seed{+ {path: "docs", isDir: true},+ {path: "docs/a.txt", content: "a"},+ {path: "docs/sub", isDir: true},+ {path: "docs/sub/b.txt", content: "b"},+ {path: "archive", isDir: true},+ },+ req: copyRequest{Source: "docs", Destination: "archive", Force: true},+ wantStatus: http.StatusOK,+ wantPaths: []string{"docs", "docs/a.txt", "docs/sub", "docs/sub/b.txt", "archive", "archive/a.txt", "archive/sub", "archive/sub/b.txt"},+ wantResponsePaths: []string{"archive/a.txt", "archive/sub", "archive/sub/b.txt"},+ wantEvents: []resourceEvent{+ {action: "added", path: "archive/a.txt"},+ {action: "added", path: "archive/sub"},+ {action: "added", path: "archive/sub/b.txt"},+ },+ },+ {+ name: "directory merge with existing file overwrites file",+ seeds: []seed{+ {path: "docs", isDir: true},+ {path: "docs/a.txt", content: "src-a"},+ {path: "archive", isDir: true},+ {path: "archive/a.txt", content: "dst-a"},+ },+ req: copyRequest{Source: "docs", Destination: "archive", Force: true},+ wantStatus: http.StatusOK,+ wantPaths: []string{"docs", "docs/a.txt", "archive", "archive/a.txt"},+ wantResponsePaths: []string{"archive/a.txt"},+ wantEvents: []resourceEvent{{action: "deleted", path: "archive/a.txt"}, {action: "updated", path: "archive/a.txt"}},+ wantDeletedBlobTexts: []string{"dst-a"},+ },+ {+ name: "directory merge with existing subdirectory keeps destination directory",+ seeds: []seed{+ {path: "docs", isDir: true},+ {path: "docs/sub", isDir: true},+ {path: "docs/sub/a.txt", content: "a"},+ {path: "archive", isDir: true},+ {path: "archive/sub", isDir: true},+ },+ req: copyRequest{Source: "docs", Destination: "archive", Force: true},+ wantStatus: http.StatusOK,+ wantPaths: []string{"docs", "docs/sub", "docs/sub/a.txt", "archive", "archive/sub", "archive/sub/a.txt"},+ wantResponsePaths: []string{"archive/sub", "archive/sub/a.txt"},+ wantEvents: []resourceEvent{{action: "added", path: "archive/sub/a.txt"}, {action: "updated", path: "archive/sub"}},+ },+ {+ name: "directory merge file over existing directory conflicts",+ seeds: []seed{{path: "docs", isDir: true}, {path: "docs/a.txt", content: "a"}, {path: "archive", isDir: true}, {path: "archive/a.txt", isDir: true}},+ req: copyRequest{Source: "docs", Destination: "archive", Force: true},+ wantStatus: http.StatusConflict,+ wantPaths: []string{"archive", "archive/a.txt", "docs", "docs/a.txt"},+ },+ {+ name: "directory into itself is invalid",+ seeds: []seed{{path: "docs", isDir: true}},+ req: copyRequest{Source: "docs", Destination: "docs/archive", Force: true},+ wantStatus: http.StatusBadRequest,+ wantPaths: []string{"docs"},+ },+ {+ name: "same source and destination is invalid",+ seeds: []seed{{path: "a.txt", content: "a"}},+ req: copyRequest{Source: "a.txt", Destination: "a.txt", Force: true},+ wantStatus: http.StatusBadRequest,+ wantPaths: []string{"a.txt"},+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ db := setupResourceServiceTestDB(t)+ dataDir := t.TempDir()+ ss := &captureSubscriptions{}+ svc := NewResourceService(db, dataDir, ss)+ deletedHashes := map[string]string{}+ for _, rec := range tt.seeds {+ seeded := models.UserResource{+ UserID: 1,+ Name: filepath.Base(rec.path),+ Path: rec.path,+ IsDir: rec.isDir,+ }+ if !rec.isDir {+ seeded.Hash = md5HexForService(rec.content)+ seeded.Size = int64(len(rec.content))+ writeResourceBlob(t, dataDir, seeded.Hash, rec.content)+ deletedHashes[rec.content] = seeded.Hash+ }+ seedResource(t, db, seeded)+ }++ bodyBytes, err := json.Marshal(tt.req)+ require.NoError(t, err)+ c, w := newResourceTestContext(http.MethodPost, "/resources/copy", bytes.NewBuffer(bodyBytes), []string{"resources.edit"})+ c.Request.Header.Set("Content-Type", "application/json")++ svc.CopyResource(c)++ require.Equal(t, tt.wantStatus, w.Code)+ assert.ElementsMatch(t, tt.wantPaths, allResourcePaths(t, db))+ assert.Equal(t, tt.wantEvents, ss.events)+ if tt.wantStatus == http.StatusOK {+ list := decodeResourceListResponse(t, w)+ assert.ElementsMatch(t, tt.wantResponsePaths, resourcePaths(list.Items))+ }+ for _, content := range tt.wantDeletedBlobTexts {+ _, err := os.Lstat(resources.BlobPath(dataDir, deletedHashes[content]))+ assert.True(t, os.IsNotExist(err), "blob for %q should be removed", content)+ }+ })+ }+}++func TestResourceService_MoveResourceScenarios(t *testing.T) {+ type seed struct {+ path string+ isDir bool+ content string+ }+ type moveRequest struct {+ Source string `json:"source"`+ Destination string `json:"destination"`+ Force bool `json:"force,omitempty"`+ }++ tests := []struct {+ name string+ seeds []seed+ req moveRequest+ wantStatus int+ wantPaths []string+ wantResponsePaths []string+ wantEvents []resourceEvent+ wantDeletedBlobTexts []string+ }{+ {+ name: "file to absent path updates source",+ seeds: []seed{{path: "a.txt", content: "src"}},+ req: moveRequest{Source: "a.txt", Destination: "b.txt"},+ wantStatus: http.StatusOK,+ wantPaths: []string{"b.txt"},+ wantResponsePaths: []string{"b.txt"},+ wantEvents: []resourceEvent{{action: "updated", path: "b.txt"}},+ },+ {+ name: "file to existing file without force conflicts",+ seeds: []seed{{path: "a.txt", content: "src"}, {path: "b.txt", content: "dst"}},+ req: moveRequest{Source: "a.txt", Destination: "b.txt"},+ wantStatus: http.StatusConflict,+ wantPaths: []string{"a.txt", "b.txt"},+ },+ {+ name: "file to existing file with force overwrites destination",+ seeds: []seed{{path: "a.txt", content: "src"}, {path: "b.txt", content: "dst"}},+ req: moveRequest{Source: "a.txt", Destination: "b.txt", Force: true},+ wantStatus: http.StatusOK,+ wantPaths: []string{"b.txt"},+ wantResponsePaths: []string{"b.txt"},+ wantEvents: []resourceEvent{{action: "deleted", path: "b.txt"}, {action: "updated", path: "b.txt"}},+ wantDeletedBlobTexts: []string{"dst"},+ },+ {+ name: "file to existing directory moves inside directory",+ seeds: []seed{{path: "a.txt", content: "src"}, {path: "docs", isDir: true}},+ req: moveRequest{Source: "a.txt", Destination: "docs"},+ wantStatus: http.StatusOK,+ wantPaths: []string{"docs", "docs/a.txt"},+ wantResponsePaths: []string{"docs/a.txt"},+ wantEvents: []resourceEvent{{action: "updated", path: "docs/a.txt"}},+ },+ {+ name: "file to existing directory child without force conflicts",+ seeds: []seed{{path: "a.txt", content: "src"}, {path: "docs", isDir: true}, {path: "docs/a.txt", content: "dst"}},+ req: moveRequest{Source: "a.txt", Destination: "docs"},+ wantStatus: http.StatusConflict,+ wantPaths: []string{"a.txt", "docs", "docs/a.txt"},+ },+ {+ name: "file to existing directory child with force overwrites child",+ seeds: []seed{{path: "a.txt", content: "src"}, {path: "docs", isDir: true}, {path: "docs/a.txt", content: "dst"}},+ req: moveRequest{Source: "a.txt", Destination: "docs", Force: true},+ wantStatus: http.StatusOK,+ wantPaths: []string{"docs", "docs/a.txt"},+ wantResponsePaths: []string{"docs/a.txt"},+ wantEvents: []resourceEvent{{action: "deleted", path: "docs/a.txt"}, {action: "updated", path: "docs/a.txt"}},+ wantDeletedBlobTexts: []string{"dst"},+ },+ {+ name: "file to existing directory child directory conflicts",+ seeds: []seed{{path: "a.txt", content: "src"}, {path: "docs", isDir: true}, {path: "docs/a.txt", isDir: true}},+ req: moveRequest{Source: "a.txt", Destination: "docs", Force: true},+ wantStatus: http.StatusConflict,+ wantPaths: []string{"a.txt", "docs", "docs/a.txt"},+ },+ {+ name: "directory to absent path updates whole tree",+ seeds: []seed{+ {path: "docs", isDir: true},+ {path: "docs/a.txt", content: "a"},+ {path: "docs/sub", isDir: true},+ {path: "docs/sub/b.txt", content: "b"},+ },+ req: moveRequest{Source: "docs", Destination: "archive/docs"},+ wantStatus: http.StatusOK,+ wantPaths: []string{"archive/docs", "archive/docs/a.txt", "archive/docs/sub", "archive/docs/sub/b.txt"},+ wantResponsePaths: []string{"archive/docs", "archive/docs/a.txt", "archive/docs/sub", "archive/docs/sub/b.txt"},+ wantEvents: []resourceEvent{+ {action: "updated", path: "archive/docs"},+ {action: "updated", path: "archive/docs/a.txt"},+ {action: "updated", path: "archive/docs/sub"},+ {action: "updated", path: "archive/docs/sub/b.txt"},+ },+ },+ {+ name: "directory to existing file conflicts",+ seeds: []seed{{path: "docs", isDir: true}, {path: "target", content: "file"}},+ req: moveRequest{Source: "docs", Destination: "target", Force: true},+ wantStatus: http.StatusConflict,+ wantPaths: []string{"docs", "target"},+ },+ {+ name: "directory to existing directory without force conflicts",+ seeds: []seed{{path: "docs", isDir: true}, {path: "archive", isDir: true}},+ req: moveRequest{Source: "docs", Destination: "archive"},+ wantStatus: http.StatusConflict,+ wantPaths: []string{"archive", "docs"},+ },+ {+ name: "directory to existing directory with force merges",+ seeds: []seed{+ {path: "docs", isDir: true},+ {path: "docs/a.txt", content: "a"},+ {path: "docs/sub", isDir: true},+ {path: "docs/sub/b.txt", content: "b"},+ {path: "archive", isDir: true},+ },+ req: moveRequest{Source: "docs", Destination: "archive", Force: true},+ wantStatus: http.StatusOK,+ wantPaths: []string{"archive", "archive/a.txt", "archive/sub", "archive/sub/b.txt"},+ wantResponsePaths: []string{"archive/a.txt", "archive/sub", "archive/sub/b.txt"},+ wantEvents: []resourceEvent{+ {action: "updated", path: "archive/a.txt"},+ {action: "updated", path: "archive/sub"},+ {action: "updated", path: "archive/sub/b.txt"},+ {action: "deleted", path: "docs"},+ },+ },+ {+ name: "directory merge with existing file overwrites file",+ seeds: []seed{+ {path: "docs", isDir: true},+ {path: "docs/a.txt", content: "src-a"},+ {path: "archive", isDir: true},+ {path: "archive/a.txt", content: "dst-a"},+ },+ req: moveRequest{Source: "docs", Destination: "archive", Force: true},+ wantStatus: http.StatusOK,+ wantPaths: []string{"archive", "archive/a.txt"},+ wantResponsePaths: []string{"archive/a.txt"},+ wantEvents: []resourceEvent{{action: "deleted", path: "archive/a.txt"}, {action: "updated", path: "archive/a.txt"}, {action: "deleted", path: "docs"}},+ wantDeletedBlobTexts: []string{"dst-a"},+ },+ {+ name: "directory merge with existing subdirectory keeps destination directory",+ seeds: []seed{+ {path: "docs", isDir: true},+ {path: "docs/sub", isDir: true},+ {path: "docs/sub/a.txt", content: "a"},+ {path: "archive", isDir: true},+ {path: "archive/sub", isDir: true},+ },+ req: moveRequest{Source: "docs", Destination: "archive", Force: true},+ wantStatus: http.StatusOK,+ wantPaths: []string{"archive", "archive/sub", "archive/sub/a.txt"},+ wantResponsePaths: []string{"archive/sub/a.txt"},+ wantEvents: []resourceEvent{+ {action: "updated", path: "archive/sub/a.txt"},+ {action: "deleted", path: "docs/sub"},+ {action: "deleted", path: "docs"},+ },+ },+ {+ name: "directory merge file over existing directory conflicts",+ seeds: []seed{{path: "docs", isDir: true}, {path: "docs/a.txt", content: "a"}, {path: "archive", isDir: true}, {path: "archive/a.txt", isDir: true}},+ req: moveRequest{Source: "docs", Destination: "archive", Force: true},+ wantStatus: http.StatusConflict,+ wantPaths: []string{"archive", "archive/a.txt", "docs", "docs/a.txt"},+ },+ {+ name: "directory into itself is invalid",+ seeds: []seed{{path: "docs", isDir: true}},+ req: moveRequest{Source: "docs", Destination: "docs/archive", Force: true},+ wantStatus: http.StatusBadRequest,+ wantPaths: []string{"docs"},+ },+ {+ name: "same source and destination is invalid",+ seeds: []seed{{path: "a.txt", content: "a"}},+ req: moveRequest{Source: "a.txt", Destination: "a.txt", Force: true},+ wantStatus: http.StatusBadRequest,+ wantPaths: []string{"a.txt"},+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ db := setupResourceServiceTestDB(t)+ dataDir := t.TempDir()+ ss := &captureSubscriptions{}+ svc := NewResourceService(db, dataDir, ss)+ deletedHashes := map[string]string{}+ for _, rec := range tt.seeds {+ seeded := models.UserResource{+ UserID: 1,+ Name: filepath.Base(rec.path),+ Path: rec.path,+ IsDir: rec.isDir,+ }+ if !rec.isDir {+ seeded.Hash = md5HexForService(rec.content)+ seeded.Size = int64(len(rec.content))+ writeResourceBlob(t, dataDir, seeded.Hash, rec.content)+ deletedHashes[rec.content] = seeded.Hash+ }+ seedResource(t, db, seeded)+ }++ bodyBytes, err := json.Marshal(tt.req)+ require.NoError(t, err)+ c, w := newResourceTestContext(http.MethodPut, "/resources/move", bytes.NewBuffer(bodyBytes), []string{"resources.edit"})+ c.Request.Header.Set("Content-Type", "application/json")++ svc.MoveResource(c)++ require.Equal(t, tt.wantStatus, w.Code)+ assert.ElementsMatch(t, tt.wantPaths, allResourcePaths(t, db))+ assert.Equal(t, tt.wantEvents, ss.events)+ if tt.wantStatus == http.StatusOK {+ list := decodeResourceListResponse(t, w)+ assert.ElementsMatch(t, tt.wantResponsePaths, resourcePaths(list.Items))+ }+ for _, content := range tt.wantDeletedBlobTexts {+ _, err := os.Lstat(resources.BlobPath(dataDir, deletedHashes[content]))+ assert.True(t, os.IsNotExist(err), "blob for %q should be removed", content)+ }+ })+ }+}++func TestResourceService_QueryResources(t *testing.T) {+ db := setupResourceServiceTestDB(t)+ svc := NewResourceService(db, t.TempDir(), nil)++ seedResource(t, db, models.UserResource{UserID: 1, Hash: md5HexForService("root"), Name: "root.txt", Path: "root.txt", Size: 4})+ seedResource(t, db, models.UserResource{UserID: 1, Name: "docs", Path: "docs", IsDir: true})+ seedResource(t, db, models.UserResource{UserID: 1, Hash: md5HexForService("a"), Name: "a.txt", Path: "docs/a.txt", Size: 1})+ seedResource(t, db, models.UserResource{UserID: 1, Name: "sub", Path: "docs/sub", IsDir: true})+ seedResource(t, db, models.UserResource{UserID: 1, Hash: md5HexForService("b"), Name: "b.txt", Path: "docs/sub/b.txt", Size: 1})+ seedResource(t, db, models.UserResource{UserID: 2, Hash: md5HexForService("other"), Name: "other.txt", Path: "other.txt", Size: 5})++ root, err := svc.queryResources(1, false, "", false)+ require.NoError(t, err)+ assert.ElementsMatch(t, []string{"root.txt", "docs"}, resourcePaths(root))++ docs, err := svc.queryResources(1, false, "docs", false)+ require.NoError(t, err)+ assert.ElementsMatch(t, []string{"docs", "docs/a.txt", "docs/sub"}, resourcePaths(docs))++ recursive, err := svc.queryResources(1, false, "docs", true)+ require.NoError(t, err)+ assert.ElementsMatch(t, []string{"docs", "docs/a.txt", "docs/sub", "docs/sub/b.txt"}, resourcePaths(recursive))++ adminRoot, err := svc.queryResources(1, true, "", false)+ require.NoError(t, err)+ assert.ElementsMatch(t, []string{"root.txt", "docs", "other.txt"}, resourcePaths(adminRoot))+}++func TestResourceService_CleanupOrphanBlobs(t *testing.T) {+ db := setupResourceServiceTestDB(t)+ dataDir := t.TempDir()+ svc := NewResourceService(db, dataDir, nil)+ referencedHash := md5HexForService("referenced")+ orphanHash := md5HexForService("orphan")+ writeResourceBlob(t, dataDir, referencedHash, "referenced")+ writeResourceBlob(t, dataDir, orphanHash, "orphan")+ seedResource(t, db, models.UserResource{+ UserID: 1,+ Hash: referencedHash,+ Name: "referenced.txt",+ Path: "referenced.txt",+ Size: 10,+ })++ svc.cleanupOrphanBlobs(context.Background(), []string{referencedHash, orphanHash})++ _, err := os.Lstat(resources.BlobPath(dataDir, referencedHash))+ require.NoError(t, err)+ _, err = os.Lstat(resources.BlobPath(dataDir, orphanHash))+ assert.True(t, os.IsNotExist(err))+}++func TestResourceService_ConvertResourceToModel(t *testing.T) {+ entry := models.ResourceEntry{+ ID: 42,+ UserID: 7,+ Name: "report.txt",+ Path: "docs/report.txt",+ Size: 123,+ IsDir: false,+ }++ modelResource := convertResourceToModel(entry)++ require.NotNil(t, modelResource)+ assert.Equal(t, entry.ID, modelResource.ID)+ assert.Equal(t, int64(entry.UserID), modelResource.UserID)+ assert.Equal(t, entry.Name, modelResource.Name)+ assert.Equal(t, entry.Path, modelResource.Path)+ assert.Equal(t, int(entry.Size), modelResource.Size)+ assert.Equal(t, entry.IsDir, modelResource.IsDir)+}++func writeResourceBlob(t *testing.T, dataDir, hash, content string) {+ t.Helper()++ blobPath := resources.BlobPath(dataDir, hash)+ require.NoError(t, os.MkdirAll(filepath.Dir(blobPath), 0755))+ require.NoError(t, os.WriteFile(blobPath, []byte(content), 0644))+}++func md5HexForService(content string) string {+ sum := md5.Sum([]byte(content))+ return hex.EncodeToString(sum[:])+}diff --git a/backend/pkg/templates/prompts/adviser.tmpl b/backend/pkg/templates/prompts/adviser.tmplindex 37ae0c13..6185195d 100644--- a/backend/pkg/templates/prompts/adviser.tmpl+++ b/backend/pkg/templates/prompts/adviser.tmpl@@ -269,6 +269,20 @@ When YOU lack confident understanding of optimal solution:<execution_context>{{.ExecutionContext}}</execution_context>+{{if .UserFiles}}++## TASK MATERIALS++<task_materials_protocol>+These files are part of the engagement being advised on and are available READ-ONLY in the container:+- `{{.Cwd}}/uploads` — files delivered specifically for this flow+- `{{.Cwd}}/resources` — reference materials prepared for this engagement++When advising on tasks that reference specific filenames, account for these files being available at the full path `<base>/<relative_path>`. These directories are READ-ONLY.+</task_materials_protocol>++{{.UserFiles}}+{{end}}## DATA INTERPRETATIONdiff --git a/backend/pkg/templates/prompts/assistant.tmpl b/backend/pkg/templates/prompts/assistant.tmplindex 4c3302aa..cfe4a33e 100644--- a/backend/pkg/templates/prompts/assistant.tmpl+++ b/backend/pkg/templates/prompts/assistant.tmpl@@ -228,6 +228,23 @@ You are a specialized AI assistant for penetration testing and security engineer<execution_context>{{.ExecutionContext}}</execution_context>+{{if .UserFiles}}++## TASK MATERIALS++<task_materials_protocol>+The following files were provided by the user and are available READ-ONLY in the container for this session:+- `{{.Cwd}}/uploads` — files the user uploaded for this session+- `{{.Cwd}}/resources` — reference materials the user considers important for this engagement++Rules:+- Access any file by combining its `base` path with the listed relative path: `<base>/<relative_path>`+- If the user mentions a filename that matches an entry here, that is the file they are referring to+- These directories are READ-ONLY — write all outputs to `{{.Cwd}}/`+</task_materials_protocol>++{{.UserFiles}}+{{end}}## SENIOR MENTOR SUPERVISIONdiff --git a/backend/pkg/templates/prompts/coder.tmpl b/backend/pkg/templates/prompts/coder.tmplindex 05efff90..d9946ab2 100644--- a/backend/pkg/templates/prompts/coder.tmpl+++ b/backend/pkg/templates/prompts/coder.tmpl@@ -245,6 +245,23 @@ Use both:<execution_context>{{.ExecutionContext}}</execution_context>+{{if .UserFiles}}++## TASK MATERIALS++<task_materials_protocol>+The following files are attached to this coding assignment and are available READ-ONLY in the container:+- `{{.Cwd}}/uploads` — files delivered for this task (source code, binaries, data samples)+- `{{.Cwd}}/resources` — reference materials prepared for this engagement++Rules:+- Access any file by combining its `base` path with the listed relative path: `<base>/<relative_path>`+- If the task description references a filename present in this list, use the full path when reading it+- These directories are READ-ONLY — write all outputs and modified copies to `{{.Cwd}}/`+</task_materials_protocol>++{{.UserFiles}}+{{end}}## SENIOR MENTOR SUPERVISIONdiff --git a/backend/pkg/templates/prompts/enricher.tmpl b/backend/pkg/templates/prompts/enricher.tmplindex bbd53d7f..3ed9254f 100644--- a/backend/pkg/templates/prompts/enricher.tmpl+++ b/backend/pkg/templates/prompts/enricher.tmpl@@ -214,6 +214,20 @@ Example bad enrichments:<execution_context>{{.ExecutionContext}}</execution_context>+{{if .UserFiles}}++## TASK MATERIALS++<task_materials_protocol>+The following files are attached to this flow and available READ-ONLY in the container:+- `{{.Cwd}}/uploads` — files delivered specifically for this flow+- `{{.Cwd}}/resources` — reference materials for this engagement++If the question relates to these files, read their contents using `{{.FileToolName}}` with the full path `<base>/<relative_path>` and include relevant excerpts in the enrichment result. These directories are READ-ONLY.+</task_materials_protocol>++{{.UserFiles}}+{{end}}## COMPLETION REQUIREMENTSdiff --git a/backend/pkg/templates/prompts/generator.tmpl b/backend/pkg/templates/prompts/generator.tmplindex be72be28..f4870790 100644--- a/backend/pkg/templates/prompts/generator.tmpl+++ b/backend/pkg/templates/prompts/generator.tmpl@@ -179,5 +179,19 @@ You MUST complete your analysis by using the "{{.SubtaskListToolName}}" tool wit- A complete, ordered list of subtasks meeting the above requirements- Brief explanation of how the plan follows the optimal task distribution structure- Confirmation that all aspects of the user's request will be addressed+{{if .UserFiles}}++## TASK MATERIALS++<task_materials_protocol>+The following files are attached to this flow and available READ-ONLY in the container at `{{.Cwd}}`:+- `{{.Cwd}}/uploads` — files delivered specifically for this flow+- `{{.Cwd}}/resources` — reference materials prepared for this engagement++When generating subtasks: if the task description references a filename present in this list, include the full path (`<base>/<relative_path>`) explicitly in the relevant subtask descriptions so the executing agent can locate the file without ambiguity. These directories are READ-ONLY.+</task_materials_protocol>++{{.UserFiles}}+{{end}}{{.ToolPlaceholder}}diff --git a/backend/pkg/templates/prompts/installer.tmpl b/backend/pkg/templates/prompts/installer.tmplindex 56603b8e..c5fec645 100644--- a/backend/pkg/templates/prompts/installer.tmpl+++ b/backend/pkg/templates/prompts/installer.tmpl@@ -154,6 +154,23 @@ You are an elite DevOps engineer specialized in infrastructure maintenance, inst<execution_context>{{.ExecutionContext}}</execution_context>+{{if .UserFiles}}++## TASK MATERIALS++<task_materials_protocol>+The following files are attached to this assignment and are available READ-ONLY in the container:+- `{{.Cwd}}/uploads` — files delivered for this task (scripts, packages, configuration files)+- `{{.Cwd}}/resources` — reference materials prepared for this engagement++Rules:+- Access any file by combining its `base` path with the listed relative path: `<base>/<relative_path>`+- If the task references a filename present in this list, use the full path when reading or executing it+- These directories are READ-ONLY — copy files to `{{.Cwd}}/` before modifying them+</task_materials_protocol>++{{.UserFiles}}+{{end}}## SENIOR MENTOR SUPERVISIONdiff --git a/backend/pkg/templates/prompts/memorist.tmpl b/backend/pkg/templates/prompts/memorist.tmplindex 32cc5b4a..051ed863 100644--- a/backend/pkg/templates/prompts/memorist.tmpl+++ b/backend/pkg/templates/prompts/memorist.tmpl@@ -203,6 +203,20 @@ Vector database provides the "library" of reusable solutions.<execution_context>{{.ExecutionContext}}</execution_context>+{{if .UserFiles}}++## TASK MATERIALS++<task_materials_protocol>+The following files are attached to this flow and available READ-ONLY in the container:+- `{{.Cwd}}/uploads` — files delivered specifically for this flow+- `{{.Cwd}}/resources` — reference materials prepared for this engagement++If memory retrieval requires verifying or cross-referencing file contents, access them using the full path (`<base>/<relative_path>`). These directories are READ-ONLY.+</task_materials_protocol>++{{.UserFiles}}+{{end}}## COMPLETION REQUIREMENTSdiff --git a/backend/pkg/templates/prompts/pentester.tmpl b/backend/pkg/templates/prompts/pentester.tmplindex 925700e9..95b15d15 100644--- a/backend/pkg/templates/prompts/pentester.tmpl+++ b/backend/pkg/templates/prompts/pentester.tmpl@@ -347,6 +347,23 @@ If you see hanging or port conflicts: `pkill -f msfconsole`, verify with `ps aux<execution_context>{{.ExecutionContext}}</execution_context>+{{if .UserFiles}}++## TASK MATERIALS++<task_materials_protocol>+The following files are attached to this engagement and are available READ-ONLY in the container:+- `{{.Cwd}}/uploads` — files delivered for this engagement (target lists, credentials, configurations, custom scripts)+- `{{.Cwd}}/resources` — reference materials (scope definitions, prior findings, wordlists)++Rules:+- Access any file by combining its `base` path with the listed relative path: `<base>/<relative_path>`+- If the task description references a filename present in this list, use the full path when referencing it in commands+- These directories are READ-ONLY — write all outputs to `{{.Cwd}}/`+</task_materials_protocol>++{{.UserFiles}}+{{end}}## SENIOR MENTOR SUPERVISIONdiff --git a/backend/pkg/templates/prompts/primary_agent.tmpl b/backend/pkg/templates/prompts/primary_agent.tmplindex 6f055f89..96f5e3b7 100644--- a/backend/pkg/templates/prompts/primary_agent.tmpl+++ b/backend/pkg/templates/prompts/primary_agent.tmpl@@ -197,6 +197,23 @@ You are the primary task orchestrator for a specialized engineering and penetrat<execution_context>{{.ExecutionContext}}</execution_context>+{{if .UserFiles}}++## TASK MATERIALS++<task_materials_protocol>+The following files are attached to this flow as part of the task assignment and are available READ-ONLY inside the container:+- `{{.Cwd}}/uploads` — files delivered specifically for this flow+- `{{.Cwd}}/resources` — reference materials prepared for this engagement++Rules:+- Access any file by combining its `base` path with the listed relative path: `<base>/<relative_path>`+- When delegating to specialists, pass the full absolute path+- These directories are READ-ONLY — write all outputs elsewhere (e.g., `{{.Cwd}}/`)+</task_materials_protocol>++{{.UserFiles}}+{{end}}## SENIOR MENTOR SUPERVISIONdiff --git a/backend/pkg/templates/prompts/refiner.tmpl b/backend/pkg/templates/prompts/refiner.tmplindex d5b65867..17803c02 100644--- a/backend/pkg/templates/prompts/refiner.tmpl+++ b/backend/pkg/templates/prompts/refiner.tmpl@@ -221,5 +221,19 @@ You MUST complete your refinement by using the "{{.SubtaskPatchToolName}}" tool- A clear explanatory message summarizing progress and changes made- Justification for any significant modifications- Brief analysis of completed tasks' outcomes and how they inform the refined plan+{{if .UserFiles}}++## TASK MATERIALS++<task_materials_protocol>+The following files are attached to this flow and available READ-ONLY in the container at `{{.Cwd}}`:+- `{{.Cwd}}/uploads` — files delivered specifically for this flow+- `{{.Cwd}}/resources` — reference materials prepared for this engagement++When refining subtasks: if a remaining subtask references a filename present in this list, include the full path (`<base>/<relative_path>`) explicitly in its description so the executing agent can locate the file without ambiguity. These directories are READ-ONLY.+</task_materials_protocol>++{{.UserFiles}}+{{end}}{{.ToolPlaceholder}}diff --git a/backend/pkg/templates/prompts/reporter.tmpl b/backend/pkg/templates/prompts/reporter.tmplindex 034406e2..a8944dd3 100644--- a/backend/pkg/templates/prompts/reporter.tmpl+++ b/backend/pkg/templates/prompts/reporter.tmpl@@ -98,5 +98,19 @@ You MUST complete your evaluation by using the "{{.ReportResultToolName}}" tool- A clear success/failure assessment in the "success" field (true/false)- A detailed report in the "result" field explaining your assessment with evidence- A concise message in the "message" field summarizing the key outcome for the user+{{if .UserFiles}}++## TASK MATERIALS++<task_materials_protocol>+The following files were attached to this engagement and available READ-ONLY in the container during execution:+- `{{.Cwd}}/uploads` — files delivered for this flow+- `{{.Cwd}}/resources` — reference materials for this engagement++When evaluating whether file-related subtasks were completed correctly, account for these materials. If the original task referenced specific filenames present in this list, verify that the corresponding work addressed those files.+</task_materials_protocol>++{{.UserFiles}}+{{end}}{{.ToolPlaceholder}}diff --git a/backend/pkg/templates/prompts/searcher.tmpl b/backend/pkg/templates/prompts/searcher.tmplindex dee08bea..f6f5f7b6 100644--- a/backend/pkg/templates/prompts/searcher.tmpl+++ b/backend/pkg/templates/prompts/searcher.tmpl@@ -108,6 +108,20 @@ You are an elite search intelligence agent optimized for maximum efficiency. You<execution_context>{{.ExecutionContext}}</execution_context>+{{if .UserFiles}}++## TASK MATERIALS++<task_materials_protocol>+The following files are attached to this flow as engagement context:+- `{{.Cwd}}/uploads` — files delivered specifically for this flow+- `{{.Cwd}}/resources` — reference materials for this engagement++These files are available to other agents in the container. If the search task involves researching a topic related to these files (e.g., a tool, format, or technique referenced by filename), factor them into the search strategy.+</task_materials_protocol>++{{.UserFiles}}+{{end}}## OPERATIONAL PROTOCOLSdiff --git a/backend/pkg/templates/templates.go b/backend/pkg/templates/templates.goindex 8ad23038..4767c752 100644--- a/backend/pkg/templates/templates.go+++ b/backend/pkg/templates/templates.go@@ -81,10 +81,12 @@ var PromptVariables = map[PromptType][]string{"AskUserToolName","AskUserEnabled","ExecutionContext",+ "Cwd","Lang","DockerImage","CurrentTime","ToolPlaceholder",+ "UserFiles",},PromptTypeAssistant: {"SearchToolName",@@ -119,6 +121,7 @@ var PromptVariables = map[PromptType][]string{"StopFlowToolName","SubmitFlowInputToolName","PatchFlowSubtasksToolName",+ "UserFiles",},PromptTypePentester: {"HackResultToolName",@@ -141,6 +144,7 @@ var PromptVariables = map[PromptType][]string{"Lang","CurrentTime","ToolPlaceholder",+ "UserFiles",},PromptTypeQuestionPentester: {"Question",@@ -164,6 +168,7 @@ var PromptVariables = map[PromptType][]string{"Lang","CurrentTime","ToolPlaceholder",+ "UserFiles",},PromptTypeQuestionCoder: {"Question",@@ -184,6 +189,7 @@ var PromptVariables = map[PromptType][]string{"Lang","CurrentTime","ToolPlaceholder",+ "UserFiles",},PromptTypeQuestionInstaller: {"Question",@@ -195,9 +201,11 @@ var PromptVariables = map[PromptType][]string{"SummarizationToolName","SummarizedContentPrefix","ExecutionContext",+ "Cwd","Lang","CurrentTime","ToolPlaceholder",+ "UserFiles",},PromptTypeQuestionSearcher: {"Question",@@ -219,6 +227,7 @@ var PromptVariables = map[PromptType][]string{"Lang","CurrentTime","ToolPlaceholder",+ "UserFiles",},PromptTypeQuestionMemorist: {"Question",@@ -243,6 +252,7 @@ var PromptVariables = map[PromptType][]string{"DockerImage","Cwd","ContainerPorts",+ "UserFiles",},PromptTypeQuestionAdviser: {"InitiatorAgent",@@ -260,10 +270,12 @@ var PromptVariables = map[PromptType][]string{"SummarizationToolName","SummarizedContentPrefix","DockerImage",+ "Cwd","Lang","CurrentTime","N","ToolPlaceholder",+ "UserFiles",},PromptTypeSubtasksGenerator: {"Task",@@ -279,10 +291,12 @@ var PromptVariables = map[PromptType][]string{"SummarizationToolName","SummarizedContentPrefix","DockerImage",+ "Cwd","Lang","CurrentTime","N","ToolPlaceholder",+ "UserFiles",},PromptTypeSubtasksRefiner: {"Task",@@ -296,9 +310,11 @@ var PromptVariables = map[PromptType][]string{"ReportResultToolName","SummarizationToolName","SummarizedContentPrefix",+ "Cwd","Lang","N","ToolPlaceholder",+ "UserFiles",},PromptTypeTaskReporter: {"Task",@@ -323,6 +339,7 @@ var PromptVariables = map[PromptType][]string{"SummarizationToolName","SummarizedContentPrefix","ExecutionContext",+ "Cwd","Lang","CurrentTime","ToolPlaceholder",@@ -332,6 +349,7 @@ var PromptVariables = map[PromptType][]string{"FileToolName","TerminalToolName","BrowserToolName",+ "UserFiles",},PromptTypeQuestionEnricher: {"Question",diff --git a/backend/pkg/templates/validator/testdata.go b/backend/pkg/templates/validator/testdata.goindex 15385c45..3b4612e4 100644--- a/backend/pkg/templates/validator/testdata.go+++ b/backend/pkg/templates/validator/testdata.go@@ -100,6 +100,11 @@ func CreateDummyTemplateData() map[string]any {// Numeric limits"N": providers.TasksNumberLimit,+ "UserFiles": "<user_files>\nUser-provided files for this flow. Use them as input data.\n" ++ "<uploads>\n/work/uploads/test_file_1.txt\n</uploads>\n" ++ "<resources>\n/work/resources/test_file_2.txt\n</resources>\n" ++ "</user_files>",+// Input/Output data"Input": "Test input for the task","Question": "Test question for processing",diff --git a/backend/pkg/tools/terminal_test.go b/backend/pkg/tools/terminal_test.goindex dc771d04..11516e3d 100644--- a/backend/pkg/tools/terminal_test.go+++ b/backend/pkg/tools/terminal_test.go@@ -266,6 +266,93 @@ func TestWriteUploadsTar(t *testing.T) {assert.NotContains(t, contents, "uploads/link.txt")}+func TestCollectFileSyncEntries(t *testing.T) {+ localDir := t.TempDir()+ requireNoError := func(err error) {+ if err != nil {+ t.Fatal(err)+ }+ }+ requireNoError(os.MkdirAll(filepath.Join(localDir, "targets"), 0755))+ requireNoError(os.WriteFile(filepath.Join(localDir, "targets", "ips.txt"), []byte("127.0.0.1"), 0644))+ requireNoError(os.WriteFile(filepath.Join(localDir, "top.txt"), []byte("top"), 0644))+ if err := os.Symlink(filepath.Join(localDir, "top.txt"), filepath.Join(localDir, "link.txt")); err != nil {+ t.Skipf("symlink creation not available: %v", err)+ }++ entries, err := collectFileSyncEntries(localDir, flowfiles.UploadsDirName)+ assert.NoError(t, err)++ byTarPath := map[string]fileSyncEntry{}+ for _, entry := range entries {+ byTarPath[entry.tarPath] = entry+ }++ assert.Contains(t, byTarPath, "uploads/top.txt")+ assert.Contains(t, byTarPath, "uploads/targets/ips.txt")+ assert.NotContains(t, byTarPath, "uploads/link.txt")+ assert.Equal(t, docker.WorkFolderPathInContainer+"/uploads/top.txt", byTarPath["uploads/top.txt"].containerPath)+ assert.Equal(t, filepath.Join(localDir, "top.txt"), byTarPath["uploads/top.txt"].localPath)+}++func TestCollectFileSyncEntriesMissingDir(t *testing.T) {+ entries, err := collectFileSyncEntries(filepath.Join(t.TempDir(), "missing"), flowfiles.ResourcesDirName)+ assert.NoError(t, err)+ assert.Empty(t, entries)+}++func TestConvertSyncEntriesToTarEntries(t *testing.T) {+ entries := []fileSyncEntry{+ {localPath: "/tmp/a.txt", tarPath: "uploads/a.txt"},+ {localPath: "/tmp/b.txt", tarPath: "resources/b.txt"},+ }++ tarEntries := convertSyncEntriesToTarEntries(entries)++ assert.Equal(t, []flowfiles.TarEntry{+ {LocalPath: "/tmp/a.txt", TarPath: "uploads/a.txt"},+ {LocalPath: "/tmp/b.txt", TarPath: "resources/b.txt"},+ }, tarEntries)+}++func TestFindMissingInContainer(t *testing.T) {+ mock := &contextAwareMockDockerClient{+ execCreateResp: container.ExecCreateResponse{ID: "exec-file-check"},+ attachOutput: []byte(+ docker.WorkFolderPathInContainer + "/uploads/a.txt\n" ++ docker.WorkFolderPathInContainer + "/resources/b.txt\n" ++ docker.WorkFolderPathInContainer + "/unknown.txt\n",+ ),+ inspectResp: container.ExecInspect{ExitCode: 0},+ }+ fte := &flowToolsExecutor{flowID: 7, docker: mock}+ entries := []fileSyncEntry{+ {localPath: "/tmp/a.txt", containerPath: docker.WorkFolderPathInContainer + "/uploads/a.txt", tarPath: "uploads/a.txt"},+ {localPath: "/tmp/b.txt", containerPath: docker.WorkFolderPathInContainer + "/resources/b.txt", tarPath: "resources/b.txt"},+ }++ missing, err := fte.findMissingInContainer(t.Context(), entries)++ assert.NoError(t, err)+ assert.Equal(t, entries, missing)+}++func TestFindMissingInContainerChecksExitCode(t *testing.T) {+ mock := &contextAwareMockDockerClient{+ execCreateResp: container.ExecCreateResponse{ID: "exec-file-check"},+ attachOutput: []byte("shell failed"),+ inspectResp: container.ExecInspect{ExitCode: 2},+ }+ fte := &flowToolsExecutor{flowID: 7, docker: mock}++ _, err := fte.findMissingInContainer(t.Context(), []fileSyncEntry{+ {containerPath: docker.WorkFolderPathInContainer + "/uploads/a.txt"},+ })++ assert.Error(t, err)+ assert.Contains(t, err.Error(), "exit code 2")+}+func TestConfiguredExecTimeout(t *testing.T) {t.Parallel()diff --git a/backend/pkg/tools/tools.go b/backend/pkg/tools/tools.goindex cf986b14..5e792cac 100644--- a/backend/pkg/tools/tools.go+++ b/backend/pkg/tools/tools.go@@ -3,10 +3,14 @@ package toolsimport ("context""encoding/json"+ "errors""fmt""io"+ "io/fs""os"+ "path""path/filepath"+ "strings""time""pentagi/pkg/config"@@ -414,8 +418,8 @@ 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)+ if err := fte.syncMissingFiles(ctx); err != nil {+ return fmt.Errorf("failed to sync missing files to container '%s': %w", PrimaryTerminalName(fte.flowID), err)}return nildefault:@@ -449,81 +453,193 @@ 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)+ if err := fte.syncMissingFiles(ctx); err != nil {+ return fmt.Errorf("failed to sync files to container '%s': %w", containerName, err)}return nil}-func (fte *flowToolsExecutor) syncCachedUploads(ctx context.Context) error {- uploadDir, err := fte.cachedUploadsDir()+// fileSyncEntry maps a local host file to its expected path inside the container.+type fileSyncEntry struct {+ localPath string // absolute path on host+ containerPath string // absolute path in container, e.g. /work/uploads/file.txt+ tarPath string // relative tar path (relative to /work/), e.g. uploads/file.txt+}++// syncMissingFiles is the single method responsible for keeping uploads/ and resources/+// in sync with the container. It collects all local files, checks which are absent in the+// container with ONE exec call, then copies only the missing ones in a single tar stream.+func (fte *flowToolsExecutor) syncMissingFiles(ctx context.Context) error {+ entries, err := fte.collectSyncEntries()if err != nil {return err}-- containerName := PrimaryTerminalName(fte.flowID)- if err := fte.resetContainerUploads(ctx, containerName); err != nil {- return err+ if len(entries) == 0 {+ return nil}- entries, err := os.ReadDir(uploadDir)+ missing, err := fte.findMissingInContainer(ctx, entries)if err != nil {- if os.IsNotExist(err) {- return nil- }- return fmt.Errorf("failed to read uploads cache directory: %w", err)+ return err}- if len(entries) == 0 {+ if len(missing) == 0 {return nil}- pr, pw := io.Pipe()- errCh := make(chan error, 1)- go func() {- errCh <- flowfiles.WriteUploadsTar(pw, uploadDir)- }()+ return fte.copyEntriesToContainer(ctx, missing)+}- copyErr := fte.docker.CopyToContainer(ctx, containerName, docker.WorkFolderPathInContainer, pr,- container.CopyToContainerOptions{AllowOverwriteDirWithFile: true})- pr.Close()- writeErr := <-errCh- if copyErr != nil {- return copyErr+// collectSyncEntries walks uploads/ and resources/ on disk and returns sync entries.+func (fte *flowToolsExecutor) collectSyncEntries() ([]fileSyncEntry, error) {+ var entries []fileSyncEntry++ uploadsDir, err := fte.cachedUploadsDir()+ if err != nil {+ return nil, err+ }+ if uploadsEntries, err := collectFileSyncEntries(uploadsDir, flowfiles.UploadsDirName); err != nil {+ return nil, fmt.Errorf("failed to collect uploads: %w", err)+ } else {+ entries = append(entries, uploadsEntries...)}- return writeErr+ resourcesDir, err := fte.cachedResourcesDir()+ if err != nil {+ return nil, err+ }+ if resourcesEntries, err := collectFileSyncEntries(resourcesDir, flowfiles.ResourcesDirName); err != nil {+ return nil, fmt.Errorf("failed to collect resources: %w", err)+ } else {+ entries = append(entries, resourcesEntries...)+ }++ return entries, nil}-func (fte *flowToolsExecutor) resetContainerUploads(ctx context.Context, containerName string) error {+// collectFileSyncEntries walks localDir and builds sync entries using dirName as the+// top-level name inside /work/ (e.g. "uploads" or "resources").+func collectFileSyncEntries(localDir, dirName string) ([]fileSyncEntry, error) {+ var entries []fileSyncEntry+ err := filepath.WalkDir(localDir, func(entryPath string, d fs.DirEntry, err error) error {+ if err != nil {+ if errors.Is(err, os.ErrNotExist) {+ return nil+ }+ return err+ }+ if entryPath == localDir || d.IsDir() {+ return nil+ }+ if d.Type()&os.ModeSymlink != 0 || !d.Type().IsRegular() {+ return nil+ }++ rel, err := filepath.Rel(localDir, entryPath)+ if err != nil {+ return err+ }+ tarPath := path.Join(dirName, filepath.ToSlash(rel))+ entries = append(entries, fileSyncEntry{+ localPath: entryPath,+ containerPath: docker.WorkFolderPathInContainer + "/" + tarPath,+ tarPath: tarPath,+ })+ return nil+ })++ return entries, err+}++// findMissingInContainer executes a single shell command inside the container that tests+// the existence of every expected file and outputs the container path of each missing one.+// This is the only exec call needed in the happy-path (all files already present → returns empty).+func (fte *flowToolsExecutor) findMissingInContainer(ctx context.Context, entries []fileSyncEntry) ([]fileSyncEntry, error) {+ // sh -c 'for f in "$@"; do [ -f "$f" ] || printf "%s\n" "$f"; done' -- /path1 /path2 …+ cmd := make([]string, 0, len(entries)+4)+ cmd = append(cmd, "sh", "-c",+ `for f in "$@"; do [ -f "$f" ] || printf '%s\n' "$f"; done`, "--")+ for _, e := range entries {+ cmd = append(cmd, e.containerPath)+ }++ containerName := PrimaryTerminalName(fte.flowID)createResp, err := fte.docker.ContainerExecCreate(ctx, containerName, container.ExecOptions{- Cmd: []string{"sh", "-c", "rm -rf -- /work/uploads && mkdir -p -- /work/uploads"},+ Cmd: cmd,AttachStdout: true,AttachStderr: true,})if err != nil {- return fmt.Errorf("failed to create uploads reset exec: %w", err)+ return nil, fmt.Errorf("failed to create file-check 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)+ return nil, fmt.Errorf("failed to attach file-check exec: %w", err)}- output, copyErr := io.ReadAll(resp.Reader)+ output, readErr := io.ReadAll(resp.Reader)resp.Close()- if copyErr != nil {- return fmt.Errorf("failed to read uploads reset output: %w", copyErr)+ if readErr != nil {+ return nil, fmt.Errorf("failed to read file-check output: %w", readErr)}-inspect, err := fte.docker.ContainerExecInspect(ctx, createResp.ID)if err != nil {- return fmt.Errorf("failed to inspect uploads reset exec: %w", err)+ return nil, fmt.Errorf("failed to inspect file-check 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, fmt.Errorf("file-check exec failed with exit code %d: %s", inspect.ExitCode, strings.TrimSpace(string(output)))}- return nil+ // Build a lookup map for O(1) access.+ byContainerPath := make(map[string]fileSyncEntry, len(entries))+ for _, e := range entries {+ byContainerPath[e.containerPath] = e+ }++ var missing []fileSyncEntry+ for _, line := range strings.Split(string(output), "\n") {+ line = strings.TrimSpace(line)+ if line == "" {+ continue+ }+ if e, ok := byContainerPath[line]; ok {+ missing = append(missing, e)+ }+ }++ return missing, nil+}++// copyEntriesToContainer writes all missing files as a single tar stream into the container.+func (fte *flowToolsExecutor) copyEntriesToContainer(ctx context.Context, entries []fileSyncEntry) error {+ pr, pw := io.Pipe()+ errCh := make(chan error, 1)+ go func() {+ errCh <- flowfiles.WriteFilesTar(pw, convertSyncEntriesToTarEntries(entries))+ }()++ containerName := PrimaryTerminalName(fte.flowID)+ 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 convertSyncEntriesToTarEntries(entries []fileSyncEntry) []flowfiles.TarEntry {+ tarEntries := make([]flowfiles.TarEntry, 0, len(entries))+ for _, entry := range entries {+ tarEntries = append(tarEntries, flowfiles.TarEntry{+ LocalPath: entry.localPath,+ TarPath: entry.tarPath,+ })+ }+ return tarEntries}func (fte *flowToolsExecutor) cachedUploadsDir() (string, error) {@@ -535,6 +651,15 @@ func (fte *flowToolsExecutor) cachedUploadsDir() (string, error) {return flowfiles.FlowUploadsDir(dataDir, uint64(fte.flowID)), nil}+func (fte *flowToolsExecutor) cachedResourcesDir() (string, error) {+ dataDir, err := filepath.Abs(fte.cfg.DataDir)+ if err != nil {+ return "", fmt.Errorf("failed to resolve data directory: %w", err)+ }++ return flowfiles.FlowResourcesDir(dataDir, uint64(fte.flowID)), nil+}+func (fte *flowToolsExecutor) Release(ctx context.Context) error {if fte.store != nil {fte.store.Close()diff --git a/backend/sqlc/models/resources.sql b/backend/sqlc/models/resources.sqlnew file mode 100644index 00000000..0137381e--- /dev/null+++ b/backend/sqlc/models/resources.sql@@ -0,0 +1,50 @@+-- name: GetUserResourcesRoot :many+SELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_at+FROM user_resources+WHERE user_id = sqlc.arg(user_id) AND path NOT LIKE '%/%'+ORDER BY updated_at DESC, name ASC;++-- name: GetUserResourcesInDir :many+SELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_at+FROM user_resources+WHERE user_id = sqlc.arg(user_id)+ AND ((path = sqlc.arg(dir_path) AND is_dir = true)+ OR (path LIKE sqlc.arg(child_prefix) AND path NOT LIKE sqlc.arg(deep_prefix)))+ORDER BY updated_at DESC, name ASC;++-- name: GetUserResourcesRecursive :many+SELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_at+FROM user_resources+WHERE user_id = sqlc.arg(user_id)+ AND (path = sqlc.arg(dir_path) OR path LIKE sqlc.arg(child_prefix))+ORDER BY updated_at DESC, name ASC;++-- name: GetAllResourcesRoot :many+SELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_at+FROM user_resources+WHERE path NOT LIKE '%/%'+ORDER BY updated_at DESC, name ASC;++-- name: GetAllResourcesInDir :many+SELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_at+FROM user_resources+WHERE (path = sqlc.arg(dir_path) AND is_dir = true)+ OR (path LIKE sqlc.arg(child_prefix) AND path NOT LIKE sqlc.arg(deep_prefix))+ORDER BY updated_at DESC, name ASC;++-- name: GetAllResourcesRecursive :many+SELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_at+FROM user_resources+WHERE path = sqlc.arg(dir_path) OR path LIKE sqlc.arg(child_prefix)+ORDER BY updated_at DESC, name ASC;++-- name: GetUserResourceByID :one+SELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_at+FROM user_resources+WHERE id = sqlc.arg(id);++-- name: GetUserResourcesByIDs :many+SELECT id, user_id, hash, name, path, size, is_dir, created_at, updated_at+FROM user_resources+WHERE id = ANY(sqlc.arg(ids)::bigint[])+ORDER BY id ASC;diff --git a/frontend/graphql-schema.graphql b/frontend/graphql-schema.graphqlindex eb1cc4e6..feff3487 100644--- a/frontend/graphql-schema.graphql+++ b/frontend/graphql-schema.graphql@@ -98,6 +98,17 @@ fragment flowFileFragment on FlowFile {modifiedAt}+fragment userResourceFragment on UserResource {+ id+ userId+ name+ path+ size+ isDir+ createdAt+ updatedAt+}+fragment agentLogFragment on AgentLog {idflowId@@ -787,6 +798,12 @@ query flowFiles($flowId: ID!) {}}+query resources($path: String, $recursive: Boolean) {+ resources(path: $path, recursive: $recursive) {+ ...userResourceFragment+ }+}+query assistants($flowId: ID!) {assistants(flowId: $flowId) {...assistantFragment@@ -977,8 +994,8 @@ mutation deleteFlowTemplate($templateId: ID!) {# ==================== Flows ====================-mutation createFlow($modelProvider: String!, $input: String!) {- createFlow(modelProvider: $modelProvider, input: $input) {+mutation createFlow($modelProvider: String!, $input: String!, $resourceIds: [ID!]) {+ createFlow(modelProvider: $modelProvider, input: $input, resourceIds: $resourceIds) {...flowFragment}}@@ -987,8 +1004,8 @@ mutation deleteFlow($flowId: ID!) {deleteFlow(flowId: $flowId)}-mutation putUserInput($flowId: ID!, $input: String!, $modelProvider: String) {- putUserInput(flowId: $flowId, input: $input, modelProvider: $modelProvider)+mutation putUserInput($flowId: ID!, $input: String!, $modelProvider: String, $resourceIds: [ID!]) {+ putUserInput(flowId: $flowId, input: $input, modelProvider: $modelProvider, resourceIds: $resourceIds)}mutation finishFlow($flowId: ID!) {@@ -1003,8 +1020,8 @@ mutation renameFlow($flowId: ID!, $title: String!) {renameFlow(flowId: $flowId, title: $title)}-mutation createAssistant($flowId: ID!, $modelProvider: String!, $input: String!, $useAgents: Boolean!) {- createAssistant(flowId: $flowId, modelProvider: $modelProvider, input: $input, useAgents: $useAgents) {+mutation createAssistant($flowId: ID!, $modelProvider: String!, $input: String!, $useAgents: Boolean!, $resourceIds: [ID!]) {+ createAssistant(flowId: $flowId, modelProvider: $modelProvider, input: $input, useAgents: $useAgents, resourceIds: $resourceIds) {flow {...flowFragment}@@ -1014,8 +1031,8 @@ mutation createAssistant($flowId: ID!, $modelProvider: String!, $input: String!,}}-mutation callAssistant($flowId: ID!, $assistantId: ID!, $input: String!, $useAgents: Boolean!) {- callAssistant(flowId: $flowId, assistantId: $assistantId, input: $input, useAgents: $useAgents)+mutation callAssistant($flowId: ID!, $assistantId: ID!, $input: String!, $useAgents: Boolean!, $resourceIds: [ID!]) {+ callAssistant(flowId: $flowId, assistantId: $assistantId, input: $input, useAgents: $useAgents, resourceIds: $resourceIds)}mutation stopAssistant($flowId: ID!, $assistantId: ID!) {@@ -1281,3 +1298,21 @@ subscription flowTemplateDeleted {...flowTemplateFragment}}++subscription resourceAdded {+ resourceAdded {+ ...userResourceFragment+ }+}++subscription resourceUpdated {+ resourceUpdated {+ ...userResourceFragment+ }+}++subscription resourceDeleted {+ resourceDeleted {+ ...userResourceFragment+ }+}diff --git a/frontend/src/graphql/types.ts b/frontend/src/graphql/types.tsindex fdd25c94..299bea6f 100644--- a/frontend/src/graphql/types.ts+++ b/frontend/src/graphql/types.ts@@ -423,6 +423,7 @@ export type MutationCallAssistantArgs = {assistantId: Scalars['ID']['input'];flowId: Scalars['ID']['input'];input: Scalars['String']['input'];+ resourceIds?: InputMaybe<Array<Scalars['ID']['input']>>;useAgents: Scalars['Boolean']['input'];};@@ -434,12 +435,14 @@ export type MutationCreateAssistantArgs = {flowId: Scalars['ID']['input'];input: Scalars['String']['input'];modelProvider: Scalars['String']['input'];+ resourceIds?: InputMaybe<Array<Scalars['ID']['input']>>;useAgents: Scalars['Boolean']['input'];};export type MutationCreateFlowArgs = {input: Scalars['String']['input'];modelProvider: Scalars['String']['input'];+ resourceIds?: InputMaybe<Array<Scalars['ID']['input']>>;};export type MutationCreateFlowTemplateArgs = {@@ -494,6 +497,7 @@ export type MutationPutUserInputArgs = {flowId: Scalars['ID']['input'];input: Scalars['String']['input'];modelProvider?: InputMaybe<Scalars['String']['input']>;+ resourceIds?: InputMaybe<Array<Scalars['ID']['input']>>;};export type MutationRenameFlowArgs = {@@ -709,6 +713,7 @@ export type Query = {flowsStatsTotal: FlowsStats;messageLogs?: Maybe<Array<MessageLog>>;providers: Array<Provider>;+ resources: Array<UserResource>;screenshots?: Maybe<Array<Screenshot>>;searchLogs?: Maybe<Array<SearchLog>>;settings: Settings;@@ -778,6 +783,11 @@ export type QueryMessageLogsArgs = {flowId: Scalars['ID']['input'];};+export type QueryResourcesArgs = {+ path?: InputMaybe<Scalars['String']['input']>;+ recursive?: InputMaybe<Scalars['Boolean']['input']>;+};+export type QueryScreenshotsArgs = {flowId: Scalars['ID']['input'];};@@ -915,6 +925,9 @@ export type Subscription = {providerCreated: ProviderConfig;providerDeleted: ProviderConfig;providerUpdated: ProviderConfig;+ resourceAdded: UserResource;+ resourceDeleted: UserResource;+ resourceUpdated: UserResource;screenshotAdded: Screenshot;searchLogAdded: SearchLog;settingsUserUpdated: UserPreferences;@@ -1135,6 +1148,17 @@ export type UserPrompt = {updatedAt: Scalars['Time']['output'];};+export type UserResource = {+ createdAt: Scalars['Time']['output'];+ id: Scalars['ID']['output'];+ isDir: Scalars['Boolean']['output'];+ name: Scalars['String']['output'];+ path: Scalars['String']['output'];+ size: Scalars['Int']['output'];+ updatedAt: Scalars['Time']['output'];+ userId: Scalars['ID']['output'];+};+export enum VectorStoreAction {Retrieve = 'retrieve',Store = 'store',@@ -1246,6 +1270,17 @@ export type FlowFileFragmentFragment = {modifiedAt: any;};+export type UserResourceFragmentFragment = {+ id: string;+ userId: string;+ name: string;+ path: string;+ size: number;+ isDir: boolean;+ createdAt: any;+ updatedAt: any;+};+export type AgentLogFragmentFragment = {id: string;flowId: string;@@ -1635,6 +1670,13 @@ export type FlowFilesQueryVariables = Exact<{export type FlowFilesQuery = { flowFiles: Array<FlowFileFragmentFragment> };+export type ResourcesQueryVariables = Exact<{+ path?: InputMaybe<Scalars['String']['input']>;+ recursive?: InputMaybe<Scalars['Boolean']['input']>;+}>;++export type ResourcesQuery = { resources: Array<UserResourceFragmentFragment> };+export type AssistantsQueryVariables = Exact<{flowId: Scalars['ID']['input'];}>;@@ -1810,6 +1852,7 @@ export type DeleteFlowTemplateMutation = { deleteFlowTemplate: ResultType };export type CreateFlowMutationVariables = Exact<{modelProvider: Scalars['String']['input'];input: Scalars['String']['input'];+ resourceIds?: InputMaybe<Array<Scalars['ID']['input']> | Scalars['ID']['input']>;}>;export type CreateFlowMutation = { createFlow: FlowFragmentFragment };@@ -1824,6 +1867,7 @@ export type PutUserInputMutationVariables = Exact<{flowId: Scalars['ID']['input'];input: Scalars['String']['input'];modelProvider?: InputMaybe<Scalars['String']['input']>;+ resourceIds?: InputMaybe<Array<Scalars['ID']['input']> | Scalars['ID']['input']>;}>;export type PutUserInputMutation = { putUserInput: ResultType };@@ -1852,6 +1896,7 @@ export type CreateAssistantMutationVariables = Exact<{modelProvider: Scalars['String']['input'];input: Scalars['String']['input'];useAgents: Scalars['Boolean']['input'];+ resourceIds?: InputMaybe<Array<Scalars['ID']['input']> | Scalars['ID']['input']>;}>;export type CreateAssistantMutation = {@@ -1863,6 +1908,7 @@ export type CallAssistantMutationVariables = Exact<{assistantId: Scalars['ID']['input'];input: Scalars['String']['input'];useAgents: Scalars['Boolean']['input'];+ resourceIds?: InputMaybe<Array<Scalars['ID']['input']> | Scalars['ID']['input']>;}>;export type CallAssistantMutation = { callAssistant: ResultType };@@ -2126,6 +2172,18 @@ export type FlowTemplateDeletedSubscriptionVariables = Exact<{ [key: string]: neexport type FlowTemplateDeletedSubscription = { flowTemplateDeleted: FlowTemplateFragmentFragment };+export type ResourceAddedSubscriptionVariables = Exact<{ [key: string]: never }>;++export type ResourceAddedSubscription = { resourceAdded: UserResourceFragmentFragment };++export type ResourceUpdatedSubscriptionVariables = Exact<{ [key: string]: never }>;++export type ResourceUpdatedSubscription = { resourceUpdated: UserResourceFragmentFragment };++export type ResourceDeletedSubscriptionVariables = Exact<{ [key: string]: never }>;++export type ResourceDeletedSubscription = { resourceDeleted: UserResourceFragmentFragment };+export const SettingsFragmentFragmentDoc = gql`fragment settingsFragment on Settings {debug@@ -2242,6 +2300,18 @@ export const FlowFileFragmentFragmentDoc = gql`modifiedAt}`;+export const UserResourceFragmentFragmentDoc = gql`+ fragment userResourceFragment on UserResource {+ id+ userId+ name+ path+ size+ isDir+ createdAt+ updatedAt+ }+`;export const AgentLogFragmentFragmentDoc = gql`fragment agentLogFragment on AgentLog {id@@ -3371,6 +3441,59 @@ 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 ResourcesDocument = gql`+ query resources($path: String, $recursive: Boolean) {+ resources(path: $path, recursive: $recursive) {+ ...userResourceFragment+ }+ }+ ${UserResourceFragmentFragmentDoc}+`;++/**+ * __useResourcesQuery__+ *+ * To run a query within a React component, call `useResourcesQuery` and pass it any options that fit your needs.+ * When your component renders, `useResourcesQuery` 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 } = useResourcesQuery({+ * variables: {+ * path: // value for 'path'+ * recursive: // value for 'recursive'+ * },+ * });+ */+export function useResourcesQuery(baseOptions?: Apollo.QueryHookOptions<ResourcesQuery, ResourcesQueryVariables>) {+ const options = { ...defaultOptions, ...baseOptions };+ return Apollo.useQuery<ResourcesQuery, ResourcesQueryVariables>(ResourcesDocument, options);+}+export function useResourcesLazyQuery(+ baseOptions?: Apollo.LazyQueryHookOptions<ResourcesQuery, ResourcesQueryVariables>,+) {+ const options = { ...defaultOptions, ...baseOptions };+ return Apollo.useLazyQuery<ResourcesQuery, ResourcesQueryVariables>(ResourcesDocument, options);+}+// @ts-ignore+export function useResourcesSuspenseQuery(+ baseOptions?: Apollo.SuspenseQueryHookOptions<ResourcesQuery, ResourcesQueryVariables>,+): Apollo.UseSuspenseQueryResult<ResourcesQuery, ResourcesQueryVariables>;+export function useResourcesSuspenseQuery(+ baseOptions?: Apollo.SkipToken | Apollo.SuspenseQueryHookOptions<ResourcesQuery, ResourcesQueryVariables>,+): Apollo.UseSuspenseQueryResult<ResourcesQuery | undefined, ResourcesQueryVariables>;+export function useResourcesSuspenseQuery(+ baseOptions?: Apollo.SkipToken | Apollo.SuspenseQueryHookOptions<ResourcesQuery, ResourcesQueryVariables>,+) {+ const options = baseOptions === Apollo.skipToken ? baseOptions : { ...defaultOptions, ...baseOptions };+ return Apollo.useSuspenseQuery<ResourcesQuery, ResourcesQueryVariables>(ResourcesDocument, options);+}+export type ResourcesQueryHookResult = ReturnType<typeof useResourcesQuery>;+export type ResourcesLazyQueryHookResult = ReturnType<typeof useResourcesLazyQuery>;+export type ResourcesSuspenseQueryHookResult = ReturnType<typeof useResourcesSuspenseQuery>;+export type ResourcesQueryResult = Apollo.QueryResult<ResourcesQuery, ResourcesQueryVariables>;export const AssistantsDocument = gql`query assistants($flowId: ID!) {assistants(flowId: $flowId) {@@ -5260,8 +5383,8 @@ export type DeleteFlowTemplateMutationOptions = Apollo.BaseMutationOptions<DeleteFlowTemplateMutationVariables>;export const CreateFlowDocument = gql`- mutation createFlow($modelProvider: String!, $input: String!) {- createFlow(modelProvider: $modelProvider, input: $input) {+ mutation createFlow($modelProvider: String!, $input: String!, $resourceIds: [ID!]) {+ createFlow(modelProvider: $modelProvider, input: $input, resourceIds: $resourceIds) {...flowFragment}}@@ -5284,6 +5407,7 @@ export type CreateFlowMutationFn = Apollo.MutationFunction<CreateFlowMutation, C* variables: {* modelProvider: // value for 'modelProvider'* input: // value for 'input'+ * resourceIds: // value for 'resourceIds'* },* });*/@@ -5330,8 +5454,8 @@ export type DeleteFlowMutationHookResult = ReturnType<typeof useDeleteFlowMutatiexport type DeleteFlowMutationResult = Apollo.MutationResult<DeleteFlowMutation>;export type DeleteFlowMutationOptions = Apollo.BaseMutationOptions<DeleteFlowMutation, DeleteFlowMutationVariables>;export const PutUserInputDocument = gql`- mutation putUserInput($flowId: ID!, $input: String!, $modelProvider: String) {- putUserInput(flowId: $flowId, input: $input, modelProvider: $modelProvider)+ mutation putUserInput($flowId: ID!, $input: String!, $modelProvider: String, $resourceIds: [ID!]) {+ putUserInput(flowId: $flowId, input: $input, modelProvider: $modelProvider, resourceIds: $resourceIds)}`;export type PutUserInputMutationFn = Apollo.MutationFunction<PutUserInputMutation, PutUserInputMutationVariables>;@@ -5352,6 +5476,7 @@ export type PutUserInputMutationFn = Apollo.MutationFunction<PutUserInputMutatio* flowId: // value for 'flowId'* input: // value for 'input'* modelProvider: // value for 'modelProvider'+ * resourceIds: // value for 'resourceIds'* },* });*/@@ -5468,8 +5593,20 @@ export type RenameFlowMutationHookResult = ReturnType<typeof useRenameFlowMutatiexport type RenameFlowMutationResult = Apollo.MutationResult<RenameFlowMutation>;export type RenameFlowMutationOptions = Apollo.BaseMutationOptions<RenameFlowMutation, RenameFlowMutationVariables>;export const CreateAssistantDocument = gql`- mutation createAssistant($flowId: ID!, $modelProvider: String!, $input: String!, $useAgents: Boolean!) {- createAssistant(flowId: $flowId, modelProvider: $modelProvider, input: $input, useAgents: $useAgents) {+ mutation createAssistant(+ $flowId: ID!+ $modelProvider: String!+ $input: String!+ $useAgents: Boolean!+ $resourceIds: [ID!]+ ) {+ createAssistant(+ flowId: $flowId+ modelProvider: $modelProvider+ input: $input+ useAgents: $useAgents+ resourceIds: $resourceIds+ ) {flow {...flowFragment}@@ -5503,6 +5640,7 @@ export type CreateAssistantMutationFn = Apollo.MutationFunction<* modelProvider: // value for 'modelProvider'* input: // value for 'input'* useAgents: // value for 'useAgents'+ * resourceIds: // value for 'resourceIds'* },* });*/@@ -5522,8 +5660,20 @@ export type CreateAssistantMutationOptions = Apollo.BaseMutationOptions<CreateAssistantMutationVariables>;export const CallAssistantDocument = gql`- mutation callAssistant($flowId: ID!, $assistantId: ID!, $input: String!, $useAgents: Boolean!) {- callAssistant(flowId: $flowId, assistantId: $assistantId, input: $input, useAgents: $useAgents)+ mutation callAssistant(+ $flowId: ID!+ $assistantId: ID!+ $input: String!+ $useAgents: Boolean!+ $resourceIds: [ID!]+ ) {+ callAssistant(+ flowId: $flowId+ assistantId: $assistantId+ input: $input+ useAgents: $useAgents+ resourceIds: $resourceIds+ )}`;export type CallAssistantMutationFn = Apollo.MutationFunction<CallAssistantMutation, CallAssistantMutationVariables>;@@ -5545,6 +5695,7 @@ export type CallAssistantMutationFn = Apollo.MutationFunction<CallAssistantMutat* assistantId: // value for 'assistantId'* input: // value for 'input'* useAgents: // value for 'useAgents'+ * resourceIds: // value for 'resourceIds'* },* });*/@@ -7218,3 +7369,108 @@ export function useFlowTemplateDeletedSubscription(}export type FlowTemplateDeletedSubscriptionHookResult = ReturnType<typeof useFlowTemplateDeletedSubscription>;export type FlowTemplateDeletedSubscriptionResult = Apollo.SubscriptionResult<FlowTemplateDeletedSubscription>;+export const ResourceAddedDocument = gql`+ subscription resourceAdded {+ resourceAdded {+ ...userResourceFragment+ }+ }+ ${UserResourceFragmentFragmentDoc}+`;++/**+ * __useResourceAddedSubscription__+ *+ * To run a query within a React component, call `useResourceAddedSubscription` and pass it any options that fit your needs.+ * When your component renders, `useResourceAddedSubscription` 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 } = useResourceAddedSubscription({+ * variables: {+ * },+ * });+ */+export function useResourceAddedSubscription(+ baseOptions?: Apollo.SubscriptionHookOptions<ResourceAddedSubscription, ResourceAddedSubscriptionVariables>,+) {+ const options = { ...defaultOptions, ...baseOptions };+ return Apollo.useSubscription<ResourceAddedSubscription, ResourceAddedSubscriptionVariables>(+ ResourceAddedDocument,+ options,+ );+}+export type ResourceAddedSubscriptionHookResult = ReturnType<typeof useResourceAddedSubscription>;+export type ResourceAddedSubscriptionResult = Apollo.SubscriptionResult<ResourceAddedSubscription>;+export const ResourceUpdatedDocument = gql`+ subscription resourceUpdated {+ resourceUpdated {+ ...userResourceFragment+ }+ }+ ${UserResourceFragmentFragmentDoc}+`;++/**+ * __useResourceUpdatedSubscription__+ *+ * To run a query within a React component, call `useResourceUpdatedSubscription` and pass it any options that fit your needs.+ * When your component renders, `useResourceUpdatedSubscription` 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 } = useResourceUpdatedSubscription({+ * variables: {+ * },+ * });+ */+export function useResourceUpdatedSubscription(+ baseOptions?: Apollo.SubscriptionHookOptions<ResourceUpdatedSubscription, ResourceUpdatedSubscriptionVariables>,+) {+ const options = { ...defaultOptions, ...baseOptions };+ return Apollo.useSubscription<ResourceUpdatedSubscription, ResourceUpdatedSubscriptionVariables>(+ ResourceUpdatedDocument,+ options,+ );+}+export type ResourceUpdatedSubscriptionHookResult = ReturnType<typeof useResourceUpdatedSubscription>;+export type ResourceUpdatedSubscriptionResult = Apollo.SubscriptionResult<ResourceUpdatedSubscription>;+export const ResourceDeletedDocument = gql`+ subscription resourceDeleted {+ resourceDeleted {+ ...userResourceFragment+ }+ }+ ${UserResourceFragmentFragmentDoc}+`;++/**+ * __useResourceDeletedSubscription__+ *+ * To run a query within a React component, call `useResourceDeletedSubscription` and pass it any options that fit your needs.+ * When your component renders, `useResourceDeletedSubscription` 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 } = useResourceDeletedSubscription({+ * variables: {+ * },+ * });+ */+export function useResourceDeletedSubscription(+ baseOptions?: Apollo.SubscriptionHookOptions<ResourceDeletedSubscription, ResourceDeletedSubscriptionVariables>,+) {+ const options = { ...defaultOptions, ...baseOptions };+ return Apollo.useSubscription<ResourceDeletedSubscription, ResourceDeletedSubscriptionVariables>(+ ResourceDeletedDocument,+ options,+ );+}+export type ResourceDeletedSubscriptionHookResult = ReturnType<typeof useResourceDeletedSubscription>;+export type ResourceDeletedSubscriptionResult = Apollo.SubscriptionResult<ResourceDeletedSubscription>;diff --git a/frontend/src/lib/apollo.ts b/frontend/src/lib/apollo.tsindex 28e3d439..d854dbfe 100644--- a/frontend/src/lib/apollo.ts+++ b/frontend/src/lib/apollo.ts@@ -111,6 +111,9 @@ const subscriptionToCacheFieldMap: Record<string, string> = {providerCreated: 'settingsProviders',providerDeleted: 'settingsProviders',providerUpdated: 'settingsProviders',+ resourceAdded: 'resources',+ resourceDeleted: 'resources',+ resourceUpdated: 'resources',screenshotAdded: 'screenshots',searchLogAdded: 'searchLogs',settingsUserUpdated: 'settingsUser',@@ -505,6 +508,7 @@ const createApolloClient = () => {flowTemplates: { ...replaceWithIncoming },messageLogs: { keyArgs: ['flowId'], ...replaceWithIncoming },providers: { ...replaceWithIncoming },+ resources: { keyArgs: ['path', 'recursive'], ...replaceWithIncoming },screenshots: { keyArgs: ['flowId'], ...replaceWithIncoming },searchLogs: { keyArgs: ['flowId'], ...replaceWithIncoming },settingsPrompts: { ...replaceWithIncoming },