@google/adk 1.0.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.
- package/dist/cjs/agents/functions.js +4 -0
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +305 -0
- package/dist/cjs/code_executors/code_execution_utils.js +1 -1
- package/dist/cjs/common.js +19 -0
- package/dist/cjs/events/event.js +3 -1
- package/dist/cjs/index.js +97 -125
- package/dist/cjs/integrations/agent_registry/agent_registry.js +362 -0
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +103 -0
- package/dist/cjs/integrations/agent_registry/helpers.js +57 -0
- package/dist/cjs/integrations/agent_registry/types.js +50 -0
- package/dist/cjs/memory/vertex_ai_memory_bank_service.js +496 -0
- package/dist/cjs/runner/in_memory_runner.js +10 -5
- package/dist/cjs/runner/runner.js +32 -2
- package/dist/cjs/sessions/database_session_service.js +49 -3
- package/dist/cjs/sessions/in_memory_session_service.js +70 -14
- package/dist/cjs/sessions/registry.js +4 -0
- package/dist/cjs/sessions/vertex_ai_session_service.js +428 -0
- package/dist/cjs/tools/agent_tool.js +11 -6
- package/dist/cjs/tools/exit_loop_tool.js +9 -0
- package/dist/cjs/tools/function_tool.js +7 -2
- package/dist/cjs/tools/google_maps_grounding_tool.js +80 -0
- package/dist/cjs/tools/long_running_tool.js +2 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/cjs/tools/mcp/mcp_tool.js +12 -7
- package/dist/cjs/tools/mcp/mcp_toolset.js +27 -4
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +78 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +84 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +133 -0
- package/dist/cjs/tools/skill/load_skill_resource_tool.js +2 -25
- package/dist/cjs/tools/url_context_tool.js +73 -0
- package/dist/cjs/tools/vertex_ai_search_tool.js +127 -0
- package/dist/cjs/tools/vertex_rag_retrieval_tool.js +64 -0
- package/dist/cjs/utils/file_utils.js +28 -0
- package/dist/cjs/utils/gemini_schema_util.js +18 -0
- package/dist/cjs/utils/model_name.js +8 -2
- package/dist/cjs/utils/partial_copy.js +51 -0
- package/dist/cjs/utils/streaming_utils.js +167 -121
- package/dist/cjs/utils/vertex_ai_utils.js +50 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/functions.js +4 -0
- package/dist/esm/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +281 -0
- package/dist/esm/code_executors/code_execution_utils.js +1 -1
- package/dist/esm/common.js +15 -0
- package/dist/esm/events/event.js +3 -1
- package/dist/esm/index.js +54 -130
- package/dist/esm/integrations/agent_registry/agent_registry.js +333 -0
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +77 -0
- package/dist/esm/integrations/agent_registry/helpers.js +28 -0
- package/dist/esm/integrations/agent_registry/types.js +20 -0
- package/dist/esm/memory/vertex_ai_memory_bank_service.js +468 -0
- package/dist/esm/runner/in_memory_runner.js +10 -5
- package/dist/esm/runner/runner.js +32 -2
- package/dist/esm/sessions/database_session_service.js +49 -3
- package/dist/esm/sessions/in_memory_session_service.js +70 -14
- package/dist/esm/sessions/registry.js +7 -0
- package/dist/esm/sessions/vertex_ai_session_service.js +403 -0
- package/dist/esm/tools/agent_tool.js +11 -6
- package/dist/esm/tools/exit_loop_tool.js +9 -0
- package/dist/esm/tools/function_tool.js +7 -2
- package/dist/esm/tools/google_maps_grounding_tool.js +54 -0
- package/dist/esm/tools/long_running_tool.js +2 -1
- package/dist/esm/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/esm/tools/mcp/mcp_tool.js +12 -7
- package/dist/esm/tools/mcp/mcp_toolset.js +27 -4
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +48 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
- package/dist/esm/tools/skill/load_skill_resource_tool.js +1 -24
- package/dist/esm/tools/url_context_tool.js +44 -0
- package/dist/esm/tools/vertex_ai_search_tool.js +103 -0
- package/dist/esm/tools/vertex_rag_retrieval_tool.js +36 -0
- package/dist/esm/utils/file_utils.js +26 -0
- package/dist/esm/utils/gemini_schema_util.js +18 -0
- package/dist/esm/utils/model_name.js +6 -1
- package/dist/esm/utils/partial_copy.js +23 -0
- package/dist/esm/utils/streaming_utils.js +165 -120
- package/dist/esm/utils/vertex_ai_utils.js +22 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +14 -0
- package/dist/types/agents/processors/base_llm_processor.d.ts +12 -4
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +5 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +4 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +5 -0
- package/dist/types/agents/run_config.d.ts +15 -0
- package/dist/types/code_executors/agent_engine_sandbox_code_executor.d.ts +51 -0
- package/dist/types/common.d.ts +7 -0
- package/dist/types/events/event_actions.d.ts +24 -6
- package/dist/types/events/structured_events.d.ts +13 -0
- package/dist/types/examples/example_util.d.ts +25 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/integrations/agent_registry/agent_registry.d.ts +94 -0
- package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +43 -0
- package/dist/types/integrations/agent_registry/helpers.d.ts +7 -0
- package/dist/types/integrations/agent_registry/types.d.ts +101 -0
- package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +52 -0
- package/dist/types/runner/in_memory_runner.d.ts +28 -1
- package/dist/types/runner/runner.d.ts +47 -0
- package/dist/types/sessions/base_session_service.d.ts +18 -0
- package/dist/types/sessions/database_session_service.d.ts +1 -1
- package/dist/types/sessions/in_memory_session_service.d.ts +1 -1
- package/dist/types/sessions/vertex_ai_session_service.d.ts +37 -0
- package/dist/types/tools/exit_loop_tool.d.ts +9 -0
- package/dist/types/tools/function_tool.d.ts +22 -2
- package/dist/types/tools/google_maps_grounding_tool.d.ts +22 -0
- package/dist/types/tools/long_running_tool.d.ts +11 -1
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +3 -0
- package/dist/types/tools/mcp/mcp_tool.d.ts +7 -1
- package/dist/types/tools/mcp/mcp_toolset.d.ts +7 -1
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +25 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +20 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.d.ts +20 -0
- package/dist/types/tools/url_context_tool.d.ts +17 -0
- package/dist/types/tools/vertex_ai_search_tool.d.ts +55 -0
- package/dist/types/tools/vertex_rag_retrieval_tool.d.ts +42 -0
- package/dist/types/utils/file_utils.d.ts +2 -0
- package/dist/types/utils/model_name.d.ts +4 -0
- package/dist/types/utils/partial_copy.d.ts +13 -0
- package/dist/types/utils/streaming_utils.d.ts +8 -17
- package/dist/types/utils/vertex_ai_utils.d.ts +14 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/functions.js +4 -0
- package/dist/web/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/web/code_executors/agent_engine_sandbox_code_executor.js +281 -0
- package/dist/web/code_executors/code_execution_utils.js +1 -1
- package/dist/web/common.js +15 -0
- package/dist/web/events/event.js +3 -1
- package/dist/web/index.js +54 -12
- package/dist/web/integrations/agent_registry/agent_registry.js +333 -0
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +90 -0
- package/dist/web/integrations/agent_registry/helpers.js +28 -0
- package/dist/web/integrations/agent_registry/types.js +20 -0
- package/dist/web/memory/vertex_ai_memory_bank_service.js +475 -0
- package/dist/web/runner/in_memory_runner.js +10 -5
- package/dist/web/runner/runner.js +32 -2
- package/dist/web/sessions/database_session_service.js +49 -3
- package/dist/web/sessions/in_memory_session_service.js +70 -14
- package/dist/web/sessions/registry.js +7 -0
- package/dist/web/sessions/vertex_ai_session_service.js +414 -0
- package/dist/web/tools/agent_tool.js +11 -6
- package/dist/web/tools/exit_loop_tool.js +9 -0
- package/dist/web/tools/function_tool.js +7 -2
- package/dist/web/tools/google_maps_grounding_tool.js +54 -0
- package/dist/web/tools/long_running_tool.js +2 -1
- package/dist/web/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/web/tools/mcp/mcp_tool.js +12 -7
- package/dist/web/tools/mcp/mcp_toolset.js +27 -4
- package/dist/web/tools/openapi_tool/auth/auth_helpers.js +48 -0
- package/dist/web/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
- package/dist/web/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
- package/dist/web/tools/skill/load_skill_resource_tool.js +1 -24
- package/dist/web/tools/url_context_tool.js +44 -0
- package/dist/web/tools/vertex_ai_search_tool.js +103 -0
- package/dist/web/tools/vertex_rag_retrieval_tool.js +36 -0
- package/dist/web/utils/file_utils.js +26 -0
- package/dist/web/utils/gemini_schema_util.js +18 -0
- package/dist/web/utils/model_name.js +6 -1
- package/dist/web/utils/partial_copy.js +23 -0
- package/dist/web/utils/streaming_utils.js +219 -121
- package/dist/web/utils/vertex_ai_utils.js +22 -0
- package/dist/web/version.js +1 -1
- package/package.json +3 -2
- package/dist/cjs/index.js.map +0 -7
- package/dist/esm/index.js.map +0 -7
- package/dist/web/index.js.map +0 -7
|
@@ -193,6 +193,8 @@ function buildResponseEvent(tool, functionResult, toolContext, invocationContext
|
|
|
193
193
|
let responseResult;
|
|
194
194
|
if (typeof functionResult !== "object" || functionResult == null) {
|
|
195
195
|
responseResult = { result: functionResult };
|
|
196
|
+
} else if (Array.isArray(functionResult)) {
|
|
197
|
+
responseResult = { results: functionResult };
|
|
196
198
|
} else {
|
|
197
199
|
responseResult = functionResult;
|
|
198
200
|
}
|
|
@@ -331,6 +333,8 @@ async function handleFunctionCallList({
|
|
|
331
333
|
functionResponse = { error: functionResponseError };
|
|
332
334
|
} else if (typeof functionResponse !== "object" || functionResponse == null) {
|
|
333
335
|
functionResponse = { result: functionResponse };
|
|
336
|
+
} else if (Array.isArray(functionResponse)) {
|
|
337
|
+
functionResponse = { results: functionResponse };
|
|
334
338
|
}
|
|
335
339
|
const functionResponseEvent = (0, import_event.createEvent)({
|
|
336
340
|
invocationId: invocationContext.invocationId,
|
|
@@ -152,6 +152,18 @@ class OAuth2DiscoveryManager {
|
|
|
152
152
|
return void 0;
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
|
+
function normaliseHostname(raw) {
|
|
156
|
+
const stripped = raw.replace(/^\[|\]$/g, "");
|
|
157
|
+
const m = stripped.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i);
|
|
158
|
+
if (m) {
|
|
159
|
+
const hi = parseInt(m[1], 16);
|
|
160
|
+
const lo = parseInt(m[2], 16);
|
|
161
|
+
return [hi >> 8 & 255, hi & 255, lo >> 8 & 255, lo & 255].join(".");
|
|
162
|
+
}
|
|
163
|
+
const mDot = stripped.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/i);
|
|
164
|
+
if (mDot) return mDot[1];
|
|
165
|
+
return raw;
|
|
166
|
+
}
|
|
155
167
|
function validateDiscoveryUrl(urlStr) {
|
|
156
168
|
try {
|
|
157
169
|
const url = new URL(urlStr);
|
|
@@ -159,8 +171,8 @@ function validateDiscoveryUrl(urlStr) {
|
|
|
159
171
|
import_logger.logger.warn(`Unsafe protocol for discovery URL: ${url.protocol}`);
|
|
160
172
|
return false;
|
|
161
173
|
}
|
|
162
|
-
const host = url.hostname.toLowerCase();
|
|
163
|
-
if (host === "localhost" || host === "127.0.0.1" || host === "[::1]" || host.startsWith("10.") || host.startsWith("192.168.") || host.startsWith("169.254.")) {
|
|
174
|
+
const host = normaliseHostname(url.hostname.toLowerCase());
|
|
175
|
+
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.")) {
|
|
164
176
|
import_logger.logger.warn(`Unsafe host for discovery URL: ${host}`);
|
|
165
177
|
return false;
|
|
166
178
|
}
|
|
@@ -172,6 +184,18 @@ function validateDiscoveryUrl(urlStr) {
|
|
|
172
184
|
return false;
|
|
173
185
|
}
|
|
174
186
|
}
|
|
187
|
+
const cgnatMatch = host.match(/^100\.(\d+)\./);
|
|
188
|
+
if (cgnatMatch) {
|
|
189
|
+
const secondOctet = parseInt(cgnatMatch[1], 10);
|
|
190
|
+
if (secondOctet >= 64 && secondOctet <= 127) {
|
|
191
|
+
import_logger.logger.warn(`Unsafe host for discovery URL: ${host}`);
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (/^\[(f[cd][0-9a-f]{2}|fe[89ab][0-9a-f]):/i.test(url.hostname)) {
|
|
196
|
+
import_logger.logger.warn(`Unsafe host for discovery URL: ${url.hostname}`);
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
175
199
|
return true;
|
|
176
200
|
} catch (e) {
|
|
177
201
|
import_logger.logger.warn(`Failed to parse URL for validation ${urlStr}: ${e}`);
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
26
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
27
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
28
|
+
if (decorator = decorators[i])
|
|
29
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
30
|
+
if (kind && result) __defProp(target, key, result);
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
var agent_engine_sandbox_code_executor_exports = {};
|
|
34
|
+
__export(agent_engine_sandbox_code_executor_exports, {
|
|
35
|
+
AgentEngineSandboxCodeExecutor: () => AgentEngineSandboxCodeExecutor
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(agent_engine_sandbox_code_executor_exports);
|
|
38
|
+
var import_vertexai = require("@google-cloud/vertexai");
|
|
39
|
+
var import_types = require("@google-cloud/vertexai/build/src/genai/types.js");
|
|
40
|
+
var import_experimental = require("../utils/experimental.js");
|
|
41
|
+
var import_file_utils = require("../utils/file_utils.js");
|
|
42
|
+
var import_logger = require("../utils/logger.js");
|
|
43
|
+
var import_base_code_executor = require("./base_code_executor.js");
|
|
44
|
+
var import_code_execution_utils = require("./code_execution_utils.js");
|
|
45
|
+
/**
|
|
46
|
+
* @license
|
|
47
|
+
* Copyright 2026 Google LLC
|
|
48
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
49
|
+
*/
|
|
50
|
+
const SANDBOX_PATTERN = /^projects\/([a-zA-Z0-9-_]+)\/locations\/([a-zA-Z0-9-_]+)\/reasoningEngines\/(\d+)\/sandboxEnvironments\/(\d+)$/;
|
|
51
|
+
const ENGINE_PATTERN = /^projects\/([a-zA-Z0-9-_]+)\/locations\/([a-zA-Z0-9-_]+)\/reasoningEngines\/(\d+)$/;
|
|
52
|
+
const DEFAULT_MAX_ATTEMPTS = 180;
|
|
53
|
+
const DEFAULT_SANDBOX_TTL = "31536000s";
|
|
54
|
+
const DEFAULT_SANDBOX_DISPLAY_NAME = "default_sandbox";
|
|
55
|
+
const DEFAULT_ENGINE_DISPLAY_NAME = "default_engine";
|
|
56
|
+
function mapLanguage(lang) {
|
|
57
|
+
switch (lang) {
|
|
58
|
+
case import_code_execution_utils.CodeExecutionLanguage.PYTHON:
|
|
59
|
+
return import_types.Language.LANGUAGE_PYTHON;
|
|
60
|
+
case import_code_execution_utils.CodeExecutionLanguage.JAVASCRIPT:
|
|
61
|
+
return import_types.Language.LANGUAGE_JAVASCRIPT;
|
|
62
|
+
default:
|
|
63
|
+
throw new Error(`Unsupported language for Agent Engine Sandbox: ${lang}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
let AgentEngineSandboxCodeExecutor = class extends import_base_code_executor.BaseCodeExecutor {
|
|
67
|
+
constructor(options = {}) {
|
|
68
|
+
super();
|
|
69
|
+
this.sandboxResourceName = options.sandboxResourceName;
|
|
70
|
+
this.agentEngineResourceName = options.agentEngineResourceName;
|
|
71
|
+
this.projectId = options.projectId || process.env.GOOGLE_CLOUD_PROJECT;
|
|
72
|
+
this.location = options.location || process.env.GOOGLE_CLOUD_LOCATION || "us-central1";
|
|
73
|
+
if (this.sandboxResourceName) {
|
|
74
|
+
const match = this.sandboxResourceName.match(SANDBOX_PATTERN);
|
|
75
|
+
if (match) {
|
|
76
|
+
this.projectId = match[1];
|
|
77
|
+
this.location = match[2];
|
|
78
|
+
} else {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Invalid sandbox resource name: ${this.sandboxResourceName}`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
} else if (this.agentEngineResourceName) {
|
|
84
|
+
const match = this.agentEngineResourceName.match(ENGINE_PATTERN);
|
|
85
|
+
if (match) {
|
|
86
|
+
this.projectId = match[1];
|
|
87
|
+
this.location = match[2];
|
|
88
|
+
} else {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`Invalid agent engine resource name: ${this.agentEngineResourceName}`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (options.client) {
|
|
95
|
+
this.client = options.client;
|
|
96
|
+
} else {
|
|
97
|
+
if (!this.projectId) {
|
|
98
|
+
throw new Error("Project ID is required.");
|
|
99
|
+
}
|
|
100
|
+
this.client = new import_vertexai.Client({
|
|
101
|
+
project: this.projectId,
|
|
102
|
+
location: this.location
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async executeCode(params) {
|
|
107
|
+
var _a;
|
|
108
|
+
const { invocationContext, codeExecutionInput } = params;
|
|
109
|
+
const language = mapLanguage(codeExecutionInput.language);
|
|
110
|
+
const agentEngineName = await this.getOrCreateAgentEngine();
|
|
111
|
+
const sandboxName = await this.getOrCreateSandbox(
|
|
112
|
+
invocationContext,
|
|
113
|
+
agentEngineName,
|
|
114
|
+
language
|
|
115
|
+
);
|
|
116
|
+
const inputs = [
|
|
117
|
+
{
|
|
118
|
+
mimeType: "application/json",
|
|
119
|
+
data: Buffer.from(
|
|
120
|
+
JSON.stringify({ code: codeExecutionInput.code })
|
|
121
|
+
).toString("base64")
|
|
122
|
+
}
|
|
123
|
+
];
|
|
124
|
+
if (codeExecutionInput.inputFiles) {
|
|
125
|
+
for (const file of codeExecutionInput.inputFiles) {
|
|
126
|
+
inputs.push({
|
|
127
|
+
mimeType: file.mimeType,
|
|
128
|
+
data: file.content,
|
|
129
|
+
// Assumed to be already base64 encoded based on CodeExecutionInput definition
|
|
130
|
+
metadata: {
|
|
131
|
+
attributes: {
|
|
132
|
+
file_name: Buffer.from(file.name).toString("base64")
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
import_logger.logger.debug(`Executing code in sandbox ${sandboxName}...`);
|
|
139
|
+
const response = await this.client.agentEnginesInternal.sandboxes.executeCodeInternal({
|
|
140
|
+
name: sandboxName,
|
|
141
|
+
inputs
|
|
142
|
+
});
|
|
143
|
+
let stdout = "";
|
|
144
|
+
let stderr = "";
|
|
145
|
+
const outputFiles = [];
|
|
146
|
+
if (response.outputs) {
|
|
147
|
+
for (const output of response.outputs) {
|
|
148
|
+
const attributes = ((_a = output.metadata) == null ? void 0 : _a.attributes) || {};
|
|
149
|
+
const encodedFileName = attributes["file_name"];
|
|
150
|
+
const fileName = encodedFileName ? Buffer.from(encodedFileName, "base64").toString("utf-8") : void 0;
|
|
151
|
+
if (output.mimeType === "application/json" && !fileName) {
|
|
152
|
+
if (output.data) {
|
|
153
|
+
const jsonStr = Buffer.from(output.data, "base64").toString(
|
|
154
|
+
"utf-8"
|
|
155
|
+
);
|
|
156
|
+
try {
|
|
157
|
+
const jsonData = JSON.parse(jsonStr);
|
|
158
|
+
if (jsonData.msg_out !== void 0) {
|
|
159
|
+
stdout = jsonData.msg_out;
|
|
160
|
+
} else {
|
|
161
|
+
stdout = "";
|
|
162
|
+
}
|
|
163
|
+
if (jsonData.msg_err !== void 0) {
|
|
164
|
+
stderr = jsonData.msg_err;
|
|
165
|
+
} else {
|
|
166
|
+
stderr = "";
|
|
167
|
+
}
|
|
168
|
+
} catch (e) {
|
|
169
|
+
import_logger.logger.warn("Failed to parse JSON output from sandbox", e);
|
|
170
|
+
stdout = jsonStr;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
let mimeType = output.mimeType;
|
|
175
|
+
const name = fileName || "output_file";
|
|
176
|
+
if (!mimeType) {
|
|
177
|
+
mimeType = (0, import_file_utils.guessMimeType)(name);
|
|
178
|
+
}
|
|
179
|
+
outputFiles.push({
|
|
180
|
+
name,
|
|
181
|
+
content: output.data || "",
|
|
182
|
+
mimeType
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
stdout,
|
|
189
|
+
stderr,
|
|
190
|
+
outputFiles
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
async getOrCreateAgentEngine() {
|
|
194
|
+
if (this.agentEngineResourceName) {
|
|
195
|
+
return this.agentEngineResourceName;
|
|
196
|
+
}
|
|
197
|
+
if (!this.agentEngineCreationPromise) {
|
|
198
|
+
this.agentEngineCreationPromise = (async () => {
|
|
199
|
+
import_logger.logger.debug(
|
|
200
|
+
"No Agent Engine resource name provided. Creating a new one..."
|
|
201
|
+
);
|
|
202
|
+
const operation = await this.client.agentEnginesInternal.createInternal(
|
|
203
|
+
{
|
|
204
|
+
config: {
|
|
205
|
+
displayName: DEFAULT_ENGINE_DISPLAY_NAME
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
);
|
|
209
|
+
let apiResponse = operation;
|
|
210
|
+
let attempts = 0;
|
|
211
|
+
while (!apiResponse.done && attempts < DEFAULT_MAX_ATTEMPTS) {
|
|
212
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
213
|
+
apiResponse = await this.client.agentEnginesInternal.getAgentOperationInternal({
|
|
214
|
+
operationName: operation.name
|
|
215
|
+
});
|
|
216
|
+
attempts++;
|
|
217
|
+
}
|
|
218
|
+
if (!apiResponse.done) {
|
|
219
|
+
throw new Error(
|
|
220
|
+
`Agent Engine creation operation ${operation.name} did not complete in time.`
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
const response = apiResponse.response;
|
|
224
|
+
this.agentEngineResourceName = response.name;
|
|
225
|
+
import_logger.logger.debug(`Created Agent Engine: ${this.agentEngineResourceName}`);
|
|
226
|
+
return this.agentEngineResourceName;
|
|
227
|
+
})();
|
|
228
|
+
}
|
|
229
|
+
return this.agentEngineCreationPromise;
|
|
230
|
+
}
|
|
231
|
+
async getOrCreateSandbox(invocationContext, agentEngineName, language) {
|
|
232
|
+
var _a, _b;
|
|
233
|
+
if (this.sandboxResourceName) {
|
|
234
|
+
return this.sandboxResourceName;
|
|
235
|
+
}
|
|
236
|
+
const stateKey = `sandbox_name_${language.toLowerCase()}`;
|
|
237
|
+
let sandboxName = (_b = (_a = invocationContext.session) == null ? void 0 : _a.state) == null ? void 0 : _b[stateKey];
|
|
238
|
+
let createNewSandbox = false;
|
|
239
|
+
if (!sandboxName) {
|
|
240
|
+
createNewSandbox = true;
|
|
241
|
+
} else {
|
|
242
|
+
try {
|
|
243
|
+
const sandbox = await this.client.agentEnginesInternal.sandboxes.getInternal({
|
|
244
|
+
name: sandboxName
|
|
245
|
+
});
|
|
246
|
+
if (!sandbox || sandbox.state !== "STATE_RUNNING") {
|
|
247
|
+
createNewSandbox = true;
|
|
248
|
+
}
|
|
249
|
+
} catch (error) {
|
|
250
|
+
import_logger.logger.debug(
|
|
251
|
+
`Failed to get sandbox ${sandboxName}, will create a new one`,
|
|
252
|
+
error
|
|
253
|
+
);
|
|
254
|
+
createNewSandbox = true;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (createNewSandbox) {
|
|
258
|
+
import_logger.logger.debug(`Creating a new ${language} code execution sandbox...`);
|
|
259
|
+
const operation = await this.client.agentEnginesInternal.sandboxes.createInternal({
|
|
260
|
+
name: agentEngineName,
|
|
261
|
+
spec: {
|
|
262
|
+
codeExecutionEnvironment: {
|
|
263
|
+
codeLanguage: language
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
config: {
|
|
267
|
+
displayName: DEFAULT_SANDBOX_DISPLAY_NAME,
|
|
268
|
+
ttl: DEFAULT_SANDBOX_TTL
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
let apiResponse = operation;
|
|
272
|
+
let attempts = 0;
|
|
273
|
+
while (!apiResponse.done && attempts < DEFAULT_MAX_ATTEMPTS) {
|
|
274
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
275
|
+
apiResponse = await this.client.agentEnginesInternal.sandboxes.getSandboxOperationInternal(
|
|
276
|
+
{
|
|
277
|
+
operationName: operation.name
|
|
278
|
+
}
|
|
279
|
+
);
|
|
280
|
+
attempts++;
|
|
281
|
+
}
|
|
282
|
+
if (!apiResponse.done) {
|
|
283
|
+
throw new Error(
|
|
284
|
+
`Sandbox creation operation ${operation.name} did not complete in time.`
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
const response = apiResponse.response;
|
|
288
|
+
sandboxName = response.name;
|
|
289
|
+
if (invocationContext.session) {
|
|
290
|
+
if (!invocationContext.session.state) {
|
|
291
|
+
invocationContext.session.state = {};
|
|
292
|
+
}
|
|
293
|
+
invocationContext.session.state[stateKey] = sandboxName;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return sandboxName;
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
AgentEngineSandboxCodeExecutor = __decorateClass([
|
|
300
|
+
import_experimental.experimental
|
|
301
|
+
], AgentEngineSandboxCodeExecutor);
|
|
302
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
303
|
+
0 && (module.exports = {
|
|
304
|
+
AgentEngineSandboxCodeExecutor
|
|
305
|
+
});
|
|
@@ -80,7 +80,7 @@ function extractCodeAndTruncateContent(content, codeBlockDelimiters) {
|
|
|
80
80
|
const leadingDelimiterPattern = codeBlockDelimiters.map((d) => d[0]).join("|");
|
|
81
81
|
const trailingDelimiterPattern = codeBlockDelimiters.map((d) => d[1]).join("|");
|
|
82
82
|
const match = new RegExp(
|
|
83
|
-
|
|
83
|
+
`(?<prefix>.*?)(${leadingDelimiterPattern})(?<codeStr>.*?)(${trailingDelimiterPattern})(?<suffix>.*?)$`,
|
|
84
84
|
"s"
|
|
85
85
|
).exec(responseText);
|
|
86
86
|
const { prefix, codeStr } = (match == null ? void 0 : match.groups) || {};
|
package/dist/cjs/common.js
CHANGED
|
@@ -57,9 +57,11 @@ __export(common_exports, {
|
|
|
57
57
|
ExitLoopTool: () => import_exit_loop_tool.ExitLoopTool,
|
|
58
58
|
FileContentEncoding: () => import_code_execution_utils.FileContentEncoding,
|
|
59
59
|
FunctionTool: () => import_function_tool.FunctionTool,
|
|
60
|
+
GOOGLE_MAPS_GROUNDING: () => import_google_maps_grounding_tool.GOOGLE_MAPS_GROUNDING,
|
|
60
61
|
GOOGLE_SEARCH: () => import_google_search_tool.GOOGLE_SEARCH,
|
|
61
62
|
Gemini: () => import_google_llm.Gemini,
|
|
62
63
|
GoogleLLMVariant: () => import_variant_utils.GoogleLLMVariant,
|
|
64
|
+
GoogleMapsGroundingTool: () => import_google_maps_grounding_tool.GoogleMapsGroundingTool,
|
|
63
65
|
GoogleSearchTool: () => import_google_search_tool.GoogleSearchTool,
|
|
64
66
|
InMemoryArtifactService: () => import_in_memory_artifact_service.InMemoryArtifactService,
|
|
65
67
|
InMemoryCredentialService: () => import_in_memory_credential_service.InMemoryCredentialService,
|
|
@@ -105,6 +107,11 @@ __export(common_exports, {
|
|
|
105
107
|
TokenBasedContextCompactor: () => import_token_based_context_compactor.TokenBasedContextCompactor,
|
|
106
108
|
ToolConfirmation: () => import_tool_confirmation.ToolConfirmation,
|
|
107
109
|
TruncatingContextCompactor: () => import_truncating_context_compactor.TruncatingContextCompactor,
|
|
110
|
+
URL_CONTEXT: () => import_url_context_tool.URL_CONTEXT,
|
|
111
|
+
UrlContextTool: () => import_url_context_tool.UrlContextTool,
|
|
112
|
+
VertexAiMemoryBankService: () => import_vertex_ai_memory_bank_service.VertexAiMemoryBankService,
|
|
113
|
+
VertexAiSearchTool: () => import_vertex_ai_search_tool.VertexAiSearchTool,
|
|
114
|
+
VertexRagRetrievalTool: () => import_vertex_rag_retrieval_tool.VertexRagRetrievalTool,
|
|
108
115
|
createEvent: () => import_event.createEvent,
|
|
109
116
|
createEventActions: () => import_event_actions.createEventActions,
|
|
110
117
|
createSession: () => import_session.createSession,
|
|
@@ -179,6 +186,7 @@ var import_event_actions = require("./events/event_actions.js");
|
|
|
179
186
|
var import_structured_events = require("./events/structured_events.js");
|
|
180
187
|
var import_base_example_provider = require("./examples/base_example_provider.js");
|
|
181
188
|
var import_in_memory_memory_service = require("./memory/in_memory_memory_service.js");
|
|
189
|
+
var import_vertex_ai_memory_bank_service = require("./memory/vertex_ai_memory_bank_service.js");
|
|
182
190
|
var import_apigee_llm = require("./models/apigee_llm.js");
|
|
183
191
|
var import_base_llm = require("./models/base_llm.js");
|
|
184
192
|
var import_google_llm = require("./models/google_llm.js");
|
|
@@ -199,12 +207,16 @@ var import_base_tool = require("./tools/base_tool.js");
|
|
|
199
207
|
var import_base_toolset = require("./tools/base_toolset.js");
|
|
200
208
|
var import_exit_loop_tool = require("./tools/exit_loop_tool.js");
|
|
201
209
|
var import_function_tool = require("./tools/function_tool.js");
|
|
210
|
+
var import_google_maps_grounding_tool = require("./tools/google_maps_grounding_tool.js");
|
|
202
211
|
var import_google_search_tool = require("./tools/google_search_tool.js");
|
|
203
212
|
var import_load_artifacts_tool = require("./tools/load_artifacts_tool.js");
|
|
204
213
|
var import_load_memory_tool = require("./tools/load_memory_tool.js");
|
|
205
214
|
var import_long_running_tool = require("./tools/long_running_tool.js");
|
|
206
215
|
var import_preload_memory_tool = require("./tools/preload_memory_tool.js");
|
|
207
216
|
var import_tool_confirmation = require("./tools/tool_confirmation.js");
|
|
217
|
+
var import_url_context_tool = require("./tools/url_context_tool.js");
|
|
218
|
+
var import_vertex_ai_search_tool = require("./tools/vertex_ai_search_tool.js");
|
|
219
|
+
var import_vertex_rag_retrieval_tool = require("./tools/vertex_rag_retrieval_tool.js");
|
|
208
220
|
var import_logger = require("./utils/logger.js");
|
|
209
221
|
var import_model_name = require("./utils/model_name.js");
|
|
210
222
|
var import_simple_zod_to_json = require("./utils/simple_zod_to_json.js");
|
|
@@ -258,9 +270,11 @@ __reExport(common_exports, require("./tools/base_tool.js"), module.exports);
|
|
|
258
270
|
ExitLoopTool,
|
|
259
271
|
FileContentEncoding,
|
|
260
272
|
FunctionTool,
|
|
273
|
+
GOOGLE_MAPS_GROUNDING,
|
|
261
274
|
GOOGLE_SEARCH,
|
|
262
275
|
Gemini,
|
|
263
276
|
GoogleLLMVariant,
|
|
277
|
+
GoogleMapsGroundingTool,
|
|
264
278
|
GoogleSearchTool,
|
|
265
279
|
InMemoryArtifactService,
|
|
266
280
|
InMemoryCredentialService,
|
|
@@ -306,6 +320,11 @@ __reExport(common_exports, require("./tools/base_tool.js"), module.exports);
|
|
|
306
320
|
TokenBasedContextCompactor,
|
|
307
321
|
ToolConfirmation,
|
|
308
322
|
TruncatingContextCompactor,
|
|
323
|
+
URL_CONTEXT,
|
|
324
|
+
UrlContextTool,
|
|
325
|
+
VertexAiMemoryBankService,
|
|
326
|
+
VertexAiSearchTool,
|
|
327
|
+
VertexRagRetrievalTool,
|
|
309
328
|
createEvent,
|
|
310
329
|
createEventActions,
|
|
311
330
|
createSession,
|
package/dist/cjs/events/event.js
CHANGED
|
@@ -95,7 +95,7 @@ function stringifyContent(event) {
|
|
|
95
95
|
if (!((_a = event.content) == null ? void 0 : _a.parts)) {
|
|
96
96
|
return "";
|
|
97
97
|
}
|
|
98
|
-
return event.content.parts.map((part) => {
|
|
98
|
+
return event.content.parts.filter((part) => !part.thought).map((part) => {
|
|
99
99
|
var _a2;
|
|
100
100
|
return (_a2 = part.text) != null ? _a2 : "";
|
|
101
101
|
}).join("");
|
|
@@ -114,6 +114,7 @@ const PRESERVE_KEYS_CAMEL_CASE = [
|
|
|
114
114
|
"actions.requestedAuthConfigs",
|
|
115
115
|
"actions.requestedToolConfirmations",
|
|
116
116
|
"actions.customMetadata",
|
|
117
|
+
"customMetadata",
|
|
117
118
|
"content.parts.functionCall.args",
|
|
118
119
|
"content.parts.functionResponse.response"
|
|
119
120
|
];
|
|
@@ -123,6 +124,7 @@ const PRESERVE_KEYS_SNAKE_CASE = [
|
|
|
123
124
|
"actions.requested_auth_configs",
|
|
124
125
|
"actions.requested_tool_confirmations",
|
|
125
126
|
"actions.custom_metadata",
|
|
127
|
+
"custom_metadata",
|
|
126
128
|
"content.parts.function_call.args",
|
|
127
129
|
"content.parts.function_response.response"
|
|
128
130
|
];
|