DeviceClient
The main class for connecting a device to a Lua AI agent. ExtendsEventEmitter.
Constructor
Configuration object for the device client. See DeviceClientConfig below.
DeviceClientConfig
Agent ID to connect to.
API key for authentication.
Unique name for this device. Lowercase with hyphens.
Commands this device supports. Sent to the server at connect time.
Transport protocol.
Server URL for Socket.IO transport.
MQTT broker URL. Required when
transport is 'mqtt'.CDN URL for file uploads and downloads.
Optional device group name.
Methods
connect()
Connect to the device gateway. Resolves when the connection is established and authenticated. Automatically reconnects on disconnect unlessdisconnect() was called.
disconnect()
Disconnect from the device gateway. Stops auto-reconnection.isConnected()
Check if the client is currently connected.onCommand()
Register a handler for a specific command name. The handler receives the command payload and must return a result (or throw an error).Command name to handle.
Async function that executes the command. Return value is sent back to the agent. Thrown errors are sent as error responses.
trigger()
Fire a trigger event to the agent. Resolves when the server acknowledges receipt (not execution completion).Trigger name.
Trigger payload data.
onTriggerResult()
Listen for trigger execution results from the agent. Optional — triggers are fire-and-forget by default.Trigger name to listen for.
Callback function receiving the trigger execution result.
Properties
cdn
CDN client for uploading and downloading files. Available immediately after construction.CDN
The CDN class provides file upload and download capabilities.cdn.upload()
Upload a file to the Lua CDN.File content.
Filename with extension.
MIME type. Defaults to
application/octet-stream.CdnUploadResult
cdn.download()
Download a file from the CDN.cdn.getUrl()
Get the public URL for a file.Events
TheDeviceClient extends EventEmitter and emits the following events:
| Event | Payload | Description |
|---|---|---|
connected | (none) | Initial connection established |
reconnected | (none) | Reconnected after a disconnect |
disconnected | reason: string | Connection lost |
error | error: any | Connection or protocol error |
trigger_ack | DeviceTriggerAckMessage | Server acknowledged a trigger |
trigger_error | error: any | Trigger delivery error |
DeviceCommandDefinition
Describes a command the device supports.Command name.
Human-readable description shown to the AI agent.
JSON Schema for input parameters.
Command timeout in milliseconds.
Retry configuration for failed commands.
Type Exports
The package exports the following types:Next Steps
Node.js Client Guide
Usage guide with examples
MicroPython Client
API reference for the MicroPython client
Quickstart
Get started in 5 minutes
Examples
Full working examples

