Public Access
Add transcript line workflow rules
PR and Push Build/Test / build-and-test (push) Failing after 13m27s
PR and Push Build/Test / build-and-test (push) Failing after 13m27s
This commit is contained in:
@@ -12,6 +12,11 @@ public interface IMeetingWorkflowEngine
|
||||
MeetingWorkflowEvent workflowEvent,
|
||||
MeetingAssistantOptions options,
|
||||
CancellationToken cancellationToken);
|
||||
|
||||
Task<string> TransformTranscriptLineAsync(
|
||||
MeetingWorkflowEvent workflowEvent,
|
||||
MeetingAssistantOptions options,
|
||||
CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
public sealed class NoopMeetingWorkflowEngine : IMeetingWorkflowEngine
|
||||
@@ -25,6 +30,14 @@ public sealed class NoopMeetingWorkflowEngine : IMeetingWorkflowEngine
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<string> TransformTranscriptLineAsync(
|
||||
MeetingWorkflowEvent workflowEvent,
|
||||
MeetingAssistantOptions options,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.FromResult(workflowEvent.TranscriptLineText ?? "");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MeetingWorkflowEngine : IMeetingWorkflowEngine
|
||||
@@ -39,7 +52,9 @@ public sealed class MeetingWorkflowEngine : IMeetingWorkflowEngine
|
||||
"event.type",
|
||||
"state.from",
|
||||
"state.to",
|
||||
"speaker.name"
|
||||
"speaker.name",
|
||||
"transcript.line",
|
||||
"transcript.speaker"
|
||||
];
|
||||
|
||||
private readonly IMeetingWorkflowRulesProvider rulesProvider;
|
||||
@@ -64,11 +79,35 @@ public sealed class MeetingWorkflowEngine : IMeetingWorkflowEngine
|
||||
MeetingWorkflowEvent workflowEvent,
|
||||
MeetingAssistantOptions options,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
_ = await RunCoreAsync(workflowEvent, options, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<string> TransformTranscriptLineAsync(
|
||||
MeetingWorkflowEvent workflowEvent,
|
||||
MeetingAssistantOptions options,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (workflowEvent.Type != MeetingWorkflowEventType.TranscriptLine)
|
||||
{
|
||||
throw new ArgumentException("Workflow event must be a transcript line event.", nameof(workflowEvent));
|
||||
}
|
||||
|
||||
return await RunCoreAsync(workflowEvent, options, cancellationToken)
|
||||
?? workflowEvent.TranscriptLineText
|
||||
?? "";
|
||||
}
|
||||
|
||||
private async Task<string?> RunCoreAsync(
|
||||
MeetingWorkflowEvent workflowEvent,
|
||||
MeetingAssistantOptions options,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var rules = await rulesProvider.GetRulesAsync(options, cancellationToken);
|
||||
var context = new MeetingWorkflowExecutionContext(workflowEvent);
|
||||
if (rules.Count == 0)
|
||||
{
|
||||
return;
|
||||
return context.TranscriptLine;
|
||||
}
|
||||
|
||||
var meeting = await meetingNoteStore.ReadAsync(
|
||||
@@ -79,7 +118,7 @@ public sealed class MeetingWorkflowEngine : IMeetingWorkflowEngine
|
||||
foreach (var rule in rules)
|
||||
{
|
||||
if (!MatchesTrigger(rule, workflowEvent) ||
|
||||
!EvaluateConditions(rule.If, meeting, workflowEvent))
|
||||
!EvaluateConditions(rule.If, meeting, context))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -88,16 +127,16 @@ public sealed class MeetingWorkflowEngine : IMeetingWorkflowEngine
|
||||
"Applying meeting workflow rule {RuleName} for event {EventType}",
|
||||
rule.Name,
|
||||
workflowEvent.Type);
|
||||
var model = CreateTemplateModel(meeting, workflowEvent);
|
||||
var model = CreateTemplateModel(meeting, context);
|
||||
foreach (var step in rule.Steps)
|
||||
{
|
||||
noteChanged |= await ApplyStepAsync(
|
||||
step,
|
||||
meeting,
|
||||
workflowEvent,
|
||||
context,
|
||||
model,
|
||||
cancellationToken);
|
||||
model = CreateTemplateModel(meeting, workflowEvent);
|
||||
model = CreateTemplateModel(meeting, context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +148,8 @@ public sealed class MeetingWorkflowEngine : IMeetingWorkflowEngine
|
||||
saved,
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
return context.TranscriptLine;
|
||||
}
|
||||
|
||||
private static bool MatchesTrigger(
|
||||
@@ -151,41 +192,51 @@ public sealed class MeetingWorkflowEngine : IMeetingWorkflowEngine
|
||||
StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
if (trigger.TranscriptLine is not null)
|
||||
{
|
||||
return workflowEvent.Type == MeetingWorkflowEventType.TranscriptLine &&
|
||||
(string.IsNullOrWhiteSpace(trigger.TranscriptLine.Speaker) ||
|
||||
string.Equals(
|
||||
trigger.TranscriptLine.Speaker.Trim(),
|
||||
workflowEvent.SpeakerName,
|
||||
StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool EvaluateConditions(
|
||||
IReadOnlyList<MeetingWorkflowCondition> conditions,
|
||||
MeetingNote meeting,
|
||||
MeetingWorkflowEvent workflowEvent)
|
||||
MeetingWorkflowExecutionContext context)
|
||||
{
|
||||
return conditions.Count == 0 ||
|
||||
conditions.All(condition => EvaluateCondition(condition, meeting, workflowEvent));
|
||||
conditions.All(condition => EvaluateCondition(condition, meeting, context));
|
||||
}
|
||||
|
||||
private bool EvaluateCondition(
|
||||
MeetingWorkflowCondition condition,
|
||||
MeetingNote meeting,
|
||||
MeetingWorkflowEvent workflowEvent)
|
||||
MeetingWorkflowExecutionContext context)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(condition.Condition))
|
||||
{
|
||||
return EvaluateExpression(condition.Condition, meeting, workflowEvent);
|
||||
return EvaluateExpression(condition.Condition, meeting, context);
|
||||
}
|
||||
|
||||
if (condition.And is { Count: > 0 })
|
||||
{
|
||||
return condition.And.All(child => EvaluateCondition(child, meeting, workflowEvent));
|
||||
return condition.And.All(child => EvaluateCondition(child, meeting, context));
|
||||
}
|
||||
|
||||
if (condition.Or is { Count: > 0 })
|
||||
{
|
||||
return condition.Or.Any(child => EvaluateCondition(child, meeting, workflowEvent));
|
||||
return condition.Or.Any(child => EvaluateCondition(child, meeting, context));
|
||||
}
|
||||
|
||||
if (condition.Not is not null)
|
||||
{
|
||||
return !EvaluateCondition(condition.Not, meeting, workflowEvent);
|
||||
return !EvaluateCondition(condition.Not, meeting, context);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -194,10 +245,10 @@ public sealed class MeetingWorkflowEngine : IMeetingWorkflowEngine
|
||||
private bool EvaluateExpression(
|
||||
string expressionText,
|
||||
MeetingNote meeting,
|
||||
MeetingWorkflowEvent workflowEvent)
|
||||
MeetingWorkflowExecutionContext context)
|
||||
{
|
||||
var expression = new Expression(PrepareExpression(expressionText));
|
||||
foreach (var (name, value) in BuildParameters(meeting, workflowEvent))
|
||||
foreach (var (name, value) in BuildParameters(meeting, context))
|
||||
{
|
||||
expression.Parameters[name] = value;
|
||||
}
|
||||
@@ -219,7 +270,7 @@ public sealed class MeetingWorkflowEngine : IMeetingWorkflowEngine
|
||||
private async Task<bool> ApplyStepAsync(
|
||||
MeetingWorkflowStep step,
|
||||
MeetingNote meeting,
|
||||
MeetingWorkflowEvent workflowEvent,
|
||||
MeetingWorkflowExecutionContext context,
|
||||
MeetingWorkflowTemplateModel model,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -232,14 +283,17 @@ public sealed class MeetingWorkflowEngine : IMeetingWorkflowEngine
|
||||
return RemoveValue(meeting.Frontmatter.Attendees, value);
|
||||
case "add_project":
|
||||
return AddUnique(meeting.Frontmatter.Projects, value, static project => project.Trim());
|
||||
case "set_property":
|
||||
return SetProperty(meeting, step.Property ?? step.Name, value);
|
||||
case "add_context":
|
||||
await meetingArtifactStore.AppendAssistantContextAsync(
|
||||
workflowEvent.Artifacts,
|
||||
context.Event.Artifacts,
|
||||
value,
|
||||
cancellationToken);
|
||||
return false;
|
||||
case "set_property" when IsTranscriptLineProperty(step.Property ?? step.Name):
|
||||
SetTranscriptLine(context, value);
|
||||
return false;
|
||||
case "set_property":
|
||||
return SetProperty(meeting, step.Property ?? step.Name, value);
|
||||
default:
|
||||
throw new InvalidOperationException($"Unknown meeting workflow step '{step.Uses}'.");
|
||||
}
|
||||
@@ -272,6 +326,28 @@ public sealed class MeetingWorkflowEngine : IMeetingWorkflowEngine
|
||||
throw new InvalidOperationException($"Unsupported meeting workflow property '{property}'.");
|
||||
}
|
||||
|
||||
private static void SetTranscriptLine(
|
||||
MeetingWorkflowExecutionContext context,
|
||||
string value)
|
||||
{
|
||||
if (context.Event.Type != MeetingWorkflowEventType.TranscriptLine)
|
||||
{
|
||||
throw new InvalidOperationException("The transcript.line property can only be set during transcript_line events.");
|
||||
}
|
||||
|
||||
if (string.Equals(context.TranscriptLine, value, StringComparison.Ordinal))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
context.TranscriptLine = value;
|
||||
}
|
||||
|
||||
private static bool IsTranscriptLineProperty(string? property)
|
||||
{
|
||||
return string.Equals(property?.Trim(), "transcript.line", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private static bool AddUnique(
|
||||
List<string> values,
|
||||
string value,
|
||||
@@ -338,8 +414,9 @@ public sealed class MeetingWorkflowEngine : IMeetingWorkflowEngine
|
||||
|
||||
private static IReadOnlyDictionary<string, object?> BuildParameters(
|
||||
MeetingNote meeting,
|
||||
MeetingWorkflowEvent workflowEvent)
|
||||
MeetingWorkflowExecutionContext context)
|
||||
{
|
||||
var workflowEvent = context.Event;
|
||||
return new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["meeting.attendees.count"] = meeting.Frontmatter.Attendees.Count,
|
||||
@@ -350,14 +427,17 @@ public sealed class MeetingWorkflowEngine : IMeetingWorkflowEngine
|
||||
["event.type"] = workflowEvent.Type.ToString(),
|
||||
["state.from"] = workflowEvent.FromState is { } from ? MeetingWorkflowStateNames.ToRuleName(from) : "",
|
||||
["state.to"] = workflowEvent.ToState is { } to ? MeetingWorkflowStateNames.ToRuleName(to) : "",
|
||||
["speaker.name"] = workflowEvent.SpeakerName
|
||||
["speaker.name"] = workflowEvent.SpeakerName,
|
||||
["transcript.line"] = context.TranscriptLine ?? "",
|
||||
["transcript.speaker"] = workflowEvent.SpeakerName ?? ""
|
||||
};
|
||||
}
|
||||
|
||||
private static MeetingWorkflowTemplateModel CreateTemplateModel(
|
||||
MeetingNote meeting,
|
||||
MeetingWorkflowEvent workflowEvent)
|
||||
MeetingWorkflowExecutionContext context)
|
||||
{
|
||||
var workflowEvent = context.Event;
|
||||
return new MeetingWorkflowTemplateModel(
|
||||
new MeetingWorkflowMeetingModel(
|
||||
meeting.Frontmatter.Title,
|
||||
@@ -370,6 +450,22 @@ public sealed class MeetingWorkflowEngine : IMeetingWorkflowEngine
|
||||
workflowEvent.ToState is { } to ? MeetingWorkflowStateNames.ToRuleName(to) : null),
|
||||
string.IsNullOrWhiteSpace(workflowEvent.SpeakerName)
|
||||
? null
|
||||
: new MeetingWorkflowSpeakerModel(workflowEvent.SpeakerName));
|
||||
: new MeetingWorkflowSpeakerModel(workflowEvent.SpeakerName),
|
||||
new MeetingWorkflowTranscriptModel(
|
||||
context.TranscriptLine ?? "",
|
||||
workflowEvent.SpeakerName ?? ""));
|
||||
}
|
||||
|
||||
private sealed class MeetingWorkflowExecutionContext
|
||||
{
|
||||
public MeetingWorkflowExecutionContext(MeetingWorkflowEvent workflowEvent)
|
||||
{
|
||||
Event = workflowEvent;
|
||||
TranscriptLine = workflowEvent.TranscriptLineText;
|
||||
}
|
||||
|
||||
public MeetingWorkflowEvent Event { get; }
|
||||
|
||||
public string? TranscriptLine { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user