refactor: replace bare dict with dict[str, Any] in core tools and runtime (#35111)

This commit is contained in:
wdeveloper16 2026-04-14 05:03:13 +02:00 committed by GitHub
parent eeebedcfe8
commit 0f643bca76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 19 additions and 16 deletions

View File

@ -735,7 +735,9 @@ class IndexingRunner:
@staticmethod @staticmethod
def _update_document_index_status( def _update_document_index_status(
document_id: str, after_indexing_status: IndexingStatus, extra_update_params: dict | None = None document_id: str,
after_indexing_status: IndexingStatus,
extra_update_params: dict[Any, Any] | None = None,
): ):
""" """
Update the document indexing status. Update the document indexing status.
@ -762,7 +764,7 @@ class IndexingRunner:
db.session.commit() db.session.commit()
@staticmethod @staticmethod
def _update_segments_by_document(dataset_document_id: str, update_params: dict): def _update_segments_by_document(dataset_document_id: str, update_params: dict[Any, Any]):
""" """
Update the document segment by document id. Update the document segment by document id.
""" """

View File

@ -200,7 +200,7 @@ def _handle_native_json_schema(
provider: str, provider: str,
model_schema: AIModelEntity, model_schema: AIModelEntity,
structured_output_schema: Mapping, structured_output_schema: Mapping,
model_parameters: dict, model_parameters: dict[str, Any],
rules: list[ParameterRule], rules: list[ParameterRule],
): ):
""" """
@ -224,7 +224,7 @@ def _handle_native_json_schema(
return model_parameters return model_parameters
def _set_response_format(model_parameters: dict, rules: list): def _set_response_format(model_parameters: dict[str, Any], rules: list[ParameterRule]):
""" """
Set the appropriate response format parameter based on model rules. Set the appropriate response format parameter based on model rules.
@ -326,7 +326,7 @@ def _prepare_schema_for_model(provider: str, model_schema: AIModelEntity, schema
return {"schema": processed_schema, "name": "llm_response"} return {"schema": processed_schema, "name": "llm_response"}
def remove_additional_properties(schema: dict): def remove_additional_properties(schema: dict[str, Any]):
""" """
Remove additionalProperties fields from JSON schema. Remove additionalProperties fields from JSON schema.
Used for models like Gemini that don't support this property. Used for models like Gemini that don't support this property.

View File

@ -198,7 +198,7 @@ class Tool(ABC):
message=ToolInvokeMessage.TextMessage(text=text), message=ToolInvokeMessage.TextMessage(text=text),
) )
def create_blob_message(self, blob: bytes, meta: dict | None = None) -> ToolInvokeMessage: def create_blob_message(self, blob: bytes, meta: dict[str, Any] | None = None) -> ToolInvokeMessage:
""" """
create a blob message create a blob message
@ -212,7 +212,7 @@ class Tool(ABC):
meta=meta, meta=meta,
) )
def create_json_message(self, object: dict, suppress_output: bool = False) -> ToolInvokeMessage: def create_json_message(self, object: dict[str, Any], suppress_output: bool = False) -> ToolInvokeMessage:
""" """
create a json message create a json message
""" """

View File

@ -149,7 +149,7 @@ class ToolInvokeMessage(BaseModel):
text: str text: str
class JsonMessage(BaseModel): class JsonMessage(BaseModel):
json_object: dict | list json_object: dict[str, Any] | list[Any]
suppress_output: bool = Field(default=False, description="Whether to suppress JSON output in result string") suppress_output: bool = Field(default=False, description="Whether to suppress JSON output in result string")
class BlobMessage(BaseModel): class BlobMessage(BaseModel):
@ -337,7 +337,7 @@ class ToolParameter(PluginParameter):
form: ToolParameterForm = Field(..., description="The form of the parameter, schema/form/llm") form: ToolParameterForm = Field(..., description="The form of the parameter, schema/form/llm")
llm_description: str | None = None llm_description: str | None = None
# MCP object and array type parameters use this field to store the schema # MCP object and array type parameters use this field to store the schema
input_schema: dict | None = None input_schema: dict[str, Any] | None = None
@classmethod @classmethod
def get_simple_instance( def get_simple_instance(
@ -463,7 +463,7 @@ class ToolInvokeMeta(BaseModel):
time_cost: float = Field(..., description="The time cost of the tool invoke") time_cost: float = Field(..., description="The time cost of the tool invoke")
error: str | None = None error: str | None = None
tool_config: dict | None = None tool_config: dict[str, Any] | None = None
@classmethod @classmethod
def empty(cls) -> ToolInvokeMeta: def empty(cls) -> ToolInvokeMeta:

View File

@ -85,7 +85,8 @@ class ToolEngine:
invocation_meta_dict: dict[str, ToolInvokeMeta] = {} invocation_meta_dict: dict[str, ToolInvokeMeta] = {}
def message_callback( def message_callback(
invocation_meta_dict: dict, messages: Generator[ToolInvokeMessage | ToolInvokeMeta, None, None] invocation_meta_dict: dict[str, Any],
messages: Generator[ToolInvokeMessage | ToolInvokeMeta, None, None],
): ):
for message in messages: for message in messages:
if isinstance(message, ToolInvokeMeta): if isinstance(message, ToolInvokeMeta):
@ -200,7 +201,7 @@ class ToolEngine:
@staticmethod @staticmethod
def _invoke( def _invoke(
tool: Tool, tool: Tool,
tool_parameters: dict, tool_parameters: dict[str, Any],
user_id: str, user_id: str,
conversation_id: str | None = None, conversation_id: str | None = None,
app_id: str | None = None, app_id: str | None = None,

View File

@ -33,7 +33,7 @@ class DatasetRetrieverTool(Tool):
invoke_from: InvokeFrom, invoke_from: InvokeFrom,
hit_callback: DatasetIndexToolCallbackHandler, hit_callback: DatasetIndexToolCallbackHandler,
user_id: str, user_id: str,
inputs: dict, inputs: dict[str, Any],
) -> list["DatasetRetrieverTool"]: ) -> list["DatasetRetrieverTool"]:
""" """
get dataset tool get dataset tool

View File

@ -277,7 +277,7 @@ class WorkflowTool(Tool):
session.expunge(app) session.expunge(app)
return app return app
def _transform_args(self, tool_parameters: dict) -> tuple[dict, list[dict]]: def _transform_args(self, tool_parameters: dict[str, Any]) -> tuple[dict[str, Any], list[dict[str, Any]]]:
""" """
transform the tool parameters transform the tool parameters
@ -323,7 +323,7 @@ class WorkflowTool(Tool):
return parameters_result, files return parameters_result, files
def _extract_files(self, outputs: dict) -> tuple[dict, list[File]]: def _extract_files(self, outputs: dict[str, Any]) -> tuple[dict[str, Any], list[File]]:
""" """
extract files from the result extract files from the result
@ -355,7 +355,7 @@ class WorkflowTool(Tool):
return result, files return result, files
def _update_file_mapping(self, file_dict: dict): def _update_file_mapping(self, file_dict: dict[str, Any]):
file_id = resolve_file_record_id(file_dict.get("reference") or file_dict.get("related_id")) file_id = resolve_file_record_id(file_dict.get("reference") or file_dict.get("related_id"))
transfer_method = FileTransferMethod.value_of(file_dict.get("transfer_method")) transfer_method = FileTransferMethod.value_of(file_dict.get("transfer_method"))
match transfer_method: match transfer_method: