@retrivora-ai/rag-engine 2.4.0 → 2.4.1
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/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
|
@@ -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.';
|
package/src/llm/LLMFactory.ts
CHANGED
|
@@ -40,7 +40,7 @@ export class LLMFactory {
|
|
|
40
40
|
*/
|
|
41
41
|
static register(name: string, factory: (config: LLMConfig) => ILLMProvider): void {
|
|
42
42
|
customProviders.set(name.toLowerCase(), factory);
|
|
43
|
-
console.log(`[LLMFactory] Registered custom provider: "${name}"`);
|
|
43
|
+
//console.log(`[LLMFactory] Registered custom provider: "${name}"`);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
@@ -70,12 +70,12 @@ export class UniversalLLMAdapter implements ILLMProvider {
|
|
|
70
70
|
...(this.opts.headers || {}),
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
-
console.log('[UniversalLLMAdapter] Initialized with:', {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
});
|
|
73
|
+
// console.log('[UniversalLLMAdapter] Initialized with:', {
|
|
74
|
+
// model: this.model,
|
|
75
|
+
// baseUrl: this.baseUrl,
|
|
76
|
+
// hasApiKey: !!this.apiKey,
|
|
77
|
+
// apiKeyPrefix: this.apiKey ? `${this.apiKey.slice(0, 12)}...` : undefined,
|
|
78
|
+
// });
|
|
79
79
|
|
|
80
80
|
this.http = axios.create({
|
|
81
81
|
baseURL: this.baseUrl,
|
|
@@ -121,7 +121,7 @@ export class UniversalLLMAdapter implements ILLMProvider {
|
|
|
121
121
|
console.debug(`[UniversalLLMAdapter] POST ${this.baseUrl}${path}`);
|
|
122
122
|
console.debug(`[UniversalLLMAdapter] Model: ${this.model}`);
|
|
123
123
|
console.debug(`[UniversalLLMAdapter] Auth: Bearer ${this.apiKey?.substring(0, 20) || 'none'}...`);
|
|
124
|
-
|
|
124
|
+
|
|
125
125
|
const { data } = await this.http.post(path, payload);
|
|
126
126
|
const extractPath = this.opts.responseExtractPath ?? 'choices[0].message.content';
|
|
127
127
|
const result = resolvePath(data, extractPath) ?? extractContent(data);
|
|
@@ -173,7 +173,7 @@ export class UniversalLLMAdapter implements ILLMProvider {
|
|
|
173
173
|
* Streaming chat using native fetch + ReadableStream.
|
|
174
174
|
* Parses OpenAI-compatible SSE frames: `data: {...}\n\n`
|
|
175
175
|
*/
|
|
176
|
-
async *chatStream(messages: ChatMessage[], context?: string): AsyncIterable<string> {
|
|
176
|
+
async * chatStream(messages: ChatMessage[], context?: string): AsyncIterable<string> {
|
|
177
177
|
const path = this.opts.chatPath ?? '/chat/completions';
|
|
178
178
|
const url = `${this.baseUrl.replace(/\/$/, '')}${path}`;
|
|
179
179
|
const extractPath = (this.opts.responseExtractPath ?? 'choices[0].message.content')
|
|
@@ -325,18 +325,18 @@ export class UniversalLLMAdapter implements ILLMProvider {
|
|
|
325
325
|
|
|
326
326
|
// First attempt: try HTTP call with fallback
|
|
327
327
|
try {
|
|
328
|
-
console.log(`[UniversalLLMAdapter] Posting to embedding endpoint: ${this.baseUrl}${path}`, {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
});
|
|
328
|
+
// console.log(`[UniversalLLMAdapter] Posting to embedding endpoint: ${this.baseUrl}${path}`, {
|
|
329
|
+
// model: this.model,
|
|
330
|
+
// inputLength: typeof text === 'string' ? text.length : 'unknown',
|
|
331
|
+
// });
|
|
332
332
|
const { data } = await this.http.post(path, payload);
|
|
333
333
|
const extractPath = this.opts.embedExtractPath ?? 'data[0].embedding';
|
|
334
334
|
const vector = resolvePath(data, extractPath) as number[] | undefined;
|
|
335
335
|
if (Array.isArray(vector)) {
|
|
336
|
-
console.log(`[UniversalLLMAdapter] Embedding HTTP request successful. Vector size: ${vector.length}`);
|
|
336
|
+
//console.log(`[UniversalLLMAdapter] Embedding HTTP request successful. Vector size: ${vector.length}`);
|
|
337
337
|
return vector;
|
|
338
338
|
}
|
|
339
|
-
|
|
339
|
+
|
|
340
340
|
// If we get here, the API succeeded but the response format was invalid
|
|
341
341
|
console.warn(
|
|
342
342
|
`[UniversalLLMAdapter] Embedding API returned unexpected format for path '${extractPath}'. Response:`,
|
|
@@ -347,7 +347,7 @@ export class UniversalLLMAdapter implements ILLMProvider {
|
|
|
347
347
|
`[UniversalLLMAdapter] HTTP embedding request failed: ${err?.message || err}`,
|
|
348
348
|
{ path, model: this.model, response: err?.response?.data }
|
|
349
349
|
);
|
|
350
|
-
|
|
350
|
+
|
|
351
351
|
// In-process fallback for embeddings
|
|
352
352
|
const _g = globalThis as any;
|
|
353
353
|
const dispatchEmbed = _g.__retrivoraDispatchEmbedding;
|
|
@@ -366,16 +366,16 @@ export class UniversalLLMAdapter implements ILLMProvider {
|
|
|
366
366
|
|
|
367
367
|
// Second attempt: retry the HTTP call
|
|
368
368
|
try {
|
|
369
|
-
console.log(`[UniversalLLMAdapter] Retrying embedding request to: ${this.baseUrl}${path}`);
|
|
369
|
+
//console.log(`[UniversalLLMAdapter] Retrying embedding request to: ${this.baseUrl}${path}`);
|
|
370
370
|
const { data } = await this.http.post(path, payload);
|
|
371
371
|
const extractPath = this.opts.embedExtractPath ?? 'data[0].embedding';
|
|
372
372
|
const vector = resolvePath(data, extractPath) as number[] | undefined;
|
|
373
373
|
|
|
374
374
|
if (Array.isArray(vector)) {
|
|
375
|
-
console.log(`[UniversalLLMAdapter] Retry embedding HTTP request successful. Vector size: ${vector.length}`);
|
|
375
|
+
//console.log(`[UniversalLLMAdapter] Retry embedding HTTP request successful. Vector size: ${vector.length}`);
|
|
376
376
|
return vector;
|
|
377
377
|
}
|
|
378
|
-
|
|
378
|
+
|
|
379
379
|
console.error(
|
|
380
380
|
`[UniversalLLMAdapter] Retry embedding failed: unexpected response format for path '${extractPath}'. Response:`,
|
|
381
381
|
data
|
|
@@ -9,7 +9,7 @@ export class SimpleGraphProvider extends BaseGraphProvider {
|
|
|
9
9
|
private edges: Edge[] = [];
|
|
10
10
|
|
|
11
11
|
async initialize(): Promise<void> {
|
|
12
|
-
console.log('[SimpleGraphProvider] Initialised in-memory graph store.');
|
|
12
|
+
//console.log('[SimpleGraphProvider] Initialised in-memory graph store.');
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
async addNodes(nodes: GraphNode[]): Promise<void> {
|
|
@@ -24,16 +24,16 @@ export class SimpleGraphProvider extends BaseGraphProvider {
|
|
|
24
24
|
|
|
25
25
|
async query(queryText: string, limit = 5): Promise<GraphSearchResult> {
|
|
26
26
|
const q = queryText.toLowerCase();
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
// Simple keyword matching for demonstration
|
|
29
|
-
const matchedNodes = Array.from(this.nodes.values()).filter(node =>
|
|
30
|
-
node.id.toLowerCase().includes(q) ||
|
|
29
|
+
const matchedNodes = Array.from(this.nodes.values()).filter(node =>
|
|
30
|
+
node.id.toLowerCase().includes(q) ||
|
|
31
31
|
node.label.toLowerCase().includes(q) ||
|
|
32
32
|
JSON.stringify(node.properties).toLowerCase().includes(q)
|
|
33
33
|
).slice(0, limit);
|
|
34
34
|
|
|
35
35
|
const matchedNodeIds = new Set(matchedNodes.map(n => n.id));
|
|
36
|
-
const matchedEdges = this.edges.filter(edge =>
|
|
36
|
+
const matchedEdges = this.edges.filter(edge =>
|
|
37
37
|
matchedNodeIds.has(edge.source) || matchedNodeIds.has(edge.target)
|
|
38
38
|
);
|
|
39
39
|
|