diff --git a/src/converters/_memorybanks_converters.ts b/src/converters/_memorybanks_converters.ts index 88dfd9ec..cd0a7ef2 100644 --- a/src/converters/_memorybanks_converters.ts +++ b/src/converters/_memorybanks_converters.ts @@ -799,3 +799,51 @@ export function structuredMemorySchemaConfigToVertex( return toObject; } + +export function updateMemoryBankConfigToVertex( + fromObject: types.UpdateMemoryBankConfig, + parentObject: Record, +): Record { + const toObject: Record = {}; + + const fromDisplayName = common.getValueByPath(fromObject, ['displayName']); + if (parentObject !== undefined && fromDisplayName != null) { + common.setValueByPath(parentObject, ['displayName'], fromDisplayName); + } + + const fromDescription = common.getValueByPath(fromObject, ['description']); + if (parentObject !== undefined && fromDescription != null) { + common.setValueByPath(parentObject, ['description'], fromDescription); + } + + return toObject; +} + +export function updateMemoryBankRequestParametersToVertex( + fromObject: types.UpdateMemoryBankRequestParameters, +): Record { + const toObject: Record = {}; + + const fromName = common.getValueByPath(fromObject, ['name']); + if (fromName != null) { + common.setValueByPath(toObject, ['_url', 'name'], fromName); + } + + const fromMemoryBankConfig = common.getValueByPath(fromObject, [ + 'memoryBankConfig', + ]); + if (fromMemoryBankConfig != null) { + common.setValueByPath( + toObject, + ['context_spec', 'memory_bank_config'], + reasoningEngineContextSpecMemoryBankConfigToVertex(fromMemoryBankConfig), + ); + } + + const fromConfig = common.getValueByPath(fromObject, ['config']); + if (fromConfig != null) { + updateMemoryBankConfigToVertex(fromConfig, toObject); + } + + return toObject; +} diff --git a/src/memorybanks.ts b/src/memorybanks.ts index e1738285..64bed7dd 100644 --- a/src/memorybanks.ts +++ b/src/memorybanks.ts @@ -63,6 +63,49 @@ export class MemoryBanks extends BaseModule { } } + async updateInternal( + params: types.UpdateMemoryBankRequestParameters, + ): Promise { + let response: Promise; + + let path: string = ''; + let queryParams: Record = {}; + if (this.apiClient.isVertexAI()) { + const body = converters.updateMemoryBankRequestParametersToVertex(params); + path = common.formatMap( + '{name}', + body['_url'] as Record, + ); + queryParams = body['_query'] as Record; + delete body['_url']; + delete body['_query']; + delete body['config']; + + response = this.apiClient + .request({ + path: path, + queryParams: queryParams, + body: JSON.stringify(body), + httpMethod: 'PATCH', + httpOptions: params.config?.httpOptions, + abortSignal: params.config?.abortSignal, + }) + .then((httpResponse) => { + return httpResponse.json(); + }) as Promise; + + return response.then((apiResponse) => { + const resp = converters.memoryBankOperationFromVertex(apiResponse); + + return resp as types.MemoryBankOperation; + }); + } else { + throw new Error( + 'This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).', + ); + } + } + async deleteInternal( params: types.DeleteMemoryBankRequestParameters, ): Promise { diff --git a/src/types/common.ts b/src/types/common.ts index 10d6dcd1..ca4fb1b3 100644 --- a/src/types/common.ts +++ b/src/types/common.ts @@ -1410,6 +1410,35 @@ export declare interface MemoryBankOperation { response?: MemoryBank; } +/** Config for updating a memory bank. */ +export declare interface UpdateMemoryBankConfig { + /** Used to override HTTP request options. */ + httpOptions?: genaiTypes.HttpOptions; + /** Abort signal which can be used to cancel the request. + + NOTE: AbortSignal is a client-only operation. Using it to cancel an + operation will not cancel the request in the service. You will still + be charged usage for any applicable operations. + */ + abortSignal?: AbortSignal; + /** The user-defined name of the Memory Bank. + + The display name can be up to 128 characters long and can comprise any + UTF-8 characters. + */ + displayName?: string; + /** The description of the Memory Bank. */ + description?: string; +} + +/** Parameters for updating memory banks. */ +export declare interface UpdateMemoryBankRequestParameters { + /** Name of the memory bank. */ + name: string; + memoryBankConfig?: ReasoningEngineContextSpecMemoryBankConfig; + config?: UpdateMemoryBankConfig; +} + /** Config for delete memory bank. */ export declare interface DeleteMemoryBankConfig { /** Used to override HTTP request options. */