@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
|
@@ -102,6 +102,29 @@ let RoutedAgent = class extends (_b = BaseAgent, _a = ROUTED_AGENT_SIGNATURE_SYM
|
|
|
102
102
|
}
|
|
103
103
|
this.router = config.router;
|
|
104
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Creates a detached copy of this routed agent.
|
|
107
|
+
*
|
|
108
|
+
* The inherited {@link BaseAgent.clone} only deep-clones `subAgents`, but a
|
|
109
|
+
* `RoutedAgent` derives its routing targets from `config.agents`. Rebuilding
|
|
110
|
+
* through the base clone alone would re-read the already-parented original
|
|
111
|
+
* agents and throw "already has a parent agent". This override deep-clones the
|
|
112
|
+
* routing targets (unless the caller overrides `agents`) so the rebuilt
|
|
113
|
+
* constructor re-parents fresh, detached copies. The array-vs-record shape
|
|
114
|
+
* and, for records, the keys are preserved so the router keeps selecting the
|
|
115
|
+
* same targets.
|
|
116
|
+
*
|
|
117
|
+
* @param overrides Config fields to override on the clone. Overriding
|
|
118
|
+
* `parentAgent` is rejected by the base implementation.
|
|
119
|
+
* @returns A new detached `RoutedAgent` of the same concrete class.
|
|
120
|
+
*/
|
|
121
|
+
clone(overrides) {
|
|
122
|
+
const nextOverrides = __spreadValues({}, overrides);
|
|
123
|
+
if (!("agents" in nextOverrides)) {
|
|
124
|
+
nextOverrides.agents = cloneRoutingTargets(this.config.agents);
|
|
125
|
+
}
|
|
126
|
+
return super.clone(nextOverrides);
|
|
127
|
+
}
|
|
105
128
|
/**
|
|
106
129
|
* Runs the selected agent via text-based conversation.
|
|
107
130
|
*/
|
|
@@ -132,6 +155,14 @@ let RoutedAgent = class extends (_b = BaseAgent, _a = ROUTED_AGENT_SIGNATURE_SYM
|
|
|
132
155
|
RoutedAgent = __decorateClass([
|
|
133
156
|
experimental
|
|
134
157
|
], RoutedAgent);
|
|
158
|
+
function cloneRoutingTargets(agents) {
|
|
159
|
+
if (Array.isArray(agents)) {
|
|
160
|
+
return agents.map((agent) => agent.clone());
|
|
161
|
+
}
|
|
162
|
+
return Object.fromEntries(
|
|
163
|
+
Object.entries(agents).map(([key, agent]) => [key, agent.clone()])
|
|
164
|
+
);
|
|
165
|
+
}
|
|
135
166
|
export {
|
|
136
167
|
RoutedAgent,
|
|
137
168
|
isRoutedAgent
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
2
|
const require = topLevelCreateRequire(import.meta.url);
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
6
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -16,6 +18,7 @@ var __spreadValues = (a, b) => {
|
|
|
16
18
|
}
|
|
17
19
|
return a;
|
|
18
20
|
};
|
|
21
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
19
22
|
/**
|
|
20
23
|
* @license
|
|
21
24
|
* Copyright 2025 Google LLC
|
|
@@ -29,14 +32,16 @@ var StreamingMode = /* @__PURE__ */ ((StreamingMode2) => {
|
|
|
29
32
|
return StreamingMode2;
|
|
30
33
|
})(StreamingMode || {});
|
|
31
34
|
function createRunConfig(params = {}) {
|
|
32
|
-
|
|
35
|
+
var _a;
|
|
36
|
+
return __spreadProps(__spreadValues({
|
|
33
37
|
saveInputBlobsAsArtifacts: false,
|
|
34
38
|
supportCfc: false,
|
|
35
39
|
enableAffectiveDialog: false,
|
|
36
40
|
streamingMode: "none" /* NONE */,
|
|
37
|
-
maxLlmCalls: validateMaxLlmCalls(params.maxLlmCalls || 500),
|
|
38
41
|
pauseOnToolCalls: false
|
|
39
|
-
}, params)
|
|
42
|
+
}, params), {
|
|
43
|
+
maxLlmCalls: validateMaxLlmCalls((_a = params.maxLlmCalls) != null ? _a : 500)
|
|
44
|
+
});
|
|
40
45
|
}
|
|
41
46
|
function validateMaxLlmCalls(value) {
|
|
42
47
|
if (value > Number.MAX_SAFE_INTEGER) {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2026 Google LLC
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
var _a;
|
|
9
|
+
import { isBaseAgent } from "../agents/base_agent.js";
|
|
10
|
+
const VALID_APP_NAME_RE = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
|
|
11
|
+
function validateAppName(name) {
|
|
12
|
+
if (!VALID_APP_NAME_RE.test(name)) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
"Invalid app name '".concat(name, "': must start with a letter and can only consist of letters, digits, underscores, and hyphens.")
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
if (name === "user") {
|
|
18
|
+
throw new Error("App name cannot be 'user'; reserved for end-user input.");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const APP_SIGNATURE_SYMBOL = Symbol.for("google.adk.app");
|
|
22
|
+
function isApp(obj) {
|
|
23
|
+
return typeof obj === "object" && obj !== null && APP_SIGNATURE_SYMBOL in obj && obj[APP_SIGNATURE_SYMBOL] === true;
|
|
24
|
+
}
|
|
25
|
+
_a = APP_SIGNATURE_SYMBOL;
|
|
26
|
+
class App {
|
|
27
|
+
constructor(options) {
|
|
28
|
+
this[_a] = true;
|
|
29
|
+
var _a2, _b, _c, _d;
|
|
30
|
+
validateAppName(options.name);
|
|
31
|
+
if (options.rootAgent === void 0 || options.rootAgent === null) {
|
|
32
|
+
throw new Error("rootAgent must be provided.");
|
|
33
|
+
}
|
|
34
|
+
if (!isBaseAgent(options.rootAgent)) {
|
|
35
|
+
throw new TypeError(
|
|
36
|
+
"rootAgent must be a BaseAgent instance, got ".concat((_c = (_b = (_a2 = options.rootAgent) == null ? void 0 : _a2.constructor) == null ? void 0 : _b.name) != null ? _c : typeof options.rootAgent)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
this.name = options.name;
|
|
40
|
+
this.rootAgent = options.rootAgent;
|
|
41
|
+
this.plugins = (_d = options.plugins) != null ? _d : [];
|
|
42
|
+
this.resumabilityConfig = options.resumabilityConfig;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
App,
|
|
47
|
+
isApp,
|
|
48
|
+
validateAppName
|
|
49
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* @license
|
|
21
|
+
* Copyright 2026 Google LLC
|
|
22
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
23
|
+
*/
|
|
24
|
+
function createResumabilityConfig(params = {}) {
|
|
25
|
+
return __spreadValues({
|
|
26
|
+
isResumable: false
|
|
27
|
+
}, params);
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
createResumabilityConfig
|
|
31
|
+
};
|
|
@@ -43,7 +43,7 @@ class FileArtifactService {
|
|
|
43
43
|
artifact,
|
|
44
44
|
customMetadata
|
|
45
45
|
}) {
|
|
46
|
-
if (!artifact.inlineData && !artifact.text) {
|
|
46
|
+
if (!artifact.inlineData && !artifact.text && !artifact.fileData) {
|
|
47
47
|
throw new Error("Artifact must have either inlineData or text content.");
|
|
48
48
|
}
|
|
49
49
|
const artifactDir = getArtifactDir(
|
|
@@ -61,12 +61,19 @@ class FileArtifactService {
|
|
|
61
61
|
const storedFilename = path.basename(artifactDir);
|
|
62
62
|
const contentPath = path.join(versionDir, storedFilename);
|
|
63
63
|
let mimeType;
|
|
64
|
+
let fileUri;
|
|
64
65
|
if (artifact.inlineData) {
|
|
65
66
|
const data = artifact.inlineData.data || "";
|
|
66
67
|
await fs.writeFile(contentPath, Buffer.from(data, "base64"));
|
|
67
68
|
mimeType = artifact.inlineData.mimeType || "application/octet-stream";
|
|
68
69
|
} else if (artifact.text !== void 0) {
|
|
69
70
|
await fs.writeFile(contentPath, artifact.text, "utf-8");
|
|
71
|
+
} else {
|
|
72
|
+
fileUri = artifact.fileData.fileUri;
|
|
73
|
+
if (!fileUri) {
|
|
74
|
+
throw new Error("Artifact fileData must have a fileUri.");
|
|
75
|
+
}
|
|
76
|
+
mimeType = artifact.fileData.mimeType;
|
|
70
77
|
}
|
|
71
78
|
const canonicalUri = await getCanonicalUri(
|
|
72
79
|
this.rootDir,
|
|
@@ -78,6 +85,7 @@ class FileArtifactService {
|
|
|
78
85
|
const metadata = {
|
|
79
86
|
fileName: filename,
|
|
80
87
|
mimeType,
|
|
88
|
+
fileUri,
|
|
81
89
|
version: nextVersion,
|
|
82
90
|
canonicalUri,
|
|
83
91
|
customMetadata
|
|
@@ -129,6 +137,11 @@ class FileArtifactService {
|
|
|
129
137
|
);
|
|
130
138
|
const metadataPath = path.join(versionDir, "metadata.json");
|
|
131
139
|
const metadata = await readMetadata(metadataPath);
|
|
140
|
+
if (metadata.fileUri) {
|
|
141
|
+
return {
|
|
142
|
+
fileData: { fileUri: metadata.fileUri, mimeType: metadata.mimeType }
|
|
143
|
+
};
|
|
144
|
+
}
|
|
132
145
|
const storedFilename = path.basename(artifactDir);
|
|
133
146
|
let contentPath = path.join(versionDir, storedFilename);
|
|
134
147
|
if (metadata.canonicalUri) {
|
|
@@ -27,12 +27,16 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
27
27
|
import { Storage } from "@google-cloud/storage";
|
|
28
28
|
import { createPartFromBase64, createPartFromText } from "@google/genai";
|
|
29
29
|
import { logger } from "../utils/logger.js";
|
|
30
|
+
const GCS_FILE_URI_METADATA_KEY = "adkFileUri";
|
|
31
|
+
const GCS_FILE_MIME_TYPE_METADATA_KEY = "adkFileMimeType";
|
|
32
|
+
const GCS_DISPLAY_NAME_METADATA_KEY = "adkDisplayName";
|
|
33
|
+
const GCS_IS_TEXT_METADATA_KEY = "adkIsText";
|
|
30
34
|
class GcsArtifactService {
|
|
31
|
-
constructor(bucket) {
|
|
32
|
-
this.bucket = new Storage().bucket(bucket);
|
|
35
|
+
constructor(bucket, options) {
|
|
36
|
+
this.bucket = new Storage(options).bucket(bucket);
|
|
33
37
|
}
|
|
34
38
|
async saveArtifact(request) {
|
|
35
|
-
if (!request.artifact.inlineData && !request.artifact.text) {
|
|
39
|
+
if (!request.artifact.inlineData && !request.artifact.text && !request.artifact.fileData) {
|
|
36
40
|
throw new Error("Artifact must have either inlineData or text content.");
|
|
37
41
|
}
|
|
38
42
|
const versions = await this.listVersions(request);
|
|
@@ -42,24 +46,46 @@ class GcsArtifactService {
|
|
|
42
46
|
version
|
|
43
47
|
}))
|
|
44
48
|
);
|
|
45
|
-
const
|
|
49
|
+
const customMetadata = __spreadValues({}, request.customMetadata);
|
|
46
50
|
if (request.artifact.inlineData) {
|
|
51
|
+
if (request.artifact.inlineData.displayName) {
|
|
52
|
+
customMetadata[GCS_DISPLAY_NAME_METADATA_KEY] = request.artifact.inlineData.displayName;
|
|
53
|
+
}
|
|
47
54
|
await file.save(
|
|
48
55
|
Buffer.from(request.artifact.inlineData.data || "", "base64"),
|
|
49
56
|
{
|
|
50
57
|
contentType: request.artifact.inlineData.mimeType,
|
|
51
|
-
metadata
|
|
58
|
+
metadata: { metadata: customMetadata }
|
|
52
59
|
}
|
|
53
60
|
);
|
|
54
61
|
return version;
|
|
62
|
+
} else if (request.artifact.text !== void 0) {
|
|
63
|
+
await file.save(request.artifact.text, {
|
|
64
|
+
contentType: "text/plain",
|
|
65
|
+
metadata: {
|
|
66
|
+
metadata: __spreadProps(__spreadValues({}, customMetadata), { [GCS_IS_TEXT_METADATA_KEY]: "true" })
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return version;
|
|
70
|
+
} else {
|
|
71
|
+
const fileData = request.artifact.fileData;
|
|
72
|
+
const fileUri = fileData == null ? void 0 : fileData.fileUri;
|
|
73
|
+
if (!fileUri) {
|
|
74
|
+
throw new Error("Artifact fileData must have a fileUri.");
|
|
75
|
+
}
|
|
76
|
+
customMetadata[GCS_FILE_URI_METADATA_KEY] = fileUri;
|
|
77
|
+
if (fileData.mimeType) {
|
|
78
|
+
customMetadata[GCS_FILE_MIME_TYPE_METADATA_KEY] = fileData.mimeType;
|
|
79
|
+
}
|
|
80
|
+
await file.save("", {
|
|
81
|
+
contentType: fileData.mimeType || void 0,
|
|
82
|
+
metadata: { metadata: customMetadata }
|
|
83
|
+
});
|
|
84
|
+
return version;
|
|
55
85
|
}
|
|
56
|
-
await file.save(request.artifact.text, {
|
|
57
|
-
contentType: "text/plain",
|
|
58
|
-
metadata
|
|
59
|
-
});
|
|
60
|
-
return version;
|
|
61
86
|
}
|
|
62
87
|
async loadArtifact(request) {
|
|
88
|
+
var _a, _b, _c;
|
|
63
89
|
try {
|
|
64
90
|
let version = request.version;
|
|
65
91
|
if (version === void 0) {
|
|
@@ -74,11 +100,25 @@ class GcsArtifactService {
|
|
|
74
100
|
version
|
|
75
101
|
}))
|
|
76
102
|
);
|
|
77
|
-
const [
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
103
|
+
const [metadata] = await file.getMetadata();
|
|
104
|
+
const customMeta = (_a = metadata.metadata) != null ? _a : {};
|
|
105
|
+
const fileUri = customMeta[GCS_FILE_URI_METADATA_KEY];
|
|
106
|
+
if (fileUri) {
|
|
107
|
+
const mimeType = (_c = (_b = customMeta[GCS_FILE_MIME_TYPE_METADATA_KEY]) != null ? _b : metadata.contentType) != null ? _c : void 0;
|
|
108
|
+
return { fileData: { fileUri, mimeType } };
|
|
109
|
+
}
|
|
110
|
+
const [rawDataBuffer] = await file.download();
|
|
111
|
+
const displayName = customMeta[GCS_DISPLAY_NAME_METADATA_KEY];
|
|
112
|
+
if (displayName) {
|
|
113
|
+
return {
|
|
114
|
+
inlineData: {
|
|
115
|
+
data: rawDataBuffer.toString("base64"),
|
|
116
|
+
mimeType: metadata.contentType,
|
|
117
|
+
displayName
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
if (customMeta[GCS_IS_TEXT_METADATA_KEY] === "true" || metadata.contentType === "text/plain") {
|
|
82
122
|
return createPartFromText(rawDataBuffer.toString("utf-8"));
|
|
83
123
|
}
|
|
84
124
|
return createPartFromBase64(
|
|
@@ -5,6 +5,7 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
5
5
|
* Copyright 2025 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
|
+
import { logger } from "../utils/logger.js";
|
|
8
9
|
function isInMemoryConnectionString(uri) {
|
|
9
10
|
return uri === "memory://";
|
|
10
11
|
}
|
|
@@ -20,7 +21,7 @@ class InMemoryArtifactService {
|
|
|
20
21
|
artifact,
|
|
21
22
|
customMetadata
|
|
22
23
|
}) {
|
|
23
|
-
if (!artifact.inlineData && !artifact.text) {
|
|
24
|
+
if (!artifact.inlineData && !artifact.text && !artifact.fileData) {
|
|
24
25
|
return Promise.reject(
|
|
25
26
|
new Error("Artifact must have either inlineData or text content.")
|
|
26
27
|
);
|
|
@@ -34,6 +35,10 @@ class InMemoryArtifactService {
|
|
|
34
35
|
version,
|
|
35
36
|
customMetadata
|
|
36
37
|
};
|
|
38
|
+
if (!artifact.inlineData && artifact.text === void 0) {
|
|
39
|
+
const fileData = artifact.fileData;
|
|
40
|
+
metadata.mimeType = fileData.mimeType;
|
|
41
|
+
}
|
|
37
42
|
this.artifacts[path].push({ part: artifact, metadata });
|
|
38
43
|
return Promise.resolve(version);
|
|
39
44
|
}
|
|
@@ -52,6 +57,12 @@ class InMemoryArtifactService {
|
|
|
52
57
|
if (version === void 0) {
|
|
53
58
|
version = versions.length - 1;
|
|
54
59
|
}
|
|
60
|
+
if (!versions[version]) {
|
|
61
|
+
logger.warn(
|
|
62
|
+
"[InMemoryArtifactService] loadArtifact: Artifact ".concat(filename, " version ").concat(version, " not found")
|
|
63
|
+
);
|
|
64
|
+
return Promise.resolve(void 0);
|
|
65
|
+
}
|
|
55
66
|
return Promise.resolve(versions[version].part);
|
|
56
67
|
}
|
|
57
68
|
listArtifactKeys({
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* @license
|
|
21
|
+
* Copyright 2026 Google LLC
|
|
22
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
23
|
+
*/
|
|
24
|
+
class ScopedArtifactService {
|
|
25
|
+
constructor(delegate, appName, userId, sessionId) {
|
|
26
|
+
this.delegate = delegate;
|
|
27
|
+
this.appName = appName;
|
|
28
|
+
this.userId = userId;
|
|
29
|
+
this.sessionId = sessionId;
|
|
30
|
+
}
|
|
31
|
+
async saveArtifact(request) {
|
|
32
|
+
return this.delegate.saveArtifact(__spreadValues({
|
|
33
|
+
appName: this.appName,
|
|
34
|
+
userId: this.userId,
|
|
35
|
+
sessionId: this.sessionId
|
|
36
|
+
}, request));
|
|
37
|
+
}
|
|
38
|
+
async loadArtifact(request) {
|
|
39
|
+
return this.delegate.loadArtifact(__spreadValues({
|
|
40
|
+
appName: this.appName,
|
|
41
|
+
userId: this.userId,
|
|
42
|
+
sessionId: this.sessionId
|
|
43
|
+
}, request));
|
|
44
|
+
}
|
|
45
|
+
async listArtifactKeys() {
|
|
46
|
+
return this.delegate.listArtifactKeys({
|
|
47
|
+
appName: this.appName,
|
|
48
|
+
userId: this.userId,
|
|
49
|
+
sessionId: this.sessionId
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async deleteArtifact(filename) {
|
|
53
|
+
return this.delegate.deleteArtifact({
|
|
54
|
+
appName: this.appName,
|
|
55
|
+
userId: this.userId,
|
|
56
|
+
sessionId: this.sessionId,
|
|
57
|
+
filename
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async listVersions(filename) {
|
|
61
|
+
return this.delegate.listVersions({
|
|
62
|
+
appName: this.appName,
|
|
63
|
+
userId: this.userId,
|
|
64
|
+
sessionId: this.sessionId,
|
|
65
|
+
filename
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async listArtifactVersions(filename) {
|
|
69
|
+
return this.delegate.listArtifactVersions({
|
|
70
|
+
appName: this.appName,
|
|
71
|
+
userId: this.userId,
|
|
72
|
+
sessionId: this.sessionId,
|
|
73
|
+
filename
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
async getArtifactVersion(request) {
|
|
77
|
+
return this.delegate.getArtifactVersion(__spreadValues({
|
|
78
|
+
appName: this.appName,
|
|
79
|
+
userId: this.userId,
|
|
80
|
+
sessionId: this.sessionId
|
|
81
|
+
}, request));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
ScopedArtifactService
|
|
86
|
+
};
|
|
@@ -55,7 +55,11 @@ class OAuth2DiscoveryManager {
|
|
|
55
55
|
method: "GET",
|
|
56
56
|
headers: {
|
|
57
57
|
Accept: "application/json"
|
|
58
|
-
}
|
|
58
|
+
},
|
|
59
|
+
// Never follow redirects: validateDiscoveryUrl only checks the
|
|
60
|
+
// initial URL, so following a 3xx would let a validated host
|
|
61
|
+
// redirect discovery to a private/cloud-metadata address (CWE-918).
|
|
62
|
+
redirect: "error"
|
|
59
63
|
});
|
|
60
64
|
if (!response.ok) {
|
|
61
65
|
continue;
|
|
@@ -103,7 +107,11 @@ class OAuth2DiscoveryManager {
|
|
|
103
107
|
method: "GET",
|
|
104
108
|
headers: {
|
|
105
109
|
Accept: "application/json"
|
|
106
|
-
}
|
|
110
|
+
},
|
|
111
|
+
// Never follow redirects: validateDiscoveryUrl only checks the
|
|
112
|
+
// initial URL, so following a 3xx would let a validated host
|
|
113
|
+
// redirect discovery to a private/cloud-metadata address (CWE-918).
|
|
114
|
+
redirect: "error"
|
|
107
115
|
});
|
|
108
116
|
if (!response.ok) {
|
|
109
117
|
return void 0;
|
|
@@ -143,7 +151,7 @@ function validateDiscoveryUrl(urlStr) {
|
|
|
143
151
|
return false;
|
|
144
152
|
}
|
|
145
153
|
const host = normaliseHostname(url.hostname.toLowerCase());
|
|
146
|
-
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.")) {
|
|
154
|
+
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.")) {
|
|
147
155
|
logger.warn("Unsafe host for discovery URL: ".concat(host));
|
|
148
156
|
return false;
|
|
149
157
|
}
|
|
@@ -176,5 +184,7 @@ function validateDiscoveryUrl(urlStr) {
|
|
|
176
184
|
export {
|
|
177
185
|
AuthorizationServerMetadataSchema,
|
|
178
186
|
OAuth2DiscoveryManager,
|
|
179
|
-
ProtectedResourceMetadataSchema
|
|
187
|
+
ProtectedResourceMetadataSchema,
|
|
188
|
+
normaliseHostname,
|
|
189
|
+
validateDiscoveryUrl
|
|
180
190
|
};
|
|
@@ -6,6 +6,7 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
8
|
import { logger } from "../../utils/logger.js";
|
|
9
|
+
import { validateDiscoveryUrl } from "./oauth2_discovery.js";
|
|
9
10
|
function getTokenEndpoint(authScheme) {
|
|
10
11
|
if (authScheme.type === "openIdConnect" && authScheme.tokenEndpoint) {
|
|
11
12
|
return authScheme.tokenEndpoint;
|
|
@@ -20,13 +21,23 @@ function getTokenEndpoint(authScheme) {
|
|
|
20
21
|
return void 0;
|
|
21
22
|
}
|
|
22
23
|
async function fetchOAuth2Tokens(endpoint, body) {
|
|
24
|
+
if (!validateDiscoveryUrl(endpoint)) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
"SSRF protection: OAuth2 token endpoint '".concat(endpoint, "' is not allowed. Must use HTTPS and must not target private/loopback/cloud-metadata addresses.")
|
|
27
|
+
);
|
|
28
|
+
}
|
|
23
29
|
try {
|
|
24
30
|
const response = await fetch(endpoint, {
|
|
25
31
|
method: "POST",
|
|
26
32
|
headers: {
|
|
27
33
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
28
34
|
},
|
|
29
|
-
body: body.toString()
|
|
35
|
+
body: body.toString(),
|
|
36
|
+
// Never follow redirects: the SSRF blocklist only validates `endpoint`,
|
|
37
|
+
// so a validated host that responds with a 3xx could otherwise redirect
|
|
38
|
+
// this credential-bearing POST (client_secret/refresh_token) to a
|
|
39
|
+
// private/cloud-metadata address (CWE-918).
|
|
40
|
+
redirect: "error"
|
|
30
41
|
});
|
|
31
42
|
if (!response.ok) {
|
|
32
43
|
throw new Error("Token request failed with status ".concat(response.status));
|