| from core.workflow.nodes.base.node import Node | from core.workflow.nodes.base.node import Node | ||||
| from core.workflow.nodes.base.template import Template | from core.workflow.nodes.base.template import Template | ||||
| from core.workflow.nodes.end.end_node import EndNode | from core.workflow.nodes.end.end_node import EndNode | ||||
| from core.workflow.nodes.knowledge_index import KnowledgeIndexNode | |||||
| @dataclass | @dataclass | ||||
| Raises: | Raises: | ||||
| TypeError: If node is not an AnswerNode or EndNode | TypeError: If node is not an AnswerNode or EndNode | ||||
| """ | """ | ||||
| if not isinstance(node, AnswerNode | EndNode): | |||||
| if not isinstance(node, AnswerNode | EndNode | KnowledgeIndexNode): | |||||
| raise TypeError | raise TypeError | ||||
| return cls( | return cls( | ||||
| node_id=node.id, | node_id=node.id, |
| from core.rag.retrieval.retrieval_methods import RetrievalMethod | from core.rag.retrieval.retrieval_methods import RetrievalMethod | ||||
| from core.workflow.entities.variable_pool import VariablePool | from core.workflow.entities.variable_pool import VariablePool | ||||
| from core.workflow.entities.workflow_node_execution import WorkflowNodeExecutionStatus | from core.workflow.entities.workflow_node_execution import WorkflowNodeExecutionStatus | ||||
| from core.workflow.enums import ErrorStrategy, NodeType, SystemVariableKey | |||||
| from core.workflow.enums import ErrorStrategy, NodeExecutionType, NodeType, SystemVariableKey | |||||
| from core.workflow.node_events import NodeRunResult | from core.workflow.node_events import NodeRunResult | ||||
| from core.workflow.nodes.base.entities import BaseNodeData, RetryConfig | from core.workflow.nodes.base.entities import BaseNodeData, RetryConfig | ||||
| from core.workflow.nodes.base.node import Node | from core.workflow.nodes.base.node import Node | ||||
| from core.workflow.nodes.base.template import Template | |||||
| from extensions.ext_database import db | from extensions.ext_database import db | ||||
| from models.dataset import Dataset, Document, DocumentSegment | from models.dataset import Dataset, Document, DocumentSegment | ||||
| class KnowledgeIndexNode(Node): | class KnowledgeIndexNode(Node): | ||||
| _node_data: KnowledgeIndexNodeData | _node_data: KnowledgeIndexNodeData | ||||
| node_type = NodeType.KNOWLEDGE_INDEX | node_type = NodeType.KNOWLEDGE_INDEX | ||||
| execution_type = NodeExecutionType.RESPONSE | |||||
| def init_node_data(self, data: Mapping[str, Any]) -> None: | def init_node_data(self, data: Mapping[str, Any]) -> None: | ||||
| self._node_data = KnowledgeIndexNodeData.model_validate(data) | self._node_data = KnowledgeIndexNodeData.model_validate(data) | ||||
| @classmethod | @classmethod | ||||
| def version(cls) -> str: | def version(cls) -> str: | ||||
| return "1" | return "1" | ||||
| def get_streaming_template(self) -> Template: | |||||
| """ | |||||
| Get the template for streaming. | |||||
| Returns: | |||||
| Template instance for this knowledge index node | |||||
| """ | |||||
| return Template(segments=[]) |
| session.commit() | session.commit() | ||||
| return workflow_node_execution_db_model | return workflow_node_execution_db_model | ||||
| def get_recommended_plugins(self) -> list[dict]: | |||||
| def get_recommended_plugins(self) -> dict: | |||||
| # Query active recommended plugins | # Query active recommended plugins | ||||
| pipeline_recommended_plugins = ( | pipeline_recommended_plugins = ( | ||||
| db.session.query(PipelineRecommendedPlugin) | db.session.query(PipelineRecommendedPlugin) | ||||
| ) | ) | ||||
| if not pipeline_recommended_plugins: | if not pipeline_recommended_plugins: | ||||
| return [] | |||||
| return { | |||||
| "installed_recommended_plugins": [], | |||||
| "uninstalled_recommended_plugins": [], | |||||
| } | |||||
| # Batch fetch plugin manifests | # Batch fetch plugin manifests | ||||
| plugin_ids = [plugin.plugin_id for plugin in pipeline_recommended_plugins] | plugin_ids = [plugin.plugin_id for plugin in pipeline_recommended_plugins] | ||||
| providers = BuiltinToolManageService.list_builtin_tools( | |||||
| user_id=current_user.id, | |||||
| tenant_id=current_user.current_tenant_id, | |||||
| ) | |||||
| providers_map = {provider.plugin_id: provider for provider in providers} | |||||
| plugin_manifests = marketplace.batch_fetch_plugin_manifests(plugin_ids) | plugin_manifests = marketplace.batch_fetch_plugin_manifests(plugin_ids) | ||||
| builtin_tools = BuiltinToolManageService.list_builtin_tools( | |||||
| user_id=current_user.id, | |||||
| tenant_id=current_user.current_tenant_id, | |||||
| ) | |||||
| installed_plugin_ids = {tool.plugin_id for tool in builtin_tools} | |||||
| plugin_manifests_map = {manifest.plugin_id: manifest for manifest in plugin_manifests} | |||||
| installed_plugin_list = [] | |||||
| uninstalled_plugin_list = [] | |||||
| for plugin_id in plugin_ids: | |||||
| if providers_map.get(plugin_id): | |||||
| installed_plugin_list.append(providers_map.get(plugin_id)) | |||||
| else: | |||||
| plugin_manifest = plugin_manifests_map.get(plugin_id) | |||||
| if plugin_manifest: | |||||
| uninstalled_plugin_list.append({ | |||||
| "plugin_id": plugin_id, | |||||
| "name": plugin_manifest.name, | |||||
| "icon": plugin_manifest.icon, | |||||
| "plugin_unique_identifier": plugin_manifest.latest_package_identifier, | |||||
| }) | |||||
| # Build recommended plugins list | # Build recommended plugins list | ||||
| return [ | |||||
| { | |||||
| "plugin_id": manifest.plugin_id, | |||||
| "name": manifest.name, | |||||
| "icon": manifest.icon, | |||||
| "plugin_unique_identifier": manifest.latest_package_identifier, | |||||
| "installed": manifest.plugin_id in installed_plugin_ids, | |||||
| } | |||||
| for manifest in plugin_manifests | |||||
| ] | |||||
| return { | |||||
| "installed_recommended_plugins": installed_plugin_list, | |||||
| "uninstalled_recommended_plugins": uninstalled_plugin_list, | |||||
| } |