From a067e149fdaf17eff34eef50788a3d4b00bcc511 Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Fri, 20 Sep 2024 10:42:25 -0700 Subject: [PATCH] part way thru bump of kcl-lib (#900) * part way thru bump Signed-off-by: Jess Frazelle * Migrate context and text2cad cmd * Convert more files over * Shorter names * Fix 1 test * test fix Signed-off-by: Jess Frazelle * test fix Signed-off-by: Jess Frazelle * updates Signed-off-by: Jess Frazelle --------- Signed-off-by: Jess Frazelle Co-authored-by: Adam Chalmers --- Cargo.lock | 248 +++++++++++++++++++++++++++------- Cargo.toml | 5 +- src/cmd_file.rs | 30 ++-- src/cmd_kcl.rs | 171 ++++++++++++----------- src/cmd_ml/cmd_text_to_cad.rs | 46 +++---- src/context.rs | 38 +++--- src/tests.rs | 2 +- 7 files changed, 356 insertions(+), 184 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1da3968a..4b375059 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -150,13 +150,19 @@ dependencies = [ "backtrace", ] +[[package]] +name = "approx" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08abcc3b4e9339e33a3d0a5ed15d84a687350c05689d825e0f6655eef9e76a94" + [[package]] name = "approx" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" dependencies = [ - "num-traits", + "num-traits 0.2.19", ] [[package]] @@ -426,7 +432,7 @@ dependencies = [ "libm", "num-bigint", "num-integer", - "num-traits", + "num-traits 0.2.19", "serde", ] @@ -493,9 +499,9 @@ dependencies = [ [[package]] name = "bson" -version = "2.11.0" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8a88e82b9106923b5c4d6edfca9e7db958d4e98a478ec115022e81b9b38e2c8" +checksum = "068208f2b6fcfa27a7f1ee37488d2bb8ba2640f68f5475d08e1d9130696aba59" dependencies = [ "ahash", "base64 0.13.1", @@ -505,7 +511,7 @@ dependencies = [ "indexmap 2.5.0", "js-sys", "once_cell", - "rand", + "rand 0.8.5", "serde", "serde_bytes", "serde_json", @@ -570,6 +576,18 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cgmath" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a4b57c8f4e3a2e9ac07e0f6abc9c24b6fc9e1b54c3478cfb598f3d0023e51c" +dependencies = [ + "approx 0.1.1", + "mint", + "num-traits 0.1.43", + "rand 0.4.6", +] + [[package]] name = "chrono" version = "0.4.38" @@ -579,7 +597,7 @@ dependencies = [ "android-tzdata", "iana-time-zone", "js-sys", - "num-traits", + "num-traits 0.2.19", "serde", "wasm-bindgen", "windows-targets 0.52.6", @@ -902,9 +920,9 @@ dependencies = [ [[package]] name = "dashmap" -version = "6.0.1" +version = "6.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "804c8821570c3f8b70230c2ba75ffa5c0f9a4189b9a432b6656c536712acae28" +checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf" dependencies = [ "cfg-if", "crossbeam-utils", @@ -954,9 +972,9 @@ dependencies = [ [[package]] name = "derive-docs" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e6d3f12f7b5600d3ee788eccd1eff60af70b35ee8188146f6d9cdab27e39f87" +checksum = "0f01937b7b4c59463ee93c31ad1afcedfdd13783f3ee2f72cce5549f8fba790e" dependencies = [ "Inflector", "convert_case", @@ -1089,6 +1107,26 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "enum-iterator" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c280b9e6b3ae19e152d8e31cf47f18389781e119d4013a2a2bb0180e5facc635" +dependencies = [ + "enum-iterator-derive", +] + +[[package]] +name = "enum-iterator-derive" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ab991c1362ac86c61ab6f556cff143daa22e5a15e4e189df818b2fd19fe65b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -1105,6 +1143,16 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "euler" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f19d11568a4a46aee488bdab3a2963e5e2c3cfd6091aa0abceaddcea82c0bc1" +dependencies = [ + "approx 0.1.1", + "cgmath", +] + [[package]] name = "event-listener" version = "2.5.3" @@ -1239,6 +1287,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + [[package]] name = "funty" version = "2.0.0" @@ -1666,7 +1720,7 @@ dependencies = [ "exr", "gif", "jpeg-decoder", - "num-traits", + "num-traits 0.2.19", "png", "qoi", "tiff", @@ -1680,7 +1734,7 @@ checksum = "99314c8a2152b8ddb211f924cdae532d8c5e4c8bb54728e12fff1b0cd5963a10" dependencies = [ "bytemuck", "byteorder-lite", - "num-traits", + "num-traits 0.2.19", "png", ] @@ -1843,19 +1897,19 @@ dependencies = [ [[package]] name = "kcl-lib" -version = "0.2.13" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab16bfd2d240f1eb091af8e80ce018cfd379196c2fe6f16e161cec728559a4df" +checksum = "dd84b54a9e59fac58975dc5dfc49d112671dfba20f9f7898d4d249d70c0784a7" dependencies = [ "anyhow", - "approx", + "approx 0.5.1", "async-recursion", "async-trait", "base64 0.22.1", "bson", "chrono", "convert_case", - "dashmap 6.0.1", + "dashmap 6.1.0", "databake", "derive-docs", "form_urlencoded", @@ -1864,8 +1918,10 @@ dependencies = [ "gltf-json", "http 0.2.12", "image 0.25.2", + "indexmap 2.5.0", "js-sys", "kittycad", + "kittycad-modeling-cmds", "lazy_static", "measurements", "mime_guess", @@ -1889,7 +1945,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "winnow 0.5.40", + "winnow", "zip", ] @@ -1910,9 +1966,9 @@ dependencies = [ [[package]] name = "kittycad" -version = "0.3.18" +version = "0.3.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94feea5b1cf851b33dd108aa35aa01bde99772aa74d2ba1590295aac0b7ca33e" +checksum = "b6d94d74f88582f566f81fa443c638439f5d7b7eeb80d4c321f64703310a45da" dependencies = [ "anyhow", "async-trait", @@ -1930,7 +1986,7 @@ dependencies = [ "mime_guess", "parse-display 0.9.1", "phonenumber", - "rand", + "rand 0.8.5", "reqwest", "reqwest-conditional-middleware", "reqwest-middleware", @@ -1949,6 +2005,56 @@ dependencies = [ "uuid", ] +[[package]] +name = "kittycad-modeling-cmds" +version = "0.2.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dbf14ba7cee8eef75c489bf27ed6c4c5f0516e134e9e72fe0db87a034c3ebf" +dependencies = [ + "anyhow", + "chrono", + "data-encoding", + "enum-iterator", + "enum-iterator-derive", + "euler", + "http 0.2.12", + "kittycad", + "kittycad-modeling-cmds-macros", + "kittycad-unit-conversion-derive", + "measurements", + "parse-display 0.9.1", + "parse-display-derive 0.9.1", + "schemars", + "serde", + "serde_bytes", + "serde_json", + "tabled", + "uuid", +] + +[[package]] +name = "kittycad-modeling-cmds-macros" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0cdc505a33bfffb87c317435ec41ced8f73474217cf30db685e479bf289757e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", +] + +[[package]] +name = "kittycad-unit-conversion-derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7001c46a92c1edce6722a3900539b198230980799035f02d92b4e7df3fc08738" +dependencies = [ + "inflections", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "kv-log-macro" version = "1.0.7" @@ -2105,6 +2211,12 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "mint" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e53debba6bda7a793e5f99b8dacf19e626084f525f7829104ba9898f367d85ff" + [[package]] name = "mio" version = "0.8.11" @@ -2165,7 +2277,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" dependencies = [ "num-integer", - "num-traits", + "num-traits 0.2.19", ] [[package]] @@ -2180,7 +2292,16 @@ version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "num-traits", + "num-traits 0.2.19", +] + +[[package]] +name = "num-traits" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" +dependencies = [ + "num-traits 0.2.19", ] [[package]] @@ -2208,7 +2329,7 @@ dependencies = [ "chrono", "getrandom", "http 0.2.12", - "rand", + "rand 0.8.5", "reqwest", "serde", "serde_json", @@ -2273,7 +2394,7 @@ dependencies = [ "phonenumber", "proc-macro2", "quote", - "rand", + "rand 0.8.5", "regex", "reqwest", "reqwest-middleware", @@ -2325,7 +2446,7 @@ dependencies = [ "lazy_static", "percent-encoding", "pin-project", - "rand", + "rand 0.8.5", "thiserror", ] @@ -2687,6 +2808,19 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" +[[package]] +name = "rand" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" +dependencies = [ + "fuchsia-cprng", + "libc", + "rand_core 0.3.1", + "rdrand", + "winapi", +] + [[package]] name = "rand" version = "0.8.5" @@ -2695,7 +2829,7 @@ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", "rand_chacha", - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -2705,9 +2839,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", ] +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + [[package]] name = "rand_core" version = "0.6.4" @@ -2737,6 +2886,15 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -2933,7 +3091,7 @@ checksum = "e09bbcb5003282bcb688f0bae741b278e9c7e8f378f561522c9806c58e075d9b" dependencies = [ "anyhow", "chrono", - "rand", + "rand 0.8.5", ] [[package]] @@ -3043,9 +3201,9 @@ dependencies = [ [[package]] name = "rustls-native-certs" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f1fb85efa936c42c6d5fc28d2629bb51e4b2f4b8a5211e297d599cc5a093792" +checksum = "fcaf18a4f2be7326cd874a5fa579fae794320a0f388d365dca7e480e55f83f8a" dependencies = [ "openssl-probe", "rustls-pemfile 2.1.2", @@ -3230,9 +3388,9 @@ dependencies = [ [[package]] name = "serde_bytes" -version = "0.11.14" +version = "0.11.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b8497c313fd43ab992087548117643f6fcd935cbf36f176ffda0aacf9591734" +checksum = "387cc504cb06bb40a96c8e04e951fe01854cf6bc921053c954e4a606d9675c6a" dependencies = [ "serde", ] @@ -3965,9 +4123,9 @@ dependencies = [ [[package]] name = "tokio-tungstenite" -version = "0.23.1" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6989540ced10490aaf14e6bad2e3d33728a2813310a0c71d1574304c49631cd" +checksum = "edc5f74e248dc973e0dbb7b74c7e0d6fcc301c694ff50049504004ef4d0cdcd9" dependencies = [ "futures-util", "log", @@ -4023,7 +4181,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.18", + "winnow", ] [[package]] @@ -4202,9 +4360,9 @@ dependencies = [ [[package]] name = "tungstenite" -version = "0.23.0" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e2e2ce1e47ed2994fd43b04c8f618008d4cabdd5ee34027cf14f9d918edd9c8" +checksum = "18e5b8366ee7a95b16d32197d0b2604b43a0be89dc5fac9f8e96ccafbaedda8a" dependencies = [ "byteorder", "bytes", @@ -4212,7 +4370,7 @@ dependencies = [ "http 1.1.0", "httparse", "log", - "rand", + "rand 0.8.5", "rustls 0.23.10", "rustls-pki-types", "sha1", @@ -4747,15 +4905,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" -[[package]] -name = "winnow" -version = "0.5.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" -dependencies = [ - "memchr", -] - [[package]] name = "winnow" version = "0.6.18" @@ -4848,7 +4997,7 @@ dependencies = [ [[package]] name = "zoo" -version = "0.2.78" +version = "0.2.79" dependencies = [ "anyhow", "async-trait", @@ -4872,9 +5021,10 @@ dependencies = [ "kcl-lib", "kcl-test-server", "kittycad", + "kittycad-modeling-cmds", "log", "nu-ansi-term", - "num-traits", + "num-traits 0.2.19", "oauth2", "open", "parse-display 0.10.0", diff --git a/Cargo.toml b/Cargo.toml index 9e382acd..2639e853 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zoo" -version = "0.2.78" +version = "0.2.79" edition = "2021" build = "build.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -22,9 +22,10 @@ git_rev = "0.1.0" heck = "0.5.0" http = "0.2.6" itertools = "0.12.1" -kcl-lib = { version = "0.2.13", features = ["disable-println"] } +kcl-lib = { version = "0.2.16", features = ["disable-println"] } kcl-test-server = "0.1.11" kittycad = { version = "0.3.18", features = ["clap", "tabled", "requests", "retry"] } +kittycad-modeling-cmds = { version= "0.2.60", features = ["websocket", "convert_client_crate", "tabled"] } log = "0.4.22" nu-ansi-term = "0.50.1" num-traits = "0.2.19" diff --git a/src/cmd_file.rs b/src/cmd_file.rs index 85650ef5..72098c92 100644 --- a/src/cmd_file.rs +++ b/src/cmd_file.rs @@ -7,6 +7,7 @@ use anyhow::Result; use base64::prelude::*; use clap::Parser; use kcl_lib::engine::EngineManager; +use kittycad_modeling_cmds as kcmc; use crate::cmd_kcl::write_deterministic_export; @@ -205,7 +206,10 @@ impl crate::cmd::Command for CmdFileSnapshot { // Parse the image format. let output_format = if let Some(output_format) = &self.output_format { - output_format.clone() + match output_format { + kittycad::types::ImageFormat::Png => kcmc::ImageFormat::Png, + kittycad::types::ImageFormat::Jpeg => kcmc::ImageFormat::Jpeg, + } } else { crate::cmd_kcl::get_image_format_from_extension(&crate::cmd_file::get_extension(self.output_file.clone()))? }; @@ -280,15 +284,15 @@ impl crate::cmd::Command for CmdFileSnapshot { .send_modeling_cmd( uuid::Uuid::new_v4(), kcl_lib::executor::SourceRange::default(), - kittycad::types::ModelingCmd::ImportFiles { - files, - format: src_format, - }, + kcmc::ModelingCmd::ImportFiles(kcmc::ImportFiles { + files: files.into_iter().map(|f| f.into()).collect(), + format: src_format.into(), + }), ) .await?; - let kittycad::types::OkWebSocketResponseData::Modeling { - modeling_response: kittycad::types::OkModelingCmdResponse::ImportFiles { data }, + let kittycad_modeling_cmds::websocket::OkWebSocketResponseData::Modeling { + modeling_response: kittycad_modeling_cmds::ok_response::OkModelingCmdResponse::ImportFiles(data), } = &resp else { anyhow::bail!("Unexpected response from engine import: {:?}", resp); @@ -301,7 +305,9 @@ impl crate::cmd::Command for CmdFileSnapshot { .send_modeling_cmd( uuid::Uuid::new_v4(), kcl_lib::executor::SourceRange::default(), - kittycad::types::ModelingCmd::DefaultCameraFocusOn { uuid: object_id }, + kittycad_modeling_cmds::ModelingCmd::DefaultCameraFocusOn( + kittycad_modeling_cmds::DefaultCameraFocusOn { uuid: object_id }, + ), ) .await?; @@ -311,12 +317,14 @@ impl crate::cmd::Command for CmdFileSnapshot { .send_modeling_cmd( uuid::Uuid::new_v4(), kcl_lib::executor::SourceRange::default(), - kittycad::types::ModelingCmd::TakeSnapshot { format: output_format }, + kittycad_modeling_cmds::ModelingCmd::TakeSnapshot(kittycad_modeling_cmds::TakeSnapshot { + format: output_format, + }), ) .await?; - if let kittycad::types::OkWebSocketResponseData::Modeling { - modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data }, + if let kittycad_modeling_cmds::websocket::OkWebSocketResponseData::Modeling { + modeling_response: kittycad_modeling_cmds::ok_response::OkModelingCmdResponse::TakeSnapshot(data), } = &resp { // Save the snapshot locally. diff --git a/src/cmd_kcl.rs b/src/cmd_kcl.rs index 50aaa483..67630e26 100644 --- a/src/cmd_kcl.rs +++ b/src/cmd_kcl.rs @@ -2,6 +2,9 @@ use std::{net::SocketAddr, str::FromStr}; use anyhow::Result; use clap::Parser; +use kcmc::format::OutputFormat; +use kittycad::types as kt; +use kittycad_modeling_cmds as kcmc; use url::Url; use crate::iostreams::IoStreams; @@ -127,15 +130,15 @@ impl crate::cmd::Command for CmdKclExport { .send_kcl_modeling_cmd( "", input, - kittycad::types::ModelingCmd::Export { + kittycad_modeling_cmds::ModelingCmd::Export(kittycad_modeling_cmds::Export { entity_ids: vec![], format: get_output_format(&self.output_format, src_unit.into()), - }, + }), executor_settings, ) .await?; - if let kittycad::types::OkWebSocketResponseData::Export { files } = resp { + if let kittycad_modeling_cmds::websocket::OkWebSocketResponseData::Export { files } = resp { // Save the files to our export directory. for file in files { let path = self.output_dir.join(file.name); @@ -151,7 +154,7 @@ impl crate::cmd::Command for CmdKclExport { } if self.show_trace { - print_trace_link(&mut ctx.io, &session_data) + print_trace_link(&mut ctx.io, &session_data.map(kt::ModelingSessionData::from)) } Ok(()) @@ -311,7 +314,10 @@ impl crate::cmd::Command for CmdKclSnapshot { // Parse the image format. let output_format = if let Some(output_format) = &self.output_format { - output_format.clone() + match output_format { + kittycad::types::ImageFormat::Png => kittycad_modeling_cmds::ImageFormat::Png, + kittycad::types::ImageFormat::Jpeg => kittycad_modeling_cmds::ImageFormat::Jpeg, + } } else { get_image_format_from_extension(&crate::cmd_file::get_extension(self.output_file.clone()))? }; @@ -360,16 +366,18 @@ impl crate::cmd::Command for CmdKclSnapshot { .send_kcl_modeling_cmd( "", &input, - kittycad::types::ModelingCmd::TakeSnapshot { format: output_format }, + kittycad_modeling_cmds::ModelingCmd::TakeSnapshot(kittycad_modeling_cmds::TakeSnapshot { + format: output_format, + }), executor_settings, ) .await?; - if let kittycad::types::OkWebSocketResponseData::Modeling { - modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data }, - } = resp + if let kittycad_modeling_cmds::websocket::OkWebSocketResponseData::Modeling { + modeling_response: kittycad_modeling_cmds::ok_response::OkModelingCmdResponse::TakeSnapshot(data), + } = &resp { - (data.contents.0, session_data) + (data.contents.0.clone(), session_data) } else { anyhow::bail!("Unexpected response from engine: {:?}", resp); } @@ -384,7 +392,7 @@ impl crate::cmd::Command for CmdKclSnapshot { self.output_file.to_str().unwrap_or("") )?; if self.show_trace { - print_trace_link(&mut ctx.io, &session_data) + print_trace_link(&mut ctx.io, &session_data.map(kt::ModelingSessionData::from)) } Ok(()) @@ -444,15 +452,15 @@ impl crate::cmd::Command for CmdKclView { .send_kcl_modeling_cmd( "", input, - kittycad::types::ModelingCmd::TakeSnapshot { - format: kittycad::types::ImageFormat::Png, - }, + kittycad_modeling_cmds::ModelingCmd::TakeSnapshot(kittycad_modeling_cmds::TakeSnapshot { + format: kittycad_modeling_cmds::ImageFormat::Png, + }), executor_settings, ) .await?; - if let kittycad::types::OkWebSocketResponseData::Modeling { - modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data }, + if let kittycad_modeling_cmds::websocket::OkWebSocketResponseData::Modeling { + modeling_response: kittycad_modeling_cmds::ok_response::OkModelingCmdResponse::TakeSnapshot(data), } = &resp { // Save the snapshot locally. @@ -487,8 +495,8 @@ impl crate::cmd::Command for CmdKclView { } /// Get the image format from the extension. -pub fn get_image_format_from_extension(ext: &str) -> Result { - match kittycad::types::ImageFormat::from_str(ext) { +pub fn get_image_format_from_extension(ext: &str) -> Result { + match kittycad_modeling_cmds::ImageFormat::from_str(ext) { Ok(format) => Ok(format), Err(_) => { anyhow::bail!( @@ -501,53 +509,54 @@ pub fn get_image_format_from_extension(ext: &str) -> Result kittycad::types::OutputFormat { + src_unit: kittycad_modeling_cmds::units::UnitLength, +) -> kittycad_modeling_cmds::format::OutputFormat { // Zoo co-ordinate system. // // * Forward: -Y // * Up: +Z // * Handedness: Right - let coords = kittycad::types::System { - forward: kittycad::types::AxisDirectionPair { - axis: kittycad::types::Axis::Y, - direction: kittycad::types::Direction::Negative, + let coords = kcmc::coord::System { + forward: kcmc::coord::AxisDirectionPair { + axis: kcmc::coord::Axis::Y, + direction: kcmc::coord::Direction::Negative, }, - up: kittycad::types::AxisDirectionPair { - axis: kittycad::types::Axis::Z, - direction: kittycad::types::Direction::Positive, + up: kcmc::coord::AxisDirectionPair { + axis: kcmc::coord::Axis::Z, + direction: kcmc::coord::Direction::Positive, }, }; match format { - kittycad::types::FileExportFormat::Fbx => kittycad::types::OutputFormat::Fbx { - storage: kittycad::types::FbxStorage::Binary, - }, - kittycad::types::FileExportFormat::Glb => kittycad::types::OutputFormat::Gltf { - storage: kittycad::types::GltfStorage::Binary, - presentation: kittycad::types::GltfPresentation::Compact, - }, - kittycad::types::FileExportFormat::Gltf => kittycad::types::OutputFormat::Gltf { - storage: kittycad::types::GltfStorage::Embedded, - presentation: kittycad::types::GltfPresentation::Pretty, - }, - kittycad::types::FileExportFormat::Obj => kittycad::types::OutputFormat::Obj { + kt::FileExportFormat::Fbx => OutputFormat::Fbx(kcmc::format::fbx::export::Options { + storage: kcmc::format::fbx::export::Storage::Binary, + created: None, + }), + kt::FileExportFormat::Glb => OutputFormat::Gltf(kcmc::format::gltf::export::Options { + storage: kcmc::format::gltf::export::Storage::Binary, + presentation: kcmc::format::gltf::export::Presentation::Compact, + }), + kt::FileExportFormat::Gltf => OutputFormat::Gltf(kcmc::format::gltf::export::Options { + storage: kcmc::format::gltf::export::Storage::Embedded, + presentation: kcmc::format::gltf::export::Presentation::Pretty, + }), + kt::FileExportFormat::Obj => OutputFormat::Obj(kcmc::format::obj::export::Options { coords, units: src_unit, - }, - kittycad::types::FileExportFormat::Ply => kittycad::types::OutputFormat::Ply { - storage: kittycad::types::PlyStorage::Ascii, + }), + kt::FileExportFormat::Ply => OutputFormat::Ply(kcmc::format::ply::export::Options { + storage: kcmc::format::ply::export::Storage::Ascii, coords, - selection: kittycad::types::Selection::DefaultScene {}, + selection: kcmc::format::Selection::DefaultScene, units: src_unit, - }, - kittycad::types::FileExportFormat::Step => kittycad::types::OutputFormat::Step { coords }, - kittycad::types::FileExportFormat::Stl => kittycad::types::OutputFormat::Stl { - storage: kittycad::types::StlStorage::Ascii, + }), + kt::FileExportFormat::Step => OutputFormat::Step(kcmc::format::step::export::Options { coords, created: None }), + kt::FileExportFormat::Stl => OutputFormat::Stl(kcmc::format::stl::export::Options { + storage: kcmc::format::stl::export::Storage::Ascii, coords, units: src_unit, - selection: kittycad::types::Selection::DefaultScene {}, - }, + selection: kcmc::format::Selection::DefaultScene, + }), } } @@ -609,16 +618,16 @@ impl crate::cmd::Command for CmdKclVolume { .send_kcl_modeling_cmd( "", input, - kittycad::types::ModelingCmd::Volume { + kittycad_modeling_cmds::ModelingCmd::Volume(kittycad_modeling_cmds::Volume { entity_ids: vec![], // get whole model - output_unit: self.output_unit.clone(), - }, + output_unit: self.output_unit.clone().into(), + }), executor_settings, ) .await?; - if let kittycad::types::OkWebSocketResponseData::Modeling { - modeling_response: kittycad::types::OkModelingCmdResponse::Volume { data }, + if let kittycad_modeling_cmds::websocket::OkWebSocketResponseData::Modeling { + modeling_response: kittycad_modeling_cmds::ok_response::OkModelingCmdResponse::Volume(data), } = &resp { // Print the output. @@ -629,7 +638,7 @@ impl crate::cmd::Command for CmdKclVolume { } if self.show_trace { - print_trace_link(&mut ctx.io, &session_data) + print_trace_link(&mut ctx.io, &session_data.map(kt::ModelingSessionData::from)) } Ok(()) } @@ -705,18 +714,18 @@ impl crate::cmd::Command for CmdKclMass { .send_kcl_modeling_cmd( "", input, - kittycad::types::ModelingCmd::Mass { + kittycad_modeling_cmds::ModelingCmd::Mass(kittycad_modeling_cmds::Mass { entity_ids: vec![], // get whole model material_density: self.material_density.into(), - material_density_unit: self.material_density_unit.clone(), - output_unit: self.output_unit.clone(), - }, + material_density_unit: self.material_density_unit.clone().into(), + output_unit: self.output_unit.clone().into(), + }), executor_settings, ) .await?; - if let kittycad::types::OkWebSocketResponseData::Modeling { - modeling_response: kittycad::types::OkModelingCmdResponse::Mass { data }, + if let kittycad_modeling_cmds::websocket::OkWebSocketResponseData::Modeling { + modeling_response: kittycad_modeling_cmds::ok_response::OkModelingCmdResponse::Mass(data), } = &resp { // Print the output. @@ -727,7 +736,7 @@ impl crate::cmd::Command for CmdKclMass { } if self.show_trace { - print_trace_link(&mut ctx.io, &session_data) + print_trace_link(&mut ctx.io, &session_data.map(kt::ModelingSessionData::from)) } Ok(()) } @@ -791,16 +800,16 @@ impl crate::cmd::Command for CmdKclCenterOfMass { .send_kcl_modeling_cmd( "", input, - kittycad::types::ModelingCmd::CenterOfMass { + kittycad_modeling_cmds::ModelingCmd::CenterOfMass(kittycad_modeling_cmds::CenterOfMass { entity_ids: vec![], // get whole model - output_unit: self.output_unit.clone(), - }, + output_unit: self.output_unit.clone().into(), + }), executor_settings, ) .await?; - if let kittycad::types::OkWebSocketResponseData::Modeling { - modeling_response: kittycad::types::OkModelingCmdResponse::CenterOfMass { data }, + if let kittycad_modeling_cmds::websocket::OkWebSocketResponseData::Modeling { + modeling_response: kittycad_modeling_cmds::ok_response::OkModelingCmdResponse::CenterOfMass(data), } = &resp { // Print the output. @@ -811,7 +820,7 @@ impl crate::cmd::Command for CmdKclCenterOfMass { } if self.show_trace { - print_trace_link(&mut ctx.io, &session_data) + print_trace_link(&mut ctx.io, &session_data.map(kt::ModelingSessionData::from)) } Ok(()) } @@ -887,18 +896,18 @@ impl crate::cmd::Command for CmdKclDensity { .send_kcl_modeling_cmd( "", input, - kittycad::types::ModelingCmd::Density { + kittycad_modeling_cmds::ModelingCmd::Density(kittycad_modeling_cmds::Density { entity_ids: vec![], // get whole model material_mass: self.material_mass.into(), - material_mass_unit: self.material_mass_unit.clone(), - output_unit: self.output_unit.clone(), - }, + material_mass_unit: self.material_mass_unit.clone().into(), + output_unit: self.output_unit.clone().into(), + }), executor_settings, ) .await?; - if let kittycad::types::OkWebSocketResponseData::Modeling { - modeling_response: kittycad::types::OkModelingCmdResponse::Density { data }, + if let kittycad_modeling_cmds::websocket::OkWebSocketResponseData::Modeling { + modeling_response: kittycad_modeling_cmds::ok_response::OkModelingCmdResponse::Density(data), } = &resp { // Print the output. @@ -909,7 +918,7 @@ impl crate::cmd::Command for CmdKclDensity { } if self.show_trace { - print_trace_link(&mut ctx.io, &session_data) + print_trace_link(&mut ctx.io, &session_data.map(kt::ModelingSessionData::from)) } Ok(()) } @@ -973,16 +982,16 @@ impl crate::cmd::Command for CmdKclSurfaceArea { .send_kcl_modeling_cmd( "", input, - kittycad::types::ModelingCmd::SurfaceArea { + kittycad_modeling_cmds::ModelingCmd::SurfaceArea(kittycad_modeling_cmds::SurfaceArea { entity_ids: vec![], // get whole model - output_unit: self.output_unit.clone(), - }, + output_unit: self.output_unit.clone().into(), + }), executor_settings, ) .await?; - if let kittycad::types::OkWebSocketResponseData::Modeling { - modeling_response: kittycad::types::OkModelingCmdResponse::SurfaceArea { data }, + if let kittycad_modeling_cmds::websocket::OkWebSocketResponseData::Modeling { + modeling_response: kittycad_modeling_cmds::ok_response::OkModelingCmdResponse::SurfaceArea(data), } = &resp { // Print the output. @@ -993,7 +1002,7 @@ impl crate::cmd::Command for CmdKclSurfaceArea { } if self.show_trace { - print_trace_link(&mut ctx.io, &session_data) + print_trace_link(&mut ctx.io, &session_data.map(kt::ModelingSessionData::from)) } Ok(()) } diff --git a/src/cmd_ml/cmd_text_to_cad.rs b/src/cmd_ml/cmd_text_to_cad.rs index aa58fec4..3efd3ce3 100644 --- a/src/cmd_ml/cmd_text_to_cad.rs +++ b/src/cmd_ml/cmd_text_to_cad.rs @@ -1,6 +1,12 @@ use anyhow::Result; use clap::Parser; use kcl_lib::engine::EngineManager; +use kcmc::each_cmd as mcmd; +use kcmc::format::InputFormat; +use kcmc::ok_response::OkModelingCmdResponse; +use kcmc::websocket::OkWebSocketResponseData; +use kcmc::{shared::FileExportFormat, ImageFormat, ModelingCmd}; +use kittycad_modeling_cmds::{self as kcmc, ImportFile}; /// Perform Text-to-CAD commands. #[derive(Parser, Debug, Clone)] @@ -45,7 +51,7 @@ pub struct CmdTextToCadExport { /// A valid output file format. #[clap(short = 't', long = "output-format", value_enum)] - output_format: kittycad::types::FileExportFormat, + output_format: FileExportFormat, /// Command output format. #[clap(long, short, value_enum)] @@ -75,9 +81,7 @@ impl crate::cmd::Command for CmdTextToCadExport { anyhow::bail!("prompt cannot be empty"); } - let mut model = ctx - .get_model_for_prompt("", &prompt, self.output_format.clone()) - .await?; + let mut model = ctx.get_model_for_prompt("", &prompt, self.output_format).await?; if let Some(outputs) = model.outputs { // Write the contents of the files to the output directory. @@ -127,7 +131,7 @@ pub struct CmdTextToCadSnapshot { /// A valid output image format. #[clap(short = 't', long = "output-format", value_enum, default_value = "png")] - output_format: kittycad::types::ImageFormat, + output_format: ImageFormat, /// Command output format. #[clap(long, short, value_enum)] @@ -157,9 +161,7 @@ impl crate::cmd::Command for CmdTextToCadSnapshot { anyhow::bail!("prompt cannot be empty"); } - let model = ctx - .get_model_for_prompt("", &prompt, kittycad::types::FileExportFormat::Gltf) - .await?; + let model = ctx.get_model_for_prompt("", &prompt, FileExportFormat::Gltf).await?; // Get the gltf bytes. let mut gltf_bytes = vec![]; @@ -215,9 +217,7 @@ impl crate::cmd::Command for CmdTextToCadView { anyhow::bail!("prompt cannot be empty"); } - let model = ctx - .get_model_for_prompt("", &prompt, kittycad::types::FileExportFormat::Gltf) - .await?; + let model = ctx.get_model_for_prompt("", &prompt, FileExportFormat::Gltf).await?; // Get the gltf bytes. let mut gltf_bytes = vec![]; @@ -236,7 +236,7 @@ impl crate::cmd::Command for CmdTextToCadView { let mut tmp_file = std::env::temp_dir(); tmp_file.push(format!("zoo-text-to-cad-view-{}.png", uuid::Uuid::new_v4())); - let image_bytes = get_image_bytes(ctx, &gltf_bytes, kittycad::types::ImageFormat::Png).await?; + let image_bytes = get_image_bytes(ctx, &gltf_bytes, ImageFormat::Png).await?; // Save the snapshot locally. std::fs::write(&tmp_file, image_bytes)?; @@ -269,7 +269,7 @@ impl crate::cmd::Command for CmdTextToCadView { async fn get_image_bytes( ctx: &mut crate::context::Context<'_>, gltf_bytes: &[u8], - output_format: kittycad::types::ImageFormat, + output_format: ImageFormat, ) -> Result> { let engine = ctx.engine("", None).await?; @@ -278,18 +278,18 @@ async fn get_image_bytes( .send_modeling_cmd( uuid::Uuid::new_v4(), kcl_lib::executor::SourceRange::default(), - kittycad::types::ModelingCmd::ImportFiles { - files: vec![kittycad::types::ImportFile { + ModelingCmd::from(mcmd::ImportFiles { + files: vec![ImportFile { path: "model.gltf".to_string(), data: gltf_bytes.to_vec(), }], - format: kittycad::types::InputFormat::Gltf {}, - }, + format: InputFormat::Gltf(Default::default()), + }), ) .await?; - let kittycad::types::OkWebSocketResponseData::Modeling { - modeling_response: kittycad::types::OkModelingCmdResponse::ImportFiles { data }, + let OkWebSocketResponseData::Modeling { + modeling_response: OkModelingCmdResponse::ImportFiles(data), } = &resp else { anyhow::bail!("Unexpected response from engine import: {:?}", resp); @@ -302,7 +302,7 @@ async fn get_image_bytes( .send_modeling_cmd( uuid::Uuid::new_v4(), kcl_lib::executor::SourceRange::default(), - kittycad::types::ModelingCmd::DefaultCameraFocusOn { uuid: object_id }, + ModelingCmd::from(mcmd::DefaultCameraFocusOn { uuid: object_id }), ) .await?; @@ -312,12 +312,12 @@ async fn get_image_bytes( .send_modeling_cmd( uuid::Uuid::new_v4(), kcl_lib::executor::SourceRange::default(), - kittycad::types::ModelingCmd::TakeSnapshot { format: output_format }, + ModelingCmd::from(mcmd::TakeSnapshot { format: output_format }), ) .await?; - if let kittycad::types::OkWebSocketResponseData::Modeling { - modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data }, + if let OkWebSocketResponseData::Modeling { + modeling_response: OkModelingCmdResponse::TakeSnapshot(data), } = &resp { // Save the snapshot locally. diff --git a/src/context.rs b/src/context.rs index 13efcdaf..caf6604f 100644 --- a/src/context.rs +++ b/src/context.rs @@ -2,7 +2,10 @@ use std::str::FromStr; use anyhow::{anyhow, Result}; use kcl_lib::engine::EngineManager; -use kittycad::types::OkWebSocketResponseData; +use kcmc::each_cmd as mcmd; +use kcmc::websocket::OkWebSocketResponseData; +use kittycad::types::{ApiCallStatus, AsyncApiCallOutput, TextToCad, TextToCadCreateBody}; +use kittycad_modeling_cmds::{self as kcmc, shared::FileExportFormat, websocket::ModelingSessionData, ModelingCmd}; use crate::{config::Config, config_file::get_env_var, kcl_error_fmt, types::FormatOutput}; @@ -101,7 +104,7 @@ impl Context<'_> { pub async fn send_single_modeling_cmd( &self, hostname: &str, - cmd: kittycad::types::ModelingCmd, + cmd: ModelingCmd, replay: Option, ) -> Result { let engine = self.engine(hostname, replay).await?; @@ -137,9 +140,9 @@ impl Context<'_> { &self, hostname: &str, code: &str, - cmd: kittycad::types::ModelingCmd, + cmd: kittycad_modeling_cmds::ModelingCmd, settings: kcl_lib::executor::ExecutorSettings, - ) -> Result<(OkWebSocketResponseData, Option)> { + ) -> Result<(OkWebSocketResponseData, Option)> { let client = self.api_client(hostname)?; let tokens = kcl_lib::token::lexer(code)?; @@ -159,10 +162,11 @@ impl Context<'_> { .send_modeling_cmd( uuid::Uuid::new_v4(), kcl_lib::executor::SourceRange::default(), - kittycad::types::ModelingCmd::ZoomToFit { + ModelingCmd::from(mcmd::ZoomToFit { + animated: false, object_ids: Default::default(), padding: 0.1, - }, + }), ) .await?; @@ -178,17 +182,17 @@ impl Context<'_> { &self, hostname: &str, prompt: &str, - format: kittycad::types::FileExportFormat, - ) -> Result { + format: FileExportFormat, + ) -> Result { let client = self.api_client(hostname)?; // Create the text-to-cad request. - let mut gen_model: kittycad::types::TextToCad = client + let mut gen_model: TextToCad = client .ml() .create_text_to_cad( None, - format, - &kittycad::types::TextToCadCreateBody { + format.into(), + &TextToCadCreateBody { prompt: prompt.to_string(), }, ) @@ -200,14 +204,14 @@ impl Context<'_> { let start = std::time::Instant::now(); // Give it 5 minutes to complete. That should be way // more than enough! - while status != kittycad::types::ApiCallStatus::Completed - && status != kittycad::types::ApiCallStatus::Failed + while status != ApiCallStatus::Completed + && status != ApiCallStatus::Failed && start.elapsed().as_secs() < 60 * 5 { // Poll for the status. let result = client.api_calls().get_async_operation(gen_model.id).await?; - if let kittycad::types::AsyncApiCallOutput::TextToCad { + if let AsyncApiCallOutput::TextToCad { completed_at, created_at, error, @@ -225,7 +229,7 @@ impl Context<'_> { model, } = result { - gen_model = kittycad::types::TextToCad { + gen_model = TextToCad { completed_at, created_at, error, @@ -253,7 +257,7 @@ impl Context<'_> { } // If the model failed we will want to tell the user. - if gen_model.status == kittycad::types::ApiCallStatus::Failed { + if gen_model.status == ApiCallStatus::Failed { if let Some(error) = gen_model.error { anyhow::bail!("Your prompt returned an error: ```\n{}\n```", error); } else { @@ -261,7 +265,7 @@ impl Context<'_> { } } - if gen_model.status != kittycad::types::ApiCallStatus::Completed { + if gen_model.status != ApiCallStatus::Completed { anyhow::bail!("Your prompt timed out"); } diff --git a/src/tests.rs b/src/tests.rs index 9ca017de..f1bf3b14 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -534,7 +534,7 @@ access-control-allow-credentials: """# "--output-unit".to_string(), "cm".to_string(), ], - want_out: r#"center_of_mass | Point3D { x: -3.630934486409387e-8, y: 0.05000002682209015, z: -1.856890335938388e-10 }"#.to_string(), + want_out: r#"(-0.00000003630934486409387, 0.05000002682209015, -0.0000000001856890335938388)"#.to_string(), want_err: "".to_string(), want_code: 0, ..Default::default()