@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,63 @@
|
|
|
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 interactions_request_processor_exports = {};
|
|
26
|
+
__export(interactions_request_processor_exports, {
|
|
27
|
+
INTERACTIONS_REQUEST_PROCESSOR: () => INTERACTIONS_REQUEST_PROCESSOR,
|
|
28
|
+
InteractionsRequestProcessor: () => InteractionsRequestProcessor
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(interactions_request_processor_exports);
|
|
31
|
+
var import_google_llm = require("../../models/google_llm.js");
|
|
32
|
+
var import_llm_agent = require("../llm_agent.js");
|
|
33
|
+
/**
|
|
34
|
+
* @license
|
|
35
|
+
* Copyright 2026 Google LLC
|
|
36
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
37
|
+
*/
|
|
38
|
+
class InteractionsRequestProcessor {
|
|
39
|
+
// eslint-disable-next-line require-yield
|
|
40
|
+
async *runAsync(invocationContext, llmRequest) {
|
|
41
|
+
const agent = invocationContext.agent;
|
|
42
|
+
if (!agent || !(0, import_llm_agent.isLlmAgent)(agent)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const model = agent.canonicalModel;
|
|
46
|
+
if ((0, import_google_llm.isGemini)(model) && model.useInteractionsApi) {
|
|
47
|
+
const events = invocationContext.session.events;
|
|
48
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
49
|
+
const event = events[i];
|
|
50
|
+
if (event.branch === invocationContext.branch && event.author === agent.name && event.interactionId) {
|
|
51
|
+
llmRequest.previousInteractionId = event.interactionId;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const INTERACTIONS_REQUEST_PROCESSOR = new InteractionsRequestProcessor();
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
INTERACTIONS_REQUEST_PROCESSOR,
|
|
62
|
+
InteractionsRequestProcessor
|
|
63
|
+
});
|
|
@@ -64,6 +64,29 @@ let RoutedAgent = class extends (_b = import_base_agent.BaseAgent, _a = ROUTED_A
|
|
|
64
64
|
}
|
|
65
65
|
this.router = config.router;
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Creates a detached copy of this routed agent.
|
|
69
|
+
*
|
|
70
|
+
* The inherited {@link BaseAgent.clone} only deep-clones `subAgents`, but a
|
|
71
|
+
* `RoutedAgent` derives its routing targets from `config.agents`. Rebuilding
|
|
72
|
+
* through the base clone alone would re-read the already-parented original
|
|
73
|
+
* agents and throw "already has a parent agent". This override deep-clones the
|
|
74
|
+
* routing targets (unless the caller overrides `agents`) so the rebuilt
|
|
75
|
+
* constructor re-parents fresh, detached copies. The array-vs-record shape
|
|
76
|
+
* and, for records, the keys are preserved so the router keeps selecting the
|
|
77
|
+
* same targets.
|
|
78
|
+
*
|
|
79
|
+
* @param overrides Config fields to override on the clone. Overriding
|
|
80
|
+
* `parentAgent` is rejected by the base implementation.
|
|
81
|
+
* @returns A new detached `RoutedAgent` of the same concrete class.
|
|
82
|
+
*/
|
|
83
|
+
clone(overrides) {
|
|
84
|
+
const nextOverrides = { ...overrides };
|
|
85
|
+
if (!("agents" in nextOverrides)) {
|
|
86
|
+
nextOverrides.agents = cloneRoutingTargets(this.config.agents);
|
|
87
|
+
}
|
|
88
|
+
return super.clone(nextOverrides);
|
|
89
|
+
}
|
|
67
90
|
/**
|
|
68
91
|
* Runs the selected agent via text-based conversation.
|
|
69
92
|
*/
|
|
@@ -90,6 +113,14 @@ let RoutedAgent = class extends (_b = import_base_agent.BaseAgent, _a = ROUTED_A
|
|
|
90
113
|
RoutedAgent = __decorateClass([
|
|
91
114
|
import_experimental.experimental
|
|
92
115
|
], RoutedAgent);
|
|
116
|
+
function cloneRoutingTargets(agents) {
|
|
117
|
+
if (Array.isArray(agents)) {
|
|
118
|
+
return agents.map((agent) => agent.clone());
|
|
119
|
+
}
|
|
120
|
+
return Object.fromEntries(
|
|
121
|
+
Object.entries(agents).map(([key, agent]) => [key, agent.clone()])
|
|
122
|
+
);
|
|
123
|
+
}
|
|
93
124
|
// Annotate the CommonJS export names for ESM import in node:
|
|
94
125
|
0 && (module.exports = {
|
|
95
126
|
RoutedAgent,
|
|
@@ -41,14 +41,15 @@ var StreamingMode = /* @__PURE__ */ ((StreamingMode2) => {
|
|
|
41
41
|
return StreamingMode2;
|
|
42
42
|
})(StreamingMode || {});
|
|
43
43
|
function createRunConfig(params = {}) {
|
|
44
|
+
var _a;
|
|
44
45
|
return {
|
|
45
46
|
saveInputBlobsAsArtifacts: false,
|
|
46
47
|
supportCfc: false,
|
|
47
48
|
enableAffectiveDialog: false,
|
|
48
49
|
streamingMode: "none" /* NONE */,
|
|
49
|
-
maxLlmCalls: validateMaxLlmCalls(params.maxLlmCalls || 500),
|
|
50
50
|
pauseOnToolCalls: false,
|
|
51
|
-
...params
|
|
51
|
+
...params,
|
|
52
|
+
maxLlmCalls: validateMaxLlmCalls((_a = params.maxLlmCalls) != null ? _a : 500)
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
55
|
function validateMaxLlmCalls(value) {
|
|
@@ -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 app_exports = {};
|
|
26
|
+
__export(app_exports, {
|
|
27
|
+
App: () => App,
|
|
28
|
+
isApp: () => isApp,
|
|
29
|
+
validateAppName: () => validateAppName
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(app_exports);
|
|
32
|
+
var import_base_agent = require("../agents/base_agent.js");
|
|
33
|
+
/**
|
|
34
|
+
* @license
|
|
35
|
+
* Copyright 2026 Google LLC
|
|
36
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
37
|
+
*/
|
|
38
|
+
var _a;
|
|
39
|
+
const VALID_APP_NAME_RE = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
|
|
40
|
+
function validateAppName(name) {
|
|
41
|
+
if (!VALID_APP_NAME_RE.test(name)) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Invalid app name '${name}': must start with a letter and can only consist of letters, digits, underscores, and hyphens.`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
if (name === "user") {
|
|
47
|
+
throw new Error("App name cannot be 'user'; reserved for end-user input.");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const APP_SIGNATURE_SYMBOL = Symbol.for("google.adk.app");
|
|
51
|
+
function isApp(obj) {
|
|
52
|
+
return typeof obj === "object" && obj !== null && APP_SIGNATURE_SYMBOL in obj && obj[APP_SIGNATURE_SYMBOL] === true;
|
|
53
|
+
}
|
|
54
|
+
_a = APP_SIGNATURE_SYMBOL;
|
|
55
|
+
class App {
|
|
56
|
+
constructor(options) {
|
|
57
|
+
this[_a] = true;
|
|
58
|
+
var _a2, _b, _c, _d;
|
|
59
|
+
validateAppName(options.name);
|
|
60
|
+
if (options.rootAgent === void 0 || options.rootAgent === null) {
|
|
61
|
+
throw new Error("rootAgent must be provided.");
|
|
62
|
+
}
|
|
63
|
+
if (!(0, import_base_agent.isBaseAgent)(options.rootAgent)) {
|
|
64
|
+
throw new TypeError(
|
|
65
|
+
`rootAgent must be a BaseAgent instance, got ${(_c = (_b = (_a2 = options.rootAgent) == null ? void 0 : _a2.constructor) == null ? void 0 : _b.name) != null ? _c : typeof options.rootAgent}`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
this.name = options.name;
|
|
69
|
+
this.rootAgent = options.rootAgent;
|
|
70
|
+
this.plugins = (_d = options.plugins) != null ? _d : [];
|
|
71
|
+
this.resumabilityConfig = options.resumabilityConfig;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
App,
|
|
77
|
+
isApp,
|
|
78
|
+
validateAppName
|
|
79
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
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 resumability_config_exports = {};
|
|
26
|
+
__export(resumability_config_exports, {
|
|
27
|
+
createResumabilityConfig: () => createResumabilityConfig
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(resumability_config_exports);
|
|
30
|
+
/**
|
|
31
|
+
* @license
|
|
32
|
+
* Copyright 2026 Google LLC
|
|
33
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
34
|
+
*/
|
|
35
|
+
function createResumabilityConfig(params = {}) {
|
|
36
|
+
return {
|
|
37
|
+
isResumable: false,
|
|
38
|
+
...params
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
createResumabilityConfig
|
|
44
|
+
});
|
|
@@ -67,7 +67,7 @@ class FileArtifactService {
|
|
|
67
67
|
artifact,
|
|
68
68
|
customMetadata
|
|
69
69
|
}) {
|
|
70
|
-
if (!artifact.inlineData && !artifact.text) {
|
|
70
|
+
if (!artifact.inlineData && !artifact.text && !artifact.fileData) {
|
|
71
71
|
throw new Error("Artifact must have either inlineData or text content.");
|
|
72
72
|
}
|
|
73
73
|
const artifactDir = getArtifactDir(
|
|
@@ -85,12 +85,19 @@ class FileArtifactService {
|
|
|
85
85
|
const storedFilename = path.basename(artifactDir);
|
|
86
86
|
const contentPath = path.join(versionDir, storedFilename);
|
|
87
87
|
let mimeType;
|
|
88
|
+
let fileUri;
|
|
88
89
|
if (artifact.inlineData) {
|
|
89
90
|
const data = artifact.inlineData.data || "";
|
|
90
91
|
await fs.writeFile(contentPath, Buffer.from(data, "base64"));
|
|
91
92
|
mimeType = artifact.inlineData.mimeType || "application/octet-stream";
|
|
92
93
|
} else if (artifact.text !== void 0) {
|
|
93
94
|
await fs.writeFile(contentPath, artifact.text, "utf-8");
|
|
95
|
+
} else {
|
|
96
|
+
fileUri = artifact.fileData.fileUri;
|
|
97
|
+
if (!fileUri) {
|
|
98
|
+
throw new Error("Artifact fileData must have a fileUri.");
|
|
99
|
+
}
|
|
100
|
+
mimeType = artifact.fileData.mimeType;
|
|
94
101
|
}
|
|
95
102
|
const canonicalUri = await getCanonicalUri(
|
|
96
103
|
this.rootDir,
|
|
@@ -102,6 +109,7 @@ class FileArtifactService {
|
|
|
102
109
|
const metadata = {
|
|
103
110
|
fileName: filename,
|
|
104
111
|
mimeType,
|
|
112
|
+
fileUri,
|
|
105
113
|
version: nextVersion,
|
|
106
114
|
canonicalUri,
|
|
107
115
|
customMetadata
|
|
@@ -153,6 +161,11 @@ class FileArtifactService {
|
|
|
153
161
|
);
|
|
154
162
|
const metadataPath = path.join(versionDir, "metadata.json");
|
|
155
163
|
const metadata = await readMetadata(metadataPath);
|
|
164
|
+
if (metadata.fileUri) {
|
|
165
|
+
return {
|
|
166
|
+
fileData: { fileUri: metadata.fileUri, mimeType: metadata.mimeType }
|
|
167
|
+
};
|
|
168
|
+
}
|
|
156
169
|
const storedFilename = path.basename(artifactDir);
|
|
157
170
|
let contentPath = path.join(versionDir, storedFilename);
|
|
158
171
|
if (metadata.canonicalUri) {
|
|
@@ -35,12 +35,16 @@ var import_logger = require("../utils/logger.js");
|
|
|
35
35
|
* Copyright 2025 Google LLC
|
|
36
36
|
* SPDX-License-Identifier: Apache-2.0
|
|
37
37
|
*/
|
|
38
|
+
const GCS_FILE_URI_METADATA_KEY = "adkFileUri";
|
|
39
|
+
const GCS_FILE_MIME_TYPE_METADATA_KEY = "adkFileMimeType";
|
|
40
|
+
const GCS_DISPLAY_NAME_METADATA_KEY = "adkDisplayName";
|
|
41
|
+
const GCS_IS_TEXT_METADATA_KEY = "adkIsText";
|
|
38
42
|
class GcsArtifactService {
|
|
39
|
-
constructor(bucket) {
|
|
40
|
-
this.bucket = new import_storage.Storage().bucket(bucket);
|
|
43
|
+
constructor(bucket, options) {
|
|
44
|
+
this.bucket = new import_storage.Storage(options).bucket(bucket);
|
|
41
45
|
}
|
|
42
46
|
async saveArtifact(request) {
|
|
43
|
-
if (!request.artifact.inlineData && !request.artifact.text) {
|
|
47
|
+
if (!request.artifact.inlineData && !request.artifact.text && !request.artifact.fileData) {
|
|
44
48
|
throw new Error("Artifact must have either inlineData or text content.");
|
|
45
49
|
}
|
|
46
50
|
const versions = await this.listVersions(request);
|
|
@@ -51,24 +55,48 @@ class GcsArtifactService {
|
|
|
51
55
|
version
|
|
52
56
|
})
|
|
53
57
|
);
|
|
54
|
-
const
|
|
58
|
+
const customMetadata = {
|
|
59
|
+
...request.customMetadata
|
|
60
|
+
};
|
|
55
61
|
if (request.artifact.inlineData) {
|
|
62
|
+
if (request.artifact.inlineData.displayName) {
|
|
63
|
+
customMetadata[GCS_DISPLAY_NAME_METADATA_KEY] = request.artifact.inlineData.displayName;
|
|
64
|
+
}
|
|
56
65
|
await file.save(
|
|
57
66
|
Buffer.from(request.artifact.inlineData.data || "", "base64"),
|
|
58
67
|
{
|
|
59
68
|
contentType: request.artifact.inlineData.mimeType,
|
|
60
|
-
metadata
|
|
69
|
+
metadata: { metadata: customMetadata }
|
|
61
70
|
}
|
|
62
71
|
);
|
|
63
72
|
return version;
|
|
73
|
+
} else if (request.artifact.text !== void 0) {
|
|
74
|
+
await file.save(request.artifact.text, {
|
|
75
|
+
contentType: "text/plain",
|
|
76
|
+
metadata: {
|
|
77
|
+
metadata: { ...customMetadata, [GCS_IS_TEXT_METADATA_KEY]: "true" }
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return version;
|
|
81
|
+
} else {
|
|
82
|
+
const fileData = request.artifact.fileData;
|
|
83
|
+
const fileUri = fileData == null ? void 0 : fileData.fileUri;
|
|
84
|
+
if (!fileUri) {
|
|
85
|
+
throw new Error("Artifact fileData must have a fileUri.");
|
|
86
|
+
}
|
|
87
|
+
customMetadata[GCS_FILE_URI_METADATA_KEY] = fileUri;
|
|
88
|
+
if (fileData.mimeType) {
|
|
89
|
+
customMetadata[GCS_FILE_MIME_TYPE_METADATA_KEY] = fileData.mimeType;
|
|
90
|
+
}
|
|
91
|
+
await file.save("", {
|
|
92
|
+
contentType: fileData.mimeType || void 0,
|
|
93
|
+
metadata: { metadata: customMetadata }
|
|
94
|
+
});
|
|
95
|
+
return version;
|
|
64
96
|
}
|
|
65
|
-
await file.save(request.artifact.text, {
|
|
66
|
-
contentType: "text/plain",
|
|
67
|
-
metadata
|
|
68
|
-
});
|
|
69
|
-
return version;
|
|
70
97
|
}
|
|
71
98
|
async loadArtifact(request) {
|
|
99
|
+
var _a, _b, _c;
|
|
72
100
|
try {
|
|
73
101
|
let version = request.version;
|
|
74
102
|
if (version === void 0) {
|
|
@@ -84,11 +112,25 @@ class GcsArtifactService {
|
|
|
84
112
|
version
|
|
85
113
|
})
|
|
86
114
|
);
|
|
87
|
-
const [
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
115
|
+
const [metadata] = await file.getMetadata();
|
|
116
|
+
const customMeta = (_a = metadata.metadata) != null ? _a : {};
|
|
117
|
+
const fileUri = customMeta[GCS_FILE_URI_METADATA_KEY];
|
|
118
|
+
if (fileUri) {
|
|
119
|
+
const mimeType = (_c = (_b = customMeta[GCS_FILE_MIME_TYPE_METADATA_KEY]) != null ? _b : metadata.contentType) != null ? _c : void 0;
|
|
120
|
+
return { fileData: { fileUri, mimeType } };
|
|
121
|
+
}
|
|
122
|
+
const [rawDataBuffer] = await file.download();
|
|
123
|
+
const displayName = customMeta[GCS_DISPLAY_NAME_METADATA_KEY];
|
|
124
|
+
if (displayName) {
|
|
125
|
+
return {
|
|
126
|
+
inlineData: {
|
|
127
|
+
data: rawDataBuffer.toString("base64"),
|
|
128
|
+
mimeType: metadata.contentType,
|
|
129
|
+
displayName
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
if (customMeta[GCS_IS_TEXT_METADATA_KEY] === "true" || metadata.contentType === "text/plain") {
|
|
92
134
|
return (0, import_genai.createPartFromText)(rawDataBuffer.toString("utf-8"));
|
|
93
135
|
}
|
|
94
136
|
return (0, import_genai.createPartFromBase64)(
|
|
@@ -28,6 +28,7 @@ __export(in_memory_artifact_service_exports, {
|
|
|
28
28
|
isInMemoryConnectionString: () => isInMemoryConnectionString
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(in_memory_artifact_service_exports);
|
|
31
|
+
var import_logger = require("../utils/logger.js");
|
|
31
32
|
/**
|
|
32
33
|
* @license
|
|
33
34
|
* Copyright 2025 Google LLC
|
|
@@ -48,7 +49,7 @@ class InMemoryArtifactService {
|
|
|
48
49
|
artifact,
|
|
49
50
|
customMetadata
|
|
50
51
|
}) {
|
|
51
|
-
if (!artifact.inlineData && !artifact.text) {
|
|
52
|
+
if (!artifact.inlineData && !artifact.text && !artifact.fileData) {
|
|
52
53
|
return Promise.reject(
|
|
53
54
|
new Error("Artifact must have either inlineData or text content.")
|
|
54
55
|
);
|
|
@@ -62,6 +63,10 @@ class InMemoryArtifactService {
|
|
|
62
63
|
version,
|
|
63
64
|
customMetadata
|
|
64
65
|
};
|
|
66
|
+
if (!artifact.inlineData && artifact.text === void 0) {
|
|
67
|
+
const fileData = artifact.fileData;
|
|
68
|
+
metadata.mimeType = fileData.mimeType;
|
|
69
|
+
}
|
|
65
70
|
this.artifacts[path].push({ part: artifact, metadata });
|
|
66
71
|
return Promise.resolve(version);
|
|
67
72
|
}
|
|
@@ -80,6 +85,12 @@ class InMemoryArtifactService {
|
|
|
80
85
|
if (version === void 0) {
|
|
81
86
|
version = versions.length - 1;
|
|
82
87
|
}
|
|
88
|
+
if (!versions[version]) {
|
|
89
|
+
import_logger.logger.warn(
|
|
90
|
+
`[InMemoryArtifactService] loadArtifact: Artifact ${filename} version ${version} not found`
|
|
91
|
+
);
|
|
92
|
+
return Promise.resolve(void 0);
|
|
93
|
+
}
|
|
83
94
|
return Promise.resolve(versions[version].part);
|
|
84
95
|
}
|
|
85
96
|
listArtifactKeys({
|
|
@@ -0,0 +1,101 @@
|
|
|
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 scoped_artifact_service_exports = {};
|
|
26
|
+
__export(scoped_artifact_service_exports, {
|
|
27
|
+
ScopedArtifactService: () => ScopedArtifactService
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(scoped_artifact_service_exports);
|
|
30
|
+
/**
|
|
31
|
+
* @license
|
|
32
|
+
* Copyright 2026 Google LLC
|
|
33
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
34
|
+
*/
|
|
35
|
+
class ScopedArtifactService {
|
|
36
|
+
constructor(delegate, appName, userId, sessionId) {
|
|
37
|
+
this.delegate = delegate;
|
|
38
|
+
this.appName = appName;
|
|
39
|
+
this.userId = userId;
|
|
40
|
+
this.sessionId = sessionId;
|
|
41
|
+
}
|
|
42
|
+
async saveArtifact(request) {
|
|
43
|
+
return this.delegate.saveArtifact({
|
|
44
|
+
appName: this.appName,
|
|
45
|
+
userId: this.userId,
|
|
46
|
+
sessionId: this.sessionId,
|
|
47
|
+
...request
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async loadArtifact(request) {
|
|
51
|
+
return this.delegate.loadArtifact({
|
|
52
|
+
appName: this.appName,
|
|
53
|
+
userId: this.userId,
|
|
54
|
+
sessionId: this.sessionId,
|
|
55
|
+
...request
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
async listArtifactKeys() {
|
|
59
|
+
return this.delegate.listArtifactKeys({
|
|
60
|
+
appName: this.appName,
|
|
61
|
+
userId: this.userId,
|
|
62
|
+
sessionId: this.sessionId
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async deleteArtifact(filename) {
|
|
66
|
+
return this.delegate.deleteArtifact({
|
|
67
|
+
appName: this.appName,
|
|
68
|
+
userId: this.userId,
|
|
69
|
+
sessionId: this.sessionId,
|
|
70
|
+
filename
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
async listVersions(filename) {
|
|
74
|
+
return this.delegate.listVersions({
|
|
75
|
+
appName: this.appName,
|
|
76
|
+
userId: this.userId,
|
|
77
|
+
sessionId: this.sessionId,
|
|
78
|
+
filename
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async listArtifactVersions(filename) {
|
|
82
|
+
return this.delegate.listArtifactVersions({
|
|
83
|
+
appName: this.appName,
|
|
84
|
+
userId: this.userId,
|
|
85
|
+
sessionId: this.sessionId,
|
|
86
|
+
filename
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async getArtifactVersion(request) {
|
|
90
|
+
return this.delegate.getArtifactVersion({
|
|
91
|
+
appName: this.appName,
|
|
92
|
+
userId: this.userId,
|
|
93
|
+
sessionId: this.sessionId,
|
|
94
|
+
...request
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
+
0 && (module.exports = {
|
|
100
|
+
ScopedArtifactService
|
|
101
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var session_artifact_service_exports = {};
|
|
22
|
+
module.exports = __toCommonJS(session_artifact_service_exports);
|
|
23
|
+
/**
|
|
24
|
+
* @license
|
|
25
|
+
* Copyright 2026 Google LLC
|
|
26
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
27
|
+
*/
|
|
@@ -26,7 +26,9 @@ var oauth2_discovery_exports = {};
|
|
|
26
26
|
__export(oauth2_discovery_exports, {
|
|
27
27
|
AuthorizationServerMetadataSchema: () => AuthorizationServerMetadataSchema,
|
|
28
28
|
OAuth2DiscoveryManager: () => OAuth2DiscoveryManager,
|
|
29
|
-
ProtectedResourceMetadataSchema: () => ProtectedResourceMetadataSchema
|
|
29
|
+
ProtectedResourceMetadataSchema: () => ProtectedResourceMetadataSchema,
|
|
30
|
+
normaliseHostname: () => normaliseHostname,
|
|
31
|
+
validateDiscoveryUrl: () => validateDiscoveryUrl
|
|
30
32
|
});
|
|
31
33
|
module.exports = __toCommonJS(oauth2_discovery_exports);
|
|
32
34
|
var import_zod = require("zod");
|
|
@@ -84,7 +86,11 @@ class OAuth2DiscoveryManager {
|
|
|
84
86
|
method: "GET",
|
|
85
87
|
headers: {
|
|
86
88
|
Accept: "application/json"
|
|
87
|
-
}
|
|
89
|
+
},
|
|
90
|
+
// Never follow redirects: validateDiscoveryUrl only checks the
|
|
91
|
+
// initial URL, so following a 3xx would let a validated host
|
|
92
|
+
// redirect discovery to a private/cloud-metadata address (CWE-918).
|
|
93
|
+
redirect: "error"
|
|
88
94
|
});
|
|
89
95
|
if (!response.ok) {
|
|
90
96
|
continue;
|
|
@@ -132,7 +138,11 @@ class OAuth2DiscoveryManager {
|
|
|
132
138
|
method: "GET",
|
|
133
139
|
headers: {
|
|
134
140
|
Accept: "application/json"
|
|
135
|
-
}
|
|
141
|
+
},
|
|
142
|
+
// Never follow redirects: validateDiscoveryUrl only checks the
|
|
143
|
+
// initial URL, so following a 3xx would let a validated host
|
|
144
|
+
// redirect discovery to a private/cloud-metadata address (CWE-918).
|
|
145
|
+
redirect: "error"
|
|
136
146
|
});
|
|
137
147
|
if (!response.ok) {
|
|
138
148
|
return void 0;
|
|
@@ -172,7 +182,7 @@ function validateDiscoveryUrl(urlStr) {
|
|
|
172
182
|
return false;
|
|
173
183
|
}
|
|
174
184
|
const host = normaliseHostname(url.hostname.toLowerCase());
|
|
175
|
-
if (host === "localhost" || host === "metadata.google.internal" || host === "metadata.goog" || host.startsWith("127.") || host === "[::1]" || host === "0.0.0.0" || host.startsWith("10.") || host.startsWith("192.168.") || host.startsWith("169.254.")) {
|
|
185
|
+
if (host === "localhost" || host === "metadata.google.internal" || host === "metadata.goog" || host.startsWith("127.") || host === "[::1]" || host === "[::]" || host === "0.0.0.0" || host.startsWith("10.") || host.startsWith("192.168.") || host.startsWith("169.254.")) {
|
|
176
186
|
import_logger.logger.warn(`Unsafe host for discovery URL: ${host}`);
|
|
177
187
|
return false;
|
|
178
188
|
}
|
|
@@ -206,5 +216,7 @@ function validateDiscoveryUrl(urlStr) {
|
|
|
206
216
|
0 && (module.exports = {
|
|
207
217
|
AuthorizationServerMetadataSchema,
|
|
208
218
|
OAuth2DiscoveryManager,
|
|
209
|
-
ProtectedResourceMetadataSchema
|
|
219
|
+
ProtectedResourceMetadataSchema,
|
|
220
|
+
normaliseHostname,
|
|
221
|
+
validateDiscoveryUrl
|
|
210
222
|
});
|
|
@@ -32,6 +32,7 @@ __export(oauth2_utils_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(oauth2_utils_exports);
|
|
34
34
|
var import_logger = require("../../utils/logger.js");
|
|
35
|
+
var import_oauth2_discovery = require("./oauth2_discovery.js");
|
|
35
36
|
/**
|
|
36
37
|
* @license
|
|
37
38
|
* Copyright 2026 Google LLC
|
|
@@ -51,13 +52,23 @@ function getTokenEndpoint(authScheme) {
|
|
|
51
52
|
return void 0;
|
|
52
53
|
}
|
|
53
54
|
async function fetchOAuth2Tokens(endpoint, body) {
|
|
55
|
+
if (!(0, import_oauth2_discovery.validateDiscoveryUrl)(endpoint)) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`SSRF protection: OAuth2 token endpoint '${endpoint}' is not allowed. Must use HTTPS and must not target private/loopback/cloud-metadata addresses.`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
54
60
|
try {
|
|
55
61
|
const response = await fetch(endpoint, {
|
|
56
62
|
method: "POST",
|
|
57
63
|
headers: {
|
|
58
64
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
59
65
|
},
|
|
60
|
-
body: body.toString()
|
|
66
|
+
body: body.toString(),
|
|
67
|
+
// Never follow redirects: the SSRF blocklist only validates `endpoint`,
|
|
68
|
+
// so a validated host that responds with a 3xx could otherwise redirect
|
|
69
|
+
// this credential-bearing POST (client_secret/refresh_token) to a
|
|
70
|
+
// private/cloud-metadata address (CWE-918).
|
|
71
|
+
redirect: "error"
|
|
61
72
|
});
|
|
62
73
|
if (!response.ok) {
|
|
63
74
|
throw new Error(`Token request failed with status ${response.status}`);
|