#!/bin/bash
# Build script for AgentLink SDK WASM

set -e

echo "Building AgentLink SDK WASM..."

# Build the WASM target
cargo build -p agentlink-wasm --target wasm32-unknown-unknown --release

# Check if wasm-bindgen is installed
if ! command -v wasm-bindgen &> /dev/null; then
    echo "wasm-bindgen not found, installing..."
    cargo install wasm-bindgen-cli
fi

# Generate JavaScript/TypeScript bindings
mkdir -p pkg
wasm-bindgen target/wasm32-unknown-unknown/release/agentlink_wasm.wasm \
    --out-dir pkg \
    --target web \
    --typescript

echo "Build complete! Output in wasm/pkg/"
echo ""
echo "Files generated:"
ls -lh pkg/
