Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Feature: add apply and delete version for agent (#21538)

Wang Qi68492cd6db18
diff --git a/internal/dao/user_canvas_version.go b/internal/dao/user_canvas_version.go
index 2177db6109..c1fa187c42 100644
--- a/internal/dao/user_canvas_version.go
+++ b/internal/dao/user_canvas_version.go
@@ -47,12 +47,12 @@ var ErrPipelineVersionMissing = errors.New("pipeline version missing or not owne
// (pipeline_version_id is empty / not selected). Per design C5/G3 the empty
// version is no longer auto-backfilled to the canvas latest; instead the Save is
// rejected so the UI can surface the red "Missing" badge and the
-// "版本信息缺失" error. BuiltIn mode (no canvas bound) is exempt.
-var ErrPipelineVersionEmpty = errors.New("版本信息缺失")
+// "version information is missing" error. BuiltIn mode (no canvas bound) is exempt.
+var ErrPipelineVersionEmpty = errors.New("version information is missing")
// userFacingVersionHint is appended to every Missing-state error so the runtime
// parse path can surface a human-readable instruction (design section 6.2, C4).
-const userFacingVersionHint = "pipeline 版本不存在,请重新选择版本"
+const userFacingVersionHint = "pipeline version does not exist. Please select a version again"
// MaxCanvasVersions is the per-canvas cap on the number of DSL versions (K=64,
// design: limit the number of versions of a DSL). When a canvas already holds
@@ -65,7 +65,7 @@ const MaxCanvasVersions = 64
// ErrCanvasVersionLimitExceeded is returned by SaveOrReplaceLatestTx when a new
// version write would exceed MaxCanvasVersions. The handler surfaces it to the
// frontend as a data error with this user-facing hint.
-var ErrCanvasVersionLimitExceeded = errors.New("版本数已达上限(最多 64 个),请删除旧的不再使用的版本")
+var ErrCanvasVersionLimitExceeded = errors.New("version limit reached (maximum 64). Please delete old versions that are no longer in use")
// LoadCanvasVersionDSL resolves the DSL for a dataflow canvas version. When
// versionID is non-empty it pins that exact version; when empty it resolves the
diff --git a/internal/dao/user_canvas_version_limit_test.go b/internal/dao/user_canvas_version_limit_test.go
index a4d5699312..46ae22d175 100644
--- a/internal/dao/user_canvas_version_limit_test.go
+++ b/internal/dao/user_canvas_version_limit_test.go
@@ -85,8 +85,8 @@ func TestCanvasVersionLimit_RejectsAtCap(t *testing.T) {
if !errors.Is(err, ErrCanvasVersionLimitExceeded) {
t.Fatalf("cap rejection must return ErrCanvasVersionLimitExceeded, got: %v", err)
}
- if !strings.Contains(err.Error(), "版本数已达上限") {
- t.Fatalf("cap error must surface the Chinese hint, got: %v", err)
+ if !strings.Contains(err.Error(), "version limit reached") {
+ t.Fatalf("cap error must surface the English hint, got: %v", err)
}
after := countVersions(t, db, canvasID)
if after != before {
diff --git a/internal/ingestion/task/pipeline_version_test.go b/internal/ingestion/task/pipeline_version_test.go
index 3d115624a8..a2b06d5538 100644
--- a/internal/ingestion/task/pipeline_version_test.go
+++ b/internal/ingestion/task/pipeline_version_test.go
@@ -160,7 +160,7 @@ func TestLoadDSLFromCanvas_PinnedMissingVersionFails(t *testing.T) {
if !errors.Is(err, ErrPipelineVersionMissing) {
t.Fatalf("err = %v, want ErrPipelineVersionMissing", err)
}
- if !strings.Contains(err.Error(), "pipeline 版本不存在,请重新选择版本") {
+ if !strings.Contains(err.Error(), "pipeline version does not exist. Please select a version again") {
t.Fatalf("err message missing user hint: %v", err)
}
})
diff --git a/web/src/hooks/use-agent-request.ts b/web/src/hooks/use-agent-request.ts
index 4f6dfc91d1..1fe2f442d0 100644
--- a/web/src/hooks/use-agent-request.ts
+++ b/web/src/hooks/use-agent-request.ts
@@ -902,6 +902,35 @@ export const useDeleteVersion = () => {
return { loading, isError, deleteVersion: mutateAsync };
};
+export const useApplyVersion = () => {
+ const queryClient = useQueryClient();
+ const { isPending: loading, mutateAsync } = useMutation({
+ mutationFn: async ({
+ canvasId,
+ versionId,
+ }: {
+ canvasId: string;
+ versionId: string;
+ }) => {
+ const { data } = await agentService.applyVersion({
+ agentId: canvasId,
+ versionId,
+ });
+ return data?.code === 0;
+ },
+ onSuccess: (ok, { canvasId }) => {
+ if (!ok) return;
+ queryClient.invalidateQueries({ queryKey: AgentKeys.list() });
+ queryClient.invalidateQueries({
+ queryKey: AgentKeys.versionList(canvasId),
+ });
+ queryClient.invalidateQueries({ queryKey: AgentKeys.detail(canvasId) });
+ },
+ });
+
+ return { loading, applyVersion: mutateAsync };
+};
+
export const useUpdateVersion = () => {
const queryClient = useQueryClient();
const {
diff --git a/web/src/pages/agent/version-dialog/index.test.tsx b/web/src/pages/agent/version-dialog/index.test.tsx
index a513dbcab6..6ac46f8809 100644
--- a/web/src/pages/agent/version-dialog/index.test.tsx
+++ b/web/src/pages/agent/version-dialog/index.test.tsx
@@ -68,7 +68,7 @@ jest.mock('@/hooks/use-agent-request', () => ({
loading: false,
isError: false,
}),
- useSetAgent: () => ({ setAgent: jest.fn(), loading: false }),
+ useApplyVersion: () => ({ applyVersion: jest.fn(), loading: false }),
useUpdateVersion: () => ({
updateVersion: mockUpdateVersion,
loading: false,
diff --git a/web/src/pages/agent/version-dialog/index.tsx b/web/src/pages/agent/version-dialog/index.tsx
index 413fce12da..c4285c0c9e 100644
--- a/web/src/pages/agent/version-dialog/index.tsx
+++ b/web/src/pages/agent/version-dialog/index.tsx
@@ -24,10 +24,10 @@ import { Spin } from '@/components/ui/spin';
import { AntToolTip, RAGFlowTooltip } from '@/components/ui/tooltip';
import { useClientPagination } from '@/hooks/logic-hooks/use-pagination';
import {
+ useApplyVersion,
useDeleteVersion,
useFetchVersion,
useFetchVersionList,
- useSetAgent,
useUpdateVersion,
} from '@/hooks/use-agent-request';
import { IModalProps } from '@/interfaces/common';
@@ -103,7 +103,7 @@ export function VersionDialog({
const [pending, setPending] = useState<PendingAction>(null);
const { deleteVersion, loading: deleting } = useDeleteVersion();
- const { setAgent, loading: restoring } = useSetAgent(false);
+ const { applyVersion, loading: restoring } = useApplyVersion();
const { updateVersion } = useUpdateVersion();
// Backend returns the list newest-first (design section 7/E1); the first
@@ -146,22 +146,14 @@ export function VersionDialog({
});
if (ok && selectedId === pending.versionId) setSelectedId('');
} else if (pending.kind === 'restore') {
- await setAgent({
- id: canvasId,
- dsl: agent?.dsl,
- title: agent?.title,
+ const ok = await applyVersion({
+ canvasId,
+ versionId: pending.versionId,
});
+ if (ok) hideModal?.();
}
setPending(null);
- }, [
- pending,
- canvasId,
- deleteVersion,
- selectedId,
- setAgent,
- agent?.dsl,
- agent?.title,
- ]);
+ }, [pending, canvasId, deleteVersion, selectedId, applyVersion, hideModal]);
// Keep the current selection across list refreshes; only fall back to the
// newest version when the selected one was pruned server-side.
diff --git a/web/src/services/agent-service.ts b/web/src/services/agent-service.ts
index d4606ef19f..29140aa73a 100644
--- a/web/src/services/agent-service.ts
+++ b/web/src/services/agent-service.ts
@@ -68,7 +68,8 @@ const methods = {
method: 'get',
},
deleteVersion: {
- url: deleteVersion,
+ url: (config: { agentId: string; versionId: string }) =>
+ deleteVersion(config.agentId, config.versionId),
method: 'delete',
},
updateVersion: {
@@ -76,6 +77,11 @@ const methods = {
updateVersionApi(config.agentId, config.versionId),
method: 'put',
},
+ applyVersion: {
+ url: (config: { agentId: string; versionId: string }) =>
+ api.applyVersion(config.agentId, config.versionId),
+ method: 'post',
+ },
listAgents: {
url: listAgents,
method: 'get',
diff --git a/web/src/utils/api.ts b/web/src/utils/api.ts
index 76566ca43c..fd84419a58 100644
--- a/web/src/utils/api.ts
+++ b/web/src/utils/api.ts
@@ -370,6 +370,8 @@ export default {
`${restAPIv1}/agents/${agentId}/versions/${versionId}`,
updateVersion: (agentId: string, versionId: string) =>
`${restAPIv1}/agents/${agentId}/versions/${versionId}`,
+ applyVersion: (agentId: string, versionId: string) =>
+ `${restAPIv1}/agents/${agentId}/versions/${versionId}/apply`,
getAgent: (id: string) => `${restAPIv1}/agents/${id}`,
uploadAgentFile: (id?: string) => `${restAPIv1}/agents/${id}/upload`,
createAgentSession: (agentId: string) =>