Skip to content
Open
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
62 changes: 61 additions & 1 deletion src/agentengines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,73 @@ export class AgentEngines extends BaseModule {
public readonly sandboxes: Sandboxes;
public readonly memories: Memories;

/** Cached resource name of the lazily-created default agent engine. */
private defaultAgentEngineName?: string;
/** In-flight promise so concurrent callers share a single default agent engine. */
private defaultAgentEnginePromise?: Promise<string>;

constructor(private readonly apiClient: ApiClient) {
super();
this.sessions = new Sessions(apiClient);
this.sandboxes = new Sandboxes(apiClient);
this.sandboxes = new Sandboxes(apiClient, () =>
this.ensureDefaultAgentEngine(),
);
this.memories = new Memories(apiClient);
}

/**
* Returns the resource name of a shared "default" agent engine for this
* project and location, creating it lazily if it does not exist. This backs
* sandbox calls where the caller does not supply an agent engine name, so
* repeated calls reuse one agent engine instead of creating many.
*/
private async ensureDefaultAgentEngine(): Promise<string> {
if (this.defaultAgentEngineName) {
return this.defaultAgentEngineName;
}
if (!this.defaultAgentEnginePromise) {
this.defaultAgentEnginePromise = this.resolveDefaultAgentEngine().catch(
(e) => {
// Allow a later call to retry if resolution failed.
this.defaultAgentEnginePromise = undefined;
throw e;
},
);
}
return this.defaultAgentEnginePromise;
}

private async resolveDefaultAgentEngine(): Promise<string> {
const displayName = 'default-agent-platform-sandbox-host';
// Reuse an existing default agent engine if one already exists.
const listResponse = await this.listInternal({});
const existing = listResponse.reasoningEngines?.find(
(reasoningEngine) =>
reasoningEngine.displayName === displayName && !!reasoningEngine.name,
);
if (existing?.name) {
this.defaultAgentEngineName = existing.name;
return existing.name;
}
// Otherwise create one and wait for the operation to complete.
let operation = await this.createInternal({config: {displayName}});
while (!operation.done) {
await new Promise((resolve) => setTimeout(resolve, 5000));
operation = await this.getAgentOperationInternal({
operationName: operation.name!,
});
}
if (operation.error) {
throw new Error(
`Failed to create default agent engine: ${JSON.stringify(
operation.error,
)}`,
);
}
this.defaultAgentEngineName = operation.response!.name!;
return this.defaultAgentEngineName;
}

async createInternal(
params: types.CreateAgentEngineRequestParameters,
): Promise<types.AgentEngineOperation> {
Expand Down
9 changes: 9 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import {ApiClient, NodeAuth, NodeDownloader, NodeUploader,} from '@google/genai/vertex_internal';

import {AgentEngines} from './agentengines';
import {Sandboxes} from './sandboxes';
import {Skills} from './skills';
import {Prompts} from './prompts';

Expand Down Expand Up @@ -78,4 +79,12 @@ export class Client {
}
return this._agentEnginesInternal;
}

/**
* Provides access to the Agent Platform Sandboxes API, including its
* `environments`, `templates`, and `snapshots` submodules.
*/
public get sandboxes(): Sandboxes {
return this._agentEnginesInternal.sandboxes;
}
}
195 changes: 195 additions & 0 deletions src/converters/_sandboxenvironments_converters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/**
* @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 common from '@google/genai/vertex_internal';
import * as types from '../types.js';

export function createAgentEngineSandboxConfigToVertex(
fromObject: types.CreateAgentEngineSandboxConfig,
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);
}

const fromTtl = common.getValueByPath(fromObject, ['ttl']);
if (parentObject !== undefined && fromTtl != null) {
common.setValueByPath(parentObject, ['ttl'], fromTtl);
}

const fromSandboxEnvironmentTemplate = common.getValueByPath(fromObject, [
'sandboxEnvironmentTemplate',
]);
if (parentObject !== undefined && fromSandboxEnvironmentTemplate != null) {
common.setValueByPath(
parentObject,
['sandboxEnvironmentTemplate'],
fromSandboxEnvironmentTemplate,
);
}

const fromSandboxEnvironmentSnapshot = common.getValueByPath(fromObject, [
'sandboxEnvironmentSnapshot',
]);
if (parentObject !== undefined && fromSandboxEnvironmentSnapshot != null) {
common.setValueByPath(
parentObject,
['sandboxEnvironmentSnapshot'],
fromSandboxEnvironmentSnapshot,
);
}

const fromOwner = common.getValueByPath(fromObject, ['owner']);
if (parentObject !== undefined && fromOwner != null) {
common.setValueByPath(parentObject, ['owner'], fromOwner);
}

return toObject;
}

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

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

const fromName = common.getValueByPath(fromObject, ['name']);
if (fromName != null) {
common.setValueByPath(toObject, ['_url', 'name'], fromName);
}

return toObject;
}

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

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

const fromOperationName = common.getValueByPath(fromObject, [
'operationName',
]);
if (fromOperationName != null) {
common.setValueByPath(
toObject,
['_url', 'operationName'],
fromOperationName,
);
}

return toObject;
}

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

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

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

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;
}
Loading
Loading