"""Quality workflow tools supplement the existing capability contracts.""" from copy import deepcopy from .agent_tools import CONTROL_TOOLS, build_capability_tools from .claims import claim_schema def function(name, description, properties, required=()): return {"type": "function", "name": name, "description": description, "strict": False, "parameters": {"type": "object", "properties": properties, "required": list(required), "additionalProperties": False}} def quality_tools(registry): parameters = {"type": "array", "maxItems": 100, "items": {"type": "object", "properties": { "name": {"type": "string"}, "value": {"anyOf": [{"type": "number"}, {"type": "string"}, {"type": "array", "items": {"type": "number"}}, {"type": "null"}], "description": "实际采用值:尺寸填数值,方向填字符串(如 Y),位置填坐标数组;只有 unresolved 可为 null"}, "unit": {"type": "string"}, "source": {"type": "string", "enum": ["explicit", "assumed", "unresolved"]}, "evidence": {"type": "string"}, "requirement_ids": {"type": "array", "items": {"type": "string"}}}, "required": ["name", "value", "source", "evidence"], "additionalProperties": False}} result = build_capability_tools(registry) for tool in result: tool["strict"] = False tool["parameters"]["additionalProperties"] = False tool["parameters"]["properties"]["target"]["type"] = ["string", "null"] capability_tools = result result = [] for original in CONTROL_TOOLS: if original["name"] == "finish": continue tool = deepcopy(original) tool["strict"] = False if tool["name"] == "render_snapshot": tool["parameters"]["properties"]["view"]["enum"] += ["back", "bottom", "left", "right"] result.append(tool) result.extend([ function("report_constraint_conflict", "当原始资料与冻结尺寸作用对象冲突时,回查来源;不会按候选放宽原始要求。", {}, []), function("record_parameters", "记录当前建模采用的参数来源;按 name 更新,并传给独立核对。只记录事实,不能改变冻结要求。", {"parameters": parameters}, ["parameters"]), function("get_reference_images", "获取用户原图和已下载参考图纸的编号、来源页码及像素尺寸,用于定位局部尺寸及引出线", {}), function("crop_reference", "从原始图纸按像素裁切局部并查看,保留来源映射;裁切图也会交给独立核对。", { "image_index": {"type": "integer"}, "box": {"type": "array", "items": {"type": "integer"}, "minItems": 4, "maxItems": 4, "description": "原图像素 [left, top, right, bottom],保留尺寸引出线端点"}, }, ["image_index", "box"]), function("get_model", "获取当前完整操作序列,用于修改历史参数后整体重建", {}), function("revise_model", "只修改已存在操作的参数或target依赖;宿主从原始操作序列原子重放,成功才替换,失败保留整个旧模型。无需重抄未改动操作。", { "updates": {"type":"array", "minItems":1,"maxItems":32,"items":{"type":"object","properties":{ "id":{"type":"string"},"params":{"type":"object"},"target":{"type":["string","null"]}},"required":["id"],"additionalProperties":False}}, }, ["updates"]), function("rebuild_model", "执行完整操作序列,全部成功才替换当前会话。下游从头重算,失败保留原模型。", { "operations": {"type": "array", "items": {"type": "object", "properties": { "op": {"type": "string"}, "id": {"type": "string"}, "target": {"type": ["string", "null"]}, "params": {"type": "object"}}, "required": ["op", "id", "target", "params"], "additionalProperties": False}}, }, ["operations"]), function("inspect_geometry", "测量实体包络、圆柱面、平面切口、锥面倒角宽度/角度、Z轴螺旋导程/旋向和牙侧角,以及材料点。include_edges可取边索引用于局部倒角。", { "radial_sections": {"type":"object","properties":{ "origin":{"type":"array","minItems":3,"maxItems":3,"items":{"type":"number"}}, "axis":{"type":"array","minItems":3,"maxItems":3,"items":{"type":"number"}}, "offsets":{"type":"array","minItems":1,"maxItems":12,"items":{"type":"number"}}}, "required":["origin","axis","offsets"],"additionalProperties":False, "description":"实际实体垂直轴截面,返回外轮廓半径、齿状峰数及相位,以及低半径齿根区域的接点切向跳变和BRep曲率。offsets沿axis距origin的毫米距离;选择避开轮毂/支架的齿部。不可证明压力角或啮合;相位按齿距取模,需多截面避免混叠。配置保存并在提交时重新实测。"}, "include_edges": {"type": "boolean", "description": "需要按边索引局部倒角时才设true;几何变化后索引必须重新获取"}, "id": {"type": "string"}, "points": {"type": "array", "items": {"type": "array", "items": {"type": "number"}, "minItems": 3, "maxItems": 3}}, }, ["id"]), function("submit_stage", "提交当前阶段候选;宿主运行冻结尺寸检查及独立多视图评审,失败后继续修复。", { "parameters": parameters, "output_id": {"type": "string"}, "expected_solid_count": {"type": "integer"}, "claims": claim_schema(), }, ["output_id"]), ]) variants = [] for tool in capability_tools: schema = deepcopy(tool["parameters"]) schema["properties"].pop("id", None) schema["properties"].pop("target", None) schema["required"] = [key for key in schema.get("required", []) if key not in ("id", "target")] variants.append({"type": "object", "description": tool["description"], "properties": { "op": {"type": "string", "enum": [tool["name"][3:]]}, "id": {"type": "string"}, "target": {"type": ["string", "null"]}, "params": schema}, "required": ["op", "id", "target", "params"], "additionalProperties": False}) submission = next(t for t in result if t["name"] == "submit_stage")["parameters"]["properties"] result.insert(0, function("execute_batch", "批量执行一个阶段,逐步验证并保存。append 保留成功前缀;rebuild 全部成功才替换旧模型。带 output_id 自动提交当前阶段独立核对。", { "operations": {"type": "array", "minItems": 1, "maxItems": 80, "items": {"anyOf": variants}}, "mode": {"type": "string", "enum": ["append", "rebuild"]}, **deepcopy(submission)}, ["operations", "mode"])) return result