Show IM channel source on threads

This commit is contained in:
taohe
2026-06-11 16:51:04 +08:00
parent 42fd0cc22f
commit 4f56437030
9 changed files with 303 additions and 26 deletions
+38 -1
View File
@@ -1,6 +1,6 @@
import { expect, test } from "vitest";
import { pathOfThread } from "@/core/threads/utils";
import { channelSourceOfThread, pathOfThread } from "@/core/threads/utils";
test("uses standard chat route when thread has no agent context", () => {
expect(pathOfThread("thread-123")).toBe("/workspace/chats/thread-123");
@@ -44,3 +44,40 @@ test("prefers context.agent_name over metadata.agent_name", () => {
}),
).toBe("/workspace/agents/from-context/chats/thread-789");
});
test("reads IM channel source metadata", () => {
expect(
channelSourceOfThread({
metadata: {
channel_source: {
type: "im_channel",
provider: "feishu",
chat_id: "oc_123",
},
},
}),
).toEqual({
type: "im_channel",
provider: "feishu",
label: "Feishu",
});
});
test("ignores threads without valid IM channel source metadata", () => {
expect(channelSourceOfThread({ metadata: {} })).toBeNull();
expect(
channelSourceOfThread({
metadata: { channel_source: { provider: "" } },
}),
).toBeNull();
expect(
channelSourceOfThread({
metadata: {
channel_source: {
type: "other",
provider: "feishu",
},
},
}),
).toBeNull();
});