@google/adk 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/dist/cjs/agents/functions.js +4 -0
  2. package/dist/cjs/auth/oauth2/oauth2_discovery.js +26 -2
  3. package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +305 -0
  4. package/dist/cjs/code_executors/code_execution_utils.js +1 -1
  5. package/dist/cjs/common.js +11 -0
  6. package/dist/cjs/events/event.js +3 -1
  7. package/dist/cjs/index.js +14 -0
  8. package/dist/cjs/integrations/agent_registry/agent_registry.js +362 -0
  9. package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +103 -0
  10. package/dist/cjs/integrations/agent_registry/helpers.js +57 -0
  11. package/dist/cjs/integrations/agent_registry/types.js +50 -0
  12. package/dist/cjs/memory/vertex_ai_memory_bank_service.js +496 -0
  13. package/dist/cjs/runner/in_memory_runner.js +10 -5
  14. package/dist/cjs/runner/runner.js +32 -2
  15. package/dist/cjs/sessions/database_session_service.js +49 -3
  16. package/dist/cjs/sessions/in_memory_session_service.js +70 -14
  17. package/dist/cjs/sessions/registry.js +4 -0
  18. package/dist/cjs/sessions/vertex_ai_session_service.js +428 -0
  19. package/dist/cjs/tools/agent_tool.js +10 -5
  20. package/dist/cjs/tools/exit_loop_tool.js +9 -0
  21. package/dist/cjs/tools/function_tool.js +7 -2
  22. package/dist/cjs/tools/google_maps_grounding_tool.js +80 -0
  23. package/dist/cjs/tools/long_running_tool.js +2 -1
  24. package/dist/cjs/tools/mcp/mcp_session_manager.js +11 -0
  25. package/dist/cjs/tools/mcp/mcp_tool.js +10 -6
  26. package/dist/cjs/tools/mcp/mcp_toolset.js +26 -3
  27. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +78 -0
  28. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +84 -0
  29. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +133 -0
  30. package/dist/cjs/tools/skill/load_skill_resource_tool.js +2 -25
  31. package/dist/cjs/tools/vertex_rag_retrieval_tool.js +64 -0
  32. package/dist/cjs/utils/file_utils.js +28 -0
  33. package/dist/cjs/utils/gemini_schema_util.js +18 -0
  34. package/dist/cjs/utils/partial_copy.js +51 -0
  35. package/dist/cjs/utils/streaming_utils.js +167 -121
  36. package/dist/cjs/utils/vertex_ai_utils.js +50 -0
  37. package/dist/cjs/version.js +1 -1
  38. package/dist/esm/agents/functions.js +4 -0
  39. package/dist/esm/auth/oauth2/oauth2_discovery.js +26 -2
  40. package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +281 -0
  41. package/dist/esm/code_executors/code_execution_utils.js +1 -1
  42. package/dist/esm/common.js +10 -0
  43. package/dist/esm/events/event.js +3 -1
  44. package/dist/esm/index.js +11 -0
  45. package/dist/esm/integrations/agent_registry/agent_registry.js +333 -0
  46. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +77 -0
  47. package/dist/esm/integrations/agent_registry/helpers.js +28 -0
  48. package/dist/esm/integrations/agent_registry/types.js +20 -0
  49. package/dist/esm/memory/vertex_ai_memory_bank_service.js +468 -0
  50. package/dist/esm/runner/in_memory_runner.js +10 -5
  51. package/dist/esm/runner/runner.js +32 -2
  52. package/dist/esm/sessions/database_session_service.js +49 -3
  53. package/dist/esm/sessions/in_memory_session_service.js +70 -14
  54. package/dist/esm/sessions/registry.js +7 -0
  55. package/dist/esm/sessions/vertex_ai_session_service.js +403 -0
  56. package/dist/esm/tools/agent_tool.js +10 -5
  57. package/dist/esm/tools/exit_loop_tool.js +9 -0
  58. package/dist/esm/tools/function_tool.js +7 -2
  59. package/dist/esm/tools/google_maps_grounding_tool.js +54 -0
  60. package/dist/esm/tools/long_running_tool.js +2 -1
  61. package/dist/esm/tools/mcp/mcp_session_manager.js +11 -0
  62. package/dist/esm/tools/mcp/mcp_tool.js +10 -6
  63. package/dist/esm/tools/mcp/mcp_toolset.js +26 -3
  64. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +48 -0
  65. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
  66. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
  67. package/dist/esm/tools/skill/load_skill_resource_tool.js +1 -24
  68. package/dist/esm/tools/vertex_rag_retrieval_tool.js +36 -0
  69. package/dist/esm/utils/file_utils.js +26 -0
  70. package/dist/esm/utils/gemini_schema_util.js +18 -0
  71. package/dist/esm/utils/partial_copy.js +23 -0
  72. package/dist/esm/utils/streaming_utils.js +165 -120
  73. package/dist/esm/utils/vertex_ai_utils.js +22 -0
  74. package/dist/esm/version.js +1 -1
  75. package/dist/types/a2a/a2a_remote_agent.d.ts +14 -0
  76. package/dist/types/agents/processors/base_llm_processor.d.ts +12 -4
  77. package/dist/types/agents/processors/basic_llm_request_processor.d.ts +5 -0
  78. package/dist/types/agents/processors/identity_llm_request_processor.d.ts +4 -0
  79. package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +5 -0
  80. package/dist/types/agents/run_config.d.ts +15 -0
  81. package/dist/types/code_executors/agent_engine_sandbox_code_executor.d.ts +51 -0
  82. package/dist/types/common.d.ts +4 -0
  83. package/dist/types/events/event_actions.d.ts +24 -6
  84. package/dist/types/events/structured_events.d.ts +13 -0
  85. package/dist/types/examples/example_util.d.ts +25 -0
  86. package/dist/types/index.d.ts +6 -0
  87. package/dist/types/integrations/agent_registry/agent_registry.d.ts +94 -0
  88. package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +43 -0
  89. package/dist/types/integrations/agent_registry/helpers.d.ts +7 -0
  90. package/dist/types/integrations/agent_registry/types.d.ts +101 -0
  91. package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +52 -0
  92. package/dist/types/runner/in_memory_runner.d.ts +28 -1
  93. package/dist/types/runner/runner.d.ts +47 -0
  94. package/dist/types/sessions/base_session_service.d.ts +18 -0
  95. package/dist/types/sessions/database_session_service.d.ts +1 -1
  96. package/dist/types/sessions/in_memory_session_service.d.ts +1 -1
  97. package/dist/types/sessions/vertex_ai_session_service.d.ts +37 -0
  98. package/dist/types/tools/exit_loop_tool.d.ts +9 -0
  99. package/dist/types/tools/function_tool.d.ts +22 -2
  100. package/dist/types/tools/google_maps_grounding_tool.d.ts +22 -0
  101. package/dist/types/tools/long_running_tool.d.ts +11 -1
  102. package/dist/types/tools/mcp/mcp_session_manager.d.ts +3 -0
  103. package/dist/types/tools/mcp/mcp_toolset.d.ts +2 -1
  104. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +25 -0
  105. package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +20 -0
  106. package/dist/types/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.d.ts +20 -0
  107. package/dist/types/tools/vertex_rag_retrieval_tool.d.ts +42 -0
  108. package/dist/types/utils/file_utils.d.ts +2 -0
  109. package/dist/types/utils/partial_copy.d.ts +13 -0
  110. package/dist/types/utils/streaming_utils.d.ts +8 -17
  111. package/dist/types/utils/vertex_ai_utils.d.ts +14 -0
  112. package/dist/types/version.d.ts +1 -1
  113. package/dist/web/agents/functions.js +4 -0
  114. package/dist/web/auth/oauth2/oauth2_discovery.js +26 -2
  115. package/dist/web/code_executors/agent_engine_sandbox_code_executor.js +281 -0
  116. package/dist/web/code_executors/code_execution_utils.js +1 -1
  117. package/dist/web/common.js +10 -0
  118. package/dist/web/events/event.js +3 -1
  119. package/dist/web/index.js +11 -0
  120. package/dist/web/integrations/agent_registry/agent_registry.js +333 -0
  121. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +90 -0
  122. package/dist/web/integrations/agent_registry/helpers.js +28 -0
  123. package/dist/web/integrations/agent_registry/types.js +20 -0
  124. package/dist/web/memory/vertex_ai_memory_bank_service.js +475 -0
  125. package/dist/web/runner/in_memory_runner.js +10 -5
  126. package/dist/web/runner/runner.js +32 -2
  127. package/dist/web/sessions/database_session_service.js +49 -3
  128. package/dist/web/sessions/in_memory_session_service.js +70 -14
  129. package/dist/web/sessions/registry.js +7 -0
  130. package/dist/web/sessions/vertex_ai_session_service.js +414 -0
  131. package/dist/web/tools/agent_tool.js +10 -5
  132. package/dist/web/tools/exit_loop_tool.js +9 -0
  133. package/dist/web/tools/function_tool.js +7 -2
  134. package/dist/web/tools/google_maps_grounding_tool.js +54 -0
  135. package/dist/web/tools/long_running_tool.js +2 -1
  136. package/dist/web/tools/mcp/mcp_session_manager.js +11 -0
  137. package/dist/web/tools/mcp/mcp_tool.js +10 -6
  138. package/dist/web/tools/mcp/mcp_toolset.js +26 -3
  139. package/dist/web/tools/openapi_tool/auth/auth_helpers.js +48 -0
  140. package/dist/web/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
  141. package/dist/web/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
  142. package/dist/web/tools/skill/load_skill_resource_tool.js +1 -24
  143. package/dist/web/tools/vertex_rag_retrieval_tool.js +36 -0
  144. package/dist/web/utils/file_utils.js +26 -0
  145. package/dist/web/utils/gemini_schema_util.js +18 -0
  146. package/dist/web/utils/partial_copy.js +23 -0
  147. package/dist/web/utils/streaming_utils.js +219 -121
  148. package/dist/web/utils/vertex_ai_utils.js +22 -0
  149. package/dist/web/version.js +1 -1
  150. package/package.json +2 -1
