Headless client overview
AutopilotClient is the framework-agnostic core of the library. Everything else in the package — the Pinia store, the bar — is built on top of it.
Importing
import {
AutopilotClient,
useAutopilotClient,
setAutopilotClient,
} from '@llmor/autopilot-core';Creating an instance
You have two options.
Option 1: explicit instance
const client = new AutopilotClient();Create as many as you like. None of them touch global state.
Option 2: singleton
const client = useAutopilotClient(); // returns a shared singletonThe Pinia store and enableAutopilotBar() both look up the singleton, so this option is convenient when you want to share one client across loosely coupled code. If you create your own instance with new, register it as the singleton:
const client = new AutopilotClient();
setAutopilotClient(client);Lifecycle
const client = new AutopilotClient();
client.on('status', (status) => console.log(status));
await client.connect({
conversationUrl: 'https://llmor.example.com/v1/conversations/<token>',
});
// … use the client …
client.disconnect();disconnect() tears down the Socket.IO connection, clears pending timers, and emits status: 'disconnected'. Registered functions and context are kept on the instance — calling connect() again restores them.
Dependency injection
Every external dependency (fetch, io, setTimeout, clearTimeout) can be overridden through the constructor — useful for tests:
const client = new AutopilotClient({
fetch: myFetch,
io: myIoFactory,
});The defaults pull from globalThis.
What the client gives you
| Area | Methods | Page |
|---|---|---|
| Connection | connect, disconnect, isConnected, getStatus, interruptStreaming | Connection |
| Functions | registerFunction, unregisterFunction, clearFunctions, hasFunction, getRegisteredFunctions | Functions |
| Context | getContext, setContext, updateContext, mergeContext, clearContext, flushContextSync | Context |
| Conversation | getConversation, getConversationMessages, engageAutopilot, interactWithConversation, resetConversation, fetchConversation | Conversation |
| Streaming | getStreamingMessage, isStreaming, interruptStreaming | Streaming |
| Events | on, once, off | Events |