Add sleep and spin-around global command handling

This commit is contained in:
Jacob Dubin
2026-05-17 23:38:29 -05:00
parent 51e36bc492
commit e588f00c43
9 changed files with 371 additions and 3 deletions

View File

@@ -101,6 +101,11 @@ public sealed class LegacyMimCatalogImporterTests
catalog.PersonalityReplies);
Assert.Contains("I was put together in a factory piece by piece.", catalog.PersonalityReplies);
Assert.Contains("I really like sunflowers.", catalog.PersonalityReplies);
Assert.Contains(catalog.PersonalityReplies, reply =>
reply.Contains("I do. I usually fall asleep at night.", StringComparison.OrdinalIgnoreCase));
Assert.Contains(catalog.PersonalityReplies, reply =>
reply.Contains("go to sleep", StringComparison.OrdinalIgnoreCase));
Assert.Contains("Don't mind if I do.", catalog.PersonalityReplies);
Assert.Contains("Ha. Of course I know R2D2. I mean, not personally.", catalog.PersonalityReplies);
Assert.Contains("Yes! I like all things in space. They're so spacey.", catalog.PersonalityReplies);
Assert.Contains("Yes yes, I think kids are great. They're a little closer to my size.",

View File

@@ -3096,6 +3096,56 @@ public sealed class JiboInteractionServiceTests
Assert.Equal("global_commands", decision.SkillPayload["nluDomain"]);
}
[Fact]
public async Task BuildDecisionAsync_CanYouGoToSleep_UsesSourceBackedSleepReply()
{
var service = CreateService();
var decision = await service.BuildDecisionAsync(new TurnContext
{
RawTranscript = "can you go to sleep",
NormalizedTranscript = "can you go to sleep"
});
Assert.Equal("robot_can_sleep", decision.IntentName);
Assert.Contains("I do. I usually fall asleep at night.", decision.ReplyText, StringComparison.OrdinalIgnoreCase);
Assert.Equal("ScriptedResponse", decision.ContextUpdates![ChitchatRouteKey]);
}
[Fact]
public async Task BuildDecisionAsync_GoToSleep_MapsToIdleSleepCommand()
{
var service = CreateService();
var decision = await service.BuildDecisionAsync(new TurnContext
{
RawTranscript = "go to sleep",
NormalizedTranscript = "go to sleep"
});
Assert.Equal("sleep", decision.IntentName);
Assert.Equal("@be/idle", decision.SkillName);
Assert.Equal("sleep", decision.SkillPayload!["globalIntent"]);
Assert.Equal("global_commands", decision.SkillPayload["nluDomain"]);
}
[Fact]
public async Task BuildDecisionAsync_TurnAround_MapsToIdleSpinAroundCommand()
{
var service = CreateService();
var decision = await service.BuildDecisionAsync(new TurnContext
{
RawTranscript = "turn around",
NormalizedTranscript = "turn around"
});
Assert.Equal("spin_around", decision.IntentName);
Assert.Equal("@be/idle", decision.SkillName);
Assert.Equal("spinAround", decision.SkillPayload!["globalIntent"]);
Assert.Equal("global_commands", decision.SkillPayload["nluDomain"]);
}
[Fact]
public async Task BuildDecisionAsync_NeverMindWithPunctuation_MapsToIdleStopCommand()
{

View File

@@ -2831,6 +2831,90 @@ public sealed class JiboWebSocketServiceTests
redirectPayload.RootElement.GetProperty("data").GetProperty("nlu").GetProperty("intent").GetString());
}
[Fact]
public async Task ClientAsr_GoToSleep_EmitsIdleSleepRedirect()
{
await _service.HandleMessageAsync(new WebSocketMessageEnvelope
{
HostName = "neo-hub.jibo.com",
Path = "/listen",
Kind = "neo-hub-listen",
Token = "hub-sleep-token",
Text =
"""{"type":"LISTEN","transID":"trans-sleep","data":{"hotphrase":true,"rules":["launch","globals/global_commands_launch"]}}"""
});
var replies = await _service.HandleMessageAsync(new WebSocketMessageEnvelope
{
HostName = "neo-hub.jibo.com",
Path = "/listen",
Kind = "neo-hub-listen",
Token = "hub-sleep-token",
Text = """{"type":"CLIENT_ASR","transID":"trans-sleep","data":{"text":"go to sleep"}}"""
});
Assert.Equal(5, replies.Count);
Assert.Equal("LISTEN", ReadReplyType(replies[0]));
Assert.Equal("EOS", ReadReplyType(replies[1]));
Assert.Equal("SKILL_REDIRECT", ReadReplyType(replies[2]));
Assert.Equal("SKILL_ACTION", ReadReplyType(replies[3]));
Assert.Equal("SKILL_ACTION", ReadReplyType(replies[4]));
using var listenPayload = JsonDocument.Parse(replies[0].Text!);
var nlu = listenPayload.RootElement.GetProperty("data").GetProperty("nlu");
Assert.Equal("sleep", nlu.GetProperty("intent").GetString());
Assert.Equal("global_commands", nlu.GetProperty("domain").GetString());
Assert.Equal("globals/global_commands_launch", nlu.GetProperty("rules")[0].GetString());
using var redirectPayload = JsonDocument.Parse(replies[2].Text!);
Assert.Equal("@be/idle",
redirectPayload.RootElement.GetProperty("data").GetProperty("match").GetProperty("skillID").GetString());
Assert.Equal("sleep",
redirectPayload.RootElement.GetProperty("data").GetProperty("nlu").GetProperty("intent").GetString());
}
[Fact]
public async Task ClientAsr_TurnAround_EmitsIdleSpinAroundRedirect()
{
await _service.HandleMessageAsync(new WebSocketMessageEnvelope
{
HostName = "neo-hub.jibo.com",
Path = "/listen",
Kind = "neo-hub-listen",
Token = "hub-spin-token",
Text =
"""{"type":"LISTEN","transID":"trans-spin","data":{"hotphrase":true,"rules":["launch","globals/global_commands_launch"]}}"""
});
var replies = await _service.HandleMessageAsync(new WebSocketMessageEnvelope
{
HostName = "neo-hub.jibo.com",
Path = "/listen",
Kind = "neo-hub-listen",
Token = "hub-spin-token",
Text = """{"type":"CLIENT_ASR","transID":"trans-spin","data":{"text":"turn around"}}"""
});
Assert.Equal(5, replies.Count);
Assert.Equal("LISTEN", ReadReplyType(replies[0]));
Assert.Equal("EOS", ReadReplyType(replies[1]));
Assert.Equal("SKILL_REDIRECT", ReadReplyType(replies[2]));
Assert.Equal("SKILL_ACTION", ReadReplyType(replies[3]));
Assert.Equal("SKILL_ACTION", ReadReplyType(replies[4]));
using var listenPayload = JsonDocument.Parse(replies[0].Text!);
var nlu = listenPayload.RootElement.GetProperty("data").GetProperty("nlu");
Assert.Equal("spinAround", nlu.GetProperty("intent").GetString());
Assert.Equal("global_commands", nlu.GetProperty("domain").GetString());
Assert.Equal("globals/global_commands_launch", nlu.GetProperty("rules")[0].GetString());
using var redirectPayload = JsonDocument.Parse(replies[2].Text!);
Assert.Equal("@be/idle",
redirectPayload.RootElement.GetProperty("data").GetProperty("match").GetProperty("skillID").GetString());
Assert.Equal("spinAround",
redirectPayload.RootElement.GetProperty("data").GetProperty("nlu").GetProperty("intent").GetString());
}
[Fact]
public async Task ClientAsr_TurnItDown_EmitsGlobalVolumeDownWithoutCloudSpeech()
{