@majkapp/plugin-kit 3.5.3 → 3.5.5

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/docs/FULL.md CHANGED
@@ -10,11 +10,13 @@ Comprehensive reference for @majkapp/plugin-kit covering all features and patter
10
10
  4. [Screens](#screens)
11
11
  5. [Generated Hooks](#generated-hooks)
12
12
  6. [Context API](#context-api)
13
- 7. [Services](#services)
14
- 8. [Lifecycle](#lifecycle)
15
- 9. [Testing](#testing)
16
- 10. [Configuration](#configuration)
17
- 11. [Best Practices](#best-practices)
13
+ 7. [AI API](#ai-api)
14
+ 8. [Services](#services)
15
+ 9. [Teammates](#teammates)
16
+ 10. [Lifecycle](#lifecycle)
17
+ 11. [Testing](#testing)
18
+ 12. [Configuration](#configuration)
19
+ 13. [Best Practices](#best-practices)
18
20
 
19
21
  ## Quick Start
20
22
 
@@ -333,6 +335,147 @@ await ctx.majk.mcpServers.get(id);
333
335
  const subscription = await ctx.majk.eventBus.subscribeAll(handler);
334
336
  ```
335
337
 
338
+ ## AI API
339
+
340
+ Access AI providers and language models with a unified, provider-agnostic interface.
341
+
342
+ ### Basic Usage
343
+
344
+ ```typescript
345
+ // Get default LLM
346
+ const llm = ctx.majk.ai.getDefaultLLM();
347
+
348
+ // Send a prompt
349
+ const result = await llm.prompt({
350
+ messages: [
351
+ { role: 'system', content: 'You are a helpful assistant' },
352
+ { role: 'user', content: 'What is TypeScript?' }
353
+ ],
354
+ temperature: 0.7,
355
+ maxTokens: 500
356
+ });
357
+
358
+ console.log(result.content);
359
+ console.log(`Tokens used: ${result.usage?.totalTokens}`);
360
+ ```
361
+
362
+ ### Provider Management
363
+
364
+ ```typescript
365
+ // List all providers
366
+ const providers = ctx.majk.ai.listProviders();
367
+ for (const provider of providers) {
368
+ console.log(`${provider.name}: ${provider.capabilities}`);
369
+ }
370
+
371
+ // Get specific provider
372
+ const bedrock = ctx.majk.ai.getProvider('bedrock');
373
+ if (bedrock) {
374
+ const claude = bedrock.getLLM('anthropic.claude-3-5-sonnet-20241022-v2:0');
375
+ }
376
+
377
+ // Query by capability
378
+ const imageProviders = ctx.majk.ai.getProvidersWithCapability('imageGeneration');
379
+
380
+ // Check status
381
+ const status = await ctx.majk.ai.getProviderStatus('bedrock');
382
+ console.log(`Available: ${status.available}, Authenticated: ${status.authenticated}`);
383
+ ```
384
+
385
+ ### Streaming Responses
386
+
387
+ ```typescript
388
+ const stream = llm.promptStream({
389
+ messages: [{ role: 'user', content: 'Tell me a story' }]
390
+ });
391
+
392
+ for await (const chunk of stream) {
393
+ if (chunk.type === 'content_delta') {
394
+ process.stdout.write(chunk.content);
395
+ }
396
+ }
397
+ ```
398
+
399
+ ### Structured JSON Output
400
+
401
+ ```typescript
402
+ const result = await llm.promptForJson({
403
+ messages: [
404
+ { role: 'user', content: 'Analyze sentiment: "This is amazing!"' }
405
+ ],
406
+ schema: {
407
+ type: 'object',
408
+ properties: {
409
+ sentiment: { type: 'string', enum: ['positive', 'negative', 'neutral'] },
410
+ confidence: { type: 'number' }
411
+ },
412
+ required: ['sentiment', 'confidence']
413
+ }
414
+ });
415
+
416
+ console.log(result.sentiment); // Type-safe access
417
+ ```
418
+
419
+ ### Advanced Features
420
+
421
+ ```typescript
422
+ // Function calling
423
+ const result = await llm.functionCall({
424
+ messages: [{ role: 'user', content: 'What is the weather?' }],
425
+ functions: [{
426
+ name: 'getWeather',
427
+ description: 'Get weather for a location',
428
+ parameters: {
429
+ type: 'object',
430
+ properties: {
431
+ location: { type: 'string' }
432
+ }
433
+ }
434
+ }]
435
+ });
436
+
437
+ // Image generation (if provider supports it)
438
+ const imageProviders = ctx.majk.ai.getProvidersWithCapability('imageGeneration');
439
+ if (imageProviders.length > 0) {
440
+ const image = await imageProviders[0].generateImage?.({
441
+ prompt: 'A beautiful sunset',
442
+ size: '1024x1024'
443
+ });
444
+ }
445
+
446
+ // Text embeddings (if provider supports it)
447
+ const embedding = await provider.generateEmbedding?.('Some text to embed');
448
+
449
+ // Audio transcription (if provider supports it)
450
+ const transcription = await provider.transcribeAudio?.({
451
+ audio: audioBuffer,
452
+ format: 'mp3'
453
+ });
454
+ ```
455
+
456
+ ### Error Handling
457
+
458
+ ```typescript
459
+ import { AIProviderError } from '@majkapp/plugin-kit';
460
+
461
+ try {
462
+ const result = await llm.prompt({ messages });
463
+ } catch (error) {
464
+ if (error instanceof AIProviderError) {
465
+ console.error(`AI Error [${error.code}]: ${error.message}`);
466
+
467
+ if (error.code === 'RATE_LIMIT_EXCEEDED') {
468
+ // Handle rate limiting
469
+ }
470
+ if (error.code === 'AUTHENTICATION_FAILED') {
471
+ // Handle auth errors
472
+ }
473
+ }
474
+ }
475
+ ```
476
+
477
+ For complete AI documentation, run: `npx @majkapp/plugin-kit --ai`
478
+
336
479
  ## Services
337
480
 
338
481
  Group related functions together.
@@ -379,6 +522,91 @@ Group related functions together.
379
522
  .endService()
380
523
  ```
381
524
 
525
+ ## Teammates
526
+
527
+ Define AI agents that users can interact with.
528
+
529
+ ### Auto-Generated Default Teammate
530
+
531
+ Every plugin automatically gets a default teammate with access to ALL functions.
532
+
533
+ **Default Behavior**:
534
+ - Name: `"<Plugin Name> Expert"`
535
+ - ID: Same as package name (e.g., `"@majk/my-plugin"`)
536
+ - Functions: ALL plugin functions
537
+ - System Prompt: Generic (customizable)
538
+
539
+ ### Custom Instructions
540
+
541
+ ```typescript
542
+ .instructions(`You are an expert assistant for My Plugin.
543
+
544
+ Your capabilities:
545
+ - Function 1 using func1
546
+ - Function 2 using func2
547
+
548
+ When helping users:
549
+ 1. Explain what you're doing
550
+ 2. Present results clearly
551
+ 3. Suggest next steps`)
552
+ ```
553
+
554
+ ### Disable Default Teammate
555
+
556
+ ```typescript
557
+ .noDefaultTeammate()
558
+ ```
559
+
560
+ ### Custom Teammates
561
+
562
+ ```typescript
563
+ .teamMember([
564
+ {
565
+ id: 'viewer',
566
+ name: 'Viewer (Read-Only)',
567
+ systemPrompt: 'You are a read-only assistant...',
568
+ expertise: ['Data Viewing'],
569
+ skills: {
570
+ primary: ['Query'],
571
+ secondary: [],
572
+ languages: [],
573
+ frameworks: [],
574
+ tools: []
575
+ },
576
+ personality: {
577
+ workStyle: 'methodical',
578
+ codeStyle: 'concise',
579
+ reviewStyle: 'pragmatic',
580
+ communicationStyle: 'explanatory'
581
+ },
582
+ metadata: {
583
+ totalTasks: 0,
584
+ successfulTasks: 0,
585
+ projectHistory: [],
586
+ codeStats: {
587
+ linesWritten: 0,
588
+ filesModified: 0,
589
+ testsWritten: 0,
590
+ reviewsPassed: 0,
591
+ commitsCreated: 0
592
+ }
593
+ },
594
+ mcpServerIds: [],
595
+ functions: [
596
+ 'getData', // Simple: current plugin
597
+ 'searchData',
598
+ { // Advanced: cross-plugin
599
+ pluginId: '@other/plugin',
600
+ serviceName: '@other/plugin:all',
601
+ functionName: 'otherFunc'
602
+ }
603
+ ]
604
+ }
605
+ ])
606
+ ```
607
+
608
+ See `npx @majkapp/plugin-kit --teammates` for complete guide.
609
+
382
610
  ## Lifecycle
383
611
 
384
612
  Initialize and clean up resources.
package/docs/INDEX.md CHANGED
@@ -639,7 +639,9 @@ Run `npx @majkapp/plugin-kit --functions` - Deep dive into function patterns
639
639
  Run `npx @majkapp/plugin-kit --screens` - Screen configuration details
640
640
  Run `npx @majkapp/plugin-kit --hooks` - Generated hooks reference
641
641
  Run `npx @majkapp/plugin-kit --context` - ctx.majk and ctx.logger APIs
642
+ Run `npx @majkapp/plugin-kit --ai` - AI providers and LLMs
642
643
  Run `npx @majkapp/plugin-kit --services` - Service grouping patterns
644
+ Run `npx @majkapp/plugin-kit --teammates` - AI teammates and agents
643
645
  Run `npx @majkapp/plugin-kit --lifecycle` - onReady and cleanup
644
646
  Run `npx @majkapp/plugin-kit --testing` - Complete testing guide
645
647
  Run `npx @majkapp/plugin-kit --config` - vite.config.js and project setup