Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/iii-hq/sdk/llms.txt

Use this file to discover all available pages before exploring further.

init()

Initialize a new III SDK instance and connect to the engine.
import { init } from 'iii-sdk'

const iii = init(address, options?)
address
string
required
WebSocket URL of the III Engine (e.g., ws://localhost:49199)
options
InitOptions
Optional configuration for the SDK instance
iii
ISdk
An initialized III SDK instance

Example

import { init } from 'iii-sdk'

const iii = init('ws://localhost:49199', {
  workerName: 'api-worker-1',
  invocationTimeoutMs: 30000, // 30 seconds
  reconnectionConfig: {
    maxRetries: 10,
    initialDelayMs: 500
  },
  otel: {
    serviceName: 'my-api-service',
    serviceVersion: '1.0.0',
    metricsEnabled: true
  }
})

Connection Management

getConnectionState()

Get the current connection state.
const state = iii.getConnectionState()
state
IIIConnectionState
Current connection state: 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'failed'

onConnectionStateChange()

Register a callback to be notified of connection state changes.
const unsubscribe = iii.onConnectionStateChange((state) => {
  console.log('Connection state:', state)
})

// Later: unsubscribe
unsubscribe()
callback
(state: IIIConnectionState) => void
required
Function called when connection state changes
unsubscribe
() => void
Function to unregister the callback

Example: Connection State Handling

import { init } from 'iii-sdk'

const iii = init('ws://localhost:49199')

iii.onConnectionStateChange((state) => {
  switch (state) {
    case 'connected':
      console.log('✓ Connected to III Engine')
      break
    case 'reconnecting':
      console.warn('⟳ Reconnecting...')
      break
    case 'failed':
      console.error('✗ Connection failed')
      break
  }
})

Lifecycle Management

shutdown()

Gracefully shutdown the SDK, cleaning up all resources.
await iii.shutdown()
This method:
  • Stops all metrics reporting
  • Flushes and shuts down OpenTelemetry
  • Rejects all pending invocations
  • Closes the WebSocket connection
  • Clears all callbacks

Example: Graceful Shutdown

import { init } from 'iii-sdk'

const iii = init('ws://localhost:49199')

// Handle shutdown signals
process.on('SIGINT', async () => {
  console.log('Shutting down...')
  await iii.shutdown()
  process.exit(0)
})

process.on('SIGTERM', async () => {
  console.log('Shutting down...')
  await iii.shutdown()
  process.exit(0)
})

Engine Queries

listFunctions()

List all functions registered across the III network.
const functions = await iii.listFunctions()
functions
FunctionInfo[]
Array of registered function information

listWorkers()

List all workers connected to the engine.
const workers = await iii.listWorkers()
workers
WorkerInfo[]
Array of connected worker information

Example: Service Discovery

// Discover available functions
const functions = await iii.listFunctions()

console.log('Available functions:')
for (const fn of functions) {
  console.log(`- ${fn.function_id}: ${fn.description || 'No description'}`)
}

// Monitor worker health
const workers = await iii.listWorkers()

console.log(`\n${workers.length} workers online`)
for (const worker of workers) {
  console.log(`- ${worker.name}: ${worker.function_count} functions, ${worker.active_invocations} active`)
}

Build docs developers (and LLMs) love