@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 '".concat(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: ".concat(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,14 +26,17 @@ 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.\n\nSkills are folders of instructions and resources that extend your capabilities for specialized tasks. Each skill folder contains:\n- **SKILL.md** (required): The main instruction file with skill metadata and detailed markdown instructions.\n- **references/** (Optional): Additional documentation or examples for skill usage.\n- **assets/** (Optional): Templates, scripts or other resources used by the skill.\n- **scripts/** (Optional): Executable scripts that can be run via bash.\n\nThis is very important:\n\n1. If a skill seems relevant to the current user query, you MUST use the `load_skill` tool with `name=\"<SKILL_NAME>\"` to read its full instructions before proceeding.\n2. Once you have read the instructions, follow them exactly as documented before replying to the user. For example, If the instruction lists multiple steps, please make sure you complete all of them in order.\n3. The `load_skill_resource` tool is for viewing files within a skill's directory (e.g., `references/*`, `assets/*`, `scripts/*`). Do NOT use other tools to access these files.\n4. Use `run_skill_script` to run scripts from a skill's `scripts/` directory. Use `load_skill_resource` to view script content first if needed.\n";
|
|
29
31
|
let SkillToolset = class extends BaseToolset {
|
|
30
32
|
constructor(skills, options = {}) {
|
|
31
33
|
super([], "adk_skill_toolset");
|
|
32
34
|
this.toolCache = /* @__PURE__ */ new Map();
|
|
35
|
+
this.fetchedSkillCache = /* @__PURE__ */ new Map();
|
|
33
36
|
this.skills = Array.isArray(skills) ? Object.fromEntries(skills.map((s) => [s.frontmatter.name, s])) : skills;
|
|
34
37
|
this.codeExecutor = options.codeExecutor;
|
|
35
38
|
this.additionalTools = options.additionalTools || [];
|
|
39
|
+
this.registry = options.registry;
|
|
36
40
|
this.tools = [
|
|
37
41
|
new ListSkillsTool(this),
|
|
38
42
|
new LoadSkillTool(this),
|
|
@@ -40,24 +44,55 @@ let SkillToolset = class extends BaseToolset {
|
|
|
40
44
|
new RunSkillScriptTool(this),
|
|
41
45
|
new RunSkillInlineScriptTool(this)
|
|
42
46
|
];
|
|
47
|
+
if (this.registry) {
|
|
48
|
+
this.tools.push(new SearchSkillsTool(this));
|
|
49
|
+
}
|
|
43
50
|
}
|
|
44
51
|
async getTools(context) {
|
|
45
52
|
const dynamicTools = await this.resolveAdditionalTools(context);
|
|
46
53
|
return [...this.tools, ...dynamicTools];
|
|
47
54
|
}
|
|
48
55
|
async close() {
|
|
56
|
+
this.fetchedSkillCache.clear();
|
|
49
57
|
}
|
|
50
58
|
getSkill(name) {
|
|
51
59
|
return this.skills[name];
|
|
52
60
|
}
|
|
61
|
+
async getOrFetchSkill(name, invocationId) {
|
|
62
|
+
if (this.skills[name]) {
|
|
63
|
+
return this.skills[name];
|
|
64
|
+
}
|
|
65
|
+
if (!this.registry) {
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
const contextKey = invocationId || "default";
|
|
69
|
+
if (!this.fetchedSkillCache.has(contextKey)) {
|
|
70
|
+
this.fetchedSkillCache.set(contextKey, /* @__PURE__ */ new Map());
|
|
71
|
+
}
|
|
72
|
+
const cache = this.fetchedSkillCache.get(contextKey);
|
|
73
|
+
if (cache.has(name)) {
|
|
74
|
+
return cache.get(name);
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const skill = await this.registry.getSkill(name);
|
|
78
|
+
cache.set(name, skill);
|
|
79
|
+
return skill;
|
|
80
|
+
} catch (e) {
|
|
81
|
+
logger.warn("Failed to fetch skill '".concat(name, "' from registry: ").concat(e));
|
|
82
|
+
throw e;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
53
85
|
async processLlmRequest(toolContext, llmRequest) {
|
|
54
86
|
await super.processLlmRequest(toolContext, llmRequest);
|
|
55
87
|
const skills = Object.values(this.skills);
|
|
56
88
|
const skillsXml = formatSkillsAsXml(skills);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
89
|
+
const instructions = [DEFAULT_SKILL_SYSTEM_INSTRUCTION, skillsXml];
|
|
90
|
+
if (this.registry) {
|
|
91
|
+
instructions.push(
|
|
92
|
+
"\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."
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
appendInstructions(llmRequest, instructions);
|
|
61
96
|
}
|
|
62
97
|
async resolveAdditionalTools(context) {
|
|
63
98
|
if (!context) return [];
|
|
@@ -71,7 +106,7 @@ let SkillToolset = class extends BaseToolset {
|
|
|
71
106
|
}
|
|
72
107
|
const additionalToolNames = /* @__PURE__ */ new Set();
|
|
73
108
|
for (const skillName of activatedSkills) {
|
|
74
|
-
const skill = this.
|
|
109
|
+
const skill = await this.getOrFetchSkill(skillName, context.invocationId);
|
|
75
110
|
if (skill && skill.frontmatter.metadata) {
|
|
76
111
|
const tools = skill.frontmatter.metadata["adk_additional_tools"];
|
|
77
112
|
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 "".concat(name, "/").concat(match[1]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return "Browser";
|
|
33
|
+
}
|
|
14
34
|
function _getDefaultLabels() {
|
|
15
35
|
let frameworkLabel = "".concat(ADK_LABEL, "/").concat(version);
|
|
16
36
|
if (!isBrowser() && process.env[AGENT_ENGINE_TELEMETRY_ENV_VARIABLE_NAME]) {
|
|
17
37
|
frameworkLabel = "".concat(frameworkLabel, "+").concat(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 = "".concat(LANGUAGE_LABEL, "/").concat(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,254 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* @license
|
|
21
|
+
* Copyright 2026 Google LLC
|
|
22
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
23
|
+
*/
|
|
24
|
+
import { isGemini3xFlashLive } from "./model_name.js";
|
|
25
|
+
class LiveResponseAggregator {
|
|
26
|
+
constructor(modelVersion) {
|
|
27
|
+
this.modelVersion = modelVersion;
|
|
28
|
+
this.text = "";
|
|
29
|
+
this.isThought = false;
|
|
30
|
+
this.toolCallParts = [];
|
|
31
|
+
this.pendingGroundingMetadata = void 0;
|
|
32
|
+
this.inputTranscriptionText = "";
|
|
33
|
+
this.outputTranscriptionText = "";
|
|
34
|
+
}
|
|
35
|
+
*processMessage(message) {
|
|
36
|
+
if (message.usageMetadata) {
|
|
37
|
+
yield __spreadValues({
|
|
38
|
+
usageMetadata: message.usageMetadata
|
|
39
|
+
}, this.modelVersion ? { modelVersion: this.modelVersion } : {});
|
|
40
|
+
}
|
|
41
|
+
if (message.serverContent) {
|
|
42
|
+
const serverContent = message.serverContent;
|
|
43
|
+
const content = serverContent.modelTurn;
|
|
44
|
+
if (serverContent.groundingMetadata) {
|
|
45
|
+
this.pendingGroundingMetadata = serverContent.groundingMetadata;
|
|
46
|
+
}
|
|
47
|
+
if (!(content && content.parts) && serverContent.groundingMetadata && !serverContent.turnComplete) {
|
|
48
|
+
yield __spreadValues(__spreadValues({
|
|
49
|
+
groundingMetadata: serverContent.groundingMetadata
|
|
50
|
+
}, serverContent.interrupted !== void 0 ? { interrupted: serverContent.interrupted } : {}), this.modelVersion ? { modelVersion: this.modelVersion } : {});
|
|
51
|
+
}
|
|
52
|
+
if (content && content.parts) {
|
|
53
|
+
const llmResponse = __spreadValues(__spreadValues({
|
|
54
|
+
content
|
|
55
|
+
}, serverContent.interrupted !== void 0 ? { interrupted: serverContent.interrupted } : {}), this.modelVersion ? { modelVersion: this.modelVersion } : {});
|
|
56
|
+
if (!serverContent.turnComplete && serverContent.groundingMetadata) {
|
|
57
|
+
llmResponse.groundingMetadata = serverContent.groundingMetadata;
|
|
58
|
+
}
|
|
59
|
+
const hasInlineData = content.parts.some((p) => p.inlineData);
|
|
60
|
+
for (const part of content.parts) {
|
|
61
|
+
if (part.text) {
|
|
62
|
+
const currentIsThought = !!part.thought;
|
|
63
|
+
if (this.text && currentIsThought !== this.isThought) {
|
|
64
|
+
yield this.buildFullTextResponse(this.text, this.isThought);
|
|
65
|
+
this.text = "";
|
|
66
|
+
this.isThought = false;
|
|
67
|
+
}
|
|
68
|
+
this.text += part.text;
|
|
69
|
+
this.isThought = currentIsThought;
|
|
70
|
+
llmResponse.partial = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (this.text && !content.parts.some((p) => p.text) && !hasInlineData) {
|
|
74
|
+
yield this.buildFullTextResponse(this.text, this.isThought);
|
|
75
|
+
this.text = "";
|
|
76
|
+
this.isThought = false;
|
|
77
|
+
}
|
|
78
|
+
yield llmResponse;
|
|
79
|
+
}
|
|
80
|
+
if (serverContent.inputTranscription) {
|
|
81
|
+
if (serverContent.inputTranscription.text) {
|
|
82
|
+
this.inputTranscriptionText += serverContent.inputTranscription.text;
|
|
83
|
+
yield __spreadValues({
|
|
84
|
+
inputTranscription: {
|
|
85
|
+
text: serverContent.inputTranscription.text,
|
|
86
|
+
finished: false
|
|
87
|
+
},
|
|
88
|
+
partial: true
|
|
89
|
+
}, this.modelVersion ? { modelVersion: this.modelVersion } : {});
|
|
90
|
+
}
|
|
91
|
+
if (serverContent.inputTranscription.finished) {
|
|
92
|
+
yield __spreadValues({
|
|
93
|
+
inputTranscription: {
|
|
94
|
+
text: this.inputTranscriptionText,
|
|
95
|
+
finished: true
|
|
96
|
+
},
|
|
97
|
+
partial: false
|
|
98
|
+
}, this.modelVersion ? { modelVersion: this.modelVersion } : {});
|
|
99
|
+
this.inputTranscriptionText = "";
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (serverContent.outputTranscription) {
|
|
103
|
+
if (serverContent.outputTranscription.text) {
|
|
104
|
+
this.outputTranscriptionText += serverContent.outputTranscription.text;
|
|
105
|
+
yield __spreadValues({
|
|
106
|
+
outputTranscription: {
|
|
107
|
+
text: serverContent.outputTranscription.text,
|
|
108
|
+
finished: false
|
|
109
|
+
},
|
|
110
|
+
partial: true
|
|
111
|
+
}, this.modelVersion ? { modelVersion: this.modelVersion } : {});
|
|
112
|
+
}
|
|
113
|
+
if (serverContent.outputTranscription.finished) {
|
|
114
|
+
yield __spreadValues({
|
|
115
|
+
outputTranscription: {
|
|
116
|
+
text: this.outputTranscriptionText,
|
|
117
|
+
finished: true
|
|
118
|
+
},
|
|
119
|
+
partial: false
|
|
120
|
+
}, this.modelVersion ? { modelVersion: this.modelVersion } : {});
|
|
121
|
+
this.outputTranscriptionText = "";
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (serverContent.interrupted || serverContent.turnComplete || serverContent.generationComplete) {
|
|
125
|
+
if (this.inputTranscriptionText) {
|
|
126
|
+
yield __spreadValues({
|
|
127
|
+
inputTranscription: {
|
|
128
|
+
text: this.inputTranscriptionText,
|
|
129
|
+
finished: true
|
|
130
|
+
},
|
|
131
|
+
partial: false
|
|
132
|
+
}, this.modelVersion ? { modelVersion: this.modelVersion } : {});
|
|
133
|
+
this.inputTranscriptionText = "";
|
|
134
|
+
}
|
|
135
|
+
if (this.outputTranscriptionText) {
|
|
136
|
+
yield __spreadValues({
|
|
137
|
+
outputTranscription: {
|
|
138
|
+
text: this.outputTranscriptionText,
|
|
139
|
+
finished: true
|
|
140
|
+
},
|
|
141
|
+
partial: false
|
|
142
|
+
}, this.modelVersion ? { modelVersion: this.modelVersion } : {});
|
|
143
|
+
this.outputTranscriptionText = "";
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (serverContent.turnComplete) {
|
|
147
|
+
let gMetadataToYield = this.pendingGroundingMetadata;
|
|
148
|
+
if (this.text) {
|
|
149
|
+
yield this.buildFullTextResponse(
|
|
150
|
+
this.text,
|
|
151
|
+
this.isThought,
|
|
152
|
+
gMetadataToYield
|
|
153
|
+
);
|
|
154
|
+
this.text = "";
|
|
155
|
+
this.isThought = false;
|
|
156
|
+
gMetadataToYield = void 0;
|
|
157
|
+
}
|
|
158
|
+
if (this.toolCallParts.length > 0) {
|
|
159
|
+
yield __spreadValues({
|
|
160
|
+
content: { role: "model", parts: this.toolCallParts }
|
|
161
|
+
}, this.modelVersion ? { modelVersion: this.modelVersion } : {});
|
|
162
|
+
this.toolCallParts = [];
|
|
163
|
+
}
|
|
164
|
+
const finalResponse = __spreadValues({
|
|
165
|
+
turnComplete: true
|
|
166
|
+
}, this.modelVersion ? { modelVersion: this.modelVersion } : {});
|
|
167
|
+
if (serverContent.interrupted !== void 0) {
|
|
168
|
+
finalResponse.interrupted = serverContent.interrupted;
|
|
169
|
+
}
|
|
170
|
+
const finalGrounding = serverContent.groundingMetadata || gMetadataToYield;
|
|
171
|
+
if (finalGrounding !== void 0 && finalGrounding !== null) {
|
|
172
|
+
finalResponse.groundingMetadata = finalGrounding;
|
|
173
|
+
}
|
|
174
|
+
yield finalResponse;
|
|
175
|
+
}
|
|
176
|
+
if (serverContent.interrupted) {
|
|
177
|
+
if (this.text) {
|
|
178
|
+
yield this.buildFullTextResponse(this.text, this.isThought);
|
|
179
|
+
this.text = "";
|
|
180
|
+
this.isThought = false;
|
|
181
|
+
} else {
|
|
182
|
+
yield __spreadValues({
|
|
183
|
+
interrupted: serverContent.interrupted
|
|
184
|
+
}, this.modelVersion ? { modelVersion: this.modelVersion } : {});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (message.toolCall) {
|
|
189
|
+
if (this.text) {
|
|
190
|
+
yield this.buildFullTextResponse(this.text, this.isThought);
|
|
191
|
+
this.text = "";
|
|
192
|
+
this.isThought = false;
|
|
193
|
+
}
|
|
194
|
+
if (message.toolCall.functionCalls) {
|
|
195
|
+
this.toolCallParts.push(
|
|
196
|
+
...message.toolCall.functionCalls.map((fc) => ({
|
|
197
|
+
functionCall: fc
|
|
198
|
+
}))
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
const isGemini3x = isGemini3xFlashLive(this.modelVersion);
|
|
202
|
+
if (isGemini3x && this.toolCallParts.length > 0) {
|
|
203
|
+
yield __spreadValues({
|
|
204
|
+
content: { role: "model", parts: this.toolCallParts }
|
|
205
|
+
}, this.modelVersion ? { modelVersion: this.modelVersion } : {});
|
|
206
|
+
this.toolCallParts = [];
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (message.sessionResumptionUpdate) {
|
|
210
|
+
yield __spreadValues({
|
|
211
|
+
liveSessionResumptionUpdate: message.sessionResumptionUpdate
|
|
212
|
+
}, this.modelVersion ? { modelVersion: this.modelVersion } : {});
|
|
213
|
+
}
|
|
214
|
+
if (message.goAway) {
|
|
215
|
+
yield __spreadValues({
|
|
216
|
+
goAway: message.goAway
|
|
217
|
+
}, this.modelVersion ? { modelVersion: this.modelVersion } : {});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Flushes any remaining aggregated components when the connection is closed.
|
|
222
|
+
*/
|
|
223
|
+
*close() {
|
|
224
|
+
if (this.toolCallParts.length > 0) {
|
|
225
|
+
yield __spreadValues({
|
|
226
|
+
content: { role: "model", parts: this.toolCallParts }
|
|
227
|
+
}, this.modelVersion ? { modelVersion: this.modelVersion } : {});
|
|
228
|
+
this.toolCallParts = [];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
buildFullTextResponse(text, isThought, groundingMetadata) {
|
|
232
|
+
const part = { text };
|
|
233
|
+
if (isThought) {
|
|
234
|
+
part.thought = true;
|
|
235
|
+
}
|
|
236
|
+
const response = {
|
|
237
|
+
content: {
|
|
238
|
+
role: "model",
|
|
239
|
+
parts: [part]
|
|
240
|
+
},
|
|
241
|
+
partial: false
|
|
242
|
+
};
|
|
243
|
+
if (groundingMetadata !== void 0 && groundingMetadata !== null) {
|
|
244
|
+
response.groundingMetadata = groundingMetadata;
|
|
245
|
+
}
|
|
246
|
+
if (this.modelVersion) {
|
|
247
|
+
response.modelVersion = this.modelVersion;
|
|
248
|
+
}
|
|
249
|
+
return response;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
export {
|
|
253
|
+
LiveResponseAggregator
|
|
254
|
+
};
|
|
@@ -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
|
};
|