@rainbow-robotics/muscat-plugin-kit 1.3.6-dev.8 → 1.3.7

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.
Files changed (125) hide show
  1. package/cli/README.md +8 -3
  2. package/cli/bin/muscat-pk.mjs +5 -0
  3. package/cli/bundle-templates.mjs +6 -1
  4. package/cli/docker/Dockerfile.cpp +28 -6
  5. package/cli/docker/Dockerfile.dev +32 -0
  6. package/cli/docker/Dockerfile.python +19 -0
  7. package/cli/src/bridge.mjs +45 -12
  8. package/cli/src/build.mjs +48 -79
  9. package/cli/src/cpp.mjs +11 -5
  10. package/cli/src/dev.mjs +7 -2
  11. package/cli/src/devBack.mjs +97 -40
  12. package/cli/src/host_agent.py +143 -83
  13. package/cli/src/manifest.mjs +11 -0
  14. package/cli/src/mcp.mjs +398 -54
  15. package/cli/src/new.mjs +13 -3
  16. package/cli/src/ports.mjs +21 -7
  17. package/cli/src/python.mjs +16 -20
  18. package/cli/src/ros2.mjs +16 -8
  19. package/cli/src/sdk.mjs +23 -21
  20. package/cli/src/type.mjs +44 -10
  21. package/cli/src/uninstall.mjs +3 -20
  22. package/cli/src/update.mjs +14 -8
  23. package/cli/src/util.mjs +70 -9
  24. package/cli/storybook-dist/_stories-src/RBDatePicker/RBRangeDateInput.stories.tsx +13 -1
  25. package/cli/storybook-dist/_stories-src/RBInput/RBSelectBox.stories.tsx +98 -1
  26. package/cli/storybook-dist/assets/{Color-YHDXOIA2-Du8dJ-nM.js → Color-YHDXOIA2-CdTgUqrV.js} +1 -1
  27. package/cli/storybook-dist/assets/{Docs-Sy5RDbtH.js → Docs-C8wx5zsC.js} +1 -1
  28. package/cli/storybook-dist/assets/{Docs-guGflRzZ.js → Docs-CbRKwHpQ.js} +1 -1
  29. package/cli/storybook-dist/assets/{Docs-Cb72AJnj.js → Docs-Cf0s04QW.js} +1 -1
  30. package/cli/storybook-dist/assets/{Docs-pwGqGTV_.js → Docs-CsxMprX5.js} +1 -1
  31. package/cli/storybook-dist/assets/{Docs-LdjYwuG4.js → Docs-FyPFrbUS.js} +1 -1
  32. package/cli/storybook-dist/assets/{Docs--Fm8069p.js → Docs-YtqU-aVu.js} +1 -1
  33. package/cli/storybook-dist/assets/{DocsRenderer-CFRXHY34-YGBLQ4BD.js → DocsRenderer-CFRXHY34-VSENNRoY.js} +1 -1
  34. package/cli/storybook-dist/assets/{NxAvatar.stories-C1d4n8cq.js → NxAvatar.stories-oCcYtLwq.js} +1 -1
  35. package/cli/storybook-dist/assets/{NxButton.stories-gCBoZdMq.js → NxButton.stories-C5jUScIj.js} +1 -1
  36. package/cli/storybook-dist/assets/{NxIcons.stories-Dg42riT5.js → NxIcons.stories-DeqrVzVs.js} +1 -1
  37. package/cli/storybook-dist/assets/{NxNumberInput.stories-DB-vLM2J.js → NxNumberInput.stories-gjsEulIN.js} +1 -1
  38. package/cli/storybook-dist/assets/{NxPagination.stories-CS8iMIak.js → NxPagination.stories-BK6uSWIa.js} +1 -1
  39. package/cli/storybook-dist/assets/{NxPointerHoldButton.stories-D66BopeS.js → NxPointerHoldButton.stories-BDD5CvSZ.js} +1 -1
  40. package/cli/storybook-dist/assets/{NxRangeInput.stories-CZxddsJ2.js → NxRangeInput.stories-C_nW26_x.js} +3 -3
  41. package/cli/storybook-dist/assets/{NxSelectBox.stories-CmezGGrm.js → NxSelectBox.stories-DqLfKU9H.js} +1 -1
  42. package/cli/storybook-dist/assets/{NxSlideRange.stories-CGAFMITi.js → NxSlideRange.stories-CQjHA8yv.js} +1 -1
  43. package/cli/storybook-dist/assets/{NxSwitch.stories-B3QInkXX.js → NxSwitch.stories-BMHCiPoL.js} +1 -1
  44. package/cli/storybook-dist/assets/{NxTextArea.stories-BgJcgZNe.js → NxTextArea.stories-k7r1WVQh.js} +1 -1
  45. package/cli/storybook-dist/assets/{NxTextInput.stories-CwMQwI9L.js → NxTextInput.stories-Cqfe1I32.js} +1 -1
  46. package/cli/storybook-dist/assets/{RBAccordion.stories-BuBVNzJT.js → RBAccordion.stories-CJ3Ttuja.js} +1 -1
  47. package/cli/storybook-dist/assets/{RBAccordionGroup.stories-Crdb6kFF.js → RBAccordionGroup.stories-BThv7tM0.js} +1 -1
  48. package/cli/storybook-dist/assets/{RBAlert.stories-CqXgUvA2.js → RBAlert.stories-CSMP8Vun.js} +1 -1
  49. package/cli/storybook-dist/assets/{RBBadge.stories-BCw_ksML.js → RBBadge.stories-cBMA2R6F.js} +1 -1
  50. package/cli/storybook-dist/assets/{RBBattery.stories-0id4XYoc.js → RBBattery.stories-BKVOskqs.js} +1 -1
  51. package/cli/storybook-dist/assets/{RBCard.stories-CgpG-7Lk.js → RBCard.stories-BTOfK0HC.js} +1 -1
  52. package/cli/storybook-dist/assets/{RBCheckBox.stories-BG02BoGX.js → RBCheckBox.stories-DyE912wG.js} +1 -1
  53. package/cli/storybook-dist/assets/{RBCheckIconButton.stories-vrjD4GQ4.js → RBCheckIconButton.stories-0sLFU0kM.js} +1 -1
  54. package/cli/storybook-dist/assets/{RBCheckLabelButton.stories-POba8lU-.js → RBCheckLabelButton.stories-c8VecClE.js} +1 -1
  55. package/cli/storybook-dist/assets/{RBChipTab.stories-XWJbFrHF.js → RBChipTab.stories-CQ9Uav5_.js} +1 -1
  56. package/cli/storybook-dist/assets/{RBChipsBoxTab.stories-BdU0Dzdp.js → RBChipsBoxTab.stories-Ap4NlhAZ.js} +1 -1
  57. package/cli/storybook-dist/assets/{RBColorIcons.stories-C_0dCNXG.js → RBColorIcons.stories-BPPXjif2.js} +1 -1
  58. package/cli/storybook-dist/assets/{RBCommand.stories-Dvrko5No.js → RBCommand.stories-PDpYOKlm.js} +1 -1
  59. package/cli/storybook-dist/assets/{RBConfirm.stories-CkTn0sHa.js → RBConfirm.stories-BEWvMAYP.js} +1 -1
  60. package/cli/storybook-dist/assets/{RBDateInput.stories-BH3D08cs.js → RBDateInput.stories-DLdyNnVF.js} +1 -1
  61. package/cli/storybook-dist/assets/{RBDialog.stories-C2nNX9fl.js → RBDialog.stories-HsawMNOb.js} +1 -1
  62. package/cli/storybook-dist/assets/{RBDivider.stories-D-GrJ0QZ.js → RBDivider.stories-dlWwOxik.js} +1 -1
  63. package/cli/storybook-dist/assets/{RBDrawer.stories-XLOnLOnh.js → RBDrawer.stories-C87iqGk0.js} +1 -1
  64. package/cli/storybook-dist/assets/{RBDropdownMenu.stories-BjBSeoV2.js → RBDropdownMenu.stories-B8EQhA0z.js} +1 -1
  65. package/cli/storybook-dist/assets/{RBEmptyView.stories-C6U2zKNE.js → RBEmptyView.stories-SzpIhNDw.js} +1 -1
  66. package/cli/storybook-dist/assets/{RBIconButton.stories-MCJq5Hta.js → RBIconButton.stories-BQ0nM1gb.js} +1 -1
  67. package/cli/storybook-dist/assets/{RBIcons.stories-DxOCiCe0.js → RBIcons.stories-C19g5M5z.js} +1 -1
  68. package/cli/storybook-dist/assets/{RBInlineLabelButton.stories-BVZi1aEs.js → RBInlineLabelButton.stories-DbgI4-1P.js} +1 -1
  69. package/cli/storybook-dist/assets/{RBJoyStick.stories-BDThbEek.js → RBJoyStick.stories-smF-vpGL.js} +1 -1
  70. package/cli/storybook-dist/assets/{RBLabelButton.stories-CaPEKUS6.js → RBLabelButton.stories-s53klwDv.js} +1 -1
  71. package/cli/storybook-dist/assets/{RBLight.stories-CihQzyEL.js → RBLight.stories-BnzkoR51.js} +1 -1
  72. package/cli/storybook-dist/assets/{RBMenubar.stories-J852XVFh.js → RBMenubar.stories-CW014klu.js} +1 -1
  73. package/cli/storybook-dist/assets/{RBMultiRangeInput.stories-DXyX0cOZ.js → RBMultiRangeInput.stories-qa4tH_4Y.js} +1 -1
  74. package/cli/storybook-dist/assets/{RBPagination.stories-C9_49ymO.js → RBPagination.stories-YoQNUpQH.js} +1 -1
  75. package/cli/storybook-dist/assets/{RBPopover.stories-DxLE912-.js → RBPopover.stories-Bhpi0OaH.js} +1 -1
  76. package/cli/storybook-dist/assets/{RBPrompt.stories-DlsfGqWb.js → RBPrompt.stories-iQM5iAka.js} +1 -1
  77. package/cli/storybook-dist/assets/{RBRadioBox.stories-hb5cNWW1.js → RBRadioBox.stories-BGyq4rzx.js} +1 -1
  78. package/cli/storybook-dist/assets/{RBRadioButton.stories-CSuOgeN-.js → RBRadioButton.stories-DF6BcUcJ.js} +1 -1
  79. package/cli/storybook-dist/assets/RBRangeDateInput.stories-COOQ_HNF.js +15 -0
  80. package/cli/storybook-dist/assets/{RBResizable.stories-BetjF9vG.js → RBResizable.stories-DSVHvwjp.js} +1 -1
  81. package/cli/storybook-dist/assets/RBSelectBox.stories-BookV8Sm.js +74 -0
  82. package/cli/storybook-dist/assets/{RBSheet.stories-D3QbcMKq.js → RBSheet.stories-CAK9hb-p.js} +1 -1
  83. package/cli/storybook-dist/assets/{RBSideNumberInput.stories-DcTh0IjM.js → RBSideNumberInput.stories-DUymnH-9.js} +1 -1
  84. package/cli/storybook-dist/assets/{RBSlider.stories-B59We7ei.js → RBSlider.stories-BwlDh9--.js} +1 -1
  85. package/cli/storybook-dist/assets/{RBSpinner.stories-9u3_ETbi.js → RBSpinner.stories-VOlkuP6t.js} +1 -1
  86. package/cli/storybook-dist/assets/{RBSwitch.stories-DrVm1WGX.js → RBSwitch.stories-BiW2dQnT.js} +1 -1
  87. package/cli/storybook-dist/assets/{RBTab.stories-D8Dm7cRW.js → RBTab.stories-DFKVsy0C.js} +1 -1
  88. package/cli/storybook-dist/assets/{RBTable.stories-dRdZ8g1j.js → RBTable.stories-BWG0ZSYI.js} +1 -1
  89. package/cli/storybook-dist/assets/{RBTableRow.stories-rZeoGwHZ.js → RBTableRow.stories-JVTD83Mh.js} +1 -1
  90. package/cli/storybook-dist/assets/{RBTabs.stories-STRV2lgO.js → RBTabs.stories-D-aN385u.js} +1 -1
  91. package/cli/storybook-dist/assets/{RBTextArea.stories-CfgUbrbJ.js → RBTextArea.stories-Dx5xkmZS.js} +1 -1
  92. package/cli/storybook-dist/assets/{RBTextField.stories-B5t8-Y97.js → RBTextField.stories-DmVciExd.js} +1 -1
  93. package/cli/storybook-dist/assets/{RBTextInput.stories-Bf1edN6l.js → RBTextInput.stories-CCf0VGEv.js} +1 -1
  94. package/cli/storybook-dist/assets/{RBToast.stories-Cnm8JwQ6.js → RBToast.stories-DT0DGn05.js} +1 -1
  95. package/cli/storybook-dist/assets/{RBToggle.stories-B0OCo6zd.js → RBToggle.stories-Ce_q3EtP.js} +1 -1
  96. package/cli/storybook-dist/assets/{RBToggleGroup.stories-GdYO2Fxg.js → RBToggleGroup.stories-CN40YHsR.js} +1 -1
  97. package/cli/storybook-dist/assets/{RBTooltip.stories-DXJTCScO.js → RBTooltip.stories-L7btDEpA.js} +1 -1
  98. package/cli/storybook-dist/assets/SideNumberInput-B5_xLK8z.js +1109 -0
  99. package/cli/storybook-dist/assets/browserUtils-CQM9Za7e.js +1 -0
  100. package/cli/storybook-dist/assets/{entry-preview-DSRwIaVJ.js → entry-preview-raBQdKjS.js} +1 -1
  101. package/cli/storybook-dist/assets/{iframe-Cj53Wn3d.js → iframe-BmIue__l.js} +2 -2
  102. package/cli/storybook-dist/assets/{index-CkHtLEe8.js → index-CSIe-YDr.js} +3 -3
  103. package/cli/storybook-dist/assets/{index-C1OzuK6-.js → index-ClAc6FBW.js} +1 -1
  104. package/cli/storybook-dist/assets/{preview-CILRoSnB.js → preview-BVJwlGUF.js} +1 -1
  105. package/cli/storybook-dist/assets/{preview-D_2um8Sd.js → preview-CUgthyJT.js} +1 -1
  106. package/cli/storybook-dist/assets/{preview-CgOtgtCD.js → preview-DD51RTKv.js} +2 -2
  107. package/cli/storybook-dist/assets/preview-zuAvMksL.css +1 -0
  108. package/cli/storybook-dist/assets/react-resizable-panels.browser-CYcsrUgg.js +120 -0
  109. package/cli/storybook-dist/iframe.html +1 -1
  110. package/cli/storybook-dist/index.json +1 -1
  111. package/cli/storybook-dist/project.json +1 -1
  112. package/cli/templates/common/README.md +211 -7
  113. package/cli/templates/common/py/main.py +29 -2
  114. package/cli/templates/cpp/cpp/CMakeLists.txt +6 -7
  115. package/cli/templates/cpp/cpp/main.cpp +57 -10
  116. package/cli/templates/readme-cpp/README.md +993 -0
  117. package/cli/templates/ros2-cpp/ros2_ws/src/__PLUGIN_SLUG__/CMakeLists.txt +4 -0
  118. package/cli/templates/ros2-cpp/ros2_ws/src/__PLUGIN_SLUG__/src/node.cpp +5 -4
  119. package/package.json +3 -3
  120. package/cli/storybook-dist/assets/RBRangeDateInput.stories-KRg2glX8.js +0 -15
  121. package/cli/storybook-dist/assets/RBSelectBox.stories-ILLQQ8M8.js +0 -6
  122. package/cli/storybook-dist/assets/SideNumberInput-CrF-a1Nr.js +0 -1114
  123. package/cli/storybook-dist/assets/browserUtils-CxJ5gea3.js +0 -1
  124. package/cli/storybook-dist/assets/preview-CEfMaO1t.css +0 -1
  125. package/cli/storybook-dist/assets/react-resizable-panels.browser-CtORL3tG.js +0 -102
