@majkapp/plugin-kit 3.5.4 → 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,12 +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. [Teammates](#teammates)
15
- 9. [Lifecycle](#lifecycle)
16
- 10. [Testing](#testing)
17
- 11. [Configuration](#configuration)
18
- 12. [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)
19
20
 
20
21
  ## Quick Start
21
22
 
@@ -334,6 +335,147 @@ await ctx.majk.mcpServers.get(id);
334
335
  const subscription = await ctx.majk.eventBus.subscribeAll(handler);
335
336
  ```
336
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
+
337
479
  ## Services
338
480
 
339
481
  Group related functions together.
package/docs/INDEX.md CHANGED
@@ -639,6 +639,7 @@ 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
643
644
  Run `npx @majkapp/plugin-kit --teammates` - AI teammates and agents
644
645
  Run `npx @majkapp/plugin-kit --lifecycle` - onReady and cleanup
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@majkapp/plugin-kit",
3
- "version": "3.5.4",
3
+ "version": "3.5.5",
4
4
  "description": "Pure plugin definition library for MAJK - outputs plugin definitions, not HTTP servers",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",