feat: Implement wiki editing functionalities and UI components
- Added new tools for wiki page editing, including writing, replacing text, renaming, and deleting pages, with corresponding data structures for each action. - Enhanced the frontend with a new `WikiEditResult` component to display results of wiki edits, supporting multiple languages for improved accessibility. - Updated localization files for English and Chinese to include new strings related to wiki actions. - Modified existing tools to return structured data for wiki actions, improving the clarity and usability of the output messages. These changes significantly enhance the wiki editing capabilities, providing users with a more robust and user-friendly experience when managing wiki content.
This commit is contained in:
@@ -106,10 +106,20 @@ func (t *wikiDeletePageTool) Execute(ctx context.Context, args json.RawMessage)
|
||||
}
|
||||
}
|
||||
|
||||
outputMsg := fmt.Sprintf("Successfully deleted page %s and cleaned up %d incoming links.", params.Slug, updatedCount)
|
||||
outputMsg := fmt.Sprintf("Successfully deleted page [[%s]] and cleaned up %d incoming links.", params.Slug, updatedCount)
|
||||
if updatedCount > 0 {
|
||||
outputMsg += fmt.Sprintf(" Affected pages: %s", strings.Join(updatedSlugs, ", "))
|
||||
outputMsg += fmt.Sprintf("\n- Affected pages: %s", strings.Join(updatedSlugs, ", "))
|
||||
}
|
||||
|
||||
return &types.ToolResult{Success: true, Output: outputMsg}, nil
|
||||
return &types.ToolResult{
|
||||
Success: true,
|
||||
Output: outputMsg,
|
||||
Data: map[string]interface{}{
|
||||
"display_type": "wiki_delete_page",
|
||||
"slug": params.Slug,
|
||||
"title": existingPage.Title,
|
||||
"updated_count": updatedCount,
|
||||
"affected_pages": updatedSlugs,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -134,10 +134,21 @@ func (t *wikiRenamePageTool) Execute(ctx context.Context, args json.RawMessage)
|
||||
// Rebuild the index page to reflect the new/updated summary
|
||||
_ = t.wikiPageService.RebuildIndexPage(ctx, kbID)
|
||||
|
||||
outputMsg := fmt.Sprintf("Successfully renamed page %s to %s and updated %d incoming links.", params.Slug, params.NewSlug, updatedCount)
|
||||
outputMsg := fmt.Sprintf("Successfully renamed page [[%s]] → [[%s]] and updated %d incoming links.", params.Slug, params.NewSlug, updatedCount)
|
||||
if updatedCount > 0 {
|
||||
outputMsg += fmt.Sprintf(" Affected pages: %s", strings.Join(updatedSlugs, ", "))
|
||||
outputMsg += fmt.Sprintf("\n- Affected pages: %s", strings.Join(updatedSlugs, ", "))
|
||||
}
|
||||
|
||||
return &types.ToolResult{Success: true, Output: outputMsg}, nil
|
||||
return &types.ToolResult{
|
||||
Success: true,
|
||||
Output: outputMsg,
|
||||
Data: map[string]interface{}{
|
||||
"display_type": "wiki_rename_page",
|
||||
"old_slug": params.Slug,
|
||||
"new_slug": params.NewSlug,
|
||||
"title": existingPage.Title,
|
||||
"updated_count": updatedCount,
|
||||
"affected_pages": updatedSlugs,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -95,5 +95,20 @@ func (t *wikiReplaceTextTool) Execute(ctx context.Context, args json.RawMessage)
|
||||
return &types.ToolResult{Success: false, Error: "Failed to update page: " + err.Error()}, nil
|
||||
}
|
||||
|
||||
return &types.ToolResult{Success: true, Output: fmt.Sprintf("Successfully replaced text on page %s.", params.Slug)}, nil
|
||||
oldPreview := truncateRunes(params.OldText, 80)
|
||||
newPreview := truncateRunes(params.NewText, 80)
|
||||
|
||||
output := fmt.Sprintf("Successfully replaced text on page [[%s]].\n- Old: %s\n- New: %s", params.Slug, oldPreview, newPreview)
|
||||
|
||||
return &types.ToolResult{
|
||||
Success: true,
|
||||
Output: output,
|
||||
Data: map[string]interface{}{
|
||||
"display_type": "wiki_replace_text",
|
||||
"slug": params.Slug,
|
||||
"title": existingPage.Title,
|
||||
"old_text": oldPreview,
|
||||
"new_text": newPreview,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -404,3 +404,11 @@ func extractSnippet(content string, query string) string {
|
||||
|
||||
return "... " + strings.TrimSpace(snippet) + " ..."
|
||||
}
|
||||
|
||||
func truncateRunes(s string, maxRunes int) string {
|
||||
runes := []rune(s)
|
||||
if len(runes) <= maxRunes {
|
||||
return s
|
||||
}
|
||||
return string(runes[:maxRunes]) + "..."
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/application/repository"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
@@ -142,8 +143,24 @@ func (t *wikiWritePageTool) Execute(ctx context.Context, args json.RawMessage) (
|
||||
// Rebuild the index page to reflect the new/updated summary
|
||||
_ = t.wikiPageService.RebuildIndexPage(ctx, kbID)
|
||||
|
||||
output := fmt.Sprintf("Successfully %s page [[%s]].\n- Title: %s\n- Type: %s\n- Summary: %s\n- Content length: %d chars", action, params.Slug, params.Title, params.PageType, params.Summary, len(params.Content))
|
||||
if len(params.Aliases) > 0 {
|
||||
output += fmt.Sprintf("\n- Aliases: %s", strings.Join(params.Aliases, ", "))
|
||||
}
|
||||
if len(resolvedRefs) > 0 {
|
||||
output += fmt.Sprintf("\n- Source refs: %d document(s)", len(resolvedRefs))
|
||||
}
|
||||
|
||||
return &types.ToolResult{
|
||||
Success: true,
|
||||
Output: fmt.Sprintf("Successfully %s page %s.", action, params.Slug),
|
||||
Output: output,
|
||||
Data: map[string]interface{}{
|
||||
"display_type": "wiki_write_page",
|
||||
"action": action,
|
||||
"slug": params.Slug,
|
||||
"title": params.Title,
|
||||
"page_type": params.PageType,
|
||||
"summary": params.Summary,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user