@retrivora-ai/rag-engine 0.1.7 → 0.1.9
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/{ChromaDBProvider-QNI7UCX4.mjs → ChromaDBProvider-T7TK3ONZ.mjs} +2 -2
- package/dist/{MilvusProvider-OO6QGZDZ.mjs → MilvusProvider-Y5FV5EAE.mjs} +2 -2
- package/dist/{MongoDBProvider-WWVJG3WT.mjs → MongoDBProvider-QHMGD2LZ.mjs} +2 -2
- package/dist/{PineconeProvider-ZRAFNFEC.mjs → PineconeProvider-A47MRRYJ.mjs} +2 -2
- package/dist/{PostgreSQLProvider-ZNXA67IM.mjs → PostgreSQLProvider-PJ5ER5Z4.mjs} +1 -1
- package/dist/{QdrantProvider-VAED5VA7.mjs → QdrantProvider-OLPJK7CY.mjs} +2 -2
- package/dist/{RagConfig-hBGXJmSx.d.mts → RagConfig-D_rSf8ep.d.mts} +1 -1
- package/dist/{RagConfig-hBGXJmSx.d.ts → RagConfig-D_rSf8ep.d.ts} +1 -1
- package/dist/{RedisProvider-ASONNYBI.mjs → RedisProvider-ANEJ3BHR.mjs} +2 -2
- package/dist/UniversalVectorProvider-QJIV2AJJ.mjs +9 -0
- package/dist/{WeaviateProvider-PSDCUGC7.mjs → WeaviateProvider-WIK2QN23.mjs} +2 -2
- package/dist/{chunk-7YQWGERZ.mjs → chunk-2VR5ZMXV.mjs} +740 -193
- package/dist/{chunk-QEYVWVT5.mjs → chunk-5HXNKSCR.mjs} +1 -1
- package/dist/{chunk-ZM6TYIDH.mjs → chunk-BMHJTWSU.mjs} +4 -2
- package/dist/{chunk-UKDXCXW7.mjs → chunk-EDLTMSNY.mjs} +1 -1
- package/dist/{chunk-I4E63NIC.mjs → chunk-FWCSY2DS.mjs} +14 -1
- package/dist/{chunk-VPNRDXIA.mjs → chunk-HOMXEE3M.mjs} +17 -11
- package/dist/{chunk-V75V7BT2.mjs → chunk-RUKZC3ON.mjs} +3 -3
- package/dist/{chunk-7NXI6ZWX.mjs → chunk-VEJNRS4B.mjs} +9 -6
- package/dist/{chunk-HUGLYKD6.mjs → chunk-VKE5ZW7Y.mjs} +28 -10
- package/dist/chunk-VV2ML6TM.mjs +156 -0
- package/dist/{chunk-CWQQHAF6.mjs → chunk-W2PQR3UK.mjs} +4 -6
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +877 -625
- package/dist/handlers/index.mjs +3 -4
- package/dist/index-BJ8CUArE.d.mts +114 -0
- package/dist/index-DtNprGGj.d.ts +114 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +67 -58
- package/dist/index.mjs +74 -47
- package/dist/server.d.mts +601 -17
- package/dist/server.d.ts +601 -17
- package/dist/server.js +1426 -708
- package/dist/server.mjs +429 -18
- package/package.json +11 -2
- package/src/app/constants.tsx +220 -0
- package/src/app/page.tsx +193 -363
- package/src/app/types.ts +30 -0
- package/src/components/ChatWindow.tsx +3 -11
- package/src/config/ConfigBuilder.ts +373 -0
- package/src/config/EmbeddingStrategy.ts +147 -0
- package/src/config/serverConfig.ts +51 -18
- package/src/core/ConfigValidator.ts +67 -50
- package/src/core/Pipeline.ts +28 -26
- package/src/core/PluginManager.ts +277 -0
- package/src/core/ProviderHealthCheck.ts +75 -139
- package/src/core/ProviderRegistry.ts +38 -15
- package/src/providers/vectordb/ChromaDBProvider.ts +37 -12
- package/src/providers/vectordb/MilvusProvider.ts +25 -10
- package/src/providers/vectordb/MultiTablePostgresProvider.ts +164 -0
- package/src/providers/vectordb/PineconeProvider.ts +17 -2
- package/src/providers/vectordb/QdrantProvider.ts +3 -6
- package/src/providers/vectordb/RedisProvider.ts +34 -11
- package/src/providers/vectordb/UniversalVectorProvider.ts +220 -0
- package/src/providers/vectordb/WeaviateProvider.ts +17 -10
- package/src/server.ts +29 -10
- package/dist/LLMFactory-JFOY2V4X.mjs +0 -8
- package/dist/chunk-JI6VD5TJ.mjs +0 -387
- package/dist/index-Bx182KKn.d.ts +0 -64
- package/dist/index-Ck2pt7-8.d.mts +0 -64
- package/src/test-refactor.ts +0 -59
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PluginManager — Universal plugin registration and lifecycle management
|
|
3
|
+
*
|
|
4
|
+
* Provides a flexible architecture for registering custom vector DBs, LLMs,
|
|
5
|
+
* and other providers without modifying core code.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Dynamic plugin registration
|
|
9
|
+
* - Dependency resolution
|
|
10
|
+
* - Plugin validation
|
|
11
|
+
* - Lifecycle management
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export interface PluginMetadata {
|
|
15
|
+
/** Unique identifier (e.g., 'myprovider.vectordb.custom') */
|
|
16
|
+
id: string;
|
|
17
|
+
/** Human-readable name */
|
|
18
|
+
name: string;
|
|
19
|
+
/** Plugin version */
|
|
20
|
+
version: string;
|
|
21
|
+
/** Detailed description */
|
|
22
|
+
description?: string;
|
|
23
|
+
/** Author information */
|
|
24
|
+
author?: string;
|
|
25
|
+
/** Supported capabilities */
|
|
26
|
+
capabilities: PluginCapability[];
|
|
27
|
+
/** Required dependencies (other plugin IDs) */
|
|
28
|
+
dependencies?: string[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type PluginCapability = 'chat' | 'embed' | 'vector-db' | 'reranker' | 'parser';
|
|
32
|
+
|
|
33
|
+
export interface IPluginProvider {
|
|
34
|
+
/**
|
|
35
|
+
* Get plugin metadata
|
|
36
|
+
*/
|
|
37
|
+
getMetadata(): PluginMetadata;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Validate configuration for this plugin
|
|
41
|
+
*/
|
|
42
|
+
validateConfig?(config: Record<string, unknown>): {
|
|
43
|
+
valid: boolean;
|
|
44
|
+
errors?: string[];
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Initialize plugin with configuration
|
|
49
|
+
*/
|
|
50
|
+
initialize(config: Record<string, unknown>): Promise<void>;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Check if plugin is ready
|
|
54
|
+
*/
|
|
55
|
+
isReady(): Promise<boolean>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Gracefully shutdown plugin
|
|
59
|
+
*/
|
|
60
|
+
shutdown(): Promise<void>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Get plugin-specific health status
|
|
64
|
+
*/
|
|
65
|
+
getHealthStatus?(): Promise<{
|
|
66
|
+
healthy: boolean;
|
|
67
|
+
details?: Record<string, unknown>;
|
|
68
|
+
}>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface PluginDescriptor {
|
|
72
|
+
metadata: PluginMetadata;
|
|
73
|
+
factory: (config: Record<string, unknown>) => Promise<IPluginProvider>;
|
|
74
|
+
validateConfig?: (config: Record<string, unknown>) => {
|
|
75
|
+
valid: boolean;
|
|
76
|
+
errors?: string[];
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export class PluginManager {
|
|
81
|
+
private static readonly registeredPlugins: Map<string, PluginDescriptor> = new Map();
|
|
82
|
+
private static readonly instances: Map<string, IPluginProvider> = new Map();
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Register a new plugin provider
|
|
86
|
+
*/
|
|
87
|
+
static registerPlugin(descriptor: PluginDescriptor): void {
|
|
88
|
+
const { metadata } = descriptor;
|
|
89
|
+
|
|
90
|
+
if (this.registeredPlugins.has(metadata.id)) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`[PluginManager] Plugin with ID "${metadata.id}" is already registered. ` +
|
|
93
|
+
`Use unregisterPlugin() first if you need to replace it.`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Validate metadata
|
|
98
|
+
if (!metadata.id || !metadata.name || !metadata.version) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
'[PluginManager] Plugin metadata must include id, name, and version'
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (metadata.capabilities.length === 0) {
|
|
105
|
+
throw new Error('[PluginManager] Plugin must declare at least one capability');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
this.registeredPlugins.set(metadata.id, descriptor);
|
|
109
|
+
console.log(
|
|
110
|
+
`[PluginManager] Registered plugin: ${metadata.name} v${metadata.version} (${metadata.id})`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Unregister a plugin and cleanup its instance
|
|
116
|
+
*/
|
|
117
|
+
static async unregisterPlugin(pluginId: string): Promise<void> {
|
|
118
|
+
if (this.instances.has(pluginId)) {
|
|
119
|
+
const instance = this.instances.get(pluginId)!;
|
|
120
|
+
await instance.shutdown();
|
|
121
|
+
this.instances.delete(pluginId);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
this.registeredPlugins.delete(pluginId);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Get plugin metadata
|
|
129
|
+
*/
|
|
130
|
+
static getPluginMetadata(pluginId: string): PluginMetadata | null {
|
|
131
|
+
return this.registeredPlugins.get(pluginId)?.metadata ?? null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* List all registered plugins with optional filtering by capability
|
|
136
|
+
*/
|
|
137
|
+
static listPlugins(capability?: PluginCapability): PluginMetadata[] {
|
|
138
|
+
const plugins = Array.from(this.registeredPlugins.values()).map(d => d.metadata);
|
|
139
|
+
|
|
140
|
+
if (capability) {
|
|
141
|
+
return plugins.filter(p => p.capabilities.includes(capability));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return plugins;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Create and cache a plugin instance with dependency resolution
|
|
149
|
+
*/
|
|
150
|
+
static async createInstance(
|
|
151
|
+
pluginId: string,
|
|
152
|
+
config: Record<string, unknown>
|
|
153
|
+
): Promise<IPluginProvider> {
|
|
154
|
+
// Return cached instance if already created
|
|
155
|
+
if (this.instances.has(pluginId)) {
|
|
156
|
+
return this.instances.get(pluginId)!;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const descriptor = this.registeredPlugins.get(pluginId);
|
|
160
|
+
if (!descriptor) {
|
|
161
|
+
throw new Error(
|
|
162
|
+
`[PluginManager] Plugin "${pluginId}" not registered. ` +
|
|
163
|
+
`Registered plugins: ${Array.from(this.registeredPlugins.keys()).join(', ')}`
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const { metadata, factory } = descriptor;
|
|
168
|
+
|
|
169
|
+
// Validate configuration
|
|
170
|
+
if (descriptor.validateConfig) {
|
|
171
|
+
const validation = descriptor.validateConfig(config);
|
|
172
|
+
if (!validation.valid) {
|
|
173
|
+
throw new Error(
|
|
174
|
+
`[PluginManager] Invalid configuration for plugin "${pluginId}": ` +
|
|
175
|
+
`${validation.errors?.join('; ') || 'Unknown error'}`
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Resolve dependencies
|
|
181
|
+
if (metadata.dependencies && metadata.dependencies.length > 0) {
|
|
182
|
+
for (const depId of metadata.dependencies) {
|
|
183
|
+
if (!this.instances.has(depId)) {
|
|
184
|
+
throw new Error(
|
|
185
|
+
`[PluginManager] Plugin "${pluginId}" requires "${depId}" to be initialized first`
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Initialize plugin
|
|
192
|
+
console.log(`[PluginManager] Initializing plugin: ${pluginId}`);
|
|
193
|
+
const instance = await factory(config);
|
|
194
|
+
|
|
195
|
+
// Verify plugin is ready
|
|
196
|
+
const isReady = await instance.isReady();
|
|
197
|
+
if (!isReady) {
|
|
198
|
+
throw new Error(
|
|
199
|
+
`[PluginManager] Plugin "${pluginId}" failed to initialize properly`
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Cache instance
|
|
204
|
+
this.instances.set(pluginId, instance);
|
|
205
|
+
|
|
206
|
+
return instance;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Get cached instance of a plugin
|
|
211
|
+
*/
|
|
212
|
+
static getInstance(pluginId: string): IPluginProvider | null {
|
|
213
|
+
return this.instances.get(pluginId) ?? null;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Check if a plugin is ready (either registered or instantiated)
|
|
218
|
+
*/
|
|
219
|
+
static isPluginAvailable(pluginId: string): boolean {
|
|
220
|
+
return this.registeredPlugins.has(pluginId) || this.instances.has(pluginId);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Shutdown all plugin instances
|
|
225
|
+
*/
|
|
226
|
+
static async shutdownAll(): Promise<void> {
|
|
227
|
+
const errors: Error[] = [];
|
|
228
|
+
|
|
229
|
+
for (const [pluginId, instance] of this.instances.entries()) {
|
|
230
|
+
try {
|
|
231
|
+
await instance.shutdown();
|
|
232
|
+
console.log(`[PluginManager] Shutdown plugin: ${pluginId}`);
|
|
233
|
+
} catch (error) {
|
|
234
|
+
errors.push(
|
|
235
|
+
new Error(`Failed to shutdown plugin ${pluginId}: ${error instanceof Error ? error.message : String(error)}`)
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
this.instances.clear();
|
|
241
|
+
|
|
242
|
+
if (errors.length > 0) {
|
|
243
|
+
throw new AggregateError(errors, '[PluginManager] Errors during shutdown');
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Get health status of all instantiated plugins
|
|
249
|
+
*/
|
|
250
|
+
static async getHealthStatus(): Promise<
|
|
251
|
+
Map<string, { healthy: boolean; details?: Record<string, unknown> }>
|
|
252
|
+
> {
|
|
253
|
+
const status = new Map();
|
|
254
|
+
|
|
255
|
+
for (const [pluginId, instance] of this.instances.entries()) {
|
|
256
|
+
try {
|
|
257
|
+
const health = await instance.getHealthStatus?.();
|
|
258
|
+
status.set(pluginId, health ?? { healthy: true });
|
|
259
|
+
} catch (error) {
|
|
260
|
+
status.set(pluginId, {
|
|
261
|
+
healthy: false,
|
|
262
|
+
details: { error: error instanceof Error ? error.message : String(error) },
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return status;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Clear all registered and instantiated plugins (for testing)
|
|
272
|
+
*/
|
|
273
|
+
static reset(): void {
|
|
274
|
+
this.registeredPlugins.clear();
|
|
275
|
+
this.instances.clear();
|
|
276
|
+
}
|
|
277
|
+
}
|