From dc2afbaaf7f94fecaef4502e67e018e1c8a3685a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Hartvig=20Gr=C3=B8nbech?= Date: Mon, 18 May 2026 16:24:39 +0200 Subject: [PATCH 1/4] Mark AOAI user message AddTextPart/AddFilePart as OnPrem and GenerateChatCompletion impl overload as NonDebuggable Fixes AB#635890 Co-Authored-By: Claude Opus 4.7 (1M context) --- .../App/AI/src/Azure OpenAI/AzureOpenAIImpl.Codeunit.al | 1 + .../Azure OpenAI/Chat Completion/AOAIUserMessage.Codeunit.al | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/System Application/App/AI/src/Azure OpenAI/AzureOpenAIImpl.Codeunit.al b/src/System Application/App/AI/src/Azure OpenAI/AzureOpenAIImpl.Codeunit.al index 5ff77fd125..71731dc20f 100644 --- a/src/System Application/App/AI/src/Azure OpenAI/AzureOpenAIImpl.Codeunit.al +++ b/src/System Application/App/AI/src/Azure OpenAI/AzureOpenAIImpl.Codeunit.al @@ -263,6 +263,7 @@ codeunit 7772 "Azure OpenAI Impl" implements "AI Service Name" GenerateChatCompletion(ChatMessages, AOAIChatCompletionParams, AOAIOperationResponse, CallerModuleInfo); end; + [NonDebuggable] procedure GenerateChatCompletion(var ChatMessages: Codeunit "AOAI Chat Messages"; AOAIChatCompletionParams: Codeunit "AOAI Chat Completion Params"; var AOAIOperationResponse: Codeunit "AOAI Operation Response"; CallerModuleInfo: ModuleInfo) var AOAIPolicyParams: Codeunit "AOAI Policy Params"; diff --git a/src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIUserMessage.Codeunit.al b/src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIUserMessage.Codeunit.al index 7f9db0594f..8f030af6e6 100644 --- a/src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIUserMessage.Codeunit.al +++ b/src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIUserMessage.Codeunit.al @@ -21,6 +21,7 @@ codeunit 7783 "AOAI User Message" /// Adds a text content part to the user message. /// /// The text content to add. + [Scope('OnPrem')] procedure AddTextPart(TextContent: Text) begin AOAIUserMessageImpl.AddTextPart(TextContent); @@ -30,6 +31,7 @@ codeunit 7783 "AOAI User Message" /// Adds a file content part to the user message. /// /// The file data to add (e.g. base64-encoded content). + [Scope('OnPrem')] procedure AddFilePart(FileData: Text) begin AOAIUserMessageImpl.AddFilePart(FileData); From 6f17090510838d5c1c95818ad967e8d50c45b361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Hartvig=20Gr=C3=B8nbech?= Date: Mon, 18 May 2026 16:48:23 +0200 Subject: [PATCH 2/4] Suppress AS0022 on OnPrem scoped AddTextPart/AddFilePart Co-Authored-By: Claude Opus 4.7 (1M context) --- .../Azure OpenAI/Chat Completion/AOAIUserMessage.Codeunit.al | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIUserMessage.Codeunit.al b/src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIUserMessage.Codeunit.al index 8f030af6e6..a490bc38dd 100644 --- a/src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIUserMessage.Codeunit.al +++ b/src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIUserMessage.Codeunit.al @@ -22,7 +22,9 @@ codeunit 7783 "AOAI User Message" /// /// The text content to add. [Scope('OnPrem')] +#pragma warning disable AS0022 procedure AddTextPart(TextContent: Text) +#pragma warning restore AS0022 begin AOAIUserMessageImpl.AddTextPart(TextContent); end; @@ -32,7 +34,9 @@ codeunit 7783 "AOAI User Message" /// /// The file data to add (e.g. base64-encoded content). [Scope('OnPrem')] +#pragma warning disable AS0022 procedure AddFilePart(FileData: Text) +#pragma warning restore AS0022 begin AOAIUserMessageImpl.AddFilePart(FileData); end; From 89180b91ab362bd0deb719f1ad1ee5106cd0e43c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Hartvig=20Gr=C3=B8nbech?= Date: Mon, 18 May 2026 16:58:14 +0200 Subject: [PATCH 3/4] Restrict AddTextPart/AddFilePart to Microsoft publisher Co-Authored-By: Claude Opus 4.7 (1M context) --- .../Chat Completion/AOAIUserMessage.Codeunit.al | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIUserMessage.Codeunit.al b/src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIUserMessage.Codeunit.al index a490bc38dd..95fb6b803d 100644 --- a/src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIUserMessage.Codeunit.al +++ b/src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIUserMessage.Codeunit.al @@ -16,6 +16,8 @@ codeunit 7783 "AOAI User Message" var AOAIUserMessageImpl: Codeunit "AOAI User Message Impl"; + CopilotCapabilityImpl: Codeunit "Copilot Capability Impl"; + NotMicrosoftPublisherErr: Label 'This functionality is only available to Microsoft published apps.'; /// /// Adds a text content part to the user message. @@ -25,7 +27,12 @@ codeunit 7783 "AOAI User Message" #pragma warning disable AS0022 procedure AddTextPart(TextContent: Text) #pragma warning restore AS0022 + var + CallerModuleInfo: ModuleInfo; begin + NavApp.GetCallerModuleInfo(CallerModuleInfo); + if not CopilotCapabilityImpl.IsPublisherMicrosoft(CallerModuleInfo) then + Error(NotMicrosoftPublisherErr); AOAIUserMessageImpl.AddTextPart(TextContent); end; @@ -37,7 +44,12 @@ codeunit 7783 "AOAI User Message" #pragma warning disable AS0022 procedure AddFilePart(FileData: Text) #pragma warning restore AS0022 + var + CallerModuleInfo: ModuleInfo; begin + NavApp.GetCallerModuleInfo(CallerModuleInfo); + if not CopilotCapabilityImpl.IsPublisherMicrosoft(CallerModuleInfo) then + Error(NotMicrosoftPublisherErr); AOAIUserMessageImpl.AddFilePart(FileData); end; From cb9550f2b7159c97b205742140117ad6959c9fee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Hartvig=20Gr=C3=B8nbech?= Date: Mon, 18 May 2026 17:00:42 +0200 Subject: [PATCH 4/4] Move publisher check into AOAI User Message Impl Co-Authored-By: Claude Opus 4.7 (1M context) --- .../Chat Completion/AOAIUserMessage.Codeunit.al | 10 ++-------- .../Chat Completion/AOAIUserMessageImpl.Codeunit.al | 10 ++++++++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIUserMessage.Codeunit.al b/src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIUserMessage.Codeunit.al index 95fb6b803d..05addf2cf6 100644 --- a/src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIUserMessage.Codeunit.al +++ b/src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIUserMessage.Codeunit.al @@ -16,8 +16,6 @@ codeunit 7783 "AOAI User Message" var AOAIUserMessageImpl: Codeunit "AOAI User Message Impl"; - CopilotCapabilityImpl: Codeunit "Copilot Capability Impl"; - NotMicrosoftPublisherErr: Label 'This functionality is only available to Microsoft published apps.'; /// /// Adds a text content part to the user message. @@ -31,9 +29,7 @@ codeunit 7783 "AOAI User Message" CallerModuleInfo: ModuleInfo; begin NavApp.GetCallerModuleInfo(CallerModuleInfo); - if not CopilotCapabilityImpl.IsPublisherMicrosoft(CallerModuleInfo) then - Error(NotMicrosoftPublisherErr); - AOAIUserMessageImpl.AddTextPart(TextContent); + AOAIUserMessageImpl.AddTextPart(TextContent, CallerModuleInfo); end; /// @@ -48,9 +44,7 @@ codeunit 7783 "AOAI User Message" CallerModuleInfo: ModuleInfo; begin NavApp.GetCallerModuleInfo(CallerModuleInfo); - if not CopilotCapabilityImpl.IsPublisherMicrosoft(CallerModuleInfo) then - Error(NotMicrosoftPublisherErr); - AOAIUserMessageImpl.AddFilePart(FileData); + AOAIUserMessageImpl.AddFilePart(FileData, CallerModuleInfo); end; /// diff --git a/src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIUserMessageImpl.Codeunit.al b/src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIUserMessageImpl.Codeunit.al index 8fdae0b9c9..92cd084937 100644 --- a/src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIUserMessageImpl.Codeunit.al +++ b/src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIUserMessageImpl.Codeunit.al @@ -11,15 +11,19 @@ codeunit 7784 "AOAI User Message Impl" InherentPermissions = X; var + CopilotCapabilityImpl: Codeunit "Copilot Capability Impl"; [NonDebuggable] ContentParts: JsonArray; HasFileContent, HasTextContent : Boolean; + NotMicrosoftPublisherErr: Label 'This functionality is only available to Microsoft published apps.'; [NonDebuggable] - procedure AddTextPart(TextContent: Text) + procedure AddTextPart(TextContent: Text; CallerModuleInfo: ModuleInfo) var TextPartObject: JsonObject; begin + if not CopilotCapabilityImpl.IsPublisherMicrosoft(CallerModuleInfo) then + Error(NotMicrosoftPublisherErr); TextPartObject.Add('type', 'text'); TextPartObject.Add('text', TextContent); ContentParts.Add(TextPartObject); @@ -27,11 +31,13 @@ codeunit 7784 "AOAI User Message Impl" end; [NonDebuggable] - procedure AddFilePart(FileData: Text) + procedure AddFilePart(FileData: Text; CallerModuleInfo: ModuleInfo) var FilePartObject: JsonObject; FileDataObject: JsonObject; begin + if not CopilotCapabilityImpl.IsPublisherMicrosoft(CallerModuleInfo) then + Error(NotMicrosoftPublisherErr); FileDataObject.Add('file_data', FileData); FilePartObject.Add('type', 'file'); FilePartObject.Add('file', FileDataObject);