@softactivate/adk 1.1.0 → 1.2.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 (141) hide show
  1. package/dist/cjs/agents/functions.js +4 -0
  2. package/dist/cjs/auth/oauth2/oauth2_discovery.js +26 -2
  3. package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +305 -0
  4. package/dist/cjs/code_executors/code_execution_utils.js +1 -1
  5. package/dist/cjs/common.js +3 -0
  6. package/dist/cjs/events/event.js +2 -0
  7. package/dist/cjs/index.js +14 -0
  8. package/dist/cjs/integrations/agent_registry/agent_registry.js +362 -0
  9. package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +103 -0
  10. package/dist/cjs/integrations/agent_registry/helpers.js +57 -0
  11. package/dist/cjs/integrations/agent_registry/types.js +50 -0
  12. package/dist/cjs/memory/vertex_ai_memory_bank_service.js +496 -0
  13. package/dist/cjs/runner/in_memory_runner.js +10 -5
  14. package/dist/cjs/runner/runner.js +32 -2
  15. package/dist/cjs/sessions/database_session_service.js +49 -3
  16. package/dist/cjs/sessions/in_memory_session_service.js +70 -14
  17. package/dist/cjs/sessions/registry.js +4 -0
  18. package/dist/cjs/sessions/vertex_ai_session_service.js +428 -0
  19. package/dist/cjs/tools/agent_tool.js +17 -8
  20. package/dist/cjs/tools/exit_loop_tool.js +9 -0
  21. package/dist/cjs/tools/function_tool.js +7 -2
  22. package/dist/cjs/tools/long_running_tool.js +2 -1
  23. package/dist/cjs/tools/mcp/mcp_session_manager.js +11 -0
  24. package/dist/cjs/tools/mcp/mcp_tool.js +10 -7
  25. package/dist/cjs/tools/mcp/mcp_toolset.js +10 -2
  26. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +78 -0
  27. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +84 -0
  28. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +133 -0
  29. package/dist/cjs/tools/skill/load_skill_resource_tool.js +2 -25
  30. package/dist/cjs/utils/file_utils.js +28 -0
  31. package/dist/cjs/utils/gemini_schema_util.js +18 -0
  32. package/dist/cjs/utils/partial_copy.js +51 -0
  33. package/dist/cjs/utils/streaming_utils.js +167 -118
  34. package/dist/cjs/utils/vertex_ai_utils.js +50 -0
  35. package/dist/cjs/version.js +1 -1
  36. package/dist/esm/agents/functions.js +4 -0
  37. package/dist/esm/auth/oauth2/oauth2_discovery.js +26 -2
  38. package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +281 -0
  39. package/dist/esm/code_executors/code_execution_utils.js +1 -1
  40. package/dist/esm/common.js +2 -0
  41. package/dist/esm/events/event.js +2 -0
  42. package/dist/esm/index.js +11 -0
  43. package/dist/esm/integrations/agent_registry/agent_registry.js +333 -0
  44. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +77 -0
  45. package/dist/esm/integrations/agent_registry/helpers.js +28 -0
  46. package/dist/esm/integrations/agent_registry/types.js +20 -0
  47. package/dist/esm/memory/vertex_ai_memory_bank_service.js +468 -0
  48. package/dist/esm/runner/in_memory_runner.js +10 -5
  49. package/dist/esm/runner/runner.js +32 -2
  50. package/dist/esm/sessions/database_session_service.js +49 -3
  51. package/dist/esm/sessions/in_memory_session_service.js +70 -14
  52. package/dist/esm/sessions/registry.js +7 -0
  53. package/dist/esm/sessions/vertex_ai_session_service.js +403 -0
  54. package/dist/esm/tools/agent_tool.js +17 -8
  55. package/dist/esm/tools/exit_loop_tool.js +9 -0
  56. package/dist/esm/tools/function_tool.js +7 -2
  57. package/dist/esm/tools/long_running_tool.js +2 -1
  58. package/dist/esm/tools/mcp/mcp_session_manager.js +11 -0
  59. package/dist/esm/tools/mcp/mcp_tool.js +10 -7
  60. package/dist/esm/tools/mcp/mcp_toolset.js +10 -2
  61. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +48 -0
  62. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
  63. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
  64. package/dist/esm/tools/skill/load_skill_resource_tool.js +1 -24
  65. package/dist/esm/utils/file_utils.js +26 -0
  66. package/dist/esm/utils/gemini_schema_util.js +18 -0
  67. package/dist/esm/utils/partial_copy.js +23 -0
  68. package/dist/esm/utils/streaming_utils.js +165 -117
  69. package/dist/esm/utils/vertex_ai_utils.js +22 -0
  70. package/dist/esm/version.js +1 -1
  71. package/dist/types/a2a/a2a_remote_agent.d.ts +14 -0
  72. package/dist/types/agents/processors/base_llm_processor.d.ts +12 -4
  73. package/dist/types/agents/processors/basic_llm_request_processor.d.ts +5 -0
  74. package/dist/types/agents/processors/identity_llm_request_processor.d.ts +4 -0
  75. package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +5 -0
  76. package/dist/types/agents/run_config.d.ts +15 -0
  77. package/dist/types/code_executors/agent_engine_sandbox_code_executor.d.ts +51 -0
  78. package/dist/types/common.d.ts +2 -0
  79. package/dist/types/events/event_actions.d.ts +24 -6
  80. package/dist/types/events/structured_events.d.ts +13 -0
  81. package/dist/types/examples/example_util.d.ts +25 -0
  82. package/dist/types/index.d.ts +6 -0
  83. package/dist/types/integrations/agent_registry/agent_registry.d.ts +94 -0
  84. package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +43 -0
  85. package/dist/types/integrations/agent_registry/helpers.d.ts +7 -0
  86. package/dist/types/integrations/agent_registry/types.d.ts +101 -0
  87. package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +52 -0
  88. package/dist/types/runner/in_memory_runner.d.ts +28 -1
  89. package/dist/types/runner/runner.d.ts +47 -0
  90. package/dist/types/sessions/base_session_service.d.ts +18 -0
  91. package/dist/types/sessions/database_session_service.d.ts +1 -1
  92. package/dist/types/sessions/in_memory_session_service.d.ts +1 -1
  93. package/dist/types/sessions/vertex_ai_session_service.d.ts +37 -0
  94. package/dist/types/tools/exit_loop_tool.d.ts +9 -0
  95. package/dist/types/tools/function_tool.d.ts +22 -2
  96. package/dist/types/tools/long_running_tool.d.ts +11 -1
  97. package/dist/types/tools/mcp/mcp_session_manager.d.ts +3 -0
  98. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +25 -0
  99. package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +20 -0
  100. package/dist/types/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.d.ts +20 -0
  101. package/dist/types/utils/file_utils.d.ts +2 -0
  102. package/dist/types/utils/partial_copy.d.ts +13 -0
  103. package/dist/types/utils/streaming_utils.d.ts +8 -17
  104. package/dist/types/utils/vertex_ai_utils.d.ts +14 -0
  105. package/dist/types/version.d.ts +1 -1
  106. package/dist/web/agents/functions.js +4 -0
  107. package/dist/web/auth/oauth2/oauth2_discovery.js +26 -2
  108. package/dist/web/code_executors/agent_engine_sandbox_code_executor.js +281 -0
  109. package/dist/web/code_executors/code_execution_utils.js +1 -1
  110. package/dist/web/common.js +2 -0
  111. package/dist/web/events/event.js +2 -0
  112. package/dist/web/index.js +11 -0
  113. package/dist/web/integrations/agent_registry/agent_registry.js +333 -0
  114. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +90 -0
  115. package/dist/web/integrations/agent_registry/helpers.js +28 -0
  116. package/dist/web/integrations/agent_registry/types.js +20 -0
  117. package/dist/web/memory/vertex_ai_memory_bank_service.js +475 -0
  118. package/dist/web/runner/in_memory_runner.js +10 -5
  119. package/dist/web/runner/runner.js +32 -2
  120. package/dist/web/sessions/database_session_service.js +49 -3
  121. package/dist/web/sessions/in_memory_session_service.js +70 -14
  122. package/dist/web/sessions/registry.js +7 -0
  123. package/dist/web/sessions/vertex_ai_session_service.js +414 -0
  124. package/dist/web/tools/agent_tool.js +17 -8
  125. package/dist/web/tools/exit_loop_tool.js +9 -0
  126. package/dist/web/tools/function_tool.js +7 -2
  127. package/dist/web/tools/long_running_tool.js +2 -1
  128. package/dist/web/tools/mcp/mcp_session_manager.js +11 -0
  129. package/dist/web/tools/mcp/mcp_tool.js +10 -7
  130. package/dist/web/tools/mcp/mcp_toolset.js +10 -2
  131. package/dist/web/tools/openapi_tool/auth/auth_helpers.js +48 -0
  132. package/dist/web/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
  133. package/dist/web/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
  134. package/dist/web/tools/skill/load_skill_resource_tool.js +1 -24
  135. package/dist/web/utils/file_utils.js +26 -0
  136. package/dist/web/utils/gemini_schema_util.js +18 -0
  137. package/dist/web/utils/partial_copy.js +23 -0
  138. package/dist/web/utils/streaming_utils.js +218 -117
  139. package/dist/web/utils/vertex_ai_utils.js +22 -0
  140. package/dist/web/version.js +1 -1
  141. package/package.json +2 -1
@@ -24,7 +24,8 @@ var __copyProps = (to, from, except, desc) => {
24
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
25
  var streaming_utils_exports = {};
26
26
  __export(streaming_utils_exports, {
27
- StreamingResponseAggregator: () => StreamingResponseAggregator
27
+ StreamingResponseAggregator: () => StreamingResponseAggregator,
28
+ isEmptyContentPart: () => isEmptyContentPart
28
29
  });
29
30
  module.exports = __toCommonJS(streaming_utils_exports);
30
31
  var import_genai = require("@google/genai");
@@ -37,15 +38,8 @@ var import_llm_response = require("../models/llm_response.js");
37
38
  * Copyright 2026 Google LLC
38
39
  * SPDX-License-Identifier: Apache-2.0
39
40
  */
40
- class StreamingResponseAggregator {
41
- constructor(isProgressiveMode = (0, import_feature_registry.isFeatureEnabled)(
42
- import_feature_registry.FeatureName.PROGRESSIVE_SSE_STREAMING
43
- )) {
44
- this.isProgressiveMode = isProgressiveMode;
45
- // For non-progressive SSE streaming mode
46
- this.text = "";
47
- this.thoughtText = "";
48
- // For progressive SSE streaming mode: accumulate parts in order
41
+ class ProgressiveStrategy {
42
+ constructor() {
49
43
  this.partsSequence = [];
50
44
  this.currentTextBuffer = "";
51
45
  this.currentFcArgs = {};
@@ -172,11 +166,6 @@ class StreamingResponseAggregator {
172
166
  if (!fc) {
173
167
  return;
174
168
  }
175
- if (part.thoughtSignature) {
176
- this.lastThoughtSignature = part.thoughtSignature;
177
- } else if (this.lastThoughtSignature) {
178
- part.thoughtSignature = this.lastThoughtSignature.toString();
179
- }
180
169
  if (fc.partialArgs || fc.willContinue) {
181
170
  if (!fc.id && !this.currentFcId) {
182
171
  fc.id = (0, import_functions.generateClientFunctionCallId)();
@@ -195,108 +184,102 @@ class StreamingResponseAggregator {
195
184
  }
196
185
  }
197
186
  }
198
- async *processResponse(response) {
199
- var _a, _b, _c;
200
- this.response = response;
201
- const llmResponse = (0, import_llm_response.createLlmResponse)(response);
202
- this.usageMetadata = llmResponse.usageMetadata;
203
- if (llmResponse.groundingMetadata) {
204
- this.groundingMetadata = llmResponse.groundingMetadata;
205
- }
206
- if (llmResponse.citationMetadata) {
207
- this.citationMetadata = llmResponse.citationMetadata;
208
- }
209
- if (llmResponse.finishReason) {
210
- this.finishReason = llmResponse.finishReason;
211
- }
187
+ async *processResponse(llmResponse) {
188
+ var _a;
212
189
  if (llmResponse.content && llmResponse.content.parts) {
213
190
  for (const part of llmResponse.content.parts) {
214
- if (part.thoughtSignature) {
215
- this.lastThoughtSignature = part.thoughtSignature;
216
- } else if (part.functionCall && this.lastThoughtSignature) {
217
- part.thoughtSignature = this.lastThoughtSignature.toString();
191
+ if (part.text) {
192
+ const isThought = (_a = part.thought) != null ? _a : false;
193
+ if (this.currentTextBuffer && isThought !== this.currentTextIsThought) {
194
+ this.flushTextBufferToSequence();
195
+ }
196
+ if (!this.currentTextBuffer) {
197
+ this.currentTextIsThought = isThought;
198
+ }
199
+ this.currentTextBuffer += part.text;
200
+ } else if (part.functionCall) {
201
+ this.processFunctionCallPart(part);
202
+ } else {
203
+ this.flushTextBufferToSequence();
204
+ this.partsSequence.push(part);
218
205
  }
219
206
  }
220
207
  }
221
- if (this.isProgressiveMode) {
222
- if (llmResponse.content && llmResponse.content.parts) {
223
- for (const part of llmResponse.content.parts) {
224
- if (part.text) {
225
- const isThought = (_a = part.thought) != null ? _a : false;
226
- if (this.currentTextBuffer && isThought !== this.currentTextIsThought) {
227
- this.flushTextBufferToSequence();
228
- }
229
- if (!this.currentTextBuffer) {
230
- this.currentTextIsThought = isThought;
231
- }
232
- this.currentTextBuffer += part.text;
233
- } else if (part.functionCall) {
234
- this.processFunctionCallPart(part);
208
+ llmResponse.partial = true;
209
+ yield llmResponse;
210
+ }
211
+ close() {
212
+ this.flushTextBufferToSequence();
213
+ this.flushFunctionCallToSequence();
214
+ const finalParts = this.partsSequence;
215
+ if (finalParts.length === 0) {
216
+ return void 0;
217
+ }
218
+ return finalParts;
219
+ }
220
+ }
221
+ class NonProgressiveStrategy {
222
+ constructor() {
223
+ this.text = "";
224
+ this.thoughtText = "";
225
+ }
226
+ async *processResponse(llmResponse) {
227
+ var _a;
228
+ if ((_a = llmResponse.content) == null ? void 0 : _a.parts) {
229
+ const nonTextParts = [];
230
+ let sawTextPart = false;
231
+ for (const part of llmResponse.content.parts) {
232
+ if (typeof part.text === "string") {
233
+ sawTextPart = true;
234
+ if (part.thought) {
235
+ this.thoughtText += part.text;
235
236
  } else {
236
- this.flushTextBufferToSequence();
237
- this.partsSequence.push(part);
237
+ this.text += part.text;
238
238
  }
239
+ continue;
239
240
  }
241
+ if (part.functionCall && !part.functionCall.id) {
242
+ part.functionCall.id = (0, import_functions.generateClientFunctionCallId)();
243
+ }
244
+ nonTextParts.push(part);
240
245
  }
241
- llmResponse.partial = true;
242
- yield llmResponse;
243
- return;
244
- }
245
- if (llmResponse.content && llmResponse.content.parts && typeof ((_b = llmResponse.content.parts[0]) == null ? void 0 : _b.text) === "string") {
246
- const part0 = llmResponse.content.parts[0];
247
- const partText = part0.text || "";
248
- if (part0.thought) {
249
- this.thoughtText += partText;
250
- } else {
251
- this.text += partText;
252
- }
253
- llmResponse.partial = true;
254
- } else if ((this.thoughtText || this.text) && (!llmResponse.content || !llmResponse.content.parts || !((_c = llmResponse.content.parts[0]) == null ? void 0 : _c.inlineData))) {
255
- const parts = [];
256
- if (this.thoughtText) {
257
- parts.push({ text: this.thoughtText, thought: true });
246
+ if (nonTextParts.length > 0) {
247
+ if (this.thoughtText || this.text) {
248
+ const parts = [];
249
+ if (this.thoughtText) {
250
+ parts.push({ text: this.thoughtText, thought: true });
251
+ }
252
+ if (this.text) {
253
+ parts.push({ text: this.text });
254
+ }
255
+ yield {
256
+ content: {
257
+ role: "model",
258
+ parts
259
+ },
260
+ usageMetadata: llmResponse.usageMetadata,
261
+ partial: false
262
+ };
263
+ this.thoughtText = "";
264
+ this.text = "";
265
+ }
266
+ yield {
267
+ ...llmResponse,
268
+ content: {
269
+ role: llmResponse.content.role,
270
+ parts: nonTextParts
271
+ },
272
+ partial: false
273
+ };
274
+ return;
258
275
  }
259
- if (this.text) {
260
- parts.push({ text: this.text });
276
+ if (sawTextPart) {
277
+ llmResponse.partial = true;
261
278
  }
262
- yield {
263
- content: {
264
- role: "model",
265
- parts
266
- },
267
- usageMetadata: llmResponse.usageMetadata,
268
- partial: false
269
- };
270
- this.thoughtText = "";
271
- this.text = "";
272
279
  }
273
280
  yield llmResponse;
274
281
  }
275
282
  close() {
276
- var _a, _b, _c, _d, _e, _f;
277
- if (this.isProgressiveMode) {
278
- this.flushTextBufferToSequence();
279
- this.flushFunctionCallToSequence();
280
- const finalParts = this.partsSequence;
281
- if (finalParts.length === 0) {
282
- return;
283
- }
284
- const candidate = (_b = (_a = this.response) == null ? void 0 : _a.candidates) == null ? void 0 : _b[0];
285
- const finishReason = (_c = this.finishReason) != null ? _c : candidate == null ? void 0 : candidate.finishReason;
286
- return {
287
- content: {
288
- role: "model",
289
- parts: finalParts
290
- },
291
- groundingMetadata: this.groundingMetadata,
292
- citationMetadata: this.citationMetadata,
293
- errorCode: finishReason === import_genai.FinishReason.STOP ? void 0 : finishReason,
294
- errorMessage: finishReason === import_genai.FinishReason.STOP ? void 0 : candidate == null ? void 0 : candidate.finishMessage,
295
- usageMetadata: this.usageMetadata,
296
- finishReason,
297
- partial: false
298
- };
299
- }
300
283
  if (this.text || this.thoughtText) {
301
284
  const parts = [];
302
285
  if (this.thoughtText) {
@@ -305,26 +288,92 @@ class StreamingResponseAggregator {
305
288
  if (this.text) {
306
289
  parts.push({ text: this.text });
307
290
  }
308
- const candidate = (_e = (_d = this.response) == null ? void 0 : _d.candidates) == null ? void 0 : _e[0];
309
- const finishReason = (_f = this.finishReason) != null ? _f : candidate == null ? void 0 : candidate.finishReason;
310
- return {
311
- content: {
312
- role: "model",
313
- parts
314
- },
315
- groundingMetadata: this.groundingMetadata,
316
- citationMetadata: this.citationMetadata,
317
- errorCode: finishReason === import_genai.FinishReason.STOP ? void 0 : finishReason,
318
- errorMessage: finishReason === import_genai.FinishReason.STOP ? void 0 : candidate == null ? void 0 : candidate.finishMessage,
319
- usageMetadata: this.usageMetadata,
320
- finishReason,
321
- partial: false
322
- };
291
+ return parts;
323
292
  }
324
293
  return void 0;
325
294
  }
326
295
  }
296
+ class StreamingResponseAggregator {
297
+ constructor(isProgressiveMode = (0, import_feature_registry.isFeatureEnabled)(
298
+ import_feature_registry.FeatureName.PROGRESSIVE_SSE_STREAMING
299
+ )) {
300
+ this.isProgressiveMode = isProgressiveMode;
301
+ this.lastThoughtSignature = {};
302
+ this.sawFunctionCall = false;
303
+ this.strategy = this.isProgressiveMode ? new ProgressiveStrategy() : new NonProgressiveStrategy();
304
+ }
305
+ async *processResponse(response) {
306
+ var _a, _b;
307
+ const llmResponse = (0, import_llm_response.createLlmResponse)(response);
308
+ const parts = (_b = (_a = llmResponse.content) == null ? void 0 : _a.parts) != null ? _b : [];
309
+ if (parts.some((part) => part.functionCall)) {
310
+ this.sawFunctionCall = true;
311
+ }
312
+ if (this.sawFunctionCall && llmResponse.finishReason === import_genai.FinishReason.STOP && parts.length > 0 && parts.every(isEmptyContentPart)) {
313
+ if (llmResponse.usageMetadata) {
314
+ this.usageMetadata = llmResponse.usageMetadata;
315
+ }
316
+ if (llmResponse.groundingMetadata) {
317
+ this.groundingMetadata = llmResponse.groundingMetadata;
318
+ }
319
+ if (llmResponse.citationMetadata) {
320
+ this.citationMetadata = llmResponse.citationMetadata;
321
+ }
322
+ if (llmResponse.finishReason) {
323
+ this.finishReason = llmResponse.finishReason;
324
+ }
325
+ return;
326
+ }
327
+ this.response = response;
328
+ this.usageMetadata = llmResponse.usageMetadata;
329
+ if (llmResponse.groundingMetadata) {
330
+ this.groundingMetadata = llmResponse.groundingMetadata;
331
+ }
332
+ if (llmResponse.citationMetadata) {
333
+ this.citationMetadata = llmResponse.citationMetadata;
334
+ }
335
+ if (llmResponse.finishReason) {
336
+ this.finishReason = llmResponse.finishReason;
337
+ }
338
+ if (llmResponse.content && llmResponse.content.parts) {
339
+ for (const part of llmResponse.content.parts) {
340
+ if (part.thoughtSignature) {
341
+ this.lastThoughtSignature.value = part.thoughtSignature;
342
+ } else if (part.functionCall && this.lastThoughtSignature.value) {
343
+ part.thoughtSignature = this.lastThoughtSignature.value.toString();
344
+ }
345
+ }
346
+ }
347
+ yield* this.strategy.processResponse(llmResponse);
348
+ }
349
+ close() {
350
+ var _a, _b, _c;
351
+ const finalParts = this.strategy.close();
352
+ if (!finalParts) {
353
+ return void 0;
354
+ }
355
+ const candidate = (_b = (_a = this.response) == null ? void 0 : _a.candidates) == null ? void 0 : _b[0];
356
+ const finishReason = (_c = this.finishReason) != null ? _c : candidate == null ? void 0 : candidate.finishReason;
357
+ return {
358
+ content: {
359
+ role: "model",
360
+ parts: finalParts
361
+ },
362
+ groundingMetadata: this.groundingMetadata,
363
+ citationMetadata: this.citationMetadata,
364
+ errorCode: finishReason === import_genai.FinishReason.STOP ? void 0 : finishReason,
365
+ errorMessage: finishReason === import_genai.FinishReason.STOP ? void 0 : candidate == null ? void 0 : candidate.finishMessage,
366
+ usageMetadata: this.usageMetadata,
367
+ finishReason,
368
+ partial: false
369
+ };
370
+ }
371
+ }
372
+ function isEmptyContentPart(part) {
373
+ return !part.functionCall && !part.functionResponse && !part.fileData && !part.inlineData && !part.executableCode && !part.codeExecutionResult && (!part.text || part.text === "");
374
+ }
327
375
  // Annotate the CommonJS export names for ESM import in node:
328
376
  0 && (module.exports = {
329
- StreamingResponseAggregator
377
+ StreamingResponseAggregator,
378
+ isEmptyContentPart
330
379
  });
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ "use strict";
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var vertex_ai_utils_exports = {};
26
+ __export(vertex_ai_utils_exports, {
27
+ getExpressModeApiKey: () => getExpressModeApiKey
28
+ });
29
+ module.exports = __toCommonJS(vertex_ai_utils_exports);
30
+ var import_env_aware_utils = require("./env_aware_utils.js");
31
+ /**
32
+ * @license
33
+ * Copyright 2026 Google LLC
34
+ * SPDX-License-Identifier: Apache-2.0
35
+ */
36
+ function getExpressModeApiKey(project, location, expressModeApiKey) {
37
+ if ((project || location) && expressModeApiKey) {
38
+ throw new Error(
39
+ "Cannot specify project or location and expressModeApiKey. Either use project and location, or just the expressModeApiKey."
40
+ );
41
+ }
42
+ if ((0, import_env_aware_utils.getBooleanEnvVar)("GOOGLE_GENAI_USE_VERTEXAI")) {
43
+ return expressModeApiKey || process.env.GOOGLE_API_KEY;
44
+ }
45
+ return void 0;
46
+ }
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ getExpressModeApiKey
50
+ });
@@ -32,7 +32,7 @@ module.exports = __toCommonJS(version_exports);
32
32
  * Copyright 2025 Google LLC
33
33
  * SPDX-License-Identifier: Apache-2.0
34
34
  */
35
- const version = "1.1.0";
35
+ const version = "1.2.0";
36
36
  // Annotate the CommonJS export names for ESM import in node:
37
37
  0 && (module.exports = {
38
38
  version
@@ -160,6 +160,8 @@ function buildResponseEvent(tool, functionResult, toolContext, invocationContext
160
160
  let responseResult;
161
161
  if (typeof functionResult !== "object" || functionResult == null) {
162
162
  responseResult = { result: functionResult };
163
+ } else if (Array.isArray(functionResult)) {
164
+ responseResult = { results: functionResult };
163
165
  } else {
164
166
  responseResult = functionResult;
165
167
  }
@@ -380,6 +382,8 @@ async function handleFunctionCallList({
380
382
  functionResponse = { error: functionResponseError };
381
383
  } else if (typeof functionResponse !== "object" || functionResponse == null) {
382
384
  functionResponse = { result: functionResponse };
385
+ } else if (Array.isArray(functionResponse)) {
386
+ functionResponse = { results: functionResponse };
383
387
  }
384
388
  const functionResponseEvent = createEvent({
385
389
  invocationId: invocationContext.invocationId,
@@ -123,6 +123,18 @@ class OAuth2DiscoveryManager {
123
123
  return void 0;
124
124
  }
125
125
  }
126
+ function normaliseHostname(raw) {
127
+ const stripped = raw.replace(/^\[|\]$/g, "");
128
+ const m = stripped.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i);
129
+ if (m) {
130
+ const hi = parseInt(m[1], 16);
131
+ const lo = parseInt(m[2], 16);
132
+ return [hi >> 8 & 255, hi & 255, lo >> 8 & 255, lo & 255].join(".");
133
+ }
134
+ const mDot = stripped.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/i);
135
+ if (mDot) return mDot[1];
136
+ return raw;
137
+ }
126
138
  function validateDiscoveryUrl(urlStr) {
127
139
  try {
128
140
  const url = new URL(urlStr);
@@ -130,8 +142,8 @@ function validateDiscoveryUrl(urlStr) {
130
142
  logger.warn(`Unsafe protocol for discovery URL: ${url.protocol}`);
131
143
  return false;
132
144
  }
133
- const host = url.hostname.toLowerCase();
134
- if (host === "localhost" || host === "127.0.0.1" || host === "[::1]" || host.startsWith("10.") || host.startsWith("192.168.") || host.startsWith("169.254.")) {
145
+ const host = normaliseHostname(url.hostname.toLowerCase());
146
+ if (host === "localhost" || host === "127.0.0.1" || host === "[::1]" || host === "0.0.0.0" || host.startsWith("10.") || host.startsWith("192.168.") || host.startsWith("169.254.")) {
135
147
  logger.warn(`Unsafe host for discovery URL: ${host}`);
136
148
  return false;
137
149
  }
@@ -143,6 +155,18 @@ function validateDiscoveryUrl(urlStr) {
143
155
  return false;
144
156
  }
145
157
  }
158
+ const cgnatMatch = host.match(/^100\.(\d+)\./);
159
+ if (cgnatMatch) {
160
+ const secondOctet = parseInt(cgnatMatch[1], 10);
161
+ if (secondOctet >= 64 && secondOctet <= 127) {
162
+ logger.warn(`Unsafe host for discovery URL: ${host}`);
163
+ return false;
164
+ }
165
+ }
166
+ if (/^\[(f[cd][0-9a-f]{2}|fe[89ab][0-9a-f]):/i.test(url.hostname)) {
167
+ logger.warn(`Unsafe host for discovery URL: ${url.hostname}`);
168
+ return false;
169
+ }
146
170
  return true;
147
171
  } catch (e) {
148
172
  logger.warn(`Failed to parse URL for validation ${urlStr}: ${e}`);