@@ -398,6 +398,103 @@ if __name__ == "__main__":
398
398
  time.sleep(1)
399
399
  ```
400
400
 
401
+ #### External endpoints (`plugin.router`)
402
+
403
+ `plugin.serve` / `plugin.subscribe` / `plugin.publish` are **internal only** (plugin
404
+ UI ↔ backend, plugin ↔ plugin). To expose an endpoint to the outside world —
405
+ REST, Socket.IO, TCP, MQTT, WebRTC — use `plugin.router`. Declaring one is a
406
+ single decorator; the running Muscat (`common`) picks it up without a restart,
407
+ and it disappears when the plugin stops or is removed.
408
+
409
+ > Requires a robot running `rainbow-rb-sdk` **0.0.9.dev5 or newer** (the SDK is
410
+ > provided by the plugin container at runtime). On older robots `plugin.router`
411
+ > does not exist and raises `AttributeError`.
412
+
413
+ ```python
414
+ from rainbow.rb_sdk import RBPluginCall
415
+ from rainbow.rb_sdk.plugin import PluginRouteError
416
+
417
+ plugin = RBPluginCall() # plugin_id comes from env RB_PLUGIN_ID
418
+
419
+
420
+ @plugin.router.on("/hello") # all 5 transports
421
+ def hello(payload: dict, meta: dict):
422
+ return {"msg": f"hi {payload.get('name')}"} # return value = response body
423
+
424
+
425
+ @plugin.router.on("/admin", explicit_routes=["api"]) # REST only
426
+ def admin(payload, meta):
427
+ if not (meta.get("principal") or {}).get("is_admin"):
428
+ raise PluginRouteError(403, "admin only") # becomes the external status
429
+ ...
430
+
431
+
432
+ @plugin.router.subscribe("/cmd", explicit_events=["tcp"]) # receive external TCP publish
433
+ def on_cmd(payload: dict):
434
+ ...
435
+
436
+
437
+ plugin.router.emit("/state", {"busy": True}) # push to external subscribers
438
+ ```
439
+
440
+ | API | Meaning | External address |
441
+ | --- | --- | --- |
442
+ | `router.on(path, explicit_routes=None)` | request/response handler | `common/plugin/{plugin_id}/{path}` (REST is always `POST`) |
443
+ | `router.subscribe(topic, explicit_events=None)` | receive external publishes | external side publishes to `common/plugin/{plugin_id}/{topic}` |
444
+ | `router.emit(topic, payload)` | plugin → external push | external side subscribes to `common/plugin/{plugin_id}/{topic}` |
445
+
446
+ - The `plugin_id` prefix is added by the SDK — write only the path in plugin code.
447
+ - Paths may have several segments (`/tool/echo`). Declaring the same path twice raises `ValueError`.
448
+ - Transport names: `api | socket | tcp | mqtt | webrtc`. `subscribe` accepts only `tcp | mqtt | webrtc`. Unknown names raise `ValueError`.
449
+ - `explicit_routes` / `explicit_events` of `None` means every transport. A request on a transport not listed gets 404.
450
+
451
+ Handler contract:
452
+
453
+ - Signature `(payload, meta)`, `(payload)` or `()` — only the arguments you declare are injected. Sync and async both work.
454
+ - `payload`: what the caller sent (for REST: JSON body merged with query params). The shape is up to the plugin.
455
+ - `meta`: `{"transport": "api"|"socket"|"tcp"|"mqtt"|"webrtc", "principal": dict | None}`. When the robot's login policy is on, `principal` holds the token subject. **Role checks are the plugin's job** — inspect `meta["principal"]` yourself.
456
+ - The return value is the response body (must be JSON-serialisable). `None` → empty response.
457
+ - Status codes: `raise PluginRouteError(code, message)`. Any other exception → 500 with `str(exc)` as the message.
458
+ - `subscribe` handlers take `(payload)` only and return nothing.
459
+
460
+ #### Calling plugin endpoints from outside
461
+
462
+ | Transport | How |
463
+ | --- | --- |
464
+ | REST | `POST /common/plugin/{plugin_id}/{path}` (through the api-gateway), JSON body |
465
+ | Socket.IO | emit event `common/plugin/{plugin_id}/{path}`, response arrives in the ack |
466
+ | TCP | topic `common/plugin/{plugin_id}/{path}` request / publish |
467
+ | MQTT | request: `common/plugin/{plugin_id}/{path}/__req__`, publish: `common/plugin/{plugin_id}/{topic}` |
468
+ | WebRTC | data channel topic `common/plugin/{plugin_id}/{path}` |
469
+
470
+ Auth: when the robot's login policy is on, a token is **required** (any role — GUEST passes). When it is off, calls go straight through. REST uses the same Bearer token as the other Muscat APIs.
471
+
472
+ ```bash
473
+ curl -s -X POST http://<robot>/common/plugin/my-plugin/hello \
474
+ -H 'Content-Type: application/json' -d '{"name":"kim"}'
475
+ ```
476
+
477
+ | Situation | Status |
478
+ | --- | --- |
479
+ | No plugin declares that path / plugin is down / transport not allowed | 404 |
480
+ | Plugin did not answer within 10 s | 504 |
481
+ | `common` ↔ gateway not connected | 503 |
482
+ | Handler raised | 500 (`PluginRouteError` → its `code`) |
483
+
484
+ Known limits:
485
+
486
+ - A plugin path named `install` cannot be called over REST (`POST /common/plugin/{id}/install` is taken by the registry install route first). Socket/TCP are unaffected.
487
+ - Swagger shows one catch-all route, not per-plugin paths.
488
+ - The MQTT broker echoes to the sender: a plugin that `emit`s and `subscribe`s the same topic receives its own push over `mqtt`. Drop `mqtt` from `explicit_events` or use separate topics. (TCP is filtered by `sender_id`.)
489
+ - `on` and `subscribe` may share a name — they live in separate tables.
490
+
491
+ During `muscat-pk dev` / `dev:back` the local bridge (port `10000`) accepts the
492
+ `router.*` registrations, but **external calls need a running `common`** — it is
493
+ `common` that routes `common/plugin/...` to the gateway. Use a robot (or a local
494
+ `common`) to exercise the external addresses. After restarting the plugin process,
495
+ external calls may return 504 for up to about a minute (until the gateway notices
496
+ the old socket is gone), then 404 — that is expected.
497
+
401
498
  #### Program command backend (`program.panel`)
402
499
 
403
500
  A `program.panel` contribution defines a **custom command** your plugin adds to
@@ -637,9 +734,8 @@ below).
637
734
 
638
735
  ### C++
639
736
 
640
- C++ plugins use `cpp/` and are built with CMake inside Docker. The current C++
641
- template is a build/run skeleton; wire it to the plugin gateway when the C++ SDK
642
- is available.
737
+ C++ plugins use `cpp/` and are built with CMake inside Docker against the
738
+ Rainbow Robotics C++ SDK (see _C++ SDK_ below).
643
739
 
644
740
  ```cpp
