From 9ad61eef3b7957ba0a91feea1f5ae0c5072da82c Mon Sep 17 00:00:00 2001 From: Cheney Date: Sun, 16 Aug 2026 22:10:00 +0800 Subject: [PATCH] retry --- server.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server.ts b/server.ts index 5064b62..ae6cf31 100644 --- a/server.ts +++ b/server.ts @@ -70,6 +70,7 @@ async function log(level: string, category: string, data: any) { try { if (!existsSync(LOG_DIR)) await mkdir(LOG_DIR, { recursive: true }); await appendFile(`${LOG_DIR}/chat-${ts.slice(0, 10)}.log`, line, "utf-8"); + await appendFile(`${LOG_DIR}/global.log`, line, "utf-8"); } catch { /* 忽略日志写入失败 */ } @@ -457,8 +458,9 @@ async function runConversation(initialMessages: ChatMsg[], res: any, fromApprova messages: messages.map((m) => ({ role: m.role, content: clip(m.content, 800) })), }); - // 工具循环(最多 5 轮避免死循环) - for (let round = 0; round < 5; round++) { + // 工具循环(最多 10 轮避免死循环) + for (let round = 0; round < 10; round++) { + log("debug", "round_start", { round: round + 1, pendingMessages: messages.length }); const gen = streamLLM(messages); let content = ""; let toolCall: any = null; @@ -475,6 +477,7 @@ async function runConversation(initialMessages: ChatMsg[], res: any, fromApprova sseSend(res, { type: "token", content: "\n\n⚠️ " + ev.content }); } } + log("debug", "assistant_round", { round: round + 1, content: clip(content, 1000), wantsTool: !!toolCall }); if (errored) { sseSend(res, { type: "done" }); res.end(); return; } @@ -526,6 +529,7 @@ async function runConversation(initialMessages: ChatMsg[], res: any, fromApprova return; } + log("warn", "round_limit", { round: 10 }); sseSend(res, { type: "token", content: "\n[达到最大工具调用轮数]" }); sseSend(res, { type: "done" }); res.end();