feat(frontend): add wiki tool support and enhance agent tool icon mapping

- Implement `getWikiPageText` function to handle persisted slugs and JSON input for wiki page text retrieval.
- Update `getAgentToolIconName` to include mappings for `wiki_search` and `wiki_read_page` tools.
- Enhance tests to cover new functionality for wiki tools and ensure proper icon mapping in the agent stream display.
- Modify `AgentStreamDisplay` to utilize new wiki tool features and improve localization for wiki-related actions.
This commit is contained in:
wizardchen
2026-06-22 12:24:33 +08:00
committed by lyingbug
parent 0c3c866f0b
commit 483f507104
6 changed files with 65 additions and 3 deletions
@@ -5,6 +5,7 @@ import {
getKnowledgeSearchSummaryHtml,
getQueryText,
getRagPipelineStepTitle,
getWikiPageText,
} from './agent-tool-display.ts'
const t = (key, params) => {
@@ -22,6 +23,12 @@ test('getAgentToolIconName maps rag pipeline tools', () => {
assert.equal(getAgentToolIconName('knowledge_search'), 'data-search')
})
test('getAgentToolIconName maps Wiki tools to semantic search and reading icons', () => {
assert.equal(getAgentToolIconName('wiki_search'), 'search')
assert.equal(getAgentToolIconName('wiki_read_page'), 'file-search')
assert.equal(getAgentToolIconName('wiki_read_source_doc'), 'file-search')
})
test('getQueryText joins unique query strings', () => {
assert.equal(getQueryText({ query: 'foo', queries: ['foo', 'bar'] }), 'foo,bar')
})
@@ -35,6 +42,14 @@ test('getQueryText parses JSON-encoded queries string', () => {
)
})
test('getWikiPageText supports persisted slugs arrays', () => {
assert.equal(
getWikiPageText({ slugs: ['entity/知识助理', 'concept/API管理'] }),
'entity/知识助理、concept/API管理',
)
assert.equal(getWikiPageText('{"slug":"index"}'), 'index')
})
test('getKnowledgeSearchSummaryHtml includes file count when present', () => {
const html = getKnowledgeSearchSummaryHtml(t, {
results: [{}, {}],
+22
View File
@@ -49,6 +49,28 @@ export function getQueryText(args: unknown): string {
return Array.from(new Set(queries)).join(',')
}
export function getWikiPageText(args: unknown): string {
if (!args) return ''
let parsedArgs = args
if (typeof parsedArgs === 'string') {
try {
parsedArgs = JSON.parse(parsedArgs)
} catch {
return ''
}
}
if (!parsedArgs || typeof parsedArgs !== 'object') return ''
const record = parsedArgs as Record<string, unknown>
const slugs = [
...collectQueryStrings(record.slug),
...collectQueryStrings(record.slugs),
]
return Array.from(new Set(slugs)).join('、')
}
export function getKnowledgeSearchSummaryHtml(
t: ComposerTranslation,
toolData: Record<string, unknown> | null | undefined,
+4 -1
View File
@@ -6,6 +6,9 @@ export function getAgentToolIconName(toolName: string): string {
if (toolName === 'search_knowledge' || toolName === 'knowledge_search') {
return 'data-search'
}
if (toolName === 'wiki_search') {
return 'search'
}
if (toolName === 'grep_chunks') {
return 'search'
}
@@ -15,7 +18,7 @@ export function getAgentToolIconName(toolName: string): string {
if (toolName === 'get_document_info' || toolName === 'list_knowledge_chunks') {
return 'file-search'
}
if (toolName === 'get_document_content' || toolName === 'wiki_read_source_doc') {
if (toolName === 'get_document_content' || toolName === 'wiki_read_page' || toolName === 'wiki_read_source_doc') {
return 'file-search'
}
if (toolName === 'todo_write') {