From e971a61bd3cf89d13af35f1d6560960d4177ad91 Mon Sep 17 00:00:00 2001 From: AnotiaWang Date: Tue, 11 Feb 2025 19:26:45 +0800 Subject: [PATCH] chore: cleanup unused `ResearchStep` params --- components/DeepResearch.vue | 53 +++++++++++++++++++------------------ components/Tree.vue | 23 +++++++++------- lib/deep-research.ts | 46 ++++++++++++-------------------- 3 files changed, 57 insertions(+), 65 deletions(-) diff --git a/components/DeepResearch.vue b/components/DeepResearch.vue index 5050284..71cfcc9 100644 --- a/components/DeepResearch.vue +++ b/components/DeepResearch.vue @@ -3,13 +3,11 @@ import type { TreeNode } from './Tree.vue' const tree = ref({ - id: 'root', + id: '0', label: 'Start', children: [], - depth: 0, - breadth: 0, }) - const hoveredNode = ref(null) + const selectedNode = ref(null) const searchResults = ref>({}) const modelValue = computed(() => Object.values(searchResults.value)) @@ -32,9 +30,6 @@ if (!node) { console.error('Creating new node', { nodeId, - depth: step.depth, - breadth: step.breadth, - index: step.nodeIndex, }) // 创建新节点 node = { @@ -43,12 +38,10 @@ researchGoal: 'Generating research goal...', learnings: [], children: [], - depth: step.depth, - breadth: step.breadth, - index: step.nodeIndex, } + const parentNodeId = getParentNodeId(nodeId) // 如果是根节点的直接子节点 - if (step.depth === 1) { + if (parentNodeId === '0') { tree.value.children.push(node) } else { // 找到父节点并添加 @@ -81,6 +74,7 @@ case 'search_complete': { if (node) { + node.visitedUrls = step.urls // node.label = `Found ${step.urls.length} results for: ${node.query}` } break @@ -90,7 +84,6 @@ if (node) { node.learnings = step.result.learnings || [] node.followUpQuestions = step.result.followUpQuestions || [] - // node.label = `Processing results: ${node.query}` } break } @@ -98,7 +91,6 @@ case 'processed_search_result': { if (node) { node.learnings = step.result.learnings - // node.label = `Completed: ${node.query}` searchResults.value[nodeId] = step.result } break @@ -144,9 +136,7 @@ ) { console.log('startResearch', query, depth, breadth, feedback) tree.value.children = [] - tree.value.depth = depth - tree.value.breadth = breadth - hoveredNode.value = null + selectedNode.value = null searchResults.value = {} try { const combinedQuery = ` @@ -178,18 +168,29 @@ ${feedback.map((qa) => `Q: ${qa.assistantQuestion}\nA: ${qa.userAnswer}`).join('
- +
-
-

{{ hoveredNode.label }}

-

Research Goal:

-

{{ hoveredNode.researchGoal }}

-
-

Learnings:

-
    -
  • {{ learning }}
  • +
    +

    {{ selectedNode.label }}

    + + +

    This is the beginning of your deep research journey!

    +
diff --git a/components/Tree.vue b/components/Tree.vue index 4859007..ff36025 100644 --- a/components/Tree.vue +++ b/components/Tree.vue @@ -10,18 +10,14 @@ researchGoal?: string learnings?: string[] followUpQuestions?: string[] + visitedUrls?: string[] status?: TreeNodeStatus children: TreeNode[] - /** Current depth of the node */ - depth: number - /** Maximum breadth at the current depth */ - breadth: number - /** Index of the node among its siblings */ - index?: number } const props = defineProps<{ node: TreeNode + selectedNode: TreeNode | null }>() const emit = defineEmits<{ @@ -64,12 +60,19 @@