@softactivate/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.
- 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 +3 -0
- package/dist/cjs/events/event.js +2 -0
- package/dist/cjs/index.js +14 -0
- 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 +17 -8
- package/dist/cjs/tools/exit_loop_tool.js +9 -0
- package/dist/cjs/tools/function_tool.js +7 -2
- 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 +10 -7
- package/dist/cjs/tools/mcp/mcp_toolset.js +10 -2
- 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/utils/file_utils.js +28 -0
- package/dist/cjs/utils/gemini_schema_util.js +18 -0
- package/dist/cjs/utils/partial_copy.js +51 -0
- package/dist/cjs/utils/streaming_utils.js +167 -118
- 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 +2 -0
- package/dist/esm/events/event.js +2 -0
- package/dist/esm/index.js +11 -0
- 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 +17 -8
- package/dist/esm/tools/exit_loop_tool.js +9 -0
- package/dist/esm/tools/function_tool.js +7 -2
- 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 +10 -7
- package/dist/esm/tools/mcp/mcp_toolset.js +10 -2
- 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/utils/file_utils.js +26 -0
- package/dist/esm/utils/gemini_schema_util.js +18 -0
- package/dist/esm/utils/partial_copy.js +23 -0
- package/dist/esm/utils/streaming_utils.js +165 -117
- 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 +2 -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/long_running_tool.d.ts +11 -1
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +3 -0
- 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/utils/file_utils.d.ts +2 -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 +2 -0
- package/dist/web/events/event.js +2 -0
- package/dist/web/index.js +11 -0
- 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 +17 -8
- package/dist/web/tools/exit_loop_tool.js +9 -0
- package/dist/web/tools/function_tool.js +7 -2
- 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 +10 -7
- package/dist/web/tools/mcp/mcp_toolset.js +10 -2
- 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/utils/file_utils.js +26 -0
- package/dist/web/utils/gemini_schema_util.js +18 -0
- package/dist/web/utils/partial_copy.js +23 -0
- package/dist/web/utils/streaming_utils.js +218 -117
- package/dist/web/utils/vertex_ai_utils.js +22 -0
- package/dist/web/version.js +1 -1
- package/package.json +2 -1
|
@@ -195,6 +195,8 @@ function buildResponseEvent(tool, functionResult, toolContext, invocationContext
|
|
|
195
195
|
let responseResult;
|
|
196
196
|
if (typeof functionResult !== "object" || functionResult == null) {
|
|
197
197
|
responseResult = { result: functionResult };
|
|
198
|
+
} else if (Array.isArray(functionResult)) {
|
|
199
|
+
responseResult = { results: functionResult };
|
|
198
200
|
} else {
|
|
199
201
|
responseResult = functionResult;
|
|
200
202
|
}
|
|
@@ -415,6 +417,8 @@ async function handleFunctionCallList({
|
|
|
415
417
|
functionResponse = { error: functionResponseError };
|
|
416
418
|
} else if (typeof functionResponse !== "object" || functionResponse == null) {
|
|
417
419
|
functionResponse = { result: functionResponse };
|
|
420
|
+
} else if (Array.isArray(functionResponse)) {
|
|
421
|
+
functionResponse = { results: functionResponse };
|
|
418
422
|
}
|
|
419
423
|
const functionResponseEvent = (0, import_event.createEvent)({
|
|
420
424
|
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
|
@@ -109,6 +109,7 @@ __export(common_exports, {
|
|
|
109
109
|
TruncatingContextCompactor: () => import_truncating_context_compactor.TruncatingContextCompactor,
|
|
110
110
|
URL_CONTEXT: () => import_url_context_tool.URL_CONTEXT,
|
|
111
111
|
UrlContextTool: () => import_url_context_tool.UrlContextTool,
|
|
112
|
+
VertexAiMemoryBankService: () => import_vertex_ai_memory_bank_service.VertexAiMemoryBankService,
|
|
112
113
|
VertexAiSearchTool: () => import_vertex_ai_search_tool.VertexAiSearchTool,
|
|
113
114
|
VertexRagRetrievalTool: () => import_vertex_rag_retrieval_tool.VertexRagRetrievalTool,
|
|
114
115
|
createEvent: () => import_event.createEvent,
|
|
@@ -185,6 +186,7 @@ var import_event_actions = require("./events/event_actions.js");
|
|
|
185
186
|
var import_structured_events = require("./events/structured_events.js");
|
|
186
187
|
var import_base_example_provider = require("./examples/base_example_provider.js");
|
|
187
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");
|
|
188
190
|
var import_apigee_llm = require("./models/apigee_llm.js");
|
|
189
191
|
var import_base_llm = require("./models/base_llm.js");
|
|
190
192
|
var import_google_llm = require("./models/google_llm.js");
|
|
@@ -320,6 +322,7 @@ __reExport(common_exports, require("./tools/base_tool.js"), module.exports);
|
|
|
320
322
|
TruncatingContextCompactor,
|
|
321
323
|
URL_CONTEXT,
|
|
322
324
|
UrlContextTool,
|
|
325
|
+
VertexAiMemoryBankService,
|
|
323
326
|
VertexAiSearchTool,
|
|
324
327
|
VertexRagRetrievalTool,
|
|
325
328
|
createEvent,
|
package/dist/cjs/events/event.js
CHANGED
|
@@ -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
|
];
|
package/dist/cjs/index.js
CHANGED
|
@@ -27,13 +27,17 @@ var index_exports = {};
|
|
|
27
27
|
__export(index_exports, {
|
|
28
28
|
A2AAgentExecutor: () => import_agent_executor.A2AAgentExecutor,
|
|
29
29
|
AGENT_CARD_PATH: () => import_a2a_remote_agent.AGENT_CARD_PATH,
|
|
30
|
+
AgentEngineSandboxCodeExecutor: () => import_agent_engine_sandbox_code_executor.AgentEngineSandboxCodeExecutor,
|
|
31
|
+
CodeExecutionLanguage: () => import_code_execution_utils.CodeExecutionLanguage,
|
|
30
32
|
DatabaseSessionService: () => import_database_session_service.DatabaseSessionService,
|
|
31
33
|
FileArtifactService: () => import_file_artifact_service.FileArtifactService,
|
|
32
34
|
GcsArtifactService: () => import_gcs_artifact_service.GcsArtifactService,
|
|
35
|
+
InvocationContext: () => import_invocation_context.InvocationContext,
|
|
33
36
|
RemoteA2AAgent: () => import_a2a_remote_agent.RemoteA2AAgent,
|
|
34
37
|
RunSkillInlineScriptTool: () => import_run_skill_inline_script_tool.RunSkillInlineScriptTool,
|
|
35
38
|
RunSkillScriptTool: () => import_run_skill_script_tool.RunSkillScriptTool,
|
|
36
39
|
UnsafeLocalCodeExecutor: () => import_unsafe_local_code_executor.UnsafeLocalCodeExecutor,
|
|
40
|
+
VertexAiSessionService: () => import_vertex_ai_session_service.VertexAiSessionService,
|
|
37
41
|
getA2AAgentCard: () => import_agent_card.getA2AAgentCard,
|
|
38
42
|
getArtifactServiceFromUri: () => import_registry.getArtifactServiceFromUri,
|
|
39
43
|
getSessionServiceFromUri: () => import_registry2.getSessionServiceFromUri,
|
|
@@ -47,16 +51,21 @@ var import_a2a_remote_agent = require("./a2a/a2a_remote_agent.js");
|
|
|
47
51
|
var import_agent_card = require("./a2a/agent_card.js");
|
|
48
52
|
var import_agent_executor = require("./a2a/agent_executor.js");
|
|
49
53
|
var import_agent_to_a2a = require("./a2a/agent_to_a2a.js");
|
|
54
|
+
var import_invocation_context = require("./agents/invocation_context.js");
|
|
50
55
|
var import_file_artifact_service = require("./artifacts/file_artifact_service.js");
|
|
51
56
|
var import_gcs_artifact_service = require("./artifacts/gcs_artifact_service.js");
|
|
52
57
|
var import_registry = require("./artifacts/registry.js");
|
|
58
|
+
var import_agent_engine_sandbox_code_executor = require("./code_executors/agent_engine_sandbox_code_executor.js");
|
|
59
|
+
var import_code_execution_utils = require("./code_executors/code_execution_utils.js");
|
|
53
60
|
var import_unsafe_local_code_executor = require("./code_executors/unsafe_local_code_executor.js");
|
|
54
61
|
__reExport(index_exports, require("./common.js"), module.exports);
|
|
55
62
|
var import_database_session_service = require("./sessions/database_session_service.js");
|
|
56
63
|
var import_registry2 = require("./sessions/registry.js");
|
|
64
|
+
var import_vertex_ai_session_service = require("./sessions/vertex_ai_session_service.js");
|
|
57
65
|
var import_loader = require("./skills/loader.js");
|
|
58
66
|
var import_run_skill_inline_script_tool = require("./tools/skill/run_skill_inline_script_tool.js");
|
|
59
67
|
var import_run_skill_script_tool = require("./tools/skill/run_skill_script_tool.js");
|
|
68
|
+
__reExport(index_exports, require("./integrations/agent_registry/agent_registry.js"), module.exports);
|
|
60
69
|
__reExport(index_exports, require("./telemetry/google_cloud.js"), module.exports);
|
|
61
70
|
__reExport(index_exports, require("./telemetry/setup.js"), module.exports);
|
|
62
71
|
__reExport(index_exports, require("./tools/mcp/mcp_session_manager.js"), module.exports);
|
|
@@ -71,13 +80,17 @@ __reExport(index_exports, require("./tools/mcp/mcp_toolset.js"), module.exports)
|
|
|
71
80
|
0 && (module.exports = {
|
|
72
81
|
A2AAgentExecutor,
|
|
73
82
|
AGENT_CARD_PATH,
|
|
83
|
+
AgentEngineSandboxCodeExecutor,
|
|
84
|
+
CodeExecutionLanguage,
|
|
74
85
|
DatabaseSessionService,
|
|
75
86
|
FileArtifactService,
|
|
76
87
|
GcsArtifactService,
|
|
88
|
+
InvocationContext,
|
|
77
89
|
RemoteA2AAgent,
|
|
78
90
|
RunSkillInlineScriptTool,
|
|
79
91
|
RunSkillScriptTool,
|
|
80
92
|
UnsafeLocalCodeExecutor,
|
|
93
|
+
VertexAiSessionService,
|
|
81
94
|
getA2AAgentCard,
|
|
82
95
|
getArtifactServiceFromUri,
|
|
83
96
|
getSessionServiceFromUri,
|
|
@@ -86,6 +99,7 @@ __reExport(index_exports, require("./tools/mcp/mcp_toolset.js"), module.exports)
|
|
|
86
99
|
toA2a,
|
|
87
100
|
validateSkillDir,
|
|
88
101
|
...require("./common.js"),
|
|
102
|
+
...require("./integrations/agent_registry/agent_registry.js"),
|
|
89
103
|
...require("./telemetry/google_cloud.js"),
|
|
90
104
|
...require("./telemetry/setup.js"),
|
|
91
105
|
...require("./tools/mcp/mcp_session_manager.js"),
|