forked from EduCraft/curriculum-project-hub
fix: repair streaming output broken by markdown rendering changes
Two bugs were introduced when sendTextMessage was changed to auto-detect message format (text/post/interactive): 1. Message type mismatch: sendTextMessage could create a text or post message, but patchTextMessage only works on interactive cards. Fix: add sendInteractiveCardMessage for streaming create (always interactive, always patchable). 2. flushTextToSink state corruption: the text management after flush had a flawed appendedDuringFlush heuristic that could lose text or duplicate it. Fix: properly track sent vs unsent text by removing the sent prefix length, keeping only the last chunk for future patches. Also fix finish() to flush pending text regardless of currentMessageId.
This commit is contained in:
@@ -234,6 +234,24 @@ export async function sendText(rt: FeishuRuntime, chatId: string, text: string):
|
||||
await sendTextMessage(rt, chatId, text);
|
||||
}
|
||||
|
||||
/** Send an interactive card message (always patchable). Used for streaming. */
|
||||
export async function sendInteractiveCardMessage(rt: FeishuRuntime, chatId: string, text: string): Promise<string | null> {
|
||||
const payload = buildOutboundPayload(text);
|
||||
const card = buildInteractiveCardFromOutboundPayload(payload);
|
||||
const client = rt.client as unknown as {
|
||||
im: { v1: { message: { create: (p: unknown) => Promise<MessageCreateResponse> } } };
|
||||
};
|
||||
try {
|
||||
const res = await client.im.v1.message.create({
|
||||
params: { receive_id_type: "chat_id" },
|
||||
data: { receive_id: chatId, msg_type: "interactive", content: JSON.stringify(card) },
|
||||
});
|
||||
return messageIdFromResponse(res);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Patch a text-as-card message in-place (streaming updates). */
|
||||
export async function patchTextMessage(rt: FeishuRuntime, messageId: string, text: string): Promise<void> {
|
||||
const payload = buildOutboundPayload(text);
|
||||
|
||||
Reference in New Issue
Block a user