|
25 | 25 | from typing import TYPE_CHECKING, Optional |
26 | 26 |
|
27 | 27 | from openviking.core.building_tree import BuildingTree |
| 28 | +from openviking.core.context import Context |
28 | 29 | from openviking.parse.parsers.media.utils import get_media_base_uri, get_media_type |
29 | 30 | from openviking.server.identity import RequestContext |
30 | 31 | from openviking.storage.queuefs import SemanticMsg, get_queue_manager |
@@ -87,29 +88,18 @@ async def finalize_from_temp( |
87 | 88 | self, |
88 | 89 | temp_dir_path: str, |
89 | 90 | ctx: RequestContext, |
90 | | - scope: str, |
| 91 | + scope: str = "resources", |
91 | 92 | base_uri: Optional[str] = None, |
92 | 93 | source_path: Optional[str] = None, |
93 | 94 | source_format: Optional[str] = None, |
| 95 | + trigger_semantic: bool = False, |
94 | 96 | ) -> "BuildingTree": |
95 | 97 | """ |
96 | | - Finalize tree from temporary directory (v5.0 architecture). |
97 | | -
|
98 | | - New architecture: |
99 | | - 1. Move directory to AGFS |
100 | | - 2. Enqueue to SemanticQueue for async semantic generation |
101 | | - 3. Scan and create Resource objects (for compatibility) |
| 98 | + Finalize processing by moving from temp to AGFS. |
102 | 99 |
|
103 | 100 | Args: |
104 | | - temp_dir_path: Temporary directory Viking URI (e.g., viking://temp/xxx) |
105 | | - scope: Scope ("resources", "user", or "agent") |
106 | | - base_uri: Base URI (None = use scope default) |
107 | | - source_node: Source ResourceNode |
108 | | - source_path: Source file path |
109 | | - source_format: Source file format |
110 | | -
|
111 | | - Returns: |
112 | | - Complete BuildingTree with all resources moved to AGFS |
| 101 | + trigger_semantic: Whether to automatically trigger semantic generation. |
| 102 | + Default is False (handled by ResourceProcessor/Summarizer). |
113 | 103 | """ |
114 | 104 |
|
115 | 105 | viking_fs = get_viking_fs() |
@@ -185,18 +175,23 @@ async def finalize_from_temp( |
185 | 175 | logger.warning(f"[TreeBuilder] Failed to cleanup temp root: {e}") |
186 | 176 |
|
187 | 177 | # 6. Enqueue to SemanticQueue for async semantic generation |
188 | | - try: |
189 | | - await self._enqueue_semantic_generation(final_uri, "resource", ctx=ctx) |
190 | | - logger.info(f"[TreeBuilder] Enqueued semantic generation for: {final_uri}") |
191 | | - except Exception as e: |
192 | | - logger.error(f"[TreeBuilder] Failed to enqueue semantic generation: {e}", exc_info=True) |
| 178 | + if trigger_semantic: |
| 179 | + try: |
| 180 | + await self._enqueue_semantic_generation(final_uri, "resource", ctx=ctx) |
| 181 | + logger.info(f"[TreeBuilder] Enqueued semantic generation for: {final_uri}") |
| 182 | + except Exception as e: |
| 183 | + logger.error(f"[TreeBuilder] Failed to enqueue semantic generation: {e}", exc_info=True) |
193 | 184 |
|
194 | 185 | # 7. Return simple BuildingTree (no scanning needed) |
195 | 186 | tree = BuildingTree( |
196 | 187 | source_path=source_path, |
197 | 188 | source_format=source_format, |
198 | 189 | ) |
199 | 190 | tree._root_uri = final_uri |
| 191 | + |
| 192 | + # Create a minimal Context object for the root so that tree.root is not None |
| 193 | + root_context = Context(uri=final_uri) |
| 194 | + tree.add_context(root_context) |
200 | 195 |
|
201 | 196 | return tree |
202 | 197 |
|
|
0 commit comments