@google/adk 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (300) hide show
  1. package/dist/cjs/agents/base_agent.js +19 -1
  2. package/dist/cjs/agents/functions.js +4 -0
  3. package/dist/cjs/agents/instructions.js +81 -33
  4. package/dist/cjs/agents/invocation_context.js +0 -1
  5. package/dist/cjs/agents/llm_agent.js +52 -5
  6. package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  7. package/dist/cjs/agents/processors/basic_llm_request_processor.js +8 -1
  8. package/dist/cjs/agents/processors/content_processor_utils.js +37 -24
  9. package/dist/cjs/agents/processors/content_request_processor.js +7 -0
  10. package/dist/cjs/agents/processors/context_compactor_request_processor.js +12 -0
  11. package/dist/cjs/agents/processors/identity_llm_request_processor.js +7 -0
  12. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +5 -0
  13. package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  14. package/dist/cjs/agents/processors/tool_filter_request_processor.js +7 -1
  15. package/dist/cjs/auth/auth_preprocessor.js +12 -10
  16. package/dist/cjs/auth/oauth2/oauth2_discovery.js +26 -2
  17. package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +305 -0
  18. package/dist/cjs/code_executors/code_execution_utils.js +1 -1
  19. package/dist/cjs/code_executors/code_executor_context.js +7 -7
  20. package/dist/cjs/common.js +50 -0
  21. package/dist/cjs/context/summarizers/llm_summarizer.js +11 -0
  22. package/dist/cjs/context/token_based_context_compactor.js +1 -1
  23. package/dist/cjs/events/event.js +4 -2
  24. package/dist/cjs/index.js +14 -0
  25. package/dist/cjs/integrations/agent_registry/agent_registry.js +362 -0
  26. package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +122 -0
  27. package/dist/cjs/integrations/agent_registry/helpers.js +57 -0
  28. package/dist/cjs/integrations/agent_registry/types.js +50 -0
  29. package/dist/cjs/memory/vertex_ai_memory_bank_service.js +496 -0
  30. package/dist/cjs/models/gemini_llm_connection.js +62 -19
  31. package/dist/cjs/models/google_llm.js +26 -8
  32. package/dist/cjs/plugins/security_plugin.js +16 -0
  33. package/dist/cjs/runner/in_memory_runner.js +10 -5
  34. package/dist/cjs/runner/runner.js +32 -2
  35. package/dist/cjs/sessions/base_session_service.js +13 -2
  36. package/dist/cjs/sessions/database_session_service.js +51 -5
  37. package/dist/cjs/sessions/db/schema.js +45 -10
  38. package/dist/cjs/sessions/in_memory_session_service.js +72 -15
  39. package/dist/cjs/sessions/registry.js +4 -0
  40. package/dist/cjs/sessions/vertex_ai_session_service.js +429 -0
  41. package/dist/cjs/skills/gcp_skill_registry.js +104 -0
  42. package/dist/cjs/skills/loader.js +65 -0
  43. package/dist/cjs/skills/skill_registry.js +27 -0
  44. package/dist/cjs/tools/agent_tool.js +10 -5
  45. package/dist/cjs/tools/exit_loop_tool.js +9 -0
  46. package/dist/cjs/tools/function_tool.js +7 -2
  47. package/dist/cjs/tools/google_maps_grounding_tool.js +80 -0
  48. package/dist/cjs/tools/long_running_tool.js +2 -1
  49. package/dist/cjs/tools/mcp/mcp_session_manager.js +11 -0
  50. package/dist/cjs/tools/mcp/mcp_tool.js +10 -6
  51. package/dist/cjs/tools/mcp/mcp_toolset.js +26 -3
  52. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +78 -0
  53. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +84 -0
  54. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +133 -0
  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 +127 -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 +27 -28
  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/tools/vertex_rag_retrieval_tool.js +64 -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/env_aware_utils.js +4 -0
  69. package/dist/cjs/utils/file_utils.js +28 -0
  70. package/dist/cjs/utils/gemini_schema_util.js +18 -0
  71. package/dist/cjs/utils/live_connection_utils.js +284 -0
  72. package/dist/cjs/utils/model_name.js +9 -0
  73. package/dist/cjs/utils/partial_copy.js +51 -0
  74. package/dist/cjs/utils/streaming_utils.js +169 -122
  75. package/dist/cjs/utils/vertex_ai_utils.js +50 -0
  76. package/dist/cjs/version.js +1 -1
  77. package/dist/esm/agents/base_agent.js +19 -1
  78. package/dist/esm/agents/functions.js +4 -0
  79. package/dist/esm/agents/instructions.js +81 -33
  80. package/dist/esm/agents/invocation_context.js +0 -1
  81. package/dist/esm/agents/llm_agent.js +53 -5
  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/content_processor_utils.js +35 -23
  85. package/dist/esm/agents/processors/content_request_processor.js +7 -0
  86. package/dist/esm/agents/processors/context_compactor_request_processor.js +12 -0
  87. package/dist/esm/agents/processors/identity_llm_request_processor.js +7 -0
  88. package/dist/esm/agents/processors/instructions_llm_request_processor.js +5 -0
  89. package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  90. package/dist/esm/agents/processors/tool_filter_request_processor.js +7 -1
  91. package/dist/esm/auth/auth_preprocessor.js +12 -10
  92. package/dist/esm/auth/oauth2/oauth2_discovery.js +26 -2
  93. package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +281 -0
  94. package/dist/esm/code_executors/code_execution_utils.js +1 -1
  95. package/dist/esm/code_executors/code_executor_context.js +7 -7
  96. package/dist/esm/common.js +43 -1
  97. package/dist/esm/context/summarizers/llm_summarizer.js +11 -0
  98. package/dist/esm/context/token_based_context_compactor.js +1 -1
  99. package/dist/esm/events/event.js +4 -2
  100. package/dist/esm/index.js +11 -0
  101. package/dist/esm/integrations/agent_registry/agent_registry.js +333 -0
  102. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +96 -0
  103. package/dist/esm/integrations/agent_registry/helpers.js +28 -0
  104. package/dist/esm/integrations/agent_registry/types.js +20 -0
  105. package/dist/esm/memory/vertex_ai_memory_bank_service.js +468 -0
  106. package/dist/esm/models/gemini_llm_connection.js +62 -19
  107. package/dist/esm/models/google_llm.js +26 -8
  108. package/dist/esm/plugins/security_plugin.js +16 -0
  109. package/dist/esm/runner/in_memory_runner.js +10 -5
  110. package/dist/esm/runner/runner.js +32 -2
  111. package/dist/esm/sessions/base_session_service.js +11 -1
  112. package/dist/esm/sessions/database_session_service.js +51 -5
  113. package/dist/esm/sessions/db/schema.js +44 -10
  114. package/dist/esm/sessions/in_memory_session_service.js +74 -16
  115. package/dist/esm/sessions/registry.js +7 -0
  116. package/dist/esm/sessions/vertex_ai_session_service.js +405 -0
  117. package/dist/esm/skills/gcp_skill_registry.js +78 -0
  118. package/dist/esm/skills/loader.js +64 -0
  119. package/dist/esm/skills/skill_registry.js +7 -0
  120. package/dist/esm/tools/agent_tool.js +10 -5
  121. package/dist/esm/tools/exit_loop_tool.js +9 -0
  122. package/dist/esm/tools/function_tool.js +7 -2
  123. package/dist/esm/tools/google_maps_grounding_tool.js +54 -0
  124. package/dist/esm/tools/long_running_tool.js +2 -1
  125. package/dist/esm/tools/mcp/mcp_session_manager.js +11 -0
  126. package/dist/esm/tools/mcp/mcp_tool.js +10 -6
  127. package/dist/esm/tools/mcp/mcp_toolset.js +26 -3
  128. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +48 -0
  129. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
  130. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
  131. package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +206 -0
  132. package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
  133. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
  134. package/dist/esm/tools/openapi_tool/openapi_toolset.js +97 -0
  135. package/dist/esm/tools/openapi_tool/rest_api_tool.js +229 -0
  136. package/dist/esm/tools/skill/load_skill_resource_tool.js +26 -27
  137. package/dist/esm/tools/skill/load_skill_tool.js +12 -1
  138. package/dist/esm/tools/skill/run_skill_script_tool.js +12 -1
  139. package/dist/esm/tools/skill/search_skills_tool.js +82 -0
  140. package/dist/esm/tools/skill/skill_toolset.js +40 -5
  141. package/dist/esm/tools/vertex_rag_retrieval_tool.js +36 -0
  142. package/dist/esm/utils/async_queue.js +60 -0
  143. package/dist/esm/utils/case_utils.js +25 -0
  144. package/dist/esm/utils/env_aware_utils.js +4 -0
  145. package/dist/esm/utils/file_utils.js +26 -0
  146. package/dist/esm/utils/gemini_schema_util.js +18 -0
  147. package/dist/esm/utils/live_connection_utils.js +256 -0
  148. package/dist/esm/utils/model_name.js +8 -0
  149. package/dist/esm/utils/partial_copy.js +23 -0
  150. package/dist/esm/utils/streaming_utils.js +167 -121
  151. package/dist/esm/utils/vertex_ai_utils.js +22 -0
  152. package/dist/esm/version.js +1 -1
  153. package/dist/types/a2a/a2a_remote_agent.d.ts +14 -0
  154. package/dist/types/a2a/a2a_remote_agent_utils.d.ts +29 -4
  155. package/dist/types/a2a/event_converter_utils.d.ts +14 -1
  156. package/dist/types/a2a/metadata_converter_utils.d.ts +18 -0
  157. package/dist/types/a2a/part_converter_utils.d.ts +51 -6
  158. package/dist/types/agents/invocation_context.d.ts +0 -9
  159. package/dist/types/agents/llm_agent.d.ts +14 -0
  160. package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +14 -0
  161. package/dist/types/agents/processors/base_llm_processor.d.ts +12 -4
  162. package/dist/types/agents/processors/basic_llm_request_processor.d.ts +12 -0
  163. package/dist/types/agents/processors/content_processor_utils.d.ts +26 -0
  164. package/dist/types/agents/processors/content_request_processor.d.ts +16 -0
  165. package/dist/types/agents/processors/context_compactor_request_processor.d.ts +12 -0
  166. package/dist/types/agents/processors/identity_llm_request_processor.d.ts +11 -0
  167. package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +14 -1
  168. package/dist/types/agents/processors/tool_filter_request_processor.d.ts +12 -1
  169. package/dist/types/agents/run_config.d.ts +15 -0
  170. package/dist/types/code_executors/agent_engine_sandbox_code_executor.d.ts +51 -0
  171. package/dist/types/common.d.ts +19 -1
  172. package/dist/types/context/summarizers/llm_summarizer.d.ts +17 -0
  173. package/dist/types/events/event_actions.d.ts +25 -8
  174. package/dist/types/events/structured_events.d.ts +13 -0
  175. package/dist/types/examples/example_util.d.ts +25 -0
  176. package/dist/types/index.d.ts +6 -0
  177. package/dist/types/integrations/agent_registry/agent_registry.d.ts +94 -0
  178. package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +62 -0
  179. package/dist/types/integrations/agent_registry/helpers.d.ts +7 -0
  180. package/dist/types/integrations/agent_registry/types.d.ts +101 -0
  181. package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +52 -0
  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/llm_response.d.ts +10 -1
  185. package/dist/types/plugins/security_plugin.d.ts +30 -0
  186. package/dist/types/runner/in_memory_runner.d.ts +28 -1
  187. package/dist/types/runner/runner.d.ts +47 -0
  188. package/dist/types/sessions/base_session_service.d.ts +22 -0
  189. package/dist/types/sessions/database_session_service.d.ts +1 -1
  190. package/dist/types/sessions/db/schema.d.ts +1 -0
  191. package/dist/types/sessions/in_memory_session_service.d.ts +1 -1
  192. package/dist/types/sessions/vertex_ai_session_service.d.ts +37 -0
  193. package/dist/types/skills/gcp_skill_registry.d.ts +24 -0
  194. package/dist/types/skills/loader.d.ts +7 -0
  195. package/dist/types/skills/skill.d.ts +1 -1
  196. package/dist/types/skills/skill_registry.d.ts +29 -0
  197. package/dist/types/tools/exit_loop_tool.d.ts +9 -0
  198. package/dist/types/tools/function_tool.d.ts +22 -2
  199. package/dist/types/tools/google_maps_grounding_tool.d.ts +22 -0
  200. package/dist/types/tools/long_running_tool.d.ts +11 -1
  201. package/dist/types/tools/mcp/mcp_session_manager.d.ts +3 -0
  202. package/dist/types/tools/mcp/mcp_toolset.d.ts +2 -1
  203. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +25 -0
  204. package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +20 -0
  205. package/dist/types/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.d.ts +20 -0
  206. package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +34 -0
  207. package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +59 -0
  208. package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +23 -0
  209. package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +27 -0
  210. package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +50 -0
  211. package/dist/types/tools/skill/load_skill_resource_tool.d.ts +1 -1
  212. package/dist/types/tools/skill/search_skills_tool.d.ts +14 -0
  213. package/dist/types/tools/skill/skill_toolset.d.ts +5 -0
  214. package/dist/types/tools/vertex_rag_retrieval_tool.d.ts +42 -0
  215. package/dist/types/utils/async_queue.d.ts +18 -0
  216. package/dist/types/utils/case_utils.d.ts +12 -0
  217. package/dist/types/utils/file_utils.d.ts +2 -0
  218. package/dist/types/utils/live_connection_utils.d.ts +30 -0
  219. package/dist/types/utils/model_name.d.ts +7 -0
  220. package/dist/types/utils/partial_copy.d.ts +13 -0
  221. package/dist/types/utils/streaming_utils.d.ts +7 -17
  222. package/dist/types/utils/vertex_ai_utils.d.ts +14 -0
  223. package/dist/types/version.d.ts +1 -1
  224. package/dist/web/agents/base_agent.js +31 -1
  225. package/dist/web/agents/functions.js +4 -0
  226. package/dist/web/agents/instructions.js +81 -33
  227. package/dist/web/agents/invocation_context.js +0 -1
  228. package/dist/web/agents/llm_agent.js +53 -5
  229. package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  230. package/dist/web/agents/processors/basic_llm_request_processor.js +8 -1
  231. package/dist/web/agents/processors/content_processor_utils.js +53 -23
  232. package/dist/web/agents/processors/content_request_processor.js +7 -0
  233. package/dist/web/agents/processors/context_compactor_request_processor.js +12 -0
  234. package/dist/web/agents/processors/identity_llm_request_processor.js +7 -0
  235. package/dist/web/agents/processors/instructions_llm_request_processor.js +5 -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/auth/auth_preprocessor.js +12 -10
  239. package/dist/web/auth/oauth2/oauth2_discovery.js +26 -2
  240. package/dist/web/code_executors/agent_engine_sandbox_code_executor.js +281 -0
  241. package/dist/web/code_executors/code_execution_utils.js +1 -1
  242. package/dist/web/code_executors/code_executor_context.js +7 -7
  243. package/dist/web/common.js +43 -1
  244. package/dist/web/context/summarizers/llm_summarizer.js +11 -0
  245. package/dist/web/context/token_based_context_compactor.js +1 -1
  246. package/dist/web/events/event.js +4 -2
  247. package/dist/web/index.js +11 -0
  248. package/dist/web/integrations/agent_registry/agent_registry.js +333 -0
  249. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +109 -0
  250. package/dist/web/integrations/agent_registry/helpers.js +28 -0
  251. package/dist/web/integrations/agent_registry/types.js +20 -0
  252. package/dist/web/memory/vertex_ai_memory_bank_service.js +475 -0
  253. package/dist/web/models/gemini_llm_connection.js +75 -19
  254. package/dist/web/models/google_llm.js +26 -8
  255. package/dist/web/plugins/security_plugin.js +16 -0
  256. package/dist/web/runner/in_memory_runner.js +10 -5
  257. package/dist/web/runner/runner.js +32 -2
  258. package/dist/web/sessions/base_session_service.js +11 -1
  259. package/dist/web/sessions/database_session_service.js +51 -5
  260. package/dist/web/sessions/db/schema.js +44 -10
  261. package/dist/web/sessions/in_memory_session_service.js +74 -16
  262. package/dist/web/sessions/registry.js +7 -0
  263. package/dist/web/sessions/vertex_ai_session_service.js +416 -0
  264. package/dist/web/skills/gcp_skill_registry.js +78 -0
  265. package/dist/web/skills/loader.js +64 -0
  266. package/dist/web/skills/skill_registry.js +7 -0
  267. package/dist/web/tools/agent_tool.js +10 -5
  268. package/dist/web/tools/exit_loop_tool.js +9 -0
  269. package/dist/web/tools/function_tool.js +7 -2
  270. package/dist/web/tools/google_maps_grounding_tool.js +54 -0
  271. package/dist/web/tools/long_running_tool.js +2 -1
  272. package/dist/web/tools/mcp/mcp_session_manager.js +11 -0
  273. package/dist/web/tools/mcp/mcp_tool.js +10 -6
  274. package/dist/web/tools/mcp/mcp_toolset.js +26 -3
  275. package/dist/web/tools/openapi_tool/auth/auth_helpers.js +48 -0
  276. package/dist/web/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
  277. package/dist/web/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
  278. package/dist/web/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +221 -0
  279. package/dist/web/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
  280. package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
  281. package/dist/web/tools/openapi_tool/openapi_toolset.js +97 -0
  282. package/dist/web/tools/openapi_tool/rest_api_tool.js +229 -0
  283. package/dist/web/tools/skill/load_skill_resource_tool.js +26 -27
  284. package/dist/web/tools/skill/load_skill_tool.js +12 -1
  285. package/dist/web/tools/skill/run_skill_script_tool.js +12 -1
  286. package/dist/web/tools/skill/search_skills_tool.js +82 -0
  287. package/dist/web/tools/skill/skill_toolset.js +40 -5
  288. package/dist/web/tools/vertex_rag_retrieval_tool.js +36 -0
  289. package/dist/web/utils/async_queue.js +60 -0
  290. package/dist/web/utils/case_utils.js +25 -0
  291. package/dist/web/utils/env_aware_utils.js +4 -0
  292. package/dist/web/utils/file_utils.js +26 -0
  293. package/dist/web/utils/gemini_schema_util.js +18 -0
  294. package/dist/web/utils/live_connection_utils.js +254 -0
  295. package/dist/web/utils/model_name.js +8 -0
  296. package/dist/web/utils/partial_copy.js +23 -0
  297. package/dist/web/utils/streaming_utils.js +221 -122
  298. package/dist/web/utils/vertex_ai_utils.js +22 -0
  299. package/dist/web/version.js +1 -1
  300. package/package.json +4 -1
