stripe ros2 schema desc

add create-device-skill
This commit is contained in:
Xuwznln
2026-03-22 03:21:13 +08:00
parent 59c26265e9
commit 23c2e3b2f7
8 changed files with 629 additions and 92 deletions

View File

@@ -866,68 +866,40 @@ liquid_handler:
additionalProperties: false
properties:
category:
description: Field of type <rosidl_parser.definition.UnboundedString
object at 0x0000025304D2D2A0>
type: string
children:
description: Field of type <rosidl_parser.definition.UnboundedSequence
object at 0x0000025304D12EC0>
items:
description: Field of type <rosidl_parser.definition.UnboundedString
object at 0x0000025304D2C320>
type: string
type: array
config:
description: Field of type <rosidl_parser.definition.UnboundedString
object at 0x0000025304D2D2C0>
type: string
data:
description: Field of type <rosidl_parser.definition.UnboundedString
object at 0x0000025304D2D2E0>
type: string
id:
description: Field of type <rosidl_parser.definition.UnboundedString
object at 0x0000025304D2D280>
type: string
name:
description: Field of type <rosidl_parser.definition.UnboundedString
object at 0x0000025304D2D240>
type: string
parent:
description: Field of type <rosidl_parser.definition.UnboundedString
object at 0x0000025304D2CF80>
type: string
pose:
additionalProperties: false
description: Field of type <rosidl_parser.definition.NamespacedType
object at 0x0000025304D12EF0>
properties:
orientation:
additionalProperties: false
description: Field of type <rosidl_parser.definition.NamespacedType
object at 0x000002530511A080>
properties:
w:
description: Field of type <rosidl_parser.definition.BasicType
object at 0x0000025305138C70>
maximum: 1.7976931348623157e+308
minimum: -1.7976931348623157e+308
type: number
x:
description: Field of type <rosidl_parser.definition.BasicType
object at 0x0000025305138BE0>
maximum: 1.7976931348623157e+308
minimum: -1.7976931348623157e+308
type: number
y:
description: Field of type <rosidl_parser.definition.BasicType
object at 0x0000025305138C10>
maximum: 1.7976931348623157e+308
minimum: -1.7976931348623157e+308
type: number
z:
description: Field of type <rosidl_parser.definition.BasicType
object at 0x0000025305138C40>
maximum: 1.7976931348623157e+308
minimum: -1.7976931348623157e+308
type: number
@@ -940,24 +912,16 @@ liquid_handler:
type: object
position:
additionalProperties: false
description: Field of type <rosidl_parser.definition.NamespacedType
object at 0x000002530511A050>
properties:
x:
description: Field of type <rosidl_parser.definition.BasicType
object at 0x00000253050E7FD0>
maximum: 1.7976931348623157e+308
minimum: -1.7976931348623157e+308
type: number
y:
description: Field of type <rosidl_parser.definition.BasicType
object at 0x0000025305118040>
maximum: 1.7976931348623157e+308
minimum: -1.7976931348623157e+308
type: number
z:
description: Field of type <rosidl_parser.definition.BasicType
object at 0x0000025305118070>
maximum: 1.7976931348623157e+308
minimum: -1.7976931348623157e+308
type: number
@@ -973,12 +937,8 @@ liquid_handler:
title: pose
type: object
sample_id:
description: Field of type <rosidl_parser.definition.UnboundedString
object at 0x0000025304D2D220>
type: string
type:
description: Field of type <rosidl_parser.definition.UnboundedString
object at 0x0000025304D2CE20>
type: string
title: plate
type: object
@@ -9300,68 +9260,40 @@ liquid_handler.prcxi:
additionalProperties: false
properties:
category:
description: Field of type <rosidl_parser.definition.UnboundedString
object at 0x0000025304D2D2A0>
type: string
children:
description: Field of type <rosidl_parser.definition.UnboundedSequence
object at 0x0000025304D12EC0>
items:
description: Field of type <rosidl_parser.definition.UnboundedString
object at 0x0000025304D2C320>
type: string
type: array
config:
description: Field of type <rosidl_parser.definition.UnboundedString
object at 0x0000025304D2D2C0>
type: string
data:
description: Field of type <rosidl_parser.definition.UnboundedString
object at 0x0000025304D2D2E0>
type: string
id:
description: Field of type <rosidl_parser.definition.UnboundedString
object at 0x0000025304D2D280>
type: string
name:
description: Field of type <rosidl_parser.definition.UnboundedString
object at 0x0000025304D2D240>
type: string
parent:
description: Field of type <rosidl_parser.definition.UnboundedString
object at 0x0000025304D2CF80>
type: string
pose:
additionalProperties: false
description: Field of type <rosidl_parser.definition.NamespacedType
object at 0x0000025304D12EF0>
properties:
orientation:
additionalProperties: false
description: Field of type <rosidl_parser.definition.NamespacedType
object at 0x000002530511A080>
properties:
w:
description: Field of type <rosidl_parser.definition.BasicType
object at 0x0000025305138C70>
maximum: 1.7976931348623157e+308
minimum: -1.7976931348623157e+308
type: number
x:
description: Field of type <rosidl_parser.definition.BasicType
object at 0x0000025305138BE0>
maximum: 1.7976931348623157e+308
minimum: -1.7976931348623157e+308
type: number
y:
description: Field of type <rosidl_parser.definition.BasicType
object at 0x0000025305138C10>
maximum: 1.7976931348623157e+308
minimum: -1.7976931348623157e+308
type: number
z:
description: Field of type <rosidl_parser.definition.BasicType
object at 0x0000025305138C40>
maximum: 1.7976931348623157e+308
minimum: -1.7976931348623157e+308
type: number
@@ -9374,24 +9306,16 @@ liquid_handler.prcxi:
type: object
position:
additionalProperties: false
description: Field of type <rosidl_parser.definition.NamespacedType
object at 0x000002530511A050>
properties:
x:
description: Field of type <rosidl_parser.definition.BasicType
object at 0x00000253050E7FD0>
maximum: 1.7976931348623157e+308
minimum: -1.7976931348623157e+308
type: number
y:
description: Field of type <rosidl_parser.definition.BasicType
object at 0x0000025305118040>
maximum: 1.7976931348623157e+308
minimum: -1.7976931348623157e+308
type: number
z:
description: Field of type <rosidl_parser.definition.BasicType
object at 0x0000025305118070>
maximum: 1.7976931348623157e+308
minimum: -1.7976931348623157e+308
type: number
@@ -9407,12 +9331,8 @@ liquid_handler.prcxi:
title: pose
type: object
sample_id:
description: Field of type <rosidl_parser.definition.UnboundedString
object at 0x0000025304D2D220>
type: string
type:
description: Field of type <rosidl_parser.definition.UnboundedString
object at 0x0000025304D2CE20>
type: string
title: plate
type: object

