Skip to content

Commit 05ec6df

Browse files
committed
Fix #63: Improve protobuf/gRPC definitions with industry best practices
1 parent f59c13d commit 05ec6df

File tree

18 files changed

+160
-130
lines changed

18 files changed

+160
-130
lines changed

capabilities-archetypes/capabilities-archetypes-java-tool/src/main/resources/archetype-resources/src/main/java/AppTool.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package ${package};
22

3-
import ai.wanaku.core.exchange.ToolInvokeReply;
4-
import ai.wanaku.core.exchange.ToolInvokeRequest;
5-
import ai.wanaku.core.exchange.ToolInvokerGrpc;
3+
import ai.wanaku.core.exchange.v1.ToolInvokeReply;
4+
import ai.wanaku.core.exchange.v1.ToolInvokeRequest;
5+
import ai.wanaku.core.exchange.v1.ToolInvokerGrpc;
6+
import io.grpc.Status;
67
import io.grpc.stub.StreamObserver;
78
import java.util.List;
89
import java.util.Map;
@@ -29,12 +30,13 @@ public void invokeTool(ToolInvokeRequest request, StreamObserver<ToolInvokeReply
2930
// Build the response
3031
responseObserver.onNext(
3132
ToolInvokeReply.newBuilder()
32-
.setIsError(false)
3333
.addAllContent(List.of(response.toString())).build());
3434

3535
responseObserver.onCompleted();
36-
} finally {
37-
// cleanup
36+
} catch (Exception e) {
37+
responseObserver.onError(Status.INTERNAL
38+
.withDescription(String.format("Unable to invoke tool: %s", e.getMessage()))
39+
.asRuntimeException());
3840
}
3941
}
40-
}
42+
}

capabilities-archetypes/capabilities-archetypes-java-tool/src/main/resources/archetype-resources/src/main/java/ProvisionBase.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import ai.wanaku.capabilities.sdk.config.provider.api.ProvisionedConfig;
55
import ai.wanaku.capabilities.sdk.runtime.provisioners.FileProvisionerLoader;
66
import ai.wanaku.capabilities.sdk.util.ProvisioningHelper;
7-
import ai.wanaku.core.exchange.PropertySchema;
8-
import ai.wanaku.core.exchange.ProvisionReply;
9-
import ai.wanaku.core.exchange.ProvisionRequest;
10-
import ai.wanaku.core.exchange.ProvisionerGrpc;
7+
import ai.wanaku.core.exchange.v1.PropertySchema;
8+
import ai.wanaku.core.exchange.v1.ProvisionReply;
9+
import ai.wanaku.core.exchange.v1.ProvisionRequest;
10+
import ai.wanaku.core.exchange.v1.ProvisionerGrpc;
1111
import io.grpc.stub.StreamObserver;
1212
import java.util.Map;
1313

capabilities-exchange/src/main/java/ai/wanaku/capabilities/sdk/util/ProvisioningHelper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import java.net.URI;
44
import ai.wanaku.capabilities.sdk.config.provider.api.ConfigProvisioner;
55
import ai.wanaku.capabilities.sdk.config.provider.api.ProvisionedConfig;
6-
import ai.wanaku.core.exchange.Configuration;
7-
import ai.wanaku.core.exchange.ProvisionRequest;
8-
import ai.wanaku.core.exchange.Secret;
6+
import ai.wanaku.core.exchange.v1.Configuration;
7+
import ai.wanaku.core.exchange.v1.ProvisionRequest;
8+
import ai.wanaku.core.exchange.v1.Secret;
99

1010
/**
1111
* Helper class for provisioning configurations and secrets.

capabilities-exchange/src/main/proto/codeexecution.proto

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
syntax = "proto3";
22

3+
import "google/protobuf/timestamp.proto";
4+
35
option java_multiple_files = true;
4-
option java_package = "ai.wanaku.core.exchange";
6+
option java_package = "ai.wanaku.core.exchange.v1";
57
option java_outer_classname = "CodeExecutionExchange";
68

7-
package codeexecution;
9+
package ai.wanaku.codeexecution.v1;
810

911
/**
1012
* The code execution service definition.
@@ -51,20 +53,20 @@ message CodeExecutionRequest {
5153
* Optional URI reference to configuration data.
5254
* Used to provide additional configuration for the execution environment.
5355
*/
54-
string configurationURI = 5;
56+
string configuration_uri = 5;
5557

5658
/**
5759
* Optional URI reference to secrets data.
5860
* Used to provide secure credentials or sensitive data needed for execution.
5961
*/
60-
string secretsURI = 6;
62+
string secrets_uri = 6;
6163

