@max1874/feishu 0.2.2 → 0.2.3
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/docx.ts +80 -7
package/package.json
CHANGED
package/src/docx.ts
CHANGED
|
@@ -123,12 +123,34 @@ async function insertBlocks(
|
|
|
123
123
|
return { children: [], skipped };
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
126
|
+
// Log table blocks for debugging
|
|
127
|
+
const tableBlocks = cleaned.filter((b) => b.block_type === 31);
|
|
128
|
+
if (tableBlocks.length > 0) {
|
|
129
|
+
console.log(`[feishu_doc] Attempting to insert ${tableBlocks.length} table block(s)`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
const res = await client.docx.documentBlockChildren.create({
|
|
134
|
+
path: { document_id: docToken, block_id: blockId },
|
|
135
|
+
data: { children: cleaned },
|
|
136
|
+
});
|
|
137
|
+
if (res.code !== 0) {
|
|
138
|
+
throw new Error(`API error ${res.code}: ${res.msg}`);
|
|
139
|
+
}
|
|
140
|
+
return { children: res.data?.children ?? [], skipped };
|
|
141
|
+
} catch (err: any) {
|
|
142
|
+
// Enhanced error logging
|
|
143
|
+
const errMsg = err?.response?.data?.msg || err?.message || String(err);
|
|
144
|
+
const errCode = err?.response?.data?.code || err?.code;
|
|
145
|
+
console.error(`[feishu_doc] insertBlocks failed: code=${errCode}, msg=${errMsg}`);
|
|
146
|
+
|
|
147
|
+
// If table blocks exist, report them as problematic
|
|
148
|
+
if (tableBlocks.length > 0) {
|
|
149
|
+
console.error(`[feishu_doc] Table block structure sample:`, JSON.stringify(tableBlocks[0], null, 2).slice(0, 500));
|
|
150
|
+
throw new Error(`Table insertion failed (code=${errCode}): ${errMsg}. Tables may not be supported via this API.`);
|
|
151
|
+
}
|
|
152
|
+
throw err;
|
|
153
|
+
}
|
|
132
154
|
}
|
|
133
155
|
|
|
134
156
|
/** Delete all child blocks from a parent */
|
|
@@ -572,6 +594,32 @@ async function listAppScopes(client: Lark.Client) {
|
|
|
572
594
|
};
|
|
573
595
|
}
|
|
574
596
|
|
|
597
|
+
/** Debug: convert markdown and show resulting block structure */
|
|
598
|
+
async function debugConvertMarkdown(client: Lark.Client, markdown: string) {
|
|
599
|
+
const { blocks } = await convertMarkdown(client, markdown);
|
|
600
|
+
|
|
601
|
+
const blockTypeCounts: Record<string, number> = {};
|
|
602
|
+
for (const block of blocks) {
|
|
603
|
+
const typeName = BLOCK_TYPE_NAMES[block.block_type] || `type_${block.block_type}`;
|
|
604
|
+
blockTypeCounts[typeName] = (blockTypeCounts[typeName] || 0) + 1;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// Find table blocks and show their structure
|
|
608
|
+
const tableBlocks = blocks.filter((b) => b.block_type === 31);
|
|
609
|
+
let tableSample: any = null;
|
|
610
|
+
if (tableBlocks.length > 0) {
|
|
611
|
+
tableSample = tableBlocks[0];
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
return {
|
|
615
|
+
total_blocks: blocks.length,
|
|
616
|
+
block_types: blockTypeCounts,
|
|
617
|
+
has_tables: tableBlocks.length > 0,
|
|
618
|
+
table_count: tableBlocks.length,
|
|
619
|
+
table_sample: tableSample ? JSON.stringify(tableSample, null, 2) : null,
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
|
|
575
623
|
// ============ Schemas ============
|
|
576
624
|
|
|
577
625
|
const DocTokenSchema = Type.Object({
|
|
@@ -628,6 +676,10 @@ const SetPermissionSchema = Type.Object({
|
|
|
628
676
|
}),
|
|
629
677
|
});
|
|
630
678
|
|
|
679
|
+
const DebugConvertSchema = Type.Object({
|
|
680
|
+
content: Type.String({ description: "Markdown content to convert (for debugging block structure)" }),
|
|
681
|
+
});
|
|
682
|
+
|
|
631
683
|
// Wiki Schemas
|
|
632
684
|
const WikiTokenSchema = Type.Object({
|
|
633
685
|
wiki_token: Type.String({ description: "Wiki token (extract from URL /wiki/XXX)" }),
|
|
@@ -963,5 +1015,26 @@ export function registerFeishuDocTools(api: OpenClawPluginApi) {
|
|
|
963
1015
|
{ name: "feishu_app_scopes" },
|
|
964
1016
|
);
|
|
965
1017
|
|
|
966
|
-
|
|
1018
|
+
// Tool 15: feishu_debug_convert (for diagnosing markdown conversion issues)
|
|
1019
|
+
api.registerTool(
|
|
1020
|
+
{
|
|
1021
|
+
name: "feishu_debug_convert",
|
|
1022
|
+
label: "Feishu Debug Convert",
|
|
1023
|
+
description:
|
|
1024
|
+
"Debug tool: convert markdown to blocks and show the resulting structure. Use to diagnose why certain markdown (like tables) may fail to write.",
|
|
1025
|
+
parameters: DebugConvertSchema,
|
|
1026
|
+
async execute(_toolCallId, params) {
|
|
1027
|
+
const { content } = params as { content: string };
|
|
1028
|
+
try {
|
|
1029
|
+
const result = await debugConvertMarkdown(getClient(), content);
|
|
1030
|
+
return json(result);
|
|
1031
|
+
} catch (err) {
|
|
1032
|
+
return json({ error: err instanceof Error ? err.message : String(err) });
|
|
1033
|
+
}
|
|
1034
|
+
},
|
|
1035
|
+
},
|
|
1036
|
+
{ name: "feishu_debug_convert" },
|
|
1037
|
+
);
|
|
1038
|
+
|
|
1039
|
+
api.logger.info?.(`feishu_doc: Registered 15 document/wiki tools`);
|
|
967
1040
|
}
|