@max1874/feishu 0.2.6 → 0.2.7

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/docx.ts +22 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@max1874/feishu",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "type": "module",
5
5
  "description": "OpenClaw Feishu/Lark channel plugin",
6
6
  "license": "MIT",
package/src/docx.ts CHANGED
@@ -172,6 +172,9 @@ async function convertMarkdown(client: Lark.Client, markdown: string) {
172
172
  }
173
173
 
174
174
  /** Insert blocks as children of a parent block */
175
+ // Batch size for inserting blocks (API may have limits)
176
+ const INSERT_BATCH_SIZE = 50;
177
+
175
178
  async function insertBlocks(
176
179
  client: Lark.Client,
177
180
  docToken: string,
@@ -185,19 +188,26 @@ async function insertBlocks(
185
188
  return { children: [], skipped };
186
189
  }
187
190
 
188
- try {
189
- const res = await client.docx.documentBlockChildren.create({
190
- path: { document_id: docToken, block_id: blockId },
191
- data: { children: cleaned },
192
- });
193
- if (res.code !== 0) throw new Error(res.msg);
194
- return { children: res.data?.children ?? [], skipped };
195
- } catch (err) {
196
- // Log block types for debugging
197
- const blockTypes = cleaned.map((b) => BLOCK_TYPE_NAMES[b.block_type] || `type_${b.block_type}`);
198
- const errMsg = err instanceof Error ? err.message : String(err);
199
- throw new Error(`insertBlocks failed: ${errMsg}. Block types: [${blockTypes.join(", ")}]. Count: ${cleaned.length}`);
191
+ const allChildren: any[] = [];
192
+
193
+ // Insert in batches to avoid API limits
194
+ for (let i = 0; i < cleaned.length; i += INSERT_BATCH_SIZE) {
195
+ const batch = cleaned.slice(i, i + INSERT_BATCH_SIZE);
196
+ try {
197
+ const res = await client.docx.documentBlockChildren.create({
198
+ path: { document_id: docToken, block_id: blockId },
199
+ data: { children: batch },
200
+ });
201
+ if (res.code !== 0) throw new Error(res.msg);
202
+ allChildren.push(...(res.data?.children ?? []));
203
+ } catch (err) {
204
+ const blockTypes = batch.map((b) => BLOCK_TYPE_NAMES[b.block_type] || `type_${b.block_type}`);
205
+ const errMsg = err instanceof Error ? err.message : String(err);
206
+ throw new Error(`insertBlocks failed at batch ${Math.floor(i / INSERT_BATCH_SIZE) + 1}: ${errMsg}. Batch types: [${blockTypes.join(", ")}]. Batch size: ${batch.length}`);
207
+ }
200
208
  }
209
+
210
+ return { children: allChildren, skipped };
201
211
  }
202
212
 
203
213
  /** Delete all child blocks from a parent */