View File

@@ -47,7 +47,6 @@ from unilabos.registry.utils import (
normalize_ast_action_handles,
wrap_action_schema,
preserve_field_descriptions,
strip_ros_descriptions,
resolve_method_params_via_import,
SIMPLE_TYPE_MAP,
)
@@ -501,12 +500,17 @@ class Registry:
json_type = SIMPLE_TYPE_MAP.get(param_type.lower())
if json_type:
prop_schema["type"] = json_type
elif ":" in param_type:
type_obj = resolve_type_object(param_type)
if type_obj is not None:
prop_schema = type_to_schema(type_obj)
else:
prop_schema["type"] = "object"
elif import_map and param_type in import_map:
type_obj = resolve_type_object(import_map[param_type])
if type_obj is not None:
prop_schema = type_to_schema(type_obj)
else:
# 无法 import 的自定义类型,默认当 object 处理(与 YAML runtime 路径一致)
prop_schema["type"] = "object"
else:
json_type = get_json_schema_type(param_type)
@@ -914,7 +918,6 @@ class Registry:
logger.debug(f"[AST] device action '{action_name}': Result enrichment failed: {e}")
try:
schema = ros_action_to_json_schema(action_type_obj)
strip_ros_descriptions(schema)
except Exception:
pass
# 直接从 ROS2 Goal 实例获取默认值 (msgcenterpy)
@@ -1826,7 +1829,6 @@ class Registry:
pass
try:
entry_schema = ros_action_to_json_schema(action_type_obj)
strip_ros_descriptions(entry_schema)
if old_schema:
preserve_field_descriptions(entry_schema, old_schema)
if "description" in old_schema:
@@ -1914,7 +1916,6 @@ class Registry:
action_config["goal_default"] = {}
prev_schema = action_config.get("schema", {})
action_config["schema"] = ros_action_to_json_schema(target_type)
strip_ros_descriptions(action_config["schema"])
if prev_schema:
preserve_field_descriptions(action_config["schema"], prev_schema)
if "description" in prev_schema:

View File

@@ -717,6 +717,19 @@ def ros_field_type_to_json_schema(
# return {'type': 'object', 'description': f'未知类型: {field_type}'}
def _strip_rosidl_descriptions(schema: Any) -> None:
"""递归清除 rosidl_parser 自动生成的无意义 description含内存地址"""
if isinstance(schema, dict):
desc = schema.get("description", "")
if isinstance(desc, str) and "rosidl_parser" in desc:
del schema["description"]
for v in schema.values():
_strip_rosidl_descriptions(v)
elif isinstance(schema, list):
for item in schema:
_strip_rosidl_descriptions(item)
def ros_message_to_json_schema(msg_class: Any, field_name: str) -> Dict[str, Any]:
"""
将 ROS 消息类转换为 JSON Schema
@@ -730,7 +743,8 @@ def ros_message_to_json_schema(msg_class: Any, field_name: str) -> Dict[str, Any
"""
schema = ROS2MessageInstance(msg_class()).get_json_schema()
schema["title"] = field_name
schema.pop("description")
schema.pop("description", None)
_strip_rosidl_descriptions(schema)
return schema
@@ -777,6 +791,8 @@ def ros_action_to_json_schema(
"required": ["goal"],
}
_strip_rosidl_descriptions(schema)
# 保留之前 schema 中 goal/feedback/result 下一级字段的 description
if previous_schema:
_preserve_field_descriptions(schema, previous_schema)

View File

@@ -1884,7 +1884,8 @@ class BaseROS2DeviceNode(Node, Generic[T]):
continue
# 处理单个 ResourceSlot
if arg_type == "unilabos.registry.placeholder_type:ResourceSlot":
_is_resource_slot = isinstance(arg_type, str) and arg_type.endswith(":ResourceSlot")
if _is_resource_slot:
resource_data = function_args[arg_name]
if isinstance(resource_data, dict) and "id" in resource_data:
try:
@@ -1898,8 +1899,7 @@ class BaseROS2DeviceNode(Node, Generic[T]):
# 处理 ResourceSlot 列表
elif isinstance(arg_type, tuple) and len(arg_type) == 2:
resource_slot_type = "unilabos.registry.placeholder_type:ResourceSlot"
if arg_type[0] == "list" and arg_type[1] == resource_slot_type:
if arg_type[0] == "list" and isinstance(arg_type[1], str) and arg_type[1].endswith(":ResourceSlot"):
resource_list = function_args[arg_name]
if isinstance(resource_list, list):
try:

View File

@@ -325,10 +325,11 @@ class ImportManager:
return self._get_type_string(signature.return_annotation)
def _get_type_string(self, annotation) -> Union[str, Tuple[str, Any]]:
"""将类型注解转换为短类名(与 AST _get_annotation_str 对齐)
"""将类型注解转换为类型字符串
自定义类只返回短名(如 ``"SetLiquidReturn"``),完整路径由
``import_map`` 负责解析,保持与 AST 分析一致。
非内建类返回 ``module:ClassName`` 全路径(如
``"unilabos.registry.placeholder_type:ResourceSlot"``
避免短名冲突;内建类型直接返回短名(如 ``"str"``、``"int"``)。
"""
if annotation == inspect.Parameter.empty:
return "Any"
@@ -358,6 +359,9 @@ class ImportManager:
else annotation._name.lower()
)
if hasattr(annotation, "__name__"):
module = getattr(annotation, "__module__", None)
if module and module != "builtins":
return f"{module}:{annotation.__name__}"
return annotation.__name__
elif hasattr(annotation, "_name"):
return annotation._name