more refactors

This commit is contained in:
Jacob Dubin
2026-05-21 07:31:11 -05:00
parent c4c512497c
commit 2bf686f791
2 changed files with 45 additions and 40 deletions

View File

@@ -1,15 +1,26 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=ampm/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=ampm/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Arrrr/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Arrrr/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=bday/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=bleebo/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=didn/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=didnt/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=dont/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=esml/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=esml/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Hotphrase/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Hotphrase/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Jibo/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Jibo/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=jiboji/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=jibos/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Jibo_0027s/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Jibo_0027s/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=mult/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=multichunk/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=multichunk/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=nevermind/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=nevermind/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=noinput/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=noinput/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=onomies/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=openjibo/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=openjibo/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Photobooth/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Photobooth/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=photogal/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=roboting/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=slnx/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=slnx/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=slowdance/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=slowdance/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=timecoded/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=timecoded/@EntryIndexedValue">True</s:Boolean>

View File

@@ -518,7 +518,7 @@ public sealed class JiboInteractionService(
randomizer, randomizer,
selected => RenderHolidayTemplate(selected, turn, greetingPresence), selected => RenderHolidayTemplate(selected, turn, greetingPresence),
out var seasonalHolidayDecision)) out var seasonalHolidayDecision))
return seasonalHolidayDecision; return seasonalHolidayDecision!;
return semanticIntent switch return semanticIntent switch
{ {
@@ -943,11 +943,10 @@ public sealed class JiboInteractionService(
[ChitchatStateMachine.RouteMetadataKey] = "ScriptedResponse", [ChitchatStateMachine.RouteMetadataKey] = "ScriptedResponse",
[ChitchatStateMachine.EmotionMetadataKey] = string.Empty, [ChitchatStateMachine.EmotionMetadataKey] = string.Empty,
[GreetingRouteMetadataKey] = route, [GreetingRouteMetadataKey] = route,
[GreetingSpeakerMetadataKey] = speakerId ?? string.Empty [GreetingSpeakerMetadataKey] = speakerId ?? string.Empty,
[proactive ? LastProactiveGreetingUtcMetadataKey : LastReactiveGreetingUtcMetadataKey] = DateTimeOffset.UtcNow.ToString("O", CultureInfo.InvariantCulture)
}; };
updates[proactive ? LastProactiveGreetingUtcMetadataKey : LastReactiveGreetingUtcMetadataKey] =
DateTimeOffset.UtcNow.ToString("O", CultureInfo.InvariantCulture);
return updates; return updates;
} }
@@ -1263,6 +1262,7 @@ public sealed class JiboInteractionService(
private static JiboInteractionDecision BuildProactivePizzaFactOfferDecision() private static JiboInteractionDecision BuildProactivePizzaFactOfferDecision()
{ {
var listenContexts = new[] { "shared/yes_no" };
return new JiboInteractionDecision( return new JiboInteractionDecision(
"proactive_offer_pizza_fact", "proactive_offer_pizza_fact",
"Do you want to hear a fun pizza fact?", "Do you want to hear a fun pizza fact?",
@@ -1273,7 +1273,7 @@ public sealed class JiboInteractionService(
["mim_type"] = "question", ["mim_type"] = "question",
["prompt_id"] = "RUNTIME_PROMPT", ["prompt_id"] = "RUNTIME_PROMPT",
["prompt_sub_category"] = "Q", ["prompt_sub_category"] = "Q",
["listen_contexts"] = new[] { "shared/yes_no" } ["listen_contexts"] = listenContexts
}); });
} }
@@ -1339,7 +1339,7 @@ public sealed class JiboInteractionService(
"No problem. We can save the pizza fact for another time."); "No problem. We can save the pizza fact for another time.");
} }
private JiboInteractionDecision BuildCurrentLocationDecision(TurnContext turn) private static JiboInteractionDecision BuildCurrentLocationDecision(TurnContext turn)
{ {
var locationName = TryResolveCurrentLocationName(turn); var locationName = TryResolveCurrentLocationName(turn);
if (string.IsNullOrWhiteSpace(locationName)) if (string.IsNullOrWhiteSpace(locationName))
@@ -1660,19 +1660,19 @@ public sealed class JiboInteractionService(
var template = ChooseCommuteTemplate(snapshot, catalog, mode); var template = ChooseCommuteTemplate(snapshot, catalog, mode);
var reply = RenderCommuteTemplate(template, durationText, minutesLeftText); var reply = RenderCommuteTemplate(template, durationText, minutesLeftText);
if (minutesLeft > 0 && minutesLeft < 30) if (minutesLeft is > 0 and < 30)
{ {
var minutesTemplate = ChooseShortestTemplate(catalog.CommuteMinutesLeftReplies) var minutesTemplate = ChooseShortestTemplate(catalog.CommuteMinutesLeftReplies)
?? "That's in about ${skill.commute.minsLeft} minutes."; ?? "That's in about ${skill.commute.minsLeft} minutes.";
reply = $"{reply} {RenderCommuteTemplate(minutesTemplate, durationText, minutesLeftText)}"; reply = $"{reply} {RenderCommuteTemplate(minutesTemplate, durationText, minutesLeftText)}";
} }
if (minutesLeft > 0 && minutesLeft < 120) if (minutesLeft is <= 0 or >= 120)
{ return reply.Replace(" ", " ", StringComparison.Ordinal).Trim();
var departTemplate = ChooseCommuteDepartTimeTemplate(snapshot, catalog, mode);
if (!string.IsNullOrWhiteSpace(departTemplate)) var departTemplate = ChooseCommuteDepartTimeTemplate(snapshot, catalog, mode);
reply = $"{reply} {RenderCommuteTemplate(departTemplate, durationText, minutesLeftText)}"; if (!string.IsNullOrWhiteSpace(departTemplate))
} reply = $"{reply} {RenderCommuteTemplate(departTemplate, durationText, minutesLeftText)}";
return reply.Replace(" ", " ", StringComparison.Ordinal).Trim(); return reply.Replace(" ", " ", StringComparison.Ordinal).Trim();
} }
@@ -1691,9 +1691,9 @@ public sealed class JiboInteractionService(
var minutesUntilWork = snapshot.MinutesUntilWork; var minutesUntilWork = snapshot.MinutesUntilWork;
var extraMinutes = Math.Max(0, snapshot.ExtraMinutes); var extraMinutes = Math.Max(0, snapshot.ExtraMinutes);
var isLate = minutesUntilWork <= 0; var isLate = minutesUntilWork <= 0;
var isHurry = minutesUntilWork > 0 && minutesUntilWork <= 10; var isHurry = minutesUntilWork is > 0 and <= 10;
var isNormal = !isLate && !isHurry; var isNormal = !isLate && !isHurry;
var isFarAway = minutesUntilWork > 120 || minutesUntilWork < -30; var isFarAway = minutesUntilWork is > 120 or < -30;
var hasTrafficSeverity = minutesUntilWork > 0; var hasTrafficSeverity = minutesUntilWork > 0;
var isTerrible = hasTrafficSeverity && extraMinutes >= 15; var isTerrible = hasTrafficSeverity && extraMinutes >= 15;
var isPoor = hasTrafficSeverity && extraMinutes >= 5; var isPoor = hasTrafficSeverity && extraMinutes >= 5;
@@ -1796,7 +1796,7 @@ public sealed class JiboInteractionService(
var resolvedReference = referenceLocalTime ?? DateTimeOffset.UtcNow; var resolvedReference = referenceLocalTime ?? DateTimeOffset.UtcNow;
var referenceDate = resolvedReference.Date; var referenceDate = resolvedReference.Date;
return snapshots return [.. snapshots
.OrderBy(static item => item.DayOffset) .OrderBy(static item => item.DayOffset)
.Take(MaxWeatherForecastDayOffset) .Take(MaxWeatherForecastDayOffset)
.Select(item => .Select(item =>
@@ -1823,8 +1823,7 @@ public sealed class JiboInteractionService(
unit, unit,
temperatureBand, temperatureBand,
spokenLine); spokenLine);
}) })];
.ToArray();
} }
private static IDictionary<string, object?> BuildWeeklyWeatherSkillPayload( private static IDictionary<string, object?> BuildWeeklyWeatherSkillPayload(
@@ -2114,7 +2113,7 @@ public sealed class JiboInteractionService(
return rendered; return rendered;
} }
private string ChooseWeatherServiceDownReply(JiboExperienceCatalog catalog) private static string ChooseWeatherServiceDownReply(JiboExperienceCatalog catalog)
{ {
var template = ChooseWeatherTemplate( var template = ChooseWeatherTemplate(
catalog.WeatherServiceDownReplies, catalog.WeatherServiceDownReplies,
@@ -2122,7 +2121,7 @@ public sealed class JiboInteractionService(
return template.Trim(); return template.Trim();
} }
private string ChooseCommuteServiceDownReply(JiboExperienceCatalog catalog) private static string ChooseCommuteServiceDownReply(JiboExperienceCatalog catalog)
{ {
var template = ChooseWeatherTemplate( var template = ChooseWeatherTemplate(
catalog.CommuteServiceDownReplies, catalog.CommuteServiceDownReplies,
@@ -2195,7 +2194,7 @@ public sealed class JiboInteractionService(
? filtered.OrderBy(static template => template.Length).First() ? filtered.OrderBy(static template => template.Length).First()
: templates.OrderBy(static template => template.Length).FirstOrDefault(); : templates.OrderBy(static template => template.Length).FirstOrDefault();
return string.IsNullOrWhiteSpace(selected) ? fallback : selected!; return string.IsNullOrWhiteSpace(selected) ? fallback : selected;
} }
private string ChooseCalendarNothingReply(JiboExperienceCatalog catalog) private string ChooseCalendarNothingReply(JiboExperienceCatalog catalog)
@@ -2441,7 +2440,7 @@ public sealed class JiboInteractionService(
["news_provider_status"] = status, ["news_provider_status"] = status,
["news_provider_requested_headlines"] = requestedHeadlineCount, ["news_provider_requested_headlines"] = requestedHeadlineCount,
["news_provider_preferred_categories"] = preferredCategories.Count > 0 ["news_provider_preferred_categories"] = preferredCategories.Count > 0
? preferredCategories.ToArray() ? [.. preferredCategories]
: Array.Empty<string>() : Array.Empty<string>()
}; };
@@ -2537,7 +2536,7 @@ public sealed class JiboInteractionService(
foreach (var category in MapNewsCategoryText(item)) AddNewsCategory(categories, category); foreach (var category in MapNewsCategoryText(item)) AddNewsCategory(categories, category);
} }
return categories.Take(MaxPreferredNewsCategories).ToList(); return [.. categories.Take(MaxPreferredNewsCategories)];
} }
private static IEnumerable<string> MapNewsCategoryText(string text) private static IEnumerable<string> MapNewsCategoryText(string text)
@@ -2596,7 +2595,7 @@ public sealed class JiboInteractionService(
var pizzaSignal = ResolvePizzaSignal(tenantScope); var pizzaSignal = ResolvePizzaSignal(tenantScope);
if (pizzaSignal.Affinity == PersonalAffinity.Dislike) return candidates; if (pizzaSignal.Affinity == PersonalAffinity.Dislike) return candidates;
if (referenceDate.Month == 2 && referenceDate.Day == 9) if (referenceDate is { Month: 2, Day: 9 })
{ {
var holidayWeight = pizzaSignal.Affinity switch var holidayWeight = pizzaSignal.Affinity switch
{ {
@@ -4096,7 +4095,7 @@ public sealed class JiboInteractionService(
return false; return false;
} }
private static YesNoReply TryClassifyTrailingYesNoReply(IReadOnlyList<string> tokens) private static YesNoReply TryClassifyTrailingYesNoReply(string[] tokens)
{ {
var selectedReply = YesNoReply.None; var selectedReply = YesNoReply.None;
var selectedIndex = -1; var selectedIndex = -1;
@@ -4109,7 +4108,7 @@ public sealed class JiboInteractionService(
selectedIndex = candidateIndex; selectedIndex = candidateIndex;
} }
for (var index = 0; index < tokens.Count; index += 1) for (var index = 0; index < tokens.Length; index += 1)
{ {
var token = tokens[index]; var token = tokens[index];
if (YesNoNegativeLeadTokens.Contains(token)) if (YesNoNegativeLeadTokens.Contains(token))
@@ -4121,7 +4120,7 @@ public sealed class JiboInteractionService(
if (YesNoAffirmativeLeadTokens.Contains(token)) Consider(YesNoReply.Affirmative, index); if (YesNoAffirmativeLeadTokens.Contains(token)) Consider(YesNoReply.Affirmative, index);
} }
for (var index = 0; index + 1 < tokens.Count; index += 1) for (var index = 0; index + 1 < tokens.Length; index += 1)
{ {
var phrase = $"{tokens[index]} {tokens[index + 1]}"; var phrase = $"{tokens[index]} {tokens[index + 1]}";
if (YesNoNegativeLeadPhrases.Contains(phrase)) if (YesNoNegativeLeadPhrases.Contains(phrase))
@@ -4133,7 +4132,7 @@ public sealed class JiboInteractionService(
if (YesNoAffirmativeLeadPhrases.Contains(phrase)) Consider(YesNoReply.Affirmative, index + 1); if (YesNoAffirmativeLeadPhrases.Contains(phrase)) Consider(YesNoReply.Affirmative, index + 1);
} }
for (var index = 0; index + 2 < tokens.Count; index += 1) for (var index = 0; index + 2 < tokens.Length; index += 1)
{ {
var phrase = $"{tokens[index]} {tokens[index + 1]} {tokens[index + 2]}"; var phrase = $"{tokens[index]} {tokens[index + 1]} {tokens[index + 2]}";
if (YesNoNegativeLeadPhrases.Contains(phrase)) if (YesNoNegativeLeadPhrases.Contains(phrase))
@@ -4721,7 +4720,7 @@ public sealed class JiboInteractionService(
dayOffset = ((int)DayOfWeek.Saturday - (int)referenceLocalTime.DayOfWeek + 7) % 7; dayOffset = ((int)DayOfWeek.Saturday - (int)referenceLocalTime.DayOfWeek + 7) % 7;
if (hasNextWeekend) if (hasNextWeekend)
{ {
dayOffset = dayOffset + 7; dayOffset += 7;
leadIn = "Next weekend"; leadIn = "Next weekend";
} }
else else
@@ -4967,16 +4966,11 @@ public sealed class JiboInteractionService(
"my bday is " "my bday is "
}; };
foreach (var marker in markers) return (from marker in markers
{ let markerIndex = normalized.IndexOf(marker, StringComparison.Ordinal)
var markerIndex = normalized.IndexOf(marker, StringComparison.Ordinal); where markerIndex >= 0
if (markerIndex < 0) continue; select normalized[(markerIndex + marker.Length)..].Trim())
.FirstOrDefault(value => !string.IsNullOrWhiteSpace(value));
var value = normalized[(markerIndex + marker.Length)..].Trim();
if (!string.IsNullOrWhiteSpace(value)) return value;
}
return null;
} }
private static bool IsPreferenceRecallQuestion(string loweredTranscript) private static bool IsPreferenceRecallQuestion(string loweredTranscript)
@@ -5762,7 +5756,7 @@ public sealed class JiboInteractionService(
public static GreetingPresenceProfile Empty { get; } = new( public static GreetingPresenceProfile Empty { get; } = new(
null, null,
null, null,
Array.Empty<string>(), [],
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)); new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase));
public bool HasKnownIdentity => !string.IsNullOrWhiteSpace(PrimaryPersonId); public bool HasKnownIdentity => !string.IsNullOrWhiteSpace(PrimaryPersonId);