@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
|
@@ -7,7 +7,18 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
7
7
|
*/
|
|
8
8
|
class InMemoryCredentialService {
|
|
9
9
|
constructor() {
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* A map from app name to a map from user ID to a map from credential key to
|
|
12
|
+
* credential.
|
|
13
|
+
*
|
|
14
|
+
* `appName`, `userId` and `credentialKey` are all attacker-influenced, so
|
|
15
|
+
* every level is created with `Object.create(null)`. On an ordinary `{}`
|
|
16
|
+
* literal a key of `__proto__` resolves to the inherited `__proto__`
|
|
17
|
+
* accessor rather than creating an own property, so nested assignment
|
|
18
|
+
* pollutes every object in the process, and a lookup of an inherited key
|
|
19
|
+
* such as `toString` returns a function instead of `undefined`.
|
|
20
|
+
*/
|
|
21
|
+
this.credentials = /* @__PURE__ */ Object.create(null);
|
|
11
22
|
}
|
|
12
23
|
loadCredential(authConfig, toolContext) {
|
|
13
24
|
const credentialBucket = this.getBucketForCurrentContext(toolContext);
|
|
@@ -22,10 +33,10 @@ class InMemoryCredentialService {
|
|
|
22
33
|
getBucketForCurrentContext(toolContext) {
|
|
23
34
|
const { appName, userId } = toolContext.invocationContext.session;
|
|
24
35
|
if (!this.credentials[appName]) {
|
|
25
|
-
this.credentials[appName] =
|
|
36
|
+
this.credentials[appName] = /* @__PURE__ */ Object.create(null);
|
|
26
37
|
}
|
|
27
38
|
if (!this.credentials[appName][userId]) {
|
|
28
|
-
this.credentials[appName][userId] =
|
|
39
|
+
this.credentials[appName][userId] = /* @__PURE__ */ Object.create(null);
|
|
29
40
|
}
|
|
30
41
|
return this.credentials[appName][userId];
|
|
31
42
|
}
|
|
@@ -5,7 +5,7 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
5
5
|
* Copyright 2026 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
|
-
import { spawn } from "child_process";
|
|
8
|
+
import { spawn } from "node:child_process";
|
|
9
9
|
import * as fs from "node:fs/promises";
|
|
10
10
|
import * as os from "node:os";
|
|
11
11
|
import * as path from "node:path";
|
|
@@ -17,13 +17,21 @@ import {
|
|
|
17
17
|
CodeExecutionLanguage
|
|
18
18
|
} from "./code_execution_utils.js";
|
|
19
19
|
const IS_WINDOWS = os.platform() === "win32";
|
|
20
|
+
const POWERSHELL_BASE_ARGS = [
|
|
21
|
+
"-NoLogo",
|
|
22
|
+
"-NoProfile",
|
|
23
|
+
"-ExecutionPolicy",
|
|
24
|
+
"Bypass",
|
|
25
|
+
"-File"
|
|
26
|
+
];
|
|
27
|
+
const CMD_BASE_ARGS = ["/D", "/c"];
|
|
28
|
+
function isPowerShellCommand(commandPath) {
|
|
29
|
+
return /^(powershell|pwsh)(\.exe)?$/i.test(path.win32.basename(commandPath));
|
|
30
|
+
}
|
|
20
31
|
async function createTempScriptFile(code, language, shellCommandPath) {
|
|
21
|
-
const tempDir =
|
|
22
|
-
os.tmpdir(),
|
|
23
|
-
"adk_js_unsafe_code_executor",
|
|
24
|
-
Date.now().toString() + "_" + Math.random().toString(36).slice(2)
|
|
32
|
+
const tempDir = await fs.mkdtemp(
|
|
33
|
+
path.join(os.tmpdir(), "adk_js_unsafe_code_executor_")
|
|
25
34
|
);
|
|
26
|
-
await fs.mkdir(tempDir, { recursive: true });
|
|
27
35
|
const ext = getExtensionForLanguage(language, shellCommandPath) || ".js";
|
|
28
36
|
const filePath = path.join(tempDir, "script".concat(ext));
|
|
29
37
|
await fs.writeFile(filePath, code);
|
|
@@ -43,6 +51,9 @@ function getExtensionForLanguage(language, shellCommandPath) {
|
|
|
43
51
|
return ".bat";
|
|
44
52
|
}
|
|
45
53
|
if (language === CodeExecutionLanguage.SHELL) {
|
|
54
|
+
if (shellCommandPath && isPowerShellCommand(shellCommandPath)) {
|
|
55
|
+
return ".ps1";
|
|
56
|
+
}
|
|
46
57
|
if (IS_WINDOWS) {
|
|
47
58
|
if (shellCommandPath && shellCommandPath.toLowerCase().includes("cmd")) {
|
|
48
59
|
return ".bat";
|
|
@@ -101,17 +112,17 @@ class UnsafeLocalCodeExecutor extends BaseCodeExecutor {
|
|
|
101
112
|
command = this.pythonCommandPath;
|
|
102
113
|
} else if (language === CodeExecutionLanguage.SHELL) {
|
|
103
114
|
command = this.shellCommandPath;
|
|
104
|
-
if (this.shellCommandPath
|
|
105
|
-
args = [
|
|
115
|
+
if (isPowerShellCommand(this.shellCommandPath)) {
|
|
116
|
+
args = [...POWERSHELL_BASE_ARGS, filePath];
|
|
106
117
|
} else if (this.shellCommandPath.toLowerCase().includes("cmd")) {
|
|
107
|
-
args = [
|
|
118
|
+
args = [...CMD_BASE_ARGS, filePath];
|
|
108
119
|
}
|
|
109
120
|
} else if (language === CodeExecutionLanguage.POWERSHELL) {
|
|
110
121
|
command = IS_WINDOWS ? "powershell" : "pwsh";
|
|
111
|
-
args = [
|
|
122
|
+
args = [...POWERSHELL_BASE_ARGS, filePath];
|
|
112
123
|
} else if (language === CodeExecutionLanguage.WINDOWS_CMD) {
|
|
113
124
|
command = "cmd.exe";
|
|
114
|
-
args = [
|
|
125
|
+
args = [...CMD_BASE_ARGS, filePath];
|
|
115
126
|
}
|
|
116
127
|
if (params.codeExecutionInput.args) {
|
|
117
128
|
if (Array.isArray(params.codeExecutionInput.args)) {
|
package/dist/web/common.js
CHANGED
|
@@ -56,17 +56,22 @@ import {
|
|
|
56
56
|
FileContentEncoding
|
|
57
57
|
} from "./code_executors/code_execution_utils.js";
|
|
58
58
|
import { AgentControlledContextCompactor } from "./context/agent_controlled_context_compactor.js";
|
|
59
|
+
import { AnchoredContextCompactor } from "./context/anchored_context_compactor.js";
|
|
59
60
|
import { LlmSummarizer } from "./context/summarizers/llm_summarizer.js";
|
|
60
61
|
import { TokenBasedContextCompactor } from "./context/token_based_context_compactor.js";
|
|
61
62
|
import { TrajectoryThoughtPruningCompactor } from "./context/trajectory_thought_pruning_compactor.js";
|
|
62
63
|
import { TruncatingContextCompactor } from "./context/truncating_context_compactor.js";
|
|
63
|
-
import { isCompactedEvent } from "./events/compacted_event.js";
|
|
64
|
+
import { isCompactedEvent, isScratchpadEvent } from "./events/compacted_event.js";
|
|
64
65
|
import {
|
|
65
66
|
createEvent,
|
|
67
|
+
generateClientFunctionCallId,
|
|
66
68
|
getFunctionCalls,
|
|
67
69
|
getFunctionResponses,
|
|
70
|
+
hasThoughts,
|
|
68
71
|
hasTrailingCodeExecutionResult,
|
|
69
72
|
isFinalResponse,
|
|
73
|
+
populateClientFunctionCallId,
|
|
74
|
+
pruneThoughts,
|
|
70
75
|
stringifyContent
|
|
71
76
|
} from "./events/event.js";
|
|
72
77
|
import { createEventActions } from "./events/event_actions.js";
|
|
@@ -83,6 +88,7 @@ import { Gemini, geminiInitParams } from "./models/google_llm.js";
|
|
|
83
88
|
import { LLMRegistry } from "./models/registry.js";
|
|
84
89
|
import { RoutedLlm } from "./models/routed_llm.js";
|
|
85
90
|
import { BasePlugin, ContextCompactionTrigger } from "./plugins/base_plugin.js";
|
|
91
|
+
import { GlobalInstructionPlugin } from "./plugins/global_instruction_plugin.js";
|
|
86
92
|
import { LoggingPlugin } from "./plugins/logging_plugin.js";
|
|
87
93
|
import { PluginManager } from "./plugins/plugin_manager.js";
|
|
88
94
|
import {
|
|
@@ -108,8 +114,14 @@ import { AgentTool, isAgentTool } from "./tools/agent_tool.js";
|
|
|
108
114
|
import { BaseTool, isBaseTool } from "./tools/base_tool.js";
|
|
109
115
|
import { BaseToolset, isBaseToolset } from "./tools/base_toolset.js";
|
|
110
116
|
import { ConsolidateContextTool } from "./tools/consolidate_context_tool.js";
|
|
117
|
+
import {
|
|
118
|
+
ENTERPRISE_WEB_SEARCH,
|
|
119
|
+
EnterpriseWebSearchTool
|
|
120
|
+
} from "./tools/enterprise_web_search_tool.js";
|
|
121
|
+
import { ExampleTool } from "./tools/example_tool.js";
|
|
111
122
|
import { EXIT_LOOP, ExitLoopTool } from "./tools/exit_loop_tool.js";
|
|
112
123
|
import { FunctionTool, isFunctionTool } from "./tools/function_tool.js";
|
|
124
|
+
import { getUserChoiceTool } from "./tools/get_user_choice_tool.js";
|
|
113
125
|
import {
|
|
114
126
|
GOOGLE_MAPS_GROUNDING,
|
|
115
127
|
GoogleMapsGroundingTool
|
|
@@ -120,11 +132,13 @@ import {
|
|
|
120
132
|
LoadArtifactsTool
|
|
121
133
|
} from "./tools/load_artifacts_tool.js";
|
|
122
134
|
import { LOAD_MEMORY, LoadMemoryTool } from "./tools/load_memory_tool.js";
|
|
135
|
+
import { LOAD_WEB_PAGE, loadWebPage } from "./tools/load_web_page.js";
|
|
123
136
|
import { LongRunningFunctionTool } from "./tools/long_running_tool.js";
|
|
124
137
|
import {
|
|
125
138
|
PRELOAD_MEMORY,
|
|
126
139
|
PreloadMemoryTool
|
|
127
140
|
} from "./tools/preload_memory_tool.js";
|
|
141
|
+
import { requestInputTool } from "./tools/request_input_tool.js";
|
|
128
142
|
import { ToolConfirmation } from "./tools/tool_confirmation.js";
|
|
129
143
|
import { URL_CONTEXT, UrlContextTool } from "./tools/url_context_tool.js";
|
|
130
144
|
import { VertexAiSearchTool } from "./tools/vertex_ai_search_tool.js";
|
|
@@ -174,6 +188,7 @@ export {
|
|
|
174
188
|
AgentControlledContextCompactor,
|
|
175
189
|
AgentTool,
|
|
176
190
|
AgentTransferLlmRequestProcessor,
|
|
191
|
+
AnchoredContextCompactor,
|
|
177
192
|
ApigeeLlm,
|
|
178
193
|
AuthCredentialTypes,
|
|
179
194
|
AuthHandler,
|
|
@@ -199,8 +214,11 @@ export {
|
|
|
199
214
|
ContextCompactorRequestProcessor,
|
|
200
215
|
CredentialExchangeError,
|
|
201
216
|
CredentialRefresherRegistry,
|
|
217
|
+
ENTERPRISE_WEB_SEARCH,
|
|
202
218
|
EXIT_LOOP,
|
|
219
|
+
EnterpriseWebSearchTool,
|
|
203
220
|
EventType,
|
|
221
|
+
ExampleTool,
|
|
204
222
|
ExitLoopTool,
|
|
205
223
|
FileContentEncoding,
|
|
206
224
|
FunctionTool,
|
|
@@ -208,6 +226,7 @@ export {
|
|
|
208
226
|
GOOGLE_MAPS_GROUNDING,
|
|
209
227
|
GOOGLE_SEARCH,
|
|
210
228
|
Gemini,
|
|
229
|
+
GlobalInstructionPlugin,
|
|
211
230
|
GoogleLLMVariant,
|
|
212
231
|
GoogleMapsGroundingTool,
|
|
213
232
|
GoogleSearchTool,
|
|
@@ -223,6 +242,7 @@ export {
|
|
|
223
242
|
LLMRegistry,
|
|
224
243
|
LOAD_ARTIFACTS,
|
|
225
244
|
LOAD_MEMORY,
|
|
245
|
+
LOAD_WEB_PAGE,
|
|
226
246
|
ListSkillsTool,
|
|
227
247
|
LiveRequestQueue,
|
|
228
248
|
LlmAgent2 as LlmAgent,
|
|
@@ -281,11 +301,14 @@ export {
|
|
|
281
301
|
findMatchingFunctionCall,
|
|
282
302
|
functionsExportedForTestingOnly,
|
|
283
303
|
geminiInitParams,
|
|
304
|
+
generateClientFunctionCallId,
|
|
284
305
|
getAskUserConfirmationFunctionCalls,
|
|
285
306
|
getClientLabels,
|
|
286
307
|
getFunctionCalls,
|
|
287
308
|
getFunctionResponses,
|
|
288
309
|
getLogger,
|
|
310
|
+
getUserChoiceTool,
|
|
311
|
+
hasThoughts,
|
|
289
312
|
hasTrailingCodeExecutionResult,
|
|
290
313
|
isAgentTool,
|
|
291
314
|
isBaseAgent,
|
|
@@ -304,10 +327,15 @@ export {
|
|
|
304
327
|
isRoutableLlmAgent,
|
|
305
328
|
isRoutedAgent,
|
|
306
329
|
isRunner,
|
|
330
|
+
isScratchpadEvent,
|
|
307
331
|
isSequentialAgent,
|
|
308
332
|
loadAllSkillsInDir,
|
|
309
333
|
loadSkillFromDir,
|
|
310
334
|
loadSkillFromZipBuffer,
|
|
335
|
+
loadWebPage,
|
|
336
|
+
populateClientFunctionCallId,
|
|
337
|
+
pruneThoughts,
|
|
338
|
+
requestInputTool,
|
|
311
339
|
runWithClientLabel,
|
|
312
340
|
setLogLevel,
|
|
313
341
|
setLogger,
|
|
@@ -5,9 +5,9 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
5
5
|
* Copyright 2026 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
|
-
import { isCompactedEvent } from "../events/compacted_event.js";
|
|
9
8
|
import { createEvent } from "../events/event.js";
|
|
10
9
|
import { ContextCompactionTrigger } from "../plugins/base_plugin.js";
|
|
10
|
+
import { getActiveEvents } from "./compaction_utils.js";
|
|
11
11
|
class AgentControlledContextCompactor {
|
|
12
12
|
constructor(options) {
|
|
13
13
|
this.trigger = ContextCompactionTrigger.AgentControlled;
|
|
@@ -18,7 +18,7 @@ class AgentControlledContextCompactor {
|
|
|
18
18
|
}
|
|
19
19
|
async compact(invocationContext) {
|
|
20
20
|
const events = invocationContext.session.events;
|
|
21
|
-
const activeEvents =
|
|
21
|
+
const activeEvents = getActiveEvents(events);
|
|
22
22
|
const consolidateToolCallIndex = activeEvents.reduce(
|
|
23
23
|
(acc, e, idx) => {
|
|
24
24
|
var _a, _b;
|
|
@@ -66,15 +66,6 @@ class AgentControlledContextCompactor {
|
|
|
66
66
|
delete invocationContext.session.state["temp:consolidate_context"];
|
|
67
67
|
delete invocationContext.session.state["temp:consolidate_context_detail"];
|
|
68
68
|
}
|
|
69
|
-
getActiveEvents(events) {
|
|
70
|
-
const latest = events.filter(isCompactedEvent).pop();
|
|
71
|
-
return latest ? [
|
|
72
|
-
latest,
|
|
73
|
-
...events.filter(
|
|
74
|
-
(e) => !isCompactedEvent(e) && e.timestamp > latest.endTime
|
|
75
|
-
)
|
|
76
|
-
] : events;
|
|
77
|
-
}
|
|
78
69
|
}
|
|
79
70
|
export {
|
|
80
71
|
AgentControlledContextCompactor
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
+
/**
|
|
23
|
+
* @license
|
|
24
|
+
* Copyright 2026 Google LLC
|
|
25
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
26
|
+
*/
|
|
27
|
+
import { isScratchpadEvent } from "../events/compacted_event.js";
|
|
28
|
+
import { getEventTokens } from "../events/event.js";
|
|
29
|
+
import { calculateRetainStartIndex } from "./compaction_utils.js";
|
|
30
|
+
class AnchoredContextCompactor {
|
|
31
|
+
constructor(options) {
|
|
32
|
+
this.tokenThreshold = options.tokenThreshold;
|
|
33
|
+
this.eventRetentionSize = options.eventRetentionSize;
|
|
34
|
+
this.summarizer = options.summarizer;
|
|
35
|
+
}
|
|
36
|
+
getActiveEvents(events) {
|
|
37
|
+
let latestScratchpad = void 0;
|
|
38
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
39
|
+
const e = events[i];
|
|
40
|
+
if (isScratchpadEvent(e)) {
|
|
41
|
+
latestScratchpad = e;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (!latestScratchpad) {
|
|
46
|
+
return events;
|
|
47
|
+
}
|
|
48
|
+
const activeRawEvents = events.filter(
|
|
49
|
+
(e) => e.timestamp > latestScratchpad.endTime && !isScratchpadEvent(e)
|
|
50
|
+
);
|
|
51
|
+
return [latestScratchpad, ...activeRawEvents];
|
|
52
|
+
}
|
|
53
|
+
shouldCompact(invocationContext) {
|
|
54
|
+
const events = invocationContext.session.events;
|
|
55
|
+
const activeEvents = this.getActiveEvents(events);
|
|
56
|
+
const hasScratchpad = activeEvents.length > 0 && isScratchpadEvent(activeEvents[0]);
|
|
57
|
+
const rawEvents = hasScratchpad ? activeEvents.slice(1) : activeEvents;
|
|
58
|
+
if (rawEvents.length <= this.eventRetentionSize) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
const retainStartIndex = calculateRetainStartIndex(
|
|
62
|
+
rawEvents,
|
|
63
|
+
this.eventRetentionSize
|
|
64
|
+
);
|
|
65
|
+
if (retainStartIndex === 0) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const totalTokens = activeEvents.reduce(
|
|
69
|
+
(sum, event) => sum + getEventTokens(event),
|
|
70
|
+
0
|
|
71
|
+
);
|
|
72
|
+
return totalTokens > this.tokenThreshold;
|
|
73
|
+
}
|
|
74
|
+
async compact(invocationContext) {
|
|
75
|
+
const events = invocationContext.session.events;
|
|
76
|
+
const activeEvents = this.getActiveEvents(events);
|
|
77
|
+
const hasScratchpad = activeEvents.length > 0 && isScratchpadEvent(activeEvents[0]);
|
|
78
|
+
const rawEvents = hasScratchpad ? activeEvents.slice(1) : activeEvents;
|
|
79
|
+
if (rawEvents.length <= this.eventRetentionSize) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const retainStartIndex = calculateRetainStartIndex(
|
|
83
|
+
rawEvents,
|
|
84
|
+
this.eventRetentionSize
|
|
85
|
+
);
|
|
86
|
+
if (retainStartIndex === 0) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const rawEventsToCompact = rawEvents.slice(0, retainStartIndex);
|
|
90
|
+
let scratchpadEvent;
|
|
91
|
+
if (hasScratchpad) {
|
|
92
|
+
const existingScratchpad = activeEvents[0];
|
|
93
|
+
scratchpadEvent = await this.summarizer.summarize([
|
|
94
|
+
existingScratchpad,
|
|
95
|
+
...rawEventsToCompact
|
|
96
|
+
]);
|
|
97
|
+
} else {
|
|
98
|
+
scratchpadEvent = await this.summarizer.summarize(rawEventsToCompact);
|
|
99
|
+
}
|
|
100
|
+
const updatedScratchpad = __spreadProps(__spreadValues({}, scratchpadEvent), {
|
|
101
|
+
isScratchpad: true,
|
|
102
|
+
author: "system"
|
|
103
|
+
});
|
|
104
|
+
const inactiveEvents = events.slice(0, events.indexOf(activeEvents[0]));
|
|
105
|
+
const retainedRawEvents = rawEvents.slice(retainStartIndex);
|
|
106
|
+
const newEventsList = [
|
|
107
|
+
...inactiveEvents,
|
|
108
|
+
updatedScratchpad,
|
|
109
|
+
...retainedRawEvents
|
|
110
|
+
];
|
|
111
|
+
events.length = 0;
|
|
112
|
+
events.push(...newEventsList);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export {
|
|
116
|
+
AnchoredContextCompactor
|
|
117
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
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 { isCompactedEvent } from "../events/compacted_event.js";
|
|
9
|
+
import {
|
|
10
|
+
getFunctionCalls,
|
|
11
|
+
getFunctionResponses
|
|
12
|
+
} from "../events/event.js";
|
|
13
|
+
function getActiveEvents(events) {
|
|
14
|
+
const latest = events.filter(isCompactedEvent).pop();
|
|
15
|
+
return latest ? [
|
|
16
|
+
latest,
|
|
17
|
+
...events.filter(
|
|
18
|
+
(e) => !isCompactedEvent(e) && e.timestamp > latest.endTime
|
|
19
|
+
)
|
|
20
|
+
] : events;
|
|
21
|
+
}
|
|
22
|
+
function calculateRetainStartIndex(rawEvents, eventRetentionSize) {
|
|
23
|
+
let retainStartIndex = Math.max(0, rawEvents.length - eventRetentionSize);
|
|
24
|
+
while (retainStartIndex > 0) {
|
|
25
|
+
const eventToRetain = rawEvents[retainStartIndex];
|
|
26
|
+
const previousEvent = rawEvents[retainStartIndex - 1];
|
|
27
|
+
if (getFunctionResponses(eventToRetain).length > 0 && getFunctionCalls(previousEvent).length > 0) {
|
|
28
|
+
retainStartIndex--;
|
|
29
|
+
} else {
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return retainStartIndex;
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
calculateRetainStartIndex,
|
|
37
|
+
getActiveEvents
|
|
38
|
+
};
|
|
@@ -7,6 +7,10 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
7
7
|
*/
|
|
8
8
|
import { getContents } from "../agents/processors/content_processor_utils.js";
|
|
9
9
|
import { isCompactedEvent } from "../events/compacted_event.js";
|
|
10
|
+
import {
|
|
11
|
+
calculateRetainStartIndex,
|
|
12
|
+
getActiveEvents
|
|
13
|
+
} from "./compaction_utils.js";
|
|
10
14
|
const CHARS_PER_TOKEN = 4;
|
|
11
15
|
class TokenBasedContextCompactor {
|
|
12
16
|
constructor(options) {
|
|
@@ -14,31 +18,20 @@ class TokenBasedContextCompactor {
|
|
|
14
18
|
this.eventRetentionSize = options.eventRetentionSize;
|
|
15
19
|
this.summarizer = options.summarizer;
|
|
16
20
|
}
|
|
17
|
-
getActiveEvents(events) {
|
|
18
|
-
let latestCompactedEvent = void 0;
|
|
19
|
-
for (let i = events.length - 1; i >= 0; i--) {
|
|
20
|
-
const e = events[i];
|
|
21
|
-
if (isCompactedEvent(e)) {
|
|
22
|
-
if (!latestCompactedEvent || e.endTime > latestCompactedEvent.endTime) {
|
|
23
|
-
latestCompactedEvent = e;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if (!latestCompactedEvent) {
|
|
28
|
-
return events;
|
|
29
|
-
}
|
|
30
|
-
const activeRawEvents = events.filter(
|
|
31
|
-
(e) => !isCompactedEvent(e) && e.timestamp > latestCompactedEvent.endTime
|
|
32
|
-
);
|
|
33
|
-
return [latestCompactedEvent, ...activeRawEvents];
|
|
34
|
-
}
|
|
35
21
|
shouldCompact(invocationContext) {
|
|
36
22
|
const events = invocationContext.session.events;
|
|
37
|
-
const activeEvents =
|
|
23
|
+
const activeEvents = getActiveEvents(events);
|
|
38
24
|
const rawEvents = activeEvents.filter((e) => !isCompactedEvent(e));
|
|
39
25
|
if (rawEvents.length <= this.eventRetentionSize) {
|
|
40
26
|
return false;
|
|
41
27
|
}
|
|
28
|
+
const retainStartIndex = calculateRetainStartIndex(
|
|
29
|
+
rawEvents,
|
|
30
|
+
this.eventRetentionSize
|
|
31
|
+
);
|
|
32
|
+
if (retainStartIndex === 0) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
42
35
|
const promptTokenCount = latestPromptTokenCount(
|
|
43
36
|
activeEvents,
|
|
44
37
|
invocationContext
|
|
@@ -50,24 +43,15 @@ class TokenBasedContextCompactor {
|
|
|
50
43
|
}
|
|
51
44
|
async compact(invocationContext) {
|
|
52
45
|
const events = invocationContext.session.events;
|
|
53
|
-
const activeEvents =
|
|
46
|
+
const activeEvents = getActiveEvents(events);
|
|
54
47
|
const rawEvents = activeEvents.filter((e) => !isCompactedEvent(e));
|
|
55
48
|
if (rawEvents.length <= this.eventRetentionSize) {
|
|
56
49
|
return;
|
|
57
50
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
51
|
+
const retainStartIndex = calculateRetainStartIndex(
|
|
52
|
+
rawEvents,
|
|
53
|
+
this.eventRetentionSize
|
|
61
54
|
);
|
|
62
|
-
while (retainStartIndex > 0) {
|
|
63
|
-
const eventToRetain = rawEvents[retainStartIndex];
|
|
64
|
-
const previousEvent = rawEvents[retainStartIndex - 1];
|
|
65
|
-
if (hasFunctionResponse(eventToRetain) && hasFunctionCall(previousEvent)) {
|
|
66
|
-
retainStartIndex--;
|
|
67
|
-
} else {
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
55
|
if (retainStartIndex === 0) {
|
|
72
56
|
return;
|
|
73
57
|
}
|
|
@@ -122,18 +106,6 @@ function estimatePromptTokenCount(activeEvents, invocationContext) {
|
|
|
122
106
|
}
|
|
123
107
|
return Math.ceil(totalChars / CHARS_PER_TOKEN);
|
|
124
108
|
}
|
|
125
|
-
function hasFunctionCall(event) {
|
|
126
|
-
var _a, _b;
|
|
127
|
-
return !!((_b = (_a = event.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.some(
|
|
128
|
-
(part) => part.functionCall !== void 0
|
|
129
|
-
));
|
|
130
|
-
}
|
|
131
|
-
function hasFunctionResponse(event) {
|
|
132
|
-
var _a, _b;
|
|
133
|
-
return !!((_b = (_a = event.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.some(
|
|
134
|
-
(part) => part.functionResponse !== void 0
|
|
135
|
-
));
|
|
136
|
-
}
|
|
137
109
|
export {
|
|
138
110
|
TokenBasedContextCompactor
|
|
139
111
|
};
|
|
@@ -28,15 +28,20 @@ import { createEvent } from "./event.js";
|
|
|
28
28
|
function isCompactedEvent(event) {
|
|
29
29
|
return "isCompacted" in event && event.isCompacted === true;
|
|
30
30
|
}
|
|
31
|
+
function isScratchpadEvent(event) {
|
|
32
|
+
return isCompactedEvent(event) && event.isScratchpad === true;
|
|
33
|
+
}
|
|
31
34
|
function createCompactedEvent(params = {}) {
|
|
32
35
|
return __spreadProps(__spreadValues({}, createEvent(params)), {
|
|
33
36
|
isCompacted: params.isCompacted || true,
|
|
34
37
|
startTime: params.startTime,
|
|
35
38
|
endTime: params.endTime,
|
|
36
|
-
compactedContent: params.compactedContent
|
|
39
|
+
compactedContent: params.compactedContent,
|
|
40
|
+
isScratchpad: params.isScratchpad
|
|
37
41
|
});
|
|
38
42
|
}
|
|
39
43
|
export {
|
|
40
44
|
createCompactedEvent,
|
|
41
|
-
isCompactedEvent
|
|
45
|
+
isCompactedEvent,
|
|
46
|
+
isScratchpadEvent
|
|
42
47
|
};
|
package/dist/web/events/event.js
CHANGED
|
@@ -24,6 +24,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
24
24
|
* Copyright 2026 Google LLC
|
|
25
25
|
* SPDX-License-Identifier: Apache-2.0
|
|
26
26
|
*/
|
|
27
|
+
import { randomUUID } from "../utils/env_aware_utils.js";
|
|
27
28
|
import { toCamelCase, toSnakeCase } from "../utils/object_notation_utils.js";
|
|
28
29
|
import { createEventActions } from "./event_actions.js";
|
|
29
30
|
function createEvent(params = {}) {
|
|
@@ -54,6 +55,17 @@ function getFunctionCalls(event) {
|
|
|
54
55
|
}
|
|
55
56
|
return funcCalls;
|
|
56
57
|
}
|
|
58
|
+
const AF_FUNCTION_CALL_ID_PREFIX = "adk-";
|
|
59
|
+
function generateClientFunctionCallId() {
|
|
60
|
+
return "".concat(AF_FUNCTION_CALL_ID_PREFIX).concat(randomUUID());
|
|
61
|
+
}
|
|
62
|
+
function populateClientFunctionCallId(modelResponseEvent) {
|
|
63
|
+
for (const functionCall of getFunctionCalls(modelResponseEvent)) {
|
|
64
|
+
if (!functionCall.id) {
|
|
65
|
+
functionCall.id = generateClientFunctionCallId();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
57
69
|
function getFunctionResponses(event) {
|
|
58
70
|
const funcResponses = [];
|
|
59
71
|
if (event.content && event.content.parts) {
|
|
@@ -83,6 +95,14 @@ function stringifyContent(event) {
|
|
|
83
95
|
return (_a2 = part.text) != null ? _a2 : "";
|
|
84
96
|
}).join("");
|
|
85
97
|
}
|
|
98
|
+
function getEventTokens(event) {
|
|
99
|
+
var _a;
|
|
100
|
+
if (((_a = event.usageMetadata) == null ? void 0 : _a.promptTokenCount) !== void 0) {
|
|
101
|
+
return event.usageMetadata.promptTokenCount;
|
|
102
|
+
}
|
|
103
|
+
const contentStr = stringifyContent(event);
|
|
104
|
+
return Math.ceil(contentStr.length / 4);
|
|
105
|
+
}
|
|
86
106
|
function hasThoughts(event) {
|
|
87
107
|
var _a, _b;
|
|
88
108
|
return !!((_b = (_a = event.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.some((part) => part.thought === true));
|
|
@@ -136,13 +156,17 @@ function transformToSnakeCaseEvent(event) {
|
|
|
136
156
|
return toSnakeCase(event, PRESERVE_KEYS_CAMEL_CASE);
|
|
137
157
|
}
|
|
138
158
|
export {
|
|
159
|
+
AF_FUNCTION_CALL_ID_PREFIX,
|
|
139
160
|
createEvent,
|
|
140
161
|
createNewEventId,
|
|
162
|
+
generateClientFunctionCallId,
|
|
163
|
+
getEventTokens,
|
|
141
164
|
getFunctionCalls,
|
|
142
165
|
getFunctionResponses,
|
|
143
166
|
hasThoughts,
|
|
144
167
|
hasTrailingCodeExecutionResult,
|
|
145
168
|
isFinalResponse,
|
|
169
|
+
populateClientFunctionCallId,
|
|
146
170
|
pruneThoughts,
|
|
147
171
|
stringifyContent,
|
|
148
172
|
transformToCamelCaseEvent,
|
package/dist/web/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import { AGENT_CARD_PATH, RemoteA2AAgent } from "./a2a/a2a_remote_agent.js";
|
|
|
9
9
|
import { getA2AAgentCard } from "./a2a/agent_card.js";
|
|
10
10
|
import { A2AAgentExecutor } from "./a2a/agent_executor.js";
|
|
11
11
|
import { toA2a } from "./a2a/agent_to_a2a.js";
|
|
12
|
+
import { bearerTokenUserBuilder } from "./a2a/auth.js";
|
|
12
13
|
import { InvocationContext } from "./agents/invocation_context.js";
|
|
13
14
|
import { FileArtifactService } from "./artifacts/file_artifact_service.js";
|
|
14
15
|
import { GcsArtifactService } from "./artifacts/gcs_artifact_service.js";
|
|
@@ -29,11 +30,15 @@ import {
|
|
|
29
30
|
loadSkillFromDir,
|
|
30
31
|
validateSkillDir
|
|
31
32
|
} from "./skills/loader.js";
|
|
32
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
RunSkillInlineScriptErrorCode,
|
|
35
|
+
RunSkillInlineScriptTool
|
|
36
|
+
} from "./tools/skill/run_skill_inline_script_tool.js";
|
|
33
37
|
import { RunSkillScriptTool } from "./tools/skill/run_skill_script_tool.js";
|
|
34
38
|
export * from "./integrations/agent_registry/agent_registry.js";
|
|
35
39
|
export * from "./telemetry/google_cloud.js";
|
|
36
40
|
export * from "./telemetry/setup.js";
|
|
41
|
+
export * from "./tools/mcp/load_mcp_resource_tool.js";
|
|
37
42
|
export * from "./tools/mcp/mcp_session_manager.js";
|
|
38
43
|
export * from "./tools/mcp/mcp_tool.js";
|
|
39
44
|
export * from "./tools/mcp/mcp_toolset.js";
|
|
@@ -47,10 +52,12 @@ export {
|
|
|
47
52
|
GcsArtifactService,
|
|
48
53
|
InvocationContext,
|
|
49
54
|
RemoteA2AAgent,
|
|
55
|
+
RunSkillInlineScriptErrorCode,
|
|
50
56
|
RunSkillInlineScriptTool,
|
|
51
57
|
RunSkillScriptTool,
|
|
52
58
|
UnsafeLocalCodeExecutor,
|
|
53
59
|
VertexAiSessionService,
|
|
60
|
+
bearerTokenUserBuilder,
|
|
54
61
|
getA2AAgentCard,
|
|
55
62
|
getArtifactServiceFromUri,
|
|
56
63
|
getSessionServiceFromUri,
|
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
MCPSessionManager
|
|
30
30
|
} from "../../tools/mcp/mcp_session_manager.js";
|
|
31
31
|
import { MCPTool } from "../../tools/mcp/mcp_tool.js";
|
|
32
|
+
import { logger } from "../../utils/logger.js";
|
|
32
33
|
import { GCP_MCP_SERVER_DESTINATION_ID } from "./types.js";
|
|
33
34
|
class AgentRegistrySingleMCPToolset extends BaseToolset {
|
|
34
35
|
/**
|
|
@@ -78,7 +79,14 @@ class AgentRegistrySingleMCPToolset extends BaseToolset {
|
|
|
78
79
|
});
|
|
79
80
|
const sessionManager = new MCPSessionManager(connectionParamsCopy);
|
|
80
81
|
const session = await sessionManager.createSession();
|
|
81
|
-
|
|
82
|
+
let listResult;
|
|
83
|
+
try {
|
|
84
|
+
listResult = await session.listTools();
|
|
85
|
+
} finally {
|
|
86
|
+
await sessionManager.closeSession(session).catch((e) => {
|
|
87
|
+
logger.warn("Failed to close MCP discovery session", e);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
82
90
|
const tools = listResult.tools.map((tool) => {
|
|
83
91
|
const prefixedName = this.prefix ? "".concat(this.prefix, "_").concat(tool.name) : tool.name;
|
|
84
92
|
const mcpTool = new MCPTool(
|