@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,563 @@
1
+ /**
2
+ * Plugin SDK - Unified API for Claude Flow Plugin Development
3
+ *
4
+ * Provides a comprehensive SDK for building plugins with full access to:
5
+ * - Plugin lifecycle management
6
+ * - Worker capabilities
7
+ * - Hook system
8
+ * - Memory backends (AgentDB integration)
9
+ * - LLM providers
10
+ * - MCP tools
11
+ */
12
+
13
+ import {
14
+ HookEvent,
15
+ HookPriority,
16
+ type PluginMetadata,
17
+ type PluginContext,
18
+ type PluginConfig,
19
+ type ILogger,
20
+ type IEventBus,
21
+ type ServiceContainer,
22
+ type AgentTypeDefinition,
23
+ type TaskTypeDefinition,
24
+ type MCPToolDefinition,
25
+ type CLICommandDefinition,
26
+ type MemoryBackendFactory,
27
+ type HookDefinition,
28
+ type HookHandler,
29
+ type WorkerDefinition,
30
+ type WorkerType,
31
+ type LLMProviderDefinition,
32
+ type HealthCheckResult,
33
+ type JSONSchema,
34
+ } from '../types/index.js';
35
+ import { BasePlugin, createSimplePlugin } from '../core/base-plugin.js';
36
+ import type { IPlugin, PluginFactory } from '../core/plugin-interface.js';
37
+ import { validatePlugin, validatePluginMetadata, PLUGIN_EVENTS } from '../core/plugin-interface.js';
38
+ import { PluginRegistry, getDefaultRegistry, setDefaultRegistry } from '../registry/plugin-registry.js';
39
+
40
+ // ============================================================================
41
+ // SDK Builder Pattern
42
+ // ============================================================================
43
+
44
+ /**
45
+ * Plugin builder for fluent plugin creation.
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const myPlugin = new PluginBuilder('my-plugin', '1.0.0')
50
+ * .withDescription('My awesome plugin')
51
+ * .withMCPTools([{
52
+ * name: 'my-tool',
53
+ * description: 'Does something useful',
54
+ * inputSchema: { type: 'object', properties: {} },
55
+ * handler: async (input) => ({ content: [{ type: 'text', text: 'Done!' }] })
56
+ * }])
57
+ * .withHooks([{
58
+ * event: HookEvent.PostTaskComplete,
59
+ * handler: async (ctx) => ({ success: true })
60
+ * }])
61
+ * .onInitialize(async (ctx) => {
62
+ * console.log('Plugin initialized!');
63
+ * })
64
+ * .build();
65
+ * ```
66
+ */
67
+ export class PluginBuilder {
68
+ private metadata: PluginMetadata;
69
+ private agentTypes: AgentTypeDefinition[] = [];
70
+ private taskTypes: TaskTypeDefinition[] = [];
71
+ private mcpTools: MCPToolDefinition[] = [];
72
+ private cliCommands: CLICommandDefinition[] = [];
73
+ private hooks: HookDefinition[] = [];
74
+ private workers: WorkerDefinition[] = [];
75
+ private providers: LLMProviderDefinition[] = [];
76
+ private initHandler?: (context: PluginContext) => Promise<void>;
77
+ private shutdownHandler?: () => Promise<void>;
78
+
79
+ constructor(name: string, version: string) {
80
+ this.metadata = { name, version };
81
+ }
82
+
83
+ // =========================================================================
84
+ // Metadata Configuration
85
+ // =========================================================================
86
+
87
+ withDescription(description: string): this {
88
+ this.metadata = { ...this.metadata, description };
89
+ return this;
90
+ }
91
+
92
+ withAuthor(author: string): this {
93
+ this.metadata = { ...this.metadata, author };
94
+ return this;
95
+ }
96
+
97
+ withLicense(license: string): this {
98
+ this.metadata = { ...this.metadata, license };
99
+ return this;
100
+ }
101
+
102
+ withRepository(repository: string): this {
103
+ this.metadata = { ...this.metadata, repository };
104
+ return this;
105
+ }
106
+
107
+ withDependencies(dependencies: string[]): this {
108
+ this.metadata = { ...this.metadata, dependencies };
109
+ return this;
110
+ }
111
+
112
+ withTags(tags: string[]): this {
113
+ this.metadata = { ...this.metadata, tags };
114
+ return this;
115
+ }
116
+
117
+ withMinCoreVersion(minCoreVersion: string): this {
118
+ this.metadata = { ...this.metadata, minCoreVersion };
119
+ return this;
120
+ }
121
+
122
+ // =========================================================================
123
+ // Extension Points
124
+ // =========================================================================
125
+
126
+ withAgentTypes(types: AgentTypeDefinition[]): this {
127
+ this.agentTypes.push(...types);
128
+ return this;
129
+ }
130
+
131
+ withTaskTypes(types: TaskTypeDefinition[]): this {
132
+ this.taskTypes.push(...types);
133
+ return this;
134
+ }
135
+
136
+ withMCPTools(tools: MCPToolDefinition[]): this {
137
+ this.mcpTools.push(...tools);
138
+ return this;
139
+ }
140
+
141
+ withCLICommands(commands: CLICommandDefinition[]): this {
142
+ this.cliCommands.push(...commands);
143
+ return this;
144
+ }
145
+
146
+ withHooks(hooks: HookDefinition[]): this {
147
+ this.hooks.push(...hooks);
148
+ return this;
149
+ }
150
+
151
+ withWorkers(workers: WorkerDefinition[]): this {
152
+ this.workers.push(...workers);
153
+ return this;
154
+ }
155
+
156
+ withProviders(providers: LLMProviderDefinition[]): this {
157
+ this.providers.push(...providers);
158
+ return this;
159
+ }
160
+
161
+ // =========================================================================
162
+ // Lifecycle Handlers
163
+ // =========================================================================
164
+
165
+ onInitialize(handler: (context: PluginContext) => Promise<void>): this {
166
+ this.initHandler = handler;
167
+ return this;
168
+ }
169
+
170
+ onShutdown(handler: () => Promise<void>): this {
171
+ this.shutdownHandler = handler;
172
+ return this;
173
+ }
174
+
175
+ // =========================================================================
176
+ // Build
177
+ // =========================================================================
178
+
179
+ build(): IPlugin {
180
+ return createSimplePlugin({
181
+ metadata: this.metadata,
182
+ onInitialize: this.initHandler,
183
+ onShutdown: this.shutdownHandler,
184
+ agentTypes: this.agentTypes.length > 0 ? this.agentTypes : undefined,
185
+ taskTypes: this.taskTypes.length > 0 ? this.taskTypes : undefined,
186
+ mcpTools: this.mcpTools.length > 0 ? this.mcpTools : undefined,
187
+ cliCommands: this.cliCommands.length > 0 ? this.cliCommands : undefined,
188
+ hooks: this.hooks.length > 0 ? this.hooks : undefined,
189
+ workers: this.workers.length > 0 ? this.workers : undefined,
190
+ providers: this.providers.length > 0 ? this.providers : undefined,
191
+ });
192
+ }
193
+
194
+ /**
195
+ * Build and automatically register with the default registry.
196
+ */
197
+ async buildAndRegister(config?: Partial<PluginConfig>): Promise<IPlugin> {
198
+ const plugin = this.build();
199
+ await getDefaultRegistry().register(plugin, config);
200
+ return plugin;
201
+ }
202
+ }
203
+
204
+ // ============================================================================
205
+ // Quick Plugin Creation Helpers
206
+ // ============================================================================
207
+
208
+ /**
209
+ * Create a tool-only plugin quickly.
210
+ */
211
+ export function createToolPlugin(
212
+ name: string,
213
+ version: string,
214
+ tools: MCPToolDefinition[]
215
+ ): IPlugin {
216
+ return new PluginBuilder(name, version)
217
+ .withMCPTools(tools)
218
+ .build();
219
+ }
220
+
221
+ /**
222
+ * Create a hooks-only plugin quickly.
223
+ */
224
+ export function createHooksPlugin(
225
+ name: string,
226
+ version: string,
227
+ hooks: HookDefinition[]
228
+ ): IPlugin {
229
+ return new PluginBuilder(name, version)
230
+ .withHooks(hooks)
231
+ .build();
232
+ }
233
+
234
+ /**
235
+ * Create a worker plugin quickly.
236
+ */
237
+ export function createWorkerPlugin(
238
+ name: string,
239
+ version: string,
240
+ workers: WorkerDefinition[]
241
+ ): IPlugin {
242
+ return new PluginBuilder(name, version)
243
+ .withWorkers(workers)
244
+ .build();
245
+ }
246
+
247
+ /**
248
+ * Create a provider plugin quickly.
249
+ */
250
+ export function createProviderPlugin(
251
+ name: string,
252
+ version: string,
253
+ providers: LLMProviderDefinition[]
254
+ ): IPlugin {
255
+ return new PluginBuilder(name, version)
256
+ .withProviders(providers)
257
+ .build();
258
+ }
259
+
260
+ // ============================================================================
261
+ // Tool Builder
262
+ // ============================================================================
263
+
264
+ /**
265
+ * Builder for creating MCP tools with validation.
266
+ */
267
+ export class MCPToolBuilder {
268
+ private name: string;
269
+ private description: string = '';
270
+ private properties: Record<string, JSONSchema> = {};
271
+ private required: string[] = [];
272
+ private handler?: MCPToolDefinition['handler'];
273
+
274
+ constructor(name: string) {
275
+ this.name = name;
276
+ }
277
+
278
+ withDescription(description: string): this {
279
+ this.description = description;
280
+ return this;
281
+ }
282
+
283
+ addStringParam(
284
+ name: string,
285
+ description: string,
286
+ options?: { required?: boolean; default?: string; enum?: string[] }
287
+ ): this {
288
+ this.properties[name] = {
289
+ type: 'string',
290
+ description,
291
+ default: options?.default,
292
+ enum: options?.enum,
293
+ };
294
+ if (options?.required) {
295
+ this.required.push(name);
296
+ }
297
+ return this;
298
+ }
299
+
300
+ addNumberParam(
301
+ name: string,
302
+ description: string,
303
+ options?: { required?: boolean; default?: number; minimum?: number; maximum?: number }
304
+ ): this {
305
+ this.properties[name] = {
306
+ type: 'number',
307
+ description,
308
+ default: options?.default,
309
+ minimum: options?.minimum,
310
+ maximum: options?.maximum,
311
+ };
312
+ if (options?.required) {
313
+ this.required.push(name);
314
+ }
315
+ return this;
316
+ }
317
+
318
+ addBooleanParam(
319
+ name: string,
320
+ description: string,
321
+ options?: { required?: boolean; default?: boolean }
322
+ ): this {
323
+ this.properties[name] = {
324
+ type: 'boolean',
325
+ description,
326
+ default: options?.default,
327
+ };
328
+ if (options?.required) {
329
+ this.required.push(name);
330
+ }
331
+ return this;
332
+ }
333
+
334
+ addObjectParam(
335
+ name: string,
336
+ description: string,
337
+ schema: JSONSchema,
338
+ options?: { required?: boolean }
339
+ ): this {
340
+ this.properties[name] = {
341
+ ...schema,
342
+ description,
343
+ };
344
+ if (options?.required) {
345
+ this.required.push(name);
346
+ }
347
+ return this;
348
+ }
349
+
350
+ addArrayParam(
351
+ name: string,
352
+ description: string,
353
+ itemsSchema: JSONSchema,
354
+ options?: { required?: boolean }
355
+ ): this {
356
+ this.properties[name] = {
357
+ type: 'array',
358
+ description,
359
+ items: itemsSchema,
360
+ };
361
+ if (options?.required) {
362
+ this.required.push(name);
363
+ }
364
+ return this;
365
+ }
366
+
367
+ withHandler(handler: MCPToolDefinition['handler']): this {
368
+ this.handler = handler;
369
+ return this;
370
+ }
371
+
372
+ build(): MCPToolDefinition {
373
+ if (!this.handler) {
374
+ throw new Error(`Tool ${this.name} requires a handler`);
375
+ }
376
+
377
+ return {
378
+ name: this.name,
379
+ description: this.description,
380
+ inputSchema: {
381
+ type: 'object',
382
+ properties: this.properties,
383
+ required: this.required.length > 0 ? this.required : undefined,
384
+ },
385
+ handler: this.handler,
386
+ };
387
+ }
388
+ }
389
+
390
+ // ============================================================================
391
+ // Hook Builder
392
+ // ============================================================================
393
+
394
+ /**
395
+ * Builder for creating hooks with validation.
396
+ */
397
+ export class HookBuilder {
398
+ private event: HookEvent;
399
+ private name?: string;
400
+ private description?: string;
401
+ private priority: HookPriority = HookPriority.Normal;
402
+ private async: boolean = true;
403
+ private handler?: HookHandler;
404
+
405
+ constructor(event: HookEvent) {
406
+ this.event = event;
407
+ }
408
+
409
+ withName(name: string): this {
410
+ this.name = name;
411
+ return this;
412
+ }
413
+
414
+ withDescription(description: string): this {
415
+ this.description = description;
416
+ return this;
417
+ }
418
+
419
+ withPriority(priority: HookPriority): this {
420
+ this.priority = priority;
421
+ return this;
422
+ }
423
+
424
+ synchronous(): this {
425
+ this.async = false;
426
+ return this;
427
+ }
428
+
429
+ withHandler(handler: HookHandler): this {
430
+ this.handler = handler;
431
+ return this;
432
+ }
433
+
434
+ build(): HookDefinition {
435
+ if (!this.handler) {
436
+ throw new Error(`Hook for event ${this.event} requires a handler`);
437
+ }
438
+
439
+ return {
440
+ event: this.event,
441
+ handler: this.handler,
442
+ priority: this.priority,
443
+ name: this.name,
444
+ description: this.description,
445
+ async: this.async,
446
+ };
447
+ }
448
+ }
449
+
450
+ // ============================================================================
451
+ // Worker Builder
452
+ // ============================================================================
453
+
454
+ /**
455
+ * Builder for creating workers with validation.
456
+ */
457
+ export class WorkerBuilder {
458
+ private type: WorkerType;
459
+ private name: string;
460
+ private description?: string;
461
+ private capabilities: string[] = [];
462
+ private specialization?: Float32Array;
463
+ private maxConcurrentTasks: number = 5;
464
+ private timeout: number = 30000;
465
+ private priority: number = 50;
466
+ private metadata: Record<string, unknown> = {};
467
+
468
+ constructor(type: WorkerType, name: string) {
469
+ this.type = type;
470
+ this.name = name;
471
+ }
472
+
473
+ withDescription(description: string): this {
474
+ this.description = description;
475
+ return this;
476
+ }
477
+
478
+ withCapabilities(capabilities: string[]): this {
479
+ this.capabilities.push(...capabilities);
480
+ return this;
481
+ }
482
+
483
+ withSpecialization(vector: Float32Array): this {
484
+ this.specialization = vector;
485
+ return this;
486
+ }
487
+
488
+ withMaxConcurrentTasks(max: number): this {
489
+ this.maxConcurrentTasks = max;
490
+ return this;
491
+ }
492
+
493
+ withTimeout(timeout: number): this {
494
+ this.timeout = timeout;
495
+ return this;
496
+ }
497
+
498
+ withPriority(priority: number): this {
499
+ this.priority = priority;
500
+ return this;
501
+ }
502
+
503
+ withMetadata(metadata: Record<string, unknown>): this {
504
+ this.metadata = { ...this.metadata, ...metadata };
505
+ return this;
506
+ }
507
+
508
+ build(): WorkerDefinition {
509
+ return {
510
+ type: this.type,
511
+ name: this.name,
512
+ description: this.description,
513
+ capabilities: this.capabilities,
514
+ specialization: this.specialization,
515
+ maxConcurrentTasks: this.maxConcurrentTasks,
516
+ timeout: this.timeout,
517
+ priority: this.priority,
518
+ metadata: Object.keys(this.metadata).length > 0 ? this.metadata : undefined,
519
+ };
520
+ }
521
+ }
522
+
523
+ // ============================================================================
524
+ // Exports
525
+ // ============================================================================
526
+
527
+ // Re-export core types and interfaces
528
+ export {
529
+ // Types
530
+ type PluginMetadata,
531
+ type PluginContext,
532
+ type PluginConfig,
533
+ type ILogger,
534
+ type IEventBus,
535
+ type ServiceContainer,
536
+ type AgentTypeDefinition,
537
+ type TaskTypeDefinition,
538
+ type MCPToolDefinition,
539
+ type CLICommandDefinition,
540
+ type MemoryBackendFactory,
541
+ type HookDefinition,
542
+ type HookHandler,
543
+ type WorkerDefinition,
544
+ type LLMProviderDefinition,
545
+ type HealthCheckResult,
546
+ type JSONSchema,
547
+ HookEvent,
548
+ HookPriority,
549
+ type WorkerType,
550
+ // Plugin interface
551
+ type IPlugin,
552
+ type PluginFactory,
553
+ validatePlugin,
554
+ validatePluginMetadata,
555
+ PLUGIN_EVENTS,
556
+ // Base plugin
557
+ BasePlugin,
558
+ createSimplePlugin,
559
+ // Registry
560
+ PluginRegistry,
561
+ getDefaultRegistry,
562
+ setDefaultRegistry,
563
+ };