DeviceClient
The main class for connecting a device to a Lua AI agent. ExtendsEventEmitter.
Constructor
DeviceClientConfig
required
Configuration object for the device client. See DeviceClientConfig below.
DeviceClientConfig
At least one credential field,deviceCredential or apiKey, is required.
string
required
Agent ID to connect to.
string
Device credential for new provisioning. See Device credentials.
string
Existing compatibility field, supported indefinitely. Non-dotted legacy keys also remain valid indefinitely.
string
required
Unique name for this device. Lowercase with hyphens.
DeviceCommandDefinition[]
Commands this device supports. Sent to the server at connect time.
'socketio' | 'mqtt'
default:"socketio"
Transport protocol.
string
default:"https://api.heylua.ai"
Server URL for Socket.IO transport.
string
default:"wss://mqtt.heylua.ai/mqtt"
MQTT broker URL. Required when
transport is 'mqtt'.string
default:"https://cdn.heylua.ai"
CDN URL for file uploads and downloads.
string
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).string
required
Command name to handle.
(payload: any) => Promise<any>
required
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).string
required
Trigger name.
any
required
Trigger payload data.
onTriggerResult()
Listen for trigger execution results from the agent. Optional — triggers are fire-and-forget by default.string
required
Trigger name to listen for.
(result: any) => void
required
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.Buffer | Blob
required
File content.
string
required
Filename with extension.
string
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:
DeviceCommandDefinition
Describes a command the device supports.string
required
Command name.
string
required
Human-readable description shown to the AI agent.
Record<string, any>
JSON Schema for input parameters.
number
default:"30000"
Command timeout in milliseconds.
{ maxAttempts: number; backoffMs: number }
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

