@dataclouder/ngx-agent-cards 0.1.64 → 0.1.66

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.
@@ -1082,13 +1082,25 @@ function getDefaultPromptByType(conversationType) {
1082
1082
  return prompt;
1083
1083
  }
1084
1084
 
1085
+ const DEFAULT_AVATAR_IMAGES = {
1086
+ user: 'assets/defaults/avatar_user.png',
1087
+ assistant: 'assets/defaults/avatar_ai.webp',
1088
+ };
1085
1089
  class ConversationPromptBuilderService {
1086
1090
  constructor() {
1087
1091
  this.userService = inject(UserService);
1088
1092
  }
1089
1093
  // For chat conversation i need inital settings.
1090
- buildConversationSettings(agentCard, parseDict = null) {
1094
+ buildConversationSettingsFromAgentCard(agentCard, parseDict = null) {
1091
1095
  const converstionSettings = agentCard?.conversationSettings || {};
1096
+ converstionSettings.avatarImages = { ...DEFAULT_AVATAR_IMAGES }; // agent does not have avatar images so use default.
1097
+ if (agentCard?.assets?.image?.url) {
1098
+ converstionSettings.avatarImages.assistant = agentCard.assets.image.url;
1099
+ }
1100
+ if (this.userService.user().urlPicture) {
1101
+ converstionSettings.avatarImages.user = this.userService.user().urlPicture;
1102
+ }
1103
+ // Agregar avatas aqui.
1092
1104
  converstionSettings.messages = this.buildConversationMessages(agentCard, parseDict);
1093
1105
  converstionSettings.last_prompt = this.getJailBrakePrompt(agentCard);
1094
1106
  return converstionSettings;
@@ -1436,7 +1448,7 @@ const Endpoints$2 = {
1436
1448
  UserCards: 'api/agent-cards/user-cards', // For findFilteredAgentCards
1437
1449
  ListModels: 'api/agent-cards/models', // For getListModels
1438
1450
  TranslateConversation: 'api/agent-cards/translate', // For translateConversation
1439
- TranscribeAudio: 'api/audio/transcribe/whisper', // For getAudioTranscriptions
1451
+ TranscribeAudio: 'api/ai-services/adapter/stt/transcribe-bytes', // For getAudioTranscriptions
1440
1452
  };
1441
1453
  // ♦️ Finish this will be the default so i dont need to create a new one everytime
1442
1454
  class DefaultAgentCardsService extends EntityCommunicationService {
@@ -1509,7 +1521,7 @@ class DefaultAgentCardsService extends EntityCommunicationService {
1509
1521
  async getAudioTranscriptions(audio, options) {
1510
1522
  // Note: Original service in agent-cards.service.ts used 'node' as host. Using 'primary'.
1511
1523
  // 'options' parameter corresponds to 'metadata' in the original service.
1512
- return this.httpService.uploadFile(`${Endpoints$2.TranscribeAudio}`, audio, options, 'primary');
1524
+ return this.httpService.uploadFile(`${Endpoints$2.TranscribeAudio}?provider=groq`, audio, options, this.appConfig.aiServicesUrl);
1513
1525
  }
1514
1526
  async callInstruction(prompt, model) {
1515
1527
  const messages = [{ content: prompt, role: ChatRole.User }];
@@ -1945,28 +1957,26 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImpor
1945
1957
  }], ctorParameters: () => [] });
1946
1958
 
1947
1959
  class MessageProcessingService {
1948
- processMessage(message, conversationSettings, extraData = {}) {
1960
+ processMessage(message, conversationSettings) {
1961
+ console.log('processMessage conversation data', message, conversationSettings);
1949
1962
  const processedMessage = {
1950
1963
  ...message,
1951
1964
  messageId: message.messageId || nanoid(),
1952
1965
  };
1953
1966
  if (processedMessage.role === ChatRole.User) {
1954
- return this.processUserMessage(processedMessage, extraData);
1967
+ if (conversationSettings.avatarImages.user) {
1968
+ processedMessage.imgUrl = conversationSettings.avatarImages.user;
1969
+ }
1970
+ return processedMessage;
1955
1971
  }
1956
1972
  if (processedMessage.role === ChatRole.Assistant) {
1957
- return this.processAssistantMessage(processedMessage, conversationSettings, extraData);
1973
+ return this.processAssistantMessage(processedMessage, conversationSettings);
1958
1974
  }
1959
1975
  return processedMessage;
1960
1976
  }
1961
- processUserMessage(message, extraData) {
1962
- if (extraData.userImg) {
1963
- message.imgUrl = extraData.userImg;
1964
- }
1965
- return message;
1966
- }
1967
- processAssistantMessage(message, settings, extraData) {
1968
- if (extraData.assistantImg) {
1969
- message.imgUrl = extraData.assistantImg;
1977
+ processAssistantMessage(message, settings) {
1978
+ if (settings.avatarImages.assistant) {
1979
+ message.imgUrl = settings.avatarImages.assistant;
1970
1980
  }
1971
1981
  const mainVoice = settings?.mainVoice?.voice || settings?.tts?.voice;
1972
1982
  message.voice = this.getVoice(mainVoice);
@@ -2003,10 +2013,10 @@ class MessageProcessingService {
2003
2013
  });
2004
2014
  }
2005
2015
  processSSML(message, settings) {
2006
- if (!settings?.tts?.secondaryVoice) {
2016
+ if (!settings?.secondaryVoice?.voice) {
2007
2017
  throw new Error('Secondary voice is required for SSML');
2008
2018
  }
2009
- const content = this.subsItalicsByTag(message.content, settings.tts.secondaryVoice);
2019
+ const content = this.subsItalicsByTag(message.content, settings.secondaryVoice.voice);
2010
2020
  message.ssml = `<speak>${content}</speak>`;
2011
2021
  }
2012
2022
  splitContent(content, maxLength) {
@@ -2688,6 +2698,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImpor
2688
2698
  }]
2689
2699
  }] });
2690
2700
 
2701
+ const DEFUALT_USER_AVATAR = 'assets/defaults/avatar_user.jpg';
2702
+ const DEFUALT_ASSISTANT_AVATAR = 'assets/defaults/avatar_ai.webp';
2691
2703
  class ConversationService {
2692
2704
  constructor() {
2693
2705
  this.defaultAgentCardService = inject(DefaultAgentCardsService);
@@ -2710,9 +2722,9 @@ class ConversationService {
2710
2722
  this.wordClickedSignal = signal(null, ...(ngDevMode ? [{ debugName: "wordClickedSignal" }] : [])); // Signal for clicked word
2711
2723
  this.agentCardSignal = signal(null, ...(ngDevMode ? [{ debugName: "agentCardSignal" }] : []));
2712
2724
  this.agentCard$ = this.agentCardSignal.asReadonly();
2713
- // Var State
2714
- this.avatarImages = { userImg: 'assets/defaults/avatar_user.png', assistantImg: 'assets/defaults/avatar_ai.webp' };
2715
2725
  }
2726
+ // Var State
2727
+ // private avatarImages = { userImg: 'assets/defaults/avatar_user.png', assistantImg: 'assets/defaults/avatar_ai.webp' };
2716
2728
  /**
2717
2729
  * Notifies subscribers that a word has been clicked in a message.
2718
2730
  * @param wordData The data associated with the clicked word.
@@ -2729,7 +2741,7 @@ class ConversationService {
2729
2741
  }
2730
2742
  createNewUserMessage() {
2731
2743
  const message = { content: '...', role: ChatRole.User };
2732
- const processedMessage = this.messageProcessingService.processMessage(message, this.conversationSettingsState(), this.avatarImages);
2744
+ const processedMessage = this.messageProcessingService.processMessage(message, this.conversationSettingsState());
2733
2745
  this.messagesStateService.addMessage(processedMessage);
2734
2746
  return processedMessage.messageId;
2735
2747
  }
@@ -2749,8 +2761,7 @@ class ConversationService {
2749
2761
  }
2750
2762
  setupConversationWithAgentCard(agentCard, parseDict = null, defaultAppConversationFlow = null) {
2751
2763
  this.agentCardSignal.set(agentCard);
2752
- this.avatarImages.assistantImg = agentCard?.assets?.image?.url || this.avatarImages.assistantImg;
2753
- const conversationSettings = this.conversationBuilder.buildConversationSettings(agentCard, parseDict);
2764
+ const conversationSettings = this.conversationBuilder.buildConversationSettingsFromAgentCard(agentCard, parseDict);
2754
2765
  this.overrideSettingsByUserSettings(conversationSettings);
2755
2766
  this.conversationSettingsState.set(conversationSettings);
2756
2767
  const conversationFlow = this.mergeConversationFlows(agentCard.conversationFlow, defaultAppConversationFlow);
@@ -2777,13 +2788,19 @@ class ConversationService {
2777
2788
  return mergedFlow;
2778
2789
  }
2779
2790
  async initConversationWithSettings(conversationSettings, conversationFlow) {
2791
+ // Assign images.
2780
2792
  this.overrideSettingsByUserSettings(conversationSettings);
2793
+ // Set default images.
2794
+ conversationSettings.avatarImages = conversationSettings.avatarImages || { user: DEFUALT_USER_AVATAR, assistant: DEFUALT_ASSISTANT_AVATAR };
2795
+ if (!conversationSettings.avatarImages?.user) {
2796
+ conversationSettings.avatarImages.user = this.userService.user().urlPicture || DEFUALT_USER_AVATAR;
2797
+ }
2798
+ console.log('initConversationWithSettings final antes de set', conversationSettings);
2781
2799
  this.conversationSettingsState.set(conversationSettings);
2782
2800
  this.dynamicFlowService.setConversationFlow(conversationFlow);
2783
2801
  await this.initConversation();
2784
2802
  }
2785
2803
  async initConversation() {
2786
- this.avatarImages.userImg = this.userService.user().urlPicture;
2787
2804
  const conversationSettings = this.conversationSettingsState();
2788
2805
  for (const i in conversationSettings.messages) {
2789
2806
  if (!conversationSettings.messages[i].messageId) {
@@ -2802,7 +2819,7 @@ class ConversationService {
2802
2819
  const firstAssistantMsg = conversationSettings.messages.find((message) => message.role === ChatRole.Assistant);
2803
2820
  if (firstAssistantMsg) {
2804
2821
  // Process the first assistant message
2805
- const processedMessage = this.messageProcessingService.processMessage(firstAssistantMsg, this.conversationSettingsState(), this.avatarImages);
2822
+ const processedMessage = this.messageProcessingService.processMessage(firstAssistantMsg, this.conversationSettingsState());
2806
2823
  this.messagesStateService.updateMessage(firstAssistantMsg.messageId, processedMessage);
2807
2824
  // Find the index of the message with the matching ID
2808
2825
  const messageIndex = conversationSettings.messages.findIndex((message) => message.messageId === firstAssistantMsg.messageId);
@@ -2851,7 +2868,7 @@ class ConversationService {
2851
2868
  }
2852
2869
  else {
2853
2870
  // Means is new meessage, Process and add the new message
2854
- const processedMessage = this.messageProcessingService.processMessage(message, this.conversationSettingsState(), this.avatarImages);
2871
+ const processedMessage = this.messageProcessingService.processMessage(message, this.conversationSettingsState());
2855
2872
  // Ensure ID exists (processMessage should handle this, but fallback just in case)
2856
2873
  processedMessage.messageId = processedMessage.messageId || nanoid();
2857
2874
  this.messagesStateService.addMessage(processedMessage);
@@ -2909,7 +2926,7 @@ class ConversationService {
2909
2926
  throw new Error('No message returned from AI');
2910
2927
  }
2911
2928
  // Process response
2912
- const newMessage = this.messageProcessingService.processMessage({ content: response.content, role: ChatRole.Assistant }, conversationSettings, this.avatarImages);
2929
+ const newMessage = this.messageProcessingService.processMessage({ content: response.content, role: ChatRole.Assistant }, conversationSettings);
2913
2930
  this.messagesStateService.addMessage(newMessage);
2914
2931
  this.isThinkingSignal.set(false);
2915
2932
  // Run Dynamic Flow Evaluations
@@ -4380,6 +4397,7 @@ class DCChatComponent {
4380
4397
  this.conversationService.setDestroyed(false);
4381
4398
  this.chatMonitorService.isConversationActive.set(true);
4382
4399
  if (this.conversationSettings) {
4400
+ console.log('iniciando conversación', this.conversationSettings);
4383
4401
  await this.conversationService.initConversationWithSettings(this.conversationSettings, this.conversationFlow);
4384
4402
  }
4385
4403
  else {
@@ -7127,6 +7145,49 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImpor
7127
7145
  args: [{ selector: 'app-conversationRules', imports: [RouterModule], changeDetection: ChangeDetectionStrategy.OnPush, template: "<router-outlet />\n", styles: [":host{display:block;height:100%}\n"] }]
7128
7146
  }] });
7129
7147
 
7148
+ class ChatEngineTestComponent {
7149
+ constructor() {
7150
+ this.conversationSettings = {
7151
+ autoStart: false,
7152
+ messages: [
7153
+ { role: ChatRole.System, content: 'You are a Teacher english, you only now english and cant speak another language.' },
7154
+ { role: ChatRole.System, content: 'talk with the user and help him to learn english.' },
7155
+ { role: ChatRole.User, content: 'Hello' },
7156
+ { role: ChatRole.Assistant, content: 'Hello, its a wonderful day.' },
7157
+ ],
7158
+ // avatarImages: {
7159
+ // user: 'https://res.cloudinary.com/hcti/image/fetch/c_limit,f_auto,q_auto:good,w_400/https://docs.htmlcsstoimage.com/assets/images/cat.png',
7160
+ // assistant: 'https://pngimg.com/uploads/pokemon/pokemon_PNG129.png',
7161
+ // },
7162
+ };
7163
+ this.conversationFlow = {
7164
+ goal: { task: 'Have a simple conversation' },
7165
+ triggerTasks: {},
7166
+ dynamicConditions: [],
7167
+ moodState: { enabled: false, useAssetStatesOnly: false, detectableStates: [] },
7168
+ };
7169
+ this.agentCard = {
7170
+ name: 'Test Agent',
7171
+ description: 'This is a test agent card.',
7172
+ characterCard: {
7173
+ data: {
7174
+ name: 'Test Agent',
7175
+ description: 'This is a test agent card.',
7176
+ tags: ['test', 'dummy'],
7177
+ gender: 'other',
7178
+ hook: 'A friendly assistant for testing purposes.',
7179
+ },
7180
+ },
7181
+ };
7182
+ }
7183
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: ChatEngineTestComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
7184
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.1.6", type: ChatEngineTestComponent, isStandalone: true, selector: "dc-chat-engine-test", ngImport: i0, template: "<div class=\"chat-engine-test-container\">\n <dc-chat [conversationSettings]=\"conversationSettings\"></dc-chat>\n</div>\n", styles: [".chat-engine-test-container{width:100%;height:100vh;display:flex;justify-content:center;align-items:center}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "component", type: DCChatComponent, selector: "dc-chat", inputs: ["chatUserSettings", "conversationSettings", "conversationFlow", "agentCard", "parseDict"], outputs: ["chatEvent", "goalCompleted"] }] }); }
7185
+ }
7186
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: ChatEngineTestComponent, decorators: [{
7187
+ type: Component,
7188
+ args: [{ selector: 'dc-chat-engine-test', standalone: true, imports: [CommonModule, DCChatComponent], template: "<div class=\"chat-engine-test-container\">\n <dc-chat [conversationSettings]=\"conversationSettings\"></dc-chat>\n</div>\n", styles: [".chat-engine-test-container{width:100%;height:100vh;display:flex;justify-content:center;align-items:center}\n"] }]
7189
+ }] });
7190
+
7130
7191
  /*
7131
7192
  * Public API Surface of ngx-agent-cards
7132
7193
  */
@@ -7136,5 +7197,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImpor
7136
7197
  * Generated bundle index. Do not edit.
7137
7198
  */
7138
7199
 
7139
- export { ACCDataGenerationComponent, AGENT_CARDS_STATE_SERVICE, AIGenerationService, AgentCardListComponent, AgentCardUI, AgentCardsGenerationService, AudioService, AudioSpeed, BACKGROUND_SERVICE_TOKEN, CONVERSATION_AI_TOKEN, CardsCreatorComponent, ChatEventType, ChatMessage, ChatMessageOrchestratorComponent, ChatMonitorService, ChatRole, ConditionOperator, ConditionType, ContextEngineService, ContextType, ConversationDTO, ConversationEvents, ConversationMessagesDTO, ConversationPromptBuilderService, ConversationRuleService, ConversationRulesComponent, ConversationType, ConversationTypeOptions, DCAgentCardFormComponent, DCChatComponent, DCConversationUserChatSettingsComponent, DcAgentCardDetailsComponent, DefaultAgentCardsService, DoActionTypeOptions, DynamicFlowService, DynamicFlowTaskTypeOptions, EAccountsPlatform, EAgentType, EDoActionType, EDynamicFlowTaskType, EntityThen, EntityWhatOptions, EntityWhenOptions, EvalResultStringDefinition, GlobalToolsService, MessageContent, MessageContentDisplayer, MessagesStateService, ModelSelectorComponent, PopupService, PromptPreviewComponent, SectionType, SystemPromptType, TextEngineOptions, TextEngines, VIDEO_PLAYER_SERVICE_TOKEN, VideoPlayerService, VoiceTTSOption, VoiceTTSOptions, WordTimestamps, buildObjectTTSRequest, characterCardStringDataDefinition, convertToHTML, createAIModelFormGroup, defaultconvUserSettings, extractAudioAndTranscription, extractJsonFromResponse, getMoodStateLabelsAsString, getMoodStatePrompt, markdownToHtml, matchTranscription, provideAgentCardService, removeEmojis, removeEmojisAndSpecialCharacters, removeSpecialCharacters };
7200
+ export { ACCDataGenerationComponent, AGENT_CARDS_STATE_SERVICE, AIGenerationService, AgentCardListComponent, AgentCardUI, AgentCardsGenerationService, AudioService, AudioSpeed, BACKGROUND_SERVICE_TOKEN, CONVERSATION_AI_TOKEN, CardsCreatorComponent, ChatEngineTestComponent, ChatEventType, ChatMessage, ChatMessageOrchestratorComponent, ChatMonitorService, ChatRole, ConditionOperator, ConditionType, ContextEngineService, ContextType, ConversationDTO, ConversationEvents, ConversationMessagesDTO, ConversationPromptBuilderService, ConversationRuleService, ConversationRulesComponent, ConversationType, ConversationTypeOptions, DCAgentCardFormComponent, DCChatComponent, DCConversationUserChatSettingsComponent, DcAgentCardDetailsComponent, DefaultAgentCardsService, DoActionTypeOptions, DynamicFlowService, DynamicFlowTaskTypeOptions, EAccountsPlatform, EAgentType, EDoActionType, EDynamicFlowTaskType, EntityThen, EntityWhatOptions, EntityWhenOptions, EvalResultStringDefinition, GlobalToolsService, MessageContent, MessageContentDisplayer, MessagesStateService, ModelSelectorComponent, PopupService, PromptPreviewComponent, SectionType, SystemPromptType, TextEngineOptions, TextEngines, VIDEO_PLAYER_SERVICE_TOKEN, VideoPlayerService, VoiceTTSOption, VoiceTTSOptions, WordTimestamps, buildObjectTTSRequest, characterCardStringDataDefinition, convertToHTML, createAIModelFormGroup, defaultconvUserSettings, extractAudioAndTranscription, extractJsonFromResponse, getMoodStateLabelsAsString, getMoodStatePrompt, markdownToHtml, matchTranscription, provideAgentCardService, removeEmojis, removeEmojisAndSpecialCharacters, removeSpecialCharacters };
7140
7201
  //# sourceMappingURL=dataclouder-ngx-agent-cards.mjs.map