6264
/**
6365
* Optional timeout in milliseconds.
6466
* Maximum time allowed for code execution before termination.
6567
* If not specified, a default timeout will be applied.
6668
*/
67-
int64 timeout = 7;
69+
optional int64 timeout = 7;
6870

6971
/**
7072
* Optional map of environment variables.
@@ -79,11 +81,8 @@ message CodeExecutionRequest {
7981
* Multiple messages may be sent for a single execution request.
8082
*/
8183
message CodeExecutionReply {
82-
/**
83-
* Indicates whether this message represents an error condition.
84-
* true if the execution encountered an error, false otherwise.
85-
*/
86-
bool isError = 1;
84+
reserved 1;
85+
reserved "isError";
8786

8887
/**
8988
* The execution output content.
@@ -97,7 +96,7 @@ message CodeExecutionReply {
9796
* The type of output this reply represents.
9897
* Indicates whether this is stdout, stderr, or a status message.
9998
*/
100-
OutputType outputType = 3;
99+
OutputType output_type = 3;
101100

102101
/**
103102
* The current execution status.
@@ -110,71 +109,80 @@ message CodeExecutionReply {
110109
* Only present in the final message when execution completes.
111110
* A value of 0 typically indicates successful execution.
112111
*/
113-
int32 exitCode = 5;
112+
optional int32 exit_code = 5;
114113

115114
/**
116115
* Optional timestamp when this output was generated.
117-
* Unix timestamp in milliseconds since epoch.
118116
*/
119-
int64 timestamp = 6;
117+
google.protobuf.Timestamp timestamp = 6;
120118
}
121119

122120
/**
123121
* Enumeration of output types for code execution replies.
124122
*/
125123
enum OutputType {
124+
/**
125+
* Unspecified output type.
126+
*/
127+
OUTPUT_TYPE_UNSPECIFIED = 0;
128+
126129
/**
127130
* Standard output (stdout) from the executed code.
128131
*/
129-
STDOUT = 0;
132+
OUTPUT_TYPE_STDOUT = 1;
130133

131134
/**
132135
* Standard error (stderr) from the executed code.
133136
*/
134-
STDERR = 1;
137+
OUTPUT_TYPE_STDERR = 2;
135138

136139
/**
137140
* Status or informational message about execution progress.
138141
*/
139-
STATUS = 2;
142+
OUTPUT_TYPE_STATUS = 3;
140143

141144
/**
142145
* Final completion message indicating execution has finished.
143146
*/
144-
COMPLETION = 3;
147+
OUTPUT_TYPE_COMPLETION = 4;
145148
}
146149

147150
/**
148151
* Enumeration of execution status values.
149152
*/
150153
enum ExecutionStatus {
154+
/**
155+
* Unspecified execution status.
156+
*/
157+
EXECUTION_STATUS_UNSPECIFIED = 0;
158+
151159
/**
152160
* Execution is pending and has not yet started.
153161
*/
154-
PENDING = 0;
162+
EXECUTION_STATUS_PENDING = 1;
155163

156164
/**
157165
* Code is currently being executed.
158166
*/
159-
RUNNING = 1;
167+
EXECUTION_STATUS_RUNNING = 2;
160168

161169
/**
162170
* Execution completed successfully.
163171
*/
164-
COMPLETED = 2;
172+
EXECUTION_STATUS_COMPLETED = 3;
165173

166174
/**
167175
* Execution failed with an error.
168176
*/
169-
FAILED = 3;
177+
EXECUTION_STATUS_FAILED = 4;
170178

171179
/**
172180
* Execution was cancelled by the client.
173181
*/
174-
CANCELLED = 4;
182+
EXECUTION_STATUS_CANCELLED = 5;
175183

176184
/**
177185
* Execution exceeded the timeout limit.
178186
*/
179-
TIMEOUT = 5;
187+
EXECUTION_STATUS_TIMEOUT = 6;
180188
}

capabilities-exchange/src/main/proto/healthprobe.proto

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
syntax = "proto3";
22

33
option java_multiple_files = true;
4-
option java_package = "ai.wanaku.core.exchange";
4+
option java_package = "ai.wanaku.core.exchange.v1";
55
option java_outer_classname = "HealthProbeExchange";
66

7-
package health;
7+
package ai.wanaku.health.v1;
88

