@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,446 @@
1
+ /**
2
+ * @sparkleideas/plugins - Core Type Definitions
3
+ *
4
+ * Unified type system for plugins, workers, hooks, and providers.
5
+ */
6
+
7
+ // ============================================================================
8
+ // Plugin Lifecycle
9
+ // ============================================================================
10
+
11
+ export type PluginLifecycleState =
12
+ | 'uninitialized'
13
+ | 'initializing'
14
+ | 'initialized'
15
+ | 'shutting-down'
16
+ | 'shutdown'
17
+ | 'error';
18
+
19
+ export interface PluginMetadata {
20
+ readonly name: string;
21
+ readonly version: string;
22
+ readonly description?: string;
23
+ readonly author?: string;
24
+ readonly license?: string;
25
+ readonly repository?: string;
26
+ readonly dependencies?: string[];
27
+ readonly peerDependencies?: Record<string, string>;
28
+ readonly minCoreVersion?: string;
29
+ readonly maxCoreVersion?: string;
30
+ readonly tags?: string[];
31
+ }
32
+
33
+ // ============================================================================
34
+ // Plugin Context & Configuration
35
+ // ============================================================================
36
+
37
+ export interface PluginConfig {
38
+ readonly enabled: boolean;
39
+ readonly priority: number;
40
+ readonly settings: Record<string, unknown>;
41
+ readonly sandbox?: boolean;
42
+ readonly timeout?: number;
43
+ readonly maxMemoryMb?: number;
44
+ }
45
+
46
+ export interface PluginContext {
47
+ readonly config: PluginConfig;
48
+ readonly eventBus: IEventBus;
49
+ readonly logger: ILogger;
50
+ readonly services: ServiceContainer;
51
+ readonly coreVersion: string;
52
+ readonly dataDir: string;
53
+ }
54
+
55
+ export interface ServiceContainer {
56
+ get<T>(key: string): T | undefined;
57
+ set<T>(key: string, value: T): void;
58
+ has(key: string): boolean;
59
+ delete(key: string): boolean;
60
+ }
61
+
62
+ // ============================================================================
63
+ // Event System
64
+ // ============================================================================
65
+
66
+ export interface IEventBus {
67
+ emit(event: string, data?: unknown): void;
68
+ on(event: string, handler: EventHandler): () => void;
69
+ off(event: string, handler: EventHandler): void;
70
+ once(event: string, handler: EventHandler): () => void;
71
+ }
72
+
73
+ export type EventHandler = (data?: unknown) => void | Promise<void>;
74
+
75
+ // ============================================================================
76
+ // Logging
77
+ // ============================================================================
78
+
79
+ export interface ILogger {
80
+ debug(message: string, ...args: unknown[]): void;
81
+ info(message: string, ...args: unknown[]): void;
82
+ warn(message: string, ...args: unknown[]): void;
83
+ error(message: string, ...args: unknown[]): void;
84
+ child(context: Record<string, unknown>): ILogger;
85
+ }
86
+
87
+ // ============================================================================
88
+ // Extension Points
89
+ // ============================================================================
90
+
91
+ export interface AgentTypeDefinition {
92
+ readonly type: string;
93
+ readonly name: string;
94
+ readonly description?: string;
95
+ readonly capabilities: string[];
96
+ readonly systemPrompt?: string;
97
+ readonly model?: string;
98
+ readonly temperature?: number;
99
+ readonly maxTokens?: number;
100
+ readonly tools?: string[];
101
+ readonly metadata?: Record<string, unknown>;
102
+ }
103
+
104
+ export interface TaskTypeDefinition {
105
+ readonly type: string;
106
+ readonly name: string;
107
+ readonly description?: string;
108
+ readonly inputSchema: JSONSchema;
109
+ readonly outputSchema?: JSONSchema;
110
+ readonly handler?: string;
111
+ readonly timeout?: number;
112
+ readonly retries?: number;
113
+ readonly metadata?: Record<string, unknown>;
114
+ }
115
+
116
+ export interface MCPToolDefinition {
117
+ readonly name: string;
118
+ readonly description: string;
119
+ readonly inputSchema: {
120
+ type: 'object';
121
+ properties: Record<string, unknown>;
122
+ required?: string[];
123
+ };
124
+ readonly handler: (input: Record<string, unknown>) => Promise<MCPToolResult>;
125
+ }
126
+
127
+ export interface MCPToolResult {
128
+ content: Array<{ type: 'text'; text: string }>;
129
+ isError?: boolean;
130
+ }
131
+
132
+ export interface CLICommandDefinition {
133
+ readonly name: string;
134
+ readonly description: string;
135
+ readonly aliases?: string[];
136
+ readonly args?: CLIArgumentDefinition[];
137
+ readonly options?: CLIOptionDefinition[];
138
+ readonly handler: (args: Record<string, unknown>) => Promise<number>;
139
+ }
140
+
141
+ export interface CLIArgumentDefinition {
142
+ readonly name: string;
143
+ readonly description?: string;
144
+ readonly required?: boolean;
145
+ readonly default?: unknown;
146
+ }
147
+
148
+ export interface CLIOptionDefinition {
149
+ readonly name: string;
150
+ readonly short?: string;
151
+ readonly description?: string;
152
+ readonly type: 'string' | 'number' | 'boolean';
153
+ readonly required?: boolean;
154
+ readonly default?: unknown;
155
+ }
156
+
157
+ export interface MemoryBackendFactory {
158
+ readonly name: string;
159
+ readonly description?: string;
160
+ readonly create: (config: Record<string, unknown>) => Promise<IMemoryBackend>;
161
+ }
162
+
163
+ export interface IMemoryBackend {
164
+ initialize(): Promise<void>;
165
+ shutdown(): Promise<void>;
166
+ store(key: string, value: unknown, metadata?: Record<string, unknown>): Promise<void>;
167
+ retrieve(key: string): Promise<unknown | null>;
168
+ delete(key: string): Promise<boolean>;
169
+ search(query: string, options?: MemorySearchOptions): Promise<MemorySearchResult[]>;
170
+ clear(): Promise<void>;
171
+ getStats(): Promise<MemoryBackendStats>;
172
+ }
173
+
174
+ export interface MemorySearchOptions {
175
+ limit?: number;
176
+ threshold?: number;
177
+ filters?: Record<string, unknown>;
178
+ }
179
+
180
+ export interface MemorySearchResult {
181
+ key: string;
182
+ value: unknown;
183
+ score: number;
184
+ metadata?: Record<string, unknown>;
185
+ }
186
+
187
+ export interface MemoryBackendStats {
188
+ entries: number;
189
+ sizeBytes: number;
190
+ lastAccess: Date;
191
+ }
192
+
193
+ // ============================================================================
194
+ // Worker Types
195
+ // ============================================================================
196
+
197
+ export type WorkerType =
198
+ | 'coder'
199
+ | 'reviewer'
200
+ | 'tester'
201
+ | 'researcher'
202
+ | 'planner'
203
+ | 'architect'
204
+ | 'coordinator'
205
+ | 'security'
206
+ | 'performance'
207
+ | 'specialized'
208
+ | 'long-running'
209
+ | 'generic';
210
+
211
+ export interface WorkerDefinition {
212
+ readonly type: WorkerType;
213
+ readonly name: string;
214
+ readonly description?: string;
215
+ readonly capabilities: string[];
216
+ readonly specialization?: Float32Array;
217
+ readonly maxConcurrentTasks?: number;
218
+ readonly timeout?: number;
219
+ readonly priority?: number;
220
+ readonly metadata?: Record<string, unknown>;
221
+ }
222
+
223
+ export interface WorkerResult {
224
+ readonly workerId: string;
225
+ readonly success: boolean;
226
+ readonly output?: unknown;
227
+ readonly error?: string;
228
+ readonly duration: number;
229
+ readonly tokensUsed?: number;
230
+ readonly metadata?: Record<string, unknown>;
231
+ }
232
+
233
+ export interface WorkerMetrics {
234
+ tasksExecuted: number;
235
+ tasksSucceeded: number;
236
+ tasksFailed: number;
237
+ avgDuration: number;
238
+ totalTokensUsed: number;
239
+ currentLoad: number;
240
+ uptime: number;
241
+ lastActivity: number;
242
+ healthScore: number;
243
+ }
244
+
245
+ export interface WorkerHealth {
246
+ status: 'healthy' | 'degraded' | 'unhealthy';
247
+ score: number;
248
+ issues: string[];
249
+ resources: {
250
+ memoryMb: number;
251
+ cpuPercent: number;
252
+ };
253
+ }
254
+
255
+ // ============================================================================
256
+ // Hook Types
257
+ // ============================================================================
258
+
259
+ export enum HookEvent {
260
+ // Tool lifecycle
261
+ PreToolUse = 'hook:pre-tool-use',
262
+ PostToolUse = 'hook:post-tool-use',
263
+
264
+ // Session lifecycle
265
+ SessionStart = 'hook:session-start',
266
+ SessionEnd = 'hook:session-end',
267
+ SessionRestore = 'hook:session-restore',
268
+
269
+ // Task execution
270
+ PreTaskExecute = 'hook:pre-task-execute',
271
+ PostTaskComplete = 'hook:post-task-complete',
272
+ TaskFailed = 'hook:task-failed',
273
+
274
+ // File operations
275
+ PreFileWrite = 'hook:pre-file-write',
276
+ PostFileWrite = 'hook:post-file-write',
277
+ PreFileDelete = 'hook:pre-file-delete',
278
+
279
+ // Command execution
280
+ PreCommand = 'hook:pre-command',
281
+ PostCommand = 'hook:post-command',
282
+
283
+ // Agent operations
284
+ AgentSpawned = 'hook:agent-spawned',
285
+ AgentTerminated = 'hook:agent-terminated',
286
+
287
+ // Memory operations
288
+ PreMemoryStore = 'hook:pre-memory-store',
289
+ PostMemoryStore = 'hook:post-memory-store',
290
+
291
+ // Learning
292
+ PatternDetected = 'hook:pattern-detected',
293
+ StrategyUpdated = 'hook:strategy-updated',
294
+
295
+ // Plugin lifecycle
296
+ PluginLoaded = 'hook:plugin-loaded',
297
+ PluginUnloaded = 'hook:plugin-unloaded',
298
+ }
299
+
300
+ export enum HookPriority {
301
+ Critical = 100,
302
+ High = 75,
303
+ Normal = 50,
304
+ Low = 25,
305
+ Deferred = 0,
306
+ }
307
+
308
+ export interface HookDefinition {
309
+ readonly event: HookEvent;
310
+ readonly handler: HookHandler;
311
+ readonly priority?: HookPriority;
312
+ readonly name?: string;
313
+ readonly description?: string;
314
+ readonly async?: boolean;
315
+ }
316
+
317
+ export type HookHandler = (context: HookContext) => HookResult | Promise<HookResult>;
318
+
319
+ export interface HookContext {
320
+ readonly event: HookEvent;
321
+ readonly data: unknown;
322
+ readonly timestamp: Date;
323
+ readonly source?: string;
324
+ readonly metadata?: Record<string, unknown>;
325
+ }
326
+
327
+ export interface HookResult {
328
+ readonly success: boolean;
329
+ readonly data?: unknown;
330
+ readonly error?: string;
331
+ readonly modified?: boolean;
332
+ readonly abort?: boolean;
333
+ }
334
+
335
+ // ============================================================================
336
+ // Provider Types
337
+ // ============================================================================
338
+
339
+ export interface LLMProviderDefinition {
340
+ readonly name: string;
341
+ readonly displayName: string;
342
+ readonly models: string[];
343
+ readonly capabilities: LLMCapability[];
344
+ readonly rateLimit?: RateLimitConfig;
345
+ readonly costPerToken?: CostConfig;
346
+ }
347
+
348
+ export type LLMCapability =
349
+ | 'completion'
350
+ | 'chat'
351
+ | 'streaming'
352
+ | 'function-calling'
353
+ | 'vision'
354
+ | 'embeddings'
355
+ | 'code-generation';
356
+
357
+ export interface RateLimitConfig {
358
+ requestsPerMinute: number;
359
+ tokensPerMinute: number;
360
+ tokensPerDay?: number;
361
+ }
362
+
363
+ export interface CostConfig {
364
+ input: number;
365
+ output: number;
366
+ currency: string;
367
+ }
368
+
369
+ export interface LLMRequest {
370
+ model: string;
371
+ messages: LLMMessage[];
372
+ temperature?: number;
373
+ maxTokens?: number;
374
+ stop?: string[];
375
+ tools?: LLMTool[];
376
+ stream?: boolean;
377
+ }
378
+
379
+ export interface LLMMessage {
380
+ role: 'system' | 'user' | 'assistant' | 'tool';
381
+ content: string;
382
+ name?: string;
383
+ toolCallId?: string;
384
+ }
385
+
386
+ export interface LLMTool {
387
+ name: string;
388
+ description: string;
389
+ parameters: JSONSchema;
390
+ }
391
+
392
+ export interface LLMResponse {
393
+ id: string;
394
+ model: string;
395
+ content: string;
396
+ usage: {
397
+ promptTokens: number;
398
+ completionTokens: number;
399
+ totalTokens: number;
400
+ };
401
+ finishReason: string;
402
+ toolCalls?: LLMToolCall[];
403
+ }
404
+
405
+ export interface LLMToolCall {
406
+ id: string;
407
+ name: string;
408
+ arguments: string;
409
+ }
410
+
411
+ // ============================================================================
412
+ // JSON Schema
413
+ // ============================================================================
414
+
415
+ export interface JSONSchema {
416
+ type?: string;
417
+ properties?: Record<string, JSONSchema>;
418
+ required?: string[];
419
+ items?: JSONSchema;
420
+ enum?: unknown[];
421
+ description?: string;
422
+ default?: unknown;
423
+ minimum?: number;
424
+ maximum?: number;
425
+ minLength?: number;
426
+ maxLength?: number;
427
+ pattern?: string;
428
+ format?: string;
429
+ additionalProperties?: boolean | JSONSchema;
430
+ }
431
+
432
+ // ============================================================================
433
+ // Health Check
434
+ // ============================================================================
435
+
436
+ export interface HealthCheckResult {
437
+ healthy: boolean;
438
+ status: 'healthy' | 'degraded' | 'unhealthy';
439
+ message?: string;
440
+ checks: Record<string, {
441
+ healthy: boolean;
442
+ message?: string;
443
+ latencyMs?: number;
444
+ }>;
445
+ timestamp: Date;
446
+ }