-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathAgentTask.Codeunit.al
More file actions
154 lines (139 loc) · 6.18 KB
/
AgentTask.Codeunit.al
File metadata and controls
154 lines (139 loc) · 6.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// ------------------------------------------------------------------------------------------------
// 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;
using System.Environment;
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="ExternalId">The external ID to check.</param>
/// <returns>True if task exists, false if not.</returns>
procedure TaskExists(AgentUserSecurityId: Guid; ExternalId: Text): Boolean
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
FeatureAccessManagement.AgentTaskManagementPreviewEnabled(true);
exit(AgentTaskImpl.TaskExists(AgentUserSecurityId, ExternalId));
end;
/// <summary>
/// Get the task for the given agent user and external ID.
/// </summary>
/// <param name="AgentUserSecurityId">The agent user ID.</param>
/// <param name="ExternalId">The external ID of the task.</param>
/// <returns>A record with the given task.</returns>
procedure GetTaskByExternalId(AgentUserSecurityId: Guid; ExternalId: Text): Record "Agent Task"
var
AgentTask: Record "Agent Task";
begin
FeatureAccessManagement.AgentTaskManagementPreviewEnabled(true);
AgentTask.SetRange("Agent User Security ID", AgentUserSecurityId);
AgentTask.SetRange("External ID", ExternalId);
AgentTask.FindFirst();
exit(AgentTask);
end;
/// <summary>
/// Set the status of the task to ready if the task is in the state that it can be started again.
/// The agent task will be be picked up for processing shortly after updating the status.
/// </summary>
/// <param name="AgentTask">The agent task to set to ready.</param>
/// <returns>The agent task with the status set to ready.</returns>
procedure SetStatusToReady(var AgentTask: Record "Agent Task")
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
FeatureAccessManagement.AgentTaskManagementPreviewEnabled(true);
AgentTaskImpl.SetTaskStatusToReadyIfPossible(AgentTask);
end;
/// <summary>
/// Checks if the task can be set to ready and started again.
/// </summary>
/// <param name="AgentTask">The agent task to check.</param>
/// <returns>True if agent task can be set to ready, false otherwise</returns>
procedure CanSetStatusToReady(AgentTask: Record "Agent Task"): Boolean
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
FeatureAccessManagement.AgentTaskManagementPreviewEnabled(true);
exit(AgentTaskImpl.CanAgentTaskBeSetToReady(AgentTask));
end;
/// <summary>
/// Stops the agent task.
/// </summary>
/// <param name="AgentTask">The agent task to stop.</param>
/// <param name="UserConfirm">Whether to show a confirmation dialog to the user.</param>
procedure StopTask(var AgentTask: Record "Agent Task"; UserConfirm: Boolean)
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
TaskStatus: Enum "Agent Task Status";
begin
FeatureAccessManagement.AgentTaskManagementPreviewEnabled(true);
AgentTaskImpl.StopTask(AgentTask, TaskStatus::"Stopped by User", UserConfirm);
end;
/// <summary>
/// Restarts the agent task by setting its status to ready.
/// </summary>
/// <param name="AgentTask">The agent task to restart.</param>
/// <param name="UserConfirm">Whether to show a confirmation dialog to the user.</param>
procedure RestartTask(var AgentTask: Record "Agent Task"; UserConfirm: Boolean)
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
FeatureAccessManagement.AgentTaskManagementPreviewEnabled(true);
AgentTaskImpl.RestartTask(AgentTask, UserConfirm);
end;
/// <summary>
/// Checks if the agent task is currently running.
/// </summary>
/// <param name="AgentTask">The agent task to check.</param>
/// <returns>True if the task is running, false otherwise.</returns>
procedure IsTaskRunning(var AgentTask: Record "Agent Task"): Boolean
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
FeatureAccessManagement.AgentTaskManagementPreviewEnabled(true);
exit(AgentTaskImpl.IsTaskRunning(AgentTask));
end;
/// <summary>
/// Checks if the agent task is completed.
/// </summary>
/// <param name="AgentTask">The agent task to check.</param>
/// <returns>True if the task is completed, false otherwise.</returns>
procedure IsTaskCompleted(var AgentTask: Record "Agent Task"): Boolean
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
FeatureAccessManagement.AgentTaskManagementPreviewEnabled(true);
exit(AgentTaskImpl.IsTaskCompleted(AgentTask));
end;
/// <summary>
/// Checks if the agent task is stopped (by user or system).
/// </summary>
/// <param name="AgentTask">The agent task to check.</param>
/// <returns>True if the task is stopped, false otherwise.</returns>
procedure IsTaskStopped(var AgentTask: Record "Agent Task"): Boolean
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
FeatureAccessManagement.AgentTaskManagementPreviewEnabled(true);
exit(AgentTaskImpl.IsTaskStopped(AgentTask));
end;
/// <summary>
/// Gets the total Copilot credits consumed by the agent task.
/// </summary>
/// <param name="AgentTaskID">The ID of the agent task to get consumed credits for.</param>
/// <returns>The total Copilot credits consumed by the agent task.</returns>
procedure GetCopilotCreditsConsumed(AgentTaskID: BigInteger): Decimal
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
exit(AgentTaskImpl.GetCopilotCreditsConsumed(AgentTaskID));
end;
var
FeatureAccessManagement: Codeunit "Feature Access Management";
}