@google/adk 0.2.5 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (264) hide show
  1. package/dist/cjs/a2a/part_converter_utils.js +210 -0
  2. package/dist/cjs/agents/active_streaming_tool.js +1 -1
  3. package/dist/cjs/agents/base_agent.js +46 -24
  4. package/dist/cjs/agents/base_llm_processor.js +1 -1
  5. package/dist/cjs/agents/callback_context.js +5 -2
  6. package/dist/cjs/agents/content_processor_utils.js +16 -8
  7. package/dist/cjs/agents/functions.js +81 -30
  8. package/dist/cjs/agents/instructions.js +1 -1
  9. package/dist/cjs/agents/invocation_context.js +1 -1
  10. package/dist/cjs/agents/live_request_queue.js +1 -1
  11. package/dist/cjs/agents/llm_agent.js +106 -62
  12. package/dist/cjs/agents/loop_agent.js +3 -2
  13. package/dist/cjs/agents/parallel_agent.js +4 -5
  14. package/dist/cjs/agents/readonly_context.js +13 -1
  15. package/dist/cjs/agents/run_config.js +2 -1
  16. package/dist/cjs/agents/sequential_agent.js +1 -1
  17. package/dist/cjs/agents/transcription_entry.js +1 -1
  18. package/dist/cjs/artifacts/base_artifact_service.js +1 -1
  19. package/dist/cjs/artifacts/file_artifact_service.js +491 -0
  20. package/dist/cjs/artifacts/gcs_artifact_service.js +145 -58
  21. package/dist/cjs/artifacts/in_memory_artifact_service.js +72 -10
  22. package/dist/cjs/artifacts/registry.js +55 -0
  23. package/dist/cjs/auth/auth_credential.js +1 -1
  24. package/dist/cjs/auth/auth_handler.js +4 -2
  25. package/dist/cjs/auth/auth_schemes.js +1 -1
  26. package/dist/cjs/auth/auth_tool.js +1 -1
  27. package/dist/cjs/auth/credential_service/base_credential_service.js +1 -1
  28. package/dist/cjs/auth/credential_service/in_memory_credential_service.js +1 -1
  29. package/dist/cjs/auth/exchanger/base_credential_exchanger.js +1 -1
  30. package/dist/cjs/auth/exchanger/credential_exchanger_registry.js +1 -1
  31. package/dist/cjs/code_executors/base_code_executor.js +4 -2
  32. package/dist/cjs/code_executors/built_in_code_executor.js +8 -4
  33. package/dist/cjs/code_executors/code_execution_utils.js +1 -1
  34. package/dist/cjs/code_executors/code_executor_context.js +6 -6
  35. package/dist/cjs/common.js +18 -1
  36. package/dist/cjs/events/event.js +34 -7
  37. package/dist/cjs/events/event_actions.js +2 -2
  38. package/dist/cjs/events/structured_events.js +105 -0
  39. package/dist/cjs/examples/base_example_provider.js +1 -1
  40. package/dist/cjs/examples/example.js +1 -1
  41. package/dist/cjs/examples/example_util.js +1 -1
  42. package/dist/cjs/index.js +54 -83
  43. package/dist/cjs/index_web.js +1 -1
  44. package/dist/cjs/memory/base_memory_service.js +1 -1
  45. package/dist/cjs/memory/in_memory_memory_service.js +4 -2
  46. package/dist/cjs/memory/memory_entry.js +1 -1
  47. package/dist/cjs/models/apigee_llm.js +182 -0
  48. package/dist/cjs/models/base_llm.js +9 -5
  49. package/dist/cjs/models/base_llm_connection.js +1 -1
  50. package/dist/cjs/models/gemini_llm_connection.js +2 -1
  51. package/dist/cjs/models/google_llm.js +73 -54
  52. package/dist/cjs/models/llm_request.js +1 -1
  53. package/dist/cjs/models/llm_response.js +1 -1
  54. package/dist/cjs/models/registry.js +3 -1
  55. package/dist/cjs/plugins/base_plugin.js +13 -1
  56. package/dist/cjs/plugins/logging_plugin.js +51 -14
  57. package/dist/cjs/plugins/plugin_manager.js +57 -25
  58. package/dist/cjs/plugins/security_plugin.js +2 -2
  59. package/dist/cjs/runner/in_memory_runner.js +1 -1
  60. package/dist/cjs/runner/runner.js +142 -96
  61. package/dist/cjs/sessions/base_session_service.js +53 -3
  62. package/dist/cjs/sessions/database_session_service.js +364 -0
  63. package/dist/cjs/sessions/db/operations.js +114 -0
  64. package/dist/cjs/sessions/db/schema.js +204 -0
  65. package/dist/cjs/sessions/in_memory_session_service.js +60 -34
  66. package/dist/cjs/sessions/registry.js +49 -0
  67. package/dist/cjs/sessions/session.js +1 -1
  68. package/dist/cjs/sessions/state.js +1 -1
  69. package/dist/cjs/telemetry/google_cloud.js +8 -10
  70. package/dist/cjs/telemetry/setup.js +16 -8
  71. package/dist/cjs/telemetry/tracing.js +38 -16
  72. package/dist/cjs/tools/agent_tool.js +9 -5
  73. package/dist/cjs/tools/base_tool.js +5 -3
  74. package/dist/cjs/tools/base_toolset.js +1 -1
  75. package/dist/cjs/tools/forwarding_artifact_service.js +18 -2
  76. package/dist/cjs/tools/function_tool.js +2 -3
  77. package/dist/cjs/tools/google_search_tool.js +2 -3
  78. package/dist/cjs/tools/long_running_tool.js +1 -1
  79. package/dist/cjs/tools/mcp/mcp_session_manager.js +17 -11
  80. package/dist/cjs/tools/mcp/mcp_tool.js +2 -4
  81. package/dist/cjs/tools/mcp/mcp_toolset.js +2 -2
  82. package/dist/cjs/tools/tool_confirmation.js +1 -1
  83. package/dist/cjs/tools/tool_context.js +1 -1
  84. package/dist/cjs/utils/client_labels.js +1 -1
  85. package/dist/cjs/utils/env_aware_utils.js +11 -2
  86. package/dist/cjs/utils/gemini_schema_util.js +10 -5
  87. package/dist/cjs/utils/logger.js +48 -4
  88. package/dist/cjs/utils/model_name.js +1 -1
  89. package/dist/cjs/utils/object_notation_utils.js +78 -0
  90. package/dist/cjs/utils/simple_zod_to_json.js +101 -142
  91. package/dist/cjs/utils/variant_utils.js +3 -9
  92. package/dist/cjs/version.js +2 -2
  93. package/dist/esm/a2a/part_converter_utils.js +171 -0
  94. package/dist/esm/agents/base_agent.js +50 -24
  95. package/dist/esm/agents/callback_context.js +4 -1
  96. package/dist/esm/agents/content_processor_utils.js +25 -9
  97. package/dist/esm/agents/functions.js +84 -29
  98. package/dist/esm/agents/llm_agent.js +110 -62
  99. package/dist/esm/agents/loop_agent.js +2 -1
  100. package/dist/esm/agents/parallel_agent.js +3 -4
  101. package/dist/esm/agents/readonly_context.js +12 -0
  102. package/dist/esm/agents/run_config.js +1 -0
  103. package/dist/esm/artifacts/file_artifact_service.js +451 -0
  104. package/dist/esm/artifacts/gcs_artifact_service.js +144 -57
  105. package/dist/esm/artifacts/in_memory_artifact_service.js +69 -8
  106. package/dist/esm/artifacts/registry.js +28 -0
  107. package/dist/esm/auth/auth_handler.js +3 -1
  108. package/dist/esm/code_executors/base_code_executor.js +3 -1
  109. package/dist/esm/code_executors/built_in_code_executor.js +7 -3
  110. package/dist/esm/code_executors/code_executor_context.js +5 -5
  111. package/dist/esm/common.js +12 -2
  112. package/dist/esm/events/event.js +30 -5
  113. package/dist/esm/events/event_actions.js +1 -1
  114. package/dist/esm/events/structured_events.js +74 -0
  115. package/dist/esm/index.js +18 -88
  116. package/dist/esm/memory/in_memory_memory_service.js +3 -1
  117. package/dist/esm/models/apigee_llm.js +152 -0
  118. package/dist/esm/models/base_llm.js +8 -4
  119. package/dist/esm/models/gemini_llm_connection.js +1 -0
  120. package/dist/esm/models/google_llm.js +75 -53
  121. package/dist/esm/models/registry.js +2 -0
  122. package/dist/esm/plugins/base_plugin.js +12 -0
  123. package/dist/esm/plugins/logging_plugin.js +55 -14
  124. package/dist/esm/plugins/plugin_manager.js +56 -24
  125. package/dist/esm/plugins/security_plugin.js +1 -1
  126. package/dist/esm/runner/runner.js +145 -96
  127. package/dist/esm/sessions/base_session_service.js +49 -1
  128. package/dist/esm/sessions/database_session_service.js +350 -0
  129. package/dist/esm/sessions/db/operations.js +87 -0
  130. package/dist/esm/sessions/db/schema.js +172 -0
  131. package/dist/esm/sessions/in_memory_session_service.js +61 -33
  132. package/dist/esm/sessions/registry.js +25 -0
  133. package/dist/esm/telemetry/google_cloud.js +7 -9
  134. package/dist/esm/telemetry/setup.js +23 -9
  135. package/dist/esm/telemetry/tracing.js +37 -15
  136. package/dist/esm/tools/agent_tool.js +8 -4
  137. package/dist/esm/tools/base_tool.js +4 -2
  138. package/dist/esm/tools/forwarding_artifact_service.js +17 -1
  139. package/dist/esm/tools/function_tool.js +1 -2
  140. package/dist/esm/tools/google_search_tool.js +2 -5
  141. package/dist/esm/tools/long_running_tool.js +3 -1
  142. package/dist/esm/tools/mcp/mcp_session_manager.js +22 -12
  143. package/dist/esm/tools/mcp/mcp_tool.js +1 -3
  144. package/dist/esm/tools/mcp/mcp_toolset.js +1 -1
  145. package/dist/esm/utils/env_aware_utils.js +9 -1
  146. package/dist/esm/utils/gemini_schema_util.js +9 -4
  147. package/dist/esm/utils/logger.js +43 -2
  148. package/dist/esm/utils/object_notation_utils.js +47 -0
  149. package/dist/esm/utils/simple_zod_to_json.js +102 -141
  150. package/dist/esm/utils/variant_utils.js +1 -7
  151. package/dist/esm/version.js +1 -1
  152. package/dist/types/a2a/part_converter_utils.d.ts +47 -0
  153. package/dist/types/agents/base_agent.d.ts +2 -1
  154. package/dist/types/agents/callback_context.d.ts +1 -1
  155. package/dist/types/agents/llm_agent.d.ts +12 -12
  156. package/dist/types/agents/loop_agent.d.ts +1 -1
  157. package/dist/types/agents/parallel_agent.d.ts +1 -1
  158. package/dist/types/agents/readonly_context.d.ts +8 -0
  159. package/dist/types/agents/run_config.d.ts +6 -0
  160. package/dist/types/artifacts/base_artifact_service.d.ts +31 -0
  161. package/dist/types/artifacts/file_artifact_service.d.ts +43 -0
  162. package/dist/types/artifacts/gcs_artifact_service.d.ts +3 -1
  163. package/dist/types/artifacts/in_memory_artifact_service.d.ts +8 -5
  164. package/dist/types/artifacts/registry.d.ts +7 -0
  165. package/dist/types/code_executors/built_in_code_executor.d.ts +1 -1
  166. package/dist/types/code_executors/code_executor_context.d.ts +2 -4
  167. package/dist/types/common.d.ts +13 -3
  168. package/dist/types/events/event.d.ts +15 -1
  169. package/dist/types/events/event_actions.d.ts +1 -1
  170. package/dist/types/events/structured_events.d.ts +106 -0
  171. package/dist/types/index.d.ts +7 -3
  172. package/dist/types/models/apigee_llm.d.ts +59 -0
  173. package/dist/types/models/base_llm_connection.d.ts +1 -1
  174. package/dist/types/models/google_llm.d.ts +5 -2
  175. package/dist/types/models/llm_response.d.ts +1 -1
  176. package/dist/types/plugins/logging_plugin.d.ts +12 -12
  177. package/dist/types/plugins/plugin_manager.d.ts +12 -12
  178. package/dist/types/plugins/security_plugin.d.ts +1 -1
  179. package/dist/types/runner/runner.d.ts +16 -1
  180. package/dist/types/sessions/base_session_service.d.ts +20 -0
  181. package/dist/types/sessions/database_session_service.d.ts +31 -0
  182. package/dist/types/sessions/db/operations.d.ts +29 -0
  183. package/dist/types/sessions/db/schema.d.ts +45 -0
  184. package/dist/types/sessions/in_memory_session_service.d.ts +9 -6
  185. package/dist/types/sessions/registry.d.ts +7 -0
  186. package/dist/types/telemetry/setup.d.ts +1 -1
  187. package/dist/types/telemetry/tracing.d.ts +7 -6
  188. package/dist/types/tools/agent_tool.d.ts +1 -1
  189. package/dist/types/tools/base_tool.d.ts +1 -1
  190. package/dist/types/tools/base_toolset.d.ts +2 -1
  191. package/dist/types/tools/forwarding_artifact_service.d.ts +4 -2
  192. package/dist/types/tools/function_tool.d.ts +4 -3
  193. package/dist/types/tools/google_search_tool.d.ts +3 -3
  194. package/dist/types/tools/mcp/mcp_session_manager.d.ts +10 -3
  195. package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -2
  196. package/dist/types/utils/env_aware_utils.d.ts +7 -0
  197. package/dist/types/utils/gemini_schema_util.d.ts +4 -12
  198. package/dist/types/utils/logger.d.ts +11 -10
  199. package/dist/types/utils/object_notation_utils.d.ts +21 -0
  200. package/dist/types/utils/simple_zod_to_json.d.ts +5 -4
  201. package/dist/types/version.d.ts +1 -1
  202. package/dist/web/a2a/part_converter_utils.js +171 -0
  203. package/dist/web/agents/base_agent.js +96 -35
  204. package/dist/web/agents/callback_context.js +4 -1
  205. package/dist/web/agents/content_processor_utils.js +25 -9
  206. package/dist/web/agents/functions.js +84 -29
  207. package/dist/web/agents/llm_agent.js +166 -83
  208. package/dist/web/agents/loop_agent.js +2 -1
  209. package/dist/web/agents/parallel_agent.js +3 -4
  210. package/dist/web/agents/readonly_context.js +12 -0
  211. package/dist/web/agents/run_config.js +2 -1
  212. package/dist/web/artifacts/file_artifact_service.js +506 -0
  213. package/dist/web/artifacts/gcs_artifact_service.js +139 -54
  214. package/dist/web/artifacts/in_memory_artifact_service.js +69 -8
  215. package/dist/web/artifacts/registry.js +28 -0
  216. package/dist/web/auth/auth_handler.js +3 -1
  217. package/dist/web/code_executors/base_code_executor.js +3 -1
  218. package/dist/web/code_executors/built_in_code_executor.js +7 -3
  219. package/dist/web/code_executors/code_executor_context.js +5 -5
  220. package/dist/web/common.js +12 -2
  221. package/dist/web/events/event.js +30 -5
  222. package/dist/web/events/event_actions.js +1 -1
  223. package/dist/web/events/structured_events.js +74 -0
  224. package/dist/web/index.js +18 -8
  225. package/dist/web/memory/in_memory_memory_service.js +3 -1
  226. package/dist/web/models/apigee_llm.js +219 -0
  227. package/dist/web/models/base_llm.js +8 -4
  228. package/dist/web/models/gemini_llm_connection.js +1 -0
  229. package/dist/web/models/google_llm.js +75 -50
  230. package/dist/web/models/registry.js +2 -0
  231. package/dist/web/plugins/base_plugin.js +12 -0
  232. package/dist/web/plugins/logging_plugin.js +55 -14
  233. package/dist/web/plugins/plugin_manager.js +56 -24
  234. package/dist/web/plugins/security_plugin.js +1 -1
  235. package/dist/web/runner/runner.js +192 -108
  236. package/dist/web/sessions/base_session_service.js +49 -1
  237. package/dist/web/sessions/database_session_service.js +368 -0
  238. package/dist/web/sessions/db/operations.js +87 -0
  239. package/dist/web/sessions/db/schema.js +172 -0
  240. package/dist/web/sessions/in_memory_session_service.js +61 -33
  241. package/dist/web/sessions/registry.js +25 -0
  242. package/dist/web/telemetry/google_cloud.js +7 -9
  243. package/dist/web/telemetry/setup.js +23 -9
  244. package/dist/web/telemetry/tracing.js +37 -15
  245. package/dist/web/tools/agent_tool.js +8 -4
  246. package/dist/web/tools/base_tool.js +4 -2
  247. package/dist/web/tools/forwarding_artifact_service.js +17 -1
  248. package/dist/web/tools/function_tool.js +1 -2
  249. package/dist/web/tools/google_search_tool.js +2 -5
  250. package/dist/web/tools/long_running_tool.js +3 -1
  251. package/dist/web/tools/mcp/mcp_session_manager.js +22 -12
  252. package/dist/web/tools/mcp/mcp_tool.js +1 -3
  253. package/dist/web/tools/mcp/mcp_toolset.js +1 -1
  254. package/dist/web/utils/env_aware_utils.js +9 -1
  255. package/dist/web/utils/gemini_schema_util.js +9 -4
  256. package/dist/web/utils/logger.js +43 -2
  257. package/dist/web/utils/object_notation_utils.js +47 -0
  258. package/dist/web/utils/simple_zod_to_json.js +102 -155
  259. package/dist/web/utils/variant_utils.js +1 -7
  260. package/dist/web/version.js +1 -1
  261. package/package.json +16 -5
  262. package/dist/cjs/index.js.map +0 -7
  263. package/dist/esm/index.js.map +0 -7
  264. package/dist/web/index.js.map +0 -7
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -116,6 +116,7 @@ class GeminiLlmConnection {
116
116
  };
