@sowonai/crewx-sdk 0.1.0-dev.0 → 0.1.0-dev.2

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 (74) hide show
  1. package/README.md +444 -0
  2. package/dist/config/yaml-loader.d.ts +8 -0
  3. package/dist/config/yaml-loader.js +137 -0
  4. package/dist/config/yaml-loader.js.map +1 -0
  5. package/dist/core/agent/agent-factory.d.ts +1 -1
  6. package/dist/core/agent/agent-factory.js +4 -6
  7. package/dist/core/agent/agent-factory.js.map +1 -1
  8. package/dist/core/agent/index.d.ts +1 -1
  9. package/dist/core/agent/index.js +2 -1
  10. package/dist/core/agent/index.js.map +1 -1
  11. package/dist/core/parallel/helpers.d.ts +27 -0
  12. package/dist/core/parallel/helpers.js +252 -0
  13. package/dist/core/parallel/helpers.js.map +1 -0
  14. package/dist/core/parallel/index.d.ts +4 -0
  15. package/dist/core/parallel/index.js +11 -0
  16. package/dist/core/parallel/index.js.map +1 -0
  17. package/dist/core/parallel/parallel-runner.d.ts +16 -0
  18. package/dist/core/parallel/parallel-runner.js +230 -0
  19. package/dist/core/parallel/parallel-runner.js.map +1 -0
  20. package/dist/core/parallel/types.d.ts +41 -0
  21. package/dist/core/parallel/types.js +3 -0
  22. package/dist/core/parallel/types.js.map +1 -0
  23. package/dist/core/providers/base-ai.provider.d.ts +12 -26
  24. package/dist/core/providers/base-ai.provider.js +37 -30
  25. package/dist/core/providers/base-ai.provider.js.map +1 -1
  26. package/dist/core/providers/base-ai.types.d.ts +15 -0
  27. package/dist/core/providers/base-ai.types.js +3 -0
  28. package/dist/core/providers/base-ai.types.js.map +1 -0
  29. package/dist/core/providers/claude.provider.d.ts +4 -3
  30. package/dist/core/providers/claude.provider.js +16 -33
  31. package/dist/core/providers/claude.provider.js.map +1 -1
  32. package/dist/core/providers/codex.provider.d.ts +2 -1
  33. package/dist/core/providers/codex.provider.js +4 -18
  34. package/dist/core/providers/codex.provider.js.map +1 -1
  35. package/dist/core/providers/copilot.provider.d.ts +4 -3
  36. package/dist/core/providers/copilot.provider.js +10 -28
  37. package/dist/core/providers/copilot.provider.js.map +1 -1
  38. package/dist/core/providers/gemini.provider.d.ts +4 -3
  39. package/dist/core/providers/gemini.provider.js +18 -36
  40. package/dist/core/providers/gemini.provider.js.map +1 -1
  41. package/dist/core/providers/index.d.ts +5 -0
  42. package/dist/core/providers/index.js +14 -0
  43. package/dist/core/providers/index.js.map +1 -0
  44. package/dist/core/providers/tool-call.types.d.ts +39 -0
  45. package/dist/core/providers/tool-call.types.js +3 -0
  46. package/dist/core/providers/tool-call.types.js.map +1 -0
  47. package/dist/core/remote/index.d.ts +3 -0
  48. package/dist/core/remote/index.js +20 -0
  49. package/dist/core/remote/index.js.map +1 -0
  50. package/dist/core/remote/remote-agent-manager.d.ts +24 -0
  51. package/dist/core/remote/remote-agent-manager.js +195 -0
  52. package/dist/core/remote/remote-agent-manager.js.map +1 -0
  53. package/dist/core/remote/remote-transport.d.ts +15 -0
  54. package/dist/core/remote/remote-transport.js +70 -0
  55. package/dist/core/remote/remote-transport.js.map +1 -0
  56. package/dist/core/remote/types.d.ts +79 -0
  57. package/dist/core/remote/types.js +3 -0
  58. package/dist/core/remote/types.js.map +1 -0
  59. package/dist/index.d.ts +12 -1
  60. package/dist/index.js +26 -1
  61. package/dist/index.js.map +1 -1
  62. package/dist/types/structured-payload.types.d.ts +46 -0
  63. package/dist/types/structured-payload.types.js +65 -0
  64. package/dist/types/structured-payload.types.js.map +1 -0
  65. package/dist/utils/base-message-formatter.d.ts +32 -0
  66. package/dist/utils/base-message-formatter.js +170 -0
  67. package/dist/utils/base-message-formatter.js.map +1 -0
  68. package/package.json +4 -1
  69. package/dist/core/providers/dynamic-provider.factory.d.ts +0 -55
  70. package/dist/core/providers/dynamic-provider.factory.js +0 -587
  71. package/dist/core/providers/dynamic-provider.factory.js.map +0 -1
  72. package/dist/version.d.ts +0 -1
  73. package/dist/version.js +0 -17
  74. package/dist/version.js.map +0 -1
