@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.
Files changed (294) hide show
  1. package/dist/cjs/agents/active_streaming_tool.js +6 -1
  2. package/dist/cjs/agents/base_agent.js +19 -1
  3. package/dist/cjs/agents/context.js +1 -11
  4. package/dist/cjs/agents/functions.js +35 -16
  5. package/dist/cjs/agents/instructions.js +99 -33
  6. package/dist/cjs/agents/invocation_context.js +2 -6
  7. package/dist/cjs/agents/llm_agent.js +60 -11
  8. package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  9. package/dist/cjs/agents/processors/basic_llm_request_processor.js +8 -1
  10. package/dist/cjs/agents/processors/code_execution_request_processor.js +0 -3
  11. package/dist/cjs/agents/processors/content_processor_utils.js +51 -25
  12. package/dist/cjs/agents/processors/content_request_processor.js +7 -0
  13. package/dist/cjs/agents/processors/context_compactor_request_processor.js +16 -2
  14. package/dist/cjs/agents/processors/identity_llm_request_processor.js +7 -0
  15. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +5 -0
  16. package/dist/cjs/agents/processors/interactions_request_processor.js +63 -0
  17. package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  18. package/dist/cjs/agents/processors/tool_filter_request_processor.js +7 -1
  19. package/dist/cjs/apps/app.js +79 -0
  20. package/dist/cjs/apps/resumability_config.js +44 -0
  21. package/dist/cjs/artifacts/file_artifact_service.js +14 -1
  22. package/dist/cjs/artifacts/gcs_artifact_service.js +57 -15
  23. package/dist/cjs/artifacts/in_memory_artifact_service.js +5 -1
  24. package/dist/cjs/artifacts/scoped_artifact_service.js +101 -0
  25. package/dist/cjs/artifacts/session_artifact_service.js +27 -0
  26. package/dist/cjs/auth/auth_preprocessor.js +12 -10
  27. package/dist/cjs/auth/oauth2/oauth2_discovery.js +17 -5
  28. package/dist/cjs/auth/oauth2/oauth2_utils.js +12 -1
  29. package/dist/cjs/code_executors/code_executor_context.js +7 -7
  30. package/dist/cjs/common.js +86 -0
  31. package/dist/cjs/context/agent_controlled_context_compactor.js +109 -0
  32. package/dist/cjs/context/summarizers/llm_summarizer.js +11 -0
  33. package/dist/cjs/context/token_based_context_compactor.js +43 -11
  34. package/dist/cjs/context/trajectory_thought_pruning_compactor.js +71 -0
  35. package/dist/cjs/events/event.js +25 -1
  36. package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
  37. package/dist/cjs/models/gemini_llm_connection.js +62 -19
  38. package/dist/cjs/models/google_llm.js +51 -18
  39. package/dist/cjs/models/interactions_utils.js +732 -0
  40. package/dist/cjs/plugins/base_plugin.js +1 -0
  41. package/dist/cjs/plugins/security_plugin.js +16 -0
  42. package/dist/cjs/runner/in_memory_runner.js +13 -2
  43. package/dist/cjs/runner/runner.js +93 -72
  44. package/dist/cjs/sessions/base_session_service.js +19 -3
  45. package/dist/cjs/sessions/database_session_service.js +26 -9
  46. package/dist/cjs/sessions/db/schema.js +45 -10
  47. package/dist/cjs/sessions/in_memory_session_service.js +2 -1
  48. package/dist/cjs/sessions/vertex_ai_session_service.js +21 -5
  49. package/dist/cjs/skills/gcp_skill_registry.js +104 -0
  50. package/dist/cjs/skills/loader.js +67 -2
  51. package/dist/cjs/skills/skill_registry.js +27 -0
  52. package/dist/cjs/tools/base_toolset.js +1 -1
  53. package/dist/cjs/tools/consolidate_context_tool.js +79 -0
  54. package/dist/cjs/tools/forwarding_artifact_service.js +16 -28
  55. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +232 -0
  56. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +224 -0
  57. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +117 -0
  58. package/dist/cjs/tools/openapi_tool/openapi_toolset.js +133 -0
  59. package/dist/cjs/tools/openapi_tool/rest_api_tool.js +256 -0
  60. package/dist/cjs/tools/skill/load_skill_resource_tool.js +25 -3
  61. package/dist/cjs/tools/skill/load_skill_tool.js +12 -1
  62. package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -1
  63. package/dist/cjs/tools/skill/search_skills_tool.js +108 -0
  64. package/dist/cjs/tools/skill/skill_toolset.js +40 -5
  65. package/dist/cjs/utils/async_hooks_shim.js +52 -0
  66. package/dist/cjs/utils/async_queue.js +88 -0
  67. package/dist/cjs/utils/case_utils.js +53 -0
  68. package/dist/cjs/utils/client_labels.js +41 -3
  69. package/dist/cjs/utils/env_aware_utils.js +14 -1
  70. package/dist/cjs/utils/live_connection_utils.js +284 -0
  71. package/dist/cjs/utils/model_name.js +9 -0
  72. package/dist/cjs/utils/streaming_utils.js +18 -11
  73. package/dist/cjs/utils/task.js +62 -0
  74. package/dist/cjs/version.js +1 -1
  75. package/dist/esm/agents/active_streaming_tool.js +6 -1
  76. package/dist/esm/agents/base_agent.js +19 -1
  77. package/dist/esm/agents/context.js +1 -11
  78. package/dist/esm/agents/functions.js +36 -15
  79. package/dist/esm/agents/instructions.js +99 -33
  80. package/dist/esm/agents/invocation_context.js +2 -6
  81. package/dist/esm/agents/llm_agent.js +61 -11
  82. package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  83. package/dist/esm/agents/processors/basic_llm_request_processor.js +8 -1
  84. package/dist/esm/agents/processors/code_execution_request_processor.js +0 -3
  85. package/dist/esm/agents/processors/content_processor_utils.js +48 -24
  86. package/dist/esm/agents/processors/content_request_processor.js +7 -0
  87. package/dist/esm/agents/processors/context_compactor_request_processor.js +16 -2
  88. package/dist/esm/agents/processors/identity_llm_request_processor.js +7 -0
  89. package/dist/esm/agents/processors/instructions_llm_request_processor.js +5 -0
  90. package/dist/esm/agents/processors/interactions_request_processor.js +34 -0
  91. package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  92. package/dist/esm/agents/processors/tool_filter_request_processor.js +7 -1
  93. package/dist/esm/apps/app.js +49 -0
  94. package/dist/esm/apps/resumability_config.js +16 -0
  95. package/dist/esm/artifacts/file_artifact_service.js +14 -1
  96. package/dist/esm/artifacts/gcs_artifact_service.js +57 -15
  97. package/dist/esm/artifacts/in_memory_artifact_service.js +5 -1
  98. package/dist/esm/artifacts/scoped_artifact_service.js +73 -0
  99. package/dist/esm/artifacts/session_artifact_service.js +7 -0
  100. package/dist/esm/auth/auth_preprocessor.js +12 -10
  101. package/dist/esm/auth/oauth2/oauth2_discovery.js +14 -4
  102. package/dist/esm/auth/oauth2/oauth2_utils.js +12 -1
  103. package/dist/esm/code_executors/code_executor_context.js +7 -7
  104. package/dist/esm/common.js +75 -3
  105. package/dist/esm/context/agent_controlled_context_compactor.js +81 -0
  106. package/dist/esm/context/summarizers/llm_summarizer.js +11 -0
  107. package/dist/esm/context/token_based_context_compactor.js +43 -11
  108. package/dist/esm/context/trajectory_thought_pruning_compactor.js +43 -0
  109. package/dist/esm/events/event.js +23 -1
  110. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
  111. package/dist/esm/models/gemini_llm_connection.js +62 -19
  112. package/dist/esm/models/google_llm.js +49 -17
  113. package/dist/esm/models/interactions_utils.js +697 -0
  114. package/dist/esm/plugins/base_plugin.js +1 -0
  115. package/dist/esm/plugins/security_plugin.js +16 -0
  116. package/dist/esm/runner/in_memory_runner.js +13 -2
  117. package/dist/esm/runner/runner.js +91 -73
  118. package/dist/esm/sessions/base_session_service.js +17 -2
  119. package/dist/esm/sessions/database_session_service.js +26 -9
  120. package/dist/esm/sessions/db/schema.js +44 -10
  121. package/dist/esm/sessions/in_memory_session_service.js +4 -2
  122. package/dist/esm/sessions/vertex_ai_session_service.js +21 -5
  123. package/dist/esm/skills/gcp_skill_registry.js +78 -0
  124. package/dist/esm/skills/loader.js +66 -2
  125. package/dist/esm/skills/skill_registry.js +7 -0
  126. package/dist/esm/tools/base_toolset.js +1 -1
  127. package/dist/esm/tools/consolidate_context_tool.js +51 -0
  128. package/dist/esm/tools/forwarding_artifact_service.js +16 -28
  129. package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +206 -0
  130. package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
  131. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +91 -0
  132. package/dist/esm/tools/openapi_tool/openapi_toolset.js +97 -0
  133. package/dist/esm/tools/openapi_tool/rest_api_tool.js +229 -0
  134. package/dist/esm/tools/skill/load_skill_resource_tool.js +25 -3
  135. package/dist/esm/tools/skill/load_skill_tool.js +12 -1
  136. package/dist/esm/tools/skill/run_skill_script_tool.js +12 -1
  137. package/dist/esm/tools/skill/search_skills_tool.js +82 -0
  138. package/dist/esm/tools/skill/skill_toolset.js +40 -5
  139. package/dist/esm/utils/async_hooks_shim.js +24 -0
  140. package/dist/esm/utils/async_queue.js +60 -0
  141. package/dist/esm/utils/case_utils.js +25 -0
  142. package/dist/esm/utils/client_labels.js +38 -2
  143. package/dist/esm/utils/env_aware_utils.js +14 -1
  144. package/dist/esm/utils/live_connection_utils.js +256 -0
  145. package/dist/esm/utils/model_name.js +8 -0
  146. package/dist/esm/utils/streaming_utils.js +18 -11
  147. package/dist/esm/utils/task.js +34 -0
  148. package/dist/esm/version.js +1 -1
  149. package/dist/types/a2a/a2a_remote_agent_utils.d.ts +29 -4
  150. package/dist/types/a2a/event_converter_utils.d.ts +14 -1
  151. package/dist/types/a2a/metadata_converter_utils.d.ts +18 -0
  152. package/dist/types/a2a/part_converter_utils.d.ts +51 -6
  153. package/dist/types/agents/active_streaming_tool.d.ts +3 -4
  154. package/dist/types/agents/functions.d.ts +12 -9
  155. package/dist/types/agents/invocation_context.d.ts +7 -12
  156. package/dist/types/agents/llm_agent.d.ts +14 -0
  157. package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +14 -0
  158. package/dist/types/agents/processors/basic_llm_request_processor.d.ts +7 -0
  159. package/dist/types/agents/processors/content_processor_utils.d.ts +34 -0
  160. package/dist/types/agents/processors/content_request_processor.d.ts +16 -0
  161. package/dist/types/agents/processors/context_compactor_request_processor.d.ts +12 -0
  162. package/dist/types/agents/processors/identity_llm_request_processor.d.ts +7 -0
  163. package/dist/types/agents/processors/interactions_request_processor.d.ts +17 -0
  164. package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +9 -1
  165. package/dist/types/agents/processors/tool_filter_request_processor.d.ts +12 -1
  166. package/dist/types/apps/app.d.ts +52 -0
  167. package/dist/types/apps/resumability_config.d.ts +27 -0
  168. package/dist/types/artifacts/base_artifact_service.d.ts +6 -36
  169. package/dist/types/artifacts/gcs_artifact_service.d.ts +2 -1
  170. package/dist/types/artifacts/scoped_artifact_service.d.ts +25 -0
  171. package/dist/types/artifacts/session_artifact_service.d.ts +25 -0
  172. package/dist/types/auth/oauth2/oauth2_discovery.d.ts +11 -0
  173. package/dist/types/common.d.ts +35 -4
  174. package/dist/types/context/agent_controlled_context_compactor.d.ts +24 -0
  175. package/dist/types/context/base_context_compactor.d.ts +3 -0
  176. package/dist/types/context/summarizers/llm_summarizer.d.ts +17 -0
  177. package/dist/types/context/token_based_context_compactor.d.ts +6 -1
  178. package/dist/types/context/trajectory_thought_pruning_compactor.d.ts +27 -0
  179. package/dist/types/events/event.d.ts +8 -0
  180. package/dist/types/events/event_actions.d.ts +1 -2
  181. package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +21 -2
  182. package/dist/types/models/base_llm_connection.d.ts +10 -0
  183. package/dist/types/models/gemini_llm_connection.d.ts +15 -4
  184. package/dist/types/models/google_llm.d.ts +15 -1
  185. package/dist/types/models/interactions_utils.d.ts +92 -0
  186. package/dist/types/models/llm_request.d.ts +4 -0
  187. package/dist/types/models/llm_response.d.ts +14 -1
  188. package/dist/types/plugins/base_plugin.d.ts +2 -1
  189. package/dist/types/plugins/security_plugin.d.ts +30 -0
  190. package/dist/types/runner/in_memory_runner.d.ts +7 -1
  191. package/dist/types/runner/runner.d.ts +43 -9
  192. package/dist/types/sessions/base_session_service.d.ts +7 -16
  193. package/dist/types/sessions/db/schema.d.ts +1 -0
  194. package/dist/types/sessions/session.d.ts +11 -0
  195. package/dist/types/sessions/vertex_ai_session_service.d.ts +9 -1
  196. package/dist/types/skills/gcp_skill_registry.d.ts +24 -0
  197. package/dist/types/skills/loader.d.ts +7 -0
  198. package/dist/types/skills/skill.d.ts +1 -1
  199. package/dist/types/skills/skill_registry.d.ts +29 -0
  200. package/dist/types/tools/consolidate_context_tool.d.ts +19 -0
  201. package/dist/types/tools/forwarding_artifact_service.d.ts +3 -2
  202. package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +34 -0
  203. package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +59 -0
  204. package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +23 -0
  205. package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +27 -0
  206. package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +50 -0
  207. package/dist/types/tools/skill/load_skill_resource_tool.d.ts +1 -1
  208. package/dist/types/tools/skill/search_skills_tool.d.ts +14 -0
  209. package/dist/types/tools/skill/skill_toolset.d.ts +5 -0
  210. package/dist/types/utils/async_hooks_shim.d.ts +10 -0
  211. package/dist/types/utils/async_queue.d.ts +18 -0
  212. package/dist/types/utils/case_utils.d.ts +12 -0
  213. package/dist/types/utils/client_labels.d.ts +10 -0
  214. package/dist/types/utils/env_aware_utils.d.ts +3 -3
  215. package/dist/types/utils/live_connection_utils.d.ts +30 -0
  216. package/dist/types/utils/model_name.d.ts +7 -0
  217. package/dist/types/utils/streaming_utils.d.ts +0 -1
  218. package/dist/types/utils/task.d.ts +24 -0
  219. package/dist/types/version.d.ts +1 -1
  220. package/dist/web/agents/active_streaming_tool.js +6 -1
  221. package/dist/web/agents/base_agent.js +31 -1
  222. package/dist/web/agents/context.js +1 -11
  223. package/dist/web/agents/functions.js +36 -15
  224. package/dist/web/agents/instructions.js +99 -33
  225. package/dist/web/agents/invocation_context.js +2 -6
  226. package/dist/web/agents/llm_agent.js +61 -11
  227. package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  228. package/dist/web/agents/processors/basic_llm_request_processor.js +8 -1
  229. package/dist/web/agents/processors/code_execution_request_processor.js +0 -3
  230. package/dist/web/agents/processors/content_processor_utils.js +66 -24
  231. package/dist/web/agents/processors/content_request_processor.js +7 -0
  232. package/dist/web/agents/processors/context_compactor_request_processor.js +16 -2
  233. package/dist/web/agents/processors/identity_llm_request_processor.js +7 -0
  234. package/dist/web/agents/processors/instructions_llm_request_processor.js +5 -0
  235. package/dist/web/agents/processors/interactions_request_processor.js +52 -0
  236. package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  237. package/dist/web/agents/processors/tool_filter_request_processor.js +7 -1
  238. package/dist/web/apps/app.js +49 -0
  239. package/dist/web/apps/resumability_config.js +31 -0
  240. package/dist/web/artifacts/file_artifact_service.js +14 -1
  241. package/dist/web/artifacts/gcs_artifact_service.js +55 -15
  242. package/dist/web/artifacts/in_memory_artifact_service.js +5 -1
  243. package/dist/web/artifacts/scoped_artifact_service.js +86 -0
  244. package/dist/web/artifacts/session_artifact_service.js +7 -0
  245. package/dist/web/auth/auth_preprocessor.js +12 -10
  246. package/dist/web/auth/oauth2/oauth2_discovery.js +14 -4
  247. package/dist/web/auth/oauth2/oauth2_utils.js +12 -1
  248. package/dist/web/code_executors/code_executor_context.js +7 -7
  249. package/dist/web/common.js +75 -3
  250. package/dist/web/context/agent_controlled_context_compactor.js +81 -0
  251. package/dist/web/context/summarizers/llm_summarizer.js +11 -0
  252. package/dist/web/context/token_based_context_compactor.js +43 -11
  253. package/dist/web/context/trajectory_thought_pruning_compactor.js +43 -0
  254. package/dist/web/events/event.js +21 -1
  255. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
  256. package/dist/web/models/gemini_llm_connection.js +75 -19
  257. package/dist/web/models/google_llm.js +80 -17
  258. package/dist/web/models/interactions_utils.js +728 -0
  259. package/dist/web/plugins/base_plugin.js +1 -0
  260. package/dist/web/plugins/security_plugin.js +16 -0
  261. package/dist/web/runner/in_memory_runner.js +13 -2
  262. package/dist/web/runner/runner.js +111 -75
  263. package/dist/web/sessions/base_session_service.js +17 -2
  264. package/dist/web/sessions/database_session_service.js +26 -9
  265. package/dist/web/sessions/db/schema.js +44 -10
  266. package/dist/web/sessions/in_memory_session_service.js +4 -2
  267. package/dist/web/sessions/vertex_ai_session_service.js +21 -5
  268. package/dist/web/skills/gcp_skill_registry.js +78 -0
  269. package/dist/web/skills/loader.js +66 -2
  270. package/dist/web/skills/skill_registry.js +7 -0
  271. package/dist/web/tools/base_toolset.js +1 -1
  272. package/dist/web/tools/consolidate_context_tool.js +51 -0
  273. package/dist/web/tools/forwarding_artifact_service.js +16 -28
  274. package/dist/web/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +221 -0
  275. package/dist/web/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
  276. package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +91 -0
  277. package/dist/web/tools/openapi_tool/openapi_toolset.js +97 -0
  278. package/dist/web/tools/openapi_tool/rest_api_tool.js +229 -0
  279. package/dist/web/tools/skill/load_skill_resource_tool.js +25 -3
  280. package/dist/web/tools/skill/load_skill_tool.js +12 -1
  281. package/dist/web/tools/skill/run_skill_script_tool.js +12 -1
  282. package/dist/web/tools/skill/search_skills_tool.js +82 -0
  283. package/dist/web/tools/skill/skill_toolset.js +40 -5
  284. package/dist/web/utils/async_hooks_shim.js +24 -0
  285. package/dist/web/utils/async_queue.js +60 -0
  286. package/dist/web/utils/case_utils.js +25 -0
  287. package/dist/web/utils/client_labels.js +38 -2
  288. package/dist/web/utils/env_aware_utils.js +14 -1
  289. package/dist/web/utils/live_connection_utils.js +254 -0
  290. package/dist/web/utils/model_name.js +8 -0
  291. package/dist/web/utils/streaming_utils.js +18 -11
  292. package/dist/web/utils/task.js +34 -0
  293. package/dist/web/version.js +1 -1
  294. package/package.json +4 -2