645
741
  #include <chrono>
@@ -661,10 +757,31 @@ int main() {
661
757
  }
662
758
  ```
663
759
 
760
+ #### C++ SDK (`rainbow-rb-sdk-dev`)
761
+
762
+ Both C++ runtimes (`cpp`, `ros2` + `rclcpp`) link the Rainbow Robotics C++ SDK
763
+ from the apt package `rainbow-rb-sdk-dev`. The `muscat-pk` dev containers already
764
+ have it, so `muscat-pk dev` / `build` need nothing extra. To build outside the
765
+ container (your own Ubuntu 24.04 machine, or the robot PC):
766
+
767
+ ```bash
768
+ curl -fsSL https://rainbowrobotics.github.io/rb-sdk/rb-sdk-apt-repo.gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/rb-sdk-apt.gpg
769
+ echo 'deb [signed-by=/usr/share/keyrings/rb-sdk-apt.gpg] https://rainbowrobotics.github.io/rb-sdk stable main' | sudo tee /etc/apt/sources.list.d/rb-sdk.list
770
+ sudo apt update && sudo apt install rainbow-rb-sdk-dev
771
+ ```
772
+
773
+ - CMake: `find_package(rb_sdk REQUIRED)` + `target_link_libraries(<target> rb_sdk::rb_sdk)` (C++20). pkg-config: `rb_sdk`.
774
+ - Headers: `<rainbow/rb_sdk/manipulate/rb_manipulate_sdk.hpp>` (`RBManipulateSDK`),
775
+ `<rainbow/rb_sdk/program/plugin_program_context.hpp>` (`rb_plugin::PluginProgramContext`, for `program.panel` commands — the header's top comment has a full `main()` example).
776
+ - The binary is linked **dynamically**; `muscat-pk build` copies the matching `librb_sdk.so` into `dist/<arch>/lib/` (the robot has no SDK installed), so each plugin keeps the SDK version it was built with. Change the version with `MUSCAT_PK_RB_SDK_VERSION=<version> MUSCAT_PK_REBUILD_IMAGE=1 muscat-pk dev`.
777
+ - UI ↔ backend messaging works from C++ too: `rb_plugin::RBPluginCall` in `<rainbow/rb_sdk/plugin/rb_plugin.hpp>` (see the scaffolded `cpp/main.cpp`).
778
+
664
779
  ### ROS2 (rclpy)
665
780
 
666
- ROS2 Python plugins use `ros2_ws/` with `runtime.rosClient: "rclpy"`. The node
667
- is launched with `--ros-args -r __ns:=/{slug}` automatically by `dev:back`.
781
+ ROS2 Python plugins use `ros2_ws/` with `runtime.rosClient: "rclpy"`. relative topic names are placed under the plugin's ROS namespace — the plugin id
782
+ with "." → "/" and "-" → "_" (`com.example.my-plugin` → `/com/example/my_plugin`), in dev
783
+ and on the robot. Use an absolute name (`/cmd_vel`) for topics shared with other nodes.
784
+ `RBPluginCall` works in the node module too (UI messaging and `plugin.router`).
668
785
 
669
786
  ```python
