瀏覽代碼

fix: types

Yeuoly 8 月之前
父節點
當前提交
113ff27d07

+ 40 - 3
api/controllers/console/app/workflow.py

@@ -20,6 +20,7 @@ from fields.workflow_run_fields import workflow_run_node_execution_fields
 from libs import helper
 from libs.helper import TimestampField, uuid_value
 from libs.login import current_user, login_required
+from models.account import Account
 from models.model import App, AppMode
 from services.app_dsl_service import AppDslService
 from services.app_generate_service import AppGenerateService
@@ -97,6 +98,9 @@ class DraftWorkflowApi(Resource):
         else:
             abort(415)
 
+        if not isinstance(current_user, Account):
+            raise Forbidden()
+
         workflow_service = WorkflowService()
 
         try:
@@ -136,6 +140,9 @@ class DraftWorkflowImportApi(Resource):
         # The role of the current user in the ta table must be admin, owner, or editor
         if not current_user.is_editor:
             raise Forbidden()
+        
+        if not isinstance(current_user, Account):
+            raise Forbidden()
 
         parser = reqparse.RequestParser()
         parser.add_argument("data", type=str, required=True, nullable=False, location="json")
@@ -160,6 +167,9 @@ class AdvancedChatDraftWorkflowRunApi(Resource):
         # The role of the current user in the ta table must be admin, owner, or editor
         if not current_user.is_editor:
             raise Forbidden()
+        
+        if not isinstance(current_user, Account):
+            raise Forbidden()
 
         parser = reqparse.RequestParser()
         parser.add_argument("inputs", type=dict, location="json")
@@ -197,6 +207,9 @@ class AdvancedChatDraftRunIterationNodeApi(Resource):
         # The role of the current user in the ta table must be admin, owner, or editor
         if not current_user.is_editor:
             raise Forbidden()
+        
+        if not isinstance(current_user, Account):
+            raise Forbidden()
 
         parser = reqparse.RequestParser()
         parser.add_argument("inputs", type=dict, location="json")
@@ -231,6 +244,9 @@ class WorkflowDraftRunIterationNodeApi(Resource):
         # The role of the current user in the ta table must be admin, owner, or editor
         if not current_user.is_editor:
             raise Forbidden()
+        
+        if not isinstance(current_user, Account):
+            raise Forbidden()
 
         parser = reqparse.RequestParser()
         parser.add_argument("inputs", type=dict, location="json")
@@ -265,6 +281,9 @@ class DraftWorkflowRunApi(Resource):
         # The role of the current user in the ta table must be admin, owner, or editor
         if not current_user.is_editor:
             raise Forbidden()
+        
+        if not isinstance(current_user, Account):
+            raise Forbidden()
 
         parser = reqparse.RequestParser()
         parser.add_argument("inputs", type=dict, required=True, nullable=False, location="json")
@@ -315,14 +334,21 @@ class DraftWorkflowNodeRunApi(Resource):
         # The role of the current user in the ta table must be admin, owner, or editor
         if not current_user.is_editor:
             raise Forbidden()
+        
+        if not isinstance(current_user, Account):
+            raise Forbidden()
 
         parser = reqparse.RequestParser()
         parser.add_argument("inputs", type=dict, required=True, nullable=False, location="json")
         args = parser.parse_args()
 
+        inputs = args.get("inputs")
+        if inputs == None:
+            raise ValueError("missing inputs")
+
         workflow_service = WorkflowService()
         workflow_node_execution = workflow_service.run_draft_workflow_node(
-            app_model=app_model, node_id=node_id, user_inputs=args.get("inputs"), account=current_user
+            app_model=app_model, node_id=node_id, user_inputs=inputs, account=current_user
         )
 
         return workflow_node_execution
@@ -360,6 +386,9 @@ class PublishedWorkflowApi(Resource):
         # The role of the current user in the ta table must be admin, owner, or editor
         if not current_user.is_editor:
             raise Forbidden()
+        
+        if not isinstance(current_user, Account):
+            raise Forbidden()
 
         workflow_service = WorkflowService()
         workflow = workflow_service.publish_workflow(app_model=app_model, account=current_user)
@@ -397,15 +426,20 @@ class DefaultBlockConfigApi(Resource):
         # The role of the current user in the ta table must be admin, owner, or editor
         if not current_user.is_editor:
             raise Forbidden()
+        
+        if not isinstance(current_user, Account):
+            raise Forbidden()
 
         parser = reqparse.RequestParser()
         parser.add_argument("q", type=str, location="args")
         args = parser.parse_args()
 
+        q = args.get("q")
+
         filters = None
-        if args.get("q"):
+        if q:
             try:
-                filters = json.loads(args.get("q"))
+                filters = json.loads(q)
             except json.JSONDecodeError:
                 raise ValueError("Invalid filters")
 
@@ -428,6 +462,9 @@ class ConvertToWorkflowApi(Resource):
         # The role of the current user in the ta table must be admin, owner, or editor
         if not current_user.is_editor:
             raise Forbidden()
+        
+        if not isinstance(current_user, Account):
+            raise Forbidden()
 
         if request.data:
             parser = reqparse.RequestParser()

+ 1 - 1
api/controllers/console/app/wraps.py

@@ -8,7 +8,7 @@ from libs.login import current_user
 from models.model import App, AppMode
 
 
-def get_app_model(view: Optional[Callable] = None, *, mode: Union[AppMode, list[AppMode]] = None):
+def get_app_model(view: Optional[Callable] = None, *, mode: Union[AppMode, list[AppMode], None] = None):
     def decorator(view_func):
         @wraps(view_func)
         def decorated_view(*args, **kwargs):

+ 2 - 2
api/controllers/inner_api/plugin/plugin.py

@@ -7,7 +7,7 @@ from controllers.console.setup import setup_required
 from controllers.inner_api import api
 from controllers.inner_api.plugin.wraps import get_tenant, plugin_data
 from controllers.inner_api.wraps import plugin_inner_api_only
-from core.plugin.backwards_invocation.model import PluginBackwardsInvocation
+from core.plugin.backwards_invocation.model import PluginModelBackwardsInvocation
 from core.plugin.entities.request import (
     RequestInvokeLLM,
     RequestInvokeModeration,
@@ -29,7 +29,7 @@ class PluginInvokeLLMApi(Resource):
     @plugin_data(payload_type=RequestInvokeLLM)
     def post(self, user_id: str, tenant_model: Tenant, payload: RequestInvokeLLM):
         def generator():
-            response = PluginBackwardsInvocation.invoke_llm(user_id, tenant_model, payload)
+            response = PluginModelBackwardsInvocation.invoke_llm(user_id, tenant_model, payload)
             if isinstance(response, Generator):
                 for chunk in response:
                     yield chunk.model_dump_json().encode() + b'\n\n'

+ 1 - 1
api/core/app/apps/base_app_generator.py

@@ -1,5 +1,5 @@
-from collections.abc import Generator, Mapping
 import json
+from collections.abc import Generator, Mapping
 from typing import Any, Optional, Union
 
 from core.app.app_config.entities import AppConfig, VariableEntity, VariableEntityType