@aichatbot-saas/core
v0.1.0
Published
Framework-agnostic core (REST client, theme, headless chat controller) for the AIChatbot web SDKs.
Maintainers
Readme
@aichatbot-saas/core
Framework-agnostic core for the AIChatbot web SDKs. It contains everything except
the UI: the REST client, the theme model, conversation persistence, and a headless
chat controller that holds all behavior and exposes immutable state via a
subscribe() pattern.
The React, Vue, and Angular packages all build on this — so the logic lives here once. You can also use it standalone to build your own UI.
This is the shared dependency of
@aichatbot-saas/react,@aichatbot-saas/vue, and@aichatbot-saas/angular. For the full contract see../README.md.
Install
npm install @aichatbot-saas/coreHeadless controller
import { createChatController } from '@aichatbot-saas/core';
const chat = createChatController({
apiKey: 'pk_live_xxx',
apiUrl: 'https://api.you.com',
theme: { primaryColor: '#16a34a' }, // optional local overrides
});
const unsubscribe = chat.subscribe((state) => {
// state: { status, config, theme, messages, suggestions, isTyping, sending, error }
render(state);
});
await chat.start(); // load config, greeting, starter suggestions
await chat.send('Hi there'); // optimistic user bubble -> typing -> bot reply
// chat.submitFeedback(botMessage, 'positive');
// unsubscribe(); chat.destroy();State is replaced (new object identity) on every change, so it plugs straight into
React's useSyncExternalStore, Vue reactivity, or Angular change detection.
Just the client
import { AIChatbotClient } from '@aichatbot-saas/core';
const client = new AIChatbotClient({ apiKey: 'pk_live_xxx', apiUrl: 'https://api.you.com' });
const config = await client.fetchConfig();
const reply = await client.sendMessage({ text: 'Hello', conversationId: null });Exports
createChatController(opts)/ChatController— headless state machineAIChatbotClient— REST client (fetchConfig,fetchSuggestions,sendMessage,sendFeedback)resolveTheme(config, overrides),DEFAULT_THEME— theme normalizationgetConversationId/setConversationId/isStorageAvailable— SSR-safe persistencesuggestionLabel— normalize a suggestion (object-or-string) to a label- Types:
ChatConfig,ChatMessage,ChatResponse,ChatTheme,ChatState,Suggestion, …
License
MIT
