@alfe.ai/chat
v0.0.19
Published
Runtime-agnostic WebSocket client for the Alfe chat service
Readme
@alfe.ai/chat
Runtime-agnostic WebSocket client for the Alfe chat service
Part of Alfe — the operating system for AI agents: build, deploy, and run agents with persistent memory, identity, integrations, and channels. See the documentation to get started.
Install
npm install @alfe.ai/chatUsage
import { ChatServiceClient, resolveAlfeChat } from '@alfe.ai/chat'
const { apiKey, chatWsUrl } = resolveAlfeChat()
if (!apiKey || !chatWsUrl) throw new Error('Alfe chat is not configured')
const client = new ChatServiceClient({
apiKey,
wsUrl: chatWsUrl,
onRequest: async (request) => {
// Dispatch the authenticated request to the agent runtime, then reply with
// client.sendResponse(request.id, true, result).
},
onConnectionChange: (connected) => {
console.log(`Chat relay ${connected ? 'connected' : 'disconnected'}`)
},
})
client.start()start() is idempotent and the client reconnects with bounded exponential
backoff and jitter. stop() permanently fences callbacks from the old socket
until start() is called again.
Ordinary responses/events sent while disconnected use a bounded in-memory
queue. sendRequest() is deliberately different: it requires a live socket
and is never moved into the offline queue, so a timed-out RPC cannot execute
later after reconnect.
resolveAlfeChat() normalizes explicit configuration, then reads
~/.alfe/config.toml, then falls back to ALFE_API_KEY and
ALFE_CHAT_WS_URL.
Links
- 🌐 Website: https://alfe.ai
- 📚 Docs: https://docs.alfe.ai
