@sparkleideas/plugins 3.0.0-alpha.10

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.
Files changed (80) hide show
  1. package/README.md +401 -0
  2. package/__tests__/collection-manager.test.ts +332 -0
  3. package/__tests__/dependency-graph.test.ts +434 -0
  4. package/__tests__/enhanced-plugin-registry.test.ts +488 -0
  5. package/__tests__/plugin-registry.test.ts +368 -0
  6. package/__tests__/ruvector-bridge.test.ts +2429 -0
  7. package/__tests__/ruvector-integration.test.ts +1602 -0
  8. package/__tests__/ruvector-migrations.test.ts +1099 -0
  9. package/__tests__/ruvector-quantization.test.ts +846 -0
  10. package/__tests__/ruvector-streaming.test.ts +1088 -0
  11. package/__tests__/sdk.test.ts +325 -0
  12. package/__tests__/security.test.ts +348 -0
  13. package/__tests__/utils/ruvector-test-utils.ts +860 -0
  14. package/examples/plugin-creator/index.ts +636 -0
  15. package/examples/plugin-creator/plugin-creator.test.ts +312 -0
  16. package/examples/ruvector/README.md +288 -0
  17. package/examples/ruvector/attention-patterns.ts +394 -0
  18. package/examples/ruvector/basic-usage.ts +288 -0
  19. package/examples/ruvector/docker-compose.yml +75 -0
  20. package/examples/ruvector/gnn-analysis.ts +501 -0
  21. package/examples/ruvector/hyperbolic-hierarchies.ts +557 -0
  22. package/examples/ruvector/init-db.sql +119 -0
  23. package/examples/ruvector/quantization.ts +680 -0
  24. package/examples/ruvector/self-learning.ts +447 -0
  25. package/examples/ruvector/semantic-search.ts +576 -0
  26. package/examples/ruvector/streaming-large-data.ts +507 -0
  27. package/examples/ruvector/transactions.ts +594 -0
  28. package/examples/ruvector-plugins/hook-pattern-library.ts +486 -0
  29. package/examples/ruvector-plugins/index.ts +79 -0
  30. package/examples/ruvector-plugins/intent-router.ts +354 -0
  31. package/examples/ruvector-plugins/mcp-tool-optimizer.ts +424 -0
  32. package/examples/ruvector-plugins/reasoning-bank.ts +657 -0
  33. package/examples/ruvector-plugins/ruvector-plugins.test.ts +518 -0
  34. package/examples/ruvector-plugins/semantic-code-search.ts +498 -0
  35. package/examples/ruvector-plugins/shared/index.ts +20 -0
  36. package/examples/ruvector-plugins/shared/vector-utils.ts +257 -0
  37. package/examples/ruvector-plugins/sona-learning.ts +445 -0
  38. package/package.json +97 -0
  39. package/src/collections/collection-manager.ts +661 -0
  40. package/src/collections/index.ts +56 -0
  41. package/src/collections/official/index.ts +1040 -0
  42. package/src/core/base-plugin.ts +416 -0
  43. package/src/core/plugin-interface.ts +215 -0
  44. package/src/hooks/index.ts +685 -0
  45. package/src/index.ts +378 -0
  46. package/src/integrations/agentic-flow.ts +743 -0
  47. package/src/integrations/index.ts +88 -0
  48. package/src/integrations/ruvector/ARCHITECTURE.md +1245 -0
  49. package/src/integrations/ruvector/attention-advanced.ts +1040 -0
  50. package/src/integrations/ruvector/attention-executor.ts +782 -0
  51. package/src/integrations/ruvector/attention-mechanisms.ts +757 -0
  52. package/src/integrations/ruvector/attention.ts +1063 -0
  53. package/src/integrations/ruvector/gnn.ts +3050 -0
  54. package/src/integrations/ruvector/hyperbolic.ts +1948 -0
  55. package/src/integrations/ruvector/index.ts +394 -0
  56. package/src/integrations/ruvector/migrations/001_create_extension.sql +135 -0
  57. package/src/integrations/ruvector/migrations/002_create_vector_tables.sql +259 -0
  58. package/src/integrations/ruvector/migrations/003_create_indices.sql +328 -0
  59. package/src/integrations/ruvector/migrations/004_create_functions.sql +598 -0
  60. package/src/integrations/ruvector/migrations/005_create_attention_functions.sql +654 -0
  61. package/src/integrations/ruvector/migrations/006_create_gnn_functions.sql +728 -0
  62. package/src/integrations/ruvector/migrations/007_create_hyperbolic_functions.sql +762 -0
  63. package/src/integrations/ruvector/migrations/index.ts +35 -0
  64. package/src/integrations/ruvector/migrations/migrations.ts +647 -0
  65. package/src/integrations/ruvector/quantization.ts +2036 -0
  66. package/src/integrations/ruvector/ruvector-bridge.ts +2000 -0
  67. package/src/integrations/ruvector/self-learning.ts +2376 -0
  68. package/src/integrations/ruvector/streaming.ts +1737 -0
  69. package/src/integrations/ruvector/types.ts +1945 -0
  70. package/src/providers/index.ts +643 -0
  71. package/src/registry/dependency-graph.ts +568 -0
  72. package/src/registry/enhanced-plugin-registry.ts +994 -0
  73. package/src/registry/plugin-registry.ts +604 -0
  74. package/src/sdk/index.ts +563 -0
  75. package/src/security/index.ts +594 -0
  76. package/src/types/index.ts +446 -0
  77. package/src/workers/index.ts +700 -0
  78. package/tmp.json +0 -0
  79. package/tsconfig.json +25 -0
  80. package/vitest.config.ts +23 -0
