@google/adk 1.4.0 → 1.6.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/a2a/a2a_remote_agent.js +12 -2
- package/dist/cjs/a2a/agent_to_a2a.js +18 -3
- package/dist/cjs/a2a/auth.js +65 -0
- package/dist/cjs/a2a/event_converter_utils.js +47 -18
- package/dist/cjs/a2a/metadata_converter_utils.js +1 -1
- package/dist/cjs/agents/base_agent.js +39 -0
- package/dist/cjs/agents/functions.js +26 -28
- package/dist/cjs/agents/llm_agent.js +4 -2
- package/dist/cjs/agents/loop_agent.js +15 -3
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/cjs/agents/processors/content_processor_utils.js +2 -1
- package/dist/cjs/agents/processors/content_request_processor.js +2 -21
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +3 -1
- package/dist/cjs/agents/routed_agent.js +31 -0
- package/dist/cjs/agents/run_config.js +3 -2
- package/dist/cjs/artifacts/in_memory_artifact_service.js +17 -9
- package/dist/cjs/auth/credential_service/in_memory_credential_service.js +14 -3
- package/dist/cjs/code_executors/unsafe_local_code_executor.js +23 -12
- package/dist/cjs/common.js +35 -0
- package/dist/cjs/context/agent_controlled_context_compactor.js +2 -11
- package/dist/cjs/context/anchored_context_compactor.js +127 -0
- package/dist/cjs/context/compaction_utils.js +64 -0
- package/dist/cjs/context/token_based_context_compactor.js +13 -44
- package/dist/cjs/events/compacted_event.js +9 -3
- package/dist/cjs/events/event.js +28 -0
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/cjs/memory/in_memory_memory_service.js +13 -2
- package/dist/cjs/memory/vertex_ai_memory_bank_service.js +3 -0
- package/dist/cjs/plugins/base_plugin.js +4 -2
- package/dist/cjs/plugins/global_instruction_plugin.js +97 -0
- package/dist/cjs/runner/runner.js +69 -23
- package/dist/cjs/sessions/base_session_service.js +8 -3
- package/dist/cjs/sessions/in_memory_session_service.js +8 -8
- package/dist/cjs/sessions/vertex_ai_session_service.js +22 -10
- package/dist/cjs/skills/loader.js +40 -6
- package/dist/cjs/tools/enterprise_web_search_tool.js +81 -0
- package/dist/cjs/tools/example_tool.js +68 -0
- package/dist/cjs/tools/get_user_choice_tool.js +53 -0
- package/dist/cjs/tools/load_web_page.js +250 -0
- package/dist/cjs/tools/mcp/load_mcp_resource_tool.js +140 -0
- package/dist/cjs/tools/mcp/mcp_session_manager.js +35 -21
- package/dist/cjs/tools/mcp/mcp_toolset.js +63 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
- package/dist/cjs/tools/request_input_tool.js +54 -0
- package/dist/cjs/tools/skill/run_skill_inline_script_tool.js +54 -4
- package/dist/cjs/tools/skill/skill_toolset.js +4 -2
- package/dist/cjs/utils/branch_trie.js +41 -0
- package/dist/cjs/utils/crypto_shim.js +43 -0
- package/dist/cjs/utils/env_aware_utils.js +15 -13
- package/dist/cjs/utils/error_utils.js +120 -0
- package/dist/cjs/utils/file_utils.js +5 -2
- package/dist/cjs/utils/output_schema_utils.js +43 -0
- package/dist/cjs/utils/streaming_utils.js +5 -5
- package/dist/cjs/utils/vertex_ai_utils.js +3 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_remote_agent.js +12 -2
- package/dist/esm/a2a/agent_to_a2a.js +18 -3
- package/dist/esm/a2a/auth.js +37 -0
- package/dist/esm/a2a/event_converter_utils.js +47 -18
- package/dist/esm/a2a/metadata_converter_utils.js +1 -1
- package/dist/esm/agents/base_agent.js +39 -0
- package/dist/esm/agents/functions.js +27 -24
- package/dist/esm/agents/llm_agent.js +6 -4
- package/dist/esm/agents/loop_agent.js +15 -3
- package/dist/esm/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/esm/agents/processors/content_processor_utils.js +2 -1
- package/dist/esm/agents/processors/content_request_processor.js +2 -21
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +3 -1
- package/dist/esm/agents/routed_agent.js +31 -0
- package/dist/esm/agents/run_config.js +3 -2
- package/dist/esm/artifacts/in_memory_artifact_service.js +17 -9
- package/dist/esm/auth/credential_service/in_memory_credential_service.js +14 -3
- package/dist/esm/code_executors/unsafe_local_code_executor.js +22 -11
- package/dist/esm/common.js +29 -1
- package/dist/esm/context/agent_controlled_context_compactor.js +2 -11
- package/dist/esm/context/anchored_context_compactor.js +99 -0
- package/dist/esm/context/compaction_utils.js +38 -0
- package/dist/esm/context/token_based_context_compactor.js +16 -44
- package/dist/esm/events/compacted_event.js +7 -2
- package/dist/esm/events/event.js +24 -0
- package/dist/esm/index.js +8 -1
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/esm/memory/in_memory_memory_service.js +13 -2
- package/dist/esm/memory/vertex_ai_memory_bank_service.js +7 -1
- package/dist/esm/plugins/base_plugin.js +4 -2
- package/dist/esm/plugins/global_instruction_plugin.js +69 -0
- package/dist/esm/runner/runner.js +69 -23
- package/dist/esm/sessions/base_session_service.js +8 -3
- package/dist/esm/sessions/in_memory_session_service.js +8 -8
- package/dist/esm/sessions/vertex_ai_session_service.js +26 -11
- package/dist/esm/skills/loader.js +40 -6
- package/dist/esm/tools/enterprise_web_search_tool.js +55 -0
- package/dist/esm/tools/example_tool.js +42 -0
- package/dist/esm/tools/get_user_choice_tool.js +25 -0
- package/dist/esm/tools/load_web_page.js +221 -0
- package/dist/esm/tools/mcp/load_mcp_resource_tool.js +114 -0
- package/dist/esm/tools/mcp/mcp_session_manager.js +35 -21
- package/dist/esm/tools/mcp/mcp_toolset.js +63 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
- package/dist/esm/tools/request_input_tool.js +26 -0
- package/dist/esm/tools/skill/run_skill_inline_script_tool.js +53 -4
- package/dist/esm/tools/skill/skill_toolset.js +4 -2
- package/dist/esm/utils/branch_trie.js +13 -0
- package/dist/esm/utils/crypto_shim.js +15 -0
- package/dist/esm/utils/env_aware_utils.js +15 -13
- package/dist/esm/utils/error_utils.js +92 -0
- package/dist/esm/utils/file_utils.js +5 -2
- package/dist/esm/utils/output_schema_utils.js +15 -0
- package/dist/esm/utils/streaming_utils.js +1 -1
- package/dist/esm/utils/vertex_ai_utils.js +2 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +5 -1
- package/dist/types/a2a/agent_to_a2a.d.ts +38 -0
- package/dist/types/a2a/auth.d.ts +30 -0
- package/dist/types/a2a/event_converter_utils.d.ts +4 -1
- package/dist/types/agents/base_agent.d.ts +29 -1
- package/dist/types/agents/functions.d.ts +1 -9
- package/dist/types/agents/llm_agent.d.ts +5 -1
- package/dist/types/agents/loop_agent.d.ts +2 -2
- package/dist/types/agents/routed_agent.d.ts +24 -1
- package/dist/types/agents/run_config.d.ts +1 -1
- package/dist/types/auth/credential_service/in_memory_credential_service.d.ts +11 -0
- package/dist/types/code_executors/unsafe_local_code_executor.d.ts +5 -1
- package/dist/types/common.d.ts +11 -2
- package/dist/types/context/agent_controlled_context_compactor.d.ts +0 -1
- package/dist/types/context/anchored_context_compactor.d.ts +35 -0
- package/dist/types/context/compaction_utils.d.ts +23 -0
- package/dist/types/context/token_based_context_compactor.d.ts +0 -1
- package/dist/types/events/compacted_event.d.ts +10 -0
- package/dist/types/events/event.d.ts +13 -0
- package/dist/types/index.d.ts +5 -3
- package/dist/types/memory/in_memory_memory_service.d.ts +11 -0
- package/dist/types/plugins/base_plugin.d.ts +4 -2
- package/dist/types/plugins/global_instruction_plugin.d.ts +38 -0
- package/dist/types/runner/runner.d.ts +1 -1
- package/dist/types/sessions/base_session_service.d.ts +8 -0
- package/dist/types/sessions/in_memory_session_service.d.ts +9 -0
- package/dist/types/sessions/vertex_ai_session_service.d.ts +19 -1
- package/dist/types/skills/loader.d.ts +5 -0
- package/dist/types/tools/enterprise_web_search_tool.d.ts +26 -0
- package/dist/types/tools/example_tool.d.ts +21 -0
- package/dist/types/tools/get_user_choice_tool.d.ts +14 -0
- package/dist/types/tools/load_web_page.d.ts +33 -0
- package/dist/types/tools/mcp/load_mcp_resource_tool.d.ts +26 -0
- package/dist/types/tools/mcp/mcp_toolset.d.ts +27 -0
- package/dist/types/tools/request_input_tool.d.ts +15 -0
- package/dist/types/tools/skill/run_skill_inline_script_tool.d.ts +25 -0
- package/dist/types/tools/skill/skill_toolset.d.ts +9 -0
- package/dist/types/utils/branch_trie.d.ts +14 -0
- package/dist/types/utils/crypto_shim.d.ts +16 -0
- package/dist/types/utils/env_aware_utils.d.ts +23 -0
- package/dist/types/utils/error_utils.d.ts +18 -0
- package/dist/types/utils/output_schema_utils.d.ts +18 -0
- package/dist/types/utils/vertex_ai_utils.d.ts +1 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_remote_agent.js +12 -2
- package/dist/web/a2a/agent_to_a2a.js +18 -3
- package/dist/web/a2a/auth.js +37 -0
- package/dist/web/a2a/event_converter_utils.js +47 -18
- package/dist/web/a2a/metadata_converter_utils.js +1 -1
- package/dist/web/agents/base_agent.js +39 -0
- package/dist/web/agents/functions.js +27 -24
- package/dist/web/agents/llm_agent.js +6 -4
- package/dist/web/agents/loop_agent.js +27 -3
- package/dist/web/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/web/agents/processors/content_processor_utils.js +2 -1
- package/dist/web/agents/processors/content_request_processor.js +2 -21
- package/dist/web/agents/processors/instructions_llm_request_processor.js +3 -1
- package/dist/web/agents/routed_agent.js +31 -0
- package/dist/web/agents/run_config.js +8 -3
- package/dist/web/artifacts/in_memory_artifact_service.js +17 -9
- package/dist/web/auth/credential_service/in_memory_credential_service.js +14 -3
- package/dist/web/code_executors/unsafe_local_code_executor.js +22 -11
- package/dist/web/common.js +29 -1
- package/dist/web/context/agent_controlled_context_compactor.js +2 -11
- package/dist/web/context/anchored_context_compactor.js +117 -0
- package/dist/web/context/compaction_utils.js +38 -0
- package/dist/web/context/token_based_context_compactor.js +16 -44
- package/dist/web/events/compacted_event.js +7 -2
- package/dist/web/events/event.js +24 -0
- package/dist/web/index.js +8 -1
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/web/memory/in_memory_memory_service.js +13 -2
- package/dist/web/memory/vertex_ai_memory_bank_service.js +7 -1
- package/dist/web/plugins/base_plugin.js +4 -2
- package/dist/web/plugins/global_instruction_plugin.js +67 -0
- package/dist/web/runner/runner.js +65 -22
- package/dist/web/sessions/base_session_service.js +8 -3
- package/dist/web/sessions/in_memory_session_service.js +8 -8
- package/dist/web/sessions/vertex_ai_session_service.js +24 -11
- package/dist/web/skills/loader.js +40 -6
- package/dist/web/tools/enterprise_web_search_tool.js +55 -0
- package/dist/web/tools/example_tool.js +42 -0
- package/dist/web/tools/get_user_choice_tool.js +25 -0
- package/dist/web/tools/load_web_page.js +221 -0
- package/dist/web/tools/mcp/load_mcp_resource_tool.js +107 -0
- package/dist/web/tools/mcp/mcp_session_manager.js +35 -21
- package/dist/web/tools/mcp/mcp_toolset.js +63 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
- package/dist/web/tools/request_input_tool.js +26 -0
- package/dist/web/tools/skill/run_skill_inline_script_tool.js +51 -4
- package/dist/web/tools/skill/skill_toolset.js +4 -2
- package/dist/web/utils/branch_trie.js +13 -0
- package/dist/web/utils/crypto_shim.js +15 -0
- package/dist/web/utils/env_aware_utils.js +15 -13
- package/dist/web/utils/error_utils.js +92 -0
- package/dist/web/utils/file_utils.js +5 -2
- package/dist/web/utils/output_schema_utils.js +15 -0
- package/dist/web/utils/streaming_utils.js +1 -1
- package/dist/web/utils/vertex_ai_utils.js +2 -0
- package/dist/web/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,120 @@
|
|
|
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 error_utils_exports = {};
|
|
26
|
+
__export(error_utils_exports, {
|
|
27
|
+
formatError: () => formatError
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(error_utils_exports);
|
|
30
|
+
/**
|
|
31
|
+
* @license
|
|
32
|
+
* Copyright 2026 Google LLC
|
|
33
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
34
|
+
*/
|
|
35
|
+
const MAX_RESPONSE_BODY_LENGTH = 1e3;
|
|
36
|
+
const TRUNCATION_MARKER = "... [truncated]";
|
|
37
|
+
const UNKNOWN_ERROR = "Unknown error";
|
|
38
|
+
const MIN_HTTP_STATUS = 100;
|
|
39
|
+
const MAX_HTTP_STATUS = 599;
|
|
40
|
+
function asRecord(value) {
|
|
41
|
+
return value !== null && typeof value === "object" ? value : void 0;
|
|
42
|
+
}
|
|
43
|
+
function firstString(...values) {
|
|
44
|
+
for (const value of values) {
|
|
45
|
+
if (typeof value === "string") {
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
function truncateBody(body) {
|
|
52
|
+
return body.length > MAX_RESPONSE_BODY_LENGTH ? body.slice(0, MAX_RESPONSE_BODY_LENGTH) + TRUNCATION_MARKER : body;
|
|
53
|
+
}
|
|
54
|
+
function baseMessage(err) {
|
|
55
|
+
if (err instanceof Error) {
|
|
56
|
+
return err.message;
|
|
57
|
+
}
|
|
58
|
+
if (typeof err === "string") {
|
|
59
|
+
return err;
|
|
60
|
+
}
|
|
61
|
+
return String(err);
|
|
62
|
+
}
|
|
63
|
+
function extractHttpDetails(err) {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
const record = asRecord(err);
|
|
66
|
+
if (record === void 0) {
|
|
67
|
+
return void 0;
|
|
68
|
+
}
|
|
69
|
+
const response = asRecord(record["response"]);
|
|
70
|
+
const rawStatus = (_b = (_a = record["status"]) != null ? _a : record["code"]) != null ? _b : response == null ? void 0 : response["status"];
|
|
71
|
+
const status = typeof rawStatus === "number" && rawStatus >= MIN_HTTP_STATUS && rawStatus <= MAX_HTTP_STATUS ? rawStatus : void 0;
|
|
72
|
+
const statusText = firstString(
|
|
73
|
+
record["statusText"],
|
|
74
|
+
response == null ? void 0 : response["statusText"]
|
|
75
|
+
);
|
|
76
|
+
const body = firstString(
|
|
77
|
+
response == null ? void 0 : response["data"],
|
|
78
|
+
response == null ? void 0 : response["body"],
|
|
79
|
+
response == null ? void 0 : response["text"]
|
|
80
|
+
);
|
|
81
|
+
if (status === void 0 && body === void 0) {
|
|
82
|
+
return void 0;
|
|
83
|
+
}
|
|
84
|
+
const head = status === void 0 ? "HTTP error" : `HTTP ${status}${statusText === void 0 ? "" : ` ${statusText}`}`;
|
|
85
|
+
return body === void 0 ? head : `${head}: ${truncateBody(body)}`;
|
|
86
|
+
}
|
|
87
|
+
function formatErrorRecursive(err, seen) {
|
|
88
|
+
var _a;
|
|
89
|
+
if (err === null || err === void 0) {
|
|
90
|
+
return UNKNOWN_ERROR;
|
|
91
|
+
}
|
|
92
|
+
if (typeof err === "object") {
|
|
93
|
+
if (seen.has(err)) {
|
|
94
|
+
return baseMessage(err);
|
|
95
|
+
}
|
|
96
|
+
seen.add(err);
|
|
97
|
+
}
|
|
98
|
+
if (err instanceof AggregateError && err.errors.length > 0) {
|
|
99
|
+
return err.errors.map((sub) => formatErrorRecursive(sub, seen)).join(" | ");
|
|
100
|
+
}
|
|
101
|
+
const http = extractHttpDetails(err);
|
|
102
|
+
const base = baseMessage(err);
|
|
103
|
+
const cause = (_a = asRecord(err)) == null ? void 0 : _a["cause"];
|
|
104
|
+
const causeMessage = cause !== void 0 ? formatErrorRecursive(cause, seen) : void 0;
|
|
105
|
+
let message = base.length > 0 ? base : UNKNOWN_ERROR;
|
|
106
|
+
if (http !== void 0) {
|
|
107
|
+
message = `${message} (${http})`;
|
|
108
|
+
}
|
|
109
|
+
if (causeMessage !== void 0 && http === void 0 && !message.includes(causeMessage)) {
|
|
110
|
+
message = `${message}: ${causeMessage}`;
|
|
111
|
+
}
|
|
112
|
+
return message;
|
|
113
|
+
}
|
|
114
|
+
function formatError(err) {
|
|
115
|
+
return formatErrorRecursive(err, /* @__PURE__ */ new Set());
|
|
116
|
+
}
|
|
117
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
118
|
+
0 && (module.exports = {
|
|
119
|
+
formatError
|
|
120
|
+
});
|
|
@@ -46,12 +46,15 @@ var path = __toESM(require("node:path"), 1);
|
|
|
46
46
|
* Copyright 2026 Google LLC
|
|
47
47
|
* SPDX-License-Identifier: Apache-2.0
|
|
48
48
|
*/
|
|
49
|
+
function isInsideDir(resolvedPath, resolvedBaseDir) {
|
|
50
|
+
return resolvedPath === resolvedBaseDir || resolvedPath.startsWith(resolvedBaseDir + path.sep);
|
|
51
|
+
}
|
|
49
52
|
async function materializeFiles(files, dir = process.cwd()) {
|
|
50
53
|
const resolvedBaseDir = path.resolve(dir);
|
|
51
54
|
const createdFiles = [];
|
|
52
55
|
for (const file of files) {
|
|
53
56
|
const fullPath = path.resolve(dir, file.name);
|
|
54
|
-
if (!fullPath
|
|
57
|
+
if (!isInsideDir(fullPath, resolvedBaseDir)) {
|
|
55
58
|
throw new Error(
|
|
56
59
|
`Path traversal detected: ${file.name} resolves outside of ${dir}`
|
|
57
60
|
);
|
|
@@ -73,7 +76,7 @@ async function materializeFiles(files, dir = process.cwd()) {
|
|
|
73
76
|
break;
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
|
-
if (!finalPath
|
|
79
|
+
if (!isInsideDir(finalPath, resolvedBaseDir)) {
|
|
77
80
|
throw new Error(
|
|
78
81
|
`Path traversal detected: ${file.name} resolves outside of ${dir}`
|
|
79
82
|
);
|
|
@@ -0,0 +1,43 @@
|
|
|
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 output_schema_utils_exports = {};
|
|
26
|
+
__export(output_schema_utils_exports, {
|
|
27
|
+
canUseOutputSchemaWithTools: () => canUseOutputSchemaWithTools
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(output_schema_utils_exports);
|
|
30
|
+
var import_model_name = require("./model_name.js");
|
|
31
|
+
var import_variant_utils = require("./variant_utils.js");
|
|
32
|
+
/**
|
|
33
|
+
* @license
|
|
34
|
+
* Copyright 2026 Google LLC
|
|
35
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
36
|
+
*/
|
|
37
|
+
function canUseOutputSchemaWithTools(modelString) {
|
|
38
|
+
return (0, import_variant_utils.getGoogleLlmVariant)() === import_variant_utils.GoogleLLMVariant.VERTEX_AI && (0, import_model_name.isGemini2OrAbove)(modelString);
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
canUseOutputSchemaWithTools
|
|
43
|
+
});
|
|
@@ -30,7 +30,7 @@ __export(streaming_utils_exports, {
|
|
|
30
30
|
module.exports = __toCommonJS(streaming_utils_exports);
|
|
31
31
|
var import_genai = require("@google/genai");
|
|
32
32
|
var import_jsonpath_plus = require("jsonpath-plus");
|
|
33
|
-
var
|
|
33
|
+
var import_event = require("../events/event.js");
|
|
34
34
|
var import_feature_registry = require("../features/feature_registry.js");
|
|
35
35
|
var import_llm_response = require("../models/llm_response.js");
|
|
36
36
|
/**
|
|
@@ -127,7 +127,7 @@ class ProgressiveStrategy {
|
|
|
127
127
|
functionCall: {
|
|
128
128
|
name: this.currentFcName,
|
|
129
129
|
args: JSON.parse(JSON.stringify(this.currentFcArgs)),
|
|
130
|
-
id: (_a = this.currentFcId) != null ? _a : (0,
|
|
130
|
+
id: (_a = this.currentFcId) != null ? _a : (0, import_event.generateClientFunctionCallId)()
|
|
131
131
|
}
|
|
132
132
|
};
|
|
133
133
|
if (this.currentThoughtSignature) {
|
|
@@ -172,7 +172,7 @@ class ProgressiveStrategy {
|
|
|
172
172
|
}
|
|
173
173
|
if (fc.partialArgs || fc.willContinue) {
|
|
174
174
|
if (!fc.id && !this.currentFcId) {
|
|
175
|
-
fc.id = (0,
|
|
175
|
+
fc.id = (0, import_event.generateClientFunctionCallId)();
|
|
176
176
|
}
|
|
177
177
|
if (part.thoughtSignature && !this.currentThoughtSignature) {
|
|
178
178
|
this.currentThoughtSignature = part.thoughtSignature;
|
|
@@ -181,7 +181,7 @@ class ProgressiveStrategy {
|
|
|
181
181
|
} else {
|
|
182
182
|
if (fc.name) {
|
|
183
183
|
if (!fc.id) {
|
|
184
|
-
fc.id = (0,
|
|
184
|
+
fc.id = (0, import_event.generateClientFunctionCallId)();
|
|
185
185
|
}
|
|
186
186
|
this.flushTextBufferToSequence();
|
|
187
187
|
this.partsSequence.push(part);
|
|
@@ -243,7 +243,7 @@ class NonProgressiveStrategy {
|
|
|
243
243
|
continue;
|
|
244
244
|
}
|
|
245
245
|
if (part.functionCall && !part.functionCall.id) {
|
|
246
|
-
part.functionCall.id = (0,
|
|
246
|
+
part.functionCall.id = (0, import_event.generateClientFunctionCallId)();
|
|
247
247
|
}
|
|
248
248
|
nonTextParts.push(part);
|
|
249
249
|
}
|
|
@@ -24,6 +24,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var vertex_ai_utils_exports = {};
|
|
26
26
|
__export(vertex_ai_utils_exports, {
|
|
27
|
+
EXPRESS_MODE_UNSUPPORTED_MESSAGE: () => EXPRESS_MODE_UNSUPPORTED_MESSAGE,
|
|
27
28
|
getExpressModeApiKey: () => getExpressModeApiKey
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(vertex_ai_utils_exports);
|
|
@@ -33,6 +34,7 @@ var import_env_aware_utils = require("./env_aware_utils.js");
|
|
|
33
34
|
* Copyright 2026 Google LLC
|
|
34
35
|
* SPDX-License-Identifier: Apache-2.0
|
|
35
36
|
*/
|
|
37
|
+
const EXPRESS_MODE_UNSUPPORTED_MESSAGE = "Vertex AI Express Mode (expressModeApiKey / GOOGLE_API_KEY) is not supported: the @google-cloud/vertexai Agent Engine client cannot send an API key. Provide projectId and location (with Application Default Credentials), or inject a preconfigured client.";
|
|
36
38
|
function getExpressModeApiKey(project, location, expressModeApiKey) {
|
|
37
39
|
if ((project || location) && expressModeApiKey) {
|
|
38
40
|
throw new Error(
|
|
@@ -46,5 +48,6 @@ function getExpressModeApiKey(project, location, expressModeApiKey) {
|
|
|
46
48
|
}
|
|
47
49
|
// Annotate the CommonJS export names for ESM import in node:
|
|
48
50
|
0 && (module.exports = {
|
|
51
|
+
EXPRESS_MODE_UNSUPPORTED_MESSAGE,
|
|
49
52
|
getExpressModeApiKey
|
|
50
53
|
});
|
package/dist/cjs/version.js
CHANGED
|
@@ -32,7 +32,7 @@ module.exports = __toCommonJS(version_exports);
|
|
|
32
32
|
* Copyright 2025 Google LLC
|
|
33
33
|
* SPDX-License-Identifier: Apache-2.0
|
|
34
34
|
*/
|
|
35
|
-
const version = "1.
|
|
35
|
+
const version = "1.6.0";
|
|
36
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
37
|
0 && (module.exports = {
|
|
38
38
|
version
|
|
@@ -107,7 +107,12 @@ class RemoteA2AAgent extends BaseAgent {
|
|
|
107
107
|
await callback(context, chunk);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
const adkEvent = toAdkEvent(
|
|
110
|
+
const adkEvent = toAdkEvent(
|
|
111
|
+
chunk,
|
|
112
|
+
context.invocationId,
|
|
113
|
+
this.name,
|
|
114
|
+
context.branch
|
|
115
|
+
);
|
|
111
116
|
if (!adkEvent) {
|
|
112
117
|
continue;
|
|
113
118
|
}
|
|
@@ -128,7 +133,12 @@ class RemoteA2AAgent extends BaseAgent {
|
|
|
128
133
|
await callback(context, result);
|
|
129
134
|
}
|
|
130
135
|
}
|
|
131
|
-
const adkEvent = toAdkEvent(
|
|
136
|
+
const adkEvent = toAdkEvent(
|
|
137
|
+
result,
|
|
138
|
+
context.invocationId,
|
|
139
|
+
this.name,
|
|
140
|
+
context.branch
|
|
141
|
+
);
|
|
132
142
|
if (adkEvent) {
|
|
133
143
|
processor.updateCustomMetadata(adkEvent, result);
|
|
134
144
|
yield adkEvent;
|
|
@@ -16,10 +16,26 @@ import {
|
|
|
16
16
|
import express from "express";
|
|
17
17
|
import { StreamingMode } from "../agents/run_config.js";
|
|
18
18
|
import { InMemorySessionService } from "../sessions/in_memory_session_service.js";
|
|
19
|
+
import { logger } from "../utils/logger.js";
|
|
19
20
|
import { getA2AAgentCard, resolveAgentCard } from "./agent_card.js";
|
|
20
21
|
import { A2AAgentExecutor } from "./agent_executor.js";
|
|
22
|
+
function resolveA2aUserBuilder(options) {
|
|
23
|
+
if (options.authentication) {
|
|
24
|
+
return options.authentication;
|
|
25
|
+
}
|
|
26
|
+
if (options.allowUnauthenticated === true) {
|
|
27
|
+
logger.warn(
|
|
28
|
+
"SECURITY WARNING: Mounting the A2A server WITHOUT authentication because `allowUnauthenticated: true` was set. The agent and all of its tools are exposed to any network-reachable caller, which can invoke them with arbitrary input and read the output. Do NOT use this outside of local, trusted development."
|
|
29
|
+
);
|
|
30
|
+
return UserBuilder.noAuthentication;
|
|
31
|
+
}
|
|
32
|
+
throw new Error(
|
|
33
|
+
"toA2a: refusing to mount the A2A server without authentication. The A2A surface lets any network-reachable caller invoke this agent and its tools with arbitrary input and read the output, so it must be authenticated. Provide `authentication` (a UserBuilder that validates the request, e.g. a bearer token or OIDC credential) or, only for local/trusted development, explicitly set `allowUnauthenticated: true`."
|
|
34
|
+
);
|
|
35
|
+
}
|
|
21
36
|
async function toA2a(agent, options = {}) {
|
|
22
37
|
var _a, _b, _c, _d;
|
|
38
|
+
const userBuilder = resolveA2aUserBuilder(options);
|
|
23
39
|
const host = (_a = options.host) != null ? _a : "localhost";
|
|
24
40
|
const port = (_b = options.port) != null ? _b : 8e3;
|
|
25
41
|
const protocol = (_c = options.protocol) != null ? _c : "http";
|
|
@@ -54,7 +70,6 @@ async function toA2a(agent, options = {}) {
|
|
|
54
70
|
);
|
|
55
71
|
const app = (_d = options.app) != null ? _d : express();
|
|
56
72
|
if (!options.app) {
|
|
57
|
-
app.use(express.urlencoded({ limit: "50mb", extended: true }));
|
|
58
73
|
app.use(express.json({ limit: "50mb" }));
|
|
59
74
|
}
|
|
60
75
|
app.use(
|
|
@@ -65,14 +80,14 @@ async function toA2a(agent, options = {}) {
|
|
|
65
80
|
`${basePath}/rest`,
|
|
66
81
|
restHandler({
|
|
67
82
|
requestHandler,
|
|
68
|
-
userBuilder
|
|
83
|
+
userBuilder
|
|
69
84
|
})
|
|
70
85
|
);
|
|
71
86
|
app.use(
|
|
72
87
|
`${basePath}/jsonrpc`,
|
|
73
88
|
jsonRpcHandler({
|
|
74
89
|
requestHandler,
|
|
75
|
-
userBuilder
|
|
90
|
+
userBuilder
|
|
76
91
|
})
|
|
77
92
|
);
|
|
78
93
|
return app;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2026 Google LLC
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
import { timingSafeEqual } from "node:crypto";
|
|
9
|
+
const AUTHENTICATED_USER_NAME = "a2a-bearer-token";
|
|
10
|
+
const BEARER_SCHEME_PREFIX = "bearer ";
|
|
11
|
+
function timingSafeEqualStrings(a, b) {
|
|
12
|
+
const left = Buffer.from(a, "utf8");
|
|
13
|
+
const right = Buffer.from(b, "utf8");
|
|
14
|
+
return left.length === right.length && timingSafeEqual(left, right);
|
|
15
|
+
}
|
|
16
|
+
function bearerTokenUserBuilder(token) {
|
|
17
|
+
const expected = token.trim();
|
|
18
|
+
if (!expected) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
"bearerTokenUserBuilder: an empty A2A bearer token is not a valid authenticator. Supply a real shared secret, or configure no token at all to run the A2A surface unauthenticated."
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
return async (req) => {
|
|
24
|
+
var _a;
|
|
25
|
+
const header = (_a = req.headers.authorization) != null ? _a : "";
|
|
26
|
+
const credential = header.toLowerCase().startsWith(BEARER_SCHEME_PREFIX) ? header.slice(BEARER_SCHEME_PREFIX.length) : "";
|
|
27
|
+
if (!timingSafeEqualStrings(credential, expected)) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
"A2A request rejected: missing or invalid `Authorization: Bearer` credential."
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
return { isAuthenticated: true, userName: AUTHENTICATED_USER_NAME };
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
bearerTokenUserBuilder
|
|
37
|
+
};
|
|
@@ -43,33 +43,35 @@ function toA2AMessage(event, {
|
|
|
43
43
|
metadata: getA2AEventMetadata(event, { appName, userId, sessionId })
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
-
function toAdkEvent(event, invocationId, agentName) {
|
|
46
|
+
function toAdkEvent(event, invocationId, agentName, branch) {
|
|
47
47
|
if (isMessage(event)) {
|
|
48
|
-
return messageToAdkEvent(event, invocationId, agentName);
|
|
48
|
+
return messageToAdkEvent(event, invocationId, agentName, branch);
|
|
49
49
|
}
|
|
50
50
|
if (isTask(event)) {
|
|
51
|
-
return taskToAdkEvent(event, invocationId, agentName);
|
|
51
|
+
return taskToAdkEvent(event, invocationId, agentName, branch);
|
|
52
52
|
}
|
|
53
53
|
if (isTaskArtifactUpdateEvent(event)) {
|
|
54
|
-
return artifactUpdateToAdkEvent(event, invocationId, agentName);
|
|
54
|
+
return artifactUpdateToAdkEvent(event, invocationId, agentName, branch);
|
|
55
55
|
}
|
|
56
56
|
if (isTaskStatusUpdateEvent(event)) {
|
|
57
|
-
return event.final ? finalTaskStatusUpdateToAdkEvent(event, invocationId, agentName) : taskStatusUpdateToAdkEvent(event, invocationId, agentName);
|
|
57
|
+
return event.final ? finalTaskStatusUpdateToAdkEvent(event, invocationId, agentName, branch) : taskStatusUpdateToAdkEvent(event, invocationId, agentName, branch);
|
|
58
58
|
}
|
|
59
59
|
return void 0;
|
|
60
60
|
}
|
|
61
|
-
function messageToAdkEvent(msg, invocationId, agentName,
|
|
61
|
+
function messageToAdkEvent(msg, invocationId, agentName, branch) {
|
|
62
62
|
const parts = toGenAIParts(msg.parts);
|
|
63
|
+
const content = parts.length === 0 ? void 0 : msg.role === MessageRole.USER ? createUserContent(parts) : createModelContent(parts);
|
|
63
64
|
return {
|
|
64
|
-
...createAdkEventFromMetadata(
|
|
65
|
+
...createAdkEventFromMetadata(msg),
|
|
65
66
|
invocationId,
|
|
66
67
|
author: msg.role === MessageRole.USER ? MessageRole.USER : agentName,
|
|
67
|
-
|
|
68
|
+
branch,
|
|
69
|
+
content,
|
|
68
70
|
turnComplete: true,
|
|
69
71
|
partial: false
|
|
70
72
|
};
|
|
71
73
|
}
|
|
72
|
-
function artifactUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
|
|
74
|
+
function artifactUpdateToAdkEvent(a2aEvent, invocationId, agentName, branch) {
|
|
73
75
|
var _a;
|
|
74
76
|
const partsToConvert = ((_a = a2aEvent.artifact) == null ? void 0 : _a.parts) || [];
|
|
75
77
|
if (partsToConvert.length === 0) {
|
|
@@ -80,12 +82,13 @@ function artifactUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
|
|
|
80
82
|
...createAdkEventFromMetadata(a2aEvent),
|
|
81
83
|
invocationId,
|
|
82
84
|
author: agentName,
|
|
85
|
+
branch,
|
|
83
86
|
content: createModelContent(toGenAIParts(partsToConvert)),
|
|
84
87
|
longRunningToolIds: getLongRunningToolIDs(partsToConvert),
|
|
85
88
|
partial
|
|
86
89
|
};
|
|
87
90
|
}
|
|
88
|
-
function finalTaskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
|
|
91
|
+
function finalTaskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName, branch) {
|
|
89
92
|
var _a;
|
|
90
93
|
const partsToConvert = ((_a = a2aEvent.status.message) == null ? void 0 : _a.parts) || [];
|
|
91
94
|
if (partsToConvert.length === 0) {
|
|
@@ -98,28 +101,33 @@ function finalTaskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
|
|
|
98
101
|
...createAdkEventFromMetadata(a2aEvent),
|
|
99
102
|
invocationId,
|
|
100
103
|
author: agentName,
|
|
104
|
+
branch,
|
|
101
105
|
errorMessage: isFailedTask ? getFailedTaskStatusUpdateEventError(a2aEvent) : void 0,
|
|
102
106
|
content: hasContent ? createModelContent(parts) : void 0,
|
|
103
107
|
longRunningToolIds: getLongRunningToolIDs(partsToConvert),
|
|
104
108
|
turnComplete: true
|
|
105
109
|
};
|
|
106
110
|
}
|
|
107
|
-
function taskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
|
|
111
|
+
function taskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName, branch) {
|
|
108
112
|
const msg = a2aEvent.status.message;
|
|
109
113
|
if (!msg) {
|
|
110
114
|
return void 0;
|
|
111
115
|
}
|
|
112
116
|
const parts = toGenAIParts(msg.parts);
|
|
117
|
+
if (parts.length === 0) {
|
|
118
|
+
return void 0;
|
|
119
|
+
}
|
|
113
120
|
return {
|
|
114
121
|
...createAdkEventFromMetadata(a2aEvent),
|
|
115
122
|
invocationId,
|
|
116
123
|
author: agentName,
|
|
124
|
+
branch,
|
|
117
125
|
content: createModelContent(parts),
|
|
118
126
|
turnComplete: false,
|
|
119
127
|
partial: true
|
|
120
128
|
};
|
|
121
129
|
}
|
|
122
|
-
function taskToAdkEvent(a2aTask, invocationId, agentName) {
|
|
130
|
+
function taskToAdkEvent(a2aTask, invocationId, agentName, branch) {
|
|
123
131
|
var _a, _b;
|
|
124
132
|
const parts = [];
|
|
125
133
|
const longRunningToolIds = [];
|
|
@@ -140,23 +148,33 @@ function taskToAdkEvent(a2aTask, invocationId, agentName) {
|
|
|
140
148
|
}
|
|
141
149
|
const isTerminal = isTerminalTaskStatusUpdateEvent(a2aTask) || isInputRequiredTaskStatusUpdateEvent(a2aTask);
|
|
142
150
|
const isFailed = isFailedTaskStatusUpdateEvent(a2aTask);
|
|
143
|
-
if (parts.length === 0 && !
|
|
151
|
+
if (parts.length === 0 && !isFailed) {
|
|
144
152
|
return void 0;
|
|
145
153
|
}
|
|
146
154
|
return {
|
|
147
155
|
...createAdkEventFromMetadata(a2aTask),
|
|
148
156
|
invocationId,
|
|
149
157
|
author: agentName,
|
|
158
|
+
branch,
|
|
150
159
|
content: isFailed ? void 0 : createModelContent(parts),
|
|
151
160
|
errorMessage: isFailed ? getFailedTaskStatusUpdateEventError(a2aTask) : void 0,
|
|
152
161
|
longRunningToolIds,
|
|
153
162
|
turnComplete: isTerminal
|
|
154
163
|
};
|
|
155
164
|
}
|
|
165
|
+
const PEER_SETTABLE_ACTION_FIELDS = /* @__PURE__ */ new Set(["escalate"]);
|
|
156
166
|
function createAdkEventFromMetadata(a2aEvent) {
|
|
157
167
|
const metadata = a2aEvent.metadata || {};
|
|
158
168
|
return createEvent({
|
|
159
|
-
branch
|
|
169
|
+
// `branch` is intentionally NOT restored from peer metadata here (unlike
|
|
170
|
+
// the other fields below): it is the mechanism getContents() (see
|
|
171
|
+
// content_processor_utils.ts) uses to keep sibling sub-agent branches'
|
|
172
|
+
// conversation contexts isolated from each other. A remote A2A peer that
|
|
173
|
+
// controls its own outgoing metadata could otherwise forge `adk_branch`
|
|
174
|
+
// (set it to a shared ancestor branch, or omit it) to leak its content
|
|
175
|
+
// into an unrelated sibling agent's LLM context. Every caller of the
|
|
176
|
+
// `*ToAdkEvent` functions in this file force-sets `branch` from its own
|
|
177
|
+
// local `InvocationContext` instead, the same way `author` is handled.
|
|
160
178
|
author: metadata[A2AMetadataKeys.AUTHOR],
|
|
161
179
|
partial: metadata[A2AMetadataKeys.PARTIAL],
|
|
162
180
|
errorCode: metadata[A2AMetadataKeys.ERROR_CODE],
|
|
@@ -165,10 +183,21 @@ function createAdkEventFromMetadata(a2aEvent) {
|
|
|
165
183
|
groundingMetadata: metadata[A2AMetadataKeys.GROUNDING_METADATA],
|
|
166
184
|
usageMetadata: metadata[A2AMetadataKeys.USAGE_METADATA],
|
|
167
185
|
customMetadata: metadata[A2AMetadataKeys.CUSTOM_METADATA],
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
186
|
+
// Only fields in PEER_SETTABLE_ACTION_FIELDS may be restored from
|
|
187
|
+
// metadata a remote A2A peer controls. Every other action field either
|
|
188
|
+
// mutates the caller's own session or drives the caller's own control
|
|
189
|
+
// flow (e.g. `transferToAgent`, see llm_agent.ts), so it must never be
|
|
190
|
+
// rebuilt from peer-supplied data. Filtering through an allowlist here
|
|
191
|
+
// (rather than just omitting the unsafe field) means a future action
|
|
192
|
+
// field is unsafe-by-default: adding it to `candidateActions` alone
|
|
193
|
+
// does nothing until it's also added to the allowlist.
|
|
194
|
+
actions: createEventActions(
|
|
195
|
+
Object.fromEntries(
|
|
196
|
+
Object.entries({
|
|
197
|
+
escalate: !!metadata[A2AMetadataKeys.ESCALATE]
|
|
198
|
+
}).filter(([key]) => PEER_SETTABLE_ACTION_FIELDS.has(key))
|
|
199
|
+
)
|
|
200
|
+
)
|
|
172
201
|
});
|
|
173
202
|
}
|
|
174
203
|
function getLongRunningToolIDs(parts) {
|
|
@@ -56,7 +56,7 @@ function getA2AEventMetadata(adkEvent, {
|
|
|
56
56
|
[A2AMetadataKeys.INVOCATION_ID]: adkEvent.invocationId,
|
|
57
57
|
[A2AMetadataKeys.AUTHOR]: adkEvent.author,
|
|
58
58
|
[A2AMetadataKeys.BRANCH]: adkEvent.branch,
|
|
59
|
-
[A2AMetadataKeys.ERROR_CODE]: adkEvent.
|
|
59
|
+
[A2AMetadataKeys.ERROR_CODE]: adkEvent.errorCode,
|
|
60
60
|
[A2AMetadataKeys.ERROR_MESSAGE]: adkEvent.errorMessage,
|
|
61
61
|
[A2AMetadataKeys.CITATION_METADATA]: adkEvent.citationMetadata,
|
|
62
62
|
[A2AMetadataKeys.GROUNDING_METADATA]: adkEvent.groundingMetadata,
|
|
@@ -26,6 +26,7 @@ class BaseAgent {
|
|
|
26
26
|
* A unique symbol to identify ADK agent classes.
|
|
27
27
|
*/
|
|
28
28
|
this[_a] = true;
|
|
29
|
+
this.config = { ...config };
|
|
29
30
|
this.name = validateAgentName(config.name);
|
|
30
31
|
this.description = config.description;
|
|
31
32
|
this.parentAgent = config.parentAgent;
|
|
@@ -43,6 +44,44 @@ class BaseAgent {
|
|
|
43
44
|
get rootAgent() {
|
|
44
45
|
return getRootAgent(this);
|
|
45
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates a copy of this agent with the given config fields overridden.
|
|
49
|
+
*
|
|
50
|
+
* Mirrors adk-python's `BaseAgent.clone(update=...)`. The clone is a detached
|
|
51
|
+
* root: its `parentAgent` is always `undefined`. Sub-agents are recursively
|
|
52
|
+
* cloned (and re-parented to the clone) unless `subAgents` is overridden.
|
|
53
|
+
* Rebuilding via the concrete constructor re-derives all state, so a cloned
|
|
54
|
+
* `LlmAgent` gets a fresh `requestProcessors` array rather than sharing the
|
|
55
|
+
* original's. See google/adk-js#534.
|
|
56
|
+
*
|
|
57
|
+
* @param overrides Config fields to override on the clone. Overriding
|
|
58
|
+
* `parentAgent` is rejected, matching adk-python.
|
|
59
|
+
* @returns A new detached agent instance of the same concrete class.
|
|
60
|
+
*/
|
|
61
|
+
clone(overrides) {
|
|
62
|
+
if (overrides && "parentAgent" in overrides) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
"Cannot update `parentAgent` field in clone. Parent agent is set only when the parent agent is instantiated with the sub-agents."
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
const merged = { ...this.config, ...overrides };
|
|
68
|
+
merged.parentAgent = void 0;
|
|
69
|
+
const mergedRecord = merged;
|
|
70
|
+
for (const key of Object.keys(mergedRecord)) {
|
|
71
|
+
if (key === "subAgents" || overrides && key in overrides) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const value = mergedRecord[key];
|
|
75
|
+
if (Array.isArray(value)) {
|
|
76
|
+
mergedRecord[key] = value.slice();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!overrides || !("subAgents" in overrides)) {
|
|
80
|
+
merged.subAgents = this.subAgents.map((subAgent) => subAgent.clone());
|
|
81
|
+
}
|
|
82
|
+
const ctor = this.constructor;
|
|
83
|
+
return new ctor(merged);
|
|
84
|
+
}
|
|
46
85
|
/**
|
|
47
86
|
* Entry method to run an agent via text-based conversation.
|
|
48
87
|
*
|