@google/adk 1.2.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 (190) hide show
  1. package/dist/cjs/agents/base_agent.js +19 -1
  2. package/dist/cjs/agents/instructions.js +81 -33
  3. package/dist/cjs/agents/invocation_context.js +0 -1
  4. package/dist/cjs/agents/llm_agent.js +52 -5
  5. package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  6. package/dist/cjs/agents/processors/basic_llm_request_processor.js +8 -1
  7. package/dist/cjs/agents/processors/content_processor_utils.js +37 -24
  8. package/dist/cjs/agents/processors/content_request_processor.js +7 -0
  9. package/dist/cjs/agents/processors/context_compactor_request_processor.js +12 -0
  10. package/dist/cjs/agents/processors/identity_llm_request_processor.js +7 -0
  11. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +5 -0
  12. package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  13. package/dist/cjs/agents/processors/tool_filter_request_processor.js +7 -1
  14. package/dist/cjs/auth/auth_preprocessor.js +12 -10
  15. package/dist/cjs/auth/oauth2/oauth2_discovery.js +1 -1
  16. package/dist/cjs/code_executors/code_executor_context.js +7 -7
  17. package/dist/cjs/common.js +39 -0
  18. package/dist/cjs/context/summarizers/llm_summarizer.js +11 -0
  19. package/dist/cjs/context/token_based_context_compactor.js +1 -1
  20. package/dist/cjs/events/event.js +1 -1
  21. package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
  22. package/dist/cjs/models/gemini_llm_connection.js +62 -19
  23. package/dist/cjs/models/google_llm.js +26 -8
  24. package/dist/cjs/plugins/security_plugin.js +16 -0
  25. package/dist/cjs/sessions/base_session_service.js +13 -2
  26. package/dist/cjs/sessions/database_session_service.js +2 -2
  27. package/dist/cjs/sessions/db/schema.js +45 -10
  28. package/dist/cjs/sessions/in_memory_session_service.js +2 -1
  29. package/dist/cjs/sessions/vertex_ai_session_service.js +2 -1
  30. package/dist/cjs/skills/gcp_skill_registry.js +104 -0
  31. package/dist/cjs/skills/loader.js +65 -0
  32. package/dist/cjs/skills/skill_registry.js +27 -0
  33. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +232 -0
  34. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +224 -0
  35. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +127 -0
  36. package/dist/cjs/tools/openapi_tool/openapi_toolset.js +133 -0
  37. package/dist/cjs/tools/openapi_tool/rest_api_tool.js +256 -0
  38. package/dist/cjs/tools/skill/load_skill_resource_tool.js +25 -3
  39. package/dist/cjs/tools/skill/load_skill_tool.js +12 -1
  40. package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -1
  41. package/dist/cjs/tools/skill/search_skills_tool.js +108 -0
  42. package/dist/cjs/tools/skill/skill_toolset.js +40 -5
  43. package/dist/cjs/utils/async_queue.js +88 -0
  44. package/dist/cjs/utils/case_utils.js +53 -0
  45. package/dist/cjs/utils/env_aware_utils.js +4 -0
  46. package/dist/cjs/utils/live_connection_utils.js +284 -0
  47. package/dist/cjs/utils/model_name.js +9 -0
  48. package/dist/cjs/utils/streaming_utils.js +9 -8
  49. package/dist/cjs/version.js +1 -1
  50. package/dist/esm/agents/base_agent.js +19 -1
  51. package/dist/esm/agents/instructions.js +81 -33
  52. package/dist/esm/agents/invocation_context.js +0 -1
  53. package/dist/esm/agents/llm_agent.js +53 -5
  54. package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  55. package/dist/esm/agents/processors/basic_llm_request_processor.js +8 -1
  56. package/dist/esm/agents/processors/content_processor_utils.js +35 -23
  57. package/dist/esm/agents/processors/content_request_processor.js +7 -0
  58. package/dist/esm/agents/processors/context_compactor_request_processor.js +12 -0
  59. package/dist/esm/agents/processors/identity_llm_request_processor.js +7 -0
  60. package/dist/esm/agents/processors/instructions_llm_request_processor.js +5 -0
  61. package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  62. package/dist/esm/agents/processors/tool_filter_request_processor.js +7 -1
  63. package/dist/esm/auth/auth_preprocessor.js +12 -10
  64. package/dist/esm/auth/oauth2/oauth2_discovery.js +1 -1
  65. package/dist/esm/code_executors/code_executor_context.js +7 -7
  66. package/dist/esm/common.js +33 -1
  67. package/dist/esm/context/summarizers/llm_summarizer.js +11 -0
  68. package/dist/esm/context/token_based_context_compactor.js +1 -1
  69. package/dist/esm/events/event.js +1 -1
  70. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
  71. package/dist/esm/models/gemini_llm_connection.js +62 -19
  72. package/dist/esm/models/google_llm.js +26 -8
  73. package/dist/esm/plugins/security_plugin.js +16 -0
  74. package/dist/esm/sessions/base_session_service.js +11 -1
  75. package/dist/esm/sessions/database_session_service.js +2 -2
  76. package/dist/esm/sessions/db/schema.js +44 -10
  77. package/dist/esm/sessions/in_memory_session_service.js +4 -2
  78. package/dist/esm/sessions/vertex_ai_session_service.js +4 -2
  79. package/dist/esm/skills/gcp_skill_registry.js +78 -0
  80. package/dist/esm/skills/loader.js +64 -0
  81. package/dist/esm/skills/skill_registry.js +7 -0
  82. package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +206 -0
  83. package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
  84. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
  85. package/dist/esm/tools/openapi_tool/openapi_toolset.js +97 -0
  86. package/dist/esm/tools/openapi_tool/rest_api_tool.js +229 -0
  87. package/dist/esm/tools/skill/load_skill_resource_tool.js +25 -3
  88. package/dist/esm/tools/skill/load_skill_tool.js +12 -1
  89. package/dist/esm/tools/skill/run_skill_script_tool.js +12 -1
  90. package/dist/esm/tools/skill/search_skills_tool.js +82 -0
  91. package/dist/esm/tools/skill/skill_toolset.js +40 -5
  92. package/dist/esm/utils/async_queue.js +60 -0
  93. package/dist/esm/utils/case_utils.js +25 -0
  94. package/dist/esm/utils/env_aware_utils.js +4 -0
  95. package/dist/esm/utils/live_connection_utils.js +256 -0
  96. package/dist/esm/utils/model_name.js +8 -0
  97. package/dist/esm/utils/streaming_utils.js +9 -8
  98. package/dist/esm/version.js +1 -1
  99. package/dist/types/a2a/a2a_remote_agent_utils.d.ts +29 -4
  100. package/dist/types/a2a/event_converter_utils.d.ts +14 -1
  101. package/dist/types/a2a/metadata_converter_utils.d.ts +18 -0
  102. package/dist/types/a2a/part_converter_utils.d.ts +51 -6
  103. package/dist/types/agents/invocation_context.d.ts +0 -9
  104. package/dist/types/agents/llm_agent.d.ts +14 -0
  105. package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +14 -0
  106. package/dist/types/agents/processors/basic_llm_request_processor.d.ts +7 -0
  107. package/dist/types/agents/processors/content_processor_utils.d.ts +26 -0
  108. package/dist/types/agents/processors/content_request_processor.d.ts +16 -0
  109. package/dist/types/agents/processors/context_compactor_request_processor.d.ts +12 -0
  110. package/dist/types/agents/processors/identity_llm_request_processor.d.ts +7 -0
  111. package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +9 -1
  112. package/dist/types/agents/processors/tool_filter_request_processor.d.ts +12 -1
  113. package/dist/types/common.d.ts +15 -1
  114. package/dist/types/context/summarizers/llm_summarizer.d.ts +17 -0
  115. package/dist/types/events/event_actions.d.ts +1 -2
  116. package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +21 -2
  117. package/dist/types/models/base_llm_connection.d.ts +10 -0
  118. package/dist/types/models/gemini_llm_connection.d.ts +15 -4
  119. package/dist/types/models/llm_response.d.ts +10 -1
  120. package/dist/types/plugins/security_plugin.d.ts +30 -0
  121. package/dist/types/sessions/base_session_service.d.ts +4 -0
  122. package/dist/types/sessions/db/schema.d.ts +1 -0
  123. package/dist/types/skills/gcp_skill_registry.d.ts +24 -0
  124. package/dist/types/skills/loader.d.ts +7 -0
  125. package/dist/types/skills/skill.d.ts +1 -1
  126. package/dist/types/skills/skill_registry.d.ts +29 -0
  127. package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +34 -0
  128. package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +59 -0
  129. package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +23 -0
  130. package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +27 -0
  131. package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +50 -0
  132. package/dist/types/tools/skill/load_skill_resource_tool.d.ts +1 -1
  133. package/dist/types/tools/skill/search_skills_tool.d.ts +14 -0
  134. package/dist/types/tools/skill/skill_toolset.d.ts +5 -0
  135. package/dist/types/utils/async_queue.d.ts +18 -0
  136. package/dist/types/utils/case_utils.d.ts +12 -0
  137. package/dist/types/utils/live_connection_utils.d.ts +30 -0
  138. package/dist/types/utils/model_name.d.ts +7 -0
  139. package/dist/types/utils/streaming_utils.d.ts +0 -1
  140. package/dist/types/version.d.ts +1 -1
  141. package/dist/web/agents/base_agent.js +31 -1
  142. package/dist/web/agents/instructions.js +81 -33
  143. package/dist/web/agents/invocation_context.js +0 -1
  144. package/dist/web/agents/llm_agent.js +53 -5
  145. package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  146. package/dist/web/agents/processors/basic_llm_request_processor.js +8 -1
  147. package/dist/web/agents/processors/content_processor_utils.js +53 -23
  148. package/dist/web/agents/processors/content_request_processor.js +7 -0
  149. package/dist/web/agents/processors/context_compactor_request_processor.js +12 -0
  150. package/dist/web/agents/processors/identity_llm_request_processor.js +7 -0
  151. package/dist/web/agents/processors/instructions_llm_request_processor.js +5 -0
  152. package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  153. package/dist/web/agents/processors/tool_filter_request_processor.js +7 -1
  154. package/dist/web/auth/auth_preprocessor.js +12 -10
  155. package/dist/web/auth/oauth2/oauth2_discovery.js +1 -1
  156. package/dist/web/code_executors/code_executor_context.js +7 -7
  157. package/dist/web/common.js +33 -1
  158. package/dist/web/context/summarizers/llm_summarizer.js +11 -0
  159. package/dist/web/context/token_based_context_compactor.js +1 -1
  160. package/dist/web/events/event.js +1 -1
  161. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
  162. package/dist/web/models/gemini_llm_connection.js +75 -19
  163. package/dist/web/models/google_llm.js +26 -8
  164. package/dist/web/plugins/security_plugin.js +16 -0
  165. package/dist/web/sessions/base_session_service.js +11 -1
  166. package/dist/web/sessions/database_session_service.js +2 -2
  167. package/dist/web/sessions/db/schema.js +44 -10
  168. package/dist/web/sessions/in_memory_session_service.js +4 -2
  169. package/dist/web/sessions/vertex_ai_session_service.js +4 -2
  170. package/dist/web/skills/gcp_skill_registry.js +78 -0
  171. package/dist/web/skills/loader.js +64 -0
  172. package/dist/web/skills/skill_registry.js +7 -0
  173. package/dist/web/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +221 -0
  174. package/dist/web/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
  175. package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
  176. package/dist/web/tools/openapi_tool/openapi_toolset.js +97 -0
  177. package/dist/web/tools/openapi_tool/rest_api_tool.js +229 -0
  178. package/dist/web/tools/skill/load_skill_resource_tool.js +25 -3
  179. package/dist/web/tools/skill/load_skill_tool.js +12 -1
  180. package/dist/web/tools/skill/run_skill_script_tool.js +12 -1
  181. package/dist/web/tools/skill/search_skills_tool.js +82 -0
  182. package/dist/web/tools/skill/skill_toolset.js +40 -5
  183. package/dist/web/utils/async_queue.js +60 -0
  184. package/dist/web/utils/case_utils.js +25 -0
  185. package/dist/web/utils/env_aware_utils.js +4 -0
  186. package/dist/web/utils/live_connection_utils.js +254 -0
  187. package/dist/web/utils/model_name.js +8 -0
  188. package/dist/web/utils/streaming_utils.js +9 -8
  189. package/dist/web/version.js +1 -1
  190. package/package.json +3 -1
