chat-load-utils
v1.0.0
Published
A utility library for loading and processing chat messages and conversations
Maintainers
Readme
Chat Load Utils
A utility library for loading and processing chat messages, conversations, and managing chat history with both server and local storage support.
Installation
npm install chat-load-utilsUsage
import {
loadAndProcessMessages,
loadMessagesFromLocalStorage,
loadLocalConversations,
processConversationResponse,
restoreChartState,
scrollToBottom,
createReactiveObject,
createAPIConfig
} from 'chat-load-utils';
// Create reactive objects
const messages = createReactiveObject([]);
const conversationId = createReactiveObject('');
// Create API config
const API_CONFIG = createAPIConfig({
history: 'local', // or 'server'
conversations: 'server' // or 'local'
});
// Load messages from API response
await loadAndProcessMessages(
response,
messages,
conversationId,
'conversation-123',
messagesContainer,
'Welcome message',
dialogText,
isShowDialog,
conversations,
currentChat
);
// Load messages from localStorage
const loaded = loadMessagesFromLocalStorage(
'conversation-123',
messages,
messagesContainer,
'Welcome message',
API_CONFIG
);
// Load conversations from localStorage
loadLocalConversations(conversations, hasMoreConversations, API_CONFIG);API Reference
Core Functions
scrollToBottom(element)- Scroll to the bottom of the specified elementloadAndProcessMessages(response, messages, conversationId, id, messagesContainer, PROMPT_MESSAGE, Dialogtext, isShowDialog, conversations, currentChat, messageIds)- Load and process messages from API responseloadMessagesFromLocalStorage(id, messages, messagesContainer, PROMPT_MESSAGE, API_CONFIG)- Load messages from localStoragerestoreChartState(messages, conversationId, messagesContainer)- Restore chart state from localStorageloadLocalConversations(conversations, hasMoreConversations, API_CONFIG)- Load conversations from localStorageprocessConversationResponse(response, conversations, hasMoreConversations)- Process conversation API response
Utility Functions
createReactiveObject(value)- Create a simple reactive object (Vue compatibility)createAPIConfig(config)- Create API configuration object
Features
- Dual Storage Support: Support for both server API and localStorage
- Message Processing: Comprehensive message loading and processing
- Conversation Management: Load and manage chat conversations
- State Restoration: Restore chart and conversation states
- Error Handling: Robust error handling for network and storage operations
- Vue Compatibility: Helper functions for Vue reactivity patterns
Storage Modes
Server Mode
- Messages and conversations are loaded from API endpoints
- Requires proper API configuration
Local Mode
- Messages and conversations are loaded from localStorage
- Useful for offline functionality or testing
Browser Support
This library requires modern browser features:
- ES6 Modules
- Fetch API
- localStorage
- async/await
License
MIT
