Skip to content

Commit 1d7a535

Browse files
committed
Move core java code from Wanaku to the Capabilities SDK
This supports fixing issue wanaku-ai/wanaku#673
1 parent 5a4f04b commit 1d7a535

File tree

104 files changed

+5080
-124
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+5080
-124
lines changed

.github/workflows/early-access.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: early-access
2+
3+
on:
4+
workflow_dispatch:
5+
workflow_call:
6+
7+
jobs:
8+
publish-snapshot:
9+
name: Publish Snapshot
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Setup Java
19+
uses: actions/setup-java@v4
20+
with:
21+
java-version: 21
22+
distribution: 'zulu'
23+
server-id: central
24+
server-username: MAVEN_USERNAME
25+
server-password: MAVEN_CENTRAL_TOKEN
26+
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
27+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
28+
cache: maven
29+
30+
- name: Publish snapshot to Maven Central
31+
env:
32+
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
33+
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
34+
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
35+
run: |
36+
export GPG_TTY=$(tty)
37+
mvn -Pdist -B --file pom.xml deploy

.github/workflows/main-build.yml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,16 @@ jobs:
1919
build:
2020
runs-on: ubuntu-latest
2121
steps:
22-
- name: Checkout Wanaku Main project
23-
uses: actions/checkout@v4
22+
- uses: actions/checkout@v4
2423
with:
25-
repository: wanaku-ai/wanaku
24+
ref: ${{ github.ref_name }}
2625
persist-credentials: false
27-
ref: main
28-
path: wanaku
26+
fetch-depth: 0
2927
- name: Set up JDK 21
3028
uses: actions/setup-java@v4
3129
with:
3230
java-version: '21'
3331
distribution: 'temurin'
3432
cache: maven
35-
- name: Build Wanaku Main Project
36-
run: mvn -DskipTests clean install
37-
working-directory: ${{ github.workspace }}/wanaku
38-
- uses: actions/checkout@v4
39-
with:
40-
ref: main
41-
persist-credentials: false
42-
fetch-depth: 0
4333
- name: Build with Maven
4434
run: mvn -B package --file pom.xml

.github/workflows/pr-builds.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,15 @@ jobs:
4141
fail-fast: true
4242

4343
steps:
44-
- name: Checkout Wanaku Main project
45-
uses: actions/checkout@v4
44+
- uses: actions/checkout@v4
4645
with:
47-
repository: wanaku-ai/wanaku
4846
persist-credentials: false
49-
ref: main
50-
path: wanaku
47+
fetch-depth: 0
5148
- name: Set up JDK 21
5249
uses: actions/setup-java@v4
5350
with:
5451
java-version: '21'
5552
distribution: 'temurin'
5653
cache: maven
57-
- name: Build Wanaku Main Project
58-
run: mvn -DskipTests clean install
59-
working-directory: ${{ github.workspace }}/wanaku
60-
- uses: actions/checkout@v4
61-
with:
62-
ref: main
63-
persist-credentials: false
64-
fetch-depth: 0
6554
- name: Build with Maven
6655
run: mvn -B package --file pom.xml
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Trigger Early Access
2+
3+
on:
4+
schedule:
5+
# Run every 2 days at 00:00 UTC
6+
- cron: '0 0 */2 * *'
7+
8+
jobs:
9+
trigger:
10+
name: Trigger Early Access Workflow
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Trigger early-access workflow
14+
uses: actions/github-script@v7
15+
with:
16+
script: |
17+
await github.rest.actions.createWorkflowDispatch({
18+
owner: context.repo.owner,
19+
repo: context.repo.repo,
20+
workflow_id: 'early-access.yml',
21+
ref: 'main'
22+
})

