@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
|
@@ -16,6 +16,11 @@ var PolicyOutcome = /* @__PURE__ */ ((PolicyOutcome2) => {
|
|
|
16
16
|
return PolicyOutcome2;
|
|
17
17
|
})(PolicyOutcome || {});
|
|
18
18
|
class InMemoryPolicyEngine {
|
|
19
|
+
/**
|
|
20
|
+
* Always returns {@link PolicyOutcome.ALLOW} for every tool call.
|
|
21
|
+
*
|
|
22
|
+
* @returns A promise resolving to an ALLOW result.
|
|
23
|
+
*/
|
|
19
24
|
async evaluate() {
|
|
20
25
|
return Promise.resolve({
|
|
21
26
|
outcome: "ALLOW" /* ALLOW */,
|
|
@@ -24,11 +29,22 @@ class InMemoryPolicyEngine {
|
|
|
24
29
|
}
|
|
25
30
|
}
|
|
26
31
|
class SecurityPlugin extends BasePlugin {
|
|
32
|
+
/**
|
|
33
|
+
* @param params - Optional configuration. Defaults to {@link InMemoryPolicyEngine}
|
|
34
|
+
* when no policy engine is provided.
|
|
35
|
+
*/
|
|
27
36
|
constructor(params) {
|
|
28
37
|
var _a;
|
|
29
38
|
super("security_plugin");
|
|
30
39
|
this.policyEngine = (_a = params == null ? void 0 : params.policyEngine) != null ? _a : new InMemoryPolicyEngine();
|
|
31
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Intercepts tool calls, evaluating them against the policy engine before
|
|
43
|
+
* execution and handling confirmation flows for calls that require it.
|
|
44
|
+
*
|
|
45
|
+
* @returns A partial or error response object if the call is blocked or
|
|
46
|
+
* awaiting confirmation, or `undefined` to allow execution to proceed.
|
|
47
|
+
*/
|
|
32
48
|
async beforeToolCallback({
|
|
33
49
|
tool,
|
|
34
50
|
toolArgs,
|
|
@@ -14,19 +14,30 @@ class InMemoryRunner extends Runner {
|
|
|
14
14
|
* Creates a new InMemoryRunner instance.
|
|
15
15
|
*
|
|
16
16
|
* @param params The configuration for the runner.
|
|
17
|
+
* @param params.app An optional application instance to run.
|
|
17
18
|
* @param params.agent The root agent to run.
|
|
18
19
|
* @param params.appName The application name. Defaults to `'InMemoryRunner'`.
|
|
19
20
|
* @param params.plugins An optional list of plugins.
|
|
21
|
+
* @param params.resumabilityConfig An optional resumability configuration.
|
|
20
22
|
*/
|
|
21
23
|
constructor(params) {
|
|
22
|
-
|
|
24
|
+
var _a;
|
|
25
|
+
const {
|
|
26
|
+
agent,
|
|
27
|
+
appName = "InMemoryRunner",
|
|
28
|
+
plugins = [],
|
|
29
|
+
app,
|
|
30
|
+
resumabilityConfig
|
|
31
|
+
} = params;
|
|
23
32
|
super({
|
|
33
|
+
app,
|
|
24
34
|
appName,
|
|
25
35
|
agent,
|
|
26
36
|
plugins,
|
|
27
37
|
artifactService: new InMemoryArtifactService(),
|
|
28
38
|
sessionService: new InMemorySessionService(),
|
|
29
|
-
memoryService: new InMemoryMemoryService()
|
|
39
|
+
memoryService: new InMemoryMemoryService(),
|
|
40
|
+
resumabilityConfig: (_a = app == null ? void 0 : app.resumabilityConfig) != null ? _a : resumabilityConfig
|
|
30
41
|
});
|
|
31
42
|
}
|
|
32
43
|
}
|
|
@@ -8,17 +8,19 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
8
8
|
var _a;
|
|
9
9
|
import { createPartFromText } from "@google/genai";
|
|
10
10
|
import { context, trace } from "@opentelemetry/api";
|
|
11
|
+
import { findMatchingFunctionCall } from "../agents/functions.js";
|
|
11
12
|
import {
|
|
12
13
|
InvocationContext,
|
|
13
14
|
newInvocationContextId
|
|
14
15
|
} from "../agents/invocation_context.js";
|
|
15
16
|
import { isLlmAgent } from "../agents/llm_agent.js";
|
|
16
17
|
import { createRunConfig } from "../agents/run_config.js";
|
|
18
|
+
import { ScopedArtifactService } from "../artifacts/scoped_artifact_service.js";
|
|
17
19
|
import {
|
|
18
20
|
BuiltInCodeExecutor,
|
|
19
21
|
isBuiltInCodeExecutor
|
|
20
22
|
} from "../code_executors/built_in_code_executor.js";
|
|
21
|
-
import { createEvent
|
|
23
|
+
import { createEvent } from "../events/event.js";
|
|
22
24
|
import { createEventActions } from "../events/event_actions.js";
|
|
23
25
|
import { PluginManager } from "../plugins/plugin_manager.js";
|
|
24
26
|
import {
|
|
@@ -41,14 +43,24 @@ class Runner {
|
|
|
41
43
|
*/
|
|
42
44
|
constructor(input) {
|
|
43
45
|
this[_a] = true;
|
|
44
|
-
var _a2;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
47
|
+
const appName = (_b = (_a2 = input.app) == null ? void 0 : _a2.name) != null ? _b : input.appName;
|
|
48
|
+
const agent = (_d = (_c = input.app) == null ? void 0 : _c.rootAgent) != null ? _d : input.agent;
|
|
49
|
+
if (!agent) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
"agent must be provided in runner constructor (or via app.rootAgent)"
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
this.appName = appName;
|
|
55
|
+
this.agent = agent;
|
|
56
|
+
const appPlugins = (_f = (_e = input.app) == null ? void 0 : _e.plugins) != null ? _f : [];
|
|
57
|
+
const configPlugins = (_g = input.plugins) != null ? _g : [];
|
|
58
|
+
this.pluginManager = new PluginManager([...appPlugins, ...configPlugins]);
|
|
48
59
|
this.artifactService = input.artifactService;
|
|
49
60
|
this.sessionService = input.sessionService;
|
|
50
61
|
this.memoryService = input.memoryService;
|
|
51
62
|
this.credentialService = input.credentialService;
|
|
63
|
+
this.resumabilityConfig = (_i = (_h = input.app) == null ? void 0 : _h.resumabilityConfig) != null ? _i : input.resumabilityConfig;
|
|
52
64
|
}
|
|
53
65
|
/**
|
|
54
66
|
* Runs the agent with a new, ephemeral session.
|
|
@@ -98,6 +110,9 @@ class Runner {
|
|
|
98
110
|
const { userId, sessionId, stateDelta } = params;
|
|
99
111
|
const runConfig = createRunConfig(params.runConfig);
|
|
100
112
|
let newMessage = params.newMessage;
|
|
113
|
+
if (newMessage && !newMessage.role) {
|
|
114
|
+
newMessage.role = "user";
|
|
115
|
+
}
|
|
101
116
|
const span = tracer.startSpan("invocation");
|
|
102
117
|
const ctx = trace.setSpan(context.active(), span);
|
|
103
118
|
try {
|
|
@@ -117,7 +132,7 @@ class Runner {
|
|
|
117
132
|
if (!session) {
|
|
118
133
|
if (!this.appName) {
|
|
119
134
|
throw new Error(
|
|
120
|
-
`Session lookup failed: appName must be provided in runner constructor`
|
|
135
|
+
`Session lookup failed: appName must be provided in runner constructor (or via app.name)`
|
|
121
136
|
);
|
|
122
137
|
}
|
|
123
138
|
throw new Error(`Session not found: ${sessionId}`);
|
|
@@ -134,7 +149,12 @@ class Runner {
|
|
|
134
149
|
}
|
|
135
150
|
}
|
|
136
151
|
const invocationContext = new InvocationContext({
|
|
137
|
-
artifactService: this.artifactService
|
|
152
|
+
artifactService: this.artifactService ? new ScopedArtifactService(
|
|
153
|
+
this.artifactService,
|
|
154
|
+
this.appName,
|
|
155
|
+
userId,
|
|
156
|
+
sessionId
|
|
157
|
+
) : void 0,
|
|
138
158
|
sessionService: this.sessionService,
|
|
139
159
|
memoryService: this.memoryService,
|
|
140
160
|
credentialService: this.credentialService,
|
|
@@ -261,6 +281,11 @@ class Runner {
|
|
|
261
281
|
if (!this.artifactService || !((_a2 = message.parts) == null ? void 0 : _a2.length)) {
|
|
262
282
|
return;
|
|
263
283
|
}
|
|
284
|
+
const sessionKey = {
|
|
285
|
+
appName: this.appName,
|
|
286
|
+
userId,
|
|
287
|
+
sessionId
|
|
288
|
+
};
|
|
264
289
|
for (let i = 0; i < message.parts.length; i++) {
|
|
265
290
|
const part = message.parts[i];
|
|
266
291
|
if (!part.inlineData) {
|
|
@@ -268,9 +293,7 @@ class Runner {
|
|
|
268
293
|
}
|
|
269
294
|
const fileName = `artifact_${invocationId}_${i}`;
|
|
270
295
|
await this.artifactService.saveArtifact({
|
|
271
|
-
|
|
272
|
-
userId,
|
|
273
|
-
sessionId,
|
|
296
|
+
...sessionKey,
|
|
274
297
|
filename: fileName,
|
|
275
298
|
artifact: part
|
|
276
299
|
});
|
|
@@ -283,86 +306,78 @@ class Runner {
|
|
|
283
306
|
* Determines the next agent to run to continue the session. This is primarily
|
|
284
307
|
* used for session resumption.
|
|
285
308
|
*/
|
|
286
|
-
|
|
287
|
-
|
|
309
|
+
/**
|
|
310
|
+
* Determines the next agent to run to continue the session. This is primarily
|
|
311
|
+
* used for session resumption across tool and LRO boundaries.
|
|
312
|
+
*/
|
|
288
313
|
determineAgentForResumption(session, rootAgent) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
logger.info("event:", JSON.stringify(session.events[i]));
|
|
295
|
-
const event2 = session.events[i];
|
|
296
|
-
if (event2.author === "user" || !event2.author) {
|
|
297
|
-
continue;
|
|
298
|
-
}
|
|
299
|
-
if (event2.author === rootAgent.name) {
|
|
300
|
-
return rootAgent;
|
|
301
|
-
}
|
|
302
|
-
const agent = rootAgent.findSubAgent(event2.author);
|
|
303
|
-
if (!agent) {
|
|
304
|
-
logger.warn(
|
|
305
|
-
`Event from an unknown agent: ${event2.author}, event id: ${event2.id}`
|
|
306
|
-
);
|
|
307
|
-
continue;
|
|
308
|
-
}
|
|
309
|
-
if (this.isRoutableLlmAgent(agent)) {
|
|
310
|
-
return agent;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
return rootAgent;
|
|
314
|
+
return determineAgentForResumption(
|
|
315
|
+
session,
|
|
316
|
+
rootAgent,
|
|
317
|
+
this.resumabilityConfig
|
|
318
|
+
);
|
|
314
319
|
}
|
|
315
320
|
/**
|
|
316
321
|
* Whether the agent to run can transfer to any other agent in the agent tree.
|
|
317
322
|
*
|
|
318
|
-
* An agent is transferable if:
|
|
319
|
-
* - It is an instance of `LlmAgent`.
|
|
320
|
-
* - All its ancestors are also transferable (i.e., they have
|
|
321
|
-
* `disallowTransferToParent` set to false).
|
|
322
|
-
*
|
|
323
323
|
* @param agentToRun The agent to check for transferability.
|
|
324
324
|
* @returns True if the agent can transfer, False otherwise.
|
|
325
325
|
*/
|
|
326
326
|
isRoutableLlmAgent(agentToRun) {
|
|
327
|
-
|
|
328
|
-
while (agent) {
|
|
329
|
-
if (!isLlmAgent(agent)) {
|
|
330
|
-
return false;
|
|
331
|
-
}
|
|
332
|
-
if (agent.disallowTransferToParent) {
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
335
|
-
agent = agent.parentAgent;
|
|
336
|
-
}
|
|
337
|
-
return true;
|
|
327
|
+
return isRoutableLlmAgent(agentToRun);
|
|
338
328
|
}
|
|
339
329
|
// TODO - b/425992518: Implement runLive and related methods.
|
|
340
330
|
}
|
|
341
|
-
function
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
331
|
+
function determineAgentForResumption(session, rootAgent, resumabilityConfig) {
|
|
332
|
+
const event = findEventByLastFunctionResponseId(session.events);
|
|
333
|
+
const isResumable = Boolean(resumabilityConfig == null ? void 0 : resumabilityConfig.isResumable);
|
|
334
|
+
if (event && event.author && isResumable) {
|
|
335
|
+
const resumedAgent = rootAgent.findAgent(event.author);
|
|
336
|
+
if (resumedAgent) {
|
|
337
|
+
return resumedAgent;
|
|
338
|
+
}
|
|
339
|
+
logger.warn(
|
|
340
|
+
`Function response from an unknown agent: ${event.author}, event id: ${event.id}`
|
|
341
|
+
);
|
|
352
342
|
}
|
|
353
|
-
for (let i = events.length -
|
|
354
|
-
|
|
355
|
-
const
|
|
356
|
-
if (!
|
|
343
|
+
for (let i = session.events.length - 1; i >= 0; i--) {
|
|
344
|
+
logger.debug("event:", JSON.stringify(session.events[i]));
|
|
345
|
+
const event2 = session.events[i];
|
|
346
|
+
if (event2.author === "user" || !event2.author) {
|
|
357
347
|
continue;
|
|
358
348
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
349
|
+
if (event2.author === rootAgent.name) {
|
|
350
|
+
return rootAgent;
|
|
351
|
+
}
|
|
352
|
+
const agent = rootAgent.findSubAgent(event2.author);
|
|
353
|
+
if (!agent) {
|
|
354
|
+
logger.warn(
|
|
355
|
+
`Event from an unknown agent: ${event2.author}, event id: ${event2.id}`
|
|
356
|
+
);
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
if (isRoutableLlmAgent(agent)) {
|
|
360
|
+
return agent;
|
|
363
361
|
}
|
|
364
362
|
}
|
|
365
|
-
return
|
|
363
|
+
return rootAgent;
|
|
364
|
+
}
|
|
365
|
+
function isRoutableLlmAgent(agentToRun) {
|
|
366
|
+
let agent = agentToRun;
|
|
367
|
+
while (agent) {
|
|
368
|
+
if (!isLlmAgent(agent)) {
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
if (agent.disallowTransferToParent) {
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
agent = agent.parentAgent;
|
|
375
|
+
}
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
function findEventByLastFunctionResponseId(events) {
|
|
379
|
+
var _a2;
|
|
380
|
+
return (_a2 = findMatchingFunctionCall(events)) != null ? _a2 : null;
|
|
366
381
|
}
|
|
367
382
|
function getAllToolsets(agent) {
|
|
368
383
|
const toolsets = [];
|
|
@@ -386,5 +401,8 @@ function getAllToolsets(agent) {
|
|
|
386
401
|
}
|
|
387
402
|
export {
|
|
388
403
|
Runner,
|
|
404
|
+
determineAgentForResumption,
|
|
405
|
+
findEventByLastFunctionResponseId,
|
|
406
|
+
isRoutableLlmAgent,
|
|
389
407
|
isRunner
|
|
390
408
|
};
|
|
@@ -40,7 +40,12 @@ class BaseSessionService {
|
|
|
40
40
|
}
|
|
41
41
|
event = trimTempDeltaState(event);
|
|
42
42
|
this.updateSessionState({ session, event });
|
|
43
|
-
session.events.
|
|
43
|
+
const index = session.events.findIndex((e) => e.id === event.id);
|
|
44
|
+
if (index >= 0) {
|
|
45
|
+
session.events[index] = event;
|
|
46
|
+
} else {
|
|
47
|
+
session.events.push(event);
|
|
48
|
+
}
|
|
44
49
|
return event;
|
|
45
50
|
}
|
|
46
51
|
/**
|
|
@@ -74,6 +79,15 @@ function trimTempDeltaState(event) {
|
|
|
74
79
|
event.actions.stateDelta = filteredStateDelta;
|
|
75
80
|
return event;
|
|
76
81
|
}
|
|
82
|
+
function trimTempState(state) {
|
|
83
|
+
const filteredState = {};
|
|
84
|
+
for (const [key, value] of Object.entries(state)) {
|
|
85
|
+
if (!key.startsWith(State.TEMP_PREFIX)) {
|
|
86
|
+
filteredState[key] = value;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return filteredState;
|
|
90
|
+
}
|
|
77
91
|
function mergeStates(appState = {}, userState = {}, sessionState = {}) {
|
|
78
92
|
const merged = cloneDeep(sessionState);
|
|
79
93
|
for (const [k, v] of Object.entries(appState)) {
|
|
@@ -87,5 +101,6 @@ function mergeStates(appState = {}, userState = {}, sessionState = {}) {
|
|
|
87
101
|
export {
|
|
88
102
|
BaseSessionService,
|
|
89
103
|
mergeStates,
|
|
90
|
-
trimTempDeltaState
|
|
104
|
+
trimTempDeltaState,
|
|
105
|
+
trimTempState
|
|
91
106
|
};
|
|
@@ -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
|
}
|
|
@@ -357,7 +357,7 @@ class DatabaseSessionService extends BaseSessionService {
|
|
|
357
357
|
appDelta[key.replace(State.APP_PREFIX, "")] = value;
|
|
358
358
|
} else if (key.startsWith(State.USER_PREFIX)) {
|
|
359
359
|
userDelta[key.replace(State.USER_PREFIX, "")] = value;
|
|
360
|
-
} else {
|
|
360
|
+
} else if (!key.startsWith(State.TEMP_PREFIX)) {
|
|
361
361
|
sessionDelta[key] = value;
|
|
362
362
|
}
|
|
363
363
|
}
|
|
@@ -371,16 +371,28 @@ class DatabaseSessionService extends BaseSessionService {
|
|
|
371
371
|
storageSession.state = { ...storageSession.state, ...sessionDelta };
|
|
372
372
|
}
|
|
373
373
|
}
|
|
374
|
-
const
|
|
374
|
+
const existingStorageEvent = await txEm.findOne(StorageEvent, {
|
|
375
375
|
id: trimmedEvent.id,
|
|
376
376
|
appName: session.appName,
|
|
377
377
|
userId: session.userId,
|
|
378
|
-
sessionId: session.id
|
|
379
|
-
invocationId: trimmedEvent.invocationId,
|
|
380
|
-
timestamp: new Date(trimmedEvent.timestamp),
|
|
381
|
-
eventData: trimmedEvent
|
|
378
|
+
sessionId: session.id
|
|
382
379
|
});
|
|
383
|
-
|
|
380
|
+
if (existingStorageEvent) {
|
|
381
|
+
existingStorageEvent.eventData = trimmedEvent;
|
|
382
|
+
existingStorageEvent.timestamp = new Date(trimmedEvent.timestamp);
|
|
383
|
+
txEm.persist(existingStorageEvent);
|
|
384
|
+
} else {
|
|
385
|
+
const newStorageEvent = txEm.create(StorageEvent, {
|
|
386
|
+
id: trimmedEvent.id,
|
|
387
|
+
appName: session.appName,
|
|
388
|
+
userId: session.userId,
|
|
389
|
+
sessionId: session.id,
|
|
390
|
+
invocationId: trimmedEvent.invocationId,
|
|
391
|
+
timestamp: new Date(trimmedEvent.timestamp),
|
|
392
|
+
eventData: trimmedEvent
|
|
393
|
+
});
|
|
394
|
+
txEm.persist(newStorageEvent);
|
|
395
|
+
}
|
|
384
396
|
await txEm.commit();
|
|
385
397
|
storageSession.updateTime = new Date(event.timestamp);
|
|
386
398
|
const newMergedState = mergeStates(
|
|
@@ -389,7 +401,12 @@ class DatabaseSessionService extends BaseSessionService {
|
|
|
389
401
|
storageSession.state
|
|
390
402
|
);
|
|
391
403
|
session.state = newMergedState;
|
|
392
|
-
session.events.
|
|
404
|
+
const index = session.events.findIndex((e) => e.id === event.id);
|
|
405
|
+
if (index >= 0) {
|
|
406
|
+
session.events[index] = event;
|
|
407
|
+
} else {
|
|
408
|
+
session.events.push(event);
|
|
409
|
+
}
|
|
393
410
|
session.lastUpdateTime = storageSession.updateTime.getTime();
|
|
394
411
|
});
|
|
395
412
|
return event;
|
|
@@ -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
|
});
|
|
@@ -22,7 +22,8 @@ import { logger } from "../utils/logger.js";
|
|
|
22
22
|
import { getExpressModeApiKey } from "../utils/vertex_ai_utils.js";
|
|
23
23
|
import { partialCopy } from "../utils/partial_copy.js";
|
|
24
24
|
import {
|
|
25
|
-
BaseSessionService
|
|
25
|
+
BaseSessionService,
|
|
26
|
+
trimTempState
|
|
26
27
|
} from "./base_session_service.js";
|
|
27
28
|
import { createSession } from "./session.js";
|
|
28
29
|
const DEFAULT_MAX_ATTEMPTS = 30;
|
|
@@ -31,6 +32,10 @@ const HTTP_NOT_FOUND = 404;
|
|
|
31
32
|
function isVertexAiConnectionString(uri) {
|
|
32
33
|
return (uri == null ? void 0 : uri.startsWith("vertexai://")) || false;
|
|
33
34
|
}
|
|
35
|
+
function quoteFilterLiteral(value) {
|
|
36
|
+
const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
37
|
+
return `"${escaped}"`;
|
|
38
|
+
}
|
|
34
39
|
let VertexAiSessionService = class extends BaseSessionService {
|
|
35
40
|
constructor(options) {
|
|
36
41
|
super();
|
|
@@ -83,11 +88,12 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
83
88
|
}) {
|
|
84
89
|
var _a;
|
|
85
90
|
const reasoningEngineId = this.getReasoningEngineId(appName);
|
|
91
|
+
const filteredState = state ? trimTempState(state) : void 0;
|
|
86
92
|
let apiResponse = await this.sessions.createInternal({
|
|
87
93
|
name: `reasoningEngines/${reasoningEngineId}`,
|
|
88
94
|
userId,
|
|
89
95
|
config: {
|
|
90
|
-
...
|
|
96
|
+
...filteredState ? { sessionState: filteredState } : {},
|
|
91
97
|
...sessionId ? { sessionId } : {}
|
|
92
98
|
}
|
|
93
99
|
});
|
|
@@ -197,7 +203,7 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
197
203
|
const response = await this.sessions.listInternal({
|
|
198
204
|
name: `reasoningEngines/${reasoningEngineId}`,
|
|
199
205
|
config: {
|
|
200
|
-
...userId ? { filter: `user_id
|
|
206
|
+
...userId ? { filter: `user_id=${quoteFilterLiteral(userId)}` } : {},
|
|
201
207
|
...pageToken ? { pageToken } : {}
|
|
202
208
|
}
|
|
203
209
|
});
|
|
@@ -258,10 +264,19 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
258
264
|
}
|
|
259
265
|
async deleteSession({
|
|
260
266
|
appName,
|
|
261
|
-
userId
|
|
267
|
+
userId,
|
|
262
268
|
sessionId
|
|
263
269
|
}) {
|
|
264
270
|
const reasoningEngineId = this.getReasoningEngineId(appName);
|
|
271
|
+
const session = await this.getSession({
|
|
272
|
+
appName,
|
|
273
|
+
userId,
|
|
274
|
+
sessionId,
|
|
275
|
+
config: { numRecentEvents: 0 }
|
|
276
|
+
});
|
|
277
|
+
if (!session) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
265
280
|
await this.sessions.delete({
|
|
266
281
|
name: `reasoningEngines/${reasoningEngineId}/sessions/${sessionId}`
|
|
267
282
|
});
|
|
@@ -399,5 +414,6 @@ function _fromApiEvent(apiEventObj) {
|
|
|
399
414
|
}
|
|
400
415
|
export {
|
|
401
416
|
VertexAiSessionService,
|
|
402
|
-
isVertexAiConnectionString
|
|
417
|
+
isVertexAiConnectionString,
|
|
418
|
+
quoteFilterLiteral
|
|
403
419
|
};
|