@@ -5,6 +5,15 @@
5
5
  */
6
6
  import { FunctionDeclaration } from '@google/genai';
7
7
  import { FunctionTool, ToolInputParameters, ToolOptions } from './function_tool.js';
8
+ /**
9
+ * A {@link FunctionTool} for long-running operations whose result is returned
10
+ * asynchronously.
11
+ *
12
+ * The framework invokes the user-provided function and delivers the response
13
+ * back to the model once it completes, identified by the `function_call_id`.
14
+ * The model is also instructed not to re-invoke the tool while a call is
15
+ * already in flight.
16
+ */
8
17
  export declare class LongRunningFunctionTool<TParameters extends ToolInputParameters = undefined> extends FunctionTool<TParameters> {
9
18
  /**
10
19
  * The constructor acts as the user-friendly factory.
@@ -12,7 +21,8 @@ export declare class LongRunningFunctionTool<TParameters extends ToolInputParame
12
21
  */
13
22
  constructor(options: ToolOptions<TParameters>);
14
23
  /**
15
- * Provide a schema for the function.
24
+ * Returns the function declaration with an appended instruction warning the
25
+ * model not to re-invoke the tool while it is still running.
16
26
  */
17
27
  _getDeclaration(): FunctionDeclaration;
18
28
  }
