feat: 来对话列表的处理

This commit is contained in:
2025-07-29 20:21:43 +08:00
parent 0efc7fe6a0
commit 87a302b799
4 changed files with 45 additions and 13 deletions

View File

@@ -12,6 +12,7 @@ const API = '/agent/assistant/chat';
function agentChatStream(params, onChunk) {
return new Promise((resolve, reject) => {
const token = uni.getStorageSync('token');
let hasError = false;
console.log("发送请求内容: ", params)
// #ifdef MP-WEIXIN
@@ -34,7 +35,7 @@ function agentChatStream(params, onChunk) {
reject(err);
},
complete(res) {
if(res.statusCode === 500) {
if(res.statusCode !== 200) {
console.log("====> ", JSON.stringify(res))
if (onChunk) {
@@ -47,9 +48,18 @@ function agentChatStream(params, onChunk) {
requestTask.onHeadersReceived(res => {
console.log('onHeadersReceived', res);
const status = res.statusCode || (res.header && res.header.statusCode);
if (status && status !== 200) {
hasError = true;
if (onChunk) {
onChunk({ error: true, message: `服务器错误(${status})`, detail: res });
}
requestTask.abort && requestTask.abort();
}
});
requestTask.onChunkReceived(res => {
if (hasError) return;
const base64 = uni.arrayBufferToBase64(res.data);
let data = '';
try {