117
117
  }
118
118
  // TODO(b/425992518): GenAI SDK inconsistent API, missing methods.
119
+ // eslint-disable-next-line require-yield
119
120
  async *receive() {
120
121
  throw new Error("Not Implemented.");
121
122
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -24,10 +24,12 @@ var __copyProps = (to, from, except, desc) => {
24
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
25
  var google_llm_exports = {};
26
26
  __export(google_llm_exports, {
27
- Gemini: () => Gemini
27
+ Gemini: () => Gemini,
28
+ geminiInitParams: () => geminiInitParams
28
29
  });
29
30
  module.exports = __toCommonJS(google_llm_exports);
30
31
  var import_genai = require("@google/genai");
32
+ var import_env_aware_utils = require("../utils/env_aware_utils.js");
31
33
  var import_logger = require("../utils/logger.js");
32
34
  var import_variant_utils = require("../utils/variant_utils.js");
33
35
  var import_base_llm = require("./base_llm.js");
@@ -38,8 +40,6 @@ var import_llm_response = require("./llm_response.js");
38
40
  * Copyright 2025 Google LLC
39
41
  * SPDX-License-Identifier: Apache-2.0
40
42
  */
41
- const AGENT_ENGINE_TELEMETRY_TAG = "remote_reasoning_engine";
42
- const AGENT_ENGINE_TELEMETRY_ENV_VARIABLE_NAME = "GOOGLE_CLOUD_AGENT_ENGINE_ID";
43
43
  class Gemini extends import_base_llm.BaseLlm {
44
44
  /**
45
45
  * @param params The parameters for creating a Gemini instance.
@@ -56,45 +56,23 @@ class Gemini extends import_base_llm.BaseLlm {
56
56
  model = "gemini-2.5-flash";
57
57
  }
58
58
  super({ model });
59
- this.project = project;
60
- this.location = location;
61
- this.apiKey = apiKey;
62
- this.headers = headers;
63
- const canReadEnv = typeof process === "object";
64
- this.vertexai = !!vertexai;
65
- if (!this.vertexai && canReadEnv) {
66
- const vertexAIfromEnv = process.env["GOOGLE_GENAI_USE_VERTEXAI"];
67
- if (vertexAIfromEnv) {
68
- this.vertexai = vertexAIfromEnv.toLowerCase() === "true" || vertexAIfromEnv === "1";
69
- }
70
- }
71
- if (this.vertexai) {
72
- if (canReadEnv && !this.project) {
73
- this.project = process.env["GOOGLE_CLOUD_PROJECT"];
74
- }
75
- if (canReadEnv && !this.location) {
76
- this.location = process.env["GOOGLE_CLOUD_LOCATION"];
77
- }
78
- if (!this.project) {
79
- throw new Error(
80
- "VertexAI project must be provided via constructor or GOOGLE_CLOUD_PROJECT environment variable."
81
- );
82
- }
83
- if (!this.location) {
84
- throw new Error(
85
- "VertexAI location must be provided via constructor or GOOGLE_CLOUD_LOCATION environment variable."
86
- );
87
- }
88
- } else {
89
- if (!this.apiKey && canReadEnv) {
90
- this.apiKey = process.env["GOOGLE_GENAI_API_KEY"] || process.env["GEMINI_API_KEY"];
91
- }
92
- if (!this.apiKey) {
93
- throw new Error(
94
- "API key must be provided via constructor or GOOGLE_GENAI_API_KEY or GEMINI_API_KEY environment variable."
95
- );
96
- }
59
+ const params = geminiInitParams({
60
+ model,
61
+ vertexai,
62
+ project,
63
+ location,
64
+ apiKey
65
+ });
66
+ if (!params.vertexai && !params.apiKey) {
67
+ throw new Error(
68
+ "API key must be provided via constructor or GOOGLE_GENAI_API_KEY or GEMINI_API_KEY environment variable."
69
+ );
97
70
  }
71
+ this.project = params.project;
72
+ this.location = params.location;
73
+ this.apiKey = params.apiKey;
74
+ this.headers = headers;
75
+ this.vertexai = !!params.vertexai;
98
76
  }
99
77
  /**
100
78
  * Sends a request to the Gemini model.
@@ -183,25 +161,24 @@ class Gemini extends import_base_llm.BaseLlm {
183
161
  yield (0, import_llm_response.createLlmResponse)(response);
184
162
  }
185
163
  }
164
+ getHttpOptions() {
165
+ return { headers: { ...this.trackingHeaders, ...this.headers } };
166
+ }
186
167
  get apiClient() {
187
168
  if (this._apiClient) {
188
169
  return this._apiClient;
189
170
  }
190
- const combinedHeaders = {
191
- ...this.trackingHeaders,
192
- ...this.headers
193
- };
194
171
  if (this.vertexai) {
195
172
  this._apiClient = new import_genai.GoogleGenAI({
196
173
  vertexai: this.vertexai,
197
174
  project: this.project,
198
175
  location: this.location,
199
- httpOptions: { headers: combinedHeaders }
176
+ httpOptions: this.getHttpOptions()
200
177
  });
201
178
  } else {
202
179
  this._apiClient = new import_genai.GoogleGenAI({
203
180
  apiKey: this.apiKey,
204
- httpOptions: { headers: combinedHeaders }
181
+ httpOptions: this.getHttpOptions()
205
182
  });
206
183
  }
207
184
  return this._apiClient;
@@ -218,14 +195,17 @@ class Gemini extends import_base_llm.BaseLlm {
218
195
  }
219
196
  return this._liveApiVersion;
220
197
  }
198
+ getLiveHttpOptions() {
199
+ return {
200
+ headers: this.trackingHeaders,
201
+ apiVersion: this.liveApiVersion
202
+ };
203
+ }
221
204
  get liveApiClient() {
222
205
  if (!this._liveApiClient) {
223
206
  this._liveApiClient = new import_genai.GoogleGenAI({
224
207
  apiKey: this.apiKey,
225
- httpOptions: {
226
- headers: this.trackingHeaders,
227
- apiVersion: this.liveApiVersion
228
- }
208
+ httpOptions: this.getLiveHttpOptions()
229
209
  });
230
210
  }
231
211
  return this._liveApiClient;
@@ -252,7 +232,9 @@ class Gemini extends import_base_llm.BaseLlm {
252
232
  llmRequest.liveConnectConfig.systemInstruction = {
253
233
  role: "system",
254
234
  // TODO - b/425992518: validate type casting works well.
255
- parts: [(0, import_genai.createPartFromText)(llmRequest.config.systemInstruction)]
235
+ parts: [
236
+ (0, import_genai.createPartFromText)(llmRequest.config.systemInstruction)
237
+ ]
256
238
  };
257
239
  }
258
240
  llmRequest.liveConnectConfig.tools = (_c = llmRequest.config) == null ? void 0 : _c.tools;
@@ -301,7 +283,44 @@ function removeDisplayNameIfPresent(dataObj) {
301
283
  dataObj.displayName = void 0;
302
284
  }
303
285
  }
286
+ function geminiInitParams({
287
+ model,
288
+ vertexai,
289
+ project,
290
+ location,
291
+ apiKey
292
+ }) {
293
+ const params = { model, vertexai, project, location, apiKey };
294
+ params.vertexai = !!vertexai;
295
+ if (!params.vertexai && !(0, import_env_aware_utils.isBrowser)()) {
296
+ params.vertexai = (0, import_env_aware_utils.getBooleanEnvVar)("GOOGLE_GENAI_USE_VERTEXAI");
297
+ }
298
+ if (params.vertexai) {
299
+ if (!(0, import_env_aware_utils.isBrowser)() && !params.project) {
300
+ params.project = process.env["GOOGLE_CLOUD_PROJECT"];
301
+ }
302
+ if (!(0, import_env_aware_utils.isBrowser)() && !params.location) {
303
+ params.location = process.env["GOOGLE_CLOUD_LOCATION"];
304
+ }
305
+ if (!params.project) {
306
+ throw new Error(
307
+ "VertexAI project must be provided via constructor or GOOGLE_CLOUD_PROJECT environment variable."
308
+ );
309
+ }
310
+ if (!params.location) {
311
+ throw new Error(
312
+ "VertexAI location must be provided via constructor or GOOGLE_CLOUD_LOCATION environment variable."
313
+ );
314
+ }
315
+ } else {
316
+ if (!params.apiKey && !(0, import_env_aware_utils.isBrowser)()) {
317
+ params.apiKey = process.env["GOOGLE_GENAI_API_KEY"] || process.env["GEMINI_API_KEY"];
318
+ }
319
+ }
320
+ return params;
321
+ }
304
322
  // Annotate the CommonJS export names for ESM import in node:
305
323
  0 && (module.exports = {
306
- Gemini
324
+ Gemini,
325
+ geminiInitParams
307
326
  });
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -28,6 +28,7 @@ __export(registry_exports, {
28
28
  });
29
29
  module.exports = __toCommonJS(registry_exports);
30
30
  var import_logger = require("../utils/logger.js");
31
+ var import_apigee_llm = require("./apigee_llm.js");
31
32
  var import_google_llm = require("./google_llm.js");
32
33
  /**
33
34
  * @license
@@ -115,6 +116,7 @@ _LLMRegistry.llmRegistryDict = /* @__PURE__ */ new Map();
115
116
  _LLMRegistry.resolveCache = new LRUCache(32);
116
117
  let LLMRegistry = _LLMRegistry;
117
118
  LLMRegistry.register(import_google_llm.Gemini);
119
+ LLMRegistry.register(import_apigee_llm.ApigeeLlm);
118
120
  // Annotate the CommonJS export names for ESM import in node:
119
121
  0 && (module.exports = {
120
122
  LLMRegistry
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -54,6 +54,7 @@ class BasePlugin {
54
54
  * value to replace the user message. Returning `undefined` to proceed
55
55
  * normally.
56
56
  */
57
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
57
58
  async onUserMessageCallback(params) {
58
59
  return;
59
60
  }
@@ -69,6 +70,7 @@ class BasePlugin {
69
70
  * to halt execution of the runner and ends the runner with that event.
70
71
  * Return `undefined` to proceed normally.
71
72
  */
73
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
72
74
  async beforeRunCallback(params) {
73
75
  return;
74
76
  }
@@ -84,6 +86,7 @@ class BasePlugin {
84
86
  * framework to modify or replace the response. Returning `undefined`
85
87
  * allows the original response to be used.
86
88
  */
89
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
87
90
  async onEventCallback(params) {
88
91
  return;
89
92
  }
@@ -96,6 +99,7 @@ class BasePlugin {
96
99
  * @param params.invocationContext The context for the entire invocation.
97
100
  * @returns undefined
98
101
  */
102
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
99
103
  async afterRunCallback(params) {
100
104
  return;
101
105
  }
@@ -111,6 +115,7 @@ class BasePlugin {
111
115
  * bypass the agent's callbacks and its execution, and return this value
112
116
  * directly. Returning `undefined` allows the agent to proceed normally.
113
117
  */
118
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
114
119
  async beforeAgentCallback(params) {
115
120
  return;
116
121
  }
@@ -126,6 +131,7 @@ class BasePlugin {
126
131
  * replace the agent's original result. Returning `undefined` uses the
127
132
  * original, unmodified result.
128
133
  */
134
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
129
135
  async afterAgentCallback(params) {
130
136
  return;
131
137
  }
@@ -142,6 +148,7 @@ class BasePlugin {
142
148
  * trigger an early exit and returns the response immediately. Returning
143
149
  * `undefined` allows the LLM request to proceed normally.
144
150
  */
151
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
145
152
  async beforeModelCallback(params) {
146
153
  return;
147
154
  }
@@ -157,6 +164,7 @@ class BasePlugin {
157
164
  * framework to modify or replace the response. Returning `undefined`
158
165
  * allows the original response to be used.
159
166
  */
167
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
160
168
  async afterModelCallback(params) {
161
169
  return;
162
170
  }
@@ -174,6 +182,7 @@ class BasePlugin {
174
182
  * used instead of propagating the error. Returning `undefined` allows
175
183
  * the original error to be raised.
176
184
  */
185
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
177
186
  async onModelErrorCallback(params) {
178
187
  return;
179
188
  }
@@ -191,6 +200,7 @@ class BasePlugin {
191
200
  * the tool execution and return this response immediately. Returning
192
201
  * `undefined` uses the original, unmodified arguments.
193
202
  */
203
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
194
204
  async beforeToolCallback(params) {
195
205
  return;
196
206
  }
@@ -209,6 +219,7 @@ class BasePlugin {
209
219
  * post-processing or altering tool outputs. Returning `undefined` uses
210
220
  * the original, unmodified result.
211
221
  */
222
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
212
223
  async afterToolCallback(params) {
213
224
  return;
214
225
  }
@@ -236,6 +247,7 @@ class BasePlugin {
236
247
  * used as the tool response instead of propagating the error. Returning
237
248
  * `undefined` allows the original error to be raised.
238
249
  */
250
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
239
251
  async onToolErrorCallback(params) {
240
252
  return;
241
253
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -44,7 +44,10 @@ class LoggingPlugin extends import_base_plugin.BasePlugin {
44
44
  constructor(name = "logging_plugin") {
45
45
  super(name);
46
46
  }
47
- async onUserMessageCallback({ invocationContext, userMessage }) {
47
+ async onUserMessageCallback({
48
+ invocationContext,
49
+ userMessage
50
+ }) {
48
51
  var _a;
49
52
  this.log("\u{1F680} USER MESSAGE RECEIVED");
50
53
  this.log(` Invocation ID: ${invocationContext.invocationId}`);
@@ -58,14 +61,18 @@ class LoggingPlugin extends import_base_plugin.BasePlugin {
58
61
  }
59
62
  return void 0;
60
63
  }
61
- async beforeRunCallback({ invocationContext }) {
64
+ async beforeRunCallback({
65
+ invocationContext
66
+ }) {
62
67
  var _a;
63
68
  this.log("\u{1F3C3} INVOCATION STARTING");
64
69
  this.log(` Invocation ID: ${invocationContext.invocationId}`);
65
70
  this.log(` Starting Agent: ${(_a = invocationContext.agent.name) != null ? _a : "Unknown"}`);
66
71
  return void 0;
67
72
  }
68
- async onEventCallback({ invocationContext, event }) {
73
+ async onEventCallback({
74
+ event
75
+ }) {
69
76
  this.log("\u{1F4E2} EVENT YIELDED");
70
77
  this.log(` Event ID: ${event.id}`);
71
78
  this.log(` Author: ${event.author}`);
@@ -86,14 +93,18 @@ class LoggingPlugin extends import_base_plugin.BasePlugin {
86
93
  }
87
94
  return void 0;
88
95
  }
89
- async afterRunCallback({ invocationContext }) {
96
+ async afterRunCallback({
97
+ invocationContext
98
+ }) {
90
99
  var _a;
91
100
  this.log("\u2705 INVOCATION COMPLETED");
92
101
  this.log(` Invocation ID: ${invocationContext.invocationId}`);
93
102
  this.log(` Final Agent: ${(_a = invocationContext.agent.name) != null ? _a : "Unknown"}`);
94
103
  return void 0;
95
104
  }
96
- async beforeAgentCallback({ agent, callbackContext }) {
105
+ async beforeAgentCallback({
106
+ callbackContext
107
+ }) {
97
108
  this.log("\u{1F916} AGENT STARTING");
98
109
  this.log(` Agent Name: ${callbackContext.agentName}`);
99
110
  this.log(` Invocation ID: ${callbackContext.invocationId}`);
@@ -102,13 +113,18 @@ class LoggingPlugin extends import_base_plugin.BasePlugin {
102
113
  }
103
114
  return void 0;
104
115
  }
105
- async afterAgentCallback({ agent, callbackContext }) {
116
+ async afterAgentCallback({
117
+ callbackContext
118
+ }) {
106
119
  this.log("\u{1F916} AGENT COMPLETED");
107
120
  this.log(` Agent Name: ${callbackContext.agentName}`);
108
121
  this.log(` Invocation ID: ${callbackContext.invocationId}`);
109
122
  return void 0;
110
123
  }
111
- async beforeModelCallback({ callbackContext, llmRequest }) {
124
+ async beforeModelCallback({
125
+ callbackContext,
126
+ llmRequest
127
+ }) {
112
128
  var _a;
113
129
  this.log("\u{1F9E0} LLM REQUEST");
114
130
  this.log(` Model: ${(_a = llmRequest.model) != null ? _a : "default"}`);
@@ -126,7 +142,10 @@ class LoggingPlugin extends import_base_plugin.BasePlugin {
126
142
  }
127
143
  return void 0;
128
144
  }
129
- async afterModelCallback({ callbackContext, llmResponse }) {
145
+ async afterModelCallback({
146
+ callbackContext,
147
+ llmResponse
148
+ }) {
130
149
  this.log("\u{1F9E0} LLM RESPONSE");
131
150
  this.log(` Agent: ${callbackContext.agentName}`);
132
151
  if (llmResponse.errorCode) {
@@ -142,11 +161,17 @@ class LoggingPlugin extends import_base_plugin.BasePlugin {
142
161
  }
143
162
  }
144
163
  if (llmResponse.usageMetadata) {
145
- this.log(` Token Usage - Input: ${llmResponse.usageMetadata.promptTokenCount}, Output: ${llmResponse.usageMetadata.candidatesTokenCount}`);
164
+ this.log(
165
+ ` Token Usage - Input: ${llmResponse.usageMetadata.promptTokenCount}, Output: ${llmResponse.usageMetadata.candidatesTokenCount}`
166
+ );
146
167
  }
147
168
  return void 0;
148
169
  }
149
- async beforeToolCallback({ tool, toolArgs, toolContext }) {
170
+ async beforeToolCallback({
171
+ tool,
172
+ toolArgs,
173
+ toolContext
174
+ }) {
150
175
  this.log("\u{1F527} TOOL STARTING");
151
176
  this.log(` Tool Name: ${tool.name}`);
152
177
  this.log(` Agent: ${toolContext.agentName}`);
@@ -154,7 +179,11 @@ class LoggingPlugin extends import_base_plugin.BasePlugin {
154
179
  this.log(` Arguments: ${this.formatArgs(toolArgs)}`);
155
180
  return void 0;
156
181
  }
157
- async afterToolCallback({ tool, toolArgs, toolContext, result }) {
182
+ async afterToolCallback({
183
+ tool,
184
+ toolContext,
185
+ result
186
+ }) {
158
187
  this.log("\u{1F527} TOOL COMPLETED");
159
188
  this.log(` Tool Name: ${tool.name}`);
160
189
  this.log(` Agent: ${toolContext.agentName}`);
@@ -162,13 +191,21 @@ class LoggingPlugin extends import_base_plugin.BasePlugin {
162
191
  this.log(` Result: ${this.formatArgs(result)}`);
163
192
  return void 0;
164
193
  }
165
- async onModelErrorCallback({ callbackContext, llmRequest, error }) {
194
+ async onModelErrorCallback({
195
+ callbackContext,
196
+ error
197
+ }) {
166
198
  this.log("\u{1F9E0} LLM ERROR");
167
199
  this.log(` Agent: ${callbackContext.agentName}`);
168
200
  this.log(` Error: ${error}`);
169
201
  return void 0;
170
202
  }
171
- async onToolErrorCallback({ tool, toolArgs, toolContext, error }) {
203
+ async onToolErrorCallback({
204
+ tool,
205
+ toolArgs,
206
+ toolContext,
207
+ error
208
+ }) {
172
209
  this.log("\u{1F527} TOOL ERROR");
173
210
  this.log(` Tool Name: ${tool.name}`);
174
211
  this.log(` Agent: ${toolContext.agentName}`);
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
@@ -107,19 +107,22 @@ class PluginManager {
107
107
  /**
108
108
  * Runs the `onUserMessageCallback` for all plugins.
109
109
  */
110
- async runOnUserMessageCallback({ userMessage, invocationContext }) {
110
+ async runOnUserMessageCallback({
111
+ userMessage,
112
+ invocationContext
113
+ }) {
111
114
  return await this.runCallbacks(
112
115
  this.plugins,
113
- (plugin) => plugin.onUserMessageCallback(
114
- { userMessage, invocationContext }
115
- ),
116
+ (plugin) => plugin.onUserMessageCallback({ userMessage, invocationContext }),
116
117
  "onUserMessageCallback"
117
118
  );
118
119
  }
119
120
  /**
120
121
  * Runs the `beforeRunCallback` for all plugins.
121
122
  */
122
- async runBeforeRunCallback({ invocationContext }) {
123
+ async runBeforeRunCallback({
124
+ invocationContext
125
+ }) {
123
126
  return await this.runCallbacks(
124
127
  this.plugins,
125
128
  (plugin) => plugin.beforeRunCallback({ invocationContext }),
@@ -129,7 +132,9 @@ class PluginManager {
129
132
  /**
130
133
  * Runs the `afterRunCallback` for all plugins.
131
134
  */
132
- async runAfterRunCallback({ invocationContext }) {
135
+ async runAfterRunCallback({
136
+ invocationContext
137
+ }) {
133
138
  await this.runCallbacks(
134
139
  this.plugins,
135
140
  (plugin) => plugin.afterRunCallback({ invocationContext }),
@@ -139,7 +144,10 @@ class PluginManager {
139
144
  /**
140
145
  * Runs the `onEventCallback` for all plugins.
141
146
  */
142
- async runOnEventCallback({ invocationContext, event }) {
147
+ async runOnEventCallback({
148
+ invocationContext,
149
+ event
150
+ }) {
143
151
  return await this.runCallbacks(
144
152
  this.plugins,
145
153
  (plugin) => plugin.onEventCallback({ invocationContext, event }),
@@ -149,7 +157,10 @@ class PluginManager {
149
157
  /**
150
158
  * Runs the `beforeAgentCallback` for all plugins.
151
159
  */
152
- async runBeforeAgentCallback({ agent, callbackContext }) {
160
+ async runBeforeAgentCallback({
161
+ agent,
162
+ callbackContext
163
+ }) {
153
164
  return await this.runCallbacks(
154
165
  this.plugins,
155
166
  (plugin) => plugin.beforeAgentCallback({ agent, callbackContext }),
@@ -159,7 +170,10 @@ class PluginManager {
159
170
  /**
160
171
  * Runs the `afterAgentCallback` for all plugins.
161
172
  */
162
- async runAfterAgentCallback({ agent, callbackContext }) {
173
+ async runAfterAgentCallback({
174
+ agent,
175
+ callbackContext
176
+ }) {
163
177
  return await this.runCallbacks(
164
178
  this.plugins,
165
179
  (plugin) => plugin.afterAgentCallback({ agent, callbackContext }),
@@ -169,7 +183,11 @@ class PluginManager {
169
183
  /**
170
184
  * Runs the `beforeToolCallback` for all plugins.
171
185
  */
172
- async runBeforeToolCallback({ tool, toolArgs, toolContext }) {
186
+ async runBeforeToolCallback({
187
+ tool,
188
+ toolArgs,
189
+ toolContext
190
+ }) {
173
191
  return await this.runCallbacks(
174
192
  this.plugins,
175
193
  (plugin) => plugin.beforeToolCallback({ tool, toolArgs, toolContext }),
@@ -179,31 +197,39 @@ class PluginManager {
179
197
  /**
180
198
  * Runs the `afterToolCallback` for all plugins.
181
199
  */
182
- async runAfterToolCallback({ tool, toolArgs, toolContext, result }) {
200
+ async runAfterToolCallback({
201
+ tool,
202
+ toolArgs,
203
+ toolContext,
204
+ result
205
+ }) {
183
206
  return await this.runCallbacks(
184
207
  this.plugins,
185
- (plugin) => plugin.afterToolCallback(
186
- { tool, toolArgs, toolContext, result }
187
- ),
208
+ (plugin) => plugin.afterToolCallback({ tool, toolArgs, toolContext, result }),
188
209
  "afterToolCallback"
189
210
  );
190
211
  }
191
212
  /**
192
213
  * Runs the `onModelErrorCallback` for all plugins.
193
214
  */
194
- async runOnModelErrorCallback({ callbackContext, llmRequest, error }) {
215
+ async runOnModelErrorCallback({
216
+ callbackContext,
217
+ llmRequest,
218
+ error
219
+ }) {
195
220
  return await this.runCallbacks(
196
221
  this.plugins,
197
- (plugin) => plugin.onModelErrorCallback(
198
- { callbackContext, llmRequest, error }
199
- ),
222
+ (plugin) => plugin.onModelErrorCallback({ callbackContext, llmRequest, error }),
200
223
  "onModelErrorCallback"
201
224
  );
202
225
  }
203
226
  /**
204
227
  * Runs the `beforeModelCallback` for all plugins.
205
228
  */
206
- async runBeforeModelCallback({ callbackContext, llmRequest }) {
229
+ async runBeforeModelCallback({
230
+ callbackContext,
231
+ llmRequest
232
+ }) {
207
233
  return await this.runCallbacks(
208
234
  this.plugins,
209
235
  (plugin) => plugin.beforeModelCallback({ callbackContext, llmRequest }),
@@ -213,7 +239,10 @@ class PluginManager {
213
239
  /**
214
240
  * Runs the `afterModelCallback` for all plugins.
215
241
  */
216
- async runAfterModelCallback({ callbackContext, llmResponse }) {
242
+ async runAfterModelCallback({
243
+ callbackContext,
244
+ llmResponse
245
+ }) {
217
246
  return await this.runCallbacks(
218
247
  this.plugins,
219
248
  (plugin) => plugin.afterModelCallback({ callbackContext, llmResponse }),
@@ -223,12 +252,15 @@ class PluginManager {
223
252
  /**
224
253
  * Runs the `onToolErrorCallback` for all plugins.
225
254
  */
226
- async runOnToolErrorCallback({ tool, toolArgs, toolContext, error }) {
255
+ async runOnToolErrorCallback({
256
+ tool,
257
+ toolArgs,
258
+ toolContext,
259
+ error
260
+ }) {
227
261
  return await this.runCallbacks(
228
262
  this.plugins,
229
- (plugin) => plugin.onToolErrorCallback(
230
- { tool, toolArgs, toolContext, error }
231
- ),
263
+ (plugin) => plugin.onToolErrorCallback({ tool, toolArgs, toolContext, error }),
232
264
  "onToolErrorCallback"
233
265
  );
234
266
  }