From 21116ec278483dc1c79b0d157195721c3deea1df Mon Sep 17 00:00:00 2001 From: Darrick Date: Mon, 3 Mar 2025 09:26:11 +0100 Subject: [PATCH 1/2] Move quota checks to page background task (#3115) #### Summary The quota check from platform can be delayed resulting in a delay in opening the page. We should not be blocking/delaying the opening of page, as such, that logic is moved to page background task. #### Work Item(s) Fixes [AB#567292](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/567292) --- .../src/Copilot/CopilotAICapabilities.Page.al | 39 ++++++++++++++++++- .../src/Copilot/CopilotQuotaImpl.Codeunit.al | 18 +++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/System Application/App/AI/src/Copilot/CopilotAICapabilities.Page.al b/src/System Application/App/AI/src/Copilot/CopilotAICapabilities.Page.al index a14e01503e..3d41de8aa4 100644 --- a/src/System Application/App/AI/src/Copilot/CopilotAICapabilities.Page.al +++ b/src/System Application/App/AI/src/Copilot/CopilotAICapabilities.Page.al @@ -252,6 +252,7 @@ page 7775 "Copilot AI Capabilities" EnvironmentInformation: Codeunit "Environment Information"; WithinGeo: Boolean; WithinEUDB: Boolean; + TaskId: Integer; begin OnRegisterCopilotCapability(); @@ -280,7 +281,43 @@ page 7775 "Copilot AI Capabilities" if EnvironmentInformation.IsSaaSInfrastructure() then begin CopilotNotifications.ShowBillingInTheFutureNotification(); - CopilotNotifications.CheckAIQuotaAndShowNotification(); + CurrPage.EnqueueBackgroundTask(TaskId, Codeunit::"Copilot Quota Impl."); + end; + end; + + trigger OnPageBackgroundTaskCompleted(TaskId: Integer; Results: Dictionary of [Text, Text]) + var + CopilotNotifications: Codeunit "Copilot Notifications"; + Value: Text; + CanConsume: Boolean; + HasBilling: Boolean; + QuotaUsedPercentage: Decimal; + CanConsumeLbl: Label 'CanConsume', Locked = true; + HasSetupBillingLbl: Label 'HasSetupBilling', Locked = true; + QuotaUsedPercentageLbl: Label 'QuotaUsedPercentage', Locked = true; + begin + if Results.ContainsKey(CanConsumeLbl) then begin + Results.Get(CanConsumeLbl, Value); + if Evaluate(CanConsume, Value) then; + if not CanConsume then begin + CopilotNotifications.ShowAIQuotaUsedUpNotification(); + exit; + end; + end; + + if Results.ContainsKey(HasSetupBillingLbl) then begin + Results.Get(HasSetupBillingLbl, Value); + if Evaluate(HasBilling, Value) then; + if HasBilling then + exit; + end; + + if Results.ContainsKey(QuotaUsedPercentageLbl) then begin + Results.Get(QuotaUsedPercentageLbl, Value); + if Evaluate(QuotaUsedPercentage, Value) then; + if QuotaUsedPercentage >= 80.0 then + CopilotNotifications.ShowAIQuotaNearlyUsedUpNotification(); + exit; end; end; diff --git a/src/System Application/App/AI/src/Copilot/CopilotQuotaImpl.Codeunit.al b/src/System Application/App/AI/src/Copilot/CopilotQuotaImpl.Codeunit.al index 1a57a0c489..68aad20b2f 100644 --- a/src/System Application/App/AI/src/Copilot/CopilotQuotaImpl.Codeunit.al +++ b/src/System Application/App/AI/src/Copilot/CopilotQuotaImpl.Codeunit.al @@ -17,6 +17,24 @@ codeunit 7786 "Copilot Quota Impl." 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; + trigger OnRun() + var + ALCopilotFunctions: DotNet ALCopilotFunctions; + ALCopilotQuotaDetails: Dotnet ALCopilotQuotaDetails; + Results: Dictionary of [Text, Text]; + begin + ALCopilotQuotaDetails := ALCopilotFunctions.GetCopilotQuotaDetails(); + + if IsNull(ALCopilotQuotaDetails) then + exit; + + Results.Add('CanConsume', Format(ALCopilotQuotaDetails.CanConsume())); + Results.Add('HasSetupBilling', Format(ALCopilotQuotaDetails.HasSetupBilling())); + Results.Add('QuotaUsedPercentage', Format(ALCopilotQuotaDetails.QuotaUsedPercentage())); + + Page.SetBackgroundTaskResult(Results); + end; + procedure LogQuotaUsage(CopilotCapability: Enum "Copilot Capability"; Usage: Integer; CopilotQuotaUsageType: Enum "Copilot Quota Usage Type"; CallerModuleInfo: ModuleInfo) var CopilotCapabilityImpl: Codeunit "Copilot Capability Impl"; From bf63eec136c5f6d2bdf41679d651238ee637a028 Mon Sep 17 00:00:00 2001 From: Steffen Balslev Date: Mon, 3 Mar 2025 13:06:10 +0100 Subject: [PATCH 2/2] Update ToolTip for Edit User Settings action (#3009) Fixes [AB#562392](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/562392) --- .../App/AppSource Gallery/src/AppSourceProductList.Page.al | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System Application/App/AppSource Gallery/src/AppSourceProductList.Page.al b/src/System Application/App/AppSource Gallery/src/AppSourceProductList.Page.al index 780a39e9a6..b2fd2ba3ad 100644 --- a/src/System Application/App/AppSource Gallery/src/AppSourceProductList.Page.al +++ b/src/System Application/App/AppSource Gallery/src/AppSourceProductList.Page.al @@ -135,7 +135,7 @@ page 2515 "AppSource Product List" Caption = 'Edit User Settings'; RunObject = page "User Settings"; Image = UserSetup; - ToolTip = 'Locale will be used to determine the market and language will be used to determine the language of the app details listed here.'; + ToolTip = 'Locale determines the language used for details about the app in Business Central and on AppSource.'; } }