Skip to content

Commit 46c89af

Browse files
committed
fix(feishu): populate document content during create
1 parent 7c138c6 commit 46c89af

5 files changed

Lines changed: 90 additions & 7 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Docs: https://docs.openclaw.ai
1212

1313
### Fixes
1414

15+
- Feishu/Docx: allow `feishu_doc` create to populate initial markdown content, including explicit empty content, while keeping create responses free of misleading deleted-block counts. Fixes #48373; carries forward #48377. Thanks @wzx011011.
1516
- NVIDIA/NIM: persist the `NVIDIA_API_KEY` provider marker and mark bundled NVIDIA Chat Completions models as string-content compatible, so NIM models load from `models.json` and OpenAI-compatible subagent calls send plain text content. Fixes #73013 and #50107; refs #73014. Thanks @bautrey, @iot2edge, @ifearghal, and @futhgar.
1617
- CLI/plugins: use plugin metadata snapshots for install slot selection and add opt-in plugin lifecycle timing traces, so plugin install avoids runtime-loading the plugin registry for metadata-only decisions. Thanks @shakkernerd.
1718
- fix(plugins): restrict bundled plugin dir resolution to trusted package roots. (#73275) Thanks @pgondhi987.

‎extensions/feishu/skills/feishu-doc/SKILL.md‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Appends markdown to end of document.
4343
### Create Document
4444

4545
```json
46-
{ "action": "create", "title": "New Document", "owner_open_id": "ou_xxx" }
46+
{ "action": "create", "title": "New Document" }
4747
```
4848

4949
With folder:
@@ -52,12 +52,23 @@ With folder:
5252
{
5353
"action": "create",
5454
"title": "New Document",
55-
"folder_token": "fldcnXXX",
56-
"owner_open_id": "ou_xxx"
55+
"folder_token": "fldcnXXX"
5756
}
5857
```
5958

60-
**Important:** Always pass `owner_open_id` with the requesting user's `open_id` (from inbound metadata `sender_id`) so the user automatically gets `full_access` permission on the created document. Without this, only the bot app has access.
59+
With initial markdown content:
60+
61+
```json
62+
{
63+
"action": "create",
64+
"title": "New Document",
65+
"content": "# Title\n\nInitial content"
66+
}
67+
```
68+
69+
`content` is optional. If provided as an empty string, the tool intentionally creates an empty document.
70+
71+
By default, when called from a trusted Feishu message context, the tool grants the requester edit permission on the created document. Set `grant_to_requester: false` to skip that grant.
6172

6273
### List Blocks
6374

‎extensions/feishu/src/doc-schema.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ export const FeishuDocSchema = Type.Union([
4343
action: Type.Literal("create"),
4444
title: Type.String({ description: "Document title" }),
4545
content: Type.Optional(
46-
Type.String({ description: "Markdown content to populate the document (optional)" }),
46+
Type.String({
47+
description:
48+
"Markdown content to populate the document (optional). Pass an empty string to create an empty document intentionally.",
49+
}),
4750
),
4851
folder_token: Type.Optional(Type.String({ description: "Target folder token (optional)" })),
4952
grant_to_requester: Type.Optional(

‎extensions/feishu/src/docx.test.ts‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,69 @@ describe("feishu_doc image fetch hardening", () => {
431431
expect(result.details.requester_permission_added).toBeUndefined();
432432
});
433433

434+
it("create writes provided markdown content without reporting deleted blocks", async () => {
435+
convertMock.mockResolvedValueOnce({
436+
code: 0,
437+
data: {
438+
blocks: [{ block_type: 2, block_id: "body_1" }],
439+
first_level_block_ids: ["body_1"],
440+
},
441+
});
442+
blockDescendantCreateMock.mockImplementationOnce(async ({ data }) => ({
443+
code: 0,
444+
data: {
445+
children: (data.children_id as string[]).map((id) => ({ block_id: id })),
446+
},
447+
}));
448+
449+
const feishuDocTool = resolveFeishuDocTool();
450+
451+
const result = await executeFeishuDocTool(feishuDocTool, {
452+
action: "create",
453+
title: "Demo",
454+
content: "# Hello",
455+
});
456+
457+
expect(documentCreateMock).toHaveBeenCalledWith({
458+
data: { title: "Demo", folder_token: undefined },
459+
});
460+
expect(convertMock).toHaveBeenCalledWith({
461+
data: { content_type: "markdown", content: "# Hello" },
462+
});
463+
expect(blockDescendantCreateMock).toHaveBeenCalledTimes(1);
464+
expect(result.details.document_id).toBe("doc_created");
465+
expect(result.details.success).toBe(true);
466+
expect(result.details.blocks_added).toBe(1);
467+
expect(result.details.blocks_deleted).toBeUndefined();
468+
});
469+
470+
it("create treats explicit empty content as an intentional empty write", async () => {
471+
convertMock.mockResolvedValueOnce({
472+
code: 0,
473+
data: {
474+
blocks: [],
475+
first_level_block_ids: [],
476+
},
477+
});
478+
479+
const feishuDocTool = resolveFeishuDocTool();
480+
481+
const result = await executeFeishuDocTool(feishuDocTool, {
482+
action: "create",
483+
title: "Demo",
484+
content: "",
485+
});
486+
487+
expect(convertMock).toHaveBeenCalledWith({
488+
data: { content_type: "markdown", content: "" },
489+
});
490+
expect(blockDescendantCreateMock).not.toHaveBeenCalled();
491+
expect(result.details.document_id).toBe("doc_created");
492+
expect(result.details.success).toBe(true);
493+
expect(result.details.blocks_added).toBe(0);
494+
expect(result.details.blocks_deleted).toBeUndefined();
495+
});
496+
434497
it("returns an error when create response omits document_id", async () => {
435498
documentCreateMock.mockResolvedValueOnce({
436499
code: 0,

‎extensions/feishu/src/docx.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ function json(data: unknown) {
3636
};
3737
}
3838

39+
function hasOwnProperty(data: object, key: string): boolean {
40+
return Object.prototype.hasOwnProperty.call(data, key);
41+
}
42+
3943
function resolveDocToolLocalRoots(ctx: {
4044
workspaceDir?: string;
4145
fsPolicy?: { workspaceOnly: boolean };
@@ -1472,11 +1476,12 @@ export function registerFeishuDocTools(api: OpenClawPluginApi) {
14721476
grantToRequester: p.grant_to_requester,
14731477
requesterOpenId: trustedRequesterOpenId,
14741478
});
1475-
if (p.content) {
1479+
if (hasOwnProperty(p, "content")) {
1480+
const content = p.content ?? "";
14761481
const writeResult = await writeDoc(
14771482
client,
14781483
created.document_id,
1479-
p.content,
1484+
content,
14801485
getMediaMaxBytes(p, defaultAccountId),
14811486
api.logger,
14821487
);

0 commit comments

Comments
 (0)