@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
|
@@ -0,0 +1,53 @@
|
|
|
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 case_utils_exports = {};
|
|
26
|
+
__export(case_utils_exports, {
|
|
27
|
+
camelCaseKeys: () => camelCaseKeys
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(case_utils_exports);
|
|
30
|
+
/**
|
|
31
|
+
* @license
|
|
32
|
+
* Copyright 2026 Google LLC
|
|
33
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
34
|
+
*/
|
|
35
|
+
function camelCaseKeys(val) {
|
|
36
|
+
if (Array.isArray(val)) {
|
|
37
|
+
return val.map(camelCaseKeys);
|
|
38
|
+
}
|
|
39
|
+
if (val !== null && typeof val === "object" && val.constructor === Object) {
|
|
40
|
+
const obj = val;
|
|
41
|
+
const newObj = {};
|
|
42
|
+
for (const key of Object.keys(obj)) {
|
|
43
|
+
const camelKey = key.replace(/_([a-z])/g, (_, g) => g.toUpperCase());
|
|
44
|
+
newObj[camelKey] = camelCaseKeys(obj[key]);
|
|
45
|
+
}
|
|
46
|
+
return newObj;
|
|
47
|
+
}
|
|
48
|
+
return val;
|
|
49
|
+
}
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
camelCaseKeys
|
|
53
|
+
});
|
|
@@ -24,9 +24,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var client_labels_exports = {};
|
|
26
26
|
__export(client_labels_exports, {
|
|
27
|
-
getClientLabels: () => getClientLabels
|
|
27
|
+
getClientLabels: () => getClientLabels,
|
|
28
|
+
parseUserAgent: () => parseUserAgent,
|
|
29
|
+
runWithClientLabel: () => runWithClientLabel
|
|
28
30
|
});
|
|
29
31
|
module.exports = __toCommonJS(client_labels_exports);
|
|
32
|
+
var import_node_async_hooks = require("node:async_hooks");
|
|
30
33
|
var import_version = require("../version.js");
|
|
31
34
|
var import_env_aware_utils = require("./env_aware_utils.js");
|
|
32
35
|
/**
|
|
@@ -38,19 +41,54 @@ const ADK_LABEL = "google-adk";
|
|
|
38
41
|
const LANGUAGE_LABEL = "gl-typescript";
|
|
39
42
|
const AGENT_ENGINE_TELEMETRY_TAG = "remote_reasoning_engine";
|
|
40
43
|
const AGENT_ENGINE_TELEMETRY_ENV_VARIABLE_NAME = "GOOGLE_CLOUD_AGENT_ENGINE_ID";
|
|
44
|
+
const clientLabelLocalStorage = new import_node_async_hooks.AsyncLocalStorage();
|
|
45
|
+
const USER_AGENT_PATTERNS = [
|
|
46
|
+
["Edge", /(?:Edg|Edge|EdgA)\/([0-9.]+)/i],
|
|
47
|
+
["Firefox", /(?:Firefox|FxiOS)\/([0-9.]+)/i],
|
|
48
|
+
["Chrome", /(?:Chrome|CriOS)\/([0-9.]+)/i],
|
|
49
|
+
["Safari", /Version\/([0-9.]+).*Safari/i]
|
|
50
|
+
];
|
|
51
|
+
function parseUserAgent(userAgent) {
|
|
52
|
+
if (!userAgent) {
|
|
53
|
+
return "Browser";
|
|
54
|
+
}
|
|
55
|
+
for (const [name, regex] of USER_AGENT_PATTERNS) {
|
|
56
|
+
const match = userAgent.match(regex);
|
|
57
|
+
if (match) {
|
|
58
|
+
return `${name}/${match[1]}`;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return "Browser";
|
|
62
|
+
}
|
|
41
63
|
function _getDefaultLabels() {
|
|
42
64
|
let frameworkLabel = `${ADK_LABEL}/${import_version.version}`;
|
|
43
65
|
if (!(0, import_env_aware_utils.isBrowser)() && process.env[AGENT_ENGINE_TELEMETRY_ENV_VARIABLE_NAME]) {
|
|
44
66
|
frameworkLabel = `${frameworkLabel}+${AGENT_ENGINE_TELEMETRY_TAG}`;
|
|
45
67
|
}
|
|
46
|
-
const
|
|
68
|
+
const languageLabelDetail = (0, import_env_aware_utils.isBrowser)() ? (
|
|
69
|
+
// eslint-disable-next-line no-undef
|
|
70
|
+
parseUserAgent(window.navigator.userAgent)
|
|
71
|
+
) : process.version;
|
|
72
|
+
const languageLabel = `${LANGUAGE_LABEL}/${languageLabelDetail}`;
|
|
47
73
|
return [frameworkLabel, languageLabel];
|
|
48
74
|
}
|
|
75
|
+
function runWithClientLabel(clientLabel, callback) {
|
|
76
|
+
if (typeof clientLabel !== "string" || clientLabel.trim() === "") {
|
|
77
|
+
throw new Error("Client label must be a non-empty string.");
|
|
78
|
+
}
|
|
79
|
+
return clientLabelLocalStorage.run(clientLabel, callback);
|
|
80
|
+
}
|
|
49
81
|
function getClientLabels() {
|
|
50
82
|
const labels = _getDefaultLabels();
|
|
83
|
+
const contextLabel = clientLabelLocalStorage.getStore();
|
|
84
|
+
if (contextLabel) {
|
|
85
|
+
labels.push(contextLabel);
|
|
86
|
+
}
|
|
51
87
|
return labels;
|
|
52
88
|
}
|
|
53
89
|
// Annotate the CommonJS export names for ESM import in node:
|
|
54
90
|
0 && (module.exports = {
|
|
55
|
-
getClientLabels
|
|
91
|
+
getClientLabels,
|
|
92
|
+
parseUserAgent,
|
|
93
|
+
runWithClientLabel
|
|
56
94
|
});
|
|
@@ -42,6 +42,10 @@ function isBrowser() {
|
|
|
42
42
|
}
|
|
43
43
|
const UUID_MASK = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
|
|
44
44
|
function randomUUID() {
|
|
45
|
+
var _a;
|
|
46
|
+
if ((_a = globalThis.crypto) == null ? void 0 : _a.randomUUID) {
|
|
47
|
+
return globalThis.crypto.randomUUID();
|
|
48
|
+
}
|
|
45
49
|
let uuid = "";
|
|
46
50
|
for (let i = 0; i < UUID_MASK.length; i++) {
|
|
47
51
|
const randomValue = Math.random() * 16 | 0;
|
|
@@ -57,7 +61,16 @@ function randomUUID() {
|
|
|
57
61
|
}
|
|
58
62
|
function base64Encode(data) {
|
|
59
63
|
if (isBrowser()) {
|
|
60
|
-
|
|
64
|
+
let strData = "";
|
|
65
|
+
if (typeof data === "string") {
|
|
66
|
+
strData = data;
|
|
67
|
+
} else {
|
|
68
|
+
const len = data.byteLength;
|
|
69
|
+
for (let i = 0; i < len; i++) {
|
|
70
|
+
strData += String.fromCharCode(data[i]);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return window.btoa(strData);
|
|
61
74
|
}
|
|
62
75
|
return Buffer.from(data).toString("base64");
|
|
63
76
|
}
|
|
@@ -0,0 +1,284 @@
|
|
|
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 live_connection_utils_exports = {};
|
|
26
|
+
__export(live_connection_utils_exports, {
|
|
27
|
+
LiveResponseAggregator: () => LiveResponseAggregator
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(live_connection_utils_exports);
|
|
30
|
+
var import_model_name = require("./model_name.js");
|
|
31
|
+
/**
|
|
32
|
+
* @license
|
|
33
|
+
* Copyright 2026 Google LLC
|
|
34
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
35
|
+
*/
|
|
36
|
+
class LiveResponseAggregator {
|
|
37
|
+
constructor(modelVersion) {
|
|
38
|
+
this.modelVersion = modelVersion;
|
|
39
|
+
this.text = "";
|
|
40
|
+
this.isThought = false;
|
|
41
|
+
this.toolCallParts = [];
|
|
42
|
+
this.pendingGroundingMetadata = void 0;
|
|
43
|
+
this.inputTranscriptionText = "";
|
|
44
|
+
this.outputTranscriptionText = "";
|
|
45
|
+
}
|
|
46
|
+
*processMessage(message) {
|
|
47
|
+
if (message.usageMetadata) {
|
|
48
|
+
yield {
|
|
49
|
+
usageMetadata: message.usageMetadata,
|
|
50
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (message.serverContent) {
|
|
54
|
+
const serverContent = message.serverContent;
|
|
55
|
+
const content = serverContent.modelTurn;
|
|
56
|
+
if (serverContent.groundingMetadata) {
|
|
57
|
+
this.pendingGroundingMetadata = serverContent.groundingMetadata;
|
|
58
|
+
}
|
|
59
|
+
if (!(content && content.parts) && serverContent.groundingMetadata && !serverContent.turnComplete) {
|
|
60
|
+
yield {
|
|
61
|
+
groundingMetadata: serverContent.groundingMetadata,
|
|
62
|
+
...serverContent.interrupted !== void 0 ? { interrupted: serverContent.interrupted } : {},
|
|
63
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (content && content.parts) {
|
|
67
|
+
const llmResponse = {
|
|
68
|
+
content,
|
|
69
|
+
...serverContent.interrupted !== void 0 ? { interrupted: serverContent.interrupted } : {},
|
|
70
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
71
|
+
};
|
|
72
|
+
if (!serverContent.turnComplete && serverContent.groundingMetadata) {
|
|
73
|
+
llmResponse.groundingMetadata = serverContent.groundingMetadata;
|
|
74
|
+
}
|
|
75
|
+
const hasInlineData = content.parts.some((p) => p.inlineData);
|
|
76
|
+
for (const part of content.parts) {
|
|
77
|
+
if (part.text) {
|
|
78
|
+
const currentIsThought = !!part.thought;
|
|
79
|
+
if (this.text && currentIsThought !== this.isThought) {
|
|
80
|
+
yield this.buildFullTextResponse(this.text, this.isThought);
|
|
81
|
+
this.text = "";
|
|
82
|
+
this.isThought = false;
|
|
83
|
+
}
|
|
84
|
+
this.text += part.text;
|
|
85
|
+
this.isThought = currentIsThought;
|
|
86
|
+
llmResponse.partial = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (this.text && !content.parts.some((p) => p.text) && !hasInlineData) {
|
|
90
|
+
yield this.buildFullTextResponse(this.text, this.isThought);
|
|
91
|
+
this.text = "";
|
|
92
|
+
this.isThought = false;
|
|
93
|
+
}
|
|
94
|
+
yield llmResponse;
|
|
95
|
+
}
|
|
96
|
+
if (serverContent.inputTranscription) {
|
|
97
|
+
if (serverContent.inputTranscription.text) {
|
|
98
|
+
this.inputTranscriptionText += serverContent.inputTranscription.text;
|
|
99
|
+
yield {
|
|
100
|
+
inputTranscription: {
|
|
101
|
+
text: serverContent.inputTranscription.text,
|
|
102
|
+
finished: false
|
|
103
|
+
},
|
|
104
|
+
partial: true,
|
|
105
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
if (serverContent.inputTranscription.finished) {
|
|
109
|
+
yield {
|
|
110
|
+
inputTranscription: {
|
|
111
|
+
text: this.inputTranscriptionText,
|
|
112
|
+
finished: true
|
|
113
|
+
},
|
|
114
|
+
partial: false,
|
|
115
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
116
|
+
};
|
|
117
|
+
this.inputTranscriptionText = "";
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (serverContent.outputTranscription) {
|
|
121
|
+
if (serverContent.outputTranscription.text) {
|
|
122
|
+
this.outputTranscriptionText += serverContent.outputTranscription.text;
|
|
123
|
+
yield {
|
|
124
|
+
outputTranscription: {
|
|
125
|
+
text: serverContent.outputTranscription.text,
|
|
126
|
+
finished: false
|
|
127
|
+
},
|
|
128
|
+
partial: true,
|
|
129
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
if (serverContent.outputTranscription.finished) {
|
|
133
|
+
yield {
|
|
134
|
+
outputTranscription: {
|
|
135
|
+
text: this.outputTranscriptionText,
|
|
136
|
+
finished: true
|
|
137
|
+
},
|
|
138
|
+
partial: false,
|
|
139
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
140
|
+
};
|
|
141
|
+
this.outputTranscriptionText = "";
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (serverContent.interrupted || serverContent.turnComplete || serverContent.generationComplete) {
|
|
145
|
+
if (this.inputTranscriptionText) {
|
|
146
|
+
yield {
|
|
147
|
+
inputTranscription: {
|
|
148
|
+
text: this.inputTranscriptionText,
|
|
149
|
+
finished: true
|
|
150
|
+
},
|
|
151
|
+
partial: false,
|
|
152
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
153
|
+
};
|
|
154
|
+
this.inputTranscriptionText = "";
|
|
155
|
+
}
|
|
156
|
+
if (this.outputTranscriptionText) {
|
|
157
|
+
yield {
|
|
158
|
+
outputTranscription: {
|
|
159
|
+
text: this.outputTranscriptionText,
|
|
160
|
+
finished: true
|
|
161
|
+
},
|
|
162
|
+
partial: false,
|
|
163
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
164
|
+
};
|
|
165
|
+
this.outputTranscriptionText = "";
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (serverContent.turnComplete) {
|
|
169
|
+
let gMetadataToYield = this.pendingGroundingMetadata;
|
|
170
|
+
if (this.text) {
|
|
171
|
+
yield this.buildFullTextResponse(
|
|
172
|
+
this.text,
|
|
173
|
+
this.isThought,
|
|
174
|
+
gMetadataToYield
|
|
175
|
+
);
|
|
176
|
+
this.text = "";
|
|
177
|
+
this.isThought = false;
|
|
178
|
+
gMetadataToYield = void 0;
|
|
179
|
+
}
|
|
180
|
+
if (this.toolCallParts.length > 0) {
|
|
181
|
+
yield {
|
|
182
|
+
content: { role: "model", parts: this.toolCallParts },
|
|
183
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
184
|
+
};
|
|
185
|
+
this.toolCallParts = [];
|
|
186
|
+
}
|
|
187
|
+
const finalResponse = {
|
|
188
|
+
turnComplete: true,
|
|
189
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
190
|
+
};
|
|
191
|
+
if (serverContent.interrupted !== void 0) {
|
|
192
|
+
finalResponse.interrupted = serverContent.interrupted;
|
|
193
|
+
}
|
|
194
|
+
const finalGrounding = serverContent.groundingMetadata || gMetadataToYield;
|
|
195
|
+
if (finalGrounding !== void 0 && finalGrounding !== null) {
|
|
196
|
+
finalResponse.groundingMetadata = finalGrounding;
|
|
197
|
+
}
|
|
198
|
+
yield finalResponse;
|
|
199
|
+
}
|
|
200
|
+
if (serverContent.interrupted) {
|
|
201
|
+
if (this.text) {
|
|
202
|
+
yield this.buildFullTextResponse(this.text, this.isThought);
|
|
203
|
+
this.text = "";
|
|
204
|
+
this.isThought = false;
|
|
205
|
+
} else {
|
|
206
|
+
yield {
|
|
207
|
+
interrupted: serverContent.interrupted,
|
|
208
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (message.toolCall) {
|
|
214
|
+
if (this.text) {
|
|
215
|
+
yield this.buildFullTextResponse(this.text, this.isThought);
|
|
216
|
+
this.text = "";
|
|
217
|
+
this.isThought = false;
|
|
218
|
+
}
|
|
219
|
+
if (message.toolCall.functionCalls) {
|
|
220
|
+
this.toolCallParts.push(
|
|
221
|
+
...message.toolCall.functionCalls.map((fc) => ({
|
|
222
|
+
functionCall: fc
|
|
223
|
+
}))
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
const isGemini3x = (0, import_model_name.isGemini3xFlashLive)(this.modelVersion);
|
|
227
|
+
if (isGemini3x && this.toolCallParts.length > 0) {
|
|
228
|
+
yield {
|
|
229
|
+
content: { role: "model", parts: this.toolCallParts },
|
|
230
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
231
|
+
};
|
|
232
|
+
this.toolCallParts = [];
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (message.sessionResumptionUpdate) {
|
|
236
|
+
yield {
|
|
237
|
+
liveSessionResumptionUpdate: message.sessionResumptionUpdate,
|
|
238
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
if (message.goAway) {
|
|
242
|
+
yield {
|
|
243
|
+
goAway: message.goAway,
|
|
244
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Flushes any remaining aggregated components when the connection is closed.
|
|
250
|
+
*/
|
|
251
|
+
*close() {
|
|
252
|
+
if (this.toolCallParts.length > 0) {
|
|
253
|
+
yield {
|
|
254
|
+
content: { role: "model", parts: this.toolCallParts },
|
|
255
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
256
|
+
};
|
|
257
|
+
this.toolCallParts = [];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
buildFullTextResponse(text, isThought, groundingMetadata) {
|
|
261
|
+
const part = { text };
|
|
262
|
+
if (isThought) {
|
|
263
|
+
part.thought = true;
|
|
264
|
+
}
|
|
265
|
+
const response = {
|
|
266
|
+
content: {
|
|
267
|
+
role: "model",
|
|
268
|
+
parts: [part]
|
|
269
|
+
},
|
|
270
|
+
partial: false
|
|
271
|
+
};
|
|
272
|
+
if (groundingMetadata !== void 0 && groundingMetadata !== null) {
|
|
273
|
+
response.groundingMetadata = groundingMetadata;
|
|
274
|
+
}
|
|
275
|
+
if (this.modelVersion) {
|
|
276
|
+
response.modelVersion = this.modelVersion;
|
|
277
|
+
}
|
|
278
|
+
return response;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
282
|
+
0 && (module.exports = {
|
|
283
|
+
LiveResponseAggregator
|
|
284
|
+
});
|
|
@@ -27,6 +27,7 @@ __export(model_name_exports, {
|
|
|
27
27
|
extractModelName: () => extractModelName,
|
|
28
28
|
isGemini1Model: () => isGemini1Model,
|
|
29
29
|
isGemini2OrAbove: () => isGemini2OrAbove,
|
|
30
|
+
isGemini3xFlashLive: () => isGemini3xFlashLive,
|
|
30
31
|
isGeminiModel: () => isGeminiModel,
|
|
31
32
|
isGeminiModelIdCheckDisabled: () => isGeminiModelIdCheckDisabled
|
|
32
33
|
});
|
|
@@ -77,6 +78,13 @@ function isGemini2OrAbove(modelString) {
|
|
|
77
78
|
const parsedVersion = parseVersion(versionString);
|
|
78
79
|
return parsedVersion.valid && parsedVersion.major >= 2;
|
|
79
80
|
}
|
|
81
|
+
function isGemini3xFlashLive(modelString) {
|
|
82
|
+
if (!modelString) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
const modelName = extractModelName(modelString);
|
|
86
|
+
return modelName.startsWith("gemini-3.") && modelName.includes("-flash-live");
|
|
87
|
+
}
|
|
80
88
|
function isGeminiModelIdCheckDisabled() {
|
|
81
89
|
return (0, import_env_aware_utils.getBooleanEnvVar)("ADK_DISABLE_GEMINI_MODEL_ID_CHECK");
|
|
82
90
|
}
|
|
@@ -85,6 +93,7 @@ function isGeminiModelIdCheckDisabled() {
|
|
|
85
93
|
extractModelName,
|
|
86
94
|
isGemini1Model,
|
|
87
95
|
isGemini2OrAbove,
|
|
96
|
+
isGemini3xFlashLive,
|
|
88
97
|
isGeminiModel,
|
|
89
98
|
isGeminiModelIdCheckDisabled
|
|
90
99
|
});
|
|
@@ -38,6 +38,7 @@ var import_llm_response = require("../models/llm_response.js");
|
|
|
38
38
|
* Copyright 2026 Google LLC
|
|
39
39
|
* SPDX-License-Identifier: Apache-2.0
|
|
40
40
|
*/
|
|
41
|
+
const UNSAFE_PROPERTY_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
41
42
|
class ProgressiveStrategy {
|
|
42
43
|
constructor() {
|
|
43
44
|
this.partsSequence = [];
|
|
@@ -104,10 +105,13 @@ class ProgressiveStrategy {
|
|
|
104
105
|
const pathParts = import_jsonpath_plus.JSONPath.toPathArray(jsonPath).filter(
|
|
105
106
|
(p) => p !== "$" && p !== "$["
|
|
106
107
|
);
|
|
108
|
+
if (pathParts.some((part) => UNSAFE_PROPERTY_KEYS.has(String(part)))) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
107
111
|
let current = this.currentFcArgs;
|
|
108
112
|
for (let i = 0; i < pathParts.length - 1; i++) {
|
|
109
113
|
const part = pathParts[i];
|
|
110
|
-
if (!(part
|
|
114
|
+
if (!Object.prototype.hasOwnProperty.call(current, part)) {
|
|
111
115
|
current[part] = {};
|
|
112
116
|
}
|
|
113
117
|
current = current[part];
|
|
@@ -299,17 +303,13 @@ class StreamingResponseAggregator {
|
|
|
299
303
|
)) {
|
|
300
304
|
this.isProgressiveMode = isProgressiveMode;
|
|
301
305
|
this.lastThoughtSignature = {};
|
|
302
|
-
this.sawFunctionCall = false;
|
|
303
306
|
this.strategy = this.isProgressiveMode ? new ProgressiveStrategy() : new NonProgressiveStrategy();
|
|
304
307
|
}
|
|
305
308
|
async *processResponse(response) {
|
|
306
309
|
var _a, _b;
|
|
307
310
|
const llmResponse = (0, import_llm_response.createLlmResponse)(response);
|
|
308
311
|
const parts = (_b = (_a = llmResponse.content) == null ? void 0 : _a.parts) != null ? _b : [];
|
|
309
|
-
if (parts.
|
|
310
|
-
this.sawFunctionCall = true;
|
|
311
|
-
}
|
|
312
|
-
if (this.sawFunctionCall && llmResponse.finishReason === import_genai.FinishReason.STOP && parts.length > 0 && parts.every(isEmptyContentPart)) {
|
|
312
|
+
if (parts.every(isEmptyContentPart) && (llmResponse.finishReason === void 0 || llmResponse.finishReason === import_genai.FinishReason.STOP)) {
|
|
313
313
|
if (llmResponse.usageMetadata) {
|
|
314
314
|
this.usageMetadata = llmResponse.usageMetadata;
|
|
315
315
|
}
|
|
@@ -349,16 +349,23 @@ class StreamingResponseAggregator {
|
|
|
349
349
|
close() {
|
|
350
350
|
var _a, _b, _c;
|
|
351
351
|
const finalParts = this.strategy.close();
|
|
352
|
-
|
|
352
|
+
const hasMetadata = this.usageMetadata !== void 0 || this.groundingMetadata !== void 0 || this.citationMetadata !== void 0;
|
|
353
|
+
if (!finalParts && !hasMetadata) {
|
|
353
354
|
return void 0;
|
|
354
355
|
}
|
|
355
356
|
const candidate = (_b = (_a = this.response) == null ? void 0 : _a.candidates) == null ? void 0 : _b[0];
|
|
356
357
|
const finishReason = (_c = this.finishReason) != null ? _c : candidate == null ? void 0 : candidate.finishReason;
|
|
357
358
|
return {
|
|
358
|
-
content
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
359
|
+
// Only attach a model `content` when there are actual parts to emit. When
|
|
360
|
+
// the turn accumulated no parts (e.g. a function call that was already
|
|
361
|
+
// flushed, followed by a trailing STOP chunk that carries only usage
|
|
362
|
+
// metadata) we still surface that trailing metadata, but MUST NOT emit
|
|
363
|
+
// `content: { parts: [] }`. An empty-parts model turn corrupts the session
|
|
364
|
+
// history: on the next request the Vertex AI backend rejects the whole
|
|
365
|
+
// call with HTTP 400 "Unable to submit request because it must include at
|
|
366
|
+
// least one parts field", which breaks multi-turn tool-using sessions
|
|
367
|
+
// right after the first tool call (google/adk-js#21, #22).
|
|
368
|
+
content: finalParts ? { role: "model", parts: finalParts } : void 0,
|
|
362
369
|
groundingMetadata: this.groundingMetadata,
|
|
363
370
|
citationMetadata: this.citationMetadata,
|
|
364
371
|
errorCode: finishReason === import_genai.FinishReason.STOP ? void 0 : finishReason,
|
|
@@ -0,0 +1,62 @@
|
|
|
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 task_exports = {};
|
|
26
|
+
__export(task_exports, {
|
|
27
|
+
Task: () => Task
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(task_exports);
|
|
30
|
+
/**
|
|
31
|
+
* @license
|
|
32
|
+
* Copyright 2026 Google LLC
|
|
33
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
34
|
+
*/
|
|
35
|
+
class Task {
|
|
36
|
+
constructor(executable) {
|
|
37
|
+
this.executable = executable;
|
|
38
|
+
this.isDone = false;
|
|
39
|
+
this.abortController = new AbortController();
|
|
40
|
+
const markDone = () => {
|
|
41
|
+
this.isDone = true;
|
|
42
|
+
};
|
|
43
|
+
this.promise = executable(this.abortController.signal);
|
|
44
|
+
this.promise.then(markDone).catch(markDone);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Cancels the task execution.
|
|
48
|
+
*/
|
|
49
|
+
cancel() {
|
|
50
|
+
this.abortController.abort();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Returns true if the task has completed (either resolved or rejected).
|
|
54
|
+
*/
|
|
55
|
+
done() {
|
|
56
|
+
return this.isDone;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
Task
|
|
62
|
+
});
|
package/dist/cjs/version.js
CHANGED
|
@@ -32,7 +32,7 @@ module.exports = __toCommonJS(version_exports);
|
|
|
32
32
|
* Copyright 2025 Google LLC
|
|
33
33
|
* SPDX-License-Identifier: Apache-2.0
|
|
34
34
|
*/
|
|
35
|
-
const version = "1.
|
|
35
|
+
const version = "1.4.0";
|
|
36
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
37
|
0 && (module.exports = {
|
|
38
38
|
version
|
|
@@ -5,9 +5,14 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
5
5
|
* Copyright 2025 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
|
+
import { Task } from "../utils/task.js";
|
|
8
9
|
class ActiveStreamingTool {
|
|
9
10
|
constructor(params = {}) {
|
|
10
|
-
|
|
11
|
+
if (params.task instanceof Promise) {
|
|
12
|
+
this.task = new Task(() => params.task);
|
|
13
|
+
} else {
|
|
14
|
+
this.task = params.task;
|
|
15
|
+
}
|
|
11
16
|
this.stream = params.stream;
|
|
12
17
|
}
|
|
13
18
|
}
|
|
@@ -99,9 +99,27 @@ class BaseAgent {
|
|
|
99
99
|
ctx,
|
|
100
100
|
this,
|
|
101
101
|
async function* () {
|
|
102
|
+
var _a2, _b;
|
|
103
|
+
const context2 = this.createInvocationContext(parentContext);
|
|
104
|
+
const beforeAgentCallbackEvent = await this.handleBeforeAgentCallback(context2);
|
|
105
|
+
if (beforeAgentCallbackEvent) {
|
|
106
|
+
yield beforeAgentCallbackEvent;
|
|
107
|
+
}
|
|
108
|
+
if (context2.endInvocation || ((_a2 = parentContext.abortSignal) == null ? void 0 : _a2.aborted)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
for await (const event of this.runLiveImpl(context2)) {
|
|
112
|
+
yield event;
|
|
113
|
+
}
|
|
114
|
+
if (context2.endInvocation || ((_b = parentContext.abortSignal) == null ? void 0 : _b.aborted)) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const afterAgentCallbackEvent = await this.handleAfterAgentCallback(context2);
|
|
118
|
+
if (afterAgentCallbackEvent) {
|
|
119
|
+
yield afterAgentCallbackEvent;
|
|
120
|
+
}
|
|
102
121
|
}
|
|
103
122
|
);
|
|
104
|
-
throw new Error("Live mode is not implemented yet.");
|
|
105
123
|
} finally {
|
|
106
124
|
span.end();
|
|
107
125
|
}
|
|
@@ -56,9 +56,6 @@ class Context extends ReadonlyContext {
|
|
|
56
56
|
throw new Error("Artifact service is not initialized.");
|
|
57
57
|
}
|
|
58
58
|
return this.invocationContext.artifactService.loadArtifact({
|
|
59
|
-
appName: this.invocationContext.appName,
|
|
60
|
-
userId: this.invocationContext.userId,
|
|
61
|
-
sessionId: this.invocationContext.session.id,
|
|
62
59
|
filename,
|
|
63
60
|
version
|
|
64
61
|
});
|
|
@@ -75,9 +72,6 @@ class Context extends ReadonlyContext {
|
|
|
75
72
|
throw new Error("Artifact service is not initialized.");
|
|
76
73
|
}
|
|
77
74
|
const version = await this.invocationContext.artifactService.saveArtifact({
|
|
78
|
-
appName: this.invocationContext.appName,
|
|
79
|
-
userId: this.invocationContext.userId,
|
|
80
|
-
sessionId: this.invocationContext.session.id,
|
|
81
75
|
filename,
|
|
82
76
|
artifact
|
|
83
77
|
});
|
|
@@ -110,11 +104,7 @@ class Context extends ReadonlyContext {
|
|
|
110
104
|
if (!this.invocationContext.artifactService) {
|
|
111
105
|
throw new Error("Artifact service is not initialized.");
|
|
112
106
|
}
|
|
113
|
-
return this.invocationContext.artifactService.listArtifactKeys(
|
|
114
|
-
appName: this.invocationContext.session.appName,
|
|
115
|
-
userId: this.invocationContext.session.userId,
|
|
116
|
-
sessionId: this.invocationContext.session.id
|
|
117
|
-
});
|
|
107
|
+
return this.invocationContext.artifactService.listArtifactKeys();
|
|
118
108
|
}
|
|
119
109
|
/**
|
|
120
110
|
* Searches the memory of the current user.
|