### Wassette CLI Quick Start Source: https://github.com/microsoft/wassette/blob/main/docs/cli.md Provides essential commands to get started with the Wassette CLI, including checking help, listing components, loading components from OCI registries or local files, and starting the MCP server. ```bash # Check available commands wassette --help # List currently loaded components wassette component list # Load a component from an OCI registry wassette component load oci://ghcr.io/yoshuawuyts/time:latest # Load a component from a local file wassette component load file:///path/to/component.wasm # Start the MCP server (traditional mode) wassette serve --stdio ``` -------------------------------- ### Example WIT Interface Definition Source: https://github.com/microsoft/wassette/blob/main/docs/development/go.md An example WIT file defining an interface for a Go module server. It includes functions to get module versions and information, returning results that can be either a string or an error string. ```WIT package local:gomodule-server; interface gomodule { /// Get the latest version of multiple Go modules /// Returns JSON string with module -> version mapping get-latest-versions: func(module-names: string) -> result; /// Get detailed information about multiple Go modules /// Returns JSON string with module information array get-module-info: func(module-names: string) -> result; } world gomodule-server { include wasi:cli/imports@0.2.0; import wasi:http/outgoing-handler@0.2.0; export gomodule; } ``` -------------------------------- ### Wassette Example Tools Source: https://github.com/microsoft/wassette/blob/main/docs/faq.md Examples of Wassette tools implemented in various programming languages. These examples showcase how to build WebAssembly Components for different functionalities, including JavaScript for time and weather services, Python for evaluation, Rust for fetch and filesystem operations, and Go for module management. ```JavaScript ../examples/time-server-js ../examples/get-weather-js ``` ```Python ../examples/eval-py ``` ```Rust ../examples/fetch-rs ../examples/filesystem-rs ``` ```Go ../examples/gomodule-go ``` -------------------------------- ### Example Wassette Configuration Source: https://github.com/microsoft/wassette/blob/main/docs/cli.md An example of a Wassette configuration file in TOML format, showing how to specify the plugin directory for components. ```toml # Directory where components are stored plugin_dir = "/opt/wassette/components" ``` -------------------------------- ### Install TinyGo Source: https://github.com/microsoft/wassette/blob/main/docs/development/go.md Command to check the installed TinyGo version. Install TinyGo from https://tinygo.org/getting-started/install/. ```Bash # Install TinyGo from https://tinygo.org/getting-started/install/ tinygo version ``` -------------------------------- ### Get Go Module Information Source: https://github.com/microsoft/wassette/blob/main/examples/gomodule-go/README.md Demonstrates how to query for the latest versions of a specified Go module. ```bash get the latest versions for the go module urfave/cli ``` -------------------------------- ### Install Build Tools Source: https://github.com/microsoft/wassette/blob/main/docs/development/python.md Installs the necessary build tools for the project. ```bash just install ``` -------------------------------- ### Project Setup and Dependencies Source: https://github.com/microsoft/wassette/blob/main/docs/development/javascript.md Initializes a new Node.js project for a WebAssembly component and installs necessary dependencies, including componentize-js and jco. ```bash mkdir my-component cd my-component npm init -y ``` ```json { "type": "module", "dependencies": { "@bytecodealliance/componentize-js": "^0.18.1", "@bytecodealliance/jco": "^1.11.1" }, "scripts": { "build:component": "jco componentize -w ./wit main.js -o component.wasm" } } ``` ```bash npm install ``` -------------------------------- ### Component Distribution Workflow Source: https://github.com/microsoft/wassette/blob/main/docs/cli.md Steps for distributing components from an OCI registry, configuring permissions, and starting a server for clients. ```bash # 1. Load component from OCI registry wassette component load oci://ghcr.io/myorg/my-tool:v1.0.0 # 2. Configure permissions based on component needs wassette permission grant storage my-tool fs://workspace/** --access read,write wassette permission grant network my-tool api.myservice.com # 3. Start server for clients wassette serve --sse ``` -------------------------------- ### Load Wassette Fetch Component Source: https://github.com/microsoft/wassette/blob/main/examples/fetch-rs/README.md Instructions on how to load the Wassette fetch component from its OCI registry location. ```Shell Please load the component from oci://ghcr.io/microsoft/fetch-rs:latest ``` -------------------------------- ### Optimize Binary Size with TinyGo Flags (Bash) Source: https://github.com/microsoft/wassette/blob/main/docs/development/go.md Provides an example of TinyGo build command with additional flags for optimizing the WebAssembly binary size. ```Bash # Use additional TinyGo flags for smaller binaries tinygo build -o component.wasm \ -target wasip2 \ --wit-package ./wit \ --wit-world my-component \ -opt=2 \ -gc=leaking \ main.go ``` -------------------------------- ### Local Testing with Wassette (Bash) Source: https://github.com/microsoft/wassette/blob/main/docs/development/go.md Commands for starting Wassette to serve a component and connecting with the MCP inspector for local testing. ```Bash wassette serve --sse --plugin-dir ./" npx @modelcontextprotocol/inspector --cli http://127.0.0.1:9001/sse ``` -------------------------------- ### Install Wassette using Homebrew Source: https://github.com/microsoft/wassette/blob/main/docs/src/homebrew.md Installs the 'wassette' tool by tapping the Microsoft repository and installing the 'wassette' formula. ```bash brew tap microsoft/wassette https://github.com/microsoft/wassette brew install wassette ``` -------------------------------- ### Load Filesystem Component Source: https://github.com/microsoft/wassette/blob/main/examples/filesystem-rs/README.md Instructions on how to load the filesystem component from its OCI registry location. ```Shell Please load the component from oci://ghcr.io/microsoft/filesystem-rs:latest ``` -------------------------------- ### Install Wassette via Script Source: https://github.com/microsoft/wassette/blob/main/README.md Installs the latest Wassette binary to your PATH for Linux, macOS, and WSL. It automatically detects the platform. ```bash curl -fsSL https://raw.githubusercontent.com/microsoft/wassette/main/install.sh | bash ``` -------------------------------- ### Install and Run Wassette with Nix Flakes Source: https://github.com/microsoft/wassette/blob/main/docs/src/nix.md Provides commands to install and run the Wassette project using Nix flakes. This includes running directly without installation, installing to the user's profile, and entering a development shell. ```bash # Run directly without installation nix run github:microsoft/wassette -- serve --stdio # Install to your profile nix profile install github:microsoft/wassette # Or in a development shell nix develop github:microsoft/wassette ``` -------------------------------- ### Install Wassette on Linux/macOS Source: https://github.com/microsoft/wassette/blob/main/docs/faq.md Installs Wassette using a curl script for Linux and macOS environments. ```bash curl -fsSL https://raw.githubusercontent.com/microsoft/wassette/main/install.sh | bash ``` -------------------------------- ### Build Automation with Justfile Source: https://github.com/microsoft/wassette/blob/main/docs/development/python.md Defines build automation tasks using 'Just', including installing uv, installing dependencies, generating bindings, and componentizing the Python code into a Wasm file. ```Just install-uv: if ! command -v uv &> /dev/null; then curl -LsSf https://astral.sh/uv/install.sh | sh; fi install: install-uv uv pip install componentize-py bindings: uv run componentize-py -d wit -w calculator bindings . build: uv run componentize-py -d wit -w calculator componentize -s main -o calculator.wasm all: bindings build ``` -------------------------------- ### VS Code Configuration for Wassette Serve Source: https://github.com/microsoft/wassette/blob/main/docs/cli.md An example JSON configuration for VS Code to launch the Wassette server with standard input/output communication. ```json { "name": "wassette", "command": "wassette", "args": ["serve", "--stdio"] } ``` -------------------------------- ### Example Permission Policy Source: https://github.com/microsoft/wassette/blob/main/docs/src/overview.md An example of a permission policy for Wassette, defining allow/deny lists for file system paths and network endpoint access. This policy demonstrates how to configure granular access controls for MCP tools. ```yaml version: "1.0" description: "An example policy" permissions: storage: allow: - uri: "fs://workspace/**" access: ["read", "write"] - uri: "fs://config/app.yaml" access: ["read"] network: allow: - host: "api.openai.com" ``` -------------------------------- ### Install uv Package Manager Source: https://github.com/microsoft/wassette/blob/main/docs/development/python.md Installs the uv package manager, a fast Python package and project manager, using a curl script. ```Bash # Install uv if not already installed curl -LsSf https://astral.sh/uv/install.sh | sh ``` -------------------------------- ### Local Development Workflow Source: https://github.com/microsoft/wassette/blob/main/docs/cli.md A step-by-step guide for local component development, including loading, listing, granting permissions, and testing via MCP server. ```bash # 1. Build and load a local component wassette component load file://./target/wasm32-wasi/debug/my-tool.wasm # 2. Check it loaded correctly wassette component list --output-format table # 3. Grant necessary permissions wassette permission grant storage my-tool fs://$(pwd)/workspace --access read,write wassette permission grant network my-tool api.example.com # 4. Verify permissions wassette policy get my-tool --output-format yaml # 5. Test via MCP server wassette serve --stdio ``` -------------------------------- ### Wassette Network Policy Configuration Source: https://github.com/microsoft/wassette/blob/main/examples/fetch-rs/README.md Example `policy.yaml` file to define network permissions for the Wassette fetch component, allowing access to specific hosts. ```YAML version: "1.0" description: "Permission policy for fetch-rs example in wassette" permissions: network: allow: - host: "https://rss.nytimes.com/" ``` -------------------------------- ### Wassette Component Loading Source: https://github.com/microsoft/wassette/blob/main/docs/cli.md Demonstrates how to load WebAssembly components into Wassette, either from an OCI registry or a local file path. Shows examples with custom plugin directories. ```bash # Load a component from GitHub Container Registry wassette component load oci://ghcr.io/yoshuawuyts/time:latest # Load with custom plugin directory wassette component load oci://ghcr.io/microsoft/gomodule:latest --plugin-dir /custom/components # Load a local component file wassette component load file:///path/to/component.wasm # Load with relative path wassette component load file://./my-component.wasm ``` -------------------------------- ### Wassette Component Listing and Formatting Source: https://github.com/microsoft/wassette/blob/main/docs/cli.md Shows how to list all loaded components in Wassette and format the output in JSON, YAML, or a human-readable table. Includes example JSON and table outputs. ```bash # Basic JSON output wassette component list # Pretty-printed JSON wassette component list --output-format json # YAML format wassette component list --output-format yaml # Table format (human-readable) wassette component list --output-format table ``` ```json { "components": [ { "id": "time-component", "schema": { "tools": [ { "name": "get-current-time", "description": "Get the current time", "inputSchema": { "type": "object", "properties": {} } } ] }, "tools_count": 1 } ], "total": 1 } ``` ```yaml # Example YAML output would be similar in structure to JSON but in YAML format. ``` ```table ID | Tools | Description ---------------|-------|---------------------------------- time-component | 1 | Provides time-related functions ``` -------------------------------- ### Verify Wassette Installation Source: https://github.com/microsoft/wassette/blob/main/docs/src/homebrew.md Checks if the 'wassette' tool has been installed correctly by displaying its version. ```bash wassette --version ``` -------------------------------- ### Install jco Source: https://github.com/microsoft/wassette/blob/main/docs/development/javascript.md Installs the JavaScript Component Tools (jco) globally or as a project dependency. ```bash npm install -g @bytecodealliance/jco ``` ```bash npm install @bytecodealliance/jco @bytecodealliance/componentize-js ``` -------------------------------- ### Install and Configure Wassette MCP Server for Claude Code Source: https://github.com/microsoft/wassette/blob/main/docs/src/mcp-clients.md Steps to install Claude Code and add the Wassette MCP server. This involves using npm to install the package and then a specific command to register Wassette as a local stdio server for Claude Code. ```bash npm install -g @anthropic-ai/claude-code ``` ```bash claude mcp add -- wassette wassette serve --stdio ``` ```bash claude mcp list ``` ```bash claude mcp remove wassette ``` -------------------------------- ### Verify Wassette Installation Source: https://github.com/microsoft/wassette/blob/main/docs/src/winget.md Checks if Wassette has been successfully installed by running the version command. ```bash wassette --version ``` -------------------------------- ### Install Wassette using WinGet Manifest Source: https://github.com/microsoft/wassette/blob/main/docs/src/winget.md Downloads the WinGet manifest for Wassette and installs it on the Windows system. Requires administrator privileges for enabling local manifest files if installation fails. ```powershell Invoke-WebRequest -Uri https://raw.githubusercontent.com/microsoft/wassette/main/winget/Microsoft.Wassette.yaml -OutFile Microsoft.Wassette.yaml winget install --manifest Microsoft.Wassette.yaml ``` -------------------------------- ### Install Go Source: https://github.com/microsoft/wassette/blob/main/docs/development/go.md Command to check the installed Go version. Download Go from https://golang.org/dl/. TinyGo currently supports Go versions 1.19 through 1.23. ```Bash # Download from https://golang.org/dl/ # Note: TinyGo currently supports Go 1.19-1.23, not newer versions go version ``` -------------------------------- ### Install and Run wit-bindgen CLI Source: https://github.com/microsoft/wassette/blob/main/docs/development/rust.md Instructions to install the wit-bindgen CLI tool using Cargo and generate Rust bindings from a WIT file. ```Bash # Install wit-bindgen CLI tool cargo install wit-bindgen-cli --version 0.37.0 # Generate Rust bindings from your WIT file wit-bindgen rust wit/ --out-dir src/ --runtime-path wit_bindgen_rt --async none # This creates a generated file (e.g., src/your_component.rs) # Rename it to bindings.rs for consistency mv src/your_component.rs src/bindings.rs ``` -------------------------------- ### Filesystem Access Policy Source: https://github.com/microsoft/wassette/blob/main/examples/filesystem-rs/README.md An example `policy.yaml` file defining permissions for the filesystem component, specifying allowed URIs and access types (read). ```YAML version: "1.0" description: "Permission policy for filesystem access in wassette" permissions: storage: allow: - uri: "fs:///Users/USERNAME/github/wassette" access: ["read"] - uri: "fs:///Users/USERNAME" access: ["read"] - uri: "fs:////" access: ["read"] ``` -------------------------------- ### Wassette Security Policy Example Source: https://github.com/microsoft/wassette/blob/main/docs/faq.md An example of a Wassette policy file defining permissions for file system and network access. This policy specifies read/write access to the workspace directory and read access to a specific configuration file, along with network access to a particular host. ```YAML version: "1.0" description: "Permission policy for filesystem access" permissions: storage: allow: - uri: "fs://workspace/**" access: ["read", "write"] - uri: "fs://config/app.yaml" access: ["read"] network: allow: - host: "api.openai.com" ``` -------------------------------- ### Serve Component with Wassette Source: https://github.com/microsoft/wassette/blob/main/docs/development/python.md Starts a Wassette server to serve the component, enabling live reloading via Server-Sent Events (SSE). ```bash wassette serve --sse --plugin-dir . ``` -------------------------------- ### Load Wassette Go Module Component Source: https://github.com/microsoft/wassette/blob/main/examples/gomodule-go/README.md Shows how to load the Wassette Go module component from its OCI registry location. ```bash Please load the component from oci://ghcr.io/microsoft/gomodule-go:latest ``` -------------------------------- ### npm Scripts for Component Building Source: https://github.com/microsoft/wassette/blob/main/docs/development/javascript.md Example npm scripts in package.json for building and transpiling WebAssembly components using jco. ```json { "scripts": { "build": "jco componentize main.js --wit ./wit -o component.wasm", "build:deps": "jco componentize main.js --wit ./wit -d http -d random -o component.wasm", "transpile": "jco transpile component.wasm -o transpiled" } } ``` -------------------------------- ### Fetch Content with Wassette Source: https://github.com/microsoft/wassette/blob/main/examples/fetch-rs/README.md Command to fetch content from a given URL using the loaded Wassette component. ```Shell Please fetch the content of https://example.com ``` -------------------------------- ### Wassette Server Commands Source: https://github.com/microsoft/wassette/blob/main/docs/cli.md Commands for starting the Wassette MCP server using different transport methods like stdio, HTTP, or Server-Sent Events (SSE). Includes options for specifying plugin directories. ```bash # Start server with stdio transport wassette serve --stdio # Use with specific configuration directory wassette serve --stdio --plugin-dir /custom/components # Start server with HTTP transport wassette serve --http # Use Server-Sent Events (SSE) transport wassette serve --sse ``` -------------------------------- ### Load Wassette Time Server Component Source: https://github.com/microsoft/wassette/blob/main/examples/time-server-js/README.md Demonstrates how to load the Wassette time server component from the OCI registry using the provided command. ```Shell Please load the component from oci://ghcr.io/microsoft/time-server-js:latest ``` -------------------------------- ### Make HTTP Requests (Go) Source: https://github.com/microsoft/wassette/blob/main/docs/development/go.md Shows how to make HTTP GET requests from a component using the wasi-http-go library, including request creation, headers, response handling, and error checking. ```Go import ( "net/http" wasihttp "github.com/ydnar/wasi-http-go/wasihttp ) func httpRequest(url string) ([]byte, error) { client := &http.Client{ Transport: &wasihttp.Transport{}, } req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, fmt.Errorf("failed to create request: %v", err) } req.Header.Set("User-Agent", "my-component/1.0") resp, err := client.Do(req) if err != nil { return nil, fmt.Errorf("HTTP request failed: %v", err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("HTTP request failed with status: %d", resp.StatusCode) } body, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("failed to read response body: %v", err) } return body, nil } ``` -------------------------------- ### wit-bindgen-go Version Check Source: https://github.com/microsoft/wassette/blob/main/docs/development/go.md Command to check the version of wit-bindgen-go. This tool is used for generating Go bindings from WIT files and is automatically installed during the build process. ```Bash # This will be installed automatically during the build process go run go.bytecodealliance.org/cmd/wit-bindgen-go@v0.6.2 version ``` -------------------------------- ### Graceful Error Handling Example (Go) Source: https://github.com/microsoft/wassette/blob/main/docs/development/go.md Demonstrates a best practice for handling errors gracefully within a component function, including input validation and processing errors using cm.Result. ```Go func safeOperation(input string) MyResult { if input == "" { return cm.Err[MyResult]("validation error: input is required") } // Process input... result, err := processInput(input) if err != nil { return cm.Err[MyResult](fmt.Sprintf("processing error: %v", err)) } return cm.OK[MyResult](result) } ``` -------------------------------- ### Wassette CLI Error Handling Examples Source: https://github.com/microsoft/wassette/blob/main/docs/cli.md Illustrates common error scenarios encountered with the Wassette CLI, such as component not found, invalid paths, and permission denied. ```bash # Component not found $ wassette component unload nonexistent Error: Component 'nonexistent' not found # Invalid path $ wassette component load invalid://path Error: Unsupported URI scheme 'invalid'. Use 'file://' or 'oci://' # Permission denied $ wassette permission grant storage my-component /restricted --access write Error: Permission denied: cannot grant write access to /restricted ``` -------------------------------- ### Unit Testing Component Function (Go) Source: https://github.com/microsoft/wassette/blob/main/docs/development/go.md Example of writing a Go unit test for a component function, asserting expected output and checking for errors using the cm.Result type. ```Go package main import ( "testing" "go.bytecodealliance.org/cm" ) func TestProcessData(t *testing.T) { result := processData("test input") if result.IsErr() { t.Fatalf("Expected success, got error: %v", result.Err()) } expected := "Processed: test input" if result.OK() != expected { t.Errorf("Expected %q, got %q", expected, result.OK()) } } ``` -------------------------------- ### Get Weather by Coordinates Source: https://github.com/microsoft/wassette/blob/main/examples/get-weather-js/README.md Retrieves weather information for a specific geographic location using latitude and longitude coordinates. ```Shell get the weather for latitude 43.65 and longitude -79.38 ``` -------------------------------- ### Initialize Go Wasm Component Project Source: https://github.com/microsoft/wassette/blob/main/docs/development/go.md Commands to set up a new Go Wasm component project. This includes creating a project directory, initializing a Go module, and defining a basic WIT interface file. ```Bash # Create project directory mkdir my-component && cd my-component # Initialize Go module go mod init my-component # Create wit directory and main WIT file mkdir wit cat > wit/world.wit << 'EOF' package local:my-component; interface my-interface { // Define your functions here process-data: func(input: string) -> result; } world my-component { include wasi:cli/imports@0.2.0; export my-interface; } EOF ``` -------------------------------- ### Integration Test with Wassette Source: https://github.com/microsoft/wassette/blob/main/docs/development/python.md Instructions for performing integration testing of a WebAssembly component using Wassette. It involves building the component, starting Wassette in serve mode, and then using the '@modelcontextprotocol/inspector' to interact with the running component. ```bash # Build your component just build # Start Wassette with your component wassette serve --sse --plugin-dir . # In another terminal, test with MCP inspector npx @modelcontextprotocol/inspector --cli http://127.0.0.1:9001/sse ``` -------------------------------- ### Wassette Component Policy Source: https://github.com/microsoft/wassette/blob/main/examples/get-weather-js/README.md Defines the permissions for a WebAssembly component, specifying allowed network hosts and environment variables. This example allows access to OpenWeather's API host and the OPENWEATHER_API_KEY environment variable. ```YAML version: "1.0" description: "Permission policy for wassette weather demo" permissions: network: allow: - host: "api.openweathermap.org" environment: allow: - key: "OPENWEATHER_API_KEY" ``` -------------------------------- ### Get File Content Source: https://github.com/microsoft/wassette/blob/main/examples/filesystem-rs/README.md Command to retrieve the content of a specific file using the filesystem component. ```Shell Please get the content of the file examples/filesystem-rs/README.md ``` -------------------------------- ### Get Current Time with Wassette Source: https://github.com/microsoft/wassette/blob/main/examples/time-server-js/README.md Shows the command to query the loaded Wassette component for the current time. ```Shell What is the current time? ``` -------------------------------- ### Load Wassette Component Source: https://github.com/microsoft/wassette/blob/main/examples/get-weather-js/README.md Loads the 'get-weather-js' Wassette component from the OCI registry. This component is used to retrieve weather information. ```Shell Please load the component from oci://ghcr.io/microsoft/get-weather-js:latest ``` -------------------------------- ### Set OpenWeather API Key Source: https://github.com/microsoft/wassette/blob/main/examples/get-weather-js/README.md Exports the OpenWeather API key as an environment variable, which is required by the get-weather-js component to fetch weather data. ```Bash export OPENWEATHER_API_KEY="your_api_key_here" ``` -------------------------------- ### Manual Component Build Steps Source: https://github.com/microsoft/wassette/blob/main/docs/development/python.md Manual steps to componentize Python code into a WebAssembly component. ```bash uv run componentize-py -d wit -w calculator bindings . uv run componentize-py -d wit -w calculator componentize -s main -o calculator.wasm ``` -------------------------------- ### Wassette Integration Testing Commands Source: https://github.com/microsoft/wassette/blob/main/docs/development/rust.md Provides bash commands for building a WebAssembly component for WASI version 2 and starting the Wassette server for local integration testing. This setup allows for testing components in a simulated environment. ```bash # Build your component CARGO_BUILD_TARGET=wasm32-wasip2 cargo build --release # Start Wassette with your component # Ensure your component is in the current directory or specify --plugin-dir wassette serve --sse --plugin-dir . ``` -------------------------------- ### Project Structure for Go Wasm Component Source: https://github.com/microsoft/wassette/blob/main/docs/development/go.md Illustrates a typical directory structure for a Go WebAssembly component project. It includes directories for WIT definitions, generated bindings, the main Go implementation, and module definition files. ```Bash my-component/ ├── wit/ │ ├── world.wit # Main WIT interface definition │ ├── deps/ # WIT dependencies (auto-managed) │ └── wkg.lock # Dependency lock file ├── gen/ # Generated Go bindings (auto-generated) ├── main.go # Your component implementation ├── go.mod # Go module definition └── go.sum # Go dependency checksums ``` -------------------------------- ### Enable Local Manifest Files for WinGet Source: https://github.com/microsoft/wassette/blob/main/docs/src/winget.md Enables the local installation feature for WinGet, which is necessary if direct installation from a downloaded manifest fails. ```powershell winget settings --enable LocalManifestFiles ``` -------------------------------- ### Load Wassette Component from Local File Source: https://github.com/microsoft/wassette/blob/main/docs/faq.md Demonstrates how to load a WebAssembly component from a local file path using Wassette. ```text Please load the component from ./path/to/component.wasm ``` -------------------------------- ### Install Rust Toolchain Source: https://github.com/microsoft/wassette/blob/main/docs/development/rust.md Installs the Rust toolchain using the official installation script. Ensures the latest version or a specific version is available for Wasm development. ```Bash curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source ~/.cargo/env ``` -------------------------------- ### Complete Component Creation Walkthrough Source: https://github.com/microsoft/wassette/blob/main/docs/development/rust.md A step-by-step guide to creating a Rust WebAssembly component, including setting up the project, defining the WIT interface, configuring Cargo.toml, generating bindings, implementing the component logic, and building the final Wasm file. ```bash # Create new project cargo new --lib hello-component cd hello-component # Create the WIT directory and interface mkdir wit cat > wit/world.wit << 'EOF' package component:hello-component; world hello-component { export greet: func(name: string) -> string; } EOF # Configure Cargo.toml cat > Cargo.toml << 'EOF' [package] name = "hello-component" version = "0.1.0" edition = "2021" license = "MIT" [dependencies] wit-bindgen-rt = { version = "0.37.0", features = ["bitflags"] } [lib] crate-type = ["cdylib"] [profile.release] codegen-units = 1 opt-level = "s" debug = false strip = true lto = true [package.metadata.component] package = "component:hello-component" [workspace] EOF # Install the WASI target rustup target add wasm32-wasip2 # Install wit-bindgen (if not already installed) cargo install wit-bindgen-cli --version 0.37.0 # Generate bindings wit-bindgen rust wit/ --out-dir src/ --runtime-path wit_bindgen_rt --async none mv src/hello_component.rs src/bindings.rs # Implement the component cat > src/lib.rs << 'EOF' #[allow(warnings)] mod bindings; use bindings::Guest; struct Component; impl Guest for Component { fn greet(name: String) -> String { format!("Hello, {}!", name) } } bindings::export!(Component with_types_in bindings); EOF # Build the component cargo build --target wasm32-wasip2 --release # Check the result ls -la target/wasm32-wasip2/release/hello_component.wasm ``` -------------------------------- ### Create Project Structure Source: https://github.com/microsoft/wassette/blob/main/docs/development/python.md Commands to create a new directory for a Python Wasm component and set up the necessary subdirectories for WIT definitions and generated bindings. ```Bash # Create a new directory for your component mkdir my-python-tool cd my-python-tool # Create the necessary directories mkdir wit wit_world ``` -------------------------------- ### Wassette Management Tools Source: https://github.com/microsoft/wassette/blob/main/docs/faq.md Lists the built-in command-line tools provided by Wassette for managing WebAssembly components and their permissions. ```text load-component: Load WebAssembly components unload-component: Unload components list-components: List loaded components get-policy: Get policy information grant-storage-permission: Grant storage access grant-network-permission: Grant network access grant-environment-variable-permission: Grant environment variable access revoke-storage-permission: Revoke storage access permissions revoke-network-permission: Revoke network access permissions revoke-environment-variable-permission: Revoke environment variable access permissions reset-permission: Reset all permissions for a component ``` -------------------------------- ### Build and Serve Component Source: https://github.com/microsoft/wassette/blob/main/docs/development/javascript.md Commands to build a component using npm and serve it locally using Wassette, enabling local testing and debugging. ```bash # Start Wassette with your component directory wassette serve --sse --plugin-dir . ``` -------------------------------- ### Evaluate Python Expression with Wassette Source: https://github.com/microsoft/wassette/blob/main/examples/eval-py/README.md Demonstrates how to evaluate a Python expression using the loaded Wassette component. The example shows a simple addition operation. ```Shell Please evaluate the python expression '2 + 2' ``` -------------------------------- ### TypeScript User Service Example Source: https://github.com/microsoft/wassette/blob/main/docs/development/javascript.md An example of a UserService implemented in TypeScript, demonstrating type safety for user data and service methods. It includes creating and retrieving users. ```typescript interface User { id: number; name: string; email?: string; } interface UserService { createUser(name: string, email?: string): User; getUser(id: number): User | undefined; } let nextId = 1; const users = new Map(); export const userService: UserService = { createUser(name: string, email?: string): User { const user: User = { id: nextId++, name, email }; users.set(user.id, user); return user; }, getUser(id: number): User | undefined { return users.get(id); } }; ``` -------------------------------- ### Implement Wassette Component (Go) Source: https://github.com/microsoft/wassette/blob/main/docs/development/go.md Demonstrates how to implement a component's main function, register exports, and handle results using the cm.Result type in Go. ```Go package main import ( "encoding/json" "fmt" // Import the generated bindings "my-component/gen/local/my-component/my-interface" "go.bytecodealliance.org/cm" ) func init() { // Register your function implementations myinterface.Exports.ProcessData = processData } // Define result types using the cm package type ProcessDataResult = cm.Result[string, string, string] // Implement your function func processData(input string) ProcessDataResult { // Your implementation logic here result := fmt.Sprintf("Processed: %s", input) // Return success return cm.OK[ProcessDataResult](result) // For errors, return: // return cm.Err[ProcessDataResult]("error message") } func main() { // Required but can be empty for components } ``` -------------------------------- ### Generate Bindings and Build Component Source: https://github.com/microsoft/wassette/blob/main/docs/development/python.md Generates language bindings and builds the WebAssembly component. ```bash just all ``` -------------------------------- ### Load Wassette Component from OCI Registry Source: https://github.com/microsoft/wassette/blob/main/docs/faq.md Demonstrates how to load a WebAssembly component from an OCI registry using Wassette. ```text Please load the component from oci://ghcr.io/microsoft/time-server-js:latest ``` -------------------------------- ### Generate Go Bindings for Wasm Component Source: https://github.com/microsoft/wassette/blob/main/docs/development/go.md Command to generate Go bindings from WIT files using the `wit-bindgen-go` tool. The generated `.go` files, which correspond to the WIT interface definitions, are placed in the `gen` folder. ```Bash go run go.bytecodealliance.org/cmd/wit-bindgen-go@v0.6.2 generate -o gen ./wit ```