Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@

/** Async module of {@link Memories} */
public final class AsyncMemories {
public final AsyncMemoryRevisions revisions;

Memories memories;
ApiClient apiClient;

public AsyncMemories(ApiClient apiClient) {
this.apiClient = apiClient;
this.memories = new Memories(apiClient);

this.revisions = new AsyncMemoryRevisions(apiClient);
}

CompletableFuture<AgentEngineMemoryOperation> privateCreate(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Auto-generated code. Do not edit.

package com.google.cloud.vertexai.genai;

import com.google.cloud.vertexai.genai.types.GetAgentEngineMemoryRevisionConfig;
import com.google.cloud.vertexai.genai.types.ListAgentEngineMemoryRevisionsConfig;
import com.google.cloud.vertexai.genai.types.ListAgentEngineMemoryRevisionsResponse;
import com.google.cloud.vertexai.genai.types.MemoryRevision;
import com.google.genai.ApiClient;
import com.google.genai.ApiResponse;
import com.google.genai.Common.BuiltRequest;
import java.util.concurrent.CompletableFuture;

/** Async module of {@link MemoryRevisions} */
public final class AsyncMemoryRevisions {

MemoryRevisions memoryRevisions;
ApiClient apiClient;

public AsyncMemoryRevisions(ApiClient apiClient) {
this.apiClient = apiClient;
this.memoryRevisions = new MemoryRevisions(apiClient);
}

public CompletableFuture<MemoryRevision> get(
String name, GetAgentEngineMemoryRevisionConfig config) {

BuiltRequest builtRequest = memoryRevisions.buildRequestForGet(name, config);
return this.apiClient
.asyncRequest("get", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
.thenApplyAsync(
response -> {
try (ApiResponse res = response) {
return memoryRevisions.processResponseForGet(res, config);
}
});
}

CompletableFuture<ListAgentEngineMemoryRevisionsResponse> privateList(
String name, ListAgentEngineMemoryRevisionsConfig config) {

BuiltRequest builtRequest = memoryRevisions.buildRequestForPrivateList(name, config);
return this.apiClient
.asyncRequest("get", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
.thenApplyAsync(
response -> {
try (ApiResponse res = response) {
return memoryRevisions.processResponseForPrivateList(res, config);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@
import okhttp3.ResponseBody;

public final class Memories {
public final MemoryRevisions revisions;

final ApiClient apiClient;

public Memories(ApiClient apiClient) {
this.apiClient = apiClient;
this.revisions = new MemoryRevisions(apiClient);
}

@ExcludeFromGeneratedCoverageReport
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Auto-generated code. Do not edit.

package com.google.cloud.vertexai.genai;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.cloud.vertexai.genai.types.GetAgentEngineMemoryRevisionConfig;
import com.google.cloud.vertexai.genai.types.GetAgentEngineMemoryRevisionRequestParameters;
import com.google.cloud.vertexai.genai.types.ListAgentEngineMemoryRevisionsConfig;
import com.google.cloud.vertexai.genai.types.ListAgentEngineMemoryRevisionsRequestParameters;
import com.google.cloud.vertexai.genai.types.ListAgentEngineMemoryRevisionsResponse;
import com.google.cloud.vertexai.genai.types.MemoryRevision;
import com.google.genai.ApiClient;
import com.google.genai.ApiResponse;
import com.google.genai.Common;
import com.google.genai.Common.BuiltRequest;
import com.google.genai.JsonSerializable;
import com.google.genai.errors.GenAiIOException;
import com.google.genai.types.HttpOptions;
import java.io.IOException;
import java.util.Optional;
import okhttp3.ResponseBody;

public final class MemoryRevisions {

final ApiClient apiClient;

public MemoryRevisions(ApiClient apiClient) {
this.apiClient = apiClient;
}

@ExcludeFromGeneratedCoverageReport
ObjectNode getAgentEngineMemoryRevisionRequestParametersToVertex(
JsonNode fromObject, ObjectNode parentObject) {
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
if (Common.getValueByPath(fromObject, new String[] {"name"}) != null) {
Common.setValueByPath(
toObject,
new String[] {"_url", "name"},
Common.getValueByPath(fromObject, new String[] {"name"}));
}

return toObject;
}

@ExcludeFromGeneratedCoverageReport
ObjectNode listAgentEngineMemoryRevisionsConfigToVertex(
JsonNode fromObject, ObjectNode parentObject) {
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();

if (Common.getValueByPath(fromObject, new String[] {"pageSize"}) != null) {
Common.setValueByPath(
parentObject,
new String[] {"_query", "pageSize"},
Common.getValueByPath(fromObject, new String[] {"pageSize"}));
}

if (Common.getValueByPath(fromObject, new String[] {"pageToken"}) != null) {
Common.setValueByPath(
parentObject,
new String[] {"_query", "pageToken"},
Common.getValueByPath(fromObject, new String[] {"pageToken"}));
}

if (Common.getValueByPath(fromObject, new String[] {"filter"}) != null) {
Common.setValueByPath(
parentObject,
new String[] {"_query", "filter"},
Common.getValueByPath(fromObject, new String[] {"filter"}));
}

return toObject;
}

@ExcludeFromGeneratedCoverageReport
ObjectNode listAgentEngineMemoryRevisionsRequestParametersToVertex(
JsonNode fromObject, ObjectNode parentObject) {
ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
if (Common.getValueByPath(fromObject, new String[] {"name"}) != null) {
Common.setValueByPath(
toObject,
new String[] {"_url", "name"},
Common.getValueByPath(fromObject, new String[] {"name"}));
}

if (Common.getValueByPath(fromObject, new String[] {"config"}) != null) {
JsonNode unused =
listAgentEngineMemoryRevisionsConfigToVertex(
JsonSerializable.toJsonNode(
Common.getValueByPath(fromObject, new String[] {"config"})),
toObject);
}

return toObject;
}

/** A shared buildRequest method for both sync and async methods. */
BuiltRequest buildRequestForGet(String name, GetAgentEngineMemoryRevisionConfig config) {

GetAgentEngineMemoryRevisionRequestParameters.Builder parameterBuilder =
GetAgentEngineMemoryRevisionRequestParameters.builder();

if (!Common.isZero(name)) {
parameterBuilder.name(name);
}
if (!Common.isZero(config)) {
parameterBuilder.config(config);
}
JsonNode parameterNode = JsonSerializable.toJsonNode(parameterBuilder.build());

ObjectNode body;
String path;
if (this.apiClient.vertexAI()) {
body = getAgentEngineMemoryRevisionRequestParametersToVertex(parameterNode, null);
path = Common.formatMap("{name}", body.get("_url"));
} else {
throw new UnsupportedOperationException(
"This method is only supported in the Vertex AI client.");
}
body.remove("_url");

JsonNode queryParams = body.get("_query");
if (queryParams != null) {
body.remove("_query");
path = String.format("%s?%s", path, Common.urlEncode((ObjectNode) queryParams));
}

// TODO: Remove the hack that removes config.
Optional<HttpOptions> requestHttpOptions = Optional.empty();
if (config != null) {
requestHttpOptions = config.httpOptions();
}

return new BuiltRequest(path, JsonSerializable.toJsonString(body), requestHttpOptions);
}

/** A shared processResponse function for both sync and async methods. */
MemoryRevision processResponseForGet(
ApiResponse response, GetAgentEngineMemoryRevisionConfig config) {
ResponseBody responseBody = response.getBody();
String responseString;
try {
responseString = responseBody.string();
} catch (IOException e) {
throw new GenAiIOException("Failed to read HTTP response.", e);
}

JsonNode responseNode = JsonSerializable.stringToJsonNode(responseString);

if (!this.apiClient.vertexAI()) {
throw new UnsupportedOperationException(
"This method is only supported in the Vertex AI client.");
}

return JsonSerializable.fromJsonNode(responseNode, MemoryRevision.class);
}

public MemoryRevision get(String name, GetAgentEngineMemoryRevisionConfig config) {
BuiltRequest builtRequest = buildRequestForGet(name, config);

try (ApiResponse response =
this.apiClient.request(
"get", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())) {
return processResponseForGet(response, config);
}
}

/** A shared buildRequest method for both sync and async methods. */
BuiltRequest buildRequestForPrivateList(
String name, ListAgentEngineMemoryRevisionsConfig config) {

ListAgentEngineMemoryRevisionsRequestParameters.Builder parameterBuilder =
ListAgentEngineMemoryRevisionsRequestParameters.builder();

if (!Common.isZero(name)) {
parameterBuilder.name(name);
}
if (!Common.isZero(config)) {
parameterBuilder.config(config);
}
JsonNode parameterNode = JsonSerializable.toJsonNode(parameterBuilder.build());

ObjectNode body;
String path;
if (this.apiClient.vertexAI()) {
body = listAgentEngineMemoryRevisionsRequestParametersToVertex(parameterNode, null);
path = Common.formatMap("{name}/revisions", body.get("_url"));
} else {
throw new UnsupportedOperationException(
"This method is only supported in the Vertex AI client.");
}
body.remove("_url");

JsonNode queryParams = body.get("_query");
if (queryParams != null) {
body.remove("_query");
path = String.format("%s?%s", path, Common.urlEncode((ObjectNode) queryParams));
}

// TODO: Remove the hack that removes config.
Optional<HttpOptions> requestHttpOptions = Optional.empty();
if (config != null) {
requestHttpOptions = config.httpOptions();
}

return new BuiltRequest(path, JsonSerializable.toJsonString(body), requestHttpOptions);
}

/** A shared processResponse function for both sync and async methods. */
ListAgentEngineMemoryRevisionsResponse processResponseForPrivateList(
ApiResponse response, ListAgentEngineMemoryRevisionsConfig config) {
ResponseBody responseBody = response.getBody();
String responseString;
try {
responseString = responseBody.string();
} catch (IOException e) {
throw new GenAiIOException("Failed to read HTTP response.", e);
}

JsonNode responseNode = JsonSerializable.stringToJsonNode(responseString);

if (!this.apiClient.vertexAI()) {
throw new UnsupportedOperationException(
"This method is only supported in the Vertex AI client.");
}

return JsonSerializable.fromJsonNode(
responseNode, ListAgentEngineMemoryRevisionsResponse.class);
}

public ListAgentEngineMemoryRevisionsResponse privateList(
String name, ListAgentEngineMemoryRevisionsConfig config) {
BuiltRequest builtRequest = buildRequestForPrivateList(name, config);

try (ApiResponse response =
this.apiClient.request(
"get", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())) {
return processResponseForPrivateList(response, config);
}
}
}
Loading
Loading