Skip to content

Commit 6e1b76b

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: Add sandboxes.pause() and sandboxes.resume() methods to the Agent Engine sandbox SDK across Python, Java, and JS SDKs.
PiperOrigin-RevId: 971502868
1 parent a907304 commit 6e1b76b

5 files changed

Lines changed: 314 additions & 0 deletions

File tree

src/converters/_sandboxenvironments_converters.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,29 @@ export function listAgentEngineSandboxesRequestParametersToVertex(
193193

194194
return toObject;
195195
}
196+
197+
export function pauseAgentEngineSandboxRequestParametersToVertex(
198+
fromObject: types.PauseAgentEngineSandboxRequestParameters,
199+
): Record<string, unknown> {
200+
const toObject: Record<string, unknown> = {};
201+
202+
const fromName = common.getValueByPath(fromObject, ['name']);
203+
if (fromName != null) {
204+
common.setValueByPath(toObject, ['_url', 'name'], fromName);
205+
}
206+
207+
return toObject;
208+
}
209+
210+
export function resumeAgentEngineSandboxRequestParametersToVertex(
211+
fromObject: types.ResumeAgentEngineSandboxRequestParameters,
212+
): Record<string, unknown> {
213+
const toObject: Record<string, unknown> = {};
214+
215+
const fromName = common.getValueByPath(fromObject, ['name']);
216+
if (fromName != null) {
217+
common.setValueByPath(toObject, ['_url', 'name'], fromName);
218+
}
219+
220+
return toObject;
221+
}

src/converters/_sandboxes_converters.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,29 @@ export function listAgentEngineSandboxesRequestParametersToVertex(
193193

194194
return toObject;
195195
}
196+
197+
export function pauseAgentEngineSandboxRequestParametersToVertex(
198+
fromObject: types.PauseAgentEngineSandboxRequestParameters,
199+
): Record<string, unknown> {
200+
const toObject: Record<string, unknown> = {};
201+
202+
const fromName = common.getValueByPath(fromObject, ['name']);
203+
if (fromName != null) {
204+
common.setValueByPath(toObject, ['_url', 'name'], fromName);
205+
}
206+
207+
return toObject;
208+
}
209+
210+
export function resumeAgentEngineSandboxRequestParametersToVertex(
211+
fromObject: types.ResumeAgentEngineSandboxRequestParameters,
212+
): Record<string, unknown> {
213+
const toObject: Record<string, unknown> = {};
214+
215+
const fromName = common.getValueByPath(fromObject, ['name']);
216+
if (fromName != null) {
217+
common.setValueByPath(toObject, ['_url', 'name'], fromName);
218+
}
219+
220+
return toObject;
221+
}

src/sandboxenvironments.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,88 @@ export class SandboxEnvironments extends BaseModule {
344344
);
345345
}
346346
}
347+
348+
async pauseInternal(
349+
params: types.PauseAgentEngineSandboxRequestParameters,
350+
): Promise<types.AgentEngineSandboxOperation> {
351+
let response: Promise<types.AgentEngineSandboxOperation>;
352+
353+
let path: string = '';
354+
let queryParams: Record<string, string> = {};
355+
if (this.apiClient.isVertexAI()) {
356+
const body =
357+
converters.pauseAgentEngineSandboxRequestParametersToVertex(params);
358+
path = common.formatMap(
359+
'{name}/:pause',
360+
body['_url'] as Record<string, unknown>,
361+
);
362+
queryParams = body['_query'] as Record<string, string>;
363+
delete body['_url'];
364+
delete body['_query'];
365+
delete body['config'];
366+
367+
response = this.apiClient
368+
.request({
369+
path: path,
370+
queryParams: queryParams,
371+
body: JSON.stringify(body),
372+
httpMethod: 'POST',
373+
httpOptions: params.config?.httpOptions,
374+
abortSignal: params.config?.abortSignal,
375+
})
376+
.then((httpResponse) => {
377+
return httpResponse.json();
378+
}) as Promise<types.AgentEngineSandboxOperation>;
379+
380+
return response.then((resp) => {
381+
return resp as types.AgentEngineSandboxOperation;
382+
});
383+
} else {
384+
throw new Error(
385+
'This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).',
386+
);
387+
}
388+
}
389+
390+
async resumeInternal(
391+
params: types.ResumeAgentEngineSandboxRequestParameters,
392+
): Promise<types.AgentEngineSandboxOperation> {
393+
let response: Promise<types.AgentEngineSandboxOperation>;
394+
395+
let path: string = '';
396+
let queryParams: Record<string, string> = {};
397+
if (this.apiClient.isVertexAI()) {
398+
const body =
399+
converters.resumeAgentEngineSandboxRequestParametersToVertex(params);
400+
path = common.formatMap(
401+
'{name}/:resume',
402+
body['_url'] as Record<string, unknown>,
403+
);
404+
queryParams = body['_query'] as Record<string, string>;
405+
delete body['_url'];
406+
delete body['_query'];
407+
delete body['config'];
408+
409+
response = this.apiClient
410+
.request({
411+
path: path,
412+
queryParams: queryParams,
413+
body: JSON.stringify(body),
414+
httpMethod: 'POST',
415+
httpOptions: params.config?.httpOptions,
416+
abortSignal: params.config?.abortSignal,
417+
})
418+
.then((httpResponse) => {
419+
return httpResponse.json();
420+
}) as Promise<types.AgentEngineSandboxOperation>;
421+
422+
return response.then((resp) => {
423+
return resp as types.AgentEngineSandboxOperation;
424+
});
425+
} else {
426+
throw new Error(
427+
'This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).',
428+
);
429+
}
430+
}
347431
}

src/sandboxes.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,4 +354,88 @@ export class Sandboxes extends BaseModule {
354354
);
355355
}
356356
}
357+
358+
async pauseInternal(
359+
params: types.PauseAgentEngineSandboxRequestParameters,
360+
): Promise<types.AgentEngineSandboxOperation> {
361+
let response: Promise<types.AgentEngineSandboxOperation>;
362+
363+
let path: string = '';
364+
let queryParams: Record<string, string> = {};
365+
if (this.apiClient.isVertexAI()) {
366+
const body =
367+
converters.pauseAgentEngineSandboxRequestParametersToVertex(params);
368+
path = common.formatMap(
369+
'{name}/:pause',
370+
body['_url'] as Record<string, unknown>,
371+
);
372+
queryParams = body['_query'] as Record<string, string>;
373+
delete body['_url'];
374+
delete body['_query'];
375+
delete body['config'];
376+
377+
response = this.apiClient
378+
.request({
379+
path: path,
380+
queryParams: queryParams,
381+
body: JSON.stringify(body),
382+
httpMethod: 'POST',
383+
httpOptions: params.config?.httpOptions,
384+
abortSignal: params.config?.abortSignal,
385+
})
386+
.then((httpResponse) => {
387+
return httpResponse.json();
388+
}) as Promise<types.AgentEngineSandboxOperation>;
389+
390+
return response.then((resp) => {
391+
return resp as types.AgentEngineSandboxOperation;
392+
});
393+
} else {
394+
throw new Error(
395+
'This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).',
396+
);
397+
}
398+
}
399+
400+
async resumeInternal(
401+
params: types.ResumeAgentEngineSandboxRequestParameters,
402+
): Promise<types.AgentEngineSandboxOperation> {
403+
let response: Promise<types.AgentEngineSandboxOperation>;
404+
405+
let path: string = '';
406+
let queryParams: Record<string, string> = {};
407+
if (this.apiClient.isVertexAI()) {
408+
const body =
409+
converters.resumeAgentEngineSandboxRequestParametersToVertex(params);
410+
path = common.formatMap(
411+
'{name}/:resume',
412+
body['_url'] as Record<string, unknown>,
413+
);
414+
queryParams = body['_query'] as Record<string, string>;
415+
delete body['_url'];
416+
delete body['_query'];
417+
delete body['config'];
418+
419+
response = this.apiClient
420+
.request({
421+
path: path,
422+
queryParams: queryParams,
423+
body: JSON.stringify(body),
424+
httpMethod: 'POST',
425+
httpOptions: params.config?.httpOptions,
426+
abortSignal: params.config?.abortSignal,
427+
})
428+
.then((httpResponse) => {
429+
return httpResponse.json();
430+
}) as Promise<types.AgentEngineSandboxOperation>;
431+
432+
return response.then((resp) => {
433+
return resp as types.AgentEngineSandboxOperation;
434+
});
435+
} else {
436+
throw new Error(
437+
'This method is only supported by the Gemini Enterprise Agent Platform (previously known as Vertex AI).',
438+
);
439+
}
440+
}
357441
}