@@ -0,0 +1,256 @@
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 { isGemini3xFlashLive } from "./model_name.js";
9
+ class LiveResponseAggregator {
10
+ constructor(modelVersion) {
11
+ this.modelVersion = modelVersion;
12
+ this.text = "";
13
+ this.isThought = false;
14
+ this.toolCallParts = [];
15
+ this.pendingGroundingMetadata = void 0;
16
+ this.inputTranscriptionText = "";
17
+ this.outputTranscriptionText = "";
18
+ }
19
+ *processMessage(message) {
20
+ if (message.usageMetadata) {
21
+ yield {
22
+ usageMetadata: message.usageMetadata,
23
+ ...this.modelVersion ? { modelVersion: this.modelVersion } : {}
24
+ };
25
+ }
26
+ if (message.serverContent) {
27
+ const serverContent = message.serverContent;
28
+ const content = serverContent.modelTurn;
29
+ if (serverContent.groundingMetadata) {
30
+ this.pendingGroundingMetadata = serverContent.groundingMetadata;
31
+ }
32
+ if (!(content && content.parts) && serverContent.groundingMetadata && !serverContent.turnComplete) {
33
+ yield {
34
+ groundingMetadata: serverContent.groundingMetadata,
35
+ ...serverContent.interrupted !== void 0 ? { interrupted: serverContent.interrupted } : {},
36
+ ...this.modelVersion ? { modelVersion: this.modelVersion } : {}
37
+ };
38
+ }
39
+ if (content && content.parts) {
40
+ const llmResponse = {
41
+ content,
42
+ ...serverContent.interrupted !== void 0 ? { interrupted: serverContent.interrupted } : {},
43
+ ...this.modelVersion ? { modelVersion: this.modelVersion } : {}
44
+ };
45
+ if (!serverContent.turnComplete && serverContent.groundingMetadata) {
46
+ llmResponse.groundingMetadata = serverContent.groundingMetadata;
47
+ }
48
+ const hasInlineData = content.parts.some((p) => p.inlineData);
49
+ for (const part of content.parts) {
50
+ if (part.text) {
51
+ const currentIsThought = !!part.thought;
52
+ if (this.text && currentIsThought !== this.isThought) {
53
+ yield this.buildFullTextResponse(this.text, this.isThought);
54
+ this.text = "";
55
+ this.isThought = false;
56
+ }
57
+ this.text += part.text;
58
+ this.isThought = currentIsThought;
59
+ llmResponse.partial = true;
60
+ }
61
+ }
62
+ if (this.text && !content.parts.some((p) => p.text) && !hasInlineData) {
63
+ yield this.buildFullTextResponse(this.text, this.isThought);
64
+ this.text = "";
65
+ this.isThought = false;
66
+ }
67
+ yield llmResponse;
68
+ }
69
+ if (serverContent.inputTranscription) {
70
+ if (serverContent.inputTranscription.text) {
71
+ this.inputTranscriptionText += serverContent.inputTranscription.text;
72
+ yield {
73
+ inputTranscription: {
74
+ text: serverContent.inputTranscription.text,
75
+ finished: false
76
+ },
77
+ partial: true,
78
+ ...this.modelVersion ? { modelVersion: this.modelVersion } : {}
79
+ };
80
+ }
81
+ if (serverContent.inputTranscription.finished) {
82
+ yield {
83
+ inputTranscription: {
84
+ text: this.inputTranscriptionText,
85
+ finished: true
86
+ },
87
+ partial: false,
88
+ ...this.modelVersion ? { modelVersion: this.modelVersion } : {}
89
+ };
90
+ this.inputTranscriptionText = "";
91
+ }
92
+ }
93
+ if (serverContent.outputTranscription) {
94
+ if (serverContent.outputTranscription.text) {
95
+ this.outputTranscriptionText += serverContent.outputTranscription.text;
96
+ yield {
97
+ outputTranscription: {
98
+ text: serverContent.outputTranscription.text,
99
+ finished: false
100
+ },
101
+ partial: true,
102
+ ...this.modelVersion ? { modelVersion: this.modelVersion } : {}
103
+ };
104
+ }
105
+ if (serverContent.outputTranscription.finished) {
106
+ yield {
107
+ outputTranscription: {
108
+ text: this.outputTranscriptionText,
109
+ finished: true
110
+ },
111
+ partial: false,
112
+ ...this.modelVersion ? { modelVersion: this.modelVersion } : {}
113
+ };
114
+ this.outputTranscriptionText = "";
115
+ }
116
+ }
117
+ if (serverContent.interrupted || serverContent.turnComplete || serverContent.generationComplete) {
118
+ if (this.inputTranscriptionText) {
119
+ yield {
120
+ inputTranscription: {
121
+ text: this.inputTranscriptionText,
122
+ finished: true
123
+ },
124
+ partial: false,
125
+ ...this.modelVersion ? { modelVersion: this.modelVersion } : {}
126
+ };
127
+ this.inputTranscriptionText = "";
128
+ }
129
+ if (this.outputTranscriptionText) {
130
+ yield {
131
+ outputTranscription: {
132
+ text: this.outputTranscriptionText,
133
+ finished: true
134
+ },
135
+ partial: false,
136
+ ...this.modelVersion ? { modelVersion: this.modelVersion } : {}
137
+ };
138
+ this.outputTranscriptionText = "";
139
+ }
140
+ }
141
+ if (serverContent.turnComplete) {
142
+ let gMetadataToYield = this.pendingGroundingMetadata;
143
+ if (this.text) {
144
+ yield this.buildFullTextResponse(
145
+ this.text,
146
+ this.isThought,
147
+ gMetadataToYield
148
+ );
149
+ this.text = "";
150
+ this.isThought = false;
151
+ gMetadataToYield = void 0;
152
+ }
153
+ if (this.toolCallParts.length > 0) {
154
+ yield {
155
+ content: { role: "model", parts: this.toolCallParts },
156
+ ...this.modelVersion ? { modelVersion: this.modelVersion } : {}
157
+ };
158
+ this.toolCallParts = [];
159
+ }
160
+ const finalResponse = {
161
+ turnComplete: true,
162
+ ...this.modelVersion ? { modelVersion: this.modelVersion } : {}
163
+ };
164
+ if (serverContent.interrupted !== void 0) {
165
+ finalResponse.interrupted = serverContent.interrupted;
166
+ }
167
+ const finalGrounding = serverContent.groundingMetadata || gMetadataToYield;
168
+ if (finalGrounding !== void 0 && finalGrounding !== null) {
169
+ finalResponse.groundingMetadata = finalGrounding;
170
+ }
171
+ yield finalResponse;
172
+ }
173
+ if (serverContent.interrupted) {
174
+ if (this.text) {
175
+ yield this.buildFullTextResponse(this.text, this.isThought);
176
+ this.text = "";
177
+ this.isThought = false;
178
+ } else {
179
+ yield {
180
+ interrupted: serverContent.interrupted,
181
+ ...this.modelVersion ? { modelVersion: this.modelVersion } : {}
182
+ };
183
+ }
184
+ }
185
+ }
186
+ if (message.toolCall) {
187
+ if (this.text) {
188
+ yield this.buildFullTextResponse(this.text, this.isThought);
189
+ this.text = "";
190
+ this.isThought = false;
191
+ }
192
+ if (message.toolCall.functionCalls) {
193
+ this.toolCallParts.push(
194
+ ...message.toolCall.functionCalls.map((fc) => ({
195
+ functionCall: fc
196
+ }))
197
+ );
198
+ }
199
+ const isGemini3x = isGemini3xFlashLive(this.modelVersion);
200
+ if (isGemini3x && this.toolCallParts.length > 0) {
201
+ yield {
202
+ content: { role: "model", parts: this.toolCallParts },
203
+ ...this.modelVersion ? { modelVersion: this.modelVersion } : {}
204
+ };
205
+ this.toolCallParts = [];
206
+ }
207
+ }
208
+ if (message.sessionResumptionUpdate) {
209
+ yield {
210
+ liveSessionResumptionUpdate: message.sessionResumptionUpdate,
211
+ ...this.modelVersion ? { modelVersion: this.modelVersion } : {}
212
+ };
213
+ }
214
+ if (message.goAway) {
215
+ yield {
216
+ goAway: message.goAway,
217
+ ...this.modelVersion ? { modelVersion: this.modelVersion } : {}
218
+ };
219
+ }
220
+ }
221
+ /**
222
+ * Flushes any remaining aggregated components when the connection is closed.
223
+ */
224
+ *close() {
225
+ if (this.toolCallParts.length > 0) {
226
+ yield {
227
+ content: { role: "model", parts: this.toolCallParts },
228
+ ...this.modelVersion ? { modelVersion: this.modelVersion } : {}
229
+ };
230
+ this.toolCallParts = [];
231
+ }
232
+ }
233
+ buildFullTextResponse(text, isThought, groundingMetadata) {
234
+ const part = { text };
235
+ if (isThought) {
236
+ part.thought = true;
237
+ }
238
+ const response = {
239
+ content: {
240
+ role: "model",
241
+ parts: [part]
242
+ },
243
+ partial: false
244
+ };
245
+ if (groundingMetadata !== void 0 && groundingMetadata !== null) {
246
+ response.groundingMetadata = groundingMetadata;
247
+ }
248
+ if (this.modelVersion) {
249
+ response.modelVersion = this.modelVersion;
250
+ }
251
+ return response;
252
+ }
253
+ }
254
+ export {
255
+ LiveResponseAggregator
256
+ };
@@ -46,6 +46,13 @@ function isGemini2OrAbove(modelString) {
46
46
  const parsedVersion = parseVersion(versionString);
47
47
  return parsedVersion.valid && parsedVersion.major >= 2;
48
48
  }
