@google/adk 2.2.1 → 2.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/a2a/a2a_remote_agent.js +4 -1
- package/dist/cjs/a2a/agent_card.js +102 -26
- package/dist/cjs/a2a/agent_to_a2a.js +1 -1
- package/dist/cjs/agents/agent_engine_client.js +172 -0
- package/dist/cjs/agents/base_agent.js +20 -4
- package/dist/cjs/agents/functions.js +227 -25
- package/dist/cjs/agents/instructions.js +6 -2
- package/dist/cjs/agents/invocation_context.js +26 -4
- package/dist/cjs/agents/langgraph_agent.js +152 -0
- package/dist/cjs/agents/llm_agent.js +194 -107
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +1 -1
- package/dist/cjs/agents/processors/code_execution_request_processor.js +18 -6
- package/dist/cjs/agents/processors/content_processor_utils.js +38 -10
- package/dist/cjs/agents/processors/content_request_processor.js +34 -2
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/cjs/agents/processors/nl_planning_processor.js +12 -3
- package/dist/cjs/artifacts/in_memory_artifact_service.js +14 -0
- package/dist/cjs/auth/auth_handler.js +37 -5
- package/dist/cjs/auth/auth_schemes.js +9 -0
- package/dist/cjs/cli/cli_eval.js +532 -0
- package/dist/cjs/cli/utils/envs.js +116 -0
- package/dist/cjs/cli/utils/evals.js +137 -0
- package/dist/cjs/cli/utils/logs.js +150 -0
- package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +7 -2
- package/dist/cjs/code_executors/code_execution_utils.js +48 -16
- package/dist/cjs/code_executors/code_executor_context.js +6 -2
- package/dist/cjs/code_executors/container_code_executor.js +27 -16
- package/dist/cjs/code_executors/unsafe_local_code_executor.js +6 -1
- package/dist/cjs/common.js +61 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +12 -10
- package/dist/cjs/context/token_based_context_compactor.js +2 -1
- package/dist/cjs/errors/input_validation_error.js +3 -2
- package/dist/cjs/events/event.js +4 -2
- package/dist/cjs/examples/example_util.js +23 -2
- package/dist/cjs/flows/llm_flows/audio_transcriber.js +170 -0
- package/dist/cjs/index.js +104 -1
- package/dist/cjs/integrations/agent_registry/helpers.js +1 -1
- package/dist/cjs/models/gemini_llm_connection.js +16 -8
- package/dist/cjs/models/google_llm.js +13 -16
- package/dist/cjs/models/llm_response.js +9 -1
- package/dist/cjs/models/registry.js +1 -1
- package/dist/cjs/models/routed_llm.js +9 -8
- package/dist/cjs/planners/plan_re_act_planner.js +1 -1
- package/dist/cjs/plugins/base_plugin.js +13 -23
- package/dist/cjs/runner/in_memory_runner.js +6 -11
- package/dist/cjs/runner/runner.js +105 -33
- package/dist/cjs/sessions/base_session_service.js +14 -8
- package/dist/cjs/sessions/database_session_service.js +50 -28
- package/dist/cjs/sessions/db/operations.js +1 -1
- package/dist/cjs/sessions/in_memory_session_service.js +3 -1
- package/dist/cjs/sessions/stale_session_error.js +59 -0
- package/dist/cjs/sessions/state.js +8 -4
- package/dist/cjs/sessions/vertex_ai_session_service.js +34 -15
- package/dist/cjs/skills/loader.js +52 -18
- package/dist/cjs/telemetry/setup.js +0 -1
- package/dist/cjs/telemetry/tracing.js +147 -73
- package/dist/cjs/tools/agent_tool.js +44 -0
- package/dist/cjs/tools/apihub_tool/apihub_toolset.js +137 -0
- package/dist/cjs/tools/apihub_tool/clients/apihub_client.js +272 -0
- package/dist/cjs/tools/apihub_tool/clients/secret_client.js +148 -0
- package/dist/cjs/tools/apihub_tool/clients/service_account.js +48 -0
- package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +263 -0
- package/dist/cjs/tools/application_integration_tool/clients/cloud_request.js +133 -0
- package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +671 -0
- package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +223 -0
- package/dist/cjs/tools/application_integration_tool/integration_connector_tool.js +184 -0
- package/dist/cjs/tools/example_tool.js +10 -0
- package/dist/cjs/tools/function_tool.js +319 -0
- package/dist/cjs/tools/google_api_tool/google_api_tool.js +100 -0
- package/dist/cjs/tools/google_api_tool/google_api_toolset.js +173 -0
- package/dist/cjs/tools/google_api_tool/google_api_toolsets.js +124 -0
- package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +440 -0
- package/dist/cjs/tools/google_api_tool/index.js +61 -0
- package/dist/cjs/tools/load_artifacts_tool.js +12 -6
- package/dist/cjs/tools/load_memory_tool.js +12 -10
- package/dist/cjs/tools/mcp/index.js +12 -0
- package/dist/cjs/tools/mcp/mcp_session_manager.js +25 -0
- package/dist/cjs/tools/mcp/mcp_toolset.js +1 -14
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +1 -2
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +46 -2
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +4 -3
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +20 -6
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +17 -6
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +14 -2
- package/dist/cjs/tools/openapi_tool/openapi_toolset.js +7 -13
- package/dist/cjs/tools/openapi_tool/rest_api_tool.js +17 -1
- package/dist/cjs/tools/retrieval/base_retrieval_tool.js +18 -3
- package/dist/cjs/tools/toolbox_toolset.js +174 -0
- package/dist/cjs/tools/webmcp/webmcp_toolset.js +1 -14
- package/dist/cjs/utils/client_labels.js +19 -2
- package/dist/cjs/utils/env_aware_utils.js +6 -8
- package/dist/cjs/utils/error_utils.js +11 -11
- package/dist/cjs/utils/failover_utils.js +1 -1
- package/dist/cjs/utils/file_extension_utils.js +11 -0
- package/dist/cjs/utils/file_utils.js +2 -24
- package/dist/cjs/utils/gemini_schema_util.js +28 -7
- package/dist/cjs/utils/json_utils.js +49 -0
- package/dist/cjs/utils/live_connection_utils.js +4 -5
- package/dist/cjs/utils/logger_node.js +11 -1
- package/dist/cjs/utils/object_notation_utils.js +6 -3
- package/dist/cjs/utils/output_schema_utils.js +5 -2
- package/dist/cjs/utils/streaming_utils.js +12 -12
- package/dist/cjs/utils/task.js +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_remote_agent.js +4 -1
- package/dist/esm/a2a/agent_card.js +103 -27
- package/dist/esm/a2a/agent_to_a2a.js +5 -2
- package/dist/esm/agents/agent_engine_client.js +144 -0
- package/dist/esm/agents/base_agent.js +20 -4
- package/dist/esm/agents/functions.js +226 -25
- package/dist/esm/agents/instructions.js +6 -2
- package/dist/esm/agents/invocation_context.js +24 -4
- package/dist/esm/agents/langgraph_agent.js +123 -0
- package/dist/esm/agents/llm_agent.js +204 -110
- package/dist/esm/agents/processors/basic_llm_request_processor.js +1 -1
- package/dist/esm/agents/processors/code_execution_request_processor.js +21 -8
- package/dist/esm/agents/processors/content_processor_utils.js +38 -10
- package/dist/esm/agents/processors/content_request_processor.js +34 -2
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/esm/agents/processors/nl_planning_processor.js +12 -3
- package/dist/esm/artifacts/in_memory_artifact_service.js +14 -0
- package/dist/esm/auth/auth_handler.js +37 -5
- package/dist/esm/auth/auth_schemes.js +8 -0
- package/dist/esm/cli/cli_eval.js +510 -0
- package/dist/esm/cli/utils/envs.js +78 -0
- package/dist/esm/cli/utils/evals.js +109 -0
- package/dist/esm/cli/utils/logs.js +111 -0
- package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +7 -2
- package/dist/esm/code_executors/code_execution_utils.js +46 -16
- package/dist/esm/code_executors/code_executor_context.js +5 -2
- package/dist/esm/code_executors/container_code_executor.js +27 -16
- package/dist/esm/code_executors/unsafe_local_code_executor.js +6 -1
- package/dist/esm/common.js +65 -4
- package/dist/esm/context/summarizers/llm_summarizer.js +12 -10
- package/dist/esm/context/token_based_context_compactor.js +2 -1
- package/dist/esm/errors/input_validation_error.js +3 -2
- package/dist/esm/events/event.js +4 -2
- package/dist/esm/examples/example_util.js +21 -1
- package/dist/esm/flows/llm_flows/audio_transcriber.js +142 -0
- package/dist/esm/index.js +114 -2
- package/dist/esm/integrations/agent_registry/helpers.js +1 -1
- package/dist/esm/models/gemini_llm_connection.js +16 -8
- package/dist/esm/models/google_llm.js +14 -17
- package/dist/esm/models/llm_response.js +9 -1
- package/dist/esm/models/registry.js +1 -1
- package/dist/esm/models/routed_llm.js +9 -8
- package/dist/esm/planners/plan_re_act_planner.js +1 -1
- package/dist/esm/plugins/base_plugin.js +13 -23
- package/dist/esm/runner/in_memory_runner.js +6 -11
- package/dist/esm/runner/runner.js +105 -33
- package/dist/esm/sessions/base_session_service.js +12 -7
- package/dist/esm/sessions/database_session_service.js +49 -28
- package/dist/esm/sessions/db/operations.js +1 -1
- package/dist/esm/sessions/in_memory_session_service.js +3 -1
- package/dist/esm/sessions/stale_session_error.js +31 -0
- package/dist/esm/sessions/state.js +8 -4
- package/dist/esm/sessions/vertex_ai_session_service.js +34 -15
- package/dist/esm/skills/loader.js +51 -17
- package/dist/esm/telemetry/setup.js +1 -2
- package/dist/esm/telemetry/tracing.js +151 -74
- package/dist/esm/tools/agent_tool.js +44 -0
- package/dist/esm/tools/apihub_tool/apihub_toolset.js +101 -0
- package/dist/esm/tools/apihub_tool/clients/apihub_client.js +244 -0
- package/dist/esm/tools/apihub_tool/clients/secret_client.js +132 -0
- package/dist/esm/tools/apihub_tool/clients/service_account.js +21 -0
- package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +245 -0
- package/dist/esm/tools/application_integration_tool/clients/cloud_request.js +103 -0
- package/dist/esm/tools/application_integration_tool/clients/connections_client.js +629 -0
- package/dist/esm/tools/application_integration_tool/clients/integration_client.js +219 -0
- package/dist/esm/tools/application_integration_tool/integration_connector_tool.js +158 -0
- package/dist/esm/tools/example_tool.js +13 -1
- package/dist/esm/tools/function_tool.js +316 -0
- package/dist/esm/tools/google_api_tool/google_api_tool.js +73 -0
- package/dist/esm/tools/google_api_tool/google_api_toolset.js +146 -0
- package/dist/esm/tools/google_api_tool/google_api_toolsets.js +94 -0
- package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +393 -0
- package/dist/esm/tools/google_api_tool/index.js +31 -0
- package/dist/esm/tools/load_artifacts_tool.js +10 -5
- package/dist/esm/tools/load_memory_tool.js +12 -10
- package/dist/esm/tools/mcp/index.js +6 -0
- package/dist/esm/tools/mcp/mcp_session_manager.js +25 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +1 -14
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +1 -2
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +50 -3
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +4 -3
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +20 -6
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +17 -6
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -2
- package/dist/esm/tools/openapi_tool/openapi_toolset.js +6 -12
- package/dist/esm/tools/openapi_tool/rest_api_tool.js +17 -1
- package/dist/esm/tools/retrieval/base_retrieval_tool.js +16 -2
- package/dist/esm/tools/toolbox_toolset.js +148 -0
- package/dist/esm/tools/webmcp/webmcp_toolset.js +1 -14
- package/dist/esm/utils/client_labels.js +19 -2
- package/dist/esm/utils/env_aware_utils.js +6 -8
- package/dist/esm/utils/error_utils.js +9 -10
- package/dist/esm/utils/failover_utils.js +1 -1
- package/dist/esm/utils/file_extension_utils.js +11 -0
- package/dist/esm/utils/file_utils.js +2 -23
- package/dist/esm/utils/gemini_schema_util.js +27 -7
- package/dist/esm/utils/json_utils.js +21 -0
- package/dist/esm/utils/live_connection_utils.js +4 -5
- package/dist/esm/utils/logger_node.js +11 -1
- package/dist/esm/utils/object_notation_utils.js +4 -2
- package/dist/esm/utils/output_schema_utils.js +5 -2
- package/dist/esm/utils/streaming_utils.js +11 -11
- package/dist/esm/utils/task.js +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +9 -0
- package/dist/types/a2a/agent_card.d.ts +44 -1
- package/dist/types/a2a/agent_to_a2a.d.ts +9 -0
- package/dist/types/a2a/index.d.ts +1 -0
- package/dist/types/agents/agent_engine_client.d.ts +37 -0
- package/dist/types/agents/base_agent.d.ts +12 -0
- package/dist/types/agents/functions.d.ts +33 -1
- package/dist/types/agents/invocation_context.d.ts +20 -1
- package/dist/types/agents/langgraph_agent.d.ts +153 -0
- package/dist/types/agents/llm_agent.d.ts +5 -1
- package/dist/types/agents/processors/content_processor_utils.d.ts +4 -2
- package/dist/types/agents/processors/nl_planning_processor.d.ts +2 -1
- package/dist/types/auth/auth_handler.d.ts +28 -1
- package/dist/types/auth/auth_schemes.d.ts +13 -0
- package/dist/types/cli/cli_eval.d.ts +173 -0
- package/dist/types/cli/utils/envs.d.ts +23 -0
- package/dist/types/cli/utils/evals.d.ts +47 -0
- package/dist/types/cli/utils/logs.d.ts +38 -0
- package/dist/types/code_executors/code_execution_utils.d.ts +39 -0
- package/dist/types/code_executors/code_executor_context.d.ts +1 -0
- package/dist/types/code_executors/container_code_executor.d.ts +17 -5
- package/dist/types/common.d.ts +24 -5
- package/dist/types/errors/input_validation_error.d.ts +2 -1
- package/dist/types/events/event.d.ts +4 -0
- package/dist/types/examples/example_util.d.ts +17 -0
- package/dist/types/flows/llm_flows/audio_transcriber.d.ts +85 -0
- package/dist/types/index.d.ts +19 -2
- package/dist/types/models/gemini_llm_connection.d.ts +6 -7
- package/dist/types/models/routed_llm.d.ts +1 -1
- package/dist/types/plugins/base_plugin.d.ts +0 -10
- package/dist/types/runner/in_memory_runner.d.ts +2 -1
- package/dist/types/runner/runner.d.ts +34 -0
- package/dist/types/sessions/base_session_service.d.ts +5 -0
- package/dist/types/sessions/database_session_service.d.ts +17 -1
- package/dist/types/sessions/stale_session_error.d.ts +21 -0
- package/dist/types/sessions/state.d.ts +5 -1
- package/dist/types/sessions/vertex_ai_session_service.d.ts +8 -0
- package/dist/types/skills/loader.d.ts +3 -2
- package/dist/types/skills/skill.d.ts +1 -1
- package/dist/types/telemetry/tracing.d.ts +20 -4
- package/dist/types/tools/apihub_tool/apihub_toolset.d.ts +115 -0
- package/dist/types/tools/apihub_tool/clients/apihub_client.d.ts +142 -0
- package/dist/types/tools/apihub_tool/clients/secret_client.d.ts +55 -0
- package/dist/types/tools/apihub_tool/clients/service_account.d.ts +11 -0
- package/dist/types/tools/application_integration_tool/application_integration_toolset.d.ts +109 -0
- package/dist/types/tools/application_integration_tool/clients/cloud_request.d.ts +53 -0
- package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +229 -0
- package/dist/types/tools/application_integration_tool/clients/integration_client.d.ts +72 -0
- package/dist/types/tools/application_integration_tool/integration_connector_tool.d.ts +70 -0
- package/dist/types/tools/base_toolset.d.ts +6 -5
- package/dist/types/tools/example_tool.d.ts +10 -0
- package/dist/types/tools/function_tool.d.ts +32 -0
- package/dist/types/tools/google_api_tool/google_api_tool.d.ts +37 -0
- package/dist/types/tools/google_api_tool/google_api_toolset.d.ts +55 -0
- package/dist/types/tools/google_api_tool/google_api_toolsets.d.ts +48 -0
- package/dist/types/tools/google_api_tool/googleapi_to_openapi_converter.d.ts +165 -0
- package/dist/types/tools/google_api_tool/index.d.ts +10 -0
- package/dist/types/tools/load_artifacts_tool.d.ts +14 -1
- package/dist/types/tools/load_memory_tool.d.ts +23 -1
- package/dist/types/tools/mcp/index.d.ts +3 -0
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +34 -1
- package/dist/types/tools/mcp/mcp_toolset.d.ts +15 -0
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +19 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +18 -1
- package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +12 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +8 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +2 -1
- package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +5 -0
- package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +10 -0
- package/dist/types/tools/retrieval/base_retrieval_tool.d.ts +15 -0
- package/dist/types/tools/toolbox_toolset.d.ts +159 -0
- package/dist/types/utils/client_labels.d.ts +2 -1
- package/dist/types/utils/env_aware_utils.d.ts +18 -2
- package/dist/types/utils/error_utils.d.ts +7 -0
- package/dist/types/utils/file_utils.d.ts +6 -1
- package/dist/types/utils/gemini_schema_util.d.ts +9 -2
- package/dist/types/utils/json_utils.d.ts +11 -0
- package/dist/types/utils/object_notation_utils.d.ts +7 -0
- package/dist/types/utils/output_schema_utils.d.ts +3 -2
- package/dist/types/utils/simple_zod_to_json.d.ts +1 -2
- package/dist/types/utils/streaming_utils.d.ts +11 -4
- package/dist/types/version.d.ts +1 -1
- package/dist/web/index_web.js +117 -110
- package/dist/web/index_web.js.map +4 -4
- package/package.json +38 -26
- package/dist/cjs/models/gemini_continuation.js +0 -232
- package/dist/esm/models/gemini_continuation.js +0 -205
- package/dist/types/models/gemini_continuation.d.ts +0 -59
|
@@ -8,10 +8,12 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
8
8
|
* SPDX-License-Identifier: Apache-2.0
|
|
9
9
|
*/
|
|
10
10
|
import AdmZip from "adm-zip";
|
|
11
|
-
import yaml from "js-yaml";
|
|
11
|
+
import * as yaml from "js-yaml";
|
|
12
12
|
import { isUtf8 } from "node:buffer";
|
|
13
13
|
import * as fs from "node:fs/promises";
|
|
14
14
|
import * as path from "node:path";
|
|
15
|
+
import { InputValidationError } from "../errors/input_validation_error.js";
|
|
16
|
+
import { NotFoundError } from "../errors/not_found_error.js";
|
|
15
17
|
import { logger } from "../utils/logger.js";
|
|
16
18
|
import {
|
|
17
19
|
FrontmatterSchema
|
|
@@ -88,24 +90,37 @@ async function loadDir(directoryPath) {
|
|
|
88
90
|
return files;
|
|
89
91
|
}
|
|
90
92
|
__name(loadDir, "loadDir");
|
|
93
|
+
const FRONTMATTER_BOM = "\uFEFF";
|
|
94
|
+
const FRONTMATTER_PATTERN = /^---[ \t]*\r?\n(?:([\s\S]*?)\r?\n)??---[ \t]*(?:\r?\n|$)/;
|
|
91
95
|
function parseFrontmatterYaml(content) {
|
|
92
|
-
|
|
93
|
-
|
|
96
|
+
var _a;
|
|
97
|
+
const text = content.startsWith(FRONTMATTER_BOM) ? content.slice(FRONTMATTER_BOM.length) : content;
|
|
98
|
+
if (!text.startsWith("---")) {
|
|
99
|
+
throw new InputValidationError(
|
|
100
|
+
"SKILL.md must start with YAML frontmatter (---)"
|
|
101
|
+
);
|
|
94
102
|
}
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
throw new
|
|
103
|
+
const match = FRONTMATTER_PATTERN.exec(text);
|
|
104
|
+
if (!match) {
|
|
105
|
+
throw new InputValidationError(
|
|
106
|
+
"SKILL.md frontmatter not properly closed with ---"
|
|
107
|
+
);
|
|
98
108
|
}
|
|
99
|
-
const frontmatterStr =
|
|
100
|
-
const body =
|
|
109
|
+
const frontmatterStr = (_a = match[1]) != null ? _a : "";
|
|
110
|
+
const body = text.slice(match[0].length).trim();
|
|
101
111
|
try {
|
|
102
112
|
const parsed = yaml.load(frontmatterStr);
|
|
103
113
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
104
|
-
throw new
|
|
114
|
+
throw new InputValidationError(
|
|
115
|
+
"SKILL.md frontmatter must be a YAML mapping"
|
|
116
|
+
);
|
|
105
117
|
}
|
|
106
118
|
return { raw: parsed, body };
|
|
107
119
|
} catch (e) {
|
|
108
|
-
throw new
|
|
120
|
+
throw new InputValidationError(
|
|
121
|
+
`Invalid YAML in frontmatter: ${e.message}`,
|
|
122
|
+
{ cause: e }
|
|
123
|
+
);
|
|
109
124
|
}
|
|
110
125
|
}
|
|
111
126
|
__name(parseFrontmatterYaml, "parseFrontmatterYaml");
|
|
@@ -113,7 +128,10 @@ function validateFrontmatter(raw) {
|
|
|
113
128
|
try {
|
|
114
129
|
return FrontmatterSchema.parse(raw);
|
|
115
130
|
} catch (e) {
|
|
116
|
-
throw new
|
|
131
|
+
throw new InputValidationError(
|
|
132
|
+
`Invalid YAML in frontmatter: ${e.message}`,
|
|
133
|
+
{ cause: e }
|
|
134
|
+
);
|
|
117
135
|
}
|
|
118
136
|
}
|
|
119
137
|
__name(validateFrontmatter, "validateFrontmatter");
|
|
@@ -160,6 +178,18 @@ __name(loadSkillFromDir, "loadSkillFromDir");
|
|
|
160
178
|
async function validateSkillDir(skillDir) {
|
|
161
179
|
const problems = [];
|
|
162
180
|
const resolvedDir = path.resolve(skillDir);
|
|
181
|
+
try {
|
|
182
|
+
const stats = await fs.stat(resolvedDir);
|
|
183
|
+
if (!stats.isDirectory()) {
|
|
184
|
+
return [`'${resolvedDir}' is not a directory.`];
|
|
185
|
+
}
|
|
186
|
+
} catch (e) {
|
|
187
|
+
const code = e.code;
|
|
188
|
+
if (code === "ENOENT" || code === "ENOTDIR") {
|
|
189
|
+
return [`Directory '${resolvedDir}' does not exist.`];
|
|
190
|
+
}
|
|
191
|
+
return [`Failed to access '${resolvedDir}': ${e.message}`];
|
|
192
|
+
}
|
|
163
193
|
let skill;
|
|
164
194
|
try {
|
|
165
195
|
skill = await loadSkillFile(resolvedDir);
|
|
@@ -209,7 +239,7 @@ async function loadSkillFile(skillDir) {
|
|
|
209
239
|
);
|
|
210
240
|
}
|
|
211
241
|
if (!skillMdPath) {
|
|
212
|
-
throw new
|
|
242
|
+
throw new NotFoundError(
|
|
213
243
|
`SKILL.md (or any case variation like skill.md) not found in '${skillDir}'.`
|
|
214
244
|
);
|
|
215
245
|
}
|
|
@@ -217,7 +247,7 @@ async function loadSkillFile(skillDir) {
|
|
|
217
247
|
const frontmatter = FrontmatterSchema.parse(parsed);
|
|
218
248
|
const dirName = path.basename(resolvedDir);
|
|
219
249
|
if (dirName !== frontmatter.name) {
|
|
220
|
-
throw new
|
|
250
|
+
throw new InputValidationError(
|
|
221
251
|
`Skill name '${frontmatter.name}' does not match directory name '${dirName}'.`
|
|
222
252
|
);
|
|
223
253
|
}
|
|
@@ -279,7 +309,9 @@ function loadSkillFromZipBuffer(zipBuffer) {
|
|
|
279
309
|
const entries = zip.getEntries();
|
|
280
310
|
for (const entry of entries) {
|
|
281
311
|
if (isDangerousZipEntryName(entry.entryName)) {
|
|
282
|
-
throw new
|
|
312
|
+
throw new InputValidationError(
|
|
313
|
+
`Dangerous zip entry ignored: ${entry.entryName}`
|
|
314
|
+
);
|
|
283
315
|
}
|
|
284
316
|
}
|
|
285
317
|
let skillMdContent = "";
|
|
@@ -291,15 +323,17 @@ function loadSkillFromZipBuffer(zipBuffer) {
|
|
|
291
323
|
}
|
|
292
324
|
}
|
|
293
325
|
if (!skillMdContent) {
|
|
294
|
-
throw new
|
|
326
|
+
throw new NotFoundError("SKILL.md not found in zipped filesystem.");
|
|
295
327
|
}
|
|
296
328
|
const { raw, body } = parseFrontmatterYaml(skillMdContent);
|
|
297
329
|
const skillName = raw["name"];
|
|
298
330
|
if (!skillName) {
|
|
299
|
-
throw new
|
|
331
|
+
throw new InputValidationError("SKILL.md frontmatter must contain 'name'");
|
|
300
332
|
}
|
|
301
333
|
if (typeof skillName !== "string" || !isBareSkillName(skillName)) {
|
|
302
|
-
throw new
|
|
334
|
+
throw new InputValidationError(
|
|
335
|
+
`Invalid skill name in SKILL.md: ${String(skillName)}`
|
|
336
|
+
);
|
|
303
337
|
}
|
|
304
338
|
const frontmatter = validateFrontmatter(raw);
|
|
305
339
|
const references = {};
|
|
@@ -7,7 +7,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
7
7
|
* Copyright 2025 Google LLC
|
|
8
8
|
* SPDX-License-Identifier: Apache-2.0
|
|
9
9
|
*/
|
|
10
|
-
import { metrics
|
|
10
|
+
import { metrics } from "@opentelemetry/api";
|
|
11
11
|
import { logs } from "@opentelemetry/api-logs";
|
|
12
12
|
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
13
13
|
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
|
|
@@ -39,7 +39,6 @@ function maybeSetOtelProviders(otelHooksToSetup = [], otelResource) {
|
|
|
39
39
|
spanProcessors
|
|
40
40
|
});
|
|
41
41
|
tracerProvider.register();
|
|
42
|
-
trace.setGlobalTracerProvider(tracerProvider);
|
|
43
42
|
}
|
|
44
43
|
if (metricReaders.length > 0) {
|
|
45
44
|
const meterProvider = new MeterProvider({
|
|
@@ -7,23 +7,53 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
7
7
|
* Copyright 2025 Google LLC
|
|
8
8
|
* SPDX-License-Identifier: Apache-2.0
|
|
9
9
|
*/
|
|
10
|
-
import {
|
|
10
|
+
import { ApiError } from "@google/genai";
|
|
11
|
+
import {
|
|
12
|
+
context,
|
|
13
|
+
SpanStatusCode,
|
|
14
|
+
trace
|
|
15
|
+
} from "@opentelemetry/api";
|
|
11
16
|
import { version } from "../version.js";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
var GenAiAttr = /* @__PURE__ */ ((GenAiAttr2) => {
|
|
18
|
+
GenAiAttr2["AGENT_DESCRIPTION"] = "gen_ai.agent.description";
|
|
19
|
+
GenAiAttr2["AGENT_NAME"] = "gen_ai.agent.name";
|
|
20
|
+
GenAiAttr2["CONVERSATION_ID"] = "gen_ai.conversation.id";
|
|
21
|
+
GenAiAttr2["OPERATION_NAME"] = "gen_ai.operation.name";
|
|
22
|
+
GenAiAttr2["SYSTEM"] = "gen_ai.system";
|
|
23
|
+
GenAiAttr2["TOOL_CALL_ID"] = "gen_ai.tool.call.id";
|
|
24
|
+
GenAiAttr2["TOOL_DESCRIPTION"] = "gen_ai.tool.description";
|
|
25
|
+
GenAiAttr2["TOOL_NAME"] = "gen_ai.tool.name";
|
|
26
|
+
GenAiAttr2["TOOL_TYPE"] = "gen_ai.tool.type";
|
|
27
|
+
GenAiAttr2["REQUEST_MODEL"] = "gen_ai.request.model";
|
|
28
|
+
GenAiAttr2["REQUEST_TOP_P"] = "gen_ai.request.top_p";
|
|
29
|
+
GenAiAttr2["REQUEST_MAX_TOKENS"] = "gen_ai.request.max_tokens";
|
|
30
|
+
GenAiAttr2["USAGE_INPUT_TOKENS"] = "gen_ai.usage.input_tokens";
|
|
31
|
+
GenAiAttr2["USAGE_OUTPUT_TOKENS"] = "gen_ai.usage.output_tokens";
|
|
32
|
+
GenAiAttr2["RESPONSE_FINISH_REASONS"] = "gen_ai.response.finish_reasons";
|
|
33
|
+
return GenAiAttr2;
|
|
34
|
+
})(GenAiAttr || {});
|
|
35
|
+
var AdkAttr = /* @__PURE__ */ ((AdkAttr2) => {
|
|
36
|
+
AdkAttr2["WORKFLOW_NAME"] = "adk.workflow.name";
|
|
37
|
+
AdkAttr2["NODE_PATH"] = "adk.node.path";
|
|
38
|
+
AdkAttr2["NODE_RUN_ID"] = "adk.node.run_id";
|
|
39
|
+
AdkAttr2["NODE_ATTEMPT"] = "adk.node.attempt";
|
|
40
|
+
AdkAttr2["NODE_STATUS"] = "adk.node.status";
|
|
41
|
+
AdkAttr2["NODE_INTERRUPT_COUNT"] = "adk.node.interrupt_count";
|
|
42
|
+
return AdkAttr2;
|
|
43
|
+
})(AdkAttr || {});
|
|
44
|
+
var GcpAttr = /* @__PURE__ */ ((GcpAttr2) => {
|
|
45
|
+
GcpAttr2["INVOCATION_ID"] = "gcp.vertex.agent.invocation_id";
|
|
46
|
+
GcpAttr2["SESSION_ID"] = "gcp.vertex.agent.session_id";
|
|
47
|
+
GcpAttr2["EVENT_ID"] = "gcp.vertex.agent.event_id";
|
|
48
|
+
GcpAttr2["LLM_REQUEST"] = "gcp.vertex.agent.llm_request";
|
|
49
|
+
GcpAttr2["LLM_RESPONSE"] = "gcp.vertex.agent.llm_response";
|
|
50
|
+
GcpAttr2["TOOL_CALL_ARGS"] = "gcp.vertex.agent.tool_call_args";
|
|
51
|
+
GcpAttr2["TOOL_RESPONSE"] = "gcp.vertex.agent.tool_response";
|
|
52
|
+
GcpAttr2["DATA"] = "gcp.vertex.agent.data";
|
|
53
|
+
return GcpAttr2;
|
|
54
|
+
})(GcpAttr || {});
|
|
55
|
+
const GEN_AI_SYSTEM_VALUE = "gcp.vertex.agent";
|
|
56
|
+
const tracer = trace.getTracer(GEN_AI_SYSTEM_VALUE, version);
|
|
27
57
|
function safeJsonSerialize(obj) {
|
|
28
58
|
try {
|
|
29
59
|
return JSON.stringify(obj);
|
|
@@ -39,11 +69,11 @@ function traceAgentInvocation({
|
|
|
39
69
|
const span = trace.getActiveSpan();
|
|
40
70
|
if (!span) return;
|
|
41
71
|
span.setAttributes({
|
|
42
|
-
[
|
|
72
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "invoke_agent",
|
|
43
73
|
// Conditionally Required
|
|
44
|
-
[
|
|
45
|
-
[
|
|
46
|
-
[
|
|
74
|
+
["gen_ai.agent.description" /* AGENT_DESCRIPTION */]: agent.description,
|
|
75
|
+
["gen_ai.agent.name" /* AGENT_NAME */]: agent.name,
|
|
76
|
+
["gen_ai.conversation.id" /* CONVERSATION_ID */]: invocationContext.session.id
|
|
47
77
|
});
|
|
48
78
|
}
|
|
49
79
|
__name(traceAgentInvocation, "traceAgentInvocation");
|
|
@@ -55,10 +85,10 @@ function traceWorkflowInvocation({
|
|
|
55
85
|
const span = trace.getActiveSpan();
|
|
56
86
|
if (!span) return;
|
|
57
87
|
span.setAttributes({
|
|
58
|
-
[
|
|
59
|
-
[
|
|
60
|
-
[
|
|
61
|
-
[
|
|
88
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "invoke_workflow",
|
|
89
|
+
["gen_ai.conversation.id" /* CONVERSATION_ID */]: sessionId,
|
|
90
|
+
["adk.workflow.name" /* WORKFLOW_NAME */]: workflowName,
|
|
91
|
+
["adk.node.path" /* NODE_PATH */]: nodePath
|
|
62
92
|
});
|
|
63
93
|
}
|
|
64
94
|
__name(traceWorkflowInvocation, "traceWorkflowInvocation");
|
|
@@ -72,40 +102,83 @@ function traceNodeExecution({
|
|
|
72
102
|
const span = trace.getActiveSpan();
|
|
73
103
|
if (!span) return;
|
|
74
104
|
span.setAttributes({
|
|
75
|
-
[
|
|
76
|
-
[
|
|
77
|
-
[
|
|
78
|
-
[
|
|
79
|
-
[
|
|
80
|
-
[
|
|
105
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "execute_node",
|
|
106
|
+
["adk.node.path" /* NODE_PATH */]: nodePath,
|
|
107
|
+
["adk.node.run_id" /* NODE_RUN_ID */]: runId,
|
|
108
|
+
["adk.node.attempt" /* NODE_ATTEMPT */]: attempt,
|
|
109
|
+
["adk.node.status" /* NODE_STATUS */]: status,
|
|
110
|
+
["adk.node.interrupt_count" /* NODE_INTERRUPT_COUNT */]: interruptCount
|
|
81
111
|
});
|
|
82
112
|
}
|
|
83
113
|
__name(traceNodeExecution, "traceNodeExecution");
|
|
84
|
-
function
|
|
85
|
-
tool,
|
|
86
|
-
args,
|
|
87
|
-
functionResponseEvent
|
|
88
|
-
}) {
|
|
114
|
+
function resolveErrorType(error) {
|
|
89
115
|
var _a, _b;
|
|
90
|
-
|
|
116
|
+
if (error !== null && (typeof error === "object" || typeof error === "function")) {
|
|
117
|
+
try {
|
|
118
|
+
const errorObject = error;
|
|
119
|
+
const customErrorType = (_a = errorObject.errorType) != null ? _a : errorObject.error_type;
|
|
120
|
+
if (typeof customErrorType === "string" || typeof customErrorType === "number") {
|
|
121
|
+
return String(customErrorType);
|
|
122
|
+
}
|
|
123
|
+
if (error instanceof ApiError) {
|
|
124
|
+
return String(error.status);
|
|
125
|
+
}
|
|
126
|
+
const constructorName = (_b = errorObject.constructor) == null ? void 0 : _b.name;
|
|
127
|
+
if (typeof constructorName === "string" && constructorName.length > 0) {
|
|
128
|
+
return constructorName;
|
|
129
|
+
}
|
|
130
|
+
} catch {
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return typeof error;
|
|
134
|
+
}
|
|
135
|
+
__name(resolveErrorType, "resolveErrorType");
|
|
136
|
+
function traceToolCall(params) {
|
|
137
|
+
var _a, _b, _c;
|
|
138
|
+
const {
|
|
139
|
+
tool,
|
|
140
|
+
args,
|
|
141
|
+
functionResponseEvent,
|
|
142
|
+
invocationContext,
|
|
143
|
+
error,
|
|
144
|
+
errorType
|
|
145
|
+
} = params;
|
|
146
|
+
const span = (_a = params.span) != null ? _a : trace.getActiveSpan();
|
|
91
147
|
if (!span) return;
|
|
148
|
+
const hasError = Object.hasOwn(params, "error");
|
|
149
|
+
const failureType = hasError ? resolveErrorType(error) : errorType;
|
|
150
|
+
if (hasError) {
|
|
151
|
+
let exception;
|
|
152
|
+
try {
|
|
153
|
+
exception = error instanceof Error ? error : resolveErrorType(error);
|
|
154
|
+
} catch {
|
|
155
|
+
exception = resolveErrorType(error);
|
|
156
|
+
}
|
|
157
|
+
span.recordException(exception);
|
|
158
|
+
}
|
|
159
|
+
if (failureType !== void 0) {
|
|
160
|
+
span.setAttribute("error.type", failureType);
|
|
161
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: failureType });
|
|
162
|
+
}
|
|
92
163
|
span.setAttributes({
|
|
93
|
-
[
|
|
94
|
-
[
|
|
95
|
-
[
|
|
164
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "execute_tool",
|
|
165
|
+
["gen_ai.system" /* SYSTEM */]: GEN_AI_SYSTEM_VALUE,
|
|
166
|
+
["gen_ai.tool.description" /* TOOL_DESCRIPTION */]: tool.description || "",
|
|
167
|
+
["gen_ai.tool.name" /* TOOL_NAME */]: tool.name,
|
|
96
168
|
// e.g. FunctionTool
|
|
97
|
-
[
|
|
169
|
+
["gen_ai.tool.type" /* TOOL_TYPE */]: tool.constructor.name,
|
|
170
|
+
["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
|
|
98
171
|
// Setting empty llm request and response (as UI expect these) while not
|
|
99
172
|
// applicable for tool_response.
|
|
100
|
-
"gcp.vertex.agent.llm_request": "{}",
|
|
101
|
-
"gcp.vertex.agent.llm_response": "{}",
|
|
102
|
-
"gcp.vertex.agent.tool_call_args": shouldAddRequestResponseToSpans() ? safeJsonSerialize(args) : "{}"
|
|
173
|
+
["gcp.vertex.agent.llm_request" /* LLM_REQUEST */]: "{}",
|
|
174
|
+
["gcp.vertex.agent.llm_response" /* LLM_RESPONSE */]: "{}",
|
|
175
|
+
["gcp.vertex.agent.tool_call_args" /* TOOL_CALL_ARGS */]: shouldAddRequestResponseToSpans() ? safeJsonSerialize(args) : "{}"
|
|
103
176
|
});
|
|
104
177
|
let toolCallId = "<not specified>";
|
|
105
178
|
let toolResponse = "<not specified>";
|
|
106
|
-
if ((
|
|
179
|
+
if ((_b = functionResponseEvent == null ? void 0 : functionResponseEvent.content) == null ? void 0 : _b.parts) {
|
|
107
180
|
const responseParts = functionResponseEvent.content.parts;
|
|
108
|
-
const functionResponse = (
|
|
181
|
+
const functionResponse = (_c = responseParts[0]) == null ? void 0 : _c.functionResponse;
|
|
109
182
|
if (functionResponse == null ? void 0 : functionResponse.id) {
|
|
110
183
|
toolCallId = functionResponse.id;
|
|
111
184
|
}
|
|
@@ -117,32 +190,35 @@ function traceToolCall({
|
|
|
117
190
|
toolResponse = { result: toolResponse };
|
|
118
191
|
}
|
|
119
192
|
span.setAttributes({
|
|
120
|
-
[
|
|
121
|
-
"gcp.vertex.agent.event_id": functionResponseEvent.id,
|
|
122
|
-
"gcp.vertex.agent.tool_response": shouldAddRequestResponseToSpans() ? safeJsonSerialize(toolResponse) : "{}"
|
|
193
|
+
["gen_ai.tool.call.id" /* TOOL_CALL_ID */]: toolCallId,
|
|
194
|
+
...functionResponseEvent ? { ["gcp.vertex.agent.event_id" /* EVENT_ID */]: functionResponseEvent.id } : {},
|
|
195
|
+
["gcp.vertex.agent.tool_response" /* TOOL_RESPONSE */]: shouldAddRequestResponseToSpans() ? safeJsonSerialize(toolResponse) : "{}"
|
|
123
196
|
});
|
|
124
197
|
}
|
|
125
198
|
__name(traceToolCall, "traceToolCall");
|
|
126
199
|
function traceMergedToolCalls({
|
|
127
200
|
responseEventId,
|
|
128
|
-
functionResponseEvent
|
|
201
|
+
functionResponseEvent,
|
|
202
|
+
invocationContext
|
|
129
203
|
}) {
|
|
130
204
|
const span = trace.getActiveSpan();
|
|
131
205
|
if (!span) return;
|
|
132
206
|
span.setAttributes({
|
|
133
|
-
[
|
|
134
|
-
[
|
|
135
|
-
[
|
|
136
|
-
[
|
|
137
|
-
"
|
|
138
|
-
"gcp.vertex.agent.
|
|
207
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "execute_tool",
|
|
208
|
+
["gen_ai.system" /* SYSTEM */]: GEN_AI_SYSTEM_VALUE,
|
|
209
|
+
["gen_ai.tool.name" /* TOOL_NAME */]: "(merged tools)",
|
|
210
|
+
["gen_ai.tool.description" /* TOOL_DESCRIPTION */]: "(merged tools)",
|
|
211
|
+
["gen_ai.tool.call.id" /* TOOL_CALL_ID */]: responseEventId,
|
|
212
|
+
["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
|
|
213
|
+
["gcp.vertex.agent.tool_call_args" /* TOOL_CALL_ARGS */]: "N/A",
|
|
214
|
+
["gcp.vertex.agent.event_id" /* EVENT_ID */]: responseEventId,
|
|
139
215
|
// Setting empty llm request and response (as UI expect these) while not
|
|
140
216
|
// applicable for tool_response.
|
|
141
|
-
"gcp.vertex.agent.llm_request": "{}",
|
|
142
|
-
"gcp.vertex.agent.llm_response": "{}"
|
|
217
|
+
["gcp.vertex.agent.llm_request" /* LLM_REQUEST */]: "{}",
|
|
218
|
+
["gcp.vertex.agent.llm_response" /* LLM_RESPONSE */]: "{}"
|
|
143
219
|
});
|
|
144
220
|
span.setAttribute(
|
|
145
|
-
"gcp.vertex.agent.tool_response"
|
|
221
|
+
"gcp.vertex.agent.tool_response" /* TOOL_RESPONSE */,
|
|
146
222
|
shouldAddRequestResponseToSpans() ? safeJsonSerialize(functionResponseEvent) : "{}"
|
|
147
223
|
);
|
|
148
224
|
}
|
|
@@ -157,43 +233,43 @@ function traceCallLlm({
|
|
|
157
233
|
const span = trace.getActiveSpan();
|
|
158
234
|
if (!span) return;
|
|
159
235
|
span.setAttributes({
|
|
160
|
-
"gen_ai.system":
|
|
161
|
-
"gen_ai.request.model": llmRequest.model,
|
|
162
|
-
...((_a = invocationContext.agent) == null ? void 0 : _a.name) ? { [
|
|
163
|
-
"gcp.vertex.agent.invocation_id": invocationContext.invocationId,
|
|
164
|
-
"gcp.vertex.agent.session_id": invocationContext.session.id,
|
|
165
|
-
"gcp.vertex.agent.event_id": eventId,
|
|
236
|
+
["gen_ai.system" /* SYSTEM */]: GEN_AI_SYSTEM_VALUE,
|
|
237
|
+
["gen_ai.request.model" /* REQUEST_MODEL */]: llmRequest.model,
|
|
238
|
+
...((_a = invocationContext.agent) == null ? void 0 : _a.name) ? { ["gen_ai.agent.name" /* AGENT_NAME */]: invocationContext.agent.name } : {},
|
|
239
|
+
["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
|
|
240
|
+
["gcp.vertex.agent.session_id" /* SESSION_ID */]: invocationContext.session.id,
|
|
241
|
+
["gcp.vertex.agent.event_id" /* EVENT_ID */]: eventId,
|
|
166
242
|
// Consider removing once GenAI SDK provides a way to record this info.
|
|
167
|
-
"gcp.vertex.agent.llm_request": shouldAddRequestResponseToSpans() ? safeJsonSerialize(buildLlmRequestForTrace(llmRequest)) : "{}"
|
|
243
|
+
["gcp.vertex.agent.llm_request" /* LLM_REQUEST */]: shouldAddRequestResponseToSpans() ? safeJsonSerialize(buildLlmRequestForTrace(llmRequest)) : "{}"
|
|
168
244
|
});
|
|
169
245
|
if ((_b = llmRequest.config) == null ? void 0 : _b.topP) {
|
|
170
|
-
span.setAttribute("gen_ai.request.top_p"
|
|
246
|
+
span.setAttribute("gen_ai.request.top_p" /* REQUEST_TOP_P */, llmRequest.config.topP);
|
|
171
247
|
}
|
|
172
248
|
if (((_c = llmRequest.config) == null ? void 0 : _c.maxOutputTokens) !== void 0) {
|
|
173
249
|
span.setAttribute(
|
|
174
|
-
"gen_ai.request.max_tokens"
|
|
250
|
+
"gen_ai.request.max_tokens" /* REQUEST_MAX_TOKENS */,
|
|
175
251
|
llmRequest.config.maxOutputTokens
|
|
176
252
|
);
|
|
177
253
|
}
|
|
178
254
|
span.setAttribute(
|
|
179
|
-
"gcp.vertex.agent.llm_response"
|
|
255
|
+
"gcp.vertex.agent.llm_response" /* LLM_RESPONSE */,
|
|
180
256
|
shouldAddRequestResponseToSpans() ? safeJsonSerialize(llmResponse) : "{}"
|
|
181
257
|
);
|
|
182
258
|
if (llmResponse.usageMetadata) {
|
|
183
259
|
span.setAttribute(
|
|
184
|
-
"gen_ai.usage.input_tokens"
|
|
260
|
+
"gen_ai.usage.input_tokens" /* USAGE_INPUT_TOKENS */,
|
|
185
261
|
llmResponse.usageMetadata.promptTokenCount || 0
|
|
186
262
|
);
|
|
187
263
|
}
|
|
188
264
|
if ((_d = llmResponse.usageMetadata) == null ? void 0 : _d.candidatesTokenCount) {
|
|
189
265
|
span.setAttribute(
|
|
190
|
-
"gen_ai.usage.output_tokens"
|
|
266
|
+
"gen_ai.usage.output_tokens" /* USAGE_OUTPUT_TOKENS */,
|
|
191
267
|
llmResponse.usageMetadata.candidatesTokenCount
|
|
192
268
|
);
|
|
193
269
|
}
|
|
194
270
|
if (llmResponse.finishReason) {
|
|
195
271
|
const finishReasonValue = typeof llmResponse.finishReason === "string" ? llmResponse.finishReason.toLowerCase() : String(llmResponse.finishReason).toLowerCase();
|
|
196
|
-
span.setAttribute("gen_ai.response.finish_reasons"
|
|
272
|
+
span.setAttribute("gen_ai.response.finish_reasons" /* RESPONSE_FINISH_REASONS */, [finishReasonValue]);
|
|
197
273
|
}
|
|
198
274
|
}
|
|
199
275
|
__name(traceCallLlm, "traceCallLlm");
|
|
@@ -205,11 +281,11 @@ function traceSendData({
|
|
|
205
281
|
const span = trace.getActiveSpan();
|
|
206
282
|
if (!span) return;
|
|
207
283
|
span.setAttributes({
|
|
208
|
-
"gcp.vertex.agent.invocation_id": invocationContext.invocationId,
|
|
209
|
-
"gcp.vertex.agent.event_id": eventId
|
|
284
|
+
["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
|
|
285
|
+
["gcp.vertex.agent.event_id" /* EVENT_ID */]: eventId
|
|
210
286
|
});
|
|
211
287
|
span.setAttribute(
|
|
212
|
-
"gcp.vertex.agent.data"
|
|
288
|
+
"gcp.vertex.agent.data" /* DATA */,
|
|
213
289
|
shouldAddRequestResponseToSpans() ? safeJsonSerialize(data) : "{}"
|
|
214
290
|
);
|
|
215
291
|
}
|
|
@@ -272,6 +348,7 @@ function shouldAddRequestResponseToSpans() {
|
|
|
272
348
|
}
|
|
273
349
|
__name(shouldAddRequestResponseToSpans, "shouldAddRequestResponseToSpans");
|
|
274
350
|
export {
|
|
351
|
+
resolveErrorType,
|
|
275
352
|
runAsyncGeneratorWithOtelContext,
|
|
276
353
|
traceAgentInvocation,
|
|
277
354
|
traceCallLlm,
|
|
@@ -17,6 +17,44 @@ import { GoogleLLMVariant } from "../utils/variant_utils.js";
|
|
|
17
17
|
import { State } from "../sessions/state.js";
|
|
18
18
|
import { BaseTool } from "./base_tool.js";
|
|
19
19
|
import { ForwardingArtifactService } from "./forwarding_artifact_service.js";
|
|
20
|
+
import { parseWithSchema } from "../utils/schema.js";
|
|
21
|
+
import { isZodSchema } from "../utils/simple_zod_to_json.js";
|
|
22
|
+
function excludeNone(value) {
|
|
23
|
+
if (Array.isArray(value)) {
|
|
24
|
+
return value.map((item) => excludeNone(item));
|
|
25
|
+
}
|
|
26
|
+
if (value !== null && typeof value === "object") {
|
|
27
|
+
const result = {};
|
|
28
|
+
for (const [key, val] of Object.entries(value)) {
|
|
29
|
+
if (val !== null && val !== void 0) {
|
|
30
|
+
result[key] = excludeNone(val);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
__name(excludeNone, "excludeNone");
|
|
38
|
+
function validateAndStripAgentInput(agent, args) {
|
|
39
|
+
var _a2;
|
|
40
|
+
if (typeof args !== "object" || args === null || Array.isArray(args)) {
|
|
41
|
+
throw new Error("AgentTool input args must be a plain object.");
|
|
42
|
+
}
|
|
43
|
+
const schema = isZodSchema(agent.inputSchema) ? agent.inputSchema : (_a2 = agent.inputSchemaSource) != null ? _a2 : agent.inputSchema;
|
|
44
|
+
const validated = parseWithSchema(schema, args);
|
|
45
|
+
return excludeNone(validated);
|
|
46
|
+
}
|
|
47
|
+
__name(validateAndStripAgentInput, "validateAndStripAgentInput");
|
|
48
|
+
function validateAndStripAgentOutput(agent, mergedText) {
|
|
49
|
+
var _a2;
|
|
50
|
+
const parsed = JSON.parse(mergedText);
|
|
51
|
+
const validated = typeof agent.validateOutput === "function" ? agent.validateOutput(parsed) : parseWithSchema(
|
|
52
|
+
isZodSchema(agent.outputSchema) ? agent.outputSchema : (_a2 = agent.outputSchemaSource) != null ? _a2 : agent.outputSchema,
|
|
53
|
+
parsed
|
|
54
|
+
);
|
|
55
|
+
return excludeNone(validated);
|
|
56
|
+
}
|
|
57
|
+
__name(validateAndStripAgentOutput, "validateAndStripAgentOutput");
|
|
20
58
|
const AGENT_TOOL_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for("google.adk.agentTool");
|
|
21
59
|
function isAgentTool(obj) {
|
|
22
60
|
return typeof obj === "object" && obj !== null && AGENT_TOOL_SIGNATURE_SYMBOL in obj && obj[AGENT_TOOL_SIGNATURE_SYMBOL] === true;
|
|
@@ -70,6 +108,9 @@ const _AgentTool = class _AgentTool extends (_b = BaseTool, _a = AGENT_TOOL_SIGN
|
|
|
70
108
|
}) {
|
|
71
109
|
var _a2, _b2, _c, _d, _e, _f;
|
|
72
110
|
const hasInputSchema = isLlmAgent(this.agent) && this.agent.inputSchema;
|
|
111
|
+
if (hasInputSchema && isLlmAgent(this.agent)) {
|
|
112
|
+
args = validateAndStripAgentInput(this.agent, args);
|
|
113
|
+
}
|
|
73
114
|
const content = {
|
|
74
115
|
role: "user",
|
|
75
116
|
parts: [
|
|
@@ -124,6 +165,9 @@ const _AgentTool = class _AgentTool extends (_b = BaseTool, _a = AGENT_TOOL_SIGN
|
|
|
124
165
|
}
|
|
125
166
|
const hasOutputSchema = isLlmAgent(this.agent) && this.agent.outputSchema;
|
|
126
167
|
const mergedText = lastEvent.content.parts.filter((part) => !part.thought).map((part) => part.text).filter((text) => text).join("\n");
|
|
168
|
+
if (hasOutputSchema && isLlmAgent(this.agent)) {
|
|
169
|
+
return validateAndStripAgentOutput(this.agent, mergedText);
|
|
170
|
+
}
|
|
127
171
|
return hasOutputSchema ? JSON.parse(mergedText) : mergedText;
|
|
128
172
|
}
|
|
129
173
|
};
|
|
@@ -0,0 +1,101 @@
|
|
|
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
7
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
8
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
9
|
+
if (decorator = decorators[i])
|
|
10
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
11
|
+
if (kind && result) __defProp(target, key, result);
|
|
12
|
+
return result;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* @license
|
|
16
|
+
* Copyright 2026 Google LLC
|
|
17
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
18
|
+
*/
|
|
19
|
+
import * as yaml from "js-yaml";
|
|
20
|
+
import { toSnakeCaseName } from "../../utils/case_utils.js";
|
|
21
|
+
import { experimental } from "../../utils/experimental.js";
|
|
22
|
+
import { BaseToolset } from "../base_toolset.js";
|
|
23
|
+
import { OpenAPIToolset } from "../openapi_tool/openapi_toolset.js";
|
|
24
|
+
import { APIHubClient } from "./clients/apihub_client.js";
|
|
25
|
+
let APIHubToolset = class extends BaseToolset {
|
|
26
|
+
constructor(options) {
|
|
27
|
+
var _a, _b, _c, _d, _e;
|
|
28
|
+
super((_a = options.toolFilter) != null ? _a : []);
|
|
29
|
+
this.name = (_b = options.name) != null ? _b : "";
|
|
30
|
+
this.description = (_c = options.description) != null ? _c : "";
|
|
31
|
+
this.apihubResourceName = options.apihubResourceName;
|
|
32
|
+
this.lazyLoadSpec = (_d = options.lazyLoadSpec) != null ? _d : false;
|
|
33
|
+
this.authScheme = options.authScheme;
|
|
34
|
+
this.authCredential = options.authCredential;
|
|
35
|
+
this.apihubClient = (_e = options.apihubClient) != null ? _e : new APIHubClient({
|
|
36
|
+
accessToken: options.accessToken,
|
|
37
|
+
serviceAccountJson: options.serviceAccountJson
|
|
38
|
+
});
|
|
39
|
+
if (!this.lazyLoadSpec) {
|
|
40
|
+
this.toolsetPromise = this.prepareTools();
|
|
41
|
+
this.toolsetPromise.catch(() => void 0);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Returns one tool per operation in the spec, or an empty array when the
|
|
46
|
+
* spec is empty.
|
|
47
|
+
*
|
|
48
|
+
* @throws When the spec cannot be fetched or is not valid YAML or JSON.
|
|
49
|
+
*/
|
|
50
|
+
async getTools(context) {
|
|
51
|
+
const toolset = await this.loadToolset();
|
|
52
|
+
return toolset ? toolset.getTools(context) : [];
|
|
53
|
+
}
|
|
54
|
+
async close() {
|
|
55
|
+
if (!this.toolsetPromise) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const toolset = await this.toolsetPromise.catch(() => void 0);
|
|
59
|
+
await (toolset == null ? void 0 : toolset.close());
|
|
60
|
+
}
|
|
61
|
+
loadToolset() {
|
|
62
|
+
if (!this.toolsetPromise) {
|
|
63
|
+
const promise = this.prepareTools();
|
|
64
|
+
this.toolsetPromise = promise;
|
|
65
|
+
promise.catch(() => {
|
|
66
|
+
if (this.toolsetPromise === promise) {
|
|
67
|
+
this.toolsetPromise = void 0;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return this.toolsetPromise;
|
|
72
|
+
}
|
|
73
|
+
async prepareTools() {
|
|
74
|
+
var _a, _b, _c, _d;
|
|
75
|
+
const spec = await this.apihubClient.getSpecContent(
|
|
76
|
+
this.apihubResourceName
|
|
77
|
+
);
|
|
78
|
+
if (!spec.trim()) {
|
|
79
|
+
return void 0;
|
|
80
|
+
}
|
|
81
|
+
const specDict = yaml.load(spec);
|
|
82
|
+
if (!specDict) {
|
|
83
|
+
return void 0;
|
|
84
|
+
}
|
|
85
|
+
this.name || (this.name = toSnakeCaseName((_b = (_a = specDict.info) == null ? void 0 : _a.title) != null ? _b : "unnamed"));
|
|
86
|
+
this.description || (this.description = (_d = (_c = specDict.info) == null ? void 0 : _c.description) != null ? _d : "");
|
|
87
|
+
return new OpenAPIToolset({
|
|
88
|
+
specDict,
|
|
89
|
+
authScheme: this.authScheme,
|
|
90
|
+
authCredential: this.authCredential,
|
|
91
|
+
toolFilter: this.toolFilter
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
__name(APIHubToolset, "APIHubToolset");
|
|
96
|
+
APIHubToolset = __decorateClass([
|
|
97
|
+
experimental
|
|
98
|
+
], APIHubToolset);
|
|
99
|
+
export {
|
|
100
|
+
APIHubToolset
|
|
101
|
+
};
|