agentlink-wasm 0.1.1

AgentLink SDK WASM - WebAssembly bindings for browser/Node.js
docs.rs failed to build agentlink-wasm-0.1.1
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

AgentLink SDK WASM

WebAssembly bindings for AgentLink SDK, enabling usage in browsers and Node.js.

Building

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

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

Usage

In a Web Application

<!DOCTYPE html>
<html>
<head>
    <script type="module">
        import init, { JsHttpClient, JsMqttClient, getVersion, init as sdkInit } from './pkg/agentlink_wasm.js';
        
        async function main() {
            // Initialize the WASM module
            await init();
            
            // Initialize SDK logging
            sdkInit();
            
            console.log('SDK Version:', getVersion());
            
            // Create HTTP client
            const httpClient = new JsHttpClient('https://api.example.com');
            
            // Set auth token
            httpClient.setAuthToken('your-auth-token');
            
            // Make requests
            try {
                const response = await httpClient.get('/users/me');
                console.log('User:', response);
            } catch (e) {
                console.error('Error:', e);
            }
            
            // Create MQTT client
            const mqttClient = new JsMqttClient();
            
            // Set up event handler
            mqttClient.onEvent((event) => {
                console.log('MQTT Event:', event);
            });
            
            // Connect to broker
            await mqttClient.connect('wss://mqtt.example.com/mqtt', 'client-1', 'username');
            
            // Subscribe to topic
            await mqttClient.subscribe('chat/room/1', 1);
            
            // Publish message
            const payload = new TextEncoder().encode('Hello, World!');
            await mqttClient.publish('chat/room/1', payload, 1);
        }
        
        main();
    </script>
</head>
<body>
    <h1>AgentLink SDK WASM Demo</h1>
</body>
</html>

In Node.js

Use --target bundler or --target nodejs when running wasm-bindgen:

wasm-bindgen target/wasm32-unknown-unknown/release/agentlink_wasm.wasm \
  --out-dir pkg-node \
  --target nodejs
const { JsHttpClient, JsMqttClient, getVersion } = require('./pkg-node/agentlink_wasm.js');

console.log('SDK Version:', getVersion());

const client = new JsHttpClient('https://api.example.com');
// ... use the client

API

JsHttpClient

  • new JsHttpClient(baseUrl: string) - Create a new HTTP client
  • setAuthToken(token: string) - Set authentication token
  • getAuthToken(): string | undefined - Get current auth token
  • get(path: string): Promise<any> - Perform GET request
  • post(path: string, body: any): Promise<any> - Perform POST request
  • put(path: string, body: any): Promise<any> - Perform PUT request
  • delete(path: string): Promise<any> - Perform DELETE request

JsMqttClient

  • new JsMqttClient() - Create a new MQTT client
  • connect(brokerUrl: string, clientId: string, username?: string): Promise<void> - Connect to broker
  • disconnect(): Promise<void> - Disconnect from broker
  • subscribe(topic: string, qos: number): Promise<void> - Subscribe to topic
  • unsubscribe(topic: string): Promise<void> - Unsubscribe from topic
  • publish(topic: string, payload: Uint8Array, qos: number): Promise<void> - Publish message
  • getConnectionState(): string - Get connection state
  • onEvent(callback: Function) - Set event callback

Functions

  • init() - Initialize the SDK (sets up panic hook and logger)
  • getVersion(): string - Get SDK version
  • loginWithEmailCode(baseUrl: string, email: string, code: string): Promise<any> - Login helper

Features

  • ✅ HTTP Client using Fetch API
  • ✅ MQTT Client using WebSocket
  • ✅ TypeScript definitions included
  • ✅ Async/Promise-based API
  • ✅ Event callbacks for MQTT

Notes

  • The MQTT client uses WebSocket connections (ws:// or wss://)
  • MQTT URLs are automatically converted: mqtt://ws://, mqtts://wss://
  • The SDK requires a modern browser with WebAssembly support