@retrivora-ai/rag-engine 2.4.0 → 2.4.2
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/README.md +1 -1
- package/dist/handlers/index.js +1 -62
- package/dist/handlers/index.mjs +1 -62
- package/dist/index.js +2 -16
- package/dist/index.mjs +2 -16
- package/dist/server.d.mts +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +7 -94
- package/dist/server.mjs +7 -94
- package/package.json +1 -1
- package/src/LicensedRetrivora.ts +21 -16
- package/src/browser.tsx +139 -0
- package/src/components/ConfigProvider.tsx +1 -9
- package/src/components/DocumentUpload.tsx +28 -29
- package/src/components/UIDispatcher.tsx +1 -1
- package/src/config/LicenseConfigResolver.ts +11 -11
- package/src/config/serverConfig.ts +24 -24
- package/src/core/ConfigFetcher.ts +2 -2
- package/src/core/LLMRouter.ts +3 -3
- package/src/core/PluginManager.ts +5 -5
- package/src/core/mcp.ts +5 -5
- package/src/handlers/index.ts +9 -9
- package/src/hooks/useRagChat.ts +13 -13
- package/src/llm/LLMFactory.ts +1 -1
- package/src/llm/providers/UniversalLLMAdapter.ts +18 -18
- package/src/providers/graphdb/SimpleGraphProvider.ts +5 -5
- package/src/providers/vectordb/ChromaDBProvider.ts +4 -4
- package/src/providers/vectordb/MultiTablePostgresProvider.ts +32 -32
- package/src/providers/vectordb/QdrantProvider.ts +17 -17
- package/src/telemetry/TelemetryService.ts +12 -12
- package/src/utils/SchemaMapper.ts +1 -1
- package/src/utils/UITransformer.ts +1 -1
package/src/browser.tsx
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { createRoot } from 'react-dom/client';
|
|
5
|
+
import { ChatWidget } from './components/ChatWidget';
|
|
6
|
+
import { ConfigProvider } from './components/ConfigProvider';
|
|
7
|
+
|
|
8
|
+
class RetrivoraChatElement extends HTMLElement {
|
|
9
|
+
private root: any = null;
|
|
10
|
+
|
|
11
|
+
connectedCallback() {
|
|
12
|
+
// 1. Inject Stylesheet if not already present
|
|
13
|
+
// We dynamically determine the CDN host from the script tag's src attribute
|
|
14
|
+
const currentScript = document.currentScript as HTMLScriptElement;
|
|
15
|
+
let cdnUrl = 'https://cdn.retrivora.com';
|
|
16
|
+
if (currentScript && currentScript.src) {
|
|
17
|
+
try {
|
|
18
|
+
const url = new URL(currentScript.src);
|
|
19
|
+
cdnUrl = url.origin;
|
|
20
|
+
} catch (e) {
|
|
21
|
+
console.error('[Retrivora] Failed to parse script source URL:', e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const cssId = 'retrivora-sdk-styles';
|
|
26
|
+
if (!document.getElementById(cssId)) {
|
|
27
|
+
const link = document.createElement('link');
|
|
28
|
+
link.id = cssId;
|
|
29
|
+
link.rel = 'stylesheet';
|
|
30
|
+
link.href = `${cdnUrl}/retrivora.css`;
|
|
31
|
+
document.head.appendChild(link);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 2. Parse attributes from the HTML element
|
|
35
|
+
const projectId = this.getAttribute('project-id') || '';
|
|
36
|
+
const licenseKey = this.getAttribute('license-key') || '';
|
|
37
|
+
const primaryColor = this.getAttribute('primary-color') || '#6366f1';
|
|
38
|
+
const secondaryColor = this.getAttribute('secondary-color') || '#8b5cf6';
|
|
39
|
+
const accentColor = this.getAttribute('accent-color') || secondaryColor;
|
|
40
|
+
const theme = (this.getAttribute('theme') || 'system') as any;
|
|
41
|
+
const position = (this.getAttribute('position') || 'bottom-right') as any;
|
|
42
|
+
const botName = this.getAttribute('bot-name') || 'Retrivora Assistant';
|
|
43
|
+
const companyName = this.getAttribute('company-name') || 'Retrivora AI';
|
|
44
|
+
const welcomeMessage = this.getAttribute('welcome-message') || 'Hi, I can help you search your knowledge base.';
|
|
45
|
+
const telemetryEnabled = this.getAttribute('telemetry') !== 'disabled';
|
|
46
|
+
const authMode = (this.getAttribute('auth-mode') || 'public') as any;
|
|
47
|
+
const allowedOrigins = (this.getAttribute('allowed-origins') || '').split(',').filter(Boolean);
|
|
48
|
+
const retrivoraApiBase = this.getAttribute('retrivora-api-base') || undefined;
|
|
49
|
+
|
|
50
|
+
// 3. Construct config and project settings
|
|
51
|
+
const projectSettings = {
|
|
52
|
+
projectId,
|
|
53
|
+
branding: {
|
|
54
|
+
companyName,
|
|
55
|
+
botName,
|
|
56
|
+
welcomeMessage,
|
|
57
|
+
primaryColor,
|
|
58
|
+
secondaryColor,
|
|
59
|
+
fontFamily: 'Inter, sans-serif',
|
|
60
|
+
borderRadius: 12,
|
|
61
|
+
logoUrl: '',
|
|
62
|
+
avatarUrl: '',
|
|
63
|
+
customCss: '',
|
|
64
|
+
},
|
|
65
|
+
ai: {
|
|
66
|
+
defaultModel: '',
|
|
67
|
+
embeddingModel: '',
|
|
68
|
+
systemPrompt: '',
|
|
69
|
+
memoryEnabled: true,
|
|
70
|
+
multiModelEnabled: false,
|
|
71
|
+
citationsEnabled: true,
|
|
72
|
+
fileUploadEnabled: false,
|
|
73
|
+
},
|
|
74
|
+
auth: {
|
|
75
|
+
mode: authMode,
|
|
76
|
+
allowedOrigins,
|
|
77
|
+
requireVerifiedEmail: false,
|
|
78
|
+
sessionTtlMinutes: 60,
|
|
79
|
+
},
|
|
80
|
+
widget: {
|
|
81
|
+
position,
|
|
82
|
+
theme,
|
|
83
|
+
lazyLoad: false,
|
|
84
|
+
autoReconnect: true,
|
|
85
|
+
persistConversations: true,
|
|
86
|
+
showRetrivoraBranding: true,
|
|
87
|
+
},
|
|
88
|
+
telemetry: {
|
|
89
|
+
enabled: telemetryEnabled,
|
|
90
|
+
collectBrowser: true,
|
|
91
|
+
collectCountry: true,
|
|
92
|
+
redactPii: true,
|
|
93
|
+
retentionDays: 30,
|
|
94
|
+
},
|
|
95
|
+
lifecycleHooks: [],
|
|
96
|
+
conversationFeatures: [],
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const config = {
|
|
100
|
+
projectId,
|
|
101
|
+
licenseKey,
|
|
102
|
+
retrivoraApiBase,
|
|
103
|
+
projectSettings,
|
|
104
|
+
autoLoadProjectSettings: true,
|
|
105
|
+
primaryColor,
|
|
106
|
+
secondaryColor,
|
|
107
|
+
accentColor,
|
|
108
|
+
theme,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// 4. Create mount container inside custom element
|
|
112
|
+
const container = document.createElement('div');
|
|
113
|
+
this.appendChild(container);
|
|
114
|
+
|
|
115
|
+
// 5. Mount React Tree
|
|
116
|
+
this.root = createRoot(container);
|
|
117
|
+
this.root.render(
|
|
118
|
+
<React.StrictMode>
|
|
119
|
+
<ConfigProvider config={config}>
|
|
120
|
+
<ChatWidget position={position} />
|
|
121
|
+
</ConfigProvider>
|
|
122
|
+
</React.StrictMode>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
disconnectedCallback() {
|
|
127
|
+
if (this.root) {
|
|
128
|
+
const root = this.root;
|
|
129
|
+
setTimeout(() => {
|
|
130
|
+
root.unmount();
|
|
131
|
+
}, 0);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Register the custom element if it hasn't been defined yet
|
|
137
|
+
if (typeof window !== 'undefined' && !customElements.get('retrivora-chat')) {
|
|
138
|
+
customElements.define('retrivora-chat', RetrivoraChatElement);
|
|
139
|
+
}
|
|
@@ -47,15 +47,7 @@ export function ConfigProvider({
|
|
|
47
47
|
if (config?.borderRadius) flatUi.borderRadius = config.borderRadius;
|
|
48
48
|
if (config?.visualStyle) flatUi.visualStyle = config.visualStyle;
|
|
49
49
|
return { ...flatUi, ...config?.ui };
|
|
50
|
-
}, [
|
|
51
|
-
config?.ui,
|
|
52
|
-
config?.primaryColor,
|
|
53
|
-
config?.secondaryColor,
|
|
54
|
-
config?.accentColor,
|
|
55
|
-
config?.theme,
|
|
56
|
-
config?.borderRadius,
|
|
57
|
-
config?.visualStyle
|
|
58
|
-
]);
|
|
50
|
+
}, [config]);
|
|
59
51
|
const explicitSettings = useMemo(
|
|
60
52
|
() => projectSettingsInput
|
|
61
53
|
? normalizeProjectSettings(projectId, projectSettingsInput)
|
|
@@ -38,15 +38,15 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
|
|
|
38
38
|
namespaceUsed: string;
|
|
39
39
|
} | null>(null);
|
|
40
40
|
|
|
41
|
-
const resolvedLicenseKey = licenseKey ||
|
|
42
|
-
configHeaders?.['x-license-key'] ||
|
|
43
|
-
configHeaders?.['X-License-Key'] ||
|
|
44
|
-
configHeaders?.['authorization']?.replace(/^Bearer\s+/i, '') ||
|
|
41
|
+
const resolvedLicenseKey = licenseKey ||
|
|
42
|
+
configHeaders?.['x-license-key'] ||
|
|
43
|
+
configHeaders?.['X-License-Key'] ||
|
|
44
|
+
configHeaders?.['authorization']?.replace(/^Bearer\s+/i, '') ||
|
|
45
45
|
configHeaders?.['Authorization']?.replace(/^Bearer\s+/i, '');
|
|
46
46
|
|
|
47
47
|
const licenseTier = decodeLicenseTier(resolvedLicenseKey);
|
|
48
|
-
const isFreeTier = !projectId ||
|
|
49
|
-
projectId.includes('free') ||
|
|
48
|
+
const isFreeTier = !projectId ||
|
|
49
|
+
projectId.includes('free') ||
|
|
50
50
|
projectId.includes('demo') ||
|
|
51
51
|
['free_trial', 'free_tier', 'free', 'hobby'].includes(licenseTier.toLowerCase());
|
|
52
52
|
|
|
@@ -59,14 +59,14 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
|
|
|
59
59
|
const COMMON_DIMENSIONS = [64, 128, 256, 384, 512, 768, 1024, 1536, 3072];
|
|
60
60
|
const currentModel = embedding?.model || 'unknown';
|
|
61
61
|
const defaultDimension = isFreeTier ? 768 : (embedding?.dimensions || 1536);
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
let availableDimensions = isFreeTier
|
|
64
64
|
? [768]
|
|
65
65
|
: Object.entries(MULTI_DIMENSION_MODELS).find(([k]) => currentModel.includes(k))?.[1];
|
|
66
66
|
|
|
67
67
|
if (!availableDimensions) {
|
|
68
|
-
availableDimensions = COMMON_DIMENSIONS.includes(defaultDimension)
|
|
69
|
-
? COMMON_DIMENSIONS
|
|
68
|
+
availableDimensions = COMMON_DIMENSIONS.includes(defaultDimension)
|
|
69
|
+
? COMMON_DIMENSIONS
|
|
70
70
|
: [...COMMON_DIMENSIONS, defaultDimension].sort((a, b) => a - b);
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -123,7 +123,7 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
|
|
|
123
123
|
...(licenseKey ? { 'x-license-key': licenseKey } : {}),
|
|
124
124
|
};
|
|
125
125
|
|
|
126
|
-
console.log(`[Retrivora SDK] 📤 Initiating upload request to "${primaryUrl}" (Files: ${idleFiles.length}, Namespace: "${targetNs}", Dimension: ${dimension})`);
|
|
126
|
+
//console.log(`[Retrivora SDK] 📤 Initiating upload request to "${primaryUrl}" (Files: ${idleFiles.length}, Namespace: "${targetNs}", Dimension: ${dimension})`);
|
|
127
127
|
|
|
128
128
|
try {
|
|
129
129
|
let response = await fetch(primaryUrl, {
|
|
@@ -145,7 +145,7 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
|
|
|
145
145
|
|
|
146
146
|
if (!response.ok) throw new Error(result.error || `Upload failed with HTTP status ${response.status}`);
|
|
147
147
|
|
|
148
|
-
console.log(`[Retrivora SDK] ✅ Upload response success:`, result);
|
|
148
|
+
//console.log(`[Retrivora SDK] ✅ Upload response success:`, result);
|
|
149
149
|
|
|
150
150
|
setFileStates(prev => prev.map(s => s.status === 'uploading' ? { ...s, status: 'success' } : s));
|
|
151
151
|
|
|
@@ -170,18 +170,17 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
|
|
|
170
170
|
|
|
171
171
|
return (
|
|
172
172
|
<>
|
|
173
|
-
<div
|
|
174
|
-
className={`p-6 border-2 border-dashed transition-all duration-300 rounded-2xl ${
|
|
175
|
-
|
|
176
|
-
? 'border-emerald-500 bg-emerald-50/50 dark:bg-emerald-500/5'
|
|
173
|
+
<div
|
|
174
|
+
className={`p-6 border-2 border-dashed transition-all duration-300 rounded-2xl ${isDragging
|
|
175
|
+
? 'border-emerald-500 bg-emerald-50/50 dark:bg-emerald-500/5'
|
|
177
176
|
: 'border-slate-200 dark:border-white/10 bg-white dark:bg-white/5'
|
|
178
|
-
|
|
177
|
+
} ${className}`}
|
|
179
178
|
onDragOver={onDragOver}
|
|
180
179
|
onDragLeave={onDragLeave}
|
|
181
180
|
onDrop={onDrop}
|
|
182
181
|
>
|
|
183
182
|
<div className="flex flex-col items-center justify-center text-center">
|
|
184
|
-
<div
|
|
183
|
+
<div
|
|
185
184
|
className="w-12 h-12 rounded-full flex items-center justify-center mb-4 shadow-sm"
|
|
186
185
|
style={{ background: `linear-gradient(135deg, ${ui.primaryColor}20, ${ui.accentColor}20)` }}
|
|
187
186
|
>
|
|
@@ -196,7 +195,7 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
|
|
|
196
195
|
onClick={() => fileInputRef.current?.click()}
|
|
197
196
|
disabled={isUploading}
|
|
198
197
|
className="px-4 py-2 rounded-lg text-sm font-medium transition-all hover:scale-105 active:scale-95 disabled:opacity-50"
|
|
199
|
-
style={{
|
|
198
|
+
style={{
|
|
200
199
|
backgroundColor: `${ui.primaryColor}15`,
|
|
201
200
|
color: ui.primaryColor,
|
|
202
201
|
border: `1px solid ${ui.primaryColor}30`
|
|
@@ -204,12 +203,12 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
|
|
|
204
203
|
>
|
|
205
204
|
Select Files
|
|
206
205
|
</button>
|
|
207
|
-
<input
|
|
206
|
+
<input
|
|
208
207
|
ref={fileInputRef}
|
|
209
|
-
type="file"
|
|
210
|
-
multiple
|
|
211
|
-
onChange={onFileSelect}
|
|
212
|
-
className="hidden"
|
|
208
|
+
type="file"
|
|
209
|
+
multiple
|
|
210
|
+
onChange={onFileSelect}
|
|
211
|
+
className="hidden"
|
|
213
212
|
accept=".pdf,.docx,.doc,.xlsx,.xls,.csv,.txt,.md,.json"
|
|
214
213
|
/>
|
|
215
214
|
|
|
@@ -222,9 +221,9 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
|
|
|
222
221
|
className="px-3 py-1.5 rounded-lg bg-slate-50 dark:bg-white/5 border border-slate-200 dark:border-white/10 text-slate-800 dark:text-white/90 outline-none focus:border-emerald-500 transition-colors text-sm font-medium cursor-pointer"
|
|
223
222
|
>
|
|
224
223
|
{availableDimensions.map(dim => (
|
|
225
|
-
<option
|
|
226
|
-
key={dim}
|
|
227
|
-
value={dim}
|
|
224
|
+
<option
|
|
225
|
+
key={dim}
|
|
226
|
+
value={dim}
|
|
228
227
|
className="bg-white dark:bg-slate-900 text-slate-800 dark:text-white"
|
|
229
228
|
>
|
|
230
229
|
{dim}
|
|
@@ -237,7 +236,7 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
|
|
|
237
236
|
{fileStates.length > 0 && (
|
|
238
237
|
<div className="mt-8 space-y-3">
|
|
239
238
|
{fileStates.map((state, i) => (
|
|
240
|
-
<div
|
|
239
|
+
<div
|
|
241
240
|
key={i}
|
|
242
241
|
className="flex items-center justify-between p-3 rounded-xl bg-slate-50 dark:bg-white/5 border border-slate-100 dark:border-white/10"
|
|
243
242
|
>
|
|
@@ -263,9 +262,9 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
|
|
|
263
262
|
<AlertCircle className="w-4 h-4 text-rose-500" />
|
|
264
263
|
</div>
|
|
265
264
|
)}
|
|
266
|
-
|
|
265
|
+
|
|
267
266
|
{state.status !== 'uploading' && (
|
|
268
|
-
<button
|
|
267
|
+
<button
|
|
269
268
|
onClick={() => removeFile(i)}
|
|
270
269
|
className="p-1 rounded-md hover:bg-slate-200 dark:hover:bg-white/10 transition-colors"
|
|
271
270
|
>
|
|
@@ -166,7 +166,7 @@ export function UIDispatcher({ rawContent, primaryColor, accentColor, isStreamin
|
|
|
166
166
|
onAddToCart?: (product: Product) => void;
|
|
167
167
|
viewportSize?: ChatViewportSize;
|
|
168
168
|
}) {
|
|
169
|
-
console.log('rawContent', rawContent);
|
|
169
|
+
//console.log('rawContent', rawContent);
|
|
170
170
|
const result = React.useMemo<{ config: UIConfig } | { error: string } | { loading: true }>(() => {
|
|
171
171
|
try {
|
|
172
172
|
const clean = rawContent
|
|
@@ -96,26 +96,26 @@ export class LicenseConfigResolver {
|
|
|
96
96
|
const cacheKey = `${licenseKey}:${projectId}`;
|
|
97
97
|
const cached = this.configCache.get(cacheKey);
|
|
98
98
|
if (cached && Date.now() - cached.timestamp < this.CACHE_TTL_MS) {
|
|
99
|
-
console.log('[LicenseConfigResolver] Using cached config for', projectId);
|
|
99
|
+
//console.log('[LicenseConfigResolver] Using cached config for', projectId);
|
|
100
100
|
return this.buildConfigs(cached.config, cached.credentials, licenseKey, projectId);
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
// Fetch tier config from /api/v1/config
|
|
104
|
-
console.log('[LicenseConfigResolver] Fetching tier config from Retrivora...');
|
|
104
|
+
//console.log('[LicenseConfigResolver] Fetching tier config from Retrivora...');
|
|
105
105
|
const tierConfig = await this.fetchTierConfig(licenseKey, projectId);
|
|
106
106
|
|
|
107
107
|
// Fetch provider credentials from /api/v1/credentials
|
|
108
|
-
console.log('[LicenseConfigResolver] Fetching provider credentials from Retrivora...');
|
|
108
|
+
//console.log('[LicenseConfigResolver] Fetching provider credentials from Retrivora...');
|
|
109
109
|
const credentials = await this.fetchProviderCredentials(licenseKey, projectId);
|
|
110
110
|
|
|
111
111
|
// Cache both
|
|
112
112
|
this.configCache.set(cacheKey, { config: tierConfig, credentials, timestamp: Date.now() });
|
|
113
113
|
|
|
114
|
-
console.log('[LicenseConfigResolver] ✅ Successfully resolved config from Retrivora:', {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
});
|
|
114
|
+
// console.log('[LicenseConfigResolver] ✅ Successfully resolved config from Retrivora:', {
|
|
115
|
+
// tier: tierConfig.tier,
|
|
116
|
+
// llmModel: tierConfig.llmModel,
|
|
117
|
+
// embeddingModel: tierConfig.embeddingModel,
|
|
118
|
+
// });
|
|
119
119
|
|
|
120
120
|
return this.buildConfigs(tierConfig, credentials, licenseKey, projectId);
|
|
121
121
|
}
|
|
@@ -145,7 +145,7 @@ export class LicenseConfigResolver {
|
|
|
145
145
|
);
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
console.log(`[LicenseConfigResolver] Resolved tier: ${response.data.config.tier}`);
|
|
148
|
+
//console.log(`[LicenseConfigResolver] Resolved tier: ${response.data.config.tier}`);
|
|
149
149
|
return response.data.config;
|
|
150
150
|
} catch (err: any) {
|
|
151
151
|
console.error('[LicenseConfigResolver] Failed to fetch config:', err.message);
|
|
@@ -180,7 +180,7 @@ export class LicenseConfigResolver {
|
|
|
180
180
|
);
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
console.log(`[LicenseConfigResolver] Retrieved provider credentials for project: ${projectId}`);
|
|
183
|
+
//console.log(`[LicenseConfigResolver] Retrieved provider credentials for project: ${projectId}`);
|
|
184
184
|
return response.data.credentials;
|
|
185
185
|
} catch (err: any) {
|
|
186
186
|
console.error('[LicenseConfigResolver] Failed to fetch credentials:', err.message);
|
|
@@ -283,7 +283,7 @@ export class LicenseConfigResolver {
|
|
|
283
283
|
*/
|
|
284
284
|
static clearCache(): void {
|
|
285
285
|
this.configCache.clear();
|
|
286
|
-
console.log('[LicenseConfigResolver] Configuration cache cleared');
|
|
286
|
+
//console.log('[LicenseConfigResolver] Configuration cache cleared');
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
/**
|
|
@@ -57,13 +57,13 @@ let _runtimeConfig: RuntimeTierConfig | null = null;
|
|
|
57
57
|
*/
|
|
58
58
|
export function injectRuntimeConfig(config: RuntimeTierConfig): void {
|
|
59
59
|
_runtimeConfig = config;
|
|
60
|
-
console.log('[serverConfig] ✅ Runtime tier config injected:', {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
});
|
|
60
|
+
// console.log('[serverConfig] ✅ Runtime tier config injected:', {
|
|
61
|
+
// tier: config.tier,
|
|
62
|
+
// llmModel: config.llmModel,
|
|
63
|
+
// embeddingModel: config.embeddingModel,
|
|
64
|
+
// llmBaseUrl: config.llmBaseUrl,
|
|
65
|
+
// hasLitellmKey: !!config.litellmApiKey,
|
|
66
|
+
// });
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/** Returns the currently injected runtime config, or null if not yet set. */
|
|
@@ -253,15 +253,15 @@ export function getEnvConfig(env: Record<string, string | undefined> = process.e
|
|
|
253
253
|
// llmApiKey: LITELLM_MASTER_KEY env wins, then injected litellm key, then licenseKey
|
|
254
254
|
const llmApiKey = readString(env, 'LITELLM_MASTER_KEY') ?? rt?.litellmApiKey ?? base?.llm?.apiKey ?? licenseKey;
|
|
255
255
|
const llmProfile = readString(env, 'LLM_UNIVERSAL_PROFILE') ?? (base?.llm?.options?.profile as string) ?? 'litellm';
|
|
256
|
-
|
|
257
|
-
console.log('[serverConfig] 🔧 LLM Configuration:', {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
});
|
|
264
|
-
|
|
256
|
+
|
|
257
|
+
// console.log('[serverConfig] 🔧 LLM Configuration:', {
|
|
258
|
+
// baseUrl: llmBaseUrl,
|
|
259
|
+
// model: llmModel,
|
|
260
|
+
// provider: llmProvider,
|
|
261
|
+
// hasApiKey: !!llmApiKey,
|
|
262
|
+
// source: rt?.llmModel ? 'runtime-injected' : 'env/fallback',
|
|
263
|
+
// });
|
|
264
|
+
|
|
265
265
|
const defaultEmbeddingProvider = 'universal_rest';
|
|
266
266
|
const embeddingProvider = (readEnum(env, 'EMBEDDING_PROVIDER', defaultEmbeddingProvider, EMBEDDING_PROVIDERS) ?? base?.embedding?.provider ?? defaultEmbeddingProvider) as EmbeddingProvider;
|
|
267
267
|
const embeddingBaseUrl = readString(env, 'LITELLM_BASE_URL') ?? readString(env, 'EMBEDDING_BASE_URL') ?? readString(env, 'LLM_BASE_URL') ?? base?.embedding?.baseUrl ?? rt?.embeddingBaseUrl ?? rt?.llmBaseUrl ?? defaultGatewayUrl;
|
|
@@ -269,14 +269,14 @@ export function getEnvConfig(env: Record<string, string | undefined> = process.e
|
|
|
269
269
|
// embeddingApiKey: same key as LLM (LiteLLM gateway handles both)
|
|
270
270
|
const embeddingApiKey = readString(env, 'LITELLM_MASTER_KEY') ?? rt?.litellmApiKey ?? base?.embedding?.apiKey ?? licenseKey;
|
|
271
271
|
const embeddingProfile = readString(env, 'EMBEDDING_UNIVERSAL_PROFILE') ?? (base?.embedding?.options?.profile as string) ?? 'litellm';
|
|
272
|
-
|
|
273
|
-
console.log('[serverConfig] 🔧 Embedding Configuration:', {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
});
|
|
272
|
+
|
|
273
|
+
// console.log('[serverConfig] 🔧 Embedding Configuration:', {
|
|
274
|
+
// baseUrl: embeddingBaseUrl,
|
|
275
|
+
// model: embeddingModel,
|
|
276
|
+
// provider: embeddingProvider,
|
|
277
|
+
// hasApiKey: !!embeddingApiKey,
|
|
278
|
+
// source: rt?.embeddingModel ? 'runtime-injected' : 'env/fallback',
|
|
279
|
+
// });
|
|
280
280
|
|
|
281
281
|
return {
|
|
282
282
|
projectId,
|
|
@@ -113,7 +113,7 @@ export class ConfigFetcher {
|
|
|
113
113
|
for (const baseUrl of controlPlaneUrls) {
|
|
114
114
|
try {
|
|
115
115
|
const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
|
|
116
|
-
console.log(`[ConfigFetcher] Fetching config from: ${url}`);
|
|
116
|
+
//console.log(`[ConfigFetcher] Fetching config from: ${url}`);
|
|
117
117
|
const res = await fetch(url, {
|
|
118
118
|
method: 'GET',
|
|
119
119
|
headers: {
|
|
@@ -123,7 +123,7 @@ export class ConfigFetcher {
|
|
|
123
123
|
},
|
|
124
124
|
});
|
|
125
125
|
|
|
126
|
-
console.log(`[ConfigFetcher] Response status: ${res.status}`);
|
|
126
|
+
//console.log(`[ConfigFetcher] Response status: ${res.status}`);
|
|
127
127
|
if (!res.ok) {
|
|
128
128
|
console.warn(`[ConfigFetcher] Error text: ${await res.text()}`);
|
|
129
129
|
}
|
package/src/core/LLMRouter.ts
CHANGED
|
@@ -30,7 +30,7 @@ const FAST_MODEL_DEFAULTS: Record<string, string> = {
|
|
|
30
30
|
export class LLMRouter {
|
|
31
31
|
private models = new Map<string, ILLMProvider>();
|
|
32
32
|
|
|
33
|
-
constructor(private config: RagConfig) {}
|
|
33
|
+
constructor(private config: RagConfig) { }
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Initialize all LLM roles.
|
|
@@ -50,14 +50,14 @@ export class LLMRouter {
|
|
|
50
50
|
const fastModelName = envFastModel || providerFastDefault;
|
|
51
51
|
|
|
52
52
|
if (fastModelName && fastModelName !== this.config.llm.model) {
|
|
53
|
-
console.log(`[LLMRouter] Fast role → provider="${this.config.llm.provider}" model="${fastModelName}"`);
|
|
53
|
+
//console.log(`[LLMRouter] Fast role → provider="${this.config.llm.provider}" model="${fastModelName}"`);
|
|
54
54
|
const fastConfig: LLMConfig = {
|
|
55
55
|
...this.config.llm,
|
|
56
56
|
model: fastModelName,
|
|
57
57
|
};
|
|
58
58
|
this.models.set('fast', LLMFactory.create(fastConfig, this.config.embedding));
|
|
59
59
|
} else {
|
|
60
|
-
console.log(`[LLMRouter] Fast role → reusing default model (no lightweight alternative configured).`);
|
|
60
|
+
//console.log(`[LLMRouter] Fast role → reusing default model (no lightweight alternative configured).`);
|
|
61
61
|
this.models.set('fast', defaultModel);
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -106,9 +106,9 @@ export class PluginManager {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
this.registeredPlugins.set(metadata.id, descriptor);
|
|
109
|
-
console.log(
|
|
110
|
-
|
|
111
|
-
);
|
|
109
|
+
// console.log(
|
|
110
|
+
// `[PluginManager] Registered plugin: ${metadata.name} v${metadata.version} (${metadata.id})`
|
|
111
|
+
// );
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
/**
|
|
@@ -189,7 +189,7 @@ export class PluginManager {
|
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
// Initialize plugin
|
|
192
|
-
console.log(`[PluginManager] Initializing plugin: ${pluginId}`);
|
|
192
|
+
//console.log(`[PluginManager] Initializing plugin: ${pluginId}`);
|
|
193
193
|
const instance = await factory(config);
|
|
194
194
|
|
|
195
195
|
// Verify plugin is ready
|
|
@@ -229,7 +229,7 @@ export class PluginManager {
|
|
|
229
229
|
for (const [pluginId, instance] of this.instances.entries()) {
|
|
230
230
|
try {
|
|
231
231
|
await instance.shutdown();
|
|
232
|
-
console.log(`[PluginManager] Shutdown plugin: ${pluginId}`);
|
|
232
|
+
//console.log(`[PluginManager] Shutdown plugin: ${pluginId}`);
|
|
233
233
|
} catch (error) {
|
|
234
234
|
errors.push(
|
|
235
235
|
new Error(`Failed to shutdown plugin ${pluginId}: ${error instanceof Error ? error.message : String(error)}`)
|
package/src/core/mcp.ts
CHANGED
|
@@ -8,7 +8,7 @@ interface MCPTool {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
interface MCPCallResult {
|
|
11
|
-
content: Array<{ type: string; text?: string;
|
|
11
|
+
content: Array<{ type: string; text?: string;[key: string]: any }>;
|
|
12
12
|
isError?: boolean;
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -20,7 +20,7 @@ export class MCPClient {
|
|
|
20
20
|
private stdioBuffer = '';
|
|
21
21
|
private initialized = false;
|
|
22
22
|
|
|
23
|
-
constructor(private config: MCPServerConfig) {}
|
|
23
|
+
constructor(private config: MCPServerConfig) { }
|
|
24
24
|
|
|
25
25
|
private getNextMessageId(): number {
|
|
26
26
|
return ++this.messageIdCounter;
|
|
@@ -52,7 +52,7 @@ export class MCPClient {
|
|
|
52
52
|
// Send initialized notification
|
|
53
53
|
await this.sendNotification('notifications/initialized');
|
|
54
54
|
this.initialized = true;
|
|
55
|
-
console.log(`[MCPClient] Connected and initialized server "${this.config.name}" successfully.`);
|
|
55
|
+
//console.log(`[MCPClient] Connected and initialized server "${this.config.name}" successfully.`);
|
|
56
56
|
} catch (err: any) {
|
|
57
57
|
this.disconnect();
|
|
58
58
|
throw new Error(`[MCPClient] Failed to initialize server "${this.config.name}": ${err.message}`);
|
|
@@ -84,7 +84,7 @@ export class MCPClient {
|
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
this.childProcess.on('close', (code) => {
|
|
87
|
-
console.log(`[MCPClient] Connection closed for "${this.config.name}" with exit code: ${code}`);
|
|
87
|
+
//console.log(`[MCPClient] Connection closed for "${this.config.name}" with exit code: ${code}`);
|
|
88
88
|
this.disconnect();
|
|
89
89
|
});
|
|
90
90
|
|
|
@@ -209,7 +209,7 @@ export class MCPClient {
|
|
|
209
209
|
this.initialized = false;
|
|
210
210
|
this.pendingRequests.forEach(req => req.reject(new Error('MCPClient disconnected')));
|
|
211
211
|
this.pendingRequests.clear();
|
|
212
|
-
|
|
212
|
+
|
|
213
213
|
if (this.childProcess) {
|
|
214
214
|
try {
|
|
215
215
|
this.childProcess.kill();
|
package/src/handlers/index.ts
CHANGED
|
@@ -813,7 +813,7 @@ export function createStreamHandler(
|
|
|
813
813
|
},
|
|
814
814
|
cancel(reason) {
|
|
815
815
|
isActive = false;
|
|
816
|
-
console.log('[createStreamHandler] Stream connection closed by client:', reason);
|
|
816
|
+
//console.log('[createStreamHandler] Stream connection closed by client:', reason);
|
|
817
817
|
}
|
|
818
818
|
});
|
|
819
819
|
|
|
@@ -998,7 +998,7 @@ export function createLicenseHandler(
|
|
|
998
998
|
|
|
999
999
|
const projectId = body?.projectId || config.projectId || '';
|
|
1000
1000
|
|
|
1001
|
-
console.log(`[DEBUG] createLicenseHandler: projectId="${projectId}", body.projectId="${body?.projectId}", config.projectId="${config.projectId}"`);
|
|
1001
|
+
//console.log(`[DEBUG] createLicenseHandler: projectId="${projectId}", body.projectId="${body?.projectId}", config.projectId="${config.projectId}"`);
|
|
1002
1002
|
|
|
1003
1003
|
const payload = await LicenseVerifier.verifyAsync(licenseKey, projectId);
|
|
1004
1004
|
|
|
@@ -1053,7 +1053,7 @@ export function createUploadHandler(
|
|
|
1053
1053
|
const onAuthorize = options?.onAuthorize;
|
|
1054
1054
|
|
|
1055
1055
|
return async function POST(req: any, context?: any) {
|
|
1056
|
-
console.log('Upload handler invoked');
|
|
1056
|
+
//console.log('Upload handler invoked');
|
|
1057
1057
|
const authResult = await checkAuth(req, onAuthorize);
|
|
1058
1058
|
if (authResult) return authResult as any;
|
|
1059
1059
|
|
|
@@ -1065,7 +1065,7 @@ export function createUploadHandler(
|
|
|
1065
1065
|
try {
|
|
1066
1066
|
const formData = await req.formData();
|
|
1067
1067
|
const files = formData.getAll('files') as File[];
|
|
1068
|
-
console.log('Files received for upload:', files.map(f => f.name));
|
|
1068
|
+
//console.log('Files received for upload:', files.map(f => f.name));
|
|
1069
1069
|
const namespace = (formData.get('namespace') as string) || undefined;
|
|
1070
1070
|
const dimensionRaw = formData.get('dimension');
|
|
1071
1071
|
const dimension = dimensionRaw ? parseInt(dimensionRaw as string, 10) : undefined;
|
|
@@ -1590,11 +1590,11 @@ export function createRagHandler(
|
|
|
1590
1590
|
? await context.params
|
|
1591
1591
|
: context?.params;
|
|
1592
1592
|
|
|
1593
|
-
const segments: string[] = resolvedParams?.retrivora ||
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1593
|
+
const segments: string[] = resolvedParams?.retrivora ||
|
|
1594
|
+
resolvedParams?.params?.retrivora ||
|
|
1595
|
+
resolvedParams?.rag ||
|
|
1596
|
+
resolvedParams?.params?.rag ||
|
|
1597
|
+
[];
|
|
1598
1598
|
const joined = segments.join('/');
|
|
1599
1599
|
return joined || 'chat';
|
|
1600
1600
|
}
|
package/src/hooks/useRagChat.ts
CHANGED
|
@@ -24,12 +24,12 @@ import { useStoredMessages } from './useStoredMessages';
|
|
|
24
24
|
|
|
25
25
|
// ─── SSE Frame Parser ──────────────────────────────────────────────────────────
|
|
26
26
|
|
|
27
|
-
interface SseTextFrame
|
|
28
|
-
interface SseThinkingFrame
|
|
29
|
-
interface SseMetaFrame
|
|
30
|
-
interface SseErrorFrame
|
|
31
|
-
interface SseUiFrame
|
|
32
|
-
interface SseObservabilityFrame { type: 'observability';
|
|
27
|
+
interface SseTextFrame { type: 'text'; text: string }
|
|
28
|
+
interface SseThinkingFrame { type: 'thinking'; text: string }
|
|
29
|
+
interface SseMetaFrame { type: 'metadata'; sources?: VectorMatch[]; thinkingMs?: number }
|
|
30
|
+
interface SseErrorFrame { type: 'error'; error: string }
|
|
31
|
+
interface SseUiFrame { type: 'ui_transformation'; data: unknown }
|
|
32
|
+
interface SseObservabilityFrame { type: 'observability'; data: ObservabilityTrace }
|
|
33
33
|
type SseFrame = SseTextFrame | SseThinkingFrame | SseMetaFrame | SseErrorFrame | SseUiFrame | SseObservabilityFrame;
|
|
34
34
|
|
|
35
35
|
/**
|
|
@@ -213,11 +213,11 @@ export function useRagChat(
|
|
|
213
213
|
setMessages((prev) =>
|
|
214
214
|
prev.map((msg) =>
|
|
215
215
|
msg.id === msgId
|
|
216
|
-
? {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
216
|
+
? {
|
|
217
|
+
...msg,
|
|
218
|
+
content: snapshot,
|
|
219
|
+
thinking: thinkingSnapshot || undefined,
|
|
220
|
+
}
|
|
221
221
|
: msg
|
|
222
222
|
)
|
|
223
223
|
);
|
|
@@ -248,7 +248,7 @@ export function useRagChat(
|
|
|
248
248
|
|
|
249
249
|
buffer += decoder.decode(value, { stream: true });
|
|
250
250
|
const frames = parseSseChunk(buffer);
|
|
251
|
-
|
|
251
|
+
|
|
252
252
|
// Clear processed frames from buffer (approximate by matching last found frame boundary)
|
|
253
253
|
const lastIndex = buffer.lastIndexOf('\n\n');
|
|
254
254
|
if (lastIndex !== -1) {
|
|
@@ -308,7 +308,7 @@ export function useRagChat(
|
|
|
308
308
|
onReply?.(finalMsg);
|
|
309
309
|
} catch (err) {
|
|
310
310
|
if (err instanceof Error && err.name === 'AbortError') {
|
|
311
|
-
console.log('[useRagChat] Streaming stopped by user.');
|
|
311
|
+
//console.log('[useRagChat] Streaming stopped by user.');
|
|
312
312
|
return;
|
|
313
313
|
}
|
|
314
314
|
let msg = err instanceof Error ? err.message : 'Something went wrong. Please try again.';
|