onairos 2.0.7 → 2.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SDK_MIGRATION_SUMMARY.md +140 -0
- package/dist/iframe.bundle.js +1 -1
- package/dist/iframe.bundle.js.map +1 -1
- package/dist/onairos.bundle.js +1 -1
- package/dist/onairos.bundle.js.map +1 -1
- package/dist/onairos.esm.js +1 -1
- package/dist/onairos.esm.js.map +1 -1
- package/onairos.d.ts +0 -182
- package/package.json +8 -18
- package/src/components/DataRequest.js +138 -127
- package/src/index.js +0 -9
- package/src/onairos.jsx +0 -16
- package/src/sdk/LLMWrapper.js +0 -221
- package/src/sdk/MemoryManager.js +0 -290
- package/src/sdk/OnairosClient.js +0 -152
- package/src/sdk/SessionManager.js +0 -257
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# Onairos LLM SDK - Backend Migration Summary
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
The Onairos LLM SDK has been **migrated from frontend to backend** to improve security, performance, and enable server-side RAG (Retrieval-Augmented Generation) capabilities. This document summarizes the SDK components that were removed from the frontend package.
|
|
5
|
+
|
|
6
|
+
## Architecture Summary
|
|
7
|
+
|
|
8
|
+
### Core Components Migrated
|
|
9
|
+
|
|
10
|
+
#### 1. **OnairosClient** (`OnairosClient.js`)
|
|
11
|
+
- **Purpose**: Main SDK entry point providing unified completion API with RAG enhancement
|
|
12
|
+
- **Key Features**:
|
|
13
|
+
- Unified interface for multiple LLM providers
|
|
14
|
+
- RAG-enhanced personalization using user memory
|
|
15
|
+
- Session management and validation
|
|
16
|
+
- User memory management (store/retrieve/clear)
|
|
17
|
+
|
|
18
|
+
#### 2. **LLMWrapper** (`LLMWrapper.js`)
|
|
19
|
+
- **Purpose**: Unified interface for multiple LLM providers
|
|
20
|
+
- **Supported Providers**:
|
|
21
|
+
- **OpenAI**: GPT-4, GPT-4-turbo, GPT-3.5-turbo, O1-preview, O1-mini
|
|
22
|
+
- **Anthropic**: Claude-3-opus, Claude-3-sonnet, Claude-3-haiku, Claude-3.5-sonnet
|
|
23
|
+
- **Google**: Gemini-pro, Gemini-pro-vision, Gemini-1.5-pro, Gemini-1.5-flash
|
|
24
|
+
- **Features**:
|
|
25
|
+
- Standardized response format across providers
|
|
26
|
+
- Message format conversion for each provider
|
|
27
|
+
- Error handling and API key management
|
|
28
|
+
|
|
29
|
+
#### 3. **MemoryManager** (`MemoryManager.js`)
|
|
30
|
+
- **Purpose**: RAG functionality with vector storage and memory extraction
|
|
31
|
+
- **Key Features**:
|
|
32
|
+
- **Pinecone Integration**: Vector database for semantic search
|
|
33
|
+
- **OpenAI Embeddings**: text-embedding-3-small model
|
|
34
|
+
- **Memory Extraction**: Intelligent extraction of meaningful data from conversations
|
|
35
|
+
- **Semantic Retrieval**: Context-aware memory retrieval for personalization
|
|
36
|
+
- **User Isolation**: Per-user memory management and cleanup
|
|
37
|
+
|
|
38
|
+
#### 4. **SessionManager** (`SessionManager.js`)
|
|
39
|
+
- **Purpose**: User authentication and session isolation
|
|
40
|
+
- **Features**:
|
|
41
|
+
- **JWT Token Management**: Secure session tokens with expiration
|
|
42
|
+
- **User Validation**: Session validation and user access control
|
|
43
|
+
- **API Key Generation**: Server-to-server authentication
|
|
44
|
+
- **Guest Sessions**: Anonymous user support
|
|
45
|
+
|
|
46
|
+
## Dependencies Migrated
|
|
47
|
+
|
|
48
|
+
The following npm packages were used in the frontend SDK and are now backend dependencies:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"@anthropic-ai/sdk": "^0.24.3",
|
|
53
|
+
"@google/generative-ai": "^0.15.0",
|
|
54
|
+
"@pinecone-database/pinecone": "^2.2.2",
|
|
55
|
+
"openai": "^4.52.7",
|
|
56
|
+
"jsonwebtoken": "^9.0.0",
|
|
57
|
+
"uuid": "^9.0.0"
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Backend Integration
|
|
62
|
+
|
|
63
|
+
### User Hash System
|
|
64
|
+
The frontend now generates a `userHash` for each user that is sent to the backend. This hash enables:
|
|
65
|
+
|
|
66
|
+
1. **Automatic Memory Integration**: Backend LLM calls can automatically include relevant user memories
|
|
67
|
+
2. **User Isolation**: Secure separation of user data in the vector database
|
|
68
|
+
3. **Personalization**: Context-aware responses based on user history
|
|
69
|
+
|
|
70
|
+
### API Integration Flow
|
|
71
|
+
```
|
|
72
|
+
Frontend → API Call with userHash → Backend LLM SDK → Enhanced Response
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Migration Benefits
|
|
76
|
+
|
|
77
|
+
### Security
|
|
78
|
+
- ✅ API keys no longer exposed in frontend
|
|
79
|
+
- ✅ User data processing happens server-side
|
|
80
|
+
- ✅ Secure session management
|
|
81
|
+
|
|
82
|
+
### Performance
|
|
83
|
+
- ✅ Reduced frontend bundle size
|
|
84
|
+
- ✅ Server-side caching and optimization
|
|
85
|
+
- ✅ Better error handling and retry logic
|
|
86
|
+
|
|
87
|
+
### Scalability
|
|
88
|
+
- ✅ Centralized LLM provider management
|
|
89
|
+
- ✅ Shared memory and session state
|
|
90
|
+
- ✅ Better resource utilization
|
|
91
|
+
|
|
92
|
+
## Frontend Changes
|
|
93
|
+
|
|
94
|
+
### Removed Files
|
|
95
|
+
- `src/sdk/OnairosClient.js` (152 lines)
|
|
96
|
+
- `src/sdk/LLMWrapper.js` (221 lines)
|
|
97
|
+
- `src/sdk/MemoryManager.js` (290 lines)
|
|
98
|
+
- `src/sdk/SessionManager.js` (257 lines)
|
|
99
|
+
|
|
100
|
+
### Added Features
|
|
101
|
+
- User hash generation in `DataRequest.js`
|
|
102
|
+
- Simplified data request flow (Basic Info + Memories)
|
|
103
|
+
- Enhanced API response handling with user hash
|
|
104
|
+
|
|
105
|
+
## Backend SDK Usage
|
|
106
|
+
|
|
107
|
+
The backend Onairos SDK can now be used to automatically enhance LLM calls with user context:
|
|
108
|
+
|
|
109
|
+
```javascript
|
|
110
|
+
// Backend usage example
|
|
111
|
+
const onairos = new OnairosClient({
|
|
112
|
+
openaiApiKey: process.env.OPENAI_API_KEY,
|
|
113
|
+
anthropicApiKey: process.env.ANTHROPIC_API_KEY,
|
|
114
|
+
pineconeApiKey: process.env.PINECONE_API_KEY,
|
|
115
|
+
// ... other config
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Enhanced completion with user memory
|
|
119
|
+
const response = await onairos.completions({
|
|
120
|
+
model: 'gpt-4',
|
|
121
|
+
messages: [...],
|
|
122
|
+
userId: userHash, // From frontend
|
|
123
|
+
sessionToken: sessionToken
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Data Flow
|
|
128
|
+
|
|
129
|
+
1. **User Interaction**: User approves data sharing in frontend
|
|
130
|
+
2. **Hash Generation**: Frontend generates unique `userHash`
|
|
131
|
+
3. **API Call**: Data sent to backend with `userHash`
|
|
132
|
+
4. **Memory Integration**: Backend SDK automatically retrieves relevant user memories
|
|
133
|
+
5. **Enhanced Response**: LLM response includes personalized context
|
|
134
|
+
6. **Memory Storage**: New interactions stored for future personalization
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
**Migration Date**: December 2024
|
|
139
|
+
**Reason**: Security, performance, and enhanced RAG capabilities
|
|
140
|
+
**Status**: ✅ Complete - SDK fully operational in backend environment
|