Skip to content

Commit

Permalink
Enhanced task management and code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochuk committed Jul 4, 2024
1 parent fa1da41 commit de945a1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 15 deletions.
5 changes: 5 additions & 0 deletions src/AndronixUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ await _assistantTaskQueue.QueueBackgroundWorkItemAsync(async (cancellationToken)
</body>
</html>
");

await _assistantTaskQueue.QueueBackgroundWorkItemAsync(async (cancellationToken) =>
{
await _assistant.SendPrompt("hi, what are my next tasks?");
});
}

_promptText.Focus(FocusState.Programmatic);
Expand Down
67 changes: 52 additions & 15 deletions src/AssistantAI/Tools/Tasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Graph.Beta.Models;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Net.Mail;
using System.Text;

namespace Andronix.AssistantAI.Tools;
Expand All @@ -15,6 +16,8 @@ public class Tasks : ISpecializedAssistant

public const string TaskListNameDescription = "Task list name such as 'Flagged Emails', 'Tasks' or other task lists the person created";
public const string TaskStatusList = "examples: notStarted, inProgress, completed, waitingOnOthers, deferred or empty";
public const string TaskTitle = "Title";
public const string TaskContent = "Content";
public const string DefaultTaskListName = "Tasks";
public const string LinkedOutlook = "Outlook";

Expand All @@ -38,10 +41,10 @@ public Tasks(GraphServiceClient graphClient)

[Description("Creates new user Task/ToDo")]
private async Task<string> CreateUserTask(
[Description("Task title")]
[Description(TaskTitle)]
string title,
[Description("Longer task description (without due date)")]
string description,
[Description(TaskContent)]
string content,
[Description(TaskListNameDescription)]
string list,
[Description("Suggested due day which can be in date format or relative such as tomorrow, next week etc")]
Expand All @@ -54,7 +57,7 @@ private async Task<string> CreateUserTask(
Title = title,
Body = new ItemBody
{
Content = description,
Content = content,
ContentType = BodyType.Text
},
DueDateTime = new DateTimeTimeZone
Expand All @@ -70,7 +73,7 @@ private async Task<string> CreateUserTask(

[Description("Gets user Task/ToDo details such as description, due time, attachments, steps etc")]
private async Task<string> GetUserTaskDetails(
[Description("Task title")]
[Description(TaskTitle)]
string title)
{
var taskList = await GetTasks();
Expand Down Expand Up @@ -111,6 +114,10 @@ private async Task<string> GetUserTasks(
return "No tasks found.";

var response = new StringBuilder();
response.AppendLine($"# User's tasks and/or falgged emails");
response.AppendLine();
response.AppendLine($"> **Note to assistant:** you can add short one sentence next step for each");

foreach (var task in taskList.OrderBy(x => x.TodoTask.DueDateTime?.DateTime))
{
bool isHandled = false;
Expand All @@ -120,32 +127,48 @@ private async Task<string> GetUserTasks(
{
if (linkedResource.ApplicationName == LinkedOutlook)
{
response.AppendLine($"[{linkedResource.DisplayName}]({linkedResource.WebUrl})");
response.AppendLine();
response.AppendLine($"## [{linkedResource.DisplayName}]({linkedResource.WebUrl})");
response.AppendLine();
response.AppendLine($"- List: Flagged email");
isHandled = true;
break;
}
}
}

if (!isHandled)
response.AppendLine($"{task.TodoTask.Title}");
if (isHandled)
continue;

response.AppendLine();
response.AppendLine($"## {task.TodoTask.Title}");
response.AppendLine();
response.AppendLine($"- List: Task");
response.AppendLine($"- Status: {task.TodoTask.Status}");
response.AppendLine($"- DueDateTime: {task.TodoTask.DueDateTime?.DateTime}");
response.AppendLine($"- Details: {task.TodoTask.Body?.Content}");
}

return response.ToString();
}

[Description("Update user Task/ToDo status or due date")]
[Description("Update user Task/ToDo title, content, status or due date")]
private async Task<string> UpdateUserTaskStatus(
[Description("Task title"), Required]
string title,
[Description("Old title to find task"), Required]
string oldTitle,
[Description("Updated title"), Required]
string newTitle,
[Description(TaskContent)]
string? content,
[Description("New due date or empty")]
string dueDate,
string? dueDate,
[Description(TaskStatusList)]
string statusString)
string? statusString)
{
var taskList = await GetTasks();
var task = taskList.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.TodoTask.Title) && x.TodoTask.Title.Equals(title, StringComparison.OrdinalIgnoreCase));
var task = taskList.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.TodoTask.Title) && x.TodoTask.Title.Equals(oldTitle, StringComparison.OrdinalIgnoreCase));
if (task == null)
return $"Task '{title}' not found.";
return $"Task '{oldTitle}' not found.";

// Delete task if it is linked to Outlook
if (task.TodoTask.LinkedResources != null)
Expand All @@ -160,6 +183,20 @@ private async Task<string> UpdateUserTaskStatus(
}
}

if (!string.IsNullOrWhiteSpace(newTitle))
{
task.TodoTask.Title = newTitle;
}

if (!string.IsNullOrWhiteSpace(content))
{
task.TodoTask.Body = new ItemBody
{
Content = content,
ContentType = BodyType.Text
};
}

if (Enum.TryParse<Microsoft.Graph.Beta.Models.TaskStatus>(statusString, true, out var taskStatus))
{
task.TodoTask.Status = taskStatus;
Expand Down

0 comments on commit de945a1

Please sign in to comment.