Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agents - Introduce agent system app to v25.x #2458

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------

namespace System.Agents;

codeunit 4307 "Agent Message"
{
InherentEntitlements = X;
InherentPermissions = X;

/// <summary>
/// Get the message text for the given agent task message.
/// </summary>
/// <param name="AgentTaskMessage">Agent task message.</param>
/// <returns>The body of the agent task message.</returns>
[Scope('OnPrem')]
procedure GetText(var AgentTaskMessage: Record "Agent Task Message"): Text
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
exit(AgentMessageImpl.GetMessageText(AgentTaskMessage));
end;

/// <summary>
/// Updates the message text.
/// </summary>
/// <param name="AgentTaskMessage">The message record to update.</param>
/// <param name="NewMessageText">New message text to set.</param>
[Scope('OnPrem')]
procedure UpdateText(var AgentTaskMessage: Record "Agent Task Message"; NewMessageText: Text)
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
AgentMessageImpl.UpdateText(AgentTaskMessage, NewMessageText);
end;

/// <summary>
/// Check if it is possible to edit the message.
/// </summary>
/// <param name="AgentTaskMessage">Agent task message to verify.</param>
/// <returns>If it is possible to change the message.</returns>
[Scope('OnPrem')]
procedure IsEditable(var AgentTaskMessage: Record "Agent Task Message"): Boolean
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
exit(AgentMessageImpl.IsMessageEditable(AgentTaskMessage));
end;

/// <summary>
/// Sets the message status to sent.
/// </summary>
/// <param name="AgentTaskMessage">Agent task message to update status.</param>
[Scope('OnPrem')]
procedure SetStatusToSent(var AgentTaskMessage: Record "Agent Task Message")
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
AgentMessageImpl.SetStatusToSent(AgentTaskMessage);
end;

/// <summary>
/// Downloads the attachments for a specific message.
/// </summary>
/// <param name="AgentTaskMessage">Message to download attachments for.</param>
[Scope('OnPrem')]
procedure DownloadAttachments(var AgentTaskMessage: Record "Agent Task Message")
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
AgentMessageImpl.DownloadAttachments(AgentTaskMessage);
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------

namespace System.Agents;

codeunit 4308 "Agent Message Impl."
{
Access = Internal;
InherentEntitlements = X;
InherentPermissions = X;

procedure GetMessageText(var AgentTaskMessage: Record "Agent Task Message"): Text
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
ContentInStream: InStream;
ContentText: Text;
begin
AgentTaskMessage.CalcFields(Content);
AgentTaskMessage.Content.CreateInStream(ContentInStream, AgentTaskImpl.GetDefaultEncoding());
ContentInStream.Read(ContentText);
exit(ContentText);
end;

procedure UpdateText(var AgentTaskMessage: Record "Agent Task Message"; NewMessageText: Text)
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
ContentOutStream: OutStream;
begin
Clear(AgentTaskMessage.Content);
AgentTaskMessage.Content.CreateOutStream(ContentOutStream, AgentTaskImpl.GetDefaultEncoding());
ContentOutStream.Write(NewMessageText);
AgentTaskMessage.Modify(true);
end;

procedure IsMessageEditable(var AgentTaskMessage: Record "Agent Task Message"): Boolean
begin
if AgentTaskMessage.Type <> AgentTaskMessage.Type::Output then
exit(false);

exit(AgentTaskMessage.Status = AgentTaskMessage.Status::Draft);
end;

procedure SetStatusToSent(var AgentTaskMessage: Record "Agent Task Message")
begin
UpdateAgentTaskMessageStatus(AgentTaskMessage, AgentTaskMessage.Status::Sent);
end;

procedure DownloadAttachments(var AgentTaskMessage: Record "Agent Task Message")
var
AgentTaskFile: Record "Agent Task File";
AgentTaskMessageAttachment: Record "Agent Task Message Attachment";
AgentTaskImpl: Codeunit "Agent Task Impl.";
InStream: InStream;
FileName: Text;
DownloadDialogTitleLbl: Label 'Download Email Attachment';
begin
AgentTaskMessageAttachment.SetRange("Task ID", AgentTaskMessage."Task ID");
AgentTaskMessageAttachment.SetRange("Message ID", AgentTaskMessage.ID);
if not AgentTaskMessageAttachment.FindSet() then
exit;

repeat
if not AgentTaskFile.Get(AgentTaskMessageAttachment."Task ID", AgentTaskMessageAttachment."File ID") then
exit;

FileName := AgentTaskFile."File Name";
AgentTaskFile.CalcFields(Content);
AgentTaskFile.Content.CreateInStream(InStream, AgentTaskImpl.GetDefaultEncoding());
File.DownloadFromStream(InStream, DownloadDialogTitleLbl, '', '', FileName);
until AgentTaskMessageAttachment.Next() = 0;
end;

procedure UpdateAgentTaskMessageStatus(var AgentTaskMessage: Record "Agent Task Message"; Status: Option)
begin
AgentTaskMessage.Status := Status;
AgentTaskMessage.Modify(true);
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------

namespace System.Agents;

codeunit 4303 "Agent Task"
{
InherentEntitlements = X;
InherentPermissions = X;

/// <summary>
/// Check if a task exists for the given agent user and conversation
/// </summary>
/// <param name="AgentUserSecurityID">The user security ID of the agent.</param>
/// <param name="ConversationId">The conversation ID to check.</param>
/// <returns>True if task exists, false if not.</returns>
[Scope('OnPrem')]
procedure TaskExists(AgentUserSecurityId: Guid; ConversationId: Text): Boolean
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
exit(AgentTaskImpl.TaskExists(AgentUserSecurityId, ConversationId));
end;

/// <summary>
/// Create a new task message for the given agent user and conversation.
/// If task does not exist, it will be created.
/// </summary>
/// <param name="From">Specifies from address.</param>
/// <param name="MessageText">The message text for the task.</param>
/// <param name="CurrentAgentTask">Current Agent Task to which the message will be added.</param>
[Scope('OnPrem')]
procedure CreateTaskMessage(From: Text[250]; MessageText: Text; ExternalMessageId: Text[2048]; var CurrentAgentTask: Record "Agent Task")
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
AgentTaskImpl.CreateTaskMessage(From, MessageText, ExternalMessageId, CurrentAgentTask);
end;
}
Loading
Loading