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:
wizardchen
2026-04-10 21:35:28 +08:00
parent 995e2157cd
commit 84edfa5439
10 changed files with 483 additions and 11 deletions
+18
View File
@@ -2030,6 +2030,24 @@ export default {
noKnowledgeBases: 'No knowledge bases available',
enterDescription: 'Enter description',
rawOutputLabel: 'Raw output',
wikiWritePageTitle: 'Wiki Page Write',
wikiReplaceTextTitle: 'Wiki Text Replace',
wikiRenamePageTitle: 'Wiki Page Rename',
wikiDeletePageTitle: 'Wiki Page Delete',
wikiActionCreated: 'Created',
wikiActionUpdated: 'Updated',
wikiActionRenamed: 'Renamed',
wikiActionDeleted: 'Deleted',
wikiFieldSlug: 'Slug',
wikiFieldTitle: 'Title',
wikiFieldPageType: 'Type',
wikiFieldSummary: 'Summary',
wikiFieldOldText: 'Old text',
wikiFieldNewText: 'New text',
wikiFieldOldSlug: 'Old slug',
wikiFieldNewSlug: 'New slug',
wikiFieldAffectedPages: 'Affected pages',
wikiAffectedCount: '{count} page link(s) updated',
selectKnowledgeBaseWarning: 'Please select at least one knowledge base',
processError: 'Processing error',
sessionExcerpt: 'Session Excerpt',
+18
View File
@@ -403,6 +403,24 @@ export default {
knowledgeBaseCount: "共 {count} 个知识库",
noKnowledgeBases: "没有可用的知识库",
rawOutputLabel: "原始输出",
wikiWritePageTitle: "Wiki 页面写入",
wikiReplaceTextTitle: "Wiki 文本替换",
wikiRenamePageTitle: "Wiki 页面重命名",
wikiDeletePageTitle: "Wiki 页面删除",
wikiActionCreated: "已创建",
wikiActionUpdated: "已更新",
wikiActionRenamed: "已重命名",
wikiActionDeleted: "已删除",
wikiFieldSlug: "页面路径",
wikiFieldTitle: "标题",
wikiFieldPageType: "类型",
wikiFieldSummary: "摘要",
wikiFieldOldText: "原文本",
wikiFieldNewText: "新文本",
wikiFieldOldSlug: "原路径",
wikiFieldNewSlug: "新路径",
wikiFieldAffectedPages: "受影响页面",
wikiAffectedCount: "{count} 个页面的链接已更新",
selectKnowledgeBaseWarning: "请至少选择一个知识库",
processError: "处理出错",
sessionExcerpt: "会话摘录",
+51 -2
View File
@@ -20,7 +20,11 @@ export type DisplayType =
| 'database_query'
| 'web_search_results'
| 'web_fetch_results'
| 'grep_results';
| 'grep_results'
| 'wiki_write_page'
| 'wiki_replace_text'
| 'wiki_rename_page'
| 'wiki_delete_page';
// Search result item
export interface SearchResultItem {
@@ -216,6 +220,47 @@ export interface GrepResultsData {
max_results: number;
}
// Wiki write page data
export interface WikiWritePageData {
display_type: 'wiki_write_page';
action: 'created' | 'updated';
slug: string;
title: string;
page_type: string;
summary: string;
}
// Wiki replace text data
export interface WikiReplaceTextData {
display_type: 'wiki_replace_text';
slug: string;
title: string;
old_text: string;
new_text: string;
}
// Wiki rename page data
export interface WikiRenamePageData {
display_type: 'wiki_rename_page';
old_slug: string;
new_slug: string;
title: string;
updated_count: number;
affected_pages?: string[];
}
// Wiki delete page data
export interface WikiDeletePageData {
display_type: 'wiki_delete_page';
slug: string;
title: string;
updated_count: number;
affected_pages?: string[];
}
// Union type for all wiki edit data
export type WikiEditData = WikiWritePageData | WikiReplaceTextData | WikiRenamePageData | WikiDeletePageData;
// Union type for all tool result data
export type ToolResultData =
| SearchResultsData
@@ -229,7 +274,11 @@ export type ToolResultData =
| DatabaseQueryData
| WebSearchResultsData
| WebFetchResultsData
| GrepResultsData;
| GrepResultsData
| WikiWritePageData
| WikiReplaceTextData
| WikiRenamePageData
| WikiDeletePageData;
// Action data (from index.vue)
export interface ActionData {
@@ -73,6 +73,12 @@
:data="toolData as GrepResultsData"
/>
<!-- Wiki Edit Results Display -->
<WikiEditResult
v-else-if="displayType === 'wiki_write_page' || displayType === 'wiki_replace_text' || displayType === 'wiki_rename_page' || displayType === 'wiki_delete_page'"
:data="toolData as WikiEditData"
/>
<!-- Fallback: Display raw output -->
<div v-else class="fallback-output">
<div class="fallback-header">
@@ -100,7 +106,8 @@ import type {
DatabaseQueryData,
WebSearchResultsData,
WebFetchResultsData,
GrepResultsData
GrepResultsData,
WikiEditData
} from '@/types/tool-results';
import SearchResults from './tool-results/SearchResults.vue';
@@ -115,6 +122,7 @@ import DatabaseQuery from './tool-results/DatabaseQuery.vue';
import WebSearchResults from './tool-results/WebSearchResults.vue';
import WebFetchResults from './tool-results/WebFetchResults.vue';
import GrepResults from './tool-results/GrepResults.vue';
import WikiEditResult from './tool-results/WikiEditResult.vue';
interface Props {
displayType?: DisplayType;
@@ -0,0 +1,318 @@
<template>
<div class="wiki-edit-result">
<div class="result-card wiki-card">
<div class="result-header wiki-header">
<div class="result-title">
<span class="wiki-icon" :class="actionClass">{{ actionIcon }}</span>
<span class="wiki-title-text">{{ headerTitle }}</span>
</div>
<div class="result-meta">
<span class="action-badge" :class="actionClass">{{ actionLabel }}</span>
</div>
</div>
<div class="result-content expanded">
<div class="info-section">
<!-- wiki_write_page -->
<template v-if="data.display_type === 'wiki_write_page'">
<div class="info-field">
<span class="field-label">{{ $t('chat.wikiFieldSlug') }}</span>
<span class="field-value"><code>{{ data.slug }}</code></span>
</div>
<div class="info-field">
<span class="field-label">{{ $t('chat.wikiFieldTitle') }}</span>
<span class="field-value">{{ data.title }}</span>
</div>
<div class="info-field">
<span class="field-label">{{ $t('chat.wikiFieldPageType') }}</span>
<span class="field-value"><code>{{ data.page_type }}</code></span>
</div>
<div class="info-field">
<span class="field-label">{{ $t('chat.wikiFieldSummary') }}</span>
<span class="field-value">{{ data.summary }}</span>
</div>
</template>
<!-- wiki_replace_text -->
<template v-else-if="data.display_type === 'wiki_replace_text'">
<div class="info-field">
<span class="field-label">{{ $t('chat.wikiFieldSlug') }}</span>
<span class="field-value"><code>{{ data.slug }}</code></span>
</div>
<div class="info-field" v-if="data.title">
<span class="field-label">{{ $t('chat.wikiFieldTitle') }}</span>
<span class="field-value">{{ data.title }}</span>
</div>
<div class="diff-block">
<div class="diff-line diff-old">
<span class="diff-marker">-</span>
<span class="diff-text">{{ data.old_text }}</span>
</div>
<div class="diff-line diff-new">
<span class="diff-marker">+</span>
<span class="diff-text">{{ data.new_text }}</span>
</div>
</div>
</template>
<!-- wiki_rename_page -->
<template v-else-if="data.display_type === 'wiki_rename_page'">
<div class="info-field" v-if="data.title">
<span class="field-label">{{ $t('chat.wikiFieldTitle') }}</span>
<span class="field-value">{{ data.title }}</span>
</div>
<div class="rename-visual">
<code class="slug-old">{{ data.old_slug }}</code>
<span class="rename-arrow">→</span>
<code class="slug-new">{{ data.new_slug }}</code>
</div>
<div class="info-field" v-if="data.updated_count > 0">
<span class="field-label">{{ $t('chat.wikiFieldAffectedPages') }}</span>
<span class="field-value">{{ $t('chat.wikiAffectedCount', { count: data.updated_count }) }}</span>
</div>
<div class="affected-list" v-if="data.affected_pages?.length">
<code v-for="slug in data.affected_pages" :key="slug" class="affected-slug">{{ slug }}</code>
</div>
</template>
<!-- wiki_delete_page -->
<template v-else-if="data.display_type === 'wiki_delete_page'">
<div class="info-field">
<span class="field-label">{{ $t('chat.wikiFieldSlug') }}</span>
<span class="field-value"><code>{{ data.slug }}</code></span>
</div>
<div class="info-field" v-if="data.title">
<span class="field-label">{{ $t('chat.wikiFieldTitle') }}</span>
<span class="field-value">{{ data.title }}</span>
</div>
<div class="info-field" v-if="data.updated_count > 0">
<span class="field-label">{{ $t('chat.wikiFieldAffectedPages') }}</span>
<span class="field-value">{{ $t('chat.wikiAffectedCount', { count: data.updated_count }) }}</span>
</div>
<div class="affected-list" v-if="data.affected_pages?.length">
<code v-for="slug in data.affected_pages" :key="slug" class="affected-slug">{{ slug }}</code>
</div>
</template>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
import type { WikiEditData } from '@/types/tool-results';
const props = defineProps<{
data: WikiEditData;
}>();
const { t } = useI18n();
const actionIcon = computed(() => {
switch (props.data.display_type) {
case 'wiki_write_page': return (props.data as any).action === 'created' ? '✦' : '✎';
case 'wiki_replace_text': return '⇄';
case 'wiki_rename_page': return '↻';
case 'wiki_delete_page': return '✕';
default: return '•';
}
});
const actionClass = computed(() => {
switch (props.data.display_type) {
case 'wiki_write_page':
return (props.data as any).action === 'created' ? 'created' : 'updated';
case 'wiki_replace_text': return 'updated';
case 'wiki_rename_page': return 'renamed';
case 'wiki_delete_page': return 'deleted';
default: return '';
}
});
const actionLabel = computed(() => {
switch (props.data.display_type) {
case 'wiki_write_page':
return (props.data as any).action === 'created'
? t('chat.wikiActionCreated')
: t('chat.wikiActionUpdated');
case 'wiki_replace_text': return t('chat.wikiActionUpdated');
case 'wiki_rename_page': return t('chat.wikiActionRenamed');
case 'wiki_delete_page': return t('chat.wikiActionDeleted');
default: return '';
}
});
const headerTitle = computed(() => {
switch (props.data.display_type) {
case 'wiki_write_page': return t('chat.wikiWritePageTitle');
case 'wiki_replace_text': return t('chat.wikiReplaceTextTitle');
case 'wiki_rename_page': return t('chat.wikiRenamePageTitle');
case 'wiki_delete_page': return t('chat.wikiDeletePageTitle');
default: return 'Wiki';
}
});
</script>
<style lang="less" scoped>
@import './tool-results.less';
.wiki-edit-result {
display: flex;
flex-direction: column;
gap: 8px;
}
.wiki-card {
margin: 0 8px 8px 8px;
}
.wiki-header {
.wiki-icon {
font-size: 14px;
width: 20px;
height: 20px;
display: inline-flex;
align-items: center;
justify-content: center;
border-radius: 4px;
flex-shrink: 0;
&.created {
color: var(--td-success-color);
background: rgba(0, 168, 112, 0.1);
}
&.updated {
color: var(--td-brand-color);
background: rgba(7, 192, 95, 0.1);
}
&.renamed {
color: var(--td-warning-color);
background: rgba(255, 152, 0, 0.1);
}
&.deleted {
color: var(--td-error-color);
background: rgba(227, 77, 89, 0.1);
}
}
.wiki-title-text {
font-size: 13px;
font-weight: 500;
color: var(--td-text-color-primary);
}
}
.action-badge {
font-size: 11px;
font-weight: 600;
padding: 2px 8px;
border-radius: 10px;
line-height: 1.5;
&.created {
color: var(--td-success-color);
background: rgba(0, 168, 112, 0.1);
border: 1px solid rgba(0, 168, 112, 0.2);
}
&.updated {
color: var(--td-brand-color);
background: rgba(7, 192, 95, 0.1);
border: 1px solid rgba(7, 192, 95, 0.2);
}
&.renamed {
color: var(--td-warning-color);
background: rgba(255, 152, 0, 0.1);
border: 1px solid rgba(255, 152, 0, 0.2);
}
&.deleted {
color: var(--td-error-color);
background: rgba(227, 77, 89, 0.1);
border: 1px solid rgba(227, 77, 89, 0.2);
}
}
.diff-block {
margin-top: 8px;
border: 1px solid @card-border;
border-radius: 4px;
overflow: hidden;
font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
font-size: 12px;
}
.diff-line {
display: flex;
gap: 8px;
padding: 6px 10px;
line-height: 1.5;
&.diff-old {
background: rgba(227, 77, 89, 0.06);
color: var(--td-error-color);
border-bottom: 1px solid @card-border;
}
&.diff-new {
background: rgba(0, 168, 112, 0.06);
color: var(--td-success-color);
}
}
.diff-marker {
font-weight: 700;
flex-shrink: 0;
width: 14px;
text-align: center;
}
.diff-text {
word-break: break-word;
color: var(--td-text-color-primary);
}
.rename-visual {
display: flex;
align-items: center;
gap: 10px;
padding: 8px 0;
flex-wrap: wrap;
.slug-old {
text-decoration: line-through;
opacity: 0.6;
}
.slug-new {
color: var(--td-success-color);
font-weight: 600;
}
.rename-arrow {
font-size: 16px;
color: var(--td-text-color-placeholder);
}
}
.affected-list {
display: flex;
flex-wrap: wrap;
gap: 4px;
margin-top: 6px;
padding-left: 90px;
.affected-slug {
font-size: 11px;
padding: 2px 6px;
border-radius: 3px;
background: var(--td-bg-color-secondarycontainer);
border: 1px solid @card-border;
}
}
code {
font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
font-size: 11px;
background: var(--td-bg-color-secondarycontainer);
padding: 2px 5px;
border-radius: 3px;
color: var(--td-text-color-primary);
}
</style>
+13 -3
View File
@@ -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
}
+14 -3
View File
@@ -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
}
+16 -1
View File
@@ -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
}
+8
View File
@@ -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]) + "..."
}
+18 -1
View File
@@ -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
}