package/README.md CHANGED
@@ -433,6 +433,450 @@ export class DatabaseConversationProvider implements IConversationHistoryProvide
433
433
  }
434
434
  ```
435
435
 
436
+ ## Shared SDK/CLI Integration (WBS-9)
437
+
438
+ The SDK provides reusable components that were previously CLI-only. These abstractions enable custom platform integrations while maintaining consistency.
439
+
440
+ ### Message Formatting (Phase 1)
441
+
442
+ The SDK provides a flexible message formatting system that supports multiple platforms (Slack, Terminal, API, etc.) and allows custom formatters.
443
+
444
+ #### Platform-Specific Formatters
445
+
446
+ **Terminal Formatter (Built-in)**
447
+
448
+ ```typescript
449
+ import { BaseMessageFormatter, type StructuredMessage } from '@sowonai/crewx-sdk';
450
+
451
+ const formatter = new BaseMessageFormatter();
452
+
453
+ // Format messages for terminal display
454
+ const history = formatter.formatHistory(messages, {
455
+ includeUserId: true,
456
+ includeTimestamp: true,
457
+ timestampFormat: 'iso', // 'iso' | 'relative' | 'unix'
458
+ });
459
+
460
+ console.log(history);
461
+ // Output:
462
+ // [2025-10-17T10:00:00Z] user123: Hello!
463
+ // [2025-10-17T10:00:05Z] assistant: How can I help?
464
+ ```
465
+
466
+ **Slack Formatter (Built-in)**
467
+
468
+ For Slack bot integrations, use the Slack-specific formatter that handles threading, mentions, and rich formatting:
469
+
470
+ ```typescript
471
+ import { SlackMessageFormatter } from '@sowonai/crewx-sdk';
472
+
473
+ const slackFormatter = new SlackMessageFormatter();
474
+
475
+ // Format for Slack with rich text support
476
+ const formatted = slackFormatter.formatForSlack(messages, {
477
+ includeTimestamp: true,
478
+ useThreading: true,
479
+ preserveMentions: true,
480
+ });
481
+
482
+ // Format agent response with Slack-specific blocks
483
+ const response = slackFormatter.formatAgentResponse({
484
+ content: 'Task completed successfully!',
485
+ agentId: 'backend',
486
+ metadata: { status: 'success' }
487
+ });
488
+
489
+ // Send to Slack
490
+ await slackClient.chat.postMessage({
491
+ channel: channelId,
492
+ blocks: response.blocks,
493
+ thread_ts: threadId,
494
+ });
495
+ ```
496
+
497
+ **API/JSON Formatter**
498
+
499
+ For API responses or structured data:
500
+
501
+ ```typescript
502
+ import {
503
+ BaseMessageFormatter,
504
+ type StructuredMessage,
505
+ type ConversationMetadata
506
+ } from '@sowonai/crewx-sdk';
507
+
508
+ class APIFormatter extends BaseMessageFormatter {
509
+ formatForAPI(messages: StructuredMessage[]): {
510
+ messages: Array<{
511
+ id: string;
512
+ author: { id: string; isBot: boolean };
513
+ content: string;
514
+ timestamp: string;
515
+ metadata?: Record<string, unknown>;
516
+ }>;
517
+ meta: ConversationMetadata;
518
+ } {
519
+ return {
520
+ messages: messages.map(msg => ({
521
+ id: msg.id,
522
+ author: {
523
+ id: msg.userId || 'unknown',
524
+ isBot: msg.isAssistant || false,
525
+ },
526
+ content: msg.text,
527
+ timestamp: msg.timestamp,
528
+ metadata: msg.metadata,
529
+ })),
530
+ meta: {
531
+ platform: 'api',
532
+ totalMessages: messages.length,
533
+ generatedAt: new Date().toISOString(),
534
+ },
535
+ };
536
+ }
537
+ }
538
+
539
+ const apiFormatter = new APIFormatter();
540
+ const response = apiFormatter.formatForAPI(messages);
541
+
542
+ // Return as JSON API response
543
+ res.json(response);
544
+ ```
545
+
546
+ #### Custom Formatter Extension
547
+
548
+ Create your own formatter for custom platforms:
549
+
550
+ ```typescript
551
+ import {
552
+ BaseMessageFormatter,
553
+ StructuredMessage,
554
+ FormatterOptions
555
+ } from '@sowonai/crewx-sdk';
556
+
557
+ class DiscordFormatter extends BaseMessageFormatter {
558
+ formatMessage(msg: StructuredMessage, options: FormatterOptions): string {
559
+ const timestamp = options.includeTimestamp
560
+ ? `<t:${Math.floor(new Date(msg.timestamp).getTime() / 1000)}:R> `
561
+ : '';
562
+
563
+ const author = msg.isAssistant ? '🤖 **Bot**' : `👤 **${msg.userId}**`;
564
+
565
+ return `${timestamp}${author}: ${msg.text}`;
566
+ }
567
+
568
+ formatForDiscordEmbed(
569
+ message: string,
570
+ options: { color?: number; title?: string }
571
+ ) {
572
+ return {
573
+ embeds: [{
574
+ title: options.title || 'Agent Response',
575
+ description: message,
576
+ color: options.color || 0x5865F2,
577
+ timestamp: new Date().toISOString(),
578
+ }],
579
+ };
580
+ }
581
+ }
582
+
583
+ const discordFormatter = new DiscordFormatter();
584
+ const embed = discordFormatter.formatForDiscordEmbed(
585
+ 'Analysis complete!',
586
+ { title: 'Backend Agent', color: 0x00FF00 }
587
+ );
588
+
589
+ await discordChannel.send(embed);
590
+ ```
591
+
592
+ #### Metadata Handling
593
+
594
+ The formatter system supports rich metadata for enhanced context:
595
+
596
+ ```typescript
597
+ import {
598
+ BaseMessageFormatter,
599
+ type StructuredMessage,
600
+ type ConversationMetadata
601
+ } from '@sowonai/crewx-sdk';
602
+
603
+ const messages: StructuredMessage[] = [
604
+ {
605
+ id: 'msg-1',
606
+ userId: 'user123',
607
+ text: 'What is the status?',
608
+ timestamp: new Date().toISOString(),
609
+ isAssistant: false,
610
+ metadata: {
611
+ platform: 'slack',
612
+ channelId: 'C123456',
613
+ threadTs: '1234567890.123456',
614
+ userAgent: 'SlackBot/1.0',
615
+ },
616
+ },
617
+ {
618
+ id: 'msg-2',
619
+ userId: 'backend-agent',
620
+ text: 'All systems operational.',
621
+ timestamp: new Date().toISOString(),
622
+ isAssistant: true,
623
+ metadata: {
624
+ agentId: 'backend',
625
+ model: 'claude-3-5-sonnet',
626
+ processingTime: 1234,
627
+ tokenUsage: { input: 50, output: 100 },
628
+ },
629
+ },
630
+ ];
631
+
632
+ const formatter = new BaseMessageFormatter();
633
+
634
+ // Format with metadata extraction
635
+ const formatted = formatter.formatHistory(messages, {
636
+ includeUserId: true,
637
+ includeTimestamp: true,
638
+ extractMetadata: true,
639
+ });
640
+
641
+ // Access metadata
642
+ messages.forEach(msg => {
643
+ if (msg.metadata?.tokenUsage) {
644
+ console.log(`Tokens used: ${msg.metadata.tokenUsage.input + msg.metadata.tokenUsage.output}`);
645
+ }
646
+ });
647
+ ```
648
+
649
+ #### Migration Guide for Existing Formatter Users
650
+
651
+ If you're migrating from the CLI's internal formatter to the SDK formatter:
652
+
653
+ **Before (CLI internal)**
654
+ ```typescript
655
+ // This was CLI-only code
656
+ import { MessageFormatter } from '../cli/src/utils/message-formatter';
657
+
658
+ const formatter = new MessageFormatter();
659
+ const result = formatter.format(messages);
660
+ ```
661
+
662
+ **After (SDK)**
663
+ ```typescript
664
+ // Now use SDK's BaseMessageFormatter
665
+ import { BaseMessageFormatter } from '@sowonai/crewx-sdk';
666
+
667
+ const formatter = new BaseMessageFormatter();
668
+ const result = formatter.formatHistory(messages, {
669
+ includeUserId: true,
670
+ includeTimestamp: true,
671
+ });
672
+ ```
673
+
674
+ **Key Changes:**
675
+ 1. Import from `@sowonai/crewx-sdk` instead of CLI internals
676
+ 2. Use `formatHistory()` method instead of `format()`
677
+ 3. Options are now explicitly passed as second parameter
678
+ 4. Metadata handling is built-in with `extractMetadata` option
679
+
680
+ **Slack Migration**
681
+ ```typescript
682
+ // Before (CLI)
683
+ import { SlackFormatter } from '../cli/src/slack/formatter';
684
+
685
+ // After (SDK)
686
+ import { SlackMessageFormatter } from '@sowonai/crewx-sdk';
687
+
688
+ const formatter = new SlackMessageFormatter();
689
+ // Same API, now available in SDK
690
+ ```
691
+
692
+ #### CLI Developer Guide: Adding Slack Formatting
693
+
694
+ If you're building a CLI tool and want to add Slack formatting support:
695
+
696
+ **Step 1: Install SDK**
697
+ ```bash
698
+ npm install @sowonai/crewx-sdk
699
+ ```
700
+
701
+ **Step 2: Import Slack Formatter**
702
+ ```typescript
703
+ import { SlackMessageFormatter } from '@sowonai/crewx-sdk';
704
+ import { WebClient } from '@slack/web-api';
705
+
706
+ const slackClient = new WebClient(process.env.SLACK_BOT_TOKEN);
707
+ const formatter = new SlackMessageFormatter();
708
+ ```
709
+
710
+ **Step 3: Format Messages for Slack**
711
+ ```typescript
712
+ async function sendToSlack(
713
+ channelId: string,
714
+ content: string,
715
+ threadTs?: string
716
+ ) {
717
+ // Format using SDK formatter
718
+ const formatted = formatter.formatAgentResponse({
719
+ content,
720
+ agentId: 'my-cli-agent',
721
+ metadata: {
722
+ source: 'cli',
723
+ timestamp: new Date().toISOString(),
724
+ },
725
+ });
726
+
727
+ // Send to Slack
728
+ await slackClient.chat.postMessage({
729
+ channel: channelId,
730
+ text: content, // Fallback text
731
+ blocks: formatted.blocks,
732
+ thread_ts: threadTs,
733
+ });
734
+ }
735
+ ```
736
+
737
+ **Step 4: Handle Conversation History**
738
+ ```typescript
739
+ import {
740
+ SlackMessageFormatter,
741
+ type StructuredMessage
742
+ } from '@sowonai/crewx-sdk';
743
+
744
+ async function formatSlackThread(threadTs: string) {
745
+ // Fetch Slack thread
746
+ const thread = await slackClient.conversations.replies({
747
+ channel: channelId,
748
+ ts: threadTs,
749
+ });
750
+
751
+ // Convert to StructuredMessage format
752
+ const messages: StructuredMessage[] = thread.messages.map(msg => ({
753
+ id: msg.ts,
754
+ userId: msg.user || 'bot',
755
+ text: msg.text || '',
756
+ timestamp: new Date(parseFloat(msg.ts) * 1000).toISOString(),
757
+ isAssistant: !!msg.bot_id,
758
+ metadata: {
759
+ platform: 'slack',
760
+ threadTs: msg.thread_ts,
761
+ },
762
+ }));
763
+
764
+ // Format for display or processing
765
+ const formatter = new SlackMessageFormatter();
766
+ const formatted = formatter.formatHistory(messages, {
767
+ includeTimestamp: true,
768
+ useThreading: true,
769
+ });
770
+
771
+ return formatted;
772
+ }
773
+ ```
774
+
775
+ **Step 5: Error Handling**
776
+ ```typescript
777
+ try {
778
+ await sendToSlack(channelId, 'Task completed!', threadTs);
779
+ } catch (error) {
780
+ // Format error for Slack
781
+ const errorMessage = formatter.formatAgentResponse({
782
+ content: `❌ Error: ${error.message}`,
783
+ agentId: 'cli-agent',
784
+ metadata: { status: 'error' },
785
+ });
786
+
787
+ await slackClient.chat.postMessage({
788
+ channel: channelId,
789
+ blocks: errorMessage.blocks,
790
+ });
791
+ }
792
+ ```
793
+
794
+ ### AI Providers (Phase 2)
795
+
796
+ Use built-in providers or create custom ones:
797
+
798
+ ```typescript
799
+ import {
800
+ BaseAIProvider,
801
+ ClaudeProvider,
802
+ GeminiProvider,
803
+ CopilotProvider,
804
+ CodexProvider,
805
+ type LoggerLike,
806
+ type BaseAIProviderOptions
807
+ } from '@sowonai/crewx-sdk';
808
+
809
+ // Use built-in provider
810
+ const claude = new ClaudeProvider({
811
+ apiKey: process.env.ANTHROPIC_API_KEY,
812
+ logger: console,
813
+ enableToolUse: true,
814
+ model: 'claude-3-5-sonnet-20241022',
815
+ });
816
+
817
+ // Custom provider
818
+ class MyProvider extends BaseAIProvider {
819
+ constructor(options: BaseAIProviderOptions) {
820
+ super(options);
821
+ }
822
+
823
+ async query(prompt: string, options: AIQueryOptions): Promise<AIResponse> {
824
+ // Custom implementation
825
+ return { content: 'Response', metadata: {} };
826
+ }
827
+ }
828
+ ```
829
+
830
+ ### Remote Agent Management (Phase 3)
831
+
832
+ Manage remote agent communications:
833
+
834
+ ```typescript
835
+ import {
836
+ RemoteAgentManager,
837
+ FetchRemoteTransport,
838
+ MockRemoteTransport,
839
+ type RemoteAgentConfig
840
+ } from '@sowonai/crewx-sdk';
841
+
842
+ // Production transport
843
+ const transport = new FetchRemoteTransport({
844
+ timeout: 30000,
845
+ headers: { 'Authorization': `Bearer ${token}` },
846
+ });
847
+
848
+ // Testing transport
849
+ const mockTransport = new MockRemoteTransport({
850
+ 'agent-1': { content: 'Mocked response', success: true },
851
+ });
852
+
853
+ const manager = new RemoteAgentManager({
854
+ transport,
855
+ enableLogging: true,
856
+ logger: console,
857
+ });
858
+
859
+ // Load remote agent
860
+ await manager.loadAgent({
861
+ id: 'backend',
862
+ url: 'https://api.example.com/agent',
863
+ apiKey: process.env.REMOTE_API_KEY,
864
+ tools: ['search', 'analyze'],
865
+ });
866
+
867
+ // Query remote agent
868
+ const result = await manager.queryAgent('backend', 'Analyze codebase');
869
+ console.log(result.content);
870
+ ```
871
+
872
+ ### Migration Guide
873
+
874
+ For detailed migration instructions from CLI to SDK, see:
875
+ - [WBS-9 Phase 1-5 Integration Guide](../../docs/wbs-9-phase1-5-integration.md)
876
+ - [Phase 1: Message Formatter](../../docs/wbs-9-phase1-migration.md)
877
+ - [Phase 2: AI Providers](../../docs/wbs-9-phase2-migration.md)
878
+ - [Phase 3: Remote Agents](../../docs/wbs-9-phase3-migration.md)
879
+
436
880
  ## Advanced Usage
437
881
 
438
882
  ### Using Internal APIs
@@ -0,0 +1,8 @@
1
+ import { CrewxAgentConfig } from '../core/agent/agent-factory';
2
+ export declare class YamlConfigError extends Error {
3
+ readonly cause?: Error | undefined;
4
+ constructor(message: string, cause?: Error | undefined);
5
+ }
6
+ export declare function loadAgentConfigFromYaml(yamlString: string): CrewxAgentConfig;
7
+ export declare function loadAgentConfigFromFile(filePath: string): CrewxAgentConfig;
8
+ export declare function validateAgentConfig(config: CrewxAgentConfig): boolean;
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.YamlConfigError = void 0;
4
+ exports.loadAgentConfigFromYaml = loadAgentConfigFromYaml;
5
+ exports.loadAgentConfigFromFile = loadAgentConfigFromFile;
6
+ exports.validateAgentConfig = validateAgentConfig;
7
+ const js_yaml_1 = require("js-yaml");
8
+ const fs_1 = require("fs");
9
+ class YamlConfigError extends Error {
10
+ constructor(message, cause) {
11
+ super(message);
12
+ this.cause = cause;
13
+ this.name = 'YamlConfigError';
14
+ }
15
+ }
16
+ exports.YamlConfigError = YamlConfigError;
17
+ function loadAgentConfigFromYaml(yamlString) {
18
+ if (!yamlString || typeof yamlString !== 'string') {
19
+ throw new YamlConfigError('YAML string is required and must be a non-empty string');
20
+ }
21
+ let parsed;
22
+ try {
23
+ const trimmed = yamlString.trim();
24
+ parsed = (0, js_yaml_1.load)(trimmed);
25
+ if (process.env.DEBUG_YAML === '1') {
26
+ console.log('[YAML DEBUG] Input length:', yamlString.length);
27
+ console.log('[YAML DEBUG] Trimmed length:', trimmed.length);
28
+ console.log('[YAML DEBUG] Parsed:', JSON.stringify(parsed));
29
+ console.log('[YAML DEBUG] Type:', typeof parsed);
30
+ console.log('[YAML DEBUG] Is null:', parsed === null);
31
+ console.log('[YAML DEBUG] Is array:', Array.isArray(parsed));
32
+ console.log('[YAML DEBUG] Truthy check:', !parsed);
33
+ }
34
+ }
35
+ catch (error) {
36
+ throw new YamlConfigError(`Failed to parse YAML: ${error instanceof Error ? error.message : 'Unknown error'}`, error instanceof Error ? error : undefined);
37
+ }
38
+ if (parsed === null || parsed === undefined || typeof parsed !== 'object' || Array.isArray(parsed)) {
39
+ throw new YamlConfigError('YAML must contain a valid object structure');
40
+ }
41
+ return parseYamlConfig(parsed);
42
+ }
43
+ function loadAgentConfigFromFile(filePath) {
44
+ if (!filePath || typeof filePath !== 'string') {
45
+ throw new YamlConfigError('File path is required and must be a non-empty string');
46
+ }
47
+ let fileContent;
48
+ try {
49
+ fileContent = (0, fs_1.readFileSync)(filePath, 'utf-8');
50
+ }
51
+ catch (error) {
52
+ throw new YamlConfigError(`Failed to read YAML file '${filePath}': ${error instanceof Error ? error.message : 'Unknown error'}`, error instanceof Error ? error : undefined);
53
+ }
54
+ return loadAgentConfigFromYaml(fileContent);
55
+ }
56
+ function parseYamlConfig(raw) {
57
+ const config = {};
58
+ if (raw.agents && typeof raw.agents === 'object') {
59
+ const agentIds = Object.keys(raw.agents);
60
+ if (agentIds.length > 0) {
61
+ const firstAgentId = agentIds[0];
62
+ const agentConfig = raw.agents[firstAgentId];
63
+ if (agentConfig) {
64
+ config.defaultAgentId = firstAgentId;
65
+ if (agentConfig.provider) {
66
+ config.provider = parseProvider(agentConfig.provider, agentConfig.inline);
67
+ }
68
+ if (agentConfig.knowledgeBase) {
69
+ config.knowledgeBase = parseKnowledgeBase(agentConfig.knowledgeBase);
70
+ }
71
+ }
72
+ }
73
+ }
74
+ if (raw.defaults && typeof raw.defaults === 'object') {
75
+ if (raw.defaults.provider && !config.provider) {
76
+ config.provider = parseProvider(raw.defaults.provider);
77
+ }
78
+ if (raw.defaults.knowledgeBase && !config.knowledgeBase) {
79
+ config.knowledgeBase = parseKnowledgeBase(raw.defaults.knowledgeBase);
80
+ }
81
+ }
82
+ return config;
83
+ }
84
+ function parseProvider(providerString, inline) {
85
+ if (!providerString || typeof providerString !== 'string') {
86
+ throw new YamlConfigError('Provider must be a non-empty string');
87
+ }
88
+ const parts = providerString.split('/');
89
+ if (parts.length !== 2) {
90
+ throw new YamlConfigError(`Invalid provider format '${providerString}'. Expected format: 'namespace/id' (e.g., 'cli/claude')`);
91
+ }
92
+ const [namespace, id] = parts;
93
+ if (!namespace || !id) {
94
+ throw new YamlConfigError(`Provider namespace and id cannot be empty. Got: '${providerString}'`);
95
+ }
96
+ const config = {
97
+ namespace,
98
+ id,
99
+ };
100
+ if (inline && typeof inline === 'object') {
101
+ if (inline.model && typeof inline.model === 'string') {
102
+ config.model = inline.model;
103
+ }
104
+ if (inline.apiKey && typeof inline.apiKey === 'string') {
105
+ config.apiKey = inline.apiKey;
106
+ }
107
+ }
108
+ return config;
109
+ }
110
+ function parseKnowledgeBase(value) {
111
+ if (typeof value === 'string') {
112
+ return { path: value };
113
+ }
114
+ if (Array.isArray(value)) {
115
+ return { sources: value.filter((s) => typeof s === 'string') };
116
+ }
117
+ throw new YamlConfigError('Knowledge base must be a string (path) or array of strings (sources)');
118
+ }
119
+ function validateAgentConfig(config) {
120
+ if (!config || typeof config !== 'object') {
121
+ throw new YamlConfigError('Configuration must be a valid object');
122
+ }
123
+ if (config.provider) {
124
+ if (!config.provider.namespace || !config.provider.id) {
125
+ throw new YamlConfigError('Provider must have both namespace and id');
126
+ }
127
+ }
128
+ if (config.knowledgeBase) {
129
+ const hasPath = config.knowledgeBase.path && typeof config.knowledgeBase.path === 'string';
130
+ const hasSources = Array.isArray(config.knowledgeBase.sources) && config.knowledgeBase.sources.length > 0;
131
+ if (!hasPath && !hasSources) {
132
+ throw new YamlConfigError('Knowledge base must have either path or sources');
133
+ }
134
+ }
135
+ return true;
136
+ }
137
+ //# sourceMappingURL=yaml-loader.js.map
@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CrewxAgentConfig): Promise<CrewxAgentResult>;
30
- export declare function loadAgentConfigFromYaml(yamlString: string): CrewxAgentConfig;
30
+ export { loadAgentConfigFromYaml, loadAgentConfigFromFile } from '../../config/yaml-loader';
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadAgentConfigFromFile = exports.loadAgentConfigFromYaml = void 0;
3
4
  exports.createCrewxAgent = createCrewxAgent;
4
- exports.loadAgentConfigFromYaml = loadAgentConfigFromYaml;
5
5
  const agent_runtime_1 = require("./agent-runtime");
6
6
  const event_bus_1 = require("./event-bus");
7
7
  async function createCrewxAgent(config = {}) {
@@ -23,9 +23,7 @@ async function createCrewxAgent(config = {}) {
23
23
  eventBus,
24
24
  };
25
25
  }
26
- function loadAgentConfigFromYaml(yamlString) {
27
- return {
28
- defaultAgentId: 'crewx',
29
- };
30
- }
26
+ var yaml_loader_1 = require("../../config/yaml-loader");
27
+ Object.defineProperty(exports, "loadAgentConfigFromYaml", { enumerable: true, get: function () { return yaml_loader_1.loadAgentConfigFromYaml; } });
28
+ Object.defineProperty(exports, "loadAgentConfigFromFile", { enumerable: true, get: function () { return yaml_loader_1.loadAgentConfigFromFile; } });
31
29
  //# sourceMappingURL=agent-factory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent-factory.js","sourceRoot":"","sources":["../../../src/core/agent/agent-factory.ts"],"names":[],"mappings":";;AAoFA,4CA6BC;AAMD,0DAMC;AAxHD,mDAAoE;AACpE,2CAAsD;AA8E/C,KAAK,UAAU,gBAAgB,CACpC,SAA2B,EAAE;IAG7B,MAAM,QAAQ,GAAG,IAAI,oBAAQ,EAAE,CAAC;IAGhC,MAAM,cAAc,GAAwB;QAC1C,QAAQ;QACR,eAAe,EAAE,MAAM,CAAC,eAAe,IAAI,KAAK;QAChD,cAAc,EAAE,MAAM,CAAC,cAAc,IAAI,OAAO;KACjD,CAAC;IAGF,MAAM,OAAO,GAAG,IAAI,4BAAY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AO,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC;QAClE,QAAQ;KACT,CAAC;AACJ,CAAC;AAQD,wDAA4F;AAAnF,sHAAA,uBAAuB,OAAA;AAAE,sHAAA,uBAAuB,OAAA"}
@@ -1,3 +1,3 @@
1
- export { createCrewxAgent, loadAgentConfigFromYaml, type CrewxAgent, type CrewxAgentConfig, type CrewxAgentResult, type ProviderConfig, type KnowledgeBaseConfig, } from './agent-factory';
1
+ export { createCrewxAgent, loadAgentConfigFromYaml, loadAgentConfigFromFile, type CrewxAgent, type CrewxAgentConfig, type CrewxAgentResult, type ProviderConfig, type KnowledgeBaseConfig, } from './agent-factory';
2
2
  export { AgentRuntime, type AgentQueryRequest, type AgentExecuteRequest, type AgentResult, type AgentRuntimeOptions, } from './agent-runtime';
3
3
  export { EventBus, type EventListener, type CallStackFrame, type AgentEvent, } from './event-bus';
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EventBus = exports.AgentRuntime = exports.loadAgentConfigFromYaml = exports.createCrewxAgent = void 0;
3
+ exports.EventBus = exports.AgentRuntime = exports.loadAgentConfigFromFile = exports.loadAgentConfigFromYaml = exports.createCrewxAgent = void 0;
4
4
  var agent_factory_1 = require("./agent-factory");
5
5
  Object.defineProperty(exports, "createCrewxAgent", { enumerable: true, get: function () { return agent_factory_1.createCrewxAgent; } });
6
6
  Object.defineProperty(exports, "loadAgentConfigFromYaml", { enumerable: true, get: function () { return agent_factory_1.loadAgentConfigFromYaml; } });
7
+ Object.defineProperty(exports, "loadAgentConfigFromFile", { enumerable: true, get: function () { return agent_factory_1.loadAgentConfigFromFile; } });
7
8
  var agent_runtime_1 = require("./agent-runtime");
8
9
  Object.defineProperty(exports, "AgentRuntime", { enumerable: true, get: function () { return agent_runtime_1.AgentRuntime; } });
9
10
  var event_bus_1 = require("./event-bus");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/agent/index.ts"],"names":[],"mappings":";;;AAIA,iDAQyB;AAPvB,iHAAA,gBAAgB,OAAA;AAChB,wHAAA,uBAAuB,OAAA;AAQzB,iDAMyB;AALvB,6GAAA,YAAY,OAAA;AAOd,yCAKqB;AAJnB,qGAAA,QAAQ,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/agent/index.ts"],"names":[],"mappings":";;;AAIA,iDASyB;AARvB,iHAAA,gBAAgB,OAAA;AAChB,wHAAA,uBAAuB,OAAA;AACvB,wHAAA,uBAAuB,OAAA;AAQzB,iDAMyB;AALvB,6GAAA,YAAY,OAAA;AAOd,yCAKqB;AAJnB,qGAAA,QAAQ,OAAA"}