Forráskód Böngészése

fix: get tool runtime parameters

Yeuoly 7 hónapja%!(EXTRA string=óta)
szülő
commit
2f36692bf9

+ 4 - 3
api/core/plugin/manager/tool.py

@@ -164,11 +164,11 @@ class PluginToolManager(BasePluginManager):
             parameters: list[ToolParameter]
 
         response = self._request_with_plugin_daemon_response_stream(
-            "GET",
+            "POST",
             f"plugin/{tenant_id}/dispatch/tool/get_runtime_parameters",
             RuntimeParametersResponse,
-            params={
-                "user_id": user_id,
+            data={
+                "user_id": "user_id",
                 "data": {
                     "provider": provider_name,
                     "tool": tool,
@@ -177,6 +177,7 @@ class PluginToolManager(BasePluginManager):
             },
             headers={
                 "X-Plugin-ID": plugin_id,
+                "Content-Type": "application/json",
             },
         )
 

+ 9 - 2
api/core/tools/plugin_tool/tool.py

@@ -1,5 +1,5 @@
 from collections.abc import Generator
-from typing import Any
+from typing import Any, Optional
 
 from core.plugin.manager.tool import PluginToolManager
 from core.tools.__base.tool import Tool
@@ -9,10 +9,12 @@ from core.tools.entities.tool_entities import ToolEntity, ToolInvokeMessage, Too
 
 class PluginTool(Tool):
     tenant_id: str
+    runtime_parameters: Optional[list[ToolParameter]]
 
     def __init__(self, entity: ToolEntity, runtime: ToolRuntime, tenant_id: str) -> None:
         super().__init__(entity, runtime)
         self.tenant_id = tenant_id
+        self.runtime_parameters = None
 
     @property
     def tool_provider_type(self) -> ToolProviderType:
@@ -43,11 +45,16 @@ class PluginTool(Tool):
         if not self.entity.has_runtime_parameters:
             return self.entity.parameters
 
+        if self.runtime_parameters is not None:
+            return self.runtime_parameters
+
         manager = PluginToolManager()
-        return manager.get_runtime_parameters(
+        self.runtime_parameters = manager.get_runtime_parameters(
             tenant_id=self.tenant_id,
             user_id="",
             provider=self.entity.identity.provider,
             tool=self.entity.identity.name,
             credentials=self.runtime.credentials,
         )
+
+        return self.runtime_parameters

+ 6 - 6
api/core/tools/tool_manager.py

@@ -312,7 +312,7 @@ class ToolManager:
         """
         get the workflow tool runtime
         """
-        tool_entity = cls.get_tool_runtime(
+        tool_runtime = cls.get_tool_runtime(
             provider_type=workflow_tool.provider_type,
             provider_id=workflow_tool.provider_id,
             tool_name=workflow_tool.tool_name,
@@ -321,7 +321,7 @@ class ToolManager:
             tool_invoke_from=ToolInvokeFrom.WORKFLOW,
         )
         runtime_parameters = {}
-        parameters = tool_entity.get_merged_runtime_parameters()
+        parameters = tool_runtime.get_merged_runtime_parameters()
 
         for parameter in parameters:
             # save tool parameter to tool entity memory
@@ -332,7 +332,7 @@ class ToolManager:
         # decrypt runtime parameters
         encryption_manager = ToolParameterConfigurationManager(
             tenant_id=tenant_id,
-            tool_runtime=tool_entity,
+            tool_runtime=tool_runtime,
             provider_name=workflow_tool.provider_id,
             provider_type=workflow_tool.provider_type,
             identity_id=f"WORKFLOW.{app_id}.{node_id}",
@@ -341,11 +341,11 @@ class ToolManager:
         if runtime_parameters:
             runtime_parameters = encryption_manager.decrypt_tool_parameters(runtime_parameters)
 
-        if not tool_entity.runtime:
+        if not tool_runtime.runtime:
             raise Exception("tool missing runtime")
 
-        tool_entity.runtime.runtime_parameters.update(runtime_parameters)
-        return tool_entity
+        tool_runtime.runtime.runtime_parameters.update(runtime_parameters)
+        return tool_runtime
 
     @classmethod
     def get_builtin_provider_icon(cls, provider: str, tenant_id: str) -> tuple[str, str]:

+ 1 - 1
api/core/workflow/nodes/tool/tool_node.py

@@ -54,7 +54,7 @@ class ToolNode(BaseNode):
             return
 
         # get parameters
-        tool_parameters = tool_runtime.get_runtime_parameters() or []
+        tool_parameters = tool_runtime.get_merged_runtime_parameters() or []
         parameters = self._generate_parameters(
             tool_parameters=tool_parameters, variable_pool=self.graph_runtime_state.variable_pool, node_data=node_data
         )