@google/adk 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/agents/active_streaming_tool.js +6 -1
- package/dist/cjs/agents/base_agent.js +19 -1
- package/dist/cjs/agents/context.js +1 -11
- package/dist/cjs/agents/functions.js +35 -16
- package/dist/cjs/agents/instructions.js +99 -33
- package/dist/cjs/agents/invocation_context.js +2 -6
- package/dist/cjs/agents/llm_agent.js +60 -11
- package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/cjs/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/cjs/agents/processors/content_processor_utils.js +51 -25
- package/dist/cjs/agents/processors/content_request_processor.js +7 -0
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +16 -2
- package/dist/cjs/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/cjs/agents/processors/interactions_request_processor.js +63 -0
- package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/cjs/agents/processors/tool_filter_request_processor.js +7 -1
- 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 +5 -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/auth_preprocessor.js +12 -10
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +17 -5
- package/dist/cjs/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/cjs/code_executors/code_executor_context.js +7 -7
- package/dist/cjs/common.js +86 -0
- package/dist/cjs/context/agent_controlled_context_compactor.js +109 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +11 -0
- package/dist/cjs/context/token_based_context_compactor.js +43 -11
- package/dist/cjs/context/trajectory_thought_pruning_compactor.js +71 -0
- package/dist/cjs/events/event.js +25 -1
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
- package/dist/cjs/models/gemini_llm_connection.js +62 -19
- package/dist/cjs/models/google_llm.js +51 -18
- package/dist/cjs/models/interactions_utils.js +732 -0
- package/dist/cjs/plugins/base_plugin.js +1 -0
- package/dist/cjs/plugins/security_plugin.js +16 -0
- package/dist/cjs/runner/in_memory_runner.js +13 -2
- package/dist/cjs/runner/runner.js +93 -72
- package/dist/cjs/sessions/base_session_service.js +19 -3
- package/dist/cjs/sessions/database_session_service.js +26 -9
- package/dist/cjs/sessions/db/schema.js +45 -10
- package/dist/cjs/sessions/in_memory_session_service.js +2 -1
- package/dist/cjs/sessions/vertex_ai_session_service.js +21 -5
- package/dist/cjs/skills/gcp_skill_registry.js +104 -0
- package/dist/cjs/skills/loader.js +67 -2
- package/dist/cjs/skills/skill_registry.js +27 -0
- package/dist/cjs/tools/base_toolset.js +1 -1
- package/dist/cjs/tools/consolidate_context_tool.js +79 -0
- package/dist/cjs/tools/forwarding_artifact_service.js +16 -28
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +232 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +224 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +117 -0
- package/dist/cjs/tools/openapi_tool/openapi_toolset.js +133 -0
- package/dist/cjs/tools/openapi_tool/rest_api_tool.js +256 -0
- package/dist/cjs/tools/skill/load_skill_resource_tool.js +25 -3
- package/dist/cjs/tools/skill/load_skill_tool.js +12 -1
- package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/cjs/tools/skill/search_skills_tool.js +108 -0
- package/dist/cjs/tools/skill/skill_toolset.js +40 -5
- package/dist/cjs/utils/async_hooks_shim.js +52 -0
- package/dist/cjs/utils/async_queue.js +88 -0
- package/dist/cjs/utils/case_utils.js +53 -0
- package/dist/cjs/utils/client_labels.js +41 -3
- package/dist/cjs/utils/env_aware_utils.js +14 -1
- package/dist/cjs/utils/live_connection_utils.js +284 -0
- package/dist/cjs/utils/model_name.js +9 -0
- package/dist/cjs/utils/streaming_utils.js +18 -11
- package/dist/cjs/utils/task.js +62 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/active_streaming_tool.js +6 -1
- package/dist/esm/agents/base_agent.js +19 -1
- package/dist/esm/agents/context.js +1 -11
- package/dist/esm/agents/functions.js +36 -15
- package/dist/esm/agents/instructions.js +99 -33
- package/dist/esm/agents/invocation_context.js +2 -6
- package/dist/esm/agents/llm_agent.js +61 -11
- package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/esm/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/esm/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/esm/agents/processors/content_processor_utils.js +48 -24
- package/dist/esm/agents/processors/content_request_processor.js +7 -0
- package/dist/esm/agents/processors/context_compactor_request_processor.js +16 -2
- package/dist/esm/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/esm/agents/processors/interactions_request_processor.js +34 -0
- package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/esm/agents/processors/tool_filter_request_processor.js +7 -1
- 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 +5 -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/auth_preprocessor.js +12 -10
- package/dist/esm/auth/oauth2/oauth2_discovery.js +14 -4
- package/dist/esm/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/esm/code_executors/code_executor_context.js +7 -7
- package/dist/esm/common.js +75 -3
- package/dist/esm/context/agent_controlled_context_compactor.js +81 -0
- package/dist/esm/context/summarizers/llm_summarizer.js +11 -0
- package/dist/esm/context/token_based_context_compactor.js +43 -11
- package/dist/esm/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/esm/events/event.js +23 -1
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
- package/dist/esm/models/gemini_llm_connection.js +62 -19
- package/dist/esm/models/google_llm.js +49 -17
- package/dist/esm/models/interactions_utils.js +697 -0
- package/dist/esm/plugins/base_plugin.js +1 -0
- package/dist/esm/plugins/security_plugin.js +16 -0
- package/dist/esm/runner/in_memory_runner.js +13 -2
- package/dist/esm/runner/runner.js +91 -73
- package/dist/esm/sessions/base_session_service.js +17 -2
- package/dist/esm/sessions/database_session_service.js +26 -9
- package/dist/esm/sessions/db/schema.js +44 -10
- package/dist/esm/sessions/in_memory_session_service.js +4 -2
- package/dist/esm/sessions/vertex_ai_session_service.js +21 -5
- package/dist/esm/skills/gcp_skill_registry.js +78 -0
- package/dist/esm/skills/loader.js +66 -2
- package/dist/esm/skills/skill_registry.js +7 -0
- package/dist/esm/tools/base_toolset.js +1 -1
- package/dist/esm/tools/consolidate_context_tool.js +51 -0
- package/dist/esm/tools/forwarding_artifact_service.js +16 -28
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +206 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +91 -0
- package/dist/esm/tools/openapi_tool/openapi_toolset.js +97 -0
- package/dist/esm/tools/openapi_tool/rest_api_tool.js +229 -0
- package/dist/esm/tools/skill/load_skill_resource_tool.js +25 -3
- package/dist/esm/tools/skill/load_skill_tool.js +12 -1
- package/dist/esm/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/esm/tools/skill/search_skills_tool.js +82 -0
- package/dist/esm/tools/skill/skill_toolset.js +40 -5
- package/dist/esm/utils/async_hooks_shim.js +24 -0
- package/dist/esm/utils/async_queue.js +60 -0
- package/dist/esm/utils/case_utils.js +25 -0
- package/dist/esm/utils/client_labels.js +38 -2
- package/dist/esm/utils/env_aware_utils.js +14 -1
- package/dist/esm/utils/live_connection_utils.js +256 -0
- package/dist/esm/utils/model_name.js +8 -0
- package/dist/esm/utils/streaming_utils.js +18 -11
- package/dist/esm/utils/task.js +34 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent_utils.d.ts +29 -4
- package/dist/types/a2a/event_converter_utils.d.ts +14 -1
- package/dist/types/a2a/metadata_converter_utils.d.ts +18 -0
- package/dist/types/a2a/part_converter_utils.d.ts +51 -6
- package/dist/types/agents/active_streaming_tool.d.ts +3 -4
- package/dist/types/agents/functions.d.ts +12 -9
- package/dist/types/agents/invocation_context.d.ts +7 -12
- package/dist/types/agents/llm_agent.d.ts +14 -0
- package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +14 -0
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +7 -0
- package/dist/types/agents/processors/content_processor_utils.d.ts +34 -0
- package/dist/types/agents/processors/content_request_processor.d.ts +16 -0
- package/dist/types/agents/processors/context_compactor_request_processor.d.ts +12 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +7 -0
- package/dist/types/agents/processors/interactions_request_processor.d.ts +17 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +9 -1
- package/dist/types/agents/processors/tool_filter_request_processor.d.ts +12 -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 +35 -4
- package/dist/types/context/agent_controlled_context_compactor.d.ts +24 -0
- package/dist/types/context/base_context_compactor.d.ts +3 -0
- package/dist/types/context/summarizers/llm_summarizer.d.ts +17 -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/event.d.ts +8 -0
- package/dist/types/events/event_actions.d.ts +1 -2
- package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +21 -2
- package/dist/types/models/base_llm_connection.d.ts +10 -0
- package/dist/types/models/gemini_llm_connection.d.ts +15 -4
- 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 +14 -1
- package/dist/types/plugins/base_plugin.d.ts +2 -1
- package/dist/types/plugins/security_plugin.d.ts +30 -0
- package/dist/types/runner/in_memory_runner.d.ts +7 -1
- package/dist/types/runner/runner.d.ts +43 -9
- package/dist/types/sessions/base_session_service.d.ts +7 -16
- package/dist/types/sessions/db/schema.d.ts +1 -0
- package/dist/types/sessions/session.d.ts +11 -0
- package/dist/types/sessions/vertex_ai_session_service.d.ts +9 -1
- package/dist/types/skills/gcp_skill_registry.d.ts +24 -0
- package/dist/types/skills/loader.d.ts +7 -0
- package/dist/types/skills/skill.d.ts +1 -1
- package/dist/types/skills/skill_registry.d.ts +29 -0
- package/dist/types/tools/consolidate_context_tool.d.ts +19 -0
- package/dist/types/tools/forwarding_artifact_service.d.ts +3 -2
- package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +34 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +59 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +23 -0
- package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +27 -0
- package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +50 -0
- package/dist/types/tools/skill/load_skill_resource_tool.d.ts +1 -1
- package/dist/types/tools/skill/search_skills_tool.d.ts +14 -0
- package/dist/types/tools/skill/skill_toolset.d.ts +5 -0
- package/dist/types/utils/async_hooks_shim.d.ts +10 -0
- package/dist/types/utils/async_queue.d.ts +18 -0
- package/dist/types/utils/case_utils.d.ts +12 -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/live_connection_utils.d.ts +30 -0
- package/dist/types/utils/model_name.d.ts +7 -0
- package/dist/types/utils/streaming_utils.d.ts +0 -1
- package/dist/types/utils/task.d.ts +24 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/active_streaming_tool.js +6 -1
- package/dist/web/agents/base_agent.js +31 -1
- package/dist/web/agents/context.js +1 -11
- package/dist/web/agents/functions.js +36 -15
- package/dist/web/agents/instructions.js +99 -33
- package/dist/web/agents/invocation_context.js +2 -6
- package/dist/web/agents/llm_agent.js +61 -11
- package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/web/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/web/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/web/agents/processors/content_processor_utils.js +66 -24
- package/dist/web/agents/processors/content_request_processor.js +7 -0
- package/dist/web/agents/processors/context_compactor_request_processor.js +16 -2
- package/dist/web/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/web/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/web/agents/processors/interactions_request_processor.js +52 -0
- package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/web/agents/processors/tool_filter_request_processor.js +7 -1
- 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 +5 -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/auth_preprocessor.js +12 -10
- package/dist/web/auth/oauth2/oauth2_discovery.js +14 -4
- package/dist/web/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/web/code_executors/code_executor_context.js +7 -7
- package/dist/web/common.js +75 -3
- package/dist/web/context/agent_controlled_context_compactor.js +81 -0
- package/dist/web/context/summarizers/llm_summarizer.js +11 -0
- package/dist/web/context/token_based_context_compactor.js +43 -11
- package/dist/web/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/web/events/event.js +21 -1
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
- package/dist/web/models/gemini_llm_connection.js +75 -19
- package/dist/web/models/google_llm.js +80 -17
- package/dist/web/models/interactions_utils.js +728 -0
- package/dist/web/plugins/base_plugin.js +1 -0
- package/dist/web/plugins/security_plugin.js +16 -0
- package/dist/web/runner/in_memory_runner.js +13 -2
- package/dist/web/runner/runner.js +111 -75
- package/dist/web/sessions/base_session_service.js +17 -2
- package/dist/web/sessions/database_session_service.js +26 -9
- package/dist/web/sessions/db/schema.js +44 -10
- package/dist/web/sessions/in_memory_session_service.js +4 -2
- package/dist/web/sessions/vertex_ai_session_service.js +21 -5
- package/dist/web/skills/gcp_skill_registry.js +78 -0
- package/dist/web/skills/loader.js +66 -2
- package/dist/web/skills/skill_registry.js +7 -0
- package/dist/web/tools/base_toolset.js +1 -1
- package/dist/web/tools/consolidate_context_tool.js +51 -0
- package/dist/web/tools/forwarding_artifact_service.js +16 -28
- package/dist/web/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +221 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +91 -0
- package/dist/web/tools/openapi_tool/openapi_toolset.js +97 -0
- package/dist/web/tools/openapi_tool/rest_api_tool.js +229 -0
- package/dist/web/tools/skill/load_skill_resource_tool.js +25 -3
- package/dist/web/tools/skill/load_skill_tool.js +12 -1
- package/dist/web/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/web/tools/skill/search_skills_tool.js +82 -0
- package/dist/web/tools/skill/skill_toolset.js +40 -5
- package/dist/web/utils/async_hooks_shim.js +24 -0
- package/dist/web/utils/async_queue.js +60 -0
- package/dist/web/utils/case_utils.js +25 -0
- package/dist/web/utils/client_labels.js +38 -2
- package/dist/web/utils/env_aware_utils.js +14 -1
- package/dist/web/utils/live_connection_utils.js +254 -0
- package/dist/web/utils/model_name.js +8 -0
- package/dist/web/utils/streaming_utils.js +18 -11
- package/dist/web/utils/task.js +34 -0
- package/dist/web/version.js +1 -1
- package/package.json +4 -2
|
@@ -25,7 +25,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
25
25
|
var content_processor_utils_exports = {};
|
|
26
26
|
__export(content_processor_utils_exports, {
|
|
27
27
|
getContents: () => getContents,
|
|
28
|
-
getCurrentTurnContents: () => getCurrentTurnContents
|
|
28
|
+
getCurrentTurnContents: () => getCurrentTurnContents,
|
|
29
|
+
mergeFunctionResponseEvents: () => mergeFunctionResponseEvents,
|
|
30
|
+
removeClientFunctionCallId: () => removeClientFunctionCallId
|
|
29
31
|
});
|
|
30
32
|
module.exports = __toCommonJS(content_processor_utils_exports);
|
|
31
33
|
var import_genai = require("@google/genai");
|
|
@@ -38,6 +40,17 @@ var import_functions = require("../functions.js");
|
|
|
38
40
|
* Copyright 2025 Google LLC
|
|
39
41
|
* SPDX-License-Identifier: Apache-2.0
|
|
40
42
|
*/
|
|
43
|
+
function removeClientFunctionCallId(content) {
|
|
44
|
+
var _a, _b, _c, _d, _e;
|
|
45
|
+
for (const part of (_a = content == null ? void 0 : content.parts) != null ? _a : []) {
|
|
46
|
+
if ((_c = (_b = part.functionCall) == null ? void 0 : _b.id) == null ? void 0 : _c.startsWith(import_functions.AF_FUNCTION_CALL_ID_PREFIX)) {
|
|
47
|
+
part.functionCall.id = void 0;
|
|
48
|
+
}
|
|
49
|
+
if ((_e = (_d = part.functionResponse) == null ? void 0 : _d.id) == null ? void 0 : _e.startsWith(import_functions.AF_FUNCTION_CALL_ID_PREFIX)) {
|
|
50
|
+
part.functionResponse.id = void 0;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
41
54
|
function getContents(events, agentName, currentBranch) {
|
|
42
55
|
var _a, _b, _c;
|
|
43
56
|
const filteredEvents = [];
|
|
@@ -67,7 +80,7 @@ function getContents(events, agentName, currentBranch) {
|
|
|
67
80
|
const contents = [];
|
|
68
81
|
for (const event of resultEvents) {
|
|
69
82
|
const content = (0, import_lodash_es.cloneDeep)(event.content);
|
|
70
|
-
|
|
83
|
+
removeClientFunctionCallId(content);
|
|
71
84
|
contents.push(content);
|
|
72
85
|
}
|
|
73
86
|
return contents;
|
|
@@ -127,17 +140,19 @@ function convertForeignEvent(event) {
|
|
|
127
140
|
text: `[${event.author}] said: ${part.text}`
|
|
128
141
|
});
|
|
129
142
|
} else if (part.functionCall) {
|
|
130
|
-
const argsText = safeStringify(part.functionCall.args);
|
|
131
143
|
(_d = content.parts) == null ? void 0 : _d.push({
|
|
132
|
-
text: `[${event.author}] called tool \`${part.functionCall.name}\` with parameters: ${
|
|
144
|
+
text: `[${event.author}] called tool \`${part.functionCall.name}\` with parameters: ${safeStringify(
|
|
145
|
+
part.functionCall.args
|
|
146
|
+
)}`
|
|
133
147
|
});
|
|
134
148
|
} else if (part.functionResponse) {
|
|
135
|
-
const responseText = safeStringify(part.functionResponse.response);
|
|
136
149
|
(_e = content.parts) == null ? void 0 : _e.push({
|
|
137
|
-
text: `[${event.author}] tool \`${part.functionResponse.name}\` returned result: ${
|
|
150
|
+
text: `[${event.author}] tool \`${part.functionResponse.name}\` returned result: ${safeStringify(
|
|
151
|
+
part.functionResponse.response
|
|
152
|
+
)}`
|
|
138
153
|
});
|
|
139
154
|
} else {
|
|
140
|
-
(_f = content.parts) == null ? void 0 : _f.push(part);
|
|
155
|
+
(_f = content.parts) == null ? void 0 : _f.push((0, import_lodash_es.cloneDeep)(part));
|
|
141
156
|
}
|
|
142
157
|
}
|
|
143
158
|
return (0, import_event.createEvent)({
|
|
@@ -153,9 +168,12 @@ function mergeFunctionResponseEvents(events) {
|
|
|
153
168
|
if (events.length === 0) {
|
|
154
169
|
throw new Error("Cannot merge an empty list of events.");
|
|
155
170
|
}
|
|
156
|
-
const mergedEvent = (0, import_event.createEvent)(
|
|
157
|
-
|
|
158
|
-
|
|
171
|
+
const mergedEvent = (0, import_event.createEvent)({
|
|
172
|
+
...events[0],
|
|
173
|
+
content: events[0].content ? (0, import_lodash_es.cloneDeep)(events[0].content) : void 0
|
|
174
|
+
});
|
|
175
|
+
const partsInMergedEvent = (_a = mergedEvent.content) == null ? void 0 : _a.parts;
|
|
176
|
+
if (!partsInMergedEvent || partsInMergedEvent.length === 0) {
|
|
159
177
|
throw new Error("There should be at least one function_response part.");
|
|
160
178
|
}
|
|
161
179
|
const partIndicesInMergedEvent = {};
|
|
@@ -170,16 +188,17 @@ function mergeFunctionResponseEvents(events) {
|
|
|
170
188
|
throw new Error("There should be at least one function_response part.");
|
|
171
189
|
}
|
|
172
190
|
for (const part of event.content.parts) {
|
|
173
|
-
|
|
174
|
-
|
|
191
|
+
const clonedPart = (0, import_lodash_es.cloneDeep)(part);
|
|
192
|
+
if (clonedPart.functionResponse && clonedPart.functionResponse.id) {
|
|
193
|
+
const functionCallId = clonedPart.functionResponse.id;
|
|
175
194
|
if (functionCallId in partIndicesInMergedEvent) {
|
|
176
|
-
partsInMergedEvent[partIndicesInMergedEvent[functionCallId]] =
|
|
195
|
+
partsInMergedEvent[partIndicesInMergedEvent[functionCallId]] = clonedPart;
|
|
177
196
|
} else {
|
|
178
|
-
partsInMergedEvent.push(
|
|
197
|
+
partsInMergedEvent.push(clonedPart);
|
|
179
198
|
partIndicesInMergedEvent[functionCallId] = partsInMergedEvent.length - 1;
|
|
180
199
|
}
|
|
181
200
|
} else {
|
|
182
|
-
partsInMergedEvent.push(
|
|
201
|
+
partsInMergedEvent.push(clonedPart);
|
|
183
202
|
}
|
|
184
203
|
}
|
|
185
204
|
}
|
|
@@ -194,7 +213,7 @@ function rearrangeEventsForLatestFunctionResponse(events) {
|
|
|
194
213
|
if (!(functionResponses == null ? void 0 : functionResponses.length)) {
|
|
195
214
|
return events;
|
|
196
215
|
}
|
|
197
|
-
|
|
216
|
+
const functionResponsesIds = new Set(
|
|
198
217
|
functionResponses.filter((response) => !!response.id).map((response) => response.id)
|
|
199
218
|
);
|
|
200
219
|
const secondLatestEvent = events.at(-2);
|
|
@@ -208,16 +227,16 @@ function rearrangeEventsForLatestFunctionResponse(events) {
|
|
|
208
227
|
}
|
|
209
228
|
}
|
|
210
229
|
}
|
|
211
|
-
let
|
|
230
|
+
let match;
|
|
212
231
|
for (let idx = events.length - 2; idx >= 0; idx--) {
|
|
213
232
|
const event = events[idx];
|
|
214
233
|
const functionCalls = (0, import_event.getFunctionCalls)(event);
|
|
215
234
|
if (!(functionCalls == null ? void 0 : functionCalls.length)) {
|
|
216
235
|
continue;
|
|
217
236
|
}
|
|
237
|
+
let matchedInEvent = false;
|
|
218
238
|
for (const functionCall of functionCalls) {
|
|
219
239
|
if (functionCall.id && functionResponsesIds.has(functionCall.id)) {
|
|
220
|
-
functionCallEventIdx = idx;
|
|
221
240
|
const functionCallIds = new Set(
|
|
222
241
|
functionCalls.map((fc) => fc.id).filter((id) => !!id)
|
|
223
242
|
);
|
|
@@ -231,12 +250,16 @@ function rearrangeEventsForLatestFunctionResponse(events) {
|
|
|
231
250
|
)}, function response ids provided: ${Array.from(functionResponsesIds).join(", ")}`
|
|
232
251
|
);
|
|
233
252
|
}
|
|
234
|
-
|
|
253
|
+
match = { eventIdx: idx, responseIds: functionCallIds };
|
|
254
|
+
matchedInEvent = true;
|
|
235
255
|
break;
|
|
236
256
|
}
|
|
237
257
|
}
|
|
258
|
+
if (matchedInEvent) {
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
238
261
|
}
|
|
239
|
-
if (
|
|
262
|
+
if (!match) {
|
|
240
263
|
throw new Error(
|
|
241
264
|
`No function call event found for function responses ids: ${Array.from(
|
|
242
265
|
functionResponsesIds
|
|
@@ -244,17 +267,18 @@ function rearrangeEventsForLatestFunctionResponse(events) {
|
|
|
244
267
|
);
|
|
245
268
|
}
|
|
246
269
|
const functionResponseEvents = [];
|
|
247
|
-
|
|
270
|
+
const activeResponses = match.responseIds;
|
|
271
|
+
for (let idx = match.eventIdx + 1; idx < events.length - 1; idx++) {
|
|
248
272
|
const event = events[idx];
|
|
249
273
|
const responses = (0, import_event.getFunctionResponses)(event);
|
|
250
274
|
if (responses && responses.some(
|
|
251
|
-
(response) => response.id &&
|
|
275
|
+
(response) => response.id && activeResponses.has(response.id)
|
|
252
276
|
)) {
|
|
253
277
|
functionResponseEvents.push(event);
|
|
254
278
|
}
|
|
255
279
|
}
|
|
256
280
|
functionResponseEvents.push(events[events.length - 1]);
|
|
257
|
-
const resultEvents = events.slice(0,
|
|
281
|
+
const resultEvents = events.slice(0, match.eventIdx + 1);
|
|
258
282
|
resultEvents.push(mergeFunctionResponseEvents(functionResponseEvents));
|
|
259
283
|
return resultEvents;
|
|
260
284
|
}
|
|
@@ -293,7 +317,7 @@ function rearrangeEventsForAsyncFunctionResponsesInHistory(events) {
|
|
|
293
317
|
continue;
|
|
294
318
|
}
|
|
295
319
|
if (functionResponseEventsIndices.size === 1) {
|
|
296
|
-
const [responseIndex] =
|
|
320
|
+
const [responseIndex] = Array.from(functionResponseEventsIndices);
|
|
297
321
|
resultEvents.push(events[responseIndex]);
|
|
298
322
|
} else {
|
|
299
323
|
const indicesArray = Array.from(functionResponseEventsIndices).sort(
|
|
@@ -334,5 +358,7 @@ ${event.compactedContent}`
|
|
|
334
358
|
// Annotate the CommonJS export names for ESM import in node:
|
|
335
359
|
0 && (module.exports = {
|
|
336
360
|
getContents,
|
|
337
|
-
getCurrentTurnContents
|
|
361
|
+
getCurrentTurnContents,
|
|
362
|
+
mergeFunctionResponseEvents,
|
|
363
|
+
removeClientFunctionCallId
|
|
338
364
|
});
|
|
@@ -37,6 +37,13 @@ var import_content_processor_utils = require("./content_processor_utils.js");
|
|
|
37
37
|
* SPDX-License-Identifier: Apache-2.0
|
|
38
38
|
*/
|
|
39
39
|
class ContentRequestProcessor {
|
|
40
|
+
/**
|
|
41
|
+
* Fills {@link LlmRequest.contents} based on the session event history and
|
|
42
|
+
* agent configuration.
|
|
43
|
+
*
|
|
44
|
+
* @param invocationContext - The current invocation context.
|
|
45
|
+
* @param llmRequest - The request whose contents field will be populated.
|
|
46
|
+
*/
|
|
40
47
|
// eslint-disable-next-line require-yield
|
|
41
48
|
async *runAsync(invocationContext, llmRequest) {
|
|
42
49
|
const agent = invocationContext.agent;
|
|
@@ -34,24 +34,38 @@ var import_base_plugin = require("../../plugins/base_plugin.js");
|
|
|
34
34
|
* SPDX-License-Identifier: Apache-2.0
|
|
35
35
|
*/
|
|
36
36
|
class ContextCompactorRequestProcessor {
|
|
37
|
+
/**
|
|
38
|
+
* @param compactors - Ordered list of compactors to evaluate; the first one
|
|
39
|
+
* that reports it should compact will perform the compaction.
|
|
40
|
+
*/
|
|
37
41
|
constructor(compactors) {
|
|
38
42
|
this.compactors = compactors;
|
|
39
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Evaluates compactors in priority order. The first compactor that indicates
|
|
46
|
+
* it should compact will compact the session history, fire plugin hooks, and
|
|
47
|
+
* yield any newly generated events. Iteration stops after one compaction.
|
|
48
|
+
*
|
|
49
|
+
* @param invocationContext - The current invocation context.
|
|
50
|
+
* @param _llmRequest - Unused; present to satisfy the {@link BaseLlmRequestProcessor} interface.
|
|
51
|
+
*/
|
|
40
52
|
async *runAsync(invocationContext, _llmRequest) {
|
|
53
|
+
var _a;
|
|
41
54
|
for (const compactor of this.compactors) {
|
|
42
55
|
const shouldCompact = await Promise.resolve(
|
|
43
56
|
compactor.shouldCompact(invocationContext)
|
|
44
57
|
);
|
|
45
58
|
if (shouldCompact) {
|
|
59
|
+
const trigger = (_a = compactor.trigger) != null ? _a : import_base_plugin.ContextCompactionTrigger.Auto;
|
|
46
60
|
await invocationContext.pluginManager.runBeforeContextCompaction({
|
|
47
61
|
invocationContext,
|
|
48
|
-
trigger
|
|
62
|
+
trigger
|
|
49
63
|
});
|
|
50
64
|
const oldEvents = new Set(invocationContext.session.events);
|
|
51
65
|
await Promise.resolve(compactor.compact(invocationContext));
|
|
52
66
|
await invocationContext.pluginManager.runAfterContextCompaction({
|
|
53
67
|
invocationContext,
|
|
54
|
-
trigger
|
|
68
|
+
trigger
|
|
55
69
|
});
|
|
56
70
|
const newEvents = invocationContext.session.events.filter(
|
|
57
71
|
(e) => !oldEvents.has(e)
|
|
@@ -36,6 +36,13 @@ var import_base_llm_processor = require("./base_llm_processor.js");
|
|
|
36
36
|
* SPDX-License-Identifier: Apache-2.0
|
|
37
37
|
*/
|
|
38
38
|
class IdentityLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
|
|
39
|
+
/**
|
|
40
|
+
* Appends agent name and description as identity instructions to the system
|
|
41
|
+
* prompt of the request.
|
|
42
|
+
*
|
|
43
|
+
* @param invocationContext - The current invocation context.
|
|
44
|
+
* @param llmRequest - The request object to append instructions to.
|
|
45
|
+
*/
|
|
39
46
|
// eslint-disable-next-line require-yield
|
|
40
47
|
async *runAsync(invocationContext, llmRequest) {
|
|
41
48
|
const agent = invocationContext.agent;
|
|
@@ -75,6 +75,11 @@ class InstructionsLlmRequestProcessor extends import_base_llm_processor.BaseLlmR
|
|
|
75
75
|
}
|
|
76
76
|
(0, import_llm_request.appendInstructions)(llmRequest, [instructionWithState]);
|
|
77
77
|
}
|
|
78
|
+
if (agent.outputSchema && agent.tools && agent.tools.length > 0) {
|
|
79
|
+
(0, import_llm_request.appendInstructions)(llmRequest, [
|
|
80
|
+
'To output the final result, you must call the "set_model_response" function with the appropriate values. Do not output anything else.'
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
78
83
|
}
|
|
79
84
|
}
|
|
80
85
|
const INSTRUCTIONS_LLM_REQUEST_PROCESSOR = new InstructionsLlmRequestProcessor();
|
|
@@ -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
|
+
});
|
|
@@ -40,7 +40,15 @@ var import_base_llm_processor = require("./base_llm_processor.js");
|
|
|
40
40
|
* SPDX-License-Identifier: Apache-2.0
|
|
41
41
|
*/
|
|
42
42
|
class RequestConfirmationLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
|
|
43
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* Resumes tool calls that were paused for user confirmation, re-invoking
|
|
45
|
+
* them with the confirmed or denied decision before the next LLM turn.
|
|
46
|
+
*
|
|
47
|
+
* @param invocationContext - The current invocation context, including the
|
|
48
|
+
* session event history used to locate pending confirmation responses.
|
|
49
|
+
* @yields Function response events for tools that have been confirmed and
|
|
50
|
+
* are ready to resume.
|
|
51
|
+
*/
|
|
44
52
|
async *runAsync(invocationContext) {
|
|
45
53
|
const agent = invocationContext.agent;
|
|
46
54
|
if (!(0, import_llm_agent.isLlmAgent)(agent)) {
|
|
@@ -38,7 +38,13 @@ var import_base_llm_processor = require("./base_llm_processor.js");
|
|
|
38
38
|
* SPDX-License-Identifier: Apache-2.0
|
|
39
39
|
*/
|
|
40
40
|
class ToolFilterRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
|
|
41
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* Invokes plugin-based tool filtering and updates {@link LlmRequest.allowedTools}
|
|
43
|
+
* with the reduced tool set if any plugin returns a filtered result.
|
|
44
|
+
*
|
|
45
|
+
* @param invocationContext - The current invocation context.
|
|
46
|
+
* @param llmRequest - The request whose allowed tools may be restricted.
|
|
47
|
+
*/
|
|
42
48
|
// eslint-disable-next-line require-yield
|
|
43
49
|
async *runAsync(invocationContext, llmRequest) {
|
|
44
50
|
const agent = invocationContext.agent;
|
|
@@ -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)(
|
|
@@ -48,7 +48,7 @@ class InMemoryArtifactService {
|
|
|
48
48
|
artifact,
|
|
49
49
|
customMetadata
|
|
50
50
|
}) {
|
|
51
|
-
if (!artifact.inlineData && !artifact.text) {
|
|
51
|
+
if (!artifact.inlineData && !artifact.text && !artifact.fileData) {
|
|
52
52
|
return Promise.reject(
|
|
53
53
|
new Error("Artifact must have either inlineData or text content.")
|
|
54
54
|
);
|
|
@@ -62,6 +62,10 @@ class InMemoryArtifactService {
|
|
|
62
62
|
version,
|
|
63
63
|
customMetadata
|
|
64
64
|
};
|
|
65
|
+
if (!artifact.inlineData && artifact.text === void 0) {
|
|
66
|
+
const fileData = artifact.fileData;
|
|
67
|
+
metadata.mimeType = fileData.mimeType;
|
|
68
|
+
}
|
|
65
69
|
this.artifacts[path].push({ part: artifact, metadata });
|
|
66
70
|
return Promise.resolve(version);
|
|
67
71
|
}
|