Merge branch 'PingChuan' into shiy-login
This commit is contained in:
@@ -209,7 +209,7 @@ export default function Index() {
|
||||
// console.log('📌 [Index] 合同模块,跳转到:', targetPath);
|
||||
} else if (module.name === '智慧法务大模型') {
|
||||
// 智慧法务大模型 → 跳转到 AI 对话
|
||||
targetPath = '/chat-with-llm';
|
||||
targetPath = '/chat-with-llm/chat';
|
||||
// console.log('📌 [Index] 智慧法务大模型,跳转到:', targetPath);
|
||||
} else {
|
||||
// console.log('📌 [Index] 其他模块,跳转到:', targetPath);
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import { type LoaderFunctionArgs } from '@remix-run/node';
|
||||
import { API_BASE_URL } from '~/config/api-config';
|
||||
|
||||
/**
|
||||
* GET /api/dataset/datasets/:datasetId/documents/:batch/indexing-status
|
||||
* 获取文档嵌入状态(处理进度)
|
||||
*
|
||||
* Dify API: GET /datasets/{dataset_id}/documents/{batch}/indexing-status
|
||||
*
|
||||
* 返回示例:
|
||||
* {
|
||||
* "data": [{
|
||||
* "id": "",
|
||||
* "indexing_status": "indexing",
|
||||
* "processing_started_at": 1681623462.0,
|
||||
* "parsing_completed_at": 1681623462.0,
|
||||
* "cleaning_completed_at": 1681623462.0,
|
||||
* "splitting_completed_at": 1681623462.0,
|
||||
* "completed_at": null,
|
||||
* "paused_at": null,
|
||||
* "error": null,
|
||||
* "stopped_at": null,
|
||||
* "completed_segments": 24,
|
||||
* "total_segments": 100
|
||||
* }]
|
||||
* }
|
||||
*/
|
||||
export async function loader({ request, params }: LoaderFunctionArgs) {
|
||||
try {
|
||||
const { getUserSession } = await import("~/api/login/auth.server");
|
||||
const { frontendJWT } = await getUserSession(request);
|
||||
|
||||
if (!frontendJWT) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'JWT认证失败,请重新登录' }),
|
||||
{ status: 401, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const { datasetId, batch } = params;
|
||||
if (!datasetId || !batch) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: '缺少必要参数 (datasetId, batch)' }),
|
||||
{ status: 400, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
console.log('[API] Indexing Status:', { datasetId, batch });
|
||||
|
||||
// 转发请求到 FastAPI -> Dify API
|
||||
const apiUrl = `${API_BASE_URL}/dify_dataset/datasets/${datasetId}/documents/${batch}/indexing-status`;
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${frontendJWT}`,
|
||||
},
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
return new Response(JSON.stringify(data), {
|
||||
status: response.status,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('[API] Indexing Status - Error:', error.message);
|
||||
return new Response(
|
||||
JSON.stringify({ error: error.message || 'Failed to get indexing status' }),
|
||||
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
import { type ActionFunctionArgs } from '@remix-run/node';
|
||||
import { API_BASE_URL } from '~/config/api-config';
|
||||
|
||||
/**
|
||||
* PATCH /api/dataset/datasets/:datasetId/documents/:documentId/segments/:segmentId/child_chunks/:childChunkId - 更新子分段
|
||||
* DELETE /api/dataset/datasets/:datasetId/documents/:documentId/segments/:segmentId/child_chunks/:childChunkId - 删除子分段
|
||||
*
|
||||
* Dify API:
|
||||
* - PATCH /datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks/{child_chunk_id}
|
||||
* - DELETE /datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks/{child_chunk_id}
|
||||
*/
|
||||
export async function action({ request, params }: ActionFunctionArgs) {
|
||||
try {
|
||||
const { getUserSession } = await import("~/api/login/auth.server");
|
||||
const { frontendJWT } = await getUserSession(request);
|
||||
|
||||
if (!frontendJWT) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'JWT认证失败,请重新登录' }),
|
||||
{ status: 401, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const { datasetId, documentId, segmentId, childChunkId } = params;
|
||||
if (!datasetId || !documentId || !segmentId || !childChunkId) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: '缺少必要参数' }),
|
||||
{ status: 400, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const method = request.method;
|
||||
const apiUrl = `${API_BASE_URL}/dify_dataset/datasets/${datasetId}/documents/${documentId}/segments/${segmentId}/child_chunks/${childChunkId}`;
|
||||
|
||||
if (method === 'DELETE') {
|
||||
console.log('[API] Delete Child Chunk:', { datasetId, documentId, segmentId, childChunkId });
|
||||
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${frontendJWT}`,
|
||||
},
|
||||
});
|
||||
|
||||
// Dify 删除子分段返回 204 No Content
|
||||
if (response.status === 204) {
|
||||
return new Response(
|
||||
JSON.stringify({ result: 'success' }),
|
||||
{ status: 200, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return new Response(JSON.stringify(data), {
|
||||
status: response.status,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
|
||||
if (method === 'PATCH') {
|
||||
const body = await request.json();
|
||||
console.log('[API] Update Child Chunk:', { datasetId, documentId, segmentId, childChunkId, body });
|
||||
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${frontendJWT}`,
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
return new Response(JSON.stringify(data), {
|
||||
status: response.status,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'Method not allowed' }),
|
||||
{ status: 405, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('[API] Child Chunk Action - Error:', error.message);
|
||||
return new Response(
|
||||
JSON.stringify({ error: error.message || 'Failed to process child chunk request' }),
|
||||
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
import { type LoaderFunctionArgs, type ActionFunctionArgs } from '@remix-run/node';
|
||||
import { API_BASE_URL } from '~/config/api-config';
|
||||
|
||||
/**
|
||||
* GET /api/dataset/datasets/:datasetId/documents/:documentId/segments/:segmentId/child_chunks - 获取子分段列表
|
||||
* Dify API: GET /datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks
|
||||
*/
|
||||
export async function loader({ request, params }: LoaderFunctionArgs) {
|
||||
try {
|
||||
const { getUserSession } = await import("~/api/login/auth.server");
|
||||
const { frontendJWT } = await getUserSession(request);
|
||||
|
||||
if (!frontendJWT) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'JWT认证失败,请重新登录' }),
|
||||
{ status: 401, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const { datasetId, documentId, segmentId } = params;
|
||||
if (!datasetId || !documentId || !segmentId) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: '缺少必要参数' }),
|
||||
{ status: 400, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
// 获取查询参数
|
||||
const url = new URL(request.url);
|
||||
const page = url.searchParams.get('page') || '1';
|
||||
const limit = url.searchParams.get('limit') || '20';
|
||||
const keyword = url.searchParams.get('keyword') || '';
|
||||
|
||||
console.log('[API] Child Chunks List:', { datasetId, documentId, segmentId, page, limit, keyword });
|
||||
|
||||
// 构建查询参数
|
||||
const queryParams = new URLSearchParams({ page, limit });
|
||||
if (keyword) queryParams.append('keyword', keyword);
|
||||
|
||||
// 转发请求到 FastAPI -> Dify API
|
||||
const apiUrl = `${API_BASE_URL}/dify_dataset/datasets/${datasetId}/documents/${documentId}/segments/${segmentId}/child_chunks?${queryParams}`;
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${frontendJWT}`,
|
||||
},
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
return new Response(JSON.stringify(data), {
|
||||
status: response.status,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('[API] Child Chunks List - Error:', error.message);
|
||||
return new Response(
|
||||
JSON.stringify({ error: error.message || 'Failed to get child chunks' }),
|
||||
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/dataset/datasets/:datasetId/documents/:documentId/segments/:segmentId/child_chunks - 新增子分段
|
||||
* Dify API: POST /datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}/child_chunks
|
||||
* 请求体: { content: string }
|
||||
*/
|
||||
export async function action({ request, params }: ActionFunctionArgs) {
|
||||
try {
|
||||
const { getUserSession } = await import("~/api/login/auth.server");
|
||||
const { frontendJWT } = await getUserSession(request);
|
||||
|
||||
if (!frontendJWT) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'JWT认证失败,请重新登录' }),
|
||||
{ status: 401, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const { datasetId, documentId, segmentId } = params;
|
||||
if (!datasetId || !documentId || !segmentId) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: '缺少必要参数' }),
|
||||
{ status: 400, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
if (request.method !== 'POST') {
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'Method not allowed' }),
|
||||
{ status: 405, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
console.log('[API] Create Child Chunk:', { datasetId, documentId, segmentId });
|
||||
|
||||
// 转发请求到 FastAPI -> Dify API
|
||||
const apiUrl = `${API_BASE_URL}/dify_dataset/datasets/${datasetId}/documents/${documentId}/segments/${segmentId}/child_chunks`;
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${frontendJWT}`,
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
return new Response(JSON.stringify(data), {
|
||||
status: response.status,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('[API] Create Child Chunk - Error:', error.message);
|
||||
return new Response(
|
||||
JSON.stringify({ error: error.message || 'Failed to create child chunk' }),
|
||||
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
import { type LoaderFunctionArgs, type ActionFunctionArgs } from '@remix-run/node';
|
||||
import { API_BASE_URL } from '~/config/api-config';
|
||||
|
||||
/**
|
||||
* GET /api/dataset/datasets/:datasetId/documents/:documentId/segments/:segmentId - 获取分段详情
|
||||
* Dify API: GET /datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}
|
||||
*/
|
||||
export async function loader({ request, params }: LoaderFunctionArgs) {
|
||||
try {
|
||||
const { getUserSession } = await import("~/api/login/auth.server");
|
||||
const { frontendJWT } = await getUserSession(request);
|
||||
|
||||
if (!frontendJWT) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'JWT认证失败,请重新登录' }),
|
||||
{ status: 401, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const { datasetId, documentId, segmentId } = params;
|
||||
if (!datasetId || !documentId || !segmentId) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: '缺少必要参数' }),
|
||||
{ status: 400, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
console.log('[API] Segment Detail:', { datasetId, documentId, segmentId });
|
||||
|
||||
// 转发请求到 FastAPI -> Dify API
|
||||
const apiUrl = `${API_BASE_URL}/dify_dataset/datasets/${datasetId}/documents/${documentId}/segments/${segmentId}`;
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${frontendJWT}`,
|
||||
},
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
return new Response(JSON.stringify(data), {
|
||||
status: response.status,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('[API] Segment Detail - Error:', error.message);
|
||||
return new Response(
|
||||
JSON.stringify({ error: error.message || 'Failed to get segment' }),
|
||||
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* DELETE /api/dataset/datasets/:datasetId/documents/:documentId/segments/:segmentId - 删除分段
|
||||
* POST - 更新分段 (Dify用POST更新分段,可传enabled参数切换状态)
|
||||
* Dify API: DELETE/POST /datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}
|
||||
*/
|
||||
export async function action({ request, params }: ActionFunctionArgs) {
|
||||
try {
|
||||
const { getUserSession } = await import("~/api/login/auth.server");
|
||||
const { frontendJWT } = await getUserSession(request);
|
||||
|
||||
if (!frontendJWT) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'JWT认证失败,请重新登录' }),
|
||||
{ status: 401, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const { datasetId, documentId, segmentId } = params;
|
||||
if (!datasetId || !documentId || !segmentId) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: '缺少必要参数' }),
|
||||
{ status: 400, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const method = request.method;
|
||||
const apiUrl = `${API_BASE_URL}/dify_dataset/datasets/${datasetId}/documents/${documentId}/segments/${segmentId}`;
|
||||
|
||||
if (method === 'DELETE') {
|
||||
console.log('[API] Delete Segment:', { datasetId, documentId, segmentId });
|
||||
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${frontendJWT}`,
|
||||
},
|
||||
});
|
||||
|
||||
// Dify删除分段返回 204 No Content
|
||||
if (response.status === 204) {
|
||||
return new Response(
|
||||
JSON.stringify({ result: 'success' }),
|
||||
{ status: 200, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return new Response(JSON.stringify(data), {
|
||||
status: response.status,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
|
||||
if (method === 'POST') {
|
||||
// POST 用于更新分段(包括启用/禁用)
|
||||
const body = await request.json();
|
||||
console.log('[API] Update Segment:', { datasetId, documentId, segmentId, body });
|
||||
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${frontendJWT}`,
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
return new Response(JSON.stringify(data), {
|
||||
status: response.status,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'Method not allowed' }),
|
||||
{ status: 405, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('[API] Segment Action - Error:', error.message);
|
||||
return new Response(
|
||||
JSON.stringify({ error: error.message || 'Failed to process segment request' }),
|
||||
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
import { type LoaderFunctionArgs, type ActionFunctionArgs } from '@remix-run/node';
|
||||
import { API_BASE_URL } from '~/config/api-config';
|
||||
|
||||
/**
|
||||
* GET /api/dataset/datasets/:datasetId/documents/:documentId/segments - 获取分段列表
|
||||
* Dify API: GET /datasets/{dataset_id}/documents/{document_id}/segments
|
||||
*/
|
||||
export async function loader({ request, params }: LoaderFunctionArgs) {
|
||||
try {
|
||||
const { getUserSession } = await import("~/api/login/auth.server");
|
||||
const { frontendJWT } = await getUserSession(request);
|
||||
|
||||
if (!frontendJWT) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'JWT认证失败,请重新登录' }),
|
||||
{ status: 401, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const { datasetId, documentId } = params;
|
||||
if (!datasetId || !documentId) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: '缺少必要参数' }),
|
||||
{ status: 400, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
// 获取查询参数
|
||||
const url = new URL(request.url);
|
||||
const page = url.searchParams.get('page') || '1';
|
||||
const limit = url.searchParams.get('limit') || '20';
|
||||
const keyword = url.searchParams.get('keyword') || '';
|
||||
const status = url.searchParams.get('status') || '';
|
||||
|
||||
console.log('[API] Segments List:', { datasetId, documentId, page, limit, keyword, status });
|
||||
|
||||
// 构建查询参数
|
||||
const queryParams = new URLSearchParams({ page, limit });
|
||||
if (keyword) queryParams.append('keyword', keyword);
|
||||
if (status) queryParams.append('status', status);
|
||||
|
||||
// 转发请求到 FastAPI -> Dify API
|
||||
const apiUrl = `${API_BASE_URL}/dify_dataset/datasets/${datasetId}/documents/${documentId}/segments?${queryParams}`;
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${frontendJWT}`,
|
||||
},
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
return new Response(JSON.stringify(data), {
|
||||
status: response.status,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('[API] Segments List - Error:', error.message);
|
||||
return new Response(
|
||||
JSON.stringify({ error: error.message || 'Failed to get segments' }),
|
||||
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/dataset/datasets/:datasetId/documents/:documentId/segments - 新增分段(批量)
|
||||
* Dify API: POST /datasets/{dataset_id}/documents/{document_id}/segments
|
||||
* 请求体: { segments: [{ content, answer?, keywords? }] }
|
||||
*/
|
||||
export async function action({ request, params }: ActionFunctionArgs) {
|
||||
try {
|
||||
const { getUserSession } = await import("~/api/login/auth.server");
|
||||
const { frontendJWT } = await getUserSession(request);
|
||||
|
||||
if (!frontendJWT) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'JWT认证失败,请重新登录' }),
|
||||
{ status: 401, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const { datasetId, documentId } = params;
|
||||
if (!datasetId || !documentId) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: '缺少必要参数' }),
|
||||
{ status: 400, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
if (request.method !== 'POST') {
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'Method not allowed' }),
|
||||
{ status: 405, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
console.log('[API] Create Segments:', { datasetId, documentId, segmentsCount: body.segments?.length });
|
||||
|
||||
// 转发请求到 FastAPI -> Dify API
|
||||
const apiUrl = `${API_BASE_URL}/dify_dataset/datasets/${datasetId}/documents/${documentId}/segments`;
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${frontendJWT}`,
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
return new Response(JSON.stringify(data), {
|
||||
status: response.status,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('[API] Create Segments - Error:', error.message);
|
||||
return new Response(
|
||||
JSON.stringify({ error: error.message || 'Failed to create segments' }),
|
||||
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
|
||||
|
||||
console.log('[API] Document Detail:', { datasetId, documentId });
|
||||
|
||||
const apiUrl = `${API_BASE_URL}/dify-dataset/datasets/${datasetId}/documents/${documentId}`;
|
||||
const apiUrl = `${API_BASE_URL}/dify_dataset/datasets/${datasetId}/documents/${documentId}`;
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
@@ -79,7 +79,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
||||
if (method === 'DELETE') {
|
||||
console.log('[API] Delete Document:', { datasetId, documentId });
|
||||
|
||||
const apiUrl = `${API_BASE_URL}/dify-dataset/datasets/${datasetId}/documents/${documentId}`;
|
||||
const apiUrl = `${API_BASE_URL}/dify_dataset/datasets/${datasetId}/documents/${documentId}`;
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
|
||||
+26
-13
@@ -1,10 +1,26 @@
|
||||
import { type ActionFunctionArgs } from '@remix-run/node';
|
||||
import { type LoaderFunctionArgs } from '@remix-run/node';
|
||||
import { API_BASE_URL } from '~/config/api-config';
|
||||
|
||||
/**
|
||||
* PATCH /api/dataset/datasets/:datasetId/documents/:documentId/status - 切换文档状态
|
||||
* GET /api/dataset/datasets/:datasetId/documents/:documentId/upload-file
|
||||
* 获取文档上传文件信息
|
||||
*
|
||||
* Dify API: GET /datasets/{dataset_id}/documents/{document_id}/upload-file
|
||||
*
|
||||
* 返回示例:
|
||||
* {
|
||||
* "id": "file_id",
|
||||
* "name": "file_name",
|
||||
* "size": 1024,
|
||||
* "extension": "txt",
|
||||
* "url": "preview_url",
|
||||
* "download_url": "download_url",
|
||||
* "mime_type": "text/plain",
|
||||
* "created_by": "user_id",
|
||||
* "created_at": 1728734540
|
||||
* }
|
||||
*/
|
||||
export async function action({ request, params }: ActionFunctionArgs) {
|
||||
export async function loader({ request, params }: LoaderFunctionArgs) {
|
||||
try {
|
||||
const { getUserSession } = await import("~/api/login/auth.server");
|
||||
const { frontendJWT } = await getUserSession(request);
|
||||
@@ -19,24 +35,21 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
||||
const { datasetId, documentId } = params;
|
||||
if (!datasetId || !documentId) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: '缺少必要参数' }),
|
||||
JSON.stringify({ error: '缺少必要参数 (datasetId, documentId)' }),
|
||||
{ status: 400, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const { enabled } = body;
|
||||
console.log('[API] Upload File Info:', { datasetId, documentId });
|
||||
|
||||
console.log('[API] Toggle Document Status:', { datasetId, documentId, enabled });
|
||||
|
||||
const apiUrl = `${API_BASE_URL}/dify-dataset/datasets/${datasetId}/documents/${documentId}/status`;
|
||||
// 转发请求到 FastAPI -> Dify API
|
||||
const apiUrl = `${API_BASE_URL}/dify_dataset/datasets/${datasetId}/documents/${documentId}/upload-file`;
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'PATCH',
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${frontendJWT}`,
|
||||
},
|
||||
body: JSON.stringify({ enabled }),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
@@ -47,9 +60,9 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
||||
});
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('[API] Toggle Document Status - Error:', error.message);
|
||||
console.error('[API] Upload File Info - Error:', error.message);
|
||||
return new Response(
|
||||
JSON.stringify({ error: error.message || 'Failed to toggle status' }),
|
||||
JSON.stringify({ error: error.message || 'Failed to get upload file info' }),
|
||||
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import { type ActionFunctionArgs } from '@remix-run/node';
|
||||
import { API_BASE_URL } from '~/config/api-config';
|
||||
|
||||
/**
|
||||
* PATCH /api/dataset/datasets/:datasetId/documents/status/:action - 批量更新文档状态
|
||||
* Dify API: PATCH /datasets/{dataset_id}/documents/status/{action}
|
||||
* action: enable / disable / archive / un_archive
|
||||
*/
|
||||
export async function action({ request, params }: ActionFunctionArgs) {
|
||||
try {
|
||||
const { getUserSession } = await import("~/api/login/auth.server");
|
||||
const { frontendJWT } = await getUserSession(request);
|
||||
|
||||
if (!frontendJWT) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'JWT认证失败,请重新登录' }),
|
||||
{ status: 401, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const { datasetId, action: statusAction } = params;
|
||||
if (!datasetId || !statusAction) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: '缺少必要参数' }),
|
||||
{ status: 400, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
// 验证action参数
|
||||
const validActions = ['enable', 'disable', 'archive', 'un_archive'];
|
||||
if (!validActions.includes(statusAction)) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: `无效的action参数,有效值: ${validActions.join(', ')}` }),
|
||||
{ status: 400, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const { document_ids } = body;
|
||||
|
||||
if (!document_ids || !Array.isArray(document_ids) || document_ids.length === 0) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: '缺少 document_ids 参数' }),
|
||||
{ status: 400, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
console.log('[API] Update Documents Status:', { datasetId, action: statusAction, document_ids });
|
||||
|
||||
// 转发请求到 FastAPI -> Dify API
|
||||
const apiUrl = `${API_BASE_URL}/dify_dataset/datasets/${datasetId}/documents/status/${statusAction}`;
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${frontendJWT}`,
|
||||
},
|
||||
body: JSON.stringify({ document_ids }),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
return new Response(JSON.stringify(data), {
|
||||
status: response.status,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('[API] Update Documents Status - Error:', error.message);
|
||||
return new Response(
|
||||
JSON.stringify({ error: error.message || 'Failed to update documents status' }),
|
||||
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
|
||||
if (keyword) queryParams.append('keyword', keyword);
|
||||
|
||||
// 转发请求到 FastAPI
|
||||
const apiUrl = `${API_BASE_URL}/dify-dataset/datasets/${datasetId}/documents?${queryParams}`;
|
||||
const apiUrl = `${API_BASE_URL}/dify_dataset/datasets/${datasetId}/documents?${queryParams}`;
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
@@ -92,8 +92,8 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
||||
|
||||
console.log('[API] Upload Document:', { datasetId });
|
||||
|
||||
// 转发请求到 FastAPI
|
||||
const apiUrl = `${API_BASE_URL}/dify-dataset/datasets/${datasetId}/documents/create-by-file`;
|
||||
// 转发请求到 FastAPI (注意:Dify API是 /document/create-by-file,document是单数)
|
||||
const apiUrl = `${API_BASE_URL}/dify_dataset/datasets/${datasetId}/document/create-by-file`;
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
import { type ActionFunctionArgs } from '@remix-run/node';
|
||||
import { API_BASE_URL } from '~/config/api-config';
|
||||
|
||||
/**
|
||||
* POST /api/dataset/datasets/:datasetId/retrieve - 检索知识库
|
||||
* Dify API: POST /datasets/{dataset_id}/retrieve
|
||||
*
|
||||
* 请求体:
|
||||
* {
|
||||
* query: string, // 检索关键词
|
||||
* retrieval_model?: {
|
||||
* search_method: 'keyword_search' | 'semantic_search' | 'full_text_search' | 'hybrid_search',
|
||||
* reranking_enable?: boolean,
|
||||
* reranking_model?: {
|
||||
* reranking_provider_name: string,
|
||||
* reranking_model_name: string
|
||||
* },
|
||||
* top_k?: number,
|
||||
* score_threshold_enabled?: boolean,
|
||||
* score_threshold?: number
|
||||
* },
|
||||
* metadata_filtering_conditions?: {
|
||||
* logical_operator: 'and' | 'or',
|
||||
* conditions: Array<{
|
||||
* name: string,
|
||||
* comparison_operator: string,
|
||||
* value?: string | number
|
||||
* }>
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
export async function action({ request, params }: ActionFunctionArgs) {
|
||||
try {
|
||||
const { getUserSession } = await import("~/api/login/auth.server");
|
||||
const { frontendJWT } = await getUserSession(request);
|
||||
|
||||
if (!frontendJWT) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'JWT认证失败,请重新登录' }),
|
||||
{ status: 401, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const { datasetId } = params;
|
||||
if (!datasetId) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: '缺少知识库ID' }),
|
||||
{ status: 400, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
if (request.method !== 'POST') {
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'Method not allowed' }),
|
||||
{ status: 405, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
console.log('[API] Retrieve Dataset:', { datasetId, query: body.query });
|
||||
|
||||
// 转发请求到 FastAPI -> Dify API
|
||||
const apiUrl = `${API_BASE_URL}/dify_dataset/datasets/${datasetId}/retrieve`;
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${frontendJWT}`,
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
return new Response(JSON.stringify(data), {
|
||||
status: response.status,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('[API] Retrieve Dataset - Error:', error.message);
|
||||
return new Response(
|
||||
JSON.stringify({ error: error.message || 'Failed to retrieve dataset' }),
|
||||
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
import { type LoaderFunctionArgs, type ActionFunctionArgs } from '@remix-run/node';
|
||||
import { API_BASE_URL } from '~/config/api-config';
|
||||
|
||||
/**
|
||||
* GET /api/dataset/datasets/:datasetId - 获取知识库详情
|
||||
* Dify API: GET /datasets/{dataset_id}
|
||||
*/
|
||||
export async function loader({ request, params }: LoaderFunctionArgs) {
|
||||
try {
|
||||
const { getUserSession } = await import("~/api/login/auth.server");
|
||||
const { frontendJWT } = await getUserSession(request);
|
||||
|
||||
if (!frontendJWT) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'JWT认证失败,请重新登录' }),
|
||||
{ status: 401, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const { datasetId } = params;
|
||||
if (!datasetId) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: '缺少 datasetId 参数' }),
|
||||
{ status: 400, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
console.log('[API] Dataset Detail:', { datasetId });
|
||||
|
||||
// 转发请求到 FastAPI -> Dify API
|
||||
const apiUrl = `${API_BASE_URL}/dify_dataset/datasets/${datasetId}`;
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${frontendJWT}`,
|
||||
},
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
return new Response(JSON.stringify(data), {
|
||||
status: response.status,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('[API] Dataset Detail - Error:', error.message);
|
||||
return new Response(
|
||||
JSON.stringify({ error: error.message || 'Failed to get dataset' }),
|
||||
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PATCH /api/dataset/datasets/:datasetId - 修改知识库名称
|
||||
*
|
||||
* Dify API: PATCH /datasets/{dataset_id}
|
||||
*
|
||||
* 请求体: { "name": "新的知识库名称" }
|
||||
*
|
||||
* 注意:
|
||||
* - 仅允许修改知识库名称,其他字段不开放修改
|
||||
* - 删除知识库功能不对外开放
|
||||
*/
|
||||
export async function action({ request, params }: ActionFunctionArgs) {
|
||||
try {
|
||||
const { getUserSession } = await import("~/api/login/auth.server");
|
||||
const { frontendJWT } = await getUserSession(request);
|
||||
|
||||
if (!frontendJWT) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'JWT认证失败,请重新登录' }),
|
||||
{ status: 401, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const { datasetId } = params;
|
||||
if (!datasetId) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: '缺少 datasetId 参数' }),
|
||||
{ status: 400, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const method = request.method;
|
||||
|
||||
if (method === 'PATCH') {
|
||||
const body = await request.json();
|
||||
|
||||
// 只允许修改 name 字段
|
||||
if (!body.name || typeof body.name !== 'string') {
|
||||
return new Response(
|
||||
JSON.stringify({ error: '请提供有效的知识库名称 (name)' }),
|
||||
{ status: 400, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
// 只传递 name 字段,忽略其他字段
|
||||
const allowedBody = { name: body.name.trim() };
|
||||
|
||||
if (allowedBody.name.length === 0) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: '知识库名称不能为空' }),
|
||||
{ status: 400, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
console.log('[API] Update Dataset Name:', { datasetId, name: allowedBody.name });
|
||||
|
||||
const apiUrl = `${API_BASE_URL}/dify_dataset/datasets/${datasetId}`;
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${frontendJWT}`,
|
||||
},
|
||||
body: JSON.stringify(allowedBody),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
return new Response(JSON.stringify(data), {
|
||||
status: response.status,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'Method not allowed' }),
|
||||
{ status: 405, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('[API] Dataset Action - Error:', error.message);
|
||||
return new Response(
|
||||
JSON.stringify({ error: error.message || 'Failed to process dataset request' }),
|
||||
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
||||
console.log('[API] Dataset List - 获取知识库列表:', { page, limit });
|
||||
|
||||
// 转发请求到 FastAPI
|
||||
const apiUrl = `${API_BASE_URL}/dify-dataset/datasets?page=${page}&limit=${limit}`;
|
||||
const apiUrl = `${API_BASE_URL}/dify_dataset/datasets?page=${page}&limit=${limit}`;
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
|
||||
@@ -43,7 +43,7 @@ export const meta: MetaFunction = () => {
|
||||
export default function ChatWithLLMIndex() {
|
||||
return (
|
||||
<div className="chat-container" style={{
|
||||
height: '93vh', // 使用视口高度的90%
|
||||
height: '90vh', // 使用视口高度的90%
|
||||
borderRadius: '0.5rem',
|
||||
marginBottom: '-20px',
|
||||
marginTop: '2vh',
|
||||
+5
-5
@@ -1,7 +1,7 @@
|
||||
import DatasetManager from "~/components/dify-dataset-manager";
|
||||
import datasetManagerStyles from "~/styles/components/dify-dataset-manager/index.css?url";
|
||||
import sidebarStyles from "~/styles/components/dify-dataset-manager/sidebar.css?url";
|
||||
import documentListStyles from "~/styles/components/dify-dataset-manager/document-list.css?url";
|
||||
// import sidebarStyles from "~/styles/components/dify-dataset-manager/sidebar.css?url";
|
||||
// import documentListStyles from "~/styles/components/dify-dataset-manager/document-list.css?url";
|
||||
|
||||
/**
|
||||
* 注册样式
|
||||
@@ -9,8 +9,8 @@ import documentListStyles from "~/styles/components/dify-dataset-manager/documen
|
||||
export function links() {
|
||||
return [
|
||||
{ rel: "stylesheet", href: datasetManagerStyles },
|
||||
{ rel: "stylesheet", href: sidebarStyles },
|
||||
{ rel: "stylesheet", href: documentListStyles },
|
||||
// { rel: "stylesheet", href: sidebarStyles },
|
||||
// { rel: "stylesheet", href: documentListStyles },
|
||||
];
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ export function links() {
|
||||
*/
|
||||
export default function DatasetManagerIndex() {
|
||||
return (
|
||||
<div className="dataset-manager-page" style={{ height: '93vh', padding: '16px' }}>
|
||||
<div className="dataset-manager-page" style={{ height: '90vh', padding: '16px' }}>
|
||||
<DatasetManager />
|
||||
</div>
|
||||
);
|
||||
@@ -1,20 +0,0 @@
|
||||
import { Outlet } from "@remix-run/react";
|
||||
import type { MetaFunction } from "@remix-run/node";
|
||||
|
||||
export const meta: MetaFunction = () => {
|
||||
return [
|
||||
{ title: "知识库管理 - 智能审核系统" },
|
||||
{ name: "description", content: "Dify 知识库文档管理" },
|
||||
];
|
||||
};
|
||||
|
||||
export const handle = {
|
||||
breadcrumb: "知识库管理",
|
||||
};
|
||||
|
||||
/**
|
||||
* 知识库管理布局路由
|
||||
*/
|
||||
export default function DatasetManagerLayout() {
|
||||
return <Outlet />;
|
||||
}
|
||||
Reference in New Issue
Block a user