670
787
  # ros2_ws/src/__PLUGIN_SLUG__/__PLUGIN_SLUG__/node.py
@@ -682,9 +799,29 @@ class __PLUGIN_CLASS__Node(Node):
682
799
  # use sdk alongside ROS2 publishers/subscribers/services as needed
683
800
  ```
684
801
 
802
+
803
+ #### Talking to an external PC over ROS 2
804
+
805
+ ROS 2 discovery stays on the robot (`ROS_AUTOMATIC_DISCOVERY_RANGE=LOCALHOST`; `muscat-pk dev`
806
+ runs the same), so robots on one LAN don't mix topics. Allow specific PCs from the plugin UI —
807
+ Muscat keeps the list per plugin, starts your backend with `ROS_STATIC_PEERS` set to it, and
808
+ restarts the plugin when it changes. Your ROS code needs no changes; the PC needs no extra settings.
809
+
810
+ ```tsx
811
+ const rb = useRb();
812
+ const peers = await rb.rosPeers.get(); // ["192.168.0.50"]
813
+ await rb.rosPeers.set(["192.168.0.50", "192.168.0.51"]); // saves + restarts the plugin; rejects on a bad IP
814
+ ```
815
+
816
+ - Per plugin: plugin B keeps its allowed PCs when plugin A (allowing the same PC) is stopped or removed.
817
+ - It opens communication; it is not access control — a PC that knows the robot's IP can still
818
+ add the robot to its own `ROS_STATIC_PEERS`.
819
+ - In `muscat-pk dev` the list is kept in `.muscat-dev/ros-peers.json` (ROS 2 backends).
820
+
685
821
  ### ROS2 (rclcpp)
686
822
 
687
- ROS2 C++ plugins use `ros2_ws/` with `runtime.rosClient: "rclcpp"`.
823
+ ROS2 C++ plugins use `ros2_ws/` with `runtime.rosClient: "rclcpp"`. The node links
824
+ the Rainbow C++ SDK the same way as the `cpp` runtime (see _C++ SDK_ above).
688
825
 
689
826
  ```cpp
