diff --git a/OpenJibo/docs/feature-backlog.md b/OpenJibo/docs/feature-backlog.md index 974cb91..4ca3926 100644 --- a/OpenJibo/docs/feature-backlog.md +++ b/OpenJibo/docs/feature-backlog.md @@ -89,6 +89,7 @@ Parallel tags: - the attached `jibo test 13` session includes both examples in one bundle: - a proactive or share-style prompt where spoken `yes` was treated as generic speech - a later update prompt where spoken `no` was accepted correctly + - the share prompt uses `surprises-date/offer_date_fact` with `$YESNO`, and the failing reply leaked `globals/*` rules back into a Nimbus relaunch - Implementation notes: - compare the active listen rules, ASR hints, and local skill ownership for the share-style prompt versus OTA prompts - make constrained yes-no detection cover this prompt family without regressing the already-working update `no` path diff --git a/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Application/Services/JiboInteractionService.cs b/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Application/Services/JiboInteractionService.cs index 8283dc2..b5e46c1 100644 --- a/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Application/Services/JiboInteractionService.cs +++ b/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Application/Services/JiboInteractionService.cs @@ -340,6 +340,7 @@ public sealed class JiboInteractionService( string.Equals(rule, "$YESNO", StringComparison.OrdinalIgnoreCase) || string.Equals(rule, "create/is_it_a_keeper", StringComparison.OrdinalIgnoreCase) || string.Equals(rule, "settings/download_now_later", StringComparison.OrdinalIgnoreCase) || + string.Equals(rule, "surprises-date/offer_date_fact", StringComparison.OrdinalIgnoreCase) || string.Equals(rule, "surprises-ota/want_to_download_now", StringComparison.OrdinalIgnoreCase)); } diff --git a/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Application/Services/ResponsePlanToSocketMessagesMapper.cs b/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Application/Services/ResponsePlanToSocketMessagesMapper.cs index d877c8c..c748908 100644 --- a/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Application/Services/ResponsePlanToSocketMessagesMapper.cs +++ b/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Application/Services/ResponsePlanToSocketMessagesMapper.cs @@ -57,7 +57,16 @@ public sealed class ResponsePlanToSocketMessagesMapper : isWordOfDayGuess ? ["word-of-the-day/puzzle"] : isYesNoTurn && isYesNoIntent ? [yesNoRule!] : rules; - var entities = ReadEntities(turn, messageType, isYesNoTurn && isYesNoIntent, isWordOfDayLaunch, isRadioLaunch, isWordOfDayGuess, wordOfDayGuess, radioStation); + var entities = ReadEntities( + turn, + messageType, + isYesNoTurn && isYesNoIntent, + ShouldIncludeCreateDomain(yesNoRule), + isWordOfDayLaunch, + isRadioLaunch, + isWordOfDayGuess, + wordOfDayGuess, + radioStation); var listenMessage = new { type = "LISTEN", @@ -265,15 +274,21 @@ public sealed class ResponsePlanToSocketMessagesMapper private static object ReadEntities( TurnContext turn, string? messageType, - bool yesNoCreateTurn, + bool yesNoTurn, + bool includeCreateDomain, bool wordOfDayLaunch, bool radioLaunch, bool wordOfDayGuess, string? guess, string? radioStation) { - if (yesNoCreateTurn) + if (yesNoTurn) { + if (!includeCreateDomain) + { + return new Dictionary(); + } + return new Dictionary { ["domain"] = "create" @@ -331,9 +346,16 @@ public sealed class ResponsePlanToSocketMessagesMapper .FirstOrDefault(static rule => string.Equals(rule, "create/is_it_a_keeper", StringComparison.OrdinalIgnoreCase) || string.Equals(rule, "settings/download_now_later", StringComparison.OrdinalIgnoreCase) || + string.Equals(rule, "surprises-date/offer_date_fact", StringComparison.OrdinalIgnoreCase) || string.Equals(rule, "surprises-ota/want_to_download_now", StringComparison.OrdinalIgnoreCase)); } + private static bool ShouldIncludeCreateDomain(string? yesNoRule) + { + return string.Equals(yesNoRule, "create/is_it_a_keeper", StringComparison.OrdinalIgnoreCase) || + string.Equals(yesNoRule, "surprises-ota/want_to_download_now", StringComparison.OrdinalIgnoreCase); + } + private static IEnumerable ReadRuleValues(TurnContext turn) { return ReadRuleValues(turn, "listenRules").Concat(ReadRuleValues(turn, "clientRules")); @@ -715,8 +737,7 @@ public sealed class ResponsePlanToSocketMessagesMapper .Replace("&", "&", StringComparison.Ordinal) .Replace("<", "<", StringComparison.Ordinal) .Replace(">", ">", StringComparison.Ordinal) - .Replace("\"", """, StringComparison.Ordinal) - .Replace("'", "'", StringComparison.Ordinal); + .Replace("\"", """, StringComparison.Ordinal); } private static string? ReadPayloadString(IDictionary? payload, string key) diff --git a/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Application/Services/WebSocketTurnFinalizationService.cs b/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Application/Services/WebSocketTurnFinalizationService.cs index b7bfac4..9cb67d4 100644 --- a/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Application/Services/WebSocketTurnFinalizationService.cs +++ b/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Application/Services/WebSocketTurnFinalizationService.cs @@ -710,6 +710,7 @@ public sealed class WebSocketTurnFinalizationService( string.Equals(rule, "$YESNO", StringComparison.OrdinalIgnoreCase) || string.Equals(rule, "create/is_it_a_keeper", StringComparison.OrdinalIgnoreCase) || string.Equals(rule, "settings/download_now_later", StringComparison.OrdinalIgnoreCase) || + string.Equals(rule, "surprises-date/offer_date_fact", StringComparison.OrdinalIgnoreCase) || string.Equals(rule, "surprises-ota/want_to_download_now", StringComparison.OrdinalIgnoreCase)); } diff --git a/OpenJibo/tests/Jibo.Cloud.Tests/WebSockets/JiboInteractionServiceTests.cs b/OpenJibo/tests/Jibo.Cloud.Tests/WebSockets/JiboInteractionServiceTests.cs index 1efd92a..5ef09fc 100644 --- a/OpenJibo/tests/Jibo.Cloud.Tests/WebSockets/JiboInteractionServiceTests.cs +++ b/OpenJibo/tests/Jibo.Cloud.Tests/WebSockets/JiboInteractionServiceTests.cs @@ -115,6 +115,26 @@ public sealed class JiboInteractionServiceTests Assert.Equal("No.", decision.ReplyText); } + [Fact] + public async Task BuildDecisionAsync_SurprisesDateOfferPrompt_MapsShortAffirmationToYesIntent() + { + var service = CreateService(); + + var decision = await service.BuildDecisionAsync(new TurnContext + { + RawTranscript = "Yes!", + NormalizedTranscript = "Yes!", + Attributes = new Dictionary + { + ["listenRules"] = new[] { "surprises-date/offer_date_fact", "globals/global_commands_launch" }, + ["listenAsrHints"] = new[] { "$YESNO" } + } + }); + + Assert.Equal("yes", decision.IntentName); + Assert.Equal("Yes.", decision.ReplyText); + } + [Fact] public async Task BuildDecisionAsync_SkillPhraseVariant_MapsToKnownIntent() { diff --git a/OpenJibo/tests/Jibo.Cloud.Tests/WebSockets/JiboWebSocketServiceTests.cs b/OpenJibo/tests/Jibo.Cloud.Tests/WebSockets/JiboWebSocketServiceTests.cs index db4323e..48e86d3 100644 --- a/OpenJibo/tests/Jibo.Cloud.Tests/WebSockets/JiboWebSocketServiceTests.cs +++ b/OpenJibo/tests/Jibo.Cloud.Tests/WebSockets/JiboWebSocketServiceTests.cs @@ -4,6 +4,7 @@ using Jibo.Cloud.Domain.Models; using Jibo.Cloud.Infrastructure.Content; using Jibo.Cloud.Infrastructure.Persistence; using Jibo.Cloud.Tests.Fixtures; +using Jibo.Runtime.Abstractions; namespace Jibo.Cloud.Tests.WebSockets; @@ -403,6 +404,85 @@ public sealed class JiboWebSocketServiceTests Assert.Equal("surprises-ota/want_to_download_now", listenPayload.RootElement.GetProperty("data").GetProperty("match").GetProperty("rule").GetString()); } + [Fact] + public async Task ClientAsr_SurprisesDateOfferPrompt_MapsYesWithoutGlobalRuleLeak() + { + await _service.HandleMessageAsync(new WebSocketMessageEnvelope + { + HostName = "neo-hub.jibo.com", + Path = "/listen", + Kind = "neo-hub-listen", + Token = "hub-share-yesno-token", + Text = """{"type":"LISTEN","transID":"trans-share-yes","data":{"rules":["surprises-date/offer_date_fact","globals/gui_nav","globals/mim_repeat","globals/global_commands_launch"],"asr":{"hints":["$YESNO"]}}}""" + }); + + var replies = await _service.HandleMessageAsync(new WebSocketMessageEnvelope + { + HostName = "neo-hub.jibo.com", + Path = "/listen", + Kind = "neo-hub-listen", + Token = "hub-share-yesno-token", + Text = """{"type":"CLIENT_ASR","transID":"trans-share-yes","data":{"text":"Yes!"}}""" + }); + + Assert.Equal(3, replies.Count); + + using var listenPayload = JsonDocument.Parse(replies[0].Text!); + Assert.Equal("yes", listenPayload.RootElement.GetProperty("data").GetProperty("nlu").GetProperty("intent").GetString()); + var rules = listenPayload.RootElement.GetProperty("data").GetProperty("nlu").GetProperty("rules"); + Assert.Single(rules.EnumerateArray()); + Assert.Equal("surprises-date/offer_date_fact", rules[0].GetString()); + Assert.Equal("surprises-date/offer_date_fact", listenPayload.RootElement.GetProperty("data").GetProperty("match").GetProperty("rule").GetString()); + Assert.Equal(0, listenPayload.RootElement.GetProperty("data").GetProperty("nlu").GetProperty("entities").EnumerateObject().Count()); + } + + [Fact] + public void ResponsePlanMapper_EscapesSpeechWithoutEncodingApostrophes() + { + var plan = new ResponsePlan + { + IntentName = "chat", + Actions = + { + new SpeakAction + { + Sequence = 0, + Text = "I'm glad you're here.", + Voice = "griffin" + }, + new InvokeNativeSkillAction + { + Sequence = 1, + SkillName = "chitchat-skill", + Payload = new Dictionary() + } + } + }; + + var turn = new TurnContext + { + Attributes = new Dictionary + { + ["transID"] = "trans-apostrophe" + } + }; + + var replies = ResponsePlanToSocketMessagesMapper.Map(plan, turn, new CloudSession(), emitSkillActions: true); + using var payload = JsonDocument.Parse(replies[2].Text); + var esml = payload.RootElement + .GetProperty("data") + .GetProperty("action") + .GetProperty("config") + .GetProperty("jcp") + .GetProperty("config") + .GetProperty("play") + .GetProperty("esml") + .GetString(); + + Assert.Contains("I'm glad you're here.", esml, StringComparison.Ordinal); + Assert.DoesNotContain("'", esml, StringComparison.Ordinal); + } + [Fact] public async Task ClientAsr_OpenTheRadio_EmitsRadioRedirectAndSilentCompletion() {