mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-10-01 08:10:13 +03:00
fix(typing): resolve mypy errors in agent.gns3_copilot.gns3_client.api_handlers
This commit is contained in:
parent
9882eba088
commit
bc27c4814f
@ -162,14 +162,14 @@ def build_gns3_ctx(jwt_token: str | None = None, url: str | None = None) -> dict
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _filter_node_response(node: dict, fields: list[str] = None) -> dict:
|
def _filter_node_response(node: dict, fields: list[str] | None = None) -> dict:
|
||||||
"""Filter node response to only include requested fields."""
|
"""Filter node response to only include requested fields."""
|
||||||
if not fields:
|
if not fields:
|
||||||
fields = ["node_id", "name", "node_type", "status", "console"]
|
fields = ["node_id", "name", "node_type", "status", "console"]
|
||||||
return {k: node[k] for k in fields if k in node}
|
return {k: node[k] for k in fields if k in node}
|
||||||
|
|
||||||
|
|
||||||
def _filter_link_response(link: dict, fields: list[str] = None) -> dict:
|
def _filter_link_response(link: dict, fields: list[str] | None = None) -> dict:
|
||||||
"""Filter link response to only include requested fields."""
|
"""Filter link response to only include requested fields."""
|
||||||
if not fields:
|
if not fields:
|
||||||
fields = LINK_DEFAULT_FIELDS
|
fields = LINK_DEFAULT_FIELDS
|
||||||
@ -332,7 +332,7 @@ def suspend_node_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> di
|
|||||||
return {"message": f"Node {node_id} suspended", "node_id": node_id}
|
return {"message": f"Node {node_id} suspended", "node_id": node_id}
|
||||||
|
|
||||||
|
|
||||||
def create_node_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dict[str, Any]:
|
def create_node_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dict[str, Any] | list[dict[str, Any]]:
|
||||||
|
|
||||||
project_id = params.get("project_id")
|
project_id = params.get("project_id")
|
||||||
if not project_id:
|
if not project_id:
|
||||||
@ -401,7 +401,7 @@ def create_node_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dic
|
|||||||
return _filter_node_response(resp, fields)
|
return _filter_node_response(resp, fields)
|
||||||
|
|
||||||
|
|
||||||
def delete_node_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dict[str, Any]:
|
def delete_node_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dict[str, Any] | list[dict[str, Any]]:
|
||||||
project_id = params.get("project_id")
|
project_id = params.get("project_id")
|
||||||
if not project_id:
|
if not project_id:
|
||||||
return {"error": "project_id is required"}
|
return {"error": "project_id is required"}
|
||||||
@ -706,7 +706,7 @@ def available_filters_handler(params: dict[str, Any], gns3_ctx: dict[str, Any])
|
|||||||
return conn.http_call("get", url).json()
|
return conn.http_call("get", url).json()
|
||||||
|
|
||||||
|
|
||||||
def create_link_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dict[str, Any]:
|
def create_link_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dict[str, Any] | list[dict[str, Any]]:
|
||||||
project_id = params.get("project_id")
|
project_id = params.get("project_id")
|
||||||
if not project_id:
|
if not project_id:
|
||||||
return {"error": "project_id is required"}
|
return {"error": "project_id is required"}
|
||||||
@ -762,7 +762,7 @@ def create_link_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dic
|
|||||||
return _filter_link_response(resp, fields)
|
return _filter_link_response(resp, fields)
|
||||||
|
|
||||||
|
|
||||||
def delete_link_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dict[str, Any]:
|
def delete_link_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dict[str, Any] | list[dict[str, Any]]:
|
||||||
project_id = params.get("project_id")
|
project_id = params.get("project_id")
|
||||||
if not project_id:
|
if not project_id:
|
||||||
return {"error": "project_id is required"}
|
return {"error": "project_id is required"}
|
||||||
@ -809,7 +809,7 @@ def update_link_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dic
|
|||||||
# ── Link capture / reset handlers ──────────────────────────────────────
|
# ── Link capture / reset handlers ──────────────────────────────────────
|
||||||
|
|
||||||
|
|
||||||
def reset_link_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dict[str, Any]:
|
def reset_link_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dict[str, Any] | list[dict[str, Any]]:
|
||||||
project_id = params.get("project_id")
|
project_id = params.get("project_id")
|
||||||
if not project_id:
|
if not project_id:
|
||||||
return {"error": "project_id is required"}
|
return {"error": "project_id is required"}
|
||||||
|
|||||||
@ -222,6 +222,8 @@ class GNS3LinkTool(BaseTool):
|
|||||||
},
|
},
|
||||||
gns3_ctx,
|
gns3_ctx,
|
||||||
)
|
)
|
||||||
|
if isinstance(link_resp, list):
|
||||||
|
raise RuntimeError("Unexpected batch response when creating a single link")
|
||||||
if "error" in link_resp:
|
if "error" in link_resp:
|
||||||
raise RuntimeError(link_resp["error"])
|
raise RuntimeError(link_resp["error"])
|
||||||
|
|
||||||
|
|||||||
@ -230,6 +230,8 @@ class GNS3CreateNodeTool(BaseTool):
|
|||||||
},
|
},
|
||||||
gns3_ctx,
|
gns3_ctx,
|
||||||
)
|
)
|
||||||
|
if isinstance(created, list):
|
||||||
|
raise RuntimeError("Unexpected batch response when creating a single node")
|
||||||
if "error" in created:
|
if "error" in created:
|
||||||
raise RuntimeError(created["error"])
|
raise RuntimeError(created["error"])
|
||||||
node_info = {
|
node_info = {
|
||||||
|
|||||||
@ -296,7 +296,6 @@ enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
|
|||||||
module = [
|
module = [
|
||||||
"gns3server.agent.gns3_copilot.agent.context_manager", # 5
|
"gns3server.agent.gns3_copilot.agent.context_manager", # 5
|
||||||
"gns3server.agent.gns3_copilot.agent.model_factory", # 4
|
"gns3server.agent.gns3_copilot.agent.model_factory", # 4
|
||||||
"gns3server.agent.gns3_copilot.gns3_client.api_handlers", # 10
|
|
||||||
"gns3server.agent.gns3_copilot.gns3_client.connector_factory", # 1
|
"gns3server.agent.gns3_copilot.gns3_client.connector_factory", # 1
|
||||||
"gns3server.agent.gns3_copilot.gns3_client.project_inventory", # 2
|
"gns3server.agent.gns3_copilot.gns3_client.project_inventory", # 2
|
||||||
"gns3server.agent.gns3_copilot.skills.loader", # 1
|
"gns3server.agent.gns3_copilot.skills.loader", # 1
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user