@milerliu/feishu 0.1.5 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/reply-dispatcher.ts +2 -2
- package/src/send.ts +19 -40
package/package.json
CHANGED
package/src/reply-dispatcher.ts
CHANGED
|
@@ -118,8 +118,8 @@ export function createFeishuReplyDispatcher(params: CreateFeishuReplyDispatcherP
|
|
|
118
118
|
// Only include @mentions in the first chunk (avoid duplicate @s)
|
|
119
119
|
let isFirstChunk = true;
|
|
120
120
|
|
|
121
|
-
// Streaming mode: use streaming card for
|
|
122
|
-
if (streamingEnabled
|
|
121
|
+
// Streaming mode: use streaming card for all messages (regardless of content type)
|
|
122
|
+
if (streamingEnabled) {
|
|
123
123
|
params.runtime.log?.(`feishu deliver: using streaming mode for text (${text.length} chars)`);
|
|
124
124
|
await sendStreamingMessageFeishu({
|
|
125
125
|
cfg,
|
package/src/send.ts
CHANGED
|
@@ -91,70 +91,49 @@ export async function sendStreamingMessageFeishu(params: {
|
|
|
91
91
|
|
|
92
92
|
const messageId = response.data?.message_id ?? "unknown";
|
|
93
93
|
|
|
94
|
-
// Extract card_id from response
|
|
94
|
+
// Extract card_id from response
|
|
95
95
|
const cardData = response.data as Record<string, unknown> | undefined;
|
|
96
96
|
const cardId = cardData?.card_id as string | undefined;
|
|
97
97
|
|
|
98
98
|
if (!cardId) {
|
|
99
99
|
console.warn('No card_id returned, falling back to regular card send');
|
|
100
|
-
// Fallback: send as regular card if no card_id
|
|
101
100
|
const fallbackCard = buildMarkdownCard(messageText);
|
|
102
101
|
return sendCardFeishu({ cfg, to, card: fallbackCard });
|
|
103
102
|
}
|
|
104
103
|
|
|
105
|
-
// Stream
|
|
106
|
-
|
|
107
|
-
const chunkSize = 300; // Smaller chunks for smoother streaming
|
|
104
|
+
// Stream content updates using Feishu cardkit batch_update API
|
|
105
|
+
const chunkSize = 300;
|
|
108
106
|
const chunks: string[] = [];
|
|
109
|
-
|
|
110
107
|
for (let i = 0; i < messageText.length; i += chunkSize) {
|
|
111
108
|
chunks.push(messageText.slice(i, i + chunkSize));
|
|
112
109
|
}
|
|
113
110
|
|
|
114
|
-
// Send updates with small delay
|
|
111
|
+
// Send updates with small delay
|
|
115
112
|
for (let i = 0; i < chunks.length; i++) {
|
|
116
113
|
const partialContent = chunks.slice(0, i + 1).join("");
|
|
117
|
-
|
|
118
|
-
const updateCard = {
|
|
119
|
-
header: {
|
|
120
|
-
title: {
|
|
121
|
-
tag: "plain_text",
|
|
122
|
-
content: "AI 回复",
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
config: {
|
|
126
|
-
wide_screen_mode: true,
|
|
127
|
-
streaming_update: true,
|
|
128
|
-
},
|
|
129
|
-
elements: [
|
|
130
|
-
{
|
|
131
|
-
tag: "markdown",
|
|
132
|
-
content: partialContent,
|
|
133
|
-
},
|
|
134
|
-
],
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
const updateContent = JSON.stringify(updateCard);
|
|
138
|
-
|
|
139
|
-
// Use PATCH /im/message/:message_id with card_id for streaming update
|
|
140
|
-
// Note: This is the official streaming update method
|
|
114
|
+
|
|
141
115
|
try {
|
|
142
|
-
|
|
143
|
-
|
|
116
|
+
// Use cardkit v1 API for batch update
|
|
117
|
+
const updateResponse = await (client as any).cardkit.v1.cards.batch_update({
|
|
118
|
+
path: { card_id: cardId },
|
|
144
119
|
data: {
|
|
145
|
-
|
|
146
|
-
|
|
120
|
+
card: {
|
|
121
|
+
header: {
|
|
122
|
+
title: { tag: "plain_text", content: "AI 回复" },
|
|
123
|
+
},
|
|
124
|
+
config: { wide_screen_mode: true, streaming_update: true },
|
|
125
|
+
elements: [{ tag: "markdown", content: partialContent }],
|
|
126
|
+
},
|
|
147
127
|
},
|
|
148
|
-
})
|
|
128
|
+
});
|
|
149
129
|
|
|
150
|
-
if (
|
|
151
|
-
console.error(`
|
|
130
|
+
if (updateResponse.code !== 0) {
|
|
131
|
+
console.error(`Cardkit batch update failed: ${updateResponse.msg}`);
|
|
152
132
|
}
|
|
153
133
|
} catch (err) {
|
|
154
|
-
console.error(`
|
|
134
|
+
console.error(`Cardkit update error: ${err}`);
|
|
155
135
|
}
|
|
156
136
|
|
|
157
|
-
// Add small delay between updates for streaming effect
|
|
158
137
|
if (i < chunks.length - 1) {
|
|
159
138
|
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
160
139
|
}
|