51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
// app/static/js/api.js
|
|
|
|
const API_BASE = '/api';
|
|
|
|
const api = {
|
|
// 创建研究
|
|
createResearch: async (question) => {
|
|
const response = await fetch(`${API_BASE}/research`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
question: question,
|
|
auto_start: true
|
|
})
|
|
});
|
|
return response.json();
|
|
},
|
|
|
|
// 获取会话列表
|
|
getSessions: async (limit = 20, offset = 0) => {
|
|
const response = await fetch(`${API_BASE}/research/sessions?limit=${limit}&offset=${offset}`);
|
|
return response.json();
|
|
},
|
|
|
|
// 获取会话状态
|
|
getSessionStatus: async (sessionId) => {
|
|
const response = await fetch(`${API_BASE}/research/${sessionId}/status`);
|
|
return response.json();
|
|
},
|
|
|
|
// 获取研究大纲
|
|
getOutline: async (sessionId) => {
|
|
const response = await fetch(`${API_BASE}/research/${sessionId}/outline`);
|
|
return response.json();
|
|
},
|
|
|
|
// 取消研究
|
|
cancelResearch: async (sessionId) => {
|
|
const response = await fetch(`${API_BASE}/research/${sessionId}/cancel`, {
|
|
method: 'POST'
|
|
});
|
|
return response.json();
|
|
},
|
|
|
|
// 下载报告
|
|
downloadReport: async (sessionId) => {
|
|
window.open(`${API_BASE}/research/${sessionId}/report?format=markdown`, '_blank');
|
|
}
|
|
}; |