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
48 changes: 48 additions & 0 deletions src/converters/_memorybanks_converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -799,3 +799,51 @@ export function structuredMemorySchemaConfigToVertex(

return toObject;
}

export function updateMemoryBankConfigToVertex(
fromObject: types.UpdateMemoryBankConfig,
parentObject: Record<string, unknown>,
): Record<string, unknown> {
const toObject: Record<string, unknown> = {};

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<string, unknown> {
const toObject: Record<string, unknown> = {};

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;
}
43 changes: 43 additions & 0 deletions src/memorybanks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,49 @@ export class MemoryBanks extends BaseModule {
}
}

async updateInternal(
params: types.UpdateMemoryBankRequestParameters,
): Promise<types.MemoryBankOperation> {
let response: Promise<types.MemoryBankOperation>;

let path: string = '';
let queryParams: Record<string, string> = {};
if (this.apiClient.isVertexAI()) {
const body = converters.updateMemoryBankRequestParametersToVertex(params);
path = common.formatMap(
'{name}',
body['_url'] as Record<string, unknown>,
);
queryParams = body['_query'] as Record<string, string>;
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<types.MemoryBankOperation>;

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<types.DeleteMemoryBankOperation> {
Expand Down
29 changes: 29 additions & 0 deletions src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
Loading