mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-20 06:31:02 +08:00
Feat: Agent api (#14157)
### What problem does this PR solve?
1. **List agents**
**Prev API**:
- `/v1/canvas/list GET`
- `/api/v1/agents GET`
**Current API**: `/api/v2/agents GET`
2. **Get canvas template**
**Prev API**: `/v1/canvas/templates GET`
**Current API**: `/api/v2/agents/templates GET`
3. **Delete an agent**
**Prev API**:
- `/v1/canvas/rm POST`
- `/api/v1/agents/<agent_id> DELETE`
**Current API**: `/api/v2/agents/<agent_id> DELETE`
4. **Update an agent**
**Prev API**:
- `/api/v1/agents/<agent_id> PUT`
- `/v1/canvas/setting POST `
**Current API**: `/api/v2/agents/<agent_id> PATCH`
5. **Create an agent**
**Prev API**:
- `/v1/canvas/set POST`
- `/api/v1/agents POST`
**Current API**: `/api/v2/agents POST`
6. **Get an agent**
**Prev API**:
- `/v1/canvas/get/<canvas_id> GET `
**Current API**: `/api/v2/agents/<agent_id> GET`
7. **Reset an agent**
**Prev API**:
- `/v1/canvas/reset POST`
**Current API**: `/api/v2/agents/<agent_id>/reset POST`
8. **Upload a file to an agent**
**Prev API**:
- `/v1/canvas/upload/<canvas_id> POST`
**Current API**: `/api/v2/agents/<agent_id>/upload POST`
9. **Input form**
**Prev API**:
- `/v1/canvas/input_form GET`
**Current API**:
`/api/v2/agents/<agent_id>/components/<component_id>/input-form GET`
10. **Debug an agent**
**Prev API**:
- `/v1/canvas/debug POST`
**Current API**:
`/api/v2/agents/<agent_id>/components/<component_id>/debug POST`
11. **Trace an agent**
**Prev API**:
- `/v1/canvas/trace GET`
**Current API**: `/api/v2/agents/<agent_id>/logs/<message_id> GET`
12. **Get an agent version list**
**Prev API**:
- `/v1/canvas/getlistversion/<canvas_id>`
**Current API**: `/api/v2/agents/<agent_id>/versions GET`
13. **Get a version of agent**
**Prev API**:
- `/v1/canvas/getversion/<version_id>`
**Current API**: `/api/v2/agents/<agent_id>/versions/<version_id> GET`
14. **Test db connection**
**Prev API**:
- `/v1/canvas/test_db_connect POST`
**Current API**: `/api/v2/agents/test_db_connection`
15. **Rerun the agent**
**Prev API**:
- `/v1/canvas/rerun POST`
**Current API**: `/api/v2/agents/rerun POST`
16. **Get prompts**
**Prev API**:
- `/v1/canvas/prompts GET`
**Current API**: `/api/v2/agents/prompts GET`
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
---------
Co-authored-by: chanx <1243304602@qq.com>
This commit is contained in:
@@ -8,25 +8,20 @@ import { registerNextServer } from '@/utils/register-server';
|
||||
import request from '@/utils/request';
|
||||
|
||||
const {
|
||||
getCanvasSSE,
|
||||
setCanvas,
|
||||
listCanvas,
|
||||
resetCanvas,
|
||||
removeCanvas,
|
||||
runCanvas,
|
||||
listTemplates,
|
||||
createAgent,
|
||||
updateAgent: updateAgentApi,
|
||||
listAgents,
|
||||
deleteAgent,
|
||||
agentChatCompletion,
|
||||
resetAgent,
|
||||
listAgentTemplate,
|
||||
testDbConnect,
|
||||
getInputElements,
|
||||
debug,
|
||||
settingCanvas,
|
||||
uploadCanvasFile,
|
||||
trace,
|
||||
inputForm,
|
||||
fetchVersionList,
|
||||
fetchVersion,
|
||||
fetchCanvas,
|
||||
fetchAgentAvatar,
|
||||
fetchAgentLogs,
|
||||
getAgent,
|
||||
fetchAgentSessions,
|
||||
fetchExternalAgentInputs,
|
||||
prompt,
|
||||
cancelDataflow,
|
||||
@@ -34,16 +29,12 @@ const {
|
||||
} = api;
|
||||
|
||||
const methods = {
|
||||
fetchCanvas: {
|
||||
url: fetchCanvas,
|
||||
getAgent: {
|
||||
url: getAgent,
|
||||
method: 'get',
|
||||
},
|
||||
getCanvasSSE: {
|
||||
url: getCanvasSSE,
|
||||
method: 'get',
|
||||
},
|
||||
setCanvas: {
|
||||
url: setCanvas,
|
||||
createAgent: {
|
||||
url: createAgent,
|
||||
method: 'post',
|
||||
},
|
||||
fetchVersionList: {
|
||||
@@ -51,27 +42,28 @@ const methods = {
|
||||
method: 'get',
|
||||
},
|
||||
fetchVersion: {
|
||||
url: fetchVersion,
|
||||
url: (config: { agentId: string; versionId: string }) =>
|
||||
fetchVersion(config.agentId, config.versionId),
|
||||
method: 'get',
|
||||
},
|
||||
listCanvas: {
|
||||
url: listCanvas,
|
||||
listAgents: {
|
||||
url: listAgents,
|
||||
method: 'get',
|
||||
},
|
||||
resetCanvas: {
|
||||
url: resetCanvas,
|
||||
resetAgent: {
|
||||
url: resetAgent,
|
||||
method: 'post',
|
||||
},
|
||||
removeCanvas: {
|
||||
url: removeCanvas,
|
||||
deleteAgent: {
|
||||
url: deleteAgent,
|
||||
method: 'delete',
|
||||
},
|
||||
agentChatCompletion: {
|
||||
url: agentChatCompletion,
|
||||
method: 'post',
|
||||
},
|
||||
runCanvas: {
|
||||
url: runCanvas,
|
||||
method: 'post',
|
||||
},
|
||||
listTemplates: {
|
||||
url: listTemplates,
|
||||
listAgentTemplate: {
|
||||
url: listAgentTemplate,
|
||||
method: 'get',
|
||||
},
|
||||
testDbConnect: {
|
||||
@@ -83,31 +75,26 @@ const methods = {
|
||||
method: 'get',
|
||||
},
|
||||
debugSingle: {
|
||||
url: debug,
|
||||
url: (config: { agentId: string; componentId: string }) =>
|
||||
api.debug(config.agentId, config.componentId),
|
||||
method: 'post',
|
||||
},
|
||||
settingCanvas: {
|
||||
url: settingCanvas,
|
||||
method: 'post',
|
||||
},
|
||||
uploadCanvasFile: {
|
||||
url: uploadCanvasFile,
|
||||
uploadAgentFile: {
|
||||
url: (config: { agentId: string }) => api.uploadAgentFile(config.agentId),
|
||||
method: 'post',
|
||||
},
|
||||
trace: {
|
||||
url: trace,
|
||||
url: (config: { agentId: string; messageId: string }) =>
|
||||
trace(config.agentId, config.messageId),
|
||||
method: 'get',
|
||||
},
|
||||
inputForm: {
|
||||
url: inputForm,
|
||||
method: 'get',
|
||||
},
|
||||
fetchAgentAvatar: {
|
||||
url: fetchAgentAvatar,
|
||||
url: (config: { agentId: string; componentId: string }) =>
|
||||
api.inputForm(config.agentId, config.componentId),
|
||||
method: 'get',
|
||||
},
|
||||
fetchAgentLogs: {
|
||||
url: fetchAgentLogs,
|
||||
url: fetchAgentSessions,
|
||||
method: 'get',
|
||||
},
|
||||
fetchExternalAgentInputs: {
|
||||
@@ -127,15 +114,34 @@ const methods = {
|
||||
method: 'put',
|
||||
},
|
||||
createAgentSession: {
|
||||
url: fetchAgentLogs,
|
||||
method: 'put',
|
||||
url: api.createAgentSession,
|
||||
method: 'post',
|
||||
},
|
||||
} as const;
|
||||
|
||||
const agentService = registerNextServer<keyof typeof methods>(methods);
|
||||
|
||||
export const updateAgent = (
|
||||
agentId: string,
|
||||
params: {
|
||||
title?: string;
|
||||
dsl?: Record<string, any>;
|
||||
avatar?: string;
|
||||
description?: string | null;
|
||||
permission?: string;
|
||||
release?: string;
|
||||
},
|
||||
) => {
|
||||
return request(updateAgentApi(agentId), { method: 'put', data: params });
|
||||
};
|
||||
|
||||
export const fetchTrace = (data: { canvas_id: string; message_id: string }) => {
|
||||
return request.get(methods.trace.url, { params: data });
|
||||
return request.get(
|
||||
methods.trace.url({
|
||||
agentId: data.canvas_id,
|
||||
messageId: data.message_id,
|
||||
}),
|
||||
);
|
||||
};
|
||||
export const fetchAgentLogsByCanvasId = (
|
||||
canvasId: string,
|
||||
@@ -145,11 +151,11 @@ export const fetchAgentLogsByCanvasId = (
|
||||
};
|
||||
|
||||
export const fetchAgentLogsById = (canvasId: string, sessionId: string) => {
|
||||
return request.get(api.fetchAgentLogsById(canvasId, sessionId));
|
||||
return request.get(api.fetchAgentSessionById(canvasId, sessionId));
|
||||
};
|
||||
|
||||
export const fetchPipeLineList = (params: IPipeLineListRequest) => {
|
||||
return request.get(api.listCanvas, { params: params });
|
||||
return request.get(api.listAgents, { params: params });
|
||||
};
|
||||
|
||||
export const fetchWebhookTrace = (
|
||||
@@ -160,11 +166,18 @@ export const fetchWebhookTrace = (
|
||||
};
|
||||
|
||||
export function createAgentSession({ id, name }: { id: string; name: string }) {
|
||||
return request.put(api.fetchAgentLogs(id), { data: { name } });
|
||||
return request.post(api.createAgentSession(id), { data: { name } });
|
||||
}
|
||||
|
||||
export const deleteAgentSession = (canvasId: string, sessionId: string) => {
|
||||
return request.delete(api.fetchAgentLogsById(canvasId, sessionId));
|
||||
return request.delete(api.fetchAgentSessionById(canvasId, sessionId));
|
||||
};
|
||||
|
||||
export const uploadAgentFile = (agentId: string, data: FormData) => {
|
||||
return request(api.uploadAgentFile(agentId), {
|
||||
method: 'post',
|
||||
data,
|
||||
});
|
||||
};
|
||||
|
||||
export default agentService;
|
||||
|
||||
Reference in New Issue
Block a user