@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,6 +7,15 @@ import { Session } from './session.js';
|
|
|
7
7
|
export declare function isInMemoryConnectionString(uri?: string): boolean;
|
|
8
8
|
/**
|
|
9
9
|
* An in-memory implementation of the session service.
|
|
10
|
+
*
|
|
11
|
+
* Every map below is keyed by untrusted input — `appName`, `userId`,
|
|
12
|
+
* `sessionId` and state keys all arrive straight off the request path or body
|
|
13
|
+
* on a dev server — so each is created with `Object.create(null)`. On an
|
|
14
|
+
* ordinary `{}` literal a key of `__proto__` resolves to the inherited
|
|
15
|
+
* `__proto__` accessor instead of creating an own property, so
|
|
16
|
+
* `map[appName][userId] = ...` writes onto `Object.prototype` and pollutes
|
|
17
|
+
* every object in the process. A null-prototype map has no such accessor, so
|
|
18
|
+
* those keys become ordinary own properties.
|
|
10
19
|
*/
|
|
11
20
|
export declare class InMemorySessionService extends BaseSessionService {
|
|
12
21
|
/**
|
|
@@ -26,6 +26,19 @@ export interface VertexAiSessionServiceOptions {
|
|
|
26
26
|
expressModeApiKey?: string;
|
|
27
27
|
sessions?: Sessions;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* The parameters for `VertexAiSessionService.createSession`.
|
|
31
|
+
*
|
|
32
|
+
* Extends the common {@link CreateSessionRequest} with the mutually exclusive
|
|
33
|
+
* session-expiration options supported by Vertex AI Agent Engine Sessions. See
|
|
34
|
+
* https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1beta1/projects.locations.reasoningEngines.sessions
|
|
35
|
+
*/
|
|
36
|
+
export interface VertexAiCreateSessionRequest extends CreateSessionRequest {
|
|
37
|
+
/** Lifetime relative to creation, in seconds, e.g. `'7200s'`. */
|
|
38
|
+
ttl?: string;
|
|
39
|
+
/** Absolute RFC 3339 UTC expiration, e.g. `'2025-10-01T00:00:00Z'`. */
|
|
40
|
+
expireTime?: string;
|
|
41
|
+
}
|
|
29
42
|
/**
|
|
30
43
|
* A session service implementation that integrates with Vertex AI Agent Engine Sessions.
|
|
31
44
|
*/
|
|
@@ -37,7 +50,12 @@ export declare class VertexAiSessionService extends BaseSessionService {
|
|
|
37
50
|
private location?;
|
|
38
51
|
constructor(options: VertexAiSessionServiceOptions);
|
|
39
52
|
private getReasoningEngineId;
|
|
40
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Creates a session on Vertex AI Agent Engine.
|
|
55
|
+
*
|
|
56
|
+
* @throws if both `ttl` and `expireTime` are specified.
|
|
57
|
+
*/
|
|
58
|
+
createSession({ appName, userId, state, sessionId, ttl, expireTime, }: VertexAiCreateSessionRequest): Promise<Session>;
|
|
41
59
|
getSession({ appName, userId, sessionId, config, }: GetSessionRequest): Promise<Session | undefined>;
|
|
42
60
|
listSessions({ appName, userId, limit, offset, page, order, }: ListSessionsRequest): Promise<ListSessionsResponse>;
|
|
43
61
|
deleteSession({ appName, userId, sessionId, }: DeleteSessionRequest): Promise<void>;
|
|
@@ -39,7 +39,12 @@ export declare function loadAllSkillsInDir(skillsBasePath: string): Promise<Reco
|
|
|
39
39
|
/**
|
|
40
40
|
* Loads a complete skill directly from in-memory zip file buffer.
|
|
41
41
|
*
|
|
42
|
+
* The whole archive is rejected if any member name escapes the extraction
|
|
43
|
+
* root, and the skill name must be a bare path segment.
|
|
44
|
+
*
|
|
42
45
|
* @param zipBuffer - The raw Buffer of the zip file containing the skill.
|
|
43
46
|
* @returns A Skill object with all components loaded.
|
|
47
|
+
* @throws {Error} If a member name is a traversal path, if SKILL.md is missing,
|
|
48
|
+
* or if the skill name is missing or is not a bare path segment.
|
|
44
49
|
*/
|
|
45
50
|
export declare function loadSkillFromZipBuffer(zipBuffer: Buffer): Skill;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { LlmRequest } from '../models/llm_request.js';
|
|
2
|
+
import { BaseTool, ToolProcessLlmRequest } from './base_tool.js';
|
|
3
|
+
/**
|
|
4
|
+
* Appends the Enterprise Web Search built-in tool to the LLM request when the
|
|
5
|
+
* target model supports it.
|
|
6
|
+
*
|
|
7
|
+
* NOTE: This is NOT Vertex AI Search (formerly "Enterprise Search"). See
|
|
8
|
+
* https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/web-grounding-enterprise
|
|
9
|
+
*/
|
|
10
|
+
export declare function applyEnterpriseWebSearch(llmRequest: LlmRequest): void;
|
|
11
|
+
/**
|
|
12
|
+
* A Gemini 2+ built-in tool that grounds responses on public web data via
|
|
13
|
+
* Vertex AI Search with Enterprise (Sec4) compliance.
|
|
14
|
+
*
|
|
15
|
+
* This tool operates internally within the model and does not require or
|
|
16
|
+
* perform local code execution.
|
|
17
|
+
*/
|
|
18
|
+
export declare class EnterpriseWebSearchTool extends BaseTool {
|
|
19
|
+
constructor();
|
|
20
|
+
runAsync(): Promise<unknown>;
|
|
21
|
+
processLlmRequest({ llmRequest, }: ToolProcessLlmRequest): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A global instance of {@link EnterpriseWebSearchTool}.
|
|
25
|
+
*/
|
|
26
|
+
export declare const ENTERPRISE_WEB_SEARCH: EnterpriseWebSearchTool;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { BaseExampleProvider } from '../examples/base_example_provider.js';
|
|
7
|
+
import { Example } from '../examples/example.js';
|
|
8
|
+
import { BaseTool, RunAsyncToolRequest, ToolProcessLlmRequest } from './base_tool.js';
|
|
9
|
+
/**
|
|
10
|
+
* A tool that adds (few-shot) examples to the LLM request.
|
|
11
|
+
*
|
|
12
|
+
* This tool is executed for each LLM request and is never called by the model;
|
|
13
|
+
* it only mutates the outgoing request by appending few-shot instructions built
|
|
14
|
+
* from the latest user query.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ExampleTool extends BaseTool {
|
|
17
|
+
readonly examples: Example[] | BaseExampleProvider;
|
|
18
|
+
constructor(examples: Example[] | BaseExampleProvider);
|
|
19
|
+
runAsync(_request: RunAsyncToolRequest): Promise<unknown>;
|
|
20
|
+
processLlmRequest({ toolContext, llmRequest, }: ToolProcessLlmRequest): Promise<void>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { LongRunningFunctionTool } from './long_running_tool.js';
|
|
8
|
+
/**
|
|
9
|
+
* A long-running tool that presents a list of options to the user and awaits
|
|
10
|
+
* their selection.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getUserChoiceTool: LongRunningFunctionTool<z.ZodObject<{
|
|
13
|
+
options: z.ZodArray<z.ZodString>;
|
|
14
|
+
}, z.core.$strip>>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { FunctionTool } from './function_tool.js';
|
|
8
|
+
/** Options for {@link loadWebPage}. */
|
|
9
|
+
export interface LoadWebPageOptions {
|
|
10
|
+
/** Request timeout in milliseconds. Defaults to 30_000 (30s). */
|
|
11
|
+
timeoutMs?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Fetches the content at `url` and returns its extracted, readable text.
|
|
15
|
+
*
|
|
16
|
+
* Hardened against SSRF: only `http`/`https` URLs are fetched, the host is
|
|
17
|
+
* resolved and rejected up front if it is `localhost`-style or resolves to a
|
|
18
|
+
* private / loopback / link-local / shared / reserved / multicast address, and
|
|
19
|
+
* redirects are never followed. Never throws for expected failures (bad scheme,
|
|
20
|
+
* blocked host, non-200, timeout, network error); returns
|
|
21
|
+
* `Failed to fetch url: <url>` instead.
|
|
22
|
+
*
|
|
23
|
+
* Known limitation: global `fetch` performs its own DNS resolution at connect
|
|
24
|
+
* time, so a residual time-of-check/time-of-use (DNS-rebinding) window exists
|
|
25
|
+
* between this pre-flight lookup and fetch's own lookup. Full connection
|
|
26
|
+
* IP-pinning (e.g. an `undici` Agent with a custom `lookup`) is a possible
|
|
27
|
+
* future hardening.
|
|
28
|
+
*/
|
|
29
|
+
export declare function loadWebPage(url: string, options?: LoadWebPageOptions): Promise<string>;
|
|
30
|
+
/** A global {@link FunctionTool} exposing {@link loadWebPage} to the model. */
|
|
31
|
+
export declare const LOAD_WEB_PAGE: FunctionTool<z.ZodObject<{
|
|
32
|
+
url: z.ZodString;
|
|
33
|
+
}, z.core.$strip>>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { FunctionDeclaration } from '@google/genai';
|
|
7
|
+
import { BaseTool, RunAsyncToolRequest, ToolProcessLlmRequest } from '../base_tool.js';
|
|
8
|
+
import { MCPToolset } from './mcp_toolset.js';
|
|
9
|
+
/**
|
|
10
|
+
* A tool that loads MCP server resources and adds them to the session.
|
|
11
|
+
*
|
|
12
|
+
* This mirrors the in-repo `LoadArtifactsTool` idiom: the model calls
|
|
13
|
+
* `load_mcp_resource` with the names of the resources it wants, and on the next
|
|
14
|
+
* turn {@link processLlmRequest} reads those resources over the MCP session and
|
|
15
|
+
* appends their contents (text and base64-encoded binary) to the request
|
|
16
|
+
* context.
|
|
17
|
+
*/
|
|
18
|
+
export declare class LoadMcpResourceTool extends BaseTool {
|
|
19
|
+
private readonly mcpToolset;
|
|
20
|
+
constructor(mcpToolset: MCPToolset);
|
|
21
|
+
_getDeclaration(): FunctionDeclaration;
|
|
22
|
+
runAsync({ args }: RunAsyncToolRequest): Promise<unknown>;
|
|
23
|
+
processLlmRequest(request: ToolProcessLlmRequest): Promise<void>;
|
|
24
|
+
private appendResourcesToLlmRequest;
|
|
25
|
+
private mcpContentToPart;
|
|
26
|
+
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { BlobResourceContents, Resource, TextResourceContents } from '@modelcontextprotocol/sdk/types.js';
|
|
6
7
|
import { ReadonlyContext } from '../../agents/readonly_context.js';
|
|
7
8
|
import { BaseTool } from '../base_tool.js';
|
|
8
9
|
import { BaseToolset, ToolPredicate } from '../base_toolset.js';
|
|
@@ -40,5 +41,31 @@ export declare class MCPToolset extends BaseToolset {
|
|
|
40
41
|
private readonly mcpSessionManager;
|
|
41
42
|
constructor(connectionParams: MCPConnectionParams, toolFilter?: ToolPredicate | string[], prefix?: string);
|
|
42
43
|
getTools(context?: ReadonlyContext): Promise<BaseTool[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Lists the names of the resources advertised by the MCP server.
|
|
46
|
+
*
|
|
47
|
+
* @return The resource names available on the server.
|
|
48
|
+
*/
|
|
49
|
+
listResources(): Promise<string[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Returns metadata for the resource whose name matches `name`.
|
|
52
|
+
*
|
|
53
|
+
* @param name The advertised name of the resource.
|
|
54
|
+
* @return The matching MCP `Resource`.
|
|
55
|
+
* @throws If no resource with the given name is advertised by the server.
|
|
56
|
+
*/
|
|
57
|
+
getResourceInfo(name: string): Promise<Resource>;
|
|
58
|
+
/**
|
|
59
|
+
* Reads the contents of the named resource from the MCP server.
|
|
60
|
+
*
|
|
61
|
+
* The resource name is resolved to a URI via {@link getResourceInfo} before
|
|
62
|
+
* reading. Binary contents are returned base64-encoded, exactly as provided
|
|
63
|
+
* by the server (never decoded and re-encoded).
|
|
64
|
+
*
|
|
65
|
+
* @param name The advertised name of the resource to read.
|
|
66
|
+
* @return The resource contents (text and/or base64-encoded binary).
|
|
67
|
+
* @throws If the resource is unknown or has no URI.
|
|
68
|
+
*/
|
|
69
|
+
readResource(name: string): Promise<Array<TextResourceContents | BlobResourceContents>>;
|
|
43
70
|
close(): Promise<void>;
|
|
44
71
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { LongRunningFunctionTool } from './long_running_tool.js';
|
|
8
|
+
/**
|
|
9
|
+
* A long-running tool that presents a custom message to the user and awaits
|
|
10
|
+
* unstructured or structured input.
|
|
11
|
+
*/
|
|
12
|
+
export declare const requestInputTool: LongRunningFunctionTool<z.ZodObject<{
|
|
13
|
+
message: z.ZodString;
|
|
14
|
+
responseSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
15
|
+
}, z.core.$strip>>;
|
|
@@ -6,9 +6,34 @@
|
|
|
6
6
|
import { FunctionDeclaration } from '@google/genai';
|
|
7
7
|
import { BaseTool, RunAsyncToolRequest } from '../base_tool.js';
|
|
8
8
|
import { SkillToolset } from './skill_toolset.js';
|
|
9
|
+
/**
|
|
10
|
+
* Error codes returned by {@link RunSkillInlineScriptTool} when a call cannot
|
|
11
|
+
* be completed. The string values are part of the tool's response contract and
|
|
12
|
+
* must remain stable.
|
|
13
|
+
*/
|
|
14
|
+
export declare enum RunSkillInlineScriptErrorCode {
|
|
15
|
+
MISSING_SCRIPT_CONTENT = "MISSING_SCRIPT_CONTENT",
|
|
16
|
+
MISSING_LANGUAGE = "MISSING_LANGUAGE",
|
|
17
|
+
NO_CODE_EXECUTOR = "NO_CODE_EXECUTOR",
|
|
18
|
+
EXECUTION_ERROR = "EXECUTION_ERROR",
|
|
19
|
+
CONFIRMATION_REJECTED = "CONFIRMATION_REJECTED"
|
|
20
|
+
}
|
|
9
21
|
export declare class RunSkillInlineScriptTool extends BaseTool {
|
|
10
22
|
private toolset;
|
|
11
23
|
constructor(toolset: SkillToolset);
|
|
12
24
|
_getDeclaration(): FunctionDeclaration;
|
|
13
25
|
runAsync({ args, toolContext, }: RunAsyncToolRequest): Promise<unknown>;
|
|
26
|
+
/**
|
|
27
|
+
* Enforces a human-in-the-loop confirmation gate before executing an inline
|
|
28
|
+
* script, using the repo's standard tool-confirmation mechanism.
|
|
29
|
+
*
|
|
30
|
+
* - When no confirmation has been provided yet, a confirmation is requested
|
|
31
|
+
* (surfacing the language and script that would run) and an intermediate
|
|
32
|
+
* result is returned so the tool call pauses until the client responds.
|
|
33
|
+
* - When a confirmation exists but was not confirmed, a rejection error is
|
|
34
|
+
* returned and execution is refused.
|
|
35
|
+
* - When the confirmation is confirmed, `undefined` is returned to allow the
|
|
36
|
+
* caller to proceed with execution.
|
|
37
|
+
*/
|
|
38
|
+
private enforceConfirmation;
|
|
14
39
|
}
|
|
@@ -23,6 +23,15 @@ export declare class SkillToolset extends BaseToolset {
|
|
|
23
23
|
codeExecutor?: BaseCodeExecutor;
|
|
24
24
|
additionalTools?: Array<BaseTool | BaseToolset>;
|
|
25
25
|
registry?: SkillRegistry;
|
|
26
|
+
/**
|
|
27
|
+
* Whether to expose the `run_skill_inline_script` tool, which executes
|
|
28
|
+
* model-provided script content in the configured code executor. This is
|
|
29
|
+
* disabled by default because arbitrary inline-script execution is a
|
|
30
|
+
* sensitive capability; opt in explicitly by setting this to `true`.
|
|
31
|
+
* Execution additionally remains gated behind a human-in-the-loop
|
|
32
|
+
* confirmation.
|
|
33
|
+
*/
|
|
34
|
+
allowInlineScripts?: boolean;
|
|
26
35
|
});
|
|
27
36
|
getTools(context?: ReadonlyContext): Promise<BaseTool[]>;
|
|
28
37
|
close(): Promise<void>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Checks whether targetBranch is equal to or an ancestor of currentBranch
|
|
8
|
+
* by verifying segment-by-segment matching without substring false positives.
|
|
9
|
+
*
|
|
10
|
+
* @param currentBranch The branch being evaluated.
|
|
11
|
+
* @param targetBranch The candidate prefix or ancestor branch.
|
|
12
|
+
* @returns true if targetBranch equals currentBranch or is an ancestor of currentBranch.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isSegmentPrefix(currentBranch: string, targetBranch: string): boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Browser stand-in for the `node:crypto` builtin, wired up by the alias in
|
|
8
|
+
* `build.js` so that the Node fallback in `env_aware_utils.ts` does not pull a
|
|
9
|
+
* Node builtin into the web bundle.
|
|
10
|
+
*
|
|
11
|
+
* `randomUUID` is reached here only after both `globalThis.crypto` branches in
|
|
12
|
+
* `env_aware_utils.ts` have been ruled out. In a browser that means the Web
|
|
13
|
+
* Crypto API is genuinely absent, so there is no secure source left to fall
|
|
14
|
+
* back to and the only correct move is to fail rather than degrade.
|
|
15
|
+
*/
|
|
16
|
+
export declare function randomUUID(): string;
|
|
@@ -7,6 +7,29 @@
|
|
|
7
7
|
* Returns true if the environment is a browser.
|
|
8
8
|
*/
|
|
9
9
|
export declare function isBrowser(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Generates a random UUID from a cryptographically secure source.
|
|
12
|
+
*
|
|
13
|
+
* `crypto.randomUUID()` is only exposed in secure contexts, so it is absent on
|
|
14
|
+
* plain-HTTP origins even though `crypto` itself is present.
|
|
15
|
+
* `crypto.getRandomValues()` carries no such restriction, so it is used as the
|
|
16
|
+
* fallback rather than `Math.random()`.
|
|
17
|
+
*
|
|
18
|
+
* In Node the `globalThis.crypto` global was added in v17.4.0 and stayed behind
|
|
19
|
+
* `--experimental-global-webcrypto` until v19.0.0, so neither of those branches
|
|
20
|
+
* matches on a default Node 18 or earlier. `node:crypto` carries no such gate —
|
|
21
|
+
* its `randomUUID` has existed since v14.17.0 — so it is the last resort. In
|
|
22
|
+
* the bundled web build the import is aliased to `crypto_shim.ts`, which
|
|
23
|
+
* throws, because a browser without the Web Crypto API has no secure source
|
|
24
|
+
* left. The non-bundle `dist/web` output that `package.json#browser` points
|
|
25
|
+
* at keeps the import verbatim, as it already does for `node:async_hooks`
|
|
26
|
+
* and `node:path`.
|
|
27
|
+
*
|
|
28
|
+
* Some callers use this value to make security decisions — the OAuth2 `state`
|
|
29
|
+
* parameter in `AuthHandler` and the session identifiers minted by the session
|
|
30
|
+
* services — so this function must not silently degrade to a non-cryptographic
|
|
31
|
+
* generator.
|
|
32
|
+
*/
|
|
10
33
|
export declare function randomUUID(): string;
|
|
11
34
|
/**
|
|
12
35
|
* Encodes the given string or Uint8Array to base64.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Formats an arbitrary thrown value into a readable, root-cause message.
|
|
8
|
+
*
|
|
9
|
+
* Recursively flattens `AggregateError.errors` (joining leaves with ` | `) and
|
|
10
|
+
* unwraps the `Error.cause` chain, and — when HTTP details are synchronously
|
|
11
|
+
* available — appends the status code and a response-body snippet truncated to
|
|
12
|
+
* 1000 characters with a `... [truncated]` marker. It never throws and is safe
|
|
13
|
+
* on `null`/`undefined` and cyclic error graphs.
|
|
14
|
+
*
|
|
15
|
+
* @param err The thrown or rejected value to format.
|
|
16
|
+
* @return A single human-readable message describing the root cause(s).
|
|
17
|
+
*/
|
|
18
|
+
export declare function formatError(err: unknown): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Returns whether the model can natively accept an output schema at the same
|
|
8
|
+
* time as tools, which is strictly more reliable than the prompt-based
|
|
9
|
+
* `set_model_response` workaround.
|
|
10
|
+
*
|
|
11
|
+
* Early Access Program model names encode no numeric version, so
|
|
12
|
+
* `isGemini2OrAbove` rejects them even on Vertex AI. The Python
|
|
13
|
+
* implementation accepts them; that gap lives in the shared predicate.
|
|
14
|
+
*
|
|
15
|
+
* @param modelString A simple or path-based model name.
|
|
16
|
+
* @return True if the model supports an output schema alongside tools.
|
|
17
|
+
*/
|
|
18
|
+
export declare function canUseOutputSchemaWithTools(modelString: string): boolean;
|
package/dist/types/version.d.ts
CHANGED
|
@@ -127,7 +127,12 @@ class RemoteA2AAgent extends BaseAgent {
|
|
|
127
127
|
yield new __await(callback(context, chunk));
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
const adkEvent = toAdkEvent(
|
|
130
|
+
const adkEvent = toAdkEvent(
|
|
131
|
+
chunk,
|
|
132
|
+
context.invocationId,
|
|
133
|
+
this.name,
|
|
134
|
+
context.branch
|
|
135
|
+
);
|
|
131
136
|
if (!adkEvent) {
|
|
132
137
|
continue;
|
|
133
138
|
}
|
|
@@ -158,7 +163,12 @@ class RemoteA2AAgent extends BaseAgent {
|
|
|
158
163
|
yield new __await(callback(context, result));
|
|
159
164
|
}
|
|
160
165
|
}
|
|
161
|
-
const adkEvent = toAdkEvent(
|
|
166
|
+
const adkEvent = toAdkEvent(
|
|
167
|
+
result,
|
|
168
|
+
context.invocationId,
|
|
169
|
+
this.name,
|
|
170
|
+
context.branch
|
|
171
|
+
);
|
|
162
172
|
if (adkEvent) {
|
|
163
173
|
processor.updateCustomMetadata(adkEvent, result);
|
|
164
174
|
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
|
"".concat(basePath, "/rest"),
|
|
66
81
|
restHandler({
|
|
67
82
|
requestHandler,
|
|
68
|
-
userBuilder
|
|
83
|
+
userBuilder
|
|
69
84
|
})
|
|
70
85
|
);
|
|
71
86
|
app.use(
|
|
72
87
|
"".concat(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
|
+
};
|