@@ -19,6 +19,7 @@ import { experimental } from "../utils/experimental.js";
19
19
  var ContextCompactionTrigger = /* @__PURE__ */ ((ContextCompactionTrigger2) => {
20
20
  ContextCompactionTrigger2["Manual"] = "Manual";
21
21
  ContextCompactionTrigger2["Auto"] = "Auto";
22
+ ContextCompactionTrigger2["AgentControlled"] = "AgentControlled";
22
23
  return ContextCompactionTrigger2;
23
24
  })(ContextCompactionTrigger || {});
24
25
  class BasePlugin {
@@ -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
- const { agent, appName = "InMemoryRunner", plugins = [] } = params;
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
  }
@@ -1,9 +1,28 @@
1
1
  import {createRequire as topLevelCreateRequire} from 'module';
2
2
  const require = topLevelCreateRequire(import.meta.url);
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
3
9
  var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
4
10
  var __typeError = (msg) => {
5
11
  throw TypeError(msg);
6
12
  };
13
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
+ var __spreadValues = (a, b) => {
15
+ for (var prop in b || (b = {}))
16
+ if (__hasOwnProp.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ if (__getOwnPropSymbols)
19
+ for (var prop of __getOwnPropSymbols(b)) {
20
+ if (__propIsEnum.call(b, prop))
21
+ __defNormalProp(a, prop, b[prop]);
22
+ }
23
+ return a;
24
+ };
25
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7
26
  var __await = function(promise, isYieldStar) {
8
27
  this[0] = promise;
9
28
  this[1] = isYieldStar;
@@ -56,17 +75,19 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
56
75
  var _a;
57
76
  import { createPartFromText } from "@google/genai";
58
77
  import { context, trace } from "@opentelemetry/api";
78
+ import { findMatchingFunctionCall } from "../agents/functions.js";
59
79
  import {
60
80
  InvocationContext,
61
81
  newInvocationContextId
62
82
  } from "../agents/invocation_context.js";
63
83
  import { isLlmAgent } from "../agents/llm_agent.js";
64
84
  import { createRunConfig } from "../agents/run_config.js";
85
+ import { ScopedArtifactService } from "../artifacts/scoped_artifact_service.js";
65
86
  import {
66
87
  BuiltInCodeExecutor,
67
88
  isBuiltInCodeExecutor
68
89
  } from "../code_executors/built_in_code_executor.js";
69
- import { createEvent, getFunctionCalls } from "../events/event.js";
90
+ import { createEvent } from "../events/event.js";
70
91
  import { createEventActions } from "../events/event_actions.js";
71
92
  import { PluginManager } from "../plugins/plugin_manager.js";
72
93
  import {
@@ -89,14 +110,24 @@ class Runner {
89
110
  */
90
111
  constructor(input) {
91
112
  this[_a] = true;
92
- var _a2;
93
- this.appName = input.appName;
94
- this.agent = input.agent;
95
- this.pluginManager = new PluginManager((_a2 = input.plugins) != null ? _a2 : []);
113
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
114
+ const appName = (_b = (_a2 = input.app) == null ? void 0 : _a2.name) != null ? _b : input.appName;
115
+ const agent = (_d = (_c = input.app) == null ? void 0 : _c.rootAgent) != null ? _d : input.agent;
116
+ if (!agent) {
117
+ throw new Error(
118
+ "agent must be provided in runner constructor (or via app.rootAgent)"
119
+ );
120
+ }
121
+ this.appName = appName;
122
+ this.agent = agent;
123
+ const appPlugins = (_f = (_e = input.app) == null ? void 0 : _e.plugins) != null ? _f : [];
124
+ const configPlugins = (_g = input.plugins) != null ? _g : [];
125
+ this.pluginManager = new PluginManager([...appPlugins, ...configPlugins]);
96
126
  this.artifactService = input.artifactService;
97
127
  this.sessionService = input.sessionService;
98
128
  this.memoryService = input.memoryService;
99
129
  this.credentialService = input.credentialService;
130
+ this.resumabilityConfig = (_i = (_h = input.app) == null ? void 0 : _h.resumabilityConfig) != null ? _i : input.resumabilityConfig;
100
131
  }
101
132
  /**
102
133
  * Runs the agent with a new, ephemeral session.
@@ -149,6 +180,9 @@ class Runner {
149
180
  const { userId, sessionId, stateDelta } = params;
150
181
  const runConfig = createRunConfig(params.runConfig);
151
182
  let newMessage = params.newMessage;
183
+ if (newMessage && !newMessage.role) {
184
+ newMessage.role = "user";
185
+ }
152
186
  const span = tracer.startSpan("invocation");
153
187
  const ctx = trace.setSpan(context.active(), span);
154
188
  try {
@@ -169,7 +203,7 @@ class Runner {
169
203
  if (!session) {
170
204
  if (!this.appName) {
171
205
  throw new Error(
172
- "Session lookup failed: appName must be provided in runner constructor"
206
+ "Session lookup failed: appName must be provided in runner constructor (or via app.name)"
173
207
  );
174
208
  }
175
209
  throw new Error("Session not found: ".concat(sessionId));
@@ -186,7 +220,12 @@ class Runner {
186
220
  }
187
221
  }
188
222
  const invocationContext = new InvocationContext({
189
- artifactService: this.artifactService,
223
+ artifactService: this.artifactService ? new ScopedArtifactService(
224
+ this.artifactService,
225
+ this.appName,
226
+ userId,
227
+ sessionId
228
+ ) : void 0,
190
229
  sessionService: this.sessionService,
191
230
  memoryService: this.memoryService,
192
231
  credentialService: this.credentialService,
@@ -327,19 +366,21 @@ class Runner {
327
366
  if (!this.artifactService || !((_a2 = message.parts) == null ? void 0 : _a2.length)) {
328
367
  return;
329
368
  }
369
+ const sessionKey = {
370
+ appName: this.appName,
371
+ userId,
372
+ sessionId
373
+ };
330
374
  for (let i = 0; i < message.parts.length; i++) {
331
375
  const part = message.parts[i];
332
376
  if (!part.inlineData) {
333
377
  continue;
334
378
  }
335
379
  const fileName = "artifact_".concat(invocationId, "_").concat(i);
336
- await this.artifactService.saveArtifact({
337
- appName: this.appName,
338
- userId,
339
- sessionId,
380
+ await this.artifactService.saveArtifact(__spreadProps(__spreadValues({}, sessionKey), {
340
381
  filename: fileName,
341
382
  artifact: part
342
- });
383
+ }));
343
384
  message.parts[i] = createPartFromText(
344
385
  "Uploaded file: ".concat(fileName, ". It is saved into artifacts")
345
386
  );
@@ -349,86 +390,78 @@ class Runner {
349
390
  * Determines the next agent to run to continue the session. This is primarily
350
391
  * used for session resumption.
351
392
  */
352
- // TODO - b/425992518: This is where LRO integration should happen.
353
- // Needs clean up before we can generalize it.
393
+ /**
394
+ * Determines the next agent to run to continue the session. This is primarily
395
+ * used for session resumption across tool and LRO boundaries.
396
+ */
354
397
  determineAgentForResumption(session, rootAgent) {
355
- const event = findEventByLastFunctionResponseId(session.events);
356
- if (event && event.author) {
357
- return rootAgent.findAgent(event.author) || rootAgent;
358
- }
359
- for (let i = session.events.length - 1; i >= 0; i--) {
360
- logger.info("event:", JSON.stringify(session.events[i]));
361
- const event2 = session.events[i];
362
- if (event2.author === "user" || !event2.author) {
363
- continue;
364
- }
365
- if (event2.author === rootAgent.name) {
366
- return rootAgent;
367
- }
368
- const agent = rootAgent.findSubAgent(event2.author);
369
- if (!agent) {
370
- logger.warn(
371
- "Event from an unknown agent: ".concat(event2.author, ", event id: ").concat(event2.id)
372
- );
373
- continue;
374
- }
375
- if (this.isRoutableLlmAgent(agent)) {
376
- return agent;
377
- }
378
- }
379
- return rootAgent;
398
+ return determineAgentForResumption(
399
+ session,
400
+ rootAgent,
401
+ this.resumabilityConfig
402
+ );
380
403
  }
381
404
  /**
382
405
  * Whether the agent to run can transfer to any other agent in the agent tree.
383
406
  *
384
- * An agent is transferable if:
385
- * - It is an instance of `LlmAgent`.
386
- * - All its ancestors are also transferable (i.e., they have
387
- * `disallowTransferToParent` set to false).
388
- *
389
407
  * @param agentToRun The agent to check for transferability.
390
408
  * @returns True if the agent can transfer, False otherwise.
391
409
  */
392
410
  isRoutableLlmAgent(agentToRun) {
393
- let agent = agentToRun;
394
- while (agent) {
395
- if (!isLlmAgent(agent)) {
396
- return false;
397
- }
398
- if (agent.disallowTransferToParent) {
399
- return false;
400
- }
401
- agent = agent.parentAgent;
402
- }
403
- return true;
411
+ return isRoutableLlmAgent(agentToRun);
404
412
  }
405
413
  // TODO - b/425992518: Implement runLive and related methods.
406
414
  }
407
- function findEventByLastFunctionResponseId(events) {
408
- var _a2, _b, _c, _d;
409
- if (!events.length) {
410
- return null;
411
- }
412
- const lastEvent = events[events.length - 1];
413
- const functionCallId = (_d = (_c = (_b = (_a2 = lastEvent.content) == null ? void 0 : _a2.parts) == null ? void 0 : _b.find(
414
- (part) => part.functionResponse
415
- )) == null ? void 0 : _c.functionResponse) == null ? void 0 : _d.id;
416
- if (!functionCallId) {
417
- return null;
415
+ function determineAgentForResumption(session, rootAgent, resumabilityConfig) {
416
+ const event = findEventByLastFunctionResponseId(session.events);
417
+ const isResumable = Boolean(resumabilityConfig == null ? void 0 : resumabilityConfig.isResumable);
418
+ if (event && event.author && isResumable) {
419
+ const resumedAgent = rootAgent.findAgent(event.author);
420
+ if (resumedAgent) {
421
+ return resumedAgent;
422
+ }
423
+ logger.warn(
424
+ "Function response from an unknown agent: ".concat(event.author, ", event id: ").concat(event.id)
425
+ );
418
426
  }
419
- for (let i = events.length - 2; i >= 0; i--) {
420
- const event = events[i];
421
- const functionCalls = getFunctionCalls(event);
422
- if (!functionCalls) {
427
+ for (let i = session.events.length - 1; i >= 0; i--) {
428
+ logger.debug("event:", JSON.stringify(session.events[i]));
429
+ const event2 = session.events[i];
430
+ if (event2.author === "user" || !event2.author) {
423
431
  continue;
424
432
  }
425
- for (const functionCall of functionCalls) {
426
- if (functionCall.id === functionCallId) {
427
- return event;
428
- }
433
+ if (event2.author === rootAgent.name) {
434
+ return rootAgent;
435
+ }
436
+ const agent = rootAgent.findSubAgent(event2.author);
437
+ if (!agent) {
438
+ logger.warn(
439
+ "Event from an unknown agent: ".concat(event2.author, ", event id: ").concat(event2.id)
440
+ );
441
+ continue;
442
+ }
443
+ if (isRoutableLlmAgent(agent)) {
444
+ return agent;
429
445
  }
430
446
  }
431
- return null;
447
+ return rootAgent;
448
+ }
449
+ function isRoutableLlmAgent(agentToRun) {
450
+ let agent = agentToRun;
451
+ while (agent) {
452
+ if (!isLlmAgent(agent)) {
453
+ return false;
454
+ }
455
+ if (agent.disallowTransferToParent) {
456
+ return false;
457
+ }
458
+ agent = agent.parentAgent;
459
+ }
460
+ return true;
461
+ }
462
+ function findEventByLastFunctionResponseId(events) {
463
+ var _a2;
464
+ return (_a2 = findMatchingFunctionCall(events)) != null ? _a2 : null;
432
465
  }
433
466
  function getAllToolsets(agent) {
434
467
  const toolsets = [];
@@ -452,5 +485,8 @@ function getAllToolsets(agent) {
452
485
  }
453
486
  export {
454
487
  Runner,
488
+ determineAgentForResumption,
489
+ findEventByLastFunctionResponseId,
490
+ isRoutableLlmAgent,
455
491
  isRunner
456
492
  };
@@ -40,7 +40,12 @@ class BaseSessionService {
40
40
  }
41
41
  event = trimTempDeltaState(event);
42
42
  this.updateSessionState({ session, event });
43
- session.events.push(event);
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
  };
@@ -126,7 +126,7 @@ class DatabaseSessionService extends BaseSessionService {
126
126
  appStateDelta[key.replace(State.APP_PREFIX, "")] = value;
127
127
  } else if (key.startsWith(State.USER_PREFIX)) {
128
128
  userStateDelta[key.replace(State.USER_PREFIX, "")] = value;
129
- } else {
129
+ } else if (!key.startsWith(State.TEMP_PREFIX)) {
130
130
  sessionState[key] = value;
131
131
  }
132
132
  }
@@ -375,7 +375,7 @@ class DatabaseSessionService extends BaseSessionService {
375
375
  appDelta[key.replace(State.APP_PREFIX, "")] = value;
376
376
  } else if (key.startsWith(State.USER_PREFIX)) {
377
377
  userDelta[key.replace(State.USER_PREFIX, "")] = value;
378
- } else {
378
+ } else if (!key.startsWith(State.TEMP_PREFIX)) {
379
379
  sessionDelta[key] = value;
380
380
  }
381
381
  }
@@ -389,16 +389,28 @@ class DatabaseSessionService extends BaseSessionService {
389
389
  storageSession.state = __spreadValues(__spreadValues({}, storageSession.state), sessionDelta);
390
390
  }
391
391
  }
392
- const newStorageEvent = txEm.create(StorageEvent, {
392
+ const existingStorageEvent = await txEm.findOne(StorageEvent, {
393
393
  id: trimmedEvent.id,
394
394
  appName: session.appName,
395
395
  userId: session.userId,
396
- sessionId: session.id,
397
- invocationId: trimmedEvent.invocationId,
398
- timestamp: new Date(trimmedEvent.timestamp),
399
- eventData: trimmedEvent
396
+ sessionId: session.id
400
397
  });
401
- txEm.persist(newStorageEvent);
398
+ if (existingStorageEvent) {
399
+ existingStorageEvent.eventData = trimmedEvent;
400
+ existingStorageEvent.timestamp = new Date(trimmedEvent.timestamp);
401
+ txEm.persist(existingStorageEvent);
402
+ } else {
403
+ const newStorageEvent = txEm.create(StorageEvent, {
404
+ id: trimmedEvent.id,
405
+ appName: session.appName,
406
+ userId: session.userId,
407
+ sessionId: session.id,
408
+ invocationId: trimmedEvent.invocationId,
409
+ timestamp: new Date(trimmedEvent.timestamp),
410
+ eventData: trimmedEvent
411
+ });
412
+ txEm.persist(newStorageEvent);
413
+ }
402
414
  await txEm.commit();
403
415
  storageSession.updateTime = new Date(event.timestamp);
404
416
  const newMergedState = mergeStates(
@@ -407,7 +419,12 @@ class DatabaseSessionService extends BaseSessionService {
407
419
  storageSession.state
408
420
  );
409
421
  session.state = newMergedState;
410
- session.events.push(event);
422
+ const index = session.events.findIndex((e) => e.id === event.id);
423
+ if (index >= 0) {
424
+ session.events[index] = event;
425
+ } else {
426
+ session.events.push(event);
427
+ }
411
428
  session.lastUpdateTime = storageSession.updateTime.getTime();
412
429
  });
413
430
  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({ type: "string", fieldName: "app_name" })
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({ type: "string", fieldName: "app_name" })
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({ type: "string", fieldName: "user_id" })
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({ type: "string", fieldName: "app_name" })
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({ type: "string", fieldName: "user_id" })
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({ type: "string", fieldName: "app_name" })
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({ type: "string", fieldName: "user_id" })
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({ type: "string", fieldName: "session_id" })
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
  });
@@ -40,7 +40,8 @@ import { logger } from "../utils/logger.js";
40
40
  import { getExpressModeApiKey } from "../utils/vertex_ai_utils.js";
41
41
  import { partialCopy } from "../utils/partial_copy.js";
42
42
  import {
43
- BaseSessionService
43
+ BaseSessionService,
44
+ trimTempState
44
45
  } from "./base_session_service.js";
45
46
  import { createSession } from "./session.js";
46
47
  const DEFAULT_MAX_ATTEMPTS = 30;
@@ -49,6 +50,10 @@ const HTTP_NOT_FOUND = 404;
49
50
  function isVertexAiConnectionString(uri) {
50
51
  return (uri == null ? void 0 : uri.startsWith("vertexai://")) || false;
51
52
  }
53
+ function quoteFilterLiteral(value) {
54
+ const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
55
+ return '"'.concat(escaped, '"');
56
+ }
52
57
  let VertexAiSessionService = class extends BaseSessionService {
53
58
  constructor(options) {
54
59
  super();
@@ -101,10 +106,11 @@ let VertexAiSessionService = class extends BaseSessionService {
101
106
  }) {
102
107
  var _a;
103
108
  const reasoningEngineId = this.getReasoningEngineId(appName);
109
+ const filteredState = state ? trimTempState(state) : void 0;
104
110
  let apiResponse = await this.sessions.createInternal({
105
111
  name: "reasoningEngines/".concat(reasoningEngineId),
106
112
  userId,
107
- config: __spreadValues(__spreadValues({}, state ? { sessionState: state } : {}), sessionId ? { sessionId } : {})
113
+ config: __spreadValues(__spreadValues({}, filteredState ? { sessionState: filteredState } : {}), sessionId ? { sessionId } : {})
108
114
  });
109
115
  const operationName = apiResponse.name;
110
116
  let attempts = 0;
@@ -211,7 +217,7 @@ let VertexAiSessionService = class extends BaseSessionService {
211
217
  do {
212
218
  const response = await this.sessions.listInternal({
213
219
  name: "reasoningEngines/".concat(reasoningEngineId),
214
- config: __spreadValues(__spreadValues({}, userId ? { filter: 'user_id="'.concat(userId, '"') } : {}), pageToken ? { pageToken } : {})
220
+ config: __spreadValues(__spreadValues({}, userId ? { filter: "user_id=".concat(quoteFilterLiteral(userId)) } : {}), pageToken ? { pageToken } : {})
215
221
  });
216
222
  const sessions = response.sessions || [];
217
223
  for (const sessionObj of sessions) {
@@ -270,10 +276,19 @@ let VertexAiSessionService = class extends BaseSessionService {
270
276
  }
271
277
  async deleteSession({
272
278
  appName,
273
- userId: _userId,
279
+ userId,
274
280
  sessionId
275
281
  }) {
276
282
  const reasoningEngineId = this.getReasoningEngineId(appName);
283
+ const session = await this.getSession({
284
+ appName,
285
+ userId,
286
+ sessionId,
287
+ config: { numRecentEvents: 0 }
288
+ });
289
+ if (!session) {
290
+ return;
291
+ }
277
292
  await this.sessions.delete({
278
293
  name: "reasoningEngines/".concat(reasoningEngineId, "/sessions/").concat(sessionId)
279
294
  });
@@ -410,5 +425,6 @@ function _fromApiEvent(apiEventObj) {
410
425
  }
411
426
  export {
412
427
  VertexAiSessionService,
413
- isVertexAiConnectionString
428
+ isVertexAiConnectionString,
429
+ quoteFilterLiteral
414
430
  };