49
+ function isGemini3xFlashLive(modelString) {
50
+ if (!modelString) {
51
+ return false;
52
+ }
53
+ const modelName = extractModelName(modelString);
54
+ return modelName.startsWith("gemini-3.") && modelName.includes("-flash-live");
55
+ }
49
56
  function isGeminiModelIdCheckDisabled() {
50
57
  return getBooleanEnvVar("ADK_DISABLE_GEMINI_MODEL_ID_CHECK");
51
58
  }
@@ -53,6 +60,7 @@ export {
53
60
  extractModelName,
54
61
  isGemini1Model,
55
62
  isGemini2OrAbove,
63
+ isGemini3xFlashLive,
56
64
  isGeminiModel,
57
65
  isGeminiModelIdCheckDisabled
58
66
  };
@@ -12,6 +12,7 @@ import { JSONPath } from "jsonpath-plus";
12
12
  import { generateClientFunctionCallId } from "../agents/functions.js";
13
13
  import { FeatureName, isFeatureEnabled } from "../features/feature_registry.js";
14
14
  import { createLlmResponse } from "../models/llm_response.js";
15
+ const UNSAFE_PROPERTY_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
15
16
  class ProgressiveStrategy {
16
17
  constructor() {
17
18
  this.partsSequence = [];
@@ -78,10 +79,13 @@ class ProgressiveStrategy {
78
79
  const pathParts = JSONPath.toPathArray(jsonPath).filter(
79
80
  (p) => p !== "$" && p !== "$["
80
81
  );
82
+ if (pathParts.some((part) => UNSAFE_PROPERTY_KEYS.has(String(part)))) {
83
+ return;
84
+ }
81
85
  let current = this.currentFcArgs;
82
86
  for (let i = 0; i < pathParts.length - 1; i++) {
83
87
  const part = pathParts[i];
84
- if (!(part in current)) {
88
+ if (!Object.prototype.hasOwnProperty.call(current, part)) {
85
89
  current[part] = {};
86
90
  }
87
91
  current = current[part];
@@ -273,17 +277,13 @@ class StreamingResponseAggregator {
273
277
  )) {
274
278
  this.isProgressiveMode = isProgressiveMode;
275
279
  this.lastThoughtSignature = {};
276
- this.sawFunctionCall = false;
277
280
  this.strategy = this.isProgressiveMode ? new ProgressiveStrategy() : new NonProgressiveStrategy();
278
281
  }
279
282
  async *processResponse(response) {
280
283
  var _a, _b;
281
284
  const llmResponse = createLlmResponse(response);
282
285
  const parts = (_b = (_a = llmResponse.content) == null ? void 0 : _a.parts) != null ? _b : [];
283
- if (parts.some((part) => part.functionCall)) {
284
- this.sawFunctionCall = true;
285
- }
286
- if (this.sawFunctionCall && llmResponse.finishReason === FinishReason.STOP && parts.length > 0 && parts.every(isEmptyContentPart)) {
286
+ if (parts.every(isEmptyContentPart) && (llmResponse.finishReason === void 0 || llmResponse.finishReason === FinishReason.STOP)) {
287
287
  if (llmResponse.usageMetadata) {
288
288
  this.usageMetadata = llmResponse.usageMetadata;
289
289
  }
@@ -323,7 +323,8 @@ class StreamingResponseAggregator {
323
323
  close() {
324
324
  var _a, _b, _c;
325
325
  const finalParts = this.strategy.close();
326
- if (!finalParts) {
326
+ const hasMetadata = this.usageMetadata !== void 0 || this.groundingMetadata !== void 0 || this.citationMetadata !== void 0;
327
+ if (!finalParts && !hasMetadata) {
327
328
  return void 0;
328
329
  }
329
330
  const candidate = (_b = (_a = this.response) == null ? void 0 : _a.candidates) == null ? void 0 : _b[0];
@@ -331,7 +332,7 @@ class StreamingResponseAggregator {
331
332
  return {
332
333
  content: {
333
334
  role: "model",
334
- parts: finalParts
335
+ parts: finalParts != null ? finalParts : []
335
336
  },
336
337
  groundingMetadata: this.groundingMetadata,
337
338
  citationMetadata: this.citationMetadata,
@@ -5,7 +5,7 @@ const require = topLevelCreateRequire(import.meta.url);
5
5
  * Copyright 2025 Google LLC
6
6
  * SPDX-License-Identifier: Apache-2.0
7
7
  */
8
- const version = "1.2.0";
8
+ const version = "1.3.0";
9
9
  export {
10
10
  version
11
11
  };
@@ -13,26 +13,51 @@ export interface UserFunctionCall {
13
13
  contextId: string;
14
14
  }
15
15
  /**
16
- * Returns a UserFunctionCall when the event at index has a FunctionResponse.
16
+ * Returns a UserFunctionCall when the event at `index` contains a
17
+ * FunctionResponse that can be traced back to a preceding FunctionCall event.
18
+ *
19
+ * @param session - The session whose event history to inspect.
20
+ * @param index - Index of the candidate event to examine.
21
+ * @returns The matching `UserFunctionCall`, or `undefined` if the event at
22
+ * `index` is not a user function-response event or has no preceding call.
17
23
  */
18
24
  export declare function getUserFunctionCallAt(session: Session, index: number): UserFunctionCall | undefined;
19
25
  /**
20
26
  * Checks if an event contains a function call with the given ID.
27
+ *
28
+ * @param event - The event to inspect.
29
+ * @param callId - The function call ID to look for.
30
+ * @returns `true` if a part in the event has a matching `functionCall.id`.
21
31
  */
22
32
  export declare function isFunctionCallEvent(event: AdkEvent, callId: string): boolean;
23
33
  /**
24
34
  * Finds the first part with a FunctionResponse and returns the call ID.
35
+ *
36
+ * @param event - The event to inspect.
37
+ * @returns The `id` of the first FunctionResponse part, or `undefined` if
38
+ * none is found.
25
39
  */
26
40
  export declare function getFunctionResponseCallId(event: AdkEvent): string | undefined;
27
41
  /**
28
- * Returns content parts for all events not present in the remote session
29
- * and a2a contextId if found in a remote agent event metadata.
42
+ * Returns A2A content parts for all events not yet seen by the remote agent,
43
+ * along with the A2A context ID found in the most recent remote agent event.
44
+ *
45
+ * @param ctx - The current invocation context, used to identify the remote
46
+ * agent's authored events.
47
+ * @param session - The local session whose event history to diff.
48
+ * @returns An object with the missing `parts` and an optional `contextId`.
30
49
  */
31
50
  export declare function toMissingRemoteSessionParts(ctx: InvocationContext, session: Session): {
32
51
  parts: A2APart[];
33
52
  contextId?: string;
34
53
  };
35
54
  /**
36
- * Wraps an agent event as a user message for context.
55
+ * Wraps an agent event as a user message so it can be sent as context to a
56
+ * remote agent that only accepts user-role messages.
57
+ *
58
+ * @param ctx - The current invocation context.
59
+ * @param agentEvent - The agent-authored event to reframe as a user message.
60
+ * @returns A new event with `author: 'user'` whose parts summarise the
61
+ * original agent event's text, function calls, and function responses.
37
62
  */
38
63
  export declare function presentAsUserMessage(ctx: InvocationContext, agentEvent: AdkEvent): AdkEvent;
@@ -8,6 +8,12 @@ import { Event as AdkEvent } from '../events/event.js';
8
8
  import { A2AEvent } from './a2a_event.js';
9
9
  /**
10
10
  * Converts a session Event to an A2A Message.
11
+ *
12
+ * @param event - The ADK event to convert.
13
+ * @param appName - The name of the ADK application.
14
+ * @param userId - The ID of the current user.
15
+ * @param sessionId - The ID of the current session.
16
+ * @returns An A2A message with the event's parts and metadata.
11
17
  */
12
18
  export declare function toA2AMessage(event: AdkEvent, { appName, userId, sessionId, }: {
13
19
  appName: string;
@@ -15,6 +21,13 @@ export declare function toA2AMessage(event: AdkEvent, { appName, userId, session
15
21
  sessionId: string;
16
22
  }): Message;
17
23
  /**
18
- * Converts an A2A Event to a Session Event.
24
+ * Converts an A2A Event to an ADK Session Event.
25
+ *
26
+ * @param event - The A2A event to convert (message, task, artifact update, or
27
+ * status update).
28
+ * @param invocationId - The ADK invocation ID to attach to the resulting event.
29
+ * @param agentName - The name of the agent to use as the event author.
30
+ * @returns The converted ADK event, or `undefined` if the A2A event type
31
+ * produces no content.
19
32
  */
20
33
  export declare function toAdkEvent(event: A2AEvent, invocationId: string, agentName: string): AdkEvent | undefined;
@@ -39,10 +39,19 @@ export declare enum AdkMetadataKeys {
39
39
  }
40
40
  /**
41
41
  * Creates ADK Event metadata from an A2A Event.
42
+ *
43
+ * @param a2aEvent - The A2A event to extract metadata from.
44
+ * @returns A record containing the ADK task ID and context ID keys.
42
45
  */
43
46
  export declare function getAdkEventMetadata(a2aEvent: A2AEvent): Record<string, unknown>;
44
47
  /**
45
48
  * Creates A2A Event metadata from an ADK Event.
49
+ *
50
+ * @param adkEvent - The ADK event to extract metadata from.
51
+ * @param appName - The name of the ADK application.
52
+ * @param userId - The ID of the current user.
53
+ * @param sessionId - The ID of the current session.
54
+ * @returns A record of A2A metadata keys populated from the ADK event.
46
55
  */
47
56
  export declare function getA2AEventMetadata(adkEvent: AdkEvent, { appName, userId, sessionId, }: {
48
57
  appName: string;
@@ -51,6 +60,11 @@ export declare function getA2AEventMetadata(adkEvent: AdkEvent, { appName, userI
51
60
  }): Record<string, unknown>;
52
61
  /**
53
62
  * Creates A2A Session metadata from ADK Event invocation metadata.
63
+ *
64
+ * @param appName - The name of the ADK application.
65
+ * @param userId - The ID of the current user.
66
+ * @param sessionId - The ID of the current session.
67
+ * @returns A record of A2A metadata keys for app name, user ID, and session ID.
54
68
  */
55
69
  export declare function getA2ASessionMetadata({ appName, userId, sessionId, }: {
56
70
  appName: string;
@@ -59,5 +73,9 @@ export declare function getA2ASessionMetadata({ appName, userId, sessionId, }: {
59
73
  }): Record<string, unknown>;
60
74
  /**
61
75
  * Creates A2A Event metadata from ADK Event actions.
76
+ *
77
+ * @param actions - The ADK event actions to extract escalation and transfer
78
+ * metadata from.
79
+ * @returns A record with escalate and transfer-to-agent A2A metadata keys.
62
80
  */
63
81
  export declare function getA2AEventMetadataFromActions(actions: AdkEventActions): Record<string, unknown>;
@@ -6,43 +6,88 @@
6
6
  import { DataPart as A2ADataPart, FilePart as A2AFilePart, Part as A2APart, TextPart as A2ATextPart, Message } from '@a2a-js/sdk';
7
7
  import { Content as GenAIContent, Part as GenAIPart } from '@google/genai';
8
8
  /**
9
- * Converts GenAI Parts to A2A Parts.
9
+ * Converts an array of GenAI Parts to A2A Parts.
10
+ *
11
+ * @param parts - The GenAI parts to convert. Defaults to an empty array.
12
+ * @param longRunningToolIDs - IDs of function calls that are long-running.
13
+ * @returns An array of A2A parts.
10
14
  */
11
15
  export declare function toA2AParts(parts?: GenAIPart[], longRunningToolIDs?: string[]): A2APart[];
12
16
  /**
13
- * Converts a GenAI Part to an A2A Part.
17
+ * Converts a single GenAI Part to the appropriate A2A Part type.
18
+ *
19
+ * @param part - The GenAI part to convert.
20
+ * @param longRunningToolIDs - IDs of function calls that are long-running.
21
+ * @returns The corresponding A2A part (text, file, or data).
14
22
  */
15
23
  export declare function toA2APart(part: GenAIPart, longRunningToolIDs?: string[]): A2APart;
16
24
  /**
17
25
  * Converts a GenAI Text Part to an A2A Text Part.
26
+ *
27
+ * @param part - The GenAI part containing a text field.
28
+ * @returns An A2A text part, with thought metadata attached if applicable.
18
29
  */
19
30
  export declare function toA2ATextPart(part: GenAIPart): A2APart;
20
31
  /**
21
32
  * Converts a GenAI File Part to an A2A File Part.
33
+ *
34
+ * @param part - The GenAI part containing `fileData` or `inlineData`.
35
+ * @returns An A2A file part with URI or bytes depending on the source.
36
+ * @throws {Error} If the part contains neither `fileData` nor `inlineData`.
22
37
  */
23
38
  export declare function toA2AFilePart(part: GenAIPart): A2APart;
24
39
  /**
25
- * Converts a GenAI Data Part to an A2A Data Part.
40
+ * Converts a GenAI Data Part (function call/response or code) to an A2A Data Part.
41
+ *
42
+ * @param part - The GenAI part containing structured data.
43
+ * @param longRunningToolIDs - IDs of function calls that are long-running.
44
+ * @returns An A2A data part with the appropriate type metadata.
26
45
  */
27
46
  export declare function toA2ADataPart(part: GenAIPart, longRunningToolIDs?: string[]): A2APart;
47
+ /**
48
+ * Converts an A2A Message to a GenAI Content object.
49
+ *
50
+ * @param a2aMessage - The A2A message to convert.
51
+ * @returns A GenAI user or model content object based on the message role.
52
+ */
28
53
  export declare function toGenAIContent(a2aMessage: Message): GenAIContent;
29
54
  /**
30
- * Converts an A2A Part to a GenAI Part.
55
+ * Converts an array of A2A Parts to GenAI Parts.
56
+ *
57
+ * @param a2aParts - The A2A parts to convert.
58
+ * @returns An array of GenAI parts.
31
59
  */
32
60
  export declare function toGenAIParts(a2aParts: A2APart[]): GenAIPart[];
33
61
  /**
34
- * Converts an A2A Part to a GenAI Part.
62
+ * Converts a single A2A Part to the appropriate GenAI Part type.
63
+ *
64
+ * @param a2aPart - The A2A part to convert.
65
+ * @returns The corresponding GenAI part.
66
+ * @throws {Error} If the A2A part has an unrecognized `kind`.
35
67
  */
36
68
  export declare function toGenAIPart(a2aPart: A2APart): GenAIPart;
37
69
  /**
38
70
  * Converts an A2A Text Part to a GenAI Part.
71
+ *
72
+ * @param a2aPart - The A2A text part to convert.
73
+ * @returns A GenAI part with `text` and optional `thought` flag.
39
74
  */
40
75
  export declare function toGenAIPartText(a2aPart: A2ATextPart): GenAIPart;
41
76
  /**
42
77
  * Converts an A2A File Part to a GenAI Part.
78
+ *
79
+ * @param a2aPart - The A2A file part containing bytes or a URI.
80
+ * @returns A GenAI part with `inlineData` or `fileData` depending on the
81
+ * source, with optional video metadata attached.
82
+ * @throws {Error} If the file part contains neither bytes nor a URI.
43
83
  */
44
84
  export declare function toGenAIPartFile(a2aPart: A2AFilePart): GenAIPart;
45
85
  /**
46
- * Converts an A2A Data Part to a GenAI Part.
86
+ * Converts an A2A Data Part to the appropriate GenAI Part.
87
+ *
88
+ * @param a2aPart - The A2A data part containing structured data and type metadata.
89
+ * @returns A GenAI part with the appropriate function call, function response,
90
+ * or code execution fields, falling back to a JSON text part if the type is
91
+ * unrecognized.
47
92
  */
48
93
  export declare function toGenAIPartData(a2aPart: A2ADataPart): GenAIPart;
@@ -12,7 +12,6 @@ import { BaseSessionService } from '../sessions/base_session_service.js';
12
12
  import { Session } from '../sessions/session.js';
13
13
  import { ActiveStreamingTool } from './active_streaming_tool.js';
14
14
  import { BaseAgent } from './base_agent.js';
15
- import { LiveRequestQueue } from './live_request_queue.js';
16
15
  import { RunConfig } from './run_config.js';
17
16
  import { TranscriptionEntry } from './transcription_entry.js';
18
17
  /**
@@ -31,7 +30,6 @@ export interface InvocationContextParams {
31
30
  endInvocation?: boolean;
32
31
  transcriptionCache?: TranscriptionEntry[];
33
32
  runConfig?: RunConfig;
34
- liveRequestQueue?: LiveRequestQueue;
35
33
  activeStreamingTools?: Record<string, ActiveStreamingTool>;
36
34
  pluginManager: PluginManager;
37
35
  abortSignal?: AbortSignal;
@@ -124,10 +122,6 @@ export declare class InvocationContext {
124
122
  * this invocation.
125
123
  */
126
124
  private readonly invocationCostManager;
127
- /**
128
- * The queue to receive live requests.
129
- */
130
- liveRequestQueue?: LiveRequestQueue;
131
125
  /**
132
126
  * The running streaming tools of this invocation.
133
127
  */
@@ -136,9 +130,6 @@ export declare class InvocationContext {
136
130
  * The manager for keeping track of plugins in this invocation.
137
131
  */
138
132
  pluginManager: PluginManager;
139
- /**
140
- * The abort signal for the invocation.
141
- */
142
133
  readonly abortSignal?: AbortSignal;
143
134
  /**
144
135
  * @param params The parameters for creating an invocation context.
@@ -327,6 +327,20 @@ export declare class LlmAgent extends BaseAgent {
327
327
  private maybeSaveOutputToState;
328
328
  protected runAsyncImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
329
329
  protected runLiveImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
330
+ /**
331
+ * Runs the bidirectional (live) flow for this agent.
332
+ *
333
+ * Establishes a live connection to the model, drains the invocation's
334
+ * `liveRequestQueue` into the connection on a parallel task, and yields
335
+ * events derived from server messages until the queue closes, the model
336
+ * finishes, or an agent transfer occurs.
337
+ *
338
+ * If the live connection drops (network failure, server `goAway`) and a
339
+ * session resumption handle has been observed, the flow transparently
340
+ * reconnects using that handle up to {@link MAX_LIVE_RECONNECT_ATTEMPTS}
341
+ * times. Subsequent reconnects skip `sendHistory` because the server
342
+ * already holds the conversation state associated with the handle.
343
+ */
330
344
  private runLiveFlow;
331
345
  private runOneStepAsync;
332
346
  private postprocess;
@@ -7,9 +7,23 @@ import { Event } from '../../events/event.js';
7
7
  import { LlmRequest } from '../../models/llm_request.js';
8
8
  import { InvocationContext } from '../invocation_context.js';
9
9
  import { BaseLlmRequestProcessor } from './base_llm_processor.js';
10
+ /**
11
+ * Augments the {@link LlmRequest} to support agent transfer. When the current
12
+ * agent has reachable transfer targets (sub-agents, peer agents, or a parent
13
+ * agent), this processor registers a `transfer_to_agent` function tool and
14
+ * appends instructions describing each candidate so the model can choose to
15
+ * hand off control.
16
+ */
10
17
  export declare class AgentTransferLlmRequestProcessor extends BaseLlmRequestProcessor {
11
18
  private readonly toolName;
12
19
  private readonly tool;
20
+ /**
21
+ * Appends transfer instructions and registers the `transfer_to_agent` tool
22
+ * when the agent has reachable transfer targets.
23
+ *
24
+ * @param invocationContext - The current invocation context.
25
+ * @param llmRequest - The request to augment with transfer instructions and the transfer tool.
26
+ */
13
27
  runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event, void, void>;
14
28
  private buildTargetAgentsInfo;
15
29
  private buildTargetAgentsInstructions;
@@ -13,6 +13,13 @@ import { BaseLlmRequestProcessor } from './base_llm_processor.js';
13
13
  * connect settings.
14
14
  */
15
15
  export declare class BasicLlmRequestProcessor extends BaseLlmRequestProcessor {
16
+ /**
17
+ * Populates model name, generation config, output schema, and live connect
18
+ * settings on the request from the agent and run config.
19
+ *
20
+ * @param invocationContext - The current invocation context.
21
+ * @param llmRequest - The request object to populate in place.
22
+ */
16
23
  runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event, void, void>;
17
24
  }
18
25
  export declare const BASIC_LLM_REQUEST_PROCESSOR: BasicLlmRequestProcessor;