diff --git a/Cargo.toml b/Cargo.toml index b7c07c8..47b14aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,8 @@ members = [ "glsp-mcp-server", "glsp-tauri/src-tauri", + #"composer", + "tasklist_mcp_client" ] resolver = "2" @@ -58,4 +60,4 @@ once_cell = "1.0" parking_lot = "0.12" validator = "0.18" futures-util = "0.3" -lru = "0.12" \ No newline at end of file +lru = "0.12" diff --git a/README.md b/README.md index fff2f4d..954f17e 100644 --- a/README.md +++ b/README.md @@ -230,4 +230,4 @@ MIT License - see [LICENSE](LICENSE) file for details. --- -**🎯 Ready to revolutionize diagram creation with AI?** Start the system and create your first AI-generated diagram in under 2 minutes! πŸš€ \ No newline at end of file + diff --git a/composer/Cargo.toml b/composer/Cargo.toml new file mode 100644 index 0000000..b8f9974 --- /dev/null +++ b/composer/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "composer" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +wit-bindgen = "0.43.0" + diff --git a/composer/README.md b/composer/README.md new file mode 100644 index 0000000..464000a --- /dev/null +++ b/composer/README.md @@ -0,0 +1,135 @@ +# WIT Composition Project + +This project demonstrates the composition of WebAssembly Interface Types (WIT) definitions using `math.wit`, `user.wit`, and `world.wit`. The project provides a clear example of how multiple WIT definitions can interact and be composed in Rust using the WebAssembly component model. + +## Project Structure + +``` +wit-composition-project/ +β”œβ”€β”€ wit/ +β”‚ β”œβ”€β”€ math.wit +β”‚ β”œβ”€β”€ user.wit +β”‚ └── world.wit +└── src/ + └── lib.rs +``` + +## WIT Interfaces + +### math.wit + +Defines basic mathematical operations. + +```wit +interface math { + add: func(a: f32, b: f32) -> f32 + subtract: func(a: f32, b: f32) -> f32 + multiply: func(a: f32, b: f32) -> f32 + divide: func(a: f32, b: f32) -> result +} +``` + +### user.wit + +Defines user-related functionality. + +```wit +interface user { + record User { + id: u32, + name: string, + } + + get-user: func(id: u32) -> option + create-user: func(name: string) -> User +} +``` + +### world.wit + +Composes the interfaces and defines the main entry point. + +```wit +world world { + import math + import user + + export greet-user: func(id: u32) -> string + export calculate-and-greet: func(id: u32, a: f32, b: f32) -> string +} +``` + +## Rust Implementation (`src/lib.rs`) + +The Rust library provides implementations for the composed WIT interfaces. + +```rust +use wit_bindgen::generate; + +// Generate Rust bindings from WIT definitions +generate!("world"); + +struct UserService; +struct MathService; + +impl world::user::User for UserService { + fn get_user(id: u32) -> Option { + Some(world::user::User { id, name: format!("User{id}") }) + } + + fn create_user(name: String) -> world::user::User { + world::user::User { id: 1, name } + } +} + +impl world::math::Math for MathService { + fn add(a: f32, b: f32) -> f32 { a + b } + fn subtract(a: f32, b: f32) -> f32 { a - b } + fn multiply(a: f32, b: f32) -> f32 { a * b } + + fn divide(a: f32, b: f32) -> Result { + if b == 0.0 { + Err("Cannot divide by zero".into()) + } else { + Ok(a / b) + } + } +} + +pub struct Component; + +impl world::World for Component { + fn greet_user(id: u32) -> String { + match UserService::get_user(id) { + Some(user) => format!("Hello, {}!", user.name), + None => "User not found".into(), + } + } + + fn calculate_and_greet(id: u32, a: f32, b: f32) -> String { + match MathService::divide(a, b) { + Ok(result) => format!("Hello User{}, the result is {:.2}", id, result), + Err(e) => format!("Calculation error: {}", e), + } + } +} +``` + +## Usage + +Compile the project using Cargo with WASM support: + +```bash +cargo build --target wasm32-unknown-unknown --release +``` + +## Tools and Dependencies + +* Rust +* WebAssembly Interface Types (WIT) +* `wit-bindgen` for Rust bindings generation + +## License + +MIT License + diff --git a/composer/package.json b/composer/package.json new file mode 100644 index 0000000..5df557f --- /dev/null +++ b/composer/package.json @@ -0,0 +1,11 @@ +{ + "name": "wasm-composer-project", + "version": "1.0.0", + "scripts": { + "build:wasm": "cargo build --target wasm32-unknown-unknown --release", + "build": " npm run build:wasm" + }, + "devDependencies": { + "wit-bindgen": "^0.20.0" + } +} diff --git a/composer/src/lib.rs b/composer/src/lib.rs new file mode 100644 index 0000000..bc130d3 --- /dev/null +++ b/composer/src/lib.rs @@ -0,0 +1,22 @@ +wit_bindgen::generate!({ + path: "../wit", + world: "math", + exports: { + generate_all, + } +}); + +pub struct Math; + +impl Math { + pub fn add_points(p1: bindings::Point, p2: bindings::Point) -> bindings::Point { + bindings::Point { + x: p1.x + p2.x, + y: p1.y + p2.y, + } + } +} + +pub fn compose_points(p1: bindings::Point, p2: bindings::Point) -> bindings::Point { + Math::add_points(p1, p2) +} diff --git a/composer/wit/example/math.wit b/composer/wit/example/math.wit new file mode 100644 index 0000000..fa9246c --- /dev/null +++ b/composer/wit/example/math.wit @@ -0,0 +1,11 @@ +package example:math + +interface math { + record point { + x: f64, + y: f64, + } + + distance-from-origin: func(p: point) -> f64 +} + diff --git a/composer/wit/example/user.wit b/composer/wit/example/user.wit new file mode 100644 index 0000000..c4d234f --- /dev/null +++ b/composer/wit/example/user.wit @@ -0,0 +1,12 @@ +package example:user + +interface user { + record user-profile { + id: u32, + username: string, + is-active: bool, + } + + greet-user: func(profile: user-profile) -> string +} + diff --git a/composer/wit/world.wit b/composer/wit/world.wit new file mode 100644 index 0000000..9856cf9 --- /dev/null +++ b/composer/wit/world.wit @@ -0,0 +1,9 @@ +package composer:test + +world my-world { + import example:math/math; + import example:user/user; +} +# this is a test world for the composer package +# it imports the math and user packages from the example namespace +# it is used to test the composer functionality diff --git a/glsp-web-client/index.html b/glsp-web-client/index.html index c2df635..1959f7d 100644 --- a/glsp-web-client/index.html +++ b/glsp-web-client/index.html @@ -1,317 +1,317 @@ - - - - - WASM Component Designer - - - - - - - - - - - - - - -