@google/adk 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/agents/functions.js +4 -0
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +305 -0
- package/dist/cjs/code_executors/code_execution_utils.js +1 -1
- package/dist/cjs/common.js +19 -0
- package/dist/cjs/events/event.js +3 -1
- package/dist/cjs/index.js +97 -125
- package/dist/cjs/integrations/agent_registry/agent_registry.js +362 -0
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +103 -0
- package/dist/cjs/integrations/agent_registry/helpers.js +57 -0
- package/dist/cjs/integrations/agent_registry/types.js +50 -0
- package/dist/cjs/memory/vertex_ai_memory_bank_service.js +496 -0
- package/dist/cjs/runner/in_memory_runner.js +10 -5
- package/dist/cjs/runner/runner.js +32 -2
- package/dist/cjs/sessions/database_session_service.js +49 -3
- package/dist/cjs/sessions/in_memory_session_service.js +70 -14
- package/dist/cjs/sessions/registry.js +4 -0
- package/dist/cjs/sessions/vertex_ai_session_service.js +428 -0
- package/dist/cjs/tools/agent_tool.js +11 -6
- package/dist/cjs/tools/exit_loop_tool.js +9 -0
- package/dist/cjs/tools/function_tool.js +7 -2
- package/dist/cjs/tools/google_maps_grounding_tool.js +80 -0
- package/dist/cjs/tools/long_running_tool.js +2 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/cjs/tools/mcp/mcp_tool.js +12 -7
- package/dist/cjs/tools/mcp/mcp_toolset.js +27 -4
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +78 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +84 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +133 -0
- package/dist/cjs/tools/skill/load_skill_resource_tool.js +2 -25
- package/dist/cjs/tools/url_context_tool.js +73 -0
- package/dist/cjs/tools/vertex_ai_search_tool.js +127 -0
- package/dist/cjs/tools/vertex_rag_retrieval_tool.js +64 -0
- package/dist/cjs/utils/file_utils.js +28 -0
- package/dist/cjs/utils/gemini_schema_util.js +18 -0
- package/dist/cjs/utils/model_name.js +8 -2
- package/dist/cjs/utils/partial_copy.js +51 -0
- package/dist/cjs/utils/streaming_utils.js +167 -121
- package/dist/cjs/utils/vertex_ai_utils.js +50 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/functions.js +4 -0
- package/dist/esm/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +281 -0
- package/dist/esm/code_executors/code_execution_utils.js +1 -1
- package/dist/esm/common.js +15 -0
- package/dist/esm/events/event.js +3 -1
- package/dist/esm/index.js +54 -130
- package/dist/esm/integrations/agent_registry/agent_registry.js +333 -0
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +77 -0
- package/dist/esm/integrations/agent_registry/helpers.js +28 -0
- package/dist/esm/integrations/agent_registry/types.js +20 -0
- package/dist/esm/memory/vertex_ai_memory_bank_service.js +468 -0
- package/dist/esm/runner/in_memory_runner.js +10 -5
- package/dist/esm/runner/runner.js +32 -2
- package/dist/esm/sessions/database_session_service.js +49 -3
- package/dist/esm/sessions/in_memory_session_service.js +70 -14
- package/dist/esm/sessions/registry.js +7 -0
- package/dist/esm/sessions/vertex_ai_session_service.js +403 -0
- package/dist/esm/tools/agent_tool.js +11 -6
- package/dist/esm/tools/exit_loop_tool.js +9 -0
- package/dist/esm/tools/function_tool.js +7 -2
- package/dist/esm/tools/google_maps_grounding_tool.js +54 -0
- package/dist/esm/tools/long_running_tool.js +2 -1
- package/dist/esm/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/esm/tools/mcp/mcp_tool.js +12 -7
- package/dist/esm/tools/mcp/mcp_toolset.js +27 -4
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +48 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
- package/dist/esm/tools/skill/load_skill_resource_tool.js +1 -24
- package/dist/esm/tools/url_context_tool.js +44 -0
- package/dist/esm/tools/vertex_ai_search_tool.js +103 -0
- package/dist/esm/tools/vertex_rag_retrieval_tool.js +36 -0
- package/dist/esm/utils/file_utils.js +26 -0
- package/dist/esm/utils/gemini_schema_util.js +18 -0
- package/dist/esm/utils/model_name.js +6 -1
- package/dist/esm/utils/partial_copy.js +23 -0
- package/dist/esm/utils/streaming_utils.js +165 -120
- package/dist/esm/utils/vertex_ai_utils.js +22 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +14 -0
- package/dist/types/agents/processors/base_llm_processor.d.ts +12 -4
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +5 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +4 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +5 -0
- package/dist/types/agents/run_config.d.ts +15 -0
- package/dist/types/code_executors/agent_engine_sandbox_code_executor.d.ts +51 -0
- package/dist/types/common.d.ts +7 -0
- package/dist/types/events/event_actions.d.ts +24 -6
- package/dist/types/events/structured_events.d.ts +13 -0
- package/dist/types/examples/example_util.d.ts +25 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/integrations/agent_registry/agent_registry.d.ts +94 -0
- package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +43 -0
- package/dist/types/integrations/agent_registry/helpers.d.ts +7 -0
- package/dist/types/integrations/agent_registry/types.d.ts +101 -0
- package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +52 -0
- package/dist/types/runner/in_memory_runner.d.ts +28 -1
- package/dist/types/runner/runner.d.ts +47 -0
- package/dist/types/sessions/base_session_service.d.ts +18 -0
- package/dist/types/sessions/database_session_service.d.ts +1 -1
- package/dist/types/sessions/in_memory_session_service.d.ts +1 -1
- package/dist/types/sessions/vertex_ai_session_service.d.ts +37 -0
- package/dist/types/tools/exit_loop_tool.d.ts +9 -0
- package/dist/types/tools/function_tool.d.ts +22 -2
- package/dist/types/tools/google_maps_grounding_tool.d.ts +22 -0
- package/dist/types/tools/long_running_tool.d.ts +11 -1
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +3 -0
- package/dist/types/tools/mcp/mcp_tool.d.ts +7 -1
- package/dist/types/tools/mcp/mcp_toolset.d.ts +7 -1
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +25 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +20 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.d.ts +20 -0
- package/dist/types/tools/url_context_tool.d.ts +17 -0
- package/dist/types/tools/vertex_ai_search_tool.d.ts +55 -0
- package/dist/types/tools/vertex_rag_retrieval_tool.d.ts +42 -0
- package/dist/types/utils/file_utils.d.ts +2 -0
- package/dist/types/utils/model_name.d.ts +4 -0
- package/dist/types/utils/partial_copy.d.ts +13 -0
- package/dist/types/utils/streaming_utils.d.ts +8 -17
- package/dist/types/utils/vertex_ai_utils.d.ts +14 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/functions.js +4 -0
- package/dist/web/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/web/code_executors/agent_engine_sandbox_code_executor.js +281 -0
- package/dist/web/code_executors/code_execution_utils.js +1 -1
- package/dist/web/common.js +15 -0
- package/dist/web/events/event.js +3 -1
- package/dist/web/index.js +54 -12
- package/dist/web/integrations/agent_registry/agent_registry.js +333 -0
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +90 -0
- package/dist/web/integrations/agent_registry/helpers.js +28 -0
- package/dist/web/integrations/agent_registry/types.js +20 -0
- package/dist/web/memory/vertex_ai_memory_bank_service.js +475 -0
- package/dist/web/runner/in_memory_runner.js +10 -5
- package/dist/web/runner/runner.js +32 -2
- package/dist/web/sessions/database_session_service.js +49 -3
- package/dist/web/sessions/in_memory_session_service.js +70 -14
- package/dist/web/sessions/registry.js +7 -0
- package/dist/web/sessions/vertex_ai_session_service.js +414 -0
- package/dist/web/tools/agent_tool.js +11 -6
- package/dist/web/tools/exit_loop_tool.js +9 -0
- package/dist/web/tools/function_tool.js +7 -2
- package/dist/web/tools/google_maps_grounding_tool.js +54 -0
- package/dist/web/tools/long_running_tool.js +2 -1
- package/dist/web/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/web/tools/mcp/mcp_tool.js +12 -7
- package/dist/web/tools/mcp/mcp_toolset.js +27 -4
- package/dist/web/tools/openapi_tool/auth/auth_helpers.js +48 -0
- package/dist/web/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
- package/dist/web/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
- package/dist/web/tools/skill/load_skill_resource_tool.js +1 -24
- package/dist/web/tools/url_context_tool.js +44 -0
- package/dist/web/tools/vertex_ai_search_tool.js +103 -0
- package/dist/web/tools/vertex_rag_retrieval_tool.js +36 -0
- package/dist/web/utils/file_utils.js +26 -0
- package/dist/web/utils/gemini_schema_util.js +18 -0
- package/dist/web/utils/model_name.js +6 -1
- package/dist/web/utils/partial_copy.js +23 -0
- package/dist/web/utils/streaming_utils.js +219 -121
- package/dist/web/utils/vertex_ai_utils.js +22 -0
- package/dist/web/version.js +1 -1
- package/package.json +3 -2
- package/dist/cjs/index.js.map +0 -7
- package/dist/esm/index.js.map +0 -7
- package/dist/web/index.js.map +0 -7
|
@@ -0,0 +1,80 @@
|
|
|
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 google_maps_grounding_tool_exports = {};
|
|
26
|
+
__export(google_maps_grounding_tool_exports, {
|
|
27
|
+
GOOGLE_MAPS_GROUNDING: () => GOOGLE_MAPS_GROUNDING,
|
|
28
|
+
GoogleMapsGroundingTool: () => GoogleMapsGroundingTool,
|
|
29
|
+
applyGoogleMapsGrounding: () => applyGoogleMapsGrounding
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(google_maps_grounding_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 applyGoogleMapsGrounding(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.isGemini1Model)(llmRequest.model)) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
"Google Maps grounding tool cannot be used with Gemini 1.x models."
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
if ((0, import_model_name.isGeminiModel)(llmRequest.model) || modelCheckDisabled) {
|
|
52
|
+
llmRequest.config.tools.push({
|
|
53
|
+
googleMaps: {}
|
|
54
|
+
});
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
throw new Error(
|
|
58
|
+
`Google maps tool is not supported for model ${llmRequest.model}`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
class GoogleMapsGroundingTool extends import_base_tool.BaseTool {
|
|
62
|
+
constructor() {
|
|
63
|
+
super({ name: "google_maps", description: "Google Maps Grounding Tool" });
|
|
64
|
+
}
|
|
65
|
+
runAsync() {
|
|
66
|
+
return Promise.resolve();
|
|
67
|
+
}
|
|
68
|
+
async processLlmRequest({
|
|
69
|
+
llmRequest
|
|
70
|
+
}) {
|
|
71
|
+
applyGoogleMapsGrounding(llmRequest);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const GOOGLE_MAPS_GROUNDING = new GoogleMapsGroundingTool();
|
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
+
0 && (module.exports = {
|
|
77
|
+
GOOGLE_MAPS_GROUNDING,
|
|
78
|
+
GoogleMapsGroundingTool,
|
|
79
|
+
applyGoogleMapsGrounding
|
|
80
|
+
});
|
|
@@ -45,7 +45,8 @@ class LongRunningFunctionTool extends import_function_tool.FunctionTool {
|
|
|
45
45
|
super({ ...options, isLongRunning: true });
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
|
-
*
|
|
48
|
+
* Returns the function declaration with an appended instruction warning the
|
|
49
|
+
* model not to re-invoke the tool while it is still running.
|
|
49
50
|
*/
|
|
50
51
|
_getDeclaration() {
|
|
51
52
|
const declaration = super._getDeclaration();
|
|
@@ -37,6 +37,7 @@ var import_streamableHttp = require("@modelcontextprotocol/sdk/client/streamable
|
|
|
37
37
|
*/
|
|
38
38
|
class MCPSessionManager {
|
|
39
39
|
constructor(connectionParams) {
|
|
40
|
+
this.activeSessions = /* @__PURE__ */ new Set();
|
|
40
41
|
this.connectionParams = connectionParams;
|
|
41
42
|
}
|
|
42
43
|
async createSession() {
|
|
@@ -68,8 +69,18 @@ class MCPSessionManager {
|
|
|
68
69
|
break;
|
|
69
70
|
}
|
|
70
71
|
}
|
|
72
|
+
this.activeSessions.add(client);
|
|
71
73
|
return client;
|
|
72
74
|
}
|
|
75
|
+
async closeSession(client) {
|
|
76
|
+
if (this.activeSessions.has(client)) {
|
|
77
|
+
this.activeSessions.delete(client);
|
|
78
|
+
await client.close();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
getActiveSessions() {
|
|
82
|
+
return Array.from(this.activeSessions);
|
|
83
|
+
}
|
|
73
84
|
}
|
|
74
85
|
// Annotate the CommonJS export names for ESM import in node:
|
|
75
86
|
0 && (module.exports = {
|
|
@@ -35,10 +35,11 @@ var import_base_tool = require("../base_tool.js");
|
|
|
35
35
|
* SPDX-License-Identifier: Apache-2.0
|
|
36
36
|
*/
|
|
37
37
|
class MCPTool extends import_base_tool.BaseTool {
|
|
38
|
-
constructor(mcpTool, mcpSessionManager) {
|
|
38
|
+
constructor(mcpTool, mcpSessionManager, originalName) {
|
|
39
39
|
super({ name: mcpTool.name, description: mcpTool.description || "" });
|
|
40
40
|
this.mcpTool = mcpTool;
|
|
41
41
|
this.mcpSessionManager = mcpSessionManager;
|
|
42
|
+
this.originalName = originalName || mcpTool.name;
|
|
42
43
|
}
|
|
43
44
|
_getDeclaration() {
|
|
44
45
|
return {
|
|
@@ -52,12 +53,16 @@ class MCPTool extends import_base_tool.BaseTool {
|
|
|
52
53
|
}
|
|
53
54
|
async runAsync(request) {
|
|
54
55
|
const session = await this.mcpSessionManager.createSession();
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
try {
|
|
57
|
+
const callRequest = {};
|
|
58
|
+
callRequest.params = { name: this.originalName, arguments: request.args };
|
|
59
|
+
const result = await session.callTool(callRequest.params, void 0, {
|
|
60
|
+
signal: request.toolContext.abortSignal
|
|
61
|
+
});
|
|
62
|
+
return result;
|
|
63
|
+
} finally {
|
|
64
|
+
await this.mcpSessionManager.closeSession(session);
|
|
65
|
+
}
|
|
61
66
|
}
|
|
62
67
|
}
|
|
63
68
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -41,22 +41,45 @@ class MCPToolset extends import_base_toolset.BaseToolset {
|
|
|
41
41
|
super(toolFilter, prefix);
|
|
42
42
|
this.mcpSessionManager = new import_mcp_session_manager.MCPSessionManager(connectionParams);
|
|
43
43
|
}
|
|
44
|
-
async getTools() {
|
|
44
|
+
async getTools(context) {
|
|
45
45
|
const session = await this.mcpSessionManager.createSession();
|
|
46
|
-
|
|
46
|
+
let listResult;
|
|
47
|
+
try {
|
|
48
|
+
listResult = await session.listTools();
|
|
49
|
+
} finally {
|
|
50
|
+
await this.mcpSessionManager.closeSession(session);
|
|
51
|
+
}
|
|
47
52
|
import_logger.logger.debug(`number of tools: ${listResult.tools.length}`);
|
|
48
53
|
for (const tool of listResult.tools) {
|
|
49
54
|
import_logger.logger.debug(`tool: ${tool.name}`);
|
|
50
55
|
}
|
|
51
|
-
|
|
56
|
+
const tools = listResult.tools.map((tool) => {
|
|
52
57
|
const toolWithPrefix = {
|
|
53
58
|
...tool,
|
|
54
59
|
name: this.prefix ? `${this.prefix}_${tool.name}` : tool.name
|
|
55
60
|
};
|
|
56
|
-
return new import_mcp_tool.MCPTool(toolWithPrefix, this.mcpSessionManager);
|
|
61
|
+
return new import_mcp_tool.MCPTool(toolWithPrefix, this.mcpSessionManager, tool.name);
|
|
57
62
|
});
|
|
63
|
+
const filter = this.toolFilter;
|
|
64
|
+
if (!filter || Array.isArray(filter) && filter.length === 0) {
|
|
65
|
+
return tools;
|
|
66
|
+
}
|
|
67
|
+
if (Array.isArray(filter)) {
|
|
68
|
+
return tools.filter((tool) => filter.includes(tool.name));
|
|
69
|
+
}
|
|
70
|
+
if (context) {
|
|
71
|
+
return tools.filter((tool) => filter(tool, context));
|
|
72
|
+
}
|
|
73
|
+
import_logger.logger.warn(
|
|
74
|
+
"MCPToolset: a ToolPredicate toolFilter was provided but getTools() was called without a ReadonlyContext. The filter will not be applied."
|
|
75
|
+
);
|
|
76
|
+
return tools;
|
|
58
77
|
}
|
|
59
78
|
async close() {
|
|
79
|
+
const sessions = this.mcpSessionManager.getActiveSessions();
|
|
80
|
+
await Promise.allSettled(
|
|
81
|
+
sessions.map((session) => this.mcpSessionManager.closeSession(session))
|
|
82
|
+
);
|
|
60
83
|
}
|
|
61
84
|
}
|
|
62
85
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -0,0 +1,78 @@
|
|
|
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 auth_helpers_exports = {};
|
|
26
|
+
__export(auth_helpers_exports, {
|
|
27
|
+
applyCredential: () => applyCredential,
|
|
28
|
+
createApiKeyScheme: () => createApiKeyScheme,
|
|
29
|
+
createBearerScheme: () => createBearerScheme
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(auth_helpers_exports);
|
|
32
|
+
/**
|
|
33
|
+
* @license
|
|
34
|
+
* Copyright 2026 Google LLC
|
|
35
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
36
|
+
*/
|
|
37
|
+
function applyCredential(url, headers, credential, authScheme) {
|
|
38
|
+
if (!credential) return url;
|
|
39
|
+
if (credential.apiKey) {
|
|
40
|
+
let inLocation;
|
|
41
|
+
let name = "key";
|
|
42
|
+
if (authScheme && authScheme.type === "apiKey") {
|
|
43
|
+
const apiKeyScheme = authScheme;
|
|
44
|
+
inLocation = apiKeyScheme.in;
|
|
45
|
+
name = apiKeyScheme.name;
|
|
46
|
+
}
|
|
47
|
+
if (inLocation === "header") {
|
|
48
|
+
headers[name] = credential.apiKey;
|
|
49
|
+
} else if (inLocation === "query") {
|
|
50
|
+
const separator = url.includes("?") ? "&" : "?";
|
|
51
|
+
url += `${separator}${name}=${encodeURIComponent(credential.apiKey)}`;
|
|
52
|
+
} else {
|
|
53
|
+
headers["Authorization"] = credential.apiKey;
|
|
54
|
+
}
|
|
55
|
+
} else if (credential.http && credential.http.credentials && credential.http.credentials.token) {
|
|
56
|
+
headers["Authorization"] = `Bearer ${credential.http.credentials.token}`;
|
|
57
|
+
}
|
|
58
|
+
return url;
|
|
59
|
+
}
|
|
60
|
+
function createApiKeyScheme(name, inLocation) {
|
|
61
|
+
return {
|
|
62
|
+
type: "apiKey",
|
|
63
|
+
name,
|
|
64
|
+
in: inLocation
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function createBearerScheme() {
|
|
68
|
+
return {
|
|
69
|
+
type: "http",
|
|
70
|
+
scheme: "bearer"
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
applyCredential,
|
|
76
|
+
createApiKeyScheme,
|
|
77
|
+
createBearerScheme
|
|
78
|
+
});
|
package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
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 __decorateClass = (decorators, target, key, kind) => {
|
|
26
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
27
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
28
|
+
if (decorator = decorators[i])
|
|
29
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
30
|
+
if (kind && result) __defProp(target, key, result);
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
var auto_auth_credential_exchanger_exports = {};
|
|
34
|
+
__export(auto_auth_credential_exchanger_exports, {
|
|
35
|
+
AutoAuthCredentialExchanger: () => AutoAuthCredentialExchanger
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(auto_auth_credential_exchanger_exports);
|
|
38
|
+
var import_auth_credential = require("../../../../auth/auth_credential.js");
|
|
39
|
+
var import_oauth2_credential_exchanger = require("../../../../auth/oauth2/oauth2_credential_exchanger.js");
|
|
40
|
+
var import_experimental = require("../../../../utils/experimental.js");
|
|
41
|
+
var import_service_account_exchanger = require("./service_account_exchanger.js");
|
|
42
|
+
/**
|
|
43
|
+
* @license
|
|
44
|
+
* Copyright 2026 Google LLC
|
|
45
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
46
|
+
*/
|
|
47
|
+
let AutoAuthCredentialExchanger = class {
|
|
48
|
+
constructor() {
|
|
49
|
+
this.exchangers = /* @__PURE__ */ new Map();
|
|
50
|
+
this.exchangers.set(
|
|
51
|
+
import_auth_credential.AuthCredentialTypes.OAUTH2,
|
|
52
|
+
new import_oauth2_credential_exchanger.OAuth2CredentialExchanger()
|
|
53
|
+
);
|
|
54
|
+
this.exchangers.set(
|
|
55
|
+
import_auth_credential.AuthCredentialTypes.OPEN_ID_CONNECT,
|
|
56
|
+
new import_oauth2_credential_exchanger.OAuth2CredentialExchanger()
|
|
57
|
+
);
|
|
58
|
+
this.exchangers.set(
|
|
59
|
+
import_auth_credential.AuthCredentialTypes.SERVICE_ACCOUNT,
|
|
60
|
+
new import_service_account_exchanger.ServiceAccountCredentialExchanger()
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
async exchange(params) {
|
|
64
|
+
const { authCredential, authScheme } = params;
|
|
65
|
+
const exchanger = this.exchangers.get(authCredential.authType);
|
|
66
|
+
if (!exchanger) {
|
|
67
|
+
return {
|
|
68
|
+
credential: authCredential,
|
|
69
|
+
wasExchanged: false
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return exchanger.exchange({ authScheme, authCredential });
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
__decorateClass([
|
|
76
|
+
import_experimental.experimental
|
|
77
|
+
], AutoAuthCredentialExchanger.prototype, "exchange", 1);
|
|
78
|
+
AutoAuthCredentialExchanger = __decorateClass([
|
|
79
|
+
import_experimental.experimental
|
|
80
|
+
], AutoAuthCredentialExchanger);
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
AutoAuthCredentialExchanger
|
|
84
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
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 __decorateClass = (decorators, target, key, kind) => {
|
|
26
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
27
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
28
|
+
if (decorator = decorators[i])
|
|
29
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
30
|
+
if (kind && result) __defProp(target, key, result);
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
var service_account_exchanger_exports = {};
|
|
34
|
+
__export(service_account_exchanger_exports, {
|
|
35
|
+
ServiceAccountCredentialExchanger: () => ServiceAccountCredentialExchanger
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(service_account_exchanger_exports);
|
|
38
|
+
var import_google_auth_library = require("google-auth-library");
|
|
39
|
+
var import_auth_credential = require("../../../../auth/auth_credential.js");
|
|
40
|
+
var import_base_credential_exchanger = require("../../../../auth/exchanger/base_credential_exchanger.js");
|
|
41
|
+
var import_experimental = require("../../../../utils/experimental.js");
|
|
42
|
+
/**
|
|
43
|
+
* @license
|
|
44
|
+
* Copyright 2026 Google LLC
|
|
45
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
46
|
+
*/
|
|
47
|
+
const DEFAULT_SCOPES = ["https://www.googleapis.com/auth/cloud-platform"];
|
|
48
|
+
let ServiceAccountCredentialExchanger = class {
|
|
49
|
+
async exchange(params) {
|
|
50
|
+
const { authCredential } = params;
|
|
51
|
+
if (authCredential.authType !== import_auth_credential.AuthCredentialTypes.SERVICE_ACCOUNT || !authCredential.serviceAccount) {
|
|
52
|
+
throw new import_base_credential_exchanger.CredentialExchangeError(
|
|
53
|
+
"Invalid credential type for ServiceAccountCredentialExchanger"
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
const saConfig = authCredential.serviceAccount;
|
|
57
|
+
if (saConfig.useDefaultCredential) {
|
|
58
|
+
return this.exchangeForDefaultCredential(saConfig);
|
|
59
|
+
}
|
|
60
|
+
return this.exchangeForExplicitCredential(saConfig);
|
|
61
|
+
}
|
|
62
|
+
async exchangeForDefaultCredential(saConfig) {
|
|
63
|
+
try {
|
|
64
|
+
const auth = new import_google_auth_library.GoogleAuth({
|
|
65
|
+
scopes: saConfig.scopes || DEFAULT_SCOPES
|
|
66
|
+
});
|
|
67
|
+
const client = await auth.getClient();
|
|
68
|
+
const tokenResponse = await client.getAccessToken();
|
|
69
|
+
const token = tokenResponse.token;
|
|
70
|
+
if (!token) {
|
|
71
|
+
throw new Error("Failed to get access token from default credentials");
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
credential: {
|
|
75
|
+
authType: import_auth_credential.AuthCredentialTypes.HTTP,
|
|
76
|
+
http: {
|
|
77
|
+
scheme: "bearer",
|
|
78
|
+
credentials: { token }
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
wasExchanged: true
|
|
82
|
+
};
|
|
83
|
+
} catch (error) {
|
|
84
|
+
throw new import_base_credential_exchanger.CredentialExchangeError(
|
|
85
|
+
`Failed to exchange default service account token: ${error.message}`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async exchangeForExplicitCredential(saConfig) {
|
|
90
|
+
const creds = saConfig.serviceAccountCredential;
|
|
91
|
+
if (!creds) {
|
|
92
|
+
throw new import_base_credential_exchanger.CredentialExchangeError(
|
|
93
|
+
"Service account credentials are missing."
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const client = new import_google_auth_library.JWT({
|
|
98
|
+
email: creds.clientEmail,
|
|
99
|
+
key: creds.privateKey,
|
|
100
|
+
scopes: saConfig.scopes
|
|
101
|
+
});
|
|
102
|
+
const tokens = await client.authorize();
|
|
103
|
+
const token = tokens.access_token;
|
|
104
|
+
if (!token) {
|
|
105
|
+
throw new Error("Failed to get access token from explicit credentials");
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
credential: {
|
|
109
|
+
authType: import_auth_credential.AuthCredentialTypes.HTTP,
|
|
110
|
+
http: {
|
|
111
|
+
scheme: "bearer",
|
|
112
|
+
credentials: { token }
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
wasExchanged: true
|
|
116
|
+
};
|
|
117
|
+
} catch (error) {
|
|
118
|
+
throw new import_base_credential_exchanger.CredentialExchangeError(
|
|
119
|
+
`Failed to exchange explicit service account token: ${error.message}`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
__decorateClass([
|
|
125
|
+
import_experimental.experimental
|
|
126
|
+
], ServiceAccountCredentialExchanger.prototype, "exchange", 1);
|
|
127
|
+
ServiceAccountCredentialExchanger = __decorateClass([
|
|
128
|
+
import_experimental.experimental
|
|
129
|
+
], ServiceAccountCredentialExchanger);
|
|
130
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
131
|
+
0 && (module.exports = {
|
|
132
|
+
ServiceAccountCredentialExchanger
|
|
133
|
+
});
|
|
@@ -48,6 +48,7 @@ module.exports = __toCommonJS(load_skill_resource_tool_exports);
|
|
|
48
48
|
var import_genai = require("@google/genai");
|
|
49
49
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
50
50
|
var import_experimental = require("../../utils/experimental.js");
|
|
51
|
+
var import_file_utils = require("../../utils/file_utils.js");
|
|
51
52
|
var import_base_tool = require("../base_tool.js");
|
|
52
53
|
/**
|
|
53
54
|
* @license
|
|
@@ -55,30 +56,6 @@ var import_base_tool = require("../base_tool.js");
|
|
|
55
56
|
* SPDX-License-Identifier: Apache-2.0
|
|
56
57
|
*/
|
|
57
58
|
const BINARY_FILE_DETECTED_MSG = "Binary file detected. The content has been injected into the conversation history for you to analyze.";
|
|
58
|
-
const EXTENSION_TO_MIME_TYPE = {
|
|
59
|
-
"pdf": "application/pdf",
|
|
60
|
-
"jpg": "image/jpeg",
|
|
61
|
-
"jpeg": "image/jpeg",
|
|
62
|
-
"png": "image/png",
|
|
63
|
-
"gif": "image/gif",
|
|
64
|
-
"csv": "text/csv",
|
|
65
|
-
"json": "application/json",
|
|
66
|
-
"xml": "application/xml",
|
|
67
|
-
"sh": "text/x-shellscript",
|
|
68
|
-
"bash": "text/x-shellscript",
|
|
69
|
-
"py": "text/x-python",
|
|
70
|
-
"js": "text/javascript",
|
|
71
|
-
"cjs": "text/javascript",
|
|
72
|
-
"mjs": "text/javascript",
|
|
73
|
-
"ts": "text/javascript",
|
|
74
|
-
"cts": "text/javascript",
|
|
75
|
-
"mts": "text/javascript"
|
|
76
|
-
};
|
|
77
|
-
function guessMimeType(filePath) {
|
|
78
|
-
var _a;
|
|
79
|
-
const ext = ((_a = filePath.split(".").pop()) == null ? void 0 : _a.toLowerCase()) || "";
|
|
80
|
-
return EXTENSION_TO_MIME_TYPE[ext] || "application/octet-stream";
|
|
81
|
-
}
|
|
82
59
|
let LoadSkillResourceTool = class extends import_base_tool.BaseTool {
|
|
83
60
|
constructor(toolset) {
|
|
84
61
|
super({
|
|
@@ -197,7 +174,7 @@ let LoadSkillResourceTool = class extends import_base_tool.BaseTool {
|
|
|
197
174
|
content = (_b = skillResources.assets) == null ? void 0 : _b[resourcePath.substring("assets/".length)];
|
|
198
175
|
}
|
|
199
176
|
if (Buffer.isBuffer(content)) {
|
|
200
|
-
const mimeType = guessMimeType(resourcePath);
|
|
177
|
+
const mimeType = (0, import_file_utils.guessMimeType)(resourcePath);
|
|
201
178
|
llmRequest.contents.push({
|
|
202
179
|
role: "user",
|
|
203
180
|
parts: [
|
|
@@ -0,0 +1,73 @@
|
|
|
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 url_context_tool_exports = {};
|
|
26
|
+
__export(url_context_tool_exports, {
|
|
27
|
+
URL_CONTEXT: () => URL_CONTEXT,
|
|
28
|
+
UrlContextTool: () => UrlContextTool
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(url_context_tool_exports);
|
|
31
|
+
var import_model_name = require("../utils/model_name.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 UrlContextTool extends import_base_tool.BaseTool {
|
|
39
|
+
constructor() {
|
|
40
|
+
super({ name: "url_context", description: "URL Context Tool" });
|
|
41
|
+
}
|
|
42
|
+
runAsync() {
|
|
43
|
+
return Promise.resolve();
|
|
44
|
+
}
|
|
45
|
+
async processLlmRequest({
|
|
46
|
+
llmRequest
|
|
47
|
+
}) {
|
|
48
|
+
if (!llmRequest.model) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (!(0, import_model_name.isGeminiModel)(llmRequest.model)) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`URL context tool is not supported for model ${llmRequest.model}`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
if (!(0, import_model_name.isGemini2OrAbove)(llmRequest.model)) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
`URL context tool requires Gemini 2 or above, but got ${llmRequest.model}`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
llmRequest.config = llmRequest.config || {};
|
|
62
|
+
llmRequest.config.tools = llmRequest.config.tools || [];
|
|
63
|
+
llmRequest.config.tools.push({
|
|
64
|
+
urlContext: {}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const URL_CONTEXT = new UrlContextTool();
|
|
69
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
70
|
+
0 && (module.exports = {
|
|
71
|
+
URL_CONTEXT,
|
|
72
|
+
UrlContextTool
|
|
73
|
+
});
|