99
// The health probe service definition.
1010
service HealthProbe {
@@ -19,10 +19,30 @@ message HealthProbeRequest {
1919

2020
// The runtime status of the capability
2121
enum RuntimeStatus {
22-
STOPPED = 0;
23-
STOPPING = 1;
24-
STARTING = 2;
25-
STARTED = 3;
22+
/**
23+
* Unspecified runtime status.
24+
*/
25+
RUNTIME_STATUS_UNSPECIFIED = 0;
26+
27+
/**
28+
* The capability is stopped.
29+
*/
30+
RUNTIME_STATUS_STOPPED = 1;
31+
32+
/**
33+
* The capability is stopping.
34+
*/
35+
RUNTIME_STATUS_STOPPING = 2;
36+
37+
/**
38+
* The capability is starting.
39+
*/
40+
RUNTIME_STATUS_STARTING = 3;
41+
42+
/**
43+
* The capability is started.
44+
*/
45+
RUNTIME_STATUS_STARTED = 4;
2646
}
2747

2848
// The health probe response message

capabilities-exchange/src/main/proto/provision.proto

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
syntax = "proto3";
22

33
option java_multiple_files = true;
4-
option java_package = "ai.wanaku.core.exchange";
4+
option java_package = "ai.wanaku.core.exchange.v1";
55
option java_outer_classname = "ProvisionExchange";
66

7-
package tool;
7+
package ai.wanaku.provision.v1;
88

9-
// The inquirer exchange service definition.
9+
// The provisioner service definition.
1010
service Provisioner {
11-
// Invokes a tool
11+
// Provisions configuration and secrets
1212
rpc Provision (ProvisionRequest) returns (ProvisionReply) {}
1313
}
1414

@@ -17,12 +17,20 @@ service Provisioner {
1717
* itself, etc
1818
*/
1919
enum PayloadType {
20-
REFERENCE = 0;
20+
/**
21+
* Unspecified payload type.
22+
*/
23+
PAYLOAD_TYPE_UNSPECIFIED = 0;
24+
25+
/**
26+
* A reference to an external configuration or secret.
27+
*/
28+
PAYLOAD_TYPE_REFERENCE = 1;
2129

2230
/**
23-
* Invokes tools
31+
* A built-in configuration or secret payload.
2432
*/
25-
BUILTIN = 1;
33+
PAYLOAD_TYPE_BUILTIN = 2;
2634
}
2735

2836
// Represents a configuration reference
@@ -52,9 +60,9 @@ message PropertySchema {
5260
bool required = 3;
5361
}
5462

55-
// The invocation response message
63+
// The provision response message
5664
message ProvisionReply {
57-
string configurationUri = 1;
58-
string secretUri = 2;
65+
string configuration_uri = 1;
66+
string secret_uri = 2;
5967
map<string, PropertySchema> properties = 3;
60-
}
68+
}
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
syntax = "proto3";
22

33
option java_multiple_files = true;
4-
option java_package = "ai.wanaku.core.exchange";
4+
option java_package = "ai.wanaku.core.exchange.v1";
55
option java_outer_classname = "ResourceExchange";
66

7-
package resource;
7+
package ai.wanaku.resource.v1;
88

9-
// The tool exchange service definition.
9+
// The resource exchange service definition.
1010
service ResourceAcquirer {
11-
// Invokes a tool
11+
// Acquires a resource
1212
rpc ResourceAcquire (ResourceRequest) returns (ResourceReply) {}
1313
}
1414

15-
// The invocation request message
15+
// The resource request message
1616
message ResourceRequest {
1717
string location = 1;
1818
string type = 2;
1919
string name = 3;
2020
map<string, string> params = 4;
21-
string configurationURI = 5;
22-
string secretsURI = 6;
21+
string configuration_uri = 5;
22+
string secrets_uri = 6;
2323
}
2424

25-
// The invocation response message
25+
// The resource response message
2626
message ResourceReply {
27-
bool isError = 1;
27+
reserved 1;
28+
reserved "isError";
2829
repeated string content = 2;
29-
}
30+
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
syntax = "proto3";
22

33
option java_multiple_files = true;
4-
option java_package = "ai.wanaku.core.exchange";
4+
option java_package = "ai.wanaku.core.exchange.v1";
55
option java_outer_classname = "ToolExchange";
66

7-
package tool;
7+
package ai.wanaku.tool.v1;
88

99
// The tool exchange service definition.
1010
service ToolInvoker {
@@ -17,13 +17,14 @@ message ToolInvokeRequest {
1717
string uri = 1;
1818
string body = 2;
1919
map<string, string> arguments = 3;
20-
string configurationURI = 4;
21-
string secretsURI = 5;
20+
string configuration_uri = 4;
21+
string secrets_uri = 5;
2222
map<string, string> headers = 6;
2323
}
2424

2525
// The invocation response message
2626
message ToolInvokeReply {
27-
bool isError = 1;
27+
reserved 1;
28+
reserved "isError";
2829
repeated string content = 2;
29-
}
30+
}

0 commit comments

Comments
 (0)