@@ -16,15 +16,20 @@ var __asyncGenerator = (__this, __arguments, generator) => {
16
16
  }, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
17
17
  return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
18
18
  };
19
+ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
19
20
  /**
20
21
  * @license
21
- * Copyright 2025 Google LLC
22
+ * Copyright 2026 Google LLC
22
23
  * SPDX-License-Identifier: Apache-2.0
23
24
  */
25
+ import { LiveResponseAggregator } from "../utils/live_connection_utils.js";
24
26
  import { logger } from "../utils/logger.js";
27
+ import { isGemini3xFlashLive } from "../utils/model_name.js";
25
28
  class GeminiLlmConnection {
26
- constructor(geminiSession) {
29
+ constructor(geminiSession, modelVersion, messageQueue) {
27
30
  this.geminiSession = geminiSession;
31
+ this.modelVersion = modelVersion;
32
+ this.messageQueue = messageQueue;
28
33
  }
29
34
  /**
30
35
  * Sends the conversation history to the gemini model.
@@ -43,9 +48,10 @@ class GeminiLlmConnection {
43
48
  }
44
49
  );
45
50
  if (contents.length > 0) {
51
+ const isGemini3x = isGemini3xFlashLive(this.modelVersion);
46
52
  this.geminiSession.sendClientContent({
47
53
  turns: contents,
48
- turnComplete: contents[contents.length - 1].role === "user"
54
+ turnComplete: isGemini3x ? true : contents[contents.length - 1].role === "user"
49
55
  });
50
56
  } else {
51
57
  logger.info("no content is sent");
@@ -72,10 +78,16 @@ class GeminiLlmConnection {
72
78
  });
73
79
  } else {
74
80
  logger.debug("Sending LLM new content", content);
75
- this.geminiSession.sendClientContent({
76
- turns: [content],
77
- turnComplete: true
78
- });
81
+ const isGemini3x = isGemini3xFlashLive(this.modelVersion);
82
+ if (isGemini3x && content.parts.length === 1 && content.parts[0].text) {
83
+ logger.debug("Using sendRealtimeInput for Gemini 3.x text input");
84
+ this.geminiSession.sendRealtimeInput({ text: content.parts[0].text });
85
+ } else {
86
+ this.geminiSession.sendClientContent({
87
+ turns: [content],
88
+ turnComplete: true
89
+ });
90
+ }
79
91
  }
80
92
  }
81
93
  /**
@@ -84,8 +96,36 @@ class GeminiLlmConnection {
84
96
  * @param blob The blob to send to the model.
85
97
  */
86
98
  async sendRealtime(blob) {
99
+ var _a, _b, _c;
87
100
  logger.debug("Sending LLM Blob:", blob);
88
- this.geminiSession.sendRealtimeInput({ media: blob });
101
+ const isGemini3x = isGemini3xFlashLive(this.modelVersion);
102
+ const isNativeAudio = (_a = this.modelVersion) == null ? void 0 : _a.includes("native-audio");
103
+ if (isGemini3x || isNativeAudio) {
104
+ if ((_b = blob.mimeType) == null ? void 0 : _b.startsWith("audio/")) {
105
+ this.geminiSession.sendRealtimeInput({ audio: blob });
106
+ } else if ((_c = blob.mimeType) == null ? void 0 : _c.startsWith("image/")) {
107
+ this.geminiSession.sendRealtimeInput({ video: blob });
108
+ } else {
109
+ logger.warn(
110
+ "Blob not sent. Unknown or empty mime type for sendRealtimeInput:",
111
+ blob.mimeType
112
+ );
113
+ }
114
+ } else {
115
+ this.geminiSession.sendRealtimeInput({ media: blob });
116
+ }
117
+ }
118
+ /**
119
+ * Sends an activity start signal to the model.
120
+ */
121
+ async sendActivityStart() {
122
+ this.geminiSession.sendRealtimeInput({ activityStart: {} });
123
+ }
124
+ /**
125
+ * Sends an activity end signal to the model.
126
+ */
127
+ async sendActivityEnd() {
128
+ this.geminiSession.sendRealtimeInput({ activityEnd: {} });
89
129
  }
90
130
  /**
91
131
  * Builds a full text response.
@@ -94,21 +134,37 @@ class GeminiLlmConnection {
94
134
  * partial.
95
135
  *
96
136
  * @param text The text to be included in the response.
137
+ * @param isThought Whether the text is a thought.
138
+ * @param groundingMetadata The grounding metadata to include.
97
139
  * @returns An LlmResponse containing the full text.
98
140
  */
99
- buildFullTextResponse(text) {
100
- return {
101
- content: {
102
- role: "model",
103
- parts: [{ text }]
104
- }
105
- };
106
- }
107
- // TODO(b/425992518): GenAI SDK inconsistent API, missing methods.
108
- // eslint-disable-next-line require-yield
109
141
  receive() {
110
142
  return __asyncGenerator(this, null, function* () {
111
- throw new Error("Not Implemented.");
143
+ if (!this.messageQueue) {
144
+ throw new Error("Message queue is not initialized.");
145
+ }
146
+ const aggregator = new LiveResponseAggregator(this.modelVersion);
147
+ try {
148
+ for (var iter = __forAwait(this.messageQueue), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
149
+ const message = temp.value;
150
+ logger.debug("Got LLM Live message:", message);
151
+ for (const response of aggregator.processMessage(message)) {
152
+ yield response;
153
+ }
154
+ }
155
+ } catch (temp) {
156
+ error = [temp];
157
+ } finally {
158
+ try {
159
+ more && (temp = iter.return) && (yield new __await(temp.call(iter)));
160
+ } finally {
161
+ if (error)
162
+ throw error[0];
163
+ }
164
+ }
165
+ for (const response of aggregator.close()) {
166
+ yield response;
167
+ }
112
168
  });
113
169
  }
114
170
  /**
@@ -45,6 +45,7 @@ import {
45
45
  import { getBooleanEnvVar, isBrowser } from "../utils/env_aware_utils.js";
46
46
  import { logger } from "../utils/logger.js";
47
47
  import { GoogleLLMVariant } from "../utils/variant_utils.js";
48
+ import { AsyncQueue } from "../utils/async_queue.js";
48
49
  import { StreamingResponseAggregator } from "../utils/streaming_utils.js";
49
50
  import { BaseLlm } from "./base_llm.js";
50
51
  import { GeminiLlmConnection } from "./gemini_llm_connection.js";
@@ -199,10 +200,19 @@ class Gemini extends BaseLlm {
199
200
  }
200
201
  get liveApiClient() {
201
202
  if (!this._liveApiClient) {
202
- this._liveApiClient = new GoogleGenAI({
203
- apiKey: this.apiKey,
204
- httpOptions: this.getLiveHttpOptions()
205
- });
203
+ if (this.vertexai) {
204
+ this._liveApiClient = new GoogleGenAI({
205
+ vertexai: this.vertexai,
206
+ project: this.project,
207
+ location: this.location || "global",
208
+ httpOptions: this.getLiveHttpOptions()
209
+ });
210
+ } else {
211
+ this._liveApiClient = new GoogleGenAI({
212
+ apiKey: this.apiKey,
213
+ httpOptions: this.getLiveHttpOptions()
214
+ });
215
+ }
206
216
  }
207
217
  return this._liveApiClient;
208
218
  }
@@ -234,16 +244,24 @@ class Gemini extends BaseLlm {
234
244
  };
235
245
  }
236
246
  llmRequest.liveConnectConfig.tools = (_c = llmRequest.config) == null ? void 0 : _c.tools;
247
+ const modelVersion = (_d = llmRequest.model) != null ? _d : this.model;
248
+ const messageQueue = new AsyncQueue();
237
249
  const liveSession = await this.liveApiClient.live.connect({
238
- model: (_d = llmRequest.model) != null ? _d : this.model,
250
+ model: modelVersion,
239
251
  config: llmRequest.liveConnectConfig,
240
252
  callbacks: {
241
- // TODO - b/425992518: GenAI SDK inconsistent API, missing methods.
242
- onmessage: () => {
253
+ onmessage: (message) => {
254
+ messageQueue.push(message);
255
+ },
256
+ onerror: (error) => {
257
+ messageQueue.error(error);
258
+ },
259
+ onclose: () => {
260
+ messageQueue.close();
243
261
  }
244
262
  }
245
263
  });
246
- return new GeminiLlmConnection(liveSession);
264
+ return new GeminiLlmConnection(liveSession, modelVersion, messageQueue);
247
265
  }
248
266
  preprocessRequest(llmRequest) {
249
267
  if (this.apiBackend === GoogleLLMVariant.GEMINI_API) {
@@ -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,
@@ -10,11 +10,16 @@ import { InMemoryMemoryService } from "../memory/in_memory_memory_service.js";
10
10
  import { InMemorySessionService } from "../sessions/in_memory_session_service.js";
11
11
  import { Runner } from "./runner.js";
12
12
  class InMemoryRunner extends Runner {
13
- constructor({
14
- agent,
15
- appName = "InMemoryRunner",
16
- plugins = []
17
- }) {
13
+ /**
14
+ * Creates a new InMemoryRunner instance.
15
+ *
16
+ * @param params The configuration for the runner.
17
+ * @param params.agent The root agent to run.
18
+ * @param params.appName The application name. Defaults to `'InMemoryRunner'`.
19
+ * @param params.plugins An optional list of plugins.
20
+ */
21
+ constructor(params) {
22
+ const { agent, appName = "InMemoryRunner", plugins = [] } = params;
18
23
  super({
19
24
  appName,
20
25
  agent,
@@ -73,6 +73,7 @@ import {
73
73
  runAsyncGeneratorWithOtelContext,
74
74
  tracer
75
75
  } from "../telemetry/tracing.js";
76
+ import { isBaseToolset } from "../tools/base_toolset.js";
76
77
  import { logger } from "../utils/logger.js";
77
78
  import { isGemini2OrAbove } from "../utils/model_name.js";
78
79
  const RUNNER_SIGNATURE_SYMBOL = Symbol.for("google.adk.runner");
@@ -81,6 +82,11 @@ function isRunner(obj) {
81
82
  }
82
83
  _a = RUNNER_SIGNATURE_SYMBOL;
83
84
  class Runner {
85
+ /**
86
+ * Creates a new Runner instance.
87
+ *
88
+ * @param input The configuration for the runner.
89
+ */
84
90
  constructor(input) {
85
91
  this[_a] = true;
86
92
  var _a2;
@@ -114,7 +120,8 @@ class Runner {
114
120
  sessionId,
115
121
  newMessage: params.newMessage,
116
122
  stateDelta: params.stateDelta,
117
- runConfig: params.runConfig
123
+ runConfig: params.runConfig,
124
+ customMetadata: params.customMetadata
118
125
  }));
119
126
  } finally {
120
127
  yield new __await(this.sessionService.deleteSession({
@@ -222,7 +229,8 @@ class Runner {
222
229
  invocationId: invocationContext.invocationId,
223
230
  author: "user",
224
231
  actions: stateDelta ? createEventActions({ stateDelta }) : void 0,
225
- content: newMessage
232
+ content: newMessage,
233
+ customMetadata: params.customMetadata
226
234
  })
227
235
  }));
228
236
  if ((_e = params.abortSignal) == null ? void 0 : _e.aborted) {
@@ -300,6 +308,8 @@ class Runner {
300
308
  ));
301
309
  } finally {
302
310
  span.end();
311
+ const toolsets = getAllToolsets(this.agent);
312
+ yield new __await(Promise.allSettled(toolsets.map((t) => t.close())));
303
313
  }
304
314
  });
305
315
  }
