Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
members = [
"glsp-mcp-server",
"glsp-tauri/src-tauri",
#"composer",
"tasklist_mcp_client"
]
resolver = "2"

Expand Down Expand Up @@ -58,4 +60,4 @@ once_cell = "1.0"
parking_lot = "0.12"
validator = "0.18"
futures-util = "0.3"
lru = "0.12"
lru = "0.12"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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! 🚀

11 changes: 11 additions & 0 deletions composer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "composer"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
wit-bindgen = "0.43.0"

135 changes: 135 additions & 0 deletions composer/README.md
Original file line number Diff line number Diff line change
@@ -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<f32, string>
}
```

### user.wit

Defines user-related functionality.

```wit
interface user {
record User {
id: u32,
name: string,
}

get-user: func(id: u32) -> option<User>
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<world::user::User> {
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<f32, String> {
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

11 changes: 11 additions & 0 deletions composer/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
22 changes: 22 additions & 0 deletions composer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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)
}
11 changes: 11 additions & 0 deletions composer/wit/example/math.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package example:math

interface math {
record point {
x: f64,
y: f64,
}

distance-from-origin: func(p: point) -> f64
}

12 changes: 12 additions & 0 deletions composer/wit/example/user.wit
Original file line number Diff line number Diff line change
@@ -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
}

9 changes: 9 additions & 0 deletions composer/wit/world.wit
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading