@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
package/dist/esm/events/event.js
CHANGED
|
@@ -91,8 +91,10 @@ function stringifyContent(event) {
|
|
|
91
91
|
__name(stringifyContent, "stringifyContent");
|
|
92
92
|
function getEventTokens(event) {
|
|
93
93
|
var _a;
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
const usage = event.usageMetadata;
|
|
95
|
+
const promptTokenCount = (_a = usage == null ? void 0 : usage.initialPromptTokenCount) != null ? _a : usage == null ? void 0 : usage.promptTokenCount;
|
|
96
|
+
if (promptTokenCount !== void 0) {
|
|
97
|
+
return promptTokenCount;
|
|
96
98
|
}
|
|
97
99
|
const contentStr = stringifyContent(event);
|
|
98
100
|
return Math.ceil(contentStr.length / 4);
|
|
@@ -7,11 +7,30 @@ 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 { z } from "zod";
|
|
11
|
+
import { InputValidationError } from "../errors/input_validation_error.js";
|
|
10
12
|
import { getFunctionResponses } from "../events/event.js";
|
|
11
13
|
import { logger } from "../utils/logger.js";
|
|
12
14
|
import {
|
|
13
15
|
isBaseExampleProvider
|
|
14
16
|
} from "./base_example_provider.js";
|
|
17
|
+
const contentSchema = z.object({
|
|
18
|
+
role: z.string().optional(),
|
|
19
|
+
parts: z.array(z.object({}).loose()).optional()
|
|
20
|
+
}).loose();
|
|
21
|
+
const examplesSchema = z.array(
|
|
22
|
+
z.object({ input: contentSchema, output: z.array(contentSchema) })
|
|
23
|
+
);
|
|
24
|
+
function validateExamples(examples) {
|
|
25
|
+
const result = examplesSchema.safeParse(examples);
|
|
26
|
+
if (!result.success) {
|
|
27
|
+
throw new InputValidationError(
|
|
28
|
+
`Invalid few-shot examples:
|
|
29
|
+
${z.prettifyError(result.error)}`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
__name(validateExamples, "validateExamples");
|
|
15
34
|
const EXAMPLES_INTRO = "<EXAMPLES>\nBegin few-shot\nThe following are examples of user queries and model responses using the available tools.\n\n";
|
|
16
35
|
const EXAMPLES_END = "End few-shot\n<EXAMPLES>";
|
|
17
36
|
const EXAMPLE_START = "EXAMPLE {}:\nBegin example\n";
|
|
@@ -102,5 +121,6 @@ export {
|
|
|
102
121
|
_getLatestMessageFromUser,
|
|
103
122
|
buildExampleSi,
|
|
104
123
|
convertExamplesToText,
|
|
105
|
-
getLatestMessageFromUser
|
|
124
|
+
getLatestMessageFromUser,
|
|
125
|
+
validateExamples
|
|
106
126
|
};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
/**
|
|
6
|
+
* @license
|
|
7
|
+
* Copyright 2026 Google LLC
|
|
8
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
*/
|
|
10
|
+
var AudioEncoding = /* @__PURE__ */ ((AudioEncoding2) => {
|
|
11
|
+
AudioEncoding2[AudioEncoding2["ENCODING_UNSPECIFIED"] = 0] = "ENCODING_UNSPECIFIED";
|
|
12
|
+
AudioEncoding2[AudioEncoding2["LINEAR16"] = 1] = "LINEAR16";
|
|
13
|
+
return AudioEncoding2;
|
|
14
|
+
})(AudioEncoding || {});
|
|
15
|
+
function isSpeechClientLike(value) {
|
|
16
|
+
return typeof value === "object" && value !== null && typeof value.recognize === "function";
|
|
17
|
+
}
|
|
18
|
+
__name(isSpeechClientLike, "isSpeechClientLike");
|
|
19
|
+
function isContentEntry(data) {
|
|
20
|
+
return "parts" in data || !("data" in data) && !("mimeType" in data);
|
|
21
|
+
}
|
|
22
|
+
__name(isContentEntry, "isContentEntry");
|
|
23
|
+
function blobDataToBytes(data) {
|
|
24
|
+
if (typeof data !== "string") {
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
if (data.length > 0 && data.length % 4 === 0 && /^[A-Za-z0-9+/]+={0,2}$/.test(data)) {
|
|
28
|
+
const atobFn = globalThis.atob;
|
|
29
|
+
if (typeof Buffer === "undefined" && typeof atobFn === "function") {
|
|
30
|
+
const binary = atobFn(data);
|
|
31
|
+
return Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
32
|
+
}
|
|
33
|
+
return new Uint8Array(Buffer.from(data, "base64"));
|
|
34
|
+
}
|
|
35
|
+
return new TextEncoder().encode(data);
|
|
36
|
+
}
|
|
37
|
+
__name(blobDataToBytes, "blobDataToBytes");
|
|
38
|
+
function concatBytes(first, second) {
|
|
39
|
+
const merged = new Uint8Array(first.length + second.length);
|
|
40
|
+
merged.set(first, 0);
|
|
41
|
+
merged.set(second, first.length);
|
|
42
|
+
return merged;
|
|
43
|
+
}
|
|
44
|
+
__name(concatBytes, "concatBytes");
|
|
45
|
+
const _AudioTranscriber = class _AudioTranscriber {
|
|
46
|
+
constructor(optionsOrClient) {
|
|
47
|
+
if (isSpeechClientLike(optionsOrClient)) {
|
|
48
|
+
this.client = optionsOrClient;
|
|
49
|
+
} else if (optionsOrClient == null ? void 0 : optionsOrClient.client) {
|
|
50
|
+
this.client = optionsOrClient.client;
|
|
51
|
+
} else {
|
|
52
|
+
this.client = {
|
|
53
|
+
recognize() {
|
|
54
|
+
throw new Error(
|
|
55
|
+
"SpeechClient is not configured on AudioTranscriber. Pass a SpeechClientLike implementation to new AudioTranscriber({client})."
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Bundles consecutive audio blobs from the same speaker in
|
|
63
|
+
* `invocationContext.transcriptionCache`, transcribes user audio bundles into
|
|
64
|
+
* text `Content` entries, preserves already-transcribed `Content`
|
|
65
|
+
* entries in order, clears `invocationContext.transcriptionCache`, and
|
|
66
|
+
* returns the resulting content list.
|
|
67
|
+
*
|
|
68
|
+
* @param invocationContext The invocation context holding `transcriptionCache`.
|
|
69
|
+
* @returns Ordered list of transcribed `Content` objects.
|
|
70
|
+
*/
|
|
71
|
+
async transcribeFile(invocationContext) {
|
|
72
|
+
var _a, _b, _c, _d;
|
|
73
|
+
const bundledAudio = [];
|
|
74
|
+
const transcriptionHistory = [];
|
|
75
|
+
let currentSpeaker = void 0;
|
|
76
|
+
let currentAudioData = new Uint8Array(0);
|
|
77
|
+
for (const transcriptionEntry of (_a = invocationContext.transcriptionCache) != null ? _a : []) {
|
|
78
|
+
const speaker = transcriptionEntry.role;
|
|
79
|
+
const audioData = transcriptionEntry.data;
|
|
80
|
+
if (isContentEntry(audioData)) {
|
|
81
|
+
if (currentSpeaker !== void 0) {
|
|
82
|
+
bundledAudio.push([currentSpeaker, currentAudioData]);
|
|
83
|
+
currentSpeaker = void 0;
|
|
84
|
+
currentAudioData = new Uint8Array(0);
|
|
85
|
+
}
|
|
86
|
+
bundledAudio.push([speaker, audioData]);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const rawData = audioData.data;
|
|
90
|
+
if (!rawData) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const chunkBytes = blobDataToBytes(rawData);
|
|
94
|
+
if (chunkBytes.length === 0) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (speaker === currentSpeaker) {
|
|
98
|
+
currentAudioData = concatBytes(currentAudioData, chunkBytes);
|
|
99
|
+
} else {
|
|
100
|
+
if (currentSpeaker !== void 0) {
|
|
101
|
+
bundledAudio.push([currentSpeaker, currentAudioData]);
|
|
102
|
+
}
|
|
103
|
+
currentSpeaker = speaker;
|
|
104
|
+
currentAudioData = chunkBytes;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (currentSpeaker !== void 0) {
|
|
108
|
+
bundledAudio.push([currentSpeaker, currentAudioData]);
|
|
109
|
+
}
|
|
110
|
+
invocationContext.transcriptionCache = [];
|
|
111
|
+
for (const [speaker, data] of bundledAudio) {
|
|
112
|
+
if (ArrayBuffer.isView(data)) {
|
|
113
|
+
const audio = { content: data };
|
|
114
|
+
const config = {
|
|
115
|
+
encoding: 1 /* LINEAR16 */,
|
|
116
|
+
sampleRateHertz: 16e3,
|
|
117
|
+
languageCode: "en-US"
|
|
118
|
+
};
|
|
119
|
+
const rawResponse = await this.client.recognize({ config, audio });
|
|
120
|
+
const response = Array.isArray(rawResponse) ? rawResponse[0] : rawResponse;
|
|
121
|
+
for (const result of (_b = response.results) != null ? _b : []) {
|
|
122
|
+
const transcript = (_d = (_c = result.alternatives) == null ? void 0 : _c[0]) == null ? void 0 : _d.transcript;
|
|
123
|
+
if (transcript !== void 0 && transcript !== null) {
|
|
124
|
+
transcriptionHistory.push({
|
|
125
|
+
role: speaker ? speaker.toLowerCase() : "user",
|
|
126
|
+
parts: [{ text: transcript }]
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
transcriptionHistory.push(data);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return transcriptionHistory;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
__name(_AudioTranscriber, "AudioTranscriber");
|
|
138
|
+
let AudioTranscriber = _AudioTranscriber;
|
|
139
|
+
export {
|
|
140
|
+
AudioEncoding,
|
|
141
|
+
AudioTranscriber
|
|
142
|
+
};
|
package/dist/esm/index.js
CHANGED
|
@@ -26,7 +26,15 @@ export * from "./common.js";
|
|
|
26
26
|
import { LocalEnvironment } from "./environment/local_environment.js";
|
|
27
27
|
import { VertexAiMemoryBankService } from "./memory/vertex_ai_memory_bank_service.js";
|
|
28
28
|
import { VertexAiRagMemoryService } from "./memory/vertex_ai_rag_memory_service.js";
|
|
29
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
DebugLoggingPlugin,
|
|
31
|
+
isDebugLoggingPlugin
|
|
32
|
+
} from "./plugins/debug_logging_plugin.js";
|
|
33
|
+
import {
|
|
34
|
+
DatabaseSessionService,
|
|
35
|
+
isStaleSessionError,
|
|
36
|
+
StaleSessionError
|
|
37
|
+
} from "./sessions/database_session_service.js";
|
|
30
38
|
import { getSessionServiceFromUri } from "./sessions/registry.js";
|
|
31
39
|
import { VertexAiSessionService } from "./sessions/vertex_ai_session_service.js";
|
|
32
40
|
import { GCPSkillRegistry } from "./skills/gcp_skill_registry.js";
|
|
@@ -36,6 +44,43 @@ import {
|
|
|
36
44
|
loadSkillFromZipBuffer,
|
|
37
45
|
validateSkillDir
|
|
38
46
|
} from "./skills/loader.js";
|
|
47
|
+
import {
|
|
48
|
+
APIHubToolset
|
|
49
|
+
} from "./tools/apihub_tool/apihub_toolset.js";
|
|
50
|
+
import {
|
|
51
|
+
APIHubClient
|
|
52
|
+
} from "./tools/apihub_tool/clients/apihub_client.js";
|
|
53
|
+
import {
|
|
54
|
+
SecretManagerClient
|
|
55
|
+
} from "./tools/apihub_tool/clients/secret_client.js";
|
|
56
|
+
import {
|
|
57
|
+
ApplicationIntegrationToolset
|
|
58
|
+
} from "./tools/application_integration_tool/application_integration_toolset.js";
|
|
59
|
+
import {
|
|
60
|
+
actionRequest,
|
|
61
|
+
actionResponse,
|
|
62
|
+
ConnectionsClient,
|
|
63
|
+
CONNECTOR_BASE_SPEC,
|
|
64
|
+
connectorPayload,
|
|
65
|
+
createOperation,
|
|
66
|
+
createOperationRequest,
|
|
67
|
+
deleteOperation,
|
|
68
|
+
deleteOperationRequest,
|
|
69
|
+
executeCustomQueryRequest,
|
|
70
|
+
getActionOperation,
|
|
71
|
+
getOperation,
|
|
72
|
+
getOperationRequest,
|
|
73
|
+
listOperation,
|
|
74
|
+
listOperationRequest,
|
|
75
|
+
updateOperation,
|
|
76
|
+
updateOperationRequest
|
|
77
|
+
} from "./tools/application_integration_tool/clients/connections_client.js";
|
|
78
|
+
import {
|
|
79
|
+
IntegrationClient
|
|
80
|
+
} from "./tools/application_integration_tool/clients/integration_client.js";
|
|
81
|
+
import {
|
|
82
|
+
IntegrationConnectorTool
|
|
83
|
+
} from "./tools/application_integration_tool/integration_connector_tool.js";
|
|
39
84
|
import { LOAD_WEB_PAGE, loadWebPage } from "./tools/load_web_page.js";
|
|
40
85
|
import {
|
|
41
86
|
credentialToParam,
|
|
@@ -54,6 +99,7 @@ import {
|
|
|
54
99
|
} from "./tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.js";
|
|
55
100
|
import {
|
|
56
101
|
exchangeCredential,
|
|
102
|
+
generateAuthToken,
|
|
57
103
|
OAuth2BearerExchanger
|
|
58
104
|
} from "./tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js";
|
|
59
105
|
import { ServiceAccountCredentialExchanger } from "./tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js";
|
|
@@ -86,59 +132,125 @@ import { SkillToolset } from "./tools/skill/skill_toolset.js";
|
|
|
86
132
|
export * from "./integrations/agent_registry/agent_registry.js";
|
|
87
133
|
export * from "./telemetry/google_cloud.js";
|
|
88
134
|
export * from "./telemetry/setup.js";
|
|
135
|
+
export * from "./tools/google_api_tool/index.js";
|
|
136
|
+
import {
|
|
137
|
+
DEFAULT_CRITERIA,
|
|
138
|
+
EVAL_SESSION_ID_PREFIX,
|
|
139
|
+
EvalStatus,
|
|
140
|
+
getEvaluationCriteriaOrDefault,
|
|
141
|
+
getRootAgent,
|
|
142
|
+
MISSING_EVAL_DEPENDENCIES_MESSAGE,
|
|
143
|
+
parseAndGetEvalsToRun,
|
|
144
|
+
RESPONSE_EVALUATION_SCORE_KEY,
|
|
145
|
+
RESPONSE_MATCH_SCORE_KEY,
|
|
146
|
+
runEvals,
|
|
147
|
+
TOOL_TRAJECTORY_SCORE_KEY,
|
|
148
|
+
tryGetResetFunc
|
|
149
|
+
} from "./cli/cli_eval.js";
|
|
150
|
+
import { loadDotenvForAgent, walkToRootUntilFound } from "./cli/utils/envs.js";
|
|
151
|
+
import {
|
|
152
|
+
LOGGING_FORMAT,
|
|
153
|
+
logToTmpFolder,
|
|
154
|
+
setupAdkLogger
|
|
155
|
+
} from "./cli/utils/logs.js";
|
|
89
156
|
export * from "./tools/mcp/index.js";
|
|
90
157
|
export {
|
|
158
|
+
APIHubClient,
|
|
159
|
+
APIHubToolset,
|
|
91
160
|
AgentEngineSandboxCodeExecutor,
|
|
161
|
+
ApplicationIntegrationToolset,
|
|
92
162
|
AuthCredentialMissingError,
|
|
93
163
|
AutoAuthCredentialExchanger,
|
|
94
164
|
BaseAuthCredentialExchanger,
|
|
165
|
+
CONNECTOR_BASE_SPEC,
|
|
95
166
|
CodeExecutionLanguage,
|
|
167
|
+
ConnectionsClient,
|
|
96
168
|
ContainerCodeExecutor,
|
|
169
|
+
DEFAULT_CRITERIA,
|
|
97
170
|
DatabaseSessionService,
|
|
171
|
+
DebugLoggingPlugin,
|
|
172
|
+
EVAL_SESSION_ID_PREFIX,
|
|
173
|
+
EvalStatus,
|
|
98
174
|
FileArtifactService,
|
|
99
175
|
FilesRetrieval,
|
|
100
176
|
GCPSkillRegistry,
|
|
101
177
|
GcsArtifactService,
|
|
102
178
|
INTERNAL_AUTH_PREFIX,
|
|
179
|
+
IntegrationClient,
|
|
180
|
+
IntegrationConnectorTool,
|
|
103
181
|
InvocationContext,
|
|
104
182
|
LOAD_WEB_PAGE,
|
|
183
|
+
LOGGING_FORMAT,
|
|
105
184
|
LoadSkillResourceTool,
|
|
106
185
|
LocalEnvironment,
|
|
186
|
+
MISSING_EVAL_DEPENDENCIES_MESSAGE,
|
|
107
187
|
OAuth2BearerExchanger,
|
|
108
188
|
OpenAPIToolset,
|
|
109
189
|
OpenApiSpecParser,
|
|
110
190
|
OperationParser,
|
|
191
|
+
RESPONSE_EVALUATION_SCORE_KEY,
|
|
192
|
+
RESPONSE_MATCH_SCORE_KEY,
|
|
111
193
|
RestApiTool,
|
|
112
194
|
RunSkillInlineScriptErrorCode,
|
|
113
195
|
RunSkillInlineScriptTool,
|
|
114
196
|
RunSkillScriptTool,
|
|
197
|
+
SecretManagerClient,
|
|
115
198
|
ServiceAccountCredentialExchanger,
|
|
116
199
|
SkillToolset,
|
|
200
|
+
StaleSessionError,
|
|
201
|
+
TOOL_TRAJECTORY_SCORE_KEY,
|
|
117
202
|
ToolAuthHandler,
|
|
118
203
|
ToolContextCredentialStore,
|
|
119
204
|
UnsafeLocalCodeExecutor,
|
|
120
205
|
VertexAiMemoryBankService,
|
|
121
206
|
VertexAiRagMemoryService,
|
|
122
207
|
VertexAiSessionService,
|
|
208
|
+
actionRequest,
|
|
209
|
+
actionResponse,
|
|
210
|
+
connectorPayload,
|
|
123
211
|
createApiParameter,
|
|
212
|
+
createOperation,
|
|
213
|
+
createOperationRequest,
|
|
124
214
|
createRestApiTool,
|
|
125
215
|
createRestApiToolFromJson,
|
|
126
216
|
credentialToParam,
|
|
217
|
+
deleteOperation,
|
|
218
|
+
deleteOperationRequest,
|
|
127
219
|
dictToAuthScheme,
|
|
128
220
|
exchangeCredential,
|
|
221
|
+
executeCustomQueryRequest,
|
|
222
|
+
generateAuthToken,
|
|
129
223
|
generateParamDoc,
|
|
130
224
|
generateReturnDoc,
|
|
225
|
+
getActionOperation,
|
|
131
226
|
getArtifactServiceFromUri,
|
|
227
|
+
getEvaluationCriteriaOrDefault,
|
|
228
|
+
getOperation,
|
|
229
|
+
getOperationRequest,
|
|
230
|
+
getRootAgent,
|
|
132
231
|
getSessionServiceFromUri,
|
|
133
232
|
getTypeHint,
|
|
233
|
+
isDebugLoggingPlugin,
|
|
234
|
+
isStaleSessionError,
|
|
235
|
+
listOperation,
|
|
236
|
+
listOperationRequest,
|
|
134
237
|
loadAllSkillsInDir,
|
|
238
|
+
loadDotenvForAgent,
|
|
135
239
|
loadSkillFromDir,
|
|
136
240
|
loadSkillFromZipBuffer,
|
|
137
241
|
loadWebPage,
|
|
242
|
+
logToTmpFolder,
|
|
138
243
|
openidDictToSchemeCredential,
|
|
139
244
|
openidUrlToSchemeCredential,
|
|
245
|
+
parseAndGetEvalsToRun,
|
|
246
|
+
runEvals,
|
|
140
247
|
serviceAccountDictToSchemeCredential,
|
|
141
248
|
serviceAccountSchemeCredential,
|
|
249
|
+
setupAdkLogger,
|
|
142
250
|
tokenToSchemeCredential,
|
|
143
|
-
|
|
251
|
+
tryGetResetFunc,
|
|
252
|
+
updateOperation,
|
|
253
|
+
updateOperationRequest,
|
|
254
|
+
validateSkillDir,
|
|
255
|
+
walkToRootUntilFound
|
|
144
256
|
};
|
|
@@ -10,7 +10,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
10
10
|
function isGoogleApi(url) {
|
|
11
11
|
try {
|
|
12
12
|
const parsed = new URL(url);
|
|
13
|
-
return parsed.hostname === "googleapis.com" || parsed.hostname.endsWith(".googleapis.com");
|
|
13
|
+
return parsed.protocol === "https:" && (parsed.hostname === "googleapis.com" || parsed.hostname.endsWith(".googleapis.com"));
|
|
14
14
|
} catch {
|
|
15
15
|
return false;
|
|
16
16
|
}
|
|
@@ -114,26 +114,34 @@ const _GeminiLlmConnection = class _GeminiLlmConnection {
|
|
|
114
114
|
this.geminiSession.sendRealtimeInput({ activityEnd: {} });
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
117
|
-
*
|
|
117
|
+
* Receives the model responses for one model turn.
|
|
118
118
|
*
|
|
119
|
-
* The
|
|
120
|
-
*
|
|
119
|
+
* The generator ends after the message that completes the turn has been
|
|
120
|
+
* processed, or when the server closes the connection. Call `receive()`
|
|
121
|
+
* again to read the next turn; it continues from the next server message.
|
|
121
122
|
*
|
|
122
|
-
* @
|
|
123
|
-
* @param isThought Whether the text is a thought.
|
|
124
|
-
* @param groundingMetadata The grounding metadata to include.
|
|
125
|
-
* @returns An LlmResponse containing the full text.
|
|
123
|
+
* @returns A generator of the LlmResponses of one model turn.
|
|
126
124
|
*/
|
|
127
125
|
async *receive() {
|
|
126
|
+
var _a, _b;
|
|
128
127
|
if (!this.messageQueue) {
|
|
129
128
|
throw new Error("Message queue is not initialized.");
|
|
130
129
|
}
|
|
130
|
+
(_a = this.messageIterator) != null ? _a : this.messageIterator = this.messageQueue[Symbol.asyncIterator]();
|
|
131
131
|
const aggregator = new LiveResponseAggregator(this.modelVersion);
|
|
132
|
-
|
|
132
|
+
while (true) {
|
|
133
|
+
const next = await this.messageIterator.next();
|
|
134
|
+
if (next.done) {
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
const message = next.value;
|
|
133
138
|
logger.debug("Got LLM Live message:", message);
|
|
134
139
|
for (const response of aggregator.processMessage(message)) {
|
|
135
140
|
yield response;
|
|
136
141
|
}
|
|
142
|
+
if ((_b = message.serverContent) == null ? void 0 : _b.turnComplete) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
137
145
|
}
|
|
138
146
|
for (const response of aggregator.close()) {
|
|
139
147
|
yield response;
|
|
@@ -16,7 +16,7 @@ import { isBrowser, isEnterpriseModeEnabled } from "../utils/env_aware_utils.js"
|
|
|
16
16
|
import { logger } from "../utils/logger.js";
|
|
17
17
|
import { GoogleLLMVariant } from "../utils/variant_utils.js";
|
|
18
18
|
import { AsyncQueue } from "../utils/async_queue.js";
|
|
19
|
-
import {
|
|
19
|
+
import { GeminiStreamingResponseAggregator } from "../utils/streaming_utils.js";
|
|
20
20
|
import { BaseLlm } from "./base_llm.js";
|
|
21
21
|
import { GeminiLlmConnection } from "./gemini_llm_connection.js";
|
|
22
22
|
import { generateContentViaInteractions } from "./interactions_utils.js";
|
|
@@ -76,7 +76,7 @@ const _Gemini = class _Gemini extends (_b = BaseLlm, _a = GEMINI_MODEL_SYMBOL, _
|
|
|
76
76
|
* metadata and no `content`; only a stream with neither ends silently.
|
|
77
77
|
*/
|
|
78
78
|
async *generateContentAsync(llmRequest, stream = false, abortSignal) {
|
|
79
|
-
var _a2, _b2
|
|
79
|
+
var _a2, _b2;
|
|
80
80
|
if (this.useInteractionsApi) {
|
|
81
81
|
yield* generateContentViaInteractions(this.apiClient, llmRequest, stream);
|
|
82
82
|
return;
|
|
@@ -98,28 +98,23 @@ const _Gemini = class _Gemini extends (_b = BaseLlm, _a = GEMINI_MODEL_SYMBOL, _
|
|
|
98
98
|
if (abortSignal) {
|
|
99
99
|
llmRequest.config.abortSignal = abortSignal;
|
|
100
100
|
}
|
|
101
|
+
const params = {
|
|
102
|
+
model: (_b2 = llmRequest.model) != null ? _b2 : this.model,
|
|
103
|
+
contents: llmRequest.contents,
|
|
104
|
+
config: llmRequest.config
|
|
105
|
+
};
|
|
101
106
|
if (stream) {
|
|
102
|
-
const streamResult = await this.apiClient.models.generateContentStream(
|
|
103
|
-
|
|
104
|
-
contents: llmRequest.contents,
|
|
105
|
-
config: llmRequest.config
|
|
106
|
-
});
|
|
107
|
-
const aggregator = new StreamingResponseAggregator();
|
|
107
|
+
const streamResult = await this.apiClient.models.generateContentStream(params);
|
|
108
|
+
const aggregator = new GeminiStreamingResponseAggregator();
|
|
108
109
|
for await (const response of streamResult) {
|
|
109
|
-
|
|
110
|
-
yield llmResponse;
|
|
111
|
-
}
|
|
110
|
+
yield* aggregator.processResponse(response);
|
|
112
111
|
}
|
|
113
112
|
const finalResponse = aggregator.close();
|
|
114
113
|
if (finalResponse) {
|
|
115
114
|
yield finalResponse;
|
|
116
115
|
}
|
|
117
116
|
} else {
|
|
118
|
-
const response = await this.apiClient.models.generateContent(
|
|
119
|
-
model: (_c = llmRequest.model) != null ? _c : this.model,
|
|
120
|
-
contents: llmRequest.contents,
|
|
121
|
-
config: llmRequest.config
|
|
122
|
-
});
|
|
117
|
+
const response = await this.apiClient.models.generateContent(params);
|
|
123
118
|
yield createLlmResponse(response);
|
|
124
119
|
}
|
|
125
120
|
}
|
|
@@ -139,6 +134,7 @@ const _Gemini = class _Gemini extends (_b = BaseLlm, _a = GEMINI_MODEL_SYMBOL, _
|
|
|
139
134
|
});
|
|
140
135
|
} else {
|
|
141
136
|
this._apiClient = new GoogleGenAI({
|
|
137
|
+
vertexai: false,
|
|
142
138
|
apiKey: this.apiKey,
|
|
143
139
|
httpOptions: this.getHttpOptions()
|
|
144
140
|
});
|
|
@@ -174,6 +170,7 @@ const _Gemini = class _Gemini extends (_b = BaseLlm, _a = GEMINI_MODEL_SYMBOL, _
|
|
|
174
170
|
});
|
|
175
171
|
} else {
|
|
176
172
|
this._liveApiClient = new GoogleGenAI({
|
|
173
|
+
vertexai: false,
|
|
177
174
|
apiKey: this.apiKey,
|
|
178
175
|
httpOptions: this.getLiveHttpOptions()
|
|
179
176
|
});
|
|
@@ -280,7 +277,7 @@ function geminiInitParams({
|
|
|
280
277
|
}) {
|
|
281
278
|
const params = { model, vertexai, project, location, apiKey };
|
|
282
279
|
params.vertexai = !!vertexai;
|
|
283
|
-
if (
|
|
280
|
+
if (vertexai === void 0 && !isBrowser()) {
|
|
284
281
|
params.vertexai = isEnterpriseModeEnabled();
|
|
285
282
|
}
|
|
286
283
|
if (params.vertexai) {
|
|
@@ -7,9 +7,17 @@ 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
|
+
function withOwnInitialPromptTokenCount(usage) {
|
|
11
|
+
const initialPromptTokenCount = usage == null ? void 0 : usage.initialPromptTokenCount;
|
|
12
|
+
if (!usage || initialPromptTokenCount === void 0 || initialPromptTokenCount === usage.promptTokenCount || Object.prototype.propertyIsEnumerable.call(usage, "initialPromptTokenCount")) {
|
|
13
|
+
return usage;
|
|
14
|
+
}
|
|
15
|
+
return { ...usage, initialPromptTokenCount };
|
|
16
|
+
}
|
|
17
|
+
__name(withOwnInitialPromptTokenCount, "withOwnInitialPromptTokenCount");
|
|
10
18
|
function createLlmResponse(response) {
|
|
11
19
|
var _a;
|
|
12
|
-
const usageMetadata = response.usageMetadata;
|
|
20
|
+
const usageMetadata = withOwnInitialPromptTokenCount(response.usageMetadata);
|
|
13
21
|
if (response.candidates && response.candidates.length > 0) {
|
|
14
22
|
const candidate = response.candidates[0];
|
|
15
23
|
if (((_a = candidate.content) == null ? void 0 : _a.parts) && candidate.content.parts.length > 0) {
|
|
@@ -75,7 +75,7 @@ const _LLMRegistry = class _LLMRegistry {
|
|
|
75
75
|
}
|
|
76
76
|
for (const [regex, llmClass] of _LLMRegistry.llmRegistryDict.entries()) {
|
|
77
77
|
const pattern = new RegExp(
|
|
78
|
-
|
|
78
|
+
`^(?:${regex instanceof RegExp ? regex.source : regex})$`,
|
|
79
79
|
regex instanceof RegExp ? regex.flags : void 0
|
|
80
80
|
);
|
|
81
81
|
if (pattern.test(model)) {
|
|
@@ -28,14 +28,12 @@ const _RoutedLlm = class _RoutedLlm extends BaseLlm {
|
|
|
28
28
|
/**
|
|
29
29
|
* Generates content by delegating to the selected model.
|
|
30
30
|
*/
|
|
31
|
-
async *generateContentAsync(llmRequest, stream) {
|
|
31
|
+
async *generateContentAsync(llmRequest, stream, abortSignal) {
|
|
32
32
|
logger.info(`Routing request via ${this.model}`);
|
|
33
|
-
yield* runWithRouting(
|
|
34
|
-
|
|
35
|
-
llmRequest,
|
|
36
|
-
|
|
37
|
-
(model) => model.generateContentAsync(llmRequest, stream)
|
|
38
|
-
);
|
|
33
|
+
yield* runWithRouting(this.models, llmRequest, this.router, (model) => {
|
|
34
|
+
llmRequest.model = model.model;
|
|
35
|
+
return model.generateContentAsync(llmRequest, stream, abortSignal);
|
|
36
|
+
});
|
|
39
37
|
}
|
|
40
38
|
/**
|
|
41
39
|
* Creates a live connection to the LLM by delegating to the selected model.
|
|
@@ -47,7 +45,10 @@ const _RoutedLlm = class _RoutedLlm extends BaseLlm {
|
|
|
47
45
|
this.models,
|
|
48
46
|
llmRequest,
|
|
49
47
|
this.router,
|
|
50
|
-
(model) =>
|
|
48
|
+
(model) => {
|
|
49
|
+
llmRequest.model = model.model;
|
|
50
|
+
return model.connect(llmRequest);
|
|
51
|
+
}
|
|
51
52
|
);
|
|
52
53
|
const result = await generator.next();
|
|
53
54
|
if (result.done || result.value === void 0) {
|
|
@@ -41,7 +41,7 @@ const _PlanReActPlanner = class _PlanReActPlanner extends BasePlanner {
|
|
|
41
41
|
}
|
|
42
42
|
handleNonFunctionCallPart(part, preservedParts);
|
|
43
43
|
}
|
|
44
|
-
if (firstFcPartIndex
|
|
44
|
+
if (firstFcPartIndex >= 0) {
|
|
45
45
|
for (let j = firstFcPartIndex + 1; j < responseParts.length; j++) {
|
|
46
46
|
if (!responseParts[j].functionCall) {
|
|
47
47
|
break;
|
|
@@ -246,29 +246,19 @@ const _BasePlugin = class _BasePlugin {
|
|
|
246
246
|
return;
|
|
247
247
|
}
|
|
248
248
|
/**
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
* potentially providing alternative responses or recovery mechanisms.
|
|
263
|
-
*
|
|
264
|
-
* @param _params.tool The tool instance that encountered an error.
|
|
265
|
-
* @param _params.toolArgs The arguments that were passed to the tool.
|
|
266
|
-
* @param _params.toolContext The context specific to the tool execution.
|
|
267
|
-
* @param _params.error The exception that was raised during tool execution.
|
|
268
|
-
* @returns An optional dictionary. If a dictionary is returned, it will be
|
|
269
|
-
* used as the tool response instead of propagating the error. Returning
|
|
270
|
-
* `undefined` allows the original error to be raised.
|
|
271
|
-
*/
|
|
249
|
+
* Callback executed when a tool call encounters an error.
|
|
250
|
+
*
|
|
251
|
+
* This callback provides an opportunity to handle tool errors gracefully,
|
|
252
|
+
* potentially providing alternative responses or recovery mechanisms.
|
|
253
|
+
*
|
|
254
|
+
* @param _params.tool The tool instance that encountered an error.
|
|
255
|
+
* @param _params.toolArgs The arguments that were passed to the tool.
|
|
256
|
+
* @param _params.toolContext The context specific to the tool execution.
|
|
257
|
+
* @param _params.error The exception that was raised during tool execution.
|
|
258
|
+
* @returns An optional dictionary. If a dictionary is returned, it will be
|
|
259
|
+
* used as the tool response instead of propagating the error. Returning
|
|
260
|
+
* `undefined` allows the original error to be raised.
|
|
261
|
+
*/
|
|
272
262
|
async onToolErrorCallback(_params) {
|
|
273
263
|
return;
|
|
274
264
|
}
|
|
@@ -18,28 +18,23 @@ const _InMemoryRunner = class _InMemoryRunner extends Runner {
|
|
|
18
18
|
* @param params The configuration for the runner.
|
|
19
19
|
* @param params.app An optional application instance to run.
|
|
20
20
|
* @param params.agent The root agent to run.
|
|
21
|
-
* @param params.appName The application name. Defaults to `
|
|
21
|
+
* @param params.appName The application name. Defaults to `app.name` when
|
|
22
|
+
* `app` is provided, or `'InMemoryRunner'` otherwise.
|
|
22
23
|
* @param params.plugins An optional list of plugins.
|
|
23
24
|
* @param params.resumabilityConfig An optional resumability configuration.
|
|
24
25
|
*/
|
|
25
26
|
constructor(params) {
|
|
26
|
-
var _a;
|
|
27
|
-
const {
|
|
28
|
-
agent,
|
|
29
|
-
appName = "InMemoryRunner",
|
|
30
|
-
plugins = [],
|
|
31
|
-
app,
|
|
32
|
-
resumabilityConfig
|
|
33
|
-
} = params;
|
|
27
|
+
var _a, _b;
|
|
28
|
+
const { agent, appName, plugins = [], app, resumabilityConfig } = params;
|
|
34
29
|
super({
|
|
35
30
|
app,
|
|
36
|
-
appName,
|
|
31
|
+
appName: (_a = appName != null ? appName : app == null ? void 0 : app.name) != null ? _a : "InMemoryRunner",
|
|
37
32
|
agent,
|
|
38
33
|
plugins,
|
|
39
34
|
artifactService: new InMemoryArtifactService(),
|
|
40
35
|
sessionService: new InMemorySessionService(),
|
|
41
36
|
memoryService: new InMemoryMemoryService(),
|
|
42
|
-
resumabilityConfig: (
|
|
37
|
+
resumabilityConfig: (_b = app == null ? void 0 : app.resumabilityConfig) != null ? _b : resumabilityConfig
|
|
43
38
|
});
|
|
44
39
|
}
|
|
45
40
|
};
|