@google/adk 1.3.0 → 1.5.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/agent_to_a2a.js +18 -2
- package/dist/cjs/a2a/event_converter_utils.js +8 -4
- package/dist/cjs/a2a/metadata_converter_utils.js +1 -1
- package/dist/cjs/agents/active_streaming_tool.js +6 -1
- package/dist/cjs/agents/base_agent.js +39 -0
- package/dist/cjs/agents/context.js +1 -11
- package/dist/cjs/agents/functions.js +39 -35
- package/dist/cjs/agents/instructions.js +23 -5
- package/dist/cjs/agents/invocation_context.js +2 -5
- package/dist/cjs/agents/llm_agent.js +10 -7
- package/dist/cjs/agents/loop_agent.js +15 -3
- package/dist/cjs/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/cjs/agents/processors/content_processor_utils.js +18 -4
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +4 -2
- package/dist/cjs/agents/processors/interactions_request_processor.js +63 -0
- package/dist/cjs/agents/routed_agent.js +31 -0
- package/dist/cjs/agents/run_config.js +3 -2
- package/dist/cjs/apps/app.js +79 -0
- package/dist/cjs/apps/resumability_config.js +44 -0
- package/dist/cjs/artifacts/file_artifact_service.js +14 -1
- package/dist/cjs/artifacts/gcs_artifact_service.js +57 -15
- package/dist/cjs/artifacts/in_memory_artifact_service.js +12 -1
- package/dist/cjs/artifacts/scoped_artifact_service.js +101 -0
- package/dist/cjs/artifacts/session_artifact_service.js +27 -0
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +17 -5
- package/dist/cjs/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/cjs/common.js +76 -0
- package/dist/cjs/context/agent_controlled_context_compactor.js +109 -0
- package/dist/cjs/context/anchored_context_compactor.js +127 -0
- package/dist/cjs/context/compaction_utils.js +52 -0
- package/dist/cjs/context/token_based_context_compactor.js +52 -33
- package/dist/cjs/context/trajectory_thought_pruning_compactor.js +71 -0
- package/dist/cjs/events/compacted_event.js +9 -3
- package/dist/cjs/events/event.js +52 -0
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/cjs/models/google_llm.js +25 -10
- package/dist/cjs/models/interactions_utils.js +732 -0
- package/dist/cjs/plugins/base_plugin.js +1 -0
- package/dist/cjs/plugins/global_instruction_plugin.js +97 -0
- package/dist/cjs/runner/in_memory_runner.js +13 -2
- package/dist/cjs/runner/runner.js +143 -83
- package/dist/cjs/sessions/base_session_service.js +6 -1
- package/dist/cjs/sessions/database_session_service.js +24 -7
- package/dist/cjs/sessions/vertex_ai_session_service.js +19 -4
- package/dist/cjs/skills/loader.js +2 -2
- package/dist/cjs/tools/base_toolset.js +1 -1
- package/dist/cjs/tools/consolidate_context_tool.js +79 -0
- package/dist/cjs/tools/enterprise_web_search_tool.js +81 -0
- package/dist/cjs/tools/example_tool.js +68 -0
- package/dist/cjs/tools/forwarding_artifact_service.js +16 -28
- 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_toolset.js +63 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
- 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/async_hooks_shim.js +52 -0
- package/dist/cjs/utils/branch_trie.js +41 -0
- package/dist/cjs/utils/client_labels.js +41 -3
- package/dist/cjs/utils/env_aware_utils.js +10 -1
- package/dist/cjs/utils/streaming_utils.js +15 -9
- package/dist/cjs/utils/task.js +62 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/agent_to_a2a.js +18 -2
- package/dist/esm/a2a/event_converter_utils.js +8 -4
- package/dist/esm/a2a/metadata_converter_utils.js +1 -1
- package/dist/esm/agents/active_streaming_tool.js +6 -1
- package/dist/esm/agents/base_agent.js +39 -0
- package/dist/esm/agents/context.js +1 -11
- package/dist/esm/agents/functions.js +43 -32
- package/dist/esm/agents/instructions.js +23 -5
- package/dist/esm/agents/invocation_context.js +2 -5
- package/dist/esm/agents/llm_agent.js +12 -9
- package/dist/esm/agents/loop_agent.js +15 -3
- package/dist/esm/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/esm/agents/processors/content_processor_utils.js +16 -3
- package/dist/esm/agents/processors/context_compactor_request_processor.js +4 -2
- package/dist/esm/agents/processors/interactions_request_processor.js +34 -0
- package/dist/esm/agents/routed_agent.js +31 -0
- package/dist/esm/agents/run_config.js +3 -2
- package/dist/esm/apps/app.js +49 -0
- package/dist/esm/apps/resumability_config.js +16 -0
- package/dist/esm/artifacts/file_artifact_service.js +14 -1
- package/dist/esm/artifacts/gcs_artifact_service.js +57 -15
- package/dist/esm/artifacts/in_memory_artifact_service.js +12 -1
- package/dist/esm/artifacts/scoped_artifact_service.js +73 -0
- package/dist/esm/artifacts/session_artifact_service.js +7 -0
- package/dist/esm/auth/oauth2/oauth2_discovery.js +14 -4
- package/dist/esm/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/esm/common.js +67 -3
- package/dist/esm/context/agent_controlled_context_compactor.js +81 -0
- package/dist/esm/context/anchored_context_compactor.js +99 -0
- package/dist/esm/context/compaction_utils.js +27 -0
- package/dist/esm/context/token_based_context_compactor.js +52 -33
- package/dist/esm/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/esm/events/compacted_event.js +7 -2
- package/dist/esm/events/event.js +46 -0
- package/dist/esm/index.js +6 -1
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/esm/models/google_llm.js +23 -9
- package/dist/esm/models/interactions_utils.js +697 -0
- package/dist/esm/plugins/base_plugin.js +1 -0
- package/dist/esm/plugins/global_instruction_plugin.js +69 -0
- package/dist/esm/runner/in_memory_runner.js +13 -2
- package/dist/esm/runner/runner.js +141 -84
- package/dist/esm/sessions/base_session_service.js +6 -1
- package/dist/esm/sessions/database_session_service.js +24 -7
- package/dist/esm/sessions/vertex_ai_session_service.js +17 -3
- package/dist/esm/skills/loader.js +2 -2
- package/dist/esm/tools/base_toolset.js +1 -1
- package/dist/esm/tools/consolidate_context_tool.js +51 -0
- package/dist/esm/tools/enterprise_web_search_tool.js +55 -0
- package/dist/esm/tools/example_tool.js +42 -0
- package/dist/esm/tools/forwarding_artifact_service.js +16 -28
- 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_toolset.js +63 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
- 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/async_hooks_shim.js +24 -0
- package/dist/esm/utils/branch_trie.js +13 -0
- package/dist/esm/utils/client_labels.js +38 -2
- package/dist/esm/utils/env_aware_utils.js +10 -1
- package/dist/esm/utils/streaming_utils.js +11 -5
- package/dist/esm/utils/task.js +34 -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/agents/active_streaming_tool.d.ts +3 -4
- package/dist/types/agents/base_agent.d.ts +29 -1
- package/dist/types/agents/functions.d.ts +12 -17
- package/dist/types/agents/invocation_context.d.ts +7 -3
- package/dist/types/agents/llm_agent.d.ts +5 -1
- package/dist/types/agents/loop_agent.d.ts +2 -2
- package/dist/types/agents/processors/content_processor_utils.d.ts +8 -0
- package/dist/types/agents/processors/interactions_request_processor.d.ts +17 -0
- package/dist/types/agents/routed_agent.d.ts +24 -1
- package/dist/types/agents/run_config.d.ts +1 -1
- package/dist/types/apps/app.d.ts +52 -0
- package/dist/types/apps/resumability_config.d.ts +27 -0
- package/dist/types/artifacts/base_artifact_service.d.ts +6 -36
- package/dist/types/artifacts/gcs_artifact_service.d.ts +2 -1
- package/dist/types/artifacts/scoped_artifact_service.d.ts +25 -0
- package/dist/types/artifacts/session_artifact_service.d.ts +25 -0
- package/dist/types/auth/oauth2/oauth2_discovery.d.ts +11 -0
- package/dist/types/common.d.ts +29 -5
- package/dist/types/context/agent_controlled_context_compactor.d.ts +24 -0
- package/dist/types/context/anchored_context_compactor.d.ts +35 -0
- package/dist/types/context/base_context_compactor.d.ts +3 -0
- package/dist/types/context/compaction_utils.d.ts +15 -0
- package/dist/types/context/token_based_context_compactor.d.ts +6 -1
- package/dist/types/context/trajectory_thought_pruning_compactor.d.ts +27 -0
- package/dist/types/events/compacted_event.d.ts +10 -0
- package/dist/types/events/event.d.ts +21 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/models/google_llm.d.ts +15 -1
- package/dist/types/models/interactions_utils.d.ts +92 -0
- package/dist/types/models/llm_request.d.ts +4 -0
- package/dist/types/models/llm_response.d.ts +4 -0
- package/dist/types/plugins/base_plugin.d.ts +2 -1
- package/dist/types/plugins/global_instruction_plugin.d.ts +38 -0
- package/dist/types/runner/in_memory_runner.d.ts +7 -1
- package/dist/types/runner/runner.d.ts +44 -10
- package/dist/types/sessions/base_session_service.d.ts +3 -16
- package/dist/types/sessions/session.d.ts +11 -0
- package/dist/types/sessions/vertex_ai_session_service.d.ts +9 -1
- package/dist/types/tools/consolidate_context_tool.d.ts +19 -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/forwarding_artifact_service.d.ts +3 -2
- 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/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/async_hooks_shim.d.ts +10 -0
- package/dist/types/utils/branch_trie.d.ts +14 -0
- package/dist/types/utils/client_labels.d.ts +10 -0
- package/dist/types/utils/env_aware_utils.d.ts +3 -3
- package/dist/types/utils/task.d.ts +24 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/agent_to_a2a.js +18 -2
- package/dist/web/a2a/event_converter_utils.js +8 -4
- package/dist/web/a2a/metadata_converter_utils.js +1 -1
- package/dist/web/agents/active_streaming_tool.js +6 -1
- package/dist/web/agents/base_agent.js +39 -0
- package/dist/web/agents/context.js +1 -11
- package/dist/web/agents/functions.js +43 -32
- package/dist/web/agents/instructions.js +23 -5
- package/dist/web/agents/invocation_context.js +2 -5
- package/dist/web/agents/llm_agent.js +12 -9
- package/dist/web/agents/loop_agent.js +27 -3
- package/dist/web/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/web/agents/processors/content_processor_utils.js +16 -3
- package/dist/web/agents/processors/context_compactor_request_processor.js +4 -2
- package/dist/web/agents/processors/interactions_request_processor.js +52 -0
- package/dist/web/agents/routed_agent.js +31 -0
- package/dist/web/agents/run_config.js +8 -3
- package/dist/web/apps/app.js +49 -0
- package/dist/web/apps/resumability_config.js +31 -0
- package/dist/web/artifacts/file_artifact_service.js +14 -1
- package/dist/web/artifacts/gcs_artifact_service.js +55 -15
- package/dist/web/artifacts/in_memory_artifact_service.js +12 -1
- package/dist/web/artifacts/scoped_artifact_service.js +86 -0
- package/dist/web/artifacts/session_artifact_service.js +7 -0
- package/dist/web/auth/oauth2/oauth2_discovery.js +14 -4
- package/dist/web/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/web/common.js +67 -3
- package/dist/web/context/agent_controlled_context_compactor.js +81 -0
- package/dist/web/context/anchored_context_compactor.js +117 -0
- package/dist/web/context/compaction_utils.js +27 -0
- package/dist/web/context/token_based_context_compactor.js +52 -33
- package/dist/web/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/web/events/compacted_event.js +7 -2
- package/dist/web/events/event.js +44 -0
- package/dist/web/index.js +6 -1
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/web/models/google_llm.js +54 -9
- package/dist/web/models/interactions_utils.js +728 -0
- package/dist/web/plugins/base_plugin.js +1 -0
- package/dist/web/plugins/global_instruction_plugin.js +67 -0
- package/dist/web/runner/in_memory_runner.js +13 -2
- package/dist/web/runner/runner.js +157 -84
- package/dist/web/sessions/base_session_service.js +6 -1
- package/dist/web/sessions/database_session_service.js +24 -7
- package/dist/web/sessions/vertex_ai_session_service.js +17 -3
- package/dist/web/skills/loader.js +2 -2
- package/dist/web/tools/base_toolset.js +1 -1
- package/dist/web/tools/consolidate_context_tool.js +51 -0
- package/dist/web/tools/enterprise_web_search_tool.js +55 -0
- package/dist/web/tools/example_tool.js +42 -0
- package/dist/web/tools/forwarding_artifact_service.js +16 -28
- 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_toolset.js +63 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
- 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/async_hooks_shim.js +24 -0
- package/dist/web/utils/branch_trie.js +13 -0
- package/dist/web/utils/client_labels.js +38 -2
- package/dist/web/utils/env_aware_utils.js +10 -1
- package/dist/web/utils/streaming_utils.js +11 -5
- package/dist/web/utils/task.js +34 -0
- package/dist/web/version.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,79 @@
|
|
|
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 consolidate_context_tool_exports = {};
|
|
26
|
+
__export(consolidate_context_tool_exports, {
|
|
27
|
+
ConsolidateContextTool: () => ConsolidateContextTool
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(consolidate_context_tool_exports);
|
|
30
|
+
var import_genai = require("@google/genai");
|
|
31
|
+
var import_base_tool = require("./base_tool.js");
|
|
32
|
+
/**
|
|
33
|
+
* @license
|
|
34
|
+
* Copyright 2026 Google LLC
|
|
35
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
36
|
+
*/
|
|
37
|
+
class ConsolidateContextTool extends import_base_tool.BaseTool {
|
|
38
|
+
constructor() {
|
|
39
|
+
super({
|
|
40
|
+
name: "consolidate_context",
|
|
41
|
+
description: "Requests context consolidation (compaction) to manage history size. Use this when a subtask is complete and you want to summarize progress and clear detailed history."
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
_getDeclaration() {
|
|
45
|
+
return {
|
|
46
|
+
name: this.name,
|
|
47
|
+
description: this.description,
|
|
48
|
+
parameters: {
|
|
49
|
+
type: import_genai.Type.OBJECT,
|
|
50
|
+
properties: {
|
|
51
|
+
detail: {
|
|
52
|
+
type: import_genai.Type.STRING,
|
|
53
|
+
description: "Optional description of what has been accomplished so far. This detail will be used to guide the summarization of the history."
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async runAsync({
|
|
60
|
+
args,
|
|
61
|
+
toolContext
|
|
62
|
+
}) {
|
|
63
|
+
toolContext.state.set("temp:consolidate_context", true);
|
|
64
|
+
if (args["detail"] !== void 0) {
|
|
65
|
+
toolContext.state.set(
|
|
66
|
+
"temp:consolidate_context_detail",
|
|
67
|
+
args["detail"]
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
status: "success",
|
|
72
|
+
message: "Context consolidation requested."
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
ConsolidateContextTool
|
|
79
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
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 enterprise_web_search_tool_exports = {};
|
|
26
|
+
__export(enterprise_web_search_tool_exports, {
|
|
27
|
+
ENTERPRISE_WEB_SEARCH: () => ENTERPRISE_WEB_SEARCH,
|
|
28
|
+
EnterpriseWebSearchTool: () => EnterpriseWebSearchTool,
|
|
29
|
+
applyEnterpriseWebSearch: () => applyEnterpriseWebSearch
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(enterprise_web_search_tool_exports);
|
|
32
|
+
var import_model_name = require("../utils/model_name.js");
|
|
33
|
+
var import_base_tool = require("./base_tool.js");
|
|
34
|
+
/**
|
|
35
|
+
* @license
|
|
36
|
+
* Copyright 2026 Google LLC
|
|
37
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
38
|
+
*/
|
|
39
|
+
function applyEnterpriseWebSearch(llmRequest) {
|
|
40
|
+
if (!llmRequest.model) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const modelCheckDisabled = (0, import_model_name.isGeminiModelIdCheckDisabled)();
|
|
44
|
+
llmRequest.config = llmRequest.config || {};
|
|
45
|
+
llmRequest.config.tools = llmRequest.config.tools || [];
|
|
46
|
+
if ((0, import_model_name.isGeminiModel)(llmRequest.model) || modelCheckDisabled) {
|
|
47
|
+
if ((0, import_model_name.isGemini1Model)(llmRequest.model) && llmRequest.config.tools.length > 0) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
"Enterprise Web Search tool cannot be used with other tools in Gemini 1.x."
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
llmRequest.config.tools.push({ enterpriseWebSearch: {} });
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
throw new Error(
|
|
56
|
+
`Enterprise Web Search tool is not supported for model ${llmRequest.model}`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
class EnterpriseWebSearchTool extends import_base_tool.BaseTool {
|
|
60
|
+
constructor() {
|
|
61
|
+
super({
|
|
62
|
+
name: "enterprise_web_search",
|
|
63
|
+
description: "Enterprise Web Search Tool"
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
runAsync() {
|
|
67
|
+
return Promise.resolve();
|
|
68
|
+
}
|
|
69
|
+
async processLlmRequest({
|
|
70
|
+
llmRequest
|
|
71
|
+
}) {
|
|
72
|
+
applyEnterpriseWebSearch(llmRequest);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const ENTERPRISE_WEB_SEARCH = new EnterpriseWebSearchTool();
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
ENTERPRISE_WEB_SEARCH,
|
|
79
|
+
EnterpriseWebSearchTool,
|
|
80
|
+
applyEnterpriseWebSearch
|
|
81
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
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 example_tool_exports = {};
|
|
26
|
+
__export(example_tool_exports, {
|
|
27
|
+
ExampleTool: () => ExampleTool
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(example_tool_exports);
|
|
30
|
+
var import_example_util = require("../examples/example_util.js");
|
|
31
|
+
var import_llm_request = require("../models/llm_request.js");
|
|
32
|
+
var import_base_tool = require("./base_tool.js");
|
|
33
|
+
/**
|
|
34
|
+
* @license
|
|
35
|
+
* Copyright 2026 Google LLC
|
|
36
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
37
|
+
*/
|
|
38
|
+
class ExampleTool extends import_base_tool.BaseTool {
|
|
39
|
+
constructor(examples) {
|
|
40
|
+
super({
|
|
41
|
+
// Name and description are not used because this tool only changes
|
|
42
|
+
// llmRequest.
|
|
43
|
+
name: "example_tool",
|
|
44
|
+
description: "example tool"
|
|
45
|
+
});
|
|
46
|
+
this.examples = examples;
|
|
47
|
+
}
|
|
48
|
+
async runAsync(_request) {
|
|
49
|
+
throw new Error("ExampleTool should not be called by model");
|
|
50
|
+
}
|
|
51
|
+
async processLlmRequest({
|
|
52
|
+
toolContext,
|
|
53
|
+
llmRequest
|
|
54
|
+
}) {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
const parts = (_a = toolContext.userContent) == null ? void 0 : _a.parts;
|
|
57
|
+
if (!parts || !((_b = parts[0]) == null ? void 0 : _b.text)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
(0, import_llm_request.appendInstructions)(llmRequest, [
|
|
61
|
+
(0, import_example_util.buildExampleSi)(this.examples, parts[0].text, llmRequest.model)
|
|
62
|
+
]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
ExampleTool
|
|
68
|
+
});
|
|
@@ -37,48 +37,36 @@ class ForwardingArtifactService {
|
|
|
37
37
|
this.toolContext = toolContext;
|
|
38
38
|
this.invocationContext = toolContext.invocationContext;
|
|
39
39
|
}
|
|
40
|
-
// TODO - b/425992518: Remove unnecessary parameters. We should rethink the
|
|
41
|
-
// abstraction layer to make it more clear.
|
|
42
40
|
async saveArtifact(request) {
|
|
43
41
|
return this.toolContext.saveArtifact(request.filename, request.artifact);
|
|
44
42
|
}
|
|
45
43
|
async loadArtifact(request) {
|
|
46
44
|
return this.toolContext.loadArtifact(request.filename, request.version);
|
|
47
45
|
}
|
|
48
|
-
async listArtifactKeys() {
|
|
46
|
+
async listArtifactKeys(_request) {
|
|
49
47
|
return this.toolContext.listArtifacts();
|
|
50
48
|
}
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
getArtifactService() {
|
|
50
|
+
const service = this.invocationContext.artifactService;
|
|
51
|
+
if (!service) {
|
|
53
52
|
throw new Error("Artifact service is not initialized.");
|
|
54
53
|
}
|
|
55
|
-
return
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
return service;
|
|
55
|
+
}
|
|
56
|
+
async deleteArtifact(request) {
|
|
57
|
+
return this.getArtifactService().deleteArtifact(request.filename);
|
|
58
58
|
}
|
|
59
59
|
async listVersions(request) {
|
|
60
|
-
|
|
61
|
-
throw new Error("Artifact service is not initialized.");
|
|
62
|
-
}
|
|
63
|
-
return this.toolContext.invocationContext.artifactService.listVersions(
|
|
64
|
-
request
|
|
65
|
-
);
|
|
60
|
+
return this.getArtifactService().listVersions(request.filename);
|
|
66
61
|
}
|
|
67
|
-
listArtifactVersions(request) {
|
|
68
|
-
|
|
69
|
-
throw new Error("Artifact service is not initialized.");
|
|
70
|
-
}
|
|
71
|
-
return this.toolContext.invocationContext.artifactService.listArtifactVersions(
|
|
72
|
-
request
|
|
73
|
-
);
|
|
62
|
+
async listArtifactVersions(request) {
|
|
63
|
+
return this.getArtifactService().listArtifactVersions(request.filename);
|
|
74
64
|
}
|
|
75
|
-
getArtifactVersion(request) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
request
|
|
81
|
-
);
|
|
65
|
+
async getArtifactVersion(request) {
|
|
66
|
+
return this.getArtifactService().getArtifactVersion({
|
|
67
|
+
filename: request.filename,
|
|
68
|
+
version: request.version
|
|
69
|
+
});
|
|
82
70
|
}
|
|
83
71
|
}
|
|
84
72
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -0,0 +1,250 @@
|
|
|
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 load_web_page_exports = {};
|
|
26
|
+
__export(load_web_page_exports, {
|
|
27
|
+
LOAD_WEB_PAGE: () => LOAD_WEB_PAGE,
|
|
28
|
+
loadWebPage: () => loadWebPage
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(load_web_page_exports);
|
|
31
|
+
var import_promises = require("node:dns/promises");
|
|
32
|
+
var import_node_net = require("node:net");
|
|
33
|
+
var import_zod = require("zod");
|
|
34
|
+
var import_function_tool = require("./function_tool.js");
|
|
35
|
+
/**
|
|
36
|
+
* @license
|
|
37
|
+
* Copyright 2026 Google LLC
|
|
38
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
39
|
+
*/
|
|
40
|
+
const ALLOWED_SCHEMES = /* @__PURE__ */ new Set(["http:", "https:"]);
|
|
41
|
+
const DEFAULT_TIMEOUT_MS = 3e4;
|
|
42
|
+
const BLOCKED_IPV4_CIDRS = [
|
|
43
|
+
"0.0.0.0/8",
|
|
44
|
+
// "this host on this network"
|
|
45
|
+
"10.0.0.0/8",
|
|
46
|
+
// private
|
|
47
|
+
"100.64.0.0/10",
|
|
48
|
+
// shared address space / CGNAT
|
|
49
|
+
"127.0.0.0/8",
|
|
50
|
+
// loopback
|
|
51
|
+
"169.254.0.0/16",
|
|
52
|
+
// link-local (includes GCP metadata 169.254.169.254)
|
|
53
|
+
"172.16.0.0/12",
|
|
54
|
+
// private
|
|
55
|
+
"192.0.0.0/24",
|
|
56
|
+
// IETF protocol assignments
|
|
57
|
+
"192.0.2.0/24",
|
|
58
|
+
// TEST-NET-1 (documentation)
|
|
59
|
+
"192.88.99.0/24",
|
|
60
|
+
// 6to4 relay anycast (deprecated)
|
|
61
|
+
"192.168.0.0/16",
|
|
62
|
+
// private
|
|
63
|
+
"198.18.0.0/15",
|
|
64
|
+
// benchmarking
|
|
65
|
+
"198.51.100.0/24",
|
|
66
|
+
// TEST-NET-2 (documentation)
|
|
67
|
+
"203.0.113.0/24",
|
|
68
|
+
// TEST-NET-3 (documentation)
|
|
69
|
+
"224.0.0.0/4",
|
|
70
|
+
// multicast
|
|
71
|
+
"240.0.0.0/4"
|
|
72
|
+
// reserved / future use (includes 255.255.255.255)
|
|
73
|
+
].map(parseIpv4Cidr);
|
|
74
|
+
const BLOCKED_IPV6_CIDRS = [
|
|
75
|
+
"::/128",
|
|
76
|
+
// unspecified
|
|
77
|
+
"::1/128",
|
|
78
|
+
// loopback
|
|
79
|
+
"64:ff9b:1::/48",
|
|
80
|
+
// local NAT64
|
|
81
|
+
"100::/64",
|
|
82
|
+
// discard-only
|
|
83
|
+
"2001:db8::/32",
|
|
84
|
+
// documentation
|
|
85
|
+
"fc00::/7",
|
|
86
|
+
// unique-local (ULA, private)
|
|
87
|
+
"fe80::/10",
|
|
88
|
+
// link-local
|
|
89
|
+
"ff00::/8"
|
|
90
|
+
// multicast
|
|
91
|
+
].map(parseIpv6Cidr);
|
|
92
|
+
function failedToFetchMessage(url) {
|
|
93
|
+
return `Failed to fetch url: ${url}`;
|
|
94
|
+
}
|
|
95
|
+
function isBlockedHostname(hostname) {
|
|
96
|
+
const normalized = hostname.replace(/\.+$/, "").toLowerCase();
|
|
97
|
+
return normalized === "localhost" || normalized.endsWith(".localhost");
|
|
98
|
+
}
|
|
99
|
+
function normalizeHost(hostname) {
|
|
100
|
+
return hostname.startsWith("[") ? hostname.slice(1, -1) : hostname;
|
|
101
|
+
}
|
|
102
|
+
function parseIpv4(address) {
|
|
103
|
+
const match = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(address);
|
|
104
|
+
if (!match) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
const octets = match.slice(1).map(Number);
|
|
108
|
+
if (octets.some((octet) => octet > 255)) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
return octets;
|
|
112
|
+
}
|
|
113
|
+
function parseIpv6(address) {
|
|
114
|
+
if ((0, import_node_net.isIP)(address) !== 6) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
const [head, tail] = address.split("::");
|
|
118
|
+
const highGroups = head ? expandHextets(head) : [];
|
|
119
|
+
const lowGroups = tail ? expandHextets(tail) : [];
|
|
120
|
+
const compressed = address.includes("::") ? new Array(8 - highGroups.length - lowGroups.length).fill(0) : [];
|
|
121
|
+
return [...highGroups, ...compressed, ...lowGroups];
|
|
122
|
+
}
|
|
123
|
+
function expandHextets(fragment) {
|
|
124
|
+
const hextets = [];
|
|
125
|
+
for (const group of fragment.split(":")) {
|
|
126
|
+
if (group.includes(".")) {
|
|
127
|
+
const octets = parseIpv4(group);
|
|
128
|
+
hextets.push(octets[0] << 8 | octets[1], octets[2] << 8 | octets[3]);
|
|
129
|
+
} else {
|
|
130
|
+
hextets.push(parseInt(group, 16));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return hextets;
|
|
134
|
+
}
|
|
135
|
+
function ipv4ToInt(octets) {
|
|
136
|
+
return (octets[0] << 24 | octets[1] << 16 | octets[2] << 8 | octets[3]) >>> 0;
|
|
137
|
+
}
|
|
138
|
+
function hextetsToBigInt(hextets) {
|
|
139
|
+
let value = 0n;
|
|
140
|
+
for (const hextet of hextets) {
|
|
141
|
+
value = value << 16n | BigInt(hextet);
|
|
142
|
+
}
|
|
143
|
+
return value;
|
|
144
|
+
}
|
|
145
|
+
function parseIpv4Cidr(cidr) {
|
|
146
|
+
const [address, prefix] = cidr.split("/");
|
|
147
|
+
const mask = 4294967295 << 32 - Number(prefix) >>> 0;
|
|
148
|
+
return { base: (ipv4ToInt(parseIpv4(address)) & mask) >>> 0, mask };
|
|
149
|
+
}
|
|
150
|
+
function parseIpv6Cidr(cidr) {
|
|
151
|
+
const [address, prefix] = cidr.split("/");
|
|
152
|
+
return { base: hextetsToBigInt(parseIpv6(address)), prefix: Number(prefix) };
|
|
153
|
+
}
|
|
154
|
+
function isBlockedIpv4(octets) {
|
|
155
|
+
const value = ipv4ToInt(octets);
|
|
156
|
+
return BLOCKED_IPV4_CIDRS.some(
|
|
157
|
+
({ base, mask }) => (value & mask) >>> 0 === base
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
function isBlockedIpv6(hextets) {
|
|
161
|
+
const value = hextetsToBigInt(hextets);
|
|
162
|
+
if (value >> 32n === 0xffffn) {
|
|
163
|
+
return isBlockedIpv4([
|
|
164
|
+
Number(value >> 24n & 0xffn),
|
|
165
|
+
Number(value >> 16n & 0xffn),
|
|
166
|
+
Number(value >> 8n & 0xffn),
|
|
167
|
+
Number(value & 0xffn)
|
|
168
|
+
]);
|
|
169
|
+
}
|
|
170
|
+
return BLOCKED_IPV6_CIDRS.some(
|
|
171
|
+
({ base, prefix }) => value >> BigInt(128 - prefix) === base >> BigInt(128 - prefix)
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
function isBlockedAddress(address) {
|
|
175
|
+
const octets = parseIpv4(address);
|
|
176
|
+
if (octets) {
|
|
177
|
+
return isBlockedIpv4(octets);
|
|
178
|
+
}
|
|
179
|
+
const hextets = parseIpv6(address);
|
|
180
|
+
if (hextets) {
|
|
181
|
+
return isBlockedIpv6(hextets);
|
|
182
|
+
}
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
async function resolveHostAddresses(hostname) {
|
|
186
|
+
if ((0, import_node_net.isIP)(hostname) !== 0) {
|
|
187
|
+
return [hostname];
|
|
188
|
+
}
|
|
189
|
+
const records = await (0, import_promises.lookup)(hostname, { all: true });
|
|
190
|
+
const addresses = [...new Set(records.map((record) => record.address))];
|
|
191
|
+
if (addresses.length === 0) {
|
|
192
|
+
throw new Error(`Unable to resolve host: ${hostname}`);
|
|
193
|
+
}
|
|
194
|
+
return addresses;
|
|
195
|
+
}
|
|
196
|
+
function assertUrlAllowed(url) {
|
|
197
|
+
const parsed = new URL(url);
|
|
198
|
+
if (!ALLOWED_SCHEMES.has(parsed.protocol)) {
|
|
199
|
+
throw new Error(`Unsupported url scheme: ${url}`);
|
|
200
|
+
}
|
|
201
|
+
if (isBlockedHostname(parsed.hostname)) {
|
|
202
|
+
throw new Error(`Blocked host: ${parsed.hostname}`);
|
|
203
|
+
}
|
|
204
|
+
return parsed;
|
|
205
|
+
}
|
|
206
|
+
async function validateResolvedAddresses(hostname) {
|
|
207
|
+
const addresses = await resolveHostAddresses(hostname);
|
|
208
|
+
if (addresses.some(isBlockedAddress)) {
|
|
209
|
+
throw new Error(`Blocked host: ${hostname}`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function decodeHtmlEntities(text) {
|
|
213
|
+
return text.replace(/ /g, " ").replace(/'/g, "'").replace(/'/g, "'").replace(/"/g, '"').replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
214
|
+
}
|
|
215
|
+
function htmlToText(html) {
|
|
216
|
+
const withoutCode = html.replace(/<script[\s\S]*?<\/script>/gi, " ").replace(/<style[\s\S]*?<\/style>/gi, " ").replace(/<!--[\s\S]*?-->/g, " ");
|
|
217
|
+
const text = decodeHtmlEntities(withoutCode.replace(/<[^>]+>/g, "\n"));
|
|
218
|
+
return text.split("\n").map((line) => line.trim()).filter((line) => line.split(/\s+/).filter(Boolean).length > 3).join("\n");
|
|
219
|
+
}
|
|
220
|
+
async function loadWebPage(url, options) {
|
|
221
|
+
var _a;
|
|
222
|
+
const timeoutMs = (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : DEFAULT_TIMEOUT_MS;
|
|
223
|
+
try {
|
|
224
|
+
const parsed = assertUrlAllowed(url);
|
|
225
|
+
await validateResolvedAddresses(normalizeHost(parsed.hostname));
|
|
226
|
+
const response = await fetch(url, {
|
|
227
|
+
redirect: "manual",
|
|
228
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
229
|
+
});
|
|
230
|
+
if (response.status !== 200) {
|
|
231
|
+
return failedToFetchMessage(url);
|
|
232
|
+
}
|
|
233
|
+
return htmlToText(await response.text());
|
|
234
|
+
} catch {
|
|
235
|
+
return failedToFetchMessage(url);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const LOAD_WEB_PAGE = new import_function_tool.FunctionTool({
|
|
239
|
+
name: "load_web_page",
|
|
240
|
+
description: "Fetches the content at the given URL and returns the readable text extracted from the page.",
|
|
241
|
+
parameters: import_zod.z.object({
|
|
242
|
+
url: import_zod.z.string().describe("The URL to fetch and extract text from.")
|
|
243
|
+
}),
|
|
244
|
+
execute: ({ url }) => loadWebPage(url)
|
|
245
|
+
});
|
|
246
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
247
|
+
0 && (module.exports = {
|
|
248
|
+
LOAD_WEB_PAGE,
|
|
249
|
+
loadWebPage
|
|
250
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
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 load_mcp_resource_tool_exports = {};
|
|
26
|
+
__export(load_mcp_resource_tool_exports, {
|
|
27
|
+
LoadMcpResourceTool: () => LoadMcpResourceTool
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(load_mcp_resource_tool_exports);
|
|
30
|
+
var import_genai = require("@google/genai");
|
|
31
|
+
var import_llm_request = require("../../models/llm_request.js");
|
|
32
|
+
var import_logger = require("../../utils/logger.js");
|
|
33
|
+
var import_base_tool = require("../base_tool.js");
|
|
34
|
+
/**
|
|
35
|
+
* @license
|
|
36
|
+
* Copyright 2026 Google LLC
|
|
37
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
38
|
+
*/
|
|
39
|
+
class LoadMcpResourceTool extends import_base_tool.BaseTool {
|
|
40
|
+
constructor(mcpToolset) {
|
|
41
|
+
super({
|
|
42
|
+
name: "load_mcp_resource",
|
|
43
|
+
description: `Loads resources from the MCP server.
|
|
44
|
+
|
|
45
|
+
NOTE: Call when you need access to resources.`
|
|
46
|
+
});
|
|
47
|
+
this.mcpToolset = mcpToolset;
|
|
48
|
+
}
|
|
49
|
+
_getDeclaration() {
|
|
50
|
+
return {
|
|
51
|
+
name: this.name,
|
|
52
|
+
description: this.description,
|
|
53
|
+
parameters: {
|
|
54
|
+
type: import_genai.Type.OBJECT,
|
|
55
|
+
properties: {
|
|
56
|
+
resource_names: {
|
|
57
|
+
type: import_genai.Type.ARRAY,
|
|
58
|
+
items: {
|
|
59
|
+
type: import_genai.Type.STRING
|
|
60
|
+
},
|
|
61
|
+
description: "The names of the MCP resources to load."
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async runAsync({ args }) {
|
|
68
|
+
const resourceNames = args["resource_names"] || [];
|
|
69
|
+
return {
|
|
70
|
+
resource_names: resourceNames,
|
|
71
|
+
status: "resource contents temporarily inserted and removed. to access these resources, call load_mcp_resource tool again."
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
async processLlmRequest(request) {
|
|
75
|
+
await super.processLlmRequest(request);
|
|
76
|
+
await this.appendResourcesToLlmRequest(request.llmRequest);
|
|
77
|
+
}
|
|
78
|
+
async appendResourcesToLlmRequest(llmRequest) {
|
|
79
|
+
var _a, _b;
|
|
80
|
+
try {
|
|
81
|
+
const availableResourceNames = await this.mcpToolset.listResources();
|
|
82
|
+
if (availableResourceNames.length > 0) {
|
|
83
|
+
(0, import_llm_request.appendInstructions)(llmRequest, [
|
|
84
|
+
`You have a list of MCP resources:
|
|
85
|
+
${JSON.stringify(
|
|
86
|
+
availableResourceNames
|
|
87
|
+
)}
|
|
88
|
+
|
|
89
|
+
When the user asks questions about any of the resources, you should call the
|
|
90
|
+
\`load_mcp_resource\` function to load the resource. Always call load_mcp_resource
|
|
91
|
+
before answering questions related to the resources.`
|
|
92
|
+
]);
|
|
93
|
+
}
|
|
94
|
+
} catch (e) {
|
|
95
|
+
import_logger.logger.warn(`Failed to list MCP resources: ${e}`);
|
|
96
|
+
}
|
|
97
|
+
const lastContent = llmRequest.contents.at(-1);
|
|
98
|
+
const functionResponse = (_b = (_a = lastContent == null ? void 0 : lastContent.parts) == null ? void 0 : _a[0]) == null ? void 0 : _b.functionResponse;
|
|
99
|
+
if (!functionResponse || functionResponse.name !== this.name) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const response = functionResponse.response || {};
|
|
103
|
+
const requestedResourceNames = response["resource_names"] || [];
|
|
104
|
+
for (const resourceName of requestedResourceNames) {
|
|
105
|
+
try {
|
|
106
|
+
const resourceContents = await this.mcpToolset.readResource(resourceName);
|
|
107
|
+
for (const content of resourceContents) {
|
|
108
|
+
llmRequest.contents.push({
|
|
109
|
+
role: "user",
|
|
110
|
+
parts: [
|
|
111
|
+
{ text: `Resource ${resourceName} is:` },
|
|
112
|
+
this.mcpContentToPart(content, resourceName)
|
|
113
|
+
]
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
} catch (e) {
|
|
117
|
+
import_logger.logger.warn(`Failed to read MCP resource '${resourceName}': ${e}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
mcpContentToPart(content, resourceName) {
|
|
122
|
+
var _a;
|
|
123
|
+
if ("text" in content) {
|
|
124
|
+
return { text: content.text };
|
|
125
|
+
}
|
|
126
|
+
if ("blob" in content) {
|
|
127
|
+
return {
|
|
128
|
+
inlineData: {
|
|
129
|
+
data: content.blob,
|
|
130
|
+
mimeType: (_a = content.mimeType) != null ? _a : "application/octet-stream"
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return { text: `[Unknown content type for ${resourceName}]` };
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
138
|
+
0 && (module.exports = {
|
|
139
|
+
LoadMcpResourceTool
|
|
140
|
+
});
|