@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
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
BuiltInCodeExecutor,
|
|
32
32
|
isBuiltInCodeExecutor
|
|
33
33
|
} from "../code_executors/built_in_code_executor.js";
|
|
34
|
+
import { buildAbortEvents, isAbortEvent } from "../events/abort_events.js";
|
|
34
35
|
import { createEvent } from "../events/event.js";
|
|
35
36
|
import { createEventActions } from "../events/event_actions.js";
|
|
36
37
|
import {
|
|
@@ -64,8 +65,8 @@ const _Runner = class _Runner {
|
|
|
64
65
|
*/
|
|
65
66
|
constructor(input) {
|
|
66
67
|
this[_a] = true;
|
|
67
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
68
|
-
const appName = (_b = (_a2 = input.app) == null ? void 0 : _a2.name
|
|
68
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
69
|
+
const appName = (_b = input.appName) != null ? _b : (_a2 = input.app) == null ? void 0 : _a2.name;
|
|
69
70
|
const agent = (_d = (_c = input.app) == null ? void 0 : _c.rootAgent) != null ? _d : input.agent;
|
|
70
71
|
if (!agent) {
|
|
71
72
|
throw new Error(
|
|
@@ -82,6 +83,20 @@ const _Runner = class _Runner {
|
|
|
82
83
|
this.memoryService = input.memoryService;
|
|
83
84
|
this.credentialService = input.credentialService;
|
|
84
85
|
this.resumabilityConfig = (_i = (_h = input.app) == null ? void 0 : _h.resumabilityConfig) != null ? _i : input.resumabilityConfig;
|
|
86
|
+
this.autoCreateSession = (_j = input.autoCreateSession) != null ? _j : false;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Looks the session up, creating it first when `autoCreateSession` is set.
|
|
90
|
+
*
|
|
91
|
+
* A runner with no `appName` cannot address a session, so it falls through to
|
|
92
|
+
* the plain lookup rather than creating one under an undefined app name.
|
|
93
|
+
*/
|
|
94
|
+
async resolveSession(userId, sessionId) {
|
|
95
|
+
const key = { appName: this.appName, userId, sessionId };
|
|
96
|
+
if (this.autoCreateSession && this.appName) {
|
|
97
|
+
return this.sessionService.getOrCreateSession(key);
|
|
98
|
+
}
|
|
99
|
+
return this.sessionService.getSession(key);
|
|
85
100
|
}
|
|
86
101
|
/**
|
|
87
102
|
* Runs the agent with a new, ephemeral session.
|
|
@@ -142,12 +157,8 @@ const _Runner = class _Runner {
|
|
|
142
157
|
ctx,
|
|
143
158
|
this,
|
|
144
159
|
async function* () {
|
|
145
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
146
|
-
const session = await this.
|
|
147
|
-
appName: this.appName,
|
|
148
|
-
userId,
|
|
149
|
-
sessionId
|
|
150
|
-
});
|
|
160
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
161
|
+
const session = await this.resolveSession(userId, sessionId);
|
|
151
162
|
if ((_a2 = params.abortSignal) == null ? void 0 : _a2.aborted) {
|
|
152
163
|
return;
|
|
153
164
|
}
|
|
@@ -258,35 +269,45 @@ const _Runner = class _Runner {
|
|
|
258
269
|
}
|
|
259
270
|
yield earlyExitEvent;
|
|
260
271
|
} else {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
session,
|
|
280
|
-
event: outputEvent
|
|
281
|
-
});
|
|
272
|
+
let abortSealed = false;
|
|
273
|
+
const sealAbortedInvocation = /* @__PURE__ */ __name(() => {
|
|
274
|
+
abortSealed = true;
|
|
275
|
+
return this.synthesizeAbortEvents(invocationContext);
|
|
276
|
+
}, "sealAbortedInvocation");
|
|
277
|
+
try {
|
|
278
|
+
for await (const event of this.runRoot(invocationContext)) {
|
|
279
|
+
if ((_h = params.abortSignal) == null ? void 0 : _h.aborted) {
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
const outputEvent = await this.processAndAppendEvent(
|
|
283
|
+
invocationContext,
|
|
284
|
+
event
|
|
285
|
+
);
|
|
286
|
+
if ((_i = params.abortSignal) == null ? void 0 : _i.aborted) {
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
yield outputEvent;
|
|
282
290
|
}
|
|
283
291
|
if ((_j = params.abortSignal) == null ? void 0 : _j.aborted) {
|
|
292
|
+
for (const abortEvent of await sealAbortedInvocation()) {
|
|
293
|
+
yield abortEvent;
|
|
294
|
+
}
|
|
284
295
|
return;
|
|
285
296
|
}
|
|
286
|
-
|
|
297
|
+
} finally {
|
|
298
|
+
if (((_k = params.abortSignal) == null ? void 0 : _k.aborted) && !abortSealed) {
|
|
299
|
+
try {
|
|
300
|
+
await sealAbortedInvocation();
|
|
301
|
+
} catch (e) {
|
|
302
|
+
logger.error(
|
|
303
|
+
`Failed to seal aborted invocation ${invocationContext.invocationId}.`,
|
|
304
|
+
e
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
287
308
|
}
|
|
288
309
|
await this.pluginManager.runAfterRunCallback({ invocationContext });
|
|
289
|
-
if ((
|
|
310
|
+
if ((_l = params.abortSignal) == null ? void 0 : _l.aborted) {
|
|
290
311
|
return;
|
|
291
312
|
}
|
|
292
313
|
}
|
|
@@ -318,6 +339,56 @@ const _Runner = class _Runner {
|
|
|
318
339
|
}
|
|
319
340
|
yield* runNodeAsInvocation(this.agent, invocationContext);
|
|
320
341
|
}
|
|
342
|
+
/**
|
|
343
|
+
* Runs the on_event plugin callbacks on an event and appends the result to
|
|
344
|
+
* the session unless it is partial.
|
|
345
|
+
*
|
|
346
|
+
* @returns The event as streamed to the caller.
|
|
347
|
+
*/
|
|
348
|
+
async processAndAppendEvent(invocationContext, event) {
|
|
349
|
+
var _a2;
|
|
350
|
+
const modifiedEvent = await this.pluginManager.runOnEventCallback({
|
|
351
|
+
invocationContext,
|
|
352
|
+
event
|
|
353
|
+
});
|
|
354
|
+
const outputEvent = modifiedEvent ? {
|
|
355
|
+
...withInternalMetadataOf(event, modifiedEvent),
|
|
356
|
+
id: event.id,
|
|
357
|
+
invocationId: event.invocationId,
|
|
358
|
+
timestamp: event.timestamp,
|
|
359
|
+
author: modifiedEvent.author || event.author,
|
|
360
|
+
branch: (_a2 = modifiedEvent.branch) != null ? _a2 : event.branch
|
|
361
|
+
} : event;
|
|
362
|
+
if (!event.partial) {
|
|
363
|
+
await this.sessionService.appendEvent({
|
|
364
|
+
session: invocationContext.session,
|
|
365
|
+
event: outputEvent
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
return outputEvent;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Seals an aborted invocation in session history: answers its dangling
|
|
372
|
+
* function calls with error responses, or records a plain abort event when
|
|
373
|
+
* there is nothing to answer.
|
|
374
|
+
*
|
|
375
|
+
* @returns The synthetic events after plugin processing and persistence.
|
|
376
|
+
*/
|
|
377
|
+
async synthesizeAbortEvents(invocationContext) {
|
|
378
|
+
const abortEvents = buildAbortEvents({
|
|
379
|
+
events: invocationContext.session.events,
|
|
380
|
+
invocationId: invocationContext.invocationId,
|
|
381
|
+
rootAgentName: this.agent.name,
|
|
382
|
+
branch: invocationContext.branch
|
|
383
|
+
});
|
|
384
|
+
const outputEvents = [];
|
|
385
|
+
for (const event of abortEvents) {
|
|
386
|
+
outputEvents.push(
|
|
387
|
+
await this.processAndAppendEvent(invocationContext, event)
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
return outputEvents;
|
|
391
|
+
}
|
|
321
392
|
/**
|
|
322
393
|
* Saves artifacts from the message parts and replaces the inline data with
|
|
323
394
|
* a file name placeholder and optional file reference.
|
|
@@ -564,7 +635,8 @@ function isLiveModelMediaEventWithInlineData(event) {
|
|
|
564
635
|
}
|
|
565
636
|
__name(isLiveModelMediaEventWithInlineData, "isLiveModelMediaEventWithInlineData");
|
|
566
637
|
function determineAgentForResumption(session, rootAgent, resumabilityConfig) {
|
|
567
|
-
const
|
|
638
|
+
const lastEvent = session.events[session.events.length - 1];
|
|
639
|
+
const event = lastEvent && !isAbortEvent(lastEvent) ? findEventByLastFunctionResponseId(session.events) : null;
|
|
568
640
|
const isResumable = Boolean(resumabilityConfig == null ? void 0 : resumabilityConfig.isResumable);
|
|
569
641
|
if (event && event.author && isResumable) {
|
|
570
642
|
const conflictingAuthors = getConflictingFunctionResponseAuthors(
|
|
@@ -588,7 +660,7 @@ function determineAgentForResumption(session, rootAgent, resumabilityConfig) {
|
|
|
588
660
|
for (let i = session.events.length - 1; i >= 0; i--) {
|
|
589
661
|
logger.debug("event:", stringifyWithRedactedInlineData(session.events[i]));
|
|
590
662
|
const event2 = session.events[i];
|
|
591
|
-
if (event2.author === "user" || !event2.author) {
|
|
663
|
+
if (event2.author === "user" || !event2.author || isAbortEvent(event2)) {
|
|
592
664
|
continue;
|
|
593
665
|
}
|
|
594
666
|
if (event2.author === rootAgent.name) {
|
|
@@ -43,12 +43,7 @@ const _BaseSessionService = class _BaseSessionService {
|
|
|
43
43
|
}
|
|
44
44
|
event = trimTempDeltaState(event);
|
|
45
45
|
this.updateSessionState({ session, event });
|
|
46
|
-
|
|
47
|
-
if (index >= 0) {
|
|
48
|
-
session.events[index] = event;
|
|
49
|
-
} else {
|
|
50
|
-
session.events.push(event);
|
|
51
|
-
}
|
|
46
|
+
upsertSessionEvent(session, event);
|
|
52
47
|
return event;
|
|
53
48
|
}
|
|
54
49
|
/**
|
|
@@ -78,6 +73,15 @@ const _BaseSessionService = class _BaseSessionService {
|
|
|
78
73
|
};
|
|
79
74
|
__name(_BaseSessionService, "BaseSessionService");
|
|
80
75
|
let BaseSessionService = _BaseSessionService;
|
|
76
|
+
function upsertSessionEvent(session, event) {
|
|
77
|
+
const index = session.events.findIndex((e) => e.id === event.id);
|
|
78
|
+
if (index >= 0) {
|
|
79
|
+
session.events[index] = event;
|
|
80
|
+
} else {
|
|
81
|
+
session.events.push(event);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
__name(upsertSessionEvent, "upsertSessionEvent");
|
|
81
85
|
function trimTempDeltaState(event) {
|
|
82
86
|
if (!event.actions || !event.actions.stateDelta) {
|
|
83
87
|
return event;
|
|
@@ -119,5 +123,6 @@ export {
|
|
|
119
123
|
BaseSessionService,
|
|
120
124
|
mergeStates,
|
|
121
125
|
trimTempDeltaState,
|
|
122
|
-
trimTempState
|
|
126
|
+
trimTempState,
|
|
127
|
+
upsertSessionEvent
|
|
123
128
|
};
|
|
@@ -29,12 +29,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
29
|
* SPDX-License-Identifier: Apache-2.0
|
|
30
30
|
*/
|
|
31
31
|
import { randomUUID } from "../utils/env_aware_utils.js";
|
|
32
|
+
import { logger } from "../utils/logger.js";
|
|
32
33
|
import {
|
|
33
34
|
BaseSessionService,
|
|
34
35
|
mergeStates,
|
|
35
|
-
trimTempDeltaState
|
|
36
|
+
trimTempDeltaState,
|
|
37
|
+
upsertSessionEvent
|
|
36
38
|
} from "./base_session_service.js";
|
|
37
39
|
import { createSession } from "./session.js";
|
|
40
|
+
import { StaleSessionError } from "./stale_session_error.js";
|
|
38
41
|
import { State } from "./state.js";
|
|
39
42
|
let MikroORM;
|
|
40
43
|
let LockMode;
|
|
@@ -67,6 +70,12 @@ async function importMikroOrm() {
|
|
|
67
70
|
} = operations);
|
|
68
71
|
}
|
|
69
72
|
__name(importMikroOrm, "importMikroOrm");
|
|
73
|
+
import { isStaleSessionError, StaleSessionError as StaleSessionError2 } from "./stale_session_error.js";
|
|
74
|
+
function formatDateTime(dateOrEpochMs) {
|
|
75
|
+
const date = typeof dateOrEpochMs === "number" ? new Date(dateOrEpochMs) : dateOrEpochMs;
|
|
76
|
+
return date.toISOString().replace("T", " ").slice(0, 19);
|
|
77
|
+
}
|
|
78
|
+
__name(formatDateTime, "formatDateTime");
|
|
70
79
|
function isDatabaseConnectionString(uri) {
|
|
71
80
|
if (!uri) {
|
|
72
81
|
return false;
|
|
@@ -75,16 +84,20 @@ function isDatabaseConnectionString(uri) {
|
|
|
75
84
|
}
|
|
76
85
|
__name(isDatabaseConnectionString, "isDatabaseConnectionString");
|
|
77
86
|
const _DatabaseSessionService = class _DatabaseSessionService extends BaseSessionService {
|
|
78
|
-
constructor(connectionStringOrOptions) {
|
|
87
|
+
constructor(connectionStringOrOptions, options) {
|
|
88
|
+
var _a;
|
|
79
89
|
super();
|
|
80
90
|
this.initialized = false;
|
|
81
91
|
if (typeof connectionStringOrOptions === "string") {
|
|
82
92
|
this.connectionString = connectionStringOrOptions;
|
|
93
|
+
this.staleSession = (_a = options == null ? void 0 : options.staleSession) != null ? _a : "reject";
|
|
83
94
|
} else {
|
|
84
95
|
if (!connectionStringOrOptions.driver) {
|
|
85
96
|
throw new Error("Driver is required when passing options object.");
|
|
86
97
|
}
|
|
87
|
-
|
|
98
|
+
const { staleSession, ...mikroOptions } = connectionStringOrOptions;
|
|
99
|
+
this.options = mikroOptions;
|
|
100
|
+
this.staleSession = staleSession != null ? staleSession : "reject";
|
|
88
101
|
}
|
|
89
102
|
}
|
|
90
103
|
async init() {
|
|
@@ -330,6 +343,7 @@ const _DatabaseSessionService = class _DatabaseSessionService extends BaseSessio
|
|
|
330
343
|
return event;
|
|
331
344
|
}
|
|
332
345
|
const trimmedEvent = trimTempDeltaState(event);
|
|
346
|
+
let sessionWasStale = false;
|
|
333
347
|
await em.transactional(async (txEm) => {
|
|
334
348
|
const storageSession = await txEm.findOne(
|
|
335
349
|
StorageSession,
|
|
@@ -343,6 +357,14 @@ const _DatabaseSessionService = class _DatabaseSessionService extends BaseSessio
|
|
|
343
357
|
if (!storageSession) {
|
|
344
358
|
throw new Error(`Session ${session.id} not found for appendEvent`);
|
|
345
359
|
}
|
|
360
|
+
if (storageSession.updateTime.getTime() > session.lastUpdateTime) {
|
|
361
|
+
if (this.staleSession === "reject") {
|
|
362
|
+
throw new StaleSessionError(
|
|
363
|
+
`The last_update_time provided in the session object ${formatDateTime(session.lastUpdateTime)} is earlier than the update_time in the storage_session ${formatDateTime(storageSession.updateTime)}. Please check if it is a stale session.`
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
sessionWasStale = true;
|
|
367
|
+
}
|
|
346
368
|
let appStateModel = await txEm.findOne(StorageAppState, {
|
|
347
369
|
appName: session.appName
|
|
348
370
|
});
|
|
@@ -366,24 +388,6 @@ const _DatabaseSessionService = class _DatabaseSessionService extends BaseSessio
|
|
|
366
388
|
});
|
|
367
389
|
txEm.persist(userStateModel);
|
|
368
390
|
}
|
|
369
|
-
if (storageSession.updateTime.getTime() > session.lastUpdateTime) {
|
|
370
|
-
const events = await txEm.find(
|
|
371
|
-
StorageEvent,
|
|
372
|
-
{
|
|
373
|
-
appName: session.appName,
|
|
374
|
-
userId: session.userId,
|
|
375
|
-
sessionId: session.id
|
|
376
|
-
},
|
|
377
|
-
{ orderBy: { timestamp: "ASC" } }
|
|
378
|
-
);
|
|
379
|
-
const mergedState = mergeStates(
|
|
380
|
-
appStateModel.state,
|
|
381
|
-
userStateModel.state,
|
|
382
|
-
storageSession.state
|
|
383
|
-
);
|
|
384
|
-
session.state = mergedState;
|
|
385
|
-
session.events = events.map((e) => e.eventData);
|
|
386
|
-
}
|
|
387
391
|
if (event.actions && event.actions.stateDelta) {
|
|
388
392
|
const appDelta = {};
|
|
389
393
|
const userDelta = {};
|
|
@@ -437,14 +441,29 @@ const _DatabaseSessionService = class _DatabaseSessionService extends BaseSessio
|
|
|
437
441
|
storageSession.state
|
|
438
442
|
);
|
|
439
443
|
session.state = newMergedState;
|
|
440
|
-
|
|
441
|
-
if (index >= 0) {
|
|
442
|
-
session.events[index] = event;
|
|
443
|
-
} else {
|
|
444
|
-
session.events.push(event);
|
|
445
|
-
}
|
|
444
|
+
upsertSessionEvent(session, event);
|
|
446
445
|
session.lastUpdateTime = storageSession.updateTime.getTime();
|
|
447
446
|
});
|
|
447
|
+
if (sessionWasStale) {
|
|
448
|
+
try {
|
|
449
|
+
const storageEvents = await em.find(
|
|
450
|
+
StorageEvent,
|
|
451
|
+
{
|
|
452
|
+
appName: session.appName,
|
|
453
|
+
userId: session.userId,
|
|
454
|
+
sessionId: session.id
|
|
455
|
+
},
|
|
456
|
+
{ orderBy: { timestamp: "ASC" } }
|
|
457
|
+
);
|
|
458
|
+
session.events = storageEvents.map((se) => se.eventData);
|
|
459
|
+
upsertSessionEvent(session, event);
|
|
460
|
+
} catch (e) {
|
|
461
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
462
|
+
logger.warn(
|
|
463
|
+
`Failed to reload events for stale session ${session.id} after appendEvent; the event was persisted but session.events may be missing concurrent appends: ${message}`
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
448
467
|
return event;
|
|
449
468
|
}
|
|
450
469
|
};
|
|
@@ -452,5 +471,7 @@ __name(_DatabaseSessionService, "DatabaseSessionService");
|
|
|
452
471
|
let DatabaseSessionService = _DatabaseSessionService;
|
|
453
472
|
export {
|
|
454
473
|
DatabaseSessionService,
|
|
455
|
-
|
|
474
|
+
StaleSessionError2 as StaleSessionError,
|
|
475
|
+
isDatabaseConnectionString,
|
|
476
|
+
isStaleSessionError
|
|
456
477
|
};
|
|
@@ -281,7 +281,7 @@ async function getConnectionOptionsFromUri(uri) {
|
|
|
281
281
|
);
|
|
282
282
|
return {
|
|
283
283
|
entities: ENTITIES,
|
|
284
|
-
dbName: uri === "sqlite://:memory:" ? ":memory:" : uri.substring("sqlite://".length),
|
|
284
|
+
dbName: uri === "sqlite://:memory:" || uri === "sqlite:///:memory:" ? ":memory:" : uri.substring("sqlite://".length),
|
|
285
285
|
driver: SqliteDriver
|
|
286
286
|
};
|
|
287
287
|
}
|
|
@@ -47,7 +47,9 @@ const _InMemorySessionService = class _InMemorySessionService extends BaseSessio
|
|
|
47
47
|
var _a;
|
|
48
48
|
const filteredState = state ? trimTempState(state) : void 0;
|
|
49
49
|
const session = createSession({
|
|
50
|
-
|
|
50
|
+
// Surrounding whitespace is dropped so that a later lookup by the bare
|
|
51
|
+
// id finds the session, and a blank id gets a generated one.
|
|
52
|
+
id: (sessionId == null ? void 0 : sessionId.trim()) || randomUUID(),
|
|
51
53
|
appName,
|
|
52
54
|
userId,
|
|
53
55
|
state: filteredState,
|
|
@@ -0,0 +1,31 @@
|
|
|
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 _a, _b;
|
|
11
|
+
const STALE_SESSION_ERROR_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for(
|
|
12
|
+
"google.adk.staleSessionError"
|
|
13
|
+
);
|
|
14
|
+
const _StaleSessionError = class _StaleSessionError extends (_b = Error, _a = STALE_SESSION_ERROR_SIGNATURE_SYMBOL, _b) {
|
|
15
|
+
constructor(message) {
|
|
16
|
+
super(message);
|
|
17
|
+
this[_a] = true;
|
|
18
|
+
this.name = "StaleSessionError";
|
|
19
|
+
Object.setPrototypeOf(this, _StaleSessionError.prototype);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
__name(_StaleSessionError, "StaleSessionError");
|
|
23
|
+
let StaleSessionError = _StaleSessionError;
|
|
24
|
+
function isStaleSessionError(obj) {
|
|
25
|
+
return typeof obj === "object" && obj !== null && (STALE_SESSION_ERROR_SIGNATURE_SYMBOL in obj || obj instanceof Error && obj.name === "StaleSessionError");
|
|
26
|
+
}
|
|
27
|
+
__name(isStaleSessionError, "isStaleSessionError");
|
|
28
|
+
export {
|
|
29
|
+
StaleSessionError,
|
|
30
|
+
isStaleSessionError
|
|
31
|
+
};
|
|
@@ -74,16 +74,19 @@ const _State = class _State {
|
|
|
74
74
|
/**
|
|
75
75
|
* Returns the value of the state dict for the given key.
|
|
76
76
|
*
|
|
77
|
+
* Only keys the state holds itself are found. Names inherited from
|
|
78
|
+
* `Object.prototype`, such as `toString`, are treated as missing.
|
|
79
|
+
*
|
|
77
80
|
* @param key The key to get the value for.
|
|
78
81
|
* @param defaultValue The default value to return if the key is not found.
|
|
79
82
|
* @return The value of the state for the given key, or the default value if
|
|
80
83
|
* not found.
|
|
81
84
|
*/
|
|
82
85
|
get(key, defaultValue) {
|
|
83
|
-
if (
|
|
86
|
+
if (Object.hasOwn(this.delta, key)) {
|
|
84
87
|
return this.delta[key];
|
|
85
88
|
}
|
|
86
|
-
if (
|
|
89
|
+
if (Object.hasOwn(this.value, key)) {
|
|
87
90
|
return this.value[key];
|
|
88
91
|
}
|
|
89
92
|
return defaultValue;
|
|
@@ -101,10 +104,11 @@ const _State = class _State {
|
|
|
101
104
|
recordStateWrite(this.value, this.delta, key);
|
|
102
105
|
}
|
|
103
106
|
/**
|
|
104
|
-
* Whether the state
|
|
107
|
+
* Whether the state holds the given key, either as a stored value or as a
|
|
108
|
+
* pending delta. Names inherited from `Object.prototype` are not keys.
|
|
105
109
|
*/
|
|
106
110
|
has(key) {
|
|
107
|
-
return
|
|
111
|
+
return Object.hasOwn(this.value, key) || Object.hasOwn(this.delta, key);
|
|
108
112
|
}
|
|
109
113
|
/**
|
|
110
114
|
* Whether the state has pending delta.
|
|
@@ -44,17 +44,22 @@ function quoteFilterLiteral(value) {
|
|
|
44
44
|
return `"${escaped}"`;
|
|
45
45
|
}
|
|
46
46
|
__name(quoteFilterLiteral, "quoteFilterLiteral");
|
|
47
|
+
function toStateMap(state) {
|
|
48
|
+
return Object.assign(/* @__PURE__ */ Object.create(null), state);
|
|
49
|
+
}
|
|
50
|
+
__name(toStateMap, "toStateMap");
|
|
47
51
|
let VertexAiSessionService = class extends BaseSessionService {
|
|
48
52
|
constructor(options) {
|
|
49
53
|
super();
|
|
50
54
|
this.agentEngineId = options.agentEngineId;
|
|
51
|
-
this.projectId = options.projectId;
|
|
52
|
-
this.location = options.location;
|
|
53
55
|
this.expressModeApiKey = getExpressModeApiKey(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
options.projectId,
|
|
57
|
+
options.location,
|
|
56
58
|
options.expressModeApiKey
|
|
57
59
|
);
|
|
60
|
+
const useEnvironment = !options.expressModeApiKey;
|
|
61
|
+
this.projectId = options.projectId || (useEnvironment ? process.env["GOOGLE_CLOUD_PROJECT"] : void 0);
|
|
62
|
+
this.location = options.location || (useEnvironment ? process.env["GOOGLE_CLOUD_LOCATION"] : void 0);
|
|
58
63
|
if (options.sessions) {
|
|
59
64
|
this.sessions = options.sessions;
|
|
60
65
|
} else {
|
|
@@ -140,7 +145,7 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
140
145
|
id,
|
|
141
146
|
appName,
|
|
142
147
|
userId,
|
|
143
|
-
state: getSessionResponse.sessionState,
|
|
148
|
+
state: toStateMap(getSessionResponse.sessionState),
|
|
144
149
|
events: [],
|
|
145
150
|
lastUpdateTime: getSessionResponse.updateTime ? Date.parse(getSessionResponse.updateTime) : Date.now()
|
|
146
151
|
});
|
|
@@ -155,13 +160,14 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
155
160
|
const sessionResourceName = `reasoningEngines/${reasoningEngineId}/sessions/${sessionId}`;
|
|
156
161
|
try {
|
|
157
162
|
let getSessionResponse;
|
|
158
|
-
|
|
163
|
+
const eventsIterator = [];
|
|
164
|
+
const listConfig = {};
|
|
165
|
+
let pageToken;
|
|
159
166
|
if (config && config.numRecentEvents === 0) {
|
|
160
167
|
getSessionResponse = await this.sessions.get({
|
|
161
168
|
name: sessionResourceName
|
|
162
169
|
});
|
|
163
170
|
} else {
|
|
164
|
-
const listConfig = {};
|
|
165
171
|
if (config && config.afterTimestamp) {
|
|
166
172
|
listConfig.filter = `timestamp>="${new Date(
|
|
167
173
|
config.afterTimestamp
|
|
@@ -175,7 +181,9 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
175
181
|
})
|
|
176
182
|
]);
|
|
177
183
|
getSessionResponse = sessionRes;
|
|
178
|
-
|
|
184
|
+
const firstPage = eventsRes;
|
|
185
|
+
eventsIterator.push(...firstPage.sessionEvents || []);
|
|
186
|
+
pageToken = firstPage.nextPageToken;
|
|
179
187
|
}
|
|
180
188
|
const sessionObj = getSessionResponse;
|
|
181
189
|
if (sessionObj.userId !== userId) {
|
|
@@ -183,20 +191,29 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
183
191
|
`Session ${sessionId} does not belong to user ${userId}.`
|
|
184
192
|
);
|
|
185
193
|
}
|
|
194
|
+
while (pageToken) {
|
|
195
|
+
const eventsRes = await this.sessions.events.listInternal({
|
|
196
|
+
name: sessionResourceName,
|
|
197
|
+
config: {
|
|
198
|
+
...listConfig,
|
|
199
|
+
pageToken
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
eventsIterator.push(...eventsRes.sessionEvents || []);
|
|
203
|
+
pageToken = eventsRes.nextPageToken;
|
|
204
|
+
}
|
|
186
205
|
const session = createSession({
|
|
187
206
|
id: sessionId,
|
|
188
207
|
appName,
|
|
189
208
|
userId,
|
|
190
|
-
state: sessionObj.sessionState,
|
|
209
|
+
state: toStateMap(sessionObj.sessionState),
|
|
191
210
|
events: [],
|
|
192
211
|
lastUpdateTime: sessionObj.updateTime ? Date.parse(sessionObj.updateTime) : Date.now()
|
|
193
212
|
});
|
|
194
|
-
|
|
213
|
+
const recentEvents = config && config.numRecentEvents ? eventsIterator.slice(-config.numRecentEvents) : eventsIterator;
|
|
214
|
+
for (const event of recentEvents) {
|
|
195
215
|
session.events.push(_fromApiEvent(event));
|
|
196
216
|
}
|
|
197
|
-
if (config && config.numRecentEvents) {
|
|
198
|
-
session.events = session.events.slice(-config.numRecentEvents);
|
|
199
|
-
}
|
|
200
217
|
return session;
|
|
201
218
|
} catch (error) {
|
|
202
219
|
const err = error;
|
|
@@ -235,7 +252,7 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
235
252
|
id,
|
|
236
253
|
appName,
|
|
237
254
|
userId: sessionObj.userId,
|
|
238
|
-
state: sessionObj.sessionState,
|
|
255
|
+
state: toStateMap(sessionObj.sessionState),
|
|
239
256
|
events: [],
|
|
240
257
|
lastUpdateTime: sessionObj.updateTime ? new Date(sessionObj.updateTime).getTime() : Date.now()
|
|
241
258
|
})
|
|
@@ -481,7 +498,9 @@ function _fromApiEvent(apiEventObj) {
|
|
|
481
498
|
}
|
|
482
499
|
}
|
|
483
500
|
const eventActions = {
|
|
484
|
-
stateDelta:
|
|
501
|
+
stateDelta: toStateMap(
|
|
502
|
+
actions["stateDelta"]
|
|
503
|
+
),
|
|
485
504
|
artifactDelta: actions["artifactDelta"] || {},
|
|
486
505
|
requestedAuthConfigs: actions.requestedAuthConfigs || {},
|
|
487
506
|
requestedToolConfirmations: actions["requestedToolConfirmations"] || {},
|