e147209e77
This commit introduces the complete wiki feature for WeKnora, enabling AI-powered wiki page generation and management. The implementation includes: **Backend Changes:** - Wiki data model: WikiPage type with support for multiple page types (Summary, Entity, Concept, Index, Log) - Database schema: wiki_pages table with full migration support - WikiPageService: CRUD operations and page management - WikiPageRepository: GORM-based persistence layer - Wiki ingest pipeline: Automated generation of wiki pages from knowledge documents * Summary page generation using LLM * Entity and concept extraction in a single LLM call * Synthesis opportunity detection * Index page rebuilding * Log page maintenance - Wiki boost feature: Enhance chat retrieval with wiki context - Wiki linting: Maintenance and validation utilities - Agent wiki tools: Enable agents to query and interact with wiki pages - Wiki prompts: Comprehensive LLM prompt templates for all wiki generation tasks - Language support: Reuse existing middleware language infrastructure for LLM prompts **Frontend Changes:** - Wiki browser UI: View all wiki pages with filtering and search - Wiki API client: Knowledge base wiki management endpoints - Knowledge base editor: Configure wiki settings (language, auto-ingest, synthesis model) - i18n updates: Support for English, Korean, Russian, and Chinese interfaces **Configuration:** - Container DI: Wire up all wiki services - Router: Register wiki API endpoints - Task handling: Support async wiki ingest tasks **Testing:** - Unit tests for wiki page types - Service layer tests - Endpoint tests for wiki operations - Integration tests with LLM mocking **Documentation:** - Language refactoring analysis and guides - Implementation completion reports - Quick reference guides for developers **Key Features:** ✅ LLM-powered wiki page generation from documents ✅ Multi-language support (9+ languages) ✅ Automatic extraction of entities and concepts ✅ Synthesis opportunity detection ✅ Index and log page maintenance ✅ Progressive wiki building across multiple documents ✅ Agent-based wiki interaction ✅ Chat retrieval enhancement with wiki context ✅ Full frontend UI for wiki browsing Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
104 lines
2.2 KiB
Go
104 lines
2.2 KiB
Go
package tools
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestTruncateForSummary(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
content string
|
|
maxLen int
|
|
want string
|
|
}{
|
|
{
|
|
name: "short content",
|
|
content: "Hello world",
|
|
maxLen: 50,
|
|
want: "Hello world",
|
|
},
|
|
{
|
|
name: "strips heading prefix",
|
|
content: "# My Title\n\nSome content",
|
|
maxLen: 50,
|
|
want: "My Title",
|
|
},
|
|
{
|
|
name: "strips h2 prefix",
|
|
content: "## Section\n\nContent here",
|
|
maxLen: 50,
|
|
want: "Section",
|
|
},
|
|
{
|
|
name: "truncates long content",
|
|
content: "This is a very long paragraph that should be truncated at some point because it exceeds the maximum length",
|
|
maxLen: 20,
|
|
want: "This is a very long ..."},
|
|
{
|
|
name: "takes first paragraph",
|
|
content: "First paragraph.\n\nSecond paragraph.",
|
|
maxLen: 100,
|
|
want: "First paragraph.",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := truncateForSummary(tt.content, tt.maxLen)
|
|
if got != tt.want {
|
|
t.Errorf("truncateForSummary() = %q, want %q", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestWikiToolConstants(t *testing.T) {
|
|
// Verify all wiki tool constants are defined and unique
|
|
names := []string{
|
|
ToolWikiReadPage,
|
|
ToolWikiWritePage,
|
|
ToolWikiSearch,
|
|
ToolWikiReadIndex,
|
|
ToolWikiLint,
|
|
}
|
|
|
|
seen := make(map[string]bool)
|
|
for _, name := range names {
|
|
if name == "" {
|
|
t.Error("Wiki tool constant is empty")
|
|
}
|
|
if seen[name] {
|
|
t.Errorf("Duplicate wiki tool constant: %s", name)
|
|
}
|
|
seen[name] = true
|
|
|
|
// Verify name length is within OpenAI limit
|
|
if len(name) > maxFunctionNameLength {
|
|
t.Errorf("Wiki tool name too long: %s (%d chars, max %d)", name, len(name), maxFunctionNameLength)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestWikiToolsInAvailableDefinitions(t *testing.T) {
|
|
defs := AvailableToolDefinitions()
|
|
wikiTools := map[string]bool{
|
|
ToolWikiReadPage: false,
|
|
ToolWikiWritePage: false,
|
|
ToolWikiSearch: false,
|
|
ToolWikiReadIndex: false,
|
|
ToolWikiLint: false,
|
|
}
|
|
|
|
for _, def := range defs {
|
|
if _, ok := wikiTools[def.Name]; ok {
|
|
wikiTools[def.Name] = true
|
|
}
|
|
}
|
|
|
|
for name, found := range wikiTools {
|
|
if !found {
|
|
t.Errorf("Wiki tool %s missing from AvailableToolDefinitions()", name)
|
|
}
|
|
}
|
|
}
|