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
Feat: Modify the alias of a published agent (#21620)
balibabud4d130187af8
diff --git a/web/package-lock.json b/web/package-lock.jsonindex 2c5e2edc92..e92b536fde 100644--- a/web/package-lock.json+++ b/web/package-lock.json@@ -90,7 +90,7 @@"jszip": "^3.10.1","lexical": "^0.45.0","lodash": "^4.18.1",- "lucide-react": "^1.48.0",+ "lucide-react": "^1.63.0","mermaid": "^11.16.1","next-themes": "^0.4.6","openai-speech-stream-player": "^1.0.8",@@ -3292,9 +3292,6 @@"arm64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -3312,9 +3309,6 @@"arm64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -3332,9 +3326,6 @@"ppc64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -3352,9 +3343,6 @@"riscv64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -3372,9 +3360,6 @@"riscv64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -3392,9 +3377,6 @@"s390x"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -3412,9 +3394,6 @@"x64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -3432,9 +3411,6 @@"x64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -18256,12 +18232,18 @@}},"node_modules/lucide-react": {- "version": "1.48.0",- "resolved": "https://registry.npmmirror.com/lucide-react/-/lucide-react-1.48.0.tgz",- "integrity": "sha512-R0CIKY/fXiC6y9xRBADgsK+VW2p/pcTJOMhLZf1T+uG+vJUvyUR02nGOgmIIC7MPkiNK4Ox8QDnbqF8rJYWPZQ==",+ "version": "1.63.0",+ "resolved": "https://registry.npmmirror.com/lucide-react/-/lucide-react-1.63.0.tgz",+ "integrity": "sha512-GkBfQG+FUJ41x6y3/lNXiOziVU0Rcqqq0TCzhHS8avsFXHZmOdmfBqsVTvHSaVmbI+wbdGkxHRmhYWhD3N4/yA==","license": "ISC","peerDependencies": {+ "@types/react": "*","react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0"+ },+ "peerDependenciesMeta": {+ "@types/react": {+ "optional": true+ }}},"node_modules/lz-string": {diff --git a/web/package.json b/web/package.jsonindex d3ffdd4f14..5893ba7075 100644--- a/web/package.json+++ b/web/package.json@@ -100,7 +100,7 @@"jszip": "^3.10.1","lexical": "^0.45.0","lodash": "^4.18.1",- "lucide-react": "^1.48.0",+ "lucide-react": "^1.63.0","mermaid": "^11.16.1","next-themes": "^0.4.6","openai-speech-stream-player": "^1.0.8",diff --git a/web/src/locales/en.ts b/web/src/locales/en.tsindex 009bf60f28..78499fef24 100644--- a/web/src/locales/en.ts+++ b/web/src/locales/en.ts@@ -3438,6 +3438,10 @@ This delimiter is used to split the input text into several text pieces echo oflatest: 'Latest version',filterByAlias: 'Filter by alias',alias: 'Alias',+ addAlias: 'Add alias',+ editAlias: 'Edit alias',+ editAliasDescription:+ 'Give this version a memorable alias so you can find it quickly later.',pinnedTooltip:'This dataset is pinned to a specific version. New versions published on the agent will not affect it.',outdated:@@ -3581,9 +3585,6 @@ This process aggregates variables from multiple branches into a single variable'Write your SQL query here. You can use variables, raw SQL, or mix both using variable syntax.',frameworkPrompts: 'Framework',release: 'Publish',- production: 'Production',- productionTooltip:- 'This version is published to production. Access it via the API or the embedded page.',confirmPublish: 'Confirm publish',publishIngestionPipeline:'You are about to publish this Ingestion pipeline.',diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.tsindex 31d077a181..2ab4597b70 100644--- a/web/src/locales/zh.ts+++ b/web/src/locales/zh.ts@@ -2472,6 +2472,10 @@ NER:使用 spaCy NER 和基于规则的关键词提取来抽取 Entities 和 Rlatest: '最新版本',filterByAlias: '按别名筛选',alias: '别名',+ addAlias: '添加别名',+ editAlias: '编辑别名',+ editAliasDescription:+ '为该版本设置一个便于识别的别名,方便后续快速查找。',pinnedTooltip:'该数据集已固定到特定版本。智能体新发布的版本不会影响它。',outdated: '固定的版本不是最新版本。点击了解详情;我们不会自动升级它。',@@ -3098,8 +3102,6 @@ NER:使用 spaCy NER 和基于规则的关键词提取来抽取 Entities 和 R'在此处编写您的 SQL 查询。您可以使用变量、原始 SQL,或使用变量语法混合使用两者。',frameworkPrompts: '框架',release: '发布',- production: '正式版',- productionTooltip: '此版本已发布到生产环境。可通过 API 或嵌入页面访问。',confirmPublish: '确认发布',publishIngestionPipeline: '您即将发布此 Ingestion pipeline。',publishAgent: '您即将发布此智能体',diff --git a/web/src/pages/agent/components/alias-form-dialog.tsx b/web/src/pages/agent/components/alias-form-dialog.tsxnew file mode 100644index 0000000000..6bdbc9b460--- /dev/null+++ b/web/src/pages/agent/components/alias-form-dialog.tsx@@ -0,0 +1,108 @@+import { RAGFlowFormItem } from '@/components/ragflow-form';+import { Button } from '@/components/ui/button';+import {+ Dialog,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+} from '@/components/ui/dialog';+import { Form } from '@/components/ui/form';+import { Input } from '@/components/ui/input';+import { zodResolver } from '@hookform/resolvers/zod';+import { ReactNode, useCallback, useId } from 'react';+import { useForm } from 'react-hook-form';+import { useTranslation } from 'react-i18next';+import { z } from 'zod';++const FormSchema = z.object({+ // Alias is optional and mirrors the user_canvas_version.alias column.+ alias: z.string().trim().max(255).optional(),+});++interface AliasFormDialogProps {+ open: boolean;+ onOpenChange: (open: boolean) => void;+ title: string;+ description?: string;+ initialAlias?: string;+ onSubmit: (alias?: string) => void;+ children?: ReactNode;+}++export function AliasFormDialog({+ open,+ onOpenChange,+ title,+ description,+ initialAlias = '',+ onSubmit,+ children,+}: AliasFormDialogProps) {+ const { t } = useTranslation();+ const formId = useId();++ const form = useForm<z.infer<typeof FormSchema>>({+ resolver: zodResolver(FormSchema),+ defaultValues: { alias: initialAlias },+ });++ const handleConfirm = useCallback(+ (values: z.infer<typeof FormSchema>) => {+ onSubmit(values.alias || undefined);+ form.reset();+ onOpenChange(false);+ },+ [onSubmit, form, onOpenChange],+ );++ const handleOpenChange = useCallback(+ (nextOpen: boolean) => {+ if (!nextOpen) {+ form.reset();+ }+ onOpenChange(nextOpen);+ },+ [form, onOpenChange],+ );++ const handleCancelClick = useCallback(() => {+ handleOpenChange(false);+ }, [handleOpenChange]);++ return (+ <Dialog open={open} onOpenChange={handleOpenChange}>+ <DialogContent>+ <DialogHeader>+ <DialogTitle>{title}</DialogTitle>+ </DialogHeader>+ {description && (+ <DialogDescription className="text-sm text-text-secondary">+ {description}+ </DialogDescription>+ )}+ <Form {...form}>+ <form+ id={formId}+ onSubmit={form.handleSubmit(handleConfirm)}+ className="space-y-3"+ >+ {children}+ <RAGFlowFormItem name="alias" label={t('flow.version.alias')}>+ <Input placeholder={t('flow.version.alias')} autoComplete="off" />+ </RAGFlowFormItem>+ </form>+ </Form>+ <DialogFooter className="gap-2 mt-4">+ <Button variant="outline" onClick={handleCancelClick}>+ {t('common.cancel')}+ </Button>+ <Button type="submit" form={formId}>+ {t('common.confirm')}+ </Button>+ </DialogFooter>+ </DialogContent>+ </Dialog>+ );+}diff --git a/web/src/pages/agent/components/publish-confirm-dialog.tsx b/web/src/pages/agent/components/publish-confirm-dialog.tsxindex 6f85c648e7..7b6b92f415 100644--- a/web/src/pages/agent/components/publish-confirm-dialog.tsx+++ b/web/src/pages/agent/components/publish-confirm-dialog.tsx@@ -1,13 +1,5 @@import { RAGFlowAvatar } from '@/components/ragflow-avatar';-import { Button, ButtonLoading } from '@/components/ui/button';-import {- Dialog,- DialogContent,- DialogDescription,- DialogFooter,- DialogHeader,- DialogTitle,-} from '@/components/ui/dialog';+import { ButtonLoading } from '@/components/ui/button';import { IFlow } from '@/interfaces/database/agent';import { IDataset } from '@/interfaces/database/dataset';import { formatDate } from '@/utils/date';@@ -15,11 +7,12 @@ import { BookPlus } from 'lucide-react';import { useCallback, useMemo, useState } from 'react';import { useTranslation } from 'react-i18next';import { useIsPipeline } from '../hooks/use-is-pipeline';+import { AliasFormDialog } from './alias-form-dialog';interface PublishConfirmDialogProps {agentDetail: IFlow;loading: boolean;- onPublish: () => void;+ onPublish: (alias?: string) => void;}function AssociatedDataset({@@ -80,21 +73,12 @@ export function PublishConfirmDialog({return agentDetail?.datasets || [];}, [agentDetail?.datasets]);- const handleConfirmPublish = useCallback(() => {- onPublish();- setOpen(false);- }, [onPublish]);-const handleTriggerClick = useCallback(() => {setOpen(true);}, []);- if (isPipeline) {- return null;- }-return (- <Dialog open={open} onOpenChange={setOpen}>+ <><ButtonLoadingvariant={'secondary'}loading={loading}@@ -102,54 +86,41 @@ export function PublishConfirmDialog({><BookPlus /> {t('flow.release')}</ButtonLoading>- <DialogContent>- <DialogHeader>- <DialogTitle>{t('flow.confirmPublish')}</DialogTitle>- </DialogHeader>- <DialogDescription>- <div className="space-y-3">- <div className="text-sm text-text-secondary">- {t(- `flow.${isPipeline ? 'publishIngestionPipeline' : 'publishAgent'}`,- )}- </div>-- <section className="bg-bg-input px-2.5 py-4 rounded border border-border-default">- <div className="flex gap-2.5 items-center">- <RAGFlowAvatar- avatar={agentDetail.avatar}- name={agentDetail.title}- className="size-8"- />- <span className="text-text-primary text-lg">- {agentDetail.title}- </span>- </div>+ <AliasFormDialog+ open={open}+ onOpenChange={setOpen}+ title={t('flow.confirmPublish')}+ description={t(+ `flow.${isPipeline ? 'publishIngestionPipeline' : 'publishAgent'}`,+ )}+ onSubmit={onPublish}+ >+ <section className="bg-bg-input px-2.5 py-4 rounded border border-border-default">+ <div className="flex gap-2.5 items-center">+ <RAGFlowAvatar+ avatar={agentDetail.avatar}+ name={agentDetail.title}+ className="size-8"+ />+ <span className="text-text-primary text-lg">+ {agentDetail.title}+ </span>+ </div>- {isPipeline && (- <AssociatedDataset- associatedDatasets={associatedDatasets}- ></AssociatedDataset>- )}- </section>+ {isPipeline && (+ <AssociatedDataset+ associatedDatasets={associatedDatasets}+ ></AssociatedDataset>+ )}+ </section>- <div className="flex flex-col gap-2">- {lastPublished && (- <div className="flex items-center text-sm text-text-secondary gap-2">- <span>{t('flow.lastPublished')}:</span>- <span>{lastPublished}</span>- </div>- )}- </div>+ {lastPublished && (+ <div className="flex items-center text-sm text-text-secondary gap-2">+ <span>{t('flow.lastPublished')}:</span>+ <span>{lastPublished}</span></div>- </DialogDescription>- <DialogFooter className="gap-2 mt-4">- <Button variant="outline" onClick={() => setOpen(false)}>- {t('common.cancel')}- </Button>- <Button onClick={handleConfirmPublish}>{t('common.confirm')}</Button>- </DialogFooter>- </DialogContent>- </Dialog>+ )}+ </AliasFormDialog>+ </>);}diff --git a/web/src/pages/agent/hooks/use-save-graph.ts b/web/src/pages/agent/hooks/use-save-graph.tsindex 2bdf0cd36c..54e4b7df1f 100644--- a/web/src/pages/agent/hooks/use-save-graph.ts+++ b/web/src/pages/agent/hooks/use-save-graph.ts@@ -38,6 +38,7 @@ export const useSaveGraph = (},release?: boolean,autosave?: boolean,+ alias?: string,) => {if (!id) {return;@@ -52,12 +53,16 @@ export const useSaveGraph = (if (release) {params.release = 'true';}- // Design §5.1: the debounced auto-save path passes autosave:true so the- // backend refreshes only the live draft and never mints a new version.- // An explicit (manual) Save omits this flag.+ // Both the debounced auto-save and the explicit Save button pass+ // autosave:true so the backend refreshes only the live draft and never+ // mints a new version. Only publishing (release) writes a version row,+ // optionally carrying an alias into user_canvas_version.if (autosave) {params.autosave = true;}+ if (alias) {+ params.alias = alias;+ }return saveAgent(params);},@@ -105,7 +110,7 @@ export const useSaveGraphBeforeOpeningDebugDrawer = (show: () => void) => {);return;}- const saveRet = await saveGraph(nextNodes);+ const saveRet = await saveGraph(nextNodes, undefined, undefined, true);if (saveRet?.code === 0) {// Call the reset api before opening the run drawer each timeconst resetRet = await resetAgent();diff --git a/web/src/pages/agent/index.tsx b/web/src/pages/agent/index.tsxindex 1c0868bcac..c586738693 100644--- a/web/src/pages/agent/index.tsx+++ b/web/src/pages/agent/index.tsx@@ -116,9 +116,17 @@ export default function Agent() {const { handleExportJson } = useHandleExportJsonFile();const { saveGraph, loading } = useSaveGraph();+ // Manual Save is a draft save, same as auto-save: it refreshes the live+ // canvas without minting a user_canvas_version row. Publishing does that.const handleSave = useCallback(() => {- saveGraph();+ saveGraph(undefined, undefined, undefined, true);}, [saveGraph]);+ const handlePublish = useCallback(+ (alias?: string) => {+ saveGraph(undefined, undefined, true, undefined, alias);+ },+ [saveGraph],+ );// Back-link lands on the agents list tab matching this canvas: ingestion// pipeline canvases return to the pipeline tab, agent canvases to workflow.const handleBackToAgents = useCallback(() => {@@ -340,7 +348,7 @@ export default function Agent() {<PublishConfirmDialogagentDetail={agentDetail}loading={loading}- onPublish={() => saveGraph(undefined, undefined, true)}+ onPublish={handlePublish}/><CanvasChecklist issues={issues} /><DropdownMenu>diff --git a/web/src/pages/agent/version-dialog/index.test.tsx b/web/src/pages/agent/version-dialog/index.test.tsxindex 225e0e5a6d..0faa143c18 100644--- a/web/src/pages/agent/version-dialog/index.test.tsx+++ b/web/src/pages/agent/version-dialog/index.test.tsx@@ -14,7 +14,14 @@* limitations under the License.*/-import { fireEvent, render, screen } from '@testing-library/react';+import { TooltipProvider } from '@/components/ui/tooltip';+import {+ fireEvent,+ render,+ screen,+ waitFor,+ within,+} from '@testing-library/react';jest.mock('react-i18next', () => {const actual = jest.requireActual('react-i18next');@@ -42,7 +49,9 @@ jest.mock('@xyflow/react', () => ({const mockUpdateVersion = jest.fn();-const mockVersions = [+// Both versions are released: the dialog only lists published versions.+// `let` so pagination tests can swap in a larger list before rendering.+let mockVersions = [{id: 'v-latest',title: 'Latest',@@ -54,7 +63,7 @@ const mockVersions = [id: 'v-old',title: 'Old Snapshot',created_at: '2024-01-01',- release: false,+ release: true,alias: 'old',},];@@ -78,42 +87,83 @@ jest.mock('@/hooks/use-agent-request', () => ({import { VersionDialog } from './index';-describe('VersionDialog outdated marker (D1/D2/D3, T21)', () => {- it('marks non-latest versions with the ! outdated indicator but not the latest', () => {- render(<VersionDialog hideModal={jest.fn()} />);-- expect(screen.getByText('Latest')).toBeInTheDocument();- expect(screen.getByText('Old Snapshot')).toBeInTheDocument();- // Exactly one ! marker: the non-latest list entry. The latest is selected by- // default, so the detail panel shows no marker.- expect(screen.getAllByText('!')).toHaveLength(1);+// TooltipProvider lives at the app root in production; tests must supply it.+const renderDialog = () =>+ render(+ <TooltipProvider>+ <VersionDialog hideModal={jest.fn()} />+ </TooltipProvider>,+ );++const getRow = (title: string) => screen.getByText(title).closest('li')!;++describe('VersionDialog alias edit entry (G2/section 4.4, T35)', () => {+ it('renders an edit-alias button for every version', () => {+ renderDialog();+ // Two mock versions => one edit-alias button per row.+ expect(within(getRow('Latest')).getByRole('button')).toBeInTheDocument();+ expect(+ within(getRow('Old Snapshot')).getByRole('button'),+ ).toBeInTheDocument();});-});-describe('VersionDialog editable alias input (G2/section 4.4, T35)', () => {- it('renders an editable alias input for every version', () => {- render(<VersionDialog hideModal={jest.fn()} />);- // Two mock versions => two alias inputs (design G2/section 4.4).- expect(screen.getAllByPlaceholderText('flow.version.alias')).toHaveLength(- 2,+ it('opens the alias dialog with the current alias when the button is clicked', () => {+ renderDialog();++ fireEvent.click(within(getRow('Old Snapshot')).getByRole('button'));++ expect(screen.getByPlaceholderText('flow.version.alias')).toHaveValue(+ 'old',);});++ it('PATCHes the trimmed new alias on confirm', async () => {+ mockUpdateVersion.mockClear();+ renderDialog();++ fireEvent.click(within(getRow('Old Snapshot')).getByRole('button'));+ fireEvent.change(screen.getByPlaceholderText('flow.version.alias'), {+ target: { value: ' renamed ' },+ });+ fireEvent.click(screen.getByRole('button', { name: 'common.confirm' }));++ await waitFor(() => {+ expect(mockUpdateVersion).toHaveBeenCalledTimes(1);+ });+ expect(mockUpdateVersion).toHaveBeenCalledWith({+ canvasId: 'canvas-1',+ versionId: 'v-old',+ alias: 'renamed',+ });+ });++ it('does not PATCH when the dialog is cancelled', () => {+ mockUpdateVersion.mockClear();+ renderDialog();++ fireEvent.click(within(getRow('Old Snapshot')).getByRole('button'));+ fireEvent.click(screen.getByRole('button', { name: 'common.cancel' }));++ expect(mockUpdateVersion).not.toHaveBeenCalled();+ expect(+ screen.queryByPlaceholderText('flow.version.alias'),+ ).not.toBeInTheDocument();+ });});describe('VersionDialog alias filter (A2/F1, T19)', () => {it('narrows the list to aliases matching the query', () => {- render(<VersionDialog hideModal={jest.fn()} />);+ renderDialog();const filter = screen.getByPlaceholderText('flow.version.filterByAlias');fireEvent.change(filter, { target: { value: 'prod' } });expect(screen.queryByText('Old Snapshot')).not.toBeInTheDocument();expect(screen.getByText('Latest')).toBeInTheDocument();- expect(screen.queryByText('!')).not.toBeInTheDocument();});it('shows every version when the alias filter is cleared', () => {- render(<VersionDialog hideModal={jest.fn()} />);+ renderDialog();const filter = screen.getByPlaceholderText('flow.version.filterByAlias');fireEvent.change(filter, { target: { value: 'prod' } });@@ -121,40 +171,36 @@ describe('VersionDialog alias filter (A2/F1, T19)', () => {expect(screen.getByText('Latest')).toBeInTheDocument();expect(screen.getByText('Old Snapshot')).toBeInTheDocument();- expect(screen.getAllByText('!')).toHaveLength(1);});-});-describe('VersionDialog alias edit commits on blur (G2/section 4.4, T35)', () => {- it('PATCHes the trimmed new alias when the input loses focus', () => {- mockUpdateVersion.mockClear();- render(<VersionDialog hideModal={jest.fn()} />);-- // mockVersions order: [v-latest (alias prod), v-old (alias old)].- const inputs = screen.getAllByPlaceholderText('flow.version.alias');- const oldInput = inputs[1];-- fireEvent.change(oldInput, { target: { value: ' renamed ' } });- fireEvent.blur(oldInput);-- expect(mockUpdateVersion).toHaveBeenCalledTimes(1);- expect(mockUpdateVersion).toHaveBeenCalledWith({- canvasId: 'canvas-1',- versionId: 'v-old',- alias: 'renamed',- });- });-- it('does not PATCH when the alias is unchanged', () => {- mockUpdateVersion.mockClear();- render(<VersionDialog hideModal={jest.fn()} />);-- const inputs = screen.getAllByPlaceholderText('flow.version.alias');- const oldInput = inputs[1]; // alias old-- fireEvent.change(oldInput, { target: { value: 'old' } });- fireEvent.blur(oldInput);-- expect(mockUpdateVersion).not.toHaveBeenCalled();+ it('jumps back to page 1 when filtering shrinks the list', () => {+ const originalVersions = mockVersions;+ // 12 released versions overfill one 10-row page; only the last (page-2)+ // row carries an alias, so filtering must surface it from page 1.+ mockVersions = Array.from({ length: 12 }, (_, i) => ({+ id: `v-${i}`,+ title: `Version ${i}`,+ created_at: '2024-01-01',+ release: true,+ alias: i === 11 ? 'special' : '',+ }));++ try {+ renderDialog();++ fireEvent.click(screen.getByText('2'));+ expect(screen.queryByText('Version 0')).not.toBeInTheDocument();+ expect(screen.getByText('Version 11')).toBeInTheDocument();++ const filter = screen.getByPlaceholderText('flow.version.filterByAlias');+ fireEvent.change(filter, { target: { value: 'special' } });++ // Without the page reset, page 2 would slice past the single match and+ // render an empty list.+ expect(screen.getByText('Version 11')).toBeInTheDocument();+ expect(screen.queryByText('2')).not.toBeInTheDocument();+ } finally {+ mockVersions = originalVersions;+ }});});diff --git a/web/src/pages/agent/version-dialog/index.tsx b/web/src/pages/agent/version-dialog/index.tsxindex 5f29dbbb38..781d6f42ae 100644--- a/web/src/pages/agent/version-dialog/index.tsx+++ b/web/src/pages/agent/version-dialog/index.tsx@@ -1,4 +1,5 @@import { AgentBackground } from '@/components/canvas/background';+import { ConfirmDeleteDialog } from '@/components/confirm-delete-dialog';import Spotlight from '@/components/spotlight';import { Button } from '@/components/ui/button';import { Card, CardContent } from '@/components/ui/card';@@ -8,7 +9,7 @@ import {DialogHeader,DialogTitle,} from '@/components/ui/dialog';-import { Input } from '@/components/ui/input';+import { SearchInput } from '@/components/ui/input';import {AlertDialog,AlertDialogAction,@@ -21,7 +22,11 @@ import {} from '@/components/ui/alert-dialog';import { RAGFlowPagination } from '@/components/ui/ragflow-pagination';import { Spin } from '@/components/ui/spin';-import { AntToolTip, RAGFlowTooltip } from '@/components/ui/tooltip';+import {+ Tooltip,+ TooltipContent,+ TooltipTrigger,+} from '@/components/ui/tooltip';import { useClientPagination } from '@/hooks/logic-hooks/use-pagination';import {useApplyVersion,@@ -34,54 +39,34 @@ import { IModalProps } from '@/interfaces/common';import { cn } from '@/lib/utils';import { formatDate } from '@/utils/date';import { ConnectionMode, ReactFlow, ReactFlowProvider } from '@xyflow/react';-import { ArrowDownToLine, RotateCcw, Trash2 } from 'lucide-react';-import { ReactNode, useCallback, useEffect, useMemo, useState } from 'react';+import {+ ArrowDownToLine,+ Pencil,+ RotateCcw,+ SavePlus,+ Trash2,+} from 'lucide-react';+import {+ ChangeEvent,+ MouseEvent,+ ReactNode,+ useCallback,+ useEffect,+ useMemo,+ useState,+} from 'react';import { useTranslation } from 'react-i18next';import { useParams } from 'react-router';import { nodeTypes } from '../canvas';+import { AliasFormDialog } from '../components/alias-form-dialog';import { downloadDsl } from '../utils/download-dsl';-function Dot() {- return (- <span className="w-2 h-2 inline-block rounded-full bg-accent-primary flex-shrink-0" />- );-}-type PendingAction =| { kind: 'delete'; versionId: string; title: string }| { kind: 'restore'; versionId: string; title: string }| null;-// AliasInput is a controlled input for a single canvas version's free-text alias-// (design G2/section 4.4). It keeps the value in local state and is keyed by-// version id, so parent re-renders (including version-list refetches triggered by-// focus changes or row selection) never unmount the field and wipe in-progress-// keystrokes the way an uncontrolled defaultValue input with a volatile key could.-const AliasInput = ({- placeholder,- initialAlias,- onCommit,-}: {- placeholder: string;- initialAlias: string;- onCommit: (alias: string) => void;-}) => {- const [val, setVal] = useState(initialAlias);- return (- <Input- className="h-7 text-xs"- placeholder={placeholder}- value={val}- onChange={(e) => setVal(e.target.value)}- onClick={(e) => e.stopPropagation()}- onBlur={() => {- const v = val.trim();- if (v === initialAlias) return;- onCommit(v);- }}- />- );-};+type EditingAlias = { versionId: string; alias: string } | null;export function VersionDialog({hideModal,@@ -97,26 +82,44 @@ export function VersionDialog({} = useFetchVersion(selectedId);const [aliasFilter, setAliasFilter] = useState('');const [pending, setPending] = useState<PendingAction>(null);+ const [editingAlias, setEditingAlias] = useState<EditingAlias>(null);const { deleteVersion, loading: deleting } = useDeleteVersion();const { applyVersion, loading: applyRestoring } = useApplyVersion();const { updateVersion } = useUpdateVersion();- // Backend returns the list newest-first (design section 7/E1); the first- // entry is therefore the latest version and every other entry is an older- // snapshot. Non-latest versions get a D1/D2/D3 `!` marker.- const latestId = data[0]?.id;+ // Only published versions are listed: draft saves (manual Save and+ // auto-save) no longer write user_canvas_version rows, so this dialog shows+ // what was published. Rows predating that change are filtered out here.+ const released = useMemo(() => data.filter((x) => x.release), [data]);// A2/F1: alias filtering is a pure front-end filter over the returned set.const filtered = useMemo(() => {const q = aliasFilter.trim().toLowerCase();- if (!q) return data;- return data.filter((x) => (x.alias ?? '').toLowerCase().includes(q));- }, [data, aliasFilter]);+ if (!q) return released;+ return released.filter((x) => (x.alias ?? '').toLowerCase().includes(q));+ }, [released, aliasFilter]);- const { page, pageSize, onPaginationChange, pagedList } =+ const { page, pageSize, setPage, onPaginationChange, pagedList } =useClientPagination(filtered);+ // The version detail (IFlow) has no alias field, so the preview header+ // reads the alias from the list row for the selected version.+ const selectedAlias = useMemo(+ () => released.find((x) => x.id === selectedId)?.alias,+ [released, selectedId],+ );++ // Filtering shrinks the list, so jump back to page 1; otherwise a stale+ // page 2+ selection would render an empty list with matches out of view.+ const handleAliasFilterChange = useCallback(+ (e: ChangeEvent<HTMLInputElement>) => {+ setAliasFilter(e.target.value);+ setPage(1);+ },+ [setPage],+ );+const handleClick = useCallback((id: string) => () => {setSelectedId(id);@@ -124,6 +127,37 @@ export function VersionDialog({[],);+ const handleEditAlias = useCallback(+ (versionId: string, alias: string) => (e: MouseEvent) => {+ // Keep the icon click from also selecting the row.+ e.stopPropagation();+ setEditingAlias({ versionId, alias });+ },+ [],+ );++ const handleAliasDialogOpenChange = useCallback((open: boolean) => {+ if (!open) setEditingAlias(null);+ }, []);++ const handlePendingOpenChange = useCallback((open: boolean) => {+ if (!open) setPending(null);+ }, []);++ const handleSubmitAlias = useCallback(+ (alias?: string) => {+ if (!editingAlias || !canvasId) return;+ // An empty alias clears it (design G2/§4.4); the hook invalidates the+ // version-list cache so the row and preview header refresh in place.+ updateVersion({+ canvasId,+ versionId: editingAlias.versionId,+ alias: alias ?? '',+ });+ },+ [editingAlias, canvasId, updateVersion],+ );+const downloadFile = useCallback(() => {if (agent?.dsl) {downloadDsl(agent.dsl, agent.title);@@ -154,10 +188,10 @@ export function VersionDialog({// Keep the current selection across list refreshes; only fall back to the// newest version when the selected one was pruned server-side.useEffect(() => {- if (data.length > 0 && !data.some((x) => x.id === selectedId)) {- setSelectedId(data[0].id);+ if (released.length > 0 && !released.some((x) => x.id === selectedId)) {+ setSelectedId(released[0].id);}- }, [data, selectedId]);+ }, [released, selectedId]);return (<Dialog open onOpenChange={hideModal}>@@ -169,56 +203,55 @@ export function VersionDialog({</DialogHeader><section className="flex gap-8 relative min-w-0"><div className="w-72 shrink-0 max-h-[60vh] overflow-auto min-h-[40vh]">- <Input- className="mb-3"+ <SearchInput+ rootClassName="m-0.5 mb-3"placeholder={t('flow.version.filterByAlias')}value={aliasFilter}- onChange={(e) => setAliasFilter(e.target.value)}+ onChange={handleAliasFilterChange}/>{loading ? (<Spin className="top-1/2"></Spin>) : (<ul className="space-y-4 text-sm">{pagedList.map((x) => {- const isLatest = x.id === latestId;return (<likey={x.id}- className={cn('cursor-pointer p-2', {- 'bg-card rounded-md ': x.id === selectedId,+ className={cn('group cursor-pointer p-2', {+ 'bg-bg-card rounded-md ': x.id === selectedId,})}onClick={handleClick(x.id)}><div className="flex items-center gap-2"><span className="truncate min-w-0">{x.title}</span>- {x.release && <Dot></Dot>}- {!isLatest && (- <AntToolTip- title={t('flow.version.outdated')}- trigger="click"- >- <span className="text-destructive font-bold">- !- </span>- </AntToolTip>+ {x.alias && (+ <span className="shrink-0 max-w-[20%] truncate text-accent-primary text-xs">+ {x.alias}+ </span>)}- </div>- <div className="mt-1">- {/* Editable alias (design G2, section 4.4): PATCHes the- version metadata without creating a new version or touching the DSL.- Clicking the input must not also select the row. Controlled via AliasInput- so re-renders never wipe in-progress keystrokes. */}- <AliasInput- placeholder={t('flow.version.alias')}- initialAlias={x.alias ?? ''}- onCommit={(alias) =>- updateVersion({- canvasId: canvasId ?? '',- versionId: x.id,- alias,- })- }- />+ {/* Alias edit entry (design G2, section 4.4): PATCHes+ the version metadata without creating a new version or touching the DSL.+ Pencil edits an existing alias, SavePlus adds one. */}+ <Tooltip>+ <TooltipTrigger asChild>+ <button+ type="button"+ className="ml-auto shrink-0 text-text-secondary opacity-0 group-hover:opacity-100 hover:text-text-primary"+ onClick={handleEditAlias(x.id, x.alias ?? '')}+ >+ {x.alias ? (+ <Pencil className="size-3.5" />+ ) : (+ <SavePlus className="size-4" />+ )}+ </button>+ </TooltipTrigger>+ <TooltipContent>+ {x.alias+ ? t('flow.version.editAlias')+ : t('flow.version.addAlias')}+ </TooltipContent>+ </Tooltip></div></li>);@@ -240,25 +273,10 @@ export function VersionDialog({<div className="min-w-0"><div className="flex min-w-0 items-center"><span className="pb-1 truncate">{agent?.title}</span>- {agent?.release && (- <RAGFlowTooltip tooltip={t('flow.productionTooltip')}>- <Button className="bg-accent-primary-5 ml-3">- <Dot></Dot>- <span className="text-accent-primary pl-2 rounded">- {t('flow.production')}- </span>- </Button>- </RAGFlowTooltip>- )}- {selectedId !== latestId && (- <AntToolTip- title={t('flow.version.outdated')}- trigger="click"- >- <span className="ml-2 text-destructive font-bold cursor-help">- !- </span>- </AntToolTip>+ {selectedAlias && (+ <span className="ml-2 shrink-0 text-accent-primary text-sm">+ {selectedAlias}+ </span>)}</div><p className="text-text-secondary text-xs">@@ -285,17 +303,12 @@ export function VersionDialog({})}title={t('flow.version.restore')}- disabled={- selectedId === latestId ||- !selectedId ||- applyRestoring- }+ disabled={!selectedId || applyRestoring}><RotateCcw /></Button><Buttonvariant={'ghost'}- className="text-destructive"onClick={() =>setPending({kind: 'delete',@@ -351,42 +364,48 @@ export function VersionDialog({></RAGFlowPagination></DialogContent>+ <ConfirmDeleteDialog+ open={pending?.kind === 'delete'}+ onOpenChange={handlePendingOpenChange}+ onOk={runPending}+ title={t('flow.version.deleteConfirmTitle')}+ content={{ node: t('flow.version.deleteConfirmContent') }}+ />+<AlertDialog- open={!!pending}- onOpenChange={(open) => {- if (!open) setPending(null);- }}+ open={pending?.kind === 'restore'}+ onOpenChange={handlePendingOpenChange}><AlertDialogContent><AlertDialogHeader><AlertDialogTitle>- {pending?.kind === 'delete'- ? t('flow.version.deleteConfirmTitle')- : t('flow.version.restoreConfirmTitle')}+ {t('flow.version.restoreConfirmTitle')}</AlertDialogTitle><AlertDialogDescription>- {pending?.kind === 'delete'- ? t('flow.version.deleteConfirmContent')- : t('flow.version.restoreConfirmContent')}+ {t('flow.version.restoreConfirmContent')}</AlertDialogDescription></AlertDialogHeader><AlertDialogFooter><AlertDialogCancel>{t('common.cancel')}</AlertDialogCancel>- <AlertDialogAction- onClick={runPending}- className={- pending?.kind === 'delete'- ? 'bg-destructive hover:bg-destructive'- : ''- }- >- {pending?.kind === 'delete'- ? t('flow.version.delete')- : t('flow.version.restore')}+ <AlertDialogAction onClick={runPending}>+ {t('flow.version.restore')}</AlertDialogAction></AlertDialogFooter></AlertDialogContent></AlertDialog>++ {editingAlias && (+ <AliasFormDialog+ // Remount per target version so defaultValues picks up its alias.+ key={editingAlias.versionId}+ open+ onOpenChange={handleAliasDialogOpenChange}+ title={t('flow.version.editAlias')}+ description={t('flow.version.editAliasDescription')}+ initialAlias={editingAlias.alias}+ onSubmit={handleSubmitAlias}+ />+ )}</Dialog>);}