Skip to content

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

ts
import {
  AutopilotClient,
  useAutopilotClient,
  setAutopilotClient,
} from '@llmor/autopilot-core';

Creating an instance

You have two options.

Option 1: explicit instance

ts
const client = new AutopilotClient();

Create as many as you like. None of them touch global state.

Option 2: singleton

ts
const client = useAutopilotClient(); // returns a shared singleton

The 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:

ts
const client = new AutopilotClient();
setAutopilotClient(client);

Lifecycle

ts
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:

ts
const client = new AutopilotClient({
  fetch: myFetch,
  io: myIoFactory,
});

The defaults pull from globalThis.

What the client gives you

AreaMethodsPage
Connectionconnect, disconnect, isConnected, getStatus, interruptStreamingConnection
FunctionsregisterFunction, unregisterFunction, clearFunctions, hasFunction, getRegisteredFunctionsFunctions
ContextgetContext, setContext, updateContext, mergeContext, clearContext, flushContextSyncContext
ConversationgetConversation, getConversationMessages, engageAutopilot, interactWithConversation, resetConversation, fetchConversationConversation
StreaminggetStreamingMessage, isStreaming, interruptStreamingStreaming
Eventson, once, offEvents