refactor(web): extract JS results payload into payload module #249
Conversation
Move the Js* serializable structs, JsResults::from_results, and the build_mask_overlay/put/task_of helpers out of lib.rs into a dedicated crates/web/src/payload.rs. This is the Results -> Serialize boundary (~230 lines); separating it from the session/predict flow shrinks lib.rs and groups the JS mapping in one place. JsResults and from_results are pub(crate); the rest stay private to the module. No behavior change.
Signed-off-by: Onuralp SEZER <onuralp@ultralytics.com>
Signed-off-by: Onuralp SEZER <onuralp@ultralytics.com>
|
👋 Hello @onuralpszr, thank you for submitting a
For more guidance, please refer to our Contributing Guide. Don't hesitate to leave a comment if you have any questions. Thank you for contributing to Ultralytics! 🚀 |
UltralyticsAssistant
left a comment
There was a problem hiding this comment.
🔍 PR Review
Made with ❤️ by Ultralytics Actions
Clean refactor. The payload extraction appears behavior-preserving: imports were updated consistently, JsResults visibility is scoped appropriately with pub(crate), and the moved serialization/mask helper logic is unchanged in substance. I did not find any genuine bugs or regressions in the diff.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…tation Signed-off-by: Onuralp SEZER <onuralp@ultralytics.com>
…andling Signed-off-by: Onuralp SEZER <onuralp@ultralytics.com>
|
🎉 Merged — thank you, @onuralpszr! This is a thoughtful cleanup that makes the web inference stack easier to maintain and extend, from separating JS payload serialization into a dedicated module to centralizing TypeScript defaults and fetch error handling. As Leonardo da Vinci said, “Simplicity is the ultimate sophistication.” That fits this PR well: cleaner structure, less duplication, and clearer browser-side behavior without changing the user-facing results. Really appreciate the care put into keeping behavior intact while improving the foundation for future work. |
🛠️ PR Summary
Made with ❤️ by Ultralytics Actions
🌟 Summary
🧹 This PR refactors the web inference package by moving JS result serialization into its own module and improving reuse of default settings and fetch error handling in the TypeScript API.
📊 Key Changes
crates/web/src/lib.rsinto a new dedicated file,crates/web/src/payload.rs.JsResults::from_results()into the new module, without changing the core result format.lib.rsto use the newpayload::JsResultsmodule and removed now-unneeded direct result imports.fetchOk()helper inweb/src/index.tsto standardize network requests and error messages for models and images.🎯 Purpose & Impact