(convId: string, refreshToken: string, assistantId = DEFAULT_ASSISTANT_ID)
| 292 | } |
| 293 | |
| 294 | async function removeConversation(convId: string, refreshToken: string, assistantId = DEFAULT_ASSISTANT_ID) { |
| 295 | const token = await acquireToken(refreshToken); |
| 296 | const sign = await generateSign(); |
| 297 | const controller = new AbortController(); |
| 298 | const timeoutId = setTimeout(() => controller.abort(), 15000); |
| 299 | try { |
| 300 | const response = await fetch("https://chatglm.cn/chatglm/backend-api/assistant/conversation/delete", { |
| 301 | method: "POST", |
| 302 | headers: { |
| 303 | Authorization: `Bearer ${token}`, |
| 304 | Referer: "https://chatglm.cn/main/alltoolsdetail", |
| 305 | "X-Device-Id": uuid(false), |
| 306 | "X-Request-Id": uuid(false), |
| 307 | "X-Sign": sign.sign, |
| 308 | "X-Timestamp": sign.timestamp, |
| 309 | "X-Nonce": sign.nonce, |
| 310 | ...getHeaders(), |
| 311 | }, |
| 312 | body: JSON.stringify({ assistant_id: assistantId, conversation_id: convId }), |
| 313 | signal: controller.signal, |
| 314 | }); |
| 315 | await checkResult(response, refreshToken); |
| 316 | } catch {} |
| 317 | finally { clearTimeout(timeoutId); } |
| 318 | } |
| 319 | |
| 320 | async function checkResult(response: Response, refreshToken: string): Promise<any> { |
| 321 | const data: any = await response.json().catch(() => null); |
no test coverage detected