@google/adk 2.1.0 → 2.2.1

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 (166) hide show
  1. package/dist/cjs/a2a/agent_card.js +8 -0
  2. package/dist/cjs/a2a/agent_executor.js +8 -3
  3. package/dist/cjs/a2a/event_converter_utils.js +5 -1
  4. package/dist/cjs/a2a/metadata_converter_utils.js +2 -1
  5. package/dist/cjs/agents/llm_agent.js +15 -1
  6. package/dist/cjs/agents/processors/content_processor_utils.js +10 -2
  7. package/dist/cjs/agents/processors/nl_planning_processor.js +114 -0
  8. package/dist/cjs/artifacts/gcs_artifact_service.js +13 -7
  9. package/dist/cjs/auth/auth_credential.js +12 -2
  10. package/dist/cjs/code_executors/code_execution_utils.js +3 -3
  11. package/dist/cjs/common.js +63 -0
  12. package/dist/cjs/events/abort_events.js +135 -0
  13. package/dist/cjs/events/internal_metadata.js +131 -0
  14. package/dist/cjs/examples/example.js +92 -0
  15. package/dist/cjs/examples/example_util.js +28 -4
  16. package/dist/cjs/examples/index.js +39 -0
  17. package/dist/cjs/examples/vertex_ai_example_store.js +39 -0
  18. package/dist/cjs/index.js +46 -0
  19. package/dist/cjs/memory/vertex_ai_memory_bank_service.js +17 -5
  20. package/dist/cjs/models/base_llm.js +1 -6
  21. package/dist/cjs/models/chrome_prompt_llm.js +16 -2
  22. package/dist/cjs/models/chrome_prompt_utils.js +54 -2
  23. package/dist/cjs/models/gemini_continuation.js +232 -0
  24. package/dist/cjs/models/gemini_llm_connection.js +5 -4
  25. package/dist/cjs/planners/base_planner.js +56 -0
  26. package/dist/cjs/planners/built_in_planner.js +85 -0
  27. package/dist/cjs/planners/plan_re_act_planner.js +172 -0
  28. package/dist/cjs/plugins/base_plugin.js +46 -61
  29. package/dist/cjs/plugins/debug_logging_plugin.js +653 -0
  30. package/dist/cjs/plugins/plugin_manager.js +1 -1
  31. package/dist/cjs/plugins/tool_call_integrity_plugin.js +364 -0
  32. package/dist/cjs/runner/runner.js +17 -3
  33. package/dist/cjs/tools/example_tool.js +1 -1
  34. package/dist/cjs/tools/mcp/mcp_session_manager.js +14 -8
  35. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +281 -2
  36. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +15 -1
  37. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.js +70 -0
  38. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +120 -0
  39. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +10 -10
  40. package/dist/cjs/tools/openapi_tool/common/common.js +139 -0
  41. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +11 -6
  42. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +73 -13
  43. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +146 -34
  44. package/dist/cjs/tools/openapi_tool/openapi_toolset.js +14 -2
  45. package/dist/cjs/tools/openapi_tool/rest_api_tool.js +90 -28
  46. package/dist/cjs/tools/skill/skill_toolset.js +2 -0
  47. package/dist/cjs/tools/tool_context.js +41 -0
  48. package/dist/cjs/tools/webmcp/index.js +37 -0
  49. package/dist/cjs/tools/webmcp/webmcp_tool.js +156 -0
  50. package/dist/cjs/tools/webmcp/webmcp_toolset.js +116 -0
  51. package/dist/cjs/tools/webmcp/webmcp_types.js +50 -0
  52. package/dist/cjs/utils/case_utils.js +52 -2
  53. package/dist/cjs/utils/client_labels.js +67 -0
  54. package/dist/cjs/utils/gemini_schema_util.js +103 -3
  55. package/dist/cjs/utils/hash_utils.js +73 -0
  56. package/dist/cjs/utils/live_connection_utils.js +10 -9
  57. package/dist/cjs/utils/model_name.js +17 -2
  58. package/dist/cjs/utils/simple_zod_to_json.js +5 -0
  59. package/dist/cjs/version.js +1 -1
  60. package/dist/esm/a2a/agent_card.js +8 -0
  61. package/dist/esm/a2a/agent_executor.js +8 -3
  62. package/dist/esm/a2a/event_converter_utils.js +5 -1
  63. package/dist/esm/a2a/metadata_converter_utils.js +2 -1
  64. package/dist/esm/agents/llm_agent.js +18 -1
  65. package/dist/esm/agents/processors/content_processor_utils.js +10 -2
  66. package/dist/esm/agents/processors/nl_planning_processor.js +87 -0
  67. package/dist/esm/artifacts/gcs_artifact_service.js +13 -7
  68. package/dist/esm/auth/auth_credential.js +11 -1
  69. package/dist/esm/code_executors/code_execution_utils.js +3 -3
  70. package/dist/esm/common.js +58 -2
  71. package/dist/esm/events/abort_events.js +110 -0
  72. package/dist/esm/events/internal_metadata.js +97 -0
  73. package/dist/esm/examples/example.js +85 -0
  74. package/dist/esm/examples/example_util.js +25 -3
  75. package/dist/esm/examples/index.js +11 -0
  76. package/dist/esm/examples/vertex_ai_example_store.js +11 -0
  77. package/dist/esm/index.js +51 -1
  78. package/dist/esm/memory/vertex_ai_memory_bank_service.js +17 -5
  79. package/dist/esm/models/base_llm.js +2 -7
  80. package/dist/esm/models/chrome_prompt_llm.js +20 -3
  81. package/dist/esm/models/chrome_prompt_utils.js +51 -2
  82. package/dist/esm/models/gemini_continuation.js +205 -0
  83. package/dist/esm/models/gemini_llm_connection.js +6 -5
  84. package/dist/esm/planners/base_planner.js +28 -0
  85. package/dist/esm/planners/built_in_planner.js +57 -0
  86. package/dist/esm/planners/plan_re_act_planner.js +145 -0
  87. package/dist/esm/plugins/base_plugin.js +46 -61
  88. package/dist/esm/plugins/debug_logging_plugin.js +615 -0
  89. package/dist/esm/plugins/plugin_manager.js +1 -1
  90. package/dist/esm/plugins/tool_call_integrity_plugin.js +339 -0
  91. package/dist/esm/runner/runner.js +20 -3
  92. package/dist/esm/tools/example_tool.js +1 -1
  93. package/dist/esm/tools/mcp/mcp_session_manager.js +14 -8
  94. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +272 -1
  95. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +15 -1
  96. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.js +43 -0
  97. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +93 -0
  98. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +10 -12
  99. package/dist/esm/tools/openapi_tool/common/common.js +112 -0
  100. package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +11 -6
  101. package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +80 -13
  102. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +146 -33
  103. package/dist/esm/tools/openapi_tool/openapi_toolset.js +14 -2
  104. package/dist/esm/tools/openapi_tool/rest_api_tool.js +89 -28
  105. package/dist/esm/tools/skill/skill_toolset.js +2 -0
  106. package/dist/esm/tools/tool_context.js +15 -0
  107. package/dist/esm/tools/webmcp/index.js +10 -0
  108. package/dist/esm/tools/webmcp/webmcp_tool.js +131 -0
  109. package/dist/esm/tools/webmcp/webmcp_toolset.js +89 -0
  110. package/dist/esm/tools/webmcp/webmcp_types.js +22 -0
  111. package/dist/esm/utils/case_utils.js +49 -1
  112. package/dist/esm/utils/client_labels.js +65 -0
  113. package/dist/esm/utils/gemini_schema_util.js +102 -3
  114. package/dist/esm/utils/hash_utils.js +45 -0
  115. package/dist/esm/utils/live_connection_utils.js +11 -10
  116. package/dist/esm/utils/model_name.js +15 -2
  117. package/dist/esm/utils/simple_zod_to_json.js +5 -0
  118. package/dist/esm/version.js +1 -1
  119. package/dist/types/agents/llm_agent.d.ts +12 -1
  120. package/dist/types/agents/processors/nl_planning_processor.d.ts +30 -0
  121. package/dist/types/auth/auth_credential.d.ts +9 -0
  122. package/dist/types/common.d.ts +19 -4
  123. package/dist/types/events/abort_events.d.ts +43 -0
  124. package/dist/types/events/internal_metadata.d.ts +78 -0
  125. package/dist/types/examples/base_example_provider.d.ts +2 -2
  126. package/dist/types/examples/example.d.ts +75 -0
  127. package/dist/types/examples/example_util.d.ts +13 -2
  128. package/dist/types/examples/index.d.ts +18 -0
  129. package/dist/types/examples/vertex_ai_example_store.d.ts +7 -0
  130. package/dist/types/index.d.ts +12 -3
  131. package/dist/types/memory/memory_entry.d.ts +15 -0
  132. package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +9 -0
  133. package/dist/types/models/chrome_prompt_utils.d.ts +29 -0
  134. package/dist/types/models/gemini_continuation.d.ts +59 -0
  135. package/dist/types/planners/base_planner.d.ts +50 -0
  136. package/dist/types/planners/built_in_planner.d.ts +53 -0
  137. package/dist/types/planners/plan_re_act_planner.d.ts +21 -0
  138. package/dist/types/plugins/base_plugin.d.ts +52 -52
  139. package/dist/types/plugins/debug_logging_plugin.d.ts +157 -0
  140. package/dist/types/plugins/tool_call_integrity_plugin.d.ts +116 -0
  141. package/dist/types/skills/skill_registry.d.ts +8 -0
  142. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +110 -1
  143. package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +32 -2
  144. package/dist/types/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.d.ts +35 -0
  145. package/dist/types/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.d.ts +54 -0
  146. package/dist/types/tools/openapi_tool/common/common.d.ts +60 -0
  147. package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +7 -0
  148. package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +56 -2
  149. package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +73 -5
  150. package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +11 -0
  151. package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +42 -8
  152. package/dist/types/tools/tool_context.d.ts +19 -0
  153. package/dist/types/tools/webmcp/index.d.ts +12 -0
  154. package/dist/types/tools/webmcp/webmcp_tool.d.ts +47 -0
  155. package/dist/types/tools/webmcp/webmcp_toolset.d.ts +67 -0
  156. package/dist/types/tools/webmcp/webmcp_types.d.ts +69 -0
  157. package/dist/types/utils/case_utils.d.ts +36 -0
  158. package/dist/types/utils/client_labels.d.ts +33 -0
  159. package/dist/types/utils/gemini_schema_util.d.ts +13 -0
  160. package/dist/types/utils/hash_utils.d.ts +25 -0
  161. package/dist/types/utils/logger.d.ts +10 -2
  162. package/dist/types/utils/model_name.d.ts +30 -2
  163. package/dist/types/version.d.ts +1 -1
  164. package/dist/web/index_web.js +113 -80
  165. package/dist/web/index_web.js.map +4 -4
  166. package/package.json +8 -2
@@ -63,7 +63,7 @@ const ENABLE_CONSOLIDATION_KEY = "enable_consolidation";
63
63
  const MAX_DIRECT_MEMORIES_PER_GENERATE_CALL = 5;
64
64
  function shouldFilterOutEvent(content) {
65
65
  return !((content == null ? void 0 : content.parts) || []).some(
66
- (p) => p.text || p.inlineData || p.fileData
66
+ (p) => p.text || p.inlineData || p.fileData || p.functionCall || p.functionResponse || p.executableCode || p.codeExecutionResult || p.toolCall || p.toolResponse
67
67
  );
68
68
  }
69
69
  __name(shouldFilterOutEvent, "shouldFilterOutEvent");
@@ -149,6 +149,15 @@ const _VertexAiMemoryBankService = class _VertexAiMemoryBankService {
149
149
  }
150
150
  /**
151
151
  * Adds explicit memory items using Vertex Memory Bank.
152
+ *
153
+ * When a `MemoryEntry.id` is set, it is forwarded as the `memoryId` of the
154
+ * created memory, so the caller picks the last component of the memory
155
+ * resource name instead of letting the service generate one. An explicit
156
+ * `customMetadata['memoryId']` takes precedence over `MemoryEntry.id`.
157
+ *
158
+ * The id is forwarded unvalidated, so an id the API rejects fails the create
159
+ * call. Vertex accepts up to 63 characters from `[a-z0-9-]`, starting with a
160
+ * letter and ending with a letter or number.
152
161
  */
153
162
  async addMemory(request) {
154
163
  if (isConsolidationEnabled(request.customMetadata)) {
@@ -224,7 +233,8 @@ const _VertexAiMemoryBankService = class _VertexAiMemoryBankService {
224
233
  const memoryRevisionLabels = revisionLabelsForMemory(memory);
225
234
  const config = buildCreateMemoryConfig({
226
235
  customMetadata: memoryMetadata,
227
- memoryRevisionLabels
236
+ memoryRevisionLabels,
237
+ memoryId: memory.id
228
238
  });
229
239
  const params = {
230
240
  name: `reasoningEngines/${this.agentEngineId}`,
@@ -325,6 +335,9 @@ function buildCreateMemoryConfig(params) {
325
335
  };
326
336
  }
327
337
  }
338
+ if (params.memoryId !== void 0 && config["memoryId"] === void 0) {
339
+ config["memoryId"] = params.memoryId;
340
+ }
328
341
  const revisionLabels = {
329
342
  ...customRevisionLabels,
330
343
  ...params.memoryRevisionLabels
@@ -458,9 +471,8 @@ function mergeCustomMetadataForMemory(params) {
458
471
  if (params.customMetadata) {
459
472
  Object.assign(mergedMetadata, params.customMetadata);
460
473
  }
461
- const memoryWithMetadata = params.memory;
462
- if (memoryWithMetadata.customMetadata) {
463
- Object.assign(mergedMetadata, memoryWithMetadata.customMetadata);
474
+ if (params.memory.customMetadata) {
475
+ Object.assign(mergedMetadata, params.memory.customMetadata);
464
476
  }
465
477
  if (Object.keys(mergedMetadata).length === 0) {
466
478
  return void 0;
@@ -57,12 +57,7 @@ const _BaseLlm = class _BaseLlm {
57
57
  this.model = model;
58
58
  }
59
59
  get trackingHeaders() {
60
- const labels = (0, import_client_labels.getClientLabels)();
61
- const headerValue = labels.join(" ");
62
- return {
63
- "x-goog-api-client": headerValue,
64
- "user-agent": headerValue
65
- };
60
+ return (0, import_client_labels.getTrackingHeaders)();
66
61
  }
67
62
  /**
68
63
  * Appends a user content, so that model can continue to output.
@@ -249,11 +249,19 @@ const _ChromeBuiltInLlm = class _ChromeBuiltInLlm extends import_base_llm.BaseLl
249
249
  }
250
250
  }
251
251
  if (!(0, import_chrome_prompt_utils.isRecord)(parsed)) {
252
+ const salvaged = (0, import_chrome_prompt_utils.salvageFinalText)(raw);
253
+ if (salvaged !== void 0) {
254
+ this.diagnostic({
255
+ phase: "parse-fallback",
256
+ note: "truncated envelope; recovered the text"
257
+ });
258
+ return (0, import_chrome_prompt_utils.finalText)(salvaged);
259
+ }
252
260
  this.diagnostic({
253
261
  phase: "parse-fallback",
254
262
  note: "unparseable JSON; treated as text"
255
263
  });
256
- return (0, import_chrome_prompt_utils.finalText)(raw);
264
+ return (0, import_chrome_prompt_utils.finalText)((0, import_chrome_prompt_utils.looksLikeEnvelope)(raw) ? import_chrome_prompt_utils.TRUNCATED_REPLY : raw);
257
265
  }
258
266
  if (parsed["kind"] === "tool" && typeof parsed["name"] === "string") {
259
267
  const name = parsed["name"];
@@ -271,7 +279,13 @@ const _ChromeBuiltInLlm = class _ChromeBuiltInLlm extends import_base_llm.BaseLl
271
279
  turnComplete: true
272
280
  };
273
281
  }
274
- return (0, import_chrome_prompt_utils.finalText)(typeof parsed["text"] === "string" ? parsed["text"] : raw);
282
+ if (typeof parsed["text"] === "string") return (0, import_chrome_prompt_utils.finalText)(parsed["text"]);
283
+ if (parsed["text"] !== void 0) return (0, import_chrome_prompt_utils.finalText)(String(parsed["text"]));
284
+ this.diagnostic({
285
+ phase: "parse-fallback",
286
+ note: "envelope carried no text"
287
+ });
288
+ return (0, import_chrome_prompt_utils.finalText)((0, import_chrome_prompt_utils.looksLikeEnvelope)(raw) ? import_chrome_prompt_utils.TRUNCATED_REPLY : raw);
275
289
  }
276
290
  async connect(_llmRequest) {
277
291
  throw new Error(
@@ -25,6 +25,7 @@ var __copyProps = (to, from, except, desc) => {
25
25
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
26
  var chrome_prompt_utils_exports = {};
27
27
  __export(chrome_prompt_utils_exports, {
28
+ TRUNCATED_REPLY: () => TRUNCATED_REPLY,
28
29
  buildToolChoiceSchema: () => buildToolChoiceSchema,
29
30
  collectFunctionDeclarations: () => collectFunctionDeclarations,
30
31
  contentsToMessages: () => contentsToMessages,
@@ -33,8 +34,10 @@ __export(chrome_prompt_utils_exports, {
33
34
  finalText: () => finalText,
34
35
  isAbortError: () => isAbortError,
35
36
  isRecord: () => isRecord,
37
+ looksLikeEnvelope: () => looksLikeEnvelope,
36
38
  renderToolInstructions: () => renderToolInstructions,
37
39
  renderToolResult: () => renderToolResult,
40
+ salvageFinalText: () => salvageFinalText,
38
41
  stripAdkIdentityPreamble: () => stripAdkIdentityPreamble
39
42
  });
40
43
  module.exports = __toCommonJS(chrome_prompt_utils_exports);
@@ -79,7 +82,8 @@ function buildToolChoiceSchema(declarations) {
79
82
  kind: { type: "string", enum: ["final"] },
80
83
  text: { type: "string" }
81
84
  },
82
- required: ["kind", "text"]
85
+ required: ["kind", "text"],
86
+ additionalProperties: false
83
87
  }
84
88
  ];
85
89
  for (const declaration of declarations) {
@@ -91,7 +95,8 @@ function buildToolChoiceSchema(declarations) {
91
95
  name: { type: "string", enum: [declaration.name] },
92
96
  args: argumentSchema(declaration)
93
97
  },
94
- required: ["kind", "name", "args"]
98
+ required: ["kind", "name", "args"],
99
+ additionalProperties: false
95
100
  });
96
101
  }
97
102
  return branches.length === 1 ? branches[0] : { anyOf: branches };
@@ -213,8 +218,53 @@ function errorResponse(error) {
213
218
  return { errorCode: name, errorMessage: message, turnComplete: true };
214
219
  }
215
220
  __name(errorResponse, "errorResponse");
221
+ const TRUNCATED_REPLY = "The model started an answer and did not finish it. Ask again.";
222
+ function looksLikeEnvelope(raw) {
223
+ return /^\s*[[{]/.test(raw) || /"kind"\s*:/.test(raw);
224
+ }
225
+ __name(looksLikeEnvelope, "looksLikeEnvelope");
226
+ function salvageFinalText(raw) {
227
+ var _a;
228
+ const key = raw.match(/"text"\s*:\s*"/);
229
+ if ((key == null ? void 0 : key.index) === void 0) return void 0;
230
+ const escapes = {
231
+ n: "\n",
232
+ t: " ",
233
+ r: "\r",
234
+ b: "\b",
235
+ f: "\f",
236
+ '"': '"',
237
+ "\\": "\\",
238
+ "/": "/"
239
+ };
240
+ let out = "";
241
+ for (let i = key.index + key[0].length; i < raw.length; i++) {
242
+ const char = raw[i];
243
+ if (char === '"') break;
244
+ if (char !== "\\") {
245
+ out += char;
246
+ continue;
247
+ }
248
+ const next = raw[i + 1];
249
+ if (next === void 0) break;
250
+ if (next === "u") {
251
+ const hex = raw.slice(i + 2, i + 6);
252
+ if (/^[0-9a-fA-F]{4}$/.test(hex)) {
253
+ out += String.fromCharCode(parseInt(hex, 16));
254
+ i += 5;
255
+ continue;
256
+ }
257
+ }
258
+ out += (_a = escapes[next]) != null ? _a : next;
259
+ i++;
260
+ }
261
+ const text = out.trim();
262
+ return text.length ? text : void 0;
263
+ }
264
+ __name(salvageFinalText, "salvageFinalText");
216
265
  // Annotate the CommonJS export names for ESM import in node:
217
266
  0 && (module.exports = {
267
+ TRUNCATED_REPLY,
218
268
  buildToolChoiceSchema,
219
269
  collectFunctionDeclarations,
220
270
  contentsToMessages,
@@ -223,7 +273,9 @@ __name(errorResponse, "errorResponse");
223
273
  finalText,
224
274
  isAbortError,
225
275
  isRecord,
276
+ looksLikeEnvelope,
226
277
  renderToolInstructions,
227
278
  renderToolResult,
279
+ salvageFinalText,
228
280
  stripAdkIdentityPreamble
229
281
  });
@@ -0,0 +1,232 @@
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
13
+ var __export = (target, all) => {
14
+ for (var name in all)
15
+ __defProp(target, name, { get: all[name], enumerable: true });
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
+ var gemini_continuation_exports = {};
27
+ __export(gemini_continuation_exports, {
28
+ GeminiContinuation: () => GeminiContinuation,
29
+ MAX_RESUMES: () => MAX_RESUMES,
30
+ resumeToken: () => resumeToken
31
+ });
32
+ module.exports = __toCommonJS(gemini_continuation_exports);
33
+ var import_genai = require("@google/genai");
34
+ var import_content_processor_utils = require("../agents/processors/content_processor_utils.js");
35
+ var import_logger = require("../utils/logger.js");
36
+ var import_llm_response = require("./llm_response.js");
37
+ /**
38
+ * @license
39
+ * Copyright 2026 Google LLC
40
+ * SPDX-License-Identifier: Apache-2.0
41
+ */
42
+ const MAX_RESUMES = 256;
43
+ function resumeToken(response) {
44
+ var _a;
45
+ const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
46
+ if ((candidate == null ? void 0 : candidate.finishReason) !== import_genai.FinishReason.CONTINUATION) {
47
+ return void 0;
48
+ }
49
+ if (!candidate.continuationToken) {
50
+ import_logger.logger.warn(
51
+ "The model paused the generation for continuation, but the response carries no continuation token, so the partial output is returned."
52
+ );
53
+ return void 0;
54
+ }
55
+ return candidate.continuationToken;
56
+ }
57
+ __name(resumeToken, "resumeToken");
58
+ const _GeminiContinuation = class _GeminiContinuation {
59
+ constructor(contents, config) {
60
+ this.config = config;
61
+ this.parts = [];
62
+ this.resumes = 0;
63
+ this.contents = [...contents];
64
+ }
65
+ /**
66
+ * Adds one request's output to the generation: its parts to the content and
67
+ * its usage to the total.
68
+ */
69
+ addOutput(newParts, newUsage) {
70
+ this.usage = addUsage(this.usage, newUsage);
71
+ this.appendParts(newParts);
72
+ }
73
+ /**
74
+ * Returns the request that resumes the generation after a request that
75
+ * ended with `nextToken`. Returns undefined if the request did not pause,
76
+ * returned the previous token again, or the generation was already resumed
77
+ * {@link MAX_RESUMES} times.
78
+ */
79
+ resumeRequest(nextToken) {
80
+ if (nextToken === void 0) {
81
+ return void 0;
82
+ }
83
+ if (!this.willResume(nextToken)) {
84
+ if (nextToken === this.token) {
85
+ import_logger.logger.warn(
86
+ "The model returned the same continuation token twice; returning the output generated so far."
87
+ );
88
+ } else {
89
+ import_logger.logger.warn(
90
+ `The model paused the generation ${MAX_RESUMES} times; returning the output generated so far.`
91
+ );
92
+ }
93
+ return void 0;
94
+ }
95
+ this.token = nextToken;
96
+ this.resumes++;
97
+ import_logger.logger.debug("The model paused the generation; resuming it.");
98
+ return this.buildResumeRequest(nextToken);
99
+ }
100
+ /** Returns `response` with the content and usage of all requests, if resumed. */
101
+ complete(response) {
102
+ var _a;
103
+ if (!this.resumed) {
104
+ return (0, import_llm_response.createLlmResponse)(response);
105
+ }
106
+ const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
107
+ return (0, import_llm_response.createLlmResponse)({
108
+ ...response,
109
+ usageMetadata: this.usage,
110
+ candidates: candidate && this.parts.length > 0 ? [{ ...candidate, content: this.content() }] : response.candidates
111
+ });
112
+ }
113
+ /**
114
+ * Returns the final streamed `response`, with usage summed across all
115
+ * requests if resumed.
116
+ */
117
+ withSummedUsage(response) {
118
+ return this.resumed ? { ...response, usageMetadata: this.usage } : response;
119
+ }
120
+ /** Returns whether a request that ended with `nextToken` is resumed. */
121
+ willResume(nextToken) {
122
+ return nextToken !== this.token && this.resumes < MAX_RESUMES;
123
+ }
124
+ /** Whether the generation took more than one request. */
125
+ get resumed() {
126
+ return this.token !== void 0;
127
+ }
128
+ content() {
129
+ return { role: "model", parts: [...this.parts] };
130
+ }
131
+ buildResumeRequest(nextToken) {
132
+ const contents = [...this.contents];
133
+ if (this.parts.length > 0) {
134
+ const content = structuredClone(this.content());
135
+ (0, import_content_processor_utils.removeClientFunctionCallId)(content);
136
+ contents.push(content);
137
+ }
138
+ return {
139
+ contents,
140
+ config: { ...this.config, continuationToken: nextToken }
141
+ };
142
+ }
143
+ /** Appends `newParts`, joining text as the streaming aggregator does. */
144
+ appendParts(newParts) {
145
+ for (const part of newParts) {
146
+ const last = this.parts.length - 1;
147
+ const previous = last >= 0 ? this.parts[last] : void 0;
148
+ if (previous && canJoin(previous, part)) {
149
+ const joined = { text: previous.text + part.text };
150
+ if (previous.thought !== void 0) {
151
+ joined.thought = previous.thought;
152
+ }
153
+ const signature = previous.thoughtSignature || part.thoughtSignature;
154
+ if (signature !== void 0) {
155
+ joined.thoughtSignature = signature;
156
+ }
157
+ this.parts[last] = joined;
158
+ } else {
159
+ this.parts.push(part);
160
+ }
161
+ }
162
+ }
163
+ };
164
+ __name(_GeminiContinuation, "GeminiContinuation");
165
+ let GeminiContinuation = _GeminiContinuation;
166
+ function canJoin(first, second) {
167
+ var _a, _b;
168
+ return isText(first) && isText(second) && ((_a = first.thought) != null ? _a : false) === ((_b = second.thought) != null ? _b : false);
169
+ }
170
+ __name(canJoin, "canJoin");
171
+ function isText(part) {
172
+ if (!part.text) {
173
+ return false;
174
+ }
175
+ return Object.entries(part).every(
176
+ ([key, value]) => value === void 0 || key === "text" || key === "thought" || key === "thoughtSignature"
177
+ );
178
+ }
179
+ __name(isText, "isText");
180
+ const COUNT_FIELDS = [
181
+ "promptTokenCount",
182
+ "candidatesTokenCount",
183
+ "totalTokenCount",
184
+ "cachedContentTokenCount",
185
+ "thoughtsTokenCount",
186
+ "toolUsePromptTokenCount"
187
+ ];
188
+ const MODALITY_FIELDS = [
189
+ "promptTokensDetails",
190
+ "candidatesTokensDetails",
191
+ "cacheTokensDetails",
192
+ "toolUsePromptTokensDetails"
193
+ ];
194
+ function addUsage(total, next) {
195
+ var _a, _b;
196
+ if (!total || !next) {
197
+ return total != null ? total : next;
198
+ }
199
+ const combined = { ...next };
200
+ for (const field of COUNT_FIELDS) {
201
+ if (total[field] !== void 0 || next[field] !== void 0) {
202
+ combined[field] = ((_a = total[field]) != null ? _a : 0) + ((_b = next[field]) != null ? _b : 0);
203
+ }
204
+ }
205
+ for (const field of MODALITY_FIELDS) {
206
+ if (total[field] !== void 0 || next[field] !== void 0) {
207
+ combined[field] = addModalityCounts(total[field], next[field]);
208
+ }
209
+ }
210
+ return combined;
211
+ }
212
+ __name(addUsage, "addUsage");
213
+ function addModalityCounts(first, second) {
214
+ var _a, _b;
215
+ const totals = /* @__PURE__ */ new Map();
216
+ for (const count of [...first != null ? first : [], ...second != null ? second : []]) {
217
+ totals.set(
218
+ count.modality,
219
+ ((_a = totals.get(count.modality)) != null ? _a : 0) + ((_b = count.tokenCount) != null ? _b : 0)
220
+ );
221
+ }
222
+ return [...totals].map(
223
+ ([modality, tokenCount]) => modality === void 0 ? { tokenCount } : { modality, tokenCount }
224
+ );
225
+ }
226
+ __name(addModalityCounts, "addModalityCounts");
227
+ // Annotate the CommonJS export names for ESM import in node:
228
+ 0 && (module.exports = {
229
+ GeminiContinuation,
230
+ MAX_RESUMES,
231
+ resumeToken
232
+ });
@@ -59,7 +59,7 @@ const _GeminiLlmConnection = class _GeminiLlmConnection {
59
59
  }
60
60
  );
61
61
  if (contents.length > 0) {
62
- const isGemini3x = (0, import_model_name.isGemini3xFlashLive)(this.modelVersion);
62
+ const isGemini3x = (0, import_model_name.isGemini3xLive)(this.modelVersion);
63
63
  this.geminiSession.sendClientContent({
64
64
  turns: contents,
65
65
  turnComplete: isGemini3x ? true : contents[contents.length - 1].role === "user"
@@ -89,7 +89,7 @@ const _GeminiLlmConnection = class _GeminiLlmConnection {
89
89
  });
90
90
  } else {
91
91
  import_logger.logger.debug("Sending LLM new content", content);
92
- const isGemini3x = (0, import_model_name.isGemini3xFlashLive)(this.modelVersion);
92
+ const isGemini3x = (0, import_model_name.isGemini3xLive)(this.modelVersion);
93
93
  if (isGemini3x && content.parts.length === 1 && content.parts[0].text) {
94
94
  import_logger.logger.debug("Using sendRealtimeInput for Gemini 3.x text input");
95
95
  this.geminiSession.sendRealtimeInput({ text: content.parts[0].text });
@@ -109,9 +109,10 @@ const _GeminiLlmConnection = class _GeminiLlmConnection {
109
109
  async sendRealtime(blob) {
110
110
  var _a, _b, _c;
111
111
  import_logger.logger.debug("Sending LLM Blob:", blob);
112
- const isGemini3x = (0, import_model_name.isGemini3xFlashLive)(this.modelVersion);
112
+ const isGemini3x = (0, import_model_name.isGemini3xLive)(this.modelVersion);
113
113
  const isNativeAudio = (_a = this.modelVersion) == null ? void 0 : _a.includes("native-audio");
114
- if (isGemini3x || isNativeAudio) {
114
+ const isLiveTranslate = (0, import_model_name.isGemini35LiveTranslate)(this.modelVersion);
115
+ if (isGemini3x || isNativeAudio || isLiveTranslate) {
115
116
  if ((_b = blob.mimeType) == null ? void 0 : _b.startsWith("audio/")) {
116
117
  this.geminiSession.sendRealtimeInput({ audio: blob });
117
118
  } else if ((_c = blob.mimeType) == null ? void 0 : _c.startsWith("image/")) {
@@ -0,0 +1,56 @@
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
13
+ var __export = (target, all) => {
14
+ for (var name in all)
15
+ __defProp(target, name, { get: all[name], enumerable: true });
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
+ var base_planner_exports = {};
27
+ __export(base_planner_exports, {
28
+ BasePlanner: () => BasePlanner,
29
+ isBasePlanner: () => isBasePlanner
30
+ });
31
+ module.exports = __toCommonJS(base_planner_exports);
32
+ /**
33
+ * @license
34
+ * Copyright 2026 Google LLC
35
+ * SPDX-License-Identifier: Apache-2.0
36
+ */
37
+ var _a;
38
+ const BASE_PLANNER_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for("google.adk.basePlanner");
39
+ function isBasePlanner(obj) {
40
+ return typeof obj === "object" && obj !== null && BASE_PLANNER_SIGNATURE_SYMBOL in obj && obj[BASE_PLANNER_SIGNATURE_SYMBOL] === true;
41
+ }
42
+ __name(isBasePlanner, "isBasePlanner");
43
+ _a = BASE_PLANNER_SIGNATURE_SYMBOL;
44
+ const _BasePlanner = class _BasePlanner {
45
+ constructor() {
46
+ /** A unique symbol to identify ADK base planner class. */
47
+ this[_a] = true;
48
+ }
49
+ };
50
+ __name(_BasePlanner, "BasePlanner");
51
+ let BasePlanner = _BasePlanner;
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ BasePlanner,
55
+ isBasePlanner
56
+ });
@@ -0,0 +1,85 @@
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
13
+ var __export = (target, all) => {
14
+ for (var name in all)
15
+ __defProp(target, name, { get: all[name], enumerable: true });
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
+ var built_in_planner_exports = {};
27
+ __export(built_in_planner_exports, {
28
+ BuiltInPlanner: () => BuiltInPlanner,
29
+ isBuiltInPlanner: () => isBuiltInPlanner
30
+ });
31
+ module.exports = __toCommonJS(built_in_planner_exports);
32
+ var import_base_planner = require("./base_planner.js");
33
+ /**
34
+ * @license
35
+ * Copyright 2026 Google LLC
36
+ * SPDX-License-Identifier: Apache-2.0
37
+ */
38
+ var _a, _b;
39
+ const BUILT_IN_PLANNER_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for(
40
+ "google.adk.builtInPlanner"
41
+ );
42
+ function isBuiltInPlanner(obj) {
43
+ return typeof obj === "object" && obj !== null && BUILT_IN_PLANNER_SIGNATURE_SYMBOL in obj && obj[BUILT_IN_PLANNER_SIGNATURE_SYMBOL] === true;
44
+ }
45
+ __name(isBuiltInPlanner, "isBuiltInPlanner");
46
+ const _BuiltInPlanner = class _BuiltInPlanner extends (_b = import_base_planner.BasePlanner, _a = BUILT_IN_PLANNER_SIGNATURE_SYMBOL, _b) {
47
+ /**
48
+ * Initializes the built-in planner.
49
+ *
50
+ * @param options.thinkingConfig Config for model built-in thinking features.
51
+ * An error will be returned if this field is set for models that don't
52
+ * support thinking.
53
+ */
54
+ constructor(options) {
55
+ super();
56
+ /** A unique symbol to identify ADK built-in planner class. */
57
+ this[_a] = true;
58
+ this.thinkingConfig = options.thinkingConfig;
59
+ }
60
+ /**
61
+ * Applies the thinking config to the LLM request.
62
+ *
63
+ * @param llmRequest The LLM request to apply the thinking config to.
64
+ */
65
+ applyThinkingConfig(llmRequest) {
66
+ var _a2;
67
+ if (this.thinkingConfig) {
68
+ llmRequest.config = (_a2 = llmRequest.config) != null ? _a2 : {};
69
+ llmRequest.config.thinkingConfig = this.thinkingConfig;
70
+ }
71
+ }
72
+ buildPlanningInstruction(_readonlyContext, _llmRequest) {
73
+ return void 0;
74
+ }
75
+ processPlanningResponse(_callbackContext, _responseParts) {
76
+ return void 0;
77
+ }
78
+ };
79
+ __name(_BuiltInPlanner, "BuiltInPlanner");
80
+ let BuiltInPlanner = _BuiltInPlanner;
81
+ // Annotate the CommonJS export names for ESM import in node:
82
+ 0 && (module.exports = {
83
+ BuiltInPlanner,
84
+ isBuiltInPlanner
85
+ });