690
827
  #include "rclcpp/rclcpp.hpp"
@@ -699,6 +836,65 @@ public:
699
836
 
700
837
  ---
701
838
 
839
+ ## Video streaming (MediaMTX)
840
+
841
+ Muscat runs a MediaMTX media server. The backend publishes a stream over RTSP and
842
+ the UI plays it over WebRTC. `muscat-pk dev` runs the same server (or uses a local
843
+ Muscat's), so the addresses are identical in dev and on the robot.
844
+
845
+ | | Address |
846
+ | --- | --- |
847
+ | Publish (backend) | `rtsp://127.0.0.1:8554/<plugin_id>/<name>` |
848
+ | Play (UI) | `http://<host>:8889/<plugin_id>/<name>/` |
849
+
850
+ - Prefix the path with your plugin id — paths are shared with robot cameras and other plugins.
851
+ - The robot runtime has no ffmpeg, GStreamer or OpenCV; bring your own encoder (below).
852
+
853
+ **Backend (Python)** — use PyAV: add `av` and `numpy` to `requirements.txt`. Its wheels
854
+ include FFmpeg, so they ship in the ZIP like any other dependency.
855
+
856
+ ```python
857
+ import fractions, time
858
+ import av, numpy as np
859
+
860
+ out = av.open("rtsp://127.0.0.1:8554/__PLUGIN_ID__/cam", mode="w", format="rtsp",
861
+ options={"rtsp_transport": "tcp"})
862
+ stream = out.add_stream("libx264", rate=25, options={"preset": "ultrafast", "tune": "zerolatency"})
863
+ stream.width, stream.height, stream.pix_fmt = 640, 360, "yuv420p"
864
+
865
+ i = 0
866
+ while True:
867
+ img = np.zeros((360, 640, 3), dtype=np.uint8) # your RGB frame here
868
+ frame = av.VideoFrame.from_ndarray(img, format="rgb24")
869
+ frame.pts, frame.time_base = i, fractions.Fraction(1, 25)
870
+ for packet in stream.encode(frame):
871
+ out.mux(packet)
872
+ i += 1
873
+ time.sleep(1 / 25)
874
+ ```
875
+
876
+ Run the encoder loop in a thread (or `asyncio.to_thread`) so it doesn't block the
877
+ `RBPluginCall` handlers.
878
+
879
+ **UI** — embed MediaMTX's WebRTC player. `location.hostname` is `localhost` in the
880
+ preview and the robot's address on the robot:
881
+
882
+ ```tsx
883
+ const STREAM = "__PLUGIN_ID__/cam"; // the path the backend publishes
884
+
885
+ export default function Camera() {
886
+ return (
887
+ <iframe
888
+ src={`${location.protocol}//${location.hostname}:8889/${STREAM}/`}
889
+ allow="autoplay"
890
+ className="aspect-video w-full border-0"
891
+ />
892
+ );
893
+ }
894
+ ```
895
+
896
+ ---
897
+
702
898
  ## manifest.json
703
899
 
704
900
  ```jsonc
