fix: let agents download Feishu message resources

This commit is contained in:
2026-07-10 12:17:07 +08:00
parent 4ca4afb141
commit 1094ebd651
9 changed files with 332 additions and 27 deletions
+56 -1
View File
@@ -1,4 +1,4 @@
import { mkdtemp, rm } from "node:fs/promises";
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { describe, it, expect, beforeEach, afterEach, afterAll, vi } from "vitest";
@@ -153,6 +153,61 @@ describe("trigger full lifecycle (integration)", () => {
expect(run.costSource).toBe("provider_reported");
});
it("includes downloaded post image paths in the agent prompt", async () => {
const workspaceDir = await tempWorkspaceRoot();
await seedProject("proj-post-image", "chat-post-image");
await prisma.project.update({
where: { id: "proj-post-image" },
data: { workspaceDir },
});
let downloadedPath: string | undefined;
const messageResourceGet = vi.fn(async () => ({
writeFile: async (filePath: string) => {
downloadedPath = filePath;
await writeFile(filePath, "image bytes");
},
}));
const imV1 = (rt.client as unknown as {
im: { v1: { messageResource?: { get: typeof messageResourceGet } } };
}).im.v1;
imV1.messageResource = { get: messageResourceGet };
const baseEvent = makeEvent("chat-post-image", "@_user_1 看看这张图");
const event: MessageReceiveEvent = {
...baseEvent,
message: {
...baseEvent.message,
message_type: "post",
content: JSON.stringify({
zh_cn: {
content: [[
{ tag: "text", text: "@_user_1 看看这张图" },
{ tag: "img", image_key: "img-key-1" },
]],
},
}),
},
};
const trigger = makeTriggerHandler({
prisma,
settings,
logger: silentLogger,
runAgent,
messageBatcherOptions: { maxMessages: 1 },
});
await trigger(event, rt);
await vi.waitFor(() => {
expect(runAgentCalls).toHaveLength(1);
});
expect(downloadedPath).toBeDefined();
expect(runAgentCalls[0]?.prompt).toContain(downloadedPath);
expect(messageResourceGet).toHaveBeenCalledWith({
params: { type: "image" },
path: { message_id: event.message.message_id, file_key: "img-key-1" },
});
});
it("sends an onboarding card when an unbound chat mentions the bot", async () => {
await seedOnboardingUser("u-onboard-card", "ou_onboard_card", "MEMBER");
const trigger = makeTriggerHandler({