@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
|
@@ -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: ${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: ${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: ${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 ${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 ${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: ${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_${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 ${sandboxName}, will create a new one`,
|
|
229
|
+
error
|
|
230
|
+
);
|
|
231
|
+
createNewSandbox = true;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (createNewSandbox) {
|
|
235
|
+
logger.debug(`Creating a new ${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 ${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
|
-
|
|
50
|
+
`(?<prefix>.*?)(${leadingDelimiterPattern})(?<codeStr>.*?)(${trailingDelimiterPattern})(?<suffix>.*?)$`,
|
|
51
51
|
"s"
|
|
52
52
|
).exec(responseText);
|
|
53
53
|
const { prefix, codeStr } = (match == null ? void 0 : match.groups) || {};
|
package/dist/esm/common.js
CHANGED
|
@@ -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,
|
|
@@ -102,6 +107,9 @@ import {
|
|
|
102
107
|
PreloadMemoryTool
|
|
103
108
|
} from "./tools/preload_memory_tool.js";
|
|
104
109
|
import { ToolConfirmation } from "./tools/tool_confirmation.js";
|
|
110
|
+
import { URL_CONTEXT, UrlContextTool } from "./tools/url_context_tool.js";
|
|
111
|
+
import { VertexAiSearchTool } from "./tools/vertex_ai_search_tool.js";
|
|
112
|
+
import { VertexRagRetrievalTool } from "./tools/vertex_rag_retrieval_tool.js";
|
|
105
113
|
import { LogLevel, getLogger, setLogLevel, setLogger } from "./utils/logger.js";
|
|
106
114
|
import { isGemini2OrAbove } from "./utils/model_name.js";
|
|
107
115
|
import { zodObjectToSchema } from "./utils/simple_zod_to_json.js";
|
|
@@ -149,9 +157,11 @@ export {
|
|
|
149
157
|
ExitLoopTool,
|
|
150
158
|
FileContentEncoding,
|
|
151
159
|
FunctionTool,
|
|
160
|
+
GOOGLE_MAPS_GROUNDING,
|
|
152
161
|
GOOGLE_SEARCH,
|
|
153
162
|
Gemini,
|
|
154
163
|
GoogleLLMVariant,
|
|
164
|
+
GoogleMapsGroundingTool,
|
|
155
165
|
GoogleSearchTool,
|
|
156
166
|
InMemoryArtifactService,
|
|
157
167
|
InMemoryCredentialService,
|
|
@@ -197,6 +207,11 @@ export {
|
|
|
197
207
|
TokenBasedContextCompactor,
|
|
198
208
|
ToolConfirmation,
|
|
199
209
|
TruncatingContextCompactor,
|
|
210
|
+
URL_CONTEXT,
|
|
211
|
+
UrlContextTool,
|
|
212
|
+
VertexAiMemoryBankService,
|
|
213
|
+
VertexAiSearchTool,
|
|
214
|
+
VertexRagRetrievalTool,
|
|
200
215
|
createEvent,
|
|
201
216
|
createEventActions,
|
|
202
217
|
createSession,
|
package/dist/esm/events/event.js
CHANGED
|
@@ -60,7 +60,7 @@ function stringifyContent(event) {
|
|
|
60
60
|
if (!((_a = event.content) == null ? void 0 : _a.parts)) {
|
|
61
61
|
return "";
|
|
62
62
|
}
|
|
63
|
-
return event.content.parts.map((part) => {
|
|
63
|
+
return event.content.parts.filter((part) => !part.thought).map((part) => {
|
|
64
64
|
var _a2;
|
|
65
65
|
return (_a2 = part.text) != null ? _a2 : "";
|
|
66
66
|
}).join("");
|
|
@@ -79,6 +79,7 @@ const PRESERVE_KEYS_CAMEL_CASE = [
|
|
|
79
79
|
"actions.requestedAuthConfigs",
|
|
80
80
|
"actions.requestedToolConfirmations",
|
|
81
81
|
"actions.customMetadata",
|
|
82
|
+
"customMetadata",
|
|
82
83
|
"content.parts.functionCall.args",
|
|
83
84
|
"content.parts.functionResponse.response"
|
|
84
85
|
];
|
|
@@ -88,6 +89,7 @@ const PRESERVE_KEYS_SNAKE_CASE = [
|
|
|
88
89
|
"actions.requested_auth_configs",
|
|
89
90
|
"actions.requested_tool_confirmations",
|
|
90
91
|
"actions.custom_metadata",
|
|
92
|
+
"custom_metadata",
|
|
91
93
|
"content.parts.function_call.args",
|
|
92
94
|
"content.parts.function_response.response"
|
|
93
95
|
];
|