@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
@@ -8,7 +8,11 @@ const require = topLevelCreateRequire(import.meta.url);
8
8
  import { ActiveStreamingTool } from "./agents/active_streaming_tool.js";
9
9
  import { BaseAgent, isBaseAgent } from "./agents/base_agent.js";
10
10
  import { Context } from "./agents/context.js";
11
- import { functionsExportedForTestingOnly } from "./agents/functions.js";
11
+ import {
12
+ findEventByFunctionCallId,
13
+ findMatchingFunctionCall,
14
+ functionsExportedForTestingOnly
15
+ } from "./agents/functions.js";
12
16
  import { InvocationContext } from "./agents/invocation_context.js";
13
17
  import { LiveRequestQueue } from "./agents/live_request_queue.js";
14
18
  import { LlmAgent, LlmAgent as LlmAgent2, isLlmAgent } from "./agents/llm_agent.js";
@@ -24,13 +28,19 @@ import {
24
28
  ContentRequestProcessor
25
29
  } from "./agents/processors/content_request_processor.js";
26
30
  import { ContextCompactorRequestProcessor } from "./agents/processors/context_compactor_request_processor.js";
31
+ import {
32
+ INTERACTIONS_REQUEST_PROCESSOR,
33
+ InteractionsRequestProcessor
34
+ } from "./agents/processors/interactions_request_processor.js";
27
35
  import { ReadonlyContext } from "./agents/readonly_context.js";
28
36
  import { RoutedAgent, isRoutedAgent } from "./agents/routed_agent.js";
29
37
  import { StreamingMode } from "./agents/run_config.js";
30
38
  import { SequentialAgent, isSequentialAgent } from "./agents/sequential_agent.js";
39
+ import { createResumabilityConfig } from "./apps/resumability_config.js";
31
40
  import { InMemoryArtifactService } from "./artifacts/in_memory_artifact_service.js";
32
41
  import { AuthCredentialTypes } from "./auth/auth_credential.js";
33
42
  import { AuthHandler } from "./auth/auth_handler.js";
43
+ import { AUTH_PREPROCESSOR, AuthPreprocessor } from "./auth/auth_preprocessor.js";
34
44
  import { AuthProviderRegistry } from "./auth/auth_provider_registry.js";
35
45
  import { OAuthGrantType } from "./auth/auth_schemes.js";
36
46
  import { InMemoryCredentialService } from "./auth/credential_service/in_memory_credential_service.js";
@@ -45,8 +55,10 @@ import {
45
55
  CodeExecutionLanguage,
46
56
  FileContentEncoding
47
57
  } from "./code_executors/code_execution_utils.js";
58
+ import { AgentControlledContextCompactor } from "./context/agent_controlled_context_compactor.js";
48
59
  import { LlmSummarizer } from "./context/summarizers/llm_summarizer.js";
49
60
  import { TokenBasedContextCompactor } from "./context/token_based_context_compactor.js";
61
+ import { TrajectoryThoughtPruningCompactor } from "./context/trajectory_thought_pruning_compactor.js";
50
62
  import { TruncatingContextCompactor } from "./context/truncating_context_compactor.js";
51
63
  import { isCompactedEvent } from "./events/compacted_event.js";