src/types/common.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,22 @@ export enum DefaultContainerCategory {
188188
DEFAULT_CONTAINER_CATEGORY_SHELL_SANDBOX = 'DEFAULT_CONTAINER_CATEGORY_SHELL_SANDBOX',
189189
}
190190

191+
/** Output only. The state of the PSC service automation. */
192+
export enum PscAutomationState {
193+
/**
194+
* Should not be used.
195+
*/
196+
PSC_AUTOMATION_STATE_UNSPECIFIED = 'PSC_AUTOMATION_STATE_UNSPECIFIED',
197+
/**
198+
* The PSC service automation is successful.
199+
*/
200+
PSC_AUTOMATION_STATE_SUCCESSFUL = 'PSC_AUTOMATION_STATE_SUCCESSFUL',
201+
/**
202+
* The PSC service automation has failed.
203+
*/
204+
PSC_AUTOMATION_STATE_FAILED = 'PSC_AUTOMATION_STATE_FAILED',
205+
}
206+
191207
/** Input only. Action to take on the source SandboxEnvironment after the snapshot is taken. This field is only used in CreateSandboxEnvironmentSnapshotRequest and it is not stored in the resource. */
192208
export enum PostSnapshotAction {
193209
/**
@@ -2329,6 +2345,8 @@ export declare interface SandboxEnvironmentConnectionInfo {
23292345
sandboxInternalIp?: string;
23302346
/** Output only. The routing token for the SandboxEnvironment. */
23312347
routingToken?: string;
2348+
/** Output only. The name of the PSC-E service attachment created for private ingress to this SandboxEnvironment. Only populated when the template enables private ingress (see SandboxEnvironmentTemplate.ingress_control_config). VPC-SC customers use this to create a PSC endpoint in their VPC. */
2349+
serviceAttachment?: string;
23322350
}
23332351

23342352
/** A sandbox environment. */
@@ -2515,6 +2533,50 @@ export declare interface GetAgentEngineSandboxOperationParameters {
25152533
config?: GetAgentEngineOperationConfig;
25162534
}
25172535

