refactor: Enhance AgentQARequest structure with additional fields and improve session handling methods for clarity and functionality

This commit is contained in:
wizardchen
2025-11-27 17:56:53 +08:00
parent 0550d3669a
commit c222993777
8 changed files with 637 additions and 425 deletions
+9 -12
View File
@@ -193,29 +193,26 @@ export interface WebFetchResultsData {
count?: number;
}
// Grep chunk result item
export interface GrepChunkItem {
id: string;
content: string;
chunk_index: number;
// Grep knowledge aggregation item
export interface GrepKnowledgeResult {
knowledge_id: string;
knowledge_base_id: string;
chunk_type?: string;
knowledge_title?: string;
knowledge_title: string;
chunk_hit_count: number;
pattern_counts: Record<string, number>;
total_pattern_hits: number;
distinct_patterns: number;
}
// Grep results data
export interface GrepResultsData {
display_type: 'grep_results';
patterns: string[];
case_sensitive: boolean;
use_regex: boolean;
results: GrepChunkItem[];
knowledge_results: GrepKnowledgeResult[];
result_count: number;
total_matches: number;
knowledge_base_ids?: string[];
knowledge_ids?: string[];
limit: number;
max_results: number;
}
// Union type for all tool result data
@@ -1,38 +1,16 @@
<template>
<div class="grep-results">
<!-- Results List -->
<div v-if="results && results.length > 0" class="results-list">
<div
v-for="(result, index) in results"
:key="result.id"
class="result-item"
<div v-if="results.length" class="results-list">
<div
v-for="(result, index) in results"
:key="result.knowledge_id"
class="result-row"
>
<t-popup
:overlayClassName="`grep-popup-${result.id}`"
placement="bottom-left"
width="400"
:showArrow="false"
trigger="click"
destroy-on-close
>
<template #content>
<ContentPopup
:content="result.content"
:chunk-id="result.id"
:knowledge-id="result.knowledge_id"
/>
</template>
<div class="result-header">
<div class="result-title">
<span class="result-index">#{{ index + 1 }}</span>
<span class="knowledge-title">{{ result.knowledge_title || 'Untitled' }}</span>
</div>
</div>
</t-popup>
<div class="result-row__index">#{{ index + 1 }}</div>
<div class="result-row__title">{{ result.knowledge_title || 'Untitled' }}</div>
</div>
</div>
<!-- Empty State -->
<div v-else class="empty-state">
未找到匹配的内容
</div>
@@ -42,22 +20,20 @@
<script setup lang="ts">
import { computed } from 'vue';
import type { GrepResultsData } from '@/types/tool-results';
import ContentPopup from './ContentPopup.vue';
const props = defineProps<{
data: GrepResultsData;
}>();
const maxDisplayPatterns = 2;
const patterns = computed(() => props.data.patterns ?? []);
const results = computed(() => props.data.knowledge_results ?? []);
const displayPatterns = computed(() => {
if (!props.data.patterns || props.data.patterns.length === 0) {
return [];
}
return props.data.patterns.slice(0, maxDisplayPatterns);
});
const resultCount = computed(() => props.data.result_count ?? results.value.length);
const totalMatches = computed(() => props.data.total_matches ?? results.value.length);
const maxResults = computed(() => props.data.max_results ?? results.value.length);
const hasMoreResults = computed(() => totalMatches.value > resultCount.value);
const results = computed(() => props.data.results || []);
// Compact view, no per-pattern stats
</script>
<style lang="less" scoped>
@@ -66,98 +42,72 @@ const results = computed(() => props.data.results || []);
.grep-results {
display: flex;
flex-direction: column;
gap: 3px;
padding: 0 0 0 12px;
gap: 8px;
}
.summary-inline {
font-size: 12px;
color: #6b7280;
display: flex;
align-items: center;
gap: 6px;
&__divider {
color: #d1d5db;
}
&__truncated {
color: #f59e0b;
}
}
.results-list {
display: flex;
flex-direction: column;
gap: 3px;
gap: 4px;
padding: 10px 12px 10px 12px;
}
.result-item {
background: transparent;
border: none;
border-radius: 0;
overflow: visible;
}
.result-header {
padding: 2px 0;
cursor: pointer;
user-select: none;
display: flex;
.result-row {
display: grid;
grid-template-columns: 40px minmax(120px, 1fr) auto;
align-items: center;
gap: 6px;
transition: color 0.15s ease;
&:hover {
color: #07c05f;
}
}
.result-title {
display: flex;
align-items: center;
gap: 6px;
flex: 1;
min-width: 0;
gap: 8px;
padding: 4px 10px;
border-radius: 4px;
background: #f9fafb;
border: 1px solid #edf2f7;
font-size: 12px;
line-height: 1.4;
}
.result-index {
font-size: 11px;
color: #9ca3af;
.result-row__index {
font-weight: 600;
flex-shrink: 0;
color: #9ca3af;
}
.pattern-badge {
display: inline-flex;
align-items: center;
gap: 3px;
flex-shrink: 0;
.pattern-text {
font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
font-size: 10px;
background: #f3f4f6;
color: #6b7280;
padding: 2px 5px;
border-radius: 3px;
white-space: nowrap;
font-weight: 500;
}
.more-patterns {
font-size: 10px;
color: #9ca3af;
padding: 2px 4px;
background: #f3f4f6;
border-radius: 3px;
}
}
.knowledge-title {
font-size: 12px;
color: #374151;
flex: 1;
.result-row__title {
color: #111827;
font-weight: 500;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
min-width: 0;
}
.chunk-info {
font-size: 10px;
color: #9ca3af;
background: #f3f4f6;
padding: 2px 5px;
border-radius: 3px;
flex-shrink: 0;
.result-row__meta {
display: flex;
gap: 6px;
flex-wrap: wrap;
justify-content: flex-end;
}
.meta-pill {
font-size: 11px;
color: #6b7280;
background: #fff;
border: 1px solid #e5e7eb;
border-radius: 999px;
padding: 2px 8px;
}
.empty-state {
@@ -166,20 +116,8 @@ const results = computed(() => props.data.results || []);
color: #9ca3af;
font-size: 12px;
font-style: italic;
}
// Popup overlay styles
:deep([class*="grep-popup-"]) {
.t-popup__content {
max-height: 400px;
max-width: 500px;
overflow-y: auto;
overflow-x: hidden;
padding: 0;
border-radius: 6px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
word-wrap: break-word;
word-break: break-word;
}
background: #f9fafb;
border-radius: 6px;
border: 1px dashed #e5e7eb;
}
</style>