forked from EduCraft/curriculum-project-hub
fix(hub): 保留飞书回复上下文
This commit is contained in:
@@ -63,6 +63,21 @@ export interface MockFeishuRuntime extends FeishuRuntime {
|
||||
readonly sentCards: unknown[];
|
||||
readonly sentPatches: unknown[];
|
||||
readonly reactions: Array<{ readonly messageId: string; readonly emoji: string }>;
|
||||
readonly readableMessages: Map<string, MockFeishuMessage>;
|
||||
readonly threadMessages: Map<string, readonly MockFeishuMessage[]>;
|
||||
}
|
||||
|
||||
export interface MockFeishuMessage {
|
||||
readonly message_id?: string;
|
||||
readonly root_id?: string;
|
||||
readonly parent_id?: string;
|
||||
readonly thread_id?: string;
|
||||
readonly msg_type?: string;
|
||||
readonly create_time?: string;
|
||||
readonly chat_id?: string;
|
||||
readonly sender?: { readonly id?: string; readonly sender_type?: string };
|
||||
readonly body?: { readonly content?: string };
|
||||
readonly content?: string;
|
||||
}
|
||||
|
||||
export function mockFeishuRuntime(): MockFeishuRuntime {
|
||||
@@ -70,6 +85,8 @@ export function mockFeishuRuntime(): MockFeishuRuntime {
|
||||
const sentCards: unknown[] = [];
|
||||
const sentPatches: unknown[] = [];
|
||||
const reactions: Array<{ messageId: string; emoji: string }> = [];
|
||||
const readableMessages = new Map<string, MockFeishuMessage>();
|
||||
const threadMessages = new Map<string, readonly MockFeishuMessage[]>();
|
||||
// Mock the client — sendText/sendCard are in client.ts, not on the runtime
|
||||
// object directly. We patch by providing a runtime whose client is a stub;
|
||||
// the actual send functions cast through shape, so a minimal stub works.
|
||||
@@ -114,6 +131,20 @@ export function mockFeishuRuntime(): MockFeishuRuntime {
|
||||
if (text !== null) sentTexts.push(text);
|
||||
return {};
|
||||
},
|
||||
get: async (p: unknown) => {
|
||||
const payload = p as { path?: { message_id?: string } };
|
||||
const messageId = payload.path?.message_id ?? "";
|
||||
const message = readableMessages.get(messageId);
|
||||
return { data: { items: message === undefined ? [] : [message] } };
|
||||
},
|
||||
list: async (p: unknown) => {
|
||||
const payload = p as { params?: { container_id?: string } };
|
||||
const containerId = payload.params?.container_id ?? "";
|
||||
const items =
|
||||
threadMessages.get(containerId) ??
|
||||
[...readableMessages.values()].filter((message) => message.parent_id === containerId);
|
||||
return { data: { items } };
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -123,6 +154,8 @@ export function mockFeishuRuntime(): MockFeishuRuntime {
|
||||
sentCards,
|
||||
sentPatches,
|
||||
reactions,
|
||||
readableMessages,
|
||||
threadMessages,
|
||||
};
|
||||
return rt;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user