@@ -927,6 +1123,8 @@ muscat-pk type change --to python # → Python
927
1123
 
928
1124
  > Existing backend dirs (`ros2_ws/`, `cpp/`) are not deleted when switching away. Remove them manually if no longer needed.
929
1125
 
1126
+ > Switching between a Python and a C++ backend asks whether to replace this README with the matching one (the old file is kept as `README.md.bak`). Add `--readme` to answer yes without the prompt.
1127
+
930
1128
  ---
931
1129
 
932
1130
  ## AI coding assistants (MCP)
@@ -943,7 +1141,9 @@ letting it guess. `muscat-pk mcp` is an MCP server exposing:
943
1141
  - `search_rb_sdk` — how to use `useRb()`, `rb.*`, `useRbFormData`/`useRbSave`, and
944
1142
  the backend runtimes.
945
1143
  - `list_rb_sdk` / `get_rb_sdk_api` — the installed `rainbow-rb-sdk` (Python
946
- backend) classes and signatures.
1144
+ backend) classes and signatures; with `lang: "cpp"`, the C++ SDK headers
1145
+ (`rainbow-rb-sdk-dev`, read out of the `muscat-pk` cpp dev image — build it
1146
+ once with `muscat-pk dev:back`).
947
1147
 
948
1148
  **Browse the components live** with `muscat-pk storybook`.
