Skip to content
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
2 changes: 1 addition & 1 deletion src/System Application/App/AI/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"idRanges": [
{
"from": 7757,
"to": 7782
"to": 7786
}
],
"target": "OnPrem",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,22 @@ codeunit 7774 "Copilot Capability Impl"
end;

procedure GetCapabilityName(): Text
begin
CheckCapabilitySet();

exit(CapabilityToEnumName(CopilotSettings.Capability));
end;

procedure CapabilityToEnumName(CopilotCapability: Enum "Copilot Capability"): Text
var
CapabilityIndex: Integer;
CapabilityName: Text;
begin
CheckCapabilitySet();

CapabilityIndex := CopilotSettings.Capability.Ordinals.IndexOf(CopilotSettings.Capability.AsInteger());
CapabilityName := CopilotSettings.Capability.Names.Get(CapabilityIndex);
CapabilityIndex := CopilotCapability.Ordinals.IndexOf(CopilotCapability.AsInteger());
CapabilityName := CopilotCapability.Names.Get(CapabilityIndex);

if CapabilityName.Trim() = '' then
exit(Format(CopilotSettings.Capability, 0, 9));
exit(Format(CopilotCapability, 0, 9));

exit(CapabilityName);
end;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------
namespace System.AI;

/// <summary>
/// Codeunit that exposes functionality related to Copilot Quota, such as logging quota usage
/// </summary>
codeunit 7785 "Copilot Quota"
{
Access = Public;
InherentEntitlements = X;
InherentPermissions = X;

var
CopilotQuotaImpl: Codeunit "Copilot Quota Impl.";

/// <summary>
/// Try function to log usage of Copilot quota in the system. This function is only available for Microsoft Copilot features.
/// </summary>
/// <param name="CopilotCapability">The Copilot Capability to log usage for.</param>
/// <param name="Usage">The usage to log.</param>
/// <param name="CopilotQuotaUsageType">The type of Copilot Quota to log.</param>
[TryFunction]
[Scope('OnPrem')]
procedure TryLogQuotaUsage(CopilotCapability: Enum "Copilot Capability"; Usage: Integer; CopilotQuotaUsageType: Enum "Copilot Quota Usage Type")
var
CallerModuleInfo: ModuleInfo;
begin
NavApp.GetCallerModuleInfo(CallerModuleInfo);
CopilotQuotaImpl.LogQuotaUsage(CopilotCapability, Usage, CopilotQuotaUsageType, CallerModuleInfo);
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------
namespace System.AI;

using System;

codeunit 7786 "Copilot Quota Impl."
{
Access = Internal;
InherentEntitlements = X;
InherentPermissions = X;

var
InvalidUsageTypeErr: Label 'The value "%1" is not a valid Copilot Quota Usage Type.', Comment = '%1=a value such as "AI response" or "5"';
CapabilityNotRegisteredTelemetryMsg: Label 'Capability "%1" is not registered in the system but is logging usage.', Locked = true;
LoggingUsageTelemetryMsg: Label 'Capability "%1" is logging %2 usage of type %3.', Locked = true;

procedure LogQuotaUsage(CopilotCapability: Enum "Copilot Capability"; Usage: Integer; CopilotQuotaUsageType: Enum "Copilot Quota Usage Type"; CallerModuleInfo: ModuleInfo)
var
CopilotCapabilityImpl: Codeunit "Copilot Capability Impl";
ALCopilotFunctions: DotNet ALCopilotFunctions;
AlCopilotCapability: DotNet ALCopilotCapability;
AlCopilotUsageType: DotNet ALCopilotUsageType;
begin
if not CopilotCapabilityImpl.IsCapabilityRegistered(CopilotCapability, CallerModuleInfo) then
Session.LogMessage('0000OSL', StrSubstNo(CapabilityNotRegisteredTelemetryMsg, CopilotCapability), Verbosity::Warning, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', CopilotCapabilityImpl.GetCopilotCategory());

Session.LogMessage('0000OSM', StrSubstNo(LoggingUsageTelemetryMsg, CopilotCapability, Usage, CopilotQuotaUsageType), Verbosity::Verbose, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', CopilotCapabilityImpl.GetCopilotCategory());

ALCopilotCapability := ALCopilotCapability.ALCopilotCapability(
CallerModuleInfo.Publisher(), CallerModuleInfo.Id(), Format(CallerModuleInfo.AppVersion()), CopilotCapabilityImpl.CapabilityToEnumName(CopilotCapability));

UsageTypeToDotnetUsageType(CopilotQuotaUsageType, AlCopilotUsageType);

ALCopilotFunctions.LogCopilotQuotaUsage(AlCopilotCapability, Usage, AlCopilotUsageType);
end;

local procedure UsageTypeToDotnetUsageType(CopilotQuotaUsageType: Enum "Copilot Quota Usage Type"; var AlCopilotUsageType: DotNet AlCopilotUsageType)
begin
case CopilotQuotaUsageType of
CopilotQuotaUsageType::"Generative AI Answer":
AlCopilotUsageType := AlCopilotUsageType::GenAIAnswer;
CopilotQuotaUsageType::"Autonomous Action":
AlCopilotUsageType := AlCopilotUsageType::AutonomousAction;
else
Error(InvalidUsageTypeErr, CopilotQuotaUsageType);
end;
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------
namespace System.AI;

/// <summary>
/// Enumeration of valid types of usage of the Copilot Quota.
/// </summary>
enum 7785 "Copilot Quota Usage Type"
{
Caption = 'Copilot Quota Usage Type';
Access = Public;
Extensible = false;

/// <summary>
/// Represents a Generative AI Answer usage type.
/// </summary>
value(0; "Generative AI Answer")
{
Caption = 'Generative AI Answer';
}

/// <summary>
/// Represents an Autonomous Action usage type.
/// </summary>
value(1; "Autonomous Action")
{
Caption = 'Autonomous Action';
}
}
4 changes: 4 additions & 0 deletions src/System Application/App/DotNet Aliases/src/dotnet.al
Original file line number Diff line number Diff line change
Expand Up @@ -2144,6 +2144,10 @@ dotnet
{
}

type("Microsoft.Dynamics.Nav.Service.CopilotApi.AL.ALCopilotUsageType"; ALCopilotUsageType)
{
}

type("Microsoft.Dynamics.Nav.Service.CopilotApi.AL.ALCopilotQuotaDetails"; ALCopilotQuotaDetails)
{
}
Expand Down
Loading