@google/adk 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/agents/active_streaming_tool.js +6 -1
- package/dist/cjs/agents/base_agent.js +19 -1
- package/dist/cjs/agents/context.js +1 -11
- package/dist/cjs/agents/functions.js +35 -16
- package/dist/cjs/agents/instructions.js +99 -33
- package/dist/cjs/agents/invocation_context.js +2 -6
- package/dist/cjs/agents/llm_agent.js +60 -11
- package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/cjs/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/cjs/agents/processors/content_processor_utils.js +51 -25
- package/dist/cjs/agents/processors/content_request_processor.js +7 -0
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +16 -2
- package/dist/cjs/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/cjs/agents/processors/interactions_request_processor.js +63 -0
- package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/cjs/agents/processors/tool_filter_request_processor.js +7 -1
- package/dist/cjs/apps/app.js +79 -0
- package/dist/cjs/apps/resumability_config.js +44 -0
- package/dist/cjs/artifacts/file_artifact_service.js +14 -1
- package/dist/cjs/artifacts/gcs_artifact_service.js +57 -15
- package/dist/cjs/artifacts/in_memory_artifact_service.js +5 -1
- package/dist/cjs/artifacts/scoped_artifact_service.js +101 -0
- package/dist/cjs/artifacts/session_artifact_service.js +27 -0
- package/dist/cjs/auth/auth_preprocessor.js +12 -10
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +17 -5
- package/dist/cjs/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/cjs/code_executors/code_executor_context.js +7 -7
- package/dist/cjs/common.js +86 -0
- package/dist/cjs/context/agent_controlled_context_compactor.js +109 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +11 -0
- package/dist/cjs/context/token_based_context_compactor.js +43 -11
- package/dist/cjs/context/trajectory_thought_pruning_compactor.js +71 -0
- package/dist/cjs/events/event.js +25 -1
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
- package/dist/cjs/models/gemini_llm_connection.js +62 -19
- package/dist/cjs/models/google_llm.js +51 -18
- package/dist/cjs/models/interactions_utils.js +732 -0
- package/dist/cjs/plugins/base_plugin.js +1 -0
- package/dist/cjs/plugins/security_plugin.js +16 -0
- package/dist/cjs/runner/in_memory_runner.js +13 -2
- package/dist/cjs/runner/runner.js +93 -72
- package/dist/cjs/sessions/base_session_service.js +19 -3
- package/dist/cjs/sessions/database_session_service.js +26 -9
- package/dist/cjs/sessions/db/schema.js +45 -10
- package/dist/cjs/sessions/in_memory_session_service.js +2 -1
- package/dist/cjs/sessions/vertex_ai_session_service.js +21 -5
- package/dist/cjs/skills/gcp_skill_registry.js +104 -0
- package/dist/cjs/skills/loader.js +67 -2
- package/dist/cjs/skills/skill_registry.js +27 -0
- package/dist/cjs/tools/base_toolset.js +1 -1
- package/dist/cjs/tools/consolidate_context_tool.js +79 -0
- package/dist/cjs/tools/forwarding_artifact_service.js +16 -28
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +232 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +224 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +117 -0
- package/dist/cjs/tools/openapi_tool/openapi_toolset.js +133 -0
- package/dist/cjs/tools/openapi_tool/rest_api_tool.js +256 -0
- package/dist/cjs/tools/skill/load_skill_resource_tool.js +25 -3
- package/dist/cjs/tools/skill/load_skill_tool.js +12 -1
- package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/cjs/tools/skill/search_skills_tool.js +108 -0
- package/dist/cjs/tools/skill/skill_toolset.js +40 -5
- package/dist/cjs/utils/async_hooks_shim.js +52 -0
- package/dist/cjs/utils/async_queue.js +88 -0
- package/dist/cjs/utils/case_utils.js +53 -0
- package/dist/cjs/utils/client_labels.js +41 -3
- package/dist/cjs/utils/env_aware_utils.js +14 -1
- package/dist/cjs/utils/live_connection_utils.js +284 -0
- package/dist/cjs/utils/model_name.js +9 -0
- package/dist/cjs/utils/streaming_utils.js +18 -11
- package/dist/cjs/utils/task.js +62 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/active_streaming_tool.js +6 -1
- package/dist/esm/agents/base_agent.js +19 -1
- package/dist/esm/agents/context.js +1 -11
- package/dist/esm/agents/functions.js +36 -15
- package/dist/esm/agents/instructions.js +99 -33
- package/dist/esm/agents/invocation_context.js +2 -6
- package/dist/esm/agents/llm_agent.js +61 -11
- package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/esm/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/esm/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/esm/agents/processors/content_processor_utils.js +48 -24
- package/dist/esm/agents/processors/content_request_processor.js +7 -0
- package/dist/esm/agents/processors/context_compactor_request_processor.js +16 -2
- package/dist/esm/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/esm/agents/processors/interactions_request_processor.js +34 -0
- package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/esm/agents/processors/tool_filter_request_processor.js +7 -1
- package/dist/esm/apps/app.js +49 -0
- package/dist/esm/apps/resumability_config.js +16 -0
- package/dist/esm/artifacts/file_artifact_service.js +14 -1
- package/dist/esm/artifacts/gcs_artifact_service.js +57 -15
- package/dist/esm/artifacts/in_memory_artifact_service.js +5 -1
- package/dist/esm/artifacts/scoped_artifact_service.js +73 -0
- package/dist/esm/artifacts/session_artifact_service.js +7 -0
- package/dist/esm/auth/auth_preprocessor.js +12 -10
- package/dist/esm/auth/oauth2/oauth2_discovery.js +14 -4
- package/dist/esm/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/esm/code_executors/code_executor_context.js +7 -7
- package/dist/esm/common.js +75 -3
- package/dist/esm/context/agent_controlled_context_compactor.js +81 -0
- package/dist/esm/context/summarizers/llm_summarizer.js +11 -0
- package/dist/esm/context/token_based_context_compactor.js +43 -11
- package/dist/esm/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/esm/events/event.js +23 -1
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
- package/dist/esm/models/gemini_llm_connection.js +62 -19
- package/dist/esm/models/google_llm.js +49 -17
- package/dist/esm/models/interactions_utils.js +697 -0
- package/dist/esm/plugins/base_plugin.js +1 -0
- package/dist/esm/plugins/security_plugin.js +16 -0
- package/dist/esm/runner/in_memory_runner.js +13 -2
- package/dist/esm/runner/runner.js +91 -73
- package/dist/esm/sessions/base_session_service.js +17 -2
- package/dist/esm/sessions/database_session_service.js +26 -9
- package/dist/esm/sessions/db/schema.js +44 -10
- package/dist/esm/sessions/in_memory_session_service.js +4 -2
- package/dist/esm/sessions/vertex_ai_session_service.js +21 -5
- package/dist/esm/skills/gcp_skill_registry.js +78 -0
- package/dist/esm/skills/loader.js +66 -2
- package/dist/esm/skills/skill_registry.js +7 -0
- package/dist/esm/tools/base_toolset.js +1 -1
- package/dist/esm/tools/consolidate_context_tool.js +51 -0
- package/dist/esm/tools/forwarding_artifact_service.js +16 -28
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +206 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +91 -0
- package/dist/esm/tools/openapi_tool/openapi_toolset.js +97 -0
- package/dist/esm/tools/openapi_tool/rest_api_tool.js +229 -0
- package/dist/esm/tools/skill/load_skill_resource_tool.js +25 -3
- package/dist/esm/tools/skill/load_skill_tool.js +12 -1
- package/dist/esm/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/esm/tools/skill/search_skills_tool.js +82 -0
- package/dist/esm/tools/skill/skill_toolset.js +40 -5
- package/dist/esm/utils/async_hooks_shim.js +24 -0
- package/dist/esm/utils/async_queue.js +60 -0
- package/dist/esm/utils/case_utils.js +25 -0
- package/dist/esm/utils/client_labels.js +38 -2
- package/dist/esm/utils/env_aware_utils.js +14 -1
- package/dist/esm/utils/live_connection_utils.js +256 -0
- package/dist/esm/utils/model_name.js +8 -0
- package/dist/esm/utils/streaming_utils.js +18 -11
- package/dist/esm/utils/task.js +34 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent_utils.d.ts +29 -4
- package/dist/types/a2a/event_converter_utils.d.ts +14 -1
- package/dist/types/a2a/metadata_converter_utils.d.ts +18 -0
- package/dist/types/a2a/part_converter_utils.d.ts +51 -6
- package/dist/types/agents/active_streaming_tool.d.ts +3 -4
- package/dist/types/agents/functions.d.ts +12 -9
- package/dist/types/agents/invocation_context.d.ts +7 -12
- package/dist/types/agents/llm_agent.d.ts +14 -0
- package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +14 -0
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +7 -0
- package/dist/types/agents/processors/content_processor_utils.d.ts +34 -0
- package/dist/types/agents/processors/content_request_processor.d.ts +16 -0
- package/dist/types/agents/processors/context_compactor_request_processor.d.ts +12 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +7 -0
- package/dist/types/agents/processors/interactions_request_processor.d.ts +17 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +9 -1
- package/dist/types/agents/processors/tool_filter_request_processor.d.ts +12 -1
- package/dist/types/apps/app.d.ts +52 -0
- package/dist/types/apps/resumability_config.d.ts +27 -0
- package/dist/types/artifacts/base_artifact_service.d.ts +6 -36
- package/dist/types/artifacts/gcs_artifact_service.d.ts +2 -1
- package/dist/types/artifacts/scoped_artifact_service.d.ts +25 -0
- package/dist/types/artifacts/session_artifact_service.d.ts +25 -0
- package/dist/types/auth/oauth2/oauth2_discovery.d.ts +11 -0
- package/dist/types/common.d.ts +35 -4
- package/dist/types/context/agent_controlled_context_compactor.d.ts +24 -0
- package/dist/types/context/base_context_compactor.d.ts +3 -0
- package/dist/types/context/summarizers/llm_summarizer.d.ts +17 -0
- package/dist/types/context/token_based_context_compactor.d.ts +6 -1
- package/dist/types/context/trajectory_thought_pruning_compactor.d.ts +27 -0
- package/dist/types/events/event.d.ts +8 -0
- package/dist/types/events/event_actions.d.ts +1 -2
- package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +21 -2
- package/dist/types/models/base_llm_connection.d.ts +10 -0
- package/dist/types/models/gemini_llm_connection.d.ts +15 -4
- package/dist/types/models/google_llm.d.ts +15 -1
- package/dist/types/models/interactions_utils.d.ts +92 -0
- package/dist/types/models/llm_request.d.ts +4 -0
- package/dist/types/models/llm_response.d.ts +14 -1
- package/dist/types/plugins/base_plugin.d.ts +2 -1
- package/dist/types/plugins/security_plugin.d.ts +30 -0
- package/dist/types/runner/in_memory_runner.d.ts +7 -1
- package/dist/types/runner/runner.d.ts +43 -9
- package/dist/types/sessions/base_session_service.d.ts +7 -16
- package/dist/types/sessions/db/schema.d.ts +1 -0
- package/dist/types/sessions/session.d.ts +11 -0
- package/dist/types/sessions/vertex_ai_session_service.d.ts +9 -1
- package/dist/types/skills/gcp_skill_registry.d.ts +24 -0
- package/dist/types/skills/loader.d.ts +7 -0
- package/dist/types/skills/skill.d.ts +1 -1
- package/dist/types/skills/skill_registry.d.ts +29 -0
- package/dist/types/tools/consolidate_context_tool.d.ts +19 -0
- package/dist/types/tools/forwarding_artifact_service.d.ts +3 -2
- package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +34 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +59 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +23 -0
- package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +27 -0
- package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +50 -0
- package/dist/types/tools/skill/load_skill_resource_tool.d.ts +1 -1
- package/dist/types/tools/skill/search_skills_tool.d.ts +14 -0
- package/dist/types/tools/skill/skill_toolset.d.ts +5 -0
- package/dist/types/utils/async_hooks_shim.d.ts +10 -0
- package/dist/types/utils/async_queue.d.ts +18 -0
- package/dist/types/utils/case_utils.d.ts +12 -0
- package/dist/types/utils/client_labels.d.ts +10 -0
- package/dist/types/utils/env_aware_utils.d.ts +3 -3
- package/dist/types/utils/live_connection_utils.d.ts +30 -0
- package/dist/types/utils/model_name.d.ts +7 -0
- package/dist/types/utils/streaming_utils.d.ts +0 -1
- package/dist/types/utils/task.d.ts +24 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/active_streaming_tool.js +6 -1
- package/dist/web/agents/base_agent.js +31 -1
- package/dist/web/agents/context.js +1 -11
- package/dist/web/agents/functions.js +36 -15
- package/dist/web/agents/instructions.js +99 -33
- package/dist/web/agents/invocation_context.js +2 -6
- package/dist/web/agents/llm_agent.js +61 -11
- package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/web/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/web/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/web/agents/processors/content_processor_utils.js +66 -24
- package/dist/web/agents/processors/content_request_processor.js +7 -0
- package/dist/web/agents/processors/context_compactor_request_processor.js +16 -2
- package/dist/web/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/web/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/web/agents/processors/interactions_request_processor.js +52 -0
- package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/web/agents/processors/tool_filter_request_processor.js +7 -1
- package/dist/web/apps/app.js +49 -0
- package/dist/web/apps/resumability_config.js +31 -0
- package/dist/web/artifacts/file_artifact_service.js +14 -1
- package/dist/web/artifacts/gcs_artifact_service.js +55 -15
- package/dist/web/artifacts/in_memory_artifact_service.js +5 -1
- package/dist/web/artifacts/scoped_artifact_service.js +86 -0
- package/dist/web/artifacts/session_artifact_service.js +7 -0
- package/dist/web/auth/auth_preprocessor.js +12 -10
- package/dist/web/auth/oauth2/oauth2_discovery.js +14 -4
- package/dist/web/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/web/code_executors/code_executor_context.js +7 -7
- package/dist/web/common.js +75 -3
- package/dist/web/context/agent_controlled_context_compactor.js +81 -0
- package/dist/web/context/summarizers/llm_summarizer.js +11 -0
- package/dist/web/context/token_based_context_compactor.js +43 -11
- package/dist/web/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/web/events/event.js +21 -1
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
- package/dist/web/models/gemini_llm_connection.js +75 -19
- package/dist/web/models/google_llm.js +80 -17
- package/dist/web/models/interactions_utils.js +728 -0
- package/dist/web/plugins/base_plugin.js +1 -0
- package/dist/web/plugins/security_plugin.js +16 -0
- package/dist/web/runner/in_memory_runner.js +13 -2
- package/dist/web/runner/runner.js +111 -75
- package/dist/web/sessions/base_session_service.js +17 -2
- package/dist/web/sessions/database_session_service.js +26 -9
- package/dist/web/sessions/db/schema.js +44 -10
- package/dist/web/sessions/in_memory_session_service.js +4 -2
- package/dist/web/sessions/vertex_ai_session_service.js +21 -5
- package/dist/web/skills/gcp_skill_registry.js +78 -0
- package/dist/web/skills/loader.js +66 -2
- package/dist/web/skills/skill_registry.js +7 -0
- package/dist/web/tools/base_toolset.js +1 -1
- package/dist/web/tools/consolidate_context_tool.js +51 -0
- package/dist/web/tools/forwarding_artifact_service.js +16 -28
- package/dist/web/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +221 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +91 -0
- package/dist/web/tools/openapi_tool/openapi_toolset.js +97 -0
- package/dist/web/tools/openapi_tool/rest_api_tool.js +229 -0
- package/dist/web/tools/skill/load_skill_resource_tool.js +25 -3
- package/dist/web/tools/skill/load_skill_tool.js +12 -1
- package/dist/web/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/web/tools/skill/search_skills_tool.js +82 -0
- package/dist/web/tools/skill/skill_toolset.js +40 -5
- package/dist/web/utils/async_hooks_shim.js +24 -0
- package/dist/web/utils/async_queue.js +60 -0
- package/dist/web/utils/case_utils.js +25 -0
- package/dist/web/utils/client_labels.js +38 -2
- package/dist/web/utils/env_aware_utils.js +14 -1
- package/dist/web/utils/live_connection_utils.js +254 -0
- package/dist/web/utils/model_name.js +8 -0
- package/dist/web/utils/streaming_utils.js +18 -11
- package/dist/web/utils/task.js +34 -0
- package/dist/web/version.js +1 -1
- package/package.json +4 -2
|
@@ -45,6 +45,7 @@ var import_experimental = require("../utils/experimental.js");
|
|
|
45
45
|
var ContextCompactionTrigger = /* @__PURE__ */ ((ContextCompactionTrigger2) => {
|
|
46
46
|
ContextCompactionTrigger2["Manual"] = "Manual";
|
|
47
47
|
ContextCompactionTrigger2["Auto"] = "Auto";
|
|
48
|
+
ContextCompactionTrigger2["AgentControlled"] = "AgentControlled";
|
|
48
49
|
return ContextCompactionTrigger2;
|
|
49
50
|
})(ContextCompactionTrigger || {});
|
|
50
51
|
class BasePlugin {
|
|
@@ -47,6 +47,11 @@ var PolicyOutcome = /* @__PURE__ */ ((PolicyOutcome2) => {
|
|
|
47
47
|
return PolicyOutcome2;
|
|
48
48
|
})(PolicyOutcome || {});
|
|
49
49
|
class InMemoryPolicyEngine {
|
|
50
|
+
/**
|
|
51
|
+
* Always returns {@link PolicyOutcome.ALLOW} for every tool call.
|
|
52
|
+
*
|
|
53
|
+
* @returns A promise resolving to an ALLOW result.
|
|
54
|
+
*/
|
|
50
55
|
async evaluate() {
|
|
51
56
|
return Promise.resolve({
|
|
52
57
|
outcome: "ALLOW" /* ALLOW */,
|
|
@@ -55,11 +60,22 @@ class InMemoryPolicyEngine {
|
|
|
55
60
|
}
|
|
56
61
|
}
|
|
57
62
|
class SecurityPlugin extends import_base_plugin.BasePlugin {
|
|
63
|
+
/**
|
|
64
|
+
* @param params - Optional configuration. Defaults to {@link InMemoryPolicyEngine}
|
|
65
|
+
* when no policy engine is provided.
|
|
66
|
+
*/
|
|
58
67
|
constructor(params) {
|
|
59
68
|
var _a;
|
|
60
69
|
super("security_plugin");
|
|
61
70
|
this.policyEngine = (_a = params == null ? void 0 : params.policyEngine) != null ? _a : new InMemoryPolicyEngine();
|
|
62
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Intercepts tool calls, evaluating them against the policy engine before
|
|
74
|
+
* execution and handling confirmation flows for calls that require it.
|
|
75
|
+
*
|
|
76
|
+
* @returns A partial or error response object if the call is blocked or
|
|
77
|
+
* awaiting confirmation, or `undefined` to allow execution to proceed.
|
|
78
|
+
*/
|
|
63
79
|
async beforeToolCallback({
|
|
64
80
|
tool,
|
|
65
81
|
toolArgs,
|
|
@@ -41,19 +41,30 @@ class InMemoryRunner extends import_runner.Runner {
|
|
|
41
41
|
* Creates a new InMemoryRunner instance.
|
|
42
42
|
*
|
|
43
43
|
* @param params The configuration for the runner.
|
|
44
|
+
* @param params.app An optional application instance to run.
|
|
44
45
|
* @param params.agent The root agent to run.
|
|
45
46
|
* @param params.appName The application name. Defaults to `'InMemoryRunner'`.
|
|
46
47
|
* @param params.plugins An optional list of plugins.
|
|
48
|
+
* @param params.resumabilityConfig An optional resumability configuration.
|
|
47
49
|
*/
|
|
48
50
|
constructor(params) {
|
|
49
|
-
|
|
51
|
+
var _a;
|
|
52
|
+
const {
|
|
53
|
+
agent,
|
|
54
|
+
appName = "InMemoryRunner",
|
|
55
|
+
plugins = [],
|
|
56
|
+
app,
|
|
57
|
+
resumabilityConfig
|
|
58
|
+
} = params;
|
|
50
59
|
super({
|
|
60
|
+
app,
|
|
51
61
|
appName,
|
|
52
62
|
agent,
|
|
53
63
|
plugins,
|
|
54
64
|
artifactService: new import_in_memory_artifact_service.InMemoryArtifactService(),
|
|
55
65
|
sessionService: new import_in_memory_session_service.InMemorySessionService(),
|
|
56
|
-
memoryService: new import_in_memory_memory_service.InMemoryMemoryService()
|
|
66
|
+
memoryService: new import_in_memory_memory_service.InMemoryMemoryService(),
|
|
67
|
+
resumabilityConfig: (_a = app == null ? void 0 : app.resumabilityConfig) != null ? _a : resumabilityConfig
|
|
57
68
|
});
|
|
58
69
|
}
|
|
59
70
|
}
|
|
@@ -25,14 +25,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
25
25
|
var runner_exports = {};
|
|
26
26
|
__export(runner_exports, {
|
|
27
27
|
Runner: () => Runner,
|
|
28
|
+
determineAgentForResumption: () => determineAgentForResumption,
|
|
29
|
+
findEventByLastFunctionResponseId: () => findEventByLastFunctionResponseId,
|
|
30
|
+
isRoutableLlmAgent: () => isRoutableLlmAgent,
|
|
28
31
|
isRunner: () => isRunner
|
|
29
32
|
});
|
|
30
33
|
module.exports = __toCommonJS(runner_exports);
|
|
31
34
|
var import_genai = require("@google/genai");
|
|
32
35
|
var import_api = require("@opentelemetry/api");
|
|
36
|
+
var import_functions = require("../agents/functions.js");
|
|
33
37
|
var import_invocation_context = require("../agents/invocation_context.js");
|
|
34
38
|
var import_llm_agent = require("../agents/llm_agent.js");
|
|
35
39
|
var import_run_config = require("../agents/run_config.js");
|
|
40
|
+
var import_scoped_artifact_service = require("../artifacts/scoped_artifact_service.js");
|
|
36
41
|
var import_built_in_code_executor = require("../code_executors/built_in_code_executor.js");
|
|
37
42
|
var import_event = require("../events/event.js");
|
|
38
43
|
var import_event_actions = require("../events/event_actions.js");
|
|
@@ -60,14 +65,24 @@ class Runner {
|
|
|
60
65
|
*/
|
|
61
66
|
constructor(input) {
|
|
62
67
|
this[_a] = true;
|
|
63
|
-
var _a2;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
69
|
+
const appName = (_b = (_a2 = input.app) == null ? void 0 : _a2.name) != null ? _b : input.appName;
|
|
70
|
+
const agent = (_d = (_c = input.app) == null ? void 0 : _c.rootAgent) != null ? _d : input.agent;
|
|
71
|
+
if (!agent) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
"agent must be provided in runner constructor (or via app.rootAgent)"
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
this.appName = appName;
|
|
77
|
+
this.agent = agent;
|
|
78
|
+
const appPlugins = (_f = (_e = input.app) == null ? void 0 : _e.plugins) != null ? _f : [];
|
|
79
|
+
const configPlugins = (_g = input.plugins) != null ? _g : [];
|
|
80
|
+
this.pluginManager = new import_plugin_manager.PluginManager([...appPlugins, ...configPlugins]);
|
|
67
81
|
this.artifactService = input.artifactService;
|
|
68
82
|
this.sessionService = input.sessionService;
|
|
69
83
|
this.memoryService = input.memoryService;
|
|
70
84
|
this.credentialService = input.credentialService;
|
|
85
|
+
this.resumabilityConfig = (_i = (_h = input.app) == null ? void 0 : _h.resumabilityConfig) != null ? _i : input.resumabilityConfig;
|
|
71
86
|
}
|
|
72
87
|
/**
|
|
73
88
|
* Runs the agent with a new, ephemeral session.
|
|
@@ -117,6 +132,9 @@ class Runner {
|
|
|
117
132
|
const { userId, sessionId, stateDelta } = params;
|
|
118
133
|
const runConfig = (0, import_run_config.createRunConfig)(params.runConfig);
|
|
119
134
|
let newMessage = params.newMessage;
|
|
135
|
+
if (newMessage && !newMessage.role) {
|
|
136
|
+
newMessage.role = "user";
|
|
137
|
+
}
|
|
120
138
|
const span = import_tracing.tracer.startSpan("invocation");
|
|
121
139
|
const ctx = import_api.trace.setSpan(import_api.context.active(), span);
|
|
122
140
|
try {
|
|
@@ -136,7 +154,7 @@ class Runner {
|
|
|
136
154
|
if (!session) {
|
|
137
155
|
if (!this.appName) {
|
|
138
156
|
throw new Error(
|
|
139
|
-
`Session lookup failed: appName must be provided in runner constructor`
|
|
157
|
+
`Session lookup failed: appName must be provided in runner constructor (or via app.name)`
|
|
140
158
|
);
|
|
141
159
|
}
|
|
142
160
|
throw new Error(`Session not found: ${sessionId}`);
|
|
@@ -153,7 +171,12 @@ class Runner {
|
|
|
153
171
|
}
|
|
154
172
|
}
|
|
155
173
|
const invocationContext = new import_invocation_context.InvocationContext({
|
|
156
|
-
artifactService: this.artifactService
|
|
174
|
+
artifactService: this.artifactService ? new import_scoped_artifact_service.ScopedArtifactService(
|
|
175
|
+
this.artifactService,
|
|
176
|
+
this.appName,
|
|
177
|
+
userId,
|
|
178
|
+
sessionId
|
|
179
|
+
) : void 0,
|
|
157
180
|
sessionService: this.sessionService,
|
|
158
181
|
memoryService: this.memoryService,
|
|
159
182
|
credentialService: this.credentialService,
|
|
@@ -280,6 +303,11 @@ class Runner {
|
|
|
280
303
|
if (!this.artifactService || !((_a2 = message.parts) == null ? void 0 : _a2.length)) {
|
|
281
304
|
return;
|
|
282
305
|
}
|
|
306
|
+
const sessionKey = {
|
|
307
|
+
appName: this.appName,
|
|
308
|
+
userId,
|
|
309
|
+
sessionId
|
|
310
|
+
};
|
|
283
311
|
for (let i = 0; i < message.parts.length; i++) {
|
|
284
312
|
const part = message.parts[i];
|
|
285
313
|
if (!part.inlineData) {
|
|
@@ -287,9 +315,7 @@ class Runner {
|
|
|
287
315
|
}
|
|
288
316
|
const fileName = `artifact_${invocationId}_${i}`;
|
|
289
317
|
await this.artifactService.saveArtifact({
|
|
290
|
-
|
|
291
|
-
userId,
|
|
292
|
-
sessionId,
|
|
318
|
+
...sessionKey,
|
|
293
319
|
filename: fileName,
|
|
294
320
|
artifact: part
|
|
295
321
|
});
|
|
@@ -302,86 +328,78 @@ class Runner {
|
|
|
302
328
|
* Determines the next agent to run to continue the session. This is primarily
|
|
303
329
|
* used for session resumption.
|
|
304
330
|
*/
|
|
305
|
-
|
|
306
|
-
|
|
331
|
+
/**
|
|
332
|
+
* Determines the next agent to run to continue the session. This is primarily
|
|
333
|
+
* used for session resumption across tool and LRO boundaries.
|
|
334
|
+
*/
|
|
307
335
|
determineAgentForResumption(session, rootAgent) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
import_logger.logger.info("event:", JSON.stringify(session.events[i]));
|
|
314
|
-
const event2 = session.events[i];
|
|
315
|
-
if (event2.author === "user" || !event2.author) {
|
|
316
|
-
continue;
|
|
317
|
-
}
|
|
318
|
-
if (event2.author === rootAgent.name) {
|
|
319
|
-
return rootAgent;
|
|
320
|
-
}
|
|
321
|
-
const agent = rootAgent.findSubAgent(event2.author);
|
|
322
|
-
if (!agent) {
|
|
323
|
-
import_logger.logger.warn(
|
|
324
|
-
`Event from an unknown agent: ${event2.author}, event id: ${event2.id}`
|
|
325
|
-
);
|
|
326
|
-
continue;
|
|
327
|
-
}
|
|
328
|
-
if (this.isRoutableLlmAgent(agent)) {
|
|
329
|
-
return agent;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
return rootAgent;
|
|
336
|
+
return determineAgentForResumption(
|
|
337
|
+
session,
|
|
338
|
+
rootAgent,
|
|
339
|
+
this.resumabilityConfig
|
|
340
|
+
);
|
|
333
341
|
}
|
|
334
342
|
/**
|
|
335
343
|
* Whether the agent to run can transfer to any other agent in the agent tree.
|
|
336
344
|
*
|
|
337
|
-
* An agent is transferable if:
|
|
338
|
-
* - It is an instance of `LlmAgent`.
|
|
339
|
-
* - All its ancestors are also transferable (i.e., they have
|
|
340
|
-
* `disallowTransferToParent` set to false).
|
|
341
|
-
*
|
|
342
345
|
* @param agentToRun The agent to check for transferability.
|
|
343
346
|
* @returns True if the agent can transfer, False otherwise.
|
|
344
347
|
*/
|
|
345
348
|
isRoutableLlmAgent(agentToRun) {
|
|
346
|
-
|
|
347
|
-
while (agent) {
|
|
348
|
-
if (!(0, import_llm_agent.isLlmAgent)(agent)) {
|
|
349
|
-
return false;
|
|
350
|
-
}
|
|
351
|
-
if (agent.disallowTransferToParent) {
|
|
352
|
-
return false;
|
|
353
|
-
}
|
|
354
|
-
agent = agent.parentAgent;
|
|
355
|
-
}
|
|
356
|
-
return true;
|
|
349
|
+
return isRoutableLlmAgent(agentToRun);
|
|
357
350
|
}
|
|
358
351
|
// TODO - b/425992518: Implement runLive and related methods.
|
|
359
352
|
}
|
|
360
|
-
function
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
353
|
+
function determineAgentForResumption(session, rootAgent, resumabilityConfig) {
|
|
354
|
+
const event = findEventByLastFunctionResponseId(session.events);
|
|
355
|
+
const isResumable = Boolean(resumabilityConfig == null ? void 0 : resumabilityConfig.isResumable);
|
|
356
|
+
if (event && event.author && isResumable) {
|
|
357
|
+
const resumedAgent = rootAgent.findAgent(event.author);
|
|
358
|
+
if (resumedAgent) {
|
|
359
|
+
return resumedAgent;
|
|
360
|
+
}
|
|
361
|
+
import_logger.logger.warn(
|
|
362
|
+
`Function response from an unknown agent: ${event.author}, event id: ${event.id}`
|
|
363
|
+
);
|
|
371
364
|
}
|
|
372
|
-
for (let i = events.length -
|
|
373
|
-
|
|
374
|
-
const
|
|
375
|
-
if (!
|
|
365
|
+
for (let i = session.events.length - 1; i >= 0; i--) {
|
|
366
|
+
import_logger.logger.debug("event:", JSON.stringify(session.events[i]));
|
|
367
|
+
const event2 = session.events[i];
|
|
368
|
+
if (event2.author === "user" || !event2.author) {
|
|
376
369
|
continue;
|
|
377
370
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
371
|
+
if (event2.author === rootAgent.name) {
|
|
372
|
+
return rootAgent;
|
|
373
|
+
}
|
|
374
|
+
const agent = rootAgent.findSubAgent(event2.author);
|
|
375
|
+
if (!agent) {
|
|
376
|
+
import_logger.logger.warn(
|
|
377
|
+
`Event from an unknown agent: ${event2.author}, event id: ${event2.id}`
|
|
378
|
+
);
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
if (isRoutableLlmAgent(agent)) {
|
|
382
|
+
return agent;
|
|
382
383
|
}
|
|
383
384
|
}
|
|
384
|
-
return
|
|
385
|
+
return rootAgent;
|
|
386
|
+
}
|
|
387
|
+
function isRoutableLlmAgent(agentToRun) {
|
|
388
|
+
let agent = agentToRun;
|
|
389
|
+
while (agent) {
|
|
390
|
+
if (!(0, import_llm_agent.isLlmAgent)(agent)) {
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
if (agent.disallowTransferToParent) {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
agent = agent.parentAgent;
|
|
397
|
+
}
|
|
398
|
+
return true;
|
|
399
|
+
}
|
|
400
|
+
function findEventByLastFunctionResponseId(events) {
|
|
401
|
+
var _a2;
|
|
402
|
+
return (_a2 = (0, import_functions.findMatchingFunctionCall)(events)) != null ? _a2 : null;
|
|
385
403
|
}
|
|
386
404
|
function getAllToolsets(agent) {
|
|
387
405
|
const toolsets = [];
|
|
@@ -406,5 +424,8 @@ function getAllToolsets(agent) {
|
|
|
406
424
|
// Annotate the CommonJS export names for ESM import in node:
|
|
407
425
|
0 && (module.exports = {
|
|
408
426
|
Runner,
|
|
427
|
+
determineAgentForResumption,
|
|
428
|
+
findEventByLastFunctionResponseId,
|
|
429
|
+
isRoutableLlmAgent,
|
|
409
430
|
isRunner
|
|
410
431
|
});
|
|
@@ -26,7 +26,8 @@ var base_session_service_exports = {};
|
|
|
26
26
|
__export(base_session_service_exports, {
|
|
27
27
|
BaseSessionService: () => BaseSessionService,
|
|
28
28
|
mergeStates: () => mergeStates,
|
|
29
|
-
trimTempDeltaState: () => trimTempDeltaState
|
|
29
|
+
trimTempDeltaState: () => trimTempDeltaState,
|
|
30
|
+
trimTempState: () => trimTempState
|
|
30
31
|
});
|
|
31
32
|
module.exports = __toCommonJS(base_session_service_exports);
|
|
32
33
|
var import_lodash_es = require("lodash-es");
|
|
@@ -69,7 +70,12 @@ class BaseSessionService {
|
|
|
69
70
|
}
|
|
70
71
|
event = trimTempDeltaState(event);
|
|
71
72
|
this.updateSessionState({ session, event });
|
|
72
|
-
session.events.
|
|
73
|
+
const index = session.events.findIndex((e) => e.id === event.id);
|
|
74
|
+
if (index >= 0) {
|
|
75
|
+
session.events[index] = event;
|
|
76
|
+
} else {
|
|
77
|
+
session.events.push(event);
|
|
78
|
+
}
|
|
73
79
|
return event;
|
|
74
80
|
}
|
|
75
81
|
/**
|
|
@@ -103,6 +109,15 @@ function trimTempDeltaState(event) {
|
|
|
103
109
|
event.actions.stateDelta = filteredStateDelta;
|
|
104
110
|
return event;
|
|
105
111
|
}
|
|
112
|
+
function trimTempState(state) {
|
|
113
|
+
const filteredState = {};
|
|
114
|
+
for (const [key, value] of Object.entries(state)) {
|
|
115
|
+
if (!key.startsWith(import_state.State.TEMP_PREFIX)) {
|
|
116
|
+
filteredState[key] = value;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return filteredState;
|
|
120
|
+
}
|
|
106
121
|
function mergeStates(appState = {}, userState = {}, sessionState = {}) {
|
|
107
122
|
const merged = (0, import_lodash_es.cloneDeep)(sessionState);
|
|
108
123
|
for (const [k, v] of Object.entries(appState)) {
|
|
@@ -117,5 +132,6 @@ function mergeStates(appState = {}, userState = {}, sessionState = {}) {
|
|
|
117
132
|
0 && (module.exports = {
|
|
118
133
|
BaseSessionService,
|
|
119
134
|
mergeStates,
|
|
120
|
-
trimTempDeltaState
|
|
135
|
+
trimTempDeltaState,
|
|
136
|
+
trimTempState
|
|
121
137
|
});
|
|
@@ -119,7 +119,7 @@ class DatabaseSessionService extends import_base_session_service.BaseSessionServ
|
|
|
119
119
|
appStateDelta[key.replace(import_state.State.APP_PREFIX, "")] = value;
|
|
120
120
|
} else if (key.startsWith(import_state.State.USER_PREFIX)) {
|
|
121
121
|
userStateDelta[key.replace(import_state.State.USER_PREFIX, "")] = value;
|
|
122
|
-
} else {
|
|
122
|
+
} else if (!key.startsWith(import_state.State.TEMP_PREFIX)) {
|
|
123
123
|
sessionState[key] = value;
|
|
124
124
|
}
|
|
125
125
|
}
|
|
@@ -368,7 +368,7 @@ class DatabaseSessionService extends import_base_session_service.BaseSessionServ
|
|
|
368
368
|
appDelta[key.replace(import_state.State.APP_PREFIX, "")] = value;
|
|
369
369
|
} else if (key.startsWith(import_state.State.USER_PREFIX)) {
|
|
370
370
|
userDelta[key.replace(import_state.State.USER_PREFIX, "")] = value;
|
|
371
|
-
} else {
|
|
371
|
+
} else if (!key.startsWith(import_state.State.TEMP_PREFIX)) {
|
|
372
372
|
sessionDelta[key] = value;
|
|
373
373
|
}
|
|
374
374
|
}
|
|
@@ -382,16 +382,28 @@ class DatabaseSessionService extends import_base_session_service.BaseSessionServ
|
|
|
382
382
|
storageSession.state = { ...storageSession.state, ...sessionDelta };
|
|
383
383
|
}
|
|
384
384
|
}
|
|
385
|
-
const
|
|
385
|
+
const existingStorageEvent = await txEm.findOne(import_schema.StorageEvent, {
|
|
386
386
|
id: trimmedEvent.id,
|
|
387
387
|
appName: session.appName,
|
|
388
388
|
userId: session.userId,
|
|
389
|
-
sessionId: session.id
|
|
390
|
-
invocationId: trimmedEvent.invocationId,
|
|
391
|
-
timestamp: new Date(trimmedEvent.timestamp),
|
|
392
|
-
eventData: trimmedEvent
|
|
389
|
+
sessionId: session.id
|
|
393
390
|
});
|
|
394
|
-
|
|
391
|
+
if (existingStorageEvent) {
|
|
392
|
+
existingStorageEvent.eventData = trimmedEvent;
|
|
393
|
+
existingStorageEvent.timestamp = new Date(trimmedEvent.timestamp);
|
|
394
|
+
txEm.persist(existingStorageEvent);
|
|
395
|
+
} else {
|
|
396
|
+
const newStorageEvent = txEm.create(import_schema.StorageEvent, {
|
|
397
|
+
id: trimmedEvent.id,
|
|
398
|
+
appName: session.appName,
|
|
399
|
+
userId: session.userId,
|
|
400
|
+
sessionId: session.id,
|
|
401
|
+
invocationId: trimmedEvent.invocationId,
|
|
402
|
+
timestamp: new Date(trimmedEvent.timestamp),
|
|
403
|
+
eventData: trimmedEvent
|
|
404
|
+
});
|
|
405
|
+
txEm.persist(newStorageEvent);
|
|
406
|
+
}
|
|
395
407
|
await txEm.commit();
|
|
396
408
|
storageSession.updateTime = new Date(event.timestamp);
|
|
397
409
|
const newMergedState = (0, import_base_session_service.mergeStates)(
|
|
@@ -400,7 +412,12 @@ class DatabaseSessionService extends import_base_session_service.BaseSessionServ
|
|
|
400
412
|
storageSession.state
|
|
401
413
|
);
|
|
402
414
|
session.state = newMergedState;
|
|
403
|
-
session.events.
|
|
415
|
+
const index = session.events.findIndex((e) => e.id === event.id);
|
|
416
|
+
if (index >= 0) {
|
|
417
|
+
session.events[index] = event;
|
|
418
|
+
} else {
|
|
419
|
+
session.events.push(event);
|
|
420
|
+
}
|
|
404
421
|
session.lastUpdateTime = storageSession.updateTime.getTime();
|
|
405
422
|
});
|
|
406
423
|
return event;
|
|
@@ -35,6 +35,7 @@ __export(schema_exports, {
|
|
|
35
35
|
ENTITIES: () => ENTITIES,
|
|
36
36
|
SCHEMA_VERSION_1_JSON: () => SCHEMA_VERSION_1_JSON,
|
|
37
37
|
SCHEMA_VERSION_KEY: () => SCHEMA_VERSION_KEY,
|
|
38
|
+
STORAGE_KEY_COLUMN_LENGTH: () => STORAGE_KEY_COLUMN_LENGTH,
|
|
38
39
|
StorageAppState: () => StorageAppState,
|
|
39
40
|
StorageEvent: () => StorageEvent,
|
|
40
41
|
StorageMetadata: () => StorageMetadata,
|
|
@@ -51,6 +52,7 @@ var import_event = require("../../events/event.js");
|
|
|
51
52
|
*/
|
|
52
53
|
const SCHEMA_VERSION_KEY = "schema_version";
|
|
53
54
|
const SCHEMA_VERSION_1_JSON = "1";
|
|
55
|
+
const STORAGE_KEY_COLUMN_LENGTH = 191;
|
|
54
56
|
class CamelCaseToSnakeCaseJsonType extends import_core.JsonType {
|
|
55
57
|
convertToDatabaseValue(value) {
|
|
56
58
|
return JSON.stringify((0, import_event.transformToSnakeCaseEvent)(value));
|
|
@@ -79,7 +81,11 @@ let StorageAppState = class {
|
|
|
79
81
|
}
|
|
80
82
|
};
|
|
81
83
|
__decorateClass([
|
|
82
|
-
(0, import_core.PrimaryKey)({
|
|
84
|
+
(0, import_core.PrimaryKey)({
|
|
85
|
+
type: "string",
|
|
86
|
+
fieldName: "app_name",
|
|
87
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
88
|
+
})
|
|
83
89
|
], StorageAppState.prototype, "appName", 2);
|
|
84
90
|
__decorateClass([
|
|
85
91
|
(0, import_core.Property)({ type: "json" })
|
|
@@ -102,10 +108,18 @@ let StorageUserState = class {
|
|
|
102
108
|
}
|
|
103
109
|
};
|
|
104
110
|
__decorateClass([
|
|
105
|
-
(0, import_core.PrimaryKey)({
|
|
111
|
+
(0, import_core.PrimaryKey)({
|
|
112
|
+
type: "string",
|
|
113
|
+
fieldName: "app_name",
|
|
114
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
115
|
+
})
|
|
106
116
|
], StorageUserState.prototype, "appName", 2);
|
|
107
117
|
__decorateClass([
|
|
108
|
-
(0, import_core.PrimaryKey)({
|
|
118
|
+
(0, import_core.PrimaryKey)({
|
|
119
|
+
type: "string",
|
|
120
|
+
fieldName: "user_id",
|
|
121
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
122
|
+
})
|
|
109
123
|
], StorageUserState.prototype, "userId", 2);
|
|
110
124
|
__decorateClass([
|
|
111
125
|
(0, import_core.Property)({ type: "json" })
|
|
@@ -129,13 +143,21 @@ let StorageSession = class {
|
|
|
129
143
|
}
|
|
130
144
|
};
|
|
131
145
|
__decorateClass([
|
|
132
|
-
(0, import_core.PrimaryKey)({ type: "string" })
|
|
146
|
+
(0, import_core.PrimaryKey)({ type: "string", length: STORAGE_KEY_COLUMN_LENGTH })
|
|
133
147
|
], StorageSession.prototype, "id", 2);
|
|
134
148
|
__decorateClass([
|
|
135
|
-
(0, import_core.PrimaryKey)({
|
|
149
|
+
(0, import_core.PrimaryKey)({
|
|
150
|
+
type: "string",
|
|
151
|
+
fieldName: "app_name",
|
|
152
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
153
|
+
})
|
|
136
154
|
], StorageSession.prototype, "appName", 2);
|
|
137
155
|
__decorateClass([
|
|
138
|
-
(0, import_core.PrimaryKey)({
|
|
156
|
+
(0, import_core.PrimaryKey)({
|
|
157
|
+
type: "string",
|
|
158
|
+
fieldName: "user_id",
|
|
159
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
160
|
+
})
|
|
139
161
|
], StorageSession.prototype, "userId", 2);
|
|
140
162
|
__decorateClass([
|
|
141
163
|
(0, import_core.Property)({ type: "json" })
|
|
@@ -161,16 +183,28 @@ import_core.PrimaryKey.name;
|
|
|
161
183
|
let StorageEvent = class {
|
|
162
184
|
};
|
|
163
185
|
__decorateClass([
|
|
164
|
-
(0, import_core.PrimaryKey)({ type: "string" })
|
|
186
|
+
(0, import_core.PrimaryKey)({ type: "string", length: STORAGE_KEY_COLUMN_LENGTH })
|
|
165
187
|
], StorageEvent.prototype, "id", 2);
|
|
166
188
|
__decorateClass([
|
|
167
|
-
(0, import_core.PrimaryKey)({
|
|
189
|
+
(0, import_core.PrimaryKey)({
|
|
190
|
+
type: "string",
|
|
191
|
+
fieldName: "app_name",
|
|
192
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
193
|
+
})
|
|
168
194
|
], StorageEvent.prototype, "appName", 2);
|
|
169
195
|
__decorateClass([
|
|
170
|
-
(0, import_core.PrimaryKey)({
|
|
196
|
+
(0, import_core.PrimaryKey)({
|
|
197
|
+
type: "string",
|
|
198
|
+
fieldName: "user_id",
|
|
199
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
200
|
+
})
|
|
171
201
|
], StorageEvent.prototype, "userId", 2);
|
|
172
202
|
__decorateClass([
|
|
173
|
-
(0, import_core.PrimaryKey)({
|
|
203
|
+
(0, import_core.PrimaryKey)({
|
|
204
|
+
type: "string",
|
|
205
|
+
fieldName: "session_id",
|
|
206
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
207
|
+
})
|
|
174
208
|
], StorageEvent.prototype, "sessionId", 2);
|
|
175
209
|
__decorateClass([
|
|
176
210
|
(0, import_core.Property)({ type: "string", fieldName: "invocation_id" })
|
|
@@ -196,6 +230,7 @@ const ENTITIES = [
|
|
|
196
230
|
ENTITIES,
|
|
197
231
|
SCHEMA_VERSION_1_JSON,
|
|
198
232
|
SCHEMA_VERSION_KEY,
|
|
233
|
+
STORAGE_KEY_COLUMN_LENGTH,
|
|
199
234
|
StorageAppState,
|
|
200
235
|
StorageEvent,
|
|
201
236
|
StorageMetadata,
|
|
@@ -66,11 +66,12 @@ class InMemorySessionService extends import_base_session_service.BaseSessionServ
|
|
|
66
66
|
sessionId
|
|
67
67
|
}) {
|
|
68
68
|
var _a;
|
|
69
|
+
const filteredState = state ? (0, import_base_session_service.trimTempState)(state) : void 0;
|
|
69
70
|
const session = (0, import_session.createSession)({
|
|
70
71
|
id: sessionId || (0, import_env_aware_utils.randomUUID)(),
|
|
71
72
|
appName,
|
|
72
73
|
userId,
|
|
73
|
-
state,
|
|
74
|
+
state: filteredState,
|
|
74
75
|
events: [],
|
|
75
76
|
lastUpdateTime: Date.now()
|
|
76
77
|
});
|
|
@@ -33,7 +33,8 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
33
33
|
var vertex_ai_session_service_exports = {};
|
|
34
34
|
__export(vertex_ai_session_service_exports, {
|
|
35
35
|
VertexAiSessionService: () => VertexAiSessionService,
|
|
36
|
-
isVertexAiConnectionString: () => isVertexAiConnectionString
|
|
36
|
+
isVertexAiConnectionString: () => isVertexAiConnectionString,
|
|
37
|
+
quoteFilterLiteral: () => quoteFilterLiteral
|
|
37
38
|
});
|
|
38
39
|
module.exports = __toCommonJS(vertex_ai_session_service_exports);
|
|
39
40
|
var import_client = require("@google-cloud/vertexai/build/src/genai/client.js");
|
|
@@ -55,6 +56,10 @@ const HTTP_NOT_FOUND = 404;
|
|
|
55
56
|
function isVertexAiConnectionString(uri) {
|
|
56
57
|
return (uri == null ? void 0 : uri.startsWith("vertexai://")) || false;
|
|
57
58
|
}
|
|
59
|
+
function quoteFilterLiteral(value) {
|
|
60
|
+
const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
61
|
+
return `"${escaped}"`;
|
|
62
|
+
}
|
|
58
63
|
let VertexAiSessionService = class extends import_base_session_service.BaseSessionService {
|
|
59
64
|
constructor(options) {
|
|
60
65
|
super();
|
|
@@ -107,11 +112,12 @@ let VertexAiSessionService = class extends import_base_session_service.BaseSessi
|
|
|
107
112
|
}) {
|
|
108
113
|
var _a;
|
|
109
114
|
const reasoningEngineId = this.getReasoningEngineId(appName);
|
|
115
|
+
const filteredState = state ? (0, import_base_session_service.trimTempState)(state) : void 0;
|
|
110
116
|
let apiResponse = await this.sessions.createInternal({
|
|
111
117
|
name: `reasoningEngines/${reasoningEngineId}`,
|
|
112
118
|
userId,
|
|
113
119
|
config: {
|
|
114
|
-
...
|
|
120
|
+
...filteredState ? { sessionState: filteredState } : {},
|
|
115
121
|
...sessionId ? { sessionId } : {}
|
|
116
122
|
}
|
|
117
123
|
});
|
|
@@ -221,7 +227,7 @@ let VertexAiSessionService = class extends import_base_session_service.BaseSessi
|
|
|
221
227
|
const response = await this.sessions.listInternal({
|
|
222
228
|
name: `reasoningEngines/${reasoningEngineId}`,
|
|
223
229
|
config: {
|
|
224
|
-
...userId ? { filter: `user_id
|
|
230
|
+
...userId ? { filter: `user_id=${quoteFilterLiteral(userId)}` } : {},
|
|
225
231
|
...pageToken ? { pageToken } : {}
|
|
226
232
|
}
|
|
227
233
|
});
|
|
@@ -282,10 +288,19 @@ let VertexAiSessionService = class extends import_base_session_service.BaseSessi
|
|
|
282
288
|
}
|
|
283
289
|
async deleteSession({
|
|
284
290
|
appName,
|
|
285
|
-
userId
|
|
291
|
+
userId,
|
|
286
292
|
sessionId
|
|
287
293
|
}) {
|
|
288
294
|
const reasoningEngineId = this.getReasoningEngineId(appName);
|
|
295
|
+
const session = await this.getSession({
|
|
296
|
+
appName,
|
|
297
|
+
userId,
|
|
298
|
+
sessionId,
|
|
299
|
+
config: { numRecentEvents: 0 }
|
|
300
|
+
});
|
|
301
|
+
if (!session) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
289
304
|
await this.sessions.delete({
|
|
290
305
|
name: `reasoningEngines/${reasoningEngineId}/sessions/${sessionId}`
|
|
291
306
|
});
|
|
@@ -424,5 +439,6 @@ function _fromApiEvent(apiEventObj) {
|
|
|
424
439
|
// Annotate the CommonJS export names for ESM import in node:
|
|
425
440
|
0 && (module.exports = {
|
|
426
441
|
VertexAiSessionService,
|
|
427
|
-
isVertexAiConnectionString
|
|
442
|
+
isVertexAiConnectionString,
|
|
443
|
+
quoteFilterLiteral
|
|
428
444
|
});
|