949
1149
 
@@ -991,6 +1191,10 @@ muscat-pk build # build + ZIP
991
1191
  muscat-pk build --no-zip # build only, no ZIP
992
1192
  ```
993
1193
 
1194
+ > Building the other arch (e.g. arm64 on an amd64 PC) runs in an emulated container for
1195
+ > C++ backends. Docker Desktop has it built in; on Linux enable it once with
1196
+ > `docker run --privileged --rm tonistiigi/binfmt --install all`, or pass `--arch` for one arch.
1197
+
994
1198
  - Builds `ui/content.tsx` → `dist/content.js` (minified)
995
1199
  - Pins `requirements.txt` to latest versions (stable-only on `main` branch)
996
1200
  - Copies `assets/`, `manifest.json`, `README*.md`, `py/`, and `requirements.txt` into `dist/`
@@ -10,6 +10,13 @@ Remote dev (from your laptop):
10
10
  MUSCAT_ROBOT_HOST=192.168.1.100
11
11
  MUSCAT_ROBOT_TOKEN=<service token>
12
12
  Then: muscat-pk dev:back
13
+
14
+ Handlers:
15
+ plugin.serve / plugin.subscribe / plugin.publish -> plugin UI <-> backend only
16
+ plugin.router.on / subscribe / emit -> external endpoints
17
+ (REST / Socket.IO / TCP / MQTT / WebRTC at common/plugin/<plugin_id>/<path>).
18
+ Needs a robot running rainbow-rb-sdk >= 0.0.9.dev5; older robots have no
19
+ `plugin.router` (AttributeError). See README "External endpoints".
13
20
  """
14
21
 
15
22
  import asyncio
@@ -17,6 +24,7 @@ import os
17
24
  from typing import Any
18
25
 
19
26
  from rainbow.rb_sdk import RBManipulateSDK, RBPluginCall
27
+ from rainbow.rb_sdk.rb_sdk_cpp import ConnectOptions
20
28
 
21
29
 
22
30
  PLUGIN_NAME = "__PLUGIN_NAME__"
@@ -29,6 +37,8 @@ def register_handlers():
29
37
  # Register handlers here — called after connect() so subscriptions survive
30
38
  # session reconnection in remote-dev mode.
31
39
 
40
+ # --- Plugin UI <-> backend (not reachable from outside Muscat) ---
41
+
32
42
  @plugin.subscribe("event")
33
43
  def on_ui_event(payload: dict[str, Any] | None = None):
34
44
  """Handle messages published from the plugin UI with rb.pub("event", ...)."""
@@ -47,6 +57,19 @@ def register_handlers():
47
57
  """Small query example callable from the UI with rb.action("tool/echo", ...)."""
48
58
  return {"echo": payload, "plugin": PLUGIN_NAME}
49
59
 
60
+ # --- External endpoints (REST / Socket.IO / TCP / MQTT / WebRTC) ---
61
+ # Exposed as common/plugin/<plugin_id>/hello, e.g.
62
+ # curl -X POST http://<robot>/common/plugin/<plugin_id>/hello \
63
+ # -H 'Content-Type: application/json' -d '{"name": "kim"}'
64
+ # Restrict transports with explicit_routes=["api"] (REST only), etc.
65
+ # Raise PluginRouteError(403, "msg") to set the response status.
66
+
67
+ @plugin.router.on("/hello")
68
+ def hello(payload: dict[str, Any] | None = None, meta: dict[str, Any] | None = None):
69
+ """meta = {"transport": "api"|"socket"|"tcp"|"mqtt"|"webrtc", "principal": dict | None}."""
70
+ name = (payload or {}).get("name", "there")
71
+ return {"msg": f"hi {name}", "via": (meta or {}).get("transport")}
72
+
50
73
 
51
74
  def move_j_example():
52
75
  """
@@ -73,11 +96,15 @@ async def main():
73
96
  # Remote dev: connect to the robot before registering any handlers.
74
97
  # connect() closes and reopens the Zenoh session, so handlers registered
75
98
  # before this call would be lost.
76
- await manipulate.connect(token=robot_token, host=robot_host)
99
+ opts = ConnectOptions()
100
+ opts.token = robot_token
101
+ opts.host = robot_host
102
+ manipulate.connect(opts)
77
103
 
78
104
  register_handlers()
79
105
 
80
- plugin.publish("state", {"ready": True, "plugin": PLUGIN_NAME})
106
+ plugin.publish("state", {"ready": True, "plugin": PLUGIN_NAME}) # -> plugin UI
107
+ plugin.router.emit("/state", {"ready": True, "plugin": PLUGIN_NAME}) # -> external subscribers of common/plugin/<plugin_id>/state
81
108
  print(f"[{PLUGIN_NAME}] backend ready")
82
109
 
83
110
  try:
@@ -1,14 +1,13 @@
1
1
  cmake_minimum_required(VERSION 3.16)
2
2
  project(__PLUGIN_SLUG__ CXX)
3
3
 
4
- set(CMAKE_CXX_STANDARD 17)
4
+ set(CMAKE_CXX_STANDARD 20)
5
5
  set(CMAKE_CXX_STANDARD_REQUIRED ON)
6
6
 
7
+ # Rainbow Robotics C++ SDK — provided by the apt package rainbow-rb-sdk-dev
8
+ # (pre-installed in the muscat-pk dev container).
9
+ find_package(rb_sdk REQUIRED)
10
+
7
11
  # The executable name must match runtime.entry in manifest.json.
8
12
  add_executable(__PLUGIN_SLUG__ main.cpp)
9
-
10
- # TODO(cpp-sdk): link the rainbow cpp SDK dynamically (the robot provides the
11
- # .so at runtime — do NOT bundle/static-link it). Once the SDK ships an apt
12
- # package with CMake config, enable:
13
- # find_package(rainbow_cpp_sdk REQUIRED)
14
- # target_link_libraries(__PLUGIN_SLUG__ PRIVATE rainbow::cpp_sdk)
13
+ target_link_libraries(__PLUGIN_SLUG__ PRIVATE rb_sdk::rb_sdk)
@@ -1,9 +1,19 @@
1
1
  // __PLUGIN_NAME__ — C++ plugin back end.
2
2
  //
3
- // The C++ plugin SDK is not available yet, so this is a build/run skeleton.
4
- // Once the SDK lands, connect to the plugin gateway here (the host exposes it
5
- // at the RB_PLUGIN_GATEWAY / RB_PLUGIN_ID environment variables) and wire up
6
- // pub / sub / serve, mirroring the Python rainbow.rb_sdk.RBPluginCall API.
3
+ // The Rainbow Robotics C++ SDK (apt: rainbow-rb-sdk-dev) is installed in the
4
+ // dev container and linked via CMake (rb_sdk::rb_sdk). Headers live under
5
+ // <rainbow/rb_sdk/...>:
6
+ // - plugin/rb_plugin.hpp rb_plugin::RBPluginCall — plugin UI <-> backend
7
+ // (serve/subscribe/publish) and external endpoints (router)
8
+ // - manipulate/rb_manipulate_sdk.hpp RBManipulateSDK — control the robot
9
+ // - program/plugin_program_context.hpp rb_plugin::PluginProgramContext —
10
+ // program.panel commands (done/pause/stop,
11
+ // program variables)
12
+
13
+ #include <rainbow/rb_sdk/manipulate/rb_manipulate_sdk.hpp>
14
+ #include <rainbow/rb_sdk/plugin/rb_plugin.hpp>
15
+
16
+ #include <nlohmann/json.hpp>
7
17
 
8
18
  #include <chrono>
9
19
  #include <cstdlib>
@@ -11,14 +21,51 @@
11
21
  #include <string>
12
22
  #include <thread>
13
23
 
24
+ using nlohmann::json;
25
+ using rb_plugin::RBPluginCall;
26
+
14
27
  int main() {
15
- const char* plugin_id = std::getenv("RB_PLUGIN_ID");
16
- std::cout << "[__PLUGIN_NAME__] backend ready"
17
- << (plugin_id ? std::string(" (id=") + plugin_id + ")" : "")
18
- << std::endl;
28
+ const std::string name = "__PLUGIN_NAME__";
29
+
30
+ // Remote dev: connect before registering handlers (connect() reopens the session).
31
+ RBManipulateSDK manipulate;
32
+ const char* host = std::getenv("MUSCAT_ROBOT_HOST");
33
+ const char* token = std::getenv("MUSCAT_ROBOT_TOKEN");
34
+ if (host && token) manipulate.connect({.token = token, .host = host});
35
+
36
+ // plugin id comes from RB_PLUGIN_ID.
37
+ auto plugin = RBPluginCall::get_instance(RBPluginCall::resolve_plugin_id(std::nullopt));
38
+
39
+ // --- Plugin UI <-> backend (not reachable from outside Muscat) ---
40
+
41
+ // UI: await rb.action("grip", { width })
42
+ plugin->serve("grip", [&](const json& payload) {
43
+ const int width = payload.is_object() ? payload.value("width", 20) : 20;
44
+ std::cout << "[" << name << "] grip requested: width=" << width << std::endl;
45
+ plugin->publish("state", {{"ready", true}, {"last_grip_width", width}}); // -> rb.sub("state")
46
+ return json{{"ok", true}, {"width", width}};
47
+ });
48
+
49
+ // UI: rb.pub("event", ...)
50
+ auto event_sub = plugin->subscribe("event", [&](const std::string&, const json& payload) {
51
+ std::cout << "[" << name << "] event: " << payload.dump() << std::endl;
52
+ });
53
+
54
+ // --- External endpoints (REST / Socket.IO / TCP / MQTT / WebRTC) ---
55
+ // curl -X POST http://<robot>/common/plugin/<plugin_id>/hello -d '{"name":"kim"}'
56
+ plugin->router().on("/hello", [](const json& payload, const json& meta) {
57
+ const std::string who = payload.is_object() ? payload.value("name", std::string("there")) : "there";
58
+ return json{{"msg", "hi " + who}, {"via", meta.value("transport", std::string())}};
59
+ });
60
+
61
+ // Example: robot control (not called automatically — add safety checks first).
62
+ // IPC::MoveInput_TargetT t; t.tar_values = {0, 0, 0, 0, 0, 0};
63
+ // manipulate.move.call_move_j("C500920", t);
64
+
65
+ plugin->publish("state", {{"ready", true}, {"plugin", name}});
66
+ std::cout << "[" << name << "] backend ready" << std::endl;
19
67
 
20
- // TODO: connect to the plugin gateway and register handlers once the
21
- // C++ SDK is available. For now, just keep the process alive.
68
+ // Keep the process alive.
22
69
  while (true) {
23
70
  std::this_thread::sleep_for(std::chrono::seconds(1));
24
71
  }