@@ -0,0 +1,394 @@
1
+ /**
2
+ * RuVector PostgreSQL Bridge
3
+ *
4
+ * Integration module for RuVector - a PostgreSQL extension providing
5
+ * advanced vector search, attention mechanisms, graph neural networks,
6
+ * and hyperbolic embeddings.
7
+ *
8
+ * @module @sparkleideas/plugins/integrations/ruvector
9
+ */
10
+
11
+ // Export the main bridge plugin
12
+ export { RuVectorBridge, createRuVectorBridge } from './ruvector-bridge.js';
13
+ export { default as RuVectorBridgeDefault } from './ruvector-bridge.js';
14
+
15
+ // Export all types
16
+ export * from './types.js';
17
+
18
+ // Export GNN module
19
+ export * from './gnn.js';
20
+
21
+ // Export hyperbolic embeddings module
22
+ export * from './hyperbolic.js';
23
+
24
+ // Re-export commonly used types for convenience
25
+ export type {
26
+ // Configuration
27
+ RuVectorConfig,
28
+ RuVectorClientOptions,
29
+ SSLConfig,
30
+ PoolConfig,
31
+ RetryConfig,
32
+
33
+ // Vector Operations
34
+ VectorSearchOptions,
35
+ VectorSearchResult,
36
+ VectorInsertOptions,
37
+ VectorUpdateOptions,
38
+ VectorIndexOptions,
39
+ BatchVectorOptions,
40
+ DistanceMetric,
41
+ VectorIndexType,
42
+
43
+ // Attention
44
+ AttentionMechanism,
45
+ AttentionConfig,
46
+ AttentionInput,
47
+ AttentionOutput,
48
+ AttentionParams,
49
+
50
+ // GNN
51
+ GNNLayerType,
52
+ GNNLayer,
53
+ GNNLayerParams,
54
+ GraphData,
55
+ GNNOutput,
56
+ GNNAggregation,
57
+
58
+ // Hyperbolic
59
+ HyperbolicModel,
60
+ HyperbolicEmbedding,
61
+ HyperbolicInput,
62
+ HyperbolicOutput,
63
+ HyperbolicOperation,
64
+
65
+ // Events
66
+ RuVectorEventType,
67
+ RuVectorEvent,
68
+ RuVectorEventHandler,
69
+ RuVectorEventEmitter,
70
+
71
+ // Results
72
+ Result,
73
+ AsyncResult,
74
+ ConnectionResult,
75
+ QueryResult,
76
+ BatchResult,
77
+ TransactionResult,
78
+ BulkSearchResult,
79
+ EmbeddingResult,
80
+
81
+ // Client Interface
82
+ IRuVectorClient,
83
+ IRuVectorTransaction,
84
+
85
+ // Utilities
86
+ RuVectorStats,
87
+ HealthStatus,
88
+ IndexStats,
89
+ } from './types.js';
90
+
91
+ // Export type guards
92
+ export {
93
+ isDistanceMetric,
94
+ isAttentionMechanism,
95
+ isGNNLayerType,
96
+ isHyperbolicModel,
97
+ isVectorIndexType,
98
+ isSuccess,
99
+ isError,
100
+ } from './types.js';
101
+
102
+ // Export namespace
103
+ export { RuVector } from './types.js';
104
+
105
+ // Export GNN module classes and utilities
106
+ export {
107
+ // Core classes
108
+ GNNLayerRegistry,
109
+ BaseGNNLayer,
110
+ GraphOperations,
111
+ GNNSQLGenerator,
112
+ GNNEmbeddingCache,
113
+
114
+ // Layer implementations
115
+ GCNLayer,
116
+ GATLayer,
117
+ GATv2Layer,
118
+ GraphSAGELayer,
119
+ GINLayer,
120
+ MPNNLayer,
121
+ EdgeConvLayer,
122
+ PointConvLayer,
123
+ GraphTransformerLayer,
124
+ PNALayer,
125
+ FiLMLayer,
126
+ RGCNLayer,
127
+ HGTLayer,
128
+ HANLayer,
129
+ MetaPathLayer,
130
+
131
+ // Factory functions
132
+ createGNNLayerRegistry,
133
+ createGNNLayer,
134
+ createGraphOperations,
135
+
136
+ // Constants
137
+ GNN_DEFAULTS,
138
+ GNN_SQL_FUNCTIONS,
139
+
140
+ // Types
141
+ type NodeId,
142
+ type NodeFeatures,
143
+ type EdgeFeatures,
144
+ type Message,
145
+ type AggregationMethod,
146
+ type Path,
147
+ type Community,
148
+ type PageRankOptions,
149
+ type CommunityOptions,
150
+ type GNNLayerConfig,
151
+ type GNNLayerFactory,
152
+ type IGNNLayer,
153
+ type SQLGenerationOptions,
154
+ } from './gnn.js';
155
+
156
+ // Export hyperbolic module classes and utilities
157
+ export {
158
+ // Core class
159
+ HyperbolicSpace,
160
+
161
+ // SQL generation
162
+ HyperbolicSQL,
163
+
164
+ // Batch processing
165
+ HyperbolicBatchProcessor,
166
+
167
+ // Use case implementations
168
+ HierarchyEmbedder,
169
+ ASTEmbedder,
170
+ DependencyGraphEmbedder,
171
+
172
+ // Factory functions
173
+ createHyperbolicSpace,
174
+ fromEmbeddingConfig,
175
+ validatePoint,
176
+
177
+ // Types
178
+ type HyperbolicSpaceConfig,
179
+ type HyperbolicDistanceResult,
180
+ type HyperbolicSearchResult,
181
+ type HyperbolicBatchOptions,
182
+ type HyperbolicBatchResult,
183
+ type ASTNode,
184
+ type TreeNode,
185
+ } from './hyperbolic.js';
186
+
187
+ // Export self-learning optimization module
188
+ export * from './self-learning.js';
189
+
190
+ // Export streaming and transaction module
191
+ export * from './streaming.js';
192
+
193
+ // Export streaming classes and utilities
194
+ export {
195
+ // Core streaming classes
196
+ RuVectorStream,
197
+ RuVectorTransaction,
198
+ BatchProcessor,
199
+ PoolEventEmitter,
200
+
201
+ // Factory functions
202
+ createRuVectorStream,
203
+ createRuVectorTransaction,
204
+ createBatchProcessor,
205
+ createPoolEventEmitter,
206
+
207
+ // Types
208
+ type StreamSearchOptions,
209
+ type InsertResult,
210
+ type VectorEntry,
211
+ type IsolationLevel,
212
+ type BatchOptions,
213
+ type PoolEvents,
214
+ type PoolClient,
215
+ } from './streaming.js';
216
+
217
+ // Export self-learning classes and utilities
218
+ export {
219
+ // Core classes
220
+ QueryOptimizer,
221
+ IndexTuner,
222
+ PatternRecognizer,
223
+ LearningLoop,
224
+
225
+ // Factory function
226
+ createSelfLearningSystem,
227
+
228
+ // Configuration presets
229
+ DEFAULT_LEARNING_CONFIG,
230
+ HIGH_PERF_LEARNING_CONFIG,
231
+ HIGH_ACCURACY_LEARNING_CONFIG,
232
+
233
+ // Types
234
+ type QueryAnalysis,
235
+ type QueryType,
236
+ type VectorOperation,
237
+ type IndexHint,
238
+ type Bottleneck,
239
+ type Optimization,
240
+ type OptimizationType,
241
+ type QueryExecutionStats,
242
+ type WorkloadAnalysis,
243
+ type QueryPattern,
244
+ type TableAccess,
245
+ type IndexUsageSummary,
246
+ type WorkloadCharacteristics,
247
+ type WorkloadRecommendation,
248
+ type IndexSuggestion,
249
+ type HNSWParams,
250
+ type QueryHistory,
251
+ type Pattern,
252
+ type PatternType,
253
+ type TemporalPattern,
254
+ type PerformancePattern,
255
+ type Context,
256
+ type Anomaly,
257
+ type AnomalyType,
258
+ type LearningConfig,
259
+ type LearningStats,
260
+ type EWCState,
261
+ } from './self-learning.js';
262
+
263
+ // ============================================================================
264
+ // Attention Module Exports
265
+ // ============================================================================
266
+
267
+ // Export attention module
268
+ export * from './attention.js';
269
+ export * from './attention-mechanisms.js';
270
+ export * from './attention-advanced.js';
271
+ export * from './attention-executor.js';
272
+
273
+ // Core attention exports
274
+ export {
275
+ AttentionRegistry,
276
+ BaseAttentionMechanism,
277
+ type IAttentionMechanism,
278
+ type AttentionOptions,
279
+ type AttentionCategory,
280
+ MultiHeadAttention,
281
+ SelfAttention,
282
+ CrossAttention,
283
+ CausalAttention,
284
+ BidirectionalAttention,
285
+ LocalAttention,
286
+ GlobalAttention,
287
+ FlashAttention,
288
+ FlashAttentionV2,
289
+ MemoryEfficientAttention,
290
+ ChunkAttention,
291
+ SlidingWindowAttention,
292
+ DilatedAttention,
293
+ } from './attention.js';
294
+
295
+ // Additional attention mechanisms
296
+ export {
297
+ SparseAttention,
298
+ BlockSparseAttention,
299
+ LinearAttention,
300
+ PerformerAttention,
301
+ LinformerAttention,
302
+ ReformerAttention,
303
+ RelativePositionAttention,
304
+ RotaryPositionAttention,
305
+ ALiBiAttention,
306
+ AxialAttention,
307
+ } from './attention-mechanisms.js';
308
+
309
+ // Advanced attention mechanisms
310
+ export {
311
+ GraphAttention,
312
+ HyperbolicAttention,
313
+ SphericalAttention,
314
+ ToroidalAttention,
315
+ TemporalAttention,
316
+ RecurrentAttention,
317
+ StateSpaceAttention,
318
+ CrossModalAttention,
319
+ PerceiverAttention,
320
+ FlamingoAttention,
321
+ RetrievalAttention,
322
+ KNNAttention,
323
+ MemoryAugmentedAttention,
324
+ SynthesizerAttention,
325
+ RoutingAttention,
326
+ MixtureOfExpertsAttention,
327
+ } from './attention-advanced.js';
328
+
329
+ // Executor and factory
330
+ export {
331
+ AttentionExecutor,
332
+ AttentionFactory,
333
+ AttentionStack,
334
+ AttentionSQLBuilder,
335
+ createDefaultRegistry,
336
+ type ExecutionOptions,
337
+ type ExecutionResult,
338
+ } from './attention-executor.js';
339
+
340
+ // ============================================================================
341
+ // Quantization Module Exports
342
+ // ============================================================================
343
+
344
+ // Export quantization module
345
+ export * from './quantization.js';
346
+
347
+ // Export migrations module
348
+ export * from './migrations/index.js';
349
+
350
+ // Migration classes and utilities
351
+ export {
352
+ MigrationManager,
353
+ createMigrationManager,
354
+ runMigrationsFromCLI,
355
+ MIGRATION_FILES,
356
+ type MigrationFile,
357
+ type AppliedMigration,
358
+ type MigrationResult,
359
+ type MigrationManagerOptions,
360
+ type DatabaseClient,
361
+ type MigrationName,
362
+ } from './migrations/index.js';
363
+
364
+ // Quantization classes and utilities
365
+ export {
366
+ // Core quantizer classes
367
+ ScalarQuantizer,
368
+ BinaryQuantizer,
369
+ ProductQuantizer,
370
+ OptimizedProductQuantizer,
371
+
372
+ // SQL integration
373
+ QuantizationSQL,
374
+
375
+ // Factory functions
376
+ createQuantizer,
377
+ computeQuantizationStats,
378
+ serializeQuantizer,
379
+ deserializeQuantizer,
380
+
381
+ // Configuration presets
382
+ QUANTIZATION_PRESETS,
383
+ MEMORY_REDUCTION,
384
+
385
+ // Types
386
+ type QuantizationType,
387
+ type IQuantizer,
388
+ type ScalarQuantizationOptions,
389
+ type BinaryQuantizationOptions,
390
+ type ProductQuantizationOptions,
391
+ type OptimizedProductQuantizationOptions,
392
+ type QuantizationOptions,
393
+ type QuantizationStats,
394
+ } from './quantization.js';
@@ -0,0 +1,135 @@
1
+ -- ============================================================================
2
+ -- Migration 001: Create Extensions and Schema
3
+ -- RuVector PostgreSQL Bridge - Claude Flow V3
4
+ --
5
+ -- Enables required PostgreSQL extensions and creates the claude_flow schema.
6
+ -- Compatible with PostgreSQL 14+ and pgvector 0.5+
7
+ -- ============================================================================
8
+
9
+ -- Transaction wrapper for atomicity
10
+ BEGIN;
11
+
12
+ -- ----------------------------------------------------------------------------
13
+ -- Extension: pgvector
14
+ -- Provides vector similarity search capabilities
15
+ -- ----------------------------------------------------------------------------
16
+ CREATE EXTENSION IF NOT EXISTS vector;
17
+
18
+ -- Verify pgvector version (0.5.0+ required for HNSW)
19
+ DO $$
20
+ DECLARE
21
+ v_version text;
22
+ BEGIN
23
+ SELECT extversion INTO v_version FROM pg_extension WHERE extname = 'vector';
24
+ IF v_version IS NULL THEN
25
+ RAISE EXCEPTION 'pgvector extension not installed';
26
+ END IF;
27
+
28
+ -- Parse version and check >= 0.5.0
29
+ IF string_to_array(v_version, '.')::int[] < ARRAY[0, 5, 0] THEN
30
+ RAISE WARNING 'pgvector version % detected. Version 0.5.0+ recommended for HNSW support.', v_version;
31
+ END IF;
32
+ END $$;
33
+
34
+ -- ----------------------------------------------------------------------------
35
+ -- Extension: pg_trgm (for fuzzy text search on metadata)
36
+ -- ----------------------------------------------------------------------------
37
+ CREATE EXTENSION IF NOT EXISTS pg_trgm;
38
+
39
+ -- ----------------------------------------------------------------------------
40
+ -- Extension: btree_gin (for composite GIN indexes)
41
+ -- ----------------------------------------------------------------------------
42
+ CREATE EXTENSION IF NOT EXISTS btree_gin;
43
+
44
+ -- ----------------------------------------------------------------------------
45
+ -- Extension: uuid-ossp (for UUID generation)
46
+ -- ----------------------------------------------------------------------------
47
+ CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
48
+
49
+ -- ----------------------------------------------------------------------------
50
+ -- RuVector Extension (if available)
51
+ -- Provides advanced neural search capabilities
52
+ -- ----------------------------------------------------------------------------
53
+ DO $$
54
+ BEGIN
55
+ -- Try to create RuVector extension if available
56
+ BEGIN
57
+ CREATE EXTENSION IF NOT EXISTS ruvector;
58
+ RAISE NOTICE 'RuVector extension enabled successfully';
59
+ EXCEPTION
60
+ WHEN undefined_file THEN
61
+ RAISE NOTICE 'RuVector extension not available - using pgvector only';
62
+ WHEN OTHERS THEN
63
+ RAISE NOTICE 'RuVector extension not available: %', SQLERRM;
64
+ END;
65
+ END $$;
66
+
67
+ -- ----------------------------------------------------------------------------
68
+ -- Schema: claude_flow
69
+ -- Namespace for all Claude Flow tables and functions
70
+ -- ----------------------------------------------------------------------------
71
+ CREATE SCHEMA IF NOT EXISTS claude_flow;
72
+
73
+ -- Set search path to include claude_flow schema
74
+ COMMENT ON SCHEMA claude_flow IS 'Claude Flow V3 - RuVector PostgreSQL Bridge schema';
75
+
76
+ -- Grant usage on schema
77
+ DO $$
78
+ BEGIN
79
+ -- Grant to PUBLIC for general access (modify as needed for security)
80
+ GRANT USAGE ON SCHEMA claude_flow TO PUBLIC;
81
+ GRANT CREATE ON SCHEMA claude_flow TO PUBLIC;
82
+ END $$;
83
+
84
+ -- ----------------------------------------------------------------------------
85
+ -- Configuration table for RuVector settings
86
+ -- ----------------------------------------------------------------------------
87
+ CREATE TABLE IF NOT EXISTS claude_flow.config (
88
+ key TEXT PRIMARY KEY,
89
+ value JSONB NOT NULL,
90
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
91
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
92
+ );
93
+
94
+ -- Insert default configuration
95
+ INSERT INTO claude_flow.config (key, value) VALUES
96
+ ('version', '"1.0.0"'),
97
+ ('default_dimensions', '1536'),
98
+ ('default_metric', '"cosine"'),
99
+ ('hnsw_m', '16'),
100
+ ('hnsw_ef_construction', '64'),
101
+ ('ivfflat_lists', '100')
102
+ ON CONFLICT (key) DO NOTHING;
103
+
104
+ -- ----------------------------------------------------------------------------
105
+ -- Migration tracking table
106
+ -- ----------------------------------------------------------------------------
107
+ CREATE TABLE IF NOT EXISTS claude_flow.migrations (
108
+ id SERIAL PRIMARY KEY,
109
+ name TEXT NOT NULL UNIQUE,
110
+ applied_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
111
+ checksum TEXT,
112
+ execution_time_ms INTEGER,
113
+ rolled_back_at TIMESTAMPTZ
114
+ );
115
+
116
+ -- Record this migration
117
+ INSERT INTO claude_flow.migrations (name, checksum)
118
+ VALUES ('001_create_extension', md5('001_create_extension'))
119
+ ON CONFLICT (name) DO NOTHING;
120
+
121
+ COMMIT;
122
+
123
+ -- ============================================================================
124
+ -- Rollback Script (run separately if needed)
125
+ -- ============================================================================
126
+ -- BEGIN;
127
+ -- DROP TABLE IF EXISTS claude_flow.migrations;
128
+ -- DROP TABLE IF EXISTS claude_flow.config;
129
+ -- DROP SCHEMA IF EXISTS claude_flow CASCADE;
130
+ -- DROP EXTENSION IF EXISTS ruvector;
131
+ -- DROP EXTENSION IF EXISTS "uuid-ossp";
132
+ -- DROP EXTENSION IF EXISTS btree_gin;
133
+ -- DROP EXTENSION IF EXISTS pg_trgm;
134
+ -- DROP EXTENSION IF EXISTS vector;
135
+ -- COMMIT;