@dataclouder/ngx-agent-cards 0.1.64 → 0.1.65
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
|
-
|
|
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/
|
|
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,
|
|
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,25 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImpor
|
|
|
1945
1957
|
}], ctorParameters: () => [] });
|
|
1946
1958
|
|
|
1947
1959
|
class MessageProcessingService {
|
|
1948
|
-
processMessage(message, conversationSettings
|
|
1960
|
+
processMessage(message, conversationSettings) {
|
|
1949
1961
|
const processedMessage = {
|
|
1950
1962
|
...message,
|
|
1951
1963
|
messageId: message.messageId || nanoid(),
|
|
1952
1964
|
};
|
|
1953
1965
|
if (processedMessage.role === ChatRole.User) {
|
|
1954
|
-
|
|
1966
|
+
if (conversationSettings.avatarImages.user) {
|
|
1967
|
+
processedMessage.imgUrl = conversationSettings.avatarImages.user;
|
|
1968
|
+
}
|
|
1969
|
+
return processedMessage;
|
|
1955
1970
|
}
|
|
1956
1971
|
if (processedMessage.role === ChatRole.Assistant) {
|
|
1957
|
-
return this.processAssistantMessage(processedMessage, conversationSettings
|
|
1972
|
+
return this.processAssistantMessage(processedMessage, conversationSettings);
|
|
1958
1973
|
}
|
|
1959
1974
|
return processedMessage;
|
|
1960
1975
|
}
|
|
1961
|
-
|
|
1962
|
-
if (
|
|
1963
|
-
message.imgUrl =
|
|
1964
|
-
}
|
|
1965
|
-
return message;
|
|
1966
|
-
}
|
|
1967
|
-
processAssistantMessage(message, settings, extraData) {
|
|
1968
|
-
if (extraData.assistantImg) {
|
|
1969
|
-
message.imgUrl = extraData.assistantImg;
|
|
1976
|
+
processAssistantMessage(message, settings) {
|
|
1977
|
+
if (settings.avatarImages.assistant) {
|
|
1978
|
+
message.imgUrl = settings.avatarImages.assistant;
|
|
1970
1979
|
}
|
|
1971
1980
|
const mainVoice = settings?.mainVoice?.voice || settings?.tts?.voice;
|
|
1972
1981
|
message.voice = this.getVoice(mainVoice);
|
|
@@ -2003,10 +2012,10 @@ class MessageProcessingService {
|
|
|
2003
2012
|
});
|
|
2004
2013
|
}
|
|
2005
2014
|
processSSML(message, settings) {
|
|
2006
|
-
if (!settings?.
|
|
2015
|
+
if (!settings?.secondaryVoice?.voice) {
|
|
2007
2016
|
throw new Error('Secondary voice is required for SSML');
|
|
2008
2017
|
}
|
|
2009
|
-
const content = this.subsItalicsByTag(message.content, settings.
|
|
2018
|
+
const content = this.subsItalicsByTag(message.content, settings.secondaryVoice.voice);
|
|
2010
2019
|
message.ssml = `<speak>${content}</speak>`;
|
|
2011
2020
|
}
|
|
2012
2021
|
splitContent(content, maxLength) {
|
|
@@ -2688,6 +2697,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImpor
|
|
|
2688
2697
|
}]
|
|
2689
2698
|
}] });
|
|
2690
2699
|
|
|
2700
|
+
const DEFUALT_USER_AVATAR = 'assets/defaults/avatar_user.jpg';
|
|
2701
|
+
const DEFUALT_ASSISTANT_AVATAR = 'assets/defaults/avatar_ai.webp';
|
|
2691
2702
|
class ConversationService {
|
|
2692
2703
|
constructor() {
|
|
2693
2704
|
this.defaultAgentCardService = inject(DefaultAgentCardsService);
|
|
@@ -2710,9 +2721,9 @@ class ConversationService {
|
|
|
2710
2721
|
this.wordClickedSignal = signal(null, ...(ngDevMode ? [{ debugName: "wordClickedSignal" }] : [])); // Signal for clicked word
|
|
2711
2722
|
this.agentCardSignal = signal(null, ...(ngDevMode ? [{ debugName: "agentCardSignal" }] : []));
|
|
2712
2723
|
this.agentCard$ = this.agentCardSignal.asReadonly();
|
|
2713
|
-
// Var State
|
|
2714
|
-
this.avatarImages = { userImg: 'assets/defaults/avatar_user.png', assistantImg: 'assets/defaults/avatar_ai.webp' };
|
|
2715
2724
|
}
|
|
2725
|
+
// Var State
|
|
2726
|
+
// private avatarImages = { userImg: 'assets/defaults/avatar_user.png', assistantImg: 'assets/defaults/avatar_ai.webp' };
|
|
2716
2727
|
/**
|
|
2717
2728
|
* Notifies subscribers that a word has been clicked in a message.
|
|
2718
2729
|
* @param wordData The data associated with the clicked word.
|
|
@@ -2729,7 +2740,7 @@ class ConversationService {
|
|
|
2729
2740
|
}
|
|
2730
2741
|
createNewUserMessage() {
|
|
2731
2742
|
const message = { content: '...', role: ChatRole.User };
|
|
2732
|
-
const processedMessage = this.messageProcessingService.processMessage(message, this.conversationSettingsState()
|
|
2743
|
+
const processedMessage = this.messageProcessingService.processMessage(message, this.conversationSettingsState());
|
|
2733
2744
|
this.messagesStateService.addMessage(processedMessage);
|
|
2734
2745
|
return processedMessage.messageId;
|
|
2735
2746
|
}
|
|
@@ -2749,8 +2760,7 @@ class ConversationService {
|
|
|
2749
2760
|
}
|
|
2750
2761
|
setupConversationWithAgentCard(agentCard, parseDict = null, defaultAppConversationFlow = null) {
|
|
2751
2762
|
this.agentCardSignal.set(agentCard);
|
|
2752
|
-
|
|
2753
|
-
const conversationSettings = this.conversationBuilder.buildConversationSettings(agentCard, parseDict);
|
|
2763
|
+
const conversationSettings = this.conversationBuilder.buildConversationSettingsFromAgentCard(agentCard, parseDict);
|
|
2754
2764
|
this.overrideSettingsByUserSettings(conversationSettings);
|
|
2755
2765
|
this.conversationSettingsState.set(conversationSettings);
|
|
2756
2766
|
const conversationFlow = this.mergeConversationFlows(agentCard.conversationFlow, defaultAppConversationFlow);
|
|
@@ -2777,13 +2787,18 @@ class ConversationService {
|
|
|
2777
2787
|
return mergedFlow;
|
|
2778
2788
|
}
|
|
2779
2789
|
async initConversationWithSettings(conversationSettings, conversationFlow) {
|
|
2790
|
+
// Assign images.
|
|
2780
2791
|
this.overrideSettingsByUserSettings(conversationSettings);
|
|
2792
|
+
// Set default images.
|
|
2793
|
+
conversationSettings.avatarImages = conversationSettings.avatarImages || { user: DEFUALT_USER_AVATAR, assistant: DEFUALT_ASSISTANT_AVATAR };
|
|
2794
|
+
if (!conversationSettings.avatarImages?.user) {
|
|
2795
|
+
conversationSettings.avatarImages.user = this.userService.user().urlPicture || DEFUALT_USER_AVATAR;
|
|
2796
|
+
}
|
|
2781
2797
|
this.conversationSettingsState.set(conversationSettings);
|
|
2782
2798
|
this.dynamicFlowService.setConversationFlow(conversationFlow);
|
|
2783
2799
|
await this.initConversation();
|
|
2784
2800
|
}
|
|
2785
2801
|
async initConversation() {
|
|
2786
|
-
this.avatarImages.userImg = this.userService.user().urlPicture;
|
|
2787
2802
|
const conversationSettings = this.conversationSettingsState();
|
|
2788
2803
|
for (const i in conversationSettings.messages) {
|
|
2789
2804
|
if (!conversationSettings.messages[i].messageId) {
|
|
@@ -2802,7 +2817,7 @@ class ConversationService {
|
|
|
2802
2817
|
const firstAssistantMsg = conversationSettings.messages.find((message) => message.role === ChatRole.Assistant);
|
|
2803
2818
|
if (firstAssistantMsg) {
|
|
2804
2819
|
// Process the first assistant message
|
|
2805
|
-
const processedMessage = this.messageProcessingService.processMessage(firstAssistantMsg, this.conversationSettingsState()
|
|
2820
|
+
const processedMessage = this.messageProcessingService.processMessage(firstAssistantMsg, this.conversationSettingsState());
|
|
2806
2821
|
this.messagesStateService.updateMessage(firstAssistantMsg.messageId, processedMessage);
|
|
2807
2822
|
// Find the index of the message with the matching ID
|
|
2808
2823
|
const messageIndex = conversationSettings.messages.findIndex((message) => message.messageId === firstAssistantMsg.messageId);
|
|
@@ -2851,7 +2866,7 @@ class ConversationService {
|
|
|
2851
2866
|
}
|
|
2852
2867
|
else {
|
|
2853
2868
|
// Means is new meessage, Process and add the new message
|
|
2854
|
-
const processedMessage = this.messageProcessingService.processMessage(message, this.conversationSettingsState()
|
|
2869
|
+
const processedMessage = this.messageProcessingService.processMessage(message, this.conversationSettingsState());
|
|
2855
2870
|
// Ensure ID exists (processMessage should handle this, but fallback just in case)
|
|
2856
2871
|
processedMessage.messageId = processedMessage.messageId || nanoid();
|
|
2857
2872
|
this.messagesStateService.addMessage(processedMessage);
|
|
@@ -2909,7 +2924,7 @@ class ConversationService {
|
|
|
2909
2924
|
throw new Error('No message returned from AI');
|
|
2910
2925
|
}
|
|
2911
2926
|
// Process response
|
|
2912
|
-
const newMessage = this.messageProcessingService.processMessage({ content: response.content, role: ChatRole.Assistant }, conversationSettings
|
|
2927
|
+
const newMessage = this.messageProcessingService.processMessage({ content: response.content, role: ChatRole.Assistant }, conversationSettings);
|
|
2913
2928
|
this.messagesStateService.addMessage(newMessage);
|
|
2914
2929
|
this.isThinkingSignal.set(false);
|
|
2915
2930
|
// Run Dynamic Flow Evaluations
|
|
@@ -7127,6 +7142,49 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImpor
|
|
|
7127
7142
|
args: [{ selector: 'app-conversationRules', imports: [RouterModule], changeDetection: ChangeDetectionStrategy.OnPush, template: "<router-outlet />\n", styles: [":host{display:block;height:100%}\n"] }]
|
|
7128
7143
|
}] });
|
|
7129
7144
|
|
|
7145
|
+
class ChatEngineTestComponent {
|
|
7146
|
+
constructor() {
|
|
7147
|
+
this.conversationSettings = {
|
|
7148
|
+
autoStart: false,
|
|
7149
|
+
messages: [
|
|
7150
|
+
{ role: ChatRole.System, content: 'You are a Teacher english, you only now english and cant speak another language.' },
|
|
7151
|
+
{ role: ChatRole.System, content: 'talk with the user and help him to learn english.' },
|
|
7152
|
+
{ role: ChatRole.User, content: 'Hello' },
|
|
7153
|
+
{ role: ChatRole.Assistant, content: 'Hello, its a wonderful day.' },
|
|
7154
|
+
],
|
|
7155
|
+
// avatarImages: {
|
|
7156
|
+
// 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',
|
|
7157
|
+
// assistant: 'https://pngimg.com/uploads/pokemon/pokemon_PNG129.png',
|
|
7158
|
+
// },
|
|
7159
|
+
};
|
|
7160
|
+
this.conversationFlow = {
|
|
7161
|
+
goal: { task: 'Have a simple conversation' },
|
|
7162
|
+
triggerTasks: {},
|
|
7163
|
+
dynamicConditions: [],
|
|
7164
|
+
moodState: { enabled: false, useAssetStatesOnly: false, detectableStates: [] },
|
|
7165
|
+
};
|
|
7166
|
+
this.agentCard = {
|
|
7167
|
+
name: 'Test Agent',
|
|
7168
|
+
description: 'This is a test agent card.',
|
|
7169
|
+
characterCard: {
|
|
7170
|
+
data: {
|
|
7171
|
+
name: 'Test Agent',
|
|
7172
|
+
description: 'This is a test agent card.',
|
|
7173
|
+
tags: ['test', 'dummy'],
|
|
7174
|
+
gender: 'other',
|
|
7175
|
+
hook: 'A friendly assistant for testing purposes.',
|
|
7176
|
+
},
|
|
7177
|
+
},
|
|
7178
|
+
};
|
|
7179
|
+
}
|
|
7180
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: ChatEngineTestComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
7181
|
+
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"] }] }); }
|
|
7182
|
+
}
|
|
7183
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: ChatEngineTestComponent, decorators: [{
|
|
7184
|
+
type: Component,
|
|
7185
|
+
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"] }]
|
|
7186
|
+
}] });
|
|
7187
|
+
|
|
7130
7188
|
/*
|
|
7131
7189
|
* Public API Surface of ngx-agent-cards
|
|
7132
7190
|
*/
|
|
@@ -7136,5 +7194,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImpor
|
|
|
7136
7194
|
* Generated bundle index. Do not edit.
|
|
7137
7195
|
*/
|
|
7138
7196
|
|
|
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 };
|
|
7197
|
+
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
7198
|
//# sourceMappingURL=dataclouder-ngx-agent-cards.mjs.map
|