RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
Filter agent version, allow filter with alias (#21943)
Wang Qi2d82fe3a1e99
diff --git a/internal/dao/user_canvas.go b/internal/dao/user_canvas.goindex 42ab7d958e..c21652bee4 100644--- a/internal/dao/user_canvas.go+++ b/internal/dao/user_canvas.go@@ -184,6 +184,18 @@ func (dao *UserCanvasDAO) GetList(ctx context.Context, db *gorm.DB, tenantID strreturn canvases, err}+// ListMetadataByIDs loads only the fields needed by the version catalog.+func (dao *UserCanvasDAO) ListMetadataByIDs(ctx context.Context, db *gorm.DB, canvasIDs []string, category string) ([]entity.UserCanvas, error) {+ if len(canvasIDs) == 0 {+ return []entity.UserCanvas{}, nil+ }+ var canvases []entity.UserCanvas+ err := db.WithContext(ctx).Select("id", "title").+ Where("id IN ? AND canvas_category = ?", canvasIDs, category).+ Order("create_time DESC").Order("id ASC").Find(&canvases).Error+ return canvases, err+}+// UserCanvasListItem is the joined row returned by ListByIDs.type UserCanvasListItem struct {ID string `gorm:"column:id"`diff --git a/internal/dao/user_canvas_version.go b/internal/dao/user_canvas_version.goindex c1fa187c42..ebcc61a5b1 100644--- a/internal/dao/user_canvas_version.go+++ b/internal/dao/user_canvas_version.go@@ -163,6 +163,18 @@ func (dao *UserCanvasVersionDAO) ListByCanvasID(ctx context.Context, db *gorm.DBreturn vs, err}+// ListMetadataByCanvasIDs loads version metadata without reading DSL blobs.+func (dao *UserCanvasVersionDAO) ListMetadataByCanvasIDs(ctx context.Context, db *gorm.DB, canvasIDs []string) ([]entity.UserCanvasVersion, error) {+ if len(canvasIDs) == 0 {+ return []entity.UserCanvasVersion{}, nil+ }+ var versions []entity.UserCanvasVersion+ err := db.WithContext(ctx).Select("id", "user_canvas_id", "title", "alias").+ Where("user_canvas_id IN ?", canvasIDs).+ Order("create_time DESC").Order("id ASC").Find(&versions).Error+ return versions, err+}+// GetLatest returns the most recently created version of canvasID, or// ErrUserCanvasVersionNotFound when the canvas has never been published.func (dao *UserCanvasVersionDAO) GetLatest(ctx context.Context, db *gorm.DB, canvasID string) (*entity.UserCanvasVersion, error) {diff --git a/internal/handler/agent_version_catalog.go b/internal/handler/agent_version_catalog.gonew file mode 100644index 0000000000..7e85180383--- /dev/null+++ b/internal/handler/agent_version_catalog.go@@ -0,0 +1,53 @@+//+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.+//++package handler++import (+ "github.com/gin-gonic/gin"++ "ragflow/internal/common"+)++// ListVersionCatalog returns lightweight version metadata grouped by canvas.+// @Summary List agent or pipeline versions+// @Tags agents+// @Produce json+// @Param category query string true "Canvas category" Enums(dataflow,agent)+// @Success 200 {array} service.AgentVersionCatalogItem+// @Router /api/v1/agents/versions [get]+func (h *AgentHandler) ListVersionCatalog(c *gin.Context) {+ if _, code, msg := GetUser(c); code != common.CodeSuccess {+ common.RespondError(c, code, msg)+ return+ }+ var canvasCategory string+ switch c.Query("category") {+ case "dataflow":+ canvasCategory = "dataflow_canvas"+ case "agent":+ canvasCategory = "agent_canvas"+ default:+ common.RespondError(c, common.CodeBadRequest, "category must be dataflow or agent")+ return+ }+ items, err := h.agentService.ListVersionCatalog(c.Request.Context(), canvasCategory)+ if err != nil {+ common.RespondError(c, common.CodeServerError, err.Error())+ return+ }+ common.RespondSuccessList(c, items, "success", int64(len(items)))+}diff --git a/internal/handler/agent_version_catalog_test.go b/internal/handler/agent_version_catalog_test.gonew file mode 100644index 0000000000..355b4a1fb7--- /dev/null+++ b/internal/handler/agent_version_catalog_test.go@@ -0,0 +1,249 @@+//+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.+//++package handler++import (+ "context"+ "encoding/json"+ "net/http/httptest"+ "reflect"+ "strings"+ "testing"++ "gorm.io/gorm"++ "ragflow/internal/common"+ "ragflow/internal/entity"+ "ragflow/internal/service"+)++func TestListVersionCatalog(t *testing.T) {+ for _, category := range []string{"dataflow", "agent"} {+ t.Run(category, func(t *testing.T) {+ c, w, db := setupGinContextWithUserAndDB(t, "GET", "/api/v1/agents/versions?category="+category)+ canvases := []entity.UserCanvas{+ {ID: "pipe-1", UserID: "user-1", Title: sptr("Invoices"), Description: sptr("Invoice parser"), CanvasCategory: "dataflow_canvas"},+ {ID: "pipe-empty", UserID: "user-1", CanvasCategory: "dataflow_canvas"},+ {ID: "agent-1", UserID: "user-1", Title: sptr("Assistant"), CanvasCategory: "agent_canvas"},+ {ID: "foreign", UserID: "user-2", CanvasCategory: "dataflow_canvas"},+ {ID: "foreign-agent", UserID: "user-2", CanvasCategory: "agent_canvas"},+ }+ if err := db.Create(&canvases).Error; err != nil {+ t.Fatal(err)+ }+ oldTime, newTime := int64(1), int64(2)+ versions := []entity.UserCanvasVersion{+ {ID: "v1", UserCanvasID: "pipe-1", Title: sptr("Version one"), Description: sptr("First parser"), Alias: sptr("production"), Release: true, BaseModel: entity.BaseModel{CreateTime: &oldTime}},+ {ID: "v2", UserCanvasID: "pipe-1", Title: sptr("Version two"), Release: false, BaseModel: entity.BaseModel{CreateTime: &newTime}},+ {ID: "foreign-version", UserCanvasID: "foreign"},+ {ID: "foreign-agent-version", UserCanvasID: "foreign-agent"},+ {ID: "agent-version", UserCanvasID: "agent-1", Title: sptr("Agent version"), Alias: sptr("agent alias")},+ }+ for i := range versions {+ versions[i].DSL = entity.JSONMap{"secret": "must not be loaded"}+ }+ if err := db.Create(&versions).Error; err != nil {+ t.Fatal(err)+ }+ var queries []string+ if err := db.Callback().Query().After("gorm:query").Register("capture_catalog", func(tx *gorm.DB) {+ queries = append(queries, tx.Statement.SQL.String())+ }); err != nil {+ t.Fatal(err)+ }+ (&AgentHandler{agentService: service.NewAgentService()}).ListVersionCatalog(c)+ var response struct {+ Code common.ErrorCode `json:"code"`+ Data []service.AgentVersionCatalogItem `json:"data"`+ Total *int64 `json:"total"`+ }+ if err := json.Unmarshal(w.Body.Bytes(), &response); err != nil {+ t.Fatal(err)+ }+ wantTotal := int64(2)+ if category == "agent" {+ wantTotal = 1+ }+ if response.Code != common.CodeSuccess || int64(len(response.Data)) != wantTotal || response.Total == nil || *response.Total != wantTotal {+ t.Fatalf("unexpected response: %s", w.Body.String())+ }+ byID := make(map[string]service.AgentVersionCatalogItem)+ for _, item := range response.Data {+ byID[item.ID] = item+ }+ want := service.AgentVersionCatalogItem{+ ID: "pipe-1", Name: "Invoices",+ Versions: []service.AgentVersionMetadata{+ {ID: "v2", Name: "Version two"},+ {ID: "v1", Name: "Version one", Alias: "production"},+ },+ }+ if category == "dataflow" {+ if !reflect.DeepEqual(byID["pipe-1"], want) {+ t.Fatalf("pipeline = %#v, want %#v", byID["pipe-1"], want)+ }+ if empty, ok := byID["pipe-empty"]; !ok || empty.Versions == nil || len(empty.Versions) != 0 {+ t.Fatalf("empty pipeline missing or versions not []: %#v", byID)+ }+ } else {+ want = service.AgentVersionCatalogItem{+ ID: "agent-1", Name: "Assistant",+ Versions: []service.AgentVersionMetadata{{ID: "agent-version", Name: "Agent version", Alias: "agent alias"}},+ }+ if !reflect.DeepEqual(byID["agent-1"], want) {+ t.Fatalf("agent = %#v, want %#v", byID["agent-1"], want)+ }+ }+ var raw struct {+ Data []map[string]json.RawMessage `json:"data"`+ }+ if err := json.Unmarshal(w.Body.Bytes(), &raw); err != nil {+ t.Fatal(err)+ }+ for _, item := range raw.Data {+ if len(item) != 3 || item["id"] == nil || item["name"] == nil || item["versions"] == nil {+ t.Fatalf("unexpected pipeline fields: %v", item)+ }+ var rows []map[string]json.RawMessage+ if err := json.Unmarshal(item["versions"], &rows); err != nil {+ t.Fatal(err)+ }+ for _, row := range rows {+ if len(row) != 3 || row["id"] == nil || row["name"] == nil || row["alias"] == nil {+ t.Fatalf("unexpected version fields: %v", row)+ }+ }+ }+ versionQueries := 0+ for _, query := range queries {+ if strings.Contains(query, "user_canvas") && (strings.Contains(query, "SELECT *") || strings.Contains(query, "`dsl`") || strings.Contains(query, "`description`")) {+ t.Errorf("catalog loaded unnecessary fields: %s", query)+ }+ if strings.Contains(query, "FROM `user_canvas_version`") {+ versionQueries+++ }+ }+ if versionQueries != 1 {+ t.Fatalf("version queries = %d, want 1", versionQueries)+ }++ })+ }+}++func TestListVersionCatalogEmpty(t *testing.T) {+ c, w, _ := setupGinContextWithUserAndDB(t, "GET", "/api/v1/agents/versions?category=dataflow")+ (&AgentHandler{agentService: service.NewAgentService()}).ListVersionCatalog(c)+ var response struct {+ Code common.ErrorCode `json:"code"`+ Data json.RawMessage `json:"data"`+ Total *int64 `json:"total"`+ }+ if err := json.Unmarshal(w.Body.Bytes(), &response); err != nil {+ t.Fatal(err)+ }+ if response.Code != common.CodeSuccess || string(response.Data) != "[]" || response.Total == nil || *response.Total != 0 {+ t.Fatalf("unexpected response: %s", w.Body.String())+ }+}++func TestListVersionCatalogSharedPipeline(t *testing.T) {+ c, w, db := setupGinContextWithUserAndDB(t, "GET", "/api/v1/agents/versions?category=dataflow")+ if err := db.Create(&entity.UserTenant{+ ID: "membership", UserID: "user-1", TenantID: "team", Role: "normal",+ }).Error; err != nil {+ t.Fatal(err)+ }+ canvases := []entity.UserCanvas{+ {ID: "shared", UserID: "user-2", TenantID: sptr("team"), Permission: "team", CanvasCategory: "dataflow_canvas"},+ {ID: "private", UserID: "user-2", TenantID: sptr("team"), Permission: "me", CanvasCategory: "dataflow_canvas"},+ }+ if err := db.Create(&canvases).Error; err != nil {+ t.Fatal(err)+ }+ (&AgentHandler{agentService: service.NewAgentService()}).ListVersionCatalog(c)+ var response struct {+ Code common.ErrorCode `json:"code"`+ Data []service.AgentVersionCatalogItem `json:"data"`+ }+ if err := json.Unmarshal(w.Body.Bytes(), &response); err != nil {+ t.Fatal(err)+ }+ if response.Code != common.CodeSuccess || len(response.Data) != 1 || response.Data[0].ID != "shared" {+ t.Fatalf("unexpected shared pipeline response: %s", w.Body.String())+ }+}++func TestListVersionCatalogFailure(t *testing.T) {+ for _, scenario := range []string{"canceled", "version_query"} {+ t.Run(scenario, func(t *testing.T) {+ c, w, db := setupGinContextWithUserAndDB(t, "GET", "/api/v1/agents/versions?category=dataflow")+ if scenario == "canceled" {+ ctx, cancel := context.WithCancel(c.Request.Context())+ cancel()+ c.Request = c.Request.WithContext(ctx)+ } else {+ if err := db.Create(&entity.UserCanvas{ID: "pipeline", UserID: "user-1", CanvasCategory: "dataflow_canvas"}).Error; err != nil {+ t.Fatal(err)+ }+ if err := db.Migrator().DropTable(&entity.UserCanvasVersion{}); err != nil {+ t.Fatal(err)+ }+ }+ (&AgentHandler{agentService: service.NewAgentService()}).ListVersionCatalog(c)+ var response struct {+ Code common.ErrorCode `json:"code"`+ Data json.RawMessage `json:"data"`+ }+ if err := json.Unmarshal(w.Body.Bytes(), &response); err != nil {+ t.Fatal(err)+ }+ if response.Code != common.CodeServerError || response.Data != nil {+ t.Fatalf("failure reported as catalog data: %s", w.Body.String())+ }+ })+ }+}++func TestListVersionCatalogRejectsInvalidRequests(t *testing.T) {+ for _, scenario := range []string{"missing_category", "invalid_category", "unauthenticated"} {+ t.Run(scenario, func(t *testing.T) {+ c, w, _ := setupGinContextWithUserAndDB(t, "GET", "/api/v1/agents/versions?category=dataflow")+ want := common.CodeBadRequest+ switch scenario {+ case "missing_category":+ c.Request = httptest.NewRequest("GET", "/api/v1/agents/versions", nil)+ case "invalid_category":+ c.Request = httptest.NewRequest("GET", "/api/v1/agents/versions?category=anything", nil)+ case "unauthenticated":+ c.Keys = nil+ c.Request = c.Request.WithContext(t.Context())+ want = common.CodeUnauthorized+ }+ (&AgentHandler{agentService: service.NewAgentService()}).ListVersionCatalog(c)+ var response struct {+ Code common.ErrorCode `json:"code"`+ }+ if err := json.Unmarshal(w.Body.Bytes(), &response); err != nil {+ t.Fatal(err)+ }+ if response.Code != want {+ t.Fatalf("unexpected response: %s", w.Body.String())+ }+ })+ }+}diff --git a/internal/permission/database_source.go b/internal/permission/database_source.goindex 29aa8e41a0..7658b587ff 100644--- a/internal/permission/database_source.go+++ b/internal/permission/database_source.go@@ -939,7 +939,8 @@ func (s *databaseSource) loadCanvases(ctx context.Context, ids []string) (map[stif len(ids) == 0 {return canvasesByID, nil}- query := s.db.WithContext(ctx).Model(&entity.UserCanvas{}).Where("id IN ?", ids)+ query := s.db.WithContext(ctx).Model(&entity.UserCanvas{}).+ Select("id", "user_id", "tenant_id", "permission").Where("id IN ?", ids)if s.lockRows {query = query.Clauses(clause.Locking{Strength: "UPDATE"})}diff --git a/internal/router/agent_routes.go b/internal/router/agent_routes.goindex a8ce1cbd14..df6a2fe4da 100644--- a/internal/router/agent_routes.go+++ b/internal/router/agent_routes.go@@ -43,6 +43,7 @@ func RegisterAgentRoutes(g *gin.RouterGroup, h *handler.AgentHandler) {g.GET("/templates", h.ListAgentTemplates)g.GET("/prompts", h.Prompts)g.GET("/tags", h.ListAgentTags)+ g.GET("/versions", h.ListVersionCatalog)// Agent CRUD.g.GET("", h.ListAgents)diff --git a/internal/router/agent_routes_test.go b/internal/router/agent_routes_test.goindex 2b8e995bc0..500a626109 100644--- a/internal/router/agent_routes_test.go+++ b/internal/router/agent_routes_test.go@@ -21,6 +21,7 @@ import ("encoding/json""net/http""net/http/httptest"+ "strings""testing""github.com/gin-gonic/gin"@@ -55,6 +56,7 @@ func TestAgentRoutesRegistered(t *testing.T) {{http.MethodDelete, "/api/v1/agents/abc"},{http.MethodPost, "/api/v1/agents/abc/run"},{http.MethodPost, "/api/v1/agents/abc/publish"},+ {http.MethodGet, "/api/v1/agents/versions?category=dataflow"},{http.MethodGet, "/api/v1/agents/abc/versions"},{http.MethodGet, "/api/v1/agents/abc/versions/v1"},{http.MethodDelete, "/api/v1/agents/abc/versions/v1"},@@ -63,8 +65,17 @@ func TestAgentRoutesRegistered(t *testing.T) {{http.MethodPost, "/api/v1/agents/abc/webhook/credentials"},{http.MethodDelete, "/api/v1/agents/abc/webhook/credentials"},}- if len(cases) != 14 {- t.Fatalf("expected 14 routes, listed %d", len(cases))+ foundCatalog := false+ for _, route := range eng.Routes() {+ if route.Method == http.MethodGet && route.Path == "/api/v1/agents/versions" && strings.HasSuffix(route.Handler, ".ListVersionCatalog-fm") {+ foundCatalog = true+ }+ }+ if !foundCatalog {+ t.Fatal("static version catalog route missing")+ }+ if len(cases) != 15 {+ t.Fatalf("expected 15 routes, listed %d", len(cases))}for _, c := range cases {w := httptest.NewRecorder()diff --git a/internal/service/agent_version_catalog.go b/internal/service/agent_version_catalog.gonew file mode 100644index 0000000000..11f1697034--- /dev/null+++ b/internal/service/agent_version_catalog.go@@ -0,0 +1,80 @@+//+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.+//++package service++import (+ "context"+ "fmt"++ "ragflow/internal/dao"+ "ragflow/internal/permission"+)++// AgentVersionMetadata describes a saved version without its DSL.+type AgentVersionMetadata struct {+ ID string `json:"id"`+ Name string `json:"name"`+ Alias string `json:"alias"`+}++// AgentVersionCatalogItem groups a canvas's saved version metadata.+type AgentVersionCatalogItem struct {+ ID string `json:"id"`+ Name string `json:"name"`+ Versions []AgentVersionMetadata `json:"versions"`+}++// ListVersionCatalog returns accessible canvases in the selected category and+// their saved versions, newest first. Empty canvases keep an empty version list.+func (s *AgentService) ListVersionCatalog(ctx context.Context, canvasCategory string) ([]AgentVersionCatalogItem, error) {+ scope, err := permission.NewDatabaseChecker(dao.DB).Scope(ctx, permission.ScopeQuery{+ Kind: permission.ResourceKindCanvas, Operation: permission.OperationRead,+ })+ if err != nil {+ return nil, fmt.Errorf("scope version catalog: %w", err)+ }+ items := make([]AgentVersionCatalogItem, 0)+ if scope.Mode == permission.ScopeNone {+ return items, nil+ }+ canvases, err := s.canvasDAO.ListMetadataByIDs(ctx, dao.DB, scope.ResourceIDs, canvasCategory)+ if err != nil {+ return nil, fmt.Errorf("list version catalog canvases: %w", err)+ }+ canvasIDs := make([]string, 0, len(canvases))+ indexByID := make(map[string]int, len(canvases))+ for _, canvas := range canvases {+ indexByID[canvas.ID] = len(items)+ canvasIDs = append(canvasIDs, canvas.ID)+ items = append(items, AgentVersionCatalogItem{+ ID: canvas.ID, Name: derefString(canvas.Title),+ Versions: make([]AgentVersionMetadata, 0),+ })+ }+ versions, err := s.versionDAO.ListMetadataByCanvasIDs(ctx, dao.DB, canvasIDs)+ if err != nil {+ return nil, fmt.Errorf("list version catalog versions: %w", err)+ }+ for _, version := range versions {+ item := &items[indexByID[version.UserCanvasID]]+ item.Versions = append(item.Versions, AgentVersionMetadata{+ ID: version.ID, Name: derefString(version.Title),+ Alias: derefString(version.Alias),+ })+ }+ return items, nil+}diff --git a/web/src/components/document-pipeline-dialog/use-document-pipeline-form.test.tsx b/web/src/components/document-pipeline-dialog/use-document-pipeline-form.test.tsxindex af5fc6ba9c..69aa3b94e4 100644--- a/web/src/components/document-pipeline-dialog/use-document-pipeline-form.test.tsx+++ b/web/src/components/document-pipeline-dialog/use-document-pipeline-form.test.tsx@@ -13,18 +13,20 @@ jest.mock('@/hooks/use-pipeline-operator', () => ({// The hook now fetches the canvas version list itself and derives the latest// id reactively, so we mock the fetch and drive it via a mutable array.let mockVersions: Array<{ id: string; version?: number; name?: string }> = [];-jest.mock('@/hooks/use-agent-request', () => ({- useFetchCanvasVersionList: () => ({+jest.mock('@/hooks/use-pipeline-version-request', () => ({+ useFetchPipelineVersionList: () => ({data: mockVersions,loading: false,isError: false,}),- // The three hooks below back useParserTreeData, which the form hook- // consults for the missing-option validation.+ useFetchPipelineVersionCatalog: () => ({+ data: [],+ loading: false,+ isError: false,+ }),+}));+jest.mock('@/hooks/use-agent-request', () => ({useFetchBuiltinPipelines: () => ({ options: [], loading: false }),- useFetchAgentList: () => ({ data: { canvas: [], total: 0 }, loading: false }),- useFetchCanvasVersions: (canvasIds: string[]) =>- canvasIds.map(() => ({ isSuccess: true, data: mockVersions })),}));// Cut the chain parser-config-validation -> compilation-form -> locales/configdiff --git a/web/src/components/document-pipeline-dialog/use-document-pipeline-form.ts b/web/src/components/document-pipeline-dialog/use-document-pipeline-form.tsindex 3b64bf283a..3d1a867c61 100644--- a/web/src/components/document-pipeline-dialog/use-document-pipeline-form.ts+++ b/web/src/components/document-pipeline-dialog/use-document-pipeline-form.ts@@ -20,7 +20,7 @@ import {usePipelineOperatorNodes,useResetParserConfigOnPipelineChange,} from '@/hooks/use-pipeline-operator';-import { useFetchCanvasVersionList } from '@/hooks/use-agent-request';+import { useFetchPipelineVersionList } from '@/hooks/use-pipeline-version-request';import { IChangeParserRequestBody } from '@/interfaces/request/document';import {getOperatorType,@@ -148,7 +148,7 @@ export function useDocumentPipelineForm({// *reactive* value: it resolves after mount and the adoption effect below// re-fires when it does. (Reading it from a static prop captured before the// fetch would freeze it at undefined.) versions is newest-first.- const { data: versions = [] } = useFetchCanvasVersionList(+ const { data: versions = [] } = useFetchPipelineVersionList(isPipelineMode ? selectedDataFlowId : undefined,);const latestVersionId = versions[0]?.id;diff --git a/web/src/components/parser-tree-select/index.test.tsx b/web/src/components/parser-tree-select/index.test.tsxindex 7ccc136d7f..8b04067eab 100644--- a/web/src/components/parser-tree-select/index.test.tsx+++ b/web/src/components/parser-tree-select/index.test.tsx@@ -1,5 +1,6 @@import { act, render } from '@testing-library/react';import { ParserTreeSelect } from './index';+import { filterTreeNodes } from '../tree-select-utils';const mockTreeProps: any = {};jest.mock('@/components/tree-select', () => ({@@ -17,38 +18,29 @@ jest.mock('react-i18next', () => ({useTranslation: () => ({ t: (k: string) => k }),}));-const VersionList = [- { id: 'v1', title: 'v1 title', created_at: '', alias: 'jin' },-];--// Index-aligned with the sorted canvas ids the hook requests: pipe-1 is the-// selected pipeline and always fetched; pipe-2 appears once its branch is-// expanded in a test.-let mockVersionQueries: any[] = [];+const VersionList = [{ id: 'v1', name: 'v1 title', alias: 'jin' }];+let mockCatalog: any[] = [];+let mockCatalogLoading = false;jest.mock('@/hooks/use-agent-request', () => ({useFetchBuiltinPipelines: () => ({options: [{ label: 'General', value: 'general' }],loading: false,}),- useFetchAgentList: () => ({- data: {- canvas: [- { id: 'pipe-1', title: 'My Flow', type: 'pipeline' },- { id: 'pipe-2', title: 'Empty Flow', type: 'pipeline' },- // AgentListItemType.CompilationTemplateGroup — referenced as a literal- // because the jest.mock factory cannot capture an imported enum.- { id: 'grp-1', title: 'Group', type: 'compilation_template_group' },- ],- total: 2,- },- loading: false,+}));+jest.mock('@/hooks/use-pipeline-version-request', () => ({+ useFetchPipelineVersionCatalog: () => ({+ data: mockCatalog,+ loading: mockCatalogLoading,}),- useFetchCanvasVersions: () => mockVersionQueries,}));beforeEach(() => {for (const key of Object.keys(mockTreeProps)) delete mockTreeProps[key];- mockVersionQueries = [{ isSuccess: true, data: VersionList }];+ mockCatalog = [+ { id: 'pipe-1', name: 'My Flow', versions: VersionList },+ { id: 'pipe-2', name: 'Empty Flow', versions: [] },+ ];+ mockCatalogLoading = false;});describe('ParserTreeSelect', () => {@@ -67,7 +59,7 @@ describe('ParserTreeSelect', () => {expect(builtin.children).toBeUndefined();});- it('excludes compilation template groups from the pipeline branches', () => {+ it('builds branches directly from the dataflow catalog', () => {render(<ParserTreeSelect value="pipeline:pipe-1:v1" onChange={jest.fn()} />,);@@ -123,77 +115,39 @@ describe('ParserTreeSelect', () => {expect([...mockTreeProps.expandedIds]).toEqual(['pipeline:pipe-1']);});- it('keeps an unrequested branch non-selectable via a loading placeholder', () => {- render(- <ParserTreeSelect value="pipeline:pipe-1:v1" onChange={jest.fn()} />,- );- const emptyFlow = mockTreeProps.data[1];-- // pipe-2's versions were never requested, so it must not collapse into a- // selectable leaf — a disabled placeholder child keeps it a branch.- expect(emptyFlow.children).toHaveLength(1);- expect(emptyFlow.children[0].id).toBe('pipeline:pipe-2:loading');- expect(emptyFlow.children[0].disabled).toBe(true);+ it('searches a version alias in an unexpanded pipeline locally', () => {+ render(<ParserTreeSelect value={undefined} onChange={jest.fn()} />);+ expect([...mockTreeProps.expandedIds]).toEqual([]);+ const matches = filterTreeNodes(mockTreeProps.data, 'JIN');+ expect(matches.map((node) => node.id)).toEqual(['pipeline:pipe-1']);+ expect(matches[0].children?.[0].id).toBe('pipeline:pipe-1:v1');+ act(() => mockTreeProps.onSearchChange('JIN'));+ expect([...mockTreeProps.expandedIds]).toEqual(['pipeline:pipe-1']);});- it('lazily fetches versions for a freshly expanded branch', () => {- mockVersionQueries = [- { isSuccess: true, data: VersionList },- { isSuccess: false, data: undefined },- ];- render(- <ParserTreeSelect value="pipeline:pipe-1:v1" onChange={jest.fn()} />,- );- act(() => {- mockTreeProps.onExpandedChange(- new Set(['pipeline:pipe-1', 'pipeline:pipe-2']),- );- });-- const emptyFlow = mockTreeProps.data[1];- expect(emptyFlow.children[0].id).toBe('pipeline:pipe-2:loading');- expect([...mockTreeProps.loadingIds]).toContain('pipeline:pipe-2');+ it('searches pipeline names and version names locally', () => {+ render(<ParserTreeSelect value={undefined} onChange={jest.fn()} />);+ for (const term of ['MY FLOW', 'V1 TITLE']) {+ const matches = filterTreeNodes(mockTreeProps.data, term);+ expect(matches.map((node) => node.id)).toEqual(['pipeline:pipe-1']);+ expect(matches[0].children?.[0].id).toBe('pipeline:pipe-1:v1');+ }+ expect(filterTreeNodes(mockTreeProps.data, 'unknown')).toEqual([]);});- it("keeps a collapsed branch's versions instead of reverting to the loading placeholder", () => {- mockVersionQueries = [- { isSuccess: true, data: VersionList },- { isSuccess: true, data: [{ id: 'v2', title: 'v2 title' }] },- ];+ it('keeps version metadata when a branch is collapsed', () => {render(<ParserTreeSelect value="pipeline:pipe-1:v1" onChange={jest.fn()} />,);- act(() => {- mockTreeProps.onExpandedChange(- new Set(['pipeline:pipe-1', 'pipeline:pipe-2']),- );- });- // Collapse pipe-2: its versions must stay in the tree. Reverting to the- // empty-titled loading placeholder would make the search filter drop the- // whole branch while a search term is active.- act(() => {- mockTreeProps.onExpandedChange(new Set(['pipeline:pipe-1']));- });-- const collapsed = mockTreeProps.data[1];- expect(collapsed.children[0].id).toBe('pipeline:pipe-2:v2');+ act(() => mockTreeProps.onExpandedChange(new Set()));+ expect([...mockTreeProps.expandedIds]).toEqual([]);+ expect(mockTreeProps.data[0].children[0].id).toBe('pipeline:pipe-1:v1');});- it('shows a disabled empty row for a branch with no published versions', () => {- mockVersionQueries = [- { isSuccess: true, data: VersionList },- { isSuccess: true, data: [] },- ];- render(- <ParserTreeSelect value="pipeline:pipe-1:v1" onChange={jest.fn()} />,- );- act(() => {- mockTreeProps.onExpandedChange(- new Set(['pipeline:pipe-1', 'pipeline:pipe-2']),- );- });-+ it('keeps a pipeline with no versions non-selectable', () => {+ render(<ParserTreeSelect value={undefined} onChange={jest.fn()} />);const emptyFlow = mockTreeProps.data[1];+ expect(emptyFlow.children).toHaveLength(1);expect(emptyFlow.children[0].id).toBe('pipeline:pipe-2:empty');expect(emptyFlow.children[0].disabled).toBe(true);});@@ -220,7 +174,7 @@ describe('ParserTreeSelect', () => {});it('marks the select as loading while the selected versions arrive', () => {- mockVersionQueries = [{ isSuccess: false, data: undefined }];+ mockCatalogLoading = true;render(<ParserTreeSelect value="pipeline:pipe-1:v1" onChange={jest.fn()} />,);diff --git a/web/src/components/parser-tree-select/index.tsx b/web/src/components/parser-tree-select/index.tsxindex 2317fa7097..fc1d16712e 100644--- a/web/src/components/parser-tree-select/index.tsx+++ b/web/src/components/parser-tree-select/index.tsx@@ -38,7 +38,7 @@ export interface ParserTreeSelectProps {}// ParserTreeSelect is the single dropdown that merges builtin parsers and-// dataflow pipelines with their published versions: builtin parsers are+// dataflow pipelines with their saved versions: builtin parsers are// selectable root-level leaves, pipelines are non-selectable branches (the// draft) whose version leaves are the only pipeline-side choices. It is a// controlled component: the parent owns the form fields and translates the@@ -58,7 +58,6 @@ export function ParserTreeSelect({expandedIds,onExpandedChange,onSearchChange,- loadingIds,loading,selectedLeafExists,} = useParserTreeData({ value });@@ -111,8 +110,8 @@ export function ParserTreeSelect({// the icon would submit the form, and stopPropagation alone cannot cancel// that native default action. type="button" removes it, while the click// handlers still swallow the event before it bubbles to the TreeSelect- // trigger, so the click neither toggles the dropdown nor triggers the lazy- // version fetches that follow. It is hidden while the value is already+ // trigger, so the click neither toggles the dropdown nor changes branch+ // expansion. It is hidden while the value is already// reported as missing — a deleted pin is the stronger signal.const stopHintClick = useCallback((e: React.SyntheticEvent) => {e.stopPropagation();@@ -144,7 +143,6 @@ export function ParserTreeSelect({expandedIds={expandedIds}onExpandedChange={onExpandedChange}onSearchChange={onSearchChange}- loadingIds={loadingIds}loading={loading}renderSelected={renderSelected}renderMissingValue={renderMissingParser}diff --git a/web/src/components/parser-tree-select/use-parser-tree-data.tsx b/web/src/components/parser-tree-select/use-parser-tree-data.tsxindex c66e246c3f..f1ae8c6bad 100644--- a/web/src/components/parser-tree-select/use-parser-tree-data.tsx+++ b/web/src/components/parser-tree-select/use-parser-tree-data.tsx@@ -1,17 +1,10 @@-import { AgentCategory } from '@/constants/agent';-import {- ICanvasVersionRow,- useFetchAgentList,- useFetchBuiltinPipelines,- useFetchCanvasVersions,-} from '@/hooks/use-agent-request';+import { useFetchBuiltinPipelines } from '@/hooks/use-agent-request';+import { useFetchPipelineVersionCatalog } from '@/hooks/use-pipeline-version-request';import {buildParserOptionValue,parseParserOptionValue,ParserOptionKind,} from '@/hooks/use-parser-options';-import { AgentListItemType } from '@/interfaces/database/agent';-import { Loader2 } from 'lucide-react';import { useCallback, useMemo, useState } from 'react';import { useTranslation } from 'react-i18next';import { PipelineVersionLabel } from '../pipeline-version-label';@@ -27,18 +20,13 @@ import {const buildPipelineNodeId = (pipelineId: string) =>buildParserOptionValue(ParserOptionKind.Pipeline, pipelineId);-// useParserTreeData assembles the merged parser tree: dataflow pipelines as-// branches with their published versions as leaves, builtin parsers as-// root-level leaves. Versions are fetched lazily — for the currently selected-// pipeline (needed for the closed-select display) and for every branch the-// user has expanded.+// Combines the cached pipeline/version catalog with builtin parser leaves.export function useParserTreeData({ value }: { value?: string }) {const { t } = useTranslation();const { options: builtinOptions, loading: builtinLoading } =useFetchBuiltinPipelines();- const { data: pipelineData, loading: pipelineLoading } = useFetchAgentList({- canvas_category: AgentCategory.DataflowCanvas,- });+ const { data: pipelines = [], loading: pipelineLoading } =+ useFetchPipelineVersionCatalog();const selectedPipelineId = useMemo(() => {const parsed = parseParserOptionValue(value);@@ -47,8 +35,7 @@ export function useParserTreeData({ value }: { value?: string }) {: undefined;}, [value]);- // Expansion is controlled here (not inside TreeSelect) so that expansion- // drives the lazy version fetch below.+ // Expansion is local; all version metadata is already in the catalog.const [expandedIds, setExpandedIds] = useState<Set<string>>(new Set());// Render-phase adjustment (React's endorsed "adjust state when a prop@@ -70,132 +57,63 @@ export function useParserTreeData({ value }: { value?: string }) {}}- // The fetch set only grows: once a branch has been expanded, its versions- // stay loaded for the rest of the select's lifetime. Dropping the query- // observer on collapse would revert the branch's children to the- // empty-titled loading placeholder, and an active search filter would then- // drop the whole branch from the results. Freshness still comes from- // gcTime: 0 across remounts and from version mutations invalidating the- // shared query key. Render-phase adjustment, same pattern as the- // selected-branch expansion above.- const [loadedCanvasIds, setLoadedCanvasIds] = useState<Set<string>>(- new Set(),- );- const [prevExpandedIds, setPrevExpandedIds] = useState(expandedIds);- if (expandedIds !== prevExpandedIds) {- setPrevExpandedIds(expandedIds);- setLoadedCanvasIds((prev) => {- const next = new Set(prev);- let added = false;- expandedIds.forEach((nodeId) => {- const parsed = parseParserOptionValue(nodeId);- if (- parsed?.kind === ParserOptionKind.Pipeline &&- !next.has(parsed.rawId)- ) {- next.add(parsed.rawId);- added = true;- }- });- return added ? next : prev;- });- }-- // Versions load for the selected pipeline plus every branch expanded so- // far. Sorted so the useQueries array stays stable across changes.- const versionCanvasIds = useMemo(() => {- const ids = new Set(loadedCanvasIds);- if (selectedPipelineId) ids.add(selectedPipelineId);- return [...ids].sort();- }, [selectedPipelineId, loadedCanvasIds]);- const versionResults = useFetchCanvasVersions(versionCanvasIds);-- const { versionsByCanvas, loadingCanvasIds } = useMemo(() => {- const versionsByCanvas = new Map<string, ICanvasVersionRow[]>();- const loadingCanvasIds = new Set<string>();- versionCanvasIds.forEach((canvasId, index) => {- const query = versionResults[index];- if (query?.isSuccess) {- versionsByCanvas.set(canvasId, query.data ?? []);- } else {- loadingCanvasIds.add(canvasId);- }- });- return { versionsByCanvas, loadingCanvasIds };- }, [versionResults, versionCanvasIds]);-// Trim: some locales still define the marker with surrounding whitespace// from when it was appended to the label text.const builtInTag = t('knowledgeConfiguration.builtInSuffix').trim();const treeData = useMemo<TreeSelectNode[]>(() => {- const pipelines = (pipelineData?.canvas ?? [])- .filter(- (item) => item.type !== AgentListItemType.CompilationTemplateGroup,- )- .map((item): TreeSelectNode => {- const nodeId = buildPipelineNodeId(item.id);- const versions = versionsByCanvas.get(item.id);- let children: TreeSelectNode[];- if (!versions) {- children = [- {- id: `${nodeId}:loading`,- title: '',- disabled: true,- label: (- <Loader2 className="size-3.5 animate-spin text-text-disabled" />- ),- },- ];- } else if (versions.length === 0) {- // A pipeline draft without published versions stays visible but- // offers nothing to select. The disabled placeholder row also keeps- // the branch non-empty, so TreeSelect never treats the draft itself- // as a selectable leaf.- children = [- {- id: `${nodeId}:empty`,- title: '',- disabled: true,- label: (- <span className="text-text-disabled">- {t('flow.version.noPublished')}- </span>- ),- },- ];- } else {- children = versions.map((version): TreeSelectNode => ({- id: buildParserOptionValue(- ParserOptionKind.Pipeline,- item.id,- version.id,- ),- // The alias joins the plain-text title so TreeSelect search- // matches it; `label` renders it as secondary text instead.- title: version.alias- ? `${version.title} ${version.alias}`- : version.title,- searchKeywords: version.alias ? [version.alias] : undefined,- // The trigger display needs the alias and the unpolluted title- // (title above has the alias joined in for search). The dropdown- // row caps the alias at a fixed width — the popover is w-auto, so- // an uncapped alias would blow it wide instead of truncating.- data: version.alias- ? { title: version.title, alias: version.alias }- : undefined,+ const pipelineNodes = pipelines.map((item): TreeSelectNode => {+ const nodeId = buildPipelineNodeId(item.id);+ const versions = item.versions;+ let children: TreeSelectNode[];+ if (versions.length === 0) {+ // A pipeline draft without saved versions stays visible but+ // offers nothing to select. The disabled placeholder row also keeps+ // the branch non-empty, so TreeSelect never treats the draft itself+ // as a selectable leaf.+ children = [+ {+ id: `${nodeId}:empty`,+ title: '',+ disabled: true,label: (- <PipelineVersionLabel- title={version.title}- alias={version.alias}- aliasClassName="max-w-60"- />+ <span className="text-text-disabled">+ {t('flow.version.noPublished')}+ </span>),- }));- }- return { id: nodeId, title: item.title, children };- });+ },+ ];+ } else {+ children = versions.map((version): TreeSelectNode => ({+ id: buildParserOptionValue(+ ParserOptionKind.Pipeline,+ item.id,+ version.id,+ ),+ // The alias joins the plain-text title so TreeSelect search+ // matches it; `label` renders it as secondary text instead.+ title: version.alias+ ? `${version.name} ${version.alias}`+ : version.name,+ searchKeywords: version.alias ? [version.alias] : undefined,+ // The trigger display needs the alias and the unpolluted title+ // (title above has the alias joined in for search). The dropdown+ // row caps the alias at a fixed width — the popover is w-auto, so+ // an uncapped alias would blow it wide instead of truncating.+ data: version.alias+ ? { title: version.name, alias: version.alias }+ : undefined,+ label: (+ <PipelineVersionLabel+ title={version.name}+ alias={version.alias}+ aliasClassName="max-w-60"+ />+ ),+ }));+ }+ return { id: nodeId, title: item.name, children };+ });const builtins = builtinOptions.map((option): TreeSelectNode => ({id: buildParserOptionValue(ParserOptionKind.BuiltIn, option.value),@@ -213,8 +131,8 @@ export function useParserTreeData({ value }: { value?: string }) {// Pipeline branches first, builtin leaves below — the same ordering the// flat parser select used.- return [...pipelines, ...builtins];- }, [pipelineData, builtinOptions, versionsByCanvas, t, builtInTag]);+ return [...pipelineNodes, ...builtins];+ }, [pipelines, builtinOptions, t, builtInTag]);// TreeSelect's built-in search auto-expansion only runs for uncontrolled// expansion; with expansion owned here, matching branches are expanded from@@ -233,10 +151,7 @@ export function useParserTreeData({ value }: { value?: string }) {// An unmatched value is "missing" only once everything that could contain// it has loaded; while the selected pipeline's versions are still arriving// the select must not flash the missing display.- const loading =- builtinLoading ||- pipelineLoading ||- (!!selectedPipelineId && loadingCanvasIds.has(selectedPipelineId));+ const loading = builtinLoading || pipelineLoading;const selectedLeafExists = useMemo(() => {if (!value) return false;@@ -248,19 +163,11 @@ export function useParserTreeData({ value }: { value?: string }) {return find(treeData);}, [treeData, value]);- // Node-id keyed (not canvas-id keyed) so TreeSelect can spin the chevron of- // a branch whose versions are being fetched.- const loadingIds = useMemo(- () => new Set([...loadingCanvasIds].map(buildPipelineNodeId)),- [loadingCanvasIds],- );-return {treeData,expandedIds,onExpandedChange: setExpandedIds,onSearchChange: handleSearchChange,- loadingIds,loading,selectedLeafExists,};diff --git a/web/src/hooks/__tests__/use-canvas-version-list.test.tsx b/web/src/hooks/__tests__/use-canvas-version-list.test.tsxindex 64477cc41f..37370d26ba 100644--- a/web/src/hooks/__tests__/use-canvas-version-list.test.tsx+++ b/web/src/hooks/__tests__/use-canvas-version-list.test.tsx@@ -17,10 +17,7 @@import { QueryClient, QueryClientProvider } from '@tanstack/react-query';import { renderHook, waitFor } from '@testing-library/react';import { MemoryRouter } from 'react-router';-import {- useFetchCanvasVersionList,- useFetchCanvasVersions,-} from '../use-agent-request';+import { useFetchCanvasVersionList } from '../use-agent-request';jest.mock('@/services/agent-service', () => ({__esModule: true,@@ -48,13 +45,8 @@ beforeEach(() => {jest.clearAllMocks();});-// Both version-list hooks share the 'canvasVersionList' query key, and the-// multi-canvas hook's consumers (the parser tree select) key their loading-// verdict off isSuccess. If the single-canvas hook ever seeds initialData-// again, TanStack Query applies it to the still-pending shared query and a-// pinned version briefly looks deleted — this test pins that regression.describe('useFetchCanvasVersionList', () => {- it('does not report success on the shared key while the fetch is pending', async () => {+ it('keeps pending data undefined until versions arrive', async () => {let resolveFetch: (value: unknown) => void = () => undefined;agentService.fetchVersionList.mockImplementation(() =>@@ -63,25 +55,20 @@ describe('useFetchCanvasVersionList', () => {}),);- const { result } = renderHook(- () => ({- single: useFetchCanvasVersionList('canvas-1'),- multi: useFetchCanvasVersions(['canvas-1']),- }),- { wrapper },- );+ const { result } = renderHook(() => useFetchCanvasVersionList('canvas-1'), {+ wrapper,+ });// While the request is in flight there is no version data: an empty list// here would mean "loaded and empty", i.e. the pipeline has no versions.- expect(result.current.single.data).toBeUndefined();- expect(result.current.multi[0]?.isSuccess).toBe(false);+ expect(result.current.data).toBeUndefined();resolveFetch({ data: { data: [{ id: 'version-1' }] } });await waitFor(() => {- expect(result.current.multi[0]?.isSuccess).toBe(true);+ expect(result.current.data).toEqual([{ id: 'version-1' }]);});- expect(result.current.single.data).toEqual([{ id: 'version-1' }]);+ expect(result.current.data).toEqual([{ id: 'version-1' }]);});it('stays disabled without a canvas id', () => {diff --git a/web/src/hooks/__tests__/use-pipeline-version-request.test.tsx b/web/src/hooks/__tests__/use-pipeline-version-request.test.tsxnew file mode 100644index 0000000000..9866b1e161--- /dev/null+++ b/web/src/hooks/__tests__/use-pipeline-version-request.test.tsx@@ -0,0 +1,192 @@+import { QueryClient, QueryClientProvider } from '@tanstack/react-query';+import { act, renderHook, waitFor } from '@testing-library/react';+import { MemoryRouter } from 'react-router';+import agentService, { updateVersion } from '@/services/agent-service';+import {+ AgentKeys,+ useDeleteAgent,+ useDeleteVersion,+ useSaveAgent,+ useUpdateAgentSetting,+ useUpdateVersion,+} from '../use-agent-request';+import {+ PipelineVersionKeys,+ useFetchPipelineVersionCatalog,+ useFetchPipelineVersionList,+} from '../use-pipeline-version-request';++jest.mock('@/services/agent-service', () => ({+ __esModule: true,+ default: {+ listAgentVersions: jest.fn(),+ deleteVersion: jest.fn(),+ deleteAgent: jest.fn(),+ },+ updateVersion: jest.fn(),+ updateAgent: jest.fn(),+}));++import { updateAgent } from '@/services/agent-service';++const Catalog = [+ {+ id: 'pipe-1',+ name: 'Invoices',+ versions: [{ id: 'v2', name: 'Version two', alias: 'production' }],+ },+];++function setup() {+ const client = new QueryClient({+ defaultOptions: { queries: { retry: false } },+ });+ const wrapper = ({ children }: { children: React.ReactNode }) => (+ <MemoryRouter>+ <QueryClientProvider client={client}>{children}</QueryClientProvider>+ </MemoryRouter>+ );+ return { client, wrapper };+}++beforeEach(() => {+ jest.clearAllMocks();+ jest+ .mocked(agentService.listAgentVersions)+ .mockResolvedValue({ data: { code: 0, data: Catalog, total: 1 } } as any);+});++it('shares one catalog request across the tree and selected version observers', async () => {+ const { wrapper } = setup();+ const { result } = renderHook(+ () => ({+ catalog: useFetchPipelineVersionCatalog(),+ selected: useFetchPipelineVersionList('pipe-1'),+ missing: useFetchPipelineVersionList('deleted-pipeline'),+ }),+ { wrapper },+ );+ await waitFor(() => expect(result.current.catalog.data).toEqual(Catalog));+ expect(result.current.selected.data).toEqual(Catalog[0].versions);+ expect(result.current.missing.data).toEqual([]);+ expect(agentService.listAgentVersions).toHaveBeenCalledTimes(1);+ expect(agentService.listAgentVersions).toHaveBeenCalledWith(+ { params: { category: 'dataflow' } },+ true,+ );+});++it('reuses the fresh catalog after unmounting and reopening the picker', async () => {+ const { wrapper } = setup();+ const first = renderHook(() => useFetchPipelineVersionCatalog(), { wrapper });+ await waitFor(() => expect(first.result.current.data).toEqual(Catalog));+ first.unmount();+ const second = renderHook(() => useFetchPipelineVersionCatalog(), {+ wrapper,+ });+ expect(second.result.current.data).toEqual(Catalog);+ expect(agentService.listAgentVersions).toHaveBeenCalledTimes(1);+});++it('distinguishes pending data from an empty version list', async () => {+ let resolveFetch!: (value: any) => void;+ jest.mocked(agentService.listAgentVersions).mockImplementation(+ () =>+ new Promise((resolve) => {+ resolveFetch = resolve;+ }),+ );+ const { wrapper } = setup();+ const { result } = renderHook(() => useFetchPipelineVersionList('pipe-1'), {+ wrapper,+ });+ expect(result.current.data).toBeUndefined();+ expect(result.current.loading).toBe(true);+ await act(async () => resolveFetch({ data: { code: 0, data: [] } }));+ await waitFor(() => expect(result.current.data).toEqual([]));+});++it('does not fetch the catalog for an absent selected pipeline', () => {+ const { wrapper } = setup();+ const { result } = renderHook(() => useFetchPipelineVersionList(), {+ wrapper,+ });+ expect(result.current.data).toBeUndefined();+ expect(agentService.listAgentVersions).not.toHaveBeenCalled();+});++it('surfaces API failures instead of caching them as an empty catalog', async () => {+ jest.mocked(agentService.listAgentVersions).mockResolvedValue({+ data: { code: 500, message: 'Failed to load catalog' },+ } as any);+ const { wrapper } = setup();+ const { result } = renderHook(() => useFetchPipelineVersionCatalog(), {+ wrapper,+ });+ await waitFor(() => expect(result.current.isError).toBe(true));+ expect(result.current.data).toBeUndefined();+});++it.each(['alias', 'deleteVersion', 'deletePipeline', 'save', 'rename'])(+ 'invalidates cached catalog metadata after %s',+ async (action) => {+ const { client, wrapper } = setup();+ client.setQueryData(PipelineVersionKeys.catalog(), Catalog);+ client.setQueryData(AgentKeys.canvasVersionList('pipe-1'), [+ { id: 'v2', title: 'Version two', alias: 'production' },+ ]);+ jest.mocked(updateVersion).mockResolvedValue({ data: { code: 0 } } as any);+ jest.mocked(updateAgent).mockResolvedValue({ data: { code: 0 } } as any);+ jest+ .mocked(agentService.deleteVersion)+ .mockResolvedValue({ data: { code: 0 } } as any);+ jest+ .mocked(agentService.deleteAgent)+ .mockResolvedValue({ data: { code: 0 } } as any);+ const { result } = renderHook(+ () => ({+ alias: useUpdateVersion(),+ deleteVersion: useDeleteVersion(),+ deletePipeline: useDeleteAgent(),+ save: useSaveAgent(false),+ rename: useUpdateAgentSetting(),+ }),+ { wrapper },+ );+ await act(async () => {+ if (action === 'alias')+ await result.current.alias.updateVersion({+ canvasId: 'pipe-1',+ versionId: 'v2',+ alias: 'new alias',+ });+ if (action === 'deleteVersion')+ await result.current.deleteVersion.deleteVersion({+ canvasId: 'pipe-1',+ versionId: 'v2',+ });+ if (action === 'deletePipeline')+ await result.current.deletePipeline.deleteAgent('pipe-1');+ if (action === 'save')+ await result.current.save.saveAgent({ id: 'pipe-1', release: 'true' });+ if (action === 'rename')+ await result.current.rename.updateAgentSetting({+ id: 'pipe-1',+ title: 'Renamed',+ });+ });+ expect(+ client.getQueryState(PipelineVersionKeys.catalog())?.isInvalidated,+ ).toBe(true);+ if (action === 'alias' || action === 'deleteVersion') {+ expect(AgentKeys.canvasVersionList('pipe-1')).toEqual([+ 'canvasVersionList',+ 'pipe-1',+ ]);+ expect(+ client.getQueryState(AgentKeys.canvasVersionList('pipe-1'))+ ?.isInvalidated,+ ).toBe(true);+ }+ },+);diff --git a/web/src/hooks/use-agent-request.ts b/web/src/hooks/use-agent-request.tsindex 7551ba874b..dc1385cf54 100644--- a/web/src/hooks/use-agent-request.ts+++ b/web/src/hooks/use-agent-request.ts@@ -57,12 +57,7 @@ import agentService, {} from '@/services/agent-service';import { buildMessageListWithUuid } from '@/utils/chat';import { markListItemsDeleted } from '@/utils/list-deletion-util';-import {- useMutation,- useQueries,- useQuery,- useQueryClient,-} from '@tanstack/react-query';+import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';import { useDebounce } from 'ahooks';import { get, isEmpty, set } from 'lodash';import { useCallback, useState } from 'react';@@ -72,6 +67,7 @@ import {useHandleSearchChange,} from './logic-hooks';import { useSessionList } from './use-session-list';+import { PipelineVersionKeys } from './use-pipeline-version-request';export const enum AgentApiAction {FetchAgentListByPage = 'fetchAgentListByPage',@@ -148,6 +144,8 @@ export const AgentKeys = {[AgentApiAction.FetchInputForm, agentId, componentId] as const,versionList: (agentId?: string) =>[AgentApiAction.FetchVersionList, agentId] as const,+ canvasVersionList: (canvasId?: string) =>+ ['canvasVersionList', canvasId] as const,version: (agentId?: string, versionId?: string) =>[AgentApiAction.FetchVersion, agentId, versionId] as const,};@@ -330,6 +328,9 @@ export const useUpdateAgentSetting = () => {queryClient.invalidateQueries({queryKey: AgentKeys.list(),});+ queryClient.invalidateQueries({+ queryKey: PipelineVersionKeys.catalog(),+ });}return ret?.data?.code;},@@ -352,6 +353,9 @@ export const useDeleteAgent = () => {queryClient.invalidateQueries({queryKey: AgentKeys.list(),});+ queryClient.invalidateQueries({+ queryKey: PipelineVersionKeys.catalog(),+ });queryClient.invalidateQueries({queryKey: AgentKeys.filters(),});@@ -481,9 +485,9 @@ export const useResetAgent = () => {};// Every create flow (blank, template, JSON import, built-in pipeline copy)-// navigates to the new canvas on success, and the list-page queries refetch on-// remount (gcTime: 0) — so creation intentionally invalidates nothing.+// navigates to the new canvas; invalidate the cached metadata catalog too.export const useCreateAgent = (showMessage: boolean = true) => {+ const queryClient = useQueryClient();const {data,isPending: loading,@@ -497,8 +501,11 @@ export const useCreateAgent = (showMessage: boolean = true) => {canvas_category?: string;}) => {const { data = {} } = await agentService.createAgent(params);- if (data.code === 0 && showMessage) {- message.success(i18n.t('message.created'));+ if (data.code === 0) {+ queryClient.invalidateQueries({+ queryKey: PipelineVersionKeys.catalog(),+ });+ if (showMessage) message.success(i18n.t('message.created'));}return data;},@@ -548,6 +555,11 @@ export const useSaveAgent = (if (showMessage) {message.success(i18n.t('message.modified'));}+ if (!params.autosave || params.release) {+ queryClient.invalidateQueries({+ queryKey: PipelineVersionKeys.catalog(),+ });+ }// Every save can prune the oldest unpublished versions server-side,// so the version history list must refetch even when autosave skips// the detail refresh.@@ -787,33 +799,15 @@ export interface ICanvasVersionRow {alias?: string;}-// Shared query key/options for a canvas's published version list. The raw-// 'canvasVersionList' key predates the AgentKeys factory; both the single- and-// multi-canvas hooks must keep using it verbatim so the version delete/alias-// mutations below invalidate every observer.-const canvasVersionListQuery = (canvasId: string) => ({- queryKey: ['canvasVersionList', canvasId] as const,- queryFn: async (): Promise<ICanvasVersionRow[]> => {- const { data } = await agentService.fetchVersionList(canvasId);- return data?.data ?? [];- },-});--// useFetchCanvasVersionList lists the published versions of an arbitrary canvas-// (dataflow or agent) by id. Unlike useFetchVersionList it takes the canvas id-// explicitly (not from route params) so the document pipeline dialog can load-// versions for the currently selected dataflow canvas. It must not set-// initialData: the key is shared with useFetchCanvasVersions, whose consumers-// rely on isSuccess to tell "loaded and empty" from "still loading" — an-// initialData [] would report success while the real fetch is in flight and a-// pinned version would briefly look deleted.+// Lists versions for document status displays. Parser selection uses the+// lightweight catalog instead. No initialData so pending and empty differ.export const useFetchCanvasVersionList = (canvasId?: string) => {const {data,isFetching: loading,isError,} = useQuery({- queryKey: ['canvasVersionList', canvasId],+ queryKey: AgentKeys.canvasVersionList(canvasId),gcTime: 0,enabled: !!canvasId,queryFn: async (): Promise<ICanvasVersionRow[]> => {@@ -826,21 +820,6 @@ export const useFetchCanvasVersionList = (canvasId?: string) => {return { data, loading, isError };};-// useFetchCanvasVersions lazily loads the published versions of several-// canvases at once (the parser tree select fetches a canvas's versions only-// when the user expands it). `isSuccess` distinguishes "loaded and empty" from-// "still loading" — kept truthful by neither version-list hook setting-// initialData (see useFetchCanvasVersionList). The returned array aligns-// index-by-index with `canvasIds`.-export const useFetchCanvasVersions = (canvasIds: string[]) => {- return useQueries({- queries: canvasIds.map((canvasId) => ({- ...canvasVersionListQuery(canvasId),- gcTime: 0,- })),- });-};-// useDeleteVersion removes a single canvas version (design section 7/B2). The// backend still allows deletion when the version is referenced by a dataset or// file; the binding then enters a Missing (unparseable) state, so the UI shows a@@ -866,15 +845,15 @@ export const useDeleteVersion = () => {return data?.code === 0;},onSuccess: (_result, variables) => {- // Invalidate both version-list caches so the deleted version disappears- // without a manual refresh: the version dialog reads- // AgentKeys.versionList (canvas id from route params) and the document- // pipeline dialog reads the canvasVersionList key.+ // Refresh version history, document status, and the parser catalog.queryClient.invalidateQueries({queryKey: AgentKeys.versionList(variables.canvasId),});queryClient.invalidateQueries({- queryKey: ['canvasVersionList', variables.canvasId],+ queryKey: AgentKeys.canvasVersionList(variables.canvasId),+ });+ queryClient.invalidateQueries({+ queryKey: PipelineVersionKeys.catalog(),});},});@@ -905,6 +884,9 @@ export const useApplyVersion = () => {queryKey: AgentKeys.versionList(canvasId),});queryClient.invalidateQueries({ queryKey: AgentKeys.detail(canvasId) });+ queryClient.invalidateQueries({+ queryKey: PipelineVersionKeys.catalog(),+ });},});@@ -938,7 +920,10 @@ export const useUpdateVersion = () => {queryKey: AgentKeys.versionList(variables.canvasId),});queryClient.invalidateQueries({- queryKey: ['canvasVersionList', variables.canvasId],+ queryKey: AgentKeys.canvasVersionList(variables.canvasId),+ });+ queryClient.invalidateQueries({+ queryKey: PipelineVersionKeys.catalog(),});},});diff --git a/web/src/hooks/use-pipeline-version-request.ts b/web/src/hooks/use-pipeline-version-request.tsnew file mode 100644index 0000000000..4d6509300b--- /dev/null+++ b/web/src/hooks/use-pipeline-version-request.ts@@ -0,0 +1,43 @@+import { IAgentVersionCatalogItem } from '@/interfaces/database/agent';+import agentService from '@/services/agent-service';+import { useQuery } from '@tanstack/react-query';++export const PipelineVersionKeys = {+ catalog: () => ['pipelineVersionCatalog', 'dataflow'] as const,+};++export function useFetchPipelineVersionCatalog(enabled = true) {+ const {+ data,+ isFetching: loading,+ isError,+ } = useQuery({+ queryKey: PipelineVersionKeys.catalog(),+ enabled,+ staleTime: 60_000,+ gcTime: 5 * 60_000,+ queryFn: async (): Promise<IAgentVersionCatalogItem[]> => {+ const { data } = await agentService.listAgentVersions(+ { params: { category: 'dataflow' } },+ true,+ );+ if (data?.code !== 0) throw new Error(data?.message);+ return data.data ?? [];+ },+ });++ return { data, loading, isError };+}++export function useFetchPipelineVersionList(pipelineId?: string) {+ const { data, loading, isError } =+ useFetchPipelineVersionCatalog(!!pipelineId);+ return {+ data:+ pipelineId && data+ ? (data.find((pipeline) => pipeline.id === pipelineId)?.versions ?? [])+ : undefined,+ loading,+ isError,+ };+}diff --git a/web/src/interfaces/database/agent.ts b/web/src/interfaces/database/agent.tsindex a859537c21..e1e1491808 100644--- a/web/src/interfaces/database/agent.ts+++ b/web/src/interfaces/database/agent.ts@@ -401,3 +401,15 @@ export interface IAgentWebhookCredential {credential: string;webhook_url: string;}++export interface IAgentVersionMetadata {+ id: string;+ name: string;+ alias: string;+}++export interface IAgentVersionCatalogItem {+ id: string;+ name: string;+ versions: IAgentVersionMetadata[];+}diff --git a/web/src/pages/agents/use-copy-builtin-pipeline.ts b/web/src/pages/agents/use-copy-builtin-pipeline.tsindex bc35529c36..0508487c01 100644--- a/web/src/pages/agents/use-copy-builtin-pipeline.ts+++ b/web/src/pages/agents/use-copy-builtin-pipeline.ts@@ -1,16 +1,18 @@-import { useMutation } from '@tanstack/react-query';+import { useMutation, useQueryClient } from '@tanstack/react-query';import message from '@/components/ui/message';import { AgentCategory } from '@/constants/agent';import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks';+import { PipelineVersionKeys } from '@/hooks/use-pipeline-version-request';import agentService from '@/services/agent-service';import i18n from '@/locales/config';// useCopyBuiltinPipeline turns a read-only built-in pipeline into a user-owned// dataflow canvas: it fetches the built-in DSL via GET /api/v1/pipelines/:id,// creates a new canvas with that DSL, and opens it for editing. The agents-// list refetches on return (gcTime: 0), so no list invalidation is needed.+// list refetches on return; the metadata catalog is invalidated on creation.export function useCopyBuiltinPipeline() {const { navigateToAgent } = useNavigatePage();+ const queryClient = useQueryClient();const { mutateAsync, isPending } = useMutation({mutationFn: async ({ id, title }: { id: string; title: string }) => {try {@@ -33,6 +35,9 @@ export function useCopyBuiltinPipeline() {});if (created?.code === 0) {+ queryClient.invalidateQueries({+ queryKey: PipelineVersionKeys.catalog(),+ });message.success(i18n.t('message.created'));navigateToAgent(created.data.id, AgentCategory.DataflowCanvas)();return created;diff --git a/web/src/pages/dataset/setting/index.test.tsx b/web/src/pages/dataset/setting/index.test.tsxindex db71da655b..47ea3143bf 100644--- a/web/src/pages/dataset/setting/index.test.tsx+++ b/web/src/pages/dataset/setting/index.test.tsx@@ -37,7 +37,7 @@ jest.mock('@/components/ui/message', () => ({}));jest.mock('./form-schema', () => {const { z } = require('zod');- return { formSchema: z.object({}).passthrough() };+ return { buildFormSchema: () => z.object({}).passthrough() };});jest.mock('./hooks', () => ({useFetchDatasetSettingOnMount: (form: {@@ -74,9 +74,11 @@ jest.mock('./general-form', () => ({);},}));-jest.mock('@/components/parser-select', () => ({ ParserSelect: () => null }));-jest.mock('@/components/pipeline-version-select', () => ({- PipelineVersionSelect: () => null,+jest.mock('@/components/parser-tree-select', () => ({+ ParserTreeSelect: () => null,+}));+jest.mock('@/components/parser-tree-select/use-parser-tree-data', () => ({+ useParserTreeData: () => ({ selectedLeafExists: true, loading: false }),}));jest.mock('@/components/pipeline-operator-tabs', () => ({__esModule: true,@@ -107,8 +109,8 @@ jest.mock('@/utils/pipeline-operator', () => ({jest.mock('./parser-config', () => ({normalizeParserConfigForComparison: (config: unknown) => config,}));-jest.mock('@/hooks/use-agent-request', () => ({- useFetchCanvasVersionList: () => ({ data: [] }),+jest.mock('@/hooks/use-pipeline-version-request', () => ({+ useFetchPipelineVersionList: () => ({ data: [] }),}));jest.mock('./use-reveal-submit-errors', () => ({useRevealSubmitErrors: () => ({}),diff --git a/web/src/pages/dataset/setting/index.tsx b/web/src/pages/dataset/setting/index.tsxindex 5db3cd8600..03f71d8718 100644--- a/web/src/pages/dataset/setting/index.tsx+++ b/web/src/pages/dataset/setting/index.tsx@@ -45,7 +45,7 @@ import {useSaveDatasetSetting,} from './hooks';import { normalizeParserConfigForComparison } from './parser-config';-import { useFetchCanvasVersionList } from '@/hooks/use-agent-request';+import { useFetchPipelineVersionList } from '@/hooks/use-pipeline-version-request';import { useRevealSubmitErrors } from './use-reveal-submit-errors';import { ApplyParserConfigDialog } from './apply-parser-config-dialog';@@ -183,10 +183,9 @@ export default function DatasetSetting() {? (knowledgeDetails?.pipeline_version_id ?? ''): '';- // Published versions of the selected dataflow canvas, fetched here only to- // prefill the latest version for unpinned datasets (design C1/C2); the- // select itself lazy-loads whatever branches the user expands.- const { data: canvasVersions } = useFetchCanvasVersionList(+ // Reuse the select's catalog cache to prefill the latest saved version for+ // unpinned datasets.+ const { data: canvasVersions } = useFetchPipelineVersionList(parseType === ParseType.Pipeline && pipelineId ? pipelineId : undefined,);// Show the outdated bang only while the form still holds the SAVED pin:diff --git a/web/src/services/agent-service.ts b/web/src/services/agent-service.tsindex 83896114ef..67ac982fa3 100644--- a/web/src/services/agent-service.ts+++ b/web/src/services/agent-service.ts@@ -87,6 +87,10 @@ const methods = {url: listAgents,method: 'get',},+ listAgentVersions: {+ url: api.listAgentVersions,+ method: 'get',+ },listAgentTags: {url: api.listAgentTags,method: 'get',diff --git a/web/src/utils/api.ts b/web/src/utils/api.tsindex cec36143e1..01331ffece 100644--- a/web/src/utils/api.ts+++ b/web/src/utils/api.ts@@ -347,6 +347,7 @@ const apiEndpoints = {// flowlistAgentTemplate: `${restAPIv1}/agents/templates`,listAgents: `${restAPIv1}/agents`,+ listAgentVersions: `${restAPIv1}/agents/versions`,listAgentTags: `${restAPIv1}/agents/tags`,updateAgentTags: (agentId: string) => `${restAPIv1}/agents/${agentId}/tags`,createAgent: `${restAPIv1}/agents`,