@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,82 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
6
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
7
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
8
|
+
if (decorator = decorators[i])
|
|
9
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
10
|
+
if (kind && result) __defProp(target, key, result);
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @license
|
|
15
|
+
* Copyright 2026 Google LLC
|
|
16
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
*/
|
|
18
|
+
import { Type } from "@google/genai";
|
|
19
|
+
import { experimental } from "../../utils/experimental.js";
|
|
20
|
+
import { logger } from "../../utils/logger.js";
|
|
21
|
+
import { BaseTool } from "../base_tool.js";
|
|
22
|
+
let SearchSkillsTool = class extends BaseTool {
|
|
23
|
+
constructor(toolset) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
if (!toolset.registry) {
|
|
26
|
+
throw new Error("SearchSkillsTool requires a configured skill registry.");
|
|
27
|
+
}
|
|
28
|
+
super({
|
|
29
|
+
name: "search_skills",
|
|
30
|
+
description: ((_b = (_a = toolset.registry).searchToolDescription) == null ? void 0 : _b.call(_a)) || "Searches for relevant skills in the registry based on a semantic or keyword query."
|
|
31
|
+
});
|
|
32
|
+
this.toolset = toolset;
|
|
33
|
+
}
|
|
34
|
+
_getDeclaration() {
|
|
35
|
+
return {
|
|
36
|
+
name: this.name,
|
|
37
|
+
description: this.description,
|
|
38
|
+
parameters: {
|
|
39
|
+
type: Type.OBJECT,
|
|
40
|
+
properties: {
|
|
41
|
+
query: {
|
|
42
|
+
type: Type.STRING,
|
|
43
|
+
description: "Semantic or keyword search query."
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
required: ["query"]
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async runAsync({ args }) {
|
|
51
|
+
const query = args["query"];
|
|
52
|
+
if (!query) {
|
|
53
|
+
return {
|
|
54
|
+
error: "Argument 'query' is required.",
|
|
55
|
+
error_code: "INVALID_ARGUMENTS"
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const results = await this.toolset.registry.searchSkills(query);
|
|
60
|
+
return results.filter((r) => {
|
|
61
|
+
if (this.toolset.skills[r.name]) {
|
|
62
|
+
logger.warn(
|
|
63
|
+
`Skill naming conflict: skill '${r.name}' already exists locally. Registry skill is filtered.`
|
|
64
|
+
);
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
});
|
|
69
|
+
} catch (e) {
|
|
70
|
+
return {
|
|
71
|
+
error: `Failed to search skills from registry: ${e.message || e}`,
|
|
72
|
+
error_code: "REGISTRY_ERROR"
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
SearchSkillsTool = __decorateClass([
|
|
78
|
+
experimental
|
|
79
|
+
], SearchSkillsTool);
|
|
80
|
+
export {
|
|
81
|
+
SearchSkillsTool
|
|
82
|
+
};
|
|
@@ -18,6 +18,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
18
18
|
import { appendInstructions } from "../../models/llm_request.js";
|
|
19
19
|
import { formatSkillsAsXml } from "../../skills/prompt.js";
|
|
20
20
|
import { experimental } from "../../utils/experimental.js";
|
|
21
|
+
import { logger } from "../../utils/logger.js";
|
|
21
22
|
import { BaseTool } from "../base_tool.js";
|
|
22
23
|
import { BaseToolset } from "../base_toolset.js";
|
|
23
24
|
import { ListSkillsTool } from "./list_skills_tool.js";
|
|
@@ -25,6 +26,7 @@ import { LoadSkillResourceTool } from "./load_skill_resource_tool.js";
|
|
|
25
26
|
import { LoadSkillTool } from "./load_skill_tool.js";
|
|
26
27
|
import { RunSkillInlineScriptTool } from "./run_skill_inline_script_tool.js";
|
|
27
28
|
import { RunSkillScriptTool } from "./run_skill_script_tool.js";
|
|
29
|
+
import { SearchSkillsTool } from "./search_skills_tool.js";
|
|
28
30
|
const DEFAULT_SKILL_SYSTEM_INSTRUCTION = `You can use specialized 'skills' to help you with complex tasks. You MUST use the skill tools to interact with these skills.
|
|
29
31
|
|
|
30
32
|
Skills are folders of instructions and resources that extend your capabilities for specialized tasks. Each skill folder contains:
|
|
@@ -44,9 +46,11 @@ let SkillToolset = class extends BaseToolset {
|
|
|
44
46
|
constructor(skills, options = {}) {
|
|
45
47
|
super([], "adk_skill_toolset");
|
|
46
48
|
this.toolCache = /* @__PURE__ */ new Map();
|
|
49
|
+
this.fetchedSkillCache = /* @__PURE__ */ new Map();
|
|
47
50
|
this.skills = Array.isArray(skills) ? Object.fromEntries(skills.map((s) => [s.frontmatter.name, s])) : skills;
|
|
48
51
|
this.codeExecutor = options.codeExecutor;
|
|
49
52
|
this.additionalTools = options.additionalTools || [];
|
|
53
|
+
this.registry = options.registry;
|
|
50
54
|
this.tools = [
|
|
51
55
|
new ListSkillsTool(this),
|
|
52
56
|
new LoadSkillTool(this),
|
|
@@ -54,24 +58,55 @@ let SkillToolset = class extends BaseToolset {
|
|
|
54
58
|
new RunSkillScriptTool(this),
|
|
55
59
|
new RunSkillInlineScriptTool(this)
|
|
56
60
|
];
|
|
61
|
+
if (this.registry) {
|
|
62
|
+
this.tools.push(new SearchSkillsTool(this));
|
|
63
|
+
}
|
|
57
64
|
}
|
|
58
65
|
async getTools(context) {
|
|
59
66
|
const dynamicTools = await this.resolveAdditionalTools(context);
|
|
60
67
|
return [...this.tools, ...dynamicTools];
|
|
61
68
|
}
|
|
62
69
|
async close() {
|
|
70
|
+
this.fetchedSkillCache.clear();
|
|
63
71
|
}
|
|
64
72
|
getSkill(name) {
|
|
65
73
|
return this.skills[name];
|
|
66
74
|
}
|
|
75
|
+
async getOrFetchSkill(name, invocationId) {
|
|
76
|
+
if (this.skills[name]) {
|
|
77
|
+
return this.skills[name];
|
|
78
|
+
}
|
|
79
|
+
if (!this.registry) {
|
|
80
|
+
return void 0;
|
|
81
|
+
}
|
|
82
|
+
const contextKey = invocationId || "default";
|
|
83
|
+
if (!this.fetchedSkillCache.has(contextKey)) {
|
|
84
|
+
this.fetchedSkillCache.set(contextKey, /* @__PURE__ */ new Map());
|
|
85
|
+
}
|
|
86
|
+
const cache = this.fetchedSkillCache.get(contextKey);
|
|
87
|
+
if (cache.has(name)) {
|
|
88
|
+
return cache.get(name);
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
const skill = await this.registry.getSkill(name);
|
|
92
|
+
cache.set(name, skill);
|
|
93
|
+
return skill;
|
|
94
|
+
} catch (e) {
|
|
95
|
+
logger.warn(`Failed to fetch skill '${name}' from registry: ${e}`);
|
|
96
|
+
throw e;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
67
99
|
async processLlmRequest(toolContext, llmRequest) {
|
|
68
100
|
await super.processLlmRequest(toolContext, llmRequest);
|
|
69
101
|
const skills = Object.values(this.skills);
|
|
70
102
|
const skillsXml = formatSkillsAsXml(skills);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
103
|
+
const instructions = [DEFAULT_SKILL_SYSTEM_INSTRUCTION, skillsXml];
|
|
104
|
+
if (this.registry) {
|
|
105
|
+
instructions.push(
|
|
106
|
+
"\nIf the locally available skills are not sufficient to complete your task, you can use the `search_skills` tool to discover additional skills from the registry."
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
appendInstructions(llmRequest, instructions);
|
|
75
110
|
}
|
|
76
111
|
async resolveAdditionalTools(context) {
|
|
77
112
|
if (!context) return [];
|
|
@@ -85,7 +120,7 @@ let SkillToolset = class extends BaseToolset {
|
|
|
85
120
|
}
|
|
86
121
|
const additionalToolNames = /* @__PURE__ */ new Set();
|
|
87
122
|
for (const skillName of activatedSkills) {
|
|
88
|
-
const skill = this.
|
|
123
|
+
const skill = await this.getOrFetchSkill(skillName, context.invocationId);
|
|
89
124
|
if (skill && skill.frontmatter.metadata) {
|
|
90
125
|
const tools = skill.frontmatter.metadata["adk_additional_tools"];
|
|
91
126
|
if (tools) {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2026 Google LLC
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
class AsyncLocalStorage {
|
|
9
|
+
run(store, callback) {
|
|
10
|
+
const previous = this.store;
|
|
11
|
+
this.store = store;
|
|
12
|
+
try {
|
|
13
|
+
return callback();
|
|
14
|
+
} finally {
|
|
15
|
+
this.store = previous;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
getStore() {
|
|
19
|
+
return this.store;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
AsyncLocalStorage
|
|
24
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2026 Google LLC
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
class AsyncQueue {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.queue = [];
|
|
11
|
+
this.resolvers = [];
|
|
12
|
+
this.closed = false;
|
|
13
|
+
}
|
|
14
|
+
push(value) {
|
|
15
|
+
if (this.closed) return;
|
|
16
|
+
if (this.resolvers.length > 0) {
|
|
17
|
+
const { resolve } = this.resolvers.shift();
|
|
18
|
+
resolve({ value, done: false });
|
|
19
|
+
} else {
|
|
20
|
+
this.queue.push(value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
error(err) {
|
|
24
|
+
this.errorVal = err;
|
|
25
|
+
while (this.resolvers.length > 0) {
|
|
26
|
+
const { reject } = this.resolvers.shift();
|
|
27
|
+
reject(err);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
close() {
|
|
31
|
+
this.closed = true;
|
|
32
|
+
while (this.resolvers.length > 0) {
|
|
33
|
+
const { resolve } = this.resolvers.shift();
|
|
34
|
+
resolve({ value: void 0, done: true });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
[Symbol.asyncIterator]() {
|
|
38
|
+
return {
|
|
39
|
+
next: () => {
|
|
40
|
+
if (this.errorVal) {
|
|
41
|
+
const err = this.errorVal;
|
|
42
|
+
this.errorVal = void 0;
|
|
43
|
+
return Promise.reject(err);
|
|
44
|
+
}
|
|
45
|
+
if (this.queue.length > 0) {
|
|
46
|
+
return Promise.resolve({ value: this.queue.shift(), done: false });
|
|
47
|
+
}
|
|
48
|
+
if (this.closed) {
|
|
49
|
+
return Promise.resolve({ value: void 0, done: true });
|
|
50
|
+
}
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
this.resolvers.push({ resolve, reject });
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
AsyncQueue
|
|
60
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2026 Google LLC
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
function camelCaseKeys(val) {
|
|
9
|
+
if (Array.isArray(val)) {
|
|
10
|
+
return val.map(camelCaseKeys);
|
|
11
|
+
}
|
|
12
|
+
if (val !== null && typeof val === "object" && val.constructor === Object) {
|
|
13
|
+
const obj = val;
|
|
14
|
+
const newObj = {};
|
|
15
|
+
for (const key of Object.keys(obj)) {
|
|
16
|
+
const camelKey = key.replace(/_([a-z])/g, (_, g) => g.toUpperCase());
|
|
17
|
+
newObj[camelKey] = camelCaseKeys(obj[key]);
|
|
18
|
+
}
|
|
19
|
+
return newObj;
|
|
20
|
+
}
|
|
21
|
+
return val;
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
camelCaseKeys
|
|
25
|
+
};
|
|
@@ -5,24 +5,60 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
5
5
|
* Copyright 2025 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8
9
|
import { version } from "../version.js";
|
|
9
10
|
import { isBrowser } from "./env_aware_utils.js";
|
|
10
11
|
const ADK_LABEL = "google-adk";
|
|
11
12
|
const LANGUAGE_LABEL = "gl-typescript";
|
|
12
13
|
const AGENT_ENGINE_TELEMETRY_TAG = "remote_reasoning_engine";
|
|
13
14
|
const AGENT_ENGINE_TELEMETRY_ENV_VARIABLE_NAME = "GOOGLE_CLOUD_AGENT_ENGINE_ID";
|
|
15
|
+
const clientLabelLocalStorage = new AsyncLocalStorage();
|
|
16
|
+
const USER_AGENT_PATTERNS = [
|
|
17
|
+
["Edge", /(?:Edg|Edge|EdgA)\/([0-9.]+)/i],
|
|
18
|
+
["Firefox", /(?:Firefox|FxiOS)\/([0-9.]+)/i],
|
|
19
|
+
["Chrome", /(?:Chrome|CriOS)\/([0-9.]+)/i],
|
|
20
|
+
["Safari", /Version\/([0-9.]+).*Safari/i]
|
|
21
|
+
];
|
|
22
|
+
function parseUserAgent(userAgent) {
|
|
23
|
+
if (!userAgent) {
|
|
24
|
+
return "Browser";
|
|
25
|
+
}
|
|
26
|
+
for (const [name, regex] of USER_AGENT_PATTERNS) {
|
|
27
|
+
const match = userAgent.match(regex);
|
|
28
|
+
if (match) {
|
|
29
|
+
return `${name}/${match[1]}`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return "Browser";
|
|
33
|
+
}
|
|
14
34
|
function _getDefaultLabels() {
|
|
15
35
|
let frameworkLabel = `${ADK_LABEL}/${version}`;
|
|
16
36
|
if (!isBrowser() && process.env[AGENT_ENGINE_TELEMETRY_ENV_VARIABLE_NAME]) {
|
|
17
37
|
frameworkLabel = `${frameworkLabel}+${AGENT_ENGINE_TELEMETRY_TAG}`;
|
|
18
38
|
}
|
|
19
|
-
const
|
|
39
|
+
const languageLabelDetail = isBrowser() ? (
|
|
40
|
+
// eslint-disable-next-line no-undef
|
|
41
|
+
parseUserAgent(window.navigator.userAgent)
|
|
42
|
+
) : process.version;
|
|
43
|
+
const languageLabel = `${LANGUAGE_LABEL}/${languageLabelDetail}`;
|
|
20
44
|
return [frameworkLabel, languageLabel];
|
|
21
45
|
}
|
|
46
|
+
function runWithClientLabel(clientLabel, callback) {
|
|
47
|
+
if (typeof clientLabel !== "string" || clientLabel.trim() === "") {
|
|
48
|
+
throw new Error("Client label must be a non-empty string.");
|
|
49
|
+
}
|
|
50
|
+
return clientLabelLocalStorage.run(clientLabel, callback);
|
|
51
|
+
}
|
|
22
52
|
function getClientLabels() {
|
|
23
53
|
const labels = _getDefaultLabels();
|
|
54
|
+
const contextLabel = clientLabelLocalStorage.getStore();
|
|
55
|
+
if (contextLabel) {
|
|
56
|
+
labels.push(contextLabel);
|
|
57
|
+
}
|
|
24
58
|
return labels;
|
|
25
59
|
}
|
|
26
60
|
export {
|
|
27
|
-
getClientLabels
|
|
61
|
+
getClientLabels,
|
|
62
|
+
parseUserAgent,
|
|
63
|
+
runWithClientLabel
|
|
28
64
|
};
|
|
@@ -10,6 +10,10 @@ function isBrowser() {
|
|
|
10
10
|
}
|
|
11
11
|
const UUID_MASK = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
|
|
12
12
|
function randomUUID() {
|
|
13
|
+
var _a;
|
|
14
|
+
if ((_a = globalThis.crypto) == null ? void 0 : _a.randomUUID) {
|
|
15
|
+
return globalThis.crypto.randomUUID();
|
|
16
|
+
}
|
|
13
17
|
let uuid = "";
|
|
14
18
|
for (let i = 0; i < UUID_MASK.length; i++) {
|
|
15
19
|
const randomValue = Math.random() * 16 | 0;
|
|
@@ -25,7 +29,16 @@ function randomUUID() {
|
|
|
25
29
|
}
|
|
26
30
|
function base64Encode(data) {
|
|
27
31
|
if (isBrowser()) {
|
|
28
|
-
|
|
32
|
+
let strData = "";
|
|
33
|
+
if (typeof data === "string") {
|
|
34
|
+
strData = data;
|
|
35
|
+
} else {
|
|
36
|
+
const len = data.byteLength;
|
|
37
|
+
for (let i = 0; i < len; i++) {
|
|
38
|
+
strData += String.fromCharCode(data[i]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return window.btoa(strData);
|
|
29
42
|
}
|
|
30
43
|
return Buffer.from(data).toString("base64");
|
|
31
44
|
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2026 Google LLC
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
import { isGemini3xFlashLive } from "./model_name.js";
|
|
9
|
+
class LiveResponseAggregator {
|
|
10
|
+
constructor(modelVersion) {
|
|
11
|
+
this.modelVersion = modelVersion;
|
|
12
|
+
this.text = "";
|
|
13
|
+
this.isThought = false;
|
|
14
|
+
this.toolCallParts = [];
|
|
15
|
+
this.pendingGroundingMetadata = void 0;
|
|
16
|
+
this.inputTranscriptionText = "";
|
|
17
|
+
this.outputTranscriptionText = "";
|
|
18
|
+
}
|
|
19
|
+
*processMessage(message) {
|
|
20
|
+
if (message.usageMetadata) {
|
|
21
|
+
yield {
|
|
22
|
+
usageMetadata: message.usageMetadata,
|
|
23
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (message.serverContent) {
|
|
27
|
+
const serverContent = message.serverContent;
|
|
28
|
+
const content = serverContent.modelTurn;
|
|
29
|
+
if (serverContent.groundingMetadata) {
|
|
30
|
+
this.pendingGroundingMetadata = serverContent.groundingMetadata;
|
|
31
|
+
}
|
|
32
|
+
if (!(content && content.parts) && serverContent.groundingMetadata && !serverContent.turnComplete) {
|
|
33
|
+
yield {
|
|
34
|
+
groundingMetadata: serverContent.groundingMetadata,
|
|
35
|
+
...serverContent.interrupted !== void 0 ? { interrupted: serverContent.interrupted } : {},
|
|
36
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (content && content.parts) {
|
|
40
|
+
const llmResponse = {
|
|
41
|
+
content,
|
|
42
|
+
...serverContent.interrupted !== void 0 ? { interrupted: serverContent.interrupted } : {},
|
|
43
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
44
|
+
};
|
|
45
|
+
if (!serverContent.turnComplete && serverContent.groundingMetadata) {
|
|
46
|
+
llmResponse.groundingMetadata = serverContent.groundingMetadata;
|
|
47
|
+
}
|
|
48
|
+
const hasInlineData = content.parts.some((p) => p.inlineData);
|
|
49
|
+
for (const part of content.parts) {
|
|
50
|
+
if (part.text) {
|
|
51
|
+
const currentIsThought = !!part.thought;
|
|
52
|
+
if (this.text && currentIsThought !== this.isThought) {
|
|
53
|
+
yield this.buildFullTextResponse(this.text, this.isThought);
|
|
54
|
+
this.text = "";
|
|
55
|
+
this.isThought = false;
|
|
56
|
+
}
|
|
57
|
+
this.text += part.text;
|
|
58
|
+
this.isThought = currentIsThought;
|
|
59
|
+
llmResponse.partial = true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (this.text && !content.parts.some((p) => p.text) && !hasInlineData) {
|
|
63
|
+
yield this.buildFullTextResponse(this.text, this.isThought);
|
|
64
|
+
this.text = "";
|
|
65
|
+
this.isThought = false;
|
|
66
|
+
}
|
|
67
|
+
yield llmResponse;
|
|
68
|
+
}
|
|
69
|
+
if (serverContent.inputTranscription) {
|
|
70
|
+
if (serverContent.inputTranscription.text) {
|
|
71
|
+
this.inputTranscriptionText += serverContent.inputTranscription.text;
|
|
72
|
+
yield {
|
|
73
|
+
inputTranscription: {
|
|
74
|
+
text: serverContent.inputTranscription.text,
|
|
75
|
+
finished: false
|
|
76
|
+
},
|
|
77
|
+
partial: true,
|
|
78
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (serverContent.inputTranscription.finished) {
|
|
82
|
+
yield {
|
|
83
|
+
inputTranscription: {
|
|
84
|
+
text: this.inputTranscriptionText,
|
|
85
|
+
finished: true
|
|
86
|
+
},
|
|
87
|
+
partial: false,
|
|
88
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
89
|
+
};
|
|
90
|
+
this.inputTranscriptionText = "";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (serverContent.outputTranscription) {
|
|
94
|
+
if (serverContent.outputTranscription.text) {
|
|
95
|
+
this.outputTranscriptionText += serverContent.outputTranscription.text;
|
|
96
|
+
yield {
|
|
97
|
+
outputTranscription: {
|
|
98
|
+
text: serverContent.outputTranscription.text,
|
|
99
|
+
finished: false
|
|
100
|
+
},
|
|
101
|
+
partial: true,
|
|
102
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (serverContent.outputTranscription.finished) {
|
|
106
|
+
yield {
|
|
107
|
+
outputTranscription: {
|
|
108
|
+
text: this.outputTranscriptionText,
|
|
109
|
+
finished: true
|
|
110
|
+
},
|
|
111
|
+
partial: false,
|
|
112
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
113
|
+
};
|
|
114
|
+
this.outputTranscriptionText = "";
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (serverContent.interrupted || serverContent.turnComplete || serverContent.generationComplete) {
|
|
118
|
+
if (this.inputTranscriptionText) {
|
|
119
|
+
yield {
|
|
120
|
+
inputTranscription: {
|
|
121
|
+
text: this.inputTranscriptionText,
|
|
122
|
+
finished: true
|
|
123
|
+
},
|
|
124
|
+
partial: false,
|
|
125
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
126
|
+
};
|
|
127
|
+
this.inputTranscriptionText = "";
|
|
128
|
+
}
|
|
129
|
+
if (this.outputTranscriptionText) {
|
|
130
|
+
yield {
|
|
131
|
+
outputTranscription: {
|
|
132
|
+
text: this.outputTranscriptionText,
|
|
133
|
+
finished: true
|
|
134
|
+
},
|
|
135
|
+
partial: false,
|
|
136
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
137
|
+
};
|
|
138
|
+
this.outputTranscriptionText = "";
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (serverContent.turnComplete) {
|
|
142
|
+
let gMetadataToYield = this.pendingGroundingMetadata;
|
|
143
|
+
if (this.text) {
|
|
144
|
+
yield this.buildFullTextResponse(
|
|
145
|
+
this.text,
|
|
146
|
+
this.isThought,
|
|
147
|
+
gMetadataToYield
|
|
148
|
+
);
|
|
149
|
+
this.text = "";
|
|
150
|
+
this.isThought = false;
|
|
151
|
+
gMetadataToYield = void 0;
|
|
152
|
+
}
|
|
153
|
+
if (this.toolCallParts.length > 0) {
|
|
154
|
+
yield {
|
|
155
|
+
content: { role: "model", parts: this.toolCallParts },
|
|
156
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
157
|
+
};
|
|
158
|
+
this.toolCallParts = [];
|
|
159
|
+
}
|
|
160
|
+
const finalResponse = {
|
|
161
|
+
turnComplete: true,
|
|
162
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
163
|
+
};
|
|
164
|
+
if (serverContent.interrupted !== void 0) {
|
|
165
|
+
finalResponse.interrupted = serverContent.interrupted;
|
|
166
|
+
}
|
|
167
|
+
const finalGrounding = serverContent.groundingMetadata || gMetadataToYield;
|
|
168
|
+
if (finalGrounding !== void 0 && finalGrounding !== null) {
|
|
169
|
+
finalResponse.groundingMetadata = finalGrounding;
|
|
170
|
+
}
|
|
171
|
+
yield finalResponse;
|
|
172
|
+
}
|
|
173
|
+
if (serverContent.interrupted) {
|
|
174
|
+
if (this.text) {
|
|
175
|
+
yield this.buildFullTextResponse(this.text, this.isThought);
|
|
176
|
+
this.text = "";
|
|
177
|
+
this.isThought = false;
|
|
178
|
+
} else {
|
|
179
|
+
yield {
|
|
180
|
+
interrupted: serverContent.interrupted,
|
|
181
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (message.toolCall) {
|
|
187
|
+
if (this.text) {
|
|
188
|
+
yield this.buildFullTextResponse(this.text, this.isThought);
|
|
189
|
+
this.text = "";
|
|
190
|
+
this.isThought = false;
|
|
191
|
+
}
|
|
192
|
+
if (message.toolCall.functionCalls) {
|
|
193
|
+
this.toolCallParts.push(
|
|
194
|
+
...message.toolCall.functionCalls.map((fc) => ({
|
|
195
|
+
functionCall: fc
|
|
196
|
+
}))
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
const isGemini3x = isGemini3xFlashLive(this.modelVersion);
|
|
200
|
+
if (isGemini3x && this.toolCallParts.length > 0) {
|
|
201
|
+
yield {
|
|
202
|
+
content: { role: "model", parts: this.toolCallParts },
|
|
203
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
204
|
+
};
|
|
205
|
+
this.toolCallParts = [];
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (message.sessionResumptionUpdate) {
|
|
209
|
+
yield {
|
|
210
|
+
liveSessionResumptionUpdate: message.sessionResumptionUpdate,
|
|
211
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
if (message.goAway) {
|
|
215
|
+
yield {
|
|
216
|
+
goAway: message.goAway,
|
|
217
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Flushes any remaining aggregated components when the connection is closed.
|
|
223
|
+
*/
|
|
224
|
+
*close() {
|
|
225
|
+
if (this.toolCallParts.length > 0) {
|
|
226
|
+
yield {
|
|
227
|
+
content: { role: "model", parts: this.toolCallParts },
|
|
228
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
229
|
+
};
|
|
230
|
+
this.toolCallParts = [];
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
buildFullTextResponse(text, isThought, groundingMetadata) {
|
|
234
|
+
const part = { text };
|
|
235
|
+
if (isThought) {
|
|
236
|
+
part.thought = true;
|
|
237
|
+
}
|
|
238
|
+
const response = {
|
|
239
|
+
content: {
|
|
240
|
+
role: "model",
|
|
241
|
+
parts: [part]
|
|
242
|
+
},
|
|
243
|
+
partial: false
|
|
244
|
+
};
|
|
245
|
+
if (groundingMetadata !== void 0 && groundingMetadata !== null) {
|
|
246
|
+
response.groundingMetadata = groundingMetadata;
|
|
247
|
+
}
|
|
248
|
+
if (this.modelVersion) {
|
|
249
|
+
response.modelVersion = this.modelVersion;
|
|
250
|
+
}
|
|
251
|
+
return response;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
export {
|
|
255
|
+
LiveResponseAggregator
|
|
256
|
+
};
|
|
@@ -46,6 +46,13 @@ function isGemini2OrAbove(modelString) {
|
|
|
46
46
|
const parsedVersion = parseVersion(versionString);
|
|
47
47
|
return parsedVersion.valid && parsedVersion.major >= 2;
|
|
48
48
|
}
|
|
49
|
+
function isGemini3xFlashLive(modelString) {
|
|
50
|
+
if (!modelString) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
const modelName = extractModelName(modelString);
|
|
54
|
+
return modelName.startsWith("gemini-3.") && modelName.includes("-flash-live");
|
|
55
|
+
}
|
|
49
56
|
function isGeminiModelIdCheckDisabled() {
|
|
50
57
|
return getBooleanEnvVar("ADK_DISABLE_GEMINI_MODEL_ID_CHECK");
|
|
51
58
|
}
|
|
@@ -53,6 +60,7 @@ export {
|
|
|
53
60
|
extractModelName,
|
|
54
61
|
isGemini1Model,
|
|
55
62
|
isGemini2OrAbove,
|
|
63
|
+
isGemini3xFlashLive,
|
|
56
64
|
isGeminiModel,
|
|
57
65
|
isGeminiModelIdCheckDisabled
|
|
58
66
|
};
|