Skip to content

🤖 Open-source, local-first alternative to Grok Bot, OpenAI dots and Claude Duet. Your own AI bots on any model: GPT, Claude, Gemini, Grok, DeepSeek, Kimi, GLM and 70+ more through one Modelflare key. Reach them in the app, WeChat or Feishu; they remember you, work in the background, run commands and use your computer. Pay per use.

Merge pull request #16 from modelflare-ai/fix/bughunt-2-3-4-9

marla-modelflarececc03164a5c
diff --cc src/agent/bridge.ts
index e2a99ba,a7f1932..19c65df
--- a/src/agent/bridge.ts
+++ b/src/agent/bridge.ts
@@@ -214,13 -182,26 +216,31 @@@ export class AgentBridge
else return void res.writeHead(404).end();
res.writeHead(200, { "content-type": "application/json" }).end(JSON.stringify(out));
}
+
+ /**
+ * 可能要十几分钟的调用(生视频):先回响应头,每分钟写一个空格,做完再写 JSON(前导空白不影响解析)。
+ * 子进程里的 fetch 等响应头、等下一段数据都只等 5 分钟,超时工具就失败了,生成却还在继续、照样扣费。
+ */
+ private async longCall(res: http.ServerResponse, p: Promise<unknown>): Promise<void> {
+ res.writeHead(200, { "content-type": "application/json" });
+ res.flushHeaders();
+ const keep = setInterval(() => {
+ if (!res.writableEnded && !res.destroyed) res.write(" ");
+ }, KEEPALIVE_MS);
+ res.on("close", () => clearInterval(keep));
+ try {
+ res.end(JSON.stringify(await p.catch((e: Error) => ({ error: e.message }))));
+ } finally {
+ clearInterval(keep);
+ }
+ }
}
+/** 模型请求的路径:Chat Completions、Responses、Anthropic Messages(代理按模型选其一) */
+export function isModelPath(p: string): boolean {
+ return /\/v1\/(chat\/completions|responses|messages)$/.test(p);
+}
+
/** 请求体里的模型名、工具名与第一条用户消息开头(只在有人订阅时解析;解析失败就不给) */
function requestInfo(body: Buffer | undefined): { model?: string; tools?: string[]; lastUser?: string } {
if (!body || body.length > 8 * 1024 * 1024) return {};
diff --cc src/agent/manager.ts
index 87307e2,0b81175..2d30eef
--- a/src/agent/manager.ts
+++ b/src/agent/manager.ts
@@@ -141,9 -150,11 +156,13 @@@ export class AgentManager
onNotice: this.o.onNotice,
media: !!this.o.media,
contextWindow: this.o.contextWindow,
+ apiInfo: this.o.apiInfo,
+ apiFallbacks: this.apiFallbacks,
});
+ // 代理进程退出(/stop、看门狗、换模型或设置、崩溃、重启、停止):进程里的压缩跟着没了,不再等它
+ h.on((e) => {
+ if (e.type === "exit") this.endCompaction((c) => c.botId === botId);
+ });
this.hosts.set(botId, h);
}
return h;