| // Copyright 2026 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 |
| // |
| // http://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. |
| |
| // Code generated by the Google Gen AI SDK generator DO NOT EDIT. |
| |
| package agentplatform |
| |
| import ( |
| "context" |
| "fmt" |
| "net/http" |
| "reflect" |
| |
| "cloud.google.com/go/agentplatform/types" |
| "google.golang.org/genai" |
| ) |
| |
| func getAgentEngineMemoryRevisionRequestParametersToVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) { |
| toObject = make(map[string]any) |
| |
| fromName := genai.InternalGetValueByPath(fromObject, []string{"name"}) |
| if fromName != nil { |
| genai.InternalSetValueByPath(toObject, []string{"_url", "name"}, fromName) |
| } |
| |
| return toObject, nil |
| } |
| |
| func listAgentEngineMemoryRevisionsConfigToVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) { |
| toObject = make(map[string]any) |
| |
| fromPageSize := genai.InternalGetValueByPath(fromObject, []string{"pageSize"}) |
| if fromPageSize != nil { |
| genai.InternalSetValueByPath(parentObject, []string{"_query", "pageSize"}, fromPageSize) |
| } |
| |
| fromPageToken := genai.InternalGetValueByPath(fromObject, []string{"pageToken"}) |
| if fromPageToken != nil { |
| genai.InternalSetValueByPath(parentObject, []string{"_query", "pageToken"}, fromPageToken) |
| } |
| |
| fromFilter := genai.InternalGetValueByPath(fromObject, []string{"filter"}) |
| if fromFilter != nil { |
| genai.InternalSetValueByPath(parentObject, []string{"_query", "filter"}, fromFilter) |
| } |
| |
| return toObject, nil |
| } |
| |
| func listAgentEngineMemoryRevisionsRequestParametersToVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) { |
| toObject = make(map[string]any) |
| |
| fromName := genai.InternalGetValueByPath(fromObject, []string{"name"}) |
| if fromName != nil { |
| genai.InternalSetValueByPath(toObject, []string{"_url", "name"}, fromName) |
| } |
| |
| fromConfig := genai.InternalGetValueByPath(fromObject, []string{"config"}) |
| if fromConfig != nil { |
| _, err = listAgentEngineMemoryRevisionsConfigToVertex(fromConfig.(map[string]any), toObject, rootObject) |
| if err != nil { |
| return nil, err |
| } |
| } |
| |
| return toObject, nil |
| } |
| |
| type MemoryRevisions struct { |
| apiClient *genai.InternalAPIClient |
| } |
| |
| func (m MemoryRevisions) Get(ctx context.Context, name string, config *types.GetAgentEngineMemoryRevisionConfig) (*types.MemoryRevision, error) { |
| parameterMap := make(map[string]any) |
| |
| kwargs := map[string]any{"name": name, "config": config} |
| genai.InternalDeepMarshal(kwargs, ¶meterMap) |
| |
| var httpOptions *genai.HTTPOptions |
| if config == nil || config.HTTPOptions == nil { |
| httpOptions = &genai.HTTPOptions{} |
| } else { |
| httpOptions = config.HTTPOptions |
| } |
| if httpOptions.Headers == nil { |
| httpOptions.Headers = http.Header{} |
| } |
| var response = new(types.MemoryRevision) |
| var responseMap map[string]any |
| var toConverter func(map[string]any, map[string]any, map[string]any) (map[string]any, error) |
| if m.apiClient.ClientConfig().Backend == genai.BackendVertexAI { |
| toConverter = getAgentEngineMemoryRevisionRequestParametersToVertex |
| |
| } else { |
| |
| return nil, fmt.Errorf("method Get is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode. You can choose to use Gemini Enterprise Agent Platform by setting ClientConfig.Backend to BackendEnterprise.") |
| |
| } |
| |
| body, err := toConverter(parameterMap, nil, parameterMap) |
| if err != nil { |
| return nil, err |
| } |
| delete(body, "config") |
| var path string |
| var urlParams map[string]any |
| if _, ok := body["_url"]; ok { |
| urlParams = body["_url"].(map[string]any) |
| delete(body, "_url") |
| } |
| if m.apiClient.ClientConfig().Backend == genai.BackendVertexAI { |
| path, err = genai.InternalFormatMap("{name}", urlParams) |
| } else { |
| path, err = genai.InternalFormatMap("None", urlParams) |
| } |
| if err != nil { |
| return nil, fmt.Errorf("invalid url params: %#v.\n%w", urlParams, err) |
| } |
| if _, ok := body["_query"]; ok { |
| query, err := genai.InternalCreateURLQuery(body["_query"].(map[string]any)) |
| if err != nil { |
| return nil, err |
| } |
| path += "?" + query |
| delete(body, "_query") |
| } |
| responseMap, err = genai.SendRequest(ctx, m.apiClient, path, http.MethodGet, body, httpOptions) |
| if err != nil { |
| return nil, err |
| } |
| err = genai.InternalMapToStruct(responseMap, response) |
| if err != nil { |
| return nil, err |
| } |
| |
| if field, ok := reflect.TypeOf(response).Elem().FieldByName("SDKHTTPResponse"); ok { |
| { |
| if reflect.ValueOf(response).Elem().FieldByName("SDKHTTPResponse").IsValid() { |
| { |
| reflect.ValueOf(response).Elem().FieldByName("SDKHTTPResponse").Set(reflect.Zero(field.Type)) |
| } |
| } |
| } |
| } |
| |
| return response, nil |
| } |
| |
| func (m MemoryRevisions) list(ctx context.Context, name string, config *types.ListAgentEngineMemoryRevisionsConfig) (*types.ListAgentEngineMemoryRevisionsResponse, error) { |
| parameterMap := make(map[string]any) |
| |
| kwargs := map[string]any{"name": name, "config": config} |
| genai.InternalDeepMarshal(kwargs, ¶meterMap) |
| |
| var httpOptions *genai.HTTPOptions |
| if config == nil || config.HTTPOptions == nil { |
| httpOptions = &genai.HTTPOptions{} |
| } else { |
| httpOptions = config.HTTPOptions |
| } |
| if httpOptions.Headers == nil { |
| httpOptions.Headers = http.Header{} |
| } |
| var response = new(types.ListAgentEngineMemoryRevisionsResponse) |
| var responseMap map[string]any |
| var toConverter func(map[string]any, map[string]any, map[string]any) (map[string]any, error) |
| if m.apiClient.ClientConfig().Backend == genai.BackendVertexAI { |
| toConverter = listAgentEngineMemoryRevisionsRequestParametersToVertex |
| |
| } else { |
| |
| return nil, fmt.Errorf("method List is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode. You can choose to use Gemini Enterprise Agent Platform by setting ClientConfig.Backend to BackendEnterprise.") |
| |
| } |
| |
| body, err := toConverter(parameterMap, nil, parameterMap) |
| if err != nil { |
| return nil, err |
| } |
| delete(body, "config") |
| var path string |
| var urlParams map[string]any |
| if _, ok := body["_url"]; ok { |
| urlParams = body["_url"].(map[string]any) |
| delete(body, "_url") |
| } |
| if m.apiClient.ClientConfig().Backend == genai.BackendVertexAI { |
| path, err = genai.InternalFormatMap("{name}/revisions", urlParams) |
| } else { |
| path, err = genai.InternalFormatMap("None", urlParams) |
| } |
| if err != nil { |
| return nil, fmt.Errorf("invalid url params: %#v.\n%w", urlParams, err) |
| } |
| if _, ok := body["_query"]; ok { |
| query, err := genai.InternalCreateURLQuery(body["_query"].(map[string]any)) |
| if err != nil { |
| return nil, err |
| } |
| path += "?" + query |
| delete(body, "_query") |
| } |
| responseMap, err = genai.SendRequest(ctx, m.apiClient, path, http.MethodGet, body, httpOptions) |
| if err != nil { |
| return nil, err |
| } |
| err = genai.InternalMapToStruct(responseMap, response) |
| if err != nil { |
| return nil, err |
| } |
| |
| if field, ok := reflect.TypeOf(response).Elem().FieldByName("SDKHTTPResponse"); ok { |
| { |
| if reflect.ValueOf(response).Elem().FieldByName("SDKHTTPResponse").IsValid() { |
| { |
| reflect.ValueOf(response).Elem().FieldByName("SDKHTTPResponse").Set(reflect.Zero(field.Type)) |
| } |
| } |
| } |
| } |
| |
| return response, nil |
| } |
| |
| // List lists the memory revisions for the given name and config, and returns the response. |
| func (m MemoryRevisions) List(ctx context.Context, name string, config *types.ListAgentEngineMemoryRevisionsConfig) (*types.ListAgentEngineMemoryRevisionsResponse, error) { |
| return m.list(ctx, name, config) |
| } |