@forgent3d/cad-runtime 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,7 +9,7 @@ This package is intentionally runtime-light:
9
9
  - no React
10
10
  - no database clients
11
11
 
12
- `cad-agent` and `cf-sandbox` can both depend on this package without coupling their deploy targets together.
12
+ `@forgent3d/cloud` and `cf-sandbox` can both depend on this package without coupling their deploy targets together.
13
13
 
14
14
  ## Python Runtime Assets
15
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forgent3d/cad-runtime",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Shared CAD runtime protocol, types, and pure utilities for Forgent3D cloud services.",
5
5
  "license": "MIT",
6
6
  "author": "Forgent3D",
@@ -30,6 +30,58 @@ MODELS_DIR = os.path.join(PROJECT_ROOT, "models")
30
30
  CACHE_DIR = os.path.join(PROJECT_ROOT, ".cache")
31
31
  MODEL_KINDS = ("part",)
32
32
 
33
+ # Sentinel-prefixed line emitted on stdout when --emit-build-json is passed, so a
34
+ # caller can read the build summary (bbox/anchors/hasResult) from this single run
35
+ # instead of a separate aicad-script build pass. Keep in sync with cf-sandbox rebuild.ts.
36
+ BUILD_JSON_SENTINEL = "@@AICAD_BUILD_JSON@@"
37
+
38
+
39
+ def _emit_build_json(payload) -> None:
40
+ print(BUILD_JSON_SENTINEL + json.dumps(payload, ensure_ascii=False, separators=(",", ":")))
41
+
42
+
43
+ def _bbox_summary(shape):
44
+ if shape is None or not hasattr(shape, "bounding_box"):
45
+ return None
46
+ try:
47
+ bb = shape.bounding_box()
48
+ return {
49
+ "min": [float(bb.min.X), float(bb.min.Y), float(bb.min.Z)],
50
+ "max": [float(bb.max.X), float(bb.max.Y), float(bb.max.Z)],
51
+ "size": [
52
+ float(bb.max.X - bb.min.X),
53
+ float(bb.max.Y - bb.min.Y),
54
+ float(bb.max.Z - bb.min.Z),
55
+ ],
56
+ }
57
+ except Exception:
58
+ return None
59
+
60
+
61
+ def _build_summary_payload(model_name, part_name, source_path, ns, result):
62
+ metadata = ns.get("metadata") if isinstance(ns, dict) else None
63
+ anchors = None
64
+ metadata_keys = []
65
+ if isinstance(metadata, dict):
66
+ metadata_keys = sorted(str(k) for k in metadata.keys())
67
+ if isinstance(metadata.get("anchors"), dict):
68
+ try:
69
+ anchors = _json_safe(metadata.get("anchors"))
70
+ except Exception:
71
+ anchors = None
72
+ return {
73
+ "ok": result is not None,
74
+ "script": "build",
75
+ "model": model_name,
76
+ "part": part_name,
77
+ "source": os.path.relpath(source_path, PROJECT_ROOT).replace(os.sep, "/") if source_path else None,
78
+ "resultType": type(result).__name__ if result is not None else None,
79
+ "hasResult": result is not None,
80
+ "bbox": _bbox_summary(result),
81
+ "metadataKeys": metadata_keys,
82
+ "metadataAnchors": anchors,
83
+ }
84
+
33
85
 
34
86
  def _looks_like_build123d(obj) -> bool:
35
87
  return any(c.__module__.startswith("build123d") for c in type(obj).__mro__)
@@ -552,7 +604,7 @@ def _build_namespace(model_name: str, part_name: str, source_override: str = Non
552
604
  return ns, source_path, 0
553
605
 
554
606
 
555
- def build_one(model_name: str, part_name: str = None, export_format: str = "brep", output: str = None, source_override: str = None) -> int:
607
+ def build_one(model_name: str, part_name: str = None, export_format: str = "brep", output: str = None, source_override: str = None, emit_build_json: bool = False) -> int:
556
608
  part_name = part_name or model_name
557
609
  build_started = time.perf_counter()
558
610
  ns, source_path, err = _build_namespace(model_name, part_name, source_override)
@@ -566,6 +618,8 @@ def build_one(model_name: str, part_name: str = None, export_format: str = "brep
566
618
  if candidate is not None:
567
619
  result = candidate
568
620
  if result is None:
621
+ if emit_build_json:
622
+ _emit_build_json(_build_summary_payload(model_name, part_name, source_path, ns, None))
569
623
  print(f"[export_runner] {source_path} must define a global result (or assembly) object (build123d).",
570
624
  file=sys.stderr)
571
625
  return 4
@@ -575,6 +629,8 @@ def build_one(model_name: str, part_name: str = None, export_format: str = "brep
575
629
  except Exception as exc:
576
630
  print(f"[export_runner] Failed to write metadata.json: {exc}", file=sys.stderr)
577
631
  return 8
632
+ if emit_build_json:
633
+ _emit_build_json(_build_summary_payload(model_name, part_name, source_path, ns, result))
578
634
 
579
635
  fmt = (export_format or "brep").strip().lower()
580
636
  if fmt not in ("brep", "step", "stl", "obj", "glb", "3mf"):
@@ -625,6 +681,8 @@ def main() -> int:
625
681
  parser.add_argument("--source", default=None, help="Optional project-relative or absolute source file path (overrides default lookup)")
626
682
  parser.add_argument("--export-format", default="brep", choices=["brep", "step", "stl", "obj", "glb", "3mf"])
627
683
  parser.add_argument("--output", default=None, help="Optional absolute path for exported file")
684
+ parser.add_argument("--emit-build-json", action="store_true",
685
+ help="Emit a sentinel-prefixed build-summary JSON line on stdout (cloud rebuild fast path)")
628
686
  args = parser.parse_args()
629
687
  global PROJECT_ROOT, MODELS_DIR, CACHE_DIR
630
688
  PROJECT_ROOT = os.path.abspath(args.project) if args.project else HERE
@@ -633,7 +691,7 @@ def main() -> int:
633
691
  model_name = args.model or args.part
634
692
  if not model_name:
635
693
  parser.error("one of --model / --part is required")
636
- return build_one(model_name, args.part_name or model_name, args.export_format, args.output, args.source)
694
+ return build_one(model_name, args.part_name or model_name, args.export_format, args.output, args.source, args.emit_build_json)
637
695
 
638
696
 
639
697
  if __name__ == "__main__":