2536+
/** Config for pausing an Agent Engine sandbox. */
2537+
export declare interface PauseAgentEngineSandboxConfig {
2538+
/** Used to override HTTP request options. */
2539+
httpOptions?: genaiTypes.HttpOptions;
2540+
/** Abort signal which can be used to cancel the request.
2541+
2542+
NOTE: AbortSignal is a client-only operation. Using it to cancel an
2543+
operation will not cancel the request in the service. You will still
2544+
be charged usage for any applicable operations.
2545+
*/
2546+
abortSignal?: AbortSignal;
2547+
/** Waits for the operation to complete before returning. */
2548+
waitForCompletion?: boolean;
2549+
}
2550+
2551+
/** Parameters for pausing an Agent Engine sandbox. */
2552+
export declare interface PauseAgentEngineSandboxRequestParameters {
2553+
/** Name of the agent engine sandbox to pause. */
2554+
name: string;
2555+
config?: PauseAgentEngineSandboxConfig;
2556+
}
2557+
2558+
/** Config for resuming an Agent Engine sandbox. */
2559+
export declare interface ResumeAgentEngineSandboxConfig {
2560+
/** Used to override HTTP request options. */
2561+
httpOptions?: genaiTypes.HttpOptions;
2562+
/** Abort signal which can be used to cancel the request.
2563+
2564+
NOTE: AbortSignal is a client-only operation. Using it to cancel an
2565+
operation will not cancel the request in the service. You will still
2566+
be charged usage for any applicable operations.
2567+
*/
2568+
abortSignal?: AbortSignal;
2569+
/** Waits for the operation to complete before returning. */
2570+
waitForCompletion?: boolean;
2571+
}
2572+
2573+
/** Parameters for resuming an Agent Engine sandbox. */
2574+
export declare interface ResumeAgentEngineSandboxRequestParameters {
2575+
/** Name of the agent engine sandbox to resume. */
2576+
name: string;
2577+
config?: ResumeAgentEngineSandboxConfig;
2578+
}
2579+
25182580
/** Specification for deploying from a custom container image. */
25192581
export declare interface SandboxEnvironmentTemplateCustomContainerSpec {
25202582
/** Required. The Artifact Registry Docker image URI (e.g., us-central1-docker.pkg.dev/my-project/my-repo/my-image:tag) of the container image that is to be run on each worker replica. */
@@ -2607,6 +2669,36 @@ export declare interface CreateSandboxEnvironmentTemplateRequestParameters {
26072669
config?: CreateSandboxEnvironmentTemplateConfig;
26082670
}
26092671

2672+
/** PSC config that is used to automatically create PSC endpoints in the user projects. */
2673+
export declare interface PSCAutomationConfig {
2674+
/** Output only. Error message if the PSC service automation failed. */
2675+
errorMessage?: string;
2676+
/** Output only. Forwarding rule created by the PSC service automation. */
2677+
forwardingRule?: string;
2678+
/** Output only. IP address rule created by the PSC service automation. */
2679+
ipAddress?: string;
2680+
/** Required. The full name of the Google Compute Engine [network](https://cloud.google.com/compute/docs/networks-and-firewalls#networks). [Format](https://cloud.google.com/compute/docs/reference/rest/v1/networks/get): `projects/{project}/global/networks/{network}`. */
2681+
network?: string;
2682+
/** Required. Project id used to create forwarding rule. */
2683+
projectId?: string;
2684+
/** Output only. The state of the PSC service automation. */
2685+
state?: PscAutomationState;
2686+
}
2687+
2688+
/** Represents configuration for private service connect. */
2689+
export declare interface PrivateServiceConnectConfig {
2690+
/** Required. If true, expose the IndexEndpoint via private service connect. */
2691+
enablePrivateServiceConnect?: boolean;
2692+
/** Optional. If set to true, enable secure private service connect with IAM authorization. Otherwise, private service connect will be done without authorization. Note latency will be slightly increased if authorization is enabled. */
2693+
enableSecurePrivateServiceConnect?: boolean;
2694+
/** A list of Projects from which the forwarding rule will target the service attachment. */
2695+
projectAllowlist?: string[];
2696+
/** Optional. List of projects and networks where the PSC endpoints will be created. This field is used by Online Inference(Prediction) only. */
2697+
pscAutomationConfigs?: PSCAutomationConfig[];
2698+
/** Output only. The name of the generated service attachment resource. This is only populated if the endpoint is deployed with PrivateServiceConnect. */
2699+
serviceAttachment?: string;
2700+
}
2701+
26102702
/** A sandbox environment template. */
26112703
export declare interface SandboxEnvironmentTemplate {
26122704
/** Output only. The timestamp when this SandboxEnvironmentTemplate was created. */
@@ -2631,6 +2723,8 @@ export declare interface SandboxEnvironmentTemplate {
26312723
| 'FAILED';
26322724
/** Output only. The timestamp when this SandboxEnvironmentTemplate was most recently updated. */
26332725
updateTime?: string;
2726+
/** Optional. The configuration for private ingress (PSC-E) of this template. When set, the sandbox router is exposed privately via a PSC service attachment so VPC-SC customers can connect from their VPC over a private endpoint instead of the public internet. The resulting service attachment is surfaced on `SandboxEnvironment.connection_info.service_attachment`. Only the PSC-E (service-attachment/ingress) portion of `PrivateServiceConnectConfig` applies here: `enable_private_service_connect` and `project_allowlist` (the consumer projects allowed to connect). The nested `psc_interface_config` (PSC-I / egress) is not used for sandbox ingress; sandbox egress is configured via `egress_control_config` instead. */
2727+
ingressControlConfig?: PrivateServiceConnectConfig;
26342728
}
26352729

26362730
/** Operation that has an agent engine sandbox as a response. */

0 commit comments

Comments
 (0)