🤖 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.
Python ai-agentai-assistantchatbotclaudecomputer-usedeepseekdesktop-appdshelectronfeishugeminigptgrokllmlocal-firstmodelflaremulti-modelopenai-compatiblepersonal-ai-agentwechat
Chat: drop tool-call progress messages; typing indicator is the only working signal; no WeChat quota reserve
Marladcb37843aa08
diff --git a/src/channels/feishu/card.ts b/src/channels/feishu/card.tsindex 7bdeaa1..f3a30c4 100644--- a/src/channels/feishu/card.ts+++ b/src/channels/feishu/card.ts@@ -19,7 +19,6 @@ export class FeishuReply implements ReplySession {private fallback = false;private started = false;private closed = false;- private progress: string[] = [];constructor(private transport: FeishuTransport, private replyTo: string, private throttleMs = 400) {}@@ -37,12 +36,6 @@ export class FeishuReply implements ReplySession {this.latest = op.text;this.schedule();return;- case "progress":- this.progress.push(op.text);- if (this.progress.length > 12) this.progress.splice(0, this.progress.length - 12);- this.latest = `⏳ 进行中…\n${this.progress.join("\n")}`;- this.schedule();- return;case "stream.finish":return this.finish(op.text);case "text":diff --git a/src/channels/weixin/channel.ts b/src/channels/weixin/channel.tsindex 722130b..dbb37f4 100644--- a/src/channels/weixin/channel.ts+++ b/src/channels/weixin/channel.ts@@ -53,23 +53,14 @@ export function weixinParts(items: MessageItem[] | undefined): Part[] {return parts;}-/** 进度批量发送参数(微信每次入站后 24h 内仅 10 条可发) */-export const PROGRESS_FLUSH_MS = 15_000;-export const PROGRESS_MAX_PER_TURN = 3;-/** 进度消息发送后至少保留的配额(留给最终回复与审批提示) */-export const PROGRESS_QUOTA_RESERVE = 4;-/**- * 微信回复会话:不流式;生成期间显示“正在输入”,结束时一次性发送(>4000 字切分),遵守配额。- * 代理进度按 ~15s 合并为一条,每回合最多 3 条,且始终为最终回复/审批保留配额;发完进度后恢复“正在输入”。+ * 微信回复会话:不流式;生成期间只显示“正在输入”(每 5 秒续期),结束时一次性发送最终回复(>4000 字切分),遵守配额。+ * 不发送工具调用进度;只有最终回复、审批/提问提示和交付文件会成为聊天消息,配额全部留给它们。*/export class WeixinReply implements ReplySession {private ticket: string | undefined;private typingTimer: NodeJS.Timeout | undefined;private typingOn = false;- private progressBuf: string[] = [];- private progressTimer: NodeJS.Timeout | undefined;- private progressSent = 0;private chain: Promise<void> = Promise.resolve();readonly sent: string[] = [];private log = logger("weixin.reply");@@ -79,7 +70,6 @@ export class WeixinReply implements ReplySession {private userId: string,private contextToken: string,private quota: WeixinQuota,- private progressFlushMs = PROGRESS_FLUSH_MS,) {}private enqueue(fn: () => Promise<void>): Promise<void> {@@ -92,21 +82,12 @@ export class WeixinReply implements ReplySession {switch (op.type) {case "typing":this.typingOn = op.on;- if (!op.on) this.dropProgress();return this.typing(op.on);case "stream.start":case "stream.update":return;- case "progress":- this.progressBuf.push(op.text);- this.progressTimer ??= setTimeout(() => {- this.progressTimer = undefined;- void this.enqueue(() => this.flushProgress());- }, this.progressFlushMs);- return;case "stream.finish":case "text":- this.dropProgress();return this.enqueue(() => this.send(op.text));case "file":return this.enqueue(async () => {@@ -129,13 +110,10 @@ export class WeixinReply implements ReplySession {}});case "interactive": {- if (this.progressTimer) clearTimeout(this.progressTimer);- this.progressTimer = undefined;const text = op.requestId? op.prompt // 代理请求:提示里已含编号/回复方式: `${op.prompt}${op.options?.length ? "\n" + op.options.map((o, i) => `${i + 1}. ${o}`).join("\n") + "\n(回复编号选择)" : ""}`;return this.enqueue(async () => {- await this.flushProgress();await this.send(text, { raw: !!op.requestId });if (this.typingOn) await this.typing(true);});@@ -143,24 +121,6 @@ export class WeixinReply implements ReplySession {}}- private dropProgress(): void {- if (this.progressTimer) clearTimeout(this.progressTimer);- this.progressTimer = undefined;- this.progressBuf = [];- }-- private async flushProgress(): Promise<void> {- if (!this.progressBuf.length) return;- const lines = this.progressBuf;- this.progressBuf = [];- if (this.progressSent >= PROGRESS_MAX_PER_TURN) return;- if (this.quota.remaining(this.userId) <= PROGRESS_QUOTA_RESERVE) return;- const shown = lines.length > 8 ? [...lines.slice(0, 3), `…(另 ${lines.length - 6} 步)`, ...lines.slice(-3)] : lines;- this.progressSent++;- await this.send(`⏳ 进行中:\n${shown.join("\n")}`, { raw: true, maxChunks: 1 });- if (this.typingOn) await this.typing(true);- }-private async typing(on: boolean): Promise<void> {try {if (on) {diff --git a/src/core/runtime.ts b/src/core/runtime.tsindex 6d81886..da81c8b 100644--- a/src/core/runtime.ts+++ b/src/core/runtime.ts@@ -148,9 +148,9 @@ export class BotRuntime {text: input,model,observer: {- onProgress: (t) => {+ // 工具调用不进入聊天:只用于判断代理已开始工作(不再回退到纯对话),正在输入状态由渠道维持+ onProgress: () => {visible = true;- void out.apply({ type: "progress", text: t });},},});diff --git a/src/core/types.ts b/src/core/types.tsindex 2c948b9..5761cc6 100644--- a/src/core/types.ts+++ b/src/core/types.ts@@ -30,8 +30,6 @@ export type OutboundOp =| { type: "stream.update"; text: string }| { type: "stream.finish"; text: string }| { type: "text"; text: string }- /** 代理执行中的进度(工具调用等):微信批量发送并受配额约束,飞书写入卡片,网页收集 */- | { type: "progress"; text: string }/** 代理交付的本地文件(present):微信走 CDN 媒体消息,飞书上传文件/图片,网页列出文件名 */| { type: "file"; path: string; name: string }/**diff --git a/src/web/server.ts b/src/web/server.tsindex ea6e4a8..bde261b 100644--- a/src/web/server.ts+++ b/src/web/server.ts@@ -90,13 +90,11 @@ function publicBot(b: NonNullable<ReturnType<App["store"]["getBot"]>>) {/** 网页“测试对话”渠道:收集输出 */class CollectReply implements ReplySession {text = "";- progress: string[] = [];prompts: Array<{ kind: string; prompt: string; requestId?: string; code?: string }> = [];files: string[] = [];async apply(op: OutboundOp): Promise<void> {if (op.type === "file") this.files.push(op.name);if (op.type === "stream.finish" || op.type === "text") this.text += (this.text ? "\n" : "") + op.text;- else if (op.type === "progress") this.progress.push(op.text);else if (op.type === "interactive") this.prompts.push({ kind: op.kind, prompt: op.prompt, requestId: op.requestId, code: op.code });}}@@ -334,10 +332,10 @@ export async function startWebServer(app: App, opts: { port?: number; host?: strreceivedAt: Date.now(),};const intercepted = app.runtime.interceptReply(ev);- if (intercepted.handled) return send(res, 200, { reply: intercepted.ack ?? "", progress: [], prompts: [] });+ if (intercepted.handled) return send(res, 200, { reply: intercepted.ack ?? "", prompts: [] });const out = new CollectReply();await app.queue.run(`web:${id}:console`, () => app.runtime.handle(ev, out));- return send(res, 200, { reply: out.text, progress: out.progress, prompts: out.prompts, files: out.files });+ return send(res, 200, { reply: out.text, prompts: out.prompts, files: out.files });}}throw new HttpError(404, "not found");diff --git a/test/agent.integration.test.ts b/test/agent.integration.test.tsindex ea44f09..c54dbf7 100644--- a/test/agent.integration.test.ts+++ b/test/agent.integration.test.ts@@ -105,7 +105,7 @@ describe.skipIf(!runtime || !hasBwrap || process.platform !== "linux")("agent hoconst chat = async (text: string) => {const r = await fetch(`${base}/amb/api/bots/default/chat`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ text }) });expect(r.status).toBe(200);- return (await r.json()) as { reply: string; progress: string[]; prompts: any[]; files?: string[] };+ return (await r.json()) as { reply: string; progress?: string[]; prompts: any[]; files?: string[] };};it("runs a sandboxed bash tool in the bot workspace (quicksort)", async () => {@@ -114,6 +114,13 @@ describe.skipIf(!runtime || !hasBwrap || process.platform !== "linux")("agent hoexpect(fs.existsSync(path.join(dataDir, "workspaces", "default", "qs.py"))).toBe(true);// 模型只看到真实上游密钥,子进程只拿到 bridge 令牌expect([...seenAuth]).toEqual(["Bearer gw-key"]);+ // 工具调用不进入聊天:响应与会话历史里只有用户消息和最终回复+ expect(r.progress).toBeUndefined();+ const convs = ((await (await fetch(`${base}/amb/api/conversations?bot=default`)).json()) as any).conversations;+ const conv = convs.find((c: any) => String(c.id).includes("web"));+ const hist = ((await (await fetch(`${base}/amb/api/conversations/${encodeURIComponent(conv.id)}/messages`)).json()) as any).messages;+ expect(hist.map((m: any) => m.role)).toEqual(["user", "assistant"]);+ expect(JSON.stringify(hist)).not.toMatch(/🔧|tool|bash:/);}, 120_000);it("escalation waits for approval; approve via API allows once", async () => {diff --git a/test/agent.unit.test.ts b/test/agent.unit.test.tsindex b1b7d80..276f942 100644--- a/test/agent.unit.test.ts+++ b/test/agent.unit.test.ts@@ -93,46 +93,45 @@ describe("parseAnswer", () => {});});-describe("WeixinReply progress batching", () => {+describe("WeixinReply: only final reply / prompts / files become messages", () => {function setup(remaining = 10) {store.upsertWeixinPeer({ botId: "b", userId: "u1", contextToken: "ctx", quotaRemaining: remaining, windowStartedAt: Date.now() });const sent: string[] = [];+ const typing: boolean[] = [];const client = {sendText: async (_u: string, t: string) => void sent.push(t),getTypingTicket: async () => "ticket",- sendTyping: async () => {},+ sendTyping: async (_u: string, _t: string, on: boolean) => void typing.push(on),} as any;- return { sent, reply: new WeixinReply(client, "u1", "ctx", new WeixinQuota(store, "b"), 30) };+ return { sent, typing, reply: new WeixinReply(client, "u1", "ctx", new WeixinQuota(store, "b")) };}const tick = (ms: number) => new Promise((r) => setTimeout(r, ms));- it("batches progress lines into one message per flush, max 3 per turn", async () => {- const { sent, reply } = setup();- for (let round = 0; round < 5; round++) {- await reply.apply({ type: "progress", text: `🔧 step ${round}a` });- await reply.apply({ type: "progress", text: `🔧 step ${round}b` });- await tick(60);- }- expect(sent.length).toBe(3);- expect(sent[0]).toBe("⏳ 进行中:\n🔧 step 0a\n🔧 step 0b");+ it("uses the typing indicator as the only working signal and sends just the final reply", async () => {+ const { sent, typing, reply } = setup();+ await reply.apply({ type: "typing", on: true });+ await reply.apply({ type: "stream.start" });await reply.apply({ type: "stream.finish", text: "完成" });+ await reply.apply({ type: "typing", on: false });await tick(10);- expect(sent.at(-1)).toBe("完成");+ expect(sent).toEqual(["完成"]);+ expect(typing).toEqual([true, false]);});- it("keeps a quota reserve and drops pending progress when the final reply arrives", async () => {- const low = setup(4);- await low.reply.apply({ type: "progress", text: "🔧 x" });- await tick(60);- expect(low.sent).toEqual([]);+ it("no quota is reserved: the last remaining message goes to the reply", async () => {+ const low = setup(1);+ await low.reply.apply({ type: "stream.finish", text: "最终答案" });+ expect(low.sent).toEqual(["最终答案"]);});- it("sends approval prompts raw (backticks intact) and flushes progress first", async () => {- const { sent, reply } = setup();- await reply.apply({ type: "progress", text: "🔧 bash ls" });- await reply.apply({ type: "interactive", kind: "confirm", prompt: "需批准: bash `rm -rf build` — 回复 y 1234 / n 1234", requestId: "r1", code: "1234" } as any);+ it("sends approval prompts raw (backticks intact) and resumes typing", async () => {+ const { sent, typing, reply } = setup();+ await reply.apply({ type: "typing", on: true });+ await reply.apply({ type: "interactive", kind: "approval", prompt: "需批准: bash `rm -rf build` — 回复 y 1234 / n 1234", requestId: "r1", code: "1234" });await tick(10);- expect(sent).toEqual(["⏳ 进行中:\n🔧 bash ls", "需批准: bash `rm -rf build` — 回复 y 1234 / n 1234"]);+ expect(sent).toEqual(["需批准: bash `rm -rf build` — 回复 y 1234 / n 1234"]);+ expect(typing.filter(Boolean).length).toBe(2);+ await reply.apply({ type: "typing", on: false });});});@@ -184,7 +183,7 @@ describe("WeChat media delivery", () => {},} as any;const quota = new WeixinQuota(store, "b");- const reply = new WeixinReply(client, "u1", "ctx", quota, 30);+ const reply = new WeixinReply(client, "u1", "ctx", quota);await reply.apply({ type: "file", path: "/w/a.png", name: "a.png" });expect(sent).toEqual(["media:/w/a.png"]);expect(quota.remaining("u1")).toBe(1);diff --git a/ui/app.js b/ui/app.jsindex 22508c2..b2c445b 100644--- a/ui/app.js+++ b/ui/app.js@@ -100,7 +100,7 @@ function TestChat({ botId }) {setText(""); setBusy(true); setLog((l) => [...l, { role: "user", content: t }]);try {const r = await api(`/bots/${botId}/chat`, { method: "POST", body: { text: t } });- const extra = [...(r.progress || []).map((p) => ({ role: "assistant progress", content: "⏳ " + p })), ...(r.prompts || []).map((p) => ({ role: "assistant prompt", content: p.prompt }))];+ const extra = [...(r.prompts || []).map((p) => ({ role: "assistant prompt", content: p.prompt }))];const files = (r.files || []).map((f) => ({ role: "assistant progress", content: "📎 已交付文件:" + f + "(微信/飞书会直接发送;网页端请在机器人工作区查看)" }));setLog((l) => [...l, ...extra, { role: "assistant", content: r.reply }, ...files]);}