Skip to content
Open
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
4 changes: 2 additions & 2 deletions logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<appender-ref ref="CONSOLE"/>
</root>

<!-- <logger name="org.apache.hc.client5.http.wire" level="DEBUG"/>-->
<!-- <logger name="org.apache.http.wire" level="DEBUG"/>-->
<logger name="org.apache.hc.client5.http.wire" level="DEBUG"/>
<logger name="org.apache.http.wire" level="DEBUG"/>
<logger name="com.sap.ai.sdk" level="DEBUG"/>
<!-- Disable org.eclipse.jetty logging -->
<logger name="org.eclipse.jetty" level="OFF"/>
Expand Down
58 changes: 58 additions & 0 deletions sample-code/spring-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@
<dependency>
<groupId>com.sap.ai.sdk</groupId>
<artifactId>core</artifactId>
<exclusions>
<exclusion>
<groupId>com.sap.cloud.sdk.cloudplatform</groupId>
<artifactId>connectivity-oauth</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sap.cloud.sdk.cloudplatform</groupId>
<artifactId>connectivity-oauth</artifactId>
<version>5.27.0-SNAPSHOT</version>
<!-- Oauth2Service:234 - additionalParameters.put("token_format", "jwt"); -->
</dependency>
<dependency>
<groupId>com.sap.ai.sdk.foundationmodels</groupId>
Expand Down Expand Up @@ -241,6 +253,52 @@
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>
<!-- Agent Tool Integration Layer dependencies -->
<dependency>
<groupId>com.sap.cloud.environment.servicebinding.api</groupId>
<artifactId>java-access-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sap.cloud.environment.servicebinding.api</groupId>
<artifactId>java-core-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sap.cloud.sdk.cloudplatform</groupId>
<artifactId>connectivity-apache-httpclient5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sap.cloud.environment.servicebinding</groupId>
<artifactId>java-sap-vcap-services</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.vavr</groupId>
<artifactId>vavr</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sap.cloud.sdk.cloudplatform</groupId>
<artifactId>security</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.sap.ai.sdk.app.controllers;

import static com.sap.cloud.environment.servicebinding.api.ServiceIdentifier.IDENTITY_AUTHENTICATION;
import static org.apache.hc.core5.http.ContentType.APPLICATION_JSON;

import com.auth0.jwt.JWT;
import com.sap.cloud.environment.servicebinding.SapVcapServicesServiceBindingAccessor;
import com.sap.cloud.environment.servicebinding.api.DefaultServiceBindingAccessor;
import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5Accessor;
import com.sap.cloud.sdk.cloudplatform.connectivity.BtpServiceOptions.AuthenticationServiceOptions;
import com.sap.cloud.sdk.cloudplatform.connectivity.BtpServiceOptions.IasOptions;
import com.sap.cloud.sdk.cloudplatform.connectivity.OnBehalfOf;
import com.sap.cloud.sdk.cloudplatform.connectivity.ServiceBindingDestinationLoader;
import com.sap.cloud.sdk.cloudplatform.connectivity.ServiceBindingDestinationOptions;
import com.sap.cloud.sdk.cloudplatform.security.AuthToken;
import com.sap.cloud.sdk.cloudplatform.security.AuthTokenAccessor;
import io.vavr.control.Try;
import java.util.Collections;
import lombok.SneakyThrows;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.impl.classic.BasicHttpClientResponseHandler;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* How to run this test:
*
* <p><b>1. Get the VCAP_SERVICES</b>: Navigate to <a *
* href="https://canary.cockpit.btp.int.sap/cockpit/#/globalaccount/92129a35-5f7b-4e98-ba96-ca830111f86c/subaccount/94bbb59e-56ff-4cf3-9787-f6b28d5e565b/org/f29b2548-6ca5-410b-8a1e-0d90641a1f40/space/397b46f3-1311-4b1d-99a4-bf19efecfd7b/app/d1a35dbe-cad3-4795-8593-6a21b505cacd/environmentvariables">BTP
* > agent-approuter > environment variables</a> and copy the <code>VCAP_SERVICES</code> part
* starting with <code>{"identity"</code>.
*
* <p><b>2. Get the JSON_WEB_TOKEN</b>: Copy your password while logging into <a
* href="https://ma.accounts400.ondemand.com">Cloud Identity</a>. Make a Bruno request to <code>
* https://ma.accounts400.ondemand.com/oauth2/token</code> with the following URL encoded body:
*
* <pre>
* grant_type=client_credentials
* &client_id=&ltapprouter-client-id>
* &client_secret=&ltapprouter-client-secret>
* &username=&ltyour-email>
* &password=&ltCloud-Indentity-password>
* </pre>
*/
class AgentToolIntegrationLayerTest {

private static final String VCAP_SERVICES =
"""
""";

private static final String JSON_WEB_TOKEN =
"""
""";

String payload =
"""
{
"message": {
"role": "user",
"parts": [
{
"kind": "data",
"data": {
"userQuery": "Plan a travel itinerary for me for Berlin"
}
}
],
"kind": "message"
}
}
""";

@BeforeEach
void prepareInboundAccessToken() {
DefaultServiceBindingAccessor.setInstance(
new SapVcapServicesServiceBindingAccessor(
Collections.singletonMap("VCAP_SERVICES", VCAP_SERVICES)::get));
AuthTokenAccessor.setAuthTokenFacade(
() -> Try.success(new AuthToken(JWT.decode(JSON_WEB_TOKEN))));
}

@Test
@SneakyThrows
void testAgentToolIntegrationLayer() {
var options =
ServiceBindingDestinationOptions.forService(IDENTITY_AUTHENTICATION)
.withOption(
AuthenticationServiceOptions.withTargetUri(
"https://gen-ai-hub-sdk-8pengs8d.eu12.sapdas.cloud.sap"))
.withOption(IasOptions.withApplicationName("Agent2Joule"))
.onBehalfOf(OnBehalfOf.NAMED_USER_CURRENT_TENANT)
.build();

var destination = ServiceBindingDestinationLoader.defaultLoaderChain().getDestination(options);

String atilUrl =
"/api/content/v1/capabilities/com.sap.ai.sdk/my_assistant_capability/scenarios/plan_travel/v1/message:send?assistant=my_assistant_i563080";
var httpPost = new HttpPost(atilUrl);
httpPost.setEntity(new StringEntity(payload, APPLICATION_JSON.withCharset((String) null)));
httpPost.setHeader(
"x-callback-target", "https://echo-server.cfapps.eu12-001.hana.ondemand.com");
httpPost.setHeader("x-global-user-id", "01361f5a-9ca7-4593-9c54-2425a127edff");
httpPost.setHeader("Accept-Language", "en");

var response =
ApacheHttpClient5Accessor.getHttpClient(destination)
.execute(httpPost, new BasicHttpClientResponseHandler());
System.out.println(response);
}
}
Loading