Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(wecom): report attachment delivery failures
davidb7f2ca0a6fe3
diff --git a/packages/lizi-im/src/wecom/__tests__/index.test.ts b/packages/lizi-im/src/wecom/__tests__/index.test.tsindex 84937f1e9c..f94e3d1a2a 100644--- a/packages/lizi-im/src/wecom/__tests__/index.test.ts+++ b/packages/lizi-im/src/wecom/__tests__/index.test.ts@@ -374,6 +374,34 @@ describe("WecomIM routing and ownership", () => {});});+ it("notifies the recipient when a terminal attachment fails to send", async () => {+ const { host, secrets } = createHost();+ secrets.set("wecom-owner-user-id", "owner");+ const client = new FakeClient();+ const im = new WecomIM(host, { clientFactory: () => client as never });+ vi.spyOn(im, "sendFile").mockResolvedValue({+ ok: false,+ reason: "UPLOAD_FAIL",+ });++ await im.init();+ await im.commitFinal({+ userId: "owner",+ text: "done",+ terminal: "done",+ mediaAbsPaths: ["missing"],+ });++ expect(client.sendMessage).toHaveBeenNthCalledWith(1, "owner", {+ msgtype: "markdown",+ markdown: { content: "done" },+ });+ expect(client.sendMessage).toHaveBeenNthCalledWith(2, "owner", {+ msgtype: "markdown",+ markdown: { content: "⚠️ 有 1 个附件发送失败,请稍后重试。" },+ });+ });+it("deduplicates repeated callback message ids", async () => {const { host, secrets } = createHost();secrets.set("wecom-owner-user-id", "owner");diff --git a/packages/lizi-im/src/wecom/index.ts b/packages/lizi-im/src/wecom/index.tsindex 4e494e1671..73d323d76a 100644--- a/packages/lizi-im/src/wecom/index.ts+++ b/packages/lizi-im/src/wecom/index.ts@@ -398,6 +398,7 @@ export class WecomIM extends BaseIM implements TextChannelIM {visibleText || (attachments.length > 0 ? "📎 附件如下" : "_(空回复)_"),);await this.sendFinalChunks(output.userId, chunks);+ let failedAttachmentCount = 0;for (const attachment of attachments.slice(0, MAX_TERMINAL_ATTACHMENTS)) {const result = await this.sendFile(output.userId,@@ -405,11 +406,25 @@ export class WecomIM extends BaseIM implements TextChannelIM {attachment.displayName,);if (!result.ok) {+ failedAttachmentCount += 1;this.log.warn("failed to send terminal attachment", {reason: result.reason,});}}+ if (failedAttachmentCount > 0) {+ try {+ await this.sendMarkdownText(+ output.userId,+ `⚠️ 有 ${failedAttachmentCount} 个附件发送失败,请稍后重试。`,+ );+ } catch (error) {+ this.log.warn(+ "failed to report terminal attachment delivery failure",+ safeError(error),+ );+ }+ }}private connect(botId: string, secret: string): void {