@google/adk 1.4.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/a2a/a2a_remote_agent.js +12 -2
- package/dist/cjs/a2a/agent_to_a2a.js +18 -3
- package/dist/cjs/a2a/auth.js +65 -0
- package/dist/cjs/a2a/event_converter_utils.js +47 -18
- package/dist/cjs/a2a/metadata_converter_utils.js +1 -1
- package/dist/cjs/agents/base_agent.js +39 -0
- package/dist/cjs/agents/functions.js +26 -28
- package/dist/cjs/agents/llm_agent.js +4 -2
- package/dist/cjs/agents/loop_agent.js +15 -3
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/cjs/agents/processors/content_processor_utils.js +2 -1
- package/dist/cjs/agents/processors/content_request_processor.js +2 -21
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +3 -1
- package/dist/cjs/agents/routed_agent.js +31 -0
- package/dist/cjs/agents/run_config.js +3 -2
- package/dist/cjs/artifacts/in_memory_artifact_service.js +17 -9
- package/dist/cjs/auth/credential_service/in_memory_credential_service.js +14 -3
- package/dist/cjs/code_executors/unsafe_local_code_executor.js +23 -12
- package/dist/cjs/common.js +35 -0
- package/dist/cjs/context/agent_controlled_context_compactor.js +2 -11
- package/dist/cjs/context/anchored_context_compactor.js +127 -0
- package/dist/cjs/context/compaction_utils.js +64 -0
- package/dist/cjs/context/token_based_context_compactor.js +13 -44
- package/dist/cjs/events/compacted_event.js +9 -3
- package/dist/cjs/events/event.js +28 -0
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/cjs/memory/in_memory_memory_service.js +13 -2
- package/dist/cjs/memory/vertex_ai_memory_bank_service.js +3 -0
- package/dist/cjs/plugins/base_plugin.js +4 -2
- package/dist/cjs/plugins/global_instruction_plugin.js +97 -0
- package/dist/cjs/runner/runner.js +69 -23
- package/dist/cjs/sessions/base_session_service.js +8 -3
- package/dist/cjs/sessions/in_memory_session_service.js +8 -8
- package/dist/cjs/sessions/vertex_ai_session_service.js +22 -10
- package/dist/cjs/skills/loader.js +40 -6
- package/dist/cjs/tools/enterprise_web_search_tool.js +81 -0
- package/dist/cjs/tools/example_tool.js +68 -0
- package/dist/cjs/tools/get_user_choice_tool.js +53 -0
- package/dist/cjs/tools/load_web_page.js +250 -0
- package/dist/cjs/tools/mcp/load_mcp_resource_tool.js +140 -0
- package/dist/cjs/tools/mcp/mcp_session_manager.js +35 -21
- package/dist/cjs/tools/mcp/mcp_toolset.js +63 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
- package/dist/cjs/tools/request_input_tool.js +54 -0
- package/dist/cjs/tools/skill/run_skill_inline_script_tool.js +54 -4
- package/dist/cjs/tools/skill/skill_toolset.js +4 -2
- package/dist/cjs/utils/branch_trie.js +41 -0
- package/dist/cjs/utils/crypto_shim.js +43 -0
- package/dist/cjs/utils/env_aware_utils.js +15 -13
- package/dist/cjs/utils/error_utils.js +120 -0
- package/dist/cjs/utils/file_utils.js +5 -2
- package/dist/cjs/utils/output_schema_utils.js +43 -0
- package/dist/cjs/utils/streaming_utils.js +5 -5
- package/dist/cjs/utils/vertex_ai_utils.js +3 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_remote_agent.js +12 -2
- package/dist/esm/a2a/agent_to_a2a.js +18 -3
- package/dist/esm/a2a/auth.js +37 -0
- package/dist/esm/a2a/event_converter_utils.js +47 -18
- package/dist/esm/a2a/metadata_converter_utils.js +1 -1
- package/dist/esm/agents/base_agent.js +39 -0
- package/dist/esm/agents/functions.js +27 -24
- package/dist/esm/agents/llm_agent.js +6 -4
- package/dist/esm/agents/loop_agent.js +15 -3
- package/dist/esm/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/esm/agents/processors/content_processor_utils.js +2 -1
- package/dist/esm/agents/processors/content_request_processor.js +2 -21
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +3 -1
- package/dist/esm/agents/routed_agent.js +31 -0
- package/dist/esm/agents/run_config.js +3 -2
- package/dist/esm/artifacts/in_memory_artifact_service.js +17 -9
- package/dist/esm/auth/credential_service/in_memory_credential_service.js +14 -3
- package/dist/esm/code_executors/unsafe_local_code_executor.js +22 -11
- package/dist/esm/common.js +29 -1
- package/dist/esm/context/agent_controlled_context_compactor.js +2 -11
- package/dist/esm/context/anchored_context_compactor.js +99 -0
- package/dist/esm/context/compaction_utils.js +38 -0
- package/dist/esm/context/token_based_context_compactor.js +16 -44
- package/dist/esm/events/compacted_event.js +7 -2
- package/dist/esm/events/event.js +24 -0
- package/dist/esm/index.js +8 -1
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/esm/memory/in_memory_memory_service.js +13 -2
- package/dist/esm/memory/vertex_ai_memory_bank_service.js +7 -1
- package/dist/esm/plugins/base_plugin.js +4 -2
- package/dist/esm/plugins/global_instruction_plugin.js +69 -0
- package/dist/esm/runner/runner.js +69 -23
- package/dist/esm/sessions/base_session_service.js +8 -3
- package/dist/esm/sessions/in_memory_session_service.js +8 -8
- package/dist/esm/sessions/vertex_ai_session_service.js +26 -11
- package/dist/esm/skills/loader.js +40 -6
- package/dist/esm/tools/enterprise_web_search_tool.js +55 -0
- package/dist/esm/tools/example_tool.js +42 -0
- package/dist/esm/tools/get_user_choice_tool.js +25 -0
- package/dist/esm/tools/load_web_page.js +221 -0
- package/dist/esm/tools/mcp/load_mcp_resource_tool.js +114 -0
- package/dist/esm/tools/mcp/mcp_session_manager.js +35 -21
- package/dist/esm/tools/mcp/mcp_toolset.js +63 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
- package/dist/esm/tools/request_input_tool.js +26 -0
- package/dist/esm/tools/skill/run_skill_inline_script_tool.js +53 -4
- package/dist/esm/tools/skill/skill_toolset.js +4 -2
- package/dist/esm/utils/branch_trie.js +13 -0
- package/dist/esm/utils/crypto_shim.js +15 -0
- package/dist/esm/utils/env_aware_utils.js +15 -13
- package/dist/esm/utils/error_utils.js +92 -0
- package/dist/esm/utils/file_utils.js +5 -2
- package/dist/esm/utils/output_schema_utils.js +15 -0
- package/dist/esm/utils/streaming_utils.js +1 -1
- package/dist/esm/utils/vertex_ai_utils.js +2 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +5 -1
- package/dist/types/a2a/agent_to_a2a.d.ts +38 -0
- package/dist/types/a2a/auth.d.ts +30 -0
- package/dist/types/a2a/event_converter_utils.d.ts +4 -1
- package/dist/types/agents/base_agent.d.ts +29 -1
- package/dist/types/agents/functions.d.ts +1 -9
- package/dist/types/agents/llm_agent.d.ts +5 -1
- package/dist/types/agents/loop_agent.d.ts +2 -2
- package/dist/types/agents/routed_agent.d.ts +24 -1
- package/dist/types/agents/run_config.d.ts +1 -1
- package/dist/types/auth/credential_service/in_memory_credential_service.d.ts +11 -0
- package/dist/types/code_executors/unsafe_local_code_executor.d.ts +5 -1
- package/dist/types/common.d.ts +11 -2
- package/dist/types/context/agent_controlled_context_compactor.d.ts +0 -1
- package/dist/types/context/anchored_context_compactor.d.ts +35 -0
- package/dist/types/context/compaction_utils.d.ts +23 -0
- package/dist/types/context/token_based_context_compactor.d.ts +0 -1
- package/dist/types/events/compacted_event.d.ts +10 -0
- package/dist/types/events/event.d.ts +13 -0
- package/dist/types/index.d.ts +5 -3
- package/dist/types/memory/in_memory_memory_service.d.ts +11 -0
- package/dist/types/plugins/base_plugin.d.ts +4 -2
- package/dist/types/plugins/global_instruction_plugin.d.ts +38 -0
- package/dist/types/runner/runner.d.ts +1 -1
- package/dist/types/sessions/base_session_service.d.ts +8 -0
- package/dist/types/sessions/in_memory_session_service.d.ts +9 -0
- package/dist/types/sessions/vertex_ai_session_service.d.ts +19 -1
- package/dist/types/skills/loader.d.ts +5 -0
- package/dist/types/tools/enterprise_web_search_tool.d.ts +26 -0
- package/dist/types/tools/example_tool.d.ts +21 -0
- package/dist/types/tools/get_user_choice_tool.d.ts +14 -0
- package/dist/types/tools/load_web_page.d.ts +33 -0
- package/dist/types/tools/mcp/load_mcp_resource_tool.d.ts +26 -0
- package/dist/types/tools/mcp/mcp_toolset.d.ts +27 -0
- package/dist/types/tools/request_input_tool.d.ts +15 -0
- package/dist/types/tools/skill/run_skill_inline_script_tool.d.ts +25 -0
- package/dist/types/tools/skill/skill_toolset.d.ts +9 -0
- package/dist/types/utils/branch_trie.d.ts +14 -0
- package/dist/types/utils/crypto_shim.d.ts +16 -0
- package/dist/types/utils/env_aware_utils.d.ts +23 -0
- package/dist/types/utils/error_utils.d.ts +18 -0
- package/dist/types/utils/output_schema_utils.d.ts +18 -0
- package/dist/types/utils/vertex_ai_utils.d.ts +1 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_remote_agent.js +12 -2
- package/dist/web/a2a/agent_to_a2a.js +18 -3
- package/dist/web/a2a/auth.js +37 -0
- package/dist/web/a2a/event_converter_utils.js +47 -18
- package/dist/web/a2a/metadata_converter_utils.js +1 -1
- package/dist/web/agents/base_agent.js +39 -0
- package/dist/web/agents/functions.js +27 -24
- package/dist/web/agents/llm_agent.js +6 -4
- package/dist/web/agents/loop_agent.js +27 -3
- package/dist/web/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/web/agents/processors/content_processor_utils.js +2 -1
- package/dist/web/agents/processors/content_request_processor.js +2 -21
- package/dist/web/agents/processors/instructions_llm_request_processor.js +3 -1
- package/dist/web/agents/routed_agent.js +31 -0
- package/dist/web/agents/run_config.js +8 -3
- package/dist/web/artifacts/in_memory_artifact_service.js +17 -9
- package/dist/web/auth/credential_service/in_memory_credential_service.js +14 -3
- package/dist/web/code_executors/unsafe_local_code_executor.js +22 -11
- package/dist/web/common.js +29 -1
- package/dist/web/context/agent_controlled_context_compactor.js +2 -11
- package/dist/web/context/anchored_context_compactor.js +117 -0
- package/dist/web/context/compaction_utils.js +38 -0
- package/dist/web/context/token_based_context_compactor.js +16 -44
- package/dist/web/events/compacted_event.js +7 -2
- package/dist/web/events/event.js +24 -0
- package/dist/web/index.js +8 -1
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/web/memory/in_memory_memory_service.js +13 -2
- package/dist/web/memory/vertex_ai_memory_bank_service.js +7 -1
- package/dist/web/plugins/base_plugin.js +4 -2
- package/dist/web/plugins/global_instruction_plugin.js +67 -0
- package/dist/web/runner/runner.js +65 -22
- package/dist/web/sessions/base_session_service.js +8 -3
- package/dist/web/sessions/in_memory_session_service.js +8 -8
- package/dist/web/sessions/vertex_ai_session_service.js +24 -11
- package/dist/web/skills/loader.js +40 -6
- package/dist/web/tools/enterprise_web_search_tool.js +55 -0
- package/dist/web/tools/example_tool.js +42 -0
- package/dist/web/tools/get_user_choice_tool.js +25 -0
- package/dist/web/tools/load_web_page.js +221 -0
- package/dist/web/tools/mcp/load_mcp_resource_tool.js +107 -0
- package/dist/web/tools/mcp/mcp_session_manager.js +35 -21
- package/dist/web/tools/mcp/mcp_toolset.js +63 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
- package/dist/web/tools/request_input_tool.js +26 -0
- package/dist/web/tools/skill/run_skill_inline_script_tool.js +51 -4
- package/dist/web/tools/skill/skill_toolset.js +4 -2
- package/dist/web/utils/branch_trie.js +13 -0
- package/dist/web/utils/crypto_shim.js +15 -0
- package/dist/web/utils/env_aware_utils.js +15 -13
- package/dist/web/utils/error_utils.js +92 -0
- package/dist/web/utils/file_utils.js +5 -2
- package/dist/web/utils/output_schema_utils.js +15 -0
- package/dist/web/utils/streaming_utils.js +1 -1
- package/dist/web/utils/vertex_ai_utils.js +2 -0
- package/dist/web/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,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
|
+
});
|
|
@@ -30,11 +30,16 @@ module.exports = __toCommonJS(mcp_session_manager_exports);
|
|
|
30
30
|
var import_client = require("@modelcontextprotocol/sdk/client/index.js");
|
|
31
31
|
var import_stdio = require("@modelcontextprotocol/sdk/client/stdio.js");
|
|
32
32
|
var import_streamableHttp = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
33
|
+
var import_error_utils = require("../../utils/error_utils.js");
|
|
34
|
+
var import_logger = require("../../utils/logger.js");
|
|
33
35
|
/**
|
|
34
36
|
* @license
|
|
35
37
|
* Copyright 2025 Google LLC
|
|
36
38
|
* SPDX-License-Identifier: Apache-2.0
|
|
37
39
|
*/
|
|
40
|
+
function logTransportError(err) {
|
|
41
|
+
import_logger.logger.error("MCP transport error: " + (0, import_error_utils.formatError)(err));
|
|
42
|
+
}
|
|
38
43
|
class MCPSessionManager {
|
|
39
44
|
constructor(connectionParams) {
|
|
40
45
|
this.activeSessions = /* @__PURE__ */ new Set();
|
|
@@ -43,31 +48,40 @@ class MCPSessionManager {
|
|
|
43
48
|
async createSession() {
|
|
44
49
|
var _a;
|
|
45
50
|
const client = new import_client.Client({ name: "MCPClient", version: "1.0.0" });
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
new import_stdio.StdioClientTransport(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
options.requestInit = {
|
|
56
|
-
headers: this.connectionParams.header
|
|
57
|
-
};
|
|
51
|
+
try {
|
|
52
|
+
switch (this.connectionParams.type) {
|
|
53
|
+
case "StdioConnectionParams": {
|
|
54
|
+
const transport = new import_stdio.StdioClientTransport(
|
|
55
|
+
this.connectionParams.serverParams
|
|
56
|
+
);
|
|
57
|
+
transport.onerror = logTransportError;
|
|
58
|
+
await client.connect(transport);
|
|
59
|
+
break;
|
|
58
60
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
case "StreamableHTTPConnectionParams": {
|
|
62
|
+
const options = (_a = this.connectionParams.transportOptions) != null ? _a : {};
|
|
63
|
+
if (!options.requestInit && this.connectionParams.header !== void 0) {
|
|
64
|
+
options.requestInit = {
|
|
65
|
+
headers: this.connectionParams.header
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const transport = new import_streamableHttp.StreamableHTTPClientTransport(
|
|
61
69
|
new URL(this.connectionParams.url),
|
|
62
70
|
options
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
);
|
|
72
|
+
transport.onerror = logTransportError;
|
|
73
|
+
await client.connect(transport);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
default: {
|
|
77
|
+
const _exhaustiveCheck = this.connectionParams;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
70
80
|
}
|
|
81
|
+
} catch (err) {
|
|
82
|
+
throw new Error("Failed to create MCP session: " + (0, import_error_utils.formatError)(err), {
|
|
83
|
+
cause: err
|
|
84
|
+
});
|
|
71
85
|
}
|
|
72
86
|
this.activeSessions.add(client);
|
|
73
87
|
return client;
|
|
@@ -75,6 +75,69 @@ class MCPToolset extends import_base_toolset.BaseToolset {
|
|
|
75
75
|
);
|
|
76
76
|
return tools;
|
|
77
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Lists the names of the resources advertised by the MCP server.
|
|
80
|
+
*
|
|
81
|
+
* @return The resource names available on the server.
|
|
82
|
+
*/
|
|
83
|
+
async listResources() {
|
|
84
|
+
const session = await this.mcpSessionManager.createSession();
|
|
85
|
+
try {
|
|
86
|
+
const result = await session.listResources();
|
|
87
|
+
return result.resources.map((resource) => resource.name);
|
|
88
|
+
} finally {
|
|
89
|
+
await this.mcpSessionManager.closeSession(session);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Returns metadata for the resource whose name matches `name`.
|
|
94
|
+
*
|
|
95
|
+
* @param name The advertised name of the resource.
|
|
96
|
+
* @return The matching MCP `Resource`.
|
|
97
|
+
* @throws If no resource with the given name is advertised by the server.
|
|
98
|
+
*/
|
|
99
|
+
async getResourceInfo(name) {
|
|
100
|
+
const session = await this.mcpSessionManager.createSession();
|
|
101
|
+
let result;
|
|
102
|
+
try {
|
|
103
|
+
result = await session.listResources();
|
|
104
|
+
} finally {
|
|
105
|
+
await this.mcpSessionManager.closeSession(session);
|
|
106
|
+
}
|
|
107
|
+
const resource = result.resources.find(
|
|
108
|
+
(candidate) => candidate.name === name
|
|
109
|
+
);
|
|
110
|
+
if (!resource) {
|
|
111
|
+
throw new Error(`Resource with name '${name}' not found.`);
|
|
112
|
+
}
|
|
113
|
+
return resource;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Reads the contents of the named resource from the MCP server.
|
|
117
|
+
*
|
|
118
|
+
* The resource name is resolved to a URI via {@link getResourceInfo} before
|
|
119
|
+
* reading. Binary contents are returned base64-encoded, exactly as provided
|
|
120
|
+
* by the server (never decoded and re-encoded).
|
|
121
|
+
*
|
|
122
|
+
* @param name The advertised name of the resource to read.
|
|
123
|
+
* @return The resource contents (text and/or base64-encoded binary).
|
|
124
|
+
* @throws If the resource is unknown or has no URI.
|
|
125
|
+
*/
|
|
126
|
+
async readResource(name) {
|
|
127
|
+
const resourceInfo = await this.getResourceInfo(name);
|
|
128
|
+
if (!resourceInfo.uri) {
|
|
129
|
+
throw new Error(`Resource '${name}' has no URI.`);
|
|
130
|
+
}
|
|
131
|
+
const session = await this.mcpSessionManager.createSession();
|
|
132
|
+
try {
|
|
133
|
+
const result = await session.readResource({
|
|
134
|
+
uri: resourceInfo.uri
|
|
135
|
+
});
|
|
136
|
+
return result.contents;
|
|
137
|
+
} finally {
|
|
138
|
+
await this.mcpSessionManager.closeSession(session);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
78
141
|
async close() {
|
|
79
142
|
const sessions = this.mcpSessionManager.getActiveSessions();
|
|
80
143
|
await Promise.allSettled(
|
|
@@ -87,19 +87,22 @@ let ToolAuthHandler = class {
|
|
|
87
87
|
rawAuthCredential: this.authCredential,
|
|
88
88
|
credentialKey: this.credentialKey || "default_openapi_key"
|
|
89
89
|
};
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
90
|
+
const authResponseCredential = this.context.getAuthResponse(authConfig);
|
|
91
|
+
const credential = authResponseCredential != null ? authResponseCredential : this.authCredential;
|
|
92
|
+
if (!credential) {
|
|
93
|
+
this.context.requestCredential(authConfig);
|
|
94
|
+
return { state: "pending" };
|
|
95
|
+
}
|
|
96
|
+
const exchanger = new import_auto_auth_credential_exchanger.AutoAuthCredentialExchanger();
|
|
97
|
+
const result = await exchanger.exchange({
|
|
98
|
+
authScheme: this.authScheme,
|
|
99
|
+
authCredential: credential
|
|
100
|
+
});
|
|
101
|
+
if (authResponseCredential || result.wasExchanged) {
|
|
97
102
|
const key = store.getCredentialKey(this.authScheme);
|
|
98
103
|
store.storeCredential(key, result.credential);
|
|
99
|
-
return { state: "done", authCredential: result.credential };
|
|
100
104
|
}
|
|
101
|
-
|
|
102
|
-
return { state: "pending" };
|
|
105
|
+
return { state: "done", authCredential: result.credential };
|
|
103
106
|
}
|
|
104
107
|
};
|
|
105
108
|
__decorateClass([
|
|
@@ -0,0 +1,54 @@
|
|
|
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 request_input_tool_exports = {};
|
|
26
|
+
__export(request_input_tool_exports, {
|
|
27
|
+
requestInputTool: () => requestInputTool
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(request_input_tool_exports);
|
|
30
|
+
var import_zod = require("zod");
|
|
31
|
+
var import_long_running_tool = require("./long_running_tool.js");
|
|
32
|
+
/**
|
|
33
|
+
* @license
|
|
34
|
+
* Copyright 2026 Google LLC
|
|
35
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
36
|
+
*/
|
|
37
|
+
const requestInputTool = new import_long_running_tool.LongRunningFunctionTool({
|
|
38
|
+
name: "adk_request_input",
|
|
39
|
+
description: "Presents a custom message to the user and awaits unstructured or structured input.",
|
|
40
|
+
parameters: import_zod.z.object({
|
|
41
|
+
message: import_zod.z.string().describe("The prompt for the user."),
|
|
42
|
+
responseSchema: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional().describe("Expected schema of the response.")
|
|
43
|
+
}),
|
|
44
|
+
execute: async (input, context) => {
|
|
45
|
+
if (context) {
|
|
46
|
+
context.actions.skipSummarization = true;
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {
|
|
53
|
+
requestInputTool
|
|
54
|
+
});
|
|
@@ -32,6 +32,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
32
32
|
};
|
|
33
33
|
var run_skill_inline_script_tool_exports = {};
|
|
34
34
|
__export(run_skill_inline_script_tool_exports, {
|
|
35
|
+
RunSkillInlineScriptErrorCode: () => RunSkillInlineScriptErrorCode,
|
|
35
36
|
RunSkillInlineScriptTool: () => RunSkillInlineScriptTool
|
|
36
37
|
});
|
|
37
38
|
module.exports = __toCommonJS(run_skill_inline_script_tool_exports);
|
|
@@ -46,6 +47,15 @@ var import_base_tool = require("../base_tool.js");
|
|
|
46
47
|
* Copyright 2026 Google LLC
|
|
47
48
|
* SPDX-License-Identifier: Apache-2.0
|
|
48
49
|
*/
|
|
50
|
+
var RunSkillInlineScriptErrorCode = /* @__PURE__ */ ((RunSkillInlineScriptErrorCode2) => {
|
|
51
|
+
RunSkillInlineScriptErrorCode2["MISSING_SCRIPT_CONTENT"] = "MISSING_SCRIPT_CONTENT";
|
|
52
|
+
RunSkillInlineScriptErrorCode2["MISSING_LANGUAGE"] = "MISSING_LANGUAGE";
|
|
53
|
+
RunSkillInlineScriptErrorCode2["NO_CODE_EXECUTOR"] = "NO_CODE_EXECUTOR";
|
|
54
|
+
RunSkillInlineScriptErrorCode2["EXECUTION_ERROR"] = "EXECUTION_ERROR";
|
|
55
|
+
RunSkillInlineScriptErrorCode2["CONFIRMATION_REJECTED"] = "CONFIRMATION_REJECTED";
|
|
56
|
+
return RunSkillInlineScriptErrorCode2;
|
|
57
|
+
})(RunSkillInlineScriptErrorCode || {});
|
|
58
|
+
const REQUIRE_CONFIRMATION_MESSAGE = "This tool call needs external confirmation before completion.";
|
|
49
59
|
let RunSkillInlineScriptTool = class extends import_base_tool.BaseTool {
|
|
50
60
|
constructor(toolset) {
|
|
51
61
|
super({
|
|
@@ -95,13 +105,13 @@ let RunSkillInlineScriptTool = class extends import_base_tool.BaseTool {
|
|
|
95
105
|
if (!inlineScriptContent) {
|
|
96
106
|
return {
|
|
97
107
|
error: "Script content is required.",
|
|
98
|
-
errorCode: "MISSING_SCRIPT_CONTENT"
|
|
108
|
+
errorCode: "MISSING_SCRIPT_CONTENT" /* MISSING_SCRIPT_CONTENT */
|
|
99
109
|
};
|
|
100
110
|
}
|
|
101
111
|
if (!language) {
|
|
102
112
|
return {
|
|
103
113
|
error: "Language is required.",
|
|
104
|
-
errorCode: "MISSING_LANGUAGE"
|
|
114
|
+
errorCode: "MISSING_LANGUAGE" /* MISSING_LANGUAGE */
|
|
105
115
|
};
|
|
106
116
|
}
|
|
107
117
|
let codeExecutor = (_a = this.toolset) == null ? void 0 : _a.codeExecutor;
|
|
@@ -114,9 +124,17 @@ let RunSkillInlineScriptTool = class extends import_base_tool.BaseTool {
|
|
|
114
124
|
if (!codeExecutor) {
|
|
115
125
|
return {
|
|
116
126
|
error: "No code executor configured.",
|
|
117
|
-
errorCode: "NO_CODE_EXECUTOR"
|
|
127
|
+
errorCode: "NO_CODE_EXECUTOR" /* NO_CODE_EXECUTOR */
|
|
118
128
|
};
|
|
119
129
|
}
|
|
130
|
+
const confirmationResult = this.enforceConfirmation(
|
|
131
|
+
toolContext,
|
|
132
|
+
inlineScriptContent,
|
|
133
|
+
language
|
|
134
|
+
);
|
|
135
|
+
if (confirmationResult) {
|
|
136
|
+
return confirmationResult;
|
|
137
|
+
}
|
|
120
138
|
try {
|
|
121
139
|
const result = await codeExecutor.executeCode({
|
|
122
140
|
invocationContext: toolContext.invocationContext,
|
|
@@ -132,9 +150,40 @@ let RunSkillInlineScriptTool = class extends import_base_tool.BaseTool {
|
|
|
132
150
|
} catch (e) {
|
|
133
151
|
return {
|
|
134
152
|
error: `Failed to execute inline script: ${e.message}`,
|
|
135
|
-
errorCode: "EXECUTION_ERROR"
|
|
153
|
+
errorCode: "EXECUTION_ERROR" /* EXECUTION_ERROR */
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Enforces a human-in-the-loop confirmation gate before executing an inline
|
|
159
|
+
* script, using the repo's standard tool-confirmation mechanism.
|
|
160
|
+
*
|
|
161
|
+
* - When no confirmation has been provided yet, a confirmation is requested
|
|
162
|
+
* (surfacing the language and script that would run) and an intermediate
|
|
163
|
+
* result is returned so the tool call pauses until the client responds.
|
|
164
|
+
* - When a confirmation exists but was not confirmed, a rejection error is
|
|
165
|
+
* returned and execution is refused.
|
|
166
|
+
* - When the confirmation is confirmed, `undefined` is returned to allow the
|
|
167
|
+
* caller to proceed with execution.
|
|
168
|
+
*/
|
|
169
|
+
enforceConfirmation(toolContext, scriptContent, language) {
|
|
170
|
+
const confirmation = toolContext.toolConfirmation;
|
|
171
|
+
if (!confirmation) {
|
|
172
|
+
toolContext.requestConfirmation({
|
|
173
|
+
hint: `Confirmation is required before executing an inline skill script. The agent requested to run the following ${language} script in the code executor. Only approve if you trust its contents:
|
|
174
|
+
|
|
175
|
+
` + scriptContent,
|
|
176
|
+
payload: { language, scriptContent }
|
|
177
|
+
});
|
|
178
|
+
return { partial: REQUIRE_CONFIRMATION_MESSAGE };
|
|
179
|
+
}
|
|
180
|
+
if (!confirmation.confirmed) {
|
|
181
|
+
return {
|
|
182
|
+
error: "Inline script execution was not confirmed and was rejected.",
|
|
183
|
+
errorCode: "CONFIRMATION_REJECTED" /* CONFIRMATION_REJECTED */
|
|
136
184
|
};
|
|
137
185
|
}
|
|
186
|
+
return void 0;
|
|
138
187
|
}
|
|
139
188
|
};
|
|
140
189
|
RunSkillInlineScriptTool = __decorateClass([
|
|
@@ -142,5 +191,6 @@ RunSkillInlineScriptTool = __decorateClass([
|
|
|
142
191
|
], RunSkillInlineScriptTool);
|
|
143
192
|
// Annotate the CommonJS export names for ESM import in node:
|
|
144
193
|
0 && (module.exports = {
|
|
194
|
+
RunSkillInlineScriptErrorCode,
|
|
145
195
|
RunSkillInlineScriptTool
|
|
146
196
|
});
|
|
@@ -80,9 +80,11 @@ let SkillToolset = class extends import_base_toolset.BaseToolset {
|
|
|
80
80
|
new import_list_skills_tool.ListSkillsTool(this),
|
|
81
81
|
new import_load_skill_tool.LoadSkillTool(this),
|
|
82
82
|
new import_load_skill_resource_tool.LoadSkillResourceTool(this),
|
|
83
|
-
new import_run_skill_script_tool.RunSkillScriptTool(this)
|
|
84
|
-
new import_run_skill_inline_script_tool.RunSkillInlineScriptTool(this)
|
|
83
|
+
new import_run_skill_script_tool.RunSkillScriptTool(this)
|
|
85
84
|
];
|
|
85
|
+
if (options.allowInlineScripts) {
|
|
86
|
+
this.tools.push(new import_run_skill_inline_script_tool.RunSkillInlineScriptTool(this));
|
|
87
|
+
}
|
|
86
88
|
if (this.registry) {
|
|
87
89
|
this.tools.push(new import_search_skills_tool.SearchSkillsTool(this));
|
|
88
90
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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 branch_trie_exports = {};
|
|
26
|
+
__export(branch_trie_exports, {
|
|
27
|
+
isSegmentPrefix: () => isSegmentPrefix
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(branch_trie_exports);
|
|
30
|
+
/**
|
|
31
|
+
* @license
|
|
32
|
+
* Copyright 2026 Google LLC
|
|
33
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
34
|
+
*/
|
|
35
|
+
function isSegmentPrefix(currentBranch, targetBranch) {
|
|
36
|
+
return !targetBranch || targetBranch === currentBranch || !!currentBranch && currentBranch.startsWith(`${targetBranch}.`);
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
isSegmentPrefix
|
|
41
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var crypto_shim_exports = {};
|
|
26
|
+
__export(crypto_shim_exports, {
|
|
27
|
+
randomUUID: () => randomUUID
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(crypto_shim_exports);
|
|
30
|
+
/**
|
|
31
|
+
* @license
|
|
32
|
+
* Copyright 2026 Google LLC
|
|
33
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
34
|
+
*/
|
|
35
|
+
function randomUUID() {
|
|
36
|
+
throw new Error(
|
|
37
|
+
"randomUUID: no cryptographically secure source of randomness is available. Neither crypto.randomUUID() nor crypto.getRandomValues() is present in this environment."
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
randomUUID
|
|
43
|
+
});
|
|
@@ -32,6 +32,7 @@ __export(env_aware_utils_exports, {
|
|
|
32
32
|
randomUUID: () => randomUUID
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(env_aware_utils_exports);
|
|
35
|
+
var import_node_crypto = require("node:crypto");
|
|
35
36
|
/**
|
|
36
37
|
* @license
|
|
37
38
|
* Copyright 2025 Google LLC
|
|
@@ -40,24 +41,25 @@ module.exports = __toCommonJS(env_aware_utils_exports);
|
|
|
40
41
|
function isBrowser() {
|
|
41
42
|
return typeof window !== "undefined";
|
|
42
43
|
}
|
|
43
|
-
const UUID_MASK = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
|
|
44
44
|
function randomUUID() {
|
|
45
|
-
var _a;
|
|
45
|
+
var _a, _b;
|
|
46
46
|
if ((_a = globalThis.crypto) == null ? void 0 : _a.randomUUID) {
|
|
47
47
|
return globalThis.crypto.randomUUID();
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
if ((_b = globalThis.crypto) == null ? void 0 : _b.getRandomValues) {
|
|
50
|
+
const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16));
|
|
51
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
52
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
53
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
|
|
54
|
+
return [
|
|
55
|
+
hex.slice(0, 4),
|
|
56
|
+
hex.slice(4, 6),
|
|
57
|
+
hex.slice(6, 8),
|
|
58
|
+
hex.slice(8, 10),
|
|
59
|
+
hex.slice(10, 16)
|
|
60
|
+
].map((group) => group.join("")).join("-");
|
|
59
61
|
}
|
|
60
|
-
return
|
|
62
|
+
return (0, import_node_crypto.randomUUID)();
|
|
61
63
|
}
|
|
62
64
|
function base64Encode(data) {
|
|
63
65
|
if (isBrowser()) {
|