@@ -59,6 +59,9 @@ export type MCPConnectionParams = StdioConnectionParams | StreamableHTTPConnecti
59
59
  */
60
60
  export declare class MCPSessionManager {
61
61
  private readonly connectionParams;
62
+ private readonly activeSessions;
62
63
  constructor(connectionParams: MCPConnectionParams);
63
64
  createSession(): Promise<Client>;
65
+ closeSession(client: Client): Promise<void>;
66
+ getActiveSessions(): Client[];
64
67
  }
@@ -3,6 +3,7 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ import { ReadonlyContext } from '../../agents/readonly_context.js';
6
7
  import { BaseTool } from '../base_tool.js';
7
8
  import { BaseToolset, ToolPredicate } from '../base_toolset.js';
8
9
  import { MCPConnectionParams } from './mcp_session_manager.js';
@@ -38,6 +39,6 @@ import { MCPConnectionParams } from './mcp_session_manager.js';
38
39
  export declare class MCPToolset extends BaseToolset {
39
40
  private readonly mcpSessionManager;
40
41
  constructor(connectionParams: MCPConnectionParams, toolFilter?: ToolPredicate | string[], prefix?: string);
41
- getTools(): Promise<BaseTool[]>;
42
+ getTools(context?: ReadonlyContext): Promise<BaseTool[]>;
42
43
  close(): Promise<void>;
43
44
  }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { OpenAPIV3 } from 'openapi-types';
