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 origin/master into feat/feishu-catchup

Marla74bb5791d3ff
diff --cc src/channels/feishu/transport.ts
index cf3c6a5,d507949..f9b67c9
--- a/src/channels/feishu/transport.ts
+++ b/src/channels/feishu/transport.ts
@@@ -21,32 -21,29 +21,53 @@@ export interface FeishuMessageEvent
senderOpenId: string;
mentions: Array<{ key: string; name?: string; openId?: string }>;
createTime: number;
+ /** 回复(或话题里的消息):回复链的根消息、直接回复的那条(message_id);不是回复时没有 */
+ rootId?: string;
+ parentId?: string;
+ }
+
+ /** im.message.receive_v1 的事件 → FeishuMessageEvent */
+ export function messageEventOf(data: any): FeishuMessageEvent {
+ const m = data?.message ?? {};
+ return {
+ eventId: data?.event_id,
+ messageId: m.message_id,
+ chatId: m.chat_id,
+ chatType: m.chat_type,
+ messageType: m.message_type,
+ content: m.content ?? "{}",
+ senderOpenId: data?.sender?.sender_id?.open_id ?? "",
+ mentions: (m.mentions ?? []).map((x: any) => ({ key: x.key, name: x.name, openId: x.id?.open_id })),
+ createTime: Number(m.create_time ?? Date.now()),
+ ...(m.root_id ? { rootId: String(m.root_id) } : {}),
+ ...(m.parent_id ? { parentId: String(m.parent_id) } : {}),
+ };
}
+/** 读不了会话的历史消息(应用没开 im:message.history:readonly 这类权限、机器人不在群里、用户不在可用范围):离线补消息做不了 */
+export class HistoryDenied extends Error {}
+
+/** 飞书说的「没权限」:HTTP 403,缺权限范围(99991672 / 99991679)、缺必要权限(230027)、不在群里(230002)、不在可用范围(230013) */
+export function historyDenied(status: number | undefined, code: number | undefined, msg = ""): boolean {
+ if (status === 403) return true;
+ if (code !== undefined && [99991672, 99991679, 230027, 230002, 230013].includes(code)) return true;
+ return /scope|permission|access denied|权限/i.test(msg);
+}
+
+/** 会话历史里的一条(im.v1.message.list 的 item)→ FeishuMessageEvent;chatType 由调用方给(列表里没有) */
+export function historyEvent(m: any, chatType: string): FeishuMessageEvent {
+ return {
+ messageId: String(m?.message_id ?? ""),
+ chatId: String(m?.chat_id ?? ""),
+ chatType,
+ messageType: String(m?.msg_type ?? ""),
+ content: m?.body?.content ?? "{}",
+ senderOpenId: m?.sender?.id_type === "open_id" ? String(m.sender.id ?? "") : "",
+ mentions: (m?.mentions ?? []).map((x: any) => ({ key: x.key, name: x.name, openId: x.id_type === "open_id" ? x.id : undefined })),
+ createTime: Number(m?.create_time ?? 0),
+ };
+}
+
/**
* 飞书传输层抽象(便于离线测试用 mock 替换)。
* 真实实现:WSClient 长连接接收事件 + OpenAPI(CardKit 流式卡片 / 文本回复)。
diff --cc test/helpers.ts
index 2297dd2,ec60fe3..dba0900
--- a/test/helpers.ts
+++ b/test/helpers.ts
@@@ -290,7 -270,9 +290,9 @@@ export function feishuEvent(text: strin
content: opts.content ?? JSON.stringify({ text }),
senderOpenId: opts.senderOpenId ?? "ou_user1",
mentions: opts.mentions ?? [],
- createTime: Date.now(),
+ createTime: opts.createTime ?? Date.now(),
+ ...(opts.rootId ? { rootId: opts.rootId } : {}),
+ ...(opts.parentId ? { parentId: opts.parentId } : {}),
};
}