fix(feishu): chunk large documents for write/append to avoid API 400 errors#14402
Conversation
| function splitMarkdownByHeadings(markdown: string): string[] { | ||
| const lines = markdown.split("\n"); | ||
| const chunks: string[] = []; |
There was a problem hiding this comment.
Splits inside code fences
splitMarkdownByHeadings() splits on any line matching ^#{1,2}\s, without tracking fenced code blocks. If a long markdown contains a fenced code block with lines starting with # / ## (common in shell scripts or embedded markdown examples), this will split inside the fence; chunkedConvertMarkdown() then calls document.convert on partial/unterminated fences, which can change or corrupt the resulting blocks compared to converting the full markdown in one call.
Also affects: extensions/feishu/src/docx.ts:143-152.
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/feishu/src/docx.ts
Line: 124:126
Comment:
**Splits inside code fences**
`splitMarkdownByHeadings()` splits on any line matching `^#{1,2}\s`, without tracking fenced code blocks. If a long markdown contains a fenced code block with lines starting with `# ` / `## ` (common in shell scripts or embedded markdown examples), this will split *inside* the fence; `chunkedConvertMarkdown()` then calls `document.convert` on partial/unterminated fences, which can change or corrupt the resulting blocks compared to converting the full markdown in one call.
Also affects: extensions/feishu/src/docx.ts:143-152.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Fixed in afc7e54 — splitMarkdownByHeadings() now tracks fenced code blocks and skips heading detection when inside one. Thanks for catching this!
afc7e54 to
596b2b7
Compare
9ded3d5 to
48256a8
Compare
bfc1ccb to
f92900f
Compare
48256a8 to
9b7fb57
Compare
|
This pull request has been automatically marked as stale due to inactivity. |
|
Strong +1 on the problem statement, but this implementation needs rework before merge. Blocking concerns:
Suggested path:
Happy to re-review once those are in. |
…errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches.
Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content.
9b7fb57 to
2e101fa
Compare
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> (cherry picked from commit dff8cc3)
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> (cherry picked from commit dff8cc3)
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> (cherry picked from commit dff8cc3)
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> (cherry picked from commit 4dc55ea) # Conflicts: # CHANGELOG.md # extensions/feishu/src/docx.ts
…errors (openclaw#14402) Cherry-pick of upstream 4dc55ea.
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> (cherry picked from commit 4dc55ea) # Conflicts: # CHANGELOG.md
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…errors (openclaw#14402) Cherry-pick of upstream 4dc55ea.
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…errors (openclaw#14402) * fix(feishu): chunk large documents for write/append to avoid API 400 errors The Feishu API limits documentBlockChildren.create to 50 blocks per request and document.convert has content size limits for large markdown. Previously, writeDoc and appendDoc would send the entire content in a single API call, causing HTTP 400 errors for long documents. This commit adds: - splitMarkdownByHeadings(): splits markdown at # or ## headings - chunkedConvertMarkdown(): converts each chunk independently - chunkedInsertBlocks(): batches blocks into groups of ≤50 Both writeDoc and appendDoc now use the chunked helpers while preserving backward compatibility for small documents. Image processing correctly receives all inserted blocks across batches. * fix(feishu): skip heading detection inside fenced code blocks Addresses review feedback: splitMarkdownByHeadings() now tracks fenced code blocks (``` or ~~~) and skips heading-based splitting when inside one, preventing corruption of code block content. * Feishu/Docx: add convert fallback chunking + tests --------- Co-authored-by: lml2468 <lml2468@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
Problem
When writing long documents via
feishu_doctool (action: "write"oraction: "append"), the Feishu API returns HTTP 400 errors because:documentBlockChildren.createis limited to 50 blocks per requestdocument.converthas content size limits for large markdown inputThis makes it impossible to write comprehensive reports or long-form content to Feishu docs in a single operation — users must manually split content and call
appendmultiple times.Solution
Added three helper functions to
extensions/feishu/src/docx.ts:splitMarkdownByHeadings()— Splits markdown at#/##headings into smaller chunkschunkedConvertMarkdown()— Converts each chunk independently via the convert API, combining all blockschunkedInsertBlocks()— Batches blocks into groups of ≤50 for the insert APIUpdated
writeDocandappendDocto use the chunked helpers. Small documents work exactly as before (single chunk, single batch).Image processing correctly receives all inserted blocks across batches.
Testing
Changes
extensions/feishu/src/docx.ts: +61/-4 linesGreptile Overview
Greptile Summary
This PR updates the Feishu
feishu_docwrite/append implementation to handle large inputs by:docx.document.convert, anddocumentBlockChildren.createlimits.The batching approach fits into the existing
convertMarkdown→insertBlocksflow inextensions/feishu/src/docx.ts, withwriteDoc/appendDocnow delegating to chunked helpers and passing the aggregated inserted blocks toprocessImages.Confidence Score: 3/5
#/##lines.(2/5) Greptile learns from your feedback when you react with thumbs up/down!