7
+ import { AuthCredential } from '../../../auth/auth_credential.js';
8
+ /**
9
+ * Applies the given credential to the request headers and URL.
10
+ *
11
+ * @param url The target URL.
12
+ * @param headers The request headers.
13
+ * @param credential The auth credential.
14
+ * @param authScheme The auth scheme from OpenAPI spec.
15
+ * @returns The updated URL (if modified by query params).
16
+ */
17
+ export declare function applyCredential(url: string, headers: Record<string, string>, credential?: AuthCredential, authScheme?: OpenAPIV3.SecuritySchemeObject): string;
18
+ /**
19
+ * Helper to create a simple API Key auth scheme.
20
+ */
21
+ export declare function createApiKeyScheme(name: string, inLocation: 'header' | 'query' | 'cookie'): OpenAPIV3.SecuritySchemeObject;
22
+ /**
23
+ * Helper to create a simple Bearer Token auth scheme.
24
+ */
25
+ export declare function createBearerScheme(): OpenAPIV3.SecuritySchemeObject;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { AuthCredential } from '../../../../auth/auth_credential.js';
7
+ import { AuthScheme } from '../../../../auth/auth_schemes.js';
8
+ import { BaseCredentialExchanger, ExchangeResult } from '../../../../auth/exchanger/base_credential_exchanger.js';
9
+ /**
10
+ * Automatically selects the appropriate credential exchanger based on the auth scheme.
11
+ * Ported from Python implementation.
12
+ */
13
+ export declare class AutoAuthCredentialExchanger implements BaseCredentialExchanger {
14
+ private exchangers;
15
+ constructor();
16
+ exchange(params: {
17
+ authScheme?: AuthScheme;
18
+ authCredential: AuthCredential;
19
+ }): Promise<ExchangeResult>;
20
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { AuthCredential } from '../../../../auth/auth_credential.js';
7
+ import { AuthScheme } from '../../../../auth/auth_schemes.js';
8
+ import { BaseCredentialExchanger, ExchangeResult } from '../../../../auth/exchanger/base_credential_exchanger.js';
9
+ /**
10
+ * Fetches credentials for Google Service Account.
11
+ * Ported from Python implementation.
12
+ */
13
+ export declare class ServiceAccountCredentialExchanger implements BaseCredentialExchanger {
14
+ exchange(params: {
15
+ authScheme?: AuthScheme;
16
+ authCredential: AuthCredential;
17
+ }): Promise<ExchangeResult>;
18
+ private exchangeForDefaultCredential;
19
+ private exchangeForExplicitCredential;
20
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { VertexRagStore } from '@google/genai';
7
+ import { BaseTool, ToolProcessLlmRequest } from './base_tool.js';
8
+ /**
9
+ * A tool that retrieves relevant content from a Vertex AI RAG corpus to ground
10
+ * model responses.
11
+ *
12
+ * This tool operates server-side; it modifies the LLM request config to enable
13
+ * RAG retrieval via the `retrieval.vertexRagStore` field and does not perform
14
+ * local code execution.
15
+ *
16
+ * **Note:** The Vertex AI RAG Engine only supports one corpus per
17
+ * `ragResources` array. Create one `VertexRagRetrievalTool` instance per
18
+ * corpus.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { VertexRagRetrievalTool } from '@google/adk';
23
+ * import { VertexRagStore } from '@google/genai';
24
+ *
25
+ * const ragTool = new VertexRagRetrievalTool({
26
+ * ragResources: [{ragCorpus: 'projects/my-project/locations/us-central1/ragCorpora/my-corpus'}],
27
+ * similarityTopK: 5,
28
+ * });
29
+ *
30
+ * const agent = new LlmAgent({ tools: [ragTool], ... });
31
+ * ```
32
+ */
33
+ export declare class VertexRagRetrievalTool extends BaseTool {
34
+ private readonly vertexRagStore;
35
+ constructor(config: VertexRagStore);
36
+ /**
37
+ * This tool is executed server-side by the Vertex AI RAG Engine.
38
+ * Local execution is not required.
39
+ */
40
+ runAsync(): Promise<unknown>;
41
+ processLlmRequest({ llmRequest, }: ToolProcessLlmRequest): Promise<void>;
42
+ }
@@ -9,3 +9,5 @@ import { File } from '../code_executors/code_execution_utils.js';
9
9
  * @param files The files to materialize.
10
10
  */
11
11
  export declare function materializeFiles(files: File[], dir?: string): Promise<File[]>;
12
+ export declare const EXTENSION_TO_MIME_TYPE: Record<string, string>;
13
+ export declare function guessMimeType(filePath: string): string;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Copies a set of keys from one object to another.
8
+ *
9
+ * @param source The source object.
10
+ * @param targetKeys The keys to copy.
11
+ * @returns A new object with the specified keys copied from source.
12
+ */
13
+ export declare function partialCopy<TDest extends object>(source: object, targetKeys: (keyof TDest)[]): TDest;
@@ -3,7 +3,7 @@
3
3
  * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { GenerateContentResponse } from '@google/genai';
6
+ import { GenerateContentResponse, Part } from '@google/genai';
7
7
  import { LlmResponse } from '../models/llm_response.js';
8
8
  /**
9
9
  * Aggregates partial streaming responses.
@@ -17,24 +17,15 @@ export declare class StreamingResponseAggregator {
17
17
  private groundingMetadata?;
18
18
  private citationMetadata?;
19
19
  private response?;
20
- private text;
21
- private thoughtText;
22
- private partsSequence;
23
- private currentTextBuffer;
24
- private currentTextIsThought?;
25
20
  private finishReason?;
26
- private currentFcName?;
27
- private currentFcArgs;
28
- private currentFcId?;
29
- private currentThoughtSignature?;
30
- private lastThoughtSignature?;
21
+ private lastThoughtSignature;
22
+ private sawFunctionCall;
23
+ private readonly strategy;
31
24
  constructor(isProgressiveMode?: boolean);
32
- private flushTextBufferToSequence;
33
- private getValueFromPartialArg;
34
- private setValueByJsonPath;
35
- private flushFunctionCallToSequence;
36
- private processStreamingFunctionCall;
37
- private processFunctionCallPart;
38
25
  processResponse(response: GenerateContentResponse): AsyncGenerator<LlmResponse, void, void>;
39
26
  close(): LlmResponse | undefined;
40
27
  }
28
+ /**
29
+ * Checks if a response part has no meaningful content (empty text, no tool calls, etc.)
30
+ */
31
+ export declare function isEmptyContentPart(part: Part): boolean;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Validates and returns the API key for Express Mode.
8
+ *
9
+ * @param project The project id.
10
+ * @param location The location.
11
+ * @param expressModeApiKey The API key for Express Mode.
12
+ * @returns The resolved API key or undefined.
13
+ */
14
+ export declare function getExpressModeApiKey(project?: string, location?: string, expressModeApiKey?: string): string | undefined;
@@ -3,4 +3,4 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- export declare const version = "1.1.0";
6
+ export declare const version = "1.2.0";
@@ -159,6 +159,8 @@ function buildResponseEvent(tool, functionResult, toolContext, invocationContext
159
159
  let responseResult;
160
160
  if (typeof functionResult !== "object" || functionResult == null) {
161
161
  responseResult = { result: functionResult };
162
+ } else if (Array.isArray(functionResult)) {
163
+ responseResult = { results: functionResult };
162
164
  } else {
163
165
  responseResult = functionResult;
164
166
  }
@@ -297,6 +299,8 @@ async function handleFunctionCallList({
297
299
  functionResponse = { error: functionResponseError };
298
300
  } else if (typeof functionResponse !== "object" || functionResponse == null) {
299
301
  functionResponse = { result: functionResponse };
302
+ } else if (Array.isArray(functionResponse)) {
303
+ functionResponse = { results: functionResponse };
300
304
  }
301
305
  const functionResponseEvent = createEvent({
302
306
  invocationId: invocationContext.invocationId,
@@ -123,6 +123,18 @@ class OAuth2DiscoveryManager {
123
123
  return void 0;
124
124
  }
125
125
  }
126
+ function normaliseHostname(raw) {
127
+ const stripped = raw.replace(/^\[|\]$/g, "");
128
+ const m = stripped.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i);
129
+ if (m) {
130
+ const hi = parseInt(m[1], 16);
131
+ const lo = parseInt(m[2], 16);
132
+ return [hi >> 8 & 255, hi & 255, lo >> 8 & 255, lo & 255].join(".");
133
+ }
134
+ const mDot = stripped.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/i);
135
+ if (mDot) return mDot[1];
136
+ return raw;
137
+ }
126
138
  function validateDiscoveryUrl(urlStr) {
127
139
  try {
128
140
  const url = new URL(urlStr);
@@ -130,8 +142,8 @@ function validateDiscoveryUrl(urlStr) {
130
142
  logger.warn("Unsafe protocol for discovery URL: ".concat(url.protocol));
131
143
  return false;
132
144
  }
133
- const host = url.hostname.toLowerCase();
134
- if (host === "localhost" || host === "127.0.0.1" || host === "[::1]" || host.startsWith("10.") || host.startsWith("192.168.") || host.startsWith("169.254.")) {
145
+ const host = normaliseHostname(url.hostname.toLowerCase());
146
+ if (host === "localhost" || host === "127.0.0.1" || host === "[::1]" || host === "0.0.0.0" || host.startsWith("10.") || host.startsWith("192.168.") || host.startsWith("169.254.")) {
135
147
  logger.warn("Unsafe host for discovery URL: ".concat(host));
136
148
  return false;
137
149
  }
@@ -143,6 +155,18 @@ function validateDiscoveryUrl(urlStr) {
143
155
  return false;
144
156
  }
145
157
  }
158
+ const cgnatMatch = host.match(/^100\.(\d+)\./);
159
+ if (cgnatMatch) {
160
+ const secondOctet = parseInt(cgnatMatch[1], 10);
161
+ if (secondOctet >= 64 && secondOctet <= 127) {
162
+ logger.warn("Unsafe host for discovery URL: ".concat(host));
163
+ return false;
164
+ }
165
+ }
166
+ if (/^\[(f[cd][0-9a-f]{2}|fe[89ab][0-9a-f]):/i.test(url.hostname)) {
167
+ logger.warn("Unsafe host for discovery URL: ".concat(url.hostname));
168
+ return false;
169
+ }
146
170
  return true;
147
171
  } catch (e) {
148
172
  logger.warn("Failed to parse URL for validation ".concat(urlStr, ": ").concat(e));
@@ -0,0 +1,281 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __decorateClass = (decorators, target, key, kind) => {
6
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
7
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
8
+ if (decorator = decorators[i])
9
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
10
+ if (kind && result) __defProp(target, key, result);
11
+ return result;
12
+ };
13
+ /**
14
+ * @license
15
+ * Copyright 2026 Google LLC
16
+ * SPDX-License-Identifier: Apache-2.0
17
+ */
18
+ import { Client } from "@google-cloud/vertexai";
19
+ import { Language } from "@google-cloud/vertexai/build/src/genai/types.js";
20
+ import { experimental } from "../utils/experimental.js";
21
+ import { guessMimeType } from "../utils/file_utils.js";
22
+ const SANDBOX_PATTERN = /^projects\/([a-zA-Z0-9-_]+)\/locations\/([a-zA-Z0-9-_]+)\/reasoningEngines\/(\d+)\/sandboxEnvironments\/(\d+)$/;
23
+ const ENGINE_PATTERN = /^projects\/([a-zA-Z0-9-_]+)\/locations\/([a-zA-Z0-9-_]+)\/reasoningEngines\/(\d+)$/;
24
+ import { logger } from "../utils/logger.js";
25
+ import { BaseCodeExecutor } from "./base_code_executor.js";
26
+ import {
27
+ CodeExecutionLanguage
28
+ } from "./code_execution_utils.js";
29
+ const DEFAULT_MAX_ATTEMPTS = 180;
30
+ const DEFAULT_SANDBOX_TTL = "31536000s";
31
+ const DEFAULT_SANDBOX_DISPLAY_NAME = "default_sandbox";
32
+ const DEFAULT_ENGINE_DISPLAY_NAME = "default_engine";
33
+ function mapLanguage(lang) {
34
+ switch (lang) {
35
+ case CodeExecutionLanguage.PYTHON:
36
+ return Language.LANGUAGE_PYTHON;
37
+ case CodeExecutionLanguage.JAVASCRIPT:
38
+ return Language.LANGUAGE_JAVASCRIPT;
39
+ default:
40
+ throw new Error("Unsupported language for Agent Engine Sandbox: ".concat(lang));
41
+ }
42
+ }
43
+ let AgentEngineSandboxCodeExecutor = class extends BaseCodeExecutor {
44
+ constructor(options = {}) {
45
+ super();
46
+ this.sandboxResourceName = options.sandboxResourceName;
47
+ this.agentEngineResourceName = options.agentEngineResourceName;
48
+ this.projectId = options.projectId || process.env.GOOGLE_CLOUD_PROJECT;
49
+ this.location = options.location || process.env.GOOGLE_CLOUD_LOCATION || "us-central1";
50
+ if (this.sandboxResourceName) {
51
+ const match = this.sandboxResourceName.match(SANDBOX_PATTERN);
52
+ if (match) {
53
+ this.projectId = match[1];
54
+ this.location = match[2];
55
+ } else {
56
+ throw new Error(
57
+ "Invalid sandbox resource name: ".concat(this.sandboxResourceName)
58
+ );
59
+ }
60
+ } else if (this.agentEngineResourceName) {
61
+ const match = this.agentEngineResourceName.match(ENGINE_PATTERN);
62
+ if (match) {
63
+ this.projectId = match[1];
64
+ this.location = match[2];
65
+ } else {
66
+ throw new Error(
67
+ "Invalid agent engine resource name: ".concat(this.agentEngineResourceName)
68
+ );
69
+ }
70
+ }
71
+ if (options.client) {
72
+ this.client = options.client;
73
+ } else {
74
+ if (!this.projectId) {
75
+ throw new Error("Project ID is required.");
76
+ }
77
+ this.client = new Client({
78
+ project: this.projectId,
79
+ location: this.location
80
+ });
81
+ }
82
+ }
83
+ async executeCode(params) {
84
+ var _a;
85
+ const { invocationContext, codeExecutionInput } = params;
86
+ const language = mapLanguage(codeExecutionInput.language);
87
+ const agentEngineName = await this.getOrCreateAgentEngine();
88
+ const sandboxName = await this.getOrCreateSandbox(
89
+ invocationContext,
90
+ agentEngineName,
91
+ language
92
+ );
93
+ const inputs = [
94
+ {
95
+ mimeType: "application/json",
96
+ data: Buffer.from(
97
+ JSON.stringify({ code: codeExecutionInput.code })
98
+ ).toString("base64")
99
+ }
100
+ ];
101
+ if (codeExecutionInput.inputFiles) {
102
+ for (const file of codeExecutionInput.inputFiles) {
103
+ inputs.push({
104
+ mimeType: file.mimeType,
105
+ data: file.content,
106
+ // Assumed to be already base64 encoded based on CodeExecutionInput definition
107
+ metadata: {
108
+ attributes: {
109
+ file_name: Buffer.from(file.name).toString("base64")
110
+ }
111
+ }
112
+ });
113
+ }
114
+ }
115
+ logger.debug("Executing code in sandbox ".concat(sandboxName, "..."));
116
+ const response = await this.client.agentEnginesInternal.sandboxes.executeCodeInternal({
117
+ name: sandboxName,
118
+ inputs
119
+ });
120
+ let stdout = "";
121
+ let stderr = "";
122
+ const outputFiles = [];
123
+ if (response.outputs) {
124
+ for (const output of response.outputs) {
125
+ const attributes = ((_a = output.metadata) == null ? void 0 : _a.attributes) || {};
126
+ const encodedFileName = attributes["file_name"];
127
+ const fileName = encodedFileName ? Buffer.from(encodedFileName, "base64").toString("utf-8") : void 0;
128
+ if (output.mimeType === "application/json" && !fileName) {
129
+ if (output.data) {
130
+ const jsonStr = Buffer.from(output.data, "base64").toString(
131
+ "utf-8"
132
+ );
133
+ try {
134
+ const jsonData = JSON.parse(jsonStr);
135
+ if (jsonData.msg_out !== void 0) {
136
+ stdout = jsonData.msg_out;
137
+ } else {
138
+ stdout = "";
139
+ }
140
+ if (jsonData.msg_err !== void 0) {
141
+ stderr = jsonData.msg_err;
142
+ } else {
143
+ stderr = "";
144
+ }
145
+ } catch (e) {
146
+ logger.warn("Failed to parse JSON output from sandbox", e);
147
+ stdout = jsonStr;
148
+ }
149
+ }
150
+ } else {
151
+ let mimeType = output.mimeType;
152
+ const name = fileName || "output_file";
153
+ if (!mimeType) {
154
+ mimeType = guessMimeType(name);
155
+ }
156
+ outputFiles.push({
157
+ name,
158
+ content: output.data || "",
159
+ mimeType
160
+ });
161
+ }
162
+ }
163
+ }
164
+ return {
165
+ stdout,
166
+ stderr,
167
+ outputFiles
168
+ };
169
+ }
170
+ async getOrCreateAgentEngine() {
171
+ if (this.agentEngineResourceName) {
172
+ return this.agentEngineResourceName;
173
+ }
174
+ if (!this.agentEngineCreationPromise) {
175
+ this.agentEngineCreationPromise = (async () => {
176
+ logger.debug(
177
+ "No Agent Engine resource name provided. Creating a new one..."
178
+ );
179
+ const operation = await this.client.agentEnginesInternal.createInternal(
180
+ {
181
+ config: {
182
+ displayName: DEFAULT_ENGINE_DISPLAY_NAME
183
+ }
184
+ }
185
+ );
186
+ let apiResponse = operation;
187
+ let attempts = 0;
188
+ while (!apiResponse.done && attempts < DEFAULT_MAX_ATTEMPTS) {
189
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
190
+ apiResponse = await this.client.agentEnginesInternal.getAgentOperationInternal({
191
+ operationName: operation.name
192
+ });
193
+ attempts++;
194
+ }
195
+ if (!apiResponse.done) {
196
+ throw new Error(
197
+ "Agent Engine creation operation ".concat(operation.name, " did not complete in time.")
198
+ );
199
+ }
200
+ const response = apiResponse.response;
201
+ this.agentEngineResourceName = response.name;
202
+ logger.debug("Created Agent Engine: ".concat(this.agentEngineResourceName));
203
+ return this.agentEngineResourceName;
204
+ })();
205
+ }
206
+ return this.agentEngineCreationPromise;
207
+ }
208
+ async getOrCreateSandbox(invocationContext, agentEngineName, language) {
209
+ var _a, _b;
210
+ if (this.sandboxResourceName) {
211
+ return this.sandboxResourceName;
212
+ }
213
+ const stateKey = "sandbox_name_".concat(language.toLowerCase());
214
+ let sandboxName = (_b = (_a = invocationContext.session) == null ? void 0 : _a.state) == null ? void 0 : _b[stateKey];
215
+ let createNewSandbox = false;
216
+ if (!sandboxName) {
217
+ createNewSandbox = true;
218
+ } else {
219
+ try {
220
+ const sandbox = await this.client.agentEnginesInternal.sandboxes.getInternal({
221
+ name: sandboxName
222
+ });
223
+ if (!sandbox || sandbox.state !== "STATE_RUNNING") {
224
+ createNewSandbox = true;
225
+ }
226
+ } catch (error) {
227
+ logger.debug(
228
+ "Failed to get sandbox ".concat(sandboxName, ", will create a new one"),
229
+ error
230
+ );
231
+ createNewSandbox = true;
232
+ }
233
+ }
234
+ if (createNewSandbox) {
235
+ logger.debug("Creating a new ".concat(language, " code execution sandbox..."));
236
+ const operation = await this.client.agentEnginesInternal.sandboxes.createInternal({
237
+ name: agentEngineName,
238
+ spec: {
239
+ codeExecutionEnvironment: {
240
+ codeLanguage: language
241
+ }
242
+ },
243
+ config: {
244
+ displayName: DEFAULT_SANDBOX_DISPLAY_NAME,
245
+ ttl: DEFAULT_SANDBOX_TTL
246
+ }
247
+ });
248
+ let apiResponse = operation;
249
+ let attempts = 0;
250
+ while (!apiResponse.done && attempts < DEFAULT_MAX_ATTEMPTS) {
251
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
252
+ apiResponse = await this.client.agentEnginesInternal.sandboxes.getSandboxOperationInternal(
253
+ {
254
+ operationName: operation.name
255
+ }
256
+ );
257
+ attempts++;
258
+ }
259
+ if (!apiResponse.done) {
260
+ throw new Error(
261
+ "Sandbox creation operation ".concat(operation.name, " did not complete in time.")
262
+ );
263
+ }
264
+ const response = apiResponse.response;
265
+ sandboxName = response.name;
266
+ if (invocationContext.session) {
267
+ if (!invocationContext.session.state) {
268
+ invocationContext.session.state = {};
269
+ }
270
+ invocationContext.session.state[stateKey] = sandboxName;
271
+ }
272
+ }
273
+ return sandboxName;
274
+ }
275
+ };
276
+ AgentEngineSandboxCodeExecutor = __decorateClass([
277
+ experimental
278
+ ], AgentEngineSandboxCodeExecutor);
279
+ export {
280
+ AgentEngineSandboxCodeExecutor
281
+ };
@@ -47,7 +47,7 @@ function extractCodeAndTruncateContent(content, codeBlockDelimiters) {
47
47
  const leadingDelimiterPattern = codeBlockDelimiters.map((d) => d[0]).join("|");
48
48
  const trailingDelimiterPattern = codeBlockDelimiters.map((d) => d[1]).join("|");
49
49
  const match = new RegExp(
50
- "?<prefix>.*?)(".concat(leadingDelimiterPattern, ")(?<codeStr>.*?)(").concat(trailingDelimiterPattern, ")(?<suffix>.*?)$"),
50
+ "(?<prefix>.*?)(".concat(leadingDelimiterPattern, ")(?<codeStr>.*?)(").concat(trailingDelimiterPattern, ")(?<suffix>.*?)$"),
51
51
  "s"
52
52
  ).exec(responseText);
53
53
  const { prefix, codeStr } = (match == null ? void 0 : match.groups) || {};
@@ -64,6 +64,7 @@ import {
64
64
  isBaseExampleProvider
65
65
  } from "./examples/base_example_provider.js";
66
66
  import { InMemoryMemoryService } from "./memory/in_memory_memory_service.js";
67
+ import { VertexAiMemoryBankService } from "./memory/vertex_ai_memory_bank_service.js";
67
68
  import { ApigeeLlm } from "./models/apigee_llm.js";
68
69
  import { BaseLlm, isBaseLlm } from "./models/base_llm.js";
69
70
  import { Gemini, geminiInitParams } from "./models/google_llm.js";
@@ -90,6 +91,10 @@ import { BaseTool, isBaseTool } from "./tools/base_tool.js";
90
91
  import { BaseToolset, isBaseToolset } from "./tools/base_toolset.js";
91
92
  import { EXIT_LOOP, ExitLoopTool } from "./tools/exit_loop_tool.js";
92
93
  import { FunctionTool, isFunctionTool } from "./tools/function_tool.js";
94
+ import {
95
+ GOOGLE_MAPS_GROUNDING,
96
+ GoogleMapsGroundingTool
97
+ } from "./tools/google_maps_grounding_tool.js";
93
98
  import { GOOGLE_SEARCH, GoogleSearchTool } from "./tools/google_search_tool.js";
94
99
  import {
95
100
  LOAD_ARTIFACTS,
@@ -104,6 +109,7 @@ import {
104
109
  import { ToolConfirmation } from "./tools/tool_confirmation.js";
105
110
  import { URL_CONTEXT, UrlContextTool } from "./tools/url_context_tool.js";
106
111
  import { VertexAiSearchTool } from "./tools/vertex_ai_search_tool.js";
112
+ import { VertexRagRetrievalTool } from "./tools/vertex_rag_retrieval_tool.js";
107
113
  import { LogLevel, getLogger, setLogLevel, setLogger } from "./utils/logger.js";
108
114
  import { isGemini2OrAbove } from "./utils/model_name.js";
109
115
  import { zodObjectToSchema } from "./utils/simple_zod_to_json.js";
@@ -151,9 +157,11 @@ export {
151
157
  ExitLoopTool,
152
158
  FileContentEncoding,
153
159
  FunctionTool,
160
+ GOOGLE_MAPS_GROUNDING,
154
161
  GOOGLE_SEARCH,
155
162
  Gemini,
156
163
  GoogleLLMVariant,
164
+ GoogleMapsGroundingTool,
157
165
  GoogleSearchTool,
158
166
  InMemoryArtifactService,
159
167
  InMemoryCredentialService,
@@ -201,7 +209,9 @@ export {
201
209
  TruncatingContextCompactor,
202
210
  URL_CONTEXT,
203
211
  UrlContextTool,
212
+ VertexAiMemoryBankService,
204
213
  VertexAiSearchTool,
214
+ VertexRagRetrievalTool,
205
215
  createEvent,
206
216
  createEventActions,
207
217
  createSession,