From 30c42fc51bd5616f21e44624018b5c275aabc4b6 Mon Sep 17 00:00:00 2001 From: Wu Yue Date: Mon, 28 Jul 2025 13:36:39 +0800 Subject: [PATCH] fix(core): add document content params for section edit tool (#13334) ## Summary by CodeRabbit * **New Features** * Section editing now uses the full document context to ensure edits are consistent with the overall tone, style, and structure. * Cleaner output for edited sections, with internal markdown comments removed. * **Improvements** * Enhanced instructions and descriptions for section editing, providing clearer guidance and examples for users. --- .../server/src/plugins/copilot/prompt/prompts.ts | 14 +++++++++++--- .../src/plugins/copilot/tools/section-edit.ts | 14 ++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/backend/server/src/plugins/copilot/prompt/prompts.ts b/packages/backend/server/src/plugins/copilot/prompt/prompts.ts index 8484c2a0fd..e0e2ce1de5 100644 --- a/packages/backend/server/src/plugins/copilot/prompt/prompts.ts +++ b/packages/backend/server/src/plugins/copilot/prompt/prompts.ts @@ -1481,13 +1481,21 @@ Key requirements: - Maintain the original markdown formatting - Preserve the tone and style unless specifically asked to change it - Only make the requested changes -- Return only the modified text without any explanations or comments`, +- Return only the modified text without any explanations or comments +- Use the full document context to ensure consistency and accuracy +- Do not output markdown annotations like `, }, { role: 'user', content: `Please modify the following text according to these instructions: "{{instructions}}" -Original text: -{{content}}`, + +Full document context: +{{document}} + +Section to edit: +{{content}} + +Please return only the modified section, maintaining consistency with the overall document context.`, }, ], }, diff --git a/packages/backend/server/src/plugins/copilot/tools/section-edit.ts b/packages/backend/server/src/plugins/copilot/tools/section-edit.ts index 9952e434fb..7ae93f1e9c 100644 --- a/packages/backend/server/src/plugins/copilot/tools/section-edit.ts +++ b/packages/backend/server/src/plugins/copilot/tools/section-edit.ts @@ -14,20 +14,25 @@ export const createSectionEditTool = ( ) => { return tool({ description: - 'Intelligently edit and modify a specific section of a document based on user instructions. This tool can refine, rewrite, translate, restructure, or enhance any part of markdown content while preserving formatting and maintaining contextual coherence. Perfect for targeted improvements without affecting the entire document.', + 'Intelligently edit and modify a specific section of a document based on user instructions, with full document context awareness. This tool can refine, rewrite, translate, restructure, or enhance any part of markdown content while preserving formatting, maintaining contextual coherence, and ensuring consistency with the entire document. Perfect for targeted improvements that consider the broader document context.', parameters: z.object({ section: z .string() .describe( - 'The section of the document to be modified (in markdown format)' + 'The specific section or text snippet to be modified (in markdown format). This is the target content that will be edited and replaced.' ), instructions: z .string() .describe( - 'Clear instructions from the user describing the desired changes (e.g., "make this more formal", "translate to Chinese", "add more details", "fix grammar errors")' + 'Clear and specific instructions describing the desired changes. Examples: "make this more formal and professional", "translate to Chinese while keeping technical terms", "add more technical details and examples", "fix grammar and improve clarity", "restructure for better readability"' + ), + document: z + .string() + .describe( + "The complete document content (in markdown format) that provides context for the section being edited. This ensures the edited section maintains consistency with the document's overall tone, style, terminology, and structure." ), }), - execute: async ({ section, instructions }) => { + execute: async ({ section, instructions, document }) => { try { const prompt = await promptService.get('Section Edit'); if (!prompt) { @@ -45,6 +50,7 @@ export const createSectionEditTool = ( prompt.finish({ content: section, instructions, + document, }) );