| // 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 createAgentEngineSessionConfigToVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) { |
| toObject = make(map[string]any) |
| |
| fromDisplayName := genai.InternalGetValueByPath(fromObject, []string{"displayName"}) |
| if fromDisplayName != nil { |
| genai.InternalSetValueByPath(parentObject, []string{"displayName"}, fromDisplayName) |
| } |
| |
| fromSessionState := genai.InternalGetValueByPath(fromObject, []string{"sessionState"}) |
| if fromSessionState != nil { |
| genai.InternalSetValueByPath(parentObject, []string{"sessionState"}, fromSessionState) |
| } |
| |
| fromTtl := genai.InternalGetValueByPath(fromObject, []string{"ttl"}) |
| if fromTtl != nil { |
| genai.InternalSetValueByPath(parentObject, []string{"ttl"}, fromTtl) |
| } |
| |
| fromExpireTime := genai.InternalGetValueByPath(fromObject, []string{"expireTime"}) |
| if fromExpireTime != nil { |
| genai.InternalSetValueByPath(parentObject, []string{"expireTime"}, fromExpireTime) |
| } |
| |
| fromLabels := genai.InternalGetValueByPath(fromObject, []string{"labels"}) |
| if fromLabels != nil { |
| genai.InternalSetValueByPath(parentObject, []string{"labels"}, fromLabels) |
| } |
| |
| fromSessionId := genai.InternalGetValueByPath(fromObject, []string{"sessionId"}) |
| if fromSessionId != nil { |
| genai.InternalSetValueByPath(parentObject, []string{"_query", "sessionId"}, fromSessionId) |
| } |
| |
| return toObject, nil |
| } |
| |
| func createAgentEngineSessionRequestParametersToVertex(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) |
| } |
| |
| fromUserId := genai.InternalGetValueByPath(fromObject, []string{"userId"}) |
| if fromUserId != nil { |
| genai.InternalSetValueByPath(toObject, []string{"userId"}, fromUserId) |
| } |
| |
| fromConfig := genai.InternalGetValueByPath(fromObject, []string{"config"}) |
| if fromConfig != nil { |
| _, err = createAgentEngineSessionConfigToVertex(fromConfig.(map[string]any), toObject, rootObject) |
| if err != nil { |
| return nil, err |
| } |
| } |
| |
| return toObject, nil |
| } |
| |
| func deleteAgentEngineSessionRequestParametersToVertex(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 getAgentEngineSessionOperationParametersToVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) { |
| toObject = make(map[string]any) |
| |
| fromOperationName := genai.InternalGetValueByPath(fromObject, []string{"operationName"}) |
| if fromOperationName != nil { |
| genai.InternalSetValueByPath(toObject, []string{"_url", "operationName"}, fromOperationName) |
| } |
| |
| return toObject, nil |
| } |
| |
| func getAgentEngineSessionRequestParametersToVertex(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 listAgentEngineSessionsConfigToVertex(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 listAgentEngineSessionsRequestParametersToVertex(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 = listAgentEngineSessionsConfigToVertex(fromConfig.(map[string]any), toObject, rootObject) |
| if err != nil { |
| return nil, err |
| } |
| } |
| |
| return toObject, nil |
| } |
| |
| func updateAgentEngineSessionConfigToVertex(fromObject map[string]any, parentObject map[string]any, rootObject map[string]any) (toObject map[string]any, err error) { |
| toObject = make(map[string]any) |
| |
| fromDisplayName := genai.InternalGetValueByPath(fromObject, []string{"displayName"}) |
| if fromDisplayName != nil { |
| genai.InternalSetValueByPath(parentObject, []string{"displayName"}, fromDisplayName) |
| } |
| |
| fromSessionState := genai.InternalGetValueByPath(fromObject, []string{"sessionState"}) |
| if fromSessionState != nil { |
| genai.InternalSetValueByPath(parentObject, []string{"sessionState"}, fromSessionState) |
| } |
| |
| fromTtl := genai.InternalGetValueByPath(fromObject, []string{"ttl"}) |
| if fromTtl != nil { |
| genai.InternalSetValueByPath(parentObject, []string{"ttl"}, fromTtl) |
| } |
| |
| fromExpireTime := genai.InternalGetValueByPath(fromObject, []string{"expireTime"}) |
| if fromExpireTime != nil { |
| genai.InternalSetValueByPath(parentObject, []string{"expireTime"}, fromExpireTime) |
| } |
| |
| fromLabels := genai.InternalGetValueByPath(fromObject, []string{"labels"}) |
| if fromLabels != nil { |
| genai.InternalSetValueByPath(parentObject, []string{"labels"}, fromLabels) |
| } |
| |
| fromSessionId := genai.InternalGetValueByPath(fromObject, []string{"sessionId"}) |
| if fromSessionId != nil { |
| genai.InternalSetValueByPath(parentObject, []string{"_query", "sessionId"}, fromSessionId) |
| } |
| |
| fromUpdateMask := genai.InternalGetValueByPath(fromObject, []string{"updateMask"}) |
| if fromUpdateMask != nil { |
| genai.InternalSetValueByPath(parentObject, []string{"_query", "updateMask"}, fromUpdateMask) |
| } |
| |
| fromUserId := genai.InternalGetValueByPath(fromObject, []string{"userId"}) |
| if fromUserId != nil { |
| genai.InternalSetValueByPath(parentObject, []string{"userId"}, fromUserId) |
| } |
| |
| return toObject, nil |
| } |
| |
| func updateAgentEngineSessionRequestParametersToVertex(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 = updateAgentEngineSessionConfigToVertex(fromConfig.(map[string]any), toObject, rootObject) |
| if err != nil { |
| return nil, err |
| } |
| } |
| |
| return toObject, nil |
| } |
| |
| type Sessions struct { |
| apiClient *genai.InternalAPIClient |
| SessionEvents *SessionEvents |
| } |
| |
| func (m Sessions) create(ctx context.Context, name string, userId string, config *types.CreateAgentEngineSessionConfig) (*types.AgentEngineSessionOperation, error) { |
| parameterMap := make(map[string]any) |
| |
| kwargs := map[string]any{"name": name, "userId": userId, "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.AgentEngineSessionOperation) |
| 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 = createAgentEngineSessionRequestParametersToVertex |
| |
| } else { |
| |
| return nil, fmt.Errorf("method Create 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}/sessions", 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.MethodPost, 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 Sessions) Delete(ctx context.Context, name string, config *types.DeleteAgentEngineSessionConfig) (*types.DeleteAgentEngineSessionOperation, 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.DeleteAgentEngineSessionOperation) |
| 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 = deleteAgentEngineSessionRequestParametersToVertex |
| |
| } else { |
| |
| return nil, fmt.Errorf("method Delete 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.MethodDelete, 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 Sessions) Get(ctx context.Context, name string, config *types.GetAgentEngineSessionConfig) (*types.Session, 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.Session) |
| 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 = getAgentEngineSessionRequestParametersToVertex |
| |
| } 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 Sessions) list(ctx context.Context, name string, config *types.ListAgentEngineSessionsConfig) (*types.ListReasoningEnginesSessionsResponse, 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.ListReasoningEnginesSessionsResponse) |
| 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 = listAgentEngineSessionsRequestParametersToVertex |
| |
| } 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}/sessions", 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 Sessions) getSessionOperation(ctx context.Context, operationName string, config *types.GetAgentEngineOperationConfig) (*types.AgentEngineSessionOperation, error) { |
| parameterMap := make(map[string]any) |
| |
| kwargs := map[string]any{"operationName": operationName, "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.AgentEngineSessionOperation) |
| 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 = getAgentEngineSessionOperationParametersToVertex |
| |
| } else { |
| |
| return nil, fmt.Errorf("method GetSessionOperation 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("{operationName}", 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 Sessions) update(ctx context.Context, name string, config *types.UpdateAgentEngineSessionConfig) (*types.AgentEngineSessionOperation, 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.AgentEngineSessionOperation) |
| 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 = updateAgentEngineSessionRequestParametersToVertex |
| |
| } else { |
| |
| return nil, fmt.Errorf("method Update 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.MethodPatch, 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 |
| } |
| |
| // Create creates a session for the given name, user ID, and config, and returns the session |
| // operation. |
| func (m Sessions) Create(ctx context.Context, name string, userId string, config *types.CreateAgentEngineSessionConfig) (*types.AgentEngineSessionOperation, error) { |
| return m.create(ctx, name, userId, config) |
| } |
| |
| // List lists the sessions for the given name and config, and returns the response. |
| func (m Sessions) List(ctx context.Context, name string, config *types.ListAgentEngineSessionsConfig) (*types.ListReasoningEnginesSessionsResponse, error) { |
| return m.list(ctx, name, config) |
| } |
| |
| // GetSessionOperation returns the session operation for the given operation name and config, and |
| // returns the session operation representing the get session process. |
| func (m Sessions) GetSessionOperation(ctx context.Context, operationName string, config *types.GetAgentEngineOperationConfig) (*types.AgentEngineSessionOperation, error) { |
| return m.getSessionOperation(ctx, operationName, config) |
| } |
| |
| // Update updates the session with the specified name and returns the session operation representing |
| // the update session process. |
| func (m Sessions) Update(ctx context.Context, name string, config *types.UpdateAgentEngineSessionConfig) (*types.AgentEngineSessionOperation, error) { |
| return m.update(ctx, name, config) |
| } |