capabilities-api/pom.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>ai.wanaku.sdk</groupId>
8+
<artifactId>capabilities-parent</artifactId>
9+
<version>0.0.9-SNAPSHOT</version>
10+
<relativePath>../capabilities-parent/pom.xml</relativePath>
11+
</parent>
12+
13+
<artifactId>capabilities-api</artifactId>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>com.fasterxml.jackson.core</groupId>
18+
<artifactId>jackson-annotations</artifactId>
19+
</dependency>
20+
</dependencies>
21+
22+
</project>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package ai.wanaku.capabilities.sdk.api.discovery;
2+
3+
import ai.wanaku.capabilities.sdk.api.types.providers.ServiceTarget;
4+
5+
/**
6+
* Callback interface for receiving notifications about service registration lifecycle events.
7+
*
8+
* <p>Implementations of this interface can be registered with a {@link RegistrationManager}
9+
* to receive notifications when registration-related operations occur, such as successful
10+
* registration, deregistration attempts, or periodic health check pings.</p>
11+
*
12+
* <p>Callbacks are invoked synchronously after the corresponding operation completes.
13+
* If a callback throws an exception, it will be logged but will not prevent other
14+
* registered callbacks from executing.</p>
15+
*
16+
* <p>Usage example:</p>
17+
* <pre>{@code
18+
* RegistrationManager manager = ...;
19+
* manager.addCallBack(new RegistrationCallback() {
20+
* @Override
21+
* public void onRegistration(RegistrationManager manager) {
22+
* // Handle successful registration
23+
* }
24+
*
25+
* @Override
26+
* public void onPing(RegistrationManager manager, int status) {
27+
* // Handle ping result
28+
* }
29+
*
30+
* @Override
31+
* public void onDeregistration(RegistrationManager manager, int status) {
32+
* // Handle deregistration result
33+
* }
34+
* });
35+
* }</pre>
36+
*
37+
* @see RegistrationManager#addCallBack(DiscoveryCallback)
38+
*/
39+
public interface DiscoveryCallback {
40+
41+
/**
42+
* Invoked after a ping operation is sent to the discovery service.
43+
* This callback is triggered when the service sends a heartbeat to indicate
44+
* it is still active and operational.
45+
*
46+
* @param manager the {@link RegistrationManager} that performed the ping operation
47+
* @param target the {@link ServiceTarget} that was pinged
48+
* @param status the HTTP status code returned by the ping operation
49+
* (200 indicates success, other values indicate various failure conditions)
50+
*/
51+
void onPing(RegistrationManager manager, ServiceTarget target, int status);
52+
53+
/**
54+
* Invoked after the service has been successfully registered with the discovery service.
55+
* This callback is only called when registration completes successfully.
56+
*
57+
* @param manager the {@link RegistrationManager} that performed the registration
58+
* @param target the {@link ServiceTarget} that was registered
59+
*/
60+
void onRegistration(RegistrationManager manager, ServiceTarget target);
61+
62+
/**
63+
* Invoked after a deregistration attempt is made with the discovery service.
64+
* This callback is triggered when the service is being shut down or explicitly
65+
* removed from the registry.
66+
*
67+
* @param manager the {@link RegistrationManager} that performed the deregistration operation
68+
* @param target the {@link ServiceTarget} that was deregistered
69+
* @param status the HTTP status code returned by the deregistration operation
70+
* (200 indicates success, other values indicate various failure conditions)
71+
*/
72+
void onDeregistration(RegistrationManager manager, ServiceTarget target, int status);
73+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package ai.wanaku.capabilities.sdk.api.discovery;
2+
3+
/**
4+
* The `RegistrationManager` interface defines the contract for a class responsible for managing the lifecycle
5+
* registration of a capability service within the Wanaku ecosystem.
6+
*
7+
* <p>Implementations of this interface handle the processes of registering, deregistering,
8+
* and monitoring the status of a service's registration. It acts as the primary interface
9+
* for a capability service to interact with the Wanaku registration mechanism.</p>
10+
*/
11+
public interface RegistrationManager {
12+
13+
/**
14+
* Registers the capability service with Wanaku
15+
*/
16+
void register();
17+
18+
/**
19+
* Deregisters the capability service from the Wanaku registration system.
20+
* This method notifies the registry that the service is no longer available
21+
* or is shutting down, allowing for proper cleanup and resource release.
22+
*/
23+
void deregister();
24+
25+
/**
26+
* Sends a "ping" or heartbeat signal to the Wanaku registration system.
27+
* This method is used to periodically inform the registry that the service is still active
28+
* and operational, preventing its registration from expiring due to inactivity.
29+
*/
30+
void ping();
31+
32+
/**
33+
* Notifies the Wanaku registration system that the last attempted operation (tool call
34+
* or resource acquisition) from this service failed.
35+
*
36+
* @param reason A descriptive string explaining the reason for the failure.
37+
* This information can be used for logging, debugging, or alerting purposes
38+
* by the registration system.
39+
*/
40+
void lastAsFail(String reason);
41+
42+
/**
43+
* Notifies the Wanaku registration system that the last attempted operation (tool call
44+
* or resource acquisition) from this service was successful.
45+
* This method can be used to update the service's status within the registry,
46+
* indicating its continued health and availability.
47+
*/
48+
void lastAsSuccessful();
49+
50+
/**
51+
* Adds a callback to be run after some operations have executed
52+
* @param callback the callback to add
53+
*/
54+
void addCallBack(DiscoveryCallback callback);
55+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package ai.wanaku.capabilities.sdk.api.exceptions;
2+
3+
/**
4+
* This exception can be thrown if a configuration is expected in some way, but it is not found.
5+
*/
6+
public class ConfigurationNotFoundException extends WanakuException {
7+
8+
/**
9+
* Constructs a new instance of this exception without a message or cause.
10+
*/
11+
public ConfigurationNotFoundException() {}
12+
13+
/**
14+
* Constructs a new instance of this exception with the specified detail message.
15+
*
16+
* @param message the detail message (which is saved for later retrieval by the {@link #getMessage()} method)
17+
*/
18+
public ConfigurationNotFoundException(String message) {
19+
super(message);
20+
}
21+
22+
/**
23+
* Constructs a new instance of this exception with the specified detail message and cause.
24+
*
25+
* @param message the detail message (which is saved for later retrieval by the {@link #getMessage()} method)
26+
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method)
27+
*/
28+
public ConfigurationNotFoundException(String message, Throwable cause) {
29+
super(message, cause);
30+
}
31+
32+
/**
33+
* Constructs a new instance of this exception with the specified cause.
34+
*
35+
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method)
36+
*/
37+
public ConfigurationNotFoundException(Throwable cause) {
38+
super(cause);
39+
}
40+
41+
/**
42+
* Constructs a new instance of this exception with the specified detail message, cause,
43+
* enable suppression and writable stack trace.
44+
*
45+
* @param message the detail message (which is saved for later retrieval by the {@link #getMessage()} method)
46+
* @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method)
47+
* @param enableSuppression whether suppression is enabled
48+
* @param writableStackTrace whether stack traces should be writtable
49+
*/
50+
public ConfigurationNotFoundException(
51+
String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
52+
super(message, cause, enableSuppression, writableStackTrace);
53+
}
54+
55+
/**
56+
* Creates a new instance of this exception for the given tool name.
57+
*
58+
* @param toolName the name of the tool that was not found
59+
* @return a new instance of this exception with a message indicating that the tool was not found
60+
*/
61+
public static ConfigurationNotFoundException forName(String toolName) {
62+
return new ConfigurationNotFoundException(String.format("Tool %s not found", toolName));
63+
}
64+
}

0 commit comments

Comments
 (0)