diff --git a/src/genai/agentengines.ts b/src/genai/agentengines.ts index 347f33d2..e5a62026 100644 --- a/src/genai/agentengines.ts +++ b/src/genai/agentengines.ts @@ -17,15 +17,18 @@ import { NodeUploader, } from '@google/genai/vertex_internal'; import * as converters from './converters/_agentengines_converters.js'; +import {Sandboxes} from './sandboxes.js'; import {Sessions} from './sessions.js'; import * as types from './types.js'; export class AgentEngines extends BaseModule { public readonly sessions: Sessions; + public readonly sandboxes: Sandboxes; constructor(private readonly apiClient: ApiClient) { super(); this.sessions = new Sessions(apiClient); + this.sandboxes = new Sandboxes(apiClient); } private async createInternal( diff --git a/src/genai/converters/_sandboxes_converters.ts b/src/genai/converters/_sandboxes_converters.ts new file mode 100644 index 00000000..4bd9c9cc --- /dev/null +++ b/src/genai/converters/_sandboxes_converters.ts @@ -0,0 +1,169 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +// Code generated by the Google Gen AI SDK generator DO NOT EDIT. + +import type * as genaiTypes from '@google/genai'; +import * as common from '@google/genai/vertex_internal'; +import * as types from '../types.js'; + +export function createAgentEngineSandboxConfigToVertex( + fromObject: types.CreateAgentEngineSandboxConfig, + 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); + } + + const fromTtl = common.getValueByPath(fromObject, ['ttl']); + if (parentObject !== undefined && fromTtl != null) { + common.setValueByPath(parentObject, ['ttl'], fromTtl); + } + + return toObject; +} + +export function createAgentEngineSandboxRequestParametersToVertex( + fromObject: types.CreateAgentEngineSandboxRequestParameters, +): Record { + const toObject: Record = {}; + + const fromName = common.getValueByPath(fromObject, ['name']); + if (fromName != null) { + common.setValueByPath(toObject, ['_url', 'name'], fromName); + } + + const fromSpec = common.getValueByPath(fromObject, ['spec']); + if (fromSpec != null) { + common.setValueByPath(toObject, ['spec'], fromSpec); + } + + const fromConfig = common.getValueByPath(fromObject, ['config']); + if (fromConfig != null) { + createAgentEngineSandboxConfigToVertex(fromConfig, toObject); + } + + return toObject; +} + +export function deleteAgentEngineSandboxRequestParametersToVertex( + fromObject: types.DeleteAgentEngineSandboxRequestParameters, +): Record { + const toObject: Record = {}; + + const fromName = common.getValueByPath(fromObject, ['name']); + if (fromName != null) { + common.setValueByPath(toObject, ['_url', 'name'], fromName); + } + + return toObject; +} + +export function executeCodeAgentEngineSandboxRequestParametersToVertex( + fromObject: types.ExecuteCodeAgentEngineSandboxRequestParameters, +): Record { + const toObject: Record = {}; + + const fromName = common.getValueByPath(fromObject, ['name']); + if (fromName != null) { + common.setValueByPath(toObject, ['_url', 'name'], fromName); + } + + const fromInputs = common.getValueByPath(fromObject, ['inputs']); + if (fromInputs != null) { + let transformedList = fromInputs; + if (Array.isArray(transformedList)) { + transformedList = transformedList.map((item) => { + return item; + }); + } + common.setValueByPath(toObject, ['inputs'], transformedList); + } + + return toObject; +} + +export function getAgentEngineSandboxOperationParametersToVertex( + fromObject: types.GetAgentEngineSandboxOperationParameters, +): Record { + const toObject: Record = {}; + + const fromOperationName = common.getValueByPath(fromObject, [ + 'operationName', + ]); + if (fromOperationName != null) { + common.setValueByPath( + toObject, + ['_url', 'operationName'], + fromOperationName, + ); + } + + return toObject; +} + +export function getAgentEngineSandboxRequestParametersToVertex( + fromObject: types.GetAgentEngineSandboxRequestParameters, +): Record { + const toObject: Record = {}; + + const fromName = common.getValueByPath(fromObject, ['name']); + if (fromName != null) { + common.setValueByPath(toObject, ['_url', 'name'], fromName); + } + + return toObject; +} + +export function listAgentEngineSandboxesConfigToVertex( + fromObject: types.ListAgentEngineSandboxesConfig, + parentObject: Record, +): Record { + const toObject: Record = {}; + + const fromPageSize = common.getValueByPath(fromObject, ['pageSize']); + if (parentObject !== undefined && fromPageSize != null) { + common.setValueByPath(parentObject, ['_query', 'pageSize'], fromPageSize); + } + + const fromPageToken = common.getValueByPath(fromObject, ['pageToken']); + if (parentObject !== undefined && fromPageToken != null) { + common.setValueByPath(parentObject, ['_query', 'pageToken'], fromPageToken); + } + + const fromFilter = common.getValueByPath(fromObject, ['filter']); + if (parentObject !== undefined && fromFilter != null) { + common.setValueByPath(parentObject, ['_query', 'filter'], fromFilter); + } + + return toObject; +} + +export function listAgentEngineSandboxesRequestParametersToVertex( + fromObject: types.ListAgentEngineSandboxesRequestParameters, +): Record { + const toObject: Record = {}; + + const fromName = common.getValueByPath(fromObject, ['name']); + if (fromName != null) { + common.setValueByPath(toObject, ['_url', 'name'], fromName); + } + + const fromConfig = common.getValueByPath(fromObject, ['config']); + if (fromConfig != null) { + listAgentEngineSandboxesConfigToVertex(fromConfig, toObject); + } + + return toObject; +} diff --git a/src/genai/sandboxes.ts b/src/genai/sandboxes.ts new file mode 100644 index 00000000..93683504 --- /dev/null +++ b/src/genai/sandboxes.ts @@ -0,0 +1,272 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +// Code generated by the Google Gen AI SDK generator DO NOT EDIT. + +import * as genaiTypes from '@google/genai'; +import {PagedItem, Pager} from '@google/genai'; +import * as common from '@google/genai/vertex_internal'; +import { + ApiClient, + BaseModule, + NodeAuth, + NodeDownloader, + NodeUploader, +} from '@google/genai/vertex_internal'; +import * as converters from './converters/_sandboxes_converters.js'; +import * as types from './types.js'; + +export class Sandboxes extends BaseModule { + constructor(private readonly apiClient: ApiClient) { + super(); + } + + private async createInternal( + params: types.CreateAgentEngineSandboxRequestParameters, + ): Promise { + let response: Promise; + + let path: string = ''; + let queryParams: Record = {}; + if (this.apiClient.isVertexAI()) { + const body = + converters.createAgentEngineSandboxRequestParametersToVertex(params); + path = common.formatMap( + '{name}/sandboxEnvironments', + 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: 'POST', + httpOptions: params.config?.httpOptions, + abortSignal: params.config?.abortSignal, + }) + .then((httpResponse) => { + return httpResponse.json(); + }) as Promise; + + return response.then((resp) => { + return resp as types.AgentEngineSandboxOperation; + }); + } else { + throw new Error('This method is only supported by the Vertex AI.'); + } + } + + private async deleteInternal( + params: types.DeleteAgentEngineSandboxRequestParameters, + ): Promise { + let response: Promise; + + let path: string = ''; + let queryParams: Record = {}; + if (this.apiClient.isVertexAI()) { + const body = + converters.deleteAgentEngineSandboxRequestParametersToVertex(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: 'DELETE', + httpOptions: params.config?.httpOptions, + abortSignal: params.config?.abortSignal, + }) + .then((httpResponse) => { + return httpResponse.json(); + }) as Promise; + + return response.then((resp) => { + return resp as types.DeleteAgentEngineSandboxOperation; + }); + } else { + throw new Error('This method is only supported by the Vertex AI.'); + } + } + + private async executeCodeInternal( + params: types.ExecuteCodeAgentEngineSandboxRequestParameters, + ): Promise { + let response: Promise; + + let path: string = ''; + let queryParams: Record = {}; + if (this.apiClient.isVertexAI()) { + const body = + converters.executeCodeAgentEngineSandboxRequestParametersToVertex( + params, + ); + path = common.formatMap( + '{name}/:execute', + 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: 'POST', + httpOptions: params.config?.httpOptions, + abortSignal: params.config?.abortSignal, + }) + .then((httpResponse) => { + return httpResponse.json(); + }) as Promise; + + return response.then((resp) => { + const typedResp = new types.ExecuteSandboxEnvironmentResponse(); + Object.assign(typedResp, resp); + return typedResp; + }); + } else { + throw new Error('This method is only supported by the Vertex AI.'); + } + } + + private async getInternal( + params: types.GetAgentEngineSandboxRequestParameters, + ): Promise { + let response: Promise; + + let path: string = ''; + let queryParams: Record = {}; + if (this.apiClient.isVertexAI()) { + const body = + converters.getAgentEngineSandboxRequestParametersToVertex(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: 'GET', + httpOptions: params.config?.httpOptions, + abortSignal: params.config?.abortSignal, + }) + .then((httpResponse) => { + return httpResponse.json(); + }) as Promise; + + return response.then((resp) => { + return resp as types.SandboxEnvironment; + }); + } else { + throw new Error('This method is only supported by the Vertex AI.'); + } + } + + private async listInternal( + params: types.ListAgentEngineSandboxesRequestParameters, + ): Promise { + let response: Promise; + + let path: string = ''; + let queryParams: Record = {}; + if (this.apiClient.isVertexAI()) { + const body = + converters.listAgentEngineSandboxesRequestParametersToVertex(params); + path = common.formatMap( + '{name}/sandboxEnvironments', + 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: 'GET', + httpOptions: params.config?.httpOptions, + abortSignal: params.config?.abortSignal, + }) + .then((httpResponse) => { + return httpResponse.json(); + }) as Promise; + + return response.then((resp) => { + const typedResp = new types.ListAgentEngineSandboxesResponse(); + Object.assign(typedResp, resp); + return typedResp; + }); + } else { + throw new Error('This method is only supported by the Vertex AI.'); + } + } + + private async getSandboxOperationInternal( + params: types.GetAgentEngineSandboxOperationParameters, + ): Promise { + let response: Promise; + + let path: string = ''; + let queryParams: Record = {}; + if (this.apiClient.isVertexAI()) { + const body = + converters.getAgentEngineSandboxOperationParametersToVertex(params); + path = common.formatMap( + '{operationName}', + 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: 'GET', + httpOptions: params.config?.httpOptions, + abortSignal: params.config?.abortSignal, + }) + .then((httpResponse) => { + return httpResponse.json(); + }) as Promise; + + return response.then((resp) => { + return resp as types.AgentEngineSandboxOperation; + }); + } else { + throw new Error('This method is only supported by the Vertex AI.'); + } + } +} diff --git a/src/genai/types/common.ts b/src/genai/types/common.ts index 8bc5cc07..e3d67ea4 100644 --- a/src/genai/types/common.ts +++ b/src/genai/types/common.ts @@ -66,6 +66,62 @@ export enum ManagedTopicEnum { EXPLICIT_INSTRUCTIONS = 'EXPLICIT_INSTRUCTIONS', } +/** The coding language supported in this environment. */ +export enum Language { + /** + * The default value. This value is unused. + */ + LANGUAGE_UNSPECIFIED = 'LANGUAGE_UNSPECIFIED', + /** + * The coding language is Python. + */ + LANGUAGE_PYTHON = 'LANGUAGE_PYTHON', + /** + * The coding language is JavaScript. + */ + LANGUAGE_JAVASCRIPT = 'LANGUAGE_JAVASCRIPT', +} + +/** The machine config of the code execution environment. */ +export enum MachineConfig { + /** + * The default value: milligcu 2000, memory 1.5Gib + */ + MACHINE_CONFIG_UNSPECIFIED = 'MACHINE_CONFIG_UNSPECIFIED', + /** + * The default value: milligcu 4000, memory 4 Gib + */ + MACHINE_CONFIG_VCPU4_RAM4GIB = 'MACHINE_CONFIG_VCPU4_RAM4GIB', +} + +/** Output only. The runtime state of the SandboxEnvironment. */ +export enum State { + /** + * The default value. This value is unused. + */ + STATE_UNSPECIFIED = 'STATE_UNSPECIFIED', + /** + * Runtime resources are being allocated for the sandbox environment. + */ + STATE_PROVISIONING = 'STATE_PROVISIONING', + /** + * Sandbox runtime is ready for serving. + */ + STATE_RUNNING = 'STATE_RUNNING', + /** + * Sandbox runtime is halted, performing tear down tasks. + */ + STATE_DEPROVISIONING = 'STATE_DEPROVISIONING', + /** + * Sandbox has terminated with underlying runtime failure. + */ + STATE_TERMINATED = 'STATE_TERMINATED', + /** + * Sandbox runtime has been deleted. + */ + STATE_DELETED = 'STATE_DELETED', +} + /** Framework used to build the application. */ export enum Framework { /** @@ -800,6 +856,241 @@ export declare interface UpdateAgentEngineRequestParameters { config?: UpdateAgentEngineConfig; } +/** The code execution environment with customized settings. */ +export declare interface SandboxEnvironmentSpecCodeExecutionEnvironment { + /** The coding language supported in this environment. */ + codeLanguage?: Language; + /** The machine config of the code execution environment. */ + machineConfig?: MachineConfig; +} + +/** The computer use environment with customized settings. */ +export declare interface SandboxEnvironmentSpecComputerUseEnvironment {} + +/** The specification of a sandbox environment. */ +export declare interface SandboxEnvironmentSpec { + /** Optional. The code execution environment. */ + codeExecutionEnvironment?: SandboxEnvironmentSpecCodeExecutionEnvironment; + /** Optional. The computer use environment. */ + computerUseEnvironment?: SandboxEnvironmentSpecComputerUseEnvironment; +} + +/** Config for creating a Sandbox. */ +export declare interface CreateAgentEngineSandboxConfig { + /** 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 display name of the sandbox. */ + displayName?: string; + /** The description of the sandbox. */ + description?: string; + /** Waits for the operation to complete before returning. */ + waitForCompletion?: boolean; + /** The TTL for this resource. The expiration time is computed: now + TTL. */ + ttl?: string; +} + +/** Parameters for creating Agent Engine Sandboxes. */ +export declare interface CreateAgentEngineSandboxRequestParameters { + /** Name of the agent engine to create the sandbox under. */ + name: string; + /** The specification of the sandbox. */ + spec?: SandboxEnvironmentSpec; + config?: CreateAgentEngineSandboxConfig; +} + +/** The connection information of the SandboxEnvironment. */ +export declare interface SandboxEnvironmentConnectionInfo { + /** Output only. The hostname of the load balancer. */ + loadBalancerHostname?: string; + /** Output only. The IP address of the load balancer. */ + loadBalancerIp?: string; + /** Output only. The internal IP address of the SandboxEnvironment. */ + sandboxInternalIp?: string; +} + +/** A sandbox environment. */ +export declare interface SandboxEnvironment { + /** Expiration time of the sandbox environment. + */ + expireTime?: string; + /** Output only. The connection information of the SandboxEnvironment. */ + connectionInfo?: SandboxEnvironmentConnectionInfo; + /** Output only. The timestamp when this SandboxEnvironment was created. */ + createTime?: string; + /** Required. The display name of the SandboxEnvironment. */ + displayName?: string; + /** Identifier. The name of the SandboxEnvironment. */ + name?: string; + /** Optional. The configuration of the SandboxEnvironment. */ + spec?: SandboxEnvironmentSpec; + /** Output only. The runtime state of the SandboxEnvironment. */ + state?: State; + /** Optional. Input only. The TTL for the sandbox environment. The expiration time is computed: now + TTL. */ + ttl?: string; + /** Output only. The timestamp when this SandboxEnvironment was most recently updated. */ + updateTime?: string; +} + +/** Operation that has an agent engine sandbox as a response. */ +export declare interface AgentEngineSandboxOperation { + /** The server-assigned name, which is only unique within the same service that originally returns it. If you use the default HTTP mapping, the `name` should be a resource name ending with `operations/{unique_id}`. */ + name?: string; + /** Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time. Some services might not provide such metadata. Any method that returns a long-running operation should document the metadata type, if any. */ + metadata?: Record; + /** If the value is `false`, it means the operation is still in progress. If `true`, the operation is completed, and either `error` or `response` is available. */ + done?: boolean; + /** The error result of the operation in case of failure or cancellation. */ + error?: Record; + /** The Agent Engine Sandbox. */ + response?: SandboxEnvironment; +} + +/** Config for deleting an Agent Engine Sandbox. */ +export declare interface DeleteAgentEngineSandboxConfig { + /** 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; +} + +/** Parameters for deleting agent engines. */ +export declare interface DeleteAgentEngineSandboxRequestParameters { + /** Name of the agent engine sandbox to delete. */ + name: string; + config?: DeleteAgentEngineSandboxConfig; +} + +/** Operation for deleting agent engines. */ +export declare interface DeleteAgentEngineSandboxOperation { + /** The server-assigned name, which is only unique within the same service that originally returns it. If you use the default HTTP mapping, the `name` should be a resource name ending with `operations/{unique_id}`. */ + name?: string; + /** Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time. Some services might not provide such metadata. Any method that returns a long-running operation should document the metadata type, if any. */ + metadata?: Record; + /** If the value is `false`, it means the operation is still in progress. If `true`, the operation is completed, and either `error` or `response` is available. */ + done?: boolean; + /** The error result of the operation in case of failure or cancellation. */ + error?: Record; +} + +/** Metadata for a chunk. */ +export declare interface Metadata { + /** Optional. Attributes attached to the data. The keys have semantic conventions and the consumers of the attributes should know how to deserialize the value bytes based on the keys. */ + attributes?: Record; +} + +/** A chunk of data. */ +export declare interface Chunk { + /** Required. The data in the chunk. + * @remarks Encoded as base64 string. */ + data?: string; + /** Optional. Metadata that is associated with the data in the payload. */ + metadata?: Metadata; + /** Required. Mime type of the chunk data. See https://www.iana.org/assignments/media-types/media-types.xhtml for the full list. */ + mimeType?: string; +} + +/** Config for executing code in an Agent Engine sandbox. */ +export declare interface ExecuteCodeAgentEngineSandboxConfig { + /** 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; +} + +/** Parameters for executing code in an agent engine sandbox. */ +export declare interface ExecuteCodeAgentEngineSandboxRequestParameters { + /** Name of the agent engine sandbox to execute code in. */ + name: string; + /** Inputs to the code execution. */ + inputs?: Chunk[]; + config?: ExecuteCodeAgentEngineSandboxConfig; +} + +/** The response for executing a sandbox environment. */ +export class ExecuteSandboxEnvironmentResponse { + /** The outputs from the sandbox environment. */ + outputs?: Chunk[]; +} + +/** Config for getting an Agent Engine Memory. */ +export declare interface GetAgentEngineSandboxConfig { + /** 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; +} + +/** Parameters for getting an agent engine sandbox. */ +export declare interface GetAgentEngineSandboxRequestParameters { + /** Name of the agent engine sandbox. */ + name: string; + config?: GetAgentEngineSandboxConfig; +} + +/** Config for listing agent engine sandboxes. */ +export declare interface ListAgentEngineSandboxesConfig { + /** 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; + pageSize?: number; + pageToken?: string; + /** An expression for filtering the results of the request. + For field names both snake_case and camelCase are supported. */ + filter?: string; +} + +/** Parameters for listing agent engine sandboxes. */ +export declare interface ListAgentEngineSandboxesRequestParameters { + /** Name of the agent engine. */ + name: string; + config?: ListAgentEngineSandboxesConfig; +} + +/** Response for listing agent engine sandboxes. */ +export class ListAgentEngineSandboxesResponse { + /** Used to retain the full HTTP response. */ + sdkHttpResponse?: genaiTypes.HttpResponse; + nextPageToken?: string; + /** List of agent engine sandboxes. */ + sandboxEnvironments?: SandboxEnvironment[]; +} + +/** Parameters for getting an operation with a sandbox as a response. */ +export declare interface GetAgentEngineSandboxOperationParameters { + /** The server-assigned name for the operation. */ + operationName: string; + /** Used to override the default configuration. */ + config?: GetAgentEngineOperationConfig; +} + /** Config for creating a Session. */ export declare interface CreateAgentEngineSessionConfig { /** Used to override HTTP request options. */ diff --git a/test/genai/agentengines_sandboxes_test.ts b/test/genai/agentengines_sandboxes_test.ts new file mode 100644 index 00000000..5c85cd1b --- /dev/null +++ b/test/genai/agentengines_sandboxes_test.ts @@ -0,0 +1,133 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import 'jasmine'; + +import {NodeAuth} from '@google/genai/vertex_internal'; + +import {ReplayClient} from './_replay_client.js'; +describe('AgentEnginesSandboxes', () => { + let client: ReplayClient; + + beforeEach(() => { + client = new ReplayClient({ + project: 'test-project', + location: 'us-central1', + }); + }); + + it('creates an agent engine sandbox', async () => { + const fetchSpy = client.setupReplay( + 'ae_sandboxes_private_create/test_private_create.vertex.json'); + + const createSandboxOp = + await (client.agentEnginesInternal.sandboxes as any).createInternal({ + name: + `projects/964831358985/locations/us-central1/reasoningEngines/2886612747586371584`, + spec: { + codeExecutionEnvironment: { + machineConfig: 'MACHINE_CONFIG_VCPU4_RAM4GIB', + }, + }, + }); + client.verifyInteraction(0, fetchSpy.calls.argsFor(0)); + expect(createSandboxOp.name).toBeDefined(); + client.verifyAllInteractions(); + }); + + it('deletes an agent engine sandbox', async () => { + const fetchSpy = client.setupReplay( + 'ae_sandboxes_private_delete/test_private_delete.vertex.json'); + + const deleteSandboxOp = + await (client.agentEnginesInternal.sandboxes as any).deleteInternal({ + name: + `reasoningEngines/2886612747586371584/sandboxEnvironments/6068475153556176896`, + }); + client.verifyInteraction(0, fetchSpy.calls.argsFor(0)); + expect(deleteSandboxOp.name).toBeDefined(); + client.verifyAllInteractions(); + }); + it('executes code in an agent engine sandbox', async () => { + const fetchSpy = client.setupReplay( + 'ae_sandboxes_private_execute_code/test_private_execute_code.vertex.json'); + + const code = ` +with open("test.txt", "r") as input: + with open("output.txt", "w") as output_txt: + for line in input: + output_txt.write(line) +`; + // Need this to match recorded json file. + const jsonWithSpace = + JSON.stringify({code}).replace('{"code":', '{"code": '); + + const executeCodeResponse = + await (client.agentEnginesInternal.sandboxes as any).executeCodeInternal({ + name: + `reasoningEngines/2886612747586371584/sandboxEnvironments/6068475153556176896`, + inputs: [ + { + mimeType: 'application/json', + data: Buffer.from(jsonWithSpace).toString('base64'), + }, + { + mimeType: 'text/plain', + data: Buffer.from('Hello, world!').toString('base64'), + metadata: { + attributes: { + file_name: Buffer.from('test.txt').toString('base64'), + }, + }, + }, + ], + }); + client.verifyInteraction(0, fetchSpy.calls.argsFor(0)); + expect(executeCodeResponse.outputs).toBeDefined(); + client.verifyAllInteractions(); + }); + it('gets an agent engine sandbox', async () => { + const fetchSpy = client.setupReplay( + 'ae_sandboxes_private_get/test_private_get.vertex.json'); + + const sandboxName = + `projects/964831358985/locations/us-central1/reasoningEngines/2886612747586371584/sandboxEnvironments/3186171392039059456`; + const sandbox = + await (client.agentEnginesInternal.sandboxes as any).getInternal({ + name: sandboxName, + }); + client.verifyInteraction(0, fetchSpy.calls.argsFor(0)); + expect(sandbox.name).toEqual(sandboxName); + client.verifyAllInteractions(); + }); + it('gets an agent engine sandbox operation', async () => { + const fetchSpy = client.setupReplay( + 'ae_sandboxes_private_get_sandbox_operation/test_private_get_operation.vertex.json'); + + const operationName = + `projects/964831358985/locations/us-central1/operations/4799455193970245632`; + const sandbox = await (client.agentEnginesInternal.sandboxes as any) + .getSandboxOperationInternal({ + operationName: operationName, + }); + client.verifyInteraction(0, fetchSpy.calls.argsFor(0)); + expect(sandbox.name).toEqual(operationName); + client.verifyAllInteractions(); + }); + it('lists sandboxes for an agent engine', async () => { + const fetchSpy = client.setupReplay( + 'ae_sandboxes_private_list/test_private_list.vertex.json'); + + const aeName = `reasoningEngines/2886612747586371584`; + const listSandboxesResponse = + await (client.agentEnginesInternal.sandboxes as any).listInternal({ + name: aeName, + }); + client.verifyInteraction(0, fetchSpy.calls.argsFor(0)); + expect(listSandboxesResponse.sandboxEnvironments).toHaveSize(2); + client.verifyAllInteractions(); + }); +}); \ No newline at end of file