@google/adk 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/agents/base_agent.js +19 -1
- package/dist/cjs/agents/functions.js +4 -0
- package/dist/cjs/agents/instructions.js +81 -33
- package/dist/cjs/agents/invocation_context.js +0 -1
- package/dist/cjs/agents/llm_agent.js +52 -5
- package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/cjs/agents/processors/content_processor_utils.js +37 -24
- package/dist/cjs/agents/processors/content_request_processor.js +7 -0
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +12 -0
- package/dist/cjs/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/cjs/agents/processors/tool_filter_request_processor.js +7 -1
- package/dist/cjs/auth/auth_preprocessor.js +12 -10
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +305 -0
- package/dist/cjs/code_executors/code_execution_utils.js +1 -1
- package/dist/cjs/code_executors/code_executor_context.js +7 -7
- package/dist/cjs/common.js +50 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +11 -0
- package/dist/cjs/context/token_based_context_compactor.js +1 -1
- package/dist/cjs/events/event.js +4 -2
- package/dist/cjs/index.js +14 -0
- package/dist/cjs/integrations/agent_registry/agent_registry.js +362 -0
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +122 -0
- package/dist/cjs/integrations/agent_registry/helpers.js +57 -0
- package/dist/cjs/integrations/agent_registry/types.js +50 -0
- package/dist/cjs/memory/vertex_ai_memory_bank_service.js +496 -0
- package/dist/cjs/models/gemini_llm_connection.js +62 -19
- package/dist/cjs/models/google_llm.js +26 -8
- package/dist/cjs/plugins/security_plugin.js +16 -0
- package/dist/cjs/runner/in_memory_runner.js +10 -5
- package/dist/cjs/runner/runner.js +32 -2
- package/dist/cjs/sessions/base_session_service.js +13 -2
- package/dist/cjs/sessions/database_session_service.js +51 -5
- package/dist/cjs/sessions/db/schema.js +45 -10
- package/dist/cjs/sessions/in_memory_session_service.js +72 -15
- package/dist/cjs/sessions/registry.js +4 -0
- package/dist/cjs/sessions/vertex_ai_session_service.js +429 -0
- package/dist/cjs/skills/gcp_skill_registry.js +104 -0
- package/dist/cjs/skills/loader.js +65 -0
- package/dist/cjs/skills/skill_registry.js +27 -0
- package/dist/cjs/tools/agent_tool.js +10 -5
- package/dist/cjs/tools/exit_loop_tool.js +9 -0
- package/dist/cjs/tools/function_tool.js +7 -2
- package/dist/cjs/tools/google_maps_grounding_tool.js +80 -0
- package/dist/cjs/tools/long_running_tool.js +2 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/cjs/tools/mcp/mcp_tool.js +10 -6
- package/dist/cjs/tools/mcp/mcp_toolset.js +26 -3
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +78 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +84 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +133 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +232 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +224 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +127 -0
- package/dist/cjs/tools/openapi_tool/openapi_toolset.js +133 -0
- package/dist/cjs/tools/openapi_tool/rest_api_tool.js +256 -0
- package/dist/cjs/tools/skill/load_skill_resource_tool.js +27 -28
- package/dist/cjs/tools/skill/load_skill_tool.js +12 -1
- package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/cjs/tools/skill/search_skills_tool.js +108 -0
- package/dist/cjs/tools/skill/skill_toolset.js +40 -5
- package/dist/cjs/tools/vertex_rag_retrieval_tool.js +64 -0
- package/dist/cjs/utils/async_queue.js +88 -0
- package/dist/cjs/utils/case_utils.js +53 -0
- package/dist/cjs/utils/env_aware_utils.js +4 -0
- package/dist/cjs/utils/file_utils.js +28 -0
- package/dist/cjs/utils/gemini_schema_util.js +18 -0
- package/dist/cjs/utils/live_connection_utils.js +284 -0
- package/dist/cjs/utils/model_name.js +9 -0
- package/dist/cjs/utils/partial_copy.js +51 -0
- package/dist/cjs/utils/streaming_utils.js +169 -122
- package/dist/cjs/utils/vertex_ai_utils.js +50 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/base_agent.js +19 -1
- package/dist/esm/agents/functions.js +4 -0
- package/dist/esm/agents/instructions.js +81 -33
- package/dist/esm/agents/invocation_context.js +0 -1
- package/dist/esm/agents/llm_agent.js +53 -5
- package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/esm/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/esm/agents/processors/content_processor_utils.js +35 -23
- package/dist/esm/agents/processors/content_request_processor.js +7 -0
- package/dist/esm/agents/processors/context_compactor_request_processor.js +12 -0
- package/dist/esm/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/esm/agents/processors/tool_filter_request_processor.js +7 -1
- package/dist/esm/auth/auth_preprocessor.js +12 -10
- package/dist/esm/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +281 -0
- package/dist/esm/code_executors/code_execution_utils.js +1 -1
- package/dist/esm/code_executors/code_executor_context.js +7 -7
- package/dist/esm/common.js +43 -1
- package/dist/esm/context/summarizers/llm_summarizer.js +11 -0
- package/dist/esm/context/token_based_context_compactor.js +1 -1
- package/dist/esm/events/event.js +4 -2
- package/dist/esm/index.js +11 -0
- package/dist/esm/integrations/agent_registry/agent_registry.js +333 -0
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +96 -0
- package/dist/esm/integrations/agent_registry/helpers.js +28 -0
- package/dist/esm/integrations/agent_registry/types.js +20 -0
- package/dist/esm/memory/vertex_ai_memory_bank_service.js +468 -0
- package/dist/esm/models/gemini_llm_connection.js +62 -19
- package/dist/esm/models/google_llm.js +26 -8
- package/dist/esm/plugins/security_plugin.js +16 -0
- package/dist/esm/runner/in_memory_runner.js +10 -5
- package/dist/esm/runner/runner.js +32 -2
- package/dist/esm/sessions/base_session_service.js +11 -1
- package/dist/esm/sessions/database_session_service.js +51 -5
- package/dist/esm/sessions/db/schema.js +44 -10
- package/dist/esm/sessions/in_memory_session_service.js +74 -16
- package/dist/esm/sessions/registry.js +7 -0
- package/dist/esm/sessions/vertex_ai_session_service.js +405 -0
- package/dist/esm/skills/gcp_skill_registry.js +78 -0
- package/dist/esm/skills/loader.js +64 -0
- package/dist/esm/skills/skill_registry.js +7 -0
- package/dist/esm/tools/agent_tool.js +10 -5
- package/dist/esm/tools/exit_loop_tool.js +9 -0
- package/dist/esm/tools/function_tool.js +7 -2
- package/dist/esm/tools/google_maps_grounding_tool.js +54 -0
- package/dist/esm/tools/long_running_tool.js +2 -1
- package/dist/esm/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/esm/tools/mcp/mcp_tool.js +10 -6
- package/dist/esm/tools/mcp/mcp_toolset.js +26 -3
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +48 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +206 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
- package/dist/esm/tools/openapi_tool/openapi_toolset.js +97 -0
- package/dist/esm/tools/openapi_tool/rest_api_tool.js +229 -0
- package/dist/esm/tools/skill/load_skill_resource_tool.js +26 -27
- package/dist/esm/tools/skill/load_skill_tool.js +12 -1
- package/dist/esm/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/esm/tools/skill/search_skills_tool.js +82 -0
- package/dist/esm/tools/skill/skill_toolset.js +40 -5
- package/dist/esm/tools/vertex_rag_retrieval_tool.js +36 -0
- package/dist/esm/utils/async_queue.js +60 -0
- package/dist/esm/utils/case_utils.js +25 -0
- package/dist/esm/utils/env_aware_utils.js +4 -0
- package/dist/esm/utils/file_utils.js +26 -0
- package/dist/esm/utils/gemini_schema_util.js +18 -0
- package/dist/esm/utils/live_connection_utils.js +256 -0
- package/dist/esm/utils/model_name.js +8 -0
- package/dist/esm/utils/partial_copy.js +23 -0
- package/dist/esm/utils/streaming_utils.js +167 -121
- package/dist/esm/utils/vertex_ai_utils.js +22 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +14 -0
- package/dist/types/a2a/a2a_remote_agent_utils.d.ts +29 -4
- package/dist/types/a2a/event_converter_utils.d.ts +14 -1
- package/dist/types/a2a/metadata_converter_utils.d.ts +18 -0
- package/dist/types/a2a/part_converter_utils.d.ts +51 -6
- package/dist/types/agents/invocation_context.d.ts +0 -9
- package/dist/types/agents/llm_agent.d.ts +14 -0
- package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +14 -0
- package/dist/types/agents/processors/base_llm_processor.d.ts +12 -4
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +12 -0
- package/dist/types/agents/processors/content_processor_utils.d.ts +26 -0
- package/dist/types/agents/processors/content_request_processor.d.ts +16 -0
- package/dist/types/agents/processors/context_compactor_request_processor.d.ts +12 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +11 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +14 -1
- package/dist/types/agents/processors/tool_filter_request_processor.d.ts +12 -1
- package/dist/types/agents/run_config.d.ts +15 -0
- package/dist/types/code_executors/agent_engine_sandbox_code_executor.d.ts +51 -0
- package/dist/types/common.d.ts +19 -1
- package/dist/types/context/summarizers/llm_summarizer.d.ts +17 -0
- package/dist/types/events/event_actions.d.ts +25 -8
- package/dist/types/events/structured_events.d.ts +13 -0
- package/dist/types/examples/example_util.d.ts +25 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/integrations/agent_registry/agent_registry.d.ts +94 -0
- package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +62 -0
- package/dist/types/integrations/agent_registry/helpers.d.ts +7 -0
- package/dist/types/integrations/agent_registry/types.d.ts +101 -0
- package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +52 -0
- package/dist/types/models/base_llm_connection.d.ts +10 -0
- package/dist/types/models/gemini_llm_connection.d.ts +15 -4
- package/dist/types/models/llm_response.d.ts +10 -1
- package/dist/types/plugins/security_plugin.d.ts +30 -0
- package/dist/types/runner/in_memory_runner.d.ts +28 -1
- package/dist/types/runner/runner.d.ts +47 -0
- package/dist/types/sessions/base_session_service.d.ts +22 -0
- package/dist/types/sessions/database_session_service.d.ts +1 -1
- package/dist/types/sessions/db/schema.d.ts +1 -0
- package/dist/types/sessions/in_memory_session_service.d.ts +1 -1
- package/dist/types/sessions/vertex_ai_session_service.d.ts +37 -0
- package/dist/types/skills/gcp_skill_registry.d.ts +24 -0
- package/dist/types/skills/loader.d.ts +7 -0
- package/dist/types/skills/skill.d.ts +1 -1
- package/dist/types/skills/skill_registry.d.ts +29 -0
- package/dist/types/tools/exit_loop_tool.d.ts +9 -0
- package/dist/types/tools/function_tool.d.ts +22 -2
- package/dist/types/tools/google_maps_grounding_tool.d.ts +22 -0
- package/dist/types/tools/long_running_tool.d.ts +11 -1
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +3 -0
- package/dist/types/tools/mcp/mcp_toolset.d.ts +2 -1
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +25 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +20 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.d.ts +20 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +34 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +59 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +23 -0
- package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +27 -0
- package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +50 -0
- package/dist/types/tools/skill/load_skill_resource_tool.d.ts +1 -1
- package/dist/types/tools/skill/search_skills_tool.d.ts +14 -0
- package/dist/types/tools/skill/skill_toolset.d.ts +5 -0
- package/dist/types/tools/vertex_rag_retrieval_tool.d.ts +42 -0
- package/dist/types/utils/async_queue.d.ts +18 -0
- package/dist/types/utils/case_utils.d.ts +12 -0
- package/dist/types/utils/file_utils.d.ts +2 -0
- package/dist/types/utils/live_connection_utils.d.ts +30 -0
- package/dist/types/utils/model_name.d.ts +7 -0
- package/dist/types/utils/partial_copy.d.ts +13 -0
- package/dist/types/utils/streaming_utils.d.ts +7 -17
- package/dist/types/utils/vertex_ai_utils.d.ts +14 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/base_agent.js +31 -1
- package/dist/web/agents/functions.js +4 -0
- package/dist/web/agents/instructions.js +81 -33
- package/dist/web/agents/invocation_context.js +0 -1
- package/dist/web/agents/llm_agent.js +53 -5
- package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/web/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/web/agents/processors/content_processor_utils.js +53 -23
- package/dist/web/agents/processors/content_request_processor.js +7 -0
- package/dist/web/agents/processors/context_compactor_request_processor.js +12 -0
- package/dist/web/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/web/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/web/agents/processors/tool_filter_request_processor.js +7 -1
- package/dist/web/auth/auth_preprocessor.js +12 -10
- package/dist/web/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/web/code_executors/agent_engine_sandbox_code_executor.js +281 -0
- package/dist/web/code_executors/code_execution_utils.js +1 -1
- package/dist/web/code_executors/code_executor_context.js +7 -7
- package/dist/web/common.js +43 -1
- package/dist/web/context/summarizers/llm_summarizer.js +11 -0
- package/dist/web/context/token_based_context_compactor.js +1 -1
- package/dist/web/events/event.js +4 -2
- package/dist/web/index.js +11 -0
- package/dist/web/integrations/agent_registry/agent_registry.js +333 -0
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +109 -0
- package/dist/web/integrations/agent_registry/helpers.js +28 -0
- package/dist/web/integrations/agent_registry/types.js +20 -0
- package/dist/web/memory/vertex_ai_memory_bank_service.js +475 -0
- package/dist/web/models/gemini_llm_connection.js +75 -19
- package/dist/web/models/google_llm.js +26 -8
- package/dist/web/plugins/security_plugin.js +16 -0
- package/dist/web/runner/in_memory_runner.js +10 -5
- package/dist/web/runner/runner.js +32 -2
- package/dist/web/sessions/base_session_service.js +11 -1
- package/dist/web/sessions/database_session_service.js +51 -5
- package/dist/web/sessions/db/schema.js +44 -10
- package/dist/web/sessions/in_memory_session_service.js +74 -16
- package/dist/web/sessions/registry.js +7 -0
- package/dist/web/sessions/vertex_ai_session_service.js +416 -0
- package/dist/web/skills/gcp_skill_registry.js +78 -0
- package/dist/web/skills/loader.js +64 -0
- package/dist/web/skills/skill_registry.js +7 -0
- package/dist/web/tools/agent_tool.js +10 -5
- package/dist/web/tools/exit_loop_tool.js +9 -0
- package/dist/web/tools/function_tool.js +7 -2
- package/dist/web/tools/google_maps_grounding_tool.js +54 -0
- package/dist/web/tools/long_running_tool.js +2 -1
- package/dist/web/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/web/tools/mcp/mcp_tool.js +10 -6
- package/dist/web/tools/mcp/mcp_toolset.js +26 -3
- package/dist/web/tools/openapi_tool/auth/auth_helpers.js +48 -0
- package/dist/web/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
- package/dist/web/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +221 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
- package/dist/web/tools/openapi_tool/openapi_toolset.js +97 -0
- package/dist/web/tools/openapi_tool/rest_api_tool.js +229 -0
- package/dist/web/tools/skill/load_skill_resource_tool.js +26 -27
- package/dist/web/tools/skill/load_skill_tool.js +12 -1
- package/dist/web/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/web/tools/skill/search_skills_tool.js +82 -0
- package/dist/web/tools/skill/skill_toolset.js +40 -5
- package/dist/web/tools/vertex_rag_retrieval_tool.js +36 -0
- package/dist/web/utils/async_queue.js +60 -0
- package/dist/web/utils/case_utils.js +25 -0
- package/dist/web/utils/env_aware_utils.js +4 -0
- package/dist/web/utils/file_utils.js +26 -0
- package/dist/web/utils/gemini_schema_util.js +18 -0
- package/dist/web/utils/live_connection_utils.js +254 -0
- package/dist/web/utils/model_name.js +8 -0
- package/dist/web/utils/partial_copy.js +23 -0
- package/dist/web/utils/streaming_utils.js +221 -122
- package/dist/web/utils/vertex_ai_utils.js +22 -0
- package/dist/web/version.js +1 -1
- package/package.json +4 -1
|
@@ -10,11 +10,16 @@ import { InMemoryMemoryService } from "../memory/in_memory_memory_service.js";
|
|
|
10
10
|
import { InMemorySessionService } from "../sessions/in_memory_session_service.js";
|
|
11
11
|
import { Runner } from "./runner.js";
|
|
12
12
|
class InMemoryRunner extends Runner {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new InMemoryRunner instance.
|
|
15
|
+
*
|
|
16
|
+
* @param params The configuration for the runner.
|
|
17
|
+
* @param params.agent The root agent to run.
|
|
18
|
+
* @param params.appName The application name. Defaults to `'InMemoryRunner'`.
|
|
19
|
+
* @param params.plugins An optional list of plugins.
|
|
20
|
+
*/
|
|
21
|
+
constructor(params) {
|
|
22
|
+
const { agent, appName = "InMemoryRunner", plugins = [] } = params;
|
|
18
23
|
super({
|
|
19
24
|
appName,
|
|
20
25
|
agent,
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
runAsyncGeneratorWithOtelContext,
|
|
26
26
|
tracer
|
|
27
27
|
} from "../telemetry/tracing.js";
|
|
28
|
+
import { isBaseToolset } from "../tools/base_toolset.js";
|
|
28
29
|
import { logger } from "../utils/logger.js";
|
|
29
30
|
import { isGemini2OrAbove } from "../utils/model_name.js";
|
|
30
31
|
const RUNNER_SIGNATURE_SYMBOL = Symbol.for("google.adk.runner");
|
|
@@ -33,6 +34,11 @@ function isRunner(obj) {
|
|
|
33
34
|
}
|
|
34
35
|
_a = RUNNER_SIGNATURE_SYMBOL;
|
|
35
36
|
class Runner {
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new Runner instance.
|
|
39
|
+
*
|
|
40
|
+
* @param input The configuration for the runner.
|
|
41
|
+
*/
|
|
36
42
|
constructor(input) {
|
|
37
43
|
this[_a] = true;
|
|
38
44
|
var _a2;
|
|
@@ -65,7 +71,8 @@ class Runner {
|
|
|
65
71
|
sessionId,
|
|
66
72
|
newMessage: params.newMessage,
|
|
67
73
|
stateDelta: params.stateDelta,
|
|
68
|
-
runConfig: params.runConfig
|
|
74
|
+
runConfig: params.runConfig,
|
|
75
|
+
customMetadata: params.customMetadata
|
|
69
76
|
});
|
|
70
77
|
} finally {
|
|
71
78
|
await this.sessionService.deleteSession({
|
|
@@ -170,7 +177,8 @@ class Runner {
|
|
|
170
177
|
invocationId: invocationContext.invocationId,
|
|
171
178
|
author: "user",
|
|
172
179
|
actions: stateDelta ? createEventActions({ stateDelta }) : void 0,
|
|
173
|
-
content: newMessage
|
|
180
|
+
content: newMessage,
|
|
181
|
+
customMetadata: params.customMetadata
|
|
174
182
|
})
|
|
175
183
|
});
|
|
176
184
|
if ((_e = params.abortSignal) == null ? void 0 : _e.aborted) {
|
|
@@ -235,6 +243,8 @@ class Runner {
|
|
|
235
243
|
);
|
|
236
244
|
} finally {
|
|
237
245
|
span.end();
|
|
246
|
+
const toolsets = getAllToolsets(this.agent);
|
|
247
|
+
await Promise.allSettled(toolsets.map((t) => t.close()));
|
|
238
248
|
}
|
|
239
249
|
}
|
|
240
250
|
/**
|
|
@@ -354,6 +364,26 @@ function findEventByLastFunctionResponseId(events) {
|
|
|
354
364
|
}
|
|
355
365
|
return null;
|
|
356
366
|
}
|
|
367
|
+
function getAllToolsets(agent) {
|
|
368
|
+
const toolsets = [];
|
|
369
|
+
const visited = /* @__PURE__ */ new Set();
|
|
370
|
+
function traverse(curr) {
|
|
371
|
+
if (visited.has(curr)) return;
|
|
372
|
+
visited.add(curr);
|
|
373
|
+
if (isLlmAgent(curr)) {
|
|
374
|
+
for (const tool of curr.tools) {
|
|
375
|
+
if (isBaseToolset(tool)) {
|
|
376
|
+
toolsets.push(tool);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
for (const sub of curr.subAgents) {
|
|
381
|
+
traverse(sub);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
traverse(agent);
|
|
385
|
+
return toolsets;
|
|
386
|
+
}
|
|
357
387
|
export {
|
|
358
388
|
Runner,
|
|
359
389
|
isRunner
|
|
@@ -74,6 +74,15 @@ function trimTempDeltaState(event) {
|
|
|
74
74
|
event.actions.stateDelta = filteredStateDelta;
|
|
75
75
|
return event;
|
|
76
76
|
}
|
|
77
|
+
function trimTempState(state) {
|
|
78
|
+
const filteredState = {};
|
|
79
|
+
for (const [key, value] of Object.entries(state)) {
|
|
80
|
+
if (!key.startsWith(State.TEMP_PREFIX)) {
|
|
81
|
+
filteredState[key] = value;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return filteredState;
|
|
85
|
+
}
|
|
77
86
|
function mergeStates(appState = {}, userState = {}, sessionState = {}) {
|
|
78
87
|
const merged = cloneDeep(sessionState);
|
|
79
88
|
for (const [k, v] of Object.entries(appState)) {
|
|
@@ -87,5 +96,6 @@ function mergeStates(appState = {}, userState = {}, sessionState = {}) {
|
|
|
87
96
|
export {
|
|
88
97
|
BaseSessionService,
|
|
89
98
|
mergeStates,
|
|
90
|
-
trimTempDeltaState
|
|
99
|
+
trimTempDeltaState,
|
|
100
|
+
trimTempState
|
|
91
101
|
};
|
|
@@ -108,7 +108,7 @@ class DatabaseSessionService extends BaseSessionService {
|
|
|
108
108
|
appStateDelta[key.replace(State.APP_PREFIX, "")] = value;
|
|
109
109
|
} else if (key.startsWith(State.USER_PREFIX)) {
|
|
110
110
|
userStateDelta[key.replace(State.USER_PREFIX, "")] = value;
|
|
111
|
-
} else {
|
|
111
|
+
} else if (!key.startsWith(State.TEMP_PREFIX)) {
|
|
112
112
|
sessionState[key] = value;
|
|
113
113
|
}
|
|
114
114
|
}
|
|
@@ -193,7 +193,11 @@ class DatabaseSessionService extends BaseSessionService {
|
|
|
193
193
|
}
|
|
194
194
|
async listSessions({
|
|
195
195
|
appName,
|
|
196
|
-
userId
|
|
196
|
+
userId,
|
|
197
|
+
limit,
|
|
198
|
+
offset,
|
|
199
|
+
page,
|
|
200
|
+
order
|
|
197
201
|
}) {
|
|
198
202
|
await this.init();
|
|
199
203
|
const em = this.orm.em.fork();
|
|
@@ -201,7 +205,49 @@ class DatabaseSessionService extends BaseSessionService {
|
|
|
201
205
|
if (userId) {
|
|
202
206
|
where.userId = userId;
|
|
203
207
|
}
|
|
204
|
-
const
|
|
208
|
+
const orderBy = order === "asc" ? { updateTime: "ASC", id: "ASC" } : order === "desc" ? { updateTime: "DESC", id: "ASC" } : void 0;
|
|
209
|
+
let storageSessions;
|
|
210
|
+
let paginationMeta;
|
|
211
|
+
if (limit !== void 0) {
|
|
212
|
+
const totalItems = await em.count(StorageSession, where);
|
|
213
|
+
const totalPages = limit === 0 ? 0 : Math.ceil(totalItems / limit);
|
|
214
|
+
let effectiveOffset;
|
|
215
|
+
let effectivePage;
|
|
216
|
+
if (page !== void 0) {
|
|
217
|
+
effectiveOffset = (page - 1) * limit;
|
|
218
|
+
effectivePage = page;
|
|
219
|
+
} else {
|
|
220
|
+
effectiveOffset = offset != null ? offset : 0;
|
|
221
|
+
effectivePage = limit === 0 ? 1 : Math.floor(effectiveOffset / limit) + 1;
|
|
222
|
+
}
|
|
223
|
+
storageSessions = await em.find(StorageSession, where, {
|
|
224
|
+
orderBy,
|
|
225
|
+
limit,
|
|
226
|
+
offset: effectiveOffset
|
|
227
|
+
});
|
|
228
|
+
paginationMeta = { page: effectivePage, limit, totalItems, totalPages };
|
|
229
|
+
} else if (offset) {
|
|
230
|
+
const totalItems = await em.count(StorageSession, where);
|
|
231
|
+
storageSessions = await em.find(StorageSession, where, {
|
|
232
|
+
orderBy,
|
|
233
|
+
offset
|
|
234
|
+
});
|
|
235
|
+
paginationMeta = {
|
|
236
|
+
page: 1,
|
|
237
|
+
limit: totalItems,
|
|
238
|
+
totalItems,
|
|
239
|
+
totalPages: totalItems === 0 ? 0 : 1
|
|
240
|
+
};
|
|
241
|
+
} else {
|
|
242
|
+
storageSessions = await em.find(StorageSession, where, { orderBy });
|
|
243
|
+
const totalItems = storageSessions.length;
|
|
244
|
+
paginationMeta = {
|
|
245
|
+
page: 1,
|
|
246
|
+
limit: totalItems,
|
|
247
|
+
totalItems,
|
|
248
|
+
totalPages: totalItems === 0 ? 0 : 1
|
|
249
|
+
};
|
|
250
|
+
}
|
|
205
251
|
const appStateModel = await em.findOne(StorageAppState, { appName });
|
|
206
252
|
const appState = (appStateModel == null ? void 0 : appStateModel.state) || {};
|
|
207
253
|
const userStateMap = {};
|
|
@@ -226,7 +272,7 @@ class DatabaseSessionService extends BaseSessionService {
|
|
|
226
272
|
lastUpdateTime: ss.updateTime.getTime()
|
|
227
273
|
});
|
|
228
274
|
});
|
|
229
|
-
return { sessions };
|
|
275
|
+
return { sessions, ...paginationMeta };
|
|
230
276
|
}
|
|
231
277
|
async deleteSession({
|
|
232
278
|
appName,
|
|
@@ -311,7 +357,7 @@ class DatabaseSessionService extends BaseSessionService {
|
|
|
311
357
|
appDelta[key.replace(State.APP_PREFIX, "")] = value;
|
|
312
358
|
} else if (key.startsWith(State.USER_PREFIX)) {
|
|
313
359
|
userDelta[key.replace(State.USER_PREFIX, "")] = value;
|
|
314
|
-
} else {
|
|
360
|
+
} else if (!key.startsWith(State.TEMP_PREFIX)) {
|
|
315
361
|
sessionDelta[key] = value;
|
|
316
362
|
}
|
|
317
363
|
}
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
} from "../../events/event.js";
|
|
23
23
|
const SCHEMA_VERSION_KEY = "schema_version";
|
|
24
24
|
const SCHEMA_VERSION_1_JSON = "1";
|
|
25
|
+
const STORAGE_KEY_COLUMN_LENGTH = 191;
|
|
25
26
|
class CamelCaseToSnakeCaseJsonType extends JsonType {
|
|
26
27
|
convertToDatabaseValue(value) {
|
|
27
28
|
return JSON.stringify(transformToSnakeCaseEvent(value));
|
|
@@ -50,7 +51,11 @@ let StorageAppState = class {
|
|
|
50
51
|
}
|
|
51
52
|
};
|
|
52
53
|
__decorateClass([
|
|
53
|
-
PrimaryKey({
|
|
54
|
+
PrimaryKey({
|
|
55
|
+
type: "string",
|
|
56
|
+
fieldName: "app_name",
|
|
57
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
58
|
+
})
|
|
54
59
|
], StorageAppState.prototype, "appName", 2);
|
|
55
60
|
__decorateClass([
|
|
56
61
|
Property({ type: "json" })
|
|
@@ -73,10 +78,18 @@ let StorageUserState = class {
|
|
|
73
78
|
}
|
|
74
79
|
};
|
|
75
80
|
__decorateClass([
|
|
76
|
-
PrimaryKey({
|
|
81
|
+
PrimaryKey({
|
|
82
|
+
type: "string",
|
|
83
|
+
fieldName: "app_name",
|
|
84
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
85
|
+
})
|
|
77
86
|
], StorageUserState.prototype, "appName", 2);
|
|
78
87
|
__decorateClass([
|
|
79
|
-
PrimaryKey({
|
|
88
|
+
PrimaryKey({
|
|
89
|
+
type: "string",
|
|
90
|
+
fieldName: "user_id",
|
|
91
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
92
|
+
})
|
|
80
93
|
], StorageUserState.prototype, "userId", 2);
|
|
81
94
|
__decorateClass([
|
|
82
95
|
Property({ type: "json" })
|
|
@@ -100,13 +113,21 @@ let StorageSession = class {
|
|
|
100
113
|
}
|
|
101
114
|
};
|
|
102
115
|
__decorateClass([
|
|
103
|
-
PrimaryKey({ type: "string" })
|
|
116
|
+
PrimaryKey({ type: "string", length: STORAGE_KEY_COLUMN_LENGTH })
|
|
104
117
|
], StorageSession.prototype, "id", 2);
|
|
105
118
|
__decorateClass([
|
|
106
|
-
PrimaryKey({
|
|
119
|
+
PrimaryKey({
|
|
120
|
+
type: "string",
|
|
121
|
+
fieldName: "app_name",
|
|
122
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
123
|
+
})
|
|
107
124
|
], StorageSession.prototype, "appName", 2);
|
|
108
125
|
__decorateClass([
|
|
109
|
-
PrimaryKey({
|
|
126
|
+
PrimaryKey({
|
|
127
|
+
type: "string",
|
|
128
|
+
fieldName: "user_id",
|
|
129
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
130
|
+
})
|
|
110
131
|
], StorageSession.prototype, "userId", 2);
|
|
111
132
|
__decorateClass([
|
|
112
133
|
Property({ type: "json" })
|
|
@@ -132,16 +153,28 @@ PrimaryKey.name;
|
|
|
132
153
|
let StorageEvent = class {
|
|
133
154
|
};
|
|
134
155
|
__decorateClass([
|
|
135
|
-
PrimaryKey({ type: "string" })
|
|
156
|
+
PrimaryKey({ type: "string", length: STORAGE_KEY_COLUMN_LENGTH })
|
|
136
157
|
], StorageEvent.prototype, "id", 2);
|
|
137
158
|
__decorateClass([
|
|
138
|
-
PrimaryKey({
|
|
159
|
+
PrimaryKey({
|
|
160
|
+
type: "string",
|
|
161
|
+
fieldName: "app_name",
|
|
162
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
163
|
+
})
|
|
139
164
|
], StorageEvent.prototype, "appName", 2);
|
|
140
165
|
__decorateClass([
|
|
141
|
-
PrimaryKey({
|
|
166
|
+
PrimaryKey({
|
|
167
|
+
type: "string",
|
|
168
|
+
fieldName: "user_id",
|
|
169
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
170
|
+
})
|
|
142
171
|
], StorageEvent.prototype, "userId", 2);
|
|
143
172
|
__decorateClass([
|
|
144
|
-
PrimaryKey({
|
|
173
|
+
PrimaryKey({
|
|
174
|
+
type: "string",
|
|
175
|
+
fieldName: "session_id",
|
|
176
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
177
|
+
})
|
|
145
178
|
], StorageEvent.prototype, "sessionId", 2);
|
|
146
179
|
__decorateClass([
|
|
147
180
|
Property({ type: "string", fieldName: "invocation_id" })
|
|
@@ -166,6 +199,7 @@ export {
|
|
|
166
199
|
ENTITIES,
|
|
167
200
|
SCHEMA_VERSION_1_JSON,
|
|
168
201
|
SCHEMA_VERSION_KEY,
|
|
202
|
+
STORAGE_KEY_COLUMN_LENGTH,
|
|
169
203
|
StorageAppState,
|
|
170
204
|
StorageEvent,
|
|
171
205
|
StorageMetadata,
|
|
@@ -10,7 +10,8 @@ import { randomUUID } from "../utils/env_aware_utils.js";
|
|
|
10
10
|
import { logger } from "../utils/logger.js";
|
|
11
11
|
import {
|
|
12
12
|
BaseSessionService,
|
|
13
|
-
mergeStates
|
|
13
|
+
mergeStates,
|
|
14
|
+
trimTempState
|
|
14
15
|
} from "./base_session_service.js";
|
|
15
16
|
import { createSession } from "./session.js";
|
|
16
17
|
import { State } from "./state.js";
|
|
@@ -41,11 +42,12 @@ class InMemorySessionService extends BaseSessionService {
|
|
|
41
42
|
sessionId
|
|
42
43
|
}) {
|
|
43
44
|
var _a;
|
|
45
|
+
const filteredState = state ? trimTempState(state) : void 0;
|
|
44
46
|
const session = createSession({
|
|
45
47
|
id: sessionId || randomUUID(),
|
|
46
48
|
appName,
|
|
47
49
|
userId,
|
|
48
|
-
state,
|
|
50
|
+
state: filteredState,
|
|
49
51
|
events: [],
|
|
50
52
|
lastUpdateTime: Date.now()
|
|
51
53
|
});
|
|
@@ -104,25 +106,81 @@ class InMemorySessionService extends BaseSessionService {
|
|
|
104
106
|
}
|
|
105
107
|
listSessions({
|
|
106
108
|
appName,
|
|
107
|
-
userId
|
|
109
|
+
userId,
|
|
110
|
+
limit,
|
|
111
|
+
offset,
|
|
112
|
+
page,
|
|
113
|
+
order
|
|
108
114
|
}) {
|
|
109
115
|
if (!this.sessions[appName] || !this.sessions[appName][userId]) {
|
|
110
|
-
|
|
116
|
+
if (limit !== void 0) {
|
|
117
|
+
const effectiveOffset2 = page !== void 0 ? (page - 1) * limit : offset != null ? offset : 0;
|
|
118
|
+
const effectivePage2 = page !== void 0 ? page : limit === 0 ? 1 : Math.floor(effectiveOffset2 / limit) + 1;
|
|
119
|
+
return Promise.resolve({
|
|
120
|
+
sessions: [],
|
|
121
|
+
page: effectivePage2,
|
|
122
|
+
limit,
|
|
123
|
+
totalItems: 0,
|
|
124
|
+
totalPages: 0
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return Promise.resolve({
|
|
128
|
+
sessions: [],
|
|
129
|
+
page: 1,
|
|
130
|
+
limit: 0,
|
|
131
|
+
totalItems: 0,
|
|
132
|
+
totalPages: 0
|
|
133
|
+
});
|
|
111
134
|
}
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
135
|
+
const all = Object.values(this.sessions[appName][userId]).map(
|
|
136
|
+
(session) => createSession({
|
|
137
|
+
id: session.id,
|
|
138
|
+
appName: session.appName,
|
|
139
|
+
userId: session.userId,
|
|
140
|
+
state: {},
|
|
141
|
+
events: [],
|
|
142
|
+
lastUpdateTime: session.lastUpdateTime
|
|
143
|
+
})
|
|
144
|
+
);
|
|
145
|
+
if (order === "asc") {
|
|
146
|
+
all.sort(
|
|
147
|
+
(a, b) => a.lastUpdateTime - b.lastUpdateTime || a.id.localeCompare(b.id)
|
|
148
|
+
);
|
|
149
|
+
} else if (order === "desc") {
|
|
150
|
+
all.sort(
|
|
151
|
+
(a, b) => b.lastUpdateTime - a.lastUpdateTime || a.id.localeCompare(b.id)
|
|
123
152
|
);
|
|
124
153
|
}
|
|
125
|
-
|
|
154
|
+
if (limit === void 0) {
|
|
155
|
+
const totalItems2 = all.length;
|
|
156
|
+
const sliced = offset ? all.slice(offset) : all;
|
|
157
|
+
return Promise.resolve({
|
|
158
|
+
sessions: sliced,
|
|
159
|
+
page: 1,
|
|
160
|
+
limit: totalItems2,
|
|
161
|
+
totalItems: totalItems2,
|
|
162
|
+
totalPages: totalItems2 === 0 ? 0 : 1
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
const totalItems = all.length;
|
|
166
|
+
const totalPages = limit === 0 ? 0 : Math.ceil(totalItems / limit);
|
|
167
|
+
let effectiveOffset;
|
|
168
|
+
let effectivePage;
|
|
169
|
+
if (page !== void 0) {
|
|
170
|
+
effectiveOffset = (page - 1) * limit;
|
|
171
|
+
effectivePage = page;
|
|
172
|
+
} else {
|
|
173
|
+
effectiveOffset = offset != null ? offset : 0;
|
|
174
|
+
effectivePage = limit === 0 ? 1 : Math.floor(effectiveOffset / limit) + 1;
|
|
175
|
+
}
|
|
176
|
+
const paginated = all.slice(effectiveOffset, effectiveOffset + limit);
|
|
177
|
+
return Promise.resolve({
|
|
178
|
+
sessions: paginated,
|
|
179
|
+
page: effectivePage,
|
|
180
|
+
limit,
|
|
181
|
+
totalItems,
|
|
182
|
+
totalPages
|
|
183
|
+
});
|
|
126
184
|
}
|
|
127
185
|
async deleteSession({
|
|
128
186
|
appName,
|
|
@@ -13,6 +13,10 @@ import {
|
|
|
13
13
|
InMemorySessionService,
|
|
14
14
|
isInMemoryConnectionString
|
|
15
15
|
} from "./in_memory_session_service.js";
|
|
16
|
+
import {
|
|
17
|
+
VertexAiSessionService,
|
|
18
|
+
isVertexAiConnectionString
|
|
19
|
+
} from "./vertex_ai_session_service.js";
|
|
16
20
|
function getSessionServiceFromUri(uri) {
|
|
17
21
|
if (isInMemoryConnectionString(uri)) {
|
|
18
22
|
return new InMemorySessionService();
|
|
@@ -20,6 +24,9 @@ function getSessionServiceFromUri(uri) {
|
|
|
20
24
|
if (isDatabaseConnectionString(uri)) {
|
|
21
25
|
return new DatabaseSessionService(uri);
|
|
22
26
|
}
|
|
27
|
+
if (isVertexAiConnectionString(uri)) {
|
|
28
|
+
return new VertexAiSessionService({});
|
|
29
|
+
}
|
|
23
30
|
throw new Error(`Unsupported session service URI: ${uri}`);
|
|
24
31
|
}
|
|
25
32
|
export {
|