@@ -420,6 +430,26 @@ function findEventByLastFunctionResponseId(events) {
420
430
  }
421
431
  return null;
422
432
  }
433
+ function getAllToolsets(agent) {
434
+ const toolsets = [];
435
+ const visited = /* @__PURE__ */ new Set();
436
+ function traverse(curr) {
437
+ if (visited.has(curr)) return;
438
+ visited.add(curr);
439
+ if (isLlmAgent(curr)) {
440
+ for (const tool of curr.tools) {
441
+ if (isBaseToolset(tool)) {
442
+ toolsets.push(tool);
443
+ }
444
+ }
445
+ }
446
+ for (const sub of curr.subAgents) {
447
+ traverse(sub);
448
+ }
449
+ }
450
+ traverse(agent);
451
+ return toolsets;
452
+ }
423
453
  export {
424
454
  Runner,
425
455
  isRunner
@@ -74,6 +74,15 @@ function trimTempDeltaState(event) {
74
74
  event.actions.stateDelta = filteredStateDelta;
75
75
  return event;
76
76
  }
77
+ function trimTempState(state) {
78
+ const filteredState = {};
79
+ for (const [key, value] of Object.entries(state)) {
80
+ if (!key.startsWith(State.TEMP_PREFIX)) {
81
+ filteredState[key] = value;
82
+ }
83
+ }
84
+ return filteredState;
85
+ }
77
86
  function mergeStates(appState = {}, userState = {}, sessionState = {}) {
78
87
  const merged = cloneDeep(sessionState);
79
88
  for (const [k, v] of Object.entries(appState)) {
@@ -87,5 +96,6 @@ function mergeStates(appState = {}, userState = {}, sessionState = {}) {
87
96
  export {
88
97
  BaseSessionService,
89
98
  mergeStates,
90
- trimTempDeltaState
99
+ trimTempDeltaState,
100
+ trimTempState
91
101
  };
@@ -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
  }
@@ -211,7 +211,11 @@ class DatabaseSessionService extends BaseSessionService {
211
211
  }
212
212
  async listSessions({
213
213
  appName,
214
- userId
214
+ userId,
215
+ limit,
216
+ offset,
217
+ page,
218
+ order
215
219
  }) {
216
220
  await this.init();
217
221
  const em = this.orm.em.fork();
@@ -219,7 +223,49 @@ class DatabaseSessionService extends BaseSessionService {
219
223
  if (userId) {
220
224
  where.userId = userId;
221
225
  }
222
- const storageSessions = await em.find(StorageSession, where);
226
+ const orderBy = order === "asc" ? { updateTime: "ASC", id: "ASC" } : order === "desc" ? { updateTime: "DESC", id: "ASC" } : void 0;
227
+ let storageSessions;
228
+ let paginationMeta;
229
+ if (limit !== void 0) {
230
+ const totalItems = await em.count(StorageSession, where);
231
+ const totalPages = limit === 0 ? 0 : Math.ceil(totalItems / limit);
232
+ let effectiveOffset;
233
+ let effectivePage;
234
+ if (page !== void 0) {
235
+ effectiveOffset = (page - 1) * limit;
236
+ effectivePage = page;
237
+ } else {
238
+ effectiveOffset = offset != null ? offset : 0;
239
+ effectivePage = limit === 0 ? 1 : Math.floor(effectiveOffset / limit) + 1;
240
+ }
241
+ storageSessions = await em.find(StorageSession, where, {
242
+ orderBy,
243
+ limit,
244
+ offset: effectiveOffset
245
+ });
246
+ paginationMeta = { page: effectivePage, limit, totalItems, totalPages };
247
+ } else if (offset) {
248
+ const totalItems = await em.count(StorageSession, where);
249
+ storageSessions = await em.find(StorageSession, where, {
250
+ orderBy,
251
+ offset
252
+ });
253
+ paginationMeta = {
254
+ page: 1,
255
+ limit: totalItems,
256
+ totalItems,
257
+ totalPages: totalItems === 0 ? 0 : 1
258
+ };
259
+ } else {
260
+ storageSessions = await em.find(StorageSession, where, { orderBy });
261
+ const totalItems = storageSessions.length;
262
+ paginationMeta = {
263
+ page: 1,
264
+ limit: totalItems,
265
+ totalItems,
266
+ totalPages: totalItems === 0 ? 0 : 1
267
+ };
268
+ }
223
269
  const appStateModel = await em.findOne(StorageAppState, { appName });
224
270
  const appState = (appStateModel == null ? void 0 : appStateModel.state) || {};
225
271
  const userStateMap = {};
@@ -244,7 +290,7 @@ class DatabaseSessionService extends BaseSessionService {
244
290
  lastUpdateTime: ss.updateTime.getTime()
245
291
  });
246
292
  });
247
- return { sessions };
293
+ return __spreadValues({ sessions }, paginationMeta);
248
294
  }
249
295
  async deleteSession({
250
296
  appName,
@@ -329,7 +375,7 @@ class DatabaseSessionService extends BaseSessionService {
329
375
  appDelta[key.replace(State.APP_PREFIX, "")] = value;
330
376
  } else if (key.startsWith(State.USER_PREFIX)) {
331
377
  userDelta[key.replace(State.USER_PREFIX, "")] = value;
332
- } else {
378
+ } else if (!key.startsWith(State.TEMP_PREFIX)) {
333
379
  sessionDelta[key] = value;
334
380
  }
335
381
  }
@@ -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
  });
