@retrivora-ai/rag-engine 2.3.4 → 2.3.6
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/dist/{BatchProcessor-CQDtlggz.d.ts → BatchProcessor-ByBl-1MA.d.ts} +81 -3
- package/dist/{BatchProcessor-tVzb9CdE.d.mts → BatchProcessor-Dfn23VAd.d.mts} +81 -3
- package/dist/{ILLMProvider-CcJ5N6XD.d.mts → ILLMProvider-B8TAVx3j.d.mts} +63 -1
- package/dist/{ILLMProvider-CcJ5N6XD.d.ts → ILLMProvider-B8TAVx3j.d.ts} +63 -1
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +419 -169
- package/dist/handlers/index.mjs +419 -169
- package/dist/{index-BwmyPJHp.d.ts → index-ejOWsaqb.d.ts} +1 -1
- package/dist/{index-CL-zF6bD.d.mts → index-xxQOFx-u.d.mts} +1 -1
- package/dist/index.css +9 -0
- package/dist/index.d.mts +19 -5
- package/dist/index.d.ts +19 -5
- package/dist/index.js +638 -189
- package/dist/index.mjs +678 -234
- package/dist/server.d.mts +6 -6
- package/dist/server.d.ts +6 -6
- package/dist/server.js +461 -173
- package/dist/server.mjs +457 -173
- package/package.json +2 -2
- package/src/components/ChatWidget.tsx +44 -19
- package/src/components/ChatWindow.tsx +30 -14
- package/src/components/ConfigProvider.tsx +86 -6
- package/src/components/DocumentUpload.tsx +8 -2
- package/src/config/RagConfig.ts +4 -0
- package/src/core/ConfigFetcher.ts +73 -11
- package/src/core/ConfigResolver.ts +1 -0
- package/src/core/LicenseValidator.ts +31 -13
- package/src/core/ProjectSettings.ts +247 -0
- package/src/handlers/index.ts +63 -7
- package/src/hooks/useProjectSettings.ts +105 -0
- package/src/index.css +9 -0
- package/src/index.ts +28 -0
- package/src/providers/vectordb/PineconeProvider.ts +17 -4
- package/src/server.ts +23 -1
- package/src/types/props.ts +14 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@retrivora-ai/rag-engine",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.6",
|
|
4
4
|
"description": "Retrivora AI is a plug-and-play AI engine for RAG chat experiences — generic vector DB + LLM provider, embeddable or standalone.",
|
|
5
5
|
"author": "Abhinav Alkuchi",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -136,4 +136,4 @@
|
|
|
136
136
|
"tsup": "^8.5.1",
|
|
137
137
|
"typescript": "^5"
|
|
138
138
|
}
|
|
139
|
-
}
|
|
139
|
+
}
|
|
@@ -67,8 +67,19 @@ const GEMINI_STYLES = `
|
|
|
67
67
|
*
|
|
68
68
|
* @param props - Widget position, callbacks, API overrides, and license overrides
|
|
69
69
|
*/
|
|
70
|
-
export function ChatWidget({ position
|
|
71
|
-
const {
|
|
70
|
+
export function ChatWidget({ position, onAddToCart, apiUrl, retrivoraApiBase, licenseKey: licenseKeyProp, headers }: ChatWidgetProps) {
|
|
71
|
+
const {
|
|
72
|
+
ui,
|
|
73
|
+
projectId,
|
|
74
|
+
projectSettings,
|
|
75
|
+
licenseKey: contextLicenseKey,
|
|
76
|
+
headers: contextHeaders,
|
|
77
|
+
retrivoraApiBase: contextApiBase,
|
|
78
|
+
} = useConfig();
|
|
79
|
+
const effectivePosition = position || projectSettings?.widget.position || 'bottom-right';
|
|
80
|
+
const effectiveHeaders = headers || contextHeaders;
|
|
81
|
+
const effectiveLicenseKey = licenseKeyProp || contextLicenseKey;
|
|
82
|
+
const effectiveApiBase = retrivoraApiBase || contextApiBase;
|
|
72
83
|
const [isOpen, setIsOpen] = useState(false);
|
|
73
84
|
const [hasUnread, setHasUnread] = useState(false);
|
|
74
85
|
const [dimensions, setDimensions] = useState(DEFAULT_DIMENSIONS);
|
|
@@ -80,13 +91,21 @@ export function ChatWidget({ position = 'bottom-right', onAddToCart, apiUrl, ret
|
|
|
80
91
|
const [hasMountValidationFailed, setHasMountValidationFailed] = useState(false);
|
|
81
92
|
|
|
82
93
|
const positionClass =
|
|
83
|
-
|
|
94
|
+
effectivePosition === 'bottom-left'
|
|
84
95
|
? 'bottom-6 left-6'
|
|
96
|
+
: effectivePosition === 'top-left'
|
|
97
|
+
? 'top-6 left-6'
|
|
98
|
+
: effectivePosition === 'top-right'
|
|
99
|
+
? 'top-6 right-6'
|
|
85
100
|
: 'bottom-6 right-6';
|
|
86
101
|
|
|
87
102
|
const windowPositionClass =
|
|
88
|
-
|
|
103
|
+
effectivePosition === 'bottom-left'
|
|
89
104
|
? 'bottom-20 left-6'
|
|
105
|
+
: effectivePosition === 'top-left'
|
|
106
|
+
? 'top-20 left-6'
|
|
107
|
+
: effectivePosition === 'top-right'
|
|
108
|
+
? 'top-20 right-6'
|
|
90
109
|
: 'bottom-20 right-6';
|
|
91
110
|
|
|
92
111
|
/**
|
|
@@ -95,16 +114,16 @@ export function ChatWidget({ position = 'bottom-right', onAddToCart, apiUrl, ret
|
|
|
95
114
|
*/
|
|
96
115
|
const resolveLicenseKey = useCallback((): string => {
|
|
97
116
|
const getHeader = (name: string) => {
|
|
98
|
-
if (!
|
|
117
|
+
if (!effectiveHeaders) return undefined;
|
|
99
118
|
const target = name.toLowerCase();
|
|
100
|
-
for (const [k, v] of Object.entries(
|
|
119
|
+
for (const [k, v] of Object.entries(effectiveHeaders)) {
|
|
101
120
|
if (k.toLowerCase() === target) return v;
|
|
102
121
|
}
|
|
103
122
|
return undefined;
|
|
104
123
|
};
|
|
105
124
|
|
|
106
125
|
return (
|
|
107
|
-
|
|
126
|
+
effectiveLicenseKey ||
|
|
108
127
|
getHeader('x-license-key') ||
|
|
109
128
|
getHeader('authorization')?.replace(/^Bearer\s+/i, '') ||
|
|
110
129
|
(typeof process !== 'undefined'
|
|
@@ -112,7 +131,7 @@ export function ChatWidget({ position = 'bottom-right', onAddToCart, apiUrl, ret
|
|
|
112
131
|
: '') ||
|
|
113
132
|
''
|
|
114
133
|
);
|
|
115
|
-
}, [
|
|
134
|
+
}, [effectiveLicenseKey, effectiveHeaders]);
|
|
116
135
|
|
|
117
136
|
/**
|
|
118
137
|
* Proactively validate the license on mount.
|
|
@@ -127,8 +146,8 @@ export function ChatWidget({ position = 'bottom-right', onAddToCart, apiUrl, ret
|
|
|
127
146
|
await LicenseValidator.getInstance().validate({
|
|
128
147
|
licenseKey: resolvedLicenseKey,
|
|
129
148
|
projectId,
|
|
130
|
-
retrivoraApiBase,
|
|
131
|
-
headers,
|
|
149
|
+
retrivoraApiBase: effectiveApiBase,
|
|
150
|
+
headers: effectiveHeaders,
|
|
132
151
|
});
|
|
133
152
|
if (isMounted) {
|
|
134
153
|
setHasMountValidationFailed(false);
|
|
@@ -143,7 +162,7 @@ export function ChatWidget({ position = 'bottom-right', onAddToCart, apiUrl, ret
|
|
|
143
162
|
}
|
|
144
163
|
validateOnMount();
|
|
145
164
|
return () => { isMounted = false; };
|
|
146
|
-
}, [resolveLicenseKey, projectId,
|
|
165
|
+
}, [resolveLicenseKey, projectId, effectiveApiBase, effectiveHeaders]);
|
|
147
166
|
|
|
148
167
|
/**
|
|
149
168
|
* Validates the license key and opens the chat window.
|
|
@@ -162,8 +181,8 @@ export function ChatWidget({ position = 'bottom-right', onAddToCart, apiUrl, ret
|
|
|
162
181
|
await LicenseValidator.getInstance().validate({
|
|
163
182
|
licenseKey: resolvedLicenseKey,
|
|
164
183
|
projectId,
|
|
165
|
-
retrivoraApiBase,
|
|
166
|
-
headers,
|
|
184
|
+
retrivoraApiBase: effectiveApiBase,
|
|
185
|
+
headers: effectiveHeaders,
|
|
167
186
|
});
|
|
168
187
|
|
|
169
188
|
setWidgetError(null);
|
|
@@ -177,7 +196,7 @@ export function ChatWidget({ position = 'bottom-right', onAddToCart, apiUrl, ret
|
|
|
177
196
|
} finally {
|
|
178
197
|
setIsValidating(false);
|
|
179
198
|
}
|
|
180
|
-
}, [hasMountValidationFailed, widgetError, resolveLicenseKey, projectId,
|
|
199
|
+
}, [hasMountValidationFailed, widgetError, resolveLicenseKey, projectId, effectiveApiBase, effectiveHeaders]);
|
|
181
200
|
|
|
182
201
|
/** True when the license has been proven invalid and the widget must be locked. */
|
|
183
202
|
const isWidgetLocked = hasMountValidationFailed || isValidating;
|
|
@@ -259,14 +278,14 @@ export function ChatWidget({ position = 'bottom-right', onAddToCart, apiUrl, ret
|
|
|
259
278
|
isMaximized={isMaximized}
|
|
260
279
|
onAddToCart={onAddToCart}
|
|
261
280
|
apiUrl={apiUrl}
|
|
262
|
-
retrivoraApiBase={
|
|
263
|
-
licenseKey={
|
|
264
|
-
headers={
|
|
281
|
+
retrivoraApiBase={effectiveApiBase}
|
|
282
|
+
licenseKey={effectiveLicenseKey}
|
|
283
|
+
headers={effectiveHeaders}
|
|
265
284
|
/>
|
|
266
285
|
{/* Pointer (Tail) */}
|
|
267
286
|
<div
|
|
268
287
|
className={`absolute -bottom-1.5 w-4 h-4 rotate-45 border-r border-b border-slate-200 dark:border-white/10 z-0 ${ui.visualStyle === 'solid' ? 'bg-white dark:bg-[#0f0f1a]' : 'bg-white/90 dark:bg-[#0f0f1a]/90 backdrop-blur-xl'
|
|
269
|
-
} ${
|
|
288
|
+
} ${effectivePosition === 'bottom-left' || effectivePosition === 'top-left' ? 'left-5' : 'right-5'}`}
|
|
270
289
|
/>
|
|
271
290
|
</div>
|
|
272
291
|
|
|
@@ -274,7 +293,13 @@ export function ChatWidget({ position = 'bottom-right', onAddToCart, apiUrl, ret
|
|
|
274
293
|
{widgetError && !isOpen && (
|
|
275
294
|
<div
|
|
276
295
|
className={`fixed z-[9999] max-w-sm p-4 rounded-2xl shadow-2xl border border-rose-200 dark:border-rose-900/60 bg-white/95 dark:bg-[#0f0f1a]/95 backdrop-blur-xl transition-all duration-300 animate-in fade-in slide-in-from-bottom-3 ${
|
|
277
|
-
|
|
296
|
+
effectivePosition === 'bottom-left'
|
|
297
|
+
? 'bottom-24 left-6'
|
|
298
|
+
: effectivePosition === 'top-left'
|
|
299
|
+
? 'top-24 left-6'
|
|
300
|
+
: effectivePosition === 'top-right'
|
|
301
|
+
? 'top-24 right-6'
|
|
302
|
+
: 'bottom-24 right-6'
|
|
278
303
|
}`}
|
|
279
304
|
>
|
|
280
305
|
<div className="flex items-start gap-3">
|
|
@@ -106,7 +106,17 @@ export function ChatWindow({
|
|
|
106
106
|
licenseKey: licenseKeyProp,
|
|
107
107
|
headers
|
|
108
108
|
}: ChatWindowProps) {
|
|
109
|
-
const {
|
|
109
|
+
const {
|
|
110
|
+
ui,
|
|
111
|
+
projectId,
|
|
112
|
+
licenseKey: contextLicenseKey,
|
|
113
|
+
headers: contextHeaders,
|
|
114
|
+
retrivoraApiBase: contextApiBase,
|
|
115
|
+
projectSettings,
|
|
116
|
+
} = useConfig();
|
|
117
|
+
const effectiveLicenseKey = licenseKeyProp || contextLicenseKey;
|
|
118
|
+
const effectiveHeaders = headers || contextHeaders;
|
|
119
|
+
const effectiveApiBase = retrivoraApiBase || contextApiBase;
|
|
110
120
|
const [input, setInput] = useState('');
|
|
111
121
|
const [mounted, setMounted] = useState(false);
|
|
112
122
|
const [viewportSize, setViewportSize] = useState<'compact' | 'medium' | 'large'>('large');
|
|
@@ -116,9 +126,10 @@ export function ChatWindow({
|
|
|
116
126
|
const { messages, send, clear, isLoading, error, stop, submitFeedback } = useRagChat(projectId, {
|
|
117
127
|
namespace: projectId,
|
|
118
128
|
apiUrl,
|
|
119
|
-
retrivoraApiBase,
|
|
120
|
-
licenseKey:
|
|
121
|
-
headers,
|
|
129
|
+
retrivoraApiBase: effectiveApiBase,
|
|
130
|
+
licenseKey: effectiveLicenseKey,
|
|
131
|
+
headers: effectiveHeaders,
|
|
132
|
+
persist: projectSettings?.widget.persistConversations,
|
|
122
133
|
});
|
|
123
134
|
|
|
124
135
|
const [suggestions, setSuggestions] = useState<string[]>([]);
|
|
@@ -142,16 +153,16 @@ export function ChatWindow({
|
|
|
142
153
|
async function validateSessionLicense() {
|
|
143
154
|
try {
|
|
144
155
|
const getHeader = (name: string) => {
|
|
145
|
-
if (!
|
|
156
|
+
if (!effectiveHeaders) return undefined;
|
|
146
157
|
const target = name.toLowerCase();
|
|
147
|
-
for (const [k, v] of Object.entries(
|
|
158
|
+
for (const [k, v] of Object.entries(effectiveHeaders)) {
|
|
148
159
|
if (k.toLowerCase() === target) return v;
|
|
149
160
|
}
|
|
150
161
|
return undefined;
|
|
151
162
|
};
|
|
152
163
|
|
|
153
164
|
const resolvedLicenseKey =
|
|
154
|
-
|
|
165
|
+
effectiveLicenseKey ||
|
|
155
166
|
getHeader('x-license-key') ||
|
|
156
167
|
getHeader('authorization')?.replace(/^Bearer\s+/i, '') ||
|
|
157
168
|
(typeof process !== 'undefined'
|
|
@@ -162,8 +173,8 @@ export function ChatWindow({
|
|
|
162
173
|
await LicenseValidator.getInstance().validate({
|
|
163
174
|
licenseKey: resolvedLicenseKey,
|
|
164
175
|
projectId,
|
|
165
|
-
retrivoraApiBase,
|
|
166
|
-
headers,
|
|
176
|
+
retrivoraApiBase: effectiveApiBase,
|
|
177
|
+
headers: effectiveHeaders,
|
|
167
178
|
});
|
|
168
179
|
|
|
169
180
|
if (isMounted) {
|
|
@@ -183,7 +194,7 @@ export function ChatWindow({
|
|
|
183
194
|
|
|
184
195
|
validateSessionLicense();
|
|
185
196
|
return () => { isMounted = false; };
|
|
186
|
-
}, [
|
|
197
|
+
}, [effectiveApiBase, effectiveHeaders, effectiveLicenseKey, projectId]);
|
|
187
198
|
|
|
188
199
|
// Initialize SpeechRecognition
|
|
189
200
|
useEffect(() => {
|
|
@@ -313,18 +324,23 @@ export function ChatWindow({
|
|
|
313
324
|
const timer = setTimeout(async () => {
|
|
314
325
|
setIsSuggesting(true);
|
|
315
326
|
try {
|
|
316
|
-
const base =
|
|
327
|
+
const base = effectiveApiBase || '/api/retrivora';
|
|
317
328
|
const primaryUrl = `${base}/suggestions`;
|
|
329
|
+
const suggestionHeaders = {
|
|
330
|
+
'Content-Type': 'application/json',
|
|
331
|
+
...(effectiveLicenseKey ? { 'x-license-key': effectiveLicenseKey } : {}),
|
|
332
|
+
...(effectiveHeaders || {}),
|
|
333
|
+
};
|
|
318
334
|
let response = await fetch(primaryUrl, {
|
|
319
335
|
method: 'POST',
|
|
320
|
-
headers:
|
|
336
|
+
headers: suggestionHeaders,
|
|
321
337
|
body: JSON.stringify({ query: input, namespace: projectId }),
|
|
322
338
|
});
|
|
323
339
|
|
|
324
340
|
if (!response.ok && response.status === 404) {
|
|
325
341
|
response = await fetch('/api/suggestions', {
|
|
326
342
|
method: 'POST',
|
|
327
|
-
headers:
|
|
343
|
+
headers: suggestionHeaders,
|
|
328
344
|
body: JSON.stringify({ query: input, namespace: projectId }),
|
|
329
345
|
});
|
|
330
346
|
}
|
|
@@ -341,7 +357,7 @@ export function ChatWindow({
|
|
|
341
357
|
}, 800); // 800ms debounce to save costs/latency
|
|
342
358
|
|
|
343
359
|
return () => clearTimeout(timer);
|
|
344
|
-
}, [input, projectId,
|
|
360
|
+
}, [input, projectId, effectiveApiBase, effectiveHeaders, effectiveLicenseKey]);
|
|
345
361
|
|
|
346
362
|
return (
|
|
347
363
|
<div
|
|
@@ -7,23 +7,103 @@
|
|
|
7
7
|
* Only the UI-safe portions of RagConfig are exposed to the client.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import React, { createContext, useContext } from 'react';
|
|
10
|
+
import React, { createContext, useContext, useEffect, useMemo, useState } from 'react';
|
|
11
11
|
import { UIConfig } from '../config/RagConfig';
|
|
12
12
|
import { mergeDefined } from '../utils/templateUtils';
|
|
13
13
|
import { ClientConfig, ConfigProviderProps } from '../types';
|
|
14
14
|
import { DEFAULT_CONFIG } from '../config/uiConstants';
|
|
15
|
+
import { ConfigFetcher } from '../core/ConfigFetcher';
|
|
16
|
+
import { normalizeProjectSettings, projectSettingsToUiConfig } from '../core/ProjectSettings';
|
|
15
17
|
|
|
16
18
|
const ConfigContext = createContext<ClientConfig>(DEFAULT_CONFIG);
|
|
17
19
|
|
|
20
|
+
function resolveHeader(headers: Record<string, string> | undefined, name: string): string | undefined {
|
|
21
|
+
if (!headers) return undefined;
|
|
22
|
+
const target = name.toLowerCase();
|
|
23
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
24
|
+
if (key.toLowerCase() === target) return value;
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
18
29
|
export function ConfigProvider({
|
|
19
30
|
config,
|
|
20
31
|
children,
|
|
21
32
|
}: ConfigProviderProps) {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
const projectId = config?.projectId || DEFAULT_CONFIG.projectId;
|
|
34
|
+
const projectSettingsInput = config?.projectSettings;
|
|
35
|
+
const autoLoadProjectSettings = config?.autoLoadProjectSettings;
|
|
36
|
+
const licenseKeyInput = config?.licenseKey;
|
|
37
|
+
const headersInput = config?.headers;
|
|
38
|
+
const retrivoraApiBaseInput = config?.retrivoraApiBase;
|
|
39
|
+
const embeddingInput = config?.embedding;
|
|
40
|
+
const uiInput = config?.ui;
|
|
41
|
+
const explicitSettings = useMemo(
|
|
42
|
+
() => projectSettingsInput
|
|
43
|
+
? normalizeProjectSettings(projectId, projectSettingsInput)
|
|
44
|
+
: undefined,
|
|
45
|
+
[projectSettingsInput, projectId]
|
|
46
|
+
);
|
|
47
|
+
const [remoteSettings, setRemoteSettings] = useState(explicitSettings);
|
|
48
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
let cancelled = false;
|
|
52
|
+
const shouldLoad =
|
|
53
|
+
autoLoadProjectSettings !== false &&
|
|
54
|
+
!explicitSettings &&
|
|
55
|
+
Boolean(licenseKeyInput || resolveHeader(headersInput, 'x-license-key') || resolveHeader(headersInput, 'authorization'));
|
|
56
|
+
|
|
57
|
+
if (!shouldLoad) {
|
|
58
|
+
setRemoteSettings(explicitSettings);
|
|
59
|
+
setIsLoading(false);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const licenseKey =
|
|
64
|
+
licenseKeyInput ||
|
|
65
|
+
resolveHeader(headersInput, 'x-license-key') ||
|
|
66
|
+
resolveHeader(headersInput, 'authorization')?.replace(/^Bearer\s+/i, '') ||
|
|
67
|
+
'';
|
|
68
|
+
|
|
69
|
+
async function loadProjectSettings() {
|
|
70
|
+
setIsLoading(true);
|
|
71
|
+
try {
|
|
72
|
+
const remoteConfig = await ConfigFetcher.fetchRemoteConfig(projectId, licenseKey);
|
|
73
|
+
if (!cancelled) {
|
|
74
|
+
setRemoteSettings(remoteConfig?.projectSettings || explicitSettings);
|
|
75
|
+
}
|
|
76
|
+
} catch {
|
|
77
|
+
if (!cancelled) setRemoteSettings(explicitSettings);
|
|
78
|
+
} finally {
|
|
79
|
+
if (!cancelled) setIsLoading(false);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
loadProjectSettings();
|
|
84
|
+
|
|
85
|
+
return () => {
|
|
86
|
+
cancelled = true;
|
|
87
|
+
};
|
|
88
|
+
}, [autoLoadProjectSettings, headersInput, licenseKeyInput, explicitSettings, projectId]);
|
|
89
|
+
|
|
90
|
+
const merged: ClientConfig = useMemo(() => {
|
|
91
|
+
const settingsUi = remoteSettings ? projectSettingsToUiConfig(remoteSettings) : undefined;
|
|
92
|
+
return {
|
|
93
|
+
projectId,
|
|
94
|
+
ui: mergeDefined(
|
|
95
|
+
DEFAULT_CONFIG.ui,
|
|
96
|
+
mergeDefined(settingsUi || {}, uiInput)
|
|
97
|
+
) as Required<UIConfig>,
|
|
98
|
+
embedding: embeddingInput,
|
|
99
|
+
licenseKey: licenseKeyInput,
|
|
100
|
+
headers: headersInput,
|
|
101
|
+
retrivoraApiBase: retrivoraApiBaseInput,
|
|
102
|
+
projectSettings: remoteSettings,
|
|
103
|
+
autoLoadProjectSettings,
|
|
104
|
+
isProjectSettingsLoading: isLoading,
|
|
105
|
+
};
|
|
106
|
+
}, [autoLoadProjectSettings, embeddingInput, headersInput, licenseKeyInput, retrivoraApiBaseInput, uiInput, isLoading, projectId, remoteSettings]);
|
|
27
107
|
|
|
28
108
|
return <ConfigContext.Provider value={merged}>{children}</ConfigContext.Provider>;
|
|
29
109
|
}
|
|
@@ -12,7 +12,7 @@ interface FileState {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploadComplete, className = '' }: DocumentUploadProps) {
|
|
15
|
-
const { ui, embedding, projectId } = useConfig();
|
|
15
|
+
const { ui, embedding, projectId, licenseKey, headers: configHeaders, retrivoraApiBase: configuredApiBase } = useConfig();
|
|
16
16
|
const [fileStates, setFileStates] = useState<FileState[]>([]);
|
|
17
17
|
const [isDragging, setIsDragging] = useState(false);
|
|
18
18
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
@@ -93,14 +93,19 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
|
|
|
93
93
|
if (targetNs) formData.append('namespace', targetNs);
|
|
94
94
|
formData.append('dimension', dimension.toString());
|
|
95
95
|
|
|
96
|
-
const apiBase = retrivoraApiBase || '/api/retrivora';
|
|
96
|
+
const apiBase = retrivoraApiBase || configuredApiBase || '/api/retrivora';
|
|
97
97
|
const primaryUrl = uploadUrl || `${apiBase.replace(/\/$/, '')}/upload`;
|
|
98
|
+
const uploadHeaders = {
|
|
99
|
+
...(configHeaders || {}),
|
|
100
|
+
...(licenseKey ? { 'x-license-key': licenseKey } : {}),
|
|
101
|
+
};
|
|
98
102
|
|
|
99
103
|
console.log(`[Retrivora SDK] 📤 Initiating upload request to "${primaryUrl}" (Files: ${idleFiles.length}, Namespace: "${targetNs}", Dimension: ${dimension})`);
|
|
100
104
|
|
|
101
105
|
try {
|
|
102
106
|
let response = await fetch(primaryUrl, {
|
|
103
107
|
method: 'POST',
|
|
108
|
+
headers: uploadHeaders,
|
|
104
109
|
body: formData,
|
|
105
110
|
});
|
|
106
111
|
|
|
@@ -108,6 +113,7 @@ export function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploa
|
|
|
108
113
|
console.warn(`[Retrivora SDK] ⚠️ Upload endpoint "${primaryUrl}" returned 404. Retrying fallback to "/api/upload"...`);
|
|
109
114
|
response = await fetch('/api/upload', {
|
|
110
115
|
method: 'POST',
|
|
116
|
+
headers: uploadHeaders,
|
|
111
117
|
body: formData,
|
|
112
118
|
});
|
|
113
119
|
}
|
package/src/config/RagConfig.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
EMBEDDING_PROVIDERS,
|
|
15
15
|
GRAPH_DB_PROVIDERS,
|
|
16
16
|
} from './constants';
|
|
17
|
+
import type { ProjectChatSettings } from '../core/ProjectSettings';
|
|
17
18
|
|
|
18
19
|
export type VectorDBProvider = typeof VECTOR_DB_PROVIDERS[number];
|
|
19
20
|
|
|
@@ -289,6 +290,9 @@ export interface RagConfig {
|
|
|
289
290
|
/** Optional UI branding overrides */
|
|
290
291
|
ui?: UIConfig;
|
|
291
292
|
|
|
293
|
+
/** Optional dashboard-managed project chat settings */
|
|
294
|
+
projectSettings?: ProjectChatSettings;
|
|
295
|
+
|
|
292
296
|
/** Optional RAG pipeline tuning knobs */
|
|
293
297
|
rag?: RAGConfig;
|
|
294
298
|
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ConfigFetcher.ts — Dynamically fetches project credentials from Retrivora Control Plane
|
|
3
3
|
* without hardcoding plain-text master keys in NPM package binaries.
|
|
4
|
+
*
|
|
5
|
+
* SECURITY: The SDK must ONLY call the Retrivora Control Plane at https://www.retrivora.com.
|
|
6
|
+
* It must never call the end user's own localhost or any other endpoint.
|
|
7
|
+
* LLM and embedding calls are proxied through https://www.retrivora.com/api/v1 which
|
|
8
|
+
* forwards to https://llm.retrivora.com with the server-side LITELLM_MASTER_KEY.
|
|
4
9
|
*/
|
|
5
10
|
|
|
11
|
+
import { ProjectChatSettings, normalizeProjectSettings } from './ProjectSettings';
|
|
12
|
+
import { SDK_VERSION } from '../version';
|
|
13
|
+
|
|
6
14
|
export interface RemoteVectorConfig {
|
|
7
15
|
apiKey: string;
|
|
8
16
|
indexName: string;
|
|
9
17
|
provider: string;
|
|
10
18
|
projectId?: string;
|
|
19
|
+
namespace?: string;
|
|
11
20
|
}
|
|
12
21
|
|
|
13
22
|
export interface RemoteEmbeddingConfig {
|
|
@@ -28,20 +37,52 @@ export interface RemoteLLMConfig {
|
|
|
28
37
|
|
|
29
38
|
export interface RemoteConfig {
|
|
30
39
|
projectId?: string;
|
|
40
|
+
tier?: string;
|
|
41
|
+
isActive?: boolean;
|
|
42
|
+
expiresAt?: string;
|
|
31
43
|
vectorDb: RemoteVectorConfig;
|
|
32
44
|
embedding: RemoteEmbeddingConfig;
|
|
33
45
|
llm: RemoteLLMConfig;
|
|
46
|
+
workspace?: {
|
|
47
|
+
namespace: string;
|
|
48
|
+
indexName: string;
|
|
49
|
+
};
|
|
50
|
+
projectSettings?: ProjectChatSettings;
|
|
34
51
|
}
|
|
35
52
|
|
|
36
53
|
// Legacy alias
|
|
37
54
|
export type { RemoteVectorConfig as RemoteConfig_ };
|
|
38
55
|
|
|
56
|
+
/**
|
|
57
|
+
* The single source of truth for the Retrivora Control Plane URL.
|
|
58
|
+
* The SDK must only communicate with this endpoint — never with the end user's localhost.
|
|
59
|
+
*/
|
|
60
|
+
const CONTROL_PLANE_URL = 'https://www.retrivora.com';
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The LLM/Embedding proxy gateway. All LLM and embedding requests are routed
|
|
64
|
+
* through https://www.retrivora.com/api/v1, which validates the license key and
|
|
65
|
+
* forwards to https://llm.retrivora.com with the server-side master key.
|
|
66
|
+
* End users never need to know about llm.retrivora.com directly.
|
|
67
|
+
*/
|
|
68
|
+
const LLM_PROXY_BASE_URL = 'https://www.retrivora.com/api/v1';
|
|
69
|
+
|
|
39
70
|
export class ConfigFetcher {
|
|
40
71
|
private static cache = new Map<string, { config: RemoteConfig; cachedAt: number }>();
|
|
41
72
|
private static readonly TTL_MS = 5 * 60 * 1000; // 5-minute in-memory session cache
|
|
42
73
|
|
|
43
74
|
/**
|
|
44
|
-
* Fetch full project configuration (vectorDb + embedding + llm) from Retrivora Control Plane.
|
|
75
|
+
* Fetch full project configuration (vectorDb + embedding + llm + workspace) from Retrivora Control Plane.
|
|
76
|
+
*
|
|
77
|
+
* The SDK calls https://www.retrivora.com/api/v1/config with the project ID and license key.
|
|
78
|
+
* The server validates the license against the database and returns:
|
|
79
|
+
* - validity (tier, isActive, expiresAt)
|
|
80
|
+
* - LLM model info
|
|
81
|
+
* - embedding model info
|
|
82
|
+
* - Pinecone index name and workspace/namespace
|
|
83
|
+
*
|
|
84
|
+
* The Pinecone API key is NOT returned (server-only). The SDK uses local
|
|
85
|
+
* PINECONE_API_KEY if available, or vector operations are handled server-side.
|
|
45
86
|
*/
|
|
46
87
|
static async fetchRemoteConfig(projectId: string, licenseKey?: string): Promise<RemoteConfig | null> {
|
|
47
88
|
const cacheKey = `${projectId}:${licenseKey || ''}`;
|
|
@@ -52,52 +93,73 @@ export class ConfigFetcher {
|
|
|
52
93
|
return cached.config;
|
|
53
94
|
}
|
|
54
95
|
|
|
96
|
+
// SECURITY: Only call the Retrivora Control Plane — never localhost or any other endpoint.
|
|
97
|
+
// Environment overrides are allowed for explicit server-side configuration, but
|
|
98
|
+
// localhost URLs are explicitly excluded to prevent calling the end user's own app.
|
|
55
99
|
const controlPlaneUrls = [
|
|
56
100
|
process.env.RETRIVORA_CONTROL_PLANE_URL,
|
|
57
101
|
process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
'
|
|
61
|
-
'
|
|
62
|
-
].filter(Boolean) as string[];
|
|
102
|
+
CONTROL_PLANE_URL,
|
|
103
|
+
]
|
|
104
|
+
.filter((url): url is string => Boolean(url) && !url!.includes('localhost') && !url!.includes('127.0.0.1'))
|
|
105
|
+
.map((url) => url.replace(/\/$/, ''));
|
|
63
106
|
|
|
64
107
|
for (const baseUrl of controlPlaneUrls) {
|
|
65
108
|
try {
|
|
66
|
-
const url = `${baseUrl
|
|
109
|
+
const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
|
|
67
110
|
const res = await fetch(url, {
|
|
68
111
|
method: 'GET',
|
|
69
112
|
headers: {
|
|
70
113
|
'Content-Type': 'application/json',
|
|
114
|
+
'x-sdk-version': SDK_VERSION,
|
|
71
115
|
...(licenseKey ? { 'x-license-key': licenseKey } : {}),
|
|
72
116
|
},
|
|
73
117
|
});
|
|
74
118
|
|
|
75
119
|
if (res.ok) {
|
|
76
120
|
const data = await res.json();
|
|
77
|
-
|
|
121
|
+
// NOTE: The config API intentionally does NOT return vectorDb.apiKey (server-only secret).
|
|
122
|
+
// We check for data.success and data.vectorDb presence instead.
|
|
123
|
+
if (data?.success && data?.vectorDb) {
|
|
78
124
|
const fetchedProjectId = data.projectId || projectId;
|
|
79
125
|
const config: RemoteConfig = {
|
|
80
126
|
projectId: fetchedProjectId,
|
|
127
|
+
tier: data.tier,
|
|
128
|
+
isActive: data.isActive,
|
|
129
|
+
expiresAt: data.expiresAt,
|
|
81
130
|
vectorDb: {
|
|
82
|
-
apiKey
|
|
131
|
+
// apiKey is not returned by the config API — it's a server-only secret.
|
|
132
|
+
// The SDK uses local PINECONE_API_KEY if available.
|
|
133
|
+
apiKey: data.vectorDb.apiKey || '',
|
|
83
134
|
indexName: data.vectorDb.indexName || 'retrivora-free',
|
|
84
135
|
provider: data.vectorDb.provider || 'pinecone',
|
|
85
136
|
projectId: fetchedProjectId,
|
|
137
|
+
namespace: data.workspace?.namespace || data.vectorDb.namespace || fetchedProjectId,
|
|
86
138
|
},
|
|
87
139
|
embedding: {
|
|
88
140
|
provider: data.embedding?.provider || 'universal_rest',
|
|
89
141
|
model: data.embedding?.model || 'text-embedding-004',
|
|
90
|
-
|
|
142
|
+
// Route through www.retrivora.com proxy, not llm.retrivora.com directly.
|
|
143
|
+
baseUrl: data.embedding?.baseUrl || LLM_PROXY_BASE_URL,
|
|
91
144
|
apiKey: data.embedding?.apiKey || licenseKey || '',
|
|
92
145
|
profile: data.embedding?.profile || 'litellm',
|
|
93
146
|
},
|
|
94
147
|
llm: {
|
|
95
148
|
provider: data.llm?.provider || 'universal_rest',
|
|
96
149
|
model: data.llm?.model || 'llama-3.1-8b-instant',
|
|
97
|
-
|
|
150
|
+
// Route through www.retrivora.com proxy, not llm.retrivora.com directly.
|
|
151
|
+
baseUrl: data.llm?.baseUrl || LLM_PROXY_BASE_URL,
|
|
98
152
|
apiKey: data.llm?.apiKey || licenseKey || '',
|
|
99
153
|
profile: data.llm?.profile || 'litellm',
|
|
100
154
|
},
|
|
155
|
+
workspace: data.workspace || {
|
|
156
|
+
namespace: fetchedProjectId,
|
|
157
|
+
indexName: data.vectorDb.indexName || 'retrivora-free',
|
|
158
|
+
},
|
|
159
|
+
projectSettings: normalizeProjectSettings(
|
|
160
|
+
fetchedProjectId,
|
|
161
|
+
data.projectSettings || data.settings
|
|
162
|
+
),
|
|
101
163
|
};
|
|
102
164
|
this.cache.set(cacheKey, { config, cachedAt: now });
|
|
103
165
|
return config;
|
|
@@ -60,6 +60,7 @@ export class ConfigResolver {
|
|
|
60
60
|
}
|
|
61
61
|
: envConfig.embedding,
|
|
62
62
|
ui: hostConfig.ui ? mergeDefined(envConfig.ui, hostConfig.ui) : envConfig.ui,
|
|
63
|
+
projectSettings: hostConfig.projectSettings || envConfig.projectSettings,
|
|
63
64
|
rag: hostConfig.rag ? { ...envConfig.rag, ...hostConfig.rag } : envConfig.rag,
|
|
64
65
|
telemetry: hostConfig.telemetry
|
|
65
66
|
? {
|