52
64
  import {
@@ -81,7 +93,13 @@ import {
81
93
  getAskUserConfirmationFunctionCalls
82
94
  } from "./plugins/security_plugin.js";
83
95
  import { InMemoryRunner } from "./runner/in_memory_runner.js";
84
- import { Runner, isRunner } from "./runner/runner.js";
96
+ import {
97
+ Runner,
98
+ determineAgentForResumption,
99
+ findEventByLastFunctionResponseId,
100
+ isRoutableLlmAgent,
101
+ isRunner
102
+ } from "./runner/runner.js";
85
103
  import { BaseSessionService } from "./sessions/base_session_service.js";
86
104
  import { InMemorySessionService } from "./sessions/in_memory_session_service.js";
87
105
  import { createSession } from "./sessions/session.js";
@@ -89,6 +107,7 @@ import { State } from "./sessions/state.js";
89
107
  import { AgentTool, isAgentTool } from "./tools/agent_tool.js";
90
108
  import { BaseTool, isBaseTool } from "./tools/base_tool.js";
91
109
  import { BaseToolset, isBaseToolset } from "./tools/base_toolset.js";
110
+ import { ConsolidateContextTool } from "./tools/consolidate_context_tool.js";
92
111
  import { EXIT_LOOP, ExitLoopTool } from "./tools/exit_loop_tool.js";
93
112
  import { FunctionTool, isFunctionTool } from "./tools/function_tool.js";
94
113
  import {
@@ -110,28 +129,55 @@ import { ToolConfirmation } from "./tools/tool_confirmation.js";
110
129
  import { URL_CONTEXT, UrlContextTool } from "./tools/url_context_tool.js";
111
130
  import { VertexAiSearchTool } from "./tools/vertex_ai_search_tool.js";
112
131
  import { VertexRagRetrievalTool } from "./tools/vertex_rag_retrieval_tool.js";
132
+ import { getClientLabels, runWithClientLabel } from "./utils/client_labels.js";
113
133
  import { LogLevel, getLogger, setLogLevel, setLogger } from "./utils/logger.js";
114
- import { isGemini2OrAbove } from "./utils/model_name.js";
134
+ import { isGemini2OrAbove, isGemini3xFlashLive } from "./utils/model_name.js";
115
135
  import { zodObjectToSchema } from "./utils/simple_zod_to_json.js";
136
+ import { Task } from "./utils/task.js";
116
137
  import { GoogleLLMVariant } from "./utils/variant_utils.js";
117
138
  import { version } from "./version.js";
139
+ import { GCPSkillRegistry } from "./skills/gcp_skill_registry.js";
140
+ import {
141
+ loadAllSkillsInDir,
142
+ loadSkillFromDir,
143
+ loadSkillFromZipBuffer,
144
+ validateSkillDir
145
+ } from "./skills/loader.js";
118
146
  import { ListSkillsTool } from "./tools/skill/list_skills_tool.js";
119
147
  import { LoadSkillResourceTool } from "./tools/skill/load_skill_resource_tool.js";
120
148
  import { LoadSkillTool } from "./tools/skill/load_skill_tool.js";
149
+ import { SearchSkillsTool } from "./tools/skill/search_skills_tool.js";
121
150
  import { SkillToolset } from "./tools/skill/skill_toolset.js";
122
151
  export * from "./artifacts/base_artifact_service.js";
123
152
  export * from "./features/feature_registry.js";
124
153
  export * from "./memory/base_memory_service.js";
125
154
  export * from "./sessions/base_session_service.js";
126
155
  export * from "./tools/base_tool.js";
156
+ import { OpenApiSpecParser } from "./tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js";
157
+ import { OperationParser } from "./tools/openapi_tool/openapi_spec_parser/operation_parser.js";
158
+ import { ToolAuthHandler } from "./tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js";
159
+ import { OpenAPIToolset } from "./tools/openapi_tool/openapi_toolset.js";
160
+ import {
161
+ RestApiTool,
162
+ createRestApiTool
163
+ } from "./tools/openapi_tool/rest_api_tool.js";
164
+ export * from "./apps/app.js";
165
+ export * from "./artifacts/base_artifact_service.js";
166
+ export * from "./features/feature_registry.js";
167
+ export * from "./memory/base_memory_service.js";
168
+ export * from "./sessions/base_session_service.js";
169
+ export * from "./tools/base_tool.js";
127
170
  export {
171
+ AUTH_PREPROCESSOR,
128
172
  ActiveStreamingTool,
129
173
  LlmAgent as Agent,
174
+ AgentControlledContextCompactor,
130
175
  AgentTool,
131
176
  AgentTransferLlmRequestProcessor,
132
177
  ApigeeLlm,
133
178
  AuthCredentialTypes,
134
179
  AuthHandler,
180
+ AuthPreprocessor,
135
181
  AuthProviderRegistry,
136
182
  BaseAgent,
137
183
  BaseCodeExecutor,
@@ -146,6 +192,7 @@ export {
146
192
  BuiltInCodeExecutor,
147
193
  CONTENT_REQUEST_PROCESSOR,
148
194
  CodeExecutionLanguage,
195
+ ConsolidateContextTool,
149
196
  ContentRequestProcessor,
150
197
  Context,
151
198
  ContextCompactionTrigger,
@@ -157,18 +204,21 @@ export {
157
204
  ExitLoopTool,
158
205
  FileContentEncoding,
159
206
  FunctionTool,
207
+ GCPSkillRegistry,
160
208
  GOOGLE_MAPS_GROUNDING,
161
209
  GOOGLE_SEARCH,
162
210
  Gemini,
163
211
  GoogleLLMVariant,
164
212
  GoogleMapsGroundingTool,
165
213
  GoogleSearchTool,
214
+ INTERACTIONS_REQUEST_PROCESSOR,
166
215
  InMemoryArtifactService,
167
216
  InMemoryCredentialService,
168
217
  InMemoryMemoryService,
169
218
  InMemoryPolicyEngine,
170
219
  InMemoryRunner,
171
220
  InMemorySessionService,
221
+ InteractionsRequestProcessor,
172
222
  InvocationContext,
173
223
  LLMRegistry,
174
224
  LOAD_ARTIFACTS,
@@ -188,6 +238,9 @@ export {
188
238
  OAuth2CredentialExchanger,
189
239
  OAuth2DiscoveryManager,
190
240
  OAuthGrantType,
241
+ OpenAPIToolset,
242
+ OpenApiSpecParser,
243
+ OperationParser,
191
244
  PRELOAD_MEMORY,
192
245
  ParallelAgent,
193
246
  PluginManager,
@@ -195,17 +248,22 @@ export {
195
248
  PreloadMemoryTool,
196
249
  REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
197
250
  ReadonlyContext,
251
+ RestApiTool,
198
252
  RoutedAgent,
199
253
  RoutedLlm,
200
254
  Runner,
255
+ SearchSkillsTool,
201
256
  SecurityPlugin,
202
257
  SequentialAgent,
203
258
  SessionStateCredentialService,
204
259
  SkillToolset,
205
260
  State,
206
261
  StreamingMode,
262
+ Task,
207
263
  TokenBasedContextCompactor,
264
+ ToolAuthHandler,
208
265
  ToolConfirmation,
266
+ TrajectoryThoughtPruningCompactor,
209
267
  TruncatingContextCompactor,
210
268
  URL_CONTEXT,
211
269
  UrlContextTool,
@@ -214,10 +272,17 @@ export {
214
272
  VertexRagRetrievalTool,
215
273
  createEvent,
216
274
  createEventActions,
275
+ createRestApiTool,
276
+ createResumabilityConfig,
217
277
  createSession,
278
+ determineAgentForResumption,
279
+ findEventByFunctionCallId,
280
+ findEventByLastFunctionResponseId,
281
+ findMatchingFunctionCall,
218
282
  functionsExportedForTestingOnly,
219
283
  geminiInitParams,
220
284
  getAskUserConfirmationFunctionCalls,
285
+ getClientLabels,
221
286
  getFunctionCalls,
222
287
  getFunctionResponses,
223
288
  getLogger,
@@ -232,16 +297,23 @@ export {
232
297
  isFinalResponse,
233
298
  isFunctionTool,
234
299
  isGemini2OrAbove,
300
+ isGemini3xFlashLive,
235
301
  isLlmAgent,
236
302
  isLoopAgent,
237
303
  isParallelAgent,
304
+ isRoutableLlmAgent,
238
305
  isRoutedAgent,
239
306
  isRunner,
240
307
  isSequentialAgent,
308
+ loadAllSkillsInDir,
309
+ loadSkillFromDir,
310
+ loadSkillFromZipBuffer,
311
+ runWithClientLabel,
241
312
  setLogLevel,
242
313
  setLogger,
243
314
  stringifyContent,
244
315
  toStructuredEvents,
316
+ validateSkillDir,
245
317
  version,
246
318
  zodObjectToSchema
247
319
  };
@@ -0,0 +1,81 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ /**
4
+ * @license
5
+ * Copyright 2026 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ import { isCompactedEvent } from "../events/compacted_event.js";
9
+ import { createEvent } from "../events/event.js";
10
+ import { ContextCompactionTrigger } from "../plugins/base_plugin.js";
11
+ class AgentControlledContextCompactor {
12
+ constructor(options) {
13
+ this.trigger = ContextCompactionTrigger.AgentControlled;
14
+ this.summarizer = options.summarizer;
15
+ }
16
+ shouldCompact(invocationContext) {
17
+ return invocationContext.session.state["temp:consolidate_context"] === true;
18
+ }
19
+ async compact(invocationContext) {
20
+ const events = invocationContext.session.events;
21
+ const activeEvents = this.getActiveEvents(events);
22
+ const consolidateToolCallIndex = activeEvents.reduce(
23
+ (acc, e, idx) => {
24
+ var _a, _b;
25
+ return ((_b = (_a = e.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.some(
26
+ (p) => {
27
+ var _a2;
28
+ return ((_a2 = p.functionCall) == null ? void 0 : _a2.name) === "consolidate_context";
29
+ }
30
+ )) ? idx : acc;
31
+ },
32
+ -1
33
+ );
34
+ if (consolidateToolCallIndex <= 0) {
35
+ this.clearFlags(invocationContext);
36
+ return;
37
+ }
38
+ const eventsToCompact = activeEvents.slice(0, consolidateToolCallIndex);
39
+ const detail = invocationContext.session.state["temp:consolidate_context_detail"];
40
+ if (detail) {
41
+ eventsToCompact.push(
42
+ createEvent({
43
+ author: "system",
44
+ timestamp: eventsToCompact[eventsToCompact.length - 1].timestamp,
45
+ content: {
46
+ role: "user",
47
+ parts: [
48
+ {
49
+ text: "CRITICAL INSTRUCTION FOR SUMMARY: Please summarize the history. Focus especially on: ".concat(detail)
50
+ }
51
+ ]
52
+ }
53
+ })
54
+ );
55
+ }
56
+ try {
57
+ const compactedEvent = await this.summarizer.summarize(eventsToCompact);
58
+ invocationContext.session.events.push(compactedEvent);
59
+ } catch (error) {
60
+ console.error("Compaction failed:", error);
61
+ } finally {
62
+ this.clearFlags(invocationContext);
63
+ }
64
+ }
65
+ clearFlags(invocationContext) {
66
+ delete invocationContext.session.state["temp:consolidate_context"];
67
+ delete invocationContext.session.state["temp:consolidate_context_detail"];
68
+ }
69
+ getActiveEvents(events) {
70
+ const latest = events.filter(isCompactedEvent).pop();
71
+ return latest ? [
72
+ latest,
73
+ ...events.filter(
74
+ (e) => !isCompactedEvent(e) && e.timestamp > latest.endTime
75
+ )
76
+ ] : events;
77
+ }
78
+ }
79
+ export {
80
+ AgentControlledContextCompactor
81
+ };
@@ -13,10 +13,21 @@ import {
13
13
  import { stringifyContent } from "../../events/event.js";
14
14
  const DEFAULT_PROMPT = "The following is a conversation history between a user and an AI agent. Please summarize the conversation, focusing on key information and decisions made, as well as any unresolved questions or tasks. The summary should be concise and capture the essence of the interaction.";
15
15
  class LlmSummarizer {
16
+ /**
17
+ * @param options - Configuration specifying the LLM and optional prompt.
18
+ */
16
19
  constructor(options) {
17
20
  this.llm = options.llm;
18
21
  this.prompt = options.prompt || DEFAULT_PROMPT;
19
22
  }
23
+ /**
24
+ * Summarizes a list of events into a single {@link CompactedEvent} using the
25
+ * configured LLM.
26
+ *
27
+ * @param events - The events to summarize. Must be non-empty.
28
+ * @returns A promise resolving to the compacted representation.
29
+ * @throws {Error} If `events` is empty or the LLM returns no content.
30
+ */
20
31
  async summarize(events) {
21
32
  var _a, _b, _c, _d, _e, _f;
22
33
  if (events.length === 0) {
@@ -5,8 +5,9 @@ const require = topLevelCreateRequire(import.meta.url);
5
5
  * Copyright 2026 Google LLC
6
6
  * SPDX-License-Identifier: Apache-2.0
7
7
  */
8
+ import { getContents } from "../agents/processors/content_processor_utils.js";
8
9
  import { isCompactedEvent } from "../events/compacted_event.js";
9
- import { stringifyContent } from "../events/event.js";
10
+ const CHARS_PER_TOKEN = 4;
10
11
  class TokenBasedContextCompactor {
11
12
  constructor(options) {
12
13
  this.tokenThreshold = options.tokenThreshold;
@@ -38,11 +39,14 @@ class TokenBasedContextCompactor {
38
39
  if (rawEvents.length <= this.eventRetentionSize) {
39
40
  return false;
40
41
  }
41
- let totalTokens = 0;
42
- for (const event of activeEvents) {
43
- totalTokens += getEventTokens(event);
42
+ const promptTokenCount = latestPromptTokenCount(
43
+ activeEvents,
44
+ invocationContext
45
+ );
46
+ if (promptTokenCount === void 0) {
47
+ return false;
44
48
  }
45
- return totalTokens > this.tokenThreshold;
49
+ return promptTokenCount > this.tokenThreshold;
46
50
  }
47
51
  async compact(invocationContext) {
48
52
  const events = invocationContext.session.events;
@@ -75,20 +79,48 @@ class TokenBasedContextCompactor {
75
79
  compactedEvent.actions = {
76
80
  stateDelta: {},
77
81
  artifactDelta: {},
78
- requestedAuthConfigs: [],
82
+ requestedAuthConfigs: {},
79
83
  requestedToolConfirmations: {}
80
84
  };
81
85
  }
82
86
  invocationContext.session.events.push(compactedEvent);
83
87
  }
84
88
  }
85
- function getEventTokens(event) {
89
+ function latestPromptTokenCount(activeEvents, invocationContext) {
90
+ var _a;
91
+ for (let i = activeEvents.length - 1; i >= 0; i--) {
92
+ const count = (_a = activeEvents[i].usageMetadata) == null ? void 0 : _a.promptTokenCount;
93
+ if (count !== void 0) {
94
+ return count;
95
+ }
96
+ }
97
+ return estimatePromptTokenCount(activeEvents, invocationContext);
98
+ }
99
+ function estimatePromptTokenCount(activeEvents, invocationContext) {
86
100
  var _a;
87
- if (((_a = event.usageMetadata) == null ? void 0 : _a.promptTokenCount) !== void 0) {
88
- return event.usageMetadata.promptTokenCount;
101
+ const contents = getContents(
102
+ activeEvents,
103
+ invocationContext.agent.name,
104
+ invocationContext.branch
105
+ );
106
+ let totalChars = 0;
107
+ for (const content of contents) {
108
+ for (const part of (_a = content.parts) != null ? _a : []) {
109
+ if (part.text) {
110
+ totalChars += part.text.length;
111
+ }
112
+ if (part.functionCall) {
113
+ totalChars += JSON.stringify(part.functionCall).length;
114
+ }
115
+ if (part.functionResponse) {
116
+ totalChars += JSON.stringify(part.functionResponse).length;
117
+ }
118
+ }
119
+ }
120
+ if (totalChars <= 0) {
121
+ return void 0;
89
122
  }
90
- const contentStr = stringifyContent(event);
91
- return Math.ceil(contentStr.length / 4);
123
+ return Math.ceil(totalChars / CHARS_PER_TOKEN);
92
124
  }
93
125
  function hasFunctionCall(event) {
94
126
  var _a, _b;
@@ -0,0 +1,43 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ /**
4
+ * @license
5
+ * Copyright 2026 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ import { hasThoughts, pruneThoughts } from "../events/event.js";
9
+ class TrajectoryThoughtPruningCompactor {
10
+ constructor(options) {
11
+ if (options.eventRetentionSize < 0) {
12
+ throw new Error("eventRetentionSize must be a non-negative integer.");
13
+ }
14
+ this.eventRetentionSize = options.eventRetentionSize;
15
+ }
16
+ shouldCompact(invocationContext) {
17
+ const events = invocationContext.session.events;
18
+ if (events.length <= this.eventRetentionSize) {
19
+ return false;
20
+ }
21
+ const olderEvents = events.slice(
22
+ 0,
23
+ events.length - this.eventRetentionSize
24
+ );
25
+ return olderEvents.some((event) => hasThoughts(event));
26
+ }
27
+ compact(invocationContext) {
28
+ const events = invocationContext.session.events;
29
+ if (events.length <= this.eventRetentionSize) {
30
+ return;
31
+ }
32
+ const pruneLimit = events.length - this.eventRetentionSize;
33
+ for (let i = 0; i < pruneLimit; i++) {
34
+ const event = events[i];
35
+ if (hasThoughts(event)) {
36
+ events[i] = pruneThoughts(event);
37
+ }
38
+ }
39
+ }
40
+ }
41
+ export {
42
+ TrajectoryThoughtPruningCompactor
43
+ };
@@ -38,7 +38,7 @@ function createEvent(params = {}) {
38
38
  });
39
39
  }
40
40
  function isFinalResponse(event) {
41
- if (event.actions.skipSummarization || event.longRunningToolIds && event.longRunningToolIds.length > 0) {
41
+ if (event.actions.skipSummarization || event.longRunningToolIds && event.longRunningToolIds.length > 0 || event.actions.requestedAuthConfigs && Object.keys(event.actions.requestedAuthConfigs).length > 0) {
42
42
  return true;
43
43
  }
44
44
  return getFunctionCalls(event).length === 0 && getFunctionResponses(event).length === 0 && !event.partial && !hasTrailingCodeExecutionResult(event);
@@ -83,6 +83,24 @@ function stringifyContent(event) {
83
83
  return (_a2 = part.text) != null ? _a2 : "";
84
84
  }).join("");
85
85
  }
86
+ function hasThoughts(event) {
87
+ var _a, _b;
88
+ return !!((_b = (_a = event.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.some((part) => part.thought === true));
89
+ }
90
+ function pruneThoughts(event) {
91
+ var _a;
92
+ if (!((_a = event.content) == null ? void 0 : _a.parts)) {
93
+ return event;
94
+ }
95
+ const prunedParts = event.content.parts.filter(
96
+ (part) => part.thought !== true
97
+ );
98
+ return __spreadProps(__spreadValues({}, event), {
99
+ content: __spreadProps(__spreadValues({}, event.content), {
100
+ parts: prunedParts
101
+ })
102
+ });
103
+ }
86
104
  const ASCII_LETTERS_AND_NUMBERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
87
105
  function createNewEventId() {
88
106
  let id = "";
@@ -122,8 +140,10 @@ export {
122
140
  createNewEventId,
123
141
  getFunctionCalls,
124
142
  getFunctionResponses,
143
+ hasThoughts,
125
144
  hasTrailingCodeExecutionResult,
126
145
  isFinalResponse,
146
+ pruneThoughts,
127
147
  stringifyContent,
128
148
  transformToCamelCaseEvent,
129
149
  transformToSnakeCaseEvent
@@ -31,6 +31,19 @@ import {
31
31
  import { MCPTool } from "../../tools/mcp/mcp_tool.js";
32
32
  import { GCP_MCP_SERVER_DESTINATION_ID } from "./types.js";
33
33
  class AgentRegistrySingleMCPToolset extends BaseToolset {
34
+ /**
35
+ * @param options - Configuration for the MCP toolset.
36
+ * @param options.destinationResourceId - Telemetry identifier injected as
37
+ * `gcp.mcp.server.destination.id` into each resolved tool's custom metadata.
38
+ * @param options.connectionParams - HTTP connection parameters for the MCP server.
39
+ * @param options.toolFilter - Optional predicate or list of tool names to include.
40
+ * When omitted, all tools from the server are returned.
41
+ * @param options.prefix - Optional prefix prepended to each tool name (e.g. `myServer_toolName`).
42
+ * @param options.headerProvider - Optional async function called immediately before each
43
+ * {@link getTools} invocation to supply or refresh request headers (e.g. GCP auth tokens).
44
+ * @param options.authScheme - Optional auth scheme forwarded to each resolved tool.
45
+ * @param options.authCredential - Optional credential forwarded to each resolved tool.
46
+ */
34
47
  constructor(options) {
35
48
  super(options.toolFilter || [], options.prefix);
36
49
  this.destinationResourceId = options.destinationResourceId;
@@ -40,8 +53,14 @@ class AgentRegistrySingleMCPToolset extends BaseToolset {
40
53
  this.authCredential = options.authCredential;
41
54
  }
42
55
  /**
43
- * Connects to the underlying MCP server, retrieves tool definitions, prefixes tool names,
44
- * and injects destination telemetry metadata.
56
+ * Connects to the underlying MCP server, retrieves tool definitions, prefixes
57
+ * tool names, and injects destination telemetry metadata into each tool.
58
+ *
59
+ * The `headerProvider`, if configured, is invoked immediately before the
60
+ * connection is established so that tokens are always fresh.
61
+ *
62
+ * @param context - Optional readonly agent context passed to the header provider.
63
+ * @returns The resolved and optionally filtered list of {@link MCPTool} instances.
45
64
  */
46
65
  async getTools(context) {
47
66
  var _a, _b, _c;
@@ -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
  /**