@@ -104,25 +106,81 @@ class InMemorySessionService extends BaseSessionService {
104
106
  }
105
107
  listSessions({
106
108
  appName,
107
- userId
109
+ userId,
110
+ limit,
111
+ offset,
112
+ page,
113
+ order
108
114
  }) {
109
115
  if (!this.sessions[appName] || !this.sessions[appName][userId]) {
110
- return Promise.resolve({ sessions: [] });
116
+ if (limit !== void 0) {
117
+ const effectiveOffset2 = page !== void 0 ? (page - 1) * limit : offset != null ? offset : 0;
118
+ const effectivePage2 = page !== void 0 ? page : limit === 0 ? 1 : Math.floor(effectiveOffset2 / limit) + 1;
119
+ return Promise.resolve({
120
+ sessions: [],
121
+ page: effectivePage2,
122
+ limit,
123
+ totalItems: 0,
124
+ totalPages: 0
125
+ });
126
+ }
127
+ return Promise.resolve({
128
+ sessions: [],
129
+ page: 1,
130
+ limit: 0,
131
+ totalItems: 0,
132
+ totalPages: 0
133
+ });
111
134
  }
112
- const sessionsWithoutEvents = [];
113
- for (const session of Object.values(this.sessions[appName][userId])) {
114
- sessionsWithoutEvents.push(
115
- createSession({
116
- id: session.id,
117
- appName: session.appName,
118
- userId: session.userId,
119
- state: {},
120
- events: [],
121
- lastUpdateTime: session.lastUpdateTime
122
- })
135
+ const all = Object.values(this.sessions[appName][userId]).map(
136
+ (session) => createSession({
137
+ id: session.id,
138
+ appName: session.appName,
139
+ userId: session.userId,
140
+ state: {},
141
+ events: [],
142
+ lastUpdateTime: session.lastUpdateTime
143
+ })
144
+ );
145
+ if (order === "asc") {
146
+ all.sort(
147
+ (a, b) => a.lastUpdateTime - b.lastUpdateTime || a.id.localeCompare(b.id)
148
+ );
149
+ } else if (order === "desc") {
150
+ all.sort(
151
+ (a, b) => b.lastUpdateTime - a.lastUpdateTime || a.id.localeCompare(b.id)
123
152
  );
124
153
  }
125
- return Promise.resolve({ sessions: sessionsWithoutEvents });
154
+ if (limit === void 0) {
155
+ const totalItems2 = all.length;
156
+ const sliced = offset ? all.slice(offset) : all;
157
+ return Promise.resolve({
158
+ sessions: sliced,
159
+ page: 1,
160
+ limit: totalItems2,
161
+ totalItems: totalItems2,
162
+ totalPages: totalItems2 === 0 ? 0 : 1
163
+ });
164
+ }
165
+ const totalItems = all.length;
166
+ const totalPages = limit === 0 ? 0 : Math.ceil(totalItems / limit);
167
+ let effectiveOffset;
168
+ let effectivePage;
169
+ if (page !== void 0) {
170
+ effectiveOffset = (page - 1) * limit;
171
+ effectivePage = page;
172
+ } else {
173
+ effectiveOffset = offset != null ? offset : 0;
174
+ effectivePage = limit === 0 ? 1 : Math.floor(effectiveOffset / limit) + 1;
175
+ }
176
+ const paginated = all.slice(effectiveOffset, effectiveOffset + limit);
177
+ return Promise.resolve({
178
+ sessions: paginated,
179
+ page: effectivePage,
180
+ limit,
181
+ totalItems,
182
+ totalPages
183
+ });
126
184
  }
127
185
  async deleteSession({
128
186
  appName,