gnodet-bot commented on code in PR #30707:
URL: https://github.com/apache/camel/pull/30707#discussion_r4683802437


##########
components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIEndpoint.java:
##########
@@ -937,17 +945,30 @@ McpSchema.CallToolResult callTool(McpSyncClient 
mcpClient, String toolName, Map<
     private static final String NO_API_KEY = "camel-openai-no-api-key";
 
     protected OpenAIClient createClient() throws Exception {
-        String apiKey = resolveApiKey();
-
         OpenAIOkHttpClient.Builder builder = OpenAIOkHttpClient.builder();
 
-        if (ObjectHelper.isNotEmpty(apiKey)) {
-            builder.apiKey(apiKey);
+        if (ObjectHelper.isNotEmpty(configuration.getOauthProfile())) {

Review Comment:
   ⚠️ **Behavioral change: precedence inversion**
   
   Before this PR, `resolveApiKey()` checked `apiKey` first, then 
`oauthProfile`. Now this outer `if` checks `oauthProfile` before `apiKey`. If a 
user configures **both** `apiKey` and `oauthProfile`, the previous behavior was 
`apiKey` wins; the new behavior is `oauthProfile` wins. This is a silent, 
backward-incompatible change — please document it.



##########
components/camel-ai/camel-langchain4j-agent/src/main/java/org/apache/camel/component/langchain4j/agent/LangChain4jMcpServerDefinition.java:
##########
@@ -235,8 +228,19 @@ private McpTransport buildTransport(CamelContext 
camelContext) throws Exception
                     .logRequests(logRequests)
                     .logResponses(logResponses)
                     .timeout(timeout);
-            if (authHeaders != null) {
-                builder.customHeaders(authHeaders);
+            if (oauthProfile != null && !oauthProfile.isBlank() && 
camelContext != null) {
+                // Use a Supplier so the token is re-resolved on every request,
+                // allowing short-lived OAuth tokens to be refreshed when they 
expire.
+                final String profile = oauthProfile;
+                final CamelContext ctx = camelContext;
+                builder.customHeaders(() -> {

Review Comment:
   ⚠️ **Fail-fast behavior removed**
   
   Previously, `OAuthHelper.resolveOAuthToken()` was called eagerly in 
`buildTransport()`, meaning a bad OAuth profile would cause a startup failure. 
With this supplier, the error is now deferred to the first request. This is an 
intentional trade-off for the token-refresh feature — please document it in the 
method Javadoc or the PR description so operators are aware.



##########
components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIEndpoint.java:
##########
@@ -1098,16 +1119,13 @@ private void 
configureSslFromProperties(OpenAIOkHttpClient.Builder builder) thro
     }
 
     protected String resolveApiKey() throws Exception {
-        // Priority: URI parameter > OAuth profile > environment variable > 
system property
+        // Priority: URI parameter > environment variable > system property

Review Comment:
   💡 **Comment imprecision (nit)**
   
   `configuration.getApiKey()` reflects a configuration *property* (which URI 
parameters set, but which may come from other sources too). "URI parameter" is 
technically not wrong but could mislead readers. Consider `// Priority: 
configuration property (apiKey) > environment variable > system property`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to