@milerliu/feishu 0.1.5 → 0.1.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milerliu/feishu",
3
- "version": "0.1.5",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "description": "OpenClaw Feishu/Lark channel plugin",
6
6
  "license": "MIT",
@@ -119,7 +119,7 @@ export function createFeishuReplyDispatcher(params: CreateFeishuReplyDispatcherP
119
119
  let isFirstChunk = true;
120
120
 
121
121
  // Streaming mode: use streaming card for better experience
122
- if (streamingEnabled && useCard && !replyToMessageId) {
122
+ if (streamingEnabled && useCard) {
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 if available
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 the content updates using card_id
106
- // Split content into chunks for streaming effect
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 between each using the correct API
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
- const updateResponse = await (client.im.message as Record<string, unknown>).patch?.({
143
- path: { message_id: messageId },
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
- msg_type: "interactive",
146
- content: updateContent,
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
- }) ?? { code: -1, msg: "API not available" };
128
+ });
149
129
 
150
- if ((updateResponse as Record<string, unknown>).code !== 0) {
151
- console.error(`Feishu streaming update failed: ${(updateResponse as Record<string, unknown>).msg}`);
130
+ if (updateResponse.code !== 0) {
131
+ console.error(`Cardkit batch update failed: ${updateResponse.msg}`);
152
132
  }
153
133
  } catch (err) {
154
- console.error(`Feishu streaming update error: ${err}`);
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
  }